From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 50EA27803D7 for ; Tue, 14 May 2024 12:38:45 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=PpjeyVIuHuqyOenregtYiyq8pUwgCvXhUvMbkFO7fow=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1715690323; v=1; b=okyPFG1H6fIw3GqvukKv4koiK2PMIkZAynrElBDchhh5d35RJNsA0zav0C6TFHBxZSDphMEm C42dAJiQZGNaSU77AndkbDxm+pcd+nwH2tBNnN88ypZ2TuXwJ5OijSqbUcV93eQEklY/lwMp/Iz xz363yE2/7Ue/min2I+WRKbPwiUC0v+TxyWiWjeEdMQWHlhTqX1pH4GQs1tcQ+W+nRKHp+dwgdM EOXuwL1cDD/mFKCio8SlzPVnCLQ6brsslY8fzW2G/zJh9RMc9YhiKHu4ch0bJPHJUohhKbqQFRs AH2L7/hpiui35psWtAoZ9PiarOM9nIyvQ24aaRyt7C9Ag== X-Received: by 127.0.0.2 with SMTP id VzOuYY7687511xrUel5zAcEu; Tue, 14 May 2024 05:38:43 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.81]) by mx.groups.io with SMTP id smtpd.web10.14306.1715690322543707723 for ; Tue, 14 May 2024 05:38:42 -0700 X-Received: from BLAPR03CA0166.namprd03.prod.outlook.com (2603:10b6:208:32f::18) by SN7PR12MB7024.namprd12.prod.outlook.com (2603:10b6:806:26e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Tue, 14 May 2024 12:38:38 +0000 X-Received: from BL6PEPF00022574.namprd02.prod.outlook.com (2603:10b6:208:32f:cafe::89) by BLAPR03CA0166.outlook.office365.com (2603:10b6:208:32f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.25 via Frontend Transport; Tue, 14 May 2024 12:38:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.161) by BL6PEPF00022574.mail.protection.outlook.com (10.167.249.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.21 via Frontend Transport; Tue, 14 May 2024 12:38:38 +0000 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 14 May 2024 05:38:18 -0700 X-Received: from NV-CL38DL3.nvidia.com (10.126.230.35) 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.1544.4; Tue, 14 May 2024 05:38:17 -0700 From: "Nickle Wang via groups.io" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-devel] [edk2-redfish-client][PATCH v2] RedfishClientPkg: introduce RedfishBootstrapAccountDxe Date: Tue, 14 May 2024 20:38:10 +0800 Message-ID: <20240514123810.28086-1-nicklew@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00022574:EE_|SN7PR12MB7024:EE_ X-MS-Office365-Filtering-Correlation-Id: e51e1fb8-4aa3-468a-9003-08dc7412c79f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Z1PC2PazFBhyF2ANzPC7ja9SGr5CJPCnRJafxuNPxyHhv5CnfrYlnQ25nCFu?= =?us-ascii?Q?Yn/Z/IPUJcO4/idhT1dCYtzkPTdQqHDCPWvx0VcPnwSRigqwABKB4rPCQJqp?= =?us-ascii?Q?6fSZC/35AC2SKQf6NzaUVVpB0TBa2btNQKzxiKrRjZw5+lmIdOrzP2m4JchC?= =?us-ascii?Q?VB601ELea0pal4304DpKq+rjiTvGTcLaZ3XwFZLvknEGjb5nWrQtXJg3RDiB?= =?us-ascii?Q?3B/DOp3T8LNOfT694Gux1kZViyKeE4FCVqgWdAZmj7M5uooT2tWPqjwt687k?= =?us-ascii?Q?t054BZT9c/06dneV0qfe5xZZ5csNESpf3uLOmbv3Xf2RbS5D066E1vnk5k4r?= =?us-ascii?Q?nkrx1QFXUk7JRLJC1E/CgusBJti6ZGa/IwfClGz16KpRPmM/OFCe7oZL1tCy?= =?us-ascii?Q?XQFkPu0r5+jo84v4mQViuWIyFw5LrAFdjovyez4AmE9U0l2f7J6t32y3pvIx?= =?us-ascii?Q?i3jduyWQ2wdEaFC03lm5gthqNNBYyK/3c66qwxA0aLsso0o5VVmzOyMYaiZ7?= =?us-ascii?Q?CnY9RntjMyJ0LYQwfNTWjumClrBLV9x0s5NOx+8Vq7z8Czay2/i6FwkuXMOQ?= =?us-ascii?Q?+2DMAXS1Sk8a7mCS63dLP+IEsAfTnqR8lb+ZErYDVb4IYftcGFjolPRev7/R?= =?us-ascii?Q?e9L7Tcievi9Y3DXcmHVHHpJs5UgKuElwbMzMQdWB0r91JAwvnr0rFeP8Tajz?= =?us-ascii?Q?q9+kfGq+eziQAq5sxw+wDwlncsf2nJdoCqcK275EEwmPoZ5KE8AF3w/bU68W?= =?us-ascii?Q?RgdPNb8D0OpHxXbSf/OBcFnv/i3w5FCUNmBRVaw3BZK+/JPjlQuz/aZpBsAj?= =?us-ascii?Q?NuUwuw80JDe/ME5KKe9On675igbWH1Ubk9USah+gI4LQdVPgioiziz2qcVAF?= =?us-ascii?Q?W6C1kbYXFUMfe0MGYgr72uYrikmgMktniBFHsWTy1/9iLE9vHfZUIEbQuGw/?= =?us-ascii?Q?P56LgqO3FQbjRn/LaCVpUNOsdiACPorcWVWK+k296raI99XRimWYSRn3id8u?= =?us-ascii?Q?4TCrQxSbggewOATyVmwhN2HXNmLw8Uej5/W8z2XIJ/Ux94R9/aKPtEXrpmSI?= =?us-ascii?Q?dhqeJvoFlJN60qVtNjEZPEOQhEqlQyPZHQfPirs0mOKNIQsvX/LTGSlMGOCK?= =?us-ascii?Q?1y5/Hv/pka/Is0Bwp2c2iPw8/xDJZQoiIemZb8/5BWPUYV5OZRPU1oLYN8Du?= =?us-ascii?Q?YK+SOW0ejUWsY+vTSemuBzOGpy9qW7wJEk5GNfSO/VeufQurU94BLS4U201s?= =?us-ascii?Q?MkuTWMP1sevhrpuZujBxapmUbvFnRNBv7EI4EP/sCNy5hz/X2Llz1Mm0li71?= =?us-ascii?Q?C3Lsqf/UqcNg3Ra64gyDGkKdt0gNakhoAgZUwzhT0+4VNidd0Bd2ndKuBmmy?= =?us-ascii?Q?CTF8K+QzW43tcct4lUOtYyiPnh5l?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 12:38:38.5092 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e51e1fb8-4aa3-468a-9003-08dc7412c79f 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00022574.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7024 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Tue, 14 May 2024 05:38:42 -0700 Resent-From: nicklew@nvidia.com Reply-To: devel@edk2.groups.io,nicklew@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: TjfAlFpAxjhO5Gjt1Nt797lzx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Spam-Flag: yes X-Spam-Level: ************ X-GND-Spam-Score: 190 X-GND-Status: SPAM Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=okyPFG1H; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io -Introduce RedfishBootstrapAccountDxe to delete bootstrap account from /redfish/v1/AccountService/Accounts after BIOS finished all Redfish jobs. The bootstrap account won't be available to other application. So deleting bootstrap account helps to release resource at BMC. - After bootstrap account is deleted at BMC, the Redfish service instance is no longer usable. Close Redfish service instance to release the HTTP connection between BIOS and BMC. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- .../RedfishClientComponents.dsc.inc | 1 + .../RedfishBootstrapAccountDxe.inf | 53 +++ .../RedfishBootstrapAccountDxe.h | 58 +++ .../RedfishBootstrapAccountDxe.c | 337 ++++++++++++++++++ RedfishClientPkg/RedfishClient.fdf.inc | 1 + 5 files changed, 450 insertions(+) create mode 100644 RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBoot= strapAccountDxe.inf create mode 100644 RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBoot= strapAccountDxe.h create mode 100644 RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBoot= strapAccountDxe.c diff --git a/RedfishClientPkg/RedfishClientComponents.dsc.inc b/RedfishClie= ntPkg/RedfishClientComponents.dsc.inc index 42fc0c299..fe5248b62 100644 --- a/RedfishClientPkg/RedfishClientComponents.dsc.inc +++ b/RedfishClientPkg/RedfishClientComponents.dsc.inc @@ -20,6 +20,7 @@ RedfishClientPkg/HiiToRedfishMemoryDxe/HiiToRedfishMemoryDxe.inf RedfishClientPkg/HiiToRedfishBootDxe/HiiToRedfishBootDxe.inf RedfishClientPkg/HiiToRedfishBiosDxe/HiiToRedfishBiosDxe.inf + RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAccountDxe.i= nf !endif # # Below two modules should be pulled in by build tool. diff --git a/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAc= countDxe.inf b/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrap= AccountDxe.inf new file mode 100644 index 000000000..4073e95f4 --- /dev/null +++ b/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAccountDx= e.inf @@ -0,0 +1,53 @@ +## @file +# This driver deletes bootstrap account in BMC after BIOS Redfish finishe= d +# all jobs +# +# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001000b + BASE_NAME =3D RedfishBootstrapAccountDxe + FILE_GUID =3D 87555253-2F7E-45FC-B469-FD35B2E51210 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D RedfishBootstrapAccountEntryPoint + UNLOAD_IMAGE =3D RedfishBootstrapAccountUnload + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[Sources] + RedfishBootstrapAccountDxe.h + RedfishBootstrapAccountDxe.c + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PrintLib + RedfishEventLib + RedfishFeatureUtilityLib + RedfishDebugLib + RedfishVersionLib + RedfishHttpLib + UefiLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEdkIIRedfishConfigHandlerProtocolGuid ## CONSUMES ## + gEdkIIRedfishCredentialProtocolGuid ## CONSUMES ## + gEfiRestExProtocolGuid ## CONSUMES ## + +[Depex] + gEdkIIRedfishCredentialProtocolGuid diff --git a/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAc= countDxe.h b/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAc= countDxe.h new file mode 100644 index 000000000..5262f1e6b --- /dev/null +++ b/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAccountDx= e.h @@ -0,0 +1,58 @@ +/** @file + Common header file for RedfishBootstrapAccountDxe driver. + + (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REDFISH_BOOTSTRAP_ACCOUNT_DXE_H_ +#define REDFISH_BOOTSTRAP_ACCOUNT_DXE_H_ + +#include +#include + +// +// Libraries +// +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define REDFISH_BOOTSTRAP_ACCOUNT_DEBUG DEBUG_VERBOSE +#define REDFISH_MANAGER_ACCOUNT_COLLECTION_URI L"AccountService/Accounts" +#define REDFISH_URI_LENGTH 128 + +// +// Definitions of REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE +// +typedef struct { + EFI_HANDLE ImageHandle; + EFI_HANDLE RestExHandle; + REDFISH_SERVICE RedfishService; + EFI_EVENT RedfishEvent; + EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL Protocol; +} REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE; + +#define REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE_FROM_PROTOCOL(This) \ + BASE_CR ((This), REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE, Protocol) + +#endif diff --git a/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAc= countDxe.c b/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAc= countDxe.c new file mode 100644 index 000000000..8944bea4b --- /dev/null +++ b/RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAccountDx= e.c @@ -0,0 +1,337 @@ +/** @file + This driver deletes bootstrap account in BMC after BIOS Redfish finished + all jobs. + + (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "RedfishBootstrapAccountDxe.h" + +REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE *mBootstrapPrivate =3D NULL; + +/** + Close Redfish service instance by calling RestEx protocol to release ins= tance. + + @param[in] RestExHandle Handle of RestEx protocol. + + @retval EFI_SUCCESS The Redfish service is closed successfully= . + @retval EFI_INVALID_PARAMETER RestExHandle is NULL. + @retval Others Error occurs. + +**/ +EFI_STATUS +CloseRedfishService ( + IN EFI_HANDLE RestExHandle + ) +{ + EFI_REST_EX_PROTOCOL *RestEx; + EFI_STATUS Status; + + if (RestExHandle =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Status =3D gBS->HandleProtocol ( + RestExHandle, + &gEfiRestExProtocolGuid, + (VOID **)&RestEx + ); + if (!EFI_ERROR (Status)) { + Status =3D RestEx->Configure (RestEx, NULL); + DEBUG ((REDFISH_BOOTSTRAP_ACCOUNT_DEBUG, "%a: release RestEx instance:= %r\n", __func__, Status)); + } + + return Status; +} + +/** + Callback function executed when the AfterProvisioning event group is sig= naled. + + @param[in] Event Event whose notification function is being invoked= . + @param[out] Context Pointer to the Context buffer + +**/ +VOID +EFIAPI +RedfishBootstrapAccountOnRedfishAfterProvisioning ( + IN EFI_EVENT Event, + OUT VOID *Context + ) +{ + EFI_STATUS Status; + REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE *Private; + EDKII_REDFISH_CREDENTIAL_PROTOCOL *credentialProtocol; + EDKII_REDFISH_AUTH_METHOD AuthMethod; + CHAR8 *AccountName; + CHAR8 *AccountCredential; + CHAR16 TargetUri[REDFISH_URI_LENGTH]; + CHAR16 *RedfishVersion; + REDFISH_RESPONSE RedfishResponse; + + RedfishVersion =3D NULL; + + Private =3D (REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE *)Context; + if ((Private =3D=3D NULL) || (Private->RedfishService =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "%a: Redfish service is not available\n", __func_= _)); + return; + } + + // + // Locate Redfish Credential Protocol to get credential for + // accessing to Redfish service. + // + Status =3D gBS->LocateProtocol ( + &gEdkIIRedfishCredentialProtocolGuid, + NULL, + (VOID **)&credentialProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((REDFISH_BOOTSTRAP_ACCOUNT_DEBUG, "%a: No Redfish Credential Pr= otocol is installed on system.", __func__)); + return; + } + + // + // This won't create new bootstrapping account at BMC. + // The RedfishPlatformCredentialIpmiLib under RedfishPkg keeps + // bootstrapping account in UEFI variable for the use during boot time. + // And this variable gets deleted at exit-boot-service event. + // We read this cached bootstrapping account here and delete this + // account at BMC side. So, no bootstrapping account stays in both + // BMC and host side after host boots into OS. + // + Status =3D credentialProtocol->GetAuthInfo ( + credentialProtocol, + &AuthMethod, + &AccountName, + &AccountCredential + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: can not get bootstrap account information: %= r\n", __func__, Status)); + return; + } + + // + // Carving the URI + // + RedfishVersion =3D RedfishGetVersion (Private->RedfishService); + if (RedfishVersion =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: can not get Redfish version\n", __func__)); + return; + } + + UnicodeSPrint (TargetUri, (sizeof (CHAR16) * REDFISH_URI_LENGTH), L"%s%s= /%a", RedfishVersion, REDFISH_MANAGER_ACCOUNT_COLLECTION_URI, AccountName); + + DEBUG ((REDFISH_BOOTSTRAP_ACCOUNT_DEBUG, "%a: bootstrap account: %a\n= ", __func__, AccountName)); + DEBUG ((REDFISH_BOOTSTRAP_ACCOUNT_DEBUG, "%a: bootstrap credential: %a\n= ", __func__, AccountCredential)); + DEBUG ((REDFISH_BOOTSTRAP_ACCOUNT_DEBUG, "%a: bootstrap URI: %s\n= ", __func__, TargetUri)); + + // + // Remove bootstrap account at /redfish/v1/AccountService/Account + // + ZeroMem (&RedfishResponse, sizeof (REDFISH_RESPONSE)); + Status =3D RedfishHttpDeleteResource ( + Private->RedfishService, + TargetUri, + &RedfishResponse + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: can not remove bootstrap account at BMC: %r"= , __func__, Status)); + DumpRedfishResponse (__func__, DEBUG_ERROR, &RedfishResponse); + } else { + DEBUG ((REDFISH_BOOTSTRAP_ACCOUNT_DEBUG, "%a: bootstrap account: %a is= removed from: %s\n", __func__, AccountName, REDFISH_MANAGER_ACCOUNT_COLLEC= TION_URI)); + } + + // + // Clean credential + // + ZeroMem (AccountName, AsciiStrSize (AccountName)); + ZeroMem (AccountCredential, AsciiStrSize (AccountCredential)); + + // + // Since the bootstrap account is deleted at BMC, the Redfish service in= stance is no longer usable. + // Close Redfish service instance to release the HTTP connection between= BIOS and BMC. + // + Status =3D CloseRedfishService (Private->RestExHandle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: cannot close Redfish service instance: %r\n"= , __func__, Status)); + } + + RedfishHttpFreeResponse (&RedfishResponse); + + return; +} + +/** + 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 informaiton. + + @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 +RedfishBootstrapAccountInit ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This, + IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo + ) +{ + REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE *Private; + + Private =3D REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE_FROM_PROTOCOL (This); + + Private->RedfishService =3D RedfishCreateService (RedfishConfigServiceIn= fo); + if (Private->RedfishService =3D=3D NULL) { + return EFI_DEVICE_ERROR; + } + + Private->RestExHandle =3D RedfishConfigServiceInfo->RedfishServiceRestEx= Handle; + + 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 +RedfishBootstrapAccountStop ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This + ) +{ + REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE *Private; + + Private =3D REDFISH_BOOTSTRAP_ACCOUNT_PRIVATE_FROM_PROTOCOL (This); + + if (Private->RedfishService !=3D NULL) { + RedfishCleanupService (Private->RedfishService); + Private->RedfishService =3D NULL; + } + + return EFI_SUCCESS; +} + +EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL mRedfishConfigHandler =3D { + RedfishBootstrapAccountInit, + RedfishBootstrapAccountStop +}; + +/** + Unloads an image. + + @param[in] ImageHandle Handle that identifies the image to be= unloaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +RedfishBootstrapAccountUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + + if (mBootstrapPrivate =3D=3D NULL) { + return EFI_SUCCESS; + } + + if (mBootstrapPrivate->RedfishEvent !=3D NULL) { + gBS->CloseEvent (mBootstrapPrivate->RedfishEvent); + } + + Status =3D gBS->UninstallProtocolInterface ( + mBootstrapPrivate->ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + (VOID *)&mBootstrapPrivate->Protocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: can not uninstall Redfish config handler pro= tocol: %r\n", __func__, Status)); + } + + FreePool (mBootstrapPrivate); + mBootstrapPrivate =3D NULL; + + return EFI_SUCCESS; +} + +/** + 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. + + @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 Others An unexpected error occurred. +**/ +EFI_STATUS +EFIAPI +RedfishBootstrapAccountEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + if (mBootstrapPrivate !=3D NULL) { + return EFI_ALREADY_STARTED; + } + + mBootstrapPrivate =3D AllocateZeroPool (sizeof (REDFISH_BOOTSTRAP_ACCOUN= T_PRIVATE)); + if (mBootstrapPrivate =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (&mBootstrapPrivate->Protocol, &mRedfishConfigHandler, sizeof (E= DKII_REDFISH_CONFIG_HANDLER_PROTOCOL)); + Status =3D gBS->InstallProtocolInterface ( + &ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + EFI_NATIVE_INTERFACE, + &mBootstrapPrivate->Protocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: can not install Redfish config handler proto= col: %r\n", __func__, Status)); + goto ON_ERROR; + } + + // + // Register after provisioning event to remove bootstrap account. + // + Status =3D CreateAfterProvisioningEvent ( + RedfishBootstrapAccountOnRedfishAfterProvisioning, + (VOID *)mBootstrapPrivate, + &mBootstrapPrivate->RedfishEvent + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: failed to register after-provisioning event:= %r\n", __func__, Status)); + goto ON_ERROR; + } + + return EFI_SUCCESS; + +ON_ERROR: + + RedfishBootstrapAccountUnload (ImageHandle); + + return Status; +} diff --git a/RedfishClientPkg/RedfishClient.fdf.inc b/RedfishClientPkg/Redf= ishClient.fdf.inc index 154f641b2..47e5093f2 100644 --- a/RedfishClientPkg/RedfishClient.fdf.inc +++ b/RedfishClientPkg/RedfishClient.fdf.inc @@ -15,6 +15,7 @@ INF RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.inf INF RedfishClientPkg/RedfishETagDxe/RedfishETagDxe.inf INF RedfishClientPkg/RedfishConfigLangMapDxe/RedfishConfigLangMapDxe.inf + INF RedfishClientPkg/RedfishBootstrapAccountDxe/RedfishBootstrapAccountD= xe.inf INF RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf INF RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.in= f INF RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDx= e.inf --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118889): https://edk2.groups.io/g/devel/message/118889 Mute This Topic: https://groups.io/mt/106093445/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-