From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web12.8385.1657628511122912230 for ; Tue, 12 Jul 2022 05:21:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=CwnCzJ5e; 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.143.35, mailfrom: prvs=0192e24d61=nickle.wang@hpe.com) Received: from pps.filterd (m0134425.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26CCI5kX021276; Tue, 12 Jul 2022 12:21:49 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=nNuPu+25iLOi7kbqJP9RoY8gHjq23U3bubV3URQxxjg=; b=CwnCzJ5eMFQwrwBZZLYab9KtEtJAAZf4lqMhxoYbURYDqCi1QytOomGZ03r3RLL/Scdk KzD+mfL6Zw67JEA9Rr03JuKzILHC2OvuG4ICPstxoQNoLUugPbLFUKrqyBRjl2cUXBLu Izz379MlyCjlQI3+2jrFllLQBalJ5wi00/wXutsvPNtCVW6oHA8vX17bda2JwDYInxw5 iXDLto6RdmhWJfSDuxxXghjpEnVoK2C1tJG8aQU7DxkXeEeC9+Wyaz6L6qzXNP+TDcWy da8VFlIzoNcQPr5yWD0TItyUlU/GWpGfQ9bwTowTbo+jKQ4A81TM1rgbOLHhs1mXn+K1 4g== Received: from p1lg14880.it.hpe.com (p1lg14880.it.hpe.com [16.230.97.201]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3h98u800xu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Jul 2022 12:21:49 +0000 Received: from p1lg14885.dc01.its.hpecorp.net (unknown [10.119.18.236]) (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 p1lg14880.it.hpe.com (Postfix) with ESMTPS id 7EB98800236; Tue, 12 Jul 2022 12:21:47 +0000 (UTC) Received: from WAFM3XJD5N.asiapacific.hpqcorp.net (unknown [16.231.227.36]) by p1lg14885.dc01.its.hpecorp.net (Postfix) with ESMTP id 7BC78805639; Tue, 12 Jul 2022 12:21:46 +0000 (UTC) From: "Nickle Wang" To: devel@edk2.groups.io Cc: Abner Chang , Yang Atom , Nick Ramirez Subject: [edk2-staging][PATCH 02/15] edk2-staging/RedfishClientPkg: Introduce Redfish version library Date: Tue, 12 Jul 2022 20:21:30 +0800 Message-Id: <20220712122143.1827-3-nickle.wang@hpe.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20220712122143.1827-1-nickle.wang@hpe.com> References: <20220712122143.1827-1-nickle.wang@hpe.com> MIME-Version: 1.0 X-Proofpoint-GUID: 5aGZe3zfigIdo0IoD5_pYBIjwpmj1wCv X-Proofpoint-ORIG-GUID: 5aGZe3zfigIdo0IoD5_pYBIjwpmj1wCv 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-12_08,2022-07-12_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 clxscore=1015 bulkscore=0 mlxlogscore=624 spamscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207120048 Content-Transfer-Encoding: quoted-printable Add RedfishVersionLib in order to get Redfish version hosted at BMC. When there is trouble to get Redfish support version, the default version is retrieved from pre-defined PCD value. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Yang Atom Cc: Nick Ramirez --- .../Include/Library/RedfishVersionLib.h | 30 +++ RedfishClientPkg/Include/RedfishBase.h | 21 ++ .../RedfishVersionLib/RedfishVersionLib.c | 203 ++++++++++++++++++ .../RedfishVersionLib/RedfishVersionLib.inf | 50 +++++ RedfishClientPkg/RedfishClientLibs.dsc.inc | 1 + RedfishClientPkg/RedfishClientPkg.dec | 4 +- 6 files changed, 308 insertions(+), 1 deletion(-) 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..319f22bd37 --- /dev/null +++ b/RedfishClientPkg/Include/Library/RedfishVersionLib.h @@ -0,0 +1,30 @@ +/** @file=0D + This file defines the Redfish version Library interface.=0D +=0D + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef REDFISH_VERSION_LIB_H_=0D +#define REDFISH_VERSION_LIB_H_=0D +=0D +/**=0D + Query HTTP request to BMC with given redfish service and return redfish= =0D + version information. If there is troulbe to get Redfish version on BMC,= =0D + The value of PcdDefaultRedfishVersion is returned.=0D +=0D + It's call responsibility to release returned buffer.=0D +=0D + @param[in] Service Redfish service instance=0D +=0D + @retval EFI_STRING Redfish version string. NULL while error occurs.=0D +=0D +**/=0D +EFI_STRING=0D +RedfishGetVersion (=0D + IN REDFISH_SERVICE *Service=0D + );=0D +=0D +#endif=0D diff --git a/RedfishClientPkg/Include/RedfishBase.h b/RedfishClientPkg/Incl= ude/RedfishBase.h new file mode 100644 index 0000000000..cf320bb0eb --- /dev/null +++ b/RedfishClientPkg/Include/RedfishBase.h @@ -0,0 +1,21 @@ +/** @file=0D + Redfish base header file.=0D +=0D + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef EFI_REDFISH_BASE_H_=0D +#define EFI_REDFISH_BASE_H_=0D +=0D +#define IS_EMPTY_STRING(a) ((a) =3D=3D NULL || (a)[0] =3D=3D '\0')=0D +#define REDFISH_DEBUG_TRACE DEBUG_INFO=0D +=0D +///=0D +/// This GUID is used for an EFI Variable that stores the Redfish data.=0D +///=0D +EFI_GUID mRedfishVariableGuid =3D {0x91c46a3d, 0xed1a, 0x477b, {0xa5, 0x33= , 0x87, 0x2d, 0xcd, 0xb0, 0xfc, 0xc1}};=0D +=0D +#endif=0D 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=0D + Redfish version library implementation=0D +=0D + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#define REDFISH_VERSION_DEFAULT_STRING L"v1"=0D +#define REDFISH_ROOT_URI "/redfish"=0D +=0D +REDFISH_SERVICE *mCacheService;=0D +EFI_STRING mVersionCache;=0D +UINTN mVersionStringSize;=0D +=0D +/**=0D + Cache the redfish service version for later use so we don't have to quer= y=0D + HTTP request everytime.=0D +=0D + @param[in] Service Redfish service instance=0D + @param[in] Version Version string to cache=0D +=0D + @retval EFI_SUCCESS Version is saved in cache successfully.=0D + @retval Others=0D +=0D +**/=0D +EFI_STATUS=0D +CacheVersion (=0D + IN REDFISH_SERVICE *Service,=0D + IN EFI_STRING Version=0D + )=0D +{=0D + if (Service =3D=3D NULL || IS_EMPTY_STRING (Version)) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (mCacheService =3D=3D Service) {=0D + return EFI_ALREADY_STARTED;=0D + }=0D +=0D + mCacheService =3D Service;=0D + if (mVersionCache !=3D NULL) {=0D + FreePool (mVersionCache);=0D + }=0D +=0D + mVersionStringSize =3D StrSize (Version);=0D + mVersionCache =3D AllocateCopyPool (mVersionStringSize, Version);=0D + if (mVersionCache =3D=3D NULL) {=0D + mCacheService =3D NULL;=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Query HTTP request to BMC with given redfish service and return redfish= =0D + version information. If there is troulbe to get Redfish version on BMC,= =0D + The value of PcdDefaultRedfishVersion is returned.=0D +=0D + It's call responsibility to release returned buffer.=0D +=0D + @param[in] Service Redfish service instance=0D +=0D + @retval EFI_STRING Redfish version string. NULL while error occurs.=0D +=0D +**/=0D +EFI_STRING=0D +RedfishGetVersion (=0D + IN REDFISH_SERVICE *Service=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_STRING VersionString;=0D + REDFISH_RESPONSE Response;=0D + EDKII_JSON_VALUE JsonValue;=0D + EDKII_JSON_VALUE N;=0D + CHAR8 *Key;=0D + EDKII_JSON_VALUE Value;=0D +=0D + VersionString =3D NULL;=0D +=0D + if (Service =3D=3D NULL) {=0D + goto ON_ERROR;=0D + }=0D +=0D + //=0D + // Use cache to prevent HTTP connection.=0D + //=0D + if (Service =3D=3D mCacheService) {=0D + return AllocateCopyPool (mVersionStringSize, mVersionCache);=0D + }=0D +=0D + //=0D + // Get resource from redfish service.=0D + //=0D + Status =3D RedfishGetByUri (=0D + Service,=0D + REDFISH_ROOT_URI,=0D + &Response=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a, RedfishGetByService to %a failed: %r\n", __F= UNCTION__, REDFISH_ROOT_URI, Status));=0D + if (Response.Payload !=3D NULL) {=0D + RedfishDumpPayload (Response.Payload);=0D + RedfishFreeResponse (=0D + NULL,=0D + 0,=0D + NULL,=0D + Response.Payload=0D + );=0D + Response.Payload =3D NULL;=0D + }=0D +=0D + goto ON_ERROR;=0D + }=0D +=0D + JsonValue =3D RedfishJsonInPayload (Response.Payload);=0D + if (JsonValue =3D=3D NULL || !JsonValueIsObject (JsonValue)) {=0D + goto ON_ERROR;=0D + }=0D +=0D + EDKII_JSON_OBJECT_FOREACH_SAFE (JsonValue, N, Key, Value) {=0D + if (Key[0] =3D=3D 'v' && JsonValueIsString (Value)) {=0D + VersionString =3D JsonValueGetUnicodeString (Value);=0D + break;=0D + }=0D + }=0D +=0D + if (VersionString !=3D NULL) {=0D + CacheVersion (Service, VersionString);=0D + return VersionString;=0D + }=0D +=0D +ON_ERROR:=0D +=0D + VersionString =3D (CHAR16 *)PcdGetPtr (PcdDefaultRedfishVersion);=0D + if (VersionString =3D=3D NULL) {=0D + VersionString =3D REDFISH_VERSION_DEFAULT_STRING;=0D + }=0D +=0D + return AllocateCopyPool (StrSize (VersionString), VersionString);=0D +}=0D +=0D +/**=0D +=0D + Initial redfish version library instace.=0D +=0D + @param[in] ImageHandle The image handle.=0D + @param[in] SystemTable The system table.=0D +=0D + @retval EFI_SUCEESS Install Boot manager menu success.=0D + @retval Other Return error status.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +RedfishVersionLibConstructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + mCacheService =3D NULL;=0D + mVersionCache =3D NULL;=0D + mVersionStringSize =3D 0;=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + Release allocated resource.=0D +=0D + @param[in] ImageHandle Handle that identifies the image to be unlo= aded.=0D + @param[in] SystemTable The system table.=0D +=0D + @retval EFI_SUCCESS The image has been unloaded.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +RedfishVersionLibDestructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + if (mVersionCache !=3D NULL) {=0D + FreePool (mVersionCache);=0D + }=0D +=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.i= nf b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf new file mode 100644 index 0000000000..34d13d64f1 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf @@ -0,0 +1,50 @@ +## @file=0D +#=0D +# (C) Copyright 2022 Hewlett Packard Enterprise Development LP
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010006=0D + BASE_NAME =3D RedfishVersionLib=0D + FILE_GUID =3D 396A7508-B611-49F7-9C81-DAD96B526B61= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D RedfishVersionLib| DXE_DRIVER=0D + CONSTRUCTOR =3D RedfishVersionLibConstructor=0D + DESTRUCTOR =3D RedfishVersionLibDestructor=0D +=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 EBC=0D +#=0D +=0D +[Sources]=0D + RedfishVersionLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + RedfishPkg/RedfishPkg.dec=0D + RedfishClientPkg/RedfishClientPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + DebugLib=0D + MemoryAllocationLib=0D + PcdLib=0D + RedfishLib=0D + JsonLib=0D +=0D +[Protocols]=0D +=0D +[Pcd]=0D + gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion=0D +=0D +[BuildOptions]=0D + #=0D + # NOTE: /wd4706 disables the following Visual Studio compiler warning in= Jansson:=0D + # "C4706: assignment within conditional expression"=0D + #=0D + MSFT:*_*_*_CC_FLAGS =3D /wd4706=0D diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/= RedfishClientLibs.dsc.inc index ce1c27d884..1cf0406912 100644 --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc @@ -29,3 +29,4 @@ ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/ConverterCo= mmonLib/ConverterCommonLib.inf=0D =0D RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib= .inf=0D + RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVers= ionLib.inf=0D diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/Redfi= shClientPkg.dec index 39b2f5baf8..2ce51d14af 100644 --- a/RedfishClientPkg/RedfishClientPkg.dec +++ b/RedfishClientPkg/RedfishClientPkg.dec @@ -22,6 +22,7 @@ [LibraryClasses]=0D RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h=0D RedfishEventLib|Include/Library/RedfishEventLib.h=0D + RedfishVersionLib|Include/Library/RedfishVersionLib.h=0D =0D [LibraryClasses.Common.Private]=0D ## @libraryclass Redfish Helper Library=0D @@ -52,4 +53,5 @@ # { 0x7CE88FB3, 0x4BD7, 0x4679, { 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, 0x= 0D, 0x2B }}=0D #=0D gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupEv= entGuid|{0xB3, 0x8F, 0xE8, 0x7C, 0xD7, 0x4B, 0x79, 0x46, 0x87, 0xA8, 0xA8, = 0xD8, 0xDE, 0xE5, 0x0D, 0x2B}|VOID*|0x10000003=0D -=0D + ## Default Redfish version string=0D + gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion|L"v1"|VOID*|= 0x10000004=0D --=20 2.32.0.windows.2