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