2 Entry and initialization module for the browser.
4 Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
5 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.
17 SETUP_DRIVER_PRIVATE_DATA mPrivateData
= {
18 SETUP_DRIVER_SIGNATURE
,
26 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
27 EFI_HII_STRING_PROTOCOL
*mHiiString
;
28 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
30 UINTN gBrowserContextCount
= 0;
31 LIST_ENTRY gBrowserContextList
= INITIALIZE_LIST_HEAD_VARIABLE (gBrowserContextList
);
33 BANNER_DATA
*gBannerData
;
34 EFI_HII_HANDLE gFrontPageHandle
;
36 UINTN gFunctionKeySetting
;
37 BOOLEAN gResetRequired
;
38 EFI_HII_HANDLE gHiiHandle
;
40 EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
43 // Browser Global Strings
45 CHAR16
*gFunctionNineString
;
46 CHAR16
*gFunctionTenString
;
48 CHAR16
*gEnterCommitString
;
49 CHAR16
*gEnterEscapeString
;
50 CHAR16
*gEscapeString
;
52 CHAR16
*gMoveHighlight
;
53 CHAR16
*gMakeSelection
;
54 CHAR16
*gDecNumericInput
;
55 CHAR16
*gHexNumericInput
;
56 CHAR16
*gToggleCheckBox
;
57 CHAR16
*gPromptForData
;
58 CHAR16
*gPromptForPassword
;
59 CHAR16
*gPromptForNewPassword
;
60 CHAR16
*gConfirmPassword
;
61 CHAR16
*gConfirmError
;
62 CHAR16
*gPassowordInvalid
;
71 CHAR16
*gAdjustNumber
;
73 CHAR16
*gOptionMismatch
;
74 CHAR16
*gFormSuppress
;
76 CHAR16
*mUnknownString
= L
"!";
78 CHAR16 gPromptBlockWidth
;
79 CHAR16 gOptionBlockWidth
;
80 CHAR16 gHelpBlockWidth
;
82 EFI_GUID gZeroGuid
= {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
83 EFI_GUID gSetupBrowserGuid
= {
84 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
87 FORM_BROWSER_FORMSET
*gOldFormSet
;
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 @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
194 @param ActionRequest Points to the action recommended by the form.
196 @retval EFI_SUCCESS The function completed successfully.
197 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
198 @retval EFI_NOT_FOUND No valid forms could be found to display.
204 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
205 IN EFI_HII_HANDLE
*Handles
,
206 IN UINTN HandleCount
,
207 IN EFI_GUID
*FormSetGuid
, OPTIONAL
208 IN UINT16 FormId
, OPTIONAL
209 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
210 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
214 UI_MENU_SELECTION
*Selection
;
216 FORM_BROWSER_FORMSET
*FormSet
;
219 // Save globals used by SendForm()
221 SaveBrowserContext ();
223 Status
= EFI_SUCCESS
;
224 ZeroMem (&gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
227 // Seed the dimensions in the global
229 gST
->ConOut
->QueryMode (
231 gST
->ConOut
->Mode
->Mode
,
232 &gScreenDimensions
.RightColumn
,
233 &gScreenDimensions
.BottomRow
236 if (ScreenDimensions
!= NULL
) {
238 // Check local dimension vs. global dimension.
240 if ((gScreenDimensions
.RightColumn
< ScreenDimensions
->RightColumn
) ||
241 (gScreenDimensions
.BottomRow
< ScreenDimensions
->BottomRow
)
243 Status
= EFI_INVALID_PARAMETER
;
247 // Local dimension validation.
249 if ((ScreenDimensions
->RightColumn
> ScreenDimensions
->LeftColumn
) &&
250 (ScreenDimensions
->BottomRow
> ScreenDimensions
->TopRow
) &&
251 ((ScreenDimensions
->RightColumn
- ScreenDimensions
->LeftColumn
) > 2) &&
253 (ScreenDimensions
->BottomRow
- ScreenDimensions
->TopRow
) > STATUS_BAR_HEIGHT
+
254 SCROLL_ARROW_HEIGHT
*
256 FRONT_PAGE_HEADER_HEIGHT
+
261 CopyMem (&gScreenDimensions
, (VOID
*) ScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
263 Status
= EFI_INVALID_PARAMETER
;
269 gOptionBlockWidth
= (CHAR16
) ((gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
) / 3);
270 gPromptBlockWidth
= (CHAR16
) (gOptionBlockWidth
+ LEFT_SKIPPED_COLUMNS
);
271 gHelpBlockWidth
= (CHAR16
) (gOptionBlockWidth
- LEFT_SKIPPED_COLUMNS
);
274 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
276 InitializeBrowserStrings ();
278 gFunctionKeySetting
= DEFAULT_FUNCTION_KEY_SETTING
;
281 // Ensure we are in Text mode
283 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
285 for (Index
= 0; Index
< HandleCount
; Index
++) {
286 Selection
= AllocateZeroPool (sizeof (UI_MENU_SELECTION
));
287 ASSERT (Selection
!= NULL
);
289 Selection
->Handle
= Handles
[Index
];
290 if (FormSetGuid
!= NULL
) {
291 CopyMem (&Selection
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
292 Selection
->FormId
= FormId
;
298 FormSet
= AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET
));
299 ASSERT (FormSet
!= NULL
);
302 // Initialize internal data structures of FormSet
304 Status
= InitializeFormSet (Selection
->Handle
, &Selection
->FormSetGuid
, FormSet
);
305 if (EFI_ERROR (Status
) || IsListEmpty (&FormSet
->FormListHead
)) {
306 DestroyFormSet (FormSet
);
309 Selection
->FormSet
= FormSet
;
312 // Display this formset
314 gCurrentSelection
= Selection
;
316 Status
= SetupBrowser (Selection
);
318 gCurrentSelection
= NULL
;
320 if (EFI_ERROR (Status
)) {
324 } while (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
);
326 if (gOldFormSet
!= NULL
) {
327 DestroyFormSet (gOldFormSet
);
331 FreePool (Selection
);
334 if (ActionRequest
!= NULL
) {
335 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
336 if (gResetRequired
) {
337 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_RESET
;
341 FreeBrowserStrings ();
343 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
344 gST
->ConOut
->ClearScreen (gST
->ConOut
);
348 // Restore globals used by SendForm()
350 RestoreBrowserContext ();
357 This function is called by a callback handler to retrieve uncommitted state
358 data from the browser.
360 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
362 @param ResultsDataSize A pointer to the size of the buffer associated
364 @param ResultsData A string returned from an IFR browser or
365 equivalent. The results string will have no
366 routing information in them.
367 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
368 (if RetrieveData = TRUE) data from the uncommitted
369 browser state information or set (if RetrieveData
370 = FALSE) data in the uncommitted browser state
372 @param VariableGuid An optional field to indicate the target variable
374 @param VariableName An optional field to indicate the target
375 human-readable variable name.
377 @retval EFI_SUCCESS The results have been distributed or are awaiting
379 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
380 contain the results data.
386 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
387 IN OUT UINTN
*ResultsDataSize
,
388 IN OUT EFI_STRING ResultsData
,
389 IN BOOLEAN RetrieveData
,
390 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
391 IN CONST CHAR16
*VariableName OPTIONAL
396 FORMSET_STORAGE
*Storage
;
397 FORM_BROWSER_FORMSET
*FormSet
;
404 if (ResultsDataSize
== NULL
|| ResultsData
== NULL
) {
405 return EFI_INVALID_PARAMETER
;
408 if (gCurrentSelection
== NULL
) {
409 return EFI_NOT_READY
;
414 FormSet
= gCurrentSelection
->FormSet
;
417 // Find target storage
419 Link
= GetFirstNode (&FormSet
->StorageListHead
);
420 if (IsNull (&FormSet
->StorageListHead
, Link
)) {
421 return EFI_UNSUPPORTED
;
424 if (VariableGuid
!= NULL
) {
426 // Try to find target storage
429 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
430 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
431 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
433 if (CompareGuid (&Storage
->Guid
, (EFI_GUID
*) VariableGuid
)) {
434 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
436 // Buffer storage require both GUID and Name
438 if (VariableName
== NULL
) {
439 return EFI_NOT_FOUND
;
442 if (StrCmp (Storage
->Name
, (CHAR16
*) VariableName
) != 0) {
452 return EFI_NOT_FOUND
;
456 // GUID/Name is not specified, take the first storage in FormSet
458 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
463 // Skip if there is no RequestElement
465 if (Storage
->ElementCount
== 0) {
470 // Generate <ConfigResp>
472 Status
= StorageToConfigResp (Storage
, &ConfigResp
, FALSE
);
473 if (EFI_ERROR (Status
)) {
478 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
480 StrPtr
= ConfigResp
+ StrLen (Storage
->ConfigHdr
) + 1;
482 BufferSize
= StrSize (StrPtr
);
483 if (*ResultsDataSize
< BufferSize
) {
484 *ResultsDataSize
= BufferSize
;
486 FreePool (ConfigResp
);
487 return EFI_BUFFER_TOO_SMALL
;
490 *ResultsDataSize
= BufferSize
;
491 CopyMem (ResultsData
, StrPtr
, BufferSize
);
493 FreePool (ConfigResp
);
496 // Prepare <ConfigResp>
498 TmpSize
= StrLen (ResultsData
);
499 BufferSize
= (TmpSize
+ StrLen (Storage
->ConfigHdr
) + 2) * sizeof (CHAR16
);
500 ConfigResp
= AllocateZeroPool (BufferSize
);
501 ASSERT (ConfigResp
!= NULL
);
503 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
504 StrCat (ConfigResp
, L
"&");
505 StrCat (ConfigResp
, ResultsData
);
508 // Update Browser uncommited data
510 Status
= ConfigRespToStorage (Storage
, ConfigResp
);
511 if (EFI_ERROR (Status
)) {
521 Initialize Setup Browser driver.
523 @param ImageHandle The image handle.
524 @param SystemTable The system table.
526 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
527 @return Other value if failed to initialize the Setup Browser module.
533 IN EFI_HANDLE ImageHandle
,
534 IN EFI_SYSTEM_TABLE
*SystemTable
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 gHiiHandle
= HiiAddPackages (
572 ASSERT (gHiiHandle
!= NULL
);
575 // Initialize Driver private data
577 gBannerData
= AllocateZeroPool (sizeof (BANNER_DATA
));
578 ASSERT (gBannerData
!= NULL
);
581 // Install FormBrowser2 protocol
583 mPrivateData
.Handle
= NULL
;
584 Status
= gBS
->InstallProtocolInterface (
585 &mPrivateData
.Handle
,
586 &gEfiFormBrowser2ProtocolGuid
,
587 EFI_NATIVE_INTERFACE
,
588 &mPrivateData
.FormBrowser2
590 ASSERT_EFI_ERROR (Status
);
597 Create a new string in HII Package List.
599 @param String The String to be added
600 @param HiiHandle The package list in the HII database to insert the
603 @return The output string.
609 IN EFI_HII_HANDLE HiiHandle
612 EFI_STRING_ID StringId
;
614 StringId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
615 ASSERT (StringId
!= 0);
622 Delete a string from HII Package List.
624 @param StringId Id of the string in HII database.
625 @param HiiHandle The HII package list handle.
627 @retval EFI_SUCCESS The string was deleted successfully.
632 IN EFI_STRING_ID StringId
,
633 IN EFI_HII_HANDLE HiiHandle
638 NullChar
= CHAR_NULL
;
639 HiiSetString (HiiHandle
, StringId
, &NullChar
, NULL
);
645 Get the string based on the StringId and HII Package List Handle.
647 @param Token The String's ID.
648 @param HiiHandle The package list in the HII database to search for
649 the specified string.
651 @return The output string.
656 IN EFI_STRING_ID Token
,
657 IN EFI_HII_HANDLE HiiHandle
662 if (HiiHandle
== NULL
) {
666 String
= HiiGetString (HiiHandle
, Token
, NULL
);
667 if (String
== NULL
) {
668 String
= AllocateCopyPool (sizeof (mUnknownString
), mUnknownString
);
669 ASSERT (String
!= NULL
);
671 return (CHAR16
*) String
;
676 Allocate new memory and then copy the Unicode string Source to Destination.
678 @param Dest Location to copy string
679 @param Src String to copy
684 IN OUT CHAR16
**Dest
,
691 *Dest
= AllocateCopyPool (StrSize (Src
), Src
);
692 ASSERT (*Dest
!= NULL
);
697 Allocate new memory and concatinate Source on the end of Destination.
699 @param Dest String to added to the end of.
700 @param Src String to concatinate.
705 IN OUT CHAR16
**Dest
,
713 NewStringCpy (Dest
, Src
);
717 TmpSize
= StrSize (*Dest
);
718 NewString
= AllocateZeroPool (TmpSize
+ StrSize (Src
) - 1);
719 ASSERT (NewString
!= NULL
);
721 StrCpy (NewString
, *Dest
);
722 StrCat (NewString
, Src
);
730 Synchronize Storage's Edit copy to Shadow copy.
732 @param Storage The Storage to be synchronized.
737 IN FORMSET_STORAGE
*Storage
741 NAME_VALUE_NODE
*Node
;
743 switch (Storage
->Type
) {
744 case EFI_HII_VARSTORE_BUFFER
:
745 CopyMem (Storage
->Buffer
, Storage
->EditBuffer
, Storage
->Size
);
748 case EFI_HII_VARSTORE_NAME_VALUE
:
749 Link
= GetFirstNode (&Storage
->NameValueListHead
);
750 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
751 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
753 NewStringCpy (&Node
->Value
, Node
->EditValue
);
755 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
759 case EFI_HII_VARSTORE_EFI_VARIABLE
:
767 Get Value for given Name from a NameValue Storage.
769 @param Storage The NameValue Storage.
770 @param Name The Name.
771 @param Value The retured Value.
773 @retval EFI_SUCCESS Value found for given Name.
774 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
779 IN FORMSET_STORAGE
*Storage
,
781 IN OUT CHAR16
**Value
785 NAME_VALUE_NODE
*Node
;
789 Link
= GetFirstNode (&Storage
->NameValueListHead
);
790 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
791 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
793 if (StrCmp (Name
, Node
->Name
) == 0) {
794 NewStringCpy (Value
, Node
->EditValue
);
798 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
801 return EFI_NOT_FOUND
;
806 Set Value of given Name in a NameValue Storage.
808 @param Storage The NameValue Storage.
809 @param Name The Name.
810 @param Value The Value to set.
811 @param Edit Whether update editValue or Value.
813 @retval EFI_SUCCESS Value found for given Name.
814 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
819 IN FORMSET_STORAGE
*Storage
,
826 NAME_VALUE_NODE
*Node
;
829 Link
= GetFirstNode (&Storage
->NameValueListHead
);
830 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
831 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
833 if (StrCmp (Name
, Node
->Name
) == 0) {
835 Buffer
= Node
->EditValue
;
837 Buffer
= Node
->Value
;
839 if (Buffer
!= NULL
) {
842 Buffer
= AllocateCopyPool (StrSize (Value
), Value
);
843 ASSERT (Buffer
!= NULL
);
845 Node
->EditValue
= Buffer
;
847 Node
->Value
= Buffer
;
852 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
855 return EFI_NOT_FOUND
;
860 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
862 @param Buffer The Storage to be conveted.
863 @param ConfigResp The returned <ConfigResp>.
864 @param SingleForm Whether update data for single form or formset level.
866 @retval EFI_SUCCESS Convert success.
867 @retval EFI_INVALID_PARAMETER Incorrect storage type.
871 StorageToConfigResp (
873 IN CHAR16
**ConfigResp
,
874 IN BOOLEAN SingleForm
880 NAME_VALUE_NODE
*Node
;
881 CHAR16
*ConfigRequest
;
882 FORMSET_STORAGE
*Storage
;
883 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
885 Status
= EFI_SUCCESS
;
887 ConfigInfo
= (FORM_BROWSER_CONFIG_REQUEST
*) Buffer
;
888 Storage
= ConfigInfo
->Storage
;
889 ConfigRequest
= ConfigInfo
->ConfigRequest
;
891 Storage
= (FORMSET_STORAGE
*) Buffer
;
892 ConfigRequest
= Storage
->ConfigRequest
;
895 switch (Storage
->Type
) {
896 case EFI_HII_VARSTORE_BUFFER
:
897 Status
= mHiiConfigRouting
->BlockToConfig (
907 case EFI_HII_VARSTORE_NAME_VALUE
:
909 NewStringCat (ConfigResp
, Storage
->ConfigHdr
);
911 Link
= GetFirstNode (&Storage
->NameValueListHead
);
912 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
913 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
915 if (StrStr (ConfigRequest
, Node
->Name
) != NULL
) {
916 NewStringCat (ConfigResp
, L
"&");
917 NewStringCat (ConfigResp
, Node
->Name
);
918 NewStringCat (ConfigResp
, L
"=");
919 NewStringCat (ConfigResp
, Node
->EditValue
);
921 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
925 case EFI_HII_VARSTORE_EFI_VARIABLE
:
927 Status
= EFI_INVALID_PARAMETER
;
936 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
938 @param Storage The Storage to receive the settings.
939 @param ConfigResp The <ConfigResp> to be converted.
941 @retval EFI_SUCCESS Convert success.
942 @retval EFI_INVALID_PARAMETER Incorrect storage type.
946 ConfigRespToStorage (
947 IN FORMSET_STORAGE
*Storage
,
948 IN CHAR16
*ConfigResp
958 Status
= EFI_SUCCESS
;
960 switch (Storage
->Type
) {
961 case EFI_HII_VARSTORE_BUFFER
:
962 BufferSize
= Storage
->Size
;
963 Status
= mHiiConfigRouting
->ConfigToBlock (
972 case EFI_HII_VARSTORE_NAME_VALUE
:
973 StrPtr
= StrStr (ConfigResp
, L
"PATH");
974 if (StrPtr
== NULL
) {
977 StrPtr
= StrStr (ConfigResp
, L
"&");
978 while (StrPtr
!= NULL
) {
984 StrPtr
= StrStr (StrPtr
, L
"=");
985 if (StrPtr
== NULL
) {
995 StrPtr
= StrStr (StrPtr
, L
"&");
996 if (StrPtr
!= NULL
) {
999 SetValueByName (Storage
, Name
, Value
, TRUE
);
1003 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1005 Status
= EFI_INVALID_PARAMETER
;
1014 Get Question's current Value.
1016 @param FormSet FormSet data structure.
1017 @param Form Form data structure.
1018 @param Question Question to be initialized.
1019 @param Cached TRUE: get from Edit copy FALSE: get from original
1022 @retval EFI_SUCCESS The function completed successfully.
1027 IN FORM_BROWSER_FORMSET
*FormSet
,
1028 IN FORM_BROWSER_FORM
*Form
,
1029 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1039 FORMSET_STORAGE
*Storage
;
1040 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1041 CHAR16
*ConfigRequest
;
1049 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 // Get question value by read expression.
1077 if (Question
->ReadExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1078 Status
= EvaluateExpression (FormSet
, Form
, Question
->ReadExpression
);
1079 if (!EFI_ERROR (Status
) && (Question
->ReadExpression
->Result
.Type
< EFI_IFR_TYPE_OTHER
)) {
1081 // Only update question value to the valid result.
1083 CopyMem (&Question
->HiiValue
, &Question
->ReadExpression
->Result
, sizeof (EFI_HII_VALUE
));
1089 // Question value is provided by RTC
1091 Storage
= Question
->Storage
;
1092 QuestionValue
= &Question
->HiiValue
.Value
;
1093 if (Storage
== NULL
) {
1095 // It's a Question without storage, or RTC date/time
1097 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1099 // Date and time define the same Flags bit
1101 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1102 case QF_DATE_STORAGE_TIME
:
1103 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1106 case QF_DATE_STORAGE_WAKEUP
:
1107 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1110 case QF_DATE_STORAGE_NORMAL
:
1113 // For date/time without storage
1118 if (EFI_ERROR (Status
)) {
1122 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1123 QuestionValue
->date
.Year
= EfiTime
.Year
;
1124 QuestionValue
->date
.Month
= EfiTime
.Month
;
1125 QuestionValue
->date
.Day
= EfiTime
.Day
;
1127 QuestionValue
->time
.Hour
= EfiTime
.Hour
;
1128 QuestionValue
->time
.Minute
= EfiTime
.Minute
;
1129 QuestionValue
->time
.Second
= EfiTime
.Second
;
1137 // Question value is provided by EFI variable
1139 StorageWidth
= Question
->StorageWidth
;
1140 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1141 if (Question
->BufferValue
!= NULL
) {
1142 Dst
= Question
->BufferValue
;
1144 Dst
= (UINT8
*) QuestionValue
;
1147 Status
= gRT
->GetVariable (
1148 Question
->VariableName
,
1155 // Always return success, even this EFI variable doesn't exist
1161 // Question Value is provided by Buffer Storage or NameValue Storage
1163 if (Question
->BufferValue
!= NULL
) {
1165 // This Question is password or orderedlist
1167 Dst
= Question
->BufferValue
;
1170 // Other type of Questions
1172 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
1175 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1176 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1178 if (IsBufferStorage
) {
1180 // Copy from storage Edit buffer
1182 CopyMem (Dst
, Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, StorageWidth
);
1185 Status
= GetValueByName (Storage
, Question
->VariableName
, &Value
);
1186 if (EFI_ERROR (Status
)) {
1190 ASSERT (Value
!= NULL
);
1191 LengthStr
= StrLen (Value
);
1192 Status
= EFI_SUCCESS
;
1195 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1196 // Add string tail char L'\0' into Length
1198 Length
= StorageWidth
+ sizeof (CHAR16
);
1199 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1200 Status
= EFI_BUFFER_TOO_SMALL
;
1202 StringPtr
= (CHAR16
*) Dst
;
1203 ZeroMem (TemStr
, sizeof (TemStr
));
1204 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1205 StrnCpy (TemStr
, Value
+ Index
, 4);
1206 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1209 // Add tailing L'\0' character
1211 StringPtr
[Index
/4] = L
'\0';
1214 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1215 Status
= EFI_BUFFER_TOO_SMALL
;
1217 ZeroMem (TemStr
, sizeof (TemStr
));
1218 for (Index
= 0; Index
< LengthStr
; Index
++) {
1219 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1220 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1221 if ((Index
& 1) == 0) {
1222 Dst
[Index
/2] = DigitUint8
;
1224 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1234 // Request current settings from Configuration Driver
1236 if (FormSet
->ConfigAccess
== NULL
) {
1237 return EFI_NOT_FOUND
;
1241 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1242 // <ConfigHdr> + "&" + <VariableName>
1244 if (IsBufferStorage
) {
1245 Length
= StrLen (Storage
->ConfigHdr
);
1246 Length
+= StrLen (Question
->BlockName
);
1248 Length
= StrLen (Storage
->ConfigHdr
);
1249 Length
+= StrLen (Question
->VariableName
) + 1;
1251 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
1252 ASSERT (ConfigRequest
!= NULL
);
1254 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
1255 if (IsBufferStorage
) {
1256 StrCat (ConfigRequest
, Question
->BlockName
);
1258 StrCat (ConfigRequest
, L
"&");
1259 StrCat (ConfigRequest
, Question
->VariableName
);
1262 Status
= FormSet
->ConfigAccess
->ExtractConfig (
1263 FormSet
->ConfigAccess
,
1268 if (EFI_ERROR (Status
)) {
1273 // Skip <ConfigRequest>
1275 Value
= Result
+ Length
;
1276 if (IsBufferStorage
) {
1282 if (*Value
!= '=') {
1284 return EFI_NOT_FOUND
;
1287 // Skip '=', point to value
1292 // Suppress <AltResp> if any
1295 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1300 LengthStr
= StrLen (Value
);
1301 Status
= EFI_SUCCESS
;
1302 if (!IsBufferStorage
&& IsString
) {
1304 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1305 // Add string tail char L'\0' into Length
1307 Length
= StorageWidth
+ sizeof (CHAR16
);
1308 if (Length
< ((LengthStr
/ 4 + 1) * 2)) {
1309 Status
= EFI_BUFFER_TOO_SMALL
;
1311 StringPtr
= (CHAR16
*) Dst
;
1312 ZeroMem (TemStr
, sizeof (TemStr
));
1313 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
1314 StrnCpy (TemStr
, Value
+ Index
, 4);
1315 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
1318 // Add tailing L'\0' character
1320 StringPtr
[Index
/4] = L
'\0';
1323 if (StorageWidth
< ((LengthStr
+ 1) / 2)) {
1324 Status
= EFI_BUFFER_TOO_SMALL
;
1326 ZeroMem (TemStr
, sizeof (TemStr
));
1327 for (Index
= 0; Index
< LengthStr
; Index
++) {
1328 TemStr
[0] = Value
[LengthStr
- Index
- 1];
1329 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1330 if ((Index
& 1) == 0) {
1331 Dst
[Index
/2] = DigitUint8
;
1333 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
1339 if (EFI_ERROR (Status
)) {
1345 // Synchronize Edit Buffer
1347 if (IsBufferStorage
) {
1348 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Dst
, StorageWidth
);
1350 SetValueByName (Storage
, Question
->VariableName
, Value
, TRUE
);
1361 Save Question Value to edit copy(cached) or Storage(uncached).
1363 @param FormSet FormSet data structure.
1364 @param Form Form data structure.
1365 @param Question Pointer to the Question.
1366 @param Cached TRUE: set to Edit copy FALSE: set to original
1369 @retval EFI_SUCCESS The function completed successfully.
1374 IN FORM_BROWSER_FORMSET
*FormSet
,
1375 IN FORM_BROWSER_FORM
*Form
,
1376 IN OUT FORM_BROWSER_STATEMENT
*Question
,
1387 FORMSET_STORAGE
*Storage
;
1388 EFI_IFR_TYPE_VALUE
*QuestionValue
;
1393 BOOLEAN IsBufferStorage
;
1400 Status
= EFI_SUCCESS
;
1403 // Statement don't have storage, skip them
1405 if (Question
->QuestionId
== 0) {
1410 // If Question value is provided by an Expression, then it is read only
1412 if (Question
->ValueExpression
!= NULL
) {
1417 // Before set question value, evaluate its write expression.
1419 if (Question
->WriteExpression
!= NULL
&& Form
->FormType
== STANDARD_MAP_FORM_TYPE
) {
1420 Status
= EvaluateExpression (FormSet
, Form
, Question
->WriteExpression
);
1421 if (EFI_ERROR (Status
)) {
1427 // Question value is provided by RTC
1429 Storage
= Question
->Storage
;
1430 QuestionValue
= &Question
->HiiValue
.Value
;
1431 if (Storage
== NULL
) {
1433 // It's a Question without storage, or RTC date/time
1435 if (Question
->Operand
== EFI_IFR_DATE_OP
|| Question
->Operand
== EFI_IFR_TIME_OP
) {
1437 // Date and time define the same Flags bit
1439 switch (Question
->Flags
& EFI_QF_DATE_STORAGE
) {
1440 case QF_DATE_STORAGE_TIME
:
1441 Status
= gRT
->GetTime (&EfiTime
, NULL
);
1444 case QF_DATE_STORAGE_WAKEUP
:
1445 Status
= gRT
->GetWakeupTime (&Enabled
, &Pending
, &EfiTime
);
1448 case QF_DATE_STORAGE_NORMAL
:
1451 // For date/time without storage
1456 if (EFI_ERROR (Status
)) {
1460 if (Question
->Operand
== EFI_IFR_DATE_OP
) {
1461 EfiTime
.Year
= QuestionValue
->date
.Year
;
1462 EfiTime
.Month
= QuestionValue
->date
.Month
;
1463 EfiTime
.Day
= QuestionValue
->date
.Day
;
1465 EfiTime
.Hour
= QuestionValue
->time
.Hour
;
1466 EfiTime
.Minute
= QuestionValue
->time
.Minute
;
1467 EfiTime
.Second
= QuestionValue
->time
.Second
;
1470 if ((Question
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_TIME
) {
1471 Status
= gRT
->SetTime (&EfiTime
);
1473 Status
= gRT
->SetWakeupTime (TRUE
, &EfiTime
);
1481 // Question value is provided by EFI variable
1483 StorageWidth
= Question
->StorageWidth
;
1484 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1485 if (Question
->BufferValue
!= NULL
) {
1486 Src
= Question
->BufferValue
;
1488 Src
= (UINT8
*) QuestionValue
;
1491 Status
= gRT
->SetVariable (
1492 Question
->VariableName
,
1494 Storage
->Attributes
,
1502 // Question Value is provided by Buffer Storage or NameValue Storage
1504 if (Question
->BufferValue
!= NULL
) {
1505 Src
= Question
->BufferValue
;
1507 Src
= (UINT8
*) &Question
->HiiValue
.Value
;
1510 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
1511 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
1512 if (IsBufferStorage
) {
1514 // Copy to storage edit buffer
1516 CopyMem (Storage
->EditBuffer
+ Question
->VarStoreInfo
.VarOffset
, Src
, StorageWidth
);
1520 // Allocate enough string buffer.
1523 BufferLen
= ((StrLen ((CHAR16
*) Src
) * 4) + 1) * sizeof (CHAR16
);
1524 Value
= AllocateZeroPool (BufferLen
);
1525 ASSERT (Value
!= NULL
);
1527 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1529 TemName
= (CHAR16
*) Src
;
1531 for (; *TemName
!= L
'\0'; TemName
++) {
1532 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1535 BufferLen
= StorageWidth
* 2 + 1;
1536 Value
= AllocateZeroPool (BufferLen
* sizeof (CHAR16
));
1537 ASSERT (Value
!= NULL
);
1539 // Convert Buffer to Hex String
1541 TemBuffer
= Src
+ StorageWidth
- 1;
1543 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1544 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1548 Status
= SetValueByName (Storage
, Question
->VariableName
, Value
, TRUE
);
1554 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1555 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1557 if (IsBufferStorage
) {
1558 Length
= StrLen (Question
->BlockName
) + 7;
1560 Length
= StrLen (Question
->VariableName
) + 2;
1562 if (!IsBufferStorage
&& IsString
) {
1563 Length
+= (StrLen ((CHAR16
*) Src
) * 4);
1565 Length
+= (StorageWidth
* 2);
1567 ConfigResp
= AllocateZeroPool ((StrLen (Storage
->ConfigHdr
) + Length
+ 1) * sizeof (CHAR16
));
1568 ASSERT (ConfigResp
!= NULL
);
1570 StrCpy (ConfigResp
, Storage
->ConfigHdr
);
1571 if (IsBufferStorage
) {
1572 StrCat (ConfigResp
, Question
->BlockName
);
1573 StrCat (ConfigResp
, L
"&VALUE=");
1575 StrCat (ConfigResp
, L
"&");
1576 StrCat (ConfigResp
, Question
->VariableName
);
1577 StrCat (ConfigResp
, L
"=");
1580 Value
= ConfigResp
+ StrLen (ConfigResp
);
1582 if (!IsBufferStorage
&& IsString
) {
1584 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1586 TemName
= (CHAR16
*) Src
;
1588 for (; *TemName
!= L
'\0'; TemName
++) {
1589 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
1593 // Convert Buffer to Hex String
1595 TemBuffer
= Src
+ StorageWidth
- 1;
1597 for (Index
= 0; Index
< StorageWidth
; Index
++, TemBuffer
--) {
1598 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
1603 // Convert to lower char.
1605 for (TemString
= Value
; *Value
!= L
'\0'; Value
++) {
1606 if (*Value
>= L
'A' && *Value
<= L
'Z') {
1607 *Value
= (CHAR16
) (*Value
- L
'A' + L
'a');
1612 // Submit Question Value to Configuration Driver
1614 if (FormSet
->ConfigAccess
!= NULL
) {
1615 Status
= FormSet
->ConfigAccess
->RouteConfig (
1616 FormSet
->ConfigAccess
,
1620 if (EFI_ERROR (Status
)) {
1621 FreePool (ConfigResp
);
1625 FreePool (ConfigResp
);
1628 // Synchronize shadow Buffer
1630 SynchronizeStorage (Storage
);
1638 Perform inconsistent check for a Form.
1640 @param FormSet FormSet data structure.
1641 @param Form Form data structure.
1642 @param Question The Question to be validated.
1643 @param Type Validation type: InConsistent or NoSubmit
1645 @retval EFI_SUCCESS Form validation pass.
1646 @retval other Form validation failed.
1651 IN FORM_BROWSER_FORMSET
*FormSet
,
1652 IN FORM_BROWSER_FORM
*Form
,
1653 IN FORM_BROWSER_STATEMENT
*Question
,
1659 LIST_ENTRY
*ListHead
;
1662 FORM_EXPRESSION
*Expression
;
1664 if (Type
== EFI_HII_EXPRESSION_INCONSISTENT_IF
) {
1665 ListHead
= &Question
->InconsistentListHead
;
1666 } else if (Type
== EFI_HII_EXPRESSION_NO_SUBMIT_IF
) {
1667 ListHead
= &Question
->NoSubmitListHead
;
1669 return EFI_UNSUPPORTED
;
1672 Link
= GetFirstNode (ListHead
);
1673 while (!IsNull (ListHead
, Link
)) {
1674 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1677 // Evaluate the expression
1679 Status
= EvaluateExpression (FormSet
, Form
, Expression
);
1680 if (EFI_ERROR (Status
)) {
1684 if (Expression
->Result
.Value
.b
) {
1686 // Condition meet, show up error message
1688 if (Expression
->Error
!= 0) {
1689 PopUp
= GetToken (Expression
->Error
, FormSet
->HiiHandle
);
1691 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, PopUp
, gPressEnter
, gEmptyString
);
1692 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1696 return EFI_NOT_READY
;
1699 Link
= GetNextNode (ListHead
, Link
);
1707 Perform NoSubmit check for each Form in FormSet.
1709 @param FormSet FormSet data structure.
1710 @param CurrentForm Current input form data structure.
1712 @retval EFI_SUCCESS Form validation pass.
1713 @retval other Form validation failed.
1718 IN FORM_BROWSER_FORMSET
*FormSet
,
1719 IN FORM_BROWSER_FORM
*CurrentForm
1724 FORM_BROWSER_STATEMENT
*Question
;
1725 FORM_BROWSER_FORM
*Form
;
1726 LIST_ENTRY
*LinkForm
;
1728 LinkForm
= GetFirstNode (&FormSet
->FormListHead
);
1729 while (!IsNull (&FormSet
->FormListHead
, LinkForm
)) {
1730 Form
= FORM_BROWSER_FORM_FROM_LINK (LinkForm
);
1731 LinkForm
= GetNextNode (&FormSet
->FormListHead
, LinkForm
);
1733 if (CurrentForm
!= NULL
&& CurrentForm
!= Form
) {
1737 Link
= GetFirstNode (&Form
->StatementListHead
);
1738 while (!IsNull (&Form
->StatementListHead
, Link
)) {
1739 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
1741 Status
= ValidateQuestion (FormSet
, Form
, Question
, EFI_HII_EXPRESSION_NO_SUBMIT_IF
);
1742 if (EFI_ERROR (Status
)) {
1746 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
1754 Restore Storage's Edit copy to Shadow copy.
1756 @param Storage The Storage to be synchronized.
1761 IN FORMSET_STORAGE
*Storage
1765 NAME_VALUE_NODE
*Node
;
1767 switch (Storage
->Type
) {
1768 case EFI_HII_VARSTORE_BUFFER
:
1769 CopyMem (Storage
->EditBuffer
, Storage
->Buffer
, Storage
->Size
);
1772 case EFI_HII_VARSTORE_NAME_VALUE
:
1773 Link
= GetFirstNode (&Storage
->NameValueListHead
);
1774 while (!IsNull (&Storage
->NameValueListHead
, Link
)) {
1775 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1777 if (Node
->EditValue
!= NULL
) {
1778 FreePool (Node
->EditValue
);
1780 Node
->EditValue
= AllocateCopyPool (StrSize (Node
->Value
), Node
->Value
);
1781 ASSERT (Node
->EditValue
!= NULL
);
1782 Link
= GetNextNode (&Storage
->NameValueListHead
, Link
);
1786 case EFI_HII_VARSTORE_EFI_VARIABLE
:
1793 Fill storage's edit copy with settings requested from Configuration Driver.
1795 @param FormSet FormSet data structure.
1796 @param ConfigInfo The config info related to this form.
1798 @retval EFI_SUCCESS The function completed successfully.
1802 FormRestoreStorage (
1803 IN FORM_BROWSER_FORMSET
*FormSet
,
1804 IN FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
1808 EFI_STRING Progress
;
1812 NAME_VALUE_NODE
*Node
;
1814 Status
= EFI_SUCCESS
;
1816 if (FormSet
->ConfigAccess
== NULL
) {
1817 return EFI_NOT_FOUND
;
1820 if (ConfigInfo
->ElementCount
== 0) {
1822 // Skip if there is no RequestElement
1827 if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
1828 BufferSize
= ConfigInfo
->Storage
->Size
;
1829 Status
= mHiiConfigRouting
->BlockToConfig(
1831 ConfigInfo
->ConfigRequest
,
1832 ConfigInfo
->Storage
->Buffer
,
1837 if (EFI_ERROR (Status
)) {
1841 Status
= mHiiConfigRouting
->ConfigToBlock (
1844 ConfigInfo
->Storage
->EditBuffer
,
1848 if (Result
!= NULL
) {
1852 if (EFI_ERROR (Status
)) {
1855 } else if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
1856 Link
= GetFirstNode (&ConfigInfo
->Storage
->NameValueListHead
);
1857 while (!IsNull (&ConfigInfo
->Storage
->NameValueListHead
, Link
)) {
1858 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
1860 if (StrStr (ConfigInfo
->ConfigRequest
, Node
->Name
) != NULL
) {
1861 if (Node
->EditValue
!= NULL
) {
1862 FreePool (Node
->EditValue
);
1864 Node
->EditValue
= AllocateCopyPool (StrSize (Node
->Value
), Node
->Value
);
1865 ASSERT (Node
->EditValue
!= NULL
);
1868 Link
= GetNextNode (&ConfigInfo
->Storage
->NameValueListHead
, Link
);
1877 Discard data for form level or formset level.
1879 @param FormSet FormSet data structure.
1880 @param Form Form data structure.
1881 @param SingleForm Only discard single form or formset.
1883 @retval EFI_SUCCESS The function completed successfully.
1888 IN FORM_BROWSER_FORMSET
*FormSet
,
1889 IN FORM_BROWSER_FORM
*Form
,
1890 IN BOOLEAN SingleForm
1894 FORMSET_STORAGE
*Storage
;
1895 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
1898 if (Form
->NvUpdateRequired
) {
1900 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
1901 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
1902 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
1903 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
1905 if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1910 // Skip if there is no RequestElement
1912 if (ConfigInfo
->ElementCount
== 0) {
1917 // Prepare <ConfigResp>
1919 FormRestoreStorage(FormSet
, ConfigInfo
);
1922 Form
->NvUpdateRequired
= FALSE
;
1925 if (IsNvUpdateRequired(FormSet
)) {
1927 // Discard Buffer storage or Name/Value storage
1929 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1930 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1931 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1932 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1934 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
1939 // Skip if there is no RequestElement
1941 if (Storage
->ElementCount
== 0) {
1945 RestoreStorage(Storage
);
1948 UpdateNvInfoInForm(FormSet
, FALSE
);
1956 Submit data for form level or formset level.
1958 @param FormSet FormSet data structure.
1959 @param Form Form data structure.
1960 @param SingleForm whether submit for the single form or all form set.
1962 @retval EFI_SUCCESS The function completed successfully.
1967 IN FORM_BROWSER_FORMSET
*FormSet
,
1968 IN FORM_BROWSER_FORM
*Form
,
1969 IN BOOLEAN SingleForm
1974 EFI_STRING ConfigResp
;
1975 EFI_STRING Progress
;
1976 FORMSET_STORAGE
*Storage
;
1977 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
1980 // Validate the Form by NoSubmit check
1983 Status
= NoSubmitCheck (FormSet
, Form
);
1985 Status
= NoSubmitCheck (FormSet
, NULL
);
1987 if (EFI_ERROR (Status
)) {
1993 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
1994 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
1995 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
1996 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
1998 if (ConfigInfo
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2003 // Skip if there is no RequestElement
2005 if (ConfigInfo
->ElementCount
== 0) {
2010 // Prepare <ConfigResp>
2012 Status
= StorageToConfigResp (ConfigInfo
, &ConfigResp
, TRUE
);
2013 if (EFI_ERROR (Status
)) {
2018 // Send <ConfigResp> to Configuration Driver
2020 if (FormSet
->ConfigAccess
!= NULL
) {
2021 Status
= FormSet
->ConfigAccess
->RouteConfig (
2022 FormSet
->ConfigAccess
,
2026 if (EFI_ERROR (Status
)) {
2027 FreePool (ConfigResp
);
2031 FreePool (ConfigResp
);
2034 // Config success, update storage shadow Buffer
2036 SynchronizeStorage (ConfigInfo
->Storage
);
2039 Form
->NvUpdateRequired
= FALSE
;
2042 // Submit Buffer storage or Name/Value storage
2044 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2045 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2046 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2047 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2049 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2054 // Skip if there is no RequestElement
2056 if (Storage
->ElementCount
== 0) {
2061 // Prepare <ConfigResp>
2063 Status
= StorageToConfigResp (Storage
, &ConfigResp
, FALSE
);
2064 if (EFI_ERROR (Status
)) {
2069 // Send <ConfigResp> to Configuration Driver
2071 if (FormSet
->ConfigAccess
!= NULL
) {
2072 Status
= FormSet
->ConfigAccess
->RouteConfig (
2073 FormSet
->ConfigAccess
,
2077 if (EFI_ERROR (Status
)) {
2078 FreePool (ConfigResp
);
2082 FreePool (ConfigResp
);
2085 // Config success, update storage shadow Buffer
2087 SynchronizeStorage (Storage
);
2090 UpdateNvInfoInForm(FormSet
, FALSE
);
2097 Get Question default value from AltCfg string.
2099 @param FormSet The form set.
2100 @param Question The question.
2101 @param DefaultId The default Id.
2103 @retval EFI_SUCCESS Question is reset to default value.
2107 GetDefaultValueFromAltCfg (
2108 IN FORM_BROWSER_FORMSET
*FormSet
,
2109 IN OUT FORM_BROWSER_STATEMENT
*Question
,
2113 BOOLEAN IsBufferStorage
;
2116 FORMSET_STORAGE
*Storage
;
2117 CHAR16
*ConfigRequest
;
2130 Status
= EFI_NOT_FOUND
;
2133 ConfigRequest
= NULL
;
2137 Storage
= Question
->Storage
;
2139 if ((Storage
== NULL
) || (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
2144 // Question Value is provided by Buffer Storage or NameValue Storage
2146 if (Question
->BufferValue
!= NULL
) {
2148 // This Question is password or orderedlist
2150 Dst
= Question
->BufferValue
;
2153 // Other type of Questions
2155 Dst
= (UINT8
*) &Question
->HiiValue
.Value
;
2158 IsBufferStorage
= (BOOLEAN
) ((Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) ? TRUE
: FALSE
);
2159 IsString
= (BOOLEAN
) ((Question
->HiiValue
.Type
== EFI_IFR_TYPE_STRING
) ? TRUE
: FALSE
);
2162 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
2163 // <ConfigHdr> + "&" + <VariableName>
2165 if (IsBufferStorage
) {
2166 Length
= StrLen (Storage
->ConfigHdr
);
2167 Length
+= StrLen (Question
->BlockName
);
2169 Length
= StrLen (Storage
->ConfigHdr
);
2170 Length
+= StrLen (Question
->VariableName
) + 1;
2172 ConfigRequest
= AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
2173 ASSERT (ConfigRequest
!= NULL
);
2175 StrCpy (ConfigRequest
, Storage
->ConfigHdr
);
2176 if (IsBufferStorage
) {
2177 StrCat (ConfigRequest
, Question
->BlockName
);
2179 StrCat (ConfigRequest
, L
"&");
2180 StrCat (ConfigRequest
, Question
->VariableName
);
2183 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2184 FormSet
->ConfigAccess
,
2189 if (EFI_ERROR (Status
)) {
2194 // Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
2195 // Get the default configuration string according to the default ID.
2197 Status
= mHiiConfigRouting
->GetAltConfig (
2203 &DefaultId
, // it can be NULL to get the current setting.
2208 // The required setting can't be found. So, it is not required to be validated and set.
2210 if (EFI_ERROR (Status
)) {
2215 // Skip <ConfigRequest>
2217 if (IsBufferStorage
) {
2218 Value
= StrStr (ConfigResp
, L
"&VALUE");
2219 ASSERT (Value
!= NULL
);
2225 Value
= StrStr (ConfigResp
, Question
->VariableName
);
2226 ASSERT (Value
!= NULL
);
2228 Value
= Value
+ StrLen (Question
->VariableName
);
2230 if (*Value
!= '=') {
2231 Status
= EFI_NOT_FOUND
;
2235 // Skip '=', point to value
2240 // Suppress <AltResp> if any
2243 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
2248 LengthStr
= StrLen (Value
);
2249 if (!IsBufferStorage
&& IsString
) {
2250 StringPtr
= (CHAR16
*) Dst
;
2251 ZeroMem (TemStr
, sizeof (TemStr
));
2252 for (Index
= 0; Index
< LengthStr
; Index
+= 4) {
2253 StrnCpy (TemStr
, Value
+ Index
, 4);
2254 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
2257 // Add tailing L'\0' character
2259 StringPtr
[Index
/4] = L
'\0';
2261 ZeroMem (TemStr
, sizeof (TemStr
));
2262 for (Index
= 0; Index
< LengthStr
; Index
++) {
2263 TemStr
[0] = Value
[LengthStr
- Index
- 1];
2264 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
2265 if ((Index
& 1) == 0) {
2266 Dst
[Index
/2] = DigitUint8
;
2268 Dst
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Dst
[Index
/2]);
2274 if (ConfigRequest
!= NULL
){
2275 FreePool (ConfigRequest
);
2278 if (ConfigResp
!= NULL
) {
2279 FreePool (ConfigResp
);
2282 if (Result
!= NULL
) {
2290 Get default Id value used for browser.
2292 @param DefaultId The default id value used by hii.
2294 @retval Browser used default value.
2298 GetDefaultIdForCallBack (
2302 if (DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) {
2303 return EFI_BROWSER_ACTION_DEFAULT_STANDARD
;
2304 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2305 return EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
;
2306 } else if (DefaultId
== EFI_HII_DEFAULT_CLASS_SAFE
) {
2307 return EFI_BROWSER_ACTION_DEFAULT_SAFE
;
2308 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
+ 0x1000) {
2309 return EFI_BROWSER_ACTION_DEFAULT_PLATFORM
+ DefaultId
- EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN
;
2310 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
+ 0x1000) {
2311 return EFI_BROWSER_ACTION_DEFAULT_HARDWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN
;
2312 } else if (DefaultId
>= EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
&& DefaultId
< EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
+ 0x1000) {
2313 return EFI_BROWSER_ACTION_DEFAULT_FIRMWARE
+ DefaultId
- EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN
;
2320 Reset Question to its default value.
2322 @param FormSet The form set.
2323 @param Form The form.
2324 @param Question The question.
2325 @param DefaultId The Class of the default.
2327 @retval EFI_SUCCESS Question is reset to default value.
2331 GetQuestionDefault (
2332 IN FORM_BROWSER_FORMSET
*FormSet
,
2333 IN FORM_BROWSER_FORM
*Form
,
2334 IN FORM_BROWSER_STATEMENT
*Question
,
2340 QUESTION_DEFAULT
*Default
;
2341 QUESTION_OPTION
*Option
;
2342 EFI_HII_VALUE
*HiiValue
;
2344 EFI_STRING StrValue
;
2345 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2346 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
2349 Status
= EFI_SUCCESS
;
2353 // Statement don't have storage, skip them
2355 if (Question
->QuestionId
== 0) {
2360 // There are Five ways to specify default value for a Question:
2361 // 1, use call back function (highest priority)
2362 // 2, use ExtractConfig function
2363 // 3, use nested EFI_IFR_DEFAULT
2364 // 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
2365 // 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
2367 HiiValue
= &Question
->HiiValue
;
2370 // Get Question defaut value from call back function.
2372 ConfigAccess
= FormSet
->ConfigAccess
;
2373 Action
= GetDefaultIdForCallBack (DefaultId
);
2374 if ((Action
> 0) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
2375 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
2376 Status
= ConfigAccess
->Callback (
2379 Question
->QuestionId
,
2384 if (!EFI_ERROR (Status
)) {
2390 // Get default value from altcfg string.
2392 if (ConfigAccess
!= NULL
) {
2393 Status
= GetDefaultValueFromAltCfg(FormSet
, Question
, DefaultId
);
2394 if (!EFI_ERROR (Status
)) {
2400 // EFI_IFR_DEFAULT has highest priority
2402 if (!IsListEmpty (&Question
->DefaultListHead
)) {
2403 Link
= GetFirstNode (&Question
->DefaultListHead
);
2404 while (!IsNull (&Question
->DefaultListHead
, Link
)) {
2405 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
2407 if (Default
->DefaultId
== DefaultId
) {
2408 if (Default
->ValueExpression
!= NULL
) {
2410 // Default is provided by an Expression, evaluate it
2412 Status
= EvaluateExpression (FormSet
, Form
, Default
->ValueExpression
);
2413 if (EFI_ERROR (Status
)) {
2417 CopyMem (HiiValue
, &Default
->ValueExpression
->Result
, sizeof (EFI_HII_VALUE
));
2420 // Default value is embedded in EFI_IFR_DEFAULT
2422 CopyMem (HiiValue
, &Default
->Value
, sizeof (EFI_HII_VALUE
));
2425 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
2426 StrValue
= HiiGetString (FormSet
->HiiHandle
, HiiValue
->Value
.string
, NULL
);
2427 if (StrValue
== NULL
) {
2428 return EFI_NOT_FOUND
;
2430 Question
->BufferValue
= AllocateCopyPool (StrSize (StrValue
), StrValue
);
2436 Link
= GetNextNode (&Question
->DefaultListHead
, Link
);
2441 // EFI_ONE_OF_OPTION
2443 if ((Question
->Operand
== EFI_IFR_ONE_OF_OP
) && !IsListEmpty (&Question
->OptionListHead
)) {
2444 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2446 // OneOfOption could only provide Standard and Manufacturing default
2448 Link
= GetFirstNode (&Question
->OptionListHead
);
2449 while (!IsNull (&Question
->OptionListHead
, Link
)) {
2450 Option
= QUESTION_OPTION_FROM_LINK (Link
);
2452 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0)) ||
2453 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Option
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0))
2455 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
2460 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
2466 // EFI_IFR_CHECKBOX - lowest priority
2468 if (Question
->Operand
== EFI_IFR_CHECKBOX_OP
) {
2469 if (DefaultId
<= EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2471 // Checkbox could only provide Standard and Manufacturing default
2473 if (((DefaultId
== EFI_HII_DEFAULT_CLASS_STANDARD
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0)) ||
2474 ((DefaultId
== EFI_HII_DEFAULT_CLASS_MANUFACTURING
) && ((Question
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0))
2476 HiiValue
->Value
.b
= TRUE
;
2478 HiiValue
->Value
.b
= FALSE
;
2486 // For Questions without default
2488 switch (Question
->Operand
) {
2489 case EFI_IFR_NUMERIC_OP
:
2491 // Take minimum value as numeric default value
2493 if ((HiiValue
->Value
.u64
< Question
->Minimum
) || (HiiValue
->Value
.u64
> Question
->Maximum
)) {
2494 HiiValue
->Value
.u64
= Question
->Minimum
;
2498 case EFI_IFR_ONE_OF_OP
:
2500 // Take first oneof option as oneof's default value
2502 if (ValueToOption (Question
, HiiValue
) == NULL
) {
2503 Link
= GetFirstNode (&Question
->OptionListHead
);
2504 if (!IsNull (&Question
->OptionListHead
, Link
)) {
2505 Option
= QUESTION_OPTION_FROM_LINK (Link
);
2506 CopyMem (HiiValue
, &Option
->Value
, sizeof (EFI_HII_VALUE
));
2511 case EFI_IFR_ORDERED_LIST_OP
:
2513 // Take option sequence in IFR as ordered list's default value
2516 Link
= GetFirstNode (&Question
->OptionListHead
);
2517 while (!IsNull (&Question
->OptionListHead
, Link
)) {
2518 Option
= QUESTION_OPTION_FROM_LINK (Link
);
2520 SetArrayData (Question
->BufferValue
, Question
->ValueType
, Index
, Option
->Value
.Value
.u64
);
2523 if (Index
>= Question
->MaxContainers
) {
2527 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
2532 Status
= EFI_NOT_FOUND
;
2541 Reset Questions in a Formset to their default value.
2543 @param FormSet FormSet data structure.
2544 @param DefaultId The Class of the default.
2546 @retval EFI_SUCCESS The function completed successfully.
2550 ExtractFormSetDefault (
2551 IN FORM_BROWSER_FORMSET
*FormSet
,
2556 LIST_ENTRY
*FormLink
;
2557 LIST_ENTRY
*StatementLink
;
2558 FORM_BROWSER_STATEMENT
*Question
;
2559 FORM_BROWSER_FORM
*Form
;
2561 FormLink
= GetFirstNode (&FormSet
->FormListHead
);
2562 while (!IsNull (&FormSet
->FormListHead
, FormLink
)) {
2563 Form
= FORM_BROWSER_FORM_FROM_LINK (FormLink
);
2566 // Extract Form default
2568 StatementLink
= GetFirstNode (&Form
->StatementListHead
);
2569 while (!IsNull (&Form
->StatementListHead
, StatementLink
)) {
2570 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementLink
);
2571 StatementLink
= GetNextNode (&Form
->StatementListHead
, StatementLink
);
2574 // If Question is disabled, don't reset it to default
2576 if (Question
->DisableExpression
!= NULL
) {
2577 Status
= EvaluateExpression (FormSet
, Form
, Question
->DisableExpression
);
2578 if (!EFI_ERROR (Status
) && Question
->DisableExpression
->Result
.Value
.b
) {
2584 // Reset Question to its default value
2586 Status
= GetQuestionDefault (FormSet
, Form
, Question
, DefaultId
);
2587 if (EFI_ERROR (Status
)) {
2592 // Synchronize Buffer storage's Edit buffer
2594 if ((Question
->Storage
!= NULL
) &&
2595 (Question
->Storage
->Type
!= EFI_HII_VARSTORE_EFI_VARIABLE
)) {
2596 SetQuestionValue (FormSet
, Form
, Question
, TRUE
);
2599 FormLink
= GetNextNode (&FormSet
->FormListHead
, FormLink
);
2606 Initialize Question's Edit copy from Storage.
2608 @param Selection Selection contains the information about
2609 the Selection, form and formset to be displayed.
2610 Selection action may be updated in retrieve callback.
2611 @param FormSet FormSet data structure.
2612 @param Form Form data structure.
2614 @retval EFI_SUCCESS The function completed successfully.
2619 IN OUT UI_MENU_SELECTION
*Selection
,
2620 IN FORM_BROWSER_FORMSET
*FormSet
,
2621 IN FORM_BROWSER_FORM
*Form
2626 FORM_BROWSER_STATEMENT
*Question
;
2630 Link
= GetFirstNode (&Form
->StatementListHead
);
2631 while (!IsNull (&Form
->StatementListHead
, Link
)) {
2632 Question
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
2635 // Initialize local copy of Value for each Question
2637 Status
= GetQuestionValue (FormSet
, Form
, Question
, TRUE
);
2638 if (EFI_ERROR (Status
)) {
2642 if ((Question
->Operand
== EFI_IFR_STRING_OP
) || (Question
->Operand
== EFI_IFR_PASSWORD_OP
)) {
2643 HiiSetString (FormSet
->HiiHandle
, Question
->HiiValue
.Value
.string
, (CHAR16
*)Question
->BufferValue
, NULL
);
2647 // According the spec, ref opcode try to get value from call back with "retrieve" type.
2649 if ((Question
->Operand
== EFI_IFR_REF_OP
) && (FormSet
->ConfigAccess
!= NULL
)) {
2650 Status
= ProcessCallBackFunction(Selection
, Question
, EFI_BROWSER_ACTION_RETRIEVE
, TRUE
);
2651 if (EFI_ERROR (Status
)) {
2657 // Check whether EfiVarstore with CallBack can be got.
2659 if ((FormSet
->ConfigAccess
!= NULL
) &&
2660 (Selection
->Action
!= UI_ACTION_REFRESH_FORMSET
) &&
2661 (Question
->QuestionId
!= 0) &&
2662 (Question
->Storage
!= NULL
) &&
2663 (Question
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) &&
2664 ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
)) {
2667 // Check QuestionValue does exist.
2669 StorageWidth
= Question
->StorageWidth
;
2670 if (Question
->BufferValue
!= NULL
) {
2671 BufferValue
= Question
->BufferValue
;
2673 BufferValue
= (UINT8
*) &Question
->HiiValue
.Value
;
2675 Status
= gRT
->GetVariable (
2676 Question
->VariableName
,
2677 &Question
->Storage
->Guid
,
2683 if (!EFI_ERROR (Status
)) {
2684 Status
= ProcessCallBackFunction(Selection
, Question
, EFI_BROWSER_ACTION_RETRIEVE
, TRUE
);
2688 Link
= GetNextNode (&Form
->StatementListHead
, Link
);
2695 Initialize Question's Edit copy from Storage for the whole Formset.
2697 @param Selection Selection contains the information about
2698 the Selection, form and formset to be displayed.
2699 Selection action may be updated in retrieve callback.
2700 @param FormSet FormSet data structure.
2702 @retval EFI_SUCCESS The function completed successfully.
2707 IN OUT UI_MENU_SELECTION
*Selection
,
2708 IN FORM_BROWSER_FORMSET
*FormSet
2713 FORM_BROWSER_FORM
*Form
;
2715 Link
= GetFirstNode (&FormSet
->FormListHead
);
2716 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2717 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2720 // Initialize local copy of Value for each Form
2722 Status
= LoadFormConfig (Selection
, FormSet
, Form
);
2723 if (EFI_ERROR (Status
)) {
2727 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2734 Fill storage's edit copy with settings requested from Configuration Driver.
2736 @param FormSet FormSet data structure.
2737 @param Storage Buffer Storage.
2739 @retval EFI_SUCCESS The function completed successfully.
2744 IN FORM_BROWSER_FORMSET
*FormSet
,
2745 IN FORMSET_STORAGE
*Storage
2749 EFI_STRING Progress
;
2753 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
2757 if (FormSet
->ConfigAccess
== NULL
) {
2758 return EFI_NOT_FOUND
;
2761 if (Storage
->ElementCount
== 0) {
2763 // Skip if there is no RequestElement
2769 // Request current settings from Configuration Driver
2771 Status
= FormSet
->ConfigAccess
->ExtractConfig (
2772 FormSet
->ConfigAccess
,
2773 Storage
->ConfigRequest
,
2777 if (EFI_ERROR (Status
)) {
2782 // Convert Result from <ConfigAltResp> to <ConfigResp>
2784 StrPtr
= StrStr (Result
, L
"ALTCFG");
2785 if (StrPtr
!= NULL
) {
2789 Status
= ConfigRespToStorage (Storage
, Result
);
2796 Copy uncommitted data from source Storage to destination Storage.
2798 @param Dst Target Storage for uncommitted data.
2799 @param Src Source Storage for uncommitted data.
2801 @retval EFI_SUCCESS The function completed successfully.
2802 @retval EFI_INVALID_PARAMETER Source and destination Storage is not the same type.
2807 IN OUT FORMSET_STORAGE
*Dst
,
2808 IN FORMSET_STORAGE
*Src
2812 NAME_VALUE_NODE
*Node
;
2814 if ((Dst
->Type
!= Src
->Type
) || (Dst
->Size
!= Src
->Size
)) {
2815 return EFI_INVALID_PARAMETER
;
2818 switch (Src
->Type
) {
2819 case EFI_HII_VARSTORE_BUFFER
:
2820 CopyMem (Dst
->EditBuffer
, Src
->EditBuffer
, Src
->Size
);
2821 CopyMem (Dst
->Buffer
, Src
->Buffer
, Src
->Size
);
2824 case EFI_HII_VARSTORE_NAME_VALUE
:
2825 Link
= GetFirstNode (&Src
->NameValueListHead
);
2826 while (!IsNull (&Src
->NameValueListHead
, Link
)) {
2827 Node
= NAME_VALUE_NODE_FROM_LINK (Link
);
2829 SetValueByName (Dst
, Node
->Name
, Node
->EditValue
, TRUE
);
2830 SetValueByName (Dst
, Node
->Name
, Node
->Value
, FALSE
);
2832 Link
= GetNextNode (&Src
->NameValueListHead
, Link
);
2836 case EFI_HII_VARSTORE_EFI_VARIABLE
:
2846 Get current setting of Questions.
2848 @param FormSet FormSet data structure.
2850 @retval EFI_SUCCESS The function completed successfully.
2854 InitializeCurrentSetting (
2855 IN OUT FORM_BROWSER_FORMSET
*FormSet
2860 FORMSET_STORAGE
*Storage
;
2861 FORMSET_STORAGE
*StorageSrc
;
2862 FORMSET_STORAGE
*OldStorage
;
2863 FORM_BROWSER_FORM
*Form
;
2864 FORM_BROWSER_FORM
*Form2
;
2868 // Extract default from IFR binary
2870 Status
= ExtractFormSetDefault (FormSet
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2871 if (EFI_ERROR (Status
)) {
2876 // Request current settings from Configuration Driver
2878 Link
= GetFirstNode (&FormSet
->StorageListHead
);
2879 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
2880 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
2883 if (gOldFormSet
!= NULL
) {
2885 // Try to find the Storage in backup formset gOldFormSet
2887 Link2
= GetFirstNode (&gOldFormSet
->StorageListHead
);
2888 while (!IsNull (&gOldFormSet
->StorageListHead
, Link2
)) {
2889 StorageSrc
= FORMSET_STORAGE_FROM_LINK (Link2
);
2891 if (StorageSrc
->VarStoreId
== Storage
->VarStoreId
) {
2892 OldStorage
= StorageSrc
;
2896 Link2
= GetNextNode (&gOldFormSet
->StorageListHead
, Link2
);
2900 if (OldStorage
== NULL
) {
2902 // Storage is not found in backup formset, request it from ConfigDriver
2904 Status
= LoadStorage (FormSet
, Storage
);
2906 // Now Edit Buffer is filled with default values(lower priority) and current
2907 // settings(higher priority), sychronize it to shadow Buffer
2909 if (!EFI_ERROR (Status
)) {
2910 SynchronizeStorage (Storage
);
2914 // Storage found in backup formset, use it
2916 Status
= CopyStorage (Storage
, OldStorage
);
2919 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
2923 // If has old formset, get the old nv update status.
2925 if (gOldFormSet
!= NULL
) {
2926 Link
= GetFirstNode (&FormSet
->FormListHead
);
2927 while (!IsNull (&FormSet
->FormListHead
, Link
)) {
2928 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
2930 Link2
= GetFirstNode (&gOldFormSet
->FormListHead
);
2931 while (!IsNull (&gOldFormSet
->FormListHead
, Link2
)) {
2932 Form2
= FORM_BROWSER_FORM_FROM_LINK (Link2
);
2934 if (Form
->FormId
== Form2
->FormId
) {
2935 Form
->NvUpdateRequired
= Form2
->NvUpdateRequired
;
2939 Link2
= GetNextNode (&gOldFormSet
->FormListHead
, Link2
);
2941 Link
= GetNextNode (&FormSet
->FormListHead
, Link
);
2950 Fetch the Ifr binary data of a FormSet.
2952 @param Handle PackageList Handle
2953 @param FormSetGuid On input, GUID or class GUID of a formset. If not
2954 specified (NULL or zero GUID), take the first
2955 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
2956 found in package list.
2957 On output, GUID of the formset found(if not NULL).
2958 @param BinaryLength The length of the FormSet IFR binary.
2959 @param BinaryData The buffer designed to receive the FormSet.
2961 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2962 BufferLength was updated.
2963 @retval EFI_INVALID_PARAMETER The handle is unknown.
2964 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2965 be found with the requested FormId.
2970 IN EFI_HII_HANDLE Handle
,
2971 IN OUT EFI_GUID
*FormSetGuid
,
2972 OUT UINTN
*BinaryLength
,
2973 OUT UINT8
**BinaryData
2977 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2983 UINT32 PackageListLength
;
2984 EFI_HII_PACKAGE_HEADER PackageHeader
;
2986 UINT8 NumberOfClassGuid
;
2987 BOOLEAN ClassGuidMatch
;
2988 EFI_GUID
*ClassGuid
;
2989 EFI_GUID
*ComparingGuid
;
2993 ZeroMem (&PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
2996 // if FormSetGuid is NULL or zero GUID, return first Setup FormSet in the package list
2998 if (FormSetGuid
== NULL
|| CompareGuid (FormSetGuid
, &gZeroGuid
)) {
2999 ComparingGuid
= &gEfiHiiPlatformSetupFormsetGuid
;
3001 ComparingGuid
= FormSetGuid
;
3005 // Get HII PackageList
3008 HiiPackageList
= NULL
;
3009 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
3010 if (Status
== EFI_BUFFER_TOO_SMALL
) {
3011 HiiPackageList
= AllocatePool (BufferSize
);
3012 ASSERT (HiiPackageList
!= NULL
);
3014 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
3016 if (EFI_ERROR (Status
)) {
3019 ASSERT (HiiPackageList
!= NULL
);
3022 // Get Form package from this HII package List
3024 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3026 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
3028 ClassGuidMatch
= FALSE
;
3029 while (Offset
< PackageListLength
) {
3030 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
3031 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3033 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
3035 // Search FormSet in this Form Package
3037 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
3038 while (Offset2
< PackageHeader
.Length
) {
3039 OpCodeData
= Package
+ Offset2
;
3041 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
3043 // Try to compare against formset GUID
3045 if (CompareGuid (ComparingGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
3049 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
3051 // Try to compare against formset class GUID
3053 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
3054 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
3055 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
3056 if (CompareGuid (ComparingGuid
, ClassGuid
+ Index
)) {
3057 ClassGuidMatch
= TRUE
;
3061 if (ClassGuidMatch
) {
3064 } else if (ComparingGuid
== &gEfiHiiPlatformSetupFormsetGuid
) {
3065 ClassGuidMatch
= TRUE
;
3070 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
3073 if (Offset2
< PackageHeader
.Length
) {
3075 // Target formset found
3081 Offset
+= PackageHeader
.Length
;
3084 if (Offset
>= PackageListLength
) {
3086 // Form package not found in this Package List
3088 FreePool (HiiPackageList
);
3089 return EFI_NOT_FOUND
;
3092 if (ClassGuidMatch
&& (FormSetGuid
!= NULL
)) {
3094 // Return the FormSet GUID
3096 CopyMem (FormSetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
3100 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
3101 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
3102 // of the Form Package.
3104 *BinaryLength
= PackageHeader
.Length
- Offset2
;
3105 *BinaryData
= AllocateCopyPool (*BinaryLength
, OpCodeData
);
3107 FreePool (HiiPackageList
);
3109 if (*BinaryData
== NULL
) {
3110 return EFI_OUT_OF_RESOURCES
;
3118 Initialize the internal data structure of a FormSet.
3120 @param Handle PackageList Handle
3121 @param FormSetGuid On input, GUID or class GUID of a formset. If not
3122 specified (NULL or zero GUID), take the first
3123 FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
3124 found in package list.
3125 On output, GUID of the formset found(if not NULL).
3126 @param FormSet FormSet data structure.
3128 @retval EFI_SUCCESS The function completed successfully.
3129 @retval EFI_NOT_FOUND The specified FormSet could not be found.
3134 IN EFI_HII_HANDLE Handle
,
3135 IN OUT EFI_GUID
*FormSetGuid
,
3136 OUT FORM_BROWSER_FORMSET
*FormSet
3140 EFI_HANDLE DriverHandle
;
3143 Status
= GetIfrBinaryData (Handle
, FormSetGuid
, &FormSet
->IfrBinaryLength
, &FormSet
->IfrBinaryData
);
3144 if (EFI_ERROR (Status
)) {
3148 FormSet
->HiiHandle
= Handle
;
3149 CopyMem (&FormSet
->Guid
, FormSetGuid
, sizeof (EFI_GUID
));
3152 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
3154 Status
= mHiiDatabase
->GetPackageListHandle (mHiiDatabase
, Handle
, &DriverHandle
);
3155 if (EFI_ERROR (Status
)) {
3158 FormSet
->DriverHandle
= DriverHandle
;
3159 Status
= gBS
->HandleProtocol (
3161 &gEfiHiiConfigAccessProtocolGuid
,
3162 (VOID
**) &FormSet
->ConfigAccess
3164 if (EFI_ERROR (Status
)) {
3166 // Configuration Driver don't attach ConfigAccess protocol to its HII package
3167 // list, then there will be no configuration action required
3169 FormSet
->ConfigAccess
= NULL
;
3173 // Parse the IFR binary OpCodes
3175 Status
= ParseOpCodes (FormSet
);
3176 if (EFI_ERROR (Status
)) {
3181 // Set VFR type by FormSet SubClass field
3183 gClassOfVfr
= FORMSET_CLASS_PLATFORM_SETUP
;
3184 if (FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
) {
3185 gClassOfVfr
= FORMSET_CLASS_FRONT_PAGE
;
3189 // Set VFR type by FormSet class guid
3191 for (Index
= 0; Index
< 3; Index
++) {
3192 if (CompareGuid (&FormSet
->ClassGuid
[Index
], &gEfiHiiPlatformSetupFormsetGuid
)) {
3193 gClassOfVfr
|= FORMSET_CLASS_PLATFORM_SETUP
;
3198 if ((gClassOfVfr
& FORMSET_CLASS_FRONT_PAGE
) == FORMSET_CLASS_FRONT_PAGE
) {
3199 gFrontPageHandle
= FormSet
->HiiHandle
;
3203 // Match GUID to find out the function key setting. If match fail, use the default setting.
3205 for (Index
= 0; Index
< sizeof (gFunctionKeySettingTable
) / sizeof (FUNCTIION_KEY_SETTING
); Index
++) {
3206 if (CompareGuid (&FormSet
->Guid
, &(gFunctionKeySettingTable
[Index
].FormSetGuid
))) {
3208 // Update the function key setting.
3210 gFunctionKeySetting
= gFunctionKeySettingTable
[Index
].KeySetting
;
3212 // Function key prompt can not be displayed if the function key has been disabled.
3214 if ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
) {
3215 gFunctionNineString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
3218 if ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
) {
3219 gFunctionTenString
= GetToken (STRING_TOKEN (EMPTY_STRING
), gHiiHandle
);
3229 Save globals used by previous call to SendForm(). SendForm() may be called from
3230 HiiConfigAccess.Callback(), this will cause SendForm() be reentried.
3231 So, save globals of previous call to SendForm() and restore them upon exit.
3235 SaveBrowserContext (
3239 BROWSER_CONTEXT
*Context
;
3241 gBrowserContextCount
++;
3242 if (gBrowserContextCount
== 1) {
3244 // This is not reentry of SendForm(), no context to save
3249 Context
= AllocatePool (sizeof (BROWSER_CONTEXT
));
3250 ASSERT (Context
!= NULL
);
3252 Context
->Signature
= BROWSER_CONTEXT_SIGNATURE
;
3255 // Save FormBrowser context
3257 Context
->BannerData
= gBannerData
;
3258 Context
->ClassOfVfr
= gClassOfVfr
;
3259 Context
->FunctionKeySetting
= gFunctionKeySetting
;
3260 Context
->ResetRequired
= gResetRequired
;
3261 Context
->Direction
= gDirection
;
3262 Context
->FunctionNineString
= gFunctionNineString
;
3263 Context
->FunctionTenString
= gFunctionTenString
;
3264 Context
->EnterString
= gEnterString
;
3265 Context
->EnterCommitString
= gEnterCommitString
;
3266 Context
->EnterEscapeString
= gEnterEscapeString
;
3267 Context
->EscapeString
= gEscapeString
;
3268 Context
->SaveFailed
= gSaveFailed
;
3269 Context
->MoveHighlight
= gMoveHighlight
;
3270 Context
->MakeSelection
= gMakeSelection
;
3271 Context
->DecNumericInput
= gDecNumericInput
;
3272 Context
->HexNumericInput
= gHexNumericInput
;
3273 Context
->ToggleCheckBox
= gToggleCheckBox
;
3274 Context
->PromptForData
= gPromptForData
;
3275 Context
->PromptForPassword
= gPromptForPassword
;
3276 Context
->PromptForNewPassword
= gPromptForNewPassword
;
3277 Context
->ConfirmPassword
= gConfirmPassword
;
3278 Context
->ConfirmError
= gConfirmError
;
3279 Context
->PassowordInvalid
= gPassowordInvalid
;
3280 Context
->PressEnter
= gPressEnter
;
3281 Context
->EmptyString
= gEmptyString
;
3282 Context
->AreYouSure
= gAreYouSure
;
3283 Context
->YesResponse
= gYesResponse
;
3284 Context
->NoResponse
= gNoResponse
;
3285 Context
->MiniString
= gMiniString
;
3286 Context
->PlusString
= gPlusString
;
3287 Context
->MinusString
= gMinusString
;
3288 Context
->AdjustNumber
= gAdjustNumber
;
3289 Context
->SaveChanges
= gSaveChanges
;
3290 Context
->OptionMismatch
= gOptionMismatch
;
3291 Context
->FormSuppress
= gFormSuppress
;
3292 Context
->PromptBlockWidth
= gPromptBlockWidth
;
3293 Context
->OptionBlockWidth
= gOptionBlockWidth
;
3294 Context
->HelpBlockWidth
= gHelpBlockWidth
;
3295 Context
->OldFormSet
= gOldFormSet
;
3296 Context
->MenuRefreshHead
= gMenuRefreshHead
;
3298 CopyMem (&Context
->ScreenDimensions
, &gScreenDimensions
, sizeof (gScreenDimensions
));
3299 CopyMem (&Context
->MenuOption
, &gMenuOption
, sizeof (gMenuOption
));
3302 // Insert to FormBrowser context list
3304 InsertHeadList (&gBrowserContextList
, &Context
->Link
);
3309 Restore globals used by previous call to SendForm().
3313 RestoreBrowserContext (
3318 BROWSER_CONTEXT
*Context
;
3320 ASSERT (gBrowserContextCount
!= 0);
3321 gBrowserContextCount
--;
3322 if (gBrowserContextCount
== 0) {
3324 // This is not reentry of SendForm(), no context to restore
3329 ASSERT (!IsListEmpty (&gBrowserContextList
));
3331 Link
= GetFirstNode (&gBrowserContextList
);
3332 Context
= BROWSER_CONTEXT_FROM_LINK (Link
);
3335 // Restore FormBrowser context
3337 gBannerData
= Context
->BannerData
;
3338 gClassOfVfr
= Context
->ClassOfVfr
;
3339 gFunctionKeySetting
= Context
->FunctionKeySetting
;
3340 gResetRequired
= Context
->ResetRequired
;
3341 gDirection
= Context
->Direction
;
3342 gFunctionNineString
= Context
->FunctionNineString
;
3343 gFunctionTenString
= Context
->FunctionTenString
;
3344 gEnterString
= Context
->EnterString
;
3345 gEnterCommitString
= Context
->EnterCommitString
;
3346 gEnterEscapeString
= Context
->EnterEscapeString
;
3347 gEscapeString
= Context
->EscapeString
;
3348 gSaveFailed
= Context
->SaveFailed
;
3349 gMoveHighlight
= Context
->MoveHighlight
;
3350 gMakeSelection
= Context
->MakeSelection
;
3351 gDecNumericInput
= Context
->DecNumericInput
;
3352 gHexNumericInput
= Context
->HexNumericInput
;
3353 gToggleCheckBox
= Context
->ToggleCheckBox
;
3354 gPromptForData
= Context
->PromptForData
;
3355 gPromptForPassword
= Context
->PromptForPassword
;
3356 gPromptForNewPassword
= Context
->PromptForNewPassword
;
3357 gConfirmPassword
= Context
->ConfirmPassword
;
3358 gConfirmError
= Context
->ConfirmError
;
3359 gPassowordInvalid
= Context
->PassowordInvalid
;
3360 gPressEnter
= Context
->PressEnter
;
3361 gEmptyString
= Context
->EmptyString
;
3362 gAreYouSure
= Context
->AreYouSure
;
3363 gYesResponse
= Context
->YesResponse
;
3364 gNoResponse
= Context
->NoResponse
;
3365 gMiniString
= Context
->MiniString
;
3366 gPlusString
= Context
->PlusString
;
3367 gMinusString
= Context
->MinusString
;
3368 gAdjustNumber
= Context
->AdjustNumber
;
3369 gSaveChanges
= Context
->SaveChanges
;
3370 gOptionMismatch
= Context
->OptionMismatch
;
3371 gFormSuppress
= Context
->FormSuppress
;
3372 gPromptBlockWidth
= Context
->PromptBlockWidth
;
3373 gOptionBlockWidth
= Context
->OptionBlockWidth
;
3374 gHelpBlockWidth
= Context
->HelpBlockWidth
;
3375 gOldFormSet
= Context
->OldFormSet
;
3376 gMenuRefreshHead
= Context
->MenuRefreshHead
;
3378 CopyMem (&gScreenDimensions
, &Context
->ScreenDimensions
, sizeof (gScreenDimensions
));
3379 CopyMem (&gMenuOption
, &Context
->MenuOption
, sizeof (gMenuOption
));
3382 // Remove from FormBrowser context list
3384 RemoveEntryList (&Context
->Link
);
3385 gBS
->FreePool (Context
);