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.web10.3120.1652759947520608109 for ; Mon, 16 May 2022 20:59:07 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=WbybXs3Q; 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=0136f5c930=nickle.wang@hpe.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pps0720; bh=pjjM4wiJQzk6y1JQaJGMsPg40Nl1qFEbue3bOU+/idI=; b=WbybXs3QxTzwiS+tSqBeRUp+mmN4lxOVtKUVRH5qQ+4zpwhlkMIpcu9Ib/TLNF+IHnVc eefK4/jKTOMwF5+FAmdjGGsFEMpCM/wE9EGLlOUnTix1c6JY6jmiTNgiBEh+lTDnKwrN qY+aHixOzbpFZ20uNswYEP/rMbzi37jTZ3/KtRNycNWwQx7H3VbSfHEfvJq+CJIFAzgd wFsZYTojpsrQyriMS1xeMVJcRfXQwP5YlkqVrY6hrJ2lynbxiIbyFTc64TWOaD38UpM5 si8m7nmYLjkdGLBgaG9aplb8wJXFH5GNJR8B6rsDgIxlNmhDnK4vjzDhTZx1kSb/XgNk Sw== 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 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) 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-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> X-Mailer: git-send-email 2.32.0.windows.2 MIME-Version: 1.0 X-Proofpoint-GUID: Hc6lwCfYQ2dPw7Zkdm5sZaYf-laiyBnP X-Proofpoint-ORIG-GUID: Hc6lwCfYQ2dPw7Zkdm5sZaYf-laiyBnP X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-17_01,2022-05-16_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=920 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205170023 Content-Transfer-Encoding: quoted-printable 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=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..60d585c54a --- /dev/null +++ b/RedfishClientPkg/Include/RedfishBase.h @@ -0,0 +1,16 @@ +/** @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_VERBOSE=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..fcc88a4357 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf @@ -0,0 +1,44 @@ +## @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 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=0D RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/R= edfishContentCodingLibNull.inf=0D ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/ConverterCo= mmonLib/ConverterCommonLib.inf=0D -=0D + RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVers= ionLib.inf=0D 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=0D # Redfish Client Package=0D #=0D -# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
=0D +# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
=0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D ##=0D @@ -21,6 +21,7 @@ =0D [LibraryClasses]=0D RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h=0D + RedfishVersionLib|Include/Library/RedfishVersionLib.h=0D =0D [LibraryClasses.Common.Private]=0D ## @libraryclass Redfish Helper Library=0D @@ -47,4 +48,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