]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootImpl.c
NetworkPkg: Add URI configuration form to HTTP boot driver.
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootImpl.c
index 9ea0d7f95f93eb26aa7bbd58e59196fe739b696f..3adb08d9f69c5460343b122c7602abe294cb3184 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<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
@@ -21,22 +21,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @param[in]    UsingIpv6          Specifies the type of IP addresses that are to be\r
                                    used during the session that is being started.\r
                                    Set to TRUE for IPv6, and FALSE for IPv4.\r
+  @param[in]    FilePath           The device specific path of the file to load.\r
 \r
   @retval EFI_SUCCESS              HTTP boot was successfully enabled.\r
   @retval EFI_INVALID_PARAMETER    Private is NULL.\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
 EFI_STATUS\r
 HttpBootStart (\r
   IN HTTP_BOOT_PRIVATE_DATA           *Private,\r
-  IN BOOLEAN                          UsingIpv6\r
+  IN BOOLEAN                          UsingIpv6,\r
+  IN EFI_DEVICE_PATH_PROTOCOL         *FilePath\r
   )\r
 {\r
   UINTN                Index;\r
   EFI_STATUS           Status;\r
 \r
-  if (Private == NULL) {\r
+  if (Private == NULL || FilePath == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -54,6 +57,26 @@ HttpBootStart (
   } else {\r
     return EFI_UNSUPPORTED;\r
   }\r
+\r
+  //\r
+  // Check whether the URI address is specified.\r
+  //\r
+  Status = HttpBootParseFilePath (FilePath, &Private->FilePathUri);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (Private->FilePathUri != NULL) {\r
+    Status = HttpParseUrl (\r
+               Private->FilePathUri,\r
+               (UINT32) AsciiStrLen (Private->FilePathUri),\r
+               FALSE,\r
+               &Private->FilePathUriParser\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
   \r
   //\r
   // Init the content of cached DHCP offer list.\r
@@ -301,12 +324,21 @@ HttpBootStop (
       }\r
     }\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
   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
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -357,7 +389,7 @@ HttpBootDxeLoadFile (
   BOOLEAN                       UsingIpv6;\r
   EFI_STATUS                    Status;\r
 \r
-  if (This == NULL || BufferSize == NULL) {\r
+  if (This == NULL || BufferSize == NULL || FilePath == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -370,7 +402,6 @@ HttpBootDxeLoadFile (
 \r
   VirtualNic = HTTP_BOOT_VIRTUAL_NIC_FROM_LOADFILE (This);\r
   Private = VirtualNic->Private;\r
-  UsingIpv6 = FALSE;\r
   \r
   //\r
   // Check media status before HTTP boot start\r
@@ -380,27 +411,37 @@ HttpBootDxeLoadFile (
   if (!MediaPresent) {\r
     return EFI_NO_MEDIA;\r
   }\r
-\r
+  \r
   //\r
   // Check whether the virtual nic is using IPv6 or not.\r
   //\r
+  UsingIpv6 = FALSE;\r
   if (VirtualNic == Private->Ip6Nic) {\r
     UsingIpv6 = TRUE;\r
   }\r
-  \r
+\r
   //\r
-  // Initialize HTTP boot and load the boot file.\r
+  // Initialize HTTP boot.\r
   //\r
-  Status = HttpBootStart (Private, UsingIpv6);\r
-  if (Status == EFI_ALREADY_STARTED && UsingIpv6 != Private->UsingIpv6) {\r
+  Status = HttpBootStart (Private, UsingIpv6, FilePath);\r
+  if (Status == EFI_ALREADY_STARTED) {\r
     //\r
-    // Http boot Driver has already been started but not on the required IP version, restart it.\r
+    // Restart the HTTP boot driver in 2 cases:\r
+    // 1. Http boot Driver has already been started but not on the required IP version.\r
+    // 2. The required boot FilePath is different with the one we produced in the device path\r
+    // protocol.\r
     //\r
-    Status = HttpBootStop (Private);\r
-    if (!EFI_ERROR (Status)) {\r
-      Status = HttpBootStart (Private, UsingIpv6);\r
+    if ((UsingIpv6 != Private->UsingIpv6) || !IsDevicePathEnd(FilePath)) {\r
+      Status = HttpBootStop (Private);\r
+      if (!EFI_ERROR (Status)) {\r
+        Status = HttpBootStart (Private, UsingIpv6, FilePath);\r
+      }\r
     }\r
   }\r
+\r
+  //\r
+  // Load the boot file.\r
+  //\r
   if (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED) {\r
     Status = HttpBootLoadFile (Private, BufferSize, Buffer);\r
   }\r