/** @file
This EFI_DHCP6_PROTOCOL interface implementation.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Dhcp6Impl.h"
//
// Well-known multi-cast address defined in section-24.1 of rfc-3315
//
// ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2
// ALL_DHCP_Servers address: FF05::1:3
//
EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};
};
/**
Starts the DHCPv6 standard S.A.R.R. process.
The Start() function starts the DHCPv6 standard process. This function can
be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
If the DHCP process completes successfully, the state of the Dhcp6 instance
will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
Dhcp6Bound state.
Refer to rfc-3315 for precise state transitions during this process. At the
time when each event occurs in this process, the callback function that was set
by EFI_DHCP6_PROTOCOL.Configure() will be called, and the user can take this
opportunity to control the process.
@param[in] This The pointer to Dhcp6 protocol.
@retval EFI_SUCCESS The DHCPv6 standard process has started, or it has
completed when CompletionEvent is NULL.
@retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
@retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
@retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
response was received from the server within the
specified timeout value.
@retval EFI_ABORTED The user aborted the DHCPv6 process.
@retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
standard process.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
@retval EFI_NO_MEDIA There was a media error.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// The instance hasn't been configured.
//
return EFI_ACCESS_DENIED;
}
//
// The instance has already been started.
//
return EFI_ALREADY_STARTED;
}
//
// Need to clear initial time to make sure that elapsed-time
// is set to 0 for first Solicit.
//
//
// Send the solicit message to start S.A.R.R process.
//
goto ON_ERROR;
}
//
// Register receive callback for the stateful exchange process.
//
0
);
goto ON_ERROR;
}
//
// Poll udp out of the net tpl if synchronous call.
//
}
}
return EFI_SUCCESS;
return Status;
}
/**
Stops the DHCPv6 standard S.A.R.R. process.
The Stop() function is used to stop the DHCPv6 standard process. After this
function is called successfully, the state of Dhcp6 instance is transferred
into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
before DHCPv6 standard process can be started again. This function can be
called when the Dhcp6 instance is in any state.
@param[in] This The pointer to the Dhcp6 protocol.
@retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
@retval EFI_INVALID_PARAMETER This is NULL.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// The instance hasn't been configured.
//
return Status;
}
//
// The instance has already been stopped.
//
) {
return Status;
}
//
// Release the current ready Ia.
//
//
// Poll udp out of the net tpl if synchoronus call.
//
}
}
//
// Clean up the session data for the released Ia.
//
return Status;
}
/**
Returns the current operating mode data for the Dhcp6 instance.
The GetModeData() function returns the current operating mode and
cached data packet for the Dhcp6 instance.
@param[in] This The pointer to the Dhcp6 protocol.
@param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
@param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
@retval EFI_SUCCESS The mode data was returned.
@retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not
configured.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_ACCESS_DENIED;
}
//
// User needs a copy of instance config data.
//
if (Dhcp6ConfigData != NULL) {
//
// Duplicate config data, including all reference buffers.
//
goto ON_ERROR;
}
}
//
// User need a copy of instance mode data.
//
if (Dhcp6ModeData != NULL) {
//
// Duplicate a copy of EFI_DHCP6_DUID for client Id.
//
goto ON_ERROR;
}
CopyMem (
);
//
// Duplicate a copy of EFI_DHCP6_IA for configured Ia.
//
goto ON_ERROR;
}
CopyMem (
Ia,
);
//
// Duplicate a copy of reply packet if has.
//
goto ON_ERROR;
}
CopyMem (
);
}
}
}
return EFI_SUCCESS;
if (Dhcp6ConfigData != NULL) {
}
if (Dhcp6ModeData != NULL) {
}
return EFI_OUT_OF_RESOURCES;
}
/**
Initializes, changes, or resets the operational settings for the Dhcp6 instance.
The Configure() function is used to initialize or clean up the configuration
data of the Dhcp6 instance:
- When Dhcp6CfgData is not NULL and Configure() is called successfully, the
configuration data will be initialized in the Dhcp6 instance, and the state
of the configured IA will be transferred into Dhcp6Init.
- When Dhcp6CfgData is NULL and Configure() is called successfully, the
configuration data will be cleaned up and no IA will be associated with
the Dhcp6 instance.
To update the configuration data for an Dhcp6 instance, the original data
must be cleaned up before setting the new configuration data.
@param[in] This The pointer to the Dhcp6 protocol
@param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
@retval EFI_SUCCESS The Dhcp6 is configured successfully with the
Dhcp6Init state, or cleaned up the original
configuration setting.
@retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.
The Dhcp6 instance has already started the
DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
@retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// Check the parameter of configure data.
//
if (Dhcp6CfgData != NULL) {
return EFI_INVALID_PARAMETER;
}
) {
return EFI_INVALID_PARAMETER;
}
}
}
) {
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
) {
return EFI_INVALID_PARAMETER;
}
//
// Make sure the (IaId, IaType) is unique over all the instances.
//
) {
return EFI_INVALID_PARAMETER;
}
}
}
if (Dhcp6CfgData != NULL) {
//
// It's not allowed to configure one instance twice without configure null.
//
return EFI_ACCESS_DENIED;
}
//
// Duplicate config data including all reference buffers.
//
return EFI_OUT_OF_RESOURCES;
}
return EFI_OUT_OF_RESOURCES;
}
//
// Initialize the Ia descriptor from the config data, and leave the other
// fields of the Ia as default value 0.
//
return EFI_OUT_OF_RESOURCES;
}
CopyMem (
sizeof(EFI_DHCP6_IA_DESCRIPTOR)
);
} else {
return EFI_SUCCESS;
}
//
// It's not allowed to configure a started instance as null.
//
return EFI_ACCESS_DENIED;
}
}
return EFI_SUCCESS;
}
/**
Request configuration information without the assignment of any
Ia addresses of the client.
The InfoRequest() function is used to request configuration information
without the assignment of any IPv6 address of the client. The client sends
out an Information Request packet to obtain the required configuration
information, and DHCPv6 server responds with a Reply packet containing
the information for the client. The received Reply packet will be passed
to the user by ReplyCallback function. If the user returns EFI_NOT_READY from
ReplyCallback, the Dhcp6 instance will continue to receive other Reply
packets unless timeout according to the Retransmission parameter.
Otherwise, the Information Request exchange process will be finished
successfully if user returns EFI_SUCCESS from ReplyCallback.
@param[in] This The pointer to the Dhcp6 protocol.
@param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
Identifier option and include it into Information Request
packet. Otherwise, Client Identifier option will not be included.
@param[in] OptionRequest The pointer to the buffer of option request options.
@param[in] OptionCount The option number in the OptionList.
@param[in] OptionList The list of appended options.
@param[in] Retransmission The pointer to the retransmission of the message.
@param[in] TimeoutEvent The event of timeout.
@param[in] ReplyCallback The callback function when the reply was received.
@param[in] CallbackContext The pointer to the parameter passed to the callback.
@retval EFI_SUCCESS The DHCPv6 information request exchange process
completed when TimeoutEvent is NULL. Information
Request packet has been sent to DHCPv6 server when
TimeoutEvent is not NULL.
@retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
because of no response, or not all requested-options
are responded by DHCPv6 servers when Timeout happened.
@retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
by user.
@retval EFI_INVALID_PARAMETER Some parameter is NULL.
@retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
if (OptionList != NULL) {
if (OptionList[Index]->OpCode == Dhcp6OptClientId || OptionList[Index]->OpCode == Dhcp6OptRequestOption) {
return EFI_INVALID_PARAMETER;
}
}
}
//
// Create and initialize the control block for the info-request.
//
return EFI_OUT_OF_RESOURCES;
}
//
// Send the info-request message to start exchange process.
//
);
goto ON_ERROR;
}
//
// Register receive callback for the stateless exchange process.
//
0
);
goto ON_ERROR;
}
//
// Poll udp out of the net tpl if synchoronus call.
//
if (TimeoutEvent == NULL) {
}
}
return EFI_SUCCESS;
return Status;
}
/**
Manually extend the valid and preferred lifetimes for the IPv6 addresses
of the configured IA and update other configuration parameters by sending a
Renew or Rebind packet.
The RenewRebind() function is used to manually extend the valid and preferred
lifetimes for the IPv6 addresses of the configured IA, and update other
configuration parameters by sending Renew or Rebind packet.
- When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
it sends Renew packet to the previously DHCPv6 server and transfer the
state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
If fails, the state transfers to Dhcp6Bound, but the timer continues.
- When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
it will send a Rebind packet. If valid Reply packet is received, the state transfers
to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
transfers to Dhcp6Init, and the IA can't be used.
@param[in] This The pointer to the Dhcp6 protocol.
@param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
completed and at least one IPv6 address of the
configured IA has been bound again when
EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
The EFI DHCPv6 Protocol instance has sent Renew
or Rebind packet when
EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
@retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
state of the configured IA is not in Dhcp6Bound.
@retval EFI_ALREADY_STARTED The state of the configured IA has already entered
Dhcp6Renewing when RebindRequest is FALSE.
The state of the configured IA has already entered
Dhcp6Rebinding when RebindRequest is TRUE.
by the user.
because of no response.
@retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
@retval EFI_INVALID_PARAMETER Some parameter is NULL.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// The instance hasn't been configured.
//
return EFI_ACCESS_DENIED;
}
//
// The instance has already entered renewing or rebinding state.
//
) {
return EFI_ALREADY_STARTED;
}
return EFI_ACCESS_DENIED;
}
//
//
goto ON_ERROR;
}
//
// Register receive callback for the stateful exchange process.
//
0
);
goto ON_ERROR;
}
//
// Poll udp out of the net tpl if synchoronus call.
//
}
}
return EFI_SUCCESS;
return Status;
}
/**
Inform that one or more addresses assigned by a server are already
in use by another node.
The Decline() function is used to manually decline the assignment of
IPv6 addresses, which have been already used by another node. If all
IPv6 addresses of the configured IA are declined through this function,
the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
Otherwise, the state of the IA will restore to Dhcp6Bound after the
declining process. The Decline() can only be called when the IA is in
Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
this function is a blocking operation. It will return after the
declining process finishes, or aborted by user.
@param[in] This The pointer to EFI_DHCP6_PROTOCOL.
@param[in] AddressCount The number of declining addresses.
@param[in] Addresses The pointer to the buffer stored the declining
addresses.
@retval EFI_SUCCESS The DHCPv6 decline exchange process completed
when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
The Dhcp6 instance sent Decline packet when
EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
@retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
state of the configured IA is not in Dhcp6Bound.
@retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
@retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
the configured IA for this instance.
@retval EFI_INVALID_PARAMETER Some parameter is NULL.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// The instance hasn't been configured.
//
return EFI_ACCESS_DENIED;
}
return EFI_ACCESS_DENIED;
}
//
// Check whether all the declined addresses belongs to the configured Ia.
//
return Status;
}
//
// Deprive of all the declined addresses from the configured Ia, and create a
// DeclineIa used to create decline message.
//
goto ON_ERROR;
}
//
// Send the decline message to start exchange process.
//
goto ON_ERROR;
}
//
// Register receive callback for the stateful exchange process.
//
0
);
goto ON_ERROR;
}
//
// Poll udp out of the net tpl if synchoronus call.
//
}
}
return EFI_SUCCESS;
}
return Status;
}
/**
Release one or more addresses associated with the configured Ia
for current instance.
The Release() function is used to manually release one or more
IPv6 addresses. If AddressCount is zero, it will release all IPv6
addresses of the configured IA. If all IPv6 addresses of the IA are
released through this function, the state of the IA will switch
through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
IA will restore to Dhcp6Bound after the releasing process.
The Release() can only be called when the IA is in Dhcp6Bound state.
If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
a blocking operation. It will return after the releasing process
finishes, or is aborted by user.
@param[in] This The pointer to the Dhcp6 protocol.
@param[in] AddressCount The number of releasing addresses.
@param[in] Addresses The pointer to the buffer stored the releasing
addresses.
@retval EFI_SUCCESS The DHCPv6 release exchange process
completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
was NULL. The Dhcp6 instance was sent Release
packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
was not NULL.
@retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
state of the configured IA is not in Dhcp6Bound.
@retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
@retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
the configured IA for this instance.
@retval EFI_INVALID_PARAMETER Some parameter is NULL.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// The instance hasn't been configured.
//
return EFI_ACCESS_DENIED;
}
return EFI_ACCESS_DENIED;
}
//
// Check whether all the released addresses belongs to the configured Ia.
//
return Status;
}
//
// Deprive of all the released addresses from the configured Ia, and create a
// ReleaseIa used to create release message.
//
goto ON_ERROR;
}
//
// Send the release message to start exchange process.
//
goto ON_ERROR;
}
//
// Register receive callback for the stateful exchange process.
//
0
);
goto ON_ERROR;
}
//
// Poll udp out of the net tpl if synchoronus call.
//
}
}
return EFI_SUCCESS;
}
return Status;
}
/**
Parse the option data in the Dhcp6 packet.
The Parse() function is used to retrieve the option list in the DHCPv6 packet.
@param[in] This The pointer to the Dhcp6 protocol.
@param[in] Packet The pointer to the Dhcp6 packet.
@param[in, out] OptionCount The number of option in the packet.
@param[out] PacketOptionList The array of pointers to each option in the packet.
@retval EFI_SUCCESS The packet was successfully parsed.
@retval EFI_INVALID_PARAMETER Some parameter is NULL.
@retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
that were found in the Packet.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
//
// The format of Dhcp6 option:
//
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | option-code | option-len (option data) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | option-data |
// | (option-len octets) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
OptCnt = 0;
//
// Calculate the number of option in the packet.
//
OptCnt++;
}
//
// It will return buffer too small if pass-in option count is smaller than the
// actual count of options in the packet.
//
if (OptCnt > *OptionCount) {
*OptionCount = OptCnt;
return EFI_BUFFER_TOO_SMALL;
}
ZeroMem (
(*OptionCount * sizeof (EFI_DHCP6_PACKET_OPTION *))
);
OptCnt = 0;
OptCnt++;
}
return EFI_SUCCESS;
}