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 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 gIp6DriverBinding
= {
20 Ip6DriverBindingSupported
,
21 Ip6DriverBindingStart
,
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 IP6 driver which installs 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.
105 @param[in] This Protocol instance pointer.
106 @param[in] ControllerHandle Handle of device to test.
107 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
110 @retval EFI_SUCCESS This driver supports this device.
111 @retval EFI_ALREADY_STARTED This driver is already running on this device.
112 @retval other This driver does not support this device.
117 Ip6DriverBindingSupported (
118 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
119 IN EFI_HANDLE ControllerHandle
,
120 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
124 // Test for the MNP service binding Protocol
126 return gBS
->OpenProtocol (
128 &gEfiManagedNetworkServiceBindingProtocolGuid
,
130 This
->DriverBindingHandle
,
132 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
137 Clean up an IP6 service binding instance. It releases all
138 the resource allocated by the instance. The instance may be
139 partly initialized, or partly destroyed. If a resource is
140 destroyed, it is marked as that in case the destroy failed and
141 being called again later.
143 @param[in] IpSb The IP6 service binding instance to clean up.
145 @retval EFI_SUCCESS The resource used by the instance are cleaned up.
146 @retval Others Failed to clean up some of the resources.
155 EFI_IPv6_ADDRESS AllNodes
;
156 IP6_NEIGHBOR_ENTRY
*NeighborCache
;
158 IpSb
->State
= IP6_SERVICE_DESTROY
;
160 if (IpSb
->Timer
!= NULL
) {
161 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
162 gBS
->CloseEvent (IpSb
->Timer
);
167 if (IpSb
->FasterTimer
!= NULL
) {
168 gBS
->SetTimer (IpSb
->FasterTimer
, TimerCancel
, 0);
169 gBS
->CloseEvent (IpSb
->FasterTimer
);
171 IpSb
->FasterTimer
= NULL
;
174 Ip6ConfigCleanInstance (&IpSb
->Ip6ConfigInstance
);
176 if (!IpSb
->LinkLocalDadFail
) {
178 // Leave link-scope all-nodes multicast address (FF02::1)
180 Ip6SetToAllNodeMulticast (FALSE
, IP6_LINK_LOCAL_SCOPE
, &AllNodes
);
182 Status
= Ip6LeaveGroup (IpSb
, &AllNodes
);
183 if (EFI_ERROR (Status
)) {
188 if (IpSb
->DefaultInterface
!= NULL
) {
189 Ip6CleanInterface (IpSb
->DefaultInterface
, NULL
);
190 IpSb
->DefaultInterface
= NULL
;
193 Ip6CleanDefaultRouterList (IpSb
);
195 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
196 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
198 if (IpSb
->RouteTable
!= NULL
) {
199 Ip6CleanRouteTable (IpSb
->RouteTable
);
200 IpSb
->RouteTable
= NULL
;
203 if (IpSb
->InterfaceId
!= NULL
) {
204 FreePool (IpSb
->InterfaceId
);
207 IpSb
->InterfaceId
= NULL
;
209 Ip6CleanAssembleTable (&IpSb
->Assemble
);
211 if (IpSb
->MnpChildHandle
!= NULL
) {
212 if (IpSb
->Mnp
!= NULL
) {
213 IpSb
->Mnp
->Cancel (IpSb
->Mnp
, NULL
);
214 IpSb
->Mnp
->Configure (IpSb
->Mnp
, NULL
);
216 IpSb
->MnpChildHandle
,
217 &gEfiManagedNetworkProtocolGuid
,
225 NetLibDestroyServiceChild (
228 &gEfiManagedNetworkServiceBindingProtocolGuid
,
232 IpSb
->MnpChildHandle
= NULL
;
235 if (IpSb
->RecvRequest
.MnpToken
.Event
!= NULL
) {
236 gBS
->CloseEvent (IpSb
->RecvRequest
.MnpToken
.Event
);
240 // Free the Neighbor Discovery resources
242 while (!IsListEmpty (&IpSb
->NeighborTable
)) {
243 NeighborCache
= NET_LIST_HEAD (&IpSb
->NeighborTable
, IP6_NEIGHBOR_ENTRY
, Link
);
244 Ip6FreeNeighborEntry (IpSb
, NeighborCache
, FALSE
, TRUE
, EFI_SUCCESS
, NULL
, NULL
);
251 Create a new IP6 driver service binding protocol.
253 @param[in] Controller The controller that has MNP service binding
255 @param[in] ImageHandle The IP6 driver's image handle.
256 @param[out] Service The variable to receive the newly created IP6
259 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
260 @retval EFI_SUCCESS A new IP6 service binding private is created.
265 IN EFI_HANDLE Controller
,
266 IN EFI_HANDLE ImageHandle
,
267 OUT IP6_SERVICE
**Service
272 EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*MnpToken
;
273 EFI_MANAGED_NETWORK_CONFIG_DATA
*Config
;
275 ASSERT (Service
!= NULL
);
280 // allocate a service private data then initialize all the filed to
281 // empty resources, so if any thing goes wrong when allocating
282 // resources, Ip6CleanService can be called to clean it up.
284 IpSb
= AllocateZeroPool (sizeof (IP6_SERVICE
));
287 return EFI_OUT_OF_RESOURCES
;
290 IpSb
->Signature
= IP6_SERVICE_SIGNATURE
;
291 IpSb
->ServiceBinding
.CreateChild
= Ip6ServiceBindingCreateChild
;
292 IpSb
->ServiceBinding
.DestroyChild
= Ip6ServiceBindingDestroyChild
;
293 IpSb
->State
= IP6_SERVICE_UNSTARTED
;
295 IpSb
->NumChildren
= 0;
296 InitializeListHead (&IpSb
->Children
);
298 InitializeListHead (&IpSb
->Interfaces
);
299 IpSb
->DefaultInterface
= NULL
;
300 IpSb
->RouteTable
= NULL
;
302 IpSb
->RecvRequest
.Signature
= IP6_LINK_RX_SIGNATURE
;
303 IpSb
->RecvRequest
.CallBack
= NULL
;
304 IpSb
->RecvRequest
.Context
= NULL
;
305 MnpToken
= &IpSb
->RecvRequest
.MnpToken
;
306 MnpToken
->Event
= NULL
;
307 MnpToken
->Status
= EFI_NOT_READY
;
308 MnpToken
->Packet
.RxData
= NULL
;
310 Ip6CreateAssembleTable (&IpSb
->Assemble
);
312 IpSb
->MldCtrl
.Mldv1QuerySeen
= 0;
313 InitializeListHead (&IpSb
->MldCtrl
.Groups
);
315 ZeroMem (&IpSb
->LinkLocalAddr
, sizeof (EFI_IPv6_ADDRESS
));
316 IpSb
->LinkLocalOk
= FALSE
;
317 IpSb
->LinkLocalDadFail
= FALSE
;
318 IpSb
->Dhcp6NeedStart
= FALSE
;
319 IpSb
->Dhcp6NeedInfoRequest
= FALSE
;
321 IpSb
->CurHopLimit
= IP6_HOP_LIMIT
;
322 IpSb
->LinkMTU
= IP6_MIN_LINK_MTU
;
323 IpSb
->BaseReachableTime
= IP6_REACHABLE_TIME
;
324 Ip6UpdateReachableTime (IpSb
);
326 // RFC4861 RETRANS_TIMER: 1,000 milliseconds
328 IpSb
->RetransTimer
= IP6_RETRANS_TIMER
;
330 IpSb
->RoundRobin
= 0;
332 InitializeListHead (&IpSb
->NeighborTable
);
333 InitializeListHead (&IpSb
->DefaultRouterList
);
334 InitializeListHead (&IpSb
->OnlinkPrefix
);
335 InitializeListHead (&IpSb
->AutonomousPrefix
);
337 IpSb
->InterfaceIdLen
= IP6_IF_ID_LEN
;
338 IpSb
->InterfaceId
= NULL
;
340 IpSb
->RouterAdvertiseReceived
= FALSE
;
341 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
344 IpSb
->Image
= ImageHandle
;
345 IpSb
->Controller
= Controller
;
347 IpSb
->MnpChildHandle
= NULL
;
350 Config
= &IpSb
->MnpConfigData
;
351 Config
->ReceivedQueueTimeoutValue
= 0;
352 Config
->TransmitQueueTimeoutValue
= 0;
353 Config
->ProtocolTypeFilter
= IP6_ETHER_PROTO
;
354 Config
->EnableUnicastReceive
= TRUE
;
355 Config
->EnableMulticastReceive
= TRUE
;
356 Config
->EnableBroadcastReceive
= TRUE
;
357 Config
->EnablePromiscuousReceive
= FALSE
;
358 Config
->FlushQueuesOnReset
= TRUE
;
359 Config
->EnableReceiveTimestamps
= FALSE
;
360 Config
->DisableBackgroundPolling
= FALSE
;
362 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
365 IpSb
->FasterTimer
= NULL
;
367 ZeroMem (&IpSb
->Ip6ConfigInstance
, sizeof (IP6_CONFIG_INSTANCE
));
369 IpSb
->MacString
= NULL
;
372 // Create various resources. First create the route table, timer
373 // event, MNP token event and MNP child.
376 IpSb
->RouteTable
= Ip6CreateRouteTable ();
377 if (IpSb
->RouteTable
== NULL
) {
378 Status
= EFI_OUT_OF_RESOURCES
;
382 Status
= gBS
->CreateEvent (
383 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
389 if (EFI_ERROR (Status
)) {
393 Status
= gBS
->CreateEvent (
394 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
396 Ip6NdFasterTimerTicking
,
400 if (EFI_ERROR (Status
)) {
404 Status
= NetLibCreateServiceChild (
407 &gEfiManagedNetworkServiceBindingProtocolGuid
,
408 &IpSb
->MnpChildHandle
410 if (EFI_ERROR (Status
)) {
414 Status
= gBS
->OpenProtocol (
415 IpSb
->MnpChildHandle
,
416 &gEfiManagedNetworkProtocolGuid
,
417 (VOID
**) (&IpSb
->Mnp
),
420 EFI_OPEN_PROTOCOL_BY_DRIVER
422 if (EFI_ERROR (Status
)) {
426 Status
= Ip6ServiceConfigMnp (IpSb
, TRUE
);
427 if (EFI_ERROR (Status
)) {
431 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
432 if (EFI_ERROR (Status
)) {
436 IpSb
->MaxPacketSize
= IP6_MIN_LINK_MTU
- sizeof (EFI_IP6_HEADER
);
437 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
439 // This is a VLAN device, reduce MTU by VLAN tag length
441 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
443 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
446 // Currently only ETHERNET is supported in IPv6 stack, since
447 // link local address requires an IEEE 802 48-bit MACs for
448 // EUI-64 format interface identifier mapping.
450 if (IpSb
->SnpMode
.IfType
!= NET_IFTYPE_ETHERNET
) {
451 Status
= EFI_UNSUPPORTED
;
455 Status
= Ip6InitMld (IpSb
);
456 if (EFI_ERROR (Status
)) {
460 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
461 if (EFI_ERROR (Status
)) {
465 Status
= Ip6ConfigInitInstance (&IpSb
->Ip6ConfigInstance
);
466 if (EFI_ERROR (Status
)) {
470 IpSb
->DefaultInterface
= Ip6CreateInterface (IpSb
, TRUE
);
471 if (IpSb
->DefaultInterface
== NULL
) {
472 Status
= EFI_DEVICE_ERROR
;
476 Status
= gBS
->CreateEvent (
483 if (EFI_ERROR (Status
)) {
487 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
493 Ip6CleanService (IpSb
);
500 Start this driver on ControllerHandle.
502 @param[in] This Protocol instance pointer.
503 @param[in] ControllerHandle Handle of device to bind driver to.
504 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
507 @retval EFI_SUCCES This driver is added to ControllerHandle.
508 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
509 @retval other This driver does not support this device.
514 Ip6DriverBindingStart (
515 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
516 IN EFI_HANDLE ControllerHandle
,
517 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
522 EFI_IP6_CONFIG_PROTOCOL
*Ip6Cfg
;
523 IP6_CONFIG_DATA_ITEM
*DataItem
;
530 // Test for the Ip6 service binding protocol
532 Status
= gBS
->OpenProtocol (
534 &gEfiIp6ServiceBindingProtocolGuid
,
536 This
->DriverBindingHandle
,
538 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
541 if (Status
== EFI_SUCCESS
) {
542 return EFI_ALREADY_STARTED
;
545 Status
= Ip6CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
547 if (EFI_ERROR (Status
)) {
551 ASSERT (IpSb
!= NULL
);
553 Ip6Cfg
= &IpSb
->Ip6ConfigInstance
.Ip6Config
;
556 // Install the Ip6ServiceBinding Protocol onto ControlerHandle
558 Status
= gBS
->InstallMultipleProtocolInterfaces (
560 &gEfiIp6ServiceBindingProtocolGuid
,
561 &IpSb
->ServiceBinding
,
562 &gEfiIp6ConfigProtocolGuid
,
566 if (EFI_ERROR (Status
)) {
571 // Read the config data from NV variable again.
572 // The default data can be changed by other drivers.
574 Status
= Ip6ConfigReadConfigData (IpSb
->MacString
, &IpSb
->Ip6ConfigInstance
);
575 if (EFI_ERROR (Status
)) {
576 goto UNINSTALL_PROTOCOL
;
580 // If there is any default manual address, set it.
582 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeManualAddress
];
583 if (DataItem
->Data
.Ptr
!= NULL
) {
584 Status
= Ip6Cfg
->SetData (
586 Ip6ConfigDataTypeManualAddress
,
590 if (Status
== EFI_INVALID_PARAMETER
|| Status
== EFI_BAD_BUFFER_SIZE
) {
592 // Clean the invalid ManualAddress configuration.
594 Status
= Ip6Cfg
->SetData (
596 Ip6ConfigDataTypeManualAddress
,
600 DEBUG ((EFI_D_WARN
, "Ip6DriverBindingStart: Clean the invalid ManualAddress configuration.\n"));
605 // If there is any default gateway address, set it.
607 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeGateway
];
608 if (DataItem
->Data
.Ptr
!= NULL
) {
609 Status
= Ip6Cfg
->SetData (
611 Ip6ConfigDataTypeGateway
,
615 if (Status
== EFI_INVALID_PARAMETER
|| Status
== EFI_BAD_BUFFER_SIZE
) {
617 // Clean the invalid Gateway configuration.
619 Status
= Ip6Cfg
->SetData (
621 Ip6ConfigDataTypeGateway
,
625 DEBUG ((EFI_D_WARN
, "Ip6DriverBindingStart: Clean the invalid Gateway configuration.\n"));
630 // ready to go: start the receiving and timer
632 Status
= Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
633 if (EFI_ERROR (Status
)) {
634 goto UNINSTALL_PROTOCOL
;
638 // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds.
640 Status
= gBS
->SetTimer (
643 TICKS_PER_MS
* IP6_TIMER_INTERVAL_IN_MS
645 if (EFI_ERROR (Status
)) {
646 goto UNINSTALL_PROTOCOL
;
650 // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds.
652 Status
= gBS
->SetTimer (
655 TICKS_PER_MS
* IP6_ONE_SECOND_IN_MS
657 if (EFI_ERROR (Status
)) {
658 goto UNINSTALL_PROTOCOL
;
662 // Initialize the IP6 ID
664 mIp6Id
= NET_RANDOM (NetRandomInitSeed ());
669 gBS
->UninstallMultipleProtocolInterfaces (
671 &gEfiIp6ServiceBindingProtocolGuid
,
672 &IpSb
->ServiceBinding
,
673 &gEfiIp6ConfigProtocolGuid
,
679 Ip6CleanService (IpSb
);
685 Callback function which provided by user to remove one node in NetDestroyLinkList process.
687 @param[in] Entry The entry to be removed.
688 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
690 @retval EFI_SUCCESS The entry has been removed successfully.
691 @retval Others Fail to remove the entry.
696 Ip6DestroyChildEntryInHandleBuffer (
697 IN LIST_ENTRY
*Entry
,
701 IP6_PROTOCOL
*IpInstance
;
702 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
703 UINTN NumberOfChildren
;
704 EFI_HANDLE
*ChildHandleBuffer
;
706 if (Entry
== NULL
|| Context
== NULL
) {
707 return EFI_INVALID_PARAMETER
;
710 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_PROTOCOL
, Link
, IP6_PROTOCOL_SIGNATURE
);
711 ServiceBinding
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
712 NumberOfChildren
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
713 ChildHandleBuffer
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
715 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
719 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
723 Stop this driver on ControllerHandle.
725 @param[in] This Protocol instance pointer.
726 @param[in] ControllerHandle Handle of device to stop driver on.
727 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
728 of children is zero, stop the entire bus driver.
729 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
730 if NumberOfChildren is 0.
732 @retval EFI_SUCCESS The device was stopped.
733 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
738 Ip6DriverBindingStop (
739 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
740 IN EFI_HANDLE ControllerHandle
,
741 IN UINTN NumberOfChildren
,
742 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
745 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
747 EFI_HANDLE NicHandle
;
752 IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
755 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
756 if (NicHandle
== NULL
) {
757 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
758 if (NicHandle
!= NULL
) {
765 Status
= gBS
->OpenProtocol (
767 &gEfiIp6ServiceBindingProtocolGuid
,
768 (VOID
**) &ServiceBinding
,
769 This
->DriverBindingHandle
,
771 EFI_OPEN_PROTOCOL_GET_PROTOCOL
773 if (EFI_ERROR (Status
)) {
774 return EFI_DEVICE_ERROR
;
777 IpSb
= IP6_SERVICE_FROM_PROTOCOL (ServiceBinding
);
780 Status
= Ip6ConfigDestroyDhcp6 (&IpSb
->Ip6ConfigInstance
);
781 gBS
->CloseEvent (IpSb
->Ip6ConfigInstance
.Dhcp6Event
);
782 IpSb
->Ip6ConfigInstance
.Dhcp6Event
= NULL
;
783 } else if (NumberOfChildren
!= 0) {
785 // NumberOfChildren is not zero, destroy the IP6 children instances in ChildHandleBuffer.
787 List
= &IpSb
->Children
;
788 Context
.ServiceBinding
= ServiceBinding
;
789 Context
.NumberOfChildren
= NumberOfChildren
;
790 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
791 Status
= NetDestroyLinkList (
793 Ip6DestroyChildEntryInHandleBuffer
,
797 } else if (IsListEmpty (&IpSb
->Children
)) {
799 Status
= Ip6CleanService (IpSb
);
800 if (EFI_ERROR (Status
)) {
805 Status
= gBS
->UninstallMultipleProtocolInterfaces (
807 &gEfiIp6ServiceBindingProtocolGuid
,
809 &gEfiIp6ConfigProtocolGuid
,
810 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
813 ASSERT_EFI_ERROR (Status
);
815 Status
= EFI_SUCCESS
;
824 Creates a child handle with a set of I/O services.
826 @param[in] This Protocol instance pointer.
827 @param[in] ChildHandle Pointer to the handle of the child to create. If
828 it is NULL, then a new handle is created. If it
829 is not NULL, then the I/O services are added to
830 the existing child handle.
832 @retval EFI_SUCCES The child handle was created with the I/O services.
833 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
835 @retval other The child handle was not created.
840 Ip6ServiceBindingCreateChild (
841 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
842 IN EFI_HANDLE
*ChildHandle
846 IP6_PROTOCOL
*IpInstance
;
851 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
852 return EFI_INVALID_PARAMETER
;
855 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
857 if (IpSb
->LinkLocalDadFail
) {
858 return EFI_DEVICE_ERROR
;
861 IpInstance
= AllocatePool (sizeof (IP6_PROTOCOL
));
863 if (IpInstance
== NULL
) {
864 return EFI_OUT_OF_RESOURCES
;
867 Ip6InitProtocol (IpSb
, IpInstance
);
870 // Install Ip6 onto ChildHandle
872 Status
= gBS
->InstallMultipleProtocolInterfaces (
874 &gEfiIp6ProtocolGuid
,
875 &IpInstance
->Ip6Proto
,
878 if (EFI_ERROR (Status
)) {
882 IpInstance
->Handle
= *ChildHandle
;
885 // Open the Managed Network protocol BY_CHILD.
887 Status
= gBS
->OpenProtocol (
888 IpSb
->MnpChildHandle
,
889 &gEfiManagedNetworkProtocolGuid
,
891 gIp6DriverBinding
.DriverBindingHandle
,
893 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
895 if (EFI_ERROR (Status
)) {
896 gBS
->UninstallMultipleProtocolInterfaces (
898 &gEfiIp6ProtocolGuid
,
899 &IpInstance
->Ip6Proto
,
907 // Insert it into the service binding instance.
909 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
911 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
914 gBS
->RestoreTPL (OldTpl
);
918 if (EFI_ERROR (Status
)) {
920 Ip6CleanProtocol (IpInstance
);
922 FreePool (IpInstance
);
929 Destroys a child handle with a set of I/O services.
931 @param[in] This Protocol instance pointer.
932 @param[in] ChildHandle Handle of the child to destroy.
934 @retval EFI_SUCCES The I/O services were removed from the child
936 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
937 that are being removed.
938 @retval EFI_INVALID_PARAMETER Child handle is NULL.
939 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
940 its I/O services are being used.
941 @retval other The child handle was not destroyed.
946 Ip6ServiceBindingDestroyChild (
947 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
948 IN EFI_HANDLE ChildHandle
953 IP6_PROTOCOL
*IpInstance
;
954 EFI_IP6_PROTOCOL
*Ip6
;
957 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
958 return EFI_INVALID_PARAMETER
;
962 // Retrieve the private context data structures
964 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
966 Status
= gBS
->OpenProtocol (
968 &gEfiIp6ProtocolGuid
,
970 gIp6DriverBinding
.DriverBindingHandle
,
972 EFI_OPEN_PROTOCOL_GET_PROTOCOL
975 if (EFI_ERROR (Status
)) {
976 return EFI_UNSUPPORTED
;
979 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (Ip6
);
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 // Ip6DriverBindingStop 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 gIp6DriverBinding
.DriverBindingHandle
,
1011 // Uninstall the IP6 protocol first. Many thing happens during
1013 // 1. The consumer of the IP6 protocol will be stopped if it
1014 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
1015 // stopped, IP driver's stop function will be called, and uninstall
1016 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
1017 // makes it possible to create the network stack bottom up, and
1018 // stop it top down.
1019 // 2. the upper layer will recycle the received packet. The recycle
1020 // event's TPL is higher than this function. The recycle events
1021 // will be called back before preceeding. If any packets not recycled,
1022 // that means there is a resource leak.
1024 gBS
->RestoreTPL (OldTpl
);
1025 Status
= gBS
->UninstallProtocolInterface (
1027 &gEfiIp6ProtocolGuid
,
1028 &IpInstance
->Ip6Proto
1030 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1031 if (EFI_ERROR (Status
)) {
1035 Status
= Ip6CleanProtocol (IpInstance
);
1036 if (EFI_ERROR (Status
)) {
1037 gBS
->InstallMultipleProtocolInterfaces (
1039 &gEfiIp6ProtocolGuid
,
1047 RemoveEntryList (&IpInstance
->Link
);
1048 ASSERT (IpSb
->NumChildren
> 0);
1049 IpSb
->NumChildren
--;
1051 gBS
->RestoreTPL (OldTpl
);
1053 FreePool (IpInstance
);
1057 gBS
->RestoreTPL (OldTpl
);