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
;
225 Status
= EFI_SUCCESS
;
226 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
229 // Seed the dimensions in the global
231 gST
->ConOut
->QueryMode (
233 gST
->ConOut
->Mode
->Mode
,
234 &gScreenDimensions
.RightColumn
,
235 &gScreenDimensions
.BottomRow
238 if (ScreenDimensions
!= NULL
) {
240 // Check local dimension vs. global dimension.
242 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
243 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
245 return EFI_INVALID_PARAMETER
;
248 // Local dimension validation.
250 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
251 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
252 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
254 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
255 SCROLL_ARROW_HEIGHT
*
257 FRONT_PAGE_HEADER_HEIGHT
+
262 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
264 return EFI_INVALID_PARAMETER
;
269 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
270 gHelpBlockWidth
= gOptionBlockWidth
;
271 gPromptBlockWidth
= gOptionBlockWidth
;
274 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
276 InitializeBrowserStrings ();
278 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
279 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
282 // Ensure we are in Text mode
284 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
) || IsListEmpty (&FormSet
->FormListHead
)) {
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
)) {
520 Initialize Setup Browser driver.
522 @param ImageHandle The image handle.
523 @param SystemTable The system table.
525 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
526 @return Other value if failed to initialize the Setup Browser module.
532 IN EFI_HANDLE ImageHandle
,
533 IN EFI_SYSTEM_TABLE
*SystemTable
537 EFI_HANDLE HiiDriverHandle
;
538 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
541 // Locate required Hii relative protocols
543 Status
= gBS
->LocateProtocol (
544 &gEfiHiiDatabaseProtocolGuid
,
546 (VOID
**) &mHiiDatabase
548 ASSERT_EFI_ERROR (Status
);
550 Status
= gBS
->LocateProtocol (
551 &gEfiHiiStringProtocolGuid
,
553 (VOID
**) &mHiiString
555 ASSERT_EFI_ERROR (Status
);
557 Status
= gBS
->LocateProtocol (
558 &gEfiHiiConfigRoutingProtocolGuid
,
560 (VOID
**) &mHiiConfigRouting
562 ASSERT_EFI_ERROR (Status
);
565 // Publish our HII data
567 Status
= HiiLibCreateHiiDriverHandle (&HiiDriverHandle
);
568 ASSERT_EFI_ERROR (Status
);
570 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
571 ASSERT (PackageList
!= NULL
);
572 Status
= mHiiDatabase
->NewPackageList (
578 ASSERT_EFI_ERROR (Status
);
581 // Initialize Driver private data
583 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
584 ASSERT (BannerData
!= NULL
);
587 // Install FormBrowser2 protocol
589 mPrivateData
.Handle
= NULL
;
590 Status
= gBS
->InstallProtocolInterface (
591 &mPrivateData
.Handle
,
592 &gEfiFormBrowser2ProtocolGuid
,
593 EFI_NATIVE_INTERFACE
,
594 &mPrivateData
.FormBrowser2
596 ASSERT_EFI_ERROR (Status
);
599 // Install Print protocol
601 Status
= gBS
->InstallProtocolInterface (
602 &mPrivateData
.Handle
,
603 &gEfiPrint2ProtocolGuid
,
604 EFI_NATIVE_INTERFACE
,
609 // Install Ecp Print protocol, which is defined in
610 // Edk\Foundation\Protocol\Print\Print.h with protocol
611 // GUID of { 0xdf2d868e, 0x32fc, 0x4cf0, {0x8e, 0x6b, 0xff, 0xd9, 0x5d, 0x13, 0x43, 0xd0 }}
612 // This is support previous module that written to consume this protocol.
614 Status
= gBS
->InstallProtocolInterface (
615 &mPrivateData
.Handle
,
616 &gEfiPrintProtocolGuid
,
617 EFI_NATIVE_INTERFACE
,
626 Create a new string in HII Package List.
628 @param String The String to be added
629 @param HiiHandle The package list in the HII database to insert the
632 @return The output string.
638 IN EFI_HII_HANDLE HiiHandle
641 EFI_STRING_ID StringId
;
645 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
646 ASSERT_EFI_ERROR (Status
);
653 Delete a string from HII Package List.
655 @param StringId Id of the string in HII database.
656 @param HiiHandle The HII package list handle.
658 @retval EFI_SUCCESS The string was deleted successfully.
663 IN EFI_STRING_ID StringId
,
664 IN EFI_HII_HANDLE HiiHandle
669 NullChar
= CHAR_NULL
;
670 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
675 Get the string based on the StringId and HII Package List Handle.
677 @param Token The String's ID.
678 @param HiiHandle The package list in the HII database to search for
679 the specified string.
681 @return The output string.
686 IN EFI_STRING_ID Token
,
687 IN EFI_HII_HANDLE HiiHandle
695 // Set default string size assumption at no more than 256 bytes
697 BufferLength
= 0x100;
698 String
= AllocateZeroPool (BufferLength
);
699 ASSERT (String
!= NULL
);
701 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
703 if (Status
== EFI_BUFFER_TOO_SMALL
) {
704 gBS
->FreePool (String
);
705 String
= AllocateZeroPool (BufferLength
);
706 ASSERT (String
!= NULL
);
708 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
710 ASSERT_EFI_ERROR (Status
);
717 Allocate new memory and then copy the Unicode string Source to Destination.
719 @param Dest Location to copy string
720 @param Src String to copy
725 IN OUT CHAR16
**Dest
,
732 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
733 ASSERT (*Dest
!= NULL
);
738 Allocate new memory and concatinate Source on the end of Destination.
740 @param Dest String to added to the end of.
741 @param Src String to concatinate.
746 IN OUT CHAR16
**Dest
,
754 NewStringCpy (Dest
, Src
);
758 TmpSize
= StrSize (*Dest
);
759 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
760 ASSERT (NewString
!= NULL
);
762 StrCpy (NewString
, *Dest
);
763 StrCat (NewString
, Src
);
765 gBS
->FreePool (*Dest
);
771 Synchronize Storage's Edit copy to Shadow copy.
773 @param Storage The Storage to be synchronized.
778 IN FORMSET_STORAGE
*Storage
782 NAME_VALUE_NODE
*Node
;
784 switch (Storage
->Type
) {
785 case EFI_HII_VARSTORE_BUFFER
:
786 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
789 case EFI_HII_VARSTORE_NAME_VALUE
:
790 Link
= GetFirstNode (&Storage
->NameValueListHead
);
791 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
792 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
794 NewStringCpy (&Node
->Value
, Node
->EditValue
);
796 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
800 case EFI_HII_VARSTORE_EFI_VARIABLE
:
808 Get Value for given Name from a NameValue Storage.
810 @param Storage The NameValue Storage.
811 @param Name The Name.
812 @param Value The retured Value.
814 @retval EFI_SUCCESS Value found for given Name.
815 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
820 IN FORMSET_STORAGE
*Storage
,
822 IN OUT CHAR16
**Value
826 NAME_VALUE_NODE
*Node
;
830 Link
= GetFirstNode (&Storage
->NameValueListHead
);
831 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
832 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
834 if (StrCmp (Name
, Node
->Name
) == 0) {
835 NewStringCpy (Value
, Node
->EditValue
);
839 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
842 return EFI_NOT_FOUND
;
847 Set Value of given Name in a NameValue Storage.
849 @param Storage The NameValue Storage.
850 @param Name The Name.
851 @param Value The Value to set.
853 @retval EFI_SUCCESS Value found for given Name.
854 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
859 IN FORMSET_STORAGE
*Storage
,
865 NAME_VALUE_NODE
*Node
;
867 Link
= GetFirstNode (&Storage
->NameValueListHead
);
868 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
869 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
871 if (StrCmp (Name
, Node
->Name
) == 0) {
872 if (Node
->EditValue
!= NULL
) {
873 FreePool (Node
->EditValue
);
875 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
876 ASSERT (Node
->EditValue
!= NULL
);
880 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
883 return EFI_NOT_FOUND
;
888 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
890 @param Storage The Storage to be conveted.
891 @param ConfigResp The returned <ConfigResp>.
893 @retval EFI_SUCCESS Convert success.
894 @retval EFI_INVALID_PARAMETER Incorrect storage type.
898 StorageToConfigResp (
899 IN FORMSET_STORAGE
*Storage
,
900 IN CHAR16
**ConfigResp
906 NAME_VALUE_NODE
*Node
;
908 Status
= EFI_SUCCESS
;
910 switch (Storage
->Type
) {
911 case EFI_HII_VARSTORE_BUFFER
:
912 Status
= mHiiConfigRouting
->BlockToConfig (
914 Storage
->ConfigRequest
,
922 case EFI_HII_VARSTORE_NAME_VALUE
:
924 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
926 Link
= GetFirstNode (&Storage
->NameValueListHead
);
927 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
928 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
930 NewStringCat (ConfigResp
, L
"&");
931 NewStringCat (ConfigResp
, Node
->Name
);
932 NewStringCat (ConfigResp
, L
"=");
933 NewStringCat (ConfigResp
, Node
->EditValue
);
935 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
939 case EFI_HII_VARSTORE_EFI_VARIABLE
:
941 Status
= EFI_INVALID_PARAMETER
;
950 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
952 @param Storage The Storage to receive the settings.
953 @param ConfigResp The <ConfigResp> to be converted.
955 @retval EFI_SUCCESS Convert success.
956 @retval EFI_INVALID_PARAMETER Incorrect storage type.
960 ConfigRespToStorage (
961 IN FORMSET_STORAGE
*Storage
,
962 IN CHAR16
*ConfigResp
972 Status
= EFI_SUCCESS
;
974 switch (Storage
->Type
) {
975 case EFI_HII_VARSTORE_BUFFER
:
976 BufferSize
= Storage
->Size
;
977 Status
= mHiiConfigRouting
->ConfigToBlock (
986 case EFI_HII_VARSTORE_NAME_VALUE
:
987 StrPtr
= StrStr (ConfigResp
, L
"&");
988 while (StrPtr
!= NULL
) {
994 StrPtr
= StrStr (StrPtr
, L
"=");
995 if (StrPtr
== NULL
) {
1003 StrPtr
= StrPtr
+ 1;
1005 StrPtr
= StrStr (StrPtr
, L
"&");
1006 if (StrPtr
!= NULL
) {
1009 SetValueByName (Storage
, Name
, Value
);
1013 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1015 Status
= EFI_INVALID_PARAMETER
;
1024 Get Question's current Value.
1026 @param FormSet FormSet data structure.
1027 @param Form Form data structure.
1028 @param Question Question to be initialized.
1029 @param Cached TRUE: get from Edit copy FALSE: get from original
1032 @retval EFI_SUCCESS The function completed successfully.
1037 IN FORM_BROWSER_FORMSET
*FormSet
,
1038 IN FORM_BROWSER_FORM
*Form
,
1039 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1049 FORMSET_STORAGE
*Storage
;
1050 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1051 CHAR16
*ConfigRequest
;
1057 BOOLEAN IsBufferStorage
;
1060 Status
= EFI_SUCCESS
;
1063 // Statement don't have storage, skip them
1065 if (Question
->QuestionId
== 0) {
1070 // Question value is provided by an Expression, evaluate it
1072 if (Question
->ValueExpression
!= NULL
) {
1073 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1074 if (!EFI_ERROR (Status
)) {
1075 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1081 // Question value is provided by RTC
1083 Storage
= Question
->Storage
;
1084 QuestionValue
= &Question
->HiiValue
.Value
;
1085 if (Storage
== NULL
) {
1087 // It's a Question without storage, or RTC date/time
1089 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1091 // Date and time define the same Flags bit
1093 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1094 case QF_DATE_STORAGE_TIME
:
1095 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1098 case QF_DATE_STORAGE_WAKEUP
:
1099 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1102 case QF_DATE_STORAGE_NORMAL
:
1105 // For date/time without storage
1110 if (EFI_ERROR (Status
)) {
1114 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1115 QuestionValue
->date
.Year
= EfiTime
.Year
;
1116 QuestionValue
->date
.Month
= EfiTime
.Month
;
1117 QuestionValue
->date
.Day
= EfiTime
.Day
;
1119 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1120 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1121 QuestionValue
->time
.Second
= EfiTime
.Second
;
1129 // Question value is provided by EFI variable
1131 StorageWidth
= Question
->StorageWidth
;
1132 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1133 if (Question
->BufferValue
!= NULL
) {
1134 Dst
= Question
->BufferValue
;
1136 Dst
= (UINT8
*) QuestionValue
;
1139 Status
= gRT
->GetVariable (
1140 Question
->VariableName
,
1147 // Always return success, even this EFI variable doesn't exist
1153 // Question Value is provided by Buffer Storage or NameValue Storage
1155 if (Question
->BufferValue
!= NULL
) {
1157 // This Question is password or orderedlist
1159 Dst
= Question
->BufferValue
;
1162 // Other type of Questions
1164 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1167 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1168 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1170 if (IsBufferStorage
) {
1172 // Copy from storage Edit buffer
1174 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1176 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1177 if (EFI_ERROR (Status
)) {
1183 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1185 Length
= StorageWidth
+ sizeof (CHAR16
);
1186 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1188 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1191 gBS
->FreePool (Value
);
1195 // Request current settings from Configuration Driver
1197 if (FormSet
->ConfigAccess
== NULL
) {
1198 return EFI_NOT_FOUND
;
1202 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1203 // <ConfigHdr> + "&" + <VariableName>
1205 if (IsBufferStorage
) {
1206 Length
= StrLen (Storage
->ConfigHdr
);
1207 Length
+= StrLen (Question
->BlockName
);
1209 Length
= StrLen (Storage
->ConfigHdr
);
1210 Length
+= StrLen (Question
->VariableName
) + 1;
1212 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1213 ASSERT (ConfigRequest
!= NULL
);
1215 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1216 if (IsBufferStorage
) {
1217 StrCat (ConfigRequest
, Question
->BlockName
);
1219 StrCat (ConfigRequest
, L
"&");
1220 StrCat (ConfigRequest
, Question
->VariableName
);
1223 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1224 FormSet
->ConfigAccess
,
1229 if (EFI_ERROR (Status
)) {
1234 // Skip <ConfigRequest>
1236 Value
= Result
+ Length
;
1237 if (IsBufferStorage
) {
1243 if (*Value
!= '=') {
1244 gBS
->FreePool (Result
);
1245 return EFI_NOT_FOUND
;
1248 // Skip '=', point to value
1253 // Suppress <AltResp> if any
1256 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1261 if (!IsBufferStorage
&& IsString
) {
1263 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1265 Length
= StorageWidth
+ sizeof (CHAR16
);
1266 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1268 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1269 if (EFI_ERROR (Status
)) {
1270 gBS
->FreePool (Result
);
1276 // Synchronize Edit Buffer
1278 if (IsBufferStorage
) {
1279 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1281 SetValueByName (Storage
, Question
->VariableName
, Value
);
1283 gBS
->FreePool (Result
);
1291 Save Question Value to edit copy(cached) or Storage(uncached).
1293 @param FormSet FormSet data structure.
1294 @param Form Form data structure.
1295 @param Question Pointer to the Question.
1296 @param Cached TRUE: set to Edit copy FALSE: set to original
1299 @retval EFI_SUCCESS The function completed successfully.
1304 IN FORM_BROWSER_FORMSET
*FormSet
,
1305 IN FORM_BROWSER_FORM
*Form
,
1306 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1317 FORMSET_STORAGE
*Storage
;
1318 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1323 BOOLEAN IsBufferStorage
;
1326 Status
= EFI_SUCCESS
;
1329 // Statement don't have storage, skip them
1331 if (Question
->QuestionId
== 0) {
1336 // If Question value is provided by an Expression, then it is read only
1338 if (Question
->ValueExpression
!= NULL
) {
1343 // Question value is provided by RTC
1345 Storage
= Question
->Storage
;
1346 QuestionValue
= &Question
->HiiValue
.Value
;
1347 if (Storage
== NULL
) {
1349 // It's a Question without storage, or RTC date/time
1351 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1353 // Date and time define the same Flags bit
1355 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1356 case QF_DATE_STORAGE_TIME
:
1357 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1360 case QF_DATE_STORAGE_WAKEUP
:
1361 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1364 case QF_DATE_STORAGE_NORMAL
:
1367 // For date/time without storage
1372 if (EFI_ERROR (Status
)) {
1376 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1377 EfiTime
.Year
= QuestionValue
->date
.Year
;
1378 EfiTime
.Month
= QuestionValue
->date
.Month
;
1379 EfiTime
.Day
= QuestionValue
->date
.Day
;
1381 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1382 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1383 EfiTime
.Second
= QuestionValue
->time
.Second
;
1386 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1387 Status
= gRT
->SetTime (&EfiTime
);
1389 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1397 // Question value is provided by EFI variable
1399 StorageWidth
= Question
->StorageWidth
;
1400 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1401 if (Question
->BufferValue
!= NULL
) {
1402 Src
= Question
->BufferValue
;
1404 Src
= (UINT8
*) QuestionValue
;
1407 Status
= gRT
->SetVariable (
1408 Question
->VariableName
,
1410 Storage
->Attributes
,
1418 // Question Value is provided by Buffer Storage or NameValue Storage
1420 if (Question
->BufferValue
!= NULL
) {
1421 Src
= Question
->BufferValue
;
1423 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1426 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1427 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1428 if (IsBufferStorage
) {
1430 // Copy to storage edit buffer
1432 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1436 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1439 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1440 Value
= AllocateZeroPool (BufferLen
);
1441 ASSERT (Value
!= NULL
);
1442 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1443 ASSERT_EFI_ERROR (Status
);
1445 BufferLen
= StorageWidth
* 2 + 1;
1446 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1447 ASSERT (Value
!= NULL
);
1448 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1452 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1453 gBS
->FreePool (Value
);
1458 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1459 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1461 if (IsBufferStorage
) {
1462 Length
= StrLen (Question
->BlockName
) + 7;
1464 Length
= StrLen (Question
->VariableName
) + 2;
1466 if (!IsBufferStorage
&& IsString
) {
1467 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1469 Length
+= (StorageWidth
* 2);
1471 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1472 ASSERT (ConfigResp
!= NULL
);
1474 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1475 if (IsBufferStorage
) {
1476 StrCat (ConfigResp
, Question
->BlockName
);
1477 StrCat (ConfigResp
, L
"&VALUE=");
1479 StrCat (ConfigResp
, L
"&");
1480 StrCat (ConfigResp
, Question
->VariableName
);
1481 StrCat (ConfigResp
, L
"=");
1484 Value
= ConfigResp
+ StrLen (ConfigResp
);
1485 if (!IsBufferStorage
&& IsString
) {
1487 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1489 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1490 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1491 ASSERT_EFI_ERROR (Status
);
1493 BufferLen
= StorageWidth
* 2 + 1;
1494 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1499 // Submit Question Value to Configuration Driver
1501 if (FormSet
->ConfigAccess
!= NULL
) {
1502 Status
= FormSet
->ConfigAccess
->RouteConfig (
1503 FormSet
->ConfigAccess
,
1507 if (EFI_ERROR (Status
)) {
1508 gBS
->FreePool (ConfigResp
);
1512 gBS
->FreePool (ConfigResp
);
1515 // Synchronize shadow Buffer
1517 SynchronizeStorage (Storage
);
1525 Perform inconsistent check for a Form.
1527 @param FormSet FormSet data structure.
1528 @param Form Form data structure.
1529 @param Question The Question to be validated.
1530 @param Type Validation type: InConsistent or NoSubmit
1532 @retval EFI_SUCCESS Form validation pass.
1533 @retval other Form validation failed.
1538 IN FORM_BROWSER_FORMSET
*FormSet
,
1539 IN FORM_BROWSER_FORM
*Form
,
1540 IN FORM_BROWSER_STATEMENT
*Question
,
1546 LIST_ENTRY
*ListHead
;
1549 FORM_EXPRESSION
*Expression
;
1551 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1552 ListHead
= &Question
->InconsistentListHead
;
1553 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1554 ListHead
= &Question
->NoSubmitListHead
;
1556 return EFI_UNSUPPORTED
;
1559 Link
= GetFirstNode (ListHead
);
1560 while (!IsNull (ListHead
, Link
)) {
1561 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1564 // Evaluate the expression
1566 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1567 if (EFI_ERROR (Status
)) {
1571 if (Expression
->Result
.Value
.b
) {
1573 // Condition meet, show up error message
1575 if (Expression
->Error
!= 0) {
1576 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1578 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1579 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1580 gBS
->FreePool (PopUp
);
1583 return EFI_NOT_READY
;
1586 Link
= GetNextNode (ListHead
, Link
);
1594 Perform NoSubmit check for a Form.
1596 @param FormSet FormSet data structure.
1597 @param Form Form data structure.
1599 @retval EFI_SUCCESS Form validation pass.
1600 @retval other Form validation failed.
1605 IN FORM_BROWSER_FORMSET
*FormSet
,
1606 IN FORM_BROWSER_FORM
*Form
1611 FORM_BROWSER_STATEMENT
*Question
;
1613 Link
= GetFirstNode (&Form
->StatementListHead
);
1614 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1615 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1617 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1618 if (EFI_ERROR (Status
)) {
1622 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1632 @param FormSet FormSet data structure.
1633 @param Form Form data structure.
1635 @retval EFI_SUCCESS The function completed successfully.
1640 IN FORM_BROWSER_FORMSET
*FormSet
,
1641 IN FORM_BROWSER_FORM
*Form
1646 EFI_STRING ConfigResp
;
1647 EFI_STRING Progress
;
1648 FORMSET_STORAGE
*Storage
;
1651 // Validate the Form by NoSubmit check
1653 Status
= NoSubmitCheck (FormSet
, Form
);
1654 if (EFI_ERROR (Status
)) {
1659 // Submit Buffer storage or Name/Value storage
1661 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1662 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1663 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1664 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1666 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1671 // Skip if there is no RequestElement
1673 if (Storage
->ElementCount
== 0) {
1678 // Prepare <ConfigResp>
1680 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1681 if (EFI_ERROR (Status
)) {
1686 // Send <ConfigResp> to Configuration Driver
1688 if (FormSet
->ConfigAccess
!= NULL
) {
1689 Status
= FormSet
->ConfigAccess
->RouteConfig (
1690 FormSet
->ConfigAccess
,
1694 if (EFI_ERROR (Status
)) {
1695 gBS
->FreePool (ConfigResp
);
1699 gBS
->FreePool (ConfigResp
);
1702 // Config success, update storage shadow Buffer
1704 SynchronizeStorage (Storage
);
1707 gNvUpdateRequired
= FALSE
;
1714 Reset Question to its default value.
1716 @param FormSet The form set.
1717 @param Form The form.
1718 @param Question The question.
1719 @param DefaultId The Class of the default.
1721 @retval EFI_SUCCESS Question is reset to default value.
1725 GetQuestionDefault (
1726 IN FORM_BROWSER_FORMSET
*FormSet
,
1727 IN FORM_BROWSER_FORM
*Form
,
1728 IN FORM_BROWSER_STATEMENT
*Question
,
1734 QUESTION_DEFAULT
*Default
;
1735 QUESTION_OPTION
*Option
;
1736 EFI_HII_VALUE
*HiiValue
;
1739 Status
= EFI_SUCCESS
;
1742 // Statement don't have storage, skip them
1744 if (Question
->QuestionId
== 0) {
1749 // There are three ways to specify default value for a Question:
1750 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1751 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1752 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1754 HiiValue
= &Question
->HiiValue
;
1757 // EFI_IFR_DEFAULT has highest priority
1759 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1760 Link
= GetFirstNode (&Question
->DefaultListHead
);
1761 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1762 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1764 if (Default
->DefaultId
== DefaultId
) {
1765 if (Default
->ValueExpression
!= NULL
) {
1767 // Default is provided by an Expression, evaluate it
1769 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1770 if (EFI_ERROR (Status
)) {
1774 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1777 // Default value is embedded in EFI_IFR_DEFAULT
1779 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1785 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1790 // EFI_ONE_OF_OPTION
1792 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1793 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1795 // OneOfOption could only provide Standard and Manufacturing default
1797 Link
= GetFirstNode (&Question
->OptionListHead
);
1798 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1799 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1801 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1802 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1804 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1809 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1815 // EFI_IFR_CHECKBOX - lowest priority
1817 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1818 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1820 // Checkbox could only provide Standard and Manufacturing default
1822 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1823 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1825 HiiValue
->Value
.b
= TRUE
;
1827 HiiValue
->Value
.b
= FALSE
;
1835 // For Questions without default
1837 switch (Question
->Operand
) {
1838 case EFI_IFR_NUMERIC_OP
:
1840 // Take minimal value as numeric's default value
1842 HiiValue
->Value
.u64
= Question
->Minimum
;
1845 case EFI_IFR_ONE_OF_OP
:
1847 // Take first oneof option as oneof's default value
1849 Link
= GetFirstNode (&Question
->OptionListHead
);
1850 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1851 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1852 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1856 case EFI_IFR_ORDERED_LIST_OP
:
1858 // Take option sequence in IFR as ordered list's default value
1861 Link
= GetFirstNode (&Question
->OptionListHead
);
1862 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1863 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1865 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1868 if (Index
>= Question
->MaxContainers
) {
1872 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1877 Status
= EFI_NOT_FOUND
;
1886 Reset Questions in a Form to their default value.
1888 @param FormSet FormSet data structure.
1889 @param Form The Form which to be reset.
1890 @param DefaultId The Class of the default.
1892 @retval EFI_SUCCESS The function completed successfully.
1896 ExtractFormDefault (
1897 IN FORM_BROWSER_FORMSET
*FormSet
,
1898 IN FORM_BROWSER_FORM
*Form
,
1904 FORM_BROWSER_STATEMENT
*Question
;
1906 Link
= GetFirstNode (&Form
->StatementListHead
);
1907 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1908 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1909 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1912 // If Question is suppressed, don't reset it to default
1914 if (Question
->SuppressExpression
!= NULL
) {
1915 Status
= EvaluateExpression (FormSet
, Form
, Question
->SuppressExpression
);
1916 if (!EFI_ERROR (Status
) && Question
->SuppressExpression
->Result
.Value
.b
) {
1922 // Reset Question to its default value
1924 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1925 if (EFI_ERROR (Status
)) {
1930 // Synchronize Buffer storage's Edit buffer
1932 if ((Question
->Storage
!= NULL
) &&
1933 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1934 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1943 Initialize Question's Edit copy from Storage.
1945 @param FormSet FormSet data structure.
1946 @param Form Form data structure.
1948 @retval EFI_SUCCESS The function completed successfully.
1953 IN FORM_BROWSER_FORMSET
*FormSet
,
1954 IN FORM_BROWSER_FORM
*Form
1959 FORM_BROWSER_STATEMENT
*Question
;
1961 Link
= GetFirstNode (&Form
->StatementListHead
);
1962 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1963 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1966 // Initialize local copy of Value for each Question
1968 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1969 if (EFI_ERROR (Status
)) {
1973 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1981 Fill storage's edit copy with settings requested from Configuration Driver.
1983 @param FormSet FormSet data structure.
1984 @param Storage Buffer Storage.
1986 @retval EFI_SUCCESS The function completed successfully.
1991 IN FORM_BROWSER_FORMSET
*FormSet
,
1992 IN FORMSET_STORAGE
*Storage
1996 EFI_STRING Progress
;
2000 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2004 if (FormSet
->ConfigAccess
== NULL
) {
2005 return EFI_NOT_FOUND
;
2008 if (Storage
->ElementCount
== 0) {
2010 // Skip if there is no RequestElement
2016 // Request current settings from Configuration Driver
2018 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2019 FormSet
->ConfigAccess
,
2020 Storage
->ConfigRequest
,
2024 if (EFI_ERROR (Status
)) {
2029 // Convert Result from <ConfigAltResp> to <ConfigResp>
2031 StrPtr
= StrStr (Result
, L
"ALTCFG");
2032 if (StrPtr
!= NULL
) {
2036 Status
= ConfigRespToStorage (Storage
, Result
);
2037 gBS
->FreePool (Result
);
2043 Get current setting of Questions.
2045 @param FormSet FormSet data structure.
2047 @retval EFI_SUCCESS The function completed successfully.
2051 InitializeCurrentSetting (
2052 IN OUT FORM_BROWSER_FORMSET
*FormSet
2056 FORMSET_STORAGE
*Storage
;
2057 FORM_BROWSER_FORM
*Form
;
2061 // Extract default from IFR binary
2063 Link
= GetFirstNode (&FormSet
->FormListHead
);
2064 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2065 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2067 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2069 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2073 // Request current settings from Configuration Driver
2075 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2076 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2077 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2079 Status
= LoadStorage (FormSet
, Storage
);
2082 // Now Edit Buffer is filled with default values(lower priority) and current
2083 // settings(higher priority), sychronize it to shadow Buffer
2085 if (!EFI_ERROR (Status
)) {
2086 SynchronizeStorage (Storage
);
2089 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2097 Fetch the Ifr binary data of a FormSet.
2099 @param Handle PackageList Handle
2100 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2101 GUID), take the first FormSet found in package
2103 @param BinaryLength The length of the FormSet IFR binary.
2104 @param BinaryData The buffer designed to receive the FormSet.
2106 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2107 BufferLength was updated.
2108 @retval EFI_INVALID_PARAMETER The handle is unknown.
2109 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2110 be found with the requested FormId.
2115 IN EFI_HII_HANDLE Handle
,
2116 IN OUT EFI_GUID
*FormSetGuid
,
2117 OUT UINTN
*BinaryLength
,
2118 OUT UINT8
**BinaryData
2122 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2128 BOOLEAN ReturnDefault
;
2129 UINT32 PackageListLength
;
2130 EFI_HII_PACKAGE_HEADER PackageHeader
;
2134 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2137 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2139 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2140 ReturnDefault
= TRUE
;
2142 ReturnDefault
= FALSE
;
2146 // Get HII PackageList
2149 HiiPackageList
= NULL
;
2150 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2151 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2152 HiiPackageList
= AllocatePool (BufferSize
);
2153 ASSERT (HiiPackageList
!= NULL
);
2155 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2157 if (EFI_ERROR (Status
)) {
2162 // Get Form package from this HII package List
2164 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2166 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2168 while (Offset
< PackageListLength
) {
2169 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2170 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2172 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
2174 // Search FormSet in this Form Package
2176 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2177 while (Offset2
< PackageHeader
.Length
) {
2178 OpCodeData
= Package
+ Offset2
;
2180 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2182 // Check whether return default FormSet
2184 if (ReturnDefault
) {
2189 // FormSet GUID is specified, check it
2191 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2196 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2199 if (Offset2
< PackageHeader
.Length
) {
2201 // Target formset found
2207 Offset
+= PackageHeader
.Length
;
2210 if (Offset
>= PackageListLength
) {
2212 // Form package not found in this Package List
2214 gBS
->FreePool (HiiPackageList
);
2215 return EFI_NOT_FOUND
;
2218 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2220 // Return the default FormSet GUID
2222 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2226 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2227 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2228 // of the Form Package.
2230 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2231 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2233 gBS
->FreePool (HiiPackageList
);
2235 if (*BinaryData
== NULL
) {
2236 return EFI_OUT_OF_RESOURCES
;
2244 Initialize the internal data structure of a FormSet.
2246 @param Handle PackageList Handle
2247 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2248 GUID), take the first FormSet found in package
2250 @param FormSet FormSet data structure.
2252 @retval EFI_SUCCESS The function completed successfully.
2253 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2258 IN EFI_HII_HANDLE Handle
,
2259 IN OUT EFI_GUID
*FormSetGuid
,
2260 OUT FORM_BROWSER_FORMSET
*FormSet
2264 EFI_HANDLE DriverHandle
;
2267 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2268 if (EFI_ERROR (Status
)) {
2272 FormSet
->HiiHandle
= Handle
;
2273 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2276 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2278 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2279 if (EFI_ERROR (Status
)) {
2282 FormSet
->DriverHandle
= DriverHandle
;
2283 Status
= gBS
->HandleProtocol (
2285 &gEfiHiiConfigAccessProtocolGuid
,
2286 (VOID
**) &FormSet
->ConfigAccess
2288 if (EFI_ERROR (Status
)) {
2290 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2291 // list, then there will be no configuration action required
2293 FormSet
->ConfigAccess
= NULL
;
2297 // Parse the IFR binary OpCodes
2299 Status
= ParseOpCodes (FormSet
);
2300 if (EFI_ERROR (Status
)) {
2304 gClassOfVfr
= FormSet
->SubClass
;
2305 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2306 FrontPageHandle
= FormSet
->HiiHandle
;
2310 // Match GUID to find out the function key setting. If match fail, use the default setting.
2312 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2313 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2315 // Update the function key setting.
2317 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2319 // Function key prompt can not be displayed if the function key has been disabled.
2321 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2322 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2325 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2326 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2329 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2330 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2333 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2334 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);