/** @file\r
The driver binding and service binding protocol for IP4 driver.\r
\r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
\r
This program and the accompanying materials\r
IP4_PROTOCOL *IpInstance;\r
EFI_IP4_PROTOCOL *Ip4;\r
EFI_TPL OldTpl;\r
- INTN State;\r
\r
if ((This == NULL) || (ChildHandle == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
// when UDP driver is being stopped, it will destroy all\r
// the IP child it opens.\r
//\r
- if (IpInstance->State == IP4_STATE_DESTROY) {\r
+ if (IpInstance->InDestroy) {\r
gBS->RestoreTPL (OldTpl);\r
return EFI_SUCCESS;\r
}\r
\r
- State = IpInstance->State;\r
- IpInstance->State = IP4_STATE_DESTROY;\r
+ IpInstance->InDestroy = TRUE;\r
\r
//\r
// Close the Managed Network protocol.\r
);\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
if (EFI_ERROR (Status)) {\r
+ IpInstance->InDestroy = FALSE;\r
goto ON_ERROR;\r
}\r
\r
return EFI_SUCCESS;\r
\r
ON_ERROR:\r
- IpInstance->State = State;\r
gBS->RestoreTPL (OldTpl);\r
\r
return Status;\r
IpInstance->Signature = IP4_PROTOCOL_SIGNATURE;\r
CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto));\r
IpInstance->State = IP4_STATE_UNCONFIGED;\r
+ IpInstance->InDestroy = FALSE;\r
IpInstance->Service = IpSb;\r
\r
InitializeListHead (&IpInstance->Link);\r
Status = Ip4CleanProtocol (IpInstance);\r
\r
//\r
- // Don't change the state if it is DESTROY, consider the following\r
- // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,\r
+ // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,\r
// Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,\r
// the unload fails miserably.\r
//\r
/** @file\r
Ip4 internal functions and type defintions.\r
\r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
\r
This program and the accompanying materials\r
//\r
// The state of IP4 protocol. It starts from UNCONFIGED. if it is\r
// successfully configured, it goes to CONFIGED. if configure NULL\r
-// is called, it becomes UNCONFIGED again. If (partly) destroyed, it\r
-// becomes DESTROY.\r
+// is called, it becomes UNCONFIGED again.\r
//\r
#define IP4_STATE_UNCONFIGED 0\r
#define IP4_STATE_CONFIGED 1\r
-#define IP4_STATE_DESTROY 2\r
\r
//\r
// The state of IP4 service. It starts from UNSTARTED. It transits\r
EFI_HANDLE Handle;\r
INTN State;\r
\r
+ BOOLEAN InDestroy; \r
+\r
IP4_SERVICE *Service;\r
LIST_ENTRY Link; // Link to all the IP protocol from the service\r
\r
/** @file\r
Implementation of the Socket.\r
\r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\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
IN OUT SOCKET *Sock\r
)\r
{\r
- VOID *SockProtocol;\r
- EFI_GUID *ProtocolGuid;\r
- EFI_STATUS Status;\r
-\r
ASSERT (SockStream == Sock->Type);\r
\r
- if (Sock->DestroyCallback != NULL) {\r
- Sock->DestroyCallback (Sock, Sock->Context);\r
- }\r
-\r
//\r
// Flush the completion token buffered\r
// by sock and rcv, snd buffer\r
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
FreePool (Sock);\r
return ;\r
}\r
/** @file\r
Socket implementation header file.\r
\r
-Copyright (c) 2005 - 2006, Intel Corporation. All rights reserved.<BR>\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
#define _SOCK_IMPL_H_\r
\r
#include "Socket.h"\r
+#include "Tcp4Main.h"\r
\r
/**\r
Signal a event with the given status.\r
/** @file\r
Interface function of the Socket.\r
\r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\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
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
\r
Sock->InDestroy = TRUE;\r
\r
+ ProtoData = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
+ Tcb = ProtoData->TcpPcb;\r
+\r
+ ASSERT (Tcb != NULL);\r
+\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
\r
return EFI_ACCESS_DENIED;\r
}\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
//\r
// force protocol layer to detach the PCB\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
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
Tcp request dispatcher implementation.\r
\r
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\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
ASSERT (Tcb != NULL);\r
\r
Tcp4FlushPcb (Tcb);\r
-\r
- //\r
- // Close the IP protocol.\r
- //\r
- gBS->CloseProtocol (\r
- Tcb->IpInfo->ChildHandle,\r
- &gEfiIp4ProtocolGuid,\r
- ProtoData->TcpService->IpIo->Image,\r
- Sk->SockHandle\r
- );\r
\r
IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo);\r
\r