]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c
BaseTools/tools_def ARM: use softfloat target for CLANG3x
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / SockImpl.c
index 243cb681ac0b36b912d772ce990bd19b02202e51..adb5aa35cdf20771db9c6dcdcd18c9b5109e3130 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Implementation of the Socket.\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2017, 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\r
 http://opensource.org/licenses/bsd-license.php<BR>\r
@@ -33,7 +33,7 @@ SockTcpDataToRcv (
      OUT BOOLEAN        *IsUrg,\r
   IN     UINT32         BufLen\r
   );\r
-  \r
+\r
 /**\r
   Process the send token.\r
 \r
@@ -49,9 +49,10 @@ SockProcessSndToken (
   Supporting function for both SockImpl and SockInterface.\r
 \r
   @param Event             The Event this notify function registered to, ignored.\r
-  \r
+\r
 **/\r
 VOID\r
+EFIAPI\r
 SockFreeFoo (\r
   IN EFI_EVENT Event\r
   )\r
@@ -149,7 +150,7 @@ SockTcpDataToRcv (
   @param  Sock                  Pointer to the socket.\r
   @param  TcpRxData             Pointer to the application provided receive buffer.\r
   @param  RcvdBytes             The maximum length of the data can be copied.\r
-  @param  IsOOB                 If TURE the data is OOB, FALSE the data is normal.\r
+  @param  IsOOB                 If TRUE the data is OOB, FALSE the data is normal.\r
 \r
 **/\r
 VOID\r
@@ -215,7 +216,7 @@ SockProcessRcvToken (
 \r
   ASSERT (Sock != NULL);\r
 \r
-  ASSERT (SOCK_STREAM == Sock->Type);\r
+  ASSERT (SockStream == Sock->Type);\r
 \r
   RxData = RcvToken->Packet.RxData;\r
 \r
@@ -321,7 +322,7 @@ SockProcessTcpSndData (
 \r
   @param  Sock                  Pointer to the socket.\r
   @param  PendingTokenList      Pointer to the token list to be flushed.\r
-  \r
+\r
 **/\r
 VOID\r
 SockFlushPendingToken (\r
@@ -345,13 +346,13 @@ SockFlushPendingToken (
     SIGNAL_TOKEN (Token, Sock->SockError);\r
 \r
     RemoveEntryList (&(SockToken->TokenList));\r
-    gBS->FreePool (SockToken);\r
+    FreePool (SockToken);\r
   }\r
 }\r
 \r
 \r
 /**\r
-  Wake up the connection token while the connection is successfully established, \r
+  Wake up the connection token while the connection is successfully established,\r
   then try to process any pending send token.\r
 \r
   @param  Sock                  Pointer to the socket.\r
@@ -407,12 +408,12 @@ SockWakeListenToken (
     SIGNAL_TOKEN (&(ListenToken->CompletionToken), EFI_SUCCESS);\r
 \r
     RemoveEntryList (&SockToken->TokenList);\r
-    gBS->FreePool (SockToken);\r
+    FreePool (SockToken);\r
 \r
     RemoveEntryList (&Sock->ConnectionList);\r
 \r
     Parent->ConnCnt--;\r
-    DEBUG ((EFI_D_INFO, "SockWakeListenToken: accept a socket, now conncnt is %d", Parent->ConnCnt));\r
+    DEBUG ((EFI_D_NET, "SockWakeListenToken: accept a socket, now conncnt is %d", Parent->ConnCnt));\r
 \r
     Sock->Parent = NULL;\r
   }\r
@@ -457,7 +458,7 @@ SockWakeRcvToken (
     }\r
 \r
     RemoveEntryList (&(SockToken->TokenList));\r
-    gBS->FreePool (SockToken);\r
+    FreePool (SockToken);\r
     RcvdBytes -= TokenRcvdBytes;\r
   }\r
 }\r
@@ -481,7 +482,7 @@ SockProcessSndToken (
   EFI_TCP4_TRANSMIT_DATA  *TxData;\r
   EFI_STATUS              Status;\r
 \r
-  ASSERT ((Sock != NULL) && (SOCK_STREAM == Sock->Type));\r
+  ASSERT ((Sock != NULL) && (SockStream == Sock->Type));\r
 \r
   FreeSpace = SockGetFreeSpace (Sock, SOCK_SND_BUF);\r
 \r
@@ -535,7 +536,7 @@ OnError:
 \r
   RemoveEntryList (&SockToken->TokenList);\r
   SIGNAL_TOKEN (SockToken->Token, Status);\r
-  gBS->FreePool (SockToken);\r
+  FreePool (SockToken);\r
 }\r
 \r
 \r
@@ -557,7 +558,7 @@ SockCreate (
   EFI_STATUS  Status;\r
 \r
   ASSERT ((SockInitData != NULL) && (SockInitData->ProtoHandler != NULL));\r
-  ASSERT (SockInitData->Type == SOCK_STREAM);\r
+  ASSERT (SockInitData->Type == SockStream);\r
   ASSERT ((SockInitData->ProtoData != NULL) && (SockInitData->DataSize <= PROTO_RESERVED_LEN));\r
 \r
   Parent = SockInitData->Parent;\r
@@ -663,7 +664,7 @@ SockCreate (
     Parent->ConnCnt++;\r
 \r
     DEBUG (\r
-      (EFI_D_INFO,\r
+      (EFI_D_NET,\r
       "SockCreate: Create a new socket and add to parent, now conncnt is %d\n",\r
       Parent->ConnCnt)\r
       );\r
@@ -699,7 +700,7 @@ OnError:
     NetbufQueFree (Sock->RcvBuffer.DataQueue);\r
   }\r
 \r
-  gBS->FreePool (Sock);\r
+  FreePool (Sock);\r
 \r
   return NULL;\r
 }\r
@@ -716,15 +717,7 @@ SockDestroy (
   IN OUT SOCKET *Sock\r
   )\r
 {\r
-  VOID        *SockProtocol;\r
-  EFI_GUID    *ProtocolGuid;\r
-  EFI_STATUS  Status;\r
-\r
-  ASSERT (SOCK_STREAM == Sock->Type);\r
-\r
-  if (Sock->DestroyCallback != NULL) {\r
-    Sock->DestroyCallback (Sock, Sock->Context);\r
-  }\r
+  ASSERT (SockStream == Sock->Type);\r
 \r
   //\r
   // Flush the completion token buffered\r
@@ -738,7 +731,7 @@ SockDestroy (
 \r
   }\r
   //\r
-  // Destory the RcvBuffer Queue and SendBuffer Queue\r
+  // Destroy the RcvBuffer Queue and SendBuffer Queue\r
   //\r
   NetbufQueFree (Sock->RcvBuffer.DataQueue);\r
   NetbufQueFree (Sock->SndBuffer.DataQueue);\r
@@ -752,8 +745,8 @@ SockDestroy (
     (Sock->Parent->ConnCnt)--;\r
 \r
     DEBUG (\r
-      (EFI_D_INFO,\r
-      "SockDestory: Delete a unaccepted socket from parent"\r
+      (EFI_D_NET,\r
+      "SockDestroy: Delete a unaccepted socket from parent"\r
       "now conncnt is %d\n",\r
       Sock->Parent->ConnCnt)\r
       );\r
@@ -761,45 +754,7 @@ SockDestroy (
     Sock->Parent = NULL;\r
   }\r
 \r
-  //\r
-  // Set the protocol guid and driver binding handle\r
-  // in the light of Sock->SockType\r
-  //\r
-  ProtocolGuid = &gEfiTcp4ProtocolGuid;\r
-\r
-  //\r
-  // Retrieve the protocol installed on this sock\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  Sock->SockHandle,\r
-                  ProtocolGuid,\r
-                  &SockProtocol,\r
-                  Sock->DriverBinding,\r
-                  Sock->SockHandle,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-\r
-    DEBUG ((EFI_D_ERROR, "SockDestroy: Open protocol installed "\r
-      "on socket failed with %r\n", Status));\r
-\r
-    goto FreeSock;\r
-  }\r
-\r
-  //\r
-  // Uninstall the protocol installed on this sock\r
-  // in the light of Sock->SockType\r
-  //\r
-  gBS->UninstallMultipleProtocolInterfaces (\r
-        Sock->SockHandle,\r
-        ProtocolGuid,\r
-        SockProtocol,\r
-        NULL\r
-        );\r
-\r
-FreeSock:\r
-  gBS->FreePool (Sock);\r
+  FreePool (Sock);\r
   return ;\r
 }\r
 \r
@@ -873,13 +828,13 @@ SockConnFlush (
   Set the state of the socket.\r
 \r
   @param  Sock                  Pointer to the socket.\r
-  @param  State                 The new state to be set.\r
+  @param  State                 The new socket state to be set.\r
 \r
 **/\r
 VOID\r
 SockSetState (\r
   IN OUT SOCKET     *Sock,\r
-  IN     SOCK_STATE State\r
+  IN     UINT8      State\r
   )\r
 {\r
   Sock->State = State;\r
@@ -932,10 +887,10 @@ SockClone (
 \r
 \r
 /**\r
-  Called by the low layer protocol to indicate the socket a connection is \r
-  established. \r
-  \r
-  This function just changes the socket's state to SO_CONNECTED \r
+  Called by the low layer protocol to indicate the socket a connection is\r
+  established.\r
+\r
+  This function just changes the socket's state to SO_CONNECTED\r
   and signals the token used for connection establishment.\r
 \r
   @param  Sock                  Pointer to the socket associated with the\r
@@ -963,13 +918,13 @@ SockConnEstablished (
 \r
 /**\r
   Called by the low layer protocol to indicate the connection is closed.\r
-  \r
-  This function flushes the socket, sets the state to SO_CLOSED and signals \r
+\r
+  This function flushes the socket, sets the state to SO_CLOSED and signals\r
   the close token.\r
 \r
   @param  Sock                  Pointer to the socket associated with the closed\r
                                 connection.\r
-                                \r
+\r
 **/\r
 VOID\r
 SockConnClosed (\r
@@ -993,8 +948,8 @@ SockConnClosed (
 \r
 /**\r
   Called by low layer protocol to indicate that some data is sent or processed.\r
-   \r
-  This function trims the sent data in the socket send buffer, signals the data \r
+\r
+  This function trims the sent data in the socket send buffer, signals the data\r
   token if proper.\r
 \r
   @param  Sock                  Pointer to the socket.\r
@@ -1032,7 +987,7 @@ SockDataSent (
       RemoveEntryList (&(SockToken->TokenList));\r
       SIGNAL_TOKEN (SndToken, EFI_SUCCESS);\r
       Count -= SockToken->RemainDataLen;\r
-      gBS->FreePool (SockToken);\r
+      FreePool (SockToken);\r
     } else {\r
 \r
       SockToken->RemainDataLen -= Count;\r
@@ -1070,7 +1025,7 @@ SockGetDataToSend (
   IN UINT8       *Dest\r
   )\r
 {\r
-  ASSERT ((Sock != NULL) && SOCK_STREAM == Sock->Type);\r
+  ASSERT ((Sock != NULL) && SockStream == Sock->Type);\r
 \r
   return NetbufQueCopy (\r
           Sock->SndBuffer.DataQueue,\r
@@ -1083,8 +1038,8 @@ SockGetDataToSend (
 \r
 /**\r
   Called by the low layer protocol to deliver received data to socket layer.\r
-  \r
-  This function will append the data to the socket receive buffer, set ther \r
+\r
+  This function will append the data to the socket receive buffer, set ther\r
   urgent data length and then check if any receive token can be signaled.\r
 \r
   @param  Sock                  Pointer to the socket.\r
@@ -1152,47 +1107,12 @@ SockGetFreeSpace (
 }\r
 \r
 \r
-/**\r
-  Signal the receive token with the specific error or\r
-  set socket error code after error is received.\r
-\r
-  @param  Sock                  Pointer to the socket.\r
-  @param  Error                 The error code received.\r
-\r
-**/\r
-VOID\r
-SockRcvdErr (\r
-  IN OUT SOCKET       *Sock,\r
-  IN     EFI_STATUS   Error\r
-  )\r
-{\r
-  SOCK_TOKEN  *SockToken;\r
-\r
-  if (!IsListEmpty (&Sock->RcvTokenList)) {\r
-\r
-    SockToken = NET_LIST_HEAD (\r
-                  &Sock->RcvTokenList,\r
-                  SOCK_TOKEN,\r
-                  TokenList\r
-                  );\r
-\r
-    RemoveEntryList (&SockToken->TokenList);\r
-\r
-    SIGNAL_TOKEN (SockToken->Token, Error);\r
-\r
-    gBS->FreePool (SockToken);\r
-  } else {\r
-\r
-    SOCK_ERROR (Sock, Error);\r
-  }\r
-}\r
-\r
 \r
 /**\r
-  Called by the low layer protocol to indicate that there will be no more data \r
+  Called by the low layer protocol to indicate that there will be no more data\r
   from the communication peer.\r
-  \r
-  This function set the socket's state to SO_NO_MORE_DATA and signal all queued \r
+\r
+  This function set the socket's state to SO_NO_MORE_DATA and signal all queued\r
   IO tokens with the error status EFI_CONNECTION_FIN.\r
 \r
   @param  Sock                  Pointer to the socket.\r
@@ -1256,7 +1176,7 @@ SockBufFirst (
   @param  SockEntry             Pointer to the buffer block prior to the required\r
                                 one.\r
 \r
-  @return Pointer to the buffer block next to SockEntry. NULL if SockEntry is \r
+  @return Pointer to the buffer block next to SockEntry. NULL if SockEntry is\r
           the tail or head entry.\r
 \r
 **/\r