[edk2-devel] [PATCH V2 4/6] RedfishPkg/RedfishRestExDxe: Implement EDKII_HTTP_CALLBACK_PROTOCOL

Chang, Abner via groups.io posted 6 patches 2 years, 1 month ago
[edk2-devel] [PATCH V2 4/6] RedfishPkg/RedfishRestExDxe: Implement EDKII_HTTP_CALLBACK_PROTOCOL
Posted by Chang, Abner via groups.io 2 years, 1 month ago
From: Abner Chang <abner.chang@amd.com>

Implement EDKII_HTTP_CALLBACK_PROTOCOL that listens to
HttpEventTlsConfigured event for reconfiguring TLS configuration
data.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../RedfishRestExDxe/RedfishRestExDxe.inf     |  3 +
 .../RedfishRestExDxe/RedfishRestExDriver.h    | 32 ++++++---
 .../RedfishRestExDxe/RedfishRestExDriver.c    | 70 +++++++++++++++++++
 3 files changed, 95 insertions(+), 10 deletions(-)

diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf b/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
index 64e6343bfbf..6da416ddb92 100644
--- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
+++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
@@ -5,6 +5,7 @@
 #  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
 #  Copyright (c) 2023, American Megatrends International LLC.
 #  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -57,6 +58,8 @@
   gEfiHttpServiceBindingProtocolGuid              ## TO_START
   gEfiHttpProtocolGuid                            ## TO_START
   gEfiDevicePathProtocolGuid                      ## TO_START
+  gEdkiiHttpCallbackProtocolGuid                  ## CONSUMES
+  gEfiTlsProtocolGuid                             ## CONSUMES
 
 [Pcd]
   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExServiceAccessModeInBand ## CONSUMES
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h
index 6b94e5814c4..929691cea35 100644
--- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h
+++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h
@@ -4,6 +4,7 @@
   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
   Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>
+  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -32,6 +33,8 @@
 #include <Protocol/DriverBinding.h>
 #include <Protocol/RestEx.h>
 #include <Protocol/ServiceBinding.h>
+#include <Protocol/HttpCallback.h>
+#include <Protocol/Tls.h>
 
 ///
 /// Protocol instances
@@ -67,6 +70,9 @@ typedef struct _RESTEX_INSTANCE RESTEX_INSTANCE;
 #define RESTEX_INSTANCE_FROM_THIS(a)  \
   CR (a, RESTEX_INSTANCE, RestEx, RESTEX_INSTANCE_SIGNATURE)
 
+#define RESTEX_INSTANCE_FROM_HTTP_CALLBACK(a)  \
+  CR (a, RESTEX_INSTANCE, HttpCallbakFunction, RESTEX_INSTANCE_SIGNATURE)
+
 #define RESTEX_STATE_UNCONFIGED  0
 #define RESTEX_STATE_CONFIGED    1
 
