]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeTcpIoLib/DxeTcpIoLib.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Library / DxeTcpIoLib / DxeTcpIoLib.c
index 17183e1a6c818df61f2e1715b02f4d0259de140b..341295d0b7afd49874c5ee3a2aa01579820fca90 100644 (file)
@@ -2,14 +2,8 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to access TCP service.\r
 \r
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to access TCP service.\r
 \r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
-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<BR>\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 **/\r
 \r
@@ -23,7 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/BaseMemoryLib.h>\r
 \r
 /**\r
 #include <Library/BaseMemoryLib.h>\r
 \r
 /**\r
-  The common notify function associated with various TcpIo events. \r
+  The common notify function associated with various TcpIo events.\r
 \r
   @param[in]  Event   The event signaled.\r
   @param[in]  Context The context.\r
 \r
   @param[in]  Event   The event signaled.\r
   @param[in]  Context The context.\r
@@ -111,14 +105,14 @@ ON_EXIT:
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  Create a TCP socket with the specified configuration data. \r
+  Create a TCP socket with the specified configuration data.\r
 \r
   @param[in]  Image      The handle of the driver image.\r
   @param[in]  Controller The handle of the controller.\r
   @param[in]  TcpVersion The version of Tcp, TCP_VERSION_4 or TCP_VERSION_6.\r
   @param[in]  ConfigData The Tcp configuration data.\r
   @param[out] TcpIo      The TcpIo.\r
 \r
   @param[in]  Image      The handle of the driver image.\r
   @param[in]  Controller The handle of the controller.\r
   @param[in]  TcpVersion The version of Tcp, TCP_VERSION_4 or TCP_VERSION_6.\r
   @param[in]  ConfigData The Tcp configuration data.\r
   @param[out] TcpIo      The TcpIo.\r
-  \r
+\r
   @retval EFI_SUCCESS            The TCP socket is created and configured.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
   @retval EFI_UNSUPPORTED        One or more of the control options are not\r
   @retval EFI_SUCCESS            The TCP socket is created and configured.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
   @retval EFI_UNSUPPORTED        One or more of the control options are not\r
@@ -176,7 +170,7 @@ TcpIoCreateSocket (
 \r
   //\r
   // Create the TCP child instance and get the TCP protocol.\r
 \r
   //\r
   // Create the TCP child instance and get the TCP protocol.\r
-  //  \r
+  //\r
   Status = NetLibCreateServiceChild (\r
              Controller,\r
              Image,\r
   Status = NetLibCreateServiceChild (\r
              Controller,\r
              Image,\r
@@ -395,9 +389,9 @@ ON_ERROR:
 \r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
-  \r
+\r
 /**\r
 /**\r
-  Destroy the socket. \r
+  Destroy the socket.\r
 \r
   @param[in]  TcpIo The TcpIo which wraps the socket to be destroyed.\r
 \r
 \r
   @param[in]  TcpIo The TcpIo which wraps the socket to be destroyed.\r
 \r
@@ -530,8 +524,8 @@ TcpIoDestroySocket (
   Connect to the other endpoint of the TCP socket.\r
 \r
   @param[in, out]  TcpIo     The TcpIo wrapping the TCP socket.\r
   Connect to the other endpoint of the TCP socket.\r
 \r
   @param[in, out]  TcpIo     The TcpIo wrapping the TCP socket.\r
-  @param[in]       Timeout   The time to wait for connection done.\r
-  \r
+  @param[in]       Timeout   The time to wait for connection done. Set to NULL for infinite wait.\r
+\r
   @retval EFI_SUCCESS            Connect to the other endpoint of the TCP socket\r
                                  successfully.\r
   @retval EFI_TIMEOUT            Failed to connect to the other endpoint of the\r
   @retval EFI_SUCCESS            Connect to the other endpoint of the TCP socket\r
                                  successfully.\r
   @retval EFI_TIMEOUT            Failed to connect to the other endpoint of the\r
@@ -546,7 +540,7 @@ EFI_STATUS
 EFIAPI\r
 TcpIoConnect (\r
   IN OUT TCP_IO             *TcpIo,\r
 EFIAPI\r
 TcpIoConnect (\r
   IN OUT TCP_IO             *TcpIo,\r
-  IN     EFI_EVENT          Timeout\r
+  IN     EFI_EVENT          Timeout        OPTIONAL\r
   )\r
 {\r
   EFI_TCP4_PROTOCOL         *Tcp4;\r
   )\r
 {\r
   EFI_TCP4_PROTOCOL         *Tcp4;\r
@@ -576,7 +570,7 @@ TcpIoConnect (
     return Status;\r
   }\r
 \r
     return Status;\r
   }\r
 \r
-  while (!TcpIo->IsConnDone && EFI_ERROR (gBS->CheckEvent (Timeout))) {\r
+  while (!TcpIo->IsConnDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout)))) {\r
     if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
       Tcp4->Poll (Tcp4);\r
     } else {\r
     if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
       Tcp4->Poll (Tcp4);\r
     } else {\r
@@ -585,6 +579,11 @@ TcpIoConnect (
   }\r
 \r
   if (!TcpIo->IsConnDone) {\r
   }\r
 \r
   if (!TcpIo->IsConnDone) {\r
+    if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
+      Tcp4->Cancel (Tcp4, &TcpIo->ConnToken.Tcp4Token.CompletionToken);\r
+    } else {\r
+      Tcp6->Cancel (Tcp6, &TcpIo->ConnToken.Tcp6Token.CompletionToken);\r
+    }\r
     Status = EFI_TIMEOUT;\r
   } else {\r
     Status = TcpIo->ConnToken.Tcp4Token.CompletionToken.Status;\r
     Status = EFI_TIMEOUT;\r
   } else {\r
     Status = TcpIo->ConnToken.Tcp4Token.CompletionToken.Status;\r
@@ -597,9 +596,9 @@ TcpIoConnect (
   Accept the incomding request from the other endpoint of the TCP socket.\r
 \r
   @param[in, out]  TcpIo     The TcpIo wrapping the TCP socket.\r
   Accept the incomding request from the other endpoint of the TCP socket.\r
 \r
   @param[in, out]  TcpIo     The TcpIo wrapping the TCP socket.\r
-  @param[in]       Timeout   The time to wait for connection done.\r
+  @param[in]       Timeout   The time to wait for connection done. Set to NULL for infinite wait.\r
+\r
 \r
 \r
-  \r
   @retval EFI_SUCCESS            Connect to the other endpoint of the TCP socket\r
                                  successfully.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
   @retval EFI_SUCCESS            Connect to the other endpoint of the TCP socket\r
                                  successfully.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
@@ -607,7 +606,7 @@ TcpIoConnect (
                                  supported in the implementation.\r
 \r
   @retval EFI_TIMEOUT            Failed to connect to the other endpoint of the\r
                                  supported in the implementation.\r
 \r
   @retval EFI_TIMEOUT            Failed to connect to the other endpoint of the\r
-                                 TCP socket in the specified time period.                      \r
+                                 TCP socket in the specified time period.\r
   @retval Others                 Other errors as indicated.\r
 \r
 **/\r
   @retval Others                 Other errors as indicated.\r
 \r
 **/\r
