From nobody Sun May 5 14:48:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+89793+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+89793+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1652759950; cv=none; d=zohomail.com; s=zohoarc; b=WHdFiJBXmMk9QtbLNZYzT2kZH7P7v7iw6z13YkXBSwNdaxwWPiCJRKU/PenBir2jIXSOA2vr8aNny8KSxae6gfVv0x+h26AyGEbhcrySPw0r7P+tp3pLFRuPW7dX+h7GZeMhFI4KZ8kyhlIB7oNPFNFiKHzdia76vdOdLBE+siA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652759950; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=pGmGgAw62W4jhrxn+kOWBk4RBe8WoYLzvy7y2jy83pE=; b=bTFJNfn+zTl1eIhvrj8xQOm6gGzhCKRphTcC/223ZKbtlRlAuN7pvUUdOhPer1mzk8woqZ8IBMBWI0Aypm/UfQ1e4AQnJRAV2sCiTLWWNpBtZnGkCvJ9/HjGBN0QjFBofDslO3P3E4CdOtfEaM//xmVORFpiBYfyGwDjgyYYBGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+89793+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1652759950057874.4159454561207; Mon, 16 May 2022 20:59:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id teOCYY1788612x0MONvtsNjE; Mon, 16 May 2022 20:59:09 -0700 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web10.3120.1652759947520608109 for ; Mon, 16 May 2022 20:59:07 -0700 X-Received: from pps.filterd (m0148664.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24H21uKV019162 for ; Tue, 17 May 2022 03:59:06 GMT X-Received: from g4t3427.houston.hpe.com (g4t3427.houston.hpe.com [15.241.140.73]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3g3yv4b0hq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 17 May 2022 03:59:06 +0000 X-Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g4t3427.houston.hpe.com (Postfix) with ESMTP id 0DEF45C for ; Tue, 17 May 2022 03:59:06 +0000 (UTC) X-Received: from WAFM3XJD5N.asiapacific.hpqcorp.net (unknown [10.43.61.53]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 2C36F55; Tue, 17 May 2022 03:59:04 +0000 (UTC) From: "Nickle Wang" To: devel@edk2.groups.io Cc: Nickle Wang , Abner Chang Subject: [edk2-devel] [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Introduce Redfish version library Date: Tue, 17 May 2022 11:58:56 +0800 Message-Id: <20220517035856.1850-1-nickle.wang@hpe.com> MIME-Version: 1.0 X-Proofpoint-GUID: Hc6lwCfYQ2dPw7Zkdm5sZaYf-laiyBnP X-Proofpoint-ORIG-GUID: Hc6lwCfYQ2dPw7Zkdm5sZaYf-laiyBnP X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: 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,nickle.wang@hpe.com X-Gm-Message-State: ZoS6I3D7TlPnLkdtso2CxKxjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1652759949; bh=BmdsBFKM8kqNBHxX8zlSZO9DrpYtYSOI9SxJIH/5Vhw=; h=Cc:Date:From:Reply-To:Subject:To; b=gacvWB045fGNmjhPPNoOyxKojLJ41a2CPObA6hsjDmJUm15mL50yKNwHYtTySvqTmqV 6lmqrIMtkiIsyGrU5/bxzcuE0IffQdmIIDf408vpV0YXWbmgd3Jm1Gz9VCZcbSgyDJSMT HPFjos5bgQDckuKLSZCLr4fL0BvAm2PO5DY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1652759951529100003 Content-Type: text/plain; charset="utf-8" Add RedfishVersionLib to Redfish client package. This library provides interface for Redfish feature drivers to get Redfish version on BMC. Signed-off-by: Nickle Wang Cc: Abner Chang --- .../Include/Library/RedfishVersionLib.h | 30 +++ RedfishClientPkg/Include/RedfishBase.h | 16 ++ .../RedfishVersionLib/RedfishVersionLib.c | 203 ++++++++++++++++++ .../RedfishVersionLib/RedfishVersionLib.inf | 44 ++++ RedfishClientPkg/RedfishClientLibs.dsc.inc | 2 +- RedfishClientPkg/RedfishClientPkg.dec | 6 +- 6 files changed, 298 insertions(+), 3 deletions(-) create mode 100644 RedfishClientPkg/Include/Library/RedfishVersionLib.h create mode 100644 RedfishClientPkg/Include/RedfishBase.h create mode 100644 RedfishClientPkg/Library/RedfishVersionLib/RedfishVersi= onLib.c create mode 100644 RedfishClientPkg/Library/RedfishVersionLib/RedfishVersi= onLib.inf diff --git a/RedfishClientPkg/Include/Library/RedfishVersionLib.h b/Redfish= ClientPkg/Include/Library/RedfishVersionLib.h new file mode 100644 index 0000000000..5076c2ce9f --- /dev/null +++ b/RedfishClientPkg/Include/Library/RedfishVersionLib.h @@ -0,0 +1,30 @@ +/** @file + This file defines the Redfish version library interface. + + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REDFISH_VERSION_LIB_H_ +#define REDFISH_VERSION_LIB_H_ + +/** + Query HTTP request to BMC with given redfish service and return redfish + version information. If there is troulbe to get Redfish version on BMC, + The value of PcdDefaultRedfishVersion is returned. + + It's call responsibility to release returned buffer. + + @param[in] Service Redfish service instance + + @retval EFI_STRING Redfish version string. NULL while error occurs. + +**/ +EFI_STRING +RedfishGetVersion ( + IN REDFISH_SERVICE *Service + ); + +#endif diff --git a/RedfishClientPkg/Include/RedfishBase.h b/RedfishClientPkg/Incl= ude/RedfishBase.h new file mode 100644 index 0000000000..60d585c54a --- /dev/null +++ b/RedfishClientPkg/Include/RedfishBase.h @@ -0,0 +1,16 @@ +/** @file + Redfish base header file. + + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EFI_REDFISH_BASE_H_ +#define EFI_REDFISH_BASE_H_ + +#define IS_EMPTY_STRING(a) ((a) =3D=3D NULL || (a)[0] =3D=3D '\0') +#define REDFISH_DEBUG_TRACE DEBUG_VERBOSE + +#endif diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c= b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c new file mode 100644 index 0000000000..0a2ace7726 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c @@ -0,0 +1,203 @@ +/** @file + Redfish version 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 + +#define REDFISH_VERSION_DEFAULT_STRING L"v1" +#define REDFISH_ROOT_URI "/redfish" + +REDFISH_SERVICE *mCacheService; +EFI_STRING mVersionCache; +UINTN mVersionStringSize; + +/** + Cache the redfish service version for later use so we don't have to query + HTTP request everytime. + + @param[in] Service Redfish service instance + @param[in] Version Version string to cache + + @retval EFI_SUCCESS Version is saved in cache successfully. + @retval Others + +**/ +EFI_STATUS +CacheVersion ( + IN REDFISH_SERVICE *Service, + IN EFI_STRING Version + ) +{ + if (Service =3D=3D NULL || IS_EMPTY_STRING (Version)) { + return EFI_INVALID_PARAMETER; + } + + if (mCacheService =3D=3D Service) { + return EFI_ALREADY_STARTED; + } + + mCacheService =3D Service; + if (mVersionCache !=3D NULL) { + FreePool (mVersionCache); + } + + mVersionStringSize =3D StrSize (Version); + mVersionCache =3D AllocateCopyPool (mVersionStringSize, Version); + if (mVersionCache =3D=3D NULL) { + mCacheService =3D NULL; + return EFI_OUT_OF_RESOURCES; + } + + return EFI_SUCCESS; +} + +/** + Query HTTP request to BMC with given redfish service and return redfish + version information. If there is troulbe to get Redfish version on BMC, + The value of PcdDefaultRedfishVersion is returned. + + It's call responsibility to release returned buffer. + + @param[in] Service Redfish service instance + + @retval EFI_STRING Redfish version string. NULL while error occurs. + +**/ +EFI_STRING +RedfishGetVersion ( + IN REDFISH_SERVICE *Service + ) +{ + EFI_STATUS Status; + EFI_STRING VersionString; + REDFISH_RESPONSE Response; + EDKII_JSON_VALUE JsonValue; + EDKII_JSON_VALUE N; + CHAR8 *Key; + EDKII_JSON_VALUE Value; + + VersionString =3D NULL; + + if (Service =3D=3D NULL) { + goto ON_ERROR; + } + + // + // Use cache to prevent HTTP connection. + // + if (Service =3D=3D mCacheService) { + return AllocateCopyPool (mVersionStringSize, mVersionCache); + } + + // + // Get resource from redfish service. + // + Status =3D RedfishGetByUri ( + Service, + REDFISH_ROOT_URI, + &Response + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, RedfishGetByService to %a failed: %r\n", __F= UNCTION__, REDFISH_ROOT_URI, Status)); + if (Response.Payload !=3D NULL) { + RedfishDumpPayload (Response.Payload); + RedfishFreeResponse ( + NULL, + 0, + NULL, + Response.Payload + ); + Response.Payload =3D NULL; + } + + goto ON_ERROR; + } + + JsonValue =3D RedfishJsonInPayload (Response.Payload); + if (JsonValue =3D=3D NULL || !JsonValueIsObject (JsonValue)) { + goto ON_ERROR; + } + + EDKII_JSON_OBJECT_FOREACH_SAFE (JsonValue, N, Key, Value) { + if (Key[0] =3D=3D 'v' && JsonValueIsString (Value)) { + VersionString =3D JsonValueGetUnicodeString (Value); + break; + } + } + + if (VersionString !=3D NULL) { + CacheVersion (Service, VersionString); + return VersionString; + } + +ON_ERROR: + + VersionString =3D (CHAR16 *)PcdGetPtr (PcdDefaultRedfishVersion); + if (VersionString =3D=3D NULL) { + VersionString =3D REDFISH_VERSION_DEFAULT_STRING; + } + + return AllocateCopyPool (StrSize (VersionString), VersionString); +} + +/** + + Initial redfish version 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 +RedfishVersionLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + mCacheService =3D NULL; + mVersionCache =3D NULL; + mVersionStringSize =3D 0; + + return EFI_SUCCESS; +} + + +/** + Release allocated resource. + + @param[in] ImageHandle Handle that identifies the image to be unlo= aded. + @param[in] SystemTable The system table. + + @retval EFI_SUCCESS The image has been unloaded. + +**/ +EFI_STATUS +EFIAPI +RedfishVersionLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + if (mVersionCache !=3D NULL) { + FreePool (mVersionCache); + } + + return EFI_SUCCESS; +} diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.i= nf b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf new file mode 100644 index 0000000000..fcc88a4357 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf @@ -0,0 +1,44 @@ +## @file +# +# (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D RedfishVersionLib + FILE_GUID =3D 396A7508-B611-49F7-9C81-DAD96B526B61 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RedfishVersionLib| DXE_DRIVER + CONSTRUCTOR =3D RedfishVersionLibConstructor + DESTRUCTOR =3D RedfishVersionLibDestructor + +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + RedfishVersionLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + PcdLib + RedfishLib + JsonLib + +[Protocols] + +[Pcd] + gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion + diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/= RedfishClientLibs.dsc.inc index 5467acedd0..386d4d9cbb 100644 --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc @@ -27,4 +27,4 @@ RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/Red= fishPlatformConfigLib.inf RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/R= edfishContentCodingLibNull.inf ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/ConverterCo= mmonLib/ConverterCommonLib.inf - + RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVers= ionLib.inf diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/Redfi= shClientPkg.dec index 09df062dd3..b22f121e96 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 @@ =20 [LibraryClasses] RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h + RedfishVersionLib|Include/Library/RedfishVersionLib.h =20 [LibraryClasses.Common.Private] ## @libraryclass Redfish Helper Library @@ -47,4 +48,5 @@ # { 0x7CE88FB3, 0x4BD7, 0x4679, { 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, 0x= 0D, 0x2B }} # gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupEv= entGuid|{0xB3, 0x8F, 0xE8, 0x7C, 0xD7, 0x4B, 0x79, 0x46, 0x87, 0xA8, 0xA8, = 0xD8, 0xDE, 0xE5, 0x0D, 0x2B}|VOID*|0x10000003 - + ## Default Redfish version string + gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion|L"v1"|VOID*|= 0x10000004 --=20 2.32.0.windows.2 -=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 (#89793): https://edk2.groups.io/g/devel/message/89793 Mute This Topic: https://groups.io/mt/91156977/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-