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
;
216 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
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
277 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
279 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
280 if (EFI_ERROR (Status
)) {
284 // Set console control to text mode.
286 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);
288 for (Index
= 0; Index
< HandleCount
; Index
++) {
289 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
290 ASSERT (Selection
!= NULL
);
292 Selection
->Handle
= Handles
[Index
];
293 if (FormSetGuid
!= NULL
) {
294 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
295 Selection
->FormId
= FormId
;
299 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
300 ASSERT (FormSet
!= NULL
);
303 // Initialize internal data structures of FormSet
305 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
306 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
307 DestroyFormSet (FormSet
);
310 Selection
->FormSet
= FormSet
;
313 // Initialize current settings of Questions in this FormSet
315 Status
= InitializeCurrentSetting (FormSet
);
316 if (EFI_ERROR (Status
)) {
317 DestroyFormSet (FormSet
);
322 // Display this formset
324 gCurrentSelection
= Selection
;
326 Status
= SetupBrowser (Selection
);
328 gCurrentSelection
= NULL
;
329 DestroyFormSet (FormSet
);
331 if (EFI_ERROR (Status
)) {
335 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
337 FreePool (Selection
);
340 if (ActionRequest
!= NULL
) {
341 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
342 if (gResetRequired
) {
343 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
347 FreeBrowserStrings ();
349 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
350 gST
->ConOut
->ClearScreen (gST
->ConOut
);
357 This function is called by a callback handler to retrieve uncommitted state
358 data from the browser.
360 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
362 @param ResultsDataSize A pointer to the size of the buffer associated
364 @param ResultsData A string returned from an IFR browser or
365 equivalent. The results string will have no
366 routing information in them.
367 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
368 (if RetrieveData = TRUE) data from the uncommitted
369 browser state information or set (if RetrieveData
370 = FALSE) data in the uncommitted browser state
372 @param VariableGuid An optional field to indicate the target variable
374 @param VariableName An optional field to indicate the target
375 human-readable variable name.
377 @retval EFI_SUCCESS The results have been distributed or are awaiting
379 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
380 contain the results data.
386 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
387 IN OUT UINTN
*ResultsDataSize
,
388 IN OUT EFI_STRING ResultsData
,
389 IN BOOLEAN RetrieveData
,
390 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
391 IN CONST CHAR16
*VariableName OPTIONAL
396 FORMSET_STORAGE
*Storage
;
397 FORM_BROWSER_FORMSET
*FormSet
;
404 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
405 return EFI_INVALID_PARAMETER
;
408 if (gCurrentSelection
== NULL
) {
409 return EFI_NOT_READY
;
414 FormSet
= gCurrentSelection
->FormSet
;
417 // Find target storage
419 Link
= GetFirstNode (&FormSet
->StorageListHead
);
420 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
421 return EFI_UNSUPPORTED
;
424 if (VariableGuid
!= NULL
) {
426 // Try to find target storage
429 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
430 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
431 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
433 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
434 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
436 // Buffer storage require both GUID and Name
438 if (VariableName
== NULL
) {
439 return EFI_NOT_FOUND
;
442 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
452 return EFI_NOT_FOUND
;
456 // GUID/Name is not specified, take the first storage in FormSet
458 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
463 // Skip if there is no RequestElement
465 if (Storage
->ElementCount
== 0) {
470 // Generate <ConfigResp>
472 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
473 if (EFI_ERROR (Status
)) {
478 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
480 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
482 BufferSize
= StrSize (StrPtr
);
483 if (*ResultsDataSize
< BufferSize
) {
484 *ResultsDataSize
= BufferSize
;
486 FreePool (ConfigResp
);
487 return EFI_BUFFER_TOO_SMALL
;
490 *ResultsDataSize
= BufferSize
;
491 CopyMem (ResultsData
, StrPtr
, BufferSize
);
493 FreePool (ConfigResp
);
496 // Prepare <ConfigResp>
498 TmpSize
= StrLen (ResultsData
);
499 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
500 ConfigResp
= AllocateZeroPool (BufferSize
);
501 ASSERT (ConfigResp
!= NULL
);
503 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
504 StrCat (ConfigResp
, L
"&");
505 StrCat (ConfigResp
, ResultsData
);
508 // Update Browser uncommited data
510 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
511 if (EFI_ERROR (Status
)) {
521 Initialize Setup Browser driver.
523 @param ImageHandle The image handle.
524 @param SystemTable The system table.
526 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
527 @return Other value if failed to initialize the Setup Browser module.
533 IN EFI_HANDLE ImageHandle
,
534 IN EFI_SYSTEM_TABLE
*SystemTable
538 EFI_HANDLE HiiDriverHandle
;
539 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
542 // Locate required Hii relative protocols
544 Status
= gBS
->LocateProtocol (
545 &gEfiHiiDatabaseProtocolGuid
,
547 (VOID
**) &mHiiDatabase
549 ASSERT_EFI_ERROR (Status
);
551 Status
= gBS
->LocateProtocol (
552 &gEfiHiiStringProtocolGuid
,
554 (VOID
**) &mHiiString
556 ASSERT_EFI_ERROR (Status
);
558 Status
= gBS
->LocateProtocol (
559 &gEfiHiiConfigRoutingProtocolGuid
,
561 (VOID
**) &mHiiConfigRouting
563 ASSERT_EFI_ERROR (Status
);
566 // Publish our HII data
568 Status
= HiiLibCreateHiiDriverHandle (&HiiDriverHandle
);
569 ASSERT_EFI_ERROR (Status
);
571 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
572 ASSERT (PackageList
!= NULL
);
573 Status
= mHiiDatabase
->NewPackageList (
579 ASSERT_EFI_ERROR (Status
);
582 // Initialize Driver private data
584 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
585 ASSERT (BannerData
!= NULL
);
588 // Install FormBrowser2 protocol
590 mPrivateData
.Handle
= NULL
;
591 Status
= gBS
->InstallProtocolInterface (
592 &mPrivateData
.Handle
,
593 &gEfiFormBrowser2ProtocolGuid
,
594 EFI_NATIVE_INTERFACE
,
595 &mPrivateData
.FormBrowser2
597 ASSERT_EFI_ERROR (Status
);
604 Create a new string in HII Package List.
606 @param String The String to be added
607 @param HiiHandle The package list in the HII database to insert the
610 @return The output string.
616 IN EFI_HII_HANDLE HiiHandle
619 EFI_STRING_ID StringId
;
623 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
624 ASSERT_EFI_ERROR (Status
);
631 Delete a string from HII Package List.
633 @param StringId Id of the string in HII database.
634 @param HiiHandle The HII package list handle.
636 @retval EFI_SUCCESS The string was deleted successfully.
641 IN EFI_STRING_ID StringId
,
642 IN EFI_HII_HANDLE HiiHandle
647 NullChar
= CHAR_NULL
;
648 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
653 Get the string based on the StringId and HII Package List Handle.
655 @param Token The String's ID.
656 @param HiiHandle The package list in the HII database to search for
657 the specified string.
659 @return The output string.
664 IN EFI_STRING_ID Token
,
665 IN EFI_HII_HANDLE HiiHandle
673 // Set default string size assumption at no more than 256 bytes
675 BufferLength
= 0x100;
676 String
= AllocateZeroPool (BufferLength
);
677 ASSERT (String
!= NULL
);
679 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
681 if (Status
== EFI_BUFFER_TOO_SMALL
) {
683 String
= AllocateZeroPool (BufferLength
);
684 ASSERT (String
!= NULL
);
686 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
688 ASSERT_EFI_ERROR (Status
);
695 Allocate new memory and then copy the Unicode string Source to Destination.
697 @param Dest Location to copy string
698 @param Src String to copy
703 IN OUT CHAR16
**Dest
,
710 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
711 ASSERT (*Dest
!= NULL
);
716 Allocate new memory and concatinate Source on the end of Destination.
718 @param Dest String to added to the end of.
719 @param Src String to concatinate.
724 IN OUT CHAR16
**Dest
,
732 NewStringCpy (Dest
, Src
);
736 TmpSize
= StrSize (*Dest
);
737 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
738 ASSERT (NewString
!= NULL
);
740 StrCpy (NewString
, *Dest
);
741 StrCat (NewString
, Src
);
749 Synchronize Storage's Edit copy to Shadow copy.
751 @param Storage The Storage to be synchronized.
756 IN FORMSET_STORAGE
*Storage
760 NAME_VALUE_NODE
*Node
;
762 switch (Storage
->Type
) {
763 case EFI_HII_VARSTORE_BUFFER
:
764 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
767 case EFI_HII_VARSTORE_NAME_VALUE
:
768 Link
= GetFirstNode (&Storage
->NameValueListHead
);
769 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
770 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
772 NewStringCpy (&Node
->Value
, Node
->EditValue
);
774 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
778 case EFI_HII_VARSTORE_EFI_VARIABLE
:
786 Get Value for given Name from a NameValue Storage.
788 @param Storage The NameValue Storage.
789 @param Name The Name.
790 @param Value The retured Value.
792 @retval EFI_SUCCESS Value found for given Name.
793 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
798 IN FORMSET_STORAGE
*Storage
,
800 IN OUT CHAR16
**Value
804 NAME_VALUE_NODE
*Node
;
808 Link
= GetFirstNode (&Storage
->NameValueListHead
);
809 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
810 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
812 if (StrCmp (Name
, Node
->Name
) == 0) {
813 NewStringCpy (Value
, Node
->EditValue
);
817 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
820 return EFI_NOT_FOUND
;
825 Set Value of given Name in a NameValue Storage.
827 @param Storage The NameValue Storage.
828 @param Name The Name.
829 @param Value The Value to set.
831 @retval EFI_SUCCESS Value found for given Name.
832 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
837 IN FORMSET_STORAGE
*Storage
,
843 NAME_VALUE_NODE
*Node
;
845 Link
= GetFirstNode (&Storage
->NameValueListHead
);
846 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
847 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
849 if (StrCmp (Name
, Node
->Name
) == 0) {
850 if (Node
->EditValue
!= NULL
) {
851 FreePool (Node
->EditValue
);
853 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
854 ASSERT (Node
->EditValue
!= NULL
);
858 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
861 return EFI_NOT_FOUND
;
866 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
868 @param Storage The Storage to be conveted.
869 @param ConfigResp The returned <ConfigResp>.
871 @retval EFI_SUCCESS Convert success.
872 @retval EFI_INVALID_PARAMETER Incorrect storage type.
876 StorageToConfigResp (
877 IN FORMSET_STORAGE
*Storage
,
878 IN CHAR16
**ConfigResp
884 NAME_VALUE_NODE
*Node
;
886 Status
= EFI_SUCCESS
;
888 switch (Storage
->Type
) {
889 case EFI_HII_VARSTORE_BUFFER
:
890 Status
= mHiiConfigRouting
->BlockToConfig (
892 Storage
->ConfigRequest
,
900 case EFI_HII_VARSTORE_NAME_VALUE
:
902 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
904 Link
= GetFirstNode (&Storage
->NameValueListHead
);
905 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
906 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
908 NewStringCat (ConfigResp
, L
"&");
909 NewStringCat (ConfigResp
, Node
->Name
);
910 NewStringCat (ConfigResp
, L
"=");
911 NewStringCat (ConfigResp
, Node
->EditValue
);
913 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
917 case EFI_HII_VARSTORE_EFI_VARIABLE
:
919 Status
= EFI_INVALID_PARAMETER
;
928 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
930 @param Storage The Storage to receive the settings.
931 @param ConfigResp The <ConfigResp> to be converted.
933 @retval EFI_SUCCESS Convert success.
934 @retval EFI_INVALID_PARAMETER Incorrect storage type.
938 ConfigRespToStorage (
939 IN FORMSET_STORAGE
*Storage
,
940 IN CHAR16
*ConfigResp
950 Status
= EFI_SUCCESS
;
952 switch (Storage
->Type
) {
953 case EFI_HII_VARSTORE_BUFFER
:
954 BufferSize
= Storage
->Size
;
955 Status
= mHiiConfigRouting
->ConfigToBlock (
964 case EFI_HII_VARSTORE_NAME_VALUE
:
965 StrPtr
= StrStr (ConfigResp
, L
"&");
966 while (StrPtr
!= NULL
) {
972 StrPtr
= StrStr (StrPtr
, L
"=");
973 if (StrPtr
== NULL
) {
983 StrPtr
= StrStr (StrPtr
, L
"&");
984 if (StrPtr
!= NULL
) {
987 SetValueByName (Storage
, Name
, Value
);
991 case EFI_HII_VARSTORE_EFI_VARIABLE
:
993 Status
= EFI_INVALID_PARAMETER
;
1002 Get Question's current Value.
1004 @param FormSet FormSet data structure.
1005 @param Form Form data structure.
1006 @param Question Question to be initialized.
1007 @param Cached TRUE: get from Edit copy FALSE: get from original
1010 @retval EFI_SUCCESS The function completed successfully.
1015 IN FORM_BROWSER_FORMSET
*FormSet
,
1016 IN FORM_BROWSER_FORM
*Form
,
1017 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1027 FORMSET_STORAGE
*Storage
;
1028 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1029 CHAR16
*ConfigRequest
;
1035 BOOLEAN IsBufferStorage
;
1038 Status
= EFI_SUCCESS
;
1041 // Statement don't have storage, skip them
1043 if (Question
->QuestionId
== 0) {
1048 // Question value is provided by an Expression, evaluate it
1050 if (Question
->ValueExpression
!= NULL
) {
1051 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1052 if (!EFI_ERROR (Status
)) {
1053 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1059 // Question value is provided by RTC
1061 Storage
= Question
->Storage
;
1062 QuestionValue
= &Question
->HiiValue
.Value
;
1063 if (Storage
== NULL
) {
1065 // It's a Question without storage, or RTC date/time
1067 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1069 // Date and time define the same Flags bit
1071 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1072 case QF_DATE_STORAGE_TIME
:
1073 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1076 case QF_DATE_STORAGE_WAKEUP
:
1077 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1080 case QF_DATE_STORAGE_NORMAL
:
1083 // For date/time without storage
1088 if (EFI_ERROR (Status
)) {
1092 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1093 QuestionValue
->date
.Year
= EfiTime
.Year
;
1094 QuestionValue
->date
.Month
= EfiTime
.Month
;
1095 QuestionValue
->date
.Day
= EfiTime
.Day
;
1097 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1098 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1099 QuestionValue
->time
.Second
= EfiTime
.Second
;
1107 // Question value is provided by EFI variable
1109 StorageWidth
= Question
->StorageWidth
;
1110 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1111 if (Question
->BufferValue
!= NULL
) {
1112 Dst
= Question
->BufferValue
;
1114 Dst
= (UINT8
*) QuestionValue
;
1117 Status
= gRT
->GetVariable (
1118 Question
->VariableName
,
1125 // Always return success, even this EFI variable doesn't exist
1131 // Question Value is provided by Buffer Storage or NameValue Storage
1133 if (Question
->BufferValue
!= NULL
) {
1135 // This Question is password or orderedlist
1137 Dst
= Question
->BufferValue
;
1140 // Other type of Questions
1142 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1145 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1146 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1148 if (IsBufferStorage
) {
1150 // Copy from storage Edit buffer
1152 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1154 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1155 if (EFI_ERROR (Status
)) {
1161 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1163 Length
= StorageWidth
+ sizeof (CHAR16
);
1164 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1166 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1173 // Request current settings from Configuration Driver
1175 if (FormSet
->ConfigAccess
== NULL
) {
1176 return EFI_NOT_FOUND
;
1180 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1181 // <ConfigHdr> + "&" + <VariableName>
1183 if (IsBufferStorage
) {
1184 Length
= StrLen (Storage
->ConfigHdr
);
1185 Length
+= StrLen (Question
->BlockName
);
1187 Length
= StrLen (Storage
->ConfigHdr
);
1188 Length
+= StrLen (Question
->VariableName
) + 1;
1190 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1191 ASSERT (ConfigRequest
!= NULL
);
1193 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1194 if (IsBufferStorage
) {
1195 StrCat (ConfigRequest
, Question
->BlockName
);
1197 StrCat (ConfigRequest
, L
"&");
1198 StrCat (ConfigRequest
, Question
->VariableName
);
1201 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1202 FormSet
->ConfigAccess
,
1207 if (EFI_ERROR (Status
)) {
1212 // Skip <ConfigRequest>
1214 Value
= Result
+ Length
;
1215 if (IsBufferStorage
) {
1221 if (*Value
!= '=') {
1223 return EFI_NOT_FOUND
;
1226 // Skip '=', point to value
1231 // Suppress <AltResp> if any
1234 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1239 if (!IsBufferStorage
&& IsString
) {
1241 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1243 Length
= StorageWidth
+ sizeof (CHAR16
);
1244 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1246 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1247 if (EFI_ERROR (Status
)) {
1254 // Synchronize Edit Buffer
1256 if (IsBufferStorage
) {
1257 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1259 SetValueByName (Storage
, Question
->VariableName
, Value
);
1269 Save Question Value to edit copy(cached) or Storage(uncached).
1271 @param FormSet FormSet data structure.
1272 @param Form Form data structure.
1273 @param Question Pointer to the Question.
1274 @param Cached TRUE: set to Edit copy FALSE: set to original
1277 @retval EFI_SUCCESS The function completed successfully.
1282 IN FORM_BROWSER_FORMSET
*FormSet
,
1283 IN FORM_BROWSER_FORM
*Form
,
1284 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1295 FORMSET_STORAGE
*Storage
;
1296 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1301 BOOLEAN IsBufferStorage
;
1304 Status
= EFI_SUCCESS
;
1307 // Statement don't have storage, skip them
1309 if (Question
->QuestionId
== 0) {
1314 // If Question value is provided by an Expression, then it is read only
1316 if (Question
->ValueExpression
!= NULL
) {
1321 // Question value is provided by RTC
1323 Storage
= Question
->Storage
;
1324 QuestionValue
= &Question
->HiiValue
.Value
;
1325 if (Storage
== NULL
) {
1327 // It's a Question without storage, or RTC date/time
1329 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1331 // Date and time define the same Flags bit
1333 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1334 case QF_DATE_STORAGE_TIME
:
1335 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1338 case QF_DATE_STORAGE_WAKEUP
:
1339 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1342 case QF_DATE_STORAGE_NORMAL
:
1345 // For date/time without storage
1350 if (EFI_ERROR (Status
)) {
1354 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1355 EfiTime
.Year
= QuestionValue
->date
.Year
;
1356 EfiTime
.Month
= QuestionValue
->date
.Month
;
1357 EfiTime
.Day
= QuestionValue
->date
.Day
;
1359 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1360 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1361 EfiTime
.Second
= QuestionValue
->time
.Second
;
1364 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1365 Status
= gRT
->SetTime (&EfiTime
);
1367 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1375 // Question value is provided by EFI variable
1377 StorageWidth
= Question
->StorageWidth
;
1378 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1379 if (Question
->BufferValue
!= NULL
) {
1380 Src
= Question
->BufferValue
;
1382 Src
= (UINT8
*) QuestionValue
;
1385 Status
= gRT
->SetVariable (
1386 Question
->VariableName
,
1388 Storage
->Attributes
,
1396 // Question Value is provided by Buffer Storage or NameValue Storage
1398 if (Question
->BufferValue
!= NULL
) {
1399 Src
= Question
->BufferValue
;
1401 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1404 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1405 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1406 if (IsBufferStorage
) {
1408 // Copy to storage edit buffer
1410 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1414 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1417 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1418 Value
= AllocateZeroPool (BufferLen
);
1419 ASSERT (Value
!= NULL
);
1420 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1421 ASSERT_EFI_ERROR (Status
);
1423 BufferLen
= StorageWidth
* 2 + 1;
1424 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1425 ASSERT (Value
!= NULL
);
1426 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1430 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1436 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1437 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1439 if (IsBufferStorage
) {
1440 Length
= StrLen (Question
->BlockName
) + 7;
1442 Length
= StrLen (Question
->VariableName
) + 2;
1444 if (!IsBufferStorage
&& IsString
) {
1445 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1447 Length
+= (StorageWidth
* 2);
1449 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1450 ASSERT (ConfigResp
!= NULL
);
1452 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1453 if (IsBufferStorage
) {
1454 StrCat (ConfigResp
, Question
->BlockName
);
1455 StrCat (ConfigResp
, L
"&VALUE=");
1457 StrCat (ConfigResp
, L
"&");
1458 StrCat (ConfigResp
, Question
->VariableName
);
1459 StrCat (ConfigResp
, L
"=");
1462 Value
= ConfigResp
+ StrLen (ConfigResp
);
1463 if (!IsBufferStorage
&& IsString
) {
1465 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1467 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1468 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1469 ASSERT_EFI_ERROR (Status
);
1471 BufferLen
= StorageWidth
* 2 + 1;
1472 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1477 // Submit Question Value to Configuration Driver
1479 if (FormSet
->ConfigAccess
!= NULL
) {
1480 Status
= FormSet
->ConfigAccess
->RouteConfig (
1481 FormSet
->ConfigAccess
,
1485 if (EFI_ERROR (Status
)) {
1486 FreePool (ConfigResp
);
1490 FreePool (ConfigResp
);
1493 // Synchronize shadow Buffer
1495 SynchronizeStorage (Storage
);
1503 Perform inconsistent check for a Form.
1505 @param FormSet FormSet data structure.
1506 @param Form Form data structure.
1507 @param Question The Question to be validated.
1508 @param Type Validation type: InConsistent or NoSubmit
1510 @retval EFI_SUCCESS Form validation pass.
1511 @retval other Form validation failed.
1516 IN FORM_BROWSER_FORMSET
*FormSet
,
1517 IN FORM_BROWSER_FORM
*Form
,
1518 IN FORM_BROWSER_STATEMENT
*Question
,
1524 LIST_ENTRY
*ListHead
;
1527 FORM_EXPRESSION
*Expression
;
1529 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1530 ListHead
= &Question
->InconsistentListHead
;
1531 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1532 ListHead
= &Question
->NoSubmitListHead
;
1534 return EFI_UNSUPPORTED
;
1537 Link
= GetFirstNode (ListHead
);
1538 while (!IsNull (ListHead
, Link
)) {
1539 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1542 // Evaluate the expression
1544 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1545 if (EFI_ERROR (Status
)) {
1549 if (Expression
->Result
.Value
.b
) {
1551 // Condition meet, show up error message
1553 if (Expression
->Error
!= 0) {
1554 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1556 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1557 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1561 return EFI_NOT_READY
;
1564 Link
= GetNextNode (ListHead
, Link
);
1572 Perform NoSubmit check for a Form.
1574 @param FormSet FormSet data structure.
1575 @param Form Form data structure.
1577 @retval EFI_SUCCESS Form validation pass.
1578 @retval other Form validation failed.
1583 IN FORM_BROWSER_FORMSET
*FormSet
,
1584 IN FORM_BROWSER_FORM
*Form
1589 FORM_BROWSER_STATEMENT
*Question
;
1591 Link
= GetFirstNode (&Form
->StatementListHead
);
1592 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1593 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1595 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1596 if (EFI_ERROR (Status
)) {
1600 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1610 @param FormSet FormSet data structure.
1611 @param Form Form data structure.
1613 @retval EFI_SUCCESS The function completed successfully.
1618 IN FORM_BROWSER_FORMSET
*FormSet
,
1619 IN FORM_BROWSER_FORM
*Form
1624 EFI_STRING ConfigResp
;
1625 EFI_STRING Progress
;
1626 FORMSET_STORAGE
*Storage
;
1629 // Validate the Form by NoSubmit check
1631 Status
= NoSubmitCheck (FormSet
, Form
);
1632 if (EFI_ERROR (Status
)) {
1637 // Submit Buffer storage or Name/Value storage
1639 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1640 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1641 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1642 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1644 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1649 // Skip if there is no RequestElement
1651 if (Storage
->ElementCount
== 0) {
1656 // Prepare <ConfigResp>
1658 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1659 if (EFI_ERROR (Status
)) {
1664 // Send <ConfigResp> to Configuration Driver
1666 if (FormSet
->ConfigAccess
!= NULL
) {
1667 Status
= FormSet
->ConfigAccess
->RouteConfig (
1668 FormSet
->ConfigAccess
,
1672 if (EFI_ERROR (Status
)) {
1673 FreePool (ConfigResp
);
1677 FreePool (ConfigResp
);
1680 // Config success, update storage shadow Buffer
1682 SynchronizeStorage (Storage
);
1685 gNvUpdateRequired
= FALSE
;
1692 Reset Question to its default value.
1694 @param FormSet The form set.
1695 @param Form The form.
1696 @param Question The question.
1697 @param DefaultId The Class of the default.
1699 @retval EFI_SUCCESS Question is reset to default value.
1703 GetQuestionDefault (
1704 IN FORM_BROWSER_FORMSET
*FormSet
,
1705 IN FORM_BROWSER_FORM
*Form
,
1706 IN FORM_BROWSER_STATEMENT
*Question
,
1712 QUESTION_DEFAULT
*Default
;
1713 QUESTION_OPTION
*Option
;
1714 EFI_HII_VALUE
*HiiValue
;
1717 Status
= EFI_SUCCESS
;
1720 // Statement don't have storage, skip them
1722 if (Question
->QuestionId
== 0) {
1727 // There are three ways to specify default value for a Question:
1728 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1729 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1730 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1732 HiiValue
= &Question
->HiiValue
;
1735 // EFI_IFR_DEFAULT has highest priority
1737 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1738 Link
= GetFirstNode (&Question
->DefaultListHead
);
1739 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1740 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1742 if (Default
->DefaultId
== DefaultId
) {
1743 if (Default
->ValueExpression
!= NULL
) {
1745 // Default is provided by an Expression, evaluate it
1747 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1748 if (EFI_ERROR (Status
)) {
1752 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1755 // Default value is embedded in EFI_IFR_DEFAULT
1757 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1763 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1768 // EFI_ONE_OF_OPTION
1770 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1771 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1773 // OneOfOption could only provide Standard and Manufacturing default
1775 Link
= GetFirstNode (&Question
->OptionListHead
);
1776 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1777 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1779 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1780 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1782 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1787 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1793 // EFI_IFR_CHECKBOX - lowest priority
1795 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1796 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1798 // Checkbox could only provide Standard and Manufacturing default
1800 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1801 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1803 HiiValue
->Value
.b
= TRUE
;
1805 HiiValue
->Value
.b
= FALSE
;
1813 // For Questions without default
1815 switch (Question
->Operand
) {
1816 case EFI_IFR_NUMERIC_OP
:
1818 // Take minimal value as numeric's default value
1820 HiiValue
->Value
.u64
= Question
->Minimum
;
1823 case EFI_IFR_ONE_OF_OP
:
1825 // Take first oneof option as oneof's default value
1827 Link
= GetFirstNode (&Question
->OptionListHead
);
1828 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1829 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1830 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1834 case EFI_IFR_ORDERED_LIST_OP
:
1836 // Take option sequence in IFR as ordered list's default value
1839 Link
= GetFirstNode (&Question
->OptionListHead
);
1840 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1841 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1843 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1846 if (Index
>= Question
->MaxContainers
) {
1850 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1855 Status
= EFI_NOT_FOUND
;
1864 Reset Questions in a Form to their default value.
1866 @param FormSet FormSet data structure.
1867 @param Form The Form which to be reset.
1868 @param DefaultId The Class of the default.
1870 @retval EFI_SUCCESS The function completed successfully.
1874 ExtractFormDefault (
1875 IN FORM_BROWSER_FORMSET
*FormSet
,
1876 IN FORM_BROWSER_FORM
*Form
,
1882 FORM_BROWSER_STATEMENT
*Question
;
1884 Link
= GetFirstNode (&Form
->StatementListHead
);
1885 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1886 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1887 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1890 // If Question is suppressed, don't reset it to default
1892 if (Question
->SuppressExpression
!= NULL
) {
1893 Status
= EvaluateExpression (FormSet
, Form
, Question
->SuppressExpression
);
1894 if (!EFI_ERROR (Status
) && Question
->SuppressExpression
->Result
.Value
.b
) {
1900 // Reset Question to its default value
1902 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1903 if (EFI_ERROR (Status
)) {
1908 // Synchronize Buffer storage's Edit buffer
1910 if ((Question
->Storage
!= NULL
) &&
1911 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1912 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1921 Initialize Question's Edit copy from Storage.
1923 @param FormSet FormSet data structure.
1924 @param Form Form data structure.
1926 @retval EFI_SUCCESS The function completed successfully.
1931 IN FORM_BROWSER_FORMSET
*FormSet
,
1932 IN FORM_BROWSER_FORM
*Form
1937 FORM_BROWSER_STATEMENT
*Question
;
1939 Link
= GetFirstNode (&Form
->StatementListHead
);
1940 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1941 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1944 // Initialize local copy of Value for each Question
1946 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1947 if (EFI_ERROR (Status
)) {
1951 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1959 Fill storage's edit copy with settings requested from Configuration Driver.
1961 @param FormSet FormSet data structure.
1962 @param Storage Buffer Storage.
1964 @retval EFI_SUCCESS The function completed successfully.
1969 IN FORM_BROWSER_FORMSET
*FormSet
,
1970 IN FORMSET_STORAGE
*Storage
1974 EFI_STRING Progress
;
1978 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1982 if (FormSet
->ConfigAccess
== NULL
) {
1983 return EFI_NOT_FOUND
;
1986 if (Storage
->ElementCount
== 0) {
1988 // Skip if there is no RequestElement
1994 // Request current settings from Configuration Driver
1996 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1997 FormSet
->ConfigAccess
,
1998 Storage
->ConfigRequest
,
2002 if (EFI_ERROR (Status
)) {
2007 // Convert Result from <ConfigAltResp> to <ConfigResp>
2009 StrPtr
= StrStr (Result
, L
"ALTCFG");
2010 if (StrPtr
!= NULL
) {
2014 Status
= ConfigRespToStorage (Storage
, Result
);
2021 Get current setting of Questions.
2023 @param FormSet FormSet data structure.
2025 @retval EFI_SUCCESS The function completed successfully.
2029 InitializeCurrentSetting (
2030 IN OUT FORM_BROWSER_FORMSET
*FormSet
2034 FORMSET_STORAGE
*Storage
;
2035 FORM_BROWSER_FORM
*Form
;
2039 // Extract default from IFR binary
2041 Link
= GetFirstNode (&FormSet
->FormListHead
);
2042 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2043 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2045 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2047 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2051 // Request current settings from Configuration Driver
2053 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2054 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2055 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2057 Status
= LoadStorage (FormSet
, Storage
);
2060 // Now Edit Buffer is filled with default values(lower priority) and current
2061 // settings(higher priority), sychronize it to shadow Buffer
2063 if (!EFI_ERROR (Status
)) {
2064 SynchronizeStorage (Storage
);
2067 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2075 Fetch the Ifr binary data of a FormSet.
2077 @param Handle PackageList Handle
2078 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2079 GUID), take the first FormSet found in package
2081 @param BinaryLength The length of the FormSet IFR binary.
2082 @param BinaryData The buffer designed to receive the FormSet.
2084 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2085 BufferLength was updated.
2086 @retval EFI_INVALID_PARAMETER The handle is unknown.
2087 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2088 be found with the requested FormId.
2093 IN EFI_HII_HANDLE Handle
,
2094 IN OUT EFI_GUID
*FormSetGuid
,
2095 OUT UINTN
*BinaryLength
,
2096 OUT UINT8
**BinaryData
2100 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2106 BOOLEAN ReturnDefault
;
2107 UINT32 PackageListLength
;
2108 EFI_HII_PACKAGE_HEADER PackageHeader
;
2112 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2115 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2117 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2118 ReturnDefault
= TRUE
;
2120 ReturnDefault
= FALSE
;
2124 // Get HII PackageList
2127 HiiPackageList
= NULL
;
2128 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2129 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2130 HiiPackageList
= AllocatePool (BufferSize
);
2131 ASSERT (HiiPackageList
!= NULL
);
2133 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2135 if (EFI_ERROR (Status
)) {
2138 ASSERT (HiiPackageList
!= NULL
);
2141 // Get Form package from this HII package List
2143 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2145 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2147 while (Offset
< PackageListLength
) {
2148 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2149 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2151 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2153 // Search FormSet in this Form Package
2155 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2156 while (Offset2
< PackageHeader
.Length
) {
2157 OpCodeData
= Package
+ Offset2
;
2159 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2161 // Check whether return default FormSet
2163 if (ReturnDefault
) {
2168 // FormSet GUID is specified, check it
2170 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2175 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2178 if (Offset2
< PackageHeader
.Length
) {
2180 // Target formset found
2186 Offset
+= PackageHeader
.Length
;
2189 if (Offset
>= PackageListLength
) {
2191 // Form package not found in this Package List
2193 FreePool (HiiPackageList
);
2194 return EFI_NOT_FOUND
;
2197 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2199 // Return the default FormSet GUID
2201 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2205 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2206 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2207 // of the Form Package.
2209 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2210 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2212 FreePool (HiiPackageList
);
2214 if (*BinaryData
== NULL
) {
2215 return EFI_OUT_OF_RESOURCES
;
2223 Initialize the internal data structure of a FormSet.
2225 @param Handle PackageList Handle
2226 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2227 GUID), take the first FormSet found in package
2229 @param FormSet FormSet data structure.
2231 @retval EFI_SUCCESS The function completed successfully.
2232 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2237 IN EFI_HII_HANDLE Handle
,
2238 IN OUT EFI_GUID
*FormSetGuid
,
2239 OUT FORM_BROWSER_FORMSET
*FormSet
2243 EFI_HANDLE DriverHandle
;
2246 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2247 if (EFI_ERROR (Status
)) {
2251 FormSet
->HiiHandle
= Handle
;
2252 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2255 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2257 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2258 if (EFI_ERROR (Status
)) {
2261 FormSet
->DriverHandle
= DriverHandle
;
2262 Status
= gBS
->HandleProtocol (
2264 &gEfiHiiConfigAccessProtocolGuid
,
2265 (VOID
**) &FormSet
->ConfigAccess
2267 if (EFI_ERROR (Status
)) {
2269 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2270 // list, then there will be no configuration action required
2272 FormSet
->ConfigAccess
= NULL
;
2276 // Parse the IFR binary OpCodes
2278 Status
= ParseOpCodes (FormSet
);
2279 if (EFI_ERROR (Status
)) {
2283 gClassOfVfr
= FormSet
->SubClass
;
2284 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2285 FrontPageHandle
= FormSet
->HiiHandle
;
2289 // Match GUID to find out the function key setting. If match fail, use the default setting.
2291 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2292 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2294 // Update the function key setting.
2296 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2298 // Function key prompt can not be displayed if the function key has been disabled.
2300 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2301 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2304 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2305 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2308 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2309 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2312 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2313 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);