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 BOOLEAN gFlagReconnect
;
59 BOOLEAN gCallbackReconnect
;
60 BROWSER_SETTING_SCOPE gBrowserSettingScope
= FormSetLevel
;
61 BOOLEAN mBrowserScopeFirstSet
= TRUE
;
62 EXIT_HANDLER ExitHandlerFunction
= NULL
;
63 FORM_BROWSER_FORMSET
*mSystemLevelFormSet
;
66 // Browser Global Strings
69 CHAR16
*mUnknownString
= L
"!";
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
;
489 // If EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found, return EFI_UNSUPPORTED.
491 if (mFormDisplay
== NULL
) {
492 return EFI_UNSUPPORTED
;
496 // Save globals used by SendForm()
498 SaveBrowserContext ();
500 gFlagReconnect
= FALSE
;
501 gResetRequired
= FALSE
;
502 gExitRequired
= FALSE
;
503 gCallbackReconnect
= FALSE
;
504 Status
= EFI_SUCCESS
;
506 gDisplayFormData
.ScreenDimensions
= (EFI_SCREEN_DESCRIPTOR
*) ScreenDimensions
;
508 for (Index
= 0; Index
< HandleCount
; Index
++) {
509 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
510 ASSERT (Selection
!= NULL
);
512 Selection
->Handle
= Handles
[Index
];
513 if (FormSetGuid
!= NULL
) {
514 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
515 Selection
->FormId
= FormId
;
517 CopyMem (&Selection
->FormSetGuid
, &gEfiHiiPlatformSetupFormsetGuid
, sizeof (EFI_GUID
));
521 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
522 ASSERT (FormSet
!= NULL
);
525 // Validate the HiiHandle
526 // if validate failed, find the first validate parent HiiHandle.
528 if (!ValidateHiiHandle(Selection
->Handle
)) {
529 FindNextMenu (Selection
, FormSetLevel
);
533 // Initialize internal data structures of FormSet
535 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
536 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
537 DestroyFormSet (FormSet
);
540 Selection
->FormSet
= FormSet
;
541 mSystemLevelFormSet
= FormSet
;
544 // Display this formset
546 gCurrentSelection
= Selection
;
548 Status
= SetupBrowser (Selection
);
550 gCurrentSelection
= NULL
;
551 mSystemLevelFormSet
= NULL
;
553 if (gFlagReconnect
|| gCallbackReconnect
) {
554 RetVal
= ReconnectController (FormSet
->DriverHandle
);
556 PopupErrorMessage(BROWSER_RECONNECT_FAIL
, NULL
, NULL
, NULL
);
558 gFlagReconnect
= FALSE
;
559 gCallbackReconnect
= FALSE
;
563 // If no data is changed, don't need to save current FormSet into the maintain list.
565 if (!IsNvUpdateRequiredForFormSet (FormSet
)) {
566 CleanBrowserStorage(FormSet
);
567 RemoveEntryList (&FormSet
->Link
);
568 DestroyFormSet (FormSet
);
571 if (EFI_ERROR (Status
)) {
574 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
576 FreePool (Selection
);
579 if (ActionRequest
!= NULL
) {
580 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
581 if (gResetRequired
) {
582 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
586 mFormDisplay
->ExitDisplay();
589 // Clear the menu history data.
591 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
592 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
593 RemoveEntryList (&MenuList
->Link
);
598 // Restore globals used by SendForm()
600 RestoreBrowserContext ();
606 Get or set data to the storage.
608 @param ResultsDataSize The size of the buffer associatedwith ResultsData.
609 @param ResultsData A string returned from an IFR browser or
610 equivalent. The results string will have no
611 routing information in them.
612 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
613 (if RetrieveData = TRUE) data from the uncommitted
614 browser state information or set (if RetrieveData
615 = FALSE) data in the uncommitted browser state
617 @param Storage The pointer to the storage.
619 @retval EFI_SUCCESS The results have been distributed or are awaiting
625 IN OUT UINTN
*ResultsDataSize
,
626 IN OUT EFI_STRING
*ResultsData
,
627 IN BOOLEAN RetrieveData
,
628 IN BROWSER_STORAGE
*Storage
637 FORMSET_STORAGE
*BrowserStorage
;
641 // Generate <ConfigResp>
643 Status
= StorageToConfigResp (Storage
, &ConfigResp
, Storage
->ConfigRequest
, TRUE
);
644 if (EFI_ERROR (Status
)) {
649 // Skip <ConfigHdr> and '&' to point to <ConfigBody> when first copy the configbody.
650 // Also need to consider add "\0" at first time.
652 StrPtr
= StrStr (ConfigResp
, L
"PATH");
653 ASSERT (StrPtr
!= NULL
);
654 StrPtr
= StrStr (StrPtr
, L
"&");
656 BufferSize
= StrSize (StrPtr
);
659 // Copy the data if the input buffer is bigger enough.
661 if (*ResultsDataSize
>= BufferSize
) {
662 StrCpyS (*ResultsData
, *ResultsDataSize
/ sizeof (CHAR16
), StrPtr
);
665 *ResultsDataSize
= BufferSize
;
666 FreePool (ConfigResp
);
669 // Prepare <ConfigResp>
671 BrowserStorage
= GetFstStgFromBrsStg (Storage
);
672 ASSERT (BrowserStorage
!= NULL
);
673 TmpSize
= StrLen (*ResultsData
);
674 BufferSize
= (TmpSize
+ StrLen (BrowserStorage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
675 MaxLen
= BufferSize
/ sizeof (CHAR16
);
676 ConfigResp
= AllocateZeroPool (BufferSize
);
677 ASSERT (ConfigResp
!= NULL
);
679 StrCpyS (ConfigResp
, MaxLen
, BrowserStorage
->ConfigHdr
);
680 StrCatS (ConfigResp
, MaxLen
, L
"&");
681 StrCatS (ConfigResp
, MaxLen
, *ResultsData
);
684 // Update Browser uncommited data
686 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
687 FreePool (ConfigResp
);
688 if (EFI_ERROR (Status
)) {
697 This routine called this service in the browser to retrieve or set certain uncommitted
698 state information that resides in the open formsets.
700 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
702 @param ResultsDataSize A pointer to the size of the buffer associated
704 @param ResultsData A string returned from an IFR browser or
705 equivalent. The results string will have no
706 routing information in them.
707 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
708 (if RetrieveData = TRUE) data from the uncommitted
709 browser state information or set (if RetrieveData
710 = FALSE) data in the uncommitted browser state
712 @param VariableGuid An optional field to indicate the target variable
714 @param VariableName An optional field to indicate the target
715 human-readable variable name.
717 @retval EFI_SUCCESS The results have been distributed or are awaiting
719 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
720 contain the results data.
726 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
727 IN OUT UINTN
*ResultsDataSize
,
728 IN OUT EFI_STRING ResultsData
,
729 IN BOOLEAN RetrieveData
,
730 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
731 IN CONST CHAR16
*VariableName OPTIONAL
736 BROWSER_STORAGE
*Storage
;
737 FORMSET_STORAGE
*FormsetStorage
;
741 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
742 return EFI_INVALID_PARAMETER
;
745 TotalSize
= *ResultsDataSize
;
748 Status
= EFI_SUCCESS
;
750 if (VariableGuid
!= NULL
) {
752 // Try to find target storage in the current formset.
754 Link
= GetFirstNode (&gBrowserStorageList
);
755 while (!IsNull (&gBrowserStorageList
, Link
)) {
756 Storage
= BROWSER_STORAGE_FROM_LINK (Link
);
757 Link
= GetNextNode (&gBrowserStorageList
, Link
);
759 // Check the current storage.
761 if (!CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
765 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
766 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
768 // Buffer storage require both GUID and Name
770 if (VariableName
== NULL
) {
771 return EFI_NOT_FOUND
;
774 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
779 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
||
780 Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
781 if (mSystemLevelFormSet
== NULL
|| mSystemLevelFormSet
->HiiHandle
== NULL
) {
782 return EFI_NOT_FOUND
;
785 if (Storage
->HiiHandle
!= mSystemLevelFormSet
->HiiHandle
) {
790 Status
= ProcessStorage (&TotalSize
, &ResultsData
, RetrieveData
, Storage
);
791 if (EFI_ERROR (Status
)) {
795 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
796 ConfigRequestAdjust (Storage
, ResultsData
, TRUE
);
800 // Different formsets may have same varstore, so here just set the flag
801 // not exit the circle.
808 return EFI_NOT_FOUND
;
812 // GUID/Name is not specified, take the first storage in FormSet
814 if (mSystemLevelFormSet
== NULL
) {
815 return EFI_NOT_READY
;
819 // Generate <ConfigResp>
821 Link
= GetFirstNode (&mSystemLevelFormSet
->StorageListHead
);
822 if (IsNull (&mSystemLevelFormSet
->StorageListHead
, Link
)) {
823 return EFI_UNSUPPORTED
;
826 FormsetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
828 Status
= ProcessStorage (&TotalSize
, &ResultsData
, RetrieveData
, FormsetStorage
->BrowserStorage
);
829 if (EFI_ERROR (Status
)) {
835 Status
= TotalSize
<= *ResultsDataSize
? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
836 *ResultsDataSize
= TotalSize
;
845 Callback function for SimpleTextInEx protocol install events
847 @param Event the event that is signaled.
848 @param Context not used here.
853 FormDisplayCallback (
858 if (mFormDisplay
!= NULL
) {
862 gBS
->LocateProtocol (
863 &gEdkiiFormDisplayEngineProtocolGuid
,
865 (VOID
**) &mFormDisplay
870 Initialize Setup Browser driver.
872 @param ImageHandle The image handle.
873 @param SystemTable The system table.
875 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
876 @return Other value if failed to initialize the Setup Browser module.
882 IN EFI_HANDLE ImageHandle
,
883 IN EFI_SYSTEM_TABLE
*SystemTable
890 // Locate required Hii relative protocols
892 Status
= gBS
->LocateProtocol (
893 &gEfiHiiDatabaseProtocolGuid
,
895 (VOID
**) &mHiiDatabase
897 ASSERT_EFI_ERROR (Status
);
899 Status
= gBS
->LocateProtocol (
900 &gEfiHiiConfigRoutingProtocolGuid
,
902 (VOID
**) &mHiiConfigRouting
904 ASSERT_EFI_ERROR (Status
);
906 Status
= gBS
->LocateProtocol (
907 &gEfiDevicePathFromTextProtocolGuid
,
909 (VOID
**) &mPathFromText
913 // Install FormBrowser2 protocol
915 mPrivateData
.Handle
= NULL
;
916 Status
= gBS
->InstallProtocolInterface (
917 &mPrivateData
.Handle
,
918 &gEfiFormBrowser2ProtocolGuid
,
919 EFI_NATIVE_INTERFACE
,
920 &mPrivateData
.FormBrowser2
922 ASSERT_EFI_ERROR (Status
);
925 // Install FormBrowserEx2 protocol
927 InitializeListHead (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
);
928 InitializeListHead (&mPrivateData
.FormBrowserEx2
.OverrideQestListHead
);
929 mPrivateData
.Handle
= NULL
;
930 Status
= gBS
->InstallProtocolInterface (
931 &mPrivateData
.Handle
,
932 &gEdkiiFormBrowserEx2ProtocolGuid
,
933 EFI_NATIVE_INTERFACE
,
934 &mPrivateData
.FormBrowserEx2
936 ASSERT_EFI_ERROR (Status
);
938 Status
= gBS
->InstallProtocolInterface (
939 &mPrivateData
.Handle
,
940 &gEfiFormBrowserExProtocolGuid
,
941 EFI_NATIVE_INTERFACE
,
942 &mPrivateData
.FormBrowserEx
944 ASSERT_EFI_ERROR (Status
);
946 InitializeDisplayFormData ();
948 Status
= gBS
->LocateProtocol (
949 &gEdkiiFormDisplayEngineProtocolGuid
,
951 (VOID
**) &mFormDisplay
954 if (EFI_ERROR (Status
)) {
955 EfiCreateProtocolNotifyEvent (
956 &gEdkiiFormDisplayEngineProtocolGuid
,
969 Create a new string in HII Package List.
971 @param String The String to be added
972 @param HiiHandle The package list in the HII database to insert the
975 @return The output string.
981 IN EFI_HII_HANDLE HiiHandle
984 EFI_STRING_ID StringId
;
986 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
987 ASSERT (StringId
!= 0);
994 Delete a string from HII Package List.
996 @param StringId Id of the string in HII database.
997 @param HiiHandle The HII package list handle.
999 @retval EFI_SUCCESS The string was deleted successfully.
1004 IN EFI_STRING_ID StringId
,
1005 IN EFI_HII_HANDLE HiiHandle
1010 NullChar
= CHAR_NULL
;
1011 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
1017 Get the string based on the StringId and HII Package List Handle.
1019 @param Token The String's ID.
1020 @param HiiHandle The package list in the HII database to search for
1021 the specified string.
1023 @return The output string.
1028 IN EFI_STRING_ID Token
,
1029 IN EFI_HII_HANDLE HiiHandle
1034 if (HiiHandle
== NULL
) {
1038 String
= HiiGetString (HiiHandle
, Token
, NULL
);
1039 if (String
== NULL
) {
1040 String
= AllocateCopyPool (StrSize (mUnknownString
), mUnknownString
);
1041 ASSERT (String
!= NULL
);
1043 return (CHAR16
*) String
;
1048 Allocate new memory and then copy the Unicode string Source to Destination.
1050 @param Dest Location to copy string
1051 @param Src String to copy
1056 IN OUT CHAR16
**Dest
,
1060 if (*Dest
!= NULL
) {
1063 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
1064 ASSERT (*Dest
!= NULL
);
1069 Allocate new memory and concatinate Source on the end of Destination.
1071 @param Dest String to added to the end of.
1072 @param Src String to concatinate.
1077 IN OUT CHAR16
**Dest
,
1084 if (*Dest
== NULL
) {
1085 NewStringCpy (Dest
, Src
);
1089 MaxLen
= ( StrSize (*Dest
) + StrSize (Src
) - 1) / sizeof (CHAR16
);
1090 NewString
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
1091 ASSERT (NewString
!= NULL
);
1093 StrCpyS (NewString
, MaxLen
, *Dest
);
1094 StrCatS (NewString
, MaxLen
, Src
);
1101 Get Value for given Name from a NameValue Storage.
1103 @param Storage The NameValue Storage.
1104 @param Name The Name.
1105 @param Value The retured Value.
1106 @param GetValueFrom Where to get source value, from EditValue or Value.
1108 @retval EFI_SUCCESS Value found for given Name.
1109 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
1114 IN BROWSER_STORAGE
*Storage
,
1116 IN OUT CHAR16
**Value
,
1117 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
1121 NAME_VALUE_NODE
*Node
;
1123 if (GetValueFrom
!= GetSetValueWithEditBuffer
&& GetValueFrom
!= GetSetValueWithBuffer
) {
1124 return EFI_INVALID_PARAMETER
;
1129 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1130 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1131 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1133 if (StrCmp (Name
, Node
->Name
) == 0) {
1134 if (GetValueFrom
== GetSetValueWithEditBuffer
) {
1135 NewStringCpy (Value
, Node
->EditValue
);
1137 NewStringCpy (Value
, Node
->Value
);
1142 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1145 return EFI_NOT_FOUND
;
1150 Set Value of given Name in a NameValue Storage.
1152 @param Storage The NameValue Storage.
1153 @param Name The Name.
1154 @param Value The Value to set.
1155 @param SetValueTo Whether update editValue or Value.
1156 @param ReturnNode The node use the input name.
1158 @retval EFI_SUCCESS Value found for given Name.
1159 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
1164 IN BROWSER_STORAGE
*Storage
,
1167 IN GET_SET_QUESTION_VALUE_WITH SetValueTo
,
1168 OUT NAME_VALUE_NODE
**ReturnNode
1172 NAME_VALUE_NODE
*Node
;
1175 if (SetValueTo
!= GetSetValueWithEditBuffer
&& SetValueTo
!= GetSetValueWithBuffer
) {
1176 return EFI_INVALID_PARAMETER
;
1179 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1180 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1181 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1183 if (StrCmp (Name
, Node
->Name
) == 0) {
1184 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1185 Buffer
= Node
->EditValue
;
1187 Buffer
= Node
->Value
;
1189 if (Buffer
!= NULL
) {
1192 Buffer
= AllocateCopyPool (StrSize (Value
), Value
);
1193 ASSERT (Buffer
!= NULL
);
1194 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1195 Node
->EditValue
= Buffer
;
1197 Node
->Value
= Buffer
;
1200 if (ReturnNode
!= NULL
) {
1207 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1210 return EFI_NOT_FOUND
;
1215 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
1217 @param Storage The Storage to be conveted.
1218 @param ConfigResp The returned <ConfigResp>.
1219 @param ConfigRequest The ConfigRequest string.
1220 @param GetEditBuf Get the data from editbuffer or buffer.
1222 @retval EFI_SUCCESS Convert success.
1223 @retval EFI_INVALID_PARAMETER Incorrect storage type.
1227 StorageToConfigResp (
1228 IN BROWSER_STORAGE
*Storage
,
1229 IN CHAR16
**ConfigResp
,
1230 IN CHAR16
*ConfigRequest
,
1231 IN BOOLEAN GetEditBuf
1235 EFI_STRING Progress
;
1237 NAME_VALUE_NODE
*Node
;
1239 FORMSET_STORAGE
*FormsetStorage
;
1241 Status
= EFI_SUCCESS
;
1243 switch (Storage
->Type
) {
1244 case EFI_HII_VARSTORE_BUFFER
:
1245 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
1246 SourceBuf
= GetEditBuf
? Storage
->EditBuffer
: Storage
->Buffer
;
1247 Status
= mHiiConfigRouting
->BlockToConfig (
1257 case EFI_HII_VARSTORE_NAME_VALUE
:
1259 FormsetStorage
= GetFstStgFromBrsStg(Storage
);
1260 ASSERT (FormsetStorage
!= NULL
);
1261 NewStringCat (ConfigResp
, FormsetStorage
->ConfigHdr
);
1263 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1264 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1265 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1267 if (StrStr (ConfigRequest
, Node
->Name
) != NULL
) {
1268 NewStringCat (ConfigResp
, L
"&");
1269 NewStringCat (ConfigResp
, Node
->Name
);
1270 NewStringCat (ConfigResp
, L
"=");
1272 NewStringCat (ConfigResp
, Node
->EditValue
);
1274 NewStringCat (ConfigResp
, Node
->Value
);
1277 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1281 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1283 Status
= EFI_INVALID_PARAMETER
;
1292 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
1294 @param Storage The Storage to receive the settings.
1295 @param ConfigResp The <ConfigResp> to be converted.
1297 @retval EFI_SUCCESS Convert success.
1298 @retval EFI_INVALID_PARAMETER Incorrect storage type.
1302 ConfigRespToStorage (
1303 IN BROWSER_STORAGE
*Storage
,
1304 IN CHAR16
*ConfigResp
1308 EFI_STRING Progress
;
1314 Status
= EFI_SUCCESS
;
1316 switch (Storage
->Type
) {
1317 case EFI_HII_VARSTORE_BUFFER
:
1318 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
1319 BufferSize
= Storage
->Size
;
1320 Status
= mHiiConfigRouting
->ConfigToBlock (
1323 Storage
->EditBuffer
,
1329 case EFI_HII_VARSTORE_NAME_VALUE
:
1330 StrPtr
= StrStr (ConfigResp
, L
"PATH");
1331 if (StrPtr
== NULL
) {
1334 StrPtr
= StrStr (ConfigResp
, L
"&");
1335 while (StrPtr
!= NULL
) {
1339 StrPtr
= StrPtr
+ 1;
1341 StrPtr
= StrStr (StrPtr
, L
"=");
1342 if (StrPtr
== NULL
) {
1350 StrPtr
= StrPtr
+ 1;
1352 StrPtr
= StrStr (StrPtr
, L
"&");
1353 if (StrPtr
!= NULL
) {
1356 SetValueByName (Storage
, Name
, Value
, GetSetValueWithEditBuffer
, NULL
);
1360 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1362 Status
= EFI_INVALID_PARAMETER
;
1370 Convert the buffer value to HiiValue.
1372 @param Question The question.
1373 @param Value Unicode buffer save the question value.
1375 @retval Status whether convert the value success.
1380 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1385 BOOLEAN IsBufferStorage
;
1397 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1398 if (Question
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1399 Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1400 IsBufferStorage
= TRUE
;
1402 IsBufferStorage
= FALSE
;
1406 // Question Value is provided by Buffer Storage or NameValue Storage
1408 if (Question
->BufferValue
!= NULL
) {
1410 // This Question is password or orderedlist
1412 Dst
= Question
->BufferValue
;
1415 // Other type of Questions
1417 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1421 // Temp cut at the end of this section, end with '\0' or '&'.
1424 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1427 TempChar
= *StringPtr
;
1430 LengthStr
= StrLen (Value
);
1431 Status
= EFI_SUCCESS
;
1432 if (!IsBufferStorage
&& IsString
) {
1434 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1435 // Add string tail char L'\0' into Length
1437 Length
= Question
->StorageWidth
+ sizeof (CHAR16
);
1438 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1439 Status
= EFI_BUFFER_TOO_SMALL
;
1441 DstBuf
= (CHAR16
*) Dst
;
1442 ZeroMem (TemStr
, sizeof (TemStr
));
1443 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1444 StrnCpyS (TemStr
, sizeof (TemStr
) / sizeof (CHAR16
), Value
+ Index
, 4);
1445 DstBuf
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1448 // Add tailing L'\0' character
1450 DstBuf
[Index
/4] = L
'\0';
1453 if (Question
->StorageWidth
< ((LengthStr
+ 1) / 2)) {
1454 Status
= EFI_BUFFER_TOO_SMALL
;
1456 ZeroMem (TemStr
, sizeof (TemStr
));
1457 for (Index
= 0; Index
< LengthStr
; Index
++) {
1458 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1459 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1460 if ((Index
& 1) == 0) {
1461 Dst
[Index
/2] = DigitUint8
;
1463 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1469 *StringPtr
= TempChar
;
1475 Get Question's current Value.
1477 @param FormSet FormSet data structure.
1478 @param Form Form data structure.
1479 @param Question Question to be initialized.
1480 @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver.
1482 @retval EFI_SUCCESS The function completed successfully.
1487 IN FORM_BROWSER_FORMSET
*FormSet
,
1488 IN FORM_BROWSER_FORM
*Form
,
1489 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1490 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
1499 BROWSER_STORAGE
*Storage
;
1500 FORMSET_STORAGE
*FormsetStorage
;
1501 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1502 CHAR16
*ConfigRequest
;
1507 BOOLEAN IsBufferStorage
;
1510 Status
= EFI_SUCCESS
;
1514 if (GetValueFrom
>= GetSetValueWithMax
) {
1515 return EFI_INVALID_PARAMETER
;
1519 // Question value is provided by an Expression, evaluate it
1521 if (Question
->ValueExpression
!= NULL
) {
1522 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1523 if (!EFI_ERROR (Status
)) {
1524 if (Question
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1525 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1526 if (Question
->StorageWidth
> Question
->ValueExpression
->Result
.BufferLen
) {
1527 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->ValueExpression
->Result
.BufferLen
);
1528 Question
->HiiValue
.BufferLen
= Question
->ValueExpression
->Result
.BufferLen
;
1530 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
1531 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1533 FreePool (Question
->ValueExpression
->Result
.Buffer
);
1535 Question
->HiiValue
.Type
= Question
->ValueExpression
->Result
.Type
;
1536 CopyMem (&Question
->HiiValue
.Value
, &Question
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1542 // Get question value by read expression.
1544 if (Question
->ReadExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1545 Status
= EvaluateExpression (FormSet
, Form
, Question
->ReadExpression
);
1546 if (!EFI_ERROR (Status
) &&
1547 ((Question
->ReadExpression
->Result
.Type
< EFI_IFR_TYPE_OTHER
) || (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
))) {
1549 // Only update question value to the valid result.
1551 if (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1552 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1553 if (Question
->StorageWidth
> Question
->ReadExpression
->Result
.BufferLen
) {
1554 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->ReadExpression
->Result
.BufferLen
);
1555 Question
->HiiValue
.BufferLen
= Question
->ReadExpression
->Result
.BufferLen
;
1557 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->StorageWidth
);
1558 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1560 FreePool (Question
->ReadExpression
->Result
.Buffer
);
1562 Question
->HiiValue
.Type
= Question
->ReadExpression
->Result
.Type
;
1563 CopyMem (&Question
->HiiValue
.Value
, &Question
->ReadExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1569 // Question value is provided by RTC
1571 Storage
= Question
->Storage
;
1572 QuestionValue
= &Question
->HiiValue
.Value
;
1573 if (Storage
== NULL
) {
1575 // It's a Question without storage, or RTC date/time
1577 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1579 // Date and time define the same Flags bit
1581 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1582 case QF_DATE_STORAGE_TIME
:
1583 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1586 case QF_DATE_STORAGE_WAKEUP
:
1587 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1590 case QF_DATE_STORAGE_NORMAL
:
1593 // For date/time without storage
1598 if (EFI_ERROR (Status
)) {
1599 if (Question
->Operand
== EFI_IFR_DATE_OP
){
1600 QuestionValue
->date
.Year
= 0xff;
1601 QuestionValue
->date
.Month
= 0xff;
1602 QuestionValue
->date
.Day
= 0xff;
1604 QuestionValue
->time
.Hour
= 0xff;
1605 QuestionValue
->time
.Minute
= 0xff;
1606 QuestionValue
->time
.Second
= 0xff;
1611 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1612 QuestionValue
->date
.Year
= EfiTime
.Year
;
1613 QuestionValue
->date
.Month
= EfiTime
.Month
;
1614 QuestionValue
->date
.Day
= EfiTime
.Day
;
1616 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1617 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1618 QuestionValue
->time
.Second
= EfiTime
.Second
;
1626 // Question value is provided by EFI variable
1628 StorageWidth
= Question
->StorageWidth
;
1629 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1630 if (Question
->BufferValue
!= NULL
) {
1631 Dst
= Question
->BufferValue
;
1633 Dst
= (UINT8
*) QuestionValue
;
1636 Status
= gRT
->GetVariable (
1637 Question
->VariableName
,
1644 // Always return success, even this EFI variable doesn't exist
1650 // Question Value is provided by Buffer Storage or NameValue Storage
1652 if (Question
->BufferValue
!= NULL
) {
1654 // This Question is password or orderedlist
1656 Dst
= Question
->BufferValue
;
1659 // Other type of Questions
1661 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1664 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1665 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1666 IsBufferStorage
= TRUE
;
1668 IsBufferStorage
= FALSE
;
1670 if (GetValueFrom
== GetSetValueWithEditBuffer
|| GetValueFrom
== GetSetValueWithBuffer
) {
1671 if (IsBufferStorage
) {
1672 if (GetValueFrom
== GetSetValueWithEditBuffer
) {
1674 // Copy from storage Edit buffer
1676 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1679 // Copy from storage Edit buffer
1681 CopyMem (Dst
, Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1685 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
, GetValueFrom
);
1686 if (EFI_ERROR (Status
)) {
1690 ASSERT (Value
!= NULL
);
1691 Status
= BufferToValue (Question
, Value
);
1695 FormsetStorage
= GetFstStgFromVarId(FormSet
, Question
->VarStoreId
);
1696 ASSERT (FormsetStorage
!= NULL
);
1698 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1699 // <ConfigHdr> + "&" + <VariableName>
1701 if (IsBufferStorage
) {
1702 Length
= StrLen (FormsetStorage
->ConfigHdr
);
1703 Length
+= StrLen (Question
->BlockName
);
1705 Length
= StrLen (FormsetStorage
->ConfigHdr
);
1706 Length
+= StrLen (Question
->VariableName
) + 1;
1708 // Allocate buffer include '\0'
1709 MaxLen
= Length
+ 1;
1710 ConfigRequest
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
1711 ASSERT (ConfigRequest
!= NULL
);
1713 StrCpyS (ConfigRequest
, MaxLen
, FormsetStorage
->ConfigHdr
);
1714 if (IsBufferStorage
) {
1715 StrCatS (ConfigRequest
, MaxLen
, Question
->BlockName
);
1717 StrCatS (ConfigRequest
, MaxLen
, L
"&");
1718 StrCatS (ConfigRequest
, MaxLen
, Question
->VariableName
);
1722 // Request current settings from Configuration Driver
1724 Status
= mHiiConfigRouting
->ExtractConfig (
1730 FreePool (ConfigRequest
);
1731 if (EFI_ERROR (Status
)) {
1736 // Skip <ConfigRequest>
1738 if (IsBufferStorage
) {
1739 Value
= StrStr (Result
, L
"&VALUE");
1740 if (Value
== NULL
) {
1742 return EFI_NOT_FOUND
;
1749 Value
= Result
+ Length
;
1751 if (*Value
!= '=') {
1753 return EFI_NOT_FOUND
;
1756 // Skip '=', point to value
1760 Status
= BufferToValue (Question
, Value
);
1761 if (EFI_ERROR (Status
)) {
1767 // Synchronize Edit Buffer
1769 if (IsBufferStorage
) {
1770 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1772 SetValueByName (Storage
, Question
->VariableName
, Value
, GetSetValueWithEditBuffer
, NULL
);
1775 if (Result
!= NULL
) {
1785 Save Question Value to edit copy(cached) or Storage(uncached).
1787 @param FormSet FormSet data structure.
1788 @param Form Form data structure.
1789 @param Question Pointer to the Question.
1790 @param SetValueTo Update the question value to editbuffer , buffer or hii driver.
1792 @retval EFI_SUCCESS The function completed successfully.
1797 IN FORM_BROWSER_FORMSET
*FormSet
,
1798 IN FORM_BROWSER_FORM
*Form
,
1799 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1800 IN GET_SET_QUESTION_VALUE_WITH SetValueTo
1810 BROWSER_STORAGE
*Storage
;
1811 FORMSET_STORAGE
*FormsetStorage
;
1812 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1817 BOOLEAN IsBufferStorage
;
1823 NAME_VALUE_NODE
*Node
;
1826 Status
= EFI_SUCCESS
;
1829 if (SetValueTo
>= GetSetValueWithMax
) {
1830 return EFI_INVALID_PARAMETER
;
1834 // If Question value is provided by an Expression, then it is read only
1836 if (Question
->ValueExpression
!= NULL
) {
1841 // Before set question value, evaluate its write expression.
1843 if (Question
->WriteExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1844 Status
= EvaluateExpression (FormSet
, Form
, Question
->WriteExpression
);
1845 if (EFI_ERROR (Status
)) {
1851 // Question value is provided by RTC
1853 Storage
= Question
->Storage
;
1854 QuestionValue
= &Question
->HiiValue
.Value
;
1855 if (Storage
== NULL
) {
1857 // It's a Question without storage, or RTC date/time
1859 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1861 // Date and time define the same Flags bit
1863 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1864 case QF_DATE_STORAGE_TIME
:
1865 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1868 case QF_DATE_STORAGE_WAKEUP
:
1869 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1872 case QF_DATE_STORAGE_NORMAL
:
1875 // For date/time without storage
1880 if (EFI_ERROR (Status
)) {
1884 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1885 EfiTime
.Year
= QuestionValue
->date
.Year
;
1886 EfiTime
.Month
= QuestionValue
->date
.Month
;
1887 EfiTime
.Day
= QuestionValue
->date
.Day
;
1889 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1890 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1891 EfiTime
.Second
= QuestionValue
->time
.Second
;
1894 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1895 Status
= gRT
->SetTime (&EfiTime
);
1897 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1905 // Question value is provided by EFI variable
1907 StorageWidth
= Question
->StorageWidth
;
1908 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1909 if (Question
->BufferValue
!= NULL
) {
1910 Src
= Question
->BufferValue
;
1912 Src
= (UINT8
*) QuestionValue
;
1915 Status
= gRT
->SetVariable (
1916 Question
->VariableName
,
1918 Storage
->Attributes
,
1926 // Question Value is provided by Buffer Storage or NameValue Storage
1928 if (Question
->BufferValue
!= NULL
) {
1929 Src
= Question
->BufferValue
;
1931 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1934 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1935 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1936 IsBufferStorage
= TRUE
;
1938 IsBufferStorage
= FALSE
;
1940 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1942 if (SetValueTo
== GetSetValueWithEditBuffer
|| SetValueTo
== GetSetValueWithBuffer
) {
1943 if (IsBufferStorage
) {
1944 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1946 // Copy to storage edit buffer
1948 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1949 } else if (SetValueTo
== GetSetValueWithBuffer
) {
1951 // Copy to storage edit buffer
1953 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1958 // Allocate enough string buffer.
1961 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1962 Value
= AllocateZeroPool (BufferLen
);
1963 ASSERT (Value
!= NULL
);
1965 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1967 TemName
= (CHAR16
*) Src
;
1969 for (; *TemName
!= L
'\0'; TemName
++) {
1970 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1973 BufferLen
= StorageWidth
* 2 + 1;
1974 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1975 ASSERT (Value
!= NULL
);
1977 // Convert Buffer to Hex String
1979 TemBuffer
= Src
+ StorageWidth
- 1;
1981 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1982 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1986 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
, SetValueTo
, &Node
);
1988 if (EFI_ERROR (Status
)) {
1992 } else if (SetValueTo
== GetSetValueWithHiiDriver
) {
1994 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1995 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1997 if (IsBufferStorage
) {
1998 Length
= StrLen (Question
->BlockName
) + 7;
2000 Length
= StrLen (Question
->VariableName
) + 2;
2002 if (!IsBufferStorage
&& IsString
) {
2003 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
2005 Length
+= (StorageWidth
* 2);
2007 FormsetStorage
= GetFstStgFromVarId(FormSet
, Question
->VarStoreId
);
2008 ASSERT (FormsetStorage
!= NULL
);
2009 MaxLen
= StrLen (FormsetStorage
->ConfigHdr
) + Length
+ 1;
2010 ConfigResp
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
2011 ASSERT (ConfigResp
!= NULL
);
2013 StrCpyS (ConfigResp
, MaxLen
, FormsetStorage
->ConfigHdr
);
2014 if (IsBufferStorage
) {
2015 StrCatS (ConfigResp
, MaxLen
, Question
->BlockName
);
2016 StrCatS (ConfigResp
, MaxLen
, L
"&VALUE=");
2018 StrCatS (ConfigResp
, MaxLen
, L
"&");
2019 StrCatS (ConfigResp
, MaxLen
, Question
->VariableName
);
2020 StrCatS (ConfigResp
, MaxLen
, L
"=");
2023 Value
= ConfigResp
+ StrLen (ConfigResp
);
2025 if (!IsBufferStorage
&& IsString
) {
2027 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
2029 TemName
= (CHAR16
*) Src
;
2031 for (; *TemName
!= L
'\0'; TemName
++) {
2032 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
2036 // Convert Buffer to Hex String
2038 TemBuffer
= Src
+ StorageWidth
- 1;
2040 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
2041 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
2046 // Convert to lower char.
2048 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
2049 if (*Value
>= L
'A' && *Value
<= L
'Z') {
2050 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
2055 // Submit Question Value to Configuration Driver
2057 Status
= mHiiConfigRouting
->RouteConfig (
2062 if (EFI_ERROR (Status
)) {
2063 FreePool (ConfigResp
);
2066 FreePool (ConfigResp
);
2069 // Sync storage, from editbuffer to buffer.
2071 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
2079 Perform nosubmitif check for a Form.
2081 @param FormSet FormSet data structure.
2082 @param Form Form data structure.
2083 @param Question The Question to be validated.
2084 @param Type Validation type: NoSubmit
2086 @retval EFI_SUCCESS Form validation pass.
2087 @retval other Form validation failed.
2092 IN FORM_BROWSER_FORMSET
*FormSet
,
2093 IN FORM_BROWSER_FORM
*Form
,
2094 IN FORM_BROWSER_STATEMENT
*Question
,
2100 LIST_ENTRY
*ListHead
;
2101 FORM_EXPRESSION
*Expression
;
2102 UINT32 BrowserStatus
;
2105 BrowserStatus
= BROWSER_SUCCESS
;
2109 case EFI_HII_EXPRESSION_INCONSISTENT_IF
:
2110 ListHead
= &Question
->InconsistentListHead
;
2113 case EFI_HII_EXPRESSION_WARNING_IF
:
2114 ListHead
= &Question
->WarningListHead
;
2117 case EFI_HII_EXPRESSION_NO_SUBMIT_IF
:
2118 ListHead
= &Question
->NoSubmitListHead
;
2123 return EFI_UNSUPPORTED
;
2126 Link
= GetFirstNode (ListHead
);
2127 while (!IsNull (ListHead
, Link
)) {
2128 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
2131 // Evaluate the expression
2133 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
2134 if (EFI_ERROR (Status
)) {
2138 if (IsTrue (&Expression
->Result
)) {
2140 case EFI_HII_EXPRESSION_INCONSISTENT_IF
:
2141 BrowserStatus
= BROWSER_INCONSISTENT_IF
;
2144 case EFI_HII_EXPRESSION_WARNING_IF
:
2145 BrowserStatus
= BROWSER_WARNING_IF
;
2148 case EFI_HII_EXPRESSION_NO_SUBMIT_IF
:
2149 BrowserStatus
= BROWSER_NO_SUBMIT_IF
;
2151 // This code only used to compatible with old display engine,
2152 // New display engine will not use this field.
2154 if (Expression
->Error
!= 0) {
2155 ErrorStr
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
2164 if (!((Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) && mSystemSubmit
)) {
2166 // If in system submit process and for no_submit_if check, not popup this error message.
2167 // Will process this fail again later in not system submit process.
2169 PopupErrorMessage(BrowserStatus
, FormSet
->HiiHandle
, Expression
->OpCode
, ErrorStr
);
2172 if (ErrorStr
!= NULL
) {
2173 FreePool (ErrorStr
);
2176 if (Type
== EFI_HII_EXPRESSION_WARNING_IF
) {
2179 return EFI_NOT_READY
;
2183 Link
= GetNextNode (ListHead
, Link
);
2190 Perform question check.
2192 If one question has more than one check, process form high priority to low.
2193 Only one error info will be popup.
2195 @param FormSet FormSet data structure.
2196 @param Form Form data structure.
2197 @param Question The Question to be validated.
2199 @retval EFI_SUCCESS Form validation pass.
2200 @retval other Form validation failed.
2204 ValueChangedValidation (
2205 IN FORM_BROWSER_FORMSET
*FormSet
,
2206 IN FORM_BROWSER_FORM
*Form
,
2207 IN FORM_BROWSER_STATEMENT
*Question
2212 Status
= EFI_SUCCESS
;
2215 // Do the inconsistentif check.
2217 if (!IsListEmpty (&Question
->InconsistentListHead
)) {
2218 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_INCONSISTENT_IF
);
2219 if (EFI_ERROR (Status
)) {
2225 // Do the warningif check.
2227 if (!IsListEmpty (&Question
->WarningListHead
)) {
2228 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_WARNING_IF
);
2235 Perform NoSubmit check for each Form in FormSet.
2237 @param FormSet FormSet data structure.
2238 @param CurrentForm Current input form data structure.
2239 @param Statement The statement for this check.
2241 @retval EFI_SUCCESS Form validation pass.
2242 @retval other Form validation failed.
2247 IN FORM_BROWSER_FORMSET
*FormSet
,
2248 IN OUT FORM_BROWSER_FORM
**CurrentForm
,
2249 OUT FORM_BROWSER_STATEMENT
**Statement
2254 FORM_BROWSER_STATEMENT
*Question
;
2255 FORM_BROWSER_FORM
*Form
;
2256 LIST_ENTRY
*LinkForm
;
2258 LinkForm
= GetFirstNode (&FormSet
->FormListHead
);
2259 while (!IsNull (&FormSet
->FormListHead
, LinkForm
)) {
2260 Form
= FORM_BROWSER_FORM_FROM_LINK (LinkForm
);
2261 LinkForm
= GetNextNode (&FormSet
->FormListHead
, LinkForm
);
2263 if (*CurrentForm
!= NULL
&& *CurrentForm
!= Form
) {
2267 Link
= GetFirstNode (&Form
->StatementListHead
);
2268 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2269 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2270 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
2271 if (EFI_ERROR (Status
)) {
2272 if (*CurrentForm
== NULL
) {
2273 *CurrentForm
= Form
;
2275 if (Statement
!= NULL
) {
2276 *Statement
= Question
;
2281 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2289 Fill storage's edit copy with settings requested from Configuration Driver.
2291 @param Storage The storage which need to sync.
2292 @param ConfigRequest The config request string which used to sync storage.
2293 @param SyncOrRestore Sync the buffer to editbuffer or Restore the
2294 editbuffer to buffer
2295 if TRUE, copy the editbuffer to the buffer.
2296 if FALSE, copy the buffer to the editbuffer.
2298 @retval EFI_SUCCESS The function completed successfully.
2302 SynchronizeStorage (
2303 OUT BROWSER_STORAGE
*Storage
,
2304 IN CHAR16
*ConfigRequest
,
2305 IN BOOLEAN SyncOrRestore
2309 EFI_STRING Progress
;
2313 NAME_VALUE_NODE
*Node
;
2317 Status
= EFI_SUCCESS
;
2320 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
2321 (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
2322 BufferSize
= Storage
->Size
;
2324 if (SyncOrRestore
) {
2325 Src
= Storage
->EditBuffer
;
2326 Dst
= Storage
->Buffer
;
2328 Src
= Storage
->Buffer
;
2329 Dst
= Storage
->EditBuffer
;
2332 if (ConfigRequest
!= NULL
) {
2333 Status
= mHiiConfigRouting
->BlockToConfig(
2341 if (EFI_ERROR (Status
)) {
2345 Status
= mHiiConfigRouting
->ConfigToBlock (
2352 if (Result
!= NULL
) {
2356 CopyMem (Dst
, Src
, BufferSize
);
2358 } else if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2359 Link
= GetFirstNode (&Storage
->NameValueListHead
);
2360 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
2361 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
2363 if ((ConfigRequest
!= NULL
&& StrStr (ConfigRequest
, Node
->Name
) != NULL
) ||
2364 (ConfigRequest
== NULL
)) {
2365 if (SyncOrRestore
) {
2366 NewStringCpy (&Node
->Value
, Node
->EditValue
);
2368 NewStringCpy (&Node
->EditValue
, Node
->Value
);
2372 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
2380 When discard the question value, call the callback function with Changed type
2381 to inform the hii driver.
2383 @param FormSet FormSet data structure.
2384 @param Form Form data structure.
2388 SendDiscardInfoToDriver (
2389 IN FORM_BROWSER_FORMSET
*FormSet
,
2390 IN FORM_BROWSER_FORM
*Form
2394 FORM_BROWSER_STATEMENT
*Question
;
2395 EFI_IFR_TYPE_VALUE
*TypeValue
;
2396 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
2398 if (FormSet
->ConfigAccess
== NULL
) {
2402 Link
= GetFirstNode (&Form
->StatementListHead
);
2403 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2404 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2405 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2407 if (Question
->Storage
== NULL
|| Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2411 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != EFI_IFR_FLAG_CALLBACK
) {
2415 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
) {
2419 if (!Question
->ValueChanged
) {
2424 // Restore the question value before call the CHANGED callback type.
2426 GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
2428 if (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
) {
2429 TypeValue
= (EFI_IFR_TYPE_VALUE
*) Question
->BufferValue
;
2431 TypeValue
= &Question
->HiiValue
.Value
;
2434 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
2435 FormSet
->ConfigAccess
->Callback (
2436 FormSet
->ConfigAccess
,
2437 EFI_BROWSER_ACTION_CHANGED
,
2438 Question
->QuestionId
,
2439 Question
->HiiValue
.Type
,
2447 Validate the HiiHandle.
2449 @param HiiHandle The input HiiHandle which need to validate.
2451 @retval TRUE The handle is validate.
2452 @retval FALSE The handle is invalidate.
2457 EFI_HII_HANDLE HiiHandle
2460 EFI_HII_HANDLE
*HiiHandles
;
2464 if (HiiHandle
== NULL
) {
2470 HiiHandles
= HiiGetHiiHandles (NULL
);
2471 ASSERT (HiiHandles
!= NULL
);
2473 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
2474 if (HiiHandles
[Index
] == HiiHandle
) {
2480 FreePool (HiiHandles
);
2486 Validate the FormSet. If the formset is not validate, remove it from the list.
2488 @param FormSet The input FormSet which need to validate.
2490 @retval TRUE The handle is validate.
2491 @retval FALSE The handle is invalidate.
2496 FORM_BROWSER_FORMSET
*FormSet
2501 ASSERT (FormSet
!= NULL
);
2503 Find
= ValidateHiiHandle(FormSet
->HiiHandle
);
2505 // Should not remove the formset which is being used.
2507 if (!Find
&& (FormSet
!= gCurrentSelection
->FormSet
)) {
2508 CleanBrowserStorage(FormSet
);
2509 RemoveEntryList (&FormSet
->Link
);
2510 DestroyFormSet (FormSet
);
2516 Check whether need to enable the reset flag in form level.
2517 Also clean all ValueChanged flag in question.
2519 @param SetFlag Whether need to set the Reset Flag.
2520 @param FormSet FormSet data structure.
2521 @param Form Form data structure.
2527 IN FORM_BROWSER_FORMSET
*FormSet
,
2528 IN FORM_BROWSER_FORM
*Form
2532 FORM_BROWSER_STATEMENT
*Question
;
2535 Link
= GetFirstNode (&Form
->StatementListHead
);
2536 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2537 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2538 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2540 if (!Question
->ValueChanged
) {
2544 OldValue
= Question
->ValueChanged
;
2547 // Compare the buffer and editbuffer data to see whether the data has been saved.
2549 Question
->ValueChanged
= IsQuestionValueChanged(FormSet
, Form
, Question
, GetSetValueWithBothBuffer
);
2552 // Only the changed data has been saved, then need to set the reset flag.
2554 if (SetFlag
&& OldValue
&& !Question
->ValueChanged
) {
2555 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_RESET_REQUIRED
) != 0) {
2556 gResetRequired
= TRUE
;
2559 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_RECONNECT_REQUIRED
) != 0) {
2560 gFlagReconnect
= TRUE
;
2567 Check whether need to enable the reset flag.
2568 Also clean ValueChanged flag for all statements.
2570 Form level or formset level, only one.
2572 @param SetFlag Whether need to set the Reset Flag.
2573 @param FormSet FormSet data structure.
2574 @param Form Form data structure.
2578 ValueChangeResetFlagUpdate (
2580 IN FORM_BROWSER_FORMSET
*FormSet
,
2581 IN FORM_BROWSER_FORM
*Form
2584 FORM_BROWSER_FORM
*CurrentForm
;
2588 UpdateFlagForForm(SetFlag
, FormSet
, Form
);
2592 Link
= GetFirstNode (&FormSet
->FormListHead
);
2593 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2594 CurrentForm
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2595 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2597 UpdateFlagForForm(SetFlag
, FormSet
, CurrentForm
);
2602 Base on the return Progress string to find the form.
2604 Base on the first return Offset/Width (Name) string to find the form
2605 which keep this string.
2607 @param FormSet FormSet data structure.
2608 @param Storage Storage which has this Progress string.
2609 @param Progress The Progress string which has the first fail string.
2610 @param RetForm The return form for this progress string.
2611 @param RetQuestion The return question for the error progress string.
2613 @retval TRUE Find the error form and statement for this error progress string.
2614 @retval FALSE Not find the error form.
2618 FindQuestionFromProgress (
2619 IN FORM_BROWSER_FORMSET
*FormSet
,
2620 IN BROWSER_STORAGE
*Storage
,
2621 IN EFI_STRING Progress
,
2622 OUT FORM_BROWSER_FORM
**RetForm
,
2623 OUT FORM_BROWSER_STATEMENT
**RetQuestion
2627 LIST_ENTRY
*LinkStorage
;
2628 LIST_ENTRY
*LinkStatement
;
2629 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2630 FORM_BROWSER_FORM
*Form
;
2632 FORM_BROWSER_STATEMENT
*Statement
;
2634 ASSERT ((*Progress
== '&') || (*Progress
== 'G'));
2638 *RetQuestion
= NULL
;
2641 // Skip the first "&" or the ConfigHdr part.
2643 if (*Progress
== '&') {
2647 // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string.
2649 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2651 // For Name/Value type, Skip the ConfigHdr part.
2653 EndStr
= StrStr (Progress
, L
"PATH=");
2654 ASSERT (EndStr
!= NULL
);
2655 while (*EndStr
!= '&') {
2662 // For Buffer type, Skip the ConfigHdr part.
2664 EndStr
= StrStr (Progress
, L
"&OFFSET=");
2665 ASSERT (EndStr
!= NULL
);
2669 Progress
= EndStr
+ 1;
2673 // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string.
2675 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2677 // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset,
2678 // here, just keep the "Fred" string.
2680 EndStr
= StrStr (Progress
, L
"=");
2681 ASSERT (EndStr
!= NULL
);
2685 // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####",
2686 // here, just keep the "OFFSET=0x####&WIDTH=0x####" string.
2688 EndStr
= StrStr (Progress
, L
"&VALUE=");
2689 ASSERT (EndStr
!= NULL
);
2694 // Search in the form list.
2696 Link
= GetFirstNode (&FormSet
->FormListHead
);
2697 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2698 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2699 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2702 // Search in the ConfigReqeust list in this form.
2704 LinkStorage
= GetFirstNode (&Form
->ConfigRequestHead
);
2705 while (!IsNull (&Form
->ConfigRequestHead
, LinkStorage
)) {
2706 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (LinkStorage
);
2707 LinkStorage
= GetNextNode (&Form
->ConfigRequestHead
, LinkStorage
);
2709 if (Storage
!= ConfigInfo
->Storage
) {
2713 if (StrStr (ConfigInfo
->ConfigRequest
, Progress
) != NULL
) {
2715 // Find the OffsetWidth string in this form.
2722 if (*RetForm
!= NULL
) {
2723 LinkStatement
= GetFirstNode (&Form
->StatementListHead
);
2724 while (!IsNull (&Form
->StatementListHead
, LinkStatement
)) {
2725 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (LinkStatement
);
2726 LinkStatement
= GetNextNode (&Form
->StatementListHead
, LinkStatement
);
2728 if (Statement
->BlockName
!= NULL
&& StrStr (Statement
->BlockName
, Progress
) != NULL
) {
2729 *RetQuestion
= Statement
;
2733 if (Statement
->VariableName
!= NULL
&& StrStr (Statement
->VariableName
, Progress
) != NULL
) {
2734 *RetQuestion
= Statement
;
2740 if (*RetForm
!= NULL
) {
2746 // restore the OffsetWidth string to the original format.
2748 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2754 return (BOOLEAN
) (*RetForm
!= NULL
);
2758 Popup an save error info and get user input.
2760 @param TitleId The form title id.
2761 @param HiiHandle The hii handle for this package.
2763 @retval UINT32 The user select option for the save fail.
2764 BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET
2768 IN EFI_STRING_ID TitleId
,
2769 IN EFI_HII_HANDLE HiiHandle
2773 CHAR16
*StringBuffer
;
2776 FormTitle
= GetToken (TitleId
, HiiHandle
);
2778 StringBuffer
= AllocateZeroPool (256 * sizeof (CHAR16
));
2779 ASSERT (StringBuffer
!= NULL
);
2783 24 * sizeof (CHAR16
) + StrSize (FormTitle
),
2784 L
"Submit Fail For Form: %s.",
2788 RetVal
= PopupErrorMessage(BROWSER_SUBMIT_FAIL
, NULL
, NULL
, StringBuffer
);
2790 FreePool (StringBuffer
);
2791 FreePool (FormTitle
);
2797 Popup an NO_SUBMIT_IF error info and get user input.
2799 @param TitleId The form title id.
2800 @param HiiHandle The hii handle for this package.
2802 @retval UINT32 The user select option for the save fail.
2803 BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET
2806 ConfirmNoSubmitFail (
2807 IN EFI_STRING_ID TitleId
,
2808 IN EFI_HII_HANDLE HiiHandle
2812 CHAR16
*StringBuffer
;
2815 FormTitle
= GetToken (TitleId
, HiiHandle
);
2817 StringBuffer
= AllocateZeroPool (256 * sizeof (CHAR16
));
2818 ASSERT (StringBuffer
!= NULL
);
2822 24 * sizeof (CHAR16
) + StrSize (FormTitle
),
2823 L
"NO_SUBMIT_IF error For Form: %s.",
2827 RetVal
= PopupErrorMessage(BROWSER_SUBMIT_FAIL_NO_SUBMIT_IF
, NULL
, NULL
, StringBuffer
);
2829 FreePool (StringBuffer
);
2830 FreePool (FormTitle
);
2836 Discard data based on the input setting scope (Form, FormSet or System).
2838 @param FormSet FormSet data structure.
2839 @param Form Form data structure.
2840 @param SettingScope Setting Scope for Discard action.
2842 @retval EFI_SUCCESS The function completed successfully.
2843 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2848 IN FORM_BROWSER_FORMSET
*FormSet
,
2849 IN FORM_BROWSER_FORM
*Form
,
2850 IN BROWSER_SETTING_SCOPE SettingScope
2854 FORMSET_STORAGE
*Storage
;
2855 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2856 FORM_BROWSER_FORMSET
*LocalFormSet
;
2857 FORM_BROWSER_FORMSET
*OldFormSet
;
2860 // Check the supported setting level.
2862 if (SettingScope
>= MaxLevel
) {
2863 return EFI_UNSUPPORTED
;
2866 if (SettingScope
== FormLevel
&& IsNvUpdateRequiredForForm (Form
)) {
2868 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
2869 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
2870 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
2871 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
2873 if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2878 // Skip if there is no RequestElement
2880 if (ConfigInfo
->ElementCount
== 0) {
2885 // Prepare <ConfigResp>
2887 SynchronizeStorage(ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, FALSE
);
2890 // Call callback with Changed type to inform the driver.
2892 SendDiscardInfoToDriver (FormSet
, Form
);
2895 ValueChangeResetFlagUpdate (FALSE
, FormSet
, Form
);
2896 } else if (SettingScope
== FormSetLevel
&& IsNvUpdateRequiredForFormSet (FormSet
)) {
2899 // Discard Buffer storage or Name/Value storage
2901 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2902 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2903 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2904 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2906 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2911 // Skip if there is no RequestElement
2913 if (Storage
->ElementCount
== 0) {
2917 SynchronizeStorage(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
2920 Link
= GetFirstNode (&FormSet
->FormListHead
);
2921 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2922 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2923 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2926 // Call callback with Changed type to inform the driver.
2928 SendDiscardInfoToDriver (FormSet
, Form
);
2931 ValueChangeResetFlagUpdate(FALSE
, FormSet
, NULL
);
2932 } else if (SettingScope
== SystemLevel
) {
2934 // System Level Discard.
2936 OldFormSet
= mSystemLevelFormSet
;
2939 // Discard changed value for each FormSet in the maintain list.
2941 Link
= GetFirstNode (&gBrowserFormSetList
);
2942 while (!IsNull (&gBrowserFormSetList
, Link
)) {
2943 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
2944 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
2945 if (!ValidateFormSet(LocalFormSet
)) {
2949 mSystemLevelFormSet
= LocalFormSet
;
2951 DiscardForm (LocalFormSet
, NULL
, FormSetLevel
);
2952 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
2954 // Remove maintain backup list after discard except for the current using FormSet.
2956 CleanBrowserStorage(LocalFormSet
);
2957 RemoveEntryList (&LocalFormSet
->Link
);
2958 DestroyFormSet (LocalFormSet
);
2962 mSystemLevelFormSet
= OldFormSet
;
2969 Submit data for a form.
2971 @param FormSet FormSet data structure.
2972 @param Form Form data structure.
2974 @retval EFI_SUCCESS The function completed successfully.
2975 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2980 IN FORM_BROWSER_FORMSET
*FormSet
,
2981 IN FORM_BROWSER_FORM
*Form
2986 EFI_STRING ConfigResp
;
2987 EFI_STRING Progress
;
2988 BROWSER_STORAGE
*Storage
;
2989 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2991 if (!IsNvUpdateRequiredForForm (Form
)) {
2995 Status
= NoSubmitCheck (FormSet
, &Form
, NULL
);
2996 if (EFI_ERROR (Status
)) {
3000 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
3001 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
3002 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
3003 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
3005 Storage
= ConfigInfo
->Storage
;
3006 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
3011 // Skip if there is no RequestElement
3013 if (ConfigInfo
->ElementCount
== 0) {
3018 // 1. Prepare <ConfigResp>
3020 Status
= StorageToConfigResp (ConfigInfo
->Storage
, &ConfigResp
, ConfigInfo
->ConfigRequest
, TRUE
);
3021 if (EFI_ERROR (Status
)) {
3026 // 2. Set value to hii config routine protocol.
3028 Status
= mHiiConfigRouting
->RouteConfig (
3033 FreePool (ConfigResp
);
3035 if (EFI_ERROR (Status
)) {
3036 InsertTailList (&gBrowserSaveFailFormSetList
, &ConfigInfo
->SaveFailLink
);
3041 // 3. Config success, update storage shadow Buffer, only update the data belong to this form.
3043 SynchronizeStorage (ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, TRUE
);
3047 // 4. Process the save failed storage.
3049 if (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3050 if (ConfirmSaveFail (Form
->FormTitle
, FormSet
->HiiHandle
) == BROWSER_ACTION_DISCARD
) {
3051 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3052 while (!IsNull (&gBrowserSaveFailFormSetList
, Link
)) {
3053 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link
);
3054 Link
= GetNextNode (&gBrowserSaveFailFormSetList
, Link
);
3056 SynchronizeStorage(ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, FALSE
);
3058 Status
= EFI_SUCCESS
;
3061 Status
= EFI_UNSUPPORTED
;
3065 // Free Form save fail list.
3067 while (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3068 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3069 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link
);
3070 RemoveEntryList (&ConfigInfo
->SaveFailLink
);
3075 // 5. Update the NV flag.
3077 ValueChangeResetFlagUpdate(TRUE
, FormSet
, Form
);
3083 Submit data for a formset.
3085 @param FormSet FormSet data structure.
3086 @param SkipProcessFail Whether skip to process the save failed storage.
3087 If submit formset is called when do system level save,
3088 set this value to true and process the failed formset
3090 if submit formset is called when do formset level save,
3091 set the value to false and process the failed storage
3092 right after process all storages for this formset.
3094 @retval EFI_SUCCESS The function completed successfully.
3095 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3100 IN FORM_BROWSER_FORMSET
*FormSet
,
3101 IN BOOLEAN SkipProcessFail
3106 EFI_STRING ConfigResp
;
3107 EFI_STRING Progress
;
3108 BROWSER_STORAGE
*Storage
;
3109 FORMSET_STORAGE
*FormSetStorage
;
3110 FORM_BROWSER_FORM
*Form
;
3111 BOOLEAN HasInserted
;
3112 FORM_BROWSER_STATEMENT
*Question
;
3114 HasInserted
= FALSE
;
3116 if (!IsNvUpdateRequiredForFormSet (FormSet
)) {
3121 Status
= NoSubmitCheck (FormSet
, &Form
, &Question
);
3122 if (EFI_ERROR (Status
)) {
3123 if (SkipProcessFail
) {
3125 // Process NO_SUBMIT check first, so insert it at head.
3127 FormSet
->SaveFailForm
= Form
;
3128 FormSet
->SaveFailStatement
= Question
;
3129 InsertHeadList (&gBrowserSaveFailFormSetList
, &FormSet
->SaveFailLink
);
3138 // Submit Buffer storage or Name/Value storage
3140 Link
= GetFirstNode (&FormSet
->StorageListHead
);
3141 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
3142 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
3143 Storage
= FormSetStorage
->BrowserStorage
;
3144 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
3146 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
3151 // Skip if there is no RequestElement
3153 if (FormSetStorage
->ElementCount
== 0) {
3158 // 1. Prepare <ConfigResp>
3160 Status
= StorageToConfigResp (Storage
, &ConfigResp
, FormSetStorage
->ConfigRequest
, TRUE
);
3161 if (EFI_ERROR (Status
)) {
3166 // 2. Send <ConfigResp> to Routine config Protocol.
3168 Status
= mHiiConfigRouting
->RouteConfig (
3173 if (EFI_ERROR (Status
)) {
3174 InsertTailList (&FormSet
->SaveFailStorageListHead
, &FormSetStorage
->SaveFailLink
);
3177 // Call submit formset for system level, save the formset info
3178 // and process later.
3180 FindQuestionFromProgress(FormSet
, Storage
, Progress
, &Form
, &Question
);
3181 ASSERT (Form
!= NULL
&& Question
!= NULL
);
3182 FormSet
->SaveFailForm
= Form
;
3183 FormSet
->SaveFailStatement
= Question
;
3184 if (SkipProcessFail
) {
3185 InsertTailList (&gBrowserSaveFailFormSetList
, &FormSet
->SaveFailLink
);
3190 FreePool (ConfigResp
);
3194 FreePool (ConfigResp
);
3196 // 3. Config success, update storage shadow Buffer
3198 SynchronizeStorage (Storage
, FormSetStorage
->ConfigRequest
, TRUE
);
3202 // 4. Has save fail storage need to handle.
3205 if (!SkipProcessFail
) {
3207 // If not in system level, just handl the save failed storage here.
3209 if (ConfirmSaveFail (Form
->FormTitle
, FormSet
->HiiHandle
) == BROWSER_ACTION_DISCARD
) {
3210 Link
= GetFirstNode (&FormSet
->SaveFailStorageListHead
);
3211 while (!IsNull (&FormSet
->SaveFailStorageListHead
, Link
)) {
3212 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link
);
3213 Storage
= FormSetStorage
->BrowserStorage
;
3214 Link
= GetNextNode (&FormSet
->SaveFailStorageListHead
, Link
);
3216 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3218 Status
= EFI_SUCCESS
;
3221 UiCopyMenuList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &Form
->FormViewListHead
);
3223 gCurrentSelection
->Action
= UI_ACTION_REFRESH_FORMSET
;
3224 gCurrentSelection
->Handle
= FormSet
->HiiHandle
;
3225 CopyGuid (&gCurrentSelection
->FormSetGuid
, &FormSet
->Guid
);
3226 gCurrentSelection
->FormId
= Form
->FormId
;
3227 gCurrentSelection
->QuestionId
= Question
->QuestionId
;
3229 Status
= EFI_UNSUPPORTED
;
3233 // Free FormSet save fail list.
3235 while (!IsListEmpty (&FormSet
->SaveFailStorageListHead
)) {
3236 Link
= GetFirstNode (&FormSet
->SaveFailStorageListHead
);
3237 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link
);
3238 RemoveEntryList (&FormSetStorage
->SaveFailLink
);
3242 // If in system level, just return error and handle the failed formset later.
3244 Status
= EFI_UNSUPPORTED
;
3249 // 5. Update the NV flag.
3251 ValueChangeResetFlagUpdate(TRUE
, FormSet
, NULL
);
3257 Submit data for all formsets.
3259 @retval EFI_SUCCESS The function completed successfully.
3260 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3270 LIST_ENTRY
*StorageLink
;
3271 FORMSET_STORAGE
*FormSetStorage
;
3272 FORM_BROWSER_FORM
*Form
;
3273 FORM_BROWSER_FORMSET
*LocalFormSet
;
3274 UINT32 UserSelection
;
3275 FORM_BROWSER_STATEMENT
*Question
;
3277 mSystemSubmit
= TRUE
;
3278 Link
= GetFirstNode (&gBrowserFormSetList
);
3279 while (!IsNull (&gBrowserFormSetList
, Link
)) {
3280 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
3281 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
3282 if (!ValidateFormSet(LocalFormSet
)) {
3286 Status
= SubmitForFormSet (LocalFormSet
, TRUE
);
3287 if (EFI_ERROR (Status
)) {
3292 // Remove maintain backup list after save except for the current using FormSet.
3294 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
3295 CleanBrowserStorage(LocalFormSet
);
3296 RemoveEntryList (&LocalFormSet
->Link
);
3297 DestroyFormSet (LocalFormSet
);
3300 mSystemSubmit
= FALSE
;
3302 Status
= EFI_SUCCESS
;
3305 // Process the save failed formsets.
3307 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3308 while (!IsNull (&gBrowserSaveFailFormSetList
, Link
)) {
3309 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link
);
3310 Link
= GetNextNode (&gBrowserSaveFailFormSetList
, Link
);
3312 if (!ValidateFormSet(LocalFormSet
)) {
3316 Form
= LocalFormSet
->SaveFailForm
;
3317 Question
= LocalFormSet
->SaveFailStatement
;
3320 // Confirm with user, get user input.
3322 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3324 // NULL for SaveFailStorageListHead means error caused by NO_SUBMIT_IF check.
3326 UserSelection
= ConfirmNoSubmitFail (Form
->FormTitle
, LocalFormSet
->HiiHandle
);
3328 UserSelection
= ConfirmSaveFail (Form
->FormTitle
, LocalFormSet
->HiiHandle
);
3331 if (UserSelection
== BROWSER_ACTION_DISCARD
) {
3332 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3333 StorageLink
= GetFirstNode (&LocalFormSet
->StorageListHead
);
3334 while (!IsNull (&LocalFormSet
->StorageListHead
, StorageLink
)) {
3335 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (StorageLink
);
3336 StorageLink
= GetNextNode (&LocalFormSet
->StorageListHead
, StorageLink
);
3338 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3341 StorageLink
= GetFirstNode (&LocalFormSet
->SaveFailStorageListHead
);
3342 while (!IsNull (&LocalFormSet
->SaveFailStorageListHead
, StorageLink
)) {
3343 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink
);
3344 StorageLink
= GetNextNode (&LocalFormSet
->SaveFailStorageListHead
, StorageLink
);
3346 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3350 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
3351 CleanBrowserStorage(LocalFormSet
);
3352 RemoveEntryList (&LocalFormSet
->Link
);
3353 RemoveEntryList (&LocalFormSet
->SaveFailLink
);
3354 DestroyFormSet (LocalFormSet
);
3356 ValueChangeResetFlagUpdate(FALSE
, LocalFormSet
, NULL
);
3359 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3360 NoSubmitCheck (LocalFormSet
, &Form
, &Question
);
3363 UiCopyMenuList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &Form
->FormViewListHead
);
3365 gCurrentSelection
->Action
= UI_ACTION_REFRESH_FORMSET
;
3366 gCurrentSelection
->Handle
= LocalFormSet
->HiiHandle
;
3367 CopyGuid (&gCurrentSelection
->FormSetGuid
, &LocalFormSet
->Guid
);
3368 gCurrentSelection
->FormId
= Form
->FormId
;
3369 gCurrentSelection
->QuestionId
= Question
->QuestionId
;
3371 Status
= EFI_UNSUPPORTED
;
3377 // Clean the list which will not process.
3379 while (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3380 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3381 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link
);
3382 RemoveEntryList (&LocalFormSet
->SaveFailLink
);
3384 while (!IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3385 StorageLink
= GetFirstNode (&LocalFormSet
->SaveFailStorageListHead
);
3386 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink
);
3387 RemoveEntryList (&FormSetStorage
->SaveFailLink
);
3395 Submit data based on the input Setting level (Form, FormSet or System).
3397 @param FormSet FormSet data structure.
3398 @param Form Form data structure.
3399 @param SettingScope Setting Scope for Submit action.
3401 @retval EFI_SUCCESS The function completed successfully.
3402 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3407 IN FORM_BROWSER_FORMSET
*FormSet
,
3408 IN FORM_BROWSER_FORM
*Form
,
3409 IN BROWSER_SETTING_SCOPE SettingScope
3414 switch (SettingScope
) {
3416 Status
= SubmitForForm(FormSet
, Form
);
3420 Status
= SubmitForFormSet (FormSet
, FALSE
);
3424 Status
= SubmitForSystem ();
3428 Status
= EFI_UNSUPPORTED
;
3436 Converts the unicode character of the string from uppercase to lowercase.
3437 This is a internal function.
3439 @param ConfigString String to be converted
3445 IN EFI_STRING ConfigString
3451 ASSERT (ConfigString
!= NULL
);
3454 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
3456 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
3457 if (*String
== L
'=') {
3459 } else if (*String
== L
'&') {
3461 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
3462 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
3468 Find the point in the ConfigResp string for this question.
3470 @param Question The question.
3471 @param ConfigResp Get ConfigResp string.
3473 @retval point to the offset where is for this question.
3477 GetOffsetFromConfigResp (
3478 IN FORM_BROWSER_STATEMENT
*Question
,
3479 IN CHAR16
*ConfigResp
3482 CHAR16
*RequestElement
;
3486 // Type is EFI_HII_VARSTORE_NAME_VALUE.
3488 if (Question
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3489 RequestElement
= StrStr (ConfigResp
, Question
->VariableName
);
3490 if (RequestElement
!= NULL
) {
3492 // Skip the "VariableName=" field.
3494 RequestElement
+= StrLen (Question
->VariableName
) + 1;
3497 return RequestElement
;
3501 // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
3505 // 1. Directly use Question->BlockName to find.
3507 RequestElement
= StrStr (ConfigResp
, Question
->BlockName
);
3508 if (RequestElement
!= NULL
) {
3510 // Skip the "Question->BlockName&VALUE=" field.
3512 RequestElement
+= StrLen (Question
->BlockName
) + StrLen (L
"&VALUE=");
3513 return RequestElement
;
3517 // 2. Change all hex digits in Question->BlockName to lower and compare again.
3519 BlockData
= AllocateCopyPool (StrSize(Question
->BlockName
), Question
->BlockName
);
3520 ASSERT (BlockData
!= NULL
);
3521 HiiToLower (BlockData
);
3522 RequestElement
= StrStr (ConfigResp
, BlockData
);
3523 FreePool (BlockData
);
3525 if (RequestElement
!= NULL
) {
3527 // Skip the "Question->BlockName&VALUE=" field.
3529 RequestElement
+= StrLen (Question
->BlockName
) + StrLen (L
"&VALUE=");
3532 return RequestElement
;
3536 Get Question default value from AltCfg string.
3538 @param FormSet The form set.
3539 @param Form The form
3540 @param Question The question.
3542 @retval EFI_SUCCESS Question is reset to default value.
3546 GetDefaultValueFromAltCfg (
3547 IN FORM_BROWSER_FORMSET
*FormSet
,
3548 IN FORM_BROWSER_FORM
*Form
,
3549 IN OUT FORM_BROWSER_STATEMENT
*Question
3552 BROWSER_STORAGE
*Storage
;
3553 FORMSET_STORAGE
*FormSetStorage
;
3557 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
3559 Storage
= Question
->Storage
;
3560 if ((Storage
== NULL
) || (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
3561 return EFI_NOT_FOUND
;
3565 // Try to get AltCfg string from form. If not found it, then
3566 // try to get it from formset.
3569 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
3570 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
3571 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
3572 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
3574 if (Storage
== ConfigInfo
->Storage
) {
3575 ConfigResp
= ConfigInfo
->ConfigAltResp
;
3580 if (ConfigResp
== NULL
) {
3581 Link
= GetFirstNode (&FormSet
->StorageListHead
);
3582 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
3583 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
3584 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
3586 if (Storage
== FormSetStorage
->BrowserStorage
) {
3587 ConfigResp
= FormSetStorage
->ConfigAltResp
;
3593 if (ConfigResp
== NULL
) {
3594 return EFI_NOT_FOUND
;
3597 Value
= GetOffsetFromConfigResp (Question
, ConfigResp
);
3598 if (Value
== NULL
) {
3599 return EFI_NOT_FOUND
;
3602 return BufferToValue (Question
, Value
);
3606 Get default Id value used for browser.
3608 @param DefaultId The default id value used by hii.
3610 @retval Browser used default value.
3614 GetDefaultIdForCallBack (
3618 if (DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) {
3619 return EFI_BROWSER_ACTION_DEFAULT_STANDARD
;
3620 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3621 return EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
;
3622 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_SAFE
) {
3623 return EFI_BROWSER_ACTION_DEFAULT_SAFE
;
3624 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
+ 0x1000) {
3625 return EFI_BROWSER_ACTION_DEFAULT_PLATFORM
+ DefaultId
- EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
;
3626 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
+ 0x1000) {
3627 return EFI_BROWSER_ACTION_DEFAULT_HARDWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
;
3628 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
+ 0x1000) {
3629 return EFI_BROWSER_ACTION_DEFAULT_FIRMWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
;
3638 Return data element in an Array by its Index.
3640 @param Array The data array.
3641 @param Type Type of the data in this array.
3642 @param Index Zero based index for data in this array.
3644 @retval Value The data to be returned
3656 ASSERT (Array
!= NULL
);
3660 case EFI_IFR_TYPE_NUM_SIZE_8
:
3661 Data
= (UINT64
) *(((UINT8
*) Array
) + Index
);
3664 case EFI_IFR_TYPE_NUM_SIZE_16
:
3665 Data
= (UINT64
) *(((UINT16
*) Array
) + Index
);
3668 case EFI_IFR_TYPE_NUM_SIZE_32
:
3669 Data
= (UINT64
) *(((UINT32
*) Array
) + Index
);
3672 case EFI_IFR_TYPE_NUM_SIZE_64
:
3673 Data
= (UINT64
) *(((UINT64
*) Array
) + Index
);
3685 Set value of a data element in an Array by its Index.
3687 @param Array The data array.
3688 @param Type Type of the data in this array.
3689 @param Index Zero based index for data in this array.
3690 @param Value The value to be set.
3702 ASSERT (Array
!= NULL
);
3705 case EFI_IFR_TYPE_NUM_SIZE_8
:
3706 *(((UINT8
*) Array
) + Index
) = (UINT8
) Value
;
3709 case EFI_IFR_TYPE_NUM_SIZE_16
:
3710 *(((UINT16
*) Array
) + Index
) = (UINT16
) Value
;
3713 case EFI_IFR_TYPE_NUM_SIZE_32
:
3714 *(((UINT32
*) Array
) + Index
) = (UINT32
) Value
;
3717 case EFI_IFR_TYPE_NUM_SIZE_64
:
3718 *(((UINT64
*) Array
) + Index
) = (UINT64
) Value
;
3727 Search an Option of a Question by its value.
3729 @param Question The Question
3730 @param OptionValue Value for Option to be searched.
3732 @retval Pointer Pointer to the found Option.
3733 @retval NULL Option not found.
3738 IN FORM_BROWSER_STATEMENT
*Question
,
3739 IN EFI_HII_VALUE
*OptionValue
3743 QUESTION_OPTION
*Option
;
3746 Link
= GetFirstNode (&Question
->OptionListHead
);
3747 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3748 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3750 if ((CompareHiiValue (&Option
->Value
, OptionValue
, &Result
, NULL
) == EFI_SUCCESS
) && (Result
== 0)) {
3752 // Check the suppressif condition, only a valid option can be return.
3754 if ((Option
->SuppressExpression
== NULL
) ||
3755 ((EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) == ExpressFalse
))) {
3760 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3768 Reset Question to its default value.
3770 @param FormSet The form set.
3771 @param Form The form.
3772 @param Question The question.
3773 @param DefaultId The Class of the default.
3775 @retval EFI_SUCCESS Question is reset to default value.
3779 GetQuestionDefault (
3780 IN FORM_BROWSER_FORMSET
*FormSet
,
3781 IN FORM_BROWSER_FORM
*Form
,
3782 IN FORM_BROWSER_STATEMENT
*Question
,
3788 QUESTION_DEFAULT
*Default
;
3789 QUESTION_OPTION
*Option
;
3790 EFI_HII_VALUE
*HiiValue
;
3792 EFI_STRING StrValue
;
3793 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
3794 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
3798 Status
= EFI_NOT_FOUND
;
3802 // Statement don't have storage, skip them
3804 if (Question
->QuestionId
== 0) {
3809 // There are Five ways to specify default value for a Question:
3810 // 1, use call back function (highest priority)
3811 // 2, use ExtractConfig function
3812 // 3, use nested EFI_IFR_DEFAULT
3813 // 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
3814 // 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
3816 HiiValue
= &Question
->HiiValue
;
3819 // Get Question defaut value from call back function.
3821 ConfigAccess
= FormSet
->ConfigAccess
;
3822 Action
= GetDefaultIdForCallBack (DefaultId
);
3823 if ((Action
> 0) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
3824 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
3825 Status
= ConfigAccess
->Callback (
3828 Question
->QuestionId
,
3833 if (!EFI_ERROR (Status
)) {
3834 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
3835 NewString
= GetToken (Question
->HiiValue
.Value
.string
, FormSet
->HiiHandle
);
3836 ASSERT (NewString
!= NULL
);
3838 ASSERT (StrLen (NewString
) * sizeof (CHAR16
) <= Question
->StorageWidth
);
3839 if (StrLen (NewString
) * sizeof (CHAR16
) <= Question
->StorageWidth
) {
3840 CopyMem (Question
->BufferValue
, NewString
, StrSize (NewString
));
3842 CopyMem (Question
->BufferValue
, NewString
, Question
->StorageWidth
);
3845 FreePool (NewString
);
3852 // Get default value from altcfg string.
3854 if (ConfigAccess
!= NULL
) {
3855 Status
= GetDefaultValueFromAltCfg(FormSet
, Form
, Question
);
3856 if (!EFI_ERROR (Status
)) {
3862 // EFI_IFR_DEFAULT has highest priority
3864 if (!IsListEmpty (&Question
->DefaultListHead
)) {
3865 Link
= GetFirstNode (&Question
->DefaultListHead
);
3866 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
3867 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
3869 if (Default
->DefaultId
== DefaultId
) {
3870 if (Default
->ValueExpression
!= NULL
) {
3872 // Default is provided by an Expression, evaluate it
3874 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
3875 if (EFI_ERROR (Status
)) {
3879 if (Default
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
3880 ASSERT (HiiValue
->Type
== EFI_IFR_TYPE_BUFFER
&& Question
->BufferValue
!= NULL
);
3881 if (Question
->StorageWidth
> Default
->ValueExpression
->Result
.BufferLen
) {
3882 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Default
->ValueExpression
->Result
.BufferLen
);
3883 Question
->HiiValue
.BufferLen
= Default
->ValueExpression
->Result
.BufferLen
;
3885 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
3886 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
3888 FreePool (Default
->ValueExpression
->Result
.Buffer
);
3890 HiiValue
->Type
= Default
->ValueExpression
->Result
.Type
;
3891 CopyMem (&HiiValue
->Value
, &Default
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
3894 // Default value is embedded in EFI_IFR_DEFAULT
3896 if (Default
->Value
.Type
== EFI_IFR_TYPE_BUFFER
) {
3897 ASSERT (HiiValue
->Buffer
!= NULL
);
3898 CopyMem (HiiValue
->Buffer
, Default
->Value
.Buffer
, Default
->Value
.BufferLen
);
3900 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
3904 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
3905 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
3906 if (StrValue
== NULL
) {
3907 return EFI_NOT_FOUND
;
3909 if (Question
->StorageWidth
> StrSize (StrValue
)) {
3910 CopyMem (Question
->BufferValue
, StrValue
, StrSize (StrValue
));
3912 CopyMem (Question
->BufferValue
, StrValue
, Question
->StorageWidth
);
3919 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
3924 // EFI_ONE_OF_OPTION
3926 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
3927 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3929 // OneOfOption could only provide Standard and Manufacturing default
3931 Link
= GetFirstNode (&Question
->OptionListHead
);
3932 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3933 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3934 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3936 if ((Option
->SuppressExpression
!= NULL
) &&
3937 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3941 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
3942 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
3944 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
3953 // EFI_IFR_CHECKBOX - lowest priority
3955 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
3956 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3958 // Checkbox could only provide Standard and Manufacturing default
3960 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
3961 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
3963 HiiValue
->Value
.b
= TRUE
;
3965 HiiValue
->Value
.b
= FALSE
;
3973 // For Questions without default
3975 Status
= EFI_NOT_FOUND
;
3976 switch (Question
->Operand
) {
3977 case EFI_IFR_NUMERIC_OP
:
3979 // Take minimum value as numeric default value
3981 if ((Question
->Flags
& EFI_IFR_DISPLAY
) == 0) {
3983 // In EFI_IFR_DISPLAY_INT_DEC type, should check value with int* type.
3985 switch (Question
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
3986 case EFI_IFR_NUMERIC_SIZE_1
:
3987 if (((INT8
) HiiValue
->Value
.u8
< (INT8
) Question
->Minimum
) || ((INT8
) HiiValue
->Value
.u8
> (INT8
) Question
->Maximum
)) {
3988 HiiValue
->Value
.u8
= (UINT8
) Question
->Minimum
;
3989 Status
= EFI_SUCCESS
;
3992 case EFI_IFR_NUMERIC_SIZE_2
:
3993 if (((INT16
) HiiValue
->Value
.u16
< (INT16
) Question
->Minimum
) || ((INT16
) HiiValue
->Value
.u16
> (INT16
) Question
->Maximum
)) {
3994 HiiValue
->Value
.u16
= (UINT16
) Question
->Minimum
;
3995 Status
= EFI_SUCCESS
;
3998 case EFI_IFR_NUMERIC_SIZE_4
:
3999 if (((INT32
) HiiValue
->Value
.u32
< (INT32
) Question
->Minimum
) || ((INT32
) HiiValue
->Value
.u32
> (INT32
) Question
->Maximum
)) {
4000 HiiValue
->Value
.u32
= (UINT32
) Question
->Minimum
;
4001 Status
= EFI_SUCCESS
;
4004 case EFI_IFR_NUMERIC_SIZE_8
:
4005 if (((INT64
) HiiValue
->Value
.u64
< (INT64
) Question
->Minimum
) || ((INT64
) HiiValue
->Value
.u64
> (INT64
) Question
->Maximum
)) {
4006 HiiValue
->Value
.u64
= Question
->Minimum
;
4007 Status
= EFI_SUCCESS
;
4014 if ((HiiValue
->Value
.u64
< Question
->Minimum
) || (HiiValue
->Value
.u64
> Question
->Maximum
)) {
4015 HiiValue
->Value
.u64
= Question
->Minimum
;
4016 Status
= EFI_SUCCESS
;
4021 case EFI_IFR_ONE_OF_OP
:
4023 // Take first oneof option as oneof's default value
4025 if (ValueToOption (Question
, HiiValue
) == NULL
) {
4026 Link
= GetFirstNode (&Question
->OptionListHead
);
4027 while (!IsNull (&Question
->OptionListHead
, Link
)) {
4028 Option
= QUESTION_OPTION_FROM_LINK (Link
);
4029 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
4031 if ((Option
->SuppressExpression
!= NULL
) &&
4032 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
4036 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
4037 Status
= EFI_SUCCESS
;
4043 case EFI_IFR_ORDERED_LIST_OP
:
4045 // Take option sequence in IFR as ordered list's default value
4048 Link
= GetFirstNode (&Question
->OptionListHead
);
4049 while (!IsNull (&Question
->OptionListHead
, Link
)) {
4050 Status
= EFI_SUCCESS
;
4051 Option
= QUESTION_OPTION_FROM_LINK (Link
);
4052 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
4054 if ((Option
->SuppressExpression
!= NULL
) &&
4055 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
4059 SetArrayData (Question
->BufferValue
, Question
->ValueType
, Index
, Option
->Value
.Value
.u64
);
4062 if (Index
>= Question
->MaxContainers
) {
4076 Get AltCfg string for current form.
4078 @param FormSet Form data structure.
4079 @param Form Form data structure.
4080 @param DefaultId The Class of the default.
4081 @param BrowserStorage The input request storage for the questions.
4085 ExtractAltCfgForForm (
4086 IN FORM_BROWSER_FORMSET
*FormSet
,
4087 IN FORM_BROWSER_FORM
*Form
,
4088 IN UINT16 DefaultId
,
4089 IN BROWSER_STORAGE
*BrowserStorage
4097 BROWSER_STORAGE
*Storage
;
4098 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
4099 FORMSET_STORAGE
*FormSetStorage
;
4102 // Check whether has get AltCfg string for this formset.
4103 // If yes, no need to get AltCfg for form.
4105 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4106 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4107 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4108 Storage
= FormSetStorage
->BrowserStorage
;
4109 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4110 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4114 if (Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
&&
4115 FormSetStorage
->ElementCount
!= 0 &&
4116 FormSetStorage
->HasCallAltCfg
) {
4122 // Get AltCfg string for each form.
4124 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
4125 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
4126 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
4127 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
4129 Storage
= ConfigInfo
->Storage
;
4130 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4134 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
4139 // 1. Skip if there is no RequestElement
4141 if (ConfigInfo
->ElementCount
== 0) {
4146 // 2. Get value through hii config routine protocol.
4148 Status
= mHiiConfigRouting
->ExtractConfig (
4150 ConfigInfo
->ConfigRequest
,
4154 if (EFI_ERROR (Status
)) {
4159 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
4160 // Get the default configuration string according to the default ID.
4162 Status
= mHiiConfigRouting
->GetAltConfig (
4168 &DefaultId
, // it can be NULL to get the current setting.
4172 if (EFI_ERROR (Status
)) {
4176 ConfigInfo
->ConfigAltResp
= ConfigResp
;
4181 Clean AltCfg string for current form.
4183 @param Form Form data structure.
4187 CleanAltCfgForForm (
4188 IN FORM_BROWSER_FORM
*Form
4192 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
4194 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
4195 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
4196 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
4197 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
4199 if (ConfigInfo
->ConfigAltResp
!= NULL
) {
4200 FreePool (ConfigInfo
->ConfigAltResp
);
4201 ConfigInfo
->ConfigAltResp
= NULL
;
4207 Get AltCfg string for current formset.
4209 @param FormSet Form data structure.
4210 @param DefaultId The Class of the default.
4211 @param BrowserStorage The input request storage for the questions.
4215 ExtractAltCfgForFormSet (
4216 IN FORM_BROWSER_FORMSET
*FormSet
,
4217 IN UINT16 DefaultId
,
4218 IN BROWSER_STORAGE
*BrowserStorage
4226 BROWSER_STORAGE
*Storage
;
4227 FORMSET_STORAGE
*FormSetStorage
;
4229 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4230 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4231 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4232 Storage
= FormSetStorage
->BrowserStorage
;
4233 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4235 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4239 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
4244 // 1. Skip if there is no RequestElement
4246 if (FormSetStorage
->ElementCount
== 0) {
4250 FormSetStorage
->HasCallAltCfg
= TRUE
;
4253 // 2. Get value through hii config routine protocol.
4255 Status
= mHiiConfigRouting
->ExtractConfig (
4257 FormSetStorage
->ConfigRequest
,
4261 if (EFI_ERROR (Status
)) {
4266 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
4267 // Get the default configuration string according to the default ID.
4269 Status
= mHiiConfigRouting
->GetAltConfig (
4275 &DefaultId
, // it can be NULL to get the current setting.
4280 if (EFI_ERROR (Status
)) {
4284 FormSetStorage
->ConfigAltResp
= ConfigResp
;
4290 Clean AltCfg string for current formset.
4292 @param FormSet Form data structure.
4296 CleanAltCfgForFormSet (
4297 IN FORM_BROWSER_FORMSET
*FormSet
4301 FORMSET_STORAGE
*FormSetStorage
;
4303 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4304 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4305 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4306 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4308 if (FormSetStorage
->ConfigAltResp
!= NULL
) {
4309 FreePool (FormSetStorage
->ConfigAltResp
);
4310 FormSetStorage
->ConfigAltResp
= NULL
;
4313 FormSetStorage
->HasCallAltCfg
= FALSE
;
4318 Reset Questions to their initial value or default value in a Form, Formset or System.
4320 GetDefaultValueScope parameter decides which questions will reset
4321 to its default value.
4323 @param FormSet FormSet data structure.
4324 @param Form Form data structure.
4325 @param DefaultId The Class of the default.
4326 @param SettingScope Setting Scope for Default action.
4327 @param GetDefaultValueScope Get default value scope.
4328 @param Storage Get default value only for this storage.
4329 @param RetrieveValueFirst Whether call the retrieve call back to
4330 get the initial value before get default
4332 @param SkipGetAltCfg Whether skip the get altcfg string process.
4334 @retval EFI_SUCCESS The function completed successfully.
4335 @retval EFI_UNSUPPORTED Unsupport SettingScope.
4340 IN FORM_BROWSER_FORMSET
*FormSet
,
4341 IN FORM_BROWSER_FORM
*Form
,
4342 IN UINT16 DefaultId
,
4343 IN BROWSER_SETTING_SCOPE SettingScope
,
4344 IN BROWSER_GET_DEFAULT_VALUE GetDefaultValueScope
,
4345 IN BROWSER_STORAGE
*Storage OPTIONAL
,
4346 IN BOOLEAN RetrieveValueFirst
,
4347 IN BOOLEAN SkipGetAltCfg
4351 LIST_ENTRY
*FormLink
;
4353 FORM_BROWSER_STATEMENT
*Question
;
4354 FORM_BROWSER_FORMSET
*LocalFormSet
;
4355 FORM_BROWSER_FORMSET
*OldFormSet
;
4357 Status
= EFI_SUCCESS
;
4360 // Check the supported setting level.
4362 if (SettingScope
>= MaxLevel
|| GetDefaultValueScope
>= GetDefaultForMax
) {
4363 return EFI_UNSUPPORTED
;
4366 if (GetDefaultValueScope
== GetDefaultForStorage
&& Storage
== NULL
) {
4367 return EFI_UNSUPPORTED
;
4370 if (SettingScope
== FormLevel
) {
4372 // Prepare the AltCfg String for form.
4374 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4375 ExtractAltCfgForForm (FormSet
, Form
, DefaultId
, Storage
);
4379 // Extract Form default
4381 Link
= GetFirstNode (&Form
->StatementListHead
);
4382 while (!IsNull (&Form
->StatementListHead
, Link
)) {
4383 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
4384 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
4387 // If get default value only for this storage, check the storage first.
4389 if ((GetDefaultValueScope
== GetDefaultForStorage
) && (Question
->Storage
!= Storage
)) {
4394 // If get default value only for no storage question, just skip the question which has storage.
4396 if ((GetDefaultValueScope
== GetDefaultForNoStorage
) && (Question
->Storage
!= NULL
)) {
4401 // If Question is disabled, don't reset it to default
4403 if (Question
->Expression
!= NULL
) {
4404 if (EvaluateExpressionList(Question
->Expression
, TRUE
, FormSet
, Form
) == ExpressDisable
) {
4409 if (RetrieveValueFirst
) {
4411 // Call the Retrieve call back to get the initial question value.
4413 Status
= ProcessRetrieveForQuestion(FormSet
->ConfigAccess
, Question
, FormSet
);
4417 // If not request to get the initial value or get initial value fail, then get default value.
4419 if (!RetrieveValueFirst
|| EFI_ERROR (Status
)) {
4420 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
4421 if (EFI_ERROR (Status
)) {
4427 // Synchronize Buffer storage's Edit buffer
4429 if ((Question
->Storage
!= NULL
) &&
4430 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
4431 SetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4436 // Clean the AltCfg String.
4438 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4439 CleanAltCfgForForm(Form
);
4441 } else if (SettingScope
== FormSetLevel
) {
4443 // Prepare the AltCfg String for formset.
4445 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4446 ExtractAltCfgForFormSet (FormSet
, DefaultId
, Storage
);
4449 FormLink
= GetFirstNode (&FormSet
->FormListHead
);
4450 while (!IsNull (&FormSet
->FormListHead
, FormLink
)) {
4451 Form
= FORM_BROWSER_FORM_FROM_LINK (FormLink
);
4452 ExtractDefault (FormSet
, Form
, DefaultId
, FormLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
, SkipGetAltCfg
);
4453 FormLink
= GetNextNode (&FormSet
->FormListHead
, FormLink
);
4457 // Clean the AltCfg String.
4459 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4460 CleanAltCfgForFormSet (FormSet
);
4462 } else if (SettingScope
== SystemLevel
) {
4464 // Preload all Hii formset.
4466 LoadAllHiiFormset();
4468 OldFormSet
= mSystemLevelFormSet
;
4471 // Set Default Value for each FormSet in the maintain list.
4473 Link
= GetFirstNode (&gBrowserFormSetList
);
4474 while (!IsNull (&gBrowserFormSetList
, Link
)) {
4475 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
4476 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
4477 if (!ValidateFormSet(LocalFormSet
)) {
4481 mSystemLevelFormSet
= LocalFormSet
;
4483 ExtractDefault (LocalFormSet
, NULL
, DefaultId
, FormSetLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
, SkipGetAltCfg
);
4486 mSystemLevelFormSet
= OldFormSet
;
4494 Validate whether this question's value has changed.
4496 @param FormSet FormSet data structure.
4497 @param Form Form data structure.
4498 @param Question Question to be initialized.
4499 @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver.
4501 @retval TRUE Question's value has changed.
4502 @retval FALSE Question's value has not changed
4506 IsQuestionValueChanged (
4507 IN FORM_BROWSER_FORMSET
*FormSet
,
4508 IN FORM_BROWSER_FORM
*Form
,
4509 IN OUT FORM_BROWSER_STATEMENT
*Question
,
4510 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
4513 EFI_HII_VALUE BackUpValue
;
4514 CHAR8
*BackUpBuffer
;
4515 EFI_HII_VALUE BackUpValue2
;
4516 CHAR8
*BackUpBuffer2
;
4518 BOOLEAN ValueChanged
;
4522 // For quetion without storage, always mark it as data not changed.
4524 if (Question
->Storage
== NULL
&& Question
->Operand
!= EFI_IFR_TIME_OP
&& Question
->Operand
!= EFI_IFR_DATE_OP
) {
4528 BackUpBuffer
= NULL
;
4529 BackUpBuffer2
= NULL
;
4530 ValueChanged
= FALSE
;
4532 switch (Question
->Operand
) {
4533 case EFI_IFR_ORDERED_LIST_OP
:
4534 BufferWidth
= Question
->StorageWidth
;
4535 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4536 ASSERT (BackUpBuffer
!= NULL
);
4539 case EFI_IFR_STRING_OP
:
4540 case EFI_IFR_PASSWORD_OP
:
4541 BufferWidth
= (UINTN
) Question
->Maximum
* sizeof (CHAR16
);
4542 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4543 ASSERT (BackUpBuffer
!= NULL
);
4550 CopyMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
));
4552 if (GetValueFrom
== GetSetValueWithBothBuffer
) {
4553 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4554 ASSERT_EFI_ERROR(Status
);
4556 switch (Question
->Operand
) {
4557 case EFI_IFR_ORDERED_LIST_OP
:
4558 BufferWidth
= Question
->StorageWidth
;
4559 BackUpBuffer2
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4560 ASSERT (BackUpBuffer2
!= NULL
);
4563 case EFI_IFR_STRING_OP
:
4564 case EFI_IFR_PASSWORD_OP
:
4565 BufferWidth
= (UINTN
) Question
->Maximum
* sizeof (CHAR16
);
4566 BackUpBuffer2
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4567 ASSERT (BackUpBuffer2
!= NULL
);
4574 CopyMem (&BackUpValue2
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
));
4576 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithBuffer
);
4577 ASSERT_EFI_ERROR(Status
);
4579 if (CompareMem (&BackUpValue2
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
)) != 0 ||
4580 CompareMem (BackUpBuffer2
, Question
->BufferValue
, BufferWidth
) != 0) {
4581 ValueChanged
= TRUE
;
4584 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetValueFrom
);
4585 ASSERT_EFI_ERROR(Status
);
4587 if (CompareMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
)) != 0 ||
4588 CompareMem (BackUpBuffer
, Question
->BufferValue
, BufferWidth
) != 0) {
4589 ValueChanged
= TRUE
;
4593 CopyMem (&Question
->HiiValue
, &BackUpValue
, sizeof (EFI_HII_VALUE
));
4594 if (BackUpBuffer
!= NULL
) {
4595 CopyMem (Question
->BufferValue
, BackUpBuffer
, BufferWidth
);
4596 FreePool (BackUpBuffer
);
4599 if (BackUpBuffer2
!= NULL
) {
4600 FreePool (BackUpBuffer2
);
4603 Question
->ValueChanged
= ValueChanged
;
4605 return ValueChanged
;
4609 Initialize Question's Edit copy from Storage.
4611 @param Selection Selection contains the information about
4612 the Selection, form and formset to be displayed.
4613 Selection action may be updated in retrieve callback.
4614 If Selection is NULL, only initialize Question value.
4615 @param FormSet FormSet data structure.
4616 @param Form Form data structure.
4618 @retval EFI_SUCCESS The function completed successfully.
4623 IN OUT UI_MENU_SELECTION
*Selection
,
4624 IN FORM_BROWSER_FORMSET
*FormSet
,
4625 IN FORM_BROWSER_FORM
*Form
4630 FORM_BROWSER_STATEMENT
*Question
;
4632 Link
= GetFirstNode (&Form
->StatementListHead
);
4633 while (!IsNull (&Form
->StatementListHead
, Link
)) {
4634 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
4637 // Initialize local copy of Value for each Question
4639 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
&& (Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
)== 0) {
4640 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithHiiDriver
);
4642 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4644 if (EFI_ERROR (Status
)) {
4648 if ((Question
->Operand
== EFI_IFR_STRING_OP
) || (Question
->Operand
== EFI_IFR_PASSWORD_OP
)) {
4649 HiiSetString (FormSet
->HiiHandle
, Question
->HiiValue
.Value
.string
, (CHAR16
*)Question
->BufferValue
, NULL
);
4652 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
4659 Initialize Question's Edit copy from Storage for the whole Formset.
4661 @param Selection Selection contains the information about
4662 the Selection, form and formset to be displayed.
4663 Selection action may be updated in retrieve callback.
4664 If Selection is NULL, only initialize Question value.
4665 @param FormSet FormSet data structure.
4667 @retval EFI_SUCCESS The function completed successfully.
4672 IN OUT UI_MENU_SELECTION
*Selection
,
4673 IN FORM_BROWSER_FORMSET
*FormSet
4678 FORM_BROWSER_FORM
*Form
;
4680 Link
= GetFirstNode (&FormSet
->FormListHead
);
4681 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
4682 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
4685 // Initialize local copy of Value for each Form
4687 Status
= LoadFormConfig (Selection
, FormSet
, Form
);
4688 if (EFI_ERROR (Status
)) {
4692 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
4696 // Finished question initialization.
4698 FormSet
->QuestionInited
= TRUE
;
4704 Remove the Request element from the Config Request.
4706 @param Storage Pointer to the browser storage.
4707 @param RequestElement The pointer to the Request element.
4712 IN OUT BROWSER_STORAGE
*Storage
,
4713 IN CHAR16
*RequestElement
4719 ASSERT (Storage
->ConfigRequest
!= NULL
&& RequestElement
!= NULL
);
4721 NewStr
= StrStr (Storage
->ConfigRequest
, RequestElement
);
4723 if (NewStr
== NULL
) {
4728 // Remove this element from this ConfigRequest.
4731 NewStr
+= StrLen (RequestElement
);
4732 CopyMem (DestStr
, NewStr
, StrSize (NewStr
));
4734 Storage
->SpareStrLen
+= StrLen (RequestElement
);
4738 Adjust config request in storage, remove the request elements existed in the input ConfigRequest.
4740 @param Storage Pointer to the formset storage.
4741 @param ConfigRequest The pointer to the Request element.
4745 RemoveConfigRequest (
4746 FORMSET_STORAGE
*Storage
,
4747 CHAR16
*ConfigRequest
4750 CHAR16
*RequestElement
;
4751 CHAR16
*NextRequestElement
;
4755 // No request element in it, just return.
4757 if (ConfigRequest
== NULL
) {
4761 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4763 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
4768 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
4770 SearchKey
= L
"&OFFSET";
4774 // Find SearchKey storage
4776 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4777 RequestElement
= StrStr (ConfigRequest
, L
"PATH");
4778 ASSERT (RequestElement
!= NULL
);
4779 RequestElement
= StrStr (RequestElement
, SearchKey
);
4781 RequestElement
= StrStr (ConfigRequest
, SearchKey
);
4784 while (RequestElement
!= NULL
) {
4786 // +1 to avoid find header itself.
4788 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
4791 // The last Request element in configRequest string.
4793 if (NextRequestElement
!= NULL
) {
4795 // Replace "&" with '\0'.
4797 *NextRequestElement
= L
'\0';
4800 RemoveElement (Storage
->BrowserStorage
, RequestElement
);
4802 if (NextRequestElement
!= NULL
) {
4804 // Restore '&' with '\0' for later used.
4806 *NextRequestElement
= L
'&';
4809 RequestElement
= NextRequestElement
;
4813 // If no request element remain, just remove the ConfigRequest string.
4815 if (StrCmp (Storage
->BrowserStorage
->ConfigRequest
, Storage
->ConfigHdr
) == 0) {
4816 FreePool (Storage
->BrowserStorage
->ConfigRequest
);
4817 Storage
->BrowserStorage
->ConfigRequest
= NULL
;
4818 Storage
->BrowserStorage
->SpareStrLen
= 0;
4823 Base on the current formset info, clean the ConfigRequest string in browser storage.
4825 @param FormSet Pointer of the FormSet
4829 CleanBrowserStorage (
4830 IN OUT FORM_BROWSER_FORMSET
*FormSet
4834 FORMSET_STORAGE
*Storage
;
4836 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4837 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4838 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
4839 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4841 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
4842 if (Storage
->ConfigRequest
== NULL
|| Storage
->BrowserStorage
->ConfigRequest
== NULL
) {
4846 RemoveConfigRequest (Storage
, Storage
->ConfigRequest
);
4847 } else if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_BUFFER
||
4848 Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4849 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
4850 FreePool (Storage
->BrowserStorage
->ConfigRequest
);
4851 Storage
->BrowserStorage
->ConfigRequest
= NULL
;
4853 Storage
->BrowserStorage
->Initialized
= FALSE
;
4859 Check whether current element in the ConfigReqeust string.
4861 @param BrowserStorage Storage which includes ConfigReqeust.
4862 @param RequestElement New element need to check.
4864 @retval TRUE The Element is in the ConfigReqeust string.
4865 @retval FALSE The Element not in the configReqeust String.
4870 BROWSER_STORAGE
*BrowserStorage
,
4871 CHAR16
*RequestElement
4874 return StrStr (BrowserStorage
->ConfigRequest
, RequestElement
) != NULL
? TRUE
: FALSE
;
4878 Append the Request element to the Config Request.
4880 @param ConfigRequest Current ConfigRequest info.
4881 @param SpareStrLen Current remain free buffer for config reqeust.
4882 @param RequestElement New Request element.
4886 AppendConfigRequest (
4887 IN OUT CHAR16
**ConfigRequest
,
4888 IN OUT UINTN
*SpareStrLen
,
4889 IN CHAR16
*RequestElement
4897 StrLength
= StrLen (RequestElement
);
4898 StringSize
= (*ConfigRequest
!= NULL
) ? StrSize (*ConfigRequest
) : sizeof (CHAR16
);
4899 MaxLen
= StringSize
/ sizeof (CHAR16
) + *SpareStrLen
;
4902 // Append <RequestElement> to <ConfigRequest>
4904 if (StrLength
> *SpareStrLen
) {
4906 // Old String buffer is not sufficient for RequestElement, allocate a new one
4908 MaxLen
= StringSize
/ sizeof (CHAR16
) + CONFIG_REQUEST_STRING_INCREMENTAL
;
4909 NewStr
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
4910 ASSERT (NewStr
!= NULL
);
4912 if (*ConfigRequest
!= NULL
) {
4913 CopyMem (NewStr
, *ConfigRequest
, StringSize
);
4914 FreePool (*ConfigRequest
);
4916 *ConfigRequest
= NewStr
;
4917 *SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
4920 StrCatS (*ConfigRequest
, MaxLen
, RequestElement
);
4921 *SpareStrLen
-= StrLength
;
4925 Adjust the config request info, remove the request elements which already in AllConfigRequest string.
4927 @param Storage Form set Storage.
4928 @param Request The input request string.
4929 @param RespString Whether the input is ConfigRequest or ConfigResp format.
4931 @retval TRUE Has element not covered by current used elements, need to continue to call ExtractConfig
4932 @retval FALSE All elements covered by current used elements.
4936 ConfigRequestAdjust (
4937 IN BROWSER_STORAGE
*Storage
,
4939 IN BOOLEAN RespString
4942 CHAR16
*RequestElement
;
4943 CHAR16
*NextRequestElement
;
4944 CHAR16
*NextElementBakup
;
4948 CHAR16
*ConfigRequest
;
4951 NextElementBakup
= NULL
;
4954 if (Request
!= NULL
) {
4955 ConfigRequest
= Request
;
4957 ConfigRequest
= Storage
->ConfigRequest
;
4960 if (Storage
->ConfigRequest
== NULL
) {
4961 Storage
->ConfigRequest
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
4965 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4967 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
4972 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
4974 SearchKey
= L
"&OFFSET";
4975 ValueKey
= L
"&VALUE";
4979 // Find SearchKey storage
4981 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4982 RequestElement
= StrStr (ConfigRequest
, L
"PATH");
4983 ASSERT (RequestElement
!= NULL
);
4984 RequestElement
= StrStr (RequestElement
, SearchKey
);
4986 RequestElement
= StrStr (ConfigRequest
, SearchKey
);
4989 while (RequestElement
!= NULL
) {
4992 // +1 to avoid find header itself.
4994 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
4997 // The last Request element in configRequest string.
4999 if (NextRequestElement
!= NULL
) {
5000 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
5001 NextElementBakup
= NextRequestElement
;
5002 NextRequestElement
= StrStr (RequestElement
, ValueKey
);
5003 ASSERT (NextRequestElement
!= NULL
);
5006 // Replace "&" with '\0'.
5008 *NextRequestElement
= L
'\0';
5010 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
5011 NextElementBakup
= NextRequestElement
;
5012 NextRequestElement
= StrStr (RequestElement
, ValueKey
);
5013 ASSERT (NextRequestElement
!= NULL
);
5015 // Replace "&" with '\0'.
5017 *NextRequestElement
= L
'\0';
5021 if (!ElementValidation (Storage
, RequestElement
)) {
5023 // Add this element to the Storage->BrowserStorage->AllRequestElement.
5025 AppendConfigRequest(&Storage
->ConfigRequest
, &Storage
->SpareStrLen
, RequestElement
);
5029 if (NextRequestElement
!= NULL
) {
5031 // Restore '&' with '\0' for later used.
5033 *NextRequestElement
= L
'&';
5036 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
5037 RequestElement
= NextElementBakup
;
5039 RequestElement
= NextRequestElement
;
5047 Fill storage's edit copy with settings requested from Configuration Driver.
5049 @param FormSet FormSet data structure.
5050 @param Storage Buffer Storage.
5055 IN FORM_BROWSER_FORMSET
*FormSet
,
5056 IN FORMSET_STORAGE
*Storage
5060 EFI_STRING Progress
;
5063 EFI_STRING ConfigRequest
;
5066 ConfigRequest
= NULL
;
5068 switch (Storage
->BrowserStorage
->Type
) {
5069 case EFI_HII_VARSTORE_EFI_VARIABLE
:
5072 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
5073 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
5074 ConfigRequestAdjust(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
5079 case EFI_HII_VARSTORE_BUFFER
:
5080 case EFI_HII_VARSTORE_NAME_VALUE
:
5082 // Skip if there is no RequestElement.
5084 if (Storage
->ElementCount
== 0) {
5089 // Just update the ConfigRequest, if storage already initialized.
5091 if (Storage
->BrowserStorage
->Initialized
) {
5092 ConfigRequestAdjust(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
5096 Storage
->BrowserStorage
->Initialized
= TRUE
;
5103 if (Storage
->BrowserStorage
->Type
!= EFI_HII_VARSTORE_NAME_VALUE
) {
5105 // Create the config request string to get all fields for this storage.
5106 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
5107 // followed by "&OFFSET=0&WIDTH=WWWW"followed by a Null-terminator
5109 StrLen
= StrSize (Storage
->ConfigHdr
) + 20 * sizeof (CHAR16
);
5110 ConfigRequest
= AllocateZeroPool (StrLen
);
5111 ASSERT (ConfigRequest
!= NULL
);
5115 L
"%s&OFFSET=0&WIDTH=%04x",
5117 Storage
->BrowserStorage
->Size
);
5119 ConfigRequest
= Storage
->ConfigRequest
;
5123 // Request current settings from Configuration Driver
5125 Status
= mHiiConfigRouting
->ExtractConfig (
5133 // If get value fail, extract default from IFR binary
5135 if (EFI_ERROR (Status
)) {
5136 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForStorage
, Storage
->BrowserStorage
, TRUE
, TRUE
);
5139 // Convert Result from <ConfigAltResp> to <ConfigResp>
5141 StrPtr
= StrStr (Result
, L
"&GUID=");
5142 if (StrPtr
!= NULL
) {
5146 Status
= ConfigRespToStorage (Storage
->BrowserStorage
, Result
);
5150 Storage
->BrowserStorage
->ConfigRequest
= AllocateCopyPool (StrSize (Storage
->ConfigRequest
), Storage
->ConfigRequest
);
5153 // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer.
5155 SynchronizeStorage(Storage
->BrowserStorage
, NULL
, TRUE
);
5157 if (Storage
->BrowserStorage
->Type
!= EFI_HII_VARSTORE_NAME_VALUE
) {
5158 if (ConfigRequest
!= NULL
) {
5159 FreePool (ConfigRequest
);
5165 Get Value changed status from old question.
5167 @param NewFormSet FormSet data structure.
5168 @param OldQuestion Old question which has value changed.
5172 SyncStatusForQuestion (
5173 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
5174 IN FORM_BROWSER_STATEMENT
*OldQuestion
5178 LIST_ENTRY
*QuestionLink
;
5179 FORM_BROWSER_FORM
*Form
;
5180 FORM_BROWSER_STATEMENT
*Question
;
5183 // For each form in one formset.
5185 Link
= GetFirstNode (&NewFormSet
->FormListHead
);
5186 while (!IsNull (&NewFormSet
->FormListHead
, Link
)) {
5187 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
5188 Link
= GetNextNode (&NewFormSet
->FormListHead
, Link
);
5191 // for each question in one form.
5193 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
5194 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
5195 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
5196 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
5198 if (Question
->QuestionId
== OldQuestion
->QuestionId
) {
5199 Question
->ValueChanged
= TRUE
;
5207 Get Value changed status from old formset.
5209 @param NewFormSet FormSet data structure.
5210 @param OldFormSet FormSet data structure.
5214 SyncStatusForFormSet (
5215 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
5216 IN FORM_BROWSER_FORMSET
*OldFormSet
5220 LIST_ENTRY
*QuestionLink
;
5221 FORM_BROWSER_FORM
*Form
;
5222 FORM_BROWSER_STATEMENT
*Question
;
5225 // For each form in one formset.
5227 Link
= GetFirstNode (&OldFormSet
->FormListHead
);
5228 while (!IsNull (&OldFormSet
->FormListHead
, Link
)) {
5229 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
5230 Link
= GetNextNode (&OldFormSet
->FormListHead
, Link
);
5233 // for each question in one form.
5235 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
5236 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
5237 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
5238 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
5240 if (!Question
->ValueChanged
) {
5245 // Find the same question in new formset and update the value changed flag.
5247 SyncStatusForQuestion (NewFormSet
, Question
);
5253 Get current setting of Questions.
5255 @param FormSet FormSet data structure.
5259 InitializeCurrentSetting (
5260 IN OUT FORM_BROWSER_FORMSET
*FormSet
5264 FORMSET_STORAGE
*Storage
;
5265 FORM_BROWSER_FORMSET
*OldFormSet
;
5268 // Try to find pre FormSet in the maintain backup list.
5269 // If old formset != NULL, destroy this formset. Add new formset to gBrowserFormSetList.
5271 OldFormSet
= GetFormSetFromHiiHandle (FormSet
->HiiHandle
);
5272 if (OldFormSet
!= NULL
) {
5273 SyncStatusForFormSet (FormSet
, OldFormSet
);
5274 RemoveEntryList (&OldFormSet
->Link
);
5275 DestroyFormSet (OldFormSet
);
5277 InsertTailList (&gBrowserFormSetList
, &FormSet
->Link
);
5280 // Extract default from IFR binary for no storage questions.
5282 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForNoStorage
, NULL
, TRUE
, FALSE
);
5285 // Request current settings from Configuration Driver
5287 Link
= GetFirstNode (&FormSet
->StorageListHead
);
5288 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
5289 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
5291 LoadStorage (FormSet
, Storage
);
5293 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
5299 Fetch the Ifr binary data of a FormSet.
5301 @param Handle PackageList Handle
5302 @param FormSetGuid On input, GUID or class GUID of a formset. If not
5303 specified (NULL or zero GUID), take the first
5304 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
5305 found in package list.
5306 On output, GUID of the formset found(if not NULL).
5307 @param BinaryLength The length of the FormSet IFR binary.
5308 @param BinaryData The buffer designed to receive the FormSet.
5310 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
5311 BufferLength was updated.
5312 @retval EFI_INVALID_PARAMETER The handle is unknown.
5313 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
5314 be found with the requested FormId.
5319 IN EFI_HII_HANDLE Handle
,
5320 IN OUT EFI_GUID
*FormSetGuid
,
5321 OUT UINTN
*BinaryLength
,
5322 OUT UINT8
**BinaryData
5326 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
5332 UINT32 PackageListLength
;
5333 EFI_HII_PACKAGE_HEADER PackageHeader
;
5335 UINT8 NumberOfClassGuid
;
5336 BOOLEAN ClassGuidMatch
;
5337 EFI_GUID
*ClassGuid
;
5338 EFI_GUID
*ComparingGuid
;
5342 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
5345 // if FormSetGuid is NULL or zero GUID, return first Setup FormSet in the package list
5347 if (FormSetGuid
== NULL
) {
5348 ComparingGuid
= &gZeroGuid
;
5350 ComparingGuid
= FormSetGuid
;
5354 // Get HII PackageList
5357 HiiPackageList
= NULL
;
5358 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
5359 if (Status
== EFI_BUFFER_TOO_SMALL
) {
5360 HiiPackageList
= AllocatePool (BufferSize
);
5361 ASSERT (HiiPackageList
!= NULL
);
5363 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
5365 if (EFI_ERROR (Status
)) {
5368 ASSERT (HiiPackageList
!= NULL
);
5371 // Get Form package from this HII package List
5373 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
5375 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
5377 ClassGuidMatch
= FALSE
;
5378 while (Offset
< PackageListLength
) {
5379 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
5380 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
5382 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
5384 // Search FormSet in this Form Package
5386 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
5387 while (Offset2
< PackageHeader
.Length
) {
5388 OpCodeData
= Package
+ Offset2
;
5390 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
5392 // Try to compare against formset GUID
5394 if (CompareGuid (FormSetGuid
, &gZeroGuid
) ||
5395 CompareGuid (ComparingGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
5399 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
5401 // Try to compare against formset class GUID
5403 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
5404 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
5405 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
5406 if (CompareGuid (ComparingGuid
, ClassGuid
+ Index
)) {
5407 ClassGuidMatch
= TRUE
;
5411 if (ClassGuidMatch
) {
5414 } else if (ComparingGuid
== &gEfiHiiPlatformSetupFormsetGuid
) {
5415 ClassGuidMatch
= TRUE
;
5420 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
5423 if (Offset2
< PackageHeader
.Length
) {
5425 // Target formset found
5431 Offset
+= PackageHeader
.Length
;
5434 if (Offset
>= PackageListLength
) {
5436 // Form package not found in this Package List
5438 FreePool (HiiPackageList
);
5439 return EFI_NOT_FOUND
;
5442 if (FormSetGuid
!= NULL
) {
5444 // Return the FormSet GUID
5446 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
5450 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
5451 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
5452 // of the Form Package.
5454 *BinaryLength
= PackageHeader
.Length
- Offset2
;
5455 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
5457 FreePool (HiiPackageList
);
5459 if (*BinaryData
== NULL
) {
5460 return EFI_OUT_OF_RESOURCES
;
5468 Initialize the internal data structure of a FormSet.
5470 @param Handle PackageList Handle
5471 @param FormSetGuid On input, GUID or class GUID of a formset. If not
5472 specified (NULL or zero GUID), take the first
5473 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
5474 found in package list.
5475 On output, GUID of the formset found(if not NULL).
5476 @param FormSet FormSet data structure.
5478 @retval EFI_SUCCESS The function completed successfully.
5479 @retval EFI_NOT_FOUND The specified FormSet could not be found.
5484 IN EFI_HII_HANDLE Handle
,
5485 IN OUT EFI_GUID
*FormSetGuid
,
5486 OUT FORM_BROWSER_FORMSET
*FormSet
5490 EFI_HANDLE DriverHandle
;
5492 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
5493 if (EFI_ERROR (Status
)) {
5497 FormSet
->Signature
= FORM_BROWSER_FORMSET_SIGNATURE
;
5498 FormSet
->HiiHandle
= Handle
;
5499 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
5500 FormSet
->QuestionInited
= FALSE
;
5503 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
5505 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
5506 if (EFI_ERROR (Status
)) {
5509 FormSet
->DriverHandle
= DriverHandle
;
5510 Status
= gBS
->HandleProtocol (
5512 &gEfiHiiConfigAccessProtocolGuid
,
5513 (VOID
**) &FormSet
->ConfigAccess
5515 if (EFI_ERROR (Status
)) {
5517 // Configuration Driver don't attach ConfigAccess protocol to its HII package
5518 // list, then there will be no configuration action required
5520 FormSet
->ConfigAccess
= NULL
;
5524 // Parse the IFR binary OpCodes
5526 Status
= ParseOpCodes (FormSet
);
5533 Save globals used by previous call to SendForm(). SendForm() may be called from
5534 HiiConfigAccess.Callback(), this will cause SendForm() be reentried.
5535 So, save globals of previous call to SendForm() and restore them upon exit.
5539 SaveBrowserContext (
5543 BROWSER_CONTEXT
*Context
;
5544 FORM_ENTRY_INFO
*MenuList
;
5546 gBrowserContextCount
++;
5547 if (gBrowserContextCount
== 1) {
5549 // This is not reentry of SendForm(), no context to save
5554 Context
= AllocatePool (sizeof (BROWSER_CONTEXT
));
5555 ASSERT (Context
!= NULL
);
5557 Context
->Signature
= BROWSER_CONTEXT_SIGNATURE
;
5560 // Save FormBrowser context
5562 Context
->Selection
= gCurrentSelection
;
5563 Context
->ResetRequired
= gResetRequired
;
5564 Context
->FlagReconnect
= gFlagReconnect
;
5565 Context
->CallbackReconnect
= gCallbackReconnect
;
5566 Context
->ExitRequired
= gExitRequired
;
5567 Context
->HiiHandle
= mCurrentHiiHandle
;
5568 Context
->FormId
= mCurrentFormId
;
5569 CopyGuid (&Context
->FormSetGuid
, &mCurrentFormSetGuid
);
5572 // Save the menu history data.
5574 InitializeListHead(&Context
->FormHistoryList
);
5575 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
5576 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
5577 RemoveEntryList (&MenuList
->Link
);
5579 InsertTailList(&Context
->FormHistoryList
, &MenuList
->Link
);
5583 // Insert to FormBrowser context list
5585 InsertHeadList (&gBrowserContextList
, &Context
->Link
);
5590 Restore globals used by previous call to SendForm().
5594 RestoreBrowserContext (
5599 BROWSER_CONTEXT
*Context
;
5600 FORM_ENTRY_INFO
*MenuList
;
5602 ASSERT (gBrowserContextCount
!= 0);
5603 gBrowserContextCount
--;
5604 if (gBrowserContextCount
== 0) {
5606 // This is not reentry of SendForm(), no context to restore
5611 ASSERT (!IsListEmpty (&gBrowserContextList
));
5613 Link
= GetFirstNode (&gBrowserContextList
);
5614 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
5617 // Restore FormBrowser context
5619 gCurrentSelection
= Context
->Selection
;
5620 gResetRequired
= Context
->ResetRequired
;
5621 gFlagReconnect
= Context
->FlagReconnect
;
5622 gCallbackReconnect
= Context
->CallbackReconnect
;
5623 gExitRequired
= Context
->ExitRequired
;
5624 mCurrentHiiHandle
= Context
->HiiHandle
;
5625 mCurrentFormId
= Context
->FormId
;
5626 CopyGuid (&mCurrentFormSetGuid
, &Context
->FormSetGuid
);
5629 // Restore the menu history data.
5631 while (!IsListEmpty (&Context
->FormHistoryList
)) {
5632 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Context
->FormHistoryList
.ForwardLink
);
5633 RemoveEntryList (&MenuList
->Link
);
5635 InsertTailList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &MenuList
->Link
);
5639 // Remove from FormBrowser context list
5641 RemoveEntryList (&Context
->Link
);
5642 gBS
->FreePool (Context
);
5646 Find the matched FormSet context in the backup maintain list based on HiiHandle.
5648 @param Handle The Hii Handle.
5650 @return the found FormSet context. If no found, NULL will return.
5653 FORM_BROWSER_FORMSET
*
5654 GetFormSetFromHiiHandle (
5655 EFI_HII_HANDLE Handle
5659 FORM_BROWSER_FORMSET
*FormSet
;
5661 Link
= GetFirstNode (&gBrowserFormSetList
);
5662 while (!IsNull (&gBrowserFormSetList
, Link
)) {
5663 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
5664 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
5665 if (!ValidateFormSet(FormSet
)) {
5668 if (FormSet
->HiiHandle
== Handle
) {
5677 Check whether the input HII handle is the FormSet that is being used.
5679 @param Handle The Hii Handle.
5681 @retval TRUE HII handle is being used.
5682 @retval FALSE HII handle is not being used.
5686 IsHiiHandleInBrowserContext (
5687 EFI_HII_HANDLE Handle
5691 BROWSER_CONTEXT
*Context
;
5694 // HiiHandle is Current FormSet.
5696 if (mCurrentHiiHandle
== Handle
) {
5701 // Check whether HiiHandle is in BrowserContext.
5703 Link
= GetFirstNode (&gBrowserContextList
);
5704 while (!IsNull (&gBrowserContextList
, Link
)) {
5705 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
5706 if (Context
->HiiHandle
== Handle
) {
5708 // HiiHandle is in BrowserContext
5712 Link
= GetNextNode (&gBrowserContextList
, Link
);
5719 Perform Password check.
5720 Passwork may be encrypted by driver that requires the specific check.
5722 @param Form Form where Password Statement is in.
5723 @param Statement Password statement
5724 @param PasswordString Password string to be checked. It may be NULL.
5725 NULL means to restore password.
5726 "" string can be used to checked whether old password does exist.
5728 @return Status Status of Password check.
5733 IN FORM_DISPLAY_ENGINE_FORM
*Form
,
5734 IN FORM_DISPLAY_ENGINE_STATEMENT
*Statement
,
5735 IN EFI_STRING PasswordString OPTIONAL
5739 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
5740 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
5741 EFI_IFR_TYPE_VALUE IfrTypeValue
;
5742 FORM_BROWSER_STATEMENT
*Question
;
5744 ConfigAccess
= gCurrentSelection
->FormSet
->ConfigAccess
;
5745 Question
= GetBrowserStatement(Statement
);
5746 ASSERT (Question
!= NULL
);
5748 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
) {
5749 if (ConfigAccess
== NULL
) {
5750 return EFI_UNSUPPORTED
;
5753 if (PasswordString
== NULL
) {
5758 // Check whether has preexisted password.
5760 if (PasswordString
[0] == 0) {
5761 if (*((CHAR16
*) Question
->BufferValue
) == 0) {
5764 return EFI_NOT_READY
;
5769 // Check whether the input password is same as preexisted password.
5771 if (StrnCmp (PasswordString
, (CHAR16
*) Question
->BufferValue
, Question
->StorageWidth
/sizeof (CHAR16
)) == 0) {
5774 return EFI_NOT_READY
;
5779 // Prepare password string in HII database
5781 if (PasswordString
!= NULL
) {
5782 IfrTypeValue
.string
= NewString (PasswordString
, gCurrentSelection
->FormSet
->HiiHandle
);
5784 IfrTypeValue
.string
= 0;
5788 // Send password to Configuration Driver for validation
5790 Status
= ConfigAccess
->Callback (
5792 EFI_BROWSER_ACTION_CHANGING
,
5793 Question
->QuestionId
,
5794 Question
->HiiValue
.Type
,
5800 // Remove password string from HII database
5802 if (PasswordString
!= NULL
) {
5803 DeleteString (IfrTypeValue
.string
, gCurrentSelection
->FormSet
->HiiHandle
);
5810 Find the registered HotKey based on KeyData.
5812 @param[in] KeyData A pointer to a buffer that describes the keystroke
5813 information for the hot key.
5815 @return The registered HotKey context. If no found, NULL will return.
5818 GetHotKeyFromRegisterList (
5819 IN EFI_INPUT_KEY
*KeyData
5823 BROWSER_HOT_KEY
*HotKey
;
5825 Link
= GetFirstNode (&gBrowserHotKeyList
);
5826 while (!IsNull (&gBrowserHotKeyList
, Link
)) {
5827 HotKey
= BROWSER_HOT_KEY_FROM_LINK (Link
);
5828 if (HotKey
->KeyData
->ScanCode
== KeyData
->ScanCode
) {
5831 Link
= GetNextNode (&gBrowserHotKeyList
, Link
);
5838 Configure what scope the hot key will impact.
5839 All hot keys have the same scope. The mixed hot keys with the different level are not supported.
5840 If no scope is set, the default scope will be FormSet level.
5841 After all registered hot keys are removed, previous Scope can reset to another level.
5843 @param[in] Scope Scope level to be set.
5845 @retval EFI_SUCCESS Scope is set correctly.
5846 @retval EFI_INVALID_PARAMETER Scope is not the valid value specified in BROWSER_SETTING_SCOPE.
5847 @retval EFI_UNSPPORTED Scope level is different from current one that the registered hot keys have.
5853 IN BROWSER_SETTING_SCOPE Scope
5856 if (Scope
>= MaxLevel
) {
5857 return EFI_INVALID_PARAMETER
;
5861 // When no hot key registered in system or on the first setting,
5862 // Scope can be set.
5864 if (mBrowserScopeFirstSet
|| IsListEmpty (&gBrowserHotKeyList
)) {
5865 gBrowserSettingScope
= Scope
;
5866 mBrowserScopeFirstSet
= FALSE
;
5867 } else if (Scope
!= gBrowserSettingScope
) {
5868 return EFI_UNSUPPORTED
;
5875 Register the hot key with its browser action, or unregistered the hot key.
5876 Only support hot key that is not printable character (control key, function key, etc.).
5877 If the action value is zero, the hot key will be unregistered if it has been registered.
5878 If the same hot key has been registered, the new action and help string will override the previous ones.
5880 @param[in] KeyData A pointer to a buffer that describes the keystroke
5881 information for the hot key. Its type is EFI_INPUT_KEY to
5882 be supported by all ConsoleIn devices.
5883 @param[in] Action Action value that describes what action will be trigged when the hot key is pressed.
5884 @param[in] DefaultId Specifies the type of defaults to retrieve, which is only for DEFAULT action.
5885 @param[in] HelpString Help string that describes the hot key information.
5886 Its value may be NULL for the unregistered hot key.
5888 @retval EFI_SUCCESS Hot key is registered or unregistered.
5889 @retval EFI_INVALID_PARAMETER KeyData is NULL or HelpString is NULL on register.
5890 @retval EFI_NOT_FOUND KeyData is not found to be unregistered.
5891 @retval EFI_UNSUPPORTED Key represents a printable character. It is conflicted with Browser.
5896 IN EFI_INPUT_KEY
*KeyData
,
5898 IN UINT16 DefaultId
,
5899 IN EFI_STRING HelpString OPTIONAL
5902 BROWSER_HOT_KEY
*HotKey
;
5905 // Check input parameters.
5907 if (KeyData
== NULL
|| KeyData
->UnicodeChar
!= CHAR_NULL
||
5908 (Action
!= BROWSER_ACTION_UNREGISTER
&& HelpString
== NULL
)) {
5909 return EFI_INVALID_PARAMETER
;
5913 // Check whether the input KeyData is in BrowserHotKeyList.
5915 HotKey
= GetHotKeyFromRegisterList (KeyData
);
5918 // Unregister HotKey
5920 if (Action
== BROWSER_ACTION_UNREGISTER
) {
5921 if (HotKey
!= NULL
) {
5923 // The registered HotKey is found.
5924 // Remove it from List, and free its resource.
5926 RemoveEntryList (&HotKey
->Link
);
5927 FreePool (HotKey
->KeyData
);
5928 FreePool (HotKey
->HelpString
);
5932 // The registered HotKey is not found.
5934 return EFI_NOT_FOUND
;
5939 // Register HotKey into List.
5941 if (HotKey
== NULL
) {
5943 // Create new Key, and add it into List.
5945 HotKey
= AllocateZeroPool (sizeof (BROWSER_HOT_KEY
));
5946 ASSERT (HotKey
!= NULL
);
5947 HotKey
->Signature
= BROWSER_HOT_KEY_SIGNATURE
;
5948 HotKey
->KeyData
= AllocateCopyPool (sizeof (EFI_INPUT_KEY
), KeyData
);
5949 InsertTailList (&gBrowserHotKeyList
, &HotKey
->Link
);
5953 // Fill HotKey information.
5955 HotKey
->Action
= Action
;
5956 HotKey
->DefaultId
= DefaultId
;
5957 if (HotKey
->HelpString
!= NULL
) {
5958 FreePool (HotKey
->HelpString
);
5960 HotKey
->HelpString
= AllocateCopyPool (StrSize (HelpString
), HelpString
);
5966 Register Exit handler function.
5967 When more than one handler function is registered, the latter one will override the previous one.
5968 When NULL handler is specified, the previous Exit handler will be unregistered.
5970 @param[in] Handler Pointer to handler function.
5975 RegiserExitHandler (
5976 IN EXIT_HANDLER Handler
5979 ExitHandlerFunction
= Handler
;
5984 Check whether the browser data has been modified.
5986 @retval TRUE Browser data is modified.
5987 @retval FALSE No browser data is modified.
5992 IsBrowserDataModified (
5997 FORM_BROWSER_FORMSET
*FormSet
;
5999 switch (gBrowserSettingScope
) {
6001 if (gCurrentSelection
== NULL
) {
6004 return IsNvUpdateRequiredForForm (gCurrentSelection
->Form
);
6007 if (gCurrentSelection
== NULL
) {
6010 return IsNvUpdateRequiredForFormSet (gCurrentSelection
->FormSet
);
6013 Link
= GetFirstNode (&gBrowserFormSetList
);
6014 while (!IsNull (&gBrowserFormSetList
, Link
)) {
6015 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
6016 if (!ValidateFormSet(FormSet
)) {
6020 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
6023 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
6033 Execute the action requested by the Action parameter.
6035 @param[in] Action Execute the request action.
6036 @param[in] DefaultId The default Id info when need to load default value. Only used when Action is BROWSER_ACTION_DEFAULT.
6038 @retval EFI_SUCCESS Execute the request action succss.
6039 @retval EFI_INVALID_PARAMETER The input action value is invalid.
6050 FORM_BROWSER_FORMSET
*FormSet
;
6051 FORM_BROWSER_FORM
*Form
;
6053 if (gBrowserSettingScope
< SystemLevel
&& gCurrentSelection
== NULL
) {
6054 return EFI_NOT_READY
;
6057 Status
= EFI_SUCCESS
;
6060 if (gBrowserSettingScope
< SystemLevel
) {
6061 FormSet
= gCurrentSelection
->FormSet
;
6062 Form
= gCurrentSelection
->Form
;
6066 // Executet the discard action.
6068 if ((Action
& BROWSER_ACTION_DISCARD
) != 0) {
6069 Status
= DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
6070 if (EFI_ERROR (Status
)) {
6076 // Executet the difault action.
6078 if ((Action
& BROWSER_ACTION_DEFAULT
) != 0) {
6079 Status
= ExtractDefault (FormSet
, Form
, DefaultId
, gBrowserSettingScope
, GetDefaultForAll
, NULL
, FALSE
, FALSE
);
6080 if (EFI_ERROR (Status
)) {
6083 UpdateStatementStatus (FormSet
, Form
, gBrowserSettingScope
);
6087 // Executet the submit action.
6089 if ((Action
& BROWSER_ACTION_SUBMIT
) != 0) {
6090 Status
= SubmitForm (FormSet
, Form
, gBrowserSettingScope
);
6091 if (EFI_ERROR (Status
)) {
6097 // Executet the reset action.
6099 if ((Action
& BROWSER_ACTION_RESET
) != 0) {
6100 gResetRequired
= TRUE
;
6104 // Executet the exit action.
6106 if ((Action
& BROWSER_ACTION_EXIT
) != 0) {
6107 DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
6108 if (gBrowserSettingScope
== SystemLevel
) {
6109 if (ExitHandlerFunction
!= NULL
) {
6110 ExitHandlerFunction ();
6114 gExitRequired
= TRUE
;
6121 Create reminder to let user to choose save or discard the changed browser data.
6122 Caller can use it to actively check the changed browser data.
6124 @retval BROWSER_NO_CHANGES No browser data is changed.
6125 @retval BROWSER_SAVE_CHANGES The changed browser data is saved.
6126 @retval BROWSER_DISCARD_CHANGES The changed browser data is discard.
6127 @retval BROWSER_KEEP_CURRENT Browser keep current changes.
6137 FORM_BROWSER_FORMSET
*FormSet
;
6138 BOOLEAN IsDataChanged
;
6139 UINT32 DataSavedAction
;
6142 DataSavedAction
= BROWSER_NO_CHANGES
;
6143 IsDataChanged
= FALSE
;
6144 Link
= GetFirstNode (&gBrowserFormSetList
);
6145 while (!IsNull (&gBrowserFormSetList
, Link
)) {
6146 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
6147 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
6148 if (!ValidateFormSet(FormSet
)) {
6151 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
6152 IsDataChanged
= TRUE
;
6158 // No data is changed. No save is required.
6160 if (!IsDataChanged
) {
6161 return DataSavedAction
;
6165 // If data is changed, prompt user to save or discard it.
6168 ConfirmRet
= (UINT32
) mFormDisplay
->ConfirmDataChange();
6170 if (ConfirmRet
== BROWSER_ACTION_SUBMIT
) {
6171 SubmitForm (NULL
, NULL
, SystemLevel
);
6172 DataSavedAction
= BROWSER_SAVE_CHANGES
;
6174 } else if (ConfirmRet
== BROWSER_ACTION_DISCARD
) {
6175 DiscardForm (NULL
, NULL
, SystemLevel
);
6176 DataSavedAction
= BROWSER_DISCARD_CHANGES
;
6178 } else if (ConfirmRet
== BROWSER_ACTION_NONE
) {
6179 DataSavedAction
= BROWSER_KEEP_CURRENT
;
6184 return DataSavedAction
;
6188 Check whether the Reset Required for the browser
6190 @retval TRUE Browser required to reset after exit.
6191 @retval FALSE Browser not need to reset after exit.
6200 return gResetRequired
;