2 The driver binding and service binding protocol for the TCP driver.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 UINT16 mTcp4RandomPort
;
13 UINT16 mTcp6RandomPort
;
15 TCP_HEARTBEAT_TIMER mTcpTimer
= {
20 EFI_TCP4_PROTOCOL gTcp4ProtocolTemplate
= {
33 EFI_TCP6_PROTOCOL gTcp6ProtocolTemplate
= {
45 SOCK_INIT_DATA mTcpDefaultSockData
= {
54 TcpCreateSocketCallback
,
55 TcpDestroySocketCallback
,
63 EFI_DRIVER_BINDING_PROTOCOL gTcp4DriverBinding
= {
64 Tcp4DriverBindingSupported
,
65 Tcp4DriverBindingStart
,
66 Tcp4DriverBindingStop
,
72 EFI_DRIVER_BINDING_PROTOCOL gTcp6DriverBinding
= {
73 Tcp6DriverBindingSupported
,
74 Tcp6DriverBindingStart
,
75 Tcp6DriverBindingStop
,
81 EFI_SERVICE_BINDING_PROTOCOL gTcpServiceBinding
= {
82 TcpServiceBindingCreateChild
,
83 TcpServiceBindingDestroyChild
88 Create and start the heartbeat timer for the TCP driver.
90 @retval EFI_SUCCESS The timer was successfully created and started.
91 @retval other The timer was not created.
101 Status
= EFI_SUCCESS
;
103 if (mTcpTimer
.RefCnt
== 0) {
105 Status
= gBS
->CreateEvent (
106 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
110 &mTcpTimer
.TimerEvent
112 if (!EFI_ERROR (Status
)) {
114 Status
= gBS
->SetTimer (
115 mTcpTimer
.TimerEvent
,
117 (UINT64
) (TICKS_PER_SECOND
/ TCP_TICK_HZ
)
122 if (!EFI_ERROR (Status
)) {
131 Stop and destroy the heartbeat timer for TCP driver.
139 ASSERT (mTcpTimer
.RefCnt
> 0);
143 if (mTcpTimer
.RefCnt
> 0) {
147 gBS
->SetTimer (mTcpTimer
.TimerEvent
, TimerCancel
, 0);
148 gBS
->CloseEvent (mTcpTimer
.TimerEvent
);
149 mTcpTimer
.TimerEvent
= NULL
;
153 The entry point for Tcp driver, which is used to install Tcp driver on the ImageHandle.
155 @param[in] ImageHandle The firmware allocated handle for this driver image.
156 @param[in] SystemTable Pointer to the EFI system table.
158 @retval EFI_SUCCESS The driver loaded.
159 @retval other The driver did not load.
164 TcpDriverEntryPoint (
165 IN EFI_HANDLE ImageHandle
,
166 IN EFI_SYSTEM_TABLE
*SystemTable
173 // Install the TCP Driver Binding Protocol
175 Status
= EfiLibInstallDriverBindingComponentName2 (
183 if (EFI_ERROR (Status
)) {
188 // Install the TCP Driver Binding Protocol
190 Status
= EfiLibInstallDriverBindingComponentName2 (
198 if (EFI_ERROR (Status
)) {
199 EfiLibUninstallDriverBindingComponentName2 (
208 // Initialize ISS and random port.
210 Seed
= NetRandomInitSeed ();
211 mTcpGlobalIss
= NET_RANDOM (Seed
) % mTcpGlobalIss
;
212 mTcp4RandomPort
= (UINT16
) (TCP_PORT_KNOWN
+ (NET_RANDOM (Seed
) % TCP_PORT_KNOWN
));
213 mTcp6RandomPort
= mTcp4RandomPort
;
219 Create a new TCP4 or TCP6 driver service binding protocol
221 @param[in] Controller Controller handle of device to bind driver to.
222 @param[in] Image The TCP driver's image handle.
223 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
225 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
226 @retval EFI_SUCCESS A new IP6 service binding private was created.
231 IN EFI_HANDLE Controller
,
237 EFI_GUID
*IpServiceBindingGuid
;
238 EFI_GUID
*TcpServiceBindingGuid
;
239 TCP_SERVICE_DATA
*TcpServiceData
;
240 IP_IO_OPEN_DATA OpenData
;
242 if (IpVersion
== IP_VERSION_4
) {
243 IpServiceBindingGuid
= &gEfiIp4ServiceBindingProtocolGuid
;
244 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
246 IpServiceBindingGuid
= &gEfiIp6ServiceBindingProtocolGuid
;
247 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
250 Status
= gBS
->OpenProtocol (
252 TcpServiceBindingGuid
,
256 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
258 if (!EFI_ERROR (Status
)) {
259 return EFI_ALREADY_STARTED
;
262 Status
= gBS
->OpenProtocol (
264 IpServiceBindingGuid
,
268 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
270 if (EFI_ERROR (Status
)) {
271 return EFI_UNSUPPORTED
;
275 // Create the TCP service data.
277 TcpServiceData
= AllocateZeroPool (sizeof (TCP_SERVICE_DATA
));
278 if (TcpServiceData
== NULL
) {
279 return EFI_OUT_OF_RESOURCES
;
282 TcpServiceData
->Signature
= TCP_DRIVER_SIGNATURE
;
283 TcpServiceData
->ControllerHandle
= Controller
;
284 TcpServiceData
->DriverBindingHandle
= Image
;
285 TcpServiceData
->IpVersion
= IpVersion
;
287 &TcpServiceData
->ServiceBinding
,
289 sizeof (EFI_SERVICE_BINDING_PROTOCOL
)
292 TcpServiceData
->IpIo
= IpIoCreate (Image
, Controller
, IpVersion
);
293 if (TcpServiceData
->IpIo
== NULL
) {
294 Status
= EFI_OUT_OF_RESOURCES
;
299 InitializeListHead (&TcpServiceData
->SocketList
);
300 ZeroMem (&OpenData
, sizeof (IP_IO_OPEN_DATA
));
302 if (IpVersion
== IP_VERSION_4
) {
304 &OpenData
.IpConfigData
.Ip4CfgData
,
305 &mIp4IoDefaultIpConfigData
,
306 sizeof (EFI_IP4_CONFIG_DATA
)
308 OpenData
.IpConfigData
.Ip4CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
311 &OpenData
.IpConfigData
.Ip6CfgData
,
312 &mIp6IoDefaultIpConfigData
,
313 sizeof (EFI_IP6_CONFIG_DATA
)
315 OpenData
.IpConfigData
.Ip6CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
318 OpenData
.PktRcvdNotify
= TcpRxCallback
;
319 Status
= IpIoOpen (TcpServiceData
->IpIo
, &OpenData
);
320 if (EFI_ERROR (Status
)) {
324 Status
= TcpCreateTimer ();
325 if (EFI_ERROR (Status
)) {
329 Status
= gBS
->InstallMultipleProtocolInterfaces (
331 TcpServiceBindingGuid
,
332 &TcpServiceData
->ServiceBinding
,
335 if (EFI_ERROR (Status
)) {
345 if (TcpServiceData
->IpIo
!= NULL
) {
346 IpIoDestroy (TcpServiceData
->IpIo
);
347 TcpServiceData
->IpIo
= NULL
;
350 FreePool (TcpServiceData
);
356 Callback function which provided by user to remove one node in NetDestroyLinkList process.
358 @param[in] Entry The entry to be removed.
359 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
361 @retval EFI_SUCCESS The entry has been removed successfully.
362 @retval Others Fail to remove the entry.
367 TcpDestroyChildEntryInHandleBuffer (
368 IN LIST_ENTRY
*Entry
,
373 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
374 UINTN NumberOfChildren
;
375 EFI_HANDLE
*ChildHandleBuffer
;
377 if (Entry
== NULL
|| Context
== NULL
) {
378 return EFI_INVALID_PARAMETER
;
381 Sock
= NET_LIST_USER_STRUCT_S (Entry
, SOCKET
, Link
, SOCK_SIGNATURE
);
382 ServiceBinding
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
383 NumberOfChildren
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
384 ChildHandleBuffer
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
386 if (!NetIsInHandleBuffer (Sock
->SockHandle
, NumberOfChildren
, ChildHandleBuffer
)) {
390 return ServiceBinding
->DestroyChild (ServiceBinding
, Sock
->SockHandle
);
394 Destroy a TCP6 or TCP4 service binding instance. It will release all
395 the resources allocated by the instance.
397 @param[in] Controller Controller handle of device to bind driver to.
398 @param[in] ImageHandle The TCP driver's image handle.
399 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
400 of children is zero stop the entire bus driver.
401 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
402 if NumberOfChildren is 0.
403 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6
405 @retval EFI_SUCCESS The resources used by the instance were cleaned up.
406 @retval Others Failed to clean up some of the resources.
411 IN EFI_HANDLE Controller
,
412 IN EFI_HANDLE ImageHandle
,
413 IN UINTN NumberOfChildren
,
414 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
,
418 EFI_HANDLE NicHandle
;
419 EFI_GUID
*IpProtocolGuid
;
420 EFI_GUID
*ServiceBindingGuid
;
421 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
422 TCP_SERVICE_DATA
*TcpServiceData
;
425 TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
427 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
429 if (IpVersion
== IP_VERSION_4
) {
430 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
431 ServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
433 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
434 ServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
437 NicHandle
= NetLibGetNicHandle (Controller
, IpProtocolGuid
);
438 if (NicHandle
== NULL
) {
442 Status
= gBS
->OpenProtocol (
445 (VOID
**) &ServiceBinding
,
448 EFI_OPEN_PROTOCOL_GET_PROTOCOL
450 if (EFI_ERROR (Status
)) {
451 return EFI_DEVICE_ERROR
;
454 TcpServiceData
= TCP_SERVICE_FROM_THIS (ServiceBinding
);
456 if (NumberOfChildren
!= 0) {
457 List
= &TcpServiceData
->SocketList
;
458 Context
.ServiceBinding
= ServiceBinding
;
459 Context
.NumberOfChildren
= NumberOfChildren
;
460 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
461 Status
= NetDestroyLinkList (
463 TcpDestroyChildEntryInHandleBuffer
,
467 } else if (IsListEmpty (&TcpServiceData
->SocketList
)) {
469 // Uninstall TCP servicebinding protocol
471 gBS
->UninstallMultipleProtocolInterfaces (
479 // Destroy the IpIO consumed by TCP driver
481 IpIoDestroy (TcpServiceData
->IpIo
);
482 TcpServiceData
->IpIo
= NULL
;
485 // Destroy the heartbeat timer.
490 // Release the TCP service data
492 FreePool (TcpServiceData
);
494 Status
= EFI_SUCCESS
;
501 Test to see if this driver supports ControllerHandle.
503 @param[in] This Protocol instance pointer.
504 @param[in] ControllerHandle Handle of device to test.
505 @param[in] RemainingDevicePath Optional parameter use to pick a specific
506 child device to start.
508 @retval EFI_SUCCESS This driver supports this device.
509 @retval EFI_ALREADY_STARTED This driver is already running on this device.
510 @retval other This driver does not support this device.
515 Tcp4DriverBindingSupported (
516 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
517 IN EFI_HANDLE ControllerHandle
,
518 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
524 // Test for the Tcp4ServiceBinding Protocol
526 Status
= gBS
->OpenProtocol (
528 &gEfiTcp4ServiceBindingProtocolGuid
,
530 This
->DriverBindingHandle
,
532 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
534 if (!EFI_ERROR (Status
)) {
535 return EFI_ALREADY_STARTED
;
539 // Test for the Ip4ServiceBinding Protocol
541 Status
= gBS
->OpenProtocol (
543 &gEfiIp4ServiceBindingProtocolGuid
,
545 This
->DriverBindingHandle
,
547 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
553 Start this driver on ControllerHandle.
555 @param[in] This Protocol instance pointer.
556 @param[in] ControllerHandle Handle of device to bind driver to.
557 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
560 @retval EFI_SUCCESS The driver is added to ControllerHandle.
561 @retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
563 @retval other The driver cannot be added to ControllerHandle.
568 Tcp4DriverBindingStart (
569 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
570 IN EFI_HANDLE ControllerHandle
,
571 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
576 Status
= TcpCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_4
);
577 if ((Status
== EFI_ALREADY_STARTED
) || (Status
== EFI_UNSUPPORTED
)) {
578 Status
= EFI_SUCCESS
;
585 Stop this driver on ControllerHandle.
587 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
588 @param[in] ControllerHandle A handle to the device being stopped. The handle must
589 support a bus specific I/O protocol for the driver
590 to use to stop the device.
591 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
592 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
593 if NumberOfChildren is 0.
595 @retval EFI_SUCCESS The device was stopped.
596 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
601 Tcp4DriverBindingStop (
602 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
603 IN EFI_HANDLE ControllerHandle
,
604 IN UINTN NumberOfChildren
,
605 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
608 return TcpDestroyService (
610 This
->DriverBindingHandle
,
618 Test to see if this driver supports ControllerHandle.
620 @param[in] This Protocol instance pointer.
621 @param[in] ControllerHandle Handle of device to test.
622 @param[in] RemainingDevicePath Optional parameter use to pick a specific
623 child device to start.
625 @retval EFI_SUCCESS This driver supports this device.
626 @retval EFI_ALREADY_STARTED This driver is already running on this device.
627 @retval other This driver does not support this device.
632 Tcp6DriverBindingSupported (
633 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
634 IN EFI_HANDLE ControllerHandle
,
635 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
641 // Test for the Tcp6ServiceBinding Protocol
643 Status
= gBS
->OpenProtocol (
645 &gEfiTcp6ServiceBindingProtocolGuid
,
647 This
->DriverBindingHandle
,
649 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
651 if (!EFI_ERROR (Status
)) {
652 return EFI_ALREADY_STARTED
;
656 // Test for the Ip6ServiceBinding Protocol
658 Status
= gBS
->OpenProtocol (
660 &gEfiIp6ServiceBindingProtocolGuid
,
662 This
->DriverBindingHandle
,
664 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
670 Start this driver on ControllerHandle.
672 @param[in] This Protocol instance pointer.
673 @param[in] ControllerHandle Handle of device to bind driver to.
674 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
677 @retval EFI_SUCCESS The driver is added to ControllerHandle.
678 @retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
680 @retval other The driver cannot be added to ControllerHandle.
685 Tcp6DriverBindingStart (
686 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
687 IN EFI_HANDLE ControllerHandle
,
688 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
693 Status
= TcpCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_6
);
694 if ((Status
== EFI_ALREADY_STARTED
) || (Status
== EFI_UNSUPPORTED
)) {
695 Status
= EFI_SUCCESS
;
702 Stop this driver on ControllerHandle.
704 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
705 @param[in] ControllerHandle A handle to the device being stopped. The handle must
706 support a bus specific I/O protocol for the driver
707 to use to stop the device.
708 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
709 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
710 if NumberOfChildren is 0.
712 @retval EFI_SUCCESS The device was stopped.
713 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
718 Tcp6DriverBindingStop (
719 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
720 IN EFI_HANDLE ControllerHandle
,
721 IN UINTN NumberOfChildren
,
722 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
725 return TcpDestroyService (
727 This
->DriverBindingHandle
,
735 The Callback function called after the TCP socket was created.
737 @param[in] This Pointer to the socket just created
738 @param[in] Context Context of the socket
740 @retval EFI_SUCCESS This protocol installed successfully.
741 @retval other An error occurred.
745 TcpCreateSocketCallback (
751 TCP_SERVICE_DATA
*TcpServiceData
;
752 EFI_GUID
*IpProtocolGuid
;
755 if (This
->IpVersion
== IP_VERSION_4
) {
756 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
758 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
761 TcpServiceData
= ((TCP_PROTO_DATA
*) This
->ProtoReserved
)->TcpService
;
764 // Open the default IP protocol of IP_IO BY_DRIVER.
766 Status
= gBS
->OpenProtocol (
767 TcpServiceData
->IpIo
->ChildHandle
,
770 TcpServiceData
->DriverBindingHandle
,
772 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
774 if (EFI_ERROR (Status
)) {
779 // Open the device path on the handle where service binding resides on.
781 Status
= gBS
->OpenProtocol (
782 TcpServiceData
->ControllerHandle
,
783 &gEfiDevicePathProtocolGuid
,
784 (VOID
**) &This
->ParentDevicePath
,
785 TcpServiceData
->DriverBindingHandle
,
787 EFI_OPEN_PROTOCOL_GET_PROTOCOL
789 if (EFI_ERROR (Status
)) {
791 TcpServiceData
->IpIo
->ChildHandle
,
793 TcpServiceData
->DriverBindingHandle
,
798 // Insert this socket into the SocketList.
800 InsertTailList (&TcpServiceData
->SocketList
, &This
->Link
);
807 The callback function called before the TCP socket was to be destroyed.
809 @param[in] This The TCP socket to be destroyed.
810 @param[in] Context The context of the socket.
814 TcpDestroySocketCallback (
819 TCP_SERVICE_DATA
*TcpServiceData
;
820 EFI_GUID
*IpProtocolGuid
;
822 if (This
->IpVersion
== IP_VERSION_4
) {
823 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
825 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
828 TcpServiceData
= ((TCP_PROTO_DATA
*) This
->ProtoReserved
)->TcpService
;
831 // Remove this node from the list.
833 RemoveEntryList (&This
->Link
);
836 // Close the IP protocol.
839 TcpServiceData
->IpIo
->ChildHandle
,
841 TcpServiceData
->DriverBindingHandle
,
847 Creates a child handle with a set of TCP services.
849 The CreateChild() function installs a protocol on ChildHandle.
850 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
851 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
853 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
854 @param[in, out] ChildHandle Pointer to the handle of the child to create.
855 If it is NULL, then a new handle is created.
856 If it is a pointer to an existing UEFI handle,
857 then the protocol is added to the existing UEFI handle.
859 @retval EFI_SUCCESS The protocol was added to ChildHandle.
860 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
861 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
863 @retval other The child handle was not created.
868 TcpServiceBindingCreateChild (
869 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
870 IN OUT EFI_HANDLE
*ChildHandle
874 TCP_SERVICE_DATA
*TcpServiceData
;
875 TCP_PROTO_DATA TcpProto
;
879 if (NULL
== This
|| NULL
== ChildHandle
) {
880 return EFI_INVALID_PARAMETER
;
883 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
885 Status
= EFI_SUCCESS
;
886 TcpServiceData
= TCP_SERVICE_FROM_THIS (This
);
887 TcpProto
.TcpService
= TcpServiceData
;
888 TcpProto
.TcpPcb
= NULL
;
891 // Create a tcp instance with default Tcp default
892 // sock init data and TcpProto
894 mTcpDefaultSockData
.ProtoData
= &TcpProto
;
895 mTcpDefaultSockData
.DataSize
= sizeof (TCP_PROTO_DATA
);
896 mTcpDefaultSockData
.DriverBinding
= TcpServiceData
->DriverBindingHandle
;
897 mTcpDefaultSockData
.IpVersion
= TcpServiceData
->IpVersion
;
899 if (TcpServiceData
->IpVersion
== IP_VERSION_4
) {
900 mTcpDefaultSockData
.Protocol
= &gTcp4ProtocolTemplate
;
902 mTcpDefaultSockData
.Protocol
= &gTcp6ProtocolTemplate
;
905 Sock
= SockCreateChild (&mTcpDefaultSockData
);
909 "TcpDriverBindingCreateChild: No resource to create a Tcp Child\n")
912 Status
= EFI_OUT_OF_RESOURCES
;
914 *ChildHandle
= Sock
->SockHandle
;
917 mTcpDefaultSockData
.ProtoData
= NULL
;
919 gBS
->RestoreTPL (OldTpl
);
924 Destroys a child handle with a set of TCP services.
926 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
927 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
928 last protocol on ChildHandle, then ChildHandle is destroyed.
930 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
931 @param ChildHandle Handle of the child to be destroyed.
933 @retval EFI_SUCCESS The protocol was removed from ChildHandle.
934 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
935 @retval EFI_INVALID_PARAMETER Child handle is NULL.
936 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
937 because its services are being used.
938 @retval other The child handle was not destroyed.
943 TcpServiceBindingDestroyChild (
944 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
945 IN EFI_HANDLE ChildHandle
952 if (NULL
== This
|| NULL
== ChildHandle
) {
953 return EFI_INVALID_PARAMETER
;
957 // retrieve the Tcp4 protocol from ChildHandle
959 Status
= gBS
->OpenProtocol (
961 &gEfiTcp4ProtocolGuid
,
963 gTcp4DriverBinding
.DriverBindingHandle
,
965 EFI_OPEN_PROTOCOL_GET_PROTOCOL
967 if (EFI_ERROR (Status
)) {
969 // No Tcp4, try the Tcp6 protocol
971 Status
= gBS
->OpenProtocol (
973 &gEfiTcp6ProtocolGuid
,
975 gTcp6DriverBinding
.DriverBindingHandle
,
977 EFI_OPEN_PROTOCOL_GET_PROTOCOL
979 if (EFI_ERROR (Status
)) {
980 Status
= EFI_UNSUPPORTED
;
984 if (!EFI_ERROR (Status
)) {
986 // destroy this sock and related Tcp protocol control
989 Sock
= SOCK_FROM_THIS (Tcp
);
991 SockDestroyChild (Sock
);