2 The driver binding and service binding protocol for IP6 driver.
4 Copyright (c) 2009 - 2010, 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 destory 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
,
475 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
481 Ip6CleanService (IpSb
);
488 Start this driver on ControllerHandle.
490 @param[in] This Protocol instance pointer.
491 @param[in] ControllerHandle Handle of device to bind driver to.
492 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
495 @retval EFI_SUCCES This driver is added to ControllerHandle.
496 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
497 @retval other This driver does not support this device.
502 Ip6DriverBindingStart (
503 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
504 IN EFI_HANDLE ControllerHandle
,
505 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
512 // Test for the Ip6 service binding protocol
514 Status
= gBS
->OpenProtocol (
516 &gEfiIp6ServiceBindingProtocolGuid
,
518 This
->DriverBindingHandle
,
520 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
523 if (Status
== EFI_SUCCESS
) {
524 return EFI_ALREADY_STARTED
;
527 Status
= Ip6CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
529 if (EFI_ERROR (Status
)) {
533 ASSERT (IpSb
!= NULL
);
536 // Install the Ip6ServiceBinding Protocol onto ControlerHandle
538 Status
= gBS
->InstallMultipleProtocolInterfaces (
540 &gEfiIp6ServiceBindingProtocolGuid
,
541 &IpSb
->ServiceBinding
,
542 &gEfiIp6ConfigProtocolGuid
,
543 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
547 if (EFI_ERROR (Status
)) {
549 Ip6CleanService (IpSb
);
553 // Initialize the IP6 ID
555 mIp6Id
= NET_RANDOM (NetRandomInitSeed ());
557 Ip6SetVariableData (IpSb
);
564 Stop this driver on ControllerHandle.
566 @param[in] This Protocol instance pointer.
567 @param[in] ControllerHandle Handle of device to stop driver on.
568 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
569 of children is zero, stop the entire bus driver.
570 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
571 if NumberOfChildren is 0.
573 @retval EFI_SUCCESS The device was stopped.
574 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
579 Ip6DriverBindingStop (
580 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
581 IN EFI_HANDLE ControllerHandle
,
582 IN UINTN NumberOfChildren
,
583 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
586 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
588 IP6_PROTOCOL
*IpInstance
;
589 EFI_HANDLE NicHandle
;
596 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
598 if (NicHandle
!= NULL
) {
600 // DriverBindingStop is triggered by the uninstallation of the EFI DHCPv6
601 // Protocol used by Ip6Config.
606 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
608 if (NicHandle
== NULL
) {
609 return EFI_DEVICE_ERROR
;
613 Status
= gBS
->OpenProtocol (
615 &gEfiIp6ServiceBindingProtocolGuid
,
616 (VOID
**) &ServiceBinding
,
617 This
->DriverBindingHandle
,
619 EFI_OPEN_PROTOCOL_GET_PROTOCOL
621 if (EFI_ERROR (Status
)) {
622 return EFI_DEVICE_ERROR
;
625 IpSb
= IP6_SERVICE_FROM_PROTOCOL (ServiceBinding
);
627 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
629 if (IpSb
->InDestroy
) {
630 Status
= EFI_SUCCESS
;
636 Status
= Ip6ConfigDestroyDhcp6 (&IpSb
->Ip6ConfigInstance
);
637 gBS
->CloseEvent (IpSb
->Ip6ConfigInstance
.Dhcp6Event
);
638 IpSb
->Ip6ConfigInstance
.Dhcp6Event
= NULL
;
639 } else if (NumberOfChildren
== 0) {
641 IpSb
->InDestroy
= TRUE
;
643 IpSb
->State
= IP6_SERVICE_DESTROY
;
646 // Clear the variable data.
648 Ip6ClearVariableData (IpSb
);
650 Status
= Ip6CleanService (IpSb
);
651 if (EFI_ERROR (Status
)) {
656 Status
= gBS
->UninstallMultipleProtocolInterfaces (
658 &gEfiIp6ServiceBindingProtocolGuid
,
660 &gEfiIp6ConfigProtocolGuid
,
661 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
664 ASSERT_EFI_ERROR (Status
);
668 // NumberOfChildren is not zero, destroy all IP6 children instances.
670 while (!IsListEmpty (&IpSb
->Children
)) {
671 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP6_PROTOCOL
, Link
);
672 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
675 if (IpSb
->NumChildren
!= 0) {
676 Status
= EFI_DEVICE_ERROR
;
682 gBS
->RestoreTPL (OldTpl
);
689 Creates a child handle with a set of I/O services.
691 @param[in] This Protocol instance pointer.
692 @param[in] ChildHandle Pointer to the handle of the child to create. If
693 it is NULL, then a new handle is created. If it
694 is not NULL, then the I/O services are added to
695 the existing child handle.
697 @retval EFI_SUCCES The child handle was created with the I/O services.
698 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
700 @retval other The child handle was not created.
705 Ip6ServiceBindingCreateChild (
706 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
707 IN EFI_HANDLE
*ChildHandle
711 IP6_PROTOCOL
*IpInstance
;
716 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
717 return EFI_INVALID_PARAMETER
;
720 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
722 if (IpSb
->LinkLocalDadFail
) {
723 return EFI_DEVICE_ERROR
;
726 IpInstance
= AllocatePool (sizeof (IP6_PROTOCOL
));
728 if (IpInstance
== NULL
) {
729 return EFI_OUT_OF_RESOURCES
;
732 Ip6InitProtocol (IpSb
, IpInstance
);
735 // Install Ip6 onto ChildHandle
737 Status
= gBS
->InstallMultipleProtocolInterfaces (
739 &gEfiIp6ProtocolGuid
,
740 &IpInstance
->Ip6Proto
,
743 if (EFI_ERROR (Status
)) {
747 IpInstance
->Handle
= *ChildHandle
;
750 // Open the Managed Network protocol BY_CHILD.
752 Status
= gBS
->OpenProtocol (
753 IpSb
->MnpChildHandle
,
754 &gEfiManagedNetworkProtocolGuid
,
756 gIp6DriverBinding
.DriverBindingHandle
,
758 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
760 if (EFI_ERROR (Status
)) {
761 gBS
->UninstallMultipleProtocolInterfaces (
763 &gEfiIp6ProtocolGuid
,
764 &IpInstance
->Ip6Proto
,
772 // Insert it into the service binding instance.
774 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
776 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
779 gBS
->RestoreTPL (OldTpl
);
783 if (EFI_ERROR (Status
)) {
785 Ip6CleanProtocol (IpInstance
);
787 FreePool (IpInstance
);
794 Destroys a child handle with a set of I/O services.
796 @param[in] This Protocol instance pointer.
797 @param[in] ChildHandle Handle of the child to destroy.
799 @retval EFI_SUCCES The I/O services were removed from the child
801 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
802 that are being removed.
803 @retval EFI_INVALID_PARAMETER Child handle is not a valid EFI Handle.
804 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
805 its I/O services are being used.
806 @retval other The child handle was not destroyed.
811 Ip6ServiceBindingDestroyChild (
812 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
813 IN EFI_HANDLE ChildHandle
818 IP6_PROTOCOL
*IpInstance
;
819 EFI_IP6_PROTOCOL
*Ip6
;
823 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
824 return EFI_INVALID_PARAMETER
;
828 // Retrieve the private context data structures
830 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
832 Status
= gBS
->OpenProtocol (
834 &gEfiIp6ProtocolGuid
,
836 gIp6DriverBinding
.DriverBindingHandle
,
838 EFI_OPEN_PROTOCOL_GET_PROTOCOL
841 if (EFI_ERROR (Status
)) {
842 return EFI_UNSUPPORTED
;
845 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (Ip6
);
847 if (IpInstance
->Service
!= IpSb
) {
848 return EFI_INVALID_PARAMETER
;
851 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
854 // A child can be destroyed more than once. For example,
855 // Ip6DriverBindingStop will destory all of its children.
856 // when UDP driver is being stopped, it will destory all
857 // the IP child it opens.
859 if (IpInstance
->State
== IP6_STATE_DESTROY
) {
860 gBS
->RestoreTPL (OldTpl
);
864 State
= IpInstance
->State
;
865 IpInstance
->State
= IP6_STATE_DESTROY
;
868 // Close the Managed Network protocol.
871 IpSb
->MnpChildHandle
,
872 &gEfiManagedNetworkProtocolGuid
,
873 gIp6DriverBinding
.DriverBindingHandle
,
878 // Uninstall the IP6 protocol first. Many thing happens during
880 // 1. The consumer of the IP6 protocol will be stopped if it
881 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
882 // stopped, IP driver's stop function will be called, and uninstall
883 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
884 // makes it possible to create the network stack bottom up, and
886 // 2. the upper layer will recycle the received packet. The recycle
887 // event's TPL is higher than this function. The recycle events
888 // will be called back before preceeding. If any packets not recycled,
889 // that means there is a resource leak.
891 Status
= gBS
->UninstallProtocolInterface (
893 &gEfiIp6ProtocolGuid
,
894 &IpInstance
->Ip6Proto
897 if (EFI_ERROR (Status
)) {
901 Status
= Ip6CleanProtocol (IpInstance
);
903 Ip6SetVariableData (IpSb
);
905 if (EFI_ERROR (Status
)) {
906 gBS
->InstallMultipleProtocolInterfaces (
908 &gEfiIp6ProtocolGuid
,
916 RemoveEntryList (&IpInstance
->Link
);
917 ASSERT (IpSb
->NumChildren
> 0);
920 gBS
->RestoreTPL (OldTpl
);
922 FreePool (IpInstance
);
926 IpInstance
->State
= State
;
927 gBS
->RestoreTPL (OldTpl
);