2 The driver binding and service binding protocol for IP4 driver.
4 Copyright (c) 2005 - 2015, 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 service 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
= AllocateZeroPool (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
));
213 IpSb
->ReconfigEvent
= NULL
;
215 IpSb
->MediaPresent
= TRUE
;
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
->MacString
= NULL
;
284 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
286 if (EFI_ERROR (Status
)) {
290 IpSb
->DefaultInterface
= Ip4CreateInterface (IpSb
->Mnp
, Controller
, ImageHandle
);
292 if (IpSb
->DefaultInterface
== NULL
) {
293 Status
= EFI_OUT_OF_RESOURCES
;
297 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
299 ZeroMem (&IpSb
->Ip4Config2Instance
, sizeof (IP4_CONFIG2_INSTANCE
));
301 Status
= Ip4Config2InitInstance (&IpSb
->Ip4Config2Instance
);
303 if (EFI_ERROR (Status
)) {
307 IpSb
->MaxPacketSize
= IpSb
->SnpMode
.MaxPacketSize
- sizeof (IP4_HEAD
);
308 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
310 // This is a VLAN device, reduce MTU by VLAN tag length
312 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
314 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
320 Ip4CleanService (IpSb
);
328 Clean up a IP4 service binding instance. It will release all
329 the resource allocated by the instance. The instance may be
330 partly initialized, or partly destroyed. If a resource is
331 destroyed, it is marked as that in case the destroy failed and
332 being called again later.
334 @param[in] IpSb The IP4 service binding instance to clean up
336 @retval EFI_SUCCESS The resource used by the instance are cleaned up
337 @retval other Failed to clean up some of the resources.
347 if (IpSb
->DefaultInterface
!= NULL
) {
348 Status
= Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
350 if (EFI_ERROR (Status
)) {
354 IpSb
->DefaultInterface
= NULL
;
357 if (IpSb
->DefaultRouteTable
!= NULL
) {
358 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
359 IpSb
->DefaultRouteTable
= NULL
;
362 Ip4CleanAssembleTable (&IpSb
->Assemble
);
364 if (IpSb
->MnpChildHandle
!= NULL
) {
365 if (IpSb
->Mnp
!= NULL
) {
367 IpSb
->MnpChildHandle
,
368 &gEfiManagedNetworkProtocolGuid
,
376 NetLibDestroyServiceChild (
379 &gEfiManagedNetworkServiceBindingProtocolGuid
,
383 IpSb
->MnpChildHandle
= NULL
;
386 if (IpSb
->Timer
!= NULL
) {
387 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
388 gBS
->CloseEvent (IpSb
->Timer
);
393 if (IpSb
->ReconfigEvent
!= NULL
) {
394 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
396 IpSb
->ReconfigEvent
= NULL
;
399 if (IpSb
->MacString
!= NULL
) {
400 FreePool (IpSb
->MacString
);
403 Ip4Config2CleanInstance (&IpSb
->Ip4Config2Instance
);
409 Callback function which provided by user to remove one node in NetDestroyLinkList process.
411 @param[in] Entry The entry to be removed.
412 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
414 @retval EFI_SUCCESS The entry has been removed successfully.
415 @retval Others Fail to remove the entry.
420 Ip4DestroyChildEntryInHandleBuffer (
421 IN LIST_ENTRY
*Entry
,
425 IP4_PROTOCOL
*IpInstance
;
426 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
427 UINTN NumberOfChildren
;
428 EFI_HANDLE
*ChildHandleBuffer
;
430 if (Entry
== NULL
|| Context
== NULL
) {
431 return EFI_INVALID_PARAMETER
;
434 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_PROTOCOL
, Link
, IP4_PROTOCOL_SIGNATURE
);
435 ServiceBinding
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
436 NumberOfChildren
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
437 ChildHandleBuffer
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
439 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
443 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
447 Start this driver on ControllerHandle. This service is called by the
448 EFI boot service ConnectController(). In order to make
449 drivers as small as possible, there are a few calling restrictions for
450 this service. ConnectController() must follow these
451 calling restrictions. If any other agent wishes to call Start() it
452 must also follow these calling restrictions.
454 @param[in] This Protocol instance pointer.
455 @param[in] ControllerHandle Handle of device to bind driver to
456 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
459 @retval EFI_SUCCESS This driver is added to ControllerHandle
460 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
461 @retval other This driver does not support this device
466 Ip4DriverBindingStart (
467 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
468 IN EFI_HANDLE ControllerHandle
,
469 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
476 // Test for the Ip4 service binding protocol
478 Status
= gBS
->OpenProtocol (
480 &gEfiIp4ServiceBindingProtocolGuid
,
482 This
->DriverBindingHandle
,
484 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
487 if (Status
== EFI_SUCCESS
) {
488 return EFI_ALREADY_STARTED
;
491 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
493 if (EFI_ERROR (Status
)) {
497 ASSERT (IpSb
!= NULL
);
500 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
502 Status
= gBS
->InstallMultipleProtocolInterfaces (
504 &gEfiIp4ServiceBindingProtocolGuid
,
505 &IpSb
->ServiceBinding
,
506 &gEfiIp4Config2ProtocolGuid
,
507 &IpSb
->Ip4Config2Instance
.Ip4Config2
,
511 if (EFI_ERROR (Status
)) {
516 // Ready to go: start the receiving and timer.
517 // Ip4Config2SetPolicy maybe call Ip4ReceiveFrame() to set the default interface's RecvRequest first after
518 // Ip4Config2 instance is initialized. So, EFI_ALREADY_STARTED is the allowed return status.
520 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
522 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
523 goto UNINSTALL_PROTOCOL
;
526 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
528 if (EFI_ERROR (Status
)) {
529 goto UNINSTALL_PROTOCOL
;
533 // Initialize the IP4 ID
535 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
540 gBS
->UninstallProtocolInterface (
542 &gEfiIp4ServiceBindingProtocolGuid
,
543 &IpSb
->ServiceBinding
547 Ip4CleanService (IpSb
);
554 Stop this driver on ControllerHandle. This service is called by the
555 EFI boot service DisconnectController(). In order to
556 make drivers as small as possible, there are a few calling
557 restrictions for this service. DisconnectController()
558 must follow these calling restrictions. If any other agent wishes
559 to call Stop() it must also follow these calling restrictions.
561 @param[in] This Protocol instance pointer.
562 @param[in] ControllerHandle Handle of device to stop driver on
563 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
564 of children is zero stop the entire bus driver.
565 @param[in] ChildHandleBuffer List of Child Handles to Stop.
567 @retval EFI_SUCCESS This driver is removed ControllerHandle
568 @retval other This driver was not removed from this device
573 Ip4DriverBindingStop (
574 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
575 IN EFI_HANDLE ControllerHandle
,
576 IN UINTN NumberOfChildren
,
577 IN EFI_HANDLE
*ChildHandleBuffer
580 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
582 EFI_HANDLE NicHandle
;
586 IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
588 IP4_ROUTE_TABLE
*RouteTable
;
594 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
595 if (NicHandle
== NULL
) {
596 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
597 if (NicHandle
== NULL
) {
598 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
599 if (NicHandle
!= NULL
) {
607 Status
= gBS
->OpenProtocol (
609 &gEfiIp4ServiceBindingProtocolGuid
,
610 (VOID
**) &ServiceBinding
,
611 This
->DriverBindingHandle
,
613 EFI_OPEN_PROTOCOL_GET_PROTOCOL
615 if (EFI_ERROR (Status
)) {
616 return EFI_DEVICE_ERROR
;
619 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
622 Status
= Ip4Config2DestroyDhcp4 (&IpSb
->Ip4Config2Instance
);
623 gBS
->CloseEvent (IpSb
->Ip4Config2Instance
.Dhcp4Event
);
624 IpSb
->Ip4Config2Instance
.Dhcp4Event
= NULL
;
625 } else if (NumberOfChildren
!= 0) {
626 List
= &IpSb
->Children
;
627 Context
.ServiceBinding
= ServiceBinding
;
628 Context
.NumberOfChildren
= NumberOfChildren
;
629 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
630 Status
= NetDestroyLinkList (
632 Ip4DestroyChildEntryInHandleBuffer
,
636 } else if (IpSb
->DefaultInterface
->ArpHandle
== ControllerHandle
) {
639 // The ARP protocol for the default interface is being uninstalled and all
640 // its IP child handles should have been destroyed before. So, release the
641 // default interface and route table, create a new one and mark it as not started.
643 Ip4CancelReceive (IpSb
->DefaultInterface
);
644 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
645 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
647 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
651 RouteTable
= Ip4CreateRouteTable ();
652 if (RouteTable
== NULL
) {
653 Ip4FreeInterface (IpIf
, NULL
);
657 IpSb
->DefaultInterface
= IpIf
;
658 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
659 IpSb
->DefaultRouteTable
= RouteTable
;
660 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
662 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
664 } else if (IsListEmpty (&IpSb
->Children
)) {
666 IpSb
->State
= IP4_SERVICE_DESTROY
;
669 // OK, clean other resources then uninstall the service binding protocol.
671 Status
= Ip4CleanService (IpSb
);
672 if (EFI_ERROR (Status
)) {
677 gBS
->UninstallMultipleProtocolInterfaces (
679 &gEfiIp4ServiceBindingProtocolGuid
,
681 &gEfiIp4Config2ProtocolGuid
,
682 &IpSb
->Ip4Config2Instance
.Ip4Config2
,
686 if (gIp4ControllerNameTable
!= NULL
) {
687 FreeUnicodeStringTable (gIp4ControllerNameTable
);
688 gIp4ControllerNameTable
= NULL
;
699 Creates a child handle and installs a protocol.
701 The CreateChild() function installs a protocol on ChildHandle.
702 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
703 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
705 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
706 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
707 then a new handle is created. If it is a pointer to an existing UEFI handle,
708 then the protocol is added to the existing UEFI handle.
710 @retval EFI_SUCCES The protocol was added to ChildHandle.
711 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
712 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
714 @retval other The child handle was not created
719 Ip4ServiceBindingCreateChild (
720 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
721 IN OUT EFI_HANDLE
*ChildHandle
725 IP4_PROTOCOL
*IpInstance
;
730 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
731 return EFI_INVALID_PARAMETER
;
734 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
735 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
737 if (IpInstance
== NULL
) {
738 return EFI_OUT_OF_RESOURCES
;
741 Ip4InitProtocol (IpSb
, IpInstance
);
744 // Install Ip4 onto ChildHandle
746 Status
= gBS
->InstallMultipleProtocolInterfaces (
748 &gEfiIp4ProtocolGuid
,
749 &IpInstance
->Ip4Proto
,
753 if (EFI_ERROR (Status
)) {
757 IpInstance
->Handle
= *ChildHandle
;
760 // Open the Managed Network protocol BY_CHILD.
762 Status
= gBS
->OpenProtocol (
763 IpSb
->MnpChildHandle
,
764 &gEfiManagedNetworkProtocolGuid
,
766 gIp4DriverBinding
.DriverBindingHandle
,
768 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
770 if (EFI_ERROR (Status
)) {
771 gBS
->UninstallMultipleProtocolInterfaces (
773 &gEfiIp4ProtocolGuid
,
774 &IpInstance
->Ip4Proto
,
782 // Insert it into the service binding instance.
784 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
786 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
789 gBS
->RestoreTPL (OldTpl
);
793 if (EFI_ERROR (Status
)) {
795 Ip4CleanProtocol (IpInstance
);
797 FreePool (IpInstance
);
805 Destroys a child handle with a protocol installed on it.
807 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
808 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
809 last protocol on ChildHandle, then ChildHandle is destroyed.
811 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
812 @param ChildHandle Handle of the child to destroy
814 @retval EFI_SUCCES The protocol was removed from ChildHandle.
815 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
816 @retval EFI_INVALID_PARAMETER Child handle is NULL.
817 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
818 because its services are being used.
819 @retval other The child handle was not destroyed
824 Ip4ServiceBindingDestroyChild (
825 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
826 IN EFI_HANDLE ChildHandle
831 IP4_PROTOCOL
*IpInstance
;
832 EFI_IP4_PROTOCOL
*Ip4
;
836 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
837 return EFI_INVALID_PARAMETER
;
841 // Retrieve the private context data structures
843 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
845 Status
= gBS
->OpenProtocol (
847 &gEfiIp4ProtocolGuid
,
849 gIp4DriverBinding
.DriverBindingHandle
,
851 EFI_OPEN_PROTOCOL_GET_PROTOCOL
854 if (EFI_ERROR (Status
)) {
855 return EFI_UNSUPPORTED
;
858 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
860 if (IpInstance
->Service
!= IpSb
) {
861 return EFI_INVALID_PARAMETER
;
864 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
867 // A child can be destroyed more than once. For example,
868 // Ip4DriverBindingStop will destroy all of its children.
869 // when UDP driver is being stopped, it will destroy all
870 // the IP child it opens.
872 if (IpInstance
->State
== IP4_STATE_DESTROY
) {
873 gBS
->RestoreTPL (OldTpl
);
877 State
= IpInstance
->State
;
878 IpInstance
->State
= IP4_STATE_DESTROY
;
881 // Close the Managed Network protocol.
884 IpSb
->MnpChildHandle
,
885 &gEfiManagedNetworkProtocolGuid
,
886 gIp4DriverBinding
.DriverBindingHandle
,
890 if (IpInstance
->Interface
!= NULL
&& IpInstance
->Interface
->Arp
!= NULL
) {
892 IpInstance
->Interface
->ArpHandle
,
893 &gEfiArpProtocolGuid
,
894 gIp4DriverBinding
.DriverBindingHandle
,
900 // Uninstall the IP4 protocol first. Many thing happens during
902 // 1. The consumer of the IP4 protocol will be stopped if it
903 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
904 // stopped, IP driver's stop function will be called, and uninstall
905 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
906 // makes it possible to create the network stack bottom up, and
908 // 2. the upper layer will recycle the received packet. The recycle
909 // event's TPL is higher than this function. The recycle events
910 // will be called back before preceeding. If any packets not recycled,
911 // that means there is a resource leak.
913 gBS
->RestoreTPL (OldTpl
);
914 Status
= gBS
->UninstallProtocolInterface (
916 &gEfiIp4ProtocolGuid
,
917 &IpInstance
->Ip4Proto
919 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
920 if (EFI_ERROR (Status
)) {
924 Status
= Ip4CleanProtocol (IpInstance
);
925 if (EFI_ERROR (Status
)) {
926 gBS
->InstallMultipleProtocolInterfaces (
928 &gEfiIp4ProtocolGuid
,
936 RemoveEntryList (&IpInstance
->Link
);
939 gBS
->RestoreTPL (OldTpl
);
941 FreePool (IpInstance
);
945 IpInstance
->State
= State
;
946 gBS
->RestoreTPL (OldTpl
);