Re: [edk2-devel] [edk2-staging][PATCH v2 2/3] edk2-staging/RedfishClientPkg: Introduce Redfish version library
Reviewed-by: Abner Chang > -Original Message- > From: Wang, Nickle (Server BIOS) > Sent: Wednesday, May 25, 2022 11:14 AM > To: devel@edk2.groups.io > Cc: Wang, Nickle (Server BIOS) ; Chang, Abner (HPS > SW/FW Technologist) > Subject: [edk2-staging][PATCH v2 2/3] edk2-staging/RedfishClientPkg: > Introduce Redfish version library > > 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 | 211 ++ > .../RedfishVersionLib/RedfishVersionLib.inf | 44 > RedfishClientPkg/RedfishClientLibs.dsc.inc| 1 + > RedfishClientPkg/RedfishClientPkg.dec | 4 +- > 6 files changed, 305 insertions(+), 1 deletion(-) > create mode 100644 RedfishClientPkg/Include/Library/RedfishVersionLib.h > create mode 100644 RedfishClientPkg/Include/RedfishBase.h > create mode 100644 > RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c > create mode 100644 > RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf > > diff --git a/RedfishClientPkg/Include/Library/RedfishVersionLib.h > b/RedfishClientPkg/Include/Library/RedfishVersionLib.h > new file mode 100644 > index 00..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/Include/RedfishBase.h > new file mode 100644 > index 00..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) == NULL || (a)[0] == '\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 00..0fe2dd1bd0 > --- /dev/null > +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c > @@ -0,0 +1,211 @@ > +/** @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 == NULL || IS_EMPTY_STRING (Version)) { > > +return EFI_INVALID_PARAMETER; > > + } > > + > > + if (mCacheService == Service) { > > +return EFI_ALREADY_STARTED; > > + } > > + > > + mCacheService = Service; > > + if (mVersionCache != NULL) { > > +FreePool (mVersionCache); > > + } > > + > > + mVersionStringSize = StrSize (Version); > > + mVersionCache = AllocateCopyPool (mVersionStringSize, Version); > > + if (mVersionCache == NULL)
[edk2-devel] [edk2-staging][PATCH v2 2/3] edk2-staging/RedfishClientPkg: Introduce Redfish version library
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 | 211 ++ .../RedfishVersionLib/RedfishVersionLib.inf | 44 RedfishClientPkg/RedfishClientLibs.dsc.inc| 1 + RedfishClientPkg/RedfishClientPkg.dec | 4 +- 6 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 RedfishClientPkg/Include/Library/RedfishVersionLib.h create mode 100644 RedfishClientPkg/Include/RedfishBase.h create mode 100644 RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c create mode 100644 RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf diff --git a/RedfishClientPkg/Include/Library/RedfishVersionLib.h b/RedfishClientPkg/Include/Library/RedfishVersionLib.h new file mode 100644 index 00..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/Include/RedfishBase.h new file mode 100644 index 00..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) == NULL || (a)[0] == '\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 00..0fe2dd1bd0 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c @@ -0,0 +1,211 @@ +/** @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 == NULL || IS_EMPTY_STRING (Version)) { +return EFI_INVALID_PARAMETER; + } + + if (mCacheService == Service) { +return EFI_ALREADY_STARTED; + } + + mCacheService = Service; + if (mVersionCache != NULL) { +FreePool (mVersionCache); + } + + mVersionStringSize = StrSize (Version); + mVersionCache = AllocateCopyPool (mVersionStringSize, Version); + if (mVersionCache == NULL) { +mCacheService = 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_STATUSStatus; + EFI_STRINGVersionString; + REDFISH_RESPONSE Response; + EDKII_JSON_VALUE JsonValue; + EDKII_JSON_VALUE N; + CHAR8 *Key; + EDKII_JSON_VALUE Value; + + VersionString = NULL; + + if (Service == NULL) { +goto ON_ERROR; + } + + // + // Use cache to prevent HTTP connection. + // + if (Service ==