From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.64]) by mx.groups.io with SMTP id smtpd.web10.83245.1684136320444462556 for ; Mon, 15 May 2023 00:38:40 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=DF81Zf/Y; 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.237.64, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a48PGC7op1BaZmSpeQXjW4ZAJ2pfWplrFELHE8/CP40dTpqs5H/Xdfr9vZgtPhEE/rHr1PX9PdwzE8Jmy7VMAGDzTxOWK+bdKQ82EqXhJh8VlGbGC94Sr08P3KIZGTbROpeZyMdpw6JC2CjmJGyp5Lhlz+y6M9PV10PEB1F+SE6TXRi/i1ggGaK4sgY+vqUt+ozEyYlNon88LJRQd7D/wQHcqvFdoqoeHkG08rvccKREJXsbni/odi2whJrjq5EjEZ6oT3D4FKAUxaLpIxpCk5xD+9QQCyt0tFyg2+LchyXyoUr41XPov+UbP5Ar8UE7easIWOBDCF7WVYmlNEi4uw== 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=09VLdhoQWs3EVy5uLWcJLzDmng9xFphoBHzR+OB9TCA=; b=WY8QJVzavGZeWjJiss9NFk3t9d4zbSxadymHwmr/3VN0AFGrH5OT4WdX8LzHx/hMxsUNJnNa7wer4g2htoQQICq7VOKtOb+EFJXa48K7umEaVMsRJSNr8e6NVRWzjmUP5Ahge06vu+xRQF8BGzGs3V+Au3i+E24Ul+xM26R5KiVKtluOLWhQiFvUxum0lhfzvS+iRkXy+aTi9hiBznTKUds90a0hSRXTnBAVeeLvjEKEUJRXO8LqaFFwQbarPs1L4qqpjn+ai4xWeLEX9YndYvDTyITokdWfZp0xt7F/m+jUuNbqmoBLRf7ND+k38ZSZt57po6a2zkRZ0Zs+6aJC+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) 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=09VLdhoQWs3EVy5uLWcJLzDmng9xFphoBHzR+OB9TCA=; b=DF81Zf/YHvbyApQvlFwbQfCT1+SGGKVOlQXwb33nUgdq3C8UacvYuM6Mv5m+R8glEGAuBHFrsA4/MyBK48InJ8RO1C90xETXhzvPtclz+l4aM6mfv8hvtR62VpRsU37Q0E5PmyVNIvElCFWHcuYkfEwhUskBaC5FpRbUSh65wVZ+GOuUo8xwk2pch15rPpezNsQTGC7OGxjhAufWeYU3dM7qRzTrJBzeY8PoCPyvzcCs8+SJG1jZ6CKe/n5Hhp7H46/TiHohOg2Q6FFHHZyFoeXNz4MhdwcrUgg26A1EZ2SDhCNQuHdI4t5HPFWUNpyUmd5xPQcI8pCumJP/AfeD0A== Received: from DS7PR03CA0269.namprd03.prod.outlook.com (2603:10b6:5:3b3::34) by CY8PR12MB7171.namprd12.prod.outlook.com (2603:10b6:930:5c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30; Mon, 15 May 2023 07:38:37 +0000 Received: from DM6NAM11FT111.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b3:cafe::4f) by DS7PR03CA0269.outlook.office365.com (2603:10b6:5:3b3::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30 via Frontend Transport; Mon, 15 May 2023 07:38:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by DM6NAM11FT111.mail.protection.outlook.com (10.13.173.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.14 via Frontend Transport; Mon, 15 May 2023 07:38:37 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 15 May 2023 00:38:26 -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; Mon, 15 May 2023 00:38:26 -0700 Received: from NV-CL38DL3.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 15 May 2023 00:38:25 -0700 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy Subject: [edk2-redfish-client][PATCH v2 2/3] RedfishClientPkg: Add Redfish Resource Addendum Library Date: Mon, 15 May 2023 15:38:25 +0800 Message-ID: <20230515073825.13647-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: DM6NAM11FT111:EE_|CY8PR12MB7171:EE_ X-MS-Office365-Filtering-Correlation-Id: 8012e3f1-2d7b-492e-9d8f-08db5517651e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IriMpps/N5Bzy8szSJh8EmZIab5UWa+d4yMkeplDThcC6veWuEhOpQ0DpbTJcMqwzNWdCiELdG+hI2P32Ooc4ypNzDB6PVG1sh0hd9HiwagW5fR1qb88hCEacOJMCPPH00qFsW/NnnNJxAuubWokXq5+6k7yqaDi92FBGT7OMdnCaYpCk/8fYnJsiirOgcG5DMQ+ifMXXR7XS2hy/Kis1MTQC0TRPx6yP154x9gIc43ytJQZma7Lpf6QAYU89g201L7J1lw4dJPmvCOMnAMbhBPXrC4A2qtsTWBFzDCeD7MmaGzOg5vffWtXvGuZ5HZGBFUk8zvZzox0Xkj77a8nj6v48asZua2hXzhbTdimn5gwKPIDbBafj7boCD88/5JVRZu/uLEzEojn1NMlkWiu08K12ngWkEWx9o2XUTqOcIQDGowec/8dLYCTI4IOyn0HBlAvvOKCRix3WYgxSq8DLST5sKCeUeGGO8U4T4ClmBQF5OPzwMvZgJFG1Sdw0omDRPtozlU8odAe6R+GwJs/gmwBZdaPbOaxTB/4ItP/6R/HkWXhASiB/WkSVLO2TLctOYt60+o7l1diU+C4i90Bh0fGMAVY5K0nOhLT3divR1a/w9iupZbPD1uusTf8HAJCwUdnj2H6n5NhO63NWhA68dkj7EF0rD5ZGE4LeZtawHLGiCjfjgpFMT5lmbTLTItz1Zh4fgLTDNtlFFRN7DbshhJG2CTJ03RlYLFS7UnbDBFbxuvCku3Yknr5fL4pQI68 X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(346002)(39860400002)(376002)(451199021)(46966006)(40470700004)(36840700001)(336012)(47076005)(36860700001)(83380400001)(426003)(70206006)(70586007)(2616005)(1076003)(26005)(7696005)(40480700001)(478600001)(54906003)(186003)(40460700003)(5660300002)(30864003)(86362001)(8676002)(8936002)(2906002)(36756003)(41300700001)(4326008)(6916009)(82740400003)(316002)(7636003)(356005)(82310400005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2023 07:38:37.0921 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8012e3f1-2d7b-492e-9d8f-08db5517651e 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.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT111.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7171 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 | 67 +++++ .../RedfishAddendumLib/RedfishAddendumLib.c | 265 ++++++++++++++++++ 5 files changed, 377 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..ae61c825 --- /dev/null +++ b/RedfishClientPkg/Include/Library/RedfishAddendumLib.h @@ -0,0 +1,67 @@ +/** @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 + +/** + This function calls EDKII_REDFISH_RESOURCE_ADDENDUM_PROTOCOL to get + addendum data. It's call's responsibility to release JsonWithAddendum. + + @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 + ); + +/** + This function calls EDKII_REDFISH_RESOURCE_ADDENDUM_PROTOCOL to get + OEM data. It's call's responsibility to release JsonWithOem. + + @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..fd365d8d --- /dev/null +++ b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.c @@ -0,0 +1,265 @@ +/** @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 release 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, "%a: UnicodeStrToAsciiStrS failed: %r\n", __func_= _, Status)); + FreePool (AsciiStr); + return NULL; + } + + return AsciiStr; +} + +/** + This function calls Edk2 platform Redfish Resource Addendum driver to ge= t + addendum data. It's call's responsibility to release JsonWithAddendum. + + @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; +} + +/** + This function calls Edk2 platform Redfish Resource Addendum driver to ge= t + OEM data. It's call's responsibility to release JsonWithOem. + + @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