2 Entry and initialization module for the browser.
4 Copyright (c) 2007 - 2008, Intel Corporation
5 All rights reserved. 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.
19 SETUP_DRIVER_PRIVATE_DATA mPrivateData
= {
20 SETUP_DRIVER_SIGNATURE
,
28 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
29 EFI_HII_STRING_PROTOCOL
*mHiiString
;
30 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
32 BANNER_DATA
*BannerData
;
33 EFI_HII_HANDLE FrontPageHandle
;
35 UINTN gFunctionKeySetting
;
36 BOOLEAN gResetRequired
;
37 BOOLEAN gNvUpdateRequired
;
38 EFI_HII_HANDLE gHiiHandle
;
40 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
45 // Browser Global Strings
47 CHAR16
*gFunctionOneString
;
48 CHAR16
*gFunctionTwoString
;
49 CHAR16
*gFunctionNineString
;
50 CHAR16
*gFunctionTenString
;
52 CHAR16
*gEnterCommitString
;
53 CHAR16
*gEnterEscapeString
;
54 CHAR16
*gEscapeString
;
56 CHAR16
*gMoveHighlight
;
57 CHAR16
*gMakeSelection
;
58 CHAR16
*gDecNumericInput
;
59 CHAR16
*gHexNumericInput
;
60 CHAR16
*gToggleCheckBox
;
61 CHAR16
*gPromptForData
;
62 CHAR16
*gPromptForPassword
;
63 CHAR16
*gPromptForNewPassword
;
64 CHAR16
*gConfirmPassword
;
65 CHAR16
*gConfirmError
;
66 CHAR16
*gPassowordInvalid
;
75 CHAR16
*gAdjustNumber
;
77 CHAR16
*gOptionMismatch
;
79 CHAR16 gPromptBlockWidth
;
80 CHAR16 gOptionBlockWidth
;
81 CHAR16 gHelpBlockWidth
;
83 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
84 EFI_GUID gSetupBrowserGuid
= {
85 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
88 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
108 NONE_FUNCTION_KEY_SETTING
129 NONE_FUNCTION_KEY_SETTING
150 NONE_FUNCTION_KEY_SETTING
153 // BMM File Explorer FormSet.
171 NONE_FUNCTION_KEY_SETTING
176 This is the routine which an external caller uses to direct the browser
177 where to obtain it's information.
180 @param This The Form Browser protocol instanse.
181 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
182 display a list of the formsets for the handles specified.
183 @param HandleCount The number of Handles specified in Handle.
184 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
185 field in the EFI_IFR_FORM_SET op-code for the specified
186 forms-based package. If FormSetGuid is NULL, then this
187 function will display the first found forms package.
188 @param FormId This field specifies which EFI_IFR_FORM to render as the first
189 displayable page. If this field has a value of 0x0000, then
190 the forms browser will render the specified forms in their encoded order.
191 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
193 @param ActionRequest Points to the action recommended by the form.
195 @retval EFI_SUCCESS The function completed successfully.
196 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
197 @retval EFI_NOT_FOUND No valid forms could be found to display.
203 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
204 IN EFI_HII_HANDLE
*Handles
,
205 IN UINTN HandleCount
,
206 IN EFI_GUID
*FormSetGuid
, OPTIONAL
207 IN UINT16 FormId
, OPTIONAL
208 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
209 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
213 UI_MENU_SELECTION
*Selection
;
215 FORM_BROWSER_FORMSET
*FormSet
;
217 Status
= EFI_SUCCESS
;
218 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
221 // Seed the dimensions in the global
223 gST
->ConOut
->QueryMode (
225 gST
->ConOut
->Mode
->Mode
,
226 &gScreenDimensions
.RightColumn
,
227 &gScreenDimensions
.BottomRow
230 if (ScreenDimensions
!= NULL
) {
232 // Check local dimension vs. global dimension.
234 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
235 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
237 return EFI_INVALID_PARAMETER
;
240 // Local dimension validation.
242 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
243 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
244 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
246 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
247 SCROLL_ARROW_HEIGHT
*
249 FRONT_PAGE_HEADER_HEIGHT
+
254 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
256 return EFI_INVALID_PARAMETER
;
261 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
262 gHelpBlockWidth
= gOptionBlockWidth
;
263 gPromptBlockWidth
= gOptionBlockWidth
;
266 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
268 InitializeBrowserStrings ();
270 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
271 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
274 // Ensure we are in Text mode
276 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
278 for (Index
= 0; Index
< HandleCount
; Index
++) {
279 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
280 ASSERT (Selection
!= NULL
);
282 Selection
->Handle
= Handles
[Index
];
283 if (FormSetGuid
!= NULL
) {
284 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
285 Selection
->FormId
= FormId
;
289 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
290 ASSERT (FormSet
!= NULL
);
293 // Initialize internal data structures of FormSet
295 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
296 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
297 DestroyFormSet (FormSet
);
300 Selection
->FormSet
= FormSet
;
303 // Initialize current settings of Questions in this FormSet
305 Status
= InitializeCurrentSetting (FormSet
);
306 if (EFI_ERROR (Status
)) {
307 DestroyFormSet (FormSet
);
312 // Display this formset
314 gCurrentSelection
= Selection
;
316 Status
= SetupBrowser (Selection
);
318 gCurrentSelection
= NULL
;
319 DestroyFormSet (FormSet
);
321 if (EFI_ERROR (Status
)) {
325 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
327 FreePool (Selection
);
330 if (ActionRequest
!= NULL
) {
331 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
332 if (gResetRequired
) {
333 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
337 FreeBrowserStrings ();
339 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
340 gST
->ConOut
->ClearScreen (gST
->ConOut
);
347 This function is called by a callback handler to retrieve uncommitted state
348 data from the browser.
350 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
352 @param ResultsDataSize A pointer to the size of the buffer associated
354 @param ResultsData A string returned from an IFR browser or
355 equivalent. The results string will have no
356 routing information in them.
357 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
358 (if RetrieveData = TRUE) data from the uncommitted
359 browser state information or set (if RetrieveData
360 = FALSE) data in the uncommitted browser state
362 @param VariableGuid An optional field to indicate the target variable
364 @param VariableName An optional field to indicate the target
365 human-readable variable name.
367 @retval EFI_SUCCESS The results have been distributed or are awaiting
369 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
370 contain the results data.
376 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
377 IN OUT UINTN
*ResultsDataSize
,
378 IN OUT EFI_STRING ResultsData
,
379 IN BOOLEAN RetrieveData
,
380 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
381 IN CONST CHAR16
*VariableName OPTIONAL
386 FORMSET_STORAGE
*Storage
;
387 FORM_BROWSER_FORMSET
*FormSet
;
394 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
395 return EFI_INVALID_PARAMETER
;
398 if (gCurrentSelection
== NULL
) {
399 return EFI_NOT_READY
;
404 FormSet
= gCurrentSelection
->FormSet
;
407 // Find target storage
409 Link
= GetFirstNode (&FormSet
->StorageListHead
);
410 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
411 return EFI_UNSUPPORTED
;
414 if (VariableGuid
!= NULL
) {
416 // Try to find target storage
419 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
420 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
421 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
423 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
424 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
426 // Buffer storage require both GUID and Name
428 if (VariableName
== NULL
) {
429 return EFI_NOT_FOUND
;
432 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
442 return EFI_NOT_FOUND
;
446 // GUID/Name is not specified, take the first storage in FormSet
448 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
453 // Skip if there is no RequestElement
455 if (Storage
->ElementCount
== 0) {
460 // Generate <ConfigResp>
462 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
463 if (EFI_ERROR (Status
)) {
468 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
470 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
472 BufferSize
= StrSize (StrPtr
);
473 if (*ResultsDataSize
< BufferSize
) {
474 *ResultsDataSize
= BufferSize
;
476 FreePool (ConfigResp
);
477 return EFI_BUFFER_TOO_SMALL
;
480 *ResultsDataSize
= BufferSize
;
481 CopyMem (ResultsData
, StrPtr
, BufferSize
);
483 FreePool (ConfigResp
);
486 // Prepare <ConfigResp>
488 TmpSize
= StrLen (ResultsData
);
489 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
490 ConfigResp
= AllocateZeroPool (BufferSize
);
491 ASSERT (ConfigResp
!= NULL
);
493 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
494 StrCat (ConfigResp
, L
"&");
495 StrCat (ConfigResp
, ResultsData
);
498 // Update Browser uncommited data
500 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
501 if (EFI_ERROR (Status
)) {
511 Initialize Setup Browser driver.
513 @param ImageHandle The image handle.
514 @param SystemTable The system table.
516 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
517 @return Other value if failed to initialize the Setup Browser module.
523 IN EFI_HANDLE ImageHandle
,
524 IN EFI_SYSTEM_TABLE
*SystemTable
530 // Locate required Hii relative protocols
532 Status
= gBS
->LocateProtocol (
533 &gEfiHiiDatabaseProtocolGuid
,
535 (VOID
**) &mHiiDatabase
537 ASSERT_EFI_ERROR (Status
);
539 Status
= gBS
->LocateProtocol (
540 &gEfiHiiStringProtocolGuid
,
542 (VOID
**) &mHiiString
544 ASSERT_EFI_ERROR (Status
);
546 Status
= gBS
->LocateProtocol (
547 &gEfiHiiConfigRoutingProtocolGuid
,
549 (VOID
**) &mHiiConfigRouting
551 ASSERT_EFI_ERROR (Status
);
554 // Publish our HII data
556 gHiiHandle
= HiiAddPackages (
562 ASSERT (gHiiHandle
!= NULL
);
565 // Initialize Driver private data
567 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
568 ASSERT (BannerData
!= NULL
);
571 // Install FormBrowser2 protocol
573 mPrivateData
.Handle
= NULL
;
574 Status
= gBS
->InstallProtocolInterface (
575 &mPrivateData
.Handle
,
576 &gEfiFormBrowser2ProtocolGuid
,
577 EFI_NATIVE_INTERFACE
,
578 &mPrivateData
.FormBrowser2
580 ASSERT_EFI_ERROR (Status
);
587 Create a new string in HII Package List.
589 @param String The String to be added
590 @param HiiHandle The package list in the HII database to insert the
593 @return The output string.
599 IN EFI_HII_HANDLE HiiHandle
602 EFI_STRING_ID StringId
;
604 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
605 ASSERT (StringId
!= 0);
612 Delete a string from HII Package List.
614 @param StringId Id of the string in HII database.
615 @param HiiHandle The HII package list handle.
617 @retval EFI_SUCCESS The string was deleted successfully.
622 IN EFI_STRING_ID StringId
,
623 IN EFI_HII_HANDLE HiiHandle
628 NullChar
= CHAR_NULL
;
629 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
635 Get the string based on the StringId and HII Package List Handle.
637 @param Token The String's ID.
638 @param HiiHandle The package list in the HII database to search for
639 the specified string.
641 @return The output string.
646 IN EFI_STRING_ID Token
,
647 IN EFI_HII_HANDLE HiiHandle
652 String
= HiiGetString (HiiHandle
, Token
, NULL
);
653 ASSERT (String
!= NULL
);
654 return (CHAR16
*) String
;
659 Allocate new memory and then copy the Unicode string Source to Destination.
661 @param Dest Location to copy string
662 @param Src String to copy
667 IN OUT CHAR16
**Dest
,
674 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
675 ASSERT (*Dest
!= NULL
);
680 Allocate new memory and concatinate Source on the end of Destination.
682 @param Dest String to added to the end of.
683 @param Src String to concatinate.
688 IN OUT CHAR16
**Dest
,
696 NewStringCpy (Dest
, Src
);
700 TmpSize
= StrSize (*Dest
);
701 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
702 ASSERT (NewString
!= NULL
);
704 StrCpy (NewString
, *Dest
);
705 StrCat (NewString
, Src
);
713 Synchronize Storage's Edit copy to Shadow copy.
715 @param Storage The Storage to be synchronized.
720 IN FORMSET_STORAGE
*Storage
724 NAME_VALUE_NODE
*Node
;
726 switch (Storage
->Type
) {
727 case EFI_HII_VARSTORE_BUFFER
:
728 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
731 case EFI_HII_VARSTORE_NAME_VALUE
:
732 Link
= GetFirstNode (&Storage
->NameValueListHead
);
733 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
734 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
736 NewStringCpy (&Node
->Value
, Node
->EditValue
);
738 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
742 case EFI_HII_VARSTORE_EFI_VARIABLE
:
750 Get Value for given Name from a NameValue Storage.
752 @param Storage The NameValue Storage.
753 @param Name The Name.
754 @param Value The retured Value.
756 @retval EFI_SUCCESS Value found for given Name.
757 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
762 IN FORMSET_STORAGE
*Storage
,
764 IN OUT CHAR16
**Value
768 NAME_VALUE_NODE
*Node
;
772 Link
= GetFirstNode (&Storage
->NameValueListHead
);
773 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
774 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
776 if (StrCmp (Name
, Node
->Name
) == 0) {
777 NewStringCpy (Value
, Node
->EditValue
);
781 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
784 return EFI_NOT_FOUND
;
789 Set Value of given Name in a NameValue Storage.
791 @param Storage The NameValue Storage.
792 @param Name The Name.
793 @param Value The Value to set.
795 @retval EFI_SUCCESS Value found for given Name.
796 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
801 IN FORMSET_STORAGE
*Storage
,
807 NAME_VALUE_NODE
*Node
;
809 Link
= GetFirstNode (&Storage
->NameValueListHead
);
810 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
811 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
813 if (StrCmp (Name
, Node
->Name
) == 0) {
814 if (Node
->EditValue
!= NULL
) {
815 FreePool (Node
->EditValue
);
817 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
818 ASSERT (Node
->EditValue
!= NULL
);
822 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
825 return EFI_NOT_FOUND
;
830 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
832 @param Storage The Storage to be conveted.
833 @param ConfigResp The returned <ConfigResp>.
835 @retval EFI_SUCCESS Convert success.
836 @retval EFI_INVALID_PARAMETER Incorrect storage type.
840 StorageToConfigResp (
841 IN FORMSET_STORAGE
*Storage
,
842 IN CHAR16
**ConfigResp
848 NAME_VALUE_NODE
*Node
;
850 Status
= EFI_SUCCESS
;
852 switch (Storage
->Type
) {
853 case EFI_HII_VARSTORE_BUFFER
:
854 Status
= mHiiConfigRouting
->BlockToConfig (
856 Storage
->ConfigRequest
,
864 case EFI_HII_VARSTORE_NAME_VALUE
:
866 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
868 Link
= GetFirstNode (&Storage
->NameValueListHead
);
869 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
870 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
872 NewStringCat (ConfigResp
, L
"&");
873 NewStringCat (ConfigResp
, Node
->Name
);
874 NewStringCat (ConfigResp
, L
"=");
875 NewStringCat (ConfigResp
, Node
->EditValue
);
877 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
881 case EFI_HII_VARSTORE_EFI_VARIABLE
:
883 Status
= EFI_INVALID_PARAMETER
;
892 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
894 @param Storage The Storage to receive the settings.
895 @param ConfigResp The <ConfigResp> to be converted.
897 @retval EFI_SUCCESS Convert success.
898 @retval EFI_INVALID_PARAMETER Incorrect storage type.
902 ConfigRespToStorage (
903 IN FORMSET_STORAGE
*Storage
,
904 IN CHAR16
*ConfigResp
914 Status
= EFI_SUCCESS
;
916 switch (Storage
->Type
) {
917 case EFI_HII_VARSTORE_BUFFER
:
918 BufferSize
= Storage
->Size
;
919 Status
= mHiiConfigRouting
->ConfigToBlock (
928 case EFI_HII_VARSTORE_NAME_VALUE
:
929 StrPtr
= StrStr (ConfigResp
, L
"&");
930 while (StrPtr
!= NULL
) {
936 StrPtr
= StrStr (StrPtr
, L
"=");
937 if (StrPtr
== NULL
) {
947 StrPtr
= StrStr (StrPtr
, L
"&");
948 if (StrPtr
!= NULL
) {
951 SetValueByName (Storage
, Name
, Value
);
955 case EFI_HII_VARSTORE_EFI_VARIABLE
:
957 Status
= EFI_INVALID_PARAMETER
;
966 Get Question's current Value.
968 @param FormSet FormSet data structure.
969 @param Form Form data structure.
970 @param Question Question to be initialized.
971 @param Cached TRUE: get from Edit copy FALSE: get from original
974 @retval EFI_SUCCESS The function completed successfully.
979 IN FORM_BROWSER_FORMSET
*FormSet
,
980 IN FORM_BROWSER_FORM
*Form
,
981 IN OUT FORM_BROWSER_STATEMENT
*Question
,
991 FORMSET_STORAGE
*Storage
;
992 EFI_IFR_TYPE_VALUE
*QuestionValue
;
993 CHAR16
*ConfigRequest
;
1001 BOOLEAN IsBufferStorage
;
1006 Status
= EFI_SUCCESS
;
1009 // Statement don't have storage, skip them
1011 if (Question
->QuestionId
== 0) {
1016 // Question value is provided by an Expression, evaluate it
1018 if (Question
->ValueExpression
!= NULL
) {
1019 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1020 if (!EFI_ERROR (Status
)) {
1021 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1027 // Question value is provided by RTC
1029 Storage
= Question
->Storage
;
1030 QuestionValue
= &Question
->HiiValue
.Value
;
1031 if (Storage
== NULL
) {
1033 // It's a Question without storage, or RTC date/time
1035 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1037 // Date and time define the same Flags bit
1039 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1040 case QF_DATE_STORAGE_TIME
:
1041 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1044 case QF_DATE_STORAGE_WAKEUP
:
1045 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1048 case QF_DATE_STORAGE_NORMAL
:
1051 // For date/time without storage
1056 if (EFI_ERROR (Status
)) {
1060 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1061 QuestionValue
->date
.Year
= EfiTime
.Year
;
1062 QuestionValue
->date
.Month
= EfiTime
.Month
;
1063 QuestionValue
->date
.Day
= EfiTime
.Day
;
1065 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1066 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1067 QuestionValue
->time
.Second
= EfiTime
.Second
;
1075 // Question value is provided by EFI variable
1077 StorageWidth
= Question
->StorageWidth
;
1078 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1079 if (Question
->BufferValue
!= NULL
) {
1080 Dst
= Question
->BufferValue
;
1082 Dst
= (UINT8
*) QuestionValue
;
1085 Status
= gRT
->GetVariable (
1086 Question
->VariableName
,
1093 // Always return success, even this EFI variable doesn't exist
1099 // Question Value is provided by Buffer Storage or NameValue Storage
1101 if (Question
->BufferValue
!= NULL
) {
1103 // This Question is password or orderedlist
1105 Dst
= Question
->BufferValue
;
1108 // Other type of Questions
1110 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1113 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1114 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1116 if (IsBufferStorage
) {
1118 // Copy from storage Edit buffer
1120 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1122 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1123 if (EFI_ERROR (Status
)) {
1127 LengthStr
= StrLen (Value
);
1128 Status
= EFI_SUCCESS
;
1131 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1132 // Add string tail char L'\0' into Length
1134 Length
= StorageWidth
+ sizeof (CHAR16
);
1135 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1136 Status
= EFI_BUFFER_TOO_SMALL
;
1138 StringPtr
= (CHAR16
*) Dst
;
1139 ZeroMem (TemStr
, sizeof (TemStr
));
1140 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1141 StrnCpy (TemStr
, Value
+ Index
, 4);
1142 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1145 // Add tailing L'\0' character
1147 StringPtr
[Index
/4] = L
'\0';
1150 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1151 Status
= EFI_BUFFER_TOO_SMALL
;
1153 ZeroMem (TemStr
, sizeof (TemStr
));
1154 for (Index
= 0; Index
< LengthStr
; Index
++) {
1155 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1156 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1157 if ((Index
& 1) == 0) {
1158 Dst
[Index
/2] = DigitUint8
;
1160 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1170 // Request current settings from Configuration Driver
1172 if (FormSet
->ConfigAccess
== NULL
) {
1173 return EFI_NOT_FOUND
;
1177 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1178 // <ConfigHdr> + "&" + <VariableName>
1180 if (IsBufferStorage
) {
1181 Length
= StrLen (Storage
->ConfigHdr
);
1182 Length
+= StrLen (Question
->BlockName
);
1184 Length
= StrLen (Storage
->ConfigHdr
);
1185 Length
+= StrLen (Question
->VariableName
) + 1;
1187 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1188 ASSERT (ConfigRequest
!= NULL
);
1190 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1191 if (IsBufferStorage
) {
1192 StrCat (ConfigRequest
, Question
->BlockName
);
1194 StrCat (ConfigRequest
, L
"&");
1195 StrCat (ConfigRequest
, Question
->VariableName
);
1198 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1199 FormSet
->ConfigAccess
,
1204 if (EFI_ERROR (Status
)) {
1209 // Skip <ConfigRequest>
1211 Value
= Result
+ Length
;
1212 if (IsBufferStorage
) {
1218 if (*Value
!= '=') {
1220 return EFI_NOT_FOUND
;
1223 // Skip '=', point to value
1228 // Suppress <AltResp> if any
1231 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1236 LengthStr
= StrLen (Value
);
1237 Status
= EFI_SUCCESS
;
1238 if (!IsBufferStorage
&& IsString
) {
1240 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1241 // Add string tail char L'\0' into Length
1243 Length
= StorageWidth
+ sizeof (CHAR16
);
1244 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1245 Status
= EFI_BUFFER_TOO_SMALL
;
1247 StringPtr
= (CHAR16
*) Dst
;
1248 ZeroMem (TemStr
, sizeof (TemStr
));
1249 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1250 StrnCpy (TemStr
, Value
+ Index
, 4);
1251 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1254 // Add tailing L'\0' character
1256 StringPtr
[Index
/4] = L
'\0';
1259 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1260 Status
= EFI_BUFFER_TOO_SMALL
;
1262 ZeroMem (TemStr
, sizeof (TemStr
));
1263 for (Index
= 0; Index
< LengthStr
; Index
++) {
1264 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1265 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1266 if ((Index
& 1) == 0) {
1267 Dst
[Index
/2] = DigitUint8
;
1269 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1275 if (EFI_ERROR (Status
)) {
1281 // Synchronize Edit Buffer
1283 if (IsBufferStorage
) {
1284 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1286 SetValueByName (Storage
, Question
->VariableName
, Value
);
1297 Save Question Value to edit copy(cached) or Storage(uncached).
1299 @param FormSet FormSet data structure.
1300 @param Form Form data structure.
1301 @param Question Pointer to the Question.
1302 @param Cached TRUE: set to Edit copy FALSE: set to original
1305 @retval EFI_SUCCESS The function completed successfully.
1310 IN FORM_BROWSER_FORMSET
*FormSet
,
1311 IN FORM_BROWSER_FORM
*Form
,
1312 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1323 FORMSET_STORAGE
*Storage
;
1324 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1329 BOOLEAN IsBufferStorage
;
1336 Status
= EFI_SUCCESS
;
1339 // Statement don't have storage, skip them
1341 if (Question
->QuestionId
== 0) {
1346 // If Question value is provided by an Expression, then it is read only
1348 if (Question
->ValueExpression
!= NULL
) {
1353 // Question value is provided by RTC
1355 Storage
= Question
->Storage
;
1356 QuestionValue
= &Question
->HiiValue
.Value
;
1357 if (Storage
== NULL
) {
1359 // It's a Question without storage, or RTC date/time
1361 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1363 // Date and time define the same Flags bit
1365 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1366 case QF_DATE_STORAGE_TIME
:
1367 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1370 case QF_DATE_STORAGE_WAKEUP
:
1371 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1374 case QF_DATE_STORAGE_NORMAL
:
1377 // For date/time without storage
1382 if (EFI_ERROR (Status
)) {
1386 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1387 EfiTime
.Year
= QuestionValue
->date
.Year
;
1388 EfiTime
.Month
= QuestionValue
->date
.Month
;
1389 EfiTime
.Day
= QuestionValue
->date
.Day
;
1391 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1392 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1393 EfiTime
.Second
= QuestionValue
->time
.Second
;
1396 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1397 Status
= gRT
->SetTime (&EfiTime
);
1399 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1407 // Question value is provided by EFI variable
1409 StorageWidth
= Question
->StorageWidth
;
1410 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1411 if (Question
->BufferValue
!= NULL
) {
1412 Src
= Question
->BufferValue
;
1414 Src
= (UINT8
*) QuestionValue
;
1417 Status
= gRT
->SetVariable (
1418 Question
->VariableName
,
1420 Storage
->Attributes
,
1428 // Question Value is provided by Buffer Storage or NameValue Storage
1430 if (Question
->BufferValue
!= NULL
) {
1431 Src
= Question
->BufferValue
;
1433 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1436 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1437 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1438 if (IsBufferStorage
) {
1440 // Copy to storage edit buffer
1442 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1446 // Allocate enough string buffer.
1449 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1450 Value
= AllocateZeroPool (BufferLen
);
1451 ASSERT (Value
!= NULL
);
1453 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1455 TemName
= (CHAR16
*) Src
;
1457 for (; *TemName
!= L
'\0'; TemName
++) {
1458 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1461 BufferLen
= StorageWidth
* 2 + 1;
1462 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1463 ASSERT (Value
!= NULL
);
1465 // Convert Buffer to Hex String
1467 TemBuffer
= Src
+ StorageWidth
- 1;
1469 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1470 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1474 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1480 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1481 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1483 if (IsBufferStorage
) {
1484 Length
= StrLen (Question
->BlockName
) + 7;
1486 Length
= StrLen (Question
->VariableName
) + 2;
1488 if (!IsBufferStorage
&& IsString
) {
1489 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1491 Length
+= (StorageWidth
* 2);
1493 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1494 ASSERT (ConfigResp
!= NULL
);
1496 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1497 if (IsBufferStorage
) {
1498 StrCat (ConfigResp
, Question
->BlockName
);
1499 StrCat (ConfigResp
, L
"&VALUE=");
1501 StrCat (ConfigResp
, L
"&");
1502 StrCat (ConfigResp
, Question
->VariableName
);
1503 StrCat (ConfigResp
, L
"=");
1506 Value
= ConfigResp
+ StrLen (ConfigResp
);
1508 if (!IsBufferStorage
&& IsString
) {
1510 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1512 TemName
= (CHAR16
*) Src
;
1514 for (; *TemName
!= L
'\0'; TemName
++) {
1515 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1519 // Convert Buffer to Hex String
1521 TemBuffer
= Src
+ StorageWidth
- 1;
1523 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1524 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1529 // Convert to lower char.
1531 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
1532 if (*Value
>= L
'A' && *Value
<= L
'Z') {
1533 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
1538 // Submit Question Value to Configuration Driver
1540 if (FormSet
->ConfigAccess
!= NULL
) {
1541 Status
= FormSet
->ConfigAccess
->RouteConfig (
1542 FormSet
->ConfigAccess
,
1546 if (EFI_ERROR (Status
)) {
1547 FreePool (ConfigResp
);
1551 FreePool (ConfigResp
);
1554 // Synchronize shadow Buffer
1556 SynchronizeStorage (Storage
);
1564 Perform inconsistent check for a Form.
1566 @param FormSet FormSet data structure.
1567 @param Form Form data structure.
1568 @param Question The Question to be validated.
1569 @param Type Validation type: InConsistent or NoSubmit
1571 @retval EFI_SUCCESS Form validation pass.
1572 @retval other Form validation failed.
1577 IN FORM_BROWSER_FORMSET
*FormSet
,
1578 IN FORM_BROWSER_FORM
*Form
,
1579 IN FORM_BROWSER_STATEMENT
*Question
,
1585 LIST_ENTRY
*ListHead
;
1588 FORM_EXPRESSION
*Expression
;
1590 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1591 ListHead
= &Question
->InconsistentListHead
;
1592 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1593 ListHead
= &Question
->NoSubmitListHead
;
1595 return EFI_UNSUPPORTED
;
1598 Link
= GetFirstNode (ListHead
);
1599 while (!IsNull (ListHead
, Link
)) {
1600 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1603 // Evaluate the expression
1605 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1606 if (EFI_ERROR (Status
)) {
1610 if (Expression
->Result
.Value
.b
) {
1612 // Condition meet, show up error message
1614 if (Expression
->Error
!= 0) {
1615 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1617 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1618 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1622 return EFI_NOT_READY
;
1625 Link
= GetNextNode (ListHead
, Link
);
1633 Perform NoSubmit check for a Form.
1635 @param FormSet FormSet data structure.
1636 @param Form Form data structure.
1638 @retval EFI_SUCCESS Form validation pass.
1639 @retval other Form validation failed.
1644 IN FORM_BROWSER_FORMSET
*FormSet
,
1645 IN FORM_BROWSER_FORM
*Form
1650 FORM_BROWSER_STATEMENT
*Question
;
1652 Link
= GetFirstNode (&Form
->StatementListHead
);
1653 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1654 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1656 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1657 if (EFI_ERROR (Status
)) {
1661 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1671 @param FormSet FormSet data structure.
1672 @param Form Form data structure.
1674 @retval EFI_SUCCESS The function completed successfully.
1679 IN FORM_BROWSER_FORMSET
*FormSet
,
1680 IN FORM_BROWSER_FORM
*Form
1685 EFI_STRING ConfigResp
;
1686 EFI_STRING Progress
;
1687 FORMSET_STORAGE
*Storage
;
1690 // Validate the Form by NoSubmit check
1692 Status
= NoSubmitCheck (FormSet
, Form
);
1693 if (EFI_ERROR (Status
)) {
1698 // Submit Buffer storage or Name/Value storage
1700 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1701 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1702 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1703 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1705 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1710 // Skip if there is no RequestElement
1712 if (Storage
->ElementCount
== 0) {
1717 // Prepare <ConfigResp>
1719 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1720 if (EFI_ERROR (Status
)) {
1725 // Send <ConfigResp> to Configuration Driver
1727 if (FormSet
->ConfigAccess
!= NULL
) {
1728 Status
= FormSet
->ConfigAccess
->RouteConfig (
1729 FormSet
->ConfigAccess
,
1733 if (EFI_ERROR (Status
)) {
1734 FreePool (ConfigResp
);
1738 FreePool (ConfigResp
);
1741 // Config success, update storage shadow Buffer
1743 SynchronizeStorage (Storage
);
1746 gNvUpdateRequired
= FALSE
;
1753 Reset Question to its default value.
1755 @param FormSet The form set.
1756 @param Form The form.
1757 @param Question The question.
1758 @param DefaultId The Class of the default.
1760 @retval EFI_SUCCESS Question is reset to default value.
1764 GetQuestionDefault (
1765 IN FORM_BROWSER_FORMSET
*FormSet
,
1766 IN FORM_BROWSER_FORM
*Form
,
1767 IN FORM_BROWSER_STATEMENT
*Question
,
1773 QUESTION_DEFAULT
*Default
;
1774 QUESTION_OPTION
*Option
;
1775 EFI_HII_VALUE
*HiiValue
;
1778 Status
= EFI_SUCCESS
;
1781 // Statement don't have storage, skip them
1783 if (Question
->QuestionId
== 0) {
1788 // There are three ways to specify default value for a Question:
1789 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1790 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1791 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1793 HiiValue
= &Question
->HiiValue
;
1796 // EFI_IFR_DEFAULT has highest priority
1798 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1799 Link
= GetFirstNode (&Question
->DefaultListHead
);
1800 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1801 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1803 if (Default
->DefaultId
== DefaultId
) {
1804 if (Default
->ValueExpression
!= NULL
) {
1806 // Default is provided by an Expression, evaluate it
1808 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1809 if (EFI_ERROR (Status
)) {
1813 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1816 // Default value is embedded in EFI_IFR_DEFAULT
1818 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1824 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1829 // EFI_ONE_OF_OPTION
1831 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1832 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1834 // OneOfOption could only provide Standard and Manufacturing default
1836 Link
= GetFirstNode (&Question
->OptionListHead
);
1837 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1838 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1840 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1841 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1843 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1848 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1854 // EFI_IFR_CHECKBOX - lowest priority
1856 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1857 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1859 // Checkbox could only provide Standard and Manufacturing default
1861 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1862 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1864 HiiValue
->Value
.b
= TRUE
;
1866 HiiValue
->Value
.b
= FALSE
;
1874 // For Questions without default
1876 switch (Question
->Operand
) {
1877 case EFI_IFR_NUMERIC_OP
:
1879 // Take minimal value as numeric's default value
1881 HiiValue
->Value
.u64
= Question
->Minimum
;
1884 case EFI_IFR_ONE_OF_OP
:
1886 // Take first oneof option as oneof's default value
1888 Link
= GetFirstNode (&Question
->OptionListHead
);
1889 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1890 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1891 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1895 case EFI_IFR_ORDERED_LIST_OP
:
1897 // Take option sequence in IFR as ordered list's default value
1900 Link
= GetFirstNode (&Question
->OptionListHead
);
1901 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1902 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1904 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1907 if (Index
>= Question
->MaxContainers
) {
1911 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1916 Status
= EFI_NOT_FOUND
;
1925 Reset Questions in a Form to their default value.
1927 @param FormSet FormSet data structure.
1928 @param Form The Form which to be reset.
1929 @param DefaultId The Class of the default.
1931 @retval EFI_SUCCESS The function completed successfully.
1935 ExtractFormDefault (
1936 IN FORM_BROWSER_FORMSET
*FormSet
,
1937 IN FORM_BROWSER_FORM
*Form
,
1943 FORM_BROWSER_STATEMENT
*Question
;
1945 Link
= GetFirstNode (&Form
->StatementListHead
);
1946 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1947 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1948 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1951 // If Question is suppressed, don't reset it to default
1953 if (Question
->SuppressExpression
!= NULL
) {
1954 Status
= EvaluateExpression (FormSet
, Form
, Question
->SuppressExpression
);
1955 if (!EFI_ERROR (Status
) && Question
->SuppressExpression
->Result
.Value
.b
) {
1961 // Reset Question to its default value
1963 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1964 if (EFI_ERROR (Status
)) {
1969 // Synchronize Buffer storage's Edit buffer
1971 if ((Question
->Storage
!= NULL
) &&
1972 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1973 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1982 Initialize Question's Edit copy from Storage.
1984 @param FormSet FormSet data structure.
1985 @param Form Form data structure.
1987 @retval EFI_SUCCESS The function completed successfully.
1992 IN FORM_BROWSER_FORMSET
*FormSet
,
1993 IN FORM_BROWSER_FORM
*Form
1998 FORM_BROWSER_STATEMENT
*Question
;
2000 Link
= GetFirstNode (&Form
->StatementListHead
);
2001 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2002 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2005 // Initialize local copy of Value for each Question
2007 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
2008 if (EFI_ERROR (Status
)) {
2012 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2020 Fill storage's edit copy with settings requested from Configuration Driver.
2022 @param FormSet FormSet data structure.
2023 @param Storage Buffer Storage.
2025 @retval EFI_SUCCESS The function completed successfully.
2030 IN FORM_BROWSER_FORMSET
*FormSet
,
2031 IN FORMSET_STORAGE
*Storage
2035 EFI_STRING Progress
;
2039 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2043 if (FormSet
->ConfigAccess
== NULL
) {
2044 return EFI_NOT_FOUND
;
2047 if (Storage
->ElementCount
== 0) {
2049 // Skip if there is no RequestElement
2055 // Request current settings from Configuration Driver
2057 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2058 FormSet
->ConfigAccess
,
2059 Storage
->ConfigRequest
,
2063 if (EFI_ERROR (Status
)) {
2068 // Convert Result from <ConfigAltResp> to <ConfigResp>
2070 StrPtr
= StrStr (Result
, L
"ALTCFG");
2071 if (StrPtr
!= NULL
) {
2075 Status
= ConfigRespToStorage (Storage
, Result
);
2082 Get current setting of Questions.
2084 @param FormSet FormSet data structure.
2086 @retval EFI_SUCCESS The function completed successfully.
2090 InitializeCurrentSetting (
2091 IN OUT FORM_BROWSER_FORMSET
*FormSet
2095 FORMSET_STORAGE
*Storage
;
2096 FORM_BROWSER_FORM
*Form
;
2100 // Extract default from IFR binary
2102 Link
= GetFirstNode (&FormSet
->FormListHead
);
2103 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2104 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2106 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2108 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2112 // Request current settings from Configuration Driver
2114 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2115 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2116 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2118 Status
= LoadStorage (FormSet
, Storage
);
2121 // Now Edit Buffer is filled with default values(lower priority) and current
2122 // settings(higher priority), sychronize it to shadow Buffer
2124 if (!EFI_ERROR (Status
)) {
2125 SynchronizeStorage (Storage
);
2128 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2136 Fetch the Ifr binary data of a FormSet.
2138 @param Handle PackageList Handle
2139 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2140 GUID), take the first FormSet found in package
2142 @param BinaryLength The length of the FormSet IFR binary.
2143 @param BinaryData The buffer designed to receive the FormSet.
2145 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2146 BufferLength was updated.
2147 @retval EFI_INVALID_PARAMETER The handle is unknown.
2148 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2149 be found with the requested FormId.
2154 IN EFI_HII_HANDLE Handle
,
2155 IN OUT EFI_GUID
*FormSetGuid
,
2156 OUT UINTN
*BinaryLength
,
2157 OUT UINT8
**BinaryData
2161 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2167 BOOLEAN ReturnDefault
;
2168 UINT32 PackageListLength
;
2169 EFI_HII_PACKAGE_HEADER PackageHeader
;
2173 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2176 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2178 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2179 ReturnDefault
= TRUE
;
2181 ReturnDefault
= FALSE
;
2185 // Get HII PackageList
2188 HiiPackageList
= NULL
;
2189 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2190 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2191 HiiPackageList
= AllocatePool (BufferSize
);
2192 ASSERT (HiiPackageList
!= NULL
);
2194 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2196 if (EFI_ERROR (Status
)) {
2199 ASSERT (HiiPackageList
!= NULL
);
2202 // Get Form package from this HII package List
2204 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2206 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2208 while (Offset
< PackageListLength
) {
2209 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2210 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2212 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2214 // Search FormSet in this Form Package
2216 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2217 while (Offset2
< PackageHeader
.Length
) {
2218 OpCodeData
= Package
+ Offset2
;
2220 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2222 // Check whether return default FormSet
2224 if (ReturnDefault
) {
2229 // FormSet GUID is specified, check it
2231 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2236 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2239 if (Offset2
< PackageHeader
.Length
) {
2241 // Target formset found
2247 Offset
+= PackageHeader
.Length
;
2250 if (Offset
>= PackageListLength
) {
2252 // Form package not found in this Package List
2254 FreePool (HiiPackageList
);
2255 return EFI_NOT_FOUND
;
2258 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2260 // Return the default FormSet GUID
2262 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2266 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2267 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2268 // of the Form Package.
2270 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2271 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2273 FreePool (HiiPackageList
);
2275 if (*BinaryData
== NULL
) {
2276 return EFI_OUT_OF_RESOURCES
;
2284 Initialize the internal data structure of a FormSet.
2286 @param Handle PackageList Handle
2287 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2288 GUID), take the first FormSet found in package
2290 @param FormSet FormSet data structure.
2292 @retval EFI_SUCCESS The function completed successfully.
2293 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2298 IN EFI_HII_HANDLE Handle
,
2299 IN OUT EFI_GUID
*FormSetGuid
,
2300 OUT FORM_BROWSER_FORMSET
*FormSet
2304 EFI_HANDLE DriverHandle
;
2307 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2308 if (EFI_ERROR (Status
)) {
2312 FormSet
->HiiHandle
= Handle
;
2313 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2316 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2318 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2319 if (EFI_ERROR (Status
)) {
2322 FormSet
->DriverHandle
= DriverHandle
;
2323 Status
= gBS
->HandleProtocol (
2325 &gEfiHiiConfigAccessProtocolGuid
,
2326 (VOID
**) &FormSet
->ConfigAccess
2328 if (EFI_ERROR (Status
)) {
2330 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2331 // list, then there will be no configuration action required
2333 FormSet
->ConfigAccess
= NULL
;
2337 // Parse the IFR binary OpCodes
2339 Status
= ParseOpCodes (FormSet
);
2340 if (EFI_ERROR (Status
)) {
2344 gClassOfVfr
= FormSet
->SubClass
;
2345 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2346 FrontPageHandle
= FormSet
->HiiHandle
;
2350 // Match GUID to find out the function key setting. If match fail, use the default setting.
2352 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2353 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2355 // Update the function key setting.
2357 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2359 // Function key prompt can not be displayed if the function key has been disabled.
2361 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2362 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2365 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2366 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2369 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2370 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2373 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2374 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);