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 UnicodeVSPrintAsciiFormat
,
31 AsciiVSPrintUnicodeFormat
,
36 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
37 EFI_HII_STRING_PROTOCOL
*mHiiString
;
38 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
40 BANNER_DATA
*BannerData
;
41 EFI_HII_HANDLE FrontPageHandle
;
43 UINTN gFunctionKeySetting
;
44 BOOLEAN gResetRequired
;
45 BOOLEAN gNvUpdateRequired
;
46 EFI_HII_HANDLE gHiiHandle
;
48 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
53 // Browser Global Strings
55 CHAR16
*gFunctionOneString
;
56 CHAR16
*gFunctionTwoString
;
57 CHAR16
*gFunctionNineString
;
58 CHAR16
*gFunctionTenString
;
60 CHAR16
*gEnterCommitString
;
61 CHAR16
*gEnterEscapeString
;
62 CHAR16
*gEscapeString
;
64 CHAR16
*gMoveHighlight
;
65 CHAR16
*gMakeSelection
;
66 CHAR16
*gDecNumericInput
;
67 CHAR16
*gHexNumericInput
;
68 CHAR16
*gToggleCheckBox
;
69 CHAR16
*gPromptForData
;
70 CHAR16
*gPromptForPassword
;
71 CHAR16
*gPromptForNewPassword
;
72 CHAR16
*gConfirmPassword
;
73 CHAR16
*gConfirmError
;
74 CHAR16
*gPassowordInvalid
;
83 CHAR16
*gAdjustNumber
;
85 CHAR16
*gOptionMismatch
;
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
[] = {
116 NONE_FUNCTION_KEY_SETTING
137 NONE_FUNCTION_KEY_SETTING
158 NONE_FUNCTION_KEY_SETTING
161 // BMM File Explorer FormSet.
179 NONE_FUNCTION_KEY_SETTING
184 This is the routine which an external caller uses to direct the browser
185 where to obtain it's information.
188 @param This The Form Browser protocol instanse.
189 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
190 display a list of the formsets for the handles specified.
191 @param HandleCount The number of Handles specified in Handle.
192 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
193 field in the EFI_IFR_FORM_SET op-code for the specified
194 forms-based package. If FormSetGuid is NULL, then this
195 function will display the first found forms package.
196 @param FormId This field specifies which EFI_IFR_FORM to render as the first
197 displayable page. If this field has a value of 0x0000, then
198 the forms browser will render the specified forms in their encoded order.
199 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
201 @param ActionRequest Points to the action recommended by the form.
203 @retval EFI_SUCCESS The function completed successfully.
204 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
205 @retval EFI_NOT_FOUND No valid forms could be found to display.
211 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
212 IN EFI_HII_HANDLE
*Handles
,
213 IN UINTN HandleCount
,
214 IN EFI_GUID
*FormSetGuid
, OPTIONAL
215 IN UINT16 FormId
, OPTIONAL
216 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
217 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
221 UI_MENU_SELECTION
*Selection
;
223 FORM_BROWSER_FORMSET
*FormSet
;
224 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
226 Status
= EFI_SUCCESS
;
227 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
230 // Seed the dimensions in the global
232 gST
->ConOut
->QueryMode (
234 gST
->ConOut
->Mode
->Mode
,
235 &gScreenDimensions
.RightColumn
,
236 &gScreenDimensions
.BottomRow
239 if (ScreenDimensions
!= NULL
) {
241 // Check local dimension vs. global dimension.
243 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
244 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
246 return EFI_INVALID_PARAMETER
;
249 // Local dimension validation.
251 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
252 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
253 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
255 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
256 SCROLL_ARROW_HEIGHT
*
258 FRONT_PAGE_HEADER_HEIGHT
+
263 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
265 return EFI_INVALID_PARAMETER
;
270 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
271 gHelpBlockWidth
= gOptionBlockWidth
;
272 gPromptBlockWidth
= gOptionBlockWidth
;
275 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
277 InitializeBrowserStrings ();
279 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
280 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
283 // Ensure we are in Text mode
285 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
287 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
288 if (EFI_ERROR (Status
)) {
292 // Set console control to text mode.
294 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);
296 for (Index
= 0; Index
< HandleCount
; Index
++) {
297 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
298 ASSERT (Selection
!= NULL
);
300 Selection
->Handle
= Handles
[Index
];
301 if (FormSetGuid
!= NULL
) {
302 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
303 Selection
->FormId
= FormId
;
307 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
308 ASSERT (FormSet
!= NULL
);
311 // Initialize internal data structures of FormSet
313 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
314 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
315 DestroyFormSet (FormSet
);
318 Selection
->FormSet
= FormSet
;
321 // Initialize current settings of Questions in this FormSet
323 Status
= InitializeCurrentSetting (FormSet
);
324 if (EFI_ERROR (Status
)) {
325 DestroyFormSet (FormSet
);
330 // Display this formset
332 gCurrentSelection
= Selection
;
334 Status
= SetupBrowser (Selection
);
336 gCurrentSelection
= NULL
;
337 DestroyFormSet (FormSet
);
339 if (EFI_ERROR (Status
)) {
343 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
345 FreePool (Selection
);
348 if (ActionRequest
!= NULL
) {
349 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
350 if (gResetRequired
) {
351 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
355 FreeBrowserStrings ();
357 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
358 gST
->ConOut
->ClearScreen (gST
->ConOut
);
365 This function is called by a callback handler to retrieve uncommitted state
366 data from the browser.
368 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
370 @param ResultsDataSize A pointer to the size of the buffer associated
372 @param ResultsData A string returned from an IFR browser or
373 equivalent. The results string will have no
374 routing information in them.
375 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
376 (if RetrieveData = TRUE) data from the uncommitted
377 browser state information or set (if RetrieveData
378 = FALSE) data in the uncommitted browser state
380 @param VariableGuid An optional field to indicate the target variable
382 @param VariableName An optional field to indicate the target
383 human-readable variable name.
385 @retval EFI_SUCCESS The results have been distributed or are awaiting
387 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
388 contain the results data.
394 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
395 IN OUT UINTN
*ResultsDataSize
,
396 IN OUT EFI_STRING ResultsData
,
397 IN BOOLEAN RetrieveData
,
398 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
399 IN CONST CHAR16
*VariableName OPTIONAL
404 FORMSET_STORAGE
*Storage
;
405 FORM_BROWSER_FORMSET
*FormSet
;
412 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
413 return EFI_INVALID_PARAMETER
;
416 if (gCurrentSelection
== NULL
) {
417 return EFI_NOT_READY
;
422 FormSet
= gCurrentSelection
->FormSet
;
425 // Find target storage
427 Link
= GetFirstNode (&FormSet
->StorageListHead
);
428 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
429 return EFI_UNSUPPORTED
;
432 if (VariableGuid
!= NULL
) {
434 // Try to find target storage
437 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
438 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
439 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
441 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
442 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
444 // Buffer storage require both GUID and Name
446 if (VariableName
== NULL
) {
447 return EFI_NOT_FOUND
;
450 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
460 return EFI_NOT_FOUND
;
464 // GUID/Name is not specified, take the first storage in FormSet
466 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
471 // Skip if there is no RequestElement
473 if (Storage
->ElementCount
== 0) {
478 // Generate <ConfigResp>
480 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
481 if (EFI_ERROR (Status
)) {
486 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
488 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
490 BufferSize
= StrSize (StrPtr
);
491 if (*ResultsDataSize
< BufferSize
) {
492 *ResultsDataSize
= BufferSize
;
494 FreePool (ConfigResp
);
495 return EFI_BUFFER_TOO_SMALL
;
498 *ResultsDataSize
= BufferSize
;
499 CopyMem (ResultsData
, StrPtr
, BufferSize
);
501 FreePool (ConfigResp
);
504 // Prepare <ConfigResp>
506 TmpSize
= StrLen (ResultsData
);
507 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
508 ConfigResp
= AllocateZeroPool (BufferSize
);
509 ASSERT (ConfigResp
!= NULL
);
511 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
512 StrCat (ConfigResp
, L
"&");
513 StrCat (ConfigResp
, ResultsData
);
516 // Update Browser uncommited data
518 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
519 if (EFI_ERROR (Status
)) {
529 Initialize Setup Browser driver.
531 @param ImageHandle The image handle.
532 @param SystemTable The system table.
534 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
535 @return Other value if failed to initialize the Setup Browser module.
541 IN EFI_HANDLE ImageHandle
,
542 IN EFI_SYSTEM_TABLE
*SystemTable
546 EFI_HANDLE HiiDriverHandle
;
547 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
550 // Locate required Hii relative protocols
552 Status
= gBS
->LocateProtocol (
553 &gEfiHiiDatabaseProtocolGuid
,
555 (VOID
**) &mHiiDatabase
557 ASSERT_EFI_ERROR (Status
);
559 Status
= gBS
->LocateProtocol (
560 &gEfiHiiStringProtocolGuid
,
562 (VOID
**) &mHiiString
564 ASSERT_EFI_ERROR (Status
);
566 Status
= gBS
->LocateProtocol (
567 &gEfiHiiConfigRoutingProtocolGuid
,
569 (VOID
**) &mHiiConfigRouting
571 ASSERT_EFI_ERROR (Status
);
574 // Publish our HII data
576 Status
= HiiLibCreateHiiDriverHandle (&HiiDriverHandle
);
577 ASSERT_EFI_ERROR (Status
);
579 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
580 ASSERT (PackageList
!= NULL
);
581 Status
= mHiiDatabase
->NewPackageList (
587 ASSERT_EFI_ERROR (Status
);
590 // Initialize Driver private data
592 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
593 ASSERT (BannerData
!= NULL
);
596 // Install FormBrowser2 protocol
598 mPrivateData
.Handle
= NULL
;
599 Status
= gBS
->InstallProtocolInterface (
600 &mPrivateData
.Handle
,
601 &gEfiFormBrowser2ProtocolGuid
,
602 EFI_NATIVE_INTERFACE
,
603 &mPrivateData
.FormBrowser2
605 ASSERT_EFI_ERROR (Status
);
608 // Install Print protocol
610 Status
= gBS
->InstallProtocolInterface (
611 &mPrivateData
.Handle
,
612 &gEfiPrint2ProtocolGuid
,
613 EFI_NATIVE_INTERFACE
,
618 // Install Ecp Print protocol, which is defined in
619 // Edk\Foundation\Protocol\Print\Print.h with protocol
620 // GUID of { 0xdf2d868e, 0x32fc, 0x4cf0, {0x8e, 0x6b, 0xff, 0xd9, 0x5d, 0x13, 0x43, 0xd0 }}
621 // This is support previous module that written to consume this protocol.
623 Status
= gBS
->InstallProtocolInterface (
624 &mPrivateData
.Handle
,
625 &gEfiPrintProtocolGuid
,
626 EFI_NATIVE_INTERFACE
,
635 Create a new string in HII Package List.
637 @param String The String to be added
638 @param HiiHandle The package list in the HII database to insert the
641 @return The output string.
647 IN EFI_HII_HANDLE HiiHandle
650 EFI_STRING_ID StringId
;
654 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
655 ASSERT_EFI_ERROR (Status
);
662 Delete a string from HII Package List.
664 @param StringId Id of the string in HII database.
665 @param HiiHandle The HII package list handle.
667 @retval EFI_SUCCESS The string was deleted successfully.
672 IN EFI_STRING_ID StringId
,
673 IN EFI_HII_HANDLE HiiHandle
678 NullChar
= CHAR_NULL
;
679 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
684 Get the string based on the StringId and HII Package List Handle.
686 @param Token The String's ID.
687 @param HiiHandle The package list in the HII database to search for
688 the specified string.
690 @return The output string.
695 IN EFI_STRING_ID Token
,
696 IN EFI_HII_HANDLE HiiHandle
704 // Set default string size assumption at no more than 256 bytes
706 BufferLength
= 0x100;
707 String
= AllocateZeroPool (BufferLength
);
708 ASSERT (String
!= NULL
);
710 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
712 if (Status
== EFI_BUFFER_TOO_SMALL
) {
714 String
= AllocateZeroPool (BufferLength
);
715 ASSERT (String
!= NULL
);
717 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
719 ASSERT_EFI_ERROR (Status
);
726 Allocate new memory and then copy the Unicode string Source to Destination.
728 @param Dest Location to copy string
729 @param Src String to copy
734 IN OUT CHAR16
**Dest
,
741 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
742 ASSERT (*Dest
!= NULL
);
747 Allocate new memory and concatinate Source on the end of Destination.
749 @param Dest String to added to the end of.
750 @param Src String to concatinate.
755 IN OUT CHAR16
**Dest
,
763 NewStringCpy (Dest
, Src
);
767 TmpSize
= StrSize (*Dest
);
768 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
769 ASSERT (NewString
!= NULL
);
771 StrCpy (NewString
, *Dest
);
772 StrCat (NewString
, Src
);
780 Synchronize Storage's Edit copy to Shadow copy.
782 @param Storage The Storage to be synchronized.
787 IN FORMSET_STORAGE
*Storage
791 NAME_VALUE_NODE
*Node
;
793 switch (Storage
->Type
) {
794 case EFI_HII_VARSTORE_BUFFER
:
795 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
798 case EFI_HII_VARSTORE_NAME_VALUE
:
799 Link
= GetFirstNode (&Storage
->NameValueListHead
);
800 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
801 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
803 NewStringCpy (&Node
->Value
, Node
->EditValue
);
805 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
809 case EFI_HII_VARSTORE_EFI_VARIABLE
:
817 Get Value for given Name from a NameValue Storage.
819 @param Storage The NameValue Storage.
820 @param Name The Name.
821 @param Value The retured Value.
823 @retval EFI_SUCCESS Value found for given Name.
824 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
829 IN FORMSET_STORAGE
*Storage
,
831 IN OUT CHAR16
**Value
835 NAME_VALUE_NODE
*Node
;
839 Link
= GetFirstNode (&Storage
->NameValueListHead
);
840 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
841 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
843 if (StrCmp (Name
, Node
->Name
) == 0) {
844 NewStringCpy (Value
, Node
->EditValue
);
848 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
851 return EFI_NOT_FOUND
;
856 Set Value of given Name in a NameValue Storage.
858 @param Storage The NameValue Storage.
859 @param Name The Name.
860 @param Value The Value to set.
862 @retval EFI_SUCCESS Value found for given Name.
863 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
868 IN FORMSET_STORAGE
*Storage
,
874 NAME_VALUE_NODE
*Node
;
876 Link
= GetFirstNode (&Storage
->NameValueListHead
);
877 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
878 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
880 if (StrCmp (Name
, Node
->Name
) == 0) {
881 if (Node
->EditValue
!= NULL
) {
882 FreePool (Node
->EditValue
);
884 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
885 ASSERT (Node
->EditValue
!= NULL
);
889 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
892 return EFI_NOT_FOUND
;
897 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
899 @param Storage The Storage to be conveted.
900 @param ConfigResp The returned <ConfigResp>.
902 @retval EFI_SUCCESS Convert success.
903 @retval EFI_INVALID_PARAMETER Incorrect storage type.
907 StorageToConfigResp (
908 IN FORMSET_STORAGE
*Storage
,
909 IN CHAR16
**ConfigResp
915 NAME_VALUE_NODE
*Node
;
917 Status
= EFI_SUCCESS
;
919 switch (Storage
->Type
) {
920 case EFI_HII_VARSTORE_BUFFER
:
921 Status
= mHiiConfigRouting
->BlockToConfig (
923 Storage
->ConfigRequest
,
931 case EFI_HII_VARSTORE_NAME_VALUE
:
933 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
935 Link
= GetFirstNode (&Storage
->NameValueListHead
);
936 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
937 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
939 NewStringCat (ConfigResp
, L
"&");
940 NewStringCat (ConfigResp
, Node
->Name
);
941 NewStringCat (ConfigResp
, L
"=");
942 NewStringCat (ConfigResp
, Node
->EditValue
);
944 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
948 case EFI_HII_VARSTORE_EFI_VARIABLE
:
950 Status
= EFI_INVALID_PARAMETER
;
959 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
961 @param Storage The Storage to receive the settings.
962 @param ConfigResp The <ConfigResp> to be converted.
964 @retval EFI_SUCCESS Convert success.
965 @retval EFI_INVALID_PARAMETER Incorrect storage type.
969 ConfigRespToStorage (
970 IN FORMSET_STORAGE
*Storage
,
971 IN CHAR16
*ConfigResp
981 Status
= EFI_SUCCESS
;
983 switch (Storage
->Type
) {
984 case EFI_HII_VARSTORE_BUFFER
:
985 BufferSize
= Storage
->Size
;
986 Status
= mHiiConfigRouting
->ConfigToBlock (
995 case EFI_HII_VARSTORE_NAME_VALUE
:
996 StrPtr
= StrStr (ConfigResp
, L
"&");
997 while (StrPtr
!= NULL
) {
1001 StrPtr
= StrPtr
+ 1;
1003 StrPtr
= StrStr (StrPtr
, L
"=");
1004 if (StrPtr
== NULL
) {
1012 StrPtr
= StrPtr
+ 1;
1014 StrPtr
= StrStr (StrPtr
, L
"&");
1015 if (StrPtr
!= NULL
) {
1018 SetValueByName (Storage
, Name
, Value
);
1022 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1024 Status
= EFI_INVALID_PARAMETER
;
1033 Get Question's current Value.
1035 @param FormSet FormSet data structure.
1036 @param Form Form data structure.
1037 @param Question Question to be initialized.
1038 @param Cached TRUE: get from Edit copy FALSE: get from original
1041 @retval EFI_SUCCESS The function completed successfully.
1046 IN FORM_BROWSER_FORMSET
*FormSet
,
1047 IN FORM_BROWSER_FORM
*Form
,
1048 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1058 FORMSET_STORAGE
*Storage
;
1059 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1060 CHAR16
*ConfigRequest
;
1066 BOOLEAN IsBufferStorage
;
1069 Status
= EFI_SUCCESS
;
1072 // Statement don't have storage, skip them
1074 if (Question
->QuestionId
== 0) {
1079 // Question value is provided by an Expression, evaluate it
1081 if (Question
->ValueExpression
!= NULL
) {
1082 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1083 if (!EFI_ERROR (Status
)) {
1084 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1090 // Question value is provided by RTC
1092 Storage
= Question
->Storage
;
1093 QuestionValue
= &Question
->HiiValue
.Value
;
1094 if (Storage
== NULL
) {
1096 // It's a Question without storage, or RTC date/time
1098 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1100 // Date and time define the same Flags bit
1102 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1103 case QF_DATE_STORAGE_TIME
:
1104 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1107 case QF_DATE_STORAGE_WAKEUP
:
1108 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1111 case QF_DATE_STORAGE_NORMAL
:
1114 // For date/time without storage
1119 if (EFI_ERROR (Status
)) {
1123 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1124 QuestionValue
->date
.Year
= EfiTime
.Year
;
1125 QuestionValue
->date
.Month
= EfiTime
.Month
;
1126 QuestionValue
->date
.Day
= EfiTime
.Day
;
1128 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1129 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1130 QuestionValue
->time
.Second
= EfiTime
.Second
;
1138 // Question value is provided by EFI variable
1140 StorageWidth
= Question
->StorageWidth
;
1141 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1142 if (Question
->BufferValue
!= NULL
) {
1143 Dst
= Question
->BufferValue
;
1145 Dst
= (UINT8
*) QuestionValue
;
1148 Status
= gRT
->GetVariable (
1149 Question
->VariableName
,
1156 // Always return success, even this EFI variable doesn't exist
1162 // Question Value is provided by Buffer Storage or NameValue Storage
1164 if (Question
->BufferValue
!= NULL
) {
1166 // This Question is password or orderedlist
1168 Dst
= Question
->BufferValue
;
1171 // Other type of Questions
1173 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1176 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1177 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1179 if (IsBufferStorage
) {
1181 // Copy from storage Edit buffer
1183 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1185 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1186 if (EFI_ERROR (Status
)) {
1192 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1194 Length
= StorageWidth
+ sizeof (CHAR16
);
1195 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1197 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1204 // Request current settings from Configuration Driver
1206 if (FormSet
->ConfigAccess
== NULL
) {
1207 return EFI_NOT_FOUND
;
1211 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1212 // <ConfigHdr> + "&" + <VariableName>
1214 if (IsBufferStorage
) {
1215 Length
= StrLen (Storage
->ConfigHdr
);
1216 Length
+= StrLen (Question
->BlockName
);
1218 Length
= StrLen (Storage
->ConfigHdr
);
1219 Length
+= StrLen (Question
->VariableName
) + 1;
1221 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1222 ASSERT (ConfigRequest
!= NULL
);
1224 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1225 if (IsBufferStorage
) {
1226 StrCat (ConfigRequest
, Question
->BlockName
);
1228 StrCat (ConfigRequest
, L
"&");
1229 StrCat (ConfigRequest
, Question
->VariableName
);
1232 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1233 FormSet
->ConfigAccess
,
1238 if (EFI_ERROR (Status
)) {
1243 // Skip <ConfigRequest>
1245 Value
= Result
+ Length
;
1246 if (IsBufferStorage
) {
1252 if (*Value
!= '=') {
1254 return EFI_NOT_FOUND
;
1257 // Skip '=', point to value
1262 // Suppress <AltResp> if any
1265 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1270 if (!IsBufferStorage
&& IsString
) {
1272 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1274 Length
= StorageWidth
+ sizeof (CHAR16
);
1275 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1277 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1278 if (EFI_ERROR (Status
)) {
1285 // Synchronize Edit Buffer
1287 if (IsBufferStorage
) {
1288 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1290 SetValueByName (Storage
, Question
->VariableName
, Value
);
1300 Save Question Value to edit copy(cached) or Storage(uncached).
1302 @param FormSet FormSet data structure.
1303 @param Form Form data structure.
1304 @param Question Pointer to the Question.
1305 @param Cached TRUE: set to Edit copy FALSE: set to original
1308 @retval EFI_SUCCESS The function completed successfully.
1313 IN FORM_BROWSER_FORMSET
*FormSet
,
1314 IN FORM_BROWSER_FORM
*Form
,
1315 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1326 FORMSET_STORAGE
*Storage
;
1327 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1332 BOOLEAN IsBufferStorage
;
1335 Status
= EFI_SUCCESS
;
1338 // Statement don't have storage, skip them
1340 if (Question
->QuestionId
== 0) {
1345 // If Question value is provided by an Expression, then it is read only
1347 if (Question
->ValueExpression
!= NULL
) {
1352 // Question value is provided by RTC
1354 Storage
= Question
->Storage
;
1355 QuestionValue
= &Question
->HiiValue
.Value
;
1356 if (Storage
== NULL
) {
1358 // It's a Question without storage, or RTC date/time
1360 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1362 // Date and time define the same Flags bit
1364 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1365 case QF_DATE_STORAGE_TIME
:
1366 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1369 case QF_DATE_STORAGE_WAKEUP
:
1370 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1373 case QF_DATE_STORAGE_NORMAL
:
1376 // For date/time without storage
1381 if (EFI_ERROR (Status
)) {
1385 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1386 EfiTime
.Year
= QuestionValue
->date
.Year
;
1387 EfiTime
.Month
= QuestionValue
->date
.Month
;
1388 EfiTime
.Day
= QuestionValue
->date
.Day
;
1390 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1391 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1392 EfiTime
.Second
= QuestionValue
->time
.Second
;
1395 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1396 Status
= gRT
->SetTime (&EfiTime
);
1398 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1406 // Question value is provided by EFI variable
1408 StorageWidth
= Question
->StorageWidth
;
1409 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1410 if (Question
->BufferValue
!= NULL
) {
1411 Src
= Question
->BufferValue
;
1413 Src
= (UINT8
*) QuestionValue
;
1416 Status
= gRT
->SetVariable (
1417 Question
->VariableName
,
1419 Storage
->Attributes
,
1427 // Question Value is provided by Buffer Storage or NameValue Storage
1429 if (Question
->BufferValue
!= NULL
) {
1430 Src
= Question
->BufferValue
;
1432 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1435 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1436 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1437 if (IsBufferStorage
) {
1439 // Copy to storage edit buffer
1441 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1445 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1448 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1449 Value
= AllocateZeroPool (BufferLen
);
1450 ASSERT (Value
!= NULL
);
1451 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1452 ASSERT_EFI_ERROR (Status
);
1454 BufferLen
= StorageWidth
* 2 + 1;
1455 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1456 ASSERT (Value
!= NULL
);
1457 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1461 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1467 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1468 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1470 if (IsBufferStorage
) {
1471 Length
= StrLen (Question
->BlockName
) + 7;
1473 Length
= StrLen (Question
->VariableName
) + 2;
1475 if (!IsBufferStorage
&& IsString
) {
1476 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1478 Length
+= (StorageWidth
* 2);
1480 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1481 ASSERT (ConfigResp
!= NULL
);
1483 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1484 if (IsBufferStorage
) {
1485 StrCat (ConfigResp
, Question
->BlockName
);
1486 StrCat (ConfigResp
, L
"&VALUE=");
1488 StrCat (ConfigResp
, L
"&");
1489 StrCat (ConfigResp
, Question
->VariableName
);
1490 StrCat (ConfigResp
, L
"=");
1493 Value
= ConfigResp
+ StrLen (ConfigResp
);
1494 if (!IsBufferStorage
&& IsString
) {
1496 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1498 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1499 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1500 ASSERT_EFI_ERROR (Status
);
1502 BufferLen
= StorageWidth
* 2 + 1;
1503 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1508 // Submit Question Value to Configuration Driver
1510 if (FormSet
->ConfigAccess
!= NULL
) {
1511 Status
= FormSet
->ConfigAccess
->RouteConfig (
1512 FormSet
->ConfigAccess
,
1516 if (EFI_ERROR (Status
)) {
1517 FreePool (ConfigResp
);
1521 FreePool (ConfigResp
);
1524 // Synchronize shadow Buffer
1526 SynchronizeStorage (Storage
);
1534 Perform inconsistent check for a Form.
1536 @param FormSet FormSet data structure.
1537 @param Form Form data structure.
1538 @param Question The Question to be validated.
1539 @param Type Validation type: InConsistent or NoSubmit
1541 @retval EFI_SUCCESS Form validation pass.
1542 @retval other Form validation failed.
1547 IN FORM_BROWSER_FORMSET
*FormSet
,
1548 IN FORM_BROWSER_FORM
*Form
,
1549 IN FORM_BROWSER_STATEMENT
*Question
,
1555 LIST_ENTRY
*ListHead
;
1558 FORM_EXPRESSION
*Expression
;
1560 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1561 ListHead
= &Question
->InconsistentListHead
;
1562 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1563 ListHead
= &Question
->NoSubmitListHead
;
1565 return EFI_UNSUPPORTED
;
1568 Link
= GetFirstNode (ListHead
);
1569 while (!IsNull (ListHead
, Link
)) {
1570 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1573 // Evaluate the expression
1575 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1576 if (EFI_ERROR (Status
)) {
1580 if (Expression
->Result
.Value
.b
) {
1582 // Condition meet, show up error message
1584 if (Expression
->Error
!= 0) {
1585 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1587 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1588 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1592 return EFI_NOT_READY
;
1595 Link
= GetNextNode (ListHead
, Link
);
1603 Perform NoSubmit check for a Form.
1605 @param FormSet FormSet data structure.
1606 @param Form Form data structure.
1608 @retval EFI_SUCCESS Form validation pass.
1609 @retval other Form validation failed.
1614 IN FORM_BROWSER_FORMSET
*FormSet
,
1615 IN FORM_BROWSER_FORM
*Form
1620 FORM_BROWSER_STATEMENT
*Question
;
1622 Link
= GetFirstNode (&Form
->StatementListHead
);
1623 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1624 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1626 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1627 if (EFI_ERROR (Status
)) {
1631 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1641 @param FormSet FormSet data structure.
1642 @param Form Form data structure.
1644 @retval EFI_SUCCESS The function completed successfully.
1649 IN FORM_BROWSER_FORMSET
*FormSet
,
1650 IN FORM_BROWSER_FORM
*Form
1655 EFI_STRING ConfigResp
;
1656 EFI_STRING Progress
;
1657 FORMSET_STORAGE
*Storage
;
1660 // Validate the Form by NoSubmit check
1662 Status
= NoSubmitCheck (FormSet
, Form
);
1663 if (EFI_ERROR (Status
)) {
1668 // Submit Buffer storage or Name/Value storage
1670 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1671 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1672 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1673 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1675 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1680 // Skip if there is no RequestElement
1682 if (Storage
->ElementCount
== 0) {
1687 // Prepare <ConfigResp>
1689 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1690 if (EFI_ERROR (Status
)) {
1695 // Send <ConfigResp> to Configuration Driver
1697 if (FormSet
->ConfigAccess
!= NULL
) {
1698 Status
= FormSet
->ConfigAccess
->RouteConfig (
1699 FormSet
->ConfigAccess
,
1703 if (EFI_ERROR (Status
)) {
1704 FreePool (ConfigResp
);
1708 FreePool (ConfigResp
);
1711 // Config success, update storage shadow Buffer
1713 SynchronizeStorage (Storage
);
1716 gNvUpdateRequired
= FALSE
;
1723 Reset Question to its default value.
1725 @param FormSet The form set.
1726 @param Form The form.
1727 @param Question The question.
1728 @param DefaultId The Class of the default.
1730 @retval EFI_SUCCESS Question is reset to default value.
1734 GetQuestionDefault (
1735 IN FORM_BROWSER_FORMSET
*FormSet
,
1736 IN FORM_BROWSER_FORM
*Form
,
1737 IN FORM_BROWSER_STATEMENT
*Question
,
1743 QUESTION_DEFAULT
*Default
;
1744 QUESTION_OPTION
*Option
;
1745 EFI_HII_VALUE
*HiiValue
;
1748 Status
= EFI_SUCCESS
;
1751 // Statement don't have storage, skip them
1753 if (Question
->QuestionId
== 0) {
1758 // There are three ways to specify default value for a Question:
1759 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1760 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1761 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1763 HiiValue
= &Question
->HiiValue
;
1766 // EFI_IFR_DEFAULT has highest priority
1768 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1769 Link
= GetFirstNode (&Question
->DefaultListHead
);
1770 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1771 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1773 if (Default
->DefaultId
== DefaultId
) {
1774 if (Default
->ValueExpression
!= NULL
) {
1776 // Default is provided by an Expression, evaluate it
1778 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1779 if (EFI_ERROR (Status
)) {
1783 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1786 // Default value is embedded in EFI_IFR_DEFAULT
1788 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1794 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1799 // EFI_ONE_OF_OPTION
1801 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1802 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1804 // OneOfOption could only provide Standard and Manufacturing default
1806 Link
= GetFirstNode (&Question
->OptionListHead
);
1807 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1808 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1810 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1811 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1813 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1818 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1824 // EFI_IFR_CHECKBOX - lowest priority
1826 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1827 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1829 // Checkbox could only provide Standard and Manufacturing default
1831 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1832 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1834 HiiValue
->Value
.b
= TRUE
;
1836 HiiValue
->Value
.b
= FALSE
;
1844 // For Questions without default
1846 switch (Question
->Operand
) {
1847 case EFI_IFR_NUMERIC_OP
:
1849 // Take minimal value as numeric's default value
1851 HiiValue
->Value
.u64
= Question
->Minimum
;
1854 case EFI_IFR_ONE_OF_OP
:
1856 // Take first oneof option as oneof's default value
1858 Link
= GetFirstNode (&Question
->OptionListHead
);
1859 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1860 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1861 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1865 case EFI_IFR_ORDERED_LIST_OP
:
1867 // Take option sequence in IFR as ordered list's default value
1870 Link
= GetFirstNode (&Question
->OptionListHead
);
1871 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1872 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1874 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1877 if (Index
>= Question
->MaxContainers
) {
1881 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1886 Status
= EFI_NOT_FOUND
;
1895 Reset Questions in a Form to their default value.
1897 @param FormSet FormSet data structure.
1898 @param Form The Form which to be reset.
1899 @param DefaultId The Class of the default.
1901 @retval EFI_SUCCESS The function completed successfully.
1905 ExtractFormDefault (
1906 IN FORM_BROWSER_FORMSET
*FormSet
,
1907 IN FORM_BROWSER_FORM
*Form
,
1913 FORM_BROWSER_STATEMENT
*Question
;
1915 Link
= GetFirstNode (&Form
->StatementListHead
);
1916 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1917 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1918 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1921 // If Question is suppressed, don't reset it to default
1923 if (Question
->SuppressExpression
!= NULL
) {
1924 Status
= EvaluateExpression (FormSet
, Form
, Question
->SuppressExpression
);
1925 if (!EFI_ERROR (Status
) && Question
->SuppressExpression
->Result
.Value
.b
) {
1931 // Reset Question to its default value
1933 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1934 if (EFI_ERROR (Status
)) {
1939 // Synchronize Buffer storage's Edit buffer
1941 if ((Question
->Storage
!= NULL
) &&
1942 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1943 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1952 Initialize Question's Edit copy from Storage.
1954 @param FormSet FormSet data structure.
1955 @param Form Form data structure.
1957 @retval EFI_SUCCESS The function completed successfully.
1962 IN FORM_BROWSER_FORMSET
*FormSet
,
1963 IN FORM_BROWSER_FORM
*Form
1968 FORM_BROWSER_STATEMENT
*Question
;
1970 Link
= GetFirstNode (&Form
->StatementListHead
);
1971 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1972 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1975 // Initialize local copy of Value for each Question
1977 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1978 if (EFI_ERROR (Status
)) {
1982 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1990 Fill storage's edit copy with settings requested from Configuration Driver.
1992 @param FormSet FormSet data structure.
1993 @param Storage Buffer Storage.
1995 @retval EFI_SUCCESS The function completed successfully.
2000 IN FORM_BROWSER_FORMSET
*FormSet
,
2001 IN FORMSET_STORAGE
*Storage
2005 EFI_STRING Progress
;
2009 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2013 if (FormSet
->ConfigAccess
== NULL
) {
2014 return EFI_NOT_FOUND
;
2017 if (Storage
->ElementCount
== 0) {
2019 // Skip if there is no RequestElement
2025 // Request current settings from Configuration Driver
2027 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2028 FormSet
->ConfigAccess
,
2029 Storage
->ConfigRequest
,
2033 if (EFI_ERROR (Status
)) {
2038 // Convert Result from <ConfigAltResp> to <ConfigResp>
2040 StrPtr
= StrStr (Result
, L
"ALTCFG");
2041 if (StrPtr
!= NULL
) {
2045 Status
= ConfigRespToStorage (Storage
, Result
);
2052 Get current setting of Questions.
2054 @param FormSet FormSet data structure.
2056 @retval EFI_SUCCESS The function completed successfully.
2060 InitializeCurrentSetting (
2061 IN OUT FORM_BROWSER_FORMSET
*FormSet
2065 FORMSET_STORAGE
*Storage
;
2066 FORM_BROWSER_FORM
*Form
;
2070 // Extract default from IFR binary
2072 Link
= GetFirstNode (&FormSet
->FormListHead
);
2073 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2074 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2076 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2078 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2082 // Request current settings from Configuration Driver
2084 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2085 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2086 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2088 Status
= LoadStorage (FormSet
, Storage
);
2091 // Now Edit Buffer is filled with default values(lower priority) and current
2092 // settings(higher priority), sychronize it to shadow Buffer
2094 if (!EFI_ERROR (Status
)) {
2095 SynchronizeStorage (Storage
);
2098 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2106 Fetch the Ifr binary data of a FormSet.
2108 @param Handle PackageList Handle
2109 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2110 GUID), take the first FormSet found in package
2112 @param BinaryLength The length of the FormSet IFR binary.
2113 @param BinaryData The buffer designed to receive the FormSet.
2115 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2116 BufferLength was updated.
2117 @retval EFI_INVALID_PARAMETER The handle is unknown.
2118 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2119 be found with the requested FormId.
2124 IN EFI_HII_HANDLE Handle
,
2125 IN OUT EFI_GUID
*FormSetGuid
,
2126 OUT UINTN
*BinaryLength
,
2127 OUT UINT8
**BinaryData
2131 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2137 BOOLEAN ReturnDefault
;
2138 UINT32 PackageListLength
;
2139 EFI_HII_PACKAGE_HEADER PackageHeader
;
2143 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2146 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2148 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2149 ReturnDefault
= TRUE
;
2151 ReturnDefault
= FALSE
;
2155 // Get HII PackageList
2158 HiiPackageList
= NULL
;
2159 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2160 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2161 HiiPackageList
= AllocatePool (BufferSize
);
2162 ASSERT (HiiPackageList
!= NULL
);
2164 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2166 if (EFI_ERROR (Status
)) {
2171 // Get Form package from this HII package List
2173 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2175 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2177 while (Offset
< PackageListLength
) {
2178 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2179 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2181 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2183 // Search FormSet in this Form Package
2185 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2186 while (Offset2
< PackageHeader
.Length
) {
2187 OpCodeData
= Package
+ Offset2
;
2189 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2191 // Check whether return default FormSet
2193 if (ReturnDefault
) {
2198 // FormSet GUID is specified, check it
2200 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2205 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2208 if (Offset2
< PackageHeader
.Length
) {
2210 // Target formset found
2216 Offset
+= PackageHeader
.Length
;
2219 if (Offset
>= PackageListLength
) {
2221 // Form package not found in this Package List
2223 FreePool (HiiPackageList
);
2224 return EFI_NOT_FOUND
;
2227 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2229 // Return the default FormSet GUID
2231 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2235 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2236 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2237 // of the Form Package.
2239 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2240 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2242 FreePool (HiiPackageList
);
2244 if (*BinaryData
== NULL
) {
2245 return EFI_OUT_OF_RESOURCES
;
2253 Initialize the internal data structure of a FormSet.
2255 @param Handle PackageList Handle
2256 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2257 GUID), take the first FormSet found in package
2259 @param FormSet FormSet data structure.
2261 @retval EFI_SUCCESS The function completed successfully.
2262 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2267 IN EFI_HII_HANDLE Handle
,
2268 IN OUT EFI_GUID
*FormSetGuid
,
2269 OUT FORM_BROWSER_FORMSET
*FormSet
2273 EFI_HANDLE DriverHandle
;
2276 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2277 if (EFI_ERROR (Status
)) {
2281 FormSet
->HiiHandle
= Handle
;
2282 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2285 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2287 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2288 if (EFI_ERROR (Status
)) {
2291 FormSet
->DriverHandle
= DriverHandle
;
2292 Status
= gBS
->HandleProtocol (
2294 &gEfiHiiConfigAccessProtocolGuid
,
2295 (VOID
**) &FormSet
->ConfigAccess
2297 if (EFI_ERROR (Status
)) {
2299 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2300 // list, then there will be no configuration action required
2302 FormSet
->ConfigAccess
= NULL
;
2306 // Parse the IFR binary OpCodes
2308 Status
= ParseOpCodes (FormSet
);
2309 if (EFI_ERROR (Status
)) {
2313 gClassOfVfr
= FormSet
->SubClass
;
2314 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2315 FrontPageHandle
= FormSet
->HiiHandle
;
2319 // Match GUID to find out the function key setting. If match fail, use the default setting.
2321 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2322 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2324 // Update the function key setting.
2326 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2328 // Function key prompt can not be displayed if the function key has been disabled.
2330 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2331 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2334 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2335 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2338 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2339 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2342 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2343 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);