From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (NAM02-DM3-obe.outbound.protection.outlook.com [40.107.95.64]) by mx.groups.io with SMTP id smtpd.web11.18414.1683876198777439274 for ; Fri, 12 May 2023 00:23:18 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=QHJcaqSW; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.95.64, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z1omEyXOO5Aj+IQ/k2IXZ6HkHzVYttnQAQB61ubD3Gi/6r8Q6PeywPHVvIQfUzh+n5qZOV9VP5Cdx4t825uwj9JWcTZTFA6SJ6wZz3t12+lFdcQdbbYJaIft15e2Tjspx3ef1+WnVz+neD+3ac+qUQb88puoIQqURwDNq5CWXkfPTnrhQih/hKXav7lTjQuxFdTZ/syUagy2My97uQEZZZ1Y6Tg1+bVkfXhREJpvxWEQo9x5Mj0aHYBHQ7IMFiOREm+6W1DQoWKzxL73fVGe3uAPge9q2K+c20hJ7H2dlKE9GCQ5GNcEu9j9gq6SZT9sQfPkkMC06NPTQ0a+5GlQMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=l3hge/Nu1erccGlvcEMsNXEjflEcbHDS04Cyv48K/JQ=; b=I/AIr/SbUSt1sd21BGeWjfQDa6ze0Z0qj6NH2u/TnDDcOq6NRg7OoiU1jUWk7SKy34ziNJFfMqVNxlAVFaCoHiiq+b6wnvyiqG32Nj6y6Fl9iYfF2+j6QaKlORE6leAsnGjOhdfROUIYPmTy2tFXCiICUEcvX+XxvsCp1n1nMQ1emyppA6A2JI1qA29T424rDICjm+bcfNqol8VS38lUaldWZgK8nrAJyTgJH/2T2IRMREU3HPHnR9+pbK58sK97RRuCfOZBoi28XpgMAQ+WzyuIVYj8v1NXuQ6itbCw3z4d8jlWQ4KjwBTooHDbycCPMqbtNGbA2LfhiOwMeeFaBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l3hge/Nu1erccGlvcEMsNXEjflEcbHDS04Cyv48K/JQ=; b=QHJcaqSWEz7CtgmMVJjJ1qRhsYeq9PYQcbsHUYI0dU9v8rcKymL9P5geqnk7sh8ViKX48O8H2hWuWAWqjFFCWmoLWFnPK4U5yMZRQRMQ6K7N2KEurjxY7TugT0kRhHSeIT+pT5nXu9mqD1OZy+RW0FAvS32C+uSymCUrKLJYP1k4WsM/dOhNzAwUH+KbmOmJsHd0tnj3aG4to+r3Q0NC367tWmy0VaYeOahfbW3AFSI2uNXk1asnZC64uvuIBywvFLXfymTj6NmNCd5Y0RuiLyvpqYoloX2gPTmaC2AxENR5znPnvFDvkCisYTKr+XpQLdWIVkKnlP+hFCLwspZPbw== Received: from DM6PR03CA0002.namprd03.prod.outlook.com (2603:10b6:5:40::15) by DM6PR12MB4530.namprd12.prod.outlook.com (2603:10b6:5:2aa::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.21; Fri, 12 May 2023 07:23:15 +0000 Received: from DM6NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:5:40:cafe::d) by DM6PR03CA0002.outlook.office365.com (2603:10b6:5:40::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 07:23:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DM6NAM11FT019.mail.protection.outlook.com (10.13.172.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 07:23:14 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Fri, 12 May 2023 00:23:02 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Fri, 12 May 2023 00:23:02 -0700 Received: from NV-CL38DL3.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Fri, 12 May 2023 00:23:01 -0700 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy Subject: [edk2-redfish-client][PATCH 2/3] RedfishClientPkg: Add Redfish Resource Addendum Library Date: Fri, 12 May 2023 15:23:01 +0800 Message-ID: <20230512072301.17881-1-nicklew@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Return-Path: nicklew@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT019:EE_|DM6PR12MB4530:EE_ X-MS-Office365-Filtering-Correlation-Id: 383cd342-04de-4701-eff9-08db52b9c03f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D6HAiaD9ZEKFHHAFETL3jKyTHgFBGDd3qzXwodGe3uk62ys62tTCJMyEXCXdG9FNjYYuAYXnMILStWntPaoCmM1rsA9pu6AvBr33jjS59fQHhlKsB5UGRipBXzvMto3WsEqa2vBOrAuvB3WZ+75qAQvK98tW3PhTQMkddjQfKBRD7Xct/v2ycVshb7Cmgi7Tw9VyPvNE67sIsIBVc8389KJVvatBNpJCJcYntpyRNJMFLGrUwznBAh/YrUwhA+ifYQ6sqJSQ6H5gN2xPT07a6FePID9hIRDeBv27G6sEIxIaUyF3UIdxiR1ZcRD28LXase7RrlGj8B1BxNtCVK5eUYqfc8/axTBEBkFS0pq0ieYo9PgUys+FTzd/hbUg1ab77adnUf47Yc2zY9Lxftufy2+rlAVNKqbQg1Rl0LFOwevuWS0BbD2Lzy3GZbYDLBgZZTxYysNYcrDSKsg4QN6zQegNiHvowp6b6p3DE2wSsmYyAq8pVc+6RybGk2k1LpT/j1KxacEIbr1xFJpmyYIS7LKr8+zHVqkMyUwo8s7tIWayR4NkiSkGJb2IGmS6U/8I7CpnkN0PXfwszGaaeogUXo+GqIqH1ShJmvbCGw/7tZzuqlFV8jMMuIIi3D+ifn8TLsu3wYK1smM/0H1Gt/zd9clWgrtYmqu9DOov1QNSQlEWGUJTe06kYlzMx+r4Hi6tR7MOTBLNhIRu1w7IowiwbX1Tse78YrOuIDxVqbi1lqF9cWyrfc68fdQwJBgnopuk X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(39860400002)(396003)(376002)(451199021)(46966006)(36840700001)(40470700004)(36860700001)(26005)(336012)(30864003)(426003)(2906002)(1076003)(2616005)(41300700001)(5660300002)(83380400001)(47076005)(8676002)(8936002)(82740400003)(4326008)(70586007)(356005)(6916009)(40460700003)(7636003)(70206006)(316002)(186003)(478600001)(86362001)(40480700001)(36756003)(54906003)(82310400005)(7696005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 07:23:14.9494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 383cd342-04de-4701-eff9-08db52b9c03f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4530 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Implement RedfishAddendumLib to support Redfish Resource Addendum Protocol. Feature driver calls this library to get addendum data before providing data to Redfish service Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy --- RedfishClientPkg/RedfishClientLibs.dsc.inc | 4 +- RedfishClientPkg/RedfishClientPkg.dsc | 2 + .../RedfishAddendumLib/RedfishAddendumLib.inf | 40 +++ .../Include/Library/RedfishAddendumLib.h | 65 +++++ .../RedfishAddendumLib/RedfishAddendumLib.c | 262 ++++++++++++++++++ 5 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 RedfishClientPkg/Library/RedfishAddendumLib/RedfishAdde= ndumLib.inf create mode 100644 RedfishClientPkg/Include/Library/RedfishAddendumLib.h create mode 100644 RedfishClientPkg/Library/RedfishAddendumLib/RedfishAdde= ndumLib.c diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/= RedfishClientLibs.dsc.inc index fe0c4b08..5ea38015 100644 --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc @@ -2,10 +2,11 @@ # Redfish DSC include file for [LibraryClasses*] section of all Architectu= res. # # This file can be included to the [LibraryClasses*] section(s) of a platf= orm DSC file -# by using "!include RedfishPkg/RedfisLibs.dsc.inc" to specify the library= instances +# by using "!include RedfishPkg/RedfishLibs.dsc.inc" to specify the librar= y instances # of EDKII network library classes. # # (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -37,3 +38,4 @@ EdkIIRedfishResourceConfigLib|RedfishClientPkg/Library/EdkIIRedfishResou= rceConfigLib/EdkIIRedfishResourceConfigLib.inf RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib= .inf RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVers= ionLib.inf + RedfishAddendumLib|RedfishClientPkg/Library/RedfishAddendumLib/RedfishAd= dendumLib.inf diff --git a/RedfishClientPkg/RedfishClientPkg.dsc b/RedfishClientPkg/Redfi= shClientPkg.dsc index 2b2149cc..d3b645b6 100644 --- a/RedfishClientPkg/RedfishClientPkg.dsc +++ b/RedfishClientPkg/RedfishClientPkg.dsc @@ -2,6 +2,7 @@ # Redfish Client Package # # (C) Copyright 2021 Hewlett-Packard Enterprise Development LP. +# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -49,5 +50,6 @@ =20 RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityL= ib.inf RedfishClientPkg/PrivateLibrary/RedfishLib/RedfishLib.inf + RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.inf =20 !include RedfishClientPkg/RedfishClient.dsc.inc diff --git a/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib= .inf b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.inf new file mode 100644 index 00000000..1ecfaa69 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.inf @@ -0,0 +1,40 @@ +## @file +# +# Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights re= served. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D RedfishAddendumLib + FILE_GUID =3D 7B227D39-746D-4247-8291-27B0FA79A7AF + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RedfishAddendumLib| DXE_DRIVER UEFI_D= RIVER + +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + RedfishAddendumLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiBootServicesTableLib + MemoryAllocationLib + UefiLib + JsonLib + +[Protocols] + gEdkIIRedfishResourceAddendumProtocolGuid ## CONSUMED ## + diff --git a/RedfishClientPkg/Include/Library/RedfishAddendumLib.h b/Redfis= hClientPkg/Include/Library/RedfishAddendumLib.h new file mode 100644 index 00000000..d77347fd --- /dev/null +++ b/RedfishClientPkg/Include/Library/RedfishAddendumLib.h @@ -0,0 +1,65 @@ +/** @file + This file defines the Redfish addendum library interface. + + Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REDFISH_ADDENDUM_LIB_H_ +#define REDFISH_ADDENDUM_LIB_H_ + +#include +#include +#include + +/** + Provide redfish resource with addendum data in given schema. + + @param[in] Uri Uri of input resource. + @param[in] Schema Redfish schema string. + @param[in] Version Schema version string. + @param[in] JsonText Input resource in JSON format string. + @param[out] JsonWithAddendum The input resource with addendum value att= ached. + + @retval EFI_SUCCESS Addendum data is attached. + @retval EFI_NOT_FOUND No addendum protocol is found in system= . + @retval EFI_UNSUPPORTED No addendum data is required in given s= chema. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishGetAddendumData ( + IN EFI_STRING Uri, + IN CHAR8 *Schema, + IN CHAR8 *Version, + IN CHAR8 *JsonText, + OUT CHAR8 **JsonWithAddendum + ); + +/** + Provide redfish OEM resource with given schema information. + + @param[in] Uri Uri of input resource. + @param[in] Schema Redfish schema string. + @param[in] Version Schema version string. + @param[in] JsonText Input resource in JSON format string. + @param[out] JsonWithOem The input resource with OEM value attached. + + @retval EFI_SUCCESS OEM data is attached. + @retval EFI_NOT_FOUND No addendum protocol is found in system= . + @retval EFI_UNSUPPORTED No OEM data is required in given schema= . + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishGetOemData ( + IN EFI_STRING Uri, + IN CHAR8 *Schema, + IN CHAR8 *Version, + IN CHAR8 *JsonText, + OUT CHAR8 **JsonWithOem + ); + +#endif diff --git a/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib= .c b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.c new file mode 100644 index 00000000..6aa6e3cc --- /dev/null +++ b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.c @@ -0,0 +1,262 @@ +/** @file + Redfish addendum library helps Redfish application to get addendum data = and OEM + data from platform driver. + + Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include +#include +#include +#include +#include +#include + +/** + + Convert Unicode string to ASCII string. It's call responsibility to rele= ase returned buffer. + + @param[in] UnicodeStr Unicode string to convert. + + @retval CHAR8 * ASCII string returned. + @retval NULL Errors occur. + +**/ +CHAR8 * +UnicodeToAscii ( + IN EFI_STRING UnicodeStr + ) +{ + CHAR8 *AsciiStr; + UINTN AsciiStrSize; + EFI_STATUS Status; + + if (IS_EMPTY_STRING (UnicodeStr)) { + return NULL; + } + + AsciiStrSize =3D StrLen (UnicodeStr) + 1; + AsciiStr =3D AllocatePool (AsciiStrSize); + if (AsciiStr =3D=3D NULL) { + return NULL; + } + + Status =3D UnicodeStrToAsciiStrS (UnicodeStr, AsciiStr, AsciiStrSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "UnicodeStrToAsciiStrS failed: %r\n", Status)); + FreePool (AsciiStr); + return NULL; + } + + return AsciiStr; +} + +/** + Provide redfish resource with addendum data in given schema. + + @param[in] Uri Uri of input resource. + @param[in] Schema Redfish schema string. + @param[in] Version Schema version string. + @param[in] JsonText Input resource in JSON format string. + @param[out] JsonWithAddendum The input resource with addendum value att= ached. + It is the caller's responsibility to free = this buffer. + + @retval EFI_SUCCESS Addendum data is attached. + @retval EFI_NOT_FOUND No addendum protocol is found in system= . + @retval EFI_UNSUPPORTED No addendum data is required in given s= chema. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishGetAddendumData ( + IN EFI_STRING Uri, + IN CHAR8 *Schema, + IN CHAR8 *Version, + IN CHAR8 *JsonText, + OUT CHAR8 **JsonWithAddendum + ) +{ + REDFISH_RESOURCE_SCHEMA_INFO SchemaInfo; + EDKII_JSON_VALUE JsonValue; + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + UINTN Index; + EDKII_REDFISH_RESOURCE_ADDENDUM_PROTOCOL *Protocol; + + if (IS_EMPTY_STRING (Uri) || IS_EMPTY_STRING (Schema) || IS_EMPTY_STRING= (Version) || IS_EMPTY_STRING (JsonText) || (JsonWithAddendum =3D=3D NULL))= { + return EFI_INVALID_PARAMETER; + } + + *JsonWithAddendum =3D NULL; + SchemaInfo.Uri =3D UnicodeToAscii (Uri); + SchemaInfo.Schema =3D Schema; + SchemaInfo.Version =3D Version; + NumberOfHandles =3D 0; + HandleBuffer =3D NULL; + + JsonValue =3D JsonLoadString (JsonText, 0, NULL); + if ((JsonValue =3D=3D NULL) || !JsonValueIsObject (JsonValue)) { + return EFI_OUT_OF_RESOURCES; + } + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkIIRedfishResourceAddendumProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + goto ON_RELEASE; + } + + for (Index =3D 0; Index < NumberOfHandles; Index++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkIIRedfishResourceAddendumProtocolGuid, + (VOID **)&Protocol + ); + if (EFI_ERROR (Status)) { + continue; + } + + Status =3D Protocol->ProvisioningCallback (Protocol, &SchemaInfo, Json= Value); + if (!EFI_ERROR (Status)) { + *JsonWithAddendum =3D JsonDumpString (JsonValue, EDKII_JSON_COMPACT)= ; + break; + } + } + +ON_RELEASE: + + if (HandleBuffer !=3D NULL) { + FreePool (HandleBuffer); + } + + if (JsonValue !=3D NULL) { + JsonValueFree (JsonValue); + } + + if (SchemaInfo.Uri !=3D NULL) { + FreePool (SchemaInfo.Uri); + } + + return Status; +} + +/** + Provide redfish OEM resource with given schema information. + + @param[in] Uri Uri of input resource. + @param[in] Schema Redfish schema string. + @param[in] Version Schema version string. + @param[in] JsonText Input resource in JSON format string. + @param[out] JsonWithOem The input resource with OEM value attached. + + @retval EFI_SUCCESS OEM data is attached. + @retval EFI_NOT_FOUND No addendum protocol is found in system= . + @retval EFI_UNSUPPORTED No OEM data is required in given schema= . + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishGetOemData ( + IN EFI_STRING Uri, + IN CHAR8 *Schema, + IN CHAR8 *Version, + IN CHAR8 *JsonText, + OUT CHAR8 **JsonWithOem + ) +{ + REDFISH_RESOURCE_SCHEMA_INFO SchemaInfo; + EDKII_JSON_VALUE JsonValue; + EDKII_JSON_VALUE JsonValueOem; + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + UINTN Index; + EDKII_REDFISH_RESOURCE_ADDENDUM_PROTOCOL *Protocol; + + if (IS_EMPTY_STRING (Uri) || IS_EMPTY_STRING (Schema) || IS_EMPTY_STRING= (Version) || IS_EMPTY_STRING (JsonText) || (JsonWithOem =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + *JsonWithOem =3D NULL; + SchemaInfo.Uri =3D UnicodeToAscii (Uri); + SchemaInfo.Schema =3D Schema; + SchemaInfo.Version =3D Version; + JsonValue =3D NULL; + JsonValueOem =3D NULL; + NumberOfHandles =3D 0; + HandleBuffer =3D NULL; + + JsonValue =3D JsonLoadString (JsonText, 0, NULL); + if ((JsonValue =3D=3D NULL) || !JsonValueIsObject (JsonValue)) { + return EFI_OUT_OF_RESOURCES; + } + + JsonValueOem =3D JsonValueInitObject (); + if ((JsonValueOem =3D=3D NULL) || !JsonValueIsObject (JsonValueOem)) { + Status =3D EFI_OUT_OF_RESOURCES; + goto ON_RELEASE; + } + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkIIRedfishResourceAddendumProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + goto ON_RELEASE; + } + + for (Index =3D 0; Index < NumberOfHandles; Index++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkIIRedfishResourceAddendumProtocolGuid, + (VOID **)&Protocol + ); + if (EFI_ERROR (Status)) { + continue; + } + + Status =3D Protocol->OemCallback (Protocol, &SchemaInfo, JsonValueOem)= ; + if (!EFI_ERROR (Status)) { + Status =3D JsonObjectSetValue (JsonValue, "Oem", JsonValueOem); + if (!EFI_ERROR (Status)) { + *JsonWithOem =3D JsonDumpString (JsonValue, EDKII_JSON_COMPACT); + } + + break; + } + } + +ON_RELEASE: + + if (HandleBuffer !=3D NULL) { + FreePool (HandleBuffer); + } + + if (JsonValue !=3D NULL) { + JsonValueFree (JsonValue); + } + + if (JsonValueOem !=3D NULL) { + JsonValueFree (JsonValueOem); + } + + if (SchemaInfo.Uri !=3D NULL) { + FreePool (SchemaInfo.Uri); + } + + return Status; +} --=20 2.17.1