]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/EfiSocketLib/Socket.c
1. Update PXE driver to support PXEv6 boot cross subnet.
[mirror_edk2.git] / StdLib / EfiSocketLib / Socket.c
index 49c288d90a4a8d92152f8c5e049bba7a38ce1498..d53473e9c9acd024214531020457d9c4bcaaacfd 100644 (file)
@@ -5,10 +5,10 @@
   * Bound - pSocket->PortList is not NULL\r
   * Listen - AcceptWait event is not NULL\r
 \r
-  Copyright (c) 2011, Intel Corporation\r
-  All rights reserved. This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
   http://opensource.org/licenses/bsd-license.php\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 \r
   <code><pre>\r
 \r
-                +-------------+   +-------------+   +-------------+   \r
+                +---------------+   +-------------+   +-------------+\r
   Service Lists | ::ESL_SERVICE |-->| ESL_SERVICE |-->| ESL_SERVICE |--> NULL (pNext)\r
-                +-------------+   +-------------+   +-------------+   \r
+                +---------------+   +-------------+   +-------------+\r
                   ^                       | (pPortList)    |\r
     pUdp4List ^   | pTcp4List             |                |\r
               |   |                       |                |\r
           ^   |   |                       |                |\r
  pIp4List |   |   |                       |                |\r
         +---------------+                 |                |\r
-        |   ::ESL_LAYER   |   ::mEslLayer     |                |\r
+        | ::ESL_LAYER   | ::mEslLayer     |                |\r
         +---------------+                 |                |\r
                   | (pSocketList)         |                |\r
     Socket List   V                       V                V\r
-                +-------------+   +-------------+   +-------------+   \r
-                | ::ESL_SOCKET  |-->|   ::ESL_PORT  |-->|   ESL_PORT  |--> NULL (pLinkSocket)\r
-                +-------------+   +-------------+   +-------------+   \r
+                +---------------+   +-------------+   +-------------+\r
+                | ::ESL_SOCKET  |-->| ::ESL_PORT  |-->|   ESL_PORT  |--> NULL (pLinkSocket)\r
+                +---------------+   +-------------+   +-------------+\r
                   |                       |                |\r
                   |                       |                V\r
                   V                       V               NULL\r
-                +-------------+   +-------------+         \r
+                +-------------+   +-------------+\r
                 | ESL_SOCKET  |-->|   ESL_PORT  |--> NULL\r
                 +-------------+   +-------------+\r
                   |    | | | |            |\r
@@ -53,9 +53,9 @@
                        | `---------------.                  |                |\r
   pTxOobPacketListHead |                 |                  |                |\r
                        V                 V                  V                V\r
-                  +------------+    +------------+    +------------+    +------------+\r
+                  +--------------+    +------------+    +------------+    +------------+\r
                   | ::ESL_PACKET |    | ESL_PACKET |    | ESL_PACKET |    | ESL_PACKET |\r
-                  +------------+    +------------+    +------------+    +------------+\r
+                  +--------------+    +------------+    +------------+    +------------+\r
                          |                 |                |                |\r
                          V                 V                V                V\r
                   +------------+    +------------+    +------------+    +------------+\r
       ::EslTcp4PortCloseOp.\r
     </li>\r
     <li>State: PORT_STATE_CLOSE_TX_DONE</li>\r
-    <li>Arc: ::EslSocketPortCloseComplete - Called when the close operation is \r
+    <li>Arc: ::EslSocketPortCloseComplete - Called when the close operation is\r
       complete.  After the transition to PORT_STATE_CLOSE_DONE,\r
       this routine calls ::EslSocketRxCancel to abort the pending receive operations.\r
     </li>\r
          pPort->pRxActive\r
                 |\r
                 V\r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
   Active  | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
 \r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
   Free    | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
                 ^\r
                 |\r
           pPort->pRxFree\r
 \r
 <code><pre>\r
 \r
-                    +------------+   +------------+   \r
+                    +------------+   +------------+\r
     High     .----->| ESL_PACKET |-->| ESL_PACKET |--> NULL (pNext)\r
   Priority   |      +------------+   +------------+\r
              |\r
        +------------+\r
              | pRxPacketListHead\r
     Low      |\r
-  Priority   |      +------------+   +------------+   +------------+   \r
+  Priority   |      +------------+   +------------+   +------------+\r
              `----->| ::ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL\r
