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
);
117 if (!IpSb
->LinkLocalDadFail
) {
119 // Leave link-scope all-nodes multicast address (FF02::1)
121 Ip6SetToAllNodeMulticast (FALSE
, IP6_LINK_LOCAL_SCOPE
, &AllNodes
);
123 Status
= Ip6LeaveGroup (IpSb
, &AllNodes
);
124 if (EFI_ERROR (Status
)) {
129 if (IpSb
->DefaultInterface
!= NULL
) {
130 Ip6CleanInterface (IpSb
->DefaultInterface
, NULL
);
131 IpSb
->DefaultInterface
= NULL
;
134 Ip6CleanDefaultRouterList (IpSb
);
136 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
137 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
139 if (IpSb
->RouteTable
!= NULL
) {
140 Ip6CleanRouteTable (IpSb
->RouteTable
);
141 IpSb
->RouteTable
= NULL
;
144 if (IpSb
->InterfaceId
!= NULL
) {
145 FreePool (IpSb
->InterfaceId
);
148 IpSb
->InterfaceId
= NULL
;
150 Ip6CleanAssembleTable (&IpSb
->Assemble
);
152 if (IpSb
->MnpChildHandle
!= NULL
) {
153 if (IpSb
->Mnp
!= NULL
) {
154 IpSb
->Mnp
->Cancel (IpSb
->Mnp
, NULL
);
155 IpSb
->Mnp
->Configure (IpSb
->Mnp
, NULL
);
157 IpSb
->MnpChildHandle
,
158 &gEfiManagedNetworkProtocolGuid
,
166 NetLibDestroyServiceChild (
169 &gEfiManagedNetworkServiceBindingProtocolGuid
,
173 IpSb
->MnpChildHandle
= NULL
;
176 if (IpSb
->RecvRequest
.MnpToken
.Event
!= NULL
) {
177 gBS
->CloseEvent (IpSb
->RecvRequest
.MnpToken
.Event
);
180 if (IpSb
->Timer
!= NULL
) {
181 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
182 gBS
->CloseEvent (IpSb
->Timer
);
187 if (IpSb
->FasterTimer
!= NULL
) {
188 gBS
->SetTimer (IpSb
->FasterTimer
, TimerCancel
, 0);
189 gBS
->CloseEvent (IpSb
->FasterTimer
);
191 IpSb
->FasterTimer
= NULL
;
194 // Free the Neighbor Discovery resources
196 while (!IsListEmpty (&IpSb
->NeighborTable
)) {
197 NeighborCache
= NET_LIST_HEAD (&IpSb
->NeighborTable
, IP6_NEIGHBOR_ENTRY
, Link
);
198 Ip6FreeNeighborEntry (IpSb
, NeighborCache
, FALSE
, TRUE
, EFI_SUCCESS
, NULL
, NULL
);
205 Create a new IP6 driver service binding protocol.
207 @param[in] Controller The controller that has MNP service binding
209 @param[in] ImageHandle The IP6 driver's image handle.
210 @param[out] Service The variable to receive the newly created IP6
213 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
214 @retval EFI_SUCCESS A new IP6 service binding private is created.
219 IN EFI_HANDLE Controller
,
220 IN EFI_HANDLE ImageHandle
,
221 OUT IP6_SERVICE
**Service
226 EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*MnpToken
;
227 EFI_MANAGED_NETWORK_CONFIG_DATA
*Config
;
228 IP6_CONFIG_DATA_ITEM
*DataItem
;
230 ASSERT (Service
!= NULL
);
235 // allocate a service private data then initialize all the filed to
236 // empty resources, so if any thing goes wrong when allocating
237 // resources, Ip6CleanService can be called to clean it up.
239 IpSb
= AllocateZeroPool (sizeof (IP6_SERVICE
));
242 return EFI_OUT_OF_RESOURCES
;
245 IpSb
->Signature
= IP6_SERVICE_SIGNATURE
;
246 IpSb
->ServiceBinding
.CreateChild
= Ip6ServiceBindingCreateChild
;
247 IpSb
->ServiceBinding
.DestroyChild
= Ip6ServiceBindingDestroyChild
;
248 IpSb
->State
= IP6_SERVICE_UNSTARTED
;
250 IpSb
->NumChildren
= 0;
251 InitializeListHead (&IpSb
->Children
);
253 InitializeListHead (&IpSb
->Interfaces
);
254 IpSb
->DefaultInterface
= NULL
;
255 IpSb
->RouteTable
= NULL
;
257 IpSb
->RecvRequest
.Signature
= IP6_LINK_RX_SIGNATURE
;
258 IpSb
->RecvRequest
.CallBack
= NULL
;
259 IpSb
->RecvRequest
.Context
= NULL
;
260 MnpToken
= &IpSb
->RecvRequest
.MnpToken
;
261 MnpToken
->Event
= NULL
;
262 MnpToken
->Status
= EFI_NOT_READY
;
263 MnpToken
->Packet
.RxData
= NULL
;
265 Ip6CreateAssembleTable (&IpSb
->Assemble
);
267 IpSb
->MldCtrl
.Mldv1QuerySeen
= 0;
268 InitializeListHead (&IpSb
->MldCtrl
.Groups
);
270 ZeroMem (&IpSb
->LinkLocalAddr
, sizeof (EFI_IPv6_ADDRESS
));
271 IpSb
->LinkLocalOk
= FALSE
;
272 IpSb
->LinkLocalDadFail
= FALSE
;
273 IpSb
->Dhcp6NeedStart
= FALSE
;
274 IpSb
->Dhcp6NeedInfoRequest
= FALSE
;
276 IpSb
->CurHopLimit
= IP6_HOP_LIMIT
;
277 IpSb
->LinkMTU
= IP6_MIN_LINK_MTU
;
278 IpSb
->BaseReachableTime
= IP6_REACHABLE_TIME
;
279 Ip6UpdateReachableTime (IpSb
);
281 // RFC4861 RETRANS_TIMER: 1,000 milliseconds
283 IpSb
->RetransTimer
= IP6_RETRANS_TIMER
;
285 IpSb
->RoundRobin
= 0;
287 InitializeListHead (&IpSb
->NeighborTable
);
288 InitializeListHead (&IpSb
->DefaultRouterList
);
289 InitializeListHead (&IpSb
->OnlinkPrefix
);
290 InitializeListHead (&IpSb
->AutonomousPrefix
);
292 IpSb
->InterfaceIdLen
= IP6_IF_ID_LEN
;
293 IpSb
->InterfaceId
= NULL
;
295 IpSb
->RouterAdvertiseReceived
= FALSE
;
296 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
299 IpSb
->Image
= ImageHandle
;
300 IpSb
->Controller
= Controller
;
302 IpSb
->MnpChildHandle
= NULL
;
305 Config
= &IpSb
->MnpConfigData
;
306 Config
->ReceivedQueueTimeoutValue
= 0;
307 Config
->TransmitQueueTimeoutValue
= 0;
308 Config
->ProtocolTypeFilter
= IP6_ETHER_PROTO
;
309 Config
->EnableUnicastReceive
= TRUE
;
310 Config
->EnableMulticastReceive
= TRUE
;
311 Config
->EnableBroadcastReceive
= TRUE
;
312 Config
->EnablePromiscuousReceive
= FALSE
;
313 Config
->FlushQueuesOnReset
= TRUE
;
314 Config
->EnableReceiveTimestamps
= FALSE
;
315 Config
->DisableBackgroundPolling
= FALSE
;
317 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
320 IpSb
->FasterTimer
= NULL
;
322 ZeroMem (&IpSb
->Ip6ConfigInstance
, sizeof (IP6_CONFIG_INSTANCE
));
324 IpSb
->MacString
= NULL
;
327 // Create various resources. First create the route table, timer
328 // event, MNP token event and MNP child.
331 IpSb
->RouteTable
= Ip6CreateRouteTable ();
332 if (IpSb
->RouteTable
== NULL
) {
333 Status
= EFI_OUT_OF_RESOURCES
;
337 Status
= gBS
->CreateEvent (
338 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
344 if (EFI_ERROR (Status
)) {
348 Status
= gBS
->CreateEvent (
349 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
351 Ip6NdFasterTimerTicking
,
355 if (EFI_ERROR (Status
)) {
359 Status
= NetLibCreateServiceChild (
362 &gEfiManagedNetworkServiceBindingProtocolGuid
,
363 &IpSb
->MnpChildHandle
365 if (EFI_ERROR (Status
)) {
369 Status
= gBS
->OpenProtocol (
370 IpSb
->MnpChildHandle
,
371 &gEfiManagedNetworkProtocolGuid
,
372 (VOID
**) (&IpSb
->Mnp
),
375 EFI_OPEN_PROTOCOL_BY_DRIVER
377 if (EFI_ERROR (Status
)) {
381 Status
= Ip6ServiceConfigMnp (IpSb
, TRUE
);
382 if (EFI_ERROR (Status
)) {
386 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
387 if (EFI_ERROR (Status
)) {
391 IpSb
->MaxPacketSize
= IP6_MIN_LINK_MTU
- sizeof (EFI_IP6_HEADER
);
392 if (NetLibGetVlanId (IpSb
->Controller
) != 0) {
394 // This is a VLAN device, reduce MTU by VLAN tag length
396 IpSb
->MaxPacketSize
-= NET_VLAN_TAG_LEN
;
398 IpSb
->OldMaxPacketSize
= IpSb
->MaxPacketSize
;
401 // Currently only ETHERNET is supported in IPv6 stack, since
402 // link local address requires an IEEE 802 48-bit MACs for
403 // EUI-64 format interface identifier mapping.
405 if (IpSb
->SnpMode
.IfType
!= NET_IFTYPE_ETHERNET
) {
406 Status
= EFI_UNSUPPORTED
;
410 Status
= Ip6InitMld (IpSb
);
411 if (EFI_ERROR (Status
)) {
416 // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds.
418 Status
= gBS
->SetTimer (IpSb
->FasterTimer
, TimerPeriodic
, TICKS_PER_MS
* IP6_TIMER_INTERVAL_IN_MS
);
419 if (EFI_ERROR (Status
)) {
424 // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds.
426 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_MS
* IP6_ONE_SECOND_IN_MS
);
427 if (EFI_ERROR (Status
)) {
432 Status
= gBS
->CreateEvent (
439 if (EFI_ERROR (Status
)) {
443 Status
= Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
444 if (EFI_ERROR (Status
)) {
448 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &IpSb
->MacString
);
449 if (EFI_ERROR (Status
)) {
453 Status
= Ip6ConfigInitInstance (&IpSb
->Ip6ConfigInstance
);
454 if (EFI_ERROR (Status
)) {
458 IpSb
->DefaultInterface
= Ip6CreateInterface (IpSb
, TRUE
);
459 if (IpSb
->DefaultInterface
== NULL
) {
460 Status
= EFI_DEVICE_ERROR
;
465 // If there is any manual address, set it.
467 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeManualAddress
];
468 if (DataItem
->Data
.Ptr
!= NULL
) {
470 &IpSb
->Ip6ConfigInstance
,
477 // If there is any gateway address, set it.
479 DataItem
= &IpSb
->Ip6ConfigInstance
.DataItem
[Ip6ConfigDataTypeGateway
];
480 if (DataItem
->Data
.Ptr
!= NULL
) {
482 &IpSb
->Ip6ConfigInstance
,
488 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
494 Ip6CleanService (IpSb
);
501 Start this driver on ControllerHandle.
503 @param[in] This Protocol instance pointer.
504 @param[in] ControllerHandle Handle of device to bind driver to.
505 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
508 @retval EFI_SUCCES This driver is added to ControllerHandle.
509 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
510 @retval other This driver does not support this device.
515 Ip6DriverBindingStart (
516 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
517 IN EFI_HANDLE ControllerHandle
,
518 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
525 // Test for the Ip6 service binding protocol
527 Status
= gBS
->OpenProtocol (
529 &gEfiIp6ServiceBindingProtocolGuid
,
531 This
->DriverBindingHandle
,
533 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
536 if (Status
== EFI_SUCCESS
) {
537 return EFI_ALREADY_STARTED
;
540 Status
= Ip6CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
542 if (EFI_ERROR (Status
)) {
546 ASSERT (IpSb
!= NULL
);
549 // Install the Ip6ServiceBinding Protocol onto ControlerHandle
551 Status
= gBS
->InstallMultipleProtocolInterfaces (
553 &gEfiIp6ServiceBindingProtocolGuid
,
554 &IpSb
->ServiceBinding
,
555 &gEfiIp6ConfigProtocolGuid
,
556 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
560 if (EFI_ERROR (Status
)) {
562 Ip6CleanService (IpSb
);
566 // Initialize the IP6 ID
568 mIp6Id
= NET_RANDOM (NetRandomInitSeed ());
570 Ip6SetVariableData (IpSb
);
577 Callback function which provided by user to remove one node in NetDestroyLinkList process.
579 @param[in] Entry The entry to be removed.
580 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
582 @retval EFI_SUCCESS The entry has been removed successfully.
583 @retval Others Fail to remove the entry.
588 Ip6DestroyChildEntryInHandleBuffer (
589 IN LIST_ENTRY
*Entry
,
593 IP6_PROTOCOL
*IpInstance
;
594 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
595 UINTN NumberOfChildren
;
596 EFI_HANDLE
*ChildHandleBuffer
;
598 if (Entry
== NULL
|| Context
== NULL
) {
599 return EFI_INVALID_PARAMETER
;
602 IpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_PROTOCOL
, Link
, IP6_PROTOCOL_SIGNATURE
);
603 ServiceBinding
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ServiceBinding
;
604 NumberOfChildren
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->NumberOfChildren
;
605 ChildHandleBuffer
= ((IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*) Context
)->ChildHandleBuffer
;
607 if (!NetIsInHandleBuffer (IpInstance
->Handle
, NumberOfChildren
, ChildHandleBuffer
)) {
611 return ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
615 Stop this driver on ControllerHandle.
617 @param[in] This Protocol instance pointer.
618 @param[in] ControllerHandle Handle of device to stop driver on.
619 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
620 of children is zero, stop the entire bus driver.
621 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
622 if NumberOfChildren is 0.
624 @retval EFI_SUCCESS The device was stopped.
625 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
630 Ip6DriverBindingStop (
631 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
632 IN EFI_HANDLE ControllerHandle
,
633 IN UINTN NumberOfChildren
,
634 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
637 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
639 EFI_HANDLE NicHandle
;
644 IP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
647 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
648 if (NicHandle
== NULL
) {
649 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
650 if (NicHandle
!= NULL
) {
657 Status
= gBS
->OpenProtocol (
659 &gEfiIp6ServiceBindingProtocolGuid
,
660 (VOID
**) &ServiceBinding
,
661 This
->DriverBindingHandle
,
663 EFI_OPEN_PROTOCOL_GET_PROTOCOL
665 if (EFI_ERROR (Status
)) {
666 return EFI_DEVICE_ERROR
;
669 IpSb
= IP6_SERVICE_FROM_PROTOCOL (ServiceBinding
);
672 Status
= Ip6ConfigDestroyDhcp6 (&IpSb
->Ip6ConfigInstance
);
673 gBS
->CloseEvent (IpSb
->Ip6ConfigInstance
.Dhcp6Event
);
674 IpSb
->Ip6ConfigInstance
.Dhcp6Event
= NULL
;
675 } else if (NumberOfChildren
!= 0) {
677 // NumberOfChildren is not zero, destroy the IP6 children instances in ChildHandleBuffer.
679 List
= &IpSb
->Children
;
680 Context
.ServiceBinding
= ServiceBinding
;
681 Context
.NumberOfChildren
= NumberOfChildren
;
682 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
683 Status
= NetDestroyLinkList (
685 Ip6DestroyChildEntryInHandleBuffer
,
689 } else if (IsListEmpty (&IpSb
->Children
)) {
691 IpSb
->State
= IP6_SERVICE_DESTROY
;
694 // Clear the variable data.
696 Ip6ClearVariableData (IpSb
);
698 Status
= Ip6CleanService (IpSb
);
699 if (EFI_ERROR (Status
)) {
704 Status
= gBS
->UninstallMultipleProtocolInterfaces (
706 &gEfiIp6ServiceBindingProtocolGuid
,
708 &gEfiIp6ConfigProtocolGuid
,
709 &IpSb
->Ip6ConfigInstance
.Ip6Config
,
712 ASSERT_EFI_ERROR (Status
);
714 Status
= EFI_SUCCESS
;
723 Creates a child handle with a set of I/O services.
725 @param[in] This Protocol instance pointer.
726 @param[in] ChildHandle Pointer to the handle of the child to create. If
727 it is NULL, then a new handle is created. If it
728 is not NULL, then the I/O services are added to
729 the existing child handle.
731 @retval EFI_SUCCES The child handle was created with the I/O services.
732 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
734 @retval other The child handle was not created.
739 Ip6ServiceBindingCreateChild (
740 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
741 IN EFI_HANDLE
*ChildHandle
745 IP6_PROTOCOL
*IpInstance
;
750 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
751 return EFI_INVALID_PARAMETER
;
754 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
756 if (IpSb
->LinkLocalDadFail
) {
757 return EFI_DEVICE_ERROR
;
760 IpInstance
= AllocatePool (sizeof (IP6_PROTOCOL
));
762 if (IpInstance
== NULL
) {
763 return EFI_OUT_OF_RESOURCES
;
766 Ip6InitProtocol (IpSb
, IpInstance
);
769 // Install Ip6 onto ChildHandle
771 Status
= gBS
->InstallMultipleProtocolInterfaces (
773 &gEfiIp6ProtocolGuid
,
774 &IpInstance
->Ip6Proto
,
777 if (EFI_ERROR (Status
)) {
781 IpInstance
->Handle
= *ChildHandle
;
784 // Open the Managed Network protocol BY_CHILD.
786 Status
= gBS
->OpenProtocol (
787 IpSb
->MnpChildHandle
,
788 &gEfiManagedNetworkProtocolGuid
,
790 gIp6DriverBinding
.DriverBindingHandle
,
792 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
794 if (EFI_ERROR (Status
)) {
795 gBS
->UninstallMultipleProtocolInterfaces (
797 &gEfiIp6ProtocolGuid
,
798 &IpInstance
->Ip6Proto
,
806 // Insert it into the service binding instance.
808 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
810 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
813 gBS
->RestoreTPL (OldTpl
);
817 if (EFI_ERROR (Status
)) {
819 Ip6CleanProtocol (IpInstance
);
821 FreePool (IpInstance
);
828 Destroys a child handle with a set of I/O services.
830 @param[in] This Protocol instance pointer.
831 @param[in] ChildHandle Handle of the child to destroy.
833 @retval EFI_SUCCES The I/O services were removed from the child
835 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
836 that are being removed.
837 @retval EFI_INVALID_PARAMETER Child handle is NULL.
838 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
839 its I/O services are being used.
840 @retval other The child handle was not destroyed.
845 Ip6ServiceBindingDestroyChild (
846 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
847 IN EFI_HANDLE ChildHandle
852 IP6_PROTOCOL
*IpInstance
;
853 EFI_IP6_PROTOCOL
*Ip6
;
856 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
857 return EFI_INVALID_PARAMETER
;
861 // Retrieve the private context data structures
863 IpSb
= IP6_SERVICE_FROM_PROTOCOL (This
);
865 Status
= gBS
->OpenProtocol (
867 &gEfiIp6ProtocolGuid
,
869 gIp6DriverBinding
.DriverBindingHandle
,
871 EFI_OPEN_PROTOCOL_GET_PROTOCOL
874 if (EFI_ERROR (Status
)) {
875 return EFI_UNSUPPORTED
;
878 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (Ip6
);
880 if (IpInstance
->Service
!= IpSb
) {
881 return EFI_INVALID_PARAMETER
;
884 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
887 // A child can be destroyed more than once. For example,
888 // Ip6DriverBindingStop will destroy all of its children.
889 // when UDP driver is being stopped, it will destroy all
890 // the IP child it opens.
892 if (IpInstance
->InDestroy
) {
893 gBS
->RestoreTPL (OldTpl
);
897 IpInstance
->InDestroy
= TRUE
;
900 // Close the Managed Network protocol.
903 IpSb
->MnpChildHandle
,
904 &gEfiManagedNetworkProtocolGuid
,
905 gIp6DriverBinding
.DriverBindingHandle
,
910 // Uninstall the IP6 protocol first. Many thing happens during
912 // 1. The consumer of the IP6 protocol will be stopped if it
913 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
914 // stopped, IP driver's stop function will be called, and uninstall
915 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
916 // makes it possible to create the network stack bottom up, and
918 // 2. the upper layer will recycle the received packet. The recycle
919 // event's TPL is higher than this function. The recycle events
920 // will be called back before preceeding. If any packets not recycled,
921 // that means there is a resource leak.
923 gBS
->RestoreTPL (OldTpl
);
924 Status
= gBS
->UninstallProtocolInterface (
926 &gEfiIp6ProtocolGuid
,
927 &IpInstance
->Ip6Proto
929 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
930 if (EFI_ERROR (Status
)) {
934 Status
= Ip6CleanProtocol (IpInstance
);
936 Ip6SetVariableData (IpSb
);
938 if (EFI_ERROR (Status
)) {
939 gBS
->InstallMultipleProtocolInterfaces (
941 &gEfiIp6ProtocolGuid
,
949 RemoveEntryList (&IpInstance
->Link
);
950 ASSERT (IpSb
->NumChildren
> 0);
953 gBS
->RestoreTPL (OldTpl
);
955 FreePool (IpInstance
);
959 gBS
->RestoreTPL (OldTpl
);