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
*gEscapeString
;
63 CHAR16
*gMoveHighlight
;
64 CHAR16
*gMakeSelection
;
65 CHAR16
*gDecNumericInput
;
66 CHAR16
*gHexNumericInput
;
67 CHAR16
*gToggleCheckBox
;
68 CHAR16
*gPromptForData
;
69 CHAR16
*gPromptForPassword
;
70 CHAR16
*gPromptForNewPassword
;
71 CHAR16
*gConfirmPassword
;
72 CHAR16
*gConfirmError
;
73 CHAR16
*gPassowordInvalid
;
82 CHAR16
*gAdjustNumber
;
85 CHAR16 gPromptBlockWidth
;
86 CHAR16 gOptionBlockWidth
;
87 CHAR16 gHelpBlockWidth
;
89 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
90 EFI_GUID gSetupBrowserGuid
= {
91 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
94 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
114 NONE_FUNCTION_KEY_SETTING
135 NONE_FUNCTION_KEY_SETTING
156 NONE_FUNCTION_KEY_SETTING
159 // BMM File Explorer FormSet.
177 NONE_FUNCTION_KEY_SETTING
182 This is the routine which an external caller uses to direct the browser
183 where to obtain it's information.
186 @param This The Form Browser protocol instanse.
187 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
188 display a list of the formsets for the handles specified.
189 @param HandleCount The number of Handles specified in Handle.
190 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
191 field in the EFI_IFR_FORM_SET op-code for the specified
192 forms-based package. If FormSetGuid is NULL, then this
193 function will display the first found forms package.
194 @param FormId This field specifies which EFI_IFR_FORM to render as the first
195 displayable page. If this field has a value of 0x0000, then
196 the forms browser will render the specified forms in their encoded order.
197 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
199 @param ActionRequest Points to the action recommended by the form.
201 @retval EFI_SUCCESS The function completed successfully.
202 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
203 @retval EFI_NOT_FOUND No valid forms could be found to display.
209 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
210 IN EFI_HII_HANDLE
*Handles
,
211 IN UINTN HandleCount
,
212 IN EFI_GUID
*FormSetGuid
, OPTIONAL
213 IN UINT16 FormId
, OPTIONAL
214 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
215 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
219 UI_MENU_SELECTION
*Selection
;
221 FORM_BROWSER_FORMSET
*FormSet
;
223 Status
= EFI_SUCCESS
;
224 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
227 // Seed the dimensions in the global
229 gST
->ConOut
->QueryMode (
231 gST
->ConOut
->Mode
->Mode
,
232 &gScreenDimensions
.RightColumn
,
233 &gScreenDimensions
.BottomRow
236 if (ScreenDimensions
!= NULL
) {
238 // Check local dimension vs. global dimension.
240 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
241 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
243 return EFI_INVALID_PARAMETER
;
246 // Local dimension validation.
248 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
249 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
250 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
252 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
253 SCROLL_ARROW_HEIGHT
*
255 FRONT_PAGE_HEADER_HEIGHT
+
260 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
262 return EFI_INVALID_PARAMETER
;
267 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
268 gHelpBlockWidth
= gOptionBlockWidth
;
269 gPromptBlockWidth
= gOptionBlockWidth
;
272 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
274 InitializeBrowserStrings ();
276 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
277 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
280 // Ensure we are in Text mode
282 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
285 for (Index
= 0; Index
< HandleCount
; Index
++) {
286 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
287 ASSERT (Selection
!= NULL
);
289 Selection
->Handle
= Handles
[Index
];
290 if (FormSetGuid
!= NULL
) {
291 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
292 Selection
->FormId
= FormId
;
296 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
297 ASSERT (FormSet
!= NULL
);
300 // Initialize internal data structures of FormSet
302 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
303 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
304 DestroyFormSet (FormSet
);
307 Selection
->FormSet
= FormSet
;
310 // Initialize current settings of Questions in this FormSet
312 Status
= InitializeCurrentSetting (FormSet
);
313 if (EFI_ERROR (Status
)) {
314 DestroyFormSet (FormSet
);
319 // Display this formset
321 gCurrentSelection
= Selection
;
323 Status
= SetupBrowser (Selection
);
325 gCurrentSelection
= NULL
;
326 DestroyFormSet (FormSet
);
328 if (EFI_ERROR (Status
)) {
332 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
334 gBS
->FreePool (Selection
);
337 if (ActionRequest
!= NULL
) {
338 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
339 if (gResetRequired
) {
340 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
344 FreeBrowserStrings ();
346 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
347 gST
->ConOut
->ClearScreen (gST
->ConOut
);
354 This function is called by a callback handler to retrieve uncommitted state
355 data from the browser.
357 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
359 @param ResultsDataSize A pointer to the size of the buffer associated
361 @param ResultsData A string returned from an IFR browser or
362 equivalent. The results string will have no
363 routing information in them.
364 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
365 (if RetrieveData = TRUE) data from the uncommitted
366 browser state information or set (if RetrieveData
367 = FALSE) data in the uncommitted browser state
369 @param VariableGuid An optional field to indicate the target variable
371 @param VariableName An optional field to indicate the target
372 human-readable variable name.
374 @retval EFI_SUCCESS The results have been distributed or are awaiting
376 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
377 contain the results data.
383 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
384 IN OUT UINTN
*ResultsDataSize
,
385 IN OUT EFI_STRING ResultsData
,
386 IN BOOLEAN RetrieveData
,
387 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
388 IN CONST CHAR16
*VariableName OPTIONAL
393 FORMSET_STORAGE
*Storage
;
394 FORM_BROWSER_FORMSET
*FormSet
;
401 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
402 return EFI_INVALID_PARAMETER
;
405 if (gCurrentSelection
== NULL
) {
406 return EFI_NOT_READY
;
411 FormSet
= gCurrentSelection
->FormSet
;
414 // Find target storage
416 Link
= GetFirstNode (&FormSet
->StorageListHead
);
417 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
418 return EFI_UNSUPPORTED
;
421 if (VariableGuid
!= NULL
) {
423 // Try to find target storage
426 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
427 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
428 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
430 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
431 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
433 // Buffer storage require both GUID and Name
435 if (VariableName
== NULL
) {
436 return EFI_NOT_FOUND
;
439 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
449 return EFI_NOT_FOUND
;
453 // GUID/Name is not specified, take the first storage in FormSet
455 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
460 // Skip if there is no RequestElement
462 if (Storage
->ElementCount
== 0) {
467 // Generate <ConfigResp>
469 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
470 if (EFI_ERROR (Status
)) {
475 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
477 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
479 BufferSize
= StrSize (StrPtr
);
480 if (*ResultsDataSize
< BufferSize
) {
481 *ResultsDataSize
= BufferSize
;
483 gBS
->FreePool (ConfigResp
);
484 return EFI_BUFFER_TOO_SMALL
;
487 *ResultsDataSize
= BufferSize
;
488 CopyMem (ResultsData
, StrPtr
, BufferSize
);
490 gBS
->FreePool (ConfigResp
);
493 // Prepare <ConfigResp>
495 TmpSize
= StrLen (ResultsData
);
496 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
497 ConfigResp
= AllocateZeroPool (BufferSize
);
498 ASSERT (ConfigResp
!= NULL
);
500 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
501 StrCat (ConfigResp
, L
"&");
502 StrCat (ConfigResp
, ResultsData
);
505 // Update Browser uncommited data
507 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
508 if (EFI_ERROR (Status
)) {
518 Initialize Setup Browser driver.
520 @param ImageHandle The image handle.
521 @param SystemTable The system table.
523 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
524 @return Other value if failed to initialize the Setup Browser module.
530 IN EFI_HANDLE ImageHandle
,
531 IN EFI_SYSTEM_TABLE
*SystemTable
535 EFI_HANDLE HiiDriverHandle
;
536 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
539 // Locate required Hii relative protocols
541 Status
= gBS
->LocateProtocol (
542 &gEfiHiiDatabaseProtocolGuid
,
544 (VOID
**) &mHiiDatabase
546 ASSERT_EFI_ERROR (Status
);
548 Status
= gBS
->LocateProtocol (
549 &gEfiHiiStringProtocolGuid
,
551 (VOID
**) &mHiiString
553 ASSERT_EFI_ERROR (Status
);
555 Status
= gBS
->LocateProtocol (
556 &gEfiHiiConfigRoutingProtocolGuid
,
558 (VOID
**) &mHiiConfigRouting
560 ASSERT_EFI_ERROR (Status
);
563 // Publish our HII data
565 Status
= HiiLibCreateHiiDriverHandle (&HiiDriverHandle
);
566 ASSERT_EFI_ERROR (Status
);
568 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
569 ASSERT (PackageList
!= NULL
);
570 Status
= mHiiDatabase
->NewPackageList (
576 ASSERT_EFI_ERROR (Status
);
579 // Initialize Driver private data
581 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
582 ASSERT (BannerData
!= NULL
);
585 // Install FormBrowser2 protocol
587 mPrivateData
.Handle
= NULL
;
588 Status
= gBS
->InstallProtocolInterface (
589 &mPrivateData
.Handle
,
590 &gEfiFormBrowser2ProtocolGuid
,
591 EFI_NATIVE_INTERFACE
,
592 &mPrivateData
.FormBrowser2
594 ASSERT_EFI_ERROR (Status
);
597 // Install Print protocol
599 Status
= gBS
->InstallProtocolInterface (
600 &mPrivateData
.Handle
,
601 &gEfiPrint2ProtocolGuid
,
602 EFI_NATIVE_INTERFACE
,
607 // Install Ecp Print protocol, which is defined in
608 // Edk\Foundation\Protocol\Print\Print.h with protocol
609 // GUID of { 0xdf2d868e, 0x32fc, 0x4cf0, {0x8e, 0x6b, 0xff, 0xd9, 0x5d, 0x13, 0x43, 0xd0 }}
610 // This is support previous module that written to consume this protocol.
612 Status
= gBS
->InstallProtocolInterface (
613 &mPrivateData
.Handle
,
614 &gEfiPrintProtocolGuid
,
615 EFI_NATIVE_INTERFACE
,
624 Create a new string in HII Package List.
626 @param String The String to be added
627 @param HiiHandle The package list in the HII database to insert the
630 @return The output string.
636 IN EFI_HII_HANDLE HiiHandle
639 EFI_STRING_ID StringId
;
643 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
644 ASSERT_EFI_ERROR (Status
);
651 Delete a string from HII Package List.
653 @param StringId Id of the string in HII database.
654 @param HiiHandle The HII package list handle.
656 @retval EFI_SUCCESS The string was deleted successfully.
661 IN EFI_STRING_ID StringId
,
662 IN EFI_HII_HANDLE HiiHandle
667 NullChar
= CHAR_NULL
;
668 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
673 Get the string based on the StringId and HII Package List Handle.
675 @param Token The String's ID.
676 @param HiiHandle The package list in the HII database to search for
677 the specified string.
679 @return The output string.
684 IN EFI_STRING_ID Token
,
685 IN EFI_HII_HANDLE HiiHandle
693 // Set default string size assumption at no more than 256 bytes
695 BufferLength
= 0x100;
696 String
= AllocateZeroPool (BufferLength
);
697 ASSERT (String
!= NULL
);
699 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
701 if (Status
== EFI_BUFFER_TOO_SMALL
) {
702 gBS
->FreePool (String
);
703 String
= AllocateZeroPool (BufferLength
);
704 ASSERT (String
!= NULL
);
706 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
708 ASSERT_EFI_ERROR (Status
);
715 Allocate new memory and then copy the Unicode string Source to Destination.
717 @param Dest Location to copy string
718 @param Src String to copy
723 IN OUT CHAR16
**Dest
,
730 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
731 ASSERT (*Dest
!= NULL
);
736 Allocate new memory and concatinate Source on the end of Destination.
738 @param Dest String to added to the end of.
739 @param Src String to concatinate.
744 IN OUT CHAR16
**Dest
,
752 NewStringCpy (Dest
, Src
);
756 TmpSize
= StrSize (*Dest
);
757 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
758 ASSERT (NewString
!= NULL
);
760 StrCpy (NewString
, *Dest
);
761 StrCat (NewString
, Src
);
763 gBS
->FreePool (*Dest
);
769 Synchronize Storage's Edit copy to Shadow copy.
771 @param Storage The Storage to be synchronized.
776 IN FORMSET_STORAGE
*Storage
780 NAME_VALUE_NODE
*Node
;
782 switch (Storage
->Type
) {
783 case EFI_HII_VARSTORE_BUFFER
:
784 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
787 case EFI_HII_VARSTORE_NAME_VALUE
:
788 Link
= GetFirstNode (&Storage
->NameValueListHead
);
789 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
790 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
792 NewStringCpy (&Node
->Value
, Node
->EditValue
);
794 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
798 case EFI_HII_VARSTORE_EFI_VARIABLE
:
806 Get Value for given Name from a NameValue Storage.
808 @param Storage The NameValue Storage.
809 @param Name The Name.
810 @param Value The retured Value.
812 @retval EFI_SUCCESS Value found for given Name.
813 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
818 IN FORMSET_STORAGE
*Storage
,
820 IN OUT CHAR16
**Value
824 NAME_VALUE_NODE
*Node
;
828 Link
= GetFirstNode (&Storage
->NameValueListHead
);
829 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
830 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
832 if (StrCmp (Name
, Node
->Name
) == 0) {
833 NewStringCpy (Value
, Node
->EditValue
);
837 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
840 return EFI_NOT_FOUND
;
845 Set Value of given Name in a NameValue Storage.
847 @param Storage The NameValue Storage.
848 @param Name The Name.
849 @param Value The Value to set.
851 @retval EFI_SUCCESS Value found for given Name.
852 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
857 IN FORMSET_STORAGE
*Storage
,
863 NAME_VALUE_NODE
*Node
;
865 Link
= GetFirstNode (&Storage
->NameValueListHead
);
866 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
867 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
869 if (StrCmp (Name
, Node
->Name
) == 0) {
870 if (Node
->EditValue
!= NULL
) {
871 FreePool (Node
->EditValue
);
873 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
874 ASSERT (Node
->EditValue
!= NULL
);
878 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
881 return EFI_NOT_FOUND
;
886 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
888 @param Storage The Storage to be conveted.
889 @param ConfigResp The returned <ConfigResp>.
891 @retval EFI_SUCCESS Convert success.
892 @retval EFI_INVALID_PARAMETER Incorrect storage type.
896 StorageToConfigResp (
897 IN FORMSET_STORAGE
*Storage
,
898 IN CHAR16
**ConfigResp
904 NAME_VALUE_NODE
*Node
;
906 Status
= EFI_SUCCESS
;
908 switch (Storage
->Type
) {
909 case EFI_HII_VARSTORE_BUFFER
:
910 Status
= mHiiConfigRouting
->BlockToConfig (
912 Storage
->ConfigRequest
,
920 case EFI_HII_VARSTORE_NAME_VALUE
:
922 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
924 Link
= GetFirstNode (&Storage
->NameValueListHead
);
925 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
926 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
928 NewStringCat (ConfigResp
, L
"&");
929 NewStringCat (ConfigResp
, Node
->Name
);
930 NewStringCat (ConfigResp
, L
"=");
931 NewStringCat (ConfigResp
, Node
->EditValue
);
933 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
937 case EFI_HII_VARSTORE_EFI_VARIABLE
:
939 Status
= EFI_INVALID_PARAMETER
;
948 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
950 @param Storage The Storage to receive the settings.
951 @param ConfigResp The <ConfigResp> to be converted.
953 @retval EFI_SUCCESS Convert success.
954 @retval EFI_INVALID_PARAMETER Incorrect storage type.
958 ConfigRespToStorage (
959 IN FORMSET_STORAGE
*Storage
,
960 IN CHAR16
*ConfigResp
970 Status
= EFI_SUCCESS
;
972 switch (Storage
->Type
) {
973 case EFI_HII_VARSTORE_BUFFER
:
974 BufferSize
= Storage
->Size
;
975 Status
= mHiiConfigRouting
->ConfigToBlock (
984 case EFI_HII_VARSTORE_NAME_VALUE
:
985 StrPtr
= StrStr (ConfigResp
, L
"&");
986 while (StrPtr
!= NULL
) {
992 StrPtr
= StrStr (StrPtr
, L
"=");
993 if (StrPtr
== NULL
) {
1001 StrPtr
= StrPtr
+ 1;
1003 StrPtr
= StrStr (StrPtr
, L
"&");
1004 if (StrPtr
!= NULL
) {
1007 SetValueByName (Storage
, Name
, Value
);
1011 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1013 Status
= EFI_INVALID_PARAMETER
;
1022 Get Question's current Value.
1024 @param FormSet FormSet data structure.
1025 @param Form Form data structure.
1026 @param Question Question to be initialized.
1027 @param Cached TRUE: get from Edit copy FALSE: get from original
1030 @retval EFI_SUCCESS The function completed successfully.
1035 IN FORM_BROWSER_FORMSET
*FormSet
,
1036 IN FORM_BROWSER_FORM
*Form
,
1037 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1047 FORMSET_STORAGE
*Storage
;
1048 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1049 CHAR16
*ConfigRequest
;
1054 BOOLEAN IsBufferStorage
;
1057 Status
= EFI_SUCCESS
;
1060 // Statement don't have storage, skip them
1062 if (Question
->QuestionId
== 0) {
1067 // Question value is provided by an Expression, evaluate it
1069 if (Question
->ValueExpression
!= NULL
) {
1070 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1071 if (!EFI_ERROR (Status
)) {
1072 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1078 // Question value is provided by RTC
1080 Storage
= Question
->Storage
;
1081 QuestionValue
= &Question
->HiiValue
.Value
;
1082 if (Storage
== NULL
) {
1084 // It's a Question without storage, or RTC date/time
1086 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1088 // Date and time define the same Flags bit
1090 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1091 case QF_DATE_STORAGE_TIME
:
1092 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1095 case QF_DATE_STORAGE_WAKEUP
:
1096 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1099 case QF_DATE_STORAGE_NORMAL
:
1102 // For date/time without storage
1107 if (EFI_ERROR (Status
)) {
1111 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1112 QuestionValue
->date
.Year
= EfiTime
.Year
;
1113 QuestionValue
->date
.Month
= EfiTime
.Month
;
1114 QuestionValue
->date
.Day
= EfiTime
.Day
;
1116 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1117 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1118 QuestionValue
->time
.Second
= EfiTime
.Second
;
1126 // Question value is provided by EFI variable
1128 StorageWidth
= Question
->StorageWidth
;
1129 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1130 if (Question
->BufferValue
!= NULL
) {
1131 Dst
= Question
->BufferValue
;
1133 Dst
= (UINT8
*) QuestionValue
;
1136 Status
= gRT
->GetVariable (
1137 Question
->VariableName
,
1144 // Always return success, even this EFI variable doesn't exist
1150 // Question Value is provided by Buffer Storage or NameValue Storage
1152 if (Question
->BufferValue
!= NULL
) {
1154 // This Question is password or orderedlist
1156 Dst
= Question
->BufferValue
;
1159 // Other type of Questions
1161 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1164 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1165 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1167 if (IsBufferStorage
) {
1169 // Copy from storage Edit buffer
1171 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1173 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1174 if (EFI_ERROR (Status
)) {
1180 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1182 Length
= StorageWidth
+ sizeof (CHAR16
);
1183 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1185 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1188 gBS
->FreePool (Value
);
1192 // Request current settings from Configuration Driver
1194 if (FormSet
->ConfigAccess
== NULL
) {
1195 return EFI_NOT_FOUND
;
1199 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1200 // <ConfigHdr> + "&" + <VariableName>
1202 if (IsBufferStorage
) {
1203 Length
= StrLen (Storage
->ConfigHdr
);
1204 Length
+= StrLen (Question
->BlockName
);
1206 Length
= StrLen (Storage
->ConfigHdr
);
1207 Length
+= StrLen (Question
->VariableName
) + 1;
1209 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1210 ASSERT (ConfigRequest
!= NULL
);
1212 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1213 if (IsBufferStorage
) {
1214 StrCat (ConfigRequest
, Question
->BlockName
);
1216 StrCat (ConfigRequest
, L
"&");
1217 StrCat (ConfigRequest
, Question
->VariableName
);
1220 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1221 FormSet
->ConfigAccess
,
1226 if (EFI_ERROR (Status
)) {
1231 // Skip <ConfigRequest>
1233 Value
= Result
+ Length
;
1234 if (IsBufferStorage
) {
1240 if (*Value
!= '=') {
1241 gBS
->FreePool (Result
);
1242 return EFI_NOT_FOUND
;
1245 // Skip '=', point to value
1248 if (!IsBufferStorage
&& IsString
) {
1250 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1252 Length
= StorageWidth
+ sizeof (CHAR16
);
1253 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1255 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1256 if (EFI_ERROR (Status
)) {
1257 gBS
->FreePool (Result
);
1263 // Synchronize Edit Buffer
1265 if (IsBufferStorage
) {
1266 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1268 SetValueByName (Storage
, Question
->VariableName
, Value
);
1270 gBS
->FreePool (Result
);
1278 Save Question Value to edit copy(cached) or Storage(uncached).
1280 @param FormSet FormSet data structure.
1281 @param Form Form data structure.
1282 @param Question Pointer to the Question.
1283 @param Cached TRUE: set to Edit copy FALSE: set to original
1286 @retval EFI_SUCCESS The function completed successfully.
1291 IN FORM_BROWSER_FORMSET
*FormSet
,
1292 IN FORM_BROWSER_FORM
*Form
,
1293 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1304 FORMSET_STORAGE
*Storage
;
1305 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1310 BOOLEAN IsBufferStorage
;
1313 Status
= EFI_SUCCESS
;
1316 // Statement don't have storage, skip them
1318 if (Question
->QuestionId
== 0) {
1323 // If Question value is provided by an Expression, then it is read only
1325 if (Question
->ValueExpression
!= NULL
) {
1330 // Question value is provided by RTC
1332 Storage
= Question
->Storage
;
1333 QuestionValue
= &Question
->HiiValue
.Value
;
1334 if (Storage
== NULL
) {
1336 // It's a Question without storage, or RTC date/time
1338 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1340 // Date and time define the same Flags bit
1342 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1343 case QF_DATE_STORAGE_TIME
:
1344 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1347 case QF_DATE_STORAGE_WAKEUP
:
1348 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1351 case QF_DATE_STORAGE_NORMAL
:
1354 // For date/time without storage
1359 if (EFI_ERROR (Status
)) {
1363 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1364 EfiTime
.Year
= QuestionValue
->date
.Year
;
1365 EfiTime
.Month
= QuestionValue
->date
.Month
;
1366 EfiTime
.Day
= QuestionValue
->date
.Day
;
1368 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1369 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1370 EfiTime
.Second
= QuestionValue
->time
.Second
;
1373 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1374 Status
= gRT
->SetTime (&EfiTime
);
1376 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1384 // Question value is provided by EFI variable
1386 StorageWidth
= Question
->StorageWidth
;
1387 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1388 if (Question
->BufferValue
!= NULL
) {
1389 Src
= Question
->BufferValue
;
1391 Src
= (UINT8
*) QuestionValue
;
1394 Status
= gRT
->SetVariable (
1395 Question
->VariableName
,
1397 Storage
->Attributes
,
1405 // Question Value is provided by Buffer Storage or NameValue Storage
1407 if (Question
->BufferValue
!= NULL
) {
1408 Src
= Question
->BufferValue
;
1410 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1413 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1414 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1415 if (IsBufferStorage
) {
1417 // Copy to storage edit buffer
1419 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1423 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1426 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1427 Value
= AllocateZeroPool (BufferLen
);
1428 ASSERT (Value
!= NULL
);
1429 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1430 ASSERT_EFI_ERROR (Status
);
1432 BufferLen
= StorageWidth
* 2 + 1;
1433 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1434 ASSERT (Value
!= NULL
);
1435 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1439 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1440 gBS
->FreePool (Value
);
1445 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1446 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1448 if (IsBufferStorage
) {
1449 Length
= StrLen (Question
->BlockName
) + 7;
1451 Length
= StrLen (Question
->VariableName
) + 2;
1453 if (!IsBufferStorage
&& IsString
) {
1454 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1456 Length
+= (StorageWidth
* 2);
1458 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1459 ASSERT (ConfigResp
!= NULL
);
1461 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1462 if (IsBufferStorage
) {
1463 StrCat (ConfigResp
, Question
->BlockName
);
1464 StrCat (ConfigResp
, L
"&VALUE=");
1466 StrCat (ConfigResp
, L
"&");
1467 StrCat (ConfigResp
, Question
->VariableName
);
1468 StrCat (ConfigResp
, L
"=");
1471 Value
= ConfigResp
+ StrLen (ConfigResp
);
1472 if (!IsBufferStorage
&& IsString
) {
1474 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1476 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1477 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1478 ASSERT_EFI_ERROR (Status
);
1480 BufferLen
= StorageWidth
* 2 + 1;
1481 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1486 // Submit Question Value to Configuration Driver
1488 if (FormSet
->ConfigAccess
!= NULL
) {
1489 Status
= FormSet
->ConfigAccess
->RouteConfig (
1490 FormSet
->ConfigAccess
,
1494 if (EFI_ERROR (Status
)) {
1495 gBS
->FreePool (ConfigResp
);
1499 gBS
->FreePool (ConfigResp
);
1502 // Synchronize shadow Buffer
1504 SynchronizeStorage (Storage
);
1512 Perform inconsistent check for a Form.
1514 @param FormSet FormSet data structure.
1515 @param Form Form data structure.
1516 @param Question The Question to be validated.
1517 @param Type Validation type: InConsistent or NoSubmit
1519 @retval EFI_SUCCESS Form validation pass.
1520 @retval other Form validation failed.
1525 IN FORM_BROWSER_FORMSET
*FormSet
,
1526 IN FORM_BROWSER_FORM
*Form
,
1527 IN FORM_BROWSER_STATEMENT
*Question
,
1533 LIST_ENTRY
*ListHead
;
1536 FORM_EXPRESSION
*Expression
;
1538 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1539 ListHead
= &Question
->InconsistentListHead
;
1540 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1541 ListHead
= &Question
->NoSubmitListHead
;
1543 return EFI_UNSUPPORTED
;
1546 Link
= GetFirstNode (ListHead
);
1547 while (!IsNull (ListHead
, Link
)) {
1548 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1551 // Evaluate the expression
1553 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1554 if (EFI_ERROR (Status
)) {
1558 if (Expression
->Result
.Value
.b
) {
1560 // Condition meet, show up error message
1562 if (Expression
->Error
!= 0) {
1563 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1565 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1566 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1567 gBS
->FreePool (PopUp
);
1570 return EFI_NOT_READY
;
1573 Link
= GetNextNode (ListHead
, Link
);
1581 Perform NoSubmit check for a Form.
1583 @param FormSet FormSet data structure.
1584 @param Form Form data structure.
1586 @retval EFI_SUCCESS Form validation pass.
1587 @retval other Form validation failed.
1592 IN FORM_BROWSER_FORMSET
*FormSet
,
1593 IN FORM_BROWSER_FORM
*Form
1598 FORM_BROWSER_STATEMENT
*Question
;
1600 Link
= GetFirstNode (&Form
->StatementListHead
);
1601 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1602 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1604 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1605 if (EFI_ERROR (Status
)) {
1609 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1619 @param FormSet FormSet data structure.
1620 @param Form Form data structure.
1622 @retval EFI_SUCCESS The function completed successfully.
1627 IN FORM_BROWSER_FORMSET
*FormSet
,
1628 IN FORM_BROWSER_FORM
*Form
1633 EFI_STRING ConfigResp
;
1634 EFI_STRING Progress
;
1635 FORMSET_STORAGE
*Storage
;
1638 // Validate the Form by NoSubmit check
1640 Status
= NoSubmitCheck (FormSet
, Form
);
1641 if (EFI_ERROR (Status
)) {
1646 // Submit Buffer storage or Name/Value storage
1648 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1649 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1650 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1651 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1653 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1658 // Skip if there is no RequestElement
1660 if (Storage
->ElementCount
== 0) {
1665 // Prepare <ConfigResp>
1667 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1668 if (EFI_ERROR (Status
)) {
1673 // Send <ConfigResp> to Configuration Driver
1675 if (FormSet
->ConfigAccess
!= NULL
) {
1676 Status
= FormSet
->ConfigAccess
->RouteConfig (
1677 FormSet
->ConfigAccess
,
1681 if (EFI_ERROR (Status
)) {
1682 gBS
->FreePool (ConfigResp
);
1686 gBS
->FreePool (ConfigResp
);
1689 // Config success, update storage shadow Buffer
1691 SynchronizeStorage (Storage
);
1694 gNvUpdateRequired
= FALSE
;
1701 Reset Question to its default value.
1703 @param FormSet The form set.
1704 @param Form The form.
1705 @param Question The question.
1706 @param DefaultId The Class of the default.
1708 @retval EFI_SUCCESS Question is reset to default value.
1712 GetQuestionDefault (
1713 IN FORM_BROWSER_FORMSET
*FormSet
,
1714 IN FORM_BROWSER_FORM
*Form
,
1715 IN FORM_BROWSER_STATEMENT
*Question
,
1721 QUESTION_DEFAULT
*Default
;
1722 QUESTION_OPTION
*Option
;
1723 EFI_HII_VALUE
*HiiValue
;
1726 Status
= EFI_SUCCESS
;
1729 // Statement don't have storage, skip them
1731 if (Question
->QuestionId
== 0) {
1736 // There are three ways to specify default value for a Question:
1737 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1738 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1739 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1741 HiiValue
= &Question
->HiiValue
;
1744 // EFI_IFR_DEFAULT has highest priority
1746 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1747 Link
= GetFirstNode (&Question
->DefaultListHead
);
1748 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1749 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1751 if (Default
->DefaultId
== DefaultId
) {
1752 if (Default
->ValueExpression
!= NULL
) {
1754 // Default is provided by an Expression, evaluate it
1756 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1757 if (EFI_ERROR (Status
)) {
1761 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1764 // Default value is embedded in EFI_IFR_DEFAULT
1766 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1772 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1777 // EFI_ONE_OF_OPTION
1779 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1780 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1782 // OneOfOption could only provide Standard and Manufacturing default
1784 Link
= GetFirstNode (&Question
->OptionListHead
);
1785 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1786 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1788 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1789 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1791 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1796 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1802 // EFI_IFR_CHECKBOX - lowest priority
1804 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1805 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1807 // Checkbox could only provide Standard and Manufacturing default
1809 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1810 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1812 HiiValue
->Value
.b
= TRUE
;
1814 HiiValue
->Value
.b
= FALSE
;
1822 // For Questions without default
1824 switch (Question
->Operand
) {
1825 case EFI_IFR_NUMERIC_OP
:
1827 // Take minimal value as numeric's default value
1829 HiiValue
->Value
.u64
= Question
->Minimum
;
1832 case EFI_IFR_ONE_OF_OP
:
1834 // Take first oneof option as oneof's default value
1836 Link
= GetFirstNode (&Question
->OptionListHead
);
1837 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1838 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1839 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1843 case EFI_IFR_ORDERED_LIST_OP
:
1845 // Take option sequence in IFR as ordered list's default value
1848 Link
= GetFirstNode (&Question
->OptionListHead
);
1849 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1850 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1852 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1855 if (Index
>= Question
->MaxContainers
) {
1859 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1864 Status
= EFI_NOT_FOUND
;
1873 Reset Questions in a Form to their default value.
1875 @param FormSet FormSet data structure.
1876 @param Form The Form which to be reset.
1877 @param DefaultId The Class of the default.
1879 @retval EFI_SUCCESS The function completed successfully.
1883 ExtractFormDefault (
1884 IN FORM_BROWSER_FORMSET
*FormSet
,
1885 IN FORM_BROWSER_FORM
*Form
,
1891 FORM_BROWSER_STATEMENT
*Question
;
1893 Link
= GetFirstNode (&Form
->StatementListHead
);
1894 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1895 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1896 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1899 // Reset Question to its default value
1901 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1902 if (EFI_ERROR (Status
)) {
1907 // Synchronize Buffer storage's Edit buffer
1909 if ((Question
->Storage
!= NULL
) &&
1910 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1911 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1920 Initialize Question's Edit copy from Storage.
1922 @param FormSet FormSet data structure.
1923 @param Form Form data structure.
1925 @retval EFI_SUCCESS The function completed successfully.
1930 IN FORM_BROWSER_FORMSET
*FormSet
,
1931 IN FORM_BROWSER_FORM
*Form
1936 FORM_BROWSER_STATEMENT
*Question
;
1938 Link
= GetFirstNode (&Form
->StatementListHead
);
1939 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1940 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1943 // Initialize local copy of Value for each Question
1945 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1946 if (EFI_ERROR (Status
)) {
1950 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1958 Fill storage's edit copy with settings requested from Configuration Driver.
1960 @param FormSet FormSet data structure.
1961 @param Storage Buffer Storage.
1963 @retval EFI_SUCCESS The function completed successfully.
1968 IN FORM_BROWSER_FORMSET
*FormSet
,
1969 IN FORMSET_STORAGE
*Storage
1973 EFI_STRING Progress
;
1977 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1981 if (FormSet
->ConfigAccess
== NULL
) {
1982 return EFI_NOT_FOUND
;
1985 if (Storage
->ElementCount
== 0) {
1987 // Skip if there is no RequestElement
1993 // Request current settings from Configuration Driver
1995 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1996 FormSet
->ConfigAccess
,
1997 Storage
->ConfigRequest
,
2001 if (EFI_ERROR (Status
)) {
2006 // Convert Result from <ConfigAltResp> to <ConfigResp>
2008 StrPtr
= StrStr (Result
, L
"ALTCFG");
2009 if (StrPtr
!= NULL
) {
2013 Status
= ConfigRespToStorage (Storage
, Result
);
2014 gBS
->FreePool (Result
);
2020 Get current setting of Questions.
2022 @param FormSet FormSet data structure.
2024 @retval EFI_SUCCESS The function completed successfully.
2028 InitializeCurrentSetting (
2029 IN OUT FORM_BROWSER_FORMSET
*FormSet
2033 FORMSET_STORAGE
*Storage
;
2034 FORM_BROWSER_FORM
*Form
;
2038 // Extract default from IFR binary
2040 Link
= GetFirstNode (&FormSet
->FormListHead
);
2041 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2042 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2044 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2046 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2050 // Request current settings from Configuration Driver
2052 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2053 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2054 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2056 Status
= LoadStorage (FormSet
, Storage
);
2059 // Now Edit Buffer is filled with default values(lower priority) and current
2060 // settings(higher priority), sychronize it to shadow Buffer
2062 if (!EFI_ERROR (Status
)) {
2063 SynchronizeStorage (Storage
);
2066 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2074 Fetch the Ifr binary data of a FormSet.
2076 @param Handle PackageList Handle
2077 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2078 GUID), take the first FormSet found in package
2080 @param BinaryLength The length of the FormSet IFR binary.
2081 @param BinaryData The buffer designed to receive the FormSet.
2083 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2084 BufferLength was updated.
2085 @retval EFI_INVALID_PARAMETER The handle is unknown.
2086 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2087 be found with the requested FormId.
2092 IN EFI_HII_HANDLE Handle
,
2093 IN OUT EFI_GUID
*FormSetGuid
,
2094 OUT UINTN
*BinaryLength
,
2095 OUT UINT8
**BinaryData
2099 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2105 BOOLEAN ReturnDefault
;
2106 UINT32 PackageListLength
;
2107 EFI_HII_PACKAGE_HEADER PackageHeader
;
2111 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2114 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2116 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2117 ReturnDefault
= TRUE
;
2119 ReturnDefault
= FALSE
;
2123 // Get HII PackageList
2126 HiiPackageList
= NULL
;
2127 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2128 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2129 HiiPackageList
= AllocatePool (BufferSize
);
2130 ASSERT (HiiPackageList
!= NULL
);
2132 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2134 if (EFI_ERROR (Status
)) {
2139 // Get Form package from this HII package List
2141 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2143 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2145 while (Offset
< PackageListLength
) {
2146 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2147 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2149 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORM
) {
2151 // Search FormSet in this Form Package
2153 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2154 while (Offset2
< PackageHeader
.Length
) {
2155 OpCodeData
= Package
+ Offset2
;
2157 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2159 // Check whether return default FormSet
2161 if (ReturnDefault
) {
2166 // FormSet GUID is specified, check it
2168 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2173 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2176 if (Offset2
< PackageHeader
.Length
) {
2178 // Target formset found
2184 Offset
+= PackageHeader
.Length
;
2187 if (Offset
>= PackageListLength
) {
2189 // Form package not found in this Package List
2191 gBS
->FreePool (HiiPackageList
);
2192 return EFI_NOT_FOUND
;
2195 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2197 // Return the default FormSet GUID
2199 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2203 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2204 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2205 // of the Form Package.
2207 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2208 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2210 gBS
->FreePool (HiiPackageList
);
2212 if (*BinaryData
== NULL
) {
2213 return EFI_OUT_OF_RESOURCES
;
2221 Initialize the internal data structure of a FormSet.
2223 @param Handle PackageList Handle
2224 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2225 GUID), take the first FormSet found in package
2227 @param FormSet FormSet data structure.
2229 @retval EFI_SUCCESS The function completed successfully.
2230 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2235 IN EFI_HII_HANDLE Handle
,
2236 IN OUT EFI_GUID
*FormSetGuid
,
2237 OUT FORM_BROWSER_FORMSET
*FormSet
2241 EFI_HANDLE DriverHandle
;
2244 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2245 if (EFI_ERROR (Status
)) {
2249 FormSet
->HiiHandle
= Handle
;
2250 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2253 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2255 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2256 if (EFI_ERROR (Status
)) {
2259 FormSet
->DriverHandle
= DriverHandle
;
2260 Status
= gBS
->HandleProtocol (
2262 &gEfiHiiConfigAccessProtocolGuid
,
2263 (VOID
**) &FormSet
->ConfigAccess
2265 if (EFI_ERROR (Status
)) {
2267 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2268 // list, then there will be no configuration action required
2270 FormSet
->ConfigAccess
= NULL
;
2274 // Parse the IFR binary OpCodes
2276 Status
= ParseOpCodes (FormSet
);
2277 if (EFI_ERROR (Status
)) {
2281 gClassOfVfr
= FormSet
->SubClass
;
2282 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2283 FrontPageHandle
= FormSet
->HiiHandle
;
2287 // Match GUID to find out the function key setting. If match fail, use the default setting.
2289 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2290 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2292 // Update the function key setting.
2294 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2296 // Function key prompt can not be displayed if the function key has been disabled.
2298 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2299 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2302 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2303 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2306 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2307 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2310 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2311 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);