2 The driver binding and service binding protocol for the TCP driver.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 UINT16 mTcp4RandomPort
;
19 UINT16 mTcp6RandomPort
;
21 TCP_HEARTBEAT_TIMER mTcpTimer
= {
26 EFI_TCP4_PROTOCOL gTcp4ProtocolTemplate
= {
39 EFI_TCP6_PROTOCOL gTcp6ProtocolTemplate
= {
51 SOCK_INIT_DATA mTcpDefaultSockData
= {
60 TcpCreateSocketCallback
,
61 TcpDestroySocketCallback
,
69 EFI_DRIVER_BINDING_PROTOCOL gTcp4DriverBinding
= {
70 Tcp4DriverBindingSupported
,
71 Tcp4DriverBindingStart
,
72 Tcp4DriverBindingStop
,
78 EFI_DRIVER_BINDING_PROTOCOL gTcp6DriverBinding
= {
79 Tcp6DriverBindingSupported
,
80 Tcp6DriverBindingStart
,
81 Tcp6DriverBindingStop
,
87 EFI_SERVICE_BINDING_PROTOCOL gTcpServiceBinding
= {
88 TcpServiceBindingCreateChild
,
89 TcpServiceBindingDestroyChild
94 Create and start the heartbeat timer for the TCP driver.
96 @retval EFI_SUCCESS The timer was successfully created and started.
97 @retval other The timer was not created.
107 Status
= EFI_SUCCESS
;
109 if (mTcpTimer
.RefCnt
== 0) {
111 Status
= gBS
->CreateEvent (
112 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
116 &mTcpTimer
.TimerEvent
118 if (!EFI_ERROR (Status
)) {
120 Status
= gBS
->SetTimer (
121 mTcpTimer
.TimerEvent
,
123 (UINT64
) (TICKS_PER_SECOND
/ TCP_TICK_HZ
)
128 if (!EFI_ERROR (Status
)) {
137 Stop and destroy the heartbeat timer for TCP driver.
145 ASSERT (mTcpTimer
.RefCnt
> 0);
149 if (mTcpTimer
.RefCnt
> 0) {
153 gBS
->SetTimer (mTcpTimer
.TimerEvent
, TimerCancel
, 0);
154 gBS
->CloseEvent (mTcpTimer
.TimerEvent
);
155 mTcpTimer
.TimerEvent
= NULL
;
159 The entry point for Tcp driver, which is used to install Tcp driver on the ImageHandle.
161 @param[in] ImageHandle The firmware allocated handle for this driver image.
162 @param[in] SystemTable Pointer to the EFI system table.
164 @retval EFI_SUCCESS The driver loaded.
165 @retval other The driver did not load.
170 TcpDriverEntryPoint (
171 IN EFI_HANDLE ImageHandle
,
172 IN EFI_SYSTEM_TABLE
*SystemTable
179 // Install the TCP Driver Binding Protocol
181 Status
= EfiLibInstallDriverBindingComponentName2 (
189 if (EFI_ERROR (Status
)) {
194 // Install the TCP Driver Binding Protocol
196 Status
= EfiLibInstallDriverBindingComponentName2 (
204 if (EFI_ERROR (Status
)) {
205 EfiLibUninstallDriverBindingComponentName2 (
214 // Initialize ISS and random port.
216 Seed
= NetRandomInitSeed ();
217 mTcpGlobalIss
= NET_RANDOM (Seed
) % mTcpGlobalIss
;
218 mTcp4RandomPort
= (UINT16
) (TCP_PORT_KNOWN
+ (NET_RANDOM (Seed
) % TCP_PORT_KNOWN
));
219 mTcp6RandomPort
= mTcp4RandomPort
;
225 Create a new TCP4 or TCP6 driver service binding protocol
227 @param[in] Controller Controller handle of device to bind driver to.
228 @param[in] Image The TCP driver's image handle.
229 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
231 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
232 @retval EFI_SUCCESS A new IP6 service binding private was created.
237 IN EFI_HANDLE Controller
,
243 EFI_GUID
*IpServiceBindingGuid
;
244 EFI_GUID
*TcpServiceBindingGuid
;
245 TCP_SERVICE_DATA
*TcpServiceData
;
246 IP_IO_OPEN_DATA OpenData
;
248 if (IpVersion
== IP_VERSION_4
) {
249 IpServiceBindingGuid
= &gEfiIp4ServiceBindingProtocolGuid
;
250 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
252 IpServiceBindingGuid
= &gEfiIp6ServiceBindingProtocolGuid
;
253 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
256 Status
= gBS
->OpenProtocol (
258 TcpServiceBindingGuid
,
262 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
264 if (!EFI_ERROR (Status
)) {
265 return EFI_ALREADY_STARTED
;
268 Status
= gBS
->OpenProtocol (
270 IpServiceBindingGuid
,
274 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
276 if (EFI_ERROR (Status
)) {
277 return EFI_UNSUPPORTED
;
281 // Create the TCP service data.
283 TcpServiceData
= AllocateZeroPool (sizeof (TCP_SERVICE_DATA
));
284 if (TcpServiceData
== NULL
) {
285 return EFI_OUT_OF_RESOURCES
;
288 TcpServiceData
->Signature
= TCP_DRIVER_SIGNATURE
;
289 TcpServiceData
->ControllerHandle
= Controller
;
290 TcpServiceData
->DriverBindingHandle
= Image
;
291 TcpServiceData
->IpVersion
= IpVersion
;
293 &TcpServiceData
->ServiceBinding
,
295 sizeof (EFI_SERVICE_BINDING_PROTOCOL
)
298 TcpServiceData
->IpIo
= IpIoCreate (Image
, Controller
, IpVersion
);
299 if (TcpServiceData
->IpIo
== NULL
) {
300 Status
= EFI_OUT_OF_RESOURCES
;
305 InitializeListHead (&TcpServiceData
->SocketList
);
306 ZeroMem (&OpenData
, sizeof (IP_IO_OPEN_DATA
));
308 if (IpVersion
== IP_VERSION_4
) {
310 &OpenData
.IpConfigData
.Ip4CfgData
,
311 &mIp4IoDefaultIpConfigData
,
312 sizeof (EFI_IP4_CONFIG_DATA
)
314 OpenData
.IpConfigData
.Ip4CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
317 &OpenData
.IpConfigData
.Ip6CfgData
,
318 &mIp6IoDefaultIpConfigData
,
319 sizeof (EFI_IP6_CONFIG_DATA
)
321 OpenData
.IpConfigData
.Ip6CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
324 OpenData
.PktRcvdNotify
= TcpRxCallback
;
325 Status
= IpIoOpen (TcpServiceData
->IpIo
, &OpenData
);
326 if (EFI_ERROR (Status
)) {
330 Status
= TcpCreateTimer ();
331 if (EFI_ERROR (Status
)) {
335 Status
= gBS
->InstallMultipleProtocolInterfaces (
337 TcpServiceBindingGuid
,
338 &TcpServiceData
->ServiceBinding
,
341 if (EFI_ERROR (Status
)) {
351 if (TcpServiceData
->IpIo
!= NULL
) {
352 IpIoDestroy (TcpServiceData
->IpIo
);
353 TcpServiceData
->IpIo
= NULL
;
356 FreePool (TcpServiceData
);
362 Callback function which provided by user to remove one node in NetDestroyLinkList process.
364 @param[in] Entry The entry to be removed.
365 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
367 @retval EFI_SUCCESS The entry has been removed successfully.
368 @retval Others Fail to remove the entry.
373 TcpDestroyChildEntryInHandleBuffer (
374 IN LIST_ENTRY
*Entry
,
379 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
380 UINTN NumberOfChildren
;
381 EFI_HANDLE
*ChildHandleBuffer
;
383 if (Entry
== NULL
|| Context
== NULL
) {
384 return EFI_INVALID_PARAMETER
;
387 Sock
= NET_LIST_USER_STRUCT_S (Entry
, SOCKET
, Link
, SOCK_SIGNATURE
);
388 ServiceBinding
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
389 NumberOfChildren
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
390 ChildHandleBuffer
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
392 if (!NetIsInHandleBuffer (Sock
->SockHandle
, NumberOfChildren
, ChildHandleBuffer
)) {
396 return ServiceBinding
->DestroyChild (ServiceBinding
, Sock
->SockHandle
);
400 Destroy a TCP6 or TCP4 service binding instance. It will release all
401 the resources allocated by the instance.
403 @param[in] Controller Controller handle of device to bind driver to.
404 @param[in] ImageHandle The TCP driver's image handle.
405 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
406 of children is zero stop the entire bus driver.
407 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
408 if NumberOfChildren is 0.
409 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6
411 @retval EFI_SUCCESS The resources used by the instance were cleaned up.
412 @retval Others Failed to clean up some of the resources.
417 IN EFI_HANDLE Controller
,
418 IN EFI_HANDLE ImageHandle
,
419 IN UINTN NumberOfChildren
,
420 IN EFI_HANDLE
*ChildHandleBuffer
, OPTIONAL
424 EFI_HANDLE NicHandle
;
425 EFI_GUID
*IpProtocolGuid
;
426 EFI_GUID
*ServiceBindingGuid
;
427 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
428 TCP_SERVICE_DATA
*TcpServiceData
;
431 TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
433 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
435 if (IpVersion
== IP_VERSION_4
) {
436 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
437 ServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
439 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
440 ServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
443 NicHandle
= NetLibGetNicHandle (Controller
, IpProtocolGuid
);
444 if (NicHandle
== NULL
) {
448 Status
= gBS
->OpenProtocol (
451 (VOID
**) &ServiceBinding
,
454 EFI_OPEN_PROTOCOL_GET_PROTOCOL
456 if (EFI_ERROR (Status
)) {
457 return EFI_DEVICE_ERROR
;
460 TcpServiceData
= TCP_SERVICE_FROM_THIS (ServiceBinding
);
462 if (NumberOfChildren
!= 0) {
463 List
= &TcpServiceData
->SocketList
;
464 Context
.ServiceBinding
= ServiceBinding
;
465 Context
.NumberOfChildren
= NumberOfChildren
;
466 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
467 Status
= NetDestroyLinkList (
469 TcpDestroyChildEntryInHandleBuffer
,
473 } else if (IsListEmpty (&TcpServiceData
->SocketList
)) {
475 // Uninstall TCP servicebinding protocol
477 gBS
->UninstallMultipleProtocolInterfaces (
485 // Destroy the IpIO consumed by TCP driver
487 IpIoDestroy (TcpServiceData
->IpIo
);
488 TcpServiceData
->IpIo
= NULL
;
491 // Destroy the heartbeat timer.
496 // Release the TCP service data
498 FreePool (TcpServiceData
);
500 Status
= EFI_SUCCESS
;
507 Test to see if this driver supports ControllerHandle.
509 @param[in] This Protocol instance pointer.
510 @param[in] ControllerHandle Handle of device to test.
511 @param[in] RemainingDevicePath Optional parameter use to pick a specific
512 child device to start.
514 @retval EFI_SUCCESS This driver supports this device.
515 @retval EFI_ALREADY_STARTED This driver is already running on this device.
516 @retval other This driver does not support this device.
521 Tcp4DriverBindingSupported (
522 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
523 IN EFI_HANDLE ControllerHandle
,
524 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
530 // Test for the Tcp4ServiceBinding Protocol
532 Status
= gBS
->OpenProtocol (
534 &gEfiTcp4ServiceBindingProtocolGuid
,
536 This
->DriverBindingHandle
,
538 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
540 if (!EFI_ERROR (Status
)) {
541 return EFI_ALREADY_STARTED
;
545 // Test for the Ip4ServiceBinding Protocol
547 Status
= gBS
->OpenProtocol (
549 &gEfiIp4ServiceBindingProtocolGuid
,
551 This
->DriverBindingHandle
,
553 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
559 Start this driver on ControllerHandle.
561 @param[in] This Protocol instance pointer.
562 @param[in] ControllerHandle Handle of device to bind driver to.
563 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
566 @retval EFI_SUCCESS The driver is added to ControllerHandle.
567 @retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
569 @retval other The driver cannot be added to ControllerHandle.
574 Tcp4DriverBindingStart (
575 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
576 IN EFI_HANDLE ControllerHandle
,
577 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
582 Status
= TcpCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_4
);
583 if ((Status
== EFI_ALREADY_STARTED
) || (Status
== EFI_UNSUPPORTED
)) {
584 Status
= EFI_SUCCESS
;
591 Stop this driver on ControllerHandle.
593 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
594 @param[in] ControllerHandle A handle to the device being stopped. The handle must
595 support a bus specific I/O protocol for the driver
596 to use to stop the device.
597 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
598 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
599 if NumberOfChildren is 0.
601 @retval EFI_SUCCESS The device was stopped.
602 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
607 Tcp4DriverBindingStop (
608 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
609 IN EFI_HANDLE ControllerHandle
,
610 IN UINTN NumberOfChildren
,
611 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
614 return TcpDestroyService (
616 This
->DriverBindingHandle
,
624 Test to see if this driver supports ControllerHandle.
626 @param[in] This Protocol instance pointer.
627 @param[in] ControllerHandle Handle of device to test.
628 @param[in] RemainingDevicePath Optional parameter use to pick a specific
629 child device to start.
631 @retval EFI_SUCCESS This driver supports this device.
632 @retval EFI_ALREADY_STARTED This driver is already running on this device.
633 @retval other This driver does not support this device.
638 Tcp6DriverBindingSupported (
639 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
640 IN EFI_HANDLE ControllerHandle
,
641 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
647 // Test for the Tcp6ServiceBinding Protocol
649 Status
= gBS
->OpenProtocol (
651 &gEfiTcp6ServiceBindingProtocolGuid
,
653 This
->DriverBindingHandle
,
655 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
657 if (!EFI_ERROR (Status
)) {
658 return EFI_ALREADY_STARTED
;
662 // Test for the Ip6ServiceBinding Protocol
664 Status
= gBS
->OpenProtocol (
666 &gEfiIp6ServiceBindingProtocolGuid
,
668 This
->DriverBindingHandle
,
670 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
676 Start this driver on ControllerHandle.
678 @param[in] This Protocol instance pointer.
679 @param[in] ControllerHandle Handle of device to bind driver to.
680 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
683 @retval EFI_SUCCESS The driver is added to ControllerHandle.
684 @retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
686 @retval other The driver cannot be added to ControllerHandle.
691 Tcp6DriverBindingStart (
692 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
693 IN EFI_HANDLE ControllerHandle
,
694 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
699 Status
= TcpCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_6
);
700 if ((Status
== EFI_ALREADY_STARTED
) || (Status
== EFI_UNSUPPORTED
)) {
701 Status
= EFI_SUCCESS
;
708 Stop this driver on ControllerHandle.
710 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
711 @param[in] ControllerHandle A handle to the device being stopped. The handle must
712 support a bus specific I/O protocol for the driver
713 to use to stop the device.
714 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
715 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
716 if NumberOfChildren is 0.
718 @retval EFI_SUCCESS The device was stopped.
719 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
724 Tcp6DriverBindingStop (
725 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
726 IN EFI_HANDLE ControllerHandle
,
727 IN UINTN NumberOfChildren
,
728 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
731 return TcpDestroyService (
733 This
->DriverBindingHandle
,
741 The Callback funtion called after the TCP socket was created.
743 @param[in] This Pointer to the socket just created
744 @param[in] Context Context of the socket
746 @retval EFI_SUCCESS This protocol installed successfully.
747 @retval other An error occured.
751 TcpCreateSocketCallback (
757 TCP_SERVICE_DATA
*TcpServiceData
;
758 EFI_GUID
*IpProtocolGuid
;
761 if (This
->IpVersion
== IP_VERSION_4
) {
762 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
764 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
767 TcpServiceData
= ((TCP_PROTO_DATA
*) This
->ProtoReserved
)->TcpService
;
770 // Open the default IP protocol of IP_IO BY_DRIVER.
772 Status
= gBS
->OpenProtocol (
773 TcpServiceData
->IpIo
->ChildHandle
,
776 TcpServiceData
->DriverBindingHandle
,
778 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
780 if (EFI_ERROR (Status
)) {
785 // Open the device path on the handle where service binding resides on.
787 Status
= gBS
->OpenProtocol (
788 TcpServiceData
->ControllerHandle
,
789 &gEfiDevicePathProtocolGuid
,
790 (VOID
**) &This
->ParentDevicePath
,
791 TcpServiceData
->DriverBindingHandle
,
793 EFI_OPEN_PROTOCOL_GET_PROTOCOL
795 if (EFI_ERROR (Status
)) {
797 TcpServiceData
->IpIo
->ChildHandle
,
799 TcpServiceData
->DriverBindingHandle
,
804 // Insert this socket into the SocketList.
806 InsertTailList (&TcpServiceData
->SocketList
, &This
->Link
);
813 The callback function called before the TCP socket was to be destroyed.
815 @param[in] This The TCP socket to be destroyed.
816 @param[in] Context The context of the socket.
820 TcpDestroySocketCallback (
825 TCP_SERVICE_DATA
*TcpServiceData
;
826 EFI_GUID
*IpProtocolGuid
;
828 if (This
->IpVersion
== IP_VERSION_4
) {
829 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
831 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
834 TcpServiceData
= ((TCP_PROTO_DATA
*) This
->ProtoReserved
)->TcpService
;
837 // Remove this node from the list.
839 RemoveEntryList (&This
->Link
);
842 // Close the IP protocol.
845 TcpServiceData
->IpIo
->ChildHandle
,
847 TcpServiceData
->DriverBindingHandle
,
853 Creates a child handle with a set of TCP services.
855 The CreateChild() function installs a protocol on ChildHandle.
856 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
857 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
859 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
860 @param[in, out] ChildHandle Pointer to the handle of the child to create.
861 If it is NULL, then a new handle is created.
862 If it is a pointer to an existing UEFI handle,
863 then the protocol is added to the existing UEFI handle.
865 @retval EFI_SUCCES The protocol was added to ChildHandle.
866 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
867 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
869 @retval other The child handle was not created.
874 TcpServiceBindingCreateChild (
875 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
876 IN OUT EFI_HANDLE
*ChildHandle
880 TCP_SERVICE_DATA
*TcpServiceData
;
881 TCP_PROTO_DATA TcpProto
;
885 if (NULL
== This
|| NULL
== ChildHandle
) {
886 return EFI_INVALID_PARAMETER
;
889 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
891 Status
= EFI_SUCCESS
;
892 TcpServiceData
= TCP_SERVICE_FROM_THIS (This
);
893 TcpProto
.TcpService
= TcpServiceData
;
894 TcpProto
.TcpPcb
= NULL
;
897 // Create a tcp instance with defualt Tcp default
898 // sock init data and TcpProto
900 mTcpDefaultSockData
.ProtoData
= &TcpProto
;
901 mTcpDefaultSockData
.DataSize
= sizeof (TCP_PROTO_DATA
);
902 mTcpDefaultSockData
.DriverBinding
= TcpServiceData
->DriverBindingHandle
;
903 mTcpDefaultSockData
.IpVersion
= TcpServiceData
->IpVersion
;
905 if (TcpServiceData
->IpVersion
== IP_VERSION_4
) {
906 mTcpDefaultSockData
.Protocol
= &gTcp4ProtocolTemplate
;
908 mTcpDefaultSockData
.Protocol
= &gTcp6ProtocolTemplate
;
911 Sock
= SockCreateChild (&mTcpDefaultSockData
);
915 "TcpDriverBindingCreateChild: No resource to create a Tcp Child\n")
918 Status
= EFI_OUT_OF_RESOURCES
;
920 *ChildHandle
= Sock
->SockHandle
;
923 mTcpDefaultSockData
.ProtoData
= NULL
;
925 gBS
->RestoreTPL (OldTpl
);
930 Destroys a child handle with a set of TCP services.
932 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
933 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
934 last protocol on ChildHandle, then ChildHandle is destroyed.
936 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
937 @param ChildHandle Handle of the child to be destroyed.
939 @retval EFI_SUCCES The protocol was removed from ChildHandle.
940 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
941 @retval EFI_INVALID_PARAMETER Child handle is NULL.
942 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
943 because its services are being used.
944 @retval other The child handle was not destroyed.
949 TcpServiceBindingDestroyChild (
950 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
951 IN EFI_HANDLE ChildHandle
958 if (NULL
== This
|| NULL
== ChildHandle
) {
959 return EFI_INVALID_PARAMETER
;
963 // retrieve the Tcp4 protocol from ChildHandle
965 Status
= gBS
->OpenProtocol (
967 &gEfiTcp4ProtocolGuid
,
969 gTcp4DriverBinding
.DriverBindingHandle
,
971 EFI_OPEN_PROTOCOL_GET_PROTOCOL
973 if (EFI_ERROR (Status
)) {
975 // No Tcp4, try the Tcp6 protocol
977 Status
= gBS
->OpenProtocol (
979 &gEfiTcp6ProtocolGuid
,
981 gTcp6DriverBinding
.DriverBindingHandle
,
983 EFI_OPEN_PROTOCOL_GET_PROTOCOL
985 if (EFI_ERROR (Status
)) {
986 Status
= EFI_UNSUPPORTED
;
990 if (!EFI_ERROR (Status
)) {
992 // destroy this sock and related Tcp protocol control
995 Sock
= SOCK_FROM_THIS (Tcp
);
997 SockDestroyChild (Sock
);