]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Dhcp6Dxe/Dhcp6Driver.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / NetworkPkg / Dhcp6Dxe / Dhcp6Driver.c
1 /** @file
2 Driver Binding functions and Service Binding functions
3 implementationfor for Dhcp6 Driver.
4
5 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
6
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.
11
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.
14
15 **/
16
17 #include "Dhcp6Impl.h"
18
19
20 EFI_DRIVER_BINDING_PROTOCOL gDhcp6DriverBinding = {
21 Dhcp6DriverBindingSupported,
22 Dhcp6DriverBindingStart,
23 Dhcp6DriverBindingStop,
24 0xa,
25 NULL,
26 NULL
27 };
28
29 EFI_SERVICE_BINDING_PROTOCOL gDhcp6ServiceBindingTemplate = {
30 Dhcp6ServiceBindingCreateChild,
31 Dhcp6ServiceBindingDestroyChild
32 };
33
34 /**
35 Configure the default Udp6Io to receive all the DHCP6 traffic
36 on this network interface.
37
38 @param[in] UdpIo The pointer to Udp6Io to be configured.
39 @param[in] Context The pointer to the context.
40
41 @retval EFI_SUCCESS The Udp6Io is successfully configured.
42 @retval Others Failed to configure the Udp6Io.
43
44 **/
45 EFI_STATUS
46 EFIAPI
47 Dhcp6ConfigureUdpIo (
48 IN UDP_IO *UdpIo,
49 IN VOID *Context
50 )
51 {
52 EFI_UDP6_PROTOCOL *Udp6;
53 EFI_UDP6_CONFIG_DATA *Config;
54
55 Udp6 = UdpIo->Protocol.Udp6;
56 Config = &(UdpIo->Config.Udp6);
57
58 ZeroMem (Config, sizeof (EFI_UDP6_CONFIG_DATA));
59
60 //
61 // Set Udp6 configure data for the Dhcp6 instance.
62 //
63 Config->AcceptPromiscuous = FALSE;
64 Config->AcceptAnyPort = FALSE;
65 Config->AllowDuplicatePort = FALSE;
66 Config->TrafficClass = 0;
67 Config->HopLimit = 128;
68 Config->ReceiveTimeout = 0;
69 Config->TransmitTimeout = 0;
70
71 //
72 // Configure an endpoint of client(0, 546), server(0, 0), the addresses
73 // will be overridden later. Note that we MUST not limit RemotePort.
74 // More details, refer to RFC 3315 section 5.2.
75 //
76 Config->StationPort = DHCP6_PORT_CLIENT;
77 Config->RemotePort = 0;
78
79 return Udp6->Configure (Udp6, Config);;
80 }
81
82
83 /**
84 Destroy the Dhcp6 service. The Dhcp6 service may be partly initialized,
85 or partly destroyed. If a resource is destroyed, it is marked as such in
86 case the destroy failed and being called again later.
87
88 @param[in, out] Service The pointer to Dhcp6 service to be destroyed.
89
90 **/
91 VOID
92 Dhcp6DestroyService (
93 IN OUT DHCP6_SERVICE *Service
94 )
95 {
96 //
97 // All children instances should have been already destroyed here.
98 //
99 ASSERT (Service->NumOfChild == 0);
100
101 if (Service->ClientId != NULL) {
102 FreePool (Service->ClientId);
103 }
104
105 if (Service->UdpIo != NULL) {
106 UdpIoFreeIo (Service->UdpIo);
107 }
108
109 FreePool (Service);
110 }
111
112
113 /**
114 Create a new Dhcp6 service for the Nic controller.
115
116 @param[in] Controller The controller to be installed DHCP6 service
117 binding protocol.
118 @param[in] ImageHandle The image handle of the Dhcp6 driver.
119 @param[out] Service The return pointer of the new Dhcp6 service.
120
121 @retval EFI_SUCCESS The Dhcp6 service is created successfully.
122 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
123 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
124
125 **/
126 EFI_STATUS
127 Dhcp6CreateService (
128 IN EFI_HANDLE Controller,
129 IN EFI_HANDLE ImageHandle,
130 OUT DHCP6_SERVICE **Service
131 )
132 {
133 DHCP6_SERVICE *Dhcp6Srv;
134 EFI_STATUS Status;
135
136 *Service = NULL;
137 Dhcp6Srv = AllocateZeroPool (sizeof (DHCP6_SERVICE));
138
139 if (Dhcp6Srv == NULL) {
140 return EFI_OUT_OF_RESOURCES;
141 }
142
143 //
144 // Open the SNP protocol to get mode data later.
145 //
146 Dhcp6Srv->Snp = NULL;
147 NetLibGetSnpHandle (Controller, &Dhcp6Srv->Snp);
148 if (Dhcp6Srv->Snp == NULL) {
149 FreePool (Dhcp6Srv);
150 return EFI_DEVICE_ERROR;
151 }
152
153 //
154 // Initialize the fields of the new Dhcp6 service.
155 //
156 Dhcp6Srv->Signature = DHCP6_SERVICE_SIGNATURE;
157 Dhcp6Srv->Controller = Controller;
158 Dhcp6Srv->Image = ImageHandle;
159 Dhcp6Srv->Xid = (0xffffff & NET_RANDOM (NetRandomInitSeed ()));
160
161 CopyMem (
162 &Dhcp6Srv->ServiceBinding,
163 &gDhcp6ServiceBindingTemplate,
164 sizeof (EFI_SERVICE_BINDING_PROTOCOL)
165 );
166
167 //
168 // Locate Ip6->Ip6Config and store it for get IP6 Duplicate Address Detection transmits.
169 //
170 Status = gBS->HandleProtocol (
171 Controller,
172 &gEfiIp6ConfigProtocolGuid,
173 (VOID **) &Dhcp6Srv->Ip6Cfg
174 );
175 if (EFI_ERROR (Status)) {
176 FreePool (Dhcp6Srv);
177 return Status;
178 }
179
180 //
181 // Generate client Duid: If SMBIOS system UUID is located, generate DUID in DUID-UUID format.
182 // Otherwise, in DUID-LLT format.
183 //
184 Dhcp6Srv->ClientId = Dhcp6GenerateClientId (Dhcp6Srv->Snp->Mode);
185
186 if (Dhcp6Srv->ClientId == NULL) {
187 FreePool (Dhcp6Srv);
188 return EFI_DEVICE_ERROR;
189 }
190
191 //
192 // Create an Udp6Io for stateful transmit/receive of each Dhcp6 instance.
193 //
194 Dhcp6Srv->UdpIo = UdpIoCreateIo (
195 Controller,
196 ImageHandle,
197 Dhcp6ConfigureUdpIo,
198 UDP_IO_UDP6_VERSION,
199 NULL
200 );
201
202 if (Dhcp6Srv->UdpIo == NULL) {
203 FreePool (Dhcp6Srv->ClientId);
204 FreePool (Dhcp6Srv);
205 return EFI_DEVICE_ERROR;
206 }
207
208 InitializeListHead (&Dhcp6Srv->Child);
209
210 *Service = Dhcp6Srv;
211
212 return EFI_SUCCESS;
213 }
214
215
216 /**
217 Destroy the Dhcp6 instance and recycle the resources.
218
219 @param[in, out] Instance The pointer to the Dhcp6 instance.
220
221 **/
222 VOID
223 Dhcp6DestroyInstance (
224 IN OUT DHCP6_INSTANCE *Instance
225 )
226 {
227 //
228 // Clean up the retry list first.
229 //
230 Dhcp6CleanupRetry (Instance, DHCP6_PACKET_ALL);
231 gBS->CloseEvent (Instance->Timer);
232
233 //
234 // Clean up the current configure data.
235 //
236 if (Instance->Config != NULL) {
237 Dhcp6CleanupConfigData (Instance->Config);
238 FreePool (Instance->Config);
239 }
240
241 //
242 // Clean up the current Ia.
243 //
244 if (Instance->IaCb.Ia != NULL) {
245 if (Instance->IaCb.Ia->ReplyPacket != NULL) {
246 FreePool (Instance->IaCb.Ia->ReplyPacket);
247 }
248 FreePool (Instance->IaCb.Ia);
249 }
250
251 if (Instance->Unicast != NULL) {
252 FreePool (Instance->Unicast);
253 }
254
255 if (Instance->AdSelect != NULL) {
256 FreePool (Instance->AdSelect);
257 }
258
259 FreePool (Instance);
260 }
261
262
263 /**
264 Create the Dhcp6 instance and initialize it.
265
266 @param[in] Service The pointer to the Dhcp6 service.
267 @param[out] Instance The pointer to the Dhcp6 instance.
268
269 @retval EFI_SUCCESS The Dhcp6 instance is created.
270 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
271
272 **/
273 EFI_STATUS
274 Dhcp6CreateInstance (
275 IN DHCP6_SERVICE *Service,
276 OUT DHCP6_INSTANCE **Instance
277 )
278 {
279 EFI_STATUS Status;
280 DHCP6_INSTANCE *Dhcp6Ins;
281
282 *Instance = NULL;
283 Dhcp6Ins = AllocateZeroPool (sizeof (DHCP6_INSTANCE));
284
285 if (Dhcp6Ins == NULL) {
286 return EFI_OUT_OF_RESOURCES;
287 }
288
289 //
290 // Initialize the fields of the new Dhcp6 instance.
291 //
292 Dhcp6Ins->Signature = DHCP6_INSTANCE_SIGNATURE;
293 Dhcp6Ins->UdpSts = EFI_ALREADY_STARTED;
294 Dhcp6Ins->Service = Service;
295 Dhcp6Ins->InDestroy = FALSE;
296 Dhcp6Ins->MediaPresent = TRUE;
297
298 CopyMem (
299 &Dhcp6Ins->Dhcp6,
300 &gDhcp6ProtocolTemplate,
301 sizeof (EFI_DHCP6_PROTOCOL)
302 );
303
304 InitializeListHead (&Dhcp6Ins->TxList);
305 InitializeListHead (&Dhcp6Ins->InfList);
306
307 //
308 // There is a timer for each Dhcp6 instance, which is used to track the
309 // lease time of Ia and the retransmisson time of all sent packets.
310 //
311 Status = gBS->CreateEvent (
312 EVT_NOTIFY_SIGNAL | EVT_TIMER,
313 TPL_CALLBACK,
314 Dhcp6OnTimerTick,
315 Dhcp6Ins,
316 &Dhcp6Ins->Timer
317 );
318
319 if (EFI_ERROR (Status)) {
320 FreePool (Dhcp6Ins);
321 return Status;
322 }
323
324 *Instance = Dhcp6Ins;
325
326 return EFI_SUCCESS;
327 }
328
329 /**
330 Callback function which provided by user to remove one node in NetDestroyLinkList process.
331
332 @param[in] Entry The entry to be removed.
333 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
334
335 @retval EFI_SUCCESS The entry has been removed successfully.
336 @retval Others Fail to remove the entry.
337
338 **/
339 EFI_STATUS
340 Dhcp6DestroyChildEntry (
341 IN LIST_ENTRY *Entry,
342 IN VOID *Context
343 )
344 {
345 DHCP6_INSTANCE *Instance;
346 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
347
348 if (Entry == NULL || Context == NULL) {
349 return EFI_INVALID_PARAMETER;
350 }
351
352 Instance = NET_LIST_USER_STRUCT_S (Entry, DHCP6_INSTANCE, Link, DHCP6_INSTANCE_SIGNATURE);
353 ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context;
354
355 return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
356 }
357
358
359 /**
360 Entry point of the DHCP6 driver to install various protocols.
361
362 @param[in] ImageHandle The handle of the UEFI image file.
363 @param[in] SystemTable The pointer to the EFI System Table.
364
365 @retval EFI_SUCCESS The operation completed successfully.
366 @retval Others Unexpected error occurs.
367
368 **/
369 EFI_STATUS
370 EFIAPI
371 Dhcp6DriverEntryPoint (
372 IN EFI_HANDLE ImageHandle,
373 IN EFI_SYSTEM_TABLE *SystemTable
374 )
375 {
376 return EfiLibInstallDriverBindingComponentName2 (
377 ImageHandle,
378 SystemTable,
379 &gDhcp6DriverBinding,
380 ImageHandle,
381 &gDhcp6ComponentName,
382 &gDhcp6ComponentName2
383 );
384 }
385
386
387 /**
388 Test to see if this driver supports ControllerHandle. This service
389 is called by the EFI boot service ConnectController(). In
390 order to make drivers as small as possible, there are a few calling
391 restrictions for this service. ConnectController() must
392 follow these calling restrictions. If any other agent wishes to call
393 Supported() it must also follow these calling restrictions.
394
395 @param[in] This The pointer to the driver binding protocol.
396 @param[in] ControllerHandle The handle of device to be tested.
397 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
398 device to be started.
399
400 @retval EFI_SUCCESS This driver supports this device.
401 @retval Others This driver does not support this device.
402
403 **/
404 EFI_STATUS
405 EFIAPI
406 Dhcp6DriverBindingSupported (
407 IN EFI_DRIVER_BINDING_PROTOCOL *This,
408 IN EFI_HANDLE ControllerHandle,
409 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
410 )
411 {
412 return gBS->OpenProtocol (
413 ControllerHandle,
414 &gEfiUdp6ServiceBindingProtocolGuid,
415 NULL,
416 This->DriverBindingHandle,
417 ControllerHandle,
418 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
419 );
420 }
421
422
423 /**
424 Start this driver on ControllerHandle. This service is called by the
425 EFI boot service ConnectController(). In order to make
426 drivers as small as possible, there are a few calling restrictions for
427 this service. ConnectController() must follow these
428 calling restrictions. If any other agent wishes to call Start() it
429 must also follow these calling restrictions.
430
431 @param[in] This The pointer to the driver binding protocol.
432 @param[in] ControllerHandle The handle of device to be started.
433 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
434 device to be started.
435
436 @retval EFI_SUCCESS This driver is installed to ControllerHandle.
437 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
438 @retval other This driver does not support this device.
439
440 **/
441 EFI_STATUS
442 EFIAPI
443 Dhcp6DriverBindingStart (
444 IN EFI_DRIVER_BINDING_PROTOCOL *This,
445 IN EFI_HANDLE ControllerHandle,
446 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
447 )
448 {
449 EFI_STATUS Status;
450 DHCP6_SERVICE *Service;
451
452 //
453 // Check the Dhcp6 serivce whether already started.
454 //
455 Status = gBS->OpenProtocol (
456 ControllerHandle,
457 &gEfiDhcp6ServiceBindingProtocolGuid,
458 NULL,
459 This->DriverBindingHandle,
460 ControllerHandle,
461 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
462 );
463
464 if (!EFI_ERROR (Status)) {
465 return EFI_ALREADY_STARTED;
466 }
467
468 //
469 // Create and initialize the Dhcp6 service.
470 //
471 Status = Dhcp6CreateService (
472 ControllerHandle,
473 This->DriverBindingHandle,
474 &Service
475 );
476
477 if (EFI_ERROR (Status)) {
478 return Status;
479 }
480
481 ASSERT (Service != NULL);
482
483 Status = gBS->InstallMultipleProtocolInterfaces (
484 &ControllerHandle,
485 &gEfiDhcp6ServiceBindingProtocolGuid,
486 &Service->ServiceBinding,
487 NULL
488 );
489
490 if (EFI_ERROR (Status)) {
491 Dhcp6DestroyService (Service);
492 return Status;
493 }
494
495 return EFI_SUCCESS;
496 }
497
498
499 /**
500 Stop this driver on ControllerHandle. This service is called by the
501 EFI boot service DisconnectController(). In order to
502 make drivers as small as possible, there are a few calling
503 restrictions for this service. DisconnectController()
504 must follow these calling restrictions. If any other agent wishes
505 to call Stop() it must also follow these calling restrictions.
506
507 @param[in] This Protocol instance pointer.
508 @param[in] ControllerHandle Handle of device to stop driver on
509 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
510 children is zero stop the entire bus driver.
511 @param[in] ChildHandleBuffer List of Child Handles to Stop.
512
513 @retval EFI_SUCCESS This driver is removed ControllerHandle
514 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
515 @retval other This driver was not removed from this device
516
517 **/
518 EFI_STATUS
519 EFIAPI
520 Dhcp6DriverBindingStop (
521 IN EFI_DRIVER_BINDING_PROTOCOL *This,
522 IN EFI_HANDLE ControllerHandle,
523 IN UINTN NumberOfChildren,
524 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
525 )
526 {
527 EFI_STATUS Status;
528 EFI_HANDLE NicHandle;
529 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
530 DHCP6_SERVICE *Service;
531 LIST_ENTRY *List;
532 UINTN ListLength;
533
534 //
535 // Find and check the Nic handle by the controller handle.
536 //
537 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp6ProtocolGuid);
538
539 if (NicHandle == NULL) {
540 return EFI_SUCCESS;
541 }
542
543 Status = gBS->OpenProtocol (
544 NicHandle,
545 &gEfiDhcp6ServiceBindingProtocolGuid,
546 (VOID **) &ServiceBinding,
547 This->DriverBindingHandle,
548 NicHandle,
549 EFI_OPEN_PROTOCOL_GET_PROTOCOL
550 );
551
552 if (EFI_ERROR (Status)) {
553 return Status;
554 }
555
556 Service = DHCP6_SERVICE_FROM_THIS (ServiceBinding);
557 if (!IsListEmpty (&Service->Child)) {
558 //
559 // Destroy all the children instances before destory the service.
560 //
561 List = &Service->Child;
562 Status = NetDestroyLinkList (
563 List,
564 Dhcp6DestroyChildEntry,
565 ServiceBinding,
566 &ListLength
567 );
568 if (EFI_ERROR (Status) || ListLength != 0) {
569 Status = EFI_DEVICE_ERROR;
570 }
571 }
572
573 if (NumberOfChildren == 0 && !IsListEmpty (&Service->Child)) {
574 Status = EFI_DEVICE_ERROR;
575 }
576
577 if (NumberOfChildren == 0 && IsListEmpty (&Service->Child)) {
578 //
579 // Destroy the service itself if no child instance left.
580 //
581 Status = gBS->UninstallProtocolInterface (
582 NicHandle,
583 &gEfiDhcp6ServiceBindingProtocolGuid,
584 ServiceBinding
585 );
586 if (EFI_ERROR (Status)) {
587 goto ON_EXIT;
588 }
589
590 Dhcp6DestroyService (Service);
591 Status = EFI_SUCCESS;
592 }
593
594 ON_EXIT:
595 return Status;
596 }
597
598
599 /**
600 Creates a child handle and installs a protocol.
601
602 The CreateChild() function installs a protocol on ChildHandle.
603 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
604 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
605
606 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
607 @param[in, out] ChildHandle Pointer to the handle of the child to create. If it is NULL,
608 then a new handle is created. If it is a pointer to an existing
609 UEFI handle, then the protocol is added to the existing UEFI handle.
610
611 @retval EFI_SUCCES The protocol was added to ChildHandle.
612 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
613 @retval other The child handle was not created.
614
615 **/
616 EFI_STATUS
617 EFIAPI
618 Dhcp6ServiceBindingCreateChild (
619 IN EFI_SERVICE_BINDING_PROTOCOL *This,
620 IN OUT EFI_HANDLE *ChildHandle
621 )
622 {
623 EFI_STATUS Status;
624 EFI_TPL OldTpl;
625 DHCP6_SERVICE *Service;
626 DHCP6_INSTANCE *Instance;
627 VOID *Udp6;
628
629 if (This == NULL || ChildHandle == NULL) {
630 return EFI_INVALID_PARAMETER;
631 }
632
633 Service = DHCP6_SERVICE_FROM_THIS (This);
634
635 Status = Dhcp6CreateInstance (Service, &Instance);
636
637 if (EFI_ERROR (Status)) {
638 return Status;
639 }
640
641 ASSERT (Instance != NULL);
642
643 //
644 // Start the timer when the instance is ready to use.
645 //
646 Status = gBS->SetTimer (
647 Instance->Timer,
648 TimerPeriodic,
649 TICKS_PER_SECOND
650 );
651
652 if (EFI_ERROR (Status)) {
653 goto ON_ERROR;
654 }
655
656 //
657 // Install the DHCP6 protocol onto ChildHandle.
658 //
659 Status = gBS->InstallMultipleProtocolInterfaces (
660 ChildHandle,
661 &gEfiDhcp6ProtocolGuid,
662 &Instance->Dhcp6,
663 NULL
664 );
665
666 if (EFI_ERROR (Status)) {
667 goto ON_ERROR;
668 }
669
670 Instance->Handle = *ChildHandle;
671
672 //
673 // Open the UDP6 protocol BY_CHILD.
674 //
675 Status = gBS->OpenProtocol (
676 Service->UdpIo->UdpHandle,
677 &gEfiUdp6ProtocolGuid,
678 (VOID **) &Udp6,
679 gDhcp6DriverBinding.DriverBindingHandle,
680 Instance->Handle,
681 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
682 );
683
684 if (EFI_ERROR (Status)) {
685
686 gBS->UninstallMultipleProtocolInterfaces (
687 Instance->Handle,
688 &gEfiDhcp6ProtocolGuid,
689 &Instance->Dhcp6,
690 NULL
691 );
692 goto ON_ERROR;
693 }
694
695 //
696 // Add into the children list of its parent service.
697 //
698 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
699
700 InsertTailList (&Service->Child, &Instance->Link);
701 Service->NumOfChild++;
702
703 gBS->RestoreTPL (OldTpl);
704 return EFI_SUCCESS;
705
706 ON_ERROR:
707
708 Dhcp6DestroyInstance (Instance);
709 return Status;
710 }
711
712
713 /**
714 Destroys a child handle with a protocol installed on it.
715
716 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
717 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
718 last protocol on ChildHandle, then ChildHandle is destroyed.
719
720 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
721 @param[in] ChildHandle Handle of the child to destroy
722
723 @retval EFI_SUCCES The protocol was removed from ChildHandle.
724 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
725 @retval EFI_INVALID_PARAMETER Child handle is NULL.
726 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
727 because its services are being used.
728 @retval other The child handle was not destroyed
729
730 **/
731 EFI_STATUS
732 EFIAPI
733 Dhcp6ServiceBindingDestroyChild (
734 IN EFI_SERVICE_BINDING_PROTOCOL *This,
735 IN EFI_HANDLE ChildHandle
736 )
737 {
738 EFI_STATUS Status;
739 EFI_TPL OldTpl;
740 EFI_DHCP6_PROTOCOL *Dhcp6;
741 DHCP6_SERVICE *Service;
742 DHCP6_INSTANCE *Instance;
743
744 if (This == NULL || ChildHandle == NULL) {
745 return EFI_INVALID_PARAMETER;
746 }
747
748 //
749 // Retrieve the private context data structures
750 //
751 Status = gBS->OpenProtocol (
752 ChildHandle,
753 &gEfiDhcp6ProtocolGuid,
754 (VOID **) &Dhcp6,
755 gDhcp6DriverBinding.DriverBindingHandle,
756 ChildHandle,
757 EFI_OPEN_PROTOCOL_GET_PROTOCOL
758 );
759
760 if (EFI_ERROR (Status)) {
761 return EFI_UNSUPPORTED;
762 }
763
764 Instance = DHCP6_INSTANCE_FROM_THIS (Dhcp6);
765 Service = DHCP6_SERVICE_FROM_THIS (This);
766
767 if (Instance->Service != Service) {
768 return EFI_INVALID_PARAMETER;
769 }
770
771 if (Instance->InDestroy) {
772 return EFI_SUCCESS;
773 }
774
775 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
776
777 Instance->InDestroy = TRUE;
778
779 Status = gBS->CloseProtocol (
780 Service->UdpIo->UdpHandle,
781 &gEfiUdp6ProtocolGuid,
782 gDhcp6DriverBinding.DriverBindingHandle,
783 ChildHandle
784 );
785
786 if (EFI_ERROR (Status)) {
787 Instance->InDestroy = FALSE;
788 gBS->RestoreTPL (OldTpl);
789 return Status;
790 }
791
792 //
793 // Uninstall the MTFTP6 protocol first to enable a top down destruction.
794 //
795 gBS->RestoreTPL (OldTpl);
796 Status = gBS->UninstallProtocolInterface (
797 ChildHandle,
798 &gEfiDhcp6ProtocolGuid,
799 Dhcp6
800 );
801 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
802 if (EFI_ERROR (Status)) {
803 Instance->InDestroy = FALSE;
804 gBS->RestoreTPL (OldTpl);
805 return Status;
806 }
807
808 //
809 // Remove it from the children list of its parent service.
810 //
811 RemoveEntryList (&Instance->Link);
812 Service->NumOfChild--;
813
814 gBS->RestoreTPL (OldTpl);
815
816 Dhcp6DestroyInstance (Instance);
817 return EFI_SUCCESS;
818 }