+/**\r
+ Get value from config request resp string.\r
+\r
+ @param ConfigElement ConfigResp string contains the current setting.\r
+ @param VarName The variable name which need to get value.\r
+ @param VarValue The return value.\r
+ \r
+ @retval EFI_SUCCESS Get the value for the VarName\r
+ @retval EFI_OUT_OF_RESOURCES The memory is not enough.\r
+**/\r
+EFI_STATUS\r
+GetValueFromRequest (\r
+ IN CHAR16 *ConfigElement,\r
+ IN CHAR16 *VarName,\r
+ OUT UINT64 *VarValue\r
+ )\r
+{\r
+ UINT8 *TmpBuffer;\r
+ CHAR16 *StringPtr;\r
+ UINTN Length;\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Find VarName related string.\r
+ //\r
+ StringPtr = StrStr (ConfigElement, VarName);\r
+ ASSERT (StringPtr != NULL);\r
+\r
+ //\r
+ // Skip the "VarName=" string\r
+ //\r
+ StringPtr += StrLen (VarName) + 1;\r
+\r
+ //\r
+ // Get Offset\r
+ //\r
+ Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ *VarValue = 0;\r
+ CopyMem (VarValue, TmpBuffer, (((Length + 1) / 2) < sizeof (UINT64)) ? ((Length + 1) / 2) : sizeof (UINT64));\r
+\r
+ FreePool (TmpBuffer);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ This internal function parses IFR data to validate current setting.\r
+\r
+ Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid;\r
+ else the VarBuffer and CurrentBlockArray is valid.\r
+\r
+ @param HiiPackageList Point to Hii package list.\r
+ @param PackageListLength The length of the pacakge.\r
+ @param VarGuid Guid of the buffer storage.\r
+ @param VarName Name of the buffer storage.\r
+ @param VarBuffer The data buffer for the storage.\r
+ @param CurrentBlockArray The block array from the config Requst string.\r
+ @param RequestElement The config string for this storage.\r
+ @param HiiHandle The HiiHandle for this formset.\r
+ @param NameValueType Whether current storage is name/value varstore or not.\r
+ \r
+ @retval EFI_SUCCESS The current setting is valid.\r
+ @retval EFI_OUT_OF_RESOURCES The memory is not enough.\r
+ @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.\r
+**/\r
+EFI_STATUS\r
+ValidateQuestionFromVfr (\r
+ IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList,\r
+ IN UINTN PackageListLength,\r
+ IN EFI_GUID *VarGuid,\r
+ IN CHAR16 *VarName,\r
+ IN UINT8 *VarBuffer,\r
+ IN IFR_BLOCK_DATA *CurrentBlockArray,\r
+ IN CHAR16 *RequestElement,\r
+ IN EFI_HII_HANDLE HiiHandle,\r
+ IN BOOLEAN NameValueType\r
+ )\r
+{\r
+ IFR_BLOCK_DATA VarBlockData;\r
+ UINT16 Offset;\r
+ UINT16 Width;\r
+ UINT64 VarValue;\r
+ EFI_IFR_TYPE_VALUE TmpValue;\r
+ EFI_STATUS Status;\r
+ EFI_HII_PACKAGE_HEADER PackageHeader;\r
+ UINT32 PackageOffset;\r
+ UINT8 *PackageData;\r
+ UINTN IfrOffset;\r
+ EFI_IFR_OP_HEADER *IfrOpHdr;\r
+ EFI_IFR_VARSTORE *IfrVarStore;\r
+ EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueStore;\r
+ EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;\r
+ IFR_VARSTORAGE_DATA VarStoreData;\r
+ EFI_IFR_ONE_OF *IfrOneOf;\r
+ EFI_IFR_NUMERIC *IfrNumeric;\r
+ EFI_IFR_ONE_OF_OPTION *IfrOneOfOption;\r
+ EFI_IFR_CHECKBOX *IfrCheckBox;\r
+ EFI_IFR_STRING *IfrString;\r
+ CHAR8 *VarStoreName;\r
+ UINTN Index;\r
+ CHAR16 *QuestionName;\r
+ CHAR16 *StringPtr;\r
+\r
+ //\r
+ // Initialize the local variables.\r
+ //\r
+ Index = 0;\r
+ VarStoreName = NULL;\r
+ Status = EFI_SUCCESS;\r
+ VarValue = 0;\r
+ IfrVarStore = NULL;\r
+ IfrNameValueStore = NULL;\r
+ IfrEfiVarStore = NULL;\r
+ ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA));\r
+ ZeroMem (&VarBlockData, sizeof (VarBlockData));\r
+\r
+ //\r
+ // Check IFR value is in block data, then Validate Value\r
+ //\r
+ PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
+ while (PackageOffset < PackageListLength) {\r
+ CopyMem (&PackageHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PackageHeader));\r
+\r
+ //\r
+ // Parse IFR opcode from the form package.\r
+ //\r
+ if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {\r
+ IfrOffset = sizeof (PackageHeader);\r
+ PackageData = (UINT8 *) HiiPackageList + PackageOffset;\r
+ while (IfrOffset < PackageHeader.Length) {\r
+ IfrOpHdr = (EFI_IFR_OP_HEADER *) (PackageData + IfrOffset);\r
+ //\r
+ // Validate current setting to the value built in IFR opcode\r
+ //\r
+ switch (IfrOpHdr->OpCode) {\r
+ case EFI_IFR_VARSTORE_OP:\r
+ //\r
+ // VarStoreId has been found. No further found.\r
+ //\r
+ if (VarStoreData.VarStoreId != 0) {\r
+ break;\r
+ }\r
+ //\r
+ // Find the matched VarStoreId to the input VarGuid and VarName\r
+ //\r
+ IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr;\r
+ if (CompareGuid ((EFI_GUID *) (VOID *) &IfrVarStore->Guid, VarGuid)) {\r
+ VarStoreName = (CHAR8 *) IfrVarStore->Name;\r
+ for (Index = 0; VarStoreName[Index] != 0; Index ++) {\r
+ if ((CHAR16) VarStoreName[Index] != VarName[Index]) {\r
+ break;\r
+ }\r
+ }\r
+ //\r
+ // The matched VarStore is found.\r
+ //\r
+ if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) {\r
+ IfrVarStore = NULL;\r
+ }\r
+ } else {\r
+ IfrVarStore = NULL;\r
+ }\r
+\r
+ if (IfrVarStore != NULL) {\r
+ VarStoreData.VarStoreId = IfrVarStore->VarStoreId;\r
+ VarStoreData.Size = IfrVarStore->Size;\r
+ }\r
+ break;\r
+ case EFI_IFR_VARSTORE_NAME_VALUE_OP:\r
+ //\r
+ // VarStoreId has been found. No further found.\r
+ //\r
+ if (VarStoreData.VarStoreId != 0) {\r
+ break;\r
+ }\r
+ //\r
+ // Find the matched VarStoreId to the input VarGuid\r
+ //\r
+ IfrNameValueStore = (EFI_IFR_VARSTORE_NAME_VALUE *) IfrOpHdr;\r
+ if (!CompareGuid ((EFI_GUID *) (VOID *) &IfrNameValueStore->Guid, VarGuid)) {\r
+ IfrNameValueStore = NULL;\r
+ }\r
+\r
+ if (IfrNameValueStore != NULL) {\r
+ VarStoreData.VarStoreId = IfrNameValueStore->VarStoreId;\r
+ }\r
+ break;\r
+ case EFI_IFR_VARSTORE_EFI_OP:\r
+ //\r
+ // VarStore is found. Don't need to search any more.\r
+ //\r
+ if (VarStoreData.VarStoreId != 0) {\r
+ break;\r
+ }\r
+\r
+ IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;\r
+\r
+ //\r
+ // If the length is small than the structure, this is from old efi \r
+ // varstore definition. Old efi varstore get config directly from \r
+ // GetVariable function.\r
+ //\r
+ if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) {\r
+ break;\r
+ }\r
+\r
+ if (CompareGuid ((EFI_GUID *) (VOID *) &IfrEfiVarStore->Guid, VarGuid)) {\r
+ VarStoreName = (CHAR8 *) IfrEfiVarStore->Name;\r
+ for (Index = 0; VarStoreName[Index] != 0; Index ++) {\r
+ if ((CHAR16) VarStoreName[Index] != VarName[Index]) {\r
+ break;\r
+ }\r
+ }\r
+ //\r
+ // The matched VarStore is found.\r
+ //\r
+ if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) {\r
+ IfrEfiVarStore = NULL;\r
+ }\r
+ } else {\r
+ IfrEfiVarStore = NULL;\r
+ }\r
+\r
+ if (IfrEfiVarStore != NULL) {\r
+ //\r
+ // Find the matched VarStore\r
+ //\r
+ VarStoreData.VarStoreId = IfrEfiVarStore->VarStoreId;\r
+ VarStoreData.Size = IfrEfiVarStore->Size;\r
+ }\r
+ break;\r
+ case EFI_IFR_FORM_OP:\r
+ case EFI_IFR_FORM_MAP_OP:\r
+ //\r
+ // Check the matched VarStoreId is found.\r
+ //\r
+ if (VarStoreData.VarStoreId == 0) {\r
+ return EFI_SUCCESS;\r
+ }\r
+ break;\r
+ case EFI_IFR_ONE_OF_OP:\r
+ //\r
+ // Check whether current value is the one of option.\r
+ //\r
+\r
+ //\r
+ // OneOf question is not in IFR Form. This IFR form is not valid. \r
+ //\r
+ if (VarStoreData.VarStoreId == 0) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ // \r
+ // Check whether this question is for the requested varstore.\r
+ //\r
+ IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr;\r
+ if (IfrOneOf->Question.VarStoreId != VarStoreData.VarStoreId) {\r
+ break;\r
+ }\r
+\r
+ if (NameValueType) {\r
+ QuestionName = HiiGetString (HiiHandle, IfrOneOf->Question.VarStoreInfo.VarName, NULL);\r
+ ASSERT (QuestionName != NULL);\r
+\r
+ if (StrStr (RequestElement, QuestionName) == NULL) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+\r
+ Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ } else {\r
+ //\r
+ // Get Offset by Question header and Width by DataType Flags\r
+ //\r
+ Offset = IfrOneOf->Question.VarStoreInfo.VarOffset;\r
+ Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r
+ //\r
+ // Check whether this question is in current block array.\r
+ //\r
+ if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+ //\r
+ // Check this var question is in the var storage \r
+ //\r
+ if ((Offset + Width) > VarStoreData.Size) {\r
+ //\r
+ // This question exceeds the var store size. \r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Get the current value for oneof opcode\r
+ //\r
+ VarValue = 0;\r
+ CopyMem (&VarValue, VarBuffer + Offset, Width);\r
+ }\r
+ //\r
+ // Set Block Data, to be checked in the following Oneof option opcode.\r
+ //\r
+ VarBlockData.OpCode = IfrOpHdr->OpCode;\r
+ VarBlockData.Scope = IfrOpHdr->Scope;\r
+ break;\r
+ case EFI_IFR_NUMERIC_OP:\r
+ //\r
+ // Check the current value is in the numeric range.\r
+ //\r
+\r
+ //\r
+ // Numeric question is not in IFR Form. This IFR form is not valid. \r
+ //\r
+ if (VarStoreData.VarStoreId == 0) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ //\r
+ // Check whether this question is for the requested varstore.\r
+ //\r
+ IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpHdr;\r
+ if (IfrNumeric->Question.VarStoreId != VarStoreData.VarStoreId) {\r
+ break;\r
+ }\r
+\r
+ if (NameValueType) {\r
+ QuestionName = HiiGetString (HiiHandle, IfrNumeric->Question.VarStoreInfo.VarName, NULL);\r
+ ASSERT (QuestionName != NULL);\r
+\r
+ if (StrStr (RequestElement, QuestionName) == NULL) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+ \r
+ Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ } else {\r
+ //\r
+ // Get Offset by Question header and Width by DataType Flags\r
+ //\r
+ Offset = IfrNumeric->Question.VarStoreInfo.VarOffset;\r
+ Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));\r
+ //\r
+ // Check whether this question is in current block array.\r
+ //\r
+ if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+ //\r
+ // Check this var question is in the var storage \r
+ //\r
+ if ((Offset + Width) > VarStoreData.Size) {\r
+ //\r
+ // This question exceeds the var store size. \r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Check the current value is in the numeric range.\r
+ //\r
+ VarValue = 0;\r
+ CopyMem (&VarValue, VarBuffer + Offset, Width);\r
+ }\r
+ if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) {\r
+ switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
+ case EFI_IFR_NUMERIC_SIZE_1:\r
+ if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ case EFI_IFR_NUMERIC_SIZE_2:\r
+ if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ case EFI_IFR_NUMERIC_SIZE_4:\r
+ if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ case EFI_IFR_NUMERIC_SIZE_8:\r
+ if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ }\r
+ } else {\r
+ switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
+ case EFI_IFR_NUMERIC_SIZE_1:\r
+ if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ case EFI_IFR_NUMERIC_SIZE_2:\r
+ if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ case EFI_IFR_NUMERIC_SIZE_4:\r
+ if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ case EFI_IFR_NUMERIC_SIZE_8:\r
+ if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) {\r
+ //\r
+ // Not in the valid range.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ break;\r
+ case EFI_IFR_CHECKBOX_OP:\r
+ //\r
+ // Check value is BOOLEAN type, only 0 and 1 is valid.\r
+ //\r
+\r
+ //\r
+ // CheckBox question is not in IFR Form. This IFR form is not valid. \r
+ //\r
+ if (VarStoreData.VarStoreId == 0) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Check whether this question is for the requested varstore.\r
+ //\r
+ IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr;\r
+ if (IfrCheckBox->Question.VarStoreId != VarStoreData.VarStoreId) {\r
+ break;\r
+ }\r
+\r
+ if (NameValueType) {\r
+ QuestionName = HiiGetString (HiiHandle, IfrCheckBox->Question.VarStoreInfo.VarName, NULL);\r
+ ASSERT (QuestionName != NULL);\r
+\r
+ if (StrStr (RequestElement, QuestionName) == NULL) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+ \r
+ Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ } else {\r
+ //\r
+ // Get Offset by Question header\r
+ //\r
+ Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r
+ Width = (UINT16) sizeof (BOOLEAN);\r
+ //\r
+ // Check whether this question is in current block array.\r
+ //\r
+ if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+ //\r
+ // Check this var question is in the var storage \r
+ //\r
+ if ((Offset + Width) > VarStoreData.Size) {\r
+ //\r
+ // This question exceeds the var store size. \r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ //\r
+ // Check the current value is in the numeric range.\r
+ //\r
+ VarValue = 0;\r
+ CopyMem (&VarValue, VarBuffer + Offset, Width);\r
+ }\r
+ //\r
+ // Boolean type, only 1 and 0 is valid.\r
+ //\r
+ if (VarValue > 1) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ case EFI_IFR_STRING_OP:\r
+ //\r
+ // Check current string length is less than maxsize\r
+ //\r
+\r
+ //\r
+ // CheckBox question is not in IFR Form. This IFR form is not valid. \r
+ //\r
+ if (VarStoreData.VarStoreId == 0) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Check whether this question is for the requested varstore.\r
+ //\r
+ IfrString = (EFI_IFR_STRING *) IfrOpHdr;\r
+ if (IfrString->Question.VarStoreId != VarStoreData.VarStoreId) {\r
+ break;\r
+ }\r
+ //\r
+ // Get Width by OneOf Flags\r
+ //\r
+ Width = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r
+ if (NameValueType) {\r
+ QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL);\r
+ ASSERT (QuestionName != NULL);\r
+\r
+ StringPtr = StrStr (RequestElement, QuestionName);\r
+ if (StringPtr == NULL) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Skip the "=".\r
+ // \r
+ StringPtr += 1;\r
+ \r
+ //\r
+ // Check current string length is less than maxsize\r
+ //\r
+ if (StrSize (StringPtr) > Width) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ } else {\r
+ //\r
+ // Get Offset/Width by Question header and OneOf Flags\r
+ //\r
+ Offset = IfrString->Question.VarStoreInfo.VarOffset;\r
+ //\r
+ // Check whether this question is in current block array.\r
+ //\r
+ if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
+ //\r
+ // This question is not in the current configuration string. Skip it.\r
+ //\r
+ break;\r
+ }\r
+ //\r
+ // Check this var question is in the var storage \r
+ //\r
+ if ((Offset + Width) > VarStoreData.Size) {\r
+ //\r
+ // This question exceeds the var store size. \r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Check current string length is less than maxsize\r
+ //\r
+ if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ }\r
+ break;\r
+ case EFI_IFR_ONE_OF_OPTION_OP:\r
+ //\r
+ // Opcode Scope is zero. This one of option is not to be checked. \r
+ //\r
+ if (VarBlockData.Scope == 0) {\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Only check for OneOf and OrderList opcode\r
+ //\r
+ IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr;\r
+ if (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP) {\r
+ //\r
+ // Check current value is the value of one of option.\r
+ //\r
+ ASSERT (IfrOneOfOption->Type <= EFI_IFR_TYPE_NUM_SIZE_64);\r
+ ZeroMem (&TmpValue, sizeof (EFI_IFR_TYPE_VALUE));\r
+ CopyMem (&TmpValue, &IfrOneOfOption->Value, IfrOneOfOption->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value));\r
+ if (VarValue == TmpValue.u64) {\r
+ //\r
+ // The value is one of option value.\r
+ // Set OpCode to Zero, don't need check again.\r
+ //\r
+ VarBlockData.OpCode = 0;\r
+ }\r
+ }\r
+ break;\r
+ case EFI_IFR_END_OP:\r
+ //\r
+ // Decrease opcode scope for the validated opcode\r
+ //\r
+ if (VarBlockData.Scope > 0) {\r
+ VarBlockData.Scope --;\r
+ }\r
+\r
+ //\r
+ // OneOf value doesn't belong to one of option value. \r
+ //\r
+ if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ default:\r
+ //\r
+ // Increase Scope for the validated opcode\r
+ //\r
+ if (VarBlockData.Scope > 0) {\r
+ VarBlockData.Scope = (UINT8) (VarBlockData.Scope + IfrOpHdr->Scope);\r
+ }\r
+ break;\r
+ }\r
+ //\r
+ // Go to the next opcode\r
+ //\r
+ IfrOffset += IfrOpHdr->Length;\r
+ }\r
+ //\r
+ // Only one form is in a package list.\r
+ //\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Go to next package.\r
+ //\r
+ PackageOffset += PackageHeader.Length;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ This internal function parses IFR data to validate current setting.\r
+\r
+ @param ConfigElement ConfigResp element string contains the current setting.\r
+ @param CurrentBlockArray Current block array.\r
+ @param VarBuffer Data buffer for this varstore.\r
+ \r
+ @retval EFI_SUCCESS The current setting is valid.\r
+ @retval EFI_OUT_OF_RESOURCES The memory is not enough.\r
+ @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.\r
+**/\r
+EFI_STATUS\r
+GetBlockDataInfo (\r
+ IN CHAR16 *ConfigElement,\r
+ OUT IFR_BLOCK_DATA **CurrentBlockArray,\r
+ OUT UINT8 **VarBuffer\r
+ )\r
+{\r
+ IFR_BLOCK_DATA *BlockData;\r
+ IFR_BLOCK_DATA *NewBlockData;\r
+ EFI_STRING StringPtr;\r
+ UINTN Length;\r
+ UINT8 *TmpBuffer;\r
+ UINT16 Offset;\r
+ UINT16 Width;\r
+ LIST_ENTRY *Link;\r
+ UINTN MaxBufferSize;\r
+ EFI_STATUS Status;\r
+ IFR_BLOCK_DATA *BlockArray;\r
+ UINT8 *DataBuffer;\r
+ \r
+ //\r
+ // Initialize the local variables.\r
+ //\r
+ Status = EFI_SUCCESS;\r
+ BlockData = NULL;\r
+ NewBlockData = NULL;\r
+ TmpBuffer = NULL;\r
+ BlockArray = NULL;\r
+ MaxBufferSize = HII_LIB_DEFAULT_VARSTORE_SIZE;\r
+ DataBuffer = AllocateZeroPool (MaxBufferSize);\r
+ if (DataBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ //\r
+ // Init BlockArray\r
+ //\r
+ BlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
+ if (BlockArray == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+ InitializeListHead (&BlockArray->Entry);\r
+\r
+ StringPtr = StrStr (ConfigElement, L"&OFFSET=");\r
+ ASSERT (StringPtr != NULL);\r
+\r
+ //\r
+ // Parse each <RequestElement> if exists\r
+ // Only <BlockName> format is supported by this help function.\r
+ // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>\r
+ //\r
+ while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) {\r
+ //\r
+ // Skip the &OFFSET= string\r
+ // \r
+ StringPtr += StrLen (L"&OFFSET=");\r
+\r
+ //\r
+ // Get Offset\r
+ //\r
+ Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+ Offset = 0;\r
+ CopyMem (\r
+ &Offset,\r
+ TmpBuffer,\r
+ (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r
+ );\r
+ FreePool (TmpBuffer);\r
+ TmpBuffer = NULL;\r
+\r
+ StringPtr += Length;\r
+ if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+ StringPtr += StrLen (L"&WIDTH=");\r
+\r
+ //\r
+ // Get Width\r
+ //\r
+ Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+ Width = 0;\r
+ CopyMem (\r
+ &Width,\r
+ TmpBuffer,\r
+ (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r
+ );\r
+ FreePool (TmpBuffer);\r
+ TmpBuffer = NULL;\r
+\r
+ StringPtr += Length;\r
+ if (*StringPtr != 0 && *StringPtr != L'&') {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+\r
+ if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+ StringPtr += StrLen (L"&VALUE=");\r
+\r
+ //\r
+ // Get Value\r
+ //\r
+ Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+ StringPtr += Length;\r
+ if (*StringPtr != 0 && *StringPtr != L'&') {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+\r
+ //\r
+ // Check whether VarBuffer is enough\r
+ //\r
+ if ((UINTN) (Offset + Width) > MaxBufferSize) {\r
+ DataBuffer = ReallocatePool (\r
+ MaxBufferSize,\r
+ Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE,\r
+ DataBuffer\r
+ );\r
+ if (DataBuffer == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+ MaxBufferSize = Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE;\r
+ }\r
+\r
+ //\r
+ // Update the Block with configuration info\r
+ //\r
+ CopyMem (DataBuffer + Offset, TmpBuffer, Width);\r
+ FreePool (TmpBuffer);\r
+ TmpBuffer = NULL;\r
+\r
+ //\r
+ // Set new Block Data\r
+ //\r
+ NewBlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
+ if (NewBlockData == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+ NewBlockData->Offset = Offset;\r
+ NewBlockData->Width = Width;\r
+\r
+ //\r
+ // Insert the new block data into the block data array.\r
+ //\r
+ for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) {\r
+ BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
+ if (NewBlockData->Offset == BlockData->Offset) {\r
+ if (NewBlockData->Width > BlockData->Width) {\r
+ BlockData->Width = NewBlockData->Width;\r
+ }\r
+ FreePool (NewBlockData);\r
+ break;\r
+ } else if (NewBlockData->Offset < BlockData->Offset) {\r
+ //\r
+ // Insert new block data as the previous one of this link.\r
+ //\r
+ InsertTailList (Link, &NewBlockData->Entry);\r
+ break;\r
+ }\r
+ }\r