2 The driver binding and service binding protocol for IP6 driver.
4 Copyright (c) 2009 - 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 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
)) {
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 (EFI_ERROR(Status
) && Status
!= EFI_NOT_READY
) {
596 // If there is any default gateway address, set it.
598 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeGateway
];
599 if (DataItem
->Data
.Ptr
!= NULL
) {
600 Status
= Ip6Cfg
->SetData (
602 Ip6ConfigDataTypeGateway
,
606 if (EFI_ERROR(Status
)) {
612 // ready to go: start the receiving and timer
614 Status
= Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
615 if (EFI_ERROR (Status
)) {
620 // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds.
622 Status
= gBS
->SetTimer (
625 TICKS_PER_MS
* IP6_TIMER_INTERVAL_IN_MS
627 if (EFI_ERROR (Status
)) {
632 // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds.
634 Status
= gBS
->SetTimer (
637 TICKS_PER_MS
* IP6_ONE_SECOND_IN_MS
639 if (EFI_ERROR (Status
)) {
644 // Initialize the IP6 ID
646 mIp6Id
= NET_RANDOM (NetRandomInitSeed ());
651 Ip6CleanService (IpSb
);
657 Callback function which provided by user to remove one node in NetDestroyLinkList process.
659 @param[in] Entry The entry to be removed.
660 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
662 @retval EFI_SUCCESS The entry has been removed successfully.
663 @retval Others Fail to remove the entry.
668 Ip6DestroyChildEntryInHandleBuffer (
669 IN LIST_ENTRY
*Entry
,
673 IP6_PROTOCOL
*IpInstance
;
674 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
675 UINTN NumberOfChildren
;
676 EFI_HANDLE
*ChildHandleBuffer
;
678 if (Entry
== NULL
|| Context
== NULL
) {
679 return EFI_INVALID_PARAMETER
;
682 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_PROTOCOL
, Link
, IP6_PROTOCOL_SIGNATURE
);
683 ServiceBinding
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
684 NumberOfChildren
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
685 ChildHandleBuffer
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
687 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
691 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
695 Stop this driver on ControllerHandle.
697 @param[in] This Protocol instance pointer.
698 @param[in] ControllerHandle Handle of device to stop driver on.
699 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
700 of children is zero, stop the entire bus driver.
701 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
702 if NumberOfChildren is 0.
704 @retval EFI_SUCCESS The device was stopped.
705 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
710 Ip6DriverBindingStop (
711 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
712 IN EFI_HANDLE ControllerHandle
,
713 IN UINTN NumberOfChildren
,
714 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
717 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
719 EFI_HANDLE NicHandle
;
724 IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
727 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
728 if (NicHandle
== NULL
) {
729 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
730 if (NicHandle
!= NULL
) {
737 Status
= gBS
->OpenProtocol (
739 &gEfiIp6ServiceBindingProtocolGuid
,
740 (VOID
**) &ServiceBinding
,
741 This
->DriverBindingHandle
,
743 EFI_OPEN_PROTOCOL_GET_PROTOCOL
745 if (EFI_ERROR (Status
)) {
746 return EFI_DEVICE_ERROR
;
749 IpSb
= IP6_SERVICE_FROM_PROTOCOL (ServiceBinding
);
752 Status
= Ip6ConfigDestroyDhcp6 (&IpSb
->Ip6ConfigInstance
);
753 gBS
->CloseEvent (IpSb
->Ip6ConfigInstance
.Dhcp6Event
);
754 IpSb
->Ip6ConfigInstance
.Dhcp6Event
= NULL
;
755 } else if (NumberOfChildren
!= 0) {
757 // NumberOfChildren is not zero, destroy the IP6 children instances in ChildHandleBuffer.
759 List
= &IpSb
->Children
;
760 Context
.ServiceBinding
= ServiceBinding
;
761 Context
.NumberOfChildren
= NumberOfChildren
;
762 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
763 Status
= NetDestroyLinkList (
765 Ip6DestroyChildEntryInHandleBuffer
,
769 } else if (IsListEmpty (&IpSb
->Children
)) {
771 Status
= Ip6CleanService (IpSb
);
772 if (EFI_ERROR (Status
)) {
777 Status
= gBS
->UninstallMultipleProtocolInterfaces (
779 &gEfiIp6ServiceBindingProtocolGuid
,
781 &gEfiIp6ConfigProtocolGuid
,
782 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
785 ASSERT_EFI_ERROR (Status
);
787 Status
= EFI_SUCCESS
;
796 Creates a child handle with a set of I/O services.
798 @param[in] This Protocol instance pointer.
799 @param[in] ChildHandle Pointer to the handle of the child to create. If
800 it is NULL, then a new handle is created. If it
801 is not NULL, then the I/O services are added to
802 the existing child handle.
804 @retval EFI_SUCCES The child handle was created with the I/O services.
805 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
807 @retval other The child handle was not created.
812 Ip6ServiceBindingCreateChild (
813 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
814 IN EFI_HANDLE
*ChildHandle
818 IP6_PROTOCOL
*IpInstance
;
823 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
824 return EFI_INVALID_PARAMETER
;
827 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
829 if (IpSb
->LinkLocalDadFail
) {
830 return EFI_DEVICE_ERROR
;
833 IpInstance
= AllocatePool (sizeof (IP6_PROTOCOL
));
835 if (IpInstance
== NULL
) {
836 return EFI_OUT_OF_RESOURCES
;
839 Ip6InitProtocol (IpSb
, IpInstance
);
842 // Install Ip6 onto ChildHandle
844 Status
= gBS
->InstallMultipleProtocolInterfaces (
846 &gEfiIp6ProtocolGuid
,
847 &IpInstance
->Ip6Proto
,
850 if (EFI_ERROR (Status
)) {
854 IpInstance
->Handle
= *ChildHandle
;
857 // Open the Managed Network protocol BY_CHILD.
859 Status
= gBS
->OpenProtocol (
860 IpSb
->MnpChildHandle
,
861 &gEfiManagedNetworkProtocolGuid
,
863 gIp6DriverBinding
.DriverBindingHandle
,
865 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
867 if (EFI_ERROR (Status
)) {
868 gBS
->UninstallMultipleProtocolInterfaces (
870 &gEfiIp6ProtocolGuid
,
871 &IpInstance
->Ip6Proto
,
879 // Insert it into the service binding instance.
881 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
883 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
886 gBS
->RestoreTPL (OldTpl
);
890 if (EFI_ERROR (Status
)) {
892 Ip6CleanProtocol (IpInstance
);
894 FreePool (IpInstance
);
901 Destroys a child handle with a set of I/O services.
903 @param[in] This Protocol instance pointer.
904 @param[in] ChildHandle Handle of the child to destroy.
906 @retval EFI_SUCCES The I/O services were removed from the child
908 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
909 that are being removed.
910 @retval EFI_INVALID_PARAMETER Child handle is NULL.
911 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
912 its I/O services are being used.
913 @retval other The child handle was not destroyed.
918 Ip6ServiceBindingDestroyChild (
919 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
920 IN EFI_HANDLE ChildHandle
925 IP6_PROTOCOL
*IpInstance
;
926 EFI_IP6_PROTOCOL
*Ip6
;
929 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
930 return EFI_INVALID_PARAMETER
;
934 // Retrieve the private context data structures
936 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
938 Status
= gBS
->OpenProtocol (
940 &gEfiIp6ProtocolGuid
,
942 gIp6DriverBinding
.DriverBindingHandle
,
944 EFI_OPEN_PROTOCOL_GET_PROTOCOL
947 if (EFI_ERROR (Status
)) {
948 return EFI_UNSUPPORTED
;
951 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (Ip6
);
953 if (IpInstance
->Service
!= IpSb
) {
954 return EFI_INVALID_PARAMETER
;
957 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
960 // A child can be destroyed more than once. For example,
961 // Ip6DriverBindingStop will destroy all of its children.
962 // when UDP driver is being stopped, it will destroy all
963 // the IP child it opens.
965 if (IpInstance
->InDestroy
) {
966 gBS
->RestoreTPL (OldTpl
);
970 IpInstance
->InDestroy
= TRUE
;
973 // Close the Managed Network protocol.
976 IpSb
->MnpChildHandle
,
977 &gEfiManagedNetworkProtocolGuid
,
978 gIp6DriverBinding
.DriverBindingHandle
,
983 // Uninstall the IP6 protocol first. Many thing happens during
985 // 1. The consumer of the IP6 protocol will be stopped if it
986 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
987 // stopped, IP driver's stop function will be called, and uninstall
988 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
989 // makes it possible to create the network stack bottom up, and
991 // 2. the upper layer will recycle the received packet. The recycle
992 // event's TPL is higher than this function. The recycle events
993 // will be called back before preceeding. If any packets not recycled,
994 // that means there is a resource leak.
996 gBS
->RestoreTPL (OldTpl
);
997 Status
= gBS
->UninstallProtocolInterface (
999 &gEfiIp6ProtocolGuid
,
1000 &IpInstance
->Ip6Proto
1002 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1003 if (EFI_ERROR (Status
)) {
1007 Status
= Ip6CleanProtocol (IpInstance
);
1008 if (EFI_ERROR (Status
)) {
1009 gBS
->InstallMultipleProtocolInterfaces (
1011 &gEfiIp6ProtocolGuid
,
1019 RemoveEntryList (&IpInstance
->Link
);
1020 ASSERT (IpSb
->NumChildren
> 0);
1021 IpSb
->NumChildren
--;
1023 gBS
->RestoreTPL (OldTpl
);
1025 FreePool (IpInstance
);
1029 gBS
->RestoreTPL (OldTpl
);