/** @file
Support for PxeBc dhcp functions.
Copyright (c) 2007 - 2011, 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"
//
// This is a map from the interested DHCP4 option tags' index to the tag value.
//
};
/**
This function initialize the DHCP4 message instance.
This function will pad each item of dhcp4 message packet.
@param Seed Pointer to the message instance of the DHCP4 packet.
@param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.
**/
)
{
}
/**
Copy the DCHP4 packet from srouce to destination.
@param Dst Pointer to the EFI_DHCP4_PROTOCOL instance.
@param Src Pointer to the EFI_DHCP4_PROTOCOL instance.
**/
)
{
}
/**
Copy the dhcp4 packet to the PxeBc private data and parse the dhcp4 packet.
@param Private Pointer to PxeBc private data.
@param OfferIndex Index of cached packets as complements of pxe mode data,
the index is maximum offer number.
**/
)
{
}
/**
Parse the cached dhcp packet.
@param CachedPacket Pointer to cached dhcp packet.
@retval TRUE Succeed to parse and validation.
@retval FALSE Fail to parse or validation.
**/
)
{
//
// Parse interested dhcp options and store their pointers in CachedPacket->Dhcp4Option.
//
);
}
//
// Check whether is an offer with PXEClient or not.
//
}
//
//
return FALSE;
}
}
//
// Check whether bootfilename/serverhostname overloaded (See details in dhcp spec).
// If overloaded, parse this buffer as nested dhcp options, or just parse bootfilename/
// serverhostname option.
//
);
//
// RFC 2132, Section 9.5 does not strictly state Bootfile name (option 67) is null
// terminated string. So force to append null terminated character at the end of string.
//
*Ptr8 = '\0';
}
//
// If the bootfile is not present and bootfilename is present in dhcp packet, just parse it.
// And do not count dhcp option header, or else will destory the serverhostname.
//
Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] -
}
//
// Determine offer type of the dhcp packet.
//
//
// It's a bootp offer
//
//
// bootp offer without bootfilename, discard it.
//
return FALSE;
}
} else {
//
// It's a pxe10 offer with PXEClient and discover vendor option.
//
//
// It's a wfm11a offer with PXEClient and mtftp vendor option, and
// return false since mtftp not supported currently.
//
return FALSE;
} else {
//
// If the binl offer with only PXEClient.
//
OfferType = (UINT8) ((CachedPacket->IsPxeOffer) ? DHCP4_PACKET_TYPE_BINL : DHCP4_PACKET_TYPE_DHCP_ONLY);
}
}
return TRUE;
}
/**
Offer dhcp service with a BINL dhcp offer.
@param Private Pointer to PxeBc private data.
@param Index Index of cached packets as complements of pxe mode data,
the index is maximum offer number.
@retval TRUE Offer the service successfully under priority BINL.
@retval FALSE Boot Service failed, parse cached dhcp packet failed or this
BINL ack cannot find options set or bootfile name specified.
**/
)
{
//
// Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)
// in DHCPOFFER packet.
// (It does not comply with PXE Spec, Ver2.1)
//
CopyMem (
sizeof (EFI_IPv4_ADDRESS)
);
} else {
CopyMem (
sizeof (EFI_IPv4_ADDRESS)
);
}
return FALSE;
}
0,
NULL,
&ServerIp,
0,
NULL,
);
return FALSE;
}
if (!PxeBcParseCachedDhcpPacket (CachedPacket)) {
return FALSE;
}
//
// This BINL ack doesn't have discovery options set or bootfile name
// specified.
//
return FALSE;
}
return TRUE;
}
/**
Offer dhcp service for each proxy with a BINL dhcp offer.
@param Private Pointer to PxeBc private data
@param OfferIndex Pointer to the index of cached packets as complements of
pxe mode data, the index is maximum offer number.
@return If there is no service needed offer return FALSE, otherwise TRUE.
**/
)
{
//
// Try this BINL proxy offer
//
return TRUE;
}
}
return FALSE;
}
/**
This function is to check the selected proxy offer (include BINL dhcp offer and
DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe base code
mode structure.
@param Private Pointer to PxeBc private data.
@retval EFI_SUCCESS Operational successful.
@retval EFI_NO_RESPONSE Offer dhcp service failed.
**/
)
{
//
// The addresses are acquired from a BINL dhcp offer, try BINL to get
// the bootfile name
//
}
//
// The selected offer to finish the D.O.R.A. is a DHCP only offer, we need
// try proxy offers if there are some, othewise the bootfile name must be
// set in this DHCP only offer.
//
if (Private->GotProxyOffer) {
//
// Get rid of the compiler warning.
//
ProxyOfferIndex = 0;
if (Private->SortOffers) {
//
// The offers are sorted before selecting, the proxy offer type must be
// already determined.
//
//
// We buffer all received BINL proxy offers, try them all one by one
//
}
} else {
//
// For other types, only one proxy offer is buffered.
//
}
} else {
//
// The proxy offer type is not determined, choose proxy offer in the
// received order.
//
if (!IS_PROXY_DHCP_OFFER (Offer)) {
//
// Skip non proxy dhcp offers.
//
continue;
}
//
// Try BINL
//
//
// Failed, skip to the next offer
//
continue;
}
}
break;
}
}
//
// Copy the proxy offer to Mode and set the flag
//
}
} else {
//
// No proxy offer is received, the bootfile name MUST be set.
//
}
}
//
// Everything is OK, set the flag and copy the DHCP packets.
//
//
// The discover packet is already copied, just set flag here.
//
//
// Other type of ACK is already cached. Bootp is special that we should
// use the bootp reply as the ACK and put it into the DHCP_ONLY buffer.
//
}
//
// Copy the dhcp ack.
//
}
return Status;
}
/**
Cache the Dhcp4 packet offer, Parse and validate each option of the packet.
@param Private Pointer to PxeBc private data.
@param RcvdOffer Pointer to the received Dhcp proxy offer packet.
**/
)
{
//
// Cache the orignal dhcp packet
//
//
// Parse and validate the options (including dhcp option and vendor option)
//
if (!PxeBcParseCachedDhcpPacket (CachedOffer)) {
return ;
}
if (OfferType >= DHCP4_PACKET_TYPE_MAX) {
return ;
}
if (OfferType == DHCP4_PACKET_TYPE_BOOTP) {
if (Private->BootpIndex != 0) {
//
// Only cache the first bootp offer, discard others.
//
return ;
} else {
//
// Take as a dhcp only offer, but record index specifically.
//
}
} else {
if (IS_PROXY_DHCP_OFFER (Offer)) {
//
// It's a proxy dhcp offer with no your address, including pxe10, wfm11a or binl offer.
//
if (OfferType == DHCP4_PACKET_TYPE_BINL) {
//
// Cache all binl offers.
//
//
//
return ;
} else {
//
// Record index of the proxy dhcp offer with type other than binl.
//
}
} else {
//
// It's a dhcp offer with your address.
//
}
}
//
// Count the accepted offers.
//
}
/**
Select the specified proxy offer, such as BINL, DHCP_ONLY and so on.
If the proxy does not exist, try offers with bootfile.
@param Private Pointer to PxeBc private data.
**/
)
{
Private->SelectedOffer = 0;
if (Private->SortOffers) {
//
// Select offer according to the priority
//
//
// DHCP with PXE10
//
//
// DHCP with WfM
//
) {
//
// DHCP only and proxy DHCP with PXE10
//
) {
//
// DHCP only and proxy DHCP with WfM
//
//
// DHCP with BINL
//
) {
//
// DHCP only and proxy DHCP with BINL
//
} else {
//
// Try offers with bootfile
//
//
// Select the first DHCP only offer with bootfile
//
break;
}
}
if (Private->SelectedOffer == 0) {
//
// Select the Bootp reply with bootfile if any
//
}
}
} else {
//
// Try the offers in the received order.
//
if (IS_PROXY_DHCP_OFFER (Offer)) {
//
// Skip proxy offers
//
continue;
}
((!Private->GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL))) {
//
// DHCP only offer but no proxy offer received and no bootfile option in this offer
//
continue;
}
break;
}
}
}
/**
Callback routine.
EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protocol driver
to intercept events that occurred in the configuration process. This structure
provides advanced control of each state transition of the DHCP process. The
returned status code determines the behavior of the EFI DHCPv4 Protocol driver.
There are three possible returned values, which are described in the following
table.
@param This Pointer to the EFI DHCPv4 Protocol instance that is used to
configure this callback function.
@param Context Pointer to the context that is initialized by
EFI_DHCP4_PROTOCOL.Configure().
@param CurrentState The current operational state of the EFI DHCPv4 Protocol
driver.
@param Dhcp4Event The event that occurs in the current state, which usually means a
state transition.
@param Packet The DHCP packet that is going to be sent or already received.
@param NewPacket The packet that is used to replace the above Packet.
@retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to continue the DHCP process.
@retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The EFI DHCPv4 Protocol
driver will continue to wait for more DHCPOFFER packets until the retry
timeout expires.
@retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to abort the current process and
return to the Dhcp4Init or Dhcp4InitReboot state.
**/
)
{
if ((Dhcp4Event != Dhcp4RcvdOffer) &&
(Dhcp4Event != Dhcp4SelectOffer) &&
(Dhcp4Event != Dhcp4SendDiscover) &&
(Dhcp4Event != Dhcp4RcvdAck) &&
(Dhcp4Event != Dhcp4SendRequest)) {
return EFI_SUCCESS;
}
//
// Override the Maximum DHCP Message Size.
//
);
if (MaxMsgSize != NULL) {
}
);
return EFI_ABORTED;
}
}
switch (Dhcp4Event) {
case Dhcp4SendDiscover:
case Dhcp4SendRequest:
//
// send the system GUID instead of the MAC address as the hardware address
// in the DHCP packet header.
//
//
// GUID not yet set - send all 0xff's to show programable (via SetVariable)
// SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);
// GUID not yet set - send all 0's to show not programable
//
}
}
if (Dhcp4Event == Dhcp4SendDiscover) {
//
// Cache the dhcp discover packet, of which some information will be used later.
//
}
break;
case Dhcp4RcvdOffer:
//
// Cache the dhcp offers in Private->Dhcp4Offers[]
//
}
break;
case Dhcp4SelectOffer:
//
// Select an offer, if succeeded, Private->SelectedOffer points to
// the index of the selected one.
//
if (Private->SelectedOffer == 0) {
} else {
}
break;
case Dhcp4RcvdAck:
//
// Cache Ack
//
break;
default:
break;
}
return Status;
}
/**
Initialize the DHCP options and build the option list.
@param Private Pointer to PxeBc private data.
@param OptList Pointer to a DHCP option list.
@param IsDhcpDiscover Discover dhcp option or not.
@return The index item number of the option list.
**/
)
{
Index = 0;
if (!IsDhcpDiscover) {
//
// Append message type.
//
Index++;
//
// Append max message size.
//
Index++;
}
//
// Parameter request list option.
//
Index++;
//
// Append UUID/Guid-based client identifier option
//
Index++;
//
// GUID not yet set - send all 0xff's to show programable (via SetVariable)
// SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);
// GUID not yet set - send all 0's to show not programable
//
}
//
// Append client network device interface option
//
} else {
}
Index++;
//
// Append client system architecture option
//
Index++;
//
// Append client system architecture option
//
CvtNum (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType));
//
// If NII protocol exists, update DHCP option data
//
}
Index++;
return Index;
}
/**
Discover the boot of service and initialize the vendor option if exists.
@param Private Pointer to PxeBc private data.
@param Type PxeBc option boot item type
@param Layer PxeBc option boot item layer
@param UseBis Use BIS or not
@param DestIp Ip address for server
@param IpCount The total count of the server ip address
@param SrvList Server list
@param IsDiscv Discover the vendor or not
@param Reply The dhcp4 packet of Pxe reply
@retval EFI_SUCCESS Operation succeeds.
@retval EFI_OUT_OF_RESOURCES Allocate memory pool failed.
@retval EFI_NOT_FOUND There is no vendor option exists.
@retval EFI_TIMEOUT Send Pxe Discover time out.
**/
)
{
} else {
}
}
if (IsDiscv) {
//
// Add vendor option of PXE_BOOT_ITEM
//
VendorOptLen = (UINT8) ((sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1);
return EFI_OUT_OF_RESOURCES;
}
OptCount++;
}
if (IsDiscv) {
}
return Status;
}
//
// GUID not yet set - send all 0's to show not programable
//
}
}
if (IsBCast) {
} else {
}
if (!IsBCast) {
}
//
// Send Pxe Discover
//
break;
}
}
if (TryIndex > PXEBC_BOOT_REQUEST_RETRIES) {
//
// No server response our PXE request
//
}
//
// Find Pxe Reply
//
RepIndex = 0;
SrvIndex = 0;
break;
}
if ((SrvList[SrvIndex].Type == Type) && EFI_IP4_EQUAL (&(Response->Dhcp4.Header.ServerAddr), &(Private->ServerIp))) {
break;
}
SrvIndex++;
}
break;
}
SrvIndex = 0;
RepIndex++;
}
}
if (IsDiscv) {
}
} else {
}
//
// free the responselist
//
}
}
//
// Free the dhcp packet
//
return Status;
}
/**
Parse interested dhcp options.
@param Buffer Pointer to the dhcp options packet.
@param Length The length of the dhcp options.
@param OptTag The option OpCode.
@return NULL if the buffer length is 0 and OpCode is not
PXEBC_DHCP4_TAG_EOP, or the pointer to the buffer.
**/
)
{
Offset = 0;
return Option;
}
Offset++;
} else {
}
}
return NULL;
}
/**
This function is to parse and check vendor options.
@param Dhcp4Option Pointer to dhcp options
@param VendorOption Pointer to vendor options
@return TRUE if valid for vendor options, or FALSE.
**/
)
{
Offset = 0;
//
// Parse every Vendor Option and set its BitMap
//
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
}
Offset++;
} else {
}
}
//
// FixMe, return falas if invalid of any vendor option
//
return TRUE;
}
/**
This function display boot item detail.
If the length of the boot item string over 70 Char, just display 70 Char.
@param Str Pointer to a string (boot item string).
@param Len The length of string.
**/
)
{
}
/**
Choose the boot prompt.
@param Private Pointer to PxeBc private data.
@retval EFI_SUCCESS Select boot prompt done.
@retval EFI_TIMEOUT Select boot prompt time out.
@retval EFI_NOT_FOUND The proxy offer is not Pxe10.
@retval EFI_ABORTED User cancel the operation.
@retval EFI_NOT_READY Read the input key from the keybroad has not finish.
**/
)
{
TimeoutEvent = NULL;
DescendEvent = NULL;
} else {
}
return EFI_NOT_FOUND;
}
return EFI_SUCCESS;
}
if (Timeout == 0) {
return EFI_SUCCESS;
}
if (Timeout == 255) {
return EFI_TIMEOUT;
}
NULL,
NULL,
);
return Status;
}
);
goto ON_EXIT;
}
NULL,
NULL,
);
goto ON_EXIT;
}
);
goto ON_EXIT;
}
}
continue;
}
switch (InputKey.UnicodeChar) {
case CTRL ('c'):
break;
case CTRL ('m'):
case 'm':
case 'M':
break;
default:
continue;
}
} else {
case SCAN_F8:
break;
case SCAN_ESC:
break;
default:
continue;
}
}
break;
}
if (DescendEvent != NULL) {
}
if (TimeoutEvent != NULL) {
}
return Status;
}
/**
Select the boot menu.
@param Private Pointer to PxeBc private data.
@param Type The type of the menu.
@param UseDefaultItem Use default item or not.
@retval EFI_ABORTED User cancel operation.
@retval EFI_SUCCESS Select the boot menu success.
@retval EFI_NOT_READY Read the input key from the keybroad has not finish.
**/
)
{
Select = 1;
Index = 0;
*Type = 0;
} else {
}
return EFI_SUCCESS;
}
if (MenuSize == 0) {
return EFI_NOT_READY;
}
while (MenuSize > 0) {
if (Index >= PXEBC_MAX_MENU_NUM) {
break;
}
}
if (UseDefaultItem) {
return EFI_SUCCESS;
}
}
do {
//
// highlight selected row
//
LastSelect = Select;
}
switch (InputKey.UnicodeChar) {
case CTRL ('c'):
break;
break;
case ' ':
case 'd':
case 'D':
break;
case 'u':
case 'U':
break;
default:
}
}
case SCAN_LEFT:
case SCAN_UP:
if (Select > 0) {
--Select;
}
break;
case SCAN_DOWN:
case SCAN_RIGHT:
--Select;
}
break;
case SCAN_PAGE_UP:
case SCAN_HOME:
Select = 0;
break;
case SCAN_PAGE_DOWN:
case SCAN_END:
break;
case SCAN_ESC:
return EFI_ABORTED;
}
/* unhighlight last selected row */
} while (!Finish);
//
// Swap the byte order
//
return EFI_SUCCESS;
}