]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootImpl.c
NetworkPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootImpl.c
index dfd0e23db02d2f41fad348c53a86a8b08117690f..5eeb1ea2b4a76e42026ac7ffe5a1d30598243b72 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.\r
 \r
-Copyright (c) 2015 - 2017, 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
-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
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -96,7 +90,7 @@ HttpBootUninstallCallback (
 /**\r
   Enable the use of UEFI HTTP boot function.\r
 \r
-  If the driver has already been started but not satisfy the requirement (IP stack and \r
+  If the driver has already been started but not satisfy the requirement (IP stack and\r
   specified boot file path), this function will stop the driver and start it again.\r
 \r
   @param[in]    Private            The pointer to the driver's private data.\r
@@ -110,7 +104,7 @@ HttpBootUninstallCallback (
   @retval EFI_INVALID_PARAMETER    The FilePath doesn't contain a valid URI device path node.\r
   @retval EFI_ALREADY_STARTED      The driver is already in started state.\r
   @retval EFI_OUT_OF_RESOURCES     There are not enough resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 HttpBootStart (\r
@@ -122,21 +116,22 @@ 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
-  \r
+\r
   //\r
   // Check the URI in the input FilePath, in order to see whether it is\r
-  // required to boot from a new specified boot file. \r
+  // required to boot from a new specified boot file.\r
   //\r
   Status = HttpBootParseFilePath (FilePath, &Uri);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   //\r
   // Check whether we need to stop and restart the HTTP boot driver.\r
   //\r
@@ -147,13 +142,16 @@ HttpBootStart (
     // 2. The specified boot file URI in FilePath is different with the one we have\r
     // recorded before.\r
     //\r
-    if ((UsingIpv6 != Private->UsingIpv6) || \r
+    if ((UsingIpv6 != Private->UsingIpv6) ||\r
         ((Uri != NULL) && (AsciiStrCmp (Private->BootFileUri, Uri) != 0))) {\r
       //\r
       // Restart is required, first stop then continue this start function.\r
       //\r
       Status = HttpBootStop (Private);\r
       if (EFI_ERROR (Status)) {\r
+        if (Uri != NULL) {\r
+          FreePool (Uri);\r
+        }\r
         return Status;\r
       }\r
     } else {\r
@@ -197,7 +195,7 @@ HttpBootStart (
       return Status;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Init the content of cached DHCP offer list.\r
   //\r
@@ -237,7 +235,7 @@ HttpBootStart (
   @retval EFI_NOT_STARTED          The driver is in stopped state.\r
   @retval EFI_DEVICE_ERROR         An unexpected network error occurred.\r
   @retval Others                   Other errors as indicated.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 HttpBootDhcp (\r
@@ -249,7 +247,7 @@ HttpBootDhcp (
   if (Private == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if (!Private->Started) {\r
     return EFI_NOT_STARTED;\r
   }\r
@@ -288,11 +286,11 @@ HttpBootDhcp (
   @retval EFI_INVALID_PARAMETER       Private is NULL, or ImageType is NULL, or BufferSize is NULL.\r
   @retval EFI_INVALID_PARAMETER       *BufferSize is not zero, and Buffer is NULL.\r
   @retval EFI_NOT_STARTED             The driver is in stopped state.\r
-  @retval EFI_BUFFER_TOO_SMALL        The BufferSize is too small to read the boot file. BufferSize has \r
+  @retval EFI_BUFFER_TOO_SMALL        The BufferSize is too small to read the boot file. BufferSize has\r
                                       been updated with the size needed to complete the request.\r
   @retval EFI_DEVICE_ERROR            An unexpected network error occurred.\r
   @retval Others                      Other errors as indicated.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 HttpBootLoadFile (\r
@@ -311,7 +309,7 @@ HttpBootLoadFile (
   if (*BufferSize != 0 && Buffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if (!Private->Started) {\r
     return EFI_NOT_STARTED;\r
   }\r
@@ -327,6 +325,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 +368,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
@@ -391,9 +391,28 @@ HttpBootLoadFile (
              Buffer,\r
              ImageType\r
              );\r
-  \r
+\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
@@ -406,7 +425,7 @@ ON_EXIT:
   @retval EFI_NOT_STARTED          The driver is already in stopped state.\r
   @retval EFI_INVALID_PARAMETER    Private is NULL.\r
   @retval Others                   Unexpected error when stop the function.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 HttpBootStop (\r
@@ -418,16 +437,16 @@ HttpBootStop (
   if (Private == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if (!Private->Started) {\r
     return EFI_NOT_STARTED;\r
   }\r
-  \r
+\r
   if (Private->HttpCreated) {\r
     HttpIoDestroyIo (&Private->HttpIo);\r
     Private->HttpCreated = FALSE;\r
   }\r
-  \r
+\r
   Private->Started = FALSE;\r
   ZeroMem (&Private->StationIp, sizeof (EFI_IP_ADDRESS));\r
   ZeroMem (&Private->SubnetMask, sizeof (EFI_IP_ADDRESS));\r
@@ -437,7 +456,7 @@ HttpBootStop (
   Private->BootFileUriParser = NULL;\r
   Private->BootFileSize = 0;\r
   Private->SelectIndex = 0;\r
-  Private->SelectProxyType = HttpOfferTypeMax; \r
+  Private->SelectProxyType = HttpOfferTypeMax;\r
 \r
   if (!Private->UsingIpv6) {\r
     //\r
@@ -457,7 +476,7 @@ HttpBootStop (
     //\r
     Private->Dhcp6->Stop (Private->Dhcp6);\r
     Private->Dhcp6->Configure (Private->Dhcp6, NULL);\r
-    \r
+\r
     for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {\r
       if (Private->OfferBuffer[Index].Dhcp6.UriParser) {\r
         HttpUrlFreeParser (Private->OfferBuffer[Index].Dhcp6.UriParser);\r
@@ -465,20 +484,25 @@ 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
     Private->FilePathUri = NULL;\r
     Private->FilePathUriParser = NULL;\r
   }\r
-  \r
+\r
   ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer));\r
   Private->OfferNum = 0;\r
   ZeroMem (Private->OfferCount, sizeof (Private->OfferCount));\r
   ZeroMem (Private->OfferIndex, sizeof (Private->OfferIndex));\r
-  \r
+\r
   HttpBootFreeCacheList (Private);\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -525,7 +549,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
@@ -543,16 +567,17 @@ HttpBootDxeLoadFile (
 \r
   VirtualNic = HTTP_BOOT_VIRTUAL_NIC_FROM_LOADFILE (This);\r
   Private = VirtualNic->Private;\r
-  \r
+\r
   //\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
+\r
   //\r
   // Check whether the virtual nic is using IPv6 or not.\r
   //\r
@@ -568,7 +593,7 @@ HttpBootDxeLoadFile (
   if (Status != EFI_SUCCESS && Status != EFI_ALREADY_STARTED) {\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Load the boot file.\r
   //\r
@@ -590,6 +615,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
@@ -603,7 +630,7 @@ HttpBootDxeLoadFile (
 ///\r
 /// Load File Protocol instance\r
 ///\r
-GLOBAL_REMOVE_IF_UNREFERENCED \r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
 EFI_LOAD_FILE_PROTOCOL  gHttpBootDxeLoadFile = {\r
   HttpBootDxeLoadFile\r
 };\r
@@ -625,7 +652,7 @@ EFI_LOAD_FILE_PROTOCOL  gHttpBootDxeLoadFile = {
   @param[in]  DataLength          The length in bytes of the buffer pointed to by Data.\r
   @param[in]  Data                A pointer to the buffer of data, the data type is specified by\r
                                   DataType.\r
-                                  \r
+\r
   @retval EFI_SUCCESS             Tells the HTTP Boot driver to continue the HTTP Boot process.\r
   @retval EFI_ABORTED             Tells the HTTP Boot driver to abort the current HTTP Boot process.\r
 **/\r
@@ -665,7 +692,7 @@ HttpBootCallback (
   case HttpBootHttpResponse:\r
     if (Data != NULL) {\r
       HttpMessage = (EFI_HTTP_MESSAGE *) Data;\r
-      \r
+\r
       if (HttpMessage->Data.Response != NULL) {\r
         if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->StatusCode)) {\r
           //\r
@@ -681,9 +708,10 @@ HttpBootCallback (
           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
+\r
       HttpHeader = HttpFindHeader (\r
                      HttpMessage->HeaderCount,\r
                      HttpMessage->Headers,\r
@@ -733,7 +761,7 @@ HttpBootCallback (
 ///\r
 /// HTTP Boot Callback Protocol instance\r
 ///\r
-GLOBAL_REMOVE_IF_UNREFERENCED \r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
 EFI_HTTP_BOOT_CALLBACK_PROTOCOL  gHttpBootDxeHttpBootCallback = {\r
   HttpBootCallback\r
 };\r