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