+++ /dev/null
-/** @file\r
- Interface routines for PxeBc.\r
-\r
-Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-\r
-#include "PxeBcImpl.h"\r
-\r
-UINT32 mPxeDhcpTimeout[4] = { 4, 8, 16, 32 };\r
-\r
-/**\r
- Get and record the arp cache.\r
-\r
- @param This Pointer to EFI_PXE_BC_PROTOCOL\r
-\r
- @retval EFI_SUCCESS Arp cache updated successfully\r
- @retval others If error occurs when getting arp cache\r
-\r
-**/\r
-EFI_STATUS\r
-UpdateArpCache (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL * This\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_STATUS Status;\r
- UINT32 EntryLength;\r
- UINT32 EntryCount;\r
- EFI_ARP_FIND_DATA *Entries;\r
- UINT32 Index;\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- Status = Private->Arp->Find (\r
- Private->Arp,\r
- TRUE,\r
- NULL,\r
- &EntryLength,\r
- &EntryCount,\r
- &Entries,\r
- TRUE\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Mode->ArpCacheEntries = MIN (\r
- EntryCount,\r
- EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES\r
- );\r
- for (Index = 0; Index < Mode->ArpCacheEntries; Index ++) {\r
- CopyMem (\r
- &Mode->ArpCache[Index].IpAddr,\r
- Entries + 1,\r
- Entries->SwAddressLength\r
- );\r
- CopyMem (\r
- &Mode->ArpCache[Index].MacAddr,\r
- (UINT8 *) (Entries + 1) + Entries->SwAddressLength,\r
- Entries->HwAddressLength\r
- );\r
- //\r
- // Slip to the next FindData.\r
- //\r
- Entries = (EFI_ARP_FIND_DATA *) ((UINT8 *) Entries + EntryLength);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Timeout routine to update arp cache.\r
-\r
- @param Event Pointer to EFI_PXE_BC_PROTOCOL\r
- @param Context Context of the timer event\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-ArpCacheUpdateTimeout (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- UpdateArpCache ((EFI_PXE_BASE_CODE_PROTOCOL *) Context);\r
-}\r
-\r
-/**\r
- Do arp resolution from arp cache in PxeBcMode.\r
-\r
- @param PxeBcMode The PXE BC mode to look into.\r
- @param Ip4Addr The Ip4 address for resolution.\r
- @param MacAddress The resoluted MAC address if the resolution is successful.\r
- The value is undefined if resolution fails.\r
-\r
- @retval TRUE The resolution is successful.\r
- @retval FALSE Otherwise.\r
-\r
-**/\r
-BOOLEAN\r
-FindInArpCache (\r
- IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,\r
- IN EFI_IPv4_ADDRESS *Ip4Addr,\r
- OUT EFI_MAC_ADDRESS *MacAddress\r
- )\r
-{\r
- UINT32 Index;\r
-\r
- for (Index = 0; Index < PxeBcMode->ArpCacheEntries; Index ++) {\r
- if (EFI_IP4_EQUAL (&PxeBcMode->ArpCache[Index].IpAddr.v4, Ip4Addr)) {\r
- CopyMem (\r
- MacAddress,\r
- &PxeBcMode->ArpCache[Index].MacAddr,\r
- sizeof (EFI_MAC_ADDRESS)\r
- );\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- Notify function for the ICMP receive token, used to process\r
- the received ICMP packets.\r
-\r
- @param Context The PXEBC private data.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-IcmpErrorListenHandlerDpc (\r
- IN VOID *Context\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_IP4_RECEIVE_DATA *RxData;\r
- EFI_IP4_PROTOCOL *Ip4;\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- UINTN Index;\r
- UINT32 CopiedLen;\r
- UINT8 *CopiedPointer;\r
-\r
- Private = (PXEBC_PRIVATE_DATA *) Context;\r
- Mode = &Private->Mode;\r
- Status = Private->IcmpErrorRcvToken.Status;\r
- RxData = Private->IcmpErrorRcvToken.Packet.RxData;\r
- Ip4 = Private->Ip4;\r
-\r
- if (Status == EFI_ABORTED) {\r
- //\r
- // The reception is actively aborted by the consumer, directly return.\r
- //\r
- return;\r
- }\r
-\r
- if (RxData == NULL) {\r
- goto Resume;\r
- }\r
-\r
- if (Status != EFI_ICMP_ERROR) {\r
- //\r
- // The return status should be recognized as EFI_ICMP_ERROR.\r
- //\r
- goto CleanUp;\r
- }\r
-\r
- if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&\r
- (NTOHL (Mode->SubnetMask.Addr[0]) != 0) &&\r
- IP4_NET_EQUAL (NTOHL(Mode->StationIp.Addr[0]), EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0])) &&\r
- !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0]))) {\r
- //\r
- // The source address is not zero and it's not a unicast IP address, discard it.\r
- //\r
- goto CleanUp;\r
- }\r
-\r
- if (!EFI_IP4_EQUAL (&RxData->Header->DestinationAddress, &Mode->StationIp.v4)) {\r
- //\r
- // The dest address is not equal to Station Ip address, discard it.\r
- //\r
- goto CleanUp;\r
- }\r
-\r
- //\r
- // Constructor ICMP error packet\r
- //\r
- CopiedLen = 0;\r
- CopiedPointer = (UINT8 *) &Mode->IcmpError;\r
-\r
- for (Index = 0; Index < RxData->FragmentCount; Index ++) {\r
- CopiedLen += RxData->FragmentTable[Index].FragmentLength;\r
- if (CopiedLen <= sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)) {\r
- CopyMem (\r
- CopiedPointer,\r
- RxData->FragmentTable[Index].FragmentBuffer,\r
- RxData->FragmentTable[Index].FragmentLength\r
- );\r
- } else {\r
- CopyMem (\r
- CopiedPointer,\r
- RxData->FragmentTable[Index].FragmentBuffer,\r
- CopiedLen - sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)\r
- );\r
- }\r
- CopiedPointer += CopiedLen;\r
- }\r
-\r
-CleanUp:\r
- gBS->SignalEvent (RxData->RecycleSignal);\r
-\r
-Resume:\r
- Ip4->Receive (Ip4, &(Private->IcmpErrorRcvToken));\r
-}\r
-\r
-/**\r
- Request IcmpErrorListenHandlerDpc as a DPC at TPL_CALLBACK\r
-\r
- @param Event The event signaled.\r
- @param Context The context passed in by the event notifier.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-IcmpErrorListenHandler (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- //\r
- // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK\r
- //\r
- QueueDpc (TPL_CALLBACK, IcmpErrorListenHandlerDpc, Context);\r
-}\r
-\r
-/**\r
- Enables the use of the PXE Base Code Protocol functions.\r
-\r
- This function enables the use of the PXE Base Code Protocol functions. If the\r
- Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, then\r
- EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 formatted\r
- addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 formatted\r
- addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6Supported\r
- field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPORTED will\r
- be returned. If there is not enough memory or other resources to start the PXE\r
- Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwise, the\r
- PXE Base Code Protocol will be started, and all of the fields of the EFI_PXE_BASE_CODE_MODE\r
- structure will be initialized as follows:\r
- StartedSet to TRUE.\r
- Ipv6SupportedUnchanged.\r
- Ipv6AvailableUnchanged.\r
- UsingIpv6Set to UseIpv6.\r
- BisSupportedUnchanged.\r
- BisDetectedUnchanged.\r
- AutoArpSet to TRUE.\r
- SendGUIDSet to FALSE.\r
- TTLSet to DEFAULT_TTL.\r
- ToSSet to DEFAULT_ToS.\r
- DhcpCompletedSet to FALSE.\r
- ProxyOfferReceivedSet to FALSE.\r
- StationIpSet to an address of all zeros.\r
- SubnetMaskSet to a subnet mask of all zeros.\r
- DhcpDiscoverZero-filled.\r
- DhcpAckZero-filled.\r
- ProxyOfferZero-filled.\r
- PxeDiscoverValidSet to FALSE.\r
- PxeDiscoverZero-filled.\r
- PxeReplyValidSet to FALSE.\r
- PxeReplyZero-filled.\r
- PxeBisReplyValidSet to FALSE.\r
- PxeBisReplyZero-filled.\r
- IpFilterSet the Filters field to 0 and the IpCnt field to 0.\r
- ArpCacheEntriesSet to 0.\r
- ArpCacheZero-filled.\r
- RouteTableEntriesSet to 0.\r
- RouteTableZero-filled.\r
- IcmpErrorReceivedSet to FALSE.\r
- IcmpErrorZero-filled.\r
- TftpErroReceivedSet to FALSE.\r
- TftpErrorZero-filled.\r
- MakeCallbacksSet to TRUE if the PXE Base Code Callback Protocol is available.\r
- Set to FALSE if the PXE Base Code Callback Protocol is not available.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param UseIpv6 Specifies the type of IP addresses that are to be used during the session\r
- that is being started. Set to TRUE for IPv6 addresses, and FALSE for\r
- IPv4 addresses.\r
-\r
- @retval EFI_SUCCESS The PXE Base Code Protocol was started.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this oper\r
- @retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported field of the\r
- EFI_PXE_BASE_CODE_MODE structure is FALSE.\r
- @retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in the started state.\r
- @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r
- EFI_PXE_BASE_CODE_PROTOCOL structure.\r
- @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other resources to start the\r
- PXE Base Code Protocol.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcStart (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN BOOLEAN UseIpv6\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_STATUS Status;\r
-\r
- if (This == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- if (Mode->Started) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
-\r
- if (UseIpv6) {\r
- //\r
- // IPv6 is not supported now.\r
- //\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- AsciiPrint ("\n>>Start PXE over IPv4");\r
-\r
- //\r
- // Configure the udp4 instance to let it receive data\r
- //\r
- Status = Private->Udp4Read->Configure (\r
- Private->Udp4Read,\r
- &Private->Udp4CfgData\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
-\r
- //\r
- // Configure block size for TFTP as a default value to handle all link layers.\r
- //\r
- Private->BlockSize = MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) -\r
- PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;\r
- //\r
- // If PcdTftpBlockSize is set to non-zero, override the default value.\r
- //\r
- if (PcdGet64 (PcdTftpBlockSize) != 0) {\r
- Private->BlockSize = (UINTN) PcdGet64 (PcdTftpBlockSize);\r
- }\r
-\r
- Private->AddressIsOk = FALSE;\r
-\r
- ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE));\r
-\r
- Mode->Started = TRUE;\r
- Mode->TTL = DEFAULT_TTL;\r
- Mode->ToS = DEFAULT_ToS;\r
- Mode->AutoArp = TRUE;\r
-\r
- //\r
- // Create the event for Arp Cache checking.\r
- //\r
- Status = gBS->CreateEvent (\r
- EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
- TPL_CALLBACK,\r
- ArpCacheUpdateTimeout,\r
- This,\r
- &Private->GetArpCacheEvent\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- //\r
- // Start the timeout timer event.\r
- //\r
- Status = gBS->SetTimer (\r
- Private->GetArpCacheEvent,\r
- TimerPeriodic,\r
- TICKS_PER_SECOND\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- //\r
- // Create ICMP error receiving event\r
- //\r
- Status = gBS->CreateEvent (\r
- EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- IcmpErrorListenHandler,\r
- Private,\r
- &(Private->IcmpErrorRcvToken.Event)\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- //\r
- //DHCP4 service allows only one of its children to be configured in\r
- //the active state, If the DHCP4 D.O.R.A started by IP4 auto\r
- //configuration and has not been completed, the Dhcp4 state machine\r
- //will not be in the right state for the PXE to start a new round D.O.R.A.\r
- //so we need to switch it's policy to static.\r
- //\r
- Status = PxeBcSetIp4Policy (Private);\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- //\r
- // start to listen incoming packet\r
- //\r
- Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);\r
- if (!EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
-ON_EXIT:\r
- Private->Ip4->Configure (Private->Ip4, NULL);\r
-\r
- if (Private->IcmpErrorRcvToken.Event != NULL) {\r
- gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);\r
- }\r
-\r
- if (Private->GetArpCacheEvent != NULL) {\r
- gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);\r
- gBS->CloseEvent (Private->GetArpCacheEvent);\r
- }\r
-\r
- Mode->Started = FALSE;\r
- Mode->TTL = 0;\r
- Mode->ToS = 0;\r
- Mode->AutoArp = FALSE;\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Disables the use of the PXE Base Code Protocol functions.\r
-\r
- This function stops all activity on the network device. All the resources allocated\r
- in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is\r
- set to FALSE and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE\r
- structure is already FALSE, then EFI_NOT_STARTED will be returned.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
-\r
- @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.\r
- @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r
- EFI_PXE_BASE_CODE_PROTOCOL structure.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcStop (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
-\r
- if (This == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- Private->Ip4->Cancel (Private->Ip4, NULL);\r
- //\r
- // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's\r
- // events.\r
- //\r
- DispatchDpc ();\r
-\r
- Private->Ip4->Configure (Private->Ip4, NULL);\r
-\r
- //\r
- // Close the ICMP error receiving event.\r
- //\r
- gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);\r
-\r
- //\r
- // Cancel the TimeoutEvent timer.\r
- //\r
- gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);\r
-\r
- //\r
- // Close the TimeoutEvent event.\r
- //\r
- gBS->CloseEvent (Private->GetArpCacheEvent);\r
-\r
- Mode->Started = FALSE;\r
-\r
- Private->CurrentUdpSrcPort = 0;\r
- Private->Udp4Write->Configure (Private->Udp4Write, NULL);\r
- Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL);\r
- Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
-\r
- Private->Dhcp4->Stop (Private->Dhcp4);\r
- Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r
-\r
- Private->FileSize = 0;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6\r
- S.A.R.R (solicit / advertise / request / reply) sequence.\r
-\r
- This function attempts to complete the DHCP sequence. If this sequence is completed,\r
- then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived, StationIp,\r
- SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_BASE_CODE_MODE\r
- structure are filled in.\r
- If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before\r
- they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will\r
- be tried in the order in which they are received. Please see the Preboot Execution\r
- Environment (PXE) Specification for additional details on the implementation of DHCP.\r
- This function can take at least 31 seconds to timeout and return control to the\r
- caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be returned.\r
- If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r
- then the DHCP sequence will be stopped and EFI_ABORTED will be returned.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param SortOffers TRUE if the offers received should be sorted. Set to FALSE to try the\r
- offers in the order that they are received.\r
-\r
- @retval EFI_SUCCESS Valid DHCP has completed.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r
- EFI_PXE_BASE_CODE_PROTOCOL structure.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.\r
- @retval EFI_ABORTED The callback function aborted the DHCP Protocol.\r
- @retval EFI_TIMEOUT The DHCP Protocol timed out.\r
- @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.\r
- @retval EFI_NO_RESPONSE Valid PXE offer was not received.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcDhcp (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN BOOLEAN SortOffers\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_DHCP4_PROTOCOL *Dhcp4;\r
- EFI_DHCP4_CONFIG_DATA Dhcp4CfgData;\r
- EFI_DHCP4_MODE_DATA Dhcp4Mode;\r
- EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];\r
- UINT32 OptCount;\r
- EFI_STATUS Status;\r
- EFI_ARP_CONFIG_DATA ArpConfigData;\r
- EFI_PXE_BASE_CODE_IP_FILTER IpFilter;\r
-\r
- if (This == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
- Dhcp4 = Private->Dhcp4;\r
- Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DHCP;\r
- Private->SortOffers = SortOffers;\r
-\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- Mode->IcmpErrorReceived = FALSE;\r
-\r
- //\r
- // Stop Udp4Read instance\r
- //\r
- Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
-\r
- //\r
- // Initialize the DHCP options and build the option list\r
- //\r
- OptCount = PxeBcBuildDhcpOptions (Private, OptList, TRUE);\r
-\r
- //\r
- // Set the DHCP4 config data.\r
- // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.\r
- //\r
- ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r
- Dhcp4CfgData.OptionCount = OptCount;\r
- Dhcp4CfgData.OptionList = OptList;\r
- Dhcp4CfgData.Dhcp4Callback = PxeBcDhcpCallBack;\r
- Dhcp4CfgData.CallbackContext = Private;\r
- Dhcp4CfgData.DiscoverTryCount = 4;\r
- Dhcp4CfgData.DiscoverTimeout = mPxeDhcpTimeout;\r
-\r
- Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- //\r
- // Zero those arrays to record the varies numbers of DHCP OFFERS.\r
- //\r
- Private->GotProxyOffer = FALSE;\r
- Private->NumOffers = 0;\r
- Private->BootpIndex = 0;\r
- ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r
- ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r
-\r
- Status = Dhcp4->Start (Dhcp4, NULL);\r
- if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
- if (Status == EFI_ICMP_ERROR) {\r
- Mode->IcmpErrorReceived = TRUE;\r
- }\r
- goto ON_EXIT;\r
- }\r
-\r
- Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- ASSERT (Dhcp4Mode.State == Dhcp4Bound);\r
-\r
- CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r
-\r
- CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-\r
- //\r
- // Check the selected offer to see whether BINL is required, if no or BINL is\r
- // finished, set the various Mode members.\r
- //\r
- Status = PxeBcCheckSelectedOffer (Private);\r
-\r
- AsciiPrint ("\n Station IP address is ");\r
-\r
- PxeBcShowIp4Addr (&Private->StationIp.v4);\r
- AsciiPrint ("\n");\r
-\r
-ON_EXIT:\r
- if (EFI_ERROR (Status)) {\r
- Dhcp4->Stop (Dhcp4);\r
- Dhcp4->Configure (Dhcp4, NULL);\r
- } else {\r
- //\r
- // Remove the previously configured option list and callback function\r
- //\r
- ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r
- Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r
-\r
- Private->AddressIsOk = TRUE;\r
-\r
- if (!Mode->UsingIpv6) {\r
- //\r
- // If in IPv4 mode, configure the corresponding ARP with this new\r
- // station IP address.\r
- //\r
- ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r
-\r
- ArpConfigData.SwAddressType = 0x0800;\r
- ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);\r
- ArpConfigData.StationAddress = &Private->StationIp.v4;\r
-\r
- Private->Arp->Configure (Private->Arp, NULL);\r
- Private->Arp->Configure (Private->Arp, &ArpConfigData);\r
-\r
- //\r
- // Updated the route table. Fill the first entry.\r
- //\r
- Mode->RouteTableEntries = 1;\r
- Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];\r
- Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];\r
- Mode->RouteTable[0].GwAddr.Addr[0] = 0;\r
-\r
- //\r
- // Create the default route entry if there is a default router.\r
- //\r
- if (Private->GatewayIp.Addr[0] != 0) {\r
- Mode->RouteTableEntries = 2;\r
- Mode->RouteTable[1].IpAddr.Addr[0] = 0;\r
- Mode->RouteTable[1].SubnetMask.Addr[0] = 0;\r
- Mode->RouteTable[1].GwAddr.Addr[0] = Private->GatewayIp.Addr[0];\r
- }\r
-\r
- //\r
- // Flush new station IP address into Udp4CfgData and Ip4ConfigData\r
- //\r
- CopyMem (&Private->Udp4CfgData.StationAddress, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Private->Udp4CfgData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Private->Ip4ConfigData.StationAddress, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Private->Ip4ConfigData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-\r
- //\r
- // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.\r
- //\r
- Private->Ip4->Cancel (Private->Ip4, &Private->IcmpErrorRcvToken);\r
- Private->Ip4->Configure (Private->Ip4, NULL);\r
-\r
- Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
- }\r
- }\r
-\r
- Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
-\r
- //\r
- // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP\r
- // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r
- //\r
- ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r
- IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r
- This->SetIpFilter (This, &IpFilter);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Attempts to complete the PXE Boot Server and/or boot image discovery sequence.\r
-\r
- This function attempts to complete the PXE Boot Server and/or boot image discovery\r
- sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the\r
- PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the\r
- EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the\r
- PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure\r
- will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.\r
- In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],\r
- has two uses: It is the Boot Server IP address list used for unicast discovery\r
- (if the UseUCast field is TRUE), and it is the list used for Boot Server verification\r
- (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure\r
- is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot\r
- Server reply of that type will be accepted. If the AcceptAnyResponse field is\r
- FALSE, only responses from Boot Servers with matching IP addresses will be accepted.\r
- This function can take at least 10 seconds to timeout and return control to the\r
- caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be\r
- returned. Please see the Preboot Execution Environment (PXE) Specification for\r
- additional details on the implementation of the Discovery sequence.\r
- If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r
- then the Discovery sequence is stopped and EFI_ABORTED will be returned.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param Type The type of bootstrap to perform.\r
- @param Layer Pointer to the boot server layer number to discover, which must be\r
- PXE_BOOT_LAYER_INITIAL when a new server type is being\r
- discovered.\r
- @param UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.\r
- @param Info Pointer to a data structure that contains additional information on the\r
- type of discovery operation that is to be performed.\r
-\r
- @retval EFI_SUCCESS The Discovery sequence has been completed.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.\r
- @retval EFI_ABORTED The callback function aborted the Discovery sequence.\r
- @retval EFI_TIMEOUT The Discovery sequence timed out.\r
- @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery\r
- session.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcDiscover (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN UINT16 Type,\r
- IN UINT16 *Layer,\r
- IN BOOLEAN UseBis,\r
- IN EFI_PXE_BASE_CODE_DISCOVER_INFO *Info OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo;\r
- EFI_PXE_BASE_CODE_DISCOVER_INFO *CreatedInfo;\r
- EFI_PXE_BASE_CODE_SRVLIST *SrvList;\r
- EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList;\r
- PXEBC_CACHED_DHCP4_PACKET *Packet;\r
- PXEBC_VENDOR_OPTION *VendorOpt;\r
- UINT16 Index;\r
- EFI_STATUS Status;\r
- PXEBC_BOOT_SVR_ENTRY *BootSvrEntry;\r
- EFI_PXE_BASE_CODE_IP_FILTER IpFilter;\r
-\r
- if (This == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
- BootSvrEntry = NULL;\r
- SrvList = NULL;\r
- CreatedInfo = NULL;\r
- Status = EFI_DEVICE_ERROR;\r
- Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DISCOVER;\r
-\r
- if (!Private->AddressIsOk) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- //\r
- // Stop Udp4Read instance\r
- //\r
- Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
-\r
- Mode->IcmpErrorReceived = FALSE;\r
-\r
- //\r
- // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,\r
- // use the previous setting;\r
- // If info isn't offered,\r
- // use the cached DhcpAck and ProxyOffer packets.\r
- //\r
- ZeroMem (&DefaultInfo, sizeof (EFI_PXE_BASE_CODE_DISCOVER_INFO));\r
- if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) {\r
-\r
- if (!Mode->PxeDiscoverValid || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {\r
-\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_EXIT;\r
- }\r
-\r
- DefaultInfo.IpCnt = 1;\r
- DefaultInfo.UseUCast = TRUE;\r
-\r
- DefaultSrvList.Type = Type;\r
- DefaultSrvList.AcceptAnyResponse = FALSE;\r
- DefaultSrvList.IpAddr.Addr[0] = Private->ServerIp.Addr[0];\r
-\r
- SrvList = &DefaultSrvList;\r
- Info = &DefaultInfo;\r
- } else if (Info == NULL) {\r
- //\r
- // Create info by the cached packet before\r
- //\r
- Packet = (Mode->ProxyOfferReceived) ? &Private->ProxyOffer : &Private->Dhcp4Ack;\r
- VendorOpt = &Packet->PxeVendorOption;\r
-\r
- if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt->BitMap)) {\r
- //\r
- // Address is not acquired or no discovery options.\r
- //\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_EXIT;\r
- }\r
-\r
- DefaultInfo.UseMCast = (BOOLEAN)!IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
- DefaultInfo.UseBCast = (BOOLEAN)!IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
- DefaultInfo.MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);\r
- DefaultInfo.UseUCast = DefaultInfo.MustUseList;\r
-\r
- if (DefaultInfo.UseMCast) {\r
- //\r
- // Get the multicast discover ip address from vendor option.\r
- //\r
- CopyMem (\r
- &DefaultInfo.ServerMCastIp.Addr,\r
- &VendorOpt->DiscoverMcastIp,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- }\r
-\r
- DefaultInfo.IpCnt = 0;\r
- Info = &DefaultInfo;\r
- SrvList = Info->SrvList;\r
-\r
- if (DefaultInfo.MustUseList) {\r
- BootSvrEntry = VendorOpt->BootSvr;\r
- Status = EFI_INVALID_PARAMETER;\r
-\r
- while (((UINT8) (BootSvrEntry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {\r
-\r
- if (BootSvrEntry->Type == HTONS (Type)) {\r
- Status = EFI_SUCCESS;\r
- break;\r
- }\r
-\r
- BootSvrEntry = GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry);\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- DefaultInfo.IpCnt = BootSvrEntry->IpCnt;\r
-\r
- if (DefaultInfo.IpCnt >= 1) {\r
- CreatedInfo = AllocatePool (sizeof (DefaultInfo) + (DefaultInfo.IpCnt - 1) * sizeof (*SrvList));\r
- if (CreatedInfo == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto ON_EXIT;\r
-\r
- }\r
-\r
- CopyMem (CreatedInfo, &DefaultInfo, sizeof (DefaultInfo));\r
- Info = CreatedInfo;\r
- SrvList = Info->SrvList;\r
- }\r
-\r
- for (Index = 0; Index < DefaultInfo.IpCnt; Index++) {\r
- CopyMem (&SrvList[Index].IpAddr, &BootSvrEntry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));\r
- SrvList[Index].AcceptAnyResponse = FALSE;\r
- SrvList[Index].Type = BootSvrEntry->Type;\r
- }\r
- }\r
-\r
- } else {\r
-\r
- SrvList = Info->SrvList;\r
-\r
- if (!SrvList[0].AcceptAnyResponse) {\r
-\r
- for (Index = 1; Index < Info->IpCnt; Index++) {\r
- if (SrvList[Index].AcceptAnyResponse) {\r
- break;\r
- }\r
- }\r
-\r
- if (Index != Info->IpCnt) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_EXIT;\r
- }\r
- }\r
- }\r
-\r
- if ((!Info->UseUCast && !Info->UseBCast && !Info->UseMCast) || (Info->MustUseList && Info->IpCnt == 0)) {\r
-\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_EXIT;\r
- }\r
- //\r
- // Execute discover by UniCast/BroadCast/MultiCast\r
- //\r
- if (Info->UseUCast) {\r
-\r
- for (Index = 0; Index < Info->IpCnt; Index++) {\r
-\r
- if (BootSvrEntry == NULL) {\r
- Private->ServerIp.Addr[0] = SrvList[Index].IpAddr.Addr[0];\r
- } else {\r
- CopyMem (\r
- &Private->ServerIp,\r
- &BootSvrEntry->IpAddr[Index],\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- }\r
-\r
- Status = PxeBcDiscvBootService (\r
- Private,\r
- Type,\r
- Layer,\r
- UseBis,\r
- &SrvList[Index].IpAddr,\r
- 0,\r
- NULL,\r
- TRUE,\r
- &Private->PxeReply.Packet.Ack\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- break;\r
- }\r
- }\r
-\r
- } else if (Info->UseMCast) {\r
-\r
- Status = PxeBcDiscvBootService (\r
- Private,\r
- Type,\r
- Layer,\r
- UseBis,\r
- &Info->ServerMCastIp,\r
- 0,\r
- NULL,\r
- TRUE,\r
- &Private->PxeReply.Packet.Ack\r
- );\r
-\r
- } else if (Info->UseBCast) {\r
-\r
- Status = PxeBcDiscvBootService (\r
- Private,\r
- Type,\r
- Layer,\r
- UseBis,\r
- NULL,\r
- Info->IpCnt,\r
- SrvList,\r
- TRUE,\r
- &Private->PxeReply.Packet.Ack\r
- );\r
- }\r
-\r
- if (EFI_ERROR (Status) || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {\r
- if (Status == EFI_ICMP_ERROR) {\r
- Mode->IcmpErrorReceived = TRUE;\r
- } else {\r
- Status = EFI_DEVICE_ERROR;\r
- }\r
- goto ON_EXIT;\r
- } else {\r
- PxeBcParseCachedDhcpPacket (&Private->PxeReply);\r
- }\r
-\r
- if (Mode->PxeBisReplyReceived) {\r
- CopyMem (\r
- &Private->ServerIp,\r
- &Mode->PxeReply.Dhcpv4.BootpSiAddr,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- }\r
-\r
- if (CreatedInfo != NULL) {\r
- FreePool (CreatedInfo);\r
- }\r
-\r
-ON_EXIT:\r
-\r
- Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
-\r
- //\r
- // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP\r
- // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r
- //\r
- ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r
- IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r
- This->SetIpFilter (This, &IpFilter);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Used to perform TFTP and MTFTP services.\r
-\r
- This function is used to perform TFTP and MTFTP services. This includes the\r
- TFTP operations to get the size of a file, read a directory, read a file, and\r
- write a file. It also includes the MTFTP operations to get the size of a file,\r
- read a directory, and read a file. The type of operation is specified by Operation.\r
- If the callback function that is invoked during the TFTP/MTFTP operation does\r
- not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will\r
- be returned.\r
- For read operations, the return data will be placed in the buffer specified by\r
- BufferPtr. If BufferSize is too small to contain the entire downloaded file,\r
- then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero\r
- or the size of the requested file (the size of the requested file is only returned\r
- if the TFTP server supports TFTP options). If BufferSize is large enough for the\r
- read operation, then BufferSize will be set to the size of the downloaded file,\r
- and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services\r
- should use the get-file-size operations to determine the size of the downloaded\r
- file prior to using the read-file operations-especially when downloading large\r
- (greater than 64 MB) files-instead of making two calls to the read-file operation.\r
- Following this recommendation will save time if the file is larger than expected\r
- and the TFTP server does not support TFTP option extensions. Without TFTP option\r
- extension support, the client has to download the entire file, counting and discarding\r
- the received packets, to determine the file size.\r
- For write operations, the data to be sent is in the buffer specified by BufferPtr.\r
- BufferSize specifies the number of bytes to send. If the write operation completes\r
- successfully, then EFI_SUCCESS will be returned.\r
- For TFTP "get file size" operations, the size of the requested file or directory\r
- is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server\r
- does not support options, the file will be downloaded into a bit bucket and the\r
- length of the downloaded file will be returned. For MTFTP "get file size" operations,\r
- if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED\r
- will be returned.\r
- This function can take up to 10 seconds to timeout and return control to the caller.\r
- If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.\r
- If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r
- then the TFTP sequence is stopped and EFI_ABORTED will be returned.\r
- The format of the data returned from a TFTP read directory operation is a null-terminated\r
- filename followed by a null-terminated information string, of the form\r
- "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - note that\r
- the seconds field can be a decimal number), where the date and time are UTC. For\r
- an MTFTP read directory command, there is additionally a null-terminated multicast\r
- IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The final\r
- entry is itself null-terminated, so that the final information string is terminated\r
- with two null octets.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param Operation The type of operation to perform.\r
- @param BufferPtr A pointer to the data buffer.\r
- @param Overwrite Only used on write file operations. TRUE if a file on a remote server can\r
- be overwritten.\r
- @param BufferSize For get-file-size operations, *BufferSize returns the size of the\r
- requested file.\r
- @param BlockSize The requested block size to be used during a TFTP transfer.\r
- @param ServerIp The TFTP / MTFTP server IP address.\r
- @param Filename A Null-terminated ASCII string that specifies a directory name or a file\r
- name.\r
- @param Info Pointer to the MTFTP information.\r
- @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.\r
-\r
- @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.\r
- @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.\r
- @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.\r
- @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.\r
- @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcMtftp (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,\r
- IN OUT VOID *BufferPtr,\r
- IN BOOLEAN Overwrite,\r
- IN OUT UINT64 *BufferSize,\r
- IN UINTN *BlockSize OPTIONAL,\r
- IN EFI_IP_ADDRESS *ServerIp,\r
- IN UINT8 *Filename,\r
- IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL,\r
- IN BOOLEAN DontUseBuffer\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_MTFTP4_CONFIG_DATA Mtftp4Config;\r
- EFI_STATUS Status;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_MAC_ADDRESS TempMacAddr;\r
- EFI_PXE_BASE_CODE_IP_FILTER IpFilter;\r
-\r
- if ((This == NULL) ||\r
- (Filename == NULL) ||\r
- (BufferSize == NULL) ||\r
- ((ServerIp == NULL) ||\r
- (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) ||\r
- IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0])))) ||\r
- ((BufferPtr == NULL) && DontUseBuffer) ||\r
- ((BlockSize != NULL) && (*BlockSize < 512))) {\r
-\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = EFI_DEVICE_ERROR;\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = &Private->Mode;\r
-\r
- if (!Mode->AutoArp) {\r
- //\r
- // If AutoArp is set false, check arp cache\r
- //\r
- UpdateArpCache (This);\r
- if (!FindInArpCache (Mode, &ServerIp->v4, &TempMacAddr)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- }\r
-\r
- //\r
- // Stop Udp4Read instance\r
- //\r
- Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
-\r
- Mode->TftpErrorReceived = FALSE;\r
- Mode->IcmpErrorReceived = FALSE;\r
-\r
- Mtftp4Config.UseDefaultSetting = FALSE;\r
- Mtftp4Config.TimeoutValue = PXEBC_MTFTP_TIMEOUT;\r
- Mtftp4Config.TryCount = PXEBC_MTFTP_RETRIES;\r
-\r
- CopyMem (\r
- &Mtftp4Config.StationIp,\r
- &Private->StationIp,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- CopyMem (\r
- &Mtftp4Config.SubnetMask,\r
- &Private->SubnetMask,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- CopyMem (\r
- &Mtftp4Config.GatewayIp,\r
- &Private->GatewayIp,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- CopyMem (\r
- &Mtftp4Config.ServerIp,\r
- ServerIp,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
-\r
- switch (Operation) {\r
-\r
- case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE:\r
-\r
- Status = PxeBcTftpGetFileSize (\r
- Private,\r
- &Mtftp4Config,\r
- Filename,\r
- BlockSize,\r
- BufferSize\r
- );\r
-\r
- break;\r
-\r
- case EFI_PXE_BASE_CODE_TFTP_READ_FILE:\r
-\r
- Status = PxeBcTftpReadFile (\r
- Private,\r
- &Mtftp4Config,\r
- Filename,\r
- BlockSize,\r
- BufferPtr,\r
- BufferSize,\r
- DontUseBuffer\r
- );\r
-\r
- break;\r
-\r
- case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE:\r
-\r
- Status = PxeBcTftpWriteFile (\r
- Private,\r
- &Mtftp4Config,\r
- Filename,\r
- Overwrite,\r
- BlockSize,\r
- BufferPtr,\r
- BufferSize\r
- );\r
-\r
- break;\r
-\r
- case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY:\r
-\r
- Status = PxeBcTftpReadDirectory (\r
- Private,\r
- &Mtftp4Config,\r
- Filename,\r
- BlockSize,\r
- BufferPtr,\r
- BufferSize,\r
- DontUseBuffer\r
- );\r
-\r
- break;\r
-\r
- case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE:\r
- case EFI_PXE_BASE_CODE_MTFTP_READ_FILE:\r
- case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY:\r
- Status = EFI_UNSUPPORTED;\r
- break;\r
-\r
- default:\r
-\r
- Status = EFI_INVALID_PARAMETER;\r
- break;\r
- }\r
-\r
- if (Status == EFI_ICMP_ERROR) {\r
- Mode->IcmpErrorReceived = TRUE;\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
-ON_EXIT:\r
- Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
- //\r
- // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP\r
- // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r
- //\r
- ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r
- IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r
- This->SetIpFilter (This, &IpFilter);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Writes a UDP packet to the network interface.\r
-\r
- This function writes a UDP packet specified by the (optional HeaderPtr and)\r
- BufferPtr parameters to the network interface. The UDP header is automatically\r
- built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,\r
- SrcIp, and SrcPort to build this header. If the packet is successfully built and\r
- transmitted through the network interface, then EFI_SUCCESS will be returned.\r
- If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will\r
- be returned. If an ICMP error occurs during the transmission of the packet, then\r
- the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and\r
- EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return\r
- EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param OpFlags The UDP operation flags.\r
- @param DestIp The destination IP address.\r
- @param DestPort The destination UDP port number.\r
- @param GatewayIp The gateway IP address.\r
- @param SrcIp The source IP address.\r
- @param SrcPort The source UDP port number.\r
- @param HeaderSize An optional field which may be set to the length of a header at\r
- HeaderPtr to be prefixed to the data at BufferPtr.\r
- @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the\r
- data at BufferPtr.\r
- @param BufferSize A pointer to the size of the data at BufferPtr.\r
- @param BufferPtr A pointer to the data to be written.\r
-\r
- @retval EFI_SUCCESS The UDP Write operation was completed.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
- @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.\r
- @retval EFI_ABORTED The callback function aborted the UDP Write operation.\r
- @retval EFI_TIMEOUT The UDP Write operation timed out.\r
- @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcUdpWrite (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN UINT16 OpFlags,\r
- IN EFI_IP_ADDRESS *DestIp,\r
- IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,\r
- IN EFI_IP_ADDRESS *GatewayIp OPTIONAL,\r
- IN EFI_IP_ADDRESS *SrcIp OPTIONAL,\r
- IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,\r
- IN UINTN *HeaderSize OPTIONAL,\r
- IN VOID *HeaderPtr OPTIONAL,\r
- IN UINTN *BufferSize,\r
- IN VOID *BufferPtr\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_UDP4_PROTOCOL *Udp4;\r
- EFI_UDP4_COMPLETION_TOKEN Token;\r
- EFI_UDP4_TRANSMIT_DATA *Udp4TxData;\r
- UINT32 FragCount;\r
- UINT32 DataLength;\r
- EFI_UDP4_SESSION_DATA Udp4Session;\r
- EFI_STATUS Status;\r
- BOOLEAN IsDone;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_MAC_ADDRESS TempMacAddr;\r
-\r
- IsDone = FALSE;\r
-\r
- if ((This == NULL) || (DestIp == NULL) || (DestPort == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((GatewayIp != NULL) && (IP4_IS_UNSPECIFIED (NTOHL (GatewayIp->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (GatewayIp->Addr[0])))) {\r
- //\r
- // Gateway is provided but it's not a unicast IP address.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((HeaderSize != NULL) && ((*HeaderSize == 0) || (HeaderPtr == NULL))) {\r
- //\r
- // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr\r
- // is NULL.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((BufferSize == NULL) || ((*BufferSize != 0) && (BufferPtr == NULL))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Udp4 = Private->Udp4Write;\r
- Mode = &Private->Mode;\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- if (!Private->AddressIsOk && (SrcIp == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (!Mode->AutoArp) {\r
- //\r
- // If AutoArp is set false, check arp cache\r
- //\r
- UpdateArpCache (This);\r
- if (!FindInArpCache (Mode, &DestIp->v4, &TempMacAddr)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- }\r
-\r
- Mode->IcmpErrorReceived = FALSE;\r
-\r
- if ((Private->CurrentUdpSrcPort == 0) ||\r
- ((SrcPort != NULL) && (*SrcPort != Private->CurrentUdpSrcPort))) {\r
- //\r
- // Port is changed, (re)configure the Udp4Write instance\r
- //\r
- if (SrcPort != NULL) {\r
- Private->CurrentUdpSrcPort = *SrcPort;\r
- }\r
- }\r
-\r
- Status = PxeBcConfigureUdpWriteInstance (\r
- Udp4,\r
- &Private->StationIp.v4,\r
- &Private->SubnetMask.v4,\r
- &Private->GatewayIp.v4,\r
- &Private->CurrentUdpSrcPort,\r
- Private->Mode.TTL,\r
- Private->Mode.ToS\r
- );\r
- if (EFI_ERROR (Status)) {\r
- Private->CurrentUdpSrcPort = 0;\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- ZeroMem (&Token, sizeof (EFI_UDP4_COMPLETION_TOKEN));\r
- ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA));\r
-\r
- CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r
- Udp4Session.DestinationPort = *DestPort;\r
- if (SrcIp != NULL) {\r
- CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));\r
- }\r
- if (SrcPort != NULL) {\r
- Udp4Session.SourcePort = *SrcPort;\r
- }\r
-\r
- FragCount = (HeaderSize != NULL) ? 2 : 1;\r
- Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r
- if (Udp4TxData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- Udp4TxData->FragmentCount = FragCount;\r
- Udp4TxData->FragmentTable[FragCount - 1].FragmentLength = (UINT32) *BufferSize;\r
- Udp4TxData->FragmentTable[FragCount - 1].FragmentBuffer = BufferPtr;\r
- DataLength = (UINT32) *BufferSize;\r
-\r
- if (FragCount == 2) {\r
-\r
- Udp4TxData->FragmentTable[0].FragmentLength = (UINT32) *HeaderSize;\r
- Udp4TxData->FragmentTable[0].FragmentBuffer = HeaderPtr;\r
- DataLength += (UINT32) *HeaderSize;\r
- }\r
-\r
- if (GatewayIp != NULL) {\r
- Udp4TxData->GatewayAddress = (EFI_IPv4_ADDRESS *) GatewayIp;\r
- }\r
- Udp4TxData->UdpSessionData = &Udp4Session;\r
- Udp4TxData->DataLength = DataLength;\r
- Token.Packet.TxData = Udp4TxData;\r
-\r
- Status = gBS->CreateEvent (\r
- EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- PxeBcCommonNotify,\r
- &IsDone,\r
- &Token.Event\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- Status = Udp4->Transmit (Udp4, &Token);\r
- if (EFI_ERROR (Status)) {\r
- if (Status == EFI_ICMP_ERROR) {\r
- Mode->IcmpErrorReceived = TRUE;\r
- }\r
- goto ON_EXIT;\r
- }\r
-\r
- while (!IsDone) {\r
-\r
- Udp4->Poll (Udp4);\r
- }\r
-\r
- Status = Token.Status;\r
-\r
-ON_EXIT:\r
-\r
- if (Token.Event != NULL) {\r
- gBS->CloseEvent (Token.Event);\r
- }\r
-\r
- FreePool (Udp4TxData);\r
-\r
- //\r
- // Reset the instance.\r
- //\r
- Udp4->Configure (Udp4, NULL);\r
- return Status;\r
-}\r
-\r
-/**\r
- Decide whether the incoming UDP packet is acceptable per IP filter settings\r
- in provided PxeBcMode.\r
-\r
- @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.\r
- @param Session Received UDP session.\r
-\r
- @retval TRUE The UDP package matches IP filters.\r
- @retval FALSE The UDP package doesn't matches IP filters.\r
-\r
-**/\r
-BOOLEAN\r
-CheckIpByFilter (\r
- IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,\r
- IN EFI_UDP4_SESSION_DATA *Session\r
- )\r
-{\r
- UINTN Index;\r
- EFI_IPv4_ADDRESS Ip4Address;\r
- EFI_IPv4_ADDRESS DestIp4Address;\r
-\r
- if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0) {\r
- return TRUE;\r
- }\r
-\r
- CopyMem (&DestIp4Address, &Session->DestinationAddress, sizeof (DestIp4Address));\r
- if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) != 0) &&\r
- IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address))\r
- ) {\r
- return TRUE;\r
- }\r
-\r
- if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) != 0) &&\r
- IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address))\r
- ) {\r
- return TRUE;\r
- }\r
-\r
- CopyMem (&Ip4Address, &PxeBcMode->StationIp.v4, sizeof (Ip4Address));\r
- if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) &&\r
- EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)\r
- ) {\r
- return TRUE;\r
- }\r
-\r
- ASSERT (PxeBcMode->IpFilter.IpCnt < EFI_PXE_BASE_CODE_MAX_IPCNT);\r
-\r
- for (Index = 0; Index < PxeBcMode->IpFilter.IpCnt; Index++) {\r
- CopyMem (\r
- &Ip4Address,\r
- &PxeBcMode->IpFilter.IpList[Index].v4,\r
- sizeof (Ip4Address)\r
- );\r
- if (EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- Reads a UDP packet from the network interface.\r
-\r
- This function reads a UDP packet from a network interface. The data contents\r
- are returned in (the optional HeaderPtr and) BufferPtr, and the size of the\r
- buffer received is returned in BufferSize . If the input BufferSize is smaller\r
- than the UDP packet received (less optional HeaderSize), it will be set to the\r
- required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the\r
- contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is\r
- successfully received, then EFI_SUCCESS will be returned, and the information\r
- from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if\r
- they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,\r
- SrcIp, and SrcPort input values, different types of UDP packet receive filtering\r
- will be performed. The following tables summarize these receive filter operations.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param OpFlags The UDP operation flags.\r
- @param DestIp The destination IP address.\r
- @param DestPort The destination UDP port number.\r
- @param SrcIp The source IP address.\r
- @param SrcPort The source UDP port number.\r
- @param HeaderSize An optional field which may be set to the length of a header at\r
- HeaderPtr to be prefixed to the data at BufferPtr.\r
- @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the\r
- data at BufferPtr.\r
- @param BufferSize A pointer to the size of the data at BufferPtr.\r
- @param BufferPtr A pointer to the data to be read.\r
-\r
- @retval EFI_SUCCESS The UDP Read operation was completed.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.\r
- @retval EFI_ABORTED The callback function aborted the UDP Read operation.\r
- @retval EFI_TIMEOUT The UDP Read operation timed out.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcUdpRead (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN UINT16 OpFlags,\r
- IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,\r
- IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,\r
- IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,\r
- IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,\r
- IN UINTN *HeaderSize OPTIONAL,\r
- IN VOID *HeaderPtr OPTIONAL,\r
- IN OUT UINTN *BufferSize,\r
- IN VOID *BufferPtr\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_UDP4_PROTOCOL *Udp4;\r
- EFI_UDP4_COMPLETION_TOKEN Token;\r
- EFI_UDP4_RECEIVE_DATA *RxData;\r
- EFI_UDP4_SESSION_DATA *Session;\r
- EFI_STATUS Status;\r
- BOOLEAN IsDone;\r
- BOOLEAN Matched;\r
- UINTN CopiedLen;\r
- UINTN HeaderLen;\r
- UINTN HeaderCopiedLen;\r
- UINTN BufferCopiedLen;\r
- UINT32 FragmentLength;\r
- UINTN FragmentIndex;\r
- UINT8 *FragmentBuffer;\r
-\r
- if (This == NULL || DestIp == NULL || DestPort == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (DestPort == NULL)) ||\r
- ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (SrcIp == NULL)) ||\r
- ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) == 0 && (SrcPort == NULL))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderSize != NULL) && (HeaderPtr == NULL))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((BufferSize == NULL) || (BufferPtr == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
- Udp4 = Private->Udp4Read;\r
-\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- Mode->IcmpErrorReceived = FALSE;\r
-\r
- Status = gBS->CreateEvent (\r
- EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- PxeBcCommonNotify,\r
- &IsDone,\r
- &Token.Event\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
-TRY_AGAIN:\r
-\r
- IsDone = FALSE;\r
- Status = Udp4->Receive (Udp4, &Token);\r
- if (EFI_ERROR (Status)) {\r
- if (Status == EFI_ICMP_ERROR) {\r
- Mode->IcmpErrorReceived = TRUE;\r
- }\r
- goto ON_EXIT;\r
- }\r
-\r
- Udp4->Poll (Udp4);\r
-\r
- if (!IsDone) {\r
- Status = EFI_TIMEOUT;\r
- } else {\r
-\r
- //\r
- // check whether this packet matches the filters\r
- //\r
- if (EFI_ERROR (Token.Status)){\r
- goto ON_EXIT;\r
- }\r
-\r
- RxData = Token.Packet.RxData;\r
- Session = &RxData->UdpSession;\r
-\r
- Matched = TRUE;\r
-\r
- if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER) != 0) {\r
- Matched = FALSE;\r
- //\r
- // Check UDP package by IP filter settings\r
- //\r
- if (CheckIpByFilter (Mode, Session)) {\r
- Matched = TRUE;\r
- }\r
- }\r
-\r
- if (Matched) {\r
- Matched = FALSE;\r
-\r
- //\r
- // Match the destination ip of the received udp dgram\r
- //\r
- if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP) != 0) {\r
- Matched = TRUE;\r
-\r
- if (DestIp != NULL) {\r
- CopyMem (DestIp, &Session->DestinationAddress, sizeof (EFI_IPv4_ADDRESS));\r
- }\r
- } else {\r
- if (DestIp != NULL) {\r
- if (EFI_IP4_EQUAL (DestIp, &Session->DestinationAddress)) {\r
- Matched = TRUE;\r
- }\r
- } else {\r
- if (EFI_IP4_EQUAL (&Private->StationIp, &Session->DestinationAddress)) {\r
- Matched = TRUE;\r
- }\r
- }\r
- }\r
- }\r
-\r
- if (Matched) {\r
- //\r
- // Match the destination port of the received udp dgram\r
- //\r
- if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) != 0) {\r
-\r
- if (DestPort != NULL) {\r
- *DestPort = Session->DestinationPort;\r
- }\r
- } else {\r
-\r
- if (*DestPort != Session->DestinationPort) {\r
- Matched = FALSE;\r
- }\r
- }\r
- }\r
-\r
- if (Matched) {\r
- //\r
- // Match the source ip of the received udp dgram\r
- //\r
- if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) != 0) {\r
-\r
- if (SrcIp != NULL) {\r
- CopyMem (SrcIp, &Session->SourceAddress, sizeof (EFI_IPv4_ADDRESS));\r
- }\r
- } else {\r
-\r
- if (!EFI_IP4_EQUAL (SrcIp, &Session->SourceAddress)) {\r
- Matched = FALSE;\r
- }\r
- }\r
- }\r
-\r
- if (Matched) {\r
- //\r
- // Match the source port of the received udp dgram\r
- //\r
- if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) != 0) {\r
-\r
- if (SrcPort != NULL) {\r
- *SrcPort = Session->SourcePort;\r
- }\r
- } else {\r
-\r
- if (*SrcPort != Session->SourcePort) {\r
- Matched = FALSE;\r
- }\r
- }\r
- }\r
-\r
- if (Matched) {\r
- ASSERT (RxData != NULL);\r
-\r
- HeaderLen = 0;\r
- if (HeaderSize != NULL) {\r
- HeaderLen = MIN (*HeaderSize, RxData->DataLength);\r
- }\r
-\r
- if (RxData->DataLength - HeaderLen > *BufferSize) {\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- } else {\r
- *HeaderSize = HeaderLen;\r
- *BufferSize = RxData->DataLength - HeaderLen;\r
-\r
- HeaderCopiedLen = 0;\r
- BufferCopiedLen = 0;\r
- for (FragmentIndex = 0; FragmentIndex < RxData->FragmentCount; FragmentIndex++) {\r
- FragmentLength = RxData->FragmentTable[FragmentIndex].FragmentLength;\r
- FragmentBuffer = RxData->FragmentTable[FragmentIndex].FragmentBuffer;\r
- if (HeaderCopiedLen + FragmentLength < HeaderLen) {\r
- //\r
- // Copy the header part of received data.\r
- //\r
- CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, FragmentLength);\r
- HeaderCopiedLen += FragmentLength;\r
- } else if (HeaderCopiedLen < HeaderLen) {\r
- //\r
- // Copy the header part of received data.\r
- //\r
- CopiedLen = HeaderLen - HeaderCopiedLen;\r
- CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, CopiedLen);\r
- HeaderCopiedLen += CopiedLen;\r
-\r
- //\r
- // Copy the other part of received data.\r
- //\r
- CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer + CopiedLen, FragmentLength - CopiedLen);\r
- BufferCopiedLen += (FragmentLength - CopiedLen);\r
- } else {\r
- //\r
- // Copy the other part of received data.\r
- //\r
- CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer, FragmentLength);\r
- BufferCopiedLen += FragmentLength;\r
- }\r
- }\r
- }\r
- } else {\r
-\r
- Status = EFI_TIMEOUT;\r
- }\r
-\r
- //\r
- // Recycle the RxData\r
- //\r
- gBS->SignalEvent (RxData->RecycleSignal);\r
-\r
- if (!Matched) {\r
- goto TRY_AGAIN;\r
- }\r
- }\r
-\r
-ON_EXIT:\r
-\r
- Udp4->Cancel (Udp4, &Token);\r
-\r
- gBS->CloseEvent (Token.Event);\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Updates the IP receive filters of a network device and enables software filtering.\r
-\r
- The NewFilter field is used to modify the network device's current IP receive\r
- filter settings and to enable a software filter. This function updates the IpFilter\r
- field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.\r
- The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().\r
- The current hardware filter remains in effect no matter what the settings of OpFlags\r
- are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those\r
- packets whose reception is enabled in hardware-physical NIC address (unicast),\r
- broadcast address, logical address or addresses (multicast), or all (promiscuous).\r
- UdpRead() does not modify the IP filter settings.\r
- Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive\r
- filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r
- If an application or driver wishes to preserve the IP receive filter settings,\r
- it will have to preserve the IP receive filter settings before these calls, and\r
- use SetIpFilter() to restore them after the calls. If incompatible filtering is\r
- requested (for example, PROMISCUOUS with anything else) or if the device does not\r
- support a requested filter setting and it cannot be accommodated in software\r
- (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.\r
- The IPlist field is used to enable IPs other than the StationIP. They may be\r
- multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,\r
- then both the StationIP and the IPs from the IPlist will be used.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param NewFilter Pointer to the new set of IP receive filters.\r
-\r
- @retval EFI_SUCCESS The IP receive filter settings were updated.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcSetIpFilter (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter\r
- )\r
-{\r
- EFI_STATUS Status;\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- UINTN Index;\r
- EFI_UDP4_CONFIG_DATA *Udp4Cfg;\r
- BOOLEAN PromiscuousNeed;\r
- BOOLEAN AcceptPromiscuous;\r
- BOOLEAN AcceptBroadcast;\r
- BOOLEAN MultiCastUpdate;\r
-\r
- if (This == NULL) {\r
- DEBUG ((EFI_D_ERROR, "This == NULL.\n"));\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- if (NewFilter == NULL) {\r
- DEBUG ((EFI_D_ERROR, "NewFilter == NULL.\n"));\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (NewFilter->IpCnt > EFI_PXE_BASE_CODE_MAX_IPCNT) {\r
- DEBUG ((EFI_D_ERROR, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX_IPCNT));\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (!Mode->Started) {\r
- DEBUG ((EFI_D_ERROR, "BC was not started.\n"));\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- if (Mode->UsingIpv6) {\r
- DEBUG ((EFI_D_ERROR, "This driver is PXE for IPv4 Only.\n"));\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- PromiscuousNeed = FALSE;\r
-\r
- for (Index = 0; Index < NewFilter->IpCnt; ++Index) {\r
- if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter->IpList[Index].v4))) {\r
- //\r
- // The IP is a broadcast address.\r
- //\r
- DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n"));\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if ((EFI_NTOHL(Mode->StationIp) != 0) &&\r
- (EFI_NTOHL(Mode->SubnetMask) != 0) &&\r
- IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r
- NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r
- ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)) {\r
- //\r
- // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,\r
- // promiscuous mode is needed.\r
- //\r
- PromiscuousNeed = TRUE;\r
- }\r
- }\r
-\r
- AcceptPromiscuous = FALSE;\r
- AcceptBroadcast = FALSE;\r
- MultiCastUpdate = FALSE;\r
-\r
- if (PromiscuousNeed ||\r
- ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0) ||\r
- ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) != 0)\r
- ) {\r
- //\r
- // Configure the udp4 filter to receive all packages.\r
- //\r
- AcceptPromiscuous = TRUE;\r
- } else if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) != 0) {\r
- //\r
- // Configure the udp4 filter to receive all broadcast packages.\r
- //\r
- AcceptBroadcast = TRUE;\r
- }\r
-\r
- //\r
- // In multicast condition when Promiscuous FALSE and IpCnt no-zero.\r
- // Here check if there is any update of the multicast ip address. If yes,\r
- // we need leave the old multicast group (by Config UDP instance to NULL),\r
- // and join the new multicast group.\r
- //\r
- if (!AcceptPromiscuous) {\r
- if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) {\r
- if (Mode->IpFilter.IpCnt != NewFilter->IpCnt) {\r
- MultiCastUpdate = TRUE;\r
- } else if (CompareMem (Mode->IpFilter.IpList, NewFilter->IpList, NewFilter->IpCnt * sizeof (EFI_IP_ADDRESS)) != 0 ) {\r
- MultiCastUpdate = TRUE;\r
- }\r
- }\r
- }\r
-\r
- //\r
- // Check whether we need reconfigure the UDP instance.\r
- //\r
- Udp4Cfg = &Private->Udp4CfgData;\r
- if ((AcceptPromiscuous != Udp4Cfg->AcceptPromiscuous) ||\r
- (AcceptBroadcast != Udp4Cfg->AcceptBroadcast) || MultiCastUpdate) {\r
- //\r
- // Clear the UDP instance configuration, all joined groups will be left\r
- // during the operation.\r
- //\r
- Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
-\r
- //\r
- // Configure the UDP instance with the new configuration.\r
- //\r
- Udp4Cfg->AcceptPromiscuous = AcceptPromiscuous;\r
- Udp4Cfg->AcceptBroadcast = AcceptBroadcast;\r
- Status = Private->Udp4Read->Configure (Private->Udp4Read, Udp4Cfg);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // In not Promiscuous mode, need to join the new multicast group.\r
- //\r
- if (!AcceptPromiscuous) {\r
- for (Index = 0; Index < NewFilter->IpCnt; ++Index) {\r
- if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter->IpList[Index].v4))) {\r
- //\r
- // Join the mutilcast group.\r
- //\r
- Status = Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &NewFilter->IpList[Index].v4);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- //\r
- // Save the new filter.\r
- //\r
- CopyMem (&Mode->IpFilter, NewFilter, sizeof (Mode->IpFilter));\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Uses the ARP protocol to resolve a MAC address.\r
-\r
- This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field\r
- of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6\r
- addresses are being used. The IP address specified by IpAddr is used to resolve\r
- a MAC address. If the ARP protocol succeeds in resolving the specified address,\r
- then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure\r
- are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved\r
- MAC address is placed there as well. If the PXE Base Code protocol is in the\r
- stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters\r
- a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is\r
- returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r
- then EFI_ABORTED is returned.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param IpAddr Pointer to the IP address that is used to resolve a MAC address.\r
- @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the\r
- ARP protocol.\r
-\r
- @retval EFI_SUCCESS The IP or MAC address was resolved.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcArp (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r
- IN EFI_IP_ADDRESS * IpAddr,\r
- IN EFI_MAC_ADDRESS * MacAddr OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_STATUS Status;\r
- EFI_MAC_ADDRESS TempMacAddr;\r
-\r
- if (This == NULL || IpAddr == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- if (!Private->AddressIsOk || Mode->UsingIpv6) {\r
- //\r
- // We can't resolve the IP address if we don't have a local address now.\r
- // Don't have ARP for IPv6.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Mode->IcmpErrorReceived = FALSE;\r
-\r
- if (!Mode->AutoArp) {\r
- //\r
- // If AutoArp is set false, check arp cache\r
- //\r
- UpdateArpCache (This);\r
- if (!FindInArpCache (Mode, &IpAddr->v4, &TempMacAddr)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- } else {\r
- Status = Private->Arp->Request (Private->Arp, &IpAddr->v4, NULL, &TempMacAddr);\r
- if (EFI_ERROR (Status)) {\r
- if (Status == EFI_ICMP_ERROR) {\r
- Mode->IcmpErrorReceived = TRUE;\r
- }\r
- return Status;\r
- }\r
- }\r
-\r
- if (MacAddr != NULL) {\r
- CopyMem (MacAddr, &TempMacAddr, sizeof (EFI_MAC_ADDRESS));\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Updates the parameters that affect the operation of the PXE Base Code Protocol.\r
-\r
- This function sets parameters that affect the operation of the PXE Base Code Protocol.\r
- The parameter specified by NewAutoArp is used to control the generation of ARP\r
- protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated\r
- as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP\r
- Protocol packets will be generated. In this case, the only mappings that are\r
- available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.\r
- If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol\r
- service, then the service will fail. This function updates the AutoArp field of\r
- the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.\r
- The SetParameters() call must be invoked after a Callback Protocol is installed\r
- to enable the use of callbacks.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the\r
- current value of AutoARP.\r
- @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the\r
- current value of SendGUID.\r
- @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,\r
- the "time to live" field of the IP header.\r
- @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,\r
- the "type of service" field of the IP header.\r
- @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the\r
- current value of the MakeCallback field of the Mode structure.\r
-\r
- @retval EFI_SUCCESS The new parameters values were updated.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcSetParameters (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r
- IN BOOLEAN *NewAutoArp OPTIONAL,\r
- IN BOOLEAN *NewSendGUID OPTIONAL,\r
- IN UINT8 *NewTTL OPTIONAL,\r
- IN UINT8 *NewToS OPTIONAL,\r
- IN BOOLEAN *NewMakeCallback // OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_STATUS Status;\r
-\r
- Status = EFI_SUCCESS;\r
-\r
- if (This == NULL) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_EXIT;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- if (NewSendGUID != NULL && *NewSendGUID) {\r
- //\r
- // FixMe, cann't locate SendGuid\r
- //\r
- }\r
-\r
- if (NewMakeCallback != NULL && *NewMakeCallback) {\r
-\r
- Status = gBS->HandleProtocol (\r
- Private->Controller,\r
- &gEfiPxeBaseCodeCallbackProtocolGuid,\r
- (VOID **) &Private->PxeBcCallback\r
- );\r
- if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {\r
-\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_EXIT;\r
- }\r
- }\r
-\r
- if (!Mode->Started) {\r
- Status = EFI_NOT_STARTED;\r
- goto ON_EXIT;\r
- }\r
-\r
- if (NewMakeCallback != NULL) {\r
-\r
- if (*NewMakeCallback) {\r
- //\r
- // Update the Callback protocol.\r
- //\r
- Status = gBS->HandleProtocol (\r
- Private->Controller,\r
- &gEfiPxeBaseCodeCallbackProtocolGuid,\r
- (VOID **) &Private->PxeBcCallback\r
- );\r
-\r
- if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_EXIT;\r
- }\r
- } else {\r
- Private->PxeBcCallback = NULL;\r
- }\r
-\r
- Mode->MakeCallbacks = *NewMakeCallback;\r
- }\r
-\r
- if (NewAutoArp != NULL) {\r
- Mode->AutoArp = *NewAutoArp;\r
- }\r
-\r
- if (NewSendGUID != NULL) {\r
- Mode->SendGUID = *NewSendGUID;\r
- }\r
-\r
- if (NewTTL != NULL) {\r
- Mode->TTL = *NewTTL;\r
- }\r
-\r
- if (NewToS != NULL) {\r
- Mode->ToS = *NewToS;\r
- }\r
-\r
-ON_EXIT:\r
- return Status;\r
-}\r
-\r
-/**\r
- Updates the station IP address and/or subnet mask values of a network device.\r
-\r
- This function updates the station IP address and/or subnet mask values of a network\r
- device. The NewStationIp field is used to modify the network device's current IP address.\r
- If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,\r
- this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure\r
- with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet\r
- mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.\r
- Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE\r
- structure with NewSubnetMask.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param NewStationIp Pointer to the new IP address to be used by the network device.\r
- @param NewSubnetMask Pointer to the new subnet mask to be used by the network device.\r
-\r
- @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcSetStationIP (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r
- IN EFI_IP_ADDRESS * NewStationIp OPTIONAL,\r
- IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_ARP_CONFIG_DATA ArpConfigData;\r
-\r
- if (This == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (NewStationIp != NULL) {\r
- if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) ||\r
- IP4_IS_LOCAL_BROADCAST(NTOHL (NewStationIp->Addr[0])) ||\r
- (NewSubnetMask != NULL && NewSubnetMask->Addr[0] != 0 && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0])))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- if (NewStationIp != NULL) {\r
- CopyMem (&Mode->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r
- CopyMem (&Private->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r
- }\r
-\r
- if (NewSubnetMask != NULL) {\r
- CopyMem (&Mode->SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r
- CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r
- }\r
-\r
- Private->AddressIsOk = TRUE;\r
-\r
- if (!Mode->UsingIpv6) {\r
- //\r
- // If in IPv4 mode, configure the corresponding ARP with this new\r
- // station IP address.\r
- //\r
- ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r
-\r
- ArpConfigData.SwAddressType = 0x0800;\r
- ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);\r
- ArpConfigData.StationAddress = &Private->StationIp.v4;\r
-\r
- Private->Arp->Configure (Private->Arp, NULL);\r
- Private->Arp->Configure (Private->Arp, &ArpConfigData);\r
-\r
- //\r
- // Update the route table.\r
- //\r
- Mode->RouteTableEntries = 1;\r
- Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];\r
- Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];\r
- Mode->RouteTable[0].GwAddr.Addr[0] = 0;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Updates the contents of the cached DHCP and Discover packets.\r
-\r
- The pointers to the new packets are used to update the contents of the cached\r
- packets in the EFI_PXE_BASE_CODE_MODE structure.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r
- @param NewDhcpDiscoverValid Pointer to a value that will replace the current\r
- DhcpDiscoverValid field.\r
- @param NewDhcpAckReceived Pointer to a value that will replace the current\r
- DhcpAckReceived field.\r
- @param NewProxyOfferReceived Pointer to a value that will replace the current\r
- ProxyOfferReceived field.\r
- @param NewPxeDiscoverValid Pointer to a value that will replace the current\r
- ProxyOfferReceived field.\r
- @param NewPxeReplyReceived Pointer to a value that will replace the current\r
- PxeReplyReceived field.\r
- @param NewPxeBisReplyReceived Pointer to a value that will replace the current\r
- PxeBisReplyReceived field.\r
- @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.\r
- @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.\r
- @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.\r
- @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.\r
- @param NewPxeReply Pointer to the new cached PXE Reply packet contents.\r
- @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.\r
-\r
- @retval EFI_SUCCESS The cached packet contents were updated.\r
- @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r
- @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeBcSetPackets (\r
- IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r
- IN BOOLEAN * NewDhcpDiscoverValid OPTIONAL,\r
- IN BOOLEAN * NewDhcpAckReceived OPTIONAL,\r
- IN BOOLEAN * NewProxyOfferReceived OPTIONAL,\r
- IN BOOLEAN * NewPxeDiscoverValid OPTIONAL,\r
- IN BOOLEAN * NewPxeReplyReceived OPTIONAL,\r
- IN BOOLEAN * NewPxeBisReplyReceived OPTIONAL,\r
- IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover OPTIONAL,\r
- IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck OPTIONAL,\r
- IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer OPTIONAL,\r
- IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover OPTIONAL,\r
- IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply OPTIONAL,\r
- IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
-\r
- if (This == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Mode = Private->PxeBc.Mode;\r
-\r
- if (!Mode->Started) {\r
- return EFI_NOT_STARTED;\r
- }\r
-\r
- if (NewDhcpDiscoverValid != NULL) {\r
- Mode->DhcpDiscoverValid = *NewDhcpDiscoverValid;\r
- }\r
-\r
- if (NewDhcpAckReceived != NULL) {\r
- Mode->DhcpAckReceived = *NewDhcpAckReceived;\r
- }\r
-\r
- if (NewProxyOfferReceived != NULL) {\r
- Mode->ProxyOfferReceived = *NewProxyOfferReceived;\r
- }\r
-\r
- if (NewPxeDiscoverValid != NULL) {\r
- Mode->PxeDiscoverValid = *NewPxeDiscoverValid;\r
- }\r
-\r
- if (NewPxeReplyReceived != NULL) {\r
- Mode->PxeReplyReceived = *NewPxeReplyReceived;\r
- }\r
-\r
- if (NewPxeBisReplyReceived != NULL) {\r
- Mode->PxeBisReplyReceived = *NewPxeBisReplyReceived;\r
- }\r
-\r
- if (NewDhcpDiscover != NULL) {\r
- CopyMem (&Mode->DhcpDiscover, NewDhcpDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));\r
- }\r
-\r
- if (NewDhcpAck != NULL) {\r
- CopyMem (&Mode->DhcpAck, NewDhcpAck, sizeof (EFI_PXE_BASE_CODE_PACKET));\r
- }\r
-\r
- if (NewProxyOffer != NULL) {\r
- CopyMem (&Mode->ProxyOffer, NewProxyOffer, sizeof (EFI_PXE_BASE_CODE_PACKET));\r
- }\r
-\r
- if (NewPxeDiscover != NULL) {\r
- CopyMem (&Mode->PxeDiscover, NewPxeDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));\r
- }\r
-\r
- if (NewPxeReply != NULL) {\r
- CopyMem (&Mode->PxeReply, NewPxeReply, sizeof (EFI_PXE_BASE_CODE_PACKET));\r
- }\r
-\r
- if (NewPxeBisReply != NULL) {\r
- CopyMem (&Mode->PxeBisReply, NewPxeBisReply, sizeof (EFI_PXE_BASE_CODE_PACKET));\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate = {\r
- EFI_PXE_BASE_CODE_PROTOCOL_REVISION,\r
- EfiPxeBcStart,\r
- EfiPxeBcStop,\r
- EfiPxeBcDhcp,\r
- EfiPxeBcDiscover,\r
- EfiPxeBcMtftp,\r
- EfiPxeBcUdpWrite,\r
- EfiPxeBcUdpRead,\r
- EfiPxeBcSetIpFilter,\r
- EfiPxeBcArp,\r
- EfiPxeBcSetParameters,\r
- EfiPxeBcSetStationIP,\r
- EfiPxeBcSetPackets,\r
- NULL\r
-};\r
-\r
-/**\r
- Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has\r
- received, or is waiting to receive a packet.\r
-\r
- This function is invoked when the PXE Base Code Protocol is about to transmit, has received,\r
- or is waiting to receive a packet. Parameters Function and Received specify the type of event.\r
- Parameters PacketLen and Packet specify the packet that generated the event. If these fields\r
- are zero and NULL respectively, then this is a status update callback. If the operation specified\r
- by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation\r
- specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to\r
- the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.\r
- The SetParameters() function must be called after a Callback Protocol is installed to enable the\r
- use of callbacks.\r
-\r
- @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.\r
- @param Function The PXE Base Code Protocol function that is waiting for an event.\r
- @param Received TRUE if the callback is being invoked due to a receive event. FALSE if\r
- the callback is being invoked due to a transmit event.\r
- @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if\r
- this is a wait for receive event.\r
- @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;\r
- otherwise a pointer to the packet that is about to be transmitted.\r
-\r
- @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation\r
- @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation\r
-\r
-**/\r
-EFI_PXE_BASE_CODE_CALLBACK_STATUS\r
-EFIAPI\r
-EfiPxeLoadFileCallback (\r
- IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL * This,\r
- IN EFI_PXE_BASE_CODE_FUNCTION Function,\r
- IN BOOLEAN Received,\r
- IN UINT32 PacketLength,\r
- IN EFI_PXE_BASE_CODE_PACKET * PacketPtr OPTIONAL\r
- )\r
-{\r
- EFI_INPUT_KEY Key;\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Catch Ctrl-C or ESC to abort.\r
- //\r
- Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-\r
- if (!EFI_ERROR (Status)) {\r
-\r
- if (Key.ScanCode == SCAN_ESC || Key.UnicodeChar == (0x1F & 'c')) {\r
-\r
- return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT;\r
- }\r
- }\r
- //\r
- // No print if receive packet\r
- //\r
- if (Received) {\r
- return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r
- }\r
- //\r
- // Print only for three functions\r
- //\r
- switch (Function) {\r
-\r
- case EFI_PXE_BASE_CODE_FUNCTION_MTFTP:\r
- //\r
- // Print only for open MTFTP packets, not every MTFTP packets\r
- //\r
- if (PacketLength != 0 && PacketPtr != NULL) {\r
- if (PacketPtr->Raw[0x1C] != 0x00 || PacketPtr->Raw[0x1D] != 0x01) {\r
- return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r
- }\r
- }\r
- break;\r
-\r
- case EFI_PXE_BASE_CODE_FUNCTION_DHCP:\r
- case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER:\r
- break;\r
-\r
- default:\r
- return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r
- }\r
-\r
- if (PacketLength != 0 && PacketPtr != NULL) {\r
- //\r
- // Print '.' when transmit a packet\r
- //\r
- AsciiPrint (".");\r
-\r
- }\r
-\r
- return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r
-}\r
-\r
-EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate = {\r
- EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION,\r
- EfiPxeLoadFileCallback\r
-};\r
-\r
-\r
-/**\r
- Find the boot file.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param BufferSize Pointer to buffer size.\r
- @param Buffer Pointer to buffer.\r
-\r
- @retval EFI_SUCCESS Discover the boot file successfully.\r
- @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.\r
- @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.\r
- @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.\r
-\r
-**/\r
-EFI_STATUS\r
-DiscoverBootFile (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN OUT UINT64 *BufferSize,\r
- IN VOID *Buffer\r
- )\r
-{\r
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_STATUS Status;\r
- UINT16 Type;\r
- UINT16 Layer;\r
- BOOLEAN UseBis;\r
- PXEBC_CACHED_DHCP4_PACKET *Packet;\r
- UINT16 Value;\r
-\r
- PxeBc = &Private->PxeBc;\r
- Mode = PxeBc->Mode;\r
- Type = EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP;\r
- Layer = EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL;\r
-\r
- //\r
- // do DHCP.\r
- //\r
- Status = PxeBc->Dhcp (PxeBc, TRUE);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Select a boot server\r
- //\r
- Status = PxeBcSelectBootPrompt (Private);\r
-\r
- if (Status == EFI_SUCCESS) {\r
- Status = PxeBcSelectBootMenu (Private, &Type, TRUE);\r
- } else if (Status == EFI_TIMEOUT) {\r
- Status = PxeBcSelectBootMenu (Private, &Type, FALSE);\r
- }\r
-\r
- if (!EFI_ERROR (Status)) {\r
-\r
- if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {\r
- //\r
- // Local boot(PXE bootstrap server) need abort\r
- //\r
- return EFI_ABORTED;\r
- }\r
-\r
- UseBis = (BOOLEAN) (Mode->BisSupported && Mode->BisDetected);\r
- Status = PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- *BufferSize = 0;\r
-\r
- //\r
- // Get bootfile name and (m)tftp server ip addresss\r
- //\r
- if (Mode->PxeReplyReceived) {\r
- Packet = &Private->PxeReply;\r
- } else if (Mode->ProxyOfferReceived) {\r
- Packet = &Private->ProxyOffer;\r
- } else {\r
- Packet = &Private->Dhcp4Ack;\r
- }\r
-\r
- //\r
- // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)\r
- // in DHCPOFFER packet.\r
- // (It does not comply with PXE Spec, Ver2.1)\r
- //\r
- if (EFI_IP4_EQUAL (&Packet->Packet.Offer.Dhcp4.Header.ServerAddr, &mZeroIp4Addr)) {\r
- CopyMem (\r
- &Private->ServerIp,\r
- Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- } else {\r
- CopyMem (\r
- &Private->ServerIp,\r
- &Packet->Packet.Offer.Dhcp4.Header.ServerAddr,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- }\r
- if (Private->ServerIp.Addr[0] == 0) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- ASSERT (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);\r
-\r
- //\r
- // bootlfile name\r
- //\r
- Private->BootFileName = (CHAR8 *) (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data);\r
-\r
- if (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN] != NULL) {\r
- //\r
- // Already have the bootfile length option, compute the file size\r
- //\r
- CopyMem (&Value, Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN]->Data, sizeof (Value));\r
- Value = NTOHS (Value);\r
- *BufferSize = 512 * Value;\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- } else {\r
- //\r
- // Get the bootfile size from tftp\r
- //\r
- Status = PxeBc->Mtftp (\r
- PxeBc,\r
- EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r
- Buffer,\r
- FALSE,\r
- BufferSize,\r
- &Private->BlockSize,\r
- &Private->ServerIp,\r
- (UINT8 *) Private->BootFileName,\r
- NULL,\r
- FALSE\r
- );\r
- }\r
-\r
- Private->FileSize = (UINTN) *BufferSize;\r
-\r
- //\r
- // Display all the information: boot server address, boot file name and boot file size.\r
- //\r
- AsciiPrint ("\n Server IP address is ");\r
- PxeBcShowIp4Addr (&Private->ServerIp.v4);\r
- AsciiPrint ("\n NBP filename is %a", Private->BootFileName);\r
- AsciiPrint ("\n NBP filesize is %d Bytes", Private->FileSize);\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Causes the driver to load a specified file.\r
-\r
- @param This Protocol instance pointer.\r
- @param FilePath The device specific path of the file to load.\r
- @param BootPolicy If TRUE, indicates that the request originates from the\r
- boot manager is attempting to load FilePath as a boot\r
- selection. If FALSE, then FilePath must match as exact file\r
- to be loaded.\r
- @param BufferSize On input the size of Buffer in bytes. On output with a return\r
- code of EFI_SUCCESS, the amount of data transferred to\r
- Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,\r
- the size of Buffer required to retrieve the requested file.\r
- @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,\r
- then no the size of the requested file is returned in\r
- BufferSize.\r
-\r
- @retval EFI_SUCCESS The file was loaded.\r
- @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy\r
- @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or\r
- BufferSize is NULL.\r
- @retval EFI_NO_MEDIA No medium was present to load the file.\r
- @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.\r
- @retval EFI_NO_RESPONSE The remote system did not respond.\r
- @retval EFI_NOT_FOUND The file was not found.\r
- @retval EFI_ABORTED The file load process was manually cancelled.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiPxeLoadFile (\r
- IN EFI_LOAD_FILE_PROTOCOL * This,\r
- IN EFI_DEVICE_PATH_PROTOCOL * FilePath,\r
- IN BOOLEAN BootPolicy,\r
- IN OUT UINTN *BufferSize,\r
- IN VOID *Buffer OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
- BOOLEAN NewMakeCallback;\r
- EFI_STATUS Status;\r
- UINT64 TmpBufSize;\r
- EFI_STATUS MediaStatus;\r
-\r
- if (FilePath == NULL || !IsDevicePathEnd (FilePath)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_LOADFILE (This);\r
- PxeBc = &Private->PxeBc;\r
- NewMakeCallback = FALSE;\r
- Status = EFI_DEVICE_ERROR;\r
-\r
- if (This == NULL || BufferSize == NULL) {\r
-\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // Only support BootPolicy\r
- //\r
- if (!BootPolicy) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- //\r
- // Check media status before PXE start\r
- //\r
- MediaStatus = EFI_SUCCESS;\r
- NetLibDetectMediaWaitTimeout (Private->Controller, PXEBC_CHECK_MEDIA_WAITING_TIME, &MediaStatus);\r
- if (MediaStatus != EFI_SUCCESS) {\r
- return EFI_NO_MEDIA;\r
- }\r
-\r
- Status = PxeBc->Start (PxeBc, FALSE);\r
- if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
- return Status;\r
- }\r
-\r
- Status = gBS->HandleProtocol (\r
- Private->Controller,\r
- &gEfiPxeBaseCodeCallbackProtocolGuid,\r
- (VOID **) &Private->PxeBcCallback\r
- );\r
- if (Status == EFI_UNSUPPORTED) {\r
-\r
- CopyMem (&Private->LoadFileCallback, &mPxeBcCallBackTemplate, sizeof (Private->LoadFileCallback));\r
-\r
- Status = gBS->InstallProtocolInterface (\r
- &Private->Controller,\r
- &gEfiPxeBaseCodeCallbackProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- &Private->LoadFileCallback\r
- );\r
-\r
- NewMakeCallback = (BOOLEAN) (Status == EFI_SUCCESS);\r
-\r
- Status = PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);\r
- if (EFI_ERROR (Status)) {\r
- PxeBc->Stop (PxeBc);\r
- return Status;\r
- }\r
- }\r
-\r
- if (Private->FileSize == 0) {\r
- TmpBufSize = 0;\r
- Status = DiscoverBootFile (Private, &TmpBufSize, Buffer);\r
-\r
- if (sizeof (UINTN) < sizeof (UINT64) && (TmpBufSize > 0xFFFFFFFF)) {\r
- Status = EFI_DEVICE_ERROR;\r
- } else if (TmpBufSize > 0 && *BufferSize >= (UINTN) TmpBufSize && Buffer != NULL) {\r
- AsciiPrint ("\n Downloading NBP file...\n");\r
- *BufferSize = (UINTN) TmpBufSize;\r
- Status = PxeBc->Mtftp (\r
- PxeBc,\r
- EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
- Buffer,\r
- FALSE,\r
- &TmpBufSize,\r
- &Private->BlockSize,\r
- &Private->ServerIp,\r
- (UINT8 *) Private->BootFileName,\r
- NULL,\r
- FALSE\r
- );\r
- } else if (TmpBufSize > 0) {\r
- *BufferSize = (UINTN) TmpBufSize;\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- }\r
- } else if (Buffer == NULL || Private->FileSize > *BufferSize) {\r
- *BufferSize = Private->FileSize;\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- } else {\r
- //\r
- // Download the file.\r
- //\r
- AsciiPrint ("\n Downloading NBP file...\n");\r
- TmpBufSize = (UINT64) (*BufferSize);\r
- Status = PxeBc->Mtftp (\r
- PxeBc,\r
- EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
- Buffer,\r
- FALSE,\r
- &TmpBufSize,\r
- &Private->BlockSize,\r
- &Private->ServerIp,\r
- (UINT8 *) Private->BootFileName,\r
- NULL,\r
- FALSE\r
- );\r
- }\r
- //\r
- // If we added a callback protocol, now is the time to remove it.\r
- //\r
- if (NewMakeCallback) {\r
-\r
- NewMakeCallback = FALSE;\r
-\r
- PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);\r
-\r
- gBS->UninstallProtocolInterface (\r
- Private->Controller,\r
- &gEfiPxeBaseCodeCallbackProtocolGuid,\r
- &Private->LoadFileCallback\r
- );\r
- }\r
-\r
- //\r
- // Check download status\r
- //\r
- if (Status == EFI_SUCCESS) {\r
- AsciiPrint ("\n NBP file downloaded successfully.\n");\r
- //\r
- // The DHCP4 can have only one configured child instance so we need to stop\r
- // reset the DHCP4 child before we return. Otherwise the other programs which\r
- // also need to use DHCP4 will be impacted.\r
- // The functionality of PXE Base Code protocol will not be stopped,\r
- // when downloading is successfully.\r
- //\r
- Private->Dhcp4->Stop (Private->Dhcp4);\r
- Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r
- return EFI_SUCCESS;\r
-\r
- } else if (Status == EFI_BUFFER_TOO_SMALL) {\r
- if (Buffer != NULL) {\r
- AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");\r
- } else {\r
- //\r
- // The functionality of PXE Base Code protocol will not be stopped.\r
- //\r
- return Status;\r
- }\r
-\r
- } else if (Status == EFI_DEVICE_ERROR) {\r
- AsciiPrint ("PXE-E07: Network device error.\n");\r
-\r
- } else if (Status == EFI_OUT_OF_RESOURCES) {\r
- AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");\r
-\r
- } else if (Status == EFI_NO_MEDIA) {\r
- AsciiPrint ("PXE-E12: Could not detect network connection.\n");\r
-\r
- } else if (Status == EFI_NO_RESPONSE) {\r
- AsciiPrint ("PXE-E16: No offer received.\n");\r
-\r
- } else if (Status == EFI_TIMEOUT) {\r
- AsciiPrint ("PXE-E18: Server response timeout.\n");\r
-\r
- } else if (Status == EFI_ABORTED) {\r
- AsciiPrint ("PXE-E21: Remote boot cancelled.\n");\r
-\r
- } else if (Status == EFI_ICMP_ERROR) {\r
- AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");\r
-\r
- } else if (Status == EFI_TFTP_ERROR) {\r
- AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");\r
-\r
- } else {\r
- AsciiPrint ("PXE-E99: Unexpected network error.\n");\r
- }\r
-\r
- PxeBc->Stop (PxeBc);\r
-\r
- return Status;\r
-}\r
-\r
-EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate = { EfiPxeLoadFile };\r
-\r