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 4/6] RedfishClientPkg: Introduce Redfish resource config library
Date: Wed, 10 May 2023 01:29:39 +0000 [thread overview]
Message-ID: <MN2PR12MB3966DA49C999910A6F3999CFEA779@MN2PR12MB3966.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20230509135900.7133-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 4/6] RedfishClientPkg: Introduce
> Redfish resource config library
>
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> Add EdkIIRedfishResourceConfigLib in order to work with Redfish Config
> Protocol and do the communication between each feature drivers. Also
> introduce Redfish interchange data protocol to exchange data efficiently.
>
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
> RedfishClientPkg/RedfishClientPkg.dec | 5 +-
> RedfishClientPkg/RedfishClientLibs.dsc.inc | 1 +
> .../EdkIIRedfishResourceConfigLib.inf | 49 ++
> .../Library/EdkIIRedfishResourceConfigLib.h | 162 +++++
> .../Protocol/EdkIIRedfishInterchangeData.h | 52 ++
> .../RedfishFeatureUtilityInternal.h | 3 +-
> .../EdkIIRedfishResourceConfigLib.c | 603 ++++++++++++++++++
> 7 files changed, 873 insertions(+), 2 deletions(-) create mode 100644
> RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResour
> ceConfigLib.inf
> create mode 100644
> RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h
> create mode 100644
> RedfishClientPkg/Include/Protocol/EdkIIRedfishInterchangeData.h
> create mode 100644
> RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResour
> ceConfigLib.c
>
> diff --git a/RedfishClientPkg/RedfishClientPkg.dec
> b/RedfishClientPkg/RedfishClientPkg.dec
> index 2ce51d14..9d18c42c 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
> +
> + EdkIIRedfishResourceConfigLib|Include/Library/EdkIIRedfishResourceConf
> + igLib.h
> RedfishEventLib|Include/Library/RedfishEventLib.h
> RedfishVersionLib|Include/Library/RedfishVersionLib.h
>
> @@ -36,6 +37,8 @@
> gEdkIIRedfishResourceConfigProtocolGuid = { 0x6f164c68, 0xfb09, 0x4646,
> { 0xa8, 0xd3, 0x24, 0x11, 0x5d, 0xab, 0x3e, 0xe7 } }
> ## Include/Protocol/EdkiiRedfishETagProtocol.h
> gEdkIIRedfishETagProtocolGuid = { 0x5706d368, 0xaf66, 0x48f5, { 0x89,
> 0xfc, 0xa6, 0x61, 0xce, 0xb5, 0xa6, 0xa9 } }
> + ## Include/Protocol/EdkIIRedfishInterchangeData.h
> + gEdkIIRedfishFeatureInterchangeDataProtocolGuid = { 0x4B8FF71C,
> + 0x4A7B, 0x9478, { 0xB7, 0x81, 0x35, 0x9B, 0x0A, 0xF2, 0x00, 0x91 } }
>
> [Guids]
> ## Include/Guid/RedfishClientPkgTokenSpace.h
> diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> index 1cf04069..8acb4791 100644
> --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> @@ -28,5 +28,6 @@
>
> RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/
> RedfishContentCodingLibNull.inf
>
> ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/Converte
> rCommonLib/ConverterCommonLib.inf
>
> +
> + EdkIIRedfishResourceConfigLib|RedfishClientPkg/Library/EdkIIRedfishRes
> + ourceConfigLib/EdkIIRedfishResourceConfigLib.inf
>
> RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.i
> nf
>
> RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVersi
> onLib.inf
> diff --git
> a/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishReso
> urceConfigLib.inf
> b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishRes
> ourceConfigLib.inf
> new file mode 100644
> index 00000000..0da3423d
> --- /dev/null
> +++ b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfis
> +++ hResourceConfigLib.inf
> @@ -0,0 +1,49 @@
> +## @file
> +#
> +# (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR> # #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> + INF_VERSION = 0x00010006
> + BASE_NAME = EdkIIRedfishResourceConfigLib
> + FILE_GUID = B41884F6-693B-4ADE-9558-5C220A24A025
> + MODULE_TYPE = DXE_DRIVER
> + VERSION_STRING = 1.0
> + LIBRARY_CLASS = EdkIIRedfishResourceConfigLib| DXE_DRIVER
> + CONSTRUCTOR = RedfishResourceConfigConstructor
> + DESTRUCTOR = RedfishResourceConfigDestructor
> +
> +#
> +# VALID_ARCHITECTURES = IA32 X64 EBC
> +#
> +
> +[Sources]
> + EdkIIRedfishResourceConfigLib.c
> +
> +[Packages]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + RedfishPkg/RedfishPkg.dec
> + RedfishClientPkg/RedfishClientPkg.dec
> +
> +[LibraryClasses]
> + BaseLib
> + DebugLib
> + UefiBootServicesTableLib
> + BaseMemoryLib
> + PcdLib
> + MemoryAllocationLib
> + RedfishFeatureUtilityLib
> + RedfishPlatformConfigLib
> +
> +[Protocols]
> + gEdkIIRedfishResourceConfigProtocolGuid ## CONSUMES ##
> + gEdkIIRedfishFeatureInterchangeDataProtocolGuid ## CONSUMES ##
> +
> +[Pcd]
> + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize
> + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize
> +
> diff --git
> a/RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h
> b/RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h
> new file mode 100644
> index 00000000..a7856033
> --- /dev/null
> +++ b/RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h
> @@ -0,0 +1,162 @@
> +/** @file
> + This file defines the EDKII resource config Library interface.
> +
> + (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef EDKII_REDFISH_RESOURCE_CONFIG_LIB_H_
> +#define EDKII_REDFISH_RESOURCE_CONFIG_LIB_H_
> +
> +#include <Uefi.h>
> +#include <Library/PcdLib.h>
> +#include <Library/RedfishLib.h>
> +#include <Protocol/RestJsonStructure.h> #include
> +<Protocol/EdkIIRedfishResourceConfigProtocol.h>
> +#include <Protocol/EdkIIRedfishInterchangeData.h>
> +
> +/**
> + Provising redfish resource by given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri Target URI to create resource.
> + @param[in] InformationExchange Pointer to
> RESOURCE_INFORMATION_EXCHANGE.
> + @param[in] HttpPostMode TRUE if resource does not exist, HTTP
> POST method is used.
> + FALSE if the resource exist but some of properties are
> missing,
> + HTTP PUT method is used.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigProvisionging (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri,
> + IN RESOURCE_INFORMATION_EXCHANGE *InformationExchange,
> + IN BOOLEAN HttpPostMode
> + );
> +
> +/**
> + Consume resource from given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri The target URI to consume.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigConsume (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri
> + );
> +
> +/**
> + Update resource to given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri The target URI to consume.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigUpdate (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri
> + );
> +
> +/**
> + Check resource on given URI.
> +
> + @param[in] Uri The target URI to consume.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigCheck (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri
> + );
> +
> +/**
> + Identify resource on given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri The target URI to consume.
> + @param[in] InformationExchange Pointer to
> RESOURCE_INFORMATION_EXCHANGE.
> +
> + @retval EFI_SUCCESS This is target resource which we want to
> handle.
> + @retval EFI_UNSUPPORTED This is not the target resource.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigIdentify (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri,
> + IN RESOURCE_INFORMATION_EXCHANGE *InformationExchangeUri
> + );
> +
> +/**
> + Set Configure language of this resource in the
> + RESOURCE_INFORMATION_EXCHANGE structure.
> +
> + @param[in] ConfigLangList Pointer to
> REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST.
> +
> + @retval EFI_SUCCESS Configure language is set.
> + @retval EFI_UNSUPPORTED
> EdkIIRedfishFeatureInterchangeDataProtocol is not found.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceSetConfigureLang (
> + REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST *ConfigLangList
> + );
> +
> +/**
> +
> + Get schema information by given protocol and service instance.
> +
> + @param[in] RedfishService Pointer to Redfish service instance.
> + @param[in] JsonStructProtocol Json Structure protocol instance.
> + @param[in] Uri Target URI.
> + @param[out] SchemaInfo Returned schema information.
> +
> + @retval EFI_SUCCESS Schema information is returned successfully.
> + @retval Others Errors occur.
> +
> +**/
> +EFI_STATUS
> +GetRedfishSchemaInfo (
> + IN REDFISH_SERVICE *RedfishService,
> + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *JsonStructProtocol,
> + IN EFI_STRING Uri,
> + OUT REDFISH_SCHEMA_INFO *SchemaInfo
> + );
> +
> +/**
> +
> + Get supported schema list by given specify schema name.
> +
> + @param[in] Schema Schema type name.
> + @param[out] SchemaInfo Returned schema information.
> +
> + @retval EFI_SUCCESS Schema information is returned successfully.
> + @retval Others Errors occur.
> +
> +**/
> +EFI_STATUS
> +GetSupportedSchemaVersion (
> + IN CHAR8 *Schema,
> + OUT REDFISH_SCHEMA_INFO *SchemaInfo
> + );
> +
> +#endif
> diff --git
> a/RedfishClientPkg/Include/Protocol/EdkIIRedfishInterchangeData.h
> b/RedfishClientPkg/Include/Protocol/EdkIIRedfishInterchangeData.h
> new file mode 100644
> index 00000000..b2841b66
> --- /dev/null
> +++ b/RedfishClientPkg/Include/Protocol/EdkIIRedfishInterchangeData.h
> @@ -0,0 +1,52 @@
> +/** @file
> + This file defines the
> EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL interface.
> +
> + (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_H_
> +#define EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_H_
> +
> +#include <Library/RedfishFeatureUtilityLib.h>
> +
> +typedef struct
> _EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL
> +EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL;
> +
> +#define EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL_GUID
> \
> + { \
> + 0x4B8FF71C, 0x4A7B, 0x9478, { 0xB7, 0x81, 0x35, 0x9B, 0x0A, 0xF2, 0x00,
> 0x91 } \
> + }
> +
> +typedef enum {
> + InformationTypeNone = 0, ///< Invalid information.
> + InformationTypeCollectionMemberUri, ///< URI to the new created
> collection member.
> + InformationTypeCollectionMemberConfigLanguage, ///< URI to the new
> created collection member.
> + InformationTypeMax
> +} RESOURCE_INFORMATION_EXCHANGE_TYPE;
> +
> +typedef struct {
> + RESOURCE_INFORMATION_EXCHANGE_TYPE Type;
> + EFI_STRING ParentUri; ///< The parent URI (in configure
> language) of the resource to process.
> + EFI_STRING PropertyName; ///< The property name of the
> resource to process.
> + EFI_STRING FullUri; ///< The full URI (in configure language)
> of the resource to process.
> +} RESOURCE_INFORMATION_SEND;
> +
> +typedef struct {
> + RESOURCE_INFORMATION_EXCHANGE_TYPE Type;
> + REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST
> ConfigureLanguageList;
> +} RESOURCE_INFORMATION_RETURNED;
> +
> +typedef struct {
> + RESOURCE_INFORMATION_SEND SendInformation;
> + RESOURCE_INFORMATION_RETURNED ReturnedInformation;
> +} RESOURCE_INFORMATION_EXCHANGE;
> +
> +struct _EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL {
> + RESOURCE_INFORMATION_EXCHANGE *ResourceInformationExchage;
> +};
> +
> +extern EFI_GUID gEdkIIRedfishFeatureInterchangeDataProtocolGuid;
> +
> +#endif
> diff --git
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityInt
> ernal.h
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityInt
> ernal.h
> index cfb9759a..8ded4ac6 100644
> ---
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityInt
> ernal.h
> +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUt
> +++ ilityInternal.h
> @@ -34,7 +34,8 @@
> #define INDEX_STRING_SIZE 16
> #define IS_EMPTY_STRING(a) (a == NULL || a[0] == '\0')
> #define INDEX_STRING L"{%d}"
> -#define SCHEMA_NAME_PREFIX_OFFSET 15// x-uefi-redfish-
> +#define SCHEMA_NAME_PREFIX "x-uefi-redfish-"
> +#define SCHEMA_NAME_PREFIX_OFFSET (AsciiStrLen
> (SCHEMA_NAME_PREFIX))
> #define REDFISH_SYSTEM_ROOT_PATH "/v1/Systems[UUID~%g]"
> #define MAX_CONF_LANG_LEN 128
>
> diff --git
> a/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishReso
> urceConfigLib.c
> b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishRes
> ourceConfigLib.c
> new file mode 100644
> index 00000000..b1eaad75
> --- /dev/null
> +++ b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfis
> +++ hResourceConfigLib.c
> @@ -0,0 +1,603 @@
> +/** @file
> + Redfish resource config library implementation
> +
> + (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +#include <RedfishBase.h>
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/MemoryAllocationLib.h> #include
> +<Library/UefiBootServicesTableLib.h>
> +#include <Library/EdkIIRedfishResourceConfigLib.h>
> +#include <Library/RedfishFeatureUtilityLib.h>
> +#include <Library/RedfishPlatformConfigLib.h>
> +
> +EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL
> *mRedfishResourceConfigProtocol = NULL;
> +EFI_HANDLE medfishResourceConfigProtocolHandle;
> +EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL
> mRedfishFeatureInterchangeData;
> +REDFISH_SCHEMA_INFO mSchemaInfoCache;
> +
> +#define SCHEMA_NAME_PREFIX "x-uefi-redfish-"
> +#define SCHEMA_NAME_PREFIX_OFFSET (AsciiStrLen
> (SCHEMA_NAME_PREFIX))
> +
> +/**
> +
> + Get schema information by given protocol and service instance.
> +
> + @param[in] RedfishService Pointer to Redfish service instance.
> + @param[in] JsonStructProtocol Json Structure protocol instance.
> + @param[in] Uri Target URI.
> + @param[out] SchemaInfo Returned schema information.
> +
> + @retval EFI_SUCCESS Schema information is returned successfully.
> + @retval Others Errors occur.
> +
> +**/
> +EFI_STATUS
> +GetRedfishSchemaInfo (
> + IN REDFISH_SERVICE *RedfishService,
> + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *JsonStructProtocol,
> + IN EFI_STRING Uri,
> + OUT REDFISH_SCHEMA_INFO *SchemaInfo
> + )
> +{
> + EFI_STATUS Status;
> + REDFISH_RESPONSE Response;
> + REDFISH_PAYLOAD Payload;
> + CHAR8 *JsonText;
> + EFI_REST_JSON_STRUCTURE_HEADER *Header;
> +
> + if ((RedfishService == NULL) || (JsonStructProtocol == NULL) ||
> IS_EMPTY_STRING (Uri) || (SchemaInfo == NULL)) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + Status = GetResourceByUri (RedfishService, Uri, &Response); if
> + (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a, failed to get resource from %s: %r",
> __FUNCTION__, Uri, Status));
> + return Status;
> + }
> +
> + Payload = Response.Payload;
> + ASSERT (Payload != NULL);
> +
> + JsonText = JsonDumpString (RedfishJsonInPayload (Payload),
> + EDKII_JSON_COMPACT); ASSERT (JsonText != NULL);
> +
> + //
> + // Convert JSON text to C structure.
> + //
> + Status = JsonStructProtocol->ToStructure (
> + JsonStructProtocol,
> + NULL,
> + JsonText,
> + &Header
> + );
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n",
> __FUNCTION__, Status));
> + return Status;
> + }
> +
> + AsciiStrCpyS (SchemaInfo->Schema, REDFISH_SCHEMA_STRING_SIZE,
> + Header->JsonRsrcIdentifier.NameSpace.ResourceTypeName);
> + AsciiStrCpyS (SchemaInfo->Major, REDFISH_SCHEMA_VERSION_SIZE,
> + Header->JsonRsrcIdentifier.NameSpace.MajorVersion);
> + AsciiStrCpyS (SchemaInfo->Minor, REDFISH_SCHEMA_VERSION_SIZE,
> + Header->JsonRsrcIdentifier.NameSpace.MinorVersion);
> + AsciiStrCpyS (SchemaInfo->Errata, REDFISH_SCHEMA_VERSION_SIZE,
> + Header->JsonRsrcIdentifier.NameSpace.ErrataVersion);
> +
> + //
> + // Release resource.
> + //
> + JsonStructProtocol->DestoryStructure (JsonStructProtocol, Header);
> + FreePool (JsonText); RedfishFreeResponse (Response.StatusCode,
> + Response.HeaderCount, Response.Headers, Response.Payload);
> +
> + return EFI_SUCCESS;
> +}
> +
> +/**
> +
> + Get supported schema list by given specify schema name.
> +
> + @param[in] Schema Schema type name.
> + @param[out] SchemaInfo Returned schema information.
> +
> + @retval EFI_SUCCESS Schema information is returned successfully.
> + @retval Others Errors occur.
> +
> +**/
> +EFI_STATUS
> +GetSupportedSchemaVersion (
> + IN CHAR8 *Schema,
> + OUT REDFISH_SCHEMA_INFO *SchemaInfo
> + )
> +{
> + EFI_STATUS Status;
> + CHAR8 *SupportSchema;
> + CHAR8 *SchemaName;
> + UINTN Index;
> + UINTN Index2;
> + BOOLEAN Found;
> +
> + if (IS_EMPTY_STRING (Schema) || (SchemaInfo == NULL)) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + Status = RedfishPlatformConfigGetSupportedSchema (NULL,
> + &SupportSchema); if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + DEBUG ((DEBUG_INFO, "Supported schema: %a\n", SupportSchema));
> +
> + Index = 0;
> + Found = FALSE;
> + SchemaName = SupportSchema;
> + while (TRUE) {
> + if ((SupportSchema[Index] == ';') || (SupportSchema[Index] == '\0')) {
> + if (AsciiStrnCmp (&SchemaName[SCHEMA_NAME_PREFIX_OFFSET],
> Schema, AsciiStrLen (Schema)) == 0) {
> + Found = TRUE;
> + SupportSchema[Index] = '\0';
> + break;
> + }
> +
> + SchemaName = &SupportSchema[Index + 1];
> + }
> +
> + if (SupportSchema[Index] == '\0') {
> + break;
> + }
> +
> + ++Index;
> + }
> +
> + if (Found) {
> + AsciiStrCpyS (SchemaInfo->Schema, REDFISH_SCHEMA_STRING_SIZE,
> + Schema);
> +
> + //
> + // forward to '.'
> + //
> + Index = 0;
> + while (SchemaName[Index] != '\0' && SchemaName[Index] != '.') {
> + ++Index;
> + }
> +
> + ASSERT (SchemaName[Index] != '\0');
> +
> + //
> + // Skip '.' and 'v'
> + //
> + Index += 2;
> +
> + //
> + // forward to '_'
> + //
> + Index2 = Index;
> + while (SchemaName[Index2] != '\0' && SchemaName[Index2] != '_') {
> + ++Index2;
> + }
> +
> + ASSERT (SchemaName[Index2] != '\0');
> +
> + AsciiStrnCpyS (SchemaInfo->Major, REDFISH_SCHEMA_VERSION_SIZE,
> &SchemaName[Index], (Index2 - Index));
> + Index = Index2;
> +
> + //
> + // Skip '_'
> + //
> + ++Index;
> +
> + //
> + // forward to '_'
> + //
> + Index2 = Index;
> + while (SchemaName[Index2] != '\0' && SchemaName[Index2] != '_') {
> + ++Index2;
> + }
> +
> + ASSERT (SchemaName[Index2] != '\0');
> +
> + AsciiStrnCpyS (SchemaInfo->Minor, REDFISH_SCHEMA_VERSION_SIZE,
> &SchemaName[Index], (Index2 - Index));
> + Index = Index2;
> +
> + //
> + // Skip '_'
> + //
> + ++Index;
> +
> + AsciiStrCpyS (SchemaInfo->Errata, REDFISH_SCHEMA_VERSION_SIZE,
> + &SchemaName[Index]); }
> +
> + FreePool (SupportSchema);
> +
> + return (Found ? EFI_SUCCESS : EFI_NOT_FOUND); }
> +
> +/**
> +
> + Find Redfish Resource Config Protocol that supports given schema and
> version.
> +
> + @param[in] Schema Schema name.
> + @param[out] Handle Pointer to receive the handle that has
> EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL
> + installed on it.
> +
> + @retval EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL * Pointer to
> protocol
> + @retval NULL No protocol found.
> +
> +**/
> +EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *
> +GetRedfishResourceConfigProtocol (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + OUT EFI_HANDLE *Handle OPTIONAL
> + )
> +{
> + EFI_STATUS Status;
> + EFI_HANDLE *HandleBuffer;
> + UINTN NumberOfHandles;
> + UINTN Index;
> + EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *Protocol;
> + REDFISH_SCHEMA_INFO SchemaInfo;
> + BOOLEAN Found;
> +
> + if (IS_EMPTY_STRING (Schema->Schema) ||
> + IS_EMPTY_STRING (Schema->Major) ||
> + IS_EMPTY_STRING (Schema->Minor) ||
> + IS_EMPTY_STRING (Schema->Errata)
> + )
> + {
> + return NULL;
> + }
> +
> + if (mRedfishResourceConfigProtocol != NULL) {
> + if ((AsciiStrCmp (Schema->Schema, mSchemaInfoCache.Schema) == 0)
> &&
> + (AsciiStrCmp (Schema->Major, mSchemaInfoCache.Major) == 0) &&
> + (AsciiStrCmp (Schema->Minor, mSchemaInfoCache.Minor) == 0) &&
> + (AsciiStrCmp (Schema->Errata, mSchemaInfoCache.Errata) == 0))
> + {
> + if (Handle != NULL) {
> + *Handle = medfishResourceConfigProtocolHandle;
> + }
> +
> + return mRedfishResourceConfigProtocol;
> + }
> + }
> +
> + Status = gBS->LocateHandleBuffer (
> + ByProtocol,
> + &gEdkIIRedfishResourceConfigProtocolGuid,
> + NULL,
> + &NumberOfHandles,
> + &HandleBuffer
> + );
> + if (EFI_ERROR (Status)) {
> + return NULL;
> + }
> +
> + Found = FALSE;
> +
> + for (Index = 0; Index < NumberOfHandles; Index++) {
> + Status = gBS->HandleProtocol (
> + HandleBuffer[Index],
> + &gEdkIIRedfishResourceConfigProtocolGuid,
> + (VOID **)&Protocol
> + );
> + if (EFI_ERROR (Status)) {
> + continue;
> + }
> +
> + Status = Protocol->GetInfo (Protocol, &SchemaInfo);
> + if (EFI_ERROR (Status)) {
> + continue;
> + }
> +
> + if ((AsciiStrCmp (Schema->Schema, SchemaInfo.Schema) == 0) &&
> + (AsciiStrCmp (Schema->Major, SchemaInfo.Major) == 0) &&
> + (AsciiStrCmp (Schema->Minor, SchemaInfo.Minor) == 0) &&
> + (AsciiStrCmp (Schema->Errata, SchemaInfo.Errata) == 0))
> + {
> + Found = TRUE;
> + break;
> + }
> + }
> +
> + if (Found) {
> + medfishResourceConfigProtocolHandle = HandleBuffer[Index];
> + mRedfishResourceConfigProtocol = Protocol;
> + CopyMem (&mSchemaInfoCache, Schema, sizeof
> (REDFISH_SCHEMA_INFO));
> + if (Handle != NULL) {
> + *Handle = HandleBuffer[Index];
> + }
> + }
> +
> + FreePool (HandleBuffer);
> +
> + return (Found ? Protocol : NULL);
> +}
> +
> +/**
> + Install EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL
> + on child feature driver handle.
> +
> + @param[in] Handle Handle to install
> EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL.
> + @param[in] InformationExchange Pointer to
> RESOURCE_INFORMATION_EXCHANGE.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +InstallInterchangeDataProtocol (
> + IN EFI_HANDLE Handle,
> + IN RESOURCE_INFORMATION_EXCHANGE *InformationExchange
> + )
> +{
> + EFI_STATUS Status;
> + EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL *Interface;
> +
> + Status = gBS->HandleProtocol (
> + Handle,
> + &gEdkIIRedfishFeatureInterchangeDataProtocolGuid,
> + (VOID **)&Interface
> + );
> + if (!EFI_ERROR (Status)) {
> + Interface->ResourceInformationExchage = InformationExchange;
> + return EFI_SUCCESS;
> + }
> +
> + if (Status == EFI_UNSUPPORTED) {
> + mRedfishFeatureInterchangeData.ResourceInformationExchage =
> InformationExchange;
> + Status = gBS->InstallProtocolInterface (
> + &Handle,
> +
> &gEdkIIRedfishFeatureInterchangeDataProtocolGuid,
> + EFI_NATIVE_INTERFACE,
> + (VOID
> *)&mRedfishFeatureInterchangeData
> +
> + ); }
> +
> + return Status;
> +}
> +
> +/**
> + Set Configure language of this resource in the
> + RESOURCE_INFORMATION_EXCHANGE structure.
> +
> + @param[in] ConfigLangList Pointer to
> REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST.
> +
> + @retval EFI_SUCCESS Configure language is set.
> + @retval EFI_UNSUPPORTED
> EdkIIRedfishFeatureInterchangeDataProtocol is not found.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceSetConfigureLang (
> + REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST *ConfigLangList
> + )
> +{
> + EFI_STATUS Status;
> + UINTN Index;
> + EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL *Interface;
> +
> + Status = gBS->HandleProtocol (
> + medfishResourceConfigProtocolHandle,
> + &gEdkIIRedfishFeatureInterchangeDataProtocolGuid,
> + (VOID **)&Interface
> + );
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a,
> EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL is not installed
> %r", __FUNCTION__, Status));
> + return Status;
> + }
> +
> + Interface->ResourceInformationExchage->ReturnedInformation.Type
> = InformationTypeCollectionMemberConfigLanguage;
> +
> + Interface->ResourceInformationExchage-
> >ReturnedInformation.ConfigureLanguageList.Count = ConfigLangList-
> >Count; Interface->ResourceInformationExchage-
> >ReturnedInformation.ConfigureLanguageList.List =
> + AllocateZeroPool (sizeof
> (REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG) *
> + ConfigLangList->Count); if (Interface->ResourceInformationExchage-
> >ReturnedInformation.ConfigureLanguageList.List == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for
> REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG.\n", __FUNCTION__));
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + for (Index = 0; Index < ConfigLangList->Count; Index++) {
> + Interface->ResourceInformationExchage-
> >ReturnedInformation.ConfigureLanguageList.List[Index].Index =
> ConfigLangList->List[Index].Index;
> + Interface->ResourceInformationExchage-
> >ReturnedInformation.ConfigureLanguageList.List[Index].ConfigureLang =
> + (EFI_STRING)AllocateCopyPool (StrSize
> + (ConfigLangList->List[Index].ConfigureLang), (VOID
> + *)ConfigLangList->List[Index].ConfigureLang);
> + }
> +
> + return EFI_SUCCESS;
> +}
> +
> +/**
> + Provising redfish resource by given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri Target URI to create resource.
> + @param[in] InformationExchange Pointer to
> RESOURCE_INFORMATION_EXCHANGE.
> + @param[in] HttpPostMode TRUE if resource does not exist, HTTP
> POST method is used.
> + FALSE if the resource exist but some of properties are
> missing,
> + HTTP PUT method is used.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigProvisionging (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri,
> + IN RESOURCE_INFORMATION_EXCHANGE *InformationExchange,
> + IN BOOLEAN HttpPostMode
> + )
> +{
> + EFI_HANDLE Handle;
> + EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *protocol;
> +
> + protocol = GetRedfishResourceConfigProtocol (Schema, &Handle); if
> + ((protocol == NULL) || (Handle == NULL)) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> + //
> + // Install EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL on
> the
> +child
> + // feature driver handle.
> + //
> + InstallInterchangeDataProtocol (Handle, InformationExchange);
> + return protocol->Provisioning (protocol, Uri, HttpPostMode); }
> +
> +/**
> + Consume resource from given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri The target URI to consume.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigConsume (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri
> + )
> +{
> + EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *protocol;
> +
> + protocol = GetRedfishResourceConfigProtocol (Schema, NULL); if
> + (protocol == NULL) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> + return protocol->Consume (protocol, Uri); }
> +
> +/**
> + Update resource to given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri The target URI to consume.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigUpdate (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri
> + )
> +{
> + EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *protocol;
> +
> + protocol = GetRedfishResourceConfigProtocol (Schema, NULL); if
> + (protocol == NULL) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> + return protocol->Update (protocol, Uri); }
> +
> +/**
> + Check resource on given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri The target URI to consume.
> +
> + @retval EFI_SUCCESS Value is returned successfully.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigCheck (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri
> + )
> +{
> + EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *protocol;
> +
> + protocol = GetRedfishResourceConfigProtocol (Schema, NULL); if
> + (protocol == NULL) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> + return protocol->Check (protocol, Uri); }
> +
> +/**
> + Identify resource on given URI.
> +
> + @param[in] Schema Redfish schema information.
> + @param[in] Uri The target URI to consume.
> + @param[in] InformationExchange Pointer to
> RESOURCE_INFORMATION_EXCHANGE.
> +
> + @retval EFI_SUCCESS This is target resource which we want to
> handle.
> + @retval EFI_UNSUPPORTED This is not the target resource.
> + @retval Others Some error happened.
> +
> +**/
> +EFI_STATUS
> +EdkIIRedfishResourceConfigIdentify (
> + IN REDFISH_SCHEMA_INFO *Schema,
> + IN EFI_STRING Uri,
> + IN RESOURCE_INFORMATION_EXCHANGE *InformationExchange
> + )
> +{
> + EFI_HANDLE Handle;
> + EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *protocol;
> +
> + protocol = GetRedfishResourceConfigProtocol (Schema, &Handle); if
> + (protocol == NULL) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> + //
> + // Install EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_PROTOCOL on
> the
> +child
> + // feature driver handle.
> + //
> + InstallInterchangeDataProtocol (Handle, InformationExchange);
> + return protocol->Identify (protocol, Uri); }
> +
> +/**
> +
> + Initial resource config 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
> +RedfishResourceConfigConstructor (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + mRedfishResourceConfigProtocol = NULL;
> + ZeroMem (&mSchemaInfoCache, sizeof (REDFISH_SCHEMA_INFO));
> +
> + 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
> +RedfishResourceConfigDestructor (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + mRedfishResourceConfigProtocol = NULL;
> +
> + return EFI_SUCCESS;
> +}
> --
> 2.17.1
prev parent 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 4/6] RedfishClientPkg: Introduce Redfish resource config 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=MN2PR12MB3966DA49C999910A6F3999CFEA779@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