X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FConfigRouting.c;h=d5ef60b7f5ed3eb223d96c60123df4b3bb319351;hp=fe035969717bc10f337b873f180a2d3aa2ab79d1;hb=f324bf4dbeda4d64b769bd005331e8f9404b692d;hpb=1f1cb2f2166f48a63b54dfc40f43c1a998e00a37 diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c index fe03596971..d5ef60b7f5 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c @@ -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,13 +141,27 @@ 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; - } /** @@ -577,6 +600,10 @@ MergeDefaultString ( SizeAltCfgResp + StrSize (StringPtrDefault), (VOID *) (*AltCfgResp) ); + if (*AltCfgResp == NULL) { + FreePool (AltConfigHdr); + return EFI_OUT_OF_RESOURCES; + } StrCat (*AltCfgResp, StringPtrDefault); break; } else { @@ -587,6 +614,10 @@ MergeDefaultString ( SizeAltCfgResp + StrSize (StringPtrDefault), (VOID *) (*AltCfgResp) ); + if (*AltCfgResp == NULL) { + FreePool (AltConfigHdr); + return EFI_OUT_OF_RESOURCES; + } StrCat (*AltCfgResp, StringPtrDefault); *StringPtrEnd = TempChar; } @@ -594,11 +625,12 @@ MergeDefaultString ( // // Find next AltCfg String - // + // *(AltConfigHdr + HeaderLength) = L'\0'; StringPtrDefault = StrStr (StringPtrDefault + 1, AltConfigHdr); } - + + FreePool (AltConfigHdr); return EFI_SUCCESS; } @@ -652,10 +684,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) { @@ -796,7 +835,7 @@ ParseIfrData ( 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 +849,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; @@ -823,9 +861,6 @@ ParseIfrData ( EFI_STRING TempStr; UINTN LengthString; - // - // Initialize DefaultIdArray to store the map between DeaultId and DefaultName - // LengthString = 0; Status = EFI_SUCCESS; GuidStr = NULL; @@ -833,11 +868,6 @@ 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); // // Go through the form package to parse OpCode one by one. @@ -873,9 +903,9 @@ ParseIfrData ( LengthString = StrLen (GuidStr); LengthString = LengthString + StrLen (NameStr) + 1; TempStr = AllocateZeroPool (LengthString * sizeof (CHAR16)); - FreePool (GuidStr); - FreePool (NameStr); if (TempStr == NULL) { + FreePool (GuidStr); + FreePool (NameStr); FreePool (VarStoreName); Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -899,6 +929,8 @@ ParseIfrData ( // // Free alllocated temp string. // + FreePool (GuidStr); + FreePool (NameStr); FreePool (TempStr); break; @@ -933,6 +965,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. // @@ -990,7 +1029,14 @@ 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. // @@ -1054,6 +1100,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. // @@ -1125,6 +1178,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = 1; @@ -1151,6 +1205,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = 1; @@ -1168,6 +1223,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. // @@ -1232,6 +1294,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. // @@ -1342,6 +1411,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = IfrOneOfOption->Value.u64; @@ -1368,6 +1438,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = IfrOneOfOption->Value.u64; @@ -1412,6 +1483,7 @@ ParseIfrData ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + DefaultData->OpCode = IfrOpHdr->OpCode; DefaultData->DefaultId = VarDefaultId; DefaultData->DefaultName = VarDefaultName; DefaultData->Value = IfrDefault->Value.u64; @@ -1422,7 +1494,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--; @@ -1439,11 +1511,6 @@ ParseIfrData ( } Done: - // - // Set the defualt ID array. - // - *PIfrDefaultIdArray = DefaultIdArray; - return Status; } @@ -1454,7 +1521,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 @@ -1472,36 +1539,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; @@ -1510,6 +1585,7 @@ GetFullStringFromHiiFormPackages ( EFI_STRING NameStr; EFI_STRING PathStr; EFI_STRING StringPtr; + EFI_STRING Progress; UINTN Length; UINT8 *TmpBuffer; UINT16 Offset; @@ -1517,72 +1593,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) { // @@ -1608,7 +1728,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 @@ -1664,7 +1785,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. // @@ -1693,45 +1835,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; } @@ -1783,7 +1923,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) { // @@ -1792,14 +1933,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; @@ -1842,7 +1993,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' // @@ -1865,17 +2016,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; @@ -1937,11 +2098,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: @@ -2009,8 +2170,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; @@ -2082,7 +2253,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; @@ -2101,6 +2272,7 @@ HiiConfigRoutingExtractConfig ( Status = EFI_SUCCESS; AccessResults = NULL; DevicePath = NULL; + IfrDataParsedFlag = FALSE; // // The first element of should be @@ -2156,21 +2328,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; @@ -2202,12 +2372,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; } // @@ -2253,28 +2430,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"&"); @@ -2306,7 +2476,7 @@ NextConfigString: Done: if (EFI_ERROR (Status)) { FreePool (*Results); - *Results = NULL; + *Results = NULL; } if (ConfigRequest != NULL) { @@ -2362,6 +2532,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; @@ -2375,7 +2546,7 @@ HiiConfigRoutingExportConfig ( HII_DATABASE_RECORD *Database; UINT8 *DevicePathPkg; UINT8 *CurrentDevicePath; - UINTN DevicePathLength; + BOOLEAN IfrDataParsedFlag; if (This == NULL || Results == NULL) { return EFI_INVALID_PARAMETER; @@ -2419,12 +2590,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; @@ -2433,12 +2605,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; } @@ -2446,33 +2617,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; } // @@ -2546,7 +2745,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; @@ -2606,7 +2804,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 @@ -2615,12 +2812,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; } @@ -3192,7 +3388,7 @@ HiiConfigToBlock ( goto Exit; } - *Progress = StringPtr; + *Progress = StringPtr + StrLen (StringPtr); return EFI_SUCCESS; Exit: