summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/HttpBootDxe/HttpBootImpl.c
diff options
context:
space:
mode:
Diffstat (limited to 'NetworkPkg/HttpBootDxe/HttpBootImpl.c')
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootImpl.c294
1 files changed, 153 insertions, 141 deletions
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
index 79cc5697cc..3da585a291 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
@@ -20,11 +20,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
HttpBootInstallCallback (
- IN HTTP_BOOT_PRIVATE_DATA *Private
+ IN HTTP_BOOT_PRIVATE_DATA *Private
)
{
- EFI_STATUS Status;
- EFI_HANDLE ControllerHandle;
+ EFI_STATUS Status;
+ EFI_HANDLE ControllerHandle;
if (!Private->UsingIpv6) {
ControllerHandle = Private->Ip4Nic->Controller;
@@ -38,10 +38,9 @@ HttpBootInstallCallback (
Status = gBS->HandleProtocol (
ControllerHandle,
&gEfiHttpBootCallbackProtocolGuid,
- (VOID **) &Private->HttpBootCallback
+ (VOID **)&Private->HttpBootCallback
);
if (Status == EFI_UNSUPPORTED) {
-
CopyMem (
&Private->LoadFileCallback,
&gHttpBootDxeHttpBootCallback,
@@ -60,6 +59,7 @@ HttpBootInstallCallback (
if (EFI_ERROR (Status)) {
return Status;
}
+
Private->HttpBootCallback = &Private->LoadFileCallback;
}
@@ -74,15 +74,15 @@ HttpBootInstallCallback (
**/
VOID
HttpBootUninstallCallback (
- IN HTTP_BOOT_PRIVATE_DATA *Private
+ IN HTTP_BOOT_PRIVATE_DATA *Private
)
{
if (Private->HttpBootCallback == &Private->LoadFileCallback) {
gBS->UninstallProtocolInterface (
- Private->Controller,
- &gEfiHttpBootCallbackProtocolGuid,
- &Private->HttpBootCallback
- );
+ Private->Controller,
+ &gEfiHttpBootCallbackProtocolGuid,
+ &Private->HttpBootCallback
+ );
Private->HttpBootCallback = NULL;
}
}
@@ -108,18 +108,18 @@ HttpBootUninstallCallback (
**/
EFI_STATUS
HttpBootStart (
- IN HTTP_BOOT_PRIVATE_DATA *Private,
- IN BOOLEAN UsingIpv6,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath
+ IN HTTP_BOOT_PRIVATE_DATA *Private,
+ IN BOOLEAN UsingIpv6,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
- UINTN Index;
- EFI_STATUS Status;
- CHAR8 *Uri;
+ UINTN Index;
+ EFI_STATUS Status;
+ CHAR8 *Uri;
Uri = NULL;
- if (Private == NULL || FilePath == NULL) {
+ if ((Private == NULL) || (FilePath == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -143,7 +143,8 @@ HttpBootStart (
// recorded before.
//
if ((UsingIpv6 != Private->UsingIpv6) ||
- ((Uri != NULL) && (AsciiStrCmp (Private->BootFileUri, Uri) != 0))) {
+ ((Uri != NULL) && (AsciiStrCmp (Private->BootFileUri, Uri) != 0)))
+ {
//
// Restart is required, first stop then continue this start function.
//
@@ -152,6 +153,7 @@ HttpBootStart (
if (Uri != NULL) {
FreePool (Uri);
}
+
return Status;
}
} else {
@@ -161,6 +163,7 @@ HttpBootStart (
if (Uri != NULL) {
FreePool (Uri);
}
+
return EFI_ALREADY_STARTED;
}
}
@@ -168,14 +171,15 @@ HttpBootStart (
//
// Detect whether using ipv6 or not, and set it to the private data.
//
- if (UsingIpv6 && Private->Ip6Nic != NULL) {
+ if (UsingIpv6 && (Private->Ip6Nic != NULL)) {
Private->UsingIpv6 = TRUE;
- } else if (!UsingIpv6 && Private->Ip4Nic != NULL) {
+ } else if (!UsingIpv6 && (Private->Ip4Nic != NULL)) {
Private->UsingIpv6 = FALSE;
} else {
if (Uri != NULL) {
FreePool (Uri);
}
+
return EFI_UNSUPPORTED;
}
@@ -186,7 +190,7 @@ HttpBootStart (
if (Private->FilePathUri != NULL) {
Status = HttpParseUrl (
Private->FilePathUri,
- (UINT32) AsciiStrLen (Private->FilePathUri),
+ (UINT32)AsciiStrLen (Private->FilePathUri),
FALSE,
&Private->FilePathUriParser
);
@@ -219,7 +223,8 @@ HttpBootStart (
return Status;
}
}
- Private->Started = TRUE;
+
+ Private->Started = TRUE;
Print (L"\n>>Start HTTP Boot over IPv%d", Private->UsingIpv6 ? 6 : 4);
return EFI_SUCCESS;
@@ -239,10 +244,10 @@ HttpBootStart (
**/
EFI_STATUS
HttpBootDhcp (
- IN HTTP_BOOT_PRIVATE_DATA *Private
+ IN HTTP_BOOT_PRIVATE_DATA *Private
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (Private == NULL) {
return EFI_INVALID_PARAMETER;
@@ -260,7 +265,7 @@ HttpBootDhcp (
//
Status = HttpBootDhcp4Dora (Private);
} else {
- //
+ //
// Start S.A.R.R process to get a IPv6 address and other boot information.
//
Status = HttpBootDhcp6Sarr (Private);
@@ -294,19 +299,19 @@ HttpBootDhcp (
**/
EFI_STATUS
HttpBootLoadFile (
- IN HTTP_BOOT_PRIVATE_DATA *Private,
- IN OUT UINTN *BufferSize,
- IN VOID *Buffer OPTIONAL,
- OUT HTTP_BOOT_IMAGE_TYPE *ImageType
+ IN HTTP_BOOT_PRIVATE_DATA *Private,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer OPTIONAL,
+ OUT HTTP_BOOT_IMAGE_TYPE *ImageType
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
- if (Private == NULL || ImageType == NULL || BufferSize == NULL ) {
+ if ((Private == NULL) || (ImageType == NULL) || (BufferSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
- if (*BufferSize != 0 && Buffer == NULL) {
+ if ((*BufferSize != 0) && (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -315,7 +320,7 @@ HttpBootLoadFile (
}
Status = HttpBootInstallCallback (Private);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
@@ -355,7 +360,7 @@ HttpBootLoadFile (
NULL,
&Private->ImageType
);
- if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
+ 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.
//
@@ -367,7 +372,7 @@ HttpBootLoadFile (
NULL,
&Private->ImageType
);
- if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
+ if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
AsciiPrint ("\n Error: Could not retrieve NBP file size from HTTP server.\n");
goto ON_EXIT;
}
@@ -376,8 +381,8 @@ HttpBootLoadFile (
if (*BufferSize < Private->BootFileSize) {
*BufferSize = Private->BootFileSize;
- *ImageType = Private->ImageType;
- Status = EFI_BUFFER_TOO_SMALL;
+ *ImageType = Private->ImageType;
+ Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
@@ -398,7 +403,7 @@ ON_EXIT:
if (EFI_ERROR (Status)) {
if (Status == EFI_ACCESS_DENIED) {
AsciiPrint ("\n Error: Could not establish connection with HTTP server.\n");
- } else if (Status == EFI_BUFFER_TOO_SMALL && Buffer != NULL) {
+ } else if ((Status == EFI_BUFFER_TOO_SMALL) && (Buffer != NULL)) {
AsciiPrint ("\n Error: Buffer size is smaller than the requested file.\n");
} else if (Status == EFI_OUT_OF_RESOURCES) {
AsciiPrint ("\n Error: Could not allocate I/O buffers.\n");
@@ -429,10 +434,10 @@ ON_EXIT:
**/
EFI_STATUS
HttpBootStop (
- IN HTTP_BOOT_PRIVATE_DATA *Private
+ IN HTTP_BOOT_PRIVATE_DATA *Private
)
{
- UINTN Index;
+ UINTN Index;
if (Private == NULL) {
return EFI_INVALID_PARAMETER;
@@ -451,12 +456,12 @@ HttpBootStop (
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->Port = 0;
+ Private->BootFileUri = NULL;
Private->BootFileUriParser = NULL;
- Private->BootFileSize = 0;
- Private->SelectIndex = 0;
- Private->SelectProxyType = HttpOfferTypeMax;
+ Private->BootFileSize = 0;
+ Private->SelectIndex = 0;
+ Private->SelectProxyType = HttpOfferTypeMax;
if (!Private->UsingIpv6) {
//
@@ -489,10 +494,10 @@ HttpBootStop (
Private->DnsServerIp = NULL;
}
- if (Private->FilePathUri!= NULL) {
+ if (Private->FilePathUri != NULL) {
FreePool (Private->FilePathUri);
HttpUrlFreeParser (Private->FilePathUriParser);
- Private->FilePathUri = NULL;
+ Private->FilePathUri = NULL;
Private->FilePathUriParser = NULL;
}
@@ -540,21 +545,21 @@ HttpBootStop (
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
+ 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;
- HTTP_BOOT_VIRTUAL_NIC *VirtualNic;
- EFI_STATUS MediaStatus;
- BOOLEAN UsingIpv6;
- EFI_STATUS Status;
- HTTP_BOOT_IMAGE_TYPE ImageType;
-
- if (This == NULL || BufferSize == NULL || FilePath == NULL) {
+ HTTP_BOOT_PRIVATE_DATA *Private;
+ HTTP_BOOT_VIRTUAL_NIC *VirtualNic;
+ EFI_STATUS MediaStatus;
+ BOOLEAN UsingIpv6;
+ EFI_STATUS Status;
+ HTTP_BOOT_IMAGE_TYPE ImageType;
+
+ if ((This == NULL) || (BufferSize == NULL) || (FilePath == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -566,7 +571,7 @@ HttpBootDxeLoadFile (
}
VirtualNic = HTTP_BOOT_VIRTUAL_NIC_FROM_LOADFILE (This);
- Private = VirtualNic->Private;
+ Private = VirtualNic->Private;
//
// Check media status before HTTP boot start
@@ -590,7 +595,7 @@ HttpBootDxeLoadFile (
// Initialize HTTP boot.
//
Status = HttpBootStart (Private, UsingIpv6, FilePath);
- if (Status != EFI_SUCCESS && Status != EFI_ALREADY_STARTED) {
+ if ((Status != EFI_SUCCESS) && (Status != EFI_ALREADY_STARTED)) {
return Status;
}
@@ -598,20 +603,21 @@ HttpBootDxeLoadFile (
// Load the boot file.
//
ImageType = ImageTypeMax;
- Status = HttpBootLoadFile (Private, BufferSize, Buffer, &ImageType);
+ Status = HttpBootLoadFile (Private, BufferSize, Buffer, &ImageType);
if (EFI_ERROR (Status)) {
- if (Status == EFI_BUFFER_TOO_SMALL && (ImageType == ImageTypeVirtualCd || ImageType == ImageTypeVirtualDisk)) {
+ if ((Status == EFI_BUFFER_TOO_SMALL) && ((ImageType == ImageTypeVirtualCd) || (ImageType == ImageTypeVirtualDisk))) {
Status = EFI_WARN_FILE_SYSTEM;
} else if (Status != EFI_BUFFER_TOO_SMALL) {
HttpBootStop (Private);
}
+
return Status;
}
//
// Register the RAM Disk to the system if needed.
//
- if (ImageType == ImageTypeVirtualCd || ImageType == ImageTypeVirtualDisk) {
+ if ((ImageType == ImageTypeVirtualCd) || (ImageType == ImageTypeVirtualDisk)) {
Status = HttpBootRegisterRamDisk (Private, *BufferSize, Buffer, ImageType);
if (!EFI_ERROR (Status)) {
Status = EFI_WARN_FILE_SYSTEM;
@@ -659,11 +665,11 @@ EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile = {
EFI_STATUS
EFIAPI
HttpBootCallback (
- IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL *This,
- IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE DataType,
- IN BOOLEAN Received,
- IN UINT32 DataLength,
- IN VOID *Data OPTIONAL
+ IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL *This,
+ IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE DataType,
+ IN BOOLEAN Received,
+ IN UINT32 DataLength,
+ IN VOID *Data OPTIONAL
)
{
EFI_HTTP_MESSAGE *HttpMessage;
@@ -671,89 +677,95 @@ HttpBootCallback (
HTTP_BOOT_PRIVATE_DATA *Private;
UINT32 Percentage;
- Private = HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_PROTOCOL(This);
+ Private = HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_PROTOCOL (This);
switch (DataType) {
- case HttpBootDhcp4:
- case HttpBootDhcp6:
- Print (L".");
- break;
-
- case HttpBootHttpRequest:
- if (Data != NULL) {
- HttpMessage = (EFI_HTTP_MESSAGE *) Data;
- if (HttpMessage->Data.Request->Method == HttpMethodGet &&
- HttpMessage->Data.Request->Url != NULL) {
- Print (L"\n URI: %s\n", HttpMessage->Data.Request->Url);
+ case HttpBootDhcp4:
+ case HttpBootDhcp6:
+ Print (L".");
+ break;
+
+ case HttpBootHttpRequest:
+ if (Data != NULL) {
+ HttpMessage = (EFI_HTTP_MESSAGE *)Data;
+ if ((HttpMessage->Data.Request->Method == HttpMethodGet) &&
+ (HttpMessage->Data.Request->Url != NULL))
+ {
+ Print (L"\n URI: %s\n", HttpMessage->Data.Request->Url);
+ }
+ }
+
+ break;
+
+ case HttpBootHttpResponse:
+ if (Data != NULL) {
+ HttpMessage = (EFI_HTTP_MESSAGE *)Data;
+
+ if (HttpMessage->Data.Response != NULL) {
+ if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->StatusCode)) {
+ //
+ // Server indicates the resource has been redirected to a different URL
+ // according to the section 6.4 of RFC7231 and the RFC 7538.
+ // Display the redirect information on the screen.
+ //
+ HttpHeader = HttpFindHeader (
+ HttpMessage->HeaderCount,
+ HttpMessage->Headers,
+ HTTP_HEADER_LOCATION
+ );
+ if (HttpHeader != NULL) {
+ Print (L"\n HTTP ERROR: Resource Redirected.\n New Location: %a\n", HttpHeader->FieldValue);
+ }
+
+ break;
+ }
+ }
+
+ HttpHeader = HttpFindHeader (
+ HttpMessage->HeaderCount,
+ HttpMessage->Headers,
+ HTTP_HEADER_CONTENT_LENGTH
+ );
+ if (HttpHeader != NULL) {
+ Private->FileSize = AsciiStrDecimalToUintn (HttpHeader->FieldValue);
+ Private->ReceivedSize = 0;
+ Private->Percentage = 0;
+ }
}
- }
- break;
- case HttpBootHttpResponse:
- if (Data != NULL) {
- HttpMessage = (EFI_HTTP_MESSAGE *) Data;
+ break;
- if (HttpMessage->Data.Response != NULL) {
- if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->StatusCode)) {
+ case HttpBootHttpEntityBody:
+ if (DataLength != 0) {
+ if (Private->FileSize != 0) {
//
- // Server indicates the resource has been redirected to a different URL
- // according to the section 6.4 of RFC7231 and the RFC 7538.
- // Display the redirect information on the screen.
+ // We already know the file size, print in percentage format.
//
- HttpHeader = HttpFindHeader (
- HttpMessage->HeaderCount,
- HttpMessage->Headers,
- HTTP_HEADER_LOCATION
- );
- if (HttpHeader != NULL) {
- Print (L"\n HTTP ERROR: Resource Redirected.\n New Location: %a\n", HttpHeader->FieldValue);
+ if (Private->ReceivedSize == 0) {
+ Print (L" File Size: %lu Bytes\n", Private->FileSize);
}
- break;
- }
- }
- HttpHeader = HttpFindHeader (
- HttpMessage->HeaderCount,
- HttpMessage->Headers,
- HTTP_HEADER_CONTENT_LENGTH
- );
- if (HttpHeader != NULL) {
- Private->FileSize = AsciiStrDecimalToUintn (HttpHeader->FieldValue);
- Private->ReceivedSize = 0;
- Private->Percentage = 0;
- }
- }
- break;
-
- case HttpBootHttpEntityBody:
- if (DataLength != 0) {
- if (Private->FileSize != 0) {
- //
- // We already know the file size, print in percentage format.
- //
- if (Private->ReceivedSize == 0) {
- Print (L" File Size: %lu Bytes\n", Private->FileSize);
- }
- Private->ReceivedSize += DataLength;
- Percentage = (UINT32) DivU64x64Remainder (MultU64x32 (Private->ReceivedSize, 100), Private->FileSize, NULL);
- if (Private->Percentage != Percentage) {
- Private->Percentage = Percentage;
- Print (L"\r Downloading...%d%%", Percentage);
+ Private->ReceivedSize += DataLength;
+ Percentage = (UINT32)DivU64x64Remainder (MultU64x32 (Private->ReceivedSize, 100), Private->FileSize, NULL);
+ if (Private->Percentage != Percentage) {
+ Private->Percentage = Percentage;
+ Print (L"\r Downloading...%d%%", Percentage);
+ }
+ } else {
+ //
+ // In some case we couldn't get the file size from the HTTP header, so we
+ // just print the downloaded file size.
+ //
+ Private->ReceivedSize += DataLength;
+ Print (L"\r Downloading...%lu Bytes", Private->ReceivedSize);
}
- } else {
- //
- // In some case we couldn't get the file size from the HTTP header, so we
- // just print the downloaded file size.
- //
- Private->ReceivedSize += DataLength;
- Print (L"\r Downloading...%lu Bytes", Private->ReceivedSize);
}
- }
- break;
- default:
- break;
- };
+ break;
+
+ default:
+ break;
+ }
return EFI_SUCCESS;
}