2 Entry and initialization module for the browser.
4 Copyright (c) 2007 - 2014, 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
,
35 IsBrowserDataModified
,
40 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
41 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
42 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL
*mPathFromText
;
43 EDKII_FORM_DISPLAY_ENGINE_PROTOCOL
*mFormDisplay
;
45 UINTN gBrowserContextCount
= 0;
46 LIST_ENTRY gBrowserContextList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserContextList
);
47 LIST_ENTRY gBrowserFormSetList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserFormSetList
);
48 LIST_ENTRY gBrowserHotKeyList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserHotKeyList
);
49 LIST_ENTRY gBrowserStorageList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserStorageList
);
51 BOOLEAN gFinishRetrieveCall
;
52 BOOLEAN gResetRequired
;
53 BOOLEAN gExitRequired
;
54 BROWSER_SETTING_SCOPE gBrowserSettingScope
= FormSetLevel
;
55 BOOLEAN mBrowserScopeFirstSet
= TRUE
;
56 EXIT_HANDLER ExitHandlerFunction
= NULL
;
57 FORM_BROWSER_FORMSET
*mSystemLevelFormSet
;
60 // Browser Global Strings
63 CHAR16
*mUnknownString
= L
"!";
65 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
67 extern UINT32 gBrowserStatus
;
68 extern CHAR16
*gErrorInfo
;
69 extern EFI_GUID mCurrentFormSetGuid
;
70 extern EFI_HII_HANDLE mCurrentHiiHandle
;
71 extern UINT16 mCurrentFormId
;
72 extern FORM_DISPLAY_ENGINE_FORM gDisplayFormData
;
75 Create a menu with specified formset GUID and form ID, and add it as a child
76 of the given parent menu.
78 @param HiiHandle Hii handle related to this formset.
79 @param FormSetGuid The Formset Guid of menu to be added.
80 @param FormId The Form ID of menu to be added.
81 @param QuestionId The question id of this menu to be added.
83 @return A pointer to the newly added menu or NULL if memory is insufficient.
88 IN EFI_HII_HANDLE HiiHandle
,
89 IN EFI_GUID
*FormSetGuid
,
94 FORM_ENTRY_INFO
*MenuList
;
96 MenuList
= AllocateZeroPool (sizeof (FORM_ENTRY_INFO
));
97 if (MenuList
== NULL
) {
101 MenuList
->Signature
= FORM_ENTRY_INFO_SIGNATURE
;
103 MenuList
->HiiHandle
= HiiHandle
;
104 CopyMem (&MenuList
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
105 MenuList
->FormId
= FormId
;
106 MenuList
->QuestionId
= QuestionId
;
109 // If parent is not specified, it is the root Form of a Formset
111 InsertTailList (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &MenuList
->Link
);
117 Return the form id for the input hiihandle and formset.
119 @param HiiHandle HiiHandle for FormSet.
120 @param FormSetGuid The Formset GUID of the menu to search.
122 @return First form's id for this form set.
127 IN EFI_HII_HANDLE HiiHandle
,
128 IN EFI_GUID
*FormSetGuid
132 FORM_BROWSER_FORM
*Form
;
134 Link
= GetFirstNode (&gCurrentSelection
->FormSet
->FormListHead
);
135 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
141 Search Menu with given FormSetGuid and FormId in all cached menu list.
143 @param HiiHandle HiiHandle for FormSet.
144 @param FormSetGuid The Formset GUID of the menu to search.
145 @param FormId The Form ID of menu to search.
147 @return A pointer to menu found or NULL if not found.
152 IN EFI_HII_HANDLE HiiHandle
,
153 IN EFI_GUID
*FormSetGuid
,
158 FORM_ENTRY_INFO
*MenuList
;
159 FORM_ENTRY_INFO
*RetMenu
;
160 EFI_FORM_ID FirstFormId
;
164 Link
= GetFirstNode (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
);
165 while (!IsNull (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, Link
)) {
166 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Link
);
167 Link
= GetNextNode (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, Link
);
170 // If already find the menu, free the menus behind it.
172 if (RetMenu
!= NULL
) {
173 RemoveEntryList (&MenuList
->Link
);
179 // Find the same FromSet.
181 if (MenuList
->HiiHandle
== HiiHandle
) {
182 if (CompareGuid (&MenuList
->FormSetGuid
, &gZeroGuid
)) {
184 // FormSetGuid is not specified.
187 } else if (CompareGuid (&MenuList
->FormSetGuid
, FormSetGuid
)) {
188 if (MenuList
->FormId
== FormId
) {
190 } else if (FormId
== 0 || MenuList
->FormId
== 0 ) {
191 FirstFormId
= GetFirstFormId (HiiHandle
, FormSetGuid
);
192 if ((FormId
== 0 && FirstFormId
== MenuList
->FormId
) || (MenuList
->FormId
==0 && FirstFormId
== FormId
)) {
204 Find parent menu for current menu.
206 @param CurrentMenu Current Menu
208 @retval The parent menu for current menu.
212 IN FORM_ENTRY_INFO
*CurrentMenu
215 FORM_ENTRY_INFO
*ParentMenu
;
218 if (CurrentMenu
->Link
.BackLink
!= &mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
) {
219 ParentMenu
= FORM_ENTRY_INFO_FROM_LINK (CurrentMenu
->Link
.BackLink
);
226 Free Menu list linked list.
228 @param MenuListHead One Menu list point in the menu list.
233 LIST_ENTRY
*MenuListHead
236 FORM_ENTRY_INFO
*MenuList
;
238 while (!IsListEmpty (MenuListHead
)) {
239 MenuList
= FORM_ENTRY_INFO_FROM_LINK (MenuListHead
->ForwardLink
);
240 RemoveEntryList (&MenuList
->Link
);
247 Load all hii formset to the browser.
255 FORM_BROWSER_FORMSET
*LocalFormSet
;
256 EFI_HII_HANDLE
*HiiHandles
;
260 FORM_BROWSER_FORMSET
*OldFormset
;
261 BOOLEAN OldRetrieveValue
;
263 OldFormset
= mSystemLevelFormSet
;
264 OldRetrieveValue
= gFinishRetrieveCall
;
265 gFinishRetrieveCall
= FALSE
;
268 // Get all the Hii handles
270 HiiHandles
= HiiGetHiiHandles (NULL
);
271 ASSERT (HiiHandles
!= NULL
);
274 // Search for formset of each class type
276 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
278 // Check HiiHandles[Index] does exist in global maintain list.
280 if (GetFormSetFromHiiHandle (HiiHandles
[Index
]) != NULL
) {
285 // Initilize FormSet Setting
287 LocalFormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
288 ASSERT (LocalFormSet
!= NULL
);
289 mSystemLevelFormSet
= LocalFormSet
;
291 ZeroMem (&ZeroGuid
, sizeof (ZeroGuid
));
292 Status
= InitializeFormSet (HiiHandles
[Index
], &ZeroGuid
, LocalFormSet
);
293 if (EFI_ERROR (Status
) || IsListEmpty (&LocalFormSet
->FormListHead
)) {
294 DestroyFormSet (LocalFormSet
);
297 InitializeCurrentSetting (LocalFormSet
);
300 // Initilize Questions' Value
302 Status
= LoadFormSetConfig (NULL
, LocalFormSet
);
303 if (EFI_ERROR (Status
)) {
304 DestroyFormSet (LocalFormSet
);
310 // Free resources, and restore gOldFormSet and gClassOfVfr
312 FreePool (HiiHandles
);
314 gFinishRetrieveCall
= OldRetrieveValue
;
315 mSystemLevelFormSet
= OldFormset
;
319 This is the routine which an external caller uses to direct the browser
320 where to obtain it's information.
323 @param This The Form Browser protocol instanse.
324 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
325 display a list of the formsets for the handles specified.
326 @param HandleCount The number of Handles specified in Handle.
327 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
328 field in the EFI_IFR_FORM_SET op-code for the specified
329 forms-based package. If FormSetGuid is NULL, then this
330 function will display the first found forms package.
331 @param FormId This field specifies which EFI_IFR_FORM to render as the first
332 displayable page. If this field has a value of 0x0000, then
333 the forms browser will render the specified forms in their encoded order.
334 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
336 @param ActionRequest Points to the action recommended by the form.
338 @retval EFI_SUCCESS The function completed successfully.
339 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
340 @retval EFI_NOT_FOUND No valid forms could be found to display.
346 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
347 IN EFI_HII_HANDLE
*Handles
,
348 IN UINTN HandleCount
,
349 IN EFI_GUID
*FormSetGuid
, OPTIONAL
350 IN UINT16 FormId
, OPTIONAL
351 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
352 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
356 UI_MENU_SELECTION
*Selection
;
358 FORM_BROWSER_FORMSET
*FormSet
;
359 FORM_ENTRY_INFO
*MenuList
;
362 // If EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found, return EFI_UNSUPPORTED.
364 if (mFormDisplay
== NULL
) {
365 return EFI_UNSUPPORTED
;
369 // Save globals used by SendForm()
371 SaveBrowserContext ();
373 gFinishRetrieveCall
= FALSE
;
374 gResetRequired
= FALSE
;
375 gExitRequired
= FALSE
;
376 Status
= EFI_SUCCESS
;
378 gDisplayFormData
.ScreenDimensions
= (EFI_SCREEN_DESCRIPTOR
*) ScreenDimensions
;
380 for (Index
= 0; Index
< HandleCount
; Index
++) {
381 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
382 ASSERT (Selection
!= NULL
);
384 Selection
->Handle
= Handles
[Index
];
385 if (FormSetGuid
!= NULL
) {
386 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
387 Selection
->FormId
= FormId
;
389 CopyMem (&Selection
->FormSetGuid
, &gEfiHiiPlatformSetupFormsetGuid
, sizeof (EFI_GUID
));
393 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
394 ASSERT (FormSet
!= NULL
);
397 // Initialize internal data structures of FormSet
399 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
400 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
401 DestroyFormSet (FormSet
);
404 Selection
->FormSet
= FormSet
;
405 mSystemLevelFormSet
= FormSet
;
408 // Display this formset
410 gCurrentSelection
= Selection
;
412 Status
= SetupBrowser (Selection
);
414 gCurrentSelection
= NULL
;
415 mSystemLevelFormSet
= NULL
;
418 // If no data is changed, don't need to save current FormSet into the maintain list.
420 if (!IsNvUpdateRequiredForFormSet (FormSet
) && !IsStorageDataChangedForFormSet(FormSet
)) {
421 CleanBrowserStorage(FormSet
);
422 RemoveEntryList (&FormSet
->Link
);
423 DestroyFormSet (FormSet
);
426 if (EFI_ERROR (Status
)) {
429 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
431 FreePool (Selection
);
435 // Still has error info, pop up a message.
437 if (gBrowserStatus
!= BROWSER_SUCCESS
) {
438 gDisplayFormData
.BrowserStatus
= gBrowserStatus
;
439 gDisplayFormData
.ErrorString
= gErrorInfo
;
441 gBrowserStatus
= BROWSER_SUCCESS
;
444 mFormDisplay
->FormDisplay (&gDisplayFormData
, NULL
);
447 if (ActionRequest
!= NULL
) {
448 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
449 if (gResetRequired
) {
450 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
454 mFormDisplay
->ExitDisplay();
457 // Clear the menu history data.
459 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
460 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
461 RemoveEntryList (&MenuList
->Link
);
466 // Restore globals used by SendForm()
468 RestoreBrowserContext ();
474 Get or set data to the storage.
476 @param ResultsDataSize The size of the buffer associatedwith ResultsData.
477 @param ResultsData A string returned from an IFR browser or
478 equivalent. The results string will have no
479 routing information in them.
480 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
481 (if RetrieveData = TRUE) data from the uncommitted
482 browser state information or set (if RetrieveData
483 = FALSE) data in the uncommitted browser state
485 @param Storage The pointer to the storage.
487 @retval EFI_SUCCESS The results have been distributed or are awaiting
493 IN OUT UINTN
*ResultsDataSize
,
494 IN OUT EFI_STRING
*ResultsData
,
495 IN BOOLEAN RetrieveData
,
496 IN BROWSER_STORAGE
*Storage
507 // Generate <ConfigResp>
509 Status
= StorageToConfigResp (Storage
, &ConfigResp
, Storage
->ConfigRequest
, TRUE
);
510 if (EFI_ERROR (Status
)) {
515 // Skip <ConfigHdr> and '&' to point to <ConfigBody> when first copy the configbody.
516 // Also need to consider add "\0" at first time.
518 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
519 BufferSize
= StrSize (StrPtr
);
523 // Copy the data if the input buffer is bigger enough.
525 if (*ResultsDataSize
>= BufferSize
) {
526 StrCpy (*ResultsData
, StrPtr
);
529 *ResultsDataSize
= BufferSize
;
530 FreePool (ConfigResp
);
533 // Prepare <ConfigResp>
535 TmpSize
= StrLen (*ResultsData
);
536 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
537 ConfigResp
= AllocateZeroPool (BufferSize
);
538 ASSERT (ConfigResp
!= NULL
);
540 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
541 StrCat (ConfigResp
, L
"&");
542 StrCat (ConfigResp
, *ResultsData
);
545 // Update Browser uncommited data
547 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
548 FreePool (ConfigResp
);
549 if (EFI_ERROR (Status
)) {
558 This routine called this service in the browser to retrieve or set certain uncommitted
559 state information that resides in the open formsets.
561 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
563 @param ResultsDataSize A pointer to the size of the buffer associated
565 @param ResultsData A string returned from an IFR browser or
566 equivalent. The results string will have no
567 routing information in them.
568 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
569 (if RetrieveData = TRUE) data from the uncommitted
570 browser state information or set (if RetrieveData
571 = FALSE) data in the uncommitted browser state
573 @param VariableGuid An optional field to indicate the target variable
575 @param VariableName An optional field to indicate the target
576 human-readable variable name.
578 @retval EFI_SUCCESS The results have been distributed or are awaiting
580 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
581 contain the results data.
587 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
588 IN OUT UINTN
*ResultsDataSize
,
589 IN OUT EFI_STRING ResultsData
,
590 IN BOOLEAN RetrieveData
,
591 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
592 IN CONST CHAR16
*VariableName OPTIONAL
597 BROWSER_STORAGE
*Storage
;
598 FORMSET_STORAGE
*FormsetStorage
;
602 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
603 return EFI_INVALID_PARAMETER
;
606 TotalSize
= *ResultsDataSize
;
609 Status
= EFI_SUCCESS
;
612 // If set browser data, pre load all hii formset to avoid set the varstore which is not
615 if (!RetrieveData
&& (gBrowserSettingScope
== SystemLevel
)) {
619 if (VariableGuid
!= NULL
) {
621 // Try to find target storage in the current formset.
623 Link
= GetFirstNode (&gBrowserStorageList
);
624 while (!IsNull (&gBrowserStorageList
, Link
)) {
625 Storage
= BROWSER_STORAGE_FROM_LINK (Link
);
626 Link
= GetNextNode (&gBrowserStorageList
, Link
);
628 // Check the current storage.
630 if (!CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
634 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
635 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
637 // Buffer storage require both GUID and Name
639 if (VariableName
== NULL
) {
640 return EFI_NOT_FOUND
;
643 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
648 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
||
649 Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
650 if (mSystemLevelFormSet
== NULL
|| mSystemLevelFormSet
->HiiHandle
== NULL
) {
651 return EFI_NOT_FOUND
;
654 if (Storage
->HiiHandle
!= mSystemLevelFormSet
->HiiHandle
) {
659 Status
= ProcessStorage (&TotalSize
, &ResultsData
, RetrieveData
, Storage
);
660 if (EFI_ERROR (Status
)) {
665 // Different formsets may have same varstore, so here just set the flag
666 // not exit the circle.
673 return EFI_NOT_FOUND
;
677 // GUID/Name is not specified, take the first storage in FormSet
679 if (mSystemLevelFormSet
== NULL
) {
680 return EFI_NOT_READY
;
684 // Generate <ConfigResp>
686 Link
= GetFirstNode (&mSystemLevelFormSet
->StorageListHead
);
687 if (IsNull (&mSystemLevelFormSet
->StorageListHead
, Link
)) {
688 return EFI_UNSUPPORTED
;
691 FormsetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
693 Status
= ProcessStorage (&TotalSize
, &ResultsData
, RetrieveData
, FormsetStorage
->BrowserStorage
);
694 if (EFI_ERROR (Status
)) {
700 Status
= TotalSize
<= *ResultsDataSize
? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
701 *ResultsDataSize
= TotalSize
;
710 Callback function for SimpleTextInEx protocol install events
712 @param Event the event that is signaled.
713 @param Context not used here.
718 FormDisplayCallback (
725 if (mFormDisplay
!= NULL
) {
729 Status
= gBS
->LocateProtocol (
730 &gEdkiiFormDisplayEngineProtocolGuid
,
732 (VOID
**) &mFormDisplay
737 Initialize Setup Browser driver.
739 @param ImageHandle The image handle.
740 @param SystemTable The system table.
742 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
743 @return Other value if failed to initialize the Setup Browser module.
749 IN EFI_HANDLE ImageHandle
,
750 IN EFI_SYSTEM_TABLE
*SystemTable
757 // Locate required Hii relative protocols
759 Status
= gBS
->LocateProtocol (
760 &gEfiHiiDatabaseProtocolGuid
,
762 (VOID
**) &mHiiDatabase
764 ASSERT_EFI_ERROR (Status
);
766 Status
= gBS
->LocateProtocol (
767 &gEfiHiiConfigRoutingProtocolGuid
,
769 (VOID
**) &mHiiConfigRouting
771 ASSERT_EFI_ERROR (Status
);
773 Status
= gBS
->LocateProtocol (
774 &gEfiDevicePathFromTextProtocolGuid
,
776 (VOID
**) &mPathFromText
780 // Install FormBrowser2 protocol
782 mPrivateData
.Handle
= NULL
;
783 Status
= gBS
->InstallProtocolInterface (
784 &mPrivateData
.Handle
,
785 &gEfiFormBrowser2ProtocolGuid
,
786 EFI_NATIVE_INTERFACE
,
787 &mPrivateData
.FormBrowser2
789 ASSERT_EFI_ERROR (Status
);
792 // Install FormBrowserEx2 protocol
794 InitializeListHead (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
);
795 InitializeListHead (&mPrivateData
.FormBrowserEx2
.OverrideQestListHead
);
796 mPrivateData
.Handle
= NULL
;
797 Status
= gBS
->InstallProtocolInterface (
798 &mPrivateData
.Handle
,
799 &gEdkiiFormBrowserEx2ProtocolGuid
,
800 EFI_NATIVE_INTERFACE
,
801 &mPrivateData
.FormBrowserEx2
803 ASSERT_EFI_ERROR (Status
);
805 Status
= gBS
->InstallProtocolInterface (
806 &mPrivateData
.Handle
,
807 &gEfiFormBrowserExProtocolGuid
,
808 EFI_NATIVE_INTERFACE
,
809 &mPrivateData
.FormBrowserEx
811 ASSERT_EFI_ERROR (Status
);
813 InitializeDisplayFormData ();
815 Status
= gBS
->LocateProtocol (
816 &gEdkiiFormDisplayEngineProtocolGuid
,
818 (VOID
**) &mFormDisplay
821 if (EFI_ERROR (Status
)) {
822 EfiCreateProtocolNotifyEvent (
823 &gEdkiiFormDisplayEngineProtocolGuid
,
836 Create a new string in HII Package List.
838 @param String The String to be added
839 @param HiiHandle The package list in the HII database to insert the
842 @return The output string.
848 IN EFI_HII_HANDLE HiiHandle
851 EFI_STRING_ID StringId
;
853 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
854 ASSERT (StringId
!= 0);
861 Delete a string from HII Package List.
863 @param StringId Id of the string in HII database.
864 @param HiiHandle The HII package list handle.
866 @retval EFI_SUCCESS The string was deleted successfully.
871 IN EFI_STRING_ID StringId
,
872 IN EFI_HII_HANDLE HiiHandle
877 NullChar
= CHAR_NULL
;
878 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
884 Get the string based on the StringId and HII Package List Handle.
886 @param Token The String's ID.
887 @param HiiHandle The package list in the HII database to search for
888 the specified string.
890 @return The output string.
895 IN EFI_STRING_ID Token
,
896 IN EFI_HII_HANDLE HiiHandle
901 if (HiiHandle
== NULL
) {
905 String
= HiiGetString (HiiHandle
, Token
, NULL
);
906 if (String
== NULL
) {
907 String
= AllocateCopyPool (StrSize (mUnknownString
), mUnknownString
);
908 ASSERT (String
!= NULL
);
910 return (CHAR16
*) String
;
915 Allocate new memory and then copy the Unicode string Source to Destination.
917 @param Dest Location to copy string
918 @param Src String to copy
923 IN OUT CHAR16
**Dest
,
930 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
931 ASSERT (*Dest
!= NULL
);
936 Allocate new memory and concatinate Source on the end of Destination.
938 @param Dest String to added to the end of.
939 @param Src String to concatinate.
944 IN OUT CHAR16
**Dest
,
952 NewStringCpy (Dest
, Src
);
956 TmpSize
= StrSize (*Dest
);
957 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
958 ASSERT (NewString
!= NULL
);
960 StrCpy (NewString
, *Dest
);
961 StrCat (NewString
, Src
);
968 Get Value for given Name from a NameValue Storage.
970 @param Storage The NameValue Storage.
971 @param Name The Name.
972 @param Value The retured Value.
973 @param GetValueFrom Where to get source value, from EditValue or Value.
975 @retval EFI_SUCCESS Value found for given Name.
976 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
981 IN BROWSER_STORAGE
*Storage
,
983 IN OUT CHAR16
**Value
,
984 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
988 NAME_VALUE_NODE
*Node
;
990 if (GetValueFrom
!= GetSetValueWithEditBuffer
&& GetValueFrom
!= GetSetValueWithBuffer
) {
991 return EFI_INVALID_PARAMETER
;
996 Link
= GetFirstNode (&Storage
->NameValueListHead
);
997 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
998 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1000 if (StrCmp (Name
, Node
->Name
) == 0) {
1001 if (GetValueFrom
== GetSetValueWithEditBuffer
) {
1002 NewStringCpy (Value
, Node
->EditValue
);
1004 NewStringCpy (Value
, Node
->Value
);
1009 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1012 return EFI_NOT_FOUND
;
1017 Set Value of given Name in a NameValue Storage.
1019 @param Storage The NameValue Storage.
1020 @param Name The Name.
1021 @param Value The Value to set.
1022 @param SetValueTo Whether update editValue or Value.
1023 @param ReturnNode The node use the input name.
1025 @retval EFI_SUCCESS Value found for given Name.
1026 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
1031 IN BROWSER_STORAGE
*Storage
,
1034 IN GET_SET_QUESTION_VALUE_WITH SetValueTo
,
1035 OUT NAME_VALUE_NODE
**ReturnNode
1039 NAME_VALUE_NODE
*Node
;
1042 if (SetValueTo
!= GetSetValueWithEditBuffer
&& SetValueTo
!= GetSetValueWithBuffer
) {
1043 return EFI_INVALID_PARAMETER
;
1046 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1047 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1048 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1050 if (StrCmp (Name
, Node
->Name
) == 0) {
1051 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1052 Buffer
= Node
->EditValue
;
1054 Buffer
= Node
->Value
;
1056 if (Buffer
!= NULL
) {
1059 Buffer
= AllocateCopyPool (StrSize (Value
), Value
);
1060 ASSERT (Buffer
!= NULL
);
1061 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1062 Node
->EditValue
= Buffer
;
1064 Node
->Value
= Buffer
;
1067 if (ReturnNode
!= NULL
) {
1074 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1077 return EFI_NOT_FOUND
;
1082 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
1084 @param Storage The Storage to be conveted.
1085 @param ConfigResp The returned <ConfigResp>.
1086 @param ConfigRequest The ConfigRequest string.
1087 @param GetEditBuf Get the data from editbuffer or buffer.
1089 @retval EFI_SUCCESS Convert success.
1090 @retval EFI_INVALID_PARAMETER Incorrect storage type.
1094 StorageToConfigResp (
1095 IN BROWSER_STORAGE
*Storage
,
1096 IN CHAR16
**ConfigResp
,
1097 IN CHAR16
*ConfigRequest
,
1098 IN BOOLEAN GetEditBuf
1102 EFI_STRING Progress
;
1104 NAME_VALUE_NODE
*Node
;
1107 Status
= EFI_SUCCESS
;
1109 switch (Storage
->Type
) {
1110 case EFI_HII_VARSTORE_BUFFER
:
1111 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
1112 SourceBuf
= GetEditBuf
? Storage
->EditBuffer
: Storage
->Buffer
;
1113 Status
= mHiiConfigRouting
->BlockToConfig (
1123 case EFI_HII_VARSTORE_NAME_VALUE
:
1125 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
1127 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1128 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1129 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1131 if (StrStr (ConfigRequest
, Node
->Name
) != NULL
) {
1132 NewStringCat (ConfigResp
, L
"&");
1133 NewStringCat (ConfigResp
, Node
->Name
);
1134 NewStringCat (ConfigResp
, L
"=");
1136 NewStringCat (ConfigResp
, Node
->EditValue
);
1138 NewStringCat (ConfigResp
, Node
->Value
);
1141 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1145 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1147 Status
= EFI_INVALID_PARAMETER
;
1156 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
1158 @param Storage The Storage to receive the settings.
1159 @param ConfigResp The <ConfigResp> to be converted.
1161 @retval EFI_SUCCESS Convert success.
1162 @retval EFI_INVALID_PARAMETER Incorrect storage type.
1166 ConfigRespToStorage (
1167 IN BROWSER_STORAGE
*Storage
,
1168 IN CHAR16
*ConfigResp
1172 EFI_STRING Progress
;
1178 Status
= EFI_SUCCESS
;
1180 switch (Storage
->Type
) {
1181 case EFI_HII_VARSTORE_BUFFER
:
1182 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
1183 BufferSize
= Storage
->Size
;
1184 Status
= mHiiConfigRouting
->ConfigToBlock (
1187 Storage
->EditBuffer
,
1193 case EFI_HII_VARSTORE_NAME_VALUE
:
1194 StrPtr
= StrStr (ConfigResp
, L
"PATH");
1195 if (StrPtr
== NULL
) {
1198 StrPtr
= StrStr (ConfigResp
, L
"&");
1199 while (StrPtr
!= NULL
) {
1203 StrPtr
= StrPtr
+ 1;
1205 StrPtr
= StrStr (StrPtr
, L
"=");
1206 if (StrPtr
== NULL
) {
1214 StrPtr
= StrPtr
+ 1;
1216 StrPtr
= StrStr (StrPtr
, L
"&");
1217 if (StrPtr
!= NULL
) {
1220 SetValueByName (Storage
, Name
, Value
, GetSetValueWithEditBuffer
, NULL
);
1224 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1226 Status
= EFI_INVALID_PARAMETER
;
1235 Get Question's current Value.
1237 @param FormSet FormSet data structure.
1238 @param Form Form data structure.
1239 @param Question Question to be initialized.
1240 @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver.
1242 @retval EFI_SUCCESS The function completed successfully.
1247 IN FORM_BROWSER_FORMSET
*FormSet
,
1248 IN FORM_BROWSER_FORM
*Form
,
1249 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1250 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
1259 BROWSER_STORAGE
*Storage
;
1260 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1261 CHAR16
*ConfigRequest
;
1269 BOOLEAN IsBufferStorage
;
1274 Status
= EFI_SUCCESS
;
1278 if (GetValueFrom
>= GetSetValueWithMax
) {
1279 return EFI_INVALID_PARAMETER
;
1283 // Question value is provided by an Expression, evaluate it
1285 if (Question
->ValueExpression
!= NULL
) {
1286 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1287 if (!EFI_ERROR (Status
)) {
1288 if (Question
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1289 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1290 if (Question
->StorageWidth
> Question
->ValueExpression
->Result
.BufferLen
) {
1291 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->ValueExpression
->Result
.BufferLen
);
1292 Question
->HiiValue
.BufferLen
= Question
->ValueExpression
->Result
.BufferLen
;
1294 CopyMem (Question
->HiiValue
.Buffer
, Question
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
1295 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1297 FreePool (Question
->ValueExpression
->Result
.Buffer
);
1299 Question
->HiiValue
.Type
= Question
->ValueExpression
->Result
.Type
;
1300 CopyMem (&Question
->HiiValue
.Value
, &Question
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1306 // Get question value by read expression.
1308 if (Question
->ReadExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1309 Status
= EvaluateExpression (FormSet
, Form
, Question
->ReadExpression
);
1310 if (!EFI_ERROR (Status
) &&
1311 ((Question
->ReadExpression
->Result
.Type
< EFI_IFR_TYPE_OTHER
) || (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
))) {
1313 // Only update question value to the valid result.
1315 if (Question
->ReadExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
1316 ASSERT (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
&& Question
->HiiValue
.Buffer
!= NULL
);
1317 if (Question
->StorageWidth
> Question
->ReadExpression
->Result
.BufferLen
) {
1318 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->ReadExpression
->Result
.BufferLen
);
1319 Question
->HiiValue
.BufferLen
= Question
->ReadExpression
->Result
.BufferLen
;
1321 CopyMem (Question
->HiiValue
.Buffer
, Question
->ReadExpression
->Result
.Buffer
, Question
->StorageWidth
);
1322 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
1324 FreePool (Question
->ReadExpression
->Result
.Buffer
);
1326 Question
->HiiValue
.Type
= Question
->ReadExpression
->Result
.Type
;
1327 CopyMem (&Question
->HiiValue
.Value
, &Question
->ReadExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1333 // Question value is provided by RTC
1335 Storage
= Question
->Storage
;
1336 QuestionValue
= &Question
->HiiValue
.Value
;
1337 if (Storage
== NULL
) {
1339 // It's a Question without storage, or RTC date/time
1341 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1343 // Date and time define the same Flags bit
1345 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1346 case QF_DATE_STORAGE_TIME
:
1347 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1350 case QF_DATE_STORAGE_WAKEUP
:
1351 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1354 case QF_DATE_STORAGE_NORMAL
:
1357 // For date/time without storage
1362 if (EFI_ERROR (Status
)) {
1366 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1367 QuestionValue
->date
.Year
= EfiTime
.Year
;
1368 QuestionValue
->date
.Month
= EfiTime
.Month
;
1369 QuestionValue
->date
.Day
= EfiTime
.Day
;
1371 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1372 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1373 QuestionValue
->time
.Second
= EfiTime
.Second
;
1381 // Question value is provided by EFI variable
1383 StorageWidth
= Question
->StorageWidth
;
1384 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1385 if (Question
->BufferValue
!= NULL
) {
1386 Dst
= Question
->BufferValue
;
1388 Dst
= (UINT8
*) QuestionValue
;
1391 Status
= gRT
->GetVariable (
1392 Question
->VariableName
,
1399 // Always return success, even this EFI variable doesn't exist
1405 // Question Value is provided by Buffer Storage or NameValue Storage
1407 if (Question
->BufferValue
!= NULL
) {
1409 // This Question is password or orderedlist
1411 Dst
= Question
->BufferValue
;
1414 // Other type of Questions
1416 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1419 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1420 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1421 IsBufferStorage
= TRUE
;
1423 IsBufferStorage
= FALSE
;
1425 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1426 if (GetValueFrom
== GetSetValueWithEditBuffer
|| GetValueFrom
== GetSetValueWithBuffer
) {
1427 if (IsBufferStorage
) {
1428 if (GetValueFrom
== GetSetValueWithEditBuffer
) {
1430 // Copy from storage Edit buffer
1432 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1435 // Copy from storage Edit buffer
1437 CopyMem (Dst
, Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1441 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
, GetValueFrom
);
1442 if (EFI_ERROR (Status
)) {
1446 ASSERT (Value
!= NULL
);
1447 LengthStr
= StrLen (Value
);
1448 Status
= EFI_SUCCESS
;
1451 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1452 // Add string tail char L'\0' into Length
1454 Length
= StorageWidth
+ sizeof (CHAR16
);
1455 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1456 Status
= EFI_BUFFER_TOO_SMALL
;
1458 StringPtr
= (CHAR16
*) Dst
;
1459 ZeroMem (TemStr
, sizeof (TemStr
));
1460 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1461 StrnCpy (TemStr
, Value
+ Index
, 4);
1462 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1465 // Add tailing L'\0' character
1467 StringPtr
[Index
/4] = L
'\0';
1470 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1471 Status
= EFI_BUFFER_TOO_SMALL
;
1473 ZeroMem (TemStr
, sizeof (TemStr
));
1474 for (Index
= 0; Index
< LengthStr
; Index
++) {
1475 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1476 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1477 if ((Index
& 1) == 0) {
1478 Dst
[Index
/2] = DigitUint8
;
1480 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1490 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1491 // <ConfigHdr> + "&" + <VariableName>
1493 if (IsBufferStorage
) {
1494 Length
= StrLen (Storage
->ConfigHdr
);
1495 Length
+= StrLen (Question
->BlockName
);
1497 Length
= StrLen (Storage
->ConfigHdr
);
1498 Length
+= StrLen (Question
->VariableName
) + 1;
1500 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1501 ASSERT (ConfigRequest
!= NULL
);
1503 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1504 if (IsBufferStorage
) {
1505 StrCat (ConfigRequest
, Question
->BlockName
);
1507 StrCat (ConfigRequest
, L
"&");
1508 StrCat (ConfigRequest
, Question
->VariableName
);
1512 // Request current settings from Configuration Driver
1514 Status
= mHiiConfigRouting
->ExtractConfig (
1520 FreePool (ConfigRequest
);
1521 if (EFI_ERROR (Status
)) {
1526 // Skip <ConfigRequest>
1528 if (IsBufferStorage
) {
1529 Value
= StrStr (Result
, L
"&VALUE");
1530 if (Value
== NULL
) {
1532 return EFI_NOT_FOUND
;
1539 Value
= Result
+ Length
;
1541 if (*Value
!= '=') {
1543 return EFI_NOT_FOUND
;
1546 // Skip '=', point to value
1551 // Suppress <AltResp> if any
1554 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1559 LengthStr
= StrLen (Value
);
1560 Status
= EFI_SUCCESS
;
1561 if (!IsBufferStorage
&& IsString
) {
1563 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1564 // Add string tail char L'\0' into Length
1566 Length
= StorageWidth
+ sizeof (CHAR16
);
1567 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1568 Status
= EFI_BUFFER_TOO_SMALL
;
1570 StringPtr
= (CHAR16
*) Dst
;
1571 ZeroMem (TemStr
, sizeof (TemStr
));
1572 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1573 StrnCpy (TemStr
, Value
+ Index
, 4);
1574 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1577 // Add tailing L'\0' character
1579 StringPtr
[Index
/4] = L
'\0';
1582 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1583 Status
= EFI_BUFFER_TOO_SMALL
;
1585 ZeroMem (TemStr
, sizeof (TemStr
));
1586 for (Index
= 0; Index
< LengthStr
; Index
++) {
1587 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1588 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1589 if ((Index
& 1) == 0) {
1590 Dst
[Index
/2] = DigitUint8
;
1592 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1598 if (EFI_ERROR (Status
)) {
1604 // Synchronize Edit Buffer
1606 if (IsBufferStorage
) {
1607 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1609 SetValueByName (Storage
, Question
->VariableName
, Value
, GetSetValueWithEditBuffer
, NULL
);
1612 if (Result
!= NULL
) {
1622 Save Question Value to edit copy(cached) or Storage(uncached).
1624 @param FormSet FormSet data structure.
1625 @param Form Form data structure.
1626 @param Question Pointer to the Question.
1627 @param SetValueTo Update the question value to editbuffer , buffer or hii driver.
1629 @retval EFI_SUCCESS The function completed successfully.
1634 IN FORM_BROWSER_FORMSET
*FormSet
,
1635 IN FORM_BROWSER_FORM
*Form
,
1636 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1637 IN GET_SET_QUESTION_VALUE_WITH SetValueTo
1647 BROWSER_STORAGE
*Storage
;
1648 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1653 BOOLEAN IsBufferStorage
;
1659 NAME_VALUE_NODE
*Node
;
1661 Status
= EFI_SUCCESS
;
1664 if (SetValueTo
>= GetSetValueWithMax
) {
1665 return EFI_INVALID_PARAMETER
;
1669 // If Question value is provided by an Expression, then it is read only
1671 if (Question
->ValueExpression
!= NULL
) {
1676 // Before set question value, evaluate its write expression.
1678 if (Question
->WriteExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1679 Status
= EvaluateExpression (FormSet
, Form
, Question
->WriteExpression
);
1680 if (EFI_ERROR (Status
)) {
1686 // Question value is provided by RTC
1688 Storage
= Question
->Storage
;
1689 QuestionValue
= &Question
->HiiValue
.Value
;
1690 if (Storage
== NULL
) {
1692 // It's a Question without storage, or RTC date/time
1694 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1696 // Date and time define the same Flags bit
1698 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1699 case QF_DATE_STORAGE_TIME
:
1700 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1703 case QF_DATE_STORAGE_WAKEUP
:
1704 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1707 case QF_DATE_STORAGE_NORMAL
:
1710 // For date/time without storage
1715 if (EFI_ERROR (Status
)) {
1719 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1720 EfiTime
.Year
= QuestionValue
->date
.Year
;
1721 EfiTime
.Month
= QuestionValue
->date
.Month
;
1722 EfiTime
.Day
= QuestionValue
->date
.Day
;
1724 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1725 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1726 EfiTime
.Second
= QuestionValue
->time
.Second
;
1729 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1730 Status
= gRT
->SetTime (&EfiTime
);
1732 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1740 // Question value is provided by EFI variable
1742 StorageWidth
= Question
->StorageWidth
;
1743 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1744 if (Question
->BufferValue
!= NULL
) {
1745 Src
= Question
->BufferValue
;
1747 Src
= (UINT8
*) QuestionValue
;
1750 Status
= gRT
->SetVariable (
1751 Question
->VariableName
,
1753 Storage
->Attributes
,
1761 // Question Value is provided by Buffer Storage or NameValue Storage
1763 if (Question
->BufferValue
!= NULL
) {
1764 Src
= Question
->BufferValue
;
1766 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1769 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
1770 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
1771 IsBufferStorage
= TRUE
;
1773 IsBufferStorage
= FALSE
;
1775 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1777 if (SetValueTo
== GetSetValueWithEditBuffer
|| SetValueTo
== GetSetValueWithBuffer
) {
1778 if (IsBufferStorage
) {
1779 if (SetValueTo
== GetSetValueWithEditBuffer
) {
1781 // Copy to storage edit buffer
1783 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1784 } else if (SetValueTo
== GetSetValueWithBuffer
) {
1786 // Copy to storage edit buffer
1788 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1793 // Allocate enough string buffer.
1796 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1797 Value
= AllocateZeroPool (BufferLen
);
1798 ASSERT (Value
!= NULL
);
1800 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1802 TemName
= (CHAR16
*) Src
;
1804 for (; *TemName
!= L
'\0'; TemName
++) {
1805 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1808 BufferLen
= StorageWidth
* 2 + 1;
1809 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1810 ASSERT (Value
!= NULL
);
1812 // Convert Buffer to Hex String
1814 TemBuffer
= Src
+ StorageWidth
- 1;
1816 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1817 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1821 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
, SetValueTo
, &Node
);
1823 if (EFI_ERROR (Status
)) {
1827 } else if (SetValueTo
== GetSetValueWithHiiDriver
) {
1829 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1830 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1832 if (IsBufferStorage
) {
1833 Length
= StrLen (Question
->BlockName
) + 7;
1835 Length
= StrLen (Question
->VariableName
) + 2;
1837 if (!IsBufferStorage
&& IsString
) {
1838 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1840 Length
+= (StorageWidth
* 2);
1842 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1843 ASSERT (ConfigResp
!= NULL
);
1845 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1846 if (IsBufferStorage
) {
1847 StrCat (ConfigResp
, Question
->BlockName
);
1848 StrCat (ConfigResp
, L
"&VALUE=");
1850 StrCat (ConfigResp
, L
"&");
1851 StrCat (ConfigResp
, Question
->VariableName
);
1852 StrCat (ConfigResp
, L
"=");
1855 Value
= ConfigResp
+ StrLen (ConfigResp
);
1857 if (!IsBufferStorage
&& IsString
) {
1859 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1861 TemName
= (CHAR16
*) Src
;
1863 for (; *TemName
!= L
'\0'; TemName
++) {
1864 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1868 // Convert Buffer to Hex String
1870 TemBuffer
= Src
+ StorageWidth
- 1;
1872 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1873 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1878 // Convert to lower char.
1880 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
1881 if (*Value
>= L
'A' && *Value
<= L
'Z') {
1882 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
1887 // Submit Question Value to Configuration Driver
1889 Status
= mHiiConfigRouting
->RouteConfig (
1894 if (EFI_ERROR (Status
)) {
1895 FreePool (ConfigResp
);
1898 FreePool (ConfigResp
);
1901 // Sync storage, from editbuffer to buffer.
1903 CopyMem (Storage
->Buffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1911 Perform nosubmitif check for a Form.
1913 @param FormSet FormSet data structure.
1914 @param Form Form data structure.
1915 @param Question The Question to be validated.
1916 @param Type Validation type: NoSubmit
1918 @retval EFI_SUCCESS Form validation pass.
1919 @retval other Form validation failed.
1924 IN FORM_BROWSER_FORMSET
*FormSet
,
1925 IN FORM_BROWSER_FORM
*Form
,
1926 IN FORM_BROWSER_STATEMENT
*Question
,
1932 LIST_ENTRY
*ListHead
;
1934 FORM_EXPRESSION
*Expression
;
1936 if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1937 ListHead
= &Question
->NoSubmitListHead
;
1939 return EFI_UNSUPPORTED
;
1942 Link
= GetFirstNode (ListHead
);
1943 while (!IsNull (ListHead
, Link
)) {
1944 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1947 // Evaluate the expression
1949 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1950 if (EFI_ERROR (Status
)) {
1954 if ((Expression
->Result
.Type
== EFI_IFR_TYPE_BOOLEAN
) && Expression
->Result
.Value
.b
) {
1956 // Condition meet, show up error message
1958 if (Expression
->Error
!= 0) {
1959 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1960 if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1961 gBrowserStatus
= BROWSER_NO_SUBMIT_IF
;
1966 return EFI_NOT_READY
;
1969 Link
= GetNextNode (ListHead
, Link
);
1977 Perform NoSubmit check for each Form in FormSet.
1979 @param FormSet FormSet data structure.
1980 @param CurrentForm Current input form data structure.
1982 @retval EFI_SUCCESS Form validation pass.
1983 @retval other Form validation failed.
1988 IN FORM_BROWSER_FORMSET
*FormSet
,
1989 IN FORM_BROWSER_FORM
*CurrentForm
1994 FORM_BROWSER_STATEMENT
*Question
;
1995 FORM_BROWSER_FORM
*Form
;
1996 LIST_ENTRY
*LinkForm
;
1998 LinkForm
= GetFirstNode (&FormSet
->FormListHead
);
1999 while (!IsNull (&FormSet
->FormListHead
, LinkForm
)) {
2000 Form
= FORM_BROWSER_FORM_FROM_LINK (LinkForm
);
2001 LinkForm
= GetNextNode (&FormSet
->FormListHead
, LinkForm
);
2003 if (CurrentForm
!= NULL
&& CurrentForm
!= Form
) {
2007 Link
= GetFirstNode (&Form
->StatementListHead
);
2008 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2009 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2011 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
2012 if (EFI_ERROR (Status
)) {
2016 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2024 Fill storage's edit copy with settings requested from Configuration Driver.
2026 @param FormSet FormSet data structure.
2027 @param Storage The storage which need to sync.
2028 @param ConfigRequest The config request string which used to sync storage.
2029 @param SyncOrRestore Sync the buffer to editbuffer or Restore the
2030 editbuffer to buffer
2031 if TRUE, copy the editbuffer to the buffer.
2032 if FALSE, copy the buffer to the editbuffer.
2034 @retval EFI_SUCCESS The function completed successfully.
2038 SynchronizeStorage (
2039 IN FORM_BROWSER_FORMSET
*FormSet
,
2040 OUT BROWSER_STORAGE
*Storage
,
2041 IN CHAR16
*ConfigRequest
,
2042 IN BOOLEAN SyncOrRestore
2046 EFI_STRING Progress
;
2050 NAME_VALUE_NODE
*Node
;
2054 Status
= EFI_SUCCESS
;
2057 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
2058 (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
2059 BufferSize
= Storage
->Size
;
2061 if (SyncOrRestore
) {
2062 Src
= Storage
->EditBuffer
;
2063 Dst
= Storage
->Buffer
;
2065 Src
= Storage
->Buffer
;
2066 Dst
= Storage
->EditBuffer
;
2069 if (ConfigRequest
!= NULL
) {
2070 Status
= mHiiConfigRouting
->BlockToConfig(
2078 if (EFI_ERROR (Status
)) {
2082 Status
= mHiiConfigRouting
->ConfigToBlock (
2089 if (Result
!= NULL
) {
2093 CopyMem (Dst
, Src
, BufferSize
);
2095 } else if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2096 Link
= GetFirstNode (&Storage
->NameValueListHead
);
2097 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
2098 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
2100 if ((ConfigRequest
!= NULL
&& StrStr (ConfigRequest
, Node
->Name
) != NULL
) ||
2101 (ConfigRequest
== NULL
)) {
2102 if (SyncOrRestore
) {
2103 NewStringCpy (&Node
->Value
, Node
->EditValue
);
2105 NewStringCpy (&Node
->EditValue
, Node
->Value
);
2109 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
2117 When discard the question value, call the callback function with Changed type
2118 to inform the hii driver.
2120 @param FormSet FormSet data structure.
2121 @param Form Form data structure.
2125 SendDiscardInfoToDriver (
2126 IN FORM_BROWSER_FORMSET
*FormSet
,
2127 IN FORM_BROWSER_FORM
*Form
2131 FORM_BROWSER_STATEMENT
*Question
;
2132 EFI_IFR_TYPE_VALUE
*TypeValue
;
2133 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
2135 Link
= GetFirstNode (&Form
->StatementListHead
);
2136 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2137 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2138 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2140 if (Question
->Storage
== NULL
|| Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2144 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
) {
2148 if (!Question
->ValueChanged
) {
2152 if (Question
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
) {
2153 TypeValue
= (EFI_IFR_TYPE_VALUE
*) Question
->BufferValue
;
2155 TypeValue
= &Question
->HiiValue
.Value
;
2158 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
2159 FormSet
->ConfigAccess
->Callback (
2160 FormSet
->ConfigAccess
,
2161 EFI_BROWSER_ACTION_CHANGED
,
2162 Question
->QuestionId
,
2163 Question
->HiiValue
.Type
,
2171 Validate the FormSet. If the formset is not validate, remove it from the list.
2173 @param FormSet The input FormSet which need to validate.
2175 @retval TRUE The handle is validate.
2176 @retval FALSE The handle is invalidate.
2181 FORM_BROWSER_FORMSET
*FormSet
2184 EFI_HII_HANDLE
*HiiHandles
;
2188 ASSERT (FormSet
!= NULL
);
2191 // Get all the Hii handles
2193 HiiHandles
= HiiGetHiiHandles (NULL
);
2194 ASSERT (HiiHandles
!= NULL
);
2197 // Search for formset of each class type
2199 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
2200 if (HiiHandles
[Index
] == FormSet
->HiiHandle
) {
2207 CleanBrowserStorage(FormSet
);
2208 RemoveEntryList (&FormSet
->Link
);
2209 DestroyFormSet (FormSet
);
2212 FreePool (HiiHandles
);
2217 Check whether need to enable the reset flag in form level.
2218 Also clean all ValueChanged flag in question.
2220 @param SetFlag Whether need to set the Reset Flag.
2221 @param Form Form data structure.
2227 IN FORM_BROWSER_FORM
*Form
2231 FORM_BROWSER_STATEMENT
*Question
;
2235 Link
= GetFirstNode (&Form
->StatementListHead
);
2236 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2237 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2239 if (SetFlag
&& Question
->ValueChanged
&& ((Question
->QuestionFlags
& EFI_IFR_FLAG_RESET_REQUIRED
) != 0)) {
2240 gResetRequired
= TRUE
;
2243 if (Question
->ValueChanged
) {
2244 Question
->ValueChanged
= FALSE
;
2247 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2252 Check whether need to enable the reset flag.
2253 Also clean ValueChanged flag for all statements.
2255 Form level or formset level, only one.
2257 @param SetFlag Whether need to set the Reset Flag.
2258 @param FormSet FormSet data structure.
2259 @param Form Form data structure.
2263 ValueChangeResetFlagUpdate (
2265 IN FORM_BROWSER_FORMSET
*FormSet
,
2266 IN FORM_BROWSER_FORM
*Form
2269 FORM_BROWSER_FORM
*CurrentForm
;
2273 // Form != NULL means only check form level.
2276 UpdateFlagForForm(SetFlag
, Form
);
2280 Link
= GetFirstNode (&FormSet
->FormListHead
);
2281 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2282 CurrentForm
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2283 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2285 UpdateFlagForForm(SetFlag
, CurrentForm
);
2290 Discard data based on the input setting scope (Form, FormSet or System).
2292 @param FormSet FormSet data structure.
2293 @param Form Form data structure.
2294 @param SettingScope Setting Scope for Discard action.
2296 @retval EFI_SUCCESS The function completed successfully.
2297 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2302 IN FORM_BROWSER_FORMSET
*FormSet
,
2303 IN FORM_BROWSER_FORM
*Form
,
2304 IN BROWSER_SETTING_SCOPE SettingScope
2308 FORMSET_STORAGE
*Storage
;
2309 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2310 FORM_BROWSER_FORMSET
*LocalFormSet
;
2311 FORM_BROWSER_FORMSET
*OldFormSet
;
2314 // Check the supported setting level.
2316 if (SettingScope
>= MaxLevel
) {
2317 return EFI_UNSUPPORTED
;
2320 if (SettingScope
== FormLevel
&& IsNvUpdateRequiredForForm (Form
)) {
2322 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
2323 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
2324 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
2325 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
2327 if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2332 // Skip if there is no RequestElement
2334 if (ConfigInfo
->ElementCount
== 0) {
2339 // Prepare <ConfigResp>
2341 SynchronizeStorage(FormSet
, ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, FALSE
);
2344 // Call callback with Changed type to inform the driver.
2346 SendDiscardInfoToDriver (FormSet
, Form
);
2349 ValueChangeResetFlagUpdate (FALSE
, NULL
, Form
);
2350 } else if (SettingScope
== FormSetLevel
&& IsNvUpdateRequiredForFormSet (FormSet
)) {
2353 // Discard Buffer storage or Name/Value storage
2355 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2356 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2357 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2358 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2360 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2365 // Skip if there is no RequestElement
2367 if (Storage
->ElementCount
== 0) {
2371 SynchronizeStorage(FormSet
, Storage
->BrowserStorage
, Storage
->ConfigRequest
, FALSE
);
2374 Link
= GetFirstNode (&FormSet
->FormListHead
);
2375 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2376 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2377 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2380 // Call callback with Changed type to inform the driver.
2382 SendDiscardInfoToDriver (FormSet
, Form
);
2385 ValueChangeResetFlagUpdate(FALSE
, FormSet
, NULL
);
2386 } else if (SettingScope
== SystemLevel
) {
2388 // System Level Discard.
2390 OldFormSet
= mSystemLevelFormSet
;
2393 // Discard changed value for each FormSet in the maintain list.
2395 Link
= GetFirstNode (&gBrowserFormSetList
);
2396 while (!IsNull (&gBrowserFormSetList
, Link
)) {
2397 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
2398 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
2399 if (!ValidateFormSet(LocalFormSet
)) {
2403 mSystemLevelFormSet
= LocalFormSet
;
2405 DiscardForm (LocalFormSet
, NULL
, FormSetLevel
);
2406 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
2408 // Remove maintain backup list after discard except for the current using FormSet.
2410 CleanBrowserStorage(LocalFormSet
);
2411 RemoveEntryList (&LocalFormSet
->Link
);
2412 DestroyFormSet (LocalFormSet
);
2416 mSystemLevelFormSet
= OldFormSet
;
2423 Submit data based on the input Setting level (Form, FormSet or System).
2425 @param FormSet FormSet data structure.
2426 @param Form Form data structure.
2427 @param SettingScope Setting Scope for Submit action.
2429 @retval EFI_SUCCESS The function completed successfully.
2430 @retval EFI_UNSUPPORTED Unsupport SettingScope.
2435 IN FORM_BROWSER_FORMSET
*FormSet
,
2436 IN FORM_BROWSER_FORM
*Form
,
2437 IN BROWSER_SETTING_SCOPE SettingScope
2442 EFI_STRING ConfigResp
;
2443 EFI_STRING Progress
;
2444 BROWSER_STORAGE
*Storage
;
2445 FORMSET_STORAGE
*FormSetStorage
;
2446 FORM_BROWSER_FORMSET
*LocalFormSet
;
2447 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
2450 // Check the supported setting level.
2452 if (SettingScope
>= MaxLevel
) {
2453 return EFI_UNSUPPORTED
;
2457 // Validate the Form by NoSubmit check
2459 Status
= EFI_SUCCESS
;
2460 if (SettingScope
== FormLevel
) {
2461 Status
= NoSubmitCheck (FormSet
, Form
);
2462 } else if (SettingScope
== FormSetLevel
) {
2463 Status
= NoSubmitCheck (FormSet
, NULL
);
2465 if (EFI_ERROR (Status
)) {
2469 if (SettingScope
== FormLevel
&& IsNvUpdateRequiredForForm (Form
)) {
2471 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
2472 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
2473 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
2474 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
2476 Storage
= ConfigInfo
->Storage
;
2477 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2482 // Skip if there is no RequestElement
2484 if (ConfigInfo
->ElementCount
== 0) {
2489 // 1. Prepare <ConfigResp>
2491 Status
= StorageToConfigResp (ConfigInfo
->Storage
, &ConfigResp
, ConfigInfo
->ConfigRequest
, TRUE
);
2492 if (EFI_ERROR (Status
)) {
2497 // 2. Set value to hii config routine protocol.
2499 Status
= mHiiConfigRouting
->RouteConfig (
2504 if (EFI_ERROR (Status
)) {
2505 FreePool (ConfigResp
);
2509 FreePool (ConfigResp
);
2511 // 3. Config success, update storage shadow Buffer, only update the data belong to this form.
2513 SynchronizeStorage (FormSet
, ConfigInfo
->Storage
, ConfigInfo
->ConfigRequest
, TRUE
);
2517 // 4. Update the NV flag.
2519 ValueChangeResetFlagUpdate(TRUE
, NULL
, Form
);
2520 } else if (SettingScope
== FormSetLevel
&& IsNvUpdateRequiredForFormSet (FormSet
)) {
2522 // Submit Buffer storage or Name/Value storage
2524 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2525 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2526 FormSetStorage
= (FORMSET_STORAGE_FROM_LINK (Link
));
2527 Storage
= FormSetStorage
->BrowserStorage
;
2528 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2530 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2535 // Skip if there is no RequestElement
2537 if (FormSetStorage
->ElementCount
== 0) {
2542 // 1. Prepare <ConfigResp>
2544 Status
= StorageToConfigResp (Storage
, &ConfigResp
, FormSetStorage
->ConfigRequest
, TRUE
);
2545 if (EFI_ERROR (Status
)) {
2550 // 2. Send <ConfigResp> to Routine config Protocol.
2552 Status
= mHiiConfigRouting
->RouteConfig (
2557 if (EFI_ERROR (Status
)) {
2558 FreePool (ConfigResp
);
2562 FreePool (ConfigResp
);
2564 // 3. Config success, update storage shadow Buffer
2566 SynchronizeStorage (FormSet
, Storage
, FormSetStorage
->ConfigRequest
, TRUE
);
2570 // 4. Update the NV flag.
2572 ValueChangeResetFlagUpdate(TRUE
, FormSet
, NULL
);
2573 } else if (SettingScope
== SystemLevel
) {
2575 // System Level Save.
2579 // Save changed value for each FormSet in the maintain list.
2581 Link
= GetFirstNode (&gBrowserFormSetList
);
2582 while (!IsNull (&gBrowserFormSetList
, Link
)) {
2583 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
2584 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
2585 if (!ValidateFormSet(LocalFormSet
)) {
2588 SubmitForm (LocalFormSet
, NULL
, FormSetLevel
);
2589 if (!IsHiiHandleInBrowserContext (LocalFormSet
->HiiHandle
)) {
2591 // Remove maintain backup list after save except for the current using FormSet.
2593 CleanBrowserStorage(LocalFormSet
);
2594 RemoveEntryList (&LocalFormSet
->Link
);
2595 DestroyFormSet (LocalFormSet
);
2604 Get Question default value from AltCfg string.
2606 @param FormSet The form set.
2607 @param Question The question.
2608 @param DefaultId The default Id.
2610 @retval EFI_SUCCESS Question is reset to default value.
2614 GetDefaultValueFromAltCfg (
2615 IN FORM_BROWSER_FORMSET
*FormSet
,
2616 IN OUT FORM_BROWSER_STATEMENT
*Question
,
2620 BOOLEAN IsBufferStorage
;
2623 BROWSER_STORAGE
*Storage
;
2624 CHAR16
*ConfigRequest
;
2637 Status
= EFI_NOT_FOUND
;
2640 ConfigRequest
= NULL
;
2644 Storage
= Question
->Storage
;
2646 if ((Storage
== NULL
) || (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
2651 // Question Value is provided by Buffer Storage or NameValue Storage
2653 if (Question
->BufferValue
!= NULL
) {
2655 // This Question is password or orderedlist
2657 Dst
= Question
->BufferValue
;
2660 // Other type of Questions
2662 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
2665 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
|| Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
2666 IsBufferStorage
= TRUE
;
2668 IsBufferStorage
= FALSE
;
2670 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
2673 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
2674 // <ConfigHdr> + "&" + <VariableName>
2676 if (IsBufferStorage
) {
2677 Length
= StrLen (Storage
->ConfigHdr
);
2678 Length
+= StrLen (Question
->BlockName
);
2680 Length
= StrLen (Storage
->ConfigHdr
);
2681 Length
+= StrLen (Question
->VariableName
) + 1;
2683 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
2684 ASSERT (ConfigRequest
!= NULL
);
2686 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
2687 if (IsBufferStorage
) {
2688 StrCat (ConfigRequest
, Question
->BlockName
);
2690 StrCat (ConfigRequest
, L
"&");
2691 StrCat (ConfigRequest
, Question
->VariableName
);
2694 Status
= mHiiConfigRouting
->ExtractConfig (
2700 if (EFI_ERROR (Status
)) {
2705 // Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
2706 // Get the default configuration string according to the default ID.
2708 Status
= mHiiConfigRouting
->GetAltConfig (
2714 &DefaultId
, // it can be NULL to get the current setting.
2719 // The required setting can't be found. So, it is not required to be validated and set.
2721 if (EFI_ERROR (Status
)) {
2725 if (ConfigResp
== NULL
) {
2726 Status
= EFI_NOT_FOUND
;
2731 // Skip <ConfigRequest>
2733 if (IsBufferStorage
) {
2734 Value
= StrStr (ConfigResp
, L
"&VALUE");
2735 ASSERT (Value
!= NULL
);
2741 Value
= StrStr (ConfigResp
, Question
->VariableName
);
2742 ASSERT (Value
!= NULL
);
2744 Value
= Value
+ StrLen (Question
->VariableName
);
2746 if (*Value
!= '=') {
2747 Status
= EFI_NOT_FOUND
;
2751 // Skip '=', point to value
2756 // Suppress <AltResp> if any
2759 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
2764 LengthStr
= StrLen (Value
);
2765 if (!IsBufferStorage
&& IsString
) {
2766 StringPtr
= (CHAR16
*) Dst
;
2767 ZeroMem (TemStr
, sizeof (TemStr
));
2768 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
2769 StrnCpy (TemStr
, Value
+ Index
, 4);
2770 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
2773 // Add tailing L'\0' character
2775 StringPtr
[Index
/4] = L
'\0';
2777 ZeroMem (TemStr
, sizeof (TemStr
));
2778 for (Index
= 0; Index
< LengthStr
; Index
++) {
2779 TemStr
[0] = Value
[LengthStr
- Index
- 1];
2780 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
2781 if ((Index
& 1) == 0) {
2782 Dst
[Index
/2] = DigitUint8
;
2784 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
2790 if (ConfigRequest
!= NULL
){
2791 FreePool (ConfigRequest
);
2794 if (ConfigResp
!= NULL
) {
2795 FreePool (ConfigResp
);
2798 if (Result
!= NULL
) {
2806 Get default Id value used for browser.
2808 @param DefaultId The default id value used by hii.
2810 @retval Browser used default value.
2814 GetDefaultIdForCallBack (
2818 if (DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) {
2819 return EFI_BROWSER_ACTION_DEFAULT_STANDARD
;
2820 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2821 return EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
;
2822 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_SAFE
) {
2823 return EFI_BROWSER_ACTION_DEFAULT_SAFE
;
2824 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
+ 0x1000) {
2825 return EFI_BROWSER_ACTION_DEFAULT_PLATFORM
+ DefaultId
- EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
;
2826 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
+ 0x1000) {
2827 return EFI_BROWSER_ACTION_DEFAULT_HARDWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
;
2828 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
+ 0x1000) {
2829 return EFI_BROWSER_ACTION_DEFAULT_FIRMWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
;
2838 Return data element in an Array by its Index.
2840 @param Array The data array.
2841 @param Type Type of the data in this array.
2842 @param Index Zero based index for data in this array.
2844 @retval Value The data to be returned
2856 ASSERT (Array
!= NULL
);
2860 case EFI_IFR_TYPE_NUM_SIZE_8
:
2861 Data
= (UINT64
) *(((UINT8
*) Array
) + Index
);
2864 case EFI_IFR_TYPE_NUM_SIZE_16
:
2865 Data
= (UINT64
) *(((UINT16
*) Array
) + Index
);
2868 case EFI_IFR_TYPE_NUM_SIZE_32
:
2869 Data
= (UINT64
) *(((UINT32
*) Array
) + Index
);
2872 case EFI_IFR_TYPE_NUM_SIZE_64
:
2873 Data
= (UINT64
) *(((UINT64
*) Array
) + Index
);
2885 Set value of a data element in an Array by its Index.
2887 @param Array The data array.
2888 @param Type Type of the data in this array.
2889 @param Index Zero based index for data in this array.
2890 @param Value The value to be set.
2902 ASSERT (Array
!= NULL
);
2905 case EFI_IFR_TYPE_NUM_SIZE_8
:
2906 *(((UINT8
*) Array
) + Index
) = (UINT8
) Value
;
2909 case EFI_IFR_TYPE_NUM_SIZE_16
:
2910 *(((UINT16
*) Array
) + Index
) = (UINT16
) Value
;
2913 case EFI_IFR_TYPE_NUM_SIZE_32
:
2914 *(((UINT32
*) Array
) + Index
) = (UINT32
) Value
;
2917 case EFI_IFR_TYPE_NUM_SIZE_64
:
2918 *(((UINT64
*) Array
) + Index
) = (UINT64
) Value
;
2927 Search an Option of a Question by its value.
2929 @param Question The Question
2930 @param OptionValue Value for Option to be searched.
2932 @retval Pointer Pointer to the found Option.
2933 @retval NULL Option not found.
2938 IN FORM_BROWSER_STATEMENT
*Question
,
2939 IN EFI_HII_VALUE
*OptionValue
2943 QUESTION_OPTION
*Option
;
2946 Link
= GetFirstNode (&Question
->OptionListHead
);
2947 while (!IsNull (&Question
->OptionListHead
, Link
)) {
2948 Option
= QUESTION_OPTION_FROM_LINK (Link
);
2950 if ((CompareHiiValue (&Option
->Value
, OptionValue
, &Result
, NULL
) == EFI_SUCCESS
) && (Result
== 0)) {
2952 // Check the suppressif condition, only a valid option can be return.
2954 if ((Option
->SuppressExpression
== NULL
) ||
2955 ((EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) == ExpressFalse
))) {
2960 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
2968 Reset Question to its default value.
2970 @param FormSet The form set.
2971 @param Form The form.
2972 @param Question The question.
2973 @param DefaultId The Class of the default.
2975 @retval EFI_SUCCESS Question is reset to default value.
2979 GetQuestionDefault (
2980 IN FORM_BROWSER_FORMSET
*FormSet
,
2981 IN FORM_BROWSER_FORM
*Form
,
2982 IN FORM_BROWSER_STATEMENT
*Question
,
2988 QUESTION_DEFAULT
*Default
;
2989 QUESTION_OPTION
*Option
;
2990 EFI_HII_VALUE
*HiiValue
;
2992 EFI_STRING StrValue
;
2993 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2994 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
2997 Status
= EFI_NOT_FOUND
;
3001 // Statement don't have storage, skip them
3003 if (Question
->QuestionId
== 0) {
3008 // There are Five ways to specify default value for a Question:
3009 // 1, use call back function (highest priority)
3010 // 2, use ExtractConfig function
3011 // 3, use nested EFI_IFR_DEFAULT
3012 // 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
3013 // 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
3015 HiiValue
= &Question
->HiiValue
;
3018 // Get Question defaut value from call back function.
3020 ConfigAccess
= FormSet
->ConfigAccess
;
3021 Action
= GetDefaultIdForCallBack (DefaultId
);
3022 if ((Action
> 0) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
3023 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
3024 Status
= ConfigAccess
->Callback (
3027 Question
->QuestionId
,
3032 if (!EFI_ERROR (Status
)) {
3038 // Get default value from altcfg string.
3040 if (ConfigAccess
!= NULL
) {
3041 Status
= GetDefaultValueFromAltCfg(FormSet
, Question
, DefaultId
);
3042 if (!EFI_ERROR (Status
)) {
3048 // EFI_IFR_DEFAULT has highest priority
3050 if (!IsListEmpty (&Question
->DefaultListHead
)) {
3051 Link
= GetFirstNode (&Question
->DefaultListHead
);
3052 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
3053 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
3055 if (Default
->DefaultId
== DefaultId
) {
3056 if (Default
->ValueExpression
!= NULL
) {
3058 // Default is provided by an Expression, evaluate it
3060 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
3061 if (EFI_ERROR (Status
)) {
3065 if (Default
->ValueExpression
->Result
.Type
== EFI_IFR_TYPE_BUFFER
) {
3066 ASSERT (HiiValue
->Type
== EFI_IFR_TYPE_BUFFER
&& Question
->BufferValue
!= NULL
);
3067 if (Question
->StorageWidth
> Default
->ValueExpression
->Result
.BufferLen
) {
3068 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Default
->ValueExpression
->Result
.BufferLen
);
3069 Question
->HiiValue
.BufferLen
= Default
->ValueExpression
->Result
.BufferLen
;
3071 CopyMem (Question
->HiiValue
.Buffer
, Default
->ValueExpression
->Result
.Buffer
, Question
->StorageWidth
);
3072 Question
->HiiValue
.BufferLen
= Question
->StorageWidth
;
3074 FreePool (Default
->ValueExpression
->Result
.Buffer
);
3076 HiiValue
->Type
= Default
->ValueExpression
->Result
.Type
;
3077 CopyMem (&HiiValue
->Value
, &Default
->ValueExpression
->Result
.Value
, sizeof (EFI_IFR_TYPE_VALUE
));
3080 // Default value is embedded in EFI_IFR_DEFAULT
3082 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
3085 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
3086 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
3087 if (StrValue
== NULL
) {
3088 return EFI_NOT_FOUND
;
3090 if (Question
->StorageWidth
> StrSize (StrValue
)) {
3091 CopyMem (Question
->BufferValue
, StrValue
, StrSize (StrValue
));
3093 CopyMem (Question
->BufferValue
, StrValue
, Question
->StorageWidth
);
3100 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
3105 // EFI_ONE_OF_OPTION
3107 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
3108 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3110 // OneOfOption could only provide Standard and Manufacturing default
3112 Link
= GetFirstNode (&Question
->OptionListHead
);
3113 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3114 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3115 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3117 if ((Option
->SuppressExpression
!= NULL
) &&
3118 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3122 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
3123 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
3125 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
3134 // EFI_IFR_CHECKBOX - lowest priority
3136 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
3137 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
3139 // Checkbox could only provide Standard and Manufacturing default
3141 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
3142 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
3144 HiiValue
->Value
.b
= TRUE
;
3146 HiiValue
->Value
.b
= FALSE
;
3154 // For Questions without default
3156 Status
= EFI_NOT_FOUND
;
3157 switch (Question
->Operand
) {
3158 case EFI_IFR_NUMERIC_OP
:
3160 // Take minimum value as numeric default value
3162 if ((HiiValue
->Value
.u64
< Question
->Minimum
) || (HiiValue
->Value
.u64
> Question
->Maximum
)) {
3163 HiiValue
->Value
.u64
= Question
->Minimum
;
3164 Status
= EFI_SUCCESS
;
3168 case EFI_IFR_ONE_OF_OP
:
3170 // Take first oneof option as oneof's default value
3172 if (ValueToOption (Question
, HiiValue
) == NULL
) {
3173 Link
= GetFirstNode (&Question
->OptionListHead
);
3174 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3175 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3176 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3178 if ((Option
->SuppressExpression
!= NULL
) &&
3179 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3183 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
3184 Status
= EFI_SUCCESS
;
3190 case EFI_IFR_ORDERED_LIST_OP
:
3192 // Take option sequence in IFR as ordered list's default value
3195 Link
= GetFirstNode (&Question
->OptionListHead
);
3196 while (!IsNull (&Question
->OptionListHead
, Link
)) {
3197 Status
= EFI_SUCCESS
;
3198 Option
= QUESTION_OPTION_FROM_LINK (Link
);
3199 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
3201 if ((Option
->SuppressExpression
!= NULL
) &&
3202 EvaluateExpressionList(Option
->SuppressExpression
, FALSE
, NULL
, NULL
) != ExpressFalse
) {
3206 SetArrayData (Question
->BufferValue
, Question
->ValueType
, Index
, Option
->Value
.Value
.u64
);
3209 if (Index
>= Question
->MaxContainers
) {
3224 Reset Questions to their initial value or default value in a Form, Formset or System.
3226 GetDefaultValueScope parameter decides which questions will reset
3227 to its default value.
3229 @param FormSet FormSet data structure.
3230 @param Form Form data structure.
3231 @param DefaultId The Class of the default.
3232 @param SettingScope Setting Scope for Default action.
3233 @param GetDefaultValueScope Get default value scope.
3234 @param Storage Get default value only for this storage.
3235 @param RetrieveValueFirst Whether call the retrieve call back to
3236 get the initial value before get default
3239 @retval EFI_SUCCESS The function completed successfully.
3240 @retval EFI_UNSUPPORTED Unsupport SettingScope.
3245 IN FORM_BROWSER_FORMSET
*FormSet
,
3246 IN FORM_BROWSER_FORM
*Form
,
3247 IN UINT16 DefaultId
,
3248 IN BROWSER_SETTING_SCOPE SettingScope
,
3249 IN BROWSER_GET_DEFAULT_VALUE GetDefaultValueScope
,
3250 IN BROWSER_STORAGE
*Storage OPTIONAL
,
3251 IN BOOLEAN RetrieveValueFirst
3255 LIST_ENTRY
*FormLink
;
3257 FORM_BROWSER_STATEMENT
*Question
;
3258 FORM_BROWSER_FORMSET
*LocalFormSet
;
3259 FORM_BROWSER_FORMSET
*OldFormSet
;
3261 Status
= EFI_SUCCESS
;
3264 // Check the supported setting level.
3266 if (SettingScope
>= MaxLevel
|| GetDefaultValueScope
>= GetDefaultForMax
) {
3267 return EFI_UNSUPPORTED
;
3270 if (GetDefaultValueScope
== GetDefaultForStorage
&& Storage
== NULL
) {
3271 return EFI_UNSUPPORTED
;
3274 if (SettingScope
== FormLevel
) {
3276 // Extract Form default
3278 Link
= GetFirstNode (&Form
->StatementListHead
);
3279 while (!IsNull (&Form
->StatementListHead
, Link
)) {
3280 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
3281 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
3284 // If get default value only for this storage, check the storage first.
3286 if ((GetDefaultValueScope
== GetDefaultForStorage
) && (Question
->Storage
!= Storage
)) {
3291 // If get default value only for no storage question, just skip the question which has storage.
3293 if ((GetDefaultValueScope
== GetDefaultForNoStorage
) && (Question
->Storage
!= NULL
)) {
3298 // If Question is disabled, don't reset it to default
3300 if (Question
->Expression
!= NULL
) {
3301 if (EvaluateExpressionList(Question
->Expression
, TRUE
, FormSet
, Form
) == ExpressDisable
) {
3306 if (RetrieveValueFirst
) {
3308 // Call the Retrieve call back to get the initial question value.
3310 Status
= ProcessRetrieveForQuestion(FormSet
->ConfigAccess
, Question
);
3314 // If not request to get the initial value or get initial value fail, then get default value.
3316 if (!RetrieveValueFirst
|| EFI_ERROR (Status
)) {
3317 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
3318 if (EFI_ERROR (Status
)) {
3324 // Synchronize Buffer storage's Edit buffer
3326 if ((Question
->Storage
!= NULL
) &&
3327 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
3328 SetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
3331 } else if (SettingScope
== FormSetLevel
) {
3332 FormLink
= GetFirstNode (&FormSet
->FormListHead
);
3333 while (!IsNull (&FormSet
->FormListHead
, FormLink
)) {
3334 Form
= FORM_BROWSER_FORM_FROM_LINK (FormLink
);
3335 ExtractDefault (FormSet
, Form
, DefaultId
, FormLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
);
3336 FormLink
= GetNextNode (&FormSet
->FormListHead
, FormLink
);
3338 } else if (SettingScope
== SystemLevel
) {
3340 // Preload all Hii formset.
3342 LoadAllHiiFormset();
3344 OldFormSet
= mSystemLevelFormSet
;
3347 // Set Default Value for each FormSet in the maintain list.
3349 Link
= GetFirstNode (&gBrowserFormSetList
);
3350 while (!IsNull (&gBrowserFormSetList
, Link
)) {
3351 LocalFormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
3352 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
3353 if (!ValidateFormSet(LocalFormSet
)) {
3357 mSystemLevelFormSet
= LocalFormSet
;
3359 ExtractDefault (LocalFormSet
, NULL
, DefaultId
, FormSetLevel
, GetDefaultValueScope
, Storage
, RetrieveValueFirst
);
3362 mSystemLevelFormSet
= OldFormSet
;
3370 Validate whether this question's value has changed.
3372 @param FormSet FormSet data structure.
3373 @param Form Form data structure.
3374 @param Question Question to be initialized.
3375 @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver.
3377 @retval TRUE Question's value has changed.
3378 @retval FALSE Question's value has not changed
3382 IsQuestionValueChanged (
3383 IN FORM_BROWSER_FORMSET
*FormSet
,
3384 IN FORM_BROWSER_FORM
*Form
,
3385 IN OUT FORM_BROWSER_STATEMENT
*Question
,
3386 IN GET_SET_QUESTION_VALUE_WITH GetValueFrom
3389 EFI_HII_VALUE BackUpValue
;
3390 CHAR8
*BackUpBuffer
;
3392 BOOLEAN ValueChanged
;
3396 // For quetion without storage, always mark it as data not changed.
3398 if (Question
->Storage
== NULL
&& Question
->Operand
!= EFI_IFR_TIME_OP
&& Question
->Operand
!= EFI_IFR_DATE_OP
) {
3402 BackUpBuffer
= NULL
;
3403 ValueChanged
= FALSE
;
3405 switch (Question
->Operand
) {
3406 case EFI_IFR_ORDERED_LIST_OP
:
3407 BufferWidth
= Question
->StorageWidth
;
3408 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
3409 ASSERT (BackUpBuffer
!= NULL
);
3412 case EFI_IFR_STRING_OP
:
3413 case EFI_IFR_PASSWORD_OP
:
3414 BufferWidth
= (UINTN
) Question
->Maximum
* sizeof (CHAR16
);
3415 BackUpBuffer
= AllocateCopyPool (BufferWidth
, Question
->BufferValue
);
3416 ASSERT (BackUpBuffer
!= NULL
);
3423 CopyMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
));
3425 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetValueFrom
);
3426 ASSERT_EFI_ERROR(Status
);
3428 if (CompareMem (&BackUpValue
, &Question
->HiiValue
, sizeof (EFI_HII_VALUE
)) != 0 ||
3429 CompareMem (BackUpBuffer
, Question
->BufferValue
, BufferWidth
) != 0) {
3430 ValueChanged
= TRUE
;
3433 CopyMem (&Question
->HiiValue
, &BackUpValue
, sizeof (EFI_HII_VALUE
));
3434 CopyMem (Question
->BufferValue
, BackUpBuffer
, BufferWidth
);
3436 if (BackUpBuffer
!= NULL
) {
3437 FreePool (BackUpBuffer
);
3440 Question
->ValueChanged
= ValueChanged
;
3442 return ValueChanged
;
3446 Initialize Question's Edit copy from Storage.
3448 @param Selection Selection contains the information about
3449 the Selection, form and formset to be displayed.
3450 Selection action may be updated in retrieve callback.
3451 If Selection is NULL, only initialize Question value.
3452 @param FormSet FormSet data structure.
3453 @param Form Form data structure.
3455 @retval EFI_SUCCESS The function completed successfully.
3460 IN OUT UI_MENU_SELECTION
*Selection
,
3461 IN FORM_BROWSER_FORMSET
*FormSet
,
3462 IN FORM_BROWSER_FORM
*Form
3467 FORM_BROWSER_STATEMENT
*Question
;
3471 Link
= GetFirstNode (&Form
->StatementListHead
);
3472 while (!IsNull (&Form
->StatementListHead
, Link
)) {
3473 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
3476 // Initialize local copy of Value for each Question
3478 if (Question
->Operand
== EFI_IFR_PASSWORD_OP
&& (Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
)== 0) {
3479 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithHiiDriver
);
3481 Status
= GetQuestionValue (FormSet
, Form
, Question
, GetSetValueWithEditBuffer
);
3483 if (EFI_ERROR (Status
)) {
3487 if ((Question
->Operand
== EFI_IFR_STRING_OP
) || (Question
->Operand
== EFI_IFR_PASSWORD_OP
)) {
3488 HiiSetString (FormSet
->HiiHandle
, Question
->HiiValue
.Value
.string
, (CHAR16
*)Question
->BufferValue
, NULL
);
3492 // Call the Retrieve call back function for all questions.
3494 if ((FormSet
->ConfigAccess
!= NULL
) && (Selection
!= NULL
) &&
3495 ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
) &&
3496 !gFinishRetrieveCall
) {
3498 // Check QuestionValue does exist.
3500 StorageWidth
= Question
->StorageWidth
;
3501 if (Question
->BufferValue
!= NULL
) {
3502 BufferValue
= Question
->BufferValue
;
3504 BufferValue
= (UINT8
*) &Question
->HiiValue
.Value
;
3508 // For efivarstore storage, initial question value first.
3510 if ((Question
->Storage
!= NULL
) && (Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
3511 Status
= gRT
->GetVariable (
3512 Question
->VariableName
,
3513 &Question
->Storage
->Guid
,
3520 Status
= ProcessCallBackFunction(Selection
, FormSet
, Form
, Question
, EFI_BROWSER_ACTION_RETRIEVE
, TRUE
);
3523 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
3530 Initialize Question's Edit copy from Storage for the whole Formset.
3532 @param Selection Selection contains the information about
3533 the Selection, form and formset to be displayed.
3534 Selection action may be updated in retrieve callback.
3535 If Selection is NULL, only initialize Question value.
3536 @param FormSet FormSet data structure.
3538 @retval EFI_SUCCESS The function completed successfully.
3543 IN OUT UI_MENU_SELECTION
*Selection
,
3544 IN FORM_BROWSER_FORMSET
*FormSet
3549 FORM_BROWSER_FORM
*Form
;
3551 Link
= GetFirstNode (&FormSet
->FormListHead
);
3552 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
3553 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
3556 // Initialize local copy of Value for each Form
3558 Status
= LoadFormConfig (Selection
, FormSet
, Form
);
3559 if (EFI_ERROR (Status
)) {
3563 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
3567 // Finished question initialization.
3569 FormSet
->QuestionInited
= TRUE
;
3575 Remove the Request element from the Config Request.
3577 @param Storage Pointer to the browser storage.
3578 @param RequestElement The pointer to the Request element.
3583 IN OUT BROWSER_STORAGE
*Storage
,
3584 IN CHAR16
*RequestElement
3590 ASSERT (Storage
->ConfigRequest
!= NULL
&& RequestElement
!= NULL
);
3592 NewStr
= StrStr (Storage
->ConfigRequest
, RequestElement
);
3594 if (NewStr
== NULL
) {
3599 // Remove this element from this ConfigRequest.
3602 NewStr
+= StrLen (RequestElement
);
3603 CopyMem (DestStr
, NewStr
, StrSize (NewStr
));
3605 Storage
->SpareStrLen
+= StrLen (RequestElement
);
3609 Adjust config request in storage, remove the request elements existed in the input ConfigRequest.
3611 @param Storage Pointer to the browser storage.
3612 @param ConfigRequest The pointer to the Request element.
3616 RemoveConfigRequest (
3617 BROWSER_STORAGE
*Storage
,
3618 CHAR16
*ConfigRequest
3621 CHAR16
*RequestElement
;
3622 CHAR16
*NextRequestElement
;
3626 // No request element in it, just return.
3628 if (ConfigRequest
== NULL
) {
3632 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3634 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
3639 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
3641 SearchKey
= L
"&OFFSET";
3645 // Find SearchKey storage
3647 if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3648 RequestElement
= StrStr (ConfigRequest
, L
"PATH");
3649 ASSERT (RequestElement
!= NULL
);
3650 RequestElement
= StrStr (RequestElement
, SearchKey
);
3652 RequestElement
= StrStr (ConfigRequest
, SearchKey
);
3655 while (RequestElement
!= NULL
) {
3657 // +1 to avoid find header itself.
3659 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
3662 // The last Request element in configRequest string.
3664 if (NextRequestElement
!= NULL
) {
3666 // Replace "&" with '\0'.
3668 *NextRequestElement
= L
'\0';
3671 RemoveElement (Storage
, RequestElement
);
3673 if (NextRequestElement
!= NULL
) {
3675 // Restore '&' with '\0' for later used.
3677 *NextRequestElement
= L
'&';
3680 RequestElement
= NextRequestElement
;
3684 // If no request element remain, just remove the ConfigRequest string.
3686 if (StrCmp (Storage
->ConfigRequest
, Storage
->ConfigHdr
) == 0) {
3687 FreePool (Storage
->ConfigRequest
);
3688 Storage
->ConfigRequest
= NULL
;
3689 Storage
->SpareStrLen
= 0;
3694 Base on the current formset info, clean the ConfigRequest string in browser storage.
3696 @param FormSet Pointer of the FormSet
3700 CleanBrowserStorage (
3701 IN OUT FORM_BROWSER_FORMSET
*FormSet
3705 FORMSET_STORAGE
*Storage
;
3706 CHAR16
*ConfigRequest
;
3708 Link
= GetFirstNode (&FormSet
->StorageListHead
);
3709 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
3710 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
3711 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
3713 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
3714 if (Storage
->ConfigRequest
== NULL
|| Storage
->BrowserStorage
->ConfigRequest
== NULL
) {
3718 ConfigRequest
= FormSet
->QuestionInited
? Storage
->ConfigRequest
: Storage
->ConfigElements
;
3719 RemoveConfigRequest (Storage
->BrowserStorage
, ConfigRequest
);
3720 } else if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_BUFFER
||
3721 Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3722 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
3723 FreePool (Storage
->BrowserStorage
->ConfigRequest
);
3725 Storage
->BrowserStorage
->Initialized
= FALSE
;
3731 Check whether current element in the ConfigReqeust string.
3733 @param BrowserStorage Storage which includes ConfigReqeust.
3734 @param RequestElement New element need to check.
3736 @retval TRUE The Element is in the ConfigReqeust string.
3737 @retval FALSE The Element not in the configReqeust String.
3742 BROWSER_STORAGE
*BrowserStorage
,
3743 CHAR16
*RequestElement
3746 return StrStr (BrowserStorage
->ConfigRequest
, RequestElement
) != NULL
? TRUE
: FALSE
;
3750 Append the Request element to the Config Request.
3752 @param ConfigRequest Current ConfigRequest info.
3753 @param SpareStrLen Current remain free buffer for config reqeust.
3754 @param RequestElement New Request element.
3758 AppendConfigRequest (
3759 IN OUT CHAR16
**ConfigRequest
,
3760 IN OUT UINTN
*SpareStrLen
,
3761 IN CHAR16
*RequestElement
3768 StrLength
= StrLen (RequestElement
);
3771 // Append <RequestElement> to <ConfigRequest>
3773 if (StrLength
> *SpareStrLen
) {
3775 // Old String buffer is not sufficient for RequestElement, allocate a new one
3777 StringSize
= (*ConfigRequest
!= NULL
) ? StrSize (*ConfigRequest
) : sizeof (CHAR16
);
3778 NewStr
= AllocateZeroPool (StringSize
+ CONFIG_REQUEST_STRING_INCREMENTAL
* sizeof (CHAR16
));
3779 ASSERT (NewStr
!= NULL
);
3781 if (*ConfigRequest
!= NULL
) {
3782 CopyMem (NewStr
, *ConfigRequest
, StringSize
);
3783 FreePool (*ConfigRequest
);
3785 *ConfigRequest
= NewStr
;
3786 *SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
3789 StrCat (*ConfigRequest
, RequestElement
);
3790 *SpareStrLen
-= StrLength
;
3794 Adjust the config request info, remove the request elements which already in AllConfigRequest string.
3796 @param Storage Form set Storage.
3798 @retval TRUE Has element not covered by current used elements, need to continue to call ExtractConfig
3799 @retval FALSE All elements covered by current used elements.
3803 ConfigRequestAdjust (
3804 IN FORMSET_STORAGE
*Storage
3807 CHAR16
*RequestElement
;
3808 CHAR16
*NextRequestElement
;
3818 if (Storage
->BrowserStorage
->ConfigRequest
== NULL
) {
3819 Storage
->BrowserStorage
->ConfigRequest
= AllocateCopyPool (StrSize (Storage
->ConfigRequest
), Storage
->ConfigRequest
);
3820 if (Storage
->ConfigElements
!= NULL
) {
3821 FreePool (Storage
->ConfigElements
);
3823 Storage
->ConfigElements
= AllocateCopyPool (StrSize (Storage
->ConfigRequest
), Storage
->ConfigRequest
);
3827 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3829 // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
3834 // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
3836 SearchKey
= L
"&OFFSET";
3840 // Prepare the config header.
3842 RetBuf
= AllocateCopyPool(StrSize (Storage
->BrowserStorage
->ConfigHdr
), Storage
->BrowserStorage
->ConfigHdr
);
3843 ASSERT (RetBuf
!= NULL
);
3846 // Find SearchKey storage
3848 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3849 RequestElement
= StrStr (Storage
->ConfigRequest
, L
"PATH");
3850 ASSERT (RequestElement
!= NULL
);
3851 RequestElement
= StrStr (RequestElement
, SearchKey
);
3853 RequestElement
= StrStr (Storage
->ConfigRequest
, SearchKey
);
3856 while (RequestElement
!= NULL
) {
3858 // +1 to avoid find header itself.
3860 NextRequestElement
= StrStr (RequestElement
+ 1, SearchKey
);
3863 // The last Request element in configRequest string.
3865 if (NextRequestElement
!= NULL
) {
3867 // Replace "&" with '\0'.
3869 *NextRequestElement
= L
'\0';
3872 if (!ElementValidation (Storage
->BrowserStorage
, RequestElement
)) {
3874 // Add this element to the Storage->BrowserStorage->AllRequestElement.
3876 AppendConfigRequest(&Storage
->BrowserStorage
->ConfigRequest
, &Storage
->BrowserStorage
->SpareStrLen
, RequestElement
);
3877 AppendConfigRequest (&RetBuf
, &SpareBufLen
, RequestElement
);
3881 if (NextRequestElement
!= NULL
) {
3883 // Restore '&' with '\0' for later used.
3885 *NextRequestElement
= L
'&';
3888 RequestElement
= NextRequestElement
;
3892 if (Storage
->ConfigElements
!= NULL
) {
3893 FreePool (Storage
->ConfigElements
);
3895 Storage
->ConfigElements
= RetBuf
;
3905 Base on ConfigRequest info to get default value for current formset.
3907 ConfigRequest info include the info about which questions in current formset need to
3908 get default value. This function only get these questions default value.
3910 @param FormSet FormSet data structure.
3911 @param Storage Storage need to update value.
3912 @param ConfigRequest The config request string.
3916 GetDefaultForFormset (
3917 IN FORM_BROWSER_FORMSET
*FormSet
,
3918 IN BROWSER_STORAGE
*Storage
,
3919 IN CHAR16
*ConfigRequest
3924 LIST_ENTRY BackUpList
;
3925 NAME_VALUE_NODE
*Node
;
3927 LIST_ENTRY
*NodeLink
;
3928 NAME_VALUE_NODE
*TmpNode
;
3930 EFI_STRING Progress
;
3934 InitializeListHead(&BackUpList
);
3937 // Back update the edit buffer.
3939 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
3940 (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
3941 BackUpBuf
= AllocateCopyPool (Storage
->Size
, Storage
->EditBuffer
);
3942 ASSERT (BackUpBuf
!= NULL
);
3943 } else if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3944 Link
= GetFirstNode (&Storage
->NameValueListHead
);
3945 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
3946 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
3947 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
3950 // Only back Node belong to this formset.
3952 if (StrStr (Storage
->ConfigRequest
, Node
->Name
) == NULL
) {
3956 TmpNode
= AllocateCopyPool (sizeof (NAME_VALUE_NODE
), Node
);
3957 TmpNode
->Name
= AllocateCopyPool (StrSize(Node
->Name
) * sizeof (CHAR16
), Node
->Name
);
3958 TmpNode
->EditValue
= AllocateCopyPool (StrSize(Node
->EditValue
) * sizeof (CHAR16
), Node
->EditValue
);
3960 InsertTailList(&BackUpList
, &TmpNode
->Link
);
3965 // Get default value.
3967 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForStorage
, Storage
, TRUE
);
3970 // Update the question value based on the input ConfigRequest.
3972 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
3973 (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
)) {
3974 ASSERT (BackUpBuf
!= NULL
);
3975 BufferSize
= Storage
->Size
;
3976 Status
= mHiiConfigRouting
->BlockToConfig(
3979 Storage
->EditBuffer
,
3984 ASSERT_EFI_ERROR (Status
);
3986 Status
= mHiiConfigRouting
->ConfigToBlock (
3993 ASSERT_EFI_ERROR (Status
);
3995 if (Result
!= NULL
) {
3999 CopyMem (Storage
->EditBuffer
, BackUpBuf
, Storage
->Size
);
4000 FreePool (BackUpBuf
);
4001 } else if (Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
4003 // Update question value, only element in ConfigReqeust will be update.
4005 Link
= GetFirstNode (&BackUpList
);
4006 while (!IsNull (&BackUpList
, Link
)) {
4007 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
4008 Link
= GetNextNode (&BackUpList
, Link
);
4010 if (StrStr (ConfigRequest
, Node
->Name
) != NULL
) {
4014 NodeLink
= GetFirstNode (&Storage
->NameValueListHead
);
4015 while (!IsNull (&Storage
->NameValueListHead
, NodeLink
)) {
4016 TmpNode
= NAME_VALUE_NODE_FROM_LINK (NodeLink
);
4017 NodeLink
= GetNextNode (&Storage
->NameValueListHead
, NodeLink
);
4019 if (StrCmp (Node
->Name
, TmpNode
->Name
) != 0) {
4023 FreePool (TmpNode
->EditValue
);
4024 TmpNode
->EditValue
= AllocateCopyPool (StrSize(Node
->EditValue
) * sizeof (CHAR16
), Node
->EditValue
);
4026 RemoveEntryList (&Node
->Link
);
4027 FreePool (Node
->EditValue
);
4028 FreePool (Node
->Name
);
4034 // Restore the Name/Value node.
4036 Link
= GetFirstNode (&BackUpList
);
4037 while (!IsNull (&BackUpList
, Link
)) {
4038 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
4039 Link
= GetNextNode (&BackUpList
, Link
);
4044 RemoveEntryList (&Node
->Link
);
4045 FreePool (Node
->EditValue
);
4046 FreePool (Node
->Name
);
4053 Fill storage's edit copy with settings requested from Configuration Driver.
4055 @param FormSet FormSet data structure.
4056 @param Storage Buffer Storage.
4061 IN FORM_BROWSER_FORMSET
*FormSet
,
4062 IN FORMSET_STORAGE
*Storage
4066 EFI_STRING Progress
;
4069 EFI_STRING ConfigRequest
;
4072 ConfigRequest
= NULL
;
4074 switch (Storage
->BrowserStorage
->Type
) {
4075 case EFI_HII_VARSTORE_EFI_VARIABLE
:
4078 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
4079 if (Storage
->BrowserStorage
->ConfigRequest
!= NULL
) {
4080 ConfigRequestAdjust(Storage
);
4085 // Create the config request string to get all fields for this storage.
4086 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
4087 // followed by "&OFFSET=0&WIDTH=WWWW"followed by a Null-terminator
4089 StrLen
= StrSize (Storage
->BrowserStorage
->ConfigHdr
) + 20 * sizeof (CHAR16
);
4090 ConfigRequest
= AllocateZeroPool (StrLen
);
4091 ASSERT (ConfigRequest
!= NULL
);
4095 L
"%s&OFFSET=0&WIDTH=%04x",
4096 Storage
->BrowserStorage
->ConfigHdr
,
4097 Storage
->BrowserStorage
->Size
);
4100 case EFI_HII_VARSTORE_BUFFER
:
4101 case EFI_HII_VARSTORE_NAME_VALUE
:
4103 // Skip if there is no RequestElement or data has initilized.
4105 if (Storage
->ElementCount
== 0 || Storage
->BrowserStorage
->Initialized
) {
4108 Storage
->BrowserStorage
->Initialized
= TRUE
;
4109 ConfigRequest
= Storage
->ConfigRequest
;
4117 // Request current settings from Configuration Driver
4119 Status
= mHiiConfigRouting
->ExtractConfig (
4127 // If get value fail, extract default from IFR binary
4129 if (EFI_ERROR (Status
)) {
4130 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForStorage
, Storage
->BrowserStorage
, TRUE
);
4133 // Convert Result from <ConfigAltResp> to <ConfigResp>
4135 StrPtr
= StrStr (Result
, L
"&GUID=");
4136 if (StrPtr
!= NULL
) {
4140 Status
= ConfigRespToStorage (Storage
->BrowserStorage
, Result
);
4144 Storage
->BrowserStorage
->ConfigRequest
= AllocateCopyPool (StrSize (Storage
->ConfigRequest
), Storage
->ConfigRequest
);
4147 // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer.
4149 SynchronizeStorage(FormSet
, Storage
->BrowserStorage
, NULL
, TRUE
);
4151 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
4152 if (ConfigRequest
!= NULL
) {
4153 FreePool (ConfigRequest
);
4159 Get Value changed status from old question.
4161 @param NewFormSet FormSet data structure.
4162 @param OldQuestion Old question which has value changed.
4166 SyncStatusForQuestion (
4167 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
4168 IN FORM_BROWSER_STATEMENT
*OldQuestion
4172 LIST_ENTRY
*QuestionLink
;
4173 FORM_BROWSER_FORM
*Form
;
4174 FORM_BROWSER_STATEMENT
*Question
;
4177 // For each form in one formset.
4179 Link
= GetFirstNode (&NewFormSet
->FormListHead
);
4180 while (!IsNull (&NewFormSet
->FormListHead
, Link
)) {
4181 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
4182 Link
= GetNextNode (&NewFormSet
->FormListHead
, Link
);
4185 // for each question in one form.
4187 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
4188 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
4189 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
4190 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
4192 if (Question
->QuestionId
== OldQuestion
->QuestionId
) {
4193 Question
->ValueChanged
= TRUE
;
4201 Get Value changed status from old formset.
4203 @param NewFormSet FormSet data structure.
4204 @param OldFormSet FormSet data structure.
4208 SyncStatusForFormSet (
4209 IN OUT FORM_BROWSER_FORMSET
*NewFormSet
,
4210 IN FORM_BROWSER_FORMSET
*OldFormSet
4214 LIST_ENTRY
*QuestionLink
;
4215 FORM_BROWSER_FORM
*Form
;
4216 FORM_BROWSER_STATEMENT
*Question
;
4219 // For each form in one formset.
4221 Link
= GetFirstNode (&OldFormSet
->FormListHead
);
4222 while (!IsNull (&OldFormSet
->FormListHead
, Link
)) {
4223 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
4224 Link
= GetNextNode (&OldFormSet
->FormListHead
, Link
);
4227 // for each question in one form.
4229 QuestionLink
= GetFirstNode (&Form
->StatementListHead
);
4230 while (!IsNull (&Form
->StatementListHead
, QuestionLink
)) {
4231 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (QuestionLink
);
4232 QuestionLink
= GetNextNode (&Form
->StatementListHead
, QuestionLink
);
4234 if (!Question
->ValueChanged
) {
4239 // Find the same question in new formset and update the value changed flag.
4241 SyncStatusForQuestion (NewFormSet
, Question
);
4247 Get current setting of Questions.
4249 @param FormSet FormSet data structure.
4253 InitializeCurrentSetting (
4254 IN OUT FORM_BROWSER_FORMSET
*FormSet
4258 FORMSET_STORAGE
*Storage
;
4259 FORM_BROWSER_FORMSET
*OldFormSet
;
4262 // Try to find pre FormSet in the maintain backup list.
4263 // If old formset != NULL, destroy this formset. Add new formset to gBrowserFormSetList.
4265 OldFormSet
= GetFormSetFromHiiHandle (FormSet
->HiiHandle
);
4266 if (OldFormSet
!= NULL
) {
4267 SyncStatusForFormSet (FormSet
, OldFormSet
);
4268 RemoveEntryList (&OldFormSet
->Link
);
4269 DestroyFormSet (OldFormSet
);
4271 InsertTailList (&gBrowserFormSetList
, &FormSet
->Link
);
4274 // Extract default from IFR binary for no storage questions.
4276 ExtractDefault (FormSet
, NULL
, EFI_HII_DEFAULT_CLASS_STANDARD
, FormSetLevel
, GetDefaultForNoStorage
, NULL
, TRUE
);
4279 // Request current settings from Configuration Driver
4281 Link
= GetFirstNode (&FormSet
->StorageListHead
);
4282 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
4283 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
4285 LoadStorage (FormSet
, Storage
);
4287 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
4293 Fetch the Ifr binary data of a FormSet.
4295 @param Handle PackageList Handle
4296 @param FormSetGuid On input, GUID or class GUID of a formset. If not
4297 specified (NULL or zero GUID), take the first
4298 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
4299 found in package list.
4300 On output, GUID of the formset found(if not NULL).
4301 @param BinaryLength The length of the FormSet IFR binary.
4302 @param BinaryData The buffer designed to receive the FormSet.
4304 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
4305 BufferLength was updated.
4306 @retval EFI_INVALID_PARAMETER The handle is unknown.
4307 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
4308 be found with the requested FormId.
4313 IN EFI_HII_HANDLE Handle
,
4314 IN OUT EFI_GUID
*FormSetGuid
,
4315 OUT UINTN
*BinaryLength
,
4316 OUT UINT8
**BinaryData
4320 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
4326 UINT32 PackageListLength
;
4327 EFI_HII_PACKAGE_HEADER PackageHeader
;
4329 UINT8 NumberOfClassGuid
;
4330 BOOLEAN ClassGuidMatch
;
4331 EFI_GUID
*ClassGuid
;
4332 EFI_GUID
*ComparingGuid
;
4336 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
4339 // if FormSetGuid is NULL or zero GUID, return first Setup FormSet in the package list
4341 if (FormSetGuid
== NULL
) {
4342 ComparingGuid
= &gZeroGuid
;
4344 ComparingGuid
= FormSetGuid
;
4348 // Get HII PackageList
4351 HiiPackageList
= NULL
;
4352 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
4353 if (Status
== EFI_BUFFER_TOO_SMALL
) {
4354 HiiPackageList
= AllocatePool (BufferSize
);
4355 ASSERT (HiiPackageList
!= NULL
);
4357 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
4359 if (EFI_ERROR (Status
)) {
4362 ASSERT (HiiPackageList
!= NULL
);
4365 // Get Form package from this HII package List
4367 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
4369 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
4371 ClassGuidMatch
= FALSE
;
4372 while (Offset
< PackageListLength
) {
4373 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
4374 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4376 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
4378 // Search FormSet in this Form Package
4380 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
4381 while (Offset2
< PackageHeader
.Length
) {
4382 OpCodeData
= Package
+ Offset2
;
4384 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
4386 // Try to compare against formset GUID
4388 if (CompareGuid (FormSetGuid
, &gZeroGuid
) ||
4389 CompareGuid (ComparingGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
4393 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
4395 // Try to compare against formset class GUID
4397 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
4398 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
4399 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
4400 if (CompareGuid (ComparingGuid
, ClassGuid
+ Index
)) {
4401 ClassGuidMatch
= TRUE
;
4405 if (ClassGuidMatch
) {
4408 } else if (ComparingGuid
== &gEfiHiiPlatformSetupFormsetGuid
) {
4409 ClassGuidMatch
= TRUE
;
4414 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
4417 if (Offset2
< PackageHeader
.Length
) {
4419 // Target formset found
4425 Offset
+= PackageHeader
.Length
;
4428 if (Offset
>= PackageListLength
) {
4430 // Form package not found in this Package List
4432 FreePool (HiiPackageList
);
4433 return EFI_NOT_FOUND
;
4436 if (FormSetGuid
!= NULL
) {
4438 // Return the FormSet GUID
4440 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
4444 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
4445 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
4446 // of the Form Package.
4448 *BinaryLength
= PackageHeader
.Length
- Offset2
;
4449 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
4451 FreePool (HiiPackageList
);
4453 if (*BinaryData
== NULL
) {
4454 return EFI_OUT_OF_RESOURCES
;
4462 Initialize the internal data structure of a FormSet.
4464 @param Handle PackageList Handle
4465 @param FormSetGuid On input, GUID or class GUID of a formset. If not
4466 specified (NULL or zero GUID), take the first
4467 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
4468 found in package list.
4469 On output, GUID of the formset found(if not NULL).
4470 @param FormSet FormSet data structure.
4472 @retval EFI_SUCCESS The function completed successfully.
4473 @retval EFI_NOT_FOUND The specified FormSet could not be found.
4478 IN EFI_HII_HANDLE Handle
,
4479 IN OUT EFI_GUID
*FormSetGuid
,
4480 OUT FORM_BROWSER_FORMSET
*FormSet
4484 EFI_HANDLE DriverHandle
;
4486 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
4487 if (EFI_ERROR (Status
)) {
4491 FormSet
->Signature
= FORM_BROWSER_FORMSET_SIGNATURE
;
4492 FormSet
->HiiHandle
= Handle
;
4493 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
4494 FormSet
->QuestionInited
= FALSE
;
4497 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
4499 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
4500 if (EFI_ERROR (Status
)) {
4503 FormSet
->DriverHandle
= DriverHandle
;
4504 Status
= gBS
->HandleProtocol (
4506 &gEfiHiiConfigAccessProtocolGuid
,
4507 (VOID
**) &FormSet
->ConfigAccess
4509 if (EFI_ERROR (Status
)) {
4511 // Configuration Driver don't attach ConfigAccess protocol to its HII package
4512 // list, then there will be no configuration action required
4514 FormSet
->ConfigAccess
= NULL
;
4518 // Parse the IFR binary OpCodes
4520 Status
= ParseOpCodes (FormSet
);
4527 Save globals used by previous call to SendForm(). SendForm() may be called from
4528 HiiConfigAccess.Callback(), this will cause SendForm() be reentried.
4529 So, save globals of previous call to SendForm() and restore them upon exit.
4533 SaveBrowserContext (
4537 BROWSER_CONTEXT
*Context
;
4538 FORM_ENTRY_INFO
*MenuList
;
4540 gBrowserContextCount
++;
4541 if (gBrowserContextCount
== 1) {
4543 // This is not reentry of SendForm(), no context to save
4548 Context
= AllocatePool (sizeof (BROWSER_CONTEXT
));
4549 ASSERT (Context
!= NULL
);
4551 Context
->Signature
= BROWSER_CONTEXT_SIGNATURE
;
4554 // Save FormBrowser context
4556 Context
->Selection
= gCurrentSelection
;
4557 Context
->ResetRequired
= gResetRequired
;
4558 Context
->ExitRequired
= gExitRequired
;
4559 Context
->HiiHandle
= mCurrentHiiHandle
;
4560 Context
->FormId
= mCurrentFormId
;
4561 CopyGuid (&Context
->FormSetGuid
, &mCurrentFormSetGuid
);
4564 // Save the menu history data.
4566 InitializeListHead(&Context
->FormHistoryList
);
4567 while (!IsListEmpty (&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
)) {
4568 MenuList
= FORM_ENTRY_INFO_FROM_LINK (mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
.ForwardLink
);
4569 RemoveEntryList (&MenuList
->Link
);
4571 InsertTailList(&Context
->FormHistoryList
, &MenuList
->Link
);
4575 // Insert to FormBrowser context list
4577 InsertHeadList (&gBrowserContextList
, &Context
->Link
);
4582 Restore globals used by previous call to SendForm().
4586 RestoreBrowserContext (
4591 BROWSER_CONTEXT
*Context
;
4592 FORM_ENTRY_INFO
*MenuList
;
4594 ASSERT (gBrowserContextCount
!= 0);
4595 gBrowserContextCount
--;
4596 if (gBrowserContextCount
== 0) {
4598 // This is not reentry of SendForm(), no context to restore
4603 ASSERT (!IsListEmpty (&gBrowserContextList
));
4605 Link
= GetFirstNode (&gBrowserContextList
);
4606 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
4609 // Restore FormBrowser context
4611 gCurrentSelection
= Context
->Selection
;
4612 gResetRequired
= Context
->ResetRequired
;
4613 gExitRequired
= Context
->ExitRequired
;
4614 mCurrentHiiHandle
= Context
->HiiHandle
;
4615 mCurrentFormId
= Context
->FormId
;
4616 CopyGuid (&mCurrentFormSetGuid
, &Context
->FormSetGuid
);
4619 // Restore the menu history data.
4621 while (!IsListEmpty (&Context
->FormHistoryList
)) {
4622 MenuList
= FORM_ENTRY_INFO_FROM_LINK (Context
->FormHistoryList
.ForwardLink
);
4623 RemoveEntryList (&MenuList
->Link
);
4625 InsertTailList(&mPrivateData
.FormBrowserEx2
.FormViewHistoryHead
, &MenuList
->Link
);
4629 // Remove from FormBrowser context list
4631 RemoveEntryList (&Context
->Link
);
4632 gBS
->FreePool (Context
);
4636 Find the matched FormSet context in the backup maintain list based on HiiHandle.
4638 @param Handle The Hii Handle.
4640 @return the found FormSet context. If no found, NULL will return.
4643 FORM_BROWSER_FORMSET
*
4644 GetFormSetFromHiiHandle (
4645 EFI_HII_HANDLE Handle
4649 FORM_BROWSER_FORMSET
*FormSet
;
4651 Link
= GetFirstNode (&gBrowserFormSetList
);
4652 while (!IsNull (&gBrowserFormSetList
, Link
)) {
4653 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
4654 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
4655 if (!ValidateFormSet(FormSet
)) {
4658 if (FormSet
->HiiHandle
== Handle
) {
4667 Check whether the input HII handle is the FormSet that is being used.
4669 @param Handle The Hii Handle.
4671 @retval TRUE HII handle is being used.
4672 @retval FALSE HII handle is not being used.
4676 IsHiiHandleInBrowserContext (
4677 EFI_HII_HANDLE Handle
4681 BROWSER_CONTEXT
*Context
;
4684 // HiiHandle is Current FormSet.
4686 if (mCurrentHiiHandle
== Handle
) {
4691 // Check whether HiiHandle is in BrowserContext.
4693 Link
= GetFirstNode (&gBrowserContextList
);
4694 while (!IsNull (&gBrowserContextList
, Link
)) {
4695 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
4696 if (Context
->HiiHandle
== Handle
) {
4698 // HiiHandle is in BrowserContext
4702 Link
= GetNextNode (&gBrowserContextList
, Link
);
4709 Perform Password check.
4710 Passwork may be encrypted by driver that requires the specific check.
4712 @param Form Form where Password Statement is in.
4713 @param Statement Password statement
4714 @param PasswordString Password string to be checked. It may be NULL.
4715 NULL means to restore password.
4716 "" string can be used to checked whether old password does exist.
4718 @return Status Status of Password check.
4723 IN FORM_DISPLAY_ENGINE_FORM
*Form
,
4724 IN FORM_DISPLAY_ENGINE_STATEMENT
*Statement
,
4725 IN EFI_STRING PasswordString OPTIONAL
4729 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
4730 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
4731 EFI_IFR_TYPE_VALUE IfrTypeValue
;
4732 FORM_BROWSER_STATEMENT
*Question
;
4734 ConfigAccess
= gCurrentSelection
->FormSet
->ConfigAccess
;
4735 Question
= GetBrowserStatement(Statement
);
4736 ASSERT (Question
!= NULL
);
4738 if ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
) {
4739 if (ConfigAccess
== NULL
) {
4740 return EFI_UNSUPPORTED
;
4743 if (PasswordString
== NULL
) {
4748 // Check whether has preexisted password.
4750 if (PasswordString
[0] == 0) {
4751 if (*((CHAR16
*) Question
->BufferValue
) == 0) {
4754 return EFI_NOT_READY
;
4759 // Check whether the input password is same as preexisted password.
4761 if (StrnCmp (PasswordString
, (CHAR16
*) Question
->BufferValue
, Question
->StorageWidth
/sizeof (CHAR16
)) == 0) {
4764 return EFI_NOT_READY
;
4769 // Prepare password string in HII database
4771 if (PasswordString
!= NULL
) {
4772 IfrTypeValue
.string
= NewString (PasswordString
, gCurrentSelection
->FormSet
->HiiHandle
);
4774 IfrTypeValue
.string
= 0;
4778 // Send password to Configuration Driver for validation
4780 Status
= ConfigAccess
->Callback (
4782 EFI_BROWSER_ACTION_CHANGING
,
4783 Question
->QuestionId
,
4784 Question
->HiiValue
.Type
,
4790 // Remove password string from HII database
4792 if (PasswordString
!= NULL
) {
4793 DeleteString (IfrTypeValue
.string
, gCurrentSelection
->FormSet
->HiiHandle
);
4800 Find the registered HotKey based on KeyData.
4802 @param[in] KeyData A pointer to a buffer that describes the keystroke
4803 information for the hot key.
4805 @return The registered HotKey context. If no found, NULL will return.
4808 GetHotKeyFromRegisterList (
4809 IN EFI_INPUT_KEY
*KeyData
4813 BROWSER_HOT_KEY
*HotKey
;
4815 Link
= GetFirstNode (&gBrowserHotKeyList
);
4816 while (!IsNull (&gBrowserHotKeyList
, Link
)) {
4817 HotKey
= BROWSER_HOT_KEY_FROM_LINK (Link
);
4818 if (HotKey
->KeyData
->ScanCode
== KeyData
->ScanCode
) {
4821 Link
= GetNextNode (&gBrowserHotKeyList
, Link
);
4828 Configure what scope the hot key will impact.
4829 All hot keys have the same scope. The mixed hot keys with the different level are not supported.
4830 If no scope is set, the default scope will be FormSet level.
4831 After all registered hot keys are removed, previous Scope can reset to another level.
4833 @param[in] Scope Scope level to be set.
4835 @retval EFI_SUCCESS Scope is set correctly.
4836 @retval EFI_INVALID_PARAMETER Scope is not the valid value specified in BROWSER_SETTING_SCOPE.
4837 @retval EFI_UNSPPORTED Scope level is different from current one that the registered hot keys have.
4843 IN BROWSER_SETTING_SCOPE Scope
4846 if (Scope
>= MaxLevel
) {
4847 return EFI_INVALID_PARAMETER
;
4851 // When no hot key registered in system or on the first setting,
4852 // Scope can be set.
4854 if (mBrowserScopeFirstSet
|| IsListEmpty (&gBrowserHotKeyList
)) {
4855 gBrowserSettingScope
= Scope
;
4856 mBrowserScopeFirstSet
= FALSE
;
4857 } else if (Scope
!= gBrowserSettingScope
) {
4858 return EFI_UNSUPPORTED
;
4865 Register the hot key with its browser action, or unregistered the hot key.
4866 Only support hot key that is not printable character (control key, function key, etc.).
4867 If the action value is zero, the hot key will be unregistered if it has been registered.
4868 If the same hot key has been registered, the new action and help string will override the previous ones.
4870 @param[in] KeyData A pointer to a buffer that describes the keystroke
4871 information for the hot key. Its type is EFI_INPUT_KEY to
4872 be supported by all ConsoleIn devices.
4873 @param[in] Action Action value that describes what action will be trigged when the hot key is pressed.
4874 @param[in] DefaultId Specifies the type of defaults to retrieve, which is only for DEFAULT action.
4875 @param[in] HelpString Help string that describes the hot key information.
4876 Its value may be NULL for the unregistered hot key.
4878 @retval EFI_SUCCESS Hot key is registered or unregistered.
4879 @retval EFI_INVALID_PARAMETER KeyData is NULL or HelpString is NULL on register.
4880 @retval EFI_NOT_FOUND KeyData is not found to be unregistered.
4881 @retval EFI_UNSUPPORTED Key represents a printable character. It is conflicted with Browser.
4886 IN EFI_INPUT_KEY
*KeyData
,
4888 IN UINT16 DefaultId
,
4889 IN EFI_STRING HelpString OPTIONAL
4892 BROWSER_HOT_KEY
*HotKey
;
4895 // Check input parameters.
4897 if (KeyData
== NULL
|| KeyData
->UnicodeChar
!= CHAR_NULL
||
4898 (Action
!= BROWSER_ACTION_UNREGISTER
&& HelpString
== NULL
)) {
4899 return EFI_INVALID_PARAMETER
;
4903 // Check whether the input KeyData is in BrowserHotKeyList.
4905 HotKey
= GetHotKeyFromRegisterList (KeyData
);
4908 // Unregister HotKey
4910 if (Action
== BROWSER_ACTION_UNREGISTER
) {
4911 if (HotKey
!= NULL
) {
4913 // The registered HotKey is found.
4914 // Remove it from List, and free its resource.
4916 RemoveEntryList (&HotKey
->Link
);
4917 FreePool (HotKey
->KeyData
);
4918 FreePool (HotKey
->HelpString
);
4922 // The registered HotKey is not found.
4924 return EFI_NOT_FOUND
;
4929 // Register HotKey into List.
4931 if (HotKey
== NULL
) {
4933 // Create new Key, and add it into List.
4935 HotKey
= AllocateZeroPool (sizeof (BROWSER_HOT_KEY
));
4936 ASSERT (HotKey
!= NULL
);
4937 HotKey
->Signature
= BROWSER_HOT_KEY_SIGNATURE
;
4938 HotKey
->KeyData
= AllocateCopyPool (sizeof (EFI_INPUT_KEY
), KeyData
);
4939 InsertTailList (&gBrowserHotKeyList
, &HotKey
->Link
);
4943 // Fill HotKey information.
4945 HotKey
->Action
= Action
;
4946 HotKey
->DefaultId
= DefaultId
;
4947 if (HotKey
->HelpString
!= NULL
) {
4948 FreePool (HotKey
->HelpString
);
4950 HotKey
->HelpString
= AllocateCopyPool (StrSize (HelpString
), HelpString
);
4956 Register Exit handler function.
4957 When more than one handler function is registered, the latter one will override the previous one.
4958 When NULL handler is specified, the previous Exit handler will be unregistered.
4960 @param[in] Handler Pointer to handler function.
4965 RegiserExitHandler (
4966 IN EXIT_HANDLER Handler
4969 ExitHandlerFunction
= Handler
;
4974 Check whether the browser data has been modified.
4976 @retval TRUE Browser data is modified.
4977 @retval FALSE No browser data is modified.
4982 IsBrowserDataModified (
4987 FORM_BROWSER_FORMSET
*FormSet
;
4989 switch (gBrowserSettingScope
) {
4991 if (gCurrentSelection
== NULL
) {
4994 return IsNvUpdateRequiredForForm (gCurrentSelection
->Form
);
4997 if (gCurrentSelection
== NULL
) {
5000 return IsNvUpdateRequiredForFormSet (gCurrentSelection
->FormSet
);
5003 Link
= GetFirstNode (&gBrowserFormSetList
);
5004 while (!IsNull (&gBrowserFormSetList
, Link
)) {
5005 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
5006 if (!ValidateFormSet(FormSet
)) {
5010 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
5013 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
5023 Execute the action requested by the Action parameter.
5025 @param[in] Action Execute the request action.
5026 @param[in] DefaultId The default Id info when need to load default value. Only used when Action is BROWSER_ACTION_DEFAULT.
5028 @retval EFI_SUCCESS Execute the request action succss.
5029 @retval EFI_INVALID_PARAMETER The input action value is invalid.
5040 FORM_BROWSER_FORMSET
*FormSet
;
5041 FORM_BROWSER_FORM
*Form
;
5043 if (gBrowserSettingScope
< SystemLevel
&& gCurrentSelection
== NULL
) {
5044 return EFI_NOT_READY
;
5047 Status
= EFI_SUCCESS
;
5050 if (gBrowserSettingScope
< SystemLevel
) {
5051 FormSet
= gCurrentSelection
->FormSet
;
5052 Form
= gCurrentSelection
->Form
;
5056 // Executet the discard action.
5058 if ((Action
& BROWSER_ACTION_DISCARD
) != 0) {
5059 Status
= DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
5060 if (EFI_ERROR (Status
)) {
5066 // Executet the difault action.
5068 if ((Action
& BROWSER_ACTION_DEFAULT
) != 0) {
5069 Status
= ExtractDefault (FormSet
, Form
, DefaultId
, gBrowserSettingScope
, GetDefaultForAll
, NULL
, FALSE
);
5070 if (EFI_ERROR (Status
)) {
5073 UpdateStatementStatus (FormSet
, Form
, gBrowserSettingScope
);
5077 // Executet the submit action.
5079 if ((Action
& BROWSER_ACTION_SUBMIT
) != 0) {
5080 Status
= SubmitForm (FormSet
, Form
, gBrowserSettingScope
);
5081 if (EFI_ERROR (Status
)) {
5087 // Executet the reset action.
5089 if ((Action
& BROWSER_ACTION_RESET
) != 0) {
5090 gResetRequired
= TRUE
;
5094 // Executet the exit action.
5096 if ((Action
& BROWSER_ACTION_EXIT
) != 0) {
5097 DiscardForm (FormSet
, Form
, gBrowserSettingScope
);
5098 if (gBrowserSettingScope
== SystemLevel
) {
5099 if (ExitHandlerFunction
!= NULL
) {
5100 ExitHandlerFunction ();
5104 gExitRequired
= TRUE
;
5111 Create reminder to let user to choose save or discard the changed browser data.
5112 Caller can use it to actively check the changed browser data.
5114 @retval BROWSER_NO_CHANGES No browser data is changed.
5115 @retval BROWSER_SAVE_CHANGES The changed browser data is saved.
5116 @retval BROWSER_DISCARD_CHANGES The changed browser data is discard.
5117 @retval BROWSER_KEEP_CURRENT Browser keep current changes.
5127 FORM_BROWSER_FORMSET
*FormSet
;
5128 BOOLEAN IsDataChanged
;
5129 UINT32 DataSavedAction
;
5132 DataSavedAction
= BROWSER_NO_CHANGES
;
5133 IsDataChanged
= FALSE
;
5134 Link
= GetFirstNode (&gBrowserFormSetList
);
5135 while (!IsNull (&gBrowserFormSetList
, Link
)) {
5136 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (Link
);
5137 Link
= GetNextNode (&gBrowserFormSetList
, Link
);
5138 if (!ValidateFormSet(FormSet
)) {
5141 if (IsNvUpdateRequiredForFormSet (FormSet
)) {
5142 IsDataChanged
= TRUE
;
5148 // No data is changed. No save is required.
5150 if (!IsDataChanged
) {
5151 return DataSavedAction
;
5155 // If data is changed, prompt user to save or discard it.
5158 ConfirmRet
= (UINT32
) mFormDisplay
->ConfirmDataChange();
5160 if (ConfirmRet
== BROWSER_ACTION_SUBMIT
) {
5161 SubmitForm (NULL
, NULL
, SystemLevel
);
5162 DataSavedAction
= BROWSER_SAVE_CHANGES
;
5164 } else if (ConfirmRet
== BROWSER_ACTION_DISCARD
) {
5165 DiscardForm (NULL
, NULL
, SystemLevel
);
5166 DataSavedAction
= BROWSER_DISCARD_CHANGES
;
5168 } else if (ConfirmRet
== BROWSER_ACTION_NONE
) {
5169 DataSavedAction
= BROWSER_KEEP_CURRENT
;
5174 return DataSavedAction
;