2 The driver binding and service binding protocol for IP6 driver.
4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_DRIVER_BINDING_PROTOCOL gIp6DriverBinding
= {
19 Ip6DriverBindingSupported
,
20 Ip6DriverBindingStart
,
28 This is the declaration of an EFI image entry point. This entry point is
29 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
30 both device drivers and bus drivers.
32 The entry point for IP6 driver which installs the driver
33 binding and component name protocol on its image.
35 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
36 @param[in] SystemTable A pointer to the EFI System Table.
38 @retval EFI_SUCCESS The operation completed successfully.
39 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
45 IN EFI_HANDLE ImageHandle
,
46 IN EFI_SYSTEM_TABLE
*SystemTable
49 return EfiLibInstallDriverBindingComponentName2 (
60 Test to see if this driver supports ControllerHandle.
62 @param[in] This Protocol instance pointer.
63 @param[in] ControllerHandle Handle of device to test.
64 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
67 @retval EFI_SUCCESS This driver supports this device.
68 @retval EFI_ALREADY_STARTED This driver is already running on this device.
69 @retval other This driver does not support this device.
74 Ip6DriverBindingSupported (
75 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
76 IN EFI_HANDLE ControllerHandle
,
77 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
81 // Test for the MNP service binding Protocol
83 return gBS
->OpenProtocol (
85 &gEfiManagedNetworkServiceBindingProtocolGuid
,
87 This
->DriverBindingHandle
,
89 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
94 Clean up an IP6 service binding instance. It releases all
95 the resource allocated by the instance. The instance may be
96 partly initialized, or partly destroyed. If a resource is
97 destroyed, it is marked as that in case the destroy failed and
98 being called again later.
100 @param[in] IpSb The IP6 service binding instance to clean up.
102 @retval EFI_SUCCESS The resource used by the instance are cleaned up.
103 @retval Others Failed to clean up some of the resources.
112 EFI_IPv6_ADDRESS AllNodes
;
113 IP6_NEIGHBOR_ENTRY
*NeighborCache
;
115 Ip6ConfigCleanInstance (&IpSb
->Ip6ConfigInstance
);
118 // Leave link-scope all-nodes multicast address (FF02::1)
120 Ip6SetToAllNodeMulticast (FALSE
, IP6_LINK_LOCAL_SCOPE
, &AllNodes
);
122 Status
= Ip6LeaveGroup (IpSb
, &AllNodes
);
123 if (EFI_ERROR (Status
)) {
127 if (IpSb
->DefaultInterface
!= NULL
) {
128 Ip6CleanInterface (IpSb
->DefaultInterface
, NULL
);
129 IpSb
->DefaultInterface
= NULL
;
132 Ip6CleanDefaultRouterList (IpSb
);
134 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
135 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
137 if (IpSb
->RouteTable
!= NULL
) {
138 Ip6CleanRouteTable (IpSb
->RouteTable
);
139 IpSb
->RouteTable
= NULL
;
142 if (IpSb
->InterfaceId
!= NULL
) {
143 FreePool (IpSb
->InterfaceId
);
146 IpSb
->InterfaceId
= NULL
;
148 Ip6CleanAssembleTable (&IpSb
->Assemble
);
150 if (IpSb
->MnpChildHandle
!= NULL
) {
151 if (IpSb
->Mnp
!= NULL
) {
152 IpSb
->Mnp
->Cancel (IpSb
->Mnp
, NULL
);
153 IpSb
->Mnp
->Configure (IpSb
->Mnp
, NULL
);
155 IpSb
->MnpChildHandle
,
156 &gEfiManagedNetworkProtocolGuid
,
164 NetLibDestroyServiceChild (
167 &gEfiManagedNetworkServiceBindingProtocolGuid
,
171 IpSb
->MnpChildHandle
= NULL
;
174 if (IpSb
->RecvRequest
.MnpToken
.Event
!= NULL
) {
175 gBS
->CloseEvent (IpSb
->RecvRequest
.MnpToken
.Event
);
178 if (IpSb
->Timer
!= NULL
) {
179 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
180 gBS
->CloseEvent (IpSb
->Timer
);
185 if (IpSb
->FasterTimer
!= NULL
) {
186 gBS
->SetTimer (IpSb
->FasterTimer
, TimerCancel
, 0);
187 gBS
->CloseEvent (IpSb
->FasterTimer
);
189 IpSb
->FasterTimer
= NULL
;
192 // Free the Neighbor Discovery resources
194 while (!IsListEmpty (&IpSb
->NeighborTable
)) {
195 NeighborCache
= NET_LIST_HEAD (&IpSb
->NeighborTable
, IP6_NEIGHBOR_ENTRY
, Link
);
196 Ip6FreeNeighborEntry (IpSb
, NeighborCache
, FALSE
, TRUE
, EFI_SUCCESS
, NULL
, NULL
);
203 Create a new IP6 driver service binding protocol.
205 @param[in] Controller The controller that has MNP service binding
207 @param[in] ImageHandle The IP6 driver's image handle.
208 @param[out] Service The variable to receive the newly created IP6
211 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
212 @retval EFI_SUCCESS A new IP6 service binding private is created.
217 IN EFI_HANDLE Controller
,
218 IN EFI_HANDLE ImageHandle
,
219 OUT IP6_SERVICE
**Service
224 EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*MnpToken
;
225 EFI_MANAGED_NETWORK_CONFIG_DATA
*Config
;
226 IP6_CONFIG_DATA_ITEM
*DataItem
;
228 ASSERT (Service
!= NULL
);
233 // allocate a service private data then initialize all the filed to
234 // empty resources, so if any thing goes wrong when allocating
235 // resources, Ip6CleanService can be called to clean it up.
237 IpSb
= AllocateZeroPool (sizeof (IP6_SERVICE
));
240 return EFI_OUT_OF_RESOURCES
;
243 IpSb
->Signature
= IP6_SERVICE_SIGNATURE
;
244 IpSb
->ServiceBinding
.CreateChild
= Ip6ServiceBindingCreateChild
;
245 IpSb
->ServiceBinding
.DestroyChild
= Ip6ServiceBindingDestroyChild
;
246 IpSb
->State
= IP6_SERVICE_UNSTARTED
;
247 IpSb
->InDestroy
= FALSE
;
249 IpSb
->NumChildren
= 0;
250 InitializeListHead (&IpSb
->Children
);
252 InitializeListHead (&IpSb
->Interfaces
);
253 IpSb
->DefaultInterface
= NULL
;
254 IpSb
->RouteTable
= NULL
;
256 IpSb
->RecvRequest
.Signature
= IP6_LINK_RX_SIGNATURE
;
257 IpSb
->RecvRequest
.CallBack
= NULL
;
258 IpSb
->RecvRequest
.Context
= NULL
;
259 MnpToken
= &IpSb
->RecvRequest
.MnpToken
;
260 MnpToken
->Event
= NULL
;
261 MnpToken
->Status
= EFI_NOT_READY
;
262 MnpToken
->Packet
.RxData
= NULL
;
264 Ip6CreateAssembleTable (&IpSb
->Assemble
);
266 IpSb
->MldCtrl
.Mldv1QuerySeen
= 0;
267 InitializeListHead (&IpSb
->MldCtrl
.Groups
);
269 ZeroMem (&IpSb
->LinkLocalAddr
, sizeof (EFI_IPv6_ADDRESS
));
270 IpSb
->LinkLocalOk
= FALSE
;
271 IpSb
->LinkLocalDadFail
= FALSE
;
272 IpSb
->Dhcp6NeedStart
= FALSE
;
273 IpSb
->Dhcp6NeedInfoRequest
= FALSE
;
275 IpSb
->CurHopLimit
= IP6_HOP_LIMIT
;
276 IpSb
->LinkMTU
= IP6_MIN_LINK_MTU
;
277 IpSb
->BaseReachableTime
= IP6_REACHABLE_TIME
;
278 Ip6UpdateReachableTime (IpSb
);
280 // RFC4861 RETRANS_TIMER: 1,000 milliseconds
282 IpSb
->RetransTimer
= IP6_RETRANS_TIMER
;
284 IpSb
->RoundRobin
= 0;
286 InitializeListHead (&IpSb
->NeighborTable
);
287 InitializeListHead (&IpSb
->DefaultRouterList
);
288 InitializeListHead (&IpSb
->OnlinkPrefix
);
289 InitializeListHead (&IpSb
->AutonomousPrefix
);
291 IpSb
->InterfaceIdLen
= IP6_IF_ID_LEN
;
292 IpSb
->InterfaceId
= NULL
;
294 IpSb
->RouterAdvertiseReceived
= FALSE
;
295 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
298 IpSb
->Image
= ImageHandle
;
299 IpSb
->Controller
= Controller
;
301 IpSb
->MnpChildHandle
= NULL
;
304 Config
= &IpSb
->MnpConfigData
;
305 Config
->ReceivedQueueTimeoutValue
= 0;
306 Config
->TransmitQueueTimeoutValue
= 0;
307 Config
->ProtocolTypeFilter
= IP6_ETHER_PROTO
;
308 Config
->EnableUnicastReceive
= TRUE
;
309 Config
->EnableMulticastReceive
= TRUE
;
310 Config
->EnableBroadcastReceive
= TRUE
;
311 Config
->EnablePromiscuousReceive
= FALSE
;
312 Config
->FlushQueuesOnReset
= TRUE
;
313 Config
->EnableReceiveTimestamps
= FALSE
;
314 Config
->DisableBackgroundPolling
= FALSE
;
316 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
319 IpSb
->FasterTimer
= NULL
;
321 ZeroMem (&IpSb
->Ip6ConfigInstance
, sizeof (IP6_CONFIG_INSTANCE
));
323 IpSb
->MacString
= NULL
;
326 // Create various resources. First create the route table, timer
327 // event, MNP token event and MNP child.
330 IpSb
->RouteTable
= Ip6CreateRouteTable ();
331 if (IpSb
->RouteTable
== NULL
) {
332 Status
= EFI_OUT_OF_RESOURCES
;
336 Status
= gBS
->CreateEvent (
337 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
343 if (EFI_ERROR (Status
)) {
347 Status
= gBS
->CreateEvent (
348 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
350 Ip6NdFasterTimerTicking
,
354 if (EFI_ERROR (Status
)) {
358 Status
= NetLibCreateServiceChild (
361 &gEfiManagedNetworkServiceBindingProtocolGuid
,
362 &IpSb
->MnpChildHandle
364 if (EFI_ERROR (Status
)) {
368 Status
= gBS
->OpenProtocol (
369 IpSb
->MnpChildHandle
,
370 &gEfiManagedNetworkProtocolGuid
,
371 (VOID
**) (&IpSb
->Mnp
),
374 EFI_OPEN_PROTOCOL_BY_DRIVER
376 if (EFI_ERROR (Status
)) {
380 Status
= Ip6ServiceConfigMnp (IpSb
, TRUE
);
381 if (EFI_ERROR (Status
)) {
385 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
386 if (EFI_ERROR (Status
)) {
390 IpSb
->MaxPacketSize
= IP6_MIN_LINK_MTU
- sizeof (EFI_IP6_HEADER
);
391 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
393 // This is a VLAN device, reduce MTU by VLAN tag length
395 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
397 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
400 // Currently only ETHERNET is supported in IPv6 stack, since
401 // link local address requires an IEEE 802 48-bit MACs for
402 // EUI-64 format interface identifier mapping.
404 if (IpSb
->SnpMode
.IfType
!= NET_IFTYPE_ETHERNET
) {
405 Status
= EFI_UNSUPPORTED
;
409 Status
= Ip6InitMld (IpSb
);
410 if (EFI_ERROR (Status
)) {
415 // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds.
417 Status
= gBS
->SetTimer (IpSb
->FasterTimer
, TimerPeriodic
, TICKS_PER_MS
* IP6_TIMER_INTERVAL_IN_MS
);
418 if (EFI_ERROR (Status
)) {
423 // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds.
425 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_MS
* IP6_ONE_SECOND_IN_MS
);
426 if (EFI_ERROR (Status
)) {
431 Status
= gBS
->CreateEvent (
438 if (EFI_ERROR (Status
)) {
442 Status
= Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
443 if (EFI_ERROR (Status
)) {
447 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
448 if (EFI_ERROR (Status
)) {
452 Status
= Ip6ConfigInitInstance (&IpSb
->Ip6ConfigInstance
);
453 if (EFI_ERROR (Status
)) {
457 IpSb
->DefaultInterface
= Ip6CreateInterface (IpSb
, TRUE
);
458 if (IpSb
->DefaultInterface
== NULL
) {
459 Status
= EFI_DEVICE_ERROR
;
464 // If there is any manual address, set it.
466 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeManualAddress
];
467 if (DataItem
->Data
.Ptr
!= NULL
) {
469 &IpSb
->Ip6ConfigInstance
,
476 // If there is any gateway address, set it.
478 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeGateway
];
479 if (DataItem
->Data
.Ptr
!= NULL
) {
481 &IpSb
->Ip6ConfigInstance
,
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
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
);
548 // Install the Ip6ServiceBinding Protocol onto ControlerHandle
550 Status
= gBS
->InstallMultipleProtocolInterfaces (
552 &gEfiIp6ServiceBindingProtocolGuid
,
553 &IpSb
->ServiceBinding
,
554 &gEfiIp6ConfigProtocolGuid
,
555 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
559 if (EFI_ERROR (Status
)) {
561 Ip6CleanService (IpSb
);
565 // Initialize the IP6 ID
567 mIp6Id
= NET_RANDOM (NetRandomInitSeed ());
569 Ip6SetVariableData (IpSb
);
576 Stop this driver on ControllerHandle.
578 @param[in] This Protocol instance pointer.
579 @param[in] ControllerHandle Handle of device to stop driver on.
580 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
581 of children is zero, stop the entire bus driver.
582 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
583 if NumberOfChildren is 0.
585 @retval EFI_SUCCESS The device was stopped.
586 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
591 Ip6DriverBindingStop (
592 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
593 IN EFI_HANDLE ControllerHandle
,
594 IN UINTN NumberOfChildren
,
595 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
598 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
600 IP6_PROTOCOL
*IpInstance
;
601 EFI_HANDLE NicHandle
;
608 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
610 if (NicHandle
!= NULL
) {
612 // DriverBindingStop is triggered by the uninstallation of the EFI DHCPv6
613 // Protocol used by Ip6Config.
618 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
620 if (NicHandle
== NULL
) {
621 return EFI_DEVICE_ERROR
;
625 Status
= gBS
->OpenProtocol (
627 &gEfiIp6ServiceBindingProtocolGuid
,
628 (VOID
**) &ServiceBinding
,
629 This
->DriverBindingHandle
,
631 EFI_OPEN_PROTOCOL_GET_PROTOCOL
633 if (EFI_ERROR (Status
)) {
634 return EFI_DEVICE_ERROR
;
637 IpSb
= IP6_SERVICE_FROM_PROTOCOL (ServiceBinding
);
639 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
641 if (IpSb
->InDestroy
) {
642 Status
= EFI_SUCCESS
;
648 Status
= Ip6ConfigDestroyDhcp6 (&IpSb
->Ip6ConfigInstance
);
649 gBS
->CloseEvent (IpSb
->Ip6ConfigInstance
.Dhcp6Event
);
650 IpSb
->Ip6ConfigInstance
.Dhcp6Event
= NULL
;
651 } else if (NumberOfChildren
== 0) {
653 IpSb
->InDestroy
= TRUE
;
655 IpSb
->State
= IP6_SERVICE_DESTROY
;
658 // Clear the variable data.
660 Ip6ClearVariableData (IpSb
);
662 Status
= Ip6CleanService (IpSb
);
663 if (EFI_ERROR (Status
)) {
668 Status
= gBS
->UninstallMultipleProtocolInterfaces (
670 &gEfiIp6ServiceBindingProtocolGuid
,
672 &gEfiIp6ConfigProtocolGuid
,
673 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
676 ASSERT_EFI_ERROR (Status
);
680 // NumberOfChildren is not zero, destroy all IP6 children instances.
682 while (!IsListEmpty (&IpSb
->Children
)) {
683 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP6_PROTOCOL
, Link
);
684 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
687 if (IpSb
->NumChildren
!= 0) {
688 Status
= EFI_DEVICE_ERROR
;
694 gBS
->RestoreTPL (OldTpl
);
701 Creates a child handle with a set of I/O services.
703 @param[in] This Protocol instance pointer.
704 @param[in] ChildHandle Pointer to the handle of the child to create. If
705 it is NULL, then a new handle is created. If it
706 is not NULL, then the I/O services are added to
707 the existing child handle.
709 @retval EFI_SUCCES The child handle was created with the I/O services.
710 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
712 @retval other The child handle was not created.
717 Ip6ServiceBindingCreateChild (
718 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
719 IN EFI_HANDLE
*ChildHandle
723 IP6_PROTOCOL
*IpInstance
;
728 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
729 return EFI_INVALID_PARAMETER
;
732 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
734 if (IpSb
->LinkLocalDadFail
) {
735 return EFI_DEVICE_ERROR
;
738 IpInstance
= AllocatePool (sizeof (IP6_PROTOCOL
));
740 if (IpInstance
== NULL
) {
741 return EFI_OUT_OF_RESOURCES
;
744 Ip6InitProtocol (IpSb
, IpInstance
);
747 // Install Ip6 onto ChildHandle
749 Status
= gBS
->InstallMultipleProtocolInterfaces (
751 &gEfiIp6ProtocolGuid
,
752 &IpInstance
->Ip6Proto
,
755 if (EFI_ERROR (Status
)) {
759 IpInstance
->Handle
= *ChildHandle
;
762 // Open the Managed Network protocol BY_CHILD.
764 Status
= gBS
->OpenProtocol (
765 IpSb
->MnpChildHandle
,
766 &gEfiManagedNetworkProtocolGuid
,
768 gIp6DriverBinding
.DriverBindingHandle
,
770 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
772 if (EFI_ERROR (Status
)) {
773 gBS
->UninstallMultipleProtocolInterfaces (
775 &gEfiIp6ProtocolGuid
,
776 &IpInstance
->Ip6Proto
,
784 // Insert it into the service binding instance.
786 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
788 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
791 gBS
->RestoreTPL (OldTpl
);
795 if (EFI_ERROR (Status
)) {
797 Ip6CleanProtocol (IpInstance
);
799 FreePool (IpInstance
);
806 Destroys a child handle with a set of I/O services.
808 @param[in] This Protocol instance pointer.
809 @param[in] ChildHandle Handle of the child to destroy.
811 @retval EFI_SUCCES The I/O services were removed from the child
813 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
814 that are being removed.
815 @retval EFI_INVALID_PARAMETER Child handle is NULL.
816 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
817 its I/O services are being used.
818 @retval other The child handle was not destroyed.
823 Ip6ServiceBindingDestroyChild (
824 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
825 IN EFI_HANDLE ChildHandle
830 IP6_PROTOCOL
*IpInstance
;
831 EFI_IP6_PROTOCOL
*Ip6
;
835 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
836 return EFI_INVALID_PARAMETER
;
840 // Retrieve the private context data structures
842 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
844 Status
= gBS
->OpenProtocol (
846 &gEfiIp6ProtocolGuid
,
848 gIp6DriverBinding
.DriverBindingHandle
,
850 EFI_OPEN_PROTOCOL_GET_PROTOCOL
853 if (EFI_ERROR (Status
)) {
854 return EFI_UNSUPPORTED
;
857 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (Ip6
);
859 if (IpInstance
->Service
!= IpSb
) {
860 return EFI_INVALID_PARAMETER
;
863 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
866 // A child can be destroyed more than once. For example,
867 // Ip6DriverBindingStop will destroy all of its children.
868 // when UDP driver is being stopped, it will destroy all
869 // the IP child it opens.
871 if (IpInstance
->State
== IP6_STATE_DESTROY
) {
872 gBS
->RestoreTPL (OldTpl
);
876 State
= IpInstance
->State
;
877 IpInstance
->State
= IP6_STATE_DESTROY
;
880 // Close the Managed Network protocol.
883 IpSb
->MnpChildHandle
,
884 &gEfiManagedNetworkProtocolGuid
,
885 gIp6DriverBinding
.DriverBindingHandle
,
890 // Uninstall the IP6 protocol first. Many thing happens during
892 // 1. The consumer of the IP6 protocol will be stopped if it
893 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
894 // stopped, IP driver's stop function will be called, and uninstall
895 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
896 // makes it possible to create the network stack bottom up, and
898 // 2. the upper layer will recycle the received packet. The recycle
899 // event's TPL is higher than this function. The recycle events
900 // will be called back before preceeding. If any packets not recycled,
901 // that means there is a resource leak.
903 Status
= gBS
->UninstallProtocolInterface (
905 &gEfiIp6ProtocolGuid
,
906 &IpInstance
->Ip6Proto
909 if (EFI_ERROR (Status
)) {
913 Status
= Ip6CleanProtocol (IpInstance
);
915 Ip6SetVariableData (IpSb
);
917 if (EFI_ERROR (Status
)) {
918 gBS
->InstallMultipleProtocolInterfaces (
920 &gEfiIp6ProtocolGuid
,
928 RemoveEntryList (&IpInstance
->Link
);
929 ASSERT (IpSb
->NumChildren
> 0);
932 gBS
->RestoreTPL (OldTpl
);
934 FreePool (IpInstance
);
938 IpInstance
->State
= State
;
939 gBS
->RestoreTPL (OldTpl
);