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