]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c
MdeModulePkg Tcp4Dxe: Remove redundant functions
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / SockInterface.c
index d17bfa8b9d22c7ea1c679ece807597505c5140bc..cd20b8bcb2dd14cbb76126681ef54f8b112b07a1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface function of the Socket.\r
 \r
-Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2018, 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
@@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @param  List                 Pointer to the token list to be searched.\r
   @param  Event                The event to be checked.\r
 \r
-  @retval  TRUE                The specific Event exists in the List. \r
+  @retval  TRUE                The specific Event exists in the List.\r
   @retval  FALSE               The specific Event is not in the List.\r
 \r
 **/\r
@@ -58,7 +58,7 @@ SockTokenExistedInList (
   @param  Sock                 Pointer to the instance's socket.\r
   @param  Event                The event to be checked.\r
 \r
-  @retval  TRUE                The Event exists in related socket's lists. \r
+  @retval  TRUE                The Event exists in related socket's lists.\r
   @retval  FALSE               The Event is not in related socket's lists.\r
 \r
 **/\r
@@ -131,7 +131,7 @@ SockBufferToken (
 \r
 \r
 /**\r
-  Destory the socket Sock and its associated protocol control block.\r
+  Destroy the socket Sock and its associated protocol control block.\r
 \r
   @param  Sock                 The socket to be destroyed.\r
 \r
@@ -144,15 +144,66 @@ SockDestroyChild (
   IN SOCKET *Sock\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS       Status;\r
+  TCP4_PROTO_DATA  *ProtoData;\r
+  TCP_CB           *Tcb;\r
+  VOID             *SockProtocol;\r
 \r
   ASSERT ((Sock != NULL) && (Sock->ProtoHandler != NULL));\r
 \r
-  if (Sock->IsDestroyed) {\r
+  if (Sock->InDestroy) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  Sock->IsDestroyed = TRUE;\r
+  Sock->InDestroy = TRUE;\r
+\r
+  ProtoData = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
+  Tcb       = ProtoData->TcpPcb;\r
+\r
+  ASSERT (Tcb != NULL);\r
+\r
+  //\r
+  // Close the IP protocol.\r
+  //\r
+  gBS->CloseProtocol (\r
+         Tcb->IpInfo->ChildHandle,\r
+         &gEfiIp4ProtocolGuid,\r
+         ProtoData->TcpService->IpIo->Image,\r
+         Sock->SockHandle\r
+         );\r
+\r
+  if (Sock->DestroyCallback != NULL) {\r
+    Sock->DestroyCallback (Sock, Sock->Context);\r
+  }\r
+\r
+  //\r
+  // Retrieve the protocol installed on this sock\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Sock->SockHandle,\r
+                  &gEfiTcp4ProtocolGuid,\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, "SockDestroyChild: Open protocol installed "\r
+      "on socket failed with %r\n", Status));\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
+        &gEfiTcp4ProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
 \r
   Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
   if (EFI_ERROR (Status)) {\r
@@ -173,7 +224,7 @@ SockDestroyChild (
     DEBUG ((EFI_D_ERROR, "SockDestroyChild: Protocol detach socket"\r
       " failed with %r\n", Status));\r
 \r
-    Sock->IsDestroyed = FALSE;\r
+    Sock->InDestroy = FALSE;\r
   } else if (SOCK_IS_CONFIGURED (Sock)) {\r
 \r
     SockConnFlush (Sock);\r
@@ -199,7 +250,7 @@ SockDestroyChild (
   data ProtoData.\r
 \r
   @param  SockInitData         Inital data to setting the socket.\r
-  \r
+\r
   @return Pointer to the newly created socket. If NULL, error condition occured.\r
 \r
 **/\r
@@ -209,6 +260,7 @@ SockCreateChild (
   )\r
 {\r
   SOCKET      *Sock;\r
+  VOID        *SockProtocol;\r
   EFI_STATUS  Status;\r
 \r
   //\r
@@ -229,8 +281,7 @@ SockCreateChild (
     DEBUG ((EFI_D_ERROR, "SockCreateChild: Get the lock to "\r
       "access socket failed with %r\n", Status));\r
 \r
-    SockDestroy (Sock);\r
-    return NULL;\r
+    goto ERROR;\r
   }\r
   //\r
   // inform the protocol layer to attach the socket\r
@@ -243,11 +294,36 @@ SockCreateChild (
     DEBUG ((EFI_D_ERROR, "SockCreateChild: Protocol failed to"\r
       " attach a socket with %r\n", Status));\r
 \r
-    SockDestroy (Sock);\r
-    Sock = NULL;\r
+    goto ERROR;\r
   }\r
 \r
   return Sock;\r
+\r
+ERROR:\r
+\r
+  if (Sock->DestroyCallback != NULL) {\r
+    Sock->DestroyCallback (Sock, Sock->Context);\r
+  }\r
+\r
+  gBS->OpenProtocol (\r
+         Sock->SockHandle,\r
+         &gEfiTcp4ProtocolGuid,\r
+         &SockProtocol,\r
+         Sock->DriverBinding,\r
+         Sock->SockHandle,\r
+         EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+         );\r
+  //\r
+  // Uninstall the protocol installed on this sock\r
+  //\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+        Sock->SockHandle,\r
+        &gEfiTcp4ProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
+   SockDestroy (Sock);\r
+   return NULL;\r
 }\r
 \r
 \r
@@ -453,7 +529,7 @@ SockAccept (
       Socket->Parent->ConnCnt--;\r
 \r
       DEBUG (\r
-        (EFI_D_INFO,\r
+        (EFI_D_NET,\r
         "SockAccept: Accept a socket, now conncount is %d",\r
         Socket->Parent->ConnCnt)\r
         );\r
@@ -697,11 +773,7 @@ SockRcv (
   }\r
 \r
   if (RcvdBytes != 0) {\r
-    Status = SockProcessRcvToken (Sock, RcvToken);\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      goto Exit;\r
-    }\r
+    SockProcessRcvToken (Sock, RcvToken);\r
 \r
     Status = Sock->ProtoHandler (Sock, SOCK_CONSUMED, NULL);\r
   } else {\r
@@ -866,48 +938,7 @@ SockGetMode (
 }\r
 \r
 \r
-/**\r
-  Configure the low level protocol to join a multicast group for\r
-  this socket's connection.\r
-\r
-  @param  Sock                 Pointer to the socket of the connection to join the\r
-                               specific multicast group.\r
-  @param  GroupInfo            Pointer to the multicast group info.\r
-\r
-  @retval EFI_SUCCESS          The configuration is done successfully.\r
-  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.\r
-  @retval EFI_NOT_STARTED      The socket is not configured.\r
-\r
-**/\r
-EFI_STATUS\r
-SockGroup (\r
-  IN SOCKET *Sock,\r
-  IN VOID   *GroupInfo\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-\r
-  Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
-\r
-  if (EFI_ERROR (Status)) {\r
-\r
-    DEBUG ((EFI_D_ERROR, "SockGroup: Get the access for socket"\r
-      " failed with %r", Status));\r
-\r
-    return EFI_ACCESS_DENIED;\r
-  }\r
-\r
-  if (SOCK_IS_UNCONFIGURED (Sock)) {\r
-    Status = EFI_NOT_STARTED;\r
-    goto Exit;\r
-  }\r
-\r
-  Status = Sock->ProtoHandler (Sock, SOCK_GROUP, GroupInfo);\r
 \r
-Exit:\r
-  EfiReleaseLock (&(Sock->Lock));\r
-  return Status;\r
-}\r
 \r
 \r
 /**\r