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
= {
18 { 0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2 }
21 EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate
= {
34 Starts the DHCPv6 standard S.A.R.R. process.
36 The Start() function starts the DHCPv6 standard process. This function can
37 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
38 If the DHCP process completes successfully, the state of the Dhcp6 instance
39 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
41 Refer to rfc-3315 for precise state transitions during this process. At the
42 time when each event occurs in this process, the callback function that was set
43 by EFI_DHCP6_PROTOCOL.Configure() will be called, and the user can take this
44 opportunity to control the process.
46 @param[in] This The pointer to Dhcp6 protocol.
48 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it has
49 completed when CompletionEvent is NULL.
50 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
51 @retval EFI_INVALID_PARAMETER This is NULL.
52 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
53 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
54 response was received from the server within the
55 specified timeout value.
56 @retval EFI_ABORTED The user aborted the DHCPv6 process.
57 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
59 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
60 @retval EFI_NO_MEDIA There was a media error.
66 IN EFI_DHCP6_PROTOCOL
*This
71 DHCP6_INSTANCE
*Instance
;
72 DHCP6_SERVICE
*Service
;
73 EFI_STATUS MediaStatus
;
76 return EFI_INVALID_PARAMETER
;
79 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
80 Service
= Instance
->Service
;
83 // The instance hasn't been configured.
85 if (Instance
->Config
== NULL
) {
86 return EFI_ACCESS_DENIED
;
89 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
92 // The instance has already been started.
94 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
95 return EFI_ALREADY_STARTED
;
98 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
101 // Check Media Status.
103 MediaStatus
= EFI_SUCCESS
;
104 NetLibDetectMediaWaitTimeout (Service
->Controller
, DHCP_CHECK_MEDIA_WAITING_TIME
, &MediaStatus
);
105 if (MediaStatus
!= EFI_SUCCESS
) {
106 Status
= EFI_NO_MEDIA
;
110 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
113 // Send the solicit message to start S.A.R.R process.
115 Status
= Dhcp6SendSolicitMsg (Instance
);
117 if (EFI_ERROR (Status
)) {
122 // Register receive callback for the stateful exchange process.
124 Status
= UdpIoRecvDatagram (
131 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
135 gBS
->RestoreTPL (OldTpl
);
138 // Poll udp out of the net tpl if synchronous call.
140 if (Instance
->Config
->IaInfoEvent
== NULL
) {
141 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
142 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
145 return Instance
->UdpSts
;
152 gBS
->RestoreTPL (OldTpl
);
157 Stops the DHCPv6 standard S.A.R.R. process.
159 The Stop() function is used to stop the DHCPv6 standard process. After this
160 function is called successfully, the state of Dhcp6 instance is transferred
161 into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
162 before DHCPv6 standard process can be started again. This function can be
163 called when the Dhcp6 instance is in any state.
165 @param[in] This The pointer to the Dhcp6 protocol.
167 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
168 @retval EFI_INVALID_PARAMETER This is NULL.
174 IN EFI_DHCP6_PROTOCOL
*This
179 EFI_UDP6_PROTOCOL
*Udp6
;
180 DHCP6_INSTANCE
*Instance
;
181 DHCP6_SERVICE
*Service
;
184 return EFI_INVALID_PARAMETER
;
187 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
188 Service
= Instance
->Service
;
189 Udp6
= Service
->UdpIo
->Protocol
.Udp6
;
190 Status
= EFI_SUCCESS
;
193 // The instance hasn't been configured.
195 if (Instance
->Config
== NULL
) {
199 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
202 // No valid REPLY message received yet, cleanup this instance directly.
204 if ((Instance
->IaCb
.Ia
->State
== Dhcp6Init
) ||
205 (Instance
->IaCb
.Ia
->State
== Dhcp6Selecting
) ||
206 (Instance
->IaCb
.Ia
->State
== Dhcp6Requesting
)
213 // Release the current ready Ia.
215 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
217 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
218 Status
= Dhcp6SendReleaseMsg (Instance
, Instance
->IaCb
.Ia
);
219 gBS
->RestoreTPL (OldTpl
);
220 if (EFI_ERROR (Status
)) {
225 // Poll udp out of the net tpl if synchronous call.
227 if (Instance
->Config
->IaInfoEvent
== NULL
) {
228 ASSERT (Udp6
!= NULL
);
229 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
233 Status
= Instance
->UdpSts
;
238 // Clean up the session data for the released Ia.
240 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
241 Dhcp6CleanupSession (Instance
, EFI_SUCCESS
);
242 gBS
->RestoreTPL (OldTpl
);
248 Returns the current operating mode data for the Dhcp6 instance.
250 The GetModeData() function returns the current operating mode and
251 cached data packet for the Dhcp6 instance.
253 @param[in] This The pointer to the Dhcp6 protocol.
254 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
255 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
257 @retval EFI_SUCCESS The mode data was returned.
258 @retval EFI_INVALID_PARAMETER This is NULL.
259 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not
264 EfiDhcp6GetModeData (
265 IN EFI_DHCP6_PROTOCOL
*This
,
266 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
267 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
272 DHCP6_INSTANCE
*Instance
;
273 DHCP6_SERVICE
*Service
;
277 if ((This
== NULL
) || ((Dhcp6ModeData
== NULL
) && (Dhcp6ConfigData
== NULL
))) {
278 return EFI_INVALID_PARAMETER
;
281 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
282 Service
= Instance
->Service
;
284 if ((Instance
->Config
== NULL
) && (Dhcp6ConfigData
!= NULL
)) {
285 return EFI_ACCESS_DENIED
;
288 ASSERT (Service
->ClientId
!= NULL
);
290 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
293 // User needs a copy of instance config data.
295 if (Dhcp6ConfigData
!= NULL
) {
296 ZeroMem (Dhcp6ConfigData
, sizeof (EFI_DHCP6_CONFIG_DATA
));
298 // Duplicate config data, including all reference buffers.
300 if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData
, Instance
->Config
))) {
306 // User need a copy of instance mode data.
308 if (Dhcp6ModeData
!= NULL
) {
309 ZeroMem (Dhcp6ModeData
, sizeof (EFI_DHCP6_MODE_DATA
));
311 // Duplicate a copy of EFI_DHCP6_DUID for client Id.
313 IdSize
= Service
->ClientId
->Length
+ sizeof (Service
->ClientId
->Length
);
315 Dhcp6ModeData
->ClientId
= AllocateZeroPool (IdSize
);
316 if (Dhcp6ModeData
->ClientId
== NULL
) {
321 Dhcp6ModeData
->ClientId
,
326 Ia
= Instance
->IaCb
.Ia
;
329 // Duplicate a copy of EFI_DHCP6_IA for configured Ia.
331 IaSize
= sizeof (EFI_DHCP6_IA
) + (Ia
->IaAddressCount
-1) * sizeof (EFI_DHCP6_IA_ADDRESS
);
333 Dhcp6ModeData
->Ia
= AllocateZeroPool (IaSize
);
334 if (Dhcp6ModeData
->Ia
== NULL
) {
345 // Duplicate a copy of reply packet if has.
347 if (Ia
->ReplyPacket
!= NULL
) {
348 Dhcp6ModeData
->Ia
->ReplyPacket
= AllocateZeroPool (Ia
->ReplyPacket
->Size
);
349 if (Dhcp6ModeData
->Ia
->ReplyPacket
== NULL
) {
354 Dhcp6ModeData
->Ia
->ReplyPacket
,
356 Ia
->ReplyPacket
->Size
362 gBS
->RestoreTPL (OldTpl
);
368 if (Dhcp6ConfigData
!= NULL
) {
369 Dhcp6CleanupConfigData (Dhcp6ConfigData
);
372 if (Dhcp6ModeData
!= NULL
) {
373 Dhcp6CleanupModeData (Dhcp6ModeData
);
376 gBS
->RestoreTPL (OldTpl
);
378 return EFI_OUT_OF_RESOURCES
;
382 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
384 The Configure() function is used to initialize or clean up the configuration
385 data of the Dhcp6 instance:
386 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
387 configuration data will be initialized in the Dhcp6 instance, and the state
388 of the configured IA will be transferred into Dhcp6Init.
389 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
390 configuration data will be cleaned up and no IA will be associated with
392 To update the configuration data for an Dhcp6 instance, the original data
393 must be cleaned up before setting the new configuration data.
395 @param[in] This The pointer to the Dhcp6 protocol
396 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
398 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
399 Dhcp6Init state, or cleaned up the original
400 configuration setting.
401 @retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.
402 The Dhcp6 instance has already started the
403 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
404 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
405 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
406 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
412 IN EFI_DHCP6_PROTOCOL
*This
,
413 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
419 DHCP6_INSTANCE
*Other
;
420 DHCP6_INSTANCE
*Instance
;
421 DHCP6_SERVICE
*Service
;
425 return EFI_INVALID_PARAMETER
;
428 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
429 Service
= Instance
->Service
;
432 // Check the parameter of configure data.
434 if (Dhcp6CfgData
!= NULL
) {
435 if ((Dhcp6CfgData
->OptionCount
> 0) && (Dhcp6CfgData
->OptionList
== NULL
)) {
436 return EFI_INVALID_PARAMETER
;
439 if (Dhcp6CfgData
->OptionList
!= NULL
) {
440 for (Index
= 0; Index
< Dhcp6CfgData
->OptionCount
; Index
++) {
441 if ((Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptClientId
) ||
442 (Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptRapidCommit
) ||
443 (Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptReconfigureAccept
) ||
444 (Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptIana
) ||
445 (Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptIata
)
448 return EFI_INVALID_PARAMETER
;
453 if ((Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_NA
) &&
454 (Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_TA
)
457 return EFI_INVALID_PARAMETER
;
460 if ((Dhcp6CfgData
->IaInfoEvent
== NULL
) && (Dhcp6CfgData
->SolicitRetransmission
== NULL
)) {
461 return EFI_INVALID_PARAMETER
;
464 if ((Dhcp6CfgData
->SolicitRetransmission
!= NULL
) &&
465 (Dhcp6CfgData
->SolicitRetransmission
->Mrc
== 0) &&
466 (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
)
482 return EFI_INVALID_PARAMETER
;
487 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
489 if (Dhcp6CfgData
!= NULL
) {
491 // It's not allowed to configure one instance twice without configure null.
493 if (Instance
->Config
!= NULL
) {
494 gBS
->RestoreTPL (OldTpl
);
495 return EFI_ACCESS_DENIED
;
499 // Duplicate config data including all reference buffers.
501 Instance
->Config
= AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA
));
502 if (Instance
->Config
== NULL
) {
503 gBS
->RestoreTPL (OldTpl
);
504 return EFI_OUT_OF_RESOURCES
;
507 Status
= Dhcp6CopyConfigData (Instance
->Config
, Dhcp6CfgData
);
508 if (EFI_ERROR (Status
)) {
509 FreePool (Instance
->Config
);
510 gBS
->RestoreTPL (OldTpl
);
511 return EFI_OUT_OF_RESOURCES
;
515 // Initialize the Ia descriptor from the config data, and leave the other
516 // fields of the Ia as default value 0.
518 Instance
->IaCb
.Ia
= AllocateZeroPool (sizeof (EFI_DHCP6_IA
));
519 if (Instance
->IaCb
.Ia
== NULL
) {
520 Dhcp6CleanupConfigData (Instance
->Config
);
521 FreePool (Instance
->Config
);
522 gBS
->RestoreTPL (OldTpl
);
523 return EFI_OUT_OF_RESOURCES
;
527 &Instance
->IaCb
.Ia
->Descriptor
,
528 &Dhcp6CfgData
->IaDescriptor
,
529 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
);
560 Request configuration information without the assignment of any
561 Ia addresses of the client.
563 The InfoRequest() function is used to request configuration information
564 without the assignment of any IPv6 address of the client. The client sends
565 out an Information Request packet to obtain the required configuration
566 information, and DHCPv6 server responds with a Reply packet containing
567 the information for the client. The received Reply packet will be passed
568 to the user by ReplyCallback function. If the user returns EFI_NOT_READY from
569 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
570 packets unless timeout according to the Retransmission parameter.
571 Otherwise, the Information Request exchange process will be finished
572 successfully if user returns EFI_SUCCESS from ReplyCallback.
574 @param[in] This The pointer to the Dhcp6 protocol.
575 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
576 Identifier option and include it into Information Request
577 packet. Otherwise, Client Identifier option will not be included.
578 @param[in] OptionRequest The pointer to the buffer of option request options.
579 @param[in] OptionCount The option number in the OptionList.
580 @param[in] OptionList The list of appended options.
581 @param[in] Retransmission The pointer to the retransmission of the message.
582 @param[in] TimeoutEvent The event of timeout.
583 @param[in] ReplyCallback The callback function when the reply was received.
584 @param[in] CallbackContext The pointer to the parameter passed to the callback.
586 @retval EFI_SUCCESS The DHCPv6 information request exchange process
587 completed when TimeoutEvent is NULL. Information
588 Request packet has been sent to DHCPv6 server when
589 TimeoutEvent is not NULL.
590 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
591 because of no response, or not all requested-options
592 are responded by DHCPv6 servers when Timeout happened.
593 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
595 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
596 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
597 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
602 EfiDhcp6InfoRequest (
603 IN EFI_DHCP6_PROTOCOL
*This
,
604 IN BOOLEAN SendClientId
,
605 IN EFI_DHCP6_PACKET_OPTION
*OptionRequest
,
606 IN UINT32 OptionCount
,
607 IN EFI_DHCP6_PACKET_OPTION
*OptionList
[] OPTIONAL
,
608 IN EFI_DHCP6_RETRANSMISSION
*Retransmission
,
609 IN EFI_EVENT TimeoutEvent OPTIONAL
,
610 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback
,
611 IN VOID
*CallbackContext OPTIONAL
615 DHCP6_INSTANCE
*Instance
;
616 DHCP6_SERVICE
*Service
;
619 EFI_STATUS TimerStatus
;
620 UINTN GetMappingTimeOut
;
622 if ((This
== NULL
) || (OptionRequest
== NULL
) || (Retransmission
== NULL
) || (ReplyCallback
== NULL
)) {
623 return EFI_INVALID_PARAMETER
;
626 if ((Retransmission
!= NULL
) && (Retransmission
->Mrc
== 0) && (Retransmission
->Mrd
== 0)) {
627 return EFI_INVALID_PARAMETER
;
630 if ((OptionCount
> 0) && (OptionList
== NULL
)) {
631 return EFI_INVALID_PARAMETER
;
634 if (OptionList
!= NULL
) {
635 for (Index
= 0; Index
< OptionCount
; Index
++) {
636 if ((OptionList
[Index
]->OpCode
== Dhcp6OptClientId
) || (OptionList
[Index
]->OpCode
== Dhcp6OptRequestOption
)) {
637 return EFI_INVALID_PARAMETER
;
642 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
643 Service
= Instance
->Service
;
645 Status
= Dhcp6StartInfoRequest (
656 if (Status
== EFI_NO_MAPPING
) {
658 // The link local address is not ready, wait for some time and restart
659 // the DHCP6 information request process.
661 Status
= Dhcp6GetMappingTimeOut (Service
->Ip6Cfg
, &GetMappingTimeOut
);
662 if (EFI_ERROR (Status
)) {
666 Status
= gBS
->CreateEvent (EVT_TIMER
, TPL_CALLBACK
, NULL
, NULL
, &Timer
);
667 if (EFI_ERROR (Status
)) {
672 // Start the timer, wait for link local address DAD to finish.
674 Status
= gBS
->SetTimer (Timer
, TimerRelative
, GetMappingTimeOut
);
675 if (EFI_ERROR (Status
)) {
676 gBS
->CloseEvent (Timer
);
681 TimerStatus
= gBS
->CheckEvent (Timer
);
682 if (!EFI_ERROR (TimerStatus
)) {
683 Status
= Dhcp6StartInfoRequest (
695 } while (TimerStatus
== EFI_NOT_READY
);
697 gBS
->CloseEvent (Timer
);
700 if (EFI_ERROR (Status
)) {
705 // Poll udp out of the net tpl if synchronous call.
707 if (TimeoutEvent
== NULL
) {
708 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
709 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
712 return Instance
->UdpSts
;
719 Manually extend the valid and preferred lifetimes for the IPv6 addresses
720 of the configured IA and update other configuration parameters by sending a
721 Renew or Rebind packet.
723 The RenewRebind() function is used to manually extend the valid and preferred
724 lifetimes for the IPv6 addresses of the configured IA, and update other
725 configuration parameters by sending Renew or Rebind packet.
726 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
727 it sends Renew packet to the previously DHCPv6 server and transfer the
728 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
729 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
730 If fails, the state transfers to Dhcp6Bound, but the timer continues.
731 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
732 it will send a Rebind packet. If valid Reply packet is received, the state transfers
733 to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
734 transfers to Dhcp6Init, and the IA can't be used.
736 @param[in] This The pointer to the Dhcp6 protocol.
737 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
738 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
740 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has
741 completed and at least one IPv6 address of the
742 configured IA has been bound again when
743 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
744 The EFI DHCPv6 Protocol instance has sent Renew
745 or Rebind packet when
746 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
747 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
748 state of the configured IA is not in Dhcp6Bound.
749 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
750 Dhcp6Renewing when RebindRequest is FALSE.
751 The state of the configured IA has already entered
752 Dhcp6Rebinding when RebindRequest is TRUE.
753 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
755 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
756 because of no response.
757 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
758 IA after the DHCPv6 renew/rebind exchange process.
759 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
760 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
765 EfiDhcp6RenewRebind (
766 IN EFI_DHCP6_PROTOCOL
*This
,
767 IN BOOLEAN RebindRequest
772 DHCP6_INSTANCE
*Instance
;
773 DHCP6_SERVICE
*Service
;
776 return EFI_INVALID_PARAMETER
;
779 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
780 Service
= Instance
->Service
;
783 // The instance hasn't been configured.
785 if (Instance
->Config
== NULL
) {
786 return EFI_ACCESS_DENIED
;
789 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
792 // The instance has already entered renewing or rebinding state.
794 if (((Instance
->IaCb
.Ia
->State
== Dhcp6Rebinding
) && RebindRequest
) ||
795 ((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 synchronous call.
836 if (Instance
->Config
->IaInfoEvent
== NULL
) {
837 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
838 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
841 return Instance
->UdpSts
;
848 gBS
->RestoreTPL (OldTpl
);
853 Inform that one or more addresses assigned by a server are already
854 in use by another node.
856 The Decline() function is used to manually decline the assignment of
857 IPv6 addresses, which have been already used by another node. If all
858 IPv6 addresses of the configured IA are declined through this function,
859 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
860 Otherwise, the state of the IA will restore to Dhcp6Bound after the
861 declining process. The Decline() can only be called when the IA is in
862 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
863 this function is a blocking operation. It will return after the
864 declining process finishes, or aborted by user.
866 @param[in] This The pointer to EFI_DHCP6_PROTOCOL.
867 @param[in] AddressCount The number of declining addresses.
868 @param[in] Addresses The pointer to the buffer stored the declining
871 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
872 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
873 The Dhcp6 instance sent Decline packet when
874 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
875 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
876 state of the configured IA is not in Dhcp6Bound.
877 @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
878 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
879 the configured IA for this instance.
880 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
881 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
887 IN EFI_DHCP6_PROTOCOL
*This
,
888 IN UINT32 AddressCount
,
889 IN EFI_IPv6_ADDRESS
*Addresses
895 DHCP6_INSTANCE
*Instance
;
896 DHCP6_SERVICE
*Service
;
898 if ((This
== NULL
) || (AddressCount
== 0) || (Addresses
== NULL
)) {
899 return EFI_INVALID_PARAMETER
;
902 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
903 Service
= Instance
->Service
;
906 // The instance hasn't been configured.
908 if (Instance
->Config
== NULL
) {
909 return EFI_ACCESS_DENIED
;
912 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
914 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
915 return EFI_ACCESS_DENIED
;
919 // Check whether all the declined addresses belongs to the configured Ia.
921 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
923 if (EFI_ERROR (Status
)) {
927 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
928 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
931 // Deprive of all the declined addresses from the configured Ia, and create a
932 // DeclineIa used to create decline message.
934 DecIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
937 Status
= EFI_OUT_OF_RESOURCES
;
942 // Send the decline message to start exchange process.
944 Status
= Dhcp6SendDeclineMsg (Instance
, DecIa
);
946 if (EFI_ERROR (Status
)) {
951 // Register receive callback for the stateful exchange process.
953 Status
= UdpIoRecvDatagram (
960 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
965 gBS
->RestoreTPL (OldTpl
);
968 // Poll udp out of the net tpl if synchronous call.
970 if (Instance
->Config
->IaInfoEvent
== NULL
) {
971 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
972 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
975 return Instance
->UdpSts
;
986 gBS
->RestoreTPL (OldTpl
);
992 Release one or more addresses associated with the configured Ia
993 for current instance.
995 The Release() function is used to manually release one or more
996 IPv6 addresses. If AddressCount is zero, it will release all IPv6
997 addresses of the configured IA. If all IPv6 addresses of the IA are
998 released through this function, the state of the IA will switch
999 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
1000 IA will restore to Dhcp6Bound after the releasing process.
1001 The Release() can only be called when the IA is in Dhcp6Bound state.
1002 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
1003 a blocking operation. It will return after the releasing process
1004 finishes, or is aborted by user.
1006 @param[in] This The pointer to the Dhcp6 protocol.
1007 @param[in] AddressCount The number of releasing addresses.
1008 @param[in] Addresses The pointer to the buffer stored the releasing
1011 @retval EFI_SUCCESS The DHCPv6 release exchange process
1012 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1013 was NULL. The Dhcp6 instance was sent Release
1014 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1016 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
1017 state of the configured IA is not in Dhcp6Bound.
1018 @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
1019 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
1020 the configured IA for this instance.
1021 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1022 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1028 IN EFI_DHCP6_PROTOCOL
*This
,
1029 IN UINT32 AddressCount
,
1030 IN EFI_IPv6_ADDRESS
*Addresses
1035 EFI_DHCP6_IA
*RelIa
;
1036 DHCP6_INSTANCE
*Instance
;
1037 DHCP6_SERVICE
*Service
;
1039 if ((This
== NULL
) || ((AddressCount
!= 0) && (Addresses
== NULL
))) {
1040 return EFI_INVALID_PARAMETER
;
1043 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
1044 Service
= Instance
->Service
;
1047 // The instance hasn't been configured.
1049 if (Instance
->Config
== NULL
) {
1050 return EFI_ACCESS_DENIED
;
1053 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
1055 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
1056 return EFI_ACCESS_DENIED
;
1060 // Check whether all the released addresses belongs to the configured Ia.
1062 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1064 if (EFI_ERROR (Status
)) {
1068 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1069 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
1072 // Deprive of all the released addresses from the configured Ia, and create a
1073 // ReleaseIa used to create release message.
1075 RelIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1077 if (RelIa
== NULL
) {
1078 Status
= EFI_OUT_OF_RESOURCES
;
1083 // Send the release message to start exchange process.
1085 Status
= Dhcp6SendReleaseMsg (Instance
, RelIa
);
1087 if (EFI_ERROR (Status
)) {
1092 // Register receive callback for the stateful exchange process.
1094 Status
= UdpIoRecvDatagram (
1101 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
1106 gBS
->RestoreTPL (OldTpl
);
1109 // Poll udp out of the net tpl if synchronous call.
1111 if (Instance
->Config
->IaInfoEvent
== NULL
) {
1112 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
1113 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
1116 return Instance
->UdpSts
;
1123 if (RelIa
!= NULL
) {
1127 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
) {
1219 PacketOptionList
[OptCnt
] = (EFI_DHCP6_PACKET_OPTION
*)Start
;
1220 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*)Start
)->OpLen
;
1221 Start
+= (NTOHS (DataLen
) + 4);