2 This EFI_DHCP6_PROTOCOL interface implementation.
4 Copyright (c) 2009 - 2012, 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
;
81 return EFI_INVALID_PARAMETER
;
84 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
85 Service
= Instance
->Service
;
88 // The instance hasn't been configured.
90 if (Instance
->Config
== NULL
) {
91 return EFI_ACCESS_DENIED
;
94 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
97 // The instance has already been started.
99 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
100 return EFI_ALREADY_STARTED
;
103 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
104 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
107 // Need to clear initial time to make sure that elapsed-time
108 // is set to 0 for first Solicit.
110 Instance
->StartTime
= 0;
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
) {
142 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
143 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
145 return Instance
->UdpSts
;
152 gBS
->RestoreTPL (OldTpl
);
158 Stops the DHCPv6 standard S.A.R.R. process.
160 The Stop() function is used to stop the DHCPv6 standard process. After this
161 function is called successfully, the state of Dhcp6 instance is transferred
162 into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
163 before DHCPv6 standard process can be started again. This function can be
164 called when the Dhcp6 instance is in any state.
166 @param[in] This The pointer to the Dhcp6 protocol.
168 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
169 @retval EFI_INVALID_PARAMETER This is NULL.
175 IN EFI_DHCP6_PROTOCOL
*This
180 EFI_UDP6_PROTOCOL
*Udp6
;
181 DHCP6_INSTANCE
*Instance
;
182 DHCP6_SERVICE
*Service
;
185 return EFI_INVALID_PARAMETER
;
188 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
189 Service
= Instance
->Service
;
190 Udp6
= Service
->UdpIo
->Protocol
.Udp6
;
191 Status
= EFI_SUCCESS
;
194 // The instance hasn't been configured.
196 if (Instance
->Config
== NULL
) {
200 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
203 // No valid REPLY message received yet, cleanup this instance directly.
205 if (Instance
->IaCb
.Ia
->State
== Dhcp6Init
||
206 Instance
->IaCb
.Ia
->State
== Dhcp6Selecting
||
207 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 if (EFI_ERROR (Status
)) {
223 gBS
->RestoreTPL (OldTpl
);
226 // Poll udp out of the net tpl if synchoronus call.
228 if (Instance
->Config
->IaInfoEvent
== NULL
) {
229 ASSERT (Udp6
!= NULL
);
230 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
);
249 Returns the current operating mode data for the Dhcp6 instance.
251 The GetModeData() function returns the current operating mode and
252 cached data packet for the Dhcp6 instance.
254 @param[in] This The pointer to the Dhcp6 protocol.
255 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
256 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
258 @retval EFI_SUCCESS The mode data was returned.
259 @retval EFI_INVALID_PARAMETER This is NULL.
260 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not
265 EfiDhcp6GetModeData (
266 IN EFI_DHCP6_PROTOCOL
*This
,
267 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
268 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
273 DHCP6_INSTANCE
*Instance
;
274 DHCP6_SERVICE
*Service
;
278 if (This
== NULL
|| (Dhcp6ModeData
== NULL
&& Dhcp6ConfigData
== NULL
)) {
279 return EFI_INVALID_PARAMETER
;
282 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
283 Service
= Instance
->Service
;
285 if (Instance
->Config
== NULL
&& Dhcp6ConfigData
!= NULL
) {
286 return EFI_ACCESS_DENIED
;
289 ASSERT (Service
->ClientId
!= NULL
);
291 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
294 // User needs a copy of instance config data.
296 if (Dhcp6ConfigData
!= NULL
) {
297 ZeroMem (Dhcp6ConfigData
, sizeof(EFI_DHCP6_CONFIG_DATA
));
299 // Duplicate config data, including all reference buffers.
301 if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData
, Instance
->Config
))) {
307 // User need a copy of instance mode data.
309 if (Dhcp6ModeData
!= NULL
) {
310 ZeroMem (Dhcp6ModeData
, sizeof (EFI_DHCP6_MODE_DATA
));
312 // Duplicate a copy of EFI_DHCP6_DUID for client Id.
314 IdSize
= Service
->ClientId
->Length
+ sizeof (Service
->ClientId
->Length
);
316 Dhcp6ModeData
->ClientId
= AllocateZeroPool (IdSize
);
317 if (Dhcp6ModeData
->ClientId
== NULL
) {
322 Dhcp6ModeData
->ClientId
,
327 Ia
= Instance
->IaCb
.Ia
;
330 // Duplicate a copy of EFI_DHCP6_IA for configured Ia.
332 IaSize
= sizeof (EFI_DHCP6_IA
) + (Ia
->IaAddressCount
-1) * sizeof (EFI_DHCP6_IA_ADDRESS
);
334 Dhcp6ModeData
->Ia
= AllocateZeroPool (IaSize
);
335 if (Dhcp6ModeData
->Ia
== NULL
) {
346 // Duplicate a copy of reply packet if has.
348 if (Ia
->ReplyPacket
!= NULL
) {
349 Dhcp6ModeData
->Ia
->ReplyPacket
= AllocateZeroPool (Ia
->ReplyPacket
->Size
);
350 if (Dhcp6ModeData
->Ia
->ReplyPacket
== NULL
) {
354 Dhcp6ModeData
->Ia
->ReplyPacket
,
356 Ia
->ReplyPacket
->Size
362 gBS
->RestoreTPL (OldTpl
);
368 if (Dhcp6ConfigData
!= NULL
) {
369 Dhcp6CleanupConfigData (Dhcp6ConfigData
);
371 if (Dhcp6ModeData
!= NULL
) {
372 Dhcp6CleanupModeData (Dhcp6ModeData
);
374 gBS
->RestoreTPL (OldTpl
);
376 return EFI_OUT_OF_RESOURCES
;
381 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
383 The Configure() function is used to initialize or clean up the configuration
384 data of the Dhcp6 instance:
385 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
386 configuration data will be initialized in the Dhcp6 instance, and the state
387 of the configured IA will be transferred into Dhcp6Init.
388 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
389 configuration data will be cleaned up and no IA will be associated with
391 To update the configuration data for an Dhcp6 instance, the original data
392 must be cleaned up before setting the new configuration data.
394 @param[in] This The pointer to the Dhcp6 protocol
395 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
397 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
398 Dhcp6Init state, or cleaned up the original
399 configuration setting.
400 @retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.
401 The Dhcp6 instance has already started the
402 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
403 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
404 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
405 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
411 IN EFI_DHCP6_PROTOCOL
*This
,
412 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
418 DHCP6_INSTANCE
*Other
;
419 DHCP6_INSTANCE
*Instance
;
420 DHCP6_SERVICE
*Service
;
424 return EFI_INVALID_PARAMETER
;
427 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
428 Service
= Instance
->Service
;
431 // Check the parameter of configure data.
433 if (Dhcp6CfgData
!= NULL
) {
434 if (Dhcp6CfgData
->OptionCount
> 0 && Dhcp6CfgData
->OptionList
== NULL
) {
435 return EFI_INVALID_PARAMETER
;
437 if (Dhcp6CfgData
->OptionList
!= NULL
) {
438 for (Index
= 0; Index
< Dhcp6CfgData
->OptionCount
; Index
++) {
439 if (Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptClientId
||
440 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptRapidCommit
||
441 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptReconfigureAccept
||
442 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptIana
||
443 Dhcp6CfgData
->OptionList
[Index
]->OpCode
== Dhcp6OptIata
445 return EFI_INVALID_PARAMETER
;
450 if (Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_NA
&&
451 Dhcp6CfgData
->IaDescriptor
.Type
!= EFI_DHCP6_IA_TYPE_TA
453 return EFI_INVALID_PARAMETER
;
456 if (Dhcp6CfgData
->IaInfoEvent
== NULL
&& Dhcp6CfgData
->SolicitRetransmission
== NULL
) {
457 return EFI_INVALID_PARAMETER
;
460 if (Dhcp6CfgData
->SolicitRetransmission
!= NULL
&&
461 Dhcp6CfgData
->SolicitRetransmission
->Mrc
== 0 &&
462 Dhcp6CfgData
->SolicitRetransmission
->Mrd
== 0
464 return EFI_INVALID_PARAMETER
;
468 // Make sure the (IaId, IaType) is unique over all the instances.
470 NET_LIST_FOR_EACH (Entry
, &Service
->Child
) {
471 Other
= NET_LIST_USER_STRUCT (Entry
, DHCP6_INSTANCE
, Link
);
472 if (Other
->IaCb
.Ia
!= NULL
&&
473 Other
->IaCb
.Ia
->Descriptor
.Type
== Dhcp6CfgData
->IaDescriptor
.Type
&&
474 Other
->IaCb
.Ia
->Descriptor
.IaId
== Dhcp6CfgData
->IaDescriptor
.IaId
476 return EFI_INVALID_PARAMETER
;
481 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
483 if (Dhcp6CfgData
!= NULL
) {
485 // It's not allowed to configure one instance twice without configure null.
487 if (Instance
->Config
!= NULL
) {
488 gBS
->RestoreTPL (OldTpl
);
489 return EFI_ACCESS_DENIED
;
493 // Duplicate config data including all reference buffers.
495 Instance
->Config
= AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA
));
496 if (Instance
->Config
== NULL
) {
497 gBS
->RestoreTPL (OldTpl
);
498 return EFI_OUT_OF_RESOURCES
;
501 Status
= Dhcp6CopyConfigData (Instance
->Config
, Dhcp6CfgData
);
502 if (EFI_ERROR(Status
)) {
503 FreePool (Instance
->Config
);
504 gBS
->RestoreTPL (OldTpl
);
505 return EFI_OUT_OF_RESOURCES
;
509 // Initialize the Ia descriptor from the config data, and leave the other
510 // fields of the Ia as default value 0.
512 Instance
->IaCb
.Ia
= AllocateZeroPool (sizeof(EFI_DHCP6_IA
));
513 if (Instance
->IaCb
.Ia
== NULL
) {
514 Dhcp6CleanupConfigData (Instance
->Config
);
515 FreePool (Instance
->Config
);
516 gBS
->RestoreTPL (OldTpl
);
517 return EFI_OUT_OF_RESOURCES
;
520 &Instance
->IaCb
.Ia
->Descriptor
,
521 &Dhcp6CfgData
->IaDescriptor
,
522 sizeof(EFI_DHCP6_IA_DESCRIPTOR
)
527 if (Instance
->Config
== NULL
) {
528 ASSERT (Instance
->IaCb
.Ia
== NULL
);
529 gBS
->RestoreTPL (OldTpl
);
534 // It's not allowed to configure a started instance as null.
536 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Init
) {
537 gBS
->RestoreTPL (OldTpl
);
538 return EFI_ACCESS_DENIED
;
541 Dhcp6CleanupConfigData (Instance
->Config
);
542 FreePool (Instance
->Config
);
543 Instance
->Config
= NULL
;
545 FreePool (Instance
->IaCb
.Ia
);
546 Instance
->IaCb
.Ia
= NULL
;
549 gBS
->RestoreTPL (OldTpl
);
556 Request configuration information without the assignment of any
557 Ia addresses of the client.
559 The InfoRequest() function is used to request configuration information
560 without the assignment of any IPv6 address of the client. The client sends
561 out an Information Request packet to obtain the required configuration
562 information, and DHCPv6 server responds with a Reply packet containing
563 the information for the client. The received Reply packet will be passed
564 to the user by ReplyCallback function. If the user returns EFI_NOT_READY from
565 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
566 packets unless timeout according to the Retransmission parameter.
567 Otherwise, the Information Request exchange process will be finished
568 successfully if user returns EFI_SUCCESS from ReplyCallback.
570 @param[in] This The pointer to the Dhcp6 protocol.
571 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
572 Identifier option and include it into Information Request
573 packet. Otherwise, Client Identifier option will not be included.
574 @param[in] OptionRequest The pointer to the buffer of option request options.
575 @param[in] OptionCount The option number in the OptionList.
576 @param[in] OptionList The list of appended options.
577 @param[in] Retransmission The pointer to the retransmission of the message.
578 @param[in] TimeoutEvent The event of timeout.
579 @param[in] ReplyCallback The callback function when the reply was received.
580 @param[in] CallbackContext The pointer to the parameter passed to the callback.
582 @retval EFI_SUCCESS The DHCPv6 information request exchange process
583 completed when TimeoutEvent is NULL. Information
584 Request packet has been sent to DHCPv6 server when
585 TimeoutEvent is not NULL.
586 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
587 because of no response, or not all requested-options
588 are responded by DHCPv6 servers when Timeout happened.
589 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
591 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
592 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
593 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
598 EfiDhcp6InfoRequest (
599 IN EFI_DHCP6_PROTOCOL
*This
,
600 IN BOOLEAN SendClientId
,
601 IN EFI_DHCP6_PACKET_OPTION
*OptionRequest
,
602 IN UINT32 OptionCount
,
603 IN EFI_DHCP6_PACKET_OPTION
*OptionList
[] OPTIONAL
,
604 IN EFI_DHCP6_RETRANSMISSION
*Retransmission
,
605 IN EFI_EVENT TimeoutEvent OPTIONAL
,
606 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback
,
607 IN VOID
*CallbackContext OPTIONAL
611 DHCP6_INSTANCE
*Instance
;
612 DHCP6_SERVICE
*Service
;
615 EFI_STATUS TimerStatus
;
616 UINTN GetMappingTimeOut
;
618 if (This
== NULL
|| OptionRequest
== NULL
|| Retransmission
== NULL
|| ReplyCallback
== NULL
) {
619 return EFI_INVALID_PARAMETER
;
622 if (Retransmission
!= NULL
&& Retransmission
->Mrc
== 0 && Retransmission
->Mrd
== 0) {
623 return EFI_INVALID_PARAMETER
;
626 if (OptionCount
> 0 && OptionList
== NULL
) {
627 return EFI_INVALID_PARAMETER
;
630 if (OptionList
!= NULL
) {
631 for (Index
= 0; Index
< OptionCount
; Index
++) {
632 if (OptionList
[Index
]->OpCode
== Dhcp6OptClientId
|| OptionList
[Index
]->OpCode
== Dhcp6OptRequestOption
) {
633 return EFI_INVALID_PARAMETER
;
638 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
639 Service
= Instance
->Service
;
641 Status
= Dhcp6StartInfoRequest (
652 if (Status
== EFI_NO_MAPPING
) {
654 // The link local address is not ready, wait for some time and restart
655 // the DHCP6 information request process.
657 Status
= Dhcp6GetMappingTimeOut(Service
->Ip6Cfg
, &GetMappingTimeOut
);
658 if (EFI_ERROR(Status
)) {
662 Status
= gBS
->CreateEvent (EVT_TIMER
, TPL_CALLBACK
, NULL
, NULL
, &Timer
);
663 if (EFI_ERROR (Status
)) {
668 // Start the timer, wait for link local address DAD to finish.
670 Status
= gBS
->SetTimer (Timer
, TimerRelative
, GetMappingTimeOut
);
671 if (EFI_ERROR (Status
)) {
672 gBS
->CloseEvent (Timer
);
677 TimerStatus
= gBS
->CheckEvent (Timer
);
678 if (!EFI_ERROR (TimerStatus
)) {
679 Status
= Dhcp6StartInfoRequest (
691 } while (TimerStatus
== EFI_NOT_READY
);
693 gBS
->CloseEvent (Timer
);
695 if (EFI_ERROR (Status
)) {
700 // Poll udp out of the net tpl if synchoronus call.
702 if (TimeoutEvent
== NULL
) {
704 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
705 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
707 return Instance
->UdpSts
;
715 Manually extend the valid and preferred lifetimes for the IPv6 addresses
716 of the configured IA and update other configuration parameters by sending a
717 Renew or Rebind packet.
719 The RenewRebind() function is used to manually extend the valid and preferred
720 lifetimes for the IPv6 addresses of the configured IA, and update other
721 configuration parameters by sending Renew or Rebind packet.
722 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
723 it sends Renew packet to the previously DHCPv6 server and transfer the
724 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
725 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
726 If fails, the state transfers to Dhcp6Bound, but the timer continues.
727 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
728 it will send a Rebind packet. If valid Reply packet is received, the state transfers
729 to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
730 transfers to Dhcp6Init, and the IA can't be used.
732 @param[in] This The pointer to the Dhcp6 protocol.
733 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
734 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
736 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has
737 completed and at least one IPv6 address of the
738 configured IA has been bound again when
739 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
740 The EFI DHCPv6 Protocol instance has sent Renew
741 or Rebind packet when
742 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
743 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
744 state of the configured IA is not in Dhcp6Bound.
745 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
746 Dhcp6Renewing when RebindRequest is FALSE.
747 The state of the configured IA has already entered
748 Dhcp6Rebinding when RebindRequest is TRUE.
749 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
751 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
752 because of no response.
753 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
754 IA after the DHCPv6 renew/rebind exchange process.
755 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
756 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
761 EfiDhcp6RenewRebind (
762 IN EFI_DHCP6_PROTOCOL
*This
,
763 IN BOOLEAN RebindRequest
768 DHCP6_INSTANCE
*Instance
;
769 DHCP6_SERVICE
*Service
;
772 return EFI_INVALID_PARAMETER
;
775 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
776 Service
= Instance
->Service
;
779 // The instance hasn't been configured.
781 if (Instance
->Config
== NULL
) {
782 return EFI_ACCESS_DENIED
;
785 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
788 // The instance has already entered renewing or rebinding state.
790 if ((Instance
->IaCb
.Ia
->State
== Dhcp6Rebinding
&& RebindRequest
) ||
791 (Instance
->IaCb
.Ia
->State
== Dhcp6Renewing
&& !RebindRequest
)
793 return EFI_ALREADY_STARTED
;
796 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
797 return EFI_ACCESS_DENIED
;
800 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
801 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
804 // Send renew/rebind message to start exchange process.
806 Status
= Dhcp6SendRenewRebindMsg (Instance
, RebindRequest
);
808 if (EFI_ERROR (Status
)) {
813 // Register receive callback for the stateful exchange process.
815 Status
= UdpIoRecvDatagram(
822 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
826 gBS
->RestoreTPL (OldTpl
);
829 // Poll udp out of the net tpl if synchoronus call.
831 if (Instance
->Config
->IaInfoEvent
== NULL
) {
833 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
834 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
836 return Instance
->UdpSts
;
843 gBS
->RestoreTPL (OldTpl
);
849 Inform that one or more addresses assigned by a server are already
850 in use by another node.
852 The Decline() function is used to manually decline the assignment of
853 IPv6 addresses, which have been already used by another node. If all
854 IPv6 addresses of the configured IA are declined through this function,
855 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
856 Otherwise, the state of the IA will restore to Dhcp6Bound after the
857 declining process. The Decline() can only be called when the IA is in
858 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
859 this function is a blocking operation. It will return after the
860 declining process finishes, or aborted by user.
862 @param[in] This The pointer to EFI_DHCP6_PROTOCOL.
863 @param[in] AddressCount The number of declining addresses.
864 @param[in] Addresses The pointer to the buffer stored the declining
867 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
868 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
869 The Dhcp6 instance sent Decline packet when
870 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
871 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
872 state of the configured IA is not in Dhcp6Bound.
873 @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
874 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
875 the configured IA for this instance.
876 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
877 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
883 IN EFI_DHCP6_PROTOCOL
*This
,
884 IN UINT32 AddressCount
,
885 IN EFI_IPv6_ADDRESS
*Addresses
891 DHCP6_INSTANCE
*Instance
;
892 DHCP6_SERVICE
*Service
;
894 if (This
== NULL
|| AddressCount
== 0 || Addresses
== NULL
) {
895 return EFI_INVALID_PARAMETER
;
898 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
899 Service
= Instance
->Service
;
902 // The instance hasn't been configured.
904 if (Instance
->Config
== NULL
) {
905 return EFI_ACCESS_DENIED
;
908 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
910 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
911 return EFI_ACCESS_DENIED
;
915 // Check whether all the declined addresses belongs to the configured Ia.
917 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
919 if (EFI_ERROR(Status
)) {
923 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
924 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
927 // Deprive of all the declined addresses from the configured Ia, and create a
928 // DeclineIa used to create decline message.
930 DecIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
933 Status
= EFI_OUT_OF_RESOURCES
;
938 // Send the decline message to start exchange process.
940 Status
= Dhcp6SendDeclineMsg (Instance
, DecIa
);
942 if (EFI_ERROR (Status
)) {
947 // Register receive callback for the stateful exchange process.
949 Status
= UdpIoRecvDatagram(
956 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
961 gBS
->RestoreTPL (OldTpl
);
964 // Poll udp out of the net tpl if synchoronus call.
966 if (Instance
->Config
->IaInfoEvent
== NULL
) {
968 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
969 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
971 return Instance
->UdpSts
;
981 gBS
->RestoreTPL (OldTpl
);
988 Release one or more addresses associated with the configured Ia
989 for current instance.
991 The Release() function is used to manually release one or more
992 IPv6 addresses. If AddressCount is zero, it will release all IPv6
993 addresses of the configured IA. If all IPv6 addresses of the IA are
994 released through this function, the state of the IA will switch
995 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
996 IA will restore to Dhcp6Bound after the releasing process.
997 The Release() can only be called when the IA is in Dhcp6Bound state.
998 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
999 a blocking operation. It will return after the releasing process
1000 finishes, or is aborted by user.
1002 @param[in] This The pointer to the Dhcp6 protocol.
1003 @param[in] AddressCount The number of releasing addresses.
1004 @param[in] Addresses The pointer to the buffer stored the releasing
1007 @retval EFI_SUCCESS The DHCPv6 release exchange process
1008 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1009 was NULL. The Dhcp6 instance was sent Release
1010 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1012 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
1013 state of the configured IA is not in Dhcp6Bound.
1014 @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
1015 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
1016 the configured IA for this instance.
1017 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1018 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1024 IN EFI_DHCP6_PROTOCOL
*This
,
1025 IN UINT32 AddressCount
,
1026 IN EFI_IPv6_ADDRESS
*Addresses
1031 EFI_DHCP6_IA
*RelIa
;
1032 DHCP6_INSTANCE
*Instance
;
1033 DHCP6_SERVICE
*Service
;
1035 if (This
== NULL
|| (AddressCount
!= 0 && Addresses
== NULL
)) {
1036 return EFI_INVALID_PARAMETER
;
1039 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
1040 Service
= Instance
->Service
;
1043 // The instance hasn't been configured.
1045 if (Instance
->Config
== NULL
) {
1046 return EFI_ACCESS_DENIED
;
1049 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
1051 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
1052 return EFI_ACCESS_DENIED
;
1056 // Check whether all the released addresses belongs to the configured Ia.
1058 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1060 if (EFI_ERROR(Status
)) {
1064 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1065 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
1068 // Deprive of all the released addresses from the configured Ia, and create a
1069 // ReleaseIa used to create release message.
1071 RelIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1073 if (RelIa
== NULL
) {
1074 Status
= EFI_OUT_OF_RESOURCES
;
1079 // Send the release message to start exchange process.
1081 Status
= Dhcp6SendReleaseMsg (Instance
, RelIa
);
1083 if (EFI_ERROR (Status
)) {
1088 // Register receive callback for the stateful exchange process.
1090 Status
= UdpIoRecvDatagram(
1097 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
1102 gBS
->RestoreTPL (OldTpl
);
1105 // Poll udp out of the net tpl if synchoronus call.
1107 if (Instance
->Config
->IaInfoEvent
== NULL
) {
1108 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
1109 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
1111 return Instance
->UdpSts
;
1118 if (RelIa
!= NULL
) {
1121 gBS
->RestoreTPL (OldTpl
);
1128 Parse the option data in the Dhcp6 packet.
1130 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
1132 @param[in] This The pointer to the Dhcp6 protocol.
1133 @param[in] Packet The pointer to the Dhcp6 packet.
1134 @param[in, out] OptionCount The number of option in the packet.
1135 @param[out] PacketOptionList The array of pointers to each option in the packet.
1137 @retval EFI_SUCCESS The packet was successfully parsed.
1138 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1139 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
1140 that were found in the Packet.
1146 IN EFI_DHCP6_PROTOCOL
*This
,
1147 IN EFI_DHCP6_PACKET
*Packet
,
1148 IN OUT UINT32
*OptionCount
,
1149 OUT EFI_DHCP6_PACKET_OPTION
*PacketOptionList
[] OPTIONAL
1158 if (This
== NULL
|| Packet
== NULL
|| OptionCount
== NULL
) {
1159 return EFI_INVALID_PARAMETER
;
1162 if (*OptionCount
!= 0 && PacketOptionList
== NULL
) {
1163 return EFI_INVALID_PARAMETER
;
1166 if (Packet
->Length
> Packet
->Size
|| Packet
->Length
< sizeof (EFI_DHCP6_HEADER
)) {
1167 return EFI_INVALID_PARAMETER
;
1171 // The format of Dhcp6 option:
1173 // 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
1174 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1175 // | option-code | option-len (option data) |
1176 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1178 // | (option-len octets) |
1179 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1183 OptLen
= Packet
->Length
- sizeof (EFI_DHCP6_HEADER
);
1184 Start
= Packet
->Dhcp6
.Option
;
1185 End
= Start
+ OptLen
;
1188 // Calculate the number of option in the packet.
1190 while (Start
< End
) {
1191 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1192 Start
+= (NTOHS (DataLen
) + 4);
1197 // It will return buffer too small if pass-in option count is smaller than the
1198 // actual count of options in the packet.
1200 if (OptCnt
> *OptionCount
) {
1201 *OptionCount
= OptCnt
;
1202 return EFI_BUFFER_TOO_SMALL
;
1207 (*OptionCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*))
1211 Start
= Packet
->Dhcp6
.Option
;
1213 while (Start
< End
) {
1215 PacketOptionList
[OptCnt
] = (EFI_DHCP6_PACKET_OPTION
*) Start
;
1216 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1217 Start
+= (NTOHS (DataLen
) + 4);