2 The driver binding and service binding protocol for IP4 driver.
4 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding
= {
18 Ip4DriverBindingSupported
,
19 Ip4DriverBindingStart
,
27 This is the declaration of an EFI image entry point. This entry point is
28 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
29 both device drivers and bus drivers.
31 The entry point for IP4 driver which install the driver
32 binding and component name protocol on its image.
34 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
35 @param[in] SystemTable A pointer to the EFI System Table.
37 @retval EFI_SUCCESS The operation completed successfully.
38 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
44 IN EFI_HANDLE ImageHandle
,
45 IN EFI_SYSTEM_TABLE
*SystemTable
48 return EfiLibInstallDriverBindingComponentName2 (
59 Test to see if this driver supports ControllerHandle. This service
60 is called by the EFI boot service ConnectController(). In
61 order to make drivers as small as possible, there are a few calling
62 restrictions for this service. ConnectController() must
63 follow these calling restrictions. If any other agent wishes to call
64 Supported() it must also follow these calling restrictions.
66 @param[in] This Protocol instance pointer.
67 @param[in] ControllerHandle Handle of device to test
68 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
71 @retval EFI_SUCCESS This driver supports this device
72 @retval EFI_ALREADY_STARTED This driver is already running on this device
73 @retval other This driver does not support this device
78 Ip4DriverBindingSupported (
79 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
80 IN EFI_HANDLE ControllerHandle
,
81 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
87 // Test for the MNP service binding Protocol
89 Status
= gBS
->OpenProtocol (
91 &gEfiManagedNetworkServiceBindingProtocolGuid
,
93 This
->DriverBindingHandle
,
95 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
98 if (EFI_ERROR (Status
)) {
103 // Test for the Arp service binding Protocol
105 Status
= gBS
->OpenProtocol (
107 &gEfiArpServiceBindingProtocolGuid
,
109 This
->DriverBindingHandle
,
111 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
118 Clean up a IP4 service binding instance. It will release all
119 the resource allocated by the instance. The instance may be
120 partly initialized, or partly destroyed. If a resource is
121 destroyed, it is marked as that in case the destroy failed and
122 being called again later.
124 @param[in] IpSb The IP4 serviceing binding instance to clean up
126 @retval EFI_SUCCESS The resource used by the instance are cleaned up
127 @retval other Failed to clean up some of the resources.
137 Create a new IP4 driver service binding private instance.
139 @param Controller The controller that has MNP service binding
141 @param ImageHandle The IP4 driver's image handle
142 @param Service The variable to receive the newly created IP4
145 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resource
146 @retval EFI_SUCCESS A new IP4 service binding private is created.
147 @retval other Other error occurs.
152 IN EFI_HANDLE Controller
,
153 IN EFI_HANDLE ImageHandle
,
154 OUT IP4_SERVICE
**Service
160 ASSERT (Service
!= NULL
);
165 // allocate a service private data then initialize all the filed to
166 // empty resources, so if any thing goes wrong when allocating
167 // resources, Ip4CleanService can be called to clean it up.
169 IpSb
= AllocatePool (sizeof (IP4_SERVICE
));
172 return EFI_OUT_OF_RESOURCES
;
175 IpSb
->Signature
= IP4_SERVICE_SIGNATURE
;
176 IpSb
->ServiceBinding
.CreateChild
= Ip4ServiceBindingCreateChild
;
177 IpSb
->ServiceBinding
.DestroyChild
= Ip4ServiceBindingDestroyChild
;
178 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
180 IpSb
->NumChildren
= 0;
181 InitializeListHead (&IpSb
->Children
);
183 InitializeListHead (&IpSb
->Interfaces
);
184 IpSb
->DefaultInterface
= NULL
;
185 IpSb
->DefaultRouteTable
= NULL
;
187 Ip4InitAssembleTable (&IpSb
->Assemble
);
189 IpSb
->IgmpCtrl
.Igmpv1QuerySeen
= 0;
190 InitializeListHead (&IpSb
->IgmpCtrl
.Groups
);
192 IpSb
->Image
= ImageHandle
;
193 IpSb
->Controller
= Controller
;
195 IpSb
->MnpChildHandle
= NULL
;
198 IpSb
->MnpConfigData
.ReceivedQueueTimeoutValue
= 0;
199 IpSb
->MnpConfigData
.TransmitQueueTimeoutValue
= 0;
200 IpSb
->MnpConfigData
.ProtocolTypeFilter
= IP4_ETHER_PROTO
;
201 IpSb
->MnpConfigData
.EnableUnicastReceive
= TRUE
;
202 IpSb
->MnpConfigData
.EnableMulticastReceive
= TRUE
;
203 IpSb
->MnpConfigData
.EnableBroadcastReceive
= TRUE
;
204 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= FALSE
;
205 IpSb
->MnpConfigData
.FlushQueuesOnReset
= TRUE
;
206 IpSb
->MnpConfigData
.EnableReceiveTimestamps
= FALSE
;
207 IpSb
->MnpConfigData
.DisableBackgroundPolling
= FALSE
;
209 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
212 IpSb
->Ip4Config
= NULL
;
213 IpSb
->DoneEvent
= NULL
;
214 IpSb
->ReconfigEvent
= NULL
;
215 IpSb
->ActiveEvent
= NULL
;
218 // Create various resources. First create the route table, timer
219 // event and MNP child. IGMP, interface's initialization depend
222 IpSb
->DefaultRouteTable
= Ip4CreateRouteTable ();
224 if (IpSb
->DefaultRouteTable
== NULL
) {
225 Status
= EFI_OUT_OF_RESOURCES
;
229 Status
= gBS
->CreateEvent (
230 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
237 if (EFI_ERROR (Status
)) {
241 Status
= NetLibCreateServiceChild (
244 &gEfiManagedNetworkServiceBindingProtocolGuid
,
245 &IpSb
->MnpChildHandle
248 if (EFI_ERROR (Status
)) {
252 Status
= gBS
->OpenProtocol (
253 IpSb
->MnpChildHandle
,
254 &gEfiManagedNetworkProtocolGuid
,
255 (VOID
**) &IpSb
->Mnp
,
258 EFI_OPEN_PROTOCOL_BY_DRIVER
261 if (EFI_ERROR (Status
)) {
265 Status
= Ip4ServiceConfigMnp (IpSb
, TRUE
);
267 if (EFI_ERROR (Status
)) {
271 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
273 if (EFI_ERROR (Status
)) {
277 Status
= Ip4InitIgmp (IpSb
);
279 if (EFI_ERROR (Status
)) {
283 IpSb
->DefaultInterface
= Ip4CreateInterface (IpSb
->Mnp
, Controller
, ImageHandle
);
285 if (IpSb
->DefaultInterface
== NULL
) {
286 Status
= EFI_OUT_OF_RESOURCES
;
290 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
292 IpSb
->MaxPacketSize
= IpSb
->SnpMode
.MaxPacketSize
- sizeof (IP4_HEAD
);
293 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
295 // This is a VLAN device, reduce MTU by VLAN tag length
297 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
299 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
300 IpSb
->MacString
= NULL
;
306 Ip4CleanService (IpSb
);
314 Clean up a IP4 service binding instance. It will release all
315 the resource allocated by the instance. The instance may be
316 partly initialized, or partly destroyed. If a resource is
317 destroyed, it is marked as that in case the destroy failed and
318 being called again later.
320 @param[in] IpSb The IP4 serviceing binding instance to clean up
322 @retval EFI_SUCCESS The resource used by the instance are cleaned up
323 @retval other Failed to clean up some of the resources.
333 if (IpSb
->DefaultInterface
!= NULL
) {
334 Status
= Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
336 if (EFI_ERROR (Status
)) {
340 IpSb
->DefaultInterface
= NULL
;
343 if (IpSb
->DefaultRouteTable
!= NULL
) {
344 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
345 IpSb
->DefaultRouteTable
= NULL
;
348 Ip4CleanAssembleTable (&IpSb
->Assemble
);
350 if (IpSb
->MnpChildHandle
!= NULL
) {
351 if (IpSb
->Mnp
!= NULL
) {
353 IpSb
->MnpChildHandle
,
354 &gEfiManagedNetworkProtocolGuid
,
362 NetLibDestroyServiceChild (
365 &gEfiManagedNetworkServiceBindingProtocolGuid
,
369 IpSb
->MnpChildHandle
= NULL
;
372 if (IpSb
->Timer
!= NULL
) {
373 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
374 gBS
->CloseEvent (IpSb
->Timer
);
379 if (IpSb
->Ip4Config
!= NULL
) {
380 IpSb
->Ip4Config
->Stop (IpSb
->Ip4Config
);
384 &gEfiIp4ConfigProtocolGuid
,
389 gBS
->CloseEvent (IpSb
->DoneEvent
);
390 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
391 IpSb
->ActiveEvent
= NULL
;
392 IpSb
->Ip4Config
= NULL
;
399 Callback function which provided by user to remove one node in NetDestroyLinkList process.
401 @param[in] Entry The entry to be removed.
402 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
404 @retval EFI_SUCCESS The entry has been removed successfully.
405 @retval Others Fail to remove the entry.
410 Ip4DestroyChildEntryInHandleBuffer (
411 IN LIST_ENTRY
*Entry
,
415 IP4_PROTOCOL
*IpInstance
;
416 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
417 UINTN NumberOfChildren
;
418 EFI_HANDLE
*ChildHandleBuffer
;
420 if (Entry
== NULL
|| Context
== NULL
) {
421 return EFI_INVALID_PARAMETER
;
424 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_PROTOCOL
, Link
, IP4_PROTOCOL_SIGNATURE
);
425 ServiceBinding
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
426 NumberOfChildren
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
427 ChildHandleBuffer
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
429 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
433 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
437 Start this driver on ControllerHandle. This service is called by the
438 EFI boot service ConnectController(). In order to make
439 drivers as small as possible, there are a few calling restrictions for
440 this service. ConnectController() must follow these
441 calling restrictions. If any other agent wishes to call Start() it
442 must also follow these calling restrictions.
444 @param[in] This Protocol instance pointer.
445 @param[in] ControllerHandle Handle of device to bind driver to
446 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
449 @retval EFI_SUCCESS This driver is added to ControllerHandle
450 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
451 @retval other This driver does not support this device
456 Ip4DriverBindingStart (
457 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
458 IN EFI_HANDLE ControllerHandle
,
459 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
466 // Test for the Ip4 service binding protocol
468 Status
= gBS
->OpenProtocol (
470 &gEfiIp4ServiceBindingProtocolGuid
,
472 This
->DriverBindingHandle
,
474 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
477 if (Status
== EFI_SUCCESS
) {
478 return EFI_ALREADY_STARTED
;
481 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
483 if (EFI_ERROR (Status
)) {
486 ASSERT (IpSb
!= NULL
);
489 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
491 Status
= gBS
->InstallMultipleProtocolInterfaces (
493 &gEfiIp4ServiceBindingProtocolGuid
,
494 &IpSb
->ServiceBinding
,
498 if (EFI_ERROR (Status
)) {
503 // ready to go: start the receiving and timer
505 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
507 if (EFI_ERROR (Status
)) {
508 goto UNINSTALL_PROTOCOL
;
511 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
513 if (EFI_ERROR (Status
)) {
514 goto UNINSTALL_PROTOCOL
;
518 // Initialize the IP4 ID
520 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
522 Ip4SetVariableData (IpSb
);
527 gBS
->UninstallProtocolInterface (
529 &gEfiIp4ServiceBindingProtocolGuid
,
530 &IpSb
->ServiceBinding
534 Ip4CleanService (IpSb
);
542 Stop this driver on ControllerHandle. This service is called by the
543 EFI boot service DisconnectController(). In order to
544 make drivers as small as possible, there are a few calling
545 restrictions for this service. DisconnectController()
546 must follow these calling restrictions. If any other agent wishes
547 to call Stop() it must also follow these calling restrictions.
549 @param[in] This Protocol instance pointer.
550 @param[in] ControllerHandle Handle of device to stop driver on
551 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
552 of children is zero stop the entire bus driver.
553 @param[in] ChildHandleBuffer List of Child Handles to Stop.
555 @retval EFI_SUCCESS This driver is removed ControllerHandle
556 @retval other This driver was not removed from this device
561 Ip4DriverBindingStop (
562 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
563 IN EFI_HANDLE ControllerHandle
,
564 IN UINTN NumberOfChildren
,
565 IN EFI_HANDLE
*ChildHandleBuffer
568 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
570 EFI_HANDLE NicHandle
;
574 IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
577 // IP4 driver opens the MNP child, ARP children or the IP4_CONFIG protocol
578 // by driver. So the ControllerHandle may be the MNP child handle, ARP child
579 // handle, or the NIC (UNDI) handle because IP4_CONFIG protocol is installed
580 // in the NIC handle.
583 // First, check whether it is the IP4_CONFIG protocol being uninstalled.
584 // IP4_CONFIG protocol is installed on the NIC handle. It isn't necessary
585 // to clean up the default configuration if IP4_CONFIG is being stopped.
587 Status
= gBS
->OpenProtocol (
589 &gEfiIp4ConfigProtocolGuid
,
591 This
->DriverBindingHandle
,
593 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
595 if (Status
== EFI_SUCCESS
) {
597 // Retrieve the IP4 service binding protocol. If failed, it is
598 // likely that Ip4 ServiceBinding is uninstalled already. In this
599 // case, return immediately.
601 Status
= gBS
->OpenProtocol (
603 &gEfiIp4ServiceBindingProtocolGuid
,
604 (VOID
**) &ServiceBinding
,
605 This
->DriverBindingHandle
,
607 EFI_OPEN_PROTOCOL_GET_PROTOCOL
609 if (EFI_ERROR (Status
)) {
610 return EFI_DEVICE_ERROR
;
613 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
614 if (IpSb
->Ip4Config
!= NULL
&& (IpSb
->State
!= IP4_SERVICE_DESTROY
)) {
616 IpSb
->Ip4Config
->Stop (IpSb
->Ip4Config
);
618 Status
= gBS
->CloseProtocol (
620 &gEfiIp4ConfigProtocolGuid
,
624 if (EFI_ERROR (Status
)) {
629 // If the auto configure hasn't complete, mark it as not started.
631 if (IpSb
->State
== IP4_SERVICE_STARTED
) {
632 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
635 IpSb
->Ip4Config
= NULL
;
636 gBS
->CloseEvent (IpSb
->DoneEvent
);
637 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
644 // Either MNP or ARP protocol is being uninstalled. The controller
645 // handle is either the MNP child or ARP child. But, the IP4's
646 // service binding is installed on the NIC handle. So, need to open
647 // the protocol info to find the NIC handle.
649 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
650 if (NicHandle
== NULL
) {
651 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
652 if (NicHandle
== NULL
) {
658 // Retrieve the IP4 service binding protocol
660 Status
= gBS
->OpenProtocol (
662 &gEfiIp4ServiceBindingProtocolGuid
,
663 (VOID
**) &ServiceBinding
,
664 This
->DriverBindingHandle
,
666 EFI_OPEN_PROTOCOL_GET_PROTOCOL
668 if (EFI_ERROR (Status
)) {
669 return EFI_DEVICE_ERROR
;
672 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
673 if (NumberOfChildren
!= 0) {
674 List
= &IpSb
->Children
;
675 Context
.ServiceBinding
= ServiceBinding
;
676 Context
.NumberOfChildren
= NumberOfChildren
;
677 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
678 Status
= NetDestroyLinkList (
680 Ip4DestroyChildEntryInHandleBuffer
,
684 } else if (IsListEmpty (&IpSb
->Children
)) {
686 IpSb
->State
= IP4_SERVICE_DESTROY
;
689 // Clear the variable data.
691 Ip4ClearVariableData (IpSb
);
694 // OK, clean other resources then uninstall the service binding protocol.
696 Status
= Ip4CleanService (IpSb
);
697 if (EFI_ERROR (Status
)) {
702 gBS
->UninstallProtocolInterface (
704 &gEfiIp4ServiceBindingProtocolGuid
,
708 if (gIp4ControllerNameTable
!= NULL
) {
709 FreeUnicodeStringTable (gIp4ControllerNameTable
);
710 gIp4ControllerNameTable
= NULL
;
721 Creates a child handle and installs a protocol.
723 The CreateChild() function installs a protocol on ChildHandle.
724 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
725 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
727 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
728 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
729 then a new handle is created. If it is a pointer to an existing UEFI handle,
730 then the protocol is added to the existing UEFI handle.
732 @retval EFI_SUCCES The protocol was added to ChildHandle.
733 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
734 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
736 @retval other The child handle was not created
741 Ip4ServiceBindingCreateChild (
742 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
743 IN OUT EFI_HANDLE
*ChildHandle
747 IP4_PROTOCOL
*IpInstance
;
752 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
753 return EFI_INVALID_PARAMETER
;
756 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
757 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
759 if (IpInstance
== NULL
) {
760 return EFI_OUT_OF_RESOURCES
;
763 Ip4InitProtocol (IpSb
, IpInstance
);
766 // Install Ip4 onto ChildHandle
768 Status
= gBS
->InstallMultipleProtocolInterfaces (
770 &gEfiIp4ProtocolGuid
,
771 &IpInstance
->Ip4Proto
,
775 if (EFI_ERROR (Status
)) {
779 IpInstance
->Handle
= *ChildHandle
;
782 // Open the Managed Network protocol BY_CHILD.
784 Status
= gBS
->OpenProtocol (
785 IpSb
->MnpChildHandle
,
786 &gEfiManagedNetworkProtocolGuid
,
788 gIp4DriverBinding
.DriverBindingHandle
,
790 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
792 if (EFI_ERROR (Status
)) {
793 gBS
->UninstallMultipleProtocolInterfaces (
795 &gEfiIp4ProtocolGuid
,
796 &IpInstance
->Ip4Proto
,
804 // Insert it into the service binding instance.
806 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
808 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
811 gBS
->RestoreTPL (OldTpl
);
815 if (EFI_ERROR (Status
)) {
817 Ip4CleanProtocol (IpInstance
);
819 FreePool (IpInstance
);
827 Destroys a child handle with a protocol installed on it.
829 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
830 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
831 last protocol on ChildHandle, then ChildHandle is destroyed.
833 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
834 @param ChildHandle Handle of the child to destroy
836 @retval EFI_SUCCES The protocol was removed from ChildHandle.
837 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
838 @retval EFI_INVALID_PARAMETER Child handle is NULL.
839 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
840 because its services are being used.
841 @retval other The child handle was not destroyed
846 Ip4ServiceBindingDestroyChild (
847 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
848 IN EFI_HANDLE ChildHandle
853 IP4_PROTOCOL
*IpInstance
;
854 EFI_IP4_PROTOCOL
*Ip4
;
858 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
859 return EFI_INVALID_PARAMETER
;
863 // Retrieve the private context data structures
865 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
867 Status
= gBS
->OpenProtocol (
869 &gEfiIp4ProtocolGuid
,
871 gIp4DriverBinding
.DriverBindingHandle
,
873 EFI_OPEN_PROTOCOL_GET_PROTOCOL
876 if (EFI_ERROR (Status
)) {
877 return EFI_UNSUPPORTED
;
880 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
882 if (IpInstance
->Service
!= IpSb
) {
883 return EFI_INVALID_PARAMETER
;
886 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
889 // A child can be destroyed more than once. For example,
890 // Ip4DriverBindingStop will destroy all of its children.
891 // when UDP driver is being stopped, it will destroy all
892 // the IP child it opens.
894 if (IpInstance
->State
== IP4_STATE_DESTROY
) {
895 gBS
->RestoreTPL (OldTpl
);
899 State
= IpInstance
->State
;
900 IpInstance
->State
= IP4_STATE_DESTROY
;
903 // Close the Managed Network protocol.
906 IpSb
->MnpChildHandle
,
907 &gEfiManagedNetworkProtocolGuid
,
908 gIp4DriverBinding
.DriverBindingHandle
,
912 if (IpInstance
->Interface
!= NULL
&& IpInstance
->Interface
->Arp
!= NULL
) {
914 IpInstance
->Interface
->ArpHandle
,
915 &gEfiArpProtocolGuid
,
916 gIp4DriverBinding
.DriverBindingHandle
,
922 // Uninstall the IP4 protocol first. Many thing happens during
924 // 1. The consumer of the IP4 protocol will be stopped if it
925 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
926 // stopped, IP driver's stop function will be called, and uninstall
927 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
928 // makes it possible to create the network stack bottom up, and
930 // 2. the upper layer will recycle the received packet. The recycle
931 // event's TPL is higher than this function. The recycle events
932 // will be called back before preceeding. If any packets not recycled,
933 // that means there is a resource leak.
935 gBS
->RestoreTPL (OldTpl
);
936 Status
= gBS
->UninstallProtocolInterface (
938 &gEfiIp4ProtocolGuid
,
939 &IpInstance
->Ip4Proto
941 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
942 if (EFI_ERROR (Status
)) {
946 Status
= Ip4CleanProtocol (IpInstance
);
948 Ip4SetVariableData (IpSb
);
950 if (EFI_ERROR (Status
)) {
951 gBS
->InstallMultipleProtocolInterfaces (
953 &gEfiIp4ProtocolGuid
,
961 RemoveEntryList (&IpInstance
->Link
);
964 gBS
->RestoreTPL (OldTpl
);
966 FreePool (IpInstance
);
970 IpInstance
->State
= State
;
971 gBS
->RestoreTPL (OldTpl
);