]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c
MdeModulePkg FaultTolerantWritePei: Refine the code to avoid error report.
[mirror_edk2.git] / NetworkPkg / UefiPxeBcDxe / PxeBcBoot.c
index e26b412781b82b645f32429504711be431a2ef40..5bbefcee9d4f075e21a4bf8f4c265ea6327ff649 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Boot functions implementation for UefiPxeBc Driver.\r
 \r
 /** @file\r
   Boot functions implementation for UefiPxeBc Driver.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2013, 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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -86,9 +86,9 @@ PxeBcSelectBootPrompt (
   OfferType    = Mode->UsingIpv6 ? Cache->Dhcp6.OfferType : Cache->Dhcp4.OfferType;\r
 \r
   //\r
   OfferType    = Mode->UsingIpv6 ? Cache->Dhcp6.OfferType : Cache->Dhcp4.OfferType;\r
 \r
   //\r
-  // Only ProxyPxe10 offer needs boot prompt.\r
+  // Only DhcpPxe10 and ProxyPxe10 offer needs boot prompt.\r
   //\r
   //\r
-  if (OfferType != PxeOfferTypeProxyPxe10) {\r
+  if (OfferType != PxeOfferTypeProxyPxe10 && OfferType != PxeOfferTypeDhcpPxe10) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -98,8 +98,19 @@ PxeBcSelectBootPrompt (
   ASSERT (!Mode->UsingIpv6);\r
 \r
   VendorOpt = &Cache->Dhcp4.VendorOpt;\r
   ASSERT (!Mode->UsingIpv6);\r
 \r
   VendorOpt = &Cache->Dhcp4.VendorOpt;\r
+  //\r
+  // According to the PXE specification 2.1, Table 2-1 PXE DHCP Options,\r
+  // we must not consider a boot prompt or boot menu if all of the following hold:\r
+  //   - the PXE_DISCOVERY_CONTROL tag(6) is present inside the Vendor Options(43), and has bit 3 set  \r
+  //   - a boot file name has been presented in the initial DHCP or ProxyDHCP offer packet.\r
+  //\r
+  if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) &&\r
+      Cache->Dhcp4.OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {\r
+    return EFI_ABORTED;\r
+  }\r
+  \r
   if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {\r
   if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {\r
-    return EFI_SUCCESS;\r
+    return EFI_TIMEOUT;\r
   }\r
 \r
   Timeout   = VendorOpt->MenuPrompt->Timeout;\r
   }\r
 \r
   Timeout   = VendorOpt->MenuPrompt->Timeout;\r
@@ -110,10 +121,10 @@ PxeBcSelectBootPrompt (
   // The valid scope of Timeout refers to PXE2.1 spec.\r
   //\r
   if (Timeout == 0) {\r
   // The valid scope of Timeout refers to PXE2.1 spec.\r
   //\r
   if (Timeout == 0) {\r
-    return EFI_SUCCESS;\r
+    return EFI_TIMEOUT;\r
   }\r
   if (Timeout == 255) {\r
   }\r
   if (Timeout == 255) {\r
-    return EFI_TIMEOUT;\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -173,6 +184,7 @@ PxeBcSelectBootPrompt (
   gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
   AsciiPrint ("(%d) ", Timeout--);\r
 \r
   gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
   AsciiPrint ("(%d) ", Timeout--);\r
 \r
+  Status = EFI_TIMEOUT;\r
   while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {\r
     if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) {\r
       gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
   while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {\r
     if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) {\r
       gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
@@ -184,6 +196,7 @@ PxeBcSelectBootPrompt (
     }\r
     //\r
     // Parse the input key by user.\r
     }\r
     //\r
     // Parse the input key by user.\r
+    // If <F8> or <Ctrl> + <M> is pressed, return success to display the boot menu.\r
     //\r
     if (InputKey.ScanCode == 0) {\r
 \r
     //\r
     if (InputKey.ScanCode == 0) {\r
 \r
@@ -196,7 +209,7 @@ PxeBcSelectBootPrompt (
       case CTRL ('m'):\r
       case 'm':\r
       case 'M':\r
       case CTRL ('m'):\r
       case 'm':\r
       case 'M':\r
-        Status = EFI_TIMEOUT;\r
+        Status = EFI_SUCCESS;\r
         break;\r
 \r
       default:\r
         break;\r
 \r
       default:\r
@@ -208,7 +221,7 @@ PxeBcSelectBootPrompt (
       switch (InputKey.ScanCode) {\r
 \r
       case SCAN_F8:\r
       switch (InputKey.ScanCode) {\r
 \r
       case SCAN_F8:\r
-        Status = EFI_TIMEOUT;\r
+        Status = EFI_SUCCESS;\r
         break;\r
 \r
       case SCAN_ESC:\r
         break;\r
 \r
       case SCAN_ESC:\r
@@ -276,7 +289,7 @@ PxeBcSelectBootMenu (
   PXEBC_BOOT_MENU_ENTRY      *MenuArray[PXEBC_MENU_MAX_NUM];\r
 \r
   Finish    = FALSE;\r
   PXEBC_BOOT_MENU_ENTRY      *MenuArray[PXEBC_MENU_MAX_NUM];\r
 \r
   Finish    = FALSE;\r
-  Select    = 1;\r
+  Select    = 0;\r
   Index     = 0;\r
   *Type     = 0;\r
   Mode      = Private->PxeBc.Mode;\r
   Index     = 0;\r
   *Type     = 0;\r
   Mode      = Private->PxeBc.Mode;\r
@@ -284,10 +297,10 @@ PxeBcSelectBootMenu (
   OfferType = Mode->UsingIpv6 ? Cache->Dhcp6.OfferType : Cache->Dhcp4.OfferType;\r
 \r
   //\r
   OfferType = Mode->UsingIpv6 ? Cache->Dhcp6.OfferType : Cache->Dhcp4.OfferType;\r
 \r
   //\r
-  // There is no specified ProxyPxe10 for IPv6 in PXE and UEFI spec.\r
+  // There is no specified DhcpPxe10/ProxyPxe10 for IPv6 in PXE and UEFI spec.\r
   //\r
   ASSERT (!Mode->UsingIpv6);\r
   //\r
   ASSERT (!Mode->UsingIpv6);\r
-  ASSERT (OfferType == PxeOfferTypeProxyPxe10);\r
+  ASSERT (OfferType == PxeOfferTypeProxyPxe10 || OfferType == PxeOfferTypeDhcpPxe10);\r
 \r
   VendorOpt = &Cache->Dhcp4.VendorOpt;\r
   if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {\r
 \r
   VendorOpt = &Cache->Dhcp4.VendorOpt;\r
   if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {\r
@@ -351,7 +364,7 @@ PxeBcSelectBootMenu (
       gBS->Stall (10 * TICKS_PER_MS);\r
     }\r
 \r
       gBS->Stall (10 * TICKS_PER_MS);\r
     }\r
 \r
-    if (InputKey.ScanCode != 0) {\r
+    if (InputKey.ScanCode == 0) {\r
       switch (InputKey.UnicodeChar) {\r
       case CTRL ('c'):\r
         InputKey.ScanCode = SCAN_ESC;\r
       switch (InputKey.UnicodeChar) {\r
       case CTRL ('c'):\r
         InputKey.ScanCode = SCAN_ESC;\r
@@ -651,7 +664,7 @@ PxeBcDhcp6BootInfo (
 \r
   @param[in]      Private      Pointer to PxeBc private data.\r
   @param[in]      Type         The type of bootstrap to perform.\r
 \r
   @param[in]      Private      Pointer to PxeBc private data.\r
   @param[in]      Type         The type of bootstrap to perform.\r
-  @param[in, out] Info         Pointer to EFI_PXE_BASE_CODE_DISCOVER_INFO.\r
+  @param[in, out] DiscoverInfo Pointer to EFI_PXE_BASE_CODE_DISCOVER_INFO.\r
   @param[out]     BootEntry    Pointer to PXEBC_BOOT_SVR_ENTRY.\r
   @param[out]     SrvList      Pointer to EFI_PXE_BASE_CODE_SRVLIST.\r
 \r
   @param[out]     BootEntry    Pointer to PXEBC_BOOT_SVR_ENTRY.\r
   @param[out]     SrvList      Pointer to EFI_PXE_BASE_CODE_SRVLIST.\r
 \r
@@ -663,7 +676,7 @@ EFI_STATUS
 PxeBcExtractDiscoverInfo (\r
   IN     PXEBC_PRIVATE_DATA               *Private,\r
   IN     UINT16                           Type,\r
 PxeBcExtractDiscoverInfo (\r
   IN     PXEBC_PRIVATE_DATA               *Private,\r
   IN     UINT16                           Type,\r
-  IN OUT EFI_PXE_BASE_CODE_DISCOVER_INFO  *Info,\r
+  IN OUT EFI_PXE_BASE_CODE_DISCOVER_INFO  **DiscoverInfo,\r
      OUT PXEBC_BOOT_SVR_ENTRY             **BootEntry,\r
      OUT EFI_PXE_BASE_CODE_SRVLIST        **SrvList\r
   )\r
      OUT PXEBC_BOOT_SVR_ENTRY             **BootEntry,\r
      OUT EFI_PXE_BASE_CODE_SRVLIST        **SrvList\r
   )\r
@@ -673,8 +686,11 @@ PxeBcExtractDiscoverInfo (
   PXEBC_VENDOR_OPTION             *VendorOpt;\r
   PXEBC_BOOT_SVR_ENTRY            *Entry;\r
   BOOLEAN                         IsFound;\r
   PXEBC_VENDOR_OPTION             *VendorOpt;\r
   PXEBC_BOOT_SVR_ENTRY            *Entry;\r
   BOOLEAN                         IsFound;\r
+  EFI_PXE_BASE_CODE_DISCOVER_INFO *Info;\r
+  UINT16                          Index;\r
 \r
   Mode = Private->PxeBc.Mode;\r
 \r
   Mode = Private->PxeBc.Mode;\r
+  Info = *DiscoverInfo;\r
 \r
   if (Mode->UsingIpv6) {\r
     Info->IpCnt    = 1;\r
 \r
   if (Mode->UsingIpv6) {\r
     Info->IpCnt    = 1;\r
@@ -708,7 +724,7 @@ PxeBcExtractDiscoverInfo (
     Info->UseMCast    = (BOOLEAN) !IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
     Info->UseBCast    = (BOOLEAN) !IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
     Info->MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);\r
     Info->UseMCast    = (BOOLEAN) !IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
     Info->UseBCast    = (BOOLEAN) !IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
     Info->MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);\r
-    Info->UseUCast    = Info->MustUseList;\r
+    Info->UseUCast    = (BOOLEAN) IS_VALID_BOOT_SERVERS (VendorOpt->BitMap);\r
 \r
     if (Info->UseMCast) {\r
       //\r
 \r
     if (Info->UseMCast) {\r
       //\r
@@ -719,7 +735,7 @@ PxeBcExtractDiscoverInfo (
 \r
     Info->IpCnt = 0;\r
 \r
 \r
     Info->IpCnt = 0;\r
 \r
-    if (Info->MustUseList) {\r
+    if (Info->UseUCast) {\r
       Entry = VendorOpt->BootSvr;\r
 \r
       while (((UINT8) (Entry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {\r
       Entry = VendorOpt->BootSvr;\r
 \r
       while (((UINT8) (Entry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {\r
@@ -735,9 +751,24 @@ PxeBcExtractDiscoverInfo (
       }\r
 \r
       Info->IpCnt = Entry->IpCnt;\r
       }\r
 \r
       Info->IpCnt = Entry->IpCnt;\r
+      if (Info->IpCnt >= 1) {\r
+        *DiscoverInfo = AllocatePool (sizeof (*Info) + (Info->IpCnt - 1) * sizeof (**SrvList));\r
+        if (*DiscoverInfo == NULL) {\r
+          return EFI_OUT_OF_RESOURCES;       \r
+        }     \r
+        CopyMem (*DiscoverInfo, Info, sizeof (*Info));\r
+        Info = *DiscoverInfo;\r
+      }\r
+\r
+      for (Index = 0; Index < Info->IpCnt; Index++) {\r
+        CopyMem (&Info->SrvList[Index].IpAddr, &Entry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));\r
+        Info->SrvList[Index].AcceptAnyResponse = !Info->MustUseList;\r
+        Info->SrvList[Index].Type = NTOHS (Entry->Type);\r
+      }\r
     }\r
 \r
     *BootEntry = Entry;\r
     }\r
 \r
     *BootEntry = Entry;\r
+    *SrvList   = Info->SrvList;\r
   }\r
 \r
   return EFI_SUCCESS;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -842,12 +873,12 @@ PxeBcDiscoverBootFile (
     //\r
     // Choose by user's input.\r
     //\r
     //\r
     // Choose by user's input.\r
     //\r
-    Status = PxeBcSelectBootMenu (Private, &Type, TRUE);\r
+    Status = PxeBcSelectBootMenu (Private, &Type, FALSE);\r
   } else if (Status == EFI_TIMEOUT) {\r
     //\r
     // Choose by default item.\r
     //\r
   } else if (Status == EFI_TIMEOUT) {\r
     //\r
     // Choose by default item.\r
     //\r
-    Status = PxeBcSelectBootMenu (Private, &Type, FALSE);\r
+    Status = PxeBcSelectBootMenu (Private, &Type, TRUE);\r
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
@@ -868,6 +899,27 @@ PxeBcDiscoverBootFile (
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
+\r
+    if (Mode->PxeReplyReceived && !Mode->ProxyOfferReceived) {\r
+      //\r
+      // Some network boot loader only search the packet in Mode.ProxyOffer to get its server\r
+      // IP address, so we need to store a copy of Mode.PxeReply packet into Mode.ProxyOffer.\r
+      //\r
+      if (Mode->UsingIpv6) {\r
+        CopyMem (\r
+          &Mode->ProxyOffer.Dhcpv6,\r
+          &Mode->PxeReply.Dhcpv6,\r
+          Private->PxeReply.Dhcp6.Packet.Ack.Length\r
+          );\r
+      } else {\r
+        CopyMem (\r
+          &Mode->ProxyOffer.Dhcpv4,\r
+          &Mode->PxeReply.Dhcpv4,\r
+          Private->PxeReply.Dhcp4.Packet.Ack.Length\r
+          );      \r
+      }\r
+      Mode->ProxyOfferReceived = TRUE;\r
+    }\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r