/** @file\r
+ Interface function 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 - 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
http://opensource.org/licenses/bsd-license.php<BR>\r
@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 False The specific Event is not 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
BOOLEAN\r
@param Sock Pointer to the instance's socket.\r
@param Event The event to be checked.\r
\r
- @return The specific Event exists in one of socket's lists or not.\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
BOOLEAN\r
\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
**/\r
EFI_STATUS\r
SockDestroyChild (\r
- IN SOCKET *Sock\r
+ 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
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
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
)\r
{\r
SOCKET *Sock;\r
+ VOID *SockProtocol;\r
EFI_STATUS Status;\r
\r
//\r
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
// with a new protocol control block\r
//\r
Status = Sock->ProtoHandler (Sock, SOCK_ATTACH, NULL);\r
+ EfiReleaseLock (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
\r
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
- EfiReleaseLock (&(Sock->Lock));\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
SOCKET *Socket;\r
EFI_EVENT Event;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
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
SOCK_TOKEN *SockToken;\r
UINT32 DataLen;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
"Snd Data\n", Status));\r
\r
RemoveEntryList (&(SockToken->TokenList));\r
- gBS->FreePool (SockToken);\r
+ FreePool (SockToken);\r
}\r
}\r
\r
EFI_STATUS Status;\r
EFI_EVENT Event;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
}\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
{\r
EFI_STATUS Status;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
EFI_STATUS Status;\r
EFI_EVENT Event;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
}\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