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
*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
*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
*mUnknownString
= L
"!";
81 CHAR16 gPromptBlockWidth
;
82 CHAR16 gOptionBlockWidth
;
83 CHAR16 gHelpBlockWidth
;
85 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
86 EFI_GUID gSetupBrowserGuid
= {
87 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
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
;
291 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
292 ASSERT (FormSet
!= NULL
);
295 // Initialize internal data structures of FormSet
297 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
298 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
299 DestroyFormSet (FormSet
);
302 Selection
->FormSet
= FormSet
;
305 // Initialize current settings of Questions in this FormSet
307 Status
= InitializeCurrentSetting (FormSet
);
308 if (EFI_ERROR (Status
)) {
309 DestroyFormSet (FormSet
);
314 // Display this formset
316 gCurrentSelection
= Selection
;
318 Status
= SetupBrowser (Selection
);
320 gCurrentSelection
= NULL
;
321 DestroyFormSet (FormSet
);
323 if (EFI_ERROR (Status
)) {
327 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
329 FreePool (Selection
);
332 if (ActionRequest
!= NULL
) {
333 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
334 if (gResetRequired
) {
335 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
339 FreeBrowserStrings ();
341 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
342 gST
->ConOut
->ClearScreen (gST
->ConOut
);
349 This function is called by a callback handler to retrieve uncommitted state
350 data from the browser.
352 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
354 @param ResultsDataSize A pointer to the size of the buffer associated
356 @param ResultsData A string returned from an IFR browser or
357 equivalent. The results string will have no
358 routing information in them.
359 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
360 (if RetrieveData = TRUE) data from the uncommitted
361 browser state information or set (if RetrieveData
362 = FALSE) data in the uncommitted browser state
364 @param VariableGuid An optional field to indicate the target variable
366 @param VariableName An optional field to indicate the target
367 human-readable variable name.
369 @retval EFI_SUCCESS The results have been distributed or are awaiting
371 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
372 contain the results data.
378 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
379 IN OUT UINTN
*ResultsDataSize
,
380 IN OUT EFI_STRING ResultsData
,
381 IN BOOLEAN RetrieveData
,
382 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
383 IN CONST CHAR16
*VariableName OPTIONAL
388 FORMSET_STORAGE
*Storage
;
389 FORM_BROWSER_FORMSET
*FormSet
;
396 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
397 return EFI_INVALID_PARAMETER
;
400 if (gCurrentSelection
== NULL
) {
401 return EFI_NOT_READY
;
406 FormSet
= gCurrentSelection
->FormSet
;
409 // Find target storage
411 Link
= GetFirstNode (&FormSet
->StorageListHead
);
412 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
413 return EFI_UNSUPPORTED
;
416 if (VariableGuid
!= NULL
) {
418 // Try to find target storage
421 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
422 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
423 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
425 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
426 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
428 // Buffer storage require both GUID and Name
430 if (VariableName
== NULL
) {
431 return EFI_NOT_FOUND
;
434 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
444 return EFI_NOT_FOUND
;
448 // GUID/Name is not specified, take the first storage in FormSet
450 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
455 // Skip if there is no RequestElement
457 if (Storage
->ElementCount
== 0) {
462 // Generate <ConfigResp>
464 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
465 if (EFI_ERROR (Status
)) {
470 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
472 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
474 BufferSize
= StrSize (StrPtr
);
475 if (*ResultsDataSize
< BufferSize
) {
476 *ResultsDataSize
= BufferSize
;
478 FreePool (ConfigResp
);
479 return EFI_BUFFER_TOO_SMALL
;
482 *ResultsDataSize
= BufferSize
;
483 CopyMem (ResultsData
, StrPtr
, BufferSize
);
485 FreePool (ConfigResp
);
488 // Prepare <ConfigResp>
490 TmpSize
= StrLen (ResultsData
);
491 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
492 ConfigResp
= AllocateZeroPool (BufferSize
);
493 ASSERT (ConfigResp
!= NULL
);
495 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
496 StrCat (ConfigResp
, L
"&");
497 StrCat (ConfigResp
, ResultsData
);
500 // Update Browser uncommited data
502 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
503 if (EFI_ERROR (Status
)) {
513 Initialize Setup Browser driver.
515 @param ImageHandle The image handle.
516 @param SystemTable The system table.
518 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
519 @return Other value if failed to initialize the Setup Browser module.
525 IN EFI_HANDLE ImageHandle
,
526 IN EFI_SYSTEM_TABLE
*SystemTable
532 // Locate required Hii relative protocols
534 Status
= gBS
->LocateProtocol (
535 &gEfiHiiDatabaseProtocolGuid
,
537 (VOID
**) &mHiiDatabase
539 ASSERT_EFI_ERROR (Status
);
541 Status
= gBS
->LocateProtocol (
542 &gEfiHiiStringProtocolGuid
,
544 (VOID
**) &mHiiString
546 ASSERT_EFI_ERROR (Status
);
548 Status
= gBS
->LocateProtocol (
549 &gEfiHiiConfigRoutingProtocolGuid
,
551 (VOID
**) &mHiiConfigRouting
553 ASSERT_EFI_ERROR (Status
);
556 // Publish our HII data
558 gHiiHandle
= HiiAddPackages (
564 ASSERT (gHiiHandle
!= NULL
);
567 // Initialize Driver private data
569 gBannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
570 ASSERT (gBannerData
!= NULL
);
573 // Install FormBrowser2 protocol
575 mPrivateData
.Handle
= NULL
;
576 Status
= gBS
->InstallProtocolInterface (
577 &mPrivateData
.Handle
,
578 &gEfiFormBrowser2ProtocolGuid
,
579 EFI_NATIVE_INTERFACE
,
580 &mPrivateData
.FormBrowser2
582 ASSERT_EFI_ERROR (Status
);
589 Create a new string in HII Package List.
591 @param String The String to be added
592 @param HiiHandle The package list in the HII database to insert the
595 @return The output string.
601 IN EFI_HII_HANDLE HiiHandle
604 EFI_STRING_ID StringId
;
606 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
607 ASSERT (StringId
!= 0);
614 Delete a string from HII Package List.
616 @param StringId Id of the string in HII database.
617 @param HiiHandle The HII package list handle.
619 @retval EFI_SUCCESS The string was deleted successfully.
624 IN EFI_STRING_ID StringId
,
625 IN EFI_HII_HANDLE HiiHandle
630 NullChar
= CHAR_NULL
;
631 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
637 Get the string based on the StringId and HII Package List Handle.
639 @param Token The String's ID.
640 @param HiiHandle The package list in the HII database to search for
641 the specified string.
643 @return The output string.
648 IN EFI_STRING_ID Token
,
649 IN EFI_HII_HANDLE HiiHandle
654 String
= HiiGetString (HiiHandle
, Token
, NULL
);
655 if (String
== NULL
) {
656 String
= AllocateCopyPool (sizeof (mUnknownString
), mUnknownString
);
657 ASSERT (String
!= NULL
);
659 return (CHAR16
*) String
;
664 Allocate new memory and then copy the Unicode string Source to Destination.
666 @param Dest Location to copy string
667 @param Src String to copy
672 IN OUT CHAR16
**Dest
,
679 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
680 ASSERT (*Dest
!= NULL
);
685 Allocate new memory and concatinate Source on the end of Destination.
687 @param Dest String to added to the end of.
688 @param Src String to concatinate.
693 IN OUT CHAR16
**Dest
,
701 NewStringCpy (Dest
, Src
);
705 TmpSize
= StrSize (*Dest
);
706 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
707 ASSERT (NewString
!= NULL
);
709 StrCpy (NewString
, *Dest
);
710 StrCat (NewString
, Src
);
718 Synchronize Storage's Edit copy to Shadow copy.
720 @param Storage The Storage to be synchronized.
725 IN FORMSET_STORAGE
*Storage
729 NAME_VALUE_NODE
*Node
;
731 switch (Storage
->Type
) {
732 case EFI_HII_VARSTORE_BUFFER
:
733 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
736 case EFI_HII_VARSTORE_NAME_VALUE
:
737 Link
= GetFirstNode (&Storage
->NameValueListHead
);
738 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
739 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
741 NewStringCpy (&Node
->Value
, Node
->EditValue
);
743 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
747 case EFI_HII_VARSTORE_EFI_VARIABLE
:
755 Get Value for given Name from a NameValue Storage.
757 @param Storage The NameValue Storage.
758 @param Name The Name.
759 @param Value The retured Value.
761 @retval EFI_SUCCESS Value found for given Name.
762 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
767 IN FORMSET_STORAGE
*Storage
,
769 IN OUT CHAR16
**Value
773 NAME_VALUE_NODE
*Node
;
777 Link
= GetFirstNode (&Storage
->NameValueListHead
);
778 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
779 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
781 if (StrCmp (Name
, Node
->Name
) == 0) {
782 NewStringCpy (Value
, Node
->EditValue
);
786 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
789 return EFI_NOT_FOUND
;
794 Set Value of given Name in a NameValue Storage.
796 @param Storage The NameValue Storage.
797 @param Name The Name.
798 @param Value The Value to set.
800 @retval EFI_SUCCESS Value found for given Name.
801 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
806 IN FORMSET_STORAGE
*Storage
,
812 NAME_VALUE_NODE
*Node
;
814 Link
= GetFirstNode (&Storage
->NameValueListHead
);
815 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
816 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
818 if (StrCmp (Name
, Node
->Name
) == 0) {
819 if (Node
->EditValue
!= NULL
) {
820 FreePool (Node
->EditValue
);
822 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
823 ASSERT (Node
->EditValue
!= NULL
);
827 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
830 return EFI_NOT_FOUND
;
835 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
837 @param Storage The Storage to be conveted.
838 @param ConfigResp The returned <ConfigResp>.
840 @retval EFI_SUCCESS Convert success.
841 @retval EFI_INVALID_PARAMETER Incorrect storage type.
845 StorageToConfigResp (
846 IN FORMSET_STORAGE
*Storage
,
847 IN CHAR16
**ConfigResp
853 NAME_VALUE_NODE
*Node
;
855 Status
= EFI_SUCCESS
;
857 switch (Storage
->Type
) {
858 case EFI_HII_VARSTORE_BUFFER
:
859 Status
= mHiiConfigRouting
->BlockToConfig (
861 Storage
->ConfigRequest
,
869 case EFI_HII_VARSTORE_NAME_VALUE
:
871 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
873 Link
= GetFirstNode (&Storage
->NameValueListHead
);
874 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
875 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
877 NewStringCat (ConfigResp
, L
"&");
878 NewStringCat (ConfigResp
, Node
->Name
);
879 NewStringCat (ConfigResp
, L
"=");
880 NewStringCat (ConfigResp
, Node
->EditValue
);
882 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
886 case EFI_HII_VARSTORE_EFI_VARIABLE
:
888 Status
= EFI_INVALID_PARAMETER
;
897 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
899 @param Storage The Storage to receive the settings.
900 @param ConfigResp The <ConfigResp> to be converted.
902 @retval EFI_SUCCESS Convert success.
903 @retval EFI_INVALID_PARAMETER Incorrect storage type.
907 ConfigRespToStorage (
908 IN FORMSET_STORAGE
*Storage
,
909 IN CHAR16
*ConfigResp
919 Status
= EFI_SUCCESS
;
921 switch (Storage
->Type
) {
922 case EFI_HII_VARSTORE_BUFFER
:
923 BufferSize
= Storage
->Size
;
924 Status
= mHiiConfigRouting
->ConfigToBlock (
933 case EFI_HII_VARSTORE_NAME_VALUE
:
934 StrPtr
= StrStr (ConfigResp
, L
"&");
935 while (StrPtr
!= NULL
) {
941 StrPtr
= StrStr (StrPtr
, L
"=");
942 if (StrPtr
== NULL
) {
952 StrPtr
= StrStr (StrPtr
, L
"&");
953 if (StrPtr
!= NULL
) {
956 SetValueByName (Storage
, Name
, Value
);
960 case EFI_HII_VARSTORE_EFI_VARIABLE
:
962 Status
= EFI_INVALID_PARAMETER
;
971 Get Question's current Value.
973 @param FormSet FormSet data structure.
974 @param Form Form data structure.
975 @param Question Question to be initialized.
976 @param Cached TRUE: get from Edit copy FALSE: get from original
979 @retval EFI_SUCCESS The function completed successfully.
984 IN FORM_BROWSER_FORMSET
*FormSet
,
985 IN FORM_BROWSER_FORM
*Form
,
986 IN OUT FORM_BROWSER_STATEMENT
*Question
,
996 FORMSET_STORAGE
*Storage
;
997 EFI_IFR_TYPE_VALUE
*QuestionValue
;
998 CHAR16
*ConfigRequest
;
1006 BOOLEAN IsBufferStorage
;
1011 Status
= EFI_SUCCESS
;
1014 // Statement don't have storage, skip them
1016 if (Question
->QuestionId
== 0) {
1021 // Question value is provided by an Expression, evaluate it
1023 if (Question
->ValueExpression
!= NULL
) {
1024 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1025 if (!EFI_ERROR (Status
)) {
1026 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1032 // Question value is provided by RTC
1034 Storage
= Question
->Storage
;
1035 QuestionValue
= &Question
->HiiValue
.Value
;
1036 if (Storage
== NULL
) {
1038 // It's a Question without storage, or RTC date/time
1040 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1042 // Date and time define the same Flags bit
1044 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1045 case QF_DATE_STORAGE_TIME
:
1046 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1049 case QF_DATE_STORAGE_WAKEUP
:
1050 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1053 case QF_DATE_STORAGE_NORMAL
:
1056 // For date/time without storage
1061 if (EFI_ERROR (Status
)) {
1065 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1066 QuestionValue
->date
.Year
= EfiTime
.Year
;
1067 QuestionValue
->date
.Month
= EfiTime
.Month
;
1068 QuestionValue
->date
.Day
= EfiTime
.Day
;
1070 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1071 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1072 QuestionValue
->time
.Second
= EfiTime
.Second
;
1080 // Question value is provided by EFI variable
1082 StorageWidth
= Question
->StorageWidth
;
1083 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1084 if (Question
->BufferValue
!= NULL
) {
1085 Dst
= Question
->BufferValue
;
1087 Dst
= (UINT8
*) QuestionValue
;
1090 Status
= gRT
->GetVariable (
1091 Question
->VariableName
,
1098 // Always return success, even this EFI variable doesn't exist
1104 // Question Value is provided by Buffer Storage or NameValue Storage
1106 if (Question
->BufferValue
!= NULL
) {
1108 // This Question is password or orderedlist
1110 Dst
= Question
->BufferValue
;
1113 // Other type of Questions
1115 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1118 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1119 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1121 if (IsBufferStorage
) {
1123 // Copy from storage Edit buffer
1125 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1127 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1128 if (EFI_ERROR (Status
)) {
1132 LengthStr
= StrLen (Value
);
1133 Status
= EFI_SUCCESS
;
1136 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1137 // Add string tail char L'\0' into Length
1139 Length
= StorageWidth
+ sizeof (CHAR16
);
1140 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1141 Status
= EFI_BUFFER_TOO_SMALL
;
1143 StringPtr
= (CHAR16
*) Dst
;
1144 ZeroMem (TemStr
, sizeof (TemStr
));
1145 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1146 StrnCpy (TemStr
, Value
+ Index
, 4);
1147 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1150 // Add tailing L'\0' character
1152 StringPtr
[Index
/4] = L
'\0';
1155 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1156 Status
= EFI_BUFFER_TOO_SMALL
;
1158 ZeroMem (TemStr
, sizeof (TemStr
));
1159 for (Index
= 0; Index
< LengthStr
; Index
++) {
1160 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1161 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1162 if ((Index
& 1) == 0) {
1163 Dst
[Index
/2] = DigitUint8
;
1165 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1175 // Request current settings from Configuration Driver
1177 if (FormSet
->ConfigAccess
== NULL
) {
1178 return EFI_NOT_FOUND
;
1182 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1183 // <ConfigHdr> + "&" + <VariableName>
1185 if (IsBufferStorage
) {
1186 Length
= StrLen (Storage
->ConfigHdr
);
1187 Length
+= StrLen (Question
->BlockName
);
1189 Length
= StrLen (Storage
->ConfigHdr
);
1190 Length
+= StrLen (Question
->VariableName
) + 1;
1192 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1193 ASSERT (ConfigRequest
!= NULL
);
1195 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1196 if (IsBufferStorage
) {
1197 StrCat (ConfigRequest
, Question
->BlockName
);
1199 StrCat (ConfigRequest
, L
"&");
1200 StrCat (ConfigRequest
, Question
->VariableName
);
1203 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1204 FormSet
->ConfigAccess
,
1209 if (EFI_ERROR (Status
)) {
1214 // Skip <ConfigRequest>
1216 Value
= Result
+ Length
;
1217 if (IsBufferStorage
) {
1223 if (*Value
!= '=') {
1225 return EFI_NOT_FOUND
;
1228 // Skip '=', point to value
1233 // Suppress <AltResp> if any
1236 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1241 LengthStr
= StrLen (Value
);
1242 Status
= EFI_SUCCESS
;
1243 if (!IsBufferStorage
&& IsString
) {
1245 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1246 // Add string tail char L'\0' into Length
1248 Length
= StorageWidth
+ sizeof (CHAR16
);
1249 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1250 Status
= EFI_BUFFER_TOO_SMALL
;
1252 StringPtr
= (CHAR16
*) Dst
;
1253 ZeroMem (TemStr
, sizeof (TemStr
));
1254 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1255 StrnCpy (TemStr
, Value
+ Index
, 4);
1256 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1259 // Add tailing L'\0' character
1261 StringPtr
[Index
/4] = L
'\0';
1264 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1265 Status
= EFI_BUFFER_TOO_SMALL
;
1267 ZeroMem (TemStr
, sizeof (TemStr
));
1268 for (Index
= 0; Index
< LengthStr
; Index
++) {
1269 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1270 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1271 if ((Index
& 1) == 0) {
1272 Dst
[Index
/2] = DigitUint8
;
1274 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1280 if (EFI_ERROR (Status
)) {
1286 // Synchronize Edit Buffer
1288 if (IsBufferStorage
) {
1289 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1291 SetValueByName (Storage
, Question
->VariableName
, Value
);
1302 Save Question Value to edit copy(cached) or Storage(uncached).
1304 @param FormSet FormSet data structure.
1305 @param Form Form data structure.
1306 @param Question Pointer to the Question.
1307 @param Cached TRUE: set to Edit copy FALSE: set to original
1310 @retval EFI_SUCCESS The function completed successfully.
1315 IN FORM_BROWSER_FORMSET
*FormSet
,
1316 IN FORM_BROWSER_FORM
*Form
,
1317 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1328 FORMSET_STORAGE
*Storage
;
1329 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1334 BOOLEAN IsBufferStorage
;
1341 Status
= EFI_SUCCESS
;
1344 // Statement don't have storage, skip them
1346 if (Question
->QuestionId
== 0) {
1351 // If Question value is provided by an Expression, then it is read only
1353 if (Question
->ValueExpression
!= NULL
) {
1358 // Question value is provided by RTC
1360 Storage
= Question
->Storage
;
1361 QuestionValue
= &Question
->HiiValue
.Value
;
1362 if (Storage
== NULL
) {
1364 // It's a Question without storage, or RTC date/time
1366 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1368 // Date and time define the same Flags bit
1370 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1371 case QF_DATE_STORAGE_TIME
:
1372 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1375 case QF_DATE_STORAGE_WAKEUP
:
1376 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1379 case QF_DATE_STORAGE_NORMAL
:
1382 // For date/time without storage
1387 if (EFI_ERROR (Status
)) {
1391 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1392 EfiTime
.Year
= QuestionValue
->date
.Year
;
1393 EfiTime
.Month
= QuestionValue
->date
.Month
;
1394 EfiTime
.Day
= QuestionValue
->date
.Day
;
1396 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1397 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1398 EfiTime
.Second
= QuestionValue
->time
.Second
;
1401 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1402 Status
= gRT
->SetTime (&EfiTime
);
1404 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1412 // Question value is provided by EFI variable
1414 StorageWidth
= Question
->StorageWidth
;
1415 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1416 if (Question
->BufferValue
!= NULL
) {
1417 Src
= Question
->BufferValue
;
1419 Src
= (UINT8
*) QuestionValue
;
1422 Status
= gRT
->SetVariable (
1423 Question
->VariableName
,
1425 Storage
->Attributes
,
1433 // Question Value is provided by Buffer Storage or NameValue Storage
1435 if (Question
->BufferValue
!= NULL
) {
1436 Src
= Question
->BufferValue
;
1438 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1441 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1442 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1443 if (IsBufferStorage
) {
1445 // Copy to storage edit buffer
1447 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1451 // Allocate enough string buffer.
1454 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1455 Value
= AllocateZeroPool (BufferLen
);
1456 ASSERT (Value
!= NULL
);
1458 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1460 TemName
= (CHAR16
*) Src
;
1462 for (; *TemName
!= L
'\0'; TemName
++) {
1463 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1466 BufferLen
= StorageWidth
* 2 + 1;
1467 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1468 ASSERT (Value
!= NULL
);
1470 // Convert Buffer to Hex String
1472 TemBuffer
= Src
+ StorageWidth
- 1;
1474 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1475 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1479 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1485 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1486 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1488 if (IsBufferStorage
) {
1489 Length
= StrLen (Question
->BlockName
) + 7;
1491 Length
= StrLen (Question
->VariableName
) + 2;
1493 if (!IsBufferStorage
&& IsString
) {
1494 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1496 Length
+= (StorageWidth
* 2);
1498 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1499 ASSERT (ConfigResp
!= NULL
);
1501 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1502 if (IsBufferStorage
) {
1503 StrCat (ConfigResp
, Question
->BlockName
);
1504 StrCat (ConfigResp
, L
"&VALUE=");
1506 StrCat (ConfigResp
, L
"&");
1507 StrCat (ConfigResp
, Question
->VariableName
);
1508 StrCat (ConfigResp
, L
"=");
1511 Value
= ConfigResp
+ StrLen (ConfigResp
);
1513 if (!IsBufferStorage
&& IsString
) {
1515 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1517 TemName
= (CHAR16
*) Src
;
1519 for (; *TemName
!= L
'\0'; TemName
++) {
1520 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1524 // Convert Buffer to Hex String
1526 TemBuffer
= Src
+ StorageWidth
- 1;
1528 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1529 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1534 // Convert to lower char.
1536 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
1537 if (*Value
>= L
'A' && *Value
<= L
'Z') {
1538 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
1543 // Submit Question Value to Configuration Driver
1545 if (FormSet
->ConfigAccess
!= NULL
) {
1546 Status
= FormSet
->ConfigAccess
->RouteConfig (
1547 FormSet
->ConfigAccess
,
1551 if (EFI_ERROR (Status
)) {
1552 FreePool (ConfigResp
);
1556 FreePool (ConfigResp
);
1559 // Synchronize shadow Buffer
1561 SynchronizeStorage (Storage
);
1569 Perform inconsistent check for a Form.
1571 @param FormSet FormSet data structure.
1572 @param Form Form data structure.
1573 @param Question The Question to be validated.
1574 @param Type Validation type: InConsistent or NoSubmit
1576 @retval EFI_SUCCESS Form validation pass.
1577 @retval other Form validation failed.
1582 IN FORM_BROWSER_FORMSET
*FormSet
,
1583 IN FORM_BROWSER_FORM
*Form
,
1584 IN FORM_BROWSER_STATEMENT
*Question
,
1590 LIST_ENTRY
*ListHead
;
1593 FORM_EXPRESSION
*Expression
;
1595 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1596 ListHead
= &Question
->InconsistentListHead
;
1597 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1598 ListHead
= &Question
->NoSubmitListHead
;
1600 return EFI_UNSUPPORTED
;
1603 Link
= GetFirstNode (ListHead
);
1604 while (!IsNull (ListHead
, Link
)) {
1605 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1608 // Evaluate the expression
1610 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1611 if (EFI_ERROR (Status
)) {
1615 if (Expression
->Result
.Value
.b
) {
1617 // Condition meet, show up error message
1619 if (Expression
->Error
!= 0) {
1620 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1622 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1623 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1627 return EFI_NOT_READY
;
1630 Link
= GetNextNode (ListHead
, Link
);
1638 Perform NoSubmit check for a Form.
1640 @param FormSet FormSet data structure.
1641 @param Form Form data structure.
1643 @retval EFI_SUCCESS Form validation pass.
1644 @retval other Form validation failed.
1649 IN FORM_BROWSER_FORMSET
*FormSet
,
1650 IN FORM_BROWSER_FORM
*Form
1655 FORM_BROWSER_STATEMENT
*Question
;
1657 Link
= GetFirstNode (&Form
->StatementListHead
);
1658 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1659 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1661 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1662 if (EFI_ERROR (Status
)) {
1666 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1676 @param FormSet FormSet data structure.
1677 @param Form Form data structure.
1679 @retval EFI_SUCCESS The function completed successfully.
1684 IN FORM_BROWSER_FORMSET
*FormSet
,
1685 IN FORM_BROWSER_FORM
*Form
1690 EFI_STRING ConfigResp
;
1691 EFI_STRING Progress
;
1692 FORMSET_STORAGE
*Storage
;
1695 // Validate the Form by NoSubmit check
1697 Status
= NoSubmitCheck (FormSet
, Form
);
1698 if (EFI_ERROR (Status
)) {
1703 // Submit Buffer storage or Name/Value storage
1705 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1706 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1707 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1708 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1710 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1715 // Skip if there is no RequestElement
1717 if (Storage
->ElementCount
== 0) {
1722 // Prepare <ConfigResp>
1724 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1725 if (EFI_ERROR (Status
)) {
1730 // Send <ConfigResp> to Configuration Driver
1732 if (FormSet
->ConfigAccess
!= NULL
) {
1733 Status
= FormSet
->ConfigAccess
->RouteConfig (
1734 FormSet
->ConfigAccess
,
1738 if (EFI_ERROR (Status
)) {
1739 FreePool (ConfigResp
);
1743 FreePool (ConfigResp
);
1746 // Config success, update storage shadow Buffer
1748 SynchronizeStorage (Storage
);
1751 gNvUpdateRequired
= FALSE
;
1758 Reset Question to its default value.
1760 @param FormSet The form set.
1761 @param Form The form.
1762 @param Question The question.
1763 @param DefaultId The Class of the default.
1765 @retval EFI_SUCCESS Question is reset to default value.
1769 GetQuestionDefault (
1770 IN FORM_BROWSER_FORMSET
*FormSet
,
1771 IN FORM_BROWSER_FORM
*Form
,
1772 IN FORM_BROWSER_STATEMENT
*Question
,
1778 QUESTION_DEFAULT
*Default
;
1779 QUESTION_OPTION
*Option
;
1780 EFI_HII_VALUE
*HiiValue
;
1782 EFI_STRING StrValue
;
1784 Status
= EFI_SUCCESS
;
1788 // Statement don't have storage, skip them
1790 if (Question
->QuestionId
== 0) {
1795 // There are three ways to specify default value for a Question:
1796 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1797 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1798 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1800 HiiValue
= &Question
->HiiValue
;
1803 // EFI_IFR_DEFAULT has highest priority
1805 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1806 Link
= GetFirstNode (&Question
->DefaultListHead
);
1807 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1808 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1810 if (Default
->DefaultId
== DefaultId
) {
1811 if (Default
->ValueExpression
!= NULL
) {
1813 // Default is provided by an Expression, evaluate it
1815 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1816 if (EFI_ERROR (Status
)) {
1820 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1823 // Default value is embedded in EFI_IFR_DEFAULT
1825 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1828 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
1829 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
1830 if (StrValue
== NULL
) {
1831 return EFI_NOT_FOUND
;
1833 Question
->BufferValue
= AllocateCopyPool (StrSize (StrValue
), StrValue
);
1839 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1844 // EFI_ONE_OF_OPTION
1846 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1847 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1849 // OneOfOption could only provide Standard and Manufacturing default
1851 Link
= GetFirstNode (&Question
->OptionListHead
);
1852 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1853 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1855 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1856 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1858 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1863 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1869 // EFI_IFR_CHECKBOX - lowest priority
1871 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1872 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1874 // Checkbox could only provide Standard and Manufacturing default
1876 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1877 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1879 HiiValue
->Value
.b
= TRUE
;
1881 HiiValue
->Value
.b
= FALSE
;
1889 // For Questions without default
1891 switch (Question
->Operand
) {
1892 case EFI_IFR_ONE_OF_OP
:
1894 // Take first oneof option as oneof's default value
1896 if (ValueToOption (Question
, HiiValue
) == NULL
) {
1897 Link
= GetFirstNode (&Question
->OptionListHead
);
1898 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1899 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1900 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1905 case EFI_IFR_ORDERED_LIST_OP
:
1907 // Take option sequence in IFR as ordered list's default value
1910 Link
= GetFirstNode (&Question
->OptionListHead
);
1911 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1912 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1914 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1917 if (Index
>= Question
->MaxContainers
) {
1921 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1926 Status
= EFI_NOT_FOUND
;
1935 Reset Questions in a Form to their default value.
1937 @param FormSet FormSet data structure.
1938 @param Form The Form which to be reset.
1939 @param DefaultId The Class of the default.
1941 @retval EFI_SUCCESS The function completed successfully.
1945 ExtractFormDefault (
1946 IN FORM_BROWSER_FORMSET
*FormSet
,
1947 IN FORM_BROWSER_FORM
*Form
,
1953 FORM_BROWSER_STATEMENT
*Question
;
1955 Link
= GetFirstNode (&Form
->StatementListHead
);
1956 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1957 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1958 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1961 // If Question is disabled, don't reset it to default
1963 if (Question
->DisableExpression
!= NULL
) {
1964 Status
= EvaluateExpression (FormSet
, Form
, Question
->DisableExpression
);
1965 if (!EFI_ERROR (Status
) && Question
->DisableExpression
->Result
.Value
.b
) {
1971 // Reset Question to its default value
1973 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1974 if (EFI_ERROR (Status
)) {
1979 // Synchronize Buffer storage's Edit buffer
1981 if ((Question
->Storage
!= NULL
) &&
1982 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1983 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1992 Initialize Question's Edit copy from Storage.
1994 @param FormSet FormSet data structure.
1995 @param Form Form data structure.
1997 @retval EFI_SUCCESS The function completed successfully.
2002 IN FORM_BROWSER_FORMSET
*FormSet
,
2003 IN FORM_BROWSER_FORM
*Form
2008 FORM_BROWSER_STATEMENT
*Question
;
2010 Link
= GetFirstNode (&Form
->StatementListHead
);
2011 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2012 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2015 // Initialize local copy of Value for each Question
2017 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
2018 if (EFI_ERROR (Status
)) {
2022 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2030 Fill storage's edit copy with settings requested from Configuration Driver.
2032 @param FormSet FormSet data structure.
2033 @param Storage Buffer Storage.
2035 @retval EFI_SUCCESS The function completed successfully.
2040 IN FORM_BROWSER_FORMSET
*FormSet
,
2041 IN FORMSET_STORAGE
*Storage
2045 EFI_STRING Progress
;
2049 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2053 if (FormSet
->ConfigAccess
== NULL
) {
2054 return EFI_NOT_FOUND
;
2057 if (Storage
->ElementCount
== 0) {
2059 // Skip if there is no RequestElement
2065 // Request current settings from Configuration Driver
2067 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2068 FormSet
->ConfigAccess
,
2069 Storage
->ConfigRequest
,
2073 if (EFI_ERROR (Status
)) {
2078 // Convert Result from <ConfigAltResp> to <ConfigResp>
2080 StrPtr
= StrStr (Result
, L
"ALTCFG");
2081 if (StrPtr
!= NULL
) {
2085 Status
= ConfigRespToStorage (Storage
, Result
);
2092 Get current setting of Questions.
2094 @param FormSet FormSet data structure.
2096 @retval EFI_SUCCESS The function completed successfully.
2100 InitializeCurrentSetting (
2101 IN OUT FORM_BROWSER_FORMSET
*FormSet
2105 FORMSET_STORAGE
*Storage
;
2106 FORM_BROWSER_FORM
*Form
;
2110 // Extract default from IFR binary
2112 Link
= GetFirstNode (&FormSet
->FormListHead
);
2113 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2114 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2116 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2118 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2122 // Request current settings from Configuration Driver
2124 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2125 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2126 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2128 Status
= LoadStorage (FormSet
, Storage
);
2131 // Now Edit Buffer is filled with default values(lower priority) and current
2132 // settings(higher priority), sychronize it to shadow Buffer
2134 if (!EFI_ERROR (Status
)) {
2135 SynchronizeStorage (Storage
);
2138 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2146 Fetch the Ifr binary data of a FormSet.
2148 @param Handle PackageList Handle
2149 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2150 GUID), take the first FormSet found in package
2152 @param BinaryLength The length of the FormSet IFR binary.
2153 @param BinaryData The buffer designed to receive the FormSet.
2155 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2156 BufferLength was updated.
2157 @retval EFI_INVALID_PARAMETER The handle is unknown.
2158 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2159 be found with the requested FormId.
2164 IN EFI_HII_HANDLE Handle
,
2165 IN OUT EFI_GUID
*FormSetGuid
,
2166 OUT UINTN
*BinaryLength
,
2167 OUT UINT8
**BinaryData
2171 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2177 BOOLEAN ReturnDefault
;
2178 UINT32 PackageListLength
;
2179 EFI_HII_PACKAGE_HEADER PackageHeader
;
2181 UINT8 NumberOfClassGuid
;
2182 BOOLEAN IsSetupClassGuid
;
2183 EFI_GUID
*ClassGuid
;
2187 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2190 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2192 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2193 ReturnDefault
= TRUE
;
2195 ReturnDefault
= FALSE
;
2199 // Get HII PackageList
2202 HiiPackageList
= NULL
;
2203 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2204 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2205 HiiPackageList
= AllocatePool (BufferSize
);
2206 ASSERT (HiiPackageList
!= NULL
);
2208 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2210 if (EFI_ERROR (Status
)) {
2213 ASSERT (HiiPackageList
!= NULL
);
2216 // Get Form package from this HII package List
2218 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2220 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2222 while (Offset
< PackageListLength
) {
2223 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2224 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2226 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2228 // Search FormSet in this Form Package
2230 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2231 while (Offset2
< PackageHeader
.Length
) {
2232 OpCodeData
= Package
+ Offset2
;
2234 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2236 // Check whether return default FormSet
2238 if (ReturnDefault
) {
2240 // Check ClassGuid of formset OpCode
2242 IsSetupClassGuid
= FALSE
;
2243 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
2244 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
2245 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
2246 if (CompareGuid (ClassGuid
+ Index
, &gEfiHiiPlatformSetupFormsetGuid
)) {
2247 IsSetupClassGuid
= TRUE
;
2251 if (IsSetupClassGuid
) {
2257 // FormSet GUID is specified, check it
2259 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2264 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2267 if (Offset2
< PackageHeader
.Length
) {
2269 // Target formset found
2275 Offset
+= PackageHeader
.Length
;
2278 if (Offset
>= PackageListLength
) {
2280 // Form package not found in this Package List
2282 FreePool (HiiPackageList
);
2283 return EFI_NOT_FOUND
;
2286 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2288 // Return the default FormSet GUID
2290 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2294 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2295 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2296 // of the Form Package.
2298 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2299 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2301 FreePool (HiiPackageList
);
2303 if (*BinaryData
== NULL
) {
2304 return EFI_OUT_OF_RESOURCES
;
2312 Initialize the internal data structure of a FormSet.
2314 @param Handle PackageList Handle
2315 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2316 GUID), take the first FormSet found in package
2318 @param FormSet FormSet data structure.
2320 @retval EFI_SUCCESS The function completed successfully.
2321 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2326 IN EFI_HII_HANDLE Handle
,
2327 IN OUT EFI_GUID
*FormSetGuid
,
2328 OUT FORM_BROWSER_FORMSET
*FormSet
2332 EFI_HANDLE DriverHandle
;
2335 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2336 if (EFI_ERROR (Status
)) {
2340 FormSet
->HiiHandle
= Handle
;
2341 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2344 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2346 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2347 if (EFI_ERROR (Status
)) {
2350 FormSet
->DriverHandle
= DriverHandle
;
2351 Status
= gBS
->HandleProtocol (
2353 &gEfiHiiConfigAccessProtocolGuid
,
2354 (VOID
**) &FormSet
->ConfigAccess
2356 if (EFI_ERROR (Status
)) {
2358 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2359 // list, then there will be no configuration action required
2361 FormSet
->ConfigAccess
= NULL
;
2365 // Parse the IFR binary OpCodes
2367 Status
= ParseOpCodes (FormSet
);
2368 if (EFI_ERROR (Status
)) {
2372 gClassOfVfr
= FORMSET_CLASS_PLATFORM_SETUP
;
2373 if (FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
) {
2374 gClassOfVfr
= FORMSET_CLASS_FRONT_PAGE
;
2375 gFrontPageHandle
= FormSet
->HiiHandle
;
2379 // Match GUID to find out the function key setting. If match fail, use the default setting.
2381 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2382 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2384 // Update the function key setting.
2386 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2388 // Function key prompt can not be displayed if the function key has been disabled.
2390 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2391 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2394 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2395 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2398 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2399 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2402 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2403 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);