]>
Commit | Line | Data |
---|---|---|
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 | |
20 | EFI_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 | |
29 | EFI_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 | |
45 | EFI_STATUS\r | |
46 | EFIAPI\r | |
47 | Dhcp6ConfigureUdpIo (\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 | |
91 | VOID\r | |
92 | Dhcp6DestroyService (\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 | |
126 | EFI_STATUS\r | |
127 | Dhcp6CreateService (\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 | |
222 | VOID\r | |
223 | Dhcp6DestroyInstance (\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 | |
273 | EFI_STATUS\r | |
274 | Dhcp6CreateInstance (\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 | |
339 | EFI_STATUS\r | |
340 | Dhcp6DestroyChildEntry (\r | |
341 | IN LIST_ENTRY *Entry,\r | |
342 | IN VOID *Context\r | |
343 | )\r | |
344 | {\r | |
345 | DHCP6_INSTANCE *Instance;\r | |
346 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
347 | \r | |
348 | if (Entry == NULL || Context == NULL) {\r | |
349 | return EFI_INVALID_PARAMETER;\r | |
350 | }\r | |
351 | \r | |
352 | Instance = NET_LIST_USER_STRUCT_S (Entry, DHCP6_INSTANCE, Link, DHCP6_INSTANCE_SIGNATURE);\r | |
353 | ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context;\r | |
354 | \r | |
355 | return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);\r | |
356 | }\r | |
357 | \r | |
a3bcde70 HT |
358 | \r |
359 | /**\r | |
360 | Entry point of the DHCP6 driver to install various protocols.\r | |
361 | \r | |
362 | @param[in] ImageHandle The handle of the UEFI image file.\r | |
363 | @param[in] SystemTable The pointer to the EFI System Table.\r | |
364 | \r | |
365 | @retval EFI_SUCCESS The operation completed successfully.\r | |
366 | @retval Others Unexpected error occurs.\r | |
367 | \r | |
368 | **/\r | |
369 | EFI_STATUS\r | |
370 | EFIAPI\r | |
371 | Dhcp6DriverEntryPoint (\r | |
372 | IN EFI_HANDLE ImageHandle,\r | |
373 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
374 | )\r | |
375 | {\r | |
376 | return EfiLibInstallDriverBindingComponentName2 (\r | |
377 | ImageHandle,\r | |
378 | SystemTable,\r | |
379 | &gDhcp6DriverBinding,\r | |
380 | ImageHandle,\r | |
381 | &gDhcp6ComponentName,\r | |
382 | &gDhcp6ComponentName2\r | |
383 | );\r | |
384 | }\r | |
385 | \r | |
386 | \r | |
387 | /**\r | |
388 | Test to see if this driver supports ControllerHandle. This service\r | |
389 | is called by the EFI boot service ConnectController(). In\r | |
390 | order to make drivers as small as possible, there are a few calling\r | |
391 | restrictions for this service. ConnectController() must\r | |
392 | follow these calling restrictions. If any other agent wishes to call\r | |
393 | Supported() it must also follow these calling restrictions.\r | |
394 | \r | |
395 | @param[in] This The pointer to the driver binding protocol.\r | |
396 | @param[in] ControllerHandle The handle of device to be tested.\r | |
397 | @param[in] RemainingDevicePath Optional parameter use to pick a specific child\r | |
398 | device to be started.\r | |
399 | \r | |
400 | @retval EFI_SUCCESS This driver supports this device.\r | |
401 | @retval Others This driver does not support this device.\r | |
402 | \r | |
403 | **/\r | |
404 | EFI_STATUS\r | |
405 | EFIAPI\r | |
406 | Dhcp6DriverBindingSupported (\r | |
407 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
408 | IN EFI_HANDLE ControllerHandle,\r | |
409 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
410 | )\r | |
411 | {\r | |
412 | return gBS->OpenProtocol (\r | |
413 | ControllerHandle,\r | |
414 | &gEfiUdp6ServiceBindingProtocolGuid,\r | |
415 | NULL,\r | |
416 | This->DriverBindingHandle,\r | |
417 | ControllerHandle,\r | |
418 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
419 | );\r | |
420 | }\r | |
421 | \r | |
422 | \r | |
423 | /**\r | |
424 | Start this driver on ControllerHandle. This service is called by the\r | |
425 | EFI boot service ConnectController(). In order to make\r | |
426 | drivers as small as possible, there are a few calling restrictions for\r | |
427 | this service. ConnectController() must follow these\r | |
428 | calling restrictions. If any other agent wishes to call Start() it\r | |
429 | must also follow these calling restrictions.\r | |
430 | \r | |
431 | @param[in] This The pointer to the driver binding protocol.\r | |
432 | @param[in] ControllerHandle The handle of device to be started.\r | |
433 | @param[in] RemainingDevicePath Optional parameter use to pick a specific child\r | |
434 | device to be started.\r | |
435 | \r | |
436 | @retval EFI_SUCCESS This driver is installed to ControllerHandle.\r | |
437 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r | |
438 | @retval other This driver does not support this device.\r | |
439 | \r | |
440 | **/\r | |
441 | EFI_STATUS\r | |
442 | EFIAPI\r | |
443 | Dhcp6DriverBindingStart (\r | |
444 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
445 | IN EFI_HANDLE ControllerHandle,\r | |
446 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
447 | )\r | |
448 | {\r | |
449 | EFI_STATUS Status;\r | |
450 | DHCP6_SERVICE *Service;\r | |
451 | \r | |
452 | //\r | |
453 | // Check the Dhcp6 serivce whether already started.\r | |
454 | //\r | |
455 | Status = gBS->OpenProtocol (\r | |
456 | ControllerHandle,\r | |
457 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
458 | NULL,\r | |
459 | This->DriverBindingHandle,\r | |
460 | ControllerHandle,\r | |
461 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
462 | );\r | |
463 | \r | |
464 | if (!EFI_ERROR (Status)) {\r | |
465 | return EFI_ALREADY_STARTED;\r | |
466 | }\r | |
467 | \r | |
468 | //\r | |
469 | // Create and initialize the Dhcp6 service.\r | |
470 | //\r | |
471 | Status = Dhcp6CreateService (\r | |
472 | ControllerHandle,\r | |
473 | This->DriverBindingHandle,\r | |
474 | &Service\r | |
475 | );\r | |
476 | \r | |
477 | if (EFI_ERROR (Status)) {\r | |
478 | return Status;\r | |
479 | }\r | |
480 | \r | |
481 | ASSERT (Service != NULL);\r | |
482 | \r | |
483 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
484 | &ControllerHandle,\r | |
485 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
486 | &Service->ServiceBinding,\r | |
487 | NULL\r | |
488 | );\r | |
489 | \r | |
490 | if (EFI_ERROR (Status)) {\r | |
491 | Dhcp6DestroyService (Service);\r | |
492 | return Status;\r | |
493 | }\r | |
494 | \r | |
495 | return EFI_SUCCESS;\r | |
496 | }\r | |
497 | \r | |
498 | \r | |
499 | /**\r | |
500 | Stop this driver on ControllerHandle. This service is called by the\r | |
501 | EFI boot service DisconnectController(). In order to\r | |
502 | make drivers as small as possible, there are a few calling\r | |
503 | restrictions for this service. DisconnectController()\r | |
504 | must follow these calling restrictions. If any other agent wishes\r | |
505 | to call Stop() it must also follow these calling restrictions.\r | |
506 | \r | |
507 | @param[in] This Protocol instance pointer.\r | |
508 | @param[in] ControllerHandle Handle of device to stop driver on\r | |
509 | @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
510 | children is zero stop the entire bus driver.\r | |
511 | @param[in] ChildHandleBuffer List of Child Handles to Stop.\r | |
512 | \r | |
513 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
514 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
515 | @retval other This driver was not removed from this device\r | |
516 | \r | |
517 | **/\r | |
518 | EFI_STATUS\r | |
519 | EFIAPI\r | |
520 | Dhcp6DriverBindingStop (\r | |
521 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
522 | IN EFI_HANDLE ControllerHandle,\r | |
523 | IN UINTN NumberOfChildren,\r | |
524 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
525 | )\r | |
526 | {\r | |
527 | EFI_STATUS Status;\r | |
a3bcde70 HT |
528 | EFI_HANDLE NicHandle;\r |
529 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
530 | DHCP6_SERVICE *Service;\r | |
216f7970 | 531 | LIST_ENTRY *List;\r |
532 | UINTN ListLength;\r | |
a3bcde70 HT |
533 | \r |
534 | //\r | |
535 | // Find and check the Nic handle by the controller handle.\r | |
536 | //\r | |
537 | NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp6ProtocolGuid);\r | |
538 | \r | |
539 | if (NicHandle == NULL) {\r | |
216f7970 | 540 | return EFI_SUCCESS;\r |
a3bcde70 HT |
541 | }\r |
542 | \r | |
543 | Status = gBS->OpenProtocol (\r | |
544 | NicHandle,\r | |
545 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
546 | (VOID **) &ServiceBinding,\r | |
547 | This->DriverBindingHandle,\r | |
548 | NicHandle,\r | |
549 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
550 | );\r | |
551 | \r | |
552 | if (EFI_ERROR (Status)) {\r | |
553 | return Status;\r | |
554 | }\r | |
555 | \r | |
556 | Service = DHCP6_SERVICE_FROM_THIS (ServiceBinding);\r | |
216f7970 | 557 | if (!IsListEmpty (&Service->Child)) {\r |
558 | //\r | |
559 | // Destroy all the children instances before destory the service.\r | |
560 | // \r | |
561 | List = &Service->Child;\r | |
562 | Status = NetDestroyLinkList (\r | |
563 | List,\r | |
564 | Dhcp6DestroyChildEntry,\r | |
565 | ServiceBinding,\r | |
566 | &ListLength\r | |
567 | );\r | |
568 | if (EFI_ERROR (Status) || ListLength != 0) {\r | |
569 | Status = EFI_DEVICE_ERROR;\r | |
570 | }\r | |
a3bcde70 HT |
571 | }\r |
572 | \r | |
216f7970 | 573 | if (NumberOfChildren == 0 && !IsListEmpty (&Service->Child)) {\r |
574 | Status = EFI_DEVICE_ERROR;\r | |
575 | }\r | |
a3bcde70 | 576 | \r |
216f7970 | 577 | if (NumberOfChildren == 0 && IsListEmpty (&Service->Child)) {\r |
a3bcde70 | 578 | //\r |
75dce340 | 579 | // Destroy the service itself if no child instance left.\r |
a3bcde70 | 580 | //\r |
a3bcde70 HT |
581 | Status = gBS->UninstallProtocolInterface (\r |
582 | NicHandle,\r | |
583 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
584 | ServiceBinding\r | |
585 | );\r | |
a3bcde70 | 586 | if (EFI_ERROR (Status)) {\r |
a3bcde70 HT |
587 | goto ON_EXIT;\r |
588 | }\r | |
589 | \r | |
590 | Dhcp6DestroyService (Service);\r | |
216f7970 | 591 | Status = EFI_SUCCESS;\r |
a3bcde70 | 592 | }\r |
216f7970 | 593 | \r |
a3bcde70 | 594 | ON_EXIT:\r |
a3bcde70 HT |
595 | return Status;\r |
596 | }\r | |
597 | \r | |
598 | \r | |
599 | /**\r | |
600 | Creates a child handle and installs a protocol.\r | |
601 | \r | |
602 | The CreateChild() function installs a protocol on ChildHandle.\r | |
603 | If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.\r | |
604 | If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r | |
605 | \r | |
606 | @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
607 | @param[in, out] ChildHandle Pointer to the handle of the child to create. If it is NULL,\r | |
608 | then a new handle is created. If it is a pointer to an existing\r | |
609 | UEFI handle, then the protocol is added to the existing UEFI handle.\r | |
610 | \r | |
611 | @retval EFI_SUCCES The protocol was added to ChildHandle.\r | |
612 | @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r | |
613 | @retval other The child handle was not created.\r | |
614 | \r | |
615 | **/\r | |
616 | EFI_STATUS\r | |
617 | EFIAPI\r | |
618 | Dhcp6ServiceBindingCreateChild (\r | |
619 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
620 | IN OUT EFI_HANDLE *ChildHandle\r | |
621 | )\r | |
622 | {\r | |
623 | EFI_STATUS Status;\r | |
624 | EFI_TPL OldTpl;\r | |
625 | DHCP6_SERVICE *Service;\r | |
626 | DHCP6_INSTANCE *Instance;\r | |
627 | VOID *Udp6;\r | |
628 | \r | |
629 | if (This == NULL || ChildHandle == NULL) {\r | |
630 | return EFI_INVALID_PARAMETER;\r | |
631 | }\r | |
632 | \r | |
633 | Service = DHCP6_SERVICE_FROM_THIS (This);\r | |
634 | \r | |
635 | Status = Dhcp6CreateInstance (Service, &Instance);\r | |
636 | \r | |
637 | if (EFI_ERROR (Status)) {\r | |
638 | return Status;\r | |
639 | }\r | |
640 | \r | |
641 | ASSERT (Instance != NULL);\r | |
642 | \r | |
643 | //\r | |
644 | // Start the timer when the instance is ready to use.\r | |
645 | //\r | |
646 | Status = gBS->SetTimer (\r | |
647 | Instance->Timer,\r | |
648 | TimerPeriodic,\r | |
649 | TICKS_PER_SECOND\r | |
650 | );\r | |
651 | \r | |
652 | if (EFI_ERROR (Status)) {\r | |
653 | goto ON_ERROR;\r | |
654 | }\r | |
655 | \r | |
656 | //\r | |
657 | // Install the DHCP6 protocol onto ChildHandle.\r | |
658 | //\r | |
659 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
660 | ChildHandle,\r | |
661 | &gEfiDhcp6ProtocolGuid,\r | |
662 | &Instance->Dhcp6,\r | |
663 | NULL\r | |
664 | );\r | |
665 | \r | |
666 | if (EFI_ERROR (Status)) {\r | |
667 | goto ON_ERROR;\r | |
668 | }\r | |
669 | \r | |
670 | Instance->Handle = *ChildHandle;\r | |
671 | \r | |
672 | //\r | |
673 | // Open the UDP6 protocol BY_CHILD.\r | |
674 | //\r | |
675 | Status = gBS->OpenProtocol (\r | |
676 | Service->UdpIo->UdpHandle,\r | |
677 | &gEfiUdp6ProtocolGuid,\r | |
678 | (VOID **) &Udp6,\r | |
679 | gDhcp6DriverBinding.DriverBindingHandle,\r | |
680 | Instance->Handle,\r | |
681 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
682 | );\r | |
683 | \r | |
684 | if (EFI_ERROR (Status)) {\r | |
685 | \r | |
686 | gBS->UninstallMultipleProtocolInterfaces (\r | |
687 | Instance->Handle,\r | |
688 | &gEfiDhcp6ProtocolGuid,\r | |
689 | &Instance->Dhcp6,\r | |
690 | NULL\r | |
691 | );\r | |
692 | goto ON_ERROR;\r | |
693 | }\r | |
694 | \r | |
695 | //\r | |
696 | // Add into the children list of its parent service.\r | |
697 | //\r | |
698 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
699 | \r | |
700 | InsertTailList (&Service->Child, &Instance->Link);\r | |
701 | Service->NumOfChild++;\r | |
702 | \r | |
703 | gBS->RestoreTPL (OldTpl);\r | |
704 | return EFI_SUCCESS;\r | |
705 | \r | |
706 | ON_ERROR:\r | |
707 | \r | |
708 | Dhcp6DestroyInstance (Instance);\r | |
709 | return Status;\r | |
710 | }\r | |
711 | \r | |
712 | \r | |
713 | /**\r | |
714 | Destroys a child handle with a protocol installed on it.\r | |
715 | \r | |
716 | The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r | |
717 | that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r | |
718 | last protocol on ChildHandle, then ChildHandle is destroyed.\r | |
719 | \r | |
720 | @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
721 | @param[in] ChildHandle Handle of the child to destroy\r | |
722 | \r | |
723 | @retval EFI_SUCCES The protocol was removed from ChildHandle.\r | |
724 | @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r | |
15ee13fc | 725 | @retval EFI_INVALID_PARAMETER Child handle is NULL.\r |
a3bcde70 HT |
726 | @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r |
727 | because its services are being used.\r | |
728 | @retval other The child handle was not destroyed\r | |
729 | \r | |
730 | **/\r | |
731 | EFI_STATUS\r | |
732 | EFIAPI\r | |
733 | Dhcp6ServiceBindingDestroyChild (\r | |
734 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
735 | IN EFI_HANDLE ChildHandle\r | |
736 | )\r | |
737 | {\r | |
738 | EFI_STATUS Status;\r | |
739 | EFI_TPL OldTpl;\r | |
740 | EFI_DHCP6_PROTOCOL *Dhcp6;\r | |
741 | DHCP6_SERVICE *Service;\r | |
742 | DHCP6_INSTANCE *Instance;\r | |
743 | \r | |
744 | if (This == NULL || ChildHandle == NULL) {\r | |
745 | return EFI_INVALID_PARAMETER;\r | |
746 | }\r | |
747 | \r | |
748 | //\r | |
749 | // Retrieve the private context data structures\r | |
750 | //\r | |
751 | Status = gBS->OpenProtocol (\r | |
752 | ChildHandle,\r | |
753 | &gEfiDhcp6ProtocolGuid,\r | |
754 | (VOID **) &Dhcp6,\r | |
755 | gDhcp6DriverBinding.DriverBindingHandle,\r | |
756 | ChildHandle,\r | |
757 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
758 | );\r | |
759 | \r | |
760 | if (EFI_ERROR (Status)) {\r | |
761 | return EFI_UNSUPPORTED;\r | |
762 | }\r | |
763 | \r | |
764 | Instance = DHCP6_INSTANCE_FROM_THIS (Dhcp6);\r | |
765 | Service = DHCP6_SERVICE_FROM_THIS (This);\r | |
766 | \r | |
767 | if (Instance->Service != Service) {\r | |
768 | return EFI_INVALID_PARAMETER;\r | |
769 | }\r | |
770 | \r | |
75dce340 | 771 | if (Instance->InDestroy) {\r |
a3bcde70 HT |
772 | return EFI_SUCCESS;\r |
773 | }\r | |
774 | \r | |
775 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
776 | \r | |
75dce340 | 777 | Instance->InDestroy = TRUE;\r |
a3bcde70 HT |
778 | \r |
779 | Status = gBS->CloseProtocol (\r | |
780 | Service->UdpIo->UdpHandle,\r | |
781 | &gEfiUdp6ProtocolGuid,\r | |
782 | gDhcp6DriverBinding.DriverBindingHandle,\r | |
783 | ChildHandle\r | |
784 | );\r | |
785 | \r | |
786 | if (EFI_ERROR (Status)) {\r | |
75dce340 | 787 | Instance->InDestroy = FALSE;\r |
a3bcde70 HT |
788 | gBS->RestoreTPL (OldTpl);\r |
789 | return Status;\r | |
790 | }\r | |
791 | \r | |
792 | //\r | |
793 | // Uninstall the MTFTP6 protocol first to enable a top down destruction.\r | |
794 | //\r | |
216f7970 | 795 | gBS->RestoreTPL (OldTpl);\r |
a3bcde70 HT |
796 | Status = gBS->UninstallProtocolInterface (\r |
797 | ChildHandle,\r | |
798 | &gEfiDhcp6ProtocolGuid,\r | |
799 | Dhcp6\r | |
800 | );\r | |
216f7970 | 801 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
a3bcde70 | 802 | if (EFI_ERROR (Status)) {\r |
75dce340 | 803 | Instance->InDestroy = FALSE;\r |
a3bcde70 HT |
804 | gBS->RestoreTPL (OldTpl);\r |
805 | return Status;\r | |
806 | }\r | |
807 | \r | |
808 | //\r | |
809 | // Remove it from the children list of its parent service.\r | |
810 | //\r | |
811 | RemoveEntryList (&Instance->Link);\r | |
812 | Service->NumOfChild--;\r | |
813 | \r | |
a3bcde70 HT |
814 | gBS->RestoreTPL (OldTpl);\r |
815 | \r | |
216f7970 | 816 | Dhcp6DestroyInstance (Instance);\r |
a3bcde70 HT |
817 | return EFI_SUCCESS;\r |
818 | }\r |