]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/EfiSocketLib/UseEfiSocketLib.c
MdeModulePkg EsrtFmpDxe: Use EfiBootServicesData for ESRT table
[mirror_edk2.git] / StdLib / EfiSocketLib / UseEfiSocketLib.c
index b0e8ef671a2575eaff6452aaf01c3abfbfa38b03..060598af31e4b6f0684833d2492c372404f777dd 100644 (file)
 \r
 **/\r
 \r
-#include <socket.h>\r
+#include "Socket.h"\r
 \r
 \r
-CONST EFI_GUID mEslRawServiceGuid = {\r
-  0xc31bf4a5, 0x2c7, 0x49d2, { 0xa5, 0x58, 0xfe, 0x62, 0x6f, 0x7e, 0xd4, 0x77 }\r
+/**\r
+  The following GUID values are only used when an application links\r
+  against EfiSocketLib.  An alternative set of values exists in\r
+  SocketDxe\EntryUnload.c which the SocketDxe driver uses to coexist\r
+  with socket applications.\r
+  \r
+  Tag GUID - IPv4 in use by an application using EfiSocketLib\r
+**/\r
+CONST EFI_GUID mEslIp4ServiceGuid __attribute__((weak)) = {\r
+  0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }\r
+};\r
+\r
+\r
+/**\r
+  Tag GUID - IPv6 in use by an application using EfiSocketLib\r
+**/\r
+CONST EFI_GUID mEslIp6ServiceGuid __attribute__((weak)) = {\r
+  0xc51b2761, 0xc476, 0x45fe, { 0xbe, 0x61, 0xba, 0x4b, 0xcc, 0x32, 0xf2, 0x34 }\r
 };\r
 \r
-CONST EFI_GUID mEslTcp4ServiceGuid = {\r
+\r
+/**\r
+  Tag GUID - TCPv4 in use by an application using EfiSocketLib\r
+**/\r
+CONST EFI_GUID mEslTcp4ServiceGuid __attribute__((weak)) = {\r
   0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }\r
 };\r
 \r
-CONST EFI_GUID mEslUdp4ServiceGuid = {\r
+\r
+/**\r
+  Tag GUID - TCPv6 in use by an application using EfiSocketLib\r
+**/\r
+CONST EFI_GUID mEslTcp6ServiceGuid __attribute__((weak)) = {\r
+  0x279858a4, 0x4e9e, 0x4e53, { 0x93, 0x22, 0xf2, 0x54, 0xe0, 0x7e, 0xef, 0xd4 }\r
+};\r
+\r
+\r
+/**\r
+  Tag GUID - UDPv4 in use by an application using EfiSocketLib\r
+**/\r
+CONST EFI_GUID mEslUdp4ServiceGuid __attribute__((weak)) = {\r
   0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }\r
 };\r
 \r
 \r
