From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web08.5049.1603954702986378122 for ; Wed, 28 Oct 2020 23:58:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=cTmW26Jz; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=057147ffc3=nickle.wang@hpe.com) Received: from pps.filterd (m0148663.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 09T6wLQo029658 for ; Thu, 29 Oct 2020 06:58:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pps0720; bh=tik9Vb/qOcy/fdmNz4YsNyUiriX6pNWMCuyEPdK30Lw=; b=cTmW26JzEc/S520X8b8ygc6gqy+yp8q5zF8Z4znNFtcrgn0m7XxW13NK9e/kdtm+ETMI Psj32Lj6PuQpwbDGeVOadyYpxUsQBd96tsVOf8wBbG8rCji9/L89nnAkuoPAKU4NqJBl 4QygobBzVGcImAtekpX/PAg+jLUM5FnIWztHrCeeYiRHyxPy99OWi7iTP3iobpaoq13/ lR0vAUnBh0UeZRCjBuTO25pNG2HXaUJZoG50QPLychGX5NvQ0bfxBAVWmQxOdhowVyzc LviNE5UkhIAazftQ4WvP1WElpLirt6hI0cepxzXSfxmvl0xQHLlTiisa6uFqDsScTPDl 6w== Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0a-002e3701.pphosted.com with ESMTP id 34epa686f9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 29 Oct 2020 06:58:21 +0000 Received: from G1W8108.americas.hpqcorp.net (g1w8108.austin.hp.com [16.193.72.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g4t3425.houston.hpe.com (Postfix) with ESMTPS id CACBAAA for ; Thu, 29 Oct 2020 06:57:45 +0000 (UTC) Received: from G9W8454.americas.hpqcorp.net (2002:10d8:a104::10d8:a104) by G1W8108.americas.hpqcorp.net (2002:10c1:483c::10c1:483c) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 29 Oct 2020 06:57:45 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (15.241.52.10) by G9W8454.americas.hpqcorp.net (16.216.161.4) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Thu, 29 Oct 2020 06:57:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G8MoOPMkkDJxmK1ePCaEIF/foERnktDEIYFfVWIWvLUfZ0LSal/F86G1EZ5zJGQmp4khJSfheJtpxPyssi4rh15SxoLyPuI5C8W/RirEIKXzryxH70t7ga5K4lPLZ5N6IppXhzgiPZxap2L9BadAblQNGzZHp/No7axCXZyDZdlU/M6D/Hoe9ZVwG1O53UqZcokcWEsJjEfWG/i7tgkdvQLnZgMT4nC01HOMELZOHR4bYtf0W8XUDIdrP+GSibr5RvZTcO9V/NHgl/5ExzG2aHa7nQTQdY6fwdMkScGIZP64HcV/cba7ombbZOj8yxSH0Gs07qrcel+dNcFDDl0PZA== 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-SenderADCheck; bh=tik9Vb/qOcy/fdmNz4YsNyUiriX6pNWMCuyEPdK30Lw=; b=YdGLhhR68fxgq4sI/nx1x1Y6AER9TNp+o2iolm6Je/3ADnIVA47wFnkNMLLegcNCr3XKLikXCQBzPheoSxdLTrnSIcBW4g0K0GYX+xvMu2cwC8qCLV6dpPA/ZW0hO3bOitwLGVx/CvArQbmad9VqtQDvTRWmUGgK+mHlXkeUjMScu54mt3hTpKEQntApG5++O2GVHnCEeKC0BhQAPD1xT7T6zo0/ii2TCrAU0bL3w9tkaQsyGcI3zcIryvDmZXQY0haQgpfZRGFm3FXXnmpwjCNCpE6GdzsyvUORstvGAiOph9nOWMmSj1Rq4Nyp57Nrz6hOqT3eg0iUbfgCBn2Mfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Received: from DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:760d::7) by DF4PR8401MB0460.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7607::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.25; Thu, 29 Oct 2020 06:57:42 +0000 Received: from DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM ([fe80::c9cf:9c73:a8a5:331b]) by DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM ([fe80::c9cf:9c73:a8a5:331b%12]) with mapi id 15.20.3499.018; Thu, 29 Oct 2020 06:57:42 +0000 From: "Nickle Wang" To: "Chang, Abner (HPS SW/FW Technologist)" , "devel@edk2.groups.io" CC: Jiaxin Wu , Siyuan Fu , Fan Wang , Jiewen Yao Subject: Re: [RestJsonStructureDxe PATCH v3 2/3] RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol Thread-Topic: [RestJsonStructureDxe PATCH v3 2/3] RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol Thread-Index: AQHWoxEFKAtTeOWcQki1RbLJfNzAx6muOspw Date: Thu, 29 Oct 2020 06:57:42 +0000 Message-ID: References: <20201015154928.16211-1-abner.chang@hpe.com> <20201015154928.16211-3-abner.chang@hpe.com> In-Reply-To: <20201015154928.16211-3-abner.chang@hpe.com> Accept-Language: zh-TW, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: hpe.com; dkim=none (message not signed) header.d=none;hpe.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [36.224.251.48] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 474b0a17-035e-40ac-889f-08d87bd7eece x-ms-traffictypediagnostic: DF4PR8401MB0460: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:209; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ndLmAfppnpFczud2zwUYQQo9WleYPGrzU9U2VUHaq0akU+YhlNOEfIEbkNI2lPFjpINVYf2gF50igPvDSwluVAsBOXM7Ef6p9PPTMZ7ehuSU3ppEz3JTF2kNWP+Jd3JipLwCXqxtt7/7too/Qu4nawwKxr+DS9we3g7Iy9Bz03afy/4iR3UUhbOLUembgoU3A1QgEBmuZMfe+DVm1g4I51AMkWqO+2Ho2WNwPQHWk0TfEuEr5MGpKeI+pKTTLt0R1dnFPBe7EDeryLZjBvVqElrn0A6BaI8Mw7cie/b7lZ+CFM5tfBjYK1CEgilsXKGYWKrHdlSb3+lFWeL+B2qSxQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(376002)(136003)(346002)(366004)(39860400002)(396003)(64756008)(4326008)(76116006)(86362001)(83380400001)(54906003)(9686003)(33656002)(5660300002)(52536014)(66446008)(110136005)(55016002)(66946007)(478600001)(2906002)(71200400001)(316002)(30864003)(7696005)(53546011)(66476007)(66556008)(8936002)(26005)(6506007)(8676002)(186003)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: K+7nMKxrpHg+ISeYRrDLWyYZwdb9OSoD7E8nN54qmp9m6fAueUs8/C823Yjf9DXmrzWk7W6MXRWtOEZdgmAfGbIqjD9XL/EjLSOERxJPOag2v3M3hvuxa9ohbHgHKqFmYx8vm9yFTwQFubu0H8ssiDwp/V7wiMLlgX9QsPi6B+cMboKxu3izJDgNhJKvYfDO9t1FePiadQLiyINbKcjJUFfqGzPjtUoCi2sMSJcMinyfxfJj6KYI990MEN1/QcNzGCDisvwiqr9JqdN3yxglcjB0tKeTChbcfNvDOQAQNLNcKZhwp50VmWRVWpkK8Ovh5gqnRJKoWumTK08vmRL6TcYcPFlPBC6LwMthCwo5D9XuQ3NsLbKDNnQ5XhK4Cymx0ESc+vzI4MZb4hFY0UnnNPLBFdrEDaBd+3QuTG+nAMEBwhlVRaje14qnAwolUieAtwpyYqGqwRTtHH8N6QzAmF4pACD2pH2cvgz5B6C4JOmY8SN4bBBeVIvYiV4beKrI2fkz0wyIvdRijDJh+mI2NVUnJUkx6JE1OdH60v4ALl18xogsH7nadxf/91gEuFFsyoKfFourV+rgTq1P7C0ZNkrzPGqAk0vlhf64/5+GmhQVkOAYPe5UI0lMNrD82a5SAAckPLb14pqQDcCuPTzQVQ== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 474b0a17-035e-40ac-889f-08d87bd7eece X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2020 06:57:42.5983 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VZnE7j0W1TGYOGkOo0GvBB8+0Rg3hQBH3w6oXSOmmt8q877KEF7fP5hAVfsRl0QmqtfC+YGHAuXpriqrsWgZHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR8401MB0460 X-OriginatorOrg: hpe.com X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-10-29_03:2020-10-29,2020-10-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 clxscore=1015 impostorscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010290048 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Abner, I have comment for function RestJsonStructureUnload(). Please check my inli= ne comment below. Thanks, Nickle > -----Original Message----- > From: Chang, Abner (HPS SW/FW Technologist) > Sent: Thursday, October 15, 2020 11:49 PM > To: devel@edk2.groups.io > Cc: Jiaxin Wu ; Siyuan Fu ; Fan > Wang ; Jiewen Yao ; Wang, > Nickle (HPS SW) > Subject: [RestJsonStructureDxe PATCH v3 2/3] > RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol >=20 > Implementation of EFI_REST_JSON_STRUCTURE_PROTOCOL, refer to UEFI > spec > 2.8 Section 29.7.3 EFI REST JSON Resource to C Structure Converter. >=20 > Signed-off-by: Abner Chang >=20 > Cc: Jiaxin Wu > Cc: Siyuan Fu > Cc: Fan Wang > Cc: Jiewen Yao > Cc: Nickle Wang > --- > RedfishPkg/RedfishPkg.dsc | 11 + > .../RestJsonStructureDxe.c | 585 ++++++++++++++++++ > .../RestJsonStructureDxe.inf | 40 ++ > .../RestJsonStructureInternal.h | 33 + > 4 files changed, 669 insertions(+) > create mode 100644 > RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > create mode 100644 > RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > create mode 100644 > RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h >=20 > diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc > index 8acadddefc..f0c6740fac 100644 > --- a/RedfishPkg/RedfishPkg.dsc > +++ b/RedfishPkg/RedfishPkg.dsc > @@ -38,3 +38,14 @@ >=20 > DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTabl > eLib.inf > DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf >=20 > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/Dx > eReportStatusCodeLib.inf > + > +[LibraryClasses.ARM, LibraryClasses.AARCH64] > + # > + # This library provides the instrinsic functions generated by a given > compiler. > + # > + NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf > + NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf > + ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf > + > +[Components] > + RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > new file mode 100644 > index 0000000000..03fbecf993 > --- /dev/null > +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > @@ -0,0 +1,585 @@ > +/** @file > + > + The implementation of EFI REST Resource JSON to C structure convertor > + Protocol. > + > + (C) Copyright 2020 Hewlett Packard Enterprise Development LP
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include "RestJsonStructureInternal.h" > + > +LIST_ENTRY mRestJsonStructureList; > +EFI_HANDLE mProtocolHandle; > + > +/** > + This function registers Restful resource interpreter for the > + specific schema. > + > + @param[in] This This is the > EFI_REST_JSON_STRUCTURE_PROTOCOL instance. > + @param[in] JsonStructureSupported The type and version of REST JS= ON > resource which this converter > + supports. > + @param[in] ToStructure The function to convert REST JS= ON > resource to structure. > + @param[in] ToJson The function to convert REST JS= ON structure > to JSON in text format. > + @param[in] DestroyStructure Destroy REST JSON structure ret= urned > in ToStructure() function. > + > + @retval EFI_SUCCESS Register successfully. > + @retval Others Fail to register. > + > +**/ > +EFI_STATUS > +EFIAPI > +RestJsonStructureRegister ( > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > + IN EFI_REST_JSON_STRUCTURE_SUPPORTED *JsonStructureSupported, > + IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE ToStructure, > + IN EFI_REST_JSON_STRUCTURE_TO_JSON ToJson, > + IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure > +) > +{ > + UINTN NumberOfNS; > + UINTN Index; > + LIST_ENTRY *ThisList; > + REST_JSON_STRUCTURE_INSTANCE *Instance; > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *CloneSupportedInterpId; > + EFI_REST_JSON_STRUCTURE_SUPPORTED *ThisSupportedInterp; > + > + if (This =3D=3D NULL || > + ToStructure =3D=3D NULL || > + ToJson =3D=3D NULL || > + DestroyStructure =3D=3D NULL || > + JsonStructureSupported =3D=3D NULL > + ) { > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // Check how many name space interpreter can interpret. > + // > + ThisList =3D &JsonStructureSupported->NextSupportedRsrcInterp; > + NumberOfNS =3D 1; > + while (TRUE) { > + if (ThisList->ForwardLink =3D=3D &JsonStructureSupported- > >NextSupportedRsrcInterp) { > + break; > + } else { > + ThisList =3D ThisList->ForwardLink; > + NumberOfNS ++; > + } > + }; > + > + Instance =3D > + (REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof > (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof > (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER)); > + if (Instance =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + InitializeListHead (&Instance->NextRestJsonStructureInstance); > + Instance->NumberOfNameSpaceToConvert =3D NumberOfNS; > + Instance->SupportedRsrcIndentifier =3D > (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER > *)((REST_JSON_STRUCTURE_INSTANCE *)Instance + 1); > + // > + // Copy supported resource identifer interpreter. > + // > + CloneSupportedInterpId =3D Instance->SupportedRsrcIndentifier; > + ThisSupportedInterp =3D JsonStructureSupported; > + for (Index =3D 0; Index < NumberOfNS; Index ++) { > + CopyMem ((VOID *)CloneSupportedInterpId, (VOID > *)&ThisSupportedInterp->RestResourceInterp, sizeof > (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER)); > + ThisSupportedInterp =3D (EFI_REST_JSON_STRUCTURE_SUPPORTED > *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink; > + CloneSupportedInterpId ++; > + } > + Instance->JsonToStructure =3D ToStructure; > + Instance->StructureToJson =3D ToJson; > + Instance->DestroyStructure =3D DestroyStructure; > + InsertTailList (&mRestJsonStructureList, &Instance- > >NextRestJsonStructureInstance); > + return EFI_SUCCESS; > +} > + > +/** > + This function check if this interpreter instance support the given > namesapce. > + > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > instance. > + @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE > + @param[in] RsrcTypeIdentifier Resource type identifier. > + @param[in] ResourceRaw Given Restful resource. > + @param[out] RestJSonHeader Property interpreted from given > ResourceRaw. > + > + @retval EFI_SUCCESS > + @retval Others. > + > +**/ > +EFI_STATUS > +InterpreterInstanceToStruct ( > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > + IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance, > + IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier > OPTIONAL, > + IN CHAR8 *ResourceRaw, > + OUT EFI_REST_JSON_STRUCTURE_HEADER **RestJSonHeader > + ) > +{ > + UINTN Index; > + EFI_STATUS Status; > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId; > + > + if (This =3D=3D NULL || > + InterpreterInstance =3D=3D NULL || > + ResourceRaw =3D=3D NULL || > + RestJSonHeader =3D=3D NULL > + ) { > + return EFI_INVALID_PARAMETER; > + } > + > + Status =3D EFI_UNSUPPORTED; > + if (RsrcTypeIdentifier =3D=3D NULL) { > + // > + // No resource type identifier, send to intepreter anyway. > + // Interpreter may recognize this resource. > + // > + Status =3D InterpreterInstance->JsonToStructure ( > + This, > + NULL, > + ResourceRaw, > + RestJSonHeader > + ); > + } else { > + // > + // Check if the namesapce and version is supported by this interpret= er. > + // > + ThisSupportedRsrcTypeId =3D InterpreterInstance- > >SupportedRsrcIndentifier; > + for (Index =3D 0; Index < InterpreterInstance- > >NumberOfNameSpaceToConvert; Index ++){ > + if (AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.ResourceTypeName, > + ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) =3D=3D = 0){ > + if ((RsrcTypeIdentifier->NameSpace.MajorVersion =3D=3D NULL) && > + (RsrcTypeIdentifier->NameSpace.MinorVersion =3D=3D NULL) && > + (RsrcTypeIdentifier->NameSpace.ErrataVersion =3D=3D NULL) > + ) { > + // > + // Don't check version of this resource type identifier. > + // > + Status =3D InterpreterInstance->JsonToStructure ( > + This, > + RsrcTypeIdentifier, > + ResourceRaw, > + RestJSonHeader > + ); > + break; > + } else { > + // > + // Check version. > + // > + if ((AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.MajorVersion, > + ThisSupportedRsrcTypeId->NameSpace.MajorVersion) =3D=3D = 0) && > + (AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.MinorVersion, > + ThisSupportedRsrcTypeId->NameSpace.MinorVersion) =3D=3D = 0) && > + (AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.ErrataVersion, > + ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) =3D=3D= 0)) { > + Status =3D InterpreterInstance->JsonToStructure ( > + This, > + RsrcTypeIdentifier, > + ResourceRaw, > + RestJSonHeader > + ); > + break; > + } > + } > + } > + ThisSupportedRsrcTypeId ++; > + } > + } > + return Status; > +} > +/** > + This function converts JSON C structure to JSON property. > + > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > instance. > + @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE > + @param[in] RestJSonHeader Resource type identifier. > + @param[out] ResourceRaw Output in JSON text format. > + > + @retval EFI_SUCCESS > + @retval Others. > + > +**/ > +EFI_STATUS > +InterpreterEfiStructToInstance ( > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > + IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance, > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader, > + OUT CHAR8 **ResourceRaw > +) > +{ > + UINTN Index; > + EFI_STATUS Status; > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId; > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier; > + > + if (This =3D=3D NULL || > + InterpreterInstance =3D=3D NULL || > + RestJSonHeader =3D=3D NULL || > + ResourceRaw =3D=3D NULL > + ) { > + return EFI_INVALID_PARAMETER; > + } > + RsrcTypeIdentifier =3D &RestJSonHeader->JsonRsrcIdentifier; > + if (RsrcTypeIdentifier =3D=3D NULL || > + RsrcTypeIdentifier->NameSpace.ResourceTypeName =3D=3D NULL || > + RsrcTypeIdentifier->NameSpace.MajorVersion =3D=3D NULL || > + RsrcTypeIdentifier->NameSpace.MinorVersion =3D=3D NULL || > + RsrcTypeIdentifier->NameSpace.ErrataVersion =3D=3D NULL > + ) { > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // Check if the namesapce and version is supported by this interpreter= . > + // > + Status =3D EFI_UNSUPPORTED; > + ThisSupportedRsrcTypeId =3D InterpreterInstance- > >SupportedRsrcIndentifier; > + for (Index =3D 0; Index < InterpreterInstance- > >NumberOfNameSpaceToConvert; Index ++){ > + if (AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.ResourceTypeName, > + ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) =3D=3D 0)= { > + // > + // Check version. > + // > + if ((AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.MajorVersion, > + ThisSupportedRsrcTypeId->NameSpace.MajorVersion) =3D=3D 0) &= & > + (AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.MinorVersion, > + ThisSupportedRsrcTypeId->NameSpace.MinorVersion) =3D=3D 0) &= & > + (AsciiStrCmp ( > + RsrcTypeIdentifier->NameSpace.ErrataVersion, > + ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) =3D=3D 0))= { > + Status =3D InterpreterInstance->StructureToJson ( > + This, > + RestJSonHeader, > + ResourceRaw > + ); > + break; > + } > + } > + ThisSupportedRsrcTypeId ++; > + } > + return Status; > +} > + > +/** > + This function destory REST property structure. > + > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > instance. > + @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE > + @param[in] RestJSonHeader Property interpreted from given > ResourceRaw. > + > + @retval EFI_SUCCESS > + @retval Others. > + > +**/ > +EFI_STATUS > +InterpreterInstanceDestoryJsonStruct ( > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > + IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance, > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader > + ) > +{ > + UINTN Index; > + EFI_STATUS Status; > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId; > + > + if (This =3D=3D NULL || > + InterpreterInstance =3D=3D NULL || > + RestJSonHeader =3D=3D NULL > + ) { > + return EFI_INVALID_PARAMETER; > + } > + > + Status =3D EFI_UNSUPPORTED; > + // > + // Check if the namesapce and version is supported by this interpreter= . > + // > + ThisSupportedRsrcTypeId =3D InterpreterInstance- > >SupportedRsrcIndentifier; > + for (Index =3D 0; Index < InterpreterInstance- > >NumberOfNameSpaceToConvert; Index ++){ > + if (AsciiStrCmp ( > + RestJSonHeader->JsonRsrcIdentifier.NameSpace.ResourceTypeName, > + ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) =3D=3D 0)= { > + if ((RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion =3D= =3D > NULL) && > + (RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion =3D= =3D > NULL) && > + (RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion = =3D=3D > NULL) > + ) { > + // > + // Don't check version of this resource type identifier. > + // > + Status =3D InterpreterInstance->DestroyStructure ( > + This, > + RestJSonHeader > + ); > + break; > + } else { > + // > + // Check version. > + // > + if ((AsciiStrCmp ( > + RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion, > + ThisSupportedRsrcTypeId->NameSpace.MajorVersion) =3D=3D 0)= && > + (AsciiStrCmp ( > + RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion, > + ThisSupportedRsrcTypeId->NameSpace.MinorVersion) =3D=3D 0)= && > + (AsciiStrCmp ( > + RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion= , > + ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) =3D=3D 0= )) { > + Status =3D InterpreterInstance->DestroyStructure ( > + This, > + RestJSonHeader > + ); > + break; > + } > + } > + } > + ThisSupportedRsrcTypeId ++; > + } > + return Status; > +} > + > +/** > + This function translates the given JSON text to JSON C Structure. > + > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > instance. > + @param[in] RsrcTypeIdentifier Resource type identifier. > + @param[in] ResourceJsonText Given Restful resource. > + @param[out] JsonStructure Property interpreted from given > ResourceRaw. > + > + @retval EFI_SUCCESS > + @retval Others. > + > +**/ > +EFI_STATUS > +EFIAPI > +RestJsonStructureToStruct ( > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > + IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier > OPTIONAL, > + IN CHAR8 *ResourceJsonText, > + OUT EFI_REST_JSON_STRUCTURE_HEADER **JsonStructure > +) > +{ > + EFI_STATUS Status; > + REST_JSON_STRUCTURE_INSTANCE *Instance; > + > + if (This =3D=3D NULL || > + ResourceJsonText =3D=3D NULL || > + JsonStructure =3D=3D NULL > + ) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (IsListEmpty (&mRestJsonStructureList)) { > + return EFI_UNSUPPORTED; > + } > + Status =3D EFI_SUCCESS; > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > (&mRestJsonStructureList); > + while (TRUE) { > + Status =3D InterpreterInstanceToStruct ( > + This, > + Instance, > + RsrcTypeIdentifier, > + ResourceJsonText, > + JsonStructure > + ); > + if (!EFI_ERROR (Status)) { > + break; > + } > + if (IsNodeAtEnd(&mRestJsonStructureList, &Instance- > >NextRestJsonStructureInstance)) { > + Status =3D EFI_UNSUPPORTED; > + break; > + } > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > + }; > + return Status; > +} > + > +/** > + This function destory REST property EFI structure which returned in > + JsonToStructure(). > + > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instanc= e. > + @param[in] RestJSonHeader Property to destory. > + > + @retval EFI_SUCCESS > + @retval Others > + > +**/ > +EFI_STATUS > +EFIAPI > +RestJsonStructureDestroyStruct ( > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader > +) > +{ > + EFI_STATUS Status; > + REST_JSON_STRUCTURE_INSTANCE *Instance; > + > + if (This =3D=3D NULL || RestJSonHeader =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (IsListEmpty (&mRestJsonStructureList)) { > + return EFI_UNSUPPORTED; > + } > + Status =3D EFI_SUCCESS; > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > (&mRestJsonStructureList); > + while (TRUE) { > + Status =3D InterpreterInstanceDestoryJsonStruct ( > + This, > + Instance, > + RestJSonHeader > + ); > + if (!EFI_ERROR (Status)) { > + break; > + } > + if (IsNodeAtEnd(&mRestJsonStructureList, &Instance- > >NextRestJsonStructureInstance)) { > + Status =3D EFI_UNSUPPORTED; > + break; > + } > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > + }; > + return Status; > +} > + > +/** > + This function translates the given JSON C Structure to JSON text. > + > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instanc= e. > + @param[in] RestJSonHeader Given Restful resource. > + @param[out] ResourceRaw Resource in RESTfuls service oriented. > + > + @retval EFI_SUCCESS > + @retval Others Fail to remove the entry > + > +**/ > +EFI_STATUS > +EFIAPI > +RestJsonStructureToJson ( > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader, > + OUT CHAR8 **ResourceRaw > +) > +{ > + EFI_STATUS Status; > + REST_JSON_STRUCTURE_INSTANCE *Instance; > + > + if (This =3D=3D NULL || RestJSonHeader =3D=3D NULL || ResourceRaw =3D= =3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (IsListEmpty (&mRestJsonStructureList)) { > + return EFI_UNSUPPORTED; > + } > + Status =3D EFI_SUCCESS; > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > (&mRestJsonStructureList); > + while (TRUE) { > + Status =3D InterpreterEfiStructToInstance ( > + This, > + Instance, > + RestJSonHeader, > + ResourceRaw > + ); > + if (!EFI_ERROR (Status)) { > + break; > + } > + if (IsNodeAtEnd(&mRestJsonStructureList, &Instance- > >NextRestJsonStructureInstance)) { > + Status =3D EFI_UNSUPPORTED; > + break; > + } > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > + }; > + return Status; > +} > + > +EFI_REST_JSON_STRUCTURE_PROTOCOL mRestJsonStructureProtocol =3D { > + RestJsonStructureRegister, > + RestJsonStructureToStruct, > + RestJsonStructureToJson, > + RestJsonStructureDestroyStruct > +}; > + > +/** > + This is the declaration of an EFI image entry point. > + > + @param ImageHandle The firmware allocated handle for the UE= FI > image. > + @param SystemTable A pointer to the EFI System Table. > + > + @retval EFI_SUCCESS The operation completed successfully. > + @retval Others An unexpected error occurred. > +**/ > +EFI_STATUS > +EFIAPI > +RestJsonStructureEntryPoint ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + > + InitializeListHead (&mRestJsonStructureList); > + // > + // Install the Restful Resource Interpreter Protocol. > + // > + mProtocolHandle =3D NULL; > + Status =3D gBS->InstallProtocolInterface ( > + &mProtocolHandle, > + &gEfiRestJsonStructureProtocolGuid, > + EFI_NATIVE_INTERFACE, > + (VOID *)&mRestJsonStructureProtocol > + ); > + return Status; > +} > + > +/** > + This is the unload handle for Redfish discover module. > + > + Disconnect the driver specified by ImageHandle from all the devices in= the > handle database. > + Uninstall all the protocols installed in the driver entry point. > + > + @param[in] ImageHandle The drivers' driver image. > + > + @retval EFI_SUCCESS The image is unloaded. > + @retval Others Failed to unload the image. > + > +**/ > +EFI_STATUS > +EFIAPI > +RestJsonStructureUnload ( > + IN EFI_HANDLE ImageHandle > + ) > +{ > + EFI_STATUS Status; > + REST_JSON_STRUCTURE_INSTANCE *Instance; > + REST_JSON_STRUCTURE_INSTANCE *NextInstance; > + > + if (IsListEmpty (&mRestJsonStructureList)) { > + return EFI_SUCCESS; > + } We still need to uninstall REST Json Structure Protocol when list is empty,= right? The protocol is installed on driver entry when list is empty.=20 > + // > + // Free memory of REST_JSON_STRUCTURE_INSTANCE instance. > + // > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > (&mRestJsonStructureList); > + do { > + NextInstance =3D NULL; > + if (!IsNodeAtEnd(&mRestJsonStructureList, &Instance- > >NextRestJsonStructureInstance)) { > + NextInstance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > + } > + FreePool ((VOID *)Instance); > + Instance =3D NextInstance; > + } while (Instance !=3D NULL); > + > + Status =3D gBS->UninstallProtocolInterface ( > + mProtocolHandle, > + &gEfiRestJsonStructureProtocolGuid, > + (VOID *)&mRestJsonStructureProtocol > + ); > + return Status; > +} > diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > new file mode 100644 > index 0000000000..2ab1e3bc45 > --- /dev/null > +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > @@ -0,0 +1,40 @@ > +## @file > +# Implementation of EFI REST JSON Structure Protocol. > +# > +# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION =3D 0x00010005 > + BASE_NAME =3D RestJsonStructureDxe > + FILE_GUID =3D 83FAAFBF-FC4B-469F-892A-798E66A6F50A > + MODULE_TYPE =3D DXE_DRIVER > + VERSION_STRING =3D 1.0 > + ENTRY_POINT =3D RestJsonStructureEntryPoint > + UNLOAD_IMAGE =3D RestJsonStructureUnload > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + RedfishPkg/RedfishPkg.dec > + > +[Sources] > + RestJsonStructureDxe.c > + RestJsonStructureInternal.h > + > +[LibraryClasses] > + BaseLib > + BaseMemoryLib > + MemoryAllocationLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + UefiLib > + > +[Protocols] > + gEfiRestJsonStructureProtocolGuid ## Producing > + > +[Depex] > + TRUE > + > diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h > b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h > new file mode 100644 > index 0000000000..e8a3408404 > --- /dev/null > +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h > @@ -0,0 +1,33 @@ > +/** @file > + The internal definitions of EFI REST Resource JSON to C structure conv= ertor > + Protocol. > + > + (C) Copyright 2020 Hewlett Packard Enterprise Development LP
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef EFI_REST_JSON_STRUCTURE_INTERNAL_H_ > +#define EFI_REST_JSON_STRUCTURE_INTERNAL_H_ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +/// > +/// Internal structure to maintain the information of JSON to > +/// C structure convertor. > +/// > +typedef struct _REST_JSON_STRUCTURE_INSTANCE { > + LIST_ENTRY NextRestJsonStructureInstance; ///< Next convertor instanc= e > + UINTN NumberOfNameSpaceToConvert; ///< Number of resource > type this convertor supports. > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER > *SupportedRsrcIndentifier; ///< The resource type linklist > + EFI_REST_JSON_STRUCTURE_TO_STRUCTURE JsonToStructure; > ///< JSON to C structure function > + EFI_REST_JSON_STRUCTURE_TO_JSON StructureToJson; = ///< C > structure to JSON function > + EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure; > ///< Destory C struture function. > +} REST_JSON_STRUCTURE_INSTANCE; > +#endif > -- > 2.17.1