-/** @file
- The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.
-
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-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
-http://opensource.org/licenses/bsd-license.php.
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "HttpBootDxe.h"
-
-/**
- Enable the use of UEFI HTTP boot function.
-
- @param[in] Private The pointer to the driver's private data.
-
- @retval EFI_SUCCESS HTTP boot was successfully enabled.
- @retval EFI_INVALID_PARAMETER Private is NULL.
- @retval EFI_ALREADY_STARTED The driver is already in started state.
-
-**/
-EFI_STATUS
-HttpBootStart (
- IN HTTP_BOOT_PRIVATE_DATA *Private
- )
-{
- UINTN Index;
-
- if (Private == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (Private->Started) {
- return EFI_ALREADY_STARTED;
- }
-
- if (!Private->UsingIpv6) {
- //
- // Init the content of cached DHCP offer list.
- //
- ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer));
- for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {
- Private->OfferBuffer[Index].Dhcp4.Packet.Offer.Size = HTTP_BOOT_DHCP4_PACKET_MAX_SIZE;
- }
- } else {
- ASSERT (FALSE);
- }
-
- Private->Started = TRUE;
-
- return EFI_SUCCESS;
-}
-
-/**
- Attempt to complete a DHCPv4 D.O.R.A sequence to retrieve the boot resource information.
-
- @param[in] Private The pointer to the driver's private data.
-
- @retval EFI_SUCCESS Boot info was successfully retrieved.
- @retval EFI_INVALID_PARAMETER Private is NULL.
- @retval EFI_NOT_STARTED The driver is in stopped state.
- @retval EFI_DEVICE_ERROR An unexpected network error occurred.
- @retval Others Other errors as indicated.
-
-**/
-EFI_STATUS
-HttpBootDhcp (
- IN HTTP_BOOT_PRIVATE_DATA *Private
- )
-{
- EFI_STATUS Status;
-
- if (Private == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (!Private->Started) {
- return EFI_NOT_STARTED;
- }
-
- Status = EFI_DEVICE_ERROR;
-
- if (!Private->UsingIpv6) {
- Status = HttpBootDhcp4Dora (Private);
- } else {
- ASSERT (FALSE);
- }
-
- return Status;
-}
-
-/**
- Attempt to download the boot file through HTTP message exchange.
-
- @param[in] Private The pointer to the driver's private data.
- @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return
- code of EFI_SUCCESS, the amount of data transferred to
- Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
- the size of Buffer required to retrieve the requested file.
- @param[in] Buffer The memory buffer to transfer the file to. If Buffer is NULL,
- then the size of the requested file is returned in
- BufferSize.
-
- @retval EFI_SUCCESS Boot file was loaded successfully.
- @retval EFI_INVALID_PARAMETER Private is NULL.
- @retval EFI_NOT_STARTED The driver is in stopped state.
- @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the boot file. BufferSize has
- been updated with the size needed to complete the request.
- @retval EFI_DEVICE_ERROR An unexpected network error occurred.
- @retval Others Other errors as indicated.
-
-**/
-EFI_STATUS
-HttpBootLoadFile (
- IN HTTP_BOOT_PRIVATE_DATA *Private,
- IN OUT UINTN *BufferSize,
- IN VOID *Buffer OPTIONAL
- )
-{
- EFI_STATUS Status;
-
- if (Private == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (!Private->Started) {
- return EFI_NOT_STARTED;
- }
-
- Status = EFI_DEVICE_ERROR;
-
- if (Private->BootFileUri == NULL) {
- //
- // Parse the cached offer to get the boot file URL first.
- //
- Status = HttpBootDiscoverBootInfo (Private);
- if (EFI_ERROR (Status)) {
- return Status;
- }
- }
-
- if (!Private->HttpCreated) {
- //
- // Create HTTP child.
- //
- Status = HttpBootCreateHttpIo (Private);
- if (EFI_ERROR (Status)) {
- return Status;
- }
- }
-
- if (Private->BootFileSize == 0) {
- //
- // Discover the information about the bootfile if we haven't.
- //
-
- //
- // Try to use HTTP HEAD method.
- //
- Status = HttpBootGetBootFile (
- Private,
- TRUE,
- &Private->BootFileSize,
- NULL
- );
- if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
- //
- // Failed to get file size by HEAD method, may be trunked encoding, try HTTP GET method.
- //
- ASSERT (Private->BootFileSize == 0);
- Status = HttpBootGetBootFile (
- Private,
- FALSE,
- &Private->BootFileSize,
- NULL
- );
- if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
- return Status;
- }
- }
- }
-
- if (*BufferSize < Private->BootFileSize) {
- *BufferSize = Private->BootFileSize;
- return EFI_BUFFER_TOO_SMALL;
- }
-
- //
- // Load the boot file into Buffer
- //
- return HttpBootGetBootFile (
- Private,
- FALSE,
- BufferSize,
- Buffer
- );
-}
-
-/**
- Disable the use of UEFI HTTP boot function.
-
- @param[in] Private The pointer to the driver's private data.
-
- @retval EFI_SUCCESS HTTP boot was successfully disabled.
- @retval EFI_NOT_STARTED The driver is already in stopped state.
- @retval EFI_INVALID_PARAMETER Private is NULL.
- @retval Others Unexpected error when stop the function.
-
-**/
-EFI_STATUS
-HttpBootStop (
- IN HTTP_BOOT_PRIVATE_DATA *Private
- )
-{
- UINTN Index;
-
- if (Private == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (!Private->Started) {
- return EFI_NOT_STARTED;
- }
-
- if (Private->HttpCreated) {
- HttpIoDestroyIo (&Private->HttpIo);
- Private->HttpCreated = FALSE;
- }
-
- Private->Started = FALSE;
- ZeroMem (&Private->StationIp, sizeof (EFI_IP_ADDRESS));
- ZeroMem (&Private->SubnetMask, sizeof (EFI_IP_ADDRESS));
- ZeroMem (&Private->GatewayIp, sizeof (EFI_IP_ADDRESS));
- Private->Port = 0;
- Private->BootFileUri = NULL;
- Private->BootFileUriParser = NULL;
- Private->BootFileSize = 0;
- Private->SelectIndex = 0;
- Private->SelectProxyType = HttpOfferTypeMax;
-
- if (!Private->UsingIpv6) {
- for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {
- if (Private->OfferBuffer[Index].Dhcp4.UriParser) {
- HttpUrlFreeParser (Private->OfferBuffer[Index].Dhcp4.UriParser);
- }
- }
- } else {
- ASSERT (FALSE);
- }
-
- ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer));
- Private->OfferNum = 0;
- ZeroMem (Private->OfferCount, sizeof (Private->OfferCount));
- ZeroMem (Private->OfferIndex, sizeof (Private->OfferIndex));
-
- return EFI_SUCCESS;
-}
-
-/**
- Causes the driver to load a specified file.
-
- @param This Protocol instance pointer.
- @param FilePath The device specific path of the file to load.
- @param BootPolicy If TRUE, indicates that the request originates from the
- boot manager is attempting to load FilePath as a boot
- selection. If FALSE, then FilePath must match as exact file
- to be loaded.
- @param BufferSize On input the size of Buffer in bytes. On output with a return
- code of EFI_SUCCESS, the amount of data transferred to
- Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
- the size of Buffer required to retrieve the requested file.
- @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
- then the size of the requested file is returned in
- BufferSize.
-
- @retval EFI_SUCCESS The file was loaded.
- @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy
- @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
- BufferSize is NULL.
- @retval EFI_NO_MEDIA No medium was present to load the file.
- @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
- @retval EFI_NO_RESPONSE The remote system did not respond.
- @retval EFI_NOT_FOUND The file was not found.
- @retval EFI_ABORTED The file load process was manually cancelled.
- @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
- BufferSize has been updated with the size needed to complete
- the request.
-
-**/
-EFI_STATUS
-EFIAPI
-HttpBootDxeLoadFile (
- IN EFI_LOAD_FILE_PROTOCOL *This,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN BOOLEAN BootPolicy,
- IN OUT UINTN *BufferSize,
- IN VOID *Buffer OPTIONAL
- )
-{
- HTTP_BOOT_PRIVATE_DATA *Private;
- BOOLEAN MediaPresent;
- EFI_STATUS Status;
-
- if (This == NULL || BufferSize == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Only support BootPolicy
- //
- if (!BootPolicy) {
- return EFI_UNSUPPORTED;
- }
-
- Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (This);
-
- //
- // Check media status before HTTP boot start
- //
- MediaPresent = TRUE;
- NetLibDetectMedia (Private->Controller, &MediaPresent);
- if (!MediaPresent) {
- return EFI_NO_MEDIA;
- }
-
- //
- // Initialize HTTP boot and load the boot file.
- //
- Status = HttpBootStart (Private);
- if (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED) {
- Status = HttpBootLoadFile (Private, BufferSize, Buffer);
- }
-
- if (Status != EFI_SUCCESS && Status != EFI_BUFFER_TOO_SMALL) {
- HttpBootStop (Private);
- }
-
- return Status;
-}
-
-///
-/// Load File Protocol instance
-///
-GLOBAL_REMOVE_IF_UNREFERENCED
-EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile = {
- HttpBootDxeLoadFile
-};
+/** @file\r
+ The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.\r
+\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
+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
+\r
+#include "HttpBootDxe.h"\r
+\r
+/**\r
+ Enable the use of UEFI HTTP boot function.\r
+\r
+ @param[in] Private The pointer to the driver's private data.\r
+ @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 EFI_DEVICE_PATH_PROTOCOL *FilePath\r
+ )\r
+{\r
+ UINTN Index;\r
+ EFI_STATUS Status;\r
+\r
+ if (Private == NULL || FilePath == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (Private->Started) {\r
+ return EFI_ALREADY_STARTED;\r
+ }\r
+\r
+ //\r
+ // Detect whether using ipv6 or not, and set it to the private data.\r
+ //\r
+ if (UsingIpv6 && Private->Ip6Nic != NULL) {\r
+ Private->UsingIpv6 = TRUE;\r
+ } else if (!UsingIpv6 && Private->Ip4Nic != NULL) {\r
+ Private->UsingIpv6 = FALSE;\r
+ } 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
+ //\r
+ ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer));\r
+ if (!Private->UsingIpv6) {\r
+ for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {\r
+ Private->OfferBuffer[Index].Dhcp4.Packet.Offer.Size = HTTP_BOOT_DHCP4_PACKET_MAX_SIZE;\r
+ }\r
+ } else {\r
+ for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {\r
+ Private->OfferBuffer[Index].Dhcp6.Packet.Offer.Size = HTTP_BOOT_DHCP6_PACKET_MAX_SIZE;\r
+ }\r
+ }\r
+\r
+ if (Private->UsingIpv6) {\r
+ //\r
+ // Set Ip6 policy to Automatic to start the Ip6 router discovery.\r
+ //\r
+ Status = HttpBootSetIp6Policy (Private);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ }\r
+ Private->Started = TRUE;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Attempt to complete a DHCPv4 D.O.R.A or DHCPv6 S.R.A.A sequence to retrieve the boot resource information.\r
+\r
+ @param[in] Private The pointer to the driver's private data.\r
+\r
+ @retval EFI_SUCCESS Boot info was successfully retrieved.\r
+ @retval EFI_INVALID_PARAMETER Private is NULL.\r
+ @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
+EFI_STATUS\r
+HttpBootDhcp (\r
+ IN HTTP_BOOT_PRIVATE_DATA *Private\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (Private == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ \r
+ if (!Private->Started) {\r
+ return EFI_NOT_STARTED;\r
+ }\r
+\r
+ Status = EFI_DEVICE_ERROR;\r
+\r
+ if (!Private->UsingIpv6) {\r
+ //\r
+ // Start D.O.R.A process to get a IPv4 address and other boot information.\r
+ //\r
+ Status = HttpBootDhcp4Dora (Private);\r
+ } else {\r
+ //\r
+ // Start S.A.R.R process to get a IPv6 address and other boot information.\r
+ //\r
+ Status = HttpBootDhcp6Sarr (Private);\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Attempt to download the boot file through HTTP message exchange.\r
+\r
+ @param[in] Private The pointer to the driver's private data.\r
+ @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return\r
+ code of EFI_SUCCESS, the amount of data transferred to\r
+ Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,\r
+ the size of Buffer required to retrieve the requested file.\r
+ @param[in] 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
+\r
+ @retval EFI_SUCCESS Boot file was loaded successfully.\r
+ @retval EFI_INVALID_PARAMETER Private 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
+ 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
+EFI_STATUS\r
+HttpBootLoadFile (\r
+ IN HTTP_BOOT_PRIVATE_DATA *Private,\r
+ IN OUT UINTN *BufferSize,\r
+ IN VOID *Buffer OPTIONAL\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (Private == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ \r
+ if (!Private->Started) {\r
+ return EFI_NOT_STARTED;\r
+ }\r
+\r
+ Status = EFI_DEVICE_ERROR;\r
+\r
+ if (Private->BootFileUri == NULL) {\r
+ //\r
+ // Parse the cached offer to get the boot file URL first.\r
+ //\r
+ Status = HttpBootDiscoverBootInfo (Private);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ if (!Private->HttpCreated) {\r
+ //\r
+ // Create HTTP child.\r
+ //\r
+ Status = HttpBootCreateHttpIo (Private);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ if (Private->BootFileSize == 0) {\r
+ //\r
+ // Discover the information about the bootfile if we haven't.\r
+ //\r
+\r
+ //\r
+ // Try to use HTTP HEAD method.\r
+ //\r
+ Status = HttpBootGetBootFile (\r
+ Private,\r
+ TRUE,\r
+ &Private->BootFileSize,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {\r
+ //\r
+ // Failed to get file size by HEAD method, may be trunked encoding, try HTTP GET method.\r
+ //\r
+ ASSERT (Private->BootFileSize == 0);\r
+ Status = HttpBootGetBootFile (\r
+ Private,\r
+ FALSE,\r
+ &Private->BootFileSize,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {\r
+ return Status;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (*BufferSize < Private->BootFileSize) {\r
+ *BufferSize = Private->BootFileSize;\r
+ return EFI_BUFFER_TOO_SMALL;\r
+ }\r
+\r
+ //\r
+ // Load the boot file into Buffer\r
+ //\r
+ return HttpBootGetBootFile (\r
+ Private,\r
+ FALSE,\r
+ BufferSize,\r
+ Buffer\r
+ );\r
+}\r
+\r
+/**\r
+ Disable the use of UEFI HTTP boot function.\r
+\r
+ @param[in] Private The pointer to the driver's private data.\r
+\r
+ @retval EFI_SUCCESS HTTP boot was successfully disabled.\r
+ @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
+EFI_STATUS\r
+HttpBootStop (\r
+ IN HTTP_BOOT_PRIVATE_DATA *Private\r
+ )\r
+{\r
+ UINTN Index;\r
+\r
+ if (Private == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ \r
+ if (!Private->Started) {\r
+ return EFI_NOT_STARTED;\r
+ }\r
+ \r
+ if (Private->HttpCreated) {\r
+ HttpIoDestroyIo (&Private->HttpIo);\r
+ Private->HttpCreated = FALSE;\r
+ }\r
+ \r
+ Private->Started = FALSE;\r
+ ZeroMem (&Private->StationIp, sizeof (EFI_IP_ADDRESS));\r
+ ZeroMem (&Private->SubnetMask, sizeof (EFI_IP_ADDRESS));\r
+ ZeroMem (&Private->GatewayIp, sizeof (EFI_IP_ADDRESS));\r
+ Private->Port = 0;\r
+ Private->BootFileUri = NULL;\r
+ Private->BootFileUriParser = NULL;\r
+ Private->BootFileSize = 0;\r
+ Private->SelectIndex = 0;\r
+ Private->SelectProxyType = HttpOfferTypeMax; \r
+\r
+ if (!Private->UsingIpv6) {\r
+ //\r
+ // Stop and release the DHCP4 child.\r
+ //\r
+ Private->Dhcp4->Stop (Private->Dhcp4);\r
+ Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r
+\r
+ for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {\r
+ if (Private->OfferBuffer[Index].Dhcp4.UriParser) {\r
+ HttpUrlFreeParser (Private->OfferBuffer[Index].Dhcp4.UriParser);\r
+ }\r
+ }\r
+ } else {\r
+ //\r
+ // Stop and release the DHCP6 child.\r
+ //\r
+ Private->Dhcp6->Stop (Private->Dhcp6);\r
+ Private->Dhcp6->Configure (Private->Dhcp6, NULL);\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
+ }\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
+ HttpBootFreeCacheList (Private);\r
+ \r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Causes the driver to load a specified file.\r
+\r
+ @param This Protocol instance pointer.\r
+ @param FilePath The device specific path of the file to load.\r
+ @param BootPolicy If TRUE, indicates that the request originates from the\r
+ boot manager is attempting to load FilePath as a boot\r
+ selection. If FALSE, then FilePath must match as exact file\r
+ to be loaded.\r
+ @param BufferSize On input the size of Buffer in bytes. On output with a return\r
+ code of EFI_SUCCESS, the amount of data transferred to\r
+ Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,\r
+ the size of Buffer required to retrieve the requested file.\r
+ @param 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
+\r
+ @retval EFI_SUCCESS The file was loaded.\r
+ @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy\r
+ @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or\r
+ BufferSize is NULL.\r
+ @retval EFI_NO_MEDIA No medium was present to load the file.\r
+ @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.\r
+ @retval EFI_NO_RESPONSE The remote system did not respond.\r
+ @retval EFI_NOT_FOUND The file was not found.\r
+ @retval EFI_ABORTED The file load process was manually cancelled.\r
+ @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.\r
+ BufferSize has been updated with the size needed to complete\r
+ the request.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpBootDxeLoadFile (\r
+ IN EFI_LOAD_FILE_PROTOCOL *This,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
+ IN BOOLEAN BootPolicy,\r
+ IN OUT UINTN *BufferSize,\r
+ IN VOID *Buffer OPTIONAL\r
+ )\r
+{\r
+ HTTP_BOOT_PRIVATE_DATA *Private;\r
+ HTTP_BOOT_VIRTUAL_NIC *VirtualNic;\r
+ BOOLEAN MediaPresent;\r
+ BOOLEAN UsingIpv6;\r
+ EFI_STATUS Status;\r
+\r
+ if (This == NULL || BufferSize == NULL || FilePath == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Only support BootPolicy\r
+ //\r
+ if (!BootPolicy) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ VirtualNic = HTTP_BOOT_VIRTUAL_NIC_FROM_LOADFILE (This);\r
+ Private = VirtualNic->Private;\r
+ \r
+ //\r
+ // Check media status before HTTP boot start\r
+ //\r
+ MediaPresent = TRUE;\r
+ NetLibDetectMedia (Private->Controller, &MediaPresent);\r
+ if (!MediaPresent) {\r
+ return EFI_NO_MEDIA;\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
+ // Initialize HTTP boot.\r
+ //\r
+ Status = HttpBootStart (Private, UsingIpv6, FilePath);\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ //\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
+ 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
+\r
+ if (Status != EFI_SUCCESS && Status != EFI_BUFFER_TOO_SMALL) {\r
+ HttpBootStop (Private);\r
+ } else {\r
+ if (!Private->UsingIpv6) {\r
+ //\r
+ // Stop and release the DHCP4 child.\r
+ //\r
+ Private->Dhcp4->Stop (Private->Dhcp4);\r
+ Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r
+ } else {\r
+ //\r
+ // Stop and release the DHCP6 child.\r
+ //\r
+ Private->Dhcp6->Stop (Private->Dhcp6);\r
+ Private->Dhcp6->Configure (Private->Dhcp6, NULL);\r
+ }\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+///\r
+/// Load File Protocol instance\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED \r
+EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile = {\r
+ HttpBootDxeLoadFile\r
+};\r