X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FHttpBootDxe%2FHttpBootClient.c;h=1d1e47008da23ee1fb8c9ba2037c1ed3b407c9f0;hb=373b1d0ee31ea2e2868307ea82277271b18a7be7;hp=f0817e92e21e38b3d7ef4ccf606947ce2efbf605;hpb=ef422fc53c4bc978767fcee35b284f61c02ea6d5;p=mirror_edk2.git diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootDxe/HttpBootClient.c index f0817e92e2..1d1e47008d 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c @@ -1,7 +1,8 @@ /** @file Implementation of the boot file download function. -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -15,7 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "HttpBootDxe.h" /** - Update the IP and URL device path node to include the boot resource information. + Update the device path node to include the boot resource information. @param[in] Private The pointer to the driver's private data. @@ -30,12 +31,14 @@ HttpBootUpdateDevicePath ( ) { EFI_DEV_PATH *Node; - EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TmpIpDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TmpDnsDevicePath; EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; UINTN Length; EFI_STATUS Status; - TmpDevicePath = NULL; + TmpIpDevicePath = NULL; + TmpDnsDevicePath = NULL; // // Update the IP node with DHCP assigned information. @@ -71,29 +74,65 @@ HttpBootUpdateDevicePath ( CopyMem (&Node->Ipv6.GatewayIpAddress, &Private->GatewayIp.v6, sizeof (EFI_IPv6_ADDRESS)); } - TmpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node); + TmpIpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node); FreePool (Node); - if (TmpDevicePath == NULL) { + if (TmpIpDevicePath == NULL) { return EFI_OUT_OF_RESOURCES; } + // + // Update the DNS node with DNS server IP list if existed. + // + if (Private->DnsServerIp != NULL) { + Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6) + Private->DnsServerCount * sizeof (EFI_IP_ADDRESS); + Node = AllocatePool (Length); + if (Node == NULL) { + FreePool (TmpIpDevicePath); + return EFI_OUT_OF_RESOURCES; + } + Node->DevPath.Type = MESSAGING_DEVICE_PATH; + Node->DevPath.SubType = MSG_DNS_DP; + SetDevicePathNodeLength (Node, Length); + Node->Dns.IsIPv6 = Private->UsingIpv6 ? 0x01 : 0x00; + CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6), Private->DnsServerIp, Private->DnsServerCount * sizeof (EFI_IP_ADDRESS)); + + TmpDnsDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node); + FreePool (Node); + FreePool (TmpIpDevicePath); + TmpIpDevicePath = NULL; + if (TmpDnsDevicePath == NULL) { + return EFI_OUT_OF_RESOURCES; + } + } + // // Update the URI node with the boot file URI. // Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (Private->BootFileUri); Node = AllocatePool (Length); if (Node == NULL) { - FreePool (TmpDevicePath); + if (TmpIpDevicePath != NULL) { + FreePool (TmpIpDevicePath); + } + if (TmpDnsDevicePath != NULL) { + FreePool (TmpDnsDevicePath); + } return EFI_OUT_OF_RESOURCES; } Node->DevPath.Type = MESSAGING_DEVICE_PATH; Node->DevPath.SubType = MSG_URI_DP; SetDevicePathNodeLength (Node, Length); CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), Private->BootFileUri, AsciiStrSize (Private->BootFileUri)); - - NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node); + + if (TmpDnsDevicePath != NULL) { + NewDevicePath = AppendDevicePathNode (TmpDnsDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node); + FreePool (TmpDnsDevicePath); + } else { + ASSERT (TmpIpDevicePath != NULL); + NewDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node); + FreePool (TmpIpDevicePath); + } FreePool (Node); - FreePool (TmpDevicePath); if (NewDevicePath == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -152,6 +191,7 @@ HttpBootDhcp4ExtractUriInfo ( HTTP_BOOT_DHCP4_PACKET_CACHE *HttpOffer; UINT32 SelectIndex; UINT32 ProxyIndex; + UINT32 DnsServerIndex; EFI_DHCP4_PACKET_OPTION *Option; EFI_STATUS Status; @@ -160,6 +200,8 @@ HttpBootDhcp4ExtractUriInfo ( SelectIndex = Private->SelectIndex - 1; ASSERT (SelectIndex < HTTP_BOOT_OFFER_MAX_NUM); + DnsServerIndex = 0; + Status = EFI_SUCCESS; // @@ -167,26 +209,74 @@ HttpBootDhcp4ExtractUriInfo ( // HttpOffer contains the boot file URL. // SelectOffer = &Private->OfferBuffer[SelectIndex].Dhcp4; - if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) { - HttpOffer = SelectOffer; + if (Private->FilePathUri == NULL) { + // + // In Corporate environment, we need a HttpOffer. + // + if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || + (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) || + (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) { + HttpOffer = SelectOffer; + } else { + ASSERT (Private->SelectProxyType != HttpOfferTypeMax); + ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0]; + HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4; + } + Private->BootFileUriParser = HttpOffer->UriParser; + Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data; } else { - ASSERT (Private->SelectProxyType != HttpOfferTypeMax); - ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0]; - HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4; + // + // In Home environment the BootFileUri comes from the FilePath. + // + Private->BootFileUriParser = Private->FilePathUriParser; + Private->BootFileUri = Private->FilePathUri; } // - // Configure the default DNS server if server assigned. + // Check the URI scheme. // - if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || (SelectOffer->OfferType == HttpOfferTypeDhcpDns)) { + Status = HttpBootCheckUriScheme (Private->BootFileUri); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status)); + if (Status == EFI_INVALID_PARAMETER) { + AsciiPrint ("\n Error: Invalid URI address.\n"); + } else if (Status == EFI_ACCESS_DENIED) { + AsciiPrint ("\n Error: Access forbidden, only HTTPS connection is allowed.\n"); + } + return Status; + } + + if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || + (SelectOffer->OfferType == HttpOfferTypeDhcpDns) || + (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) { Option = SelectOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER]; ASSERT (Option != NULL); + + // + // Record the Dns Server address list. + // + Private->DnsServerCount = (Option->Length) / sizeof (EFI_IPv4_ADDRESS); + + Private->DnsServerIp = AllocateZeroPool (Private->DnsServerCount * sizeof (EFI_IP_ADDRESS)); + if (Private->DnsServerIp == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) { + CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_ADDRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv4_ADDRESS)); + } + + // + // Configure the default DNS server if server assigned. + // Status = HttpBootRegisterIp4Dns ( Private, Option->Length, Option->Data ); if (EFI_ERROR (Status)) { + FreePool (Private->DnsServerIp); + Private->DnsServerIp = NULL; return Status; } } @@ -195,30 +285,26 @@ HttpBootDhcp4ExtractUriInfo ( // Extract the port from URL, and use default HTTP port 80 if not provided. // Status = HttpUrlGetPort ( - (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data, - HttpOffer->UriParser, + Private->BootFileUri, + Private->BootFileUriParser, &Private->Port ); if (EFI_ERROR (Status) || Private->Port == 0) { Private->Port = 80; } - // - // Record the URI of boot file from the selected HTTP offer. - // - Private->BootFileUriParser = HttpOffer->UriParser; - Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data; - - // // All boot informations are valid here. // - AsciiPrint ("\n URI: %a", Private->BootFileUri); // - // Update the device path to include the IP and boot URI information. + // Update the device path to include the boot resource information. // Status = HttpBootUpdateDevicePath (Private); + if (EFI_ERROR (Status) && Private->DnsServerIp != NULL) { + FreePool (Private->DnsServerIp); + Private->DnsServerIp = NULL; + } return Status; } @@ -241,9 +327,11 @@ HttpBootDhcp6ExtractUriInfo ( HTTP_BOOT_DHCP6_PACKET_CACHE *HttpOffer; UINT32 SelectIndex; UINT32 ProxyIndex; + UINT32 DnsServerIndex; EFI_DHCP6_PACKET_OPTION *Option; EFI_IPv6_ADDRESS IpAddr; CHAR8 *HostName; + UINTN HostNameSize; CHAR16 *HostNameStr; EFI_STATUS Status; @@ -252,6 +340,8 @@ HttpBootDhcp6ExtractUriInfo ( SelectIndex = Private->SelectIndex - 1; ASSERT (SelectIndex < HTTP_BOOT_OFFER_MAX_NUM); + DnsServerIndex = 0; + Status = EFI_SUCCESS; HostName = NULL; // @@ -259,12 +349,41 @@ HttpBootDhcp6ExtractUriInfo ( // HttpOffer contains the boot file URL. // SelectOffer = &Private->OfferBuffer[SelectIndex].Dhcp6; - if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) { - HttpOffer = SelectOffer; + if (Private->FilePathUri == NULL) { + // + // In Corporate environment, we need a HttpOffer. + // + if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || + (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) || + (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) { + HttpOffer = SelectOffer; + } else { + ASSERT (Private->SelectProxyType != HttpOfferTypeMax); + ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0]; + HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6; + } + Private->BootFileUriParser = HttpOffer->UriParser; + Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data; } else { - ASSERT (Private->SelectProxyType != HttpOfferTypeMax); - ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0]; - HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6; + // + // In Home environment the BootFileUri comes from the FilePath. + // + Private->BootFileUriParser = Private->FilePathUriParser; + Private->BootFileUri = Private->FilePathUri; + } + + // + // Check the URI scheme. + // + Status = HttpBootCheckUriScheme (Private->BootFileUri); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "HttpBootDhcp6ExtractUriInfo: %r.\n", Status)); + if (Status == EFI_INVALID_PARAMETER) { + AsciiPrint ("\n Error: Invalid URI address.\n"); + } else if (Status == EFI_ACCESS_DENIED) { + AsciiPrint ("\n Error: Access forbidden, only HTTPS connection is allowed.\n"); + } + return Status; } // @@ -274,30 +393,55 @@ HttpBootDhcp6ExtractUriInfo ( if (EFI_ERROR (Status)) { return Status; } - + // - // Configure the default DNS server if server assigned. + // Register the IPv6 gateway address to the network device. // - if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || (SelectOffer->OfferType == HttpOfferTypeDhcpDns)) { + Status = HttpBootSetIp6Gateway (Private); + if (EFI_ERROR (Status)) { + return Status; + } + + if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || + (SelectOffer->OfferType == HttpOfferTypeDhcpDns) || + (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) { Option = SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER]; ASSERT (Option != NULL); + + // + // Record the Dns Server address list. + // + Private->DnsServerCount = HTONS (Option->OpLen) / sizeof (EFI_IPv6_ADDRESS); + + Private->DnsServerIp = AllocateZeroPool (Private->DnsServerCount * sizeof (EFI_IP_ADDRESS)); + if (Private->DnsServerIp == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) { + CopyMem (&(Private->DnsServerIp[DnsServerIndex].v6), &(((EFI_IPv6_ADDRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv6_ADDRESS)); + } + + // + // Configure the default DNS server if server assigned. + // Status = HttpBootSetIp6Dns ( Private, HTONS (Option->OpLen), Option->Data ); if (EFI_ERROR (Status)) { - return Status; + goto Error; } } // - // Extract the HTTP server Ip frome URL. This is used to Check route table + // Extract the HTTP server Ip from URL. This is used to Check route table // whether can send message to HTTP Server Ip through the GateWay. // Status = HttpUrlGetIp6 ( - (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data, - HttpOffer->UriParser, + Private->BootFileUri, + Private->BootFileUriParser, &IpAddr ); @@ -306,72 +450,69 @@ HttpBootDhcp6ExtractUriInfo ( // The Http server address is expressed by Name Ip, so perform DNS resolution // Status = HttpUrlGetHostName ( - (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data, - HttpOffer->UriParser, + Private->BootFileUri, + Private->BootFileUriParser, &HostName ); if (EFI_ERROR (Status)) { - return Status; + goto Error; } - - HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (CHAR16)); + + HostNameSize = AsciiStrSize (HostName); + HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16)); if (HostNameStr == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Error; } - AsciiStrToUnicodeStr (HostName, HostNameStr); + AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize); + + if (HostName != NULL) { + FreePool (HostName); + } + Status = HttpBootDns (Private, HostNameStr, &IpAddr); FreePool (HostNameStr); if (EFI_ERROR (Status)) { + AsciiPrint ("\n Error: Could not retrieve the host address from DNS server.\n"); goto Error; } } - CopyMem (&Private->ServerIp.v6, &IpAddr, sizeof (EFI_IPv6_ADDRESS)); - - // - // register the IPv6 gateway address to the network device. - // - Status = HttpBootSetIp6Gateway (Private); - if (EFI_ERROR (Status)) { - return Status; - } + CopyMem (&Private->ServerIp.v6, &IpAddr, sizeof (EFI_IPv6_ADDRESS)); // // Extract the port from URL, and use default HTTP port 80 if not provided. // Status = HttpUrlGetPort ( - (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data, - HttpOffer->UriParser, + Private->BootFileUri, + Private->BootFileUriParser, &Private->Port ); if (EFI_ERROR (Status) || Private->Port == 0) { Private->Port = 80; } - // - // Record the URI of boot file from the selected HTTP offer. - // - Private->BootFileUriParser = HttpOffer->UriParser; - Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data; - - // // All boot informations are valid here. // - AsciiPrint ("\n URI: %a", Private->BootFileUri); + // - // Update the device path to include the IP and boot URI information. + // Update the device path to include the boot resource information. // Status = HttpBootUpdateDevicePath (Private); + if (EFI_ERROR (Status)) { + goto Error; + } + + return Status; Error: - - if (HostName != NULL) { - FreePool (HostName); + if (Private->DnsServerIp != NULL) { + FreePool (Private->DnsServerIp); + Private->DnsServerIp = NULL; } - + return Status; } @@ -410,6 +551,40 @@ HttpBootDiscoverBootInfo ( return Status; } +/** + HttpIo Callback function which will be invoked when specified HTTP_IO_CALLBACK_EVENT happened. + + @param[in] EventType Indicate the Event type that occurs in the current callback. + @param[in] Message HTTP message which will be send to, or just received from HTTP server. + @param[in] Context The Callback Context pointer. + + @retval EFI_SUCCESS Tells the HttpIo to continue the HTTP process. + @retval Others Tells the HttpIo to abort the current HTTP process. +**/ +EFI_STATUS +EFIAPI +HttpBootHttpIoCallback ( + IN HTTP_IO_CALLBACK_EVENT EventType, + IN EFI_HTTP_MESSAGE *Message, + IN VOID *Context + ) +{ + HTTP_BOOT_PRIVATE_DATA *Private; + EFI_STATUS Status; + Private = (HTTP_BOOT_PRIVATE_DATA *) Context; + if (Private->HttpBootCallback != NULL) { + Status = Private->HttpBootCallback->Callback ( + Private->HttpBootCallback, + EventType == HttpIoRequest ? HttpBootHttpRequest : HttpBootHttpResponse, + EventType == HttpIoRequest ? FALSE : TRUE, + sizeof (EFI_HTTP_MESSAGE), + (VOID *) Message + ); + return Status; + } + return EFI_SUCCESS; +} + /** Create a HttpIo instance for the file download. @@ -426,6 +601,7 @@ HttpBootCreateHttpIo ( { HTTP_IO_CONFIG_DATA ConfigData; EFI_STATUS Status; + EFI_HANDLE ImageHandle; ASSERT (Private != NULL); @@ -435,17 +611,21 @@ HttpBootCreateHttpIo ( ConfigData.Config4.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT; IP4_COPY_ADDRESS (&ConfigData.Config4.LocalIp, &Private->StationIp.v4); IP4_COPY_ADDRESS (&ConfigData.Config4.SubnetMask, &Private->SubnetMask.v4); + ImageHandle = Private->Ip4Nic->ImageHandle; } else { ConfigData.Config6.HttpVersion = HttpVersion11; ConfigData.Config6.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT; IP6_COPY_ADDRESS (&ConfigData.Config6.LocalIp, &Private->StationIp.v6); + ImageHandle = Private->Ip6Nic->ImageHandle; } Status = HttpIoCreateIo ( - Private->Image, + ImageHandle, Private->Controller, Private->UsingIpv6 ? IP_VERSION_6 : IP_VERSION_4, &ConfigData, + HttpBootHttpIoCallback, + (VOID *) Private, &Private->HttpIo ); if (EFI_ERROR (Status)) { @@ -546,6 +726,7 @@ HttpBootFreeCacheList ( @param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL, then the size of the requested file is returned in BufferSize. + @param[out] ImageType The image type of the downloaded file. @retval EFI_SUCCESS Successfully created. @retval Others Failed to create HttpIo. @@ -556,7 +737,8 @@ HttpBootGetFileFromCache ( IN HTTP_BOOT_PRIVATE_DATA *Private, IN CHAR16 *Uri, IN OUT UINTN *BufferSize, - OUT UINT8 *Buffer + OUT UINT8 *Buffer, + OUT HTTP_BOOT_IMAGE_TYPE *ImageType ) { LIST_ENTRY *Entry; @@ -565,14 +747,10 @@ HttpBootGetFileFromCache ( HTTP_BOOT_ENTITY_DATA *EntityData; UINTN CopyedSize; - if (Uri == NULL || BufferSize == 0 || Buffer == NULL) { + if (Uri == NULL || BufferSize == NULL || Buffer == NULL || ImageType == NULL) { return EFI_INVALID_PARAMETER; } - // - // Search file in the cache list, the cache entry will be released upon a successful - // match. - // NET_LIST_FOR_EACH (Entry, &Private->CacheList) { Cache = NET_LIST_USER_STRUCT (Entry, HTTP_BOOT_CACHE_CONTENT, Link); // @@ -580,10 +758,14 @@ HttpBootGetFileFromCache ( // if ((Cache->RequestData != NULL) && (Cache->RequestData->Url != NULL) && - (StrCmp (Uri, Cache->RequestData->Url) == 0)) - { + (StrCmp (Uri, Cache->RequestData->Url) == 0)) { + // + // Hit in cache, record image type. + // + *ImageType = Cache->ImageType; + // - // Hit cache, check buffer size. + // Check buffer size. // if (*BufferSize < Cache->EntityLength) { *BufferSize = Cache->EntityLength; @@ -606,12 +788,6 @@ HttpBootGetFileFromCache ( } } *BufferSize = CopyedSize; - - // - // On success, free the cached data to release the memory resource. - // - RemoveEntryList (&Cache->Link); - HttpBootFreeCache (Cache); return EFI_SUCCESS; } } @@ -645,6 +821,8 @@ HttpBootGetBootFileCallback ( { HTTP_BOOT_CALLBACK_DATA *CallbackData; HTTP_BOOT_ENTITY_DATA *NewEntityData; + EFI_STATUS Status; + EFI_HTTP_BOOT_CALLBACK_PROTOCOL *HttpBootCallback; // // We only care about the entity data. @@ -654,6 +832,19 @@ HttpBootGetBootFileCallback ( } CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context; + HttpBootCallback = CallbackData->Private->HttpBootCallback; + if (HttpBootCallback != NULL) { + Status = HttpBootCallback->Callback ( + HttpBootCallback, + HttpBootHttpEntityBody, + TRUE, + (UINT32)Length, + Data + ); + if (EFI_ERROR (Status)) { + return Status; + } + } // // Copy data if caller has provided a buffer. // @@ -698,6 +889,7 @@ HttpBootGetBootFileCallback ( @param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL, then the size of the requested file is returned in BufferSize. + @param[out] ImageType The image type of the downloaded file. @retval EFI_SUCCESS The file was loaded. @retval EFI_INVALID_PARAMETER BufferSize is NULL or Buffer Size is not NULL but Buffer is NULL. @@ -713,10 +905,12 @@ HttpBootGetBootFile ( IN HTTP_BOOT_PRIVATE_DATA *Private, IN BOOLEAN HeaderOnly, IN OUT UINTN *BufferSize, - OUT UINT8 *Buffer + OUT UINT8 *Buffer, + OUT HTTP_BOOT_IMAGE_TYPE *ImageType ) { EFI_STATUS Status; + EFI_HTTP_STATUS_CODE StatusCode; CHAR8 *HostName; EFI_HTTP_REQUEST_DATA *RequestData; HTTP_IO_RESPONSE_DATA *ResponseData; @@ -728,6 +922,7 @@ HttpBootGetBootFile ( UINTN ContentLength; HTTP_BOOT_CACHE_CONTENT *Cache; UINT8 *Block; + UINTN UrlSize; CHAR16 *Url; BOOLEAN IdentityMode; UINTN ReceivedSize; @@ -735,7 +930,7 @@ HttpBootGetBootFile ( ASSERT (Private != NULL); ASSERT (Private->HttpCreated); - if (BufferSize == NULL) { + if (BufferSize == NULL || ImageType == NULL) { return EFI_INVALID_PARAMETER; } @@ -746,13 +941,14 @@ HttpBootGetBootFile ( // // First, check whether we already cached the requested Uri. // - Url = AllocatePool ((AsciiStrLen (Private->BootFileUri) + 1) * sizeof (CHAR16)); + UrlSize = AsciiStrSize (Private->BootFileUri); + Url = AllocatePool (UrlSize * sizeof (CHAR16)); if (Url == NULL) { return EFI_OUT_OF_RESOURCES; } - AsciiStrToUnicodeStr (Private->BootFileUri, Url); - if (!HeaderOnly) { - Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer); + AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize); + if (!HeaderOnly && Buffer != NULL) { + Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer, ImageType); if (Status != EFI_NOT_FOUND) { FreePool (Url); return Status; @@ -773,6 +969,7 @@ HttpBootGetBootFile ( Status = EFI_OUT_OF_RESOURCES; goto ERROR_1; } + Cache->ImageType = ImageTypeMax; InitializeListHead (&Cache->EntityDataList); } @@ -806,7 +1003,7 @@ HttpBootGetBootFile ( } Status = HttpBootSetHeader ( HttpIoHeader, - HTTP_FIELD_NAME_HOST, + HTTP_HEADER_HOST, HostName ); FreePool (HostName); @@ -819,7 +1016,7 @@ HttpBootGetBootFile ( // Status = HttpBootSetHeader ( HttpIoHeader, - HTTP_FIELD_NAME_ACCEPT, + HTTP_HEADER_ACCEPT, "*/*" ); if (EFI_ERROR (Status)) { @@ -831,7 +1028,7 @@ HttpBootGetBootFile ( // Status = HttpBootSetHeader ( HttpIoHeader, - HTTP_FIELD_NAME_USER_AGENT, + HTTP_HEADER_USER_AGENT, HTTP_USER_AGENT_EFI_HTTP_BOOT ); if (EFI_ERROR (Status)) { @@ -848,11 +1045,6 @@ HttpBootGetBootFile ( } RequestData->Method = HeaderOnly ? HttpMethodHead : HttpMethodGet; RequestData->Url = Url; - if (RequestData->Url == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto ERROR_4; - } - AsciiStrToUnicodeStr (Private->BootFileUri, RequestData->Url); // // 2.3 Record the request info in a temp cache item. @@ -894,6 +1086,25 @@ HttpBootGetBootFile ( TRUE, ResponseData ); + if (EFI_ERROR (Status) || EFI_ERROR (ResponseData->Status)) { + if (EFI_ERROR (ResponseData->Status)) { + StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode; + HttpBootPrintErrorMessage (StatusCode); + Status = ResponseData->Status; + } + goto ERROR_5; + } + + // + // Check the image type according to server's response. + // + Status = HttpBootCheckImageType ( + Private->BootFileUri, + Private->BootFileUriParser, + ResponseData->HeaderCount, + ResponseData->Headers, + ImageType + ); if (EFI_ERROR (Status)) { goto ERROR_5; } @@ -903,6 +1114,7 @@ HttpBootGetBootFile ( // if (Cache != NULL) { Cache->ResponseData = ResponseData; + Cache->ImageType = *ImageType; } // @@ -915,8 +1127,9 @@ HttpBootGetBootFile ( Context.Buffer = Buffer; Context.BufferSize = *BufferSize; Context.Cache = Cache; + Context.Private = Private; Status = HttpInitMsgParser ( - HeaderOnly? HttpMethodHead : HttpMethodGet, + HeaderOnly ? HttpMethodHead : HttpMethodGet, ResponseData->Response.StatusCode, ResponseData->HeaderCount, ResponseData->Headers, @@ -963,10 +1176,25 @@ HttpBootGetBootFile ( FALSE, &ResponseBody ); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) { + if (EFI_ERROR (ResponseBody.Status)) { + Status = ResponseBody.Status; + } goto ERROR_6; } ReceivedSize += ResponseBody.BodyLength; + if (Private->HttpBootCallback != NULL) { + Status = Private->HttpBootCallback->Callback ( + Private->HttpBootCallback, + HttpBootHttpEntityBody, + TRUE, + (UINT32)ResponseBody.BodyLength, + ResponseBody.Body + ); + if (EFI_ERROR (Status)) { + goto ERROR_6; + } + } } } else { // @@ -1000,7 +1228,10 @@ HttpBootGetBootFile ( FALSE, &ResponseBody ); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) { + if (EFI_ERROR (ResponseBody.Status)) { + Status = ResponseBody.Status; + } goto ERROR_6; } @@ -1029,6 +1260,8 @@ HttpBootGetBootFile ( if (*BufferSize < ContentLength) { Status = EFI_BUFFER_TOO_SMALL; + } else { + Status = EFI_SUCCESS; } *BufferSize = ContentLength; @@ -1044,7 +1277,7 @@ HttpBootGetBootFile ( HttpFreeMsgParser (Parser); } - return EFI_SUCCESS; + return Status; ERROR_6: if (Parser != NULL) { @@ -1076,3 +1309,4 @@ ERROR_1: return Status; } +