X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FConfigRouting.c;h=30f602d30fe316aa2877106fa42a1990eba02a8c;hb=3a530010ec37a3a93bea01614b4a6f153340ceda;hp=2f5118e51268b58c661aa1454045429c9ad39027;hpb=04da0b4a11fd128c08fb0192c02a142285f6fa69;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c index 2f5118e512..30f602d30f 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c @@ -1,8 +1,8 @@ /** @file Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL. -Copyright (c) 2007 - 2008, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2007 - 2011, 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 @@ -61,8 +61,9 @@ CalculateConfigStringLen ( This is a internal function. @param String UEFI configuration string - @param DevicePath binary of a UEFI device path. + @param DevicePathData Binary of a UEFI device path. + @retval EFI_NOT_FOUND The device path is not invalid. @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 device path is retrieved and translated to @@ -72,18 +73,19 @@ CalculateConfigStringLen ( EFI_STATUS GetDevicePath ( IN EFI_STRING String, - OUT UINT8 **DevicePath + OUT UINT8 **DevicePathData ) { - UINTN Length; - EFI_STRING PathHdr; - EFI_STRING DevicePathString; - UINT8 *DevicePathBuffer; - CHAR16 TemStr[2]; - UINTN Index; - UINT8 DigitUint8; - - if (String == NULL || DevicePath == NULL) { + UINTN Length; + EFI_STRING PathHdr; + UINT8 *DevicePathBuffer; + CHAR16 TemStr[2]; + UINTN Index; + UINT8 DigitUint8; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + + + if (String == NULL || DevicePathData == NULL) { return EFI_INVALID_PARAMETER; } @@ -94,8 +96,13 @@ GetDevicePath ( if (*String == 0) { return EFI_INVALID_PARAMETER; } - + // + // Check whether path data does exist. + // String += StrLen (L"PATH="); + if (*String == 0) { + return EFI_INVALID_PARAMETER; + } PathHdr = String; // @@ -104,13 +111,13 @@ GetDevicePath ( // of UEFI device path. // for (Length = 0; *String != 0 && *String != L'&'; String++, Length++); - DevicePathString = (EFI_STRING) AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); - if (DevicePathString == NULL) { - return EFI_OUT_OF_RESOURCES; + // + // Check DevicePath Length + // + if (((Length + 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL)) { + return EFI_NOT_FOUND; } - StrnCpy (DevicePathString, PathHdr, Length); - *(DevicePathString + Length) = 0; - + // // The data in is encoded as hex UNICODE %02x bytes in the same order // as the device path resides in RAM memory. @@ -118,13 +125,15 @@ GetDevicePath ( // DevicePathBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2); if (DevicePathBuffer == NULL) { - FreePool (DevicePathString); return EFI_OUT_OF_RESOURCES; } - + + // + // Convert DevicePath + // ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; DevicePathString[Index] != L'\0'; Index ++) { - TemStr[0] = DevicePathString[Index]; + for (Index = 0; Index < Length; Index ++) { + TemStr[0] = PathHdr[Index]; DigitUint8 = (UINT8) StrHexToUint64 (TemStr); if ((Index & 1) == 0) { DevicePathBuffer [Index/2] = DigitUint8; @@ -132,20 +141,34 @@ GetDevicePath ( DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8); } } - - FreePool (DevicePathString); - *DevicePath = DevicePathBuffer; + // + // Validate DevicePath + // + DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DevicePathBuffer; + while (!IsDevicePathEnd (DevicePath)) { + if ((DevicePath->Type == 0) || (DevicePath->SubType == 0) || (DevicePathNodeLength (DevicePath) < sizeof (EFI_DEVICE_PATH_PROTOCOL))) { + // + // Invalid device path + // + FreePool (DevicePathBuffer); + return EFI_NOT_FOUND; + } + DevicePath = NextDevicePathNode (DevicePath); + } + // + // return the device path + // + *DevicePathData = DevicePathBuffer; return EFI_SUCCESS; - } /** Converts the unicode character of the string from uppercase to lowercase. This is a internal function. - @param Str String to be converted + @param ConfigString String to be converted **/ VOID @@ -430,8 +453,9 @@ GetValueOfNumber ( UINTN Index; CHAR16 TemStr[2]; - ASSERT (StringPtr != NULL && Number != NULL && Len != NULL); - ASSERT (*StringPtr != L'\0'); + if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) { + return EFI_INVALID_PARAMETER; + } Buf = NULL; @@ -577,6 +601,10 @@ MergeDefaultString ( SizeAltCfgResp + StrSize (StringPtrDefault), (VOID *) (*AltCfgResp) ); + if (*AltCfgResp == NULL) { + FreePool (AltConfigHdr); + return EFI_OUT_OF_RESOURCES; + } StrCat (*AltCfgResp, StringPtrDefault); break; } else { @@ -587,6 +615,10 @@ MergeDefaultString ( SizeAltCfgResp + StrSize (StringPtrDefault), (VOID *) (*AltCfgResp) ); + if (*AltCfgResp == NULL) { + FreePool (AltConfigHdr); + return EFI_OUT_OF_RESOURCES; + } StrCat (*AltCfgResp, StringPtrDefault); *StringPtrEnd = TempChar; } @@ -594,11 +626,12 @@ MergeDefaultString ( // // Find next AltCfg String - // + // *(AltConfigHdr + HeaderLength) = L'\0'; StringPtrDefault = StrStr (StringPtrDefault + 1, AltConfigHdr); } - + + FreePool (AltConfigHdr); return EFI_SUCCESS; } @@ -652,10 +685,17 @@ InsertDefaultValue ( for (Link = BlockData->DefaultValueEntry.ForwardLink; Link != &BlockData->DefaultValueEntry; Link = Link->ForwardLink) { DefaultValueArray = BASE_CR (Link, IFR_DEFAULT_DATA, Entry); if (DefaultValueArray->DefaultId == DefaultValueData->DefaultId) { - // - // Update the default value array in BlockData. - // - DefaultValueArray->Value = DefaultValueData->Value; + if (DefaultValueData->OpCode == EFI_IFR_DEFAULT_OP) { + // + // Update the default value array in BlockData. + // + DefaultValueArray->Value = DefaultValueData->Value; + } else if (DefaultValueArray->OpCode != EFI_IFR_DEFAULT_OP) { + // + // Update the default value array in BlockData. + // + DefaultValueArray->Value = DefaultValueData->Value; + } FreePool (DefaultValueData); return; } else if (DefaultValueArray->DefaultId > DefaultValueData->DefaultId) { @@ -734,7 +774,7 @@ InsertBlockData ( /** This function checks VarOffset and VarWidth is in the block range. - @param BlockArray The block array is to be checked. + @param RequestBlockArray The block array is to be checked. @param VarOffset Offset of var to the structure @param VarWidth Width of var. @@ -792,11 +832,11 @@ EFI_STATUS EFIAPI ParseIfrData ( IN UINT8 *Package, - IN UINT32 PackageLenth, + IN UINT32 PackageLength, IN EFI_STRING ConfigHdr, IN IFR_BLOCK_DATA *RequestBlockArray, IN OUT IFR_VARSTORAGE_DATA *VarStorageData, - OUT IFR_DEFAULT_DATA **PIfrDefaultIdArray + OUT IFR_DEFAULT_DATA *DefaultIdArray ) { EFI_STATUS Status; @@ -810,7 +850,6 @@ ParseIfrData ( EFI_IFR_CHECKBOX *IfrCheckBox; EFI_IFR_PASSWORD *IfrPassword; EFI_IFR_STRING *IfrString; - IFR_DEFAULT_DATA *DefaultIdArray; IFR_DEFAULT_DATA *DefaultData; IFR_BLOCK_DATA *BlockData; CHAR16 *VarStoreName; @@ -822,10 +861,8 @@ ParseIfrData ( EFI_STRING NameStr; EFI_STRING TempStr; UINTN LengthString; + BOOLEAN FirstOneOfOption; - // - // Initialize DefaultIdArray to store the map between DeaultId and DefaultName - // LengthString = 0; Status = EFI_SUCCESS; GuidStr = NULL; @@ -833,17 +870,14 @@ ParseIfrData ( TempStr = NULL; BlockData = NULL; DefaultData = NULL; - DefaultIdArray = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); - if (DefaultIdArray == NULL) { - return EFI_OUT_OF_RESOURCES; - } - InitializeListHead (&DefaultIdArray->Entry); + VarDefaultName = 0; + FirstOneOfOption = FALSE; // // Go through the form package to parse OpCode one by one. // IfrOffset = sizeof (EFI_HII_PACKAGE_HEADER); - while (IfrOffset < PackageLenth) { + while (IfrOffset < PackageLength) { IfrOpHdr = (EFI_IFR_OP_HEADER *) (Package + IfrOffset); switch (IfrOpHdr->OpCode) { @@ -920,6 +954,7 @@ ParseIfrData ( break; case EFI_IFR_FORM_OP: + case EFI_IFR_FORM_MAP_OP: // // No matched varstore is found and directly return. // @@ -935,6 +970,13 @@ ParseIfrData ( // Numeric and OneOf has the same opcode structure. // + // + // Numeric and OneOf question is not in IFR Form. This IFR form is not valid. + // + if (VarStorageData->Size == 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } // // Check whether this question is for the requested varstore. // @@ -984,6 +1026,59 @@ ParseIfrData ( // Add Block Data into VarStorageData BlockEntry // InsertBlockData (&VarStorageData->BlockEntry, &BlockData); + + if (IfrOpHdr->OpCode == EFI_IFR_ONE_OF_OP) { + // + // Set this flag to TRUE for the first oneof option. + // + FirstOneOfOption = TRUE; + } else if (IfrOpHdr->OpCode == EFI_IFR_NUMERIC_OP) { + // + // Numeric minimum value will be used as default value when no default is specified. + // + + // + // Set standard ID and Get DefaultName String ID + // + VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; + Status = FindDefaultName (DefaultIdArray, VarDefaultId, &VarDefaultName); + if (EFI_ERROR (Status)) { + goto Done; + } + // + // Prepare new DefaultValue + // + DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); + if (DefaultData == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + DefaultData->OpCode = IfrOpHdr->OpCode; + DefaultData->DefaultId = VarDefaultId; + DefaultData->DefaultName = VarDefaultName; + + switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + DefaultData->Value = (UINT64) IfrOneOf->data.u8.MinValue; + break; + + case EFI_IFR_NUMERIC_SIZE_2: + CopyMem (&DefaultData->Value, &IfrOneOf->data.u16.MinValue, sizeof (UINT16)); + break; + + case EFI_IFR_NUMERIC_SIZE_4: + CopyMem (&DefaultData->Value, &IfrOneOf->data.u32.MinValue, sizeof (UINT32)); + break; + + case EFI_IFR_NUMERIC_SIZE_8: + CopyMem (&DefaultData->Value, &IfrOneOf->data.u64.MinValue, sizeof (UINT64)); + break; + } + // + // Add DefaultValue into current BlockData + // + InsertDefaultValue (BlockData, DefaultData); + } break; case EFI_IFR_ORDERED_LIST_OP: @@ -992,38 +1087,28 @@ ParseIfrData ( // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type // no default value and default id, how to define its default value? // - + + // + // OrderedList question is not in IFR Form. This IFR form is not valid. + // + if (VarStorageData->Size == 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } // // Check whether this question is for the requested varstore. // IfrOrderedList = (EFI_IFR_ORDERED_LIST *) IfrOpHdr; if (IfrOrderedList->Question.VarStoreId != VarStorageData->VarStoreId) { + BlockData = NULL; break; } - + // // Get Offset/Width by Question header and OneOf Flags // VarOffset = IfrOrderedList->Question.VarStoreInfo.VarOffset; VarWidth = IfrOrderedList->MaxContainers; - - // - // Check whether this question is in requested block array. - // - if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth)) { - // - // This question is not in the requested string. Skip it. - // - break; - } - - // - // Check this var question is in the var storage - // - if ((VarOffset + VarWidth) > VarStorageData->Size) { - Status = EFI_INVALID_PARAMETER; - goto Done; - } // // Set Block Data @@ -1039,11 +1124,6 @@ ParseIfrData ( BlockData->OpCode = IfrOpHdr->OpCode; BlockData->Scope = IfrOpHdr->Scope; InitializeListHead (&BlockData->DefaultValueEntry); - - // - // Add Block Data into VarStorageData BlockEntry - // - InsertBlockData (&VarStorageData->BlockEntry, &BlockData); break; case EFI_IFR_CHECKBOX_OP: @@ -1056,6 +1136,13 @@ ParseIfrData ( // default id by DeaultOption DefaultId can override CheckBox Flags and Default value. // + // + // CheckBox question is not in IFR Form. This IFR form is not valid. + // + if (VarStorageData->Size == 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } // // Check whether this question is for the requested varstore. // @@ -1068,7 +1155,7 @@ ParseIfrData ( // Get Offset/Width by Question header and OneOf Flags // VarOffset = IfrCheckBox->Question.VarStoreInfo.VarOffset; - VarWidth = sizeof (BOOLEAN); + VarWidth = (UINT16) sizeof (BOOLEAN); // // Check whether this question is in requested block array. @@ -1127,6 +1214,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = 1; @@ -1153,6 +1241,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = 1; @@ -1170,6 +1259,13 @@ ParseIfrData ( // no default value, only block array // + // + // String question is not in IFR Form. This IFR form is not valid. + // + if (VarStorageData->Size == 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } // // Check whether this question is for the requested varstore. // @@ -1234,6 +1330,13 @@ ParseIfrData ( // no default value, only block array // + // + // Password question is not in IFR Form. This IFR form is not valid. + // + if (VarStorageData->Size == 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } // // Check whether this question is for the requested varstore. // @@ -1317,17 +1420,51 @@ ParseIfrData ( // Invalid ordered list option data type. // Status = EFI_INVALID_PARAMETER; + FreePool (BlockData); goto Done; } + // // Calculate Ordered list QuestionId width. // BlockData->Width = (UINT16) (BlockData->Width * VarWidth); + // + // Check whether this question is in requested block array. + // + if (!BlockArrayCheck (RequestBlockArray, BlockData->Offset, BlockData->Width)) { + // + // This question is not in the requested string. Skip it. + // + FreePool (BlockData); + BlockData = NULL; + break; + } + // + // Check this var question is in the var storage + // + if ((BlockData->Offset + BlockData->Width) > VarStorageData->Size) { + Status = EFI_INVALID_PARAMETER; + FreePool (BlockData); + goto Done; + } + // + // Add Block Data into VarStorageData BlockEntry + // + InsertBlockData (&VarStorageData->BlockEntry, &BlockData); + // + // No default data for OrderedList. + // BlockData = NULL; break; } - if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) { + if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) || + (BlockData->OpCode == EFI_IFR_ONE_OF_OP && FirstOneOfOption)) { + // + // This flag is used to specify whether this option is the first. Set it to FALSE for the following options. + // The first oneof option value will be used as default value when no default value is specified. + // + FirstOneOfOption = FALSE; // // Set standard ID to Manufacture ID and Get DefaultName String ID // @@ -1344,6 +1481,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = IfrOneOfOption->Value.u64; @@ -1370,6 +1508,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = IfrOneOfOption->Value.u64; @@ -1414,6 +1553,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = IfrDefault->Value.u64; @@ -1424,7 +1564,7 @@ ParseIfrData ( break; case EFI_IFR_END_OP: // - // End Opcode is for Var. + // End Opcode is for Var question. // if (BlockData != NULL && BlockData->Scope > 0) { BlockData->Scope--; @@ -1441,11 +1581,6 @@ ParseIfrData ( } Done: - // - // Set the defualt ID array. - // - *PIfrDefaultIdArray = DefaultIdArray; - return Status; } @@ -1456,7 +1591,7 @@ Done: When Request points to NULL string, the request string and default value string for each varstore in form package will return. - @param HiiHandle Hii Handle which Hii Packages are registered. + @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package. @param DevicePath Device Path which Hii Config Access Protocol is registered. @param Request Pointer to a null-terminated Unicode string in format. When it doesn't contain @@ -1474,36 +1609,44 @@ Done: When Request points to NULL, the default value string for each varstore in form package will be merged into a format string and return. + @param PointerProgress Optional parameter, it can be be NULL. + When it is not NULL, if Request is NULL, it returns NULL. + On return, points to a character in the Request + string. Points to the string's null terminator if + request was successful. Points to the most recent + & before the first failing name / value pair (or + the beginning of the string if the failure is in + the first name / value pair) if the request was + not successful. @retval EFI_SUCCESS The Results string is set to the full request string. And AltCfgResp contains all default value string. @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string. @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string can't be found in Form package. @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle. - @retval EFI_INVALID_PARAMETER *Request points to NULL. + @retval EFI_INVALID_PARAMETER Request points to NULL. **/ EFI_STATUS EFIAPI GetFullStringFromHiiFormPackages ( - IN EFI_HII_HANDLE HiiHandle, + IN HII_DATABASE_RECORD *DataBaseRecord, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN OUT EFI_STRING *Request, - IN OUT EFI_STRING *AltCfgResp + IN OUT EFI_STRING *AltCfgResp, + OUT EFI_STRING *PointerProgress OPTIONAL ) { EFI_STATUS Status; - EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - UINT32 PackageListLength; - UINTN BufferSize; + UINT8 *HiiFormPackage; + UINTN PackageSize; + UINTN ResultSize; IFR_BLOCK_DATA *RequestBlockArray; IFR_BLOCK_DATA *BlockData; IFR_BLOCK_DATA *NextBlockData; IFR_DEFAULT_DATA *DefaultValueData; IFR_DEFAULT_DATA *DefaultId; IFR_DEFAULT_DATA *DefaultIdArray; - EFI_HII_PACKAGE_HEADER PacakgeHeader; - UINT32 PackageOffset; IFR_VARSTORAGE_DATA *VarStorageData; EFI_STRING DefaultAltCfgResp; EFI_STRING FullConfigRequest; @@ -1512,6 +1655,7 @@ GetFullStringFromHiiFormPackages ( EFI_STRING NameStr; EFI_STRING PathStr; EFI_STRING StringPtr; + EFI_STRING Progress; UINTN Length; UINT8 *TmpBuffer; UINT16 Offset; @@ -1519,72 +1663,116 @@ GetFullStringFromHiiFormPackages ( LIST_ENTRY *Link; LIST_ENTRY *LinkData; LIST_ENTRY *LinkDefault; + BOOLEAN DataExist; + + if (DataBaseRecord == NULL || DevicePath == NULL || Request == NULL || AltCfgResp == NULL) { + return EFI_INVALID_PARAMETER; + } // // Initialize the local variables. // RequestBlockArray = NULL; + DefaultIdArray = NULL; VarStorageData = NULL; DefaultAltCfgResp = NULL; FullConfigRequest = NULL; ConfigHdr = NULL; - DefaultIdArray = NULL; GuidStr = NULL; NameStr = NULL; PathStr = NULL; - - // - // 1. Get HiiPackage by HiiHandle - // - BufferSize = 0; - HiiPackageList = NULL; - Status = HiiExportPackageLists (&mPrivate.HiiDatabase, HiiHandle, &BufferSize, HiiPackageList); - - // - // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0. - // - if (Status != EFI_BUFFER_TOO_SMALL) { + HiiFormPackage = NULL; + ResultSize = 0; + PackageSize = 0; + DataExist = FALSE; + Progress = *Request; + + // + // 0. Get Hii Form Package by HiiHandle + // + Status = ExportFormPackages ( + &mPrivate, + DataBaseRecord->Handle, + DataBaseRecord->PackageList, + 0, + PackageSize, + HiiFormPackage, + &ResultSize + ); + if (EFI_ERROR (Status)) { return Status; } - - HiiPackageList = AllocatePool (BufferSize); - if (HiiPackageList == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Get PackageList on HiiHandle - // - Status = HiiExportPackageLists (&mPrivate.HiiDatabase, HiiHandle, &BufferSize, HiiPackageList); - if (EFI_ERROR (Status)) { + + HiiFormPackage = AllocatePool (ResultSize); + if (HiiFormPackage == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } // - // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray. - // 1) Request is NULL. - // 2) Request is not NULL. And it doesn't contain any BlockArray. - // 3) Request is not NULL. And it containts BlockArray. - // - + // Get HiiFormPackage by HiiHandle // - // Initialize VarStorageData to store the var store Block and Default value information. - // - VarStorageData = (IFR_VARSTORAGE_DATA *) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA)); - if (VarStorageData == NULL) { - Status = EFI_OUT_OF_RESOURCES; + PackageSize = ResultSize; + ResultSize = 0; + Status = ExportFormPackages ( + &mPrivate, + DataBaseRecord->Handle, + DataBaseRecord->PackageList, + 0, + PackageSize, + HiiFormPackage, + &ResultSize + ); + if (EFI_ERROR (Status)) { goto Done; } - InitializeListHead (&VarStorageData->Entry); - InitializeListHead (&VarStorageData->BlockEntry); - // - // Gte the request block array by Request String + // 1. Get the request block array by Request String when Request string containts the block array. // StringPtr = NULL; if (*Request != NULL) { - StringPtr = StrStr (*Request, L"&OFFSET="); + StringPtr = *Request; + // + // Jump + // + if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"GUID="); + 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="); + 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="); + while (*StringPtr != L'\0' && *StringPtr != L'&') { + StringPtr ++; + } + // + // Check the following string &OFFSET= + // + if (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) != 0) { + Progress = StringPtr; + Status = EFI_INVALID_PARAMETER; + goto Done; + } else if (*StringPtr == L'\0') { + // + // No request block is found. + // + StringPtr = NULL; + } } if (StringPtr != NULL) { // @@ -1610,7 +1798,8 @@ GetFullStringFromHiiFormPackages ( while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) { // // Skip the OFFSET string - // + // + Progress = StringPtr; StringPtr += StrLen (L"&OFFSET="); // // Get Offset @@ -1666,7 +1855,28 @@ GetFullStringFromHiiFormPackages ( BlockData->Offset = Offset; BlockData->Width = Width; InsertBlockData (&RequestBlockArray->Entry, &BlockData); + + // + // Skip &VALUE string if &VALUE does exists. + // + if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) == 0) { + StringPtr += StrLen (L"&VALUE="); + + // + // Get Value + // + Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += Length; + if (*StringPtr != 0 && *StringPtr != L'&') { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + } // // If '\0', parsing is finished. // @@ -1695,45 +1905,43 @@ GetFullStringFromHiiFormPackages ( } // - // Get the form package + // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray. // - PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); - PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength); - while (PackageOffset < PackageListLength) { - CopyMem (&PacakgeHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PacakgeHeader)); - - if (PacakgeHeader.Type == EFI_HII_PACKAGE_FORMS) { - // - // Reset VarStorageData - // - VarStorageData->Size = 0; - VarStorageData->VarStoreId = 0; - if (VarStorageData->Name != NULL) { - FreePool (VarStorageData->Name); - VarStorageData->Name = NULL; - } - // - // Parse the opcode in form package - // - Status = ParseIfrData ((UINT8 *) HiiPackageList + PackageOffset, PacakgeHeader.Length, *Request, RequestBlockArray, VarStorageData, &DefaultIdArray); - if (EFI_ERROR (Status)) { - goto Done; - } + // + // Initialize DefaultIdArray to store the map between DeaultId and DefaultName + // + DefaultIdArray = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); + if (DefaultIdArray == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + InitializeListHead (&DefaultIdArray->Entry); - // - // Only one form is in a pacakge list. - // - break; - } + // + // Initialize VarStorageData to store the var store Block and Default value information. + // + VarStorageData = (IFR_VARSTORAGE_DATA *) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA)); + if (VarStorageData == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + InitializeListHead (&VarStorageData->Entry); + InitializeListHead (&VarStorageData->BlockEntry); - PackageOffset += PacakgeHeader.Length; + // + // Parse the opcode in form pacakge to get the default setting. + // + Status = ParseIfrData (HiiFormPackage, (UINT32) PackageSize, *Request, RequestBlockArray, VarStorageData, DefaultIdArray); + if (EFI_ERROR (Status)) { + goto Done; } // // No requested varstore in IFR data and directly return // if (VarStorageData->Size == 0) { + Status = EFI_SUCCESS; goto Done; } @@ -1785,7 +1993,8 @@ GetFullStringFromHiiFormPackages ( // Compute the length of the entire request starting with and a // Null-terminator // - Length = StrLen (ConfigHdr) + 1; + DataExist = FALSE; + Length = StrLen (ConfigHdr) + 1; for (Link = VarStorageData->BlockEntry.ForwardLink; Link != &VarStorageData->BlockEntry; Link = Link->ForwardLink) { // @@ -1794,14 +2003,24 @@ GetFullStringFromHiiFormPackages ( // ::= &OFFSET=1234&WIDTH=1234 // | 8 | 4 | 7 | 4 | // + DataExist = TRUE; Length = Length + (8 + 4 + 7 + 4); } + // + // No any request block data is found. The request string can't be constructed. + // + if (!DataExist) { + Status = EFI_SUCCESS; + goto Done; + } + // // Allocate buffer for the entire // FullConfigRequest = AllocateZeroPool (Length * sizeof (CHAR16)); if (FullConfigRequest == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } StringPtr = FullConfigRequest; @@ -1844,7 +2063,7 @@ GetFullStringFromHiiFormPackages ( // Go through all VarStorageData Entry and get the DefaultId array for each one // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody // - + DataExist = FALSE; // // Add length for + '\0' // @@ -1867,17 +2086,27 @@ GetFullStringFromHiiFormPackages ( // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz" // | 8 | 4 | 7 | 4 | 7 | Width * 2 | // - Length += (8 + 4 + 7 + 4 + 7 + BlockData->Width * 2); + Length += (8 + 4 + 7 + 4 + 7 + BlockData->Width * 2); + DataExist = TRUE; } } } } + + // + // No default value is found. The default string doesn't exist. + // + if (!DataExist) { + Status = EFI_SUCCESS; + goto Done; + } // // Allocate buffer for the entire // DefaultAltCfgResp = AllocateZeroPool (Length * sizeof (CHAR16)); if (DefaultAltCfgResp == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } StringPtr = DefaultAltCfgResp; @@ -1939,11 +2168,11 @@ GetFullStringFromHiiFormPackages ( // // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL. // - if (*AltCfgResp != NULL) { + if (*AltCfgResp != NULL && DefaultAltCfgResp != NULL) { Status = MergeDefaultString (AltCfgResp, DefaultAltCfgResp); FreePool (DefaultAltCfgResp); - } else { - *AltCfgResp = DefaultAltCfgResp; + } else if (*AltCfgResp == NULL) { + *AltCfgResp = DefaultAltCfgResp; } Done: @@ -2011,8 +2240,18 @@ Done: // // Free Pacakge data // - if (HiiPackageList != NULL) { - FreePool (HiiPackageList); + if (HiiFormPackage != NULL) { + FreePool (HiiFormPackage); + } + + if (PointerProgress != NULL) { + if (*Request == NULL) { + *PointerProgress = NULL; + } else if (EFI_ERROR (Status)) { + *PointerProgress = Progress; + } else { + *PointerProgress = *Request + StrLen (*Request); + } } return Status; @@ -2084,7 +2323,7 @@ HiiConfigRoutingExtractConfig ( EFI_STRING AccessResults; EFI_STRING DefaultResults; BOOLEAN FirstElement; - UINTN DevicePathLength; + BOOLEAN IfrDataParsedFlag; if (This == NULL || Progress == NULL || Results == NULL) { return EFI_INVALID_PARAMETER; @@ -2103,6 +2342,7 @@ HiiConfigRoutingExtractConfig ( Status = EFI_SUCCESS; AccessResults = NULL; DevicePath = NULL; + IfrDataParsedFlag = FALSE; // // The first element of should be @@ -2158,21 +2398,19 @@ HiiConfigRoutingExtractConfig ( // DriverHandle = NULL; HiiHandle = NULL; - DevicePathLength = GetDevicePathSize (DevicePath); + Database = NULL; for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink ) { Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE); - if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) { CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER); - if ((DevicePathLength == GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath)) && - (CompareMem ( + if (CompareMem ( DevicePath, CurrentDevicePath, - DevicePathLength - ) == 0)) { + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath) + ) == 0) { DriverHandle = Database->DriverHandle; HiiHandle = Database->Handle; break; @@ -2204,12 +2442,19 @@ HiiConfigRoutingExtractConfig ( // // Check whether ConfigRequest contains request string OFFSET/WIDTH // + IfrDataParsedFlag = FALSE; if ((HiiHandle != NULL) && (StrStr (ConfigRequest, L"&OFFSET=") == NULL)) { // // Get the full request string from IFR when HiiPackage is registered to HiiHandle // - Status = GetFullStringFromHiiFormPackages (HiiHandle, DevicePath, &ConfigRequest, &DefaultResults); + IfrDataParsedFlag = TRUE; + Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, &AccessProgress); if (EFI_ERROR (Status)) { + // + // AccessProgress indicates the parsing progress on . + // Map it to the progress on then return it. + // + *Progress = StrStr (StringPtr, AccessProgress); goto Done; } // @@ -2255,28 +2500,21 @@ HiiConfigRoutingExtractConfig ( // // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle // - if (HiiHandle != NULL) { - if (DefaultResults == NULL) { - Status = GetFullStringFromHiiFormPackages (HiiHandle, DevicePath, &ConfigRequest, &AccessResults); - } else { - Status = MergeDefaultString (&AccessResults, DefaultResults); - } + if (!IfrDataParsedFlag && HiiHandle != NULL) { + Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, NULL); + ASSERT_EFI_ERROR (Status); } + FreePool (DevicePath); DevicePath = NULL; - - if (EFI_ERROR (Status)) { - goto Done; - } - // - // Free the allocated memory. - // if (DefaultResults != NULL) { + Status = MergeDefaultString (&AccessResults, DefaultResults); + ASSERT_EFI_ERROR (Status); FreePool (DefaultResults); DefaultResults = NULL; } - + NextConfigString: if (!FirstElement) { Status = AppendToMultiString (Results, L"&"); @@ -2308,7 +2546,7 @@ NextConfigString: Done: if (EFI_ERROR (Status)) { FreePool (*Results); - *Results = NULL; + *Results = NULL; } if (ConfigRequest != NULL) { @@ -2364,6 +2602,7 @@ HiiConfigRoutingExportConfig ( EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; EFI_STRING AccessResults; EFI_STRING Progress; + EFI_STRING StringPtr; EFI_STRING ConfigRequest; UINTN Index; EFI_HANDLE *ConfigAccessHandles; @@ -2377,7 +2616,7 @@ HiiConfigRoutingExportConfig ( HII_DATABASE_RECORD *Database; UINT8 *DevicePathPkg; UINT8 *CurrentDevicePath; - UINTN DevicePathLength; + BOOLEAN IfrDataParsedFlag; if (This == NULL || Results == NULL) { return EFI_INVALID_PARAMETER; @@ -2421,12 +2660,13 @@ HiiConfigRoutingExportConfig ( // // Get DevicePath and HiiHandle for this ConfigAccess driver handle // + IfrDataParsedFlag = FALSE; Progress = NULL; HiiHandle = NULL; - ConfigRequest = NULL; DefaultResults = NULL; + Database = NULL; + ConfigRequest = NULL; DevicePath = DevicePathFromHandle (ConfigAccessHandles[Index]); - DevicePathLength = GetDevicePathSize (DevicePath); if (DevicePath != NULL) { for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; @@ -2435,12 +2675,11 @@ HiiConfigRoutingExportConfig ( Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE); if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) { CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER); - if ((DevicePathLength == GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath)) && - (CompareMem ( + if (CompareMem ( DevicePath, CurrentDevicePath, - DevicePathLength - ) == 0)) { + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath) + ) == 0) { HiiHandle = Database->Handle; break; } @@ -2448,33 +2687,61 @@ HiiConfigRoutingExportConfig ( } } - // - // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle - // - if (HiiHandle != NULL && DevicePath != NULL) { - Status = GetFullStringFromHiiFormPackages (HiiHandle, DevicePath, &ConfigRequest, &DefaultResults); - } - // - // Can't parse IFR data to get the request string and default string. - // - if (EFI_ERROR (Status)) { - ConfigRequest = NULL; - DefaultResults = NULL; - } - Status = ConfigAccess->ExtractConfig ( ConfigAccess, - ConfigRequest, + NULL, &Progress, &AccessResults ); + if (EFI_ERROR (Status)) { + // + // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle + // + if (HiiHandle != NULL && DevicePath != NULL) { + IfrDataParsedFlag = TRUE; + Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, NULL); + // + // Get the full request string to get the Current setting again. + // + if (!EFI_ERROR (Status) && ConfigRequest != NULL) { + Status = ConfigAccess->ExtractConfig ( + ConfigAccess, + ConfigRequest, + &Progress, + &AccessResults + ); + FreePool (ConfigRequest); + } else { + Status = EFI_NOT_FOUND; + } + } + } + if (!EFI_ERROR (Status)) { + // + // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle + // + if (!IfrDataParsedFlag && HiiHandle != NULL && DevicePath != NULL) { + StringPtr = StrStr (AccessResults, L"&GUID="); + if (StringPtr != NULL) { + *StringPtr = 0; + } + if (StrStr (AccessResults, L"&OFFSET=") != NULL) { + Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &AccessResults, &DefaultResults, NULL); + ASSERT_EFI_ERROR (Status); + } + if (StringPtr != NULL) { + *StringPtr = L'&'; + } + } // // Merge the default sting from IFR code into the got setting from driver. // if (DefaultResults != NULL) { - MergeDefaultString (&AccessResults, DefaultResults); + Status = MergeDefaultString (&AccessResults, DefaultResults); + ASSERT_EFI_ERROR (Status); FreePool (DefaultResults); + DefaultResults = NULL; } // @@ -2548,7 +2815,6 @@ HiiConfigRoutingRouteConfig ( EFI_HANDLE DriverHandle; EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; EFI_STRING AccessProgress; - UINTN DevicePathLength; if (This == NULL || Progress == NULL) { return EFI_INVALID_PARAMETER; @@ -2608,7 +2874,6 @@ HiiConfigRoutingRouteConfig ( // Find driver which matches the routing data. // DriverHandle = NULL; - DevicePathLength = GetDevicePathSize (DevicePath); for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink @@ -2617,12 +2882,11 @@ HiiConfigRoutingRouteConfig ( if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) { CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER); - if ((DevicePathLength == GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath)) && - (CompareMem ( + if (CompareMem ( DevicePath, CurrentDevicePath, - DevicePathLength - ) == 0)) { + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath) + ) == 0) { DriverHandle = Database->DriverHandle; break; } @@ -2840,7 +3104,7 @@ HiiBlockToConfig ( // Get Offset // Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (Status == EFI_OUT_OF_RESOURCES) { + if (EFI_ERROR (Status)) { *Progress = ConfigRequest; goto Exit; } @@ -2864,7 +3128,7 @@ HiiBlockToConfig ( // Get Width // Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (Status == EFI_OUT_OF_RESOURCES) { + if (EFI_ERROR (Status)) { *Progress = ConfigRequest; goto Exit; } @@ -2990,7 +3254,7 @@ Exit: @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL instance. @param ConfigResp A null-terminated Unicode string in - format. It can be ConfigAltResp format string. + format. @param Block A possibly null array of bytes representing the current block. Only bytes referenced in the ConfigResp string in the block are modified. If @@ -3022,6 +3286,10 @@ Exit: value pair. Block is left updated and Progress points at the '&' preceding the first non-. + @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined. + @retval EFI_NOT_FOUND Target for the specified routing data was not found. + Progress points to the "G" in "GUID" of the errant + routing data. **/ EFI_STATUS @@ -3043,13 +3311,14 @@ HiiConfigToBlock ( UINTN Width; UINT8 *Value; UINTN BufferSize; + UINTN MaxBlockSize; if (This == NULL || BlockSize == NULL || Progress == NULL) { return EFI_INVALID_PARAMETER; } - if (ConfigResp == NULL || Block == NULL) { - *Progress = ConfigResp; + *Progress = ConfigResp; + if (ConfigResp == NULL) { return EFI_INVALID_PARAMETER; } @@ -3059,6 +3328,7 @@ HiiConfigToBlock ( StringPtr = ConfigResp; BufferSize = *BlockSize; Value = NULL; + MaxBlockSize = 0; // // Jump @@ -3125,7 +3395,7 @@ HiiConfigToBlock ( // Get Width // Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (Status == EFI_OUT_OF_RESOURCES) { + if (EFI_ERROR (Status)) { *Progress = ConfigResp; goto Exit; } @@ -3164,13 +3434,12 @@ HiiConfigToBlock ( // // Update the Block with configuration info // - - if (Offset + Width > BufferSize) { - return EFI_DEVICE_ERROR; + if ((Block != NULL) && (Offset + Width <= BufferSize)) { + CopyMem (Block + Offset, Value, Width); + } + if (Offset + Width > MaxBlockSize) { + MaxBlockSize = Offset + Width; } - - CopyMem (Block + Offset, Value, Width); - *BlockSize = Offset + Width - 1; FreePool (Value); Value = NULL; @@ -3194,7 +3463,21 @@ HiiConfigToBlock ( goto Exit; } - *Progress = StringPtr; + *Progress = StringPtr + StrLen (StringPtr); + *BlockSize = MaxBlockSize - 1; + + if (MaxBlockSize > BufferSize) { + *BlockSize = MaxBlockSize; + if (Block != NULL) { + return EFI_DEVICE_ERROR; + } + } + + if (Block == NULL) { + *Progress = ConfigResp; + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; Exit: @@ -3213,7 +3496,7 @@ Exit: @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL instance. @param Configuration A null-terminated Unicode string in - format. It is format. + format. @param Guid A pointer to the GUID value to search for in the routing portion of the ConfigResp string when retrieving the requested data. If Guid is NULL,