public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chang, Abner" <abner.chang@amd.com>
To: Nickle Wang <nicklew@nvidia.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Igor Kulchytskyy <igork@ami.com>
Subject: Re: [edk2-redfish-client][PATCH 5/6] RedfishClientPkg: Introduce resource identify library
Date: Wed, 10 May 2023 01:29:42 +0000	[thread overview]
Message-ID: <MN2PR12MB3966DFB9D1E1754DA52712C8EA779@MN2PR12MB3966.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20230509135909.7223-1-nicklew@nvidia.com>

[AMD Official Use Only - General]

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

> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Tuesday, May 9, 2023 9:59 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>
> Subject: [edk2-redfish-client][PATCH 5/6] RedfishClientPkg: Introduce
> resource identify library
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Introduce resource identify library which works with resource config protocol
> to identify Redfish resource. This library provides the flexibility for platform
> to implement its own policy and identify resource. Two library
> implementation are provided as demonstration code. NULL version of library
> accepts all Redfish resource and another implementation to computer
> system resource uses UUID to identify Redfish resource.
> 
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
>  RedfishClientPkg/RedfishClientPkg.dec         |   1 +
>  RedfishClientPkg/RedfishClientLibs.dsc.inc    |   2 +-
>  ...edfishResourceIdentifyLibComuterSystem.inf |  39 +++++
>  .../RedfishResourceIdentifyLibNull.inf        |  32 ++++
>  .../Library/RedfishResourceIdentifyLib.h      |  29 ++++
>  .../RedfishResourceIdentifyLibComuterSystem.c | 163
> ++++++++++++++++++
>  .../RedfishResourceIdentifyLibNull.c          |  37 ++++
>  7 files changed, 302 insertions(+), 1 deletion(-)  create mode 100644
> RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_
> 0/RedfishResourceIdentifyLibComuterSystem.inf
>  create mode 100644
> RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceId
> entifyLibNull.inf
>  create mode 100644
> RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h
>  create mode 100644
> RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_
> 0/RedfishResourceIdentifyLibComuterSystem.c
>  create mode 100644
> RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceId
> entifyLibNull.c
> 
> diff --git a/RedfishClientPkg/RedfishClientPkg.dec
> b/RedfishClientPkg/RedfishClientPkg.dec
> index 9d18c42c..c61c5812 100644
> --- a/RedfishClientPkg/RedfishClientPkg.dec
> +++ b/RedfishClientPkg/RedfishClientPkg.dec
> @@ -21,6 +21,7 @@
> 
>  [LibraryClasses]
>    RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h
> +
> + RedfishResourceIdentifyLib|Include/Library/RedfishResourceIdentifyLib.
> + h
> 
> EdkIIRedfishResourceConfigLib|Include/Library/EdkIIRedfishResourceConfig
> Lib.h
>    RedfishEventLib|Include/Library/RedfishEventLib.h
>    RedfishVersionLib|Include/Library/RedfishVersionLib.h
> diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> index 8acb4791..413b83a7 100644
> --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> @@ -27,7 +27,7 @@
> 
> RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/Red
> fishPlatformConfigLib.inf
> 
> RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/
> RedfishContentCodingLibNull.inf
> 
> ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/Converte
> rCommonLib/ConverterCommonLib.inf
> -
> +
> + RedfishResourceIdentifyLib|RedfishClientPkg/Library/RedfishResourceIde
> + ntifyLibNull/RedfishResourceIdentifyLibNull.inf
> 
> EdkIIRedfishResourceConfigLib|RedfishClientPkg/Library/EdkIIRedfishResou
> rceConfigLib/EdkIIRedfishResourceConfigLib.inf
> 
> RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.i
> nf
> 
> RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVersi
> onLib.inf
> diff --git
> a/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_
> 5_0/RedfishResourceIdentifyLibComuterSystem.inf
> b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_
> 5_0/RedfishResourceIdentifyLibComuterSystem.inf
> new file mode 100644
> index 00000000..ae269b58
> --- /dev/null
> +++
> b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v
> +++ 1_5_0/RedfishResourceIdentifyLibComuterSystem.inf
> @@ -0,0 +1,39 @@
> +## @file
> +#
> +#  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR> # #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010006
> +  BASE_NAME                      = RedfishResourceIdentifyLibComuterSystem
> +  FILE_GUID                      = 2AEE2C80-126A-44A6-877E-642F20510D13
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = RedfishResourceIdentifyLib| DXE_DRIVER
> +  CONSTRUCTOR                    =
> RedfishResourceIdentifyComuterSystemConstructor
> +
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64 EBC
> +#
> +
> +[Sources]
> +  RedfishResourceIdentifyLibComuterSystem.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  NetworkPkg/NetworkPkg.dec
> +  RedfishPkg/RedfishPkg.dec
> +  RedfishClientPkg/RedfishClientPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  UefiBootServicesTableLib
> +  UefiLib
> +
> +[Protocols]
> +  gEfiRestJsonStructureProtocolGuid   ## CONSUMES
> diff --git
> a/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResource
> IdentifyLibNull.inf
> b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourc
> eIdentifyLibNull.inf
> new file mode 100644
> index 00000000..9164b229
> --- /dev/null
> +++ b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishRes
> +++ ourceIdentifyLibNull.inf
> @@ -0,0 +1,32 @@
> +## @file
> +#
> +#  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR> # #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010006
> +  BASE_NAME                      = RedfishResourceIdentifyLibNull
> +  FILE_GUID                      = 6FFD4E25-48F8-4CB6-B194-CFAB407316E1
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = RedfishResourceIdentifyLib| DXE_DRIVER
> +
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64 EBC
> +#
> +
> +[Sources]
> +  RedfishResourceIdentifyLibNull.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  RedfishPkg/RedfishPkg.dec
> +  RedfishClientPkg/RedfishClientPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> diff --git a/RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h
> b/RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h
> new file mode 100644
> index 00000000..254f9be3
> --- /dev/null
> +++ b/RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h
> @@ -0,0 +1,29 @@
> +/** @file
> +  This file defines the Redfish resource identify Library interface.
> +
> +  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef REDFISH_RESOURCE_IDENTIFY_LIB_H_ #define
> +REDFISH_RESOURCE_IDENTIFY_LIB_H_
> +
> +/**
> +  Identify resource from given URI and context in JSON format
> +
> +  @param[in]   Uri    URI of given Redfish resource
> +  @param[in]   Json   Context in JSON format of give Redfish resource
> +
> +  @retval TRUE        This is the Redfish resource that we have to handle.
> +  @retval FALSE       We don't handle this Redfish resource.
> +
> +**/
> +BOOLEAN
> +RedfishIdentifyResource (
> +  IN     EFI_STRING  Uri,
> +  IN     CHAR8       *Json
> +  );
> +
> +#endif
> diff --git
> a/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_
> 5_0/RedfishResourceIdentifyLibComuterSystem.c
> b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_
> 5_0/RedfishResourceIdentifyLibComuterSystem.c
> new file mode 100644
> index 00000000..a15809ef
> --- /dev/null
> +++
> b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v
> +++ 1_5_0/RedfishResourceIdentifyLibComuterSystem.c
> @@ -0,0 +1,163 @@
> +/** @file
> +  Redfish resource identify library implementation for computer system
> +version 1.5.0
> +
> +  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi.h>
> +#include <RedfishBase.h>
> +
> +#include <Library/UefiLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/NetLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Library/RedfishResourceIdentifyLib.h>
> +
> +#include <Protocol/RestJsonStructure.h>
> +
> +#include
> +<RedfishJsonStructure/ComputerSystem/v1_5_0/EfiComputerSystemV1_5
> _0.h>
> +
> +EFI_REST_JSON_STRUCTURE_PROTOCOL  *mJsonStructProtocol = NULL;
> +
> +/**
> +  Identify resource from given URI and context in JSON format
> +
> +  @param[in]   Uri    URI of given Redfish resource
> +  @param[in]   Json   Context in JSON format of give Redfish resource
> +
> +  @retval TRUE        This is the Redfish resource that we have to handle.
> +  @retval FALSE       We don't handle this Redfish resource.
> +
> +**/
> +BOOLEAN
> +RedfishIdentifyResource (
> +  IN     EFI_STRING  Uri,
> +  IN     CHAR8       *Json
> +  )
> +{
> +  EFI_STATUS                            Status;
> +  EFI_REDFISH_COMPUTERSYSTEM_V1_5_0     *ComputerSystem;
> +  EFI_REDFISH_COMPUTERSYSTEM_V1_5_0_CS  *ComputerSystemCs;
> +  EFI_GUID                              SystemUuid;
> +  EFI_GUID                              ResourceUuid;
> +
> +  if (IS_EMPTY_STRING (Uri) || IS_EMPTY_STRING (Json)) {
> +    return FALSE;
> +  }
> +
> +  if (mJsonStructProtocol == NULL) {
> +    return FALSE;
> +  }
> +
> +  ComputerSystem   = NULL;
> +  ComputerSystemCs = NULL;
> +
> +  Status = mJsonStructProtocol->ToStructure (
> +                                  mJsonStructProtocol,
> +                                  NULL,
> +                                  Json,
> +                                  (EFI_REST_JSON_STRUCTURE_HEADER
> **)&ComputerSystem
> +                                  );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n",
> __FUNCTION__, Status));
> +    return FALSE;
> +  }
> +
> +  ComputerSystemCs = ComputerSystem->ComputerSystem;
> +
> +  if (IS_EMPTY_STRING (ComputerSystemCs->UUID)) {
> +    return FALSE;
> +  }
> +
> +  Status = AsciiStrToGuid (ComputerSystemCs->UUID, &ResourceUuid);  if
> + (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a, fail to get resource UUID: %r\n",
> __FUNCTION__, Status));
> +    return FALSE;
> +  }
> +
> +  Status = NetLibGetSystemGuid (&SystemUuid);  if (EFI_ERROR (Status))
> + {
> +    DEBUG ((DEBUG_ERROR, "%a, fail to get system UUID from SMBIOS:
> %r\n", __FUNCTION__, Status));
> +    return FALSE;
> +  }
> +
> +  DEBUG ((REDFISH_DEBUG_TRACE, "%a, Identify: System: %g Resource:
> + %g\n", __FUNCTION__, &SystemUuid, &ResourceUuid));  if (CompareGuid
> (&ResourceUuid, &SystemUuid)) {
> +    Status = EFI_SUCCESS;
> +  } else {
> +    Status = EFI_UNSUPPORTED;
> +  }
> +
> +  mJsonStructProtocol->DestoryStructure (
> +                         mJsonStructProtocol,
> +                         (EFI_REST_JSON_STRUCTURE_HEADER *)ComputerSystem
> +                         );
> +
> +  return (Status == EFI_SUCCESS ? TRUE : FALSE); }
> +
> +/**
> +  Callback function when gEfiRestJsonStructureProtocolGuid is installed.
> +
> +  @param[in] Event    Event whose notification function is being invoked.
> +  @param[in] Context  Pointer to the notification function's context.
> +**/
> +VOID
> +EFIAPI
> +RestJasonStructureProtocolIsReady (
> +  IN  EFI_EVENT  Event,
> +  IN  VOID       *Context
> +  )
> +{
> +  EFI_STATUS  Status;
> +
> +  if (mJsonStructProtocol != NULL) {
> +    return;
> +  }
> +
> +  Status = gBS->LocateProtocol (
> +                  &gEfiRestJsonStructureProtocolGuid,
> +                  NULL,
> +                  (VOID **)&mJsonStructProtocol
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a, failed to locate
> + gEfiRestJsonStructureProtocolGuid: %r\n", __FUNCTION__, Status));  }
> +
> +  gBS->CloseEvent (Event);
> +}
> +
> +/**
> +
> +  Install JSON protocol notification
> +
> +  @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
> +RedfishResourceIdentifyComuterSystemConstructor (
> +  IN EFI_HANDLE        ImageHandle,
> +  IN EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  VOID  *Registration;
> +
> +  EfiCreateProtocolNotifyEvent (
> +    &gEfiRestJsonStructureProtocolGuid,
> +    TPL_CALLBACK,
> +    RestJasonStructureProtocolIsReady,
> +    NULL,
> +    &Registration
> +    );
> +
> +  return EFI_SUCCESS;
> +}
> diff --git
> a/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResource
> IdentifyLibNull.c
> b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourc
> eIdentifyLibNull.c
> new file mode 100644
> index 00000000..42ee1a15
> --- /dev/null
> +++ b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishRes
> +++ ourceIdentifyLibNull.c
> @@ -0,0 +1,37 @@
> +/** @file
> +  Redfish resource identify NULL 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/RedfishResourceIdentifyLib.h>
> +
> +/**
> +  Identify resource from given URI and context in JSON format
> +
> +  @param[in]   Uri    URI of given Redfish resource
> +  @param[in]   Json   Context in JSON format of give Redfish resource
> +
> +  @retval TRUE        This is the Redfish resource that we have to handle.
> +  @retval FALSE       We don't handle this Redfish resource.
> +
> +**/
> +BOOLEAN
> +RedfishIdentifyResource (
> +  IN     EFI_STRING  Uri,
> +  IN     CHAR8       *Json
> +  )
> +{
> +  if (!IS_EMPTY_STRING (Uri)) {
> +    DEBUG ((DEBUG_VERBOSE, "%a, accept resource: %s\n", __FUNCTION__,
> +Uri));
> +  }
> +
> +  return TRUE;
> +}
> --
> 2.17.1

      reply	other threads:[~2023-05-10  1:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 13:59 [edk2-redfish-client][PATCH 5/6] RedfishClientPkg: Introduce resource identify library Nickle Wang
2023-05-10  1:29 ` Chang, Abner [this message]

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=MN2PR12MB3966DFB9D1E1754DA52712C8EA779@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