From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.61]) by mx.groups.io with SMTP id smtpd.web11.15881.1683723893027766811 for ; Wed, 10 May 2023 06:04:53 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=YRgKZ8I4; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.223.61, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mOUr4HjtcyvoMRplITJC3d+Zy+4euJgYMuBitYLkNOYCqs+eoloH8xHErZFPjmPp1tgFbjMwqDxBwZ0M9pdXL2oH07BxI8bPZFQihH7iA4pQ2P1/XuxWlTt50n9UPnJ4kNGNKo13PeXx9087jWUCqS2OMc98NyCNY2Qalrtp4wBsIIJxsXovhI4z2LLzZA1eK0RFd1Qpx8J2Pr8APktsdt/Z45yeXk7BX8f0Qfb9l6vNk6gZeW5xYolKoLn/bx+TDUohP9YbVWY8WQfwgz4aG8UyYVSakMTQ8upX8AH1ILCas6G4K0xoI94PW1HRrEPd6EfyzEv2/rqM87XTXZtWLw== 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=HaY4T5YlN2Ze1YoV85nTWunWcxNz3fGktSbTnNPMsb4=; b=IkgdnWq/4WlauYQyi8OKqQOSDAfcc8Hi90POj/SoN21vW+llA+u9QInfdPCV1IArGItOebWJvo5c4IpyBVP4fosTgLLbA4SXN3VuIMWoBsDN3n/UrbslO2gD18nB98JHX+UNHxjJw/uhiuvK8FgvCL3Mr9cAoaJ8tXJ0RhyuXegYHqlX2ZUE5jIyTRJYX+AInHEOE1jwWg8JcbkVPy8otFnThSPX3jUlz+B0Kj3uic+AJZSioxytE7gDqcRObnF6F6IBJxuLtmwuILwh324+JEzrFcMkdiyxztX5JYcA/Ai8ldyhMorhWazHkvN0lxsSDqvU30DutOMxtWCUcnxIgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HaY4T5YlN2Ze1YoV85nTWunWcxNz3fGktSbTnNPMsb4=; b=YRgKZ8I4N2fUskh9BfLzxbByu+i+mnTUjWqxxs3y7wjlP/E62MQXc3QS/4guwMu9cxypTy3Htm8Bs83mI87XDAvyySis0psBDSNc2XFps0s0LmXp+bd9PONJGjC7w7wjM2VMc7GpQoxbWiw1KWDVBsFbXe/fTOZ1dqO/Gs1W+TnaYJJFOXTlHmwkaz7m4yv9dpWK/yGY0fcp3LFvYfNNvDpZOsddJrMACocWIp3mc11FmmHOn711muwClY5bQ6tw6gkim90Z80ebDbvLzlT+2BhcBPCVblUOVPVAyw7p7uq0t9OGOqFB9RGHMTnRph8gXuicT0krjKHNtOPaart54w== Received: from BN9PR03CA0265.namprd03.prod.outlook.com (2603:10b6:408:ff::30) by DS7PR12MB8371.namprd12.prod.outlook.com (2603:10b6:8:e9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20; Wed, 10 May 2023 13:04:50 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::29) by BN9PR03CA0265.outlook.office365.com (2603:10b6:408:ff::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Wed, 10 May 2023 13:04:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 13:04:50 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 10 May 2023 06:04:36 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 10 May 2023 06:04:35 -0700 Received: from NV-CL38DL3.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Wed, 10 May 2023 06:04:35 -0700 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy Subject: [edk2-redfish-client][PATCH 3/5] RedfishClientPkg: Introduce Computer System collection driver Date: Wed, 10 May 2023 21:04:35 +0800 Message-ID: <20230510130435.9406-1-nicklew@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Return-Path: nicklew@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|DS7PR12MB8371:EE_ X-MS-Office365-Filtering-Correlation-Id: ee8a395f-b662-4b6b-8cdb-08db51572377 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uCK+gdFRzWuRy/pZuruii2FXA+iZDx3LksQHg8ym+6Ngv0qfgYFlhNtGU0B6+K9zMDWela58eF08gHSDTwbxksFfuW7UOpDZx2CNJQPZ4cfucLf8aFv/aBFouwDjHRVALp4fvKbM9CxSPdHeN0MGA0kp2d5pmU8cYXTMbfkY6NV1LFejCxL11Kda4SCzMz0gY6Q02de3B3QWGvVcte85DUSNaIooHdTI+qKRg30wYknbsQ+2RarlfMdXp0d0UIYKORV/VA4h+IAjDfCJKgoZ7MdLOGD5SjYNwXzPXZ1H+BodLPvGIRku10wgOg/j+q+z+xWWl3fFeCE0KJzkCTc7zJJRDWXZ2mzKlgV5z1wfv/Hk9EvJMVpcLwHJxZrF5cT0UZsQuP5fwGtoeyQSLyX6zUNkhlHVavcymQE3mKZsTJvAd9Vce30DHSjcaR5Oxpf7GSumgjGbKSuPTOR+eMSd7PbFjpSip2Rdq7/1t9lqdn+z/Yj1Zu3KX9cfMKTDS9VMJYxAj27Y/XdCaf4afIvkWrVDMN3MlzGhuVvCPtOAUWBqLIhSD113KQFFHiOOqZYrV2bNz3cGHEq66GlNufmR1Q/rHpLEDMaD5M0J1Xp5vgRRpwl8FzybsYWWaUAlUbko6J7JD/VoHI0BZYI71wxRHiFPZnK1ivPQ9Zr4hfxm+G7k1XVHummhCiUuYiZ7F0MwQtXy+Un/cGCh70of1dZ1zUzPOjPmSFHb9iQ8W0cG0x5hum9hEN64hjKI4tA2JYKQ+MCZKj6UWQO1GrPrT9WqBA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(346002)(376002)(39860400002)(396003)(451199021)(36840700001)(40470700004)(46966006)(4326008)(70206006)(70586007)(82310400005)(6916009)(316002)(36756003)(86362001)(40460700003)(54906003)(1076003)(26005)(186003)(40480700001)(5660300002)(8936002)(2616005)(47076005)(8676002)(30864003)(2906002)(83380400001)(426003)(336012)(36860700001)(356005)(7636003)(41300700001)(82740400003)(7696005)(478600001)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 13:04:50.0224 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ee8a395f-b662-4b6b-8cdb-08db51572377 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8371 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Introduce new feature driver to support Computer System Collection schema. Update corresponding FDF and DSC file to enable this feature driver. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy --- .../RedfishClientComponents.dsc.inc | 2 + RedfishClientPkg/RedfishClientLibs.dsc.inc | 1 + .../ComputerSystemCollectionDxe.inf | 56 ++ .../ComputerSystemCollectionDxe.h | 21 + .../ComputerSystemCollectionDxe.c | 667 ++++++++++++++++++ RedfishClientPkg/RedfishClient.fdf.inc | 2 + 6 files changed, 749 insertions(+) create mode 100644 RedfishClientPkg/Features/ComputerSystemCollectionDxe/C= omputerSystemCollectionDxe.inf create mode 100644 RedfishClientPkg/Features/ComputerSystemCollectionDxe/C= omputerSystemCollectionDxe.h create mode 100644 RedfishClientPkg/Features/ComputerSystemCollectionDxe/C= omputerSystemCollectionDxe.c diff --git a/RedfishClientPkg/RedfishClientComponents.dsc.inc b/RedfishClie= ntPkg/RedfishClientComponents.dsc.inc index 031d8755..d4a33385 100644 --- a/RedfishClientPkg/RedfishClientComponents.dsc.inc +++ b/RedfishClientPkg/RedfishClientComponents.dsc.inc @@ -21,6 +21,7 @@ # RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.inf + RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemColl= ectionDxe.inf =20 !include RedfishClientPkg/RedfishJsonStructureDxe.dsc.inc =20 @@ -30,3 +31,4 @@ RedfishClientPkg/Converter/Memory/v1_7_1/RedfishMemory_V1_7_1_Dxe.inf RedfishClientPkg/Converter/MemoryCollection/RedfishMemoryCollection_Dxe.= inf !endif + RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerSyste= mCollection_Dxe.inf diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/= RedfishClientLibs.dsc.inc index 413b83a7..21595613 100644 --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc @@ -19,6 +19,7 @@ # MemoryV1_7_1Lib|RedfishClientPkg/ConverterLib/edk2library/Memory/v1_7_1/= Lib.inf MemoryCollectionLib|RedfishClientPkg/ConverterLib/edk2library/MemoryColl= ection/Lib.inf + ComputerSystemCollectionLib|RedfishClientPkg/ConverterLib/edk2library/Co= mputerSystemCollection/Lib.inf =20 NetLib|NetworkPkg/Library/DxeNetLib/DxeNetLib.inf HttpLib|NetworkPkg/Library/DxeHttpLib/DxeHttpLib.inf diff --git a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/Computer= SystemCollectionDxe.inf b/RedfishClientPkg/Features/ComputerSystemCollectio= nDxe/ComputerSystemCollectionDxe.inf new file mode 100644 index 00000000..107d6c07 --- /dev/null +++ b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemC= ollectionDxe.inf @@ -0,0 +1,56 @@ +## @file +# +# Redfish ComputerSystemCollection collection driver. +# +# (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D ComputerSystemCollectionDxe + FILE_GUID =3D df883f2e-9f58-4514-9cc9-06cbe6f63073 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D RedfishCollectionEntryPoint + UNLOAD_IMAGE =3D RedfishCollectionUnload + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[Sources] + ComputerSystemCollectionDxe.h + ComputerSystemCollectionDxe.c + +[LibraryClasses] + DebugLib + BaseMemoryLib + ConverterCommonLib + MemoryAllocationLib + RedfishFeatureUtilityLib + RedfishLib + UefiLib + UefiDriverEntryPoint + UefiBootServicesTableLib + EdkIIRedfishResourceConfigLib + RedfishVersionLib + +[Protocols] + gEdkIIRedfishConfigHandlerProtocolGuid ## CONSUMED + gEfiRestJsonStructureProtocolGuid ## CONSUMED + gEdkIIRedfishFeatureProtocolGuid ## CONSUMED + +[Guids] + +[Pcd] + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize + +[Depex] + TRUE diff --git a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/Computer= SystemCollectionDxe.h b/RedfishClientPkg/Features/ComputerSystemCollectionD= xe/ComputerSystemCollectionDxe.h new file mode 100644 index 00000000..4c5f67fb --- /dev/null +++ b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemC= ollectionDxe.h @@ -0,0 +1,21 @@ +/** @file + + Redfish feature driver implementation - internal header file + + (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EFI_REDFISH_COMPUTERSYSTEM_COLLECTION_H_ +#define EFI_REDFISH_COMPUTERSYSTEM_COLLECTION_H_ + +#include +#include + +#define REDFISH_SCHEMA_NAME "ComputerSystem" +#define REDFISH_MANAGED_URI L"Systems/{}" +#define MAX_URI_LENGTH 256 + +#endif diff --git a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/Computer= SystemCollectionDxe.c b/RedfishClientPkg/Features/ComputerSystemCollectionD= xe/ComputerSystemCollectionDxe.c new file mode 100644 index 00000000..393ec955 --- /dev/null +++ b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemC= ollectionDxe.c @@ -0,0 +1,667 @@ +/** @file + + Redfish feature driver implementation - ComputerSystemCollection + + (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "ComputerSystemCollectionDxe.h" + +REDFISH_COLLECTION_PRIVATE *mRedfishCollectionPrivate =3D NULL; + +EFI_STATUS +HandleResource ( + IN REDFISH_COLLECTION_PRIVATE *Private, + IN EFI_STRING Uri + ) +{ + EFI_STATUS Status; + REDFISH_SCHEMA_INFO SchemaInfo; + EFI_STRING ConfigLang; + EFI_STRING ReturnedConfigLang; + UINTN Index; + + if ((Private =3D=3D NULL) || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + // + // Resource match + // + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, process resource for: %s\n", __FUNCTIO= N__, Uri)); + + Status =3D GetRedfishSchemaInfo (Private->RedfishService, Private->JsonS= tructProtocol, Uri, &SchemaInfo); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to get schema information from: %s %r= \n", __FUNCTION__, Uri, Status)); + return Status; + } + + // + // Check and see if this is target resource that we want to handle. + // Some resource is handled by other provider so we have to make sure th= is first. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%s Identify for %s\n", __FUNCTION__, Uri))= ; + ConfigLang =3D RedfishGetConfigLanguage (Uri); + if (ConfigLang =3D=3D NULL) { + Status =3D EdkIIRedfishResourceConfigIdentify (&SchemaInfo, Uri, Priva= te->InformationExchange); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_INFO, "%a, \"%s\" is not handled by us\n", __FUNCTIO= N__, Uri)); + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_ERROR, "%a, fail to identify resource: \"%s\": %r\n", = __FUNCTION__, Uri, Status)); + return Status; + } + } else { + DEBUG ((REDFISH_DEBUG_TRACE, "%a, history record found: %s\n", __FUNCT= ION__, ConfigLang)); + // + // Set exchange information + // + Status =3D GetArrayIndexFromArrayTypeConfigureLang (ConfigLang, &Retur= nedConfigLang, &Index); + if (!EFI_ERROR (Status) || (Status =3D=3D EFI_NOT_FOUND)) { + Private->InformationExchange->ReturnedInformation.Type = =3D InformationTypeCollectionMemberConfigLanguage; + Private->InformationExchange->ReturnedInformation.ConfigureLanguageL= ist.Count =3D 1; + Private->InformationExchange->ReturnedInformation.ConfigureLanguageL= ist.List =3D + AllocateZeroPool (sizeof (REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG))= ; + + if (Private->InformationExchange->ReturnedInformation.ConfigureLangu= ageList.List =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for REDFISH_FEAT= URE_ARRAY_TYPE_CONFIG_LANG.\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + Private->InformationExchange->ReturnedInformation.ConfigureLanguageL= ist.List[0].Index =3D Index; + Private->InformationExchange->ReturnedInformation.ConfigureLanguageL= ist.List[0].ConfigureLang =3D + (EFI_STRING)AllocateCopyPool (StrSize (ReturnedConfigLang), (VOID = *)ReturnedConfigLang); + } else { + DEBUG ((DEBUG_ERROR, "%a, GetArrayIndexFromArrayTypeConfigureLang fa= il: %r\n", __FUNCTION__, Status)); + } + + FreePool (ConfigLang); + } + + // + // Check and see if target property exist or not even when collection me= meber exists. + // If not, we sill do provision. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __FUNCTION__, Uri)); + Status =3D EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + // + // The target property does not exist, do the provision to create prop= erty. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a provision for %s\n", __FUNCTION__, Ur= i)); + Status =3D EdkIIRedfishResourceConfigProvisionging (&SchemaInfo, Uri, = Private->InformationExchange, FALSE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to provision with GET mode: %r\n", = __FUNCTION__, Status)); + } + + return Status; + } + + // + // Consume first. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a consume for %s\n", __FUNCTION__, Uri)); + Status =3D EdkIIRedfishResourceConfigConsume (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to consume resoruce for: %s: %r\n", _= _FUNCTION__, Uri, Status)); + } + + // + // Patch. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a update for %s\n", __FUNCTION__, Uri)); + Status =3D EdkIIRedfishResourceConfigUpdate (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to update resoruce for: %s: %r\n", __= FUNCTION__, Uri, Status)); + } + + return Status; +} + +EFI_STATUS +HandleCollectionResource ( + IN REDFISH_COLLECTION_PRIVATE *Private + ) +{ + EFI_STATUS Status; + EFI_REDFISH_COMPUTERSYSTEMCOLLECTION *Collection; + EFI_REDFISH_COMPUTERSYSTEMCOLLECTION_CS *CollectionCs; + RedfishCS_Link *List; + RedfishCS_Header *Header; + RedfishCS_Type_Uri_Data *UriData; + EFI_STRING MemberUri; + + if (Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if ((Private->JsonStructProtocol =3D=3D NULL) || (Private->CollectionJso= n =3D=3D NULL)) { + return EFI_NOT_READY; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, process collection for: %s\n", __FUNCT= ION__, Private->CollectionUri)); + + // + // Convert JSON text to C structure. + // + Status =3D Private->JsonStructProtocol->ToStructure ( + Private->JsonStructProtocol, + NULL, + Private->CollectionJson, + (EFI_REST_JSON_STRUCTURE_HEADER = **)&Collection + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n", __FUNCTION__, S= tatus)); + return Status; + } + + CollectionCs =3D Collection->ComputerSystemCollection; + + if (*CollectionCs->Membersodata_count =3D=3D 0) { + return EFI_NOT_FOUND; + } + + if (IsLinkEmpty (&CollectionCs->Members)) { + return EFI_NOT_FOUND; + } + + List =3D GetFirstLink (&CollectionCs->Members); + while (TRUE) { + Header =3D (RedfishCS_Header *)List; + if (Header->ResourceType =3D=3D RedfishCS_Type_Uri) { + UriData =3D (RedfishCS_Type_Uri_Data *)Header; + MemberUri =3D NULL; + MemberUri =3D StrAsciiToUnicode (UriData->Uri); + ASSERT (MemberUri !=3D NULL); + if (MemberUri !=3D NULL) { + Status =3D HandleResource (Private, MemberUri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, process ComputerSystemCollection resou= rce: %a failed: %r\n", __FUNCTION__, UriData->Uri, Status)); + } + + FreePool (MemberUri); + } + } + + if (IsLinkAtEnd (&CollectionCs->Members, List)) { + break; + } + + List =3D GetNextLink (&CollectionCs->Members, List); + } + + // + // Release resource. + // + Private->JsonStructProtocol->DestoryStructure (Private->JsonStructProtoc= ol, (EFI_REST_JSON_STRUCTURE_HEADER *)Collection); + + return EFI_SUCCESS; +} + +EFI_STATUS +CreateCollectionResource ( + IN REDFISH_COLLECTION_PRIVATE *Private + ) +{ + EFI_STATUS Status; + REDFISH_SCHEMA_INFO SchemaInfo; + + if (Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, create resource for collection for: %s= \n", __FUNCTION__, Private->CollectionUri)); + + Status =3D GetSupportedSchemaVersion (REDFISH_SCHEMA_NAME, &SchemaInfo); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to find supported schema from HII dat= abase: %r\n", __FUNCTION__, Status)); + return Status; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, supported schema: %a %a.%a.%a\n", __FU= NCTION__, SchemaInfo.Schema, SchemaInfo.Major, SchemaInfo.Minor, SchemaInfo= .Errata)); + + Status =3D EdkIIRedfishResourceConfigProvisionging (&SchemaInfo, Private= ->CollectionUri, Private->InformationExchange, TRUE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to create resoruce for: %s: %r\n", __= FUNCTION__, Private->CollectionUri, Status)); + } + + return Status; +} + +EFI_STATUS +ReleaseCollectionResource ( + IN REDFISH_COLLECTION_PRIVATE *Private + ) +{ + if (Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Release resource + // + if (Private->RedResponse.Payload !=3D NULL) { + RedfishFreeResponse ( + Private->RedResponse.StatusCode, + Private->RedResponse.HeaderCount, + Private->RedResponse.Headers, + Private->RedResponse.Payload + ); + Private->RedResponse.StatusCode =3D NULL; + Private->RedResponse.HeaderCount =3D 0; + Private->RedResponse.Headers =3D NULL; + Private->RedResponse.Payload =3D NULL; + } + + if (Private->CollectionJson !=3D NULL) { + FreePool (Private->CollectionJson); + Private->CollectionJson =3D NULL; + } + + if (Private->RedfishVersion !=3D NULL) { + FreePool (Private->RedfishVersion); + Private->RedfishVersion =3D NULL; + } + + return EFI_SUCCESS; +} + +EFI_STATUS +CollectionHandler ( + IN REDFISH_COLLECTION_PRIVATE *Private + ) +{ + EFI_STATUS Status; + + if (Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, collection handler for %s\n", __FUNCTI= ON__, Private->CollectionUri)); + + // + // Query collection from Redfish service. + // + Status =3D GetResourceByUri (Private->RedfishService, Private->Collectio= nUri, &Private->RedResponse); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, unable to get resource from: %s :%r\n", __FU= NCTION__, Private->CollectionUri, Status)); + goto ON_RELEASE; + } + + Private->CollectionPayload =3D Private->RedResponse.Payload; + ASSERT (Private->CollectionPayload !=3D NULL); + + Private->CollectionJson =3D JsonDumpString (RedfishJsonInPayload (Privat= e->CollectionPayload), EDKII_JSON_COMPACT); + ASSERT (Private->CollectionJson !=3D NULL); + + Status =3D HandleCollectionResource (Private); + if (EFI_ERROR (Status) && (Status =3D=3D EFI_NOT_FOUND)) { + Status =3D CreateCollectionResource (Private); + } + +ON_RELEASE: + + ReleaseCollectionResource (Private); + + return Status; +} + +/** + The callback function provided by Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROT= OCOL instance. + @param[in] FeatureAction The action Redfish feature driver sho= uld take. + @param[in] Uri The collection URI. + @param[in] Context The context of Redfish feature driver= . + @param[in,out] InformationExchange The pointer to RESOURCE_INFORMATION_E= XCHANGE + + @retval EFI_SUCCESS Redfish feature driver callback is exec= uted successfully. + @retval Others Some errors happened. + + @retval EFI_SUCCESS Redfish feature driver callback is exec= uted successfully. + @retval Others Some errors happened. + +**/ +EFI_STATUS +EFIAPI +RedfishCollectionFeatureCallback ( + IN EDKII_REDFISH_FEATURE_PROTOCOL *This, + IN FEATURE_CALLBACK_ACTION FeatureAction, + IN VOID *Context, + IN OUT RESOURCE_INFORMATION_EXCHANGE *InformationExchange + ) +{ + EFI_STATUS Status; + REDFISH_SERVICE RedfishService; + REDFISH_COLLECTION_PRIVATE *Private; + EFI_STRING ResourceUri; + + if (FeatureAction !=3D CallbackActionStartOperation) { + return EFI_UNSUPPORTED; + } + + Private =3D (REDFISH_COLLECTION_PRIVATE *)Context; + + RedfishService =3D Private->RedfishService; + if (RedfishService =3D=3D NULL) { + return EFI_NOT_READY; + } + + // + // Save in private structure. + // + Private->InformationExchange =3D InformationExchange; + + // + // Find Redfish version on BMC + // + Private->RedfishVersion =3D RedfishGetVersion (RedfishService); + + // + // Create the full URI from Redfish service root. + // + ResourceUri =3D (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH * sizeof (C= HAR16)); + if (ResourceUri =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for full URI.\n", __= FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + StrCatS (ResourceUri, MAX_URI_LENGTH, Private->RedfishVersion); + StrCatS (ResourceUri, MAX_URI_LENGTH, InformationExchange->SendInformati= on.FullUri); + + // + // Initialize collection path + // + Private->CollectionUri =3D RedfishGetUri (ResourceUri); + if (Private->CollectionUri =3D=3D NULL) { + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; + } + + Status =3D CollectionHandler (Private); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, CollectionHandler failure: %r\n", __FUNCTION= __, Status)); + } + + return EFI_SUCCESS; +} + +/** + Initialize a Redfish configure handler. + + This function will be called by the Redfish config driver to initialize = each Redfish configure + handler. + + @param[in] This Pointer to EDKII_REDFISH_CONFIG_HA= NDLER_PROTOCOL instance. + @param[in] RedfishConfigServiceInfo Redfish service informaion. + + @retval EFI_SUCCESS The handler has been initialized su= ccessfully. + @retval EFI_DEVICE_ERROR Failed to create or configure the R= EST EX protocol instance. + @retval EFI_ALREADY_STARTED This handler has already been initi= alized. + @retval Other Error happens during the initializa= tion. + +**/ +EFI_STATUS +EFIAPI +RedfishCollectionInit ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This, + IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo + ) +{ + REDFISH_COLLECTION_PRIVATE *Private; + + Private =3D REDFISH_COLLECTION_PRIVATE_DATA_FROM_PROTOCOL (This); + + Private->RedfishService =3D RedfishCreateService (RedfishConfigServiceIn= fo); + if (Private->RedfishService =3D=3D NULL) { + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + +/** + Stop a Redfish configure handler. + + @param[in] This Pointer to EDKII_REDFISH_CONFIG_HANDLER= _PROTOCOL instance. + + @retval EFI_SUCCESS This handler has been stoped successful= ly. + @retval Others Some error happened. + +**/ +EFI_STATUS +EFIAPI +RedfishCollectionStop ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This + ) +{ + REDFISH_COLLECTION_PRIVATE *Private; + + Private =3D REDFISH_COLLECTION_PRIVATE_DATA_FROM_PROTOCOL (This); + + if (Private->RedfishService !=3D NULL) { + RedfishCleanupService (Private->RedfishService); + Private->RedfishService =3D NULL; + } + + ReleaseCollectionResource (Private); + + if (Private->FeatureProtocol !=3D NULL) { + Private->FeatureProtocol->Unregister ( + Private->FeatureProtocol, + REDFISH_MANAGED_URI, + NULL + ); + } + + return EFI_SUCCESS; +} + +/** + Callback function when gEfiRestJsonStructureProtocolGuid is installed. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +EfiRestJasonStructureProtocolIsReady ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + if (mRedfishCollectionPrivate =3D=3D NULL) { + return; + } + + if (mRedfishCollectionPrivate->JsonStructProtocol !=3D NULL) { + return; + } + + Status =3D gBS->LocateProtocol ( + &gEfiRestJsonStructureProtocolGuid, + NULL, + (VOID **)&mRedfishCollectionPrivate->JsonStructProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to locate gEfiRestJsonStructureProtoc= olGuid: %r\n", __FUNCTION__, Status)); + } + + gBS->CloseEvent (Event); +} + +/** + Callback function when gEdkIIRedfishFeatureProtocolGuid is installed. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +EdkIIRedfishFeatureProtocolIsReady ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EDKII_REDFISH_FEATURE_PROTOCOL *FeatureProtocol; + + if (mRedfishCollectionPrivate =3D=3D NULL) { + return; + } + + if (mRedfishCollectionPrivate->FeatureProtocol !=3D NULL) { + return; + } + + Status =3D gBS->LocateProtocol ( + &gEdkIIRedfishFeatureProtocolGuid, + NULL, + (VOID **)&FeatureProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to locate gEdkIIRedfishFeatureProtoco= lGuid: %r\n", __FUNCTION__, Status)); + gBS->CloseEvent (Event); + return; + } + + Status =3D FeatureProtocol->Register ( + FeatureProtocol, + REDFISH_MANAGED_URI, + RedfishCollectionFeatureCallback, + (VOID *)mRedfishCollectionPrivate + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to register %s: %r\n", __FUNCTION__, = REDFISH_MANAGED_URI, Status)); + } + + mRedfishCollectionPrivate->FeatureProtocol =3D FeatureProtocol; + + gBS->CloseEvent (Event); +} + +/** + Unloads an image. + + @param ImageHandle Handle that identifies the image to be unl= oaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +RedfishCollectionUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler; + + if (mRedfishCollectionPrivate =3D=3D NULL) { + return EFI_NOT_READY; + } + + ConfigHandler =3D NULL; + + // + // Firstly, find ConfigHandler Protocol interface in this ImageHandle. + // + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + (VOID **)&ConfigHandler, + NULL, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (EFI_ERROR (Status) || (ConfigHandler =3D=3D NULL)) { + return Status; + } + + ConfigHandler->Stop (ConfigHandler); + + // + // Last, uninstall ConfigHandler Protocol. + // + Status =3D gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + ConfigHandler, + NULL + ); + + FreePool (mRedfishCollectionPrivate); + mRedfishCollectionPrivate =3D NULL; + + return Status; +} + +EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL mRedfishConfigHandler =3D { + RedfishCollectionInit, + RedfishCollectionStop +}; + +/** + This is the declaration of an EFI image entry point. This entry point is + the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers includ= ing + both device drivers and bus drivers. It initialize the global variables = and + publish the driver binding protocol. + + @param[in] ImageHandle The firmware allocated handle for the UEFI= image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_ACCESS_DENIED EFI_ISCSI_INITIATOR_NAME_PROTOCOL was inst= alled unexpectedly. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +EFIAPI +RedfishCollectionEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *Registration; + + if (mRedfishCollectionPrivate !=3D NULL) { + return EFI_ALREADY_STARTED; + } + + mRedfishCollectionPrivate =3D AllocateZeroPool (sizeof (REDFISH_COLLECTI= ON_PRIVATE)); + CopyMem (&mRedfishCollectionPrivate->ConfigHandler, &mRedfishConfigHandl= er, sizeof (EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL)); + + Status =3D gBS->InstallProtocolInterface ( + &ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + EFI_NATIVE_INTERFACE, + &mRedfishCollectionPrivate->ConfigHandler + ); + + EfiCreateProtocolNotifyEvent ( + &gEfiRestJsonStructureProtocolGuid, + TPL_CALLBACK, + EfiRestJasonStructureProtocolIsReady, + NULL, + &Registration + ); + + EfiCreateProtocolNotifyEvent ( + &gEdkIIRedfishFeatureProtocolGuid, + TPL_CALLBACK, + EdkIIRedfishFeatureProtocolIsReady, + NULL, + &Registration + ); + + return Status; +} diff --git a/RedfishClientPkg/RedfishClient.fdf.inc b/RedfishClientPkg/Redf= ishClient.fdf.inc index 5c4b9670..7d5de565 100644 --- a/RedfishClientPkg/RedfishClient.fdf.inc +++ b/RedfishClientPkg/RedfishClient.fdf.inc @@ -16,6 +16,7 @@ INF RedfishClientPkg/RedfishConfigLangMapDxe/RedfishConfigLangMapDxe.inf INF RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf INF RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.in= f + INF RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystem= CollectionDxe.inf =20 !include RedfishClientPkg/RedfishJsonStructureDxe.fdf.inc # @@ -23,4 +24,5 @@ # INF RedfishClientPkg/Converter/Memory/v1_7_1/RedfishMemory_V1_7_1_Dxe.in= f INF RedfishClientPkg/Converter/MemoryCollection/RedfishMemoryCollection_= Dxe.inf + INF RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerS= ystemCollection_Dxe.inf !endif --=20 2.17.1