2 The driver binding and service binding protocol for IP4 driver.
4 Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding
= {
20 Ip4DriverBindingSupported
,
21 Ip4DriverBindingStart
,
28 BOOLEAN mIpSec2Installed
= FALSE
;
31 Callback function for IpSec2 Protocol install.
33 @param[in] Event Event whose notification function is being invoked
34 @param[in] Context Pointer to the notification function's context
39 IpSec2InstalledCallback (
45 // Close the event so it does not get called again.
47 gBS
->CloseEvent (Event
);
49 mIpSec2Installed
= TRUE
;
53 This is the declaration of an EFI image entry point. This entry point is
54 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
55 both device drivers and bus drivers.
57 The entry point for IP4 driver which install the driver
58 binding and component name protocol on its image.
60 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
61 @param[in] SystemTable A pointer to the EFI System Table.
63 @retval EFI_SUCCESS The operation completed successfully.
64 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
70 IN EFI_HANDLE ImageHandle
,
71 IN EFI_SYSTEM_TABLE
*SystemTable
76 EfiCreateProtocolNotifyEvent (
77 &gEfiIpSec2ProtocolGuid
,
79 IpSec2InstalledCallback
,
84 return EfiLibInstallDriverBindingComponentName2 (
95 Test to see if this driver supports ControllerHandle. This service
96 is called by the EFI boot service ConnectController(). In
97 order to make drivers as small as possible, there are a few calling
98 restrictions for this service. ConnectController() must
99 follow these calling restrictions. If any other agent wishes to call
100 Supported() it must also follow these calling restrictions.
102 @param[in] This Protocol instance pointer.
103 @param[in] ControllerHandle Handle of device to test
104 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
107 @retval EFI_SUCCESS This driver supports this device
108 @retval EFI_ALREADY_STARTED This driver is already running on this device
109 @retval other This driver does not support this device
114 Ip4DriverBindingSupported (
115 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
116 IN EFI_HANDLE ControllerHandle
,
117 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
123 // Test for the MNP service binding Protocol
125 Status
= gBS
->OpenProtocol (
127 &gEfiManagedNetworkServiceBindingProtocolGuid
,
129 This
->DriverBindingHandle
,
131 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
134 if (EFI_ERROR (Status
)) {
139 // Test for the Arp service binding Protocol
141 Status
= gBS
->OpenProtocol (
143 &gEfiArpServiceBindingProtocolGuid
,
145 This
->DriverBindingHandle
,
147 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
154 Clean up a IP4 service binding instance. It will release all
155 the resource allocated by the instance. The instance may be
156 partly initialized, or partly destroyed. If a resource is
157 destroyed, it is marked as that in case the destroy failed and
158 being called again later.
160 @param[in] IpSb The IP4 service binding instance to clean up
162 @retval EFI_SUCCESS The resource used by the instance are cleaned up
163 @retval other Failed to clean up some of the resources.
173 Create a new IP4 driver service binding private instance.
175 @param Controller The controller that has MNP service binding
177 @param ImageHandle The IP4 driver's image handle
178 @param Service The variable to receive the newly created IP4
181 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resource
182 @retval EFI_SUCCESS A new IP4 service binding private is created.
183 @retval other Other error occurs.
188 IN EFI_HANDLE Controller
,
189 IN EFI_HANDLE ImageHandle
,
190 OUT IP4_SERVICE
**Service
196 ASSERT (Service
!= NULL
);
201 // allocate a service private data then initialize all the filed to
202 // empty resources, so if any thing goes wrong when allocating
203 // resources, Ip4CleanService can be called to clean it up.
205 IpSb
= AllocateZeroPool (sizeof (IP4_SERVICE
));
208 return EFI_OUT_OF_RESOURCES
;
211 IpSb
->Signature
= IP4_SERVICE_SIGNATURE
;
212 IpSb
->ServiceBinding
.CreateChild
= Ip4ServiceBindingCreateChild
;
213 IpSb
->ServiceBinding
.DestroyChild
= Ip4ServiceBindingDestroyChild
;
214 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
216 IpSb
->NumChildren
= 0;
217 InitializeListHead (&IpSb
->Children
);
219 InitializeListHead (&IpSb
->Interfaces
);
220 IpSb
->DefaultInterface
= NULL
;
221 IpSb
->DefaultRouteTable
= NULL
;
223 Ip4InitAssembleTable (&IpSb
->Assemble
);
225 IpSb
->IgmpCtrl
.Igmpv1QuerySeen
= 0;
226 InitializeListHead (&IpSb
->IgmpCtrl
.Groups
);
228 IpSb
->Image
= ImageHandle
;
229 IpSb
->Controller
= Controller
;
231 IpSb
->MnpChildHandle
= NULL
;
234 IpSb
->MnpConfigData
.ReceivedQueueTimeoutValue
= 0;
235 IpSb
->MnpConfigData
.TransmitQueueTimeoutValue
= 0;
236 IpSb
->MnpConfigData
.ProtocolTypeFilter
= IP4_ETHER_PROTO
;
237 IpSb
->MnpConfigData
.EnableUnicastReceive
= TRUE
;
238 IpSb
->MnpConfigData
.EnableMulticastReceive
= TRUE
;
239 IpSb
->MnpConfigData
.EnableBroadcastReceive
= TRUE
;
240 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= FALSE
;
241 IpSb
->MnpConfigData
.FlushQueuesOnReset
= TRUE
;
242 IpSb
->MnpConfigData
.EnableReceiveTimestamps
= FALSE
;
243 IpSb
->MnpConfigData
.DisableBackgroundPolling
= FALSE
;
245 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
249 IpSb
->ReconfigEvent
= NULL
;
251 IpSb
->Reconfig
= FALSE
;
253 IpSb
->MediaPresent
= TRUE
;
256 // Create various resources. First create the route table, timer
257 // event, ReconfigEvent and MNP child. IGMP, interface's initialization depend
260 IpSb
->DefaultRouteTable
= Ip4CreateRouteTable ();
262 if (IpSb
->DefaultRouteTable
== NULL
) {
263 Status
= EFI_OUT_OF_RESOURCES
;
267 Status
= gBS
->CreateEvent (
268 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
275 if (EFI_ERROR (Status
)) {
279 Status
= gBS
->CreateEvent (
282 Ip4AutoReconfigCallBack
,
286 if (EFI_ERROR (Status
)) {
290 Status
= NetLibCreateServiceChild (
293 &gEfiManagedNetworkServiceBindingProtocolGuid
,
294 &IpSb
->MnpChildHandle
297 if (EFI_ERROR (Status
)) {
301 Status
= gBS
->OpenProtocol (
302 IpSb
->MnpChildHandle
,
303 &gEfiManagedNetworkProtocolGuid
,
304 (VOID
**) &IpSb
->Mnp
,
307 EFI_OPEN_PROTOCOL_BY_DRIVER
310 if (EFI_ERROR (Status
)) {
314 Status
= Ip4ServiceConfigMnp (IpSb
, TRUE
);
316 if (EFI_ERROR (Status
)) {
320 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
322 if (EFI_ERROR (Status
)) {
326 Status
= Ip4InitIgmp (IpSb
);
328 if (EFI_ERROR (Status
)) {
332 IpSb
->MacString
= NULL
;
333 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
335 if (EFI_ERROR (Status
)) {
339 IpSb
->DefaultInterface
= Ip4CreateInterface (IpSb
->Mnp
, Controller
, ImageHandle
);
341 if (IpSb
->DefaultInterface
== NULL
) {
342 Status
= EFI_OUT_OF_RESOURCES
;
346 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
348 ZeroMem (&IpSb
->Ip4Config2Instance
, sizeof (IP4_CONFIG2_INSTANCE
));
350 Status
= Ip4Config2InitInstance (&IpSb
->Ip4Config2Instance
);
352 if (EFI_ERROR (Status
)) {
356 IpSb
->MaxPacketSize
= IpSb
->SnpMode
.MaxPacketSize
- sizeof (IP4_HEAD
);
357 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
359 // This is a VLAN device, reduce MTU by VLAN tag length
361 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
363 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
369 Ip4CleanService (IpSb
);
377 Clean up a IP4 service binding instance. It will release all
378 the resource allocated by the instance. The instance may be
379 partly initialized, or partly destroyed. If a resource is
380 destroyed, it is marked as that in case the destroy failed and
381 being called again later.
383 @param[in] IpSb The IP4 service binding instance to clean up
385 @retval EFI_SUCCESS The resource used by the instance are cleaned up
386 @retval other Failed to clean up some of the resources.
396 if (IpSb
->DefaultInterface
!= NULL
) {
397 Status
= Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
399 if (EFI_ERROR (Status
)) {
403 IpSb
->DefaultInterface
= NULL
;
406 if (IpSb
->DefaultRouteTable
!= NULL
) {
407 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
408 IpSb
->DefaultRouteTable
= NULL
;
411 Ip4CleanAssembleTable (&IpSb
->Assemble
);
413 if (IpSb
->MnpChildHandle
!= NULL
) {
414 if (IpSb
->Mnp
!= NULL
) {
416 IpSb
->MnpChildHandle
,
417 &gEfiManagedNetworkProtocolGuid
,
425 NetLibDestroyServiceChild (
428 &gEfiManagedNetworkServiceBindingProtocolGuid
,
432 IpSb
->MnpChildHandle
= NULL
;
435 if (IpSb
->Timer
!= NULL
) {
436 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
437 gBS
->CloseEvent (IpSb
->Timer
);
442 if (IpSb
->ReconfigEvent
!= NULL
) {
443 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
445 IpSb
->ReconfigEvent
= NULL
;
448 IpSb
->Reconfig
= FALSE
;
450 if (IpSb
->MacString
!= NULL
) {
451 FreePool (IpSb
->MacString
);
454 Ip4Config2CleanInstance (&IpSb
->Ip4Config2Instance
);
460 Callback function which provided by user to remove one node in NetDestroyLinkList process.
462 @param[in] Entry The entry to be removed.
463 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
465 @retval EFI_SUCCESS The entry has been removed successfully.
466 @retval Others Fail to remove the entry.
471 Ip4DestroyChildEntryInHandleBuffer (
472 IN LIST_ENTRY
*Entry
,
476 IP4_PROTOCOL
*IpInstance
;
477 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
478 UINTN NumberOfChildren
;
479 EFI_HANDLE
*ChildHandleBuffer
;
481 if (Entry
== NULL
|| Context
== NULL
) {
482 return EFI_INVALID_PARAMETER
;
485 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_PROTOCOL
, Link
, IP4_PROTOCOL_SIGNATURE
);
486 ServiceBinding
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
487 NumberOfChildren
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
488 ChildHandleBuffer
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
490 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
494 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
498 Start this driver on ControllerHandle. This service is called by the
499 EFI boot service ConnectController(). In order to make
500 drivers as small as possible, there are a few calling restrictions for
501 this service. ConnectController() must follow these
502 calling restrictions. If any other agent wishes to call Start() it
503 must also follow these calling restrictions.
505 @param[in] This Protocol instance pointer.
506 @param[in] ControllerHandle Handle of device to bind driver to
507 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
510 @retval EFI_SUCCESS This driver is added to ControllerHandle
511 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
512 @retval other This driver does not support this device
517 Ip4DriverBindingStart (
518 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
519 IN EFI_HANDLE ControllerHandle
,
520 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
525 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Cfg2
;
527 IP4_CONFIG2_DATA_ITEM
*DataItem
;
534 // Test for the Ip4 service binding protocol
536 Status
= gBS
->OpenProtocol (
538 &gEfiIp4ServiceBindingProtocolGuid
,
540 This
->DriverBindingHandle
,
542 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
545 if (Status
== EFI_SUCCESS
) {
546 return EFI_ALREADY_STARTED
;
549 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
551 if (EFI_ERROR (Status
)) {
555 ASSERT (IpSb
!= NULL
);
557 Ip4Cfg2
= &IpSb
->Ip4Config2Instance
.Ip4Config2
;
560 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
562 Status
= gBS
->InstallMultipleProtocolInterfaces (
564 &gEfiIp4ServiceBindingProtocolGuid
,
565 &IpSb
->ServiceBinding
,
566 &gEfiIp4Config2ProtocolGuid
,
571 if (EFI_ERROR (Status
)) {
576 // Read the config data from NV variable again.
577 // The default data can be changed by other drivers.
579 Status
= Ip4Config2ReadConfigData (IpSb
->MacString
, &IpSb
->Ip4Config2Instance
);
580 if (EFI_ERROR (Status
)) {
581 goto UNINSTALL_PROTOCOL
;
585 // Consume the installed EFI_IP4_CONFIG2_PROTOCOL to set the default data items.
587 for (Index
= Ip4Config2DataTypePolicy
; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
588 DataItem
= &IpSb
->Ip4Config2Instance
.DataItem
[Index
];
589 if (DataItem
->Data
.Ptr
!= NULL
) {
590 Status
= Ip4Cfg2
->SetData (
596 if (EFI_ERROR(Status
)) {
597 goto UNINSTALL_PROTOCOL
;
603 // Ready to go: start the receiving and timer.
604 // Ip4Config2SetPolicy maybe call Ip4ReceiveFrame() to set the default interface's RecvRequest first after
605 // Ip4Config2 instance is initialized. So, EFI_ALREADY_STARTED is the allowed return status.
607 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
609 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
610 goto UNINSTALL_PROTOCOL
;
613 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
615 if (EFI_ERROR (Status
)) {
616 goto UNINSTALL_PROTOCOL
;
620 // Initialize the IP4 ID
622 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
627 gBS
->UninstallProtocolInterface (
629 &gEfiIp4ServiceBindingProtocolGuid
,
630 &IpSb
->ServiceBinding
634 Ip4CleanService (IpSb
);
641 Stop this driver on ControllerHandle. This service is called by the
642 EFI boot service DisconnectController(). In order to
643 make drivers as small as possible, there are a few calling
644 restrictions for this service. DisconnectController()
645 must follow these calling restrictions. If any other agent wishes
646 to call Stop() it must also follow these calling restrictions.
648 @param[in] This Protocol instance pointer.
649 @param[in] ControllerHandle Handle of device to stop driver on
650 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
651 of children is zero stop the entire bus driver.
652 @param[in] ChildHandleBuffer List of Child Handles to Stop.
654 @retval EFI_SUCCESS This driver is removed ControllerHandle
655 @retval other This driver was not removed from this device
660 Ip4DriverBindingStop (
661 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
662 IN EFI_HANDLE ControllerHandle
,
663 IN UINTN NumberOfChildren
,
664 IN EFI_HANDLE
*ChildHandleBuffer
667 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
669 EFI_HANDLE NicHandle
;
673 IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
675 IP4_ROUTE_TABLE
*RouteTable
;
681 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
682 if (NicHandle
== NULL
) {
683 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
684 if (NicHandle
== NULL
) {
685 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
686 if (NicHandle
!= NULL
) {
694 Status
= gBS
->OpenProtocol (
696 &gEfiIp4ServiceBindingProtocolGuid
,
697 (VOID
**) &ServiceBinding
,
698 This
->DriverBindingHandle
,
700 EFI_OPEN_PROTOCOL_GET_PROTOCOL
702 if (EFI_ERROR (Status
)) {
703 return EFI_DEVICE_ERROR
;
706 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
709 Status
= Ip4Config2DestroyDhcp4 (&IpSb
->Ip4Config2Instance
);
710 gBS
->CloseEvent (IpSb
->Ip4Config2Instance
.Dhcp4Event
);
711 IpSb
->Ip4Config2Instance
.Dhcp4Event
= NULL
;
712 } else if (NumberOfChildren
!= 0) {
713 List
= &IpSb
->Children
;
714 Context
.ServiceBinding
= ServiceBinding
;
715 Context
.NumberOfChildren
= NumberOfChildren
;
716 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
717 Status
= NetDestroyLinkList (
719 Ip4DestroyChildEntryInHandleBuffer
,
723 } else if (IpSb
->DefaultInterface
->ArpHandle
== ControllerHandle
) {
726 // The ARP protocol for the default interface is being uninstalled and all
727 // its IP child handles should have been destroyed before. So, release the
728 // default interface and route table, create a new one and mark it as not started.
730 Ip4CancelReceive (IpSb
->DefaultInterface
);
731 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
732 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
734 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
738 RouteTable
= Ip4CreateRouteTable ();
739 if (RouteTable
== NULL
) {
740 Ip4FreeInterface (IpIf
, NULL
);
744 IpSb
->DefaultInterface
= IpIf
;
745 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
746 IpSb
->DefaultRouteTable
= RouteTable
;
747 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
749 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
751 } else if (IsListEmpty (&IpSb
->Children
)) {
753 IpSb
->State
= IP4_SERVICE_DESTROY
;
756 // OK, clean other resources then uninstall the service binding protocol.
758 Status
= Ip4CleanService (IpSb
);
759 if (EFI_ERROR (Status
)) {
764 gBS
->UninstallMultipleProtocolInterfaces (
766 &gEfiIp4ServiceBindingProtocolGuid
,
768 &gEfiIp4Config2ProtocolGuid
,
769 &IpSb
->Ip4Config2Instance
.Ip4Config2
,
773 if (gIp4ControllerNameTable
!= NULL
) {
774 FreeUnicodeStringTable (gIp4ControllerNameTable
);
775 gIp4ControllerNameTable
= NULL
;
786 Creates a child handle and installs a protocol.
788 The CreateChild() function installs a protocol on ChildHandle.
789 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
790 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
792 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
793 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
794 then a new handle is created. If it is a pointer to an existing UEFI handle,
795 then the protocol is added to the existing UEFI handle.
797 @retval EFI_SUCCES The protocol was added to ChildHandle.
798 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
799 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
801 @retval other The child handle was not created
806 Ip4ServiceBindingCreateChild (
807 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
808 IN OUT EFI_HANDLE
*ChildHandle
812 IP4_PROTOCOL
*IpInstance
;
817 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
818 return EFI_INVALID_PARAMETER
;
821 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
822 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
824 if (IpInstance
== NULL
) {
825 return EFI_OUT_OF_RESOURCES
;
828 Ip4InitProtocol (IpSb
, IpInstance
);
831 // Install Ip4 onto ChildHandle
833 Status
= gBS
->InstallMultipleProtocolInterfaces (
835 &gEfiIp4ProtocolGuid
,
836 &IpInstance
->Ip4Proto
,
840 if (EFI_ERROR (Status
)) {
844 IpInstance
->Handle
= *ChildHandle
;
847 // Open the Managed Network protocol BY_CHILD.
849 Status
= gBS
->OpenProtocol (
850 IpSb
->MnpChildHandle
,
851 &gEfiManagedNetworkProtocolGuid
,
853 gIp4DriverBinding
.DriverBindingHandle
,
855 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
857 if (EFI_ERROR (Status
)) {
858 gBS
->UninstallMultipleProtocolInterfaces (
860 &gEfiIp4ProtocolGuid
,
861 &IpInstance
->Ip4Proto
,
869 // Insert it into the service binding instance.
871 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
873 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
876 gBS
->RestoreTPL (OldTpl
);
880 if (EFI_ERROR (Status
)) {
882 Ip4CleanProtocol (IpInstance
);
884 FreePool (IpInstance
);
892 Destroys a child handle with a protocol installed on it.
894 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
895 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
896 last protocol on ChildHandle, then ChildHandle is destroyed.
898 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
899 @param ChildHandle Handle of the child to destroy
901 @retval EFI_SUCCES The protocol was removed from ChildHandle.
902 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
903 @retval EFI_INVALID_PARAMETER Child handle is NULL.
904 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
905 because its services are being used.
906 @retval other The child handle was not destroyed
911 Ip4ServiceBindingDestroyChild (
912 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
913 IN EFI_HANDLE ChildHandle
918 IP4_PROTOCOL
*IpInstance
;
919 EFI_IP4_PROTOCOL
*Ip4
;
923 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
924 return EFI_INVALID_PARAMETER
;
928 // Retrieve the private context data structures
930 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
932 Status
= gBS
->OpenProtocol (
934 &gEfiIp4ProtocolGuid
,
936 gIp4DriverBinding
.DriverBindingHandle
,
938 EFI_OPEN_PROTOCOL_GET_PROTOCOL
941 if (EFI_ERROR (Status
)) {
942 return EFI_UNSUPPORTED
;
945 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
947 if (IpInstance
->Service
!= IpSb
) {
948 return EFI_INVALID_PARAMETER
;
951 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
954 // A child can be destroyed more than once. For example,
955 // Ip4DriverBindingStop will destroy all of its children.
956 // when UDP driver is being stopped, it will destroy all
957 // the IP child it opens.
959 if (IpInstance
->State
== IP4_STATE_DESTROY
) {
960 gBS
->RestoreTPL (OldTpl
);
964 State
= IpInstance
->State
;
965 IpInstance
->State
= IP4_STATE_DESTROY
;
968 // Close the Managed Network protocol.
971 IpSb
->MnpChildHandle
,
972 &gEfiManagedNetworkProtocolGuid
,
973 gIp4DriverBinding
.DriverBindingHandle
,
977 if (IpInstance
->Interface
!= NULL
&& IpInstance
->Interface
->Arp
!= NULL
) {
979 IpInstance
->Interface
->ArpHandle
,
980 &gEfiArpProtocolGuid
,
981 gIp4DriverBinding
.DriverBindingHandle
,
987 // Uninstall the IP4 protocol first. Many thing happens during
989 // 1. The consumer of the IP4 protocol will be stopped if it
990 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
991 // stopped, IP driver's stop function will be called, and uninstall
992 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
993 // makes it possible to create the network stack bottom up, and
995 // 2. the upper layer will recycle the received packet. The recycle
996 // event's TPL is higher than this function. The recycle events
997 // will be called back before preceeding. If any packets not recycled,
998 // that means there is a resource leak.
1000 gBS
->RestoreTPL (OldTpl
);
1001 Status
= gBS
->UninstallProtocolInterface (
1003 &gEfiIp4ProtocolGuid
,
1004 &IpInstance
->Ip4Proto
1006 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1007 if (EFI_ERROR (Status
)) {
1011 Status
= Ip4CleanProtocol (IpInstance
);
1012 if (EFI_ERROR (Status
)) {
1013 gBS
->InstallMultipleProtocolInterfaces (
1015 &gEfiIp4ProtocolGuid
,
1023 RemoveEntryList (&IpInstance
->Link
);
1024 IpSb
->NumChildren
--;
1026 gBS
->RestoreTPL (OldTpl
);
1028 FreePool (IpInstance
);
1032 IpInstance
->State
= State
;
1033 gBS
->RestoreTPL (OldTpl
);