/** @file
This implementation of EFI_PXE_BASE_CODE_PROTOCOL and EFI_LOAD_FILE_PROTOCOL.
Copyright (c) 2007 - 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"
/**
Enables the use of the PXE Base Code Protocol functions.
This function enables the use of the PXE Base Code Protocol functions. If the
Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, then
EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 formatted
addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 formatted
addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6Supported
field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPORTED will
be returned. If there is not enough memory or other resources to start the PXE
Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwise, the
PXE Base Code Protocol will be started.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] UseIpv6 Specifies the type of IP addresses that are to be
used during the session that is being started.
Set to TRUE for IPv6, and FALSE for IPv4.
@retval EFI_SUCCESS The PXE Base Code Protocol was started.
@retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
@retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported field of the
EFI_PXE_BASE_CODE_MODE structure is FALSE.
@retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in the started state.
@retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
EFI_PXE_BASE_CODE_PROTOCOL structure.
@retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other resources to start the
PXE Base Code Protocol.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_ALREADY_STARTED;
}
//
// Detect whether using IPv6 or not, and set it into mode data.
//
} else {
return EFI_UNSUPPORTED;
}
AsciiPrint ("\n>>Start PXE over IPv6");
//
// Configure udp6 instance to receive data.
//
);
goto ON_ERROR;
}
//
// Configure block size for TFTP as a default value to handle all link layers.
//
//
// PXE over IPv6 starts here, initialize the fields and list header.
//
}
//
// Create event and set status for token to capture ICMP6 error message.
//
);
goto ON_ERROR;
}
} else {
AsciiPrint ("\n>>Start PXE over IPv4");
//
// Configure udp4 instance to receive data.
//
);
goto ON_ERROR;
}
//
// Configure block size for TFTP as a default value to handle all link layers.
//
//
// PXE over IPv4 starts here, initialize the fields.
//
}
//
// Create the event for Arp cache update.
//
);
goto ON_ERROR;
}
//
// Start a periodic timer by second to update Arp cache.
//
);
goto ON_ERROR;
}
//
// Create event and set status for token to capture ICMP error message.
//
);
goto ON_ERROR;
}
}
//
// If PcdTftpBlockSize is set to non-zero, override the default value.
//
if (PcdGet64 (PcdTftpBlockSize) != 0) {
}
//
//
NULL,
NULL,
);
goto ON_ERROR;
}
return EFI_SUCCESS;
}
} else {
}
}
}
return Status;
}
/**
Disable the use of the PXE Base Code Protocol functions.
This function stops all activity on the network device. All the resources allocated
in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is
set to FALSE, and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE
structure is already FALSE, then EFI_NOT_STARTED will be returned.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@retval EFI_SUCCESS The PXE Base Code Protocol was stopped.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.
@retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
EFI_PXE_BASE_CODE_PROTOCOL structure.
@retval Others
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_NOT_STARTED;
}
//
// Configure all the instances for IPv6 as NULL.
//
}
}
}
} else {
//
// Configure all the instances for IPv4 as NULL.
//
}
}
}
Private->CurSrcPort = 0;
Private->BootFileSize = 0;
Private->SolicitTimes = 0;
Private->ElapsedTime = 0;
//
// Reset the mode data.
//
return EFI_SUCCESS;
}
/**
Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6
S.A.R.R (solicit / advertise / request / reply) sequence.
If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before
they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will
be tried in the order in which they are received. Please see the Preboot Execution
Environment (PXE) Specification and Unified Extensible Firmware Interface (UEFI)
Specification for additional details on the implementation of DHCP.
If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
then the DHCP sequence will be stopped and EFI_ABORTED will be returned.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] SortOffers TRUE if the offers received should be sorted. Set to FALSE to
try the offers in the order that they are received.
@retval EFI_SUCCESS Valid DHCP has completed.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
EFI_PXE_BASE_CODE_PROTOCOL structure.
@retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
@retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.
@retval EFI_ABORTED The callback function aborted the DHCP Protocol.
@retval EFI_TIMEOUT The DHCP Protocol timed out.
@retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.
@retval EFI_NO_RESPONSE Valid PXE offer was not received.
**/
)
{
return EFI_INVALID_PARAMETER;
}
Private->SolicitTimes = 0;
Private->ElapsedTime = 0;
return EFI_NOT_STARTED;
}
//
// Stop Udp6Read instance
//
//
// Start S.A.R.R. process to get a IPv6 address and other boot information.
//
goto ON_EXIT;
}
} else {
//
// Stop Udp4Read instance
//
//
// Start D.O.R.A. process to get a IPv4 address and other boot information.
//
goto ON_EXIT;
}
}
} else {
}
//
// Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
// receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
//
return Status;
}
/**
sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the
PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the
EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the
PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure
will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.
In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],
has two uses: It is the Boot Server IP address list used for unicast discovery
(if the UseUCast field is TRUE), and it is the list used for Boot Server verification
(if the MustUseList field is TRUE). Also, if the MustUseList field in that structure
is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot
Server reply of that type will be accepted. If the AcceptAnyResponse field is
FALSE, only responses from Boot Servers with matching IP addresses will be accepted.
This function can take at least 10 seconds to timeout and return control to the
caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be
returned. Please see the Preboot Execution Environment (PXE) Specification for
additional details on the implementation of the Discovery sequence.
If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
then the Discovery sequence is stopped and EFI_ABORTED will be returned.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] Type The type of bootstrap to perform.
@param[in] Layer Pointer to the boot server layer number to discover, which must be
PXE_BOOT_LAYER_INITIAL when a new server type is being
discovered.
@param[in] UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.
@param[in] Info Pointer to a data structure that contains additional information
on the type of discovery operation that is to be performed.
It is optional.
@retval EFI_SUCCESS The Discovery sequence has been completed.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
@retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.
@retval EFI_ABORTED The callback function aborted the Discovery sequence.
@retval EFI_TIMEOUT The Discovery sequence timed out.
@retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery
session.
**/
)
{
return EFI_INVALID_PARAMETER;
}
BootSvrEntry = NULL;
return EFI_NOT_STARTED;
}
//
// Station address should be ready before do discover.
//
if (!Private->IsAddressOk) {
return EFI_INVALID_PARAMETER;
}
//
// Stop Udp6Read instance
//
} else {
//
// Stop Udp4Read instance
//
}
//
// There are 3 methods to get the information for discover.
//
if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) {
//
// 1. Take the previous setting as the discover info.
//
if (!Mode->PxeDiscoverValid ||
!Mode->PxeReplyReceived ||
goto ON_EXIT;
}
Info = &DefaultInfo;
//
// 2. Extract the discover information from the cached packets if unspecified.
//
Info = &DefaultInfo;
goto ON_EXIT;
}
} else {
//
// 3. Take the pass-in information as the discover info, and validate the server list.
//
if (!SrvList[0].AcceptAnyResponse) {
break;
}
}
//
// It's invalid if the first server doesn't accecpt any response
// and meanwhile any of the rest servers accept any reponse.
//
goto ON_EXIT;
}
}
}
//
// Info and BootSvrEntry/SrvList are all ready by now, so execute discover by UniCast/BroadCast/MultiCast.
//
goto ON_EXIT;
}
//
// Do discover by unicast.
//
if (BootSvrEntry == NULL) {
} else {
}
Type,
0,
);
}
//
// Do discover by multicast.
//
Type,
0,
);
//
// Do discover by broadcast, but only valid for IPv4.
//
Type,
NULL,
);
}
goto ON_EXIT;
} else {
//
// Parse the cached PXE reply packet, and store it into mode data if valid.
//
CopyMem (
);
}
} else {
CopyMem (
);
}
}
}
} else {
}
//
// Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
// receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
//
return Status;
}
/**
Used to perform TFTP and MTFTP services.
This function is used to perform TFTP and MTFTP services. This includes the
TFTP operations to get the size of a file, read a directory, read a file, and
write a file. It also includes the MTFTP operations to get the size of a file,
read a directory, and read a file. The type of operation is specified by Operation.
not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will
be returned.
For read operations, the return data will be placed in the buffer specified by
BufferPtr. If BufferSize is too small to contain the entire downloaded file,
then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero,
or the size of the requested file. (NOTE: the size of the requested file is only returned
if the TFTP server supports TFTP options). If BufferSize is large enough for the
read operation, then BufferSize will be set to the size of the downloaded file,
and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services
should use the get-file-size operations to determine the size of the downloaded
file prior to using the read-file operations-especially when downloading large
(greater than 64 MB) files-instead of making two calls to the read-file operation.
Following this recommendation will save time if the file is larger than expected
and the TFTP server does not support TFTP option extensions. Without TFTP option
extension support, the client must download the entire file, counting and discarding
the received packets, to determine the file size.
For write operations, the data to be sent is in the buffer specified by BufferPtr.
BufferSize specifies the number of bytes to send. If the write operation completes
successfully, then EFI_SUCCESS will be returned.
For TFTP "get file size" operations, the size of the requested file or directory
is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server
does not support options, the file will be downloaded into a bit bucket and the
length of the downloaded file will be returned. For MTFTP "get file size" operations,
if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED
will be returned.
This function can take up to 10 seconds to timeout and return control to the caller.
If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.
If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
then the TFTP sequence is stopped and EFI_ABORTED will be returned.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] Operation The type of operation to perform.
@param[in, out] BufferPtr A pointer to the data buffer.
@param[in] Overwrite Only used on write file operations. TRUE if a file on a remote
server can be overwritten.
@param[in, out] BufferSize For get-file-size operations, *BufferSize returns the size of the
requested file.
@param[in] BlockSize The requested block size to be used during a TFTP transfer.
@param[in] ServerIp The TFTP / MTFTP server IP address.
@param[in] Filename A Null-terminated ASCII string that specifies a directory name
or a file name.
@param[in] Info Pointer to the MTFTP information.
@param[in] DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
@retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.
@retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.
@retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.
**/
)
{
(BufferSize == NULL) ||
return EFI_INVALID_PARAMETER;
}
//
// Set configuration data for Mtftp6 instance.
//
Config = &Mtftp6Config;
//
// Stop Udp6Read instance
//
} else {
//
// Set configuration data for Mtftp4 instance.
//
Config = &Mtftp4Config;
//
// Stop Udp4Read instance
//
}
switch (Operation) {
//
// Send TFTP request to get file size.
//
);
break;
//
// Send TFTP request to read file.
//
);
break;
//
// Send TFTP request to write file.
//
);
break;
//
// Send TFTP request to read directory.
//
);
break;
break;
default:
break;
}
if (Status == EFI_ICMP_ERROR) {
}
goto ON_EXIT;
}
} else {
}
//
// Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
// receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
//
return Status;
}
/**
Writes a UDP packet to the network interface.
This function writes a UDP packet specified by the (optional HeaderPtr and)
BufferPtr parameters to the network interface. The UDP header is automatically
built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,
SrcIp, and SrcPort to build this header. If the packet is successfully built and
transmitted through the network interface, then EFI_SUCCESS will be returned.
If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will
be returned. If an ICMP error occurs during the transmission of the packet, then
the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and
EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return
EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] OpFlags The UDP operation flags.
@param[in] DestIp The destination IP address.
@param[in] DestPort The destination UDP port number.
@param[in] GatewayIp The gateway IP address.
@param[in] SrcIp The source IP address.
@param[in, out] SrcPort The source UDP port number.
@param[in] HeaderSize An optional field which may be set to the length of a header
at HeaderPtr to be prefixed to the data at BufferPtr.
@param[in] HeaderPtr If HeaderSize is not NULL, a pointer to a header to be
prefixed to the data at BufferPtr.
@param[in] BufferSize A pointer to the size of the data at BufferPtr.
@param[in] BufferPtr A pointer to the data to be written.
@retval EFI_SUCCESS The UDP Write operation completed.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.
@retval EFI_ABORTED The callback function aborted the UDP Write operation.
@retval EFI_TIMEOUT The UDP Write operation timed out.
@retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.
**/
)
{
return EFI_INVALID_PARAMETER;
}
if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_MAY_FRAGMENT) != 0) {
} else {
}
//
// Gateway is provided but it's not a unicast IPv4 address, while it will be ignored for IPv6.
//
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_NOT_STARTED;
}
return EFI_INVALID_PARAMETER;
}
if (Private->CurSrcPort == 0 ||
//
//
}
}
);
} else {
//
// Configure the UDPv4 instance with gateway information from DHCP server as default.
//
);
}
Private->CurSrcPort = 0;
return EFI_INVALID_PARAMETER;
}
//
// Start a timer as timeout event for this blocking API.
//
//
// Construct UDPv6 session data.
//
}
}
Status = PxeBcUdp6Write (
);
} else {
//
// Construct UDPv4 session data.
//
}
}
//
// Override the gateway information if user specified.
//
Status = PxeBcUdp4Write (
);
}
//
// Reset the UdpWrite instance.
//
} else {
}
return Status;
}
/**
Reads a UDP packet from the network interface.
+
This function reads a UDP packet from a network interface. The data contents
are returned in (the optional HeaderPtr and) BufferPtr, and the size of the
buffer received is returned in BufferSize . If the input BufferSize is smaller
than the UDP packet received (less optional HeaderSize), it will be set to the
required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the
contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is
successfully received, then EFI_SUCCESS will be returned, and the information
from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if
they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,
SrcIp, and SrcPort input values, different types of UDP packet receive filtering
will be performed. The following tables summarize these receive filter operations.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] OpFlags The UDP operation flags.
@param[in, out] DestIp The destination IP address.
@param[in, out] DestPort The destination UDP port number.
@param[in, out] SrcIp The source IP address.
@param[in, out] SrcPort The source UDP port number.
@param[in] HeaderSize An optional field which may be set to the length of a
header at HeaderPtr to be prefixed to the data at BufferPtr.
@param[in] HeaderPtr If HeaderSize is not NULL, a pointer to a header to be
prefixed to the data at BufferPtr.
@param[in, out] BufferSize A pointer to the size of the data at BufferPtr.
@param[in] BufferPtr A pointer to the data to be read.
@retval EFI_SUCCESS The UDP Read operation was completed.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
@retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.
@retval EFI_ABORTED The callback function aborted the UDP Read operation.
@retval EFI_TIMEOUT The UDP Read operation timed out.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_NOT_STARTED;
}
&IsDone,
);
return EFI_OUT_OF_RESOURCES;
}
} else {
&IsDone,
);
return EFI_OUT_OF_RESOURCES;
}
}
//
// Start a timer as timeout event for this blocking API.
//
//
//
Status = PxeBcUdp6Read (
Mode,
&IsDone,
);
} else {
Status = PxeBcUdp4Read (
Mode,
&IsDone,
);
}
}
if (Status == EFI_ICMP_ERROR ||
Status == EFI_HOST_UNREACHABLE ||
Status == EFI_PORT_UNREACHABLE) {
//
// Get different return status for icmp error from Udp, refers to UEFI spec.
//
}
if (IsMatched) {
//
// Copy the rececived packet to user if matched by filter.
//
HeaderLen = 0;
if (HeaderSize != NULL) {
}
} else {
if (HeaderSize != NULL) {
*HeaderSize = HeaderLen;
}
HeaderCopiedLen = 0;
BufferCopiedLen = 0;
//
// Copy the header part of received data.
//
} else if (HeaderCopiedLen < HeaderLen) {
//
// Copy the header part of received data.
//
//
// Copy the other part of received data.
//
CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer + CopiedLen, FragmentLength - CopiedLen);
} else {
//
// Copy the other part of received data.
//
}
}
}
//
// Recycle the receiving buffer after copy to user.
//
} else {
HeaderLen = 0;
if (HeaderSize != NULL) {
}
} else {
if (HeaderSize != NULL) {
*HeaderSize = HeaderLen;
}
HeaderCopiedLen = 0;
BufferCopiedLen = 0;
//
// Copy the header part of received data.
//
} else if (HeaderCopiedLen < HeaderLen) {
//
// Copy the header part of received data.
//
//
// Copy the other part of received data.
//
CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer + CopiedLen, FragmentLength - CopiedLen);
} else {
//
// Copy the other part of received data.
//
}
}
}
//
// Recycle the receiving buffer after copy to user.
//
}
}
} else {
}
return Status;
}
/**
Updates the IP receive filters of a network device and enables software filtering.
The NewFilter field is used to modify the network device's current IP receive
filter settings and to enable a software filter. This function updates the IpFilter
field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.
The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().
The current hardware filter remains in effect no matter what the settings of OpFlags.
This is so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those
packets whose reception is enabled in hardware-physical NIC address (unicast),
broadcast address, logical address or addresses (multicast), or all (promiscuous).
UdpRead() does not modify the IP filter settings.
Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive
filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
If an application or driver wishes to preserve the IP receive filter settings,
it will have to preserve the IP receive filter settings before these calls, and
use SetIpFilter() to restore them after the calls. If incompatible filtering is
requested (for example, PROMISCUOUS with anything else), or if the device does not
support a requested filter setting and it cannot be accommodated in software
(for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.
The IPlist field is used to enable IPs other than the StationIP. They may be
multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,
then both the StationIP and the IPs from the IPlist will be used.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] NewFilter Pointer to the new set of IP receive filters.
@retval EFI_SUCCESS The IP receive filter settings were updated.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_NOT_STARTED;
}
//
// IPv4 broadcast address should not be in IP filter.
//
return EFI_INVALID_PARAMETER;
}
//
// is in IpList, promiscuous mode is needed.
//
}
}
if (NeedPromiscuous ||
//
//
//
// Configure UDPv4 to receive all broadcast packets.
//
}
//
// In multicast condition when Promiscuous FALSE and IpCnt no-zero.
// Here check if there is any update of the multicast ip address. If yes,
// we need leave the old multicast group (by Config UDP instance to NULL),
// and join the new multicast group.
//
if (!AcceptPromiscuous) {
} else if (CompareMem (Mode->IpFilter.IpList, NewFilter->IpList, NewFilter->IpCnt * sizeof (EFI_IP_ADDRESS)) != 0 ) {
}
}
}
//
// Check whether we need reconfigure the UDP4 instance.
//
//
// Clear the UDP4 instance configuration, all joined groups will be left
// during the operation.
//
//
// Configure the UDP instance with the new configuration.
//
return Status;
}
//
// In not Promiscuous mode, need to join the new multicast group.
//
if (!AcceptPromiscuous) {
//
// Join the mutilcast group.
//
return Status;
}
}
}
}
}
} else {
//
// Check whether we need reconfigure the UDP6 instance.
//
//
// Clear the UDP6 instance configuration, all joined groups will be left
// during the operation.
//
//
// Configure the UDP instance with the new configuration.
//
return Status;
}
//
// In not Promiscuous mode, need to join the new multicast group.
//
if (!AcceptPromiscuous) {
//
// Join the mutilcast group.
//
return Status;
}
}
}
}
}
}
//
// Save the new IP filter into mode data.
//
return Status;
}
/**
Uses the ARP protocol to resolve a MAC address. It is not supported for IPv6.
This function uses the ARP protocol to resolve a MAC address. The IP address specified
by IpAddr is used to resolve a MAC address. If the ARP protocol succeeds in resolving
the specified address, then the ArpCacheEntries and ArpCache fields of the mode data
are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved
MAC address is placed there as well. If the PXE Base Code protocol is in the
stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters
a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is
returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
then EFI_ABORTED is returned.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] IpAddr Pointer to the IP address that is used to resolve a MAC address.
@param[in] MacAddr If not NULL, a pointer to the MAC address that was resolved with the
ARP protocol.
@retval EFI_SUCCESS The IP or MAC address was resolved.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
@retval EFI_ICMP_ERROR An error occur with the ICMP packet message.
**/
)
{
return EFI_INVALID_PARAMETER;
}
IsResolved = FALSE;
return EFI_NOT_STARTED;
}
return EFI_UNSUPPORTED;
}
//
// Station address should be ready before do arp.
//
if (!Private->IsAddressOk) {
return EFI_INVALID_PARAMETER;
}
//
// If AutoArp is FALSE, only search in the current Arp cache.
//
goto ON_EXIT;
}
} else {
);
goto ON_EXIT;
}
//
// If AutoArp is TRUE, try to send Arp request on initiative.
//
goto ON_EXIT;
}
while (!IsResolved) {
break;
}
}
} else {
}
}
//
// Copy the Mac address to user if needed.
//
}
if (ResolvedEvent != NULL) {
}
return Status;
}
/**
Updates the parameters that affect the operation of the PXE Base Code Protocol.
This function sets parameters that affect the operation of the PXE Base Code Protocol.
The parameter specified by NewAutoArp is used to control the generation of ARP
protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated
as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP
Protocol packets will be generated. In this case, the only mappings that are
available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.
If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol
service, then the service will fail. This function updates the AutoArp field of
the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.
The SetParameters() call must be invoked after a Callback Protocol is installed
to enable the use of callbacks.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the
current value of AutoARP.
@param[in] NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the
current value of SendGUID.
@param[in] NewTTL If not NULL, a pointer to be used in place of the current value of TTL,
the "time to live" field of the IP header.
@param[in] NewToS If not NULL, a pointer to be used in place of the current value of ToS,
the "type of service" field of the IP header.
@param[in] NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the
current value of the MakeCallback field of the Mode structure.
@retval EFI_SUCCESS The new parameters values were updated.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_NOT_STARTED;
}
if (NewMakeCallback != NULL) {
if (*NewMakeCallback) {
//
// Update the previous PxeBcCallback protocol.
//
);
return EFI_INVALID_PARAMETER;
}
} else {
}
}
if (NewSendGUID != NULL) {
return EFI_INVALID_PARAMETER;
}
}
if (NewAutoArp != NULL) {
}
}
}
return EFI_SUCCESS;
}
/**
device. The NewStationIp field is used to modify the network device's current IP address.
If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,
this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure
with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet
mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.
Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE
structure with NewSubnetMask.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] NewStationIp Pointer to the new IP address to be used by the network device.
@param[in] NewSubnetMask Pointer to the new subnet mask to be used by the network device.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
)
{
return EFI_INVALID_PARAMETER;
}
if (NewStationIp != NULL &&
return EFI_INVALID_PARAMETER;
}
NewSubnetMask != NULL &&
return EFI_INVALID_PARAMETER;
}
return EFI_NOT_STARTED;
}
//
// Set the IPv6 address by Ip6Config protocol.
//
goto ON_EXIT;
}
//
// Configure the corresponding ARP with the IPv4 address.
//
if (NewSubnetMask != NULL) {
}
}
if (NewStationIp != NULL) {
}
}
return Status;
}
/**
Updates the contents of the cached DHCP and Discover packets.
The pointers to the new packets are used to update the contents of the cached
packets in the EFI_PXE_BASE_CODE_MODE structure.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
@param[in] NewDhcpDiscoverValid Pointer to a value that will replace the current
DhcpDiscoverValid field.
@param[in] NewDhcpAckReceived Pointer to a value that will replace the current
DhcpAckReceived field.
@param[in] NewProxyOfferReceived Pointer to a value that will replace the current
ProxyOfferReceived field.
@param[in] NewPxeDiscoverValid Pointer to a value that will replace the current
ProxyOfferReceived field.
@param[in] NewPxeReplyReceived Pointer to a value that will replace the current
PxeReplyReceived field.
@param[in] NewPxeBisReplyReceived Pointer to a value that will replace the current
PxeBisReplyReceived field.
@param[in] NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.
@param[in] NewDhcpAck Pointer to the new cached DHCP Ack packet contents.
@param[in] NewProxyOffer Pointer to the new cached Proxy Offer packet contents.
@param[in] NewPxeDiscover Pointer to the new cached PXE Discover packet contents.
@param[in] NewPxeReply Pointer to the new cached PXE Reply packet contents.
@param[in] NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.
@retval EFI_SUCCESS The cached packet contents were updated.
@retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
@retval EFI_INVALID_PARAMETER This is NULL or does not point to a valid
EFI_PXE_BASE_CODE_PROTOCOL structure.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_NOT_STARTED;
}
if (NewDhcpDiscoverValid != NULL) {
}
if (NewDhcpAckReceived != NULL) {
}
if (NewProxyOfferReceived != NULL) {
}
if (NewPxeDiscoverValid != NULL) {
}
if (NewPxeReplyReceived != NULL) {
}
if (NewPxeBisReplyReceived != NULL) {
}
if (NewDhcpDiscover != NULL) {
}
if (NewDhcpAck != NULL) {
}
if (NewProxyOffer != NULL) {
}
if (NewPxeDiscover != NULL) {
}
if (NewPxeReply != NULL) {
}
if (NewPxeBisReply != NULL) {
}
return EFI_SUCCESS;
}
};
/**
Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has
received, or is waiting to receive a packet.
This function is invoked when the PXE Base Code Protocol is about to transmit, has received,
or is waiting to receive a packet. Parameters Function and Received specify the type of event.
Parameters PacketLen and Packet specify the packet that generated the event. If these fields
are zero and NULL respectively, then this is a status update callback. If the operation specified
by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation
specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to
the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.
The SetParameters() function must be called after a Callback Protocol is installed to enable the
use of callbacks.
@param[in] This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.
@param[in] Function The PXE Base Code Protocol function that is waiting for an event.
@param[in] Received TRUE if the callback is being invoked due to a receive event. FALSE if
the callback is being invoked due to a transmit event.
@param[in] PacketLength The length, in bytes, of Packet. This field will have a value of zero if
this is a wait for receive event.
@param[in] PacketPtr If Received is TRUE, a pointer to the packet that was just received;
otherwise a pointer to the packet that is about to be transmitted.
@retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE If Function specifies a continue operation.
@retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT If Function specifies an abort operation.
**/
)
{
//
// Catch Ctrl-C or ESC to abort.
//
}
}
//
// No print if receive packet
//
if (Received) {
}
//
// Print only for three functions
//
switch (Function) {
//
// Print only for open MTFTP packets, not every MTFTP packets
//
}
}
break;
break;
default:
}
//
// Print '.' when transmit a packet
//
AsciiPrint (".");
}
}
};
/**
Causes the driver to load a specified file.
@param[in] This Protocol instance pointer.
@param[in] FilePath The device specific path of the file to load.
@param[in] BootPolicy If TRUE, indicates that the request originates from the
boot manager is attempting to load FilePath as a boot
selection. If FALSE, then FilePath must match an exact file
to be loaded.
@param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return
code of EFI_SUCCESS, the amount of data transferred to
Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
the size of Buffer required to retrieve the requested file.
@param[in] Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
then no the size of the requested file is returned in
BufferSize.
@retval EFI_SUCCESS The file was loaded.
@retval EFI_UNSUPPORTED The device does not support the provided BootPolicy.
@retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
BufferSize is NULL.
@retval EFI_NO_MEDIA No medium was present to load the file.
@retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
@retval EFI_NO_RESPONSE The remote system did not respond.
@retval EFI_NOT_FOUND The file was not found.
@retval EFI_ABORTED The file load process was manually cancelled.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// Only support BootPolicy
//
if (!BootPolicy) {
return EFI_UNSUPPORTED;
}
//
// Check media status before PXE start
//
MediaPresent = TRUE;
if (!MediaPresent) {
return EFI_NO_MEDIA;
}
//
// Check whether the virtual nic is using IPv6 or not.
//
}
//
// Start Pxe Base Code to initialize PXE boot.
//
}
if (Status != EFI_SUCCESS &&
Status != EFI_UNSUPPORTED &&
Status != EFI_BUFFER_TOO_SMALL) {
//
// There are three cases, which needn't stop pxebc here.
// 1. success to download file.
// 2. success to get file size.
// 3. unsupported.
//
}
return Status;
}