/** @file
Functions implementation related with DHCPv6 for UefiPxeBc Driver.
Copyright (c) 2009 - 2012, 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 "PxeBcImpl.h"
//
// Well-known multi-cast address defined in section-24.1 of rfc-3315
//
// ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2
//
EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};
/**
Parse out a DHCPv6 option by OptTag, and find the position in buffer.
@param[in] Buffer The pointer to the option buffer.
@param[in] Length Length of the option buffer.
@param[in] OptTag The required option tag.
@retval NULL Failed to parse the required option.
@retval Others The postion of the required option in buffer.
**/
)
{
Offset = 0;
//
// OpLen and OpCode here are both stored in network order.
//
return Option;
}
}
return NULL;
}
/**
Build the options buffer for the DHCPv6 request packet.
@param[in] Private The pointer to PxeBc private data.
@param[out] OptList The pointer to the option pointer array.
@param[in] Buffer The pointer to the buffer to contain the option list.
@return Index The count of the built-in options.
**/
)
{
Index = 0;
//
// Append client option request option
//
Index++;
//
// Append client network device interface option
//
} else {
}
Index++;
//
// Append client system architecture option
//
Index++;
//
// Append vendor class option to store the PXE class identifier.
//
CopyMem (
sizeof (PXEBC_CLASS_ID)
);
);
CopyMem (
);
);
);
}
Index++;
return Index;
}
/**
Cache the DHCPv6 packet.
@param[in] Dst The pointer to the cache buffer for DHCPv6 packet.
@param[in] Src The pointer to the DHCPv6 packet to be cached.
**/
)
{
}
/**
Free all the nodes in the list for boot file.
@param[in] Head The pointer to the head of list.
**/
)
{
}
}
/**
Parse the Boot File URL option.
@param[out] FileName The pointer to the boot file name.
@param[in, out] SrvAddr The pointer to the boot server address.
@param[in] BootFile The pointer to the boot file URL option data.
@param[in] Length The length of the boot file URL option data.
@retval EFI_ABORTED User cancel operation.
@retval EFI_SUCCESS Selected the boot menu successfully.
@retval EFI_NOT_READY Read the input key from the keybroad has not finish.
**/
)
{
//
// The format of the Boot File URL option is:
//
// 0 1 2 3
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | OPT_BOOTFILE_URL | option-len |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | |
// . bootfile-url (variable length) .
// | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
//
// Based upon RFC 5970 and UEFI 2.3 Errata D specification, bootfile-url format
// is tftp://[SERVER_ADDRESS]/BOOTFILE_NAME
// As an example where the BOOTFILE_NAME is the EFI loader and
// SERVER_ADDRESS is the ASCII encoding of an IPV6 address.
//
return EFI_NOT_FOUND;
}
return EFI_OUT_OF_RESOURCES;
}
//
// Get the part of SERVER_ADDRESS string.
//
if (*ServerAddressOption != PXEBC_ADDR_START_DELIMITER) {
return EFI_INVALID_PARAMETER;
}
}
if (*ServerAddress != PXEBC_ADDR_END_DELIMITER) {
return EFI_INVALID_PARAMETER;
}
*ServerAddress = '\0';
//
// Convert the string of server address to Ipv6 address format and store it.
//
return Status;
}
//
// Get the part of BOOTFILE_NAME string.
//
if (*BootFileNamePtr != PXEBC_TFTP_URL_SEPARATOR) {
return EFI_INVALID_PARAMETER;
}
//
// Remove trailing mode=octet if present and ignore. All other modes are
// invalid for netboot6, so reject them.
//
*ModeStr = '\0';
return EFI_INVALID_PARAMETER;
}
//
// Extract boot file name from URL.
//
if (BootFileName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Decode percent-encoding in boot file name.
//
while (*BootFileNamePtr != '\0') {
if (*BootFileNamePtr == '%') {
BootFileName++;
BootFileNamePtr += 3;
} else {
BootFileName++;
}
}
*BootFileName = '\0';
}
return EFI_SUCCESS;
}
/**
Parse the Boot File Parameter option.
@param[in] BootFilePara The pointer to boot file parameter option data.
@param[out] BootFileSize The pointer to the parsed boot file size.
@retval EFI_SUCCESS Successfully obtained the boot file size from parameter option.
@retval EFI_NOT_FOUND Failed to extract the boot file size from parameter option.
**/
)
{
//
// The BootFile Size should be 1~5 byte ASCII strings
//
return EFI_NOT_FOUND;
}
//
// Extract the value of BootFile Size.
//
Size = 0;
return EFI_NOT_FOUND;
}
}
if (Size > PXEBC_DHCP6_MAX_BOOT_FILE_SIZE) {
return EFI_NOT_FOUND;
}
return EFI_SUCCESS;
}
/**
Parse the cached DHCPv6 packet, including all the options.
@param[in] Cache6 The pointer to a cached DHCPv6 packet.
@retval EFI_SUCCESS Parsed the DHCPv6 packet successfully.
@retval EFI_DEVICE_ERROR Failed to parse and invalid the packet.
**/
)
{
IsProxyOffer = TRUE;
IsPxeOffer = FALSE;
Offset = 0;
//
// OpLen and OpCode here are both stored in network order, since they are from original packet.
//
//
// The server sends this option to inform the client about an URL to a boot file.
//
}
}
//
// The offer with assigned client address is a proxy offer.
// An ia_na option, embeded with valid ia_addr option and a status_code of success.
//
);
}
}
//
// The offer with "PXEClient" is a pxe offer.
//
IsPxeOffer = TRUE;
}
//
// Determine offer type of the dhcp6 packet.
//
if (IsPxeOffer) {
//
// It's a binl offer only with PXEClient.
//
} else {
//
// It's a dhcp only offer, which is a pure dhcp6 offer packet.
//
}
return EFI_SUCCESS;
}
/**
Cache the DHCPv6 ack packet, and parse it on demand.
@param[in] Private The pointer to PxeBc private data.
@param[in] Ack The pointer to the DHCPv6 ack packet.
@param[in] Verified If TRUE, parse the ACK packet and store info into mode data.
**/
)
{
if (Verified) {
//
// Parse the ack packet and store it into mode data if needed.
//
}
}
/**
Cache the DHCPv6 proxy offer packet according to the received order.
@param[in] Private The pointer to PxeBc private data.
@param[in] OfferIndex The received order of offer packets.
**/
)
{
//
// Cache the proxy offer packet and parse it.
//
//
// Store this packet into mode data.
//
}
/**
Seek the address of the first byte of the option header.
@param[in] Buf The pointer to the buffer.
@param[in] SeekLen The length to seek.
@param[in] OptType The option type.
@retval NULL If it failed to seek the option.
@retval others The position to the option.
**/
UINT8 *
)
{
break;
}
}
return Option;
}
/**
Build and send out the request packet for the bootfile, and parse the reply.
@param[in] Private The pointer to PxeBc private data.
@param[in] Index PxeBc option boot item type.
@retval EFI_SUCCESS Successfully discovered the boot file.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
@retval EFI_NOT_FOUND Can't get the PXE reply packet.
@retval Others Failed to discover the boot file.
**/
)
{
OpFlags = 0;
return EFI_DEVICE_ERROR;
}
return EFI_OUT_OF_RESOURCES;
}
//
// Build the request packet by the cached request packet before.
//
DiscoverLen = sizeof (EFI_DHCP6_HEADER);
//
// Find Server ID Option from ProxyOffer.
//
);
return EFI_NOT_FOUND;
}
//
// Add Server ID Option.
//
if (OpCode != EFI_DHCP6_IA_TYPE_NA &&
OpCode != EFI_DHCP6_IA_TYPE_TA &&
) {
//
// Copy all the options except IA option and Server ID
//
}
}
//
// Update Elapsed option in the package
//
);
}
&DestPort,
NULL,
&SrcPort,
NULL,
NULL,
);
return Status;
}
//
// Cache the right PXE reply packet here, set valid flag later.
// Especially for PXE discover packet, store it into mode data here.
//
//
// Start Udp6Read instance
//
return Status;
}
&SrcPort,
&DestPort,
NULL,
NULL,
&ReadSize,
);
//
// Stop Udp6Read instance
//
return Status;
}
//
// Update length
//
return EFI_SUCCESS;
}
/**
Retry to request bootfile name by the BINL offer.
@param[in] Private The pointer to PxeBc private data.
@param[in] Index The received order of offer packets.
@retval EFI_SUCCESS Successfully retried a request for the bootfile name.
@retval EFI_DEVICE_ERROR Failed to retry the bootfile name.
**/
)
{
//
// There is no BootFileUrl option in dhcp6 offer, so use servers multi-cast address instead.
//
CopyMem (
sizeof (EFI_IPv6_ADDRESS)
);
} else {
//
// Parse out the next server address from the last offer, and store it
//
);
return Status;
}
}
//
// Retry Dhcp6Binl again for the bootfile, and the reply cached into Private->ProxyOffer.
//
return Status;
}
return Status;
}
//
// This BINL ack doesn't have discovery option set or multicast option set
// or bootfile name specified.
//
return EFI_DEVICE_ERROR;
}
CopyMem (
);
return EFI_SUCCESS;
}
/**
Cache all the received DHCPv6 offers, and set OfferIndex and OfferCount.
@param[in] Private The pointer to PXEBC_PRIVATE_DATA.
@param[in] RcvdOffer The pointer to the received offer packet.
**/
)
{
//
// Cache the content of DHCPv6 packet firstly.
//
//
// Validate the DHCPv6 packet, and parse the options and offer type.
//
return ;
}
//
// Determine whether cache the current offer by type, and record OfferIndex and OfferCount.
//
if (IS_PROXY_OFFER (OfferType)) {
//
// It's a proxy offer without yiaddr, including PXE10, WFM11a or BINL offer.
//
if (OfferType == PxeOfferTypeProxyBinl) {
//
// Cache all proxy BINL offers.
//
//
//
} else {
return;
}
} else {
//
// It's a DHCPv6 offer with yiaddr, and cache them all.
//
}
}
/**
Select an DHCPv6 offer, and record SelectIndex and SelectProxyType.
@param[in] Private The pointer to PXEBC_PRIVATE_DATA.
**/
)
{
Private->SelectIndex = 0;
if (Private->IsOfferSorted) {
//
// Select offer by default policy.
//
//
// 1. DhcpPxe10 offer
//
//
// 2. DhcpWfm11a offer
//
//
// 3. DhcpOnly offer and ProxyPxe10 offer.
//
//
// 4. DhcpOnly offer and ProxyWfm11a offer.
//
//
// 5. DhcpBinl offer.
//
//
// 6. DhcpOnly offer and ProxyBinl offer.
//
} else {
//
// 7. DhcpOnly offer with bootfilename.
//
break;
}
}
}
} else {
//
// Select offer by received order.
//
if (IS_PROXY_OFFER (OfferType)) {
//
// Skip proxy offers
//
continue;
}
if (!Private->IsProxyRecved &&
//
// Skip if DhcpOnly offer without any other proxy offers or bootfilename.
//
continue;
}
break;
}
}
}
/**
Handle the DHCPv6 offer packet.
@param[in] Private The pointer to PXEBC_PRIVATE_DATA.
@retval EFI_SUCCESS Handled the DHCPv6 offer packet successfully.
@retval EFI_NO_RESPONSE No response to the following request packet.
**/
)
{
//
// DhcpBinl offer is selected, so need try to request bootfilename by this offer.
//
}
if (Private->IsProxyRecved) {
//
// DhcpOnly offer is selected, so need try to request bootfilename.
//
ProxyIndex = 0;
if (Private->IsOfferSorted) {
//
// The proxy offer should be determined if select by default policy.
// IsOfferSorted means all offers are labeled by OfferIndex.
//
//
// Try all the cached ProxyBinl offer one by one to request bootfilename.
//
break;
}
}
}
} else {
//
// For other proxy offers (pxe10 or wfm11a), only one is buffered.
//
}
} else {
//
// The proxy offer should not be determined if select by received order.
//
if (!IS_PROXY_OFFER (OfferType)) {
//
// Skip non proxy dhcp offers.
//
continue;
}
if (OfferType == PxeOfferTypeProxyBinl) {
//
// Try all the cached ProxyBinl offer one by one to request bootfilename.
//
continue;
}
}
ProxyIndex = Index;
break;
}
}
//
// Success to try to request by a ProxyPxe10 or ProxyWfm11a offer, copy and parse it.
//
}
} else {
//
// Othewise, the bootfilename must be included in DhcpOnly offer.
//
}
}
//
// All PXE boot information is ready by now.
//
}
return Status;
}
/**
Unregister the address by Ip6Config protocol.
@param[in] Private The pointer to PXEBC_PRIVATE_DATA.
**/
)
{
//
// PXE driver change the policy of IP6 driver, it's a chance to recover.
// Keep the point and there is no enough requirements to do recovery.
//
}
}
/**
Register the ready address by Ip6Config protocol.
@param[in] Private The pointer to PXEBC_PRIVATE_DATA.
@param[in] Address The pointer to the ready address.
@retval EFI_SUCCESS Registered the address succesfully.
@retval Others Failed to register the address.
**/
)
{
TimeOutEvt = NULL;
DataSize = sizeof (EFI_IP6_CONFIG_POLICY);
//
// Get and store the current policy of IP6 driver.
//
&DataSize,
);
goto ON_EXIT;
}
//
// There is no channel between IP6 and PXE driver about address setting,
// so it has to set the new address by Ip6ConfigProtocol manually.
//
sizeof(EFI_IP6_CONFIG_POLICY),
);
//
// There is no need to recover later.
//
goto ON_EXIT;
}
//
// Create a timer as setting address timeout event since DAD in IP6 driver.
//
NULL,
NULL,
);
goto ON_EXIT;
}
//
// Create a notify event to set address flag when DAD if IP6 driver succeeded.
//
);
goto ON_EXIT;
}
);
goto ON_EXIT;
}
sizeof(EFI_IP6_CONFIG_MANUAL_ADDRESS),
);
goto ON_EXIT;
}
//
// Start the 5 secondes timer to wait for setting address.
//
if (Private->IsAddressOk) {
break;
}
}
);
}
if (TimeOutEvt != NULL) {
}
return Status;
}
/**
EFI_DHCP6_CALLBACK is provided by the consumer of the EFI DHCPv6 Protocol driver
to intercept events that occurred in the configuration process.
@param[in] This The pointer to the EFI DHCPv6 Protocol.
@param[in] Context The pointer to the context set by EFI_DHCP6_PROTOCOL.Configure().
@param[in] CurrentState The current operational state of the EFI DHCPv Protocol driver.
@param[in] Dhcp6Event The event that occurs in the current state, which usually means a
state transition.
@param[in] Packet The DHCPv6 packet that is going to be sent or was already received.
@param[out] NewPacket The packet that is used to replace the Packet above.
@retval EFI_SUCCESS Told the EFI DHCPv6 Protocol driver to continue the DHCP process.
@retval EFI_NOT_READY Only used in the Dhcp6Selecting state. The EFI DHCPv6 Protocol
driver will continue to wait for more packets.
@retval EFI_ABORTED Told the EFI DHCPv6 Protocol driver to abort the current process.
**/
)
{
if ((Dhcp6Event != Dhcp6RcvdAdvertise) &&
(Dhcp6Event != Dhcp6SelectAdvertise) &&
(Dhcp6Event != Dhcp6SendSolicit) &&
(Dhcp6Event != Dhcp6SendRequest) &&
(Dhcp6Event != Dhcp6RcvdReply)) {
return EFI_SUCCESS;
}
//
// Callback to user when any traffic ocurred if has.
//
);
return EFI_ABORTED;
}
}
switch (Dhcp6Event) {
case Dhcp6SendSolicit:
//
// Record the first Solicate msg time
//
if (Private->SolicitTimes == 0) {
Private->SolicitTimes++;
}
//
// Cache the dhcp discover packet to mode data directly.
//
break;
case Dhcp6RcvdAdvertise:
//
// Cache the dhcp offers to OfferBuffer[] for select later, and record
// the OfferIndex and OfferCount.
//
}
break;
case Dhcp6SendRequest:
//
// Store the request packet as seed packet for discover.
//
}
}
break;
case Dhcp6SelectAdvertise:
//
// Select offer by the default policy or by order, and record the SelectIndex
// and SelectProxyType.
//
if (Private->SelectIndex == 0) {
} else {
}
break;
case Dhcp6RcvdReply:
//
// Cache the dhcp ack to Private->Dhcp6Ack, but it's not the final ack in mode data
// without verification.
//
break;
default:
ASSERT (0);
}
return Status;
}
/**
Build and send out the request packet for the bootfile, and parse the reply.
@param[in] Private The pointer to PxeBc private data.
@param[in] Type PxeBc option boot item type.
@param[in] Layer The pointer to option boot item layer.
@param[in] UseBis Use BIS or not.
@param[in] DestIp The pointer to the server address.
@retval EFI_SUCCESS Successfully discovered the boot file.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
@retval EFI_NOT_FOUND Can't get the PXE reply packet.
@retval Others Failed to discover the boot file.
**/
)
{
OpFlags = 0;
}
return EFI_DEVICE_ERROR;
}
return EFI_OUT_OF_RESOURCES;
}
//
// Build the discover packet by the cached request packet before.
//
DiscoverLen = sizeof (EFI_DHCP6_HEADER);
if (OpCode != EFI_DHCP6_IA_TYPE_NA &&
OpCode != EFI_DHCP6_IA_TYPE_TA) {
//
// Copy all the options except IA option.
//
}
}
&DestPort,
NULL,
&SrcPort,
NULL,
NULL,
);
return Status;
}
//
// Cache the right PXE reply packet here, set valid flag later.
// Especially for PXE discover packet, store it into mode data here.
//
if (Private->IsDoDiscover) {
} else {
}
//
// Start Udp6Read instance
//
return Status;
}
&SrcPort,
&DestPort,
NULL,
NULL,
&ReadSize,
);
//
// Stop Udp6Read instance
//
return Status;
}
return EFI_SUCCESS;
}
/**
Start the DHCPv6 S.A.R.R. process to acquire the IPv6 address and other PXE boot information.
@param[in] Private The pointer to PxeBc private data.
@param[in] Dhcp6 The pointer to the EFI_DHCP6_PROTOCOL
@retval EFI_SUCCESS The S.A.R.R. process successfully finished.
@retval Others Failed to finish the S.A.R.R. process.
**/
)
{
//
// Build option list for the request packet.
//
if (Retransmit == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Configure the DHCPv6 instance for PXE boot.
//
return Status;
}
//
// Initialize the record fields for DHCPv6 offer in private data.
//
Private->SelectIndex = 0;
//
// Start DHCPv6 S.A.R.R. process to acquire IPv6 address.
//
if (Status == EFI_ICMP_ERROR) {
}
return Status;
}
//
// Get the acquired IPv6 address and store them.
//
return Status;
}
return Status;
}
return Status;
}
//
// Check the selected offer whether BINL retry is needed.
//
return Status;
}
AsciiPrint ("\n Station IP address is ");
return EFI_SUCCESS;
}