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