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
,
31 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
32 EFI_HII_STRING_PROTOCOL
*mHiiString
;
33 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
35 BANNER_DATA
*BannerData
;
36 EFI_HII_HANDLE FrontPageHandle
;
38 UINTN gFunctionKeySetting
;
39 BOOLEAN gResetRequired
;
40 BOOLEAN gNvUpdateRequired
;
41 EFI_HII_HANDLE gHiiHandle
;
44 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
49 // Browser Global Strings
51 CHAR16
*gFunctionOneString
;
52 CHAR16
*gFunctionTwoString
;
53 CHAR16
*gFunctionNineString
;
54 CHAR16
*gFunctionTenString
;
56 CHAR16
*gEnterCommitString
;
57 CHAR16
*gEscapeString
;
59 CHAR16
*gMoveHighlight
;
60 CHAR16
*gMakeSelection
;
61 CHAR16
*gDecNumericInput
;
62 CHAR16
*gHexNumericInput
;
63 CHAR16
*gToggleCheckBox
;
64 CHAR16
*gPromptForData
;
65 CHAR16
*gPromptForPassword
;
66 CHAR16
*gPromptForNewPassword
;
67 CHAR16
*gConfirmPassword
;
68 CHAR16
*gConfirmError
;
69 CHAR16
*gPassowordInvalid
;
78 CHAR16
*gAdjustNumber
;
80 CHAR16 gPromptBlockWidth
;
81 CHAR16 gOptionBlockWidth
;
82 CHAR16 gHelpBlockWidth
;
84 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
85 EFI_GUID gSetupBrowserGuid
= {
86 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
89 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
109 NONE_FUNCTION_KEY_SETTING
130 NONE_FUNCTION_KEY_SETTING
151 NONE_FUNCTION_KEY_SETTING
154 // BMM File Explorer FormSet.
172 NONE_FUNCTION_KEY_SETTING
177 This is the routine which an external caller uses to direct the browser
178 where to obtain it's information.
181 @param This The Form Browser protocol instanse.
182 @param Handles A pointer to an array of Handles. If HandleCount > 1 we
183 display a list of the formsets for the handles specified.
184 @param HandleCount The number of Handles specified in Handle.
185 @param FormSetGuid This field points to the EFI_GUID which must match the Guid
186 field in the EFI_IFR_FORM_SET op-code for the specified
187 forms-based package. If FormSetGuid is NULL, then this
188 function will display the first found forms package.
189 @param FormId This field specifies which EFI_IFR_FORM to render as the first
190 displayable page. If this field has a value of 0x0000, then
191 the forms browser will render the specified forms in their encoded order.
192 ScreenDimenions - This allows the browser to be called so that it occupies a
193 portion of the physical screen instead of dynamically determining the screen dimensions.
194 ActionRequest - Points to the action recommended by the form.
195 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
197 @param ActionRequest Points to the action recommended by the form.
199 @retval EFI_SUCCESS The function completed successfully.
200 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
201 @retval EFI_NOT_FOUND No valid forms could be found to display.
207 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
208 IN EFI_HII_HANDLE
*Handles
,
209 IN UINTN HandleCount
,
210 IN EFI_GUID
*FormSetGuid
, OPTIONAL
211 IN UINT16 FormId
, OPTIONAL
212 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
213 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
217 UI_MENU_SELECTION
*Selection
;
219 FORM_BROWSER_FORMSET
*FormSet
;
221 Status
= EFI_SUCCESS
;
222 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
225 // Seed the dimensions in the global
227 gST
->ConOut
->QueryMode (
229 gST
->ConOut
->Mode
->Mode
,
230 &gScreenDimensions
.RightColumn
,
231 &gScreenDimensions
.BottomRow
234 if (ScreenDimensions
!= NULL
) {
236 // Check local dimension vs. global dimension.
238 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
239 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
241 return EFI_INVALID_PARAMETER
;
244 // Local dimension validation.
246 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
247 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
248 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
250 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
251 SCROLL_ARROW_HEIGHT
*
253 FRONT_PAGE_HEADER_HEIGHT
+
258 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
260 return EFI_INVALID_PARAMETER
;
265 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
266 gHelpBlockWidth
= gOptionBlockWidth
;
267 gPromptBlockWidth
= gOptionBlockWidth
;
270 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
272 InitializeBrowserStrings ();
274 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
275 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
278 // Ensure we are in Text mode
282 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
286 for (Index
= 0; Index
< HandleCount
; Index
++) {
287 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
288 ASSERT (Selection
!= NULL
);
290 Selection
->Handle
= Handles
[Index
];
291 if (FormSetGuid
!= NULL
) {
292 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
293 Selection
->FormId
= FormId
;
297 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
298 ASSERT (FormSet
!= NULL
);
301 // Initialize internal data structures of FormSet
303 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
304 if (EFI_ERROR (Status
)) {
305 DestroyFormSet (FormSet
);
308 Selection
->FormSet
= FormSet
;
311 // Initialize current settings of Questions in this FormSet
313 Status
= InitializeCurrentSetting (FormSet
);
314 if (EFI_ERROR (Status
)) {
315 DestroyFormSet (FormSet
);
320 // Display this formset
322 gCurrentSelection
= Selection
;
324 Status
= SetupBrowser (Selection
);
326 gCurrentSelection
= NULL
;
327 DestroyFormSet (FormSet
);
329 if (EFI_ERROR (Status
)) {
333 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
335 gBS
->FreePool (Selection
);
338 if (ActionRequest
!= NULL
) {
339 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
340 if (gResetRequired
) {
341 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
345 FreeBrowserStrings ();
347 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
348 gST
->ConOut
->ClearScreen (gST
->ConOut
);
355 This function is called by a callback handler to retrieve uncommitted state
356 data from the browser.
358 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
360 @param ResultsDataSize A pointer to the size of the buffer associated
362 @param ResultsData A string returned from an IFR browser or
363 equivalent. The results string will have no
364 routing information in them.
365 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
366 (if RetrieveData = TRUE) data from the uncommitted
367 browser state information or set (if RetrieveData
368 = FALSE) data in the uncommitted browser state
370 @param VariableGuid An optional field to indicate the target variable
372 @param VariableName An optional field to indicate the target
373 human-readable variable name.
375 @retval EFI_SUCCESS The results have been distributed or are awaiting
377 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
378 contain the results data.
384 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
385 IN OUT UINTN
*ResultsDataSize
,
386 IN OUT EFI_STRING ResultsData
,
387 IN BOOLEAN RetrieveData
,
388 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
389 IN CONST CHAR16
*VariableName OPTIONAL
394 FORMSET_STORAGE
*Storage
;
395 FORM_BROWSER_FORMSET
*FormSet
;
402 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
403 return EFI_INVALID_PARAMETER
;
406 if (gCurrentSelection
== NULL
) {
407 return EFI_NOT_READY
;
412 FormSet
= gCurrentSelection
->FormSet
;
415 // Find target storage
417 Link
= GetFirstNode (&FormSet
->StorageListHead
);
418 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
419 return EFI_UNSUPPORTED
;
422 if (VariableGuid
!= NULL
) {
424 // Try to find target storage
427 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
428 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
429 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
431 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
432 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
434 // Buffer storage require both GUID and Name
436 if (VariableName
== NULL
) {
437 return EFI_NOT_FOUND
;
440 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
450 return EFI_NOT_FOUND
;
454 // GUID/Name is not specified, take the first storage in FormSet
456 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
461 // Skip if there is no RequestElement
463 if (Storage
->ElementCount
== 0) {
468 // Generate <ConfigResp>
470 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
471 if (EFI_ERROR (Status
)) {
476 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
478 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
480 BufferSize
= StrSize (StrPtr
);
481 if (*ResultsDataSize
< BufferSize
) {
482 *ResultsDataSize
= BufferSize
;
484 gBS
->FreePool (ConfigResp
);
485 return EFI_BUFFER_TOO_SMALL
;
488 *ResultsDataSize
= BufferSize
;
489 CopyMem (ResultsData
, StrPtr
, BufferSize
);
491 gBS
->FreePool (ConfigResp
);
494 // Prepare <ConfigResp>
496 TmpSize
= StrLen (ResultsData
);
497 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
498 ConfigResp
= AllocateZeroPool (BufferSize
);
499 ASSERT (ConfigResp
!= NULL
);
501 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
502 StrCat (ConfigResp
, L
"&");
503 StrCat (ConfigResp
, ResultsData
);
506 // Update Browser uncommited data
508 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
509 if (EFI_ERROR (Status
)) {
519 Initialize Setup Browser driver.
521 @param ImageHandle The image handle.
522 @param SystemTable The system table.
524 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
525 @return Other value if failed to initialize the Setup Browser module.
531 IN EFI_HANDLE ImageHandle
,
532 IN EFI_SYSTEM_TABLE
*SystemTable
536 EFI_HANDLE HiiDriverHandle
;
537 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
540 // Locate required Hii relative protocols
542 Status
= gBS
->LocateProtocol (
543 &gEfiHiiDatabaseProtocolGuid
,
545 (VOID
**) &mHiiDatabase
547 ASSERT_EFI_ERROR (Status
);
549 Status
= gBS
->LocateProtocol (
550 &gEfiHiiStringProtocolGuid
,
552 (VOID
**) &mHiiString
554 ASSERT_EFI_ERROR (Status
);
556 Status
= gBS
->LocateProtocol (
557 &gEfiHiiConfigRoutingProtocolGuid
,
559 (VOID
**) &mHiiConfigRouting
561 ASSERT_EFI_ERROR (Status
);
564 // Publish our HII data
566 Status
= HiiLibCreateHiiDriverHandle (&HiiDriverHandle
);
567 ASSERT_EFI_ERROR (Status
);
569 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
570 ASSERT (PackageList
!= NULL
);
571 Status
= mHiiDatabase
->NewPackageList (
577 ASSERT_EFI_ERROR (Status
);
580 // Initialize Driver private data
583 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
584 ASSERT (BannerData
!= NULL
);
587 // Install FormBrowser2 protocol
589 mPrivateData
.Handle
= NULL
;
590 Status
= gBS
->InstallProtocolInterface (
591 &mPrivateData
.Handle
,
592 &gEfiFormBrowser2ProtocolGuid
,
593 EFI_NATIVE_INTERFACE
,
594 &mPrivateData
.FormBrowser2
596 ASSERT_EFI_ERROR (Status
);
599 // Install Print protocol
601 Status
= gBS
->InstallProtocolInterface (
602 &mPrivateData
.Handle
,
603 &gEfiPrintProtocolGuid
,
604 EFI_NATIVE_INTERFACE
,
613 Create a new string in HII Package List.
615 @param String The String to be added
616 @param HiiHandle The package list in the HII database to insert the
619 @return The output string.
625 IN EFI_HII_HANDLE HiiHandle
628 EFI_STRING_ID StringId
;
632 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
633 ASSERT_EFI_ERROR (Status
);
640 Delete a string from HII Package List.
642 @param StringId Id of the string in HII database.
643 @param HiiHandle The HII package list handle.
645 @retval EFI_SUCCESS The string was deleted successfully.
650 IN EFI_STRING_ID StringId
,
651 IN EFI_HII_HANDLE HiiHandle
656 NullChar
= CHAR_NULL
;
657 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
662 Get the string based on the StringId and HII Package List Handle.
664 @param Token The String's ID.
665 @param HiiHandle The package list in the HII database to search for
666 the specified string.
668 @return The output string.
673 IN EFI_STRING_ID Token
,
674 IN EFI_HII_HANDLE HiiHandle
682 // Set default string size assumption at no more than 256 bytes
684 BufferLength
= 0x100;
685 String
= AllocateZeroPool (BufferLength
);
686 ASSERT (String
!= NULL
);
688 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
690 if (Status
== EFI_BUFFER_TOO_SMALL
) {
691 gBS
->FreePool (String
);
692 String
= AllocateZeroPool (BufferLength
);
693 ASSERT (String
!= NULL
);
695 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
697 ASSERT_EFI_ERROR (Status
);
704 Allocate new memory and then copy the Unicode string Source to Destination.
706 @param Dest Location to copy string
707 @param Src String to copy
712 IN OUT CHAR16
**Dest
,
716 SafeFreePool (*Dest
);
717 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
718 ASSERT (*Dest
!= NULL
);
723 Allocate new memory and concatinate Source on the end of Destination.
725 @param Dest String to added to the end of.
726 @param Src String to concatinate.
731 IN OUT CHAR16
**Dest
,
739 NewStringCpy (Dest
, Src
);
743 TmpSize
= StrSize (*Dest
);
744 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
745 ASSERT (NewString
!= NULL
);
747 StrCpy (NewString
, *Dest
);
748 StrCat (NewString
, Src
);
750 gBS
->FreePool (*Dest
);
756 Synchronize Storage's Edit copy to Shadow copy.
758 @param Storage The Storage to be synchronized.
763 IN FORMSET_STORAGE
*Storage
767 NAME_VALUE_NODE
*Node
;
769 switch (Storage
->Type
) {
770 case EFI_HII_VARSTORE_BUFFER
:
771 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
774 case EFI_HII_VARSTORE_NAME_VALUE
:
775 Link
= GetFirstNode (&Storage
->NameValueListHead
);
776 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
777 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
779 NewStringCpy (&Node
->Value
, Node
->EditValue
);
781 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
785 case EFI_HII_VARSTORE_EFI_VARIABLE
:
793 Get Value for given Name from a NameValue Storage.
795 @param Storage The NameValue Storage.
796 @param Name The Name.
797 @param Value The retured Value.
799 @retval EFI_SUCCESS Value found for given Name.
800 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
805 IN FORMSET_STORAGE
*Storage
,
807 IN OUT CHAR16
**Value
811 NAME_VALUE_NODE
*Node
;
815 Link
= GetFirstNode (&Storage
->NameValueListHead
);
816 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
817 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
819 if (StrCmp (Name
, Node
->Name
) == 0) {
820 NewStringCpy (Value
, Node
->EditValue
);
824 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
827 return EFI_NOT_FOUND
;
832 Set Value of given Name in a NameValue Storage.
834 @param Storage The NameValue Storage.
835 @param Name The Name.
836 @param Value The Value to set.
838 @retval EFI_SUCCESS Value found for given Name.
839 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
844 IN FORMSET_STORAGE
*Storage
,
850 NAME_VALUE_NODE
*Node
;
852 Link
= GetFirstNode (&Storage
->NameValueListHead
);
853 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
854 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
856 if (StrCmp (Name
, Node
->Name
) == 0) {
857 SafeFreePool (Node
->EditValue
);
858 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
859 ASSERT (Node
->EditValue
!= NULL
);
863 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
866 return EFI_NOT_FOUND
;
871 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
873 @param Storage The Storage to be conveted.
874 @param ConfigResp The returned <ConfigResp>.
876 @retval EFI_SUCCESS Convert success.
877 @retval EFI_INVALID_PARAMETER Incorrect storage type.
881 StorageToConfigResp (
882 IN FORMSET_STORAGE
*Storage
,
883 IN CHAR16
**ConfigResp
889 NAME_VALUE_NODE
*Node
;
891 Status
= EFI_SUCCESS
;
893 switch (Storage
->Type
) {
894 case EFI_HII_VARSTORE_BUFFER
:
895 Status
= mHiiConfigRouting
->BlockToConfig (
897 Storage
->ConfigRequest
,
905 case EFI_HII_VARSTORE_NAME_VALUE
:
907 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
909 Link
= GetFirstNode (&Storage
->NameValueListHead
);
910 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
911 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
913 NewStringCat (ConfigResp
, L
"&");
914 NewStringCat (ConfigResp
, Node
->Name
);
915 NewStringCat (ConfigResp
, L
"=");
916 NewStringCat (ConfigResp
, Node
->EditValue
);
918 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
922 case EFI_HII_VARSTORE_EFI_VARIABLE
:
924 Status
= EFI_INVALID_PARAMETER
;
933 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
935 @param Storage The Storage to receive the settings.
936 @param ConfigResp The <ConfigResp> to be converted.
938 @retval EFI_SUCCESS Convert success.
939 @retval EFI_INVALID_PARAMETER Incorrect storage type.
943 ConfigRespToStorage (
944 IN FORMSET_STORAGE
*Storage
,
945 IN CHAR16
*ConfigResp
955 Status
= EFI_SUCCESS
;
957 switch (Storage
->Type
) {
958 case EFI_HII_VARSTORE_BUFFER
:
959 BufferSize
= Storage
->Size
;
960 Status
= mHiiConfigRouting
->ConfigToBlock (
969 case EFI_HII_VARSTORE_NAME_VALUE
:
970 StrPtr
= StrStr (ConfigResp
, L
"&");
971 while (StrPtr
!= NULL
) {
977 StrPtr
= StrStr (StrPtr
, L
"=");
978 if (StrPtr
== NULL
) {
988 StrPtr
= StrStr (StrPtr
, L
"&");
989 if (StrPtr
!= NULL
) {
992 SetValueByName (Storage
, Name
, Value
);
996 case EFI_HII_VARSTORE_EFI_VARIABLE
:
998 Status
= EFI_INVALID_PARAMETER
;
1007 Get Question's current Value.
1009 @param FormSet FormSet data structure.
1010 @param Form Form data structure.
1011 @param Question Question to be initialized.
1012 @param Cached TRUE: get from Edit copy FALSE: get from original
1015 @retval EFI_SUCCESS The function completed successfully.
1020 IN FORM_BROWSER_FORMSET
*FormSet
,
1021 IN FORM_BROWSER_FORM
*Form
,
1022 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1032 FORMSET_STORAGE
*Storage
;
1033 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1034 CHAR16
*ConfigRequest
;
1039 BOOLEAN IsBufferStorage
;
1042 Status
= EFI_SUCCESS
;
1045 // Statement don't have storage, skip them
1047 if (Question
->QuestionId
== 0) {
1052 // Question value is provided by an Expression, evaluate it
1054 if (Question
->ValueExpression
!= NULL
) {
1055 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1056 if (!EFI_ERROR (Status
)) {
1057 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1063 // Question value is provided by RTC
1065 Storage
= Question
->Storage
;
1066 QuestionValue
= &Question
->HiiValue
.Value
;
1067 if (Storage
== NULL
) {
1069 // It's a Question without storage, or RTC date/time
1071 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1073 // Date and time define the same Flags bit
1075 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1076 case QF_DATE_STORAGE_TIME
:
1077 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1080 case QF_DATE_STORAGE_WAKEUP
:
1081 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1084 case QF_DATE_STORAGE_NORMAL
:
1087 // For date/time without storage
1092 if (EFI_ERROR (Status
)) {
1096 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1097 QuestionValue
->date
.Year
= EfiTime
.Year
;
1098 QuestionValue
->date
.Month
= EfiTime
.Month
;
1099 QuestionValue
->date
.Day
= EfiTime
.Day
;
1101 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1102 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1103 QuestionValue
->time
.Second
= EfiTime
.Second
;
1111 // Question value is provided by EFI variable
1113 StorageWidth
= Question
->StorageWidth
;
1114 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1115 if (Question
->BufferValue
!= NULL
) {
1116 Dst
= Question
->BufferValue
;
1118 Dst
= (UINT8
*) QuestionValue
;
1121 Status
= gRT
->GetVariable (
1122 Question
->VariableName
,
1129 // Always return success, even this EFI variable doesn't exist
1135 // Question Value is provided by Buffer Storage or NameValue Storage
1137 if (Question
->BufferValue
!= NULL
) {
1139 // This Question is password or orderedlist
1141 Dst
= Question
->BufferValue
;
1144 // Other type of Questions
1146 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1149 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1150 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1152 if (IsBufferStorage
) {
1154 // Copy from storage Edit buffer
1156 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1158 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1159 if (EFI_ERROR (Status
)) {
1165 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1167 Length
= StorageWidth
+ sizeof (CHAR16
);
1168 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1170 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1173 gBS
->FreePool (Value
);
1177 // Request current settings from Configuration Driver
1179 if (FormSet
->ConfigAccess
== NULL
) {
1180 return EFI_NOT_FOUND
;
1184 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1185 // <ConfigHdr> + "&" + <VariableName>
1187 if (IsBufferStorage
) {
1188 Length
= StrLen (Storage
->ConfigHdr
);
1189 Length
+= StrLen (Question
->BlockName
);
1191 Length
= StrLen (Storage
->ConfigHdr
);
1192 Length
+= StrLen (Question
->VariableName
) + 1;
1194 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1195 ASSERT (ConfigRequest
!= NULL
);
1197 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1198 if (IsBufferStorage
) {
1199 StrCat (ConfigRequest
, Question
->BlockName
);
1201 StrCat (ConfigRequest
, L
"&");
1202 StrCat (ConfigRequest
, Question
->VariableName
);
1205 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1206 FormSet
->ConfigAccess
,
1211 if (EFI_ERROR (Status
)) {
1216 // Skip <ConfigRequest>
1218 Value
= Result
+ Length
;
1219 if (IsBufferStorage
) {
1225 if (*Value
!= '=') {
1226 gBS
->FreePool (Result
);
1227 return EFI_NOT_FOUND
;
1230 // Skip '=', point to value
1233 if (!IsBufferStorage
&& IsString
) {
1235 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1237 Length
= StorageWidth
+ sizeof (CHAR16
);
1238 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1240 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1241 if (EFI_ERROR (Status
)) {
1242 gBS
->FreePool (Result
);
1248 // Synchronize Edit Buffer
1250 if (IsBufferStorage
) {
1251 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1253 SetValueByName (Storage
, Question
->VariableName
, Value
);
1255 gBS
->FreePool (Result
);
1263 Save Question Value to edit copy(cached) or Storage(uncached).
1265 @param FormSet FormSet data structure.
1266 @param Form Form data structure.
1267 @param Question Pointer to the Question.
1268 @param Cached TRUE: set to Edit copy FALSE: set to original
1271 @retval EFI_SUCCESS The function completed successfully.
1276 IN FORM_BROWSER_FORMSET
*FormSet
,
1277 IN FORM_BROWSER_FORM
*Form
,
1278 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1289 FORMSET_STORAGE
*Storage
;
1290 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1295 BOOLEAN IsBufferStorage
;
1298 Status
= EFI_SUCCESS
;
1301 // Statement don't have storage, skip them
1303 if (Question
->QuestionId
== 0) {
1308 // If Question value is provided by an Expression, then it is read only
1310 if (Question
->ValueExpression
!= NULL
) {
1315 // Question value is provided by RTC
1317 Storage
= Question
->Storage
;
1318 QuestionValue
= &Question
->HiiValue
.Value
;
1319 if (Storage
== NULL
) {
1321 // It's a Question without storage, or RTC date/time
1323 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1325 // Date and time define the same Flags bit
1327 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1328 case QF_DATE_STORAGE_TIME
:
1329 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1332 case QF_DATE_STORAGE_WAKEUP
:
1333 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1336 case QF_DATE_STORAGE_NORMAL
:
1339 // For date/time without storage
1344 if (EFI_ERROR (Status
)) {
1348 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1349 EfiTime
.Year
= QuestionValue
->date
.Year
;
1350 EfiTime
.Month
= QuestionValue
->date
.Month
;
1351 EfiTime
.Day
= QuestionValue
->date
.Day
;
1353 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1354 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1355 EfiTime
.Second
= QuestionValue
->time
.Second
;
1358 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1359 Status
= gRT
->SetTime (&EfiTime
);
1361 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1369 // Question value is provided by EFI variable
1371 StorageWidth
= Question
->StorageWidth
;
1372 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1373 if (Question
->BufferValue
!= NULL
) {
1374 Src
= Question
->BufferValue
;
1376 Src
= (UINT8
*) QuestionValue
;
1379 Status
= gRT
->SetVariable (
1380 Question
->VariableName
,
1382 Storage
->Attributes
,
1390 // Question Value is provided by Buffer Storage or NameValue Storage
1392 if (Question
->BufferValue
!= NULL
) {
1393 Src
= Question
->BufferValue
;
1395 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1398 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1399 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1400 if (IsBufferStorage
) {
1402 // Copy to storage edit buffer
1404 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1408 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1411 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1412 Value
= AllocateZeroPool (BufferLen
);
1413 ASSERT (Value
!= NULL
);
1414 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1415 ASSERT_EFI_ERROR (Status
);
1417 BufferLen
= StorageWidth
* 2 + 1;
1418 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1419 ASSERT (Value
!= NULL
);
1420 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1424 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1425 gBS
->FreePool (Value
);
1430 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1431 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1433 if (IsBufferStorage
) {
1434 Length
= StrLen (Question
->BlockName
) + 7;
1436 Length
= StrLen (Question
->VariableName
) + 2;
1438 if (!IsBufferStorage
&& IsString
) {
1439 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1441 Length
+= (StorageWidth
* 2);
1443 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1444 ASSERT (ConfigResp
!= NULL
);
1446 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1447 if (IsBufferStorage
) {
1448 StrCat (ConfigResp
, Question
->BlockName
);
1449 StrCat (ConfigResp
, L
"&VALUE=");
1451 StrCat (ConfigResp
, L
"&");
1452 StrCat (ConfigResp
, Question
->VariableName
);
1453 StrCat (ConfigResp
, L
"=");
1456 Value
= ConfigResp
+ StrLen (ConfigResp
);
1457 if (!IsBufferStorage
&& IsString
) {
1459 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1461 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1462 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1463 ASSERT_EFI_ERROR (Status
);
1465 BufferLen
= StorageWidth
* 2 + 1;
1466 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1471 // Submit Question Value to Configuration Driver
1473 if (FormSet
->ConfigAccess
!= NULL
) {
1474 Status
= FormSet
->ConfigAccess
->RouteConfig (
1475 FormSet
->ConfigAccess
,
1479 if (EFI_ERROR (Status
)) {
1480 gBS
->FreePool (ConfigResp
);
1484 gBS
->FreePool (ConfigResp
);
1487 // Synchronize shadow Buffer
1489 SynchronizeStorage (Storage
);
1497 Perform inconsistent check for a Form.
1499 @param FormSet FormSet data structure.
1500 @param Form Form data structure.
1501 @param Question The Question to be validated.
1502 @param Type Validation type: InConsistent or NoSubmit
1504 @retval EFI_SUCCESS Form validation pass.
1505 @retval other Form validation failed.
1510 IN FORM_BROWSER_FORMSET
*FormSet
,
1511 IN FORM_BROWSER_FORM
*Form
,
1512 IN FORM_BROWSER_STATEMENT
*Question
,
1518 LIST_ENTRY
*ListHead
;
1521 FORM_EXPRESSION
*Expression
;
1523 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1524 ListHead
= &Question
->InconsistentListHead
;
1525 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1526 ListHead
= &Question
->NoSubmitListHead
;
1528 return EFI_UNSUPPORTED
;
1531 Link
= GetFirstNode (ListHead
);
1532 while (!IsNull (ListHead
, Link
)) {
1533 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1536 // Evaluate the expression
1538 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1539 if (EFI_ERROR (Status
)) {
1543 if (Expression
->Result
.Value
.b
) {
1545 // Condition meet, show up error message
1547 if (Expression
->Error
!= 0) {
1548 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1550 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1551 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1552 gBS
->FreePool (PopUp
);
1555 return EFI_NOT_READY
;
1558 Link
= GetNextNode (ListHead
, Link
);
1566 Perform NoSubmit check for a Form.
1568 @param FormSet FormSet data structure.
1569 @param Form Form data structure.
1571 @retval EFI_SUCCESS Form validation pass.
1572 @retval other Form validation failed.
1577 IN FORM_BROWSER_FORMSET
*FormSet
,
1578 IN FORM_BROWSER_FORM
*Form
1583 FORM_BROWSER_STATEMENT
*Question
;
1585 Link
= GetFirstNode (&Form
->StatementListHead
);
1586 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1587 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1589 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1590 if (EFI_ERROR (Status
)) {
1594 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1604 @param FormSet FormSet data structure.
1605 @param Form Form data structure.
1607 @retval EFI_SUCCESS The function completed successfully.
1612 IN FORM_BROWSER_FORMSET
*FormSet
,
1613 IN FORM_BROWSER_FORM
*Form
1618 EFI_STRING ConfigResp
;
1619 EFI_STRING Progress
;
1620 FORMSET_STORAGE
*Storage
;
1623 // Validate the Form by NoSubmit check
1625 Status
= NoSubmitCheck (FormSet
, Form
);
1626 if (EFI_ERROR (Status
)) {
1631 // Submit Buffer storage or Name/Value storage
1633 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1634 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1635 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1636 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1638 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1643 // Skip if there is no RequestElement
1645 if (Storage
->ElementCount
== 0) {
1650 // Prepare <ConfigResp>
1652 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1653 if (EFI_ERROR (Status
)) {
1658 // Send <ConfigResp> to Configuration Driver
1660 if (FormSet
->ConfigAccess
!= NULL
) {
1661 Status
= FormSet
->ConfigAccess
->RouteConfig (
1662 FormSet
->ConfigAccess
,
1666 if (EFI_ERROR (Status
)) {
1667 gBS
->FreePool (ConfigResp
);
1671 gBS
->FreePool (ConfigResp
);
1674 // Config success, update storage shadow Buffer
1676 SynchronizeStorage (Storage
);
1679 gNvUpdateRequired
= FALSE
;
1686 Reset Question to its default value.
1688 @param FormSet The form set.
1689 @param Form The form.
1690 @param Question The question.
1691 @param DefaultId The Class of the default.
1693 @retval EFI_SUCCESS Question is reset to default value.
1697 GetQuestionDefault (
1698 IN FORM_BROWSER_FORMSET
*FormSet
,
1699 IN FORM_BROWSER_FORM
*Form
,
1700 IN FORM_BROWSER_STATEMENT
*Question
,
1706 QUESTION_DEFAULT
*Default
;
1707 QUESTION_OPTION
*Option
;
1708 EFI_HII_VALUE
*HiiValue
;
1711 Status
= EFI_SUCCESS
;
1714 // Statement don't have storage, skip them
1716 if (Question
->QuestionId
== 0) {
1721 // There are three ways to specify default value for a Question:
1722 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1723 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1724 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1726 HiiValue
= &Question
->HiiValue
;
1729 // EFI_IFR_DEFAULT has highest priority
1731 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1732 Link
= GetFirstNode (&Question
->DefaultListHead
);
1733 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1734 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1736 if (Default
->DefaultId
== DefaultId
) {
1737 if (Default
->ValueExpression
!= NULL
) {
1739 // Default is provided by an Expression, evaluate it
1741 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1742 if (EFI_ERROR (Status
)) {
1746 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1749 // Default value is embedded in EFI_IFR_DEFAULT
1751 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1757 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1762 // EFI_ONE_OF_OPTION
1764 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1765 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1767 // OneOfOption could only provide Standard and Manufacturing default
1769 Link
= GetFirstNode (&Question
->OptionListHead
);
1770 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1771 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1773 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
1774 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
1776 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1781 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1787 // EFI_IFR_CHECKBOX - lowest priority
1789 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1790 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1792 // Checkbox could only provide Standard and Manufacturing default
1794 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
1795 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
1797 HiiValue
->Value
.b
= TRUE
;
1799 HiiValue
->Value
.b
= FALSE
;
1807 // For Questions without default
1809 switch (Question
->Operand
) {
1810 case EFI_IFR_NUMERIC_OP
:
1812 // Take minimal value as numeric's default value
1814 HiiValue
->Value
.u64
= Question
->Minimum
;
1817 case EFI_IFR_ONE_OF_OP
:
1819 // Take first oneof option as oneof's default value
1821 Link
= GetFirstNode (&Question
->OptionListHead
);
1822 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1823 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1824 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1828 case EFI_IFR_ORDERED_LIST_OP
:
1830 // Take option sequence in IFR as ordered list's default value
1833 Link
= GetFirstNode (&Question
->OptionListHead
);
1834 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1835 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1837 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1840 if (Index
>= Question
->MaxContainers
) {
1844 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1849 Status
= EFI_NOT_FOUND
;
1858 Reset Questions in a Form to their default value.
1860 @param FormSet FormSet data structure.
1861 @param Form The Form which to be reset.
1862 @param DefaultId The Class of the default.
1864 @retval EFI_SUCCESS The function completed successfully.
1868 ExtractFormDefault (
1869 IN FORM_BROWSER_FORMSET
*FormSet
,
1870 IN FORM_BROWSER_FORM
*Form
,
1876 FORM_BROWSER_STATEMENT
*Question
;
1878 Link
= GetFirstNode (&Form
->StatementListHead
);
1879 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1880 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1881 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1884 // Reset Question to its default value
1886 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1887 if (EFI_ERROR (Status
)) {
1892 // Synchronize Buffer storage's Edit buffer
1894 if ((Question
->Storage
!= NULL
) &&
1895 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1896 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1905 Initialize Question's Edit copy from Storage.
1907 @param FormSet FormSet data structure.
1908 @param Form Form data structure.
1910 @retval EFI_SUCCESS The function completed successfully.
1915 IN FORM_BROWSER_FORMSET
*FormSet
,
1916 IN FORM_BROWSER_FORM
*Form
1921 FORM_BROWSER_STATEMENT
*Question
;
1923 Link
= GetFirstNode (&Form
->StatementListHead
);
1924 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1925 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1928 // Initialize local copy of Value for each Question
1930 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1931 if (EFI_ERROR (Status
)) {
1935 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1943 Fill storage's edit copy with settings requested from Configuration Driver.
1945 @param FormSet FormSet data structure.
1946 @param Storage Buffer Storage.
1948 @retval EFI_SUCCESS The function completed successfully.
1953 IN FORM_BROWSER_FORMSET
*FormSet
,
1954 IN FORMSET_STORAGE
*Storage
1958 EFI_STRING Progress
;
1962 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1966 if (FormSet
->ConfigAccess
== NULL
) {
1967 return EFI_NOT_FOUND
;
1970 if (Storage
->ElementCount
== 0) {
1972 // Skip if there is no RequestElement
1978 // Request current settings from Configuration Driver
1980 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1981 FormSet
->ConfigAccess
,
1982 Storage
->ConfigRequest
,
1986 if (EFI_ERROR (Status
)) {
1991 // Convert Result from <ConfigAltResp> to <ConfigResp>
1993 StrPtr
= StrStr (Result
, L
"ALTCFG");
1994 if (StrPtr
!= NULL
) {
1998 Status
= ConfigRespToStorage (Storage
, Result
);
1999 gBS
->FreePool (Result
);
2005 Get current setting of Questions.
2007 @param FormSet FormSet data structure.
2009 @retval EFI_SUCCESS The function completed successfully.
2013 InitializeCurrentSetting (
2014 IN OUT FORM_BROWSER_FORMSET
*FormSet
2018 FORMSET_STORAGE
*Storage
;
2019 FORM_BROWSER_FORM
*Form
;
2023 // Extract default from IFR binary
2025 Link
= GetFirstNode (&FormSet
->FormListHead
);
2026 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2027 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2029 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2031 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2035 // Request current settings from Configuration Driver
2037 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2038 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2039 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2041 Status
= LoadStorage (FormSet
, Storage
);
2044 // Now Edit Buffer is filled with default values(lower priority) and current
2045 // settings(higher priority), sychronize it to shadow Buffer
2047 if (!EFI_ERROR (Status
)) {
2048 SynchronizeStorage (Storage
);
2051 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2059 Fetch the Ifr binary data of a FormSet.
2061 @param Handle PackageList Handle
2062 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2063 GUID), take the first FormSet found in package
2065 @param BinaryLength The length of the FormSet IFR binary.
2066 @param BinaryData The buffer designed to receive the FormSet.
2068 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2069 BufferLength was updated.
2070 @retval EFI_INVALID_PARAMETER The handle is unknown.
2071 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2072 be found with the requested FormId.
2077 IN EFI_HII_HANDLE Handle
,
2078 IN OUT EFI_GUID
*FormSetGuid
,
2079 OUT UINTN
*BinaryLength
,
2080 OUT UINT8
**BinaryData
2084 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2090 BOOLEAN ReturnDefault
;
2091 UINT32 PackageListLength
;
2092 EFI_HII_PACKAGE_HEADER PackageHeader
;
2096 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2099 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2101 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2102 ReturnDefault
= TRUE
;
2104 ReturnDefault
= FALSE
;
2108 // Get HII PackageList
2111 HiiPackageList
= NULL
;
2112 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2113 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2114 HiiPackageList
= AllocatePool (BufferSize
);
2115 ASSERT (HiiPackageList
!= NULL
);
2117 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2119 if (EFI_ERROR (Status
)) {
2124 // Get Form package from this HII package List
2126 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2128 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2130 while (Offset
< PackageListLength
) {
2131 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2132 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2134 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORM
) {
2136 // Search FormSet in this Form Package
2138 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2139 while (Offset2
< PackageHeader
.Length
) {
2140 OpCodeData
= Package
+ Offset2
;
2142 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2144 // Check whether return default FormSet
2146 if (ReturnDefault
) {
2151 // FormSet GUID is specified, check it
2153 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2158 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2161 if (Offset2
< PackageHeader
.Length
) {
2163 // Target formset found
2169 Offset
+= PackageHeader
.Length
;
2172 if (Offset
>= PackageListLength
) {
2174 // Form package not found in this Package List
2176 gBS
->FreePool (HiiPackageList
);
2177 return EFI_NOT_FOUND
;
2180 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2182 // Return the default FormSet GUID
2184 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2188 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2189 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2190 // of the Form Package.
2192 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2193 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2195 gBS
->FreePool (HiiPackageList
);
2197 if (*BinaryData
== NULL
) {
2198 return EFI_OUT_OF_RESOURCES
;
2206 Initialize the internal data structure of a FormSet.
2208 @param Handle PackageList Handle
2209 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2210 GUID), take the first FormSet found in package
2212 @param FormSet FormSet data structure.
2214 @retval EFI_SUCCESS The function completed successfully.
2215 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2220 IN EFI_HII_HANDLE Handle
,
2221 IN OUT EFI_GUID
*FormSetGuid
,
2222 OUT FORM_BROWSER_FORMSET
*FormSet
2226 EFI_HANDLE DriverHandle
;
2229 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2230 if (EFI_ERROR (Status
)) {
2234 FormSet
->HiiHandle
= Handle
;
2235 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2238 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2240 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2241 if (EFI_ERROR (Status
)) {
2244 FormSet
->DriverHandle
= DriverHandle
;
2245 Status
= gBS
->HandleProtocol (
2247 &gEfiHiiConfigAccessProtocolGuid
,
2248 (VOID
**) &FormSet
->ConfigAccess
2250 if (EFI_ERROR (Status
)) {
2252 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2253 // list, then there will be no configuration action required
2255 FormSet
->ConfigAccess
= NULL
;
2259 // Parse the IFR binary OpCodes
2261 Status
= ParseOpCodes (FormSet
);
2262 if (EFI_ERROR (Status
)) {
2266 gClassOfVfr
= FormSet
->SubClass
;
2267 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2268 FrontPageHandle
= FormSet
->HiiHandle
;
2272 // Match GUID to find out the function key setting. If match fail, use the default setting.
2274 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2275 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2277 // Update the function key setting.
2279 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2281 // Function key prompt can not be displayed if the function key has been disabled.
2283 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2284 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2287 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2288 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2291 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2292 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2295 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2296 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);