2 The driver binding and service binding protocol for IP4 driver.
4 Copyright (c) 2005 - 2009, Intel Corporation.<BR>
5 All rights reserved. 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 destory 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
;
179 IpSb
->InDestory
= FALSE
;
181 IpSb
->NumChildren
= 0;
182 InitializeListHead (&IpSb
->Children
);
184 InitializeListHead (&IpSb
->Interfaces
);
185 IpSb
->DefaultInterface
= NULL
;
186 IpSb
->DefaultRouteTable
= NULL
;
188 Ip4InitAssembleTable (&IpSb
->Assemble
);
190 IpSb
->IgmpCtrl
.Igmpv1QuerySeen
= 0;
191 InitializeListHead (&IpSb
->IgmpCtrl
.Groups
);
193 IpSb
->Image
= ImageHandle
;
194 IpSb
->Controller
= Controller
;
196 IpSb
->MnpChildHandle
= NULL
;
199 IpSb
->MnpConfigData
.ReceivedQueueTimeoutValue
= 0;
200 IpSb
->MnpConfigData
.TransmitQueueTimeoutValue
= 0;
201 IpSb
->MnpConfigData
.ProtocolTypeFilter
= IP4_ETHER_PROTO
;
202 IpSb
->MnpConfigData
.EnableUnicastReceive
= TRUE
;
203 IpSb
->MnpConfigData
.EnableMulticastReceive
= TRUE
;
204 IpSb
->MnpConfigData
.EnableBroadcastReceive
= TRUE
;
205 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= FALSE
;
206 IpSb
->MnpConfigData
.FlushQueuesOnReset
= TRUE
;
207 IpSb
->MnpConfigData
.EnableReceiveTimestamps
= FALSE
;
208 IpSb
->MnpConfigData
.DisableBackgroundPolling
= FALSE
;
210 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
213 IpSb
->Ip4Config
= NULL
;
214 IpSb
->DoneEvent
= NULL
;
215 IpSb
->ReconfigEvent
= NULL
;
216 IpSb
->ActiveEvent
= NULL
;
219 // Create various resources. First create the route table, timer
220 // event and MNP child. IGMP, interface's initialization depend
223 IpSb
->DefaultRouteTable
= Ip4CreateRouteTable ();
225 if (IpSb
->DefaultRouteTable
== NULL
) {
226 Status
= EFI_OUT_OF_RESOURCES
;
230 Status
= gBS
->CreateEvent (
231 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
238 if (EFI_ERROR (Status
)) {
242 Status
= NetLibCreateServiceChild (
245 &gEfiManagedNetworkServiceBindingProtocolGuid
,
246 &IpSb
->MnpChildHandle
249 if (EFI_ERROR (Status
)) {
253 Status
= gBS
->OpenProtocol (
254 IpSb
->MnpChildHandle
,
255 &gEfiManagedNetworkProtocolGuid
,
256 (VOID
**) &IpSb
->Mnp
,
259 EFI_OPEN_PROTOCOL_BY_DRIVER
262 if (EFI_ERROR (Status
)) {
266 Status
= Ip4ServiceConfigMnp (IpSb
, TRUE
);
268 if (EFI_ERROR (Status
)) {
272 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
274 if (EFI_ERROR (Status
)) {
278 Status
= Ip4InitIgmp (IpSb
);
280 if (EFI_ERROR (Status
)) {
284 IpSb
->DefaultInterface
= Ip4CreateInterface (IpSb
->Mnp
, Controller
, ImageHandle
);
286 if (IpSb
->DefaultInterface
== NULL
) {
287 Status
= EFI_OUT_OF_RESOURCES
;
291 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
293 IpSb
->MaxPacketSize
= IpSb
->SnpMode
.MaxPacketSize
- sizeof (IP4_HEAD
);
294 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
296 // This is a VLAN device, reduce MTU by VLAN tag length
298 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
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 destory 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
;
400 Start this driver on ControllerHandle. This service is called by the
401 EFI boot service ConnectController(). In order to make
402 drivers as small as possible, there are a few calling restrictions for
403 this service. ConnectController() must follow these
404 calling restrictions. If any other agent wishes to call Start() it
405 must also follow these calling restrictions.
407 @param[in] This Protocol instance pointer.
408 @param[in] ControllerHandle Handle of device to bind driver to
409 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
412 @retval EFI_SUCCESS This driver is added to ControllerHandle
413 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
414 @retval other This driver does not support this device
419 Ip4DriverBindingStart (
420 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
421 IN EFI_HANDLE ControllerHandle
,
422 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
429 // Test for the Ip4 service binding protocol
431 Status
= gBS
->OpenProtocol (
433 &gEfiIp4ServiceBindingProtocolGuid
,
435 This
->DriverBindingHandle
,
437 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
440 if (Status
== EFI_SUCCESS
) {
441 return EFI_ALREADY_STARTED
;
444 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
446 if (EFI_ERROR (Status
)) {
451 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
453 Status
= gBS
->InstallMultipleProtocolInterfaces (
455 &gEfiIp4ServiceBindingProtocolGuid
,
456 &IpSb
->ServiceBinding
,
460 if (EFI_ERROR (Status
)) {
465 // ready to go: start the receiving and timer
467 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
469 if (EFI_ERROR (Status
)) {
470 goto UNINSTALL_PROTOCOL
;
473 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
475 if (EFI_ERROR (Status
)) {
476 goto UNINSTALL_PROTOCOL
;
480 // Initialize the IP4 ID
482 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
484 Ip4SetVariableData (IpSb
);
489 gBS
->UninstallProtocolInterface (
491 &gEfiIp4ServiceBindingProtocolGuid
,
492 &IpSb
->ServiceBinding
496 Ip4CleanService (IpSb
);
504 Stop this driver on ControllerHandle. This service is called by the
505 EFI boot service DisconnectController(). In order to
506 make drivers as small as possible, there are a few calling
507 restrictions for this service. DisconnectController()
508 must follow these calling restrictions. If any other agent wishes
509 to call Stop() it must also follow these calling restrictions.
511 @param[in] This Protocol instance pointer.
512 @param[in] ControllerHandle Handle of device to stop driver on
513 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
514 of children is zero stop the entire bus driver.
515 @param[in] ChildHandleBuffer List of Child Handles to Stop.
517 @retval EFI_SUCCESS This driver is removed ControllerHandle
518 @retval other This driver was not removed from this device
523 Ip4DriverBindingStop (
524 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
525 IN EFI_HANDLE ControllerHandle
,
526 IN UINTN NumberOfChildren
,
527 IN EFI_HANDLE
*ChildHandleBuffer
530 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
532 IP4_PROTOCOL
*IpInstance
;
533 EFI_HANDLE NicHandle
;
540 // IP4 driver opens the MNP child, ARP children or the IP4_CONFIG protocol
541 // by driver. So the ControllerHandle may be the MNP child handle, ARP child
542 // handle, or the NIC (UNDI) handle because IP4_CONFIG protocol is installed
543 // in the NIC handle.
546 // First, check whether it is the IP4_CONFIG protocol being uninstalled.
547 // IP4_CONFIG protocol is installed on the NIC handle. It isn't necessary
548 // to clean up the default configuration if IP4_CONFIG is being stopped.
550 Status
= gBS
->OpenProtocol (
552 &gEfiIp4ConfigProtocolGuid
,
554 This
->DriverBindingHandle
,
556 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
559 if (Status
== EFI_SUCCESS
) {
561 // Retrieve the IP4 service binding protocol. If failed, it is
562 // likely that Ip4 ServiceBinding is uninstalled already. In this
563 // case, return immediately.
565 Status
= gBS
->OpenProtocol (
567 &gEfiIp4ServiceBindingProtocolGuid
,
568 (VOID
**) &ServiceBinding
,
569 This
->DriverBindingHandle
,
571 EFI_OPEN_PROTOCOL_GET_PROTOCOL
574 if (EFI_ERROR (Status
)) {
575 return EFI_DEVICE_ERROR
;
578 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
580 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
582 if (IpSb
->Ip4Config
!= NULL
&& (IpSb
->State
!= IP4_SERVICE_DESTORY
)) {
584 IpSb
->Ip4Config
->Stop (IpSb
->Ip4Config
);
586 Status
= gBS
->CloseProtocol (
588 &gEfiIp4ConfigProtocolGuid
,
593 if (EFI_ERROR (Status
)) {
594 gBS
->RestoreTPL (OldTpl
);
599 // If the auto configure hasn't complete, mark it as not started.
601 if (IpSb
->State
== IP4_SERVICE_STARTED
) {
602 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
605 IpSb
->Ip4Config
= NULL
;
606 gBS
->CloseEvent (IpSb
->DoneEvent
);
607 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
610 gBS
->RestoreTPL (OldTpl
);
615 // Either MNP or ARP protocol is being uninstalled. The controller
616 // handle is either the MNP child or ARP child. But, the IP4's
617 // service binding is installed on the NIC handle. So, need to open
618 // the protocol info to find the NIC handle.
621 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
623 if (NicHandle
== NULL
) {
624 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
628 if (NicHandle
== NULL
) {
629 return EFI_DEVICE_ERROR
;
633 // Retrieve the IP4 service binding protocol
635 Status
= gBS
->OpenProtocol (
637 &gEfiIp4ServiceBindingProtocolGuid
,
638 (VOID
**) &ServiceBinding
,
639 This
->DriverBindingHandle
,
641 EFI_OPEN_PROTOCOL_GET_PROTOCOL
644 if (EFI_ERROR (Status
)) {
645 return EFI_DEVICE_ERROR
;
648 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
650 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
652 if (IpSb
->InDestory
) {
653 gBS
->RestoreTPL (OldTpl
);
658 while (!IsListEmpty (&IpSb
->Children
)) {
659 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP4_PROTOCOL
, Link
);
661 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
664 if (IpSb
->NumChildren
!= 0) {
665 Status
= EFI_DEVICE_ERROR
;
669 IpSb
->InDestory
= TRUE
;
672 IpSb
->State
= IP4_SERVICE_DESTORY
;
675 // Clear the variable data.
677 Ip4ClearVariableData (IpSb
);
680 // OK, clean other resources then uninstall the service binding protocol.
682 Status
= Ip4CleanService (IpSb
);
684 if (EFI_ERROR (Status
)) {
689 gBS
->UninstallProtocolInterface (
691 &gEfiIp4ServiceBindingProtocolGuid
,
696 } else if (NumberOfChildren
== 0) {
697 IpSb
->InDestory
= TRUE
;
700 IpSb
->State
= IP4_SERVICE_DESTORY
;
703 // Clear the variable data.
705 Ip4ClearVariableData (IpSb
);
708 // OK, clean other resources then uninstall the service binding protocol.
710 Status
= Ip4CleanService (IpSb
);
712 if (EFI_ERROR (Status
)) {
717 gBS
->UninstallProtocolInterface (
719 &gEfiIp4ServiceBindingProtocolGuid
,
726 while (!IsListEmpty (&IpSb
->Children
)) {
727 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP4_PROTOCOL
, Link
);
729 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
732 if (IpSb
->NumChildren
!= 0) {
733 Status
= EFI_DEVICE_ERROR
;
739 gBS
->RestoreTPL (OldTpl
);
745 Creates a child handle and installs a protocol.
747 The CreateChild() function installs a protocol on ChildHandle.
748 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
749 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
751 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
752 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
753 then a new handle is created. If it is a pointer to an existing UEFI handle,
754 then the protocol is added to the existing UEFI handle.
756 @retval EFI_SUCCES The protocol was added to ChildHandle.
757 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
758 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
760 @retval other The child handle was not created
765 Ip4ServiceBindingCreateChild (
766 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
767 IN OUT EFI_HANDLE
*ChildHandle
771 IP4_PROTOCOL
*IpInstance
;
776 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
777 return EFI_INVALID_PARAMETER
;
780 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
781 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
783 if (IpInstance
== NULL
) {
784 return EFI_OUT_OF_RESOURCES
;
787 Ip4InitProtocol (IpSb
, IpInstance
);
790 // Install Ip4 onto ChildHandle
792 Status
= gBS
->InstallMultipleProtocolInterfaces (
794 &gEfiIp4ProtocolGuid
,
795 &IpInstance
->Ip4Proto
,
799 if (EFI_ERROR (Status
)) {
803 IpInstance
->Handle
= *ChildHandle
;
806 // Open the Managed Network protocol BY_CHILD.
808 Status
= gBS
->OpenProtocol (
809 IpSb
->MnpChildHandle
,
810 &gEfiManagedNetworkProtocolGuid
,
812 gIp4DriverBinding
.DriverBindingHandle
,
814 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
816 if (EFI_ERROR (Status
)) {
817 gBS
->UninstallMultipleProtocolInterfaces (
819 &gEfiIp4ProtocolGuid
,
820 &IpInstance
->Ip4Proto
,
828 // Insert it into the service binding instance.
830 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
832 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
835 gBS
->RestoreTPL (OldTpl
);
839 if (EFI_ERROR (Status
)) {
841 Ip4CleanProtocol (IpInstance
);
843 FreePool (IpInstance
);
851 Destroys a child handle with a protocol installed on it.
853 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
854 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
855 last protocol on ChildHandle, then ChildHandle is destroyed.
857 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
858 @param ChildHandle Handle of the child to destroy
860 @retval EFI_SUCCES The protocol was removed from ChildHandle.
861 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
862 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
863 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
864 because its services are being used.
865 @retval other The child handle was not destroyed
870 Ip4ServiceBindingDestroyChild (
871 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
872 IN EFI_HANDLE ChildHandle
877 IP4_PROTOCOL
*IpInstance
;
878 EFI_IP4_PROTOCOL
*Ip4
;
882 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
883 return EFI_INVALID_PARAMETER
;
887 // Retrieve the private context data structures
889 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
891 Status
= gBS
->OpenProtocol (
893 &gEfiIp4ProtocolGuid
,
895 gIp4DriverBinding
.DriverBindingHandle
,
897 EFI_OPEN_PROTOCOL_GET_PROTOCOL
900 if (EFI_ERROR (Status
)) {
901 return EFI_UNSUPPORTED
;
904 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
906 if (IpInstance
->Service
!= IpSb
) {
907 return EFI_INVALID_PARAMETER
;
910 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
913 // A child can be destoried more than once. For example,
914 // Ip4DriverBindingStop will destory all of its children.
915 // when UDP driver is being stopped, it will destory all
916 // the IP child it opens.
918 if (IpInstance
->State
== IP4_STATE_DESTORY
) {
919 gBS
->RestoreTPL (OldTpl
);
923 State
= IpInstance
->State
;
924 IpInstance
->State
= IP4_STATE_DESTORY
;
927 // Close the Managed Network protocol.
930 IpSb
->MnpChildHandle
,
931 &gEfiManagedNetworkProtocolGuid
,
932 gIp4DriverBinding
.DriverBindingHandle
,
937 // Uninstall the IP4 protocol first. Many thing happens during
939 // 1. The consumer of the IP4 protocol will be stopped if it
940 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
941 // stopped, IP driver's stop function will be called, and uninstall
942 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
943 // makes it possible to create the network stack bottom up, and
945 // 2. the upper layer will recycle the received packet. The recycle
946 // event's TPL is higher than this function. The recycle events
947 // will be called back before preceeding. If any packets not recycled,
948 // that means there is a resource leak.
950 Status
= gBS
->UninstallProtocolInterface (
952 &gEfiIp4ProtocolGuid
,
953 &IpInstance
->Ip4Proto
956 if (EFI_ERROR (Status
)) {
960 Status
= Ip4CleanProtocol (IpInstance
);
962 Ip4SetVariableData (IpSb
);
964 if (EFI_ERROR (Status
)) {
965 gBS
->InstallMultipleProtocolInterfaces (
967 &gEfiIp4ProtocolGuid
,
975 RemoveEntryList (&IpInstance
->Link
);
978 gBS
->RestoreTPL (OldTpl
);
980 FreePool (IpInstance
);
984 IpInstance
->State
= State
;
985 gBS
->RestoreTPL (OldTpl
);