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
,
31 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
32 EFI_HII_STRING_PROTOCOL
*mHiiString
;
33 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
35 BANNER_DATA
*BannerData
;
36 EFI_HII_HANDLE FrontPageHandle
;
38 UINTN gFunctionKeySetting
;
39 BOOLEAN gResetRequired
;
40 BOOLEAN gNvUpdateRequired
;
41 EFI_HII_HANDLE gHiiHandle
;
44 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
49 // Browser Global Strings
51 CHAR16
*gFunctionOneString
;
52 CHAR16
*gFunctionTwoString
;
53 CHAR16
*gFunctionNineString
;
54 CHAR16
*gFunctionTenString
;
56 CHAR16
*gEnterCommitString
;
57 CHAR16
*gEscapeString
;
59 CHAR16
*gMoveHighlight
;
60 CHAR16
*gMakeSelection
;
61 CHAR16
*gDecNumericInput
;
62 CHAR16
*gHexNumericInput
;
63 CHAR16
*gToggleCheckBox
;
64 CHAR16
*gPromptForData
;
65 CHAR16
*gPromptForPassword
;
66 CHAR16
*gPromptForNewPassword
;
67 CHAR16
*gConfirmPassword
;
68 CHAR16
*gConfirmError
;
69 CHAR16
*gPassowordInvalid
;
78 CHAR16
*gAdjustNumber
;
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 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
109 NONE_FUNCTION_KEY_SETTING
130 NONE_FUNCTION_KEY_SETTING
151 NONE_FUNCTION_KEY_SETTING
154 // BMM File Explorer FormSet.
172 NONE_FUNCTION_KEY_SETTING
177 This is the routine which an external caller uses to direct the browser
178 where to obtain it's information.
181 @param This The Form Browser protocol instanse.
182 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
183 display a list of the formsets for the handles specified.
184 @param HandleCount The number of Handles specified in Handle.
185 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
186 field in the EFI_IFR_FORM_SET op-code for the specified
187 forms-based package. If FormSetGuid is NULL, then this
188 function will display the first found forms package.
189 @param FormId This field specifies which EFI_IFR_FORM to render as the first
190 displayable page. If this field has a value of 0x0000, then
191 the forms browser will render the specified forms in their encoded order.
192 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
194 @param ActionRequest Points to the action recommended by the form.
196 @retval EFI_SUCCESS The function completed successfully.
197 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
198 @retval EFI_NOT_FOUND No valid forms could be found to display.
204 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
205 IN EFI_HII_HANDLE
*Handles
,
206 IN UINTN HandleCount
,
207 IN EFI_GUID
*FormSetGuid
, OPTIONAL
208 IN UINT16 FormId
, OPTIONAL
209 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
210 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
214 UI_MENU_SELECTION
*Selection
;
216 FORM_BROWSER_FORMSET
*FormSet
;
218 Status
= EFI_SUCCESS
;
219 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
222 // Seed the dimensions in the global
224 gST
->ConOut
->QueryMode (
226 gST
->ConOut
->Mode
->Mode
,
227 &gScreenDimensions
.RightColumn
,
228 &gScreenDimensions
.BottomRow
231 if (ScreenDimensions
!= NULL
) {
233 // Check local dimension vs. global dimension.
235 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
236 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
238 return EFI_INVALID_PARAMETER
;
241 // Local dimension validation.
243 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
244 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
245 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
247 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
248 SCROLL_ARROW_HEIGHT
*
250 FRONT_PAGE_HEADER_HEIGHT
+
255 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
257 return EFI_INVALID_PARAMETER
;
262 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
263 gHelpBlockWidth
= gOptionBlockWidth
;
264 gPromptBlockWidth
= gOptionBlockWidth
;
267 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
269 InitializeBrowserStrings ();
271 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
272 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
275 // Ensure we are in Text mode
279 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
283 for (Index
= 0; Index
< HandleCount
; Index
++) {
284 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
285 ASSERT (Selection
!= NULL
);
287 Selection
->Handle
= Handles
[Index
];
288 if (FormSetGuid
!= NULL
) {
289 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
290 Selection
->FormId
= FormId
;
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 // Initialize current settings of Questions in this FormSet
310 Status
= InitializeCurrentSetting (FormSet
);
311 if (EFI_ERROR (Status
)) {
312 DestroyFormSet (FormSet
);
317 // Display this formset
319 gCurrentSelection
= Selection
;
321 Status
= SetupBrowser (Selection
);
323 gCurrentSelection
= NULL
;
324 DestroyFormSet (FormSet
);
326 if (EFI_ERROR (Status
)) {
330 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
332 gBS
->FreePool (Selection
);
335 if (ActionRequest
!= NULL
) {
336 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
337 if (gResetRequired
) {
338 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
342 FreeBrowserStrings ();
344 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
345 gST
->ConOut
->ClearScreen (gST
->ConOut
);
352 This function is called by a callback handler to retrieve uncommitted state
353 data from the browser.
355 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
357 @param ResultsDataSize A pointer to the size of the buffer associated
359 @param ResultsData A string returned from an IFR browser or
360 equivalent. The results string will have no
361 routing information in them.
362 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
363 (if RetrieveData = TRUE) data from the uncommitted
364 browser state information or set (if RetrieveData
365 = FALSE) data in the uncommitted browser state
367 @param VariableGuid An optional field to indicate the target variable
369 @param VariableName An optional field to indicate the target
370 human-readable variable name.
372 @retval EFI_SUCCESS The results have been distributed or are awaiting
374 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
375 contain the results data.
381 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
382 IN OUT UINTN
*ResultsDataSize
,
383 IN OUT EFI_STRING ResultsData
,
384 IN BOOLEAN RetrieveData
,
385 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
386 IN CONST CHAR16
*VariableName OPTIONAL
391 FORMSET_STORAGE
*Storage
;
392 FORM_BROWSER_FORMSET
*FormSet
;
399 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
400 return EFI_INVALID_PARAMETER
;
403 if (gCurrentSelection
== NULL
) {
404 return EFI_NOT_READY
;
409 FormSet
= gCurrentSelection
->FormSet
;
412 // Find target storage
414 Link
= GetFirstNode (&FormSet
->StorageListHead
);
415 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
416 return EFI_UNSUPPORTED
;
419 if (VariableGuid
!= NULL
) {
421 // Try to find target storage
424 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
425 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
426 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
428 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
429 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
431 // Buffer storage require both GUID and Name
433 if (VariableName
== NULL
) {
434 return EFI_NOT_FOUND
;
437 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
447 return EFI_NOT_FOUND
;
451 // GUID/Name is not specified, take the first storage in FormSet
453 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
458 // Skip if there is no RequestElement
460 if (Storage
->ElementCount
== 0) {
465 // Generate <ConfigResp>
467 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
468 if (EFI_ERROR (Status
)) {
473 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
475 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
477 BufferSize
= StrSize (StrPtr
);
478 if (*ResultsDataSize
< BufferSize
) {
479 *ResultsDataSize
= BufferSize
;
481 gBS
->FreePool (ConfigResp
);
482 return EFI_BUFFER_TOO_SMALL
;
485 *ResultsDataSize
= BufferSize
;
486 CopyMem (ResultsData
, StrPtr
, BufferSize
);
488 gBS
->FreePool (ConfigResp
);
491 // Prepare <ConfigResp>
493 TmpSize
= StrLen (ResultsData
);
494 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
495 ConfigResp
= AllocateZeroPool (BufferSize
);
496 ASSERT (ConfigResp
!= NULL
);
498 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
499 StrCat (ConfigResp
, L
"&");
500 StrCat (ConfigResp
, ResultsData
);
503 // Update Browser uncommited data
505 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
506 if (EFI_ERROR (Status
)) {
516 Initialize Setup Browser driver.
518 @param ImageHandle The image handle.
519 @param SystemTable The system table.
521 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
522 @return Other value if failed to initialize the Setup Browser module.
528 IN EFI_HANDLE ImageHandle
,
529 IN EFI_SYSTEM_TABLE
*SystemTable
533 EFI_HANDLE HiiDriverHandle
;
534 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
537 // Locate required Hii relative protocols
539 Status
= gBS
->LocateProtocol (
540 &gEfiHiiDatabaseProtocolGuid
,
542 (VOID
**) &mHiiDatabase
544 ASSERT_EFI_ERROR (Status
);
546 Status
= gBS
->LocateProtocol (
547 &gEfiHiiStringProtocolGuid
,
549 (VOID
**) &mHiiString
551 ASSERT_EFI_ERROR (Status
);
553 Status
= gBS
->LocateProtocol (
554 &gEfiHiiConfigRoutingProtocolGuid
,
556 (VOID
**) &mHiiConfigRouting
558 ASSERT_EFI_ERROR (Status
);
561 // Publish our HII data
563 Status
= HiiLibCreateHiiDriverHandle (&HiiDriverHandle
);
564 ASSERT_EFI_ERROR (Status
);
566 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
567 ASSERT (PackageList
!= NULL
);
568 Status
= mHiiDatabase
->NewPackageList (
574 ASSERT_EFI_ERROR (Status
);
577 // Initialize Driver private data
580 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
581 ASSERT (BannerData
!= NULL
);
584 // Install FormBrowser2 protocol
586 mPrivateData
.Handle
= NULL
;
587 Status
= gBS
->InstallProtocolInterface (
588 &mPrivateData
.Handle
,
589 &gEfiFormBrowser2ProtocolGuid
,
590 EFI_NATIVE_INTERFACE
,
591 &mPrivateData
.FormBrowser2
593 ASSERT_EFI_ERROR (Status
);
596 // Install Print protocol
598 Status
= gBS
->InstallProtocolInterface (
599 &mPrivateData
.Handle
,
600 &gEfiPrintProtocolGuid
,
601 EFI_NATIVE_INTERFACE
,
610 Create a new string in HII Package List.
612 @param String The String to be added
613 @param HiiHandle The package list in the HII database to insert the
616 @return The output string.
622 IN EFI_HII_HANDLE HiiHandle
625 EFI_STRING_ID StringId
;
629 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
630 ASSERT_EFI_ERROR (Status
);
637 Delete a string from HII Package List.
639 @param StringId Id of the string in HII database.
640 @param HiiHandle The HII package list handle.
642 @retval EFI_SUCCESS The string was deleted successfully.
647 IN EFI_STRING_ID StringId
,
648 IN EFI_HII_HANDLE HiiHandle
653 NullChar
= CHAR_NULL
;
654 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
659 Get the string based on the StringId and HII Package List Handle.
661 @param Token The String's ID.
662 @param HiiHandle The package list in the HII database to search for
663 the specified string.
665 @return The output string.
670 IN EFI_STRING_ID Token
,
671 IN EFI_HII_HANDLE HiiHandle
679 // Set default string size assumption at no more than 256 bytes
681 BufferLength
= 0x100;
682 String
= AllocateZeroPool (BufferLength
);
683 ASSERT (String
!= NULL
);
685 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
687 if (Status
== EFI_BUFFER_TOO_SMALL
) {
688 gBS
->FreePool (String
);
689 String
= AllocateZeroPool (BufferLength
);
690 ASSERT (String
!= NULL
);
692 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
694 ASSERT_EFI_ERROR (Status
);
701 Allocate new memory and then copy the Unicode string Source to Destination.
703 @param Dest Location to copy string
704 @param Src String to copy
709 IN OUT CHAR16
**Dest
,
713 SafeFreePool (*Dest
);
714 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
715 ASSERT (*Dest
!= NULL
);
720 Allocate new memory and concatinate Source on the end of Destination.
722 @param Dest String to added to the end of.
723 @param Src String to concatinate.
728 IN OUT CHAR16
**Dest
,
736 NewStringCpy (Dest
, Src
);
740 TmpSize
= StrSize (*Dest
);
741 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
742 ASSERT (NewString
!= NULL
);
744 StrCpy (NewString
, *Dest
);
745 StrCat (NewString
, Src
);
747 gBS
->FreePool (*Dest
);
753 Synchronize Storage's Edit copy to Shadow copy.
755 @param Storage The Storage to be synchronized.
760 IN FORMSET_STORAGE
*Storage
764 NAME_VALUE_NODE
*Node
;
766 switch (Storage
->Type
) {
767 case EFI_HII_VARSTORE_BUFFER
:
768 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
771 case EFI_HII_VARSTORE_NAME_VALUE
:
772 Link
= GetFirstNode (&Storage
->NameValueListHead
);
773 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
774 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
776 NewStringCpy (&Node
->Value
, Node
->EditValue
);
778 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
782 case EFI_HII_VARSTORE_EFI_VARIABLE
:
790 Get Value for given Name from a NameValue Storage.
792 @param Storage The NameValue Storage.
793 @param Name The Name.
794 @param Value The retured Value.
796 @retval EFI_SUCCESS Value found for given Name.
797 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
802 IN FORMSET_STORAGE
*Storage
,
804 IN OUT CHAR16
**Value
808 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 NewStringCpy (Value
, Node
->EditValue
);
821 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
824 return EFI_NOT_FOUND
;
829 Set Value of given Name in a NameValue Storage.
831 @param Storage The NameValue Storage.
832 @param Name The Name.
833 @param Value The Value to set.
835 @retval EFI_SUCCESS Value found for given Name.
836 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
841 IN FORMSET_STORAGE
*Storage
,
847 NAME_VALUE_NODE
*Node
;
849 Link
= GetFirstNode (&Storage
->NameValueListHead
);
850 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
851 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
853 if (StrCmp (Name
, Node
->Name
) == 0) {
854 SafeFreePool (Node
->EditValue
);
855 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
856 ASSERT (Node
->EditValue
!= NULL
);
860 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
863 return EFI_NOT_FOUND
;
868 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
870 @param Storage The Storage to be conveted.
871 @param ConfigResp The returned <ConfigResp>.
873 @retval EFI_SUCCESS Convert success.
874 @retval EFI_INVALID_PARAMETER Incorrect storage type.
878 StorageToConfigResp (
879 IN FORMSET_STORAGE
*Storage
,
880 IN CHAR16
**ConfigResp
886 NAME_VALUE_NODE
*Node
;
888 Status
= EFI_SUCCESS
;
890 switch (Storage
->Type
) {
891 case EFI_HII_VARSTORE_BUFFER
:
892 Status
= mHiiConfigRouting
->BlockToConfig (
894 Storage
->ConfigRequest
,
902 case EFI_HII_VARSTORE_NAME_VALUE
:
904 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
906 Link
= GetFirstNode (&Storage
->NameValueListHead
);
907 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
908 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
910 NewStringCat (ConfigResp
, L
"&");
911 NewStringCat (ConfigResp
, Node
->Name
);
912 NewStringCat (ConfigResp
, L
"=");
913 NewStringCat (ConfigResp
, Node
->EditValue
);
915 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
919 case EFI_HII_VARSTORE_EFI_VARIABLE
:
921 Status
= EFI_INVALID_PARAMETER
;
930 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
932 @param Storage The Storage to receive the settings.
933 @param ConfigResp The <ConfigResp> to be converted.
935 @retval EFI_SUCCESS Convert success.
936 @retval EFI_INVALID_PARAMETER Incorrect storage type.
940 ConfigRespToStorage (
941 IN FORMSET_STORAGE
*Storage
,
942 IN CHAR16
*ConfigResp
952 Status
= EFI_SUCCESS
;
954 switch (Storage
->Type
) {
955 case EFI_HII_VARSTORE_BUFFER
:
956 BufferSize
= Storage
->Size
;
957 Status
= mHiiConfigRouting
->ConfigToBlock (
966 case EFI_HII_VARSTORE_NAME_VALUE
:
967 StrPtr
= StrStr (ConfigResp
, L
"&");
968 while (StrPtr
!= NULL
) {
974 StrPtr
= StrStr (StrPtr
, L
"=");
975 if (StrPtr
== NULL
) {
985 StrPtr
= StrStr (StrPtr
, L
"&");
986 if (StrPtr
!= NULL
) {
989 SetValueByName (Storage
, Name
, Value
);
993 case EFI_HII_VARSTORE_EFI_VARIABLE
:
995 Status
= EFI_INVALID_PARAMETER
;
1004 Get Question's current Value.
1006 @param FormSet FormSet data structure.
1007 @param Form Form data structure.
1008 @param Question Question to be initialized.
1009 @param Cached TRUE: get from Edit copy FALSE: get from original
1012 @retval EFI_SUCCESS The function completed successfully.
1017 IN FORM_BROWSER_FORMSET
*FormSet
,
1018 IN FORM_BROWSER_FORM
*Form
,
1019 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1029 FORMSET_STORAGE
*Storage
;
1030 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1031 CHAR16
*ConfigRequest
;
1036 BOOLEAN IsBufferStorage
;
1039 Status
= EFI_SUCCESS
;
1042 // Statement don't have storage, skip them
1044 if (Question
->QuestionId
== 0) {
1049 // Question value is provided by an Expression, evaluate it
1051 if (Question
->ValueExpression
!= NULL
) {
1052 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1053 if (!EFI_ERROR (Status
)) {
1054 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1060 // Question value is provided by RTC
1062 Storage
= Question
->Storage
;
1063 QuestionValue
= &Question
->HiiValue
.Value
;
1064 if (Storage
== NULL
) {
1066 // It's a Question without storage, or RTC date/time
1068 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1070 // Date and time define the same Flags bit
1072 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1073 case QF_DATE_STORAGE_TIME
:
1074 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1077 case QF_DATE_STORAGE_WAKEUP
:
1078 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1081 case QF_DATE_STORAGE_NORMAL
:
1084 // For date/time without storage
1089 if (EFI_ERROR (Status
)) {
1093 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1094 QuestionValue
->date
.Year
= EfiTime
.Year
;
1095 QuestionValue
->date
.Month
= EfiTime
.Month
;
1096 QuestionValue
->date
.Day
= EfiTime
.Day
;
1098 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1099 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1100 QuestionValue
->time
.Second
= EfiTime
.Second
;
1108 // Question value is provided by EFI variable
1110 StorageWidth
= Question
->StorageWidth
;
1111 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1112 if (Question
->BufferValue
!= NULL
) {
1113 Dst
= Question
->BufferValue
;
1115 Dst
= (UINT8
*) QuestionValue
;
1118 Status
= gRT
->GetVariable (
1119 Question
->VariableName
,
1126 // Always return success, even this EFI variable doesn't exist
1132 // Question Value is provided by Buffer Storage or NameValue Storage
1134 if (Question
->BufferValue
!= NULL
) {
1136 // This Question is password or orderedlist
1138 Dst
= Question
->BufferValue
;
1141 // Other type of Questions
1143 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1146 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1147 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1149 if (IsBufferStorage
) {
1151 // Copy from storage Edit buffer
1153 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1155 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1156 if (EFI_ERROR (Status
)) {
1162 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1164 Length
= StorageWidth
+ sizeof (CHAR16
);
1165 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1167 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1170 gBS
->FreePool (Value
);
1174 // Request current settings from Configuration Driver
1176 if (FormSet
->ConfigAccess
== NULL
) {
1177 return EFI_NOT_FOUND
;
1181 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1182 // <ConfigHdr> + "&" + <VariableName>
1184 if (IsBufferStorage
) {
1185 Length
= StrLen (Storage
->ConfigHdr
);
1186 Length
+= StrLen (Question
->BlockName
);
1188 Length
= StrLen (Storage
->ConfigHdr
);
1189 Length
+= StrLen (Question
->VariableName
) + 1;
1191 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1192 ASSERT (ConfigRequest
!= NULL
);
1194 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1195 if (IsBufferStorage
) {
1196 StrCat (ConfigRequest
, Question
->BlockName
);
1198 StrCat (ConfigRequest
, L
"&");
1199 StrCat (ConfigRequest
, Question
->VariableName
);
1202 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1203 FormSet
->ConfigAccess
,
1208 if (EFI_ERROR (Status
)) {
1213 // Skip <ConfigRequest>
1215 Value
= Result
+ Length
;
1216 if (IsBufferStorage
) {
1222 if (*Value
!= '=') {
1223 gBS
->FreePool (Result
);
1224 return EFI_NOT_FOUND
;
1227 // Skip '=', point to value
1230 if (!IsBufferStorage
&& IsString
) {
1232 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1234 Length
= StorageWidth
+ sizeof (CHAR16
);
1235 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1237 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1238 if (EFI_ERROR (Status
)) {
1239 gBS
->FreePool (Result
);
1245 // Synchronize Edit Buffer
1247 if (IsBufferStorage
) {
1248 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1250 SetValueByName (Storage
, Question
->VariableName
, Value
);
1252 gBS
->FreePool (Result
);
1260 Save Question Value to edit copy(cached) or Storage(uncached).
1262 @param FormSet FormSet data structure.
1263 @param Form Form data structure.
1264 @param Question Pointer to the Question.
1265 @param Cached TRUE: set to Edit copy FALSE: set to original
1268 @retval EFI_SUCCESS The function completed successfully.
1273 IN FORM_BROWSER_FORMSET
*FormSet
,
1274 IN FORM_BROWSER_FORM
*Form
,
1275 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1286 FORMSET_STORAGE
*Storage
;
1287 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1292 BOOLEAN IsBufferStorage
;
1295 Status
= EFI_SUCCESS
;
1298 // Statement don't have storage, skip them
1300 if (Question
->QuestionId
== 0) {
1305 // If Question value is provided by an Expression, then it is read only
1307 if (Question
->ValueExpression
!= NULL
) {
1312 // Question value is provided by RTC
1314 Storage
= Question
->Storage
;
1315 QuestionValue
= &Question
->HiiValue
.Value
;
1316 if (Storage
== NULL
) {
1318 // It's a Question without storage, or RTC date/time
1320 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1322 // Date and time define the same Flags bit
1324 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1325 case QF_DATE_STORAGE_TIME
:
1326 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1329 case QF_DATE_STORAGE_WAKEUP
:
1330 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1333 case QF_DATE_STORAGE_NORMAL
:
1336 // For date/time without storage
1341 if (EFI_ERROR (Status
)) {
1345 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1346 EfiTime
.Year
= QuestionValue
->date
.Year
;
1347 EfiTime
.Month
= QuestionValue
->date
.Month
;
1348 EfiTime
.Day
= QuestionValue
->date
.Day
;
1350 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1351 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1352 EfiTime
.Second
= QuestionValue
->time
.Second
;
1355 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1356 Status
= gRT
->SetTime (&EfiTime
);
1358 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1366 // Question value is provided by EFI variable
1368 StorageWidth
= Question
->StorageWidth
;
1369 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1370 if (Question
->BufferValue
!= NULL
) {
1371 Src
= Question
->BufferValue
;
1373 Src
= (UINT8
*) QuestionValue
;
1376 Status
= gRT
->SetVariable (
1377 Question
->VariableName
,
1379 Storage
->Attributes
,
1387 // Question Value is provided by Buffer Storage or NameValue Storage
1389 if (Question
->BufferValue
!= NULL
) {
1390 Src
= Question
->BufferValue
;
1392 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1395 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1396 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1397 if (IsBufferStorage
) {
1399 // Copy to storage edit buffer
1401 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1405 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1408 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1409 Value
= AllocateZeroPool (BufferLen
);
1410 ASSERT (Value
!= NULL
);
1411 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1412 ASSERT_EFI_ERROR (Status
);
1414 BufferLen
= StorageWidth
* 2 + 1;
1415 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1416 ASSERT (Value
!= NULL
);
1417 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1421 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1422 gBS
->FreePool (Value
);
1427 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1428 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1430 if (IsBufferStorage
) {
1431 Length
= StrLen (Question
->BlockName
) + 7;
1433 Length
= StrLen (Question
->VariableName
) + 2;
1435 if (!IsBufferStorage
&& IsString
) {
1436 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1438 Length
+= (StorageWidth
* 2);
1440 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1441 ASSERT (ConfigResp
!= NULL
);
1443 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1444 if (IsBufferStorage
) {
1445 StrCat (ConfigResp
, Question
->BlockName
);
1446 StrCat (ConfigResp
, L
"&VALUE=");
1448 StrCat (ConfigResp
, L
"&");
1449 StrCat (ConfigResp
, Question
->VariableName
);
1450 StrCat (ConfigResp
, L
"=");
1453 Value
= ConfigResp
+ StrLen (ConfigResp
);
1454 if (!IsBufferStorage
&& IsString
) {
1456 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1458 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1459 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1460 ASSERT_EFI_ERROR (Status
);
1462 BufferLen
= StorageWidth
* 2 + 1;
1463 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1468 // Submit Question Value to Configuration Driver
1470 if (FormSet
->ConfigAccess
!= NULL
) {
1471 Status
= FormSet
->ConfigAccess
->RouteConfig (
1472 FormSet
->ConfigAccess
,
1476 if (EFI_ERROR (Status
)) {
1477 gBS
->FreePool (ConfigResp
);
1481 gBS
->FreePool (ConfigResp
);
1484 // Synchronize shadow Buffer
1486 SynchronizeStorage (Storage
);
1494 Perform inconsistent check for a Form.
1496 @param FormSet FormSet data structure.
1497 @param Form Form data structure.
1498 @param Question The Question to be validated.
1499 @param Type Validation type: InConsistent or NoSubmit
1501 @retval EFI_SUCCESS Form validation pass.
1502 @retval other Form validation failed.
1507 IN FORM_BROWSER_FORMSET
*FormSet
,
1508 IN FORM_BROWSER_FORM
*Form
,
1509 IN FORM_BROWSER_STATEMENT
*Question
,
1515 LIST_ENTRY
*ListHead
;
1518 FORM_EXPRESSION
*Expression
;
1520 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1521 ListHead
= &Question
->InconsistentListHead
;
1522 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1523 ListHead
= &Question
->NoSubmitListHead
;
1525 return EFI_UNSUPPORTED
;
1528 Link
= GetFirstNode (ListHead
);
1529 while (!IsNull (ListHead
, Link
)) {
1530 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1533 // Evaluate the expression
1535 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1536 if (EFI_ERROR (Status
)) {
1540 if (Expression
->Result
.Value
.b
) {
1542 // Condition meet, show up error message
1544 if (Expression
->Error
!= 0) {
1545 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1547 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1548 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1549 gBS
->FreePool (PopUp
);
1552 return EFI_NOT_READY
;
1555 Link
= GetNextNode (ListHead
, Link
);
1563 Perform NoSubmit check for a Form.
1565 @param FormSet FormSet data structure.
1566 @param Form Form data structure.
1568 @retval EFI_SUCCESS Form validation pass.
1569 @retval other Form validation failed.
1574 IN FORM_BROWSER_FORMSET
*FormSet
,
1575 IN FORM_BROWSER_FORM
*Form
1580 FORM_BROWSER_STATEMENT
*Question
;
1582 Link
= GetFirstNode (&Form
->StatementListHead
);
1583 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1584 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1586 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1587 if (EFI_ERROR (Status
)) {
1591 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1601 @param FormSet FormSet data structure.
1602 @param Form Form data structure.
1604 @retval EFI_SUCCESS The function completed successfully.
1609 IN FORM_BROWSER_FORMSET
*FormSet
,
1610 IN FORM_BROWSER_FORM
*Form
1615 EFI_STRING ConfigResp
;
1616 EFI_STRING Progress
;
1617 FORMSET_STORAGE
*Storage
;
1620 // Validate the Form by NoSubmit check
1622 Status
= NoSubmitCheck (FormSet
, Form
);
1623 if (EFI_ERROR (Status
)) {
1628 // Submit Buffer storage or Name/Value storage
1630 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1631 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1632 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1633 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1635 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1640 // Skip if there is no RequestElement
1642 if (Storage
->ElementCount
== 0) {
1647 // Prepare <ConfigResp>
1649 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1650 if (EFI_ERROR (Status
)) {
1655 // Send <ConfigResp> to Configuration Driver
1657 if (FormSet
->ConfigAccess
!= NULL
) {
1658 Status
= FormSet
->ConfigAccess
->RouteConfig (
1659 FormSet
->ConfigAccess
,
1663 if (EFI_ERROR (Status
)) {
1664 gBS
->FreePool (ConfigResp
);
1668 gBS
->FreePool (ConfigResp
);
1671 // Config success, update storage shadow Buffer
1673 SynchronizeStorage (Storage
);
1676 gNvUpdateRequired
= FALSE
;
1683 Reset Question to its default value.
1685 @param FormSet The form set.
1686 @param Form The form.
1687 @param Question The question.
1688 @param DefaultId The Class of the default.
1690 @retval EFI_SUCCESS Question is reset to default value.
1694 GetQuestionDefault (
1695 IN FORM_BROWSER_FORMSET
*FormSet
,
1696 IN FORM_BROWSER_FORM
*Form
,
1697 IN FORM_BROWSER_STATEMENT
*Question
,
1703 QUESTION_DEFAULT
*Default
;
1704 QUESTION_OPTION
*Option
;
1705 EFI_HII_VALUE
*HiiValue
;
1708 Status
= EFI_SUCCESS
;
1711 // Statement don't have storage, skip them
1713 if (Question
->QuestionId
== 0) {
1718 // There are three ways to specify default value for a Question:
1719 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1720 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1721 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1723 HiiValue
= &Question
->HiiValue
;
1726 // EFI_IFR_DEFAULT has highest priority
1728 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1729 Link
= GetFirstNode (&Question
->DefaultListHead
);
1730 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1731 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1733 if (Default
->DefaultId
== DefaultId
) {
1734 if (Default
->ValueExpression
!= NULL
) {
1736 // Default is provided by an Expression, evaluate it
1738 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1739 if (EFI_ERROR (Status
)) {
1743 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1746 // Default value is embedded in EFI_IFR_DEFAULT
1748 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1754 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1759 // EFI_ONE_OF_OPTION
1761 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1762 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1764 // OneOfOption could only provide Standard and Manufacturing default
1766 Link
= GetFirstNode (&Question
->OptionListHead
);
1767 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1768 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1770 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1771 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1773 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1778 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1784 // EFI_IFR_CHECKBOX - lowest priority
1786 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1787 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1789 // Checkbox could only provide Standard and Manufacturing default
1791 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1792 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1794 HiiValue
->Value
.b
= TRUE
;
1796 HiiValue
->Value
.b
= FALSE
;
1804 // For Questions without default
1806 switch (Question
->Operand
) {
1807 case EFI_IFR_NUMERIC_OP
:
1809 // Take minimal value as numeric's default value
1811 HiiValue
->Value
.u64
= Question
->Minimum
;
1814 case EFI_IFR_ONE_OF_OP
:
1816 // Take first oneof option as oneof's default value
1818 Link
= GetFirstNode (&Question
->OptionListHead
);
1819 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1820 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1821 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1825 case EFI_IFR_ORDERED_LIST_OP
:
1827 // Take option sequence in IFR as ordered list's default value
1830 Link
= GetFirstNode (&Question
->OptionListHead
);
1831 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1832 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1834 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1837 if (Index
>= Question
->MaxContainers
) {
1841 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1846 Status
= EFI_NOT_FOUND
;
1855 Reset Questions in a Form to their default value.
1857 @param FormSet FormSet data structure.
1858 @param Form The Form which to be reset.
1859 @param DefaultId The Class of the default.
1861 @retval EFI_SUCCESS The function completed successfully.
1865 ExtractFormDefault (
1866 IN FORM_BROWSER_FORMSET
*FormSet
,
1867 IN FORM_BROWSER_FORM
*Form
,
1873 FORM_BROWSER_STATEMENT
*Question
;
1875 Link
= GetFirstNode (&Form
->StatementListHead
);
1876 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1877 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1878 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1881 // Reset Question to its default value
1883 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1884 if (EFI_ERROR (Status
)) {
1889 // Synchronize Buffer storage's Edit buffer
1891 if ((Question
->Storage
!= NULL
) &&
1892 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1893 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1902 Initialize Question's Edit copy from Storage.
1904 @param FormSet FormSet data structure.
1905 @param Form Form data structure.
1907 @retval EFI_SUCCESS The function completed successfully.
1912 IN FORM_BROWSER_FORMSET
*FormSet
,
1913 IN FORM_BROWSER_FORM
*Form
1918 FORM_BROWSER_STATEMENT
*Question
;
1920 Link
= GetFirstNode (&Form
->StatementListHead
);
1921 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1922 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1925 // Initialize local copy of Value for each Question
1927 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1928 if (EFI_ERROR (Status
)) {
1932 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1940 Fill storage's edit copy with settings requested from Configuration Driver.
1942 @param FormSet FormSet data structure.
1943 @param Storage Buffer Storage.
1945 @retval EFI_SUCCESS The function completed successfully.
1950 IN FORM_BROWSER_FORMSET
*FormSet
,
1951 IN FORMSET_STORAGE
*Storage
1955 EFI_STRING Progress
;
1959 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1963 if (FormSet
->ConfigAccess
== NULL
) {
1964 return EFI_NOT_FOUND
;
1967 if (Storage
->ElementCount
== 0) {
1969 // Skip if there is no RequestElement
1975 // Request current settings from Configuration Driver
1977 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1978 FormSet
->ConfigAccess
,
1979 Storage
->ConfigRequest
,
1983 if (EFI_ERROR (Status
)) {
1988 // Convert Result from <ConfigAltResp> to <ConfigResp>
1990 StrPtr
= StrStr (Result
, L
"ALTCFG");
1991 if (StrPtr
!= NULL
) {
1995 Status
= ConfigRespToStorage (Storage
, Result
);
1996 gBS
->FreePool (Result
);
2002 Get current setting of Questions.
2004 @param FormSet FormSet data structure.
2006 @retval EFI_SUCCESS The function completed successfully.
2010 InitializeCurrentSetting (
2011 IN OUT FORM_BROWSER_FORMSET
*FormSet
2015 FORMSET_STORAGE
*Storage
;
2016 FORM_BROWSER_FORM
*Form
;
2020 // Extract default from IFR binary
2022 Link
= GetFirstNode (&FormSet
->FormListHead
);
2023 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2024 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2026 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2028 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2032 // Request current settings from Configuration Driver
2034 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2035 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2036 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2038 Status
= LoadStorage (FormSet
, Storage
);
2041 // Now Edit Buffer is filled with default values(lower priority) and current
2042 // settings(higher priority), sychronize it to shadow Buffer
2044 if (!EFI_ERROR (Status
)) {
2045 SynchronizeStorage (Storage
);
2048 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2056 Fetch the Ifr binary data of a FormSet.
2058 @param Handle PackageList Handle
2059 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2060 GUID), take the first FormSet found in package
2062 @param BinaryLength The length of the FormSet IFR binary.
2063 @param BinaryData The buffer designed to receive the FormSet.
2065 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2066 BufferLength was updated.
2067 @retval EFI_INVALID_PARAMETER The handle is unknown.
2068 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2069 be found with the requested FormId.
2074 IN EFI_HII_HANDLE Handle
,
2075 IN OUT EFI_GUID
*FormSetGuid
,
2076 OUT UINTN
*BinaryLength
,
2077 OUT UINT8
**BinaryData
2081 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2087 BOOLEAN ReturnDefault
;
2088 UINT32 PackageListLength
;
2089 EFI_HII_PACKAGE_HEADER PackageHeader
;
2093 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2096 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2098 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2099 ReturnDefault
= TRUE
;
2101 ReturnDefault
= FALSE
;
2105 // Get HII PackageList
2108 HiiPackageList
= NULL
;
2109 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2110 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2111 HiiPackageList
= AllocatePool (BufferSize
);
2112 ASSERT (HiiPackageList
!= NULL
);
2114 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2116 if (EFI_ERROR (Status
)) {
2121 // Get Form package from this HII package List
2123 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2125 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2127 while (Offset
< PackageListLength
) {
2128 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2129 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2131 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORM
) {
2133 // Search FormSet in this Form Package
2135 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2136 while (Offset2
< PackageHeader
.Length
) {
2137 OpCodeData
= Package
+ Offset2
;
2139 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2141 // Check whether return default FormSet
2143 if (ReturnDefault
) {
2148 // FormSet GUID is specified, check it
2150 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2155 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2158 if (Offset2
< PackageHeader
.Length
) {
2160 // Target formset found
2166 Offset
+= PackageHeader
.Length
;
2169 if (Offset
>= PackageListLength
) {
2171 // Form package not found in this Package List
2173 gBS
->FreePool (HiiPackageList
);
2174 return EFI_NOT_FOUND
;
2177 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2179 // Return the default FormSet GUID
2181 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2185 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2186 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2187 // of the Form Package.
2189 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2190 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2192 gBS
->FreePool (HiiPackageList
);
2194 if (*BinaryData
== NULL
) {
2195 return EFI_OUT_OF_RESOURCES
;
2203 Initialize the internal data structure of a FormSet.
2205 @param Handle PackageList Handle
2206 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2207 GUID), take the first FormSet found in package
2209 @param FormSet FormSet data structure.
2211 @retval EFI_SUCCESS The function completed successfully.
2212 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2217 IN EFI_HII_HANDLE Handle
,
2218 IN OUT EFI_GUID
*FormSetGuid
,
2219 OUT FORM_BROWSER_FORMSET
*FormSet
2223 EFI_HANDLE DriverHandle
;
2226 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2227 if (EFI_ERROR (Status
)) {
2231 FormSet
->HiiHandle
= Handle
;
2232 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2235 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2237 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2238 if (EFI_ERROR (Status
)) {
2241 FormSet
->DriverHandle
= DriverHandle
;
2242 Status
= gBS
->HandleProtocol (
2244 &gEfiHiiConfigAccessProtocolGuid
,
2245 (VOID
**) &FormSet
->ConfigAccess
2247 if (EFI_ERROR (Status
)) {
2249 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2250 // list, then there will be no configuration action required
2252 FormSet
->ConfigAccess
= NULL
;
2256 // Parse the IFR binary OpCodes
2258 Status
= ParseOpCodes (FormSet
);
2259 if (EFI_ERROR (Status
)) {
2263 gClassOfVfr
= FormSet
->SubClass
;
2264 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2265 FrontPageHandle
= FormSet
->HiiHandle
;
2269 // Match GUID to find out the function key setting. If match fail, use the default setting.
2271 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2272 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2274 // Update the function key setting.
2276 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2278 // Function key prompt can not be displayed if the function key has been disabled.
2280 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2281 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2284 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2285 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2288 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2289 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2292 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2293 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);