2 This EFI_DHCP6_PROTOCOL interface implementation.
4 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
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.
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.
16 #include "Dhcp6Impl.h"
19 // Well-known multi-cast address defined in section-24.1 of rfc-3315
21 // ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2
22 // ALL_DHCP_Servers address: FF05::1:3
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}};
27 EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate
= {
40 Starts the DHCPv6 standard S.A.R.R. process.
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
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.
52 @param[in] This The pointer to Dhcp6 protocol.
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
65 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
66 @retval EFI_NO_MEDIA There was a media error.
72 IN EFI_DHCP6_PROTOCOL
*This
77 DHCP6_INSTANCE
*Instance
;
78 DHCP6_SERVICE
*Service
;
79 EFI_STATUS MediaStatus
;
82 return EFI_INVALID_PARAMETER
;
85 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
86 Service
= Instance
->Service
;
89 // The instance hasn't been configured.
91 if (Instance
->Config
== NULL
) {
92 return EFI_ACCESS_DENIED
;
95 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
98 // The instance has already been started.
100 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
101 return EFI_ALREADY_STARTED
;
104 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
107 // Check Media Satus.
109 MediaStatus
= EFI_SUCCESS
;
110 NetLibDetectMediaWaitTimeout (Service
->Controller
, DHCP_CHECK_MEDIA_WAITING_TIME
, &MediaStatus
);
111 if (MediaStatus
!= EFI_SUCCESS
) {
112 Status
= EFI_NO_MEDIA
;
116 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
119 // Send the solicit message to start S.A.R.R process.
121 Status
= Dhcp6SendSolicitMsg (Instance
);
123 if (EFI_ERROR (Status
)) {
128 // Register receive callback for the stateful exchange process.
130 Status
= UdpIoRecvDatagram(
137 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
141 gBS
->RestoreTPL (OldTpl
);
144 // Poll udp out of the net tpl if synchronous call.
146 if (Instance
->Config
->IaInfoEvent
== NULL
) {
148 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
149 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
151 return Instance
->UdpSts
;
158 gBS
->RestoreTPL (OldTpl
);
164 Stops the DHCPv6 standard S.A.R.R. process.
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.
172 @param[in] This The pointer to the Dhcp6 protocol.
174 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
175 @retval EFI_INVALID_PARAMETER This is NULL.
181 IN EFI_DHCP6_PROTOCOL
*This
186 EFI_UDP6_PROTOCOL
*Udp6
;
187 DHCP6_INSTANCE
*Instance
;
188 DHCP6_SERVICE
*Service
;
191 return EFI_INVALID_PARAMETER
;
194 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
195 Service
= Instance
->Service
;
196 Udp6
= Service
->UdpIo
->Protocol
.Udp6
;
197 Status
= EFI_SUCCESS
;
200 // The instance hasn't been configured.
202 if (Instance
->Config
== NULL
) {
206 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
209 // No valid REPLY message received yet, cleanup this instance directly.
211 if (Instance
->IaCb
.Ia
->State
== Dhcp6Init
||
212 Instance
->IaCb
.Ia
->State
== Dhcp6Selecting
||
213 Instance
->IaCb
.Ia
->State
== Dhcp6Requesting
219 // Release the current ready Ia.
221 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
223 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
224 Status
= Dhcp6SendReleaseMsg (Instance
, Instance
->IaCb
.Ia
);
225 gBS
->RestoreTPL (OldTpl
);
226 if (EFI_ERROR (Status
)) {
231 // Poll udp out of the net tpl if synchoronus call.
233 if (Instance
->Config
->IaInfoEvent
== NULL
) {
234 ASSERT (Udp6
!= NULL
);
235 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
238 Status
= Instance
->UdpSts
;
243 // Clean up the session data for the released Ia.
245 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
246 Dhcp6CleanupSession (Instance
, EFI_SUCCESS
);
247 gBS
->RestoreTPL (OldTpl
);
254 Returns the current operating mode data for the Dhcp6 instance.
256 The GetModeData() function returns the current operating mode and
257 cached data packet for the Dhcp6 instance.
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.
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
270 EfiDhcp6GetModeData (
271 IN EFI_DHCP6_PROTOCOL
*This
,
272 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
273 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
278 DHCP6_INSTANCE
*Instance
;
279 DHCP6_SERVICE
*Service
;
283 if (This
== NULL
|| (Dhcp6ModeData
== NULL
&& Dhcp6ConfigData
== NULL
)) {
284 return EFI_INVALID_PARAMETER
;
287 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
288 Service
= Instance
->Service
;
290 if (Instance
->Config
== NULL
&& Dhcp6ConfigData
!= NULL
) {
291 return EFI_ACCESS_DENIED
;
294 ASSERT (Service
->ClientId
!= NULL
);
296 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
299 // User needs a copy of instance config data.
301 if (Dhcp6ConfigData
!= NULL
) {
302 ZeroMem (Dhcp6ConfigData
, sizeof(EFI_DHCP6_CONFIG_DATA
));
304 // Duplicate config data, including all reference buffers.
306 if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData
, Instance
->Config
))) {
312 // User need a copy of instance mode data.
314 if (Dhcp6ModeData
!= NULL
) {
315 ZeroMem (Dhcp6ModeData
, sizeof (EFI_DHCP6_MODE_DATA
));
317 // Duplicate a copy of EFI_DHCP6_DUID for client Id.
319 IdSize
= Service
->ClientId
->Length
+ sizeof (Service
->ClientId
->Length
);
321 Dhcp6ModeData
->ClientId
= AllocateZeroPool (IdSize
);
322 if (Dhcp6ModeData
->ClientId
== NULL
) {
327 Dhcp6ModeData
->ClientId
,
332 Ia
= Instance
->IaCb
.Ia
;
335 // Duplicate a copy of EFI_DHCP6_IA for configured Ia.
337 IaSize
= sizeof (EFI_DHCP6_IA
) + (Ia
->IaAddressCount
-1) * sizeof (EFI_DHCP6_IA_ADDRESS
);
339 Dhcp6ModeData
->Ia
= AllocateZeroPool (IaSize
);
340 if (Dhcp6ModeData
->Ia
== NULL
) {
351 // Duplicate a copy of reply packet if has.
353 if (Ia
->ReplyPacket
!= NULL
) {
354 Dhcp6ModeData
->Ia
->ReplyPacket
= AllocateZeroPool (Ia
->ReplyPacket
->Size
);
355 if (Dhcp6ModeData
->Ia
->ReplyPacket
== NULL
) {
359 Dhcp6ModeData
->Ia
->ReplyPacket
,
361 Ia
->ReplyPacket
->Size
367 gBS
->RestoreTPL (OldTpl
);
373 if (Dhcp6ConfigData
!= NULL
) {
374 Dhcp6CleanupConfigData (Dhcp6ConfigData
);
376 if (Dhcp6ModeData
!= NULL
) {
377 Dhcp6CleanupModeData (Dhcp6ModeData
);
379 gBS
->RestoreTPL (OldTpl
);
381 return EFI_OUT_OF_RESOURCES
;
386 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
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
396 To update the configuration data for an Dhcp6 instance, the original data
397 must be cleaned up before setting the new configuration data.
399 @param[in] This The pointer to the Dhcp6 protocol
400 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
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.
416 IN EFI_DHCP6_PROTOCOL
*This
,
417 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
423 DHCP6_INSTANCE
*Other
;
424 DHCP6_INSTANCE
*Instance
;
425 DHCP6_SERVICE
*Service
;
429 return EFI_INVALID_PARAMETER
;
432 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
433 Service
= Instance
->Service
;
436 // Check the parameter of configure data.
438 if (Dhcp6CfgData
!= NULL
) {
439 if (Dhcp6CfgData
->OptionCount
> 0 && Dhcp6CfgData
->OptionList
== NULL
) {
440 return EFI_INVALID_PARAMETER
;
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
450 return EFI_INVALID_PARAMETER
;
455 if (Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_NA
&&
456 Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_TA
458 return EFI_INVALID_PARAMETER
;
461 if (Dhcp6CfgData
->IaInfoEvent
== NULL
&& Dhcp6CfgData
->SolicitRetransmission
== NULL
) {
462 return EFI_INVALID_PARAMETER
;
465 if (Dhcp6CfgData
->SolicitRetransmission
!= NULL
&&
466 Dhcp6CfgData
->SolicitRetransmission
->Mrc
== 0 &&
467 Dhcp6CfgData
->SolicitRetransmission
->Mrd
== 0
469 return EFI_INVALID_PARAMETER
;
473 // Make sure the (IaId, IaType) is unique over all the instances.
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
481 return EFI_INVALID_PARAMETER
;
486 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
488 if (Dhcp6CfgData
!= NULL
) {
490 // It's not allowed to configure one instance twice without configure null.
492 if (Instance
->Config
!= NULL
) {
493 gBS
->RestoreTPL (OldTpl
);
494 return EFI_ACCESS_DENIED
;
498 // Duplicate config data including all reference buffers.
500 Instance
->Config
= AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA
));
501 if (Instance
->Config
== NULL
) {
502 gBS
->RestoreTPL (OldTpl
);
503 return EFI_OUT_OF_RESOURCES
;
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
;
514 // Initialize the Ia descriptor from the config data, and leave the other
515 // fields of the Ia as default value 0.
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
;
525 &Instance
->IaCb
.Ia
->Descriptor
,
526 &Dhcp6CfgData
->IaDescriptor
,
527 sizeof(EFI_DHCP6_IA_DESCRIPTOR
)
532 if (Instance
->Config
== NULL
) {
533 ASSERT (Instance
->IaCb
.Ia
== NULL
);
534 gBS
->RestoreTPL (OldTpl
);
539 // It's not allowed to configure a started instance as null.
541 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
542 gBS
->RestoreTPL (OldTpl
);
543 return EFI_ACCESS_DENIED
;
546 Dhcp6CleanupConfigData (Instance
->Config
);
547 FreePool (Instance
->Config
);
548 Instance
->Config
= NULL
;
550 FreePool (Instance
->IaCb
.Ia
);
551 Instance
->IaCb
.Ia
= NULL
;
554 gBS
->RestoreTPL (OldTpl
);
561 Request configuration information without the assignment of any
562 Ia addresses of the client.
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.
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.
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
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.
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
616 DHCP6_INSTANCE
*Instance
;
617 DHCP6_SERVICE
*Service
;
620 EFI_STATUS TimerStatus
;
621 UINTN GetMappingTimeOut
;
623 if (This
== NULL
|| OptionRequest
== NULL
|| Retransmission
== NULL
|| ReplyCallback
== NULL
) {
624 return EFI_INVALID_PARAMETER
;
627 if (Retransmission
!= NULL
&& Retransmission
->Mrc
== 0 && Retransmission
->Mrd
== 0) {
628 return EFI_INVALID_PARAMETER
;
631 if (OptionCount
> 0 && OptionList
== NULL
) {
632 return EFI_INVALID_PARAMETER
;
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
;
643 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
644 Service
= Instance
->Service
;
646 Status
= Dhcp6StartInfoRequest (
657 if (Status
== EFI_NO_MAPPING
) {
659 // The link local address is not ready, wait for some time and restart
660 // the DHCP6 information request process.
662 Status
= Dhcp6GetMappingTimeOut(Service
->Ip6Cfg
, &GetMappingTimeOut
);
663 if (EFI_ERROR(Status
)) {
667 Status
= gBS
->CreateEvent (EVT_TIMER
, TPL_CALLBACK
, NULL
, NULL
, &Timer
);
668 if (EFI_ERROR (Status
)) {
673 // Start the timer, wait for link local address DAD to finish.
675 Status
= gBS
->SetTimer (Timer
, TimerRelative
, GetMappingTimeOut
);
676 if (EFI_ERROR (Status
)) {
677 gBS
->CloseEvent (Timer
);
682 TimerStatus
= gBS
->CheckEvent (Timer
);
683 if (!EFI_ERROR (TimerStatus
)) {
684 Status
= Dhcp6StartInfoRequest (
696 } while (TimerStatus
== EFI_NOT_READY
);
698 gBS
->CloseEvent (Timer
);
700 if (EFI_ERROR (Status
)) {
705 // Poll udp out of the net tpl if synchoronus call.
707 if (TimeoutEvent
== NULL
) {
709 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
710 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
712 return Instance
->UdpSts
;
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.
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.
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.
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
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.
766 EfiDhcp6RenewRebind (
767 IN EFI_DHCP6_PROTOCOL
*This
,
768 IN BOOLEAN RebindRequest
773 DHCP6_INSTANCE
*Instance
;
774 DHCP6_SERVICE
*Service
;
777 return EFI_INVALID_PARAMETER
;
780 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
781 Service
= Instance
->Service
;
784 // The instance hasn't been configured.
786 if (Instance
->Config
== NULL
) {
787 return EFI_ACCESS_DENIED
;
790 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
793 // The instance has already entered renewing or rebinding state.
795 if ((Instance
->IaCb
.Ia
->State
== Dhcp6Rebinding
&& RebindRequest
) ||
796 (Instance
->IaCb
.Ia
->State
== Dhcp6Renewing
&& !RebindRequest
)
798 return EFI_ALREADY_STARTED
;
801 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
802 return EFI_ACCESS_DENIED
;
805 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
806 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
809 // Send renew/rebind message to start exchange process.
811 Status
= Dhcp6SendRenewRebindMsg (Instance
, RebindRequest
);
813 if (EFI_ERROR (Status
)) {
818 // Register receive callback for the stateful exchange process.
820 Status
= UdpIoRecvDatagram(
827 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
831 gBS
->RestoreTPL (OldTpl
);
834 // Poll udp out of the net tpl if synchoronus call.
836 if (Instance
->Config
->IaInfoEvent
== NULL
) {
838 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
839 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
841 return Instance
->UdpSts
;
848 gBS
->RestoreTPL (OldTpl
);
854 Inform that one or more addresses assigned by a server are already
855 in use by another node.
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.
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
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.
888 IN EFI_DHCP6_PROTOCOL
*This
,
889 IN UINT32 AddressCount
,
890 IN EFI_IPv6_ADDRESS
*Addresses
896 DHCP6_INSTANCE
*Instance
;
897 DHCP6_SERVICE
*Service
;
899 if (This
== NULL
|| AddressCount
== 0 || Addresses
== NULL
) {
900 return EFI_INVALID_PARAMETER
;
903 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
904 Service
= Instance
->Service
;
907 // The instance hasn't been configured.
909 if (Instance
->Config
== NULL
) {
910 return EFI_ACCESS_DENIED
;
913 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
915 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
916 return EFI_ACCESS_DENIED
;
920 // Check whether all the declined addresses belongs to the configured Ia.
922 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
924 if (EFI_ERROR(Status
)) {
928 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
929 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
932 // Deprive of all the declined addresses from the configured Ia, and create a
933 // DeclineIa used to create decline message.
935 DecIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
938 Status
= EFI_OUT_OF_RESOURCES
;
943 // Send the decline message to start exchange process.
945 Status
= Dhcp6SendDeclineMsg (Instance
, DecIa
);
947 if (EFI_ERROR (Status
)) {
952 // Register receive callback for the stateful exchange process.
954 Status
= UdpIoRecvDatagram(
961 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
966 gBS
->RestoreTPL (OldTpl
);
969 // Poll udp out of the net tpl if synchoronus call.
971 if (Instance
->Config
->IaInfoEvent
== NULL
) {
973 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
974 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
976 return Instance
->UdpSts
;
986 gBS
->RestoreTPL (OldTpl
);
993 Release one or more addresses associated with the configured Ia
994 for current instance.
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.
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
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
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.
1029 IN EFI_DHCP6_PROTOCOL
*This
,
1030 IN UINT32 AddressCount
,
1031 IN EFI_IPv6_ADDRESS
*Addresses
1036 EFI_DHCP6_IA
*RelIa
;
1037 DHCP6_INSTANCE
*Instance
;
1038 DHCP6_SERVICE
*Service
;
1040 if (This
== NULL
|| (AddressCount
!= 0 && Addresses
== NULL
)) {
1041 return EFI_INVALID_PARAMETER
;
1044 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
1045 Service
= Instance
->Service
;
1048 // The instance hasn't been configured.
1050 if (Instance
->Config
== NULL
) {
1051 return EFI_ACCESS_DENIED
;
1054 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
1056 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
1057 return EFI_ACCESS_DENIED
;
1061 // Check whether all the released addresses belongs to the configured Ia.
1063 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1065 if (EFI_ERROR(Status
)) {
1069 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1070 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
1073 // Deprive of all the released addresses from the configured Ia, and create a
1074 // ReleaseIa used to create release message.
1076 RelIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1078 if (RelIa
== NULL
) {
1079 Status
= EFI_OUT_OF_RESOURCES
;
1084 // Send the release message to start exchange process.
1086 Status
= Dhcp6SendReleaseMsg (Instance
, RelIa
);
1088 if (EFI_ERROR (Status
)) {
1093 // Register receive callback for the stateful exchange process.
1095 Status
= UdpIoRecvDatagram(
1102 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
1107 gBS
->RestoreTPL (OldTpl
);
1110 // Poll udp out of the net tpl if synchoronus call.
1112 if (Instance
->Config
->IaInfoEvent
== NULL
) {
1113 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
1114 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
1116 return Instance
->UdpSts
;
1123 if (RelIa
!= NULL
) {
1126 gBS
->RestoreTPL (OldTpl
);
1133 Parse the option data in the Dhcp6 packet.
1135 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
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.
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.
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
1163 if (This
== NULL
|| Packet
== NULL
|| OptionCount
== NULL
) {
1164 return EFI_INVALID_PARAMETER
;
1167 if (*OptionCount
!= 0 && PacketOptionList
== NULL
) {
1168 return EFI_INVALID_PARAMETER
;
1171 if (Packet
->Length
> Packet
->Size
|| Packet
->Length
< sizeof (EFI_DHCP6_HEADER
)) {
1172 return EFI_INVALID_PARAMETER
;
1176 // The format of Dhcp6 option:
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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1183 // | (option-len octets) |
1184 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1188 OptLen
= Packet
->Length
- sizeof (EFI_DHCP6_HEADER
);
1189 Start
= Packet
->Dhcp6
.Option
;
1190 End
= Start
+ OptLen
;
1193 // Calculate the number of option in the packet.
1195 while (Start
< End
) {
1196 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1197 Start
+= (NTOHS (DataLen
) + 4);
1202 // It will return buffer too small if pass-in option count is smaller than the
1203 // actual count of options in the packet.
1205 if (OptCnt
> *OptionCount
) {
1206 *OptionCount
= OptCnt
;
1207 return EFI_BUFFER_TOO_SMALL
;
1212 (*OptionCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*))
1216 Start
= Packet
->Dhcp6
.Option
;
1218 while (Start
< End
) {
1220 PacketOptionList
[OptCnt
] = (EFI_DHCP6_PACKET_OPTION
*) Start
;
1221 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1222 Start
+= (NTOHS (DataLen
) + 4);