public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Introduce Redfish version library
@ 2022-05-17  3:58 Nickle Wang
  2022-05-18  3:55 ` Abner Chang
  0 siblings, 1 reply; 2+ messages in thread
From: Nickle Wang @ 2022-05-17  3:58 UTC (permalink / raw)
  To: devel; +Cc: Nickle Wang, Abner Chang

Add RedfishVersionLib to Redfish client package. This library provides
interface for Redfish feature drivers to get Redfish version on BMC.

Signed-off-by: Nickle Wang <nickle.wang@hpe.com>
Cc: Abner Chang <abner.chang@hpe.com>
---
 .../Include/Library/RedfishVersionLib.h       |  30 +++
 RedfishClientPkg/Include/RedfishBase.h        |  16 ++
 .../RedfishVersionLib/RedfishVersionLib.c     | 203 ++++++++++++++++++
 .../RedfishVersionLib/RedfishVersionLib.inf   |  44 ++++
 RedfishClientPkg/RedfishClientLibs.dsc.inc    |   2 +-
 RedfishClientPkg/RedfishClientPkg.dec         |   6 +-
 6 files changed, 298 insertions(+), 3 deletions(-)
 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..5076c2ce9f
--- /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..60d585c54a
--- /dev/null
+++ b/RedfishClientPkg/Include/RedfishBase.h
@@ -0,0 +1,16 @@
+/** @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_VERBOSE
+
+#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..fcc88a4357
--- /dev/null
+++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
@@ -0,0 +1,44 @@
+## @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
+
diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/RedfishClientLibs.dsc.inc
index 5467acedd0..386d4d9cbb 100644
--- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
+++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
@@ -27,4 +27,4 @@
   RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf
   RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.inf
   ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/ConverterCommonLib/ConverterCommonLib.inf
-
+  RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/RedfishClientPkg.dec
index 09df062dd3..b22f121e96 100644
--- a/RedfishClientPkg/RedfishClientPkg.dec
+++ b/RedfishClientPkg/RedfishClientPkg.dec
@@ -1,7 +1,7 @@
 ## @file
 # Redfish Client Package
 #
-# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
+# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
@@ -21,6 +21,7 @@
 
 [LibraryClasses]
   RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h
+  RedfishVersionLib|Include/Library/RedfishVersionLib.h
 
 [LibraryClasses.Common.Private]
   ##  @libraryclass Redfish Helper Library
@@ -47,4 +48,5 @@
   # { 0x7CE88FB3, 0x4BD7, 0x4679, { 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, 0x0D, 0x2B }}
   #
   gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupEventGuid|{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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Introduce Redfish version library
  2022-05-17  3:58 [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Introduce Redfish version library Nickle Wang
@ 2022-05-18  3:55 ` Abner Chang
  0 siblings, 0 replies; 2+ messages in thread
From: Abner Chang @ 2022-05-18  3:55 UTC (permalink / raw)
  To: Wang, Nickle (Server BIOS), devel@edk2.groups.io



> -----Original Message-----
> From: Wang, Nickle (Server BIOS) <nickle.wang@hpe.com>
> Sent: Tuesday, May 17, 2022 11:59 AM
> To: devel@edk2.groups.io
> Cc: Wang, Nickle (Server BIOS) <nickle.wang@hpe.com>; Chang, Abner (HPS
> SW/FW Technologist) <abner.chang@hpe.com>
> Subject: [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Introduce
> Redfish version library
> 
> Add RedfishVersionLib to Redfish client package. This library provides
> interface for Redfish feature drivers to get Redfish version on BMC.
> 
> Signed-off-by: Nickle Wang <nickle.wang@hpe.com>
> Cc: Abner Chang <abner.chang@hpe.com>
> ---
>  .../Include/Library/RedfishVersionLib.h       |  30 +++
>  RedfishClientPkg/Include/RedfishBase.h        |  16 ++
>  .../RedfishVersionLib/RedfishVersionLib.c     | 203 ++++++++++++++++++
>  .../RedfishVersionLib/RedfishVersionLib.inf   |  44 ++++
>  RedfishClientPkg/RedfishClientLibs.dsc.inc    |   2 +-
>  RedfishClientPkg/RedfishClientPkg.dec         |   6 +-
>  6 files changed, 298 insertions(+), 3 deletions(-)
>  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..5076c2ce9f
> --- /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.
It's caller's responsibility to release the 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..60d585c54a
> --- /dev/null
> +++ b/RedfishClientPkg/Include/RedfishBase.h
> @@ -0,0 +1,16 @@
> +/** @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_VERBOSE
> 
> +
> 
> +#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)) {
We can just check the JSON type for the property is a string type per to the Redfish spec. Please also have comment to elaborate on the rational of this code block. 
Thanks
Abner
> 
> +      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..fcc88a4357
> --- /dev/null
> +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
> @@ -0,0 +1,44 @@
> +## @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
Please having these libraries in the order  of alphabet.
> 
> +
> 
> +[Protocols]
> 
> +
> 
> +[Pcd]
> 
> +  gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion
> 
> +
> 
> diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> index 5467acedd0..386d4d9cbb 100644
> --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> @@ -27,4 +27,4 @@
> 
> RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/Red
> fishPlatformConfigLib.inf
> 
> 
> RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/
> RedfishContentCodingLibNull.inf
> 
> 
> ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/Converte
> rCommonLib/ConverterCommonLib.inf
> 
> -
> 
> +
> RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVersi
> onLib.inf
> 
> diff --git a/RedfishClientPkg/RedfishClientPkg.dec
> b/RedfishClientPkg/RedfishClientPkg.dec
> index 09df062dd3..b22f121e96 100644
> --- a/RedfishClientPkg/RedfishClientPkg.dec
> +++ b/RedfishClientPkg/RedfishClientPkg.dec
> @@ -1,7 +1,7 @@
>  ## @file
> 
>  # Redfish Client Package
> 
>  #
> 
> -# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
> 
> +# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
> 
>  #
> 
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  ##
> 
> @@ -21,6 +21,7 @@
> 
> 
>  [LibraryClasses]
> 
>    RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h
> 
> +  RedfishVersionLib|Include/Library/RedfishVersionLib.h
> 
> 
> 
>  [LibraryClasses.Common.Private]
> 
>    ##  @libraryclass Redfish Helper Library
> 
> @@ -47,4 +48,5 @@
>    # { 0x7CE88FB3, 0x4BD7, 0x4679, { 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, 0x0D,
> 0x2B }}
> 
>    #
> 
> 
> gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupE
> ventGuid|{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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-18  3:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-17  3:58 [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Introduce Redfish version library Nickle Wang
2022-05-18  3:55 ` Abner Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox