2 The driver binding and service binding protocol for IP4 driver.
4 Copyright (c) 2005 - 2017, 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 (
46 // Test if protocol was even found.
47 // Notification function will be called at least once.
49 Status
= gBS
->LocateProtocol (&gEfiIpSec2ProtocolGuid
, NULL
, (VOID
**)&mIpSec
);
50 if (Status
== EFI_SUCCESS
&& mIpSec
!= NULL
) {
52 // Close the event so it does not get called again.
54 gBS
->CloseEvent (Event
);
56 mIpSec2Installed
= TRUE
;
61 This is the declaration of an EFI image entry point. This entry point is
62 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
63 both device drivers and bus drivers.
65 The entry point for IP4 driver which install the driver
66 binding and component name protocol on its image.
68 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
69 @param[in] SystemTable A pointer to the EFI System Table.
71 @retval EFI_SUCCESS The operation completed successfully.
72 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
78 IN EFI_HANDLE ImageHandle
,
79 IN EFI_SYSTEM_TABLE
*SystemTable
84 EfiCreateProtocolNotifyEvent (
85 &gEfiIpSec2ProtocolGuid
,
87 IpSec2InstalledCallback
,
92 return EfiLibInstallDriverBindingComponentName2 (
103 Test to see if this driver supports ControllerHandle. This service
104 is called by the EFI boot service ConnectController(). In
105 order to make drivers as small as possible, there are a few calling
106 restrictions for this service. ConnectController() must
107 follow these calling restrictions. If any other agent wishes to call
108 Supported() it must also follow these calling restrictions.
110 @param[in] This Protocol instance pointer.
111 @param[in] ControllerHandle Handle of device to test
112 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
115 @retval EFI_SUCCESS This driver supports this device
116 @retval EFI_ALREADY_STARTED This driver is already running on this device
117 @retval other This driver does not support this device
122 Ip4DriverBindingSupported (
123 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
124 IN EFI_HANDLE ControllerHandle
,
125 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
131 // Test for the MNP service binding Protocol
133 Status
= gBS
->OpenProtocol (
135 &gEfiManagedNetworkServiceBindingProtocolGuid
,
137 This
->DriverBindingHandle
,
139 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
142 if (EFI_ERROR (Status
)) {
147 // Test for the Arp service binding Protocol
149 Status
= gBS
->OpenProtocol (
151 &gEfiArpServiceBindingProtocolGuid
,
153 This
->DriverBindingHandle
,
155 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
162 Clean up a IP4 service binding instance. It will release all
163 the resource allocated by the instance. The instance may be
164 partly initialized, or partly destroyed. If a resource is
165 destroyed, it is marked as that in case the destroy failed and
166 being called again later.
168 @param[in] IpSb The IP4 service binding instance to clean up
170 @retval EFI_SUCCESS The resource used by the instance are cleaned up
171 @retval other Failed to clean up some of the resources.
181 Create a new IP4 driver service binding private instance.
183 @param Controller The controller that has MNP service binding
185 @param ImageHandle The IP4 driver's image handle
186 @param Service The variable to receive the newly created IP4
189 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resource
190 @retval EFI_SUCCESS A new IP4 service binding private is created.
191 @retval other Other error occurs.
196 IN EFI_HANDLE Controller
,
197 IN EFI_HANDLE ImageHandle
,
198 OUT IP4_SERVICE
**Service
204 ASSERT (Service
!= NULL
);
209 // allocate a service private data then initialize all the filed to
210 // empty resources, so if any thing goes wrong when allocating
211 // resources, Ip4CleanService can be called to clean it up.
213 IpSb
= AllocateZeroPool (sizeof (IP4_SERVICE
));
216 return EFI_OUT_OF_RESOURCES
;
219 IpSb
->Signature
= IP4_SERVICE_SIGNATURE
;
220 IpSb
->ServiceBinding
.CreateChild
= Ip4ServiceBindingCreateChild
;
221 IpSb
->ServiceBinding
.DestroyChild
= Ip4ServiceBindingDestroyChild
;
222 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
224 IpSb
->NumChildren
= 0;
225 InitializeListHead (&IpSb
->Children
);
227 InitializeListHead (&IpSb
->Interfaces
);
228 IpSb
->DefaultInterface
= NULL
;
229 IpSb
->DefaultRouteTable
= NULL
;
231 Ip4InitAssembleTable (&IpSb
->Assemble
);
233 IpSb
->IgmpCtrl
.Igmpv1QuerySeen
= 0;
234 InitializeListHead (&IpSb
->IgmpCtrl
.Groups
);
236 IpSb
->Image
= ImageHandle
;
237 IpSb
->Controller
= Controller
;
239 IpSb
->MnpChildHandle
= NULL
;
242 IpSb
->MnpConfigData
.ReceivedQueueTimeoutValue
= 0;
243 IpSb
->MnpConfigData
.TransmitQueueTimeoutValue
= 0;
244 IpSb
->MnpConfigData
.ProtocolTypeFilter
= IP4_ETHER_PROTO
;
245 IpSb
->MnpConfigData
.EnableUnicastReceive
= TRUE
;
246 IpSb
->MnpConfigData
.EnableMulticastReceive
= TRUE
;
247 IpSb
->MnpConfigData
.EnableBroadcastReceive
= TRUE
;
248 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= FALSE
;
249 IpSb
->MnpConfigData
.FlushQueuesOnReset
= TRUE
;
250 IpSb
->MnpConfigData
.EnableReceiveTimestamps
= FALSE
;
251 IpSb
->MnpConfigData
.DisableBackgroundPolling
= FALSE
;
253 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
257 IpSb
->ReconfigEvent
= NULL
;
259 IpSb
->Reconfig
= FALSE
;
261 IpSb
->MediaPresent
= TRUE
;
264 // Create various resources. First create the route table, timer
265 // event, ReconfigEvent and MNP child. IGMP, interface's initialization depend
268 IpSb
->DefaultRouteTable
= Ip4CreateRouteTable ();
270 if (IpSb
->DefaultRouteTable
== NULL
) {
271 Status
= EFI_OUT_OF_RESOURCES
;
275 Status
= gBS
->CreateEvent (
276 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
283 if (EFI_ERROR (Status
)) {
287 Status
= gBS
->CreateEvent (
290 Ip4AutoReconfigCallBack
,
294 if (EFI_ERROR (Status
)) {
298 Status
= NetLibCreateServiceChild (
301 &gEfiManagedNetworkServiceBindingProtocolGuid
,
302 &IpSb
->MnpChildHandle
305 if (EFI_ERROR (Status
)) {
309 Status
= gBS
->OpenProtocol (
310 IpSb
->MnpChildHandle
,
311 &gEfiManagedNetworkProtocolGuid
,
312 (VOID
**) &IpSb
->Mnp
,
315 EFI_OPEN_PROTOCOL_BY_DRIVER
318 if (EFI_ERROR (Status
)) {
322 Status
= Ip4ServiceConfigMnp (IpSb
, TRUE
);
324 if (EFI_ERROR (Status
)) {
328 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
330 if (EFI_ERROR (Status
)) {
334 Status
= Ip4InitIgmp (IpSb
);
336 if (EFI_ERROR (Status
)) {
340 IpSb
->MacString
= NULL
;
341 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
343 if (EFI_ERROR (Status
)) {
347 IpSb
->DefaultInterface
= Ip4CreateInterface (IpSb
->Mnp
, Controller
, ImageHandle
);
349 if (IpSb
->DefaultInterface
== NULL
) {
350 Status
= EFI_OUT_OF_RESOURCES
;
354 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
356 ZeroMem (&IpSb
->Ip4Config2Instance
, sizeof (IP4_CONFIG2_INSTANCE
));
358 Status
= Ip4Config2InitInstance (&IpSb
->Ip4Config2Instance
);
360 if (EFI_ERROR (Status
)) {
364 IpSb
->MaxPacketSize
= IpSb
->SnpMode
.MaxPacketSize
- sizeof (IP4_HEAD
);
365 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
367 // This is a VLAN device, reduce MTU by VLAN tag length
369 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
371 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
377 Ip4CleanService (IpSb
);
385 Clean up a IP4 service binding instance. It will release all
386 the resource allocated by the instance. The instance may be
387 partly initialized, or partly destroyed. If a resource is
388 destroyed, it is marked as that in case the destroy failed and
389 being called again later.
391 @param[in] IpSb The IP4 service binding instance to clean up
393 @retval EFI_SUCCESS The resource used by the instance are cleaned up
394 @retval other Failed to clean up some of the resources.
404 IpSb
->State
= IP4_SERVICE_DESTROY
;
406 if (IpSb
->Timer
!= NULL
) {
407 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
408 gBS
->CloseEvent (IpSb
->Timer
);
413 if (IpSb
->DefaultInterface
!= NULL
) {
414 Status
= Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
416 if (EFI_ERROR (Status
)) {
420 IpSb
->DefaultInterface
= NULL
;
423 if (IpSb
->DefaultRouteTable
!= NULL
) {
424 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
425 IpSb
->DefaultRouteTable
= NULL
;
428 Ip4CleanAssembleTable (&IpSb
->Assemble
);
430 if (IpSb
->MnpChildHandle
!= NULL
) {
431 if (IpSb
->Mnp
!= NULL
) {
433 IpSb
->MnpChildHandle
,
434 &gEfiManagedNetworkProtocolGuid
,
442 NetLibDestroyServiceChild (
445 &gEfiManagedNetworkServiceBindingProtocolGuid
,
449 IpSb
->MnpChildHandle
= NULL
;
452 if (IpSb
->ReconfigEvent
!= NULL
) {
453 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
455 IpSb
->ReconfigEvent
= NULL
;
458 IpSb
->Reconfig
= FALSE
;
460 if (IpSb
->MacString
!= NULL
) {
461 FreePool (IpSb
->MacString
);
464 Ip4Config2CleanInstance (&IpSb
->Ip4Config2Instance
);
470 Callback function which provided by user to remove one node in NetDestroyLinkList process.
472 @param[in] Entry The entry to be removed.
473 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
475 @retval EFI_SUCCESS The entry has been removed successfully.
476 @retval Others Fail to remove the entry.
481 Ip4DestroyChildEntryInHandleBuffer (
482 IN LIST_ENTRY
*Entry
,
486 IP4_PROTOCOL
*IpInstance
;
487 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
488 UINTN NumberOfChildren
;
489 EFI_HANDLE
*ChildHandleBuffer
;
491 if (Entry
== NULL
|| Context
== NULL
) {
492 return EFI_INVALID_PARAMETER
;
495 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_PROTOCOL
, Link
, IP4_PROTOCOL_SIGNATURE
);
496 ServiceBinding
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
497 NumberOfChildren
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
498 ChildHandleBuffer
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
500 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
504 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
508 Start this driver on ControllerHandle. This service is called by the
509 EFI boot service ConnectController(). In order to make
510 drivers as small as possible, there are a few calling restrictions for
511 this service. ConnectController() must follow these
512 calling restrictions. If any other agent wishes to call Start() it
513 must also follow these calling restrictions.
515 @param[in] This Protocol instance pointer.
516 @param[in] ControllerHandle Handle of device to bind driver to
517 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
520 @retval EFI_SUCCESS This driver is added to ControllerHandle
521 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
522 @retval other This driver does not support this device
527 Ip4DriverBindingStart (
528 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
529 IN EFI_HANDLE ControllerHandle
,
530 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
535 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Cfg2
;
537 IP4_CONFIG2_DATA_ITEM
*DataItem
;
544 // Test for the Ip4 service binding protocol
546 Status
= gBS
->OpenProtocol (
548 &gEfiIp4ServiceBindingProtocolGuid
,
550 This
->DriverBindingHandle
,
552 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
555 if (Status
== EFI_SUCCESS
) {
556 return EFI_ALREADY_STARTED
;
559 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
561 if (EFI_ERROR (Status
)) {
565 ASSERT (IpSb
!= NULL
);
567 Ip4Cfg2
= &IpSb
->Ip4Config2Instance
.Ip4Config2
;
570 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
572 Status
= gBS
->InstallMultipleProtocolInterfaces (
574 &gEfiIp4ServiceBindingProtocolGuid
,
575 &IpSb
->ServiceBinding
,
576 &gEfiIp4Config2ProtocolGuid
,
581 if (EFI_ERROR (Status
)) {
586 // Read the config data from NV variable again.
587 // The default data can be changed by other drivers.
589 Status
= Ip4Config2ReadConfigData (IpSb
->MacString
, &IpSb
->Ip4Config2Instance
);
590 if (EFI_ERROR (Status
)) {
591 goto UNINSTALL_PROTOCOL
;
595 // Consume the installed EFI_IP4_CONFIG2_PROTOCOL to set the default data items.
597 for (Index
= Ip4Config2DataTypePolicy
; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
598 DataItem
= &IpSb
->Ip4Config2Instance
.DataItem
[Index
];
599 if (DataItem
->Data
.Ptr
!= NULL
) {
600 Status
= Ip4Cfg2
->SetData (
606 if (EFI_ERROR(Status
)) {
607 goto UNINSTALL_PROTOCOL
;
610 if (Index
== Ip4Config2DataTypePolicy
&& (*(DataItem
->Data
.Policy
) == Ip4Config2PolicyDhcp
)) {
617 // Ready to go: start the receiving and timer.
618 // Ip4Config2SetPolicy maybe call Ip4ReceiveFrame() to set the default interface's RecvRequest first after
619 // Ip4Config2 instance is initialized. So, EFI_ALREADY_STARTED is the allowed return status.
621 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
623 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
624 goto UNINSTALL_PROTOCOL
;
627 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
629 if (EFI_ERROR (Status
)) {
630 goto UNINSTALL_PROTOCOL
;
634 // Initialize the IP4 ID
636 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
641 gBS
->UninstallProtocolInterface (
643 &gEfiIp4ServiceBindingProtocolGuid
,
644 &IpSb
->ServiceBinding
648 Ip4CleanService (IpSb
);
655 Stop this driver on ControllerHandle. This service is called by the
656 EFI boot service DisconnectController(). In order to
657 make drivers as small as possible, there are a few calling
658 restrictions for this service. DisconnectController()
659 must follow these calling restrictions. If any other agent wishes
660 to call Stop() it must also follow these calling restrictions.
662 @param[in] This Protocol instance pointer.
663 @param[in] ControllerHandle Handle of device to stop driver on
664 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
665 of children is zero stop the entire bus driver.
666 @param[in] ChildHandleBuffer List of Child Handles to Stop.
668 @retval EFI_SUCCESS This driver is removed ControllerHandle
669 @retval other This driver was not removed from this device
674 Ip4DriverBindingStop (
675 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
676 IN EFI_HANDLE ControllerHandle
,
677 IN UINTN NumberOfChildren
,
678 IN EFI_HANDLE
*ChildHandleBuffer
681 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
683 EFI_HANDLE NicHandle
;
687 IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
689 IP4_ROUTE_TABLE
*RouteTable
;
695 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
696 if (NicHandle
== NULL
) {
697 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
698 if (NicHandle
== NULL
) {
699 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
700 if (NicHandle
!= NULL
) {
708 Status
= gBS
->OpenProtocol (
710 &gEfiIp4ServiceBindingProtocolGuid
,
711 (VOID
**) &ServiceBinding
,
712 This
->DriverBindingHandle
,
714 EFI_OPEN_PROTOCOL_GET_PROTOCOL
716 if (EFI_ERROR (Status
)) {
717 return EFI_DEVICE_ERROR
;
720 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
723 Status
= Ip4Config2DestroyDhcp4 (&IpSb
->Ip4Config2Instance
);
724 gBS
->CloseEvent (IpSb
->Ip4Config2Instance
.Dhcp4Event
);
725 IpSb
->Ip4Config2Instance
.Dhcp4Event
= NULL
;
726 } else if (NumberOfChildren
!= 0) {
727 List
= &IpSb
->Children
;
728 Context
.ServiceBinding
= ServiceBinding
;
729 Context
.NumberOfChildren
= NumberOfChildren
;
730 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
731 Status
= NetDestroyLinkList (
733 Ip4DestroyChildEntryInHandleBuffer
,
737 } else if (IpSb
->DefaultInterface
->ArpHandle
== ControllerHandle
) {
740 // The ARP protocol for the default interface is being uninstalled and all
741 // its IP child handles should have been destroyed before. So, release the
742 // default interface and route table, create a new one and mark it as not started.
744 Ip4CancelReceive (IpSb
->DefaultInterface
);
745 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
746 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
748 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
752 RouteTable
= Ip4CreateRouteTable ();
753 if (RouteTable
== NULL
) {
754 Ip4FreeInterface (IpIf
, NULL
);
758 IpSb
->DefaultInterface
= IpIf
;
759 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
760 IpSb
->DefaultRouteTable
= RouteTable
;
761 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
763 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
765 } else if (IsListEmpty (&IpSb
->Children
)) {
768 // OK, clean other resources then uninstall the service binding protocol.
770 Status
= Ip4CleanService (IpSb
);
771 if (EFI_ERROR (Status
)) {
776 gBS
->UninstallMultipleProtocolInterfaces (
778 &gEfiIp4ServiceBindingProtocolGuid
,
780 &gEfiIp4Config2ProtocolGuid
,
781 &IpSb
->Ip4Config2Instance
.Ip4Config2
,
785 if (gIp4ControllerNameTable
!= NULL
) {
786 FreeUnicodeStringTable (gIp4ControllerNameTable
);
787 gIp4ControllerNameTable
= NULL
;
798 Creates a child handle and installs a protocol.
800 The CreateChild() function installs a protocol on ChildHandle.
801 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
802 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
804 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
805 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
806 then a new handle is created. If it is a pointer to an existing UEFI handle,
807 then the protocol is added to the existing UEFI handle.
809 @retval EFI_SUCCES The protocol was added to ChildHandle.
810 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
811 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
813 @retval other The child handle was not created
818 Ip4ServiceBindingCreateChild (
819 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
820 IN OUT EFI_HANDLE
*ChildHandle
824 IP4_PROTOCOL
*IpInstance
;
829 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
830 return EFI_INVALID_PARAMETER
;
833 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
834 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
836 if (IpInstance
== NULL
) {
837 return EFI_OUT_OF_RESOURCES
;
840 Ip4InitProtocol (IpSb
, IpInstance
);
843 // Install Ip4 onto ChildHandle
845 Status
= gBS
->InstallMultipleProtocolInterfaces (
847 &gEfiIp4ProtocolGuid
,
848 &IpInstance
->Ip4Proto
,
852 if (EFI_ERROR (Status
)) {
856 IpInstance
->Handle
= *ChildHandle
;
859 // Open the Managed Network protocol BY_CHILD.
861 Status
= gBS
->OpenProtocol (
862 IpSb
->MnpChildHandle
,
863 &gEfiManagedNetworkProtocolGuid
,
865 gIp4DriverBinding
.DriverBindingHandle
,
867 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
869 if (EFI_ERROR (Status
)) {
870 gBS
->UninstallMultipleProtocolInterfaces (
872 &gEfiIp4ProtocolGuid
,
873 &IpInstance
->Ip4Proto
,
881 // Insert it into the service binding instance.
883 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
885 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
888 gBS
->RestoreTPL (OldTpl
);
892 if (EFI_ERROR (Status
)) {
894 Ip4CleanProtocol (IpInstance
);
896 FreePool (IpInstance
);
904 Destroys a child handle with a protocol installed on it.
906 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
907 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
908 last protocol on ChildHandle, then ChildHandle is destroyed.
910 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
911 @param ChildHandle Handle of the child to destroy
913 @retval EFI_SUCCES The protocol was removed from ChildHandle.
914 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
915 @retval EFI_INVALID_PARAMETER Child handle is NULL.
916 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
917 because its services are being used.
918 @retval other The child handle was not destroyed
923 Ip4ServiceBindingDestroyChild (
924 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
925 IN EFI_HANDLE ChildHandle
930 IP4_PROTOCOL
*IpInstance
;
931 EFI_IP4_PROTOCOL
*Ip4
;
934 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
935 return EFI_INVALID_PARAMETER
;
939 // Retrieve the private context data structures
941 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
943 Status
= gBS
->OpenProtocol (
945 &gEfiIp4ProtocolGuid
,
947 gIp4DriverBinding
.DriverBindingHandle
,
949 EFI_OPEN_PROTOCOL_GET_PROTOCOL
952 if (EFI_ERROR (Status
)) {
953 return EFI_UNSUPPORTED
;
956 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
958 if (IpInstance
->Service
!= IpSb
) {
959 return EFI_INVALID_PARAMETER
;
962 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
965 // A child can be destroyed more than once. For example,
966 // Ip4DriverBindingStop will destroy all of its children.
967 // when UDP driver is being stopped, it will destroy all
968 // the IP child it opens.
970 if (IpInstance
->InDestroy
) {
971 gBS
->RestoreTPL (OldTpl
);
975 IpInstance
->InDestroy
= TRUE
;
978 // Close the Managed Network protocol.
981 IpSb
->MnpChildHandle
,
982 &gEfiManagedNetworkProtocolGuid
,
983 gIp4DriverBinding
.DriverBindingHandle
,
987 if (IpInstance
->Interface
!= NULL
&& IpInstance
->Interface
->Arp
!= NULL
) {
989 IpInstance
->Interface
->ArpHandle
,
990 &gEfiArpProtocolGuid
,
991 gIp4DriverBinding
.DriverBindingHandle
,
997 // Uninstall the IP4 protocol first. Many thing happens during
999 // 1. The consumer of the IP4 protocol will be stopped if it
1000 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
1001 // stopped, IP driver's stop function will be called, and uninstall
1002 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
1003 // makes it possible to create the network stack bottom up, and
1004 // stop it top down.
1005 // 2. the upper layer will recycle the received packet. The recycle
1006 // event's TPL is higher than this function. The recycle events
1007 // will be called back before preceeding. If any packets not recycled,
1008 // that means there is a resource leak.
1010 gBS
->RestoreTPL (OldTpl
);
1011 Status
= gBS
->UninstallProtocolInterface (
1013 &gEfiIp4ProtocolGuid
,
1014 &IpInstance
->Ip4Proto
1016 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1017 if (EFI_ERROR (Status
)) {
1018 IpInstance
->InDestroy
= FALSE
;
1022 Status
= Ip4CleanProtocol (IpInstance
);
1023 if (EFI_ERROR (Status
)) {
1024 gBS
->InstallMultipleProtocolInterfaces (
1026 &gEfiIp4ProtocolGuid
,
1034 RemoveEntryList (&IpInstance
->Link
);
1035 IpSb
->NumChildren
--;
1037 gBS
->RestoreTPL (OldTpl
);
1039 FreePool (IpInstance
);
1043 gBS
->RestoreTPL (OldTpl
);