]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootClient.c
NetworkPkg: Fix some typos of "according"
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootClient.c
index aae452729c8ebd4e0c27b7d3bbdc342221158817..99db3d5505dc01c5f7a38e94aeeffa960464f7d8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of the boot file download function.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, 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
@@ -191,6 +191,15 @@ HttpBootDhcp4ExtractUriInfo (
     Private->BootFileUri = Private->FilePathUri;\r
   }\r
 \r
+  //\r
+  // Check the URI scheme.\r
+  //\r
+  Status = HttpBootCheckUriScheme (Private->BootFileUri);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status));\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Configure the default DNS server if server assigned.\r
   //\r
@@ -255,6 +264,7 @@ HttpBootDhcp6ExtractUriInfo (
   EFI_DHCP6_PACKET_OPTION         *Option;\r
   EFI_IPv6_ADDRESS                IpAddr;\r
   CHAR8                           *HostName;\r
+  UINTN                           HostNameSize;\r
   CHAR16                          *HostNameStr;\r
   EFI_STATUS                      Status;\r
 \r
@@ -293,6 +303,15 @@ HttpBootDhcp6ExtractUriInfo (
     Private->BootFileUri = Private->FilePathUri;\r
   }\r
 \r
+  //\r
+  // Check the URI scheme.\r
+  //\r
+  Status = HttpBootCheckUriScheme (Private->BootFileUri);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootDhcp6ExtractUriInfo: %r.\n", Status));\r
+    return Status;\r
+  }\r
+\r
   //\r
   //  Set the Local station address to IP layer.\r
   //\r
@@ -300,6 +319,14 @@ HttpBootDhcp6ExtractUriInfo (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
+  //\r
+  // Register the IPv6 gateway address to the network device.\r
+  //\r
+  Status = HttpBootSetIp6Gateway (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
   \r
   //\r
   // Configure the default DNS server if server assigned.\r
@@ -341,14 +368,15 @@ HttpBootDhcp6ExtractUriInfo (
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-    \r
-    HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (CHAR16));\r
+\r
+    HostNameSize = AsciiStrSize (HostName);\r
+    HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));\r
     if (HostNameStr == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Error;\r
     }\r
     \r
-    AsciiStrToUnicodeStr (HostName, HostNameStr);\r
+    AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize);\r
     Status = HttpBootDns (Private, HostNameStr, &IpAddr);\r
     FreePool (HostNameStr);\r
     if (EFI_ERROR (Status)) {\r
@@ -356,15 +384,7 @@ HttpBootDhcp6ExtractUriInfo (
     }  \r
   } \r
   \r
-  CopyMem (&Private->ServerIp.v6, &IpAddr, sizeof (EFI_IPv6_ADDRESS));  \r
-    \r
-  //\r
-  // register the IPv6 gateway address to the network device.\r
-  //\r
-  Status = HttpBootSetIp6Gateway (Private);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
+  CopyMem (&Private->ServerIp.v6, &IpAddr, sizeof (EFI_IPv6_ADDRESS));\r
   \r
   //\r
   // Extract the port from URL, and use default HTTP port 80 if not provided.\r
