2 The driver binding and service binding protocol for IP4 driver.
4 Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding
= {
14 Ip4DriverBindingSupported
,
15 Ip4DriverBindingStart
,
22 BOOLEAN mIpSec2Installed
= FALSE
;
25 Callback function for IpSec2 Protocol install.
27 @param[in] Event Event whose notification function is being invoked
28 @param[in] Context Pointer to the notification function's context
33 IpSec2InstalledCallback (
40 // Test if protocol was even found.
41 // Notification function will be called at least once.
43 Status
= gBS
->LocateProtocol (&gEfiIpSec2ProtocolGuid
, NULL
, (VOID
**)&mIpSec
);
44 if (Status
== EFI_SUCCESS
&& mIpSec
!= NULL
) {
46 // Close the event so it does not get called again.
48 gBS
->CloseEvent (Event
);
50 mIpSec2Installed
= TRUE
;
55 This is the declaration of an EFI image entry point. This entry point is
56 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
57 both device drivers and bus drivers.
59 The entry point for IP4 driver which install the driver
60 binding and component name protocol on its image.
62 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
63 @param[in] SystemTable A pointer to the EFI System Table.
65 @retval EFI_SUCCESS The operation completed successfully.
66 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
72 IN EFI_HANDLE ImageHandle
,
73 IN EFI_SYSTEM_TABLE
*SystemTable
78 EfiCreateProtocolNotifyEvent (
79 &gEfiIpSec2ProtocolGuid
,
81 IpSec2InstalledCallback
,
86 return EfiLibInstallDriverBindingComponentName2 (
97 Test to see if this driver supports ControllerHandle. This service
98 is called by the EFI boot service ConnectController(). In
99 order to make drivers as small as possible, there are a few calling
100 restrictions for this service. ConnectController() must
101 follow these calling restrictions. If any other agent wishes to call
102 Supported() it must also follow these calling restrictions.
104 @param[in] This Protocol instance pointer.
105 @param[in] ControllerHandle Handle of device to test
106 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
109 @retval EFI_SUCCESS This driver supports this device
110 @retval EFI_ALREADY_STARTED This driver is already running on this device
111 @retval other This driver does not support this device
116 Ip4DriverBindingSupported (
117 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
118 IN EFI_HANDLE ControllerHandle
,
119 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
125 // Test for the MNP service binding Protocol
127 Status
= gBS
->OpenProtocol (
129 &gEfiManagedNetworkServiceBindingProtocolGuid
,
131 This
->DriverBindingHandle
,
133 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
136 if (EFI_ERROR (Status
)) {
141 // Test for the Arp service binding Protocol
143 Status
= gBS
->OpenProtocol (
145 &gEfiArpServiceBindingProtocolGuid
,
147 This
->DriverBindingHandle
,
149 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
156 Clean up a IP4 service binding instance. It will release all
157 the resource allocated by the instance. The instance may be
158 partly initialized, or partly destroyed. If a resource is
159 destroyed, it is marked as that in case the destroy failed and
160 being called again later.
162 @param[in] IpSb The IP4 service binding instance to clean up
164 @retval EFI_SUCCESS The resource used by the instance are cleaned up
165 @retval other Failed to clean up some of the resources.
175 Create a new IP4 driver service binding private instance.
177 @param Controller The controller that has MNP service binding
179 @param ImageHandle The IP4 driver's image handle
180 @param Service The variable to receive the newly created IP4
183 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resource
184 @retval EFI_SUCCESS A new IP4 service binding private is created.
185 @retval other Other error occurs.
190 IN EFI_HANDLE Controller
,
191 IN EFI_HANDLE ImageHandle
,
192 OUT IP4_SERVICE
**Service
198 ASSERT (Service
!= NULL
);
203 // allocate a service private data then initialize all the filed to
204 // empty resources, so if any thing goes wrong when allocating
205 // resources, Ip4CleanService can be called to clean it up.
207 IpSb
= AllocateZeroPool (sizeof (IP4_SERVICE
));
210 return EFI_OUT_OF_RESOURCES
;
213 IpSb
->Signature
= IP4_SERVICE_SIGNATURE
;
214 IpSb
->ServiceBinding
.CreateChild
= Ip4ServiceBindingCreateChild
;
215 IpSb
->ServiceBinding
.DestroyChild
= Ip4ServiceBindingDestroyChild
;
216 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
218 IpSb
->NumChildren
= 0;
219 InitializeListHead (&IpSb
->Children
);
221 InitializeListHead (&IpSb
->Interfaces
);
222 IpSb
->DefaultInterface
= NULL
;
223 IpSb
->DefaultRouteTable
= NULL
;
225 Ip4InitAssembleTable (&IpSb
->Assemble
);
227 IpSb
->IgmpCtrl
.Igmpv1QuerySeen
= 0;
228 InitializeListHead (&IpSb
->IgmpCtrl
.Groups
);
230 IpSb
->Image
= ImageHandle
;
231 IpSb
->Controller
= Controller
;
233 IpSb
->MnpChildHandle
= NULL
;
236 IpSb
->MnpConfigData
.ReceivedQueueTimeoutValue
= 0;
237 IpSb
->MnpConfigData
.TransmitQueueTimeoutValue
= 0;
238 IpSb
->MnpConfigData
.ProtocolTypeFilter
= IP4_ETHER_PROTO
;
239 IpSb
->MnpConfigData
.EnableUnicastReceive
= TRUE
;
240 IpSb
->MnpConfigData
.EnableMulticastReceive
= TRUE
;
241 IpSb
->MnpConfigData
.EnableBroadcastReceive
= TRUE
;
242 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= FALSE
;
243 IpSb
->MnpConfigData
.FlushQueuesOnReset
= TRUE
;
244 IpSb
->MnpConfigData
.EnableReceiveTimestamps
= FALSE
;
245 IpSb
->MnpConfigData
.DisableBackgroundPolling
= FALSE
;
247 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
250 IpSb
->ReconfigCheckTimer
= NULL
;
252 IpSb
->ReconfigEvent
= NULL
;
254 IpSb
->Reconfig
= FALSE
;
256 IpSb
->MediaPresent
= TRUE
;
259 // Create various resources. First create the route table, timer
260 // event, ReconfigEvent and MNP child. IGMP, interface's initialization depend
263 IpSb
->DefaultRouteTable
= Ip4CreateRouteTable ();
265 if (IpSb
->DefaultRouteTable
== NULL
) {
266 Status
= EFI_OUT_OF_RESOURCES
;
270 Status
= gBS
->CreateEvent (
271 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
278 if (EFI_ERROR (Status
)) {
282 Status
= gBS
->CreateEvent (
283 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
285 Ip4TimerReconfigChecking
,
287 &IpSb
->ReconfigCheckTimer
290 if (EFI_ERROR (Status
)) {
294 Status
= gBS
->CreateEvent (
297 Ip4AutoReconfigCallBack
,
301 if (EFI_ERROR (Status
)) {
305 Status
= NetLibCreateServiceChild (
308 &gEfiManagedNetworkServiceBindingProtocolGuid
,
309 &IpSb
->MnpChildHandle
312 if (EFI_ERROR (Status
)) {
316 Status
= gBS
->OpenProtocol (
317 IpSb
->MnpChildHandle
,
318 &gEfiManagedNetworkProtocolGuid
,
319 (VOID
**) &IpSb
->Mnp
,
322 EFI_OPEN_PROTOCOL_BY_DRIVER
325 if (EFI_ERROR (Status
)) {
329 Status
= Ip4ServiceConfigMnp (IpSb
, TRUE
);
331 if (EFI_ERROR (Status
)) {
335 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
337 if (EFI_ERROR (Status
)) {
341 Status
= Ip4InitIgmp (IpSb
);
343 if (EFI_ERROR (Status
)) {
347 IpSb
->MacString
= NULL
;
348 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
350 if (EFI_ERROR (Status
)) {
354 IpSb
->DefaultInterface
= Ip4CreateInterface (IpSb
->Mnp
, Controller
, ImageHandle
);
356 if (IpSb
->DefaultInterface
== NULL
) {
357 Status
= EFI_OUT_OF_RESOURCES
;
361 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
363 ZeroMem (&IpSb
->Ip4Config2Instance
, sizeof (IP4_CONFIG2_INSTANCE
));
365 Status
= Ip4Config2InitInstance (&IpSb
->Ip4Config2Instance
);
367 if (EFI_ERROR (Status
)) {
371 IpSb
->MaxPacketSize
= IpSb
->SnpMode
.MaxPacketSize
- sizeof (IP4_HEAD
);
372 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
374 // This is a VLAN device, reduce MTU by VLAN tag length
376 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
378 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
384 Ip4CleanService (IpSb
);
392 Clean up a IP4 service binding instance. It will release all
393 the resource allocated by the instance. The instance may be
394 partly initialized, or partly destroyed. If a resource is
395 destroyed, it is marked as that in case the destroy failed and
396 being called again later.
398 @param[in] IpSb The IP4 service binding instance to clean up
400 @retval EFI_SUCCESS The resource used by the instance are cleaned up
401 @retval other Failed to clean up some of the resources.
411 IpSb
->State
= IP4_SERVICE_DESTROY
;
413 if (IpSb
->Timer
!= NULL
) {
414 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
415 gBS
->CloseEvent (IpSb
->Timer
);
420 if (IpSb
->ReconfigCheckTimer
!= NULL
) {
421 gBS
->SetTimer (IpSb
->ReconfigCheckTimer
, TimerCancel
, 0);
422 gBS
->CloseEvent (IpSb
->ReconfigCheckTimer
);
424 IpSb
->ReconfigCheckTimer
= NULL
;
427 if (IpSb
->DefaultInterface
!= NULL
) {
428 Status
= Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
430 if (EFI_ERROR (Status
)) {
434 IpSb
->DefaultInterface
= NULL
;
437 if (IpSb
->DefaultRouteTable
!= NULL
) {
438 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
439 IpSb
->DefaultRouteTable
= NULL
;
442 Ip4CleanAssembleTable (&IpSb
->Assemble
);
444 if (IpSb
->MnpChildHandle
!= NULL
) {
445 if (IpSb
->Mnp
!= NULL
) {
447 IpSb
->MnpChildHandle
,
448 &gEfiManagedNetworkProtocolGuid
,
456 NetLibDestroyServiceChild (
459 &gEfiManagedNetworkServiceBindingProtocolGuid
,
463 IpSb
->MnpChildHandle
= NULL
;
466 if (IpSb
->ReconfigEvent
!= NULL
) {
467 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
469 IpSb
->ReconfigEvent
= NULL
;
472 IpSb
->Reconfig
= FALSE
;
474 if (IpSb
->MacString
!= NULL
) {
475 FreePool (IpSb
->MacString
);
478 Ip4Config2CleanInstance (&IpSb
->Ip4Config2Instance
);
484 Callback function which provided by user to remove one node in NetDestroyLinkList process.
486 @param[in] Entry The entry to be removed.
487 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
489 @retval EFI_SUCCESS The entry has been removed successfully.
490 @retval Others Fail to remove the entry.
495 Ip4DestroyChildEntryInHandleBuffer (
496 IN LIST_ENTRY
*Entry
,
500 IP4_PROTOCOL
*IpInstance
;
501 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
502 UINTN NumberOfChildren
;
503 EFI_HANDLE
*ChildHandleBuffer
;
505 if (Entry
== NULL
|| Context
== NULL
) {
506 return EFI_INVALID_PARAMETER
;
509 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_PROTOCOL
, Link
, IP4_PROTOCOL_SIGNATURE
);
510 ServiceBinding
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
511 NumberOfChildren
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
512 ChildHandleBuffer
= ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
514 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
518 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
522 Start this driver on ControllerHandle. This service is called by the
523 EFI boot service ConnectController(). In order to make
524 drivers as small as possible, there are a few calling restrictions for
525 this service. ConnectController() must follow these
526 calling restrictions. If any other agent wishes to call Start() it
527 must also follow these calling restrictions.
529 @param[in] This Protocol instance pointer.
530 @param[in] ControllerHandle Handle of device to bind driver to
531 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
534 @retval EFI_SUCCESS This driver is added to ControllerHandle
535 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
536 @retval other This driver does not support this device
541 Ip4DriverBindingStart (
542 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
543 IN EFI_HANDLE ControllerHandle
,
544 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
549 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Cfg2
;
551 IP4_CONFIG2_DATA_ITEM
*DataItem
;
558 // Test for the Ip4 service binding protocol
560 Status
= gBS
->OpenProtocol (
562 &gEfiIp4ServiceBindingProtocolGuid
,
564 This
->DriverBindingHandle
,
566 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
569 if (Status
== EFI_SUCCESS
) {
570 return EFI_ALREADY_STARTED
;
573 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
575 if (EFI_ERROR (Status
)) {
579 ASSERT (IpSb
!= NULL
);
581 Ip4Cfg2
= &IpSb
->Ip4Config2Instance
.Ip4Config2
;
584 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
586 Status
= gBS
->InstallMultipleProtocolInterfaces (
588 &gEfiIp4ServiceBindingProtocolGuid
,
589 &IpSb
->ServiceBinding
,
590 &gEfiIp4Config2ProtocolGuid
,
595 if (EFI_ERROR (Status
)) {
600 // Read the config data from NV variable again.
601 // The default data can be changed by other drivers.
603 Status
= Ip4Config2ReadConfigData (IpSb
->MacString
, &IpSb
->Ip4Config2Instance
);
604 if (EFI_ERROR (Status
)) {
605 goto UNINSTALL_PROTOCOL
;
609 // Consume the installed EFI_IP4_CONFIG2_PROTOCOL to set the default data items.
611 for (Index
= Ip4Config2DataTypePolicy
; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
612 DataItem
= &IpSb
->Ip4Config2Instance
.DataItem
[Index
];
613 if (DataItem
->Data
.Ptr
!= NULL
) {
614 Status
= Ip4Cfg2
->SetData (
620 if (EFI_ERROR(Status
)) {
621 goto UNINSTALL_PROTOCOL
;
624 if (Index
== Ip4Config2DataTypePolicy
&& (*(DataItem
->Data
.Policy
) == Ip4Config2PolicyDhcp
)) {
631 // Ready to go: start the receiving and timer.
632 // Ip4Config2SetPolicy maybe call Ip4ReceiveFrame() to set the default interface's RecvRequest first after
633 // Ip4Config2 instance is initialized. So, EFI_ALREADY_STARTED is the allowed return status.
635 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
637 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
638 goto UNINSTALL_PROTOCOL
;
641 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
643 if (EFI_ERROR (Status
)) {
644 goto UNINSTALL_PROTOCOL
;
647 Status
= gBS
->SetTimer (IpSb
->ReconfigCheckTimer
, TimerPeriodic
, 500 * TICKS_PER_MS
);
649 if (EFI_ERROR (Status
)) {
650 goto UNINSTALL_PROTOCOL
;
654 // Initialize the IP4 ID
656 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
661 gBS
->UninstallMultipleProtocolInterfaces (
663 &gEfiIp4ServiceBindingProtocolGuid
,
664 &IpSb
->ServiceBinding
,
665 &gEfiIp4Config2ProtocolGuid
,
671 Ip4CleanService (IpSb
);
678 Stop this driver on ControllerHandle. This service is called by the
679 EFI boot service DisconnectController(). In order to
680 make drivers as small as possible, there are a few calling
681 restrictions for this service. DisconnectController()
682 must follow these calling restrictions. If any other agent wishes
683 to call Stop() it must also follow these calling restrictions.
685 @param[in] This Protocol instance pointer.
686 @param[in] ControllerHandle Handle of device to stop driver on
687 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
688 of children is zero stop the entire bus driver.
689 @param[in] ChildHandleBuffer List of Child Handles to Stop.
691 @retval EFI_SUCCESS This driver is removed ControllerHandle
692 @retval other This driver was not removed from this device
697 Ip4DriverBindingStop (
698 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
699 IN EFI_HANDLE ControllerHandle
,
700 IN UINTN NumberOfChildren
,
701 IN EFI_HANDLE
*ChildHandleBuffer
704 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
706 EFI_HANDLE NicHandle
;
710 IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
712 IP4_ROUTE_TABLE
*RouteTable
;
718 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
719 if (NicHandle
== NULL
) {
720 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
721 if (NicHandle
== NULL
) {
722 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
723 if (NicHandle
!= NULL
) {
731 Status
= gBS
->OpenProtocol (
733 &gEfiIp4ServiceBindingProtocolGuid
,
734 (VOID
**) &ServiceBinding
,
735 This
->DriverBindingHandle
,
737 EFI_OPEN_PROTOCOL_GET_PROTOCOL
739 if (EFI_ERROR (Status
)) {
740 return EFI_DEVICE_ERROR
;
743 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
746 Status
= Ip4Config2DestroyDhcp4 (&IpSb
->Ip4Config2Instance
);
747 gBS
->CloseEvent (IpSb
->Ip4Config2Instance
.Dhcp4Event
);
748 IpSb
->Ip4Config2Instance
.Dhcp4Event
= NULL
;
749 } else if (NumberOfChildren
!= 0) {
750 List
= &IpSb
->Children
;
751 Context
.ServiceBinding
= ServiceBinding
;
752 Context
.NumberOfChildren
= NumberOfChildren
;
753 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
754 Status
= NetDestroyLinkList (
756 Ip4DestroyChildEntryInHandleBuffer
,
760 } else if (IpSb
->DefaultInterface
->ArpHandle
== ControllerHandle
) {
763 // The ARP protocol for the default interface is being uninstalled and all
764 // its IP child handles should have been destroyed before. So, release the
765 // default interface and route table, create a new one and mark it as not started.
767 Ip4CancelReceive (IpSb
->DefaultInterface
);
768 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
769 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
771 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
775 RouteTable
= Ip4CreateRouteTable ();
776 if (RouteTable
== NULL
) {
777 Ip4FreeInterface (IpIf
, NULL
);
781 IpSb
->DefaultInterface
= IpIf
;
782 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
783 IpSb
->DefaultRouteTable
= RouteTable
;
784 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
786 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
788 } else if (IsListEmpty (&IpSb
->Children
)) {
791 // OK, clean other resources then uninstall the service binding protocol.
793 Status
= Ip4CleanService (IpSb
);
794 if (EFI_ERROR (Status
)) {
799 gBS
->UninstallMultipleProtocolInterfaces (
801 &gEfiIp4ServiceBindingProtocolGuid
,
803 &gEfiIp4Config2ProtocolGuid
,
804 &IpSb
->Ip4Config2Instance
.Ip4Config2
,
808 if (gIp4ControllerNameTable
!= NULL
) {
809 FreeUnicodeStringTable (gIp4ControllerNameTable
);
810 gIp4ControllerNameTable
= NULL
;
821 Creates a child handle and installs a protocol.
823 The CreateChild() function installs a protocol on ChildHandle.
824 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
825 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
827 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
828 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
829 then a new handle is created. If it is a pointer to an existing UEFI handle,
830 then the protocol is added to the existing UEFI handle.
832 @retval EFI_SUCCES The protocol was added to ChildHandle.
833 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
834 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
836 @retval other The child handle was not created
841 Ip4ServiceBindingCreateChild (
842 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
843 IN OUT EFI_HANDLE
*ChildHandle
847 IP4_PROTOCOL
*IpInstance
;
852 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
853 return EFI_INVALID_PARAMETER
;
856 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
857 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
859 if (IpInstance
== NULL
) {
860 return EFI_OUT_OF_RESOURCES
;
863 Ip4InitProtocol (IpSb
, IpInstance
);
866 // Install Ip4 onto ChildHandle
868 Status
= gBS
->InstallMultipleProtocolInterfaces (
870 &gEfiIp4ProtocolGuid
,
871 &IpInstance
->Ip4Proto
,
875 if (EFI_ERROR (Status
)) {
879 IpInstance
->Handle
= *ChildHandle
;
882 // Open the Managed Network protocol BY_CHILD.
884 Status
= gBS
->OpenProtocol (
885 IpSb
->MnpChildHandle
,
886 &gEfiManagedNetworkProtocolGuid
,
888 gIp4DriverBinding
.DriverBindingHandle
,
890 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
892 if (EFI_ERROR (Status
)) {
893 gBS
->UninstallMultipleProtocolInterfaces (
895 &gEfiIp4ProtocolGuid
,
896 &IpInstance
->Ip4Proto
,
904 // Insert it into the service binding instance.
906 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
908 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
911 gBS
->RestoreTPL (OldTpl
);
915 if (EFI_ERROR (Status
)) {
917 Ip4CleanProtocol (IpInstance
);
919 FreePool (IpInstance
);
927 Destroys a child handle with a protocol installed on it.
929 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
930 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
931 last protocol on ChildHandle, then ChildHandle is destroyed.
933 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
934 @param ChildHandle Handle of the child to destroy
936 @retval EFI_SUCCES The protocol was removed from ChildHandle.
937 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
938 @retval EFI_INVALID_PARAMETER Child handle is NULL.
939 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
940 because its services are being used.
941 @retval other The child handle was not destroyed
946 Ip4ServiceBindingDestroyChild (
947 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
948 IN EFI_HANDLE ChildHandle
953 IP4_PROTOCOL
*IpInstance
;
954 EFI_IP4_PROTOCOL
*Ip4
;
957 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
958 return EFI_INVALID_PARAMETER
;
962 // Retrieve the private context data structures
964 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
966 Status
= gBS
->OpenProtocol (
968 &gEfiIp4ProtocolGuid
,
970 gIp4DriverBinding
.DriverBindingHandle
,
972 EFI_OPEN_PROTOCOL_GET_PROTOCOL
975 if (EFI_ERROR (Status
)) {
976 return EFI_UNSUPPORTED
;
979 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
981 if (IpInstance
->Service
!= IpSb
) {
982 return EFI_INVALID_PARAMETER
;
985 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
988 // A child can be destroyed more than once. For example,
989 // Ip4DriverBindingStop will destroy all of its children.
990 // when UDP driver is being stopped, it will destroy all
991 // the IP child it opens.
993 if (IpInstance
->InDestroy
) {
994 gBS
->RestoreTPL (OldTpl
);
998 IpInstance
->InDestroy
= TRUE
;
1001 // Close the Managed Network protocol.
1003 gBS
->CloseProtocol (
1004 IpSb
->MnpChildHandle
,
1005 &gEfiManagedNetworkProtocolGuid
,
1006 gIp4DriverBinding
.DriverBindingHandle
,
1010 if (IpInstance
->Interface
!= NULL
&& IpInstance
->Interface
->Arp
!= NULL
) {
1011 gBS
->CloseProtocol (
1012 IpInstance
->Interface
->ArpHandle
,
1013 &gEfiArpProtocolGuid
,
1014 gIp4DriverBinding
.DriverBindingHandle
,
1020 // Uninstall the IP4 protocol first. Many thing happens during
1022 // 1. The consumer of the IP4 protocol will be stopped if it
1023 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
1024 // stopped, IP driver's stop function will be called, and uninstall
1025 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
1026 // makes it possible to create the network stack bottom up, and
1027 // stop it top down.
1028 // 2. the upper layer will recycle the received packet. The recycle
1029 // event's TPL is higher than this function. The recycle events
1030 // will be called back before preceeding. If any packets not recycled,
1031 // that means there is a resource leak.
1033 gBS
->RestoreTPL (OldTpl
);
1034 Status
= gBS
->UninstallProtocolInterface (
1036 &gEfiIp4ProtocolGuid
,
1037 &IpInstance
->Ip4Proto
1039 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1040 if (EFI_ERROR (Status
)) {
1041 IpInstance
->InDestroy
= FALSE
;
1045 Status
= Ip4CleanProtocol (IpInstance
);
1046 if (EFI_ERROR (Status
)) {
1047 gBS
->InstallMultipleProtocolInterfaces (
1049 &gEfiIp4ProtocolGuid
,
1057 RemoveEntryList (&IpInstance
->Link
);
1058 IpSb
->NumChildren
--;
1060 gBS
->RestoreTPL (OldTpl
);
1062 FreePool (IpInstance
);
1066 gBS
->RestoreTPL (OldTpl
);