]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootImpl.c
BaseTools: FdfParser refactor to remove a dictionary
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootImpl.c
index 56f5babeb4bfd5c0d233ed4700b89215073c3d1f..a0fd934ec4c7bf6794a5a15e2d90e2d5c76d85fd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials are licensed and made available under \r
 the terms and conditions of the BSD License that accompanies this distribution.  \r
@@ -122,8 +122,9 @@ HttpBootStart (
   UINTN                Index;\r
   EFI_STATUS           Status;\r
   CHAR8                *Uri;\r
-  \r
 \r
+  Uri = NULL;\r
+  \r
   if (Private == NULL || FilePath == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -154,6 +155,9 @@ HttpBootStart (
       //\r
       Status = HttpBootStop (Private);\r
       if (EFI_ERROR (Status)) {\r
+        if (Uri != NULL) {\r
+          FreePool (Uri);\r
+        }\r
         return Status;\r
       }\r
     } else {\r
@@ -327,6 +331,7 @@ HttpBootLoadFile (
     //\r
     Status = HttpBootDiscoverBootInfo (Private);\r
     if (EFI_ERROR (Status)) {\r
+      AsciiPrint ("\n  Error: Could not retrieve NBP file size from HTTP server.\n");\r
       goto ON_EXIT;\r
     }\r
   }\r
@@ -369,6 +374,7 @@ HttpBootLoadFile (
                  &Private->ImageType\r
                  );\r
       if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {\r
+        AsciiPrint ("\n  Error: Could not retrieve NBP file size from HTTP server.\n");\r
         goto ON_EXIT;\r
       }\r
     }\r
@@ -394,6 +400,25 @@ HttpBootLoadFile (
   \r
 ON_EXIT:\r
   HttpBootUninstallCallback (Private);\r
+  \r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_ACCESS_DENIED) {\r
+      AsciiPrint ("\n  Error: Could not establish connection with HTTP server.\n");\r
+    } else if (Status == EFI_BUFFER_TOO_SMALL && Buffer != NULL) {\r
+      AsciiPrint ("\n  Error: Buffer size is smaller than the requested file.\n");\r
+    } else if (Status == EFI_OUT_OF_RESOURCES) {\r
+      AsciiPrint ("\n  Error: Could not allocate I/O buffers.\n");\r
+    } else if (Status == EFI_DEVICE_ERROR) {\r
+      AsciiPrint ("\n  Error: Network device error.\n");\r
+    } else if (Status == EFI_TIMEOUT) {\r
+      AsciiPrint ("\n  Error: Server response timeout.\n");\r
+    } else if (Status == EFI_ABORTED) {\r
+      AsciiPrint ("\n  Error: Remote boot cancelled.\n");\r
+    } else if (Status != EFI_BUFFER_TOO_SMALL) {\r
+      AsciiPrint ("\n  Error: Unexpected network error.\n");\r
+    }\r
+  }\r
+  \r
   return Status;\r
 }\r
 \r
@@ -465,6 +490,11 @@ HttpBootStop (
     }\r
   }\r
 \r
+  if (Private->DnsServerIp != NULL) {\r
+    FreePool (Private->DnsServerIp);\r
+    Private->DnsServerIp = NULL;\r
+  }\r
+\r
   if (Private->FilePathUri!= NULL) {\r
     FreePool (Private->FilePathUri);\r
     HttpUrlFreeParser (Private->FilePathUriParser);\r
@@ -525,7 +555,7 @@ HttpBootDxeLoadFile (
 {\r
   HTTP_BOOT_PRIVATE_DATA        *Private;\r
   HTTP_BOOT_VIRTUAL_NIC         *VirtualNic;\r
-  BOOLEAN                       MediaPresent;\r
+  EFI_STATUS                    MediaStatus;\r
   BOOLEAN                       UsingIpv6;\r
   EFI_STATUS                    Status;\r
   HTTP_BOOT_IMAGE_TYPE          ImageType;\r
@@ -547,9 +577,10 @@ HttpBootDxeLoadFile (
   //\r
   // Check media status before HTTP boot start\r
   //\r
-  MediaPresent = TRUE;\r
-  NetLibDetectMedia (Private->Controller, &MediaPresent);\r
-  if (!MediaPresent) {\r
+  MediaStatus = EFI_SUCCESS;\r
+  NetLibDetectMediaWaitTimeout (Private->Controller, HTTP_BOOT_CHECK_MEDIA_WAITING_TIME, &MediaStatus);\r
+  if (MediaStatus != EFI_SUCCESS) {\r
+    AsciiPrint ("\n  Error: Could not detect network connection.\n");\r
     return EFI_NO_MEDIA;\r
   }\r
   \r
@@ -590,6 +621,8 @@ HttpBootDxeLoadFile (
     Status = HttpBootRegisterRamDisk (Private, *BufferSize, Buffer, ImageType);\r
     if (!EFI_ERROR (Status)) {\r
       Status = EFI_WARN_FILE_SYSTEM;\r
+    } else {\r
+      AsciiPrint ("\n  Error: Could not register RAM disk to the system.\n");\r
     }\r
   }\r
 \r
@@ -630,6 +663,7 @@ EFI_LOAD_FILE_PROTOCOL  gHttpBootDxeLoadFile = {
   @retval EFI_ABORTED             Tells the HTTP Boot driver to abort the current HTTP Boot process.\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 HttpBootCallback (\r
   IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL     *This,\r
   IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE    DataType,\r
@@ -664,6 +698,26 @@ HttpBootCallback (
   case HttpBootHttpResponse:\r
     if (Data != NULL) {\r
       HttpMessage = (EFI_HTTP_MESSAGE *) Data;\r
+      \r
+      if (HttpMessage->Data.Response != NULL) {\r
+        if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->StatusCode)) {\r
+          //\r
+          // Server indicates the resource has been redirected to a different URL\r
+          // according to the section 6.4 of RFC7231 and the RFC 7538.\r
+          // Display the redirect information on the screen.\r
+          //\r
+          HttpHeader = HttpFindHeader (\r
+                 HttpMessage->HeaderCount,\r
+                 HttpMessage->Headers,\r
+                 HTTP_HEADER_LOCATION\r
+                 );\r
+          if (HttpHeader != NULL) {\r
+            Print (L"\n  HTTP ERROR: Resource Redirected.\n  New Location: %a\n", HttpHeader->FieldValue);\r
+          }\r
+          break; \r
+        }\r
+      }\r
+      \r
       HttpHeader = HttpFindHeader (\r
                      HttpMessage->HeaderCount,\r
                      HttpMessage->Headers,\r
@@ -684,7 +738,7 @@ HttpBootCallback (
         // We already know the file size, print in percentage format.\r
         //\r
         if (Private->ReceivedSize == 0) {\r
-          Print (L"  File Size: %lu\n", Private->FileSize);\r
+          Print (L"  File Size: %lu Bytes\n", Private->FileSize);\r
         }\r
         Private->ReceivedSize += DataLength;\r
         Percentage = (UINT32) DivU64x64Remainder (MultU64x32 (Private->ReceivedSize, 100), Private->FileSize, NULL);\r