2 Entry and initialization module for the browser.
4 Copyright (c) 2007 - 2009, 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
*gBannerData
;
33 EFI_HII_HANDLE gFrontPageHandle
;
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
*gFunctionNineString
;
48 CHAR16
*gFunctionTenString
;
50 CHAR16
*gEnterCommitString
;
51 CHAR16
*gEnterEscapeString
;
52 CHAR16
*gEscapeString
;
54 CHAR16
*gMoveHighlight
;
55 CHAR16
*gMakeSelection
;
56 CHAR16
*gDecNumericInput
;
57 CHAR16
*gHexNumericInput
;
58 CHAR16
*gToggleCheckBox
;
59 CHAR16
*gPromptForData
;
60 CHAR16
*gPromptForPassword
;
61 CHAR16
*gPromptForNewPassword
;
62 CHAR16
*gConfirmPassword
;
63 CHAR16
*gConfirmError
;
64 CHAR16
*gPassowordInvalid
;
73 CHAR16
*gAdjustNumber
;
75 CHAR16
*gOptionMismatch
;
77 CHAR16
*mUnknownString
= L
"!";
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 FORM_BROWSER_FORMSET
*gOldFormSet
= NULL
;
90 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
110 NONE_FUNCTION_KEY_SETTING
131 NONE_FUNCTION_KEY_SETTING
152 NONE_FUNCTION_KEY_SETTING
155 // BMM File Explorer FormSet.
173 NONE_FUNCTION_KEY_SETTING
178 This is the routine which an external caller uses to direct the browser
179 where to obtain it's information.
182 @param This The Form Browser protocol instanse.
183 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
184 display a list of the formsets for the handles specified.
185 @param HandleCount The number of Handles specified in Handle.
186 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
187 field in the EFI_IFR_FORM_SET op-code for the specified
188 forms-based package. If FormSetGuid is NULL, then this
189 function will display the first found forms package.
190 @param FormId This field specifies which EFI_IFR_FORM to render as the first
191 displayable page. If this field has a value of 0x0000, then
192 the forms browser will render the specified forms in their encoded order.
193 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
195 @param ActionRequest Points to the action recommended by the form.
197 @retval EFI_SUCCESS The function completed successfully.
198 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
199 @retval EFI_NOT_FOUND No valid forms could be found to display.
205 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
206 IN EFI_HII_HANDLE
*Handles
,
207 IN UINTN HandleCount
,
208 IN EFI_GUID
*FormSetGuid
, OPTIONAL
209 IN UINT16 FormId
, OPTIONAL
210 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
211 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
215 UI_MENU_SELECTION
*Selection
;
217 FORM_BROWSER_FORMSET
*FormSet
;
219 Status
= EFI_SUCCESS
;
220 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
223 // Seed the dimensions in the global
225 gST
->ConOut
->QueryMode (
227 gST
->ConOut
->Mode
->Mode
,
228 &gScreenDimensions
.RightColumn
,
229 &gScreenDimensions
.BottomRow
232 if (ScreenDimensions
!= NULL
) {
234 // Check local dimension vs. global dimension.
236 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
237 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
239 return EFI_INVALID_PARAMETER
;
242 // Local dimension validation.
244 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
245 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
246 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
248 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
249 SCROLL_ARROW_HEIGHT
*
251 FRONT_PAGE_HEADER_HEIGHT
+
256 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
258 return EFI_INVALID_PARAMETER
;
263 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
264 gHelpBlockWidth
= gOptionBlockWidth
;
265 gPromptBlockWidth
= gOptionBlockWidth
;
268 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
270 InitializeBrowserStrings ();
272 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
273 gClassOfVfr
= FORMSET_CLASS_PLATFORM_SETUP
;
276 // Ensure we are in Text mode
278 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
280 for (Index
= 0; Index
< HandleCount
; Index
++) {
281 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
282 ASSERT (Selection
!= NULL
);
284 Selection
->Handle
= Handles
[Index
];
285 if (FormSetGuid
!= NULL
) {
286 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
287 Selection
->FormId
= FormId
;
290 gNvUpdateRequired
= FALSE
;
293 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
294 ASSERT (FormSet
!= NULL
);
297 // Initialize internal data structures of FormSet
299 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
300 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
301 DestroyFormSet (FormSet
);
304 Selection
->FormSet
= FormSet
;
307 // Display this formset
309 gCurrentSelection
= Selection
;
311 Status
= SetupBrowser (Selection
);
313 gCurrentSelection
= NULL
;
315 if (EFI_ERROR (Status
)) {
319 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
321 if (gOldFormSet
!= NULL
) {
322 DestroyFormSet (gOldFormSet
);
326 FreePool (Selection
);
329 if (ActionRequest
!= NULL
) {
330 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
331 if (gResetRequired
) {
332 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
336 FreeBrowserStrings ();
338 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
339 gST
->ConOut
->ClearScreen (gST
->ConOut
);
346 This function is called by a callback handler to retrieve uncommitted state
347 data from the browser.
349 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
351 @param ResultsDataSize A pointer to the size of the buffer associated
353 @param ResultsData A string returned from an IFR browser or
354 equivalent. The results string will have no
355 routing information in them.
356 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
357 (if RetrieveData = TRUE) data from the uncommitted
358 browser state information or set (if RetrieveData
359 = FALSE) data in the uncommitted browser state
361 @param VariableGuid An optional field to indicate the target variable
363 @param VariableName An optional field to indicate the target
364 human-readable variable name.
366 @retval EFI_SUCCESS The results have been distributed or are awaiting
368 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
369 contain the results data.
375 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
376 IN OUT UINTN
*ResultsDataSize
,
377 IN OUT EFI_STRING ResultsData
,
378 IN BOOLEAN RetrieveData
,
379 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
380 IN CONST CHAR16
*VariableName OPTIONAL
385 FORMSET_STORAGE
*Storage
;
386 FORM_BROWSER_FORMSET
*FormSet
;
393 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
394 return EFI_INVALID_PARAMETER
;
397 if (gCurrentSelection
== NULL
) {
398 return EFI_NOT_READY
;
403 FormSet
= gCurrentSelection
->FormSet
;
406 // Find target storage
408 Link
= GetFirstNode (&FormSet
->StorageListHead
);
409 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
410 return EFI_UNSUPPORTED
;
413 if (VariableGuid
!= NULL
) {
415 // Try to find target storage
418 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
419 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
420 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
422 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
423 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
425 // Buffer storage require both GUID and Name
427 if (VariableName
== NULL
) {
428 return EFI_NOT_FOUND
;
431 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
441 return EFI_NOT_FOUND
;
445 // GUID/Name is not specified, take the first storage in FormSet
447 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
452 // Skip if there is no RequestElement
454 if (Storage
->ElementCount
== 0) {
459 // Generate <ConfigResp>
461 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
462 if (EFI_ERROR (Status
)) {
467 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
469 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
471 BufferSize
= StrSize (StrPtr
);
472 if (*ResultsDataSize
< BufferSize
) {
473 *ResultsDataSize
= BufferSize
;
475 FreePool (ConfigResp
);
476 return EFI_BUFFER_TOO_SMALL
;
479 *ResultsDataSize
= BufferSize
;
480 CopyMem (ResultsData
, StrPtr
, BufferSize
);
482 FreePool (ConfigResp
);
485 // Prepare <ConfigResp>
487 TmpSize
= StrLen (ResultsData
);
488 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
489 ConfigResp
= AllocateZeroPool (BufferSize
);
490 ASSERT (ConfigResp
!= NULL
);
492 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
493 StrCat (ConfigResp
, L
"&");
494 StrCat (ConfigResp
, ResultsData
);
497 // Update Browser uncommited data
499 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
500 if (EFI_ERROR (Status
)) {
510 Initialize Setup Browser driver.
512 @param ImageHandle The image handle.
513 @param SystemTable The system table.
515 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
516 @return Other value if failed to initialize the Setup Browser module.
522 IN EFI_HANDLE ImageHandle
,
523 IN EFI_SYSTEM_TABLE
*SystemTable
529 // Locate required Hii relative protocols
531 Status
= gBS
->LocateProtocol (
532 &gEfiHiiDatabaseProtocolGuid
,
534 (VOID
**) &mHiiDatabase
536 ASSERT_EFI_ERROR (Status
);
538 Status
= gBS
->LocateProtocol (
539 &gEfiHiiStringProtocolGuid
,
541 (VOID
**) &mHiiString
543 ASSERT_EFI_ERROR (Status
);
545 Status
= gBS
->LocateProtocol (
546 &gEfiHiiConfigRoutingProtocolGuid
,
548 (VOID
**) &mHiiConfigRouting
550 ASSERT_EFI_ERROR (Status
);
553 // Publish our HII data
555 gHiiHandle
= HiiAddPackages (
561 ASSERT (gHiiHandle
!= NULL
);
564 // Initialize Driver private data
566 gBannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
567 ASSERT (gBannerData
!= NULL
);
570 // Install FormBrowser2 protocol
572 mPrivateData
.Handle
= NULL
;
573 Status
= gBS
->InstallProtocolInterface (
574 &mPrivateData
.Handle
,
575 &gEfiFormBrowser2ProtocolGuid
,
576 EFI_NATIVE_INTERFACE
,
577 &mPrivateData
.FormBrowser2
579 ASSERT_EFI_ERROR (Status
);
586 Create a new string in HII Package List.
588 @param String The String to be added
589 @param HiiHandle The package list in the HII database to insert the
592 @return The output string.
598 IN EFI_HII_HANDLE HiiHandle
601 EFI_STRING_ID StringId
;
603 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
604 ASSERT (StringId
!= 0);
611 Delete a string from HII Package List.
613 @param StringId Id of the string in HII database.
614 @param HiiHandle The HII package list handle.
616 @retval EFI_SUCCESS The string was deleted successfully.
621 IN EFI_STRING_ID StringId
,
622 IN EFI_HII_HANDLE HiiHandle
627 NullChar
= CHAR_NULL
;
628 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
634 Get the string based on the StringId and HII Package List Handle.
636 @param Token The String's ID.
637 @param HiiHandle The package list in the HII database to search for
638 the specified string.
640 @return The output string.
645 IN EFI_STRING_ID Token
,
646 IN EFI_HII_HANDLE HiiHandle
651 String
= HiiGetString (HiiHandle
, Token
, NULL
);
652 if (String
== NULL
) {
653 String
= AllocateCopyPool (sizeof (mUnknownString
), mUnknownString
);
654 ASSERT (String
!= NULL
);
656 return (CHAR16
*) String
;
661 Allocate new memory and then copy the Unicode string Source to Destination.
663 @param Dest Location to copy string
664 @param Src String to copy
669 IN OUT CHAR16
**Dest
,
676 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
677 ASSERT (*Dest
!= NULL
);
682 Allocate new memory and concatinate Source on the end of Destination.
684 @param Dest String to added to the end of.
685 @param Src String to concatinate.
690 IN OUT CHAR16
**Dest
,
698 NewStringCpy (Dest
, Src
);
702 TmpSize
= StrSize (*Dest
);
703 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
704 ASSERT (NewString
!= NULL
);
706 StrCpy (NewString
, *Dest
);
707 StrCat (NewString
, Src
);
715 Synchronize Storage's Edit copy to Shadow copy.
717 @param Storage The Storage to be synchronized.
722 IN FORMSET_STORAGE
*Storage
726 NAME_VALUE_NODE
*Node
;
728 switch (Storage
->Type
) {
729 case EFI_HII_VARSTORE_BUFFER
:
730 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
733 case EFI_HII_VARSTORE_NAME_VALUE
:
734 Link
= GetFirstNode (&Storage
->NameValueListHead
);
735 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
736 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
738 NewStringCpy (&Node
->Value
, Node
->EditValue
);
740 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
744 case EFI_HII_VARSTORE_EFI_VARIABLE
:
752 Get Value for given Name from a NameValue Storage.
754 @param Storage The NameValue Storage.
755 @param Name The Name.
756 @param Value The retured Value.
758 @retval EFI_SUCCESS Value found for given Name.
759 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
764 IN FORMSET_STORAGE
*Storage
,
766 IN OUT CHAR16
**Value
770 NAME_VALUE_NODE
*Node
;
774 Link
= GetFirstNode (&Storage
->NameValueListHead
);
775 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
776 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
778 if (StrCmp (Name
, Node
->Name
) == 0) {
779 NewStringCpy (Value
, Node
->EditValue
);
783 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
786 return EFI_NOT_FOUND
;
791 Set Value of given Name in a NameValue Storage.
793 @param Storage The NameValue Storage.
794 @param Name The Name.
795 @param Value The Value to set.
797 @retval EFI_SUCCESS Value found for given Name.
798 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
803 IN FORMSET_STORAGE
*Storage
,
809 NAME_VALUE_NODE
*Node
;
811 Link
= GetFirstNode (&Storage
->NameValueListHead
);
812 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
813 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
815 if (StrCmp (Name
, Node
->Name
) == 0) {
816 if (Node
->EditValue
!= NULL
) {
817 FreePool (Node
->EditValue
);
819 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
820 ASSERT (Node
->EditValue
!= NULL
);
824 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
827 return EFI_NOT_FOUND
;
832 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
834 @param Storage The Storage to be conveted.
835 @param ConfigResp The returned <ConfigResp>.
837 @retval EFI_SUCCESS Convert success.
838 @retval EFI_INVALID_PARAMETER Incorrect storage type.
842 StorageToConfigResp (
843 IN FORMSET_STORAGE
*Storage
,
844 IN CHAR16
**ConfigResp
850 NAME_VALUE_NODE
*Node
;
852 Status
= EFI_SUCCESS
;
854 switch (Storage
->Type
) {
855 case EFI_HII_VARSTORE_BUFFER
:
856 Status
= mHiiConfigRouting
->BlockToConfig (
858 Storage
->ConfigRequest
,
866 case EFI_HII_VARSTORE_NAME_VALUE
:
868 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
870 Link
= GetFirstNode (&Storage
->NameValueListHead
);
871 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
872 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
874 NewStringCat (ConfigResp
, L
"&");
875 NewStringCat (ConfigResp
, Node
->Name
);
876 NewStringCat (ConfigResp
, L
"=");
877 NewStringCat (ConfigResp
, Node
->EditValue
);
879 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
883 case EFI_HII_VARSTORE_EFI_VARIABLE
:
885 Status
= EFI_INVALID_PARAMETER
;
894 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
896 @param Storage The Storage to receive the settings.
897 @param ConfigResp The <ConfigResp> to be converted.
899 @retval EFI_SUCCESS Convert success.
900 @retval EFI_INVALID_PARAMETER Incorrect storage type.
904 ConfigRespToStorage (
905 IN FORMSET_STORAGE
*Storage
,
906 IN CHAR16
*ConfigResp
916 Status
= EFI_SUCCESS
;
918 switch (Storage
->Type
) {
919 case EFI_HII_VARSTORE_BUFFER
:
920 BufferSize
= Storage
->Size
;
921 Status
= mHiiConfigRouting
->ConfigToBlock (
930 case EFI_HII_VARSTORE_NAME_VALUE
:
931 StrPtr
= StrStr (ConfigResp
, L
"&");
932 while (StrPtr
!= NULL
) {
938 StrPtr
= StrStr (StrPtr
, L
"=");
939 if (StrPtr
== NULL
) {
949 StrPtr
= StrStr (StrPtr
, L
"&");
950 if (StrPtr
!= NULL
) {
953 SetValueByName (Storage
, Name
, Value
);
957 case EFI_HII_VARSTORE_EFI_VARIABLE
:
959 Status
= EFI_INVALID_PARAMETER
;
968 Get Question's current Value.
970 @param FormSet FormSet data structure.
971 @param Form Form data structure.
972 @param Question Question to be initialized.
973 @param Cached TRUE: get from Edit copy FALSE: get from original
976 @retval EFI_SUCCESS The function completed successfully.
981 IN FORM_BROWSER_FORMSET
*FormSet
,
982 IN FORM_BROWSER_FORM
*Form
,
983 IN OUT FORM_BROWSER_STATEMENT
*Question
,
993 FORMSET_STORAGE
*Storage
;
994 EFI_IFR_TYPE_VALUE
*QuestionValue
;
995 CHAR16
*ConfigRequest
;
1003 BOOLEAN IsBufferStorage
;
1008 Status
= EFI_SUCCESS
;
1011 // Statement don't have storage, skip them
1013 if (Question
->QuestionId
== 0) {
1018 // Question value is provided by an Expression, evaluate it
1020 if (Question
->ValueExpression
!= NULL
) {
1021 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1022 if (!EFI_ERROR (Status
)) {
1023 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1029 // Question value is provided by RTC
1031 Storage
= Question
->Storage
;
1032 QuestionValue
= &Question
->HiiValue
.Value
;
1033 if (Storage
== NULL
) {
1035 // It's a Question without storage, or RTC date/time
1037 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1039 // Date and time define the same Flags bit
1041 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1042 case QF_DATE_STORAGE_TIME
:
1043 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1046 case QF_DATE_STORAGE_WAKEUP
:
1047 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1050 case QF_DATE_STORAGE_NORMAL
:
1053 // For date/time without storage
1058 if (EFI_ERROR (Status
)) {
1062 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1063 QuestionValue
->date
.Year
= EfiTime
.Year
;
1064 QuestionValue
->date
.Month
= EfiTime
.Month
;
1065 QuestionValue
->date
.Day
= EfiTime
.Day
;
1067 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1068 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1069 QuestionValue
->time
.Second
= EfiTime
.Second
;
1077 // Question value is provided by EFI variable
1079 StorageWidth
= Question
->StorageWidth
;
1080 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1081 if (Question
->BufferValue
!= NULL
) {
1082 Dst
= Question
->BufferValue
;
1084 Dst
= (UINT8
*) QuestionValue
;
1087 Status
= gRT
->GetVariable (
1088 Question
->VariableName
,
1095 // Always return success, even this EFI variable doesn't exist
1101 // Question Value is provided by Buffer Storage or NameValue Storage
1103 if (Question
->BufferValue
!= NULL
) {
1105 // This Question is password or orderedlist
1107 Dst
= Question
->BufferValue
;
1110 // Other type of Questions
1112 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1115 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1116 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1118 if (IsBufferStorage
) {
1120 // Copy from storage Edit buffer
1122 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1124 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1125 if (EFI_ERROR (Status
)) {
1129 LengthStr
= StrLen (Value
);
1130 Status
= EFI_SUCCESS
;
1133 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1134 // Add string tail char L'\0' into Length
1136 Length
= StorageWidth
+ sizeof (CHAR16
);
1137 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1138 Status
= EFI_BUFFER_TOO_SMALL
;
1140 StringPtr
= (CHAR16
*) Dst
;
1141 ZeroMem (TemStr
, sizeof (TemStr
));
1142 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1143 StrnCpy (TemStr
, Value
+ Index
, 4);
1144 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1147 // Add tailing L'\0' character
1149 StringPtr
[Index
/4] = L
'\0';
1152 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1153 Status
= EFI_BUFFER_TOO_SMALL
;
1155 ZeroMem (TemStr
, sizeof (TemStr
));
1156 for (Index
= 0; Index
< LengthStr
; Index
++) {
1157 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1158 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1159 if ((Index
& 1) == 0) {
1160 Dst
[Index
/2] = DigitUint8
;
1162 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1172 // Request current settings from Configuration Driver
1174 if (FormSet
->ConfigAccess
== NULL
) {
1175 return EFI_NOT_FOUND
;
1179 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1180 // <ConfigHdr> + "&" + <VariableName>
1182 if (IsBufferStorage
) {
1183 Length
= StrLen (Storage
->ConfigHdr
);
1184 Length
+= StrLen (Question
->BlockName
);
1186 Length
= StrLen (Storage
->ConfigHdr
);
1187 Length
+= StrLen (Question
->VariableName
) + 1;
1189 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1190 ASSERT (ConfigRequest
!= NULL
);
1192 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1193 if (IsBufferStorage
) {
1194 StrCat (ConfigRequest
, Question
->BlockName
);
1196 StrCat (ConfigRequest
, L
"&");
1197 StrCat (ConfigRequest
, Question
->VariableName
);
1200 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1201 FormSet
->ConfigAccess
,
1206 if (EFI_ERROR (Status
)) {
1211 // Skip <ConfigRequest>
1213 Value
= Result
+ Length
;
1214 if (IsBufferStorage
) {
1220 if (*Value
!= '=') {
1222 return EFI_NOT_FOUND
;
1225 // Skip '=', point to value
1230 // Suppress <AltResp> if any
1233 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1238 LengthStr
= StrLen (Value
);
1239 Status
= EFI_SUCCESS
;
1240 if (!IsBufferStorage
&& IsString
) {
1242 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1243 // Add string tail char L'\0' into Length
1245 Length
= StorageWidth
+ sizeof (CHAR16
);
1246 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1247 Status
= EFI_BUFFER_TOO_SMALL
;
1249 StringPtr
= (CHAR16
*) Dst
;
1250 ZeroMem (TemStr
, sizeof (TemStr
));
1251 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1252 StrnCpy (TemStr
, Value
+ Index
, 4);
1253 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1256 // Add tailing L'\0' character
1258 StringPtr
[Index
/4] = L
'\0';
1261 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1262 Status
= EFI_BUFFER_TOO_SMALL
;
1264 ZeroMem (TemStr
, sizeof (TemStr
));
1265 for (Index
= 0; Index
< LengthStr
; Index
++) {
1266 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1267 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1268 if ((Index
& 1) == 0) {
1269 Dst
[Index
/2] = DigitUint8
;
1271 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1277 if (EFI_ERROR (Status
)) {
1283 // Synchronize Edit Buffer
1285 if (IsBufferStorage
) {
1286 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1288 SetValueByName (Storage
, Question
->VariableName
, Value
);
1299 Save Question Value to edit copy(cached) or Storage(uncached).
1301 @param FormSet FormSet data structure.
1302 @param Form Form data structure.
1303 @param Question Pointer to the Question.
1304 @param Cached TRUE: set to Edit copy FALSE: set to original
1307 @retval EFI_SUCCESS The function completed successfully.
1312 IN FORM_BROWSER_FORMSET
*FormSet
,
1313 IN FORM_BROWSER_FORM
*Form
,
1314 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1325 FORMSET_STORAGE
*Storage
;
1326 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1331 BOOLEAN IsBufferStorage
;
1338 Status
= EFI_SUCCESS
;
1341 // Statement don't have storage, skip them
1343 if (Question
->QuestionId
== 0) {
1348 // If Question value is provided by an Expression, then it is read only
1350 if (Question
->ValueExpression
!= NULL
) {
1355 // Question value is provided by RTC
1357 Storage
= Question
->Storage
;
1358 QuestionValue
= &Question
->HiiValue
.Value
;
1359 if (Storage
== NULL
) {
1361 // It's a Question without storage, or RTC date/time
1363 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1365 // Date and time define the same Flags bit
1367 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1368 case QF_DATE_STORAGE_TIME
:
1369 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1372 case QF_DATE_STORAGE_WAKEUP
:
1373 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1376 case QF_DATE_STORAGE_NORMAL
:
1379 // For date/time without storage
1384 if (EFI_ERROR (Status
)) {
1388 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1389 EfiTime
.Year
= QuestionValue
->date
.Year
;
1390 EfiTime
.Month
= QuestionValue
->date
.Month
;
1391 EfiTime
.Day
= QuestionValue
->date
.Day
;
1393 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1394 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1395 EfiTime
.Second
= QuestionValue
->time
.Second
;
1398 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1399 Status
= gRT
->SetTime (&EfiTime
);
1401 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1409 // Question value is provided by EFI variable
1411 StorageWidth
= Question
->StorageWidth
;
1412 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1413 if (Question
->BufferValue
!= NULL
) {
1414 Src
= Question
->BufferValue
;
1416 Src
= (UINT8
*) QuestionValue
;
1419 Status
= gRT
->SetVariable (
1420 Question
->VariableName
,
1422 Storage
->Attributes
,
1430 // Question Value is provided by Buffer Storage or NameValue Storage
1432 if (Question
->BufferValue
!= NULL
) {
1433 Src
= Question
->BufferValue
;
1435 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1438 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1439 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1440 if (IsBufferStorage
) {
1442 // Copy to storage edit buffer
1444 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1448 // Allocate enough string buffer.
1451 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1452 Value
= AllocateZeroPool (BufferLen
);
1453 ASSERT (Value
!= NULL
);
1455 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1457 TemName
= (CHAR16
*) Src
;
1459 for (; *TemName
!= L
'\0'; TemName
++) {
1460 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1463 BufferLen
= StorageWidth
* 2 + 1;
1464 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1465 ASSERT (Value
!= NULL
);
1467 // Convert Buffer to Hex String
1469 TemBuffer
= Src
+ StorageWidth
- 1;
1471 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1472 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1476 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1482 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1483 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1485 if (IsBufferStorage
) {
1486 Length
= StrLen (Question
->BlockName
) + 7;
1488 Length
= StrLen (Question
->VariableName
) + 2;
1490 if (!IsBufferStorage
&& IsString
) {
1491 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1493 Length
+= (StorageWidth
* 2);
1495 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1496 ASSERT (ConfigResp
!= NULL
);
1498 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1499 if (IsBufferStorage
) {
1500 StrCat (ConfigResp
, Question
->BlockName
);
1501 StrCat (ConfigResp
, L
"&VALUE=");
1503 StrCat (ConfigResp
, L
"&");
1504 StrCat (ConfigResp
, Question
->VariableName
);
1505 StrCat (ConfigResp
, L
"=");
1508 Value
= ConfigResp
+ StrLen (ConfigResp
);
1510 if (!IsBufferStorage
&& IsString
) {
1512 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1514 TemName
= (CHAR16
*) Src
;
1516 for (; *TemName
!= L
'\0'; TemName
++) {
1517 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1521 // Convert Buffer to Hex String
1523 TemBuffer
= Src
+ StorageWidth
- 1;
1525 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1526 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1531 // Convert to lower char.
1533 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
1534 if (*Value
>= L
'A' && *Value
<= L
'Z') {
1535 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
1540 // Submit Question Value to Configuration Driver
1542 if (FormSet
->ConfigAccess
!= NULL
) {
1543 Status
= FormSet
->ConfigAccess
->RouteConfig (
1544 FormSet
->ConfigAccess
,
1548 if (EFI_ERROR (Status
)) {
1549 FreePool (ConfigResp
);
1553 FreePool (ConfigResp
);
1556 // Synchronize shadow Buffer
1558 SynchronizeStorage (Storage
);
1566 Perform inconsistent check for a Form.
1568 @param FormSet FormSet data structure.
1569 @param Form Form data structure.
1570 @param Question The Question to be validated.
1571 @param Type Validation type: InConsistent or NoSubmit
1573 @retval EFI_SUCCESS Form validation pass.
1574 @retval other Form validation failed.
1579 IN FORM_BROWSER_FORMSET
*FormSet
,
1580 IN FORM_BROWSER_FORM
*Form
,
1581 IN FORM_BROWSER_STATEMENT
*Question
,
1587 LIST_ENTRY
*ListHead
;
1590 FORM_EXPRESSION
*Expression
;
1592 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1593 ListHead
= &Question
->InconsistentListHead
;
1594 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1595 ListHead
= &Question
->NoSubmitListHead
;
1597 return EFI_UNSUPPORTED
;
1600 Link
= GetFirstNode (ListHead
);
1601 while (!IsNull (ListHead
, Link
)) {
1602 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1605 // Evaluate the expression
1607 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1608 if (EFI_ERROR (Status
)) {
1612 if (Expression
->Result
.Value
.b
) {
1614 // Condition meet, show up error message
1616 if (Expression
->Error
!= 0) {
1617 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1619 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1620 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1624 return EFI_NOT_READY
;
1627 Link
= GetNextNode (ListHead
, Link
);
1635 Perform NoSubmit check for a Form.
1637 @param FormSet FormSet data structure.
1638 @param Form Form data structure.
1640 @retval EFI_SUCCESS Form validation pass.
1641 @retval other Form validation failed.
1646 IN FORM_BROWSER_FORMSET
*FormSet
,
1647 IN FORM_BROWSER_FORM
*Form
1652 FORM_BROWSER_STATEMENT
*Question
;
1654 Link
= GetFirstNode (&Form
->StatementListHead
);
1655 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1656 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1658 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1659 if (EFI_ERROR (Status
)) {
1663 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1673 @param FormSet FormSet data structure.
1674 @param Form Form data structure.
1676 @retval EFI_SUCCESS The function completed successfully.
1681 IN FORM_BROWSER_FORMSET
*FormSet
,
1682 IN FORM_BROWSER_FORM
*Form
1687 EFI_STRING ConfigResp
;
1688 EFI_STRING Progress
;
1689 FORMSET_STORAGE
*Storage
;
1692 // Validate the Form by NoSubmit check
1694 Status
= NoSubmitCheck (FormSet
, Form
);
1695 if (EFI_ERROR (Status
)) {
1700 // Submit Buffer storage or Name/Value storage
1702 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1703 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1704 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1705 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1707 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1712 // Skip if there is no RequestElement
1714 if (Storage
->ElementCount
== 0) {
1719 // Prepare <ConfigResp>
1721 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1722 if (EFI_ERROR (Status
)) {
1727 // Send <ConfigResp> to Configuration Driver
1729 if (FormSet
->ConfigAccess
!= NULL
) {
1730 Status
= FormSet
->ConfigAccess
->RouteConfig (
1731 FormSet
->ConfigAccess
,
1735 if (EFI_ERROR (Status
)) {
1736 FreePool (ConfigResp
);
1740 FreePool (ConfigResp
);
1743 // Config success, update storage shadow Buffer
1745 SynchronizeStorage (Storage
);
1748 gNvUpdateRequired
= FALSE
;
1755 Reset Question to its default value.
1757 @param FormSet The form set.
1758 @param Form The form.
1759 @param Question The question.
1760 @param DefaultId The Class of the default.
1762 @retval EFI_SUCCESS Question is reset to default value.
1766 GetQuestionDefault (
1767 IN FORM_BROWSER_FORMSET
*FormSet
,
1768 IN FORM_BROWSER_FORM
*Form
,
1769 IN FORM_BROWSER_STATEMENT
*Question
,
1775 QUESTION_DEFAULT
*Default
;
1776 QUESTION_OPTION
*Option
;
1777 EFI_HII_VALUE
*HiiValue
;
1779 EFI_STRING StrValue
;
1781 Status
= EFI_SUCCESS
;
1785 // Statement don't have storage, skip them
1787 if (Question
->QuestionId
== 0) {
1792 // There are three ways to specify default value for a Question:
1793 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1794 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1795 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1797 HiiValue
= &Question
->HiiValue
;
1800 // EFI_IFR_DEFAULT has highest priority
1802 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1803 Link
= GetFirstNode (&Question
->DefaultListHead
);
1804 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1805 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1807 if (Default
->DefaultId
== DefaultId
) {
1808 if (Default
->ValueExpression
!= NULL
) {
1810 // Default is provided by an Expression, evaluate it
1812 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1813 if (EFI_ERROR (Status
)) {
1817 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1820 // Default value is embedded in EFI_IFR_DEFAULT
1822 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1825 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
1826 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
1827 if (StrValue
== NULL
) {
1828 return EFI_NOT_FOUND
;
1830 Question
->BufferValue
= AllocateCopyPool (StrSize (StrValue
), StrValue
);
1836 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1841 // EFI_ONE_OF_OPTION
1843 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1844 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1846 // OneOfOption could only provide Standard and Manufacturing default
1848 Link
= GetFirstNode (&Question
->OptionListHead
);
1849 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1850 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1852 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1853 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1855 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1860 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1866 // EFI_IFR_CHECKBOX - lowest priority
1868 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1869 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1871 // Checkbox could only provide Standard and Manufacturing default
1873 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1874 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1876 HiiValue
->Value
.b
= TRUE
;
1878 HiiValue
->Value
.b
= FALSE
;
1886 // For Questions without default
1888 switch (Question
->Operand
) {
1889 case EFI_IFR_ONE_OF_OP
:
1891 // Take first oneof option as oneof's default value
1893 if (ValueToOption (Question
, HiiValue
) == NULL
) {
1894 Link
= GetFirstNode (&Question
->OptionListHead
);
1895 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1896 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1897 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1902 case EFI_IFR_ORDERED_LIST_OP
:
1904 // Take option sequence in IFR as ordered list's default value
1907 Link
= GetFirstNode (&Question
->OptionListHead
);
1908 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1909 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1911 SetArrayData (Question
->BufferValue
, Question
->ValueType
, Index
, Option
->Value
.Value
.u64
);
1914 if (Index
>= Question
->MaxContainers
) {
1918 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1923 Status
= EFI_NOT_FOUND
;
1932 Reset Questions in a Form to their default value.
1934 @param FormSet FormSet data structure.
1935 @param Form The Form which to be reset.
1936 @param DefaultId The Class of the default.
1938 @retval EFI_SUCCESS The function completed successfully.
1942 ExtractFormDefault (
1943 IN FORM_BROWSER_FORMSET
*FormSet
,
1944 IN FORM_BROWSER_FORM
*Form
,
1950 FORM_BROWSER_STATEMENT
*Question
;
1952 Link
= GetFirstNode (&Form
->StatementListHead
);
1953 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1954 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1955 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1958 // If Question is disabled, don't reset it to default
1960 if (Question
->DisableExpression
!= NULL
) {
1961 Status
= EvaluateExpression (FormSet
, Form
, Question
->DisableExpression
);
1962 if (!EFI_ERROR (Status
) && Question
->DisableExpression
->Result
.Value
.b
) {
1968 // Reset Question to its default value
1970 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1971 if (EFI_ERROR (Status
)) {
1976 // Synchronize Buffer storage's Edit buffer
1978 if ((Question
->Storage
!= NULL
) &&
1979 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1980 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1989 Initialize Question's Edit copy from Storage.
1991 @param FormSet FormSet data structure.
1992 @param Form Form data structure.
1994 @retval EFI_SUCCESS The function completed successfully.
1999 IN FORM_BROWSER_FORMSET
*FormSet
,
2000 IN FORM_BROWSER_FORM
*Form
2005 FORM_BROWSER_STATEMENT
*Question
;
2007 Link
= GetFirstNode (&Form
->StatementListHead
);
2008 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2009 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2012 // Initialize local copy of Value for each Question
2014 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
2015 if (EFI_ERROR (Status
)) {
2019 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2027 Initialize Question's Edit copy from Storage for the whole Formset.
2029 @param FormSet FormSet data structure.
2031 @retval EFI_SUCCESS The function completed successfully.
2036 IN FORM_BROWSER_FORMSET
*FormSet
2041 FORM_BROWSER_FORM
*Form
;
2043 Link
= GetFirstNode (&FormSet
->FormListHead
);
2044 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2045 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2048 // Initialize local copy of Value for each Form
2050 Status
= LoadFormConfig (FormSet
, Form
);
2051 if (EFI_ERROR (Status
)) {
2055 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2063 Fill storage's edit copy with settings requested from Configuration Driver.
2065 @param FormSet FormSet data structure.
2066 @param Storage Buffer Storage.
2068 @retval EFI_SUCCESS The function completed successfully.
2073 IN FORM_BROWSER_FORMSET
*FormSet
,
2074 IN FORMSET_STORAGE
*Storage
2078 EFI_STRING Progress
;
2082 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2086 if (FormSet
->ConfigAccess
== NULL
) {
2087 return EFI_NOT_FOUND
;
2090 if (Storage
->ElementCount
== 0) {
2092 // Skip if there is no RequestElement
2098 // Request current settings from Configuration Driver
2100 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2101 FormSet
->ConfigAccess
,
2102 Storage
->ConfigRequest
,
2106 if (EFI_ERROR (Status
)) {
2111 // Convert Result from <ConfigAltResp> to <ConfigResp>
2113 StrPtr
= StrStr (Result
, L
"ALTCFG");
2114 if (StrPtr
!= NULL
) {
2118 Status
= ConfigRespToStorage (Storage
, Result
);
2125 Copy uncommitted data from source Storage to destination Storage.
2127 @param Dst Target Storage for uncommitted data.
2128 @param Src Source Storage for uncommitted data.
2130 @retval EFI_SUCCESS The function completed successfully.
2131 @retval EFI_INVALID_PARAMETER Source and destination Storage is not the same type.
2136 IN OUT FORMSET_STORAGE
*Dst
,
2137 IN FORMSET_STORAGE
*Src
2141 NAME_VALUE_NODE
*Node
;
2143 if ((Dst
->Type
!= Src
->Type
) || (Dst
->Size
!= Src
->Size
)) {
2144 return EFI_INVALID_PARAMETER
;
2147 switch (Src
->Type
) {
2148 case EFI_HII_VARSTORE_BUFFER
:
2149 CopyMem (Dst
->EditBuffer
, Src
->EditBuffer
, Src
->Size
);
2152 case EFI_HII_VARSTORE_NAME_VALUE
:
2153 Link
= GetFirstNode (&Src
->NameValueListHead
);
2154 while (!IsNull (&Src
->NameValueListHead
, Link
)) {
2155 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
2157 SetValueByName (Dst
, Node
->Name
, Node
->EditValue
);
2159 Link
= GetNextNode (&Src
->NameValueListHead
, Link
);
2163 case EFI_HII_VARSTORE_EFI_VARIABLE
:
2173 Get current setting of Questions.
2175 @param FormSet FormSet data structure.
2177 @retval EFI_SUCCESS The function completed successfully.
2181 InitializeCurrentSetting (
2182 IN OUT FORM_BROWSER_FORMSET
*FormSet
2187 FORMSET_STORAGE
*Storage
;
2188 FORMSET_STORAGE
*StorageSrc
;
2189 FORMSET_STORAGE
*OldStorage
;
2190 FORM_BROWSER_FORM
*Form
;
2194 // Extract default from IFR binary
2196 Link
= GetFirstNode (&FormSet
->FormListHead
);
2197 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2198 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2200 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2202 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2206 // Request current settings from Configuration Driver
2208 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2209 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2210 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2213 if (gOldFormSet
!= NULL
) {
2215 // Try to find the Storage in backup formset gOldFormSet
2217 Link2
= GetFirstNode (&gOldFormSet
->StorageListHead
);
2218 while (!IsNull (&gOldFormSet
->StorageListHead
, Link2
)) {
2219 StorageSrc
= FORMSET_STORAGE_FROM_LINK (Link2
);
2221 if (StorageSrc
->VarStoreId
== Storage
->VarStoreId
) {
2222 OldStorage
= StorageSrc
;
2226 Link2
= GetNextNode (&gOldFormSet
->StorageListHead
, Link2
);
2230 if (OldStorage
== NULL
) {
2232 // Storage is not found in backup formset, request it from ConfigDriver
2234 Status
= LoadStorage (FormSet
, Storage
);
2237 // Storage found in backup formset, use it
2239 Status
= CopyStorage (Storage
, OldStorage
);
2243 // Now Edit Buffer is filled with default values(lower priority) and current
2244 // settings(higher priority), sychronize it to shadow Buffer
2246 if (!EFI_ERROR (Status
)) {
2247 SynchronizeStorage (Storage
);
2250 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2258 Fetch the Ifr binary data of a FormSet.
2260 @param Handle PackageList Handle
2261 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2262 GUID), take the first FormSet found in package
2264 @param BinaryLength The length of the FormSet IFR binary.
2265 @param BinaryData The buffer designed to receive the FormSet.
2267 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2268 BufferLength was updated.
2269 @retval EFI_INVALID_PARAMETER The handle is unknown.
2270 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2271 be found with the requested FormId.
2276 IN EFI_HII_HANDLE Handle
,
2277 IN OUT EFI_GUID
*FormSetGuid
,
2278 OUT UINTN
*BinaryLength
,
2279 OUT UINT8
**BinaryData
2283 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2289 BOOLEAN ReturnDefault
;
2290 UINT32 PackageListLength
;
2291 EFI_HII_PACKAGE_HEADER PackageHeader
;
2293 UINT8 NumberOfClassGuid
;
2294 BOOLEAN IsSetupClassGuid
;
2295 EFI_GUID
*ClassGuid
;
2299 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2302 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2304 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2305 ReturnDefault
= TRUE
;
2307 ReturnDefault
= FALSE
;
2311 // Get HII PackageList
2314 HiiPackageList
= NULL
;
2315 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2316 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2317 HiiPackageList
= AllocatePool (BufferSize
);
2318 ASSERT (HiiPackageList
!= NULL
);
2320 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2322 if (EFI_ERROR (Status
)) {
2325 ASSERT (HiiPackageList
!= NULL
);
2328 // Get Form package from this HII package List
2330 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2332 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2334 while (Offset
< PackageListLength
) {
2335 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2336 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2338 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2340 // Search FormSet in this Form Package
2342 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2343 while (Offset2
< PackageHeader
.Length
) {
2344 OpCodeData
= Package
+ Offset2
;
2346 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2348 // Check whether return default FormSet
2350 if (ReturnDefault
) {
2352 // Check ClassGuid of formset OpCode
2354 IsSetupClassGuid
= FALSE
;
2355 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
2356 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
2357 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
2358 if (CompareGuid (ClassGuid
+ Index
, &gEfiHiiPlatformSetupFormsetGuid
)) {
2359 IsSetupClassGuid
= TRUE
;
2363 if (IsSetupClassGuid
) {
2369 // FormSet GUID is specified, check it
2371 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2376 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2379 if (Offset2
< PackageHeader
.Length
) {
2381 // Target formset found
2387 Offset
+= PackageHeader
.Length
;
2390 if (Offset
>= PackageListLength
) {
2392 // Form package not found in this Package List
2394 FreePool (HiiPackageList
);
2395 return EFI_NOT_FOUND
;
2398 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2400 // Return the default FormSet GUID
2402 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2406 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2407 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2408 // of the Form Package.
2410 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2411 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2413 FreePool (HiiPackageList
);
2415 if (*BinaryData
== NULL
) {
2416 return EFI_OUT_OF_RESOURCES
;
2424 Initialize the internal data structure of a FormSet.
2426 @param Handle PackageList Handle
2427 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2428 GUID), take the first FormSet found in package
2430 @param FormSet FormSet data structure.
2432 @retval EFI_SUCCESS The function completed successfully.
2433 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2438 IN EFI_HII_HANDLE Handle
,
2439 IN OUT EFI_GUID
*FormSetGuid
,
2440 OUT FORM_BROWSER_FORMSET
*FormSet
2444 EFI_HANDLE DriverHandle
;
2447 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2448 if (EFI_ERROR (Status
)) {
2452 FormSet
->HiiHandle
= Handle
;
2453 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2456 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2458 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2459 if (EFI_ERROR (Status
)) {
2462 FormSet
->DriverHandle
= DriverHandle
;
2463 Status
= gBS
->HandleProtocol (
2465 &gEfiHiiConfigAccessProtocolGuid
,
2466 (VOID
**) &FormSet
->ConfigAccess
2468 if (EFI_ERROR (Status
)) {
2470 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2471 // list, then there will be no configuration action required
2473 FormSet
->ConfigAccess
= NULL
;
2477 // Parse the IFR binary OpCodes
2479 Status
= ParseOpCodes (FormSet
);
2480 if (EFI_ERROR (Status
)) {
2484 gClassOfVfr
= FORMSET_CLASS_PLATFORM_SETUP
;
2485 if (FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
) {
2486 gClassOfVfr
= FORMSET_CLASS_FRONT_PAGE
;
2487 gFrontPageHandle
= FormSet
->HiiHandle
;
2491 // Match GUID to find out the function key setting. If match fail, use the default setting.
2493 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2494 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2496 // Update the function key setting.
2498 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2500 // Function key prompt can not be displayed if the function key has been disabled.
2502 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2503 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2506 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2507 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);