2 The driver binding and service binding protocol for the TCP driver.
4 Copyright (c) 2009 - 2016, 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 gBS
->UninstallMultipleProtocolInterfaces (
207 &gEfiDriverBindingProtocolGuid
,
209 &gEfiComponentName2ProtocolGuid
,
211 &gEfiComponentNameProtocolGuid
,
219 // Initialize ISS and random port.
221 Seed
= NetRandomInitSeed ();
222 mTcpGlobalIss
= NET_RANDOM (Seed
) % mTcpGlobalIss
;
223 mTcp4RandomPort
= (UINT16
) (TCP_PORT_KNOWN
+ (NET_RANDOM (Seed
) % TCP_PORT_KNOWN
));
224 mTcp6RandomPort
= mTcp4RandomPort
;
230 Create a new TCP4 or TCP6 driver service binding protocol
232 @param[in] Controller Controller handle of device to bind driver to.
233 @param[in] Image The TCP driver's image handle.
234 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
236 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
237 @retval EFI_SUCCESS A new IP6 service binding private was created.
242 IN EFI_HANDLE Controller
,
248 EFI_GUID
*IpServiceBindingGuid
;
249 EFI_GUID
*TcpServiceBindingGuid
;
250 TCP_SERVICE_DATA
*TcpServiceData
;
251 IP_IO_OPEN_DATA OpenData
;
253 if (IpVersion
== IP_VERSION_4
) {
254 IpServiceBindingGuid
= &gEfiIp4ServiceBindingProtocolGuid
;
255 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
257 IpServiceBindingGuid
= &gEfiIp6ServiceBindingProtocolGuid
;
258 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
261 Status
= gBS
->OpenProtocol (
263 TcpServiceBindingGuid
,
267 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
269 if (!EFI_ERROR (Status
)) {
270 return EFI_ALREADY_STARTED
;
273 Status
= gBS
->OpenProtocol (
275 IpServiceBindingGuid
,
279 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
281 if (EFI_ERROR (Status
)) {
282 return EFI_UNSUPPORTED
;
286 // Create the TCP service data.
288 TcpServiceData
= AllocateZeroPool (sizeof (TCP_SERVICE_DATA
));
289 if (TcpServiceData
== NULL
) {
290 return EFI_OUT_OF_RESOURCES
;
293 TcpServiceData
->Signature
= TCP_DRIVER_SIGNATURE
;
294 TcpServiceData
->ControllerHandle
= Controller
;
295 TcpServiceData
->DriverBindingHandle
= Image
;
296 TcpServiceData
->IpVersion
= IpVersion
;
298 &TcpServiceData
->ServiceBinding
,
300 sizeof (EFI_SERVICE_BINDING_PROTOCOL
)
303 TcpServiceData
->IpIo
= IpIoCreate (Image
, Controller
, IpVersion
);
304 if (TcpServiceData
->IpIo
== NULL
) {
305 Status
= EFI_OUT_OF_RESOURCES
;
310 InitializeListHead (&TcpServiceData
->SocketList
);
311 ZeroMem (&OpenData
, sizeof (IP_IO_OPEN_DATA
));
313 if (IpVersion
== IP_VERSION_4
) {
315 &OpenData
.IpConfigData
.Ip4CfgData
,
316 &mIp4IoDefaultIpConfigData
,
317 sizeof (EFI_IP4_CONFIG_DATA
)
319 OpenData
.IpConfigData
.Ip4CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
322 &OpenData
.IpConfigData
.Ip6CfgData
,
323 &mIp6IoDefaultIpConfigData
,
324 sizeof (EFI_IP6_CONFIG_DATA
)
326 OpenData
.IpConfigData
.Ip6CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
329 OpenData
.PktRcvdNotify
= TcpRxCallback
;
330 Status
= IpIoOpen (TcpServiceData
->IpIo
, &OpenData
);
331 if (EFI_ERROR (Status
)) {
335 Status
= TcpCreateTimer ();
336 if (EFI_ERROR (Status
)) {
340 Status
= gBS
->InstallMultipleProtocolInterfaces (
342 TcpServiceBindingGuid
,
343 &TcpServiceData
->ServiceBinding
,
346 if (EFI_ERROR (Status
)) {
356 if (TcpServiceData
->IpIo
!= NULL
) {
357 IpIoDestroy (TcpServiceData
->IpIo
);
358 TcpServiceData
->IpIo
= NULL
;
361 FreePool (TcpServiceData
);
367 Callback function which provided by user to remove one node in NetDestroyLinkList process.
369 @param[in] Entry The entry to be removed.
370 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
372 @retval EFI_SUCCESS The entry has been removed successfully.
373 @retval Others Fail to remove the entry.
378 TcpDestroyChildEntryInHandleBuffer (
379 IN LIST_ENTRY
*Entry
,
384 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
385 UINTN NumberOfChildren
;
386 EFI_HANDLE
*ChildHandleBuffer
;
388 if (Entry
== NULL
|| Context
== NULL
) {
389 return EFI_INVALID_PARAMETER
;
392 Sock
= NET_LIST_USER_STRUCT_S (Entry
, SOCKET
, Link
, SOCK_SIGNATURE
);
393 ServiceBinding
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
394 NumberOfChildren
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
395 ChildHandleBuffer
= ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
397 if (!NetIsInHandleBuffer (Sock
->SockHandle
, NumberOfChildren
, ChildHandleBuffer
)) {
401 return ServiceBinding
->DestroyChild (ServiceBinding
, Sock
->SockHandle
);
405 Destroy a TCP6 or TCP4 service binding instance. It will release all
406 the resources allocated by the instance.
408 @param[in] Controller Controller handle of device to bind driver to.
409 @param[in] ImageHandle The TCP driver's image handle.
410 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
411 of children is zero stop the entire bus driver.
412 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
413 if NumberOfChildren is 0.
414 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6
416 @retval EFI_SUCCESS The resources used by the instance were cleaned up.
417 @retval Others Failed to clean up some of the resources.
422 IN EFI_HANDLE Controller
,
423 IN EFI_HANDLE ImageHandle
,
424 IN UINTN NumberOfChildren
,
425 IN EFI_HANDLE
*ChildHandleBuffer
, OPTIONAL
429 EFI_HANDLE NicHandle
;
430 EFI_GUID
*IpProtocolGuid
;
431 EFI_GUID
*ServiceBindingGuid
;
432 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
433 TCP_SERVICE_DATA
*TcpServiceData
;
436 TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
438 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
440 if (IpVersion
== IP_VERSION_4
) {
441 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
442 ServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
444 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
445 ServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
448 NicHandle
= NetLibGetNicHandle (Controller
, IpProtocolGuid
);
449 if (NicHandle
== NULL
) {
453 Status
= gBS
->OpenProtocol (
456 (VOID
**) &ServiceBinding
,
459 EFI_OPEN_PROTOCOL_GET_PROTOCOL
461 if (EFI_ERROR (Status
)) {
462 return EFI_DEVICE_ERROR
;
465 TcpServiceData
= TCP_SERVICE_FROM_THIS (ServiceBinding
);
467 if (NumberOfChildren
!= 0) {
468 List
= &TcpServiceData
->SocketList
;
469 Context
.ServiceBinding
= ServiceBinding
;
470 Context
.NumberOfChildren
= NumberOfChildren
;
471 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
472 Status
= NetDestroyLinkList (
474 TcpDestroyChildEntryInHandleBuffer
,
478 } else if (IsListEmpty (&TcpServiceData
->SocketList
)) {
480 // Uninstall TCP servicebinding protocol
482 gBS
->UninstallMultipleProtocolInterfaces (
490 // Destroy the IpIO consumed by TCP driver
492 IpIoDestroy (TcpServiceData
->IpIo
);
493 TcpServiceData
->IpIo
= NULL
;
496 // Destroy the heartbeat timer.
501 // Release the TCP service data
503 FreePool (TcpServiceData
);
505 Status
= EFI_SUCCESS
;
512 Test to see if this driver supports ControllerHandle.
514 @param[in] This Protocol instance pointer.
515 @param[in] ControllerHandle Handle of device to test.
516 @param[in] RemainingDevicePath Optional parameter use to pick a specific
517 child device to start.
519 @retval EFI_SUCCESS This driver supports this device.
520 @retval EFI_ALREADY_STARTED This driver is already running on this device.
521 @retval other This driver does not support this device.
526 Tcp4DriverBindingSupported (
527 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
528 IN EFI_HANDLE ControllerHandle
,
529 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
535 // Test for the Tcp4ServiceBinding Protocol
537 Status
= gBS
->OpenProtocol (
539 &gEfiTcp4ServiceBindingProtocolGuid
,
541 This
->DriverBindingHandle
,
543 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
545 if (!EFI_ERROR (Status
)) {
546 return EFI_ALREADY_STARTED
;
550 // Test for the Ip4ServiceBinding Protocol
552 Status
= gBS
->OpenProtocol (
554 &gEfiIp4ServiceBindingProtocolGuid
,
556 This
->DriverBindingHandle
,
558 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
564 Start this driver on ControllerHandle.
566 @param[in] This Protocol instance pointer.
567 @param[in] ControllerHandle Handle of device to bind driver to.
568 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
571 @retval EFI_SUCCESS The driver is added to ControllerHandle.
572 @retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
574 @retval other The driver cannot be added to ControllerHandle.
579 Tcp4DriverBindingStart (
580 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
581 IN EFI_HANDLE ControllerHandle
,
582 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
587 Status
= TcpCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_4
);
588 if ((Status
== EFI_ALREADY_STARTED
) || (Status
== EFI_UNSUPPORTED
)) {
589 Status
= EFI_SUCCESS
;
596 Stop this driver on ControllerHandle.
598 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
599 @param[in] ControllerHandle A handle to the device being stopped. The handle must
600 support a bus specific I/O protocol for the driver
601 to use to stop the device.
602 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
603 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
604 if NumberOfChildren is 0.
606 @retval EFI_SUCCESS The device was stopped.
607 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
612 Tcp4DriverBindingStop (
613 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
614 IN EFI_HANDLE ControllerHandle
,
615 IN UINTN NumberOfChildren
,
616 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
619 return TcpDestroyService (
621 This
->DriverBindingHandle
,
629 Test to see if this driver supports ControllerHandle.
631 @param[in] This Protocol instance pointer.
632 @param[in] ControllerHandle Handle of device to test.
633 @param[in] RemainingDevicePath Optional parameter use to pick a specific
634 child device to start.
636 @retval EFI_SUCCESS This driver supports this device.
637 @retval EFI_ALREADY_STARTED This driver is already running on this device.
638 @retval other This driver does not support this device.
643 Tcp6DriverBindingSupported (
644 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
645 IN EFI_HANDLE ControllerHandle
,
646 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
652 // Test for the Tcp6ServiceBinding Protocol
654 Status
= gBS
->OpenProtocol (
656 &gEfiTcp6ServiceBindingProtocolGuid
,
658 This
->DriverBindingHandle
,
660 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
662 if (!EFI_ERROR (Status
)) {
663 return EFI_ALREADY_STARTED
;
667 // Test for the Ip6ServiceBinding Protocol
669 Status
= gBS
->OpenProtocol (
671 &gEfiIp6ServiceBindingProtocolGuid
,
673 This
->DriverBindingHandle
,
675 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
681 Start this driver on ControllerHandle.
683 @param[in] This Protocol instance pointer.
684 @param[in] ControllerHandle Handle of device to bind driver to.
685 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
688 @retval EFI_SUCCESS The driver is added to ControllerHandle.
689 @retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
691 @retval other The driver cannot be added to ControllerHandle.
696 Tcp6DriverBindingStart (
697 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
698 IN EFI_HANDLE ControllerHandle
,
699 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
704 Status
= TcpCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_6
);
705 if ((Status
== EFI_ALREADY_STARTED
) || (Status
== EFI_UNSUPPORTED
)) {
706 Status
= EFI_SUCCESS
;
713 Stop this driver on ControllerHandle.
715 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
716 @param[in] ControllerHandle A handle to the device being stopped. The handle must
717 support a bus specific I/O protocol for the driver
718 to use to stop the device.
719 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
720 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
721 if NumberOfChildren is 0.
723 @retval EFI_SUCCESS The device was stopped.
724 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
729 Tcp6DriverBindingStop (
730 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
731 IN EFI_HANDLE ControllerHandle
,
732 IN UINTN NumberOfChildren
,
733 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
736 return TcpDestroyService (
738 This
->DriverBindingHandle
,
746 The Callback funtion called after the TCP socket was created.
748 @param[in] This Pointer to the socket just created
749 @param[in] Context Context of the socket
751 @retval EFI_SUCCESS This protocol installed successfully.
752 @retval other An error occured.
756 TcpCreateSocketCallback (
762 TCP_SERVICE_DATA
*TcpServiceData
;
763 EFI_GUID
*IpProtocolGuid
;
766 if (This
->IpVersion
== IP_VERSION_4
) {
767 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
769 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
772 TcpServiceData
= ((TCP_PROTO_DATA
*) This
->ProtoReserved
)->TcpService
;
775 // Open the default IP protocol of IP_IO BY_DRIVER.
777 Status
= gBS
->OpenProtocol (
778 TcpServiceData
->IpIo
->ChildHandle
,
781 TcpServiceData
->DriverBindingHandle
,
783 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
785 if (EFI_ERROR (Status
)) {
790 // Open the device path on the handle where service binding resides on.
792 Status
= gBS
->OpenProtocol (
793 TcpServiceData
->ControllerHandle
,
794 &gEfiDevicePathProtocolGuid
,
795 (VOID
**) &This
->ParentDevicePath
,
796 TcpServiceData
->DriverBindingHandle
,
798 EFI_OPEN_PROTOCOL_GET_PROTOCOL
800 if (EFI_ERROR (Status
)) {
802 TcpServiceData
->IpIo
->ChildHandle
,
804 TcpServiceData
->DriverBindingHandle
,
809 // Insert this socket into the SocketList.
811 InsertTailList (&TcpServiceData
->SocketList
, &This
->Link
);
818 The callback function called before the TCP socket was to be destroyed.
820 @param[in] This The TCP socket to be destroyed.
821 @param[in] Context The context of the socket.
825 TcpDestroySocketCallback (
830 TCP_SERVICE_DATA
*TcpServiceData
;
831 EFI_GUID
*IpProtocolGuid
;
833 if (This
->IpVersion
== IP_VERSION_4
) {
834 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
836 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
839 TcpServiceData
= ((TCP_PROTO_DATA
*) This
->ProtoReserved
)->TcpService
;
842 // Remove this node from the list.
844 RemoveEntryList (&This
->Link
);
847 // Close the IP protocol.
850 TcpServiceData
->IpIo
->ChildHandle
,
852 TcpServiceData
->DriverBindingHandle
,
858 Creates a child handle with a set of TCP services.
860 The CreateChild() function installs a protocol on ChildHandle.
861 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
862 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
864 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
865 @param[in, out] ChildHandle Pointer to the handle of the child to create.
866 If it is NULL, then a new handle is created.
867 If it is a pointer to an existing UEFI handle,
868 then the protocol is added to the existing UEFI handle.
870 @retval EFI_SUCCES The protocol was added to ChildHandle.
871 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
872 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
874 @retval other The child handle was not created.
879 TcpServiceBindingCreateChild (
880 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
881 IN OUT EFI_HANDLE
*ChildHandle
885 TCP_SERVICE_DATA
*TcpServiceData
;
886 TCP_PROTO_DATA TcpProto
;
890 if (NULL
== This
|| NULL
== ChildHandle
) {
891 return EFI_INVALID_PARAMETER
;
894 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
896 Status
= EFI_SUCCESS
;
897 TcpServiceData
= TCP_SERVICE_FROM_THIS (This
);
898 TcpProto
.TcpService
= TcpServiceData
;
899 TcpProto
.TcpPcb
= NULL
;
902 // Create a tcp instance with defualt Tcp default
903 // sock init data and TcpProto
905 mTcpDefaultSockData
.ProtoData
= &TcpProto
;
906 mTcpDefaultSockData
.DataSize
= sizeof (TCP_PROTO_DATA
);
907 mTcpDefaultSockData
.DriverBinding
= TcpServiceData
->DriverBindingHandle
;
908 mTcpDefaultSockData
.IpVersion
= TcpServiceData
->IpVersion
;
910 if (TcpServiceData
->IpVersion
== IP_VERSION_4
) {
911 mTcpDefaultSockData
.Protocol
= &gTcp4ProtocolTemplate
;
913 mTcpDefaultSockData
.Protocol
= &gTcp6ProtocolTemplate
;
916 Sock
= SockCreateChild (&mTcpDefaultSockData
);
920 "TcpDriverBindingCreateChild: No resource to create a Tcp Child\n")
923 Status
= EFI_OUT_OF_RESOURCES
;
925 *ChildHandle
= Sock
->SockHandle
;
928 mTcpDefaultSockData
.ProtoData
= NULL
;
930 gBS
->RestoreTPL (OldTpl
);
935 Destroys a child handle with a set of TCP services.
937 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
938 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
939 last protocol on ChildHandle, then ChildHandle is destroyed.
941 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
942 @param ChildHandle Handle of the child to be destroyed.
944 @retval EFI_SUCCES The protocol was removed from ChildHandle.
945 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
946 @retval EFI_INVALID_PARAMETER Child handle is NULL.
947 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
948 because its services are being used.
949 @retval other The child handle was not destroyed.
954 TcpServiceBindingDestroyChild (
955 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
956 IN EFI_HANDLE ChildHandle
963 if (NULL
== This
|| NULL
== ChildHandle
) {
964 return EFI_INVALID_PARAMETER
;
968 // retrieve the Tcp4 protocol from ChildHandle
970 Status
= gBS
->OpenProtocol (
972 &gEfiTcp4ProtocolGuid
,
974 gTcp4DriverBinding
.DriverBindingHandle
,
976 EFI_OPEN_PROTOCOL_GET_PROTOCOL
978 if (EFI_ERROR (Status
)) {
980 // No Tcp4, try the Tcp6 protocol
982 Status
= gBS
->OpenProtocol (
984 &gEfiTcp6ProtocolGuid
,
986 gTcp6DriverBinding
.DriverBindingHandle
,
988 EFI_OPEN_PROTOCOL_GET_PROTOCOL
990 if (EFI_ERROR (Status
)) {
991 Status
= EFI_UNSUPPORTED
;
995 if (!EFI_ERROR (Status
)) {
997 // destroy this sock and related Tcp protocol control
1000 Sock
= SOCK_FROM_THIS (Tcp
);
1002 SockDestroyChild (Sock
);