X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FUefiHiiLib%2FHiiLib.c;h=87aeb947ae50134543b879e34b7516d3c58d4a3c;hb=40ae09a2a77740e08731fc79bc3d22f043ea3128;hp=d2b25a003645e3fc4db7a8d0184a1bee159b0435;hpb=9035e1189d2fdfe2dd88ef90725080c6fb2f109e;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index d2b25a0036..87aeb947ae 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -1,7 +1,7 @@ /** @file HII Library implementation that uses DXE protocols and services. - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -31,6 +31,11 @@ typedef struct { UINT8 Scope; } IFR_BLOCK_DATA; +typedef struct { + EFI_VARSTORE_ID VarStoreId; + UINT16 Size; +} IFR_VARSTORAGE_DATA; + // // Template // @@ -129,7 +134,7 @@ InternalHiiExtractGuidFromHiiHandle ( to packages terminated by a NULL. @retval NULL A HII Handle has already been registered in the HII Database with - the same PackageListGuid. + the same PackageListGuid and DeviceHandle. @retval NULL The HII Handle could not be created. @retval NULL An empty list of packages was passed in. @retval NULL All packages are empty. @@ -794,7 +799,6 @@ InternalHiiGetBufferFromString ( default: return EFI_INVALID_PARAMETER; - break; } return EFI_SUCCESS; @@ -914,42 +918,94 @@ InternalHiiGetValueOfNumber ( return EFI_SUCCESS; } +/** + Get value from config request resp string. + + @param ConfigElement ConfigResp string contains the current setting. + @param VarName The variable name which need to get value. + @param VarValue The return value. + + @retval EFI_SUCCESS Get the value for the VarName + @retval EFI_OUT_OF_RESOURCES The memory is not enough. +**/ +EFI_STATUS +GetValueFromRequest ( + IN CHAR16 *ConfigElement, + IN CHAR16 *VarName, + OUT UINT64 *VarValue + ) +{ + UINT8 *TmpBuffer; + CHAR16 *StringPtr; + UINTN Length; + EFI_STATUS Status; + + // + // Find VarName related string. + // + StringPtr = StrStr (ConfigElement, VarName); + ASSERT (StringPtr != NULL); + + // + // Skip the "VarName=" string + // + StringPtr += StrLen (VarName) + 1; + + // + // Get Offset + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + return Status; + } + + *VarValue = 0; + CopyMem (VarValue, TmpBuffer, (((Length + 1) / 2) < sizeof (UINT64)) ? ((Length + 1) / 2) : sizeof (UINT64)); + + FreePool (TmpBuffer); + + return EFI_SUCCESS; +} + /** This internal function parses IFR data to validate current setting. - @param ConfigResp ConfigResp string contains the current setting. + Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid; + else the VarBuffer and CurrentBlockArray is valid. + @param HiiPackageList Point to Hii package list. @param PackageListLength The length of the pacakge. @param VarGuid Guid of the buffer storage. @param VarName Name of the buffer storage. + @param VarBuffer The data buffer for the storage. + @param CurrentBlockArray The block array from the config Requst string. + @param RequestElement The config string for this storage. + @param HiiHandle The HiiHandle for this formset. + @param NameValueType Whether current storage is name/value varstore or not. @retval EFI_SUCCESS The current setting is valid. @retval EFI_OUT_OF_RESOURCES The memory is not enough. @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid. **/ EFI_STATUS -EFIAPI -InternalHiiValidateCurrentSetting ( - IN EFI_STRING ConfigResp, +ValidateQuestionFromVfr ( IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList, IN UINTN PackageListLength, IN EFI_GUID *VarGuid, - IN CHAR16 *VarName + IN CHAR16 *VarName, + IN UINT8 *VarBuffer, + IN IFR_BLOCK_DATA *CurrentBlockArray, + IN CHAR16 *RequestElement, + IN EFI_HII_HANDLE HiiHandle, + IN BOOLEAN NameValueType ) -{ - IFR_BLOCK_DATA *CurrentBlockArray; - IFR_BLOCK_DATA *BlockData; - IFR_BLOCK_DATA *NewBlockData; +{ IFR_BLOCK_DATA VarBlockData; - EFI_STRING StringPtr; - UINTN Length; UINT8 *TmpBuffer; UINT16 Offset; UINT16 Width; UINT64 VarValue; - LIST_ENTRY *Link; - UINT8 *VarBuffer; - UINTN MaxBufferSize; + EFI_IFR_TYPE_VALUE TmpValue; EFI_STATUS Status; EFI_HII_PACKAGE_HEADER PacakgeHeader; UINT32 PackageOffset; @@ -957,6 +1013,9 @@ InternalHiiValidateCurrentSetting ( UINTN IfrOffset; EFI_IFR_OP_HEADER *IfrOpHdr; EFI_IFR_VARSTORE *IfrVarStore; + EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueStore; + EFI_IFR_VARSTORE_EFI *IfrEfiVarStore; + IFR_VARSTORAGE_DATA VarStoreData; EFI_IFR_ONE_OF *IfrOneOf; EFI_IFR_NUMERIC *IfrNumeric; EFI_IFR_ONE_OF_OPTION *IfrOneOfOption; @@ -964,230 +1023,30 @@ InternalHiiValidateCurrentSetting ( EFI_IFR_STRING *IfrString; CHAR8 *VarStoreName; UINTN Index; - - // - // 1. Get the current setting to current block data array and Convert them into VarBuffer - // + CHAR16 *QuestionName; + CHAR16 *StringPtr; - // - // Skip ConfigHdr string - // - StringPtr = ConfigResp; - StringPtr = StrStr (ConfigResp, L"&OFFSET"); - if (StringPtr == NULL) { - // - // No ConfigBlock value is required to be validated. - // EFI_SUCCESS directly return. - // - return EFI_SUCCESS; - } - // // Initialize the local variables. // - Index = 0; - VarStoreName = NULL; - Status = EFI_SUCCESS; - BlockData = NULL; - NewBlockData = NULL; - TmpBuffer = NULL; - MaxBufferSize = HII_LIB_DEFAULT_VARSTORE_SIZE; - VarBuffer = AllocateZeroPool (MaxBufferSize); - if (VarBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Init CurrentBlockArray - // - CurrentBlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); - if (CurrentBlockArray == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - InitializeListHead (&CurrentBlockArray->Entry); - - // - // Parse each if exists - // Only format is supported by this help function. - // ::= &'OFFSET='&'WIDTH=' - // - while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) { - // - // Skip the &OFFSET= string - // - StringPtr += StrLen (L"&OFFSET="); - - // - // Get Offset - // - Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (EFI_ERROR (Status)) { - goto Done; - } - Offset = 0; - CopyMem ( - &Offset, - TmpBuffer, - (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) - ); - FreePool (TmpBuffer); - TmpBuffer = NULL; - - StringPtr += Length; - if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - StringPtr += StrLen (L"&WIDTH="); - - // - // Get Width - // - Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (EFI_ERROR (Status)) { - goto Done; - } - Width = 0; - CopyMem ( - &Width, - TmpBuffer, - (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) - ); - FreePool (TmpBuffer); - TmpBuffer = NULL; - - StringPtr += Length; - if (*StringPtr != 0 && *StringPtr != L'&') { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - - if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - StringPtr += StrLen (L"&VALUE="); - - // - // Get Value - // - Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (EFI_ERROR (Status)) { - goto Done; - } - - StringPtr += Length; - if (*StringPtr != 0 && *StringPtr != L'&') { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - - // - // Check whether VarBuffer is enough - // - if ((UINTN) (Offset + Width) > MaxBufferSize) { - VarBuffer = ReallocatePool ( - MaxBufferSize, - Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE, - VarBuffer - ); - if (VarBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - MaxBufferSize = Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE; - } - - // - // Update the Block with configuration info - // - CopyMem (VarBuffer + Offset, TmpBuffer, Width); - FreePool (TmpBuffer); - TmpBuffer = NULL; - - // - // Set new Block Data - // - NewBlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); - if (NewBlockData == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - NewBlockData->Offset = Offset; - NewBlockData->Width = Width; - - // - // Insert the new block data into the block data array. - // - for (Link = CurrentBlockArray->Entry.ForwardLink; Link != &CurrentBlockArray->Entry; Link = Link->ForwardLink) { - BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); - if (NewBlockData->Offset == BlockData->Offset) { - if (NewBlockData->Width > BlockData->Width) { - BlockData->Width = NewBlockData->Width; - } - FreePool (NewBlockData); - break; - } else if (NewBlockData->Offset < BlockData->Offset) { - // - // Insert new block data as the previous one of this link. - // - InsertTailList (Link, &NewBlockData->Entry); - break; - } - } - - // - // Insert new block data into the array tail. - // - if (Link == &CurrentBlockArray->Entry) { - InsertTailList (Link, &NewBlockData->Entry); - } - - // - // If '\0', parsing is finished. - // - if (*StringPtr == 0) { - break; - } - // - // Go to next ConfigBlock - // - } - - // - // Merge the aligned block data into the single block data. - // - Link = CurrentBlockArray->Entry.ForwardLink; - while ((Link != &CurrentBlockArray->Entry) && (Link->ForwardLink != &CurrentBlockArray->Entry)) { - BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); - NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry); - if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) { - if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) { - BlockData->Width = (UINT16) (NewBlockData->Offset + NewBlockData->Width - BlockData->Offset); - } - RemoveEntryList (Link->ForwardLink); - FreePool (NewBlockData); - continue; - } - Link = Link->ForwardLink; - } - - if (IsListEmpty (&CurrentBlockArray->Entry)) { - Status = EFI_SUCCESS; - goto Done; - } + Index = 0; + VarStoreName = NULL; + Status = EFI_SUCCESS; + TmpBuffer = NULL; + VarValue = 0; + IfrVarStore = NULL; + IfrNameValueStore = NULL; + IfrEfiVarStore = NULL; + ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA)); + ZeroMem (&VarBlockData, sizeof (VarBlockData)); // - // 2. Check IFR value is in block data, then Validate Value + // Check IFR value is in block data, then Validate Value // - ZeroMem (&VarBlockData, sizeof (VarBlockData)); - VarValue = 0; - IfrVarStore = NULL; PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); while (PackageOffset < PackageListLength) { CopyMem (&PacakgeHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PacakgeHeader)); - + // // Parse IFR opcode from the form package. // @@ -1200,11 +1059,11 @@ InternalHiiValidateCurrentSetting ( // Validate current setting to the value built in IFR opcode // switch (IfrOpHdr->OpCode) { - case EFI_IFR_VARSTORE_OP: + case EFI_IFR_VARSTORE_OP: // // VarStoreId has been found. No further found. // - if (IfrVarStore != NULL) { + if (VarStoreData.VarStoreId != 0) { break; } // @@ -1227,72 +1086,152 @@ InternalHiiValidateCurrentSetting ( } else { IfrVarStore = NULL; } + + if (IfrVarStore != NULL) { + VarStoreData.VarStoreId = IfrVarStore->VarStoreId; + VarStoreData.Size = IfrVarStore->Size; + } break; - case EFI_IFR_FORM_OP: - case EFI_IFR_FORM_MAP_OP: + case EFI_IFR_VARSTORE_NAME_VALUE_OP: // - // Check the matched VarStoreId is found. + // VarStoreId has been found. No further found. // - if (IfrVarStore == NULL) { - Status = EFI_SUCCESS; - goto Done; + if (VarStoreData.VarStoreId != 0) { + break; } - break; - case EFI_IFR_ONE_OF_OP: // - // Check whether current value is the one of option. + // Find the matched VarStoreId to the input VarGuid // + IfrNameValueStore = (EFI_IFR_VARSTORE_NAME_VALUE *) IfrOpHdr; + if (!CompareGuid ((EFI_GUID *) (VOID *) &IfrNameValueStore->Guid, VarGuid)) { + IfrNameValueStore = NULL; + } - // - // OneOf question is not in IFR Form. This IFR form is not valid. - // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (IfrNameValueStore != NULL) { + VarStoreData.VarStoreId = IfrNameValueStore->VarStoreId; } - // - // Check whether this question is for the requested varstore. + break; + case EFI_IFR_VARSTORE_EFI_OP: // - IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr; - if (IfrOneOf->Question.VarStoreId != IfrVarStore->VarStoreId) { + // VarStore is found. Don't need to search any more. + // + if (VarStoreData.VarStoreId != 0) { break; } - - // - // Get Offset by Question header and Width by DataType Flags + + IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr; + // - Offset = IfrOneOf->Question.VarStoreInfo.VarOffset; - Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); + // If the length is small than the structure, this is from old efi + // varstore definition. Old efi varstore get config directly from + // GetVariable function. // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) { + break; + } + + if (CompareGuid ((EFI_GUID *) (VOID *) &IfrEfiVarStore->Guid, VarGuid)) { + VarStoreName = (CHAR8 *) IfrEfiVarStore->Name; + for (Index = 0; VarStoreName[Index] != 0; Index ++) { + if ((CHAR16) VarStoreName[Index] != VarName[Index]) { + break; + } + } // - // This question is not in the current configuration string. Skip it. + // The matched VarStore is found. // - break; + if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) { + IfrEfiVarStore = NULL; + } + } else { + IfrEfiVarStore = NULL; } - // - // Check this var question is in the var storage - // - if ((Offset + Width) > IfrVarStore->Size) { + + if (IfrEfiVarStore != NULL) { // - // This question exceeds the var store size. + // Find the matched VarStore // - Status = EFI_INVALID_PARAMETER; - goto Done; + VarStoreData.VarStoreId = IfrEfiVarStore->VarStoreId; + VarStoreData.Size = IfrEfiVarStore->Size; } + break; + case EFI_IFR_FORM_OP: + case EFI_IFR_FORM_MAP_OP: + // + // Check the matched VarStoreId is found. + // + if (VarStoreData.VarStoreId == 0) { + return EFI_SUCCESS; + } + break; + case EFI_IFR_ONE_OF_OP: + // + // Check whether current value is the one of option. + // // - // Get the current value for oneof opcode + // OneOf question is not in IFR Form. This IFR form is not valid. // - VarValue = 0; - CopyMem (&VarValue, VarBuffer + Offset, Width); + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; + } + // + // Check whether this question is for the requested varstore. + // + IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr; + if (IfrOneOf->Question.VarStoreId != VarStoreData.VarStoreId) { + break; + } + + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrOneOf->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + if (StrStr (RequestElement, QuestionName) == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + + Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue); + if (EFI_ERROR (Status)) { + return Status; + } + } else { + // + // Get Offset by Question header and Width by DataType Flags + // + Offset = IfrOneOf->Question.VarStoreInfo.VarOffset; + Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); + // + // Check whether this question is in current block array. + // + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage + // + if ((Offset + Width) > VarStoreData.Size) { + // + // This question exceeds the var store size. + // + return EFI_INVALID_PARAMETER; + } + + // + // Get the current value for oneof opcode + // + VarValue = 0; + CopyMem (&VarValue, VarBuffer + Offset, Width); + } // // Set Block Data, to be checked in the following Oneof option opcode. // - VarBlockData.Offset = Offset; - VarBlockData.Width = Width; VarBlockData.OpCode = IfrOpHdr->OpCode; VarBlockData.Scope = IfrOpHdr->Scope; break; @@ -1304,56 +1243,70 @@ InternalHiiValidateCurrentSetting ( // // Numeric question is not in IFR Form. This IFR form is not valid. // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; } // // Check whether this question is for the requested varstore. // IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpHdr; - if (IfrNumeric->Question.VarStoreId != IfrVarStore->VarStoreId) { + if (IfrNumeric->Question.VarStoreId != VarStoreData.VarStoreId) { break; } - - // - // Get Offset by Question header and Width by DataType Flags - // - Offset = IfrNumeric->Question.VarStoreInfo.VarOffset; - Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE)); - // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrNumeric->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + if (StrStr (RequestElement, QuestionName) == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + + Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue); + if (EFI_ERROR (Status)) { + return Status; + } + } else { // - // This question is not in the current configuration string. Skip it. + // Get Offset by Question header and Width by DataType Flags // - break; - } - // - // Check this var question is in the var storage - // - if ((Offset + Width) > IfrVarStore->Size) { + Offset = IfrNumeric->Question.VarStoreInfo.VarOffset; + Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE)); // - // This question exceeds the var store size. + // Check whether this question is in current block array. // - Status = EFI_INVALID_PARAMETER; - goto Done; - } + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage + // + if ((Offset + Width) > VarStoreData.Size) { + // + // This question exceeds the var store size. + // + return EFI_INVALID_PARAMETER; + } - // - // Check the current value is in the numeric range. - // - VarValue = 0; - CopyMem (&VarValue, VarBuffer + Offset, Width); + // + // Check the current value is in the numeric range. + // + VarValue = 0; + CopyMem (&VarValue, VarBuffer + Offset, Width); + } switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { case EFI_IFR_NUMERIC_SIZE_1: if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) { // // Not in the valid range. // - Status = EFI_INVALID_PARAMETER; - goto Done; + return EFI_INVALID_PARAMETER; } break; case EFI_IFR_NUMERIC_SIZE_2: @@ -1361,8 +1314,7 @@ InternalHiiValidateCurrentSetting ( // // Not in the valid range. // - Status = EFI_INVALID_PARAMETER; - goto Done; + return EFI_INVALID_PARAMETER; } break; case EFI_IFR_NUMERIC_SIZE_4: @@ -1370,8 +1322,7 @@ InternalHiiValidateCurrentSetting ( // // Not in the valid range. // - Status = EFI_INVALID_PARAMETER; - goto Done; + return EFI_INVALID_PARAMETER; } break; case EFI_IFR_NUMERIC_SIZE_8: @@ -1379,8 +1330,7 @@ InternalHiiValidateCurrentSetting ( // // Not in the valid range. // - Status = EFI_INVALID_PARAMETER; - goto Done; + return EFI_INVALID_PARAMETER; } break; } @@ -1394,52 +1344,69 @@ InternalHiiValidateCurrentSetting ( // // CheckBox question is not in IFR Form. This IFR form is not valid. // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; } // // Check whether this question is for the requested varstore. // IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr; - if (IfrCheckBox->Question.VarStoreId != IfrVarStore->VarStoreId) { + if (IfrCheckBox->Question.VarStoreId != VarStoreData.VarStoreId) { break; } - - // - // Get Offset by Question header - // - Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset; - Width = (UINT16) sizeof (BOOLEAN); - // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrCheckBox->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + if (StrStr (RequestElement, QuestionName) == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + + Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue); + if (EFI_ERROR (Status)) { + return Status; + } + } else { // - // This question is not in the current configuration string. Skip it. + // Get Offset by Question header // - break; - } - // - // Check this var question is in the var storage - // - if ((Offset + Width) > IfrVarStore->Size) { + Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset; + Width = (UINT16) sizeof (BOOLEAN); // - // This question exceeds the var store size. + // Check whether this question is in current block array. + // + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } // - Status = EFI_INVALID_PARAMETER; - goto Done; + // Check this var question is in the var storage + // + if ((Offset + Width) > VarStoreData.Size) { + // + // This question exceeds the var store size. + // + return EFI_INVALID_PARAMETER; + } + // + // Check the current value is in the numeric range. + // + VarValue = 0; + CopyMem (&VarValue, VarBuffer + Offset, Width); } - // // Boolean type, only 1 and 0 is valid. // - if (*(VarBuffer + Offset) > 1) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarValue > 1) { + return EFI_INVALID_PARAMETER; } - break; case EFI_IFR_STRING_OP: // @@ -1449,121 +1416,475 @@ InternalHiiValidateCurrentSetting ( // // CheckBox question is not in IFR Form. This IFR form is not valid. // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; } // // Check whether this question is for the requested varstore. // IfrString = (EFI_IFR_STRING *) IfrOpHdr; - if (IfrString->Question.VarStoreId != IfrVarStore->VarStoreId) { + if (IfrString->Question.VarStoreId != VarStoreData.VarStoreId) { break; } - // - // Get Offset/Width by Question header and OneOf Flags + // Get Width by OneOf Flags // - Offset = IfrString->Question.VarStoreInfo.VarOffset; Width = (UINT16) (IfrString->MaxSize * sizeof (UINT16)); - // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + StringPtr = StrStr (RequestElement, QuestionName); + if (StringPtr == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + + // + // Skip the "=". + // + StringPtr += 1; + + // + // Check current string length is less than maxsize + // + if (StrSize (StringPtr) > Width) { + return EFI_INVALID_PARAMETER; + } + } else { + // + // Get Offset/Width by Question header and OneOf Flags + // + Offset = IfrString->Question.VarStoreInfo.VarOffset; + // + // Check whether this question is in current block array. + // + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage // - // This question is not in the current configuration string. Skip it. + if ((Offset + Width) > VarStoreData.Size) { + // + // This question exceeds the var store size. + // + return EFI_INVALID_PARAMETER; + } + + // + // Check current string length is less than maxsize // + if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) { + return EFI_INVALID_PARAMETER; + } + } + break; + case EFI_IFR_ONE_OF_OPTION_OP: + // + // Opcode Scope is zero. This one of option is not to be checked. + // + if (VarBlockData.Scope == 0) { break; } + // - // Check this var question is in the var storage + // Only check for OneOf and OrderList opcode // - if ((Offset + Width) > IfrVarStore->Size) { + IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr; + if (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP) { // - // This question exceeds the var store size. + // Check current value is the value of one of option. // - Status = EFI_INVALID_PARAMETER; - goto Done; + ASSERT (IfrOneOfOption->Type <= EFI_IFR_TYPE_NUM_SIZE_64); + ZeroMem (&TmpValue, sizeof (EFI_IFR_TYPE_VALUE)); + CopyMem (&TmpValue, &IfrOneOfOption->Value, IfrOneOfOption->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value)); + if (VarValue == TmpValue.u64) { + // + // The value is one of option value. + // Set OpCode to Zero, don't need check again. + // + VarBlockData.OpCode = 0; + } } - + break; + case EFI_IFR_END_OP: // - // Check current string length is less than maxsize + // Decrease opcode scope for the validated opcode + // + if (VarBlockData.Scope > 0) { + VarBlockData.Scope --; + } + + // + // OneOf value doesn't belong to one of option value. // - if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) { + return EFI_INVALID_PARAMETER; } break; - case EFI_IFR_ONE_OF_OPTION_OP: + default: // - // Opcode Scope is zero. This one of option is not to be checked. + // Increase Scope for the validated opcode // - if (VarBlockData.Scope == 0) { - break; + if (VarBlockData.Scope > 0) { + VarBlockData.Scope = (UINT8) (VarBlockData.Scope + IfrOpHdr->Scope); } + break; + } + // + // Go to the next opcode + // + IfrOffset += IfrOpHdr->Length; + } + // + // Only one form is in a package list. + // + break; + } + + // + // Go to next package. + // + PackageOffset += PacakgeHeader.Length; + } + + return EFI_SUCCESS; +} + +/** + This internal function parses IFR data to validate current setting. + + @param ConfigElement ConfigResp element string contains the current setting. + @param CurrentBlockArray Current block array. + @param VarBuffer Data buffer for this varstore. + + @retval EFI_SUCCESS The current setting is valid. + @retval EFI_OUT_OF_RESOURCES The memory is not enough. + @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid. +**/ +EFI_STATUS +GetBlockDataInfo ( + IN CHAR16 *ConfigElement, + OUT IFR_BLOCK_DATA **CurrentBlockArray, + OUT UINT8 **VarBuffer + ) +{ + IFR_BLOCK_DATA *BlockData; + IFR_BLOCK_DATA *NewBlockData; + EFI_STRING StringPtr; + UINTN Length; + UINT8 *TmpBuffer; + UINT16 Offset; + UINT16 Width; + LIST_ENTRY *Link; + UINTN MaxBufferSize; + EFI_STATUS Status; + CHAR8 *VarStoreName; + UINTN Index; + IFR_BLOCK_DATA *BlockArray; + UINT8 *DataBuffer; + + // + // Initialize the local variables. + // + Index = 0; + VarStoreName = NULL; + Status = EFI_SUCCESS; + BlockData = NULL; + NewBlockData = NULL; + TmpBuffer = NULL; + BlockArray = NULL; + MaxBufferSize = HII_LIB_DEFAULT_VARSTORE_SIZE; + DataBuffer = AllocateZeroPool (MaxBufferSize); + if (DataBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Init BlockArray + // + BlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); + if (BlockArray == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + InitializeListHead (&BlockArray->Entry); + + StringPtr = StrStr (ConfigElement, L"&OFFSET="); + ASSERT (StringPtr != NULL); + + // + // Parse each if exists + // Only format is supported by this help function. + // ::= &'OFFSET='&'WIDTH=' + // + while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) { + // + // Skip the &OFFSET= string + // + StringPtr += StrLen (L"&OFFSET="); + + // + // Get Offset + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + goto Done; + } + Offset = 0; + CopyMem ( + &Offset, + TmpBuffer, + (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) + ); + FreePool (TmpBuffer); + TmpBuffer = NULL; + + StringPtr += Length; + if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"&WIDTH="); + + // + // Get Width + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + goto Done; + } + Width = 0; + CopyMem ( + &Width, + TmpBuffer, + (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) + ); + FreePool (TmpBuffer); + TmpBuffer = NULL; + + StringPtr += Length; + if (*StringPtr != 0 && *StringPtr != L'&') { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"&VALUE="); + + // + // Get Value + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + goto Done; + } + + StringPtr += Length; + if (*StringPtr != 0 && *StringPtr != L'&') { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // Check whether VarBuffer is enough + // + if ((UINTN) (Offset + Width) > MaxBufferSize) { + DataBuffer = ReallocatePool ( + MaxBufferSize, + Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE, + DataBuffer + ); + if (DataBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + MaxBufferSize = Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE; + } - // - // Only check for OneOf and OrderList opcode - // - IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr; - if (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP) { - // - // Check current value is the value of one of option. - // - if (VarValue == IfrOneOfOption->Value.u64) { - // - // The value is one of option value. - // Set OpCode to Zero, don't need check again. - // - VarBlockData.OpCode = 0; - } - } + // + // Update the Block with configuration info + // + CopyMem (DataBuffer + Offset, TmpBuffer, Width); + FreePool (TmpBuffer); + TmpBuffer = NULL; - break; - case EFI_IFR_END_OP: - // - // Decrease opcode scope for the validated opcode - // - if (VarBlockData.Scope > 0) { - VarBlockData.Scope --; - } + // + // Set new Block Data + // + NewBlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); + if (NewBlockData == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + NewBlockData->Offset = Offset; + NewBlockData->Width = Width; - // - // OneOf value doesn't belong to one of option value. - // - if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - break; - default: - // - // Increase Scope for the validated opcode - // - if (VarBlockData.Scope > 0) { - VarBlockData.Scope = (UINT8) (VarBlockData.Scope + IfrOpHdr->Scope); - } - break; + // + // Insert the new block data into the block data array. + // + for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) { + BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); + if (NewBlockData->Offset == BlockData->Offset) { + if (NewBlockData->Width > BlockData->Width) { + BlockData->Width = NewBlockData->Width; } + FreePool (NewBlockData); + break; + } else if (NewBlockData->Offset < BlockData->Offset) { // - // Go to the next opcode + // Insert new block data as the previous one of this link. // - IfrOffset += IfrOpHdr->Length; + InsertTailList (Link, &NewBlockData->Entry); + break; } - // - // Only one form is in a package list. - // + } + + // + // Insert new block data into the array tail. + // + if (Link == &BlockArray->Entry) { + InsertTailList (Link, &NewBlockData->Entry); + } + + // + // If '\0', parsing is finished. + // + if (*StringPtr == 0) { break; } - // - // Go to next package. + // Go to next ConfigBlock // - PackageOffset += PacakgeHeader.Length; } + // + // Merge the aligned block data into the single block data. + // + Link = BlockArray->Entry.ForwardLink; + while ((Link != &BlockArray->Entry) && (Link->ForwardLink != &BlockArray->Entry)) { + BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); + NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry); + if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) { + if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) { + BlockData->Width = (UINT16) (NewBlockData->Offset + NewBlockData->Width - BlockData->Offset); + } + RemoveEntryList (Link->ForwardLink); + FreePool (NewBlockData); + continue; + } + Link = Link->ForwardLink; + } + + *VarBuffer = DataBuffer; + *CurrentBlockArray = BlockArray; + return EFI_SUCCESS; + Done: + if (DataBuffer != NULL) { + FreePool (DataBuffer); + } + + if (BlockArray != NULL) { + // + // Free Link Array CurrentBlockArray + // + while (!IsListEmpty (&BlockArray->Entry)) { + BlockData = BASE_CR (BlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry); + RemoveEntryList (&BlockData->Entry); + FreePool (BlockData); + } + FreePool (BlockArray); + } + + return Status; +} + +/** + This internal function parses IFR data to validate current setting. + + @param ConfigResp ConfigResp string contains the current setting. + @param HiiPackageList Point to Hii package list. + @param PackageListLength The length of the pacakge. + @param VarGuid Guid of the buffer storage. + @param VarName Name of the buffer storage. + @param HiiHandle The HiiHandle for this package. + + @retval EFI_SUCCESS The current setting is valid. + @retval EFI_OUT_OF_RESOURCES The memory is not enough. + @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid. +**/ +EFI_STATUS +EFIAPI +InternalHiiValidateCurrentSetting ( + IN EFI_STRING ConfigResp, + IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList, + IN UINTN PackageListLength, + IN EFI_GUID *VarGuid, + IN CHAR16 *VarName, + IN EFI_HII_HANDLE HiiHandle + ) +{ + CHAR16 *StringPtr; + EFI_STATUS Status; + IFR_BLOCK_DATA *CurrentBlockArray; + IFR_BLOCK_DATA *BlockData; + UINT8 *VarBuffer; + BOOLEAN NameValueType; + + CurrentBlockArray = NULL; + VarBuffer = NULL; + StringPtr = NULL; + Status = EFI_SUCCESS; + + // + // If StringPtr != NULL, get the request elements. + // + if (StrStr (ConfigResp, L"&OFFSET=") != NULL) { + Status = GetBlockDataInfo(ConfigResp, &CurrentBlockArray, &VarBuffer); + if (EFI_ERROR (Status)) { + return Status; + } + NameValueType = FALSE; + } else { + // + // Skip header part. + // + StringPtr = StrStr (ConfigResp, L"PATH="); + ASSERT (StringPtr != NULL); + + if (StrStr (StringPtr, L"&") != NULL) { + NameValueType = TRUE; + } else { + // + // Not found Request element, return success. + // + return EFI_SUCCESS; + } + } + + Status = ValidateQuestionFromVfr( + HiiPackageList, + PackageListLength, + VarGuid, + VarName, + VarBuffer, + CurrentBlockArray, + ConfigResp, + HiiHandle, + NameValueType + ); + if (VarBuffer != NULL) { FreePool (VarBuffer); } @@ -1577,12 +1898,40 @@ Done: RemoveEntryList (&BlockData->Entry); FreePool (BlockData); } - FreePool (CurrentBlockArray); + FreePool (CurrentBlockArray); } return Status; } +/** + Check whether the ConfigRequest string has the request elements. + For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format. + For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format. + + @param ConfigRequest The input config request string. + + @retval TRUE The input include config request elements. + @retval FALSE The input string not includes. + +**/ +BOOLEAN +GetElementsFromRequest ( + IN EFI_STRING ConfigRequest + ) +{ + EFI_STRING TmpRequest; + + TmpRequest = StrStr (ConfigRequest, L"PATH="); + ASSERT (TmpRequest != NULL); + + if ((StrStr (TmpRequest, L"&OFFSET=") != NULL) || (StrStr (TmpRequest, L"&") != NULL)) { + return TRUE; + } + + return FALSE; +} + /** This function parses the input ConfigRequest string and its matched IFR code string for setting default value and validating current setting. @@ -1629,18 +1978,12 @@ InternalHiiIfrValueAction ( UINT32 Index; EFI_GUID *VarGuid; EFI_STRING VarName; - EFI_STRING_ID DefaultName; - UINT8 *PackageData; - UINTN IfrOffset; - EFI_IFR_OP_HEADER *IfrOpHdr; EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - UINT32 PackageOffset; UINTN PackageListLength; - EFI_HII_PACKAGE_HEADER PacakgeHeader; EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - + ConfigAltResp = NULL; ConfigResp = NULL; VarGuid = NULL; @@ -1651,7 +1994,6 @@ InternalHiiIfrValueAction ( Index = 0; TempDriverHandle = NULL; HiiHandle = NULL; - PackageData = NULL; HiiPackageList = NULL; // @@ -1769,16 +2111,12 @@ InternalHiiIfrValueAction ( // Its default value and validating can't execute by parsing IFR data. // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path. // - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; goto NextConfigAltResp; } - - // - // 2. Get DefaultName string ID by parsing the PacakgeList - // // - // Get HiiPackage by HiiHandle + // 2. Get HiiPackage by HiiHandle // PackageListLength = 0; HiiPackageList = NULL; @@ -1806,59 +2144,9 @@ InternalHiiIfrValueAction ( goto Done; } - // - // Parse the form package and get the default name string ID. - // - if (ActionType == ACTION_SET_DEFAUTL_VALUE) { - PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); - Status = EFI_NOT_FOUND; - while (PackageOffset < PackageListLength) { - CopyMem (&PacakgeHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PacakgeHeader)); - - // - // Parse IFR opcode to get default store opcode - // - if (PacakgeHeader.Type == EFI_HII_PACKAGE_FORMS) { - IfrOffset = sizeof (PacakgeHeader); - PackageData = (UINT8 *) HiiPackageList + PackageOffset; - while (IfrOffset < PacakgeHeader.Length) { - IfrOpHdr = (EFI_IFR_OP_HEADER *) (PackageData + IfrOffset); - // - // Match DefaultId to find its DefaultName - // - if (IfrOpHdr->OpCode == EFI_IFR_DEFAULTSTORE_OP) { - if (((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultId == DefaultId) { - DefaultName = ((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultName; - Status = EFI_SUCCESS; - break; - } - } - IfrOffset += IfrOpHdr->Length; - } - // - // Only one form is in a package list. - // - break; - } - - // - // Go to next package. - // - PackageOffset += PacakgeHeader.Length; - } - - // - // Not found the matched default string ID - // - if (EFI_ERROR (Status)) { - Status = EFI_SUCCESS; - goto NextConfigAltResp; - } - } - // // 3. Call ConfigRouting GetAltCfg(ConfigRoute, , Guid, Name, DevicePath, AltCfgId, AltCfgResp) - // Get the default configuration string according to the found default name string ID. + // Get the default configuration string according to the default ID. // Status = gHiiConfigRouting->GetAltConfig ( gHiiConfigRouting, @@ -1866,7 +2154,7 @@ InternalHiiIfrValueAction ( VarGuid, VarName, DevicePath, - (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultName:NULL, // it can be NULL to get the current setting. + (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultId:NULL, // it can be NULL to get the current setting. &ConfigResp ); @@ -1880,7 +2168,7 @@ InternalHiiIfrValueAction ( // // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set. // - if (StrStr (ConfigResp, L"&OFFSET=") == NULL) { + if (!GetElementsFromRequest (ConfigResp)) { goto NextConfigAltResp; } @@ -1897,7 +2185,7 @@ InternalHiiIfrValueAction ( // // Current Setting is in ConfigResp, will be set into buffer, then check it again. // - Status = InternalHiiValidateCurrentSetting (ConfigResp, HiiPackageList, PackageListLength, VarGuid, VarName); + Status = InternalHiiValidateCurrentSetting (ConfigResp, HiiPackageList, PackageListLength, VarGuid, VarName, HiiHandle); } if (EFI_ERROR (Status)) { @@ -1913,10 +2201,10 @@ NextConfigAltResp: HiiPackageList = NULL; } - if (ConfigResp != NULL) { - FreePool (ConfigResp); - ConfigResp = NULL; - } + if (ConfigResp != NULL) { + FreePool (ConfigResp); + ConfigResp = NULL; + } // // Free the allocated buffer. @@ -2505,9 +2793,7 @@ InternalHiiGrowOpCodeHandle ( OpCodeBuffer->BufferSize + (Size + HII_LIB_OPCODE_ALLOCATION_SIZE), OpCodeBuffer->Buffer ); - if (Buffer == NULL) { - return NULL; - } + ASSERT (Buffer != NULL); OpCodeBuffer->Buffer = Buffer; OpCodeBuffer->BufferSize += (Size + HII_LIB_OPCODE_ALLOCATION_SIZE); } @@ -2692,7 +2978,7 @@ HiiCreateOneOfOptionOpCode ( OpCode.Type = Type; CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]); - return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OPTION_OP, sizeof (OpCode)); + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OPTION_OP, OFFSET_OF(EFI_IFR_ONE_OF_OPTION, Value) + mHiiDefaultTypeToWidth[Type]); } /** @@ -2728,7 +3014,7 @@ HiiCreateDefaultOpCode ( OpCode.DefaultId = DefaultId; CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]); - return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DEFAULT_OP, sizeof (OpCode)); + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DEFAULT_OP, OFFSET_OF(EFI_IFR_DEFAULT, Value) + mHiiDefaultTypeToWidth[Type]); } /** @@ -2918,6 +3204,82 @@ HiiCreateGotoOpCode ( return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, sizeof (OpCode)); } +/** + Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode. + + When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created. + When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created. + When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created. + When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created. + + If OpCodeHandle is NULL, then ASSERT(). + If any reserved bits are set in QuestionFlags, then ASSERT(). + + @param[in] OpCodeHandle The handle to the buffer of opcodes. + @param[in] RefFormId The Destination Form ID. + @param[in] Prompt The string ID for Prompt. + @param[in] Help The string ID for Help. + @param[in] QuestionFlags The flags in Question Header + @param[in] QuestionId Question ID. + @param[in] RefQuestionId The question on the form to which this link is referring. + If its value is zero, then the link refers to the top of the form. + @param[in] RefFormSetId The form set to which this link is referring. If its value is NULL, and RefDevicePath is + zero, then the link is to the current form set. + @param[in] RefDevicePath The string identifier that specifies the string containing the text representation of + the device path to which the form set containing the form specified by FormId. + If its value is zero, then the link refers to the current page. + + @retval NULL There is not enough space left in Buffer to add the opcode. + @retval Other A pointer to the created opcode. + +**/ +UINT8 * +EFIAPI +HiiCreateGotoExOpCode ( + IN VOID *OpCodeHandle, + IN EFI_FORM_ID RefFormId, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN EFI_QUESTION_ID QuestionId, + IN EFI_QUESTION_ID RefQuestionId, + IN EFI_GUID *RefFormSetId, OPTIONAL + IN EFI_STRING_ID RefDevicePath + ) +{ + EFI_IFR_REF4 OpCode; + UINTN OpCodeSize; + + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); + + ZeroMem (&OpCode, sizeof (OpCode)); + OpCode.Question.Header.Prompt = Prompt; + OpCode.Question.Header.Help = Help; + OpCode.Question.QuestionId = QuestionId; + OpCode.Question.Flags = QuestionFlags; + OpCode.FormId = RefFormId; + OpCode.QuestionId = RefQuestionId; + OpCode.DevicePath = RefDevicePath; + if (RefFormSetId != NULL) { + CopyMem (&OpCode.FormSetId, RefFormSetId, sizeof (OpCode.FormSetId)); + } + + // + // Cacluate OpCodeSize based on the input Ref value. + // Try to use the small OpCode to save size. + // + OpCodeSize = sizeof (EFI_IFR_REF); + if (RefDevicePath != 0) { + OpCodeSize = sizeof (EFI_IFR_REF4); + } else if (RefFormSetId != NULL) { + OpCodeSize = sizeof (EFI_IFR_REF3); + } else if (RefQuestionId != 0) { + OpCodeSize = sizeof (EFI_IFR_REF2); + } + + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, OpCodeSize); +} + /** Create EFI_IFR_CHECKBOX_OP opcode. @@ -3023,9 +3385,11 @@ HiiCreateNumericOpCode ( { EFI_IFR_NUMERIC OpCode; UINTN Position; + UINTN Length; ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); + Length = 0; ZeroMem (&OpCode, sizeof (OpCode)); OpCode.Question.QuestionId = QuestionId; OpCode.Question.VarStoreId = VarStoreId; @@ -3040,33 +3404,39 @@ HiiCreateNumericOpCode ( OpCode.data.u8.MinValue = (UINT8)Minimum; OpCode.data.u8.MaxValue = (UINT8)Maximum; OpCode.data.u8.Step = (UINT8)Step; + Length = 3; break; case EFI_IFR_NUMERIC_SIZE_2: OpCode.data.u16.MinValue = (UINT16)Minimum; OpCode.data.u16.MaxValue = (UINT16)Maximum; OpCode.data.u16.Step = (UINT16)Step; + Length = 6; break; case EFI_IFR_NUMERIC_SIZE_4: OpCode.data.u32.MinValue = (UINT32)Minimum; OpCode.data.u32.MaxValue = (UINT32)Maximum; OpCode.data.u32.Step = (UINT32)Step; + Length = 12; break; case EFI_IFR_NUMERIC_SIZE_8: OpCode.data.u64.MinValue = Minimum; OpCode.data.u64.MaxValue = Maximum; OpCode.data.u64.Step = Step; + Length = 24; break; } + Length += OFFSET_OF (EFI_IFR_NUMERIC, data); + if (DefaultsOpCodeHandle == NULL) { - return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, sizeof (OpCode)); + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length); } Position = InternalHiiOpCodeHandlePosition (OpCodeHandle); - InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, sizeof (OpCode), 0, 1); + InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length, 0, 1); InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle); HiiCreateEndOpCode (OpCodeHandle); return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position; @@ -3179,6 +3549,7 @@ HiiCreateOneOfOpCode ( { EFI_IFR_ONE_OF OpCode; UINTN Position; + UINTN Length; ASSERT (OptionsOpCodeHandle != NULL); ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0); @@ -3192,8 +3563,11 @@ HiiCreateOneOfOpCode ( OpCode.Question.Flags = QuestionFlags; OpCode.Flags = OneOfFlags; + Length = OFFSET_OF (EFI_IFR_ONE_OF, data); + Length += (1 << (OneOfFlags & EFI_IFR_NUMERIC_SIZE)) * 3; + Position = InternalHiiOpCodeHandlePosition (OpCodeHandle); - InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OP, sizeof (OpCode), 0, 1); + InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OP, Length, 0, 1); InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle); if (DefaultsOpCodeHandle != NULL) { InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);