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