@@ -615,7 +614,7 @@ EFI_STATUS
 EFIAPI\r
 TcpIoAccept (\r
   IN OUT TCP_IO             *TcpIo,\r
 EFIAPI\r
 TcpIoAccept (\r
   IN OUT TCP_IO             *TcpIo,\r
-  IN     EFI_EVENT          Timeout\r
+  IN     EFI_EVENT          Timeout        OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                Status;\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -646,7 +645,7 @@ TcpIoAccept (
     return Status;\r
   }\r
 \r
     return Status;\r
   }\r
 \r
-  while (!TcpIo->IsListenDone && EFI_ERROR (gBS->CheckEvent (Timeout))) {\r
+  while (!TcpIo->IsListenDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout)))) {\r
     if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
       Tcp4->Poll (Tcp4);\r
     } else {\r
     if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
       Tcp4->Poll (Tcp4);\r
     } else {\r
@@ -655,13 +654,18 @@ TcpIoAccept (
   }\r
 \r
   if (!TcpIo->IsListenDone) {\r
   }\r
 \r
   if (!TcpIo->IsListenDone) {\r
+    if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
+      Tcp4->Cancel (Tcp4, &TcpIo->ListenToken.Tcp4Token.CompletionToken);\r
+    } else {\r
+      Tcp6->Cancel (Tcp6, &TcpIo->ListenToken.Tcp6Token.CompletionToken);\r
+    }\r
     Status = EFI_TIMEOUT;\r
   } else {\r
     Status = TcpIo->ListenToken.Tcp4Token.CompletionToken.Status;\r
   }\r
 \r
   //\r
     Status = EFI_TIMEOUT;\r
   } else {\r
     Status = TcpIo->ListenToken.Tcp4Token.CompletionToken.Status;\r
   }\r
 \r
   //\r
