2 Copyright (c) 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 Entry and initialization module for the browser.
26 SETUP_DRIVER_PRIVATE_DATA mPrivateData
= {
27 SETUP_DRIVER_SIGNATURE
,
38 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
39 EFI_HII_STRING_PROTOCOL
*mHiiString
;
40 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
42 BANNER_DATA
*BannerData
;
43 EFI_HII_HANDLE FrontPageHandle
;
45 UINTN gFunctionKeySetting
;
46 BOOLEAN gResetRequired
;
47 BOOLEAN gNvUpdateRequired
;
48 EFI_HII_HANDLE gHiiHandle
;
51 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
56 // Browser Global Strings
58 CHAR16
*gFunctionOneString
;
59 CHAR16
*gFunctionTwoString
;
60 CHAR16
*gFunctionNineString
;
61 CHAR16
*gFunctionTenString
;
63 CHAR16
*gEnterCommitString
;
64 CHAR16
*gEscapeString
;
66 CHAR16
*gMoveHighlight
;
67 CHAR16
*gMakeSelection
;
68 CHAR16
*gDecNumericInput
;
69 CHAR16
*gHexNumericInput
;
70 CHAR16
*gToggleCheckBox
;
71 CHAR16
*gPromptForData
;
72 CHAR16
*gPromptForPassword
;
73 CHAR16
*gPromptForNewPassword
;
74 CHAR16
*gConfirmPassword
;
75 CHAR16
*gConfirmError
;
76 CHAR16
*gPassowordInvalid
;
85 CHAR16
*gAdjustNumber
;
87 CHAR16 gPromptBlockWidth
;
88 CHAR16 gOptionBlockWidth
;
89 CHAR16 gHelpBlockWidth
;
91 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
92 EFI_GUID gSetupBrowserGuid
= {
93 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
96 FUNCTIION_KEY_SETTING gFunctionKeySettingTable
[] = {
116 NONE_FUNCTION_KEY_SETTING
137 NONE_FUNCTION_KEY_SETTING
158 NONE_FUNCTION_KEY_SETTING
161 // BMM File Explorer FormSet.
179 NONE_FUNCTION_KEY_SETTING
186 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
187 IN EFI_HII_HANDLE
*Handles
,
188 IN UINTN HandleCount
,
189 IN EFI_GUID
*FormSetGuid
, OPTIONAL
190 IN UINT16 FormId
, OPTIONAL
191 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
192 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
197 This is the routine which an external caller uses to direct the browser
198 where to obtain it's information.
201 This - The Form Browser protocol instanse.
202 Handles - A pointer to an array of Handles. If HandleCount > 1 we
203 display a list of the formsets for the handles specified.
204 HandleCount - The number of Handles specified in Handle.
205 FormSetGuid - This field points to the EFI_GUID which must match the Guid
206 field in the EFI_IFR_FORM_SET op-code for the specified
207 forms-based package. If FormSetGuid is NULL, then this
208 function will display the first found forms package.
209 FormId - This field specifies which EFI_IFR_FORM to render as the first
210 displayable page. If this field has a value of 0x0000, then
211 the forms browser will render the specified forms in their encoded order.
212 ScreenDimenions - This allows the browser to be called so that it occupies a
213 portion of the physical screen instead of dynamically determining the screen dimensions.
214 ActionRequest - Points to the action recommended by the form.
217 EFI_SUCCESS - The function completed successfully.
218 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
219 EFI_NOT_FOUND - No valid forms could be found to display.
224 UI_MENU_SELECTION
*Selection
;
226 FORM_BROWSER_FORMSET
*FormSet
;
228 Status
= EFI_SUCCESS
;
229 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
232 // Seed the dimensions in the global
234 gST
->ConOut
->QueryMode (
236 gST
->ConOut
->Mode
->Mode
,
237 &gScreenDimensions
.RightColumn
,
238 &gScreenDimensions
.BottomRow
241 if (ScreenDimensions
!= NULL
) {
243 // Check local dimension vs. global dimension.
245 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
246 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
248 return EFI_INVALID_PARAMETER
;
251 // Local dimension validation.
253 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
254 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
255 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
257 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
258 SCROLL_ARROW_HEIGHT
*
260 FRONT_PAGE_HEADER_HEIGHT
+
265 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
267 return EFI_INVALID_PARAMETER
;
272 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
273 gHelpBlockWidth
= gOptionBlockWidth
;
274 gPromptBlockWidth
= gOptionBlockWidth
;
277 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
279 InitializeBrowserStrings ();
281 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
282 gClassOfVfr
= EFI_SETUP_APPLICATION_SUBCLASS
;
285 // Ensure we are in Text mode
289 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
293 for (Index
= 0; Index
< HandleCount
; Index
++) {
294 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
295 ASSERT (Selection
!= NULL
);
297 Selection
->Handle
= Handles
[Index
];
298 if (FormSetGuid
!= NULL
) {
299 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
300 Selection
->FormId
= FormId
;
304 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
305 ASSERT (FormSet
!= NULL
);
308 // Initialize internal data structures of FormSet
310 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
311 if (EFI_ERROR (Status
)) {
312 DestroyFormSet (FormSet
);
315 Selection
->FormSet
= FormSet
;
318 // Initialize current settings of Questions in this FormSet
320 Status
= InitializeCurrentSetting (FormSet
);
321 if (EFI_ERROR (Status
)) {
322 DestroyFormSet (FormSet
);
327 // Display this formset
329 gCurrentSelection
= Selection
;
331 Status
= SetupBrowser (Selection
);
333 gCurrentSelection
= NULL
;
334 DestroyFormSet (FormSet
);
336 if (EFI_ERROR (Status
)) {
340 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
342 gBS
->FreePool (Selection
);
345 if (ActionRequest
!= NULL
) {
346 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
347 if (gResetRequired
) {
348 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
352 FreeBrowserStrings ();
354 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
355 gST
->ConOut
->ClearScreen (gST
->ConOut
);
362 This function is called by a callback handler to retrieve uncommitted state
363 data from the browser.
365 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
367 @param ResultsDataSize A pointer to the size of the buffer associated
369 @param ResultsData A string returned from an IFR browser or
370 equivalent. The results string will have no
371 routing information in them.
372 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
373 (if RetrieveData = TRUE) data from the uncommitted
374 browser state information or set (if RetrieveData
375 = FALSE) data in the uncommitted browser state
377 @param VariableGuid An optional field to indicate the target variable
379 @param VariableName An optional field to indicate the target
380 human-readable variable name.
382 @retval EFI_SUCCESS The results have been distributed or are awaiting
384 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
385 contain the results data.
391 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
392 IN OUT UINTN
*ResultsDataSize
,
393 IN OUT EFI_STRING ResultsData
,
394 IN BOOLEAN RetrieveData
,
395 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
396 IN CONST CHAR16
*VariableName OPTIONAL
401 FORMSET_STORAGE
*Storage
;
402 FORM_BROWSER_FORMSET
*FormSet
;
409 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
410 return EFI_INVALID_PARAMETER
;
413 if (gCurrentSelection
== NULL
) {
414 return EFI_NOT_READY
;
419 FormSet
= gCurrentSelection
->FormSet
;
422 // Find target storage
424 Link
= GetFirstNode (&FormSet
->StorageListHead
);
425 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
426 return EFI_UNSUPPORTED
;
429 if (VariableGuid
!= NULL
) {
431 // Try to find target storage
434 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
435 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
436 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
438 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
439 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
441 // Buffer storage require both GUID and Name
443 if (VariableName
== NULL
) {
444 return EFI_NOT_FOUND
;
447 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
457 return EFI_NOT_FOUND
;
461 // GUID/Name is not specified, take the first storage in FormSet
463 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
468 // Skip if there is no RequestElement
470 if (Storage
->ElementCount
== 0) {
475 // Generate <ConfigResp>
477 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
478 if (EFI_ERROR (Status
)) {
483 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
485 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
487 BufferSize
= StrSize (StrPtr
);
488 if (*ResultsDataSize
< BufferSize
) {
489 *ResultsDataSize
= BufferSize
;
491 gBS
->FreePool (ConfigResp
);
492 return EFI_BUFFER_TOO_SMALL
;
495 *ResultsDataSize
= BufferSize
;
496 CopyMem (ResultsData
, StrPtr
, BufferSize
);
498 gBS
->FreePool (ConfigResp
);
501 // Prepare <ConfigResp>
503 TmpSize
= StrLen (ResultsData
);
504 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
505 ConfigResp
= AllocateZeroPool (BufferSize
);
506 ASSERT (ConfigResp
!= NULL
);
508 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
509 StrCat (ConfigResp
, L
"&");
510 StrCat (ConfigResp
, ResultsData
);
513 // Update Browser uncommited data
515 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
516 if (EFI_ERROR (Status
)) {
528 @param entry EFI_IMAGE_ENTRY_POINT)
530 @retval EFI_SUCCESS Setup loaded.
531 @retval other Setup Error
537 IN EFI_HANDLE ImageHandle
,
538 IN EFI_SYSTEM_TABLE
*SystemTable
542 EFI_HANDLE HiiDriverHandle
;
543 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
546 // Locate required Hii relative protocols
548 Status
= gBS
->LocateProtocol (
549 &gEfiHiiDatabaseProtocolGuid
,
551 (VOID
**) &mHiiDatabase
553 ASSERT_EFI_ERROR (Status
);
555 Status
= gBS
->LocateProtocol (
556 &gEfiHiiStringProtocolGuid
,
558 (VOID
**) &mHiiString
560 ASSERT_EFI_ERROR (Status
);
562 Status
= gBS
->LocateProtocol (
563 &gEfiHiiConfigRoutingProtocolGuid
,
565 (VOID
**) &mHiiConfigRouting
567 ASSERT_EFI_ERROR (Status
);
570 // Publish our HII data
572 Status
= HiiLibCreateHiiDriverHandle (&HiiDriverHandle
);
573 ASSERT_EFI_ERROR (Status
);
575 PackageList
= HiiLibPreparePackageList (1, &gSetupBrowserGuid
, SetupBrowserStrings
);
576 ASSERT (PackageList
!= NULL
);
577 Status
= mHiiDatabase
->NewPackageList (
583 ASSERT_EFI_ERROR (Status
);
586 // Initialize Driver private data
589 BannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
590 ASSERT (BannerData
!= NULL
);
593 // Install FormBrowser2 protocol
595 mPrivateData
.Handle
= NULL
;
596 Status
= gBS
->InstallProtocolInterface (
597 &mPrivateData
.Handle
,
598 &gEfiFormBrowser2ProtocolGuid
,
599 EFI_NATIVE_INTERFACE
,
600 &mPrivateData
.FormBrowser2
602 ASSERT_EFI_ERROR (Status
);
605 // Install Print protocol
607 Status
= gBS
->InstallProtocolInterface (
608 &mPrivateData
.Handle
,
609 &gEfiPrintProtocolGuid
,
610 EFI_NATIVE_INTERFACE
,
619 Create a new string in HII Package List.
621 @param String The String to be added
622 @param HiiHandle The package list in the HII database to insert the
625 @return The output string.
631 IN EFI_HII_HANDLE HiiHandle
634 EFI_STRING_ID StringId
;
638 Status
= HiiLibNewString (HiiHandle
, &StringId
, String
);
639 ASSERT_EFI_ERROR (Status
);
646 Delete a string from HII Package List.
648 @param StringId Id of the string in HII database.
649 @param HiiHandle The HII package list handle.
651 @retval EFI_SUCCESS The string was deleted successfully.
656 IN EFI_STRING_ID StringId
,
657 IN EFI_HII_HANDLE HiiHandle
662 NullChar
= CHAR_NULL
;
663 return HiiLibSetString (HiiHandle
, StringId
, &NullChar
);
668 Get the string based on the StringId and HII Package List Handle.
670 @param Token The String's ID.
671 @param HiiHandle The package list in the HII database to search for
672 the specified string.
674 @return The output string.
679 IN EFI_STRING_ID Token
,
680 IN EFI_HII_HANDLE HiiHandle
688 // Set default string size assumption at no more than 256 bytes
690 BufferLength
= 0x100;
691 String
= AllocateZeroPool (BufferLength
);
692 ASSERT (String
!= NULL
);
694 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
696 if (Status
== EFI_BUFFER_TOO_SMALL
) {
697 gBS
->FreePool (String
);
698 String
= AllocateZeroPool (BufferLength
);
699 ASSERT (String
!= NULL
);
701 Status
= HiiLibGetString (HiiHandle
, Token
, String
, &BufferLength
);
703 ASSERT_EFI_ERROR (Status
);
710 Allocate new memory and then copy the Unicode string Source to Destination.
712 @param Dest Location to copy string
713 @param Src String to copy
720 IN OUT CHAR16
**Dest
,
724 SafeFreePool (*Dest
);
725 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
726 ASSERT (*Dest
!= NULL
);
731 Allocate new memory and concatinate Source on the end of Destination.
733 @param Dest String to added to the end of.
734 @param Src String to concatinate.
741 IN OUT CHAR16
**Dest
,
749 NewStringCpy (Dest
, Src
);
753 TmpSize
= StrSize (*Dest
);
754 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
755 ASSERT (NewString
!= NULL
);
757 StrCpy (NewString
, *Dest
);
758 StrCat (NewString
, Src
);
760 gBS
->FreePool (*Dest
);
766 Synchronize Storage's Edit copy to Shadow copy.
768 @param Storage The Storage to be synchronized.
775 IN FORMSET_STORAGE
*Storage
779 NAME_VALUE_NODE
*Node
;
781 switch (Storage
->Type
) {
782 case EFI_HII_VARSTORE_BUFFER
:
783 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
786 case EFI_HII_VARSTORE_NAME_VALUE
:
787 Link
= GetFirstNode (&Storage
->NameValueListHead
);
788 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
789 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
791 NewStringCpy (&Node
->Value
, Node
->EditValue
);
793 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
797 case EFI_HII_VARSTORE_EFI_VARIABLE
:
805 Get Value for given Name from a NameValue Storage.
807 @param Storage The NameValue Storage.
808 @param Name The Name.
809 @param Value The retured Value.
811 @retval EFI_SUCCESS Value found for given Name.
812 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
817 IN FORMSET_STORAGE
*Storage
,
819 IN OUT CHAR16
**Value
823 NAME_VALUE_NODE
*Node
;
827 Link
= GetFirstNode (&Storage
->NameValueListHead
);
828 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
829 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
831 if (StrCmp (Name
, Node
->Name
) == 0) {
832 NewStringCpy (Value
, Node
->EditValue
);
836 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
839 return EFI_NOT_FOUND
;
844 Set Value of given Name in a NameValue Storage.
846 @param Storage The NameValue Storage.
847 @param Name The Name.
848 @param Value The Value to set.
850 @retval EFI_SUCCESS Value found for given Name.
851 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
856 IN FORMSET_STORAGE
*Storage
,
862 NAME_VALUE_NODE
*Node
;
864 Link
= GetFirstNode (&Storage
->NameValueListHead
);
865 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
866 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
868 if (StrCmp (Name
, Node
->Name
) == 0) {
869 SafeFreePool (Node
->EditValue
);
870 Node
->EditValue
= AllocateCopyPool (StrSize (Value
), Value
);
871 ASSERT (Node
->EditValue
!= NULL
);
875 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
878 return EFI_NOT_FOUND
;
883 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
885 @param Storage The Storage to be conveted.
886 @param ConfigResp The returned <ConfigResp>.
888 @retval EFI_SUCCESS Convert success.
889 @retval EFI_INVALID_PARAMETER Incorrect storage type.
893 StorageToConfigResp (
894 IN FORMSET_STORAGE
*Storage
,
895 IN CHAR16
**ConfigResp
901 NAME_VALUE_NODE
*Node
;
903 Status
= EFI_SUCCESS
;
905 switch (Storage
->Type
) {
906 case EFI_HII_VARSTORE_BUFFER
:
907 Status
= mHiiConfigRouting
->BlockToConfig (
909 Storage
->ConfigRequest
,
917 case EFI_HII_VARSTORE_NAME_VALUE
:
919 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
921 Link
= GetFirstNode (&Storage
->NameValueListHead
);
922 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
923 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
925 NewStringCat (ConfigResp
, L
"&");
926 NewStringCat (ConfigResp
, Node
->Name
);
927 NewStringCat (ConfigResp
, L
"=");
928 NewStringCat (ConfigResp
, Node
->EditValue
);
930 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
934 case EFI_HII_VARSTORE_EFI_VARIABLE
:
936 Status
= EFI_INVALID_PARAMETER
;
945 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
947 @param Storage The Storage to receive the settings.
948 @param ConfigResp The <ConfigResp> to be converted.
950 @retval EFI_SUCCESS Convert success.
951 @retval EFI_INVALID_PARAMETER Incorrect storage type.
955 ConfigRespToStorage (
956 IN FORMSET_STORAGE
*Storage
,
957 IN CHAR16
*ConfigResp
967 Status
= EFI_SUCCESS
;
969 switch (Storage
->Type
) {
970 case EFI_HII_VARSTORE_BUFFER
:
971 BufferSize
= Storage
->Size
;
972 Status
= mHiiConfigRouting
->ConfigToBlock (
981 case EFI_HII_VARSTORE_NAME_VALUE
:
982 StrPtr
= StrStr (ConfigResp
, L
"&");
983 while (StrPtr
!= NULL
) {
989 StrPtr
= StrStr (StrPtr
, L
"=");
990 if (StrPtr
== NULL
) {
1000 StrPtr
= StrStr (StrPtr
, L
"&");
1001 if (StrPtr
!= NULL
) {
1004 SetValueByName (Storage
, Name
, Value
);
1008 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1010 Status
= EFI_INVALID_PARAMETER
;
1019 Get Question's current Value.
1021 @param FormSet FormSet data structure.
1022 @param Form Form data structure.
1023 @param Question Question to be initialized.
1024 @param Cached TRUE: get from Edit copy FALSE: get from original
1027 @retval EFI_SUCCESS The function completed successfully.
1032 IN FORM_BROWSER_FORMSET
*FormSet
,
1033 IN FORM_BROWSER_FORM
*Form
,
1034 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1044 FORMSET_STORAGE
*Storage
;
1045 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1046 CHAR16
*ConfigRequest
;
1051 BOOLEAN IsBufferStorage
;
1054 Status
= EFI_SUCCESS
;
1057 // Statement don't have storage, skip them
1059 if (Question
->QuestionId
== 0) {
1064 // Question value is provided by an Expression, evaluate it
1066 if (Question
->ValueExpression
!= NULL
) {
1067 Status
= EvaluateExpression (FormSet
, Form
, Question
->ValueExpression
);
1068 if (!EFI_ERROR (Status
)) {
1069 CopyMem (&Question
->HiiValue
, &Question
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1075 // Question value is provided by RTC
1077 Storage
= Question
->Storage
;
1078 QuestionValue
= &Question
->HiiValue
.Value
;
1079 if (Storage
== NULL
) {
1081 // It's a Question without storage, or RTC date/time
1083 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1085 // Date and time define the same Flags bit
1087 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1088 case QF_DATE_STORAGE_TIME
:
1089 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1092 case QF_DATE_STORAGE_WAKEUP
:
1093 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1096 case QF_DATE_STORAGE_NORMAL
:
1099 // For date/time without storage
1104 if (EFI_ERROR (Status
)) {
1108 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1109 QuestionValue
->date
.Year
= EfiTime
.Year
;
1110 QuestionValue
->date
.Month
= EfiTime
.Month
;
1111 QuestionValue
->date
.Day
= EfiTime
.Day
;
1113 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1114 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1115 QuestionValue
->time
.Second
= EfiTime
.Second
;
1123 // Question value is provided by EFI variable
1125 StorageWidth
= Question
->StorageWidth
;
1126 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1127 if (Question
->BufferValue
!= NULL
) {
1128 Dst
= Question
->BufferValue
;
1130 Dst
= (UINT8
*) QuestionValue
;
1133 Status
= gRT
->GetVariable (
1134 Question
->VariableName
,
1141 // Always return success, even this EFI variable doesn't exist
1147 // Question Value is provided by Buffer Storage or NameValue Storage
1149 if (Question
->BufferValue
!= NULL
) {
1151 // This Question is password or orderedlist
1153 Dst
= Question
->BufferValue
;
1156 // Other type of Questions
1158 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1161 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1162 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1164 if (IsBufferStorage
) {
1166 // Copy from storage Edit buffer
1168 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1170 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1171 if (EFI_ERROR (Status
)) {
1176 StrCpy ((CHAR16
*) Dst
, Value
);
1178 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1181 gBS
->FreePool (Value
);
1185 // Request current settings from Configuration Driver
1187 if (FormSet
->ConfigAccess
== NULL
) {
1188 return EFI_NOT_FOUND
;
1192 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1193 // <ConfigHdr> + "&" + <VariableName>
1195 if (IsBufferStorage
) {
1196 Length
= StrLen (Storage
->ConfigHdr
);
1197 Length
+= StrLen (Question
->BlockName
);
1199 Length
= StrLen (Storage
->ConfigHdr
);
1200 Length
+= StrLen (Question
->VariableName
) + 1;
1202 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1203 ASSERT (ConfigRequest
!= NULL
);
1205 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1206 if (IsBufferStorage
) {
1207 StrCat (ConfigRequest
, Question
->BlockName
);
1209 StrCat (ConfigRequest
, L
"&");
1210 StrCat (ConfigRequest
, Question
->VariableName
);
1213 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1214 FormSet
->ConfigAccess
,
1219 if (EFI_ERROR (Status
)) {
1224 // Skip <ConfigRequest>
1226 Value
= Result
+ Length
;
1227 if (IsBufferStorage
) {
1233 if (*Value
!= '=') {
1234 gBS
->FreePool (Result
);
1235 return EFI_NOT_FOUND
;
1238 // Skip '=', point to value
1241 if (!IsBufferStorage
&& IsString
) {
1242 StrCpy ((CHAR16
*) Dst
, Value
);
1244 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1245 if (EFI_ERROR (Status
)) {
1246 gBS
->FreePool (Result
);
1252 // Synchronize Edit Buffer
1254 if (IsBufferStorage
) {
1255 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1257 SetValueByName (Storage
, Question
->VariableName
, Value
);
1259 gBS
->FreePool (Result
);
1267 Save Question Value to edit copy(cached) or Storage(uncached).
1269 @param FormSet FormSet data structure.
1270 @param Form Form data structure.
1271 @param Question Pointer to the Question.
1272 @param Cached TRUE: set to Edit copy FALSE: set to original
1275 @retval EFI_SUCCESS The function completed successfully.
1280 IN FORM_BROWSER_FORMSET
*FormSet
,
1281 IN FORM_BROWSER_FORM
*Form
,
1282 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1293 FORMSET_STORAGE
*Storage
;
1294 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1299 BOOLEAN IsBufferStorage
;
1302 Status
= EFI_SUCCESS
;
1305 // Statement don't have storage, skip them
1307 if (Question
->QuestionId
== 0) {
1312 // If Question value is provided by an Expression, then it is read only
1314 if (Question
->ValueExpression
!= NULL
) {
1319 // Question value is provided by RTC
1321 Storage
= Question
->Storage
;
1322 QuestionValue
= &Question
->HiiValue
.Value
;
1323 if (Storage
== NULL
) {
1325 // It's a Question without storage, or RTC date/time
1327 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1329 // Date and time define the same Flags bit
1331 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1332 case QF_DATE_STORAGE_TIME
:
1333 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1336 case QF_DATE_STORAGE_WAKEUP
:
1337 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1340 case QF_DATE_STORAGE_NORMAL
:
1343 // For date/time without storage
1348 if (EFI_ERROR (Status
)) {
1352 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1353 EfiTime
.Year
= QuestionValue
->date
.Year
;
1354 EfiTime
.Month
= QuestionValue
->date
.Month
;
1355 EfiTime
.Day
= QuestionValue
->date
.Day
;
1357 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1358 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1359 EfiTime
.Second
= QuestionValue
->time
.Second
;
1362 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1363 Status
= gRT
->SetTime (&EfiTime
);
1365 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1373 // Question value is provided by EFI variable
1375 StorageWidth
= Question
->StorageWidth
;
1376 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1377 if (Question
->BufferValue
!= NULL
) {
1378 Src
= Question
->BufferValue
;
1380 Src
= (UINT8
*) QuestionValue
;
1383 Status
= gRT
->SetVariable (
1384 Question
->VariableName
,
1386 Storage
->Attributes
,
1394 // Question Value is provided by Buffer Storage or NameValue Storage
1396 if (Question
->BufferValue
!= NULL
) {
1397 Src
= Question
->BufferValue
;
1399 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1402 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1403 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1404 if (IsBufferStorage
) {
1406 // Copy to storage edit buffer
1408 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1412 NewStringCpy (&Value
, (CHAR16
*) Src
);
1414 BufferLen
= (StorageWidth
* 2 + 1) * sizeof (CHAR16
);
1415 Value
= AllocateZeroPool (BufferLen
);
1416 ASSERT (Value
!= NULL
);
1417 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1420 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1421 gBS
->FreePool (Value
);
1426 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1427 // <ConfigHdr> + "&" + <VariableName> + "=" + "<HexCh>StorageWidth * 2"
1429 if (IsBufferStorage
) {
1430 Length
= StrLen (Question
->BlockName
) + 7;
1432 Length
= StrLen (Question
->VariableName
) + 2;
1434 if (!IsBufferStorage
&& IsString
) {
1435 Length
+= StrLen ((CHAR16
*) Src
);
1437 Length
+= (StorageWidth
* 2);
1439 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1440 ASSERT (ConfigResp
!= NULL
);
1442 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1443 if (IsBufferStorage
) {
1444 StrCat (ConfigResp
, Question
->BlockName
);
1445 StrCat (ConfigResp
, L
"&VALUE=");
1447 StrCat (ConfigResp
, L
"&");
1448 StrCat (ConfigResp
, Question
->VariableName
);
1449 StrCat (ConfigResp
, L
"=");
1452 Value
= ConfigResp
+ StrLen (ConfigResp
);
1453 if (!IsBufferStorage
&& IsString
) {
1454 StrCpy (Value
, (CHAR16
*) Src
);
1456 BufferLen
= (StorageWidth
* 2 + 1) * sizeof (CHAR16
);
1457 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1461 // Submit Question Value to Configuration Driver
1463 if (FormSet
->ConfigAccess
!= NULL
) {
1464 Status
= FormSet
->ConfigAccess
->RouteConfig (
1465 FormSet
->ConfigAccess
,
1469 if (EFI_ERROR (Status
)) {
1470 gBS
->FreePool (ConfigResp
);
1474 gBS
->FreePool (ConfigResp
);
1477 // Synchronize shadow Buffer
1479 SynchronizeStorage (Storage
);
1487 Perform inconsistent check for a Form.
1489 @param FormSet FormSet data structure.
1490 @param Form Form data structure.
1491 @param Question The Question to be validated.
1492 @param Type Validation type: InConsistent or NoSubmit
1494 @retval EFI_SUCCESS Form validation pass.
1495 @retval other Form validation failed.
1500 IN FORM_BROWSER_FORMSET
*FormSet
,
1501 IN FORM_BROWSER_FORM
*Form
,
1502 IN FORM_BROWSER_STATEMENT
*Question
,
1508 LIST_ENTRY
*ListHead
;
1511 FORM_EXPRESSION
*Expression
;
1513 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1514 ListHead
= &Question
->InconsistentListHead
;
1515 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1516 ListHead
= &Question
->NoSubmitListHead
;
1518 return EFI_UNSUPPORTED
;
1521 Link
= GetFirstNode (ListHead
);
1522 while (!IsNull (ListHead
, Link
)) {
1523 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1526 // Evaluate the expression
1528 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1529 if (EFI_ERROR (Status
)) {
1533 if (Expression
->Result
.Value
.b
) {
1535 // Condition meet, show up error message
1537 if (Expression
->Error
!= 0) {
1538 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1540 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1541 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1542 gBS
->FreePool (PopUp
);
1545 return EFI_NOT_READY
;
1548 Link
= GetNextNode (ListHead
, Link
);
1556 Perform NoSubmit check for a Form.
1558 @param FormSet FormSet data structure.
1559 @param Form Form data structure.
1561 @retval EFI_SUCCESS Form validation pass.
1562 @retval other Form validation failed.
1567 IN FORM_BROWSER_FORMSET
*FormSet
,
1568 IN FORM_BROWSER_FORM
*Form
1573 FORM_BROWSER_STATEMENT
*Question
;
1575 Link
= GetFirstNode (&Form
->StatementListHead
);
1576 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1577 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1579 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1580 if (EFI_ERROR (Status
)) {
1584 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1594 @param FormSet FormSet data structure.
1595 @param Form Form data structure.
1597 @retval EFI_SUCCESS The function completed successfully.
1602 IN FORM_BROWSER_FORMSET
*FormSet
,
1603 IN FORM_BROWSER_FORM
*Form
1608 EFI_STRING ConfigResp
;
1609 EFI_STRING Progress
;
1610 FORMSET_STORAGE
*Storage
;
1613 // Validate the Form by NoSubmit check
1615 Status
= NoSubmitCheck (FormSet
, Form
);
1616 if (EFI_ERROR (Status
)) {
1621 // Submit Buffer storage or Name/Value storage
1623 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1624 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1625 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1626 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1628 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1633 // Skip if there is no RequestElement
1635 if (Storage
->ElementCount
== 0) {
1640 // Prepare <ConfigResp>
1642 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1643 if (EFI_ERROR (Status
)) {
1648 // Send <ConfigResp> to Configuration Driver
1650 if (FormSet
->ConfigAccess
!= NULL
) {
1651 Status
= FormSet
->ConfigAccess
->RouteConfig (
1652 FormSet
->ConfigAccess
,
1656 if (EFI_ERROR (Status
)) {
1657 gBS
->FreePool (ConfigResp
);
1661 gBS
->FreePool (ConfigResp
);
1664 // Config success, update storage shadow Buffer
1666 SynchronizeStorage (Storage
);
1669 gNvUpdateRequired
= FALSE
;
1676 Reset Question to its default value.
1678 @param FormSet FormSet data structure.
1679 @param DefaultId The Class of the default.
1681 @retval EFI_SUCCESS Question is reset to default value.
1685 GetQuestionDefault (
1686 IN FORM_BROWSER_FORMSET
*FormSet
,
1687 IN FORM_BROWSER_FORM
*Form
,
1688 IN FORM_BROWSER_STATEMENT
*Question
,
1694 QUESTION_DEFAULT
*Default
;
1695 QUESTION_OPTION
*Option
;
1696 EFI_HII_VALUE
*HiiValue
;
1699 Status
= EFI_SUCCESS
;
1702 // Statement don't have storage, skip them
1704 if (Question
->QuestionId
== 0) {
1709 // There are three ways to specify default value for a Question:
1710 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1711 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1712 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1714 HiiValue
= &Question
->HiiValue
;
1717 // EFI_IFR_DEFAULT has highest priority
1719 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1720 Link
= GetFirstNode (&Question
->DefaultListHead
);
1721 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1722 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1724 if (Default
->DefaultId
== DefaultId
) {
1725 if (Default
->ValueExpression
!= NULL
) {
1727 // Default is provided by an Expression, evaluate it
1729 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1730 if (EFI_ERROR (Status
)) {
1734 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1737 // Default value is embedded in EFI_IFR_DEFAULT
1739 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1745 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1750 // EFI_ONE_OF_OPTION
1752 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1753 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1755 // OneOfOption could only provide Standard and Manufacturing default
1757 Link
= GetFirstNode (&Question
->OptionListHead
);
1758 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1759 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1761 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && (Option
->Flags
& EFI_IFR_OPTION_DEFAULT
)) ||
1762 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && (Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
))
1764 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1769 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1775 // EFI_IFR_CHECKBOX - lowest priority
1777 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1778 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1780 // Checkbox could only provide Standard and Manufacturing default
1782 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && (Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
)) ||
1783 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && (Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
))
1785 HiiValue
->Value
.b
= TRUE
;
1787 HiiValue
->Value
.b
= FALSE
;
1795 // For Questions without default
1797 switch (Question
->Operand
) {
1798 case EFI_IFR_NUMERIC_OP
:
1800 // Take minimal value as numeric's default value
1802 HiiValue
->Value
.u64
= Question
->Minimum
;
1805 case EFI_IFR_ONE_OF_OP
:
1807 // Take first oneof option as oneof's default value
1809 Link
= GetFirstNode (&Question
->OptionListHead
);
1810 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1811 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1812 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1816 case EFI_IFR_ORDERED_LIST_OP
:
1818 // Take option sequence in IFR as ordered list's default value
1821 Link
= GetFirstNode (&Question
->OptionListHead
);
1822 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1823 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1825 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1828 if (Index
>= Question
->MaxContainers
) {
1832 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1837 Status
= EFI_NOT_FOUND
;
1846 Reset Questions in a Form to their default value.
1848 @param FormSet FormSet data structure.
1849 @param Form The Form which to be reset.
1850 @param DefaultId The Class of the default.
1852 @retval EFI_SUCCESS The function completed successfully.
1856 ExtractFormDefault (
1857 IN FORM_BROWSER_FORMSET
*FormSet
,
1858 IN FORM_BROWSER_FORM
*Form
,
1864 FORM_BROWSER_STATEMENT
*Question
;
1866 Link
= GetFirstNode (&Form
->StatementListHead
);
1867 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1868 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1869 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1872 // Reset Question to its default value
1874 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1875 if (EFI_ERROR (Status
)) {
1880 // Synchronize Buffer storage's Edit buffer
1882 if ((Question
->Storage
!= NULL
) &&
1883 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1884 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1893 Initialize Question's Edit copy from Storage.
1895 @param FormSet FormSet data structure.
1896 @param Form Form data structure.
1898 @retval EFI_SUCCESS The function completed successfully.
1903 IN FORM_BROWSER_FORMSET
*FormSet
,
1904 IN FORM_BROWSER_FORM
*Form
1909 FORM_BROWSER_STATEMENT
*Question
;
1911 Link
= GetFirstNode (&Form
->StatementListHead
);
1912 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1913 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1916 // Initialize local copy of Value for each Question
1918 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1919 if (EFI_ERROR (Status
)) {
1923 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1931 Fill storage's edit copy with settings requested from Configuration Driver.
1933 @param FormSet FormSet data structure.
1934 @param Storage Buffer Storage.
1936 @retval EFI_SUCCESS The function completed successfully.
1941 IN FORM_BROWSER_FORMSET
*FormSet
,
1942 IN FORMSET_STORAGE
*Storage
1946 EFI_STRING Progress
;
1950 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1954 if (FormSet
->ConfigAccess
== NULL
) {
1955 return EFI_NOT_FOUND
;
1958 if (Storage
->ElementCount
== 0) {
1960 // Skip if there is no RequestElement
1966 // Request current settings from Configuration Driver
1968 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1969 FormSet
->ConfigAccess
,
1970 Storage
->ConfigRequest
,
1974 if (EFI_ERROR (Status
)) {
1979 // Convert Result from <ConfigAltResp> to <ConfigResp>
1981 StrPtr
= StrStr (Result
, L
"ALTCFG");
1982 if (StrPtr
!= NULL
) {
1986 Status
= ConfigRespToStorage (Storage
, Result
);
1987 gBS
->FreePool (Result
);
1993 Get current setting of Questions.
1995 @param FormSet FormSet data structure.
1997 @retval EFI_SUCCESS The function completed successfully.
2001 InitializeCurrentSetting (
2002 IN OUT FORM_BROWSER_FORMSET
*FormSet
2006 FORMSET_STORAGE
*Storage
;
2007 FORM_BROWSER_FORM
*Form
;
2011 // Extract default from IFR binary
2013 Link
= GetFirstNode (&FormSet
->FormListHead
);
2014 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2015 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2017 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2019 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2023 // Request current settings from Configuration Driver
2025 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2026 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2027 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2029 Status
= LoadStorage (FormSet
, Storage
);
2032 // Now Edit Buffer is filled with default values(lower priority) and current
2033 // settings(higher priority), sychronize it to shadow Buffer
2035 if (!EFI_ERROR (Status
)) {
2036 SynchronizeStorage (Storage
);
2039 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2047 Fetch the Ifr binary data of a FormSet.
2049 @param Handle PackageList Handle
2050 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2051 GUID), take the first FormSet found in package
2053 @param BinaryLength The length of the FormSet IFR binary.
2054 @param BinaryData The buffer designed to receive the FormSet.
2056 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2057 BufferLength was updated.
2058 @retval EFI_INVALID_PARAMETER The handle is unknown.
2059 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2060 be found with the requested FormId.
2065 IN EFI_HII_HANDLE Handle
,
2066 IN OUT EFI_GUID
*FormSetGuid
,
2067 OUT UINTN
*BinaryLength
,
2068 OUT UINT8
**BinaryData
2072 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2078 BOOLEAN ReturnDefault
;
2079 UINT32 PackageListLength
;
2080 EFI_HII_PACKAGE_HEADER PackageHeader
;
2084 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2087 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2089 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2090 ReturnDefault
= TRUE
;
2092 ReturnDefault
= FALSE
;
2096 // Get HII PackageList
2099 HiiPackageList
= NULL
;
2100 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2101 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2102 HiiPackageList
= AllocatePool (BufferSize
);
2103 ASSERT (HiiPackageList
!= NULL
);
2105 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2107 if (EFI_ERROR (Status
)) {
2112 // Get Form package from this HII package List
2114 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2116 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2118 while (Offset
< PackageListLength
) {
2119 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2120 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2122 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORM
) {
2124 // Search FormSet in this Form Package
2126 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2127 while (Offset2
< PackageHeader
.Length
) {
2128 OpCodeData
= Package
+ Offset2
;
2130 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2132 // Check whether return default FormSet
2134 if (ReturnDefault
) {
2139 // FormSet GUID is specified, check it
2141 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2146 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2149 if (Offset2
< PackageHeader
.Length
) {
2151 // Target formset found
2157 Offset
+= PackageHeader
.Length
;
2160 if (Offset
>= PackageListLength
) {
2162 // Form package not found in this Package List
2164 gBS
->FreePool (HiiPackageList
);
2165 return EFI_NOT_FOUND
;
2168 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2170 // Return the default FormSet GUID
2172 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2176 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2177 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2178 // of the Form Package.
2180 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2181 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2183 gBS
->FreePool (HiiPackageList
);
2185 if (*BinaryData
== NULL
) {
2186 return EFI_OUT_OF_RESOURCES
;
2194 Initialize the internal data structure of a FormSet.
2196 @param Handle PackageList Handle
2197 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2198 GUID), take the first FormSet found in package
2200 @param FormSet FormSet data structure.
2202 @retval EFI_SUCCESS The function completed successfully.
2203 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2208 IN EFI_HII_HANDLE Handle
,
2209 IN OUT EFI_GUID
*FormSetGuid
,
2210 OUT FORM_BROWSER_FORMSET
*FormSet
2214 EFI_HANDLE DriverHandle
;
2217 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2218 if (EFI_ERROR (Status
)) {
2222 FormSet
->HiiHandle
= Handle
;
2223 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2226 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2228 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2229 if (EFI_ERROR (Status
)) {
2232 FormSet
->DriverHandle
= DriverHandle
;
2233 Status
= gBS
->HandleProtocol (
2235 &gEfiHiiConfigAccessProtocolGuid
,
2236 (VOID
**) &FormSet
->ConfigAccess
2238 if (EFI_ERROR (Status
)) {
2240 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2241 // list, then there will be no configuration action required
2243 FormSet
->ConfigAccess
= NULL
;
2247 // Parse the IFR binary OpCodes
2249 Status
= ParseOpCodes (FormSet
);
2250 if (EFI_ERROR (Status
)) {
2254 gClassOfVfr
= FormSet
->SubClass
;
2255 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2256 FrontPageHandle
= FormSet
->HiiHandle
;
2260 // Match GUID to find out the function key setting. If match fail, use the default setting.
2262 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2263 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2265 // Update the function key setting.
2267 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2269 // Function key prompt can not be displayed if the function key has been disabled.
2271 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2272 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2275 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2276 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2279 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2280 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2283 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2284 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);