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
,
727 SafeFreePool (*Dest
);
728 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
729 ASSERT (*Dest
!= NULL
);
734 Allocate new memory and concatinate Source on the end of Destination.
736 @param Dest String to added to the end of.
737 @param Src String to concatinate.
742 IN OUT CHAR16
**Dest
,
750 NewStringCpy (Dest
, Src
);
754 TmpSize
= StrSize (*Dest
);
755 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
756 ASSERT (NewString
!= NULL
);
758 StrCpy (NewString
, *Dest
);
759 StrCat (NewString
, Src
);
761 gBS
->FreePool (*Dest
);
767 Synchronize Storage's Edit copy to Shadow copy.
769 @param Storage The Storage to be synchronized.
774 IN FORMSET_STORAGE
*Storage
778 NAME_VALUE_NODE
*Node
;
780 switch (Storage
->Type
) {
781 case EFI_HII_VARSTORE_BUFFER
:
782 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
785 case EFI_HII_VARSTORE_NAME_VALUE
:
786 Link
= GetFirstNode (&Storage
->NameValueListHead
);
787 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
788 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
790 NewStringCpy (&Node
->Value
, Node
->EditValue
);
792 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
796 case EFI_HII_VARSTORE_EFI_VARIABLE
:
804 Get Value for given Name from a NameValue Storage.
806 @param Storage The NameValue Storage.
807 @param Name The Name.
808 @param Value The retured Value.
810 @retval EFI_SUCCESS Value found for given Name.
811 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
816 IN FORMSET_STORAGE
*Storage
,
818 IN OUT CHAR16
**Value
822 NAME_VALUE_NODE
*Node
;
826 Link
= GetFirstNode (&Storage
->NameValueListHead
);
827 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
828 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
830 if (StrCmp (Name
, Node
->Name
) == 0) {
831 NewStringCpy (Value
, Node
->EditValue
);
835 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
838 return EFI_NOT_FOUND
;
843 Set Value of given Name in a NameValue Storage.
845 @param Storage The NameValue Storage.
846 @param Name The Name.
847 @param Value The Value to set.
849 @retval EFI_SUCCESS Value found for given Name.
850 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
855 IN FORMSET_STORAGE
*Storage
,
861 NAME_VALUE_NODE
*Node
;
863 Link
= GetFirstNode (&Storage
->NameValueListHead
);
864 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
865 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
867 if (StrCmp (Name
, Node
->Name
) == 0) {
868 SafeFreePool (Node
->EditValue
);
869 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
870 ASSERT (Node
->EditValue
!= NULL
);
874 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
877 return EFI_NOT_FOUND
;
882 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
884 @param Storage The Storage to be conveted.
885 @param ConfigResp The returned <ConfigResp>.
887 @retval EFI_SUCCESS Convert success.
888 @retval EFI_INVALID_PARAMETER Incorrect storage type.
892 StorageToConfigResp (
893 IN FORMSET_STORAGE
*Storage
,
894 IN CHAR16
**ConfigResp
900 NAME_VALUE_NODE
*Node
;
902 Status
= EFI_SUCCESS
;
904 switch (Storage
->Type
) {
905 case EFI_HII_VARSTORE_BUFFER
:
906 Status
= mHiiConfigRouting
->BlockToConfig (
908 Storage
->ConfigRequest
,
916 case EFI_HII_VARSTORE_NAME_VALUE
:
918 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
920 Link
= GetFirstNode (&Storage
->NameValueListHead
);
921 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
922 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
924 NewStringCat (ConfigResp
, L
"&");
925 NewStringCat (ConfigResp
, Node
->Name
);
926 NewStringCat (ConfigResp
, L
"=");
927 NewStringCat (ConfigResp
, Node
->EditValue
);
929 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
933 case EFI_HII_VARSTORE_EFI_VARIABLE
:
935 Status
= EFI_INVALID_PARAMETER
;
944 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
946 @param Storage The Storage to receive the settings.
947 @param ConfigResp The <ConfigResp> to be converted.
949 @retval EFI_SUCCESS Convert success.
950 @retval EFI_INVALID_PARAMETER Incorrect storage type.
954 ConfigRespToStorage (
955 IN FORMSET_STORAGE
*Storage
,
956 IN CHAR16
*ConfigResp
966 Status
= EFI_SUCCESS
;
968 switch (Storage
->Type
) {
969 case EFI_HII_VARSTORE_BUFFER
:
970 BufferSize
= Storage
->Size
;
971 Status
= mHiiConfigRouting
->ConfigToBlock (
980 case EFI_HII_VARSTORE_NAME_VALUE
:
981 StrPtr
= StrStr (ConfigResp
, L
"&");
982 while (StrPtr
!= NULL
) {
988 StrPtr
= StrStr (StrPtr
, L
"=");
989 if (StrPtr
== NULL
) {
999 StrPtr
= StrStr (StrPtr
, L
"&");
1000 if (StrPtr
!= NULL
) {
1003 SetValueByName (Storage
, Name
, Value
);
1007 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1009 Status
= EFI_INVALID_PARAMETER
;
1018 Get Question's current Value.
1020 @param FormSet FormSet data structure.
1021 @param Form Form data structure.
1022 @param Question Question to be initialized.
1023 @param Cached TRUE: get from Edit copy FALSE: get from original
1026 @retval EFI_SUCCESS The function completed successfully.
1031 IN FORM_BROWSER_FORMSET
*FormSet
,
1032 IN FORM_BROWSER_FORM
*Form
,
1033 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1043 FORMSET_STORAGE
*Storage
;
1044 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1045 CHAR16
*ConfigRequest
;
1050 BOOLEAN IsBufferStorage
;
1053 Status
= EFI_SUCCESS
;
1056 // Statement don't have storage, skip them
1058 if (Question
->QuestionId
== 0) {
1063 // Question value is provided by an Expression, evaluate it
1065 if (Question
->ValueExpression
!= NULL
) {
1066 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1067 if (!EFI_ERROR (Status
)) {
1068 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1074 // Question value is provided by RTC
1076 Storage
= Question
->Storage
;
1077 QuestionValue
= &Question
->HiiValue
.Value
;
1078 if (Storage
== NULL
) {
1080 // It's a Question without storage, or RTC date/time
1082 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1084 // Date and time define the same Flags bit
1086 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1087 case QF_DATE_STORAGE_TIME
:
1088 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1091 case QF_DATE_STORAGE_WAKEUP
:
1092 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1095 case QF_DATE_STORAGE_NORMAL
:
1098 // For date/time without storage
1103 if (EFI_ERROR (Status
)) {
1107 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1108 QuestionValue
->date
.Year
= EfiTime
.Year
;
1109 QuestionValue
->date
.Month
= EfiTime
.Month
;
1110 QuestionValue
->date
.Day
= EfiTime
.Day
;
1112 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1113 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1114 QuestionValue
->time
.Second
= EfiTime
.Second
;
1122 // Question value is provided by EFI variable
1124 StorageWidth
= Question
->StorageWidth
;
1125 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1126 if (Question
->BufferValue
!= NULL
) {
1127 Dst
= Question
->BufferValue
;
1129 Dst
= (UINT8
*) QuestionValue
;
1132 Status
= gRT
->GetVariable (
1133 Question
->VariableName
,
1140 // Always return success, even this EFI variable doesn't exist
1146 // Question Value is provided by Buffer Storage or NameValue Storage
1148 if (Question
->BufferValue
!= NULL
) {
1150 // This Question is password or orderedlist
1152 Dst
= Question
->BufferValue
;
1155 // Other type of Questions
1157 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1160 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1161 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1163 if (IsBufferStorage
) {
1165 // Copy from storage Edit buffer
1167 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1169 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1170 if (EFI_ERROR (Status
)) {
1176 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1178 Length
= StorageWidth
+ sizeof (CHAR16
);
1179 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1181 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1184 gBS
->FreePool (Value
);
1188 // Request current settings from Configuration Driver
1190 if (FormSet
->ConfigAccess
== NULL
) {
1191 return EFI_NOT_FOUND
;
1195 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1196 // <ConfigHdr> + "&" + <VariableName>
1198 if (IsBufferStorage
) {
1199 Length
= StrLen (Storage
->ConfigHdr
);
1200 Length
+= StrLen (Question
->BlockName
);
1202 Length
= StrLen (Storage
->ConfigHdr
);
1203 Length
+= StrLen (Question
->VariableName
) + 1;
1205 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1206 ASSERT (ConfigRequest
!= NULL
);
1208 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1209 if (IsBufferStorage
) {
1210 StrCat (ConfigRequest
, Question
->BlockName
);
1212 StrCat (ConfigRequest
, L
"&");
1213 StrCat (ConfigRequest
, Question
->VariableName
);
1216 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1217 FormSet
->ConfigAccess
,
1222 if (EFI_ERROR (Status
)) {
1227 // Skip <ConfigRequest>
1229 Value
= Result
+ Length
;
1230 if (IsBufferStorage
) {
1236 if (*Value
!= '=') {
1237 gBS
->FreePool (Result
);
1238 return EFI_NOT_FOUND
;
1241 // Skip '=', point to value
1244 if (!IsBufferStorage
&& IsString
) {
1246 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1248 Length
= StorageWidth
+ sizeof (CHAR16
);
1249 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1251 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1252 if (EFI_ERROR (Status
)) {
1253 gBS
->FreePool (Result
);
1259 // Synchronize Edit Buffer
1261 if (IsBufferStorage
) {
1262 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1264 SetValueByName (Storage
, Question
->VariableName
, Value
);
1266 gBS
->FreePool (Result
);
1274 Save Question Value to edit copy(cached) or Storage(uncached).
1276 @param FormSet FormSet data structure.
1277 @param Form Form data structure.
1278 @param Question Pointer to the Question.
1279 @param Cached TRUE: set to Edit copy FALSE: set to original
1282 @retval EFI_SUCCESS The function completed successfully.
1287 IN FORM_BROWSER_FORMSET
*FormSet
,
1288 IN FORM_BROWSER_FORM
*Form
,
1289 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1300 FORMSET_STORAGE
*Storage
;
1301 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1306 BOOLEAN IsBufferStorage
;
1309 Status
= EFI_SUCCESS
;
1312 // Statement don't have storage, skip them
1314 if (Question
->QuestionId
== 0) {
1319 // If Question value is provided by an Expression, then it is read only
1321 if (Question
->ValueExpression
!= NULL
) {
1326 // Question value is provided by RTC
1328 Storage
= Question
->Storage
;
1329 QuestionValue
= &Question
->HiiValue
.Value
;
1330 if (Storage
== NULL
) {
1332 // It's a Question without storage, or RTC date/time
1334 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1336 // Date and time define the same Flags bit
1338 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1339 case QF_DATE_STORAGE_TIME
:
1340 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1343 case QF_DATE_STORAGE_WAKEUP
:
1344 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1347 case QF_DATE_STORAGE_NORMAL
:
1350 // For date/time without storage
1355 if (EFI_ERROR (Status
)) {
1359 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1360 EfiTime
.Year
= QuestionValue
->date
.Year
;
1361 EfiTime
.Month
= QuestionValue
->date
.Month
;
1362 EfiTime
.Day
= QuestionValue
->date
.Day
;
1364 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1365 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1366 EfiTime
.Second
= QuestionValue
->time
.Second
;
1369 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1370 Status
= gRT
->SetTime (&EfiTime
);
1372 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1380 // Question value is provided by EFI variable
1382 StorageWidth
= Question
->StorageWidth
;
1383 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1384 if (Question
->BufferValue
!= NULL
) {
1385 Src
= Question
->BufferValue
;
1387 Src
= (UINT8
*) QuestionValue
;
1390 Status
= gRT
->SetVariable (
1391 Question
->VariableName
,
1393 Storage
->Attributes
,
1401 // Question Value is provided by Buffer Storage or NameValue Storage
1403 if (Question
->BufferValue
!= NULL
) {
1404 Src
= Question
->BufferValue
;
1406 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1409 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1410 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1411 if (IsBufferStorage
) {
1413 // Copy to storage edit buffer
1415 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1419 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1422 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1423 Value
= AllocateZeroPool (BufferLen
);
1424 ASSERT (Value
!= NULL
);
1425 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1426 ASSERT_EFI_ERROR (Status
);
1428 BufferLen
= StorageWidth
* 2 + 1;
1429 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1430 ASSERT (Value
!= NULL
);
1431 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1435 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1436 gBS
->FreePool (Value
);
1441 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1442 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1444 if (IsBufferStorage
) {
1445 Length
= StrLen (Question
->BlockName
) + 7;
1447 Length
= StrLen (Question
->VariableName
) + 2;
1449 if (!IsBufferStorage
&& IsString
) {
1450 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1452 Length
+= (StorageWidth
* 2);
1454 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1455 ASSERT (ConfigResp
!= NULL
);
1457 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1458 if (IsBufferStorage
) {
1459 StrCat (ConfigResp
, Question
->BlockName
);
1460 StrCat (ConfigResp
, L
"&VALUE=");
1462 StrCat (ConfigResp
, L
"&");
1463 StrCat (ConfigResp
, Question
->VariableName
);
1464 StrCat (ConfigResp
, L
"=");
1467 Value
= ConfigResp
+ StrLen (ConfigResp
);
1468 if (!IsBufferStorage
&& IsString
) {
1470 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1472 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1473 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1474 ASSERT_EFI_ERROR (Status
);
1476 BufferLen
= StorageWidth
* 2 + 1;
1477 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1482 // Submit Question Value to Configuration Driver
1484 if (FormSet
->ConfigAccess
!= NULL
) {
1485 Status
= FormSet
->ConfigAccess
->RouteConfig (
1486 FormSet
->ConfigAccess
,
1490 if (EFI_ERROR (Status
)) {
1491 gBS
->FreePool (ConfigResp
);
1495 gBS
->FreePool (ConfigResp
);
1498 // Synchronize shadow Buffer
1500 SynchronizeStorage (Storage
);
1508 Perform inconsistent check for a Form.
1510 @param FormSet FormSet data structure.
1511 @param Form Form data structure.
1512 @param Question The Question to be validated.
1513 @param Type Validation type: InConsistent or NoSubmit
1515 @retval EFI_SUCCESS Form validation pass.
1516 @retval other Form validation failed.
1521 IN FORM_BROWSER_FORMSET
*FormSet
,
1522 IN FORM_BROWSER_FORM
*Form
,
1523 IN FORM_BROWSER_STATEMENT
*Question
,
1529 LIST_ENTRY
*ListHead
;
1532 FORM_EXPRESSION
*Expression
;
1534 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1535 ListHead
= &Question
->InconsistentListHead
;
1536 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1537 ListHead
= &Question
->NoSubmitListHead
;
1539 return EFI_UNSUPPORTED
;
1542 Link
= GetFirstNode (ListHead
);
1543 while (!IsNull (ListHead
, Link
)) {
1544 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1547 // Evaluate the expression
1549 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1550 if (EFI_ERROR (Status
)) {
1554 if (Expression
->Result
.Value
.b
) {
1556 // Condition meet, show up error message
1558 if (Expression
->Error
!= 0) {
1559 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1561 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1562 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1563 gBS
->FreePool (PopUp
);
1566 return EFI_NOT_READY
;
1569 Link
= GetNextNode (ListHead
, Link
);
1577 Perform NoSubmit check for a Form.
1579 @param FormSet FormSet data structure.
1580 @param Form Form data structure.
1582 @retval EFI_SUCCESS Form validation pass.
1583 @retval other Form validation failed.
1588 IN FORM_BROWSER_FORMSET
*FormSet
,
1589 IN FORM_BROWSER_FORM
*Form
1594 FORM_BROWSER_STATEMENT
*Question
;
1596 Link
= GetFirstNode (&Form
->StatementListHead
);
1597 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1598 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1600 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1601 if (EFI_ERROR (Status
)) {
1605 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1615 @param FormSet FormSet data structure.
1616 @param Form Form data structure.
1618 @retval EFI_SUCCESS The function completed successfully.
1623 IN FORM_BROWSER_FORMSET
*FormSet
,
1624 IN FORM_BROWSER_FORM
*Form
1629 EFI_STRING ConfigResp
;
1630 EFI_STRING Progress
;
1631 FORMSET_STORAGE
*Storage
;
1634 // Validate the Form by NoSubmit check
1636 Status
= NoSubmitCheck (FormSet
, Form
);
1637 if (EFI_ERROR (Status
)) {
1642 // Submit Buffer storage or Name/Value storage
1644 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1645 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1646 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1647 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1649 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1654 // Skip if there is no RequestElement
1656 if (Storage
->ElementCount
== 0) {
1661 // Prepare <ConfigResp>
1663 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1664 if (EFI_ERROR (Status
)) {
1669 // Send <ConfigResp> to Configuration Driver
1671 if (FormSet
->ConfigAccess
!= NULL
) {
1672 Status
= FormSet
->ConfigAccess
->RouteConfig (
1673 FormSet
->ConfigAccess
,
1677 if (EFI_ERROR (Status
)) {
1678 gBS
->FreePool (ConfigResp
);
1682 gBS
->FreePool (ConfigResp
);
1685 // Config success, update storage shadow Buffer
1687 SynchronizeStorage (Storage
);
1690 gNvUpdateRequired
= FALSE
;
1697 Reset Question to its default value.
1699 @param FormSet The form set.
1700 @param Form The form.
1701 @param Question The question.
1702 @param DefaultId The Class of the default.
1704 @retval EFI_SUCCESS Question is reset to default value.
1708 GetQuestionDefault (
1709 IN FORM_BROWSER_FORMSET
*FormSet
,
1710 IN FORM_BROWSER_FORM
*Form
,
1711 IN FORM_BROWSER_STATEMENT
*Question
,
1717 QUESTION_DEFAULT
*Default
;
1718 QUESTION_OPTION
*Option
;
1719 EFI_HII_VALUE
*HiiValue
;
1722 Status
= EFI_SUCCESS
;
1725 // Statement don't have storage, skip them
1727 if (Question
->QuestionId
== 0) {
1732 // There are three ways to specify default value for a Question:
1733 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1734 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1735 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1737 HiiValue
= &Question
->HiiValue
;
1740 // EFI_IFR_DEFAULT has highest priority
1742 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1743 Link
= GetFirstNode (&Question
->DefaultListHead
);
1744 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1745 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1747 if (Default
->DefaultId
== DefaultId
) {
1748 if (Default
->ValueExpression
!= NULL
) {
1750 // Default is provided by an Expression, evaluate it
1752 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1753 if (EFI_ERROR (Status
)) {
1757 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1760 // Default value is embedded in EFI_IFR_DEFAULT
1762 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1768 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1773 // EFI_ONE_OF_OPTION
1775 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1776 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1778 // OneOfOption could only provide Standard and Manufacturing default
1780 Link
= GetFirstNode (&Question
->OptionListHead
);
1781 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1782 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1784 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1785 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1787 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1792 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1798 // EFI_IFR_CHECKBOX - lowest priority
1800 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1801 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1803 // Checkbox could only provide Standard and Manufacturing default
1805 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1806 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1808 HiiValue
->Value
.b
= TRUE
;
1810 HiiValue
->Value
.b
= FALSE
;
1818 // For Questions without default
1820 switch (Question
->Operand
) {
1821 case EFI_IFR_NUMERIC_OP
:
1823 // Take minimal value as numeric's default value
1825 HiiValue
->Value
.u64
= Question
->Minimum
;
1828 case EFI_IFR_ONE_OF_OP
:
1830 // Take first oneof option as oneof's default value
1832 Link
= GetFirstNode (&Question
->OptionListHead
);
1833 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1834 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1835 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1839 case EFI_IFR_ORDERED_LIST_OP
:
1841 // Take option sequence in IFR as ordered list's default value
1844 Link
= GetFirstNode (&Question
->OptionListHead
);
1845 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1846 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1848 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1851 if (Index
>= Question
->MaxContainers
) {
1855 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1860 Status
= EFI_NOT_FOUND
;
1869 Reset Questions in a Form to their default value.
1871 @param FormSet FormSet data structure.
1872 @param Form The Form which to be reset.
1873 @param DefaultId The Class of the default.
1875 @retval EFI_SUCCESS The function completed successfully.
1879 ExtractFormDefault (
1880 IN FORM_BROWSER_FORMSET
*FormSet
,
1881 IN FORM_BROWSER_FORM
*Form
,
1887 FORM_BROWSER_STATEMENT
*Question
;
1889 Link
= GetFirstNode (&Form
->StatementListHead
);
1890 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1891 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1892 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1895 // Reset Question to its default value
1897 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1898 if (EFI_ERROR (Status
)) {
1903 // Synchronize Buffer storage's Edit buffer
1905 if ((Question
->Storage
!= NULL
) &&
1906 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1907 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1916 Initialize Question's Edit copy from Storage.
1918 @param FormSet FormSet data structure.
1919 @param Form Form data structure.
1921 @retval EFI_SUCCESS The function completed successfully.
1926 IN FORM_BROWSER_FORMSET
*FormSet
,
1927 IN FORM_BROWSER_FORM
*Form
1932 FORM_BROWSER_STATEMENT
*Question
;
1934 Link
= GetFirstNode (&Form
->StatementListHead
);
1935 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1936 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1939 // Initialize local copy of Value for each Question
1941 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1942 if (EFI_ERROR (Status
)) {
1946 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1954 Fill storage's edit copy with settings requested from Configuration Driver.
1956 @param FormSet FormSet data structure.
1957 @param Storage Buffer Storage.
1959 @retval EFI_SUCCESS The function completed successfully.
1964 IN FORM_BROWSER_FORMSET
*FormSet
,
1965 IN FORMSET_STORAGE
*Storage
1969 EFI_STRING Progress
;
1973 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1977 if (FormSet
->ConfigAccess
== NULL
) {
1978 return EFI_NOT_FOUND
;
1981 if (Storage
->ElementCount
== 0) {
1983 // Skip if there is no RequestElement
1989 // Request current settings from Configuration Driver
1991 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1992 FormSet
->ConfigAccess
,
1993 Storage
->ConfigRequest
,
1997 if (EFI_ERROR (Status
)) {
2002 // Convert Result from <ConfigAltResp> to <ConfigResp>
2004 StrPtr
= StrStr (Result
, L
"ALTCFG");
2005 if (StrPtr
!= NULL
) {
2009 Status
= ConfigRespToStorage (Storage
, Result
);
2010 gBS
->FreePool (Result
);
2016 Get current setting of Questions.
2018 @param FormSet FormSet data structure.
2020 @retval EFI_SUCCESS The function completed successfully.
2024 InitializeCurrentSetting (
2025 IN OUT FORM_BROWSER_FORMSET
*FormSet
2029 FORMSET_STORAGE
*Storage
;
2030 FORM_BROWSER_FORM
*Form
;
2034 // Extract default from IFR binary
2036 Link
= GetFirstNode (&FormSet
->FormListHead
);
2037 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2038 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2040 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2042 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2046 // Request current settings from Configuration Driver
2048 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2049 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2050 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2052 Status
= LoadStorage (FormSet
, Storage
);
2055 // Now Edit Buffer is filled with default values(lower priority) and current
2056 // settings(higher priority), sychronize it to shadow Buffer
2058 if (!EFI_ERROR (Status
)) {
2059 SynchronizeStorage (Storage
);
2062 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2070 Fetch the Ifr binary data of a FormSet.
2072 @param Handle PackageList Handle
2073 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2074 GUID), take the first FormSet found in package
2076 @param BinaryLength The length of the FormSet IFR binary.
2077 @param BinaryData The buffer designed to receive the FormSet.
2079 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2080 BufferLength was updated.
2081 @retval EFI_INVALID_PARAMETER The handle is unknown.
2082 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2083 be found with the requested FormId.
2088 IN EFI_HII_HANDLE Handle
,
2089 IN OUT EFI_GUID
*FormSetGuid
,
2090 OUT UINTN
*BinaryLength
,
2091 OUT UINT8
**BinaryData
2095 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2101 BOOLEAN ReturnDefault
;
2102 UINT32 PackageListLength
;
2103 EFI_HII_PACKAGE_HEADER PackageHeader
;
2107 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2110 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2112 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2113 ReturnDefault
= TRUE
;
2115 ReturnDefault
= FALSE
;
2119 // Get HII PackageList
2122 HiiPackageList
= NULL
;
2123 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2124 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2125 HiiPackageList
= AllocatePool (BufferSize
);
2126 ASSERT (HiiPackageList
!= NULL
);
2128 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2130 if (EFI_ERROR (Status
)) {
2135 // Get Form package from this HII package List
2137 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2139 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2141 while (Offset
< PackageListLength
) {
2142 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2143 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2145 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORM
) {
2147 // Search FormSet in this Form Package
2149 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2150 while (Offset2
< PackageHeader
.Length
) {
2151 OpCodeData
= Package
+ Offset2
;
2153 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2155 // Check whether return default FormSet
2157 if (ReturnDefault
) {
2162 // FormSet GUID is specified, check it
2164 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2169 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2172 if (Offset2
< PackageHeader
.Length
) {
2174 // Target formset found
2180 Offset
+= PackageHeader
.Length
;
2183 if (Offset
>= PackageListLength
) {
2185 // Form package not found in this Package List
2187 gBS
->FreePool (HiiPackageList
);
2188 return EFI_NOT_FOUND
;
2191 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2193 // Return the default FormSet GUID
2195 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2199 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2200 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2201 // of the Form Package.
2203 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2204 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2206 gBS
->FreePool (HiiPackageList
);
2208 if (*BinaryData
== NULL
) {
2209 return EFI_OUT_OF_RESOURCES
;
2217 Initialize the internal data structure of a FormSet.
2219 @param Handle PackageList Handle
2220 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2221 GUID), take the first FormSet found in package
2223 @param FormSet FormSet data structure.
2225 @retval EFI_SUCCESS The function completed successfully.
2226 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2231 IN EFI_HII_HANDLE Handle
,
2232 IN OUT EFI_GUID
*FormSetGuid
,
2233 OUT FORM_BROWSER_FORMSET
*FormSet
2237 EFI_HANDLE DriverHandle
;
2240 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2241 if (EFI_ERROR (Status
)) {
2245 FormSet
->HiiHandle
= Handle
;
2246 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2249 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2251 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2252 if (EFI_ERROR (Status
)) {
2255 FormSet
->DriverHandle
= DriverHandle
;
2256 Status
= gBS
->HandleProtocol (
2258 &gEfiHiiConfigAccessProtocolGuid
,
2259 (VOID
**) &FormSet
->ConfigAccess
2261 if (EFI_ERROR (Status
)) {
2263 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2264 // list, then there will be no configuration action required
2266 FormSet
->ConfigAccess
= NULL
;
2270 // Parse the IFR binary OpCodes
2272 Status
= ParseOpCodes (FormSet
);
2273 if (EFI_ERROR (Status
)) {
2277 gClassOfVfr
= FormSet
->SubClass
;
2278 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2279 FrontPageHandle
= FormSet
->HiiHandle
;
2283 // Match GUID to find out the function key setting. If match fail, use the default setting.
2285 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2286 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2288 // Update the function key setting.
2290 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2292 // Function key prompt can not be displayed if the function key has been disabled.
2294 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2295 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2298 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2299 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2302 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2303 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2306 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2307 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);