]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / NetworkPkg / Dhcp6Dxe / Dhcp6Impl.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 This EFI_DHCP6_PROTOCOL interface implementation.\r
3\r
ed2bfecb 4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "Dhcp6Impl.h"\r
17\r
18//\r
19// Well-known multi-cast address defined in section-24.1 of rfc-3315\r
20//\r
21// ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2\r
22// ALL_DHCP_Servers address: FF05::1:3\r
23//\r
24EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};\r
25EFI_IPv6_ADDRESS mAllDhcpServersAddress = {{0xFF, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3}};\r
26\r
27EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate = {\r
28 EfiDhcp6GetModeData,\r
29 EfiDhcp6Configure,\r
30 EfiDhcp6Start,\r
31 EfiDhcp6InfoRequest,\r
32 EfiDhcp6RenewRebind,\r
33 EfiDhcp6Decline,\r
34 EfiDhcp6Release,\r
35 EfiDhcp6Stop,\r
36 EfiDhcp6Parse\r
37};\r
38\r
39/**\r
40 Starts the DHCPv6 standard S.A.R.R. process.\r
41\r
42 The Start() function starts the DHCPv6 standard process. This function can\r
43 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.\r
44 If the DHCP process completes successfully, the state of the Dhcp6 instance\r
45 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the\r
46 Dhcp6Bound state.\r
47 Refer to rfc-3315 for precise state transitions during this process. At the\r
48 time when each event occurs in this process, the callback function that was set\r
49 by EFI_DHCP6_PROTOCOL.Configure() will be called, and the user can take this\r
50 opportunity to control the process.\r
51\r
52 @param[in] This The pointer to Dhcp6 protocol.\r
53\r
54 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it has\r
55 completed when CompletionEvent is NULL.\r
56 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.\r
57 @retval EFI_INVALID_PARAMETER This is NULL.\r
58 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
59 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no\r
60 response was received from the server within the\r
61 specified timeout value.\r
62 @retval EFI_ABORTED The user aborted the DHCPv6 process.\r
63 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6\r
64 standard process.\r
65 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
66 @retval EFI_NO_MEDIA There was a media error.\r
67\r
68**/\r
69EFI_STATUS\r
70EFIAPI\r
71EfiDhcp6Start (\r
72 IN EFI_DHCP6_PROTOCOL *This\r
73 )\r
74{\r
75 EFI_STATUS Status;\r
76 EFI_TPL OldTpl;\r
77 DHCP6_INSTANCE *Instance;\r
78 DHCP6_SERVICE *Service;\r
79\r
80 if (This == NULL) {\r
81 return EFI_INVALID_PARAMETER;\r
82 }\r
83\r
84 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
85 Service = Instance->Service;\r
86\r
87 //\r
88 // The instance hasn't been configured.\r
89 //\r
90 if (Instance->Config == NULL) {\r
91 return EFI_ACCESS_DENIED;\r
92 }\r
93\r
94 ASSERT (Instance->IaCb.Ia != NULL);\r
95\r
96 //\r
97 // The instance has already been started.\r
98 //\r
99 if (Instance->IaCb.Ia->State != Dhcp6Init) {\r
100 return EFI_ALREADY_STARTED;\r
101 }\r
102\r
103 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
104 Instance->UdpSts = EFI_ALREADY_STARTED;\r
105\r
106 //\r
107 // Need to clear initial time to make sure that elapsed-time\r
108 // is set to 0 for first Solicit.\r
109 //\r
110 Instance->StartTime = 0;\r
111\r
112 //\r
113 // Send the solicit message to start S.A.R.R process.\r
114 //\r
115 Status = Dhcp6SendSolicitMsg (Instance);\r
116\r
117 if (EFI_ERROR (Status)) {\r
118 goto ON_ERROR;\r
119 }\r
120\r
121 //\r
122 // Register receive callback for the stateful exchange process.\r
123 //\r
124 Status = UdpIoRecvDatagram(\r
125 Service->UdpIo,\r
126 Dhcp6ReceivePacket,\r
127 Service,\r
128 0\r
129 );\r
130\r
131 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
132 goto ON_ERROR;\r
133 }\r
134\r
135 gBS->RestoreTPL (OldTpl);\r
136\r
137 //\r
138 // Poll udp out of the net tpl if synchronous call.\r
139 //\r
140 if (Instance->Config->IaInfoEvent == NULL) {\r
141\r
142 while (Instance->UdpSts == EFI_ALREADY_STARTED) {\r
143 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);\r
144 }\r
145 return Instance->UdpSts;\r
146 }\r
147\r
148 return EFI_SUCCESS;\r
149\r
150ON_ERROR:\r
151\r
152 gBS->RestoreTPL (OldTpl);\r
153 return Status;\r
154}\r
155\r
156\r
157/**\r
158 Stops the DHCPv6 standard S.A.R.R. process.\r
159\r
160 The Stop() function is used to stop the DHCPv6 standard process. After this\r
161 function is called successfully, the state of Dhcp6 instance is transferred\r
162 into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called\r
163 before DHCPv6 standard process can be started again. This function can be\r
164 called when the Dhcp6 instance is in any state.\r
165\r
166 @param[in] This The pointer to the Dhcp6 protocol.\r
167\r
168 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.\r
169 @retval EFI_INVALID_PARAMETER This is NULL.\r
170\r
171**/\r
172EFI_STATUS\r
173EFIAPI\r
174EfiDhcp6Stop (\r
175 IN EFI_DHCP6_PROTOCOL *This\r
176 )\r
177{\r
178 EFI_TPL OldTpl;\r
179 EFI_STATUS Status;\r
180 EFI_UDP6_PROTOCOL *Udp6;\r
181 DHCP6_INSTANCE *Instance;\r
182 DHCP6_SERVICE *Service;\r
183\r
184 if (This == NULL) {\r
185 return EFI_INVALID_PARAMETER;\r
186 }\r
187\r
188 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
189 Service = Instance->Service;\r
190 Udp6 = Service->UdpIo->Protocol.Udp6;\r
191 Status = EFI_SUCCESS;\r
192\r
193 //\r
194 // The instance hasn't been configured.\r
195 //\r
196 if (Instance->Config == NULL) {\r
197 return Status;\r
198 }\r
199\r
200 ASSERT (Instance->IaCb.Ia != NULL);\r
201\r
202 //\r
ed2bfecb 203 // No valid REPLY message received yet, cleanup this instance directly.\r
a3bcde70
HT
204 //\r
205 if (Instance->IaCb.Ia->State == Dhcp6Init ||\r
206 Instance->IaCb.Ia->State == Dhcp6Selecting ||\r
207 Instance->IaCb.Ia->State == Dhcp6Requesting\r
208 ) {\r
ed2bfecb 209 goto ON_EXIT;\r
a3bcde70
HT
210 }\r
211\r
212 //\r
213 // Release the current ready Ia.\r
214 //\r
215 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
216\r
217 Instance->UdpSts = EFI_ALREADY_STARTED;\r
ed2bfecb 218 Status = Dhcp6SendReleaseMsg (Instance, Instance->IaCb.Ia);\r
216f7970 219 gBS->RestoreTPL (OldTpl);\r
ed2bfecb 220 if (EFI_ERROR (Status)) {\r
221 goto ON_EXIT;\r
222 }\r
a3bcde70 223\r
a3bcde70
HT
224 //\r
225 // Poll udp out of the net tpl if synchoronus call.\r
226 //\r
227 if (Instance->Config->IaInfoEvent == NULL) {\r
228 ASSERT (Udp6 != NULL);\r
229 while (Instance->UdpSts == EFI_ALREADY_STARTED) {\r
230 Udp6->Poll (Udp6);\r
231 }\r
232 Status = Instance->UdpSts;\r
233 }\r
ed2bfecb 234 \r
235ON_EXIT:\r
a3bcde70
HT
236 //\r
237 // Clean up the session data for the released Ia.\r
238 //\r
239 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
240 Dhcp6CleanupSession (Instance, EFI_SUCCESS);\r
241 gBS->RestoreTPL (OldTpl);\r
242\r
243 return Status;\r
244}\r
245\r
246\r
247/**\r
248 Returns the current operating mode data for the Dhcp6 instance.\r
249\r
250 The GetModeData() function returns the current operating mode and\r
251 cached data packet for the Dhcp6 instance.\r
252\r
253 @param[in] This The pointer to the Dhcp6 protocol.\r
254 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.\r
255 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.\r
256\r
257 @retval EFI_SUCCESS The mode data was returned.\r
258 @retval EFI_INVALID_PARAMETER This is NULL.\r
259 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not\r
260 configured.\r
261**/\r
262EFI_STATUS\r
263EFIAPI\r
264EfiDhcp6GetModeData (\r
265 IN EFI_DHCP6_PROTOCOL *This,\r
266 OUT EFI_DHCP6_MODE_DATA *Dhcp6ModeData OPTIONAL,\r
267 OUT EFI_DHCP6_CONFIG_DATA *Dhcp6ConfigData OPTIONAL\r
268 )\r
269{\r
270 EFI_TPL OldTpl;\r
271 EFI_DHCP6_IA *Ia;\r
272 DHCP6_INSTANCE *Instance;\r
273 DHCP6_SERVICE *Service;\r
274 UINT32 IaSize;\r
275 UINT32 IdSize;\r
276\r
277 if (This == NULL || (Dhcp6ModeData == NULL && Dhcp6ConfigData == NULL)) {\r
278 return EFI_INVALID_PARAMETER;\r
279 }\r
280\r
281 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
282 Service = Instance->Service;\r
283\r
284 if (Instance->Config == NULL && Dhcp6ConfigData != NULL) {\r
285 return EFI_ACCESS_DENIED;\r
286 }\r
287\r
288 ASSERT (Service->ClientId != NULL);\r
289\r
290 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
291\r
292 //\r
293 // User needs a copy of instance config data.\r
294 //\r
295 if (Dhcp6ConfigData != NULL) {\r
296 ZeroMem (Dhcp6ConfigData, sizeof(EFI_DHCP6_CONFIG_DATA));\r
297 //\r
298 // Duplicate config data, including all reference buffers.\r
299 //\r
300 if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData, Instance->Config))) {\r
301 goto ON_ERROR;\r
302 }\r
303 }\r
304\r
305 //\r
306 // User need a copy of instance mode data.\r
307 //\r
308 if (Dhcp6ModeData != NULL) {\r
309 ZeroMem (Dhcp6ModeData, sizeof (EFI_DHCP6_MODE_DATA));\r
310 //\r
311 // Duplicate a copy of EFI_DHCP6_DUID for client Id.\r
312 //\r
313 IdSize = Service->ClientId->Length + sizeof (Service->ClientId->Length);\r
314\r
315 Dhcp6ModeData->ClientId = AllocateZeroPool (IdSize);\r
316 if (Dhcp6ModeData->ClientId == NULL) {\r
317 goto ON_ERROR;\r
318 }\r
319\r
320 CopyMem (\r
321 Dhcp6ModeData->ClientId,\r
322 Service->ClientId,\r
323 IdSize\r
324 );\r
325\r
326 Ia = Instance->IaCb.Ia;\r
327 if (Ia != NULL) {\r
328 //\r
329 // Duplicate a copy of EFI_DHCP6_IA for configured Ia.\r
330 //\r
331 IaSize = sizeof (EFI_DHCP6_IA) + (Ia->IaAddressCount -1) * sizeof (EFI_DHCP6_IA_ADDRESS);\r
332\r
333 Dhcp6ModeData->Ia = AllocateZeroPool (IaSize);\r
334 if (Dhcp6ModeData->Ia == NULL) {\r
335 goto ON_ERROR;\r
336 }\r
337\r
338 CopyMem (\r
339 Dhcp6ModeData->Ia,\r
340 Ia,\r
341 IaSize\r
342 );\r
343\r
344 //\r
345 // Duplicate a copy of reply packet if has.\r
346 //\r
347 if (Ia->ReplyPacket != NULL) {\r
348 Dhcp6ModeData->Ia->ReplyPacket = AllocateZeroPool (Ia->ReplyPacket->Size);\r
349 if (Dhcp6ModeData->Ia->ReplyPacket == NULL) {\r
350 goto ON_ERROR;\r
351 }\r
352 CopyMem (\r
353 Dhcp6ModeData->Ia->ReplyPacket,\r
354 Ia->ReplyPacket,\r
355 Ia->ReplyPacket->Size\r
356 );\r
357 }\r
358 }\r
359 }\r
360\r
361 gBS->RestoreTPL (OldTpl);\r
362\r
363 return EFI_SUCCESS;\r
364\r
365ON_ERROR:\r
366\r
367 if (Dhcp6ConfigData != NULL) {\r
368 Dhcp6CleanupConfigData (Dhcp6ConfigData);\r
369 }\r
370 if (Dhcp6ModeData != NULL) {\r
371 Dhcp6CleanupModeData (Dhcp6ModeData);\r
372 }\r
373 gBS->RestoreTPL (OldTpl);\r
374\r
375 return EFI_OUT_OF_RESOURCES;\r
376}\r
377\r
378\r
379/**\r
380 Initializes, changes, or resets the operational settings for the Dhcp6 instance.\r
381\r
382 The Configure() function is used to initialize or clean up the configuration\r
383 data of the Dhcp6 instance:\r
384 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the\r
385 configuration data will be initialized in the Dhcp6 instance, and the state\r
386 of the configured IA will be transferred into Dhcp6Init.\r
387 - When Dhcp6CfgData is NULL and Configure() is called successfully, the\r
388 configuration data will be cleaned up and no IA will be associated with\r
389 the Dhcp6 instance.\r
390 To update the configuration data for an Dhcp6 instance, the original data\r
391 must be cleaned up before setting the new configuration data.\r
392\r
393 @param[in] This The pointer to the Dhcp6 protocol\r
394 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.\r
395\r
396 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the\r
397 Dhcp6Init state, or cleaned up the original\r
398 configuration setting.\r
399 @retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.\r
400 The Dhcp6 instance has already started the\r
401 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.\r
402 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.\r
403 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
404 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
405\r
406**/\r
407EFI_STATUS\r
408EFIAPI\r
409EfiDhcp6Configure (\r
410 IN EFI_DHCP6_PROTOCOL *This,\r
411 IN EFI_DHCP6_CONFIG_DATA *Dhcp6CfgData OPTIONAL\r
412 )\r
413{\r
414 EFI_TPL OldTpl;\r
415 EFI_STATUS Status;\r
416 LIST_ENTRY *Entry;\r
417 DHCP6_INSTANCE *Other;\r
418 DHCP6_INSTANCE *Instance;\r
419 DHCP6_SERVICE *Service;\r
420 UINTN Index;\r
421\r
422 if (This == NULL) {\r
423 return EFI_INVALID_PARAMETER;\r
424 }\r
425\r
426 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
427 Service = Instance->Service;\r
428\r
429 //\r
430 // Check the parameter of configure data.\r
431 //\r
432 if (Dhcp6CfgData != NULL) {\r
433 if (Dhcp6CfgData->OptionCount > 0 && Dhcp6CfgData->OptionList == NULL) {\r
434 return EFI_INVALID_PARAMETER;\r
435 }\r
436 if (Dhcp6CfgData->OptionList != NULL) {\r
437 for (Index = 0; Index < Dhcp6CfgData->OptionCount; Index++) {\r
438 if (Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptClientId ||\r
439 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptRapidCommit ||\r
440 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptReconfigureAccept ||\r
441 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptIana ||\r
442 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptIata\r
443 ) {\r
444 return EFI_INVALID_PARAMETER;\r
445 }\r
446 }\r
447 }\r
448\r
449 if (Dhcp6CfgData->IaDescriptor.Type != EFI_DHCP6_IA_TYPE_NA &&\r
450 Dhcp6CfgData->IaDescriptor.Type != EFI_DHCP6_IA_TYPE_TA\r
451 ) {\r
452 return EFI_INVALID_PARAMETER;\r
453 }\r
454\r
455 if (Dhcp6CfgData->IaInfoEvent == NULL && Dhcp6CfgData->SolicitRetransmission == NULL) {\r
456 return EFI_INVALID_PARAMETER;\r
457 }\r
458\r
459 if (Dhcp6CfgData->SolicitRetransmission != NULL &&\r
460 Dhcp6CfgData->SolicitRetransmission->Mrc == 0 &&\r
461 Dhcp6CfgData->SolicitRetransmission->Mrd == 0\r
462 ) {\r
463 return EFI_INVALID_PARAMETER;\r
464 }\r
465\r
466 //\r
467 // Make sure the (IaId, IaType) is unique over all the instances.\r
468 //\r
469 NET_LIST_FOR_EACH (Entry, &Service->Child) {\r
470 Other = NET_LIST_USER_STRUCT (Entry, DHCP6_INSTANCE, Link);\r
471 if (Other->IaCb.Ia != NULL &&\r
472 Other->IaCb.Ia->Descriptor.Type == Dhcp6CfgData->IaDescriptor.Type &&\r
473 Other->IaCb.Ia->Descriptor.IaId == Dhcp6CfgData->IaDescriptor.IaId\r
474 ) {\r
475 return EFI_INVALID_PARAMETER;\r
476 }\r
477 }\r
478 }\r
479\r
480 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
481\r
482 if (Dhcp6CfgData != NULL) {\r
483 //\r
484 // It's not allowed to configure one instance twice without configure null.\r
485 //\r
486 if (Instance->Config != NULL) {\r
487 gBS->RestoreTPL (OldTpl);\r
488 return EFI_ACCESS_DENIED;\r
489 }\r
490\r
491 //\r
492 // Duplicate config data including all reference buffers.\r
493 //\r
494 Instance->Config = AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA));\r
495 if (Instance->Config == NULL) {\r
496 gBS->RestoreTPL (OldTpl);\r
497 return EFI_OUT_OF_RESOURCES;\r
498 }\r
499\r
500 Status = Dhcp6CopyConfigData (Instance->Config, Dhcp6CfgData);\r
501 if (EFI_ERROR(Status)) {\r
502 FreePool (Instance->Config);\r
503 gBS->RestoreTPL (OldTpl);\r
504 return EFI_OUT_OF_RESOURCES;\r
505 }\r
506\r
507 //\r
508 // Initialize the Ia descriptor from the config data, and leave the other\r
509 // fields of the Ia as default value 0.\r
510 //\r
511 Instance->IaCb.Ia = AllocateZeroPool (sizeof(EFI_DHCP6_IA));\r
512 if (Instance->IaCb.Ia == NULL) {\r
513 Dhcp6CleanupConfigData (Instance->Config);\r
514 FreePool (Instance->Config);\r
515 gBS->RestoreTPL (OldTpl);\r
516 return EFI_OUT_OF_RESOURCES;\r
517 }\r
518 CopyMem (\r
519 &Instance->IaCb.Ia->Descriptor,\r
520 &Dhcp6CfgData->IaDescriptor,\r
521 sizeof(EFI_DHCP6_IA_DESCRIPTOR)\r
522 );\r
523\r
524 } else {\r
525\r
526 if (Instance->Config == NULL) {\r
527 ASSERT (Instance->IaCb.Ia == NULL);\r
528 gBS->RestoreTPL (OldTpl);\r
529 return EFI_SUCCESS;\r
530 }\r
531\r
532 //\r
533 // It's not allowed to configure a started instance as null.\r
534 //\r
535 if (Instance->IaCb.Ia->State != Dhcp6Init) {\r
536 gBS->RestoreTPL (OldTpl);\r
537 return EFI_ACCESS_DENIED;\r
538 }\r
539\r
540 Dhcp6CleanupConfigData (Instance->Config);\r
541 FreePool (Instance->Config);\r
542 Instance->Config = NULL;\r
543\r
544 FreePool (Instance->IaCb.Ia);\r
545 Instance->IaCb.Ia = NULL;\r
546 }\r
547\r
548 gBS->RestoreTPL (OldTpl);\r
549\r
550 return EFI_SUCCESS;\r
551}\r
552\r
553\r
554/**\r
555 Request configuration information without the assignment of any\r
556 Ia addresses of the client.\r
557\r
558 The InfoRequest() function is used to request configuration information\r
559 without the assignment of any IPv6 address of the client. The client sends\r
560 out an Information Request packet to obtain the required configuration\r
561 information, and DHCPv6 server responds with a Reply packet containing\r
562 the information for the client. The received Reply packet will be passed\r
563 to the user by ReplyCallback function. If the user returns EFI_NOT_READY from\r
564 ReplyCallback, the Dhcp6 instance will continue to receive other Reply\r
565 packets unless timeout according to the Retransmission parameter.\r
566 Otherwise, the Information Request exchange process will be finished\r
567 successfully if user returns EFI_SUCCESS from ReplyCallback.\r
568\r
569 @param[in] This The pointer to the Dhcp6 protocol.\r
570 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client\r
571 Identifier option and include it into Information Request\r
572 packet. Otherwise, Client Identifier option will not be included.\r
573 @param[in] OptionRequest The pointer to the buffer of option request options.\r
574 @param[in] OptionCount The option number in the OptionList.\r
575 @param[in] OptionList The list of appended options.\r
576 @param[in] Retransmission The pointer to the retransmission of the message.\r
577 @param[in] TimeoutEvent The event of timeout.\r
578 @param[in] ReplyCallback The callback function when the reply was received.\r
579 @param[in] CallbackContext The pointer to the parameter passed to the callback.\r
580\r
581 @retval EFI_SUCCESS The DHCPv6 information request exchange process\r
582 completed when TimeoutEvent is NULL. Information\r
583 Request packet has been sent to DHCPv6 server when\r
584 TimeoutEvent is not NULL.\r
585 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed\r
586 because of no response, or not all requested-options\r
587 are responded by DHCPv6 servers when Timeout happened.\r
588 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted\r
589 by user.\r
590 @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r
591 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
592 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
593\r
594**/\r
595EFI_STATUS\r
596EFIAPI\r
597EfiDhcp6InfoRequest (\r
598 IN EFI_DHCP6_PROTOCOL *This,\r
599 IN BOOLEAN SendClientId,\r
600 IN EFI_DHCP6_PACKET_OPTION *OptionRequest,\r
601 IN UINT32 OptionCount,\r
602 IN EFI_DHCP6_PACKET_OPTION *OptionList[] OPTIONAL,\r
603 IN EFI_DHCP6_RETRANSMISSION *Retransmission,\r
604 IN EFI_EVENT TimeoutEvent OPTIONAL,\r
605 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback,\r
606 IN VOID *CallbackContext OPTIONAL\r
607 )\r
608{\r
609 EFI_STATUS Status;\r
a3bcde70
HT
610 DHCP6_INSTANCE *Instance;\r
611 DHCP6_SERVICE *Service;\r
a3bcde70 612 UINTN Index;\r
cc658224 613 EFI_EVENT Timer;\r
614 EFI_STATUS TimerStatus;\r
615 UINTN GetMappingTimeOut;\r
a3bcde70
HT
616\r
617 if (This == NULL || OptionRequest == NULL || Retransmission == NULL || ReplyCallback == NULL) {\r
618 return EFI_INVALID_PARAMETER;\r
619 }\r
620\r
621 if (Retransmission != NULL && Retransmission->Mrc == 0 && Retransmission->Mrd == 0) {\r
622 return EFI_INVALID_PARAMETER;\r
623 }\r
624\r
625 if (OptionCount > 0 && OptionList == NULL) {\r
626 return EFI_INVALID_PARAMETER;\r
627 }\r
628\r
629 if (OptionList != NULL) {\r
630 for (Index = 0; Index < OptionCount; Index++) {\r
631 if (OptionList[Index]->OpCode == Dhcp6OptClientId || OptionList[Index]->OpCode == Dhcp6OptRequestOption) {\r
632 return EFI_INVALID_PARAMETER;\r
633 }\r
634 }\r
635 }\r
636\r
637 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
638 Service = Instance->Service;\r
639\r
cc658224 640 Status = Dhcp6StartInfoRequest (\r
a3bcde70 641 Instance,\r
a3bcde70
HT
642 SendClientId,\r
643 OptionRequest,\r
644 OptionCount,\r
645 OptionList,\r
cc658224 646 Retransmission,\r
647 TimeoutEvent,\r
648 ReplyCallback,\r
649 CallbackContext\r
a3bcde70 650 );\r
cc658224 651 if (Status == EFI_NO_MAPPING) {\r
652 //\r
653 // The link local address is not ready, wait for some time and restart\r
654 // the DHCP6 information request process.\r
655 //\r
656 Status = Dhcp6GetMappingTimeOut(Service->Ip6Cfg, &GetMappingTimeOut);\r
657 if (EFI_ERROR(Status)) {\r
658 return Status;\r
659 }\r
a3bcde70 660\r
cc658224 661 Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer);\r
662 if (EFI_ERROR (Status)) {\r
663 return Status;\r
664 }\r
a3bcde70 665\r
cc658224 666 //\r
667 // Start the timer, wait for link local address DAD to finish.\r
668 //\r
669 Status = gBS->SetTimer (Timer, TimerRelative, GetMappingTimeOut);\r
670 if (EFI_ERROR (Status)) {\r
671 gBS->CloseEvent (Timer);\r
672 return Status;\r
673 }\r
a3bcde70 674\r
cc658224 675 do { \r
676 TimerStatus = gBS->CheckEvent (Timer);\r
677 if (!EFI_ERROR (TimerStatus)) {\r
678 Status = Dhcp6StartInfoRequest (\r
679 Instance,\r
680 SendClientId,\r
681 OptionRequest,\r
682 OptionCount,\r
683 OptionList,\r
684 Retransmission,\r
685 TimeoutEvent,\r
686 ReplyCallback,\r
687 CallbackContext\r
688 );\r
689 }\r
690 } while (TimerStatus == EFI_NOT_READY);\r
691 \r
692 gBS->CloseEvent (Timer);\r
693 }\r
694 if (EFI_ERROR (Status)) {\r
695 return Status;\r
a3bcde70 696 }\r
a3bcde70
HT
697\r
698 //\r
699 // Poll udp out of the net tpl if synchoronus call.\r
700 //\r
701 if (TimeoutEvent == NULL) {\r
702\r
703 while (Instance->UdpSts == EFI_ALREADY_STARTED) {\r
704 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);\r
705 }\r
706 return Instance->UdpSts;\r
707 }\r
708\r
709 return EFI_SUCCESS;\r
a3bcde70
HT
710}\r
711\r
712\r
713/**\r
714 Manually extend the valid and preferred lifetimes for the IPv6 addresses\r
715 of the configured IA and update other configuration parameters by sending a\r
716 Renew or Rebind packet.\r
717\r
718 The RenewRebind() function is used to manually extend the valid and preferred\r
719 lifetimes for the IPv6 addresses of the configured IA, and update other\r
720 configuration parameters by sending Renew or Rebind packet.\r
721 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,\r
722 it sends Renew packet to the previously DHCPv6 server and transfer the\r
723 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,\r
724 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.\r
725 If fails, the state transfers to Dhcp6Bound, but the timer continues.\r
726 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,\r
727 it will send a Rebind packet. If valid Reply packet is received, the state transfers\r
728 to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state\r
729 transfers to Dhcp6Init, and the IA can't be used.\r
730\r
731 @param[in] This The pointer to the Dhcp6 protocol.\r
732 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.\r
733 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.\r
734\r
735 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has\r
736 completed and at least one IPv6 address of the\r
737 configured IA has been bound again when\r
738 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.\r
739 The EFI DHCPv6 Protocol instance has sent Renew\r
740 or Rebind packet when\r
741 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.\r
742 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the\r
743 state of the configured IA is not in Dhcp6Bound.\r
744 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered\r
745 Dhcp6Renewing when RebindRequest is FALSE.\r
746 The state of the configured IA has already entered\r
747 Dhcp6Rebinding when RebindRequest is TRUE.\r
748 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted\r
749 by the user.\r
750 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed\r
751 because of no response.\r
752 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured\r
753 IA after the DHCPv6 renew/rebind exchange process.\r
754 @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r
755 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
756\r
757**/\r
758EFI_STATUS\r
759EFIAPI\r
760EfiDhcp6RenewRebind (\r
761 IN EFI_DHCP6_PROTOCOL *This,\r
762 IN BOOLEAN RebindRequest\r
763 )\r
764{\r
765 EFI_STATUS Status;\r
766 EFI_TPL OldTpl;\r
767 DHCP6_INSTANCE *Instance;\r
768 DHCP6_SERVICE *Service;\r
769\r
770 if (This == NULL) {\r
771 return EFI_INVALID_PARAMETER;\r
772 }\r
773\r
774 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
775 Service = Instance->Service;\r
776\r
777 //\r
778 // The instance hasn't been configured.\r
779 //\r
780 if (Instance->Config == NULL) {\r
781 return EFI_ACCESS_DENIED;\r
782 }\r
783\r
784 ASSERT (Instance->IaCb.Ia != NULL);\r
785\r
786 //\r
787 // The instance has already entered renewing or rebinding state.\r
788 //\r
789 if ((Instance->IaCb.Ia->State == Dhcp6Rebinding && RebindRequest) ||\r
790 (Instance->IaCb.Ia->State == Dhcp6Renewing && !RebindRequest)\r
791 ) {\r
792 return EFI_ALREADY_STARTED;\r
793 }\r
794\r
795 if (Instance->IaCb.Ia->State != Dhcp6Bound) {\r
796 return EFI_ACCESS_DENIED;\r
797 }\r
798\r
799 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
800 Instance->UdpSts = EFI_ALREADY_STARTED;\r
801\r
802 //\r
803 // Send renew/rebind message to start exchange process.\r
804 //\r
805 Status = Dhcp6SendRenewRebindMsg (Instance, RebindRequest);\r
806\r
807 if (EFI_ERROR (Status)) {\r
808 goto ON_ERROR;\r
809 }\r
810\r
811 //\r
812 // Register receive callback for the stateful exchange process.\r
813 //\r
814 Status = UdpIoRecvDatagram(\r
815 Service->UdpIo,\r
816 Dhcp6ReceivePacket,\r
817 Service,\r
818 0\r
819 );\r
820\r
821 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
822 goto ON_ERROR;\r
823 }\r
824\r
825 gBS->RestoreTPL (OldTpl);\r
826\r
827 //\r
828 // Poll udp out of the net tpl if synchoronus call.\r
829 //\r
830 if (Instance->Config->IaInfoEvent == NULL) {\r
831\r
832 while (Instance->UdpSts == EFI_ALREADY_STARTED) {\r
833 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);\r
834 }\r
835 return Instance->UdpSts;\r
836 }\r
837\r
838 return EFI_SUCCESS;\r
839\r
840ON_ERROR:\r
841\r
842 gBS->RestoreTPL (OldTpl);\r
843 return Status;\r
844}\r
845\r
846\r
847/**\r
848 Inform that one or more addresses assigned by a server are already\r
849 in use by another node.\r
850\r
851 The Decline() function is used to manually decline the assignment of\r
852 IPv6 addresses, which have been already used by another node. If all\r
853 IPv6 addresses of the configured IA are declined through this function,\r
854 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.\r
855 Otherwise, the state of the IA will restore to Dhcp6Bound after the\r
856 declining process. The Decline() can only be called when the IA is in\r
857 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,\r
858 this function is a blocking operation. It will return after the\r
859 declining process finishes, or aborted by user.\r
860\r
861 @param[in] This The pointer to EFI_DHCP6_PROTOCOL.\r
862 @param[in] AddressCount The number of declining addresses.\r
863 @param[in] Addresses The pointer to the buffer stored the declining\r
864 addresses.\r
865\r
866 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed\r
867 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.\r
868 The Dhcp6 instance sent Decline packet when\r
869 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.\r
870 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the\r
871 state of the configured IA is not in Dhcp6Bound.\r
872 @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.\r
873 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with\r
874 the configured IA for this instance.\r
875 @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r
876 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
877\r
878**/\r
879EFI_STATUS\r
880EFIAPI\r
881EfiDhcp6Decline (\r
882 IN EFI_DHCP6_PROTOCOL *This,\r
883 IN UINT32 AddressCount,\r
884 IN EFI_IPv6_ADDRESS *Addresses\r
885 )\r
886{\r
887 EFI_STATUS Status;\r
888 EFI_TPL OldTpl;\r
889 EFI_DHCP6_IA *DecIa;\r
890 DHCP6_INSTANCE *Instance;\r
891 DHCP6_SERVICE *Service;\r
892\r
893 if (This == NULL || AddressCount == 0 || Addresses == NULL) {\r
894 return EFI_INVALID_PARAMETER;\r
895 }\r
896\r
897 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
898 Service = Instance->Service;\r
899\r
900 //\r
901 // The instance hasn't been configured.\r
902 //\r
903 if (Instance->Config == NULL) {\r
904 return EFI_ACCESS_DENIED;\r
905 }\r
906\r
907 ASSERT (Instance->IaCb.Ia != NULL);\r
908\r
909 if (Instance->IaCb.Ia->State != Dhcp6Bound) {\r
910 return EFI_ACCESS_DENIED;\r
911 }\r
912\r
913 //\r
914 // Check whether all the declined addresses belongs to the configured Ia.\r
915 //\r
916 Status = Dhcp6CheckAddress (Instance->IaCb.Ia, AddressCount, Addresses);\r
917\r
918 if (EFI_ERROR(Status)) {\r
919 return Status;\r
920 }\r
921\r
922 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
923 Instance->UdpSts = EFI_ALREADY_STARTED;\r
924\r
925 //\r
926 // Deprive of all the declined addresses from the configured Ia, and create a\r
927 // DeclineIa used to create decline message.\r
928 //\r
929 DecIa = Dhcp6DepriveAddress (Instance->IaCb.Ia, AddressCount, Addresses);\r
930\r
931 if (DecIa == NULL) {\r
932 Status = EFI_OUT_OF_RESOURCES;\r
933 goto ON_ERROR;\r
934 }\r
935\r
936 //\r
937 // Send the decline message to start exchange process.\r
938 //\r
939 Status = Dhcp6SendDeclineMsg (Instance, DecIa);\r
940\r
941 if (EFI_ERROR (Status)) {\r
942 goto ON_ERROR;\r
943 }\r
944\r
945 //\r
946 // Register receive callback for the stateful exchange process.\r
947 //\r
948 Status = UdpIoRecvDatagram(\r
949 Service->UdpIo,\r
950 Dhcp6ReceivePacket,\r
951 Service,\r
952 0\r
953 );\r
954\r
955 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
956 goto ON_ERROR;\r
957 }\r
958\r
959 FreePool (DecIa);\r
960 gBS->RestoreTPL (OldTpl);\r
961\r
962 //\r
963 // Poll udp out of the net tpl if synchoronus call.\r
964 //\r
965 if (Instance->Config->IaInfoEvent == NULL) {\r
966\r
967 while (Instance->UdpSts == EFI_ALREADY_STARTED) {\r
968 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);\r
969 }\r
970 return Instance->UdpSts;\r
971 }\r
972\r
973 return EFI_SUCCESS;\r
974\r
975ON_ERROR:\r
976\r
977 if (DecIa != NULL) {\r
978 FreePool (DecIa);\r
979 }\r
980 gBS->RestoreTPL (OldTpl);\r
981\r
982 return Status;\r
983}\r
984\r
985\r
986/**\r
987 Release one or more addresses associated with the configured Ia\r
988 for current instance.\r
989\r
990 The Release() function is used to manually release one or more\r
991 IPv6 addresses. If AddressCount is zero, it will release all IPv6\r
992 addresses of the configured IA. If all IPv6 addresses of the IA are\r
993 released through this function, the state of the IA will switch\r
994 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the\r
995 IA will restore to Dhcp6Bound after the releasing process.\r
996 The Release() can only be called when the IA is in Dhcp6Bound state.\r
997 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is\r
998 a blocking operation. It will return after the releasing process\r
999 finishes, or is aborted by user.\r
1000\r
1001 @param[in] This The pointer to the Dhcp6 protocol.\r
1002 @param[in] AddressCount The number of releasing addresses.\r
1003 @param[in] Addresses The pointer to the buffer stored the releasing\r
1004 addresses.\r
1005\r
1006 @retval EFI_SUCCESS The DHCPv6 release exchange process\r
1007 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent\r
1008 was NULL. The Dhcp6 instance was sent Release\r
1009 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent\r
1010 was not NULL.\r
1011 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the\r
1012 state of the configured IA is not in Dhcp6Bound.\r
1013 @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.\r
1014 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with\r
1015 the configured IA for this instance.\r
1016 @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r
1017 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
1018\r
1019**/\r
1020EFI_STATUS\r
1021EFIAPI\r
1022EfiDhcp6Release (\r
1023 IN EFI_DHCP6_PROTOCOL *This,\r
1024 IN UINT32 AddressCount,\r
1025 IN EFI_IPv6_ADDRESS *Addresses\r
1026 )\r
1027{\r
1028 EFI_STATUS Status;\r
1029 EFI_TPL OldTpl;\r
1030 EFI_DHCP6_IA *RelIa;\r
1031 DHCP6_INSTANCE *Instance;\r
1032 DHCP6_SERVICE *Service;\r
1033\r
1034 if (This == NULL || (AddressCount != 0 && Addresses == NULL)) {\r
1035 return EFI_INVALID_PARAMETER;\r
1036 }\r
1037\r
1038 Instance = DHCP6_INSTANCE_FROM_THIS (This);\r
1039 Service = Instance->Service;\r
1040\r
1041 //\r
1042 // The instance hasn't been configured.\r
1043 //\r
1044 if (Instance->Config == NULL) {\r
1045 return EFI_ACCESS_DENIED;\r
1046 }\r
1047\r
1048 ASSERT (Instance->IaCb.Ia != NULL);\r
1049\r
1050 if (Instance->IaCb.Ia->State != Dhcp6Bound) {\r
1051 return EFI_ACCESS_DENIED;\r
1052 }\r
1053\r
1054 //\r
1055 // Check whether all the released addresses belongs to the configured Ia.\r
1056 //\r
1057 Status = Dhcp6CheckAddress (Instance->IaCb.Ia, AddressCount, Addresses);\r
1058\r
1059 if (EFI_ERROR(Status)) {\r
1060 return Status;\r
1061 }\r
1062\r
1063 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
1064 Instance->UdpSts = EFI_ALREADY_STARTED;\r
1065\r
1066 //\r
1067 // Deprive of all the released addresses from the configured Ia, and create a\r
1068 // ReleaseIa used to create release message.\r
1069 //\r
1070 RelIa = Dhcp6DepriveAddress (Instance->IaCb.Ia, AddressCount, Addresses);\r
1071\r
1072 if (RelIa == NULL) {\r
1073 Status = EFI_OUT_OF_RESOURCES;\r
1074 goto ON_ERROR;\r
1075 }\r
1076\r
1077 //\r
1078 // Send the release message to start exchange process.\r
1079 //\r
1080 Status = Dhcp6SendReleaseMsg (Instance, RelIa);\r
1081\r
1082 if (EFI_ERROR (Status)) {\r
1083 goto ON_ERROR;\r
1084 }\r
1085\r
1086 //\r
1087 // Register receive callback for the stateful exchange process.\r
1088 //\r
1089 Status = UdpIoRecvDatagram(\r
1090 Service->UdpIo,\r
1091 Dhcp6ReceivePacket,\r
1092 Service,\r
1093 0\r
1094 );\r
1095\r
1096 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
1097 goto ON_ERROR;\r
1098 }\r
1099\r
1100 FreePool (RelIa);\r
1101 gBS->RestoreTPL (OldTpl);\r
1102\r
1103 //\r
1104 // Poll udp out of the net tpl if synchoronus call.\r
1105 //\r
1106 if (Instance->Config->IaInfoEvent == NULL) {\r
1107 while (Instance->UdpSts == EFI_ALREADY_STARTED) {\r
1108 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);\r
1109 }\r
1110 return Instance->UdpSts;\r
1111 }\r
1112\r
1113 return EFI_SUCCESS;\r
1114\r
1115ON_ERROR:\r
1116\r
1117 if (RelIa != NULL) {\r
1118 FreePool (RelIa);\r
1119 }\r
1120 gBS->RestoreTPL (OldTpl);\r
1121\r
1122 return Status;\r
1123}\r
1124\r
1125\r
1126/**\r
1127 Parse the option data in the Dhcp6 packet.\r
1128\r
1129 The Parse() function is used to retrieve the option list in the DHCPv6 packet.\r
1130\r
1131 @param[in] This The pointer to the Dhcp6 protocol.\r
1132 @param[in] Packet The pointer to the Dhcp6 packet.\r
1133 @param[in, out] OptionCount The number of option in the packet.\r
1134 @param[out] PacketOptionList The array of pointers to each option in the packet.\r
1135\r
1136 @retval EFI_SUCCESS The packet was successfully parsed.\r
1137 @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r
1138 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options\r
1139 that were found in the Packet.\r
1140\r
1141**/\r
1142EFI_STATUS\r
1143EFIAPI\r
1144EfiDhcp6Parse (\r
1145 IN EFI_DHCP6_PROTOCOL *This,\r
1146 IN EFI_DHCP6_PACKET *Packet,\r
1147 IN OUT UINT32 *OptionCount,\r
1148 OUT EFI_DHCP6_PACKET_OPTION *PacketOptionList[] OPTIONAL\r
1149 )\r
1150{\r
1151 UINT32 OptCnt;\r
1152 UINT32 OptLen;\r
1153 UINT16 DataLen;\r
1154 UINT8 *Start;\r
1155 UINT8 *End;\r
1156\r
1157 if (This == NULL || Packet == NULL || OptionCount == NULL) {\r
1158 return EFI_INVALID_PARAMETER;\r
1159 }\r
1160\r
1161 if (*OptionCount != 0 && PacketOptionList == NULL) {\r
1162 return EFI_INVALID_PARAMETER;\r
1163 }\r
1164\r
1165 if (Packet->Length > Packet->Size || Packet->Length < sizeof (EFI_DHCP6_HEADER)) {\r
1166 return EFI_INVALID_PARAMETER;\r
1167 }\r
1168\r
1169 //\r
1170 // The format of Dhcp6 option:\r
1171 //\r
1172 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\r
1173 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
1174 // | option-code | option-len (option data) |\r
1175 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
1176 // | option-data |\r
1177 // | (option-len octets) |\r
1178 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
1179 //\r
1180\r
1181 OptCnt = 0;\r
1182 OptLen = Packet->Length - sizeof (EFI_DHCP6_HEADER);\r
1183 Start = Packet->Dhcp6.Option;\r
1184 End = Start + OptLen;\r
1185\r
1186 //\r
1187 // Calculate the number of option in the packet.\r
1188 //\r
1189 while (Start < End) {\r
1190 DataLen = ((EFI_DHCP6_PACKET_OPTION *) Start)->OpLen;\r
1191 Start += (NTOHS (DataLen) + 4);\r
1192 OptCnt++;\r
1193 }\r
1194\r
1195 //\r
1196 // It will return buffer too small if pass-in option count is smaller than the\r
1197 // actual count of options in the packet.\r
1198 //\r
1199 if (OptCnt > *OptionCount) {\r
1200 *OptionCount = OptCnt;\r
1201 return EFI_BUFFER_TOO_SMALL;\r
1202 }\r
1203\r
1204 ZeroMem (\r
1205 PacketOptionList,\r
1206 (*OptionCount * sizeof (EFI_DHCP6_PACKET_OPTION *))\r
1207 );\r
1208\r
1209 OptCnt = 0;\r
1210 Start = Packet->Dhcp6.Option;\r
1211\r
1212 while (Start < End) {\r
1213\r
1214 PacketOptionList[OptCnt] = (EFI_DHCP6_PACKET_OPTION *) Start;\r
1215 DataLen = ((EFI_DHCP6_PACKET_OPTION *) Start)->OpLen;\r
1216 Start += (NTOHS (DataLen) + 4);\r
1217 OptCnt++;\r
1218 }\r
1219\r
1220 return EFI_SUCCESS;\r
1221}\r
1222\r