2 Entry and initialization module for the browser.
4 Copyright (c) 2007 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 SETUP_DRIVER_PRIVATE_DATA mPrivateData
= {
20 SETUP_DRIVER_SIGNATURE
,
28 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
29 EFI_HII_STRING_PROTOCOL
*mHiiString
;
30 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
32 BANNER_DATA
*BannerData
;
33 EFI_HII_HANDLE FrontPageHandle
;
35 UINTN gFunctionKeySetting
;
36 BOOLEAN gResetRequired
;
37 BOOLEAN gNvUpdateRequired
;
38 EFI_HII_HANDLE gHiiHandle
;
40 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
45 // Browser Global Strings
47 CHAR16
*gFunctionOneString
;
48 CHAR16
*gFunctionTwoString
;
49 CHAR16
*gFunctionNineString
;
50 CHAR16
*gFunctionTenString
;
52 CHAR16
*gEnterCommitString
;
53 CHAR16
*gEnterEscapeString
;
54 CHAR16
*gEscapeString
;
56 CHAR16
*gMoveHighlight
;
57 CHAR16
*gMakeSelection
;
58 CHAR16
*gDecNumericInput
;
59 CHAR16
*gHexNumericInput
;
60 CHAR16
*gToggleCheckBox
;
61 CHAR16
*gPromptForData
;
62 CHAR16
*gPromptForPassword
;
63 CHAR16
*gPromptForNewPassword
;
64 CHAR16
*gConfirmPassword
;
65 CHAR16
*gConfirmError
;
66 CHAR16
*gPassowordInvalid
;
75 CHAR16
*gAdjustNumber
;
77 CHAR16
*gOptionMismatch
;
79 CHAR16 gPromptBlockWidth
;
80 CHAR16 gOptionBlockWidth
;
81 CHAR16 gHelpBlockWidth
;
83 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
84 EFI_GUID gSetupBrowserGuid
= {
85 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
88 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
108 NONE_FUNCTION_KEY_SETTING
129 NONE_FUNCTION_KEY_SETTING
150 NONE_FUNCTION_KEY_SETTING
153 // BMM File Explorer FormSet.
171 NONE_FUNCTION_KEY_SETTING
176 This is the routine which an external caller uses to direct the browser
177 where to obtain it's information.
180 @param This The Form Browser protocol instanse.
181 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
182 display a list of the formsets for the handles specified.
183 @param HandleCount The number of Handles specified in Handle.
184 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
185 field in the EFI_IFR_FORM_SET op-code for the specified
186 forms-based package. If FormSetGuid is NULL, then this
187 function will display the first found forms package.
188 @param FormId This field specifies which EFI_IFR_FORM to render as the first
189 displayable page. If this field has a value of 0x0000, then
190 the forms browser will render the specified forms in their encoded order.
191 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
193 @param ActionRequest Points to the action recommended by the form.
195 @retval EFI_SUCCESS The function completed successfully.
196 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
197 @retval EFI_NOT_FOUND No valid forms could be found to display.
203 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
204 IN EFI_HII_HANDLE
*Handles
,
205 IN UINTN HandleCount
,
206 IN EFI_GUID
*FormSetGuid
, OPTIONAL
207 IN UINT16 FormId
, OPTIONAL
208 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
209 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
213 UI_MENU_SELECTION
*Selection
;
215 FORM_BROWSER_FORMSET
*FormSet
;
217 Status
= EFI_SUCCESS
;
218 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
221 // Seed the dimensions in the global
223 gST
->ConOut
->QueryMode (
225 gST
->ConOut
->Mode
->Mode
,
226 &gScreenDimensions
.RightColumn
,
227 &gScreenDimensions
.BottomRow
230 if (ScreenDimensions
!= NULL
) {
232 // Check local dimension vs. global dimension.
234 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
235 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
237 return EFI_INVALID_PARAMETER
;
240 // Local dimension validation.
242 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
243 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
244 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
246 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
247 SCROLL_ARROW_HEIGHT
*
249 FRONT_PAGE_HEADER_HEIGHT
+
254 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
256 return EFI_INVALID_PARAMETER
;
261 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
262 gHelpBlockWidth
= gOptionBlockWidth
;
263 gPromptBlockWidth
= gOptionBlockWidth
;
266 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
268 InitializeBrowserStrings ();
270 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
271 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
274 // Ensure we are in Text mode
276 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
278 for (Index
= 0; Index
< HandleCount
; Index
++) {
279 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
280 ASSERT (Selection
!= NULL
);
282 Selection
->Handle
= Handles
[Index
];
283 if (FormSetGuid
!= NULL
) {
284 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
285 Selection
->FormId
= FormId
;
289 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
290 ASSERT (FormSet
!= NULL
);
293 // Initialize internal data structures of FormSet
295 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
296 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
297 DestroyFormSet (FormSet
);
300 Selection
->FormSet
= FormSet
;
303 // Initialize current settings of Questions in this FormSet
305 Status
= InitializeCurrentSetting (FormSet
);
306 if (EFI_ERROR (Status
)) {
307 DestroyFormSet (FormSet
);
312 // Display this formset
314 gCurrentSelection
= Selection
;
316 Status
= SetupBrowser (Selection
);
318 gCurrentSelection
= NULL
;
319 DestroyFormSet (FormSet
);
321 if (EFI_ERROR (Status
)) {
325 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
327 FreePool (Selection
);
330 if (ActionRequest
!= NULL
) {
331 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
332 if (gResetRequired
) {
333 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
337 FreeBrowserStrings ();
339 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
340 gST
->ConOut
->ClearScreen (gST
->ConOut
);
347 This function is called by a callback handler to retrieve uncommitted state
348 data from the browser.
350 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
352 @param ResultsDataSize A pointer to the size of the buffer associated
354 @param ResultsData A string returned from an IFR browser or
355 equivalent. The results string will have no
356 routing information in them.
357 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
358 (if RetrieveData = TRUE) data from the uncommitted
359 browser state information or set (if RetrieveData
360 = FALSE) data in the uncommitted browser state
362 @param VariableGuid An optional field to indicate the target variable
364 @param VariableName An optional field to indicate the target
365 human-readable variable name.
367 @retval EFI_SUCCESS The results have been distributed or are awaiting
369 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
370 contain the results data.
376 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
377 IN OUT UINTN
*ResultsDataSize
,
378 IN OUT EFI_STRING ResultsData
,
379 IN BOOLEAN RetrieveData
,
380 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
381 IN CONST CHAR16
*VariableName OPTIONAL
386 FORMSET_STORAGE
*Storage
;
387 FORM_BROWSER_FORMSET
*FormSet
;
394 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
395 return EFI_INVALID_PARAMETER
;
398 if (gCurrentSelection
== NULL
) {
399 return EFI_NOT_READY
;
404 FormSet
= gCurrentSelection
->FormSet
;
407 // Find target storage
409 Link
= GetFirstNode (&FormSet
->StorageListHead
);
410 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
411 return EFI_UNSUPPORTED
;
414 if (VariableGuid
!= NULL
) {
416 // Try to find target storage
419 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
420 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
421 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
423 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
424 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
426 // Buffer storage require both GUID and Name
428 if (VariableName
== NULL
) {
429 return EFI_NOT_FOUND
;
432 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
442 return EFI_NOT_FOUND
;
446 // GUID/Name is not specified, take the first storage in FormSet
448 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
453 // Skip if there is no RequestElement
455 if (Storage
->ElementCount
== 0) {
460 // Generate <ConfigResp>
462 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
463 if (EFI_ERROR (Status
)) {
468 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
470 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
472 BufferSize
= StrSize (StrPtr
);
473 if (*ResultsDataSize
< BufferSize
) {
474 *ResultsDataSize
= BufferSize
;
476 FreePool (ConfigResp
);
477 return EFI_BUFFER_TOO_SMALL
;
480 *ResultsDataSize
= BufferSize
;
481 CopyMem (ResultsData
, StrPtr
, BufferSize
);
483 FreePool (ConfigResp
);
486 // Prepare <ConfigResp>
488 TmpSize
= StrLen (ResultsData
);
489 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
490 ConfigResp
= AllocateZeroPool (BufferSize
);
491 ASSERT (ConfigResp
!= NULL
);
493 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
494 StrCat (ConfigResp
, L
"&");
495 StrCat (ConfigResp
, ResultsData
);
498 // Update Browser uncommited data
500 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
501 if (EFI_ERROR (Status
)) {
511 Initialize Setup Browser driver.
513 @param ImageHandle The image handle.
514 @param SystemTable The system table.
516 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
517 @return Other value if failed to initialize the Setup Browser module.
523 IN EFI_HANDLE ImageHandle
,
524 IN EFI_SYSTEM_TABLE
*SystemTable
528 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
531 // Locate required Hii relative protocols
533 Status
= gBS
->LocateProtocol (
534 &gEfiHiiDatabaseProtocolGuid
,
536 (VOID
**) &mHiiDatabase
538 ASSERT_EFI_ERROR (Status
);
540 Status
= gBS
->LocateProtocol (
541 &gEfiHiiStringProtocolGuid
,
543 (VOID
**) &mHiiString
545 ASSERT_EFI_ERROR (Status
);
547 Status
= gBS
->LocateProtocol (
548 &gEfiHiiConfigRoutingProtocolGuid
,
550 (VOID
**) &mHiiConfigRouting
552 ASSERT_EFI_ERROR (Status
);
555 // Publish our HII data
557 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
558 ASSERT (PackageList
!= NULL
);
559 Status
= mHiiDatabase
->NewPackageList (
565 ASSERT_EFI_ERROR (Status
);
568 // Initialize Driver private data
570 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
571 ASSERT (BannerData
!= NULL
);
574 // Install FormBrowser2 protocol
576 mPrivateData
.Handle
= NULL
;
577 Status
= gBS
->InstallProtocolInterface (
578 &mPrivateData
.Handle
,
579 &gEfiFormBrowser2ProtocolGuid
,
580 EFI_NATIVE_INTERFACE
,
581 &mPrivateData
.FormBrowser2
583 ASSERT_EFI_ERROR (Status
);
590 Create a new string in HII Package List.
592 @param String The String to be added
593 @param HiiHandle The package list in the HII database to insert the
596 @return The output string.
602 IN EFI_HII_HANDLE HiiHandle
605 EFI_STRING_ID StringId
;
609 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
610 ASSERT_EFI_ERROR (Status
);
617 Delete a string from HII Package List.
619 @param StringId Id of the string in HII database.
620 @param HiiHandle The HII package list handle.
622 @retval EFI_SUCCESS The string was deleted successfully.
627 IN EFI_STRING_ID StringId
,
628 IN EFI_HII_HANDLE HiiHandle
633 NullChar
= CHAR_NULL
;
634 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
639 Get the string based on the StringId and HII Package List Handle.
641 @param Token The String's ID.
642 @param HiiHandle The package list in the HII database to search for
643 the specified string.
645 @return The output string.
650 IN EFI_STRING_ID Token
,
651 IN EFI_HII_HANDLE HiiHandle
659 // Set default string size assumption at no more than 256 bytes
661 BufferLength
= 0x100;
662 String
= AllocateZeroPool (BufferLength
);
663 ASSERT (String
!= NULL
);
665 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
667 if (Status
== EFI_BUFFER_TOO_SMALL
) {
669 String
= AllocateZeroPool (BufferLength
);
670 ASSERT (String
!= NULL
);
672 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
674 ASSERT_EFI_ERROR (Status
);
681 Allocate new memory and then copy the Unicode string Source to Destination.
683 @param Dest Location to copy string
684 @param Src String to copy
689 IN OUT CHAR16
**Dest
,
696 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
697 ASSERT (*Dest
!= NULL
);
702 Allocate new memory and concatinate Source on the end of Destination.
704 @param Dest String to added to the end of.
705 @param Src String to concatinate.
710 IN OUT CHAR16
**Dest
,
718 NewStringCpy (Dest
, Src
);
722 TmpSize
= StrSize (*Dest
);
723 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
724 ASSERT (NewString
!= NULL
);
726 StrCpy (NewString
, *Dest
);
727 StrCat (NewString
, Src
);
735 Synchronize Storage's Edit copy to Shadow copy.
737 @param Storage The Storage to be synchronized.
742 IN FORMSET_STORAGE
*Storage
746 NAME_VALUE_NODE
*Node
;
748 switch (Storage
->Type
) {
749 case EFI_HII_VARSTORE_BUFFER
:
750 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
753 case EFI_HII_VARSTORE_NAME_VALUE
:
754 Link
= GetFirstNode (&Storage
->NameValueListHead
);
755 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
756 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
758 NewStringCpy (&Node
->Value
, Node
->EditValue
);
760 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
764 case EFI_HII_VARSTORE_EFI_VARIABLE
:
772 Get Value for given Name from a NameValue Storage.
774 @param Storage The NameValue Storage.
775 @param Name The Name.
776 @param Value The retured Value.
778 @retval EFI_SUCCESS Value found for given Name.
779 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
784 IN FORMSET_STORAGE
*Storage
,
786 IN OUT CHAR16
**Value
790 NAME_VALUE_NODE
*Node
;
794 Link
= GetFirstNode (&Storage
->NameValueListHead
);
795 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
796 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
798 if (StrCmp (Name
, Node
->Name
) == 0) {
799 NewStringCpy (Value
, Node
->EditValue
);
803 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
806 return EFI_NOT_FOUND
;
811 Set Value of given Name in a NameValue Storage.
813 @param Storage The NameValue Storage.
814 @param Name The Name.
815 @param Value The Value to set.
817 @retval EFI_SUCCESS Value found for given Name.
818 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
823 IN FORMSET_STORAGE
*Storage
,
829 NAME_VALUE_NODE
*Node
;
831 Link
= GetFirstNode (&Storage
->NameValueListHead
);
832 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
833 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
835 if (StrCmp (Name
, Node
->Name
) == 0) {
836 if (Node
->EditValue
!= NULL
) {
837 FreePool (Node
->EditValue
);
839 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
840 ASSERT (Node
->EditValue
!= NULL
);
844 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
847 return EFI_NOT_FOUND
;
852 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
854 @param Storage The Storage to be conveted.
855 @param ConfigResp The returned <ConfigResp>.
857 @retval EFI_SUCCESS Convert success.
858 @retval EFI_INVALID_PARAMETER Incorrect storage type.
862 StorageToConfigResp (
863 IN FORMSET_STORAGE
*Storage
,
864 IN CHAR16
**ConfigResp
870 NAME_VALUE_NODE
*Node
;
872 Status
= EFI_SUCCESS
;
874 switch (Storage
->Type
) {
875 case EFI_HII_VARSTORE_BUFFER
:
876 Status
= mHiiConfigRouting
->BlockToConfig (
878 Storage
->ConfigRequest
,
886 case EFI_HII_VARSTORE_NAME_VALUE
:
888 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
890 Link
= GetFirstNode (&Storage
->NameValueListHead
);
891 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
892 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
894 NewStringCat (ConfigResp
, L
"&");
895 NewStringCat (ConfigResp
, Node
->Name
);
896 NewStringCat (ConfigResp
, L
"=");
897 NewStringCat (ConfigResp
, Node
->EditValue
);
899 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
903 case EFI_HII_VARSTORE_EFI_VARIABLE
:
905 Status
= EFI_INVALID_PARAMETER
;
914 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
916 @param Storage The Storage to receive the settings.
917 @param ConfigResp The <ConfigResp> to be converted.
919 @retval EFI_SUCCESS Convert success.
920 @retval EFI_INVALID_PARAMETER Incorrect storage type.
924 ConfigRespToStorage (
925 IN FORMSET_STORAGE
*Storage
,
926 IN CHAR16
*ConfigResp
936 Status
= EFI_SUCCESS
;
938 switch (Storage
->Type
) {
939 case EFI_HII_VARSTORE_BUFFER
:
940 BufferSize
= Storage
->Size
;
941 Status
= mHiiConfigRouting
->ConfigToBlock (
950 case EFI_HII_VARSTORE_NAME_VALUE
:
951 StrPtr
= StrStr (ConfigResp
, L
"&");
952 while (StrPtr
!= NULL
) {
958 StrPtr
= StrStr (StrPtr
, L
"=");
959 if (StrPtr
== NULL
) {
969 StrPtr
= StrStr (StrPtr
, L
"&");
970 if (StrPtr
!= NULL
) {
973 SetValueByName (Storage
, Name
, Value
);
977 case EFI_HII_VARSTORE_EFI_VARIABLE
:
979 Status
= EFI_INVALID_PARAMETER
;
988 Get Question's current Value.
990 @param FormSet FormSet data structure.
991 @param Form Form data structure.
992 @param Question Question to be initialized.
993 @param Cached TRUE: get from Edit copy FALSE: get from original
996 @retval EFI_SUCCESS The function completed successfully.
1001 IN FORM_BROWSER_FORMSET
*FormSet
,
1002 IN FORM_BROWSER_FORM
*Form
,
1003 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1013 FORMSET_STORAGE
*Storage
;
1014 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1015 CHAR16
*ConfigRequest
;
1021 BOOLEAN IsBufferStorage
;
1024 Status
= EFI_SUCCESS
;
1027 // Statement don't have storage, skip them
1029 if (Question
->QuestionId
== 0) {
1034 // Question value is provided by an Expression, evaluate it
1036 if (Question
->ValueExpression
!= NULL
) {
1037 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1038 if (!EFI_ERROR (Status
)) {
1039 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1045 // Question value is provided by RTC
1047 Storage
= Question
->Storage
;
1048 QuestionValue
= &Question
->HiiValue
.Value
;
1049 if (Storage
== NULL
) {
1051 // It's a Question without storage, or RTC date/time
1053 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1055 // Date and time define the same Flags bit
1057 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1058 case QF_DATE_STORAGE_TIME
:
1059 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1062 case QF_DATE_STORAGE_WAKEUP
:
1063 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1066 case QF_DATE_STORAGE_NORMAL
:
1069 // For date/time without storage
1074 if (EFI_ERROR (Status
)) {
1078 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1079 QuestionValue
->date
.Year
= EfiTime
.Year
;
1080 QuestionValue
->date
.Month
= EfiTime
.Month
;
1081 QuestionValue
->date
.Day
= EfiTime
.Day
;
1083 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1084 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1085 QuestionValue
->time
.Second
= EfiTime
.Second
;
1093 // Question value is provided by EFI variable
1095 StorageWidth
= Question
->StorageWidth
;
1096 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1097 if (Question
->BufferValue
!= NULL
) {
1098 Dst
= Question
->BufferValue
;
1100 Dst
= (UINT8
*) QuestionValue
;
1103 Status
= gRT
->GetVariable (
1104 Question
->VariableName
,
1111 // Always return success, even this EFI variable doesn't exist
1117 // Question Value is provided by Buffer Storage or NameValue Storage
1119 if (Question
->BufferValue
!= NULL
) {
1121 // This Question is password or orderedlist
1123 Dst
= Question
->BufferValue
;
1126 // Other type of Questions
1128 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1131 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1132 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1134 if (IsBufferStorage
) {
1136 // Copy from storage Edit buffer
1138 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1140 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1141 if (EFI_ERROR (Status
)) {
1147 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1149 Length
= StorageWidth
+ sizeof (CHAR16
);
1150 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1152 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1159 // Request current settings from Configuration Driver
1161 if (FormSet
->ConfigAccess
== NULL
) {
1162 return EFI_NOT_FOUND
;
1166 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1167 // <ConfigHdr> + "&" + <VariableName>
1169 if (IsBufferStorage
) {
1170 Length
= StrLen (Storage
->ConfigHdr
);
1171 Length
+= StrLen (Question
->BlockName
);
1173 Length
= StrLen (Storage
->ConfigHdr
);
1174 Length
+= StrLen (Question
->VariableName
) + 1;
1176 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1177 ASSERT (ConfigRequest
!= NULL
);
1179 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1180 if (IsBufferStorage
) {
1181 StrCat (ConfigRequest
, Question
->BlockName
);
1183 StrCat (ConfigRequest
, L
"&");
1184 StrCat (ConfigRequest
, Question
->VariableName
);
1187 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1188 FormSet
->ConfigAccess
,
1193 if (EFI_ERROR (Status
)) {
1198 // Skip <ConfigRequest>
1200 Value
= Result
+ Length
;
1201 if (IsBufferStorage
) {
1207 if (*Value
!= '=') {
1209 return EFI_NOT_FOUND
;
1212 // Skip '=', point to value
1217 // Suppress <AltResp> if any
1220 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1225 if (!IsBufferStorage
&& IsString
) {
1227 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1229 Length
= StorageWidth
+ sizeof (CHAR16
);
1230 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1232 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1233 if (EFI_ERROR (Status
)) {
1240 // Synchronize Edit Buffer
1242 if (IsBufferStorage
) {
1243 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1245 SetValueByName (Storage
, Question
->VariableName
, Value
);
1255 Save Question Value to edit copy(cached) or Storage(uncached).
1257 @param FormSet FormSet data structure.
1258 @param Form Form data structure.
1259 @param Question Pointer to the Question.
1260 @param Cached TRUE: set to Edit copy FALSE: set to original
1263 @retval EFI_SUCCESS The function completed successfully.
1268 IN FORM_BROWSER_FORMSET
*FormSet
,
1269 IN FORM_BROWSER_FORM
*Form
,
1270 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1281 FORMSET_STORAGE
*Storage
;
1282 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1287 BOOLEAN IsBufferStorage
;
1290 Status
= EFI_SUCCESS
;
1293 // Statement don't have storage, skip them
1295 if (Question
->QuestionId
== 0) {
1300 // If Question value is provided by an Expression, then it is read only
1302 if (Question
->ValueExpression
!= NULL
) {
1307 // Question value is provided by RTC
1309 Storage
= Question
->Storage
;
1310 QuestionValue
= &Question
->HiiValue
.Value
;
1311 if (Storage
== NULL
) {
1313 // It's a Question without storage, or RTC date/time
1315 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1317 // Date and time define the same Flags bit
1319 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1320 case QF_DATE_STORAGE_TIME
:
1321 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1324 case QF_DATE_STORAGE_WAKEUP
:
1325 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1328 case QF_DATE_STORAGE_NORMAL
:
1331 // For date/time without storage
1336 if (EFI_ERROR (Status
)) {
1340 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1341 EfiTime
.Year
= QuestionValue
->date
.Year
;
1342 EfiTime
.Month
= QuestionValue
->date
.Month
;
1343 EfiTime
.Day
= QuestionValue
->date
.Day
;
1345 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1346 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1347 EfiTime
.Second
= QuestionValue
->time
.Second
;
1350 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1351 Status
= gRT
->SetTime (&EfiTime
);
1353 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1361 // Question value is provided by EFI variable
1363 StorageWidth
= Question
->StorageWidth
;
1364 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1365 if (Question
->BufferValue
!= NULL
) {
1366 Src
= Question
->BufferValue
;
1368 Src
= (UINT8
*) QuestionValue
;
1371 Status
= gRT
->SetVariable (
1372 Question
->VariableName
,
1374 Storage
->Attributes
,
1382 // Question Value is provided by Buffer Storage or NameValue Storage
1384 if (Question
->BufferValue
!= NULL
) {
1385 Src
= Question
->BufferValue
;
1387 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1390 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1391 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1392 if (IsBufferStorage
) {
1394 // Copy to storage edit buffer
1396 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1400 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1403 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1404 Value
= AllocateZeroPool (BufferLen
);
1405 ASSERT (Value
!= NULL
);
1406 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1407 ASSERT_EFI_ERROR (Status
);
1409 BufferLen
= StorageWidth
* 2 + 1;
1410 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1411 ASSERT (Value
!= NULL
);
1412 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1416 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1422 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1423 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1425 if (IsBufferStorage
) {
1426 Length
= StrLen (Question
->BlockName
) + 7;
1428 Length
= StrLen (Question
->VariableName
) + 2;
1430 if (!IsBufferStorage
&& IsString
) {
1431 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1433 Length
+= (StorageWidth
* 2);
1435 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1436 ASSERT (ConfigResp
!= NULL
);
1438 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1439 if (IsBufferStorage
) {
1440 StrCat (ConfigResp
, Question
->BlockName
);
1441 StrCat (ConfigResp
, L
"&VALUE=");
1443 StrCat (ConfigResp
, L
"&");
1444 StrCat (ConfigResp
, Question
->VariableName
);
1445 StrCat (ConfigResp
, L
"=");
1448 Value
= ConfigResp
+ StrLen (ConfigResp
);
1449 if (!IsBufferStorage
&& IsString
) {
1451 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1453 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1454 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1455 ASSERT_EFI_ERROR (Status
);
1457 BufferLen
= StorageWidth
* 2 + 1;
1458 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1463 // Submit Question Value to Configuration Driver
1465 if (FormSet
->ConfigAccess
!= NULL
) {
1466 Status
= FormSet
->ConfigAccess
->RouteConfig (
1467 FormSet
->ConfigAccess
,
1471 if (EFI_ERROR (Status
)) {
1472 FreePool (ConfigResp
);
1476 FreePool (ConfigResp
);
1479 // Synchronize shadow Buffer
1481 SynchronizeStorage (Storage
);
1489 Perform inconsistent check for a Form.
1491 @param FormSet FormSet data structure.
1492 @param Form Form data structure.
1493 @param Question The Question to be validated.
1494 @param Type Validation type: InConsistent or NoSubmit
1496 @retval EFI_SUCCESS Form validation pass.
1497 @retval other Form validation failed.
1502 IN FORM_BROWSER_FORMSET
*FormSet
,
1503 IN FORM_BROWSER_FORM
*Form
,
1504 IN FORM_BROWSER_STATEMENT
*Question
,
1510 LIST_ENTRY
*ListHead
;
1513 FORM_EXPRESSION
*Expression
;
1515 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1516 ListHead
= &Question
->InconsistentListHead
;
1517 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1518 ListHead
= &Question
->NoSubmitListHead
;
1520 return EFI_UNSUPPORTED
;
1523 Link
= GetFirstNode (ListHead
);
1524 while (!IsNull (ListHead
, Link
)) {
1525 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1528 // Evaluate the expression
1530 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1531 if (EFI_ERROR (Status
)) {
1535 if (Expression
->Result
.Value
.b
) {
1537 // Condition meet, show up error message
1539 if (Expression
->Error
!= 0) {
1540 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1542 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1543 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1547 return EFI_NOT_READY
;
1550 Link
= GetNextNode (ListHead
, Link
);
1558 Perform NoSubmit check for a Form.
1560 @param FormSet FormSet data structure.
1561 @param Form Form data structure.
1563 @retval EFI_SUCCESS Form validation pass.
1564 @retval other Form validation failed.
1569 IN FORM_BROWSER_FORMSET
*FormSet
,
1570 IN FORM_BROWSER_FORM
*Form
1575 FORM_BROWSER_STATEMENT
*Question
;
1577 Link
= GetFirstNode (&Form
->StatementListHead
);
1578 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1579 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1581 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1582 if (EFI_ERROR (Status
)) {
1586 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1596 @param FormSet FormSet data structure.
1597 @param Form Form data structure.
1599 @retval EFI_SUCCESS The function completed successfully.
1604 IN FORM_BROWSER_FORMSET
*FormSet
,
1605 IN FORM_BROWSER_FORM
*Form
1610 EFI_STRING ConfigResp
;
1611 EFI_STRING Progress
;
1612 FORMSET_STORAGE
*Storage
;
1615 // Validate the Form by NoSubmit check
1617 Status
= NoSubmitCheck (FormSet
, Form
);
1618 if (EFI_ERROR (Status
)) {
1623 // Submit Buffer storage or Name/Value storage
1625 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1626 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1627 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1628 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1630 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1635 // Skip if there is no RequestElement
1637 if (Storage
->ElementCount
== 0) {
1642 // Prepare <ConfigResp>
1644 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1645 if (EFI_ERROR (Status
)) {
1650 // Send <ConfigResp> to Configuration Driver
1652 if (FormSet
->ConfigAccess
!= NULL
) {
1653 Status
= FormSet
->ConfigAccess
->RouteConfig (
1654 FormSet
->ConfigAccess
,
1658 if (EFI_ERROR (Status
)) {
1659 FreePool (ConfigResp
);
1663 FreePool (ConfigResp
);
1666 // Config success, update storage shadow Buffer
1668 SynchronizeStorage (Storage
);
1671 gNvUpdateRequired
= FALSE
;
1678 Reset Question to its default value.
1680 @param FormSet The form set.
1681 @param Form The form.
1682 @param Question The question.
1683 @param DefaultId The Class of the default.
1685 @retval EFI_SUCCESS Question is reset to default value.
1689 GetQuestionDefault (
1690 IN FORM_BROWSER_FORMSET
*FormSet
,
1691 IN FORM_BROWSER_FORM
*Form
,
1692 IN FORM_BROWSER_STATEMENT
*Question
,
1698 QUESTION_DEFAULT
*Default
;
1699 QUESTION_OPTION
*Option
;
1700 EFI_HII_VALUE
*HiiValue
;
1703 Status
= EFI_SUCCESS
;
1706 // Statement don't have storage, skip them
1708 if (Question
->QuestionId
== 0) {
1713 // There are three ways to specify default value for a Question:
1714 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1715 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1716 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1718 HiiValue
= &Question
->HiiValue
;
1721 // EFI_IFR_DEFAULT has highest priority
1723 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1724 Link
= GetFirstNode (&Question
->DefaultListHead
);
1725 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1726 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1728 if (Default
->DefaultId
== DefaultId
) {
1729 if (Default
->ValueExpression
!= NULL
) {
1731 // Default is provided by an Expression, evaluate it
1733 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1734 if (EFI_ERROR (Status
)) {
1738 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1741 // Default value is embedded in EFI_IFR_DEFAULT
1743 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1749 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1754 // EFI_ONE_OF_OPTION
1756 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1757 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1759 // OneOfOption could only provide Standard and Manufacturing default
1761 Link
= GetFirstNode (&Question
->OptionListHead
);
1762 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1763 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1765 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1766 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1768 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1773 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1779 // EFI_IFR_CHECKBOX - lowest priority
1781 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1782 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1784 // Checkbox could only provide Standard and Manufacturing default
1786 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1787 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1789 HiiValue
->Value
.b
= TRUE
;
1791 HiiValue
->Value
.b
= FALSE
;
1799 // For Questions without default
1801 switch (Question
->Operand
) {
1802 case EFI_IFR_NUMERIC_OP
:
1804 // Take minimal value as numeric's default value
1806 HiiValue
->Value
.u64
= Question
->Minimum
;
1809 case EFI_IFR_ONE_OF_OP
:
1811 // Take first oneof option as oneof's default value
1813 Link
= GetFirstNode (&Question
->OptionListHead
);
1814 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1815 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1816 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1820 case EFI_IFR_ORDERED_LIST_OP
:
1822 // Take option sequence in IFR as ordered list's default value
1825 Link
= GetFirstNode (&Question
->OptionListHead
);
1826 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1827 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1829 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1832 if (Index
>= Question
->MaxContainers
) {
1836 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1841 Status
= EFI_NOT_FOUND
;
1850 Reset Questions in a Form to their default value.
1852 @param FormSet FormSet data structure.
1853 @param Form The Form which to be reset.
1854 @param DefaultId The Class of the default.
1856 @retval EFI_SUCCESS The function completed successfully.
1860 ExtractFormDefault (
1861 IN FORM_BROWSER_FORMSET
*FormSet
,
1862 IN FORM_BROWSER_FORM
*Form
,
1868 FORM_BROWSER_STATEMENT
*Question
;
1870 Link
= GetFirstNode (&Form
->StatementListHead
);
1871 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1872 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1873 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1876 // If Question is suppressed, don't reset it to default
1878 if (Question
->SuppressExpression
!= NULL
) {
1879 Status
= EvaluateExpression (FormSet
, Form
, Question
->SuppressExpression
);
1880 if (!EFI_ERROR (Status
) && Question
->SuppressExpression
->Result
.Value
.b
) {
1886 // Reset Question to its default value
1888 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1889 if (EFI_ERROR (Status
)) {
1894 // Synchronize Buffer storage's Edit buffer
1896 if ((Question
->Storage
!= NULL
) &&
1897 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1898 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1907 Initialize Question's Edit copy from Storage.
1909 @param FormSet FormSet data structure.
1910 @param Form Form data structure.
1912 @retval EFI_SUCCESS The function completed successfully.
1917 IN FORM_BROWSER_FORMSET
*FormSet
,
1918 IN FORM_BROWSER_FORM
*Form
1923 FORM_BROWSER_STATEMENT
*Question
;
1925 Link
= GetFirstNode (&Form
->StatementListHead
);
1926 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1927 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1930 // Initialize local copy of Value for each Question
1932 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1933 if (EFI_ERROR (Status
)) {
1937 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1945 Fill storage's edit copy with settings requested from Configuration Driver.
1947 @param FormSet FormSet data structure.
1948 @param Storage Buffer Storage.
1950 @retval EFI_SUCCESS The function completed successfully.
1955 IN FORM_BROWSER_FORMSET
*FormSet
,
1956 IN FORMSET_STORAGE
*Storage
1960 EFI_STRING Progress
;
1964 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1968 if (FormSet
->ConfigAccess
== NULL
) {
1969 return EFI_NOT_FOUND
;
1972 if (Storage
->ElementCount
== 0) {
1974 // Skip if there is no RequestElement
1980 // Request current settings from Configuration Driver
1982 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1983 FormSet
->ConfigAccess
,
1984 Storage
->ConfigRequest
,
1988 if (EFI_ERROR (Status
)) {
1993 // Convert Result from <ConfigAltResp> to <ConfigResp>
1995 StrPtr
= StrStr (Result
, L
"ALTCFG");
1996 if (StrPtr
!= NULL
) {
2000 Status
= ConfigRespToStorage (Storage
, Result
);
2007 Get current setting of Questions.
2009 @param FormSet FormSet data structure.
2011 @retval EFI_SUCCESS The function completed successfully.
2015 InitializeCurrentSetting (
2016 IN OUT FORM_BROWSER_FORMSET
*FormSet
2020 FORMSET_STORAGE
*Storage
;
2021 FORM_BROWSER_FORM
*Form
;
2025 // Extract default from IFR binary
2027 Link
= GetFirstNode (&FormSet
->FormListHead
);
2028 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2029 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2031 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2033 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2037 // Request current settings from Configuration Driver
2039 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2040 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2041 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2043 Status
= LoadStorage (FormSet
, Storage
);
2046 // Now Edit Buffer is filled with default values(lower priority) and current
2047 // settings(higher priority), sychronize it to shadow Buffer
2049 if (!EFI_ERROR (Status
)) {
2050 SynchronizeStorage (Storage
);
2053 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2061 Fetch the Ifr binary data of a FormSet.
2063 @param Handle PackageList Handle
2064 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2065 GUID), take the first FormSet found in package
2067 @param BinaryLength The length of the FormSet IFR binary.
2068 @param BinaryData The buffer designed to receive the FormSet.
2070 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2071 BufferLength was updated.
2072 @retval EFI_INVALID_PARAMETER The handle is unknown.
2073 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2074 be found with the requested FormId.
2079 IN EFI_HII_HANDLE Handle
,
2080 IN OUT EFI_GUID
*FormSetGuid
,
2081 OUT UINTN
*BinaryLength
,
2082 OUT UINT8
**BinaryData
2086 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2092 BOOLEAN ReturnDefault
;
2093 UINT32 PackageListLength
;
2094 EFI_HII_PACKAGE_HEADER PackageHeader
;
2098 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2101 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2103 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2104 ReturnDefault
= TRUE
;
2106 ReturnDefault
= FALSE
;
2110 // Get HII PackageList
2113 HiiPackageList
= NULL
;
2114 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2115 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2116 HiiPackageList
= AllocatePool (BufferSize
);
2117 ASSERT (HiiPackageList
!= NULL
);
2119 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2121 if (EFI_ERROR (Status
)) {
2124 ASSERT (HiiPackageList
!= NULL
);
2127 // Get Form package from this HII package List
2129 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2131 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2133 while (Offset
< PackageListLength
) {
2134 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2135 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2137 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2139 // Search FormSet in this Form Package
2141 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2142 while (Offset2
< PackageHeader
.Length
) {
2143 OpCodeData
= Package
+ Offset2
;
2145 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2147 // Check whether return default FormSet
2149 if (ReturnDefault
) {
2154 // FormSet GUID is specified, check it
2156 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2161 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2164 if (Offset2
< PackageHeader
.Length
) {
2166 // Target formset found
2172 Offset
+= PackageHeader
.Length
;
2175 if (Offset
>= PackageListLength
) {
2177 // Form package not found in this Package List
2179 FreePool (HiiPackageList
);
2180 return EFI_NOT_FOUND
;
2183 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2185 // Return the default FormSet GUID
2187 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2191 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2192 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2193 // of the Form Package.
2195 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2196 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2198 FreePool (HiiPackageList
);
2200 if (*BinaryData
== NULL
) {
2201 return EFI_OUT_OF_RESOURCES
;
2209 Initialize the internal data structure of a FormSet.
2211 @param Handle PackageList Handle
2212 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2213 GUID), take the first FormSet found in package
2215 @param FormSet FormSet data structure.
2217 @retval EFI_SUCCESS The function completed successfully.
2218 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2223 IN EFI_HII_HANDLE Handle
,
2224 IN OUT EFI_GUID
*FormSetGuid
,
2225 OUT FORM_BROWSER_FORMSET
*FormSet
2229 EFI_HANDLE DriverHandle
;
2232 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2233 if (EFI_ERROR (Status
)) {
2237 FormSet
->HiiHandle
= Handle
;
2238 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2241 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2243 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2244 if (EFI_ERROR (Status
)) {
2247 FormSet
->DriverHandle
= DriverHandle
;
2248 Status
= gBS
->HandleProtocol (
2250 &gEfiHiiConfigAccessProtocolGuid
,
2251 (VOID
**) &FormSet
->ConfigAccess
2253 if (EFI_ERROR (Status
)) {
2255 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2256 // list, then there will be no configuration action required
2258 FormSet
->ConfigAccess
= NULL
;
2262 // Parse the IFR binary OpCodes
2264 Status
= ParseOpCodes (FormSet
);
2265 if (EFI_ERROR (Status
)) {
2269 gClassOfVfr
= FormSet
->SubClass
;
2270 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2271 FrontPageHandle
= FormSet
->HiiHandle
;
2275 // Match GUID to find out the function key setting. If match fail, use the default setting.
2277 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2278 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2280 // Update the function key setting.
2282 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2284 // Function key prompt can not be displayed if the function key has been disabled.
2286 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2287 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2290 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2291 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2294 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2295 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2298 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2299 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);