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.web10.14965.1658885911226123375 for ; Tue, 26 Jul 2022 18:38:31 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=fhIiqDsX; 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.147.86, mailfrom: prvs=0207a15765=nickle.wang@hpe.com) Received: from pps.filterd (m0150242.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26R0sj2Z019781; Wed, 27 Jul 2022 01:38:29 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=tX+mJaLJo4Yp1WhseKOu42DUSxZthCiFeqOPG0HqvEY=; b=fhIiqDsXn6zfaTnhT3nLhXgiqKTpb4XCKtfPKzOUuRH7fttCv3X07aTW5qkEFOevT4VW sJoy4qgd/SbL0znHMBK7e1cSV+y2R37/qcjafYb1eltzTGAJB1Nf8gcLN2SuaY/cdXsM T7TL38uIjJT1eaAs8VAyLsiEwHzDDGmCDNr/1Qrh48wilHb0qOUm5ZFbu3fO808iP4EW RXJUgOwbsszWZxlscZCsyz4+D42+YzkwAHQ00NRju6Mfqvo0JYS1C1vNzC95m8waUGpZ zAlpJUUtH+PiztuGvnRGbXpSGhmqP3tSbmH7yh6hA+9Z1MgwZDChZB8sGCUBheQYjqr6 xw== Received: from p1lg14880.it.hpe.com (p1lg14880.it.hpe.com [16.230.97.201]) by mx0a-002e3701.pphosted.com (PPS) with ESMTPS id 3hjqhjsm57-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 01:38:29 +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 p1lg14880.it.hpe.com (Postfix) with ESMTPS id F118E8001A2; Wed, 27 Jul 2022 01:38:28 +0000 (UTC) Received: from WAFM3XJD5N.asiapacific.hpqcorp.net (unknown [16.231.227.36]) by p1lg14885.dc01.its.hpecorp.net (Postfix) with ESMTP id B0D17804D10; Wed, 27 Jul 2022 01:38:27 +0000 (UTC) From: "Nickle Wang" To: devel@edk2.groups.io Cc: Abner Chang , Yang Atom , Nick Ramirez Subject: [edk2-staging][PATCH v3 15/15] edk2-staging/RedfishClientPkg: Introduce Bios feature driver Date: Wed, 27 Jul 2022 09:38:02 +0800 Message-Id: <20220727013802.247-16-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: baY7iIkASXif3AtWcpYLKiTz1yqN8cuO X-Proofpoint-ORIG-GUID: baY7iIkASXif3AtWcpYLKiTz1yqN8cuO 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 phishscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 spamscore=0 bulkscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207270002 Content-Transfer-Encoding: 8bit Introduce new feature driver to support Bios version 1.0.9 schema. Update corresponding FDF and DSC file to enable this feature driver. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Yang Atom Cc: Nick Ramirez --- .../Features/Bios/v1_0_9/Common/BiosCommon.c | 741 ++++++++++++++++ .../Features/Bios/v1_0_9/Common/BiosCommon.h | 30 + .../Features/Bios/v1_0_9/Dxe/BiosDxe.c | 789 ++++++++++++++++++ .../Features/Bios/v1_0_9/Dxe/BiosDxe.inf | 52 ++ RedfishClientPkg/RedfishClient.fdf.inc | 2 + .../RedfishClientComponents.dsc.inc | 2 + RedfishClientPkg/RedfishClientLibs.dsc.inc | 6 +- 7 files changed, 1621 insertions(+), 1 deletion(-) create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.h create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c new file mode 100644 index 0000000000..d910d0d8a9 --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c @@ -0,0 +1,741 @@ +/** @file + Redfish feature driver implementation - common functions + + (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "BiosCommon.h" + +CHAR8 BiosEmptyJson[] = "{\"@odata.id\": \"\", \"@odata.type\": \"#Bios.v1_0_9.Bios\", \"Id\": \"\", \"Name\": \"\", \"Attributes\":{}}"; + +REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate = NULL; + +/** + Consume resource from given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance. + @param[in] Json The JSON to consume. + @param[in] HeaderEtag The Etag string returned in HTTP header. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishConsumeResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *Json, + IN CHAR8 *HeaderEtag OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_REDFISH_BIOS_V1_0_9 *Bios; + EFI_REDFISH_BIOS_V1_0_9_CS *BiosCs; + EFI_STRING ConfigureLang; + RedfishCS_Type_EmptyProp_CS_Data *EmptyPropCs; + + + if (Private == NULL || IS_EMPTY_STRING (Json)) { + return EFI_INVALID_PARAMETER; + } + + Bios = NULL; + BiosCs = NULL; + ConfigureLang = NULL; + + Status = Private->JsonStructProtocol->ToStructure ( + Private->JsonStructProtocol, + NULL, + Json, + (EFI_REST_JSON_STRUCTURE_HEADER **)&Bios + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n", __FUNCTION__, Status)); + return Status; + } + + BiosCs = Bios->Bios; + + // + // Check ETAG to see if we need to consume it + // + if (CheckEtag (Private->Uri, HeaderEtag, BiosCs->odata_etag)) { + // + // No change + // + DEBUG ((DEBUG_INFO, "%a, ETAG: %s has no change, ignore consume action\n", __FUNCTION__, Private->Uri)); + Status = EFI_ALREADY_STARTED; + goto ON_RELEASE; + } + + // + // Handle ATTRIBUTEREGISTRY + // + if (BiosCs->AttributeRegistry != NULL) { + // + // Find corresponding configure language for collection resource. + // + ConfigureLang = GetConfigureLang (BiosCs->odata_id, "AttributeRegistry"); + if (ConfigureLang != NULL) { + Status = ApplyFeatureSettingsStringType (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, ConfigureLang, BiosCs->AttributeRegistry); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, apply setting for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + } + + FreePool (ConfigureLang); + } else { + DEBUG ((DEBUG_ERROR, "%a, can not get configure language for URI: %s\n", __FUNCTION__, Private->Uri)); + } + } + + // + // Handle ATTRIBUTES + // + if (BiosCs->Attributes == NULL) { + BiosCs->Attributes = AllocateZeroPool (sizeof (RedfishBios_V1_0_9_Attributes_CS)); + ASSERT (BiosCs->Attributes != NULL); + } + + // + // Handle ATTRIBUTES->EmptyProperty + // + if (BiosCs->Attributes != NULL) { + // + // Validate empty property. + // + if (BiosCs->Attributes->Prop.ForwardLink == &BiosCs->Attributes->Prop) { + goto ON_RELEASE; + } + EmptyPropCs = (RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes->Prop.ForwardLink; + if (EmptyPropCs->Header.ResourceType == RedfishCS_Type_JSON) { + DEBUG ((DEBUG_ERROR, "%a, Empty property with RedfishCS_Type_JSON type resource is not supported yet. (%s)\n", __FUNCTION__, Private->Uri)); + goto ON_RELEASE; + } + // + // Find corresponding configure language for collection resource. + // + ConfigureLang = GetConfigureLang (BiosCs->odata_id, "Attributes"); + if (ConfigureLang != NULL) { + Status = ApplyFeatureSettingsVagueType (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, ConfigureLang, EmptyPropCs->KeyValuePtr, EmptyPropCs->NunmOfProperties); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, apply setting for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + } + + FreePool (ConfigureLang); + } else { + DEBUG ((DEBUG_ERROR, "%a, can not get configure language for URI: %s\n", __FUNCTION__, Private->Uri)); + } + } + + +ON_RELEASE: + + // + // Release resource. + // + Private->JsonStructProtocol->DestoryStructure ( + Private->JsonStructProtocol, + (EFI_REST_JSON_STRUCTURE_HEADER *)Bios + ); + + return EFI_SUCCESS; +} + +EFI_STATUS +ProvisioningBiosProperties ( + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *JsonStructProtocol, + IN CHAR8 *InputJson, + IN CHAR8 *ResourceId, OPTIONAL + IN EFI_STRING ConfigureLang, + IN BOOLEAN ProvisionMode, + OUT CHAR8 **ResultJson + ) +{ + EFI_REDFISH_BIOS_V1_0_9 *Bios; + EFI_REDFISH_BIOS_V1_0_9_CS *BiosCs; + EFI_STATUS Status; + BOOLEAN PropertyChanged; + CHAR8 *AsciiStringValue; + RedfishCS_EmptyProp_KeyValue *PropertyVagueValues; + UINT32 VagueValueNumber; + + + + if (JsonStructProtocol == NULL || ResultJson == NULL || IS_EMPTY_STRING (InputJson) || IS_EMPTY_STRING (ConfigureLang)) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a provision for %s with: %s\n", __FUNCTION__, ConfigureLang, (ProvisionMode ? L"Provision resource" : L"Update resource"))); + + *ResultJson = NULL; + PropertyChanged = FALSE; + + Bios = NULL; + Status = JsonStructProtocol->ToStructure ( + JsonStructProtocol, + NULL, + InputJson, + (EFI_REST_JSON_STRUCTURE_HEADER **)&Bios + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToStructure failure: %r\n", __FUNCTION__, Status)); + return Status; + } + + BiosCs = Bios->Bios; + + // + // ID + // + if (BiosCs->Id == NULL && !IS_EMPTY_STRING (ResourceId)) { + BiosCs->Id = AllocateCopyPool (AsciiStrSize (ResourceId), ResourceId); + } + + // + // Handle ATTRIBUTEREGISTRY + // + if (PropertyChecker (BiosCs->AttributeRegistry, ProvisionMode)) { + AsciiStringValue = GetPropertyStringValue (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, L"AttributeRegistry", ConfigureLang); + if (AsciiStringValue != NULL) { + if (ProvisionMode || AsciiStrCmp (BiosCs->AttributeRegistry, AsciiStringValue) != 0) { + BiosCs->AttributeRegistry = AsciiStringValue; + PropertyChanged = TRUE; + } + } + } + // + // Handle ATTRIBUTES + // + if (BiosCs->Attributes != NULL) { + // + // Handle ATTRIBUTES + // + if (PropertyChecker (BiosCs->Attributes, ProvisionMode)) { + PropertyVagueValues = GetPropertyVagueValue (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, L"Attributes", ConfigureLang, &VagueValueNumber); + if (PropertyVagueValues != NULL) { + if (ProvisionMode || !CompareRedfishPropertyVagueValues ( + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes->Prop.ForwardLink)->KeyValuePtr, + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes->Prop.ForwardLink)->NunmOfProperties, + PropertyVagueValues, + VagueValueNumber)) { + // + // Use the properties on system to replace the one on Redfish service. + // + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes->Prop.ForwardLink)->KeyValuePtr = PropertyVagueValues; + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes->Prop.ForwardLink)->NunmOfProperties = VagueValueNumber; + PropertyChanged = TRUE; + } + } + } + } + + + // + // Convert C structure back to JSON text. + // + Status = JsonStructProtocol->ToJson ( + JsonStructProtocol, + (EFI_REST_JSON_STRUCTURE_HEADER *)Bios, + ResultJson + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToJson() failed: %r\n", __FUNCTION__, Status)); + return Status; + } + + // + // Release resource. + // + JsonStructProtocol->DestoryStructure ( + JsonStructProtocol, + (EFI_REST_JSON_STRUCTURE_HEADER *)Bios + ); + + return (PropertyChanged ? EFI_SUCCESS : EFI_NOT_FOUND); +} + +EFI_STATUS +ProvisioningBiosResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN UINTN Index, + IN EFI_STRING ConfigureLang + ) +{ + CHAR8 *Json; + EFI_STATUS Status; + EFI_STRING NewResourceLocation; + CHAR8 *EtagStr; + CHAR8 ResourceId[16]; + + if (IS_EMPTY_STRING (ConfigureLang) || Private == NULL) { + return EFI_INVALID_PARAMETER; + } + + EtagStr = NULL; + AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index); + + Status = ProvisioningBiosProperties ( + Private->JsonStructProtocol, + BiosEmptyJson, + ResourceId, + ConfigureLang, + TRUE, + &Json + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, provisioning resource for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + return Status; + } + + Status = CreatePayloadToPostResource (Private->RedfishService, Private->Payload, Json, &NewResourceLocation, &EtagStr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, post Bios resource for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + goto RELEASE_RESOURCE; + } + + ASSERT (NewResourceLocation != NULL); + + // + // Keep location of new resource. + // + if (NewResourceLocation != NULL) { + RedfisSetRedfishUri (ConfigureLang, NewResourceLocation); + } + + // + // Handle Etag + // + if (EtagStr != NULL) { + SetEtagWithUri (EtagStr, NewResourceLocation); + FreePool (EtagStr); + } + +RELEASE_RESOURCE: + + if (NewResourceLocation != NULL) { + FreePool (NewResourceLocation); + } + + if (Json != NULL) { + FreePool (Json); + } + + return Status; +} + +EFI_STATUS +ProvisioningBiosResources ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private + ) +{ + UINTN Index; + EFI_STATUS Status; + REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST UnifiedConfigureLangList; + + if (Private == NULL) { + return EFI_INVALID_PARAMETER; + } + + Status = RedfishFeatureGetUnifiedArrayTypeConfigureLang (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, REDPATH_ARRAY_PATTERN, &UnifiedConfigureLangList); + if (EFI_ERROR (Status) || UnifiedConfigureLangList.Count == 0) { + DEBUG ((DEBUG_ERROR, "%a, No HII question found with configure language: %s: %r\n", __FUNCTION__, REDPATH_ARRAY_PATTERN, Status)); + return EFI_NOT_FOUND; + } + // + // Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE. + // This information is sent back to the parent resource (e.g. the collection driver). + // + EdkIIRedfishResourceSetConfigureLang (&UnifiedConfigureLangList); + + for (Index = 0; Index < UnifiedConfigureLangList.Count; Index++) { + DEBUG ((DEBUG_INFO, "[%d] create Bios resource from: %s\n", UnifiedConfigureLangList.List[Index].Index, UnifiedConfigureLangList.List[Index].ConfigureLang)); + ProvisioningBiosResource (Private, UnifiedConfigureLangList.List[Index].Index, UnifiedConfigureLangList.List[Index].ConfigureLang); + FreePool (UnifiedConfigureLangList.List[Index].ConfigureLang); + } + + return EFI_SUCCESS; +} + + +EFI_STATUS +ProvisioningBiosExistResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private + ) +{ + EFI_STATUS Status; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + CHAR8 *Json; + + if (Private == NULL) { + return EFI_INVALID_PARAMETER; + } + + EtagStr = NULL; + Json = NULL; + ConfigureLang = NULL; + + ConfigureLang = RedfishGetConfigLanguage (Private->Uri); + if (ConfigureLang == NULL) { + return EFI_NOT_FOUND; + } + + Status = ProvisioningBiosProperties ( + Private->JsonStructProtocol, + BiosEmptyJson, + NULL, + ConfigureLang, + TRUE, + &Json + ); + if (EFI_ERROR (Status)) { + if (Status == EFI_NOT_FOUND) { + DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s ignored. Nothing changed\n", __FUNCTION__, ConfigureLang)); + } else { + DEBUG ((DEBUG_ERROR, "%a, provisioning existing resource for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + } + goto ON_RELEASE; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s\n", __FUNCTION__, ConfigureLang)); + // + // PUT back to instance + // + Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + } + + // + // Handle Etag + // + if (EtagStr != NULL) { + SetEtagWithUri (EtagStr, Private->Uri); + FreePool (EtagStr); + } + +ON_RELEASE: + + if (Json != NULL) { + FreePool (Json); + } + + if (ConfigureLang != NULL) { + FreePool (ConfigureLang); + } + + return Status; +} + +/** + Provisioning redfish resource by given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance. + @param[in] ResourceExist TRUE if resource exists, PUT method will be used. + FALSE if resource does not exist POST method is used. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishProvisioningResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN BOOLEAN ResourceExist + ) +{ + if (Private == NULL) { + return EFI_INVALID_PARAMETER; + } + + return (ResourceExist ? ProvisioningBiosExistResource (Private) : ProvisioningBiosResources (Private)); +} + +/** + Check resource from given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance. + @param[in] Json The JSON to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishCheckResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *Json + ) +{ + UINTN Index; + EFI_STATUS Status; + EFI_STRING *ConfigureLangList; + UINTN Count; + EFI_STRING Property; + + if (Private == NULL || IS_EMPTY_STRING (Json)) { + return EFI_INVALID_PARAMETER; + } + + Status = RedfishPlatformConfigGetConfigureLang (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, REDPATH_ARRAY_PATTERN, &ConfigureLangList, &Count); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, BiosConfigToRedfishGetConfigureLangRegex failed: %r\n", __FUNCTION__, Status)); + return Status; + } + + if (Count == 0) { + return EFI_NOT_FOUND; + } + + Status = EFI_SUCCESS; + for (Index = 0; Index < Count; Index++) { + + Property = GetPropertyFromConfigureLang (Private->Uri, ConfigureLangList[Index]); + if (Property == NULL) { + continue; + } + + DEBUG ((DEBUG_INFO, "%a, [%d] check attribute for: %s\n", __FUNCTION__, Index, Property)); + if (!MatchPropertyWithJsonContext (Property, Json)) { + DEBUG ((DEBUG_INFO, "%a, property is missing: %s\n", __FUNCTION__, Property)); + Status = EFI_NOT_FOUND; + } + } + + FreePool (ConfigureLangList); + + return Status; +} + +/** + Update resource to given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance. + @param[in] Json The JSON to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishUpdateResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *InputJson + ) +{ + EFI_STATUS Status; + CHAR8 *Json; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + + if (Private == NULL || IS_EMPTY_STRING (InputJson)) { + return EFI_INVALID_PARAMETER; + } + + EtagStr = NULL; + Json = NULL; + ConfigureLang = NULL; + + ConfigureLang = RedfishGetConfigLanguage (Private->Uri); + if (ConfigureLang == NULL) { + return EFI_NOT_FOUND; + } + + Status = ProvisioningBiosProperties ( + Private->JsonStructProtocol, + InputJson, + NULL, + ConfigureLang, + FALSE, + &Json + ); + if (EFI_ERROR (Status)) { + if (Status == EFI_NOT_FOUND) { + DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s ignored. Nothing changed\n", __FUNCTION__, ConfigureLang)); + } else { + DEBUG ((DEBUG_ERROR, "%a, update resource for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + } + goto ON_RELEASE; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n", __FUNCTION__, ConfigureLang)); + // + // PUT back to instance + // + Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __FUNCTION__, ConfigureLang, Status)); + } + + // + // Handle Etag + // + if (EtagStr != NULL) { + SetEtagWithUri (EtagStr, Private->Uri); + FreePool (EtagStr); + } + +ON_RELEASE: + + if (Json != NULL) { + FreePool (Json); + } + + if (ConfigureLang != NULL) { + FreePool (ConfigureLang); + } + + return Status; +} + +/** + Identify resource from given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance. + @param[in] Json The JSON to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishIdentifyResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *Json + ) +{ + BOOLEAN Supported; + EFI_STATUS Status; + EFI_STRING EndOfChar; + REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST ConfigLangList; + + Supported = RedfishIdentifyResource (Private->Uri, Private->Json); + if (Supported) { + Status = RedfishFeatureGetUnifiedArrayTypeConfigureLang (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, REDPATH_ARRAY_PATTERN, &ConfigLangList); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, BiosConfigToRedfishGetConfigureLangRegex failed: %r\n", __FUNCTION__, Status)); + return Status; + } + + if (ConfigLangList.Count == 0) { + return EFI_SUCCESS; + } + + //EndOfChar = StrStr (ConfigLangList.List[0].ConfigureLang, L"}"); + Status = IsRedpathArray (ConfigLangList.List[0].ConfigureLang, NULL, &EndOfChar); + if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) { + ASSERT (FALSE); + return EFI_DEVICE_ERROR; + } + if (Status != EFI_SUCCESS) { + // + // This is not the collection redpath. + // + GetRedpathNodeByIndex (ConfigLangList.List[0].ConfigureLang, 0, &EndOfChar); + } + *(++EndOfChar) = '\0'; + // + // Keep URI and ConfigLang mapping + // + RedfisSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri); + // + // Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE. + // This information is sent back to the parent resource (e.g. the collection driver). + // + EdkIIRedfishResourceSetConfigureLang (&ConfigLangList); + DestroyConfiglanguageList (&ConfigLangList); + return EFI_SUCCESS; + } + + return EFI_UNSUPPORTED; +} + +EFI_STATUS +HandleResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN EFI_STRING Uri + ) +{ + EFI_STATUS Status; + REDFISH_SCHEMA_INFO SchemaInfo; + EFI_STRING ConfigLang; + + if (Private == NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + // + // Resource match + // + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, process resource for: %s\n", __FUNCTION__, Uri)); + + Status = GetRedfishSchemaInfo (Private->RedfishService, Private->JsonStructProtocol, 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 this first. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%s Identify for %s\n", __FUNCTION__, Uri)); + ConfigLang = RedfishGetConfigLanguage (Uri); + if (ConfigLang == NULL) { + Status = EdkIIRedfishResourceConfigIdentify (&SchemaInfo, Uri, Private->InformationExchange); + if (EFI_ERROR (Status)) { + if (Status == EFI_UNSUPPORTED) { + DEBUG ((DEBUG_INFO, "%a, \"%s\" is not handled by us\n", __FUNCTION__, 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", __FUNCTION__, ConfigLang)); + FreePool (ConfigLang); + } + + // + // Check and see if target property exist or not even when collection memeber exists. + // If not, we sill do provision. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __FUNCTION__, Uri)); + Status = EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + // + // The target property does not exist, do the provision to create property. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a provision for %s\n", __FUNCTION__, Uri)); + Status = 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 = 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 = EdkIIRedfishResourceConfigUpdate (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to update resoruce for: %s: %r\n", __FUNCTION__, Uri, Status)); + } + + return Status; +} diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.h b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.h new file mode 100644 index 0000000000..321ded7637 --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.h @@ -0,0 +1,30 @@ +/** @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_BIOS_COMMON_H_ +#define EFI_REDFISH_BIOS_COMMON_H_ + +#include +#include + +// +// Schema information. +// +#define REDFISH_MANAGED_URI L"Systems/{}/Bios" +#define MAX_URI_LENGTH 256 +#define RESOURCE_SCHEMA "Bios" +#define RESOURCE_SCHEMA_MAJOR "1" +#define RESOURCE_SCHEMA_MINOR "0" +#define RESOURCE_SCHEMA_ERRATA "9" +#define RESOURCE_SCHEMA_VERSION "v1_0_9" +#define REDPATH_ARRAY_PATTERN L"/Bios/.*" +#define REDPATH_ARRAY_PREFIX L"/Bios/" +#define RESOURCE_SCHEMA_FULL "x-uefi-redfish-Bios.v1_0_9" +#define REDFISH_SCHEMA_NAME "ComputerSystem" + +#endif diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c new file mode 100644 index 0000000000..a478061cde --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c @@ -0,0 +1,789 @@ +/** @file + Redfish feature driver implementation - Bios + + (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "../Common/BiosCommon.h" + +extern REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate; + +EFI_STATUS +HandleResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN EFI_STRING Uri + ); + +EFI_HANDLE medfishResourceConfigProtocolHandle; + +/** + Provising redfish resource by given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance. + @param[in] Uri Target URI to create resource. + @param[in] PostMode TRUE if the resource does not exist, post method is used. + FALSE if the resource exist but property is missing, put method is used. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceProvisioningResource ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri, + IN BOOLEAN PostMode + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This == NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_INFO, "%a, provisioning in %s mode\n", __FUNCTION__, (PostMode ? L"POST" : L"PATCH"))); + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This); + + if (Private->RedfishService == NULL) { + return EFI_NOT_READY; + } + + Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION__, Uri)); + return Status; + } + + Private->Uri = Uri; + Private->Payload = Response.Payload; + ASSERT (Private->Payload != NULL); + + Status = RedfishProvisioningResourceCommon (Private, !PostMode); + + // + // Release resource + // + if (Private->Payload != NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload = NULL; + } + + return Status; +} + +/** + Consume resource from given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceConsumeResource ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + CHAR8 *Etag; + + if (This == NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This); + + if (Private->RedfishService == NULL) { + return EFI_NOT_READY; + } + + Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION__, Uri)); + return Status; + } + + Private->Uri = Uri; + Private->Payload = Response.Payload; + ASSERT (Private->Payload != NULL); + + Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT); + ASSERT (Private->Json != NULL); + + // + // Find etag in HTTP response header + // + Etag = NULL; + Status = GetEtagAndLocation (&Response, &Etag, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __FUNCTION__)); + } + + Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag); + if (EFI_ERROR (Status)) { + if (Status != EFI_ALREADY_STARTED) { + DEBUG ((DEBUG_ERROR, "%a, failed to consume resource from: %s: %r\n", __FUNCTION__, Uri, Status)); + } + } else { + // + // Keep etag after consuming pending settings. + // + if (Etag != NULL) { + SetEtagWithUri (Etag, Private->Uri); + } + } + + // + // Release resource + // + if (Private->Payload != NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload = NULL; + } + + if (Private->Json != NULL) { + FreePool (Private->Json); + Private->Json = NULL; + } + + return Status; +} + +/** + Get information about this protocol. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance. + @param[out] Schema Supported schema. + @param[out] Major Supported major number. + @param[out] Minor Supported minor number. + @param[out] Errata Supported errata number. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceGetInfo ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + OUT REDFISH_SCHEMA_INFO *Info + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + + if (This == NULL || Info == NULL) { + return EFI_INVALID_PARAMETER; + } + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This); + + AsciiStrCpyS (Info->Schema, REDFISH_SCHEMA_STRING_SIZE, RESOURCE_SCHEMA); + AsciiStrCpyS (Info->Major, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_MAJOR); + AsciiStrCpyS (Info->Minor, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_MINOR); + AsciiStrCpyS (Info->Errata, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_ERRATA); + + return EFI_SUCCESS; +} + +/** + Update resource to given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceUpdate ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This == NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This); + + if (Private->RedfishService == NULL) { + return EFI_NOT_READY; + } + + Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION__, Uri)); + return Status; + } + + Private->Uri = Uri; + Private->Payload = Response.Payload; + ASSERT (Private->Payload != NULL); + + Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT); + ASSERT (Private->Json != NULL); + + Status = RedfishUpdateResourceCommon (Private, Private->Json); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to update resource from: %s: %r\n", __FUNCTION__, Uri, Status)); + } + + // + // Release resource + // + if (Private->Payload != NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload = NULL; + } + + if (Private->Json != NULL) { + FreePool (Private->Json); + Private->Json = NULL; + } + + return Status; +} + +/** + Check resource on given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceCheck ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This == NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This); + + if (Private->RedfishService == NULL) { + return EFI_NOT_READY; + } + + Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION__, Uri)); + return Status; + } + + Private->Uri = Uri; + Private->Payload = Response.Payload; + ASSERT (Private->Payload != NULL); + + Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT); + ASSERT (Private->Json != NULL); + + Status = RedfishCheckResourceCommon (Private, Private->Json); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __FUNCTION__, Uri, Status)); + } + + // + // Release resource + // + if (Private->Payload != NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload = NULL; + } + + if (Private->Json != NULL) { + FreePool (Private->Json); + Private->Json = NULL; + } + + return Status; +} + +/** + Identify resource on given URI. + + @param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS This is target resource which we want to handle. + @retval EFI_UNSUPPORTED This is not the target resource. + @retval Others Some error happened. + +**/ + +EFI_STATUS +RedfishResourceIdentify ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This == NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This); + + if (Private->RedfishService == NULL) { + return EFI_NOT_READY; + } + + Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION__, Uri)); + return Status; + } + + Private->Uri = Uri; + Private->Payload = Response.Payload; + ASSERT (Private->Payload != NULL); + + Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT); + ASSERT (Private->Json != NULL); + + Status = RedfishIdentifyResourceCommon (Private, Private->Json); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, identify %s failed: %r\n", __FUNCTION__, Uri, Status)); + } + // + // Release resource + // + if (Private->Payload != NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload = NULL; + } + + if (Private->Json != NULL) { + FreePool (Private->Json); + Private->Json = NULL; + } + + return Status; +} + +EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL mRedfishResourceConfig = { + RedfishResourceProvisioningResource, + RedfishResourceConsumeResource, + RedfishResourceUpdate, + RedfishResourceCheck, + RedfishResourceIdentify, + RedfishResourceGetInfo +}; + +/** + 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_HANDLER_PROTOCOL instance. + @param[in] RedfishConfigServiceInfo Redfish service informaion. + + @retval EFI_SUCCESS The handler has been initialized successfully. + @retval EFI_DEVICE_ERROR Failed to create or configure the REST EX protocol instance. + @retval EFI_ALREADY_STARTED This handler has already been initialized. + @retval Other Error happens during the initialization. + +**/ +EFI_STATUS +EFIAPI +RedfishResourceInit ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This, + IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (This); + + Private->RedfishService = RedfishCreateService (RedfishConfigServiceInfo); + if (Private->RedfishService == 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 successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +EFIAPI +RedfishResourceStop ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + + Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (This); + + if (Private->Event != NULL) { + gBS->CloseEvent (Private->Event); + Private->Event = NULL; + } + + if (Private->RedfishService != NULL) { + RedfishCleanupService (Private->RedfishService); + Private->RedfishService = NULL; + } + + if (Private->Payload != NULL) { + RedfishCleanupPayload (Private->Payload); + Private->Payload = NULL; + } + + return EFI_SUCCESS; +} + +EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL mRedfishConfigHandler = { + RedfishResourceInit, + RedfishResourceStop +}; + +/** + 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 (mRedfishResourcePrivate == NULL) { + return; + } + + if (mRedfishResourcePrivate->JsonStructProtocol != NULL) { + return; + } + + Status = gBS->LocateProtocol ( + &gEfiRestJsonStructureProtocolGuid, + NULL, + (VOID **)&mRedfishResourcePrivate->JsonStructProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to locate gEfiRestJsonStructureProtocolGuid: %r\n", __FUNCTION__, Status)); + } + + gBS->CloseEvent (Event); +} + +/** + Unloads an image. + + @param 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 +RedfishResourceUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler; + + if (mRedfishResourcePrivate == NULL) { + return EFI_NOT_READY; + } + + ConfigHandler = NULL; + + // + // Firstly, find ConfigHandler Protocol interface in this ImageHandle. + // + Status = gBS->OpenProtocol ( + ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + (VOID **) &ConfigHandler, + NULL, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (EFI_ERROR (Status) || ConfigHandler == NULL) { + return Status; + } + + ConfigHandler->Stop (ConfigHandler); + + // + // Last, uninstall ConfigHandler Protocol and resource protocol. + // + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + ConfigHandler, + &gEdkIIRedfishResourceConfigProtocolGuid, + &mRedfishResourcePrivate->RedfishResourceConfig, + NULL + ); + + FreePool (mRedfishResourcePrivate); + mRedfishResourcePrivate = NULL; + + return Status; +} + +/** + The callback function provided by Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROTOCOL instance. + @param[in] FeatureAction The action Redfish feature driver should 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_EXCHANGE + + @retval EFI_SUCCESS Redfish feature driver callback is executed successfully. + @retval Others Some errors happened. + + @retval EFI_SUCCESS Redfish feature driver callback is executed successfully. + @retval Others Some errors happened. + +**/ +EFI_STATUS +EFIAPI +RedfishExternalResourceResourceFeatureCallback ( + 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_RESOURCE_COMMON_PRIVATE *Private; + EFI_STRING ResourceUri; + + if (FeatureAction != CallbackActionStartOperation) { + return EFI_UNSUPPORTED; + } + + Private = (REDFISH_RESOURCE_COMMON_PRIVATE *)Context; + + RedfishService = Private->RedfishService; + if (RedfishService == NULL) { + return EFI_NOT_READY; + } + + // + // Save in private structure. + // + Private->InformationExchange = InformationExchange; + + // + // Find Redfish version on BMC + // + Private->RedfishVersion = RedfishGetVersion (RedfishService); + + // + // Create the full URI from Redfish service root. + // + ResourceUri = (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH * sizeof(CHAR16)); + if (ResourceUri == 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->SendInformation.FullUri); + + // + // Initialize collection path + // + Private->Uri = RedfishGetUri (ResourceUri); + if (Private->Uri == NULL) { + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; + } + + Status = HandleResource (Private, Private->Uri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, process external resource: %a failed: %r\n", __FUNCTION__, Private->Uri, Status)); + } + + FreePool (Private->Uri); + return Status; +} + +/** + 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 (mRedfishResourcePrivate == NULL) { + return; + } + + if (mRedfishResourcePrivate->FeatureProtocol != NULL) { + return; + } + + Status = gBS->LocateProtocol ( + &gEdkIIRedfishFeatureProtocolGuid, + NULL, + (VOID **)&FeatureProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to locate gEdkIIRedfishFeatureProtocolGuid: %r\n", __FUNCTION__, Status)); + gBS->CloseEvent (Event); + return; + } + + Status = FeatureProtocol->Register ( + FeatureProtocol, + REDFISH_MANAGED_URI, + RedfishExternalResourceResourceFeatureCallback, + (VOID *)mRedfishResourcePrivate + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to register %s: %r\n", __FUNCTION__, REDFISH_MANAGED_URI, Status)); + } + + mRedfishResourcePrivate->FeatureProtocol = FeatureProtocol; + + gBS->CloseEvent (Event); +} + +/** + 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 including + 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 installed unexpectedly. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +EFIAPI +RedfishResourceEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *Registration; + + if (mRedfishResourcePrivate != NULL) { + return EFI_ALREADY_STARTED; + } + + medfishResourceConfigProtocolHandle = ImageHandle; + + mRedfishResourcePrivate = AllocateZeroPool (sizeof (REDFISH_RESOURCE_COMMON_PRIVATE)); + CopyMem (&mRedfishResourcePrivate->ConfigHandler, &mRedfishConfigHandler, sizeof (EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL)); + CopyMem (&mRedfishResourcePrivate->RedfishResourceConfig, &mRedfishResourceConfig, sizeof (EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL)); + + // + // Publish config handler protocol and resource protocol. + // + Status = gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + &mRedfishResourcePrivate->ConfigHandler, + &gEdkIIRedfishResourceConfigProtocolGuid, + &mRedfishResourcePrivate->RedfishResourceConfig, + NULL + ); + + EfiCreateProtocolNotifyEvent ( + &gEfiRestJsonStructureProtocolGuid, + TPL_CALLBACK, + EfiRestJasonStructureProtocolIsReady, + NULL, + &Registration + ); + + EfiCreateProtocolNotifyEvent ( + &gEdkIIRedfishFeatureProtocolGuid, + TPL_CALLBACK, + EdkIIRedfishFeatureProtocolIsReady, + (VOID *)mRedfishResourcePrivate, + &Registration + ); + + return Status; +} diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf new file mode 100644 index 0000000000..8c01a3b877 --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf @@ -0,0 +1,52 @@ +## @file +# +# (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BiosDxe + FILE_GUID = d6c99bb0-ca18-45aa-8be6-a60c3ba5ecd8 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = RedfishResourceEntryPoint + UNLOAD_IMAGE = RedfishResourceUnload + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[Sources] + ../Common/BiosCommon.h + ../Common/BiosCommon.c + BiosDxe.c + +[LibraryClasses] + BaseMemoryLib + DebugLib + EdkIIRedfishResourceConfigLib + RedfishLib + RedfishFeatureUtilityLib + RedfishVersionLib + RedfishResourceIdentifyLib + UefiLib + UefiDriverEntryPoint + +[Protocols] + gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED + gEfiRestJsonStructureProtocolGuid ## CONSUMED + gEdkIIRedfishResourceConfigProtocolGuid ## PRODUCED + gEdkIIRedfishFeatureProtocolGuid ## CONSUMED + +[Pcd] + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize + +[Depex] + TRUE diff --git a/RedfishClientPkg/RedfishClient.fdf.inc b/RedfishClientPkg/RedfishClient.fdf.inc index 90240efbf7..fa4e53898b 100644 --- a/RedfishClientPkg/RedfishClient.fdf.inc +++ b/RedfishClientPkg/RedfishClient.fdf.inc @@ -18,6 +18,7 @@ INF RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.inf INF RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.inf INF RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf + INF RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf !include RedfishClientPkg/RedfishJsonStructureDxe.fdf.inc # @@ -27,4 +28,5 @@ INF RedfishClientPkg/Converter/MemoryCollection/RedfishMemoryCollection_Dxe.inf INF RedfishClientPkg/Converter/ComputerSystem/v1_5_0/RedfishComputerSystem_V1_5_0_Dxe.inf INF RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerSystemCollection_Dxe.inf + INF RedfishClientPkg/Converter/Bios/v1_0_9/RedfishBios_V1_0_9_Dxe.inf !endif diff --git a/RedfishClientPkg/RedfishClientComponents.dsc.inc b/RedfishClientPkg/RedfishClientComponents.dsc.inc index 084796e4b5..e83f4bc9bf 100644 --- a/RedfishClientPkg/RedfishClientComponents.dsc.inc +++ b/RedfishClientPkg/RedfishClientComponents.dsc.inc @@ -27,6 +27,7 @@ RedfishResourceIdentifyLib|RedfishClientPkg/Library/RedfishResourceIdentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.inf } RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf + RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf !include RedfishClientPkg/RedfishJsonStructureDxe.dsc.inc @@ -37,3 +38,4 @@ RedfishClientPkg/Converter/MemoryCollection/RedfishMemoryCollection_Dxe.inf RedfishClientPkg/Converter/ComputerSystem/v1_5_0/RedfishComputerSystem_V1_5_0_Dxe.inf RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerSystemCollection_Dxe.inf + RedfishClientPkg/Converter/Bios/v1_0_9/RedfishBios_V1_0_9_Dxe.inf diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/RedfishClientLibs.dsc.inc index 05ad09ef5e..fe0c4b0885 100644 --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc @@ -15,12 +15,16 @@ !endif # - # Below two modules should be pulled in by build tool. + # Below modules should be pulled in by build tool. # MemoryV1_7_1Lib|RedfishClientPkg/ConverterLib/edk2library/Memory/v1_7_1/Lib.inf MemoryCollectionLib|RedfishClientPkg/ConverterLib/edk2library/MemoryCollection/Lib.inf ComputerSystemV1_5_0Lib|RedfishClientPkg/ConverterLib/edk2library/ComputerSystem/v1_5_0/Lib.inf ComputerSystemCollectionLib|RedfishClientPkg/ConverterLib/edk2library/ComputerSystemCollection/Lib.inf + BiosV1_0_9Lib|RedfishClientPkg/ConverterLib/edk2library/Bios/v1_0_9/Lib.inf + # + # Above modules should be pulled in by build tool. + # NetLib|NetworkPkg/Library/DxeNetLib/DxeNetLib.inf HttpLib|NetworkPkg/Library/DxeHttpLib/DxeHttpLib.inf -- 2.32.0.windows.2