2 Copyright (c) 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 Entry and initialization module for the browser.
26 SETUP_DRIVER_PRIVATE_DATA mPrivateData
= {
27 SETUP_DRIVER_SIGNATURE
,
38 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
39 EFI_HII_STRING_PROTOCOL
*mHiiString
;
40 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
42 BANNER_DATA
*BannerData
;
43 EFI_HII_HANDLE FrontPageHandle
;
45 UINTN gFunctionKeySetting
;
46 BOOLEAN gResetRequired
;
47 BOOLEAN gNvUpdateRequired
;
48 EFI_HII_HANDLE gHiiHandle
;
51 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
56 // Browser Global Strings
58 CHAR16
*gFunctionOneString
;
59 CHAR16
*gFunctionTwoString
;
60 CHAR16
*gFunctionNineString
;
61 CHAR16
*gFunctionTenString
;
63 CHAR16
*gEnterCommitString
;
64 CHAR16
*gEscapeString
;
66 CHAR16
*gMoveHighlight
;
67 CHAR16
*gMakeSelection
;
68 CHAR16
*gDecNumericInput
;
69 CHAR16
*gHexNumericInput
;
70 CHAR16
*gToggleCheckBox
;
71 CHAR16
*gPromptForData
;
72 CHAR16
*gPromptForPassword
;
73 CHAR16
*gPromptForNewPassword
;
74 CHAR16
*gConfirmPassword
;
75 CHAR16
*gConfirmError
;
76 CHAR16
*gPassowordInvalid
;
85 CHAR16
*gAdjustNumber
;
87 CHAR16 gPromptBlockWidth
;
88 CHAR16 gOptionBlockWidth
;
89 CHAR16 gHelpBlockWidth
;
91 EFI_GUID gZeroGuid
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
92 EFI_GUID gSetupBrowserGuid
= {
93 0xab368524, 0xb60c, 0x495b, 0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32
96 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
114 NONE_FUNCTION_KEY_SETTING
133 NONE_FUNCTION_KEY_SETTING
152 NONE_FUNCTION_KEY_SETTING
155 // BMM File Explorer FormSet.
171 NONE_FUNCTION_KEY_SETTING
175 //@MT: EFI_DRIVER_ENTRY_POINT (InitializeSetup)
180 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
181 IN EFI_HII_HANDLE
*Handles
,
182 IN UINTN HandleCount
,
183 IN EFI_GUID
*FormSetGuid
, OPTIONAL
184 IN UINT16 FormId
, OPTIONAL
185 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
186 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
191 This is the routine which an external caller uses to direct the browser
192 where to obtain it's information.
195 This - The Form Browser protocol instanse.
196 Handles - A pointer to an array of Handles. If HandleCount > 1 we
197 display a list of the formsets for the handles specified.
198 HandleCount - The number of Handles specified in Handle.
199 FormSetGuid - This field points to the EFI_GUID which must match the Guid
200 field in the EFI_IFR_FORM_SET op-code for the specified
201 forms-based package. If FormSetGuid is NULL, then this
202 function will display the first found forms package.
203 FormId - This field specifies which EFI_IFR_FORM to render as the first
204 displayable page. If this field has a value of 0x0000, then
205 the forms browser will render the specified forms in their encoded order.
206 ScreenDimenions - This allows the browser to be called so that it occupies a
207 portion of the physical screen instead of dynamically determining the screen dimensions.
208 ActionRequest - Points to the action recommended by the form.
211 EFI_SUCCESS - The function completed successfully.
212 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
213 EFI_NOT_FOUND - No valid forms could be found to display.
218 UI_MENU_SELECTION
*Selection
;
220 FORM_BROWSER_FORMSET
*FormSet
;
222 Status
= EFI_SUCCESS
;
223 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
226 // Seed the dimensions in the global
228 gST
->ConOut
->QueryMode (
230 gST
->ConOut
->Mode
->Mode
,
231 &gScreenDimensions
.RightColumn
,
232 &gScreenDimensions
.BottomRow
235 if (ScreenDimensions
!= NULL
) {
237 // Check local dimension vs. global dimension.
239 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
240 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
242 return EFI_INVALID_PARAMETER
;
245 // Local dimension validation.
247 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
248 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
249 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
251 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
252 SCROLL_ARROW_HEIGHT
*
254 FRONT_PAGE_HEADER_HEIGHT
+
259 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
261 return EFI_INVALID_PARAMETER
;
266 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
267 gHelpBlockWidth
= gOptionBlockWidth
;
268 gPromptBlockWidth
= gOptionBlockWidth
;
271 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
273 InitializeBrowserStrings ();
275 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
276 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
279 // Ensure we are in Text mode
283 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
287 for (Index
= 0; Index
< HandleCount
; Index
++) {
288 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
289 ASSERT (Selection
!= NULL
);
291 Selection
->Handle
= Handles
[Index
];
292 if (FormSetGuid
!= NULL
) {
293 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
294 Selection
->FormId
= FormId
;
298 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
299 ASSERT (FormSet
!= NULL
);
302 // Initialize internal data structures of FormSet
304 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
305 if (EFI_ERROR (Status
)) {
306 DestroyFormSet (FormSet
);
309 Selection
->FormSet
= FormSet
;
312 // Initialize current settings of Questions in this FormSet
314 Status
= InitializeCurrentSetting (FormSet
);
315 if (EFI_ERROR (Status
)) {
316 DestroyFormSet (FormSet
);
321 // Display this formset
323 gCurrentSelection
= Selection
;
325 Status
= SetupBrowser (Selection
);
327 gCurrentSelection
= NULL
;
328 DestroyFormSet (FormSet
);
330 if (EFI_ERROR (Status
)) {
334 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
336 gBS
->FreePool (Selection
);
339 if (ActionRequest
!= NULL
) {
340 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
341 if (gResetRequired
) {
342 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
346 FreeBrowserStrings ();
348 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
349 gST
->ConOut
->ClearScreen (gST
->ConOut
);
356 This function is called by a callback handler to retrieve uncommitted state
357 data from the browser.
359 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
361 @param ResultsDataSize A pointer to the size of the buffer associated
363 @param ResultsData A string returned from an IFR browser or
364 equivalent. The results string will have no
365 routing information in them.
366 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
367 (if RetrieveData = TRUE) data from the uncommitted
368 browser state information or set (if RetrieveData
369 = FALSE) data in the uncommitted browser state
371 @param VariableGuid An optional field to indicate the target variable
373 @param VariableName An optional field to indicate the target
374 human-readable variable name.
376 @retval EFI_SUCCESS The results have been distributed or are awaiting
378 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
379 contain the results data.
385 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
386 IN OUT UINTN
*ResultsDataSize
,
387 IN OUT EFI_STRING ResultsData
,
388 IN BOOLEAN RetrieveData
,
389 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
390 IN CONST CHAR16
*VariableName OPTIONAL
395 FORMSET_STORAGE
*Storage
;
396 FORM_BROWSER_FORMSET
*FormSet
;
403 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
404 return EFI_INVALID_PARAMETER
;
407 if (gCurrentSelection
== NULL
) {
408 return EFI_NOT_READY
;
413 FormSet
= gCurrentSelection
->FormSet
;
416 // Find target storage
418 Link
= GetFirstNode (&FormSet
->StorageListHead
);
419 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
420 return EFI_UNSUPPORTED
;
423 if (VariableGuid
!= NULL
) {
425 // Try to find target storage
428 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
429 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
430 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
432 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
433 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
435 // Buffer storage require both GUID and Name
437 if (VariableName
== NULL
) {
438 return EFI_NOT_FOUND
;
441 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
451 return EFI_NOT_FOUND
;
455 // GUID/Name is not specified, take the first storage in FormSet
457 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
462 // Skip if there is no RequestElement
464 if (Storage
->ElementCount
== 0) {
469 // Generate <ConfigResp>
471 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
472 if (EFI_ERROR (Status
)) {
477 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
479 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
481 BufferSize
= StrSize (StrPtr
);
482 if (*ResultsDataSize
< BufferSize
) {
483 *ResultsDataSize
= BufferSize
;
485 gBS
->FreePool (ConfigResp
);
486 return EFI_BUFFER_TOO_SMALL
;
489 *ResultsDataSize
= BufferSize
;
490 CopyMem (ResultsData
, StrPtr
, BufferSize
);
492 gBS
->FreePool (ConfigResp
);
495 // Prepare <ConfigResp>
497 TmpSize
= StrLen (ResultsData
);
498 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
499 ConfigResp
= AllocateZeroPool (BufferSize
);
500 ASSERT (ConfigResp
!= NULL
);
502 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
503 StrCat (ConfigResp
, L
"&");
504 StrCat (ConfigResp
, ResultsData
);
507 // Update Browser uncommited data
509 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
510 if (EFI_ERROR (Status
)) {
522 @param entry EFI_IMAGE_ENTRY_POINT)
524 @retval EFI_SUCCESS Setup loaded.
525 @retval other Setup Error
531 IN EFI_HANDLE ImageHandle
,
532 IN EFI_SYSTEM_TABLE
*SystemTable
536 EFI_HANDLE HiiDriverHandle
;
537 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
539 //@MT: EfiInitializeDriverLib (ImageHandle, SystemTable);
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
585 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
586 ASSERT (BannerData
!= NULL
);
589 // Install FormBrowser2 protocol
591 mPrivateData
.Handle
= NULL
;
592 Status
= gBS
->InstallProtocolInterface (
593 &mPrivateData
.Handle
,
594 &gEfiFormBrowser2ProtocolGuid
,
595 EFI_NATIVE_INTERFACE
,
596 &mPrivateData
.FormBrowser2
598 ASSERT_EFI_ERROR (Status
);
601 // Install Print protocol
603 Status
= gBS
->InstallProtocolInterface (
604 &mPrivateData
.Handle
,
605 &gEfiPrintProtocolGuid
,
606 EFI_NATIVE_INTERFACE
,
615 Create a new string in HII Package List.
617 @param String The String to be added
618 @param HiiHandle The package list in the HII database to insert the
621 @return The output string.
627 IN EFI_HII_HANDLE HiiHandle
630 EFI_STRING_ID StringId
;
634 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
635 ASSERT_EFI_ERROR (Status
);
642 Delete a string from HII Package List.
644 @param StringId Id of the string in HII database.
645 @param HiiHandle The HII package list handle.
647 @retval EFI_SUCCESS The string was deleted successfully.
652 IN EFI_STRING_ID StringId
,
653 IN EFI_HII_HANDLE HiiHandle
658 NullChar
= CHAR_NULL
;
659 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
664 Get the string based on the StringId and HII Package List Handle.
666 @param Token The String's ID.
667 @param HiiHandle The package list in the HII database to search for
668 the specified string.
670 @return The output string.
675 IN EFI_STRING_ID Token
,
676 IN EFI_HII_HANDLE HiiHandle
684 // Set default string size assumption at no more than 256 bytes
686 BufferLength
= 0x100;
687 String
= AllocateZeroPool (BufferLength
);
688 ASSERT (String
!= NULL
);
690 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
692 if (Status
== EFI_BUFFER_TOO_SMALL
) {
693 gBS
->FreePool (String
);
694 String
= AllocateZeroPool (BufferLength
);
695 ASSERT (String
!= NULL
);
697 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
699 ASSERT_EFI_ERROR (Status
);
706 Allocate new memory and then copy the Unicode string Source to Destination.
708 @param Dest Location to copy string
709 @param Src String to copy
716 IN OUT CHAR16
**Dest
,
720 SafeFreePool (*Dest
);
721 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
722 ASSERT (*Dest
!= NULL
);
727 Allocate new memory and concatinate Source on the end of Destination.
729 @param Dest String to added to the end of.
730 @param Src String to concatinate.
737 IN OUT CHAR16
**Dest
,
745 NewStringCpy (Dest
, Src
);
749 TmpSize
= StrSize (*Dest
);
750 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
751 ASSERT (NewString
!= NULL
);
753 StrCpy (NewString
, *Dest
);
754 StrCat (NewString
, Src
);
756 gBS
->FreePool (*Dest
);
762 Synchronize Storage's Edit copy to Shadow copy.
764 @param Storage The Storage to be synchronized.
771 IN FORMSET_STORAGE
*Storage
775 NAME_VALUE_NODE
*Node
;
777 switch (Storage
->Type
) {
778 case EFI_HII_VARSTORE_BUFFER
:
779 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
782 case EFI_HII_VARSTORE_NAME_VALUE
:
783 Link
= GetFirstNode (&Storage
->NameValueListHead
);
784 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
785 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
787 NewStringCpy (&Node
->Value
, Node
->EditValue
);
789 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
793 case EFI_HII_VARSTORE_EFI_VARIABLE
:
801 Get Value for given Name from a NameValue Storage.
803 @param Storage The NameValue Storage.
804 @param Name The Name.
805 @param Value The retured Value.
807 @retval EFI_SUCCESS Value found for given Name.
808 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
813 IN FORMSET_STORAGE
*Storage
,
815 IN OUT CHAR16
**Value
819 NAME_VALUE_NODE
*Node
;
823 Link
= GetFirstNode (&Storage
->NameValueListHead
);
824 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
825 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
827 if (StrCmp (Name
, Node
->Name
) == 0) {
828 NewStringCpy (Value
, Node
->EditValue
);
832 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
835 return EFI_NOT_FOUND
;
840 Set Value of given Name in a NameValue Storage.
842 @param Storage The NameValue Storage.
843 @param Name The Name.
844 @param Value The Value to set.
846 @retval EFI_SUCCESS Value found for given Name.
847 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
852 IN FORMSET_STORAGE
*Storage
,
858 NAME_VALUE_NODE
*Node
;
860 Link
= GetFirstNode (&Storage
->NameValueListHead
);
861 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
862 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
864 if (StrCmp (Name
, Node
->Name
) == 0) {
865 SafeFreePool (Node
->EditValue
);
866 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
867 ASSERT (Node
->EditValue
!= NULL
);
871 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
874 return EFI_NOT_FOUND
;
879 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
881 @param Storage The Storage to be conveted.
882 @param ConfigResp The returned <ConfigResp>.
884 @retval EFI_SUCCESS Convert success.
885 @retval EFI_INVALID_PARAMETER Incorrect storage type.
889 StorageToConfigResp (
890 IN FORMSET_STORAGE
*Storage
,
891 IN CHAR16
**ConfigResp
897 NAME_VALUE_NODE
*Node
;
899 Status
= EFI_SUCCESS
;
901 switch (Storage
->Type
) {
902 case EFI_HII_VARSTORE_BUFFER
:
903 Status
= mHiiConfigRouting
->BlockToConfig (
905 Storage
->ConfigRequest
,
913 case EFI_HII_VARSTORE_NAME_VALUE
:
915 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
917 Link
= GetFirstNode (&Storage
->NameValueListHead
);
918 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
919 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
921 NewStringCat (ConfigResp
, L
"&");
922 NewStringCat (ConfigResp
, Node
->Name
);
923 NewStringCat (ConfigResp
, L
"=");
924 NewStringCat (ConfigResp
, Node
->EditValue
);
926 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
930 case EFI_HII_VARSTORE_EFI_VARIABLE
:
932 Status
= EFI_INVALID_PARAMETER
;
941 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
943 @param Storage The Storage to receive the settings.
944 @param ConfigResp The <ConfigResp> to be converted.
946 @retval EFI_SUCCESS Convert success.
947 @retval EFI_INVALID_PARAMETER Incorrect storage type.
951 ConfigRespToStorage (
952 IN FORMSET_STORAGE
*Storage
,
953 IN CHAR16
*ConfigResp
963 Status
= EFI_SUCCESS
;
965 switch (Storage
->Type
) {
966 case EFI_HII_VARSTORE_BUFFER
:
967 BufferSize
= Storage
->Size
;
968 Status
= mHiiConfigRouting
->ConfigToBlock (
977 case EFI_HII_VARSTORE_NAME_VALUE
:
978 StrPtr
= StrStr (ConfigResp
, L
"&");
979 while (StrPtr
!= NULL
) {
985 StrPtr
= StrStr (StrPtr
, L
"=");
986 if (StrPtr
== NULL
) {
996 StrPtr
= StrStr (StrPtr
, L
"&");
997 if (StrPtr
!= NULL
) {
1000 SetValueByName (Storage
, Name
, Value
);
1004 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1006 Status
= EFI_INVALID_PARAMETER
;
1015 Get Question's current Value.
1017 @param FormSet FormSet data structure.
1018 @param Form Form data structure.
1019 @param Question Question to be initialized.
1020 @param Cached TRUE: get from Edit copy FALSE: get from original
1023 @retval EFI_SUCCESS The function completed successfully.
1028 IN FORM_BROWSER_FORMSET
*FormSet
,
1029 IN FORM_BROWSER_FORM
*Form
,
1030 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1040 FORMSET_STORAGE
*Storage
;
1041 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1042 CHAR16
*ConfigRequest
;
1047 BOOLEAN IsBufferStorage
;
1050 Status
= EFI_SUCCESS
;
1053 // Statement don't have storage, skip them
1055 if (Question
->QuestionId
== 0) {
1060 // Question value is provided by an Expression, evaluate it
1062 if (Question
->ValueExpression
!= NULL
) {
1063 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1064 if (!EFI_ERROR (Status
)) {
1065 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1071 // Question value is provided by RTC
1073 Storage
= Question
->Storage
;
1074 QuestionValue
= &Question
->HiiValue
.Value
;
1075 if (Storage
== NULL
) {
1077 // It's a Question without storage, or RTC date/time
1079 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1081 // Date and time define the same Flags bit
1083 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1084 case QF_DATE_STORAGE_TIME
:
1085 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1088 case QF_DATE_STORAGE_WAKEUP
:
1089 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1092 case QF_DATE_STORAGE_NORMAL
:
1095 // For date/time without storage
1100 if (EFI_ERROR (Status
)) {
1104 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1105 QuestionValue
->date
.Year
= EfiTime
.Year
;
1106 QuestionValue
->date
.Month
= EfiTime
.Month
;
1107 QuestionValue
->date
.Day
= EfiTime
.Day
;
1109 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1110 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1111 QuestionValue
->time
.Second
= EfiTime
.Second
;
1119 // Question value is provided by EFI variable
1121 StorageWidth
= Question
->StorageWidth
;
1122 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1123 if (Question
->BufferValue
!= NULL
) {
1124 Dst
= Question
->BufferValue
;
1126 Dst
= (UINT8
*) QuestionValue
;
1129 Status
= gRT
->GetVariable (
1130 Question
->VariableName
,
1137 // Always return success, even this EFI variable doesn't exist
1143 // Question Value is provided by Buffer Storage or NameValue Storage
1145 if (Question
->BufferValue
!= NULL
) {
1147 // This Question is password or orderedlist
1149 Dst
= Question
->BufferValue
;
1152 // Other type of Questions
1154 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1157 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1158 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1160 if (IsBufferStorage
) {
1162 // Copy from storage Edit buffer
1164 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1166 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1167 if (EFI_ERROR (Status
)) {
1172 StrCpy ((CHAR16
*) Dst
, Value
);
1174 Status
= R8_HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1177 gBS
->FreePool (Value
);
1181 // Request current settings from Configuration Driver
1183 if (FormSet
->ConfigAccess
== NULL
) {
1184 return EFI_NOT_FOUND
;
1188 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1189 // <ConfigHdr> + "&" + <VariableName>
1191 if (IsBufferStorage
) {
1192 Length
= StrLen (Storage
->ConfigHdr
);
1193 Length
+= StrLen (Question
->BlockName
);
1195 Length
= StrLen (Storage
->ConfigHdr
);
1196 Length
+= StrLen (Question
->VariableName
) + 1;
1198 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1199 ASSERT (ConfigRequest
!= NULL
);
1201 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1202 if (IsBufferStorage
) {
1203 StrCat (ConfigRequest
, Question
->BlockName
);
1205 StrCat (ConfigRequest
, L
"&");
1206 StrCat (ConfigRequest
, Question
->VariableName
);
1209 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1210 FormSet
->ConfigAccess
,
1215 if (EFI_ERROR (Status
)) {
1220 // Skip <ConfigRequest>
1222 Value
= Result
+ Length
;
1223 if (IsBufferStorage
) {
1229 if (*Value
!= '=') {
1230 gBS
->FreePool (Result
);
1231 return EFI_NOT_FOUND
;
1234 // Skip '=', point to value
1237 if (!IsBufferStorage
&& IsString
) {
1238 StrCpy ((CHAR16
*) Dst
, Value
);
1240 Status
= R8_HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1241 if (EFI_ERROR (Status
)) {
1242 gBS
->FreePool (Result
);
1248 // Synchronize Edit Buffer
1250 if (IsBufferStorage
) {
1251 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1253 SetValueByName (Storage
, Question
->VariableName
, Value
);
1255 gBS
->FreePool (Result
);
1263 Save Question Value to edit copy(cached) or Storage(uncached).
1265 @param FormSet FormSet data structure.
1266 @param Form Form data structure.
1267 @param Question Pointer to the Question.
1268 @param Cached TRUE: set to Edit copy FALSE: set to original
1271 @retval EFI_SUCCESS The function completed successfully.
1276 IN FORM_BROWSER_FORMSET
*FormSet
,
1277 IN FORM_BROWSER_FORM
*Form
,
1278 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1289 FORMSET_STORAGE
*Storage
;
1290 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1295 BOOLEAN IsBufferStorage
;
1298 Status
= EFI_SUCCESS
;
1301 // Statement don't have storage, skip them
1303 if (Question
->QuestionId
== 0) {
1308 // If Question value is provided by an Expression, then it is read only
1310 if (Question
->ValueExpression
!= NULL
) {
1315 // Question value is provided by RTC
1317 Storage
= Question
->Storage
;
1318 QuestionValue
= &Question
->HiiValue
.Value
;
1319 if (Storage
== NULL
) {
1321 // It's a Question without storage, or RTC date/time
1323 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1325 // Date and time define the same Flags bit
1327 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1328 case QF_DATE_STORAGE_TIME
:
1329 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1332 case QF_DATE_STORAGE_WAKEUP
:
1333 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1336 case QF_DATE_STORAGE_NORMAL
:
1339 // For date/time without storage
1344 if (EFI_ERROR (Status
)) {
1348 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1349 EfiTime
.Year
= QuestionValue
->date
.Year
;
1350 EfiTime
.Month
= QuestionValue
->date
.Month
;
1351 EfiTime
.Day
= QuestionValue
->date
.Day
;
1353 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1354 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1355 EfiTime
.Second
= QuestionValue
->time
.Second
;
1358 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1359 Status
= gRT
->SetTime (&EfiTime
);
1361 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1369 // Question value is provided by EFI variable
1371 StorageWidth
= Question
->StorageWidth
;
1372 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1373 if (Question
->BufferValue
!= NULL
) {
1374 Src
= Question
->BufferValue
;
1376 Src
= (UINT8
*) QuestionValue
;
1379 Status
= gRT
->SetVariable (
1380 Question
->VariableName
,
1382 Storage
->Attributes
,
1390 // Question Value is provided by Buffer Storage or NameValue Storage
1392 if (Question
->BufferValue
!= NULL
) {
1393 Src
= Question
->BufferValue
;
1395 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1398 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1399 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1400 if (IsBufferStorage
) {
1402 // Copy to storage edit buffer
1404 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1408 NewStringCpy (&Value
, (CHAR16
*) Src
);
1410 BufferLen
= (StorageWidth
* 2 + 1) * sizeof (CHAR16
);
1411 Value
= AllocateZeroPool (BufferLen
);
1412 ASSERT (Value
!= NULL
);
1413 R8_BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1416 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1417 gBS
->FreePool (Value
);
1422 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1423 // <ConfigHdr> + "&" + <VariableName> + "=" + "<HexCh>StorageWidth * 2"
1425 if (IsBufferStorage
) {
1426 Length
= StrLen (Question
->BlockName
) + 7;
1428 Length
= StrLen (Question
->VariableName
) + 2;
1430 if (!IsBufferStorage
&& IsString
) {
1431 Length
+= StrLen ((CHAR16
*) Src
);
1433 Length
+= (StorageWidth
* 2);
1435 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1436 ASSERT (ConfigResp
!= NULL
);
1438 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1439 if (IsBufferStorage
) {
1440 StrCat (ConfigResp
, Question
->BlockName
);
1441 StrCat (ConfigResp
, L
"&VALUE=");
1443 StrCat (ConfigResp
, L
"&");
1444 StrCat (ConfigResp
, Question
->VariableName
);
1445 StrCat (ConfigResp
, L
"=");
1448 Value
= ConfigResp
+ StrLen (ConfigResp
);
1449 if (!IsBufferStorage
&& IsString
) {
1450 StrCpy (Value
, (CHAR16
*) Src
);
1452 BufferLen
= (StorageWidth
* 2 + 1) * sizeof (CHAR16
);
1453 R8_BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1457 // Submit Question Value to Configuration Driver
1459 if (FormSet
->ConfigAccess
!= NULL
) {
1460 Status
= FormSet
->ConfigAccess
->RouteConfig (
1461 FormSet
->ConfigAccess
,
1465 if (EFI_ERROR (Status
)) {
1466 gBS
->FreePool (ConfigResp
);
1470 gBS
->FreePool (ConfigResp
);
1473 // Synchronize shadow Buffer
1475 SynchronizeStorage (Storage
);
1483 Perform inconsistent check for a Form.
1485 @param FormSet FormSet data structure.
1486 @param Form Form data structure.
1487 @param Question The Question to be validated.
1488 @param Type Validation type: InConsistent or NoSubmit
1490 @retval EFI_SUCCESS Form validation pass.
1491 @retval other Form validation failed.
1496 IN FORM_BROWSER_FORMSET
*FormSet
,
1497 IN FORM_BROWSER_FORM
*Form
,
1498 IN FORM_BROWSER_STATEMENT
*Question
,
1504 LIST_ENTRY
*ListHead
;
1507 FORM_EXPRESSION
*Expression
;
1509 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1510 ListHead
= &Question
->InconsistentListHead
;
1511 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1512 ListHead
= &Question
->NoSubmitListHead
;
1514 return EFI_UNSUPPORTED
;
1517 Link
= GetFirstNode (ListHead
);
1518 while (!IsNull (ListHead
, Link
)) {
1519 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1522 // Evaluate the expression
1524 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1525 if (EFI_ERROR (Status
)) {
1529 if (Expression
->Result
.Value
.b
) {
1531 // Condition meet, show up error message
1533 if (Expression
->Error
!= 0) {
1534 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1536 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1537 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1538 gBS
->FreePool (PopUp
);
1541 return EFI_NOT_READY
;
1544 Link
= GetNextNode (ListHead
, Link
);
1552 Perform NoSubmit check for a Form.
1554 @param FormSet FormSet data structure.
1555 @param Form Form data structure.
1557 @retval EFI_SUCCESS Form validation pass.
1558 @retval other Form validation failed.
1563 IN FORM_BROWSER_FORMSET
*FormSet
,
1564 IN FORM_BROWSER_FORM
*Form
1569 FORM_BROWSER_STATEMENT
*Question
;
1571 Link
= GetFirstNode (&Form
->StatementListHead
);
1572 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1573 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1575 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1576 if (EFI_ERROR (Status
)) {
1580 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1590 @param FormSet FormSet data structure.
1591 @param Form Form data structure.
1593 @retval EFI_SUCCESS The function completed successfully.
1598 IN FORM_BROWSER_FORMSET
*FormSet
,
1599 IN FORM_BROWSER_FORM
*Form
1604 EFI_STRING ConfigResp
;
1605 EFI_STRING Progress
;
1606 FORMSET_STORAGE
*Storage
;
1609 // Validate the Form by NoSubmit check
1611 Status
= NoSubmitCheck (FormSet
, Form
);
1612 if (EFI_ERROR (Status
)) {
1617 // Submit Buffer storage or Name/Value storage
1619 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1620 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1621 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1622 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1624 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1629 // Skip if there is no RequestElement
1631 if (Storage
->ElementCount
== 0) {
1636 // Prepare <ConfigResp>
1638 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1639 if (EFI_ERROR (Status
)) {
1644 // Send <ConfigResp> to Configuration Driver
1646 if (FormSet
->ConfigAccess
!= NULL
) {
1647 Status
= FormSet
->ConfigAccess
->RouteConfig (
1648 FormSet
->ConfigAccess
,
1652 if (EFI_ERROR (Status
)) {
1653 gBS
->FreePool (ConfigResp
);
1657 gBS
->FreePool (ConfigResp
);
1660 // Config success, update storage shadow Buffer
1662 SynchronizeStorage (Storage
);
1665 gNvUpdateRequired
= FALSE
;
1672 Reset Question to its default value.
1674 @param FormSet FormSet data structure.
1675 @param DefaultId The Class of the default.
1677 @retval EFI_SUCCESS Question is reset to default value.
1681 GetQuestionDefault (
1682 IN FORM_BROWSER_FORMSET
*FormSet
,
1683 IN FORM_BROWSER_FORM
*Form
,
1684 IN FORM_BROWSER_STATEMENT
*Question
,
1690 QUESTION_DEFAULT
*Default
;
1691 QUESTION_OPTION
*Option
;
1692 EFI_HII_VALUE
*HiiValue
;
1695 Status
= EFI_SUCCESS
;
1698 // Statement don't have storage, skip them
1700 if (Question
->QuestionId
== 0) {
1705 // There are three ways to specify default value for a Question:
1706 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1707 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1708 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1710 HiiValue
= &Question
->HiiValue
;
1713 // EFI_IFR_DEFAULT has highest priority
1715 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1716 Link
= GetFirstNode (&Question
->DefaultListHead
);
1717 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1718 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1720 if (Default
->DefaultId
== DefaultId
) {
1721 if (Default
->ValueExpression
!= NULL
) {
1723 // Default is provided by an Expression, evaluate it
1725 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1726 if (EFI_ERROR (Status
)) {
1730 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1733 // Default value is embedded in EFI_IFR_DEFAULT
1735 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1741 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1746 // EFI_ONE_OF_OPTION
1748 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1749 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1751 // OneOfOption could only provide Standard and Manufacturing default
1753 Link
= GetFirstNode (&Question
->OptionListHead
);
1754 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1755 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1757 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && (Option
->Flags
& EFI_IFR_OPTION_DEFAULT
)) ||
1758 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && (Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
))
1760 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1765 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1771 // EFI_IFR_CHECKBOX - lowest priority
1773 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1774 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1776 // Checkbox could only provide Standard and Manufacturing default
1778 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && (Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
)) ||
1779 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && (Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
))
1781 HiiValue
->Value
.b
= TRUE
;
1783 HiiValue
->Value
.b
= FALSE
;
1791 // For Questions without default
1793 switch (Question
->Operand
) {
1794 case EFI_IFR_NUMERIC_OP
:
1796 // Take minimal value as numeric's default value
1798 HiiValue
->Value
.u64
= Question
->Minimum
;
1801 case EFI_IFR_ONE_OF_OP
:
1803 // Take first oneof option as oneof's default value
1805 Link
= GetFirstNode (&Question
->OptionListHead
);
1806 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1807 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1808 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1812 case EFI_IFR_ORDERED_LIST_OP
:
1814 // Take option sequence in IFR as ordered list's default value
1817 Link
= GetFirstNode (&Question
->OptionListHead
);
1818 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1819 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1821 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1824 if (Index
>= Question
->MaxContainers
) {
1828 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1833 Status
= EFI_NOT_FOUND
;
1842 Reset Questions in a Form to their default value.
1844 @param FormSet FormSet data structure.
1845 @param Form The Form which to be reset.
1846 @param DefaultId The Class of the default.
1848 @retval EFI_SUCCESS The function completed successfully.
1852 ExtractFormDefault (
1853 IN FORM_BROWSER_FORMSET
*FormSet
,
1854 IN FORM_BROWSER_FORM
*Form
,
1860 FORM_BROWSER_STATEMENT
*Question
;
1862 Link
= GetFirstNode (&Form
->StatementListHead
);
1863 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1864 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1865 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1868 // Reset Question to its default value
1870 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1871 if (EFI_ERROR (Status
)) {
1876 // Synchronize Buffer storage's Edit buffer
1878 if ((Question
->Storage
!= NULL
) &&
1879 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1880 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1889 Initialize Question's Edit copy from Storage.
1891 @param FormSet FormSet data structure.
1892 @param Form Form data structure.
1894 @retval EFI_SUCCESS The function completed successfully.
1899 IN FORM_BROWSER_FORMSET
*FormSet
,
1900 IN FORM_BROWSER_FORM
*Form
1905 FORM_BROWSER_STATEMENT
*Question
;
1907 Link
= GetFirstNode (&Form
->StatementListHead
);
1908 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1909 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1912 // Initialize local copy of Value for each Question
1914 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1915 if (EFI_ERROR (Status
)) {
1919 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1927 Fill storage's edit copy with settings requested from Configuration Driver.
1929 @param FormSet FormSet data structure.
1930 @param Storage Buffer Storage.
1932 @retval EFI_SUCCESS The function completed successfully.
1937 IN FORM_BROWSER_FORMSET
*FormSet
,
1938 IN FORMSET_STORAGE
*Storage
1942 EFI_STRING Progress
;
1946 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1950 if (FormSet
->ConfigAccess
== NULL
) {
1951 return EFI_NOT_FOUND
;
1954 if (Storage
->ElementCount
== 0) {
1956 // Skip if there is no RequestElement
1962 // Request current settings from Configuration Driver
1964 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1965 FormSet
->ConfigAccess
,
1966 Storage
->ConfigRequest
,
1970 if (EFI_ERROR (Status
)) {
1975 // Convert Result from <ConfigAltResp> to <ConfigResp>
1977 StrPtr
= StrStr (Result
, L
"ALTCFG");
1978 if (StrPtr
!= NULL
) {
1982 Status
= ConfigRespToStorage (Storage
, Result
);
1983 gBS
->FreePool (Result
);
1989 Get current setting of Questions.
1991 @param FormSet FormSet data structure.
1993 @retval EFI_SUCCESS The function completed successfully.
1997 InitializeCurrentSetting (
1998 IN OUT FORM_BROWSER_FORMSET
*FormSet
2002 FORMSET_STORAGE
*Storage
;
2003 FORM_BROWSER_FORM
*Form
;
2007 // Extract default from IFR binary
2009 Link
= GetFirstNode (&FormSet
->FormListHead
);
2010 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2011 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2013 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2015 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2019 // Request current settings from Configuration Driver
2021 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2022 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2023 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2025 Status
= LoadStorage (FormSet
, Storage
);
2028 // Now Edit Buffer is filled with default values(lower priority) and current
2029 // settings(higher priority), sychronize it to shadow Buffer
2031 if (!EFI_ERROR (Status
)) {
2032 SynchronizeStorage (Storage
);
2035 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2043 Fetch the Ifr binary data of a FormSet.
2045 @param Handle PackageList Handle
2046 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2047 GUID), take the first FormSet found in package
2049 @param BinaryLength The length of the FormSet IFR binary.
2050 @param BinaryData The buffer designed to receive the FormSet.
2052 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2053 BufferLength was updated.
2054 @retval EFI_INVALID_PARAMETER The handle is unknown.
2055 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2056 be found with the requested FormId.
2061 IN EFI_HII_HANDLE Handle
,
2062 IN OUT EFI_GUID
*FormSetGuid
,
2063 OUT UINTN
*BinaryLength
,
2064 OUT UINT8
**BinaryData
2068 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2074 BOOLEAN ReturnDefault
;
2075 UINT32 PackageListLength
;
2076 EFI_HII_PACKAGE_HEADER PackageHeader
;
2080 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2083 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2085 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2086 ReturnDefault
= TRUE
;
2088 ReturnDefault
= FALSE
;
2092 // Get HII PackageList
2095 HiiPackageList
= NULL
;
2096 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2097 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2098 HiiPackageList
= AllocatePool (BufferSize
);
2099 ASSERT (HiiPackageList
!= NULL
);
2101 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2103 if (EFI_ERROR (Status
)) {
2108 // Get Form package from this HII package List
2110 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2112 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2114 while (Offset
< PackageListLength
) {
2115 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2116 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2118 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORM
) {
2120 // Search FormSet in this Form Package
2122 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2123 while (Offset2
< PackageHeader
.Length
) {
2124 OpCodeData
= Package
+ Offset2
;
2126 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2128 // Check whether return default FormSet
2130 if (ReturnDefault
) {
2135 // FormSet GUID is specified, check it
2137 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2142 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2145 if (Offset2
< PackageHeader
.Length
) {
2147 // Target formset found
2153 Offset
+= PackageHeader
.Length
;
2156 if (Offset
>= PackageListLength
) {
2158 // Form package not found in this Package List
2160 gBS
->FreePool (HiiPackageList
);
2161 return EFI_NOT_FOUND
;
2164 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2166 // Return the default FormSet GUID
2168 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2172 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2173 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2174 // of the Form Package.
2176 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2177 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2179 gBS
->FreePool (HiiPackageList
);
2181 if (*BinaryData
== NULL
) {
2182 return EFI_OUT_OF_RESOURCES
;
2190 Initialize the internal data structure of a FormSet.
2192 @param Handle PackageList Handle
2193 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2194 GUID), take the first FormSet found in package
2196 @param FormSet FormSet data structure.
2198 @retval EFI_SUCCESS The function completed successfully.
2199 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2204 IN EFI_HII_HANDLE Handle
,
2205 IN OUT EFI_GUID
*FormSetGuid
,
2206 OUT FORM_BROWSER_FORMSET
*FormSet
2210 EFI_HANDLE DriverHandle
;
2213 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2214 if (EFI_ERROR (Status
)) {
2218 FormSet
->HiiHandle
= Handle
;
2219 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2222 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2224 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2225 if (EFI_ERROR (Status
)) {
2228 FormSet
->DriverHandle
= DriverHandle
;
2229 Status
= gBS
->HandleProtocol (
2231 &gEfiHiiConfigAccessProtocolGuid
,
2232 (VOID
**) &FormSet
->ConfigAccess
2234 if (EFI_ERROR (Status
)) {
2236 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2237 // list, then there will be no configuration action required
2239 FormSet
->ConfigAccess
= NULL
;
2243 // Parse the IFR binary OpCodes
2245 Status
= ParseOpCodes (FormSet
);
2246 if (EFI_ERROR (Status
)) {
2250 gClassOfVfr
= FormSet
->SubClass
;
2251 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2252 FrontPageHandle
= FormSet
->HiiHandle
;
2256 // Match GUID to find out the function key setting. If match fail, use the default setting.
2258 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2259 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2261 // Update the function key setting.
2263 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2265 // Function key prompt can not be displayed if the function key has been disabled.
2267 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2268 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2271 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2272 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2275 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2276 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2279 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2280 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);