@@ -94,25 +100,31 @@ struct _RESTEX_SERVICE {
 #define RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY  0x00000002
 
 struct _RESTEX_INSTANCE {
-  UINT32                     Signature;
-  LIST_ENTRY                 Link;
+  UINT32                        Signature;
+  LIST_ENTRY                    Link;
 
-  EFI_REST_EX_PROTOCOL       RestEx;
+  EFI_REST_EX_PROTOCOL          RestEx;
 
-  INTN                       State;
-  BOOLEAN                    InDestroy;
+  INTN                          State;
+  BOOLEAN                       InDestroy;
 
-  RESTEX_SERVICE             *Service;
-  EFI_HANDLE                 ChildHandle;
+  RESTEX_SERVICE                *Service;
+  EFI_HANDLE                    ChildHandle;
 
-  EFI_REST_EX_CONFIG_DATA    ConfigData;
+  EFI_REST_EX_CONFIG_DATA       ConfigData;
 
   //
   // HTTP_IO to access the HTTP service
   //
-  HTTP_IO                    HttpIo;
+  HTTP_IO                       HttpIo;
+
+  //
+  // EDKII_HTTP_CALLBACK_PROTOCOL that listens to
+  // HttpEventInitSession event.
+  //
+  EDKII_HTTP_CALLBACK_PROTOCOL  HttpCallbakFunction;
 
-  UINT32                     Flags;
+  UINT32                        Flags;
 };
 
 typedef struct {
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
index 7036aed4268..39221989c49 100644
--- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
+++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
@@ -4,6 +4,7 @@
   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
   Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -585,6 +586,53 @@ RedfishRestExDriverBindingStop (
   return Status;
 }
 
+/**
+  Callback function that is invoked when HTTP event occurs.
+
+  @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
+RestExHttpCallback (
+  IN EDKII_HTTP_CALLBACK_PROTOCOL  *This,
+  IN EDKII_HTTP_CALLBACK_EVENT     Event,
+  IN EFI_STATUS                    EventStatus
+  )
+{
+  EFI_STATUS        Status;
+  EFI_TLS_PROTOCOL  *TlsProtocol;
+  RESTEX_INSTANCE   *Instance;
+  EFI_TLS_VERIFY    TlsVerifyMethod;
+
+  if ((Event == HttpEventTlsConfigured) && (EventStatus == EFI_SUCCESS)) {
+    // Reconfigure TLS configuration data.
+    Instance = RESTEX_INSTANCE_FROM_HTTP_CALLBACK (This);
+    Status   = gBS->HandleProtocol (
+                      Instance->HttpIo.Handle,
+                      &gEfiTlsProtocolGuid,
+                      (VOID **)&TlsProtocol
+                      );
+    if (EFI_ERROR (Status)) {
+      return;
+    }
+
+    TlsVerifyMethod = EFI_TLS_VERIFY_NONE;
+    Status          = TlsProtocol->SetSessionData (
+                                     TlsProtocol,
+                                     EfiTlsVerifyMethod,
+                                     &TlsVerifyMethod,
+                                     sizeof (EFI_TLS_VERIFY)
+                                     );
+    if (!EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_MANAGEABILITY, "%a: REST EX reconfigures TLS verify method.\n", __func__));
+    }
+  }
+
+  return;
+}
+
 /**
   Creates a child handle and installs a protocol.
 
@@ -699,6 +747,19 @@ RedfishRestExServiceBindingCreateChild (
     goto ON_ERROR;
   }
 
+  // Initial HTTP callback funciton on this REST EX instance
+  Instance->HttpCallbakFunction.Callback = RestExHttpCallback;
+  Status                                 = gBS->InstallProtocolInterface (
+                                                  &Instance->HttpIo.Handle,
+                                                  &gEdkiiHttpCallbackProtocolGuid,
+                                                  EFI_NATIVE_INTERFACE,
+                                                  &Instance->HttpCallbakFunction
+                                                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Fail to install HttpCallbakFunction.\n", __func__));
+    goto ON_ERROR;
+  }
+
   //
   // Add it to the parent's child list.
   //
@@ -812,6 +873,15 @@ RedfishRestExServiceBindingDestroyChild (
                   RestEx
                   );
 
+  //
+  // Uninstall the HTTP callback protocol.
+  //
+  Status = gBS->UninstallProtocolInterface (
+                  Instance->HttpIo.Handle,
+                  &gEdkiiHttpCallbackProtocolGuid,
+                  &Instance->HttpCallbakFunction
+                  );
+
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
 
   if (EFI_ERROR (Status)) {
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113330): https://edk2.groups.io/g/devel/message/113330
Mute This Topic: https://groups.io/mt/103577246/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH V2 4/6] RedfishPkg/RedfishRestExDxe: Implement EDKII_HTTP_CALLBACK_PROTOCOL
Posted by Nickle Wang via groups.io 2 years, 1 month ago

Reviewed-by: Nickle Wang <nicklew@nvidia.com>

Regards,
Nickle

> -----Original Message-----
> From: abner.chang@amd.com <abner.chang@amd.com>
> Sent: Sunday, January 7, 2024 9:27 PM
> To: devel@edk2.groups.io
> Cc: Nickle Wang <nicklew@nvidia.com>; Igor Kulchytskyy <igork@ami.com>
> Subject: [PATCH V2 4/6] RedfishPkg/RedfishRestExDxe: Implement
> EDKII_HTTP_CALLBACK_PROTOCOL
> 
> External email: Use caution opening links or attachments
> 
> 
> From: Abner Chang <abner.chang@amd.com>
> 
> Implement EDKII_HTTP_CALLBACK_PROTOCOL that listens to
> HttpEventTlsConfigured event for reconfiguring TLS configuration
> data.
> 
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Nickle Wang <nicklew@nvidia.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
>  .../RedfishRestExDxe/RedfishRestExDxe.inf     |  3 +
>  .../RedfishRestExDxe/RedfishRestExDriver.h    | 32 ++++++---
>  .../RedfishRestExDxe/RedfishRestExDriver.c    | 70 +++++++++++++++++++
>  3 files changed, 95 insertions(+), 10 deletions(-)
> 
> diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
> b/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
> index 64e6343bfbf..6da416ddb92 100644
> --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
> +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
> @@ -5,6 +5,7 @@
>  #  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
>  #  Copyright (c) 2023, American Megatrends International LLC.
>  #  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
> @@ -57,6 +58,8 @@
>    gEfiHttpServiceBindingProtocolGuid              ## TO_START
>    gEfiHttpProtocolGuid                            ## TO_START
>    gEfiDevicePathProtocolGuid                      ## TO_START
> +  gEdkiiHttpCallbackProtocolGuid                  ## CONSUMES
> +  gEfiTlsProtocolGuid                             ## CONSUMES
> 
>  [Pcd]
>    gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExServiceAccessModeInBand ##
> CONSUMES
> diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h
> b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h
> index 6b94e5814c4..929691cea35 100644
> --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h
> +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h
> @@ -4,6 +4,7 @@
>    Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
>    (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
>    Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>
> +  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -32,6 +33,8 @@
>  #include <Protocol/DriverBinding.h>
>  #include <Protocol/RestEx.h>
>  #include <Protocol/ServiceBinding.h>
> +#include <Protocol/HttpCallback.h>
> +#include <Protocol/Tls.h>
> 
>  ///
>  /// Protocol instances
> @@ -67,6 +70,9 @@ typedef struct _RESTEX_INSTANCE RESTEX_INSTANCE;
>  #define RESTEX_INSTANCE_FROM_THIS(a)  \
>    CR (a, RESTEX_INSTANCE, RestEx, RESTEX_INSTANCE_SIGNATURE)
> 
> +#define RESTEX_INSTANCE_FROM_HTTP_CALLBACK(a)  \
> +  CR (a, RESTEX_INSTANCE, HttpCallbakFunction,
> RESTEX_INSTANCE_SIGNATURE)
> +
>  #define RESTEX_STATE_UNCONFIGED  0
>  #define RESTEX_STATE_CONFIGED    1
> 
> @@ -94,25 +100,31 @@ struct _RESTEX_SERVICE {
>  #define RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY  0x00000002
> 
>  struct _RESTEX_INSTANCE {
> -  UINT32                     Signature;
> -  LIST_ENTRY                 Link;
> +  UINT32                        Signature;
> +  LIST_ENTRY                    Link;
> 
> -  EFI_REST_EX_PROTOCOL       RestEx;
> +  EFI_REST_EX_PROTOCOL          RestEx;
> 
> -  INTN                       State;
> -  BOOLEAN                    InDestroy;
> +  INTN                          State;
> +  BOOLEAN                       InDestroy;
> 
> -  RESTEX_SERVICE             *Service;
> -  EFI_HANDLE                 ChildHandle;
> +  RESTEX_SERVICE                *Service;
> +  EFI_HANDLE                    ChildHandle;
> 
> -  EFI_REST_EX_CONFIG_DATA    ConfigData;
> +  EFI_REST_EX_CONFIG_DATA       ConfigData;
> 
>    //
>    // HTTP_IO to access the HTTP service
>    //
> -  HTTP_IO                    HttpIo;
> +  HTTP_IO                       HttpIo;
> +
> +  //
> +  // EDKII_HTTP_CALLBACK_PROTOCOL that listens to
> +  // HttpEventInitSession event.
> +  //
> +  EDKII_HTTP_CALLBACK_PROTOCOL  HttpCallbakFunction;
> 
> -  UINT32                     Flags;
> +  UINT32                        Flags;
>  };
> 
>  typedef struct {
> diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
> b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
> index 7036aed4268..39221989c49 100644
> --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
> +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
> @@ -4,6 +4,7 @@
>    Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
>    (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
>    Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -585,6 +586,53 @@ RedfishRestExDriverBindingStop (
>    return Status;
>  }
> 
> +/**
> +  Callback function that is invoked when HTTP event occurs.
> +
> +  @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
> +RestExHttpCallback (
> +  IN EDKII_HTTP_CALLBACK_PROTOCOL  *This,
> +  IN EDKII_HTTP_CALLBACK_EVENT     Event,
> +  IN EFI_STATUS                    EventStatus
> +  )
> +{
> +  EFI_STATUS        Status;
> +  EFI_TLS_PROTOCOL  *TlsProtocol;
> +  RESTEX_INSTANCE   *Instance;
> +  EFI_TLS_VERIFY    TlsVerifyMethod;
> +
> +  if ((Event == HttpEventTlsConfigured) && (EventStatus == EFI_SUCCESS)) {
> +    // Reconfigure TLS configuration data.
> +    Instance = RESTEX_INSTANCE_FROM_HTTP_CALLBACK (This);
> +    Status   = gBS->HandleProtocol (
> +                      Instance->HttpIo.Handle,
> +                      &gEfiTlsProtocolGuid,
> +                      (VOID **)&TlsProtocol
> +                      );
> +    if (EFI_ERROR (Status)) {
> +      return;
> +    }
> +
> +    TlsVerifyMethod = EFI_TLS_VERIFY_NONE;
> +    Status          = TlsProtocol->SetSessionData (
> +                                     TlsProtocol,
> +                                     EfiTlsVerifyMethod,
> +                                     &TlsVerifyMethod,
> +                                     sizeof (EFI_TLS_VERIFY)
> +                                     );
> +    if (!EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_MANAGEABILITY, "%a: REST EX reconfigures TLS verify
> method.\n", __func__));
> +    }
> +  }
> +
> +  return;
> +}
> +
>  /**
>    Creates a child handle and installs a protocol.
> 
> @@ -699,6 +747,19 @@ RedfishRestExServiceBindingCreateChild (
>      goto ON_ERROR;
>    }
> 
> +  // Initial HTTP callback funciton on this REST EX instance
> +  Instance->HttpCallbakFunction.Callback = RestExHttpCallback;
> +  Status                                 = gBS->InstallProtocolInterface (
> +                                                  &Instance->HttpIo.Handle,
> +                                                  &gEdkiiHttpCallbackProtocolGuid,
> +                                                  EFI_NATIVE_INTERFACE,
> +                                                  &Instance->HttpCallbakFunction
> +                                                  );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Fail to install HttpCallbakFunction.\n",
> __func__));
> +    goto ON_ERROR;
> +  }
> +
>    //
>    // Add it to the parent's child list.
>    //
> @@ -812,6 +873,15 @@ RedfishRestExServiceBindingDestroyChild (
>                    RestEx
>                    );
> 
> +  //
> +  // Uninstall the HTTP callback protocol.
> +  //
> +  Status = gBS->UninstallProtocolInterface (
> +                  Instance->HttpIo.Handle,
> +                  &gEdkiiHttpCallbackProtocolGuid,
> +                  &Instance->HttpCallbakFunction
> +                  );
> +
>    OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
> 
>    if (EFI_ERROR (Status)) {
> --
> 2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113395): https://edk2.groups.io/g/devel/message/113395
Mute This Topic: https://groups.io/mt/103577246/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-