-                    +------------+   +------------+   +------------+   \r
+                    +------------+   +------------+   +------------+\r
 \r
 </pre></code>\r
 \r
   ::EslSocketRxStart connects an ::ESL_PACKET structure to the ::ESL_IO_MGMT structure\r
-  and then calls the network layer to start the receive operation.  Upon \r
+  and then calls the network layer to start the receive operation.  Upon\r
   receive completion, ::EslSocketRxComplete breaks the connection between these\r
   structrues and places the ESL_IO_MGMT structure onto the ESL_PORT::pRxFree list to\r
   make token and event available for another receive operation.  EslSocketRxComplete\r
      *ppQueueHead: pSocket->pRxPacketListHead or pSocket->pRxOobPacketListHead\r
           |\r
           V\r
-        +------------+   +------------+   +------------+   \r
+        +------------+   +------------+   +------------+\r
   Data  | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL\r
-        +------------+   +------------+   +------------+   \r
+        +------------+   +------------+   +------------+\r
                                                      ^\r
                                                      |\r
      *ppQueueTail: pSocket->pRxPacketListTail or pSocket->pRxOobPacketListTail\r
          pPort->pTxActive or pTxOobActive\r
                 |\r
                 V\r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
   Active  | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
 \r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
   Free    | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-          +-------------+   +-------------+   +-------------+   \r
+          +-------------+   +-------------+   +-------------+\r
                 ^\r
                 |\r
           pPort->pTxFree or pTxOobFree\r
