From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web09.23387.1658712967257128419 for ; Sun, 24 Jul 2022 18:36:07 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=XB9vnuDu; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0205fca832=nickle.wang@hpe.com) Received: from pps.filterd (m0148663.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26OJTY87027459; Mon, 25 Jul 2022 01:36:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pps0720; bh=m3u//5Zha/mB5JtA9m1tOXv88HWrTRP7vv0L5aNjRE8=; b=XB9vnuDulNsp3EFmUSkeOjroYWDR+xbdhmeozMb2qat/l+Xw5HJunRZk/BerIDxGGd7j xje3K1pTvFeSBawA0kJVsw9NsYimA62QxPFtww5cxyIJGMZ+b30d0kMH7VadV7XUqTu4 fRPts+u9j5R/5Mrc8SUraINzm1VH4foI7kGqsKsvFUFOFMh3RVXKNIUUQVm7oUCySCR+ zR53LYwH2Lktt95/mkJzbUQtNCaMi1O4X530AuQ66B13XCdjipoV4KJ/JX+zs0mXN96r hwmdIjMUtjI7qZVrDCerCSWoOtbcrtwP2Mc6ltzO05OHXSrQ3eI4hUtlhdixjyuHUXpq TA== Received: from p1lg14881.it.hpe.com (p1lg14881.it.hpe.com [16.230.97.202]) by mx0a-002e3701.pphosted.com (PPS) with ESMTPS id 3hhc971jnk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Jul 2022 01:36:05 +0000 Received: from p1lg14886.dc01.its.hpecorp.net (unknown [10.119.18.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by p1lg14881.it.hpe.com (Postfix) with ESMTPS id 6D62B804C9C; Mon, 25 Jul 2022 01:36:04 +0000 (UTC) Received: from WAFM3XJD5N.asiapacific.hpqcorp.net (unknown [16.231.227.36]) by p1lg14886.dc01.its.hpecorp.net (Postfix) with ESMTP id 1CCD7800B83; Mon, 25 Jul 2022 01:36:02 +0000 (UTC) From: "Nickle Wang" To: devel@edk2.groups.io Cc: Abner Chang , Yang Atom , Nick Ramirez Subject: [edk2-staging][PATCH v2 04/15] edk2-staging/RedfishClientPkg: Introduce Redfish resource config library Date: Mon, 25 Jul 2022 09:35:44 +0800 Message-Id: <20220725013555.926-5-nickle.wang@hpe.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20220725013555.926-1-nickle.wang@hpe.com> References: <20220725013555.926-1-nickle.wang@hpe.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 24dIq13aqfBdHCEyYm4LzeS1R9pCegMA X-Proofpoint-GUID: 24dIq13aqfBdHCEyYm4LzeS1R9pCegMA X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-23_02,2022-07-21_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 priorityscore=1501 spamscore=0 clxscore=1015 impostorscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207250005 Content-Transfer-Encoding: 8bit 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 Cc: Abner Chang Cc: Yang Atom Cc: Nick Ramirez --- .../Library/EdkIIRedfishResourceConfigLib.h | 163 +++++ .../Protocol/EdkIIRedfishInterchangeData.h | 52 ++ .../EdkIIRedfishResourceConfigLib.c | 593 ++++++++++++++++++ .../EdkIIRedfishResourceConfigLib.inf | 49 ++ RedfishClientPkg/RedfishClientLibs.dsc.inc | 1 + RedfishClientPkg/RedfishClientPkg.dec | 5 +- 6 files changed, 862 insertions(+), 1 deletion(-) create mode 100644 RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h create mode 100644 RedfishClientPkg/Include/Protocol/EdkIIRedfishInterchangeData.h create mode 100644 RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.c create mode 100644 RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.inf diff --git a/RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h b/RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h new file mode 100644 index 0000000000..1e843ec551 --- /dev/null +++ b/RedfishClientPkg/Include/Library/EdkIIRedfishResourceConfigLib.h @@ -0,0 +1,163 @@ +/** @file + This file defines the EDKII resource config Library interface. + + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_REDFISH_RESOURCE_CONFIG_LIB_H_ +#define EDKII_REDFISH_RESOURCE_CONFIG_LIB_H_ + +#include +#include +#include +#include +#include +#include +/** + 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 0000000000..e8d0462fb7 --- /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
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_H_ +#define EDKII_REDFISH_FEATURE_INTERCHANGE_DATA_H_ + +#include + +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/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.c b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.c new file mode 100644 index 0000000000..d09da6bd67 --- /dev/null +++ b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.c @@ -0,0 +1,593 @@ +/** @file + Redfish resource config library implementation + + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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_OFFSET 15 // x-uefi-redfish- + +/** + + 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; +} diff --git a/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.inf b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.inf new file mode 100644 index 0000000000..0da3423d26 --- /dev/null +++ b/RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.inf @@ -0,0 +1,49 @@ +## @file +# +# (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+# +# 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/RedfishClientLibs.dsc.inc b/RedfishClientPkg/RedfishClientLibs.dsc.inc index 1cf0406912..8acb479170 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/ConverterCommonLib/ConverterCommonLib.inf + EdkIIRedfishResourceConfigLib|RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.inf RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.inf RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/RedfishClientPkg.dec index 2ce51d14af..9d18c42c24 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
+# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
# # SPDX-License-Identifier: BSD-2-Clause-Patent ## @@ -21,6 +21,7 @@ [LibraryClasses] RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h + EdkIIRedfishResourceConfigLib|Include/Library/EdkIIRedfishResourceConfigLib.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 -- 2.32.0.windows.2