X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=inline;f=MdeModulePkg%2FUniversal%2FSetupBrowserDxe%2FSetup.c;h=83dc2b86c7fad165db4e5a943a4550bb8062faee;hb=9f4048f7f8cd4b6bd5eee0f0c4bfd4eb6926a536;hp=1f8da4237e41155569e81f097813fdc6a134534d;hpb=e213ae45524e00441287176b962008a13a093804;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index 1f8da4237e..83dc2b86c7 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c @@ -1,7 +1,7 @@ /** @file Entry and initialization module for the browser. -Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2017, 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 @@ -28,12 +28,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,10 +50,13 @@ 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 gFinishRetrieveCall; +BOOLEAN mSystemSubmit = FALSE; BOOLEAN gResetRequired; BOOLEAN gExitRequired; +BOOLEAN gFlagReconnect; +BOOLEAN gCallbackReconnect; BROWSER_SETTING_SCOPE gBrowserSettingScope = FormSetLevel; BOOLEAN mBrowserScopeFirstSet = TRUE; EXIT_HANDLER ExitHandlerFunction = NULL; @@ -62,10 +68,6 @@ FORM_BROWSER_FORMSET *mSystemLevelFormSet; 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; @@ -179,7 +181,7 @@ UiFindMenuList ( // Find the same FromSet. // if (MenuList->HiiHandle == HiiHandle) { - if (CompareGuid (&MenuList->FormSetGuid, &gZeroGuid)) { + if (IsZeroGuid (&MenuList->FormSetGuid)) { // // FormSetGuid is not specified. // @@ -204,19 +206,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; @@ -243,6 +282,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. @@ -258,11 +336,8 @@ LoadAllHiiFormset ( EFI_GUID ZeroGuid; EFI_STATUS Status; FORM_BROWSER_FORMSET *OldFormset; - BOOLEAN OldRetrieveValue; OldFormset = mSystemLevelFormSet; - OldRetrieveValue = gFinishRetrieveCall; - gFinishRetrieveCall = FALSE; // // Get all the Hii handles @@ -311,10 +386,61 @@ LoadAllHiiFormset ( // FreePool (HiiHandles); - gFinishRetrieveCall = OldRetrieveValue; 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; +} + /** This is the routine which an external caller uses to direct the browser where to obtain it's information. @@ -357,11 +483,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; } @@ -370,9 +498,10 @@ SendForm ( // SaveBrowserContext (); - gFinishRetrieveCall = FALSE; + gFlagReconnect = FALSE; gResetRequired = FALSE; gExitRequired = FALSE; + gCallbackReconnect = FALSE; Status = EFI_SUCCESS; gEmptyString = L""; gDisplayFormData.ScreenDimensions = (EFI_SCREEN_DESCRIPTOR *) ScreenDimensions; @@ -393,6 +522,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 // @@ -414,6 +551,15 @@ SendForm ( gCurrentSelection = NULL; mSystemLevelFormSet = NULL; + if (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. // @@ -431,19 +577,6 @@ 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) { @@ -501,6 +634,8 @@ ProcessStorage ( CHAR16 *StrPtr; UINTN BufferSize; UINTN TmpSize; + UINTN MaxLen; + FORMSET_STORAGE *BrowserStorage; if (RetrieveData) { // @@ -515,15 +650,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; @@ -532,14 +669,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 @@ -716,13 +856,11 @@ FormDisplayCallback ( IN VOID *Context ) { - EFI_STATUS Status; - if (mFormDisplay != NULL) { return; } - Status = gBS->LocateProtocol ( + gBS->LocateProtocol ( &gEdkiiFormDisplayEngineProtocolGuid, NULL, (VOID **) &mFormDisplay @@ -800,7 +938,7 @@ InitializeSetup ( Status = gBS->InstallProtocolInterface ( &mPrivateData.Handle, - &gEfiFormBrowserExProtocolGuid, + &gEdkiiFormBrowserExProtocolGuid, EFI_NATIVE_INTERFACE, &mPrivateData.FormBrowserEx ); @@ -942,19 +1080,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; @@ -1099,6 +1237,7 @@ StorageToConfigResp ( LIST_ENTRY *Link; NAME_VALUE_NODE *Node; UINT8 *SourceBuf; + FORMSET_STORAGE *FormsetStorage; Status = EFI_SUCCESS; @@ -1118,7 +1257,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)) { @@ -1226,6 +1367,114 @@ ConfigRespToStorage ( return Status; } +/** + 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; + + 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 + // + 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; + + return Status; +} /** Get Question's current Value. @@ -1253,19 +1502,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; + UINTN MaxLen; Status = EFI_SUCCESS; Value = NULL; @@ -1356,7 +1601,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) { @@ -1418,7 +1672,6 @@ GetQuestionValue ( } else { IsBufferStorage = FALSE; } - IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE); if (GetValueFrom == GetSetValueWithEditBuffer || GetValueFrom == GetSetValueWithBuffer ) { if (IsBufferStorage) { if (GetValueFrom == GetSetValueWithEditBuffer) { @@ -1440,68 +1693,34 @@ 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 { + FormsetStorage = GetFstStgFromVarId(FormSet, Question->VarStoreId); + ASSERT (FormsetStorage != NULL); // // ::= + || // + "&" + // if (IsBufferStorage) { - Length = StrLen (Storage->ConfigHdr); + Length = StrLen (FormsetStorage->ConfigHdr); Length += StrLen (Question->BlockName); } else { - Length = StrLen (Storage->ConfigHdr); + Length = StrLen (FormsetStorage->ConfigHdr); Length += StrLen (Question->VariableName) + 1; } - ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); + // Allocate buffer include '\0' + MaxLen = Length + 1; + ConfigRequest = AllocateZeroPool (MaxLen * sizeof (CHAR16)); ASSERT (ConfigRequest != NULL); - StrCpy (ConfigRequest, Storage->ConfigHdr); + StrCpyS (ConfigRequest, MaxLen, FormsetStorage->ConfigHdr); if (IsBufferStorage) { - StrCat (ConfigRequest, Question->BlockName); + StrCatS (ConfigRequest, MaxLen, Question->BlockName); } else { - StrCat (ConfigRequest, L"&"); - StrCat (ConfigRequest, Question->VariableName); + StrCatS (ConfigRequest, MaxLen, L"&"); + StrCatS (ConfigRequest, MaxLen, Question->VariableName); } // @@ -1543,54 +1762,7 @@ GetQuestionValue ( // Value = Value + 1; - // - // Suppress if any - // - 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]); - } - } - } - } - + Status = BufferToValue (Question, Value); if (EFI_ERROR (Status)) { FreePool (Result); return Status; @@ -1641,6 +1813,7 @@ SetQuestionValue ( UINTN BufferLen; UINTN StorageWidth; BROWSER_STORAGE *Storage; + FORMSET_STORAGE *FormsetStorage; EFI_IFR_TYPE_VALUE *QuestionValue; CHAR16 *ConfigResp; CHAR16 *Progress; @@ -1653,6 +1826,7 @@ SetQuestionValue ( CHAR16 *TemString; UINTN Index; NAME_VALUE_NODE *Node; + UINTN MaxLen; Status = EFI_SUCCESS; Node = NULL; @@ -1798,7 +1972,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; @@ -1810,7 +1991,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)); } } @@ -1835,17 +2023,20 @@ SetQuestionValue ( } else { Length += (StorageWidth * 2); } - ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16)); + FormsetStorage = GetFstStgFromVarId(FormSet, Question->VarStoreId); + ASSERT (FormsetStorage != NULL); + MaxLen = StrLen (FormsetStorage->ConfigHdr) + Length + 1; + ConfigResp = AllocateZeroPool (MaxLen * sizeof (CHAR16)); ASSERT (ConfigResp != NULL); - StrCpy (ConfigResp, Storage->ConfigHdr); + StrCpyS (ConfigResp, MaxLen, FormsetStorage->ConfigHdr); if (IsBufferStorage) { - StrCat (ConfigResp, Question->BlockName); - StrCat (ConfigResp, L"&VALUE="); + StrCatS (ConfigResp, MaxLen, Question->BlockName); + StrCatS (ConfigResp, MaxLen, L"&VALUE="); } else { - StrCat (ConfigResp, L"&"); - StrCat (ConfigResp, Question->VariableName); - StrCat (ConfigResp, L"="); + StrCatS (ConfigResp, MaxLen, L"&"); + StrCatS (ConfigResp, MaxLen, Question->VariableName); + StrCatS (ConfigResp, MaxLen, L"="); } Value = ConfigResp + StrLen (ConfigResp); @@ -1857,7 +2048,14 @@ SetQuestionValue ( TemName = (CHAR16 *) Src; TemString = Value; for (; *TemName != L'\0'; TemName++) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4); + 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 { // @@ -1866,7 +2064,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, + MaxLen * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)ConfigResp), + PREFIX_ZERO | RADIX_HEX, + *TemBuffer, + 2 + ); + TemString += StrnLenS (TemString, MaxLen - ((UINTN)TemString - (UINTN)ConfigResp) / sizeof (CHAR16)); } } @@ -1926,12 +2131,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; } @@ -1947,19 +2168,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); @@ -1968,44 +2219,95 @@ ValidateQuestion ( return EFI_SUCCESS; } - /** - Perform NoSubmit check for each Form in FormSet. + 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 CurrentForm Current input form 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 -NoSubmitCheck ( +ValueChangedValidation ( IN FORM_BROWSER_FORMSET *FormSet, - IN FORM_BROWSER_FORM *CurrentForm + IN FORM_BROWSER_FORM *Form, + IN FORM_BROWSER_STATEMENT *Question ) { - EFI_STATUS Status; - LIST_ENTRY *Link; - FORM_BROWSER_STATEMENT *Question; - FORM_BROWSER_FORM *Form; - LIST_ENTRY *LinkForm; + EFI_STATUS Status; - LinkForm = GetFirstNode (&FormSet->FormListHead); - while (!IsNull (&FormSet->FormListHead, LinkForm)) { - Form = FORM_BROWSER_FORM_FROM_LINK (LinkForm); - LinkForm = GetNextNode (&FormSet->FormListHead, LinkForm); + Status = EFI_SUCCESS; - if (CurrentForm != NULL && CurrentForm != Form) { - continue; + // + // Do the inconsistentif check. + // + if (!IsListEmpty (&Question->InconsistentListHead)) { + Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF); + if (EFI_ERROR (Status)) { + return Status; } + } - Link = GetFirstNode (&Form->StatementListHead); - while (!IsNull (&Form->StatementListHead, Link)) { - Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); + // + // 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. + +**/ +EFI_STATUS +NoSubmitCheck ( + IN FORM_BROWSER_FORMSET *FormSet, + IN OUT FORM_BROWSER_FORM **CurrentForm, + OUT FORM_BROWSER_STATEMENT **Statement + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + FORM_BROWSER_STATEMENT *Question; + FORM_BROWSER_FORM *Form; + LIST_ENTRY *LinkForm; + + LinkForm = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, LinkForm)) { + Form = FORM_BROWSER_FORM_FROM_LINK (LinkForm); + LinkForm = GetNextNode (&FormSet->FormListHead, LinkForm); + 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; } @@ -2019,7 +2321,6 @@ 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 @@ -2032,7 +2333,6 @@ NoSubmitCheck ( **/ EFI_STATUS SynchronizeStorage ( - IN FORM_BROWSER_FORMSET *FormSet, OUT BROWSER_STORAGE *Storage, IN CHAR16 *ConfigRequest, IN BOOLEAN SyncOrRestore @@ -2153,6 +2453,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 { @@ -2172,49 +2481,160 @@ SendDiscardInfoToDriver ( } /** - Validate the FormSet. If the formset is not validate, remove it from the list. + When submit the question value, call the callback function with Submitted type + to inform the hii driver. - @param FormSet The input FormSet which need to validate. + @param FormSet FormSet data structure. + @param Form Form data structure. + +**/ +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 -ValidateFormSet ( - FORM_BROWSER_FORMSET *FormSet +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; } /** @@ -2222,33 +2642,49 @@ 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; } - - Link = GetNextNode (&Form->StatementListHead, Link); + + 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) { + gResetRequired = TRUE; + } + + if ((Question->QuestionFlags & EFI_IFR_FLAG_RECONNECT_REQUIRED) != 0) { + gFlagReconnect = TRUE; + } + } } } @@ -2273,11 +2709,8 @@ ValueChangeResetFlagUpdate ( 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; } @@ -2286,169 +2719,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_FORMSET *OldFormSet; - - // - // Check the supported setting level. - // - if (SettingScope >= MaxLevel) { - return EFI_UNSUPPORTED; - } + FORM_BROWSER_FORM *Form; + EFI_STRING EndStr; + FORM_BROWSER_STATEMENT *Statement; - 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; - } + EndStr = StrStr (Progress, L"="); + ASSERT (EndStr != NULL); + *EndStr = '\0'; + } 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 = '\0'; + } - // - // Skip if there is no RequestElement - // - if (Storage->ElementCount == 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); + + // + // Search in the ConfigReqeust list in this form. + // + 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; } - SynchronizeStorage(FormSet, Storage->BrowserStorage, Storage->ConfigRequest, FALSE); + if (StrStr (ConfigInfo->ConfigRequest, Progress) != NULL) { + // + // Find the OffsetWidth string in this form. + // + *RetForm = Form; + break; + } } - 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); + if (*RetForm != NULL) { + LinkStatement = GetFirstNode (&Form->StatementListHead); + while (!IsNull (&Form->StatementListHead, LinkStatement)) { + Statement = FORM_BROWSER_STATEMENT_FROM_LINK (LinkStatement); + LinkStatement = GetNextNode (&Form->StatementListHead, LinkStatement); + + if (Statement->BlockName != NULL && StrStr (Statement->BlockName, Progress) != NULL) { + *RetQuestion = Statement; + break; + } + + if (Statement->VariableName != NULL && StrStr (Statement->VariableName, Progress) != NULL) { + *RetQuestion = Statement; + break; + } + } } - ValueChangeResetFlagUpdate(FALSE, FormSet, NULL); - } else if (SettingScope == SystemLevel) { + 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) { // - // System Level Discard. + // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset, + // here, just keep the "Fred" string. // - OldFormSet = mSystemLevelFormSet; - + EndStr = StrStr (Progress, L"="); + ASSERT (EndStr != NULL); + *EndStr = L'\0'; // - // Discard changed value for each FormSet in the maintain list. + // Find the ConfigHdr in ConfigRequest. // - Link = GetFirstNode (&gBrowserFormSetList); - while (!IsNull (&gBrowserFormSetList, Link)) { - LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); - Link = GetNextNode (&gBrowserFormSetList, Link); - if (!ValidateFormSet(LocalFormSet)) { - continue; - } - - mSystemLevelFormSet = LocalFormSet; - - DiscardForm (LocalFormSet, NULL, FormSetLevel); - if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) { - // - // Remove maintain backup list after discard except for the current using FormSet. - // - CleanBrowserStorage(LocalFormSet); - RemoveEntryList (&LocalFormSet->Link); - DestroyFormSet (LocalFormSet); - } + 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); - mSystemLevelFormSet = OldFormSet; + // + // restore the Progress string to the original format. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + *EndStr = L'='; + } else { + *EndStr = L'&'; } +} - return EFI_SUCCESS; +/** + 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; } /** - Submit data based on the input Setting level (Form, FormSet or System). + 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 Submit action. + @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; - 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. @@ -2457,19 +3090,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); @@ -2477,8 +3097,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; } @@ -2490,97 +3109,61 @@ SubmitForm ( } // - // 1. Prepare - // - Status = StorageToConfigResp (ConfigInfo->Storage, &ConfigResp, ConfigInfo->ConfigRequest, TRUE); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // 2. Set value to hii config routine protocol. + // Prepare // - Status = mHiiConfigRouting->RouteConfig ( - mHiiConfigRouting, - ConfigResp, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (ConfigResp); - return Status; - } + SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->ConfigRequest, FALSE); - 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; - } - - // - // 2. Send to Routine config Protocol. - // - Status = mHiiConfigRouting->RouteConfig ( - mHiiConfigRouting, - ConfigResp, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (ConfigResp); - return Status; - } + SynchronizeStorage(Storage->BrowserStorage, Storage->ConfigRequest, FALSE); + } - FreePool (ConfigResp); + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&FormSet->FormListHead, Link); + // - // 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)) { @@ -2589,221 +3172,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; + 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)) { + 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) { - // - // This Question is password or orderedlist - // - Dst = Question->BufferValue; - } else { + 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; + } + // - // Other type of Questions + // Skip if there is no RequestElement // - Dst = (UINT8 *) &Question->HiiValue.Value; + if (ConfigInfo->ElementCount == 0) { + continue; + } + + // + // 1. Prepare + // + Status = StorageToConfigResp (ConfigInfo->Storage, &ConfigResp, ConfigInfo->ConfigRequest, TRUE); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // 2. Set value to hii config routine protocol. + // + Status = mHiiConfigRouting->RouteConfig ( + mHiiConfigRouting, + ConfigResp, + &Progress + ); + + 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); } - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { - IsBufferStorage = TRUE; - } else { - IsBufferStorage = FALSE; + // + // 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); + } } - IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE); // - // ::= + || - // + "&" + + // 5. Update the NV flag. // - if (IsBufferStorage) { - Length = StrLen (Storage->ConfigHdr); - Length += StrLen (Question->BlockName); - } else { - Length = StrLen (Storage->ConfigHdr); - Length += StrLen (Question->VariableName) + 1; + ValueChangeResetFlagUpdate(TRUE, FormSet, Form); + + // + // 6 Call callback with Submitted type to inform the driver. + // + if (!SubmitFormFail) { + SubmitCallback (FormSet, Form); } - 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); + 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; } - Status = mHiiConfigRouting->ExtractConfig ( - mHiiConfigRouting, - ConfigRequest, - &Progress, - &Result - ); + 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; // - // Call ConfigRouting GetAltCfg(ConfigRoute, , Guid, Name, DevicePath, AltCfgId, AltCfgResp) - // Get the default configuration string according to the default ID. + // Submit Buffer storage or Name/Value storage // - Status = mHiiConfigRouting->GetAltConfig ( - mHiiConfigRouting, - Result, - &Storage->Guid, - Storage->Name, - NULL, - &DefaultId, // it can be NULL to get the current setting. - &ConfigResp - ); - + 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); + } + // - // The required setting can't be found. So, it is not required to be validated and set. + // 4. Has save fail storage need to handle. // - if (EFI_ERROR (Status)) { - goto Done; + 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 (ConfigResp == NULL) { - Status = EFI_NOT_FOUND; - goto Done; + // + // 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); + } } // - // Skip + // 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; + } + + // + // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER + // + + // + // Convert all hex digits in ConfigResp to lower case before searching. + // + HiiToLower (ConfigResp); + + // + // 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); } /** @@ -2998,9 +4116,15 @@ GetQuestionDefault ( 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 @@ -3017,7 +4141,15 @@ GetQuestionDefault ( // 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. @@ -3031,7 +4163,7 @@ GetQuestionDefault ( Action, Question->QuestionId, HiiValue->Type, - &HiiValue->Value, + TypeValue, &ActionRequest ); if (!EFI_ERROR (Status)) { @@ -3041,6 +4173,7 @@ GetQuestionDefault ( 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); @@ -3056,7 +4189,7 @@ GetQuestionDefault ( // Get default value from altcfg string. // if (ConfigAccess != NULL) { - Status = GetDefaultValueFromAltCfg(FormSet, Question, DefaultId); + Status = GetDefaultValueFromAltCfg(FormSet, Form, Question); if (!EFI_ERROR (Status)) { return Status; } @@ -3097,7 +4230,12 @@ GetQuestionDefault ( // // 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) { @@ -3106,6 +4244,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); @@ -3160,8 +4299,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; @@ -3169,74 +4306,369 @@ 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. @@ -3253,6 +4685,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. @@ -3266,7 +4699,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; @@ -3288,8 +4722,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 // @@ -3346,13 +4787,34 @@ 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. @@ -3374,7 +4836,7 @@ ExtractDefault ( mSystemLevelFormSet = LocalFormSet; - ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst); + ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst, SkipGetAltCfg); } mSystemLevelFormSet = OldFormSet; @@ -3406,6 +4868,8 @@ IsQuestionValueChanged ( { EFI_HII_VALUE BackUpValue; CHAR8 *BackUpBuffer; + EFI_HII_VALUE BackUpValue2; + CHAR8 *BackUpBuffer2; EFI_STATUS Status; BOOLEAN ValueChanged; UINTN BufferWidth; @@ -3418,6 +4882,7 @@ IsQuestionValueChanged ( } BackUpBuffer = NULL; + BackUpBuffer2 = NULL; ValueChanged = FALSE; switch (Question->Operand) { @@ -3440,21 +4905,57 @@ 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; @@ -3483,8 +4984,6 @@ LoadFormConfig ( EFI_STATUS Status; LIST_ENTRY *Link; FORM_BROWSER_STATEMENT *Question; - UINT8 *BufferValue; - UINTN StorageWidth; Link = GetFirstNode (&Form->StatementListHead); while (!IsNull (&Form->StatementListHead, Link)) { @@ -3506,38 +5005,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) && - !gFinishRetrieveCall) { - // - // 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, FormSet, Form, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE); - } - Link = GetNextNode (&Form->StatementListHead, Link); } @@ -3626,13 +5093,13 @@ RemoveElement ( /** 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 ) { @@ -3647,7 +5114,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 // @@ -3662,7 +5129,7 @@ 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); @@ -3686,7 +5153,7 @@ RemoveConfigRequest ( *NextRequestElement = L'\0'; } - RemoveElement (Storage, RequestElement); + RemoveElement (Storage->BrowserStorage, RequestElement); if (NextRequestElement != NULL) { // @@ -3701,10 +5168,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; } } @@ -3732,7 +5199,7 @@ CleanBrowserStorage ( continue; } - RemoveConfigRequest (Storage->BrowserStorage, Storage->ConfigRequest); + 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) { @@ -3781,8 +5248,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 @@ -3791,8 +5261,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) { @@ -3803,7 +5273,7 @@ AppendConfigRequest ( *SpareStrLen = CONFIG_REQUEST_STRING_INCREMENTAL; } - StrCat (*ConfigRequest, RequestElement); + StrCatS (*ConfigRequest, MaxLen, RequestElement); *SpareStrLen -= StrLength; } @@ -3828,13 +5298,11 @@ ConfigRequestAdjust ( CHAR16 *RequestElement; CHAR16 *NextRequestElement; CHAR16 *NextElementBakup; - UINTN SpareBufLen; CHAR16 *SearchKey; CHAR16 *ValueKey; BOOLEAN RetVal; CHAR16 *ConfigRequest; - SpareBufLen = 0; RetVal = FALSE; NextElementBakup = NULL; ValueKey = NULL; @@ -3931,155 +5399,6 @@ ConfigRequestAdjust ( 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); - - if (StrStr (ConfigRequest, Node->Name) != NULL) { - continue; - } - - 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; - } - - FreePool (TmpNode->EditValue); - TmpNode->EditValue = AllocateCopyPool (StrSize(Node->EditValue) * sizeof (CHAR16), Node->EditValue); - - RemoveEntryList (&Node->Link); - FreePool (Node->EditValue); - FreePool (Node->Name); - FreePool (Node); - } - } - - // - // Restore the Name/Value node. - // - Link = GetFirstNode (&BackUpList); - while (!IsNull (&BackUpList, Link)) { - Node = NAME_VALUE_NODE_FROM_LINK (Link); - Link = GetNextNode (&BackUpList, Link); - - // - // Free this node. - // - RemoveEntryList (&Node->Link); - FreePool (Node->EditValue); - FreePool (Node->Name); - FreePool (Node); - } - } -} - /** Fill storage's edit copy with settings requested from Configuration Driver. @@ -4143,14 +5462,14 @@ LoadStorage ( // 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->BrowserStorage->ConfigHdr) + 20 * sizeof (CHAR16); + StrLen = StrSize (Storage->ConfigHdr) + 20 * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (StrLen); ASSERT (ConfigRequest != NULL); UnicodeSPrint ( ConfigRequest, StrLen, L"%s&OFFSET=0&WIDTH=%04x", - Storage->BrowserStorage->ConfigHdr, + Storage->ConfigHdr, Storage->BrowserStorage->Size); } else { ConfigRequest = Storage->ConfigRequest; @@ -4170,7 +5489,7 @@ LoadStorage ( // 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); + ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE, TRUE); } else { // // Convert Result from to @@ -4189,7 +5508,7 @@ LoadStorage ( // // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer. // - SynchronizeStorage(FormSet, Storage->BrowserStorage, NULL, TRUE); + SynchronizeStorage(Storage->BrowserStorage, NULL, TRUE); if (Storage->BrowserStorage->Type != EFI_HII_VARSTORE_NAME_VALUE) { if (ConfigRequest != NULL) { @@ -4316,7 +5635,7 @@ InitializeCurrentSetting ( // // 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 @@ -4428,7 +5747,7 @@ GetIfrBinaryData ( // // Try to compare against formset GUID // - if (CompareGuid (FormSetGuid, &gZeroGuid) || + if (IsZeroGuid (FormSetGuid) || CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) { break; } @@ -4577,8 +5896,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) { @@ -4598,10 +5918,16 @@ SaveBrowserContext ( // Context->Selection = gCurrentSelection; Context->ResetRequired = gResetRequired; + 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. @@ -4614,6 +5940,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 // @@ -4632,7 +5969,8 @@ RestoreBrowserContext ( { LIST_ENTRY *Link; BROWSER_CONTEXT *Context; - FORM_ENTRY_INFO *MenuList; + FORM_ENTRY_INFO *MenuList; + FORM_BROWSER_FORMSET *FormSet; ASSERT (gBrowserContextCount != 0); gBrowserContextCount--; @@ -4653,10 +5991,16 @@ RestoreBrowserContext ( // gCurrentSelection = Context->Selection; gResetRequired = 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. @@ -4668,6 +6012,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 // @@ -4783,29 +6137,10 @@ PasswordCheck ( return EFI_UNSUPPORTED; } } else { - if (PasswordString == NULL) { - return EFI_SUCCESS; - } - // - // Check whether has preexisted password. + // If a password doesn't have the CALLBACK flag, browser will not handle it. // - if (PasswordString[0] == 0) { - if (*((CHAR16 *) Question->BufferValue) == 0) { - return EFI_SUCCESS; - } else { - return EFI_NOT_READY; - } - } - - // - // Check whether the input password is same as preexisted password. - // - if (StrnCmp (PasswordString, (CHAR16 *) Question->BufferValue, Question->StorageWidth/sizeof (CHAR16)) == 0) { - return EFI_SUCCESS; - } else { - return EFI_NOT_READY; - } + return EFI_UNSUPPORTED; } // @@ -4922,6 +6257,7 @@ SetScope ( @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 @@ -4967,20 +6303,19 @@ RegisterHotKey ( 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. @@ -5109,7 +6444,7 @@ ExecuteAction ( // Executet the difault action. // if ((Action & BROWSER_ACTION_DEFAULT) != 0) { - Status = ExtractDefault (FormSet, Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE); + Status = ExtractDefault (FormSet, Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE, FALSE); if (EFI_ERROR (Status)) { return Status; } @@ -5216,3 +6551,20 @@ SaveReminder ( 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 gResetRequired; +} +