-  // The new TCP instance handle created for the established connection is \r
+  // The new TCP instance handle created for the established connection is\r
   // in ListenToken.\r
   //\r
   if (!EFI_ERROR (Status)) {\r
   // in ListenToken.\r
   //\r
   if (!EFI_ERROR (Status)) {\r
@@ -670,7 +674,7 @@ TcpIoAccept (
     } else {\r
       ProtocolGuid = &gEfiTcp6ProtocolGuid;\r
     }\r
     } else {\r
       ProtocolGuid = &gEfiTcp6ProtocolGuid;\r
     }\r
-    \r
+\r
     Status = gBS->OpenProtocol (\r
                     TcpIo->ListenToken.Tcp4Token.NewChildHandle,\r
                     ProtocolGuid,\r
     Status = gBS->OpenProtocol (\r
                     TcpIo->ListenToken.Tcp4Token.NewChildHandle,\r
                     ProtocolGuid,\r
@@ -709,7 +713,7 @@ TcpIoReset (
   Tcp4               = NULL;\r
   Tcp6               = NULL;\r
 \r
   Tcp4               = NULL;\r
   Tcp6               = NULL;\r
 \r
-  if (TcpIo->TcpVersion == TCP_VERSION_4) { \r
+  if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
     TcpIo->CloseToken.Tcp4Token.AbortOnClose = TRUE;\r
     Tcp4 = TcpIo->Tcp.Tcp4;\r
     Status = Tcp4->Close (Tcp4, &TcpIo->CloseToken.Tcp4Token);\r
     TcpIo->CloseToken.Tcp4Token.AbortOnClose = TRUE;\r
     Tcp4 = TcpIo->Tcp.Tcp4;\r
     Status = Tcp4->Close (Tcp4, &TcpIo->CloseToken.Tcp4Token);\r
@@ -734,13 +738,13 @@ TcpIoReset (
   }\r
 }\r
 \r
   }\r
 }\r
 \r
-  \r
+\r
 /**\r
   Transmit the Packet to the other endpoint of the socket.\r
 \r
   @param[in]   TcpIo           The TcpIo wrapping the TCP socket.\r
   @param[in]   Packet          The packet to transmit.\r
 /**\r
   Transmit the Packet to the other endpoint of the socket.\r
 \r
   @param[in]   TcpIo           The TcpIo wrapping the TCP socket.\r
   @param[in]   Packet          The packet to transmit.\r
-  \r
+\r
   @retval EFI_SUCCESS            The packet is trasmitted.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
   @retval EFI_UNSUPPORTED        One or more of the control options are not\r
   @retval EFI_SUCCESS            The packet is trasmitted.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
   @retval EFI_UNSUPPORTED        One or more of the control options are not\r
@@ -769,7 +773,7 @@ TcpIoTransmit (
 \r
   if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
 \r
 \r
   if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
 \r
-    Size = sizeof (EFI_TCP4_TRANSMIT_DATA) + \r
+    Size = sizeof (EFI_TCP4_TRANSMIT_DATA) +\r
            (Packet->BlockOpNum - 1) * sizeof (EFI_TCP4_FRAGMENT_DATA);\r
   } else if (TcpIo->TcpVersion == TCP_VERSION_6) {\r
     Size = sizeof (EFI_TCP6_TRANSMIT_DATA) +\r
            (Packet->BlockOpNum - 1) * sizeof (EFI_TCP4_FRAGMENT_DATA);\r
   } else if (TcpIo->TcpVersion == TCP_VERSION_6) {\r
     Size = sizeof (EFI_TCP6_TRANSMIT_DATA) +\r
@@ -815,7 +819,7 @@ TcpIoTransmit (
     if (Tcp4 == NULL) {\r
       goto ON_EXIT;\r
     }\r
     if (Tcp4 == NULL) {\r
       goto ON_EXIT;\r
     }\r
-    \r
+\r
     Status  = Tcp4->Transmit (Tcp4, &TcpIo->TxToken.Tcp4Token);\r
   } else {\r
     TcpIo->TxToken.Tcp6Token.Packet.TxData = (EFI_TCP6_TRANSMIT_DATA *) Data;\r
     Status  = Tcp4->Transmit (Tcp4, &TcpIo->TxToken.Tcp4Token);\r
   } else {\r
     TcpIo->TxToken.Tcp6Token.Packet.TxData = (EFI_TCP6_TRANSMIT_DATA *) Data;\r
@@ -860,7 +864,7 @@ ON_EXIT:
   @param[in]       Packet      The buffer to hold the data copy from the socket rx buffer.\r
   @param[in]       AsyncMode   Is this receive asyncronous or not.\r
   @param[in]       Timeout     The time to wait for receiving the amount of data the Packet\r
   @param[in]       Packet      The buffer to hold the data copy from the socket rx buffer.\r
   @param[in]       AsyncMode   Is this receive asyncronous or not.\r
   @param[in]       Timeout     The time to wait for receiving the amount of data the Packet\r
-                               can hold.\r
+                               can hold. Set to NULL for infinite wait.\r
 \r
   @retval EFI_SUCCESS            The required amount of data is received from the socket.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
 \r
   @retval EFI_SUCCESS            The required amount of data is received from the socket.\r
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
@@ -877,7 +881,7 @@ TcpIoReceive (
   IN OUT TCP_IO             *TcpIo,\r
   IN     NET_BUF            *Packet,\r
   IN     BOOLEAN            AsyncMode,\r
   IN OUT TCP_IO             *TcpIo,\r
   IN     NET_BUF            *Packet,\r
   IN     BOOLEAN            AsyncMode,\r
-  IN     EFI_EVENT          Timeout\r
+  IN     EFI_EVENT          Timeout       OPTIONAL\r
   )\r
 {\r
   EFI_TCP4_PROTOCOL         *Tcp4;\r
   )\r
 {\r
   EFI_TCP4_PROTOCOL         *Tcp4;\r
@@ -919,7 +923,7 @@ TcpIoReceive (
     }\r
 \r
     if (Tcp6 == NULL) {\r
     }\r
 \r
     if (Tcp6 == NULL) {\r
-      return EFI_DEVICE_ERROR; \r
+      return EFI_DEVICE_ERROR;\r
     }\r
 \r
   } else {\r
     }\r
 \r
   } else {\r
@@ -951,11 +955,11 @@ TcpIoReceive (
     } else {\r
       Status = Tcp6->Receive (Tcp6, &TcpIo->RxToken.Tcp6Token);\r
     }\r
     } else {\r
       Status = Tcp6->Receive (Tcp6, &TcpIo->RxToken.Tcp6Token);\r
     }\r
-    \r
+\r
     if (EFI_ERROR (Status)) {\r
       goto ON_EXIT;\r
     }\r
     if (EFI_ERROR (Status)) {\r
       goto ON_EXIT;\r
     }\r
-    \r
+\r
     while (!TcpIo->IsRxDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout)))) {\r
       //\r
       // Poll until some data is received or an error occurs.\r
     while (!TcpIo->IsRxDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout)))) {\r
       //\r
       // Poll until some data is received or an error occurs.\r