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
;
179 IpSb
->InDestroy
= 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
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
301 IpSb
->MacString
= NULL
;
307 Ip4CleanService (IpSb
);
315 Clean up a IP4 service binding instance. It will release all
316 the resource allocated by the instance. The instance may be
317 partly initialized, or partly destroyed. If a resource is
318 destroyed, it is marked as that in case the destroy failed and
319 being called again later.
321 @param[in] IpSb The IP4 serviceing binding instance to clean up
323 @retval EFI_SUCCESS The resource used by the instance are cleaned up
324 @retval other Failed to clean up some of the resources.
334 if (IpSb
->DefaultInterface
!= NULL
) {
335 Status
= Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
337 if (EFI_ERROR (Status
)) {
341 IpSb
->DefaultInterface
= NULL
;
344 if (IpSb
->DefaultRouteTable
!= NULL
) {
345 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
346 IpSb
->DefaultRouteTable
= NULL
;
349 Ip4CleanAssembleTable (&IpSb
->Assemble
);
351 if (IpSb
->MnpChildHandle
!= NULL
) {
352 if (IpSb
->Mnp
!= NULL
) {
354 IpSb
->MnpChildHandle
,
355 &gEfiManagedNetworkProtocolGuid
,
363 NetLibDestroyServiceChild (
366 &gEfiManagedNetworkServiceBindingProtocolGuid
,
370 IpSb
->MnpChildHandle
= NULL
;
373 if (IpSb
->Timer
!= NULL
) {
374 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
375 gBS
->CloseEvent (IpSb
->Timer
);
380 if (IpSb
->Ip4Config
!= NULL
) {
381 IpSb
->Ip4Config
->Stop (IpSb
->Ip4Config
);
385 &gEfiIp4ConfigProtocolGuid
,
390 gBS
->CloseEvent (IpSb
->DoneEvent
);
391 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
392 IpSb
->ActiveEvent
= NULL
;
393 IpSb
->Ip4Config
= NULL
;
401 Start this driver on ControllerHandle. This service is called by the
402 EFI boot service ConnectController(). In order to make
403 drivers as small as possible, there are a few calling restrictions for
404 this service. ConnectController() must follow these
405 calling restrictions. If any other agent wishes to call Start() it
406 must also follow these calling restrictions.
408 @param[in] This Protocol instance pointer.
409 @param[in] ControllerHandle Handle of device to bind driver to
410 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
413 @retval EFI_SUCCESS This driver is added to ControllerHandle
414 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
415 @retval other This driver does not support this device
420 Ip4DriverBindingStart (
421 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
422 IN EFI_HANDLE ControllerHandle
,
423 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
430 // Test for the Ip4 service binding protocol
432 Status
= gBS
->OpenProtocol (
434 &gEfiIp4ServiceBindingProtocolGuid
,
436 This
->DriverBindingHandle
,
438 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
441 if (Status
== EFI_SUCCESS
) {
442 return EFI_ALREADY_STARTED
;
445 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
447 if (EFI_ERROR (Status
)) {
450 ASSERT (IpSb
!= NULL
);
453 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
455 Status
= gBS
->InstallMultipleProtocolInterfaces (
457 &gEfiIp4ServiceBindingProtocolGuid
,
458 &IpSb
->ServiceBinding
,
462 if (EFI_ERROR (Status
)) {
467 // ready to go: start the receiving and timer
469 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
471 if (EFI_ERROR (Status
)) {
472 goto UNINSTALL_PROTOCOL
;
475 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
477 if (EFI_ERROR (Status
)) {
478 goto UNINSTALL_PROTOCOL
;
482 // Initialize the IP4 ID
484 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
486 Ip4SetVariableData (IpSb
);
491 gBS
->UninstallProtocolInterface (
493 &gEfiIp4ServiceBindingProtocolGuid
,
494 &IpSb
->ServiceBinding
498 Ip4CleanService (IpSb
);
506 Stop this driver on ControllerHandle. This service is called by the
507 EFI boot service DisconnectController(). In order to
508 make drivers as small as possible, there are a few calling
509 restrictions for this service. DisconnectController()
510 must follow these calling restrictions. If any other agent wishes
511 to call Stop() it must also follow these calling restrictions.
513 @param[in] This Protocol instance pointer.
514 @param[in] ControllerHandle Handle of device to stop driver on
515 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
516 of children is zero stop the entire bus driver.
517 @param[in] ChildHandleBuffer List of Child Handles to Stop.
519 @retval EFI_SUCCESS This driver is removed ControllerHandle
520 @retval other This driver was not removed from this device
525 Ip4DriverBindingStop (
526 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
527 IN EFI_HANDLE ControllerHandle
,
528 IN UINTN NumberOfChildren
,
529 IN EFI_HANDLE
*ChildHandleBuffer
532 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
534 IP4_PROTOCOL
*IpInstance
;
535 EFI_HANDLE NicHandle
;
542 // IP4 driver opens the MNP child, ARP children or the IP4_CONFIG protocol
543 // by driver. So the ControllerHandle may be the MNP child handle, ARP child
544 // handle, or the NIC (UNDI) handle because IP4_CONFIG protocol is installed
545 // in the NIC handle.
548 // First, check whether it is the IP4_CONFIG protocol being uninstalled.
549 // IP4_CONFIG protocol is installed on the NIC handle. It isn't necessary
550 // to clean up the default configuration if IP4_CONFIG is being stopped.
552 Status
= gBS
->OpenProtocol (
554 &gEfiIp4ConfigProtocolGuid
,
556 This
->DriverBindingHandle
,
558 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
561 if (Status
== EFI_SUCCESS
) {
563 // Retrieve the IP4 service binding protocol. If failed, it is
564 // likely that Ip4 ServiceBinding is uninstalled already. In this
565 // case, return immediately.
567 Status
= gBS
->OpenProtocol (
569 &gEfiIp4ServiceBindingProtocolGuid
,
570 (VOID
**) &ServiceBinding
,
571 This
->DriverBindingHandle
,
573 EFI_OPEN_PROTOCOL_GET_PROTOCOL
576 if (EFI_ERROR (Status
)) {
577 return EFI_DEVICE_ERROR
;
580 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
582 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
584 if (IpSb
->Ip4Config
!= NULL
&& (IpSb
->State
!= IP4_SERVICE_DESTROY
)) {
586 IpSb
->Ip4Config
->Stop (IpSb
->Ip4Config
);
588 Status
= gBS
->CloseProtocol (
590 &gEfiIp4ConfigProtocolGuid
,
595 if (EFI_ERROR (Status
)) {
596 gBS
->RestoreTPL (OldTpl
);
601 // If the auto configure hasn't complete, mark it as not started.
603 if (IpSb
->State
== IP4_SERVICE_STARTED
) {
604 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
607 IpSb
->Ip4Config
= NULL
;
608 gBS
->CloseEvent (IpSb
->DoneEvent
);
609 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
612 gBS
->RestoreTPL (OldTpl
);
617 // Either MNP or ARP protocol is being uninstalled. The controller
618 // handle is either the MNP child or ARP child. But, the IP4's
619 // service binding is installed on the NIC handle. So, need to open
620 // the protocol info to find the NIC handle.
623 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
625 if (NicHandle
== NULL
) {
626 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
630 if (NicHandle
== NULL
) {
631 return EFI_DEVICE_ERROR
;
635 // Retrieve the IP4 service binding protocol
637 Status
= gBS
->OpenProtocol (
639 &gEfiIp4ServiceBindingProtocolGuid
,
640 (VOID
**) &ServiceBinding
,
641 This
->DriverBindingHandle
,
643 EFI_OPEN_PROTOCOL_GET_PROTOCOL
646 if (EFI_ERROR (Status
)) {
647 return EFI_DEVICE_ERROR
;
650 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
652 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
654 if (IpSb
->InDestroy
) {
655 gBS
->RestoreTPL (OldTpl
);
660 while (!IsListEmpty (&IpSb
->Children
)) {
661 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP4_PROTOCOL
, Link
);
663 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
666 if (IpSb
->NumChildren
!= 0) {
667 Status
= EFI_DEVICE_ERROR
;
671 IpSb
->InDestroy
= TRUE
;
674 IpSb
->State
= IP4_SERVICE_DESTROY
;
677 // Clear the variable data.
679 Ip4ClearVariableData (IpSb
);
682 // OK, clean other resources then uninstall the service binding protocol.
684 Status
= Ip4CleanService (IpSb
);
686 if (EFI_ERROR (Status
)) {
691 gBS
->UninstallProtocolInterface (
693 &gEfiIp4ServiceBindingProtocolGuid
,
698 } else if (NumberOfChildren
== 0) {
699 IpSb
->InDestroy
= TRUE
;
702 IpSb
->State
= IP4_SERVICE_DESTROY
;
705 // Clear the variable data.
707 Ip4ClearVariableData (IpSb
);
710 // OK, clean other resources then uninstall the service binding protocol.
712 Status
= Ip4CleanService (IpSb
);
714 if (EFI_ERROR (Status
)) {
719 gBS
->UninstallProtocolInterface (
721 &gEfiIp4ServiceBindingProtocolGuid
,
728 while (!IsListEmpty (&IpSb
->Children
)) {
729 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP4_PROTOCOL
, Link
);
731 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
734 if (IpSb
->NumChildren
!= 0) {
735 Status
= EFI_DEVICE_ERROR
;
741 gBS
->RestoreTPL (OldTpl
);
747 Creates a child handle and installs a protocol.
749 The CreateChild() function installs a protocol on ChildHandle.
750 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
751 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
753 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
754 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
755 then a new handle is created. If it is a pointer to an existing UEFI handle,
756 then the protocol is added to the existing UEFI handle.
758 @retval EFI_SUCCES The protocol was added to ChildHandle.
759 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
760 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
762 @retval other The child handle was not created
767 Ip4ServiceBindingCreateChild (
768 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
769 IN OUT EFI_HANDLE
*ChildHandle
773 IP4_PROTOCOL
*IpInstance
;
778 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
779 return EFI_INVALID_PARAMETER
;
782 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
783 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
785 if (IpInstance
== NULL
) {
786 return EFI_OUT_OF_RESOURCES
;
789 Ip4InitProtocol (IpSb
, IpInstance
);
792 // Install Ip4 onto ChildHandle
794 Status
= gBS
->InstallMultipleProtocolInterfaces (
796 &gEfiIp4ProtocolGuid
,
797 &IpInstance
->Ip4Proto
,
801 if (EFI_ERROR (Status
)) {
805 IpInstance
->Handle
= *ChildHandle
;
808 // Open the Managed Network protocol BY_CHILD.
810 Status
= gBS
->OpenProtocol (
811 IpSb
->MnpChildHandle
,
812 &gEfiManagedNetworkProtocolGuid
,
814 gIp4DriverBinding
.DriverBindingHandle
,
816 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
818 if (EFI_ERROR (Status
)) {
819 gBS
->UninstallMultipleProtocolInterfaces (
821 &gEfiIp4ProtocolGuid
,
822 &IpInstance
->Ip4Proto
,
830 // Insert it into the service binding instance.
832 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
834 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
837 gBS
->RestoreTPL (OldTpl
);
841 if (EFI_ERROR (Status
)) {
843 Ip4CleanProtocol (IpInstance
);
845 FreePool (IpInstance
);
853 Destroys a child handle with a protocol installed on it.
855 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
856 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
857 last protocol on ChildHandle, then ChildHandle is destroyed.
859 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
860 @param ChildHandle Handle of the child to destroy
862 @retval EFI_SUCCES The protocol was removed from ChildHandle.
863 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
864 @retval EFI_INVALID_PARAMETER Child handle is NULL.
865 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
866 because its services are being used.
867 @retval other The child handle was not destroyed
872 Ip4ServiceBindingDestroyChild (
873 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
874 IN EFI_HANDLE ChildHandle
879 IP4_PROTOCOL
*IpInstance
;
880 EFI_IP4_PROTOCOL
*Ip4
;
884 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
885 return EFI_INVALID_PARAMETER
;
889 // Retrieve the private context data structures
891 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
893 Status
= gBS
->OpenProtocol (
895 &gEfiIp4ProtocolGuid
,
897 gIp4DriverBinding
.DriverBindingHandle
,
899 EFI_OPEN_PROTOCOL_GET_PROTOCOL
902 if (EFI_ERROR (Status
)) {
903 return EFI_UNSUPPORTED
;
906 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
908 if (IpInstance
->Service
!= IpSb
) {
909 return EFI_INVALID_PARAMETER
;
912 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
915 // A child can be destroyed more than once. For example,
916 // Ip4DriverBindingStop will destroy all of its children.
917 // when UDP driver is being stopped, it will destroy all
918 // the IP child it opens.
920 if (IpInstance
->State
== IP4_STATE_DESTROY
) {
921 gBS
->RestoreTPL (OldTpl
);
925 State
= IpInstance
->State
;
926 IpInstance
->State
= IP4_STATE_DESTROY
;
929 // Close the Managed Network protocol.
932 IpSb
->MnpChildHandle
,
933 &gEfiManagedNetworkProtocolGuid
,
934 gIp4DriverBinding
.DriverBindingHandle
,
939 // Uninstall the IP4 protocol first. Many thing happens during
941 // 1. The consumer of the IP4 protocol will be stopped if it
942 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
943 // stopped, IP driver's stop function will be called, and uninstall
944 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
945 // makes it possible to create the network stack bottom up, and
947 // 2. the upper layer will recycle the received packet. The recycle
948 // event's TPL is higher than this function. The recycle events
949 // will be called back before preceeding. If any packets not recycled,
950 // that means there is a resource leak.
952 Status
= gBS
->UninstallProtocolInterface (
954 &gEfiIp4ProtocolGuid
,
955 &IpInstance
->Ip4Proto
958 if (EFI_ERROR (Status
)) {
962 Status
= Ip4CleanProtocol (IpInstance
);
964 Ip4SetVariableData (IpSb
);
966 if (EFI_ERROR (Status
)) {
967 gBS
->InstallMultipleProtocolInterfaces (
969 &gEfiIp4ProtocolGuid
,
977 RemoveEntryList (&IpInstance
->Link
);
980 gBS
->RestoreTPL (OldTpl
);
982 FreePool (IpInstance
);
986 IpInstance
->State
= State
;
987 gBS
->RestoreTPL (OldTpl
);