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