From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.61]) by mx.groups.io with SMTP id smtpd.web10.6435.1683682160328053007 for ; Tue, 09 May 2023 18:29:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=5lvcrOKy; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.93.61, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XJ/dDbCu7MdYSCu1mdwfSm3TdTQ9S9tiJk1rWd9KyYt1BWaRFivbz9gdqWDtXnuKiNrIv8ww5fqAIgujbZsaochIKOBVqTualbKmS/0M2CuiLI3TAWQvbwNbRJ4wyYEoYpDZe+MCsvWzzU23ujzw2gIEo7lZ3v2rR75gL0ECZ16La5UAXw4dcDxHKjDDG6BgLBvEDSY1g/wTDD/saxgrY0efVSQYwgLK1hIh5VdmY6wooaZnDnJwxbNGMC9Der7uUKCUbi85F0rzZR+G2XS/sc7Y7I07HphfFwb70vPYsRzIkNxnErcDpB1Aa63IsbROag4aIZlLh9t4Hf3yOfS5PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kN9Ero6GTKWpGGULnpiCen6xIjzNXQhawfqFSyD8D/w=; b=Dxjneex8ip1w1ctoJWU3vjFkmt3LckHh8vrBJjfxpXWMfclb0VrfbT6NqbSTkgpmomvc8aV94Egy8C3iih9AAP2rh+S2QjXNk6Kb1QDpD3rhqf1JdKRBRpp89oUIDc69AvGZqGSLkK+15WS1b6MxGbLAwLK8UIH1V+FzwC3BvGd2TBQ9HcYq/LjlovpBeINmyEYwn6GxRPQwUf4qM0XuMkphPTUPHjexG31DyW2RJV3Kdx0WtRuDfwr5Bu2DlGyui1B01sb6Nxgn3Q9Vt1nseP4vNJsbqoG9PB6Uoyrvkad3qLuMCAHT2sYwUpssF/Z6P07/Ur13nZIsjKN+0Ecf5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kN9Ero6GTKWpGGULnpiCen6xIjzNXQhawfqFSyD8D/w=; b=5lvcrOKyHNis9ry6D8fgZy+NZ0bjWty+8r27rEXxzs/FeANwt1mqeD423v9PBjaUe02ef83uPyEg4BgSDNYFpwmz3mZunt/SzbqobjKax2av1zXctno8FdYo98mQ6281e9ADNvVTe1xEl/MyyeLeoGbsWOZC+0ZxKwFznJF1CuM= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by CY5PR12MB6550.namprd12.prod.outlook.com (2603:10b6:930:42::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 01:29:18 +0000 Received: from MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::46f1:bdce:a4bc:29e3]) by MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::46f1:bdce:a4bc:29e3%3]) with mapi id 15.20.6363.032; Wed, 10 May 2023 01:29:18 +0000 From: "Chang, Abner" To: Nickle Wang , "devel@edk2.groups.io" CC: Igor Kulchytskyy Subject: Re: [edk2-redfish-client][PATCH 2/6] RedfishClientPkg: Introduce Redfish version library Thread-Topic: [edk2-redfish-client][PATCH 2/6] RedfishClientPkg: Introduce Redfish version library Thread-Index: AQHZgn5rl1wzqEbl1EuofuYc5/EwQa9SuKuw Date: Wed, 10 May 2023 01:29:18 +0000 Message-ID: References: <20230509135843.6956-1-nicklew@nvidia.com> In-Reply-To: <20230509135843.6956-1-nicklew@nvidia.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Enabled=true; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SetDate=2023-05-10T01:29:16Z; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Method=Standard; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Name=General; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ActionId=8e7b9a47-0862-45f3-bfd7-a573e9b0c35e; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ContentBits=1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB3966:EE_|CY5PR12MB6550:EE_ x-ms-office365-filtering-correlation-id: b0cc89e7-7989-469b-7b29-08db50f5f93c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: og8zRcmCIhNn6fpx+s0ChrZiu8JsLf73jcHpBme40Pf7jyD98lf970NBrsNei/NTAZF70z0KDea1xpWt8d9xHf3qlzIndZc3gFwIDFJOZ7cxUWsAK0p3TwxVJyTQMf8OOcBSebZN+iX6PVIS8CvCUDSJC/xOv9FEb8UuDdTqG0VERcL16iw5anPZFL+5j6EsAMhe7jQRvZh8ZuO2H3qCUgAAZmIAV7C8GBh3ywEGj42x5/wni7fL0hINgJoepeBcItdUirJU0JAEDyn/JtBAQF2N4d3ukvufvNPQfjG7wILyvW7eBtvp80oGnXZvw/P4VDDqyo5KxSWCHXjBebZQUEbYK6/KXWL3Lo6YIR4PqAf9+r7bdbTdFvfhvZYs+L5G4+VWG4qhfc8LjRBMivVjtyP8AyRh959qgkIwJf443t1EQRKPqe9hRj1HeFGq1BMuJbGH/bm7w+ywP2mtF+1kwkLUiqEHRnBbY4pytwAEHdiOz6UXcHHMSHPUHVBoSgd1AAvfe2582wTE4ACiquQJ3+nTJC37+pQZah1Lf+CsAqu+OaWLfy/7mLrNhbTweFXFgQ9Rhl7aMLjSW3UShlniOGAAwjE5wnFcbQdUQYGJXLal3m6DonGMJDZsgQVZo4Im x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3966.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(366004)(396003)(136003)(346002)(376002)(451199021)(2906002)(86362001)(83380400001)(38070700005)(186003)(4326008)(41300700001)(66476007)(66946007)(76116006)(66446008)(64756008)(66556008)(9686003)(6506007)(26005)(53546011)(30864003)(5660300002)(33656002)(7696005)(38100700002)(52536014)(71200400001)(55016003)(122000001)(110136005)(316002)(8676002)(8936002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?dOB8xguIcduHS2IWO241sWgdmK41+8uwoG8NGq71lDABibVnB/l9PcrjHZGo?= =?us-ascii?Q?z8tFXheElPIMle9F+G4ugJTYOxYtUvNeaLBR47rK5S/RsKzEYWvATu56sIZL?= =?us-ascii?Q?ttZl78JvfrZaFBEJVOGi8qKe1ikuHOZAkZqUqfst/pnDa/hw7ZjMRApdgQL6?= =?us-ascii?Q?c8fBFPL5CCdqjNiJW6frZbjTDDa8xHodqJKi4TJJOXR7vZfOjkPeQl7wPhOS?= =?us-ascii?Q?SJVWF8BcmxawLGhlOY8SAw72lsCXdmHlgS01pT03QI+4Ip6j0RTykSzvWzZ7?= =?us-ascii?Q?Yg4+Wk6wb2CvqhEbjtHMok4Zwq2Z87lwaqG3Jm38UzohTVW+QEFH4kATZTQj?= =?us-ascii?Q?BMsMPKq1+H2bJCkVNMYY3TYyCQQO6Ffhvz/82OEojHdPFRz2d/TVBUmIqlHg?= =?us-ascii?Q?1RYDLQ2OYJno6ghiL1R5NM2R2/sT8ed3T+VTnsKe9MUHVi1YwiuTk3M96vKO?= =?us-ascii?Q?PEb0hL7bpwEQk7A4oCKXqC7ekQ+IwzNW7FZ4F4Ca4jJShoFsPUDb4Ja49G9v?= =?us-ascii?Q?5cctV7wHaixcxa6eFC1qQpWdfREBEIvyBLKn7Di9U7VSd2+gjmpcdlFpkiYw?= =?us-ascii?Q?ztn3sTDsmBtE1mOWHoyVMeaPHt/yWtaWXOx4ljMekveyHYJTk8aJH6zTHfZq?= =?us-ascii?Q?LWMXrt7QOODPFGKpKVboqkz7Ps06nrLoq6bTzv39zQQsZg5/SiXdyw9TByLJ?= =?us-ascii?Q?Pifrf24cjhTdhQCVZuS5hKe96zBZ2lgU9MxcLJ5vEp0IxX1OTD33Du2YcWY0?= =?us-ascii?Q?a70sd/6wACRYiHM0uFKNgrjNSjw/paMlV2m+WGCCb35+PkvzWYfjjFQ5lFRW?= =?us-ascii?Q?VXWdiMwojLsC4s8yKbw5sFchrJUgeOTyUvcpkYu6ex3DRNT6e1p0p3YSAuKX?= =?us-ascii?Q?uUoJN675gcTrGmCchmSLWIludn5A2WOxc2dZJOHN7IGY5EtyWXn6ZI8HtrjA?= =?us-ascii?Q?A84vi1d5FvXR/H4n4HiJotWvl4wWXDWYYV2tAwNTjVHeMSN/MvaeJ0CwQvZJ?= =?us-ascii?Q?/M3jayAIWgofVGQgT4gpFQp7vsnwalRe1is5dbXaozTkamwLyhaLpASkpABZ?= =?us-ascii?Q?W1hgYjq2pPytt8uX1Kr71pNS2om488bTeS/dS3I+2WVWnsF3LEv6tyMTLUdt?= =?us-ascii?Q?SO2oGt2TtTCyKUivYjjxo9qvW6Kzfse2RTC5NR8pWKLBeBkTQ36FaKaJsnL3?= =?us-ascii?Q?foe9reQIKoqqu3bgZwo5uVz/hfmk7Yq0H/FiaJVH9ygQ5t9b0ah73lUM8GeK?= =?us-ascii?Q?tewG0HGXvmE76uAkobt/+tA+2+Zx42p4urZPJkVDVx4B5f55jGW1ynsHViHB?= =?us-ascii?Q?ccMKZsRPgEOJ7H3bE+GjyLOt6ZQzZ1GS6ZIzoQaZAWL6cgaYXyb78yZlUMiB?= =?us-ascii?Q?Nhk2CFUhY8Zta6MbG2rTY3erAAUkx3hnAly4m0xUBJ4vU+PwNylLWeZVEtbC?= =?us-ascii?Q?Q2ffVC768ICFD6Ti02uRiuUuCfjAtHSHh5mG8VlcpdPzzaONIuQxfTeVtY8e?= =?us-ascii?Q?waXPTWmJAyXuWbbHxEmx2908VrshU1jrM2pDC1EC+OvLEedy3QBnyftozA/S?= =?us-ascii?Q?dfDiWjdVlazDzS0SGZU9pi/Ts8U3O6jPM7Jrchs1?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3966.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0cc89e7-7989-469b-7b29-08db50f5f93c X-MS-Exchange-CrossTenant-originalarrivaltime: 10 May 2023 01:29:18.1318 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: g88IhhnaLk8HXfUjtLDnyVG0UUXxg194SDTNHYJD+emcWxyr/ls2Miuw84eTxKsAEhMhyBUwA43E2wWJdYsOFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6550 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] Reviewed-by: Abner Chang > -----Original Message----- > From: Nickle Wang > Sent: Tuesday, May 9, 2023 9:59 PM > To: devel@edk2.groups.io > Cc: Chang, Abner ; Igor Kulchytskyy > > Subject: [edk2-redfish-client][PATCH 2/6] RedfishClientPkg: Introduce > Redfish version library >=20 > Caution: This message originated from an External Source. Use proper > caution when opening attachments, clicking links, or responding. >=20 >=20 > 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. >=20 > Signed-off-by: Nickle Wang > Cc: Abner Chang > Cc: Igor Kulchytskyy > --- > RedfishClientPkg/RedfishClientPkg.dec | 4 +- > RedfishClientPkg/RedfishClientLibs.dsc.inc | 1 + > .../RedfishVersionLib/RedfishVersionLib.inf | 50 +++++ > .../Include/Library/RedfishVersionLib.h | 30 +++ > RedfishClientPkg/Include/RedfishBase.h | 22 ++ > .../RedfishVersionLib/RedfishVersionLib.c | 202 ++++++++++++++++++ > 6 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 > RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf > create mode 100644 RedfishClientPkg/Include/Library/RedfishVersionLib.h > create mode 100644 RedfishClientPkg/Include/RedfishBase.h > create mode 100644 > RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c >=20 > diff --git a/RedfishClientPkg/RedfishClientPkg.dec > b/RedfishClientPkg/RedfishClientPkg.dec > index 39b2f5ba..2ce51d14 100644 > --- a/RedfishClientPkg/RedfishClientPkg.dec > +++ b/RedfishClientPkg/RedfishClientPkg.dec > @@ -22,6 +22,7 @@ > [LibraryClasses] > RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h > RedfishEventLib|Include/Library/RedfishEventLib.h > + RedfishVersionLib|Include/Library/RedfishVersionLib.h >=20 > [LibraryClasses.Common.Private] > ## @libraryclass Redfish Helper Library @@ -52,4 +53,5 @@ > # { 0x7CE88FB3, 0x4BD7, 0x4679, { 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, = 0x0D, > 0x2B }} > # >=20 > gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupE > ventGuid|{0xB3, 0x8F, 0xE8, 0x7C, 0xD7, 0x4B, 0x79, 0x46, 0x87, 0xA8, 0xA= 8, > 0xD8, 0xDE, 0xE5, 0x0D, 0x2B}|VOID*|0x10000003 > - > + ## Default Redfish version string > + > + > gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion|L"v1"|VOID > + *|0x10000004 > diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc > b/RedfishClientPkg/RedfishClientLibs.dsc.inc > index ce1c27d8..1cf04069 100644 > --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc > +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc > @@ -29,3 +29,4 @@ >=20 > ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/Converte > rCommonLib/ConverterCommonLib.inf >=20 >=20 > RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.= i > nf > + > + RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVe > + rsionLib.inf > diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib= .inf > b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf > new file mode 100644 > index 00000000..34d13d64 > --- /dev/null > +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf > @@ -0,0 +1,50 @@ > +## @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-DAD96B526B6= 1 > + 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 > + > +[BuildOptions] > + # > + # NOTE: /wd4706 disables the following Visual Studio compiler warning = in > Jansson: > + # "C4706: assignment within conditional expression" > + # > + MSFT:*_*_*_CC_FLAGS =3D /wd4706 > diff --git a/RedfishClientPkg/Include/Library/RedfishVersionLib.h > b/RedfishClientPkg/Include/Library/RedfishVersionLib.h > new file mode 100644 > index 00000000..319f22bd > --- /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 00000000..1abe9517 > --- /dev/null > +++ b/RedfishClientPkg/Include/RedfishBase.h > @@ -0,0 +1,22 @@ > +/** @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') #def= ine > +REDFISH_DEBUG_TRACE DEBUG_INFO > + > +/// > +/// This GUID is used for an EFI Variable that stores the Redfish data. > +/// > +EFI_GUID mRedfishVariableGuid =3D { 0x91c46a3d, 0xed1a, 0x477b, { 0xa5, > +0x33, 0x87, 0x2d, 0xcd, 0xb0, 0xfc, 0xc1 } }; > + > +#endif > diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib= .c > b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c > new file mode 100644 > index 00000000..1fd76d7f > --- /dev/null > +++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c > @@ -0,0 +1,202 @@ > +/** @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", > __FUNCTION__, 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 > unloaded. > + @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; > +} > -- > 2.17.1