public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chang, Abner" <abner.chang@amd.com>
To: Nickle Wang <nickle.wang@hpe.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Yang, Atom" <Atom.Yang@amd.com>, Nick Ramirez <nramirez@nvidia.com>
Subject: Re: [edk2-staging][PATCH v2 02/15] edk2-staging/RedfishClientPkg: Introduce Redfish version library
Date: Tue, 26 Jul 2022 01:46:28 +0000	[thread overview]
Message-ID: <MN2PR12MB3966EB02DE6C4830DD15B315EA949@MN2PR12MB3966.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20220725013555.926-3-nickle.wang@hpe.com>

[AMD Official Use Only - General]

Reviewed-by: Abner Chang <abner.chang@amd.com>

> -----Original Message-----
> From: Nickle Wang <nickle.wang@hpe.com>
> Sent: Monday, July 25, 2022 9:36 AM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Yang, Atom
> <Atom.Yang@amd.com>; Nick Ramirez <nramirez@nvidia.com>
> Subject: [edk2-staging][PATCH v2 02/15] edk2-staging/RedfishClientPkg:
> Introduce Redfish version library
> 
> [CAUTION: External Email]
> 
> Add RedfishVersionLib in order to get Redfish version hosted at BMC.
> When there is trouble to get Redfish support version, the default version is
> retrieved from pre-defined PCD value.
> 
> Signed-off-by: Nickle Wang <nickle.wang@hpe.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Yang Atom <Atom.Yang@amd.com>
> Cc: Nick Ramirez <nramirez@nvidia.com>
> ---
>  .../Include/Library/RedfishVersionLib.h       |  30 +++
>  RedfishClientPkg/Include/RedfishBase.h        |  21 ++
>  .../RedfishVersionLib/RedfishVersionLib.c     | 203 ++++++++++++++++++
>  .../RedfishVersionLib/RedfishVersionLib.inf   |  50 +++++
>  RedfishClientPkg/RedfishClientLibs.dsc.inc    |   1 +
>  RedfishClientPkg/RedfishClientPkg.dec         |   4 +-
>  6 files changed, 308 insertions(+), 1 deletion(-)  create mode 100644
> RedfishClientPkg/Include/Library/RedfishVersionLib.h
>  create mode 100644 RedfishClientPkg/Include/RedfishBase.h
>  create mode 100644
> RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
>  create mode 100644
> RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
> 
> diff --git a/RedfishClientPkg/Include/Library/RedfishVersionLib.h
> b/RedfishClientPkg/Include/Library/RedfishVersionLib.h
> new file mode 100644
> index 0000000000..319f22bd37
> --- /dev/null
> +++ b/RedfishClientPkg/Include/Library/RedfishVersionLib.h
> @@ -0,0 +1,30 @@
> +/** @file
> +  This file defines the Redfish version Library interface.
> +
> +  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef REDFISH_VERSION_LIB_H_
> +#define REDFISH_VERSION_LIB_H_
> +
> +/**
> +  Query HTTP request to BMC with given redfish service and return
> +redfish
> +  version information. If there is troulbe to get Redfish version on
> +BMC,
> +  The value of PcdDefaultRedfishVersion is returned.
> +
> +  It's call responsibility to release returned buffer.
> +
> +  @param[in]   Service  Redfish service instance
> +
> +  @retval EFI_STRING  Redfish version string. NULL while error occurs.
> +
> +**/
> +EFI_STRING
> +RedfishGetVersion (
> +  IN REDFISH_SERVICE  *Service
> +  );
> +
> +#endif
> diff --git a/RedfishClientPkg/Include/RedfishBase.h
> b/RedfishClientPkg/Include/RedfishBase.h
> new file mode 100644
> index 0000000000..cf320bb0eb
> --- /dev/null
> +++ b/RedfishClientPkg/Include/RedfishBase.h
> @@ -0,0 +1,21 @@
> +/** @file
> +  Redfish base header file.
> +
> +  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef EFI_REDFISH_BASE_H_
> +#define EFI_REDFISH_BASE_H_
> +
> +#define IS_EMPTY_STRING(a)    ((a) == NULL || (a)[0] == '\0')
> +#define REDFISH_DEBUG_TRACE   DEBUG_INFO
> +
> +///
> +/// This GUID is used for an EFI Variable that stores the Redfish data.
> +///
> +EFI_GUID mRedfishVariableGuid = {0x91c46a3d, 0xed1a, 0x477b, {0xa5,
> +0x33, 0x87, 0x2d, 0xcd, 0xb0, 0xfc, 0xc1}};
> +
> +#endif
> diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
> b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
> new file mode 100644
> index 0000000000..0a2ace7726
> --- /dev/null
> +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
> @@ -0,0 +1,203 @@
> +/** @file
> +  Redfish version library implementation
> +
> +  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi.h>
> +#include <RedfishBase.h>
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/RedfishLib.h>
> +#include <Library/JsonLib.h>
> +#include <Library/MemoryAllocationLib.h> #include
> +<Library/RedfishVersionLib.h>
> +
> +#define REDFISH_VERSION_DEFAULT_STRING L"v1"
> +#define REDFISH_ROOT_URI               "/redfish"
> +
> +REDFISH_SERVICE *mCacheService;
> +EFI_STRING      mVersionCache;
> +UINTN           mVersionStringSize;
> +
> +/**
> +  Cache the redfish service version for later use so we don't have to
> +query
> +  HTTP request everytime.
> +
> +  @param[in]   Service  Redfish service instance
> +  @param[in]   Version  Version string to cache
> +
> +  @retval EFI_SUCCESS   Version is saved in cache successfully.
> +  @retval Others
> +
> +**/
> +EFI_STATUS
> +CacheVersion (
> +  IN REDFISH_SERVICE  *Service,
> +  IN EFI_STRING       Version
> +  )
> +{
> +  if (Service == NULL || IS_EMPTY_STRING (Version)) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  if (mCacheService == Service) {
> +    return EFI_ALREADY_STARTED;
> +  }
> +
> +  mCacheService = Service;
> +  if (mVersionCache != NULL) {
> +    FreePool (mVersionCache);
> +  }
> +
> +  mVersionStringSize = StrSize (Version);  mVersionCache =
> + AllocateCopyPool (mVersionStringSize, Version);  if (mVersionCache ==
> + NULL) {
> +    mCacheService = NULL;
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Query HTTP request to BMC with given redfish service and return
> +redfish
> +  version information. If there is troulbe to get Redfish version on
> +BMC,
> +  The value of PcdDefaultRedfishVersion is returned.
> +
> +  It's call responsibility to release returned buffer.
> +
> +  @param[in]   Service  Redfish service instance
> +
> +  @retval EFI_STRING  Redfish version string. NULL while error occurs.
> +
> +**/
> +EFI_STRING
> +RedfishGetVersion (
> +  IN REDFISH_SERVICE  *Service
> +  )
> +{
> +  EFI_STATUS        Status;
> +  EFI_STRING        VersionString;
> +  REDFISH_RESPONSE  Response;
> +  EDKII_JSON_VALUE  JsonValue;
> +  EDKII_JSON_VALUE  N;
> +  CHAR8             *Key;
> +  EDKII_JSON_VALUE  Value;
> +
> +  VersionString = NULL;
> +
> +  if (Service == NULL) {
> +    goto ON_ERROR;
> +  }
> +
> +  //
> +  // Use cache to prevent HTTP connection.
> +  //
> +  if (Service == mCacheService) {
> +    return AllocateCopyPool (mVersionStringSize, mVersionCache);  }
> +
> +  //
> +  // Get resource from redfish service.
> +  //
> +  Status = RedfishGetByUri (
> +             Service,
> +             REDFISH_ROOT_URI,
> +             &Response
> +             );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a, RedfishGetByService to %a failed: %r\n",
> __FUNCTION__, REDFISH_ROOT_URI, Status));
> +    if (Response.Payload != NULL) {
> +      RedfishDumpPayload (Response.Payload);
> +      RedfishFreeResponse (
> +        NULL,
> +        0,
> +        NULL,
> +        Response.Payload
> +        );
> +      Response.Payload = NULL;
> +    }
> +
> +    goto ON_ERROR;
> +  }
> +
> +  JsonValue = RedfishJsonInPayload (Response.Payload);  if (JsonValue
> + == NULL || !JsonValueIsObject (JsonValue)) {
> +    goto ON_ERROR;
> +  }
> +
> +  EDKII_JSON_OBJECT_FOREACH_SAFE (JsonValue, N, Key, Value) {
> +    if (Key[0] == 'v' && JsonValueIsString (Value)) {
> +      VersionString = JsonValueGetUnicodeString (Value);
> +      break;
> +    }
> +  }
> +
> +  if (VersionString != NULL) {
> +    CacheVersion (Service, VersionString);
> +    return VersionString;
> +  }
> +
> +ON_ERROR:
> +
> +  VersionString = (CHAR16 *)PcdGetPtr (PcdDefaultRedfishVersion);  if
> + (VersionString == NULL) {
> +    VersionString = REDFISH_VERSION_DEFAULT_STRING;  }
> +
> +  return AllocateCopyPool (StrSize (VersionString), VersionString); }
> +
> +/**
> +
> +  Initial redfish version library instace.
> +
> +  @param[in] ImageHandle     The image handle.
> +  @param[in] SystemTable     The system table.
> +
> +  @retval  EFI_SUCEESS  Install Boot manager menu success.
> +  @retval  Other        Return error status.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +RedfishVersionLibConstructor (
> +  IN EFI_HANDLE                            ImageHandle,
> +  IN EFI_SYSTEM_TABLE                      *SystemTable
> +  )
> +{
> +  mCacheService = NULL;
> +  mVersionCache = NULL;
> +  mVersionStringSize = 0;
> +
> +  return EFI_SUCCESS;
> +}
> +
> +
> +/**
> +  Release allocated resource.
> +
> +  @param[in] ImageHandle       Handle that identifies the image to be unloaded.
> +  @param[in] SystemTable      The system table.
> +
> +  @retval EFI_SUCCESS      The image has been unloaded.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +RedfishVersionLibDestructor (
> +  IN EFI_HANDLE                            ImageHandle,
> +  IN EFI_SYSTEM_TABLE                      *SystemTable
> +  )
> +{
> +  if (mVersionCache != NULL) {
> +    FreePool (mVersionCache);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
> b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
> new file mode 100644
> index 0000000000..34d13d64f1
> --- /dev/null
> +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
> @@ -0,0 +1,50 @@
> +## @file
> +#
> +#  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR> # #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010006
> +  BASE_NAME                      = RedfishVersionLib
> +  FILE_GUID                      = 396A7508-B611-49F7-9C81-DAD96B526B61
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = RedfishVersionLib| DXE_DRIVER
> +  CONSTRUCTOR                    = RedfishVersionLibConstructor
> +  DESTRUCTOR                     = RedfishVersionLibDestructor
> +
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64 EBC
> +#
> +
> +[Sources]
> +  RedfishVersionLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  RedfishPkg/RedfishPkg.dec
> +  RedfishClientPkg/RedfishClientPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  MemoryAllocationLib
> +  PcdLib
> +  RedfishLib
> +  JsonLib
> +
> +[Protocols]
> +
> +[Pcd]
> +  gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion
> +
> +[BuildOptions]
> +  #
> +  # NOTE: /wd4706 disables the following Visual Studio compiler warning in
> Jansson:
> +  #       "C4706: assignment within conditional expression"
> +  #
> +  MSFT:*_*_*_CC_FLAGS = /wd4706
> diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> index ce1c27d884..1cf0406912 100644
> --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> @@ -29,3 +29,4 @@
> 
> ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/ConverterCo
> mmonLib/ConverterCommonLib.inf
> 
>    RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.inf
> +
> + RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVe
> + rsionLib.inf
> diff --git a/RedfishClientPkg/RedfishClientPkg.dec
> b/RedfishClientPkg/RedfishClientPkg.dec
> index 39b2f5baf8..2ce51d14af 100644
> --- a/RedfishClientPkg/RedfishClientPkg.dec
> +++ b/RedfishClientPkg/RedfishClientPkg.dec
> @@ -22,6 +22,7 @@
>  [LibraryClasses]
>    RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h
>    RedfishEventLib|Include/Library/RedfishEventLib.h
> +  RedfishVersionLib|Include/Library/RedfishVersionLib.h
> 
>  [LibraryClasses.Common.Private]
>    ##  @libraryclass Redfish Helper Library @@ -52,4 +53,5 @@
>    # { 0x7CE88FB3, 0x4BD7, 0x4679, { 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, 0x0D,
> 0x2B }}
>    #
> 
> gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupEvent
> Guid|{0xB3, 0x8F, 0xE8, 0x7C, 0xD7, 0x4B, 0x79, 0x46, 0x87, 0xA8, 0xA8, 0xD8,
> 0xDE, 0xE5, 0x0D, 0x2B}|VOID*|0x10000003
> -
> +  ## Default Redfish version string
> +
> + gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion|L"v1"|VOID
> + *|0x10000004
> --
> 2.32.0.windows.2

  reply	other threads:[~2022-07-26  1:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25  1:35 [edk2-staging][PATCH v2 00/15] Update RedfishClientpkg Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 01/15] edk2-staging/RedfishClientPkg: Introduce Redfish event library Nickle Wang
2022-07-26  1:40   ` Chang, Abner
2022-07-25  1:35 ` [edk2-staging][PATCH v2 02/15] edk2-staging/RedfishClientPkg: Introduce Redfish version library Nickle Wang
2022-07-26  1:46   ` Chang, Abner [this message]
2022-07-25  1:35 ` [edk2-staging][PATCH v2 03/15] edk2-staging/RedfishClientPkg: Update Redfish Resource Config Protocol Nickle Wang
2022-07-26  1:49   ` Chang, Abner
2022-07-25  1:35 ` [edk2-staging][PATCH v2 04/15] edk2-staging/RedfishClientPkg: Introduce Redfish resource config library Nickle Wang
2022-07-26  1:58   ` Chang, Abner
2022-07-25  1:35 ` [edk2-staging][PATCH v2 05/15] edk2-staging/RedfishClientPkg: Introduce resource identify library Nickle Wang
2022-07-26  2:04   ` Chang, Abner
2022-07-27  1:39     ` Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 06/15] edk2-staging/RedfishClientPkg: Introduce RedfishConfigLangMap driver Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 07/15] edk2-staging/RedfishClientPkg: Update ETag driver Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 08/15] edk2-staging/RedfishClientPkg: Update Redfish feature core driver Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 09/15] edk2-staging/RedfishClientPkg: Update RedfishLib Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 10/15] edk2-staging/RedfishClientPkg: Update Redfish feature utility library Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 11/15] edk2-staging/RedfishClientPkg: Rename RedfishMemoryCollection driver Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 12/15] edk2-staging/RedfishClientPkg: Rename Memory feature driver Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 13/15] edk2-staging/RedfishClientPkg: Introduce Computer System collection driver Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 14/15] edk2-staging/RedfishClientPkg: Introduce Computer System feature driver Nickle Wang
2022-07-25  1:35 ` [edk2-staging][PATCH v2 15/15] edk2-staging/RedfishClientPkg: Introduce Bios " Nickle Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MN2PR12MB3966EB02DE6C4830DD15B315EA949@MN2PR12MB3966.namprd12.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox