MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf\r
\r
[Components.IA32, Components.X64, Components.AARCH64]\r
- MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf\r
MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf\r
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf\r
+++ /dev/null
-/** @file\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
-//\r
-// EFI Component Name Functions\r
-//\r
-/**\r
- Retrieves a Unicode string that is the user readable name of the driver.\r
-\r
- This function retrieves the user readable name of a driver in the form of a\r
- Unicode string. If the driver specified by This has a user readable name in\r
- the language specified by Language, then a pointer to the driver name is\r
- returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
- by This does not support the language specified by Language,\r
- then EFI_UNSUPPORTED is returned.\r
-\r
- @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
- EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
- @param[in] Language A pointer to a Null-terminated ASCII string\r
- array indicating the language. This is the\r
- language of the driver name that the caller is\r
- requesting, and it must match one of the\r
- languages specified in SupportedLanguages. The\r
- number of languages supported by a driver is up\r
- to the driver writer. Language is specified\r
- in RFC 4646 or ISO 639-2 language code format.\r
-\r
- @param[out] DriverName A pointer to the Unicode string to return.\r
- This Unicode string is the name of the\r
- driver specified by This in the language\r
- specified by Language.\r
-\r
- @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
- This and the language specified by Language was\r
- returned in DriverName.\r
-\r
- @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
- @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
-\r
- @retval EFI_UNSUPPORTED The driver specified by This does not support\r
- the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcComponentNameGetDriverName (\r
- IN EFI_COMPONENT_NAME_PROTOCOL * This,\r
- IN CHAR8 *Language,\r
- OUT CHAR16 **DriverName\r
- );\r
-\r
-/**\r
- Retrieves a Unicode string that is the user readable name of the controller\r
- that is being managed by a driver.\r
-\r
- This function retrieves the user readable name of the controller specified by\r
- ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
- driver specified by This has a user readable name in the language specified by\r
- Language, then a pointer to the controller name is returned in ControllerName,\r
- and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
- managing the controller specified by ControllerHandle and ChildHandle,\r
- then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
- support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
-\r
- @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
- EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
- @param[in] ControllerHandle The handle of a controller that the driver\r
- specified by This is managing. This handle\r
- specifies the controller whose name is to be\r
- returned.\r
-\r
- @param[in] ChildHandle The handle of the child controller to retrieve\r
- the name of. This is an optional parameter that\r
- may be NULL. It will be NULL for device\r
- drivers. It will also be NULL for a bus drivers\r
- that wish to retrieve the name of the bus\r
- controller. It will not be NULL for a bus\r
- driver that wishes to retrieve the name of a\r
- child controller.\r
-\r
- @param[in] Language A pointer to a Null-terminated ASCII string\r
- array indicating the language. This is the\r
- language of the driver name that the caller is\r
- requesting, and it must match one of the\r
- languages specified in SupportedLanguages. The\r
- number of languages supported by a driver is up\r
- to the driver writer. Language is specified in\r
- RFC 4646 or ISO 639-2 language code format.\r
-\r
- @param[out] ControllerName A pointer to the Unicode string to return.\r
- This Unicode string is the name of the\r
- controller specified by ControllerHandle and\r
- ChildHandle in the language specified by\r
- Language from the point of view of the driver\r
- specified by This.\r
-\r
- @retval EFI_SUCCESS The Unicode string for the user readable name in\r
- the language specified by Language for the\r
- driver specified by This was returned in\r
- DriverName.\r
-\r
- @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
-\r
- @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
- EFI_HANDLE.\r
-\r
- @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
- @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
-\r
- @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
- managing the controller specified by\r
- ControllerHandle and ChildHandle.\r
-\r
- @retval EFI_UNSUPPORTED The driver specified by This does not support\r
- the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcComponentNameGetControllerName (\r
- IN EFI_COMPONENT_NAME_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_HANDLE ChildHandle OPTIONAL,\r
- IN CHAR8 *Language,\r
- OUT CHAR16 **ControllerName\r
- );\r
-\r
-//\r
-// EFI Component Name Protocol\r
-//\r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName = {\r
- PxeBcComponentNameGetDriverName,\r
- PxeBcComponentNameGetControllerName,\r
- "eng"\r
-};\r
-\r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPxeBcComponentName2 = {\r
- (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) PxeBcComponentNameGetDriverName,\r
- (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) PxeBcComponentNameGetControllerName,\r
- "en"\r
-};\r
-\r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPxeBcDriverNameTable[] = {\r
- {\r
- "eng;en",\r
- L"UEFI PXE Base Code Driver"\r
- },\r
- {\r
- NULL,\r
- NULL\r
- }\r
-};\r
-\r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPxeBcControllerNameTable[] = {\r
- {\r
- "eng;en",\r
- L"PXE Controller"\r
- },\r
- {\r
- NULL,\r
- NULL\r
- }\r
-};\r
-\r
-/**\r
- Retrieves a Unicode string that is the user readable name of the driver.\r
-\r
- This function retrieves the user readable name of a driver in the form of a\r
- Unicode string. If the driver specified by This has a user readable name in\r
- the language specified by Language, then a pointer to the driver name is\r
- returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
- by This does not support the language specified by Language,\r
- then EFI_UNSUPPORTED is returned.\r
-\r
- @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
- EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
- @param[in] Language A pointer to a Null-terminated ASCII string\r
- array indicating the language. This is the\r
- language of the driver name that the caller is\r
- requesting, and it must match one of the\r
- languages specified in SupportedLanguages. The\r
- number of languages supported by a driver is up\r
- to the driver writer. Language is specified\r
- in RFC 4646 or ISO 639-2 language code format.\r
-\r
- @param[out] DriverName A pointer to the Unicode string to return.\r
- This Unicode string is the name of the\r
- driver specified by This in the language\r
- specified by Language.\r
-\r
- @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
- This and the language specified by Language was\r
- returned in DriverName.\r
-\r
- @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
- @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
-\r
- @retval EFI_UNSUPPORTED The driver specified by This does not support\r
- the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcComponentNameGetDriverName (\r
- IN EFI_COMPONENT_NAME_PROTOCOL * This,\r
- IN CHAR8 *Language,\r
- OUT CHAR16 **DriverName\r
- )\r
-{\r
- return LookupUnicodeString2 (\r
- Language,\r
- This->SupportedLanguages,\r
- mPxeBcDriverNameTable,\r
- DriverName,\r
- (BOOLEAN)(This == &gPxeBcComponentName)\r
- );\r
-}\r
-\r
-/**\r
- Retrieves a Unicode string that is the user readable name of the controller\r
- that is being managed by a driver.\r
-\r
- This function retrieves the user readable name of the controller specified by\r
- ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
- driver specified by This has a user readable name in the language specified by\r
- Language, then a pointer to the controller name is returned in ControllerName,\r
- and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
- managing the controller specified by ControllerHandle and ChildHandle,\r
- then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
- support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
-\r
- @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
- EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
- @param[in] ControllerHandle The handle of a controller that the driver\r
- specified by This is managing. This handle\r
- specifies the controller whose name is to be\r
- returned.\r
-\r
- @param[in] ChildHandle The handle of the child controller to retrieve\r
- the name of. This is an optional parameter that\r
- may be NULL. It will be NULL for device\r
- drivers. It will also be NULL for a bus drivers\r
- that wish to retrieve the name of the bus\r
- controller. It will not be NULL for a bus\r
- driver that wishes to retrieve the name of a\r
- child controller.\r
-\r
- @param[in] Language A pointer to a Null-terminated ASCII string\r
- array indicating the language. This is the\r
- language of the driver name that the caller is\r
- requesting, and it must match one of the\r
- languages specified in SupportedLanguages. The\r
- number of languages supported by a driver is up\r
- to the driver writer. Language is specified in\r
- RFC 4646 or ISO 639-2 language code format.\r
-\r
- @param[out] ControllerName A pointer to the Unicode string to return.\r
- This Unicode string is the name of the\r
- controller specified by ControllerHandle and\r
- ChildHandle in the language specified by\r
- Language from the point of view of the driver\r
- specified by This.\r
-\r
- @retval EFI_SUCCESS The Unicode string for the user readable name in\r
- the language specified by Language for the\r
- driver specified by This was returned in\r
- DriverName.\r
-\r
- @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
-\r
- @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
- EFI_HANDLE.\r
-\r
- @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
- @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
-\r
- @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
- managing the controller specified by\r
- ControllerHandle and ChildHandle.\r
-\r
- @retval EFI_UNSUPPORTED The driver specified by This does not support\r
- the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcComponentNameGetControllerName (\r
- IN EFI_COMPONENT_NAME_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_HANDLE ChildHandle OPTIONAL,\r
- IN CHAR8 *Language,\r
- OUT CHAR16 **ControllerName\r
- )\r
-{\r
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
- EFI_HANDLE NicHandle;\r
- EFI_STATUS Status;\r
-\r
- if (ControllerHandle == NULL || ChildHandle != NULL) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiArpProtocolGuid);\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiMtftp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- NicHandle,\r
- &gEfiPxeBaseCodeProtocolGuid,\r
- (VOID **) &PxeBc,\r
- NULL,\r
- NULL,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- return LookupUnicodeString2 (\r
- Language,\r
- This->SupportedLanguages,\r
- mPxeBcControllerNameTable,\r
- ControllerName,\r
- (BOOLEAN)(This == &gPxeBcComponentName)\r
- );\r
-}\r
+++ /dev/null
-/** @file\r
- Support for PxeBc dhcp functions.\r
-\r
-Copyright (c) 2013, Red Hat, Inc.\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
-//\r
-// This is a map from the interested DHCP4 option tags' index to the tag value.\r
-//\r
-UINT8 mInterestedDhcp4Tags[PXEBC_DHCP4_TAG_INDEX_MAX] = {\r
- DHCP4_TAG_BOOTFILE_LEN,\r
- DHCP4_TAG_VENDOR,\r
- DHCP4_TAG_OVERLOAD,\r
- DHCP4_TAG_MSG_TYPE,\r
- DHCP4_TAG_SERVER_ID,\r
- DHCP4_TAG_VENDOR_CLASS_ID,\r
- DHCP4_TAG_BOOTFILE\r
-};\r
-\r
-\r
-/**\r
- This function initialize the DHCP4 message instance.\r
-\r
- This function will pad each item of dhcp4 message packet.\r
-\r
- @param Seed Pointer to the message instance of the DHCP4 packet.\r
- @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.\r
-\r
-**/\r
-VOID\r
-PxeBcInitSeedPacket (\r
- IN EFI_DHCP4_PACKET *Seed,\r
- IN EFI_UDP4_PROTOCOL *Udp4\r
- )\r
-{\r
- EFI_SIMPLE_NETWORK_MODE Mode;\r
- EFI_DHCP4_HEADER *Header;\r
-\r
- Udp4->GetModeData (Udp4, NULL, NULL, NULL, &Mode);\r
-\r
- Seed->Size = sizeof (EFI_DHCP4_PACKET);\r
- Seed->Length = sizeof (Seed->Dhcp4);\r
-\r
- Header = &Seed->Dhcp4.Header;\r
-\r
- ZeroMem (Header, sizeof (EFI_DHCP4_HEADER));\r
- Header->OpCode = PXEBC_DHCP4_OPCODE_REQUEST;\r
- Header->HwType = Mode.IfType;\r
- Header->HwAddrLen = (UINT8) Mode.HwAddressSize;\r
- CopyMem (Header->ClientHwAddr, &Mode.CurrentAddress, Header->HwAddrLen);\r
-\r
- Seed->Dhcp4.Magik = PXEBC_DHCP4_MAGIC;\r
- Seed->Dhcp4.Option[0] = DHCP4_TAG_EOP;\r
-}\r
-\r
-\r
-/**\r
- Copy the DCHP4 packet from srouce to destination.\r
-\r
- @param[in] Dst Pointer to the cache buffer for DHCPv4 packet.\r
- @param[in] Src Pointer to the DHCPv4 packet to be cached.\r
-\r
- @retval EFI_SUCCESS Packet is copied.\r
- @retval EFI_BUFFER_TOO_SMALL Cache buffer is not big enough to hold the packet.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcCopyEfiDhcp4Packet (\r
- IN EFI_DHCP4_PACKET *Dst,\r
- IN EFI_DHCP4_PACKET *Src\r
- )\r
-{\r
- if (Dst->Size < Src->Length) {\r
- return EFI_BUFFER_TOO_SMALL;\r
- }\r
-\r
- CopyMem (&Dst->Dhcp4, &Src->Dhcp4, Src->Length);\r
- Dst->Length = Src->Length;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Copy the dhcp4 packet to the PxeBc private data and parse the dhcp4 packet.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param OfferIndex Index of cached packets as complements of pxe mode data,\r
- the index is maximum offer number.\r
-\r
- @retval EFI_SUCCESS Cache and parse the packet successfully.\r
- @retval EFI_BUFFER_TOO_SMALL Cache buffer is not big enough to hold the packet.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcCopyProxyOffer (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN UINT32 OfferIndex\r
- )\r
-{\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_DHCP4_PACKET *Offer;\r
- EFI_STATUS Status;\r
-\r
- ASSERT (OfferIndex < Private->NumOffers);\r
- ASSERT (OfferIndex < PXEBC_MAX_OFFER_NUM);\r
-\r
- Mode = Private->PxeBc.Mode;\r
- Offer = &Private->Dhcp4Offers[OfferIndex].Packet.Offer;\r
-\r
- Status = PxeBcCopyEfiDhcp4Packet (&Private->ProxyOffer.Packet.Offer, Offer);\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
- CopyMem (&Mode->ProxyOffer, &Offer->Dhcp4, Offer->Length);\r
- Mode->ProxyOfferReceived = TRUE;\r
-\r
- PxeBcParseCachedDhcpPacket (&Private->ProxyOffer);\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Parse the cached dhcp packet.\r
-\r
- @param CachedPacket Pointer to cached dhcp packet.\r
-\r
- @retval TRUE Succeed to parse and validation.\r
- @retval FALSE Fail to parse or validation.\r
-\r
-**/\r
-BOOLEAN\r
-PxeBcParseCachedDhcpPacket (\r
- IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket\r
- )\r
-{\r
- EFI_DHCP4_PACKET *Offer;\r
- EFI_DHCP4_PACKET_OPTION **Options;\r
- EFI_DHCP4_PACKET_OPTION *Option;\r
- UINT8 OfferType;\r
- UINTN Index;\r
- UINT8 *Ptr8;\r
-\r
- CachedPacket->IsPxeOffer = FALSE;\r
- ZeroMem (CachedPacket->Dhcp4Option, sizeof (CachedPacket->Dhcp4Option));\r
- ZeroMem (&CachedPacket->PxeVendorOption, sizeof (CachedPacket->PxeVendorOption));\r
-\r
- Offer = &CachedPacket->Packet.Offer;\r
- Options = CachedPacket->Dhcp4Option;\r
-\r
- //\r
- // Parse interested dhcp options and store their pointers in CachedPacket->Dhcp4Option.\r
- // First, try to parse DHCPv4 options from the DHCP optional parameters field.\r
- //\r
- for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) {\r
- Options[Index] = PxeBcParseExtendOptions (\r
- Offer->Dhcp4.Option,\r
- GET_OPTION_BUFFER_LEN (Offer),\r
- mInterestedDhcp4Tags[Index]\r
- );\r
- }\r
- //\r
- // Second, Check if bootfilename and serverhostname is overloaded to carry DHCP options refers to rfc-2132.\r
- // If yes, try to parse options from the BootFileName field, then ServerName field.\r
- //\r
- Option = Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD];\r
- if (Option != NULL) {\r
- if ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE) != 0) {\r
- for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) {\r
- if (Options[Index] == NULL) {\r
- Options[Index] = PxeBcParseExtendOptions (\r
- (UINT8 *) Offer->Dhcp4.Header.BootFileName,\r
- sizeof (Offer->Dhcp4.Header.BootFileName),\r
- mInterestedDhcp4Tags[Index]\r
- );\r
- }\r
- }\r
- }\r
- if ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_SERVER_NAME) != 0) {\r
- for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) {\r
- if (Options[Index] == NULL) {\r
- Options[Index] = PxeBcParseExtendOptions (\r
- (UINT8 *) Offer->Dhcp4.Header.ServerName,\r
- sizeof (Offer->Dhcp4.Header.ServerName),\r
- mInterestedDhcp4Tags[Index]\r
- );\r
- }\r
- }\r
- }\r
- }\r
-\r
- //\r
- // Check whether is an offer with PXEClient or not.\r
- //\r
- Option = Options[PXEBC_DHCP4_TAG_INDEX_CLASS_ID];\r
- if ((Option != NULL) && (Option->Length >= 9) &&\r
- (CompareMem (Option->Data, DEFAULT_CLASS_ID_DATA, 9) == 0)) {\r
-\r
- CachedPacket->IsPxeOffer = TRUE;\r
- }\r
-\r
- //\r
- // Parse pxe vendor options and store their content/pointers in CachedPacket->PxeVendorOption.\r
- //\r
- Option = Options[PXEBC_DHCP4_TAG_INDEX_VENDOR];\r
- if (CachedPacket->IsPxeOffer && (Option != NULL)) {\r
-\r
- if (!PxeBcParseVendorOptions (Option, &CachedPacket->PxeVendorOption)) {\r
- return FALSE;\r
- }\r
- }\r
-\r
-\r
- //\r
- // Parse PXE boot file name:\r
- // According to PXE spec, boot file name should be read from DHCP option 67 (bootfile name) if present.\r
- // Otherwise, read from boot file field in DHCP header.\r
- //\r
- if (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {\r
- //\r
- // RFC 2132, Section 9.5 does not strictly state Bootfile name (option 67) is null\r
- // terminated string. So force to append null terminated character at the end of string.\r
- //\r
- Ptr8 = (UINT8*)&Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data[0];\r
- Ptr8 += Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Length;\r
- if (*(Ptr8 - 1) != '\0') {\r
- *Ptr8 = '\0';\r
- }\r
- } else if (Offer->Dhcp4.Header.BootFileName[0] != 0) {\r
- //\r
- // If the bootfile is not present and bootfilename is present in dhcp packet, just parse it.\r
- // And do not count dhcp option header, or else will destroy the serverhostname.\r
- //\r
- // Make sure "BootFileName" is not overloaded.\r
- //\r
- if (Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD] == NULL ||\r
- (Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD]->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE) == 0) {\r
- Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] -\r
- OFFSET_OF (EFI_DHCP4_PACKET_OPTION, Data[0]));\r
- }\r
- }\r
-\r
- //\r
- // Determine offer type of the dhcp packet.\r
- //\r
- Option = Options[PXEBC_DHCP4_TAG_INDEX_MSG_TYPE];\r
- if ((Option == NULL) || (Option->Data[0] == 0)) {\r
- //\r
- // It's a bootp offer\r
- //\r
- Option = CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE];\r
- if (Option == NULL) {\r
- //\r
- // bootp offer without bootfilename, discard it.\r
- //\r
- return FALSE;\r
- }\r
-\r
- OfferType = DHCP4_PACKET_TYPE_BOOTP;\r
-\r
- } else {\r
-\r
- if (IS_VALID_DISCOVER_VENDOR_OPTION (CachedPacket->PxeVendorOption.BitMap)) {\r
- //\r
- // It's a pxe10 offer with PXEClient and discover vendor option.\r
- //\r
- OfferType = DHCP4_PACKET_TYPE_PXE10;\r
- } else if (IS_VALID_MTFTP_VENDOR_OPTION (CachedPacket->PxeVendorOption.BitMap)) {\r
- //\r
- // It's a wfm11a offer with PXEClient and mtftp vendor option, and\r
- // return false since mtftp not supported currently.\r
- //\r
- return FALSE;\r
- } else {\r
- //\r
- // If the binl offer with only PXEClient.\r
- //\r
- OfferType = (UINT8) ((CachedPacket->IsPxeOffer) ? DHCP4_PACKET_TYPE_BINL : DHCP4_PACKET_TYPE_DHCP_ONLY);\r
- }\r
- }\r
-\r
- CachedPacket->OfferType = OfferType;\r
-\r
- return TRUE;\r
-}\r
-\r
-\r
-/**\r
- Offer dhcp service with a BINL dhcp offer.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param Index Index of cached packets as complements of pxe mode data,\r
- the index is maximum offer number.\r
-\r
- @retval TRUE Offer the service successfully under priority BINL.\r
- @retval FALSE Boot Service failed, parse cached dhcp packet failed or this\r
- BINL ack cannot find options set or bootfile name specified.\r
-\r
-**/\r
-BOOLEAN\r
-PxeBcTryBinl (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN UINT32 Index\r
- )\r
-{\r
- EFI_DHCP4_PACKET *Offer;\r
- EFI_IP_ADDRESS ServerIp;\r
- EFI_STATUS Status;\r
- PXEBC_CACHED_DHCP4_PACKET *CachedPacket;\r
- EFI_DHCP4_PACKET *Reply;\r
-\r
- ASSERT (Index < PXEBC_MAX_OFFER_NUM);\r
- ASSERT (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL);\r
-\r
- Offer = &Private->Dhcp4Offers[Index].Packet.Offer;\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 (&Offer->Dhcp4.Header.ServerAddr.Addr, &mZeroIp4Addr)) {\r
- CopyMem (\r
- &ServerIp.Addr[0],\r
- Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- } else {\r
- CopyMem (\r
- &ServerIp.Addr[0],\r
- &Offer->Dhcp4.Header.ServerAddr,\r
- sizeof (EFI_IPv4_ADDRESS)\r
- );\r
- }\r
- if (ServerIp.Addr[0] == 0) {\r
- return FALSE;\r
- }\r
-\r
- CachedPacket = &Private->ProxyOffer;\r
- Reply = &CachedPacket->Packet.Offer;\r
-\r
- Status = PxeBcDiscvBootService (\r
- Private,\r
- 0,\r
- NULL,\r
- FALSE,\r
- &ServerIp,\r
- 0,\r
- NULL,\r
- FALSE,\r
- Reply\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return FALSE;\r
- }\r
-\r
- if (!PxeBcParseCachedDhcpPacket (CachedPacket)) {\r
- return FALSE;\r
- }\r
-\r
- if ((CachedPacket->OfferType != DHCP4_PACKET_TYPE_PXE10) &&\r
- (CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL)) {\r
- //\r
- // This BINL ack doesn't have discovery options set or bootfile name\r
- // specified.\r
- //\r
- return FALSE;\r
- }\r
-\r
- Private->PxeBc.Mode->ProxyOfferReceived = TRUE;\r
- CopyMem (&Private->PxeBc.Mode->ProxyOffer, &Reply->Dhcp4, Reply->Length);\r
-\r
- return TRUE;\r
-}\r
-\r
-\r
-/**\r
- Offer dhcp service for each proxy with a BINL dhcp offer.\r
-\r
- @param Private Pointer to PxeBc private data\r
- @param OfferIndex Pointer to the index of cached packets as complements of\r
- pxe mode data, the index is maximum offer number.\r
-\r
- @return If there is no service needed offer return FALSE, otherwise TRUE.\r
-\r
-**/\r
-BOOLEAN\r
-PxeBcTryBinlProxy (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- OUT UINT32 *OfferIndex\r
- )\r
-{\r
- UINT32 Index;\r
-\r
- for (Index = 0; Index < Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]; Index++) {\r
-\r
- *OfferIndex = Private->BinlIndex[Index];\r
- //\r
- // Try this BINL proxy offer\r
- //\r
- if (PxeBcTryBinl (Private, *OfferIndex)) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-\r
-/**\r
- This function is to check the selected proxy offer (include BINL dhcp offer and\r
- DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe base code\r
- mode structure.\r
-\r
- @param Private Pointer to PxeBc private data.\r
-\r
- @retval EFI_SUCCESS Operational successful.\r
- @retval EFI_NO_RESPONSE Offer dhcp service failed.\r
- @retval EFI_BUFFER_TOO_SMALL Failed to copy the packet to Pxe base code mode.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcCheckSelectedOffer (\r
- IN PXEBC_PRIVATE_DATA *Private\r
- )\r
-{\r
- PXEBC_CACHED_DHCP4_PACKET *SelectedOffer;\r
- EFI_DHCP4_PACKET_OPTION **Options;\r
- UINT32 Index;\r
- EFI_DHCP4_PACKET *Offer;\r
- UINT32 ProxyOfferIndex;\r
- EFI_STATUS Status;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_DHCP4_PACKET *Ack;\r
-\r
- ASSERT (Private->SelectedOffer != 0);\r
-\r
- Status = EFI_SUCCESS;\r
- SelectedOffer = &Private->Dhcp4Offers[Private->SelectedOffer - 1];\r
- Options = SelectedOffer->Dhcp4Option;\r
-\r
- if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_BINL) {\r
- //\r
- // The addresses are acquired from a BINL dhcp offer, try BINL to get\r
- // the bootfile name\r
- //\r
- if (!PxeBcTryBinl (Private, Private->SelectedOffer - 1)) {\r
- Status = EFI_NO_RESPONSE;\r
- }\r
- } else if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) {\r
- //\r
- // The selected offer to finish the D.O.R.A. is a DHCP only offer, we need\r
- // try proxy offers if there are some, othewise the bootfile name must be\r
- // set in this DHCP only offer.\r
- //\r
- if (Private->GotProxyOffer) {\r
- //\r
- // Get rid of the compiler warning.\r
- //\r
- ProxyOfferIndex = 0;\r
- if (Private->SortOffers) {\r
- //\r
- // The offers are sorted before selecting, the proxy offer type must be\r
- // already determined.\r
- //\r
- ASSERT (Private->ProxyIndex[Private->ProxyOfferType] > 0);\r
-\r
- if (Private->ProxyOfferType == DHCP4_PACKET_TYPE_BINL) {\r
- //\r
- // We buffer all received BINL proxy offers, try them all one by one\r
- //\r
- if (!PxeBcTryBinlProxy (Private, &ProxyOfferIndex)) {\r
- Status = EFI_NO_RESPONSE;\r
- }\r
- } else {\r
- //\r
- // For other types, only one proxy offer is buffered.\r
- //\r
- ProxyOfferIndex = Private->ProxyIndex[Private->ProxyOfferType] - 1;\r
- }\r
- } else {\r
- //\r
- // The proxy offer type is not determined, choose proxy offer in the\r
- // received order.\r
- //\r
- Status = EFI_NO_RESPONSE;\r
-\r
- ASSERT (Private->NumOffers < PXEBC_MAX_OFFER_NUM);\r
- for (Index = 0; Index < Private->NumOffers; Index++) {\r
-\r
- Offer = &Private->Dhcp4Offers[Index].Packet.Offer;\r
- if (!IS_PROXY_DHCP_OFFER (Offer)) {\r
- //\r
- // Skip non proxy dhcp offers.\r
- //\r
- continue;\r
- }\r
-\r
- if (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL) {\r
- //\r
- // Try BINL\r
- //\r
- if (!PxeBcTryBinl (Private, Index)) {\r
- //\r
- // Failed, skip to the next offer\r
- //\r
- continue;\r
- }\r
- }\r
-\r
- Private->ProxyOfferType = Private->Dhcp4Offers[Index].OfferType;\r
- ProxyOfferIndex = Index;\r
- Status = EFI_SUCCESS;\r
- break;\r
- }\r
- }\r
-\r
- if (!EFI_ERROR (Status) && (Private->ProxyOfferType != DHCP4_PACKET_TYPE_BINL)) {\r
- //\r
- // Copy the proxy offer to Mode and set the flag\r
- //\r
- Status = PxeBcCopyProxyOffer (Private, ProxyOfferIndex);\r
- }\r
- } else {\r
- //\r
- // No proxy offer is received, the bootfile name MUST be set.\r
- //\r
- ASSERT (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);\r
- }\r
- }\r
-\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // Everything is OK, set the flag and copy the DHCP packets.\r
- //\r
- Mode = Private->PxeBc.Mode;\r
- Offer = &SelectedOffer->Packet.Offer;\r
-\r
- //\r
- // The discover packet is already copied, just set flag here.\r
- //\r
- Mode->DhcpDiscoverValid = TRUE;\r
-\r
- Ack = &Private->Dhcp4Ack.Packet.Ack;\r
- if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_BOOTP) {\r
- //\r
- // Other type of ACK is already cached. Bootp is special that we should\r
- // use the bootp reply as the ACK and put it into the DHCP_ONLY buffer.\r
- //\r
- Status = PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Offer);\r
- }\r
-\r
- PxeBcParseCachedDhcpPacket (&Private->Dhcp4Ack);\r
-\r
- Mode->DhcpAckReceived = TRUE;\r
-\r
- //\r
- // Copy the dhcp ack.\r
- //\r
- CopyMem (&Mode->DhcpAck, &Ack->Dhcp4, Ack->Length);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Cache the Dhcp4 packet offer, Parse and validate each option of the packet.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param RcvdOffer Pointer to the received Dhcp proxy offer packet.\r
-\r
- @retval EFI_SUCCESS Cache and parse the packet successfully.\r
- @retval Others Operation failed.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcCacheDhcpOffer (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_DHCP4_PACKET *RcvdOffer\r
- )\r
-{\r
- PXEBC_CACHED_DHCP4_PACKET *CachedOffer;\r
- EFI_DHCP4_PACKET *Offer;\r
- UINT8 OfferType;\r
- EFI_STATUS Status;\r
-\r
- CachedOffer = &Private->Dhcp4Offers[Private->NumOffers];\r
- Offer = &CachedOffer->Packet.Offer;\r
-\r
- //\r
- // Cache the orignal dhcp packet\r
- //\r
- Status = PxeBcCopyEfiDhcp4Packet (Offer, RcvdOffer);\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Parse and validate the options (including dhcp option and vendor option)\r
- //\r
- if (!PxeBcParseCachedDhcpPacket (CachedOffer)) {\r
- return EFI_ABORTED;\r
- }\r
-\r
- OfferType = CachedOffer->OfferType;\r
- if (OfferType >= DHCP4_PACKET_TYPE_MAX) {\r
- return EFI_ABORTED;\r
- }\r
-\r
- if (OfferType == DHCP4_PACKET_TYPE_BOOTP) {\r
-\r
- if (Private->BootpIndex != 0) {\r
- //\r
- // Only cache the first bootp offer, discard others.\r
- //\r
- return EFI_ABORTED;\r
- } else {\r
- //\r
- // Take as a dhcp only offer, but record index specifically.\r
- //\r
- Private->BootpIndex = Private->NumOffers + 1;\r
- }\r
- } else {\r
-\r
- if (IS_PROXY_DHCP_OFFER (Offer)) {\r
- //\r
- // It's a proxy dhcp offer with no your address, including pxe10, wfm11a or binl offer.\r
- //\r
- Private->GotProxyOffer = TRUE;\r
-\r
- if (OfferType == DHCP4_PACKET_TYPE_BINL) {\r
- //\r
- // Cache all binl offers.\r
- //\r
- Private->BinlIndex[Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]] = Private->NumOffers;\r
- Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]++;\r
- } else if (Private->ProxyIndex[OfferType] != 0) {\r
- //\r
- // Only cache the first pxe10/wfm11a offers each, discard the others.\r
- //\r
- return EFI_ABORTED;\r
- } else {\r
- //\r
- // Record index of the proxy dhcp offer with type other than binl.\r
- //\r
- Private->ProxyIndex[OfferType] = Private->NumOffers + 1;\r
- }\r
- } else {\r
- //\r
- // It's a dhcp offer with your address.\r
- //\r
- ASSERT (Private->ServerCount[OfferType] < PXEBC_MAX_OFFER_NUM);\r
- Private->OfferIndex[OfferType][Private->ServerCount[OfferType]] = Private->NumOffers;\r
- Private->ServerCount[OfferType]++;\r
- }\r
- }\r
-\r
- //\r
- // Count the accepted offers.\r
- //\r
- Private->NumOffers++;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Switch the Ip4 policy to static.\r
-\r
- @param[in] Private The pointer to PXEBC_PRIVATE_DATA.\r
-\r
- @retval EFI_SUCCESS The policy is already configured to static.\r
- @retval Others Other error as indicated..\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcSetIp4Policy (\r
- IN PXEBC_PRIVATE_DATA *Private\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2;\r
- EFI_IP4_CONFIG2_POLICY Policy;\r
- UINTN DataSize;\r
-\r
- Ip4Config2 = Private->Ip4Config2;\r
- DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);\r
- Status = Ip4Config2->GetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypePolicy,\r
- &DataSize,\r
- &Policy\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- if (Policy != Ip4Config2PolicyStatic) {\r
- Policy = Ip4Config2PolicyStatic;\r
- Status= Ip4Config2->SetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypePolicy,\r
- sizeof (EFI_IP4_CONFIG2_POLICY),\r
- &Policy\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Select the specified proxy offer, such as BINL, DHCP_ONLY and so on.\r
- If the proxy does not exist, try offers with bootfile.\r
-\r
- @param Private Pointer to PxeBc private data.\r
-\r
-**/\r
-VOID\r
-PxeBcSelectOffer (\r
- IN PXEBC_PRIVATE_DATA *Private\r
- )\r
-{\r
- UINT32 Index;\r
- UINT32 OfferIndex;\r
- EFI_DHCP4_PACKET *Offer;\r
-\r
- Private->SelectedOffer = 0;\r
-\r
- if (Private->SortOffers) {\r
- //\r
- // Select offer according to the priority\r
- //\r
- if (Private->ServerCount[DHCP4_PACKET_TYPE_PXE10] > 0) {\r
- //\r
- // DHCP with PXE10\r
- //\r
- Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_PXE10][0] + 1;\r
-\r
- } else if (Private->ServerCount[DHCP4_PACKET_TYPE_WFM11A] > 0) {\r
- //\r
- // DHCP with WfM\r
- //\r
- Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_WFM11A][0] + 1;\r
-\r
- } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_PXE10] > 0) &&\r
- (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)\r
- ) {\r
- //\r
- // DHCP only and proxy DHCP with PXE10\r
- //\r
- Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;\r
- Private->ProxyOfferType = DHCP4_PACKET_TYPE_PXE10;\r
-\r
- } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_WFM11A] > 0) &&\r
- (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)\r
- ) {\r
- //\r
- // DHCP only and proxy DHCP with WfM\r
- //\r
- Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;\r
- Private->ProxyOfferType = DHCP4_PACKET_TYPE_WFM11A;\r
-\r
- } else if (Private->ServerCount[DHCP4_PACKET_TYPE_BINL] > 0) {\r
- //\r
- // DHCP with BINL\r
- //\r
- Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_BINL][0] + 1;\r
-\r
- } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL] > 0) &&\r
- (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)\r
- ) {\r
- //\r
- // DHCP only and proxy DHCP with BINL\r
- //\r
- Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;\r
- Private->ProxyOfferType = DHCP4_PACKET_TYPE_BINL;\r
-\r
- } else {\r
- //\r
- // Try offers with bootfile\r
- //\r
- for (Index = 0; Index < Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY]; Index++) {\r
- //\r
- // Select the first DHCP only offer with bootfile\r
- //\r
- OfferIndex = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][Index];\r
- if (Private->Dhcp4Offers[OfferIndex].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {\r
- Private->SelectedOffer = OfferIndex + 1;\r
- break;\r
- }\r
- }\r
-\r
- if (Private->SelectedOffer == 0) {\r
- //\r
- // Select the Bootp reply with bootfile if any\r
- //\r
- Private->SelectedOffer = Private->BootpIndex;\r
- }\r
- }\r
- } else {\r
- //\r
- // Try the offers in the received order.\r
- //\r
- for (Index = 0; Index < Private->NumOffers; Index++) {\r
-\r
- Offer = &Private->Dhcp4Offers[Index].Packet.Offer;\r
-\r
- if (IS_PROXY_DHCP_OFFER (Offer)) {\r
- //\r
- // Skip proxy offers\r
- //\r
- continue;\r
- }\r
-\r
- if ((Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) &&\r
- ((!Private->GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL))) {\r
- //\r
- // DHCP only offer but no proxy offer received and no bootfile option in this offer\r
- //\r
- continue;\r
- }\r
-\r
- Private->SelectedOffer = Index + 1;\r
- break;\r
- }\r
- }\r
-}\r
-\r
-\r
-/**\r
- Callback routine.\r
-\r
- EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protocol driver\r
- to intercept events that occurred in the configuration process. This structure\r
- provides advanced control of each state transition of the DHCP process. The\r
- returned status code determines the behavior of the EFI DHCPv4 Protocol driver.\r
- There are three possible returned values, which are described in the following\r
- table.\r
-\r
- @param This Pointer to the EFI DHCPv4 Protocol instance that is used to\r
- configure this callback function.\r
- @param Context Pointer to the context that is initialized by\r
- EFI_DHCP4_PROTOCOL.Configure().\r
- @param CurrentState The current operational state of the EFI DHCPv4 Protocol\r
- driver.\r
- @param Dhcp4Event The event that occurs in the current state, which usually means a\r
- state transition.\r
- @param Packet The DHCP packet that is going to be sent or already received.\r
- @param NewPacket The packet that is used to replace the above Packet.\r
-\r
- @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to continue the DHCP process.\r
- @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The EFI DHCPv4 Protocol\r
- driver will continue to wait for more DHCPOFFER packets until the retry\r
- timeout expires.\r
- @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to abort the current process and\r
- return to the Dhcp4Init or Dhcp4InitReboot state.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDhcpCallBack (\r
- IN EFI_DHCP4_PROTOCOL * This,\r
- IN VOID *Context,\r
- IN EFI_DHCP4_STATE CurrentState,\r
- IN EFI_DHCP4_EVENT Dhcp4Event,\r
- IN EFI_DHCP4_PACKET * Packet OPTIONAL,\r
- OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;\r
- EFI_DHCP4_PACKET_OPTION *MaxMsgSize;\r
- UINT16 Value;\r
- EFI_STATUS Status;\r
- BOOLEAN Received;\r
- EFI_DHCP4_HEADER *DhcpHeader;\r
-\r
- if ((Dhcp4Event != Dhcp4RcvdOffer) &&\r
- (Dhcp4Event != Dhcp4SelectOffer) &&\r
- (Dhcp4Event != Dhcp4SendDiscover) &&\r
- (Dhcp4Event != Dhcp4RcvdAck) &&\r
- (Dhcp4Event != Dhcp4SendRequest)) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- Private = (PXEBC_PRIVATE_DATA *) Context;\r
- Mode = Private->PxeBc.Mode;\r
- Callback = Private->PxeBcCallback;\r
-\r
- //\r
- // Override the Maximum DHCP Message Size.\r
- //\r
- MaxMsgSize = PxeBcParseExtendOptions (\r
- Packet->Dhcp4.Option,\r
- GET_OPTION_BUFFER_LEN (Packet),\r
- DHCP4_TAG_MAXMSG\r
- );\r
- if (MaxMsgSize != NULL) {\r
- Value = HTONS (PXEBC_DHCP4_MAX_PACKET_SIZE);\r
- CopyMem (MaxMsgSize->Data, &Value, sizeof (Value));\r
- }\r
-\r
- if ((Dhcp4Event != Dhcp4SelectOffer) && (Callback != NULL)) {\r
- Received = (BOOLEAN) ((Dhcp4Event == Dhcp4RcvdOffer) || (Dhcp4Event == Dhcp4RcvdAck));\r
- Status = Callback->Callback (\r
- Callback,\r
- Private->Function,\r
- Received,\r
- Packet->Length,\r
- (EFI_PXE_BASE_CODE_PACKET *) &Packet->Dhcp4\r
- );\r
- if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) {\r
- return EFI_ABORTED;\r
- }\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
-\r
- switch (Dhcp4Event) {\r
-\r
- case Dhcp4SendDiscover:\r
- case Dhcp4SendRequest:\r
- if (Packet->Length > PXEBC_DHCP4_MAX_PACKET_SIZE) {\r
- //\r
- // If the to be sent packet exceeds the maximum length, abort the DHCP process.\r
- //\r
- Status = EFI_ABORTED;\r
- break;\r
- }\r
-\r
- if (Mode->SendGUID) {\r
- //\r
- // send the system GUID instead of the MAC address as the hardware address\r
- // in the DHCP packet header.\r
- //\r
- DhcpHeader = &Packet->Dhcp4.Header;\r
-\r
- if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {\r
- //\r
- // GUID not yet set - send all 0xff's to show programable (via SetVariable)\r
- // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);\r
- // GUID not yet set - send all 0's to show not programable\r
- //\r
- DEBUG ((EFI_D_WARN, "PXE: Failed to read system GUID from the smbios table!\n"));\r
- ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));\r
- }\r
-\r
- DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);\r
- }\r
-\r
- if (Dhcp4Event == Dhcp4SendDiscover) {\r
- //\r
- // Cache the dhcp discover packet, of which some information will be used later.\r
- //\r
- CopyMem (Mode->DhcpDiscover.Raw, &Packet->Dhcp4, Packet->Length);\r
- }\r
-\r
- break;\r
-\r
- case Dhcp4RcvdOffer:\r
- Status = EFI_NOT_READY;\r
- if (Packet->Length > PXEBC_DHCP4_MAX_PACKET_SIZE) {\r
- //\r
- // Ignore the incoming Offers which exceed the maximum length.\r
- //\r
- break;\r
- }\r
-\r
- if (Private->NumOffers < PXEBC_MAX_OFFER_NUM) {\r
- //\r
- // Cache the dhcp offers in Private->Dhcp4Offers[]\r
- // If error happens, just ignore this packet and continue to wait more offer.\r
- //\r
- PxeBcCacheDhcpOffer (Private, Packet);\r
- }\r
-\r
- break;\r
-\r
- case Dhcp4SelectOffer:\r
- //\r
- // Select an offer, if succeeded, Private->SelectedOffer points to\r
- // the index of the selected one.\r
- //\r
- PxeBcSelectOffer (Private);\r
-\r
- if (Private->SelectedOffer == 0) {\r
- Status = EFI_ABORTED;\r
- } else {\r
- *NewPacket = &Private->Dhcp4Offers[Private->SelectedOffer - 1].Packet.Offer;\r
- }\r
-\r
- break;\r
-\r
- case Dhcp4RcvdAck:\r
- //\r
- // Cache Ack\r
- //\r
- ASSERT (Private->SelectedOffer != 0);\r
-\r
- Status = PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Packet);\r
- if (EFI_ERROR (Status)) {\r
- return EFI_ABORTED;\r
- }\r
- break;\r
-\r
- default:\r
- break;\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Initialize the DHCP options and build the option list.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param OptList Pointer to a DHCP option list.\r
-\r
- @param IsDhcpDiscover Discover dhcp option or not.\r
-\r
- @return The index item number of the option list.\r
-\r
-**/\r
-UINT32\r
-PxeBcBuildDhcpOptions (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_DHCP4_PACKET_OPTION **OptList,\r
- IN BOOLEAN IsDhcpDiscover\r
- )\r
-{\r
- UINT32 Index;\r
- PXEBC_DHCP4_OPTION_ENTRY OptEnt;\r
- UINT16 Value;\r
-\r
- Index = 0;\r
- OptList[0] = (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer;\r
-\r
- if (!IsDhcpDiscover) {\r
- //\r
- // Append message type.\r
- //\r
- OptList[Index]->OpCode = DHCP4_TAG_MSG_TYPE;\r
- OptList[Index]->Length = 1;\r
- OptEnt.Mesg = (PXEBC_DHCP4_OPTION_MESG *) OptList[Index]->Data;\r
- OptEnt.Mesg->Type = PXEBC_DHCP4_MSG_TYPE_REQUEST;\r
- Index++;\r
- OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);\r
-\r
- //\r
- // Append max message size.\r
- //\r
- OptList[Index]->OpCode = DHCP4_TAG_MAXMSG;\r
- OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE);\r
- OptEnt.MaxMesgSize = (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *) OptList[Index]->Data;\r
- Value = NTOHS (PXEBC_DHCP4_MAX_PACKET_SIZE);\r
- CopyMem (&OptEnt.MaxMesgSize->Size, &Value, sizeof (UINT16));\r
- Index++;\r
- OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);\r
- }\r
- //\r
- // Parameter request list option.\r
- //\r
- OptList[Index]->OpCode = DHCP4_TAG_PARA_LIST;\r
- OptList[Index]->Length = 35;\r
- OptEnt.Para = (PXEBC_DHCP4_OPTION_PARA *) OptList[Index]->Data;\r
- OptEnt.Para->ParaList[0] = DHCP4_TAG_NETMASK;\r
- OptEnt.Para->ParaList[1] = DHCP4_TAG_TIME_OFFSET;\r
- OptEnt.Para->ParaList[2] = DHCP4_TAG_ROUTER;\r
- OptEnt.Para->ParaList[3] = DHCP4_TAG_TIME_SERVER;\r
- OptEnt.Para->ParaList[4] = DHCP4_TAG_NAME_SERVER;\r
- OptEnt.Para->ParaList[5] = DHCP4_TAG_DNS_SERVER;\r
- OptEnt.Para->ParaList[6] = DHCP4_TAG_HOSTNAME;\r
- OptEnt.Para->ParaList[7] = DHCP4_TAG_BOOTFILE_LEN;\r
- OptEnt.Para->ParaList[8] = DHCP4_TAG_DOMAINNAME;\r
- OptEnt.Para->ParaList[9] = DHCP4_TAG_ROOTPATH;\r
- OptEnt.Para->ParaList[10] = DHCP4_TAG_EXTEND_PATH;\r
- OptEnt.Para->ParaList[11] = DHCP4_TAG_EMTU;\r
- OptEnt.Para->ParaList[12] = DHCP4_TAG_TTL;\r
- OptEnt.Para->ParaList[13] = DHCP4_TAG_BROADCAST;\r
- OptEnt.Para->ParaList[14] = DHCP4_TAG_NIS_DOMAIN;\r
- OptEnt.Para->ParaList[15] = DHCP4_TAG_NIS_SERVER;\r
- OptEnt.Para->ParaList[16] = DHCP4_TAG_NTP_SERVER;\r
- OptEnt.Para->ParaList[17] = DHCP4_TAG_VENDOR;\r
- OptEnt.Para->ParaList[18] = DHCP4_TAG_REQUEST_IP;\r
- OptEnt.Para->ParaList[19] = DHCP4_TAG_LEASE;\r
- OptEnt.Para->ParaList[20] = DHCP4_TAG_SERVER_ID;\r
- OptEnt.Para->ParaList[21] = DHCP4_TAG_T1;\r
- OptEnt.Para->ParaList[22] = DHCP4_TAG_T2;\r
- OptEnt.Para->ParaList[23] = DHCP4_TAG_VENDOR_CLASS_ID;\r
- OptEnt.Para->ParaList[24] = DHCP4_TAG_TFTP;\r
- OptEnt.Para->ParaList[25] = DHCP4_TAG_BOOTFILE;\r
- OptEnt.Para->ParaList[26] = DHCP4_TAG_UUID;\r
- OptEnt.Para->ParaList[27] = 0x80;\r
- OptEnt.Para->ParaList[28] = 0x81;\r
- OptEnt.Para->ParaList[29] = 0x82;\r
- OptEnt.Para->ParaList[30] = 0x83;\r
- OptEnt.Para->ParaList[31] = 0x84;\r
- OptEnt.Para->ParaList[32] = 0x85;\r
- OptEnt.Para->ParaList[33] = 0x86;\r
- OptEnt.Para->ParaList[34] = 0x87;\r
- Index++;\r
- OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);\r
-\r
- //\r
- // Append UUID/Guid-based client identifier option\r
- //\r
- OptList[Index]->OpCode = DHCP4_TAG_UUID;\r
- OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UUID);\r
- OptEnt.Uuid = (PXEBC_DHCP4_OPTION_UUID *) OptList[Index]->Data;\r
- OptEnt.Uuid->Type = 0;\r
- Index++;\r
- OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);\r
-\r
- if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) OptEnt.Uuid->Guid))) {\r
- //\r
- // GUID not yet set - send all 0xff's to show programable (via SetVariable)\r
- // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);\r
- // GUID not yet set - send all 0's to show not programable\r
- //\r
- DEBUG ((EFI_D_WARN, "PXE: Failed to read system GUID from the smbios table!\n"));\r
- ZeroMem (OptEnt.Uuid->Guid, sizeof (EFI_GUID));\r
- }\r
-\r
- //\r
- // Append client network device interface option\r
- //\r
- OptList[Index]->OpCode = DHCP4_TAG_UNDI;\r
- OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UNDI);\r
- OptEnt.Undi = (PXEBC_DHCP4_OPTION_UNDI *) OptList[Index]->Data;\r
- if (Private->Nii != NULL) {\r
- OptEnt.Undi->Type = Private->Nii->Type;\r
- OptEnt.Undi->MajorVer = Private->Nii->MajorVer;\r
- OptEnt.Undi->MinorVer = Private->Nii->MinorVer;\r
- } else {\r
- OptEnt.Undi->Type = DEFAULT_UNDI_TYPE;\r
- OptEnt.Undi->MajorVer = DEFAULT_UNDI_MAJOR;\r
- OptEnt.Undi->MinorVer = DEFAULT_UNDI_MINOR;\r
- }\r
-\r
- Index++;\r
- OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);\r
-\r
- //\r
- // Append client system architecture option\r
- //\r
- OptList[Index]->OpCode = DHCP4_TAG_ARCH;\r
- OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_ARCH);\r
- OptEnt.Arch = (PXEBC_DHCP4_OPTION_ARCH *) OptList[Index]->Data;\r
- Value = HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE);\r
- CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16));\r
- Index++;\r
- OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);\r
-\r
- //\r
- // Append client system architecture option\r
- //\r
- OptList[Index]->OpCode = DHCP4_TAG_VENDOR_CLASS_ID;\r
- OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_CLID);\r
- OptEnt.Clid = (PXEBC_DHCP4_OPTION_CLID *) OptList[Index]->Data;\r
- CopyMem (OptEnt.Clid, DEFAULT_CLASS_ID_DATA, sizeof (PXEBC_DHCP4_OPTION_CLID));\r
- CvtNum (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType));\r
-\r
- if (Private->Nii != NULL) {\r
- //\r
- // If NII protocol exists, update DHCP option data\r
- //\r
- CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (OptEnt.Clid->InterfaceName));\r
- CvtNum (Private->Nii->MajorVer, OptEnt.Clid->UndiMajor, sizeof (OptEnt.Clid->UndiMajor));\r
- CvtNum (Private->Nii->MinorVer, OptEnt.Clid->UndiMinor, sizeof (OptEnt.Clid->UndiMinor));\r
- }\r
-\r
- Index++;\r
-\r
- return Index;\r
-}\r
-\r
-\r
-/**\r
- Discover the boot of service and initialize the vendor option if exists.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param Type PxeBc option boot item type\r
- @param Layer PxeBc option boot item layer\r
- @param UseBis Use BIS or not\r
- @param DestIp Ip address for server\r
- @param IpCount The total count of the server ip address\r
- @param SrvList Server list\r
- @param IsDiscv Discover the vendor or not\r
- @param Reply The dhcp4 packet of Pxe reply\r
-\r
- @retval EFI_SUCCESS Operation succeeds.\r
- @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed.\r
- @retval EFI_NOT_FOUND There is no vendor option exists.\r
- @retval EFI_TIMEOUT Send Pxe Discover time out.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcDiscvBootService (\r
- IN PXEBC_PRIVATE_DATA * Private,\r
- IN UINT16 Type,\r
- IN UINT16 *Layer,\r
- IN BOOLEAN UseBis,\r
- IN EFI_IP_ADDRESS * DestIp,\r
- IN UINT16 IpCount,\r
- IN EFI_PXE_BASE_CODE_SRVLIST * SrvList,\r
- IN BOOLEAN IsDiscv,\r
- OUT EFI_DHCP4_PACKET * Reply OPTIONAL\r
- )\r
-{\r
- EFI_PXE_BASE_CODE_UDP_PORT Sport;\r
- EFI_PXE_BASE_CODE_MODE *Mode;\r
- EFI_DHCP4_PROTOCOL *Dhcp4;\r
- EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN Token;\r
- BOOLEAN IsBCast;\r
- EFI_STATUS Status;\r
- UINT16 RepIndex;\r
- UINT16 SrvIndex;\r
- UINT16 TryIndex;\r
- EFI_DHCP4_LISTEN_POINT ListenPoint;\r
- EFI_DHCP4_PACKET *Response;\r
- EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];\r
- UINT32 OptCount;\r
- EFI_DHCP4_PACKET_OPTION *PxeOpt;\r
- PXEBC_OPTION_BOOT_ITEM *PxeBootItem;\r
- UINT8 VendorOptLen;\r
- EFI_DHCP4_HEADER *DhcpHeader;\r
- UINT32 Xid;\r
-\r
- Mode = Private->PxeBc.Mode;\r
- Dhcp4 = Private->Dhcp4;\r
- Status = EFI_SUCCESS;\r
-\r
- ZeroMem (&Token, sizeof (EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN));\r
-\r
- if (DestIp == NULL) {\r
- Sport = PXEBC_DHCP4_S_PORT;\r
- IsBCast = TRUE;\r
- } else {\r
- Sport = PXEBC_BS_DISCOVER_PORT;\r
- IsBCast = FALSE;\r
- }\r
-\r
- if (!UseBis && Layer != NULL) {\r
- *Layer &= EFI_PXE_BASE_CODE_BOOT_LAYER_MASK;\r
- }\r
-\r
- OptCount = PxeBcBuildDhcpOptions (Private, OptList, FALSE);\r
-\r
- if (IsDiscv) {\r
- ASSERT (Layer != NULL);\r
- //\r
- // Add vendor option of PXE_BOOT_ITEM\r
- //\r
- VendorOptLen = (UINT8) ((sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1);\r
- OptList[OptCount] = AllocatePool (VendorOptLen);\r
- if (OptList[OptCount] == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- OptList[OptCount]->OpCode = DHCP4_TAG_VENDOR;\r
- OptList[OptCount]->Length = (UINT8) (VendorOptLen - 2);\r
- PxeOpt = (EFI_DHCP4_PACKET_OPTION *) OptList[OptCount]->Data;\r
- PxeOpt->OpCode = PXEBC_VENDOR_TAG_BOOT_ITEM;\r
- PxeOpt->Length = (UINT8) sizeof (PXEBC_OPTION_BOOT_ITEM);\r
- PxeBootItem = (PXEBC_OPTION_BOOT_ITEM *) PxeOpt->Data;\r
- PxeBootItem->Type = HTONS (Type);\r
- PxeBootItem->Layer = HTONS (*Layer);\r
- PxeOpt->Data[PxeOpt->Length] = DHCP4_TAG_EOP;\r
-\r
- OptCount++;\r
- }\r
-\r
- Status = Dhcp4->Build (Dhcp4, &Private->SeedPacket, 0, NULL, OptCount, OptList, &Token.Packet);\r
-\r
- if (IsDiscv) {\r
- FreePool (OptList[OptCount - 1]);\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- DhcpHeader = &Token.Packet->Dhcp4.Header;\r
- if (Mode->SendGUID) {\r
- if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {\r
- //\r
- // GUID not yet set - send all 0's to show not programable\r
- //\r
- DEBUG ((EFI_D_WARN, "PXE: Failed to read system GUID from the smbios table!\n"));\r
- ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));\r
- }\r
-\r
- DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);\r
- }\r
-\r
- Xid = NET_RANDOM (NetRandomInitSeed ());\r
- Token.Packet->Dhcp4.Header.Xid = HTONL(Xid);\r
- Token.Packet->Dhcp4.Header.Reserved = HTONS((UINT16) ((IsBCast) ? 0x8000 : 0));\r
- CopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
-\r
- Token.RemotePort = Sport;\r
-\r
- if (IsBCast) {\r
- SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff);\r
- } else {\r
- CopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r
- }\r
-\r
- CopyMem (&Token.GatewayAddress, &Private->GatewayIp, sizeof (EFI_IPv4_ADDRESS));\r
-\r
- if (!IsBCast) {\r
- Token.ListenPointCount = 1;\r
- Token.ListenPoints = &ListenPoint;\r
- Token.ListenPoints[0].ListenPort = PXEBC_BS_DISCOVER_PORT;\r
- CopyMem (&Token.ListenPoints[0].ListenAddress, &Private->StationIp, sizeof(EFI_IPv4_ADDRESS));\r
- CopyMem (&Token.ListenPoints[0].SubnetMask, &Private->SubnetMask, sizeof(EFI_IPv4_ADDRESS));\r
- }\r
- //\r
- // Send Pxe Discover\r
- //\r
- for (TryIndex = 1; TryIndex <= PXEBC_BOOT_REQUEST_RETRIES; TryIndex++) {\r
-\r
- Token.TimeoutValue = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex);\r
- Token.Packet->Dhcp4.Header.Seconds = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * (TryIndex - 1));\r
-\r
- Status = Dhcp4->TransmitReceive (Dhcp4, &Token);\r
-\r
- if (Token.Status != EFI_TIMEOUT) {\r
- break;\r
- }\r
- }\r
-\r
- if (TryIndex > PXEBC_BOOT_REQUEST_RETRIES) {\r
- //\r
- // No server response our PXE request\r
- //\r
- Status = EFI_TIMEOUT;\r
- }\r
-\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // Find Pxe Reply\r
- //\r
- RepIndex = 0;\r
- SrvIndex = 0;\r
- Response = Token.ResponseList;\r
-\r
- while (RepIndex < Token.ResponseCount) {\r
- if (Response->Length > PXEBC_DHCP4_MAX_PACKET_SIZE) {\r
- SrvIndex = 0;\r
- RepIndex++;\r
- Response = (EFI_DHCP4_PACKET *) ((UINT8 *) Response + Response->Size);\r
- continue;\r
- }\r
-\r
- while (SrvIndex < IpCount) {\r
-\r
- if (SrvList[SrvIndex].AcceptAnyResponse) {\r
- break;\r
- }\r
-\r
- if ((SrvList[SrvIndex].Type == Type) && EFI_IP4_EQUAL (&(Response->Dhcp4.Header.ServerAddr), &(Private->ServerIp))) {\r
- break;\r
- }\r
-\r
- SrvIndex++;\r
- }\r
-\r
- if ((IpCount != SrvIndex) || (IpCount == 0)) {\r
- break;\r
- }\r
-\r
- SrvIndex = 0;\r
- RepIndex++;\r
- Response = (EFI_DHCP4_PACKET *) ((UINT8 *) Response + Response->Size);\r
- }\r
-\r
- if (RepIndex < Token.ResponseCount) {\r
-\r
- if (Reply != NULL) {\r
- Status = PxeBcCopyEfiDhcp4Packet (Reply, Response);\r
- if (EFI_ERROR(Status)) {\r
- goto ON_EXIT;\r
- }\r
- }\r
-\r
- if (IsDiscv) {\r
- CopyMem (&(Mode->PxeDiscover), &(Token.Packet->Dhcp4), Token.Packet->Length);\r
- Mode->PxeDiscoverValid = TRUE;\r
-\r
- CopyMem (Mode->PxeReply.Raw, &Response->Dhcp4, Response->Length);\r
- Mode->PxeReplyReceived = TRUE;\r
- }\r
- } else {\r
- Status = EFI_NOT_FOUND;\r
- }\r
- }\r
-\r
-ON_EXIT:\r
- //\r
- // free the responselist\r
- //\r
- if (Token.ResponseList != NULL) {\r
- FreePool (Token.ResponseList);\r
- }\r
- //\r
- // Free the dhcp packet\r
- //\r
- if (Token.Packet != NULL) {\r
- FreePool (Token.Packet);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Parse interested dhcp options.\r
-\r
- @param Buffer Pointer to the dhcp options packet.\r
- @param Length The length of the dhcp options.\r
- @param OptTag The option OpCode.\r
-\r
- @return NULL if the buffer length is 0 and OpCode is not\r
- DHCP4_TAG_EOP, or the pointer to the buffer.\r
-\r
-**/\r
-EFI_DHCP4_PACKET_OPTION *\r
-PxeBcParseExtendOptions (\r
- IN UINT8 *Buffer,\r
- IN UINT32 Length,\r
- IN UINT8 OptTag\r
- )\r
-{\r
- EFI_DHCP4_PACKET_OPTION *Option;\r
- UINT32 Offset;\r
-\r
- Option = (EFI_DHCP4_PACKET_OPTION *) Buffer;\r
- Offset = 0;\r
-\r
- while (Offset < Length && Option->OpCode != DHCP4_TAG_EOP) {\r
-\r
- if (Option->OpCode == OptTag) {\r
-\r
- return Option;\r
- }\r
-\r
- if (Option->OpCode == DHCP4_TAG_PAD) {\r
- Offset++;\r
- } else {\r
- Offset += Option->Length + 2;\r
- }\r
-\r
- Option = (EFI_DHCP4_PACKET_OPTION *) (Buffer + Offset);\r
- }\r
-\r
- return NULL;\r
-}\r
-\r
-\r
-/**\r
- This function is to parse and check vendor options.\r
-\r
- @param Dhcp4Option Pointer to dhcp options\r
- @param VendorOption Pointer to vendor options\r
-\r
- @return TRUE if valid for vendor options, or FALSE.\r
-\r
-**/\r
-BOOLEAN\r
-PxeBcParseVendorOptions (\r
- IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option,\r
- IN PXEBC_VENDOR_OPTION *VendorOption\r
- )\r
-{\r
- UINT32 *BitMap;\r
- UINT8 VendorOptionLen;\r
- EFI_DHCP4_PACKET_OPTION *PxeOption;\r
- UINT8 Offset;\r
-\r
- BitMap = VendorOption->BitMap;\r
- VendorOptionLen = Dhcp4Option->Length;\r
- PxeOption = (EFI_DHCP4_PACKET_OPTION *) &Dhcp4Option->Data[0];\r
- Offset = 0;\r
-\r
- while ((Offset < VendorOptionLen) && (PxeOption->OpCode != DHCP4_TAG_EOP)) {\r
- //\r
- // Parse every Vendor Option and set its BitMap\r
- //\r
- switch (PxeOption->OpCode) {\r
-\r
- case PXEBC_VENDOR_TAG_MTFTP_IP:\r
-\r
- CopyMem (&VendorOption->MtftpIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_MTFTP_CPORT:\r
-\r
- CopyMem (&VendorOption->MtftpCPort, PxeOption->Data, sizeof (VendorOption->MtftpCPort));\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_MTFTP_SPORT:\r
-\r
- CopyMem (&VendorOption->MtftpSPort, PxeOption->Data, sizeof (VendorOption->MtftpSPort));\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_MTFTP_TIMEOUT:\r
-\r
- VendorOption->MtftpTimeout = *PxeOption->Data;\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_MTFTP_DELAY:\r
-\r
- VendorOption->MtftpDelay = *PxeOption->Data;\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_DISCOVER_CTRL:\r
-\r
- VendorOption->DiscoverCtrl = *PxeOption->Data;\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_DISCOVER_MCAST:\r
-\r
- CopyMem (&VendorOption->DiscoverMcastIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_BOOT_SERVERS:\r
-\r
- VendorOption->BootSvrLen = PxeOption->Length;\r
- VendorOption->BootSvr = (PXEBC_BOOT_SVR_ENTRY *) PxeOption->Data;\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_BOOT_MENU:\r
-\r
- VendorOption->BootMenuLen = PxeOption->Length;\r
- VendorOption->BootMenu = (PXEBC_BOOT_MENU_ENTRY *) PxeOption->Data;\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_MENU_PROMPT:\r
-\r
- VendorOption->MenuPromptLen = PxeOption->Length;\r
- VendorOption->MenuPrompt = (PXEBC_MENU_PROMPT *) PxeOption->Data;\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_MCAST_ALLOC:\r
-\r
- CopyMem (&VendorOption->McastIpBase, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&VendorOption->McastIpBlock, PxeOption->Data + 4, sizeof (VendorOption->McastIpBlock));\r
- CopyMem (&VendorOption->McastIpRange, PxeOption->Data + 6, sizeof (VendorOption->McastIpRange));\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_CREDENTIAL_TYPES:\r
-\r
- VendorOption->CredTypeLen = PxeOption->Length;\r
- VendorOption->CredType = (UINT32 *) PxeOption->Data;\r
- break;\r
-\r
- case PXEBC_VENDOR_TAG_BOOT_ITEM:\r
-\r
- CopyMem (&VendorOption->BootSrvType, PxeOption->Data, sizeof (VendorOption->BootSrvType));\r
- CopyMem (&VendorOption->BootSrvLayer, PxeOption->Data + 2, sizeof (VendorOption->BootSrvLayer));\r
- break;\r
- }\r
-\r
- SET_VENDOR_OPTION_BIT_MAP (BitMap, PxeOption->OpCode);\r
-\r
- if (PxeOption->OpCode == DHCP4_TAG_PAD) {\r
- Offset++;\r
- } else {\r
- Offset = (UINT8) (Offset + PxeOption->Length + 2);\r
- }\r
-\r
- PxeOption = (EFI_DHCP4_PACKET_OPTION *) (Dhcp4Option->Data + Offset);\r
- }\r
-\r
- //\r
- // FixMe, return falas if invalid of any vendor option\r
- //\r
-\r
- return TRUE;\r
-}\r
-\r
-\r
-/**\r
- This function display boot item detail.\r
-\r
- If the length of the boot item string over 70 Char, just display 70 Char.\r
-\r
- @param Str Pointer to a string (boot item string).\r
- @param Len The length of string.\r
-\r
-**/\r
-VOID\r
-PxeBcDisplayBootItem (\r
- IN UINT8 *Str,\r
- IN UINT8 Len\r
- )\r
-{\r
- UINT8 Tmp;\r
-\r
- Len = (UINT8) MIN (70, Len);\r
- Tmp = Str[Len];\r
- Str[Len] = 0;\r
- AsciiPrint ("%a \n", Str);\r
- Str[Len] = Tmp;\r
-}\r
-\r
-\r
-/**\r
- Choose the boot prompt.\r
-\r
- @param Private Pointer to PxeBc private data.\r
-\r
- @retval EFI_SUCCESS Select boot prompt done.\r
- @retval EFI_TIMEOUT Select boot prompt time out.\r
- @retval EFI_NOT_FOUND The proxy offer is not Pxe10.\r
- @retval EFI_ABORTED User cancel the operation.\r
- @retval EFI_NOT_READY Read the input key from the keybroad has not finish.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcSelectBootPrompt (\r
- IN PXEBC_PRIVATE_DATA *Private\r
- )\r
-{\r
- PXEBC_CACHED_DHCP4_PACKET *Packet;\r
- PXEBC_VENDOR_OPTION *VendorOpt;\r
- EFI_EVENT TimeoutEvent;\r
- EFI_EVENT DescendEvent;\r
- EFI_INPUT_KEY InputKey;\r
- EFI_STATUS Status;\r
- UINT8 Timeout;\r
- UINT8 *Prompt;\r
- UINT8 PromptLen;\r
- INT32 SecCol;\r
- INT32 SecRow;\r
-\r
- TimeoutEvent = NULL;\r
- DescendEvent = NULL;\r
-\r
- if (Private->PxeBc.Mode->ProxyOfferReceived) {\r
-\r
- Packet = &Private->ProxyOffer;\r
- } else {\r
-\r
- Packet = &Private->Dhcp4Ack;\r
- }\r
-\r
- if (Packet->OfferType != DHCP4_PACKET_TYPE_PXE10) {\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- VendorOpt = &Packet->PxeVendorOption;\r
- //\r
- // According to the PXE specification 2.1, Table 2-1 PXE DHCP Options (Full\r
- // List), we must not consider a boot prompt or boot menu if all of the\r
- // following hold:\r
- // - the PXE_DISCOVERY_CONTROL PXE tag is present inside the Vendor Options\r
- // (=43) DHCP tag, and\r
- // - the PXE_DISCOVERY_CONTROL PXE tag has bit 3 set, and\r
- // - a boot file name has been presented with DHCP option 67.\r
- //\r
- if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) &&\r
- Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {\r
- return EFI_ABORTED;\r
- }\r
-\r
- if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- Timeout = VendorOpt->MenuPrompt->Timeout;\r
- Prompt = VendorOpt->MenuPrompt->Prompt;\r
- PromptLen = (UINT8) (VendorOpt->MenuPromptLen - 1);\r
-\r
- if (Timeout == 0) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- if (Timeout == 255) {\r
- return EFI_TIMEOUT;\r
- }\r
-\r
- Status = gBS->CreateEvent (\r
- EVT_TIMER,\r
- TPL_CALLBACK,\r
- NULL,\r
- NULL,\r
- &TimeoutEvent\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Status = gBS->SetTimer (\r
- TimeoutEvent,\r
- TimerRelative,\r
- MultU64x32 (Timeout, TICKS_PER_SECOND)\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- Status = gBS->CreateEvent (\r
- EVT_TIMER,\r
- TPL_CALLBACK,\r
- NULL,\r
- NULL,\r
- &DescendEvent\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- Status = gBS->SetTimer (\r
- DescendEvent,\r
- TimerPeriodic,\r
- TICKS_PER_SECOND\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_EXIT;\r
- }\r
-\r
- SecCol = gST->ConOut->Mode->CursorColumn;\r
- SecRow = gST->ConOut->Mode->CursorRow;\r
-\r
- PxeBcDisplayBootItem (Prompt, PromptLen);\r
-\r
- gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
- AsciiPrint ("(%d) ", Timeout--);\r
-\r
- while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {\r
-\r
- if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) {\r
- gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
- AsciiPrint ("(%d) ", Timeout--);\r
- }\r
-\r
- if (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {\r
-\r
- gBS->Stall (10 * TICKS_PER_MS);\r
- continue;\r
- }\r
-\r
- if (InputKey.ScanCode == 0) {\r
-\r
- switch (InputKey.UnicodeChar) {\r
- case CTRL ('c'):\r
- Status = EFI_ABORTED;\r
- break;\r
-\r
- case CTRL ('m'):\r
- case 'm':\r
- case 'M':\r
- Status = EFI_TIMEOUT;\r
- break;\r
-\r
- default:\r
- continue;\r
- }\r
- } else {\r
-\r
- switch (InputKey.ScanCode) {\r
- case SCAN_F8:\r
- Status = EFI_TIMEOUT;\r
- break;\r
-\r
- case SCAN_ESC:\r
- Status = EFI_ABORTED;\r
- break;\r
-\r
- default:\r
- continue;\r
- }\r
- }\r
-\r
- break;\r
- }\r
-\r
- gST->ConOut->SetCursorPosition (gST->ConOut, 0 , SecRow + 1);\r
-\r
-ON_EXIT:\r
-\r
- if (DescendEvent != NULL) {\r
- gBS->CloseEvent (DescendEvent);\r
- }\r
-\r
- if (TimeoutEvent != NULL) {\r
- gBS->CloseEvent (TimeoutEvent);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Select the boot menu.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param Type The type of the menu.\r
- @param UseDefaultItem Use default item or not.\r
-\r
- @retval EFI_ABORTED User cancel operation.\r
- @retval EFI_SUCCESS Select the boot menu success.\r
- @retval EFI_NOT_READY Read the input key from the keybroad has not finish.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcSelectBootMenu (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- OUT UINT16 *Type,\r
- IN BOOLEAN UseDefaultItem\r
- )\r
-{\r
- PXEBC_CACHED_DHCP4_PACKET *Packet;\r
- PXEBC_VENDOR_OPTION *VendorOpt;\r
- EFI_INPUT_KEY InputKey;\r
- UINT8 MenuSize;\r
- UINT8 MenuNum;\r
- INT32 TopRow;\r
- UINT16 Select;\r
- UINT16 LastSelect;\r
- UINT8 Index;\r
- BOOLEAN Finish;\r
- CHAR8 Blank[70];\r
- PXEBC_BOOT_MENU_ENTRY *MenuItem;\r
- PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MAX_MENU_NUM];\r
-\r
- Finish = FALSE;\r
- Select = 0;\r
- Index = 0;\r
- *Type = 0;\r
-\r
- if (Private->PxeBc.Mode->ProxyOfferReceived) {\r
-\r
- Packet = &Private->ProxyOffer;\r
- } else {\r
-\r
- Packet = &Private->Dhcp4Ack;\r
- }\r
-\r
- ASSERT (Packet->OfferType == DHCP4_PACKET_TYPE_PXE10);\r
-\r
- VendorOpt = &Packet->PxeVendorOption;\r
-\r
- if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- SetMem (Blank, sizeof(Blank), ' ');\r
-\r
- MenuSize = VendorOpt->BootMenuLen;\r
- MenuItem = VendorOpt->BootMenu;\r
-\r
- if (MenuSize == 0) {\r
- return EFI_NOT_READY;\r
- }\r
-\r
- while (MenuSize > 0) {\r
- MenuArray[Index++] = MenuItem;\r
- MenuSize = (UINT8) (MenuSize - (MenuItem->DescLen + 3));\r
- MenuItem = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3);\r
- if (Index >= PXEBC_MAX_MENU_NUM) {\r
- break;\r
- }\r
- }\r
-\r
- if (UseDefaultItem) {\r
- *Type = MenuArray[0]->Type;\r
- *Type = NTOHS (*Type);\r
- return EFI_SUCCESS;\r
- }\r
-\r
- MenuNum = Index;\r
-\r
- for (Index = 0; Index < MenuNum; Index++) {\r
- PxeBcDisplayBootItem (MenuArray[Index]->DescStr, MenuArray[Index]->DescLen);\r
- }\r
-\r
- TopRow = gST->ConOut->Mode->CursorRow - MenuNum;\r
-\r
- do {\r
- ASSERT (Select < PXEBC_MAX_MENU_NUM);\r
- //\r
- // highlight selected row\r
- //\r
- gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));\r
- gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + Select);\r
- Blank[MenuArray[Select]->DescLen] = 0;\r
- AsciiPrint ("%a\r", Blank);\r
- PxeBcDisplayBootItem (MenuArray[Select]->DescStr, MenuArray[Select]->DescLen);\r
- gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);\r
- LastSelect = Select;\r
-\r
- while (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {\r
- gBS->Stall (10 * TICKS_PER_MS);\r
- }\r
-\r
- if (InputKey.ScanCode == 0) {\r
- switch (InputKey.UnicodeChar) {\r
- case CTRL ('c'):\r
- InputKey.ScanCode = SCAN_ESC;\r
- break;\r
-\r
- case CTRL ('j'): /* linefeed */\r
- case CTRL ('m'): /* return */\r
- Finish = TRUE;\r
- break;\r
-\r
- case CTRL ('i'): /* tab */\r
- case ' ':\r
- case 'd':\r
- case 'D':\r
- InputKey.ScanCode = SCAN_DOWN;\r
- break;\r
-\r
- case CTRL ('h'): /* backspace */\r
- case 'u':\r
- case 'U':\r
- InputKey.ScanCode = SCAN_UP;\r
- break;\r
-\r
- default:\r
- InputKey.ScanCode = 0;\r
- }\r
- }\r
-\r
- switch (InputKey.ScanCode) {\r
- case SCAN_LEFT:\r
- case SCAN_UP:\r
- if (Select > 0) {\r
- --Select;\r
- }\r
-\r
- break;\r
-\r
- case SCAN_DOWN:\r
- case SCAN_RIGHT:\r
- if (++Select == MenuNum) {\r
- --Select;\r
- }\r
-\r
- break;\r
-\r
- case SCAN_PAGE_UP:\r
- case SCAN_HOME:\r
- Select = 0;\r
- break;\r
-\r
- case SCAN_PAGE_DOWN:\r
- case SCAN_END:\r
- Select = (UINT16) (MenuNum - 1);\r
- break;\r
-\r
- case SCAN_ESC:\r
- return EFI_ABORTED;\r
- }\r
-\r
- /* unhighlight last selected row */\r
- gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
- gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + LastSelect);\r
- Blank[MenuArray[LastSelect]->DescLen] = 0;\r
- AsciiPrint ("%a\r", Blank);\r
- PxeBcDisplayBootItem (MenuArray[LastSelect]->DescStr, MenuArray[LastSelect]->DescLen);\r
- gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);\r
- } while (!Finish);\r
-\r
- ASSERT (Select < PXEBC_MAX_MENU_NUM);\r
-\r
- //\r
- // Swap the byte order\r
- //\r
- CopyMem (Type, &MenuArray[Select]->Type, sizeof (UINT16));\r
- *Type = NTOHS (*Type);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
+++ /dev/null
-/** @file\r
- Dhcp and Discover routines for PxeBc.\r
-\r
-Copyright (c) 2013, Red Hat, Inc.\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
-#ifndef __EFI_PXEBC_DHCP_H__\r
-#define __EFI_PXEBC_DHCP_H__\r
-\r
-#define PXEBC_DHCP4_MAX_OPTION_NUM 16\r
-#define PXEBC_DHCP4_MAX_OPTION_SIZE 312\r
-#define PXEBC_DHCP4_MAX_PACKET_SIZE (sizeof (EFI_PXE_BASE_CODE_PACKET))\r
-\r
-#define PXEBC_DHCP4_S_PORT 67\r
-#define PXEBC_DHCP4_C_PORT 68\r
-#define PXEBC_BS_DOWNLOAD_PORT 69\r
-#define PXEBC_BS_DISCOVER_PORT 4011\r
-\r
-#define PXEBC_DHCP4_OPCODE_REQUEST 1\r
-#define PXEBC_DHCP4_OPCODE_REPLY 2\r
-#define PXEBC_DHCP4_MSG_TYPE_REQUEST 3\r
-#define PXEBC_DHCP4_MAGIC 0x63538263 // network byte order\r
-\r
-//\r
-// Sub-Options in Dhcp Vendor Option\r
-//\r
-#define PXEBC_VENDOR_TAG_MTFTP_IP 1\r
-#define PXEBC_VENDOR_TAG_MTFTP_CPORT 2\r
-#define PXEBC_VENDOR_TAG_MTFTP_SPORT 3\r
-#define PXEBC_VENDOR_TAG_MTFTP_TIMEOUT 4\r
-#define PXEBC_VENDOR_TAG_MTFTP_DELAY 5\r
-#define PXEBC_VENDOR_TAG_DISCOVER_CTRL 6\r
-#define PXEBC_VENDOR_TAG_DISCOVER_MCAST 7\r
-#define PXEBC_VENDOR_TAG_BOOT_SERVERS 8\r
-#define PXEBC_VENDOR_TAG_BOOT_MENU 9\r
-#define PXEBC_VENDOR_TAG_MENU_PROMPT 10\r
-#define PXEBC_VENDOR_TAG_MCAST_ALLOC 11\r
-#define PXEBC_VENDOR_TAG_CREDENTIAL_TYPES 12\r
-#define PXEBC_VENDOR_TAG_BOOT_ITEM 71\r
-\r
-#define PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT 4\r
-#define PXEBC_DHCP4_DISCOVER_RETRIES 4\r
-\r
-#define PXEBC_MAX_MENU_NUM 24\r
-#define PXEBC_MAX_OFFER_NUM 16\r
-\r
-#define PXEBC_BOOT_REQUEST_TIMEOUT 1\r
-#define PXEBC_BOOT_REQUEST_RETRIES 4\r
-\r
-#define PXEBC_DHCP4_OVERLOAD_FILE 1\r
-#define PXEBC_DHCP4_OVERLOAD_SERVER_NAME 2\r
-\r
-//\r
-// The array index of the DHCP4 option tag interested\r
-//\r
-#define PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN 0\r
-#define PXEBC_DHCP4_TAG_INDEX_VENDOR 1\r
-#define PXEBC_DHCP4_TAG_INDEX_OVERLOAD 2\r
-#define PXEBC_DHCP4_TAG_INDEX_MSG_TYPE 3\r
-#define PXEBC_DHCP4_TAG_INDEX_SERVER_ID 4\r
-#define PXEBC_DHCP4_TAG_INDEX_CLASS_ID 5\r
-#define PXEBC_DHCP4_TAG_INDEX_BOOTFILE 6\r
-#define PXEBC_DHCP4_TAG_INDEX_MAX 7\r
-\r
-//\r
-// The type of DHCP OFFER, arranged by priority, PXE10 has the highest priority.\r
-//\r
-#define DHCP4_PACKET_TYPE_PXE10 0\r
-#define DHCP4_PACKET_TYPE_WFM11A 1\r
-#define DHCP4_PACKET_TYPE_BINL 2\r
-#define DHCP4_PACKET_TYPE_DHCP_ONLY 3\r
-#define DHCP4_PACKET_TYPE_BOOTP 4\r
-#define DHCP4_PACKET_TYPE_MAX 5\r
-\r
-#define BIT(x) (1 << x)\r
-#define CTRL(x) (0x1F & (x))\r
-\r
-//\r
-// WfM11a options\r
-//\r
-#define MTFTP_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_MTFTP_IP) | \\r
- BIT (PXEBC_VENDOR_TAG_MTFTP_CPORT) | \\r
- BIT (PXEBC_VENDOR_TAG_MTFTP_SPORT) | \\r
- BIT (PXEBC_VENDOR_TAG_MTFTP_TIMEOUT) | \\r
- BIT (PXEBC_VENDOR_TAG_MTFTP_DELAY))\r
-//\r
-// Discoverty options\r
-//\r
-#define DISCOVER_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_DISCOVER_CTRL) | \\r
- BIT (PXEBC_VENDOR_TAG_DISCOVER_MCAST) | \\r
- BIT (PXEBC_VENDOR_TAG_BOOT_SERVERS) | \\r
- BIT (PXEBC_VENDOR_TAG_BOOT_MENU) | \\r
- BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))\r
-\r
-#define IS_VALID_BOOT_PROMPT(x) \\r
- ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_MENU_PROMPT)) == BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))\r
-\r
-#define IS_VALID_BOOT_MENU(x) \\r
- ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_BOOT_MENU)) == BIT (PXEBC_VENDOR_TAG_BOOT_MENU))\r
-\r
-#define IS_VALID_MTFTP_VENDOR_OPTION(x) \\r
- (((UINT32) ((x)[0]) & MTFTP_VENDOR_OPTION_BIT_MAP) == MTFTP_VENDOR_OPTION_BIT_MAP)\r
-\r
-#define IS_VALID_DISCOVER_VENDOR_OPTION(x) (((UINT32) ((x)[0]) & DISCOVER_VENDOR_OPTION_BIT_MAP) != 0)\r
-\r
-#define IS_VALID_CREDENTIAL_VENDOR_OPTION(x) \\r
- (((UINT32) ((x)[0]) & BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES)) == BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES))\r
-\r
-#define IS_VALID_BOOTITEM_VENDOR_OPTION(x) \\r
- (((UINT32) ((x)[PXEBC_VENDOR_TAG_BOOT_ITEM / 32]) & BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32)) \\r
- == BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32))\r
-\r
-#define IS_DISABLE_BCAST_DISCOVER(x) (((x) & BIT (0)) == BIT (0))\r
-#define IS_DISABLE_MCAST_DISCOVER(x) (((x) & BIT (1)) == BIT (1))\r
-#define IS_ENABLE_USE_SERVER_LIST(x) (((x) & BIT (2)) == BIT (2))\r
-#define IS_DISABLE_PROMPT_MENU(x) (((x) & BIT (3)) == BIT (3))\r
-\r
-#define SET_VENDOR_OPTION_BIT_MAP(x, y) (((x)[(y) / 32]) = (UINT32) ((x)[(y) / 32]) | BIT ((y) % 32))\r
-\r
-#pragma pack(1)\r
-typedef struct {\r
- UINT8 ParaList[135];\r
-} PXEBC_DHCP4_OPTION_PARA;\r
-\r
-typedef struct {\r
- UINT16 Size;\r
-} PXEBC_DHCP4_OPTION_MAX_MESG_SIZE;\r
-\r
-typedef struct {\r
- UINT8 Type;\r
- UINT8 MajorVer;\r
- UINT8 MinorVer;\r
-} PXEBC_DHCP4_OPTION_UNDI;\r
-\r
-typedef struct {\r
- UINT8 Type;\r
-} PXEBC_DHCP4_OPTION_MESG;\r
-\r
-typedef struct {\r
- UINT16 Type;\r
-} PXEBC_DHCP4_OPTION_ARCH;\r
-\r
-#define DEFAULT_CLASS_ID_DATA "PXEClient:Arch:xxxxx:UNDI:003000"\r
-#define DEFAULT_UNDI_TYPE 1\r
-#define DEFAULT_UNDI_MAJOR 3\r
-#define DEFAULT_UNDI_MINOR 0\r
-\r
-typedef struct {\r
- UINT8 ClassIdentifier[10];\r
- UINT8 ArchitecturePrefix[5];\r
- UINT8 ArchitectureType[5];\r
- UINT8 Lit3[1];\r
- UINT8 InterfaceName[4];\r
- UINT8 Lit4[1];\r
- UINT8 UndiMajor[3];\r
- UINT8 UndiMinor[3];\r
-} PXEBC_DHCP4_OPTION_CLID;\r
-\r
-typedef struct {\r
- UINT8 Type;\r
- UINT8 Guid[16];\r
-} PXEBC_DHCP4_OPTION_UUID;\r
-\r
-typedef struct {\r
- UINT16 Type;\r
- UINT16 Layer;\r
-} PXEBC_OPTION_BOOT_ITEM;\r
-\r
-#pragma pack()\r
-\r
-typedef union {\r
- PXEBC_DHCP4_OPTION_PARA *Para;\r
- PXEBC_DHCP4_OPTION_UNDI *Undi;\r
- PXEBC_DHCP4_OPTION_ARCH *Arch;\r
- PXEBC_DHCP4_OPTION_CLID *Clid;\r
- PXEBC_DHCP4_OPTION_UUID *Uuid;\r
- PXEBC_DHCP4_OPTION_MESG *Mesg;\r
- PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize;\r
-} PXEBC_DHCP4_OPTION_ENTRY;\r
-\r
-typedef struct {\r
- UINT16 Type;\r
- UINT8 IpCnt;\r
- EFI_IPv4_ADDRESS IpAddr[1];\r
-} PXEBC_BOOT_SVR_ENTRY;\r
-\r
-typedef struct {\r
- UINT16 Type;\r
- UINT8 DescLen;\r
- UINT8 DescStr[1];\r
-} PXEBC_BOOT_MENU_ENTRY;\r
-\r
-typedef struct {\r
- UINT8 Timeout;\r
- UINT8 Prompt[1];\r
-} PXEBC_MENU_PROMPT;\r
-\r
-typedef struct {\r
- UINT32 BitMap[8];\r
- EFI_IPv4_ADDRESS MtftpIp;\r
- UINT16 MtftpCPort;\r
- UINT16 MtftpSPort;\r
- UINT8 MtftpTimeout;\r
- UINT8 MtftpDelay;\r
- UINT8 DiscoverCtrl;\r
- EFI_IPv4_ADDRESS DiscoverMcastIp;\r
- EFI_IPv4_ADDRESS McastIpBase;\r
- UINT16 McastIpBlock;\r
- UINT16 McastIpRange;\r
- UINT16 BootSrvType;\r
- UINT16 BootSrvLayer;\r
- PXEBC_BOOT_SVR_ENTRY *BootSvr;\r
- UINT8 BootSvrLen;\r
- PXEBC_BOOT_MENU_ENTRY *BootMenu;\r
- UINT8 BootMenuLen;\r
- PXEBC_MENU_PROMPT *MenuPrompt;\r
- UINT8 MenuPromptLen;\r
- UINT32 *CredType;\r
- UINT8 CredTypeLen;\r
-} PXEBC_VENDOR_OPTION;\r
-\r
-#define PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE (OFFSET_OF (EFI_DHCP4_PACKET, Dhcp4) + PXEBC_DHCP4_MAX_PACKET_SIZE)\r
-\r
-typedef union {\r
- EFI_DHCP4_PACKET Offer;\r
- EFI_DHCP4_PACKET Ack;\r
- UINT8 Buffer[PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE];\r
-} PXEBC_DHCP4_PACKET;\r
-\r
-typedef struct {\r
- PXEBC_DHCP4_PACKET Packet;\r
- BOOLEAN IsPxeOffer;\r
- UINT8 OfferType;\r
- EFI_DHCP4_PACKET_OPTION *Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_MAX];\r
- PXEBC_VENDOR_OPTION PxeVendorOption;\r
-} PXEBC_CACHED_DHCP4_PACKET;\r
-\r
-#define GET_NEXT_DHCP_OPTION(Opt) \\r
- (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1)\r
-\r
-#define GET_OPTION_BUFFER_LEN(Pkt) ((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4)\r
-#define IS_PROXY_DHCP_OFFER(Offer) EFI_IP4_EQUAL (&((Offer)->Dhcp4.Header.YourAddr), &mZeroIp4Addr)\r
-\r
-#define GET_NEXT_BOOT_SVR_ENTRY(Ent) \\r
- (PXEBC_BOOT_SVR_ENTRY *) ((UINT8 *) Ent + sizeof (*(Ent)) + ((Ent)->IpCnt - 1) * sizeof (EFI_IPv4_ADDRESS))\r
-\r
-\r
-/**\r
- This function initialize the DHCP4 message instance.\r
-\r
- This function will pad each item of dhcp4 message packet.\r
-\r
- @param Seed Pointer to the message instance of the DHCP4 packet.\r
- @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.\r
-\r
-**/\r
-VOID\r
-PxeBcInitSeedPacket (\r
- IN EFI_DHCP4_PACKET *Seed,\r
- IN EFI_UDP4_PROTOCOL *Udp4\r
- );\r
-\r
-\r
-/**\r
- Parse the cached dhcp packet.\r
-\r
- @param CachedPacket Pointer to cached dhcp packet.\r
-\r
- @retval TRUE Succeed to parse and validation.\r
- @retval FALSE Fail to parse or validation.\r
-\r
-**/\r
-BOOLEAN\r
-PxeBcParseCachedDhcpPacket (\r
- IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket\r
- );\r
-\r
-/**\r
- This function is to check the selected proxy offer (include BINL dhcp offer and\r
- DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe base code\r
- mode structure.\r
-\r
- @param Private Pointer to PxeBc private data.\r
-\r
- @retval EFI_SUCCESS Operational successful.\r
- @retval EFI_NO_RESPONSE Offer dhcp service failed.\r
- @retval EFI_BUFFER_TOO_SMALL Failed to copy the packet to Pxe base code mode.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcCheckSelectedOffer (\r
- IN PXEBC_PRIVATE_DATA *Private\r
- );\r
-\r
-\r
-/**\r
- Callback routine.\r
-\r
- EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protocol driver\r
- to intercept events that occurred in the configuration process. This structure\r
- provides advanced control of each state transition of the DHCP process. The\r
- returned status code determines the behavior of the EFI DHCPv4 Protocol driver.\r
- There are three possible returned values, which are described in the following\r
- table.\r
-\r
- @param This Pointer to the EFI DHCPv4 Protocol instance that is used to\r
- configure this callback function.\r
- @param Context Pointer to the context that is initialized by\r
- EFI_DHCP4_PROTOCOL.Configure().\r
- @param CurrentState The current operational state of the EFI DHCPv4 Protocol\r
- driver.\r
- @param Dhcp4Event The event that occurs in the current state, which usually means a\r
- state transition.\r
- @param Packet The DHCP packet that is going to be sent or already received.\r
- @param NewPacket The packet that is used to replace the above Packet.\r
-\r
- @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to continue the DHCP process.\r
- @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The EFI DHCPv4 Protocol\r
- driver will continue to wait for more DHCPOFFER packets until the retry\r
- timeout expires.\r
- @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to abort the current process and\r
- return to the Dhcp4Init or Dhcp4InitReboot state.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDhcpCallBack (\r
- IN EFI_DHCP4_PROTOCOL * This,\r
- IN VOID *Context,\r
- IN EFI_DHCP4_STATE CurrentState,\r
- IN EFI_DHCP4_EVENT Dhcp4Event,\r
- IN EFI_DHCP4_PACKET * Packet OPTIONAL,\r
- OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL\r
- );\r
-\r
-/**\r
- Switch the Ip4 policy to static.\r
-\r
- @param[in] Private The pointer to PXEBC_PRIVATE_DATA.\r
-\r
- @retval EFI_SUCCESS The policy is already configured to static.\r
- @retval Others Other error as indicated..\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcSetIp4Policy (\r
- IN PXEBC_PRIVATE_DATA *Private\r
- );\r
-\r
-/**\r
- Discover the boot of service and initialize the vendor option if exists.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param Type PxeBc option boot item type\r
- @param Layer PxeBc option boot item layer\r
- @param UseBis Use BIS or not\r
- @param DestIp Ip address for server\r
- @param IpCount The total count of the server ip address\r
- @param SrvList Server list\r
- @param IsDiscv Discover the vendor or not\r
- @param Reply The dhcp4 packet of Pxe reply\r
-\r
- @retval EFI_SUCCESS Operation succeeds.\r
- @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed.\r
- @retval EFI_NOT_FOUND There is no vendor option exists.\r
- @retval EFI_TIMEOUT Send Pxe Discover time out.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcDiscvBootService (\r
- IN PXEBC_PRIVATE_DATA * Private,\r
- IN UINT16 Type,\r
- IN UINT16 *Layer,\r
- IN BOOLEAN UseBis,\r
- IN EFI_IP_ADDRESS * DestIp,\r
- IN UINT16 IpCount,\r
- IN EFI_PXE_BASE_CODE_SRVLIST * SrvList,\r
- IN BOOLEAN IsDiscv,\r
- OUT EFI_DHCP4_PACKET * Reply OPTIONAL\r
- );\r
-\r
-\r
-/**\r
- Initialize the DHCP options and build the option list.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param OptList Pointer to a DHCP option list.\r
-\r
- @param IsDhcpDiscover Discover dhcp option or not.\r
-\r
- @return The index item number of the option list.\r
-\r
-**/\r
-UINT32\r
-PxeBcBuildDhcpOptions (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_DHCP4_PACKET_OPTION **OptList,\r
- IN BOOLEAN IsDhcpDiscover\r
- );\r
-\r
-\r
-/**\r
- Create the boot options.\r
-\r
- @param OptList Pointer to the list of the options\r
- @param Type the type of option\r
- @param Layer the layer of the boot options\r
- @param OptLen length of opotion\r
-\r
-**/\r
-VOID\r
-PxeBcCreateBootOptions (\r
- IN EFI_DHCP4_PACKET_OPTION *OptList,\r
- IN UINT16 Type,\r
- IN UINT16 *Layer,\r
- OUT UINT32 *OptLen\r
- );\r
-\r
-\r
-/**\r
- Parse interested dhcp options.\r
-\r
- @param Buffer Pointer to the dhcp options packet.\r
- @param Length The length of the dhcp options.\r
- @param OptTag The option OpCode.\r
-\r
- @return NULL if the buffer length is 0 and OpCode is not\r
- DHCP4_TAG_EOP, or the pointer to the buffer.\r
-\r
-**/\r
-EFI_DHCP4_PACKET_OPTION *\r
-PxeBcParseExtendOptions (\r
- IN UINT8 *Buffer,\r
- IN UINT32 Length,\r
- IN UINT8 OptTag\r
- );\r
-\r
-\r
-/**\r
- This function is to parse and check vendor options.\r
-\r
- @param Dhcp4Option Pointer to dhcp options\r
- @param VendorOption Pointer to vendor options\r
-\r
- @return TRUE if valid for vendor options, or FALSE.\r
-\r
-**/\r
-BOOLEAN\r
-PxeBcParseVendorOptions (\r
- IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option,\r
- IN PXEBC_VENDOR_OPTION *VendorOption\r
- );\r
-\r
-\r
-/**\r
- Choose the boot prompt.\r
-\r
- @param Private Pointer to PxeBc private data.\r
-\r
- @retval EFI_SUCCESS Select boot prompt done.\r
- @retval EFI_TIMEOUT Select boot prompt time out.\r
- @retval EFI_NOT_FOUND The proxy offer is not Pxe10.\r
- @retval EFI_ABORTED User cancel the operation.\r
- @retval EFI_NOT_READY Read the input key from the keybroad has not finish.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcSelectBootPrompt (\r
- IN PXEBC_PRIVATE_DATA *Private\r
- );\r
-\r
-\r
-/**\r
- Select the boot menu.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param Type The type of the menu.\r
- @param UseDefaultItem Use default item or not.\r
-\r
- @retval EFI_ABORTED User cancel operation.\r
- @retval EFI_SUCCESS Select the boot menu success.\r
- @retval EFI_NOT_READY Read the input key from the keybroad has not finish.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcSelectBootMenu (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- OUT UINT16 *Type,\r
- IN BOOLEAN UseDefaultItem\r
- );\r
-\r
-#endif\r
-\r
+++ /dev/null
-/** @file\r
- The driver binding for UEFI PXEBC protocol.\r
-\r
-Copyright (c) 2007 - 2015, 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
-EFI_DRIVER_BINDING_PROTOCOL gPxeBcDriverBinding = {\r
- PxeBcDriverBindingSupported,\r
- PxeBcDriverBindingStart,\r
- PxeBcDriverBindingStop,\r
- 0xa,\r
- NULL,\r
- NULL\r
-};\r
-\r
-/**\r
- This is the declaration of an EFI image entry point. This entry point is\r
- the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
- both device drivers and bus drivers.\r
-\r
- @param ImageHandle The firmware allocated handle for the UEFI image.\r
- @param SystemTable A pointer to the EFI System Table.\r
-\r
- @retval EFI_SUCCESS The operation completed successfully.\r
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDriverEntryPoint (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
- return EfiLibInstallDriverBindingComponentName2 (\r
- ImageHandle,\r
- SystemTable,\r
- &gPxeBcDriverBinding,\r
- ImageHandle,\r
- &gPxeBcComponentName,\r
- &gPxeBcComponentName2\r
- );\r
-}\r
-\r
-\r
-/**\r
- Test to see if this driver supports ControllerHandle. This service\r
- is called by the EFI boot service ConnectController(). In\r
- order to make drivers as small as possible, there are a few calling\r
- restrictions for this service. ConnectController() must\r
- follow these calling restrictions. If any other agent wishes to call\r
- Supported() it must also follow these calling restrictions.\r
- PxeBc requires DHCP4 and MTFTP4 protocols.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to test\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS This driver supports this device\r
- @retval EFI_ALREADY_STARTED This driver is already running on this device\r
- @retval other This driver does not support this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDriverBindingSupported (\r
- IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
- )\r
-{\r
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
- EFI_STATUS Status;\r
-\r
- Status = gBS->OpenProtocol (\r
- ControllerHandle,\r
- &gEfiPxeBaseCodeProtocolGuid,\r
- (VOID **) &PxeBc,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
-\r
- if (!EFI_ERROR (Status)) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- ControllerHandle,\r
- &gEfiDhcp4ServiceBindingProtocolGuid,\r
- NULL,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
- );\r
-\r
- if (!EFI_ERROR (Status)) {\r
-\r
- Status = gBS->OpenProtocol (\r
- ControllerHandle,\r
- &gEfiMtftp4ServiceBindingProtocolGuid,\r
- NULL,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
- );\r
-\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Start this driver on ControllerHandle. This service is called by the\r
- EFI boot service ConnectController(). In order to make\r
- drivers as small as possible, there are a few calling restrictions for\r
- this service. ConnectController() must follow these\r
- calling restrictions. If any other agent wishes to call Start() it\r
- must also follow these calling restrictions.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to bind driver to\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS This driver is added to ControllerHandle\r
- @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
- @retval other This driver does not support this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDriverBindingStart (\r
- IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- UINTN Index;\r
- EFI_STATUS Status;\r
- EFI_IP4_MODE_DATA Ip4ModeData;\r
-\r
- Private = AllocateZeroPool (sizeof (PXEBC_PRIVATE_DATA));\r
- if (Private == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- Private->Signature = PXEBC_PRIVATE_DATA_SIGNATURE;\r
- Private->Controller = ControllerHandle;\r
- Private->Image = This->DriverBindingHandle;\r
- CopyMem (&Private->PxeBc, &mPxeBcProtocolTemplate, sizeof (Private->PxeBc));\r
- Private->PxeBc.Mode = &Private->Mode;\r
- CopyMem (&Private->LoadFile, &mLoadFileProtocolTemplate, sizeof (Private->LoadFile));\r
-\r
- Private->ProxyOffer.Packet.Offer.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;\r
- Private->Dhcp4Ack.Packet.Ack.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;\r
- Private->PxeReply.Packet.Ack.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;\r
-\r
- for (Index = 0; Index < PXEBC_MAX_OFFER_NUM; Index++) {\r
- Private->Dhcp4Offers[Index].Packet.Offer.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;\r
- }\r
-\r
- //\r
- // Get the NII interface if it exists.\r
- //\r
- Status = gBS->OpenProtocol (\r
- ControllerHandle,\r
- &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
- (VOID **) &Private->Nii,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- Private->Nii = NULL;\r
- }\r
-\r
- Status = NetLibCreateServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiArpServiceBindingProtocolGuid,\r
- &Private->ArpChild\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- Private->ArpChild,\r
- &gEfiArpProtocolGuid,\r
- (VOID **) &Private->Arp,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = NetLibCreateServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiDhcp4ServiceBindingProtocolGuid,\r
- &Private->Dhcp4Child\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- Private->Dhcp4Child,\r
- &gEfiDhcp4ProtocolGuid,\r
- (VOID **) &Private->Dhcp4,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = NetLibCreateServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiIp4ServiceBindingProtocolGuid,\r
- &Private->Ip4Child\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- Private->Ip4Child,\r
- &gEfiIp4ProtocolGuid,\r
- (VOID **) &Private->Ip4,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- //\r
- // Get max packet size from Ip4 to calculate block size for Tftp later.\r
- //\r
- Status = Private->Ip4->GetModeData (Private->Ip4, &Ip4ModeData, NULL, NULL);\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Private->Ip4MaxPacketSize = Ip4ModeData.MaxPacketSize;\r
-\r
- Status = NetLibCreateServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiMtftp4ServiceBindingProtocolGuid,\r
- &Private->Mtftp4Child\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- Private->Mtftp4Child,\r
- &gEfiMtftp4ProtocolGuid,\r
- (VOID **) &Private->Mtftp4,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = NetLibCreateServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiUdp4ServiceBindingProtocolGuid,\r
- &Private->Udp4ReadChild\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- //\r
- // The UDP instance for EfiPxeBcUdpRead\r
- //\r
- Status = gBS->OpenProtocol (\r
- Private->Udp4ReadChild,\r
- &gEfiUdp4ProtocolGuid,\r
- (VOID **) &Private->Udp4Read,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- //\r
- // The UDP instance for EfiPxeBcUdpWrite\r
- //\r
- Status = NetLibCreateServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiUdp4ServiceBindingProtocolGuid,\r
- &Private->Udp4WriteChild\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- Private->Udp4WriteChild,\r
- &gEfiUdp4ProtocolGuid,\r
- (VOID **) &Private->Udp4Write,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
- ZeroMem (&Private->Udp4CfgData, sizeof (EFI_UDP4_CONFIG_DATA));\r
- Private->Udp4CfgData.AcceptBroadcast = FALSE;\r
- Private->Udp4CfgData.AcceptPromiscuous = FALSE;\r
- Private->Udp4CfgData.AcceptAnyPort = TRUE;\r
- Private->Udp4CfgData.AllowDuplicatePort = TRUE;\r
- Private->Udp4CfgData.TypeOfService = DEFAULT_ToS;\r
- Private->Udp4CfgData.TimeToLive = DEFAULT_TTL;\r
- Private->Udp4CfgData.DoNotFragment = FALSE;\r
- Private->Udp4CfgData.ReceiveTimeout = PXEBC_DEFAULT_LIFETIME;\r
- Private->Udp4CfgData.UseDefaultAddress = FALSE;\r
-\r
- PxeBcInitSeedPacket (&Private->SeedPacket, Private->Udp4Read);\r
- Private->MacLen = Private->SeedPacket.Dhcp4.Header.HwAddrLen;\r
- CopyMem (&Private->Mac, &Private->SeedPacket.Dhcp4.Header.ClientHwAddr[0], Private->MacLen);\r
-\r
-\r
- ZeroMem (&Private->Ip4ConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
- Private->Ip4ConfigData.DefaultProtocol = EFI_IP_PROTO_ICMP;\r
- Private->Ip4ConfigData.AcceptIcmpErrors = TRUE;\r
- Private->Ip4ConfigData.TypeOfService = DEFAULT_ToS;\r
- Private->Ip4ConfigData.TimeToLive = DEFAULT_TTL;\r
- Private->Ip4ConfigData.DoNotFragment = FALSE;\r
- Private->Ip4ConfigData.RawData = FALSE;\r
-\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &ControllerHandle,\r
- &gEfiPxeBaseCodeProtocolGuid,\r
- &Private->PxeBc,\r
- &gEfiLoadFileProtocolGuid,\r
- &Private->LoadFile,\r
- NULL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
- //\r
- // Locate Ip4->Ip4Config2 and store it for set IPv4 Policy.\r
- //\r
- Status = gBS->HandleProtocol (\r
- ControllerHandle,\r
- &gEfiIp4Config2ProtocolGuid,\r
- (VOID **) &Private->Ip4Config2\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ON_ERROR;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-\r
-ON_ERROR:\r
-\r
- if (Private->Udp4WriteChild != NULL) {\r
- gBS->CloseProtocol (\r
- Private->Udp4WriteChild,\r
- &gEfiUdp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- ControllerHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiUdp4ServiceBindingProtocolGuid,\r
- Private->Udp4WriteChild\r
- );\r
- }\r
-\r
- if (Private->Udp4ReadChild != NULL) {\r
- gBS->CloseProtocol (\r
- Private->Udp4ReadChild,\r
- &gEfiUdp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- ControllerHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiUdp4ServiceBindingProtocolGuid,\r
- Private->Udp4ReadChild\r
- );\r
- }\r
-\r
- if (Private->Mtftp4Child != NULL) {\r
- gBS->CloseProtocol (\r
- Private->Mtftp4Child,\r
- &gEfiMtftp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- ControllerHandle\r
- );\r
-\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiMtftp4ServiceBindingProtocolGuid,\r
- Private->Mtftp4Child\r
- );\r
- }\r
-\r
- if (Private->Ip4Child != NULL) {\r
- gBS->CloseProtocol (\r
- Private->Ip4Child,\r
- &gEfiIp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- ControllerHandle\r
- );\r
-\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiIp4ServiceBindingProtocolGuid,\r
- Private->Ip4Child\r
- );\r
- }\r
-\r
- if (Private->Dhcp4Child != NULL) {\r
- gBS->CloseProtocol (\r
- Private->Dhcp4Child,\r
- &gEfiDhcp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- ControllerHandle\r
- );\r
-\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiDhcp4ServiceBindingProtocolGuid,\r
- Private->Dhcp4Child\r
- );\r
- }\r
-\r
- if (Private->ArpChild != NULL) {\r
- gBS->CloseProtocol (\r
- Private->ArpChild,\r
- &gEfiArpProtocolGuid,\r
- This->DriverBindingHandle,\r
- ControllerHandle\r
- );\r
-\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiArpServiceBindingProtocolGuid,\r
- Private->ArpChild\r
- );\r
- }\r
-\r
- FreePool (Private);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Stop this driver on ControllerHandle. This service is called by the\r
- EFI boot service DisconnectController(). In order to\r
- make drivers as small as possible, there are a few calling\r
- restrictions for this service. DisconnectController()\r
- must follow these calling restrictions. If any other agent wishes\r
- to call Stop() it must also follow these calling restrictions.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to stop driver on\r
- @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
- children is zero stop the entire bus driver.\r
- @param ChildHandleBuffer List of Child Handles to Stop.\r
-\r
- @retval EFI_SUCCESS This driver is removed ControllerHandle\r
- @retval other This driver was not removed from this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDriverBindingStop (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN UINTN NumberOfChildren,\r
- IN EFI_HANDLE *ChildHandleBuffer\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
- EFI_HANDLE NicHandle;\r
- EFI_STATUS Status;\r
-\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiArpProtocolGuid);\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiMtftp4ProtocolGuid);\r
-\r
- if (NicHandle == NULL) {\r
- return EFI_SUCCESS;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- Status = gBS->OpenProtocol (\r
- NicHandle,\r
- &gEfiPxeBaseCodeProtocolGuid,\r
- (VOID **) &PxeBc,\r
- This->DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Stop functionality of PXE Base Code protocol\r
- //\r
- Status = PxeBc->Stop (PxeBc);\r
- if (Status != EFI_SUCCESS && Status != EFI_NOT_STARTED) {\r
- return Status;\r
- }\r
-\r
- Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (PxeBc);\r
-\r
- Status = gBS->UninstallMultipleProtocolInterfaces (\r
- NicHandle,\r
- &gEfiPxeBaseCodeProtocolGuid,\r
- &Private->PxeBc,\r
- &gEfiLoadFileProtocolGuid,\r
- &Private->LoadFile,\r
- NULL\r
- );\r
-\r
- if (!EFI_ERROR (Status)) {\r
-\r
- gBS->CloseProtocol (\r
- Private->Udp4WriteChild,\r
- &gEfiUdp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- NicHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- This->DriverBindingHandle,\r
- &gEfiUdp4ServiceBindingProtocolGuid,\r
- Private->Udp4WriteChild\r
- );\r
-\r
- gBS->CloseProtocol (\r
- Private->Udp4ReadChild,\r
- &gEfiUdp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- NicHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- NicHandle,\r
- This->DriverBindingHandle,\r
- &gEfiUdp4ServiceBindingProtocolGuid,\r
- Private->Udp4ReadChild\r
- );\r
-\r
- gBS->CloseProtocol (\r
- Private->Dhcp4Child,\r
- &gEfiDhcp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- NicHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- NicHandle,\r
- This->DriverBindingHandle,\r
- &gEfiDhcp4ServiceBindingProtocolGuid,\r
- Private->Dhcp4Child\r
- );\r
-\r
- gBS->CloseProtocol (\r
- Private->Mtftp4Child,\r
- &gEfiMtftp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- NicHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- NicHandle,\r
- This->DriverBindingHandle,\r
- &gEfiMtftp4ServiceBindingProtocolGuid,\r
- Private->Mtftp4Child\r
- );\r
-\r
- gBS->CloseProtocol (\r
- Private->Ip4Child,\r
- &gEfiIp4ProtocolGuid,\r
- This->DriverBindingHandle,\r
- NicHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- NicHandle,\r
- This->DriverBindingHandle,\r
- &gEfiIp4ServiceBindingProtocolGuid,\r
- Private->Ip4Child\r
- );\r
-\r
- gBS->CloseProtocol (\r
- Private->ArpChild,\r
- &gEfiArpProtocolGuid,\r
- This->DriverBindingHandle,\r
- NicHandle\r
- );\r
- NetLibDestroyServiceChild (\r
- NicHandle,\r
- This->DriverBindingHandle,\r
- &gEfiArpServiceBindingProtocolGuid,\r
- Private->ArpChild\r
- );\r
-\r
- FreePool (Private);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
+++ /dev/null
-/** @file\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
-#ifndef __EFI_PXEBC_DRIVER_H__\r
-#define __EFI_PXEBC_DRIVER_H__\r
-\r
-/**\r
- Test to see if this driver supports ControllerHandle. This service\r
- is called by the EFI boot service ConnectController(). In\r
- order to make drivers as small as possible, there are a few calling\r
- restrictions for this service. ConnectController() must\r
- follow these calling restrictions. If any other agent wishes to call\r
- Supported() it must also follow these calling restrictions.\r
- PxeBc requires DHCP4 and MTFTP4 protocols.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to test\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS This driver supports this device\r
- @retval EFI_ALREADY_STARTED This driver is already running on this device\r
- @retval other This driver does not support this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDriverBindingSupported (\r
- IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
- );\r
-\r
-/**\r
- Start this driver on ControllerHandle. This service is called by the\r
- EFI boot service ConnectController(). In order to make\r
- drivers as small as possible, there are a few calling restrictions for\r
- this service. ConnectController() must follow these\r
- calling restrictions. If any other agent wishes to call Start() it\r
- must also follow these calling restrictions.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to bind driver to\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS This driver is added to ControllerHandle\r
- @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
- @retval other This driver does not support this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDriverBindingStart (\r
- IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
- );\r
-\r
-/**\r
- Stop this driver on ControllerHandle. This service is called by the\r
- EFI boot service DisconnectController(). In order to\r
- make drivers as small as possible, there are a few calling\r
- restrictions for this service. DisconnectController()\r
- must follow these calling restrictions. If any other agent wishes\r
- to call Stop() it must also follow these calling restrictions.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to stop driver on\r
- @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
- children is zero stop the entire bus driver.\r
- @param ChildHandleBuffer List of Child Handles to Stop.\r
-\r
- @retval EFI_SUCCESS This driver is removed ControllerHandle\r
- @retval other This driver was not removed from this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcDriverBindingStop (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN UINTN NumberOfChildren,\r
- IN EFI_HANDLE *ChildHandleBuffer\r
- );\r
-\r
-extern EFI_COMPONENT_NAME2_PROTOCOL gPxeBcComponentName2;\r
-extern EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName;\r
-extern EFI_DRIVER_BINDING_PROTOCOL gPxeBcDriverBinding;\r
-\r
-#endif\r
-\r
+++ /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
+++ /dev/null
-/** @file\r
-\r
-Copyright (c) 2007 - 2016, 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
-#ifndef __EFI_PXEBC_IMPL_H__\r
-#define __EFI_PXEBC_IMPL_H__\r
-\r
-\r
-typedef struct _PXEBC_PRIVATE_DATA PXEBC_PRIVATE_DATA;\r
-\r
-#include <Uefi.h>\r
-\r
-#include <Guid/SmBios.h>\r
-#include <IndustryStandard/SmBios.h>\r
-#include <IndustryStandard/Dhcp.h>\r
-#include <Protocol/Dhcp4.h>\r
-#include <Protocol/PxeBaseCode.h>\r
-#include <Protocol/Mtftp4.h>\r
-#include <Protocol/Udp4.h>\r
-#include <Protocol/LoadFile.h>\r
-#include <Protocol/NetworkInterfaceIdentifier.h>\r
-#include <Protocol/PxeBaseCodeCallBack.h>\r
-#include <Protocol/Arp.h>\r
-#include <Protocol/Ip4.h>\r
-#include <Protocol/Ip4Config2.h>\r
-\r
-#include <Library/DebugLib.h>\r
-#include <Library/DevicePathLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/NetLib.h>\r
-#include <Library/DpcLib.h>\r
-#include <Library/PcdLib.h>\r
-\r
-#include "PxeBcDriver.h"\r
-#include "PxeBcDhcp.h"\r
-#include "PxeBcMtftp.h"\r
-#include "PxeBcSupport.h"\r
-\r
-#define PXEBC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'X', 'E', 'P')\r
-#define PXEBC_MTFTP_TIMEOUT 4\r
-#define PXEBC_MTFTP_RETRIES 6\r
-#define PXEBC_DEFAULT_UDP_OVERHEAD_SIZE 8\r
-#define PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE 4\r
-#define PXEBC_DEFAULT_PACKET_SIZE 1480\r
-#define PXEBC_DEFAULT_LIFETIME 50000 // 50ms, unit is microsecond\r
-#define PXEBC_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)\r
-\r
-struct _PXEBC_PRIVATE_DATA {\r
- UINT32 Signature;\r
- EFI_HANDLE Controller;\r
- EFI_HANDLE Image;\r
- EFI_HANDLE ArpChild;\r
- EFI_HANDLE Dhcp4Child;\r
- EFI_HANDLE Ip4Child;\r
- EFI_HANDLE Mtftp4Child;\r
- EFI_HANDLE Udp4ReadChild;\r
- EFI_HANDLE Udp4WriteChild;\r
-\r
- EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;\r
-\r
- EFI_PXE_BASE_CODE_PROTOCOL PxeBc;\r
- EFI_LOAD_FILE_PROTOCOL LoadFile;\r
- EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL LoadFileCallback;\r
- EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *PxeBcCallback;\r
- EFI_ARP_PROTOCOL *Arp;\r
- EFI_DHCP4_PROTOCOL *Dhcp4;\r
- EFI_IP4_PROTOCOL *Ip4;\r
- EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2;\r
- EFI_IP4_CONFIG_DATA Ip4ConfigData;\r
- EFI_MTFTP4_PROTOCOL *Mtftp4;\r
- EFI_UDP4_PROTOCOL *Udp4Read;\r
- EFI_UDP4_PROTOCOL *Udp4Write;\r
- UINT16 CurrentUdpSrcPort;\r
- EFI_UDP4_CONFIG_DATA Udp4CfgData;\r
-\r
-\r
- EFI_PXE_BASE_CODE_MODE Mode;\r
- EFI_PXE_BASE_CODE_FUNCTION Function;\r
-\r
- CHAR8 *BootFileName;\r
-\r
- EFI_IP_ADDRESS StationIp;\r
- EFI_IP_ADDRESS SubnetMask;\r
- EFI_IP_ADDRESS GatewayIp;\r
- EFI_IP_ADDRESS ServerIp;\r
- BOOLEAN AddressIsOk;\r
- UINT32 Ip4MaxPacketSize;\r
- UINTN BlockSize;\r
- UINTN FileSize;\r
-\r
- UINT8 OptionBuffer[PXEBC_DHCP4_MAX_OPTION_SIZE];\r
- EFI_DHCP4_PACKET SeedPacket;\r
- EFI_MAC_ADDRESS Mac;\r
- UINT8 MacLen;\r
-\r
- BOOLEAN SortOffers;\r
- BOOLEAN GotProxyOffer;\r
- UINT32 NumOffers;\r
- UINT32 SelectedOffer;\r
- UINT32 ProxyOfferType;\r
-\r
- //\r
- // Cached packets as complements of pxe mode data\r
- //\r
- PXEBC_CACHED_DHCP4_PACKET ProxyOffer;\r
- PXEBC_CACHED_DHCP4_PACKET Dhcp4Ack;\r
- PXEBC_CACHED_DHCP4_PACKET PxeReply;\r
- PXEBC_CACHED_DHCP4_PACKET Dhcp4Offers[PXEBC_MAX_OFFER_NUM];\r
-\r
- //\r
- // Arrays for different types of offers:\r
- // ServerCount records the count of the servers we got the offers,\r
- // OfferIndex records the index of the offer sent by the server indexed by ServerCount.\r
- //\r
- UINT32 ServerCount[DHCP4_PACKET_TYPE_MAX];\r
- UINT32 OfferIndex[DHCP4_PACKET_TYPE_MAX][PXEBC_MAX_OFFER_NUM];\r
- UINT32 BootpIndex;\r
- UINT32 ProxyIndex[DHCP4_PACKET_TYPE_MAX];\r
- UINT32 BinlIndex[PXEBC_MAX_OFFER_NUM];\r
-\r
- EFI_EVENT GetArpCacheEvent;\r
- //\r
- // token and event used to get ICMP error data from IP\r
- //\r
- EFI_IP4_COMPLETION_TOKEN IcmpErrorRcvToken;\r
-};\r
-\r
-#define PXEBC_PRIVATE_DATA_FROM_PXEBC(a) CR (a, PXEBC_PRIVATE_DATA, PxeBc, PXEBC_PRIVATE_DATA_SIGNATURE)\r
-\r
-#define PXEBC_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, PXEBC_PRIVATE_DATA, LoadFile, PXEBC_PRIVATE_DATA_SIGNATURE)\r
-\r
-#define PXEBC_PRIVATE_DATA_FROM_PXEBCCALLBACK(a) CR (a, PXEBC_PRIVATE_DATA, PxeBcCallback, PXEBC_PRIVATE_DATA_SIGNATURE)\r
-\r
-extern EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate;\r
-extern EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate;\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
-#endif\r
+++ /dev/null
-/** @file\r
- PxeBc MTFTP functions.\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
-#include "PxeBcImpl.h"\r
-\r
-CHAR8 *mMtftpOptions[PXE_MTFTP_OPTION_MAXIMUM_INDEX] = {\r
- "blksize",\r
- "timeout",\r
- "tsize",\r
- "multicast"\r
-};\r
-\r
-\r
-/**\r
- This is a callback function when packets received/transmitted in Mtftp driver.\r
-\r
- A callback function that is provided by the caller to intercept\r
- the EFI_MTFTP4_OPCODE_DATA or EFI_MTFTP4_OPCODE_DATA8 packets processed in the\r
- EFI_MTFTP4_PROTOCOL.ReadFile() function, and alternatively to intercept\r
- EFI_MTFTP4_OPCODE_OACK or EFI_MTFTP4_OPCODE_ERROR packets during a call to\r
- EFI_MTFTP4_PROTOCOL.ReadFile(), WriteFile() or ReadDirectory().\r
-\r
- @param This Pointer to Mtftp protocol instance\r
- @param Token Pointer to Mtftp token\r
- @param PacketLen Length of Mtftp packet\r
- @param Packet Pointer to Mtftp packet\r
-\r
- @retval EFI_SUCCESS Operation sucess\r
- @retval EFI_ABORTED Abort transfer process\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PxeBcCheckPacket (\r
- IN EFI_MTFTP4_PROTOCOL *This,\r
- IN EFI_MTFTP4_TOKEN *Token,\r
- IN UINT16 PacketLen,\r
- IN EFI_MTFTP4_PACKET *Packet\r
- )\r
-{\r
- PXEBC_PRIVATE_DATA *Private;\r
- EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;\r
- EFI_STATUS Status;\r
-\r
- Private = (PXEBC_PRIVATE_DATA *) Token->Context;\r
- Callback = Private->PxeBcCallback;\r
- Status = EFI_SUCCESS;\r
-\r
- if (Packet->OpCode == EFI_MTFTP4_OPCODE_ERROR) {\r
- Private->Mode.TftpErrorReceived = TRUE;\r
- Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;\r
- AsciiStrnCpyS (Private->Mode.TftpError.ErrorString, PXE_MTFTP_ERROR_STRING_LENGTH, (CHAR8 *) Packet->Error.ErrorMessage, PXE_MTFTP_ERROR_STRING_LENGTH - 1);\r
- Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';\r
- }\r
-\r
- if (Callback != NULL) {\r
-\r
- Status = Callback->Callback (\r
- Callback,\r
- Private->Function,\r
- TRUE,\r
- PacketLen,\r
- (EFI_PXE_BASE_CODE_PACKET *) Packet\r
- );\r
- if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) {\r
-\r
- Status = EFI_ABORTED;\r
- } else {\r
-\r
- Status = EFI_SUCCESS;\r
- }\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- This function is to get size of a file by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data\r
- @param Config Pointer to Mtftp configuration data\r
- @param Filename Pointer to file name\r
- @param BlockSize Pointer to block size\r
- @param BufferSize Pointer to buffer size\r
-\r
- @retval EFI_SUCCESS Get the size of file success\r
- @retval EFI_NOT_FOUND Parse the tftp ptions failed.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval Other Has not get the size of the file.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpGetFileSize (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN UINTN *BlockSize,\r
- IN OUT UINT64 *BufferSize\r
- )\r
-{\r
- EFI_MTFTP4_PROTOCOL *Mtftp4;\r
- EFI_MTFTP4_OPTION ReqOpt[2];\r
- EFI_MTFTP4_PACKET *Packet;\r
- EFI_MTFTP4_OPTION *Option;\r
- UINT32 PktLen;\r
- UINT8 OptBuf[128];\r
- UINT32 OptCnt;\r
- EFI_STATUS Status;\r
-\r
- *BufferSize = 0;\r
- Status = EFI_DEVICE_ERROR;\r
- Mtftp4 = Private->Mtftp4;\r
- Packet = NULL;\r
- Option = NULL;\r
- PktLen = 0;\r
- OptCnt = 1;\r
- Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;\r
-\r
- Status = Mtftp4->Configure (Mtftp4, Config);\r
- if (EFI_ERROR (Status)) {\r
-\r
- return Status;\r
- }\r
-\r
- ReqOpt[0].OptionStr = (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_TSIZE_INDEX];\r
- UtoA10 (0, (CHAR8 *) OptBuf, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);\r
- ReqOpt[0].ValueStr = OptBuf;\r
-\r
- if (BlockSize != NULL) {\r
- ReqOpt[1].OptionStr = (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
- ReqOpt[1].ValueStr = ReqOpt[0].ValueStr + AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1;\r
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[1].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX - (AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1));\r
- OptCnt++;\r
- }\r
-\r
- Status = Mtftp4->GetInfo (\r
- Mtftp4,\r
- NULL,\r
- Filename,\r
- NULL,\r
- (UINT8) OptCnt,\r
- ReqOpt,\r
- &PktLen,\r
- &Packet\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- if (Status == EFI_TFTP_ERROR) {\r
- Private->Mode.TftpErrorReceived = TRUE;\r
- Private->Mode.TftpError.ErrorCode = (UINT8) Packet->Error.ErrorCode;\r
- AsciiStrnCpyS (\r
- Private->Mode.TftpError.ErrorString,\r
- PXE_MTFTP_ERROR_STRING_LENGTH,\r
- (CHAR8 *) Packet->Error.ErrorMessage,\r
- PXE_MTFTP_ERROR_STRING_LENGTH - 1\r
- );\r
- Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1] = '\0';\r
- }\r
- goto ON_ERROR;\r
- }\r
-\r
- OptCnt = 0;\r
-\r
- Status = Mtftp4->ParseOptions (\r
- Mtftp4,\r
- PktLen,\r
- Packet,\r
- (UINT32 *) &OptCnt,\r
- &Option\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
-\r
- goto ON_ERROR;\r
- }\r
-\r
- Status = EFI_NOT_FOUND;\r
-\r
- while (OptCnt != 0) {\r
-\r
- if (AsciiStrnCmp ((CHAR8 *) Option[OptCnt - 1].OptionStr, "tsize", 5) == 0) {\r
-\r
- *BufferSize = AtoU64 (Option[OptCnt - 1].ValueStr);\r
- Status = EFI_SUCCESS;\r
- }\r
-\r
- OptCnt--;\r
- }\r
-\r
- FreePool (Option);\r
-\r
-ON_ERROR:\r
-\r
- if (Packet != NULL) {\r
- FreePool (Packet);\r
- }\r
-\r
- Mtftp4->Configure (Mtftp4, NULL);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- This function is to get data of a file by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data\r
- @param Config Pointer to Mtftp configuration data\r
- @param Filename Pointer to file name\r
- @param BlockSize Pointer to block size\r
- @param BufferPtr Pointer to buffer\r
- @param BufferSize Pointer to buffer size\r
- @param DontUseBuffer Indicate whether with a receive buffer\r
-\r
- @retval EFI_SUCCESS Read the data success from the special file.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval other Read data from file failed.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpReadFile (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN UINTN *BlockSize,\r
- IN UINT8 *BufferPtr,\r
- IN OUT UINT64 *BufferSize,\r
- IN BOOLEAN DontUseBuffer\r
- )\r
-{\r
- EFI_MTFTP4_PROTOCOL *Mtftp4;\r
- EFI_MTFTP4_TOKEN Token;\r
- EFI_MTFTP4_OPTION ReqOpt[1];\r
- UINT32 OptCnt;\r
- UINT8 OptBuf[128];\r
- EFI_STATUS Status;\r
-\r
- Status = EFI_DEVICE_ERROR;\r
- Mtftp4 = Private->Mtftp4;\r
- OptCnt = 0;\r
- Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;\r
-\r
- Status = Mtftp4->Configure (Mtftp4, Config);\r
- if (EFI_ERROR (Status)) {\r
-\r
- return Status;\r
- }\r
-\r
- if (BlockSize != NULL) {\r
-\r
- ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
- ReqOpt[0].ValueStr = OptBuf;\r
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);\r
- OptCnt++;\r
- }\r
-\r
- Token.Event = NULL;\r
- Token.OverrideData = NULL;\r
- Token.Filename = Filename;\r
- Token.ModeStr = NULL;\r
- Token.OptionCount = OptCnt;\r
- Token.OptionList = ReqOpt;\r
- Token.Context = Private;\r
-\r
- if (DontUseBuffer) {\r
- Token.BufferSize = 0;\r
- Token.Buffer = NULL;\r
- } else {\r
- Token.BufferSize = *BufferSize;\r
- Token.Buffer = BufferPtr;\r
- }\r
-\r
- Token.CheckPacket = PxeBcCheckPacket;\r
- Token.TimeoutCallback = NULL;\r
- Token.PacketNeeded = NULL;\r
-\r
- Status = Mtftp4->ReadFile (Mtftp4, &Token);\r
-\r
- *BufferSize = Token.BufferSize;\r
-\r
- Mtftp4->Configure (Mtftp4, NULL);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- This function is put data of a file by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data\r
- @param Config Pointer to Mtftp configuration data\r
- @param Filename Pointer to file name\r
- @param Overwrite Indicate whether with overwrite attribute\r
- @param BlockSize Pointer to block size\r
- @param BufferPtr Pointer to buffer\r
- @param BufferSize Pointer to buffer size\r
-\r
- @retval EFI_SUCCESS Write the data success into the special file.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval other Write data into file failed.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpWriteFile (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN BOOLEAN Overwrite,\r
- IN UINTN *BlockSize,\r
- IN UINT8 *BufferPtr,\r
- IN OUT UINT64 *BufferSize\r
- )\r
-{\r
- EFI_MTFTP4_PROTOCOL *Mtftp4;\r
- EFI_MTFTP4_TOKEN Token;\r
- EFI_MTFTP4_OPTION ReqOpt[1];\r
- UINT32 OptCnt;\r
- UINT8 OptBuf[128];\r
- EFI_STATUS Status;\r
-\r
- Status = EFI_DEVICE_ERROR;\r
- Mtftp4 = Private->Mtftp4;\r
- OptCnt = 0;\r
- Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;\r
-\r
- Status = Mtftp4->Configure (Mtftp4, Config);\r
- if (EFI_ERROR (Status)) {\r
-\r
- return Status;\r
- }\r
-\r
- if (BlockSize != NULL) {\r
-\r
- ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
- ReqOpt[0].ValueStr = OptBuf;\r
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);\r
- OptCnt++;\r
- }\r
-\r
- Token.Event = NULL;\r
- Token.OverrideData = NULL;\r
- Token.Filename = Filename;\r
- Token.ModeStr = NULL;\r
- Token.OptionCount = OptCnt;\r
- Token.OptionList = ReqOpt;\r
- Token.BufferSize = *BufferSize;\r
- Token.Buffer = BufferPtr;\r
- Token.CheckPacket = PxeBcCheckPacket;\r
- Token.TimeoutCallback = NULL;\r
- Token.PacketNeeded = NULL;\r
-\r
- Status = Mtftp4->WriteFile (Mtftp4, &Token);\r
- *BufferSize = Token.BufferSize;\r
-\r
- Mtftp4->Configure (Mtftp4, NULL);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- This function is to get data(file) from a directory(may be a server) by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param Config Pointer to Mtftp configuration data.\r
- @param Filename Pointer to file name.\r
- @param BlockSize Pointer to block size.\r
- @param BufferPtr Pointer to buffer.\r
- @param BufferSize Pointer to buffer size.\r
- @param DontUseBuffer Indicate whether with a receive buffer.\r
-\r
- @retval EFI_SUCCES Get the data from the file included in directory success.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval other Operation failed.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpReadDirectory (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN UINTN *BlockSize,\r
- IN UINT8 *BufferPtr,\r
- IN OUT UINT64 *BufferSize,\r
- IN BOOLEAN DontUseBuffer\r
- )\r
-{\r
- EFI_MTFTP4_PROTOCOL *Mtftp4;\r
- EFI_MTFTP4_TOKEN Token;\r
- EFI_MTFTP4_OPTION ReqOpt[1];\r
- UINT32 OptCnt;\r
- UINT8 OptBuf[128];\r
- EFI_STATUS Status;\r
-\r
- Status = EFI_DEVICE_ERROR;\r
- Mtftp4 = Private->Mtftp4;\r
- OptCnt = 0;\r
- Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;\r
-\r
- Status = Mtftp4->Configure (Mtftp4, Config);\r
- if (EFI_ERROR (Status)) {\r
-\r
- return Status;\r
- }\r
-\r
- if (BlockSize != NULL) {\r
-\r
- ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
- ReqOpt[0].ValueStr = OptBuf;\r
- UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAXNUM_INDEX);\r
- OptCnt++;\r
- }\r
-\r
- Token.Event = NULL;\r
- Token.OverrideData = NULL;\r
- Token.Filename = Filename;\r
- Token.ModeStr = NULL;\r
- Token.OptionCount = OptCnt;\r
- Token.OptionList = ReqOpt;\r
- Token.Context = Private;\r
-\r
- if (DontUseBuffer) {\r
- Token.BufferSize = 0;\r
- Token.Buffer = NULL;\r
- } else {\r
- Token.BufferSize = *BufferSize;\r
- Token.Buffer = BufferPtr;\r
- }\r
-\r
- Token.CheckPacket = PxeBcCheckPacket;\r
- Token.TimeoutCallback = NULL;\r
- Token.PacketNeeded = NULL;\r
-\r
- Status = Mtftp4->ReadDirectory (Mtftp4, &Token);\r
-\r
- *BufferSize = Token.BufferSize;\r
-\r
- Mtftp4->Configure (Mtftp4, NULL);\r
-\r
- return Status;\r
-}\r
-\r
+++ /dev/null
-/** @file\r
- Mtftp 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
-#ifndef __EFI_PXEBC_MTFTP_H__\r
-#define __EFI_PXEBC_MTFTP_H__\r
-\r
-#define PXE_MTFTP_OPTION_BLKSIZE_INDEX 0\r
-#define PXE_MTFTP_OPTION_TIMEOUT_INDEX 1\r
-#define PXE_MTFTP_OPTION_TSIZE_INDEX 2\r
-#define PXE_MTFTP_OPTION_MULTICAST_INDEX 3\r
-#define PXE_MTFTP_OPTION_MAXIMUM_INDEX 4\r
-\r
-#define PXE_MTFTP_ERROR_STRING_LENGTH 127\r
-#define PXE_MTFTP_OPTBUF_MAXNUM_INDEX 128\r
-\r
-\r
-/**\r
- This function is to get size of a file by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data\r
- @param Config Pointer to Mtftp configuration data\r
- @param Filename Pointer to file name\r
- @param BlockSize Pointer to block size\r
- @param BufferSize Pointer to buffer size\r
-\r
- @retval EFI_SUCCESS Get the size of file success\r
- @retval EFI_NOT_FOUND Parse the tftp ptions failed.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval Other Has not get the size of the file.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpGetFileSize (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN UINTN *BlockSize,\r
- IN OUT UINT64 *BufferSize\r
- );\r
-\r
-\r
-/**\r
- This function is to get data of a file by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data\r
- @param Config Pointer to Mtftp configuration data\r
- @param Filename Pointer to file name\r
- @param BlockSize Pointer to block size\r
- @param BufferPtr Pointer to buffer\r
- @param BufferSize Pointer to buffer size\r
- @param DontUseBuffer Indicate whether with a receive buffer\r
-\r
- @retval EFI_SUCCESS Read the data success from the special file.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval other Read data from file failed.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpReadFile (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN UINTN *BlockSize,\r
- IN UINT8 *BufferPtr,\r
- IN OUT UINT64 *BufferSize,\r
- IN BOOLEAN DontUseBuffer\r
- );\r
-\r
-\r
-/**\r
- This function is put data of a file by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data\r
- @param Config Pointer to Mtftp configuration data\r
- @param Filename Pointer to file name\r
- @param Overwrite Indicate whether with overwrite attribute\r
- @param BlockSize Pointer to block size\r
- @param BufferPtr Pointer to buffer\r
- @param BufferSize Pointer to buffer size\r
-\r
- @retval EFI_SUCCESS Write the data success into the special file.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval other Write data into file failed.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpWriteFile (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN BOOLEAN Overwrite,\r
- IN UINTN *BlockSize,\r
- IN UINT8 *BufferPtr,\r
- IN OUT UINT64 *BufferSize\r
- );\r
-\r
-\r
-/**\r
- This function is to get data(file) from a directory(may be a server) by Tftp.\r
-\r
- @param Private Pointer to PxeBc private data.\r
- @param Config Pointer to Mtftp configuration data.\r
- @param Filename Pointer to file name.\r
- @param BlockSize Pointer to block size.\r
- @param BufferPtr Pointer to buffer.\r
- @param BufferSize Pointer to buffer size.\r
- @param DontUseBuffer Indicate whether with a receive buffer.\r
-\r
- @retval EFI_SUCCES Get the data from the file included in directory success.\r
- @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r
- @retval other Operation failed.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcTftpReadDirectory (\r
- IN PXEBC_PRIVATE_DATA *Private,\r
- IN EFI_MTFTP4_CONFIG_DATA *Config,\r
- IN UINT8 *Filename,\r
- IN UINTN *BlockSize,\r
- IN UINT8 *BufferPtr,\r
- IN OUT UINT64 *BufferSize,\r
- IN BOOLEAN DontUseBuffer\r
- );\r
-\r
-#endif\r
-\r
+++ /dev/null
-/** @file\r
- Support 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
-\r
-/**\r
- The common notify function associated with various PxeBc events.\r
-\r
- @param Event The event signaled.\r
- @param Context The context.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PxeBcCommonNotify (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- *((BOOLEAN *) Context) = TRUE;\r
-}\r
-\r
-\r
-/**\r
- This function initialize(or configure) the Udp4Write instance.\r
-\r
- @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.\r
- @param StationIp Pointer to the station ip address.\r
- @param SubnetMask Pointer to the subnetmask of the station ip address.\r
- @param Gateway Pointer to the gateway ip address.\r
- @param SrcPort Pointer to the srouce port of the station.\r
- @param Ttl The time to live field of the IP header.\r
- @param ToS The type of service field of the IP header.\r
-\r
- @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.\r
- @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,\r
- RARP, etc.) is not finished yet.\r
- @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r
- @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured\r
- and must be stopped/reset before it can be reconfigured.\r
- @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE\r
- and UdpConfigData.StationPort is already used by\r
- other instance.\r
- @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this\r
- EFI UDPv4 Protocol instance.\r
- @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance\r
- was not opened.\r
- @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcConfigureUdpWriteInstance (\r
- IN EFI_UDP4_PROTOCOL *Udp4,\r
- IN EFI_IPv4_ADDRESS *StationIp,\r
- IN EFI_IPv4_ADDRESS *SubnetMask,\r
- IN EFI_IPv4_ADDRESS *Gateway,\r
- IN OUT UINT16 *SrcPort,\r
- IN UINT8 Ttl,\r
- IN UINT8 ToS\r
- )\r
-{\r
- EFI_UDP4_CONFIG_DATA Udp4CfgData;\r
- EFI_STATUS Status;\r
-\r
- ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r
-\r
- Udp4CfgData.ReceiveTimeout = PXEBC_DEFAULT_LIFETIME;\r
- Udp4CfgData.TypeOfService = ToS;\r
- Udp4CfgData.TimeToLive = Ttl;\r
- Udp4CfgData.AllowDuplicatePort = TRUE;\r
-\r
- CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r
- CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask));\r
-\r
- Udp4CfgData.StationPort = *SrcPort;\r
-\r
- //\r
- // Reset the instance.\r
- //\r
- Udp4->Configure (Udp4, NULL);\r
-\r
- Status = Udp4->Configure (Udp4, &Udp4CfgData);\r
- if (!EFI_ERROR (Status) && (Gateway->Addr[0] != 0)) {\r
- //\r
- // basic configuration OK, need to add the default route entry\r
- //\r
- Status = Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway);\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // roll back\r
- //\r
- Udp4->Configure (Udp4, NULL);\r
- }\r
- }\r
-\r
- if (!EFI_ERROR (Status) && (*SrcPort == 0)) {\r
- Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL);\r
- *SrcPort = Udp4CfgData.StationPort;\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- This function is to display the IPv4 address.\r
-\r
- @param[in] Ip The pointer to the IPv4 address.\r
-\r
-**/\r
-VOID\r
-PxeBcShowIp4Addr (\r
- IN EFI_IPv4_ADDRESS *Ip\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < 4; Index++) {\r
- AsciiPrint ("%d", Ip->Addr[Index]);\r
- if (Index < 3) {\r
- AsciiPrint (".");\r
- }\r
- }\r
-}\r
-\r
-/**\r
- Convert number to ASCII value.\r
-\r
- @param Number Numeric value to convert to decimal ASCII value.\r
- @param Buffer Buffer to place ASCII version of the Number.\r
- @param Length Length of Buffer.\r
-\r
-**/\r
-VOID\r
-CvtNum (\r
- IN UINTN Number,\r
- IN UINT8 *Buffer,\r
- IN UINTN Length\r
- )\r
-{\r
- UINTN Remainder;\r
-\r
- for (; Length > 0; Length--) {\r
- Remainder = Number % 10;\r
- Number /= 10;\r
- Buffer[Length - 1] = (UINT8) ('0' + Remainder);\r
- }\r
-}\r
-\r
-\r
-/**\r
- Convert unsigned int number to decimal number.\r
-\r
- @param Number The unsigned int number will be converted.\r
- @param Buffer Pointer to the buffer to store the decimal number after transform.\r
- @param[in] BufferSize The maxsize of the buffer.\r
-\r
- @return the length of the number after transform.\r
-\r
-**/\r
-UINTN\r
-UtoA10 (\r
- IN UINTN Number,\r
- IN CHAR8 *Buffer,\r
- IN UINTN BufferSize\r
- )\r
-{\r
- UINTN Index;\r
- CHAR8 TempStr[64];\r
-\r
- Index = 63;\r
- TempStr[Index] = 0;\r
-\r
- do {\r
- Index--;\r
- TempStr[Index] = (CHAR8) ('0' + (Number % 10));\r
- Number = Number / 10;\r
- } while (Number != 0);\r
-\r
- AsciiStrCpyS (Buffer, BufferSize, &TempStr[Index]);\r
-\r
- return AsciiStrLen (Buffer);\r
-}\r
-\r
-\r
-/**\r
- Convert ASCII numeric string to a UINTN value.\r
-\r
- @param Buffer Pointer to the 8-byte unsigned int value.\r
-\r
- @return UINTN value of the ASCII string.\r
-\r
-**/\r
-UINT64\r
-AtoU64 (\r
- IN UINT8 *Buffer\r
- )\r
-{\r
- UINT64 Value;\r
- UINT8 Character;\r
-\r
- Value = 0;\r
- while ((Character = *Buffer++) != '\0') {\r
- Value = MultU64x32 (Value, 10) + (Character - '0');\r
- }\r
-\r
- return Value;\r
-}\r
-\r
+++ /dev/null
-/** @file\r
- Support routines for PxeBc.\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
-#ifndef __EFI_PXEBC_SUPPORT_H__\r
-#define __EFI_PXEBC_SUPPORT_H__\r
-\r
-\r
-/**\r
- The common notify function associated with various PxeBc events.\r
-\r
- @param Event The event signaled.\r
- @param Context The context.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PxeBcCommonNotify (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- );\r
-\r
-\r
-/**\r
- This function initialize(or configure) the Udp4Write instance.\r
-\r
- @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.\r
- @param StationIp Pointer to the station ip address.\r
- @param SubnetMask Pointer to the subnetmask of the station ip address.\r
- @param Gateway Pointer to the gateway ip address.\r
- @param SrcPort Pointer to the srouce port of the station.\r
- @param Ttl The time to live field of the IP header.\r
- @param ToS The type of service field of the IP header.\r
-\r
- @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.\r
- @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,\r
- RARP, etc.) is not finished yet.\r
- @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r
- @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured\r
- and must be stopped/reset before it can be reconfigured.\r
- @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE\r
- and UdpConfigData.StationPort is already used by\r
- other instance.\r
- @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this\r
- EFI UDPv4 Protocol instance.\r
- @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance\r
- was not opened.\r
- @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeBcConfigureUdpWriteInstance (\r
- IN EFI_UDP4_PROTOCOL *Udp4,\r
- IN EFI_IPv4_ADDRESS *StationIp,\r
- IN EFI_IPv4_ADDRESS *SubnetMask,\r
- IN EFI_IPv4_ADDRESS *Gateway,\r
- IN OUT UINT16 *SrcPort,\r
- IN UINT8 Ttl,\r
- IN UINT8 ToS\r
- );\r
-\r
-\r
-/**\r
- This function is to display the IPv4 address.\r
-\r
- @param[in] Ip The pointer to the IPv4 address.\r
-\r
-**/\r
-VOID\r
-PxeBcShowIp4Addr (\r
- IN EFI_IPv4_ADDRESS *Ip\r
- );\r
-\r
-\r
-/**\r
- Convert number to ASCII value.\r
-\r
- @param Number Numeric value to convert to decimal ASCII value.\r
- @param Buffer Buffer to place ASCII version of the Number.\r
- @param Length Length of Buffer.\r
-\r
-**/\r
-VOID\r
-CvtNum (\r
- IN UINTN Number,\r
- IN UINT8 *Buffer,\r
- IN UINTN Length\r
- );\r
-\r
-\r
-/**\r
- Convert unsigned int number to decimal number.\r
-\r
- @param Number The unsigned int number will be converted.\r
- @param Buffer Pointer to the buffer to store the decimal number after transform.\r
- @param[in] BufferSize The maxsize of the buffer.\r
-\r
- @return the length of the number after transform.\r
-\r
-**/\r
-UINTN\r
-UtoA10 (\r
- IN UINTN Number,\r
- IN CHAR8 *Buffer,\r
- IN UINTN BufferSize\r
-\r
- );\r
-\r
-\r
-/**\r
- Convert ASCII numeric string to a UINTN value.\r
-\r
- @param Buffer Pointer to the 8-byte unsigned int value.\r
-\r
- @return UINTN value of the ASCII string.\r
-\r
-**/\r
-UINT64\r
-AtoU64 (\r
- IN UINT8 *Buffer\r
- );\r
-\r
-\r
-#endif\r
-\r
+++ /dev/null
-// /** @file\r
-// This module produces EFI Preboot Execution Environment (PXE) Base Code Protocol.\r
-//\r
-// This module produces EFI PXE Base Code Protocol upon EFI MMP Protocl and IPv4\r
-// network stack, used to control PXE-compatible devices. It produces EFI Load File\r
-// Protocol to provide one clean way to otain control from the boot manager if the\r
-// boot patch is from the remote device.\r
-//\r
-// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
-//\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
-#string STR_MODULE_ABSTRACT #language en-US "Produces EFI Preboot Execution Environment (PXE) Base Code Protocol"\r
-\r
-#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI PXE Base Code Protocol upon the EFI MMP Protocol and the IPv4 network stack, and is used to control PXE-compatible devices. It produces the EFI Load File Protocol to provide a clean method to obtain control from the boot manager if the boot patch is from the remote device."\r
-\r
+++ /dev/null
-// /** @file\r
-// UefiPxe4BcDxe Localized Strings and Content\r
-//\r
-// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
-//\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
-#string STR_PROPERTIES_MODULE_NAME\r
-#language en-US\r
-"UEFI PXE Base Code DXE Driver"\r
-\r
-\r
+++ /dev/null
-## @file\r
-# This module produces EFI Preboot Execution Environment (PXE) Base Code Protocol.\r
-#\r
-# This module produces EFI PXE Base Code Protocol upon EFI MMP Protocl and IPv4\r
-# network stack, used to control PXE-compatible devices. It produces EFI Load File\r
-# Protocol to provide one clean way to otain control from the boot manager if the\r
-# boot patch is from the remote device. This driver only supports IPv4 network stack.\r
-#\r
-# Notes:\r
-# 1) This driver can't co-work with the UefiPxeBcDxe driver in NetworkPkg.\r
-# 2) This driver might have some issues that have been fixed in the UefiPxeBcDxe\r
-# driver in NetworkPkg.\r
-# 3) This driver supports fewer features than the UefiPxeBcDxe driver in NetworkPkg\r
-# (e.g. IPv6, MTFTP windowsize).\r
-# 4) UefiPxeBcDxe driver in NetworkPkg is recommended for use instead of this one even\r
-# though both of them can be used.\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
-\r
-[Defines]\r
- INF_VERSION = 0x00010005\r
- BASE_NAME = UefiPxe4BcDxe\r
- MODULE_UNI_FILE = UefiPxe4BcDxe.uni\r
- FILE_GUID = 3B1DEAB5-C75D-442e-9238-8E2FFB62B0BB\r
- MODULE_TYPE = UEFI_DRIVER\r
- VERSION_STRING = 1.0\r
- ENTRY_POINT = PxeBcDriverEntryPoint\r
- UNLOAD_IMAGE = NetLibDefaultUnload\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-# VALID_ARCHITECTURES = IA32 X64\r
-#\r
-# DRIVER_BINDING = gPxeBcDriverBinding\r
-# COMPONENT_NAME = gPxeBcComponentName\r
-# COMPONENT_NAME2 = gPxeBcComponentName2\r
-#\r
-\r
-[Sources]\r
- PxeBcMtftp.c\r
- PxeBcSupport.h\r
- PxeBcSupport.c\r
- PxeBcDriver.c\r
- PxeBcDhcp.h\r
- ComponentName.c\r
- PxeBcImpl.c\r
- PxeBcImpl.h\r
- PxeBcDhcp.c\r
- PxeBcMtftp.h\r
- PxeBcDriver.h\r
-\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
-\r
-[LibraryClasses]\r
- BaseLib\r
- UefiLib\r
- UefiBootServicesTableLib\r
- UefiDriverEntryPoint\r
- BaseMemoryLib\r
- MemoryAllocationLib\r
- DebugLib\r
- NetLib\r
- DpcLib\r
- PcdLib\r
-\r
-[Protocols]\r
- gEfiPxeBaseCodeCallbackProtocolGuid ## SOMETIMES_PRODUCES\r
- gEfiPxeBaseCodeProtocolGuid ## BY_START\r
- gEfiLoadFileProtocolGuid ## BY_START\r
- gEfiNetworkInterfaceIdentifierProtocolGuid_31 ## SOMETIMES_CONSUMES\r
- gEfiArpServiceBindingProtocolGuid ## TO_START\r
- gEfiArpProtocolGuid ## TO_START\r
- gEfiMtftp4ServiceBindingProtocolGuid ## TO_START\r
- gEfiMtftp4ProtocolGuid ## TO_START\r
- gEfiUdp4ServiceBindingProtocolGuid ## TO_START\r
- gEfiUdp4ProtocolGuid ## TO_START\r
- gEfiDhcp4ServiceBindingProtocolGuid ## TO_START\r
- gEfiDhcp4ProtocolGuid ## TO_START\r
- gEfiIp4ServiceBindingProtocolGuid ## TO_START\r
- gEfiIp4ProtocolGuid ## TO_START\r
- gEfiIp4Config2ProtocolGuid ## TO_START\r
-\r
-[Pcd]\r
- gEfiMdeModulePkgTokenSpaceGuid.PcdTftpBlockSize ## SOMETIMES_CONSUMES\r
-\r
-[UserExtensions.TianoCore."ExtraFiles"]\r
- UefiPxe4BcDxeExtra.uni\r