From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com [40.107.212.82]) by mx.groups.io with SMTP id smtpd.web11.16021.1670422162618467254 for ; Wed, 07 Dec 2022 06:09:22 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=uqI3g5xJ; 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.212.82, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aXJP7VRTCmnMlEZZU/lX00eDZfmkZ9LmCPFbwL7CQRh+xOCoqOTEe+ds47+X07lsY8uYNfVS5TuMD1gn6sz2WCJ5tSBLF/XcL1YGjuUfkyZSgXjZkSj1xzoS6IwgFxmdq9E/qHWjJHQJUULlS7yTSSXvouH1BspGp7KxcJGyiPnXCGlutF+IaqNzABf46NhLjlHNMia3lb8UVCXdZ9qZz2jS5V+NEfQ8fZW8UvM2l4Ukej3+9q6Yz8Ngxj3EMMa4gqhwuAr7kKlc971i47PlFUhGJA2EFUkEpxmWBjwKaDwfEqSlLZlN1OVmjX5/f6+Hlk42lLCuWKFmQxFW5IP6ZA== 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=vMHeeMXBvXrDwZwPzeyF2h5Z9bFr7gJBvoRRcGfzT1U=; b=diRLxOH6m3BiWhHTxp0H+WKKILZszibagGZU8cTWwgop8k0wMIxP/6HTyAPQc39TEc1xqwGyMOCv4IeffJANFn+el/w5EEnGpqoAMrCAEdRWSGDyLiG5ygQgCMFSCQQpjj8JphCPsAcolPHsyldQ4eoezCYAE9OocW/9YnxsxMnTWhZVjtoWG9i3olUeFimxEyiguVRZAD8AdAP8jAuwVInilkHuFwJy4cUuhBS7gyd0G7jOhKCIoX5JSp9DY8r3TTkvZYHZ/YPxuhwEFYCKpZVhws/lYDVG9JWy7fr5UE+Tq+muW8hgdoVhudawQSNqhGwrBAWTxEb++4GltiExkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=vMHeeMXBvXrDwZwPzeyF2h5Z9bFr7gJBvoRRcGfzT1U=; b=uqI3g5xJv5mnqKwDMyDeahp5UUUPosB9HKl77S95pym3Wam1nH23CCY41soxYIdOHsoKQwnC54CD5ULayPk8feSFa0cYIPnVpApvrCwMk1Ch2rwoiPxZzFOLcbJjiAW1RjAj/6Ip7DKaENlls1/0a97EM1NZ45DFaN57XGqO7yZ0dyfOTgM9MRoL+mRsdsgtGlT4MtNibKqGla2y0dgSXsJeDt0xnMl6TUhLdP35KNEUyYPEy4lL0xeCVyKdQoeHTiRTsd3KL/aB/faStRmLRZrR37R7w7jzAA5lI0eAaZcTaAvM9OlAUwjblC7akNYVZvRoBMlRdbJ03VrfoLVIig== Received: from DS7PR03CA0281.namprd03.prod.outlook.com (2603:10b6:5:3ad::16) by DM6PR12MB4316.namprd12.prod.outlook.com (2603:10b6:5:21a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:09:20 +0000 Received: from DM6NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3ad:cafe::e3) by DS7PR03CA0281.outlook.office365.com (2603:10b6:5:3ad::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:09:19 +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 Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT029.mail.protection.outlook.com (10.13.173.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.16 via Frontend Transport; Wed, 7 Dec 2022 14:09:19 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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.986.36; Wed, 7 Dec 2022 06:09:12 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Wed, 7 Dec 2022 06:09:11 -0800 Received: from NV-CL38DL3.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Wed, 7 Dec 2022 06:09:10 -0800 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-staging][PATCH 1/3] edk2-staging/RedfishPkg: Add interface to get question default value Date: Wed, 7 Dec 2022 22:09:10 +0800 Message-ID: <20221207140910.124-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: DM6NAM11FT029:EE_|DM6PR12MB4316:EE_ X-MS-Office365-Filtering-Correlation-Id: e7eb0857-cb48-40de-8b07-08dad85ca269 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v6G/D4bsD/vV4wdVZBKgBg4ptAu7XUCwwJVc+Xmyi+2zJBxHo4dbSS6pjKkqacKG6x3B/r+yLzSHU1rr1AEnd7ynwTjlbgfMj6f9A/+GbfcJZUfLY/9Nm4G1pmByVgeY/qPSbah9mM8TRPG7wmNS3I6Ce1u/0gqmCr5djmDtUOVJ30/nXdS7dTV4p6AJKm81+0seZxS8Rbrgk1TGk9TB1bTyYx45TkLhNBHwBxZjnYEu0AzsqCtfzi6eLU8qFyYx4xyWviAA1iqYNZ1/y3ccKZfC7S2hbC7w1QCyNm3MDcIE0Amlzy1GUuQnc7BpZ058eo3jQa+q5PRpZYA39rJutmbMQ5yUUcoq1li6kJpSeiduMeOFPkEWJY0tz0G45ptra+Dg9kP9V3/oYEB2p/+ao1ZwlJOVb9vYqSrf7FXFjTrm8QszPx6yldC7fZ9R7nYZlEYHjyslNZAlWDwDaDks5hz60pMXG8/OpilOpmnXPTtZNFvigzjItMCDYH9KtjSJtRE3TWITI0cgRG8pH9iwPndV8HcNQYmreQn3k+iT/jjw2SN8QqF4HcbtG3pwa1izbplv8gKn9qGXlm6DSQmZVsPC6JwG7pUtwHRTHBnzEpPPeFUHGORhn9qkpYU+xy3IxNkLVX+jSXRKyyQAcrv4vh/MVQRdsoi0rz7hy4YOHG/pJKnkB3FR3477OF3VVJ/vD4dlb08FxqWMN/1+V3V0Vw== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(136003)(346002)(376002)(451199015)(40470700004)(46966006)(36840700001)(86362001)(70206006)(40460700003)(36756003)(82310400005)(40480700001)(186003)(1076003)(41300700001)(70586007)(336012)(4326008)(8936002)(8676002)(30864003)(47076005)(5660300002)(2616005)(7696005)(6916009)(66574015)(316002)(54906003)(107886003)(478600001)(426003)(26005)(356005)(7636003)(82740400003)(36860700001)(2906002)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:09:19.8357 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e7eb0857-cb48-40de-8b07-08dad85ca269 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: DM6NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4316 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Implement GetQuestionDefault() in HiiUtilityLib. Caller can get question default value from this interface. GetQuestionDefault() is created and modifed from SetupBrowserDxe\Setup.c under MdeModulePkg. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- RedfishPkg/Include/Library/HiiUtilityLib.h | 31 +- .../Library/HiiUtilityLib/HiiExpression.c | 77 +++ .../Library/HiiUtilityLib/HiiExpression.h | 23 + .../HiiUtilityLib/HiiUtilityInternal.c | 614 ++++++++++++++++++ 4 files changed, 728 insertions(+), 17 deletions(-) diff --git a/RedfishPkg/Include/Library/HiiUtilityLib.h b/RedfishPkg/Includ= e/Library/HiiUtilityLib.h index 1f164ba49c..f4be485423 100644 --- a/RedfishPkg/Include/Library/HiiUtilityLib.h +++ b/RedfishPkg/Include/Library/HiiUtilityLib.h @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -1168,28 +1169,24 @@ GetHiiExpressionDependency ( ); =20 /** - Evaluate the result of a HII expression. - - If Expression is NULL, then ASSERT. + Get default value of question. =20 - @param FormSet FormSet associated with this expression. - @param Form Form associated with this expression. - @param Expression Expression to be evaluated. + @param FormSet The form set. + @param Form The form. + @param Question The question. + @param DefaultId The Class of the default. + @param DefaultValue The default value of given question. =20 - @retval EFI_SUCCESS The expression evaluated successfuly - @retval EFI_NOT_FOUND The Question which referenced by a Questi= onId - could not be found. - @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow= the - stack. - @retval EFI_ACCESS_DENIED The pop operation underflowed the stack - @retval EFI_INVALID_PARAMETER Syntax error with the Expression + @retval EFI_SUCCESS Question is reset to default value. =20 **/ EFI_STATUS -HpEvaluateHiiExpression ( - IN HII_FORMSET *FormSet, - IN HII_FORM *Form, - IN OUT HII_EXPRESSION *Expression +GetQuestionDefault ( + IN HII_FORMSET *FormSet, + IN HII_FORM *Form, + IN HII_STATEMENT *Question, + IN UINT16 DefaultId, + OUT HII_STATEMENT_VALUE *DefaultValue ); =20 #endif // _HII_UTILITY_LIB_ diff --git a/RedfishPkg/Library/HiiUtilityLib/HiiExpression.c b/RedfishPkg/= Library/HiiUtilityLib/HiiExpression.c index 7111b40acf..c6954587f5 100644 --- a/RedfishPkg/Library/HiiUtilityLib/HiiExpression.c +++ b/RedfishPkg/Library/HiiUtilityLib/HiiExpression.c @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -1365,3 +1366,79 @@ GetHiiExpressionDependency ( Done: return Status; } + +/** + Return the result of the expression list. Check the expression list and + return the highest priority express result. + Priority: DisableIf > SuppressIf > GrayOutIf > FALSE + + @param ExpList The input expression list. + @param Evaluate Whether need to evaluate the expression firs= t. + @param FormSet FormSet associated with this expression. + @param Form Form associated with this expression. + + @retval EXPRESS_RESULT Return the higher priority express result. + DisableIf > SuppressIf > GrayOutIf > FALSE + +**/ +EXPRESS_RESULT +EvaluateExpressionList ( + IN HII_EXPRESSION_LIST *ExpList, + IN BOOLEAN Evaluate, + IN HII_FORMSET *FormSet, OPTIONAL + IN HII_FORM *Form OPTIONAL + ) +{ + UINTN Index; + EXPRESS_RESULT ReturnVal; + EXPRESS_RESULT CompareOne; + EFI_STATUS Status; + + if (ExpList =3D=3D NULL) { + return ExpressFalse; + } + + ASSERT (ExpList->Signature =3D=3D HII_EXPRESSION_LIST_SIGNATURE); + Index =3D 0; + + // + // Check whether need to evaluate the expression first. + // + if (Evaluate) { + while (ExpList->Count > Index) { + Status =3D EvaluateHiiExpression (FormSet, Form, ExpList->Expression= [Index++]); + if (EFI_ERROR (Status)) { + return ExpressFalse; + } + } + } + + // + // Run the list of expressions. + // + ReturnVal =3D ExpressFalse; + for (Index =3D 0; Index < ExpList->Count; Index++) { + if (IsTrue (&ExpList->Expression[Index]->Result)) { + switch (ExpList->Expression[Index]->Type) { + case EFI_HII_EXPRESSION_SUPPRESS_IF: + CompareOne =3D ExpressSuppress; + break; + + case EFI_HII_EXPRESSION_GRAY_OUT_IF: + CompareOne =3D ExpressGrayOut; + break; + + case EFI_HII_EXPRESSION_DISABLE_IF: + CompareOne =3D ExpressDisable; + break; + + default: + return ExpressFalse; + } + + ReturnVal =3D ReturnVal < CompareOne ? CompareOne : ReturnVal; + } + } + + return ReturnVal; +} diff --git a/RedfishPkg/Library/HiiUtilityLib/HiiExpression.h b/RedfishPkg/= Library/HiiUtilityLib/HiiExpression.h index e96c07b4de..25a3a44b48 100644 --- a/RedfishPkg/Library/HiiUtilityLib/HiiExpression.h +++ b/RedfishPkg/Library/HiiUtilityLib/HiiExpression.h @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -187,4 +188,26 @@ PopScope ( OUT UINT8 *Operand ); =20 +/** + Return the result of the expression list. Check the expression list and + return the highest priority express result. + Priority: DisableIf > SuppressIf > GrayOutIf > FALSE + + @param ExpList The input expression list. + @param Evaluate Whether need to evaluate the expression firs= t. + @param FormSet FormSet associated with this expression. + @param Form Form associated with this expression. + + @retval EXPRESS_RESULT Return the higher priority express result. + DisableIf > SuppressIf > GrayOutIf > FALSE + +**/ +EXPRESS_RESULT +EvaluateExpressionList ( + IN HII_EXPRESSION_LIST *ExpList, + IN BOOLEAN Evaluate, + IN HII_FORMSET *FormSet, OPTIONAL + IN HII_FORM *Form OPTIONAL + ); + #endif diff --git a/RedfishPkg/Library/HiiUtilityLib/HiiUtilityInternal.c b/Redfis= hPkg/Library/HiiUtilityLib/HiiUtilityInternal.c index 55b78315d1..b4dd61f360 100644 --- a/RedfishPkg/Library/HiiUtilityLib/HiiUtilityInternal.c +++ b/RedfishPkg/Library/HiiUtilityLib/HiiUtilityInternal.c @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -5043,3 +5044,616 @@ Done: =20 return Status; } + +/** + Set value of a data element in an Array by its Index. + + @param Array The data array. + @param Type Type of the data in this array. + @param Index Zero based index for data in this array. + @param Value The value to be set. + +**/ +VOID +SetArrayData ( + IN VOID *Array, + IN UINT8 Type, + IN UINTN Index, + IN UINT64 Value + ) +{ + ASSERT (Array !=3D NULL); + + switch (Type) { + case EFI_IFR_TYPE_NUM_SIZE_8: + *(((UINT8 *)Array) + Index) =3D (UINT8)Value; + break; + + case EFI_IFR_TYPE_NUM_SIZE_16: + *(((UINT16 *)Array) + Index) =3D (UINT16)Value; + break; + + case EFI_IFR_TYPE_NUM_SIZE_32: + *(((UINT32 *)Array) + Index) =3D (UINT32)Value; + break; + + case EFI_IFR_TYPE_NUM_SIZE_64: + *(((UINT64 *)Array) + Index) =3D (UINT64)Value; + break; + + default: + break; + } +} + +/** + Search an Option of a Question by its value. + + @param Question The Question + @param OptionValue Value for Option to be searched. + + @retval Pointer Pointer to the found Option. + @retval NULL Option not found. + +**/ +HII_QUESTION_OPTION * +ValueToOption ( + IN HII_STATEMENT *Question, + IN HII_STATEMENT_VALUE *OptionValue + ) +{ + LIST_ENTRY *Link; + HII_QUESTION_OPTION *Option; + EFI_HII_VALUE Data1; + EFI_HII_VALUE Data2; + INTN Result; + EFI_STATUS Status; + + Status =3D HiiStatementValueToHiiValue (OptionValue, &Data1); + ASSERT_EFI_ERROR (Status); + + Link =3D GetFirstNode (&Question->OptionListHead); + while (!IsNull (&Question->OptionListHead, Link)) { + Option =3D HII_QUESTION_OPTION_FROM_LINK (Link); + + Status =3D HiiStatementValueToHiiValue (&Option->Value, &Data2); + ASSERT_EFI_ERROR (Status); + + if ((CompareHiiValue (&Data1, &Data2, &Result, NULL) =3D=3D EFI_SUCCES= S) && (Result =3D=3D 0)) { + // + // Check the suppressif condition, only a valid option can be return= . + // + if ((Option->SuppressExpression =3D=3D NULL) || + ((EvaluateExpressionList (Option->SuppressExpression, FALSE, NUL= L, NULL) =3D=3D ExpressFalse))) + { + return Option; + } + } + + Link =3D GetNextNode (&Question->OptionListHead, Link); + } + + return NULL; +} + +/** + Find the point in the ConfigResp string for this question. + + @param Question The question. + @param ConfigResp Get ConfigResp string. + + @retval point to the offset where is for this question. + +**/ +CHAR16 * +GetOffsetFromConfigResp ( + IN HII_STATEMENT *Question, + IN CHAR16 *ConfigResp + ) +{ + CHAR16 *RequestElement; + CHAR16 *BlockData; + + // + // Type is EFI_HII_VARSTORE_NAME_VALUE. + // + if (Question->Storage->Type =3D=3D EFI_HII_VARSTORE_NAME_VALUE) { + RequestElement =3D StrStr (ConfigResp, Question->VariableName); + if (RequestElement !=3D NULL) { + // + // Skip the "VariableName=3D" field. + // + RequestElement +=3D StrLen (Question->VariableName) + 1; + } + + return RequestElement; + } + + // + // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABL= E_BUFFER + // + + // + // Convert all hex digits in ConfigResp to lower case before searching. + // + HiiToLower (ConfigResp); + + // + // 1. Directly use Question->BlockName to find. + // + RequestElement =3D StrStr (ConfigResp, Question->BlockName); + if (RequestElement !=3D NULL) { + // + // Skip the "Question->BlockName&VALUE=3D" field. + // + RequestElement +=3D StrLen (Question->BlockName) + StrLen (L"&VALUE=3D= "); + return RequestElement; + } + + // + // 2. Change all hex digits in Question->BlockName to lower and compare = again. + // + BlockData =3D AllocateCopyPool (StrSize (Question->BlockName), Question-= >BlockName); + ASSERT (BlockData !=3D NULL); + HiiToLower (BlockData); + RequestElement =3D StrStr (ConfigResp, BlockData); + FreePool (BlockData); + + if (RequestElement !=3D NULL) { + // + // Skip the "Question->BlockName&VALUE=3D" field. + // + RequestElement +=3D StrLen (Question->BlockName) + StrLen (L"&VALUE=3D= "); + } + + return RequestElement; +} + +/** + Get Question default value from AltCfg string. + + @param FormSet The form set. + @param Form The form + @param Question The question. + @param DefaultValue Default value. + + @retval EFI_SUCCESS Question is reset to default value. + +**/ +EFI_STATUS +GetDefaultValueFromAltCfg ( + IN HII_FORMSET *FormSet, + IN HII_FORM *Form, + IN HII_STATEMENT *Question, + OUT HII_STATEMENT_VALUE *DefaultValue + ) +{ + HII_FORMSET_STORAGE *Storage; + CHAR16 *ConfigResp; + CHAR16 *Value; + LIST_ENTRY *Link; + HII_FORM_CONFIG_REQUEST *ConfigInfo; + + Storage =3D Question->Storage; + if ((Storage =3D=3D NULL) || (Storage->Type =3D=3D EFI_HII_VARSTORE_EFI_= VARIABLE)) { + return EFI_NOT_FOUND; + } + + // + // Try to get AltCfg string from form. If not found it, then + // try to get it from formset. + // + ConfigResp =3D NULL; + Link =3D GetFirstNode (&Form->ConfigRequestHead); + while (!IsNull (&Form->ConfigRequestHead, Link)) { + ConfigInfo =3D HII_FORM_CONFIG_REQUEST_FROM_LINK (Link); + Link =3D GetNextNode (&Form->ConfigRequestHead, Link); + + if (Storage =3D=3D ConfigInfo->Storage) { + ConfigResp =3D ConfigInfo->ConfigAltResp; + break; + } + } + + if (ConfigResp =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + Value =3D GetOffsetFromConfigResp (Question, ConfigResp); + if (Value =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + return BufferToValue (Question, Value, DefaultValue); +} + +/** + Get default Id value used for browser. + + @param DefaultId The default id value used by hii. + + @retval Browser used default value. + +**/ +INTN +GetDefaultIdForCallBack ( + UINTN DefaultId + ) +{ + if (DefaultId =3D=3D EFI_HII_DEFAULT_CLASS_STANDARD) { + return EFI_BROWSER_ACTION_DEFAULT_STANDARD; + } else if (DefaultId =3D=3D EFI_HII_DEFAULT_CLASS_MANUFACTURING) { + return EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING; + } else if (DefaultId =3D=3D EFI_HII_DEFAULT_CLASS_SAFE) { + return EFI_BROWSER_ACTION_DEFAULT_SAFE; + } else if ((DefaultId >=3D EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN) && (Def= aultId < EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN + 0x1000)) { + return EFI_BROWSER_ACTION_DEFAULT_PLATFORM + DefaultId - EFI_HII_DEFAU= LT_CLASS_PLATFORM_BEGIN; + } else if ((DefaultId >=3D EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN) && (Def= aultId < EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN + 0x1000)) { + return EFI_BROWSER_ACTION_DEFAULT_HARDWARE + DefaultId - EFI_HII_DEFAU= LT_CLASS_HARDWARE_BEGIN; + } else if ((DefaultId >=3D EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN) && (Def= aultId < EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN + 0x1000)) { + return EFI_BROWSER_ACTION_DEFAULT_FIRMWARE + DefaultId - EFI_HII_DEFAU= LT_CLASS_FIRMWARE_BEGIN; + } else { + return -1; + } +} + +/** + Get default value of question. + + @param FormSet The form set. + @param Form The form. + @param Question The question. + @param DefaultId The Class of the default. + @param DefaultValue The default value of given question. + + @retval EFI_SUCCESS Question is reset to default value. + +**/ +EFI_STATUS +GetQuestionDefault ( + IN HII_FORMSET *FormSet, + IN HII_FORM *Form, + IN HII_STATEMENT *Question, + IN UINT16 DefaultId, + OUT HII_STATEMENT_VALUE *DefaultValue + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + HII_QUESTION_DEFAULT *Default; + HII_QUESTION_OPTION *Option; + HII_STATEMENT_VALUE *HiiValue; + UINT8 Index; + EFI_STRING StrValue; + EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; + EFI_BROWSER_ACTION_REQUEST ActionRequest; + INTN Action; + EFI_IFR_TYPE_VALUE *TypeValue; + UINT16 OriginalDefaultId; + HII_FORMSET_DEFAULTSTORE *DefaultStore; + LIST_ENTRY *DefaultLink; + + if ((FormSet =3D=3D NULL) || (Form =3D=3D NULL) || (Question =3D=3D NULL= ) || (DefaultValue =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D EFI_NOT_FOUND; + StrValue =3D NULL; + OriginalDefaultId =3D DefaultId; + DefaultLink =3D GetFirstNode (&FormSet->DefaultStoreListHead); + + // + // Statement don't have storage, skip them + // + if (Question->QuestionId =3D=3D 0) { + return Status; + } + + // + // There are Five ways to specify default value for a Question: + // 1, use call back function (highest priority) + // 2, use ExtractConfig function + // 3, use nested EFI_IFR_DEFAULT + // 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturin= g default) + // 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing= default) (lowest priority) + // + CopyMem (DefaultValue, &Question->Value, sizeof (HII_STATEMENT_VALUE)); +ReGetDefault: + HiiValue =3D DefaultValue; + TypeValue =3D &HiiValue->Value; + if (HiiValue->Type =3D=3D EFI_IFR_TYPE_BUFFER) { + // + // For orderedlist, need to pass the BufferValue to Callback function. + // + DefaultValue->BufferLen =3D Question->Value.BufferLen; + DefaultValue->Buffer =3D AllocateZeroPool (DefaultValue->BufferLen)= ; + ASSERT (DefaultValue->Buffer !=3D NULL); + if (DefaultValue->Buffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + TypeValue =3D (EFI_IFR_TYPE_VALUE *)DefaultValue->Buffer; + } + + // + // Get Question defaut value from call back function. + // The string type of question cause HII driver to set string to its def= ault value. + // So, we don't do this otherwise it will actually set question to defau= lt value. + // We only want to get default value of question. + // + if (HiiValue->Type !=3D EFI_IFR_TYPE_STRING) { + ConfigAccess =3D FormSet->ConfigAccess; + Action =3D GetDefaultIdForCallBack (DefaultId); + if ((Action > 0) && ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK)= !=3D 0) && (ConfigAccess !=3D NULL)) { + ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_NONE; + Status =3D ConfigAccess->Callback ( + ConfigAccess, + Action, + Question->QuestionId, + HiiValue->Type, + TypeValue, + &ActionRequest + ); + if (!EFI_ERROR (Status)) { + return Status; + } + } + } + + // + // Get default value from altcfg string. + // + if (ConfigAccess !=3D NULL) { + Status =3D GetDefaultValueFromAltCfg (FormSet, Form, Question, Default= Value); + if (!EFI_ERROR (Status)) { + return Status; + } + } + + // + // EFI_IFR_DEFAULT has highest priority + // + if (!IsListEmpty (&Question->DefaultListHead)) { + Link =3D GetFirstNode (&Question->DefaultListHead); + while (!IsNull (&Question->DefaultListHead, Link)) { + Default =3D HII_QUESTION_DEFAULT_FROM_LINK (Link); + + if (Default->DefaultId =3D=3D DefaultId) { + if (Default->ValueExpression !=3D NULL) { + // + // Default is provided by an Expression, evaluate it + // + Status =3D EvaluateHiiExpression (FormSet, Form, Default->ValueE= xpression); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Default->ValueExpression->Result.Type =3D=3D EFI_IFR_TYPE_BU= FFER) { + ASSERT (HiiValue->Type =3D=3D EFI_IFR_TYPE_BUFFER && DefaultVa= lue->Buffer !=3D NULL); + if (DefaultValue->BufferLen > Default->ValueExpression->Result= .BufferLen) { + CopyMem (DefaultValue->Buffer, Default->ValueExpression->Res= ult.Buffer, Default->ValueExpression->Result.BufferLen); + DefaultValue->BufferLen =3D Default->ValueExpression->Result= .BufferLen; + } else { + CopyMem (DefaultValue->Buffer, Default->ValueExpression->Res= ult.Buffer, DefaultValue->BufferLen); + } + + FreePool (Default->ValueExpression->Result.Buffer); + } + + HiiValue->Type =3D Default->ValueExpression->Result.Type; + CopyMem (&HiiValue->Value, &Default->ValueExpression->Result.Val= ue, sizeof (EFI_IFR_TYPE_VALUE)); + } else { + // + // Default value is embedded in EFI_IFR_DEFAULT + // + if (Default->Value.Type =3D=3D EFI_IFR_TYPE_BUFFER) { + ASSERT (HiiValue->Buffer !=3D NULL); + CopyMem (HiiValue->Buffer, Default->Value.Buffer, Default->Val= ue.BufferLen); + } else { + CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE)); + } + } + + if (HiiValue->Type =3D=3D EFI_IFR_TYPE_STRING) { + StrValue =3D HiiGetString (FormSet->HiiHandle, HiiValue->Value.s= tring, NULL); + if (StrValue =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + if (DefaultValue->BufferLen > StrSize (StrValue)) { + ZeroMem (DefaultValue->Buffer, DefaultValue->BufferLen); + CopyMem (DefaultValue->Buffer, StrValue, StrSize (StrValue)); + } else { + CopyMem (DefaultValue->Buffer, StrValue, DefaultValue->BufferL= en); + } + } + + return EFI_SUCCESS; + } + + Link =3D GetNextNode (&Question->DefaultListHead, Link); + } + } + + // + // EFI_ONE_OF_OPTION + // + if ((Question->Operand =3D=3D EFI_IFR_ONE_OF_OP) && !IsListEmpty (&Quest= ion->OptionListHead)) { + if (DefaultId <=3D EFI_HII_DEFAULT_CLASS_MANUFACTURING) { + // + // OneOfOption could only provide Standard and Manufacturing default + // + Link =3D GetFirstNode (&Question->OptionListHead); + while (!IsNull (&Question->OptionListHead, Link)) { + Option =3D HII_QUESTION_OPTION_FROM_LINK (Link); + Link =3D GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression !=3D NULL) && + (EvaluateExpressionList (Option->SuppressExpression, FALSE, NU= LL, NULL) !=3D ExpressFalse)) + { + continue; + } + + if (((DefaultId =3D=3D EFI_HII_DEFAULT_CLASS_STANDARD) && ((Option= ->Flags & EFI_IFR_OPTION_DEFAULT) !=3D 0)) || + ((DefaultId =3D=3D EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((O= ption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) !=3D 0)) + ) + { + CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE)); + + return EFI_SUCCESS; + } + } + } + } + + // + // EFI_IFR_CHECKBOX - lowest priority + // + if (Question->Operand =3D=3D EFI_IFR_CHECKBOX_OP) { + if (DefaultId <=3D EFI_HII_DEFAULT_CLASS_MANUFACTURING) { + // + // Checkbox could only provide Standard and Manufacturing default + // + if (((DefaultId =3D=3D EFI_HII_DEFAULT_CLASS_STANDARD) && ((Question= ->ExtraData.Flags & EFI_IFR_CHECKBOX_DEFAULT) !=3D 0)) || + ((DefaultId =3D=3D EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Que= stion->ExtraData.Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) !=3D 0)) + ) + { + HiiValue->Value.b =3D TRUE; + } + + return EFI_SUCCESS; + } + } + + // + // For question without default value for current default Id, we try to = re-get the default value form other default id in the DefaultStoreList. + // If get, will exit the function, if not, will choose next default id i= n the DefaultStoreList. + // The default id in DefaultStoreList are in ascending order to make sur= e choose the smallest default id every time. + // + while (!IsNull (&FormSet->DefaultStoreListHead, DefaultLink)) { + DefaultStore =3D HII_FORMSET_DEFAULTSTORE_FROM_LINK (DefaultLink); + DefaultLink =3D GetNextNode (&FormSet->DefaultStoreListHead, DefaultL= ink); + DefaultId =3D DefaultStore->DefaultId; + if (DefaultId =3D=3D OriginalDefaultId) { + continue; + } + + goto ReGetDefault; + } + + // + // For Questions without default value for all the default id in the Def= aultStoreList. + // + Status =3D EFI_NOT_FOUND; + switch (Question->Operand) { + case EFI_IFR_CHECKBOX_OP: + HiiValue->Value.b =3D FALSE; + Status =3D EFI_SUCCESS; + break; + + case EFI_IFR_NUMERIC_OP: + // + // Take minimum value as numeric default value + // + if ((Question->ExtraData.NumData.Flags & EFI_IFR_DISPLAY) =3D=3D 0) = { + // + // In EFI_IFR_DISPLAY_INT_DEC type, should check value with int* t= ype. + // + switch (Question->ExtraData.NumData.Flags & EFI_IFR_NUMERIC_SIZE) = { + case EFI_IFR_NUMERIC_SIZE_1: + if (((INT8)HiiValue->Value.u8 < (INT8)Question->ExtraData.NumD= ata.Minimum) || ((INT8)HiiValue->Value.u8 > (INT8)Question->ExtraData.NumDa= ta.Maximum)) { + HiiValue->Value.u8 =3D (UINT8)Question->ExtraData.NumData.Mi= nimum; + Status =3D EFI_SUCCESS; + } + + break; + case EFI_IFR_NUMERIC_SIZE_2: + if (((INT16)HiiValue->Value.u16 < (INT16)Question->ExtraData.N= umData.Minimum) || ((INT16)HiiValue->Value.u16 > (INT16)Question->ExtraData= .NumData.Maximum)) { + HiiValue->Value.u16 =3D (UINT16)Question->ExtraData.NumData.= Minimum; + Status =3D EFI_SUCCESS; + } + + break; + case EFI_IFR_NUMERIC_SIZE_4: + if (((INT32)HiiValue->Value.u32 < (INT32)Question->ExtraData.N= umData.Minimum) || ((INT32)HiiValue->Value.u32 > (INT32)Question->ExtraData= .NumData.Maximum)) { + HiiValue->Value.u32 =3D (UINT32)Question->ExtraData.NumData.= Minimum; + Status =3D EFI_SUCCESS; + } + + break; + case EFI_IFR_NUMERIC_SIZE_8: + if (((INT64)HiiValue->Value.u64 < (INT64)Question->ExtraData.N= umData.Minimum) || ((INT64)HiiValue->Value.u64 > (INT64)Question->ExtraData= .NumData.Maximum)) { + HiiValue->Value.u64 =3D Question->ExtraData.NumData.Minimum; + Status =3D EFI_SUCCESS; + } + + break; + default: + break; + } + } else { + if ((HiiValue->Value.u64 < Question->ExtraData.NumData.Minimum) ||= (HiiValue->Value.u64 > Question->ExtraData.NumData.Maximum)) { + HiiValue->Value.u64 =3D Question->ExtraData.NumData.Minimum; + Status =3D EFI_SUCCESS; + } + } + + break; + + case EFI_IFR_ONE_OF_OP: + // + // Take first oneof option as oneof's default value + // + if (ValueToOption (Question, HiiValue) =3D=3D NULL) { + Link =3D GetFirstNode (&Question->OptionListHead); + while (!IsNull (&Question->OptionListHead, Link)) { + Option =3D HII_QUESTION_OPTION_FROM_LINK (Link); + Link =3D GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression !=3D NULL) && + (EvaluateExpressionList (Option->SuppressExpression, FALSE, = NULL, NULL) !=3D ExpressFalse)) + { + continue; + } + + CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE)); + Status =3D EFI_SUCCESS; + break; + } + } + + break; + + case EFI_IFR_ORDERED_LIST_OP: + // + // Take option sequence in IFR as ordered list's default value + // + Index =3D 0; + Link =3D GetFirstNode (&Question->OptionListHead); + while (!IsNull (&Question->OptionListHead, Link)) { + Status =3D EFI_SUCCESS; + Option =3D HII_QUESTION_OPTION_FROM_LINK (Link); + Link =3D GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression !=3D NULL) && + (EvaluateExpressionList (Option->SuppressExpression, FALSE, NU= LL, NULL) !=3D ExpressFalse)) + { + continue; + } + + SetArrayData (DefaultValue->Buffer, Question->Value.Type, Index, O= ption->Value.Value.u64); + + Index++; + if (Index >=3D Question->ExtraData.OrderListData.MaxContainers) { + break; + } + } + + break; + + default: + break; + } + + return Status; +} --=20 2.38.1.windows.1