2 The driver binding and service binding protocol for IP6 driver.
4 Copyright (c) 2009 - 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 gIp6DriverBinding
= {
14 Ip6DriverBindingSupported
,
15 Ip6DriverBindingStart
,
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 IP6 driver which installs 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.
99 @param[in] This Protocol instance pointer.
100 @param[in] ControllerHandle Handle of device to test.
101 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
104 @retval EFI_SUCCESS This driver supports this device.
105 @retval EFI_ALREADY_STARTED This driver is already running on this device.
106 @retval other This driver does not support this device.
111 Ip6DriverBindingSupported (
112 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
113 IN EFI_HANDLE ControllerHandle
,
114 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
118 // Test for the MNP service binding Protocol
120 return gBS
->OpenProtocol (
122 &gEfiManagedNetworkServiceBindingProtocolGuid
,
124 This
->DriverBindingHandle
,
126 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
131 Clean up an IP6 service binding instance. It releases all
132 the resource allocated by the instance. The instance may be
133 partly initialized, or partly destroyed. If a resource is
134 destroyed, it is marked as that in case the destroy failed and
135 being called again later.
137 @param[in] IpSb The IP6 service binding instance to clean up.
139 @retval EFI_SUCCESS The resource used by the instance are cleaned up.
140 @retval Others Failed to clean up some of the resources.
149 EFI_IPv6_ADDRESS AllNodes
;
150 IP6_NEIGHBOR_ENTRY
*NeighborCache
;
152 IpSb
->State
= IP6_SERVICE_DESTROY
;
154 if (IpSb
->Timer
!= NULL
) {
155 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
156 gBS
->CloseEvent (IpSb
->Timer
);
161 if (IpSb
->FasterTimer
!= NULL
) {
162 gBS
->SetTimer (IpSb
->FasterTimer
, TimerCancel
, 0);
163 gBS
->CloseEvent (IpSb
->FasterTimer
);
165 IpSb
->FasterTimer
= NULL
;
168 Ip6ConfigCleanInstance (&IpSb
->Ip6ConfigInstance
);
170 if (!IpSb
->LinkLocalDadFail
) {
172 // Leave link-scope all-nodes multicast address (FF02::1)
174 Ip6SetToAllNodeMulticast (FALSE
, IP6_LINK_LOCAL_SCOPE
, &AllNodes
);
176 Status
= Ip6LeaveGroup (IpSb
, &AllNodes
);
177 if (EFI_ERROR (Status
)) {
182 if (IpSb
->DefaultInterface
!= NULL
) {
183 Ip6CleanInterface (IpSb
->DefaultInterface
, NULL
);
184 IpSb
->DefaultInterface
= NULL
;
187 Ip6CleanDefaultRouterList (IpSb
);
189 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
190 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
192 if (IpSb
->RouteTable
!= NULL
) {
193 Ip6CleanRouteTable (IpSb
->RouteTable
);
194 IpSb
->RouteTable
= NULL
;
197 if (IpSb
->InterfaceId
!= NULL
) {
198 FreePool (IpSb
->InterfaceId
);
201 IpSb
->InterfaceId
= NULL
;
203 Ip6CleanAssembleTable (&IpSb
->Assemble
);
205 if (IpSb
->MnpChildHandle
!= NULL
) {
206 if (IpSb
->Mnp
!= NULL
) {
207 IpSb
->Mnp
->Cancel (IpSb
->Mnp
, NULL
);
208 IpSb
->Mnp
->Configure (IpSb
->Mnp
, NULL
);
210 IpSb
->MnpChildHandle
,
211 &gEfiManagedNetworkProtocolGuid
,
219 NetLibDestroyServiceChild (
222 &gEfiManagedNetworkServiceBindingProtocolGuid
,
226 IpSb
->MnpChildHandle
= NULL
;
229 if (IpSb
->RecvRequest
.MnpToken
.Event
!= NULL
) {
230 gBS
->CloseEvent (IpSb
->RecvRequest
.MnpToken
.Event
);
234 // Free the Neighbor Discovery resources
236 while (!IsListEmpty (&IpSb
->NeighborTable
)) {
237 NeighborCache
= NET_LIST_HEAD (&IpSb
->NeighborTable
, IP6_NEIGHBOR_ENTRY
, Link
);
238 Ip6FreeNeighborEntry (IpSb
, NeighborCache
, FALSE
, TRUE
, EFI_SUCCESS
, NULL
, NULL
);
245 Create a new IP6 driver service binding protocol.
247 @param[in] Controller The controller that has MNP service binding
249 @param[in] ImageHandle The IP6 driver's image handle.
250 @param[out] Service The variable to receive the newly created IP6
253 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
254 @retval EFI_SUCCESS A new IP6 service binding private is created.
259 IN EFI_HANDLE Controller
,
260 IN EFI_HANDLE ImageHandle
,
261 OUT IP6_SERVICE
**Service
266 EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*MnpToken
;
267 EFI_MANAGED_NETWORK_CONFIG_DATA
*Config
;
269 ASSERT (Service
!= NULL
);
274 // allocate a service private data then initialize all the filed to
275 // empty resources, so if any thing goes wrong when allocating
276 // resources, Ip6CleanService can be called to clean it up.
278 IpSb
= AllocateZeroPool (sizeof (IP6_SERVICE
));
281 return EFI_OUT_OF_RESOURCES
;
284 IpSb
->Signature
= IP6_SERVICE_SIGNATURE
;
285 IpSb
->ServiceBinding
.CreateChild
= Ip6ServiceBindingCreateChild
;
286 IpSb
->ServiceBinding
.DestroyChild
= Ip6ServiceBindingDestroyChild
;
287 IpSb
->State
= IP6_SERVICE_UNSTARTED
;
289 IpSb
->NumChildren
= 0;
290 InitializeListHead (&IpSb
->Children
);
292 InitializeListHead (&IpSb
->Interfaces
);
293 IpSb
->DefaultInterface
= NULL
;
294 IpSb
->RouteTable
= NULL
;
296 IpSb
->RecvRequest
.Signature
= IP6_LINK_RX_SIGNATURE
;
297 IpSb
->RecvRequest
.CallBack
= NULL
;
298 IpSb
->RecvRequest
.Context
= NULL
;
299 MnpToken
= &IpSb
->RecvRequest
.MnpToken
;
300 MnpToken
->Event
= NULL
;
301 MnpToken
->Status
= EFI_NOT_READY
;
302 MnpToken
->Packet
.RxData
= NULL
;
304 Ip6CreateAssembleTable (&IpSb
->Assemble
);
306 IpSb
->MldCtrl
.Mldv1QuerySeen
= 0;
307 InitializeListHead (&IpSb
->MldCtrl
.Groups
);
309 ZeroMem (&IpSb
->LinkLocalAddr
, sizeof (EFI_IPv6_ADDRESS
));
310 IpSb
->LinkLocalOk
= FALSE
;
311 IpSb
->LinkLocalDadFail
= FALSE
;
312 IpSb
->Dhcp6NeedStart
= FALSE
;
313 IpSb
->Dhcp6NeedInfoRequest
= FALSE
;
315 IpSb
->CurHopLimit
= IP6_HOP_LIMIT
;
316 IpSb
->LinkMTU
= IP6_MIN_LINK_MTU
;
317 IpSb
->BaseReachableTime
= IP6_REACHABLE_TIME
;
318 Ip6UpdateReachableTime (IpSb
);
320 // RFC4861 RETRANS_TIMER: 1,000 milliseconds
322 IpSb
->RetransTimer
= IP6_RETRANS_TIMER
;
324 IpSb
->RoundRobin
= 0;
326 InitializeListHead (&IpSb
->NeighborTable
);
327 InitializeListHead (&IpSb
->DefaultRouterList
);
328 InitializeListHead (&IpSb
->OnlinkPrefix
);
329 InitializeListHead (&IpSb
->AutonomousPrefix
);
331 IpSb
->InterfaceIdLen
= IP6_IF_ID_LEN
;
332 IpSb
->InterfaceId
= NULL
;
334 IpSb
->RouterAdvertiseReceived
= FALSE
;
335 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
338 IpSb
->Image
= ImageHandle
;
339 IpSb
->Controller
= Controller
;
341 IpSb
->MnpChildHandle
= NULL
;
344 Config
= &IpSb
->MnpConfigData
;
345 Config
->ReceivedQueueTimeoutValue
= 0;
346 Config
->TransmitQueueTimeoutValue
= 0;
347 Config
->ProtocolTypeFilter
= IP6_ETHER_PROTO
;
348 Config
->EnableUnicastReceive
= TRUE
;
349 Config
->EnableMulticastReceive
= TRUE
;
350 Config
->EnableBroadcastReceive
= TRUE
;
351 Config
->EnablePromiscuousReceive
= FALSE
;
352 Config
->FlushQueuesOnReset
= TRUE
;
353 Config
->EnableReceiveTimestamps
= FALSE
;
354 Config
->DisableBackgroundPolling
= FALSE
;
356 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
359 IpSb
->FasterTimer
= NULL
;
361 ZeroMem (&IpSb
->Ip6ConfigInstance
, sizeof (IP6_CONFIG_INSTANCE
));
363 IpSb
->MacString
= NULL
;
366 // Create various resources. First create the route table, timer
367 // event, MNP token event and MNP child.
370 IpSb
->RouteTable
= Ip6CreateRouteTable ();
371 if (IpSb
->RouteTable
== NULL
) {
372 Status
= EFI_OUT_OF_RESOURCES
;
376 Status
= gBS
->CreateEvent (
377 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
383 if (EFI_ERROR (Status
)) {
387 Status
= gBS
->CreateEvent (
388 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
390 Ip6NdFasterTimerTicking
,
394 if (EFI_ERROR (Status
)) {
398 Status
= NetLibCreateServiceChild (
401 &gEfiManagedNetworkServiceBindingProtocolGuid
,
402 &IpSb
->MnpChildHandle
404 if (EFI_ERROR (Status
)) {
408 Status
= gBS
->OpenProtocol (
409 IpSb
->MnpChildHandle
,
410 &gEfiManagedNetworkProtocolGuid
,
411 (VOID
**) (&IpSb
->Mnp
),
414 EFI_OPEN_PROTOCOL_BY_DRIVER
416 if (EFI_ERROR (Status
)) {
420 Status
= Ip6ServiceConfigMnp (IpSb
, TRUE
);
421 if (EFI_ERROR (Status
)) {
425 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
426 if (EFI_ERROR (Status
)) {
430 IpSb
->MaxPacketSize
= IP6_MIN_LINK_MTU
- sizeof (EFI_IP6_HEADER
);
431 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
433 // This is a VLAN device, reduce MTU by VLAN tag length
435 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
437 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
440 // Currently only ETHERNET is supported in IPv6 stack, since
441 // link local address requires an IEEE 802 48-bit MACs for
442 // EUI-64 format interface identifier mapping.
444 if (IpSb
->SnpMode
.IfType
!= NET_IFTYPE_ETHERNET
) {
445 Status
= EFI_UNSUPPORTED
;
449 Status
= Ip6InitMld (IpSb
);
450 if (EFI_ERROR (Status
)) {
454 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
455 if (EFI_ERROR (Status
)) {
459 Status
= Ip6ConfigInitInstance (&IpSb
->Ip6ConfigInstance
);
460 if (EFI_ERROR (Status
)) {
464 IpSb
->DefaultInterface
= Ip6CreateInterface (IpSb
, TRUE
);
465 if (IpSb
->DefaultInterface
== NULL
) {
466 Status
= EFI_DEVICE_ERROR
;
470 Status
= gBS
->CreateEvent (
477 if (EFI_ERROR (Status
)) {
481 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
487 Ip6CleanService (IpSb
);
494 Start this driver on ControllerHandle.
496 @param[in] This Protocol instance pointer.
497 @param[in] ControllerHandle Handle of device to bind driver to.
498 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
501 @retval EFI_SUCCESS This driver is added to ControllerHandle.
502 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
503 @retval other This driver does not support this device.
508 Ip6DriverBindingStart (
509 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
510 IN EFI_HANDLE ControllerHandle
,
511 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
516 EFI_IP6_CONFIG_PROTOCOL
*Ip6Cfg
;
517 IP6_CONFIG_DATA_ITEM
*DataItem
;
524 // Test for the Ip6 service binding protocol
526 Status
= gBS
->OpenProtocol (
528 &gEfiIp6ServiceBindingProtocolGuid
,
530 This
->DriverBindingHandle
,
532 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
535 if (Status
== EFI_SUCCESS
) {
536 return EFI_ALREADY_STARTED
;
539 Status
= Ip6CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
541 if (EFI_ERROR (Status
)) {
545 ASSERT (IpSb
!= NULL
);
547 Ip6Cfg
= &IpSb
->Ip6ConfigInstance
.Ip6Config
;
550 // Install the Ip6ServiceBinding Protocol onto ControllerHandle
552 Status
= gBS
->InstallMultipleProtocolInterfaces (
554 &gEfiIp6ServiceBindingProtocolGuid
,
555 &IpSb
->ServiceBinding
,
556 &gEfiIp6ConfigProtocolGuid
,
560 if (EFI_ERROR (Status
)) {
565 // Read the config data from NV variable again.
566 // The default data can be changed by other drivers.
568 Status
= Ip6ConfigReadConfigData (IpSb
->MacString
, &IpSb
->Ip6ConfigInstance
);
569 if (EFI_ERROR (Status
)) {
570 goto UNINSTALL_PROTOCOL
;
574 // If there is any default manual address, set it.
576 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeManualAddress
];
577 if (DataItem
->Data
.Ptr
!= NULL
) {
578 Status
= Ip6Cfg
->SetData (
580 Ip6ConfigDataTypeManualAddress
,
584 if (Status
== EFI_INVALID_PARAMETER
|| Status
== EFI_BAD_BUFFER_SIZE
) {
586 // Clean the invalid ManualAddress configuration.
588 Status
= Ip6Cfg
->SetData (
590 Ip6ConfigDataTypeManualAddress
,
594 DEBUG ((EFI_D_WARN
, "Ip6DriverBindingStart: Clean the invalid ManualAddress configuration.\n"));
599 // If there is any default gateway address, set it.
601 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeGateway
];
602 if (DataItem
->Data
.Ptr
!= NULL
) {
603 Status
= Ip6Cfg
->SetData (
605 Ip6ConfigDataTypeGateway
,
609 if (Status
== EFI_INVALID_PARAMETER
|| Status
== EFI_BAD_BUFFER_SIZE
) {
611 // Clean the invalid Gateway configuration.
613 Status
= Ip6Cfg
->SetData (
615 Ip6ConfigDataTypeGateway
,
619 DEBUG ((EFI_D_WARN
, "Ip6DriverBindingStart: Clean the invalid Gateway configuration.\n"));
624 // ready to go: start the receiving and timer
626 Status
= Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
627 if (EFI_ERROR (Status
)) {
628 goto UNINSTALL_PROTOCOL
;
632 // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds.
634 Status
= gBS
->SetTimer (
637 TICKS_PER_MS
* IP6_TIMER_INTERVAL_IN_MS
639 if (EFI_ERROR (Status
)) {
640 goto UNINSTALL_PROTOCOL
;
644 // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds.
646 Status
= gBS
->SetTimer (
649 TICKS_PER_MS
* IP6_ONE_SECOND_IN_MS
651 if (EFI_ERROR (Status
)) {
652 goto UNINSTALL_PROTOCOL
;
656 // Initialize the IP6 ID
658 mIp6Id
= NET_RANDOM (NetRandomInitSeed ());
663 gBS
->UninstallMultipleProtocolInterfaces (
665 &gEfiIp6ServiceBindingProtocolGuid
,
666 &IpSb
->ServiceBinding
,
667 &gEfiIp6ConfigProtocolGuid
,
673 Ip6CleanService (IpSb
);
679 Callback function which provided by user to remove one node in NetDestroyLinkList process.
681 @param[in] Entry The entry to be removed.
682 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
684 @retval EFI_SUCCESS The entry has been removed successfully.
685 @retval Others Fail to remove the entry.
690 Ip6DestroyChildEntryInHandleBuffer (
691 IN LIST_ENTRY
*Entry
,
695 IP6_PROTOCOL
*IpInstance
;
696 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
697 UINTN NumberOfChildren
;
698 EFI_HANDLE
*ChildHandleBuffer
;
700 if (Entry
== NULL
|| Context
== NULL
) {
701 return EFI_INVALID_PARAMETER
;
704 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_PROTOCOL
, Link
, IP6_PROTOCOL_SIGNATURE
);
705 ServiceBinding
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
706 NumberOfChildren
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
707 ChildHandleBuffer
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
709 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
713 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
717 Stop this driver on ControllerHandle.
719 @param[in] This Protocol instance pointer.
720 @param[in] ControllerHandle Handle of device to stop driver on.
721 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
722 of children is zero, stop the entire bus driver.
723 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
724 if NumberOfChildren is 0.
726 @retval EFI_SUCCESS The device was stopped.
727 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
732 Ip6DriverBindingStop (
733 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
734 IN EFI_HANDLE ControllerHandle
,
735 IN UINTN NumberOfChildren
,
736 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
739 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
741 EFI_HANDLE NicHandle
;
746 IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
749 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
750 if (NicHandle
== NULL
) {
751 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
752 if (NicHandle
!= NULL
) {
759 Status
= gBS
->OpenProtocol (
761 &gEfiIp6ServiceBindingProtocolGuid
,
762 (VOID
**) &ServiceBinding
,
763 This
->DriverBindingHandle
,
765 EFI_OPEN_PROTOCOL_GET_PROTOCOL
767 if (EFI_ERROR (Status
)) {
768 return EFI_DEVICE_ERROR
;
771 IpSb
= IP6_SERVICE_FROM_PROTOCOL (ServiceBinding
);
774 Status
= Ip6ConfigDestroyDhcp6 (&IpSb
->Ip6ConfigInstance
);
775 gBS
->CloseEvent (IpSb
->Ip6ConfigInstance
.Dhcp6Event
);
776 IpSb
->Ip6ConfigInstance
.Dhcp6Event
= NULL
;
777 } else if (NumberOfChildren
!= 0) {
779 // NumberOfChildren is not zero, destroy the IP6 children instances in ChildHandleBuffer.
781 List
= &IpSb
->Children
;
782 Context
.ServiceBinding
= ServiceBinding
;
783 Context
.NumberOfChildren
= NumberOfChildren
;
784 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
785 Status
= NetDestroyLinkList (
787 Ip6DestroyChildEntryInHandleBuffer
,
791 } else if (IsListEmpty (&IpSb
->Children
)) {
793 Status
= Ip6CleanService (IpSb
);
794 if (EFI_ERROR (Status
)) {
799 Status
= gBS
->UninstallMultipleProtocolInterfaces (
801 &gEfiIp6ServiceBindingProtocolGuid
,
803 &gEfiIp6ConfigProtocolGuid
,
804 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
807 ASSERT_EFI_ERROR (Status
);
809 Status
= EFI_SUCCESS
;
818 Creates a child handle with a set of I/O services.
820 @param[in] This Protocol instance pointer.
821 @param[in] ChildHandle Pointer to the handle of the child to create. If
822 it is NULL, then a new handle is created. If it
823 is not NULL, then the I/O services are added to
824 the existing child handle.
826 @retval EFI_SUCCESS The child handle was created with the I/O services.
827 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
829 @retval other The child handle was not created.
834 Ip6ServiceBindingCreateChild (
835 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
836 IN EFI_HANDLE
*ChildHandle
840 IP6_PROTOCOL
*IpInstance
;
845 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
846 return EFI_INVALID_PARAMETER
;
849 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
851 if (IpSb
->LinkLocalDadFail
) {
852 return EFI_DEVICE_ERROR
;
855 IpInstance
= AllocatePool (sizeof (IP6_PROTOCOL
));
857 if (IpInstance
== NULL
) {
858 return EFI_OUT_OF_RESOURCES
;
861 Ip6InitProtocol (IpSb
, IpInstance
);
864 // Install Ip6 onto ChildHandle
866 Status
= gBS
->InstallMultipleProtocolInterfaces (
868 &gEfiIp6ProtocolGuid
,
869 &IpInstance
->Ip6Proto
,
872 if (EFI_ERROR (Status
)) {
876 IpInstance
->Handle
= *ChildHandle
;
879 // Open the Managed Network protocol BY_CHILD.
881 Status
= gBS
->OpenProtocol (
882 IpSb
->MnpChildHandle
,
883 &gEfiManagedNetworkProtocolGuid
,
885 gIp6DriverBinding
.DriverBindingHandle
,
887 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
889 if (EFI_ERROR (Status
)) {
890 gBS
->UninstallMultipleProtocolInterfaces (
892 &gEfiIp6ProtocolGuid
,
893 &IpInstance
->Ip6Proto
,
901 // Insert it into the service binding instance.
903 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
905 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
908 gBS
->RestoreTPL (OldTpl
);
912 if (EFI_ERROR (Status
)) {
914 Ip6CleanProtocol (IpInstance
);
916 FreePool (IpInstance
);
923 Destroys a child handle with a set of I/O services.
925 @param[in] This Protocol instance pointer.
926 @param[in] ChildHandle Handle of the child to destroy.
928 @retval EFI_SUCCESS The I/O services were removed from the child
930 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
931 that are being removed.
932 @retval EFI_INVALID_PARAMETER Child handle is NULL.
933 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
934 its I/O services are being used.
935 @retval other The child handle was not destroyed.
940 Ip6ServiceBindingDestroyChild (
941 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
942 IN EFI_HANDLE ChildHandle
947 IP6_PROTOCOL
*IpInstance
;
948 EFI_IP6_PROTOCOL
*Ip6
;
951 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
952 return EFI_INVALID_PARAMETER
;
956 // Retrieve the private context data structures
958 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
960 Status
= gBS
->OpenProtocol (
962 &gEfiIp6ProtocolGuid
,
964 gIp6DriverBinding
.DriverBindingHandle
,
966 EFI_OPEN_PROTOCOL_GET_PROTOCOL
969 if (EFI_ERROR (Status
)) {
970 return EFI_UNSUPPORTED
;
973 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (Ip6
);
975 if (IpInstance
->Service
!= IpSb
) {
976 return EFI_INVALID_PARAMETER
;
979 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
982 // A child can be destroyed more than once. For example,
983 // Ip6DriverBindingStop will destroy all of its children.
984 // when UDP driver is being stopped, it will destroy all
985 // the IP child it opens.
987 if (IpInstance
->InDestroy
) {
988 gBS
->RestoreTPL (OldTpl
);
992 IpInstance
->InDestroy
= TRUE
;
995 // Close the Managed Network protocol.
998 IpSb
->MnpChildHandle
,
999 &gEfiManagedNetworkProtocolGuid
,
1000 gIp6DriverBinding
.DriverBindingHandle
,
1005 // Uninstall the IP6 protocol first. Many thing happens during
1007 // 1. The consumer of the IP6 protocol will be stopped if it
1008 // opens the protocol BY_DRIVER. For example, if MNP driver is
1009 // stopped, IP driver's stop function will be called, and uninstall
1010 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
1011 // makes it possible to create the network stack bottom up, and
1012 // stop it top down.
1013 // 2. the upper layer will recycle the received packet. The recycle
1014 // event's TPL is higher than this function. The recycle events
1015 // will be called back before preceding. If any packets not recycled,
1016 // that means there is a resource leak.
1018 gBS
->RestoreTPL (OldTpl
);
1019 Status
= gBS
->UninstallProtocolInterface (
1021 &gEfiIp6ProtocolGuid
,
1022 &IpInstance
->Ip6Proto
1024 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1025 if (EFI_ERROR (Status
)) {
1029 Status
= Ip6CleanProtocol (IpInstance
);
1030 if (EFI_ERROR (Status
)) {
1031 gBS
->InstallMultipleProtocolInterfaces (
1033 &gEfiIp6ProtocolGuid
,
1041 RemoveEntryList (&IpInstance
->Link
);
1042 ASSERT (IpSb
->NumChildren
> 0);
1043 IpSb
->NumChildren
--;
1045 gBS
->RestoreTPL (OldTpl
);
1047 FreePool (IpInstance
);
1051 gBS
->RestoreTPL (OldTpl
);