X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FUefiHiiLib%2FHiiLib.c;h=6c6561711dbf3e022fd82b0836aa977810b62d28;hp=d36828a1158ebd90fd0ca4081df211fd7e4d7ffc;hb=cd5ebaa06dca3e6ef3c464081e6defe00d358c69;hpb=d91c7bf9e42e8be23bb67bf7c189348b4ec11797 diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index d36828a115..6c6561711d 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -1,8 +1,8 @@ /** @file HII Library implementation that uses DXE protocols and services. - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. This program and the accompanying materials + Copyright (c) 2006 - 2010, 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 http://opensource.org/licenses/bsd-license.php @@ -14,6 +14,23 @@ #include "InternalHiiLib.h" +#define GUID_CONFIG_STRING_TYPE 0x00 +#define NAME_CONFIG_STRING_TYPE 0x01 +#define PATH_CONFIG_STRING_TYPE 0x02 + +#define ACTION_SET_DEFAUTL_VALUE 0x01 +#define ACTION_VALIDATE_SETTING 0x02 + +#define HII_LIB_DEFAULT_VARSTORE_SIZE 0x200 + +typedef struct { + LIST_ENTRY Entry; // Link to Block array + UINT16 Offset; + UINT16 Width; + UINT8 OpCode; + UINT8 Scope; +} IFR_BLOCK_DATA; + // // Template // @@ -29,13 +46,69 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = { EFI_HII_PACKAGE_END }; +/** + Extract Hii package list GUID for given HII handle. + + If HiiHandle could not be found in the HII database, then ASSERT. + If Guid is NULL, then ASSERT. + + @param Handle Hii handle + @param Guid Package list GUID + + @retval EFI_SUCCESS Successfully extract GUID from Hii database. + +**/ +EFI_STATUS +EFIAPI +InternalHiiExtractGuidFromHiiHandle ( + IN EFI_HII_HANDLE Handle, + OUT EFI_GUID *Guid + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; + + ASSERT (Guid != NULL); + ASSERT (Handle != NULL); + + // + // Get HII PackageList + // + BufferSize = 0; + HiiPackageList = NULL; + + Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList); + ASSERT (Status != EFI_NOT_FOUND); + + if (Status == EFI_BUFFER_TOO_SMALL) { + HiiPackageList = AllocatePool (BufferSize); + ASSERT (HiiPackageList != NULL); + + Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList); + } + if (EFI_ERROR (Status)) { + FreePool (HiiPackageList); + return Status; + } + + // + // Extract GUID + // + CopyGuid (Guid, &HiiPackageList->PackageListGuid); + + FreePool (HiiPackageList); + + return EFI_SUCCESS; +} + /** Registers a list of packages in the HII Database and returns the HII Handle associated with that registration. If an HII Handle has already been registered - with the same PackageListGuid, then NULL is returned. If there are not enough - resources to perform the registration, then NULL is returned. If an empty list - of packages is passed in, then NULL is returned. If the size of the list of - package is 0, then NULL is returned. + with the same PackageListGuid and DeviceHandle, then NULL is returned. If there + are not enough resources to perform the registration, then NULL is returned. + If an empty list of packages is passed in, then NULL is returned. If the size of + the list of package is 0, then NULL is returned. The variable arguments are pointers which point to package header that defined by UEFI VFR compiler and StringGather tool. @@ -72,7 +145,6 @@ HiiAddPackages ( ) { EFI_STATUS Status; - EFI_HII_HANDLE *HiiHandleBuffer; VA_LIST Args; UINT32 *Package; EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; @@ -82,16 +154,6 @@ HiiAddPackages ( ASSERT (PackageListGuid != NULL); - // - // Check to see if an HII Handle has already been registered with the same - // PackageListGuid - // - HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid); - if (HiiHandleBuffer != NULL) { - FreePool (HiiHandleBuffer); - return NULL; - } - // // Calculate the length of all the packages in the variable argument list // @@ -119,7 +181,7 @@ HiiAddPackages ( PackageListHeader = AllocateZeroPool (Length); // - // If the Packahge List can not be allocated, then return a NULL HII Handle + // If the Package List can not be allocated, then return a NULL HII Handle // if (PackageListHeader == NULL) { return NULL; @@ -199,18 +261,19 @@ HiiRemovePackages ( /** - Retrieves the array of all the HII Handles or the HII handle of a specific - package list in the HII Database. + Retrieves the array of all the HII Handles or the HII handles of a specific + package list GUID in the HII Database. This array is terminated with a NULL HII Handle. This function allocates the returned array using AllocatePool(). The caller is responsible for freeing the array with FreePool(). @param[in] PackageListGuid An optional parameter that is used to request - an HII Handle that is associatd with a specific - Package List GUID. If this parameter is NULL + HII Handles associated with a specific + Package List GUID. If this parameter is NULL, then all the HII Handles in the HII Database - are returned. If this parameter is not NULL - then at most 1 HII Handle is returned. + are returned. If this parameter is not NULL, + then zero or more HII Handles associated with + PackageListGuid are returned. @retval NULL No HII handles were found in the HII database @retval NULL The array of HII Handles could not be retrieved @@ -228,7 +291,8 @@ HiiGetHiiHandles ( EFI_HII_HANDLE TempHiiHandleBuffer; EFI_HII_HANDLE *HiiHandleBuffer; EFI_GUID Guid; - UINTN Index; + UINTN Index1; + UINTN Index2; // // Retrieve the size required for the buffer of all HII handles. @@ -291,83 +355,30 @@ HiiGetHiiHandles ( // return HiiHandleBuffer; } else { - for (Index = 0; HiiHandleBuffer[Index] != NULL; Index++) { - Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); + for (Index1 = 0, Index2 = 0; HiiHandleBuffer[Index1] != NULL; Index1++) { + Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index1], &Guid); ASSERT_EFI_ERROR (Status); if (CompareGuid (&Guid, PackageListGuid)) { - HiiHandleBuffer[0] = HiiHandleBuffer[Index]; - HiiHandleBuffer[1] = NULL; - return HiiHandleBuffer; + HiiHandleBuffer[Index2++] = HiiHandleBuffer[Index1]; } } - FreePool (HiiHandleBuffer); - return NULL; - } -} - -/** - Extract Hii package list GUID for given HII handle. - - If HiiHandle could not be found in the HII database, then ASSERT. - If Guid is NULL, then ASSERT. - - @param Handle Hii handle - @param Guid Package list GUID - - @retval EFI_SUCCESS Successfully extract GUID from Hii database. - -**/ -EFI_STATUS -EFIAPI -InternalHiiExtractGuidFromHiiHandle ( - IN EFI_HII_HANDLE Handle, - OUT EFI_GUID *Guid - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - - ASSERT (Guid != NULL); - ASSERT (Handle != NULL); - - // - // Get HII PackageList - // - BufferSize = 0; - HiiPackageList = NULL; - - Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList); - ASSERT (Status != EFI_NOT_FOUND); - - if (Status == EFI_BUFFER_TOO_SMALL) { - HiiPackageList = AllocatePool (BufferSize); - ASSERT (HiiPackageList != NULL); - - Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList); - } - if (EFI_ERROR (Status)) { - FreePool (HiiPackageList); - return Status; + if (Index2 > 0) { + HiiHandleBuffer[Index2] = NULL; + return HiiHandleBuffer; + } else { + FreePool (HiiHandleBuffer); + return NULL; + } } - - // - // Extract GUID - // - CopyGuid (Guid, &HiiPackageList->PackageListGuid); - - FreePool (HiiPackageList); - - return EFI_SUCCESS; } /** Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for hex digits that appear between a '=' and a '&' in a config string. - If String is NULL, then ASSERT(). + If ConfigString is NULL, then ASSERT(). - @param[in] String Pointer to a Null-terminated Unicode string. + @param[in] ConfigString Pointer to a Null-terminated Unicode string. @return Pointer to the Null-terminated Unicode result string. @@ -446,73 +457,16 @@ InternalHiiBlockToConfig ( return ConfigResp; } -/** - Uses the ConfigToBlock() service of the Config Routing Protocol to - convert to a block. The block is allocated using - AllocatePool(). The caller is responsible for freeing the block - using FreePool(). - - If ConfigResp is NULL, then ASSERT(). - - @param[in] ConfigResp Pointer to a Null-terminated Unicode string. - @param[in] BufferSize Length in bytes of buffer to hold retrived data. - - @retval NULL The block could not be generated.. - @retval Other Pointer to the allocated block. - -**/ -UINT8 * -EFIAPI -InternalHiiConfigToBlock ( - IN EFI_STRING ConfigResp, - IN UINTN BlockSize - ) -{ - EFI_STATUS Status; - CHAR16 *Progress; - UINT8 *Block; - - ASSERT (ConfigResp != NULL); - - // - // Allocate a buffer to hold the conversion - // - Block = AllocateZeroPool (BlockSize); - if (Block == NULL) { - return NULL; - } - - // - // Convert to a buffer - // - Status = gHiiConfigRouting->ConfigToBlock ( - gHiiConfigRouting, - ConfigResp, - Block, - &BlockSize, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (Block); - return NULL; - } - - // - // Return converted buffer - // - return Block; -} - /** Uses the BrowserCallback() service of the Form Browser Protocol to retrieve or set uncommitted data. If sata i being retrieved, then the buffer is allocated using AllocatePool(). The caller is then responsible for freeing the buffer using FreePool(). - @param[in] VariableName Pointer to a Null-terminated Unicode string. This - is an optional parameter that may be NULL. @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional parameter that may be NULL. + @param[in] VariableName Pointer to a Null-terminated Unicode string. This + is an optional parameter that may be NULL. @param[in] SetResultsData If not NULL, then this parameter specified the buffer of uncommited data to set. If this parameter is NULL, then the caller is requesting to get the uncommited data @@ -564,6 +518,15 @@ InternalHiiBrowserCallback ( VariableGuid, VariableName ); + + if (!EFI_ERROR (Status)) { + // + // No Resluts Data, only allocate one char for '\0' + // + ResultsData = AllocateZeroPool (sizeof (CHAR16)); + return ResultsData; + } + if (Status != EFI_BUFFER_TOO_SMALL) { return NULL; } @@ -728,296 +691,1383 @@ HiiConstructConfigHdr ( } /** - Allocates and returns a Null-terminated Unicode string. + Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path + to binary buffer from . - If Guid is NULL, then ASSERT(). - If Name is NULL, then ASSERT(). - If BlockNameArray is NULL, then ASSERT(). - - @param[in] Guid GUID of the buffer storage. - @param[in] Name Name of the buffer storage. - @param[in] DriverHandle The DriverHandle that support a Device Path - Protocol. - @param[in] BufferStorage Content of the buffer storage. - @param[in] BufferStorageSize Length in bytes of the buffer storage. - @param[in] BlockNameArray Array generated by VFR compiler. This array - contains a UINT32 value that is the length - of BlockNameArray in bytes, followed by pairs - of 16-bit values that are the offset and length - values used to contruct a string. - @param[in] ... A variable argument list that contains pairs of 16-bit - ALTCFG identifiers and pointers to DefaultValueArrays. - The variable argument list is terminated by a NULL - DefaultValueArray pointer. A DefaultValueArray - contains a UINT32 value that is the length, in bytes, - of the DefaultValueArray. The UINT32 length value - is followed by a series of records that contain - a 16-bit WIDTH value followed by a byte array with - WIDTH entries. The records must be parsed from - beginning to end until the UINT32 length limit - is reached. - - @retval NULL There are not enough resources to process the request. - @retval NULL A could not be retrieved from the Config - Routing Protocol. - @retval Other A pointer to the Null-terminate Unicode - string. + This is a internal function. + + @param String UEFI configuration string. + @param Flag Flag specifies what type buffer will be retrieved. + @param Buffer Binary of Guid, Name or Device path. + + @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid. + @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures. + @retval EFI_SUCCESS The buffer data is retrieved and translated to + binary format. **/ -EFI_STRING -EFIAPI -HiiConstructConfigAltResp ( - IN CONST EFI_GUID *Guid, - IN CONST CHAR16 *Name, - IN EFI_HANDLE DriverHandle, - IN CONST VOID *BufferStorage, - IN UINTN BufferStorageSize, - IN CONST VOID *BlockNameArray, - ... +EFI_STATUS +InternalHiiGetBufferFromString ( + IN EFI_STRING String, + IN UINT8 Flag, + OUT UINT8 **Buffer ) { - UINTN Length; - CHAR16 *String; - CHAR16 *ConfigHdr; - UINT8 *Buffer; - UINT8 *BufferEnd; - CHAR16 *ConfigRequest; - EFI_STRING ConfigResp; - EFI_STRING ConfigAltResp; - VA_LIST Args; - UINTN AltCfgId; - UINT16 Width; - UINT16 OffsetValue; - UINT16 WidthValue; - - ASSERT (Guid != NULL); - ASSERT (Name != NULL); - ASSERT (BlockNameArray != NULL); - + UINTN Length; + EFI_STRING ConfigHdr; + CHAR16 *StringPtr; + UINT8 *DataBuffer; + CHAR16 TemStr[5]; + UINTN Index; + UINT8 DigitUint8; + + if (String == NULL || Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + DataBuffer = NULL; + StringPtr = NULL; + ConfigHdr = String; // - // Initialize local variables + // The content between 'GUID', 'NAME', 'PATH' of and '&' of next element + // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string. // - ConfigHdr = NULL; - ConfigRequest = NULL; - ConfigResp = NULL; + for (Length = 0; *String != 0 && *String != L'&'; String++, Length++); - // - // Construct : "GUID=...&NAME=...&PATH=..." - // - ConfigHdr = HiiConstructConfigHdr (Guid, Name, DriverHandle); - if (ConfigHdr == NULL) { - goto Exit; + switch (Flag) { + case GUID_CONFIG_STRING_TYPE: + case PATH_CONFIG_STRING_TYPE: + // + // The data in is encoded as hex UNICODE %02x bytes in the same order + // as the device path and Guid resides in RAM memory. + // Translate the data into binary. + // + DataBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2); + if (DataBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + // + // Convert binary byte one by one + // + ZeroMem (TemStr, sizeof (TemStr)); + for (Index = 0; Index < Length; Index ++) { + TemStr[0] = ConfigHdr[Index]; + DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + if ((Index & 1) == 0) { + DataBuffer [Index/2] = DigitUint8; + } else { + DataBuffer [Index/2] = (UINT8) ((DataBuffer [Index/2] << 4) + DigitUint8); + } + } + + *Buffer = DataBuffer; + break; + + case NAME_CONFIG_STRING_TYPE: + // + // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD" + // + + // + // Add the tailling char L'\0' + // + DataBuffer = (UINT8 *) AllocateZeroPool ((Length/4 + 1) * sizeof (CHAR16)); + if (DataBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + // + // Convert character one by one + // + StringPtr = (CHAR16 *) DataBuffer; + ZeroMem (TemStr, sizeof (TemStr)); + for (Index = 0; Index < Length; Index += 4) { + StrnCpy (TemStr, ConfigHdr + Index, 4); + StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr); + } + // + // Add tailing L'\0' character + // + StringPtr[Index/4] = L'\0'; + + *Buffer = DataBuffer; + break; + + default: + return EFI_INVALID_PARAMETER; + break; } + return EFI_SUCCESS; +} + +/** + This function checks VarOffset and VarWidth is in the block range. + + @param BlockArray The block array is to be checked. + @param VarOffset Offset of var to the structure + @param VarWidth Width of var. + + @retval TRUE This Var is in the block range. + @retval FALSE This Var is not in the block range. +**/ +BOOLEAN +BlockArrayCheck ( + IN IFR_BLOCK_DATA *BlockArray, + IN UINT16 VarOffset, + IN UINT16 VarWidth + ) +{ + LIST_ENTRY *Link; + IFR_BLOCK_DATA *BlockData; + // - // Compute the length of the entire request starting with and a - // Null-terminator + // No Request Block array, all vars are got. // - Length = StrLen (ConfigHdr) + 1; - + if (BlockArray == NULL) { + return TRUE; + } + // - // Determine the size Offset/Width pairs + // Check the input var is in the request block range. // - Buffer = (UINT8 *)BlockNameArray; - BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer); - Buffer += sizeof (UINT32); + for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) { + BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); + if ((VarOffset >= BlockData->Offset) && ((VarOffset + VarWidth) <= (BlockData->Offset + BlockData->Width))) { + return TRUE; + } + } + + return FALSE; +} + +/** + Get the value of in format, i.e. the value of OFFSET + or WIDTH or VALUE. + ::= 'OFFSET='&'WIDTH='&'VALUE'= + + @param ValueString String in format and points to the + first character of . + @param ValueData The output value. Caller takes the responsibility + to free memory. + @param ValueLength Length of the , in characters. + + @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary + structures. + @retval EFI_SUCCESS Value of is outputted in Number + successfully. + +**/ +EFI_STATUS +EFIAPI +InternalHiiGetValueOfNumber ( + IN EFI_STRING ValueString, + OUT UINT8 **ValueData, + OUT UINTN *ValueLength + ) +{ + EFI_STRING StringPtr; + UINTN Length; + UINT8 *Buf; + UINT8 DigitUint8; + UINTN Index; + CHAR16 TemStr[2]; + + ASSERT (ValueString != NULL && ValueData != NULL && ValueLength != NULL); + ASSERT (*ValueString != L'\0'); // - // Add length that is composed of one or more Offset/Width pairs - // - // ::= &OFFSET=1234&WIDTH=1234 - // | 8 | 4 | 7 | 4 | + // Get the length of value string // - Length += (((BufferEnd - Buffer) / (sizeof (UINT16) + sizeof (UINT16))) * (8 + 4 + 7 + 4)); - + StringPtr = ValueString; + while (*StringPtr != L'\0' && *StringPtr != L'&') { + StringPtr++; + } + Length = StringPtr - ValueString; + // - // Allocate buffer for the entire + // Allocate buffer to store the value // - ConfigRequest = AllocateZeroPool (Length * sizeof (CHAR16)); - if (ConfigRequest == NULL) { - goto Exit; + Buf = (UINT8 *) AllocateZeroPool ((Length + 1) / 2); + if (Buf == NULL) { + return EFI_OUT_OF_RESOURCES; } - String = ConfigRequest; - + // - // Start with + // Convert character one by one to the value buffer // - StrCpy (String, ConfigHdr); - String += StrLen (String); - + ZeroMem (TemStr, sizeof (TemStr)); + for (Index = 0; Index < Length; Index ++) { + TemStr[0] = ValueString[Length - Index - 1]; + DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + if ((Index & 1) == 0) { + Buf [Index/2] = DigitUint8; + } else { + Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]); + } + } + // - // Loop through all the Offset/Width pairs and append them to ConfigRequest + // Set the converted value and string length. // - while (Buffer < BufferEnd) { + *ValueData = Buf; + *ValueLength = Length; + return EFI_SUCCESS; +} + +/** + 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. + + @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 + ) +{ + 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_STATUS Status; + EFI_HII_PACKAGE_HEADER PacakgeHeader; + UINT32 PackageOffset; + UINT8 *PackageData; + UINTN IfrOffset; + EFI_IFR_OP_HEADER *IfrOpHdr; + EFI_IFR_VARSTORE *IfrVarStore; + EFI_IFR_ONE_OF *IfrOneOf; + EFI_IFR_NUMERIC *IfrNumeric; + EFI_IFR_ONE_OF_OPTION *IfrOneOfOption; + EFI_IFR_CHECKBOX *IfrCheckBox; + EFI_IFR_STRING *IfrString; + CHAR8 *VarStoreName; + UINTN Index; + + // + // 1. Get the current setting to current block data array and Convert them into VarBuffer + // + + // + // 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; + } + + // + // 2. 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. + // + 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); + // + // Validate current setting to the value built in IFR opcode + // + switch (IfrOpHdr->OpCode) { + case EFI_IFR_VARSTORE_OP: + // + // VarStoreId has been found. No further found. + // + if (IfrVarStore != NULL) { + break; + } + // + // Find the matched VarStoreId to the input VarGuid and VarName + // + IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr; + if (CompareGuid ((EFI_GUID *) (VOID *) &IfrVarStore->Guid, VarGuid)) { + VarStoreName = (CHAR8 *) IfrVarStore->Name; + for (Index = 0; VarStoreName[Index] != 0; Index ++) { + if ((CHAR16) VarStoreName[Index] != VarName[Index]) { + break; + } + } + // + // The matched VarStore is found. + // + if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) { + IfrVarStore = NULL; + } + } else { + IfrVarStore = NULL; + } + break; + case EFI_IFR_FORM_OP: + case EFI_IFR_FORM_MAP_OP: + // + // Check the matched VarStoreId is found. + // + if (IfrVarStore == NULL) { + Status = EFI_SUCCESS; + goto Done; + } + break; + case EFI_IFR_ONE_OF_OP: + // + // Check whether current value is the one of option. + // + + // + // OneOf question is not in IFR Form. This IFR form is not valid. + // + if (IfrVarStore == NULL) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + // + // Check whether this question is for the requested varstore. + // + IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr; + if (IfrOneOf->Question.VarStoreId != IfrVarStore->VarStoreId) { + break; + } + + // + // 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) > IfrVarStore->Size) { + // + // This question exceeds the var store size. + // + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // 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; + case EFI_IFR_NUMERIC_OP: + // + // Check the current value is in the numeric range. + // + + // + // Numeric question is not in IFR Form. This IFR form is not valid. + // + if (IfrVarStore == NULL) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + // + // Check whether this question is for the requested varstore. + // + IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpHdr; + if (IfrNumeric->Question.VarStoreId != IfrVarStore->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)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage + // + if ((Offset + Width) > IfrVarStore->Size) { + // + // This question exceeds the var store size. + // + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // 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; + } + break; + case EFI_IFR_NUMERIC_SIZE_2: + if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) { + // + // Not in the valid range. + // + Status = EFI_INVALID_PARAMETER; + goto Done; + } + break; + case EFI_IFR_NUMERIC_SIZE_4: + if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) { + // + // Not in the valid range. + // + Status = EFI_INVALID_PARAMETER; + goto Done; + } + break; + case EFI_IFR_NUMERIC_SIZE_8: + if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) { + // + // Not in the valid range. + // + Status = EFI_INVALID_PARAMETER; + goto Done; + } + break; + } + + break; + case EFI_IFR_CHECKBOX_OP: + // + // Check value is BOOLEAN type, only 0 and 1 is valid. + // + + // + // CheckBox question is not in IFR Form. This IFR form is not valid. + // + if (IfrVarStore == NULL) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // Check whether this question is for the requested varstore. + // + IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr; + if (IfrCheckBox->Question.VarStoreId != IfrVarStore->VarStoreId) { + break; + } + + // + // Get Offset by Question header + // + Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset; + Width = sizeof (BOOLEAN); + // + // 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) > IfrVarStore->Size) { + // + // This question exceeds the var store size. + // + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // Boolean type, only 1 and 0 is valid. + // + if (*(VarBuffer + Offset) > 1) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + break; + case EFI_IFR_STRING_OP: + // + // Check current string length is less than maxsize + // + + // + // CheckBox question is not in IFR Form. This IFR form is not valid. + // + if (IfrVarStore == NULL) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // Check whether this question is for the requested varstore. + // + IfrString = (EFI_IFR_STRING *) IfrOpHdr; + if (IfrString->Question.VarStoreId != IfrVarStore->VarStoreId) { + break; + } + + // + // Get Offset/Width by Question header and 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)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage + // + if ((Offset + Width) > IfrVarStore->Size) { + // + // This question exceeds the var store size. + // + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // Check current string length is less than maxsize + // + if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + 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; + } + + // + // 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; + } + } + + break; + case EFI_IFR_END_OP: + // + // Decrease opcode scope for the validated opcode + // + if (VarBlockData.Scope > 0) { + VarBlockData.Scope --; + } + + // + // 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; + } + // + // Go to the next opcode + // + IfrOffset += IfrOpHdr->Length; + } + // + // Only one form is in a package list. + // + break; + } + + // + // Go to next package. + // + PackageOffset += PacakgeHeader.Length; + } + +Done: + if (VarBuffer != NULL) { + FreePool (VarBuffer); + } + + if (CurrentBlockArray != NULL) { + // + // Free Link Array CurrentBlockArray + // + while (!IsListEmpty (&CurrentBlockArray->Entry)) { + BlockData = BASE_CR (CurrentBlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry); + RemoveEntryList (&BlockData->Entry); + FreePool (BlockData); + } + FreePool (CurrentBlockArray); + } + + return Status; +} + +/** + This function parses the input ConfigRequest string and its matched IFR code + string for setting default value and validating current setting. + + 1. For setting default action, Reset the default value specified by DefaultId + to the driver configuration got by Request string. + 2. For validating current setting, Validate the current configuration + by parsing HII form IFR opcode. + + NULL request string support depends on the ExportConfig interface of + HiiConfigRouting protocol in UEFI specification. + + @param Request A null-terminated Unicode string in + format. It can be NULL. + If it is NULL, all current configuration for the + entirety of the current HII database will be validated. + If it is NULL, all configuration for the + entirety of the current HII database will be reset. + @param DefaultId Specifies the type of defaults to retrieve only for setting default action. + @param ActionType Action supports setting defaults and validate current setting. + + @retval TURE Action runs successfully. + @retval FALSE Action is not valid or Action can't be executed successfully.. +**/ +BOOLEAN +EFIAPI +InternalHiiIfrValueAction ( + IN CONST EFI_STRING Request, OPTIONAL + IN UINT16 DefaultId, + IN UINT8 ActionType + ) +{ + EFI_STRING ConfigAltResp; + EFI_STRING ConfigAltHdr; + EFI_STRING ConfigResp; + EFI_STRING Progress; + EFI_STRING StringPtr; + EFI_STRING StringHdr; + EFI_STATUS Status; + EFI_HANDLE DriverHandle; + EFI_HANDLE TempDriverHandle; + EFI_HII_HANDLE *HiiHandleBuffer; + EFI_HII_HANDLE HiiHandle; + 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; + VarName = NULL; + DevicePath = NULL; + ConfigAltHdr = NULL; + HiiHandleBuffer = NULL; + Index = 0; + TempDriverHandle = NULL; + HiiHandle = NULL; + PackageData = NULL; + HiiPackageList = NULL; + + // + // Only support set default and validate setting action. + // + if ((ActionType != ACTION_SET_DEFAUTL_VALUE) && (ActionType != ACTION_VALIDATE_SETTING)) { + return FALSE; + } + + // + // Get the full requested value and deault value string. + // + if (Request != NULL) { + Status = gHiiConfigRouting->ExtractConfig ( + gHiiConfigRouting, + Request, + &Progress, + &ConfigAltResp + ); + } else { + Status = gHiiConfigRouting->ExportConfig ( + gHiiConfigRouting, + &ConfigAltResp + ); + } + + if (EFI_ERROR (Status)) { + return FALSE; + } + + StringPtr = ConfigAltResp; + + while (StringPtr != L'\0') { + // + // 1. Find GUID=...&NAME=...&PATH=... + // + StringHdr = StringPtr; + + // + // Get Guid value + // + if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"GUID="); + Status = InternalHiiGetBufferFromString (StringPtr, GUID_CONFIG_STRING_TYPE, (UINT8 **) &VarGuid); + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // Get Name value VarName + // + while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) { + StringPtr++; + } + if (*StringPtr == L'\0') { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"&NAME="); + Status = InternalHiiGetBufferFromString (StringPtr, NAME_CONFIG_STRING_TYPE, (UINT8 **) &VarName); + if (EFI_ERROR (Status)) { + goto Done; + } + // - // Append &OFFSET=XXXX&WIDTH=YYYY + // Get Path value DevicePath // - OffsetValue = ReadUnaligned16 ((UINT16 *)Buffer); - WidthValue = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16))); - UnicodeSPrint ( - String, - (8 + 4 + 7 + 4) * sizeof (CHAR16), - L"&OFFSET=%04X&WIDTH=%04X", - OffsetValue, - WidthValue - ); + while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) { + StringPtr++; + } + if (*StringPtr == L'\0') { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"&PATH="); + Status = InternalHiiGetBufferFromString (StringPtr, PATH_CONFIG_STRING_TYPE, (UINT8 **) &DevicePath); + if (EFI_ERROR (Status)) { + goto Done; + } - String += StrLen (String); - Buffer += (sizeof (UINT16) + sizeof (UINT16)); - } + // + // Get the Driver handle by the got device path. + // + TempDevicePath = DevicePath; + Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &TempDevicePath, &DriverHandle); + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // Find the matched Hii Handle for the found Driver handle + // + HiiHandleBuffer = HiiGetHiiHandles (NULL); + if (HiiHandleBuffer == NULL) { + Status = EFI_NOT_FOUND; + goto Done; + } - // - // Get the - // - ConfigResp = InternalHiiBlockToConfig (ConfigRequest, BufferStorage, BufferStorageSize); - if (ConfigResp == NULL) { - goto Exit; - } + for (Index = 0; HiiHandleBuffer[Index] != NULL; Index ++) { + gHiiDatabase->GetPackageListHandle (gHiiDatabase, HiiHandleBuffer[Index], &TempDriverHandle); + if (TempDriverHandle == DriverHandle) { + break; + } + } - // - // Compute the length of the entire response starting with and a - // Null-terminator - // - Length = StrLen (ConfigResp) + 1; + HiiHandle = HiiHandleBuffer[Index]; + FreePool (HiiHandleBuffer); - // - // Add the length associated with each pair of variable argument parameters - // - VA_START (Args, BlockNameArray); - while (TRUE) { - AltCfgId = VA_ARG (Args, UINT16); - Buffer = VA_ARG (Args, UINT8 *); - if (Buffer == NULL) { - break; + if (HiiHandle == NULL) { + // + // This request string has no its Hii package. + // 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; + goto NextConfigAltResp; } - + // - // Add length for "&&ALTCFG=XXXX" - // |1| StrLen (ConfigHdr) | 8 | 4 | + // 2. Get DefaultName string ID by parsing the PacakgeList // - Length += (1 + StrLen (ConfigHdr) + 8 + 4); - BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer); - Buffer += sizeof (UINT32); - while (Buffer < BufferEnd) { + // + // Get HiiPackage by HiiHandle + // + PackageListLength = 0; + HiiPackageList = NULL; + Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &PackageListLength, HiiPackageList); + + // + // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0. + // + if (Status != EFI_BUFFER_TOO_SMALL) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + HiiPackageList = AllocatePool (PackageListLength); + if (HiiPackageList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + + // + // Get PackageList on HiiHandle + // + Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &PackageListLength, HiiPackageList); + if (EFI_ERROR (Status)) { + 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; + } + // - // Extract Width field + // Not found the matched default string ID // - Width = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16))); - + 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. + // + Status = gHiiConfigRouting->GetAltConfig ( + gHiiConfigRouting, + ConfigAltResp, + VarGuid, + VarName, + DevicePath, + (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultName:NULL, // it can be NULL to get the current setting. + &ConfigResp + ); + + // + // The required setting can't be found. So, it is not required to be validated and set. + // + if (EFI_ERROR (Status)) { + Status = EFI_SUCCESS; + goto NextConfigAltResp; + } + // + // 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) { + goto NextConfigAltResp; + } + + // + // 4. Set the default configuration information or Validate current setting by parse IFR code. + // Current Setting is in ConfigResp, will be set into buffer, then check it again. + // + if (ActionType == ACTION_SET_DEFAUTL_VALUE) { // - // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz" - // | 8 | 4 | 7 | 4 | 7 | Width * 2 | + // Set the default configuration information. // - Length += (8 + 4 + 7 + 4 + 7 + Width * 2); - + Status = gHiiConfigRouting->RouteConfig (gHiiConfigRouting, ConfigResp, &Progress); + } else { // - // Update Buffer to the next record + // Current Setting is in ConfigResp, will be set into buffer, then check it again. // - Buffer += (sizeof (UINT16) + sizeof (UINT16) + Width); + Status = InternalHiiValidateCurrentSetting (ConfigResp, HiiPackageList, PackageListLength, VarGuid, VarName); } - } - VA_END (Args); - - // - // Allocate a buffer for the entire response - // - ConfigAltResp = AllocateZeroPool (Length * sizeof (CHAR16)); - if (ConfigAltResp == NULL) { - goto Exit; - } - String = ConfigAltResp; - // - // Add - // - StrCpy (String, ConfigResp); - String += StrLen (String); - - // - // Add for each pair of variable argument parameters - // - VA_START (Args, BlockNameArray); - while (TRUE) { - AltCfgId = VA_ARG (Args, UINT16); - Buffer = VA_ARG (Args, UINT8 *); - if (Buffer == NULL) { - break; + if (EFI_ERROR (Status)) { + goto Done; } +NextConfigAltResp: // - // Add of the form "&&ALTCFG=XXXX" - // |1| StrLen (ConfigHdr) | 8 | 4 | + // Free the allocated pacakge buffer and the got ConfigResp string. // - UnicodeSPrint ( - String, - (1 + StrLen (ConfigHdr) + 8 + 4) * sizeof (CHAR16), - L"&%s&ALTCFG=%04X", - ConfigHdr, - AltCfgId - ); - String += StrLen (String); + if (HiiPackageList != NULL) { + FreePool (HiiPackageList); + HiiPackageList = NULL; + } + + if (ConfigResp != NULL) { + FreePool (ConfigResp); + ConfigResp = NULL; + } // - // Add ::= * + // Free the allocated buffer. // - BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer); - Buffer += sizeof (UINT32); - while (Buffer < BufferEnd) { - // - // Extract Width field - // - Width = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16))); - - // - // Add - // - UnicodeSPrint ( - String, - (8 + 4 + 7 + 4 + 7 + Width * 2) * sizeof (CHAR16), - L"&OFFSET=%04X&WIDTH=%04X&VALUE=", - ReadUnaligned16 ((UINT16 *)Buffer), - Width - ); - String += StrLen (String); + FreePool (VarGuid); + VarGuid = NULL; + + FreePool (VarName); + VarName = NULL; + + FreePool (DevicePath); + DevicePath = NULL; - // - // Update Buffer to point to the value in the current record - // - Buffer += (sizeof (UINT16) + sizeof (UINT16)); + // + // 5. Jump to next ConfigAltResp for another Guid, Name, Path. + // - // - // Convert Value to a hex string in "%x" format - // NOTE: This is in the opposite byte that GUID and PATH use - // - for (; Width > 0; Width--) { - String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, Buffer[Width - 1], 2); + // + // Get and Skip ConfigHdr + // + while (*StringPtr != L'\0' && *StringPtr != L'&') { + StringPtr++; + } + if (*StringPtr == L'\0') { + break; + } + + // + // Construct ConfigAltHdr string "&&ALTCFG=\0" + // | 1 | StrLen (ConfigHdr) | 8 | 1 | + // + ConfigAltHdr = AllocateZeroPool ((1 + StringPtr - StringHdr + 8 + 1) * sizeof (CHAR16)); + if (ConfigAltHdr == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + StrCpy (ConfigAltHdr, L"&"); + StrnCat (ConfigAltHdr, StringHdr, StringPtr - StringHdr); + StrCat (ConfigAltHdr, L"&ALTCFG="); + + // + // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr + // + while ((StringHdr = StrStr (StringPtr, ConfigAltHdr)) != NULL) { + StringPtr = StringHdr + StrLen (ConfigAltHdr); + if (*StringPtr == L'\0') { + break; } - // - // Update Buffer to the next record - // - Buffer += Width; } - } - VA_END (Args); + + // + // Free the allocated ConfigAltHdr string + // + FreePool (ConfigAltHdr); + if (*StringPtr == L'\0') { + break; + } + + // + // Find &GUID as the next ConfigHdr + // + StringPtr = StrStr (StringPtr, L"&GUID"); + if (StringPtr == NULL) { + break; + } - // - // Convert all hex digits in range [A-F] in the configuration header to [a-f] - // - return InternalHiiLowerConfigString (ConfigAltResp); + // + // Skip char '&' + // + StringPtr ++; + } + +Done: + if (VarGuid != NULL) { + FreePool (VarGuid); + } -Exit: - if (ConfigHdr != NULL) { - FreePool (ConfigHdr); + if (VarName != NULL) { + FreePool (VarName); } - if (ConfigRequest != NULL) { - FreePool (ConfigRequest); + + if (DevicePath != NULL) { + FreePool (DevicePath); } + if (ConfigResp != NULL) { FreePool (ConfigResp); } - return NULL; + if (ConfigAltResp != NULL) { + FreePool (ConfigAltResp); + } + + if (HiiPackageList != NULL) { + FreePool (HiiPackageList); + } + + if (EFI_ERROR (Status)) { + return FALSE; + } + + return TRUE; +} + +/** + Validate the current configuration by parsing HII form IFR opcode. + + NULL request string support depends on the ExportConfig interface of + HiiConfigRouting protocol in UEFI specification. + + @param Request A null-terminated Unicode string in + format. It can be NULL. + If it is NULL, all current configuration for the + entirety of the current HII database will be validated. + + @retval TURE Current configuration is valid. + @retval FALSE Current configuration is invalid. +**/ +BOOLEAN +EFIAPI +HiiValidateSettings ( + IN CONST EFI_STRING Request OPTIONAL + ) +{ + return InternalHiiIfrValueAction (Request, 0, ACTION_VALIDATE_SETTING); +} + +/** + Reset the default value specified by DefaultId to the driver + configuration got by Request string. + + NULL request string support depends on the ExportConfig interface of + HiiConfigRouting protocol in UEFI specification. + + @param Request A null-terminated Unicode string in + format. It can be NULL. + If it is NULL, all configuration for the + entirety of the current HII database will be reset. + @param DefaultId Specifies the type of defaults to retrieve. + + @retval TURE The default value is set successfully. + @retval FALSE The default value can't be found and set. +**/ +BOOLEAN +EFIAPI +HiiSetToDefaults ( + IN CONST EFI_STRING Request, OPTIONAL + IN UINT16 DefaultId + ) +{ + return InternalHiiIfrValueAction (Request, DefaultId, ACTION_SET_DEFAUTL_VALUE); } /** @@ -1038,7 +2088,7 @@ Exit: @param StartSearchString Pointer to the Null-terminated Unicode string that marks the start of the value string to compare. @param StopSearchString Pointer to the Null-terminated Unicode string that - marks the end of the vakue string to compare. + marks the end of the value string to compare. @retval FALSE StartSearchString is not present in FirstString. @retval FALSE StartSearchString is not present in SecondString. @@ -1154,39 +2204,41 @@ HiiIsConfigHdrMatch ( } /** - Retrieves uncommited data from the Form Browser and converts it to a binary - buffer. The returned buffer is allocated using AllocatePool(). The caller - is responsible for freeing the returned buffer using FreePool(). + Retrieves uncommitted data from the Form Browser and converts it to a binary + buffer. @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional parameter that may be NULL. @param[in] VariableName Pointer to a Null-terminated Unicode string. This is an optional parameter that may be NULL. - @param[in] BufferSize Length in bytes of buffer to hold retrived data. + @param[in] BufferSize Length in bytes of buffer to hold retrieved data. + @param[out] Buffer Buffer of data to be updated. - @retval NULL The uncommitted data could not be retrieved. - @retval Other A pointer to a buffer containing the uncommitted data. + @retval FALSE The uncommitted data could not be retrieved. + @retval TRUE The uncommitted data was retrieved. **/ -UINT8 * +BOOLEAN EFIAPI HiiGetBrowserData ( IN CONST EFI_GUID *VariableGuid, OPTIONAL IN CONST CHAR16 *VariableName, OPTIONAL - IN UINTN BlockSize + IN UINTN BufferSize, + OUT UINT8 *Buffer ) { EFI_STRING ResultsData; UINTN Size; EFI_STRING ConfigResp; - UINT8 *Block; + EFI_STATUS Status; + CHAR16 *Progress; // // Retrieve the results data from the Browser Callback // ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, NULL); if (ResultsData == NULL) { - return NULL; + return FALSE; } // @@ -1202,16 +2254,29 @@ HiiGetBrowserData ( // FreePool (ResultsData); if (ConfigResp == NULL) { - return NULL; + return FALSE; } // // Convert to a buffer // - Block = InternalHiiConfigToBlock (ConfigResp, BlockSize); + Status = gHiiConfigRouting->ConfigToBlock ( + gHiiConfigRouting, + ConfigResp, + Buffer, + &BufferSize, + &Progress + ); + // + // Free the allocated buffer + // FreePool (ConfigResp); - return Block; + if (EFI_ERROR (Status)) { + return FALSE; + } + + return TRUE; } /** @@ -1219,10 +2284,10 @@ HiiGetBrowserData ( If Buffer is NULL, then ASSERT(). - @param[in] VariableName Pointer to a Null-terminated Unicode string. This - is an optional parameter that may be NULL. @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional parameter that may be NULL. + @param[in] VariableName Pointer to a Null-terminated Unicode string. This + is an optional parameter that may be NULL. @param[in] BufferSize Length, in bytes, of Buffer. @param[in] Buffer Buffer of data to commit. @param[in] RequestElement An optional field to specify which part of the @@ -1354,12 +2419,14 @@ HiiAllocateOpCodeHandle ( } /** - Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle(). + Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle(). When an OpCode Handle is freed, all of the opcodes associated with the OpCode Handle are also freed. If OpCodeHandle is NULL, then ASSERT(). + @param[in] OpCodeHandle Handle to the buffer of opcodes. + **/ VOID EFIAPI @@ -1378,6 +2445,13 @@ HiiFreeOpCodeHandle ( FreePool (OpCodeBuffer); } +/** + Internal function gets the current position of opcode buffer. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + + @return Current position of opcode buffer. +**/ UINTN EFIAPI InternalHiiOpCodeHandlePosition ( @@ -1387,6 +2461,13 @@ InternalHiiOpCodeHandlePosition ( return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Position; } +/** + Internal function gets the start pointer of opcode buffer. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + + @return Pointer to the opcode buffer base. +**/ UINT8 * EFIAPI InternalHiiOpCodeHandleBuffer ( @@ -1396,11 +2477,20 @@ InternalHiiOpCodeHandleBuffer ( return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Buffer; } +/** + Internal function reserves the enough buffer for current opcode. + When the buffer is not enough, Opcode buffer will be extended. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] Size Size of current opcode. + + @return Pointer to the current opcode. +**/ UINT8 * EFIAPI InternalHiiGrowOpCodeHandle ( - VOID *OpCodeHandle, - UINTN Size + IN VOID *OpCodeHandle, + IN UINTN Size ) { HII_LIB_OPCODE_BUFFER *OpCodeBuffer; @@ -1426,6 +2516,18 @@ InternalHiiGrowOpCodeHandle ( return Buffer; } +/** + Internal function creates opcode based on the template opcode. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] OpCodeTemplate Pointer to the template buffer of opcode. + @param[in] OpCode OpCode IFR value. + @param[in] OpCodeSize Size of opcode. + @param[in] ExtensionSize Size of extended opcode. + @param[in] Scope Scope bit of opcode. + + @return Pointer to the current opcode with opcode data. +**/ UINT8 * EFIAPI InternalHiiCreateOpCodeExtended ( @@ -1451,6 +2553,16 @@ InternalHiiCreateOpCodeExtended ( return (UINT8 *)CopyMem (Buffer, Header, OpCodeSize); } +/** + Internal function creates opcode based on the template opcode for the normal opcode. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] OpCodeTemplate Pointer to the template buffer of opcode. + @param[in] OpCode OpCode IFR value. + @param[in] OpCodeSize Size of opcode. + + @return Pointer to the current opcode with opcode data. +**/ UINT8 * EFIAPI InternalHiiCreateOpCode ( @@ -1479,7 +2591,7 @@ InternalHiiCreateOpCode ( **/ UINT8 * EFIAPI -InternalHiiCreateRawOpCodes ( +HiiCreateRawOpCodes ( IN VOID *OpCodeHandle, IN UINT8 *RawBuffer, IN UINTN RawBufferSize @@ -1518,7 +2630,7 @@ InternalHiiAppendOpCodes ( ASSERT (RawOpCodeHandle != NULL); RawOpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)RawOpCodeHandle; - return InternalHiiCreateRawOpCodes (OpCodeHandle, RawOpCodeBuffer->Buffer, RawOpCodeBuffer->Position); + return HiiCreateRawOpCodes (OpCodeHandle, RawOpCodeBuffer->Buffer, RawOpCodeBuffer->Position); } /** @@ -2162,13 +3274,17 @@ HiiCreateOrderedListOpCode ( This is the internal worker function to update the data in a form specified by FormSetGuid, FormId and Label. - @param FormSetGuid The optional Formset GUID. - @param FormId The Form ID. - @param Package The package header. - - @param TempPacakge The resultant package. + @param[in] FormSetGuid The optional Formset GUID. + @param[in] FormId The Form ID. + @param[in] Package The package header. + @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR + opcodes to be inserted or replaced in the form. + @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode + that marks the end of a replace operation in the form. + @param[out] TempPackage The resultant package. @retval EFI_SUCCESS The function completes successfully. + @retval EFI_NOT_FOUND The updated opcode or endopcode is not found. **/ EFI_STATUS @@ -2218,7 +3334,7 @@ InternalHiiUpdateFormPackageData ( } else { GetFormSet = FALSE; } - } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP) { + } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP || IfrOpHdr->OpCode == EFI_IFR_FORM_MAP_OP) { if (CompareMem (&((EFI_IFR_FORM *) IfrOpHdr)->FormId, &FormId, sizeof (EFI_FORM_ID)) == 0) { GetForm = TRUE; } else { @@ -2324,22 +3440,22 @@ InternalHiiUpdateFormPackageData ( The form to update is specified by Handle, FormSetGuid, and FormId. Binary comparisons of IFR opcodes are performed from the beginning of the form being updated until an IFR opcode is found that exactly matches the first IFR opcode - specifed by StartOpCodeHandle. The following rules are used to determine if + specified by StartOpCodeHandle. The following rules are used to determine if an insert, replace, or delete operation is performed. 1) If no matches are found, then NULL is returned. 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes - from StartOpcodeHandle except the first opcode are inserted immediately after - the matching IFR opcode in the form beng updated. + from StartOpCodeHandle except the first opcode are inserted immediately after + the matching IFR opcode in the form to be updated. 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made - from the matching IFR opcode until an IFR opcode exatly matches the first + from the matching IFR opcode until an IFR opcode exactly matches the first IFR opcode specified by EndOpCodeHandle. If no match is found for the first IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match is found, then all of the IFR opcodes between the start match and the end match are deleted from the form being updated and all of the IFR opcodes - from StartOpcodeHandle except the first opcode are inserted immediately after + from StartOpCodeHandle except the first opcode are inserted immediately after the matching start IFR opcode. If StartOpCcodeHandle only contains one - IFR instruction, then the result of ths operation will delete all of the IFR + IFR instruction, then the result of this operation will delete all of the IFR opcodes between the start end matches. If HiiHandle is NULL, then ASSERT(). @@ -2380,8 +3496,8 @@ HiiUpdateForm ( IN EFI_HII_HANDLE HiiHandle, IN EFI_GUID *FormSetGuid, OPTIONAL IN EFI_FORM_ID FormId, - IN VOID *StartOpcodeHandle, - IN VOID *EndOpcodeHandle OPTIONAL + IN VOID *StartOpCodeHandle, + IN VOID *EndOpCodeHandle OPTIONAL ) { EFI_STATUS Status; @@ -2402,19 +3518,19 @@ HiiUpdateForm ( // Input update data can't be NULL. // ASSERT (HiiHandle != NULL); - ASSERT (StartOpcodeHandle != NULL); + ASSERT (StartOpCodeHandle != NULL); UpdatePackageList = NULL; TempPacakge = NULL; HiiPackageList = NULL; // - // Restrive buffer data from Opcode Handle + // Retrieve buffer data from Opcode Handle // - OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpcodeHandle; - OpCodeBufferEnd = (HII_LIB_OPCODE_BUFFER *) EndOpcodeHandle; + OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpCodeHandle; + OpCodeBufferEnd = (HII_LIB_OPCODE_BUFFER *) EndOpCodeHandle; // - // Get the orginal package list + // Get the original package list // BufferSize = 0; HiiPackageList = NULL; @@ -2465,7 +3581,7 @@ HiiUpdateForm ( UpdateBufferPos += sizeof (EFI_HII_PACKAGE_LIST_HEADER); // - // Go through each package to find the matched pacakge and update one by one + // Go through each package to find the matched package and update one by one // Updated = FALSE; Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); @@ -2481,7 +3597,7 @@ HiiUpdateForm ( // Status = InternalHiiUpdateFormPackageData (FormSetGuid, FormId, Package, OpCodeBufferStart, OpCodeBufferEnd, TempPacakge); // - // The matched package is found. Its pacakge buffer will be updated by the input new data. + // The matched package is found. Its package buffer will be updated by the input new data. // if (!EFI_ERROR(Status)) { // @@ -2511,7 +3627,7 @@ HiiUpdateForm ( WriteUnaligned32 (&UpdatePackageList->PackageLength, (UINT32) BufferSize); // - // Update Pacakge to show form + // Update Package to show form // Status = gHiiDatabase->UpdatePackageList (gHiiDatabase, HiiHandle, UpdatePackageList); } else { @@ -2536,78 +3652,3 @@ Finish: return Status; } - -/** - Configure the buffer accrording to ConfigBody strings in the format of - , , , . - This ConfigBody strings is generated by UEFI VfrCompiler for the default - values in a Form Set. The name of the ConfigBody strings is VfrMyIfrNVDataDefault0000 - constructed following this rule: - "Vfr" + varstore.name + "Default" + defaultstore.attributes. - Check the generated C file in Output for details. - - @param Buffer The start address of buffer. - @param BufferSize The size of buffer. - @param Number The number of the strings. - @param ... Variable argument list for default value in format - generated by the tool. - - @retval EFI_BUFFER_TOO_SMALL the BufferSize is too small to operate. - @retval EFI_INVALID_PARAMETER Buffer is NULL or BufferSize is 0. - @retval EFI_SUCCESS Operation successful. - -**/ -EFI_STATUS -EFIAPI -HiiIfrLibExtractDefault( - IN VOID *Buffer, - IN UINTN *BufferSize, - UINTN Number, - ... - ) -{ - VA_LIST Args; - UINTN Index; - UINT32 TotalLen; - UINT8 *BufCfgArray; - UINT8 *BufferPos; - UINT16 Offset; - UINT16 Width; - UINT8 *Value; - - if ((Buffer == NULL) || (BufferSize == NULL)) { - return EFI_INVALID_PARAMETER; - } - - Offset = 0; - Width = 0; - Value = NULL; - - VA_START (Args, Number); - for (Index = 0; Index < Number; Index++) { - BufCfgArray = (UINT8 *) VA_ARG (Args, VOID *); - TotalLen = ReadUnaligned32 ((UINT32 *)BufCfgArray); - BufferPos = BufCfgArray + sizeof (UINT32); - - while ((UINT32)(BufferPos - BufCfgArray) < TotalLen) { - Offset = ReadUnaligned16 ((UINT16 *)BufferPos); - BufferPos += sizeof (UINT16); - Width = ReadUnaligned16 ((UINT16 *)BufferPos); - BufferPos += sizeof (UINT16); - Value = BufferPos; - BufferPos += Width; - - if ((UINTN)(Offset + Width) > *BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - CopyMem ((UINT8 *)Buffer + Offset, Value, Width); - } - } - VA_END (Args); - - *BufferSize = (UINTN)Offset; - - return EFI_SUCCESS; -} -