2 Entry and initialization module for the browser.
4 Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 SETUP_DRIVER_PRIVATE_DATA mPrivateData
= {
18 SETUP_DRIVER_SIGNATURE
,
31 BROWSER_EXTENSION2_VERSION_1_1
,
35 IsBrowserDataModified
,
43 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
44 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
45 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL
*mPathFromText
;
46 EDKII_FORM_DISPLAY_ENGINE_PROTOCOL
*mFormDisplay
;
48 UINTN gBrowserContextCount
= 0;
49 LIST_ENTRY gBrowserContextList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserContextList
);
50 LIST_ENTRY gBrowserFormSetList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserFormSetList
);
51 LIST_ENTRY gBrowserHotKeyList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserHotKeyList
);
52 LIST_ENTRY gBrowserStorageList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserStorageList
);
53 LIST_ENTRY gBrowserSaveFailFormSetList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserSaveFailFormSetList
);
55 BOOLEAN mSystemSubmit
= FALSE
;
56 BOOLEAN gResetRequired
;
57 BOOLEAN gExitRequired
;
58 BROWSER_SETTING_SCOPE gBrowserSettingScope
= FormSetLevel
;
59 BOOLEAN mBrowserScopeFirstSet
= TRUE
;
60 EXIT_HANDLER ExitHandlerFunction
= NULL
;
61 FORM_BROWSER_FORMSET
*mSystemLevelFormSet
;
64 // Browser Global Strings
67 CHAR16
*mUnknownString
= L
"!";
69 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
71 extern EFI_GUID mCurrentFormSetGuid
;
72 extern EFI_HII_HANDLE mCurrentHiiHandle
;
73 extern UINT16 mCurrentFormId
;
74 extern FORM_DISPLAY_ENGINE_FORM gDisplayFormData
;
77 Create a menu with specified formset GUID and form ID, and add it as a child
78 of the given parent menu.
80 @param HiiHandle Hii handle related to this formset.
81 @param FormSetGuid The Formset Guid of menu to be added.
82 @param FormId The Form ID of menu to be added.
83 @param QuestionId The question id of this menu to be added.
85 @return A pointer to the newly added menu or NULL if memory is insufficient.
90 IN EFI_HII_HANDLE HiiHandle
,
91 IN EFI_GUID
*FormSetGuid
,
96 FORM_ENTRY_INFO
*MenuList
;
98 MenuList
= AllocateZeroPool (sizeof (FORM_ENTRY_INFO
));
99 if (MenuList
== NULL
) {
103 MenuList
->Signature
= FORM_ENTRY_INFO_SIGNATURE
;
105 MenuList
->HiiHandle
= HiiHandle
;
106 CopyMem (&MenuList
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
107 MenuList
->FormId
= FormId
;
108 MenuList
->QuestionId
= QuestionId
;
111 // If parent is not specified, it is the root Form of a Formset
113 InsertTailList (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &MenuList
->Link
);
119 Return the form id for the input hiihandle and formset.
121 @param HiiHandle HiiHandle for FormSet.
122 @param FormSetGuid The Formset GUID of the menu to search.
124 @return First form's id for this form set.
129 IN EFI_HII_HANDLE HiiHandle
,
130 IN EFI_GUID
*FormSetGuid
134 FORM_BROWSER_FORM
*Form
;
136 Link
= GetFirstNode (&gCurrentSelection
->FormSet
->FormListHead
);
137 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
143 Search Menu with given FormSetGuid and FormId in all cached menu list.
145 @param HiiHandle HiiHandle for FormSet.
146 @param FormSetGuid The Formset GUID of the menu to search.
147 @param FormId The Form ID of menu to search.
149 @return A pointer to menu found or NULL if not found.
154 IN EFI_HII_HANDLE HiiHandle
,
155 IN EFI_GUID
*FormSetGuid
,
160 FORM_ENTRY_INFO
*MenuList
;
161 FORM_ENTRY_INFO
*RetMenu
;
162 EFI_FORM_ID FirstFormId
;
166 Link
= GetFirstNode (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
);
167 while (!IsNull (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, Link
)) {
168 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Link
);
169 Link
= GetNextNode (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, Link
);
172 // If already find the menu, free the menus behind it.
174 if (RetMenu
!= NULL
) {
175 RemoveEntryList (&MenuList
->Link
);
181 // Find the same FromSet.
183 if (MenuList
->HiiHandle
== HiiHandle
) {
184 if (CompareGuid (&MenuList
->FormSetGuid
, &gZeroGuid
)) {
186 // FormSetGuid is not specified.
189 } else if (CompareGuid (&MenuList
->FormSetGuid
, FormSetGuid
)) {
190 if (MenuList
->FormId
== FormId
) {
192 } else if (FormId
== 0 || MenuList
->FormId
== 0 ) {
193 FirstFormId
= GetFirstFormId (HiiHandle
, FormSetGuid
);
194 if ((FormId
== 0 && FirstFormId
== MenuList
->FormId
) || (MenuList
->FormId
==0 && FirstFormId
== FormId
)) {
206 Find parent menu for current menu.
208 @param CurrentMenu Current Menu
209 @param SettingLevel Whether find parent menu in Form Level or Formset level.
210 In form level, just find the parent menu;
211 In formset level, find the parent menu which has different
214 @retval The parent menu for current menu.
218 IN FORM_ENTRY_INFO
*CurrentMenu
,
219 IN BROWSER_SETTING_SCOPE SettingLevel
222 FORM_ENTRY_INFO
*ParentMenu
;
225 ASSERT (SettingLevel
== FormLevel
|| SettingLevel
== FormSetLevel
);
227 if (CurrentMenu
== NULL
) {
232 Link
= &CurrentMenu
->Link
;
234 while (Link
->BackLink
!= &mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
) {
235 ParentMenu
= FORM_ENTRY_INFO_FROM_LINK (Link
->BackLink
);
237 if (SettingLevel
== FormLevel
) {
239 // For FormLevel, just find the parent menu, return.
244 if (!CompareGuid (&CurrentMenu
->FormSetGuid
, &ParentMenu
->FormSetGuid
)) {
246 // For SystemLevel, must find the menu which has different formset.
251 Link
= Link
->BackLink
;
255 // Not find the parent menu, just return NULL.
257 if (Link
->BackLink
== &mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
) {
265 Free Menu list linked list.
267 @param MenuListHead One Menu list point in the menu list.
272 LIST_ENTRY
*MenuListHead
275 FORM_ENTRY_INFO
*MenuList
;
277 while (!IsListEmpty (MenuListHead
)) {
278 MenuList
= FORM_ENTRY_INFO_FROM_LINK (MenuListHead
->ForwardLink
);
279 RemoveEntryList (&MenuList
->Link
);
286 Copy current Menu list to the new menu list.
288 @param NewMenuListHead New create Menu list.
289 @param CurrentMenuListHead Current Menu list.
294 OUT LIST_ENTRY
*NewMenuListHead
,
295 IN LIST_ENTRY
*CurrentMenuListHead
299 FORM_ENTRY_INFO
*MenuList
;
300 FORM_ENTRY_INFO
*NewMenuEntry
;
303 // If new menu list not empty, free it first.
305 UiFreeMenuList (NewMenuListHead
);
307 Link
= GetFirstNode (CurrentMenuListHead
);
308 while (!IsNull (CurrentMenuListHead
, Link
)) {
309 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Link
);
310 Link
= GetNextNode (CurrentMenuListHead
, Link
);
312 NewMenuEntry
= AllocateZeroPool (sizeof (FORM_ENTRY_INFO
));
313 ASSERT (NewMenuEntry
!= NULL
);
314 NewMenuEntry
->Signature
= FORM_ENTRY_INFO_SIGNATURE
;
315 NewMenuEntry
->HiiHandle
= MenuList
->HiiHandle
;
316 CopyMem (&NewMenuEntry
->FormSetGuid
, &MenuList
->FormSetGuid
, sizeof (EFI_GUID
));
317 NewMenuEntry
->FormId
= MenuList
->FormId
;
318 NewMenuEntry
->QuestionId
= MenuList
->QuestionId
;
320 InsertTailList (NewMenuListHead
, &NewMenuEntry
->Link
);
325 Load all hii formset to the browser.
333 FORM_BROWSER_FORMSET
*LocalFormSet
;
334 EFI_HII_HANDLE
*HiiHandles
;
338 FORM_BROWSER_FORMSET
*OldFormset
;
340 OldFormset
= mSystemLevelFormSet
;
343 // Get all the Hii handles
345 HiiHandles
= HiiGetHiiHandles (NULL
);
346 ASSERT (HiiHandles
!= NULL
);
349 // Search for formset of each class type
351 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
353 // Check HiiHandles[Index] does exist in global maintain list.
355 if (GetFormSetFromHiiHandle (HiiHandles
[Index
]) != NULL
) {
360 // Initilize FormSet Setting
362 LocalFormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
363 ASSERT (LocalFormSet
!= NULL
);
364 mSystemLevelFormSet
= LocalFormSet
;
366 ZeroMem (&ZeroGuid
, sizeof (ZeroGuid
));
367 Status
= InitializeFormSet (HiiHandles
[Index
], &ZeroGuid
, LocalFormSet
);
368 if (EFI_ERROR (Status
) || IsListEmpty (&LocalFormSet
->FormListHead
)) {
369 DestroyFormSet (LocalFormSet
);
372 InitializeCurrentSetting (LocalFormSet
);
375 // Initilize Questions' Value
377 Status
= LoadFormSetConfig (NULL
, LocalFormSet
);
378 if (EFI_ERROR (Status
)) {
379 DestroyFormSet (LocalFormSet
);
385 // Free resources, and restore gOldFormSet and gClassOfVfr
387 FreePool (HiiHandles
);
389 mSystemLevelFormSet
= OldFormset
;
393 Pop up the error info.
395 @param BrowserStatus The input browser status.
396 @param HiiHandle The Hiihandle for this opcode.
397 @param OpCode The opcode use to get the erro info and timeout value.
398 @param ErrorString Error string used by BROWSER_NO_SUBMIT_IF.
403 IN UINT32 BrowserStatus
,
404 IN EFI_HII_HANDLE HiiHandle
,
405 IN EFI_IFR_OP_HEADER
*OpCode
, OPTIONAL
406 IN CHAR16
*ErrorString
409 FORM_DISPLAY_ENGINE_STATEMENT
*Statement
;
410 USER_INPUT UserInputData
;
414 if (OpCode
!= NULL
) {
415 Statement
= AllocateZeroPool (sizeof(FORM_DISPLAY_ENGINE_STATEMENT
));
416 ASSERT (Statement
!= NULL
);
417 Statement
->OpCode
= OpCode
;
418 gDisplayFormData
.HighLightedStatement
= Statement
;
422 // Used to compatible with old display engine.
423 // New display engine not use this field.
425 gDisplayFormData
.ErrorString
= ErrorString
;
426 gDisplayFormData
.BrowserStatus
= BrowserStatus
;
428 if (HiiHandle
!= NULL
) {
429 gDisplayFormData
.HiiHandle
= HiiHandle
;
432 mFormDisplay
->FormDisplay (&gDisplayFormData
, &UserInputData
);
434 gDisplayFormData
.BrowserStatus
= BROWSER_SUCCESS
;
435 gDisplayFormData
.ErrorString
= NULL
;
437 if (OpCode
!= NULL
) {
438 FreePool (Statement
);
441 return UserInputData
.Action
;
445 This is the routine which an external caller uses to direct the browser
446 where to obtain it's information.
449 @param This The Form Browser protocol instanse.
450 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
451 display a list of the formsets for the handles specified.
452 @param HandleCount The number of Handles specified in Handle.
453 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
454 field in the EFI_IFR_FORM_SET op-code for the specified
455 forms-based package. If FormSetGuid is NULL, then this
456 function will display the first found forms package.
457 @param FormId This field specifies which EFI_IFR_FORM to render as the first
458 displayable page. If this field has a value of 0x0000, then
459 the forms browser will render the specified forms in their encoded order.
460 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
462 @param ActionRequest Points to the action recommended by the form.
464 @retval EFI_SUCCESS The function completed successfully.
465 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
466 @retval EFI_NOT_FOUND No valid forms could be found to display.
472 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
473 IN EFI_HII_HANDLE
*Handles
,
474 IN UINTN HandleCount
,
475 IN EFI_GUID
*FormSetGuid
, OPTIONAL
476 IN UINT16 FormId
, OPTIONAL
477 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
478 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
482 UI_MENU_SELECTION
*Selection
;
484 FORM_BROWSER_FORMSET
*FormSet
;
485 FORM_ENTRY_INFO
*MenuList
;
488 // If EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found, return EFI_UNSUPPORTED.
490 if (mFormDisplay
== NULL
) {
491 return EFI_UNSUPPORTED
;
495 // Save globals used by SendForm()
497 SaveBrowserContext ();
499 gResetRequired
= FALSE
;
500 gExitRequired
= FALSE
;
501 Status
= EFI_SUCCESS
;
503 gDisplayFormData
.ScreenDimensions
= (EFI_SCREEN_DESCRIPTOR
*) ScreenDimensions
;
505 for (Index
= 0; Index
< HandleCount
; Index
++) {
506 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
507 ASSERT (Selection
!= NULL
);
509 Selection
->Handle
= Handles
[Index
];
510 if (FormSetGuid
!= NULL
) {
511 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
512 Selection
->FormId
= FormId
;
514 CopyMem (&Selection
->FormSetGuid
, &gEfiHiiPlatformSetupFormsetGuid
, sizeof (EFI_GUID
));
518 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
519 ASSERT (FormSet
!= NULL
);
522 // Validate the HiiHandle
523 // if validate failed, find the first validate parent HiiHandle.
525 if (!ValidateHiiHandle(Selection
->Handle
)) {
526 FindNextMenu (Selection
, FormSetLevel
);
530 // Initialize internal data structures of FormSet
532 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
533 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
534 DestroyFormSet (FormSet
);
537 Selection
->FormSet
= FormSet
;
538 mSystemLevelFormSet
= FormSet
;
541 // Display this formset
543 gCurrentSelection
= Selection
;
545 Status
= SetupBrowser (Selection
);
547 gCurrentSelection
= NULL
;
548 mSystemLevelFormSet
= NULL
;
551 // If no data is changed, don't need to save current FormSet into the maintain list.
553 if (!IsNvUpdateRequiredForFormSet (FormSet
)) {
554 CleanBrowserStorage(FormSet
);
555 RemoveEntryList (&FormSet
->Link
);
556 DestroyFormSet (FormSet
);
559 if (EFI_ERROR (Status
)) {
562 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
564 FreePool (Selection
);
567 if (ActionRequest
!= NULL
) {
568 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
569 if (gResetRequired
) {
570 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
574 mFormDisplay
->ExitDisplay();
577 // Clear the menu history data.
579 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
580 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
581 RemoveEntryList (&MenuList
->Link
);
586 // Restore globals used by SendForm()
588 RestoreBrowserContext ();
594 Get or set data to the storage.
596 @param ResultsDataSize The size of the buffer associatedwith ResultsData.
597 @param ResultsData A string returned from an IFR browser or
598 equivalent. The results string will have no
599 routing information in them.
600 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
601 (if RetrieveData = TRUE) data from the uncommitted
602 browser state information or set (if RetrieveData
603 = FALSE) data in the uncommitted browser state
605 @param Storage The pointer to the storage.
607 @retval EFI_SUCCESS The results have been distributed or are awaiting
613 IN OUT UINTN
*ResultsDataSize
,
614 IN OUT EFI_STRING
*ResultsData
,
615 IN BOOLEAN RetrieveData
,
616 IN BROWSER_STORAGE
*Storage
624 FORMSET_STORAGE
*BrowserStorage
;
628 // Generate <ConfigResp>
630 Status
= StorageToConfigResp (Storage
, &ConfigResp
, Storage
->ConfigRequest
, TRUE
);
631 if (EFI_ERROR (Status
)) {
636 // Skip <ConfigHdr> and '&' to point to <ConfigBody> when first copy the configbody.
637 // Also need to consider add "\0" at first time.
639 StrPtr
= StrStr (ConfigResp
, L
"PATH");
640 ASSERT (StrPtr
!= NULL
);
641 StrPtr
= StrStr (StrPtr
, L
"&");
643 BufferSize
= StrSize (StrPtr
);
646 // Copy the data if the input buffer is bigger enough.
648 if (*ResultsDataSize
>= BufferSize
) {
649 StrCpy (*ResultsData
, StrPtr
);
652 *ResultsDataSize
= BufferSize
;
653 FreePool (ConfigResp
);
656 // Prepare <ConfigResp>
658 BrowserStorage
= GetFstStgFromBrsStg (Storage
);
659 ASSERT (BrowserStorage
!= NULL
);
660 TmpSize
= StrLen (*ResultsData
);
661 BufferSize
= (TmpSize
+ StrLen (BrowserStorage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
662 ConfigResp
= AllocateZeroPool (BufferSize
);
663 ASSERT (ConfigResp
!= NULL
);
665 StrCpy (ConfigResp
, BrowserStorage
->ConfigHdr
);
666 StrCat (ConfigResp
, L
"&");
667 StrCat (ConfigResp
, *ResultsData
);
670 // Update Browser uncommited data
672 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
673 FreePool (ConfigResp
);
674 if (EFI_ERROR (Status
)) {
683 This routine called this service in the browser to retrieve or set certain uncommitted
684 state information that resides in the open formsets.
686 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
688 @param ResultsDataSize A pointer to the size of the buffer associated
690 @param ResultsData A string returned from an IFR browser or
691 equivalent. The results string will have no
692 routing information in them.
693 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
694 (if RetrieveData = TRUE) data from the uncommitted
695 browser state information or set (if RetrieveData
696 = FALSE) data in the uncommitted browser state
698 @param VariableGuid An optional field to indicate the target variable
700 @param VariableName An optional field to indicate the target
701 human-readable variable name.
703 @retval EFI_SUCCESS The results have been distributed or are awaiting
705 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
706 contain the results data.
712 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
713 IN OUT UINTN
*ResultsDataSize
,
714 IN OUT EFI_STRING ResultsData
,
715 IN BOOLEAN RetrieveData
,
716 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
717 IN CONST CHAR16
*VariableName OPTIONAL
722 BROWSER_STORAGE
*Storage
;
723 FORMSET_STORAGE
*FormsetStorage
;
727 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
728 return EFI_INVALID_PARAMETER
;
731 TotalSize
= *ResultsDataSize
;
734 Status
= EFI_SUCCESS
;
736 if (VariableGuid
!= NULL
) {
738 // Try to find target storage in the current formset.
740 Link
= GetFirstNode (&gBrowserStorageList
);
741 while (!IsNull (&gBrowserStorageList
, Link
)) {
742 Storage
= BROWSER_STORAGE_FROM_LINK (Link
);
743 Link
= GetNextNode (&gBrowserStorageList
, Link
);
745 // Check the current storage.
747 if (!CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
751 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
752 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
754 // Buffer storage require both GUID and Name
756 if (VariableName
== NULL
) {
757 return EFI_NOT_FOUND
;
760 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
765 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
||
766 Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
767 if (mSystemLevelFormSet
== NULL
|| mSystemLevelFormSet
->HiiHandle
== NULL
) {
768 return EFI_NOT_FOUND
;
771 if (Storage
->HiiHandle
!= mSystemLevelFormSet
->HiiHandle
) {
776 Status
= ProcessStorage (&TotalSize
, &ResultsData
, RetrieveData
, Storage
);
777 if (EFI_ERROR (Status
)) {
781 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
782 ConfigRequestAdjust (Storage
, ResultsData
, TRUE
);
786 // Different formsets may have same varstore, so here just set the flag
787 // not exit the circle.
794 return EFI_NOT_FOUND
;
798 // GUID/Name is not specified, take the first storage in FormSet
800 if (mSystemLevelFormSet
== NULL
) {
801 return EFI_NOT_READY
;
805 // Generate <ConfigResp>
807 Link
= GetFirstNode (&mSystemLevelFormSet
->StorageListHead
);
808 if (IsNull (&mSystemLevelFormSet
->StorageListHead
, Link
)) {
809 return EFI_UNSUPPORTED
;
812 FormsetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
814 Status
= ProcessStorage (&TotalSize
, &ResultsData
, RetrieveData
, FormsetStorage
->BrowserStorage
);
815 if (EFI_ERROR (Status
)) {
821 Status
= TotalSize
<= *ResultsDataSize
? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
822 *ResultsDataSize
= TotalSize
;
831 Callback function for SimpleTextInEx protocol install events
833 @param Event the event that is signaled.
834 @param Context not used here.
839 FormDisplayCallback (
844 if (mFormDisplay
!= NULL
) {
848 gBS
->LocateProtocol (
849 &gEdkiiFormDisplayEngineProtocolGuid
,
851 (VOID
**) &mFormDisplay
856 Initialize Setup Browser driver.
858 @param ImageHandle The image handle.
859 @param SystemTable The system table.
861 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
862 @return Other value if failed to initialize the Setup Browser module.
868 IN EFI_HANDLE ImageHandle
,
869 IN EFI_SYSTEM_TABLE
*SystemTable
876 // Locate required Hii relative protocols
878 Status
= gBS
->LocateProtocol (
879 &gEfiHiiDatabaseProtocolGuid
,
881 (VOID
**) &mHiiDatabase
883 ASSERT_EFI_ERROR (Status
);
885 Status
= gBS
->LocateProtocol (
886 &gEfiHiiConfigRoutingProtocolGuid
,
888 (VOID
**) &mHiiConfigRouting
890 ASSERT_EFI_ERROR (Status
);
892 Status
= gBS
->LocateProtocol (
893 &gEfiDevicePathFromTextProtocolGuid
,
895 (VOID
**) &mPathFromText
899 // Install FormBrowser2 protocol
901 mPrivateData
.Handle
= NULL
;
902 Status
= gBS
->InstallProtocolInterface (
903 &mPrivateData
.Handle
,
904 &gEfiFormBrowser2ProtocolGuid
,
905 EFI_NATIVE_INTERFACE
,
906 &mPrivateData
.FormBrowser2
908 ASSERT_EFI_ERROR (Status
);
911 // Install FormBrowserEx2 protocol
913 InitializeListHead (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
);
914 InitializeListHead (&mPrivateData
.FormBrowserEx2
.OverrideQestListHead
);
915 mPrivateData
.Handle
= NULL
;
916 Status
= gBS
->InstallProtocolInterface (
917 &mPrivateData
.Handle
,
918 &gEdkiiFormBrowserEx2ProtocolGuid
,
919 EFI_NATIVE_INTERFACE
,
920 &mPrivateData
.FormBrowserEx2
922 ASSERT_EFI_ERROR (Status
);
924 Status
= gBS
->InstallProtocolInterface (
925 &mPrivateData
.Handle
,
926 &gEfiFormBrowserExProtocolGuid
,
927 EFI_NATIVE_INTERFACE
,
928 &mPrivateData
.FormBrowserEx
930 ASSERT_EFI_ERROR (Status
);
932 InitializeDisplayFormData ();
934 Status
= gBS
->LocateProtocol (
935 &gEdkiiFormDisplayEngineProtocolGuid
,
937 (VOID
**) &mFormDisplay
940 if (EFI_ERROR (Status
)) {
941 EfiCreateProtocolNotifyEvent (
942 &gEdkiiFormDisplayEngineProtocolGuid
,
955 Create a new string in HII Package List.
957 @param String The String to be added
958 @param HiiHandle The package list in the HII database to insert the
961 @return The output string.
967 IN EFI_HII_HANDLE HiiHandle
970 EFI_STRING_ID StringId
;
972 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
973 ASSERT (StringId
!= 0);
980 Delete a string from HII Package List.
982 @param StringId Id of the string in HII database.
983 @param HiiHandle The HII package list handle.
985 @retval EFI_SUCCESS The string was deleted successfully.
990 IN EFI_STRING_ID StringId
,
991 IN EFI_HII_HANDLE HiiHandle
996 NullChar
= CHAR_NULL
;
997 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
1003 Get the string based on the StringId and HII Package List Handle.
1005 @param Token The String's ID.
1006 @param HiiHandle The package list in the HII database to search for
1007 the specified string.
1009 @return The output string.
1014 IN EFI_STRING_ID Token
,
1015 IN EFI_HII_HANDLE HiiHandle
1020 if (HiiHandle
== NULL
) {
1024 String
= HiiGetString (HiiHandle
, Token
, NULL
);
1025 if (String
== NULL
) {
1026 String
= AllocateCopyPool (StrSize (mUnknownString
), mUnknownString
);
1027 ASSERT (String
!= NULL
);
1029 return (CHAR16
*) String
;
1034 Allocate new memory and then copy the Unicode string Source to Destination.
1036 @param Dest Location to copy string
1037 @param Src String to copy
1042 IN OUT CHAR16
**Dest
,
1046 if (*Dest
!= NULL
) {
1049 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
1050 ASSERT (*Dest
!= NULL
);
1055 Allocate new memory and concatinate Source on the end of Destination.
1057 @param Dest String to added to the end of.
1058 @param Src String to concatinate.
1063 IN OUT CHAR16
**Dest
,
1070 if (*Dest
== NULL
) {
1071 NewStringCpy (Dest
, Src
);
1075 TmpSize
= StrSize (*Dest
);
1076 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
1077 ASSERT (NewString
!= NULL
);
1079 StrCpy (NewString
, *Dest
);
1080 StrCat (NewString
, Src
);
1087 Get Value for given Name from a NameValue Storage.
1089 @param Storage The NameValue Storage.
1090 @param Name The Name.
1091 @param Value The retured Value.
1092 @param GetValueFrom Where to get source value, from EditValue or Value.
1094 @retval EFI_SUCCESS Value found for given Name.
1095 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
1100 IN BROWSER_STORAGE
*Storage
,
1102 IN OUT CHAR16
**Value
,
1103 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
1107 NAME_VALUE_NODE
*Node
;
1109 if (GetValueFrom
!= GetSetValueWithEditBuffer
&& GetValueFrom
!= GetSetValueWithBuffer
) {
1110 return EFI_INVALID_PARAMETER
;
1115 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1116 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1117 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1119 if (StrCmp (Name
, Node
->Name
) == 0) {
1120 if (GetValueFrom
== GetSetValueWithEditBuffer
) {
1121 NewStringCpy (Value
, Node
->EditValue
);
1123 NewStringCpy (Value
, Node
->Value
);
1128 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1131 return EFI_NOT_FOUND
;
1136 Set Value of given Name in a NameValue Storage.
1138 @param Storage The NameValue Storage.
1139 @param Name The Name.
1140 @param Value The Value to set.
1141 @param SetValueTo Whether update editValue or Value.
1142 @param ReturnNode The node use the input name.
1144 @retval EFI_SUCCESS Value found for given Name.
1145 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
1150 IN BROWSER_STORAGE
*Storage
,
1153 IN GET_SET_QUESTION_VALUE_WITH SetValueTo
,
1154 OUT NAME_VALUE_NODE
**ReturnNode
1158 NAME_VALUE_NODE
*Node
;
1161 if (SetValueTo
!= GetSetValueWithEditBuffer
&& SetValueTo
!= GetSetValueWithBuffer
) {
1162 return EFI_INVALID_PARAMETER
;
1165 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1166 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1167 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1169 if (StrCmp (Name
, Node
->Name
) == 0) {
1170 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1171 Buffer
= Node
->EditValue
;
1173 Buffer
= Node
->Value
;
1175 if (Buffer
!= NULL
) {
1178 Buffer
= AllocateCopyPool (StrSize (Value
), Value
);
1179 ASSERT (Buffer
!= NULL
);
1180 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1181 Node
->EditValue
= Buffer
;
1183 Node
->Value
= Buffer
;
1186 if (ReturnNode
!= NULL
) {
1193 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1196 return EFI_NOT_FOUND
;
1201 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
1203 @param Storage The Storage to be conveted.
1204 @param ConfigResp The returned <ConfigResp>.
1205 @param ConfigRequest The ConfigRequest string.
1206 @param GetEditBuf Get the data from editbuffer or buffer.
1208 @retval EFI_SUCCESS Convert success.
1209 @retval EFI_INVALID_PARAMETER Incorrect storage type.
1213 StorageToConfigResp (
1214 IN BROWSER_STORAGE
*Storage
,
1215 IN CHAR16
**ConfigResp
,
1216 IN CHAR16
*ConfigRequest
,
1217 IN BOOLEAN GetEditBuf
1221 EFI_STRING Progress
;
1223 NAME_VALUE_NODE
*Node
;
1225 FORMSET_STORAGE
*FormsetStorage
;
1227 Status
= EFI_SUCCESS
;
1229 switch (Storage
->Type
) {
1230 case EFI_HII_VARSTORE_BUFFER
:
1231 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
1232 SourceBuf
= GetEditBuf
? Storage
->EditBuffer
: Storage
->Buffer
;
1233 Status
= mHiiConfigRouting
->BlockToConfig (
1243 case EFI_HII_VARSTORE_NAME_VALUE
:
1245 FormsetStorage
= GetFstStgFromBrsStg(Storage
);
1246 ASSERT (FormsetStorage
!= NULL
);
1247 NewStringCat (ConfigResp
, FormsetStorage
->ConfigHdr
);
1249 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1250 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1251 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1253 if (StrStr (ConfigRequest
, Node
->Name
) != NULL
) {
1254 NewStringCat (ConfigResp
, L
"&");
1255 NewStringCat (ConfigResp
, Node
->Name
);
1256 NewStringCat (ConfigResp
, L
"=");
1258 NewStringCat (ConfigResp
, Node
->EditValue
);
1260 NewStringCat (ConfigResp
, Node
->Value
);
1263 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1267 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1269 Status
= EFI_INVALID_PARAMETER
;
1278 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
1280 @param Storage The Storage to receive the settings.
1281 @param ConfigResp The <ConfigResp> to be converted.
1283 @retval EFI_SUCCESS Convert success.
1284 @retval EFI_INVALID_PARAMETER Incorrect storage type.
1288 ConfigRespToStorage (
1289 IN BROWSER_STORAGE
*Storage
,
1290 IN CHAR16
*ConfigResp
1294 EFI_STRING Progress
;
1300 Status
= EFI_SUCCESS
;
1302 switch (Storage
->Type
) {
1303 case EFI_HII_VARSTORE_BUFFER
:
1304 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
1305 BufferSize
= Storage
->Size
;
1306 Status
= mHiiConfigRouting
->ConfigToBlock (
1309 Storage
->EditBuffer
,
1315 case EFI_HII_VARSTORE_NAME_VALUE
:
1316 StrPtr
= StrStr (ConfigResp
, L
"PATH");
1317 if (StrPtr
== NULL
) {
1320 StrPtr
= StrStr (ConfigResp
, L
"&");
1321 while (StrPtr
!= NULL
) {
1325 StrPtr
= StrPtr
+ 1;
1327 StrPtr
= StrStr (StrPtr
, L
"=");
1328 if (StrPtr
== NULL
) {
1336 StrPtr
= StrPtr
+ 1;
1338 StrPtr
= StrStr (StrPtr
, L
"&");
1339 if (StrPtr
!= NULL
) {
1342 SetValueByName (Storage
, Name
, Value
, GetSetValueWithEditBuffer
, NULL
);
1346 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1348 Status
= EFI_INVALID_PARAMETER
;
1356 Convert the buffer value to HiiValue.
1358 @param Question The question.
1359 @param Value Unicode buffer save the question value.
1361 @retval Status whether convert the value success.
1366 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1371 BOOLEAN IsBufferStorage
;
1383 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1384 if (Question
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1385 Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1386 IsBufferStorage
= TRUE
;
1388 IsBufferStorage
= FALSE
;
1392 // Question Value is provided by Buffer Storage or NameValue Storage
1394 if (Question
->BufferValue
!= NULL
) {
1396 // This Question is password or orderedlist
1398 Dst
= Question
->BufferValue
;
1401 // Other type of Questions
1403 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1407 // Temp cut at the end of this section, end with '\0' or '&'.
1410 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1413 TempChar
= *StringPtr
;
1416 LengthStr
= StrLen (Value
);
1417 Status
= EFI_SUCCESS
;
1418 if (!IsBufferStorage
&& IsString
) {
1420 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1421 // Add string tail char L'\0' into Length
1423 Length
= Question
->StorageWidth
+ sizeof (CHAR16
);
1424 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1425 Status
= EFI_BUFFER_TOO_SMALL
;
1427 DstBuf
= (CHAR16
*) Dst
;
1428 ZeroMem (TemStr
, sizeof (TemStr
));
1429 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1430 StrnCpy (TemStr
, Value
+ Index
, 4);
1431 DstBuf
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1434 // Add tailing L'\0' character
1436 DstBuf
[Index
/4] = L
'\0';
1439 if (Question
->StorageWidth
< ((LengthStr
+ 1) / 2)) {
1440 Status
= EFI_BUFFER_TOO_SMALL
;
1442 ZeroMem (TemStr
, sizeof (TemStr
));
1443 for (Index
= 0; Index
< LengthStr
; Index
++) {
1444 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1445 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1446 if ((Index
& 1) == 0) {
1447 Dst
[Index
/2] = DigitUint8
;
1449 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1455 *StringPtr
= TempChar
;
1461 Get Question's current Value.
1463 @param FormSet FormSet data structure.
1464 @param Form Form data structure.
1465 @param Question Question to be initialized.
1466 @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver.
1468 @retval EFI_SUCCESS The function completed successfully.
1473 IN FORM_BROWSER_FORMSET
*FormSet
,
1474 IN FORM_BROWSER_FORM
*Form
,
1475 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1476 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
1485 BROWSER_STORAGE
*Storage
;
1486 FORMSET_STORAGE
*FormsetStorage
;
1487 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1488 CHAR16
*ConfigRequest
;
1493 BOOLEAN IsBufferStorage
;
1495 Status
= EFI_SUCCESS
;
1499 if (GetValueFrom
>= GetSetValueWithMax
) {
1500 return EFI_INVALID_PARAMETER
;
1504 // Question value is provided by an Expression, evaluate it
1506 if (Question
->ValueExpression
!= NULL
) {
1507 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1508 if (!EFI_ERROR (Status
)) {
1509 if (Question
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1510 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1511 if (Question
->StorageWidth
> Question
->ValueExpression
->Result
.BufferLen
) {
1512 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->ValueExpression
->Result
.BufferLen
);
1513 Question
->HiiValue
.BufferLen
= Question
->ValueExpression
->Result
.BufferLen
;
1515 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
1516 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1518 FreePool (Question
->ValueExpression
->Result
.Buffer
);
1520 Question
->HiiValue
.Type
= Question
->ValueExpression
->Result
.Type
;
1521 CopyMem (&Question
->HiiValue
.Value
, &Question
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1527 // Get question value by read expression.
1529 if (Question
->ReadExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1530 Status
= EvaluateExpression (FormSet
, Form
, Question
->ReadExpression
);
1531 if (!EFI_ERROR (Status
) &&
1532 ((Question
->ReadExpression
->Result
.Type
< EFI_IFR_TYPE_OTHER
) || (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
))) {
1534 // Only update question value to the valid result.
1536 if (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1537 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1538 if (Question
->StorageWidth
> Question
->ReadExpression
->Result
.BufferLen
) {
1539 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->ReadExpression
->Result
.BufferLen
);
1540 Question
->HiiValue
.BufferLen
= Question
->ReadExpression
->Result
.BufferLen
;
1542 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->StorageWidth
);
1543 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1545 FreePool (Question
->ReadExpression
->Result
.Buffer
);
1547 Question
->HiiValue
.Type
= Question
->ReadExpression
->Result
.Type
;
1548 CopyMem (&Question
->HiiValue
.Value
, &Question
->ReadExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1554 // Question value is provided by RTC
1556 Storage
= Question
->Storage
;
1557 QuestionValue
= &Question
->HiiValue
.Value
;
1558 if (Storage
== NULL
) {
1560 // It's a Question without storage, or RTC date/time
1562 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1564 // Date and time define the same Flags bit
1566 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1567 case QF_DATE_STORAGE_TIME
:
1568 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1571 case QF_DATE_STORAGE_WAKEUP
:
1572 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1575 case QF_DATE_STORAGE_NORMAL
:
1578 // For date/time without storage
1583 if (EFI_ERROR (Status
)) {
1587 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1588 QuestionValue
->date
.Year
= EfiTime
.Year
;
1589 QuestionValue
->date
.Month
= EfiTime
.Month
;
1590 QuestionValue
->date
.Day
= EfiTime
.Day
;
1592 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1593 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1594 QuestionValue
->time
.Second
= EfiTime
.Second
;
1602 // Question value is provided by EFI variable
1604 StorageWidth
= Question
->StorageWidth
;
1605 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1606 if (Question
->BufferValue
!= NULL
) {
1607 Dst
= Question
->BufferValue
;
1609 Dst
= (UINT8
*) QuestionValue
;
1612 Status
= gRT
->GetVariable (
1613 Question
->VariableName
,
1620 // Always return success, even this EFI variable doesn't exist
1626 // Question Value is provided by Buffer Storage or NameValue Storage
1628 if (Question
->BufferValue
!= NULL
) {
1630 // This Question is password or orderedlist
1632 Dst
= Question
->BufferValue
;
1635 // Other type of Questions
1637 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1640 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1641 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1642 IsBufferStorage
= TRUE
;
1644 IsBufferStorage
= FALSE
;
1646 if (GetValueFrom
== GetSetValueWithEditBuffer
|| GetValueFrom
== GetSetValueWithBuffer
) {
1647 if (IsBufferStorage
) {
1648 if (GetValueFrom
== GetSetValueWithEditBuffer
) {
1650 // Copy from storage Edit buffer
1652 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1655 // Copy from storage Edit buffer
1657 CopyMem (Dst
, Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1661 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
, GetValueFrom
);
1662 if (EFI_ERROR (Status
)) {
1666 ASSERT (Value
!= NULL
);
1667 Status
= BufferToValue (Question
, Value
);
1671 FormsetStorage
= GetFstStgFromVarId(FormSet
, Question
->VarStoreId
);
1672 ASSERT (FormsetStorage
!= NULL
);
1674 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1675 // <ConfigHdr> + "&" + <VariableName>
1677 if (IsBufferStorage
) {
1678 Length
= StrLen (FormsetStorage
->ConfigHdr
);
1679 Length
+= StrLen (Question
->BlockName
);
1681 Length
= StrLen (FormsetStorage
->ConfigHdr
);
1682 Length
+= StrLen (Question
->VariableName
) + 1;
1684 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1685 ASSERT (ConfigRequest
!= NULL
);
1687 StrCpy (ConfigRequest
, FormsetStorage
->ConfigHdr
);
1688 if (IsBufferStorage
) {
1689 StrCat (ConfigRequest
, Question
->BlockName
);
1691 StrCat (ConfigRequest
, L
"&");
1692 StrCat (ConfigRequest
, Question
->VariableName
);
1696 // Request current settings from Configuration Driver
1698 Status
= mHiiConfigRouting
->ExtractConfig (
1704 FreePool (ConfigRequest
);
1705 if (EFI_ERROR (Status
)) {
1710 // Skip <ConfigRequest>
1712 if (IsBufferStorage
) {
1713 Value
= StrStr (Result
, L
"&VALUE");
1714 if (Value
== NULL
) {
1716 return EFI_NOT_FOUND
;
1723 Value
= Result
+ Length
;
1725 if (*Value
!= '=') {
1727 return EFI_NOT_FOUND
;
1730 // Skip '=', point to value
1734 Status
= BufferToValue (Question
, Value
);
1735 if (EFI_ERROR (Status
)) {
1741 // Synchronize Edit Buffer
1743 if (IsBufferStorage
) {
1744 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1746 SetValueByName (Storage
, Question
->VariableName
, Value
, GetSetValueWithEditBuffer
, NULL
);
1749 if (Result
!= NULL
) {
1759 Save Question Value to edit copy(cached) or Storage(uncached).
1761 @param FormSet FormSet data structure.
1762 @param Form Form data structure.
1763 @param Question Pointer to the Question.
1764 @param SetValueTo Update the question value to editbuffer , buffer or hii driver.
1766 @retval EFI_SUCCESS The function completed successfully.
1771 IN FORM_BROWSER_FORMSET
*FormSet
,
1772 IN FORM_BROWSER_FORM
*Form
,
1773 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1774 IN GET_SET_QUESTION_VALUE_WITH SetValueTo
1784 BROWSER_STORAGE
*Storage
;
1785 FORMSET_STORAGE
*FormsetStorage
;
1786 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1791 BOOLEAN IsBufferStorage
;
1797 NAME_VALUE_NODE
*Node
;
1799 Status
= EFI_SUCCESS
;
1802 if (SetValueTo
>= GetSetValueWithMax
) {
1803 return EFI_INVALID_PARAMETER
;
1807 // If Question value is provided by an Expression, then it is read only
1809 if (Question
->ValueExpression
!= NULL
) {
1814 // Before set question value, evaluate its write expression.
1816 if (Question
->WriteExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1817 Status
= EvaluateExpression (FormSet
, Form
, Question
->WriteExpression
);
1818 if (EFI_ERROR (Status
)) {
1824 // Question value is provided by RTC
1826 Storage
= Question
->Storage
;
1827 QuestionValue
= &Question
->HiiValue
.Value
;
1828 if (Storage
== NULL
) {
1830 // It's a Question without storage, or RTC date/time
1832 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1834 // Date and time define the same Flags bit
1836 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1837 case QF_DATE_STORAGE_TIME
:
1838 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1841 case QF_DATE_STORAGE_WAKEUP
:
1842 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1845 case QF_DATE_STORAGE_NORMAL
:
1848 // For date/time without storage
1853 if (EFI_ERROR (Status
)) {
1857 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1858 EfiTime
.Year
= QuestionValue
->date
.Year
;
1859 EfiTime
.Month
= QuestionValue
->date
.Month
;
1860 EfiTime
.Day
= QuestionValue
->date
.Day
;
1862 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1863 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1864 EfiTime
.Second
= QuestionValue
->time
.Second
;
1867 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1868 Status
= gRT
->SetTime (&EfiTime
);
1870 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1878 // Question value is provided by EFI variable
1880 StorageWidth
= Question
->StorageWidth
;
1881 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1882 if (Question
->BufferValue
!= NULL
) {
1883 Src
= Question
->BufferValue
;
1885 Src
= (UINT8
*) QuestionValue
;
1888 Status
= gRT
->SetVariable (
1889 Question
->VariableName
,
1891 Storage
->Attributes
,
1899 // Question Value is provided by Buffer Storage or NameValue Storage
1901 if (Question
->BufferValue
!= NULL
) {
1902 Src
= Question
->BufferValue
;
1904 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1907 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1908 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1909 IsBufferStorage
= TRUE
;
1911 IsBufferStorage
= FALSE
;
1913 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1915 if (SetValueTo
== GetSetValueWithEditBuffer
|| SetValueTo
== GetSetValueWithBuffer
) {
1916 if (IsBufferStorage
) {
1917 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1919 // Copy to storage edit buffer
1921 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1922 } else if (SetValueTo
== GetSetValueWithBuffer
) {
1924 // Copy to storage edit buffer
1926 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1931 // Allocate enough string buffer.
1934 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1935 Value
= AllocateZeroPool (BufferLen
);
1936 ASSERT (Value
!= NULL
);
1938 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1940 TemName
= (CHAR16
*) Src
;
1942 for (; *TemName
!= L
'\0'; TemName
++) {
1943 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1946 BufferLen
= StorageWidth
* 2 + 1;
1947 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1948 ASSERT (Value
!= NULL
);
1950 // Convert Buffer to Hex String
1952 TemBuffer
= Src
+ StorageWidth
- 1;
1954 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1955 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1959 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
, SetValueTo
, &Node
);
1961 if (EFI_ERROR (Status
)) {
1965 } else if (SetValueTo
== GetSetValueWithHiiDriver
) {
1967 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1968 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1970 if (IsBufferStorage
) {
1971 Length
= StrLen (Question
->BlockName
) + 7;
1973 Length
= StrLen (Question
->VariableName
) + 2;
1975 if (!IsBufferStorage
&& IsString
) {
1976 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1978 Length
+= (StorageWidth
* 2);
1980 FormsetStorage
= GetFstStgFromVarId(FormSet
, Question
->VarStoreId
);
1981 ASSERT (FormsetStorage
!= NULL
);
1982 ConfigResp
= AllocateZeroPool ((StrLen (FormsetStorage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1983 ASSERT (ConfigResp
!= NULL
);
1985 StrCpy (ConfigResp
, FormsetStorage
->ConfigHdr
);
1986 if (IsBufferStorage
) {
1987 StrCat (ConfigResp
, Question
->BlockName
);
1988 StrCat (ConfigResp
, L
"&VALUE=");
1990 StrCat (ConfigResp
, L
"&");
1991 StrCat (ConfigResp
, Question
->VariableName
);
1992 StrCat (ConfigResp
, L
"=");
1995 Value
= ConfigResp
+ StrLen (ConfigResp
);
1997 if (!IsBufferStorage
&& IsString
) {
1999 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
2001 TemName
= (CHAR16
*) Src
;
2003 for (; *TemName
!= L
'\0'; TemName
++) {
2004 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
2008 // Convert Buffer to Hex String
2010 TemBuffer
= Src
+ StorageWidth
- 1;
2012 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
2013 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
2018 // Convert to lower char.
2020 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
2021 if (*Value
>= L
'A' && *Value
<= L
'Z') {
2022 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
2027 // Submit Question Value to Configuration Driver
2029 Status
= mHiiConfigRouting
->RouteConfig (
2034 if (EFI_ERROR (Status
)) {
2035 FreePool (ConfigResp
);
2038 FreePool (ConfigResp
);
2041 // Sync storage, from editbuffer to buffer.
2043 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
2051 Perform nosubmitif check for a Form.
2053 @param FormSet FormSet data structure.
2054 @param Form Form data structure.
2055 @param Question The Question to be validated.
2056 @param Type Validation type: NoSubmit
2058 @retval EFI_SUCCESS Form validation pass.
2059 @retval other Form validation failed.
2064 IN FORM_BROWSER_FORMSET
*FormSet
,
2065 IN FORM_BROWSER_FORM
*Form
,
2066 IN FORM_BROWSER_STATEMENT
*Question
,
2072 LIST_ENTRY
*ListHead
;
2073 FORM_EXPRESSION
*Expression
;
2074 UINT32 BrowserStatus
;
2077 BrowserStatus
= BROWSER_SUCCESS
;
2081 case EFI_HII_EXPRESSION_INCONSISTENT_IF
:
2082 ListHead
= &Question
->InconsistentListHead
;
2085 case EFI_HII_EXPRESSION_WARNING_IF
:
2086 ListHead
= &Question
->WarningListHead
;
2089 case EFI_HII_EXPRESSION_NO_SUBMIT_IF
:
2090 ListHead
= &Question
->NoSubmitListHead
;
2095 return EFI_UNSUPPORTED
;
2098 Link
= GetFirstNode (ListHead
);
2099 while (!IsNull (ListHead
, Link
)) {
2100 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
2103 // Evaluate the expression
2105 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
2106 if (EFI_ERROR (Status
)) {
2110 if (IsTrue (&Expression
->Result
)) {
2112 case EFI_HII_EXPRESSION_INCONSISTENT_IF
:
2113 BrowserStatus
= BROWSER_INCONSISTENT_IF
;
2116 case EFI_HII_EXPRESSION_WARNING_IF
:
2117 BrowserStatus
= BROWSER_WARNING_IF
;
2120 case EFI_HII_EXPRESSION_NO_SUBMIT_IF
:
2121 BrowserStatus
= BROWSER_NO_SUBMIT_IF
;
2123 // This code only used to compatible with old display engine,
2124 // New display engine will not use this field.
2126 if (Expression
->Error
!= 0) {
2127 ErrorStr
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
2136 if (!((Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) && mSystemSubmit
)) {
2138 // If in system submit process and for no_submit_if check, not popup this error message.
2139 // Will process this fail again later in not system submit process.
2141 PopupErrorMessage(BrowserStatus
, FormSet
->HiiHandle
, Expression
->OpCode
, ErrorStr
);
2144 if (ErrorStr
!= NULL
) {
2145 FreePool (ErrorStr
);
2148 if (Type
== EFI_HII_EXPRESSION_WARNING_IF
) {
2151 return EFI_NOT_READY
;
2155 Link
= GetNextNode (ListHead
, Link
);
2162 Perform question check.
2164 If one question has more than one check, process form high priority to low.
2165 Only one error info will be popup.
2167 @param FormSet FormSet data structure.
2168 @param Form Form data structure.
2169 @param Question The Question to be validated.
2171 @retval EFI_SUCCESS Form validation pass.
2172 @retval other Form validation failed.
2176 ValueChangedValidation (
2177 IN FORM_BROWSER_FORMSET
*FormSet
,
2178 IN FORM_BROWSER_FORM
*Form
,
2179 IN FORM_BROWSER_STATEMENT
*Question
2184 Status
= EFI_SUCCESS
;
2187 // Do the inconsistentif check.
2189 if (!IsListEmpty (&Question
->InconsistentListHead
)) {
2190 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_INCONSISTENT_IF
);
2191 if (EFI_ERROR (Status
)) {
2197 // Do the warningif check.
2199 if (!IsListEmpty (&Question
->WarningListHead
)) {
2200 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_WARNING_IF
);
2207 Perform NoSubmit check for each Form in FormSet.
2209 @param FormSet FormSet data structure.
2210 @param CurrentForm Current input form data structure.
2211 @param Statement The statement for this check.
2213 @retval EFI_SUCCESS Form validation pass.
2214 @retval other Form validation failed.
2219 IN FORM_BROWSER_FORMSET
*FormSet
,
2220 IN OUT FORM_BROWSER_FORM
**CurrentForm
,
2221 OUT FORM_BROWSER_STATEMENT
**Statement
2226 FORM_BROWSER_STATEMENT
*Question
;
2227 FORM_BROWSER_FORM
*Form
;
2228 LIST_ENTRY
*LinkForm
;
2230 LinkForm
= GetFirstNode (&FormSet
->FormListHead
);
2231 while (!IsNull (&FormSet
->FormListHead
, LinkForm
)) {
2232 Form
= FORM_BROWSER_FORM_FROM_LINK (LinkForm
);
2233 LinkForm
= GetNextNode (&FormSet
->FormListHead
, LinkForm
);
2235 if (*CurrentForm
!= NULL
&& *CurrentForm
!= Form
) {
2239 Link
= GetFirstNode (&Form
->StatementListHead
);
2240 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2241 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2242 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
2243 if (EFI_ERROR (Status
)) {
2244 if (*CurrentForm
== NULL
) {
2245 *CurrentForm
= Form
;
2247 if (Statement
!= NULL
) {
2248 *Statement
= Question
;
2253 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2261 Fill storage's edit copy with settings requested from Configuration Driver.
2263 @param Storage The storage which need to sync.
2264 @param ConfigRequest The config request string which used to sync storage.
2265 @param SyncOrRestore Sync the buffer to editbuffer or Restore the
2266 editbuffer to buffer
2267 if TRUE, copy the editbuffer to the buffer.
2268 if FALSE, copy the buffer to the editbuffer.
2270 @retval EFI_SUCCESS The function completed successfully.
2274 SynchronizeStorage (
2275 OUT BROWSER_STORAGE
*Storage
,
2276 IN CHAR16
*ConfigRequest
,
2277 IN BOOLEAN SyncOrRestore
2281 EFI_STRING Progress
;
2285 NAME_VALUE_NODE
*Node
;
2289 Status
= EFI_SUCCESS
;
2292 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
2293 (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
2294 BufferSize
= Storage
->Size
;
2296 if (SyncOrRestore
) {
2297 Src
= Storage
->EditBuffer
;
2298 Dst
= Storage
->Buffer
;
2300 Src
= Storage
->Buffer
;
2301 Dst
= Storage
->EditBuffer
;
2304 if (ConfigRequest
!= NULL
) {
2305 Status
= mHiiConfigRouting
->BlockToConfig(
2313 if (EFI_ERROR (Status
)) {
2317 Status
= mHiiConfigRouting
->ConfigToBlock (
2324 if (Result
!= NULL
) {
2328 CopyMem (Dst
, Src
, BufferSize
);
2330 } else if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2331 Link
= GetFirstNode (&Storage
->NameValueListHead
);
2332 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
2333 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
2335 if ((ConfigRequest
!= NULL
&& StrStr (ConfigRequest
, Node
->Name
) != NULL
) ||
2336 (ConfigRequest
== NULL
)) {
2337 if (SyncOrRestore
) {
2338 NewStringCpy (&Node
->Value
, Node
->EditValue
);
2340 NewStringCpy (&Node
->EditValue
, Node
->Value
);
2344 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
2352 When discard the question value, call the callback function with Changed type
2353 to inform the hii driver.
2355 @param FormSet FormSet data structure.
2356 @param Form Form data structure.
2360 SendDiscardInfoToDriver (
2361 IN FORM_BROWSER_FORMSET
*FormSet
,
2362 IN FORM_BROWSER_FORM
*Form
2366 FORM_BROWSER_STATEMENT
*Question
;
2367 EFI_IFR_TYPE_VALUE
*TypeValue
;
2368 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
2370 if (FormSet
->ConfigAccess
== NULL
) {
2374 Link
= GetFirstNode (&Form
->StatementListHead
);
2375 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2376 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2377 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2379 if (Question
->Storage
== NULL
|| Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2383 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != EFI_IFR_FLAG_CALLBACK
) {
2387 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
) {
2391 if (!Question
->ValueChanged
) {
2396 // Restore the question value before call the CHANGED callback type.
2398 GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
2400 if (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
) {
2401 TypeValue
= (EFI_IFR_TYPE_VALUE
*) Question
->BufferValue
;
2403 TypeValue
= &Question
->HiiValue
.Value
;
2406 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
2407 FormSet
->ConfigAccess
->Callback (
2408 FormSet
->ConfigAccess
,
2409 EFI_BROWSER_ACTION_CHANGED
,
2410 Question
->QuestionId
,
2411 Question
->HiiValue
.Type
,
2419 Validate the HiiHandle.
2421 @param HiiHandle The input HiiHandle which need to validate.
2423 @retval TRUE The handle is validate.
2424 @retval FALSE The handle is invalidate.
2429 EFI_HII_HANDLE HiiHandle
2432 EFI_HII_HANDLE
*HiiHandles
;
2436 if (HiiHandle
== NULL
) {
2442 HiiHandles
= HiiGetHiiHandles (NULL
);
2443 ASSERT (HiiHandles
!= NULL
);
2445 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
2446 if (HiiHandles
[Index
] == HiiHandle
) {
2452 FreePool (HiiHandles
);
2458 Validate the FormSet. If the formset is not validate, remove it from the list.
2460 @param FormSet The input FormSet which need to validate.
2462 @retval TRUE The handle is validate.
2463 @retval FALSE The handle is invalidate.
2468 FORM_BROWSER_FORMSET
*FormSet
2473 ASSERT (FormSet
!= NULL
);
2475 Find
= ValidateHiiHandle(FormSet
->HiiHandle
);
2477 // Should not remove the formset which is being used.
2479 if (!Find
&& (FormSet
!= gCurrentSelection
->FormSet
)) {
2480 CleanBrowserStorage(FormSet
);
2481 RemoveEntryList (&FormSet
->Link
);
2482 DestroyFormSet (FormSet
);
2488 Check whether need to enable the reset flag in form level.
2489 Also clean all ValueChanged flag in question.
2491 @param SetFlag Whether need to set the Reset Flag.
2492 @param FormSet FormSet data structure.
2493 @param Form Form data structure.
2499 IN FORM_BROWSER_FORMSET
*FormSet
,
2500 IN FORM_BROWSER_FORM
*Form
2504 FORM_BROWSER_STATEMENT
*Question
;
2507 Link
= GetFirstNode (&Form
->StatementListHead
);
2508 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2509 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2510 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2512 if (!Question
->ValueChanged
) {
2516 OldValue
= Question
->ValueChanged
;
2519 // Compare the buffer and editbuffer data to see whether the data has been saved.
2521 Question
->ValueChanged
= IsQuestionValueChanged(FormSet
, Form
, Question
, GetSetValueWithBothBuffer
);
2524 // Only the changed data has been saved, then need to set the reset flag.
2526 if (SetFlag
&& OldValue
&& !Question
->ValueChanged
&& ((Question
->QuestionFlags
& EFI_IFR_FLAG_RESET_REQUIRED
) != 0)) {
2527 gResetRequired
= TRUE
;
2533 Check whether need to enable the reset flag.
2534 Also clean ValueChanged flag for all statements.
2536 Form level or formset level, only one.
2538 @param SetFlag Whether need to set the Reset Flag.
2539 @param FormSet FormSet data structure.
2540 @param Form Form data structure.
2544 ValueChangeResetFlagUpdate (
2546 IN FORM_BROWSER_FORMSET
*FormSet
,
2547 IN FORM_BROWSER_FORM
*Form
2550 FORM_BROWSER_FORM
*CurrentForm
;
2554 UpdateFlagForForm(SetFlag
, FormSet
, Form
);
2558 Link
= GetFirstNode (&FormSet
->FormListHead
);
2559 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2560 CurrentForm
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2561 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2563 UpdateFlagForForm(SetFlag
, FormSet
, CurrentForm
);
2568 Base on the return Progress string to find the form.
2570 Base on the first return Offset/Width (Name) string to find the form
2571 which keep this string.
2573 @param FormSet FormSet data structure.
2574 @param Storage Storage which has this Progress string.
2575 @param Progress The Progress string which has the first fail string.
2576 @param RetForm The return form for this progress string.
2577 @param RetQuestion The return question for the error progress string.
2579 @retval TRUE Find the error form and statement for this error progress string.
2580 @retval FALSE Not find the error form.
2584 FindQuestionFromProgress (
2585 IN FORM_BROWSER_FORMSET
*FormSet
,
2586 IN BROWSER_STORAGE
*Storage
,
2587 IN EFI_STRING Progress
,
2588 OUT FORM_BROWSER_FORM
**RetForm
,
2589 OUT FORM_BROWSER_STATEMENT
**RetQuestion
2593 LIST_ENTRY
*LinkStorage
;
2594 LIST_ENTRY
*LinkStatement
;
2595 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2596 FORM_BROWSER_FORM
*Form
;
2598 FORM_BROWSER_STATEMENT
*Statement
;
2600 ASSERT ((*Progress
== '&') || (*Progress
== 'G'));
2604 *RetQuestion
= NULL
;
2607 // Skip the first "&" or the ConfigHdr part.
2609 if (*Progress
== '&') {
2613 // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string.
2615 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2617 // For Name/Value type, Skip the ConfigHdr part.
2619 EndStr
= StrStr (Progress
, L
"PATH=");
2620 ASSERT (EndStr
!= NULL
);
2621 while (*EndStr
!= '&') {
2628 // For Buffer type, Skip the ConfigHdr part.
2630 EndStr
= StrStr (Progress
, L
"&OFFSET=");
2631 ASSERT (EndStr
!= NULL
);
2635 Progress
= EndStr
+ 1;
2639 // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string.
2641 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2643 // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset,
2644 // here, just keep the "Fred" string.
2646 EndStr
= StrStr (Progress
, L
"=");
2647 ASSERT (EndStr
!= NULL
);
2651 // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####",
2652 // here, just keep the "OFFSET=0x####&WIDTH=0x####" string.
2654 EndStr
= StrStr (Progress
, L
"&VALUE=");
2655 ASSERT (EndStr
!= NULL
);
2660 // Search in the form list.
2662 Link
= GetFirstNode (&FormSet
->FormListHead
);
2663 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2664 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2665 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2668 // Search in the ConfigReqeust list in this form.
2670 LinkStorage
= GetFirstNode (&Form
->ConfigRequestHead
);
2671 while (!IsNull (&Form
->ConfigRequestHead
, LinkStorage
)) {
2672 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (LinkStorage
);
2673 LinkStorage
= GetNextNode (&Form
->ConfigRequestHead
, LinkStorage
);
2675 if (Storage
!= ConfigInfo
->Storage
) {
2679 if (StrStr (ConfigInfo
->ConfigRequest
, Progress
) != NULL
) {
2681 // Find the OffsetWidth string in this form.
2688 if (*RetForm
!= NULL
) {
2689 LinkStatement
= GetFirstNode (&Form
->StatementListHead
);
2690 while (!IsNull (&Form
->StatementListHead
, LinkStatement
)) {
2691 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (LinkStatement
);
2692 LinkStatement
= GetNextNode (&Form
->StatementListHead
, LinkStatement
);
2694 if (Statement
->BlockName
!= NULL
&& StrStr (Statement
->BlockName
, Progress
) != NULL
) {
2695 *RetQuestion
= Statement
;
2699 if (Statement
->VariableName
!= NULL
&& StrStr (Statement
->VariableName
, Progress
) != NULL
) {
2700 *RetQuestion
= Statement
;
2706 if (*RetForm
!= NULL
) {
2712 // restore the OffsetWidth string to the original format.
2714 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2720 return (BOOLEAN
) (*RetForm
!= NULL
);
2724 Popup an save error info and get user input.
2726 @param TitleId The form title id.
2727 @param HiiHandle The hii handle for this package.
2729 @retval UINT32 The user select option for the save fail.
2730 BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET
2734 IN EFI_STRING_ID TitleId
,
2735 IN EFI_HII_HANDLE HiiHandle
2739 CHAR16
*StringBuffer
;
2742 FormTitle
= GetToken (TitleId
, HiiHandle
);
2744 StringBuffer
= AllocateZeroPool (256 * sizeof (CHAR16
));
2745 ASSERT (StringBuffer
!= NULL
);
2749 24 * sizeof (CHAR16
) + StrSize (FormTitle
),
2750 L
"Submit Fail For Form: %s.",
2754 RetVal
= PopupErrorMessage(BROWSER_SUBMIT_FAIL
, NULL
, NULL
, StringBuffer
);
2756 FreePool (StringBuffer
);
2757 FreePool (FormTitle
);
2763 Popup an NO_SUBMIT_IF error info and get user input.
2765 @param TitleId The form title id.
2766 @param HiiHandle The hii handle for this package.
2768 @retval UINT32 The user select option for the save fail.
2769 BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET
2772 ConfirmNoSubmitFail (
2773 IN EFI_STRING_ID TitleId
,
2774 IN EFI_HII_HANDLE HiiHandle
2778 CHAR16
*StringBuffer
;
2781 FormTitle
= GetToken (TitleId
, HiiHandle
);
2783 StringBuffer
= AllocateZeroPool (256 * sizeof (CHAR16
));
2784 ASSERT (StringBuffer
!= NULL
);
2788 24 * sizeof (CHAR16
) + StrSize (FormTitle
),
2789 L
"NO_SUBMIT_IF error For Form: %s.",
2793 RetVal
= PopupErrorMessage(BROWSER_SUBMIT_FAIL_NO_SUBMIT_IF
, NULL
, NULL
, StringBuffer
);
2795 FreePool (StringBuffer
);
2796 FreePool (FormTitle
);
2802 Discard data based on the input setting scope (Form, FormSet or System).
2804 @param FormSet FormSet data structure.
2805 @param Form Form data structure.
2806 @param SettingScope Setting Scope for Discard action.
2808 @retval EFI_SUCCESS The function completed successfully.
2809 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2814 IN FORM_BROWSER_FORMSET
*FormSet
,
2815 IN FORM_BROWSER_FORM
*Form
,
2816 IN BROWSER_SETTING_SCOPE SettingScope
2820 FORMSET_STORAGE
*Storage
;
2821 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2822 FORM_BROWSER_FORMSET
*LocalFormSet
;
2823 FORM_BROWSER_FORMSET
*OldFormSet
;
2826 // Check the supported setting level.
2828 if (SettingScope
>= MaxLevel
) {
2829 return EFI_UNSUPPORTED
;
2832 if (SettingScope
== FormLevel
&& IsNvUpdateRequiredForForm (Form
)) {
2834 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
2835 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
2836 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
2837 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
2839 if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2844 // Skip if there is no RequestElement
2846 if (ConfigInfo
->ElementCount
== 0) {
2851 // Prepare <ConfigResp>
2853 SynchronizeStorage(ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, FALSE
);
2856 // Call callback with Changed type to inform the driver.
2858 SendDiscardInfoToDriver (FormSet
, Form
);
2861 ValueChangeResetFlagUpdate (FALSE
, FormSet
, Form
);
2862 } else if (SettingScope
== FormSetLevel
&& IsNvUpdateRequiredForFormSet (FormSet
)) {
2865 // Discard Buffer storage or Name/Value storage
2867 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2868 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2869 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2870 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2872 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2877 // Skip if there is no RequestElement
2879 if (Storage
->ElementCount
== 0) {
2883 SynchronizeStorage(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
2886 Link
= GetFirstNode (&FormSet
->FormListHead
);
2887 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2888 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2889 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2892 // Call callback with Changed type to inform the driver.
2894 SendDiscardInfoToDriver (FormSet
, Form
);
2897 ValueChangeResetFlagUpdate(FALSE
, FormSet
, NULL
);
2898 } else if (SettingScope
== SystemLevel
) {
2900 // System Level Discard.
2902 OldFormSet
= mSystemLevelFormSet
;
2905 // Discard changed value for each FormSet in the maintain list.
2907 Link
= GetFirstNode (&gBrowserFormSetList
);
2908 while (!IsNull (&gBrowserFormSetList
, Link
)) {
2909 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
2910 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
2911 if (!ValidateFormSet(LocalFormSet
)) {
2915 mSystemLevelFormSet
= LocalFormSet
;
2917 DiscardForm (LocalFormSet
, NULL
, FormSetLevel
);
2918 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
2920 // Remove maintain backup list after discard except for the current using FormSet.
2922 CleanBrowserStorage(LocalFormSet
);
2923 RemoveEntryList (&LocalFormSet
->Link
);
2924 DestroyFormSet (LocalFormSet
);
2928 mSystemLevelFormSet
= OldFormSet
;
2935 Submit data for a form.
2937 @param FormSet FormSet data structure.
2938 @param Form Form data structure.
2940 @retval EFI_SUCCESS The function completed successfully.
2941 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2946 IN FORM_BROWSER_FORMSET
*FormSet
,
2947 IN FORM_BROWSER_FORM
*Form
2952 EFI_STRING ConfigResp
;
2953 EFI_STRING Progress
;
2954 BROWSER_STORAGE
*Storage
;
2955 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2957 if (!IsNvUpdateRequiredForForm (Form
)) {
2961 Status
= NoSubmitCheck (FormSet
, &Form
, NULL
);
2962 if (EFI_ERROR (Status
)) {
2966 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
2967 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
2968 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
2969 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
2971 Storage
= ConfigInfo
->Storage
;
2972 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2977 // Skip if there is no RequestElement
2979 if (ConfigInfo
->ElementCount
== 0) {
2984 // 1. Prepare <ConfigResp>
2986 Status
= StorageToConfigResp (ConfigInfo
->Storage
, &ConfigResp
, ConfigInfo
->ConfigRequest
, TRUE
);
2987 if (EFI_ERROR (Status
)) {
2992 // 2. Set value to hii config routine protocol.
2994 Status
= mHiiConfigRouting
->RouteConfig (
2999 FreePool (ConfigResp
);
3001 if (EFI_ERROR (Status
)) {
3002 InsertTailList (&gBrowserSaveFailFormSetList
, &ConfigInfo
->SaveFailLink
);
3007 // 3. Config success, update storage shadow Buffer, only update the data belong to this form.
3009 SynchronizeStorage (ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, TRUE
);
3013 // 4. Process the save failed storage.
3015 if (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3016 if (ConfirmSaveFail (Form
->FormTitle
, FormSet
->HiiHandle
) == BROWSER_ACTION_DISCARD
) {
3017 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3018 while (!IsNull (&gBrowserSaveFailFormSetList
, Link
)) {
3019 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link
);
3020 Link
= GetNextNode (&gBrowserSaveFailFormSetList
, Link
);
3022 SynchronizeStorage(ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, FALSE
);
3024 Status
= EFI_SUCCESS
;
3027 Status
= EFI_UNSUPPORTED
;
3031 // Free Form save fail list.
3033 while (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3034 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3035 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link
);
3036 RemoveEntryList (&ConfigInfo
->SaveFailLink
);
3041 // 5. Update the NV flag.
3043 ValueChangeResetFlagUpdate(TRUE
, FormSet
, Form
);
3049 Submit data for a formset.
3051 @param FormSet FormSet data structure.
3052 @param SkipProcessFail Whether skip to process the save failed storage.
3053 If submit formset is called when do system level save,
3054 set this value to true and process the failed formset
3056 if submit formset is called when do formset level save,
3057 set the value to false and process the failed storage
3058 right after process all storages for this formset.
3060 @retval EFI_SUCCESS The function completed successfully.
3061 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3066 IN FORM_BROWSER_FORMSET
*FormSet
,
3067 IN BOOLEAN SkipProcessFail
3072 EFI_STRING ConfigResp
;
3073 EFI_STRING Progress
;
3074 BROWSER_STORAGE
*Storage
;
3075 FORMSET_STORAGE
*FormSetStorage
;
3076 FORM_BROWSER_FORM
*Form
;
3077 BOOLEAN HasInserted
;
3078 FORM_BROWSER_STATEMENT
*Question
;
3080 HasInserted
= FALSE
;
3082 if (!IsNvUpdateRequiredForFormSet (FormSet
)) {
3087 Status
= NoSubmitCheck (FormSet
, &Form
, &Question
);
3088 if (EFI_ERROR (Status
)) {
3089 if (SkipProcessFail
) {
3091 // Process NO_SUBMIT check first, so insert it at head.
3093 FormSet
->SaveFailForm
= Form
;
3094 FormSet
->SaveFailStatement
= Question
;
3095 InsertHeadList (&gBrowserSaveFailFormSetList
, &FormSet
->SaveFailLink
);
3104 // Submit Buffer storage or Name/Value storage
3106 Link
= GetFirstNode (&FormSet
->StorageListHead
);
3107 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
3108 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
3109 Storage
= FormSetStorage
->BrowserStorage
;
3110 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
3112 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
3117 // Skip if there is no RequestElement
3119 if (FormSetStorage
->ElementCount
== 0) {
3124 // 1. Prepare <ConfigResp>
3126 Status
= StorageToConfigResp (Storage
, &ConfigResp
, FormSetStorage
->ConfigRequest
, TRUE
);
3127 if (EFI_ERROR (Status
)) {
3132 // 2. Send <ConfigResp> to Routine config Protocol.
3134 Status
= mHiiConfigRouting
->RouteConfig (
3139 if (EFI_ERROR (Status
)) {
3140 InsertTailList (&FormSet
->SaveFailStorageListHead
, &FormSetStorage
->SaveFailLink
);
3143 // Call submit formset for system level, save the formset info
3144 // and process later.
3146 FindQuestionFromProgress(FormSet
, Storage
, Progress
, &Form
, &Question
);
3147 ASSERT (Form
!= NULL
&& Question
!= NULL
);
3148 FormSet
->SaveFailForm
= Form
;
3149 FormSet
->SaveFailStatement
= Question
;
3150 if (SkipProcessFail
) {
3151 InsertTailList (&gBrowserSaveFailFormSetList
, &FormSet
->SaveFailLink
);
3156 FreePool (ConfigResp
);
3160 FreePool (ConfigResp
);
3162 // 3. Config success, update storage shadow Buffer
3164 SynchronizeStorage (Storage
, FormSetStorage
->ConfigRequest
, TRUE
);
3168 // 4. Has save fail storage need to handle.
3171 if (!SkipProcessFail
) {
3173 // If not in system level, just handl the save failed storage here.
3175 if (ConfirmSaveFail (Form
->FormTitle
, FormSet
->HiiHandle
) == BROWSER_ACTION_DISCARD
) {
3176 Link
= GetFirstNode (&FormSet
->SaveFailStorageListHead
);
3177 while (!IsNull (&FormSet
->SaveFailStorageListHead
, Link
)) {
3178 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link
);
3179 Storage
= FormSetStorage
->BrowserStorage
;
3180 Link
= GetNextNode (&FormSet
->SaveFailStorageListHead
, Link
);
3182 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3184 Status
= EFI_SUCCESS
;
3187 UiCopyMenuList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &Form
->FormViewListHead
);
3189 gCurrentSelection
->Action
= UI_ACTION_REFRESH_FORMSET
;
3190 gCurrentSelection
->Handle
= FormSet
->HiiHandle
;
3191 CopyGuid (&gCurrentSelection
->FormSetGuid
, &FormSet
->Guid
);
3192 gCurrentSelection
->FormId
= Form
->FormId
;
3193 gCurrentSelection
->QuestionId
= Question
->QuestionId
;
3195 Status
= EFI_UNSUPPORTED
;
3199 // Free FormSet save fail list.
3201 while (!IsListEmpty (&FormSet
->SaveFailStorageListHead
)) {
3202 Link
= GetFirstNode (&FormSet
->SaveFailStorageListHead
);
3203 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link
);
3204 RemoveEntryList (&FormSetStorage
->SaveFailLink
);
3208 // If in system level, just return error and handle the failed formset later.
3210 Status
= EFI_UNSUPPORTED
;
3215 // 5. Update the NV flag.
3217 ValueChangeResetFlagUpdate(TRUE
, FormSet
, NULL
);
3223 Submit data for all formsets.
3225 @retval EFI_SUCCESS The function completed successfully.
3226 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3236 LIST_ENTRY
*StorageLink
;
3237 FORMSET_STORAGE
*FormSetStorage
;
3238 FORM_BROWSER_FORM
*Form
;
3239 FORM_BROWSER_FORMSET
*LocalFormSet
;
3240 UINT32 UserSelection
;
3241 FORM_BROWSER_STATEMENT
*Question
;
3243 mSystemSubmit
= TRUE
;
3244 Link
= GetFirstNode (&gBrowserFormSetList
);
3245 while (!IsNull (&gBrowserFormSetList
, Link
)) {
3246 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
3247 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
3248 if (!ValidateFormSet(LocalFormSet
)) {
3252 Status
= SubmitForFormSet (LocalFormSet
, TRUE
);
3253 if (EFI_ERROR (Status
)) {
3258 // Remove maintain backup list after save except for the current using FormSet.
3260 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
3261 CleanBrowserStorage(LocalFormSet
);
3262 RemoveEntryList (&LocalFormSet
->Link
);
3263 DestroyFormSet (LocalFormSet
);
3266 mSystemSubmit
= FALSE
;
3268 Status
= EFI_SUCCESS
;
3271 // Process the save failed formsets.
3273 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3274 while (!IsNull (&gBrowserSaveFailFormSetList
, Link
)) {
3275 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link
);
3276 Link
= GetNextNode (&gBrowserSaveFailFormSetList
, Link
);
3278 if (!ValidateFormSet(LocalFormSet
)) {
3282 Form
= LocalFormSet
->SaveFailForm
;
3283 Question
= LocalFormSet
->SaveFailStatement
;
3286 // Confirm with user, get user input.
3288 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3290 // NULL for SaveFailStorageListHead means error caused by NO_SUBMIT_IF check.
3292 UserSelection
= ConfirmNoSubmitFail (Form
->FormTitle
, LocalFormSet
->HiiHandle
);
3294 UserSelection
= ConfirmSaveFail (Form
->FormTitle
, LocalFormSet
->HiiHandle
);
3297 if (UserSelection
== BROWSER_ACTION_DISCARD
) {
3298 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3299 StorageLink
= GetFirstNode (&LocalFormSet
->StorageListHead
);
3300 while (!IsNull (&LocalFormSet
->StorageListHead
, StorageLink
)) {
3301 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (StorageLink
);
3302 StorageLink
= GetNextNode (&LocalFormSet
->StorageListHead
, StorageLink
);
3304 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3307 StorageLink
= GetFirstNode (&LocalFormSet
->SaveFailStorageListHead
);
3308 while (!IsNull (&LocalFormSet
->SaveFailStorageListHead
, StorageLink
)) {
3309 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink
);
3310 StorageLink
= GetNextNode (&LocalFormSet
->SaveFailStorageListHead
, StorageLink
);
3312 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3316 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
3317 CleanBrowserStorage(LocalFormSet
);
3318 RemoveEntryList (&LocalFormSet
->Link
);
3319 RemoveEntryList (&LocalFormSet
->SaveFailLink
);
3320 DestroyFormSet (LocalFormSet
);
3322 ValueChangeResetFlagUpdate(FALSE
, LocalFormSet
, NULL
);
3325 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3326 NoSubmitCheck (LocalFormSet
, &Form
, &Question
);
3329 UiCopyMenuList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &Form
->FormViewListHead
);
3331 gCurrentSelection
->Action
= UI_ACTION_REFRESH_FORMSET
;
3332 gCurrentSelection
->Handle
= LocalFormSet
->HiiHandle
;
3333 CopyGuid (&gCurrentSelection
->FormSetGuid
, &LocalFormSet
->Guid
);
3334 gCurrentSelection
->FormId
= Form
->FormId
;
3335 gCurrentSelection
->QuestionId
= Question
->QuestionId
;
3337 Status
= EFI_UNSUPPORTED
;
3343 // Clean the list which will not process.
3345 while (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3346 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3347 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link
);
3348 RemoveEntryList (&LocalFormSet
->SaveFailLink
);
3350 while (!IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3351 StorageLink
= GetFirstNode (&LocalFormSet
->SaveFailStorageListHead
);
3352 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink
);
3353 RemoveEntryList (&FormSetStorage
->SaveFailLink
);
3361 Submit data based on the input Setting level (Form, FormSet or System).
3363 @param FormSet FormSet data structure.
3364 @param Form Form data structure.
3365 @param SettingScope Setting Scope for Submit action.
3367 @retval EFI_SUCCESS The function completed successfully.
3368 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3373 IN FORM_BROWSER_FORMSET
*FormSet
,
3374 IN FORM_BROWSER_FORM
*Form
,
3375 IN BROWSER_SETTING_SCOPE SettingScope
3380 switch (SettingScope
) {
3382 Status
= SubmitForForm(FormSet
, Form
);
3386 Status
= SubmitForFormSet (FormSet
, FALSE
);
3390 Status
= SubmitForSystem ();
3394 Status
= EFI_UNSUPPORTED
;
3402 Converts the unicode character of the string from uppercase to lowercase.
3403 This is a internal function.
3405 @param ConfigString String to be converted
3411 IN EFI_STRING ConfigString
3417 ASSERT (ConfigString
!= NULL
);
3420 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
3422 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
3423 if (*String
== L
'=') {
3425 } else if (*String
== L
'&') {
3427 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
3428 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
3434 Find the point in the ConfigResp string for this question.
3436 @param Question The question.
3437 @param ConfigResp Get ConfigResp string.
3439 @retval point to the offset where is for this question.
3443 GetOffsetFromConfigResp (
3444 IN FORM_BROWSER_STATEMENT
*Question
,
3445 IN CHAR16
*ConfigResp
3448 CHAR16
*RequestElement
;
3452 // Type is EFI_HII_VARSTORE_NAME_VALUE.
3454 if (Question
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3455 RequestElement
= StrStr (ConfigResp
, Question
->VariableName
);
3456 if (RequestElement
!= NULL
) {
3458 // Skip the "VariableName=" field.
3460 RequestElement
+= StrLen (Question
->VariableName
) + 1;
3463 return RequestElement
;
3467 // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
3471 // 1. Directly use Question->BlockName to find.
3473 RequestElement
= StrStr (ConfigResp
, Question
->BlockName
);
3474 if (RequestElement
!= NULL
) {
3476 // Skip the "Question->BlockName&VALUE=" field.
3478 RequestElement
+= StrLen (Question
->BlockName
) + StrLen (L
"&VALUE=");
3479 return RequestElement
;
3483 // 2. Change all hex digits in Question->BlockName to lower and compare again.
3485 BlockData
= AllocateCopyPool (StrSize(Question
->BlockName
), Question
->BlockName
);
3486 ASSERT (BlockData
!= NULL
);
3487 HiiToLower (BlockData
);
3488 RequestElement
= StrStr (ConfigResp
, BlockData
);
3489 FreePool (BlockData
);
3491 if (RequestElement
!= NULL
) {
3493 // Skip the "Question->BlockName&VALUE=" field.
3495 RequestElement
+= StrLen (Question
->BlockName
) + StrLen (L
"&VALUE=");
3498 return RequestElement
;
3502 Get Question default value from AltCfg string.
3504 @param FormSet The form set.
3505 @param Form The form
3506 @param Question The question.
3508 @retval EFI_SUCCESS Question is reset to default value.
3512 GetDefaultValueFromAltCfg (
3513 IN FORM_BROWSER_FORMSET
*FormSet
,
3514 IN FORM_BROWSER_FORM
*Form
,
3515 IN OUT FORM_BROWSER_STATEMENT
*Question
3518 BROWSER_STORAGE
*Storage
;
3519 FORMSET_STORAGE
*FormSetStorage
;
3523 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
3525 Storage
= Question
->Storage
;
3526 if ((Storage
== NULL
) || (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
3527 return EFI_NOT_FOUND
;
3531 // Try to get AltCfg string from form. If not found it, then
3532 // try to get it from formset.
3535 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
3536 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
3537 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
3538 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
3540 if (Storage
== ConfigInfo
->Storage
) {
3541 ConfigResp
= ConfigInfo
->ConfigAltResp
;
3546 if (ConfigResp
== NULL
) {
3547 Link
= GetFirstNode (&FormSet
->StorageListHead
);
3548 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
3549 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
3550 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
3552 if (Storage
== FormSetStorage
->BrowserStorage
) {
3553 ConfigResp
= FormSetStorage
->ConfigAltResp
;
3559 if (ConfigResp
== NULL
) {
3560 return EFI_NOT_FOUND
;
3563 Value
= GetOffsetFromConfigResp (Question
, ConfigResp
);
3564 if (Value
== NULL
) {
3565 return EFI_NOT_FOUND
;
3568 return BufferToValue (Question
, Value
);
3572 Get default Id value used for browser.
3574 @param DefaultId The default id value used by hii.
3576 @retval Browser used default value.
3580 GetDefaultIdForCallBack (
3584 if (DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) {
3585 return EFI_BROWSER_ACTION_DEFAULT_STANDARD
;
3586 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3587 return EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
;
3588 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_SAFE
) {
3589 return EFI_BROWSER_ACTION_DEFAULT_SAFE
;
3590 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
+ 0x1000) {
3591 return EFI_BROWSER_ACTION_DEFAULT_PLATFORM
+ DefaultId
- EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
;
3592 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
+ 0x1000) {
3593 return EFI_BROWSER_ACTION_DEFAULT_HARDWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
;
3594 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
+ 0x1000) {
3595 return EFI_BROWSER_ACTION_DEFAULT_FIRMWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
;
3604 Return data element in an Array by its Index.
3606 @param Array The data array.
3607 @param Type Type of the data in this array.
3608 @param Index Zero based index for data in this array.
3610 @retval Value The data to be returned
3622 ASSERT (Array
!= NULL
);
3626 case EFI_IFR_TYPE_NUM_SIZE_8
:
3627 Data
= (UINT64
) *(((UINT8
*) Array
) + Index
);
3630 case EFI_IFR_TYPE_NUM_SIZE_16
:
3631 Data
= (UINT64
) *(((UINT16
*) Array
) + Index
);
3634 case EFI_IFR_TYPE_NUM_SIZE_32
:
3635 Data
= (UINT64
) *(((UINT32
*) Array
) + Index
);
3638 case EFI_IFR_TYPE_NUM_SIZE_64
:
3639 Data
= (UINT64
) *(((UINT64
*) Array
) + Index
);
3651 Set value of a data element in an Array by its Index.
3653 @param Array The data array.
3654 @param Type Type of the data in this array.
3655 @param Index Zero based index for data in this array.
3656 @param Value The value to be set.
3668 ASSERT (Array
!= NULL
);
3671 case EFI_IFR_TYPE_NUM_SIZE_8
:
3672 *(((UINT8
*) Array
) + Index
) = (UINT8
) Value
;
3675 case EFI_IFR_TYPE_NUM_SIZE_16
:
3676 *(((UINT16
*) Array
) + Index
) = (UINT16
) Value
;
3679 case EFI_IFR_TYPE_NUM_SIZE_32
:
3680 *(((UINT32
*) Array
) + Index
) = (UINT32
) Value
;
3683 case EFI_IFR_TYPE_NUM_SIZE_64
:
3684 *(((UINT64
*) Array
) + Index
) = (UINT64
) Value
;
3693 Search an Option of a Question by its value.
3695 @param Question The Question
3696 @param OptionValue Value for Option to be searched.
3698 @retval Pointer Pointer to the found Option.
3699 @retval NULL Option not found.
3704 IN FORM_BROWSER_STATEMENT
*Question
,
3705 IN EFI_HII_VALUE
*OptionValue
3709 QUESTION_OPTION
*Option
;
3712 Link
= GetFirstNode (&Question
->OptionListHead
);
3713 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3714 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3716 if ((CompareHiiValue (&Option
->Value
, OptionValue
, &Result
, NULL
) == EFI_SUCCESS
) && (Result
== 0)) {
3718 // Check the suppressif condition, only a valid option can be return.
3720 if ((Option
->SuppressExpression
== NULL
) ||
3721 ((EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) == ExpressFalse
))) {
3726 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3734 Reset Question to its default value.
3736 @param FormSet The form set.
3737 @param Form The form.
3738 @param Question The question.
3739 @param DefaultId The Class of the default.
3741 @retval EFI_SUCCESS Question is reset to default value.
3745 GetQuestionDefault (
3746 IN FORM_BROWSER_FORMSET
*FormSet
,
3747 IN FORM_BROWSER_FORM
*Form
,
3748 IN FORM_BROWSER_STATEMENT
*Question
,
3754 QUESTION_DEFAULT
*Default
;
3755 QUESTION_OPTION
*Option
;
3756 EFI_HII_VALUE
*HiiValue
;
3758 EFI_STRING StrValue
;
3759 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
3760 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
3764 Status
= EFI_NOT_FOUND
;
3768 // Statement don't have storage, skip them
3770 if (Question
->QuestionId
== 0) {
3775 // There are Five ways to specify default value for a Question:
3776 // 1, use call back function (highest priority)
3777 // 2, use ExtractConfig function
3778 // 3, use nested EFI_IFR_DEFAULT
3779 // 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
3780 // 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
3782 HiiValue
= &Question
->HiiValue
;
3785 // Get Question defaut value from call back function.
3787 ConfigAccess
= FormSet
->ConfigAccess
;
3788 Action
= GetDefaultIdForCallBack (DefaultId
);
3789 if ((Action
> 0) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
3790 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
3791 Status
= ConfigAccess
->Callback (
3794 Question
->QuestionId
,
3799 if (!EFI_ERROR (Status
)) {
3800 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
3801 NewString
= GetToken (Question
->HiiValue
.Value
.string
, FormSet
->HiiHandle
);
3802 ASSERT (NewString
!= NULL
);
3804 ASSERT (StrLen (NewString
) * sizeof (CHAR16
) <= Question
->StorageWidth
);
3805 if (StrLen (NewString
) * sizeof (CHAR16
) <= Question
->StorageWidth
) {
3806 CopyMem (Question
->BufferValue
, NewString
, StrSize (NewString
));
3808 CopyMem (Question
->BufferValue
, NewString
, Question
->StorageWidth
);
3811 FreePool (NewString
);
3818 // Get default value from altcfg string.
3820 if (ConfigAccess
!= NULL
) {
3821 Status
= GetDefaultValueFromAltCfg(FormSet
, Form
, Question
);
3822 if (!EFI_ERROR (Status
)) {
3828 // EFI_IFR_DEFAULT has highest priority
3830 if (!IsListEmpty (&Question
->DefaultListHead
)) {
3831 Link
= GetFirstNode (&Question
->DefaultListHead
);
3832 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
3833 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
3835 if (Default
->DefaultId
== DefaultId
) {
3836 if (Default
->ValueExpression
!= NULL
) {
3838 // Default is provided by an Expression, evaluate it
3840 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
3841 if (EFI_ERROR (Status
)) {
3845 if (Default
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
3846 ASSERT (HiiValue
->Type
== EFI_IFR_TYPE_BUFFER
&& Question
->BufferValue
!= NULL
);
3847 if (Question
->StorageWidth
> Default
->ValueExpression
->Result
.BufferLen
) {
3848 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Default
->ValueExpression
->Result
.BufferLen
);
3849 Question
->HiiValue
.BufferLen
= Default
->ValueExpression
->Result
.BufferLen
;
3851 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
3852 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
3854 FreePool (Default
->ValueExpression
->Result
.Buffer
);
3856 HiiValue
->Type
= Default
->ValueExpression
->Result
.Type
;
3857 CopyMem (&HiiValue
->Value
, &Default
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
3860 // Default value is embedded in EFI_IFR_DEFAULT
3862 if (Default
->Value
.Type
== EFI_IFR_TYPE_BUFFER
) {
3863 ASSERT (HiiValue
->Buffer
!= NULL
);
3864 CopyMem (HiiValue
->Buffer
, Default
->Value
.Buffer
, Default
->Value
.BufferLen
);
3866 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
3870 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
3871 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
3872 if (StrValue
== NULL
) {
3873 return EFI_NOT_FOUND
;
3875 if (Question
->StorageWidth
> StrSize (StrValue
)) {
3876 CopyMem (Question
->BufferValue
, StrValue
, StrSize (StrValue
));
3878 CopyMem (Question
->BufferValue
, StrValue
, Question
->StorageWidth
);
3885 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
3890 // EFI_ONE_OF_OPTION
3892 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
3893 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3895 // OneOfOption could only provide Standard and Manufacturing default
3897 Link
= GetFirstNode (&Question
->OptionListHead
);
3898 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3899 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3900 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3902 if ((Option
->SuppressExpression
!= NULL
) &&
3903 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3907 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
3908 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
3910 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
3919 // EFI_IFR_CHECKBOX - lowest priority
3921 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
3922 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3924 // Checkbox could only provide Standard and Manufacturing default
3926 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
3927 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
3929 HiiValue
->Value
.b
= TRUE
;
3931 HiiValue
->Value
.b
= FALSE
;
3939 // For Questions without default
3941 Status
= EFI_NOT_FOUND
;
3942 switch (Question
->Operand
) {
3943 case EFI_IFR_NUMERIC_OP
:
3945 // Take minimum value as numeric default value
3947 if ((HiiValue
->Value
.u64
< Question
->Minimum
) || (HiiValue
->Value
.u64
> Question
->Maximum
)) {
3948 HiiValue
->Value
.u64
= Question
->Minimum
;
3949 Status
= EFI_SUCCESS
;
3953 case EFI_IFR_ONE_OF_OP
:
3955 // Take first oneof option as oneof's default value
3957 if (ValueToOption (Question
, HiiValue
) == NULL
) {
3958 Link
= GetFirstNode (&Question
->OptionListHead
);
3959 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3960 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3961 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3963 if ((Option
->SuppressExpression
!= NULL
) &&
3964 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3968 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
3969 Status
= EFI_SUCCESS
;
3975 case EFI_IFR_ORDERED_LIST_OP
:
3977 // Take option sequence in IFR as ordered list's default value
3980 Link
= GetFirstNode (&Question
->OptionListHead
);
3981 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3982 Status
= EFI_SUCCESS
;
3983 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3984 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3986 if ((Option
->SuppressExpression
!= NULL
) &&
3987 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3991 SetArrayData (Question
->BufferValue
, Question
->ValueType
, Index
, Option
->Value
.Value
.u64
);
3994 if (Index
>= Question
->MaxContainers
) {
4008 Get AltCfg string for current form.
4010 @param FormSet Form data structure.
4011 @param Form Form data structure.
4012 @param DefaultId The Class of the default.
4013 @param BrowserStorage The input request storage for the questions.
4017 ExtractAltCfgForForm (
4018 IN FORM_BROWSER_FORMSET
*FormSet
,
4019 IN FORM_BROWSER_FORM
*Form
,
4020 IN UINT16 DefaultId
,
4021 IN BROWSER_STORAGE
*BrowserStorage
4029 BROWSER_STORAGE
*Storage
;
4030 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
4031 FORMSET_STORAGE
*FormSetStorage
;
4034 // Check whether has get AltCfg string for this formset.
4035 // If yes, no need to get AltCfg for form.
4037 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4038 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4039 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4040 Storage
= FormSetStorage
->BrowserStorage
;
4041 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4042 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4046 if (Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
&&
4047 FormSetStorage
->ElementCount
!= 0 &&
4048 FormSetStorage
->HasCallAltCfg
) {
4054 // Get AltCfg string for each form.
4056 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
4057 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
4058 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
4059 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
4061 Storage
= ConfigInfo
->Storage
;
4062 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4066 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
4071 // 1. Skip if there is no RequestElement
4073 if (ConfigInfo
->ElementCount
== 0) {
4078 // 2. Get value through hii config routine protocol.
4080 Status
= mHiiConfigRouting
->ExtractConfig (
4082 ConfigInfo
->ConfigRequest
,
4086 if (EFI_ERROR (Status
)) {
4091 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
4092 // Get the default configuration string according to the default ID.
4094 Status
= mHiiConfigRouting
->GetAltConfig (
4100 &DefaultId
, // it can be NULL to get the current setting.
4104 if (EFI_ERROR (Status
)) {
4108 ConfigInfo
->ConfigAltResp
= ConfigResp
;
4113 Clean AltCfg string for current form.
4115 @param Form Form data structure.
4119 CleanAltCfgForForm (
4120 IN FORM_BROWSER_FORM
*Form
4124 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
4126 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
4127 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
4128 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
4129 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
4131 if (ConfigInfo
->ConfigAltResp
!= NULL
) {
4132 FreePool (ConfigInfo
->ConfigAltResp
);
4133 ConfigInfo
->ConfigAltResp
= NULL
;
4139 Get AltCfg string for current formset.
4141 @param FormSet Form data structure.
4142 @param DefaultId The Class of the default.
4143 @param BrowserStorage The input request storage for the questions.
4147 ExtractAltCfgForFormSet (
4148 IN FORM_BROWSER_FORMSET
*FormSet
,
4149 IN UINT16 DefaultId
,
4150 IN BROWSER_STORAGE
*BrowserStorage
4158 BROWSER_STORAGE
*Storage
;
4159 FORMSET_STORAGE
*FormSetStorage
;
4161 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4162 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4163 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4164 Storage
= FormSetStorage
->BrowserStorage
;
4165 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4167 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4171 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
4176 // 1. Skip if there is no RequestElement
4178 if (FormSetStorage
->ElementCount
== 0) {
4182 FormSetStorage
->HasCallAltCfg
= TRUE
;
4185 // 2. Get value through hii config routine protocol.
4187 Status
= mHiiConfigRouting
->ExtractConfig (
4189 FormSetStorage
->ConfigRequest
,
4193 if (EFI_ERROR (Status
)) {
4198 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
4199 // Get the default configuration string according to the default ID.
4201 Status
= mHiiConfigRouting
->GetAltConfig (
4207 &DefaultId
, // it can be NULL to get the current setting.
4212 if (EFI_ERROR (Status
)) {
4216 FormSetStorage
->ConfigAltResp
= ConfigResp
;
4222 Clean AltCfg string for current formset.
4224 @param FormSet Form data structure.
4228 CleanAltCfgForFormSet (
4229 IN FORM_BROWSER_FORMSET
*FormSet
4233 FORMSET_STORAGE
*FormSetStorage
;
4235 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4236 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4237 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4238 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4240 if (FormSetStorage
->ConfigAltResp
!= NULL
) {
4241 FreePool (FormSetStorage
->ConfigAltResp
);
4242 FormSetStorage
->ConfigAltResp
= NULL
;
4245 FormSetStorage
->HasCallAltCfg
= FALSE
;
4250 Reset Questions to their initial value or default value in a Form, Formset or System.
4252 GetDefaultValueScope parameter decides which questions will reset
4253 to its default value.
4255 @param FormSet FormSet data structure.
4256 @param Form Form data structure.
4257 @param DefaultId The Class of the default.
4258 @param SettingScope Setting Scope for Default action.
4259 @param GetDefaultValueScope Get default value scope.
4260 @param Storage Get default value only for this storage.
4261 @param RetrieveValueFirst Whether call the retrieve call back to
4262 get the initial value before get default
4264 @param SkipGetAltCfg Whether skip the get altcfg string process.
4266 @retval EFI_SUCCESS The function completed successfully.
4267 @retval EFI_UNSUPPORTED Unsupport SettingScope.
4272 IN FORM_BROWSER_FORMSET
*FormSet
,
4273 IN FORM_BROWSER_FORM
*Form
,
4274 IN UINT16 DefaultId
,
4275 IN BROWSER_SETTING_SCOPE SettingScope
,
4276 IN BROWSER_GET_DEFAULT_VALUE GetDefaultValueScope
,
4277 IN BROWSER_STORAGE
*Storage OPTIONAL
,
4278 IN BOOLEAN RetrieveValueFirst
,
4279 IN BOOLEAN SkipGetAltCfg
4283 LIST_ENTRY
*FormLink
;
4285 FORM_BROWSER_STATEMENT
*Question
;
4286 FORM_BROWSER_FORMSET
*LocalFormSet
;
4287 FORM_BROWSER_FORMSET
*OldFormSet
;
4289 Status
= EFI_SUCCESS
;
4292 // Check the supported setting level.
4294 if (SettingScope
>= MaxLevel
|| GetDefaultValueScope
>= GetDefaultForMax
) {
4295 return EFI_UNSUPPORTED
;
4298 if (GetDefaultValueScope
== GetDefaultForStorage
&& Storage
== NULL
) {
4299 return EFI_UNSUPPORTED
;
4302 if (SettingScope
== FormLevel
) {
4304 // Prepare the AltCfg String for form.
4306 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4307 ExtractAltCfgForForm (FormSet
, Form
, DefaultId
, Storage
);
4311 // Extract Form default
4313 Link
= GetFirstNode (&Form
->StatementListHead
);
4314 while (!IsNull (&Form
->StatementListHead
, Link
)) {
4315 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
4316 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
4319 // If get default value only for this storage, check the storage first.
4321 if ((GetDefaultValueScope
== GetDefaultForStorage
) && (Question
->Storage
!= Storage
)) {
4326 // If get default value only for no storage question, just skip the question which has storage.
4328 if ((GetDefaultValueScope
== GetDefaultForNoStorage
) && (Question
->Storage
!= NULL
)) {
4333 // If Question is disabled, don't reset it to default
4335 if (Question
->Expression
!= NULL
) {
4336 if (EvaluateExpressionList(Question
->Expression
, TRUE
, FormSet
, Form
) == ExpressDisable
) {
4341 if (RetrieveValueFirst
) {
4343 // Call the Retrieve call back to get the initial question value.
4345 Status
= ProcessRetrieveForQuestion(FormSet
->ConfigAccess
, Question
, FormSet
);
4349 // If not request to get the initial value or get initial value fail, then get default value.
4351 if (!RetrieveValueFirst
|| EFI_ERROR (Status
)) {
4352 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
4353 if (EFI_ERROR (Status
)) {
4359 // Synchronize Buffer storage's Edit buffer
4361 if ((Question
->Storage
!= NULL
) &&
4362 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
4363 SetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4368 // Clean the AltCfg String.
4370 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4371 CleanAltCfgForForm(Form
);
4373 } else if (SettingScope
== FormSetLevel
) {
4375 // Prepare the AltCfg String for formset.
4377 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4378 ExtractAltCfgForFormSet (FormSet
, DefaultId
, Storage
);
4381 FormLink
= GetFirstNode (&FormSet
->FormListHead
);
4382 while (!IsNull (&FormSet
->FormListHead
, FormLink
)) {
4383 Form
= FORM_BROWSER_FORM_FROM_LINK (FormLink
);
4384 ExtractDefault (FormSet
, Form
, DefaultId
, FormLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
, SkipGetAltCfg
);
4385 FormLink
= GetNextNode (&FormSet
->FormListHead
, FormLink
);
4389 // Clean the AltCfg String.
4391 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4392 CleanAltCfgForFormSet (FormSet
);
4394 } else if (SettingScope
== SystemLevel
) {
4396 // Preload all Hii formset.
4398 LoadAllHiiFormset();
4400 OldFormSet
= mSystemLevelFormSet
;
4403 // Set Default Value for each FormSet in the maintain list.
4405 Link
= GetFirstNode (&gBrowserFormSetList
);
4406 while (!IsNull (&gBrowserFormSetList
, Link
)) {
4407 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
4408 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
4409 if (!ValidateFormSet(LocalFormSet
)) {
4413 mSystemLevelFormSet
= LocalFormSet
;
4415 ExtractDefault (LocalFormSet
, NULL
, DefaultId
, FormSetLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
, SkipGetAltCfg
);
4418 mSystemLevelFormSet
= OldFormSet
;
4426 Validate whether this question's value has changed.
4428 @param FormSet FormSet data structure.
4429 @param Form Form data structure.
4430 @param Question Question to be initialized.
4431 @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver.
4433 @retval TRUE Question's value has changed.
4434 @retval FALSE Question's value has not changed
4438 IsQuestionValueChanged (
4439 IN FORM_BROWSER_FORMSET
*FormSet
,
4440 IN FORM_BROWSER_FORM
*Form
,
4441 IN OUT FORM_BROWSER_STATEMENT
*Question
,
4442 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
4445 EFI_HII_VALUE BackUpValue
;
4446 CHAR8
*BackUpBuffer
;
4447 EFI_HII_VALUE BackUpValue2
;
4448 CHAR8
*BackUpBuffer2
;
4450 BOOLEAN ValueChanged
;
4454 // For quetion without storage, always mark it as data not changed.
4456 if (Question
->Storage
== NULL
&& Question
->Operand
!= EFI_IFR_TIME_OP
&& Question
->Operand
!= EFI_IFR_DATE_OP
) {
4460 BackUpBuffer
= NULL
;
4461 BackUpBuffer2
= NULL
;
4462 ValueChanged
= FALSE
;
4464 switch (Question
->Operand
) {
4465 case EFI_IFR_ORDERED_LIST_OP
:
4466 BufferWidth
= Question
->StorageWidth
;
4467 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4468 ASSERT (BackUpBuffer
!= NULL
);
4471 case EFI_IFR_STRING_OP
:
4472 case EFI_IFR_PASSWORD_OP
:
4473 BufferWidth
= (UINTN
) Question
->Maximum
* sizeof (CHAR16
);
4474 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4475 ASSERT (BackUpBuffer
!= NULL
);
4482 CopyMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
));
4484 if (GetValueFrom
== GetSetValueWithBothBuffer
) {
4485 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4486 ASSERT_EFI_ERROR(Status
);
4488 switch (Question
->Operand
) {
4489 case EFI_IFR_ORDERED_LIST_OP
:
4490 BufferWidth
= Question
->StorageWidth
;
4491 BackUpBuffer2
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4492 ASSERT (BackUpBuffer2
!= NULL
);
4495 case EFI_IFR_STRING_OP
:
4496 case EFI_IFR_PASSWORD_OP
:
4497 BufferWidth
= (UINTN
) Question
->Maximum
* sizeof (CHAR16
);
4498 BackUpBuffer2
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4499 ASSERT (BackUpBuffer2
!= NULL
);
4506 CopyMem (&BackUpValue2
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
));
4508 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithBuffer
);
4509 ASSERT_EFI_ERROR(Status
);
4511 if (CompareMem (&BackUpValue2
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
)) != 0 ||
4512 CompareMem (BackUpBuffer2
, Question
->BufferValue
, BufferWidth
) != 0) {
4513 ValueChanged
= TRUE
;
4516 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetValueFrom
);
4517 ASSERT_EFI_ERROR(Status
);
4519 if (CompareMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
)) != 0 ||
4520 CompareMem (BackUpBuffer
, Question
->BufferValue
, BufferWidth
) != 0) {
4521 ValueChanged
= TRUE
;
4525 CopyMem (&Question
->HiiValue
, &BackUpValue
, sizeof (EFI_HII_VALUE
));
4526 if (BackUpBuffer
!= NULL
) {
4527 CopyMem (Question
->BufferValue
, BackUpBuffer
, BufferWidth
);
4528 FreePool (BackUpBuffer
);
4531 if (BackUpBuffer2
!= NULL
) {
4532 FreePool (BackUpBuffer2
);
4535 Question
->ValueChanged
= ValueChanged
;
4537 return ValueChanged
;
4541 Initialize Question's Edit copy from Storage.
4543 @param Selection Selection contains the information about
4544 the Selection, form and formset to be displayed.
4545 Selection action may be updated in retrieve callback.
4546 If Selection is NULL, only initialize Question value.
4547 @param FormSet FormSet data structure.
4548 @param Form Form data structure.
4550 @retval EFI_SUCCESS The function completed successfully.
4555 IN OUT UI_MENU_SELECTION
*Selection
,
4556 IN FORM_BROWSER_FORMSET
*FormSet
,
4557 IN FORM_BROWSER_FORM
*Form
4562 FORM_BROWSER_STATEMENT
*Question
;
4564 Link
= GetFirstNode (&Form
->StatementListHead
);
4565 while (!IsNull (&Form
->StatementListHead
, Link
)) {
4566 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
4569 // Initialize local copy of Value for each Question
4571 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
&& (Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
)== 0) {
4572 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithHiiDriver
);
4574 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4576 if (EFI_ERROR (Status
)) {
4580 if ((Question
->Operand
== EFI_IFR_STRING_OP
) || (Question
->Operand
== EFI_IFR_PASSWORD_OP
)) {
4581 HiiSetString (FormSet
->HiiHandle
, Question
->HiiValue
.Value
.string
, (CHAR16
*)Question
->BufferValue
, NULL
);
4584 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
4591 Initialize Question's Edit copy from Storage for the whole Formset.
4593 @param Selection Selection contains the information about
4594 the Selection, form and formset to be displayed.
4595 Selection action may be updated in retrieve callback.
4596 If Selection is NULL, only initialize Question value.
4597 @param FormSet FormSet data structure.
4599 @retval EFI_SUCCESS The function completed successfully.
4604 IN OUT UI_MENU_SELECTION
*Selection
,
4605 IN FORM_BROWSER_FORMSET
*FormSet
4610 FORM_BROWSER_FORM
*Form
;
4612 Link
= GetFirstNode (&FormSet
->FormListHead
);
4613 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
4614 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
4617 // Initialize local copy of Value for each Form
4619 Status
= LoadFormConfig (Selection
, FormSet
, Form
);
4620 if (EFI_ERROR (Status
)) {
4624 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
4628 // Finished question initialization.
4630 FormSet
->QuestionInited
= TRUE
;
4636 Remove the Request element from the Config Request.
4638 @param Storage Pointer to the browser storage.
4639 @param RequestElement The pointer to the Request element.
4644 IN OUT BROWSER_STORAGE
*Storage
,
4645 IN CHAR16
*RequestElement
4651 ASSERT (Storage
->ConfigRequest
!= NULL
&& RequestElement
!= NULL
);
4653 NewStr
= StrStr (Storage
->ConfigRequest
, RequestElement
);
4655 if (NewStr
== NULL
) {
4660 // Remove this element from this ConfigRequest.
4663 NewStr
+= StrLen (RequestElement
);
4664 CopyMem (DestStr
, NewStr
, StrSize (NewStr
));
4666 Storage
->SpareStrLen
+= StrLen (RequestElement
);
4670 Adjust config request in storage, remove the request elements existed in the input ConfigRequest.
4672 @param Storage Pointer to the formset storage.
4673 @param ConfigRequest The pointer to the Request element.
4677 RemoveConfigRequest (
4678 FORMSET_STORAGE
*Storage
,
4679 CHAR16
*ConfigRequest
4682 CHAR16
*RequestElement
;
4683 CHAR16
*NextRequestElement
;
4687 // No request element in it, just return.
4689 if (ConfigRequest
== NULL
) {
4693 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4695 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
4700 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
4702 SearchKey
= L
"&OFFSET";
4706 // Find SearchKey storage
4708 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4709 RequestElement
= StrStr (ConfigRequest
, L
"PATH");
4710 ASSERT (RequestElement
!= NULL
);
4711 RequestElement
= StrStr (RequestElement
, SearchKey
);
4713 RequestElement
= StrStr (ConfigRequest
, SearchKey
);
4716 while (RequestElement
!= NULL
) {
4718 // +1 to avoid find header itself.
4720 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
4723 // The last Request element in configRequest string.
4725 if (NextRequestElement
!= NULL
) {
4727 // Replace "&" with '\0'.
4729 *NextRequestElement
= L
'\0';
4732 RemoveElement (Storage
->BrowserStorage
, RequestElement
);
4734 if (NextRequestElement
!= NULL
) {
4736 // Restore '&' with '\0' for later used.
4738 *NextRequestElement
= L
'&';
4741 RequestElement
= NextRequestElement
;
4745 // If no request element remain, just remove the ConfigRequest string.
4747 if (StrCmp (Storage
->BrowserStorage
->ConfigRequest
, Storage
->ConfigHdr
) == 0) {
4748 FreePool (Storage
->BrowserStorage
->ConfigRequest
);
4749 Storage
->BrowserStorage
->ConfigRequest
= NULL
;
4750 Storage
->BrowserStorage
->SpareStrLen
= 0;
4755 Base on the current formset info, clean the ConfigRequest string in browser storage.
4757 @param FormSet Pointer of the FormSet
4761 CleanBrowserStorage (
4762 IN OUT FORM_BROWSER_FORMSET
*FormSet
4766 FORMSET_STORAGE
*Storage
;
4768 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4769 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4770 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
4771 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4773 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
4774 if (Storage
->ConfigRequest
== NULL
|| Storage
->BrowserStorage
->ConfigRequest
== NULL
) {
4778 RemoveConfigRequest (Storage
, Storage
->ConfigRequest
);
4779 } else if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_BUFFER
||
4780 Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4781 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
4782 FreePool (Storage
->BrowserStorage
->ConfigRequest
);
4783 Storage
->BrowserStorage
->ConfigRequest
= NULL
;
4785 Storage
->BrowserStorage
->Initialized
= FALSE
;
4791 Check whether current element in the ConfigReqeust string.
4793 @param BrowserStorage Storage which includes ConfigReqeust.
4794 @param RequestElement New element need to check.
4796 @retval TRUE The Element is in the ConfigReqeust string.
4797 @retval FALSE The Element not in the configReqeust String.
4802 BROWSER_STORAGE
*BrowserStorage
,
4803 CHAR16
*RequestElement
4806 return StrStr (BrowserStorage
->ConfigRequest
, RequestElement
) != NULL
? TRUE
: FALSE
;
4810 Append the Request element to the Config Request.
4812 @param ConfigRequest Current ConfigRequest info.
4813 @param SpareStrLen Current remain free buffer for config reqeust.
4814 @param RequestElement New Request element.
4818 AppendConfigRequest (
4819 IN OUT CHAR16
**ConfigRequest
,
4820 IN OUT UINTN
*SpareStrLen
,
4821 IN CHAR16
*RequestElement
4828 StrLength
= StrLen (RequestElement
);
4831 // Append <RequestElement> to <ConfigRequest>
4833 if (StrLength
> *SpareStrLen
) {
4835 // Old String buffer is not sufficient for RequestElement, allocate a new one
4837 StringSize
= (*ConfigRequest
!= NULL
) ? StrSize (*ConfigRequest
) : sizeof (CHAR16
);
4838 NewStr
= AllocateZeroPool (StringSize
+ CONFIG_REQUEST_STRING_INCREMENTAL
* sizeof (CHAR16
));
4839 ASSERT (NewStr
!= NULL
);
4841 if (*ConfigRequest
!= NULL
) {
4842 CopyMem (NewStr
, *ConfigRequest
, StringSize
);
4843 FreePool (*ConfigRequest
);
4845 *ConfigRequest
= NewStr
;
4846 *SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
4849 StrCat (*ConfigRequest
, RequestElement
);
4850 *SpareStrLen
-= StrLength
;
4854 Adjust the config request info, remove the request elements which already in AllConfigRequest string.
4856 @param Storage Form set Storage.
4857 @param Request The input request string.
4858 @param RespString Whether the input is ConfigRequest or ConfigResp format.
4860 @retval TRUE Has element not covered by current used elements, need to continue to call ExtractConfig
4861 @retval FALSE All elements covered by current used elements.
4865 ConfigRequestAdjust (
4866 IN BROWSER_STORAGE
*Storage
,
4868 IN BOOLEAN RespString
4871 CHAR16
*RequestElement
;
4872 CHAR16
*NextRequestElement
;
4873 CHAR16
*NextElementBakup
;
4877 CHAR16
*ConfigRequest
;
4880 NextElementBakup
= NULL
;
4883 if (Request
!= NULL
) {
4884 ConfigRequest
= Request
;
4886 ConfigRequest
= Storage
->ConfigRequest
;
4889 if (Storage
->ConfigRequest
== NULL
) {
4890 Storage
->ConfigRequest
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
4894 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4896 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
4901 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
4903 SearchKey
= L
"&OFFSET";
4904 ValueKey
= L
"&VALUE";
4908 // Find SearchKey storage
4910 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4911 RequestElement
= StrStr (ConfigRequest
, L
"PATH");
4912 ASSERT (RequestElement
!= NULL
);
4913 RequestElement
= StrStr (RequestElement
, SearchKey
);
4915 RequestElement
= StrStr (ConfigRequest
, SearchKey
);
4918 while (RequestElement
!= NULL
) {
4921 // +1 to avoid find header itself.
4923 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
4926 // The last Request element in configRequest string.
4928 if (NextRequestElement
!= NULL
) {
4929 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
4930 NextElementBakup
= NextRequestElement
;
4931 NextRequestElement
= StrStr (RequestElement
, ValueKey
);
4932 ASSERT (NextRequestElement
!= NULL
);
4935 // Replace "&" with '\0'.
4937 *NextRequestElement
= L
'\0';
4939 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
4940 NextElementBakup
= NextRequestElement
;
4941 NextRequestElement
= StrStr (RequestElement
, ValueKey
);
4942 ASSERT (NextRequestElement
!= NULL
);
4944 // Replace "&" with '\0'.
4946 *NextRequestElement
= L
'\0';
4950 if (!ElementValidation (Storage
, RequestElement
)) {
4952 // Add this element to the Storage->BrowserStorage->AllRequestElement.
4954 AppendConfigRequest(&Storage
->ConfigRequest
, &Storage
->SpareStrLen
, RequestElement
);
4958 if (NextRequestElement
!= NULL
) {
4960 // Restore '&' with '\0' for later used.
4962 *NextRequestElement
= L
'&';
4965 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
4966 RequestElement
= NextElementBakup
;
4968 RequestElement
= NextRequestElement
;
4976 Fill storage's edit copy with settings requested from Configuration Driver.
4978 @param FormSet FormSet data structure.
4979 @param Storage Buffer Storage.
4984 IN FORM_BROWSER_FORMSET
*FormSet
,
4985 IN FORMSET_STORAGE
*Storage
4989 EFI_STRING Progress
;
4992 EFI_STRING ConfigRequest
;
4995 ConfigRequest
= NULL
;
4997 switch (Storage
->BrowserStorage
->Type
) {
4998 case EFI_HII_VARSTORE_EFI_VARIABLE
:
5001 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
5002 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
5003 ConfigRequestAdjust(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
5008 case EFI_HII_VARSTORE_BUFFER
:
5009 case EFI_HII_VARSTORE_NAME_VALUE
:
5011 // Skip if there is no RequestElement.
5013 if (Storage
->ElementCount
== 0) {
5018 // Just update the ConfigRequest, if storage already initialized.
5020 if (Storage
->BrowserStorage
->Initialized
) {
5021 ConfigRequestAdjust(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
5025 Storage
->BrowserStorage
->Initialized
= TRUE
;
5032 if (Storage
->BrowserStorage
->Type
!= EFI_HII_VARSTORE_NAME_VALUE
) {
5034 // Create the config request string to get all fields for this storage.
5035 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
5036 // followed by "&OFFSET=0&WIDTH=WWWW"followed by a Null-terminator
5038 StrLen
= StrSize (Storage
->ConfigHdr
) + 20 * sizeof (CHAR16
);
5039 ConfigRequest
= AllocateZeroPool (StrLen
);
5040 ASSERT (ConfigRequest
!= NULL
);
5044 L
"%s&OFFSET=0&WIDTH=%04x",
5046 Storage
->BrowserStorage
->Size
);
5048 ConfigRequest
= Storage
->ConfigRequest
;
5052 // Request current settings from Configuration Driver
5054 Status
= mHiiConfigRouting
->ExtractConfig (
5062 // If get value fail, extract default from IFR binary
5064 if (EFI_ERROR (Status
)) {
5065 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForStorage
, Storage
->BrowserStorage
, TRUE
, TRUE
);
5068 // Convert Result from <ConfigAltResp> to <ConfigResp>
5070 StrPtr
= StrStr (Result
, L
"&GUID=");
5071 if (StrPtr
!= NULL
) {
5075 Status
= ConfigRespToStorage (Storage
->BrowserStorage
, Result
);
5079 Storage
->BrowserStorage
->ConfigRequest
= AllocateCopyPool (StrSize (Storage
->ConfigRequest
), Storage
->ConfigRequest
);
5082 // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer.
5084 SynchronizeStorage(Storage
->BrowserStorage
, NULL
, TRUE
);
5086 if (Storage
->BrowserStorage
->Type
!= EFI_HII_VARSTORE_NAME_VALUE
) {
5087 if (ConfigRequest
!= NULL
) {
5088 FreePool (ConfigRequest
);
5094 Get Value changed status from old question.
5096 @param NewFormSet FormSet data structure.
5097 @param OldQuestion Old question which has value changed.
5101 SyncStatusForQuestion (
5102 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
5103 IN FORM_BROWSER_STATEMENT
*OldQuestion
5107 LIST_ENTRY
*QuestionLink
;
5108 FORM_BROWSER_FORM
*Form
;
5109 FORM_BROWSER_STATEMENT
*Question
;
5112 // For each form in one formset.
5114 Link
= GetFirstNode (&NewFormSet
->FormListHead
);
5115 while (!IsNull (&NewFormSet
->FormListHead
, Link
)) {
5116 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
5117 Link
= GetNextNode (&NewFormSet
->FormListHead
, Link
);
5120 // for each question in one form.
5122 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
5123 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
5124 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
5125 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
5127 if (Question
->QuestionId
== OldQuestion
->QuestionId
) {
5128 Question
->ValueChanged
= TRUE
;
5136 Get Value changed status from old formset.
5138 @param NewFormSet FormSet data structure.
5139 @param OldFormSet FormSet data structure.
5143 SyncStatusForFormSet (
5144 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
5145 IN FORM_BROWSER_FORMSET
*OldFormSet
5149 LIST_ENTRY
*QuestionLink
;
5150 FORM_BROWSER_FORM
*Form
;
5151 FORM_BROWSER_STATEMENT
*Question
;
5154 // For each form in one formset.
5156 Link
= GetFirstNode (&OldFormSet
->FormListHead
);
5157 while (!IsNull (&OldFormSet
->FormListHead
, Link
)) {
5158 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
5159 Link
= GetNextNode (&OldFormSet
->FormListHead
, Link
);
5162 // for each question in one form.
5164 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
5165 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
5166 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
5167 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
5169 if (!Question
->ValueChanged
) {
5174 // Find the same question in new formset and update the value changed flag.
5176 SyncStatusForQuestion (NewFormSet
, Question
);
5182 Get current setting of Questions.
5184 @param FormSet FormSet data structure.
5188 InitializeCurrentSetting (
5189 IN OUT FORM_BROWSER_FORMSET
*FormSet
5193 FORMSET_STORAGE
*Storage
;
5194 FORM_BROWSER_FORMSET
*OldFormSet
;
5197 // Try to find pre FormSet in the maintain backup list.
5198 // If old formset != NULL, destroy this formset. Add new formset to gBrowserFormSetList.
5200 OldFormSet
= GetFormSetFromHiiHandle (FormSet
->HiiHandle
);
5201 if (OldFormSet
!= NULL
) {
5202 SyncStatusForFormSet (FormSet
, OldFormSet
);
5203 RemoveEntryList (&OldFormSet
->Link
);
5204 DestroyFormSet (OldFormSet
);
5206 InsertTailList (&gBrowserFormSetList
, &FormSet
->Link
);
5209 // Extract default from IFR binary for no storage questions.
5211 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForNoStorage
, NULL
, TRUE
, FALSE
);
5214 // Request current settings from Configuration Driver
5216 Link
= GetFirstNode (&FormSet
->StorageListHead
);
5217 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
5218 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
5220 LoadStorage (FormSet
, Storage
);
5222 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
5228 Fetch the Ifr binary data of a FormSet.
5230 @param Handle PackageList Handle
5231 @param FormSetGuid On input, GUID or class GUID of a formset. If not
5232 specified (NULL or zero GUID), take the first
5233 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
5234 found in package list.
5235 On output, GUID of the formset found(if not NULL).
5236 @param BinaryLength The length of the FormSet IFR binary.
5237 @param BinaryData The buffer designed to receive the FormSet.
5239 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
5240 BufferLength was updated.
5241 @retval EFI_INVALID_PARAMETER The handle is unknown.
5242 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
5243 be found with the requested FormId.
5248 IN EFI_HII_HANDLE Handle
,
5249 IN OUT EFI_GUID
*FormSetGuid
,
5250 OUT UINTN
*BinaryLength
,
5251 OUT UINT8
**BinaryData
5255 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
5261 UINT32 PackageListLength
;
5262 EFI_HII_PACKAGE_HEADER PackageHeader
;
5264 UINT8 NumberOfClassGuid
;
5265 BOOLEAN ClassGuidMatch
;
5266 EFI_GUID
*ClassGuid
;
5267 EFI_GUID
*ComparingGuid
;
5271 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
5274 // if FormSetGuid is NULL or zero GUID, return first Setup FormSet in the package list
5276 if (FormSetGuid
== NULL
) {
5277 ComparingGuid
= &gZeroGuid
;
5279 ComparingGuid
= FormSetGuid
;
5283 // Get HII PackageList
5286 HiiPackageList
= NULL
;
5287 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
5288 if (Status
== EFI_BUFFER_TOO_SMALL
) {
5289 HiiPackageList
= AllocatePool (BufferSize
);
5290 ASSERT (HiiPackageList
!= NULL
);
5292 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
5294 if (EFI_ERROR (Status
)) {
5297 ASSERT (HiiPackageList
!= NULL
);
5300 // Get Form package from this HII package List
5302 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
5304 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
5306 ClassGuidMatch
= FALSE
;
5307 while (Offset
< PackageListLength
) {
5308 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
5309 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
5311 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
5313 // Search FormSet in this Form Package
5315 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
5316 while (Offset2
< PackageHeader
.Length
) {
5317 OpCodeData
= Package
+ Offset2
;
5319 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
5321 // Try to compare against formset GUID
5323 if (CompareGuid (FormSetGuid
, &gZeroGuid
) ||
5324 CompareGuid (ComparingGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
5328 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
5330 // Try to compare against formset class GUID
5332 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
5333 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
5334 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
5335 if (CompareGuid (ComparingGuid
, ClassGuid
+ Index
)) {
5336 ClassGuidMatch
= TRUE
;
5340 if (ClassGuidMatch
) {
5343 } else if (ComparingGuid
== &gEfiHiiPlatformSetupFormsetGuid
) {
5344 ClassGuidMatch
= TRUE
;
5349 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
5352 if (Offset2
< PackageHeader
.Length
) {
5354 // Target formset found
5360 Offset
+= PackageHeader
.Length
;
5363 if (Offset
>= PackageListLength
) {
5365 // Form package not found in this Package List
5367 FreePool (HiiPackageList
);
5368 return EFI_NOT_FOUND
;
5371 if (FormSetGuid
!= NULL
) {
5373 // Return the FormSet GUID
5375 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
5379 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
5380 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
5381 // of the Form Package.
5383 *BinaryLength
= PackageHeader
.Length
- Offset2
;
5384 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
5386 FreePool (HiiPackageList
);
5388 if (*BinaryData
== NULL
) {
5389 return EFI_OUT_OF_RESOURCES
;
5397 Initialize the internal data structure of a FormSet.
5399 @param Handle PackageList Handle
5400 @param FormSetGuid On input, GUID or class GUID of a formset. If not
5401 specified (NULL or zero GUID), take the first
5402 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
5403 found in package list.
5404 On output, GUID of the formset found(if not NULL).
5405 @param FormSet FormSet data structure.
5407 @retval EFI_SUCCESS The function completed successfully.
5408 @retval EFI_NOT_FOUND The specified FormSet could not be found.
5413 IN EFI_HII_HANDLE Handle
,
5414 IN OUT EFI_GUID
*FormSetGuid
,
5415 OUT FORM_BROWSER_FORMSET
*FormSet
5419 EFI_HANDLE DriverHandle
;
5421 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
5422 if (EFI_ERROR (Status
)) {
5426 FormSet
->Signature
= FORM_BROWSER_FORMSET_SIGNATURE
;
5427 FormSet
->HiiHandle
= Handle
;
5428 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
5429 FormSet
->QuestionInited
= FALSE
;
5432 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
5434 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
5435 if (EFI_ERROR (Status
)) {
5438 FormSet
->DriverHandle
= DriverHandle
;
5439 Status
= gBS
->HandleProtocol (
5441 &gEfiHiiConfigAccessProtocolGuid
,
5442 (VOID
**) &FormSet
->ConfigAccess
5444 if (EFI_ERROR (Status
)) {
5446 // Configuration Driver don't attach ConfigAccess protocol to its HII package
5447 // list, then there will be no configuration action required
5449 FormSet
->ConfigAccess
= NULL
;
5453 // Parse the IFR binary OpCodes
5455 Status
= ParseOpCodes (FormSet
);
5462 Save globals used by previous call to SendForm(). SendForm() may be called from
5463 HiiConfigAccess.Callback(), this will cause SendForm() be reentried.
5464 So, save globals of previous call to SendForm() and restore them upon exit.
5468 SaveBrowserContext (
5472 BROWSER_CONTEXT
*Context
;
5473 FORM_ENTRY_INFO
*MenuList
;
5475 gBrowserContextCount
++;
5476 if (gBrowserContextCount
== 1) {
5478 // This is not reentry of SendForm(), no context to save
5483 Context
= AllocatePool (sizeof (BROWSER_CONTEXT
));
5484 ASSERT (Context
!= NULL
);
5486 Context
->Signature
= BROWSER_CONTEXT_SIGNATURE
;
5489 // Save FormBrowser context
5491 Context
->Selection
= gCurrentSelection
;
5492 Context
->ResetRequired
= gResetRequired
;
5493 Context
->ExitRequired
= gExitRequired
;
5494 Context
->HiiHandle
= mCurrentHiiHandle
;
5495 Context
->FormId
= mCurrentFormId
;
5496 CopyGuid (&Context
->FormSetGuid
, &mCurrentFormSetGuid
);
5499 // Save the menu history data.
5501 InitializeListHead(&Context
->FormHistoryList
);
5502 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
5503 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
5504 RemoveEntryList (&MenuList
->Link
);
5506 InsertTailList(&Context
->FormHistoryList
, &MenuList
->Link
);
5510 // Insert to FormBrowser context list
5512 InsertHeadList (&gBrowserContextList
, &Context
->Link
);
5517 Restore globals used by previous call to SendForm().
5521 RestoreBrowserContext (
5526 BROWSER_CONTEXT
*Context
;
5527 FORM_ENTRY_INFO
*MenuList
;
5529 ASSERT (gBrowserContextCount
!= 0);
5530 gBrowserContextCount
--;
5531 if (gBrowserContextCount
== 0) {
5533 // This is not reentry of SendForm(), no context to restore
5538 ASSERT (!IsListEmpty (&gBrowserContextList
));
5540 Link
= GetFirstNode (&gBrowserContextList
);
5541 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
5544 // Restore FormBrowser context
5546 gCurrentSelection
= Context
->Selection
;
5547 gResetRequired
= Context
->ResetRequired
;
5548 gExitRequired
= Context
->ExitRequired
;
5549 mCurrentHiiHandle
= Context
->HiiHandle
;
5550 mCurrentFormId
= Context
->FormId
;
5551 CopyGuid (&mCurrentFormSetGuid
, &Context
->FormSetGuid
);
5554 // Restore the menu history data.
5556 while (!IsListEmpty (&Context
->FormHistoryList
)) {
5557 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Context
->FormHistoryList
.ForwardLink
);
5558 RemoveEntryList (&MenuList
->Link
);
5560 InsertTailList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &MenuList
->Link
);
5564 // Remove from FormBrowser context list
5566 RemoveEntryList (&Context
->Link
);
5567 gBS
->FreePool (Context
);
5571 Find the matched FormSet context in the backup maintain list based on HiiHandle.
5573 @param Handle The Hii Handle.
5575 @return the found FormSet context. If no found, NULL will return.
5578 FORM_BROWSER_FORMSET
*
5579 GetFormSetFromHiiHandle (
5580 EFI_HII_HANDLE Handle
5584 FORM_BROWSER_FORMSET
*FormSet
;
5586 Link
= GetFirstNode (&gBrowserFormSetList
);
5587 while (!IsNull (&gBrowserFormSetList
, Link
)) {
5588 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
5589 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
5590 if (!ValidateFormSet(FormSet
)) {
5593 if (FormSet
->HiiHandle
== Handle
) {
5602 Check whether the input HII handle is the FormSet that is being used.
5604 @param Handle The Hii Handle.
5606 @retval TRUE HII handle is being used.
5607 @retval FALSE HII handle is not being used.
5611 IsHiiHandleInBrowserContext (
5612 EFI_HII_HANDLE Handle
5616 BROWSER_CONTEXT
*Context
;
5619 // HiiHandle is Current FormSet.
5621 if (mCurrentHiiHandle
== Handle
) {
5626 // Check whether HiiHandle is in BrowserContext.
5628 Link
= GetFirstNode (&gBrowserContextList
);
5629 while (!IsNull (&gBrowserContextList
, Link
)) {
5630 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
5631 if (Context
->HiiHandle
== Handle
) {
5633 // HiiHandle is in BrowserContext
5637 Link
= GetNextNode (&gBrowserContextList
, Link
);
5644 Perform Password check.
5645 Passwork may be encrypted by driver that requires the specific check.
5647 @param Form Form where Password Statement is in.
5648 @param Statement Password statement
5649 @param PasswordString Password string to be checked. It may be NULL.
5650 NULL means to restore password.
5651 "" string can be used to checked whether old password does exist.
5653 @return Status Status of Password check.
5658 IN FORM_DISPLAY_ENGINE_FORM
*Form
,
5659 IN FORM_DISPLAY_ENGINE_STATEMENT
*Statement
,
5660 IN EFI_STRING PasswordString OPTIONAL
5664 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
5665 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
5666 EFI_IFR_TYPE_VALUE IfrTypeValue
;
5667 FORM_BROWSER_STATEMENT
*Question
;
5669 ConfigAccess
= gCurrentSelection
->FormSet
->ConfigAccess
;
5670 Question
= GetBrowserStatement(Statement
);
5671 ASSERT (Question
!= NULL
);
5673 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
) {
5674 if (ConfigAccess
== NULL
) {
5675 return EFI_UNSUPPORTED
;
5678 if (PasswordString
== NULL
) {
5683 // Check whether has preexisted password.
5685 if (PasswordString
[0] == 0) {
5686 if (*((CHAR16
*) Question
->BufferValue
) == 0) {
5689 return EFI_NOT_READY
;
5694 // Check whether the input password is same as preexisted password.
5696 if (StrnCmp (PasswordString
, (CHAR16
*) Question
->BufferValue
, Question
->StorageWidth
/sizeof (CHAR16
)) == 0) {
5699 return EFI_NOT_READY
;
5704 // Prepare password string in HII database
5706 if (PasswordString
!= NULL
) {
5707 IfrTypeValue
.string
= NewString (PasswordString
, gCurrentSelection
->FormSet
->HiiHandle
);
5709 IfrTypeValue
.string
= 0;
5713 // Send password to Configuration Driver for validation
5715 Status
= ConfigAccess
->Callback (
5717 EFI_BROWSER_ACTION_CHANGING
,
5718 Question
->QuestionId
,
5719 Question
->HiiValue
.Type
,
5725 // Remove password string from HII database
5727 if (PasswordString
!= NULL
) {
5728 DeleteString (IfrTypeValue
.string
, gCurrentSelection
->FormSet
->HiiHandle
);
5735 Find the registered HotKey based on KeyData.
5737 @param[in] KeyData A pointer to a buffer that describes the keystroke
5738 information for the hot key.
5740 @return The registered HotKey context. If no found, NULL will return.
5743 GetHotKeyFromRegisterList (
5744 IN EFI_INPUT_KEY
*KeyData
5748 BROWSER_HOT_KEY
*HotKey
;
5750 Link
= GetFirstNode (&gBrowserHotKeyList
);
5751 while (!IsNull (&gBrowserHotKeyList
, Link
)) {
5752 HotKey
= BROWSER_HOT_KEY_FROM_LINK (Link
);
5753 if (HotKey
->KeyData
->ScanCode
== KeyData
->ScanCode
) {
5756 Link
= GetNextNode (&gBrowserHotKeyList
, Link
);
5763 Configure what scope the hot key will impact.
5764 All hot keys have the same scope. The mixed hot keys with the different level are not supported.
5765 If no scope is set, the default scope will be FormSet level.
5766 After all registered hot keys are removed, previous Scope can reset to another level.
5768 @param[in] Scope Scope level to be set.
5770 @retval EFI_SUCCESS Scope is set correctly.
5771 @retval EFI_INVALID_PARAMETER Scope is not the valid value specified in BROWSER_SETTING_SCOPE.
5772 @retval EFI_UNSPPORTED Scope level is different from current one that the registered hot keys have.
5778 IN BROWSER_SETTING_SCOPE Scope
5781 if (Scope
>= MaxLevel
) {
5782 return EFI_INVALID_PARAMETER
;
5786 // When no hot key registered in system or on the first setting,
5787 // Scope can be set.
5789 if (mBrowserScopeFirstSet
|| IsListEmpty (&gBrowserHotKeyList
)) {
5790 gBrowserSettingScope
= Scope
;
5791 mBrowserScopeFirstSet
= FALSE
;
5792 } else if (Scope
!= gBrowserSettingScope
) {
5793 return EFI_UNSUPPORTED
;
5800 Register the hot key with its browser action, or unregistered the hot key.
5801 Only support hot key that is not printable character (control key, function key, etc.).
5802 If the action value is zero, the hot key will be unregistered if it has been registered.
5803 If the same hot key has been registered, the new action and help string will override the previous ones.
5805 @param[in] KeyData A pointer to a buffer that describes the keystroke
5806 information for the hot key. Its type is EFI_INPUT_KEY to
5807 be supported by all ConsoleIn devices.
5808 @param[in] Action Action value that describes what action will be trigged when the hot key is pressed.
5809 @param[in] DefaultId Specifies the type of defaults to retrieve, which is only for DEFAULT action.
5810 @param[in] HelpString Help string that describes the hot key information.
5811 Its value may be NULL for the unregistered hot key.
5813 @retval EFI_SUCCESS Hot key is registered or unregistered.
5814 @retval EFI_INVALID_PARAMETER KeyData is NULL or HelpString is NULL on register.
5815 @retval EFI_NOT_FOUND KeyData is not found to be unregistered.
5816 @retval EFI_UNSUPPORTED Key represents a printable character. It is conflicted with Browser.
5821 IN EFI_INPUT_KEY
*KeyData
,
5823 IN UINT16 DefaultId
,
5824 IN EFI_STRING HelpString OPTIONAL
5827 BROWSER_HOT_KEY
*HotKey
;
5830 // Check input parameters.
5832 if (KeyData
== NULL
|| KeyData
->UnicodeChar
!= CHAR_NULL
||
5833 (Action
!= BROWSER_ACTION_UNREGISTER
&& HelpString
== NULL
)) {
5834 return EFI_INVALID_PARAMETER
;
5838 // Check whether the input KeyData is in BrowserHotKeyList.
5840 HotKey
= GetHotKeyFromRegisterList (KeyData
);
5843 // Unregister HotKey
5845 if (Action
== BROWSER_ACTION_UNREGISTER
) {
5846 if (HotKey
!= NULL
) {
5848 // The registered HotKey is found.
5849 // Remove it from List, and free its resource.
5851 RemoveEntryList (&HotKey
->Link
);
5852 FreePool (HotKey
->KeyData
);
5853 FreePool (HotKey
->HelpString
);
5857 // The registered HotKey is not found.
5859 return EFI_NOT_FOUND
;
5864 // Register HotKey into List.
5866 if (HotKey
== NULL
) {
5868 // Create new Key, and add it into List.
5870 HotKey
= AllocateZeroPool (sizeof (BROWSER_HOT_KEY
));
5871 ASSERT (HotKey
!= NULL
);
5872 HotKey
->Signature
= BROWSER_HOT_KEY_SIGNATURE
;
5873 HotKey
->KeyData
= AllocateCopyPool (sizeof (EFI_INPUT_KEY
), KeyData
);
5874 InsertTailList (&gBrowserHotKeyList
, &HotKey
->Link
);
5878 // Fill HotKey information.
5880 HotKey
->Action
= Action
;
5881 HotKey
->DefaultId
= DefaultId
;
5882 if (HotKey
->HelpString
!= NULL
) {
5883 FreePool (HotKey
->HelpString
);
5885 HotKey
->HelpString
= AllocateCopyPool (StrSize (HelpString
), HelpString
);
5891 Register Exit handler function.
5892 When more than one handler function is registered, the latter one will override the previous one.
5893 When NULL handler is specified, the previous Exit handler will be unregistered.
5895 @param[in] Handler Pointer to handler function.
5900 RegiserExitHandler (
5901 IN EXIT_HANDLER Handler
5904 ExitHandlerFunction
= Handler
;
5909 Check whether the browser data has been modified.
5911 @retval TRUE Browser data is modified.
5912 @retval FALSE No browser data is modified.
5917 IsBrowserDataModified (
5922 FORM_BROWSER_FORMSET
*FormSet
;
5924 switch (gBrowserSettingScope
) {
5926 if (gCurrentSelection
== NULL
) {
5929 return IsNvUpdateRequiredForForm (gCurrentSelection
->Form
);
5932 if (gCurrentSelection
== NULL
) {
5935 return IsNvUpdateRequiredForFormSet (gCurrentSelection
->FormSet
);
5938 Link
= GetFirstNode (&gBrowserFormSetList
);
5939 while (!IsNull (&gBrowserFormSetList
, Link
)) {
5940 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
5941 if (!ValidateFormSet(FormSet
)) {
5945 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
5948 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
5958 Execute the action requested by the Action parameter.
5960 @param[in] Action Execute the request action.
5961 @param[in] DefaultId The default Id info when need to load default value. Only used when Action is BROWSER_ACTION_DEFAULT.
5963 @retval EFI_SUCCESS Execute the request action succss.
5964 @retval EFI_INVALID_PARAMETER The input action value is invalid.
5975 FORM_BROWSER_FORMSET
*FormSet
;
5976 FORM_BROWSER_FORM
*Form
;
5978 if (gBrowserSettingScope
< SystemLevel
&& gCurrentSelection
== NULL
) {
5979 return EFI_NOT_READY
;
5982 Status
= EFI_SUCCESS
;
5985 if (gBrowserSettingScope
< SystemLevel
) {
5986 FormSet
= gCurrentSelection
->FormSet
;
5987 Form
= gCurrentSelection
->Form
;
5991 // Executet the discard action.
5993 if ((Action
& BROWSER_ACTION_DISCARD
) != 0) {
5994 Status
= DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
5995 if (EFI_ERROR (Status
)) {
6001 // Executet the difault action.
6003 if ((Action
& BROWSER_ACTION_DEFAULT
) != 0) {
6004 Status
= ExtractDefault (FormSet
, Form
, DefaultId
, gBrowserSettingScope
, GetDefaultForAll
, NULL
, FALSE
, FALSE
);
6005 if (EFI_ERROR (Status
)) {
6008 UpdateStatementStatus (FormSet
, Form
, gBrowserSettingScope
);
6012 // Executet the submit action.
6014 if ((Action
& BROWSER_ACTION_SUBMIT
) != 0) {
6015 Status
= SubmitForm (FormSet
, Form
, gBrowserSettingScope
);
6016 if (EFI_ERROR (Status
)) {
6022 // Executet the reset action.
6024 if ((Action
& BROWSER_ACTION_RESET
) != 0) {
6025 gResetRequired
= TRUE
;
6029 // Executet the exit action.
6031 if ((Action
& BROWSER_ACTION_EXIT
) != 0) {
6032 DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
6033 if (gBrowserSettingScope
== SystemLevel
) {
6034 if (ExitHandlerFunction
!= NULL
) {
6035 ExitHandlerFunction ();
6039 gExitRequired
= TRUE
;
6046 Create reminder to let user to choose save or discard the changed browser data.
6047 Caller can use it to actively check the changed browser data.
6049 @retval BROWSER_NO_CHANGES No browser data is changed.
6050 @retval BROWSER_SAVE_CHANGES The changed browser data is saved.
6051 @retval BROWSER_DISCARD_CHANGES The changed browser data is discard.
6052 @retval BROWSER_KEEP_CURRENT Browser keep current changes.
6062 FORM_BROWSER_FORMSET
*FormSet
;
6063 BOOLEAN IsDataChanged
;
6064 UINT32 DataSavedAction
;
6067 DataSavedAction
= BROWSER_NO_CHANGES
;
6068 IsDataChanged
= FALSE
;
6069 Link
= GetFirstNode (&gBrowserFormSetList
);
6070 while (!IsNull (&gBrowserFormSetList
, Link
)) {
6071 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
6072 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
6073 if (!ValidateFormSet(FormSet
)) {
6076 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
6077 IsDataChanged
= TRUE
;
6083 // No data is changed. No save is required.
6085 if (!IsDataChanged
) {
6086 return DataSavedAction
;
6090 // If data is changed, prompt user to save or discard it.
6093 ConfirmRet
= (UINT32
) mFormDisplay
->ConfirmDataChange();
6095 if (ConfirmRet
== BROWSER_ACTION_SUBMIT
) {
6096 SubmitForm (NULL
, NULL
, SystemLevel
);
6097 DataSavedAction
= BROWSER_SAVE_CHANGES
;
6099 } else if (ConfirmRet
== BROWSER_ACTION_DISCARD
) {
6100 DiscardForm (NULL
, NULL
, SystemLevel
);
6101 DataSavedAction
= BROWSER_DISCARD_CHANGES
;
6103 } else if (ConfirmRet
== BROWSER_ACTION_NONE
) {
6104 DataSavedAction
= BROWSER_KEEP_CURRENT
;
6109 return DataSavedAction
;
6113 Check whether the Reset Required for the browser
6115 @retval TRUE Browser required to reset after exit.
6116 @retval FALSE Browser not need to reset after exit.
6125 return gResetRequired
;