]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/EfiSocketLib/UseEfiSocketLib.c
MdeModulePkg PCI Bus Driver: Remove the workaround for the EFI_PCI_IO_ATTRIBUTE_VGA_P...
[mirror_edk2.git] / StdLib / EfiSocketLib / UseEfiSocketLib.c
index b0e8ef671a2575eaff6452aaf01c3abfbfa38b03..1c122af650d76e5849c4b2fba6168d6697ad825c 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 = {\r
+  0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }\r
 };\r
 \r
+\r
+/**\r
+  Tag GUID - TCPv4 in use by an application using EfiSocketLib\r
+**/\r
 CONST EFI_GUID mEslTcp4ServiceGuid = {\r
   0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }\r
 };\r
 \r
+\r
+/**\r
+  Tag GUID - UDPv4 in use by an application using EfiSocketLib\r
+**/\r
 CONST EFI_GUID mEslUdp4ServiceGuid = {\r
   0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }\r
 };\r
@@ -31,10 +47,20 @@ CONST EFI_GUID mEslUdp4ServiceGuid = {
 /**\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 +68,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 +107,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 +125,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 +139,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 +159,30 @@ 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
+            break;\r
+          }\r
+          bSomethingFound = TRUE;\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 +194,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 +205,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 +223,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 +239,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
@@ -205,7 +261,7 @@ EslServiceNetworkDisconnect (
       //\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
@@ -238,5 +294,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 = {\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 = EslServiceNetworkConnect;    ///<  Constructor for EfiSocketLib\r
+PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect;  ///<  Destructor for EfiSocketLib\r