+/**\r
+  Tag GUID - UDPv6 in use by an application using EfiSocketLib\r
+**/\r
+CONST EFI_GUID mEslUdp6ServiceGuid __attribute__((weak)) = {\r
+  0xaa4af677, 0x6efe, 0x477c, { 0x96, 0x68, 0xe8, 0x13, 0x9d, 0x2, 0xfd, 0x9b }\r
+};\r
+\r
+\r
+/**\r
+  Free the socket resources\r
+\r
+  This releases the socket resources allocated by calling\r
+  EslServiceGetProtocol.\r
+\r
+  This routine is called from the ::close routine in BsdSocketLib\r
+  to release the socket resources.\r
+\r
+  @param [in] pSocketProtocol   Address of an ::EFI_SOCKET_PROTOCOL\r
+                                structure\r
+\r
+  @return       Value for ::errno, zero (0) indicates success.\r
+\r
+ **/\r
+int\r
+EslServiceFreeProtocol (\r
+  IN EFI_SOCKET_PROTOCOL * pSocketProtocol\r
+  )\r
+{\r
+  int RetVal;\r
+\r
+  //\r
+  //  Release the socket resources\r
+  //\r
+  EslSocketFree ( pSocketProtocol, &RetVal );\r
+\r
+  //\r
+  //  Return the operation status\r
+  //\r
+  return RetVal;\r
+}\r
+\r
+\r
 /**\r
   Connect to the EFI socket library\r
 \r
-  @param [in] ppSocketProtocol  Address to receive the socket protocol address\r
+  This routine creates the ::ESL_SOCKET structure and returns\r
+  the API (::EFI_SOCKET_PROTOCOL address) to the socket file\r
+  system layer in BsdSocketLib.\r
+\r
+  This routine is called from the ::socket routine in BsdSocketLib\r
+  to create the data structure and initialize the API for a socket.\r
+  Note that this implementation is only used by socket applications\r
+  that link directly to EslSocketLib.\r
+\r
+  @param [in] ppSocketProtocol  Address to receive the ::EFI_SOCKET_PROTOCOL\r
+                                structure address\r
+\r
+  @return       Value for ::errno, zero (0) indicates success.\r
 \r
-  @retval 0             Successfully returned the socket protocol\r
-  @retval other         Value for errno\r
  **/\r
 int\r
 EslServiceGetProtocol (\r
@@ -42,7 +126,7 @@ EslServiceGetProtocol (
   )\r
 {\r
   EFI_HANDLE ChildHandle;\r
-  DT_SOCKET * pSocket;\r
+  ESL_SOCKET * pSocket;\r
   int RetVal;\r
   EFI_STATUS Status;\r
 \r
@@ -81,6 +165,16 @@ EslServiceGetProtocol (
 /**\r
   Connect to the network layer\r
 \r
+  This routine is the constructor for the EfiSocketLib when the\r
+  library is linked directly to an application.  This routine\r
+  walks the ::cEslSocketBinding table to create ::ESL_SERVICE\r
+  structures, associated with the network adapters, which this\r
+  routine links to the ::ESL_LAYER structure.\r
+\r
+  This routine is called from ::EslConstructor as a result of the\r
+  constructor redirection in ::mpfnEslConstructor at the end of this\r
+  file.\r
+\r
   @retval EFI_SUCCESS   Successfully connected to the network layer\r
 \r
  **/\r
@@ -89,11 +183,12 @@ EslServiceNetworkConnect (
   VOID\r
   )\r
 {\r
+  BOOLEAN bSomethingFound;\r
   UINTN HandleCount;\r
-  EFI_HANDLE * pHandles;\r
   UINTN Index;\r
-  CONST DT_SOCKET_BINDING * pSocketBinding;\r
-  CONST DT_SOCKET_BINDING * pEnd;\r
+  CONST ESL_SOCKET_BINDING * pEnd;\r
+  EFI_HANDLE * pHandles;\r
+  CONST ESL_SOCKET_BINDING * pSocketBinding;\r
   EFI_STATUS Status;\r
 \r
   DBG_ENTER ( );\r
@@ -102,13 +197,14 @@ EslServiceNetworkConnect (
   //  Initialize the socket layer\r
   //\r
   Status = EFI_SUCCESS;\r
+  bSomethingFound = FALSE;\r
   EslServiceLoad ( gImageHandle );\r
 \r
   //\r
   //  Connect the network devices\r
   //\r
-  pSocketBinding = &cEslSocketBinding [0];\r
-  pEnd = &pSocketBinding [ cEslSocketBindingEntries ];\r
+  pSocketBinding = &cEslSocketBinding[0];\r
+  pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r
   while ( pEnd > pSocketBinding ) {\r
     //\r
     //  Attempt to locate the network adapters\r
@@ -121,24 +217,37 @@ EslServiceNetworkConnect (
                                        &HandleCount,\r
                                        &pHandles );\r
     if ( EFI_ERROR ( Status )) {\r
-      break;\r
+      DEBUG (( DEBUG_ERROR,\r
+               "ERROR with %s layer, Status: %r\r\n",\r
+               pSocketBinding->pName,\r
+               Status ));\r
     }\r
-    if ( NULL != pHandles ) {\r
-      //\r
-      //  Attempt to connect to this network adapter\r
-      //\r
-      for ( Index = 0; HandleCount > Index; Index++ ) {\r
-        Status = EslServiceConnect ( gImageHandle,\r
-                                     pHandles [ Index ]);\r
-        if ( EFI_ERROR ( Status )) {\r
-          break;\r
+    else {\r
+      if ( NULL != pHandles ) {\r
+        //\r
+        //  Attempt to connect to this network adapter\r
+        //\r
+        for ( Index = 0; HandleCount > Index; Index++ ) {\r
+          Status = EslServiceConnect ( gImageHandle,\r
+                                       pHandles[ Index ]);\r
+          if ( !EFI_ERROR ( Status )) {\r
+            bSomethingFound = TRUE;\r
+          }\r
+          else {\r
+            if ( EFI_OUT_OF_RESOURCES == Status ) {\r
+              //\r
+              //  Pointless to continue without memory\r
+              //\r
+              break;\r
+            }\r
+          }\r
         }\r
-      }\r
 \r
-      //\r
-      //  Done with the handles\r
-      //\r
-      gBS->FreePool ( pHandles );\r
+        //\r
+        //  Done with the handles\r
+        //\r
+        gBS->FreePool ( pHandles );\r
+      }\r
     }\r
 \r
     //\r
@@ -150,6 +259,9 @@ EslServiceNetworkConnect (
   //\r
   //  Return the network connection status\r
   //\r
+  if ( bSomethingFound ) {\r
+    Status = EFI_SUCCESS;\r
+  }\r
   DBG_EXIT_STATUS ( Status );\r
   return Status;\r
 }\r
@@ -158,6 +270,15 @@ EslServiceNetworkConnect (
 /**\r
   Disconnect from the network layer\r
 \r
+  Destructor for the EfiSocketLib when the library is linked\r
+  directly to an application.  This routine walks the\r
+  ::cEslSocketBinding table to remove the ::ESL_SERVICE\r
+  structures (network connections) from the ::ESL_LAYER structure.\r
+\r
+  This routine is called from ::EslDestructor as a result of the\r
+  destructor redirection in ::mpfnEslDestructor at the end of this\r
+  file.\r
+\r
   @retval EFI_SUCCESS   Successfully disconnected from the network layer\r
 \r
  **/\r
@@ -167,10 +288,10 @@ EslServiceNetworkDisconnect (
   )\r
 {\r
   UINTN HandleCount;\r
-  EFI_HANDLE * pHandles;\r
   UINTN Index;\r
-  CONST DT_SOCKET_BINDING * pSocketBinding;\r
-  CONST DT_SOCKET_BINDING * pEnd;\r
+  CONST ESL_SOCKET_BINDING * pEnd;\r
+  EFI_HANDLE * pHandles;\r
+  CONST ESL_SOCKET_BINDING * pSocketBinding;\r
   EFI_STATUS Status;\r
 \r
   DBG_ENTER ( );\r
@@ -183,8 +304,8 @@ EslServiceNetworkDisconnect (
   //\r
   //  Disconnect the network devices\r
   //\r
-  pSocketBinding = &cEslSocketBinding [0];\r
-  pEnd = &pSocketBinding [ cEslSocketBindingEntries ];\r
+  pSocketBinding = &cEslSocketBinding[0];\r
+  pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r
   while ( pEnd > pSocketBinding ) {\r
     //\r
     //  Attempt to locate the network adapters\r
@@ -196,16 +317,14 @@ EslServiceNetworkDisconnect (
                                        NULL,\r
                                        &HandleCount,\r
                                        &pHandles );\r
-    if ( EFI_ERROR ( Status )) {\r
-      break;\r
-    }\r
-    if ( NULL != pHandles ) {\r
+    if (( !EFI_ERROR ( Status ))\r
+      && ( NULL != pHandles )) {\r
       //\r
       //  Attempt to disconnect from this network adapter\r
       //\r
       for ( Index = 0; HandleCount > Index; Index++ ) {\r
         Status = EslServiceDisconnect ( gImageHandle,\r
-                                        pHandles [ Index ]);\r
+                                        pHandles[ Index ]);\r
         if ( EFI_ERROR ( Status )) {\r
           break;\r
         }\r
@@ -221,6 +340,7 @@ EslServiceNetworkDisconnect (
     //  Set the next network protocol\r
     //\r
     pSocketBinding += 1;\r
+    Status = EFI_SUCCESS;\r
   }\r
 \r
   //\r
@@ -238,5 +358,19 @@ EslServiceNetworkDisconnect (
 }\r
 \r
 \r
-PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect;\r
-PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect;\r
+/**\r
+  Socket layer's service binding protocol delcaration.\r
+**/\r
+CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding __attribute__((weak)) = {\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+/**\r
+  The following entries redirect the constructor and destructor\r
+  for any socket application that links against the EfiSocketLib.\r
+  Note that the SocketDxe driver uses different redirection.\r
+**/\r
+PFN_ESL_xSTRUCTOR mpfnEslConstructor __attribute__((weak)) = EslServiceNetworkConnect;    ///<  Constructor for EfiSocketLib\r
+PFN_ESL_xSTRUCTOR mpfnEslDestructor __attribute__((weak)) = EslServiceNetworkDisconnect;  ///<  Destructor for EfiSocketLib\r