Date
1 - 2 of 2
[edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Introduce Redfish version library
Nickle Wang
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 <nickle.wang@...> Cc: Abner Chang <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<BR>=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<BR>=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<BR>=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include <Uefi.h>=0D +#include <RedfishBase.h>=0D +#include <Library/BaseLib.h>=0D +#include <Library/DebugLib.h>=0D +#include <Library/PcdLib.h>=0D +#include <Library/RedfishLib.h>=0D +#include <Library/JsonLib.h>=0D +#include <Library/MemoryAllocationLib.h>=0D +#include <Library/RedfishVersionLib.h>=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<BR>=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<BR>=0D +# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>=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 |
|
toggle quoted message
Show quoted text
-----Original Message-----It's caller's responsibility to release the returned buffer. We can just check the JSON type for the property is a string type per to the Redfish spec. Please also have comment to elaborate on the rational of this code block. Thanks Abner Please having these libraries in the order of alphabet.
|
|