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