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
612 DHCP6_INSTANCE
*Instance
;
613 DHCP6_SERVICE
*Service
;
617 if (This
== NULL
|| OptionRequest
== NULL
|| Retransmission
== NULL
|| ReplyCallback
== NULL
) {
618 return EFI_INVALID_PARAMETER
;
621 if (Retransmission
!= NULL
&& Retransmission
->Mrc
== 0 && Retransmission
->Mrd
== 0) {
622 return EFI_INVALID_PARAMETER
;
625 if (OptionCount
> 0 && OptionList
== NULL
) {
626 return EFI_INVALID_PARAMETER
;
629 if (OptionList
!= NULL
) {
630 for (Index
= 0; Index
< OptionCount
; Index
++) {
631 if (OptionList
[Index
]->OpCode
== Dhcp6OptClientId
|| OptionList
[Index
]->OpCode
== Dhcp6OptRequestOption
) {
632 return EFI_INVALID_PARAMETER
;
637 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
638 Service
= Instance
->Service
;
640 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
641 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
644 // Create and initialize the control block for the info-request.
646 InfCb
= AllocateZeroPool (sizeof(DHCP6_INF_CB
));
649 gBS
->RestoreTPL (OldTpl
);
650 return EFI_OUT_OF_RESOURCES
;
653 InfCb
->ReplyCallback
= ReplyCallback
;
654 InfCb
->CallbackContext
= CallbackContext
;
655 InfCb
->TimeoutEvent
= TimeoutEvent
;
657 InsertTailList (&Instance
->InfList
, &InfCb
->Link
);
660 // Send the info-request message to start exchange process.
662 Status
= Dhcp6SendInfoRequestMsg (
672 if (EFI_ERROR (Status
)) {
677 // Register receive callback for the stateless exchange process.
679 Status
= UdpIoRecvDatagram(
686 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
690 gBS
->RestoreTPL (OldTpl
);
693 // Poll udp out of the net tpl if synchoronus call.
695 if (TimeoutEvent
== NULL
) {
697 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
698 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
700 return Instance
->UdpSts
;
707 RemoveEntryList (&InfCb
->Link
);
709 gBS
->RestoreTPL (OldTpl
);
716 Manually extend the valid and preferred lifetimes for the IPv6 addresses
717 of the configured IA and update other configuration parameters by sending a
718 Renew or Rebind packet.
720 The RenewRebind() function is used to manually extend the valid and preferred
721 lifetimes for the IPv6 addresses of the configured IA, and update other
722 configuration parameters by sending Renew or Rebind packet.
723 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
724 it sends Renew packet to the previously DHCPv6 server and transfer the
725 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
726 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
727 If fails, the state transfers to Dhcp6Bound, but the timer continues.
728 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
729 it will send a Rebind packet. If valid Reply packet is received, the state transfers
730 to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
731 transfers to Dhcp6Init, and the IA can't be used.
733 @param[in] This The pointer to the Dhcp6 protocol.
734 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
735 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
737 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has
738 completed and at least one IPv6 address of the
739 configured IA has been bound again when
740 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
741 The EFI DHCPv6 Protocol instance has sent Renew
742 or Rebind packet when
743 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
744 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
745 state of the configured IA is not in Dhcp6Bound.
746 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
747 Dhcp6Renewing when RebindRequest is FALSE.
748 The state of the configured IA has already entered
749 Dhcp6Rebinding when RebindRequest is TRUE.
750 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
752 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
753 because of no response.
754 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
755 IA after the DHCPv6 renew/rebind exchange process.
756 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
757 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
762 EfiDhcp6RenewRebind (
763 IN EFI_DHCP6_PROTOCOL
*This
,
764 IN BOOLEAN RebindRequest
769 DHCP6_INSTANCE
*Instance
;
770 DHCP6_SERVICE
*Service
;
773 return EFI_INVALID_PARAMETER
;
776 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
777 Service
= Instance
->Service
;
780 // The instance hasn't been configured.
782 if (Instance
->Config
== NULL
) {
783 return EFI_ACCESS_DENIED
;
786 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
789 // The instance has already entered renewing or rebinding state.
791 if ((Instance
->IaCb
.Ia
->State
== Dhcp6Rebinding
&& RebindRequest
) ||
792 (Instance
->IaCb
.Ia
->State
== Dhcp6Renewing
&& !RebindRequest
)
794 return EFI_ALREADY_STARTED
;
797 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
798 return EFI_ACCESS_DENIED
;
801 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
802 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
805 // Send renew/rebind message to start exchange process.
807 Status
= Dhcp6SendRenewRebindMsg (Instance
, RebindRequest
);
809 if (EFI_ERROR (Status
)) {
814 // Register receive callback for the stateful exchange process.
816 Status
= UdpIoRecvDatagram(
823 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
827 gBS
->RestoreTPL (OldTpl
);
830 // Poll udp out of the net tpl if synchoronus call.
832 if (Instance
->Config
->IaInfoEvent
== NULL
) {
834 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
835 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
837 return Instance
->UdpSts
;
844 gBS
->RestoreTPL (OldTpl
);
850 Inform that one or more addresses assigned by a server are already
851 in use by another node.
853 The Decline() function is used to manually decline the assignment of
854 IPv6 addresses, which have been already used by another node. If all
855 IPv6 addresses of the configured IA are declined through this function,
856 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
857 Otherwise, the state of the IA will restore to Dhcp6Bound after the
858 declining process. The Decline() can only be called when the IA is in
859 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
860 this function is a blocking operation. It will return after the
861 declining process finishes, or aborted by user.
863 @param[in] This The pointer to EFI_DHCP6_PROTOCOL.
864 @param[in] AddressCount The number of declining addresses.
865 @param[in] Addresses The pointer to the buffer stored the declining
868 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
869 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
870 The Dhcp6 instance sent Decline packet when
871 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
872 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
873 state of the configured IA is not in Dhcp6Bound.
874 @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
875 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
876 the configured IA for this instance.
877 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
878 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
884 IN EFI_DHCP6_PROTOCOL
*This
,
885 IN UINT32 AddressCount
,
886 IN EFI_IPv6_ADDRESS
*Addresses
892 DHCP6_INSTANCE
*Instance
;
893 DHCP6_SERVICE
*Service
;
895 if (This
== NULL
|| AddressCount
== 0 || Addresses
== NULL
) {
896 return EFI_INVALID_PARAMETER
;
899 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
900 Service
= Instance
->Service
;
903 // The instance hasn't been configured.
905 if (Instance
->Config
== NULL
) {
906 return EFI_ACCESS_DENIED
;
909 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
911 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
912 return EFI_ACCESS_DENIED
;
916 // Check whether all the declined addresses belongs to the configured Ia.
918 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
920 if (EFI_ERROR(Status
)) {
924 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
925 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
928 // Deprive of all the declined addresses from the configured Ia, and create a
929 // DeclineIa used to create decline message.
931 DecIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
934 Status
= EFI_OUT_OF_RESOURCES
;
939 // Send the decline message to start exchange process.
941 Status
= Dhcp6SendDeclineMsg (Instance
, DecIa
);
943 if (EFI_ERROR (Status
)) {
948 // Register receive callback for the stateful exchange process.
950 Status
= UdpIoRecvDatagram(
957 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
962 gBS
->RestoreTPL (OldTpl
);
965 // Poll udp out of the net tpl if synchoronus call.
967 if (Instance
->Config
->IaInfoEvent
== NULL
) {
969 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
970 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
972 return Instance
->UdpSts
;
982 gBS
->RestoreTPL (OldTpl
);
989 Release one or more addresses associated with the configured Ia
990 for current instance.
992 The Release() function is used to manually release one or more
993 IPv6 addresses. If AddressCount is zero, it will release all IPv6
994 addresses of the configured IA. If all IPv6 addresses of the IA are
995 released through this function, the state of the IA will switch
996 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
997 IA will restore to Dhcp6Bound after the releasing process.
998 The Release() can only be called when the IA is in Dhcp6Bound state.
999 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
1000 a blocking operation. It will return after the releasing process
1001 finishes, or is aborted by user.
1003 @param[in] This The pointer to the Dhcp6 protocol.
1004 @param[in] AddressCount The number of releasing addresses.
1005 @param[in] Addresses The pointer to the buffer stored the releasing
1008 @retval EFI_SUCCESS The DHCPv6 release exchange process
1009 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1010 was NULL. The Dhcp6 instance was sent Release
1011 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1013 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
1014 state of the configured IA is not in Dhcp6Bound.
1015 @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
1016 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
1017 the configured IA for this instance.
1018 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1019 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1025 IN EFI_DHCP6_PROTOCOL
*This
,
1026 IN UINT32 AddressCount
,
1027 IN EFI_IPv6_ADDRESS
*Addresses
1032 EFI_DHCP6_IA
*RelIa
;
1033 DHCP6_INSTANCE
*Instance
;
1034 DHCP6_SERVICE
*Service
;
1036 if (This
== NULL
|| (AddressCount
!= 0 && Addresses
== NULL
)) {
1037 return EFI_INVALID_PARAMETER
;
1040 Instance
= DHCP6_INSTANCE_FROM_THIS (This
);
1041 Service
= Instance
->Service
;
1044 // The instance hasn't been configured.
1046 if (Instance
->Config
== NULL
) {
1047 return EFI_ACCESS_DENIED
;
1050 ASSERT (Instance
->IaCb
.Ia
!= NULL
);
1052 if (Instance
->IaCb
.Ia
->State
!= Dhcp6Bound
) {
1053 return EFI_ACCESS_DENIED
;
1057 // Check whether all the released addresses belongs to the configured Ia.
1059 Status
= Dhcp6CheckAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1061 if (EFI_ERROR(Status
)) {
1065 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1066 Instance
->UdpSts
= EFI_ALREADY_STARTED
;
1069 // Deprive of all the released addresses from the configured Ia, and create a
1070 // ReleaseIa used to create release message.
1072 RelIa
= Dhcp6DepriveAddress (Instance
->IaCb
.Ia
, AddressCount
, Addresses
);
1074 if (RelIa
== NULL
) {
1075 Status
= EFI_OUT_OF_RESOURCES
;
1080 // Send the release message to start exchange process.
1082 Status
= Dhcp6SendReleaseMsg (Instance
, RelIa
);
1084 if (EFI_ERROR (Status
)) {
1089 // Register receive callback for the stateful exchange process.
1091 Status
= UdpIoRecvDatagram(
1098 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
1103 gBS
->RestoreTPL (OldTpl
);
1106 // Poll udp out of the net tpl if synchoronus call.
1108 if (Instance
->Config
->IaInfoEvent
== NULL
) {
1109 while (Instance
->UdpSts
== EFI_ALREADY_STARTED
) {
1110 Service
->UdpIo
->Protocol
.Udp6
->Poll (Service
->UdpIo
->Protocol
.Udp6
);
1112 return Instance
->UdpSts
;
1119 if (RelIa
!= NULL
) {
1122 gBS
->RestoreTPL (OldTpl
);
1129 Parse the option data in the Dhcp6 packet.
1131 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
1133 @param[in] This The pointer to the Dhcp6 protocol.
1134 @param[in] Packet The pointer to the Dhcp6 packet.
1135 @param[in, out] OptionCount The number of option in the packet.
1136 @param[out] PacketOptionList The array of pointers to each option in the packet.
1138 @retval EFI_SUCCESS The packet was successfully parsed.
1139 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1140 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
1141 that were found in the Packet.
1147 IN EFI_DHCP6_PROTOCOL
*This
,
1148 IN EFI_DHCP6_PACKET
*Packet
,
1149 IN OUT UINT32
*OptionCount
,
1150 OUT EFI_DHCP6_PACKET_OPTION
*PacketOptionList
[] OPTIONAL
1159 if (This
== NULL
|| Packet
== NULL
|| OptionCount
== NULL
) {
1160 return EFI_INVALID_PARAMETER
;
1163 if (*OptionCount
!= 0 && PacketOptionList
== NULL
) {
1164 return EFI_INVALID_PARAMETER
;
1167 if (Packet
->Length
> Packet
->Size
|| Packet
->Length
< sizeof (EFI_DHCP6_HEADER
)) {
1168 return EFI_INVALID_PARAMETER
;
1172 // The format of Dhcp6 option:
1174 // 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
1175 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1176 // | option-code | option-len (option data) |
1177 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1179 // | (option-len octets) |
1180 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1184 OptLen
= Packet
->Length
- sizeof (EFI_DHCP6_HEADER
);
1185 Start
= Packet
->Dhcp6
.Option
;
1186 End
= Start
+ OptLen
;
1189 // Calculate the number of option in the packet.
1191 while (Start
< End
) {
1192 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1193 Start
+= (NTOHS (DataLen
) + 4);
1198 // It will return buffer too small if pass-in option count is smaller than the
1199 // actual count of options in the packet.
1201 if (OptCnt
> *OptionCount
) {
1202 *OptionCount
= OptCnt
;
1203 return EFI_BUFFER_TOO_SMALL
;
1208 (*OptionCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*))
1212 Start
= Packet
->Dhcp6
.Option
;
1214 while (Start
< End
) {
1216 PacketOptionList
[OptCnt
] = (EFI_DHCP6_PACKET_OPTION
*) Start
;
1217 DataLen
= ((EFI_DHCP6_PACKET_OPTION
*) Start
)->OpLen
;
1218 Start
+= (NTOHS (DataLen
) + 4);