X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FUefiPxeBcDxe%2FPxeBcBoot.c;h=f22a151e256dd7efd235d7d8ed78cd50137bc9e1;hb=HEAD;hp=253115308e8159d9f38ef773148b4acace8d7f57;hpb=ae97201c55603b69289c5d2349238ea97b2cd35e;p=mirror_edk2.git
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c b/NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c
index 253115308e..f22a151e25 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c
@@ -1,21 +1,15 @@
/** @file
Boot functions implementation for UefiPxeBc Driver.
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php.
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "PxeBcImpl.h"
-
/**
Display the string of the boot item.
@@ -27,27 +21,26 @@
**/
VOID
PxeBcDisplayBootItem (
- IN UINT8 *Str,
- IN UINT8 Len
+ IN UINT8 *Str,
+ IN UINT8 Len
)
{
- UINT8 Tmp;
+ UINT8 Tmp;
//
// Cut off the chars behind 70th.
//
- Len = (UINT8) MIN (PXEBC_DISPLAY_MAX_LINE, Len);
- Tmp = Str[Len];
- Str[Len] = 0;
+ Len = (UINT8)MIN (PXEBC_DISPLAY_MAX_LINE, Len);
+ Tmp = Str[Len];
+ Str[Len] = 0;
AsciiPrint ("%a \n", Str);
//
// Restore the original 70th char.
//
- Str[Len] = Tmp;
+ Str[Len] = Tmp;
}
-
/**
Select and maintain the boot prompt if needed.
@@ -62,22 +55,22 @@ PxeBcDisplayBootItem (
**/
EFI_STATUS
PxeBcSelectBootPrompt (
- IN PXEBC_PRIVATE_DATA *Private
+ IN PXEBC_PRIVATE_DATA *Private
)
{
- PXEBC_DHCP_PACKET_CACHE *Cache;
- PXEBC_VENDOR_OPTION *VendorOpt;
- EFI_PXE_BASE_CODE_MODE *Mode;
- EFI_EVENT TimeoutEvent;
- EFI_EVENT DescendEvent;
- EFI_INPUT_KEY InputKey;
- EFI_STATUS Status;
- UINT32 OfferType;
- UINT8 Timeout;
- UINT8 *Prompt;
- UINT8 PromptLen;
- INT32 SecCol;
- INT32 SecRow;
+ PXEBC_DHCP_PACKET_CACHE *Cache;
+ PXEBC_VENDOR_OPTION *VendorOpt;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_EVENT TimeoutEvent;
+ EFI_EVENT DescendEvent;
+ EFI_INPUT_KEY InputKey;
+ EFI_STATUS Status;
+ UINT32 OfferType;
+ UINT8 Timeout;
+ UINT8 *Prompt;
+ UINT8 PromptLen;
+ INT32 SecCol;
+ INT32 SecRow;
TimeoutEvent = NULL;
DescendEvent = NULL;
@@ -88,7 +81,7 @@ PxeBcSelectBootPrompt (
//
// Only DhcpPxe10 and ProxyPxe10 offer needs boot prompt.
//
- if (OfferType != PxeOfferTypeProxyPxe10 && OfferType != PxeOfferTypeDhcpPxe10) {
+ if ((OfferType != PxeOfferTypeProxyPxe10) && (OfferType != PxeOfferTypeDhcpPxe10)) {
return EFI_NOT_FOUND;
}
@@ -101,21 +94,22 @@ PxeBcSelectBootPrompt (
//
// According to the PXE specification 2.1, Table 2-1 PXE DHCP Options,
// we must not consider a boot prompt or boot menu if all of the following hold:
- // - the PXE_DISCOVERY_CONTROL tag(6) is present inside the Vendor Options(43), and has bit 3 set
+ // - the PXE_DISCOVERY_CONTROL tag(6) is present inside the Vendor Options(43), and has bit 3 set
// - a boot file name has been presented in the initial DHCP or ProxyDHCP offer packet.
//
if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) &&
- Cache->Dhcp4.OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {
+ (Cache->Dhcp4.OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL))
+ {
return EFI_ABORTED;
}
-
+
if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {
return EFI_TIMEOUT;
}
Timeout = VendorOpt->MenuPrompt->Timeout;
Prompt = VendorOpt->MenuPrompt->Prompt;
- PromptLen = (UINT8) (VendorOpt->MenuPromptLen - 1);
+ PromptLen = (UINT8)(VendorOpt->MenuPromptLen - 1);
//
// The valid scope of Timeout refers to PXE2.1 spec.
@@ -123,6 +117,7 @@ PxeBcSelectBootPrompt (
if (Timeout == 0) {
return EFI_TIMEOUT;
}
+
if (Timeout == 255) {
return EFI_SUCCESS;
}
@@ -144,7 +139,7 @@ PxeBcSelectBootPrompt (
Status = gBS->SetTimer (
TimeoutEvent,
TimerRelative,
- Timeout * TICKS_PER_SECOND
+ MultU64x32 (Timeout, TICKS_PER_SECOND)
);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
@@ -190,46 +185,43 @@ PxeBcSelectBootPrompt (
gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);
AsciiPrint ("(%d) ", Timeout--);
}
+
if (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
gBS->Stall (10 * TICKS_PER_MS);
continue;
}
+
//
// Parse the input key by user.
// If or + is pressed, return success to display the boot menu.
//
if (InputKey.ScanCode == 0) {
-
switch (InputKey.UnicodeChar) {
+ case CTRL ('c'):
+ Status = EFI_ABORTED;
+ break;
- case CTRL ('c'):
- Status = EFI_ABORTED;
- break;
-
- case CTRL ('m'):
- case 'm':
- case 'M':
- Status = EFI_SUCCESS;
- break;
+ case CTRL ('m'):
+ case 'm':
+ case 'M':
+ Status = EFI_SUCCESS;
+ break;
- default:
- continue;
+ default:
+ continue;
}
-
} else {
-
switch (InputKey.ScanCode) {
+ case SCAN_F8:
+ Status = EFI_SUCCESS;
+ break;
- case SCAN_F8:
- Status = EFI_SUCCESS;
- break;
-
- case SCAN_ESC:
- Status = EFI_ABORTED;
- break;
+ case SCAN_ESC:
+ Status = EFI_ABORTED;
+ break;
- default:
- continue;
+ default:
+ continue;
}
}
@@ -239,12 +231,13 @@ PxeBcSelectBootPrompt (
//
// Reset the cursor on the screen.
//
- gST->ConOut->SetCursorPosition (gST->ConOut, 0 , SecRow + 1);
+ gST->ConOut->SetCursorPosition (gST->ConOut, 0, SecRow + 1);
ON_EXIT:
if (DescendEvent != NULL) {
gBS->CloseEvent (DescendEvent);
}
+
if (TimeoutEvent != NULL) {
gBS->CloseEvent (TimeoutEvent);
}
@@ -252,7 +245,6 @@ ON_EXIT:
return Status;
}
-
/**
Select the boot menu by user's input.
@@ -262,31 +254,31 @@ ON_EXIT:
@retval EFI_ABORTED User cancel operation.
@retval EFI_SUCCESS Select the boot menu success.
- @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
+ @retval EFI_NOT_READY Read the input key from the keyboard has not finish.
**/
EFI_STATUS
PxeBcSelectBootMenu (
- IN PXEBC_PRIVATE_DATA *Private,
- OUT UINT16 *Type,
- IN BOOLEAN UseDefaultItem
+ IN PXEBC_PRIVATE_DATA *Private,
+ OUT UINT16 *Type,
+ IN BOOLEAN UseDefaultItem
)
{
- EFI_PXE_BASE_CODE_MODE *Mode;
- PXEBC_DHCP_PACKET_CACHE *Cache;
- PXEBC_VENDOR_OPTION *VendorOpt;
- EFI_INPUT_KEY InputKey;
- UINT32 OfferType;
- UINT8 MenuSize;
- UINT8 MenuNum;
- INT32 TopRow;
- UINT16 Select;
- UINT16 LastSelect;
- UINT8 Index;
- BOOLEAN Finish;
- CHAR8 Blank[PXEBC_DISPLAY_MAX_LINE];
- PXEBC_BOOT_MENU_ENTRY *MenuItem;
- PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MENU_MAX_NUM];
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ PXEBC_DHCP_PACKET_CACHE *Cache;
+ PXEBC_VENDOR_OPTION *VendorOpt;
+ EFI_INPUT_KEY InputKey;
+ UINT32 OfferType;
+ UINT8 MenuSize;
+ UINT8 MenuNum;
+ INT32 TopRow;
+ UINT16 Select;
+ UINT16 LastSelect;
+ UINT8 Index;
+ BOOLEAN Finish;
+ CHAR8 Blank[PXEBC_DISPLAY_MAX_LINE];
+ PXEBC_BOOT_MENU_ENTRY *MenuItem;
+ PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MENU_MAX_NUM];
Finish = FALSE;
Select = 0;
@@ -310,10 +302,10 @@ PxeBcSelectBootMenu (
//
// Display the boot menu on the screen.
//
- SetMem (Blank, sizeof(Blank), ' ');
+ SetMem (Blank, sizeof (Blank), ' ');
- MenuSize = VendorOpt->BootMenuLen;
- MenuItem = VendorOpt->BootMenu;
+ MenuSize = VendorOpt->BootMenuLen;
+ MenuItem = VendorOpt->BootMenu;
if (MenuSize == 0) {
return EFI_DEVICE_ERROR;
@@ -321,9 +313,9 @@ PxeBcSelectBootMenu (
while (MenuSize > 0 && Index < PXEBC_MENU_MAX_NUM) {
ASSERT (MenuItem != NULL);
- MenuArray[Index] = MenuItem;
- MenuSize = (UINT8) (MenuSize - (MenuItem->DescLen + 3));
- MenuItem = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3);
+ MenuArray[Index] = MenuItem;
+ MenuSize = (UINT8)(MenuSize - (MenuItem->DescLen + 3));
+ MenuItem = (PXEBC_BOOT_MENU_ENTRY *)((UINT8 *)MenuItem + MenuItem->DescLen + 3);
Index++;
}
@@ -366,60 +358,62 @@ PxeBcSelectBootMenu (
if (InputKey.ScanCode == 0) {
switch (InputKey.UnicodeChar) {
- case CTRL ('c'):
- InputKey.ScanCode = SCAN_ESC;
- break;
+ case CTRL ('c'):
+ InputKey.ScanCode = SCAN_ESC;
+ break;
- case CTRL ('j'): /* linefeed */
- case CTRL ('m'): /* return */
- Finish = TRUE;
- break;
+ case CTRL ('j'): /* linefeed */
+ case CTRL ('m'): /* return */
+ Finish = TRUE;
+ break;
- case CTRL ('i'): /* tab */
- case ' ':
- case 'd':
- case 'D':
- InputKey.ScanCode = SCAN_DOWN;
- break;
+ case CTRL ('i'): /* tab */
+ case ' ':
+ case 'd':
+ case 'D':
+ InputKey.ScanCode = SCAN_DOWN;
+ break;
- case CTRL ('h'): /* backspace */
- case 'u':
- case 'U':
- InputKey.ScanCode = SCAN_UP;
- break;
+ case CTRL ('h'): /* backspace */
+ case 'u':
+ case 'U':
+ InputKey.ScanCode = SCAN_UP;
+ break;
- default:
- InputKey.ScanCode = 0;
+ default:
+ InputKey.ScanCode = 0;
}
}
switch (InputKey.ScanCode) {
- case SCAN_LEFT:
- case SCAN_UP:
- if (Select != 0) {
- Select--;
- }
- break;
+ case SCAN_LEFT:
+ case SCAN_UP:
+ if (Select != 0) {
+ Select--;
+ }
- case SCAN_DOWN:
- case SCAN_RIGHT:
- if (++Select == MenuNum) {
- Select--;
- }
- break;
+ break;
- case SCAN_PAGE_UP:
- case SCAN_HOME:
- Select = 0;
- break;
+ case SCAN_DOWN:
+ case SCAN_RIGHT:
+ if (++Select == MenuNum) {
+ Select--;
+ }
- case SCAN_PAGE_DOWN:
- case SCAN_END:
- Select = (UINT16) (MenuNum - 1);
- break;
+ break;
- case SCAN_ESC:
- return EFI_ABORTED;
+ case SCAN_PAGE_UP:
+ case SCAN_HOME:
+ Select = 0;
+ break;
+
+ case SCAN_PAGE_DOWN:
+ case SCAN_END:
+ Select = (UINT16)(MenuNum - 1);
+ break;
+
+ case SCAN_ESC:
+ return EFI_ABORTED;
}
//
@@ -446,7 +440,6 @@ PxeBcSelectBootMenu (
return EFI_SUCCESS;
}
-
/**
Parse out the boot information from the last Dhcp4 reply packet.
@@ -459,8 +452,8 @@ PxeBcSelectBootMenu (
**/
EFI_STATUS
PxeBcDhcp4BootInfo (
- IN OUT PXEBC_PRIVATE_DATA *Private,
- OUT UINT64 *BufferSize
+ IN OUT PXEBC_PRIVATE_DATA *Private,
+ OUT UINT64 *BufferSize
)
{
EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
@@ -470,7 +463,7 @@ PxeBcDhcp4BootInfo (
UINT16 Value;
PXEBC_VENDOR_OPTION *VendorOpt;
PXEBC_BOOT_SVR_ENTRY *Entry;
-
+
PxeBc = &Private->PxeBc;
Mode = PxeBc->Mode;
Status = EFI_SUCCESS;
@@ -487,7 +480,20 @@ PxeBcDhcp4BootInfo (
Cache4 = &Private->DhcpAck.Dhcp4;
}
- ASSERT (Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);
+ if (Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL) {
+ //
+ // This should never happen in a correctly configured DHCP / PXE
+ // environment. One misconfiguration that can cause it is two DHCP servers
+ // mistakenly running on the same network segment at the same time, and
+ // racing each other in answering DHCP requests. Thus, the DHCP packets
+ // that the edk2 PXE client considers "belonging together" may actually be
+ // entirely independent, coming from two (competing) DHCP servers.
+ //
+ // Try to deal with this gracefully. Note that this check is not
+ // comprehensive, as we don't try to identify all such errors.
+ //
+ return EFI_PROTOCOL_ERROR;
+ }
//
// Parse the boot server address.
@@ -498,7 +504,7 @@ PxeBcDhcp4BootInfo (
VendorOpt = &Cache4->VendorOpt;
if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) && IS_VALID_BOOT_SERVERS (VendorOpt->BitMap)) {
Entry = VendorOpt->BootSvr;
- if (VendorOpt->BootSvrLen >= sizeof (PXEBC_BOOT_SVR_ENTRY) && Entry->IpCnt > 0) {
+ if ((VendorOpt->BootSvrLen >= sizeof (PXEBC_BOOT_SVR_ENTRY)) && (Entry->IpCnt > 0)) {
CopyMem (
&Private->ServerIp,
&Entry->IpAddr[0],
@@ -506,6 +512,7 @@ PxeBcDhcp4BootInfo (
);
}
}
+
if (Private->ServerIp.Addr[0] == 0) {
//
// ServerIp.Addr[0] equals zero means we failed to get IP address from boot server list.
@@ -517,6 +524,7 @@ PxeBcDhcp4BootInfo (
sizeof (EFI_IPv4_ADDRESS)
);
}
+
if (Private->ServerIp.Addr[0] == 0) {
//
// Still failed , use the IP address from option 54.
@@ -538,7 +546,7 @@ PxeBcDhcp4BootInfo (
// Parse the boot file size by option.
//
CopyMem (&Value, Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN]->Data, sizeof (Value));
- Value = NTOHS (Value);
+ Value = NTOHS (Value);
//
// The field of boot file size is 512 bytes in unit.
//
@@ -564,7 +572,7 @@ PxeBcDhcp4BootInfo (
//
// Save the value of boot file size.
//
- Private->BootFileSize = (UINTN) *BufferSize;
+ Private->BootFileSize = (UINTN)*BufferSize;
//
// Display all the information: boot server address, boot file name and boot file size.
@@ -577,7 +585,6 @@ PxeBcDhcp4BootInfo (
return Status;
}
-
/**
Parse out the boot information from the last Dhcp6 reply packet.
@@ -591,8 +598,8 @@ PxeBcDhcp4BootInfo (
**/
EFI_STATUS
PxeBcDhcp6BootInfo (
- IN OUT PXEBC_PRIVATE_DATA *Private,
- OUT UINT64 *BufferSize
+ IN OUT PXEBC_PRIVATE_DATA *Private,
+ OUT UINT64 *BufferSize
)
{
EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
@@ -617,29 +624,43 @@ PxeBcDhcp6BootInfo (
Cache6 = &Private->DhcpAck.Dhcp6;
}
- ASSERT (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] != NULL);
+ if (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL) {
+ //
+ // This should never happen in a correctly configured DHCP / PXE
+ // environment. One misconfiguration that can cause it is two DHCP servers
+ // mistakenly running on the same network segment at the same time, and
+ // racing each other in answering DHCP requests. Thus, the DHCP packets
+ // that the edk2 PXE client considers "belonging together" may actually be
+ // entirely independent, coming from two (competing) DHCP servers.
+ //
+ // Try to deal with this gracefully. Note that this check is not
+ // comprehensive, as we don't try to identify all such errors.
+ //
+ return EFI_PROTOCOL_ERROR;
+ }
+
+ //
+ // Set the station address to IP layer.
+ //
+ Status = PxeBcSetIp6Address (Private);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
//
// Parse (m)tftp server ip address and bootfile name.
//
Status = PxeBcExtractBootFileUrl (
+ Private,
&Private->BootFileName,
&Private->ServerIp.v6,
- (CHAR8 *) (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->Data),
+ (CHAR8 *)(Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->Data),
NTOHS (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->OpLen)
);
if (EFI_ERROR (Status)) {
return Status;
}
- //
- // Set the station address to IP layer.
- //
- Status = PxeBcSetIp6Address (Private);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
//
// Parse the value of boot file size.
//
@@ -647,10 +668,11 @@ PxeBcDhcp6BootInfo (
//
// Parse it out if have the boot file parameter option.
//
- Status = PxeBcExtractBootFileParam ((CHAR8 *) Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_PARAM]->Data, &Value);
+ Status = PxeBcExtractBootFileParam ((CHAR8 *)Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_PARAM]->Data, &Value);
if (EFI_ERROR (Status)) {
return Status;
}
+
//
// The field of boot file size is 512 bytes in unit.
//
@@ -676,7 +698,7 @@ PxeBcDhcp6BootInfo (
//
// Save the value of boot file size.
//
- Private->BootFileSize = (UINTN) *BufferSize;
+ Private->BootFileSize = (UINTN)*BufferSize;
//
// Display all the information: boot server address, boot file name and boot file size.
@@ -689,7 +711,6 @@ PxeBcDhcp6BootInfo (
return Status;
}
-
/**
Extract the discover information and boot server entry from the
cached packets if unspecified.
@@ -709,17 +730,17 @@ PxeBcExtractDiscoverInfo (
IN PXEBC_PRIVATE_DATA *Private,
IN UINT16 Type,
IN OUT EFI_PXE_BASE_CODE_DISCOVER_INFO **DiscoverInfo,
- OUT PXEBC_BOOT_SVR_ENTRY **BootEntry,
- OUT EFI_PXE_BASE_CODE_SRVLIST **SrvList
+ OUT PXEBC_BOOT_SVR_ENTRY **BootEntry,
+ OUT EFI_PXE_BASE_CODE_SRVLIST **SrvList
)
{
- EFI_PXE_BASE_CODE_MODE *Mode;
- PXEBC_DHCP4_PACKET_CACHE *Cache4;
- PXEBC_VENDOR_OPTION *VendorOpt;
- PXEBC_BOOT_SVR_ENTRY *Entry;
- BOOLEAN IsFound;
- EFI_PXE_BASE_CODE_DISCOVER_INFO *Info;
- UINT16 Index;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ PXEBC_DHCP4_PACKET_CACHE *Cache4;
+ PXEBC_VENDOR_OPTION *VendorOpt;
+ PXEBC_BOOT_SVR_ENTRY *Entry;
+ BOOLEAN IsFound;
+ EFI_PXE_BASE_CODE_DISCOVER_INFO *Info;
+ UINT16 Index;
Mode = Private->PxeBc.Mode;
Info = *DiscoverInfo;
@@ -736,7 +757,7 @@ PxeBcExtractDiscoverInfo (
//
CopyMem (&Info->SrvList[0].IpAddr, &Private->ServerIp, sizeof (EFI_IP_ADDRESS));
- *SrvList = Info->SrvList;
+ *SrvList = Info->SrvList;
} else {
Entry = NULL;
IsFound = FALSE;
@@ -755,8 +776,8 @@ PxeBcExtractDiscoverInfo (
//
Info->UseMCast = (BOOLEAN) !IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);
Info->UseBCast = (BOOLEAN) !IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);
- Info->MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);
- Info->UseUCast = (BOOLEAN) IS_VALID_BOOT_SERVERS (VendorOpt->BitMap);
+ Info->MustUseList = (BOOLEAN)IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);
+ Info->UseUCast = (BOOLEAN)IS_VALID_BOOT_SERVERS (VendorOpt->BitMap);
if (Info->UseMCast) {
//
@@ -770,11 +791,12 @@ PxeBcExtractDiscoverInfo (
if (Info->UseUCast) {
Entry = VendorOpt->BootSvr;
- while (((UINT8) (Entry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {
+ while (((UINT8)(Entry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {
if (Entry->Type == HTONS (Type)) {
IsFound = TRUE;
break;
}
+
Entry = GET_NEXT_BOOT_SVR_ENTRY (Entry);
}
@@ -786,8 +808,9 @@ PxeBcExtractDiscoverInfo (
if (Info->IpCnt >= 1) {
*DiscoverInfo = AllocatePool (sizeof (*Info) + (Info->IpCnt - 1) * sizeof (**SrvList));
if (*DiscoverInfo == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
+ return EFI_OUT_OF_RESOURCES;
+ }
+
CopyMem (*DiscoverInfo, Info, sizeof (*Info));
Info = *DiscoverInfo;
}
@@ -795,7 +818,7 @@ PxeBcExtractDiscoverInfo (
for (Index = 0; Index < Info->IpCnt; Index++) {
CopyMem (&Info->SrvList[Index].IpAddr, &Entry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));
Info->SrvList[Index].AcceptAnyResponse = !Info->MustUseList;
- Info->SrvList[Index].Type = NTOHS (Entry->Type);
+ Info->SrvList[Index].Type = NTOHS (Entry->Type);
}
}
@@ -806,7 +829,6 @@ PxeBcExtractDiscoverInfo (
return EFI_SUCCESS;
}
-
/**
Build the discover packet and send out for boot server.
@@ -826,13 +848,13 @@ PxeBcExtractDiscoverInfo (
**/
EFI_STATUS
PxeBcDiscoverBootServer (
- IN PXEBC_PRIVATE_DATA *Private,
- IN UINT16 Type,
- IN UINT16 *Layer,
- IN BOOLEAN UseBis,
- IN EFI_IP_ADDRESS *DestIp,
- IN UINT16 IpCount,
- IN EFI_PXE_BASE_CODE_SRVLIST *SrvList
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN UINT16 Type,
+ IN UINT16 *Layer,
+ IN BOOLEAN UseBis,
+ IN EFI_IP_ADDRESS *DestIp,
+ IN UINT16 IpCount,
+ IN EFI_PXE_BASE_CODE_SRVLIST *SrvList
)
{
if (Private->PxeBc.Mode->UsingIpv6) {
@@ -856,7 +878,6 @@ PxeBcDiscoverBootServer (
}
}
-
/**
Discover all the boot information for boot file.
@@ -871,8 +892,8 @@ PxeBcDiscoverBootServer (
**/
EFI_STATUS
PxeBcDiscoverBootFile (
- IN OUT PXEBC_PRIVATE_DATA *Private,
- OUT UINT64 *BufferSize
+ IN OUT PXEBC_PRIVATE_DATA *Private,
+ OUT UINT64 *BufferSize
)
{
EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
@@ -914,7 +935,6 @@ PxeBcDiscoverBootFile (
}
if (!EFI_ERROR (Status)) {
-
if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {
//
// Local boot(PXE bootstrap server) need abort
@@ -926,7 +946,7 @@ PxeBcDiscoverBootFile (
// Start to discover the boot server to get (m)tftp server ip address, bootfile
// name and bootfile size.
//
- UseBis = (BOOLEAN) (Mode->BisSupported && Mode->BisDetected);
+ UseBis = (BOOLEAN)(Mode->BisSupported && Mode->BisDetected);
Status = PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL);
if (EFI_ERROR (Status)) {
return Status;
@@ -948,8 +968,9 @@ PxeBcDiscoverBootFile (
&Mode->ProxyOffer.Dhcpv4,
&Mode->PxeReply.Dhcpv4,
Private->PxeReply.Dhcp4.Packet.Ack.Length
- );
+ );
}
+
Mode->ProxyOfferReceived = TRUE;
}
}
@@ -966,21 +987,20 @@ PxeBcDiscoverBootFile (
return Status;
}
-
/**
Install PxeBaseCodeCallbackProtocol if not installed before.
@param[in, out] Private Pointer to PxeBc private data.
@param[out] NewMakeCallback If TRUE, it is a new callback.
Otherwise, it is not new callback.
- @retval EFI_SUCCESS PxeBaseCodeCallbackProtocol installed succesfully.
+ @retval EFI_SUCCESS PxeBaseCodeCallbackProtocol installed successfully.
@retval Others Failed to install PxeBaseCodeCallbackProtocol.
**/
EFI_STATUS
PxeBcInstallCallback (
- IN OUT PXEBC_PRIVATE_DATA *Private,
- OUT BOOLEAN *NewMakeCallback
+ IN OUT PXEBC_PRIVATE_DATA *Private,
+ OUT BOOLEAN *NewMakeCallback
)
{
EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
@@ -991,12 +1011,11 @@ PxeBcInstallCallback (
//
PxeBc = &Private->PxeBc;
Status = gBS->HandleProtocol (
- Private->Controller,
+ Private->Mode.UsingIpv6 ? Private->Ip6Nic->Controller : Private->Ip4Nic->Controller,
&gEfiPxeBaseCodeCallbackProtocolGuid,
- (VOID **) &Private->PxeBcCallback
+ (VOID **)&Private->PxeBcCallback
);
if (Status == EFI_UNSUPPORTED) {
-
CopyMem (
&Private->LoadFileCallback,
&gPxeBcCallBackTemplate,
@@ -1007,13 +1026,13 @@ PxeBcInstallCallback (
// Install a default callback if user didn't offer one.
//
Status = gBS->InstallProtocolInterface (
- &Private->Controller,
+ Private->Mode.UsingIpv6 ? &Private->Ip6Nic->Controller : &Private->Ip4Nic->Controller,
&gEfiPxeBaseCodeCallbackProtocolGuid,
EFI_NATIVE_INTERFACE,
&Private->LoadFileCallback
);
- (*NewMakeCallback) = (BOOLEAN) (Status == EFI_SUCCESS);
+ (*NewMakeCallback) = (BOOLEAN)(Status == EFI_SUCCESS);
Status = PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, NewMakeCallback);
if (EFI_ERROR (Status)) {
@@ -1025,7 +1044,6 @@ PxeBcInstallCallback (
return EFI_SUCCESS;
}
-
/**
Uninstall PxeBaseCodeCallbackProtocol.
@@ -1036,29 +1054,27 @@ PxeBcInstallCallback (
**/
VOID
PxeBcUninstallCallback (
- IN PXEBC_PRIVATE_DATA *Private,
- IN BOOLEAN NewMakeCallback
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN BOOLEAN NewMakeCallback
)
{
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
+ EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
PxeBc = &Private->PxeBc;
if (NewMakeCallback) {
-
NewMakeCallback = FALSE;
PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);
gBS->UninstallProtocolInterface (
- Private->Controller,
- &gEfiPxeBaseCodeCallbackProtocolGuid,
- &Private->LoadFileCallback
- );
+ Private->Mode.UsingIpv6 ? Private->Ip6Nic->Controller : Private->Ip4Nic->Controller,
+ &gEfiPxeBaseCodeCallbackProtocolGuid,
+ &Private->LoadFileCallback
+ );
}
}
-
/**
Download one of boot file in the list, and it's special for IPv6.
@@ -1075,15 +1091,15 @@ PxeBcUninstallCallback (
**/
EFI_STATUS
PxeBcReadBootFileList (
- IN PXEBC_PRIVATE_DATA *Private,
- IN OUT UINT64 *BufferSize,
- IN VOID *Buffer OPTIONAL
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN OUT UINT64 *BufferSize,
+ IN VOID *Buffer OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
+ EFI_STATUS Status;
+ EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
- PxeBc = &Private->PxeBc;
+ PxeBc = &Private->PxeBc;
//
// Try to download the boot file if everything is ready.
@@ -1101,16 +1117,13 @@ PxeBcReadBootFileList (
NULL,
FALSE
);
-
-
} else {
- Status = EFI_BUFFER_TOO_SMALL;
+ Status = EFI_BUFFER_TOO_SMALL;
}
return Status;
}
-
/**
Load boot file into user buffer.
@@ -1127,17 +1140,17 @@ PxeBcReadBootFileList (
**/
EFI_STATUS
PxeBcLoadBootFile (
- IN PXEBC_PRIVATE_DATA *Private,
- IN OUT UINTN *BufferSize,
- IN VOID *Buffer OPTIONAL
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer OPTIONAL
)
{
- BOOLEAN NewMakeCallback;
- UINT64 RequiredSize;
- UINT64 CurrentSize;
- EFI_STATUS Status;
- EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
- EFI_PXE_BASE_CODE_MODE *PxeBcMode;
+ BOOLEAN NewMakeCallback;
+ UINT64 RequiredSize;
+ UINT64 CurrentSize;
+ EFI_STATUS Status;
+ EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
+ EFI_PXE_BASE_CODE_MODE *PxeBcMode;
NewMakeCallback = FALSE;
PxeBc = &Private->PxeBc;
@@ -1149,7 +1162,7 @@ PxeBcLoadBootFile (
// Install pxebc callback protocol if hasn't been installed yet.
//
Status = PxeBcInstallCallback (Private, &NewMakeCallback);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return Status;
}
@@ -1172,7 +1185,7 @@ PxeBcLoadBootFile (
//
// Get the right buffer size of the bootfile required.
//
- if (CurrentSize < RequiredSize || Buffer == NULL) {
+ if ((CurrentSize < RequiredSize) || (Buffer == NULL)) {
//
// It's buffer too small if the size of user buffer is smaller than the required.
//
@@ -1180,8 +1193,9 @@ PxeBcLoadBootFile (
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
+
CurrentSize = RequiredSize;
- } else if (RequiredSize == 0 && PxeBcMode->UsingIpv6) {
+ } else if ((RequiredSize == 0) && PxeBcMode->UsingIpv6) {
//
// Try to download another bootfile in list if failed to get the filesize of the last one.
// It's special for the case of IPv6.
@@ -1189,7 +1203,7 @@ PxeBcLoadBootFile (
Status = PxeBcReadBootFileList (Private, &CurrentSize, Buffer);
goto ON_EXIT;
}
- } else if (CurrentSize < Private->BootFileSize || Buffer == NULL ) {
+ } else if ((CurrentSize < Private->BootFileSize) || (Buffer == NULL)) {
//
// It's buffer too small if the size of user buffer is smaller than the required.
//
@@ -1224,13 +1238,13 @@ PxeBcLoadBootFile (
}
ON_EXIT:
- *BufferSize = (UINTN) CurrentSize;
- PxeBcUninstallCallback(Private, NewMakeCallback);
+ *BufferSize = (UINTN)CurrentSize;
+ PxeBcUninstallCallback (Private, NewMakeCallback);
if (Status == EFI_SUCCESS) {
- AsciiPrint ("\n Succeed to download NBP file.\n");
+ AsciiPrint ("\n NBP file downloaded successfully.\n");
return EFI_SUCCESS;
- } else if (Status == EFI_BUFFER_TOO_SMALL && Buffer != NULL) {
+ } else if ((Status == EFI_BUFFER_TOO_SMALL) && (Buffer != NULL)) {
AsciiPrint ("\n PXE-E05: Buffer size is smaller than the requested file.\n");
} else if (Status == EFI_DEVICE_ERROR) {
AsciiPrint ("\n PXE-E07: Network device error.\n");
@@ -1239,7 +1253,7 @@ ON_EXIT:
} else if (Status == EFI_NO_MEDIA) {
AsciiPrint ("\n PXE-E12: Could not detect network connection.\n");
} else if (Status == EFI_NO_RESPONSE) {
- AsciiPrint ("\n PXE-E16: No offer received.\n");
+ AsciiPrint ("\n PXE-E16: No valid offer received.\n");
} else if (Status == EFI_TIMEOUT) {
AsciiPrint ("\n PXE-E18: Server response timeout.\n");
} else if (Status == EFI_ABORTED) {
@@ -1256,4 +1270,3 @@ ON_EXIT:
return Status;
}
-