@@ -447,6 +467,7 @@ HttpBootCreateHttpIo (
 {\r
   HTTP_IO_CONFIG_DATA          ConfigData;\r
   EFI_STATUS                   Status;\r
+  EFI_HANDLE                   ImageHandle;\r
 \r
   ASSERT (Private != NULL);\r
 \r
@@ -456,14 +477,16 @@ HttpBootCreateHttpIo (
     ConfigData.Config4.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;\r
     IP4_COPY_ADDRESS (&ConfigData.Config4.LocalIp, &Private->StationIp.v4);\r
     IP4_COPY_ADDRESS (&ConfigData.Config4.SubnetMask, &Private->SubnetMask.v4);\r
+    ImageHandle = Private->Ip4Nic->ImageHandle;\r
   } else {\r
     ConfigData.Config6.HttpVersion    = HttpVersion11;\r
     ConfigData.Config6.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;\r
     IP6_COPY_ADDRESS (&ConfigData.Config6.LocalIp, &Private->StationIp.v6);\r
+    ImageHandle = Private->Ip6Nic->ImageHandle;\r
   }\r
 \r
   Status = HttpIoCreateIo (\r
-             Private->Image,\r
+             ImageHandle,\r
              Private->Controller,\r
              Private->UsingIpv6 ? IP_VERSION_6 : IP_VERSION_4,\r
              &ConfigData,\r
@@ -567,6 +590,7 @@ HttpBootFreeCacheList (
   @param[out]         Buffer          The memory buffer to transfer the file to. IF Buffer is NULL,\r
                                       then the size of the requested file is returned in\r
                                       BufferSize.\r
+  @param[out]         ImageType       The image type of the downloaded file.\r
 \r
   @retval EFI_SUCCESS          Successfully created.\r
   @retval Others               Failed to create HttpIo.\r
@@ -577,7 +601,8 @@ HttpBootGetFileFromCache (
   IN     HTTP_BOOT_PRIVATE_DATA   *Private,\r
   IN     CHAR16                   *Uri,\r
   IN OUT UINTN                    *BufferSize,\r
-     OUT UINT8                    *Buffer\r
+     OUT UINT8                    *Buffer,\r
+     OUT HTTP_BOOT_IMAGE_TYPE     *ImageType\r
   )\r
 {\r
   LIST_ENTRY                  *Entry;\r
@@ -586,7 +611,7 @@ HttpBootGetFileFromCache (
   HTTP_BOOT_ENTITY_DATA       *EntityData;\r
   UINTN                       CopyedSize;\r
   \r
-  if (Uri == NULL || BufferSize == 0 || Buffer == NULL) {\r
+  if (Uri == NULL || BufferSize == 0 || Buffer == NULL || ImageType == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -600,7 +625,12 @@ HttpBootGetFileFromCache (
         (StrCmp (Uri, Cache->RequestData->Url) == 0)) \r
     {\r
       //\r
-      // Hit cache, check buffer size.\r
+      // Hit in cache, record image type.\r
+      //\r
+      *ImageType  = Cache->ImageType;\r
+\r
+      //\r
+      // Check buffer size.\r
       //\r
       if (*BufferSize < Cache->EntityLength) {\r
         *BufferSize = Cache->EntityLength;\r
@@ -709,6 +739,7 @@ HttpBootGetBootFileCallback (
   @param[out]      Buffer          The memory buffer to transfer the file to. IF Buffer is NULL,\r
                                    then the size of the requested file is returned in\r
                                    BufferSize.\r
+  @param[out]      ImageType       The image type of the downloaded file.\r
 \r
   @retval EFI_SUCCESS              The file was loaded.\r
   @retval EFI_INVALID_PARAMETER    BufferSize is NULL or Buffer Size is not NULL but Buffer is NULL.\r
@@ -724,7 +755,8 @@ HttpBootGetBootFile (
   IN     HTTP_BOOT_PRIVATE_DATA   *Private,\r
   IN     BOOLEAN                  HeaderOnly,\r
   IN OUT UINTN                    *BufferSize,\r
-     OUT UINT8                    *Buffer\r
+     OUT UINT8                    *Buffer,\r
+     OUT HTTP_BOOT_IMAGE_TYPE     *ImageType\r
   )\r
 {\r
   EFI_STATUS                 Status;\r
@@ -740,6 +772,7 @@ HttpBootGetBootFile (
   UINTN                      ContentLength;\r
   HTTP_BOOT_CACHE_CONTENT    *Cache;\r
   UINT8                      *Block;\r
+  UINTN                      UrlSize;\r
   CHAR16                     *Url;\r
   BOOLEAN                    IdentityMode;\r
   UINTN                      ReceivedSize;\r
@@ -747,7 +780,7 @@ HttpBootGetBootFile (
   ASSERT (Private != NULL);\r
   ASSERT (Private->HttpCreated);\r
 \r
-  if (BufferSize == NULL) {\r
+  if (BufferSize == NULL || ImageType == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -758,13 +791,14 @@ HttpBootGetBootFile (
   //\r
   // First, check whether we already cached the requested Uri.\r
   //\r
-  Url = AllocatePool ((AsciiStrLen (Private->BootFileUri) + 1) * sizeof (CHAR16));\r
+  UrlSize = AsciiStrSize (Private->BootFileUri);\r
+  Url = AllocatePool (UrlSize * sizeof (CHAR16));\r
   if (Url == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  AsciiStrToUnicodeStr (Private->BootFileUri, Url);\r
+  AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize);\r
   if (!HeaderOnly) {\r
-    Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer);\r
+    Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer, ImageType);\r
     if (Status != EFI_NOT_FOUND) {\r
       FreePool (Url);\r
       return Status;\r
@@ -785,6 +819,7 @@ HttpBootGetBootFile (
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ERROR_1;\r
     }\r
+    Cache->ImageType = ImageTypeMax;\r
     InitializeListHead (&Cache->EntityDataList);\r
   }\r
 \r
@@ -860,11 +895,6 @@ HttpBootGetBootFile (
   }\r
   RequestData->Method = HeaderOnly ? HttpMethodHead : HttpMethodGet;\r
   RequestData->Url = Url;\r
-  if (RequestData->Url == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ERROR_4;\r
-  }\r
-  AsciiStrToUnicodeStr (Private->BootFileUri, RequestData->Url);\r
 \r
   //\r
   // 2.3 Record the request info in a temp cache item.\r
@@ -915,11 +945,26 @@ HttpBootGetBootFile (
     goto ERROR_5;\r
   }\r
 \r
+  //\r
+  // Check the image type according to server's response.\r
+  //\r
+  Status = HttpBootCheckImageType (\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
+             ResponseData->HeaderCount,\r
+             ResponseData->Headers,\r
+             ImageType\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR_5;\r
+  }\r
+\r
   //\r
   // 3.2 Cache the response header.\r
   //\r
   if (Cache != NULL) {\r
     Cache->ResponseData = ResponseData;\r
+    Cache->ImageType = *ImageType;\r
   }\r
   \r
   //\r
@@ -980,7 +1025,10 @@ HttpBootGetBootFile (
                    FALSE,\r
                    &ResponseBody\r
                    );\r
-        if (EFI_ERROR (Status)) {\r
+        if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) {\r
+          if (EFI_ERROR (ResponseBody.Status)) {\r
+            Status = ResponseBody.Status;\r
+          }\r
           goto ERROR_6;\r
         }\r
         ReceivedSize += ResponseBody.BodyLength;\r
@@ -1017,7 +1065,10 @@ HttpBootGetBootFile (
                    FALSE,\r
                    &ResponseBody\r
                    );\r
-        if (EFI_ERROR (Status)) {\r
+        if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) {\r
+          if (EFI_ERROR (ResponseBody.Status)) {\r
+            Status = ResponseBody.Status;\r
+          }\r
           goto ERROR_6;\r
         }\r
 \r
@@ -1046,6 +1097,8 @@ HttpBootGetBootFile (
 \r
   if (*BufferSize < ContentLength) {\r
     Status = EFI_BUFFER_TOO_SMALL;\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
   }\r
   *BufferSize = ContentLength;\r
 \r
@@ -1061,7 +1114,7 @@ HttpBootGetBootFile (
     HttpFreeMsgParser (Parser);\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
   \r
 ERROR_6:\r
   if (Parser != NULL) {\r