X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FSetupBrowserDxe%2FSetup.c;h=d046472701dfd7f3d4be02c9009ba696dec74a1c;hb=e3917e22e769898bb0d08d0112e768437f1ff9fb;hp=ba72d1220b594cb1857ed9bba97eee0ee1079a52;hpb=5a9f73bf065eda6b830445dc907e778f4a13d8d7;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index ba72d1220b..d046472701 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c @@ -1,14 +1,9 @@ /** @file Entry and initialization module for the browser. -Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
-This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+(C) Copyright 2020 Hewlett Packard Enterprise Development LP
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -28,12 +23,15 @@ SETUP_DRIVER_PRIVATE_DATA mPrivateData = { SaveReminder }, { - BROWSER_EXTENSION2_VERSION_1, + BROWSER_EXTENSION2_VERSION_1_1, SetScope, RegisterHotKey, RegiserExitHandler, IsBrowserDataModified, ExecuteAction, + {NULL,NULL}, + {NULL,NULL}, + IsResetRequired } }; @@ -47,12 +45,18 @@ LIST_ENTRY gBrowserContextList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserCon LIST_ENTRY gBrowserFormSetList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserFormSetList); LIST_ENTRY gBrowserHotKeyList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserHotKeyList); LIST_ENTRY gBrowserStorageList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserStorageList); +LIST_ENTRY gBrowserSaveFailFormSetList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserSaveFailFormSetList); -BOOLEAN gResetRequired; +BOOLEAN mSystemSubmit = FALSE; +BOOLEAN gResetRequiredFormLevel; +BOOLEAN gResetRequiredSystemLevel = FALSE; BOOLEAN gExitRequired; +BOOLEAN gFlagReconnect; +BOOLEAN gCallbackReconnect; BROWSER_SETTING_SCOPE gBrowserSettingScope = FormSetLevel; BOOLEAN mBrowserScopeFirstSet = TRUE; EXIT_HANDLER ExitHandlerFunction = NULL; +FORM_BROWSER_FORMSET *mSystemLevelFormSet; // // Browser Global Strings @@ -60,14 +64,11 @@ EXIT_HANDLER ExitHandlerFunction = NULL; CHAR16 *gEmptyString; CHAR16 *mUnknownString = L"!"; -EFI_GUID gZeroGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}}; - -extern UINT32 gBrowserStatus; -extern CHAR16 *gErrorInfo; extern EFI_GUID mCurrentFormSetGuid; extern EFI_HII_HANDLE mCurrentHiiHandle; extern UINT16 mCurrentFormId; extern FORM_DISPLAY_ENGINE_FORM gDisplayFormData; +extern BOOLEAN mDynamicFormUpdated; /** Create a menu with specified formset GUID and form ID, and add it as a child @@ -147,7 +148,7 @@ GetFirstFormId ( **/ FORM_ENTRY_INFO * UiFindMenuList ( - IN EFI_HII_HANDLE HiiHandle, + IN EFI_HII_HANDLE HiiHandle, IN EFI_GUID *FormSetGuid, IN UINT16 FormId ) @@ -163,7 +164,7 @@ UiFindMenuList ( while (!IsNull (&mPrivateData.FormBrowserEx2.FormViewHistoryHead, Link)) { MenuList = FORM_ENTRY_INFO_FROM_LINK (Link); Link = GetNextNode (&mPrivateData.FormBrowserEx2.FormViewHistoryHead, Link); - + // // If already find the menu, free the menus behind it. // @@ -177,7 +178,7 @@ UiFindMenuList ( // Find the same FromSet. // if (MenuList->HiiHandle == HiiHandle) { - if (CompareGuid (&MenuList->FormSetGuid, &gZeroGuid)) { + if (IsZeroGuid (&MenuList->FormSetGuid)) { // // FormSetGuid is not specified. // @@ -202,19 +203,56 @@ UiFindMenuList ( Find parent menu for current menu. @param CurrentMenu Current Menu + @param SettingLevel Whether find parent menu in Form Level or Formset level. + In form level, just find the parent menu; + In formset level, find the parent menu which has different + formset guid value. @retval The parent menu for current menu. **/ FORM_ENTRY_INFO * UiFindParentMenu ( - IN FORM_ENTRY_INFO *CurrentMenu + IN FORM_ENTRY_INFO *CurrentMenu, + IN BROWSER_SETTING_SCOPE SettingLevel ) { FORM_ENTRY_INFO *ParentMenu; + LIST_ENTRY *Link; + + ASSERT (SettingLevel == FormLevel || SettingLevel == FormSetLevel); + + if (CurrentMenu == NULL) { + return NULL; + } ParentMenu = NULL; - if (CurrentMenu->Link.BackLink != &mPrivateData.FormBrowserEx2.FormViewHistoryHead) { - ParentMenu = FORM_ENTRY_INFO_FROM_LINK (CurrentMenu->Link.BackLink); + Link = &CurrentMenu->Link; + + while (Link->BackLink != &mPrivateData.FormBrowserEx2.FormViewHistoryHead) { + ParentMenu = FORM_ENTRY_INFO_FROM_LINK (Link->BackLink); + + if (SettingLevel == FormLevel) { + // + // For FormLevel, just find the parent menu, return. + // + break; + } + + if (!CompareGuid (&CurrentMenu->FormSetGuid, &ParentMenu->FormSetGuid)) { + // + // For SystemLevel, must find the menu which has different formset. + // + break; + } + + Link = Link->BackLink; + } + + // + // Not find the parent menu, just return NULL. + // + if (Link->BackLink == &mPrivateData.FormBrowserEx2.FormViewHistoryHead) { + return NULL; } return ParentMenu; @@ -241,6 +279,45 @@ UiFreeMenuList ( } } +/** + Copy current Menu list to the new menu list. + + @param NewMenuListHead New create Menu list. + @param CurrentMenuListHead Current Menu list. + +**/ +VOID +UiCopyMenuList ( + OUT LIST_ENTRY *NewMenuListHead, + IN LIST_ENTRY *CurrentMenuListHead + ) +{ + LIST_ENTRY *Link; + FORM_ENTRY_INFO *MenuList; + FORM_ENTRY_INFO *NewMenuEntry; + + // + // If new menu list not empty, free it first. + // + UiFreeMenuList (NewMenuListHead); + + Link = GetFirstNode (CurrentMenuListHead); + while (!IsNull (CurrentMenuListHead, Link)) { + MenuList = FORM_ENTRY_INFO_FROM_LINK (Link); + Link = GetNextNode (CurrentMenuListHead, Link); + + NewMenuEntry = AllocateZeroPool (sizeof (FORM_ENTRY_INFO)); + ASSERT (NewMenuEntry != NULL); + NewMenuEntry->Signature = FORM_ENTRY_INFO_SIGNATURE; + NewMenuEntry->HiiHandle = MenuList->HiiHandle; + CopyMem (&NewMenuEntry->FormSetGuid, &MenuList->FormSetGuid, sizeof (EFI_GUID)); + NewMenuEntry->FormId = MenuList->FormId; + NewMenuEntry->QuestionId = MenuList->QuestionId; + + InsertTailList (NewMenuListHead, &NewMenuEntry->Link); + } +} + /** Load all hii formset to the browser. @@ -255,6 +332,9 @@ LoadAllHiiFormset ( UINTN Index; EFI_GUID ZeroGuid; EFI_STATUS Status; + FORM_BROWSER_FORMSET *OldFormset; + + OldFormset = mSystemLevelFormSet; // // Get all the Hii handles @@ -278,6 +358,8 @@ LoadAllHiiFormset ( // LocalFormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET)); ASSERT (LocalFormSet != NULL); + mSystemLevelFormSet = LocalFormSet; + ZeroMem (&ZeroGuid, sizeof (ZeroGuid)); Status = InitializeFormSet (HiiHandles[Index], &ZeroGuid, LocalFormSet); if (EFI_ERROR (Status) || IsListEmpty (&LocalFormSet->FormListHead)) { @@ -300,6 +382,60 @@ LoadAllHiiFormset ( // Free resources, and restore gOldFormSet and gClassOfVfr // FreePool (HiiHandles); + + mSystemLevelFormSet = OldFormset; +} + +/** + Pop up the error info. + + @param BrowserStatus The input browser status. + @param HiiHandle The Hiihandle for this opcode. + @param OpCode The opcode use to get the erro info and timeout value. + @param ErrorString Error string used by BROWSER_NO_SUBMIT_IF. + +**/ +UINT32 +PopupErrorMessage ( + IN UINT32 BrowserStatus, + IN EFI_HII_HANDLE HiiHandle, + IN EFI_IFR_OP_HEADER *OpCode OPTIONAL, + IN CHAR16 *ErrorString + ) +{ + FORM_DISPLAY_ENGINE_STATEMENT *Statement; + USER_INPUT UserInputData; + + Statement = NULL; + + if (OpCode != NULL) { + Statement = AllocateZeroPool (sizeof(FORM_DISPLAY_ENGINE_STATEMENT)); + ASSERT (Statement != NULL); + Statement->OpCode = OpCode; + gDisplayFormData.HighLightedStatement = Statement; + } + + // + // Used to compatible with old display engine. + // New display engine not use this field. + // + gDisplayFormData.ErrorString = ErrorString; + gDisplayFormData.BrowserStatus = BrowserStatus; + + if (HiiHandle != NULL) { + gDisplayFormData.HiiHandle = HiiHandle; + } + + mFormDisplay->FormDisplay (&gDisplayFormData, &UserInputData); + + gDisplayFormData.BrowserStatus = BROWSER_SUCCESS; + gDisplayFormData.ErrorString = NULL; + + if (OpCode != NULL) { + FreePool (Statement); + } + + return UserInputData.Action; } /** @@ -333,9 +469,9 @@ SendForm ( IN CONST EFI_FORM_BROWSER2_PROTOCOL *This, IN EFI_HII_HANDLE *Handles, IN UINTN HandleCount, - IN EFI_GUID *FormSetGuid, OPTIONAL - IN UINT16 FormId, OPTIONAL - IN CONST EFI_SCREEN_DESCRIPTOR *ScreenDimensions, OPTIONAL + IN EFI_GUID *FormSetGuid OPTIONAL, + IN UINT16 FormId OPTIONAL, + IN CONST EFI_SCREEN_DESCRIPTOR *ScreenDimensions OPTIONAL, OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest OPTIONAL ) { @@ -344,11 +480,13 @@ SendForm ( UINTN Index; FORM_BROWSER_FORMSET *FormSet; FORM_ENTRY_INFO *MenuList; + BOOLEAN RetVal; // // If EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found, return EFI_UNSUPPORTED. // if (mFormDisplay == NULL) { + DEBUG ((DEBUG_ERROR, "Fatal Error! EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found!")); return EFI_UNSUPPORTED; } @@ -357,8 +495,10 @@ SendForm ( // SaveBrowserContext (); - gResetRequired = FALSE; + gFlagReconnect = FALSE; + gResetRequiredFormLevel = FALSE; gExitRequired = FALSE; + gCallbackReconnect = FALSE; Status = EFI_SUCCESS; gEmptyString = L""; gDisplayFormData.ScreenDimensions = (EFI_SCREEN_DESCRIPTOR *) ScreenDimensions; @@ -379,6 +519,14 @@ SendForm ( FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET)); ASSERT (FormSet != NULL); + // + // Validate the HiiHandle + // if validate failed, find the first validate parent HiiHandle. + // + if (!ValidateHiiHandle(Selection->Handle)) { + FindNextMenu (Selection, FormSetLevel); + } + // // Initialize internal data structures of FormSet // @@ -388,6 +536,8 @@ SendForm ( break; } Selection->FormSet = FormSet; + mSystemLevelFormSet = FormSet; + mDynamicFormUpdated = FALSE; // // Display this formset @@ -397,11 +547,25 @@ SendForm ( Status = SetupBrowser (Selection); gCurrentSelection = NULL; + mSystemLevelFormSet = NULL; + + // + // If callback update form dynamically, it's not exiting of the formset for user so system do not reconnect driver hanlde + // this time. + // + if (!mDynamicFormUpdated && (gFlagReconnect || gCallbackReconnect)) { + RetVal = ReconnectController (FormSet->DriverHandle); + if (!RetVal) { + PopupErrorMessage(BROWSER_RECONNECT_FAIL, NULL, NULL, NULL); + } + gFlagReconnect = FALSE; + gCallbackReconnect = FALSE; + } // // If no data is changed, don't need to save current FormSet into the maintain list. // - if (!IsNvUpdateRequiredForFormSet (FormSet) && !IsStorageDataChangedForFormSet(FormSet)) { + if (!IsNvUpdateRequiredForFormSet (FormSet)) { CleanBrowserStorage(FormSet); RemoveEntryList (&FormSet->Link); DestroyFormSet (FormSet); @@ -415,22 +579,9 @@ SendForm ( FreePool (Selection); } - // - // Still has error info, pop up a message. - // - if (gBrowserStatus != BROWSER_SUCCESS) { - gDisplayFormData.BrowserStatus = gBrowserStatus; - gDisplayFormData.ErrorString = gErrorInfo; - - gBrowserStatus = BROWSER_SUCCESS; - gErrorInfo = NULL; - - mFormDisplay->FormDisplay (&gDisplayFormData, NULL); - } - if (ActionRequest != NULL) { *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; - if (gResetRequired) { + if (gResetRequiredFormLevel) { *ActionRequest = EFI_BROWSER_ACTION_REQUEST_RESET; } } @@ -472,7 +623,7 @@ SendForm ( distribution. **/ -EFI_STATUS +EFI_STATUS ProcessStorage ( IN OUT UINTN *ResultsDataSize, IN OUT EFI_STRING *ResultsData, @@ -485,6 +636,8 @@ ProcessStorage ( CHAR16 *StrPtr; UINTN BufferSize; UINTN TmpSize; + UINTN MaxLen; + FORMSET_STORAGE *BrowserStorage; if (RetrieveData) { // @@ -499,15 +652,17 @@ ProcessStorage ( // Skip and '&' to point to when first copy the configbody. // Also need to consider add "\0" at first time. // - StrPtr = ConfigResp + StrLen (Storage->ConfigHdr) + 1; + StrPtr = StrStr (ConfigResp, L"PATH"); + ASSERT (StrPtr != NULL); + StrPtr = StrStr (StrPtr, L"&"); + StrPtr += 1; BufferSize = StrSize (StrPtr); - // // Copy the data if the input buffer is bigger enough. // if (*ResultsDataSize >= BufferSize) { - StrCpy (*ResultsData, StrPtr); + StrCpyS (*ResultsData, *ResultsDataSize / sizeof (CHAR16), StrPtr); } *ResultsDataSize = BufferSize; @@ -516,14 +671,17 @@ ProcessStorage ( // // Prepare // + BrowserStorage = GetFstStgFromBrsStg (Storage); + ASSERT (BrowserStorage != NULL); TmpSize = StrLen (*ResultsData); - BufferSize = (TmpSize + StrLen (Storage->ConfigHdr) + 2) * sizeof (CHAR16); + BufferSize = (TmpSize + StrLen (BrowserStorage->ConfigHdr) + 2) * sizeof (CHAR16); + MaxLen = BufferSize / sizeof (CHAR16); ConfigResp = AllocateZeroPool (BufferSize); ASSERT (ConfigResp != NULL); - StrCpy (ConfigResp, Storage->ConfigHdr); - StrCat (ConfigResp, L"&"); - StrCat (ConfigResp, *ResultsData); + StrCpyS (ConfigResp, MaxLen, BrowserStorage->ConfigHdr); + StrCatS (ConfigResp, MaxLen, L"&"); + StrCatS (ConfigResp, MaxLen, *ResultsData); // // Update Browser uncommited data @@ -539,8 +697,8 @@ ProcessStorage ( } /** - This routine called this service in the browser to retrieve or set certain uncommitted - state information that resides in the open formsets. + This routine called this service in the browser to retrieve or set certain uncommitted + state information that resides in the open formsets. @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL instance. @@ -572,7 +730,7 @@ BrowserCallback ( IN OUT UINTN *ResultsDataSize, IN OUT EFI_STRING ResultsData, IN BOOLEAN RetrieveData, - IN CONST EFI_GUID *VariableGuid, OPTIONAL + IN CONST EFI_GUID *VariableGuid OPTIONAL, IN CONST CHAR16 *VariableName OPTIONAL ) { @@ -580,7 +738,6 @@ BrowserCallback ( LIST_ENTRY *Link; BROWSER_STORAGE *Storage; FORMSET_STORAGE *FormsetStorage; - FORM_BROWSER_FORMSET *FormSet; UINTN TotalSize; BOOLEAN Found; @@ -593,14 +750,6 @@ BrowserCallback ( Found = FALSE; Status = EFI_SUCCESS; - // - // If set browser data, pre load all hii formset to avoid set the varstore which is not - // saved in browser. - // - if (!RetrieveData && (gBrowserSettingScope == SystemLevel)) { - LoadAllHiiFormset(); - } - if (VariableGuid != NULL) { // // Try to find target storage in the current formset. @@ -630,15 +779,30 @@ BrowserCallback ( } } + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE || + Storage->Type == EFI_HII_VARSTORE_BUFFER) { + if (mSystemLevelFormSet == NULL || mSystemLevelFormSet->HiiHandle == NULL) { + return EFI_NOT_FOUND; + } + + if (Storage->HiiHandle != mSystemLevelFormSet->HiiHandle) { + continue; + } + } + Status = ProcessStorage (&TotalSize, &ResultsData, RetrieveData, Storage); if (EFI_ERROR (Status)) { return Status; } + if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { + ConfigRequestAdjust (Storage, ResultsData, TRUE); + } + // // Different formsets may have same varstore, so here just set the flag // not exit the circle. - // + // Found = TRUE; break; } @@ -650,21 +814,20 @@ BrowserCallback ( // // GUID/Name is not specified, take the first storage in FormSet // - if (gCurrentSelection == NULL) { + if (mSystemLevelFormSet == NULL) { return EFI_NOT_READY; } // // Generate // - FormSet = gCurrentSelection->FormSet; - Link = GetFirstNode (&FormSet->StorageListHead); - if (IsNull (&FormSet->StorageListHead, Link)) { + Link = GetFirstNode (&mSystemLevelFormSet->StorageListHead); + if (IsNull (&mSystemLevelFormSet->StorageListHead, Link)) { return EFI_UNSUPPORTED; } FormsetStorage = FORMSET_STORAGE_FROM_LINK (Link); - + Status = ProcessStorage (&TotalSize, &ResultsData, RetrieveData, FormsetStorage->BrowserStorage); if (EFI_ERROR (Status)) { return Status; @@ -675,7 +838,7 @@ BrowserCallback ( Status = TotalSize <= *ResultsDataSize ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; *ResultsDataSize = TotalSize; } - + return Status; } @@ -695,13 +858,11 @@ FormDisplayCallback ( IN VOID *Context ) { - EFI_STATUS Status; - if (mFormDisplay != NULL) { return; } - Status = gBS->LocateProtocol ( + gBS->LocateProtocol ( &gEdkiiFormDisplayEngineProtocolGuid, NULL, (VOID **) &mFormDisplay @@ -766,7 +927,8 @@ InitializeSetup ( // // Install FormBrowserEx2 protocol // - InitializeListHead (&mPrivateData.FormBrowserEx2.FormViewHistoryHead); + InitializeListHead (&mPrivateData.FormBrowserEx2.FormViewHistoryHead); + InitializeListHead (&mPrivateData.FormBrowserEx2.OverrideQestListHead); mPrivateData.Handle = NULL; Status = gBS->InstallProtocolInterface ( &mPrivateData.Handle, @@ -775,10 +937,10 @@ InitializeSetup ( &mPrivateData.FormBrowserEx2 ); ASSERT_EFI_ERROR (Status); - + Status = gBS->InstallProtocolInterface ( &mPrivateData.Handle, - &gEfiFormBrowserExProtocolGuid, + &gEdkiiFormBrowserExProtocolGuid, EFI_NATIVE_INTERFACE, &mPrivateData.FormBrowserEx ); @@ -801,7 +963,7 @@ InitializeSetup ( &Registration ); } - + return EFI_SUCCESS; } @@ -920,19 +1082,19 @@ NewStringCat ( ) { CHAR16 *NewString; - UINTN TmpSize; + UINTN MaxLen; if (*Dest == NULL) { NewStringCpy (Dest, Src); return; } - TmpSize = StrSize (*Dest); - NewString = AllocateZeroPool (TmpSize + StrSize (Src) - 1); + MaxLen = ( StrSize (*Dest) + StrSize (Src) - 1) / sizeof (CHAR16); + NewString = AllocateZeroPool (MaxLen * sizeof (CHAR16)); ASSERT (NewString != NULL); - StrCpy (NewString, *Dest); - StrCat (NewString, Src); + StrCpyS (NewString, MaxLen, *Dest); + StrCatS (NewString, MaxLen, Src); FreePool (*Dest); *Dest = NewString; @@ -1077,6 +1239,7 @@ StorageToConfigResp ( LIST_ENTRY *Link; NAME_VALUE_NODE *Node; UINT8 *SourceBuf; + FORMSET_STORAGE *FormsetStorage; Status = EFI_SUCCESS; @@ -1096,7 +1259,9 @@ StorageToConfigResp ( case EFI_HII_VARSTORE_NAME_VALUE: *ConfigResp = NULL; - NewStringCat (ConfigResp, Storage->ConfigHdr); + FormsetStorage = GetFstStgFromBrsStg(Storage); + ASSERT (FormsetStorage != NULL); + NewStringCat (ConfigResp, FormsetStorage->ConfigHdr); Link = GetFirstNode (&Storage->NameValueListHead); while (!IsNull (&Storage->NameValueListHead, Link)) { @@ -1204,6 +1369,195 @@ ConfigRespToStorage ( return Status; } +/** + Get bit field value from the buffer and then set the value for the question. + Note: Data type UINT32 can cover all the bit field value. + + @param Question The question refer to bit field. + @param Buffer Point to the buffer which the question value get from. + +**/ +VOID +GetBitsQuestionValue ( + IN FORM_BROWSER_STATEMENT *Question, + IN UINT8 *Buffer + ) +{ + UINTN StartBit; + UINTN EndBit; + UINT32 RetVal; + UINT32 BufferValue; + + StartBit = Question->BitVarOffset % 8; + EndBit = StartBit + Question->BitStorageWidth - 1; + + CopyMem ((UINT8 *) &BufferValue, Buffer, Question->StorageWidth); + + RetVal = BitFieldRead32 (BufferValue, StartBit, EndBit); + + // + // Set question value. + // Note: Since Question with BufferValue (orderedlist, password, string)are not supported to refer bit field. + // Only oneof/checkbox/oneof can support bit field.So we can copy the value to the Hiivalue of Question directly. + // + CopyMem ((UINT8 *) &Question->HiiValue.Value, (UINT8 *) &RetVal, Question->StorageWidth); +} + +/** + Set bit field value to the buffer. + Note: Data type UINT32 can cover all the bit field value. + + @param Question The question refer to bit field. + @param Buffer Point to the buffer which the question value set to. + @param Value The bit field value need to set. + +**/ +VOID +SetBitsQuestionValue ( + IN FORM_BROWSER_STATEMENT *Question, + IN OUT UINT8 *Buffer, + IN UINT32 Value + ) +{ + UINT32 Operand; + UINTN StartBit; + UINTN EndBit; + UINT32 RetVal; + + StartBit = Question->BitVarOffset % 8; + EndBit = StartBit + Question->BitStorageWidth - 1; + + CopyMem ((UINT8*) &Operand, Buffer, Question->StorageWidth); + + RetVal = BitFieldWrite32 (Operand, StartBit, EndBit, Value); + + CopyMem (Buffer, (UINT8*) &RetVal, Question->StorageWidth); +} + +/** + Convert the buffer value to HiiValue. + + @param Question The question. + @param Value Unicode buffer save the question value. + + @retval Status whether convert the value success. + +**/ +EFI_STATUS +BufferToValue ( + IN OUT FORM_BROWSER_STATEMENT *Question, + IN CHAR16 *Value + ) +{ + CHAR16 *StringPtr; + BOOLEAN IsBufferStorage; + CHAR16 *DstBuf; + CHAR16 TempChar; + UINTN LengthStr; + UINT8 *Dst; + CHAR16 TemStr[5]; + UINTN Index; + UINT8 DigitUint8; + BOOLEAN IsString; + UINTN Length; + EFI_STATUS Status; + UINT8 *Buffer; + + Buffer = NULL; + + IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE); + if (Question->Storage->Type == EFI_HII_VARSTORE_BUFFER || + Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { + IsBufferStorage = TRUE; + } else { + IsBufferStorage = FALSE; + } + + // + // Question Value is provided by Buffer Storage or NameValue Storage + // + if (Question->BufferValue != NULL) { + // + // This Question is password or orderedlist + // + Dst = Question->BufferValue; + } else { + // + // Other type of Questions + // + if (Question->QuestionReferToBitField) { + Buffer = (UINT8 *)AllocateZeroPool (Question->StorageWidth); + if (Buffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Dst = Buffer; + } else { + Dst = (UINT8 *) &Question->HiiValue.Value; + } + } + + // + // Temp cut at the end of this section, end with '\0' or '&'. + // + StringPtr = Value; + while (*StringPtr != L'\0' && *StringPtr != L'&') { + StringPtr++; + } + TempChar = *StringPtr; + *StringPtr = L'\0'; + + LengthStr = StrLen (Value); + + // + // Value points to a Unicode hexadecimal string, we need to convert the string to the value with CHAR16/UINT8...type. + // When generating the Value string, we follow this rule: 1 byte -> 2 Unicode characters (for string: 2 byte(CHAR16) ->4 Unicode characters). + // So the maximum value string length of a question is : Question->StorageWidth * 2. + // If the value string length > Question->StorageWidth * 2, only set the string length as Question->StorageWidth * 2, then convert. + // + if (LengthStr > (UINTN) Question->StorageWidth * 2) { + Length = (UINTN) Question->StorageWidth * 2; + } else { + Length = LengthStr; + } + + Status = EFI_SUCCESS; + if (!IsBufferStorage && IsString) { + // + // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD" + // Add string tail char L'\0' into Length + // + DstBuf = (CHAR16 *) Dst; + ZeroMem (TemStr, sizeof (TemStr)); + for (Index = 0; Index < Length; Index += 4) { + StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value + Index, 4); + DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr); + } + // + // Add tailing L'\0' character + // + DstBuf[Index/4] = L'\0'; + } else { + ZeroMem (TemStr, sizeof (TemStr)); + for (Index = 0; Index < Length; Index ++) { + TemStr[0] = Value[LengthStr - Index - 1]; + DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + if ((Index & 1) == 0) { + Dst [Index/2] = DigitUint8; + } else { + Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]); + } + } + } + + *StringPtr = TempChar; + + if (Buffer != NULL && Question->QuestionReferToBitField) { + GetBitsQuestionValue (Question, Buffer); + FreePool (Buffer); + } + + return Status; +} /** Get Question's current Value. @@ -1231,20 +1585,15 @@ GetQuestionValue ( UINTN StorageWidth; EFI_TIME EfiTime; BROWSER_STORAGE *Storage; + FORMSET_STORAGE *FormsetStorage; EFI_IFR_TYPE_VALUE *QuestionValue; CHAR16 *ConfigRequest; CHAR16 *Progress; CHAR16 *Result; CHAR16 *Value; - CHAR16 *StringPtr; UINTN Length; - UINTN Index; - UINTN LengthStr; BOOLEAN IsBufferStorage; - BOOLEAN IsString; - CHAR16 TemStr[5]; - UINT8 DigitUint8; - UINT8 *TemBuffer; + UINTN MaxLen; Status = EFI_SUCCESS; Value = NULL; @@ -1254,13 +1603,6 @@ GetQuestionValue ( return EFI_INVALID_PARAMETER; } - // - // Statement don't have storage, skip them - // - if (Question->QuestionId == 0) { - return Status; - } - // // Question value is provided by an Expression, evaluate it // @@ -1279,17 +1621,17 @@ GetQuestionValue ( FreePool (Question->ValueExpression->Result.Buffer); } Question->HiiValue.Type = Question->ValueExpression->Result.Type; - CopyMem (&Question->HiiValue.Value, &Question->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); + CopyMem (&Question->HiiValue.Value, &Question->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); } return Status; } - + // // Get question value by read expression. // if (Question->ReadExpression != NULL && Form->FormType == STANDARD_MAP_FORM_TYPE) { Status = EvaluateExpression (FormSet, Form, Question->ReadExpression); - if (!EFI_ERROR (Status) && + if (!EFI_ERROR (Status) && ((Question->ReadExpression->Result.Type < EFI_IFR_TYPE_OTHER) || (Question->ReadExpression->Result.Type == EFI_IFR_TYPE_BUFFER))) { // // Only update question value to the valid result. @@ -1306,7 +1648,7 @@ GetQuestionValue ( FreePool (Question->ReadExpression->Result.Buffer); } Question->HiiValue.Type = Question->ReadExpression->Result.Type; - CopyMem (&Question->HiiValue.Value, &Question->ReadExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); + CopyMem (&Question->HiiValue.Value, &Question->ReadExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); return EFI_SUCCESS; } } @@ -1342,7 +1684,16 @@ GetQuestionValue ( } if (EFI_ERROR (Status)) { - return Status; + if (Question->Operand == EFI_IFR_DATE_OP){ + QuestionValue->date.Year = 0xff; + QuestionValue->date.Month = 0xff; + QuestionValue->date.Day = 0xff; + } else { + QuestionValue->time.Hour = 0xff; + QuestionValue->time.Minute = 0xff; + QuestionValue->time.Second = 0xff; + } + return EFI_SUCCESS; } if (Question->Operand == EFI_IFR_DATE_OP) { @@ -1398,25 +1749,34 @@ GetQuestionValue ( Dst = (UINT8 *) &Question->HiiValue.Value; } - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || + if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { IsBufferStorage = TRUE; } else { IsBufferStorage = FALSE; } - IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE); if (GetValueFrom == GetSetValueWithEditBuffer || GetValueFrom == GetSetValueWithBuffer ) { if (IsBufferStorage) { if (GetValueFrom == GetSetValueWithEditBuffer) { // // Copy from storage Edit buffer + // If the Question refer to bit filed, get the value in the related bit filed. // - CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth); + if (Question->QuestionReferToBitField) { + GetBitsQuestionValue (Question, Storage->EditBuffer + Question->VarStoreInfo.VarOffset); + } else { + CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth); + } } else { // // Copy from storage Edit buffer + // If the Question refer to bit filed, get the value in the related bit filed. // - CopyMem (Dst, Storage->Buffer + Question->VarStoreInfo.VarOffset, StorageWidth); + if (Question->QuestionReferToBitField) { + GetBitsQuestionValue (Question, Storage->Buffer + Question->VarStoreInfo.VarOffset); + } else { + CopyMem (Dst, Storage->Buffer + Question->VarStoreInfo.VarOffset, StorageWidth); + } } } else { Value = NULL; @@ -1426,189 +1786,79 @@ GetQuestionValue ( } ASSERT (Value != NULL); - LengthStr = StrLen (Value); - Status = EFI_SUCCESS; - if (IsString) { - // - // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD" - // Add string tail char L'\0' into Length - // - Length = StorageWidth + sizeof (CHAR16); - if (Length < ((LengthStr / 4 + 1) * 2)) { - Status = EFI_BUFFER_TOO_SMALL; - } else { - StringPtr = (CHAR16 *) Dst; - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index += 4) { - StrnCpy (TemStr, Value + Index, 4); - StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr); - } - // - // Add tailing L'\0' character - // - StringPtr[Index/4] = L'\0'; - } - } else { - if (StorageWidth < ((LengthStr + 1) / 2)) { - Status = EFI_BUFFER_TOO_SMALL; - } else { - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index ++) { - TemStr[0] = Value[LengthStr - Index - 1]; - DigitUint8 = (UINT8) StrHexToUint64 (TemStr); - if ((Index & 1) == 0) { - Dst [Index/2] = DigitUint8; - } else { - Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]); - } - } - } - } - + Status = BufferToValue (Question, Value); FreePool (Value); } } else { - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { - // - // Request current settings from Configuration Driver - // - if (FormSet->ConfigAccess == NULL) { - return EFI_NOT_FOUND; - } - - // - // ::= + || - // + "&" + - // - if (IsBufferStorage) { - Length = StrLen (Storage->ConfigHdr); - Length += StrLen (Question->BlockName); - } else { - Length = StrLen (Storage->ConfigHdr); - Length += StrLen (Question->VariableName) + 1; - } - ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); - ASSERT (ConfigRequest != NULL); + FormsetStorage = GetFstStgFromVarId(FormSet, Question->VarStoreId); + ASSERT (FormsetStorage != NULL); + // + // ::= + || + // + "&" + + // + if (IsBufferStorage) { + Length = StrLen (FormsetStorage->ConfigHdr); + Length += StrLen (Question->BlockName); + } else { + Length = StrLen (FormsetStorage->ConfigHdr); + Length += StrLen (Question->VariableName) + 1; + } + // Allocate buffer include '\0' + MaxLen = Length + 1; + ConfigRequest = AllocateZeroPool (MaxLen * sizeof (CHAR16)); + ASSERT (ConfigRequest != NULL); - StrCpy (ConfigRequest, Storage->ConfigHdr); - if (IsBufferStorage) { - StrCat (ConfigRequest, Question->BlockName); - } else { - StrCat (ConfigRequest, L"&"); - StrCat (ConfigRequest, Question->VariableName); - } + StrCpyS (ConfigRequest, MaxLen, FormsetStorage->ConfigHdr); + if (IsBufferStorage) { + StrCatS (ConfigRequest, MaxLen, Question->BlockName); + } else { + StrCatS (ConfigRequest, MaxLen, L"&"); + StrCatS (ConfigRequest, MaxLen, Question->VariableName); + } - Status = FormSet->ConfigAccess->ExtractConfig ( - FormSet->ConfigAccess, - ConfigRequest, - &Progress, - &Result - ); - FreePool (ConfigRequest); - if (EFI_ERROR (Status)) { - return Status; - } + // + // Request current settings from Configuration Driver + // + Status = mHiiConfigRouting->ExtractConfig ( + mHiiConfigRouting, + ConfigRequest, + &Progress, + &Result + ); + FreePool (ConfigRequest); + if (EFI_ERROR (Status)) { + return Status; + } - // - // Skip - // - if (IsBufferStorage) { - Value = StrStr (Result, L"&VALUE"); - if (Value == NULL) { - FreePool (Result); - return EFI_NOT_FOUND; - } - // - // Skip "&VALUE" - // - Value = Value + 6; - } else { - Value = Result + Length; - } - if (*Value != '=') { + // + // Skip + // + if (IsBufferStorage) { + Value = StrStr (Result, L"&VALUE"); + if (Value == NULL) { FreePool (Result); return EFI_NOT_FOUND; } // - // Skip '=', point to value - // - Value = Value + 1; - - // - // Suppress if any + // Skip "&VALUE" // - StringPtr = Value; - while (*StringPtr != L'\0' && *StringPtr != L'&') { - StringPtr++; - } - *StringPtr = L'\0'; - - LengthStr = StrLen (Value); - Status = EFI_SUCCESS; - if (!IsBufferStorage && IsString) { - // - // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD" - // Add string tail char L'\0' into Length - // - Length = StorageWidth + sizeof (CHAR16); - if (Length < ((LengthStr / 4 + 1) * 2)) { - Status = EFI_BUFFER_TOO_SMALL; - } else { - StringPtr = (CHAR16 *) Dst; - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index += 4) { - StrnCpy (TemStr, Value + Index, 4); - StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr); - } - // - // Add tailing L'\0' character - // - StringPtr[Index/4] = L'\0'; - } - } else { - if (StorageWidth < ((LengthStr + 1) / 2)) { - Status = EFI_BUFFER_TOO_SMALL; - } else { - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index ++) { - TemStr[0] = Value[LengthStr - Index - 1]; - DigitUint8 = (UINT8) StrHexToUint64 (TemStr); - if ((Index & 1) == 0) { - Dst [Index/2] = DigitUint8; - } else { - Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]); - } - } - } - } - - if (EFI_ERROR (Status)) { - FreePool (Result); - return Status; - } - } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { - TemBuffer = NULL; - TemBuffer = AllocateZeroPool (Storage->Size); - if (TemBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - return Status; - } - Length = Storage->Size; - Status = gRT->GetVariable ( - Storage->Name, - &Storage->Guid, - NULL, - &Length, - TemBuffer - ); - if (EFI_ERROR (Status)) { - FreePool (TemBuffer); - return Status; - } - - CopyMem (Dst, TemBuffer + Question->VarStoreInfo.VarOffset, StorageWidth); + Value = Value + 6; + } else { + Value = Result + Length; + } + if (*Value != '=') { + FreePool (Result); + return EFI_NOT_FOUND; + } + // + // Skip '=', point to value + // + Value = Value + 1; - FreePool (TemBuffer); + Status = BufferToValue (Question, Value); + if (EFI_ERROR (Status)) { + FreePool (Result); + return Status; } // @@ -1656,6 +1906,7 @@ SetQuestionValue ( UINTN BufferLen; UINTN StorageWidth; BROWSER_STORAGE *Storage; + FORMSET_STORAGE *FormsetStorage; EFI_IFR_TYPE_VALUE *QuestionValue; CHAR16 *ConfigResp; CHAR16 *Progress; @@ -1668,6 +1919,7 @@ SetQuestionValue ( CHAR16 *TemString; UINTN Index; NAME_VALUE_NODE *Node; + UINTN MaxLen; Status = EFI_SUCCESS; Node = NULL; @@ -1676,20 +1928,13 @@ SetQuestionValue ( return EFI_INVALID_PARAMETER; } - // - // Statement don't have storage, skip them - // - if (Question->QuestionId == 0) { - return Status; - } - // // If Question value is provided by an Expression, then it is read only // if (Question->ValueExpression != NULL) { return Status; } - + // // Before set question value, evaluate its write expression. // @@ -1784,7 +2029,7 @@ SetQuestionValue ( Src = (UINT8 *) &Question->HiiValue.Value; } - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || + if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { IsBufferStorage = TRUE; } else { @@ -1797,21 +2042,23 @@ SetQuestionValue ( if (SetValueTo == GetSetValueWithEditBuffer) { // // Copy to storage edit buffer - // - CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); + // If the Question refer to bit filed, copy the value in related bit filed to storage edit buffer. + // + if (Question->QuestionReferToBitField) { + SetBitsQuestionValue (Question, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, (UINT32)(*Src)); + } else { + CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); + } } else if (SetValueTo == GetSetValueWithBuffer) { // - // Copy to storage edit buffer - // - CopyMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); - } - // - // Check whether question value has been changed. - // - if (CompareMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth) != 0) { - Question->ValueChanged = TRUE; - } else { - Question->ValueChanged = FALSE; + // Copy to storage buffer + // If the Question refer to bit filed, copy the value in related bit filed to storage buffer. + // + if (Question->QuestionReferToBitField) { + SetBitsQuestionValue (Question, Storage->Buffer + Question->VarStoreInfo.VarOffset, (UINT32)(*Src)); + } else { + CopyMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); + } } } else { if (IsString) { @@ -1828,7 +2075,14 @@ SetQuestionValue ( TemName = (CHAR16 *) Src; TemString = Value; for (; *TemName != L'\0'; TemName++) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4); + UnicodeValueToStringS ( + TemString, + BufferLen - ((UINTN)TemString - (UINTN)Value), + PREFIX_ZERO | RADIX_HEX, + *TemName, + 4 + ); + TemString += StrnLenS (TemString, (BufferLen - ((UINTN)TemString - (UINTN)Value)) / sizeof (CHAR16)); } } else { BufferLen = StorageWidth * 2 + 1; @@ -1840,7 +2094,14 @@ SetQuestionValue ( TemBuffer = Src + StorageWidth - 1; TemString = Value; for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2); + UnicodeValueToStringS ( + TemString, + BufferLen * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)Value), + PREFIX_ZERO | RADIX_HEX, + *TemBuffer, + 2 + ); + TemString += StrnLenS (TemString, BufferLen - ((UINTN)TemString - (UINTN)Value) / sizeof (CHAR16)); } } @@ -1849,121 +2110,97 @@ SetQuestionValue ( if (EFI_ERROR (Status)) { return Status; } - // - // Check whether question value has been changed. - // - if (StrCmp (Node->Value, Node->EditValue) != 0) { - Question->ValueChanged = TRUE; - } else { - Question->ValueChanged = FALSE; - } } } else if (SetValueTo == GetSetValueWithHiiDriver) { - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { - // - // ::= + + "&VALUE=" + "StorageWidth * 2" || - // + "&" + + "=" + "" - // - if (IsBufferStorage) { - Length = StrLen (Question->BlockName) + 7; - } else { - Length = StrLen (Question->VariableName) + 2; - } - if (!IsBufferStorage && IsString) { - Length += (StrLen ((CHAR16 *) Src) * 4); - } else { - Length += (StorageWidth * 2); - } - ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16)); - ASSERT (ConfigResp != NULL); - - StrCpy (ConfigResp, Storage->ConfigHdr); - if (IsBufferStorage) { - StrCat (ConfigResp, Question->BlockName); - StrCat (ConfigResp, L"&VALUE="); - } else { - StrCat (ConfigResp, L"&"); - StrCat (ConfigResp, Question->VariableName); - StrCat (ConfigResp, L"="); - } + // + // ::= + + "&VALUE=" + "StorageWidth * 2" || + // + "&" + + "=" + "" + // + if (IsBufferStorage) { + Length = StrLen (Question->BlockName) + 7; + } else { + Length = StrLen (Question->VariableName) + 2; + } + if (!IsBufferStorage && IsString) { + Length += (StrLen ((CHAR16 *) Src) * 4); + } else { + Length += (StorageWidth * 2); + } + FormsetStorage = GetFstStgFromVarId(FormSet, Question->VarStoreId); + ASSERT (FormsetStorage != NULL); + MaxLen = StrLen (FormsetStorage->ConfigHdr) + Length + 1; + ConfigResp = AllocateZeroPool (MaxLen * sizeof (CHAR16)); + ASSERT (ConfigResp != NULL); - Value = ConfigResp + StrLen (ConfigResp); + StrCpyS (ConfigResp, MaxLen, FormsetStorage->ConfigHdr); + if (IsBufferStorage) { + StrCatS (ConfigResp, MaxLen, Question->BlockName); + StrCatS (ConfigResp, MaxLen, L"&VALUE="); + } else { + StrCatS (ConfigResp, MaxLen, L"&"); + StrCatS (ConfigResp, MaxLen, Question->VariableName); + StrCatS (ConfigResp, MaxLen, L"="); + } - if (!IsBufferStorage && IsString) { - // - // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044" - // - TemName = (CHAR16 *) Src; - TemString = Value; - for (; *TemName != L'\0'; TemName++) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4); - } - } else { - // - // Convert Buffer to Hex String - // - TemBuffer = Src + StorageWidth - 1; - TemString = Value; - for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2); - } - } + Value = ConfigResp + StrLen (ConfigResp); + if (!IsBufferStorage && IsString) { // - // Convert to lower char. + // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044" // - for (TemString = Value; *Value != L'\0'; Value++) { - if (*Value >= L'A' && *Value <= L'Z') { - *Value = (CHAR16) (*Value - L'A' + L'a'); - } + TemName = (CHAR16 *) Src; + TemString = Value; + for (; *TemName != L'\0'; TemName++) { + UnicodeValueToStringS ( + TemString, + MaxLen * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)ConfigResp), + PREFIX_ZERO | RADIX_HEX, + *TemName, + 4 + ); + TemString += StrnLenS (TemString, MaxLen - ((UINTN)TemString - (UINTN)ConfigResp) / sizeof (CHAR16)); } - + } else { // - // Submit Question Value to Configuration Driver + // Convert Buffer to Hex String // - if (FormSet->ConfigAccess != NULL) { - Status = FormSet->ConfigAccess->RouteConfig ( - FormSet->ConfigAccess, - ConfigResp, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (ConfigResp); - return Status; - } - } - FreePool (ConfigResp); - - } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { - TemBuffer = NULL; - TemBuffer = AllocateZeroPool(Storage->Size); - if (TemBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - return Status; + TemBuffer = Src + StorageWidth - 1; + TemString = Value; + for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) { + UnicodeValueToStringS ( + TemString, + MaxLen * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)ConfigResp), + PREFIX_ZERO | RADIX_HEX, + *TemBuffer, + 2 + ); + TemString += StrnLenS (TemString, MaxLen - ((UINTN)TemString - (UINTN)ConfigResp) / sizeof (CHAR16)); } - Length = Storage->Size; - Status = gRT->GetVariable ( - Storage->Name, - &Storage->Guid, - NULL, - &Length, - TemBuffer - ); - - CopyMem (TemBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); - - Status = gRT->SetVariable ( - Storage->Name, - &Storage->Guid, - Storage->Attributes, - Storage->Size, - TemBuffer - ); - FreePool (TemBuffer); - if (EFI_ERROR (Status)){ - return Status; + } + + // + // Convert to lower char. + // + for (TemString = Value; *Value != L'\0'; Value++) { + if (*Value >= L'A' && *Value <= L'Z') { + *Value = (CHAR16) (*Value - L'A' + L'a'); } } + + // + // Submit Question Value to Configuration Driver + // + Status = mHiiConfigRouting->RouteConfig ( + mHiiConfigRouting, + ConfigResp, + &Progress + ); + if (EFI_ERROR (Status)) { + FreePool (ConfigResp); + return Status; + } + FreePool (ConfigResp); + // // Sync storage, from editbuffer to buffer. // @@ -1997,12 +2234,28 @@ ValidateQuestion ( EFI_STATUS Status; LIST_ENTRY *Link; LIST_ENTRY *ListHead; - EFI_STRING PopUp; FORM_EXPRESSION *Expression; + UINT32 BrowserStatus; + CHAR16 *ErrorStr; + + BrowserStatus = BROWSER_SUCCESS; + ErrorStr = NULL; + + switch (Type) { + case EFI_HII_EXPRESSION_INCONSISTENT_IF: + ListHead = &Question->InconsistentListHead; + break; + + case EFI_HII_EXPRESSION_WARNING_IF: + ListHead = &Question->WarningListHead; + break; - if (Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) { + case EFI_HII_EXPRESSION_NO_SUBMIT_IF: ListHead = &Question->NoSubmitListHead; - } else { + break; + + default: + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -2018,19 +2271,49 @@ ValidateQuestion ( return Status; } - if ((Expression->Result.Type == EFI_IFR_TYPE_BOOLEAN) && Expression->Result.Value.b) { - // - // Condition meet, show up error message - // - if (Expression->Error != 0) { - PopUp = GetToken (Expression->Error, FormSet->HiiHandle); - if (Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) { - gBrowserStatus = BROWSER_NO_SUBMIT_IF; - gErrorInfo = PopUp; + if (IsTrue (&Expression->Result)) { + switch (Type) { + case EFI_HII_EXPRESSION_INCONSISTENT_IF: + BrowserStatus = BROWSER_INCONSISTENT_IF; + break; + + case EFI_HII_EXPRESSION_WARNING_IF: + BrowserStatus = BROWSER_WARNING_IF; + break; + + case EFI_HII_EXPRESSION_NO_SUBMIT_IF: + BrowserStatus = BROWSER_NO_SUBMIT_IF; + // + // This code only used to compatible with old display engine, + // New display engine will not use this field. + // + if (Expression->Error != 0) { + ErrorStr = GetToken (Expression->Error, FormSet->HiiHandle); } + break; + + default: + ASSERT (FALSE); + break; } - return EFI_NOT_READY; + if (!((Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) && mSystemSubmit)) { + // + // If in system submit process and for no_submit_if check, not popup this error message. + // Will process this fail again later in not system submit process. + // + PopupErrorMessage(BrowserStatus, FormSet->HiiHandle, Expression->OpCode, ErrorStr); + } + + if (ErrorStr != NULL) { + FreePool (ErrorStr); + } + + if (Type == EFI_HII_EXPRESSION_WARNING_IF) { + return EFI_SUCCESS; + } else { + return EFI_NOT_READY; + } } Link = GetNextNode (ListHead, Link); @@ -2039,12 +2322,57 @@ ValidateQuestion ( return EFI_SUCCESS; } +/** + Perform question check. + + If one question has more than one check, process form high priority to low. + Only one error info will be popup. + + @param FormSet FormSet data structure. + @param Form Form data structure. + @param Question The Question to be validated. + + @retval EFI_SUCCESS Form validation pass. + @retval other Form validation failed. + +**/ +EFI_STATUS +ValueChangedValidation ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form, + IN FORM_BROWSER_STATEMENT *Question + ) +{ + EFI_STATUS Status; + + Status = EFI_SUCCESS; + + // + // Do the inconsistentif check. + // + if (!IsListEmpty (&Question->InconsistentListHead)) { + Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF); + if (EFI_ERROR (Status)) { + return Status; + } + } + + // + // Do the warningif check. + // + if (!IsListEmpty (&Question->WarningListHead)) { + Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_WARNING_IF); + } + + return Status; +} /** Perform NoSubmit check for each Form in FormSet. @param FormSet FormSet data structure. @param CurrentForm Current input form data structure. + @param Statement The statement for this check. @retval EFI_SUCCESS Form validation pass. @retval other Form validation failed. @@ -2052,8 +2380,9 @@ ValidateQuestion ( **/ EFI_STATUS NoSubmitCheck ( - IN FORM_BROWSER_FORMSET *FormSet, - IN FORM_BROWSER_FORM *CurrentForm + IN FORM_BROWSER_FORMSET *FormSet, + IN OUT FORM_BROWSER_FORM **CurrentForm, + OUT FORM_BROWSER_STATEMENT **Statement ) { EFI_STATUS Status; @@ -2067,16 +2396,21 @@ NoSubmitCheck ( Form = FORM_BROWSER_FORM_FROM_LINK (LinkForm); LinkForm = GetNextNode (&FormSet->FormListHead, LinkForm); - if (CurrentForm != NULL && CurrentForm != Form) { + if (*CurrentForm != NULL && *CurrentForm != Form) { continue; } Link = GetFirstNode (&Form->StatementListHead); while (!IsNull (&Form->StatementListHead, Link)) { Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); - Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_NO_SUBMIT_IF); if (EFI_ERROR (Status)) { + if (*CurrentForm == NULL) { + *CurrentForm = Form; + } + if (Statement != NULL) { + *Statement = Question; + } return Status; } @@ -2090,10 +2424,9 @@ NoSubmitCheck ( /** Fill storage's edit copy with settings requested from Configuration Driver. - @param FormSet FormSet data structure. @param Storage The storage which need to sync. @param ConfigRequest The config request string which used to sync storage. - @param SyncOrRestore Sync the buffer to editbuffer or Restore the + @param SyncOrRestore Sync the buffer to editbuffer or Restore the editbuffer to buffer if TRUE, copy the editbuffer to the buffer. if FALSE, copy the buffer to the editbuffer. @@ -2103,7 +2436,6 @@ NoSubmitCheck ( **/ EFI_STATUS SynchronizeStorage ( - IN FORM_BROWSER_FORMSET *FormSet, OUT BROWSER_STORAGE *Storage, IN CHAR16 *ConfigRequest, IN BOOLEAN SyncOrRestore @@ -2121,7 +2453,7 @@ SynchronizeStorage ( Status = EFI_SUCCESS; Result = NULL; - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || + if (Storage->Type == EFI_HII_VARSTORE_BUFFER || (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { BufferSize = Storage->Size; @@ -2199,6 +2531,10 @@ SendDiscardInfoToDriver ( EFI_IFR_TYPE_VALUE *TypeValue; EFI_BROWSER_ACTION_REQUEST ActionRequest; + if (FormSet->ConfigAccess == NULL) { + return; + } + Link = GetFirstNode (&Form->StatementListHead); while (!IsNull (&Form->StatementListHead, Link)) { Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); @@ -2208,6 +2544,10 @@ SendDiscardInfoToDriver ( continue; } + if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) { + continue; + } + if (Question->Operand == EFI_IFR_PASSWORD_OP) { continue; } @@ -2216,6 +2556,15 @@ SendDiscardInfoToDriver ( continue; } + // + // Restore the question value before call the CHANGED callback type. + // + GetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer); + + if (Question->Operand == EFI_IFR_STRING_OP){ + HiiSetString (FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL); + } + if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) { TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue; } else { @@ -2235,49 +2584,160 @@ SendDiscardInfoToDriver ( } /** - Validate the FormSet. If the formset is not validate, remove it from the list. - - @param FormSet The input FormSet which need to validate. + When submit the question value, call the callback function with Submitted type + to inform the hii driver. - @retval TRUE The handle is validate. - @retval FALSE The handle is invalidate. + @param FormSet FormSet data structure. + @param Form Form data structure. **/ -BOOLEAN -ValidateFormSet ( - FORM_BROWSER_FORMSET *FormSet +VOID +SubmitCallbackForForm ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form + ) +{ + LIST_ENTRY *Link; + FORM_BROWSER_STATEMENT *Question; + EFI_IFR_TYPE_VALUE *TypeValue; + EFI_BROWSER_ACTION_REQUEST ActionRequest; + + if (FormSet->ConfigAccess == NULL) { + return; + } + + Link = GetFirstNode (&Form->StatementListHead); + while (!IsNull (&Form->StatementListHead, Link)) { + Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); + Link = GetNextNode (&Form->StatementListHead, Link); + + if (Question->Storage == NULL || Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + continue; + } + + if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) { + continue; + } + + if (Question->Operand == EFI_IFR_PASSWORD_OP) { + continue; + } + + if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) { + TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue; + } else { + TypeValue = &Question->HiiValue.Value; + } + + ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; + FormSet->ConfigAccess->Callback ( + FormSet->ConfigAccess, + EFI_BROWSER_ACTION_SUBMITTED, + Question->QuestionId, + Question->HiiValue.Type, + TypeValue, + &ActionRequest + ); + } +} + +/** + When value set Success, call the submit callback function. + + @param FormSet FormSet data structure. + @param Form Form data structure. + +**/ +VOID +SubmitCallback ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form + ) +{ + FORM_BROWSER_FORM *CurrentForm; + LIST_ENTRY *Link; + + if (Form != NULL) { + SubmitCallbackForForm(FormSet, Form); + return; + } + + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + CurrentForm = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&FormSet->FormListHead, Link); + + SubmitCallbackForForm(FormSet, CurrentForm); + } +} + +/** + Validate the HiiHandle. + + @param HiiHandle The input HiiHandle which need to validate. + + @retval TRUE The handle is validate. + @retval FALSE The handle is invalidate. + +**/ +BOOLEAN +ValidateHiiHandle ( + EFI_HII_HANDLE HiiHandle ) { EFI_HII_HANDLE *HiiHandles; UINTN Index; BOOLEAN Find; - ASSERT (FormSet != NULL); + if (HiiHandle == NULL) { + return FALSE; + } + Find = FALSE; - // - // Get all the Hii handles - // + HiiHandles = HiiGetHiiHandles (NULL); ASSERT (HiiHandles != NULL); - // - // Search for formset of each class type - // for (Index = 0; HiiHandles[Index] != NULL; Index++) { - if (HiiHandles[Index] == FormSet->HiiHandle) { + if (HiiHandles[Index] == HiiHandle) { Find = TRUE; break; } } - if (!Find) { + FreePool (HiiHandles); + + return Find; +} + +/** + Validate the FormSet. If the formset is not validate, remove it from the list. + + @param FormSet The input FormSet which need to validate. + + @retval TRUE The handle is validate. + @retval FALSE The handle is invalidate. + +**/ +BOOLEAN +ValidateFormSet ( + FORM_BROWSER_FORMSET *FormSet + ) +{ + BOOLEAN Find; + + ASSERT (FormSet != NULL); + + Find = ValidateHiiHandle(FormSet->HiiHandle); + // + // Should not remove the formset which is being used. + // + if (!Find && (FormSet != gCurrentSelection->FormSet)) { CleanBrowserStorage(FormSet); RemoveEntryList (&FormSet->Link); DestroyFormSet (FormSet); } - FreePool (HiiHandles); - return Find; } /** @@ -2285,33 +2745,50 @@ ValidateFormSet ( Also clean all ValueChanged flag in question. @param SetFlag Whether need to set the Reset Flag. + @param FormSet FormSet data structure. @param Form Form data structure. **/ VOID UpdateFlagForForm ( IN BOOLEAN SetFlag, + IN FORM_BROWSER_FORMSET *FormSet, IN FORM_BROWSER_FORM *Form ) { LIST_ENTRY *Link; FORM_BROWSER_STATEMENT *Question; - BOOLEAN FindOne; + BOOLEAN OldValue; - FindOne = FALSE; Link = GetFirstNode (&Form->StatementListHead); while (!IsNull (&Form->StatementListHead, Link)) { Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); - - if (SetFlag && Question->ValueChanged && ((Question->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) != 0)) { - gResetRequired = TRUE; - } + Link = GetNextNode (&Form->StatementListHead, Link); - if (Question->ValueChanged) { - Question->ValueChanged = FALSE; + if (!Question->ValueChanged) { + continue; + } + + OldValue = Question->ValueChanged; + + // + // Compare the buffer and editbuffer data to see whether the data has been saved. + // + Question->ValueChanged = IsQuestionValueChanged(FormSet, Form, Question, GetSetValueWithBothBuffer); + + // + // Only the changed data has been saved, then need to set the reset flag. + // + if (SetFlag && OldValue && !Question->ValueChanged) { + if ((Question->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) != 0) { + gResetRequiredFormLevel = TRUE; + gResetRequiredSystemLevel = TRUE; + } + + if ((Question->QuestionFlags & EFI_IFR_FLAG_RECONNECT_REQUIRED) != 0) { + gFlagReconnect = TRUE; + } } - - Link = GetNextNode (&Form->StatementListHead, Link); } } @@ -2320,7 +2797,7 @@ UpdateFlagForForm ( Also clean ValueChanged flag for all statements. Form level or formset level, only one. - + @param SetFlag Whether need to set the Reset Flag. @param FormSet FormSet data structure. @param Form Form data structure. @@ -2330,17 +2807,14 @@ VOID ValueChangeResetFlagUpdate ( IN BOOLEAN SetFlag, IN FORM_BROWSER_FORMSET *FormSet, - IN FORM_BROWSER_FORM *Form + IN FORM_BROWSER_FORM *Form ) { FORM_BROWSER_FORM *CurrentForm; LIST_ENTRY *Link; - // - // Form != NULL means only check form level. - // if (Form != NULL) { - UpdateFlagForForm(SetFlag, Form); + UpdateFlagForForm(SetFlag, FormSet, Form); return; } @@ -2349,164 +2823,369 @@ ValueChangeResetFlagUpdate ( CurrentForm = FORM_BROWSER_FORM_FROM_LINK (Link); Link = GetNextNode (&FormSet->FormListHead, Link); - UpdateFlagForForm(SetFlag, CurrentForm); + UpdateFlagForForm(SetFlag, FormSet, CurrentForm); } } /** - Discard data based on the input setting scope (Form, FormSet or System). + Base on the return Progress string to find the form. + + Base on the first return Offset/Width (Name) string to find the form + which keep this string. @param FormSet FormSet data structure. - @param Form Form data structure. - @param SettingScope Setting Scope for Discard action. + @param Storage Storage which has this Progress string. + @param Progress The Progress string which has the first fail string. + @param RetForm The return form for this progress string. + @param RetQuestion The return question for the error progress string. - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_UNSUPPORTED Unsupport SettingScope. + @retval TRUE Find the error form and statement for this error progress string. + @retval FALSE Not find the error form. **/ -EFI_STATUS -DiscardForm ( +BOOLEAN +FindQuestionFromProgress ( IN FORM_BROWSER_FORMSET *FormSet, - IN FORM_BROWSER_FORM *Form, - IN BROWSER_SETTING_SCOPE SettingScope + IN BROWSER_STORAGE *Storage, + IN EFI_STRING Progress, + OUT FORM_BROWSER_FORM **RetForm, + OUT FORM_BROWSER_STATEMENT **RetQuestion ) { LIST_ENTRY *Link; - FORMSET_STORAGE *Storage; + LIST_ENTRY *LinkStorage; + LIST_ENTRY *LinkStatement; FORM_BROWSER_CONFIG_REQUEST *ConfigInfo; - FORM_BROWSER_FORMSET *LocalFormSet; + FORM_BROWSER_FORM *Form; + EFI_STRING EndStr; + FORM_BROWSER_STATEMENT *Statement; - // - // Check the supported setting level. - // - if (SettingScope >= MaxLevel) { - return EFI_UNSUPPORTED; - } - - if (SettingScope == FormLevel && IsNvUpdateRequiredForForm (Form)) { - ConfigInfo = NULL; - Link = GetFirstNode (&Form->ConfigRequestHead); - while (!IsNull (&Form->ConfigRequestHead, Link)) { - ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link); - Link = GetNextNode (&Form->ConfigRequestHead, Link); + ASSERT ((*Progress == '&') || (*Progress == 'G')); - if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { - continue; - } + ConfigInfo = NULL; + *RetForm = NULL; + *RetQuestion = NULL; + // + // Skip the first "&" or the ConfigHdr part. + // + if (*Progress == '&') { + Progress++; + } else { + // + // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { // - // Skip if there is no RequestElement + // For Name/Value type, Skip the ConfigHdr part. // - if (ConfigInfo->ElementCount == 0) { - continue; + EndStr = StrStr (Progress, L"PATH="); + ASSERT (EndStr != NULL); + while (*EndStr != '&') { + EndStr++; } + *EndStr = '\0'; + } else { // - // Prepare - // - SynchronizeStorage(FormSet, ConfigInfo->Storage, ConfigInfo->ConfigRequest, FALSE); - - // - // Call callback with Changed type to inform the driver. + // For Buffer type, Skip the ConfigHdr part. // - SendDiscardInfoToDriver (FormSet, Form); + EndStr = StrStr (Progress, L"&OFFSET="); + ASSERT (EndStr != NULL); + *EndStr = '\0'; } - ValueChangeResetFlagUpdate (FALSE, NULL, Form); - } else if (SettingScope == FormSetLevel && IsNvUpdateRequiredForFormSet (FormSet)) { + Progress = EndStr + 1; + } + // + // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { // - // Discard Buffer storage or Name/Value storage + // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset, + // here, just keep the "Fred" string. // - Link = GetFirstNode (&FormSet->StorageListHead); - while (!IsNull (&FormSet->StorageListHead, Link)) { - Storage = FORMSET_STORAGE_FROM_LINK (Link); - Link = GetNextNode (&FormSet->StorageListHead, Link); - - if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { - continue; - } - - // - // Skip if there is no RequestElement - // - if (Storage->ElementCount == 0) { - continue; - } - - SynchronizeStorage(FormSet, Storage->BrowserStorage, Storage->ConfigRequest, FALSE); - } - - Link = GetFirstNode (&FormSet->FormListHead); - while (!IsNull (&FormSet->FormListHead, Link)) { - Form = FORM_BROWSER_FORM_FROM_LINK (Link); - Link = GetNextNode (&FormSet->FormListHead, Link); - - // - // Call callback with Changed type to inform the driver. - // - SendDiscardInfoToDriver (FormSet, Form); - } - - ValueChangeResetFlagUpdate(FALSE, FormSet, NULL); - } else if (SettingScope == SystemLevel) { + EndStr = StrStr (Progress, L"="); + ASSERT (EndStr != NULL); + *EndStr = '\0'; + } else { // - // System Level Discard. + // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####", + // here, just keep the "OFFSET=0x####&WIDTH=0x####" string. // - + EndStr = StrStr (Progress, L"&VALUE="); + ASSERT (EndStr != NULL); + *EndStr = '\0'; + } + + // + // Search in the form list. + // + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&FormSet->FormListHead, Link); + // - // Discard changed value for each FormSet in the maintain list. + // Search in the ConfigReqeust list in this form. // - Link = GetFirstNode (&gBrowserFormSetList); - while (!IsNull (&gBrowserFormSetList, Link)) { - LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); - Link = GetNextNode (&gBrowserFormSetList, Link); - if (!ValidateFormSet(LocalFormSet)) { + LinkStorage = GetFirstNode (&Form->ConfigRequestHead); + while (!IsNull (&Form->ConfigRequestHead, LinkStorage)) { + ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (LinkStorage); + LinkStorage = GetNextNode (&Form->ConfigRequestHead, LinkStorage); + + if (Storage != ConfigInfo->Storage) { continue; } - DiscardForm (LocalFormSet, NULL, FormSetLevel); - if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) { + + if (StrStr (ConfigInfo->ConfigRequest, Progress) != NULL) { // - // Remove maintain backup list after discard except for the current using FormSet. + // Find the OffsetWidth string in this form. // - CleanBrowserStorage(LocalFormSet); - RemoveEntryList (&LocalFormSet->Link); - DestroyFormSet (LocalFormSet); + *RetForm = Form; + break; } } - } - return EFI_SUCCESS; -} + if (*RetForm != NULL) { + LinkStatement = GetFirstNode (&Form->StatementListHead); + while (!IsNull (&Form->StatementListHead, LinkStatement)) { + Statement = FORM_BROWSER_STATEMENT_FROM_LINK (LinkStatement); + LinkStatement = GetNextNode (&Form->StatementListHead, LinkStatement); -/** - Submit data based on the input Setting level (Form, FormSet or System). + if (Statement->BlockName != NULL && StrStr (Statement->BlockName, Progress) != NULL) { + *RetQuestion = Statement; + break; + } - @param FormSet FormSet data structure. - @param Form Form data structure. - @param SettingScope Setting Scope for Submit action. + if (Statement->VariableName != NULL && StrStr (Statement->VariableName, Progress) != NULL) { + *RetQuestion = Statement; + break; + } + } + } + + if (*RetForm != NULL) { + break; + } + } + + // + // restore the OffsetWidth string to the original format. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + *EndStr = '='; + } else { + *EndStr = '&'; + } + + return (BOOLEAN) (*RetForm != NULL); +} + +/** + Base on the return Progress string to get the SyncConfigRequest and RestoreConfigRequest + for form and formset. + + @param Storage Storage which has this Progress string. + @param ConfigRequest The ConfigRequest string. + @param Progress The Progress string which has the first fail string. + @param RestoreConfigRequest Return the RestoreConfigRequest string. + @param SyncConfigRequest Return the SyncConfigRequest string. + +**/ +VOID +GetSyncRestoreConfigRequest( + IN BROWSER_STORAGE *Storage, + IN EFI_STRING ConfigRequest, + IN EFI_STRING Progress, + OUT EFI_STRING *RestoreConfigRequest, + OUT EFI_STRING *SyncConfigRequest + ) +{ + EFI_STRING EndStr; + EFI_STRING ConfigHdrEndStr; + EFI_STRING ElementStr; + UINTN TotalSize; + UINTN RestoreEleSize; + UINTN SyncSize; + + ASSERT ((*Progress == L'&') || (*Progress == L'G')); + // + // If the Progress starts with ConfigHdr, means the failure is in the first name / value pair. + // Need to restore all the fields in the ConfigRequest. + // + if (*Progress == L'G') { + *RestoreConfigRequest = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest); + ASSERT (*RestoreConfigRequest != NULL); + return; + } + + // + // Find the first fail "NAME" or "OFFSET=0x####&WIDTH=0x####" string. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + // + // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset, + // here, just keep the "Fred" string. + // + EndStr = StrStr (Progress, L"="); + ASSERT (EndStr != NULL); + *EndStr = L'\0'; + // + // Find the ConfigHdr in ConfigRequest. + // + ConfigHdrEndStr = StrStr (ConfigRequest, L"PATH="); + ASSERT (ConfigHdrEndStr != NULL); + while (*ConfigHdrEndStr != L'&') { + ConfigHdrEndStr++; + } + } else { + // + // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####", + // here, just keep the "OFFSET=0x####&WIDTH=0x####" string. + // + EndStr = StrStr (Progress, L"&VALUE="); + ASSERT (EndStr != NULL); + *EndStr = L'\0'; + // + // Find the ConfigHdr in ConfigRequest. + // + ConfigHdrEndStr = StrStr (ConfigRequest, L"&OFFSET="); + } + // + // Find the first fail pair in the ConfigRequest. + // + ElementStr = StrStr (ConfigRequest, Progress); + ASSERT (ElementStr != NULL); + // + // To get the RestoreConfigRequest. + // + RestoreEleSize = StrSize (ElementStr); + TotalSize = (ConfigHdrEndStr - ConfigRequest) * sizeof (CHAR16) + RestoreEleSize + sizeof (CHAR16); + *RestoreConfigRequest = AllocateZeroPool (TotalSize); + ASSERT (*RestoreConfigRequest != NULL); + StrnCpyS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ConfigRequest, ConfigHdrEndStr - ConfigRequest); + StrCatS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ElementStr); + // + // To get the SyncConfigRequest. + // + SyncSize = StrSize (ConfigRequest) - RestoreEleSize + sizeof (CHAR16); + *SyncConfigRequest = AllocateZeroPool (SyncSize); + ASSERT (*SyncConfigRequest != NULL); + StrnCpyS (*SyncConfigRequest, SyncSize / sizeof (CHAR16), ConfigRequest, SyncSize / sizeof (CHAR16) - 1); + + // + // restore the Progress string to the original format. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + *EndStr = L'='; + } else { + *EndStr = L'&'; + } +} + +/** + Popup an save error info and get user input. + + @param TitleId The form title id. + @param HiiHandle The hii handle for this package. + + @retval UINT32 The user select option for the save fail. + BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET +**/ +UINT32 +ConfirmSaveFail ( + IN EFI_STRING_ID TitleId, + IN EFI_HII_HANDLE HiiHandle + ) +{ + CHAR16 *FormTitle; + CHAR16 *StringBuffer; + UINT32 RetVal; + + FormTitle = GetToken (TitleId, HiiHandle); + + StringBuffer = AllocateZeroPool (256 * sizeof (CHAR16)); + ASSERT (StringBuffer != NULL); + + UnicodeSPrint ( + StringBuffer, + 24 * sizeof (CHAR16) + StrSize (FormTitle), + L"Submit Fail For Form: %s.", + FormTitle + ); + + RetVal = PopupErrorMessage(BROWSER_SUBMIT_FAIL, NULL, NULL, StringBuffer); + + FreePool (StringBuffer); + FreePool (FormTitle); + + return RetVal; +} + +/** + Popup an NO_SUBMIT_IF error info and get user input. + + @param TitleId The form title id. + @param HiiHandle The hii handle for this package. + + @retval UINT32 The user select option for the save fail. + BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET +**/ +UINT32 +ConfirmNoSubmitFail ( + IN EFI_STRING_ID TitleId, + IN EFI_HII_HANDLE HiiHandle + ) +{ + CHAR16 *FormTitle; + CHAR16 *StringBuffer; + UINT32 RetVal; + + FormTitle = GetToken (TitleId, HiiHandle); + + StringBuffer = AllocateZeroPool (256 * sizeof (CHAR16)); + ASSERT (StringBuffer != NULL); + + UnicodeSPrint ( + StringBuffer, + 24 * sizeof (CHAR16) + StrSize (FormTitle), + L"NO_SUBMIT_IF error For Form: %s.", + FormTitle + ); + + RetVal = PopupErrorMessage(BROWSER_SUBMIT_FAIL_NO_SUBMIT_IF, NULL, NULL, StringBuffer); + + FreePool (StringBuffer); + FreePool (FormTitle); + + return RetVal; +} + +/** + Discard data based on the input setting scope (Form, FormSet or System). + + @param FormSet FormSet data structure. + @param Form Form data structure. + @param SettingScope Setting Scope for Discard action. @retval EFI_SUCCESS The function completed successfully. @retval EFI_UNSUPPORTED Unsupport SettingScope. **/ EFI_STATUS -SubmitForm ( +DiscardForm ( IN FORM_BROWSER_FORMSET *FormSet, IN FORM_BROWSER_FORM *Form, IN BROWSER_SETTING_SCOPE SettingScope ) { - EFI_STATUS Status; - LIST_ENTRY *Link; - EFI_STRING ConfigResp; - EFI_STRING Progress; - BROWSER_STORAGE *Storage; - FORMSET_STORAGE *FormSetStorage; - UINTN BufferSize; - UINT8 *TmpBuf; - FORM_BROWSER_FORMSET *LocalFormSet; + LIST_ENTRY *Link; + FORMSET_STORAGE *Storage; FORM_BROWSER_CONFIG_REQUEST *ConfigInfo; + FORM_BROWSER_FORMSET *LocalFormSet; + FORM_BROWSER_FORMSET *OldFormSet; // // Check the supported setting level. @@ -2515,19 +3194,6 @@ SubmitForm ( return EFI_UNSUPPORTED; } - // - // Validate the Form by NoSubmit check - // - Status = EFI_SUCCESS; - if (SettingScope == FormLevel) { - Status = NoSubmitCheck (FormSet, Form); - } else if (SettingScope == FormSetLevel) { - Status = NoSubmitCheck (FormSet, NULL); - } - if (EFI_ERROR (Status)) { - return Status; - } - if (SettingScope == FormLevel && IsNvUpdateRequiredForForm (Form)) { ConfigInfo = NULL; Link = GetFirstNode (&Form->ConfigRequestHead); @@ -2535,8 +3201,7 @@ SubmitForm ( ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link); Link = GetNextNode (&Form->ConfigRequestHead, Link); - Storage = ConfigInfo->Storage; - if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { continue; } @@ -2548,201 +3213,61 @@ SubmitForm ( } // - // 1. Prepare - // - Status = StorageToConfigResp (ConfigInfo->Storage, &ConfigResp, ConfigInfo->ConfigRequest, TRUE); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // 2. Set value to hii driver or efi variable. + // Prepare // - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || - Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { - // - // Send to Configuration Driver - // - if (FormSet->ConfigAccess != NULL) { - Status = FormSet->ConfigAccess->RouteConfig ( - FormSet->ConfigAccess, - ConfigResp, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (ConfigResp); - return Status; - } - } - } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { - TmpBuf = NULL; - TmpBuf = AllocateZeroPool(Storage->Size); - if (TmpBuf == NULL) { - Status = EFI_OUT_OF_RESOURCES; - return Status; - } - - BufferSize = Storage->Size; - Status = gRT->GetVariable ( - Storage->Name, - &Storage->Guid, - NULL, - &BufferSize, - TmpBuf - ); - if (EFI_ERROR (Status)) { - FreePool (TmpBuf); - FreePool (ConfigResp); - return Status; - } - ASSERT (BufferSize == Storage->Size); - Status = mHiiConfigRouting->ConfigToBlock ( - mHiiConfigRouting, - ConfigResp, - TmpBuf, - &BufferSize, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (TmpBuf); - FreePool (ConfigResp); - return Status; - } + SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->ConfigRequest, FALSE); - Status = gRT->SetVariable ( - Storage->Name, - &Storage->Guid, - Storage->Attributes, - Storage->Size, - TmpBuf - ); - FreePool (TmpBuf); - if (EFI_ERROR (Status)) { - FreePool (ConfigResp); - return Status; - } - } - FreePool (ConfigResp); // - // 3. Config success, update storage shadow Buffer, only update the data belong to this form. + // Call callback with Changed type to inform the driver. // - SynchronizeStorage (FormSet, ConfigInfo->Storage, ConfigInfo->ConfigRequest, TRUE); + SendDiscardInfoToDriver (FormSet, Form); } - // - // 4. Update the NV flag. - // - ValueChangeResetFlagUpdate(TRUE, NULL, Form); + ValueChangeResetFlagUpdate (FALSE, FormSet, Form); } else if (SettingScope == FormSetLevel && IsNvUpdateRequiredForFormSet (FormSet)) { + // - // Submit Buffer storage or Name/Value storage + // Discard Buffer storage or Name/Value storage // Link = GetFirstNode (&FormSet->StorageListHead); while (!IsNull (&FormSet->StorageListHead, Link)) { - FormSetStorage = (FORMSET_STORAGE_FROM_LINK (Link)); - Storage = FormSetStorage->BrowserStorage; + Storage = FORMSET_STORAGE_FROM_LINK (Link); Link = GetNextNode (&FormSet->StorageListHead, Link); - if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { continue; } // // Skip if there is no RequestElement // - if (FormSetStorage->ElementCount == 0) { + if (Storage->ElementCount == 0) { continue; } - // - // 1. Prepare - // - Status = StorageToConfigResp (Storage, &ConfigResp, FormSetStorage->ConfigRequest, TRUE); - if (EFI_ERROR (Status)) { - return Status; - } - - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || - Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + SynchronizeStorage(Storage->BrowserStorage, Storage->ConfigRequest, FALSE); + } - // - // 2. Send to Configuration Driver - // - if (FormSet->ConfigAccess != NULL) { - Status = FormSet->ConfigAccess->RouteConfig ( - FormSet->ConfigAccess, - ConfigResp, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (ConfigResp); - return Status; - } - } - } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { - // - // 1&2. Set the edit data to the variable. - // - TmpBuf = NULL; - TmpBuf = AllocateZeroPool (Storage->Size); - if (TmpBuf == NULL) { - Status = EFI_OUT_OF_RESOURCES; - return Status; - } - BufferSize = Storage->Size; - Status = gRT->GetVariable ( - Storage->Name, - &Storage->Guid, - NULL, - &BufferSize, - TmpBuf - ); - ASSERT (BufferSize == Storage->Size); - Status = mHiiConfigRouting->ConfigToBlock ( - mHiiConfigRouting, - ConfigResp, - TmpBuf, - &BufferSize, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (TmpBuf); - FreePool (ConfigResp); - return Status; - } + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&FormSet->FormListHead, Link); - Status = gRT->SetVariable ( - Storage->Name, - &Storage->Guid, - Storage->Attributes, - Storage->Size, - TmpBuf - ); - if (EFI_ERROR (Status)) { - FreePool (TmpBuf); - FreePool (ConfigResp); - return Status; - } - FreePool (TmpBuf); - } - FreePool (ConfigResp); // - // 3. Config success, update storage shadow Buffer + // Call callback with Changed type to inform the driver. // - SynchronizeStorage (FormSet, Storage, FormSetStorage->ConfigRequest, TRUE); + SendDiscardInfoToDriver (FormSet, Form); } - // - // 4. Update the NV flag. - // - ValueChangeResetFlagUpdate(TRUE, FormSet, NULL); + ValueChangeResetFlagUpdate(FALSE, FormSet, NULL); } else if (SettingScope == SystemLevel) { // - // System Level Save. + // System Level Discard. // + OldFormSet = mSystemLevelFormSet; // - // Save changed value for each FormSet in the maintain list. + // Discard changed value for each FormSet in the maintain list. // Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { @@ -2751,214 +3276,756 @@ SubmitForm ( if (!ValidateFormSet(LocalFormSet)) { continue; } - SubmitForm (LocalFormSet, NULL, FormSetLevel); + + mSystemLevelFormSet = LocalFormSet; + + DiscardForm (LocalFormSet, NULL, FormSetLevel); if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) { // - // Remove maintain backup list after save except for the current using FormSet. + // Remove maintain backup list after discard except for the current using FormSet. // CleanBrowserStorage(LocalFormSet); RemoveEntryList (&LocalFormSet->Link); DestroyFormSet (LocalFormSet); } } + + mSystemLevelFormSet = OldFormSet; } return EFI_SUCCESS; } /** - Get Question default value from AltCfg string. + Submit data for a form. - @param FormSet The form set. - @param Question The question. - @param DefaultId The default Id. + @param FormSet FormSet data structure. + @param Form Form data structure. - @retval EFI_SUCCESS Question is reset to default value. + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_UNSUPPORTED Unsupport SettingScope. **/ EFI_STATUS -GetDefaultValueFromAltCfg ( - IN FORM_BROWSER_FORMSET *FormSet, - IN OUT FORM_BROWSER_STATEMENT *Question, - IN UINT16 DefaultId +SubmitForForm ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form ) { - BOOLEAN IsBufferStorage; - BOOLEAN IsString; - UINTN Length; - BROWSER_STORAGE *Storage; - CHAR16 *ConfigRequest; - CHAR16 *Progress; - CHAR16 *Result; - CHAR16 *ConfigResp; - CHAR16 *Value; - CHAR16 *StringPtr; - UINTN LengthStr; - UINT8 *Dst; - CHAR16 TemStr[5]; - UINTN Index; - UINT8 DigitUint8; - EFI_STATUS Status; + EFI_STATUS Status; + LIST_ENTRY *Link; + EFI_STRING ConfigResp; + EFI_STRING Progress; + BROWSER_STORAGE *Storage; + FORM_BROWSER_CONFIG_REQUEST *ConfigInfo; + BOOLEAN SubmitFormFail; - Status = EFI_NOT_FOUND; - Length = 0; - Dst = NULL; - ConfigRequest = NULL; - Result = NULL; - ConfigResp = NULL; - Value = NULL; - Storage = Question->Storage; + SubmitFormFail = FALSE; - if ((Storage == NULL) || - (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) || - (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { + if (!IsNvUpdateRequiredForForm (Form)) { + return EFI_SUCCESS; + } + + Status = NoSubmitCheck (FormSet, &Form, NULL); + if (EFI_ERROR (Status)) { return Status; } - // - // Question Value is provided by Buffer Storage or NameValue Storage - // - if (Question->BufferValue != NULL) { + Link = GetFirstNode (&Form->ConfigRequestHead); + while (!IsNull (&Form->ConfigRequestHead, Link)) { + ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link); + Link = GetNextNode (&Form->ConfigRequestHead, Link); + + Storage = ConfigInfo->Storage; + if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + continue; + } + // - // This Question is password or orderedlist + // Skip if there is no RequestElement // - Dst = Question->BufferValue; - } else { + if (ConfigInfo->ElementCount == 0) { + continue; + } + // - // Other type of Questions + // 1. Prepare // - Dst = (UINT8 *) &Question->HiiValue.Value; - } + Status = StorageToConfigResp (ConfigInfo->Storage, &ConfigResp, ConfigInfo->ConfigRequest, TRUE); + if (EFI_ERROR (Status)) { + return Status; + } - IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE); - IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE); + // + // 2. Set value to hii config routine protocol. + // + Status = mHiiConfigRouting->RouteConfig ( + mHiiConfigRouting, + ConfigResp, + &Progress + ); - // - // ::= + || - // + "&" + - // - if (IsBufferStorage) { - Length = StrLen (Storage->ConfigHdr); - Length += StrLen (Question->BlockName); - } else { - Length = StrLen (Storage->ConfigHdr); - Length += StrLen (Question->VariableName) + 1; + if (EFI_ERROR (Status)) { + // + // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest. + // + SubmitFormFail = TRUE; + GetSyncRestoreConfigRequest (ConfigInfo->Storage, ConfigInfo->ConfigRequest, Progress, &ConfigInfo->RestoreConfigRequest, &ConfigInfo->SyncConfigRequest); + InsertTailList (&gBrowserSaveFailFormSetList, &ConfigInfo->SaveFailLink); + FreePool (ConfigResp); + continue; + } + + FreePool (ConfigResp); + // + // 3. Config success, update storage shadow Buffer, only update the data belong to this form. + // + SynchronizeStorage (ConfigInfo->Storage, ConfigInfo->ConfigRequest, TRUE); } - ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); - ASSERT (ConfigRequest != NULL); - StrCpy (ConfigRequest, Storage->ConfigHdr); - if (IsBufferStorage) { - StrCat (ConfigRequest, Question->BlockName); - } else { - StrCat (ConfigRequest, L"&"); - StrCat (ConfigRequest, Question->VariableName); + // + // 4. Process the save failed storage. + // + if (!IsListEmpty (&gBrowserSaveFailFormSetList)) { + if (ConfirmSaveFail (Form->FormTitle, FormSet->HiiHandle) == BROWSER_ACTION_DISCARD) { + Link = GetFirstNode (&gBrowserSaveFailFormSetList); + while (!IsNull (&gBrowserSaveFailFormSetList, Link)) { + ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link); + Link = GetNextNode (&gBrowserSaveFailFormSetList, Link); + // + // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer + // base on the SyncConfigRequest to Sync the buffer. + // + SynchronizeStorage (ConfigInfo->Storage, ConfigInfo->RestoreConfigRequest, FALSE); + FreePool (ConfigInfo->RestoreConfigRequest); + ConfigInfo->RestoreConfigRequest = NULL; + if (ConfigInfo->SyncConfigRequest != NULL) { + SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->SyncConfigRequest, TRUE); + FreePool (ConfigInfo->SyncConfigRequest); + ConfigInfo->SyncConfigRequest = NULL; + } + + Status = EFI_SUCCESS; + } + SendDiscardInfoToDriver (FormSet,Form); + } else { + Status = EFI_UNSUPPORTED; + } + + // + // Free Form save fail list. + // + while (!IsListEmpty (&gBrowserSaveFailFormSetList)) { + Link = GetFirstNode (&gBrowserSaveFailFormSetList); + ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link); + RemoveEntryList (&ConfigInfo->SaveFailLink); + } } - Status = FormSet->ConfigAccess->ExtractConfig ( - FormSet->ConfigAccess, - ConfigRequest, - &Progress, - &Result - ); + // + // 5. Update the NV flag. + // + ValueChangeResetFlagUpdate(TRUE, FormSet, Form); + + // + // 6 Call callback with Submitted type to inform the driver. + // + if (!SubmitFormFail) { + SubmitCallback (FormSet, Form); + } + + return Status; +} + +/** + Submit data for a formset. + + @param FormSet FormSet data structure. + @param SkipProcessFail Whether skip to process the save failed storage. + If submit formset is called when do system level save, + set this value to true and process the failed formset + together. + if submit formset is called when do formset level save, + set the value to false and process the failed storage + right after process all storages for this formset. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_UNSUPPORTED Unsupport SettingScope. + +**/ +EFI_STATUS +SubmitForFormSet ( + IN FORM_BROWSER_FORMSET *FormSet, + IN BOOLEAN SkipProcessFail + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + EFI_STRING ConfigResp; + EFI_STRING Progress; + BROWSER_STORAGE *Storage; + FORMSET_STORAGE *FormSetStorage; + FORM_BROWSER_FORM *Form; + BOOLEAN HasInserted; + FORM_BROWSER_STATEMENT *Question; + BOOLEAN SubmitFormSetFail; + BOOLEAN DiscardChange; + + HasInserted = FALSE; + SubmitFormSetFail = FALSE; + DiscardChange = FALSE; + + if (!IsNvUpdateRequiredForFormSet (FormSet)) { + return EFI_SUCCESS; + } + + Form = NULL; + Status = NoSubmitCheck (FormSet, &Form, &Question); if (EFI_ERROR (Status)) { - goto Done; + if (SkipProcessFail) { + // + // Process NO_SUBMIT check first, so insert it at head. + // + FormSet->SaveFailForm = Form; + FormSet->SaveFailStatement = Question; + InsertHeadList (&gBrowserSaveFailFormSetList, &FormSet->SaveFailLink); + } + + return Status; + } + + Form = NULL; + Question = NULL; + // + // Submit Buffer storage or Name/Value storage + // + Link = GetFirstNode (&FormSet->StorageListHead); + while (!IsNull (&FormSet->StorageListHead, Link)) { + FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link); + Storage = FormSetStorage->BrowserStorage; + Link = GetNextNode (&FormSet->StorageListHead, Link); + + if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + continue; + } + + // + // Skip if there is no RequestElement + // + if (FormSetStorage->ElementCount == 0) { + continue; + } + + // + // 1. Prepare + // + Status = StorageToConfigResp (Storage, &ConfigResp, FormSetStorage->ConfigRequest, TRUE); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // 2. Send to Routine config Protocol. + // + Status = mHiiConfigRouting->RouteConfig ( + mHiiConfigRouting, + ConfigResp, + &Progress + ); + if (EFI_ERROR (Status)) { + // + // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest. + // + SubmitFormSetFail = TRUE; + GetSyncRestoreConfigRequest (FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, Progress, &FormSetStorage->RestoreConfigRequest, &FormSetStorage->SyncConfigRequest); + InsertTailList (&FormSet->SaveFailStorageListHead, &FormSetStorage->SaveFailLink); + if (!HasInserted) { + // + // Call submit formset for system level, save the formset info + // and process later. + // + FindQuestionFromProgress(FormSet, Storage, Progress, &Form, &Question); + ASSERT (Form != NULL && Question != NULL); + FormSet->SaveFailForm = Form; + FormSet->SaveFailStatement = Question; + if (SkipProcessFail) { + InsertTailList (&gBrowserSaveFailFormSetList, &FormSet->SaveFailLink); + } + HasInserted = TRUE; + } + + FreePool (ConfigResp); + continue; + } + + FreePool (ConfigResp); + // + // 3. Config success, update storage shadow Buffer + // + SynchronizeStorage (Storage, FormSetStorage->ConfigRequest, TRUE); + } + + // + // 4. Has save fail storage need to handle. + // + if (Form != NULL) { + if (!SkipProcessFail) { + // + // If not in system level, just handl the save failed storage here. + // + if (ConfirmSaveFail (Form->FormTitle, FormSet->HiiHandle) == BROWSER_ACTION_DISCARD) { + DiscardChange = TRUE; + Link = GetFirstNode (&FormSet->SaveFailStorageListHead); + while (!IsNull (&FormSet->SaveFailStorageListHead, Link)) { + FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link); + Storage = FormSetStorage->BrowserStorage; + Link = GetNextNode (&FormSet->SaveFailStorageListHead, Link); + // + // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer + // base on the SyncConfigRequest to Sync the buffer. + // + SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE); + FreePool (FormSetStorage->RestoreConfigRequest); + FormSetStorage->RestoreConfigRequest = NULL; + if (FormSetStorage->SyncConfigRequest != NULL) { + SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE); + FreePool (FormSetStorage->SyncConfigRequest); + FormSetStorage->SyncConfigRequest = NULL; + } + + Status = EFI_SUCCESS; + } + } else { + UiCopyMenuList(&mPrivateData.FormBrowserEx2.FormViewHistoryHead, &Form->FormViewListHead); + + gCurrentSelection->Action = UI_ACTION_REFRESH_FORMSET; + gCurrentSelection->Handle = FormSet->HiiHandle; + CopyGuid (&gCurrentSelection->FormSetGuid, &FormSet->Guid); + gCurrentSelection->FormId = Form->FormId; + gCurrentSelection->QuestionId = Question->QuestionId; + + Status = EFI_UNSUPPORTED; + } + + // + // Free FormSet save fail list. + // + while (!IsListEmpty (&FormSet->SaveFailStorageListHead)) { + Link = GetFirstNode (&FormSet->SaveFailStorageListHead); + FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link); + RemoveEntryList (&FormSetStorage->SaveFailLink); + } + } else { + // + // If in system level, just return error and handle the failed formset later. + // + Status = EFI_UNSUPPORTED; + } + } + + // + // If user discard the change, send the discard info to driver. + // + if (DiscardChange) { + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&FormSet->FormListHead, Link); + // + // Call callback with Changed type to inform the driver. + // + SendDiscardInfoToDriver (FormSet, Form); + } + } + + // + // 5. Update the NV flag. + // + ValueChangeResetFlagUpdate(TRUE, FormSet, NULL); + + // + // 6. Call callback with Submitted type to inform the driver. + // + if (!SubmitFormSetFail) { + SubmitCallback (FormSet, NULL); + } + + return Status; +} + +/** + Submit data for all formsets. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_UNSUPPORTED Unsupport SettingScope. + +**/ +EFI_STATUS +SubmitForSystem ( + VOID + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + LIST_ENTRY *FormLink; + LIST_ENTRY *StorageLink; + FORMSET_STORAGE *FormSetStorage; + FORM_BROWSER_FORM *Form; + FORM_BROWSER_FORMSET *LocalFormSet; + UINT32 UserSelection; + FORM_BROWSER_STATEMENT *Question; + + mSystemSubmit = TRUE; + Link = GetFirstNode (&gBrowserFormSetList); + while (!IsNull (&gBrowserFormSetList, Link)) { + LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); + Link = GetNextNode (&gBrowserFormSetList, Link); + if (!ValidateFormSet(LocalFormSet)) { + continue; + } + + Status = SubmitForFormSet (LocalFormSet, TRUE); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Remove maintain backup list after save except for the current using FormSet. + // + if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) { + CleanBrowserStorage(LocalFormSet); + RemoveEntryList (&LocalFormSet->Link); + DestroyFormSet (LocalFormSet); + } + } + mSystemSubmit = FALSE; + + Status = EFI_SUCCESS; + + // + // Process the save failed formsets. + // + Link = GetFirstNode (&gBrowserSaveFailFormSetList); + while (!IsNull (&gBrowserSaveFailFormSetList, Link)) { + LocalFormSet = FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link); + Link = GetNextNode (&gBrowserSaveFailFormSetList, Link); + + if (!ValidateFormSet(LocalFormSet)) { + continue; + } + + Form = LocalFormSet->SaveFailForm; + Question= LocalFormSet->SaveFailStatement; + + // + // Confirm with user, get user input. + // + if (IsListEmpty (&LocalFormSet->SaveFailStorageListHead)) { + // + // NULL for SaveFailStorageListHead means error caused by NO_SUBMIT_IF check. + // + UserSelection = ConfirmNoSubmitFail (Form->FormTitle, LocalFormSet->HiiHandle); + } else { + UserSelection = ConfirmSaveFail (Form->FormTitle, LocalFormSet->HiiHandle); + } + + if (UserSelection == BROWSER_ACTION_DISCARD) { + if (IsListEmpty (&LocalFormSet->SaveFailStorageListHead)) { + StorageLink = GetFirstNode (&LocalFormSet->StorageListHead); + while (!IsNull (&LocalFormSet->StorageListHead, StorageLink)) { + FormSetStorage = FORMSET_STORAGE_FROM_LINK (StorageLink); + StorageLink = GetNextNode (&LocalFormSet->StorageListHead, StorageLink); + + SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE); + } + } else { + StorageLink = GetFirstNode (&LocalFormSet->SaveFailStorageListHead); + while (!IsNull (&LocalFormSet->SaveFailStorageListHead, StorageLink)) { + FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink); + StorageLink = GetNextNode (&LocalFormSet->SaveFailStorageListHead, StorageLink); + // + // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer + // base on the SyncConfigRequest to Sync the buffer. + // + SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE); + FreePool (FormSetStorage->RestoreConfigRequest); + FormSetStorage->RestoreConfigRequest = NULL; + if ( FormSetStorage->SyncConfigRequest != NULL) { + SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE); + FreePool (FormSetStorage->SyncConfigRequest); + FormSetStorage->SyncConfigRequest = NULL; + } + } + } + + FormLink = GetFirstNode (&LocalFormSet->FormListHead); + while (!IsNull (&LocalFormSet->FormListHead, FormLink)) { + Form = FORM_BROWSER_FORM_FROM_LINK (FormLink); + FormLink = GetNextNode (&LocalFormSet->FormListHead, FormLink); + // + // Call callback with Changed type to inform the driver. + // + SendDiscardInfoToDriver (LocalFormSet, Form); + } + + if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) { + CleanBrowserStorage(LocalFormSet); + RemoveEntryList (&LocalFormSet->Link); + RemoveEntryList (&LocalFormSet->SaveFailLink); + DestroyFormSet (LocalFormSet); + } else { + ValueChangeResetFlagUpdate(FALSE, LocalFormSet, NULL); + } + } else { + if (IsListEmpty (&LocalFormSet->SaveFailStorageListHead)) { + NoSubmitCheck (LocalFormSet, &Form, &Question); + } + + UiCopyMenuList(&mPrivateData.FormBrowserEx2.FormViewHistoryHead, &Form->FormViewListHead); + + gCurrentSelection->Action = UI_ACTION_REFRESH_FORMSET; + gCurrentSelection->Handle = LocalFormSet->HiiHandle; + CopyGuid (&gCurrentSelection->FormSetGuid, &LocalFormSet->Guid); + gCurrentSelection->FormId = Form->FormId; + gCurrentSelection->QuestionId = Question->QuestionId; + + Status = EFI_UNSUPPORTED; + break; + } + } + + // + // Clean the list which will not process. + // + while (!IsListEmpty (&gBrowserSaveFailFormSetList)) { + Link = GetFirstNode (&gBrowserSaveFailFormSetList); + LocalFormSet = FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link); + RemoveEntryList (&LocalFormSet->SaveFailLink); + + while (!IsListEmpty (&LocalFormSet->SaveFailStorageListHead)) { + StorageLink = GetFirstNode (&LocalFormSet->SaveFailStorageListHead); + FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink); + RemoveEntryList (&FormSetStorage->SaveFailLink); + } + } + + return Status; +} + +/** + Submit data based on the input Setting level (Form, FormSet or System). + + @param FormSet FormSet data structure. + @param Form Form data structure. + @param SettingScope Setting Scope for Submit action. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_UNSUPPORTED Unsupport SettingScope. + +**/ +EFI_STATUS +SubmitForm ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form, + IN BROWSER_SETTING_SCOPE SettingScope + ) +{ + EFI_STATUS Status; + + switch (SettingScope) { + case FormLevel: + Status = SubmitForForm(FormSet, Form); + break; + + case FormSetLevel: + Status = SubmitForFormSet (FormSet, FALSE); + break; + + case SystemLevel: + Status = SubmitForSystem (); + break; + + default: + Status = EFI_UNSUPPORTED; + break; + } + + return Status; +} + +/** + Converts the unicode character of the string from uppercase to lowercase. + This is a internal function. + + @param ConfigString String to be converted + +**/ +VOID +EFIAPI +HiiToLower ( + IN EFI_STRING ConfigString + ) +{ + EFI_STRING String; + BOOLEAN Lower; + + ASSERT (ConfigString != NULL); + + // + // Convert all hex digits in range [A-F] in the configuration header to [a-f] + // + for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) { + if (*String == L'=') { + Lower = TRUE; + } else if (*String == L'&') { + Lower = FALSE; + } else if (Lower && *String >= L'A' && *String <= L'F') { + *String = (CHAR16) (*String - L'A' + L'a'); + } + } +} + +/** + Find the point in the ConfigResp string for this question. + + @param Question The question. + @param ConfigResp Get ConfigResp string. + + @retval point to the offset where is for this question. + +**/ +CHAR16 * +GetOffsetFromConfigResp ( + IN FORM_BROWSER_STATEMENT *Question, + IN CHAR16 *ConfigResp + ) +{ + CHAR16 *RequestElement; + CHAR16 *BlockData; + + // + // Type is EFI_HII_VARSTORE_NAME_VALUE. + // + if (Question->Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + RequestElement = StrStr (ConfigResp, Question->VariableName); + if (RequestElement != NULL) { + // + // Skip the "VariableName=" field. + // + RequestElement += StrLen (Question->VariableName) + 1; + } + + return RequestElement; } // - // Call ConfigRouting GetAltCfg(ConfigRoute, , Guid, Name, DevicePath, AltCfgId, AltCfgResp) - // Get the default configuration string according to the default ID. + // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER // - Status = mHiiConfigRouting->GetAltConfig ( - mHiiConfigRouting, - Result, - &Storage->Guid, - Storage->Name, - NULL, - &DefaultId, // 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. + // Convert all hex digits in ConfigResp to lower case before searching. // - if (EFI_ERROR (Status)) { - goto Done; - } + HiiToLower (ConfigResp); // - // Skip + // 1. Directly use Question->BlockName to find. // - if (IsBufferStorage) { - Value = StrStr (ConfigResp, L"&VALUE"); - ASSERT (Value != NULL); + RequestElement = StrStr (ConfigResp, Question->BlockName); + if (RequestElement != NULL) { // - // Skip "&VALUE" + // Skip the "Question->BlockName&VALUE=" field. // - Value = Value + 6; - } else { - Value = StrStr (ConfigResp, Question->VariableName); - ASSERT (Value != NULL); - - Value = Value + StrLen (Question->VariableName); - } - if (*Value != '=') { - Status = EFI_NOT_FOUND; - goto Done; + RequestElement += StrLen (Question->BlockName) + StrLen (L"&VALUE="); + return RequestElement; } + // - // Skip '=', point to value + // 2. Change all hex digits in Question->BlockName to lower and compare again. // - Value = Value + 1; + BlockData = AllocateCopyPool (StrSize(Question->BlockName), Question->BlockName); + ASSERT (BlockData != NULL); + HiiToLower (BlockData); + RequestElement = StrStr (ConfigResp, BlockData); + FreePool (BlockData); + + if (RequestElement != NULL) { + // + // Skip the "Question->BlockName&VALUE=" field. + // + RequestElement += StrLen (Question->BlockName) + StrLen (L"&VALUE="); + } + + return RequestElement; +} + +/** + Get Question default value from AltCfg string. + + @param FormSet The form set. + @param Form The form + @param Question The question. + + @retval EFI_SUCCESS Question is reset to default value. + +**/ +EFI_STATUS +GetDefaultValueFromAltCfg ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form, + IN OUT FORM_BROWSER_STATEMENT *Question + ) +{ + BROWSER_STORAGE *Storage; + FORMSET_STORAGE *FormSetStorage; + CHAR16 *ConfigResp; + CHAR16 *Value; + LIST_ENTRY *Link; + FORM_BROWSER_CONFIG_REQUEST *ConfigInfo; + + Storage = Question->Storage; + if ((Storage == NULL) || (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) { + return EFI_NOT_FOUND; + } // - // Suppress if any + // Try to get AltCfg string from form. If not found it, then + // try to get it from formset. // - StringPtr = Value; - while (*StringPtr != L'\0' && *StringPtr != L'&') { - StringPtr++; - } - *StringPtr = L'\0'; + ConfigResp = NULL; + Link = GetFirstNode (&Form->ConfigRequestHead); + while (!IsNull (&Form->ConfigRequestHead, Link)) { + ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link); + Link = GetNextNode (&Form->ConfigRequestHead, Link); - LengthStr = StrLen (Value); - if (!IsBufferStorage && IsString) { - StringPtr = (CHAR16 *) Dst; - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index += 4) { - StrnCpy (TemStr, Value + Index, 4); - StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr); + if (Storage == ConfigInfo->Storage) { + ConfigResp = ConfigInfo->ConfigAltResp; + break; } - // - // Add tailing L'\0' character - // - StringPtr[Index/4] = L'\0'; - } else { - ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < LengthStr; Index ++) { - TemStr[0] = Value[LengthStr - Index - 1]; - DigitUint8 = (UINT8) StrHexToUint64 (TemStr); - if ((Index & 1) == 0) { - Dst [Index/2] = DigitUint8; - } else { - Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]); + } + + if (ConfigResp == NULL) { + Link = GetFirstNode (&FormSet->StorageListHead); + while (!IsNull (&FormSet->StorageListHead, Link)) { + FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link); + Link = GetNextNode (&FormSet->StorageListHead, Link); + + if (Storage == FormSetStorage->BrowserStorage) { + ConfigResp = FormSetStorage->ConfigAltResp; + break; } } } -Done: - if (ConfigRequest != NULL){ - FreePool (ConfigRequest); + if (ConfigResp == NULL) { + return EFI_NOT_FOUND; } - if (ConfigResp != NULL) { - FreePool (ConfigResp); - } - - if (Result != NULL) { - FreePool (Result); + Value = GetOffsetFromConfigResp (Question, ConfigResp); + if (Value == NULL) { + return EFI_NOT_FOUND; } - return Status; + return BufferToValue (Question, Value); } /** @@ -2973,7 +4040,7 @@ INTN GetDefaultIdForCallBack ( UINTN DefaultId ) -{ +{ if (DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) { return EFI_BROWSER_ACTION_DEFAULT_STANDARD; } else if (DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) { @@ -3152,9 +4219,16 @@ GetQuestionDefault ( EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; EFI_BROWSER_ACTION_REQUEST ActionRequest; INTN Action; + CHAR16 *NewString; + EFI_IFR_TYPE_VALUE *TypeValue; + UINT16 OriginalDefaultId; + FORMSET_DEFAULTSTORE *DefaultStore; + LIST_ENTRY *DefaultLink; Status = EFI_NOT_FOUND; StrValue = NULL; + OriginalDefaultId = DefaultId; + DefaultLink = GetFirstNode (&FormSet->DefaultStoreListHead); // // Statement don't have storage, skip them @@ -3167,11 +4241,19 @@ GetQuestionDefault ( // There are Five ways to specify default value for a Question: // 1, use call back function (highest priority) // 2, use ExtractConfig function - // 3, use nested EFI_IFR_DEFAULT + // 3, use nested EFI_IFR_DEFAULT // 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default) // 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority) // +ReGetDefault: HiiValue = &Question->HiiValue; + TypeValue = &HiiValue->Value; + if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) { + // + // For orderedlist, need to pass the BufferValue to Callback function. + // + TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue; + } // // Get Question defaut value from call back function. @@ -3185,10 +4267,24 @@ GetQuestionDefault ( Action, Question->QuestionId, HiiValue->Type, - &HiiValue->Value, + TypeValue, &ActionRequest ); if (!EFI_ERROR (Status)) { + if (HiiValue->Type == EFI_IFR_TYPE_STRING) { + NewString = GetToken (Question->HiiValue.Value.string, FormSet->HiiHandle); + ASSERT (NewString != NULL); + + ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Question->StorageWidth); + if (StrLen (NewString) * sizeof (CHAR16) <= Question->StorageWidth) { + ZeroMem (Question->BufferValue, Question->StorageWidth); + CopyMem (Question->BufferValue, NewString, StrSize (NewString)); + } else { + CopyMem (Question->BufferValue, NewString, Question->StorageWidth); + } + + FreePool (NewString); + } return Status; } } @@ -3196,8 +4292,8 @@ GetQuestionDefault ( // // Get default value from altcfg string. // - if (ConfigAccess != NULL) { - Status = GetDefaultValueFromAltCfg(FormSet, Question, DefaultId); + if (ConfigAccess != NULL) { + Status = GetDefaultValueFromAltCfg(FormSet, Form, Question); if (!EFI_ERROR (Status)) { return Status; } @@ -3233,12 +4329,17 @@ GetQuestionDefault ( FreePool (Default->ValueExpression->Result.Buffer); } HiiValue->Type = Default->ValueExpression->Result.Type; - CopyMem (&HiiValue->Value, &Default->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); + CopyMem (&HiiValue->Value, &Default->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); } else { // // Default value is embedded in EFI_IFR_DEFAULT // - CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE)); + if (Default->Value.Type == EFI_IFR_TYPE_BUFFER) { + ASSERT (HiiValue->Buffer != NULL); + CopyMem (HiiValue->Buffer, Default->Value.Buffer, Default->Value.BufferLen); + } else { + CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE)); + } } if (HiiValue->Type == EFI_IFR_TYPE_STRING) { @@ -3247,6 +4348,7 @@ GetQuestionDefault ( return EFI_NOT_FOUND; } if (Question->StorageWidth > StrSize (StrValue)) { + ZeroMem (Question->BufferValue, Question->StorageWidth); CopyMem (Question->BufferValue, StrValue, StrSize (StrValue)); } else { CopyMem (Question->BufferValue, StrValue, Question->StorageWidth); @@ -3301,8 +4403,6 @@ GetQuestionDefault ( ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) != 0)) ) { HiiValue->Value.b = TRUE; - } else { - HiiValue->Value.b = FALSE; } return EFI_SUCCESS; @@ -3310,79 +4410,374 @@ GetQuestionDefault ( } // - // For Questions without default + // For question without default value for current default Id, we try to re-get the default value form other default id in the DefaultStoreList. + // If get, will exit the function, if not, will choose next default id in the DefaultStoreList. + // The default id in DefaultStoreList are in ascending order to make sure choose the smallest default id every time. + // + while (!IsNull(&FormSet->DefaultStoreListHead, DefaultLink)) { + DefaultStore = FORMSET_DEFAULTSTORE_FROM_LINK(DefaultLink); + DefaultLink = GetNextNode (&FormSet->DefaultStoreListHead,DefaultLink); + DefaultId = DefaultStore->DefaultId; + if (DefaultId == OriginalDefaultId) { + continue; + } + goto ReGetDefault; + } + + // + // For Questions without default value for all the default id in the DefaultStoreList. // Status = EFI_NOT_FOUND; switch (Question->Operand) { + case EFI_IFR_CHECKBOX_OP: + HiiValue->Value.b = FALSE; + Status = EFI_SUCCESS; + break; + case EFI_IFR_NUMERIC_OP: // // Take minimum value as numeric default value // - if ((HiiValue->Value.u64 < Question->Minimum) || (HiiValue->Value.u64 > Question->Maximum)) { - HiiValue->Value.u64 = Question->Minimum; + if ((Question->Flags & EFI_IFR_DISPLAY) == 0) { + // + // In EFI_IFR_DISPLAY_INT_DEC type, should check value with int* type. + // + switch (Question->Flags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + if (((INT8) HiiValue->Value.u8 < (INT8) Question->Minimum) || ((INT8) HiiValue->Value.u8 > (INT8) Question->Maximum)) { + HiiValue->Value.u8 = (UINT8) Question->Minimum; + Status = EFI_SUCCESS; + } + break; + case EFI_IFR_NUMERIC_SIZE_2: + if (((INT16) HiiValue->Value.u16 < (INT16) Question->Minimum) || ((INT16) HiiValue->Value.u16 > (INT16) Question->Maximum)) { + HiiValue->Value.u16 = (UINT16) Question->Minimum; + Status = EFI_SUCCESS; + } + break; + case EFI_IFR_NUMERIC_SIZE_4: + if (((INT32) HiiValue->Value.u32 < (INT32) Question->Minimum) || ((INT32) HiiValue->Value.u32 > (INT32) Question->Maximum)) { + HiiValue->Value.u32 = (UINT32) Question->Minimum; + Status = EFI_SUCCESS; + } + break; + case EFI_IFR_NUMERIC_SIZE_8: + if (((INT64) HiiValue->Value.u64 < (INT64) Question->Minimum) || ((INT64) HiiValue->Value.u64 > (INT64) Question->Maximum)) { + HiiValue->Value.u64 = Question->Minimum; + Status = EFI_SUCCESS; + } + break; + default: + break; + } + } else { + if ((HiiValue->Value.u64 < Question->Minimum) || (HiiValue->Value.u64 > Question->Maximum)) { + HiiValue->Value.u64 = Question->Minimum; + Status = EFI_SUCCESS; + } + } + break; + + case EFI_IFR_ONE_OF_OP: + // + // Take first oneof option as oneof's default value + // + if (ValueToOption (Question, HiiValue) == NULL) { + Link = GetFirstNode (&Question->OptionListHead); + while (!IsNull (&Question->OptionListHead, Link)) { + Option = QUESTION_OPTION_FROM_LINK (Link); + Link = GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression != NULL) && + EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { + continue; + } + + CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE)); + Status = EFI_SUCCESS; + break; + } + } + break; + + case EFI_IFR_ORDERED_LIST_OP: + // + // Take option sequence in IFR as ordered list's default value + // + Index = 0; + Link = GetFirstNode (&Question->OptionListHead); + while (!IsNull (&Question->OptionListHead, Link)) { Status = EFI_SUCCESS; + Option = QUESTION_OPTION_FROM_LINK (Link); + Link = GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression != NULL) && + EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { + continue; + } + + SetArrayData (Question->BufferValue, Question->ValueType, Index, Option->Value.Value.u64); + + Index++; + if (Index >= Question->MaxContainers) { + break; + } + } + break; + + default: + break; + } + + return Status; +} + +/** + Get AltCfg string for current form. + + @param FormSet Form data structure. + @param Form Form data structure. + @param DefaultId The Class of the default. + @param BrowserStorage The input request storage for the questions. + +**/ +VOID +ExtractAltCfgForForm ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form, + IN UINT16 DefaultId, + IN BROWSER_STORAGE *BrowserStorage + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + CHAR16 *ConfigResp; + CHAR16 *Progress; + CHAR16 *Result; + BROWSER_STORAGE *Storage; + FORM_BROWSER_CONFIG_REQUEST *ConfigInfo; + FORMSET_STORAGE *FormSetStorage; + + // + // Check whether has get AltCfg string for this formset. + // If yes, no need to get AltCfg for form. + // + Link = GetFirstNode (&FormSet->StorageListHead); + while (!IsNull (&FormSet->StorageListHead, Link)) { + FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link); + Storage = FormSetStorage->BrowserStorage; + Link = GetNextNode (&FormSet->StorageListHead, Link); + if (BrowserStorage != NULL && BrowserStorage != Storage) { + continue; + } + + if (Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE && + FormSetStorage->ElementCount != 0 && + FormSetStorage->HasCallAltCfg) { + return; + } + } + + // + // Get AltCfg string for each form. + // + Link = GetFirstNode (&Form->ConfigRequestHead); + while (!IsNull (&Form->ConfigRequestHead, Link)) { + ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link); + Link = GetNextNode (&Form->ConfigRequestHead, Link); + + Storage = ConfigInfo->Storage; + if (BrowserStorage != NULL && BrowserStorage != Storage) { + continue; + } + + if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + continue; + } + + // + // 1. Skip if there is no RequestElement + // + if (ConfigInfo->ElementCount == 0) { + continue; + } + + // + // 2. Get value through hii config routine protocol. + // + Status = mHiiConfigRouting->ExtractConfig ( + mHiiConfigRouting, + ConfigInfo->ConfigRequest, + &Progress, + &Result + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // 3. Call ConfigRouting GetAltCfg(ConfigRoute, , Guid, Name, DevicePath, AltCfgId, AltCfgResp) + // Get the default configuration string according to the default ID. + // + Status = mHiiConfigRouting->GetAltConfig ( + mHiiConfigRouting, + Result, + &Storage->Guid, + Storage->Name, + NULL, + &DefaultId, // it can be NULL to get the current setting. + &ConfigResp + ); + FreePool (Result); + if (EFI_ERROR (Status)) { + continue; + } + + ConfigInfo->ConfigAltResp = ConfigResp; + } +} + +/** + Clean AltCfg string for current form. + + @param Form Form data structure. + +**/ +VOID +CleanAltCfgForForm ( + IN FORM_BROWSER_FORM *Form + ) +{ + LIST_ENTRY *Link; + FORM_BROWSER_CONFIG_REQUEST *ConfigInfo; + + Link = GetFirstNode (&Form->ConfigRequestHead); + while (!IsNull (&Form->ConfigRequestHead, Link)) { + ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link); + Link = GetNextNode (&Form->ConfigRequestHead, Link); + + if (ConfigInfo->ConfigAltResp != NULL) { + FreePool (ConfigInfo->ConfigAltResp); + ConfigInfo->ConfigAltResp = NULL; + } + } +} + +/** + Get AltCfg string for current formset. + + @param FormSet Form data structure. + @param DefaultId The Class of the default. + @param BrowserStorage The input request storage for the questions. + +**/ +VOID +ExtractAltCfgForFormSet ( + IN FORM_BROWSER_FORMSET *FormSet, + IN UINT16 DefaultId, + IN BROWSER_STORAGE *BrowserStorage + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + CHAR16 *ConfigResp; + CHAR16 *Progress; + CHAR16 *Result; + BROWSER_STORAGE *Storage; + FORMSET_STORAGE *FormSetStorage; + + Link = GetFirstNode (&FormSet->StorageListHead); + while (!IsNull (&FormSet->StorageListHead, Link)) { + FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link); + Storage = FormSetStorage->BrowserStorage; + Link = GetNextNode (&FormSet->StorageListHead, Link); + + if (BrowserStorage != NULL && BrowserStorage != Storage) { + continue; + } + + if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + continue; } - break; - case EFI_IFR_ONE_OF_OP: // - // Take first oneof option as oneof's default value + // 1. Skip if there is no RequestElement // - if (ValueToOption (Question, HiiValue) == NULL) { - Link = GetFirstNode (&Question->OptionListHead); - while (!IsNull (&Question->OptionListHead, Link)) { - Option = QUESTION_OPTION_FROM_LINK (Link); - Link = GetNextNode (&Question->OptionListHead, Link); + if (FormSetStorage->ElementCount == 0) { + continue; + } - if ((Option->SuppressExpression != NULL) && - EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { - continue; - } + FormSetStorage->HasCallAltCfg = TRUE; - CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE)); - Status = EFI_SUCCESS; - break; - } + // + // 2. Get value through hii config routine protocol. + // + Status = mHiiConfigRouting->ExtractConfig ( + mHiiConfigRouting, + FormSetStorage->ConfigRequest, + &Progress, + &Result + ); + if (EFI_ERROR (Status)) { + continue; } - break; - case EFI_IFR_ORDERED_LIST_OP: // - // Take option sequence in IFR as ordered list's default value + // 3. Call ConfigRouting GetAltCfg(ConfigRoute, , Guid, Name, DevicePath, AltCfgId, AltCfgResp) + // Get the default configuration string according to the default ID. // - Index = 0; - Link = GetFirstNode (&Question->OptionListHead); - while (!IsNull (&Question->OptionListHead, Link)) { - Status = EFI_SUCCESS; - Option = QUESTION_OPTION_FROM_LINK (Link); - Link = GetNextNode (&Question->OptionListHead, Link); - - if ((Option->SuppressExpression != NULL) && - EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { - continue; - } - - SetArrayData (Question->BufferValue, Question->ValueType, Index, Option->Value.Value.u64); + Status = mHiiConfigRouting->GetAltConfig ( + mHiiConfigRouting, + Result, + &Storage->Guid, + Storage->Name, + NULL, + &DefaultId, // it can be NULL to get the current setting. + &ConfigResp + ); - Index++; - if (Index >= Question->MaxContainers) { - break; - } + FreePool (Result); + if (EFI_ERROR (Status)) { + continue; } - break; - default: - break; + FormSetStorage->ConfigAltResp = ConfigResp; } - return Status; } +/** + Clean AltCfg string for current formset. + + @param FormSet Form data structure. + +**/ +VOID +CleanAltCfgForFormSet ( + IN FORM_BROWSER_FORMSET *FormSet + ) +{ + LIST_ENTRY *Link; + FORMSET_STORAGE *FormSetStorage; + + Link = GetFirstNode (&FormSet->StorageListHead); + while (!IsNull (&FormSet->StorageListHead, Link)) { + FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link); + Link = GetNextNode (&FormSet->StorageListHead, Link); + + if (FormSetStorage->ConfigAltResp != NULL) { + FreePool (FormSetStorage->ConfigAltResp); + FormSetStorage->ConfigAltResp = NULL; + } + + FormSetStorage->HasCallAltCfg = FALSE; + } +} /** Reset Questions to their initial value or default value in a Form, Formset or System. - GetDefaultValueScope parameter decides which questions will reset + GetDefaultValueScope parameter decides which questions will reset to its default value. @param FormSet FormSet data structure. @@ -3394,6 +4789,7 @@ GetQuestionDefault ( @param RetrieveValueFirst Whether call the retrieve call back to get the initial value before get default value. + @param SkipGetAltCfg Whether skip the get altcfg string process. @retval EFI_SUCCESS The function completed successfully. @retval EFI_UNSUPPORTED Unsupport SettingScope. @@ -3407,7 +4803,8 @@ ExtractDefault ( IN BROWSER_SETTING_SCOPE SettingScope, IN BROWSER_GET_DEFAULT_VALUE GetDefaultValueScope, IN BROWSER_STORAGE *Storage OPTIONAL, - IN BOOLEAN RetrieveValueFirst + IN BOOLEAN RetrieveValueFirst, + IN BOOLEAN SkipGetAltCfg ) { EFI_STATUS Status; @@ -3415,6 +4812,7 @@ ExtractDefault ( LIST_ENTRY *Link; FORM_BROWSER_STATEMENT *Question; FORM_BROWSER_FORMSET *LocalFormSet; + FORM_BROWSER_FORMSET *OldFormSet; Status = EFI_SUCCESS; @@ -3428,8 +4826,15 @@ ExtractDefault ( if (GetDefaultValueScope == GetDefaultForStorage && Storage == NULL) { return EFI_UNSUPPORTED; } - + if (SettingScope == FormLevel) { + // + // Prepare the AltCfg String for form. + // + if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) { + ExtractAltCfgForForm (FormSet, Form, DefaultId, Storage); + } + // // Extract Form default // @@ -3465,7 +4870,7 @@ ExtractDefault ( // // Call the Retrieve call back to get the initial question value. // - Status = ProcessRetrieveForQuestion(FormSet->ConfigAccess, Question); + Status = ProcessRetrieveForQuestion(FormSet->ConfigAccess, Question, FormSet); } // @@ -3486,19 +4891,42 @@ ExtractDefault ( SetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer); } } + + // + // Clean the AltCfg String. + // + if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) { + CleanAltCfgForForm(Form); + } } else if (SettingScope == FormSetLevel) { + // + // Prepare the AltCfg String for formset. + // + if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) { + ExtractAltCfgForFormSet (FormSet, DefaultId, Storage); + } + FormLink = GetFirstNode (&FormSet->FormListHead); while (!IsNull (&FormSet->FormListHead, FormLink)) { Form = FORM_BROWSER_FORM_FROM_LINK (FormLink); - ExtractDefault (FormSet, Form, DefaultId, FormLevel, GetDefaultValueScope, Storage, RetrieveValueFirst); + ExtractDefault (FormSet, Form, DefaultId, FormLevel, GetDefaultValueScope, Storage, RetrieveValueFirst, SkipGetAltCfg); FormLink = GetNextNode (&FormSet->FormListHead, FormLink); } + + // + // Clean the AltCfg String. + // + if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) { + CleanAltCfgForFormSet (FormSet); + } } else if (SettingScope == SystemLevel) { // // Preload all Hii formset. // LoadAllHiiFormset(); - + + OldFormSet = mSystemLevelFormSet; + // // Set Default Value for each FormSet in the maintain list. // @@ -3509,8 +4937,13 @@ ExtractDefault ( if (!ValidateFormSet(LocalFormSet)) { continue; } - ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst); + + mSystemLevelFormSet = LocalFormSet; + + ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst, SkipGetAltCfg); } + + mSystemLevelFormSet = OldFormSet; } return EFI_SUCCESS; @@ -3539,6 +4972,8 @@ IsQuestionValueChanged ( { EFI_HII_VALUE BackUpValue; CHAR8 *BackUpBuffer; + EFI_HII_VALUE BackUpValue2; + CHAR8 *BackUpBuffer2; EFI_STATUS Status; BOOLEAN ValueChanged; UINTN BufferWidth; @@ -3551,6 +4986,7 @@ IsQuestionValueChanged ( } BackUpBuffer = NULL; + BackUpBuffer2 = NULL; ValueChanged = FALSE; switch (Question->Operand) { @@ -3573,28 +5009,66 @@ IsQuestionValueChanged ( } CopyMem (&BackUpValue, &Question->HiiValue, sizeof (EFI_HII_VALUE)); - Status = GetQuestionValue (FormSet, Form, Question, GetValueFrom); - ASSERT_EFI_ERROR(Status); + if (GetValueFrom == GetSetValueWithBothBuffer) { + Status = GetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer); + ASSERT_EFI_ERROR(Status); + + switch (Question->Operand) { + case EFI_IFR_ORDERED_LIST_OP: + BufferWidth = Question->StorageWidth; + BackUpBuffer2 = AllocateCopyPool (BufferWidth, Question->BufferValue); + ASSERT (BackUpBuffer2 != NULL); + break; + + case EFI_IFR_STRING_OP: + case EFI_IFR_PASSWORD_OP: + BufferWidth = (UINTN) Question->Maximum * sizeof (CHAR16); + BackUpBuffer2 = AllocateCopyPool (BufferWidth, Question->BufferValue); + ASSERT (BackUpBuffer2 != NULL); + break; + + default: + BufferWidth = 0; + break; + } + CopyMem (&BackUpValue2, &Question->HiiValue, sizeof (EFI_HII_VALUE)); + + Status = GetQuestionValue (FormSet, Form, Question, GetSetValueWithBuffer); + ASSERT_EFI_ERROR(Status); + + if (CompareMem (&BackUpValue2, &Question->HiiValue, sizeof (EFI_HII_VALUE)) != 0 || + CompareMem (BackUpBuffer2, Question->BufferValue, BufferWidth) != 0) { + ValueChanged = TRUE; + } + } else { + Status = GetQuestionValue (FormSet, Form, Question, GetValueFrom); + ASSERT_EFI_ERROR(Status); - if (CompareMem (&BackUpValue, &Question->HiiValue, sizeof (EFI_HII_VALUE)) != 0 || - CompareMem (BackUpBuffer, Question->BufferValue, BufferWidth) != 0) { - ValueChanged = TRUE; + if (CompareMem (&BackUpValue, &Question->HiiValue, sizeof (EFI_HII_VALUE)) != 0 || + CompareMem (BackUpBuffer, Question->BufferValue, BufferWidth) != 0) { + ValueChanged = TRUE; + } } CopyMem (&Question->HiiValue, &BackUpValue, sizeof (EFI_HII_VALUE)); - CopyMem (Question->BufferValue, BackUpBuffer, BufferWidth); - if (BackUpBuffer != NULL) { + CopyMem (Question->BufferValue, BackUpBuffer, BufferWidth); FreePool (BackUpBuffer); } + if (BackUpBuffer2 != NULL) { + FreePool (BackUpBuffer2); + } + + Question->ValueChanged = ValueChanged; + return ValueChanged; } /** Initialize Question's Edit copy from Storage. - @param Selection Selection contains the information about + @param Selection Selection contains the information about the Selection, form and formset to be displayed. Selection action may be updated in retrieve callback. If Selection is NULL, only initialize Question value. @@ -3614,9 +5088,7 @@ LoadFormConfig ( EFI_STATUS Status; LIST_ENTRY *Link; FORM_BROWSER_STATEMENT *Question; - UINT8 *BufferValue; - UINTN StorageWidth; - + Link = GetFirstNode (&Form->StatementListHead); while (!IsNull (&Form->StatementListHead, Link)) { Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); @@ -3637,42 +5109,6 @@ LoadFormConfig ( HiiSetString (FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL); } - // - // Call the Retrieve call back function for all questions. - // - if ((FormSet->ConfigAccess != NULL) && (Selection != NULL) && - ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK)) { - // - // Check QuestionValue does exist. - // - StorageWidth = Question->StorageWidth; - if (Question->BufferValue != NULL) { - BufferValue = Question->BufferValue; - } else { - BufferValue = (UINT8 *) &Question->HiiValue.Value; - } - - // - // For efivarstore storage, initial question value first. - // - if ((Question->Storage != NULL) && (Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) { - Status = gRT->GetVariable ( - Question->VariableName, - &Question->Storage->Guid, - NULL, - &StorageWidth, - BufferValue - ); - } - - Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE); - } - - // - // Update Question Value changed flag. - // - Question->ValueChanged = IsQuestionValueChanged(FormSet, Form, Question, GetSetValueWithBuffer); - Link = GetNextNode (&Form->StatementListHead, Link); } @@ -3682,7 +5118,7 @@ LoadFormConfig ( /** Initialize Question's Edit copy from Storage for the whole Formset. - @param Selection Selection contains the information about + @param Selection Selection contains the information about the Selection, form and formset to be displayed. Selection action may be updated in retrieve callback. If Selection is NULL, only initialize Question value. @@ -3718,7 +5154,7 @@ LoadFormSetConfig ( // // Finished question initialization. - // + // FormSet->QuestionInited = TRUE; return EFI_SUCCESS; @@ -3754,20 +5190,20 @@ RemoveElement ( DestStr = NewStr; NewStr += StrLen (RequestElement); CopyMem (DestStr, NewStr, StrSize (NewStr)); - - Storage->SpareStrLen += StrLen (RequestElement); + + Storage->SpareStrLen += StrLen (RequestElement); } /** Adjust config request in storage, remove the request elements existed in the input ConfigRequest. - @param Storage Pointer to the browser storage. + @param Storage Pointer to the formset storage. @param ConfigRequest The pointer to the Request element. **/ VOID RemoveConfigRequest ( - BROWSER_STORAGE *Storage, + FORMSET_STORAGE *Storage, CHAR16 *ConfigRequest ) { @@ -3782,7 +5218,7 @@ RemoveConfigRequest ( return; } - if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) { // // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage // @@ -3797,10 +5233,10 @@ RemoveConfigRequest ( // // Find SearchKey storage // - if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) { RequestElement = StrStr (ConfigRequest, L"PATH"); ASSERT (RequestElement != NULL); - RequestElement = StrStr (RequestElement, SearchKey); + RequestElement = StrStr (RequestElement, SearchKey); } else { RequestElement = StrStr (ConfigRequest, SearchKey); } @@ -3821,7 +5257,7 @@ RemoveConfigRequest ( *NextRequestElement = L'\0'; } - RemoveElement (Storage, RequestElement); + RemoveElement (Storage->BrowserStorage, RequestElement); if (NextRequestElement != NULL) { // @@ -3836,10 +5272,10 @@ RemoveConfigRequest ( // // If no request element remain, just remove the ConfigRequest string. // - if (StrCmp (Storage->ConfigRequest, Storage->ConfigHdr) == 0) { - FreePool (Storage->ConfigRequest); - Storage->ConfigRequest = NULL; - Storage->SpareStrLen = 0; + if (StrCmp (Storage->BrowserStorage->ConfigRequest, Storage->ConfigHdr) == 0) { + FreePool (Storage->BrowserStorage->ConfigRequest); + Storage->BrowserStorage->ConfigRequest = NULL; + Storage->BrowserStorage->SpareStrLen = 0; } } @@ -3856,25 +5292,26 @@ CleanBrowserStorage ( { LIST_ENTRY *Link; FORMSET_STORAGE *Storage; - CHAR16 *ConfigRequest; Link = GetFirstNode (&FormSet->StorageListHead); while (!IsNull (&FormSet->StorageListHead, Link)) { Storage = FORMSET_STORAGE_FROM_LINK (Link); Link = GetNextNode (&FormSet->StorageListHead, Link); - if ((Storage->BrowserStorage->Type != EFI_HII_VARSTORE_BUFFER) && - (Storage->BrowserStorage->Type != EFI_HII_VARSTORE_NAME_VALUE) && - (Storage->BrowserStorage->Type != EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { - continue; - } + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { + if (Storage->ConfigRequest == NULL || Storage->BrowserStorage->ConfigRequest == NULL) { + continue; + } - if (Storage->ConfigRequest == NULL || Storage->BrowserStorage->ConfigRequest == NULL) { - continue; + RemoveConfigRequest (Storage, Storage->ConfigRequest); + } else if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_BUFFER || + Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + if (Storage->BrowserStorage->ConfigRequest != NULL) { + FreePool (Storage->BrowserStorage->ConfigRequest); + Storage->BrowserStorage->ConfigRequest = NULL; + } + Storage->BrowserStorage->Initialized = FALSE; } - - ConfigRequest = FormSet->QuestionInited ? Storage->ConfigRequest : Storage->ConfigElements; - RemoveConfigRequest (Storage->BrowserStorage, ConfigRequest); } } @@ -3888,7 +5325,7 @@ CleanBrowserStorage ( @retval FALSE The Element not in the configReqeust String. **/ -BOOLEAN +BOOLEAN ElementValidation ( BROWSER_STORAGE *BrowserStorage, CHAR16 *RequestElement @@ -3915,8 +5352,11 @@ AppendConfigRequest ( CHAR16 *NewStr; UINTN StringSize; UINTN StrLength; + UINTN MaxLen; StrLength = StrLen (RequestElement); + StringSize = (*ConfigRequest != NULL) ? StrSize (*ConfigRequest) : sizeof (CHAR16); + MaxLen = StringSize / sizeof (CHAR16) + *SpareStrLen; // // Append to @@ -3925,8 +5365,8 @@ AppendConfigRequest ( // // Old String buffer is not sufficient for RequestElement, allocate a new one // - StringSize = (*ConfigRequest != NULL) ? StrSize (*ConfigRequest) : sizeof (CHAR16); - NewStr = AllocateZeroPool (StringSize + CONFIG_REQUEST_STRING_INCREMENTAL * sizeof (CHAR16)); + MaxLen = StringSize / sizeof (CHAR16) + CONFIG_REQUEST_STRING_INCREMENTAL; + NewStr = AllocateZeroPool (MaxLen * sizeof (CHAR16)); ASSERT (NewStr != NULL); if (*ConfigRequest != NULL) { @@ -3937,7 +5377,7 @@ AppendConfigRequest ( *SpareStrLen = CONFIG_REQUEST_STRING_INCREMENTAL; } - StrCat (*ConfigRequest, RequestElement); + StrCatS (*ConfigRequest, MaxLen, RequestElement); *SpareStrLen -= StrLength; } @@ -3945,37 +5385,44 @@ AppendConfigRequest ( Adjust the config request info, remove the request elements which already in AllConfigRequest string. @param Storage Form set Storage. + @param Request The input request string. + @param RespString Whether the input is ConfigRequest or ConfigResp format. @retval TRUE Has element not covered by current used elements, need to continue to call ExtractConfig @retval FALSE All elements covered by current used elements. **/ -BOOLEAN +BOOLEAN ConfigRequestAdjust ( - IN FORMSET_STORAGE *Storage + IN BROWSER_STORAGE *Storage, + IN CHAR16 *Request, + IN BOOLEAN RespString ) { CHAR16 *RequestElement; CHAR16 *NextRequestElement; - CHAR16 *RetBuf; - UINTN SpareBufLen; + CHAR16 *NextElementBakup; CHAR16 *SearchKey; + CHAR16 *ValueKey; BOOLEAN RetVal; + CHAR16 *ConfigRequest; - SpareBufLen = 0; - RetBuf = NULL; RetVal = FALSE; + NextElementBakup = NULL; + ValueKey = NULL; - if (Storage->BrowserStorage->ConfigRequest == NULL) { - Storage->BrowserStorage->ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigRequest), Storage->ConfigRequest); - if (Storage->ConfigElements != NULL) { - FreePool (Storage->ConfigElements); - } - Storage->ConfigElements = AllocateCopyPool (StrSize (Storage->ConfigRequest), Storage->ConfigRequest); + if (Request != NULL) { + ConfigRequest = Request; + } else { + ConfigRequest = Storage->ConfigRequest; + } + + if (Storage->ConfigRequest == NULL) { + Storage->ConfigRequest = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest); return TRUE; } - if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { // // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage // @@ -3984,220 +5431,76 @@ ConfigRequestAdjust ( // // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage // - SearchKey = L"&OFFSET"; - } - - // - // Prepare the config header. - // - RetBuf = AllocateCopyPool(StrSize (Storage->BrowserStorage->ConfigHdr), Storage->BrowserStorage->ConfigHdr); - ASSERT (RetBuf != NULL); - - // - // Find SearchKey storage - // - if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) { - RequestElement = StrStr (Storage->ConfigRequest, L"PATH"); - ASSERT (RequestElement != NULL); - RequestElement = StrStr (RequestElement, SearchKey); - } else { - RequestElement = StrStr (Storage->ConfigRequest, SearchKey); - } - - while (RequestElement != NULL) { - // - // +1 to avoid find header itself. - // - NextRequestElement = StrStr (RequestElement + 1, SearchKey); - - // - // The last Request element in configRequest string. - // - if (NextRequestElement != NULL) { - // - // Replace "&" with '\0'. - // - *NextRequestElement = L'\0'; - } - - if (!ElementValidation (Storage->BrowserStorage, RequestElement)) { - // - // Add this element to the Storage->BrowserStorage->AllRequestElement. - // - AppendConfigRequest(&Storage->BrowserStorage->ConfigRequest, &Storage->BrowserStorage->SpareStrLen, RequestElement); - AppendConfigRequest (&RetBuf, &SpareBufLen, RequestElement); - RetVal = TRUE; - } - - if (NextRequestElement != NULL) { - // - // Restore '&' with '\0' for later used. - // - *NextRequestElement = L'&'; - } - - RequestElement = NextRequestElement; - } - - if (RetVal) { - if (Storage->ConfigElements != NULL) { - FreePool (Storage->ConfigElements); - } - Storage->ConfigElements = RetBuf; - } else { - FreePool (RetBuf); - } - - return RetVal; -} - -/** - - Base on ConfigRequest info to get default value for current formset. - - ConfigRequest info include the info about which questions in current formset need to - get default value. This function only get these questions default value. - - @param FormSet FormSet data structure. - @param Storage Storage need to update value. - @param ConfigRequest The config request string. - -**/ -VOID -GetDefaultForFormset ( - IN FORM_BROWSER_FORMSET *FormSet, - IN BROWSER_STORAGE *Storage, - IN CHAR16 *ConfigRequest - ) -{ - UINT8 *BackUpBuf; - UINTN BufferSize; - LIST_ENTRY BackUpList; - NAME_VALUE_NODE *Node; - LIST_ENTRY *Link; - LIST_ENTRY *NodeLink; - NAME_VALUE_NODE *TmpNode; - EFI_STATUS Status; - EFI_STRING Progress; - EFI_STRING Result; - - BackUpBuf = NULL; - InitializeListHead(&BackUpList); - - // - // Back update the edit buffer. - // - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || - (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { - BackUpBuf = AllocateCopyPool (Storage->Size, Storage->EditBuffer); - ASSERT (BackUpBuf != NULL); - } else if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { - Link = GetFirstNode (&Storage->NameValueListHead); - while (!IsNull (&Storage->NameValueListHead, Link)) { - Node = NAME_VALUE_NODE_FROM_LINK (Link); - Link = GetNextNode (&Storage->NameValueListHead, Link); - - // - // Only back Node belong to this formset. - // - if (StrStr (Storage->ConfigRequest, Node->Name) == NULL) { - continue; - } - - TmpNode = AllocateCopyPool (sizeof (NAME_VALUE_NODE), Node); - TmpNode->Name = AllocateCopyPool (StrSize(Node->Name) * sizeof (CHAR16), Node->Name); - TmpNode->EditValue = AllocateCopyPool (StrSize(Node->EditValue) * sizeof (CHAR16), Node->EditValue); - - InsertTailList(&BackUpList, &TmpNode->Link); - } - } - - // - // Get default value. - // - ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage, TRUE); - - // - // Update the question value based on the input ConfigRequest. - // - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || - (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { - ASSERT (BackUpBuf != NULL); - BufferSize = Storage->Size; - Status = mHiiConfigRouting->BlockToConfig( - mHiiConfigRouting, - ConfigRequest, - Storage->EditBuffer, - BufferSize, - &Result, - &Progress - ); - ASSERT_EFI_ERROR (Status); - - Status = mHiiConfigRouting->ConfigToBlock ( - mHiiConfigRouting, - Result, - BackUpBuf, - &BufferSize, - &Progress - ); - ASSERT_EFI_ERROR (Status); - - if (Result != NULL) { - FreePool (Result); - } - - CopyMem (Storage->EditBuffer, BackUpBuf, Storage->Size); - FreePool (BackUpBuf); - } else if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { - // - // Update question value, only element in ConfigReqeust will be update. - // - Link = GetFirstNode (&BackUpList); - while (!IsNull (&BackUpList, Link)) { - Node = NAME_VALUE_NODE_FROM_LINK (Link); - Link = GetNextNode (&BackUpList, Link); + SearchKey = L"&OFFSET"; + ValueKey = L"&VALUE"; + } - if (StrStr (ConfigRequest, Node->Name) != NULL) { - continue; - } + // + // Find SearchKey storage + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + RequestElement = StrStr (ConfigRequest, L"PATH"); + ASSERT (RequestElement != NULL); + RequestElement = StrStr (RequestElement, SearchKey); + } else { + RequestElement = StrStr (ConfigRequest, SearchKey); + } - NodeLink = GetFirstNode (&Storage->NameValueListHead); - while (!IsNull (&Storage->NameValueListHead, NodeLink)) { - TmpNode = NAME_VALUE_NODE_FROM_LINK (NodeLink); - NodeLink = GetNextNode (&Storage->NameValueListHead, NodeLink); - - if (StrCmp (Node->Name, TmpNode->Name) != 0) { - continue; - } + while (RequestElement != NULL) { - FreePool (TmpNode->EditValue); - TmpNode->EditValue = AllocateCopyPool (StrSize(Node->EditValue) * sizeof (CHAR16), Node->EditValue); + // + // +1 to avoid find header itself. + // + NextRequestElement = StrStr (RequestElement + 1, SearchKey); - RemoveEntryList (&Node->Link); - FreePool (Node->EditValue); - FreePool (Node->Name); - FreePool (Node); + // + // The last Request element in configRequest string. + // + if (NextRequestElement != NULL) { + if (RespString && (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { + NextElementBakup = NextRequestElement; + NextRequestElement = StrStr (RequestElement, ValueKey); + ASSERT (NextRequestElement != NULL); + } + // + // Replace "&" with '\0'. + // + *NextRequestElement = L'\0'; + } else { + if (RespString && (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { + NextElementBakup = NextRequestElement; + NextRequestElement = StrStr (RequestElement, ValueKey); + ASSERT (NextRequestElement != NULL); + // + // Replace "&" with '\0'. + // + *NextRequestElement = L'\0'; } } - // - // Restore the Name/Value node. - // - Link = GetFirstNode (&BackUpList); - while (!IsNull (&BackUpList, Link)) { - Node = NAME_VALUE_NODE_FROM_LINK (Link); - Link = GetNextNode (&BackUpList, Link); - + if (!ElementValidation (Storage, RequestElement)) { + // + // Add this element to the Storage->BrowserStorage->AllRequestElement. + // + AppendConfigRequest(&Storage->ConfigRequest, &Storage->SpareStrLen, RequestElement); + RetVal = TRUE; + } + + if (NextRequestElement != NULL) { // - // Free this node. + // Restore '&' with '\0' for later used. // - RemoveEntryList (&Node->Link); - FreePool (Node->EditValue); - FreePool (Node->Name); - FreePool (Node); + *NextRequestElement = L'&'; + } + + if (RespString && (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) { + RequestElement = NextElementBakup; + } else { + RequestElement = NextRequestElement; } } + + return RetVal; } /** @@ -4217,95 +5520,192 @@ LoadStorage ( EFI_STRING Progress; EFI_STRING Result; CHAR16 *StrPtr; + EFI_STRING ConfigRequest; + UINTN StrLen; + + ConfigRequest = NULL; switch (Storage->BrowserStorage->Type) { case EFI_HII_VARSTORE_EFI_VARIABLE: return; case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER: - if (Storage->BrowserStorage->ReferenceCount > 1) { - ConfigRequestAdjust(Storage); + if (Storage->BrowserStorage->ConfigRequest != NULL) { + ConfigRequestAdjust(Storage->BrowserStorage, Storage->ConfigRequest, FALSE); return; } - - Status = gRT->GetVariable ( - Storage->BrowserStorage->Name, - &Storage->BrowserStorage->Guid, - NULL, - (UINTN*)&Storage->BrowserStorage->Size, - Storage->BrowserStorage->EditBuffer - ); - // - // If get variable fail, extract default from IFR binary - // - if (EFI_ERROR (Status)) { - ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE); - } - - Storage->BrowserStorage->ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigRequest), Storage->ConfigRequest); - // - // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer. - // - SynchronizeStorage(FormSet, Storage->BrowserStorage, NULL, TRUE); break; case EFI_HII_VARSTORE_BUFFER: case EFI_HII_VARSTORE_NAME_VALUE: // - // Skip if there is no RequestElement + // Skip if there is no RequestElement. // if (Storage->ElementCount == 0) { return; } // - // Adjust the ConfigRequest string, only the field not saved in BrowserStorage->AllConfig - // will used to call ExtractConfig. - // If not elements need to udpate, return. + // Just update the ConfigRequest, if storage already initialized. // - if (!ConfigRequestAdjust(Storage)) { + if (Storage->BrowserStorage->Initialized) { + ConfigRequestAdjust(Storage->BrowserStorage, Storage->ConfigRequest, FALSE); return; } - ASSERT (Storage->ConfigElements != NULL); - Status = EFI_NOT_FOUND; - if (FormSet->ConfigAccess != NULL) { - // - // Request current settings from Configuration Driver - // - Status = FormSet->ConfigAccess->ExtractConfig ( - FormSet->ConfigAccess, - Storage->ConfigElements, - &Progress, - &Result - ); - - if (!EFI_ERROR (Status)) { - // - // Convert Result from to - // - StrPtr = StrStr (Result, L"&GUID="); - if (StrPtr != NULL) { - *StrPtr = L'\0'; - } - - Status = ConfigRespToStorage (Storage->BrowserStorage, Result); - FreePool (Result); - } - } + Storage->BrowserStorage->Initialized = TRUE; + break; - if (EFI_ERROR (Status)) { - // - // Base on the configRequest string to get default value. - // - GetDefaultForFormset (FormSet, Storage->BrowserStorage, Storage->ConfigElements); + default: + return; + } + + if (Storage->BrowserStorage->Type != EFI_HII_VARSTORE_NAME_VALUE) { + // + // Create the config request string to get all fields for this storage. + // Allocate and fill a buffer large enough to hold the template + // followed by "&OFFSET=0&WIDTH=WWWW"followed by a Null-terminator + // + StrLen = StrSize (Storage->ConfigHdr) + 20 * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (StrLen); + ASSERT (ConfigRequest != NULL); + UnicodeSPrint ( + ConfigRequest, + StrLen, + L"%s&OFFSET=0&WIDTH=%04x", + Storage->ConfigHdr, + Storage->BrowserStorage->Size); + } else { + ConfigRequest = Storage->ConfigRequest; + } + + // + // Request current settings from Configuration Driver + // + Status = mHiiConfigRouting->ExtractConfig ( + mHiiConfigRouting, + ConfigRequest, + &Progress, + &Result + ); + + // + // If get value fail, extract default from IFR binary + // + if (EFI_ERROR (Status)) { + ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE, TRUE); + } else { + // + // Convert Result from to + // + StrPtr = StrStr (Result, L"&GUID="); + if (StrPtr != NULL) { + *StrPtr = L'\0'; + } + + Status = ConfigRespToStorage (Storage->BrowserStorage, Result); + FreePool (Result); + } + + Storage->BrowserStorage->ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigRequest), Storage->ConfigRequest); + + // + // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer. + // + SynchronizeStorage(Storage->BrowserStorage, NULL, TRUE); + + if (Storage->BrowserStorage->Type != EFI_HII_VARSTORE_NAME_VALUE) { + if (ConfigRequest != NULL) { + FreePool (ConfigRequest); + } + } +} + +/** + Get Value changed status from old question. + + @param NewFormSet FormSet data structure. + @param OldQuestion Old question which has value changed. + +**/ +VOID +SyncStatusForQuestion ( + IN OUT FORM_BROWSER_FORMSET *NewFormSet, + IN FORM_BROWSER_STATEMENT *OldQuestion + ) +{ + LIST_ENTRY *Link; + LIST_ENTRY *QuestionLink; + FORM_BROWSER_FORM *Form; + FORM_BROWSER_STATEMENT *Question; + + // + // For each form in one formset. + // + Link = GetFirstNode (&NewFormSet->FormListHead); + while (!IsNull (&NewFormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&NewFormSet->FormListHead, Link); + + // + // for each question in one form. + // + QuestionLink = GetFirstNode (&Form->StatementListHead); + while (!IsNull (&Form->StatementListHead, QuestionLink)) { + Question = FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink); + QuestionLink = GetNextNode (&Form->StatementListHead, QuestionLink); + + if (Question->QuestionId == OldQuestion->QuestionId) { + Question->ValueChanged = TRUE; + return; } + } + } +} - SynchronizeStorage(FormSet, Storage->BrowserStorage, Storage->ConfigElements, TRUE); - break; +/** + Get Value changed status from old formset. - default: - break; + @param NewFormSet FormSet data structure. + @param OldFormSet FormSet data structure. + +**/ +VOID +SyncStatusForFormSet ( + IN OUT FORM_BROWSER_FORMSET *NewFormSet, + IN FORM_BROWSER_FORMSET *OldFormSet + ) +{ + LIST_ENTRY *Link; + LIST_ENTRY *QuestionLink; + FORM_BROWSER_FORM *Form; + FORM_BROWSER_STATEMENT *Question; + + // + // For each form in one formset. + // + Link = GetFirstNode (&OldFormSet->FormListHead); + while (!IsNull (&OldFormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&OldFormSet->FormListHead, Link); + + // + // for each question in one form. + // + QuestionLink = GetFirstNode (&Form->StatementListHead); + while (!IsNull (&Form->StatementListHead, QuestionLink)) { + Question = FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink); + QuestionLink = GetNextNode (&Form->StatementListHead, QuestionLink); + + if (!Question->ValueChanged) { + continue; + } + + // + // Find the same question in new formset and update the value changed flag. + // + SyncStatusForQuestion (NewFormSet, Question); + } } } @@ -4324,10 +5724,22 @@ InitializeCurrentSetting ( FORMSET_STORAGE *Storage; FORM_BROWSER_FORMSET *OldFormSet; + // + // Try to find pre FormSet in the maintain backup list. + // If old formset != NULL, destroy this formset. Add new formset to gBrowserFormSetList. + // + OldFormSet = GetFormSetFromHiiHandle (FormSet->HiiHandle); + if (OldFormSet != NULL) { + SyncStatusForFormSet (FormSet, OldFormSet); + RemoveEntryList (&OldFormSet->Link); + DestroyFormSet (OldFormSet); + } + InsertTailList (&gBrowserFormSetList, &FormSet->Link); + // // Extract default from IFR binary for no storage questions. - // - ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForNoStorage, NULL, TRUE); + // + ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForNoStorage, NULL, TRUE, FALSE); // // Request current settings from Configuration Driver @@ -4340,17 +5752,6 @@ InitializeCurrentSetting ( Link = GetNextNode (&FormSet->StorageListHead, Link); } - - // - // Try to find pre FormSet in the maintain backup list. - // If old formset != NULL, destroy this formset. Add new formset to gBrowserFormSetList. - // - OldFormSet = GetFormSetFromHiiHandle (FormSet->HiiHandle); - if (OldFormSet != NULL) { - RemoveEntryList (&OldFormSet->Link); - DestroyFormSet (OldFormSet); - } - InsertTailList (&gBrowserFormSetList, &FormSet->Link); } @@ -4450,7 +5851,7 @@ GetIfrBinaryData ( // // Try to compare against formset GUID // - if (CompareGuid (FormSetGuid, &gZeroGuid) || + if (IsZeroGuid (ComparingGuid) || CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) { break; } @@ -4589,7 +5990,7 @@ InitializeFormSet ( /** - Save globals used by previous call to SendForm(). SendForm() may be called from + Save globals used by previous call to SendForm(). SendForm() may be called from HiiConfigAccess.Callback(), this will cause SendForm() be reentried. So, save globals of previous call to SendForm() and restore them upon exit. @@ -4599,8 +6000,9 @@ SaveBrowserContext ( VOID ) { - BROWSER_CONTEXT *Context; - FORM_ENTRY_INFO *MenuList; + BROWSER_CONTEXT *Context; + FORM_ENTRY_INFO *MenuList; + FORM_BROWSER_FORMSET *FormSet; gBrowserContextCount++; if (gBrowserContextCount == 1) { @@ -4619,11 +6021,17 @@ SaveBrowserContext ( // Save FormBrowser context // Context->Selection = gCurrentSelection; - Context->ResetRequired = gResetRequired; + Context->ResetRequired = gResetRequiredFormLevel; + Context->FlagReconnect = gFlagReconnect; + Context->CallbackReconnect = gCallbackReconnect; Context->ExitRequired = gExitRequired; Context->HiiHandle = mCurrentHiiHandle; Context->FormId = mCurrentFormId; CopyGuid (&Context->FormSetGuid, &mCurrentFormSetGuid); + Context->SystemLevelFormSet = mSystemLevelFormSet; + Context->CurFakeQestId = mCurFakeQestId; + Context->HiiPackageListUpdated = mHiiPackageListUpdated; + Context->FinishRetrieveCall = mFinishRetrieveCall; // // Save the menu history data. @@ -4636,6 +6044,17 @@ SaveBrowserContext ( InsertTailList(&Context->FormHistoryList, &MenuList->Link); } + // + // Save formset list. + // + InitializeListHead(&Context->FormSetList); + while (!IsListEmpty (&gBrowserFormSetList)) { + FormSet = FORM_BROWSER_FORMSET_FROM_LINK (gBrowserFormSetList.ForwardLink); + RemoveEntryList (&FormSet->Link); + + InsertTailList(&Context->FormSetList, &FormSet->Link); + } + // // Insert to FormBrowser context list // @@ -4654,7 +6073,8 @@ RestoreBrowserContext ( { LIST_ENTRY *Link; BROWSER_CONTEXT *Context; - FORM_ENTRY_INFO *MenuList; + FORM_ENTRY_INFO *MenuList; + FORM_BROWSER_FORMSET *FormSet; ASSERT (gBrowserContextCount != 0); gBrowserContextCount--; @@ -4674,11 +6094,17 @@ RestoreBrowserContext ( // Restore FormBrowser context // gCurrentSelection = Context->Selection; - gResetRequired = Context->ResetRequired; + gResetRequiredFormLevel = Context->ResetRequired; + gFlagReconnect = Context->FlagReconnect; + gCallbackReconnect = Context->CallbackReconnect; gExitRequired = Context->ExitRequired; mCurrentHiiHandle = Context->HiiHandle; mCurrentFormId = Context->FormId; CopyGuid (&mCurrentFormSetGuid, &Context->FormSetGuid); + mSystemLevelFormSet = Context->SystemLevelFormSet; + mCurFakeQestId = Context->CurFakeQestId; + mHiiPackageListUpdated = Context->HiiPackageListUpdated; + mFinishRetrieveCall = Context->FinishRetrieveCall; // // Restore the menu history data. @@ -4690,6 +6116,16 @@ RestoreBrowserContext ( InsertTailList(&mPrivateData.FormBrowserEx2.FormViewHistoryHead, &MenuList->Link); } + // + // Restore the Formset data. + // + while (!IsListEmpty (&Context->FormSetList)) { + FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Context->FormSetList.ForwardLink); + RemoveEntryList (&FormSet->Link); + + InsertTailList(&gBrowserFormSetList, &FormSet->Link); + } + // // Remove from FormBrowser context list // @@ -4699,13 +6135,13 @@ RestoreBrowserContext ( /** Find the matched FormSet context in the backup maintain list based on HiiHandle. - + @param Handle The Hii Handle. - + @return the found FormSet context. If no found, NULL will return. **/ -FORM_BROWSER_FORMSET * +FORM_BROWSER_FORMSET * GetFormSetFromHiiHandle ( EFI_HII_HANDLE Handle ) @@ -4724,15 +6160,15 @@ GetFormSetFromHiiHandle ( return FormSet; } } - + return NULL; } /** Check whether the input HII handle is the FormSet that is being used. - + @param Handle The Hii Handle. - + @retval TRUE HII handle is being used. @retval FALSE HII handle is not being used. @@ -4766,20 +6202,20 @@ IsHiiHandleInBrowserContext ( } Link = GetNextNode (&gBrowserContextList, Link); } - + return FALSE; } /** - Perform Password check. + Perform Password check. Passwork may be encrypted by driver that requires the specific check. - + @param Form Form where Password Statement is in. @param Statement Password statement @param PasswordString Password string to be checked. It may be NULL. NULL means to restore password. "" string can be used to checked whether old password does exist. - + @return Status Status of Password check. **/ EFI_STATUS @@ -4805,17 +6241,12 @@ PasswordCheck ( return EFI_UNSUPPORTED; } } else { - if (PasswordString == NULL) { - return EFI_SUCCESS; - } - - if (StrnCmp (PasswordString, (CHAR16 *) Question->BufferValue, Question->StorageWidth/sizeof (CHAR16)) == 0) { - return EFI_SUCCESS; - } else { - return EFI_NOT_READY; - } + // + // If a password doesn't have the CALLBACK flag, browser will not handle it. + // + return EFI_UNSUPPORTED; } - + // // Prepare password string in HII database // @@ -4849,7 +6280,7 @@ PasswordCheck ( /** Find the registered HotKey based on KeyData. - + @param[in] KeyData A pointer to a buffer that describes the keystroke information for the hot key. @@ -4871,7 +6302,7 @@ GetHotKeyFromRegisterList ( } Link = GetNextNode (&gBrowserHotKeyList, Link); } - + return NULL; } @@ -4880,11 +6311,11 @@ GetHotKeyFromRegisterList ( All hot keys have the same scope. The mixed hot keys with the different level are not supported. If no scope is set, the default scope will be FormSet level. After all registered hot keys are removed, previous Scope can reset to another level. - - @param[in] Scope Scope level to be set. - + + @param[in] Scope Scope level to be set. + @retval EFI_SUCCESS Scope is set correctly. - @retval EFI_INVALID_PARAMETER Scope is not the valid value specified in BROWSER_SETTING_SCOPE. + @retval EFI_INVALID_PARAMETER Scope is not the valid value specified in BROWSER_SETTING_SCOPE. @retval EFI_UNSPPORTED Scope level is different from current one that the registered hot keys have. **/ @@ -4917,19 +6348,20 @@ SetScope ( Only support hot key that is not printable character (control key, function key, etc.). If the action value is zero, the hot key will be unregistered if it has been registered. If the same hot key has been registered, the new action and help string will override the previous ones. - + @param[in] KeyData A pointer to a buffer that describes the keystroke - information for the hot key. Its type is EFI_INPUT_KEY to + information for the hot key. Its type is EFI_INPUT_KEY to be supported by all ConsoleIn devices. - @param[in] Action Action value that describes what action will be trigged when the hot key is pressed. + @param[in] Action Action value that describes what action will be trigged when the hot key is pressed. @param[in] DefaultId Specifies the type of defaults to retrieve, which is only for DEFAULT action. @param[in] HelpString Help string that describes the hot key information. Its value may be NULL for the unregistered hot key. - + @retval EFI_SUCCESS Hot key is registered or unregistered. @retval EFI_INVALID_PARAMETER KeyData is NULL or HelpString is NULL on register. @retval EFI_NOT_FOUND KeyData is not found to be unregistered. @retval EFI_UNSUPPORTED Key represents a printable character. It is conflicted with Browser. + @retval EFI_ALREADY_STARTED Key already been registered for one hot key. **/ EFI_STATUS EFIAPI @@ -4945,7 +6377,7 @@ RegisterHotKey ( // // Check input parameters. // - if (KeyData == NULL || KeyData->UnicodeChar != CHAR_NULL || + if (KeyData == NULL || KeyData->UnicodeChar != CHAR_NULL || (Action != BROWSER_ACTION_UNREGISTER && HelpString == NULL)) { return EFI_INVALID_PARAMETER; } @@ -4954,14 +6386,14 @@ RegisterHotKey ( // Check whether the input KeyData is in BrowserHotKeyList. // HotKey = GetHotKeyFromRegisterList (KeyData); - + // // Unregister HotKey // if (Action == BROWSER_ACTION_UNREGISTER) { if (HotKey != NULL) { // - // The registered HotKey is found. + // The registered HotKey is found. // Remove it from List, and free its resource. // RemoveEntryList (&HotKey->Link); @@ -4970,25 +6402,24 @@ RegisterHotKey ( return EFI_SUCCESS; } else { // - // The registered HotKey is not found. + // The registered HotKey is not found. // return EFI_NOT_FOUND; } } - + + if (HotKey != NULL) { + return EFI_ALREADY_STARTED; + } + // - // Register HotKey into List. + // Create new Key, and add it into List. // - if (HotKey == NULL) { - // - // Create new Key, and add it into List. - // - HotKey = AllocateZeroPool (sizeof (BROWSER_HOT_KEY)); - ASSERT (HotKey != NULL); - HotKey->Signature = BROWSER_HOT_KEY_SIGNATURE; - HotKey->KeyData = AllocateCopyPool (sizeof (EFI_INPUT_KEY), KeyData); - InsertTailList (&gBrowserHotKeyList, &HotKey->Link); - } + HotKey = AllocateZeroPool (sizeof (BROWSER_HOT_KEY)); + ASSERT (HotKey != NULL); + HotKey->Signature = BROWSER_HOT_KEY_SIGNATURE; + HotKey->KeyData = AllocateCopyPool (sizeof (EFI_INPUT_KEY), KeyData); + InsertTailList (&gBrowserHotKeyList, &HotKey->Link); // // Fill HotKey information. @@ -5004,11 +6435,11 @@ RegisterHotKey ( } /** - Register Exit handler function. - When more than one handler function is registered, the latter one will override the previous one. - When NULL handler is specified, the previous Exit handler will be unregistered. - - @param[in] Handler Pointer to handler function. + Register Exit handler function. + When more than one handler function is registered, the latter one will override the previous one. + When NULL handler is specified, the previous Exit handler will be unregistered. + + @param[in] Handler Pointer to handler function. **/ VOID @@ -5037,21 +6468,27 @@ IsBrowserDataModified ( LIST_ENTRY *Link; FORM_BROWSER_FORMSET *FormSet; - if (gCurrentSelection == NULL) { - return FALSE; - } - switch (gBrowserSettingScope) { case FormLevel: + if (gCurrentSelection == NULL) { + return FALSE; + } return IsNvUpdateRequiredForForm (gCurrentSelection->Form); case FormSetLevel: + if (gCurrentSelection == NULL) { + return FALSE; + } return IsNvUpdateRequiredForFormSet (gCurrentSelection->FormSet); case SystemLevel: Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); + if (!ValidateFormSet(FormSet)) { + continue; + } + if (IsNvUpdateRequiredForFormSet (FormSet)) { return TRUE; } @@ -5074,26 +6511,34 @@ IsBrowserDataModified ( @retval EFI_INVALID_PARAMETER The input action value is invalid. **/ -EFI_STATUS +EFI_STATUS EFIAPI ExecuteAction ( IN UINT32 Action, IN UINT16 DefaultId ) { - EFI_STATUS Status; + EFI_STATUS Status; + FORM_BROWSER_FORMSET *FormSet; + FORM_BROWSER_FORM *Form; - if (gCurrentSelection == NULL) { + if (gBrowserSettingScope < SystemLevel && gCurrentSelection == NULL) { return EFI_NOT_READY; } - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; + FormSet = NULL; + Form = NULL; + if (gBrowserSettingScope < SystemLevel) { + FormSet = gCurrentSelection->FormSet; + Form = gCurrentSelection->Form; + } // // Executet the discard action. // if ((Action & BROWSER_ACTION_DISCARD) != 0) { - Status = DiscardForm (gCurrentSelection->FormSet, gCurrentSelection->Form, gBrowserSettingScope); + Status = DiscardForm (FormSet, Form, gBrowserSettingScope); if (EFI_ERROR (Status)) { return Status; } @@ -5103,17 +6548,18 @@ ExecuteAction ( // Executet the difault action. // if ((Action & BROWSER_ACTION_DEFAULT) != 0) { - Status = ExtractDefault (gCurrentSelection->FormSet, gCurrentSelection->Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE); + Status = ExtractDefault (FormSet, Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE, FALSE); if (EFI_ERROR (Status)) { return Status; } + UpdateStatementStatus (FormSet, Form, gBrowserSettingScope); } // // Executet the submit action. // if ((Action & BROWSER_ACTION_SUBMIT) != 0) { - Status = SubmitForm (gCurrentSelection->FormSet, gCurrentSelection->Form, gBrowserSettingScope); + Status = SubmitForm (FormSet, Form, gBrowserSettingScope); if (EFI_ERROR (Status)) { return Status; } @@ -5123,14 +6569,15 @@ ExecuteAction ( // Executet the reset action. // if ((Action & BROWSER_ACTION_RESET) != 0) { - gResetRequired = TRUE; + gResetRequiredFormLevel = TRUE; + gResetRequiredSystemLevel = TRUE; } // // Executet the exit action. // if ((Action & BROWSER_ACTION_EXIT) != 0) { - DiscardForm (gCurrentSelection->FormSet, gCurrentSelection->Form, gBrowserSettingScope); + DiscardForm (FormSet, Form, gBrowserSettingScope); if (gBrowserSettingScope == SystemLevel) { if (ExitHandlerFunction != NULL) { ExitHandlerFunction (); @@ -5150,6 +6597,7 @@ ExecuteAction ( @retval BROWSER_NO_CHANGES No browser data is changed. @retval BROWSER_SAVE_CHANGES The changed browser data is saved. @retval BROWSER_DISCARD_CHANGES The changed browser data is discard. + @retval BROWSER_KEEP_CURRENT Browser keep current changes. **/ UINT32 @@ -5162,6 +6610,7 @@ SaveReminder ( FORM_BROWSER_FORMSET *FormSet; BOOLEAN IsDataChanged; UINT32 DataSavedAction; + UINT32 ConfirmRet; DataSavedAction = BROWSER_NO_CHANGES; IsDataChanged = FALSE; @@ -5177,28 +6626,49 @@ SaveReminder ( break; } } - + // - // No data is changed. No save is required. + // No data is changed. No save is required. // if (!IsDataChanged) { return DataSavedAction; } - + // - // If data is changed, prompt user to save or discard it. + // If data is changed, prompt user to save or discard it. // do { - DataSavedAction = (UINT32) mFormDisplay->ConfirmDataChange(); + ConfirmRet = (UINT32) mFormDisplay->ConfirmDataChange(); - if (DataSavedAction == BROWSER_SAVE_CHANGES) { + if (ConfirmRet == BROWSER_ACTION_SUBMIT) { SubmitForm (NULL, NULL, SystemLevel); + DataSavedAction = BROWSER_SAVE_CHANGES; break; - } else if (DataSavedAction == BROWSER_DISCARD_CHANGES) { + } else if (ConfirmRet == BROWSER_ACTION_DISCARD) { DiscardForm (NULL, NULL, SystemLevel); + DataSavedAction = BROWSER_DISCARD_CHANGES; + break; + } else if (ConfirmRet == BROWSER_ACTION_NONE) { + DataSavedAction = BROWSER_KEEP_CURRENT; break; } } while (1); return DataSavedAction; } + +/** + Check whether the Reset Required for the browser + + @retval TRUE Browser required to reset after exit. + @retval FALSE Browser not need to reset after exit. + +**/ +BOOLEAN +EFIAPI +IsResetRequired ( + VOID + ) +{ + return gResetRequiredSystemLevel; +}