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
*gFunctionOneString
;
48 CHAR16
*gFunctionNineString
;
49 CHAR16
*gFunctionTenString
;
51 CHAR16
*gEnterCommitString
;
52 CHAR16
*gEnterEscapeString
;
53 CHAR16
*gEscapeString
;
55 CHAR16
*gMoveHighlight
;
56 CHAR16
*gMakeSelection
;
57 CHAR16
*gDecNumericInput
;
58 CHAR16
*gHexNumericInput
;
59 CHAR16
*gToggleCheckBox
;
60 CHAR16
*gPromptForData
;
61 CHAR16
*gPromptForPassword
;
62 CHAR16
*gPromptForNewPassword
;
63 CHAR16
*gConfirmPassword
;
64 CHAR16
*gConfirmError
;
65 CHAR16
*gPassowordInvalid
;
74 CHAR16
*gAdjustNumber
;
76 CHAR16
*gOptionMismatch
;
78 CHAR16
*mUnknownString
= L
"!";
80 CHAR16 gPromptBlockWidth
;
81 CHAR16 gOptionBlockWidth
;
82 CHAR16 gHelpBlockWidth
;
84 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
85 EFI_GUID gSetupBrowserGuid
= {
86 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
89 FORM_BROWSER_FORMSET
*gOldFormSet
= NULL
;
91 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
111 NONE_FUNCTION_KEY_SETTING
132 NONE_FUNCTION_KEY_SETTING
153 NONE_FUNCTION_KEY_SETTING
156 // BMM File Explorer FormSet.
174 NONE_FUNCTION_KEY_SETTING
179 This is the routine which an external caller uses to direct the browser
180 where to obtain it's information.
183 @param This The Form Browser protocol instanse.
184 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
185 display a list of the formsets for the handles specified.
186 @param HandleCount The number of Handles specified in Handle.
187 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
188 field in the EFI_IFR_FORM_SET op-code for the specified
189 forms-based package. If FormSetGuid is NULL, then this
190 function will display the first found forms package.
191 @param FormId This field specifies which EFI_IFR_FORM to render as the first
192 displayable page. If this field has a value of 0x0000, then
193 the forms browser will render the specified forms in their encoded order.
194 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
196 @param ActionRequest Points to the action recommended by the form.
198 @retval EFI_SUCCESS The function completed successfully.
199 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
200 @retval EFI_NOT_FOUND No valid forms could be found to display.
206 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
207 IN EFI_HII_HANDLE
*Handles
,
208 IN UINTN HandleCount
,
209 IN EFI_GUID
*FormSetGuid
, OPTIONAL
210 IN UINT16 FormId
, OPTIONAL
211 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
212 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
216 UI_MENU_SELECTION
*Selection
;
218 FORM_BROWSER_FORMSET
*FormSet
;
220 Status
= EFI_SUCCESS
;
221 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
224 // Seed the dimensions in the global
226 gST
->ConOut
->QueryMode (
228 gST
->ConOut
->Mode
->Mode
,
229 &gScreenDimensions
.RightColumn
,
230 &gScreenDimensions
.BottomRow
233 if (ScreenDimensions
!= NULL
) {
235 // Check local dimension vs. global dimension.
237 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
238 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
240 return EFI_INVALID_PARAMETER
;
243 // Local dimension validation.
245 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
246 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
247 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
249 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
250 SCROLL_ARROW_HEIGHT
*
252 FRONT_PAGE_HEADER_HEIGHT
+
257 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
259 return EFI_INVALID_PARAMETER
;
264 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
265 gHelpBlockWidth
= gOptionBlockWidth
;
266 gPromptBlockWidth
= gOptionBlockWidth
;
269 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
271 InitializeBrowserStrings ();
273 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
274 gClassOfVfr
= FORMSET_CLASS_PLATFORM_SETUP
;
277 // Ensure we are in Text mode
279 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
281 for (Index
= 0; Index
< HandleCount
; Index
++) {
282 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
283 ASSERT (Selection
!= NULL
);
285 Selection
->Handle
= Handles
[Index
];
286 if (FormSetGuid
!= NULL
) {
287 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
288 Selection
->FormId
= FormId
;
291 gNvUpdateRequired
= FALSE
;
294 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
295 ASSERT (FormSet
!= NULL
);
298 // Initialize internal data structures of FormSet
300 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
301 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
302 DestroyFormSet (FormSet
);
305 Selection
->FormSet
= FormSet
;
308 // Display this formset
310 gCurrentSelection
= Selection
;
312 Status
= SetupBrowser (Selection
);
314 gCurrentSelection
= NULL
;
316 if (EFI_ERROR (Status
)) {
320 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
322 if (gOldFormSet
!= NULL
) {
323 DestroyFormSet (gOldFormSet
);
327 FreePool (Selection
);
330 if (ActionRequest
!= NULL
) {
331 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
332 if (gResetRequired
) {
333 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
337 FreeBrowserStrings ();
339 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
340 gST
->ConOut
->ClearScreen (gST
->ConOut
);
347 This function is called by a callback handler to retrieve uncommitted state
348 data from the browser.
350 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
352 @param ResultsDataSize A pointer to the size of the buffer associated
354 @param ResultsData A string returned from an IFR browser or
355 equivalent. The results string will have no
356 routing information in them.
357 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
358 (if RetrieveData = TRUE) data from the uncommitted
359 browser state information or set (if RetrieveData
360 = FALSE) data in the uncommitted browser state
362 @param VariableGuid An optional field to indicate the target variable
364 @param VariableName An optional field to indicate the target
365 human-readable variable name.
367 @retval EFI_SUCCESS The results have been distributed or are awaiting
369 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
370 contain the results data.
376 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
377 IN OUT UINTN
*ResultsDataSize
,
378 IN OUT EFI_STRING ResultsData
,
379 IN BOOLEAN RetrieveData
,
380 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
381 IN CONST CHAR16
*VariableName OPTIONAL
386 FORMSET_STORAGE
*Storage
;
387 FORM_BROWSER_FORMSET
*FormSet
;
394 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
395 return EFI_INVALID_PARAMETER
;
398 if (gCurrentSelection
== NULL
) {
399 return EFI_NOT_READY
;
404 FormSet
= gCurrentSelection
->FormSet
;
407 // Find target storage
409 Link
= GetFirstNode (&FormSet
->StorageListHead
);
410 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
411 return EFI_UNSUPPORTED
;
414 if (VariableGuid
!= NULL
) {
416 // Try to find target storage
419 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
420 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
421 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
423 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
424 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
426 // Buffer storage require both GUID and Name
428 if (VariableName
== NULL
) {
429 return EFI_NOT_FOUND
;
432 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
442 return EFI_NOT_FOUND
;
446 // GUID/Name is not specified, take the first storage in FormSet
448 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
453 // Skip if there is no RequestElement
455 if (Storage
->ElementCount
== 0) {
460 // Generate <ConfigResp>
462 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
463 if (EFI_ERROR (Status
)) {
468 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
470 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
472 BufferSize
= StrSize (StrPtr
);
473 if (*ResultsDataSize
< BufferSize
) {
474 *ResultsDataSize
= BufferSize
;
476 FreePool (ConfigResp
);
477 return EFI_BUFFER_TOO_SMALL
;
480 *ResultsDataSize
= BufferSize
;
481 CopyMem (ResultsData
, StrPtr
, BufferSize
);
483 FreePool (ConfigResp
);
486 // Prepare <ConfigResp>
488 TmpSize
= StrLen (ResultsData
);
489 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
490 ConfigResp
= AllocateZeroPool (BufferSize
);
491 ASSERT (ConfigResp
!= NULL
);
493 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
494 StrCat (ConfigResp
, L
"&");
495 StrCat (ConfigResp
, ResultsData
);
498 // Update Browser uncommited data
500 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
501 if (EFI_ERROR (Status
)) {
511 Initialize Setup Browser driver.
513 @param ImageHandle The image handle.
514 @param SystemTable The system table.
516 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
517 @return Other value if failed to initialize the Setup Browser module.
523 IN EFI_HANDLE ImageHandle
,
524 IN EFI_SYSTEM_TABLE
*SystemTable
530 // Locate required Hii relative protocols
532 Status
= gBS
->LocateProtocol (
533 &gEfiHiiDatabaseProtocolGuid
,
535 (VOID
**) &mHiiDatabase
537 ASSERT_EFI_ERROR (Status
);
539 Status
= gBS
->LocateProtocol (
540 &gEfiHiiStringProtocolGuid
,
542 (VOID
**) &mHiiString
544 ASSERT_EFI_ERROR (Status
);
546 Status
= gBS
->LocateProtocol (
547 &gEfiHiiConfigRoutingProtocolGuid
,
549 (VOID
**) &mHiiConfigRouting
551 ASSERT_EFI_ERROR (Status
);
554 // Publish our HII data
556 gHiiHandle
= HiiAddPackages (
562 ASSERT (gHiiHandle
!= NULL
);
565 // Initialize Driver private data
567 gBannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
568 ASSERT (gBannerData
!= NULL
);
571 // Install FormBrowser2 protocol
573 mPrivateData
.Handle
= NULL
;
574 Status
= gBS
->InstallProtocolInterface (
575 &mPrivateData
.Handle
,
576 &gEfiFormBrowser2ProtocolGuid
,
577 EFI_NATIVE_INTERFACE
,
578 &mPrivateData
.FormBrowser2
580 ASSERT_EFI_ERROR (Status
);
587 Create a new string in HII Package List.
589 @param String The String to be added
590 @param HiiHandle The package list in the HII database to insert the
593 @return The output string.
599 IN EFI_HII_HANDLE HiiHandle
602 EFI_STRING_ID StringId
;
604 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
605 ASSERT (StringId
!= 0);
612 Delete a string from HII Package List.
614 @param StringId Id of the string in HII database.
615 @param HiiHandle The HII package list handle.
617 @retval EFI_SUCCESS The string was deleted successfully.
622 IN EFI_STRING_ID StringId
,
623 IN EFI_HII_HANDLE HiiHandle
628 NullChar
= CHAR_NULL
;
629 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
635 Get the string based on the StringId and HII Package List Handle.
637 @param Token The String's ID.
638 @param HiiHandle The package list in the HII database to search for
639 the specified string.
641 @return The output string.
646 IN EFI_STRING_ID Token
,
647 IN EFI_HII_HANDLE HiiHandle
652 String
= HiiGetString (HiiHandle
, Token
, NULL
);
653 if (String
== NULL
) {
654 String
= AllocateCopyPool (sizeof (mUnknownString
), mUnknownString
);
655 ASSERT (String
!= NULL
);
657 return (CHAR16
*) String
;
662 Allocate new memory and then copy the Unicode string Source to Destination.
664 @param Dest Location to copy string
665 @param Src String to copy
670 IN OUT CHAR16
**Dest
,
677 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
678 ASSERT (*Dest
!= NULL
);
683 Allocate new memory and concatinate Source on the end of Destination.
685 @param Dest String to added to the end of.
686 @param Src String to concatinate.
691 IN OUT CHAR16
**Dest
,
699 NewStringCpy (Dest
, Src
);
703 TmpSize
= StrSize (*Dest
);
704 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
705 ASSERT (NewString
!= NULL
);
707 StrCpy (NewString
, *Dest
);
708 StrCat (NewString
, Src
);
716 Synchronize Storage's Edit copy to Shadow copy.
718 @param Storage The Storage to be synchronized.
723 IN FORMSET_STORAGE
*Storage
727 NAME_VALUE_NODE
*Node
;
729 switch (Storage
->Type
) {
730 case EFI_HII_VARSTORE_BUFFER
:
731 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
734 case EFI_HII_VARSTORE_NAME_VALUE
:
735 Link
= GetFirstNode (&Storage
->NameValueListHead
);
736 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
737 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
739 NewStringCpy (&Node
->Value
, Node
->EditValue
);
741 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
745 case EFI_HII_VARSTORE_EFI_VARIABLE
:
753 Get Value for given Name from a NameValue Storage.
755 @param Storage The NameValue Storage.
756 @param Name The Name.
757 @param Value The retured Value.
759 @retval EFI_SUCCESS Value found for given Name.
760 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
765 IN FORMSET_STORAGE
*Storage
,
767 IN OUT CHAR16
**Value
771 NAME_VALUE_NODE
*Node
;
775 Link
= GetFirstNode (&Storage
->NameValueListHead
);
776 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
777 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
779 if (StrCmp (Name
, Node
->Name
) == 0) {
780 NewStringCpy (Value
, Node
->EditValue
);
784 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
787 return EFI_NOT_FOUND
;
792 Set Value of given Name in a NameValue Storage.
794 @param Storage The NameValue Storage.
795 @param Name The Name.
796 @param Value The Value to set.
798 @retval EFI_SUCCESS Value found for given Name.
799 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
804 IN FORMSET_STORAGE
*Storage
,
810 NAME_VALUE_NODE
*Node
;
812 Link
= GetFirstNode (&Storage
->NameValueListHead
);
813 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
814 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
816 if (StrCmp (Name
, Node
->Name
) == 0) {
817 if (Node
->EditValue
!= NULL
) {
818 FreePool (Node
->EditValue
);
820 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
821 ASSERT (Node
->EditValue
!= NULL
);
825 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
828 return EFI_NOT_FOUND
;
833 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
835 @param Storage The Storage to be conveted.
836 @param ConfigResp The returned <ConfigResp>.
838 @retval EFI_SUCCESS Convert success.
839 @retval EFI_INVALID_PARAMETER Incorrect storage type.
843 StorageToConfigResp (
844 IN FORMSET_STORAGE
*Storage
,
845 IN CHAR16
**ConfigResp
851 NAME_VALUE_NODE
*Node
;
853 Status
= EFI_SUCCESS
;
855 switch (Storage
->Type
) {
856 case EFI_HII_VARSTORE_BUFFER
:
857 Status
= mHiiConfigRouting
->BlockToConfig (
859 Storage
->ConfigRequest
,
867 case EFI_HII_VARSTORE_NAME_VALUE
:
869 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
871 Link
= GetFirstNode (&Storage
->NameValueListHead
);
872 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
873 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
875 NewStringCat (ConfigResp
, L
"&");
876 NewStringCat (ConfigResp
, Node
->Name
);
877 NewStringCat (ConfigResp
, L
"=");
878 NewStringCat (ConfigResp
, Node
->EditValue
);
880 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
884 case EFI_HII_VARSTORE_EFI_VARIABLE
:
886 Status
= EFI_INVALID_PARAMETER
;
895 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
897 @param Storage The Storage to receive the settings.
898 @param ConfigResp The <ConfigResp> to be converted.
900 @retval EFI_SUCCESS Convert success.
901 @retval EFI_INVALID_PARAMETER Incorrect storage type.
905 ConfigRespToStorage (
906 IN FORMSET_STORAGE
*Storage
,
907 IN CHAR16
*ConfigResp
917 Status
= EFI_SUCCESS
;
919 switch (Storage
->Type
) {
920 case EFI_HII_VARSTORE_BUFFER
:
921 BufferSize
= Storage
->Size
;
922 Status
= mHiiConfigRouting
->ConfigToBlock (
931 case EFI_HII_VARSTORE_NAME_VALUE
:
932 StrPtr
= StrStr (ConfigResp
, L
"&");
933 while (StrPtr
!= NULL
) {
939 StrPtr
= StrStr (StrPtr
, L
"=");
940 if (StrPtr
== NULL
) {
950 StrPtr
= StrStr (StrPtr
, L
"&");
951 if (StrPtr
!= NULL
) {
954 SetValueByName (Storage
, Name
, Value
);
958 case EFI_HII_VARSTORE_EFI_VARIABLE
:
960 Status
= EFI_INVALID_PARAMETER
;
969 Get Question's current Value.
971 @param FormSet FormSet data structure.
972 @param Form Form data structure.
973 @param Question Question to be initialized.
974 @param Cached TRUE: get from Edit copy FALSE: get from original
977 @retval EFI_SUCCESS The function completed successfully.
982 IN FORM_BROWSER_FORMSET
*FormSet
,
983 IN FORM_BROWSER_FORM
*Form
,
984 IN OUT FORM_BROWSER_STATEMENT
*Question
,
994 FORMSET_STORAGE
*Storage
;
995 EFI_IFR_TYPE_VALUE
*QuestionValue
;
996 CHAR16
*ConfigRequest
;
1004 BOOLEAN IsBufferStorage
;
1009 Status
= EFI_SUCCESS
;
1012 // Statement don't have storage, skip them
1014 if (Question
->QuestionId
== 0) {
1019 // Question value is provided by an Expression, evaluate it
1021 if (Question
->ValueExpression
!= NULL
) {
1022 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1023 if (!EFI_ERROR (Status
)) {
1024 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1030 // Question value is provided by RTC
1032 Storage
= Question
->Storage
;
1033 QuestionValue
= &Question
->HiiValue
.Value
;
1034 if (Storage
== NULL
) {
1036 // It's a Question without storage, or RTC date/time
1038 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1040 // Date and time define the same Flags bit
1042 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1043 case QF_DATE_STORAGE_TIME
:
1044 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1047 case QF_DATE_STORAGE_WAKEUP
:
1048 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1051 case QF_DATE_STORAGE_NORMAL
:
1054 // For date/time without storage
1059 if (EFI_ERROR (Status
)) {
1063 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1064 QuestionValue
->date
.Year
= EfiTime
.Year
;
1065 QuestionValue
->date
.Month
= EfiTime
.Month
;
1066 QuestionValue
->date
.Day
= EfiTime
.Day
;
1068 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1069 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1070 QuestionValue
->time
.Second
= EfiTime
.Second
;
1078 // Question value is provided by EFI variable
1080 StorageWidth
= Question
->StorageWidth
;
1081 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1082 if (Question
->BufferValue
!= NULL
) {
1083 Dst
= Question
->BufferValue
;
1085 Dst
= (UINT8
*) QuestionValue
;
1088 Status
= gRT
->GetVariable (
1089 Question
->VariableName
,
1096 // Always return success, even this EFI variable doesn't exist
1102 // Question Value is provided by Buffer Storage or NameValue Storage
1104 if (Question
->BufferValue
!= NULL
) {
1106 // This Question is password or orderedlist
1108 Dst
= Question
->BufferValue
;
1111 // Other type of Questions
1113 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1116 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1117 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1119 if (IsBufferStorage
) {
1121 // Copy from storage Edit buffer
1123 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1125 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1126 if (EFI_ERROR (Status
)) {
1130 LengthStr
= StrLen (Value
);
1131 Status
= EFI_SUCCESS
;
1134 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1135 // Add string tail char L'\0' into Length
1137 Length
= StorageWidth
+ sizeof (CHAR16
);
1138 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1139 Status
= EFI_BUFFER_TOO_SMALL
;
1141 StringPtr
= (CHAR16
*) Dst
;
1142 ZeroMem (TemStr
, sizeof (TemStr
));
1143 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1144 StrnCpy (TemStr
, Value
+ Index
, 4);
1145 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1148 // Add tailing L'\0' character
1150 StringPtr
[Index
/4] = L
'\0';
1153 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1154 Status
= EFI_BUFFER_TOO_SMALL
;
1156 ZeroMem (TemStr
, sizeof (TemStr
));
1157 for (Index
= 0; Index
< LengthStr
; Index
++) {
1158 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1159 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1160 if ((Index
& 1) == 0) {
1161 Dst
[Index
/2] = DigitUint8
;
1163 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1173 // Request current settings from Configuration Driver
1175 if (FormSet
->ConfigAccess
== NULL
) {
1176 return EFI_NOT_FOUND
;
1180 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1181 // <ConfigHdr> + "&" + <VariableName>
1183 if (IsBufferStorage
) {
1184 Length
= StrLen (Storage
->ConfigHdr
);
1185 Length
+= StrLen (Question
->BlockName
);
1187 Length
= StrLen (Storage
->ConfigHdr
);
1188 Length
+= StrLen (Question
->VariableName
) + 1;
1190 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1191 ASSERT (ConfigRequest
!= NULL
);
1193 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1194 if (IsBufferStorage
) {
1195 StrCat (ConfigRequest
, Question
->BlockName
);
1197 StrCat (ConfigRequest
, L
"&");
1198 StrCat (ConfigRequest
, Question
->VariableName
);
1201 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1202 FormSet
->ConfigAccess
,
1207 if (EFI_ERROR (Status
)) {
1212 // Skip <ConfigRequest>
1214 Value
= Result
+ Length
;
1215 if (IsBufferStorage
) {
1221 if (*Value
!= '=') {
1223 return EFI_NOT_FOUND
;
1226 // Skip '=', point to value
1231 // Suppress <AltResp> if any
1234 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1239 LengthStr
= StrLen (Value
);
1240 Status
= EFI_SUCCESS
;
1241 if (!IsBufferStorage
&& IsString
) {
1243 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1244 // Add string tail char L'\0' into Length
1246 Length
= StorageWidth
+ sizeof (CHAR16
);
1247 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1248 Status
= EFI_BUFFER_TOO_SMALL
;
1250 StringPtr
= (CHAR16
*) Dst
;
1251 ZeroMem (TemStr
, sizeof (TemStr
));
1252 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1253 StrnCpy (TemStr
, Value
+ Index
, 4);
1254 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1257 // Add tailing L'\0' character
1259 StringPtr
[Index
/4] = L
'\0';
1262 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1263 Status
= EFI_BUFFER_TOO_SMALL
;
1265 ZeroMem (TemStr
, sizeof (TemStr
));
1266 for (Index
= 0; Index
< LengthStr
; Index
++) {
1267 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1268 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1269 if ((Index
& 1) == 0) {
1270 Dst
[Index
/2] = DigitUint8
;
1272 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1278 if (EFI_ERROR (Status
)) {
1284 // Synchronize Edit Buffer
1286 if (IsBufferStorage
) {
1287 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1289 SetValueByName (Storage
, Question
->VariableName
, Value
);
1300 Save Question Value to edit copy(cached) or Storage(uncached).
1302 @param FormSet FormSet data structure.
1303 @param Form Form data structure.
1304 @param Question Pointer to the Question.
1305 @param Cached TRUE: set to Edit copy FALSE: set to original
1308 @retval EFI_SUCCESS The function completed successfully.
1313 IN FORM_BROWSER_FORMSET
*FormSet
,
1314 IN FORM_BROWSER_FORM
*Form
,
1315 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1326 FORMSET_STORAGE
*Storage
;
1327 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1332 BOOLEAN IsBufferStorage
;
1339 Status
= EFI_SUCCESS
;
1342 // Statement don't have storage, skip them
1344 if (Question
->QuestionId
== 0) {
1349 // If Question value is provided by an Expression, then it is read only
1351 if (Question
->ValueExpression
!= NULL
) {
1356 // Question value is provided by RTC
1358 Storage
= Question
->Storage
;
1359 QuestionValue
= &Question
->HiiValue
.Value
;
1360 if (Storage
== NULL
) {
1362 // It's a Question without storage, or RTC date/time
1364 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1366 // Date and time define the same Flags bit
1368 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1369 case QF_DATE_STORAGE_TIME
:
1370 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1373 case QF_DATE_STORAGE_WAKEUP
:
1374 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1377 case QF_DATE_STORAGE_NORMAL
:
1380 // For date/time without storage
1385 if (EFI_ERROR (Status
)) {
1389 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1390 EfiTime
.Year
= QuestionValue
->date
.Year
;
1391 EfiTime
.Month
= QuestionValue
->date
.Month
;
1392 EfiTime
.Day
= QuestionValue
->date
.Day
;
1394 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1395 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1396 EfiTime
.Second
= QuestionValue
->time
.Second
;
1399 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1400 Status
= gRT
->SetTime (&EfiTime
);
1402 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1410 // Question value is provided by EFI variable
1412 StorageWidth
= Question
->StorageWidth
;
1413 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1414 if (Question
->BufferValue
!= NULL
) {
1415 Src
= Question
->BufferValue
;
1417 Src
= (UINT8
*) QuestionValue
;
1420 Status
= gRT
->SetVariable (
1421 Question
->VariableName
,
1423 Storage
->Attributes
,
1431 // Question Value is provided by Buffer Storage or NameValue Storage
1433 if (Question
->BufferValue
!= NULL
) {
1434 Src
= Question
->BufferValue
;
1436 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1439 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1440 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1441 if (IsBufferStorage
) {
1443 // Copy to storage edit buffer
1445 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1449 // Allocate enough string buffer.
1452 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1453 Value
= AllocateZeroPool (BufferLen
);
1454 ASSERT (Value
!= NULL
);
1456 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1458 TemName
= (CHAR16
*) Src
;
1460 for (; *TemName
!= L
'\0'; TemName
++) {
1461 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1464 BufferLen
= StorageWidth
* 2 + 1;
1465 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1466 ASSERT (Value
!= NULL
);
1468 // Convert Buffer to Hex String
1470 TemBuffer
= Src
+ StorageWidth
- 1;
1472 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1473 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1477 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1483 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1484 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1486 if (IsBufferStorage
) {
1487 Length
= StrLen (Question
->BlockName
) + 7;
1489 Length
= StrLen (Question
->VariableName
) + 2;
1491 if (!IsBufferStorage
&& IsString
) {
1492 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1494 Length
+= (StorageWidth
* 2);
1496 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1497 ASSERT (ConfigResp
!= NULL
);
1499 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1500 if (IsBufferStorage
) {
1501 StrCat (ConfigResp
, Question
->BlockName
);
1502 StrCat (ConfigResp
, L
"&VALUE=");
1504 StrCat (ConfigResp
, L
"&");
1505 StrCat (ConfigResp
, Question
->VariableName
);
1506 StrCat (ConfigResp
, L
"=");
1509 Value
= ConfigResp
+ StrLen (ConfigResp
);
1511 if (!IsBufferStorage
&& IsString
) {
1513 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1515 TemName
= (CHAR16
*) Src
;
1517 for (; *TemName
!= L
'\0'; TemName
++) {
1518 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1522 // Convert Buffer to Hex String
1524 TemBuffer
= Src
+ StorageWidth
- 1;
1526 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1527 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1532 // Convert to lower char.
1534 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
1535 if (*Value
>= L
'A' && *Value
<= L
'Z') {
1536 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
1541 // Submit Question Value to Configuration Driver
1543 if (FormSet
->ConfigAccess
!= NULL
) {
1544 Status
= FormSet
->ConfigAccess
->RouteConfig (
1545 FormSet
->ConfigAccess
,
1549 if (EFI_ERROR (Status
)) {
1550 FreePool (ConfigResp
);
1554 FreePool (ConfigResp
);
1557 // Synchronize shadow Buffer
1559 SynchronizeStorage (Storage
);
1567 Perform inconsistent check for a Form.
1569 @param FormSet FormSet data structure.
1570 @param Form Form data structure.
1571 @param Question The Question to be validated.
1572 @param Type Validation type: InConsistent or NoSubmit
1574 @retval EFI_SUCCESS Form validation pass.
1575 @retval other Form validation failed.
1580 IN FORM_BROWSER_FORMSET
*FormSet
,
1581 IN FORM_BROWSER_FORM
*Form
,
1582 IN FORM_BROWSER_STATEMENT
*Question
,
1588 LIST_ENTRY
*ListHead
;
1591 FORM_EXPRESSION
*Expression
;
1593 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1594 ListHead
= &Question
->InconsistentListHead
;
1595 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1596 ListHead
= &Question
->NoSubmitListHead
;
1598 return EFI_UNSUPPORTED
;
1601 Link
= GetFirstNode (ListHead
);
1602 while (!IsNull (ListHead
, Link
)) {
1603 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1606 // Evaluate the expression
1608 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1609 if (EFI_ERROR (Status
)) {
1613 if (Expression
->Result
.Value
.b
) {
1615 // Condition meet, show up error message
1617 if (Expression
->Error
!= 0) {
1618 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1620 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1621 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1625 return EFI_NOT_READY
;
1628 Link
= GetNextNode (ListHead
, Link
);
1636 Perform NoSubmit check for a Form.
1638 @param FormSet FormSet data structure.
1639 @param Form Form data structure.
1641 @retval EFI_SUCCESS Form validation pass.
1642 @retval other Form validation failed.
1647 IN FORM_BROWSER_FORMSET
*FormSet
,
1648 IN FORM_BROWSER_FORM
*Form
1653 FORM_BROWSER_STATEMENT
*Question
;
1655 Link
= GetFirstNode (&Form
->StatementListHead
);
1656 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1657 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1659 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1660 if (EFI_ERROR (Status
)) {
1664 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1674 @param FormSet FormSet data structure.
1675 @param Form Form data structure.
1677 @retval EFI_SUCCESS The function completed successfully.
1682 IN FORM_BROWSER_FORMSET
*FormSet
,
1683 IN FORM_BROWSER_FORM
*Form
1688 EFI_STRING ConfigResp
;
1689 EFI_STRING Progress
;
1690 FORMSET_STORAGE
*Storage
;
1693 // Validate the Form by NoSubmit check
1695 Status
= NoSubmitCheck (FormSet
, Form
);
1696 if (EFI_ERROR (Status
)) {
1701 // Submit Buffer storage or Name/Value storage
1703 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1704 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1705 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1706 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1708 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1713 // Skip if there is no RequestElement
1715 if (Storage
->ElementCount
== 0) {
1720 // Prepare <ConfigResp>
1722 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1723 if (EFI_ERROR (Status
)) {
1728 // Send <ConfigResp> to Configuration Driver
1730 if (FormSet
->ConfigAccess
!= NULL
) {
1731 Status
= FormSet
->ConfigAccess
->RouteConfig (
1732 FormSet
->ConfigAccess
,
1736 if (EFI_ERROR (Status
)) {
1737 FreePool (ConfigResp
);
1741 FreePool (ConfigResp
);
1744 // Config success, update storage shadow Buffer
1746 SynchronizeStorage (Storage
);
1749 gNvUpdateRequired
= FALSE
;
1756 Reset Question to its default value.
1758 @param FormSet The form set.
1759 @param Form The form.
1760 @param Question The question.
1761 @param DefaultId The Class of the default.
1763 @retval EFI_SUCCESS Question is reset to default value.
1767 GetQuestionDefault (
1768 IN FORM_BROWSER_FORMSET
*FormSet
,
1769 IN FORM_BROWSER_FORM
*Form
,
1770 IN FORM_BROWSER_STATEMENT
*Question
,
1776 QUESTION_DEFAULT
*Default
;
1777 QUESTION_OPTION
*Option
;
1778 EFI_HII_VALUE
*HiiValue
;
1780 EFI_STRING StrValue
;
1782 Status
= EFI_SUCCESS
;
1786 // Statement don't have storage, skip them
1788 if (Question
->QuestionId
== 0) {
1793 // There are three ways to specify default value for a Question:
1794 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1795 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1796 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1798 HiiValue
= &Question
->HiiValue
;
1801 // EFI_IFR_DEFAULT has highest priority
1803 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1804 Link
= GetFirstNode (&Question
->DefaultListHead
);
1805 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1806 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1808 if (Default
->DefaultId
== DefaultId
) {
1809 if (Default
->ValueExpression
!= NULL
) {
1811 // Default is provided by an Expression, evaluate it
1813 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1814 if (EFI_ERROR (Status
)) {
1818 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1821 // Default value is embedded in EFI_IFR_DEFAULT
1823 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1826 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
1827 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
1828 if (StrValue
== NULL
) {
1829 return EFI_NOT_FOUND
;
1831 Question
->BufferValue
= AllocateCopyPool (StrSize (StrValue
), StrValue
);
1837 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1842 // EFI_ONE_OF_OPTION
1844 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1845 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1847 // OneOfOption could only provide Standard and Manufacturing default
1849 Link
= GetFirstNode (&Question
->OptionListHead
);
1850 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1851 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1853 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1854 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1856 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1861 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1867 // EFI_IFR_CHECKBOX - lowest priority
1869 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1870 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1872 // Checkbox could only provide Standard and Manufacturing default
1874 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1875 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1877 HiiValue
->Value
.b
= TRUE
;
1879 HiiValue
->Value
.b
= FALSE
;
1887 // For Questions without default
1889 switch (Question
->Operand
) {
1890 case EFI_IFR_ONE_OF_OP
:
1892 // Take first oneof option as oneof's default value
1894 if (ValueToOption (Question
, HiiValue
) == NULL
) {
1895 Link
= GetFirstNode (&Question
->OptionListHead
);
1896 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1897 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1898 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1903 case EFI_IFR_ORDERED_LIST_OP
:
1905 // Take option sequence in IFR as ordered list's default value
1908 Link
= GetFirstNode (&Question
->OptionListHead
);
1909 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1910 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1912 SetArrayData (Question
->BufferValue
, Question
->ValueType
, Index
, Option
->Value
.Value
.u64
);
1915 if (Index
>= Question
->MaxContainers
) {
1919 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1924 Status
= EFI_NOT_FOUND
;
1933 Reset Questions in a Form to their default value.
1935 @param FormSet FormSet data structure.
1936 @param Form The Form which to be reset.
1937 @param DefaultId The Class of the default.
1939 @retval EFI_SUCCESS The function completed successfully.
1943 ExtractFormDefault (
1944 IN FORM_BROWSER_FORMSET
*FormSet
,
1945 IN FORM_BROWSER_FORM
*Form
,
1951 FORM_BROWSER_STATEMENT
*Question
;
1953 Link
= GetFirstNode (&Form
->StatementListHead
);
1954 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1955 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1956 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1959 // If Question is disabled, don't reset it to default
1961 if (Question
->DisableExpression
!= NULL
) {
1962 Status
= EvaluateExpression (FormSet
, Form
, Question
->DisableExpression
);
1963 if (!EFI_ERROR (Status
) && Question
->DisableExpression
->Result
.Value
.b
) {
1969 // Reset Question to its default value
1971 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1972 if (EFI_ERROR (Status
)) {
1977 // Synchronize Buffer storage's Edit buffer
1979 if ((Question
->Storage
!= NULL
) &&
1980 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1981 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1990 Initialize Question's Edit copy from Storage.
1992 @param FormSet FormSet data structure.
1993 @param Form Form data structure.
1995 @retval EFI_SUCCESS The function completed successfully.
2000 IN FORM_BROWSER_FORMSET
*FormSet
,
2001 IN FORM_BROWSER_FORM
*Form
2006 FORM_BROWSER_STATEMENT
*Question
;
2008 Link
= GetFirstNode (&Form
->StatementListHead
);
2009 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2010 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2013 // Initialize local copy of Value for each Question
2015 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
2016 if (EFI_ERROR (Status
)) {
2020 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2028 Initialize Question's Edit copy from Storage for the whole Formset.
2030 @param FormSet FormSet data structure.
2032 @retval EFI_SUCCESS The function completed successfully.
2037 IN FORM_BROWSER_FORMSET
*FormSet
2042 FORM_BROWSER_FORM
*Form
;
2044 Link
= GetFirstNode (&FormSet
->FormListHead
);
2045 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2046 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2049 // Initialize local copy of Value for each Form
2051 Status
= LoadFormConfig (FormSet
, Form
);
2052 if (EFI_ERROR (Status
)) {
2056 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2064 Fill storage's edit copy with settings requested from Configuration Driver.
2066 @param FormSet FormSet data structure.
2067 @param Storage Buffer Storage.
2069 @retval EFI_SUCCESS The function completed successfully.
2074 IN FORM_BROWSER_FORMSET
*FormSet
,
2075 IN FORMSET_STORAGE
*Storage
2079 EFI_STRING Progress
;
2083 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2087 if (FormSet
->ConfigAccess
== NULL
) {
2088 return EFI_NOT_FOUND
;
2091 if (Storage
->ElementCount
== 0) {
2093 // Skip if there is no RequestElement
2099 // Request current settings from Configuration Driver
2101 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2102 FormSet
->ConfigAccess
,
2103 Storage
->ConfigRequest
,
2107 if (EFI_ERROR (Status
)) {
2112 // Convert Result from <ConfigAltResp> to <ConfigResp>
2114 StrPtr
= StrStr (Result
, L
"ALTCFG");
2115 if (StrPtr
!= NULL
) {
2119 Status
= ConfigRespToStorage (Storage
, Result
);
2126 Copy uncommitted data from source Storage to destination Storage.
2128 @param Dst Target Storage for uncommitted data.
2129 @param Src Source Storage for uncommitted data.
2131 @retval EFI_SUCCESS The function completed successfully.
2132 @retval EFI_INVALID_PARAMETER Source and destination Storage is not the same type.
2137 IN OUT FORMSET_STORAGE
*Dst
,
2138 IN FORMSET_STORAGE
*Src
2142 NAME_VALUE_NODE
*Node
;
2144 if ((Dst
->Type
!= Src
->Type
) || (Dst
->Size
!= Src
->Size
)) {
2145 return EFI_INVALID_PARAMETER
;
2148 switch (Src
->Type
) {
2149 case EFI_HII_VARSTORE_BUFFER
:
2150 CopyMem (Dst
->EditBuffer
, Src
->EditBuffer
, Src
->Size
);
2153 case EFI_HII_VARSTORE_NAME_VALUE
:
2154 Link
= GetFirstNode (&Src
->NameValueListHead
);
2155 while (!IsNull (&Src
->NameValueListHead
, Link
)) {
2156 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
2158 SetValueByName (Dst
, Node
->Name
, Node
->EditValue
);
2160 Link
= GetNextNode (&Src
->NameValueListHead
, Link
);
2164 case EFI_HII_VARSTORE_EFI_VARIABLE
:
2174 Get current setting of Questions.
2176 @param FormSet FormSet data structure.
2178 @retval EFI_SUCCESS The function completed successfully.
2182 InitializeCurrentSetting (
2183 IN OUT FORM_BROWSER_FORMSET
*FormSet
2188 FORMSET_STORAGE
*Storage
;
2189 FORMSET_STORAGE
*StorageSrc
;
2190 FORMSET_STORAGE
*OldStorage
;
2191 FORM_BROWSER_FORM
*Form
;
2195 // Extract default from IFR binary
2197 Link
= GetFirstNode (&FormSet
->FormListHead
);
2198 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2199 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2201 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2203 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2207 // Request current settings from Configuration Driver
2209 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2210 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2211 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2214 if (gOldFormSet
!= NULL
) {
2216 // Try to find the Storage in backup formset gOldFormSet
2218 Link2
= GetFirstNode (&gOldFormSet
->StorageListHead
);
2219 while (!IsNull (&gOldFormSet
->StorageListHead
, Link2
)) {
2220 StorageSrc
= FORMSET_STORAGE_FROM_LINK (Link2
);
2222 if (StorageSrc
->VarStoreId
== Storage
->VarStoreId
) {
2223 OldStorage
= StorageSrc
;
2227 Link2
= GetNextNode (&gOldFormSet
->StorageListHead
, Link2
);
2231 if (OldStorage
== NULL
) {
2233 // Storage is not found in backup formset, request it from ConfigDriver
2235 Status
= LoadStorage (FormSet
, Storage
);
2238 // Storage found in backup formset, use it
2240 Status
= CopyStorage (Storage
, OldStorage
);
2244 // Now Edit Buffer is filled with default values(lower priority) and current
2245 // settings(higher priority), sychronize it to shadow Buffer
2247 if (!EFI_ERROR (Status
)) {
2248 SynchronizeStorage (Storage
);
2251 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2259 Fetch the Ifr binary data of a FormSet.
2261 @param Handle PackageList Handle
2262 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2263 GUID), take the first FormSet found in package
2265 @param BinaryLength The length of the FormSet IFR binary.
2266 @param BinaryData The buffer designed to receive the FormSet.
2268 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2269 BufferLength was updated.
2270 @retval EFI_INVALID_PARAMETER The handle is unknown.
2271 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2272 be found with the requested FormId.
2277 IN EFI_HII_HANDLE Handle
,
2278 IN OUT EFI_GUID
*FormSetGuid
,
2279 OUT UINTN
*BinaryLength
,
2280 OUT UINT8
**BinaryData
2284 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2290 BOOLEAN ReturnDefault
;
2291 UINT32 PackageListLength
;
2292 EFI_HII_PACKAGE_HEADER PackageHeader
;
2294 UINT8 NumberOfClassGuid
;
2295 BOOLEAN IsSetupClassGuid
;
2296 EFI_GUID
*ClassGuid
;
2300 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2303 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2305 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2306 ReturnDefault
= TRUE
;
2308 ReturnDefault
= FALSE
;
2312 // Get HII PackageList
2315 HiiPackageList
= NULL
;
2316 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2317 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2318 HiiPackageList
= AllocatePool (BufferSize
);
2319 ASSERT (HiiPackageList
!= NULL
);
2321 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2323 if (EFI_ERROR (Status
)) {
2326 ASSERT (HiiPackageList
!= NULL
);
2329 // Get Form package from this HII package List
2331 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2333 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2335 while (Offset
< PackageListLength
) {
2336 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2337 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2339 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2341 // Search FormSet in this Form Package
2343 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2344 while (Offset2
< PackageHeader
.Length
) {
2345 OpCodeData
= Package
+ Offset2
;
2347 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2349 // Check whether return default FormSet
2351 if (ReturnDefault
) {
2353 // Check ClassGuid of formset OpCode
2355 IsSetupClassGuid
= FALSE
;
2356 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
2357 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
2358 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
2359 if (CompareGuid (ClassGuid
+ Index
, &gEfiHiiPlatformSetupFormsetGuid
)) {
2360 IsSetupClassGuid
= TRUE
;
2364 if (IsSetupClassGuid
) {
2370 // FormSet GUID is specified, check it
2372 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2377 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2380 if (Offset2
< PackageHeader
.Length
) {
2382 // Target formset found
2388 Offset
+= PackageHeader
.Length
;
2391 if (Offset
>= PackageListLength
) {
2393 // Form package not found in this Package List
2395 FreePool (HiiPackageList
);
2396 return EFI_NOT_FOUND
;
2399 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2401 // Return the default FormSet GUID
2403 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2407 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2408 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2409 // of the Form Package.
2411 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2412 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2414 FreePool (HiiPackageList
);
2416 if (*BinaryData
== NULL
) {
2417 return EFI_OUT_OF_RESOURCES
;
2425 Initialize the internal data structure of a FormSet.
2427 @param Handle PackageList Handle
2428 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2429 GUID), take the first FormSet found in package
2431 @param FormSet FormSet data structure.
2433 @retval EFI_SUCCESS The function completed successfully.
2434 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2439 IN EFI_HII_HANDLE Handle
,
2440 IN OUT EFI_GUID
*FormSetGuid
,
2441 OUT FORM_BROWSER_FORMSET
*FormSet
2445 EFI_HANDLE DriverHandle
;
2448 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2449 if (EFI_ERROR (Status
)) {
2453 FormSet
->HiiHandle
= Handle
;
2454 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2457 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2459 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2460 if (EFI_ERROR (Status
)) {
2463 FormSet
->DriverHandle
= DriverHandle
;
2464 Status
= gBS
->HandleProtocol (
2466 &gEfiHiiConfigAccessProtocolGuid
,
2467 (VOID
**) &FormSet
->ConfigAccess
2469 if (EFI_ERROR (Status
)) {
2471 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2472 // list, then there will be no configuration action required
2474 FormSet
->ConfigAccess
= NULL
;
2478 // Parse the IFR binary OpCodes
2480 Status
= ParseOpCodes (FormSet
);
2481 if (EFI_ERROR (Status
)) {
2485 gClassOfVfr
= FORMSET_CLASS_PLATFORM_SETUP
;
2486 if (FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
) {
2487 gClassOfVfr
= FORMSET_CLASS_FRONT_PAGE
;
2488 gFrontPageHandle
= FormSet
->HiiHandle
;
2492 // Match GUID to find out the function key setting. If match fail, use the default setting.
2494 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2495 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2497 // Update the function key setting.
2499 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2501 // Function key prompt can not be displayed if the function key has been disabled.
2503 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2504 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2507 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2508 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2511 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2512 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);