2 Copyright (c) 2007 - 2008, 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
)) {
1177 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1179 Length
= StorageWidth
+ sizeof (CHAR16
);
1180 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1182 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1185 gBS
->FreePool (Value
);
1189 // Request current settings from Configuration Driver
1191 if (FormSet
->ConfigAccess
== NULL
) {
1192 return EFI_NOT_FOUND
;
1196 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1197 // <ConfigHdr> + "&" + <VariableName>
1199 if (IsBufferStorage
) {
1200 Length
= StrLen (Storage
->ConfigHdr
);
1201 Length
+= StrLen (Question
->BlockName
);
1203 Length
= StrLen (Storage
->ConfigHdr
);
1204 Length
+= StrLen (Question
->VariableName
) + 1;
1206 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1207 ASSERT (ConfigRequest
!= NULL
);
1209 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1210 if (IsBufferStorage
) {
1211 StrCat (ConfigRequest
, Question
->BlockName
);
1213 StrCat (ConfigRequest
, L
"&");
1214 StrCat (ConfigRequest
, Question
->VariableName
);
1217 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1218 FormSet
->ConfigAccess
,
1223 if (EFI_ERROR (Status
)) {
1228 // Skip <ConfigRequest>
1230 Value
= Result
+ Length
;
1231 if (IsBufferStorage
) {
1237 if (*Value
!= '=') {
1238 gBS
->FreePool (Result
);
1239 return EFI_NOT_FOUND
;
1242 // Skip '=', point to value
1245 if (!IsBufferStorage
&& IsString
) {
1247 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1249 Length
= StorageWidth
+ sizeof (CHAR16
);
1250 Status
= ConfigStringToUnicode ((CHAR16
*) Dst
, &Length
, Value
);
1252 Status
= HexStringToBuf (Dst
, &StorageWidth
, Value
, NULL
);
1253 if (EFI_ERROR (Status
)) {
1254 gBS
->FreePool (Result
);
1260 // Synchronize Edit Buffer
1262 if (IsBufferStorage
) {
1263 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1265 SetValueByName (Storage
, Question
->VariableName
, Value
);
1267 gBS
->FreePool (Result
);
1275 Save Question Value to edit copy(cached) or Storage(uncached).
1277 @param FormSet FormSet data structure.
1278 @param Form Form data structure.
1279 @param Question Pointer to the Question.
1280 @param Cached TRUE: set to Edit copy FALSE: set to original
1283 @retval EFI_SUCCESS The function completed successfully.
1288 IN FORM_BROWSER_FORMSET
*FormSet
,
1289 IN FORM_BROWSER_FORM
*Form
,
1290 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1301 FORMSET_STORAGE
*Storage
;
1302 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1307 BOOLEAN IsBufferStorage
;
1310 Status
= EFI_SUCCESS
;
1313 // Statement don't have storage, skip them
1315 if (Question
->QuestionId
== 0) {
1320 // If Question value is provided by an Expression, then it is read only
1322 if (Question
->ValueExpression
!= NULL
) {
1327 // Question value is provided by RTC
1329 Storage
= Question
->Storage
;
1330 QuestionValue
= &Question
->HiiValue
.Value
;
1331 if (Storage
== NULL
) {
1333 // It's a Question without storage, or RTC date/time
1335 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1337 // Date and time define the same Flags bit
1339 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1340 case QF_DATE_STORAGE_TIME
:
1341 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1344 case QF_DATE_STORAGE_WAKEUP
:
1345 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1348 case QF_DATE_STORAGE_NORMAL
:
1351 // For date/time without storage
1356 if (EFI_ERROR (Status
)) {
1360 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1361 EfiTime
.Year
= QuestionValue
->date
.Year
;
1362 EfiTime
.Month
= QuestionValue
->date
.Month
;
1363 EfiTime
.Day
= QuestionValue
->date
.Day
;
1365 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1366 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1367 EfiTime
.Second
= QuestionValue
->time
.Second
;
1370 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1371 Status
= gRT
->SetTime (&EfiTime
);
1373 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1381 // Question value is provided by EFI variable
1383 StorageWidth
= Question
->StorageWidth
;
1384 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1385 if (Question
->BufferValue
!= NULL
) {
1386 Src
= Question
->BufferValue
;
1388 Src
= (UINT8
*) QuestionValue
;
1391 Status
= gRT
->SetVariable (
1392 Question
->VariableName
,
1394 Storage
->Attributes
,
1402 // Question Value is provided by Buffer Storage or NameValue Storage
1404 if (Question
->BufferValue
!= NULL
) {
1405 Src
= Question
->BufferValue
;
1407 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1410 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1411 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1412 if (IsBufferStorage
) {
1414 // Copy to storage edit buffer
1416 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1420 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1423 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1424 Value
= AllocateZeroPool (BufferLen
);
1425 ASSERT (Value
!= NULL
);
1426 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1427 ASSERT_EFI_ERROR (Status
);
1429 BufferLen
= StorageWidth
* 2 + 1;
1430 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1431 ASSERT (Value
!= NULL
);
1432 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1436 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
);
1437 gBS
->FreePool (Value
);
1442 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1443 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1445 if (IsBufferStorage
) {
1446 Length
= StrLen (Question
->BlockName
) + 7;
1448 Length
= StrLen (Question
->VariableName
) + 2;
1450 if (!IsBufferStorage
&& IsString
) {
1451 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1453 Length
+= (StorageWidth
* 2);
1455 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1456 ASSERT (ConfigResp
!= NULL
);
1458 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1459 if (IsBufferStorage
) {
1460 StrCat (ConfigResp
, Question
->BlockName
);
1461 StrCat (ConfigResp
, L
"&VALUE=");
1463 StrCat (ConfigResp
, L
"&");
1464 StrCat (ConfigResp
, Question
->VariableName
);
1465 StrCat (ConfigResp
, L
"=");
1468 Value
= ConfigResp
+ StrLen (ConfigResp
);
1469 if (!IsBufferStorage
&& IsString
) {
1471 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1473 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1474 Status
= UnicodeToConfigString (Value
, &BufferLen
, (CHAR16
*) Src
);
1475 ASSERT_EFI_ERROR (Status
);
1477 BufferLen
= StorageWidth
* 2 + 1;
1478 BufToHexString (Value
, &BufferLen
, Src
, StorageWidth
);
1483 // Submit Question Value to Configuration Driver
1485 if (FormSet
->ConfigAccess
!= NULL
) {
1486 Status
= FormSet
->ConfigAccess
->RouteConfig (
1487 FormSet
->ConfigAccess
,
1491 if (EFI_ERROR (Status
)) {
1492 gBS
->FreePool (ConfigResp
);
1496 gBS
->FreePool (ConfigResp
);
1499 // Synchronize shadow Buffer
1501 SynchronizeStorage (Storage
);
1509 Perform inconsistent check for a Form.
1511 @param FormSet FormSet data structure.
1512 @param Form Form data structure.
1513 @param Question The Question to be validated.
1514 @param Type Validation type: InConsistent or NoSubmit
1516 @retval EFI_SUCCESS Form validation pass.
1517 @retval other Form validation failed.
1522 IN FORM_BROWSER_FORMSET
*FormSet
,
1523 IN FORM_BROWSER_FORM
*Form
,
1524 IN FORM_BROWSER_STATEMENT
*Question
,
1530 LIST_ENTRY
*ListHead
;
1533 FORM_EXPRESSION
*Expression
;
1535 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1536 ListHead
= &Question
->InconsistentListHead
;
1537 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1538 ListHead
= &Question
->NoSubmitListHead
;
1540 return EFI_UNSUPPORTED
;
1543 Link
= GetFirstNode (ListHead
);
1544 while (!IsNull (ListHead
, Link
)) {
1545 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1548 // Evaluate the expression
1550 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1551 if (EFI_ERROR (Status
)) {
1555 if (Expression
->Result
.Value
.b
) {
1557 // Condition meet, show up error message
1559 if (Expression
->Error
!= 0) {
1560 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1562 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1563 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1564 gBS
->FreePool (PopUp
);
1567 return EFI_NOT_READY
;
1570 Link
= GetNextNode (ListHead
, Link
);
1578 Perform NoSubmit check for a Form.
1580 @param FormSet FormSet data structure.
1581 @param Form Form data structure.
1583 @retval EFI_SUCCESS Form validation pass.
1584 @retval other Form validation failed.
1589 IN FORM_BROWSER_FORMSET
*FormSet
,
1590 IN FORM_BROWSER_FORM
*Form
1595 FORM_BROWSER_STATEMENT
*Question
;
1597 Link
= GetFirstNode (&Form
->StatementListHead
);
1598 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1599 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1601 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1602 if (EFI_ERROR (Status
)) {
1606 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1616 @param FormSet FormSet data structure.
1617 @param Form Form data structure.
1619 @retval EFI_SUCCESS The function completed successfully.
1624 IN FORM_BROWSER_FORMSET
*FormSet
,
1625 IN FORM_BROWSER_FORM
*Form
1630 EFI_STRING ConfigResp
;
1631 EFI_STRING Progress
;
1632 FORMSET_STORAGE
*Storage
;
1635 // Validate the Form by NoSubmit check
1637 Status
= NoSubmitCheck (FormSet
, Form
);
1638 if (EFI_ERROR (Status
)) {
1643 // Submit Buffer storage or Name/Value storage
1645 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1646 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1647 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1648 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1650 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1655 // Skip if there is no RequestElement
1657 if (Storage
->ElementCount
== 0) {
1662 // Prepare <ConfigResp>
1664 Status
= StorageToConfigResp (Storage
, &ConfigResp
);
1665 if (EFI_ERROR (Status
)) {
1670 // Send <ConfigResp> to Configuration Driver
1672 if (FormSet
->ConfigAccess
!= NULL
) {
1673 Status
= FormSet
->ConfigAccess
->RouteConfig (
1674 FormSet
->ConfigAccess
,
1678 if (EFI_ERROR (Status
)) {
1679 gBS
->FreePool (ConfigResp
);
1683 gBS
->FreePool (ConfigResp
);
1686 // Config success, update storage shadow Buffer
1688 SynchronizeStorage (Storage
);
1691 gNvUpdateRequired
= FALSE
;
1698 Reset Question to its default value.
1700 @param FormSet FormSet data structure.
1701 @param DefaultId The Class of the default.
1703 @retval EFI_SUCCESS Question is reset to default value.
1707 GetQuestionDefault (
1708 IN FORM_BROWSER_FORMSET
*FormSet
,
1709 IN FORM_BROWSER_FORM
*Form
,
1710 IN FORM_BROWSER_STATEMENT
*Question
,
1716 QUESTION_DEFAULT
*Default
;
1717 QUESTION_OPTION
*Option
;
1718 EFI_HII_VALUE
*HiiValue
;
1721 Status
= EFI_SUCCESS
;
1724 // Statement don't have storage, skip them
1726 if (Question
->QuestionId
== 0) {
1731 // There are three ways to specify default value for a Question:
1732 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1733 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1734 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1736 HiiValue
= &Question
->HiiValue
;
1739 // EFI_IFR_DEFAULT has highest priority
1741 if (!IsListEmpty (&Question
->DefaultListHead
)) {
1742 Link
= GetFirstNode (&Question
->DefaultListHead
);
1743 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
1744 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
1746 if (Default
->DefaultId
== DefaultId
) {
1747 if (Default
->ValueExpression
!= NULL
) {
1749 // Default is provided by an Expression, evaluate it
1751 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
1752 if (EFI_ERROR (Status
)) {
1756 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
1759 // Default value is embedded in EFI_IFR_DEFAULT
1761 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
1767 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
1772 // EFI_ONE_OF_OPTION
1774 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
1775 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1777 // OneOfOption could only provide Standard and Manufacturing default
1779 Link
= GetFirstNode (&Question
->OptionListHead
);
1780 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1781 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1783 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && (Option
->Flags
& EFI_IFR_OPTION_DEFAULT
)) ||
1784 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && (Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
))
1786 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1791 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1797 // EFI_IFR_CHECKBOX - lowest priority
1799 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
1800 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
1802 // Checkbox could only provide Standard and Manufacturing default
1804 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && (Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
)) ||
1805 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && (Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
))
1807 HiiValue
->Value
.b
= TRUE
;
1809 HiiValue
->Value
.b
= FALSE
;
1817 // For Questions without default
1819 switch (Question
->Operand
) {
1820 case EFI_IFR_NUMERIC_OP
:
1822 // Take minimal value as numeric's default value
1824 HiiValue
->Value
.u64
= Question
->Minimum
;
1827 case EFI_IFR_ONE_OF_OP
:
1829 // Take first oneof option as oneof's default value
1831 Link
= GetFirstNode (&Question
->OptionListHead
);
1832 if (!IsNull (&Question
->OptionListHead
, Link
)) {
1833 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1834 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
1838 case EFI_IFR_ORDERED_LIST_OP
:
1840 // Take option sequence in IFR as ordered list's default value
1843 Link
= GetFirstNode (&Question
->OptionListHead
);
1844 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1845 Option
= QUESTION_OPTION_FROM_LINK (Link
);
1847 Question
->BufferValue
[Index
] = Option
->Value
.Value
.u8
;
1850 if (Index
>= Question
->MaxContainers
) {
1854 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1859 Status
= EFI_NOT_FOUND
;
1868 Reset Questions in a Form to their default value.
1870 @param FormSet FormSet data structure.
1871 @param Form The Form which to be reset.
1872 @param DefaultId The Class of the default.
1874 @retval EFI_SUCCESS The function completed successfully.
1878 ExtractFormDefault (
1879 IN FORM_BROWSER_FORMSET
*FormSet
,
1880 IN FORM_BROWSER_FORM
*Form
,
1886 FORM_BROWSER_STATEMENT
*Question
;
1888 Link
= GetFirstNode (&Form
->StatementListHead
);
1889 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1890 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1891 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1894 // Reset Question to its default value
1896 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
1897 if (EFI_ERROR (Status
)) {
1902 // Synchronize Buffer storage's Edit buffer
1904 if ((Question
->Storage
!= NULL
) &&
1905 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1906 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1915 Initialize Question's Edit copy from Storage.
1917 @param FormSet FormSet data structure.
1918 @param Form Form data structure.
1920 @retval EFI_SUCCESS The function completed successfully.
1925 IN FORM_BROWSER_FORMSET
*FormSet
,
1926 IN FORM_BROWSER_FORM
*Form
1931 FORM_BROWSER_STATEMENT
*Question
;
1933 Link
= GetFirstNode (&Form
->StatementListHead
);
1934 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1935 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1938 // Initialize local copy of Value for each Question
1940 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
1941 if (EFI_ERROR (Status
)) {
1945 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1953 Fill storage's edit copy with settings requested from Configuration Driver.
1955 @param FormSet FormSet data structure.
1956 @param Storage Buffer Storage.
1958 @retval EFI_SUCCESS The function completed successfully.
1963 IN FORM_BROWSER_FORMSET
*FormSet
,
1964 IN FORMSET_STORAGE
*Storage
1968 EFI_STRING Progress
;
1972 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1976 if (FormSet
->ConfigAccess
== NULL
) {
1977 return EFI_NOT_FOUND
;
1980 if (Storage
->ElementCount
== 0) {
1982 // Skip if there is no RequestElement
1988 // Request current settings from Configuration Driver
1990 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1991 FormSet
->ConfigAccess
,
1992 Storage
->ConfigRequest
,
1996 if (EFI_ERROR (Status
)) {
2001 // Convert Result from <ConfigAltResp> to <ConfigResp>
2003 StrPtr
= StrStr (Result
, L
"ALTCFG");
2004 if (StrPtr
!= NULL
) {
2008 Status
= ConfigRespToStorage (Storage
, Result
);
2009 gBS
->FreePool (Result
);
2015 Get current setting of Questions.
2017 @param FormSet FormSet data structure.
2019 @retval EFI_SUCCESS The function completed successfully.
2023 InitializeCurrentSetting (
2024 IN OUT FORM_BROWSER_FORMSET
*FormSet
2028 FORMSET_STORAGE
*Storage
;
2029 FORM_BROWSER_FORM
*Form
;
2033 // Extract default from IFR binary
2035 Link
= GetFirstNode (&FormSet
->FormListHead
);
2036 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2037 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2039 Status
= ExtractFormDefault (FormSet
, Form
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2041 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2045 // Request current settings from Configuration Driver
2047 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2048 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2049 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2051 Status
= LoadStorage (FormSet
, Storage
);
2054 // Now Edit Buffer is filled with default values(lower priority) and current
2055 // settings(higher priority), sychronize it to shadow Buffer
2057 if (!EFI_ERROR (Status
)) {
2058 SynchronizeStorage (Storage
);
2061 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2069 Fetch the Ifr binary data of a FormSet.
2071 @param Handle PackageList Handle
2072 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2073 GUID), take the first FormSet found in package
2075 @param BinaryLength The length of the FormSet IFR binary.
2076 @param BinaryData The buffer designed to receive the FormSet.
2078 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2079 BufferLength was updated.
2080 @retval EFI_INVALID_PARAMETER The handle is unknown.
2081 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2082 be found with the requested FormId.
2087 IN EFI_HII_HANDLE Handle
,
2088 IN OUT EFI_GUID
*FormSetGuid
,
2089 OUT UINTN
*BinaryLength
,
2090 OUT UINT8
**BinaryData
2094 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2100 BOOLEAN ReturnDefault
;
2101 UINT32 PackageListLength
;
2102 EFI_HII_PACKAGE_HEADER PackageHeader
;
2106 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));;
2109 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2111 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2112 ReturnDefault
= TRUE
;
2114 ReturnDefault
= FALSE
;
2118 // Get HII PackageList
2121 HiiPackageList
= NULL
;
2122 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2123 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2124 HiiPackageList
= AllocatePool (BufferSize
);
2125 ASSERT (HiiPackageList
!= NULL
);
2127 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
2129 if (EFI_ERROR (Status
)) {
2134 // Get Form package from this HII package List
2136 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
2138 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
2140 while (Offset
< PackageListLength
) {
2141 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
2142 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
2144 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORM
) {
2146 // Search FormSet in this Form Package
2148 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
2149 while (Offset2
< PackageHeader
.Length
) {
2150 OpCodeData
= Package
+ Offset2
;
2152 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
2154 // Check whether return default FormSet
2156 if (ReturnDefault
) {
2161 // FormSet GUID is specified, check it
2163 if (CompareGuid (FormSetGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
2168 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
2171 if (Offset2
< PackageHeader
.Length
) {
2173 // Target formset found
2179 Offset
+= PackageHeader
.Length
;
2182 if (Offset
>= PackageListLength
) {
2184 // Form package not found in this Package List
2186 gBS
->FreePool (HiiPackageList
);
2187 return EFI_NOT_FOUND
;
2190 if (ReturnDefault
&& FormSetGuid
!= NULL
) {
2192 // Return the default FormSet GUID
2194 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
2198 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2199 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2200 // of the Form Package.
2202 *BinaryLength
= PackageHeader
.Length
- Offset2
;
2203 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
2205 gBS
->FreePool (HiiPackageList
);
2207 if (*BinaryData
== NULL
) {
2208 return EFI_OUT_OF_RESOURCES
;
2216 Initialize the internal data structure of a FormSet.
2218 @param Handle PackageList Handle
2219 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2220 GUID), take the first FormSet found in package
2222 @param FormSet FormSet data structure.
2224 @retval EFI_SUCCESS The function completed successfully.
2225 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2230 IN EFI_HII_HANDLE Handle
,
2231 IN OUT EFI_GUID
*FormSetGuid
,
2232 OUT FORM_BROWSER_FORMSET
*FormSet
2236 EFI_HANDLE DriverHandle
;
2239 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
2240 if (EFI_ERROR (Status
)) {
2244 FormSet
->HiiHandle
= Handle
;
2245 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
2248 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2250 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
2251 if (EFI_ERROR (Status
)) {
2254 FormSet
->DriverHandle
= DriverHandle
;
2255 Status
= gBS
->HandleProtocol (
2257 &gEfiHiiConfigAccessProtocolGuid
,
2258 (VOID
**) &FormSet
->ConfigAccess
2260 if (EFI_ERROR (Status
)) {
2262 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2263 // list, then there will be no configuration action required
2265 FormSet
->ConfigAccess
= NULL
;
2269 // Parse the IFR binary OpCodes
2271 Status
= ParseOpCodes (FormSet
);
2272 if (EFI_ERROR (Status
)) {
2276 gClassOfVfr
= FormSet
->SubClass
;
2277 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2278 FrontPageHandle
= FormSet
->HiiHandle
;
2282 // Match GUID to find out the function key setting. If match fail, use the default setting.
2284 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
2285 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
2287 // Update the function key setting.
2289 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
2291 // Function key prompt can not be displayed if the function key has been disabled.
2293 if ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
) {
2294 gFunctionOneString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2297 if ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
) {
2298 gFunctionTwoString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2301 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
2302 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
2305 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
2306 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);