From 56b1ab8ca30fc40c1f57a586c935cbbf18befac2 Mon Sep 17 00:00:00 2001 From: Saloni Kasbekar Date: Wed, 25 Mar 2026 10:53:26 -0700 Subject: [PATCH] NetworkPkg/HttpBootDxe: Print TLS errors on screen during HTTP boot Install EDKII_HTTP_CALLBACK_PROTOCOL in HttpBootDxe to receive TLS events from HttpDxe during the HTTP Boot process. When a TLS error occurs (failed TLS session connection or TLS configuration), print an error message on screen using AsciiPrint(). The callback is installed in HttpBootInstallCallback() and uninstalled in HttpBootUninstallCallback(), ensuring TLS errors are only printed during the HTTP Boot process and not for other TLS accesses. Signed-off-by: Saloni Kasbekar --- NetworkPkg/HttpBootDxe/HttpBootDxe.h | 10 +++ NetworkPkg/HttpBootDxe/HttpBootDxe.inf | 1 + NetworkPkg/HttpBootDxe/HttpBootImpl.c | 91 ++++++++++++++++++++++++-- NetworkPkg/HttpBootDxe/HttpBootImpl.h | 19 ++++++ 4 files changed, 115 insertions(+), 6 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/HttpBootDxe.h index d8b722fbd4..e86ed980b6 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h @@ -59,6 +59,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // #include #include +#include // // Consumed Guids @@ -139,6 +140,14 @@ struct _HTTP_BOOT_VIRTUAL_NIC { HTTP_BOOT_PRIVATE_DATA_SIGNATURE \ ) +#define HTTP_BOOT_PRIVATE_DATA_FROM_HTTP_CALLBACK_PROTOCOL(HttpCallbackProtocol) \ + CR ( \ + HttpCallbackProtocol, \ + HTTP_BOOT_PRIVATE_DATA, \ + HttpCallback, \ + HTTP_BOOT_PRIVATE_DATA_SIGNATURE \ + ) + struct _HTTP_BOOT_PRIVATE_DATA { UINT32 Signature; EFI_HANDLE Controller; @@ -174,6 +183,7 @@ struct _HTTP_BOOT_PRIVATE_DATA { UINT32 Id; EFI_HTTP_BOOT_CALLBACK_PROTOCOL *HttpBootCallback; EFI_HTTP_BOOT_CALLBACK_PROTOCOL LoadFileCallback; + EDKII_HTTP_CALLBACK_PROTOCOL HttpCallback; // // Data for the default HTTP Boot callback protocol diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf index 6caa30f2d2..e620c6a69d 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf @@ -82,6 +82,7 @@ gEfiRamDiskProtocolGuid ## SOMETIMES_CONSUMES gEfiHiiConfigAccessProtocolGuid ## BY_START gEfiHttpBootCallbackProtocolGuid ## SOMETIMES_PRODUCES + gEdkiiHttpCallbackProtocolGuid ## SOMETIMES_PRODUCES gEfiAdapterInformationProtocolGuid ## SOMETIMES_CONSUMES [Guids] diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c index dcc270770e..768167bc19 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c @@ -9,6 +9,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "HttpBootDxe.h" +// +// Forward declaration for HttpBootUninstallCallback which is called from +// HttpBootInstallCallback's error path before its definition. +// +VOID +HttpBootUninstallCallback ( + IN HTTP_BOOT_PRIVATE_DATA *Private + ); + /** Install HTTP Boot Callback Protocol if not installed before. @@ -63,6 +72,27 @@ HttpBootInstallCallback ( Private->HttpBootCallback = &Private->LoadFileCallback; } + // + // Install the EDKII HTTP Callback Protocol to receive TLS events + // during the HTTP Boot process. + // + Private->HttpCallback.Callback = HttpBootHttpCallback; + Status = gBS->InstallProtocolInterface ( + &ControllerHandle, + &gEdkiiHttpCallbackProtocolGuid, + EFI_NATIVE_INTERFACE, + &Private->HttpCallback + ); + if (EFI_ERROR (Status)) { + // + // Clear the callback pointer so HttpBootUninstallCallback does not attempt + // to uninstall the EDKII HTTP Callback Protocol which was never installed. + // + Private->HttpCallback.Callback = NULL; + HttpBootUninstallCallback (Private); + return Status; + } + return EFI_SUCCESS; } @@ -77,15 +107,16 @@ HttpBootUninstallCallback ( IN HTTP_BOOT_PRIVATE_DATA *Private ) { + EFI_STATUS Status; EFI_HANDLE ControllerHandle; - if (Private->HttpBootCallback == &Private->LoadFileCallback) { - if (!Private->UsingIpv6) { - ControllerHandle = Private->Ip4Nic->Controller; - } else { - ControllerHandle = Private->Ip6Nic->Controller; - } + if (!Private->UsingIpv6) { + ControllerHandle = Private->Ip4Nic->Controller; + } else { + ControllerHandle = Private->Ip6Nic->Controller; + } + if (Private->HttpBootCallback == &Private->LoadFileCallback) { gBS->UninstallProtocolInterface ( ControllerHandle, &gEfiHttpBootCallbackProtocolGuid, @@ -93,6 +124,19 @@ HttpBootUninstallCallback ( ); Private->HttpBootCallback = NULL; } + + if (Private->HttpCallback.Callback != NULL) { + Status = gBS->UninstallProtocolInterface ( + ControllerHandle, + &gEdkiiHttpCallbackProtocolGuid, + &Private->HttpCallback + ); + if (!EFI_ERROR (Status)) { + Private->HttpCallback.Callback = NULL; + } else { + DEBUG ((DEBUG_ERROR, "HttpBootUninstallCallback: Failed to uninstall EDKII HTTP Callback Protocol - %r\n", Status)); + } + } } /** @@ -930,3 +974,38 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_HTTP_BOOT_CALLBACK_PROTOCOL gHttpBootDxeHttpBootCallback = { HttpBootCallback }; + +/** + Callback function that is invoked when an HTTP event occurs during HTTP Boot. + + This function handles TLS-related events (HttpEventTlsConnectSession and + HttpEventTlsConfigured) and prints error messages to the screen when a TLS + error is encountered during the HTTP Boot process. + + @param[in] This Pointer to the EDKII_HTTP_CALLBACK_PROTOCOL instance. + @param[in] Event The event that occurs in the current state. + @param[in] EventStatus The Status of Event, EFI_SUCCESS or other errors. +**/ +VOID +EFIAPI +HttpBootHttpCallback ( + IN EDKII_HTTP_CALLBACK_PROTOCOL *This, + IN EDKII_HTTP_CALLBACK_EVENT Event, + IN EFI_STATUS EventStatus + ) +{ + if (EFI_ERROR (EventStatus)) { + switch (Event) { + case HttpEventTlsConnectSession: + AsciiPrint ("\n Error: TLS session connection failed - %r.\n", EventStatus); + break; + + case HttpEventTlsConfigured: + AsciiPrint ("\n Error: TLS configuration failed - %r.\n", EventStatus); + break; + + default: + break; + } + } +} diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.h b/NetworkPkg/HttpBootDxe/HttpBootImpl.h index 5eeecb41e4..17fcd23653 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.h +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.h @@ -52,3 +52,22 @@ HttpBootStop ( ); extern EFI_HTTP_BOOT_CALLBACK_PROTOCOL gHttpBootDxeHttpBootCallback; + +/** + Callback function that is invoked when an HTTP event occurs during HTTP Boot. + + This function handles TLS-related events (HttpEventTlsConnectSession and + HttpEventTlsConfigured) and prints error messages to the screen when a TLS + error is encountered during the HTTP Boot process. + + @param[in] This Pointer to the EDKII_HTTP_CALLBACK_PROTOCOL instance. + @param[in] Event The event that occurs in the current state. + @param[in] EventStatus The Status of Event, EFI_SUCCESS or other errors. +**/ +VOID +EFIAPI +HttpBootHttpCallback ( + IN EDKII_HTTP_CALLBACK_PROTOCOL *This, + IN EDKII_HTTP_CALLBACK_EVENT Event, + IN EFI_STATUS EventStatus + );