From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 9CF31AC0F99 for ; Tue, 24 Oct 2023 08:39:16 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=FdTVeEgzQtaa5qs4MzOKzQA1i9YV+h/qJP2X/d5WDHE=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1698136755; v=1; b=sCdOb3PC6m2R+c9rDtmeWicu6xmEygEOUgZ07OR6jIoY/SJJbAoi7XrqmAdaCl4+yIHd5wWM PUakxmiiq1FwHoKPUBobaXXxnCH4+p08cCVdYGIF8PRBeAgGMUpztYE/PxM7unALliMaMZA0EJE HN8hrEvbDViMCIINTWd+hQdg= X-Received: by 127.0.0.2 with SMTP id sKZmYY7687511xcZqg3Dv6HD; Tue, 24 Oct 2023 01:39:15 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.88]) by mx.groups.io with SMTP id smtpd.web10.143290.1698136754640466664 for ; Tue, 24 Oct 2023 01:39:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gHw5iq20NTsFALLOOUb+BhTb3QJPlkbDbPjuaZurGDNfG+bbskfXc06JQIhQEkTw5LUQVFluiQ3zVEgtIB3b36Qzopl0CFpz8uLxQ4eO2wuyH0X+O9Kc+usBlbvPY+3HKPpyrE9rC+2Gxh3jVQ+6UKfEjjpC5R+Gbmu6+2GkWuE0HGaDL7b4Y7IeH8hBDsk7KDW+88XODJI+9TrcSHlcBA20DSOKntH8OHC6EjYstyjnhvU8cr39cUw0uUQmfJiKYJN0UKTUv30LGsEP//qVfU74uedUyis+5pRArDJU34bUQvDmfmJbMX+qYUiBu1118AbaG8Tm3taIvR+F65/h6w== 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=ZCzfw2zoG0SSlPsrJX/AucuqDydLZimUP/Zbl3+AjlE=; b=SsqQxDQmCK6vwnLg+HSJfyys4xfL7QJ04zTkzCSX1KRSOEKHwaZH+Vnpat1oRvxC3gMncCOigKS+sAr0G5m0vxxWZmvn5RNNhuqCb92Tk7rCGgbWOmQUuCsmYaY2dA8Dg5k6h5c1Opz0jKTm/iYbnfpRwnoh8kmAseoe5JVobboE3zVJpQFbx//eAV26TnBK9GrjXeW2QgbNUzao9GKJG8Ybx9RfFlyeRTI1jHSAxP/MGgpYs3lk2xBKd2+ex9CpGb1ROCibcMpi35Q2A31MrlisbZeZX2gjN/I8cpEOVl02sZyd8GMoo/9kSUmVX2YEzf2RemvuNo2Eor9YYQyC9Q== 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 X-Received: from CH0PR03CA0075.namprd03.prod.outlook.com (2603:10b6:610:cc::20) by IA0PR12MB7554.namprd12.prod.outlook.com (2603:10b6:208:43e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Tue, 24 Oct 2023 08:39:10 +0000 X-Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:610:cc:cafe::1a) by CH0PR03CA0075.outlook.office365.com (2603:10b6:610:cc::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Tue, 24 Oct 2023 08:39:10 +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 X-Received: from mail.nvidia.com (216.228.118.232) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.15 via Frontend Transport; Tue, 24 Oct 2023 08:39:10 +0000 X-Received: from drhqmail202.nvidia.com (10.126.190.181) 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.41; Tue, 24 Oct 2023 01:38:59 -0700 X-Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 24 Oct 2023 01:38:59 -0700 X-Received: from NV-CL38DL3.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Tue, 24 Oct 2023 01:38:58 -0700 From: "Nickle Wang via groups.io" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-devel] [PATCH 1/3] RedfishPkg/RedfishLib: introduce new interfaces. Date: Tue, 24 Oct 2023 16:38:57 +0800 Message-ID: <20231024083857.16006-1-nicklew@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|IA0PR12MB7554:EE_ X-MS-Office365-Filtering-Correlation-Id: fa53bacd-ad5f-44b6-5902-08dbd46cb1ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 1avEfp/+2af+Xce+oUQO8fPkI71RQUXAcZ/Oirv+7GunRawaOMvAzK3cdtpOHCUMeroRqsK1u01HC5LMihL2odf1gFbfCVWsxJ1M6XPq3ercCuQ0WOjQrVdnIL3U7PDouxv9FgLlcQ4t3cN9za3Un0oaZDBJzn06gWZe+/yF6V4Ywknlce386gRtbgRwvIC54JVuD3JWiD5+lzE4/Le29NnMEE0925eMJh+l7v73u79pojJLAoMLVD65j3qBQuKNsxuxGxIwTZpzrwJdp1W1WQB92oiJ8xOxTKOkLmEQyApVUHKDm2RoRTCMKy7qzVlEXjYFCN4enS5k3M95AV1dHP11Xpo3DjOCXYMypQKQ1fkGecARR/LYw/cZhDhvZLeLpjfyMZa6U9bPdC53RlknajY0VEGJSsG7X+pMHCfff4DixqrjEx5FXzSCjqt8EUYYGfNf3mQ1yU1XdCnVGNPqaiVursafDF88YK/pCYu+5P6vdUccmLuIvP95B3AqEkKLB/WmAKl3t7mb2Rrq7AZ/dYvz8hNrWJXah95FgX5zN5PDmJrb5eViyWf7ygfAVjHTyvEBhUnWKc2QBqkEpD2RuKPOBkgt3TYAVduZPGUzkYyvZGHsfLhZaBj/N/Q3UUuObutnxXdvUtCBDckzWQfON+S1LmesEm2FQxWV7SudKhiUSzlTm1kJ9hJcAG4UFh/jOG7GO409+XstKNuXG1L3SE+X3W+cXP8cidyxehbi85k= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2023 08:39:10.4472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fa53bacd-ad5f-44b6-5902-08dbd46cb1ab 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: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7554 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nicklew@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Vo89BbKBKAMxdnOijlBJw7AJx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=sCdOb3PC; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Add two new interface: RedfishServiceInPayload() and RedfishPutToUri() for Redfish HTTP protocol implementation. Fix several typos and add missing JsonLib in INF file. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- .../PrivateLibrary/RedfishLib/RedfishLib.inf | 2 + RedfishPkg/Include/Library/RedfishLib.h | 95 +++++++++-- .../PrivateLibrary/RedfishLib/RedfishLib.c | 153 ++++++++++++++++-- .../PrivateLibrary/RedfishLib/RedfishMisc.c | 13 +- 4 files changed, 226 insertions(+), 37 deletions(-) diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf b/RedfishP= kg/PrivateLibrary/RedfishLib/RedfishLib.inf index 128d511df7c9..124ecb1e3aae 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf @@ -3,6 +3,7 @@ # # Copyright (c) 2019, Intel Corporation. All rights reserved.
# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -42,6 +43,7 @@ BaseLib BaseMemoryLib DebugLib + JsonLib HttpLib MemoryAllocationLib NetLib diff --git a/RedfishPkg/Include/Library/RedfishLib.h b/RedfishPkg/Include/L= ibrary/RedfishLib.h index 28c2b290e613..8309a67c769f 100644 --- a/RedfishPkg/Include/Library/RedfishLib.h +++ b/RedfishPkg/Include/Library/RedfishLib.h @@ -61,6 +61,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -183,6 +184,23 @@ RedfishJsonInPayload ( IN REDFISH_PAYLOAD Payload ); =20 +/** + This function returns the Redfish service of a REDFISH_PAYLOAD. + + Caller doesn't need to free the returned JSON value because it will be r= eleased + in corresponding RedfishCleanupService() function. + + @param[in] Payload A REDFISH_PAYLOAD instance. + + @return Redfish service of the payload. + +**/ +REDFISH_SERVICE +EFIAPI +RedfishServiceInPayload ( + IN REDFISH_PAYLOAD Payload + ); + /** Fill the input RedPath string with system UUID from SMBIOS table or use = the customized ID if FromSmbios =3D=3D FALSE. @@ -222,7 +240,7 @@ RedfishBuildPathWithSystemUuid ( from the root node. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The correspon= ding redfish resource has been returned in Payload within RedRespo= nse. @retval EFI_INVALID_PARAMETER RedfishService, RedPath, or RedResponse = is NULL. @@ -252,7 +270,7 @@ RedfishGetByService ( @param[in] URI String to address a resource. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The correspon= ding redfish resource has been returned in Payload within RedRespo= nse. @retval EFI_INVALID_PARAMETER RedfishService, RedPath, or RedResponse = is NULL. @@ -282,7 +300,7 @@ RedfishGetByUri ( @param[in] RedPath Relative RedPath string to address a res= ource inside Payload. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful: + @retval EFI_SUCCESS The operation is successful: 1. The HTTP StatusCode is NULL and the r= eturned Payload in RedResponse is not NULL, indicates the R= edfish resource has been parsed from the input payload direc= tly. @@ -323,7 +341,7 @@ RedfishGetByPayload ( @param[in] Content JSON represented properties to be up= date. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -357,10 +375,10 @@ RedfishPatchToUri ( redfish response data. =20 @param[in] Target The target payload to be updated. - @param[in] Payload Palyoad with properties to be changed. + @param[in] Payload Payload with properties to be changed. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -398,7 +416,7 @@ RedfishPatchToPayload ( @param[in] ContentType Type of the Content to be send to Re= dfish service @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -416,8 +434,8 @@ RedfishPostToUri ( IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, IN CONST CHAR8 *Content, - IN UINTN ContentSize, - IN CONST CHAR8 *ContentType, + IN UINTN ContentSize OPTIONAL, + IN CONST CHAR8 *ContentType OPTIONAL, OUT REDFISH_RESPONSE *RedResponse ); =20 @@ -436,7 +454,7 @@ RedfishPostToUri ( @param[in] Payload The new resource to be created. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -471,7 +489,7 @@ RedfishPostToPayload ( @param[in] Uri Relative path to address the resourc= e. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX, the Redfish r= esource has been removed. If there is any message returned from se= rver, it will be returned in Payload within RedResponse. @@ -507,7 +525,7 @@ RedfishDeleteByUri ( @param[in] Content JSON represented properties to be de= leted. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX, the Redfish r= esource has been removed. If there is any message returned from se= rver, it will be returned in Payload within RedResponse. @@ -528,6 +546,49 @@ RedfishDeleteByUriEx ( OUT REDFISH_RESPONSE *RedResponse ); =20 +/** + Use HTTP PUT to create new Redfish resource in the Resource Collection. + + This function uses the RedfishService to put a Redfish resource addresse= d by + Uri (only the relative path is required). Changes to one or more propert= ies within + the target resource are represented in the input Content, properties not= specified + in Content won't be changed by this request. The corresponding redfish r= esponse will + returned, including HTTP StatusCode, Headers and Payload which record an= y HTTP response + messages. + + Callers are responsible for freeing the HTTP StatusCode, Headers and Pay= load returned in + redfish response data. + + @param[in] RedfishService The Service to access the Redfish re= sources. + @param[in] Uri Relative path to address the resourc= e. + @param[in] Content JSON represented properties to be up= date. + @param[in] ContentSize Size of the Content to be send to Re= dfish service + @param[in] ContentType Type of the Content to be send to Re= dfish service + @param[out] RedResponse Pointer to the Redfish response data= . + + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not + NULL and the value is 2XX. The Redfish r= esource will be returned + in Payload within RedResponse if server = send it back in the HTTP + response message body. + @retval EFI_INVALID_PARAMETER RedfishService, Uri, Content, or RedResp= onse is NULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error oc= curred. Callers can get + more error info from returned HTTP Statu= sCode, Headers and Payload + within RedResponse: + 1. If the returned StatusCode is NULL, i= ndicates any error happen. + 2. If the returned StatusCode is not NUL= L and the value is not 2XX, + indicates any error happen. +**/ +EFI_STATUS +EFIAPI +RedfishPutToUri ( + IN REDFISH_SERVICE RedfishService, + IN CONST CHAR8 *Uri, + IN CONST CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CONST CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *RedResponse + ); + /** Dump text in fractions. =20 @@ -582,7 +643,7 @@ RedfishFreeResponse ( Check if the "@odata.type" in Payload is valid or not. =20 @param[in] Payload The Redfish payload to be checked. - @param[in] OdataTypeName OdataType will be retrived from map= ping list. + @param[in] OdataTypeName OdataType will be retrieved from ma= pping list. @param[in] OdataTypeMappingList The list of OdataType. @param[in] OdataTypeMappingListSize The number of mapping list =20 @@ -616,7 +677,7 @@ RedfishIsPayloadCollection ( @param[in] Payload The Redfish collection payload @param[in] CollectionSize Size of this collection =20 - @return EFI_SUCCESS Coolection size is returned in Collecti= onSize + @return EFI_SUCCESS Collection size is returned in Collecti= onSize @return EFI_INVALID_PARAMETER The payload is not a collection. **/ EFI_STATUS @@ -674,18 +735,18 @@ RedfishGetServiceVersion ( /** This function returns the string of Redfish service version. =20 - @param[in] ServiceVerisonStr The string of Redfish service version. + @param[in] ServiceVersionStr The string of Redfish service version. @param[in] Url The URL to build Redpath with ID. Start with "/", for example "/Registries" @param[in] Id ID string - @param[out] Redpath Pointer to retrive Redpath, caller has to= free + @param[out] Redpath Pointer to retrieved Redpath, caller has = to free the memory allocated for this string. @return EFI_STATUS =20 **/ EFI_STATUS RedfishBuildRedpathUseId ( - IN CHAR8 *ServiceVerisonStr, + IN CHAR8 *ServiceVersionStr, IN CHAR8 *Url, IN CHAR8 *Id, OUT CHAR8 **Redpath diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c b/RedfishPkg= /PrivateLibrary/RedfishLib/RedfishLib.c index cca0ea774893..f4045044829a 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c @@ -4,6 +4,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -167,6 +168,30 @@ RedfishJsonInPayload ( return ((redfishPayload *)Payload)->json; } =20 +/** + This function returns the Redfish service of a REDFISH_PAYLOAD. + + Caller doesn't need to free the returned JSON value because it will be r= eleased + in corresponding RedfishCleanupService() function. + + @param[in] Payload A REDFISH_PAYLOAD instance. + + @return Redfish service of the payload. + +**/ +REDFISH_SERVICE +EFIAPI +RedfishServiceInPayload ( + IN REDFISH_PAYLOAD Payload + ) +{ + if (Payload =3D=3D NULL) { + return NULL; + } + + return ((redfishPayload *)Payload)->service; +} + /** Fill the input RedPath string with system UUID from SMBIOS table or use = the customized ID if FromSmbios =3D=3D FALSE. @@ -244,7 +269,7 @@ RedfishBuildPathWithSystemUuid ( from the root node. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The correspon= ding redfish resource has been returned in Payload within RedRespo= nse. @retval EFI_INVALID_PARAMETER RedfishService, RedPath, or RedResponse = is NULL. @@ -304,7 +329,7 @@ RedfishGetByService ( @param[in] Uri String to address a resource. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The correspon= ding redfish resource has been returned in Payload within RedRespo= nse. @retval EFI_INVALID_PARAMETER RedfishService, RedPath, or RedResponse = is NULL. @@ -367,7 +392,7 @@ RedfishGetByUri ( @param[in] RedPath Relative RedPath string to address a res= ource inside Payload. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful: + @retval EFI_SUCCESS The operation is successful: 1. The HTTP StatusCode is NULL and the r= eturned Payload in RedResponse is not NULL, indicates the R= edfish resource has been parsed from the input payload direc= tly. @@ -440,7 +465,7 @@ RedfishGetByPayload ( @param[in] Content JSON represented properties to be up= date. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -527,10 +552,10 @@ ON_EXIT: redfish response data. =20 @param[in] Target The target payload to be updated. - @param[in] Payload Palyoad with properties to be changed. + @param[in] Payload Payload with properties to be changed. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -601,7 +626,7 @@ RedfishPatchToPayload ( @param[in] ContentType Type of the Content to be send to Re= dfish service @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -619,8 +644,8 @@ RedfishPostToUri ( IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, IN CONST CHAR8 *Content, - IN UINTN ContentSize, - IN CONST CHAR8 *ContentType, + IN UINTN ContentSize OPTIONAL, + IN CONST CHAR8 *ContentType OPTIONAL, OUT REDFISH_RESPONSE *RedResponse ) { @@ -694,7 +719,7 @@ ON_EXIT: @param[in] Payload The new resource to be created. @param[out] RedResponse Pointer to the Redfish response data. =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX. The Redfish r= esource will be returned in Payload within RedResponse if server = send it back in the HTTP response message body. @@ -762,7 +787,7 @@ RedfishPostToPayload ( @param[in] Uri Relative path to address the resourc= e. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX, the Redfish r= esource has been removed. If there is any message returned from se= rver, it will be returned in Payload within RedResponse. @@ -850,7 +875,7 @@ ON_EXIT: @param[in] Content JSON represented properties to be de= leted. @param[out] RedResponse Pointer to the Redfish response data= . =20 - @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not NULL and the value is 2XX, the Redfish r= esource has been removed. If there is any message returned from se= rver, it will be returned in Payload within RedResponse. @@ -1060,7 +1085,7 @@ RedfishFreeResponse ( Check if the "@odata.type" in Payload is valid or not. =20 @param[in] Payload The Redfish payload to be checked. - @param[in] OdataTypeName OdataType will be retrived from map= ping list. + @param[in] OdataTypeName OdataType will be retrieved from ma= pping list. @param[in] OdataTypeMappingList The list of OdataType. @param[in] OdataTypeMappingListSize The number of mapping list =20 @@ -1127,7 +1152,7 @@ RedfishIsPayloadCollection ( @param[in] Payload The Redfish collection payload @param[in] CollectionSize Size of this collection =20 - @return EFI_SUCCESS Coolection size is returned in Collecti= onSize + @return EFI_SUCCESS Collection size is returned in Collecti= onSize @return EFI_INVALID_PARAMETER The payload is not a collection. **/ EFI_STATUS @@ -1217,3 +1242,103 @@ RedfishCheckIfRedpathExist ( =20 return EFI_SUCCESS; } + +/** + Use HTTP PUT to create new Redfish resource in the Resource Collection. + + This function uses the RedfishService to put a Redfish resource addresse= d by + Uri (only the relative path is required). Changes to one or more propert= ies within + the target resource are represented in the input Content, properties not= specified + in Content won't be changed by this request. The corresponding redfish r= esponse will + returned, including HTTP StatusCode, Headers and Payload which record an= y HTTP response + messages. + + Callers are responsible for freeing the HTTP StatusCode, Headers and Pay= load returned in + redfish response data. + + @param[in] RedfishService The Service to access the Redfish re= sources. + @param[in] Uri Relative path to address the resourc= e. + @param[in] Content JSON represented properties to be up= date. + @param[in] ContentSize Size of the Content to be send to Re= dfish service + @param[in] ContentType Type of the Content to be send to Re= dfish service + @param[out] RedResponse Pointer to the Redfish response data= . + + @retval EFI_SUCCESS The operation is successful, indicates t= he HTTP StatusCode is not + NULL and the value is 2XX. The Redfish r= esource will be returned + in Payload within RedResponse if server = send it back in the HTTP + response message body. + @retval EFI_INVALID_PARAMETER RedfishService, Uri, Content, or RedResp= onse is NULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error oc= curred. Callers can get + more error info from returned HTTP Statu= sCode, Headers and Payload + within RedResponse: + 1. If the returned StatusCode is NULL, i= ndicates any error happen. + 2. If the returned StatusCode is not NUL= L and the value is not 2XX, + indicates any error happen. +**/ +EFI_STATUS +EFIAPI +RedfishPutToUri ( + IN REDFISH_SERVICE RedfishService, + IN CONST CHAR8 *Uri, + IN CONST CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CONST CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *RedResponse + ) +{ + EFI_STATUS Status; + EDKII_JSON_VALUE JsonValue; + + Status =3D EFI_SUCCESS; + JsonValue =3D NULL; + + if ((RedfishService =3D=3D NULL) || (Uri =3D=3D NULL) || (Content =3D=3D= NULL) || (RedResponse =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE)); + + JsonValue =3D (EDKII_JSON_VALUE)putUriFromServiceEx ( + RedfishService, + Uri, + Content, + ContentSize, + ContentType, + &(RedResponse->Headers), + &(RedResponse->HeaderCount), + &(RedResponse->StatusCode) + ); + + // + // 1. If the returned StatusCode is NULL, indicates any error happen. + // + if (RedResponse->StatusCode =3D=3D NULL) { + Status =3D EFI_DEVICE_ERROR; + goto ON_EXIT; + } + + // + // 2. If the returned StatusCode is not NULL and the value is not 2XX, i= ndicates any error happen. + // NOTE: If there is any error message returned from server, it will = be returned in + // Payload within RedResponse. + // + if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \ + (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)) + { + Status =3D EFI_DEVICE_ERROR; + } + +ON_EXIT: + if (JsonValue !=3D NULL) { + RedResponse->Payload =3D createRedfishPayload (JsonValue, RedfishServi= ce); + if (RedResponse->Payload =3D=3D NULL) { + // + // Ignore the error when create RedfishPayload, just free the JsonVa= lue since it's not what + // we care about if the returned StatusCode is 2XX. + // + JsonValueFree (JsonValue); + } + } + + return Status; +} diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c b/RedfishPk= g/PrivateLibrary/RedfishLib/RedfishMisc.c index 0eb23196d2c2..b6e9a111785a 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -168,18 +169,18 @@ RedfishGetAuthInfo ( /** This function returns the string of Redfish service version. =20 - @param[in] ServiceVerisonStr The string of Redfish service version. + @param[in] ServiceVersionStr The string of Redfish service version. @param[in] Url The URL to build Redpath with ID. Start with "/", for example "/Registries" @param[in] Id ID string - @param[out] Redpath Pointer to retrive Redpath, caller has to= free + @param[out] Redpath Pointer to retrieved Redpath, caller has = to free the memory allocated for this string. @return EFI_STATUS =20 **/ EFI_STATUS RedfishBuildRedpathUseId ( - IN CHAR8 *ServiceVerisonStr, + IN CHAR8 *ServiceVersionStr, IN CHAR8 *Url, IN CHAR8 *Id, OUT CHAR8 **Redpath @@ -187,12 +188,12 @@ RedfishBuildRedpathUseId ( { UINTN RedpathSize; =20 - if ((Redpath =3D=3D NULL) || (ServiceVerisonStr =3D=3D NULL) || (Url =3D= =3D NULL) || (Id =3D=3D NULL)) { + if ((Redpath =3D=3D NULL) || (ServiceVersionStr =3D=3D NULL) || (Url =3D= =3D NULL) || (Id =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } =20 RedpathSize =3D AsciiStrLen ("/") + - AsciiStrLen (ServiceVerisonStr) + + AsciiStrLen (ServiceVersionStr) + AsciiStrLen (Url) + AsciiStrLen ("[Id=3D]") + AsciiStrLen (Id) + 1; @@ -201,6 +202,6 @@ RedfishBuildRedpathUseId ( return EFI_OUT_OF_RESOURCES; } =20 - AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=3D%a]", ServiceVerisonStr,= Url, Id); + AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=3D%a]", ServiceVersionStr,= Url, Id); return EFI_SUCCESS; } --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109991): https://edk2.groups.io/g/devel/message/109991 Mute This Topic: https://groups.io/mt/102154011/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-