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