From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web11.14905.1658885895517713174 for ; Tue, 26 Jul 2022 18:38:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=edXAZvzm; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0207a15765=nickle.wang@hpe.com) Received: from pps.filterd (m0134424.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26R1SYGW004808; Wed, 27 Jul 2022 01:38:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pps0720; bh=WUrgYAnhmeztkRQ6HgZIbuak9CTnxsbly2SZl4VNy24=; b=edXAZvzmFjO0Z0QjNeD2t6DwZP0f5210g/a3bEaZhL/8QSr0zZbgNON9rJGIWEXBHtbC b5J4tPGYaTc1ygy80rTfloUvAx5HhiRMVttW6S8C6n/Q81nw41JG2DyJS/UQK/daljEL jfsnd0F0n4iO+/7jqedGPwrwJtGLGZ3LjyY0GNi+g5y8XyKk5Xlsz2i47znRzdPcxFTr 7FysycRCmlhJgOj4MdPgdaH8lEDIqMlZudQrp0LVQY9LPszo7iJMrf+Sg+RRfNfDkWWy 5Xa3BR0yQ+wWiZ5ll2aGpMrpVocC0Rje+Lxz+619qZjCokXPdJrTx86PmQIDSaxE97IU 4w== Received: from p1lg14879.it.hpe.com (p1lg14879.it.hpe.com [16.230.97.200]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3hjuqmr2cd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 01:38:13 +0000 Received: from p1lg14885.dc01.its.hpecorp.net (unknown [10.119.18.236]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by p1lg14879.it.hpe.com (Postfix) with ESMTPS id 7A0D0D2C6; Wed, 27 Jul 2022 01:38:12 +0000 (UTC) Received: from WAFM3XJD5N.asiapacific.hpqcorp.net (unknown [16.231.227.36]) by p1lg14885.dc01.its.hpecorp.net (Postfix) with ESMTP id 3B2D2804D10; Wed, 27 Jul 2022 01:38:11 +0000 (UTC) From: "Nickle Wang" To: devel@edk2.groups.io Cc: Abner Chang , Yang Atom , Nick Ramirez Subject: [edk2-staging][PATCH v3 05/15] edk2-staging/RedfishClientPkg: Introduce resource identify library Date: Wed, 27 Jul 2022 09:37:52 +0800 Message-Id: <20220727013802.247-6-nickle.wang@hpe.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20220727013802.247-1-nickle.wang@hpe.com> References: <20220727013802.247-1-nickle.wang@hpe.com> MIME-Version: 1.0 X-Proofpoint-GUID: 44i9BUbRacs1FquObYZTXweSHn4yaJJu X-Proofpoint-ORIG-GUID: 44i9BUbRacs1FquObYZTXweSHn4yaJJu X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_07,2022-07-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 mlxlogscore=928 bulkscore=0 adultscore=0 impostorscore=0 mlxscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207270002 Content-Transfer-Encoding: 8bit Introduce resource identify library which works with resource config protocol to identify Redfish resource. This library provides the flexibility for platform to implement its own policy and identify resource. Two library implementation are provided as demonstration code. NULL version of library accepts all Redfish resource and another implementation to computer system resource uses UUID to identify Redfish resource. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Yang Atom Cc: Nick Ramirez --- .../Library/RedfishResourceIdentifyLib.h | 29 ++++ .../RedfishResourceIdentifyLibComuterSystem.c | 164 ++++++++++++++++++ ...edfishResourceIdentifyLibComuterSystem.inf | 39 +++++ .../RedfishResourceIdentifyLibNull.c | 37 ++++ .../RedfishResourceIdentifyLibNull.inf | 32 ++++ RedfishClientPkg/RedfishClientLibs.dsc.inc | 2 +- RedfishClientPkg/RedfishClientPkg.dec | 1 + 7 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h create mode 100644 RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.c create mode 100644 RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.inf create mode 100644 RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.c create mode 100644 RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.inf diff --git a/RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h b/RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h new file mode 100644 index 0000000000..91d01b7d68 --- /dev/null +++ b/RedfishClientPkg/Include/Library/RedfishResourceIdentifyLib.h @@ -0,0 +1,29 @@ +/** @file + This file defines the Redfish resource identify Library interface. + + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REDFISH_RESOURCE_IDENTIFY_LIB_H_ +#define REDFISH_RESOURCE_IDENTIFY_LIB_H_ + +/** + Identify resource from given URI and context in JSON format + + @param[in] Uri URI of given Redfish resource + @param[in] Json Context in JSON format of give Redfish resource + + @retval TRUE This is the Redfish resource that we have to handle. + @retval FALSE We don't handle this Redfish resource. + +**/ +BOOLEAN +RedfishIdentifyResource ( + IN EFI_STRING Uri, + IN CHAR8 *Json + ); + +#endif diff --git a/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.c b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.c new file mode 100644 index 0000000000..e5699f194c --- /dev/null +++ b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.c @@ -0,0 +1,164 @@ +/** @file + Redfish resource identify library implementation for computer system version 1.5.0 + + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +EFI_REST_JSON_STRUCTURE_PROTOCOL *mJsonStructProtocol = NULL; + +/** + Identify resource from given URI and context in JSON format + + @param[in] Uri URI of given Redfish resource + @param[in] Json Context in JSON format of give Redfish resource + + @retval TRUE This is the Redfish resource that we have to handle. + @retval FALSE We don't handle this Redfish resource. + +**/ +BOOLEAN +RedfishIdentifyResource ( + IN EFI_STRING Uri, + IN CHAR8 *Json + ) +{ + EFI_STATUS Status; + EFI_REDFISH_COMPUTERSYSTEM_V1_5_0 *ComputerSystem; + EFI_REDFISH_COMPUTERSYSTEM_V1_5_0_CS *ComputerSystemCs; + EFI_GUID SystemUuid; + EFI_GUID ResourceUuid; + + if (IS_EMPTY_STRING (Uri) || IS_EMPTY_STRING (Json)) { + return FALSE; + } + + if (mJsonStructProtocol == NULL) { + return FALSE; + } + + ComputerSystem = NULL; + ComputerSystemCs = NULL; + + Status = mJsonStructProtocol->ToStructure ( + mJsonStructProtocol, + NULL, + Json, + (EFI_REST_JSON_STRUCTURE_HEADER **)&ComputerSystem + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n", __FUNCTION__, Status)); + return FALSE; + } + + ComputerSystemCs = ComputerSystem->ComputerSystem; + + if (IS_EMPTY_STRING (ComputerSystemCs->UUID)) { + return FALSE; + } + + Status = AsciiStrToGuid (ComputerSystemCs->UUID, &ResourceUuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, fail to get resource UUID: %r\n", __FUNCTION__, Status)); + return FALSE; + } + + Status = NetLibGetSystemGuid (&SystemUuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, fail to get system UUID from SMBIOS: %r\n", __FUNCTION__, Status)); + return FALSE; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, Identify: System: %g Resource: %g\n", __FUNCTION__, &SystemUuid, &ResourceUuid)); + if (CompareGuid (&ResourceUuid, &SystemUuid)) { + Status = EFI_SUCCESS; + } else { + Status = EFI_UNSUPPORTED; + } + + mJsonStructProtocol->DestoryStructure ( + mJsonStructProtocol, + (EFI_REST_JSON_STRUCTURE_HEADER *)ComputerSystem + ); + + return (Status == EFI_SUCCESS ? TRUE : FALSE); +} + +/** + 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 +RestJasonStructureProtocolIsReady + ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + if (mJsonStructProtocol != NULL) { + return; + } + + Status = gBS->LocateProtocol ( + &gEfiRestJsonStructureProtocolGuid, + NULL, + (VOID **)&mJsonStructProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to locate gEfiRestJsonStructureProtocolGuid: %r\n", __FUNCTION__, Status)); + } + + gBS->CloseEvent (Event); +} + +/** + + Install JSON protocol notification + + @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 +RedfishResourceIdentifyComuterSystemConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + VOID *Registration; + + EfiCreateProtocolNotifyEvent ( + &gEfiRestJsonStructureProtocolGuid, + TPL_CALLBACK, + RestJasonStructureProtocolIsReady, + NULL, + &Registration + ); + + return EFI_SUCCESS; +} diff --git a/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.inf b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.inf new file mode 100644 index 0000000000..ae269b5849 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.inf @@ -0,0 +1,39 @@ +## @file +# +# (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010006 + BASE_NAME = RedfishResourceIdentifyLibComuterSystem + FILE_GUID = 2AEE2C80-126A-44A6-877E-642F20510D13 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = RedfishResourceIdentifyLib| DXE_DRIVER + CONSTRUCTOR = RedfishResourceIdentifyComuterSystemConstructor + +# +# VALID_ARCHITECTURES = IA32 X64 EBC +# + +[Sources] + RedfishResourceIdentifyLibComuterSystem.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + NetworkPkg/NetworkPkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiBootServicesTableLib + UefiLib + +[Protocols] + gEfiRestJsonStructureProtocolGuid ## CONSUMES diff --git a/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.c b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.c new file mode 100644 index 0000000000..98eb8fde47 --- /dev/null +++ b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.c @@ -0,0 +1,37 @@ +/** @file + Redfish resource identify NULL library implementation + + (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Identify resource from given URI and context in JSON format + + @param[in] Uri URI of given Redfish resource + @param[in] Json Context in JSON format of give Redfish resource + + @retval TRUE This is the Redfish resource that we have to handle. + @retval FALSE We don't handle this Redfish resource. + +**/ +BOOLEAN +RedfishIdentifyResource ( + IN EFI_STRING Uri, + IN CHAR8 *Json + ) +{ + if (!IS_EMPTY_STRING (Uri)) { + DEBUG ((DEBUG_VERBOSE, "%a, accept resource: %s\n", __FUNCTION__, Uri)); + } + + return TRUE; +} diff --git a/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.inf b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.inf new file mode 100644 index 0000000000..9164b229ba --- /dev/null +++ b/RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.inf @@ -0,0 +1,32 @@ +## @file +# +# (C) Copyright 2022 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010006 + BASE_NAME = RedfishResourceIdentifyLibNull + FILE_GUID = 6FFD4E25-48F8-4CB6-B194-CFAB407316E1 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = RedfishResourceIdentifyLib| DXE_DRIVER + +# +# VALID_ARCHITECTURES = IA32 X64 EBC +# + +[Sources] + RedfishResourceIdentifyLibNull.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[LibraryClasses] + BaseLib + DebugLib diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/RedfishClientLibs.dsc.inc index 8acb479170..413b83a732 100644 --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc @@ -27,7 +27,7 @@ RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.inf ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/ConverterCommonLib/ConverterCommonLib.inf - + RedfishResourceIdentifyLib|RedfishClientPkg/Library/RedfishResourceIdentifyLibNull/RedfishResourceIdentifyLibNull.inf EdkIIRedfishResourceConfigLib|RedfishClientPkg/Library/EdkIIRedfishResourceConfigLib/EdkIIRedfishResourceConfigLib.inf RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.inf RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/RedfishClientPkg.dec index 9d18c42c24..c61c581213 100644 --- a/RedfishClientPkg/RedfishClientPkg.dec +++ b/RedfishClientPkg/RedfishClientPkg.dec @@ -21,6 +21,7 @@ [LibraryClasses] RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h + RedfishResourceIdentifyLib|Include/Library/RedfishResourceIdentifyLib.h EdkIIRedfishResourceConfigLib|Include/Library/EdkIIRedfishResourceConfigLib.h RedfishEventLib|Include/Library/RedfishEventLib.h RedfishVersionLib|Include/Library/RedfishVersionLib.h -- 2.32.0.windows.2