2 This EFI_DHCP6_PROTOCOL interface implementation.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "Dhcp6Impl.h"
13 // Well-known multi-cast address defined in section-24.1 of rfc-3315
15 // ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2
17 EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress
= {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};
19 EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate
= {
32 Starts the DHCPv6 standard S.A.R.R. process.
34 The Start() function starts the DHCPv6 standard process. This function can
35 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
36 If the DHCP process completes successfully, the state of the Dhcp6 instance
37 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
39 Refer to rfc-3315 for precise state transitions during this process. At the
40 time when each event occurs in this process, the callback function that was set
41 by EFI_DHCP6_PROTOCOL.Configure() will be called, and the user can take this
42 opportunity to control the process.
44 @param[in] This The pointer to Dhcp6 protocol.
46 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it has
47 completed when CompletionEvent is NULL.
48 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
49 @retval EFI_INVALID_PARAMETER This is NULL.
50 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
51 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
52 response was received from the server within the
53 specified timeout value.
54 @retval EFI_ABORTED The user aborted the DHCPv6 process.
55 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
57 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
58 @retval EFI_NO_MEDIA There was a media error.
64 IN EFI_DHCP6_PROTOCOL
*This
69 DHCP6_INSTANCE
*Instance
;
70 DHCP6_SERVICE
*Service
;
71 EFI_STATUS MediaStatus
;
74 return EFI_INVALID_PARAMETER
;
77 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
78 Service
= Instance
->Service
;
81 // The instance hasn't been configured.
83 if (Instance
->Config
== NULL
) {
84 return EFI_ACCESS_DENIED
;
87 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
90 // The instance has already been started.
92 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
93 return EFI_ALREADY_STARTED
;
96 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
99 // Check Media Status.
101 MediaStatus
= EFI_SUCCESS
;
102 NetLibDetectMediaWaitTimeout (Service
->Controller
, DHCP_CHECK_MEDIA_WAITING_TIME
, &MediaStatus
);
103 if (MediaStatus
!= EFI_SUCCESS
) {
104 Status
= EFI_NO_MEDIA
;
108 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
111 // Send the solicit message to start S.A.R.R process.
113 Status
= Dhcp6SendSolicitMsg (Instance
);
115 if (EFI_ERROR (Status
)) {
120 // Register receive callback for the stateful exchange process.
122 Status
= UdpIoRecvDatagram(
129 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
133 gBS
->RestoreTPL (OldTpl
);
136 // Poll udp out of the net tpl if synchronous call.
138 if (Instance
->Config
->IaInfoEvent
== NULL
) {
140 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
141 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
143 return Instance
->UdpSts
;
150 gBS
->RestoreTPL (OldTpl
);
156 Stops the DHCPv6 standard S.A.R.R. process.
158 The Stop() function is used to stop the DHCPv6 standard process. After this
159 function is called successfully, the state of Dhcp6 instance is transferred
160 into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
161 before DHCPv6 standard process can be started again. This function can be
162 called when the Dhcp6 instance is in any state.
164 @param[in] This The pointer to the Dhcp6 protocol.
166 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
167 @retval EFI_INVALID_PARAMETER This is NULL.
173 IN EFI_DHCP6_PROTOCOL
*This
178 EFI_UDP6_PROTOCOL
*Udp6
;
179 DHCP6_INSTANCE
*Instance
;
180 DHCP6_SERVICE
*Service
;
183 return EFI_INVALID_PARAMETER
;
186 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
187 Service
= Instance
->Service
;
188 Udp6
= Service
->UdpIo
->Protocol
.Udp6
;
189 Status
= EFI_SUCCESS
;
192 // The instance hasn't been configured.
194 if (Instance
->Config
== NULL
) {
198 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
201 // No valid REPLY message received yet, cleanup this instance directly.
203 if (Instance
->IaCb
.Ia
->State
== Dhcp6Init
||
204 Instance
->IaCb
.Ia
->State
== Dhcp6Selecting
||
205 Instance
->IaCb
.Ia
->State
== Dhcp6Requesting
211 // Release the current ready Ia.
213 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
215 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
216 Status
= Dhcp6SendReleaseMsg (Instance
, Instance
->IaCb
.Ia
);
217 gBS
->RestoreTPL (OldTpl
);
218 if (EFI_ERROR (Status
)) {
223 // Poll udp out of the net tpl if synchronous call.
225 if (Instance
->Config
->IaInfoEvent
== NULL
) {
226 ASSERT (Udp6
!= NULL
);
227 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
230 Status
= Instance
->UdpSts
;
235 // Clean up the session data for the released Ia.
237 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
238 Dhcp6CleanupSession (Instance
, EFI_SUCCESS
);
239 gBS
->RestoreTPL (OldTpl
);
246 Returns the current operating mode data for the Dhcp6 instance.
248 The GetModeData() function returns the current operating mode and
249 cached data packet for the Dhcp6 instance.
251 @param[in] This The pointer to the Dhcp6 protocol.
252 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
253 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
255 @retval EFI_SUCCESS The mode data was returned.
256 @retval EFI_INVALID_PARAMETER This is NULL.
257 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not
262 EfiDhcp6GetModeData (
263 IN EFI_DHCP6_PROTOCOL
*This
,
264 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
265 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
270 DHCP6_INSTANCE
*Instance
;
271 DHCP6_SERVICE
*Service
;
275 if (This
== NULL
|| (Dhcp6ModeData
== NULL
&& Dhcp6ConfigData
== NULL
)) {
276 return EFI_INVALID_PARAMETER
;
279 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
280 Service
= Instance
->Service
;
282 if (Instance
->Config
== NULL
&& Dhcp6ConfigData
!= NULL
) {
283 return EFI_ACCESS_DENIED
;
286 ASSERT (Service
->ClientId
!= NULL
);
288 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
291 // User needs a copy of instance config data.
293 if (Dhcp6ConfigData
!= NULL
) {
294 ZeroMem (Dhcp6ConfigData
, sizeof(EFI_DHCP6_CONFIG_DATA
));
296 // Duplicate config data, including all reference buffers.
298 if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData
, Instance
->Config
))) {
304 // User need a copy of instance mode data.
306 if (Dhcp6ModeData
!= NULL
) {
307 ZeroMem (Dhcp6ModeData
, sizeof (EFI_DHCP6_MODE_DATA
));
309 // Duplicate a copy of EFI_DHCP6_DUID for client Id.
311 IdSize
= Service
->ClientId
->Length
+ sizeof (Service
->ClientId
->Length
);
313 Dhcp6ModeData
->ClientId
= AllocateZeroPool (IdSize
);
314 if (Dhcp6ModeData
->ClientId
== NULL
) {
319 Dhcp6ModeData
->ClientId
,
324 Ia
= Instance
->IaCb
.Ia
;
327 // Duplicate a copy of EFI_DHCP6_IA for configured Ia.
329 IaSize
= sizeof (EFI_DHCP6_IA
) + (Ia
->IaAddressCount
-1) * sizeof (EFI_DHCP6_IA_ADDRESS
);
331 Dhcp6ModeData
->Ia
= AllocateZeroPool (IaSize
);
332 if (Dhcp6ModeData
->Ia
== NULL
) {
343 // Duplicate a copy of reply packet if has.
345 if (Ia
->ReplyPacket
!= NULL
) {
346 Dhcp6ModeData
->Ia
->ReplyPacket
= AllocateZeroPool (Ia
->ReplyPacket
->Size
);
347 if (Dhcp6ModeData
->Ia
->ReplyPacket
== NULL
) {
351 Dhcp6ModeData
->Ia
->ReplyPacket
,
353 Ia
->ReplyPacket
->Size
359 gBS
->RestoreTPL (OldTpl
);
365 if (Dhcp6ConfigData
!= NULL
) {
366 Dhcp6CleanupConfigData (Dhcp6ConfigData
);
368 if (Dhcp6ModeData
!= NULL
) {
369 Dhcp6CleanupModeData (Dhcp6ModeData
);
371 gBS
->RestoreTPL (OldTpl
);
373 return EFI_OUT_OF_RESOURCES
;
378 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
380 The Configure() function is used to initialize or clean up the configuration
381 data of the Dhcp6 instance:
382 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
383 configuration data will be initialized in the Dhcp6 instance, and the state
384 of the configured IA will be transferred into Dhcp6Init.
385 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
386 configuration data will be cleaned up and no IA will be associated with
388 To update the configuration data for an Dhcp6 instance, the original data
389 must be cleaned up before setting the new configuration data.
391 @param[in] This The pointer to the Dhcp6 protocol
392 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
394 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
395 Dhcp6Init state, or cleaned up the original
396 configuration setting.
397 @retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.
398 The Dhcp6 instance has already started the
399 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
400 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
401 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
402 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
408 IN EFI_DHCP6_PROTOCOL
*This
,
409 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
415 DHCP6_INSTANCE
*Other
;
416 DHCP6_INSTANCE
*Instance
;
417 DHCP6_SERVICE
*Service
;
421 return EFI_INVALID_PARAMETER
;
424 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
425 Service
= Instance
->Service
;
428 // Check the parameter of configure data.
430 if (Dhcp6CfgData
!= NULL
) {
431 if (Dhcp6CfgData
->OptionCount
> 0 && Dhcp6CfgData
->OptionList
== NULL
) {
432 return EFI_INVALID_PARAMETER
;
434 if (Dhcp6CfgData
->OptionList
!= NULL
) {
435 for (Index
= 0; Index
< Dhcp6CfgData
->OptionCount
; Index
++) {
436 if (Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptClientId
||
437 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptRapidCommit
||
438 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptReconfigureAccept
||
439 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptIana
||
440 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptIata
442 return EFI_INVALID_PARAMETER
;
447 if (Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_NA
&&
448 Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_TA
450 return EFI_INVALID_PARAMETER
;
453 if (Dhcp6CfgData
->IaInfoEvent
== NULL
&& Dhcp6CfgData
->SolicitRetransmission
== NULL
) {
454 return EFI_INVALID_PARAMETER
;
457 if (Dhcp6CfgData
->SolicitRetransmission
!= NULL
&&
458 Dhcp6CfgData
->SolicitRetransmission
->Mrc
== 0 &&
459 Dhcp6CfgData
->SolicitRetransmission
->Mrd
== 0
461 return EFI_INVALID_PARAMETER
;
465 // Make sure the (IaId, IaType) is unique over all the instances.
467 NET_LIST_FOR_EACH (Entry
, &Service
->Child
) {
468 Other
= NET_LIST_USER_STRUCT (Entry
, DHCP6_INSTANCE
, Link
);
469 if (Other
->IaCb
.Ia
!= NULL
&&
470 Other
->IaCb
.Ia
->Descriptor
.Type
== Dhcp6CfgData
->IaDescriptor
.Type
&&
471 Other
->IaCb
.Ia
->Descriptor
.IaId
== Dhcp6CfgData
->IaDescriptor
.IaId
473 return EFI_INVALID_PARAMETER
;
478 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
480 if (Dhcp6CfgData
!= NULL
) {
482 // It's not allowed to configure one instance twice without configure null.
484 if (Instance
->Config
!= NULL
) {
485 gBS
->RestoreTPL (OldTpl
);
486 return EFI_ACCESS_DENIED
;
490 // Duplicate config data including all reference buffers.
492 Instance
->Config
= AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA
));
493 if (Instance
->Config
== NULL
) {
494 gBS
->RestoreTPL (OldTpl
);
495 return EFI_OUT_OF_RESOURCES
;
498 Status
= Dhcp6CopyConfigData (Instance
->Config
, Dhcp6CfgData
);
499 if (EFI_ERROR(Status
)) {
500 FreePool (Instance
->Config
);
501 gBS
->RestoreTPL (OldTpl
);
502 return EFI_OUT_OF_RESOURCES
;
506 // Initialize the Ia descriptor from the config data, and leave the other
507 // fields of the Ia as default value 0.
509 Instance
->IaCb
.Ia
= AllocateZeroPool (sizeof(EFI_DHCP6_IA
));
510 if (Instance
->IaCb
.Ia
== NULL
) {
511 Dhcp6CleanupConfigData (Instance
->Config
);
512 FreePool (Instance
->Config
);
513 gBS
->RestoreTPL (OldTpl
);
514 return EFI_OUT_OF_RESOURCES
;
517 &Instance
->IaCb
.Ia
->Descriptor
,
518 &Dhcp6CfgData
->IaDescriptor
,
519 sizeof(EFI_DHCP6_IA_DESCRIPTOR
)
524 if (Instance
->Config
== NULL
) {
525 ASSERT (Instance
->IaCb
.Ia
== NULL
);
526 gBS
->RestoreTPL (OldTpl
);
531 // It's not allowed to configure a started instance as null.
533 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
534 gBS
->RestoreTPL (OldTpl
);
535 return EFI_ACCESS_DENIED
;
538 Dhcp6CleanupConfigData (Instance
->Config
);
539 FreePool (Instance
->Config
);
540 Instance
->Config
= NULL
;
542 FreePool (Instance
->IaCb
.Ia
);
543 Instance
->IaCb
.Ia
= NULL
;
546 gBS
->RestoreTPL (OldTpl
);
553 Request configuration information without the assignment of any
554 Ia addresses of the client.
556 The InfoRequest() function is used to request configuration information
557 without the assignment of any IPv6 address of the client. The client sends
558 out an Information Request packet to obtain the required configuration
559 information, and DHCPv6 server responds with a Reply packet containing
560 the information for the client. The received Reply packet will be passed
561 to the user by ReplyCallback function. If the user returns EFI_NOT_READY from
562 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
563 packets unless timeout according to the Retransmission parameter.
564 Otherwise, the Information Request exchange process will be finished
565 successfully if user returns EFI_SUCCESS from ReplyCallback.
567 @param[in] This The pointer to the Dhcp6 protocol.
568 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
569 Identifier option and include it into Information Request
570 packet. Otherwise, Client Identifier option will not be included.
571 @param[in] OptionRequest The pointer to the buffer of option request options.
572 @param[in] OptionCount The option number in the OptionList.
573 @param[in] OptionList The list of appended options.
574 @param[in] Retransmission The pointer to the retransmission of the message.
575 @param[in] TimeoutEvent The event of timeout.
576 @param[in] ReplyCallback The callback function when the reply was received.
577 @param[in] CallbackContext The pointer to the parameter passed to the callback.
579 @retval EFI_SUCCESS The DHCPv6 information request exchange process
580 completed when TimeoutEvent is NULL. Information
581 Request packet has been sent to DHCPv6 server when
582 TimeoutEvent is not NULL.
583 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
584 because of no response, or not all requested-options
585 are responded by DHCPv6 servers when Timeout happened.
586 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
588 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
589 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
590 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
595 EfiDhcp6InfoRequest (
596 IN EFI_DHCP6_PROTOCOL
*This
,
597 IN BOOLEAN SendClientId
,
598 IN EFI_DHCP6_PACKET_OPTION
*OptionRequest
,
599 IN UINT32 OptionCount
,
600 IN EFI_DHCP6_PACKET_OPTION
*OptionList
[] OPTIONAL
,
601 IN EFI_DHCP6_RETRANSMISSION
*Retransmission
,
602 IN EFI_EVENT TimeoutEvent OPTIONAL
,
603 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback
,
604 IN VOID
*CallbackContext OPTIONAL
608 DHCP6_INSTANCE
*Instance
;
609 DHCP6_SERVICE
*Service
;
612 EFI_STATUS TimerStatus
;
613 UINTN GetMappingTimeOut
;
615 if (This
== NULL
|| OptionRequest
== NULL
|| Retransmission
== NULL
|| ReplyCallback
== NULL
) {
616 return EFI_INVALID_PARAMETER
;
619 if (Retransmission
!= NULL
&& Retransmission
->Mrc
== 0 && Retransmission
->Mrd
== 0) {
620 return EFI_INVALID_PARAMETER
;
623 if (OptionCount
> 0 && OptionList
== NULL
) {
624 return EFI_INVALID_PARAMETER
;
627 if (OptionList
!= NULL
) {
628 for (Index
= 0; Index
< OptionCount
; Index
++) {
629 if (OptionList
[Index
]->OpCode
== Dhcp6OptClientId
|| OptionList
[Index
]->OpCode
== Dhcp6OptRequestOption
) {
630 return EFI_INVALID_PARAMETER
;
635 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
636 Service
= Instance
->Service
;
638 Status
= Dhcp6StartInfoRequest (
649 if (Status
== EFI_NO_MAPPING
) {
651 // The link local address is not ready, wait for some time and restart
652 // the DHCP6 information request process.
654 Status
= Dhcp6GetMappingTimeOut(Service
->Ip6Cfg
, &GetMappingTimeOut
);
655 if (EFI_ERROR(Status
)) {
659 Status
= gBS
->CreateEvent (EVT_TIMER
, TPL_CALLBACK
, NULL
, NULL
, &Timer
);
660 if (EFI_ERROR (Status
)) {
665 // Start the timer, wait for link local address DAD to finish.
667 Status
= gBS
->SetTimer (Timer
, TimerRelative
, GetMappingTimeOut
);
668 if (EFI_ERROR (Status
)) {
669 gBS
->CloseEvent (Timer
);
674 TimerStatus
= gBS
->CheckEvent (Timer
);
675 if (!EFI_ERROR (TimerStatus
)) {
676 Status
= Dhcp6StartInfoRequest (
688 } while (TimerStatus
== EFI_NOT_READY
);
690 gBS
->CloseEvent (Timer
);
692 if (EFI_ERROR (Status
)) {
697 // Poll udp out of the net tpl if synchronous call.
699 if (TimeoutEvent
== NULL
) {
701 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
702 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
704 return Instance
->UdpSts
;
712 Manually extend the valid and preferred lifetimes for the IPv6 addresses
713 of the configured IA and update other configuration parameters by sending a
714 Renew or Rebind packet.
716 The RenewRebind() function is used to manually extend the valid and preferred
717 lifetimes for the IPv6 addresses of the configured IA, and update other
718 configuration parameters by sending Renew or Rebind packet.
719 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
720 it sends Renew packet to the previously DHCPv6 server and transfer the
721 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
722 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
723 If fails, the state transfers to Dhcp6Bound, but the timer continues.
724 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
725 it will send a Rebind packet. If valid Reply packet is received, the state transfers
726 to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
727 transfers to Dhcp6Init, and the IA can't be used.
729 @param[in] This The pointer to the Dhcp6 protocol.
730 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
731 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
733 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has
734 completed and at least one IPv6 address of the
735 configured IA has been bound again when
736 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
737 The EFI DHCPv6 Protocol instance has sent Renew
738 or Rebind packet when
739 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
740 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
741 state of the configured IA is not in Dhcp6Bound.
742 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
743 Dhcp6Renewing when RebindRequest is FALSE.
744 The state of the configured IA has already entered
745 Dhcp6Rebinding when RebindRequest is TRUE.
746 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
748 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
749 because of no response.
750 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
751 IA after the DHCPv6 renew/rebind exchange process.
752 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
753 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
758 EfiDhcp6RenewRebind (
759 IN EFI_DHCP6_PROTOCOL
*This
,
760 IN BOOLEAN RebindRequest
765 DHCP6_INSTANCE
*Instance
;
766 DHCP6_SERVICE
*Service
;
769 return EFI_INVALID_PARAMETER
;
772 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
773 Service
= Instance
->Service
;
776 // The instance hasn't been configured.
778 if (Instance
->Config
== NULL
) {
779 return EFI_ACCESS_DENIED
;
782 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
785 // The instance has already entered renewing or rebinding state.
787 if ((Instance
->IaCb
.Ia
->State
== Dhcp6Rebinding
&& RebindRequest
) ||
788 (Instance
->IaCb
.Ia
->State
== Dhcp6Renewing
&& !RebindRequest
)
790 return EFI_ALREADY_STARTED
;
793 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
794 return EFI_ACCESS_DENIED
;
797 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
798 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
801 // Send renew/rebind message to start exchange process.
803 Status
= Dhcp6SendRenewRebindMsg (Instance
, RebindRequest
);
805 if (EFI_ERROR (Status
)) {
810 // Register receive callback for the stateful exchange process.
812 Status
= UdpIoRecvDatagram(
819 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
823 gBS
->RestoreTPL (OldTpl
);
826 // Poll udp out of the net tpl if synchronous call.
828 if (Instance
->Config
->IaInfoEvent
== NULL
) {
830 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
831 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
833 return Instance
->UdpSts
;
840 gBS
->RestoreTPL (OldTpl
);
846 Inform that one or more addresses assigned by a server are already
847 in use by another node.
849 The Decline() function is used to manually decline the assignment of
850 IPv6 addresses, which have been already used by another node. If all
851 IPv6 addresses of the configured IA are declined through this function,
852 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
853 Otherwise, the state of the IA will restore to Dhcp6Bound after the
854 declining process. The Decline() can only be called when the IA is in
855 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
856 this function is a blocking operation. It will return after the
857 declining process finishes, or aborted by user.
859 @param[in] This The pointer to EFI_DHCP6_PROTOCOL.
860 @param[in] AddressCount The number of declining addresses.
861 @param[in] Addresses The pointer to the buffer stored the declining
864 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
865 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
866 The Dhcp6 instance sent Decline packet when
867 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
868 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
869 state of the configured IA is not in Dhcp6Bound.
870 @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
871 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
872 the configured IA for this instance.
873 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
874 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
880 IN EFI_DHCP6_PROTOCOL
*This
,
881 IN UINT32 AddressCount
,
882 IN EFI_IPv6_ADDRESS
*Addresses
888 DHCP6_INSTANCE
*Instance
;
889 DHCP6_SERVICE
*Service
;
891 if (This
== NULL
|| AddressCount
== 0 || Addresses
== NULL
) {
892 return EFI_INVALID_PARAMETER
;
895 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
896 Service
= Instance
->Service
;
899 // The instance hasn't been configured.
901 if (Instance
->Config
== NULL
) {
902 return EFI_ACCESS_DENIED
;
905 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
907 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
908 return EFI_ACCESS_DENIED
;
912 // Check whether all the declined addresses belongs to the configured Ia.
914 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
916 if (EFI_ERROR(Status
)) {
920 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
921 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
924 // Deprive of all the declined addresses from the configured Ia, and create a
925 // DeclineIa used to create decline message.
927 DecIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
930 Status
= EFI_OUT_OF_RESOURCES
;
935 // Send the decline message to start exchange process.
937 Status
= Dhcp6SendDeclineMsg (Instance
, DecIa
);
939 if (EFI_ERROR (Status
)) {
944 // Register receive callback for the stateful exchange process.
946 Status
= UdpIoRecvDatagram(
953 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
958 gBS
->RestoreTPL (OldTpl
);
961 // Poll udp out of the net tpl if synchronous call.
963 if (Instance
->Config
->IaInfoEvent
== NULL
) {
965 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
966 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
968 return Instance
->UdpSts
;
978 gBS
->RestoreTPL (OldTpl
);
985 Release one or more addresses associated with the configured Ia
986 for current instance.
988 The Release() function is used to manually release one or more
989 IPv6 addresses. If AddressCount is zero, it will release all IPv6
990 addresses of the configured IA. If all IPv6 addresses of the IA are
991 released through this function, the state of the IA will switch
992 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
993 IA will restore to Dhcp6Bound after the releasing process.
994 The Release() can only be called when the IA is in Dhcp6Bound state.
995 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
996 a blocking operation. It will return after the releasing process
997 finishes, or is aborted by user.
999 @param[in] This The pointer to the Dhcp6 protocol.
1000 @param[in] AddressCount The number of releasing addresses.
1001 @param[in] Addresses The pointer to the buffer stored the releasing
1004 @retval EFI_SUCCESS The DHCPv6 release exchange process
1005 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1006 was NULL. The Dhcp6 instance was sent Release
1007 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1009 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
1010 state of the configured IA is not in Dhcp6Bound.
1011 @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
1012 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
1013 the configured IA for this instance.
1014 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1015 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1021 IN EFI_DHCP6_PROTOCOL
*This
,
1022 IN UINT32 AddressCount
,
1023 IN EFI_IPv6_ADDRESS
*Addresses
1028 EFI_DHCP6_IA
*RelIa
;
1029 DHCP6_INSTANCE
*Instance
;
1030 DHCP6_SERVICE
*Service
;
1032 if (This
== NULL
|| (AddressCount
!= 0 && Addresses
== NULL
)) {
1033 return EFI_INVALID_PARAMETER
;
1036 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
1037 Service
= Instance
->Service
;
1040 // The instance hasn't been configured.
1042 if (Instance
->Config
== NULL
) {
1043 return EFI_ACCESS_DENIED
;
1046 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
1048 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
1049 return EFI_ACCESS_DENIED
;
1053 // Check whether all the released addresses belongs to the configured Ia.
1055 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1057 if (EFI_ERROR(Status
)) {
1061 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1062 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
1065 // Deprive of all the released addresses from the configured Ia, and create a
1066 // ReleaseIa used to create release message.
1068 RelIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1070 if (RelIa
== NULL
) {
1071 Status
= EFI_OUT_OF_RESOURCES
;
1076 // Send the release message to start exchange process.
1078 Status
= Dhcp6SendReleaseMsg (Instance
, RelIa
);
1080 if (EFI_ERROR (Status
)) {
1085 // Register receive callback for the stateful exchange process.
1087 Status
= UdpIoRecvDatagram(
1094 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
1099 gBS
->RestoreTPL (OldTpl
);
1102 // Poll udp out of the net tpl if synchronous call.
1104 if (Instance
->Config
->IaInfoEvent
== NULL
) {
1105 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
1106 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
1108 return Instance
->UdpSts
;
1115 if (RelIa
!= NULL
) {
1118 gBS
->RestoreTPL (OldTpl
);
1125 Parse the option data in the Dhcp6 packet.
1127 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
1129 @param[in] This The pointer to the Dhcp6 protocol.
1130 @param[in] Packet The pointer to the Dhcp6 packet.
1131 @param[in, out] OptionCount The number of option in the packet.
1132 @param[out] PacketOptionList The array of pointers to each option in the packet.
1134 @retval EFI_SUCCESS The packet was successfully parsed.
1135 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1136 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
1137 that were found in the Packet.
1143 IN EFI_DHCP6_PROTOCOL
*This
,
1144 IN EFI_DHCP6_PACKET
*Packet
,
1145 IN OUT UINT32
*OptionCount
,
1146 OUT EFI_DHCP6_PACKET_OPTION
*PacketOptionList
[] OPTIONAL
1155 if (This
== NULL
|| Packet
== NULL
|| OptionCount
== NULL
) {
1156 return EFI_INVALID_PARAMETER
;
1159 if (*OptionCount
!= 0 && PacketOptionList
== NULL
) {
1160 return EFI_INVALID_PARAMETER
;
1163 if (Packet
->Length
> Packet
->Size
|| Packet
->Length
< sizeof (EFI_DHCP6_HEADER
)) {
1164 return EFI_INVALID_PARAMETER
;
1168 // The format of Dhcp6 option:
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
1171 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1172 // | option-code | option-len (option data) |
1173 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1175 // | (option-len octets) |
1176 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1180 OptLen
= Packet
->Length
- sizeof (EFI_DHCP6_HEADER
);
1181 Start
= Packet
->Dhcp6
.Option
;
1182 End
= Start
+ OptLen
;
1185 // Calculate the number of option in the packet.
1187 while (Start
< End
) {
1188 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1189 Start
+= (NTOHS (DataLen
) + 4);
1194 // It will return buffer too small if pass-in option count is smaller than the
1195 // actual count of options in the packet.
1197 if (OptCnt
> *OptionCount
) {
1198 *OptionCount
= OptCnt
;
1199 return EFI_BUFFER_TOO_SMALL
;
1204 (*OptionCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*))
1208 Start
= Packet
->Dhcp6
.Option
;
1210 while (Start
< End
) {
1212 PacketOptionList
[OptCnt
] = (EFI_DHCP6_PACKET_OPTION
*) Start
;
1213 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1214 Start
+= (NTOHS (DataLen
) + 4);