]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootImpl.c
NetworkPkg: UefiPxeBcDxe: Remove the redundant code.
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootImpl.c
index 7f0616dafc065dd2db0b131078ee976848612c86..0f222adefd8b8f0c3b60ecfe7e1f45f5f4ae2a9b 100644 (file)
@@ -1,14 +1,14 @@
 /** @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
+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
+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
@@ -96,7 +96,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 +110,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 +122,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 +148,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 +201,7 @@ HttpBootStart (
       return Status;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Init the content of cached DHCP offer list.\r
   //\r
@@ -237,7 +241,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 +253,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 +292,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 +315,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,7 +331,7 @@ HttpBootLoadFile (
     //\r
     Status = HttpBootDiscoverBootInfo (Private);\r
     if (EFI_ERROR (Status)) {\r
-      AsciiPrint ("\n  Error: Could not discover the boot information for DHCP server.\n");\r
+      AsciiPrint ("\n  Error: Could not retrieve NBP file size from HTTP server.\n");\r
       goto ON_EXIT;\r
     }\r
   }\r
@@ -393,25 +397,28 @@ HttpBootLoadFile (
              Buffer,\r
              ImageType\r
              );\r
-  \r
+\r
 ON_EXIT:\r
   HttpBootUninstallCallback (Private);\r
 \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
+  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
@@ -424,7 +431,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
@@ -436,16 +443,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
@@ -455,7 +462,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
@@ -475,7 +482,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
@@ -494,14 +501,14 @@ HttpBootStop (
     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
@@ -566,7 +573,7 @@ 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
@@ -576,7 +583,7 @@ HttpBootDxeLoadFile (
     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
@@ -592,7 +599,7 @@ HttpBootDxeLoadFile (
   if (Status != EFI_SUCCESS && Status != EFI_ALREADY_STARTED) {\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Load the boot file.\r
   //\r
@@ -629,7 +636,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
@@ -651,7 +658,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
@@ -691,7 +698,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
@@ -707,9 +714,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
@@ -759,7 +767,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