@@ -956,7 +956,7 @@ EslSocketAccept (
 \r
 /**\r
   Allocate and initialize a ESL_SOCKET structure.\r
-  \r
+\r
   This support function allocates an ::ESL_SOCKET structure\r
   and installs a protocol on ChildHandle.  If pChildHandle is a\r
   pointer to NULL, then a new handle is created and returned in\r
@@ -965,7 +965,7 @@ EslSocketAccept (
 \r
   @param [in, out] pChildHandle Pointer to the handle of the child to create.\r
                                 If it is NULL, then a new handle is created.\r
-                                If it is a pointer to an existing UEFI handle, \r
+                                If it is a pointer to an existing UEFI handle,\r
                                 then the protocol is added to the existing UEFI\r
                                 handle.\r
   @param [in] DebugFlags        Flags for debug messages\r
@@ -976,7 +976,7 @@ EslSocketAccept (
   @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to create\r
                                 the child\r
   @retval other                 The child handle was not created\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1644,15 +1644,15 @@ EslSocketCloseStart (
   connection with the specified remote system.  This routine\r
   is designed to be polled by the connect routine for completion\r
   of the network connection.\r
-  \r
+\r
   @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.\r
 \r
   @param [in] pSockAddr       Network address of the remote system.\r
-    \r
+\r
   @param [in] SockAddrLength  Length in bytes of the network address.\r
-  \r
+\r
   @param [out] pErrno   Address to receive the errno value upon completion.\r
-  \r
+\r
   @retval EFI_SUCCESS   The connection was successfully established.\r
   @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
   @retval Others        The connection attempt failed.\r
@@ -1671,7 +1671,7 @@ EslSocketConnect (
   ESL_SOCKET * pSocket;\r
   EFI_STATUS Status;\r
   EFI_TPL TplPrevious;\r
-  \r
+\r
   DEBUG (( DEBUG_CONNECT, "Entering SocketConnect\r\n" ));\r
 \r
   //\r
@@ -1964,7 +1964,7 @@ EslSocketCopyFragmentedBuffer (
   handle.\r
 \r
   @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.\r
-  \r
+\r
   @param [out] pErrno         Address to receive the errno value upon completion.\r
 \r
   @retval EFI_SUCCESS   The socket resources were returned successfully.\r
@@ -2126,7 +2126,7 @@ EslSocketFree (
   address associated with the local host connection point.\r
 \r
   @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.\r
-  \r
+\r
   @param [out] pAddress       Network address to receive the local system address\r
 \r
   @param [in,out] pAddressLength  Length of the local network address structure\r
@@ -2149,14 +2149,14 @@ EslSocketGetLocalAddress (
   ESL_SOCKET * pSocket;\r
   EFI_STATUS Status;\r
   EFI_TPL TplPrevious;\r
-  \r
+\r
   DBG_ENTER ( );\r
-  \r
+\r
   //\r
   //  Assume success\r
   //\r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   //\r
   //  Validate the socket\r
   //\r
@@ -2195,7 +2195,7 @@ EslSocketGetLocalAddress (
             //  Verify the address length\r
             //\r
             LengthInBytes = pSocket->pApi->AddressLength;\r
-            if (( LengthInBytes <= *pAddressLength ) \r
+            if (( LengthInBytes <= *pAddressLength )\r
               && ( 255 >= LengthInBytes )) {\r
               //\r
               //  Return the local address and address length\r
@@ -2216,7 +2216,7 @@ EslSocketGetLocalAddress (
             pSocket->errno = ENOTCONN;\r
             Status = EFI_NOT_STARTED;\r
           }\r
-          \r
+\r
           //\r
           //  Release the socket layer synchronization\r
           //\r
@@ -2236,7 +2236,7 @@ EslSocketGetLocalAddress (
       pSocket->errno = EADDRNOTAVAIL;\r
     }\r
   }\r
-  \r
+\r
   //\r
   //  Return the operation status\r
   //\r
@@ -2264,7 +2264,7 @@ EslSocketGetLocalAddress (
   address of the remote connection point.\r
 \r
   @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.\r
-  \r
+\r
   @param [out] pAddress       Network address to receive the remote system address\r
 \r
   @param [in,out] pAddressLength  Length of the remote network address structure\r
@@ -2287,14 +2287,14 @@ EslSocketGetPeerAddress (
   ESL_SOCKET * pSocket;\r
   EFI_STATUS Status;\r
   EFI_TPL TplPrevious;\r
-  \r
+\r
   DBG_ENTER ( );\r
-  \r
+\r
   //\r
   //  Assume success\r
   //\r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   //\r
   //  Validate the socket\r
   //\r
@@ -2970,7 +2970,7 @@ EslSocketOptionGet (
         pOptionData = (CONST UINT8 *)&pSocket->RxTimeout;\r
         LengthInBytes = sizeof ( pSocket->RxTimeout );\r
         break;\r
-        \r
+\r
       case SO_RCVBUF:\r
         //\r
         //  Return the maximum receive buffer size\r
@@ -2986,7 +2986,7 @@ EslSocketOptionGet (
         pOptionData = (UINT8 *)&pSocket->bReUseAddr;\r
         LengthInBytes = sizeof ( pSocket->bReUseAddr );\r
         break;\r
-      \r
+\r
       case SO_SNDBUF:\r
         //\r
         //  Return the maximum transmit buffer size\r
@@ -3088,9 +3088,9 @@ EslSocketOptionSet (
   UINT8 * pOptionData;\r
   ESL_SOCKET * pSocket;\r
   EFI_STATUS Status;\r
-  \r
+\r
   DBG_ENTER ( );\r
-  \r
+\r
   //\r
   //  Assume failure\r
   //\r
@@ -3149,7 +3149,7 @@ EslSocketOptionSet (
         errno = ENOPROTOOPT;\r
         Status = EFI_INVALID_PARAMETER;\r
         break;\r
-    \r
+\r
       case SOL_SOCKET:\r
         switch ( OptionName ) {\r
         default:\r
@@ -3462,13 +3462,13 @@ EslSocketPoll (
       //  Synchronize with the socket layer\r
       //\r
       RAISE_TPL ( TplPrevious, TPL_SOCKETS );\r
-      \r
+\r
       //\r
       //  Increase the network performance by extending the\r
       //  polling (idle) loop down into the LAN driver\r
       //\r
       EslSocketRxPoll ( pSocket );\r
-      \r
+\r
       //\r
       //  Release the socket layer synchronization\r
       //\r
@@ -3844,7 +3844,7 @@ EslSocketPortAllocate (
     <li>::EslTcp4ConnectComplete - Connection failure and reducing the port list to a single port</li>\r
   </ul>\r
   See the \ref PortCloseStateMachine section.\r
-  \r
+\r
   @param [in] pPort       Address of an ::ESL_PORT structure.\r
 \r
   @retval EFI_SUCCESS     The port is closed\r
@@ -3865,7 +3865,7 @@ EslSocketPortClose (
   CONST ESL_SOCKET_BINDING * pSocketBinding;\r
   ESL_SOCKET * pSocket;\r
   EFI_STATUS Status;\r
-  \r
+\r
   DBG_ENTER ( );\r
 \r
   //\r
@@ -4460,13 +4460,13 @@ EslSocketPortCloseTxDone (
   ::recv and ::read are layered on top of ::recvfrom.\r
 \r
   @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.\r
-  \r
+\r
   @param [in] Flags           Message control flags\r
-  \r
+\r
   @param [in] BufferLength    Length of the the buffer\r
-  \r
+\r
   @param [in] pBuffer         Address of a buffer to receive the data.\r
-  \r
+\r
   @param [in] pDataLength     Number of received data bytes in the buffer.\r
 \r
   @param [out] pAddress       Network address to receive the remote system address\r
@@ -4577,7 +4577,7 @@ EslSocketReceive (
                 pRemoteAddress->sa_family = pSocket->pApi->AddressFamily;\r
                 pRemoteAddress->sa_len = (UINT8)pSocket->pApi->AddressLength;\r
               }\r
-              \r
+\r
               //\r
               //  Synchronize with the socket layer\r
               //\r
@@ -4789,7 +4789,7 @@ EslSocketReceive (
         }\r
       }\r
 \r
-      \r
+\r
     }\r
     else {\r
       //\r
@@ -4915,13 +4915,13 @@ EslSocketRxComplete (
   //         pPort->pRxActive\r
   //                |\r
   //                V\r
-  //          +-------------+   +-------------+   +-------------+   \r
+  //          +-------------+   +-------------+   +-------------+\r
   //  Active  | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-  //          +-------------+   +-------------+   +-------------+   \r
+  //          +-------------+   +-------------+   +-------------+\r
   //\r
-  //          +-------------+   +-------------+   +-------------+   \r
+  //          +-------------+   +-------------+   +-------------+\r
   //  Free    | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-  //          +-------------+   +-------------+   +-------------+   \r
+  //          +-------------+   +-------------+   +-------------+\r
   //                ^\r
   //                |\r
   //          pPort->pRxFree\r
@@ -4955,13 +4955,13 @@ EslSocketRxComplete (
   //            pRxOobPacketListHead              pRxOobPacketListTail\r
   //                      |                                 |\r
   //                      V                                 V\r
-  //               +------------+   +------------+   +------------+   \r
+  //               +------------+   +------------+   +------------+\r
   //  Urgent Data  | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL\r
-  //               +------------+   +------------+   +------------+   \r
+  //               +------------+   +------------+   +------------+\r
   //\r
-  //               +------------+   +------------+   +------------+   \r
+  //               +------------+   +------------+   +------------+\r
   //  Normal Data  | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL\r
-  //               +------------+   +------------+   +------------+   \r
+  //               +------------+   +------------+   +------------+\r
   //                      ^                                 ^\r
   //                      |                                 |\r
   //              pRxPacketListHead                pRxPacketListTail\r
@@ -5247,13 +5247,13 @@ EslSocketRxStart (
           //  Allocate the receive control structure\r
           //\r
           pPort->pRxFree = pIo->pNext;\r
-          \r
+\r
           //\r
           //  Mark this receive as pending\r
           //\r
           pIo->pNext = pPort->pRxActive;\r
           pPort->pRxActive = pIo;\r
-          \r
+\r
         }\r
         else {\r
           DEBUG (( DEBUG_RX | DEBUG_INFO,\r
@@ -5315,9 +5315,9 @@ EslSocketRxStart (
   operations on the socket.\r
 \r
   @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.\r
-  \r
+\r
   @param [in] How             Which operations to stop\r
-  \r
+\r
   @param [out] pErrno         Address to receive the errno value upon completion.\r
 \r
   @retval EFI_SUCCESS - Socket operations successfully shutdown\r
@@ -5335,9 +5335,9 @@ EslSocketShutdown (
   ESL_SOCKET * pSocket;\r
   EFI_STATUS Status;\r
   EFI_TPL TplPrevious;\r
-  \r
+\r
   DBG_ENTER ( );\r
-  \r
+\r
   //\r
   //  Assume success\r
   //\r
@@ -5454,13 +5454,13 @@ EslSocketShutdown (
   system.  Note that ::send and ::write are layered on top of ::sendto.\r
 \r
   @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.\r
-  \r
+\r
   @param [in] Flags           Message control flags\r
-  \r
+\r
   @param [in] BufferLength    Length of the the buffer\r
-  \r
+\r
   @param [in] pBuffer         Address of a buffer containing the data to send\r
-  \r
+\r
   @param [in] pDataLength     Address to receive the number of data bytes sent\r
 \r
   @param [in] pAddress        Network address of the remote system address\r
@@ -5827,9 +5827,9 @@ EslSocketTxStart (
     //     *ppQueueHead: pSocket->pRxPacketListHead or pSocket->pRxOobPacketListHead\r
     //          |\r
     //          V\r
-    //        +------------+   +------------+   +------------+   \r
+    //        +------------+   +------------+   +------------+\r
     //  Data  | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL\r
-    //        +------------+   +------------+   +------------+   \r
+    //        +------------+   +------------+   +------------+\r
     //                                                     ^\r
     //                                                     |\r
     //     *ppQueueTail: pSocket->pRxPacketListTail or pSocket->pRxOobPacketListTail\r
@@ -5900,9 +5900,9 @@ EslSocketTxStart (
       pIo->pPacket = pPacket;\r
 \r
       //\r
-      //          +-------------+   +-------------+   +-------------+   \r
+      //          +-------------+   +-------------+   +-------------+\r
       //  Free    | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-      //          +-------------+   +-------------+   +-------------+   \r
+      //          +-------------+   +-------------+   +-------------+\r
       //              ^\r
       //              |\r
       //          *ppFree:  pPort->pTxFree or pTxOobFree\r
@@ -5911,14 +5911,14 @@ EslSocketTxStart (
       //  Remove the IO structure from the queue\r
       //\r
       *ppFree = pIo->pNext;\r
-      \r
+\r
       //\r
       //         *ppActive:  pPort->pTxActive or pTxOobActive\r
       //             |\r
       //             V\r
-      //          +-------------+   +-------------+   +-------------+   \r
+      //          +-------------+   +-------------+   +-------------+\r
       //  Active  | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL\r
-      //          +-------------+   +-------------+   +-------------+   \r
+      //          +-------------+   +-------------+   +-------------+\r
       //\r
       //\r
       //  Mark this packet as active\r