2 The driver binding and service binding protocol for IP6 driver.
4 Copyright (c) 2009 - 2016, 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 (
45 // Close the event so it does not get called again.
47 gBS
->CloseEvent (Event
);
49 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_SUCCES 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 ControlerHandle
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
)) {
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 (EFI_ERROR(Status
) && Status
!= EFI_NOT_READY
) {
590 // If there is any default gateway address, set it.
592 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeGateway
];
593 if (DataItem
->Data
.Ptr
!= NULL
) {
594 Status
= Ip6Cfg
->SetData (
596 Ip6ConfigDataTypeGateway
,
600 if (EFI_ERROR(Status
)) {
606 // ready to go: start the receiving and timer
608 Status
= Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
609 if (EFI_ERROR (Status
)) {
614 // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds.
616 Status
= gBS
->SetTimer (
619 TICKS_PER_MS
* IP6_TIMER_INTERVAL_IN_MS
621 if (EFI_ERROR (Status
)) {
626 // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds.
628 Status
= gBS
->SetTimer (
631 TICKS_PER_MS
* IP6_ONE_SECOND_IN_MS
633 if (EFI_ERROR (Status
)) {
638 // Initialize the IP6 ID
640 mIp6Id
= NET_RANDOM (NetRandomInitSeed ());
645 Ip6CleanService (IpSb
);
651 Callback function which provided by user to remove one node in NetDestroyLinkList process.
653 @param[in] Entry The entry to be removed.
654 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
656 @retval EFI_SUCCESS The entry has been removed successfully.
657 @retval Others Fail to remove the entry.
662 Ip6DestroyChildEntryInHandleBuffer (
663 IN LIST_ENTRY
*Entry
,
667 IP6_PROTOCOL
*IpInstance
;
668 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
669 UINTN NumberOfChildren
;
670 EFI_HANDLE
*ChildHandleBuffer
;
672 if (Entry
== NULL
|| Context
== NULL
) {
673 return EFI_INVALID_PARAMETER
;
676 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_PROTOCOL
, Link
, IP6_PROTOCOL_SIGNATURE
);
677 ServiceBinding
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
678 NumberOfChildren
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
679 ChildHandleBuffer
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
681 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
685 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
689 Stop this driver on ControllerHandle.
691 @param[in] This Protocol instance pointer.
692 @param[in] ControllerHandle Handle of device to stop driver on.
693 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
694 of children is zero, stop the entire bus driver.
695 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
696 if NumberOfChildren is 0.
698 @retval EFI_SUCCESS The device was stopped.
699 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
704 Ip6DriverBindingStop (
705 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
706 IN EFI_HANDLE ControllerHandle
,
707 IN UINTN NumberOfChildren
,
708 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
711 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
713 EFI_HANDLE NicHandle
;
718 IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
721 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
722 if (NicHandle
== NULL
) {
723 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
724 if (NicHandle
!= NULL
) {
731 Status
= gBS
->OpenProtocol (
733 &gEfiIp6ServiceBindingProtocolGuid
,
734 (VOID
**) &ServiceBinding
,
735 This
->DriverBindingHandle
,
737 EFI_OPEN_PROTOCOL_GET_PROTOCOL
739 if (EFI_ERROR (Status
)) {
740 return EFI_DEVICE_ERROR
;
743 IpSb
= IP6_SERVICE_FROM_PROTOCOL (ServiceBinding
);
746 Status
= Ip6ConfigDestroyDhcp6 (&IpSb
->Ip6ConfigInstance
);
747 gBS
->CloseEvent (IpSb
->Ip6ConfigInstance
.Dhcp6Event
);
748 IpSb
->Ip6ConfigInstance
.Dhcp6Event
= NULL
;
749 } else if (NumberOfChildren
!= 0) {
751 // NumberOfChildren is not zero, destroy the IP6 children instances in ChildHandleBuffer.
753 List
= &IpSb
->Children
;
754 Context
.ServiceBinding
= ServiceBinding
;
755 Context
.NumberOfChildren
= NumberOfChildren
;
756 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
757 Status
= NetDestroyLinkList (
759 Ip6DestroyChildEntryInHandleBuffer
,
763 } else if (IsListEmpty (&IpSb
->Children
)) {
765 Status
= Ip6CleanService (IpSb
);
766 if (EFI_ERROR (Status
)) {
771 Status
= gBS
->UninstallMultipleProtocolInterfaces (
773 &gEfiIp6ServiceBindingProtocolGuid
,
775 &gEfiIp6ConfigProtocolGuid
,
776 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
779 ASSERT_EFI_ERROR (Status
);
781 Status
= EFI_SUCCESS
;
790 Creates a child handle with a set of I/O services.
792 @param[in] This Protocol instance pointer.
793 @param[in] ChildHandle Pointer to the handle of the child to create. If
794 it is NULL, then a new handle is created. If it
795 is not NULL, then the I/O services are added to
796 the existing child handle.
798 @retval EFI_SUCCES The child handle was created with the I/O services.
799 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
801 @retval other The child handle was not created.
806 Ip6ServiceBindingCreateChild (
807 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
808 IN EFI_HANDLE
*ChildHandle
812 IP6_PROTOCOL
*IpInstance
;
817 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
818 return EFI_INVALID_PARAMETER
;
821 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
823 if (IpSb
->LinkLocalDadFail
) {
824 return EFI_DEVICE_ERROR
;
827 IpInstance
= AllocatePool (sizeof (IP6_PROTOCOL
));
829 if (IpInstance
== NULL
) {
830 return EFI_OUT_OF_RESOURCES
;
833 Ip6InitProtocol (IpSb
, IpInstance
);
836 // Install Ip6 onto ChildHandle
838 Status
= gBS
->InstallMultipleProtocolInterfaces (
840 &gEfiIp6ProtocolGuid
,
841 &IpInstance
->Ip6Proto
,
844 if (EFI_ERROR (Status
)) {
848 IpInstance
->Handle
= *ChildHandle
;
851 // Open the Managed Network protocol BY_CHILD.
853 Status
= gBS
->OpenProtocol (
854 IpSb
->MnpChildHandle
,
855 &gEfiManagedNetworkProtocolGuid
,
857 gIp6DriverBinding
.DriverBindingHandle
,
859 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
861 if (EFI_ERROR (Status
)) {
862 gBS
->UninstallMultipleProtocolInterfaces (
864 &gEfiIp6ProtocolGuid
,
865 &IpInstance
->Ip6Proto
,
873 // Insert it into the service binding instance.
875 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
877 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
880 gBS
->RestoreTPL (OldTpl
);
884 if (EFI_ERROR (Status
)) {
886 Ip6CleanProtocol (IpInstance
);
888 FreePool (IpInstance
);
895 Destroys a child handle with a set of I/O services.
897 @param[in] This Protocol instance pointer.
898 @param[in] ChildHandle Handle of the child to destroy.
900 @retval EFI_SUCCES The I/O services were removed from the child
902 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
903 that are being removed.
904 @retval EFI_INVALID_PARAMETER Child handle is NULL.
905 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
906 its I/O services are being used.
907 @retval other The child handle was not destroyed.
912 Ip6ServiceBindingDestroyChild (
913 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
914 IN EFI_HANDLE ChildHandle
919 IP6_PROTOCOL
*IpInstance
;
920 EFI_IP6_PROTOCOL
*Ip6
;
923 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
924 return EFI_INVALID_PARAMETER
;
928 // Retrieve the private context data structures
930 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
932 Status
= gBS
->OpenProtocol (
934 &gEfiIp6ProtocolGuid
,
936 gIp6DriverBinding
.DriverBindingHandle
,
938 EFI_OPEN_PROTOCOL_GET_PROTOCOL
941 if (EFI_ERROR (Status
)) {
942 return EFI_UNSUPPORTED
;
945 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (Ip6
);
947 if (IpInstance
->Service
!= IpSb
) {
948 return EFI_INVALID_PARAMETER
;
951 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
954 // A child can be destroyed more than once. For example,
955 // Ip6DriverBindingStop will destroy all of its children.
956 // when UDP driver is being stopped, it will destroy all
957 // the IP child it opens.
959 if (IpInstance
->InDestroy
) {
960 gBS
->RestoreTPL (OldTpl
);
964 IpInstance
->InDestroy
= TRUE
;
967 // Close the Managed Network protocol.
970 IpSb
->MnpChildHandle
,
971 &gEfiManagedNetworkProtocolGuid
,
972 gIp6DriverBinding
.DriverBindingHandle
,
977 // Uninstall the IP6 protocol first. Many thing happens during
979 // 1. The consumer of the IP6 protocol will be stopped if it
980 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
981 // stopped, IP driver's stop function will be called, and uninstall
982 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
983 // makes it possible to create the network stack bottom up, and
985 // 2. the upper layer will recycle the received packet. The recycle
986 // event's TPL is higher than this function. The recycle events
987 // will be called back before preceeding. If any packets not recycled,
988 // that means there is a resource leak.
990 gBS
->RestoreTPL (OldTpl
);
991 Status
= gBS
->UninstallProtocolInterface (
993 &gEfiIp6ProtocolGuid
,
994 &IpInstance
->Ip6Proto
996 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
997 if (EFI_ERROR (Status
)) {
1001 Status
= Ip6CleanProtocol (IpInstance
);
1002 if (EFI_ERROR (Status
)) {
1003 gBS
->InstallMultipleProtocolInterfaces (
1005 &gEfiIp6ProtocolGuid
,
1013 RemoveEntryList (&IpInstance
->Link
);
1014 ASSERT (IpSb
->NumChildren
> 0);
1015 IpSb
->NumChildren
--;
1017 gBS
->RestoreTPL (OldTpl
);
1019 FreePool (IpInstance
);
1023 gBS
->RestoreTPL (OldTpl
);