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 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
73 extern EFI_GUID mCurrentFormSetGuid
;
74 extern EFI_HII_HANDLE mCurrentHiiHandle
;
75 extern UINT16 mCurrentFormId
;
76 extern FORM_DISPLAY_ENGINE_FORM gDisplayFormData
;
79 Create a menu with specified formset GUID and form ID, and add it as a child
80 of the given parent menu.
82 @param HiiHandle Hii handle related to this formset.
83 @param FormSetGuid The Formset Guid of menu to be added.
84 @param FormId The Form ID of menu to be added.
85 @param QuestionId The question id of this menu to be added.
87 @return A pointer to the newly added menu or NULL if memory is insufficient.
92 IN EFI_HII_HANDLE HiiHandle
,
93 IN EFI_GUID
*FormSetGuid
,
98 FORM_ENTRY_INFO
*MenuList
;
100 MenuList
= AllocateZeroPool (sizeof (FORM_ENTRY_INFO
));
101 if (MenuList
== NULL
) {
105 MenuList
->Signature
= FORM_ENTRY_INFO_SIGNATURE
;
107 MenuList
->HiiHandle
= HiiHandle
;
108 CopyMem (&MenuList
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
109 MenuList
->FormId
= FormId
;
110 MenuList
->QuestionId
= QuestionId
;
113 // If parent is not specified, it is the root Form of a Formset
115 InsertTailList (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &MenuList
->Link
);
121 Return the form id for the input hiihandle and formset.
123 @param HiiHandle HiiHandle for FormSet.
124 @param FormSetGuid The Formset GUID of the menu to search.
126 @return First form's id for this form set.
131 IN EFI_HII_HANDLE HiiHandle
,
132 IN EFI_GUID
*FormSetGuid
136 FORM_BROWSER_FORM
*Form
;
138 Link
= GetFirstNode (&gCurrentSelection
->FormSet
->FormListHead
);
139 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
145 Search Menu with given FormSetGuid and FormId in all cached menu list.
147 @param HiiHandle HiiHandle for FormSet.
148 @param FormSetGuid The Formset GUID of the menu to search.
149 @param FormId The Form ID of menu to search.
151 @return A pointer to menu found or NULL if not found.
156 IN EFI_HII_HANDLE HiiHandle
,
157 IN EFI_GUID
*FormSetGuid
,
162 FORM_ENTRY_INFO
*MenuList
;
163 FORM_ENTRY_INFO
*RetMenu
;
164 EFI_FORM_ID FirstFormId
;
168 Link
= GetFirstNode (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
);
169 while (!IsNull (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, Link
)) {
170 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Link
);
171 Link
= GetNextNode (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, Link
);
174 // If already find the menu, free the menus behind it.
176 if (RetMenu
!= NULL
) {
177 RemoveEntryList (&MenuList
->Link
);
183 // Find the same FromSet.
185 if (MenuList
->HiiHandle
== HiiHandle
) {
186 if (CompareGuid (&MenuList
->FormSetGuid
, &gZeroGuid
)) {
188 // FormSetGuid is not specified.
191 } else if (CompareGuid (&MenuList
->FormSetGuid
, FormSetGuid
)) {
192 if (MenuList
->FormId
== FormId
) {
194 } else if (FormId
== 0 || MenuList
->FormId
== 0 ) {
195 FirstFormId
= GetFirstFormId (HiiHandle
, FormSetGuid
);
196 if ((FormId
== 0 && FirstFormId
== MenuList
->FormId
) || (MenuList
->FormId
==0 && FirstFormId
== FormId
)) {
208 Find parent menu for current menu.
210 @param CurrentMenu Current Menu
211 @param SettingLevel Whether find parent menu in Form Level or Formset level.
212 In form level, just find the parent menu;
213 In formset level, find the parent menu which has different
216 @retval The parent menu for current menu.
220 IN FORM_ENTRY_INFO
*CurrentMenu
,
221 IN BROWSER_SETTING_SCOPE SettingLevel
224 FORM_ENTRY_INFO
*ParentMenu
;
227 ASSERT (SettingLevel
== FormLevel
|| SettingLevel
== FormSetLevel
);
229 if (CurrentMenu
== NULL
) {
234 Link
= &CurrentMenu
->Link
;
236 while (Link
->BackLink
!= &mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
) {
237 ParentMenu
= FORM_ENTRY_INFO_FROM_LINK (Link
->BackLink
);
239 if (SettingLevel
== FormLevel
) {
241 // For FormLevel, just find the parent menu, return.
246 if (!CompareGuid (&CurrentMenu
->FormSetGuid
, &ParentMenu
->FormSetGuid
)) {
248 // For SystemLevel, must find the menu which has different formset.
253 Link
= Link
->BackLink
;
257 // Not find the parent menu, just return NULL.
259 if (Link
->BackLink
== &mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
) {
267 Free Menu list linked list.
269 @param MenuListHead One Menu list point in the menu list.
274 LIST_ENTRY
*MenuListHead
277 FORM_ENTRY_INFO
*MenuList
;
279 while (!IsListEmpty (MenuListHead
)) {
280 MenuList
= FORM_ENTRY_INFO_FROM_LINK (MenuListHead
->ForwardLink
);
281 RemoveEntryList (&MenuList
->Link
);
288 Copy current Menu list to the new menu list.
290 @param NewMenuListHead New create Menu list.
291 @param CurrentMenuListHead Current Menu list.
296 OUT LIST_ENTRY
*NewMenuListHead
,
297 IN LIST_ENTRY
*CurrentMenuListHead
301 FORM_ENTRY_INFO
*MenuList
;
302 FORM_ENTRY_INFO
*NewMenuEntry
;
305 // If new menu list not empty, free it first.
307 UiFreeMenuList (NewMenuListHead
);
309 Link
= GetFirstNode (CurrentMenuListHead
);
310 while (!IsNull (CurrentMenuListHead
, Link
)) {
311 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Link
);
312 Link
= GetNextNode (CurrentMenuListHead
, Link
);
314 NewMenuEntry
= AllocateZeroPool (sizeof (FORM_ENTRY_INFO
));
315 ASSERT (NewMenuEntry
!= NULL
);
316 NewMenuEntry
->Signature
= FORM_ENTRY_INFO_SIGNATURE
;
317 NewMenuEntry
->HiiHandle
= MenuList
->HiiHandle
;
318 CopyMem (&NewMenuEntry
->FormSetGuid
, &MenuList
->FormSetGuid
, sizeof (EFI_GUID
));
319 NewMenuEntry
->FormId
= MenuList
->FormId
;
320 NewMenuEntry
->QuestionId
= MenuList
->QuestionId
;
322 InsertTailList (NewMenuListHead
, &NewMenuEntry
->Link
);
327 Load all hii formset to the browser.
335 FORM_BROWSER_FORMSET
*LocalFormSet
;
336 EFI_HII_HANDLE
*HiiHandles
;
340 FORM_BROWSER_FORMSET
*OldFormset
;
342 OldFormset
= mSystemLevelFormSet
;
345 // Get all the Hii handles
347 HiiHandles
= HiiGetHiiHandles (NULL
);
348 ASSERT (HiiHandles
!= NULL
);
351 // Search for formset of each class type
353 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
355 // Check HiiHandles[Index] does exist in global maintain list.
357 if (GetFormSetFromHiiHandle (HiiHandles
[Index
]) != NULL
) {
362 // Initilize FormSet Setting
364 LocalFormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
365 ASSERT (LocalFormSet
!= NULL
);
366 mSystemLevelFormSet
= LocalFormSet
;
368 ZeroMem (&ZeroGuid
, sizeof (ZeroGuid
));
369 Status
= InitializeFormSet (HiiHandles
[Index
], &ZeroGuid
, LocalFormSet
);
370 if (EFI_ERROR (Status
) || IsListEmpty (&LocalFormSet
->FormListHead
)) {
371 DestroyFormSet (LocalFormSet
);
374 InitializeCurrentSetting (LocalFormSet
);
377 // Initilize Questions' Value
379 Status
= LoadFormSetConfig (NULL
, LocalFormSet
);
380 if (EFI_ERROR (Status
)) {
381 DestroyFormSet (LocalFormSet
);
387 // Free resources, and restore gOldFormSet and gClassOfVfr
389 FreePool (HiiHandles
);
391 mSystemLevelFormSet
= OldFormset
;
395 Pop up the error info.
397 @param BrowserStatus The input browser status.
398 @param HiiHandle The Hiihandle for this opcode.
399 @param OpCode The opcode use to get the erro info and timeout value.
400 @param ErrorString Error string used by BROWSER_NO_SUBMIT_IF.
405 IN UINT32 BrowserStatus
,
406 IN EFI_HII_HANDLE HiiHandle
,
407 IN EFI_IFR_OP_HEADER
*OpCode
, OPTIONAL
408 IN CHAR16
*ErrorString
411 FORM_DISPLAY_ENGINE_STATEMENT
*Statement
;
412 USER_INPUT UserInputData
;
416 if (OpCode
!= NULL
) {
417 Statement
= AllocateZeroPool (sizeof(FORM_DISPLAY_ENGINE_STATEMENT
));
418 ASSERT (Statement
!= NULL
);
419 Statement
->OpCode
= OpCode
;
420 gDisplayFormData
.HighLightedStatement
= Statement
;
424 // Used to compatible with old display engine.
425 // New display engine not use this field.
427 gDisplayFormData
.ErrorString
= ErrorString
;
428 gDisplayFormData
.BrowserStatus
= BrowserStatus
;
430 if (HiiHandle
!= NULL
) {
431 gDisplayFormData
.HiiHandle
= HiiHandle
;
434 mFormDisplay
->FormDisplay (&gDisplayFormData
, &UserInputData
);
436 gDisplayFormData
.BrowserStatus
= BROWSER_SUCCESS
;
437 gDisplayFormData
.ErrorString
= NULL
;
439 if (OpCode
!= NULL
) {
440 FreePool (Statement
);
443 return UserInputData
.Action
;
447 This is the routine which an external caller uses to direct the browser
448 where to obtain it's information.
451 @param This The Form Browser protocol instanse.
452 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
453 display a list of the formsets for the handles specified.
454 @param HandleCount The number of Handles specified in Handle.
455 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
456 field in the EFI_IFR_FORM_SET op-code for the specified
457 forms-based package. If FormSetGuid is NULL, then this
458 function will display the first found forms package.
459 @param FormId This field specifies which EFI_IFR_FORM to render as the first
460 displayable page. If this field has a value of 0x0000, then
461 the forms browser will render the specified forms in their encoded order.
462 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
464 @param ActionRequest Points to the action recommended by the form.
466 @retval EFI_SUCCESS The function completed successfully.
467 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
468 @retval EFI_NOT_FOUND No valid forms could be found to display.
474 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
475 IN EFI_HII_HANDLE
*Handles
,
476 IN UINTN HandleCount
,
477 IN EFI_GUID
*FormSetGuid
, OPTIONAL
478 IN UINT16 FormId
, OPTIONAL
479 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
480 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
484 UI_MENU_SELECTION
*Selection
;
486 FORM_BROWSER_FORMSET
*FormSet
;
487 FORM_ENTRY_INFO
*MenuList
;
491 // If EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found, return EFI_UNSUPPORTED.
493 if (mFormDisplay
== NULL
) {
494 return EFI_UNSUPPORTED
;
498 // Save globals used by SendForm()
500 SaveBrowserContext ();
502 gFlagReconnect
= FALSE
;
503 gResetRequired
= FALSE
;
504 gExitRequired
= FALSE
;
505 gCallbackReconnect
= FALSE
;
506 Status
= EFI_SUCCESS
;
508 gDisplayFormData
.ScreenDimensions
= (EFI_SCREEN_DESCRIPTOR
*) ScreenDimensions
;
510 for (Index
= 0; Index
< HandleCount
; Index
++) {
511 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
512 ASSERT (Selection
!= NULL
);
514 Selection
->Handle
= Handles
[Index
];
515 if (FormSetGuid
!= NULL
) {
516 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
517 Selection
->FormId
= FormId
;
519 CopyMem (&Selection
->FormSetGuid
, &gEfiHiiPlatformSetupFormsetGuid
, sizeof (EFI_GUID
));
523 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
524 ASSERT (FormSet
!= NULL
);
527 // Validate the HiiHandle
528 // if validate failed, find the first validate parent HiiHandle.
530 if (!ValidateHiiHandle(Selection
->Handle
)) {
531 FindNextMenu (Selection
, FormSetLevel
);
535 // Initialize internal data structures of FormSet
537 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
538 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
539 DestroyFormSet (FormSet
);
542 Selection
->FormSet
= FormSet
;
543 mSystemLevelFormSet
= FormSet
;
546 // Display this formset
548 gCurrentSelection
= Selection
;
550 Status
= SetupBrowser (Selection
);
552 gCurrentSelection
= NULL
;
553 mSystemLevelFormSet
= NULL
;
555 if (gFlagReconnect
|| gCallbackReconnect
) {
556 RetVal
= ReconnectController (FormSet
->DriverHandle
);
558 PopupErrorMessage(BROWSER_RECONNECT_FAIL
, NULL
, NULL
, NULL
);
560 gFlagReconnect
= FALSE
;
561 gCallbackReconnect
= FALSE
;
565 // If no data is changed, don't need to save current FormSet into the maintain list.
567 if (!IsNvUpdateRequiredForFormSet (FormSet
)) {
568 CleanBrowserStorage(FormSet
);
569 RemoveEntryList (&FormSet
->Link
);
570 DestroyFormSet (FormSet
);
573 if (EFI_ERROR (Status
)) {
576 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
578 FreePool (Selection
);
581 if (ActionRequest
!= NULL
) {
582 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
583 if (gResetRequired
) {
584 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
588 mFormDisplay
->ExitDisplay();
591 // Clear the menu history data.
593 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
594 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
595 RemoveEntryList (&MenuList
->Link
);
600 // Restore globals used by SendForm()
602 RestoreBrowserContext ();
608 Get or set data to the storage.
610 @param ResultsDataSize The size of the buffer associatedwith ResultsData.
611 @param ResultsData A string returned from an IFR browser or
612 equivalent. The results string will have no
613 routing information in them.
614 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
615 (if RetrieveData = TRUE) data from the uncommitted
616 browser state information or set (if RetrieveData
617 = FALSE) data in the uncommitted browser state
619 @param Storage The pointer to the storage.
621 @retval EFI_SUCCESS The results have been distributed or are awaiting
627 IN OUT UINTN
*ResultsDataSize
,
628 IN OUT EFI_STRING
*ResultsData
,
629 IN BOOLEAN RetrieveData
,
630 IN BROWSER_STORAGE
*Storage
638 FORMSET_STORAGE
*BrowserStorage
;
642 // Generate <ConfigResp>
644 Status
= StorageToConfigResp (Storage
, &ConfigResp
, Storage
->ConfigRequest
, TRUE
);
645 if (EFI_ERROR (Status
)) {
650 // Skip <ConfigHdr> and '&' to point to <ConfigBody> when first copy the configbody.
651 // Also need to consider add "\0" at first time.
653 StrPtr
= StrStr (ConfigResp
, L
"PATH");
654 ASSERT (StrPtr
!= NULL
);
655 StrPtr
= StrStr (StrPtr
, L
"&");
657 BufferSize
= StrSize (StrPtr
);
660 // Copy the data if the input buffer is bigger enough.
662 if (*ResultsDataSize
>= BufferSize
) {
663 StrCpy (*ResultsData
, StrPtr
);
666 *ResultsDataSize
= BufferSize
;
667 FreePool (ConfigResp
);
670 // Prepare <ConfigResp>
672 BrowserStorage
= GetFstStgFromBrsStg (Storage
);
673 ASSERT (BrowserStorage
!= NULL
);
674 TmpSize
= StrLen (*ResultsData
);
675 BufferSize
= (TmpSize
+ StrLen (BrowserStorage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
676 ConfigResp
= AllocateZeroPool (BufferSize
);
677 ASSERT (ConfigResp
!= NULL
);
679 StrCpy (ConfigResp
, BrowserStorage
->ConfigHdr
);
680 StrCat (ConfigResp
, L
"&");
681 StrCat (ConfigResp
, *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 TmpSize
= StrSize (*Dest
);
1090 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
1091 ASSERT (NewString
!= NULL
);
1093 StrCpy (NewString
, *Dest
);
1094 StrCat (NewString
, 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 StrnCpy (TemStr
, 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
;
1509 Status
= EFI_SUCCESS
;
1513 if (GetValueFrom
>= GetSetValueWithMax
) {
1514 return EFI_INVALID_PARAMETER
;
1518 // Question value is provided by an Expression, evaluate it
1520 if (Question
->ValueExpression
!= NULL
) {
1521 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1522 if (!EFI_ERROR (Status
)) {
1523 if (Question
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1524 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1525 if (Question
->StorageWidth
> Question
->ValueExpression
->Result
.BufferLen
) {
1526 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->ValueExpression
->Result
.BufferLen
);
1527 Question
->HiiValue
.BufferLen
= Question
->ValueExpression
->Result
.BufferLen
;
1529 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
1530 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1532 FreePool (Question
->ValueExpression
->Result
.Buffer
);
1534 Question
->HiiValue
.Type
= Question
->ValueExpression
->Result
.Type
;
1535 CopyMem (&Question
->HiiValue
.Value
, &Question
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1541 // Get question value by read expression.
1543 if (Question
->ReadExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1544 Status
= EvaluateExpression (FormSet
, Form
, Question
->ReadExpression
);
1545 if (!EFI_ERROR (Status
) &&
1546 ((Question
->ReadExpression
->Result
.Type
< EFI_IFR_TYPE_OTHER
) || (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
))) {
1548 // Only update question value to the valid result.
1550 if (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1551 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1552 if (Question
->StorageWidth
> Question
->ReadExpression
->Result
.BufferLen
) {
1553 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->ReadExpression
->Result
.BufferLen
);
1554 Question
->HiiValue
.BufferLen
= Question
->ReadExpression
->Result
.BufferLen
;
1556 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->StorageWidth
);
1557 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1559 FreePool (Question
->ReadExpression
->Result
.Buffer
);
1561 Question
->HiiValue
.Type
= Question
->ReadExpression
->Result
.Type
;
1562 CopyMem (&Question
->HiiValue
.Value
, &Question
->ReadExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1568 // Question value is provided by RTC
1570 Storage
= Question
->Storage
;
1571 QuestionValue
= &Question
->HiiValue
.Value
;
1572 if (Storage
== NULL
) {
1574 // It's a Question without storage, or RTC date/time
1576 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1578 // Date and time define the same Flags bit
1580 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1581 case QF_DATE_STORAGE_TIME
:
1582 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1585 case QF_DATE_STORAGE_WAKEUP
:
1586 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1589 case QF_DATE_STORAGE_NORMAL
:
1592 // For date/time without storage
1597 if (EFI_ERROR (Status
)) {
1598 if (Question
->Operand
== EFI_IFR_DATE_OP
){
1599 QuestionValue
->date
.Year
= 0xff;
1600 QuestionValue
->date
.Month
= 0xff;
1601 QuestionValue
->date
.Day
= 0xff;
1603 QuestionValue
->time
.Hour
= 0xff;
1604 QuestionValue
->time
.Minute
= 0xff;
1605 QuestionValue
->time
.Second
= 0xff;
1610 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1611 QuestionValue
->date
.Year
= EfiTime
.Year
;
1612 QuestionValue
->date
.Month
= EfiTime
.Month
;
1613 QuestionValue
->date
.Day
= EfiTime
.Day
;
1615 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1616 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1617 QuestionValue
->time
.Second
= EfiTime
.Second
;
1625 // Question value is provided by EFI variable
1627 StorageWidth
= Question
->StorageWidth
;
1628 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1629 if (Question
->BufferValue
!= NULL
) {
1630 Dst
= Question
->BufferValue
;
1632 Dst
= (UINT8
*) QuestionValue
;
1635 Status
= gRT
->GetVariable (
1636 Question
->VariableName
,
1643 // Always return success, even this EFI variable doesn't exist
1649 // Question Value is provided by Buffer Storage or NameValue Storage
1651 if (Question
->BufferValue
!= NULL
) {
1653 // This Question is password or orderedlist
1655 Dst
= Question
->BufferValue
;
1658 // Other type of Questions
1660 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1663 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1664 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1665 IsBufferStorage
= TRUE
;
1667 IsBufferStorage
= FALSE
;
1669 if (GetValueFrom
== GetSetValueWithEditBuffer
|| GetValueFrom
== GetSetValueWithBuffer
) {
1670 if (IsBufferStorage
) {
1671 if (GetValueFrom
== GetSetValueWithEditBuffer
) {
1673 // Copy from storage Edit buffer
1675 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1678 // Copy from storage Edit buffer
1680 CopyMem (Dst
, Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1684 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
, GetValueFrom
);
1685 if (EFI_ERROR (Status
)) {
1689 ASSERT (Value
!= NULL
);
1690 Status
= BufferToValue (Question
, Value
);
1694 FormsetStorage
= GetFstStgFromVarId(FormSet
, Question
->VarStoreId
);
1695 ASSERT (FormsetStorage
!= NULL
);
1697 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1698 // <ConfigHdr> + "&" + <VariableName>
1700 if (IsBufferStorage
) {
1701 Length
= StrLen (FormsetStorage
->ConfigHdr
);
1702 Length
+= StrLen (Question
->BlockName
);
1704 Length
= StrLen (FormsetStorage
->ConfigHdr
);
1705 Length
+= StrLen (Question
->VariableName
) + 1;
1707 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1708 ASSERT (ConfigRequest
!= NULL
);
1710 StrCpy (ConfigRequest
, FormsetStorage
->ConfigHdr
);
1711 if (IsBufferStorage
) {
1712 StrCat (ConfigRequest
, Question
->BlockName
);
1714 StrCat (ConfigRequest
, L
"&");
1715 StrCat (ConfigRequest
, Question
->VariableName
);
1719 // Request current settings from Configuration Driver
1721 Status
= mHiiConfigRouting
->ExtractConfig (
1727 FreePool (ConfigRequest
);
1728 if (EFI_ERROR (Status
)) {
1733 // Skip <ConfigRequest>
1735 if (IsBufferStorage
) {
1736 Value
= StrStr (Result
, L
"&VALUE");
1737 if (Value
== NULL
) {
1739 return EFI_NOT_FOUND
;
1746 Value
= Result
+ Length
;
1748 if (*Value
!= '=') {
1750 return EFI_NOT_FOUND
;
1753 // Skip '=', point to value
1757 Status
= BufferToValue (Question
, Value
);
1758 if (EFI_ERROR (Status
)) {
1764 // Synchronize Edit Buffer
1766 if (IsBufferStorage
) {
1767 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1769 SetValueByName (Storage
, Question
->VariableName
, Value
, GetSetValueWithEditBuffer
, NULL
);
1772 if (Result
!= NULL
) {
1782 Save Question Value to edit copy(cached) or Storage(uncached).
1784 @param FormSet FormSet data structure.
1785 @param Form Form data structure.
1786 @param Question Pointer to the Question.
1787 @param SetValueTo Update the question value to editbuffer , buffer or hii driver.
1789 @retval EFI_SUCCESS The function completed successfully.
1794 IN FORM_BROWSER_FORMSET
*FormSet
,
1795 IN FORM_BROWSER_FORM
*Form
,
1796 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1797 IN GET_SET_QUESTION_VALUE_WITH SetValueTo
1807 BROWSER_STORAGE
*Storage
;
1808 FORMSET_STORAGE
*FormsetStorage
;
1809 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1814 BOOLEAN IsBufferStorage
;
1820 NAME_VALUE_NODE
*Node
;
1822 Status
= EFI_SUCCESS
;
1825 if (SetValueTo
>= GetSetValueWithMax
) {
1826 return EFI_INVALID_PARAMETER
;
1830 // If Question value is provided by an Expression, then it is read only
1832 if (Question
->ValueExpression
!= NULL
) {
1837 // Before set question value, evaluate its write expression.
1839 if (Question
->WriteExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1840 Status
= EvaluateExpression (FormSet
, Form
, Question
->WriteExpression
);
1841 if (EFI_ERROR (Status
)) {
1847 // Question value is provided by RTC
1849 Storage
= Question
->Storage
;
1850 QuestionValue
= &Question
->HiiValue
.Value
;
1851 if (Storage
== NULL
) {
1853 // It's a Question without storage, or RTC date/time
1855 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1857 // Date and time define the same Flags bit
1859 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1860 case QF_DATE_STORAGE_TIME
:
1861 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1864 case QF_DATE_STORAGE_WAKEUP
:
1865 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1868 case QF_DATE_STORAGE_NORMAL
:
1871 // For date/time without storage
1876 if (EFI_ERROR (Status
)) {
1880 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1881 EfiTime
.Year
= QuestionValue
->date
.Year
;
1882 EfiTime
.Month
= QuestionValue
->date
.Month
;
1883 EfiTime
.Day
= QuestionValue
->date
.Day
;
1885 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1886 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1887 EfiTime
.Second
= QuestionValue
->time
.Second
;
1890 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1891 Status
= gRT
->SetTime (&EfiTime
);
1893 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1901 // Question value is provided by EFI variable
1903 StorageWidth
= Question
->StorageWidth
;
1904 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1905 if (Question
->BufferValue
!= NULL
) {
1906 Src
= Question
->BufferValue
;
1908 Src
= (UINT8
*) QuestionValue
;
1911 Status
= gRT
->SetVariable (
1912 Question
->VariableName
,
1914 Storage
->Attributes
,
1922 // Question Value is provided by Buffer Storage or NameValue Storage
1924 if (Question
->BufferValue
!= NULL
) {
1925 Src
= Question
->BufferValue
;
1927 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1930 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1931 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1932 IsBufferStorage
= TRUE
;
1934 IsBufferStorage
= FALSE
;
1936 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1938 if (SetValueTo
== GetSetValueWithEditBuffer
|| SetValueTo
== GetSetValueWithBuffer
) {
1939 if (IsBufferStorage
) {
1940 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1942 // Copy to storage edit buffer
1944 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1945 } else if (SetValueTo
== GetSetValueWithBuffer
) {
1947 // Copy to storage edit buffer
1949 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1954 // Allocate enough string buffer.
1957 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1958 Value
= AllocateZeroPool (BufferLen
);
1959 ASSERT (Value
!= NULL
);
1961 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1963 TemName
= (CHAR16
*) Src
;
1965 for (; *TemName
!= L
'\0'; TemName
++) {
1966 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1969 BufferLen
= StorageWidth
* 2 + 1;
1970 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1971 ASSERT (Value
!= NULL
);
1973 // Convert Buffer to Hex String
1975 TemBuffer
= Src
+ StorageWidth
- 1;
1977 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1978 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1982 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
, SetValueTo
, &Node
);
1984 if (EFI_ERROR (Status
)) {
1988 } else if (SetValueTo
== GetSetValueWithHiiDriver
) {
1990 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1991 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1993 if (IsBufferStorage
) {
1994 Length
= StrLen (Question
->BlockName
) + 7;
1996 Length
= StrLen (Question
->VariableName
) + 2;
1998 if (!IsBufferStorage
&& IsString
) {
1999 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
2001 Length
+= (StorageWidth
* 2);
2003 FormsetStorage
= GetFstStgFromVarId(FormSet
, Question
->VarStoreId
);
2004 ASSERT (FormsetStorage
!= NULL
);
2005 ConfigResp
= AllocateZeroPool ((StrLen (FormsetStorage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
2006 ASSERT (ConfigResp
!= NULL
);
2008 StrCpy (ConfigResp
, FormsetStorage
->ConfigHdr
);
2009 if (IsBufferStorage
) {
2010 StrCat (ConfigResp
, Question
->BlockName
);
2011 StrCat (ConfigResp
, L
"&VALUE=");
2013 StrCat (ConfigResp
, L
"&");
2014 StrCat (ConfigResp
, Question
->VariableName
);
2015 StrCat (ConfigResp
, L
"=");
2018 Value
= ConfigResp
+ StrLen (ConfigResp
);
2020 if (!IsBufferStorage
&& IsString
) {
2022 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
2024 TemName
= (CHAR16
*) Src
;
2026 for (; *TemName
!= L
'\0'; TemName
++) {
2027 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
2031 // Convert Buffer to Hex String
2033 TemBuffer
= Src
+ StorageWidth
- 1;
2035 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
2036 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
2041 // Convert to lower char.
2043 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
2044 if (*Value
>= L
'A' && *Value
<= L
'Z') {
2045 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
2050 // Submit Question Value to Configuration Driver
2052 Status
= mHiiConfigRouting
->RouteConfig (
2057 if (EFI_ERROR (Status
)) {
2058 FreePool (ConfigResp
);
2061 FreePool (ConfigResp
);
2064 // Sync storage, from editbuffer to buffer.
2066 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
2074 Perform nosubmitif check for a Form.
2076 @param FormSet FormSet data structure.
2077 @param Form Form data structure.
2078 @param Question The Question to be validated.
2079 @param Type Validation type: NoSubmit
2081 @retval EFI_SUCCESS Form validation pass.
2082 @retval other Form validation failed.
2087 IN FORM_BROWSER_FORMSET
*FormSet
,
2088 IN FORM_BROWSER_FORM
*Form
,
2089 IN FORM_BROWSER_STATEMENT
*Question
,
2095 LIST_ENTRY
*ListHead
;
2096 FORM_EXPRESSION
*Expression
;
2097 UINT32 BrowserStatus
;
2100 BrowserStatus
= BROWSER_SUCCESS
;
2104 case EFI_HII_EXPRESSION_INCONSISTENT_IF
:
2105 ListHead
= &Question
->InconsistentListHead
;
2108 case EFI_HII_EXPRESSION_WARNING_IF
:
2109 ListHead
= &Question
->WarningListHead
;
2112 case EFI_HII_EXPRESSION_NO_SUBMIT_IF
:
2113 ListHead
= &Question
->NoSubmitListHead
;
2118 return EFI_UNSUPPORTED
;
2121 Link
= GetFirstNode (ListHead
);
2122 while (!IsNull (ListHead
, Link
)) {
2123 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
2126 // Evaluate the expression
2128 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
2129 if (EFI_ERROR (Status
)) {
2133 if (IsTrue (&Expression
->Result
)) {
2135 case EFI_HII_EXPRESSION_INCONSISTENT_IF
:
2136 BrowserStatus
= BROWSER_INCONSISTENT_IF
;
2139 case EFI_HII_EXPRESSION_WARNING_IF
:
2140 BrowserStatus
= BROWSER_WARNING_IF
;
2143 case EFI_HII_EXPRESSION_NO_SUBMIT_IF
:
2144 BrowserStatus
= BROWSER_NO_SUBMIT_IF
;
2146 // This code only used to compatible with old display engine,
2147 // New display engine will not use this field.
2149 if (Expression
->Error
!= 0) {
2150 ErrorStr
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
2159 if (!((Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) && mSystemSubmit
)) {
2161 // If in system submit process and for no_submit_if check, not popup this error message.
2162 // Will process this fail again later in not system submit process.
2164 PopupErrorMessage(BrowserStatus
, FormSet
->HiiHandle
, Expression
->OpCode
, ErrorStr
);
2167 if (ErrorStr
!= NULL
) {
2168 FreePool (ErrorStr
);
2171 if (Type
== EFI_HII_EXPRESSION_WARNING_IF
) {
2174 return EFI_NOT_READY
;
2178 Link
= GetNextNode (ListHead
, Link
);
2185 Perform question check.
2187 If one question has more than one check, process form high priority to low.
2188 Only one error info will be popup.
2190 @param FormSet FormSet data structure.
2191 @param Form Form data structure.
2192 @param Question The Question to be validated.
2194 @retval EFI_SUCCESS Form validation pass.
2195 @retval other Form validation failed.
2199 ValueChangedValidation (
2200 IN FORM_BROWSER_FORMSET
*FormSet
,
2201 IN FORM_BROWSER_FORM
*Form
,
2202 IN FORM_BROWSER_STATEMENT
*Question
2207 Status
= EFI_SUCCESS
;
2210 // Do the inconsistentif check.
2212 if (!IsListEmpty (&Question
->InconsistentListHead
)) {
2213 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_INCONSISTENT_IF
);
2214 if (EFI_ERROR (Status
)) {
2220 // Do the warningif check.
2222 if (!IsListEmpty (&Question
->WarningListHead
)) {
2223 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_WARNING_IF
);
2230 Perform NoSubmit check for each Form in FormSet.
2232 @param FormSet FormSet data structure.
2233 @param CurrentForm Current input form data structure.
2234 @param Statement The statement for this check.
2236 @retval EFI_SUCCESS Form validation pass.
2237 @retval other Form validation failed.
2242 IN FORM_BROWSER_FORMSET
*FormSet
,
2243 IN OUT FORM_BROWSER_FORM
**CurrentForm
,
2244 OUT FORM_BROWSER_STATEMENT
**Statement
2249 FORM_BROWSER_STATEMENT
*Question
;
2250 FORM_BROWSER_FORM
*Form
;
2251 LIST_ENTRY
*LinkForm
;
2253 LinkForm
= GetFirstNode (&FormSet
->FormListHead
);
2254 while (!IsNull (&FormSet
->FormListHead
, LinkForm
)) {
2255 Form
= FORM_BROWSER_FORM_FROM_LINK (LinkForm
);
2256 LinkForm
= GetNextNode (&FormSet
->FormListHead
, LinkForm
);
2258 if (*CurrentForm
!= NULL
&& *CurrentForm
!= Form
) {
2262 Link
= GetFirstNode (&Form
->StatementListHead
);
2263 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2264 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2265 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
2266 if (EFI_ERROR (Status
)) {
2267 if (*CurrentForm
== NULL
) {
2268 *CurrentForm
= Form
;
2270 if (Statement
!= NULL
) {
2271 *Statement
= Question
;
2276 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2284 Fill storage's edit copy with settings requested from Configuration Driver.
2286 @param Storage The storage which need to sync.
2287 @param ConfigRequest The config request string which used to sync storage.
2288 @param SyncOrRestore Sync the buffer to editbuffer or Restore the
2289 editbuffer to buffer
2290 if TRUE, copy the editbuffer to the buffer.
2291 if FALSE, copy the buffer to the editbuffer.
2293 @retval EFI_SUCCESS The function completed successfully.
2297 SynchronizeStorage (
2298 OUT BROWSER_STORAGE
*Storage
,
2299 IN CHAR16
*ConfigRequest
,
2300 IN BOOLEAN SyncOrRestore
2304 EFI_STRING Progress
;
2308 NAME_VALUE_NODE
*Node
;
2312 Status
= EFI_SUCCESS
;
2315 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
2316 (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
2317 BufferSize
= Storage
->Size
;
2319 if (SyncOrRestore
) {
2320 Src
= Storage
->EditBuffer
;
2321 Dst
= Storage
->Buffer
;
2323 Src
= Storage
->Buffer
;
2324 Dst
= Storage
->EditBuffer
;
2327 if (ConfigRequest
!= NULL
) {
2328 Status
= mHiiConfigRouting
->BlockToConfig(
2336 if (EFI_ERROR (Status
)) {
2340 Status
= mHiiConfigRouting
->ConfigToBlock (
2347 if (Result
!= NULL
) {
2351 CopyMem (Dst
, Src
, BufferSize
);
2353 } else if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2354 Link
= GetFirstNode (&Storage
->NameValueListHead
);
2355 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
2356 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
2358 if ((ConfigRequest
!= NULL
&& StrStr (ConfigRequest
, Node
->Name
) != NULL
) ||
2359 (ConfigRequest
== NULL
)) {
2360 if (SyncOrRestore
) {
2361 NewStringCpy (&Node
->Value
, Node
->EditValue
);
2363 NewStringCpy (&Node
->EditValue
, Node
->Value
);
2367 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
2375 When discard the question value, call the callback function with Changed type
2376 to inform the hii driver.
2378 @param FormSet FormSet data structure.
2379 @param Form Form data structure.
2383 SendDiscardInfoToDriver (
2384 IN FORM_BROWSER_FORMSET
*FormSet
,
2385 IN FORM_BROWSER_FORM
*Form
2389 FORM_BROWSER_STATEMENT
*Question
;
2390 EFI_IFR_TYPE_VALUE
*TypeValue
;
2391 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
2393 if (FormSet
->ConfigAccess
== NULL
) {
2397 Link
= GetFirstNode (&Form
->StatementListHead
);
2398 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2399 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2400 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2402 if (Question
->Storage
== NULL
|| Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2406 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != EFI_IFR_FLAG_CALLBACK
) {
2410 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
) {
2414 if (!Question
->ValueChanged
) {
2419 // Restore the question value before call the CHANGED callback type.
2421 GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
2423 if (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
) {
2424 TypeValue
= (EFI_IFR_TYPE_VALUE
*) Question
->BufferValue
;
2426 TypeValue
= &Question
->HiiValue
.Value
;
2429 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
2430 FormSet
->ConfigAccess
->Callback (
2431 FormSet
->ConfigAccess
,
2432 EFI_BROWSER_ACTION_CHANGED
,
2433 Question
->QuestionId
,
2434 Question
->HiiValue
.Type
,
2442 Validate the HiiHandle.
2444 @param HiiHandle The input HiiHandle which need to validate.
2446 @retval TRUE The handle is validate.
2447 @retval FALSE The handle is invalidate.
2452 EFI_HII_HANDLE HiiHandle
2455 EFI_HII_HANDLE
*HiiHandles
;
2459 if (HiiHandle
== NULL
) {
2465 HiiHandles
= HiiGetHiiHandles (NULL
);
2466 ASSERT (HiiHandles
!= NULL
);
2468 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
2469 if (HiiHandles
[Index
] == HiiHandle
) {
2475 FreePool (HiiHandles
);
2481 Validate the FormSet. If the formset is not validate, remove it from the list.
2483 @param FormSet The input FormSet which need to validate.
2485 @retval TRUE The handle is validate.
2486 @retval FALSE The handle is invalidate.
2491 FORM_BROWSER_FORMSET
*FormSet
2496 ASSERT (FormSet
!= NULL
);
2498 Find
= ValidateHiiHandle(FormSet
->HiiHandle
);
2500 // Should not remove the formset which is being used.
2502 if (!Find
&& (FormSet
!= gCurrentSelection
->FormSet
)) {
2503 CleanBrowserStorage(FormSet
);
2504 RemoveEntryList (&FormSet
->Link
);
2505 DestroyFormSet (FormSet
);
2511 Check whether need to enable the reset flag in form level.
2512 Also clean all ValueChanged flag in question.
2514 @param SetFlag Whether need to set the Reset Flag.
2515 @param FormSet FormSet data structure.
2516 @param Form Form data structure.
2522 IN FORM_BROWSER_FORMSET
*FormSet
,
2523 IN FORM_BROWSER_FORM
*Form
2527 FORM_BROWSER_STATEMENT
*Question
;
2530 Link
= GetFirstNode (&Form
->StatementListHead
);
2531 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2532 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2533 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2535 if (!Question
->ValueChanged
) {
2539 OldValue
= Question
->ValueChanged
;
2542 // Compare the buffer and editbuffer data to see whether the data has been saved.
2544 Question
->ValueChanged
= IsQuestionValueChanged(FormSet
, Form
, Question
, GetSetValueWithBothBuffer
);
2547 // Only the changed data has been saved, then need to set the reset flag.
2549 if (SetFlag
&& OldValue
&& !Question
->ValueChanged
) {
2550 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_RESET_REQUIRED
) != 0) {
2551 gResetRequired
= TRUE
;
2554 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_RECONNECT_REQUIRED
) != 0) {
2555 gFlagReconnect
= TRUE
;
2562 Check whether need to enable the reset flag.
2563 Also clean ValueChanged flag for all statements.
2565 Form level or formset level, only one.
2567 @param SetFlag Whether need to set the Reset Flag.
2568 @param FormSet FormSet data structure.
2569 @param Form Form data structure.
2573 ValueChangeResetFlagUpdate (
2575 IN FORM_BROWSER_FORMSET
*FormSet
,
2576 IN FORM_BROWSER_FORM
*Form
2579 FORM_BROWSER_FORM
*CurrentForm
;
2583 UpdateFlagForForm(SetFlag
, FormSet
, Form
);
2587 Link
= GetFirstNode (&FormSet
->FormListHead
);
2588 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2589 CurrentForm
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2590 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2592 UpdateFlagForForm(SetFlag
, FormSet
, CurrentForm
);
2597 Base on the return Progress string to find the form.
2599 Base on the first return Offset/Width (Name) string to find the form
2600 which keep this string.
2602 @param FormSet FormSet data structure.
2603 @param Storage Storage which has this Progress string.
2604 @param Progress The Progress string which has the first fail string.
2605 @param RetForm The return form for this progress string.
2606 @param RetQuestion The return question for the error progress string.
2608 @retval TRUE Find the error form and statement for this error progress string.
2609 @retval FALSE Not find the error form.
2613 FindQuestionFromProgress (
2614 IN FORM_BROWSER_FORMSET
*FormSet
,
2615 IN BROWSER_STORAGE
*Storage
,
2616 IN EFI_STRING Progress
,
2617 OUT FORM_BROWSER_FORM
**RetForm
,
2618 OUT FORM_BROWSER_STATEMENT
**RetQuestion
2622 LIST_ENTRY
*LinkStorage
;
2623 LIST_ENTRY
*LinkStatement
;
2624 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2625 FORM_BROWSER_FORM
*Form
;
2627 FORM_BROWSER_STATEMENT
*Statement
;
2629 ASSERT ((*Progress
== '&') || (*Progress
== 'G'));
2633 *RetQuestion
= NULL
;
2636 // Skip the first "&" or the ConfigHdr part.
2638 if (*Progress
== '&') {
2642 // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string.
2644 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2646 // For Name/Value type, Skip the ConfigHdr part.
2648 EndStr
= StrStr (Progress
, L
"PATH=");
2649 ASSERT (EndStr
!= NULL
);
2650 while (*EndStr
!= '&') {
2657 // For Buffer type, Skip the ConfigHdr part.
2659 EndStr
= StrStr (Progress
, L
"&OFFSET=");
2660 ASSERT (EndStr
!= NULL
);
2664 Progress
= EndStr
+ 1;
2668 // Prepare the "NAME" or "OFFSET=0x####&WIDTH=0x####" string.
2670 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2672 // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset,
2673 // here, just keep the "Fred" string.
2675 EndStr
= StrStr (Progress
, L
"=");
2676 ASSERT (EndStr
!= NULL
);
2680 // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####",
2681 // here, just keep the "OFFSET=0x####&WIDTH=0x####" string.
2683 EndStr
= StrStr (Progress
, L
"&VALUE=");
2684 ASSERT (EndStr
!= NULL
);
2689 // Search in the form list.
2691 Link
= GetFirstNode (&FormSet
->FormListHead
);
2692 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2693 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2694 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2697 // Search in the ConfigReqeust list in this form.
2699 LinkStorage
= GetFirstNode (&Form
->ConfigRequestHead
);
2700 while (!IsNull (&Form
->ConfigRequestHead
, LinkStorage
)) {
2701 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (LinkStorage
);
2702 LinkStorage
= GetNextNode (&Form
->ConfigRequestHead
, LinkStorage
);
2704 if (Storage
!= ConfigInfo
->Storage
) {
2708 if (StrStr (ConfigInfo
->ConfigRequest
, Progress
) != NULL
) {
2710 // Find the OffsetWidth string in this form.
2717 if (*RetForm
!= NULL
) {
2718 LinkStatement
= GetFirstNode (&Form
->StatementListHead
);
2719 while (!IsNull (&Form
->StatementListHead
, LinkStatement
)) {
2720 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (LinkStatement
);
2721 LinkStatement
= GetNextNode (&Form
->StatementListHead
, LinkStatement
);
2723 if (Statement
->BlockName
!= NULL
&& StrStr (Statement
->BlockName
, Progress
) != NULL
) {
2724 *RetQuestion
= Statement
;
2728 if (Statement
->VariableName
!= NULL
&& StrStr (Statement
->VariableName
, Progress
) != NULL
) {
2729 *RetQuestion
= Statement
;
2735 if (*RetForm
!= NULL
) {
2741 // restore the OffsetWidth string to the original format.
2743 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2749 return (BOOLEAN
) (*RetForm
!= NULL
);
2753 Popup an save error info and get user input.
2755 @param TitleId The form title id.
2756 @param HiiHandle The hii handle for this package.
2758 @retval UINT32 The user select option for the save fail.
2759 BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET
2763 IN EFI_STRING_ID TitleId
,
2764 IN EFI_HII_HANDLE HiiHandle
2768 CHAR16
*StringBuffer
;
2771 FormTitle
= GetToken (TitleId
, HiiHandle
);
2773 StringBuffer
= AllocateZeroPool (256 * sizeof (CHAR16
));
2774 ASSERT (StringBuffer
!= NULL
);
2778 24 * sizeof (CHAR16
) + StrSize (FormTitle
),
2779 L
"Submit Fail For Form: %s.",
2783 RetVal
= PopupErrorMessage(BROWSER_SUBMIT_FAIL
, NULL
, NULL
, StringBuffer
);
2785 FreePool (StringBuffer
);
2786 FreePool (FormTitle
);
2792 Popup an NO_SUBMIT_IF error info and get user input.
2794 @param TitleId The form title id.
2795 @param HiiHandle The hii handle for this package.
2797 @retval UINT32 The user select option for the save fail.
2798 BROWSER_ACTION_DISCARD or BROWSER_ACTION_JUMP_TO_FORMSET
2801 ConfirmNoSubmitFail (
2802 IN EFI_STRING_ID TitleId
,
2803 IN EFI_HII_HANDLE HiiHandle
2807 CHAR16
*StringBuffer
;
2810 FormTitle
= GetToken (TitleId
, HiiHandle
);
2812 StringBuffer
= AllocateZeroPool (256 * sizeof (CHAR16
));
2813 ASSERT (StringBuffer
!= NULL
);
2817 24 * sizeof (CHAR16
) + StrSize (FormTitle
),
2818 L
"NO_SUBMIT_IF error For Form: %s.",
2822 RetVal
= PopupErrorMessage(BROWSER_SUBMIT_FAIL_NO_SUBMIT_IF
, NULL
, NULL
, StringBuffer
);
2824 FreePool (StringBuffer
);
2825 FreePool (FormTitle
);
2831 Discard data based on the input setting scope (Form, FormSet or System).
2833 @param FormSet FormSet data structure.
2834 @param Form Form data structure.
2835 @param SettingScope Setting Scope for Discard action.
2837 @retval EFI_SUCCESS The function completed successfully.
2838 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2843 IN FORM_BROWSER_FORMSET
*FormSet
,
2844 IN FORM_BROWSER_FORM
*Form
,
2845 IN BROWSER_SETTING_SCOPE SettingScope
2849 FORMSET_STORAGE
*Storage
;
2850 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2851 FORM_BROWSER_FORMSET
*LocalFormSet
;
2852 FORM_BROWSER_FORMSET
*OldFormSet
;
2855 // Check the supported setting level.
2857 if (SettingScope
>= MaxLevel
) {
2858 return EFI_UNSUPPORTED
;
2861 if (SettingScope
== FormLevel
&& IsNvUpdateRequiredForForm (Form
)) {
2863 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
2864 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
2865 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
2866 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
2868 if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2873 // Skip if there is no RequestElement
2875 if (ConfigInfo
->ElementCount
== 0) {
2880 // Prepare <ConfigResp>
2882 SynchronizeStorage(ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, FALSE
);
2885 // Call callback with Changed type to inform the driver.
2887 SendDiscardInfoToDriver (FormSet
, Form
);
2890 ValueChangeResetFlagUpdate (FALSE
, FormSet
, Form
);
2891 } else if (SettingScope
== FormSetLevel
&& IsNvUpdateRequiredForFormSet (FormSet
)) {
2894 // Discard Buffer storage or Name/Value storage
2896 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2897 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2898 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2899 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2901 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2906 // Skip if there is no RequestElement
2908 if (Storage
->ElementCount
== 0) {
2912 SynchronizeStorage(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
2915 Link
= GetFirstNode (&FormSet
->FormListHead
);
2916 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2917 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2918 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2921 // Call callback with Changed type to inform the driver.
2923 SendDiscardInfoToDriver (FormSet
, Form
);
2926 ValueChangeResetFlagUpdate(FALSE
, FormSet
, NULL
);
2927 } else if (SettingScope
== SystemLevel
) {
2929 // System Level Discard.
2931 OldFormSet
= mSystemLevelFormSet
;
2934 // Discard changed value for each FormSet in the maintain list.
2936 Link
= GetFirstNode (&gBrowserFormSetList
);
2937 while (!IsNull (&gBrowserFormSetList
, Link
)) {
2938 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
2939 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
2940 if (!ValidateFormSet(LocalFormSet
)) {
2944 mSystemLevelFormSet
= LocalFormSet
;
2946 DiscardForm (LocalFormSet
, NULL
, FormSetLevel
);
2947 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
2949 // Remove maintain backup list after discard except for the current using FormSet.
2951 CleanBrowserStorage(LocalFormSet
);
2952 RemoveEntryList (&LocalFormSet
->Link
);
2953 DestroyFormSet (LocalFormSet
);
2957 mSystemLevelFormSet
= OldFormSet
;
2964 Submit data for a form.
2966 @param FormSet FormSet data structure.
2967 @param Form Form data structure.
2969 @retval EFI_SUCCESS The function completed successfully.
2970 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2975 IN FORM_BROWSER_FORMSET
*FormSet
,
2976 IN FORM_BROWSER_FORM
*Form
2981 EFI_STRING ConfigResp
;
2982 EFI_STRING Progress
;
2983 BROWSER_STORAGE
*Storage
;
2984 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2986 if (!IsNvUpdateRequiredForForm (Form
)) {
2990 Status
= NoSubmitCheck (FormSet
, &Form
, NULL
);
2991 if (EFI_ERROR (Status
)) {
2995 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
2996 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
2997 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
2998 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
3000 Storage
= ConfigInfo
->Storage
;
3001 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
3006 // Skip if there is no RequestElement
3008 if (ConfigInfo
->ElementCount
== 0) {
3013 // 1. Prepare <ConfigResp>
3015 Status
= StorageToConfigResp (ConfigInfo
->Storage
, &ConfigResp
, ConfigInfo
->ConfigRequest
, TRUE
);
3016 if (EFI_ERROR (Status
)) {
3021 // 2. Set value to hii config routine protocol.
3023 Status
= mHiiConfigRouting
->RouteConfig (
3028 FreePool (ConfigResp
);
3030 if (EFI_ERROR (Status
)) {
3031 InsertTailList (&gBrowserSaveFailFormSetList
, &ConfigInfo
->SaveFailLink
);
3036 // 3. Config success, update storage shadow Buffer, only update the data belong to this form.
3038 SynchronizeStorage (ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, TRUE
);
3042 // 4. Process the save failed storage.
3044 if (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3045 if (ConfirmSaveFail (Form
->FormTitle
, FormSet
->HiiHandle
) == BROWSER_ACTION_DISCARD
) {
3046 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3047 while (!IsNull (&gBrowserSaveFailFormSetList
, Link
)) {
3048 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link
);
3049 Link
= GetNextNode (&gBrowserSaveFailFormSetList
, Link
);
3051 SynchronizeStorage(ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, FALSE
);
3053 Status
= EFI_SUCCESS
;
3056 Status
= EFI_UNSUPPORTED
;
3060 // Free Form save fail list.
3062 while (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3063 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3064 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link
);
3065 RemoveEntryList (&ConfigInfo
->SaveFailLink
);
3070 // 5. Update the NV flag.
3072 ValueChangeResetFlagUpdate(TRUE
, FormSet
, Form
);
3078 Submit data for a formset.
3080 @param FormSet FormSet data structure.
3081 @param SkipProcessFail Whether skip to process the save failed storage.
3082 If submit formset is called when do system level save,
3083 set this value to true and process the failed formset
3085 if submit formset is called when do formset level save,
3086 set the value to false and process the failed storage
3087 right after process all storages for this formset.
3089 @retval EFI_SUCCESS The function completed successfully.
3090 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3095 IN FORM_BROWSER_FORMSET
*FormSet
,
3096 IN BOOLEAN SkipProcessFail
3101 EFI_STRING ConfigResp
;
3102 EFI_STRING Progress
;
3103 BROWSER_STORAGE
*Storage
;
3104 FORMSET_STORAGE
*FormSetStorage
;
3105 FORM_BROWSER_FORM
*Form
;
3106 BOOLEAN HasInserted
;
3107 FORM_BROWSER_STATEMENT
*Question
;
3109 HasInserted
= FALSE
;
3111 if (!IsNvUpdateRequiredForFormSet (FormSet
)) {
3116 Status
= NoSubmitCheck (FormSet
, &Form
, &Question
);
3117 if (EFI_ERROR (Status
)) {
3118 if (SkipProcessFail
) {
3120 // Process NO_SUBMIT check first, so insert it at head.
3122 FormSet
->SaveFailForm
= Form
;
3123 FormSet
->SaveFailStatement
= Question
;
3124 InsertHeadList (&gBrowserSaveFailFormSetList
, &FormSet
->SaveFailLink
);
3133 // Submit Buffer storage or Name/Value storage
3135 Link
= GetFirstNode (&FormSet
->StorageListHead
);
3136 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
3137 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
3138 Storage
= FormSetStorage
->BrowserStorage
;
3139 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
3141 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
3146 // Skip if there is no RequestElement
3148 if (FormSetStorage
->ElementCount
== 0) {
3153 // 1. Prepare <ConfigResp>
3155 Status
= StorageToConfigResp (Storage
, &ConfigResp
, FormSetStorage
->ConfigRequest
, TRUE
);
3156 if (EFI_ERROR (Status
)) {
3161 // 2. Send <ConfigResp> to Routine config Protocol.
3163 Status
= mHiiConfigRouting
->RouteConfig (
3168 if (EFI_ERROR (Status
)) {
3169 InsertTailList (&FormSet
->SaveFailStorageListHead
, &FormSetStorage
->SaveFailLink
);
3172 // Call submit formset for system level, save the formset info
3173 // and process later.
3175 FindQuestionFromProgress(FormSet
, Storage
, Progress
, &Form
, &Question
);
3176 ASSERT (Form
!= NULL
&& Question
!= NULL
);
3177 FormSet
->SaveFailForm
= Form
;
3178 FormSet
->SaveFailStatement
= Question
;
3179 if (SkipProcessFail
) {
3180 InsertTailList (&gBrowserSaveFailFormSetList
, &FormSet
->SaveFailLink
);
3185 FreePool (ConfigResp
);
3189 FreePool (ConfigResp
);
3191 // 3. Config success, update storage shadow Buffer
3193 SynchronizeStorage (Storage
, FormSetStorage
->ConfigRequest
, TRUE
);
3197 // 4. Has save fail storage need to handle.
3200 if (!SkipProcessFail
) {
3202 // If not in system level, just handl the save failed storage here.
3204 if (ConfirmSaveFail (Form
->FormTitle
, FormSet
->HiiHandle
) == BROWSER_ACTION_DISCARD
) {
3205 Link
= GetFirstNode (&FormSet
->SaveFailStorageListHead
);
3206 while (!IsNull (&FormSet
->SaveFailStorageListHead
, Link
)) {
3207 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link
);
3208 Storage
= FormSetStorage
->BrowserStorage
;
3209 Link
= GetNextNode (&FormSet
->SaveFailStorageListHead
, Link
);
3211 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3213 Status
= EFI_SUCCESS
;
3216 UiCopyMenuList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &Form
->FormViewListHead
);
3218 gCurrentSelection
->Action
= UI_ACTION_REFRESH_FORMSET
;
3219 gCurrentSelection
->Handle
= FormSet
->HiiHandle
;
3220 CopyGuid (&gCurrentSelection
->FormSetGuid
, &FormSet
->Guid
);
3221 gCurrentSelection
->FormId
= Form
->FormId
;
3222 gCurrentSelection
->QuestionId
= Question
->QuestionId
;
3224 Status
= EFI_UNSUPPORTED
;
3228 // Free FormSet save fail list.
3230 while (!IsListEmpty (&FormSet
->SaveFailStorageListHead
)) {
3231 Link
= GetFirstNode (&FormSet
->SaveFailStorageListHead
);
3232 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link
);
3233 RemoveEntryList (&FormSetStorage
->SaveFailLink
);
3237 // If in system level, just return error and handle the failed formset later.
3239 Status
= EFI_UNSUPPORTED
;
3244 // 5. Update the NV flag.
3246 ValueChangeResetFlagUpdate(TRUE
, FormSet
, NULL
);
3252 Submit data for all formsets.
3254 @retval EFI_SUCCESS The function completed successfully.
3255 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3265 LIST_ENTRY
*StorageLink
;
3266 FORMSET_STORAGE
*FormSetStorage
;
3267 FORM_BROWSER_FORM
*Form
;
3268 FORM_BROWSER_FORMSET
*LocalFormSet
;
3269 UINT32 UserSelection
;
3270 FORM_BROWSER_STATEMENT
*Question
;
3272 mSystemSubmit
= TRUE
;
3273 Link
= GetFirstNode (&gBrowserFormSetList
);
3274 while (!IsNull (&gBrowserFormSetList
, Link
)) {
3275 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
3276 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
3277 if (!ValidateFormSet(LocalFormSet
)) {
3281 Status
= SubmitForFormSet (LocalFormSet
, TRUE
);
3282 if (EFI_ERROR (Status
)) {
3287 // Remove maintain backup list after save except for the current using FormSet.
3289 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
3290 CleanBrowserStorage(LocalFormSet
);
3291 RemoveEntryList (&LocalFormSet
->Link
);
3292 DestroyFormSet (LocalFormSet
);
3295 mSystemSubmit
= FALSE
;
3297 Status
= EFI_SUCCESS
;
3300 // Process the save failed formsets.
3302 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3303 while (!IsNull (&gBrowserSaveFailFormSetList
, Link
)) {
3304 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link
);
3305 Link
= GetNextNode (&gBrowserSaveFailFormSetList
, Link
);
3307 if (!ValidateFormSet(LocalFormSet
)) {
3311 Form
= LocalFormSet
->SaveFailForm
;
3312 Question
= LocalFormSet
->SaveFailStatement
;
3315 // Confirm with user, get user input.
3317 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3319 // NULL for SaveFailStorageListHead means error caused by NO_SUBMIT_IF check.
3321 UserSelection
= ConfirmNoSubmitFail (Form
->FormTitle
, LocalFormSet
->HiiHandle
);
3323 UserSelection
= ConfirmSaveFail (Form
->FormTitle
, LocalFormSet
->HiiHandle
);
3326 if (UserSelection
== BROWSER_ACTION_DISCARD
) {
3327 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3328 StorageLink
= GetFirstNode (&LocalFormSet
->StorageListHead
);
3329 while (!IsNull (&LocalFormSet
->StorageListHead
, StorageLink
)) {
3330 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (StorageLink
);
3331 StorageLink
= GetNextNode (&LocalFormSet
->StorageListHead
, StorageLink
);
3333 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3336 StorageLink
= GetFirstNode (&LocalFormSet
->SaveFailStorageListHead
);
3337 while (!IsNull (&LocalFormSet
->SaveFailStorageListHead
, StorageLink
)) {
3338 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink
);
3339 StorageLink
= GetNextNode (&LocalFormSet
->SaveFailStorageListHead
, StorageLink
);
3341 SynchronizeStorage(FormSetStorage
->BrowserStorage
, FormSetStorage
->ConfigRequest
, FALSE
);
3345 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
3346 CleanBrowserStorage(LocalFormSet
);
3347 RemoveEntryList (&LocalFormSet
->Link
);
3348 RemoveEntryList (&LocalFormSet
->SaveFailLink
);
3349 DestroyFormSet (LocalFormSet
);
3351 ValueChangeResetFlagUpdate(FALSE
, LocalFormSet
, NULL
);
3354 if (IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3355 NoSubmitCheck (LocalFormSet
, &Form
, &Question
);
3358 UiCopyMenuList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &Form
->FormViewListHead
);
3360 gCurrentSelection
->Action
= UI_ACTION_REFRESH_FORMSET
;
3361 gCurrentSelection
->Handle
= LocalFormSet
->HiiHandle
;
3362 CopyGuid (&gCurrentSelection
->FormSetGuid
, &LocalFormSet
->Guid
);
3363 gCurrentSelection
->FormId
= Form
->FormId
;
3364 gCurrentSelection
->QuestionId
= Question
->QuestionId
;
3366 Status
= EFI_UNSUPPORTED
;
3372 // Clean the list which will not process.
3374 while (!IsListEmpty (&gBrowserSaveFailFormSetList
)) {
3375 Link
= GetFirstNode (&gBrowserSaveFailFormSetList
);
3376 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_SAVE_FAIL_LINK (Link
);
3377 RemoveEntryList (&LocalFormSet
->SaveFailLink
);
3379 while (!IsListEmpty (&LocalFormSet
->SaveFailStorageListHead
)) {
3380 StorageLink
= GetFirstNode (&LocalFormSet
->SaveFailStorageListHead
);
3381 FormSetStorage
= FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink
);
3382 RemoveEntryList (&FormSetStorage
->SaveFailLink
);
3390 Submit data based on the input Setting level (Form, FormSet or System).
3392 @param FormSet FormSet data structure.
3393 @param Form Form data structure.
3394 @param SettingScope Setting Scope for Submit action.
3396 @retval EFI_SUCCESS The function completed successfully.
3397 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3402 IN FORM_BROWSER_FORMSET
*FormSet
,
3403 IN FORM_BROWSER_FORM
*Form
,
3404 IN BROWSER_SETTING_SCOPE SettingScope
3409 switch (SettingScope
) {
3411 Status
= SubmitForForm(FormSet
, Form
);
3415 Status
= SubmitForFormSet (FormSet
, FALSE
);
3419 Status
= SubmitForSystem ();
3423 Status
= EFI_UNSUPPORTED
;
3431 Converts the unicode character of the string from uppercase to lowercase.
3432 This is a internal function.
3434 @param ConfigString String to be converted
3440 IN EFI_STRING ConfigString
3446 ASSERT (ConfigString
!= NULL
);
3449 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
3451 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
3452 if (*String
== L
'=') {
3454 } else if (*String
== L
'&') {
3456 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
3457 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
3463 Find the point in the ConfigResp string for this question.
3465 @param Question The question.
3466 @param ConfigResp Get ConfigResp string.
3468 @retval point to the offset where is for this question.
3472 GetOffsetFromConfigResp (
3473 IN FORM_BROWSER_STATEMENT
*Question
,
3474 IN CHAR16
*ConfigResp
3477 CHAR16
*RequestElement
;
3481 // Type is EFI_HII_VARSTORE_NAME_VALUE.
3483 if (Question
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3484 RequestElement
= StrStr (ConfigResp
, Question
->VariableName
);
3485 if (RequestElement
!= NULL
) {
3487 // Skip the "VariableName=" field.
3489 RequestElement
+= StrLen (Question
->VariableName
) + 1;
3492 return RequestElement
;
3496 // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
3500 // 1. Directly use Question->BlockName to find.
3502 RequestElement
= StrStr (ConfigResp
, Question
->BlockName
);
3503 if (RequestElement
!= NULL
) {
3505 // Skip the "Question->BlockName&VALUE=" field.
3507 RequestElement
+= StrLen (Question
->BlockName
) + StrLen (L
"&VALUE=");
3508 return RequestElement
;
3512 // 2. Change all hex digits in Question->BlockName to lower and compare again.
3514 BlockData
= AllocateCopyPool (StrSize(Question
->BlockName
), Question
->BlockName
);
3515 ASSERT (BlockData
!= NULL
);
3516 HiiToLower (BlockData
);
3517 RequestElement
= StrStr (ConfigResp
, BlockData
);
3518 FreePool (BlockData
);
3520 if (RequestElement
!= NULL
) {
3522 // Skip the "Question->BlockName&VALUE=" field.
3524 RequestElement
+= StrLen (Question
->BlockName
) + StrLen (L
"&VALUE=");
3527 return RequestElement
;
3531 Get Question default value from AltCfg string.
3533 @param FormSet The form set.
3534 @param Form The form
3535 @param Question The question.
3537 @retval EFI_SUCCESS Question is reset to default value.
3541 GetDefaultValueFromAltCfg (
3542 IN FORM_BROWSER_FORMSET
*FormSet
,
3543 IN FORM_BROWSER_FORM
*Form
,
3544 IN OUT FORM_BROWSER_STATEMENT
*Question
3547 BROWSER_STORAGE
*Storage
;
3548 FORMSET_STORAGE
*FormSetStorage
;
3552 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
3554 Storage
= Question
->Storage
;
3555 if ((Storage
== NULL
) || (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
3556 return EFI_NOT_FOUND
;
3560 // Try to get AltCfg string from form. If not found it, then
3561 // try to get it from formset.
3564 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
3565 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
3566 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
3567 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
3569 if (Storage
== ConfigInfo
->Storage
) {
3570 ConfigResp
= ConfigInfo
->ConfigAltResp
;
3575 if (ConfigResp
== NULL
) {
3576 Link
= GetFirstNode (&FormSet
->StorageListHead
);
3577 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
3578 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
3579 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
3581 if (Storage
== FormSetStorage
->BrowserStorage
) {
3582 ConfigResp
= FormSetStorage
->ConfigAltResp
;
3588 if (ConfigResp
== NULL
) {
3589 return EFI_NOT_FOUND
;
3592 Value
= GetOffsetFromConfigResp (Question
, ConfigResp
);
3593 if (Value
== NULL
) {
3594 return EFI_NOT_FOUND
;
3597 return BufferToValue (Question
, Value
);
3601 Get default Id value used for browser.
3603 @param DefaultId The default id value used by hii.
3605 @retval Browser used default value.
3609 GetDefaultIdForCallBack (
3613 if (DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) {
3614 return EFI_BROWSER_ACTION_DEFAULT_STANDARD
;
3615 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3616 return EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
;
3617 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_SAFE
) {
3618 return EFI_BROWSER_ACTION_DEFAULT_SAFE
;
3619 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
+ 0x1000) {
3620 return EFI_BROWSER_ACTION_DEFAULT_PLATFORM
+ DefaultId
- EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
;
3621 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
+ 0x1000) {
3622 return EFI_BROWSER_ACTION_DEFAULT_HARDWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
;
3623 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
+ 0x1000) {
3624 return EFI_BROWSER_ACTION_DEFAULT_FIRMWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
;
3633 Return data element in an Array by its Index.
3635 @param Array The data array.
3636 @param Type Type of the data in this array.
3637 @param Index Zero based index for data in this array.
3639 @retval Value The data to be returned
3651 ASSERT (Array
!= NULL
);
3655 case EFI_IFR_TYPE_NUM_SIZE_8
:
3656 Data
= (UINT64
) *(((UINT8
*) Array
) + Index
);
3659 case EFI_IFR_TYPE_NUM_SIZE_16
:
3660 Data
= (UINT64
) *(((UINT16
*) Array
) + Index
);
3663 case EFI_IFR_TYPE_NUM_SIZE_32
:
3664 Data
= (UINT64
) *(((UINT32
*) Array
) + Index
);
3667 case EFI_IFR_TYPE_NUM_SIZE_64
:
3668 Data
= (UINT64
) *(((UINT64
*) Array
) + Index
);
3680 Set value of a data element in an Array by its Index.
3682 @param Array The data array.
3683 @param Type Type of the data in this array.
3684 @param Index Zero based index for data in this array.
3685 @param Value The value to be set.
3697 ASSERT (Array
!= NULL
);
3700 case EFI_IFR_TYPE_NUM_SIZE_8
:
3701 *(((UINT8
*) Array
) + Index
) = (UINT8
) Value
;
3704 case EFI_IFR_TYPE_NUM_SIZE_16
:
3705 *(((UINT16
*) Array
) + Index
) = (UINT16
) Value
;
3708 case EFI_IFR_TYPE_NUM_SIZE_32
:
3709 *(((UINT32
*) Array
) + Index
) = (UINT32
) Value
;
3712 case EFI_IFR_TYPE_NUM_SIZE_64
:
3713 *(((UINT64
*) Array
) + Index
) = (UINT64
) Value
;
3722 Search an Option of a Question by its value.
3724 @param Question The Question
3725 @param OptionValue Value for Option to be searched.
3727 @retval Pointer Pointer to the found Option.
3728 @retval NULL Option not found.
3733 IN FORM_BROWSER_STATEMENT
*Question
,
3734 IN EFI_HII_VALUE
*OptionValue
3738 QUESTION_OPTION
*Option
;
3741 Link
= GetFirstNode (&Question
->OptionListHead
);
3742 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3743 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3745 if ((CompareHiiValue (&Option
->Value
, OptionValue
, &Result
, NULL
) == EFI_SUCCESS
) && (Result
== 0)) {
3747 // Check the suppressif condition, only a valid option can be return.
3749 if ((Option
->SuppressExpression
== NULL
) ||
3750 ((EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) == ExpressFalse
))) {
3755 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3763 Reset Question to its default value.
3765 @param FormSet The form set.
3766 @param Form The form.
3767 @param Question The question.
3768 @param DefaultId The Class of the default.
3770 @retval EFI_SUCCESS Question is reset to default value.
3774 GetQuestionDefault (
3775 IN FORM_BROWSER_FORMSET
*FormSet
,
3776 IN FORM_BROWSER_FORM
*Form
,
3777 IN FORM_BROWSER_STATEMENT
*Question
,
3783 QUESTION_DEFAULT
*Default
;
3784 QUESTION_OPTION
*Option
;
3785 EFI_HII_VALUE
*HiiValue
;
3787 EFI_STRING StrValue
;
3788 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
3789 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
3793 Status
= EFI_NOT_FOUND
;
3797 // Statement don't have storage, skip them
3799 if (Question
->QuestionId
== 0) {
3804 // There are Five ways to specify default value for a Question:
3805 // 1, use call back function (highest priority)
3806 // 2, use ExtractConfig function
3807 // 3, use nested EFI_IFR_DEFAULT
3808 // 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
3809 // 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
3811 HiiValue
= &Question
->HiiValue
;
3814 // Get Question defaut value from call back function.
3816 ConfigAccess
= FormSet
->ConfigAccess
;
3817 Action
= GetDefaultIdForCallBack (DefaultId
);
3818 if ((Action
> 0) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
3819 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
3820 Status
= ConfigAccess
->Callback (
3823 Question
->QuestionId
,
3828 if (!EFI_ERROR (Status
)) {
3829 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
3830 NewString
= GetToken (Question
->HiiValue
.Value
.string
, FormSet
->HiiHandle
);
3831 ASSERT (NewString
!= NULL
);
3833 ASSERT (StrLen (NewString
) * sizeof (CHAR16
) <= Question
->StorageWidth
);
3834 if (StrLen (NewString
) * sizeof (CHAR16
) <= Question
->StorageWidth
) {
3835 CopyMem (Question
->BufferValue
, NewString
, StrSize (NewString
));
3837 CopyMem (Question
->BufferValue
, NewString
, Question
->StorageWidth
);
3840 FreePool (NewString
);
3847 // Get default value from altcfg string.
3849 if (ConfigAccess
!= NULL
) {
3850 Status
= GetDefaultValueFromAltCfg(FormSet
, Form
, Question
);
3851 if (!EFI_ERROR (Status
)) {
3857 // EFI_IFR_DEFAULT has highest priority
3859 if (!IsListEmpty (&Question
->DefaultListHead
)) {
3860 Link
= GetFirstNode (&Question
->DefaultListHead
);
3861 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
3862 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
3864 if (Default
->DefaultId
== DefaultId
) {
3865 if (Default
->ValueExpression
!= NULL
) {
3867 // Default is provided by an Expression, evaluate it
3869 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
3870 if (EFI_ERROR (Status
)) {
3874 if (Default
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
3875 ASSERT (HiiValue
->Type
== EFI_IFR_TYPE_BUFFER
&& Question
->BufferValue
!= NULL
);
3876 if (Question
->StorageWidth
> Default
->ValueExpression
->Result
.BufferLen
) {
3877 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Default
->ValueExpression
->Result
.BufferLen
);
3878 Question
->HiiValue
.BufferLen
= Default
->ValueExpression
->Result
.BufferLen
;
3880 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
3881 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
3883 FreePool (Default
->ValueExpression
->Result
.Buffer
);
3885 HiiValue
->Type
= Default
->ValueExpression
->Result
.Type
;
3886 CopyMem (&HiiValue
->Value
, &Default
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
3889 // Default value is embedded in EFI_IFR_DEFAULT
3891 if (Default
->Value
.Type
== EFI_IFR_TYPE_BUFFER
) {
3892 ASSERT (HiiValue
->Buffer
!= NULL
);
3893 CopyMem (HiiValue
->Buffer
, Default
->Value
.Buffer
, Default
->Value
.BufferLen
);
3895 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
3899 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
3900 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
3901 if (StrValue
== NULL
) {
3902 return EFI_NOT_FOUND
;
3904 if (Question
->StorageWidth
> StrSize (StrValue
)) {
3905 CopyMem (Question
->BufferValue
, StrValue
, StrSize (StrValue
));
3907 CopyMem (Question
->BufferValue
, StrValue
, Question
->StorageWidth
);
3914 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
3919 // EFI_ONE_OF_OPTION
3921 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
3922 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3924 // OneOfOption could only provide Standard and Manufacturing default
3926 Link
= GetFirstNode (&Question
->OptionListHead
);
3927 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3928 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3929 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3931 if ((Option
->SuppressExpression
!= NULL
) &&
3932 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3936 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
3937 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
3939 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
3948 // EFI_IFR_CHECKBOX - lowest priority
3950 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
3951 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3953 // Checkbox could only provide Standard and Manufacturing default
3955 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
3956 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
3958 HiiValue
->Value
.b
= TRUE
;
3960 HiiValue
->Value
.b
= FALSE
;
3968 // For Questions without default
3970 Status
= EFI_NOT_FOUND
;
3971 switch (Question
->Operand
) {
3972 case EFI_IFR_NUMERIC_OP
:
3974 // Take minimum value as numeric default value
3976 if ((Question
->Flags
& EFI_IFR_DISPLAY
) == 0) {
3978 // In EFI_IFR_DISPLAY_INT_DEC type, should check value with int* type.
3980 switch (Question
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
3981 case EFI_IFR_NUMERIC_SIZE_1
:
3982 if (((INT8
) HiiValue
->Value
.u8
< (INT8
) Question
->Minimum
) || ((INT8
) HiiValue
->Value
.u8
> (INT8
) Question
->Maximum
)) {
3983 HiiValue
->Value
.u8
= (UINT8
) Question
->Minimum
;
3984 Status
= EFI_SUCCESS
;
3987 case EFI_IFR_NUMERIC_SIZE_2
:
3988 if (((INT16
) HiiValue
->Value
.u16
< (INT16
) Question
->Minimum
) || ((INT16
) HiiValue
->Value
.u16
> (INT16
) Question
->Maximum
)) {
3989 HiiValue
->Value
.u16
= (UINT16
) Question
->Minimum
;
3990 Status
= EFI_SUCCESS
;
3993 case EFI_IFR_NUMERIC_SIZE_4
:
3994 if (((INT32
) HiiValue
->Value
.u32
< (INT32
) Question
->Minimum
) || ((INT32
) HiiValue
->Value
.u32
> (INT32
) Question
->Maximum
)) {
3995 HiiValue
->Value
.u32
= (UINT32
) Question
->Minimum
;
3996 Status
= EFI_SUCCESS
;
3999 case EFI_IFR_NUMERIC_SIZE_8
:
4000 if (((INT64
) HiiValue
->Value
.u64
< (INT64
) Question
->Minimum
) || ((INT64
) HiiValue
->Value
.u64
> (INT64
) Question
->Maximum
)) {
4001 HiiValue
->Value
.u64
= Question
->Minimum
;
4002 Status
= EFI_SUCCESS
;
4009 if ((HiiValue
->Value
.u64
< Question
->Minimum
) || (HiiValue
->Value
.u64
> Question
->Maximum
)) {
4010 HiiValue
->Value
.u64
= Question
->Minimum
;
4011 Status
= EFI_SUCCESS
;
4016 case EFI_IFR_ONE_OF_OP
:
4018 // Take first oneof option as oneof's default value
4020 if (ValueToOption (Question
, HiiValue
) == NULL
) {
4021 Link
= GetFirstNode (&Question
->OptionListHead
);
4022 while (!IsNull (&Question
->OptionListHead
, Link
)) {
4023 Option
= QUESTION_OPTION_FROM_LINK (Link
);
4024 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
4026 if ((Option
->SuppressExpression
!= NULL
) &&
4027 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
4031 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
4032 Status
= EFI_SUCCESS
;
4038 case EFI_IFR_ORDERED_LIST_OP
:
4040 // Take option sequence in IFR as ordered list's default value
4043 Link
= GetFirstNode (&Question
->OptionListHead
);
4044 while (!IsNull (&Question
->OptionListHead
, Link
)) {
4045 Status
= EFI_SUCCESS
;
4046 Option
= QUESTION_OPTION_FROM_LINK (Link
);
4047 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
4049 if ((Option
->SuppressExpression
!= NULL
) &&
4050 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
4054 SetArrayData (Question
->BufferValue
, Question
->ValueType
, Index
, Option
->Value
.Value
.u64
);
4057 if (Index
>= Question
->MaxContainers
) {
4071 Get AltCfg string for current form.
4073 @param FormSet Form data structure.
4074 @param Form Form data structure.
4075 @param DefaultId The Class of the default.
4076 @param BrowserStorage The input request storage for the questions.
4080 ExtractAltCfgForForm (
4081 IN FORM_BROWSER_FORMSET
*FormSet
,
4082 IN FORM_BROWSER_FORM
*Form
,
4083 IN UINT16 DefaultId
,
4084 IN BROWSER_STORAGE
*BrowserStorage
4092 BROWSER_STORAGE
*Storage
;
4093 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
4094 FORMSET_STORAGE
*FormSetStorage
;
4097 // Check whether has get AltCfg string for this formset.
4098 // If yes, no need to get AltCfg for form.
4100 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4101 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4102 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4103 Storage
= FormSetStorage
->BrowserStorage
;
4104 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4105 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4109 if (Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
&&
4110 FormSetStorage
->ElementCount
!= 0 &&
4111 FormSetStorage
->HasCallAltCfg
) {
4117 // Get AltCfg string for each form.
4119 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
4120 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
4121 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
4122 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
4124 Storage
= ConfigInfo
->Storage
;
4125 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4129 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
4134 // 1. Skip if there is no RequestElement
4136 if (ConfigInfo
->ElementCount
== 0) {
4141 // 2. Get value through hii config routine protocol.
4143 Status
= mHiiConfigRouting
->ExtractConfig (
4145 ConfigInfo
->ConfigRequest
,
4149 if (EFI_ERROR (Status
)) {
4154 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
4155 // Get the default configuration string according to the default ID.
4157 Status
= mHiiConfigRouting
->GetAltConfig (
4163 &DefaultId
, // it can be NULL to get the current setting.
4167 if (EFI_ERROR (Status
)) {
4171 ConfigInfo
->ConfigAltResp
= ConfigResp
;
4176 Clean AltCfg string for current form.
4178 @param Form Form data structure.
4182 CleanAltCfgForForm (
4183 IN FORM_BROWSER_FORM
*Form
4187 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
4189 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
4190 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
4191 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
4192 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
4194 if (ConfigInfo
->ConfigAltResp
!= NULL
) {
4195 FreePool (ConfigInfo
->ConfigAltResp
);
4196 ConfigInfo
->ConfigAltResp
= NULL
;
4202 Get AltCfg string for current formset.
4204 @param FormSet Form data structure.
4205 @param DefaultId The Class of the default.
4206 @param BrowserStorage The input request storage for the questions.
4210 ExtractAltCfgForFormSet (
4211 IN FORM_BROWSER_FORMSET
*FormSet
,
4212 IN UINT16 DefaultId
,
4213 IN BROWSER_STORAGE
*BrowserStorage
4221 BROWSER_STORAGE
*Storage
;
4222 FORMSET_STORAGE
*FormSetStorage
;
4224 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4225 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4226 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4227 Storage
= FormSetStorage
->BrowserStorage
;
4228 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4230 if (BrowserStorage
!= NULL
&& BrowserStorage
!= Storage
) {
4234 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
4239 // 1. Skip if there is no RequestElement
4241 if (FormSetStorage
->ElementCount
== 0) {
4245 FormSetStorage
->HasCallAltCfg
= TRUE
;
4248 // 2. Get value through hii config routine protocol.
4250 Status
= mHiiConfigRouting
->ExtractConfig (
4252 FormSetStorage
->ConfigRequest
,
4256 if (EFI_ERROR (Status
)) {
4261 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
4262 // Get the default configuration string according to the default ID.
4264 Status
= mHiiConfigRouting
->GetAltConfig (
4270 &DefaultId
, // it can be NULL to get the current setting.
4275 if (EFI_ERROR (Status
)) {
4279 FormSetStorage
->ConfigAltResp
= ConfigResp
;
4285 Clean AltCfg string for current formset.
4287 @param FormSet Form data structure.
4291 CleanAltCfgForFormSet (
4292 IN FORM_BROWSER_FORMSET
*FormSet
4296 FORMSET_STORAGE
*FormSetStorage
;
4298 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4299 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4300 FormSetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
4301 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4303 if (FormSetStorage
->ConfigAltResp
!= NULL
) {
4304 FreePool (FormSetStorage
->ConfigAltResp
);
4305 FormSetStorage
->ConfigAltResp
= NULL
;
4308 FormSetStorage
->HasCallAltCfg
= FALSE
;
4313 Reset Questions to their initial value or default value in a Form, Formset or System.
4315 GetDefaultValueScope parameter decides which questions will reset
4316 to its default value.
4318 @param FormSet FormSet data structure.
4319 @param Form Form data structure.
4320 @param DefaultId The Class of the default.
4321 @param SettingScope Setting Scope for Default action.
4322 @param GetDefaultValueScope Get default value scope.
4323 @param Storage Get default value only for this storage.
4324 @param RetrieveValueFirst Whether call the retrieve call back to
4325 get the initial value before get default
4327 @param SkipGetAltCfg Whether skip the get altcfg string process.
4329 @retval EFI_SUCCESS The function completed successfully.
4330 @retval EFI_UNSUPPORTED Unsupport SettingScope.
4335 IN FORM_BROWSER_FORMSET
*FormSet
,
4336 IN FORM_BROWSER_FORM
*Form
,
4337 IN UINT16 DefaultId
,
4338 IN BROWSER_SETTING_SCOPE SettingScope
,
4339 IN BROWSER_GET_DEFAULT_VALUE GetDefaultValueScope
,
4340 IN BROWSER_STORAGE
*Storage OPTIONAL
,
4341 IN BOOLEAN RetrieveValueFirst
,
4342 IN BOOLEAN SkipGetAltCfg
4346 LIST_ENTRY
*FormLink
;
4348 FORM_BROWSER_STATEMENT
*Question
;
4349 FORM_BROWSER_FORMSET
*LocalFormSet
;
4350 FORM_BROWSER_FORMSET
*OldFormSet
;
4352 Status
= EFI_SUCCESS
;
4355 // Check the supported setting level.
4357 if (SettingScope
>= MaxLevel
|| GetDefaultValueScope
>= GetDefaultForMax
) {
4358 return EFI_UNSUPPORTED
;
4361 if (GetDefaultValueScope
== GetDefaultForStorage
&& Storage
== NULL
) {
4362 return EFI_UNSUPPORTED
;
4365 if (SettingScope
== FormLevel
) {
4367 // Prepare the AltCfg String for form.
4369 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4370 ExtractAltCfgForForm (FormSet
, Form
, DefaultId
, Storage
);
4374 // Extract Form default
4376 Link
= GetFirstNode (&Form
->StatementListHead
);
4377 while (!IsNull (&Form
->StatementListHead
, Link
)) {
4378 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
4379 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
4382 // If get default value only for this storage, check the storage first.
4384 if ((GetDefaultValueScope
== GetDefaultForStorage
) && (Question
->Storage
!= Storage
)) {
4389 // If get default value only for no storage question, just skip the question which has storage.
4391 if ((GetDefaultValueScope
== GetDefaultForNoStorage
) && (Question
->Storage
!= NULL
)) {
4396 // If Question is disabled, don't reset it to default
4398 if (Question
->Expression
!= NULL
) {
4399 if (EvaluateExpressionList(Question
->Expression
, TRUE
, FormSet
, Form
) == ExpressDisable
) {
4404 if (RetrieveValueFirst
) {
4406 // Call the Retrieve call back to get the initial question value.
4408 Status
= ProcessRetrieveForQuestion(FormSet
->ConfigAccess
, Question
, FormSet
);
4412 // If not request to get the initial value or get initial value fail, then get default value.
4414 if (!RetrieveValueFirst
|| EFI_ERROR (Status
)) {
4415 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
4416 if (EFI_ERROR (Status
)) {
4422 // Synchronize Buffer storage's Edit buffer
4424 if ((Question
->Storage
!= NULL
) &&
4425 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
4426 SetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4431 // Clean the AltCfg String.
4433 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4434 CleanAltCfgForForm(Form
);
4436 } else if (SettingScope
== FormSetLevel
) {
4438 // Prepare the AltCfg String for formset.
4440 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4441 ExtractAltCfgForFormSet (FormSet
, DefaultId
, Storage
);
4444 FormLink
= GetFirstNode (&FormSet
->FormListHead
);
4445 while (!IsNull (&FormSet
->FormListHead
, FormLink
)) {
4446 Form
= FORM_BROWSER_FORM_FROM_LINK (FormLink
);
4447 ExtractDefault (FormSet
, Form
, DefaultId
, FormLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
, SkipGetAltCfg
);
4448 FormLink
= GetNextNode (&FormSet
->FormListHead
, FormLink
);
4452 // Clean the AltCfg String.
4454 if (!SkipGetAltCfg
&& (GetDefaultValueScope
!= GetDefaultForNoStorage
)) {
4455 CleanAltCfgForFormSet (FormSet
);
4457 } else if (SettingScope
== SystemLevel
) {
4459 // Preload all Hii formset.
4461 LoadAllHiiFormset();
4463 OldFormSet
= mSystemLevelFormSet
;
4466 // Set Default Value for each FormSet in the maintain list.
4468 Link
= GetFirstNode (&gBrowserFormSetList
);
4469 while (!IsNull (&gBrowserFormSetList
, Link
)) {
4470 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
4471 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
4472 if (!ValidateFormSet(LocalFormSet
)) {
4476 mSystemLevelFormSet
= LocalFormSet
;
4478 ExtractDefault (LocalFormSet
, NULL
, DefaultId
, FormSetLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
, SkipGetAltCfg
);
4481 mSystemLevelFormSet
= OldFormSet
;
4489 Validate whether this question's value has changed.
4491 @param FormSet FormSet data structure.
4492 @param Form Form data structure.
4493 @param Question Question to be initialized.
4494 @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver.
4496 @retval TRUE Question's value has changed.
4497 @retval FALSE Question's value has not changed
4501 IsQuestionValueChanged (
4502 IN FORM_BROWSER_FORMSET
*FormSet
,
4503 IN FORM_BROWSER_FORM
*Form
,
4504 IN OUT FORM_BROWSER_STATEMENT
*Question
,
4505 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
4508 EFI_HII_VALUE BackUpValue
;
4509 CHAR8
*BackUpBuffer
;
4510 EFI_HII_VALUE BackUpValue2
;
4511 CHAR8
*BackUpBuffer2
;
4513 BOOLEAN ValueChanged
;
4517 // For quetion without storage, always mark it as data not changed.
4519 if (Question
->Storage
== NULL
&& Question
->Operand
!= EFI_IFR_TIME_OP
&& Question
->Operand
!= EFI_IFR_DATE_OP
) {
4523 BackUpBuffer
= NULL
;
4524 BackUpBuffer2
= NULL
;
4525 ValueChanged
= FALSE
;
4527 switch (Question
->Operand
) {
4528 case EFI_IFR_ORDERED_LIST_OP
:
4529 BufferWidth
= Question
->StorageWidth
;
4530 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4531 ASSERT (BackUpBuffer
!= NULL
);
4534 case EFI_IFR_STRING_OP
:
4535 case EFI_IFR_PASSWORD_OP
:
4536 BufferWidth
= (UINTN
) Question
->Maximum
* sizeof (CHAR16
);
4537 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4538 ASSERT (BackUpBuffer
!= NULL
);
4545 CopyMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
));
4547 if (GetValueFrom
== GetSetValueWithBothBuffer
) {
4548 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4549 ASSERT_EFI_ERROR(Status
);
4551 switch (Question
->Operand
) {
4552 case EFI_IFR_ORDERED_LIST_OP
:
4553 BufferWidth
= Question
->StorageWidth
;
4554 BackUpBuffer2
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4555 ASSERT (BackUpBuffer2
!= NULL
);
4558 case EFI_IFR_STRING_OP
:
4559 case EFI_IFR_PASSWORD_OP
:
4560 BufferWidth
= (UINTN
) Question
->Maximum
* sizeof (CHAR16
);
4561 BackUpBuffer2
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
4562 ASSERT (BackUpBuffer2
!= NULL
);
4569 CopyMem (&BackUpValue2
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
));
4571 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithBuffer
);
4572 ASSERT_EFI_ERROR(Status
);
4574 if (CompareMem (&BackUpValue2
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
)) != 0 ||
4575 CompareMem (BackUpBuffer2
, Question
->BufferValue
, BufferWidth
) != 0) {
4576 ValueChanged
= TRUE
;
4579 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetValueFrom
);
4580 ASSERT_EFI_ERROR(Status
);
4582 if (CompareMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
)) != 0 ||
4583 CompareMem (BackUpBuffer
, Question
->BufferValue
, BufferWidth
) != 0) {
4584 ValueChanged
= TRUE
;
4588 CopyMem (&Question
->HiiValue
, &BackUpValue
, sizeof (EFI_HII_VALUE
));
4589 if (BackUpBuffer
!= NULL
) {
4590 CopyMem (Question
->BufferValue
, BackUpBuffer
, BufferWidth
);
4591 FreePool (BackUpBuffer
);
4594 if (BackUpBuffer2
!= NULL
) {
4595 FreePool (BackUpBuffer2
);
4598 Question
->ValueChanged
= ValueChanged
;
4600 return ValueChanged
;
4604 Initialize Question's Edit copy from Storage.
4606 @param Selection Selection contains the information about
4607 the Selection, form and formset to be displayed.
4608 Selection action may be updated in retrieve callback.
4609 If Selection is NULL, only initialize Question value.
4610 @param FormSet FormSet data structure.
4611 @param Form Form data structure.
4613 @retval EFI_SUCCESS The function completed successfully.
4618 IN OUT UI_MENU_SELECTION
*Selection
,
4619 IN FORM_BROWSER_FORMSET
*FormSet
,
4620 IN FORM_BROWSER_FORM
*Form
4625 FORM_BROWSER_STATEMENT
*Question
;
4627 Link
= GetFirstNode (&Form
->StatementListHead
);
4628 while (!IsNull (&Form
->StatementListHead
, Link
)) {
4629 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
4632 // Initialize local copy of Value for each Question
4634 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
&& (Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
)== 0) {
4635 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithHiiDriver
);
4637 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
4639 if (EFI_ERROR (Status
)) {
4643 if ((Question
->Operand
== EFI_IFR_STRING_OP
) || (Question
->Operand
== EFI_IFR_PASSWORD_OP
)) {
4644 HiiSetString (FormSet
->HiiHandle
, Question
->HiiValue
.Value
.string
, (CHAR16
*)Question
->BufferValue
, NULL
);
4647 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
4654 Initialize Question's Edit copy from Storage for the whole Formset.
4656 @param Selection Selection contains the information about
4657 the Selection, form and formset to be displayed.
4658 Selection action may be updated in retrieve callback.
4659 If Selection is NULL, only initialize Question value.
4660 @param FormSet FormSet data structure.
4662 @retval EFI_SUCCESS The function completed successfully.
4667 IN OUT UI_MENU_SELECTION
*Selection
,
4668 IN FORM_BROWSER_FORMSET
*FormSet
4673 FORM_BROWSER_FORM
*Form
;
4675 Link
= GetFirstNode (&FormSet
->FormListHead
);
4676 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
4677 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
4680 // Initialize local copy of Value for each Form
4682 Status
= LoadFormConfig (Selection
, FormSet
, Form
);
4683 if (EFI_ERROR (Status
)) {
4687 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
4691 // Finished question initialization.
4693 FormSet
->QuestionInited
= TRUE
;
4699 Remove the Request element from the Config Request.
4701 @param Storage Pointer to the browser storage.
4702 @param RequestElement The pointer to the Request element.
4707 IN OUT BROWSER_STORAGE
*Storage
,
4708 IN CHAR16
*RequestElement
4714 ASSERT (Storage
->ConfigRequest
!= NULL
&& RequestElement
!= NULL
);
4716 NewStr
= StrStr (Storage
->ConfigRequest
, RequestElement
);
4718 if (NewStr
== NULL
) {
4723 // Remove this element from this ConfigRequest.
4726 NewStr
+= StrLen (RequestElement
);
4727 CopyMem (DestStr
, NewStr
, StrSize (NewStr
));
4729 Storage
->SpareStrLen
+= StrLen (RequestElement
);
4733 Adjust config request in storage, remove the request elements existed in the input ConfigRequest.
4735 @param Storage Pointer to the formset storage.
4736 @param ConfigRequest The pointer to the Request element.
4740 RemoveConfigRequest (
4741 FORMSET_STORAGE
*Storage
,
4742 CHAR16
*ConfigRequest
4745 CHAR16
*RequestElement
;
4746 CHAR16
*NextRequestElement
;
4750 // No request element in it, just return.
4752 if (ConfigRequest
== NULL
) {
4756 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4758 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
4763 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
4765 SearchKey
= L
"&OFFSET";
4769 // Find SearchKey storage
4771 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4772 RequestElement
= StrStr (ConfigRequest
, L
"PATH");
4773 ASSERT (RequestElement
!= NULL
);
4774 RequestElement
= StrStr (RequestElement
, SearchKey
);
4776 RequestElement
= StrStr (ConfigRequest
, SearchKey
);
4779 while (RequestElement
!= NULL
) {
4781 // +1 to avoid find header itself.
4783 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
4786 // The last Request element in configRequest string.
4788 if (NextRequestElement
!= NULL
) {
4790 // Replace "&" with '\0'.
4792 *NextRequestElement
= L
'\0';
4795 RemoveElement (Storage
->BrowserStorage
, RequestElement
);
4797 if (NextRequestElement
!= NULL
) {
4799 // Restore '&' with '\0' for later used.
4801 *NextRequestElement
= L
'&';
4804 RequestElement
= NextRequestElement
;
4808 // If no request element remain, just remove the ConfigRequest string.
4810 if (StrCmp (Storage
->BrowserStorage
->ConfigRequest
, Storage
->ConfigHdr
) == 0) {
4811 FreePool (Storage
->BrowserStorage
->ConfigRequest
);
4812 Storage
->BrowserStorage
->ConfigRequest
= NULL
;
4813 Storage
->BrowserStorage
->SpareStrLen
= 0;
4818 Base on the current formset info, clean the ConfigRequest string in browser storage.
4820 @param FormSet Pointer of the FormSet
4824 CleanBrowserStorage (
4825 IN OUT FORM_BROWSER_FORMSET
*FormSet
4829 FORMSET_STORAGE
*Storage
;
4831 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4832 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4833 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
4834 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4836 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
4837 if (Storage
->ConfigRequest
== NULL
|| Storage
->BrowserStorage
->ConfigRequest
== NULL
) {
4841 RemoveConfigRequest (Storage
, Storage
->ConfigRequest
);
4842 } else if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_BUFFER
||
4843 Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4844 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
4845 FreePool (Storage
->BrowserStorage
->ConfigRequest
);
4846 Storage
->BrowserStorage
->ConfigRequest
= NULL
;
4848 Storage
->BrowserStorage
->Initialized
= FALSE
;
4854 Check whether current element in the ConfigReqeust string.
4856 @param BrowserStorage Storage which includes ConfigReqeust.
4857 @param RequestElement New element need to check.
4859 @retval TRUE The Element is in the ConfigReqeust string.
4860 @retval FALSE The Element not in the configReqeust String.
4865 BROWSER_STORAGE
*BrowserStorage
,
4866 CHAR16
*RequestElement
4869 return StrStr (BrowserStorage
->ConfigRequest
, RequestElement
) != NULL
? TRUE
: FALSE
;
4873 Append the Request element to the Config Request.
4875 @param ConfigRequest Current ConfigRequest info.
4876 @param SpareStrLen Current remain free buffer for config reqeust.
4877 @param RequestElement New Request element.
4881 AppendConfigRequest (
4882 IN OUT CHAR16
**ConfigRequest
,
4883 IN OUT UINTN
*SpareStrLen
,
4884 IN CHAR16
*RequestElement
4891 StrLength
= StrLen (RequestElement
);
4894 // Append <RequestElement> to <ConfigRequest>
4896 if (StrLength
> *SpareStrLen
) {
4898 // Old String buffer is not sufficient for RequestElement, allocate a new one
4900 StringSize
= (*ConfigRequest
!= NULL
) ? StrSize (*ConfigRequest
) : sizeof (CHAR16
);
4901 NewStr
= AllocateZeroPool (StringSize
+ CONFIG_REQUEST_STRING_INCREMENTAL
* sizeof (CHAR16
));
4902 ASSERT (NewStr
!= NULL
);
4904 if (*ConfigRequest
!= NULL
) {
4905 CopyMem (NewStr
, *ConfigRequest
, StringSize
);
4906 FreePool (*ConfigRequest
);
4908 *ConfigRequest
= NewStr
;
4909 *SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
4912 StrCat (*ConfigRequest
, RequestElement
);
4913 *SpareStrLen
-= StrLength
;
4917 Adjust the config request info, remove the request elements which already in AllConfigRequest string.
4919 @param Storage Form set Storage.
4920 @param Request The input request string.
4921 @param RespString Whether the input is ConfigRequest or ConfigResp format.
4923 @retval TRUE Has element not covered by current used elements, need to continue to call ExtractConfig
4924 @retval FALSE All elements covered by current used elements.
4928 ConfigRequestAdjust (
4929 IN BROWSER_STORAGE
*Storage
,
4931 IN BOOLEAN RespString
4934 CHAR16
*RequestElement
;
4935 CHAR16
*NextRequestElement
;
4936 CHAR16
*NextElementBakup
;
4940 CHAR16
*ConfigRequest
;
4943 NextElementBakup
= NULL
;
4946 if (Request
!= NULL
) {
4947 ConfigRequest
= Request
;
4949 ConfigRequest
= Storage
->ConfigRequest
;
4952 if (Storage
->ConfigRequest
== NULL
) {
4953 Storage
->ConfigRequest
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
4957 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4959 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
4964 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
4966 SearchKey
= L
"&OFFSET";
4967 ValueKey
= L
"&VALUE";
4971 // Find SearchKey storage
4973 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4974 RequestElement
= StrStr (ConfigRequest
, L
"PATH");
4975 ASSERT (RequestElement
!= NULL
);
4976 RequestElement
= StrStr (RequestElement
, SearchKey
);
4978 RequestElement
= StrStr (ConfigRequest
, SearchKey
);
4981 while (RequestElement
!= NULL
) {
4984 // +1 to avoid find header itself.
4986 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
4989 // The last Request element in configRequest string.
4991 if (NextRequestElement
!= NULL
) {
4992 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
4993 NextElementBakup
= NextRequestElement
;
4994 NextRequestElement
= StrStr (RequestElement
, ValueKey
);
4995 ASSERT (NextRequestElement
!= NULL
);
4998 // Replace "&" with '\0'.
5000 *NextRequestElement
= L
'\0';
5002 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
5003 NextElementBakup
= NextRequestElement
;
5004 NextRequestElement
= StrStr (RequestElement
, ValueKey
);
5005 ASSERT (NextRequestElement
!= NULL
);
5007 // Replace "&" with '\0'.
5009 *NextRequestElement
= L
'\0';
5013 if (!ElementValidation (Storage
, RequestElement
)) {
5015 // Add this element to the Storage->BrowserStorage->AllRequestElement.
5017 AppendConfigRequest(&Storage
->ConfigRequest
, &Storage
->SpareStrLen
, RequestElement
);
5021 if (NextRequestElement
!= NULL
) {
5023 // Restore '&' with '\0' for later used.
5025 *NextRequestElement
= L
'&';
5028 if (RespString
&& (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
5029 RequestElement
= NextElementBakup
;
5031 RequestElement
= NextRequestElement
;
5039 Fill storage's edit copy with settings requested from Configuration Driver.
5041 @param FormSet FormSet data structure.
5042 @param Storage Buffer Storage.
5047 IN FORM_BROWSER_FORMSET
*FormSet
,
5048 IN FORMSET_STORAGE
*Storage
5052 EFI_STRING Progress
;
5055 EFI_STRING ConfigRequest
;
5058 ConfigRequest
= NULL
;
5060 switch (Storage
->BrowserStorage
->Type
) {
5061 case EFI_HII_VARSTORE_EFI_VARIABLE
:
5064 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
5065 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
5066 ConfigRequestAdjust(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
5071 case EFI_HII_VARSTORE_BUFFER
:
5072 case EFI_HII_VARSTORE_NAME_VALUE
:
5074 // Skip if there is no RequestElement.
5076 if (Storage
->ElementCount
== 0) {
5081 // Just update the ConfigRequest, if storage already initialized.
5083 if (Storage
->BrowserStorage
->Initialized
) {
5084 ConfigRequestAdjust(Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
5088 Storage
->BrowserStorage
->Initialized
= TRUE
;
5095 if (Storage
->BrowserStorage
->Type
!= EFI_HII_VARSTORE_NAME_VALUE
) {
5097 // Create the config request string to get all fields for this storage.
5098 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
5099 // followed by "&OFFSET=0&WIDTH=WWWW"followed by a Null-terminator
5101 StrLen
= StrSize (Storage
->ConfigHdr
) + 20 * sizeof (CHAR16
);
5102 ConfigRequest
= AllocateZeroPool (StrLen
);
5103 ASSERT (ConfigRequest
!= NULL
);
5107 L
"%s&OFFSET=0&WIDTH=%04x",
5109 Storage
->BrowserStorage
->Size
);
5111 ConfigRequest
= Storage
->ConfigRequest
;
5115 // Request current settings from Configuration Driver
5117 Status
= mHiiConfigRouting
->ExtractConfig (
5125 // If get value fail, extract default from IFR binary
5127 if (EFI_ERROR (Status
)) {
5128 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForStorage
, Storage
->BrowserStorage
, TRUE
, TRUE
);
5131 // Convert Result from <ConfigAltResp> to <ConfigResp>
5133 StrPtr
= StrStr (Result
, L
"&GUID=");
5134 if (StrPtr
!= NULL
) {
5138 Status
= ConfigRespToStorage (Storage
->BrowserStorage
, Result
);
5142 Storage
->BrowserStorage
->ConfigRequest
= AllocateCopyPool (StrSize (Storage
->ConfigRequest
), Storage
->ConfigRequest
);
5145 // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer.
5147 SynchronizeStorage(Storage
->BrowserStorage
, NULL
, TRUE
);
5149 if (Storage
->BrowserStorage
->Type
!= EFI_HII_VARSTORE_NAME_VALUE
) {
5150 if (ConfigRequest
!= NULL
) {
5151 FreePool (ConfigRequest
);
5157 Get Value changed status from old question.
5159 @param NewFormSet FormSet data structure.
5160 @param OldQuestion Old question which has value changed.
5164 SyncStatusForQuestion (
5165 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
5166 IN FORM_BROWSER_STATEMENT
*OldQuestion
5170 LIST_ENTRY
*QuestionLink
;
5171 FORM_BROWSER_FORM
*Form
;
5172 FORM_BROWSER_STATEMENT
*Question
;
5175 // For each form in one formset.
5177 Link
= GetFirstNode (&NewFormSet
->FormListHead
);
5178 while (!IsNull (&NewFormSet
->FormListHead
, Link
)) {
5179 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
5180 Link
= GetNextNode (&NewFormSet
->FormListHead
, Link
);
5183 // for each question in one form.
5185 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
5186 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
5187 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
5188 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
5190 if (Question
->QuestionId
== OldQuestion
->QuestionId
) {
5191 Question
->ValueChanged
= TRUE
;
5199 Get Value changed status from old formset.
5201 @param NewFormSet FormSet data structure.
5202 @param OldFormSet FormSet data structure.
5206 SyncStatusForFormSet (
5207 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
5208 IN FORM_BROWSER_FORMSET
*OldFormSet
5212 LIST_ENTRY
*QuestionLink
;
5213 FORM_BROWSER_FORM
*Form
;
5214 FORM_BROWSER_STATEMENT
*Question
;
5217 // For each form in one formset.
5219 Link
= GetFirstNode (&OldFormSet
->FormListHead
);
5220 while (!IsNull (&OldFormSet
->FormListHead
, Link
)) {
5221 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
5222 Link
= GetNextNode (&OldFormSet
->FormListHead
, Link
);
5225 // for each question in one form.
5227 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
5228 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
5229 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
5230 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
5232 if (!Question
->ValueChanged
) {
5237 // Find the same question in new formset and update the value changed flag.
5239 SyncStatusForQuestion (NewFormSet
, Question
);
5245 Get current setting of Questions.
5247 @param FormSet FormSet data structure.
5251 InitializeCurrentSetting (
5252 IN OUT FORM_BROWSER_FORMSET
*FormSet
5256 FORMSET_STORAGE
*Storage
;
5257 FORM_BROWSER_FORMSET
*OldFormSet
;
5260 // Try to find pre FormSet in the maintain backup list.
5261 // If old formset != NULL, destroy this formset. Add new formset to gBrowserFormSetList.
5263 OldFormSet
= GetFormSetFromHiiHandle (FormSet
->HiiHandle
);
5264 if (OldFormSet
!= NULL
) {
5265 SyncStatusForFormSet (FormSet
, OldFormSet
);
5266 RemoveEntryList (&OldFormSet
->Link
);
5267 DestroyFormSet (OldFormSet
);
5269 InsertTailList (&gBrowserFormSetList
, &FormSet
->Link
);
5272 // Extract default from IFR binary for no storage questions.
5274 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForNoStorage
, NULL
, TRUE
, FALSE
);
5277 // Request current settings from Configuration Driver
5279 Link
= GetFirstNode (&FormSet
->StorageListHead
);
5280 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
5281 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
5283 LoadStorage (FormSet
, Storage
);
5285 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
5291 Fetch the Ifr binary data of a FormSet.
5293 @param Handle PackageList Handle
5294 @param FormSetGuid On input, GUID or class GUID of a formset. If not
5295 specified (NULL or zero GUID), take the first
5296 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
5297 found in package list.
5298 On output, GUID of the formset found(if not NULL).
5299 @param BinaryLength The length of the FormSet IFR binary.
5300 @param BinaryData The buffer designed to receive the FormSet.
5302 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
5303 BufferLength was updated.
5304 @retval EFI_INVALID_PARAMETER The handle is unknown.
5305 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
5306 be found with the requested FormId.
5311 IN EFI_HII_HANDLE Handle
,
5312 IN OUT EFI_GUID
*FormSetGuid
,
5313 OUT UINTN
*BinaryLength
,
5314 OUT UINT8
**BinaryData
5318 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
5324 UINT32 PackageListLength
;
5325 EFI_HII_PACKAGE_HEADER PackageHeader
;
5327 UINT8 NumberOfClassGuid
;
5328 BOOLEAN ClassGuidMatch
;
5329 EFI_GUID
*ClassGuid
;
5330 EFI_GUID
*ComparingGuid
;
5334 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
5337 // if FormSetGuid is NULL or zero GUID, return first Setup FormSet in the package list
5339 if (FormSetGuid
== NULL
) {
5340 ComparingGuid
= &gZeroGuid
;
5342 ComparingGuid
= FormSetGuid
;
5346 // Get HII PackageList
5349 HiiPackageList
= NULL
;
5350 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
5351 if (Status
== EFI_BUFFER_TOO_SMALL
) {
5352 HiiPackageList
= AllocatePool (BufferSize
);
5353 ASSERT (HiiPackageList
!= NULL
);
5355 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
5357 if (EFI_ERROR (Status
)) {
5360 ASSERT (HiiPackageList
!= NULL
);
5363 // Get Form package from this HII package List
5365 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
5367 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
5369 ClassGuidMatch
= FALSE
;
5370 while (Offset
< PackageListLength
) {
5371 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
5372 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
5374 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
5376 // Search FormSet in this Form Package
5378 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
5379 while (Offset2
< PackageHeader
.Length
) {
5380 OpCodeData
= Package
+ Offset2
;
5382 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
5384 // Try to compare against formset GUID
5386 if (CompareGuid (FormSetGuid
, &gZeroGuid
) ||
5387 CompareGuid (ComparingGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
5391 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
5393 // Try to compare against formset class GUID
5395 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
5396 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
5397 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
5398 if (CompareGuid (ComparingGuid
, ClassGuid
+ Index
)) {
5399 ClassGuidMatch
= TRUE
;
5403 if (ClassGuidMatch
) {
5406 } else if (ComparingGuid
== &gEfiHiiPlatformSetupFormsetGuid
) {
5407 ClassGuidMatch
= TRUE
;
5412 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
5415 if (Offset2
< PackageHeader
.Length
) {
5417 // Target formset found
5423 Offset
+= PackageHeader
.Length
;
5426 if (Offset
>= PackageListLength
) {
5428 // Form package not found in this Package List
5430 FreePool (HiiPackageList
);
5431 return EFI_NOT_FOUND
;
5434 if (FormSetGuid
!= NULL
) {
5436 // Return the FormSet GUID
5438 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
5442 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
5443 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
5444 // of the Form Package.
5446 *BinaryLength
= PackageHeader
.Length
- Offset2
;
5447 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
5449 FreePool (HiiPackageList
);
5451 if (*BinaryData
== NULL
) {
5452 return EFI_OUT_OF_RESOURCES
;
5460 Initialize the internal data structure of a FormSet.
5462 @param Handle PackageList Handle
5463 @param FormSetGuid On input, GUID or class GUID of a formset. If not
5464 specified (NULL or zero GUID), take the first
5465 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
5466 found in package list.
5467 On output, GUID of the formset found(if not NULL).
5468 @param FormSet FormSet data structure.
5470 @retval EFI_SUCCESS The function completed successfully.
5471 @retval EFI_NOT_FOUND The specified FormSet could not be found.
5476 IN EFI_HII_HANDLE Handle
,
5477 IN OUT EFI_GUID
*FormSetGuid
,
5478 OUT FORM_BROWSER_FORMSET
*FormSet
5482 EFI_HANDLE DriverHandle
;
5484 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
5485 if (EFI_ERROR (Status
)) {
5489 FormSet
->Signature
= FORM_BROWSER_FORMSET_SIGNATURE
;
5490 FormSet
->HiiHandle
= Handle
;
5491 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
5492 FormSet
->QuestionInited
= FALSE
;
5495 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
5497 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
5498 if (EFI_ERROR (Status
)) {
5501 FormSet
->DriverHandle
= DriverHandle
;
5502 Status
= gBS
->HandleProtocol (
5504 &gEfiHiiConfigAccessProtocolGuid
,
5505 (VOID
**) &FormSet
->ConfigAccess
5507 if (EFI_ERROR (Status
)) {
5509 // Configuration Driver don't attach ConfigAccess protocol to its HII package
5510 // list, then there will be no configuration action required
5512 FormSet
->ConfigAccess
= NULL
;
5516 // Parse the IFR binary OpCodes
5518 Status
= ParseOpCodes (FormSet
);
5525 Save globals used by previous call to SendForm(). SendForm() may be called from
5526 HiiConfigAccess.Callback(), this will cause SendForm() be reentried.
5527 So, save globals of previous call to SendForm() and restore them upon exit.
5531 SaveBrowserContext (
5535 BROWSER_CONTEXT
*Context
;
5536 FORM_ENTRY_INFO
*MenuList
;
5538 gBrowserContextCount
++;
5539 if (gBrowserContextCount
== 1) {
5541 // This is not reentry of SendForm(), no context to save
5546 Context
= AllocatePool (sizeof (BROWSER_CONTEXT
));
5547 ASSERT (Context
!= NULL
);
5549 Context
->Signature
= BROWSER_CONTEXT_SIGNATURE
;
5552 // Save FormBrowser context
5554 Context
->Selection
= gCurrentSelection
;
5555 Context
->ResetRequired
= gResetRequired
;
5556 Context
->FlagReconnect
= gFlagReconnect
;
5557 Context
->CallbackReconnect
= gCallbackReconnect
;
5558 Context
->ExitRequired
= gExitRequired
;
5559 Context
->HiiHandle
= mCurrentHiiHandle
;
5560 Context
->FormId
= mCurrentFormId
;
5561 CopyGuid (&Context
->FormSetGuid
, &mCurrentFormSetGuid
);
5564 // Save the menu history data.
5566 InitializeListHead(&Context
->FormHistoryList
);
5567 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
5568 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
5569 RemoveEntryList (&MenuList
->Link
);
5571 InsertTailList(&Context
->FormHistoryList
, &MenuList
->Link
);
5575 // Insert to FormBrowser context list
5577 InsertHeadList (&gBrowserContextList
, &Context
->Link
);
5582 Restore globals used by previous call to SendForm().
5586 RestoreBrowserContext (
5591 BROWSER_CONTEXT
*Context
;
5592 FORM_ENTRY_INFO
*MenuList
;
5594 ASSERT (gBrowserContextCount
!= 0);
5595 gBrowserContextCount
--;
5596 if (gBrowserContextCount
== 0) {
5598 // This is not reentry of SendForm(), no context to restore
5603 ASSERT (!IsListEmpty (&gBrowserContextList
));
5605 Link
= GetFirstNode (&gBrowserContextList
);
5606 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
5609 // Restore FormBrowser context
5611 gCurrentSelection
= Context
->Selection
;
5612 gResetRequired
= Context
->ResetRequired
;
5613 gFlagReconnect
= Context
->FlagReconnect
;
5614 gCallbackReconnect
= Context
->CallbackReconnect
;
5615 gExitRequired
= Context
->ExitRequired
;
5616 mCurrentHiiHandle
= Context
->HiiHandle
;
5617 mCurrentFormId
= Context
->FormId
;
5618 CopyGuid (&mCurrentFormSetGuid
, &Context
->FormSetGuid
);
5621 // Restore the menu history data.
5623 while (!IsListEmpty (&Context
->FormHistoryList
)) {
5624 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Context
->FormHistoryList
.ForwardLink
);
5625 RemoveEntryList (&MenuList
->Link
);
5627 InsertTailList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &MenuList
->Link
);
5631 // Remove from FormBrowser context list
5633 RemoveEntryList (&Context
->Link
);
5634 gBS
->FreePool (Context
);
5638 Find the matched FormSet context in the backup maintain list based on HiiHandle.
5640 @param Handle The Hii Handle.
5642 @return the found FormSet context. If no found, NULL will return.
5645 FORM_BROWSER_FORMSET
*
5646 GetFormSetFromHiiHandle (
5647 EFI_HII_HANDLE Handle
5651 FORM_BROWSER_FORMSET
*FormSet
;
5653 Link
= GetFirstNode (&gBrowserFormSetList
);
5654 while (!IsNull (&gBrowserFormSetList
, Link
)) {
5655 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
5656 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
5657 if (!ValidateFormSet(FormSet
)) {
5660 if (FormSet
->HiiHandle
== Handle
) {
5669 Check whether the input HII handle is the FormSet that is being used.
5671 @param Handle The Hii Handle.
5673 @retval TRUE HII handle is being used.
5674 @retval FALSE HII handle is not being used.
5678 IsHiiHandleInBrowserContext (
5679 EFI_HII_HANDLE Handle
5683 BROWSER_CONTEXT
*Context
;
5686 // HiiHandle is Current FormSet.
5688 if (mCurrentHiiHandle
== Handle
) {
5693 // Check whether HiiHandle is in BrowserContext.
5695 Link
= GetFirstNode (&gBrowserContextList
);
5696 while (!IsNull (&gBrowserContextList
, Link
)) {
5697 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
5698 if (Context
->HiiHandle
== Handle
) {
5700 // HiiHandle is in BrowserContext
5704 Link
= GetNextNode (&gBrowserContextList
, Link
);
5711 Perform Password check.
5712 Passwork may be encrypted by driver that requires the specific check.
5714 @param Form Form where Password Statement is in.
5715 @param Statement Password statement
5716 @param PasswordString Password string to be checked. It may be NULL.
5717 NULL means to restore password.
5718 "" string can be used to checked whether old password does exist.
5720 @return Status Status of Password check.
5725 IN FORM_DISPLAY_ENGINE_FORM
*Form
,
5726 IN FORM_DISPLAY_ENGINE_STATEMENT
*Statement
,
5727 IN EFI_STRING PasswordString OPTIONAL
5731 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
5732 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
5733 EFI_IFR_TYPE_VALUE IfrTypeValue
;
5734 FORM_BROWSER_STATEMENT
*Question
;
5736 ConfigAccess
= gCurrentSelection
->FormSet
->ConfigAccess
;
5737 Question
= GetBrowserStatement(Statement
);
5738 ASSERT (Question
!= NULL
);
5740 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
) {
5741 if (ConfigAccess
== NULL
) {
5742 return EFI_UNSUPPORTED
;
5745 if (PasswordString
== NULL
) {
5750 // Check whether has preexisted password.
5752 if (PasswordString
[0] == 0) {
5753 if (*((CHAR16
*) Question
->BufferValue
) == 0) {
5756 return EFI_NOT_READY
;
5761 // Check whether the input password is same as preexisted password.
5763 if (StrnCmp (PasswordString
, (CHAR16
*) Question
->BufferValue
, Question
->StorageWidth
/sizeof (CHAR16
)) == 0) {
5766 return EFI_NOT_READY
;
5771 // Prepare password string in HII database
5773 if (PasswordString
!= NULL
) {
5774 IfrTypeValue
.string
= NewString (PasswordString
, gCurrentSelection
->FormSet
->HiiHandle
);
5776 IfrTypeValue
.string
= 0;
5780 // Send password to Configuration Driver for validation
5782 Status
= ConfigAccess
->Callback (
5784 EFI_BROWSER_ACTION_CHANGING
,
5785 Question
->QuestionId
,
5786 Question
->HiiValue
.Type
,
5792 // Remove password string from HII database
5794 if (PasswordString
!= NULL
) {
5795 DeleteString (IfrTypeValue
.string
, gCurrentSelection
->FormSet
->HiiHandle
);
5802 Find the registered HotKey based on KeyData.
5804 @param[in] KeyData A pointer to a buffer that describes the keystroke
5805 information for the hot key.
5807 @return The registered HotKey context. If no found, NULL will return.
5810 GetHotKeyFromRegisterList (
5811 IN EFI_INPUT_KEY
*KeyData
5815 BROWSER_HOT_KEY
*HotKey
;
5817 Link
= GetFirstNode (&gBrowserHotKeyList
);
5818 while (!IsNull (&gBrowserHotKeyList
, Link
)) {
5819 HotKey
= BROWSER_HOT_KEY_FROM_LINK (Link
);
5820 if (HotKey
->KeyData
->ScanCode
== KeyData
->ScanCode
) {
5823 Link
= GetNextNode (&gBrowserHotKeyList
, Link
);
5830 Configure what scope the hot key will impact.
5831 All hot keys have the same scope. The mixed hot keys with the different level are not supported.
5832 If no scope is set, the default scope will be FormSet level.
5833 After all registered hot keys are removed, previous Scope can reset to another level.
5835 @param[in] Scope Scope level to be set.
5837 @retval EFI_SUCCESS Scope is set correctly.
5838 @retval EFI_INVALID_PARAMETER Scope is not the valid value specified in BROWSER_SETTING_SCOPE.
5839 @retval EFI_UNSPPORTED Scope level is different from current one that the registered hot keys have.
5845 IN BROWSER_SETTING_SCOPE Scope
5848 if (Scope
>= MaxLevel
) {
5849 return EFI_INVALID_PARAMETER
;
5853 // When no hot key registered in system or on the first setting,
5854 // Scope can be set.
5856 if (mBrowserScopeFirstSet
|| IsListEmpty (&gBrowserHotKeyList
)) {
5857 gBrowserSettingScope
= Scope
;
5858 mBrowserScopeFirstSet
= FALSE
;
5859 } else if (Scope
!= gBrowserSettingScope
) {
5860 return EFI_UNSUPPORTED
;
5867 Register the hot key with its browser action, or unregistered the hot key.
5868 Only support hot key that is not printable character (control key, function key, etc.).
5869 If the action value is zero, the hot key will be unregistered if it has been registered.
5870 If the same hot key has been registered, the new action and help string will override the previous ones.
5872 @param[in] KeyData A pointer to a buffer that describes the keystroke
5873 information for the hot key. Its type is EFI_INPUT_KEY to
5874 be supported by all ConsoleIn devices.
5875 @param[in] Action Action value that describes what action will be trigged when the hot key is pressed.
5876 @param[in] DefaultId Specifies the type of defaults to retrieve, which is only for DEFAULT action.
5877 @param[in] HelpString Help string that describes the hot key information.
5878 Its value may be NULL for the unregistered hot key.
5880 @retval EFI_SUCCESS Hot key is registered or unregistered.
5881 @retval EFI_INVALID_PARAMETER KeyData is NULL or HelpString is NULL on register.
5882 @retval EFI_NOT_FOUND KeyData is not found to be unregistered.
5883 @retval EFI_UNSUPPORTED Key represents a printable character. It is conflicted with Browser.
5888 IN EFI_INPUT_KEY
*KeyData
,
5890 IN UINT16 DefaultId
,
5891 IN EFI_STRING HelpString OPTIONAL
5894 BROWSER_HOT_KEY
*HotKey
;
5897 // Check input parameters.
5899 if (KeyData
== NULL
|| KeyData
->UnicodeChar
!= CHAR_NULL
||
5900 (Action
!= BROWSER_ACTION_UNREGISTER
&& HelpString
== NULL
)) {
5901 return EFI_INVALID_PARAMETER
;
5905 // Check whether the input KeyData is in BrowserHotKeyList.
5907 HotKey
= GetHotKeyFromRegisterList (KeyData
);
5910 // Unregister HotKey
5912 if (Action
== BROWSER_ACTION_UNREGISTER
) {
5913 if (HotKey
!= NULL
) {
5915 // The registered HotKey is found.
5916 // Remove it from List, and free its resource.
5918 RemoveEntryList (&HotKey
->Link
);
5919 FreePool (HotKey
->KeyData
);
5920 FreePool (HotKey
->HelpString
);
5924 // The registered HotKey is not found.
5926 return EFI_NOT_FOUND
;
5931 // Register HotKey into List.
5933 if (HotKey
== NULL
) {
5935 // Create new Key, and add it into List.
5937 HotKey
= AllocateZeroPool (sizeof (BROWSER_HOT_KEY
));
5938 ASSERT (HotKey
!= NULL
);
5939 HotKey
->Signature
= BROWSER_HOT_KEY_SIGNATURE
;
5940 HotKey
->KeyData
= AllocateCopyPool (sizeof (EFI_INPUT_KEY
), KeyData
);
5941 InsertTailList (&gBrowserHotKeyList
, &HotKey
->Link
);
5945 // Fill HotKey information.
5947 HotKey
->Action
= Action
;
5948 HotKey
->DefaultId
= DefaultId
;
5949 if (HotKey
->HelpString
!= NULL
) {
5950 FreePool (HotKey
->HelpString
);
5952 HotKey
->HelpString
= AllocateCopyPool (StrSize (HelpString
), HelpString
);
5958 Register Exit handler function.
5959 When more than one handler function is registered, the latter one will override the previous one.
5960 When NULL handler is specified, the previous Exit handler will be unregistered.
5962 @param[in] Handler Pointer to handler function.
5967 RegiserExitHandler (
5968 IN EXIT_HANDLER Handler
5971 ExitHandlerFunction
= Handler
;
5976 Check whether the browser data has been modified.
5978 @retval TRUE Browser data is modified.
5979 @retval FALSE No browser data is modified.
5984 IsBrowserDataModified (
5989 FORM_BROWSER_FORMSET
*FormSet
;
5991 switch (gBrowserSettingScope
) {
5993 if (gCurrentSelection
== NULL
) {
5996 return IsNvUpdateRequiredForForm (gCurrentSelection
->Form
);
5999 if (gCurrentSelection
== NULL
) {
6002 return IsNvUpdateRequiredForFormSet (gCurrentSelection
->FormSet
);
6005 Link
= GetFirstNode (&gBrowserFormSetList
);
6006 while (!IsNull (&gBrowserFormSetList
, Link
)) {
6007 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
6008 if (!ValidateFormSet(FormSet
)) {
6012 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
6015 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
6025 Execute the action requested by the Action parameter.
6027 @param[in] Action Execute the request action.
6028 @param[in] DefaultId The default Id info when need to load default value. Only used when Action is BROWSER_ACTION_DEFAULT.
6030 @retval EFI_SUCCESS Execute the request action succss.
6031 @retval EFI_INVALID_PARAMETER The input action value is invalid.
6042 FORM_BROWSER_FORMSET
*FormSet
;
6043 FORM_BROWSER_FORM
*Form
;
6045 if (gBrowserSettingScope
< SystemLevel
&& gCurrentSelection
== NULL
) {
6046 return EFI_NOT_READY
;
6049 Status
= EFI_SUCCESS
;
6052 if (gBrowserSettingScope
< SystemLevel
) {
6053 FormSet
= gCurrentSelection
->FormSet
;
6054 Form
= gCurrentSelection
->Form
;
6058 // Executet the discard action.
6060 if ((Action
& BROWSER_ACTION_DISCARD
) != 0) {
6061 Status
= DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
6062 if (EFI_ERROR (Status
)) {
6068 // Executet the difault action.
6070 if ((Action
& BROWSER_ACTION_DEFAULT
) != 0) {
6071 Status
= ExtractDefault (FormSet
, Form
, DefaultId
, gBrowserSettingScope
, GetDefaultForAll
, NULL
, FALSE
, FALSE
);
6072 if (EFI_ERROR (Status
)) {
6075 UpdateStatementStatus (FormSet
, Form
, gBrowserSettingScope
);
6079 // Executet the submit action.
6081 if ((Action
& BROWSER_ACTION_SUBMIT
) != 0) {
6082 Status
= SubmitForm (FormSet
, Form
, gBrowserSettingScope
);
6083 if (EFI_ERROR (Status
)) {
6089 // Executet the reset action.
6091 if ((Action
& BROWSER_ACTION_RESET
) != 0) {
6092 gResetRequired
= TRUE
;
6096 // Executet the exit action.
6098 if ((Action
& BROWSER_ACTION_EXIT
) != 0) {
6099 DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
6100 if (gBrowserSettingScope
== SystemLevel
) {
6101 if (ExitHandlerFunction
!= NULL
) {
6102 ExitHandlerFunction ();
6106 gExitRequired
= TRUE
;
6113 Create reminder to let user to choose save or discard the changed browser data.
6114 Caller can use it to actively check the changed browser data.
6116 @retval BROWSER_NO_CHANGES No browser data is changed.
6117 @retval BROWSER_SAVE_CHANGES The changed browser data is saved.
6118 @retval BROWSER_DISCARD_CHANGES The changed browser data is discard.
6119 @retval BROWSER_KEEP_CURRENT Browser keep current changes.
6129 FORM_BROWSER_FORMSET
*FormSet
;
6130 BOOLEAN IsDataChanged
;
6131 UINT32 DataSavedAction
;
6134 DataSavedAction
= BROWSER_NO_CHANGES
;
6135 IsDataChanged
= FALSE
;
6136 Link
= GetFirstNode (&gBrowserFormSetList
);
6137 while (!IsNull (&gBrowserFormSetList
, Link
)) {
6138 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
6139 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
6140 if (!ValidateFormSet(FormSet
)) {
6143 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
6144 IsDataChanged
= TRUE
;
6150 // No data is changed. No save is required.
6152 if (!IsDataChanged
) {
6153 return DataSavedAction
;
6157 // If data is changed, prompt user to save or discard it.
6160 ConfirmRet
= (UINT32
) mFormDisplay
->ConfirmDataChange();
6162 if (ConfirmRet
== BROWSER_ACTION_SUBMIT
) {
6163 SubmitForm (NULL
, NULL
, SystemLevel
);
6164 DataSavedAction
= BROWSER_SAVE_CHANGES
;
6166 } else if (ConfirmRet
== BROWSER_ACTION_DISCARD
) {
6167 DiscardForm (NULL
, NULL
, SystemLevel
);
6168 DataSavedAction
= BROWSER_DISCARD_CHANGES
;
6170 } else if (ConfirmRet
== BROWSER_ACTION_NONE
) {
6171 DataSavedAction
= BROWSER_KEEP_CURRENT
;
6176 return DataSavedAction
;
6180 Check whether the Reset Required for the browser
6182 @retval TRUE Browser required to reset after exit.
6183 @retval FALSE Browser not need to reset after exit.
6192 return gResetRequired
;