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