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