2 This EFI_DHCP6_PROTOCOL interface implementation.
4 Copyright (c) 2009 - 2018, 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
23 EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress
= {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};
25 EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate
= {
38 Starts the DHCPv6 standard S.A.R.R. process.
40 The Start() function starts the DHCPv6 standard process. This function can
41 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
42 If the DHCP process completes successfully, the state of the Dhcp6 instance
43 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
45 Refer to rfc-3315 for precise state transitions during this process. At the
46 time when each event occurs in this process, the callback function that was set
47 by EFI_DHCP6_PROTOCOL.Configure() will be called, and the user can take this
48 opportunity to control the process.
50 @param[in] This The pointer to Dhcp6 protocol.
52 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it has
53 completed when CompletionEvent is NULL.
54 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
55 @retval EFI_INVALID_PARAMETER This is NULL.
56 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
57 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
58 response was received from the server within the
59 specified timeout value.
60 @retval EFI_ABORTED The user aborted the DHCPv6 process.
61 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
63 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
64 @retval EFI_NO_MEDIA There was a media error.
70 IN EFI_DHCP6_PROTOCOL
*This
75 DHCP6_INSTANCE
*Instance
;
76 DHCP6_SERVICE
*Service
;
77 EFI_STATUS MediaStatus
;
80 return EFI_INVALID_PARAMETER
;
83 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
84 Service
= Instance
->Service
;
87 // The instance hasn't been configured.
89 if (Instance
->Config
== NULL
) {
90 return EFI_ACCESS_DENIED
;
93 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
96 // The instance has already been started.
98 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
99 return EFI_ALREADY_STARTED
;
102 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
105 // Check Media Satus.
107 MediaStatus
= EFI_SUCCESS
;
108 NetLibDetectMediaWaitTimeout (Service
->Controller
, DHCP_CHECK_MEDIA_WAITING_TIME
, &MediaStatus
);
109 if (MediaStatus
!= EFI_SUCCESS
) {
110 Status
= EFI_NO_MEDIA
;
114 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
117 // Send the solicit message to start S.A.R.R process.
119 Status
= Dhcp6SendSolicitMsg (Instance
);
121 if (EFI_ERROR (Status
)) {
126 // Register receive callback for the stateful exchange process.
128 Status
= UdpIoRecvDatagram(
135 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
139 gBS
->RestoreTPL (OldTpl
);
142 // Poll udp out of the net tpl if synchronous call.
144 if (Instance
->Config
->IaInfoEvent
== NULL
) {
146 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
147 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
149 return Instance
->UdpSts
;
156 gBS
->RestoreTPL (OldTpl
);
162 Stops the DHCPv6 standard S.A.R.R. process.
164 The Stop() function is used to stop the DHCPv6 standard process. After this
165 function is called successfully, the state of Dhcp6 instance is transferred
166 into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
167 before DHCPv6 standard process can be started again. This function can be
168 called when the Dhcp6 instance is in any state.
170 @param[in] This The pointer to the Dhcp6 protocol.
172 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
173 @retval EFI_INVALID_PARAMETER This is NULL.
179 IN EFI_DHCP6_PROTOCOL
*This
184 EFI_UDP6_PROTOCOL
*Udp6
;
185 DHCP6_INSTANCE
*Instance
;
186 DHCP6_SERVICE
*Service
;
189 return EFI_INVALID_PARAMETER
;
192 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
193 Service
= Instance
->Service
;
194 Udp6
= Service
->UdpIo
->Protocol
.Udp6
;
195 Status
= EFI_SUCCESS
;
198 // The instance hasn't been configured.
200 if (Instance
->Config
== NULL
) {
204 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
207 // No valid REPLY message received yet, cleanup this instance directly.
209 if (Instance
->IaCb
.Ia
->State
== Dhcp6Init
||
210 Instance
->IaCb
.Ia
->State
== Dhcp6Selecting
||
211 Instance
->IaCb
.Ia
->State
== Dhcp6Requesting
217 // Release the current ready Ia.
219 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
221 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
222 Status
= Dhcp6SendReleaseMsg (Instance
, Instance
->IaCb
.Ia
);
223 gBS
->RestoreTPL (OldTpl
);
224 if (EFI_ERROR (Status
)) {
229 // Poll udp out of the net tpl if synchoronus call.
231 if (Instance
->Config
->IaInfoEvent
== NULL
) {
232 ASSERT (Udp6
!= NULL
);
233 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
236 Status
= Instance
->UdpSts
;
241 // Clean up the session data for the released Ia.
243 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
244 Dhcp6CleanupSession (Instance
, EFI_SUCCESS
);
245 gBS
->RestoreTPL (OldTpl
);
252 Returns the current operating mode data for the Dhcp6 instance.
254 The GetModeData() function returns the current operating mode and
255 cached data packet for the Dhcp6 instance.
257 @param[in] This The pointer to the Dhcp6 protocol.
258 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
259 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
261 @retval EFI_SUCCESS The mode data was returned.
262 @retval EFI_INVALID_PARAMETER This is NULL.
263 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not
268 EfiDhcp6GetModeData (
269 IN EFI_DHCP6_PROTOCOL
*This
,
270 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
271 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
276 DHCP6_INSTANCE
*Instance
;
277 DHCP6_SERVICE
*Service
;
281 if (This
== NULL
|| (Dhcp6ModeData
== NULL
&& Dhcp6ConfigData
== NULL
)) {
282 return EFI_INVALID_PARAMETER
;
285 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
286 Service
= Instance
->Service
;
288 if (Instance
->Config
== NULL
&& Dhcp6ConfigData
!= NULL
) {
289 return EFI_ACCESS_DENIED
;
292 ASSERT (Service
->ClientId
!= NULL
);
294 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
297 // User needs a copy of instance config data.
299 if (Dhcp6ConfigData
!= NULL
) {
300 ZeroMem (Dhcp6ConfigData
, sizeof(EFI_DHCP6_CONFIG_DATA
));
302 // Duplicate config data, including all reference buffers.
304 if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData
, Instance
->Config
))) {
310 // User need a copy of instance mode data.
312 if (Dhcp6ModeData
!= NULL
) {
313 ZeroMem (Dhcp6ModeData
, sizeof (EFI_DHCP6_MODE_DATA
));
315 // Duplicate a copy of EFI_DHCP6_DUID for client Id.
317 IdSize
= Service
->ClientId
->Length
+ sizeof (Service
->ClientId
->Length
);
319 Dhcp6ModeData
->ClientId
= AllocateZeroPool (IdSize
);
320 if (Dhcp6ModeData
->ClientId
== NULL
) {
325 Dhcp6ModeData
->ClientId
,
330 Ia
= Instance
->IaCb
.Ia
;
333 // Duplicate a copy of EFI_DHCP6_IA for configured Ia.
335 IaSize
= sizeof (EFI_DHCP6_IA
) + (Ia
->IaAddressCount
-1) * sizeof (EFI_DHCP6_IA_ADDRESS
);
337 Dhcp6ModeData
->Ia
= AllocateZeroPool (IaSize
);
338 if (Dhcp6ModeData
->Ia
== NULL
) {
349 // Duplicate a copy of reply packet if has.
351 if (Ia
->ReplyPacket
!= NULL
) {
352 Dhcp6ModeData
->Ia
->ReplyPacket
= AllocateZeroPool (Ia
->ReplyPacket
->Size
);
353 if (Dhcp6ModeData
->Ia
->ReplyPacket
== NULL
) {
357 Dhcp6ModeData
->Ia
->ReplyPacket
,
359 Ia
->ReplyPacket
->Size
365 gBS
->RestoreTPL (OldTpl
);
371 if (Dhcp6ConfigData
!= NULL
) {
372 Dhcp6CleanupConfigData (Dhcp6ConfigData
);
374 if (Dhcp6ModeData
!= NULL
) {
375 Dhcp6CleanupModeData (Dhcp6ModeData
);
377 gBS
->RestoreTPL (OldTpl
);
379 return EFI_OUT_OF_RESOURCES
;
384 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
386 The Configure() function is used to initialize or clean up the configuration
387 data of the Dhcp6 instance:
388 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
389 configuration data will be initialized in the Dhcp6 instance, and the state
390 of the configured IA will be transferred into Dhcp6Init.
391 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
392 configuration data will be cleaned up and no IA will be associated with
394 To update the configuration data for an Dhcp6 instance, the original data
395 must be cleaned up before setting the new configuration data.
397 @param[in] This The pointer to the Dhcp6 protocol
398 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
400 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
401 Dhcp6Init state, or cleaned up the original
402 configuration setting.
403 @retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.
404 The Dhcp6 instance has already started the
405 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
406 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
407 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
408 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
414 IN EFI_DHCP6_PROTOCOL
*This
,
415 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
421 DHCP6_INSTANCE
*Other
;
422 DHCP6_INSTANCE
*Instance
;
423 DHCP6_SERVICE
*Service
;
427 return EFI_INVALID_PARAMETER
;
430 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
431 Service
= Instance
->Service
;
434 // Check the parameter of configure data.
436 if (Dhcp6CfgData
!= NULL
) {
437 if (Dhcp6CfgData
->OptionCount
> 0 && Dhcp6CfgData
->OptionList
== NULL
) {
438 return EFI_INVALID_PARAMETER
;
440 if (Dhcp6CfgData
->OptionList
!= NULL
) {
441 for (Index
= 0; Index
< Dhcp6CfgData
->OptionCount
; Index
++) {
442 if (Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptClientId
||
443 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptRapidCommit
||
444 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptReconfigureAccept
||
445 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptIana
||
446 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
456 return EFI_INVALID_PARAMETER
;
459 if (Dhcp6CfgData
->IaInfoEvent
== NULL
&& Dhcp6CfgData
->SolicitRetransmission
== NULL
) {
460 return EFI_INVALID_PARAMETER
;
463 if (Dhcp6CfgData
->SolicitRetransmission
!= NULL
&&
464 Dhcp6CfgData
->SolicitRetransmission
->Mrc
== 0 &&
465 Dhcp6CfgData
->SolicitRetransmission
->Mrd
== 0
467 return EFI_INVALID_PARAMETER
;
471 // Make sure the (IaId, IaType) is unique over all the instances.
473 NET_LIST_FOR_EACH (Entry
, &Service
->Child
) {
474 Other
= NET_LIST_USER_STRUCT (Entry
, DHCP6_INSTANCE
, Link
);
475 if (Other
->IaCb
.Ia
!= NULL
&&
476 Other
->IaCb
.Ia
->Descriptor
.Type
== Dhcp6CfgData
->IaDescriptor
.Type
&&
477 Other
->IaCb
.Ia
->Descriptor
.IaId
== Dhcp6CfgData
->IaDescriptor
.IaId
479 return EFI_INVALID_PARAMETER
;
484 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
486 if (Dhcp6CfgData
!= NULL
) {
488 // It's not allowed to configure one instance twice without configure null.
490 if (Instance
->Config
!= NULL
) {
491 gBS
->RestoreTPL (OldTpl
);
492 return EFI_ACCESS_DENIED
;
496 // Duplicate config data including all reference buffers.
498 Instance
->Config
= AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA
));
499 if (Instance
->Config
== NULL
) {
500 gBS
->RestoreTPL (OldTpl
);
501 return EFI_OUT_OF_RESOURCES
;
504 Status
= Dhcp6CopyConfigData (Instance
->Config
, Dhcp6CfgData
);
505 if (EFI_ERROR(Status
)) {
506 FreePool (Instance
->Config
);
507 gBS
->RestoreTPL (OldTpl
);
508 return EFI_OUT_OF_RESOURCES
;
512 // Initialize the Ia descriptor from the config data, and leave the other
513 // fields of the Ia as default value 0.
515 Instance
->IaCb
.Ia
= AllocateZeroPool (sizeof(EFI_DHCP6_IA
));
516 if (Instance
->IaCb
.Ia
== NULL
) {
517 Dhcp6CleanupConfigData (Instance
->Config
);
518 FreePool (Instance
->Config
);
519 gBS
->RestoreTPL (OldTpl
);
520 return EFI_OUT_OF_RESOURCES
;
523 &Instance
->IaCb
.Ia
->Descriptor
,
524 &Dhcp6CfgData
->IaDescriptor
,
525 sizeof(EFI_DHCP6_IA_DESCRIPTOR
)
530 if (Instance
->Config
== NULL
) {
531 ASSERT (Instance
->IaCb
.Ia
== NULL
);
532 gBS
->RestoreTPL (OldTpl
);
537 // It's not allowed to configure a started instance as null.
539 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
540 gBS
->RestoreTPL (OldTpl
);
541 return EFI_ACCESS_DENIED
;
544 Dhcp6CleanupConfigData (Instance
->Config
);
545 FreePool (Instance
->Config
);
546 Instance
->Config
= NULL
;
548 FreePool (Instance
->IaCb
.Ia
);
549 Instance
->IaCb
.Ia
= NULL
;
552 gBS
->RestoreTPL (OldTpl
);
559 Request configuration information without the assignment of any
560 Ia addresses of the client.
562 The InfoRequest() function is used to request configuration information
563 without the assignment of any IPv6 address of the client. The client sends
564 out an Information Request packet to obtain the required configuration
565 information, and DHCPv6 server responds with a Reply packet containing
566 the information for the client. The received Reply packet will be passed
567 to the user by ReplyCallback function. If the user returns EFI_NOT_READY from
568 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
569 packets unless timeout according to the Retransmission parameter.
570 Otherwise, the Information Request exchange process will be finished
571 successfully if user returns EFI_SUCCESS from ReplyCallback.
573 @param[in] This The pointer to the Dhcp6 protocol.
574 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
575 Identifier option and include it into Information Request
576 packet. Otherwise, Client Identifier option will not be included.
577 @param[in] OptionRequest The pointer to the buffer of option request options.
578 @param[in] OptionCount The option number in the OptionList.
579 @param[in] OptionList The list of appended options.
580 @param[in] Retransmission The pointer to the retransmission of the message.
581 @param[in] TimeoutEvent The event of timeout.
582 @param[in] ReplyCallback The callback function when the reply was received.
583 @param[in] CallbackContext The pointer to the parameter passed to the callback.
585 @retval EFI_SUCCESS The DHCPv6 information request exchange process
586 completed when TimeoutEvent is NULL. Information
587 Request packet has been sent to DHCPv6 server when
588 TimeoutEvent is not NULL.
589 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
590 because of no response, or not all requested-options
591 are responded by DHCPv6 servers when Timeout happened.
592 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
594 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
595 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
596 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
601 EfiDhcp6InfoRequest (
602 IN EFI_DHCP6_PROTOCOL
*This
,
603 IN BOOLEAN SendClientId
,
604 IN EFI_DHCP6_PACKET_OPTION
*OptionRequest
,
605 IN UINT32 OptionCount
,
606 IN EFI_DHCP6_PACKET_OPTION
*OptionList
[] OPTIONAL
,
607 IN EFI_DHCP6_RETRANSMISSION
*Retransmission
,
608 IN EFI_EVENT TimeoutEvent OPTIONAL
,
609 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback
,
610 IN VOID
*CallbackContext OPTIONAL
614 DHCP6_INSTANCE
*Instance
;
615 DHCP6_SERVICE
*Service
;
618 EFI_STATUS TimerStatus
;
619 UINTN GetMappingTimeOut
;
621 if (This
== NULL
|| OptionRequest
== NULL
|| Retransmission
== NULL
|| ReplyCallback
== NULL
) {
622 return EFI_INVALID_PARAMETER
;
625 if (Retransmission
!= NULL
&& Retransmission
->Mrc
== 0 && Retransmission
->Mrd
== 0) {
626 return EFI_INVALID_PARAMETER
;
629 if (OptionCount
> 0 && OptionList
== NULL
) {
630 return EFI_INVALID_PARAMETER
;
633 if (OptionList
!= NULL
) {
634 for (Index
= 0; Index
< OptionCount
; Index
++) {
635 if (OptionList
[Index
]->OpCode
== Dhcp6OptClientId
|| OptionList
[Index
]->OpCode
== Dhcp6OptRequestOption
) {
636 return EFI_INVALID_PARAMETER
;
641 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
642 Service
= Instance
->Service
;
644 Status
= Dhcp6StartInfoRequest (
655 if (Status
== EFI_NO_MAPPING
) {
657 // The link local address is not ready, wait for some time and restart
658 // the DHCP6 information request process.
660 Status
= Dhcp6GetMappingTimeOut(Service
->Ip6Cfg
, &GetMappingTimeOut
);
661 if (EFI_ERROR(Status
)) {
665 Status
= gBS
->CreateEvent (EVT_TIMER
, TPL_CALLBACK
, NULL
, NULL
, &Timer
);
666 if (EFI_ERROR (Status
)) {
671 // Start the timer, wait for link local address DAD to finish.
673 Status
= gBS
->SetTimer (Timer
, TimerRelative
, GetMappingTimeOut
);
674 if (EFI_ERROR (Status
)) {
675 gBS
->CloseEvent (Timer
);
680 TimerStatus
= gBS
->CheckEvent (Timer
);
681 if (!EFI_ERROR (TimerStatus
)) {
682 Status
= Dhcp6StartInfoRequest (
694 } while (TimerStatus
== EFI_NOT_READY
);
696 gBS
->CloseEvent (Timer
);
698 if (EFI_ERROR (Status
)) {
703 // Poll udp out of the net tpl if synchoronus call.
705 if (TimeoutEvent
== NULL
) {
707 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
708 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
710 return Instance
->UdpSts
;
718 Manually extend the valid and preferred lifetimes for the IPv6 addresses
719 of the configured IA and update other configuration parameters by sending a
720 Renew or Rebind packet.
722 The RenewRebind() function is used to manually extend the valid and preferred
723 lifetimes for the IPv6 addresses of the configured IA, and update other
724 configuration parameters by sending Renew or Rebind packet.
725 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
726 it sends Renew packet to the previously DHCPv6 server and transfer the
727 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
728 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
729 If fails, the state transfers to Dhcp6Bound, but the timer continues.
730 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
731 it will send a Rebind packet. If valid Reply packet is received, the state transfers
732 to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
733 transfers to Dhcp6Init, and the IA can't be used.
735 @param[in] This The pointer to the Dhcp6 protocol.
736 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
737 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
739 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has
740 completed and at least one IPv6 address of the
741 configured IA has been bound again when
742 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
743 The EFI DHCPv6 Protocol instance has sent Renew
744 or Rebind packet when
745 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
746 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
747 state of the configured IA is not in Dhcp6Bound.
748 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
749 Dhcp6Renewing when RebindRequest is FALSE.
750 The state of the configured IA has already entered
751 Dhcp6Rebinding when RebindRequest is TRUE.
752 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
754 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
755 because of no response.
756 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
757 IA after the DHCPv6 renew/rebind exchange process.
758 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
759 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
764 EfiDhcp6RenewRebind (
765 IN EFI_DHCP6_PROTOCOL
*This
,
766 IN BOOLEAN RebindRequest
771 DHCP6_INSTANCE
*Instance
;
772 DHCP6_SERVICE
*Service
;
775 return EFI_INVALID_PARAMETER
;
778 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
779 Service
= Instance
->Service
;
782 // The instance hasn't been configured.
784 if (Instance
->Config
== NULL
) {
785 return EFI_ACCESS_DENIED
;
788 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
791 // The instance has already entered renewing or rebinding state.
793 if ((Instance
->IaCb
.Ia
->State
== Dhcp6Rebinding
&& RebindRequest
) ||
794 (Instance
->IaCb
.Ia
->State
== Dhcp6Renewing
&& !RebindRequest
)
796 return EFI_ALREADY_STARTED
;
799 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
800 return EFI_ACCESS_DENIED
;
803 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
804 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
807 // Send renew/rebind message to start exchange process.
809 Status
= Dhcp6SendRenewRebindMsg (Instance
, RebindRequest
);
811 if (EFI_ERROR (Status
)) {
816 // Register receive callback for the stateful exchange process.
818 Status
= UdpIoRecvDatagram(
825 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
829 gBS
->RestoreTPL (OldTpl
);
832 // Poll udp out of the net tpl if synchoronus call.
834 if (Instance
->Config
->IaInfoEvent
== NULL
) {
836 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
837 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
839 return Instance
->UdpSts
;
846 gBS
->RestoreTPL (OldTpl
);
852 Inform that one or more addresses assigned by a server are already
853 in use by another node.
855 The Decline() function is used to manually decline the assignment of
856 IPv6 addresses, which have been already used by another node. If all
857 IPv6 addresses of the configured IA are declined through this function,
858 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
859 Otherwise, the state of the IA will restore to Dhcp6Bound after the
860 declining process. The Decline() can only be called when the IA is in
861 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
862 this function is a blocking operation. It will return after the
863 declining process finishes, or aborted by user.
865 @param[in] This The pointer to EFI_DHCP6_PROTOCOL.
866 @param[in] AddressCount The number of declining addresses.
867 @param[in] Addresses The pointer to the buffer stored the declining
870 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
871 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
872 The Dhcp6 instance sent Decline packet when
873 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
874 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
875 state of the configured IA is not in Dhcp6Bound.
876 @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
877 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
878 the configured IA for this instance.
879 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
880 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
886 IN EFI_DHCP6_PROTOCOL
*This
,
887 IN UINT32 AddressCount
,
888 IN EFI_IPv6_ADDRESS
*Addresses
894 DHCP6_INSTANCE
*Instance
;
895 DHCP6_SERVICE
*Service
;
897 if (This
== NULL
|| AddressCount
== 0 || Addresses
== NULL
) {
898 return EFI_INVALID_PARAMETER
;
901 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
902 Service
= Instance
->Service
;
905 // The instance hasn't been configured.
907 if (Instance
->Config
== NULL
) {
908 return EFI_ACCESS_DENIED
;
911 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
913 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
914 return EFI_ACCESS_DENIED
;
918 // Check whether all the declined addresses belongs to the configured Ia.
920 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
922 if (EFI_ERROR(Status
)) {
926 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
927 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
930 // Deprive of all the declined addresses from the configured Ia, and create a
931 // DeclineIa used to create decline message.
933 DecIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
936 Status
= EFI_OUT_OF_RESOURCES
;
941 // Send the decline message to start exchange process.
943 Status
= Dhcp6SendDeclineMsg (Instance
, DecIa
);
945 if (EFI_ERROR (Status
)) {
950 // Register receive callback for the stateful exchange process.
952 Status
= UdpIoRecvDatagram(
959 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
964 gBS
->RestoreTPL (OldTpl
);
967 // Poll udp out of the net tpl if synchoronus call.
969 if (Instance
->Config
->IaInfoEvent
== NULL
) {
971 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
972 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
974 return Instance
->UdpSts
;
984 gBS
->RestoreTPL (OldTpl
);
991 Release one or more addresses associated with the configured Ia
992 for current instance.
994 The Release() function is used to manually release one or more
995 IPv6 addresses. If AddressCount is zero, it will release all IPv6
996 addresses of the configured IA. If all IPv6 addresses of the IA are
997 released through this function, the state of the IA will switch
998 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
999 IA will restore to Dhcp6Bound after the releasing process.
1000 The Release() can only be called when the IA is in Dhcp6Bound state.
1001 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
1002 a blocking operation. It will return after the releasing process
1003 finishes, or is aborted by user.
1005 @param[in] This The pointer to the Dhcp6 protocol.
1006 @param[in] AddressCount The number of releasing addresses.
1007 @param[in] Addresses The pointer to the buffer stored the releasing
1010 @retval EFI_SUCCESS The DHCPv6 release exchange process
1011 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1012 was NULL. The Dhcp6 instance was sent Release
1013 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1015 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
1016 state of the configured IA is not in Dhcp6Bound.
1017 @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
1018 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
1019 the configured IA for this instance.
1020 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1021 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1027 IN EFI_DHCP6_PROTOCOL
*This
,
1028 IN UINT32 AddressCount
,
1029 IN EFI_IPv6_ADDRESS
*Addresses
1034 EFI_DHCP6_IA
*RelIa
;
1035 DHCP6_INSTANCE
*Instance
;
1036 DHCP6_SERVICE
*Service
;
1038 if (This
== NULL
|| (AddressCount
!= 0 && Addresses
== NULL
)) {
1039 return EFI_INVALID_PARAMETER
;
1042 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
1043 Service
= Instance
->Service
;
1046 // The instance hasn't been configured.
1048 if (Instance
->Config
== NULL
) {
1049 return EFI_ACCESS_DENIED
;
1052 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
1054 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
1055 return EFI_ACCESS_DENIED
;
1059 // Check whether all the released addresses belongs to the configured Ia.
1061 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1063 if (EFI_ERROR(Status
)) {
1067 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1068 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
1071 // Deprive of all the released addresses from the configured Ia, and create a
1072 // ReleaseIa used to create release message.
1074 RelIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1076 if (RelIa
== NULL
) {
1077 Status
= EFI_OUT_OF_RESOURCES
;
1082 // Send the release message to start exchange process.
1084 Status
= Dhcp6SendReleaseMsg (Instance
, RelIa
);
1086 if (EFI_ERROR (Status
)) {
1091 // Register receive callback for the stateful exchange process.
1093 Status
= UdpIoRecvDatagram(
1100 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
1105 gBS
->RestoreTPL (OldTpl
);
1108 // Poll udp out of the net tpl if synchoronus call.
1110 if (Instance
->Config
->IaInfoEvent
== NULL
) {
1111 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
1112 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
1114 return Instance
->UdpSts
;
1121 if (RelIa
!= NULL
) {
1124 gBS
->RestoreTPL (OldTpl
);
1131 Parse the option data in the Dhcp6 packet.
1133 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
1135 @param[in] This The pointer to the Dhcp6 protocol.
1136 @param[in] Packet The pointer to the Dhcp6 packet.
1137 @param[in, out] OptionCount The number of option in the packet.
1138 @param[out] PacketOptionList The array of pointers to each option in the packet.
1140 @retval EFI_SUCCESS The packet was successfully parsed.
1141 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1142 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
1143 that were found in the Packet.
1149 IN EFI_DHCP6_PROTOCOL
*This
,
1150 IN EFI_DHCP6_PACKET
*Packet
,
1151 IN OUT UINT32
*OptionCount
,
1152 OUT EFI_DHCP6_PACKET_OPTION
*PacketOptionList
[] OPTIONAL
1161 if (This
== NULL
|| Packet
== NULL
|| OptionCount
== NULL
) {
1162 return EFI_INVALID_PARAMETER
;
1165 if (*OptionCount
!= 0 && PacketOptionList
== NULL
) {
1166 return EFI_INVALID_PARAMETER
;
1169 if (Packet
->Length
> Packet
->Size
|| Packet
->Length
< sizeof (EFI_DHCP6_HEADER
)) {
1170 return EFI_INVALID_PARAMETER
;
1174 // The format of Dhcp6 option:
1176 // 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
1177 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1178 // | option-code | option-len (option data) |
1179 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1181 // | (option-len octets) |
1182 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1186 OptLen
= Packet
->Length
- sizeof (EFI_DHCP6_HEADER
);
1187 Start
= Packet
->Dhcp6
.Option
;
1188 End
= Start
+ OptLen
;
1191 // Calculate the number of option in the packet.
1193 while (Start
< End
) {
1194 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1195 Start
+= (NTOHS (DataLen
) + 4);
1200 // It will return buffer too small if pass-in option count is smaller than the
1201 // actual count of options in the packet.
1203 if (OptCnt
> *OptionCount
) {
1204 *OptionCount
= OptCnt
;
1205 return EFI_BUFFER_TOO_SMALL
;
1210 (*OptionCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*))
1214 Start
= Packet
->Dhcp6
.Option
;
1216 while (Start
< End
) {
1218 PacketOptionList
[OptCnt
] = (EFI_DHCP6_PACKET_OPTION
*) Start
;
1219 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1220 Start
+= (NTOHS (DataLen
) + 4);