]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
Add comments to MdeModulePkg.dec, Correct minor comments for other files and Add...
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Setup.c
1 /** @file
2 Entry and initialization module for the browser.
3
4 Copyright (c) 2007 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
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.
12
13 **/
14
15 #include "Setup.h"
16 #include "Ui.h"
17
18
19 SETUP_DRIVER_PRIVATE_DATA mPrivateData = {
20 SETUP_DRIVER_SIGNATURE,
21 NULL,
22 {
23 SendForm,
24 BrowserCallback
25 },
26 {
27 UnicodeVSPrint
28 }
29 };
30
31 EFI_HII_DATABASE_PROTOCOL *mHiiDatabase;
32 EFI_HII_STRING_PROTOCOL *mHiiString;
33 EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting;
34
35 BANNER_DATA *BannerData;
36 EFI_HII_HANDLE FrontPageHandle;
37 UINTN gClassOfVfr;
38 UINTN gFunctionKeySetting;
39 BOOLEAN gResetRequired;
40 BOOLEAN gNvUpdateRequired;
41 EFI_HII_HANDLE gHiiHandle;
42 BOOLEAN gFirstIn;
43 UINT16 gDirection;
44 EFI_SCREEN_DESCRIPTOR gScreenDimensions;
45 BOOLEAN gUpArrow;
46 BOOLEAN gDownArrow;
47
48 //
49 // Browser Global Strings
50 //
51 CHAR16 *gFunctionOneString;
52 CHAR16 *gFunctionTwoString;
53 CHAR16 *gFunctionNineString;
54 CHAR16 *gFunctionTenString;
55 CHAR16 *gEnterString;
56 CHAR16 *gEnterCommitString;
57 CHAR16 *gEscapeString;
58 CHAR16 *gSaveFailed;
59 CHAR16 *gMoveHighlight;
60 CHAR16 *gMakeSelection;
61 CHAR16 *gDecNumericInput;
62 CHAR16 *gHexNumericInput;
63 CHAR16 *gToggleCheckBox;
64 CHAR16 *gPromptForData;
65 CHAR16 *gPromptForPassword;
66 CHAR16 *gPromptForNewPassword;
67 CHAR16 *gConfirmPassword;
68 CHAR16 *gConfirmError;
69 CHAR16 *gPassowordInvalid;
70 CHAR16 *gPressEnter;
71 CHAR16 *gEmptyString;
72 CHAR16 *gAreYouSure;
73 CHAR16 *gYesResponse;
74 CHAR16 *gNoResponse;
75 CHAR16 *gMiniString;
76 CHAR16 *gPlusString;
77 CHAR16 *gMinusString;
78 CHAR16 *gAdjustNumber;
79
80 CHAR16 gPromptBlockWidth;
81 CHAR16 gOptionBlockWidth;
82 CHAR16 gHelpBlockWidth;
83
84 EFI_GUID gZeroGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
85 EFI_GUID gSetupBrowserGuid = {
86 0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
87 };
88
89 FUNCTIION_KEY_SETTING gFunctionKeySettingTable[] = {
90 //
91 // Boot Manager
92 //
93 {
94 {
95 0x847bc3fe,
96 0xb974,
97 0x446d,
98 {
99 0x94,
100 0x49,
101 0x5a,
102 0xd5,
103 0x41,
104 0x2e,
105 0x99,
106 0x3b
107 }
108 },
109 NONE_FUNCTION_KEY_SETTING
110 },
111 //
112 // Device Manager
113 //
114 {
115 {
116 0x3ebfa8e6,
117 0x511d,
118 0x4b5b,
119 {
120 0xa9,
121 0x5f,
122 0xfb,
123 0x38,
124 0x26,
125 0xf,
126 0x1c,
127 0x27
128 }
129 },
130 NONE_FUNCTION_KEY_SETTING
131 },
132 //
133 // BMM FormSet.
134 //
135 {
136 {
137 0x642237c7,
138 0x35d4,
139 0x472d,
140 {
141 0x83,
142 0x65,
143 0x12,
144 0xe0,
145 0xcc,
146 0xf2,
147 0x7a,
148 0x22
149 }
150 },
151 NONE_FUNCTION_KEY_SETTING
152 },
153 //
154 // BMM File Explorer FormSet.
155 //
156 {
157 {
158 0x1f2d63e1,
159 0xfebd,
160 0x4dc7,
161 {
162 0x9c,
163 0xc5,
164 0xba,
165 0x2b,
166 0x1c,
167 0xef,
168 0x9c,
169 0x5b
170 }
171 },
172 NONE_FUNCTION_KEY_SETTING
173 },
174 };
175
176 /**
177 This is the routine which an external caller uses to direct the browser
178 where to obtain it's information.
179
180
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
193 characters.
194 @param ActionRequest Points to the action recommended by the form.
195
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.
199
200 **/
201 EFI_STATUS
202 EFIAPI
203 SendForm (
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
211 )
212 {
213 EFI_STATUS Status;
214 UI_MENU_SELECTION *Selection;
215 UINTN Index;
216 FORM_BROWSER_FORMSET *FormSet;
217
218 Status = EFI_SUCCESS;
219 ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
220
221 //
222 // Seed the dimensions in the global
223 //
224 gST->ConOut->QueryMode (
225 gST->ConOut,
226 gST->ConOut->Mode->Mode,
227 &gScreenDimensions.RightColumn,
228 &gScreenDimensions.BottomRow
229 );
230
231 if (ScreenDimensions != NULL) {
232 //
233 // Check local dimension vs. global dimension.
234 //
235 if ((gScreenDimensions.RightColumn < ScreenDimensions->RightColumn) ||
236 (gScreenDimensions.BottomRow < ScreenDimensions->BottomRow)
237 ) {
238 return EFI_INVALID_PARAMETER;
239 } else {
240 //
241 // Local dimension validation.
242 //
243 if ((ScreenDimensions->RightColumn > ScreenDimensions->LeftColumn) &&
244 (ScreenDimensions->BottomRow > ScreenDimensions->TopRow) &&
245 ((ScreenDimensions->RightColumn - ScreenDimensions->LeftColumn) > 2) &&
246 (
247 (ScreenDimensions->BottomRow - ScreenDimensions->TopRow) > STATUS_BAR_HEIGHT +
248 SCROLL_ARROW_HEIGHT *
249 2 +
250 FRONT_PAGE_HEADER_HEIGHT +
251 FOOTER_HEIGHT +
252 1
253 )
254 ) {
255 CopyMem (&gScreenDimensions, (VOID *) ScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
256 } else {
257 return EFI_INVALID_PARAMETER;
258 }
259 }
260 }
261
262 gOptionBlockWidth = (CHAR16) ((gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3);
263 gHelpBlockWidth = gOptionBlockWidth;
264 gPromptBlockWidth = gOptionBlockWidth;
265
266 //
267 // Initialize the strings for the browser, upon exit of the browser, the strings will be freed
268 //
269 InitializeBrowserStrings ();
270
271 gFunctionKeySetting = DEFAULT_FUNCTION_KEY_SETTING;
272 gClassOfVfr = EFI_SETUP_APPLICATION_SUBCLASS;
273
274 //
275 // Ensure we are in Text mode
276 //
277 if (gFirstIn) {
278 gFirstIn = FALSE;
279 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
280 DisableQuietBoot ();
281 }
282
283 for (Index = 0; Index < HandleCount; Index++) {
284 Selection = AllocateZeroPool (sizeof (UI_MENU_SELECTION));
285 ASSERT (Selection != NULL);
286
287 Selection->Handle = Handles[Index];
288 if (FormSetGuid != NULL) {
289 CopyMem (&Selection->FormSetGuid, FormSetGuid, sizeof (EFI_GUID));
290 Selection->FormId = FormId;
291 }
292
293 do {
294 FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));
295 ASSERT (FormSet != NULL);
296
297 //
298 // Initialize internal data structures of FormSet
299 //
300 Status = InitializeFormSet (Selection->Handle, &Selection->FormSetGuid, FormSet);
301 if (EFI_ERROR (Status)) {
302 DestroyFormSet (FormSet);
303 break;
304 }
305 Selection->FormSet = FormSet;
306
307 //
308 // Initialize current settings of Questions in this FormSet
309 //
310 Status = InitializeCurrentSetting (FormSet);
311 if (EFI_ERROR (Status)) {
312 DestroyFormSet (FormSet);
313 break;
314 }
315
316 //
317 // Display this formset
318 //
319 gCurrentSelection = Selection;
320
321 Status = SetupBrowser (Selection);
322
323 gCurrentSelection = NULL;
324 DestroyFormSet (FormSet);
325
326 if (EFI_ERROR (Status)) {
327 break;
328 }
329
330 } while (Selection->Action == UI_ACTION_REFRESH_FORMSET);
331
332 gBS->FreePool (Selection);
333 }
334
335 if (ActionRequest != NULL) {
336 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
337 if (gResetRequired) {
338 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_RESET;
339 }
340 }
341
342 FreeBrowserStrings ();
343
344 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
345 gST->ConOut->ClearScreen (gST->ConOut);
346
347 return Status;
348 }
349
350
351 /**
352 This function is called by a callback handler to retrieve uncommitted state
353 data from the browser.
354
355 @param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
356 instance.
357 @param ResultsDataSize A pointer to the size of the buffer associated
358 with ResultsData.
359 @param ResultsData A string returned from an IFR browser or
360 equivalent. The results string will have no
361 routing information in them.
362 @param RetrieveData A BOOLEAN field which allows an agent to retrieve
363 (if RetrieveData = TRUE) data from the uncommitted
364 browser state information or set (if RetrieveData
365 = FALSE) data in the uncommitted browser state
366 information.
367 @param VariableGuid An optional field to indicate the target variable
368 GUID name to use.
369 @param VariableName An optional field to indicate the target
370 human-readable variable name.
371
372 @retval EFI_SUCCESS The results have been distributed or are awaiting
373 distribution.
374 @retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
375 contain the results data.
376
377 **/
378 EFI_STATUS
379 EFIAPI
380 BrowserCallback (
381 IN CONST EFI_FORM_BROWSER2_PROTOCOL *This,
382 IN OUT UINTN *ResultsDataSize,
383 IN OUT EFI_STRING ResultsData,
384 IN BOOLEAN RetrieveData,
385 IN CONST EFI_GUID *VariableGuid, OPTIONAL
386 IN CONST CHAR16 *VariableName OPTIONAL
387 )
388 {
389 EFI_STATUS Status;
390 LIST_ENTRY *Link;
391 FORMSET_STORAGE *Storage;
392 FORM_BROWSER_FORMSET *FormSet;
393 BOOLEAN Found;
394 CHAR16 *ConfigResp;
395 CHAR16 *StrPtr;
396 UINTN BufferSize;
397 UINTN TmpSize;
398
399 if (ResultsDataSize == NULL || ResultsData == NULL) {
400 return EFI_INVALID_PARAMETER;
401 }
402
403 if (gCurrentSelection == NULL) {
404 return EFI_NOT_READY;
405 }
406
407 Storage = NULL;
408 ConfigResp = NULL;
409 FormSet = gCurrentSelection->FormSet;
410
411 //
412 // Find target storage
413 //
414 Link = GetFirstNode (&FormSet->StorageListHead);
415 if (IsNull (&FormSet->StorageListHead, Link)) {
416 return EFI_UNSUPPORTED;
417 }
418
419 if (VariableGuid != NULL) {
420 //
421 // Try to find target storage
422 //
423 Found = FALSE;
424 while (!IsNull (&FormSet->StorageListHead, Link)) {
425 Storage = FORMSET_STORAGE_FROM_LINK (Link);
426 Link = GetNextNode (&FormSet->StorageListHead, Link);
427
428 if (CompareGuid (&Storage->Guid, (EFI_GUID *) VariableGuid)) {
429 if (Storage->Type == EFI_HII_VARSTORE_BUFFER) {
430 //
431 // Buffer storage require both GUID and Name
432 //
433 if (VariableName == NULL) {
434 return EFI_NOT_FOUND;
435 }
436
437 if (StrCmp (Storage->Name, (CHAR16 *) VariableName) != 0) {
438 continue;
439 }
440 }
441 Found = TRUE;
442 break;
443 }
444 }
445
446 if (!Found) {
447 return EFI_NOT_FOUND;
448 }
449 } else {
450 //
451 // GUID/Name is not specified, take the first storage in FormSet
452 //
453 Storage = FORMSET_STORAGE_FROM_LINK (Link);
454 }
455
456 if (RetrieveData) {
457 //
458 // Skip if there is no RequestElement
459 //
460 if (Storage->ElementCount == 0) {
461 return EFI_SUCCESS;
462 }
463
464 //
465 // Generate <ConfigResp>
466 //
467 Status = StorageToConfigResp (Storage, &ConfigResp);
468 if (EFI_ERROR (Status)) {
469 return Status;
470 }
471
472 //
473 // Skip <ConfigHdr> and '&' to point to <ConfigBody>
474 //
475 StrPtr = ConfigResp + StrLen (Storage->ConfigHdr) + 1;
476
477 BufferSize = StrSize (StrPtr);
478 if (*ResultsDataSize < BufferSize) {
479 *ResultsDataSize = BufferSize;
480
481 gBS->FreePool (ConfigResp);
482 return EFI_BUFFER_TOO_SMALL;
483 }
484
485 *ResultsDataSize = BufferSize;
486 CopyMem (ResultsData, StrPtr, BufferSize);
487
488 gBS->FreePool (ConfigResp);
489 } else {
490 //
491 // Prepare <ConfigResp>
492 //
493 TmpSize = StrLen (ResultsData);
494 BufferSize = (TmpSize + StrLen (Storage->ConfigHdr) + 2) * sizeof (CHAR16);
495 ConfigResp = AllocateZeroPool (BufferSize);
496 ASSERT (ConfigResp != NULL);
497
498 StrCpy (ConfigResp, Storage->ConfigHdr);
499 StrCat (ConfigResp, L"&");
500 StrCat (ConfigResp, ResultsData);
501
502 //
503 // Update Browser uncommited data
504 //
505 Status = ConfigRespToStorage (Storage, ConfigResp);
506 if (EFI_ERROR (Status)) {
507 return Status;
508 }
509 }
510
511 return EFI_SUCCESS;
512 }
513
514
515 /**
516 Initialize Setup Browser driver.
517
518 @param ImageHandle The image handle.
519 @param SystemTable The system table.
520
521 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
522 @return Other value if failed to initialize the Setup Browser module.
523
524 **/
525 EFI_STATUS
526 EFIAPI
527 InitializeSetup (
528 IN EFI_HANDLE ImageHandle,
529 IN EFI_SYSTEM_TABLE *SystemTable
530 )
531 {
532 EFI_STATUS Status;
533 EFI_HANDLE HiiDriverHandle;
534 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
535
536 //
537 // Locate required Hii relative protocols
538 //
539 Status = gBS->LocateProtocol (
540 &gEfiHiiDatabaseProtocolGuid,
541 NULL,
542 (VOID **) &mHiiDatabase
543 );
544 ASSERT_EFI_ERROR (Status);
545
546 Status = gBS->LocateProtocol (
547 &gEfiHiiStringProtocolGuid,
548 NULL,
549 (VOID **) &mHiiString
550 );
551 ASSERT_EFI_ERROR (Status);
552
553 Status = gBS->LocateProtocol (
554 &gEfiHiiConfigRoutingProtocolGuid,
555 NULL,
556 (VOID **) &mHiiConfigRouting
557 );
558 ASSERT_EFI_ERROR (Status);
559
560 //
561 // Publish our HII data
562 //
563 Status = HiiLibCreateHiiDriverHandle (&HiiDriverHandle);
564 ASSERT_EFI_ERROR (Status);
565
566 PackageList = HiiLibPreparePackageList (1, &gSetupBrowserGuid, SetupBrowserStrings);
567 ASSERT (PackageList != NULL);
568 Status = mHiiDatabase->NewPackageList (
569 mHiiDatabase,
570 PackageList,
571 HiiDriverHandle,
572 &gHiiHandle
573 );
574 ASSERT_EFI_ERROR (Status);
575
576 //
577 // Initialize Driver private data
578 //
579 gFirstIn = TRUE;
580 BannerData = AllocateZeroPool (sizeof (BANNER_DATA));
581 ASSERT (BannerData != NULL);
582
583 //
584 // Install FormBrowser2 protocol
585 //
586 mPrivateData.Handle = NULL;
587 Status = gBS->InstallProtocolInterface (
588 &mPrivateData.Handle,
589 &gEfiFormBrowser2ProtocolGuid,
590 EFI_NATIVE_INTERFACE,
591 &mPrivateData.FormBrowser2
592 );
593 ASSERT_EFI_ERROR (Status);
594
595 //
596 // Install Print protocol
597 //
598 Status = gBS->InstallProtocolInterface (
599 &mPrivateData.Handle,
600 &gEfiPrintProtocolGuid,
601 EFI_NATIVE_INTERFACE,
602 &mPrivateData.Print
603 );
604
605 return Status;
606 }
607
608
609 /**
610 Create a new string in HII Package List.
611
612 @param String The String to be added
613 @param HiiHandle The package list in the HII database to insert the
614 specified string.
615
616 @return The output string.
617
618 **/
619 EFI_STRING_ID
620 NewString (
621 IN CHAR16 *String,
622 IN EFI_HII_HANDLE HiiHandle
623 )
624 {
625 EFI_STRING_ID StringId;
626 EFI_STATUS Status;
627
628 StringId = 0;
629 Status = HiiLibNewString (HiiHandle, &StringId, String);
630 ASSERT_EFI_ERROR (Status);
631
632 return StringId;
633 }
634
635
636 /**
637 Delete a string from HII Package List.
638
639 @param StringId Id of the string in HII database.
640 @param HiiHandle The HII package list handle.
641
642 @retval EFI_SUCCESS The string was deleted successfully.
643
644 **/
645 EFI_STATUS
646 DeleteString (
647 IN EFI_STRING_ID StringId,
648 IN EFI_HII_HANDLE HiiHandle
649 )
650 {
651 CHAR16 NullChar;
652
653 NullChar = CHAR_NULL;
654 return HiiLibSetString (HiiHandle, StringId, &NullChar);
655 }
656
657
658 /**
659 Get the string based on the StringId and HII Package List Handle.
660
661 @param Token The String's ID.
662 @param HiiHandle The package list in the HII database to search for
663 the specified string.
664
665 @return The output string.
666
667 **/
668 CHAR16 *
669 GetToken (
670 IN EFI_STRING_ID Token,
671 IN EFI_HII_HANDLE HiiHandle
672 )
673 {
674 EFI_STATUS Status;
675 CHAR16 *String;
676 UINTN BufferLength;
677
678 //
679 // Set default string size assumption at no more than 256 bytes
680 //
681 BufferLength = 0x100;
682 String = AllocateZeroPool (BufferLength);
683 ASSERT (String != NULL);
684
685 Status = HiiLibGetString (HiiHandle, Token, String, &BufferLength);
686
687 if (Status == EFI_BUFFER_TOO_SMALL) {
688 gBS->FreePool (String);
689 String = AllocateZeroPool (BufferLength);
690 ASSERT (String != NULL);
691
692 Status = HiiLibGetString (HiiHandle, Token, String, &BufferLength);
693 }
694 ASSERT_EFI_ERROR (Status);
695
696 return String;
697 }
698
699
700 /**
701 Allocate new memory and then copy the Unicode string Source to Destination.
702
703 @param Dest Location to copy string
704 @param Src String to copy
705
706 **/
707 VOID
708 NewStringCpy (
709 IN OUT CHAR16 **Dest,
710 IN CHAR16 *Src
711 )
712 {
713 SafeFreePool (*Dest);
714 *Dest = AllocateCopyPool (StrSize (Src), Src);
715 ASSERT (*Dest != NULL);
716 }
717
718
719 /**
720 Allocate new memory and concatinate Source on the end of Destination.
721
722 @param Dest String to added to the end of.
723 @param Src String to concatinate.
724
725 **/
726 VOID
727 NewStringCat (
728 IN OUT CHAR16 **Dest,
729 IN CHAR16 *Src
730 )
731 {
732 CHAR16 *NewString;
733 UINTN TmpSize;
734
735 if (*Dest == NULL) {
736 NewStringCpy (Dest, Src);
737 return;
738 }
739
740 TmpSize = StrSize (*Dest);
741 NewString = AllocateZeroPool (TmpSize + StrSize (Src) - 1);
742 ASSERT (NewString != NULL);
743
744 StrCpy (NewString, *Dest);
745 StrCat (NewString, Src);
746
747 gBS->FreePool (*Dest);
748 *Dest = NewString;
749 }
750
751
752 /**
753 Synchronize Storage's Edit copy to Shadow copy.
754
755 @param Storage The Storage to be synchronized.
756
757 **/
758 VOID
759 SynchronizeStorage (
760 IN FORMSET_STORAGE *Storage
761 )
762 {
763 LIST_ENTRY *Link;
764 NAME_VALUE_NODE *Node;
765
766 switch (Storage->Type) {
767 case EFI_HII_VARSTORE_BUFFER:
768 CopyMem (Storage->Buffer, Storage->EditBuffer, Storage->Size);
769 break;
770
771 case EFI_HII_VARSTORE_NAME_VALUE:
772 Link = GetFirstNode (&Storage->NameValueListHead);
773 while (!IsNull (&Storage->NameValueListHead, Link)) {
774 Node = NAME_VALUE_NODE_FROM_LINK (Link);
775
776 NewStringCpy (&Node->Value, Node->EditValue);
777
778 Link = GetNextNode (&Storage->NameValueListHead, Link);
779 }
780 break;
781
782 case EFI_HII_VARSTORE_EFI_VARIABLE:
783 default:
784 break;
785 }
786 }
787
788
789 /**
790 Get Value for given Name from a NameValue Storage.
791
792 @param Storage The NameValue Storage.
793 @param Name The Name.
794 @param Value The retured Value.
795
796 @retval EFI_SUCCESS Value found for given Name.
797 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
798
799 **/
800 EFI_STATUS
801 GetValueByName (
802 IN FORMSET_STORAGE *Storage,
803 IN CHAR16 *Name,
804 IN OUT CHAR16 **Value
805 )
806 {
807 LIST_ENTRY *Link;
808 NAME_VALUE_NODE *Node;
809
810 *Value = NULL;
811
812 Link = GetFirstNode (&Storage->NameValueListHead);
813 while (!IsNull (&Storage->NameValueListHead, Link)) {
814 Node = NAME_VALUE_NODE_FROM_LINK (Link);
815
816 if (StrCmp (Name, Node->Name) == 0) {
817 NewStringCpy (Value, Node->EditValue);
818 return EFI_SUCCESS;
819 }
820
821 Link = GetNextNode (&Storage->NameValueListHead, Link);
822 }
823
824 return EFI_NOT_FOUND;
825 }
826
827
828 /**
829 Set Value of given Name in a NameValue Storage.
830
831 @param Storage The NameValue Storage.
832 @param Name The Name.
833 @param Value The Value to set.
834
835 @retval EFI_SUCCESS Value found for given Name.
836 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
837
838 **/
839 EFI_STATUS
840 SetValueByName (
841 IN FORMSET_STORAGE *Storage,
842 IN CHAR16 *Name,
843 IN CHAR16 *Value
844 )
845 {
846 LIST_ENTRY *Link;
847 NAME_VALUE_NODE *Node;
848
849 Link = GetFirstNode (&Storage->NameValueListHead);
850 while (!IsNull (&Storage->NameValueListHead, Link)) {
851 Node = NAME_VALUE_NODE_FROM_LINK (Link);
852
853 if (StrCmp (Name, Node->Name) == 0) {
854 SafeFreePool (Node->EditValue);
855 Node->EditValue = AllocateCopyPool (StrSize (Value), Value);
856 ASSERT (Node->EditValue != NULL);
857 return EFI_SUCCESS;
858 }
859
860 Link = GetNextNode (&Storage->NameValueListHead, Link);
861 }
862
863 return EFI_NOT_FOUND;
864 }
865
866
867 /**
868 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
869
870 @param Storage The Storage to be conveted.
871 @param ConfigResp The returned <ConfigResp>.
872
873 @retval EFI_SUCCESS Convert success.
874 @retval EFI_INVALID_PARAMETER Incorrect storage type.
875
876 **/
877 EFI_STATUS
878 StorageToConfigResp (
879 IN FORMSET_STORAGE *Storage,
880 IN CHAR16 **ConfigResp
881 )
882 {
883 EFI_STATUS Status;
884 EFI_STRING Progress;
885 LIST_ENTRY *Link;
886 NAME_VALUE_NODE *Node;
887
888 Status = EFI_SUCCESS;
889
890 switch (Storage->Type) {
891 case EFI_HII_VARSTORE_BUFFER:
892 Status = mHiiConfigRouting->BlockToConfig (
893 mHiiConfigRouting,
894 Storage->ConfigRequest,
895 Storage->EditBuffer,
896 Storage->Size,
897 ConfigResp,
898 &Progress
899 );
900 break;
901
902 case EFI_HII_VARSTORE_NAME_VALUE:
903 *ConfigResp = NULL;
904 NewStringCat (ConfigResp, Storage->ConfigHdr);
905
906 Link = GetFirstNode (&Storage->NameValueListHead);
907 while (!IsNull (&Storage->NameValueListHead, Link)) {
908 Node = NAME_VALUE_NODE_FROM_LINK (Link);
909
910 NewStringCat (ConfigResp, L"&");
911 NewStringCat (ConfigResp, Node->Name);
912 NewStringCat (ConfigResp, L"=");
913 NewStringCat (ConfigResp, Node->EditValue);
914
915 Link = GetNextNode (&Storage->NameValueListHead, Link);
916 }
917 break;
918
919 case EFI_HII_VARSTORE_EFI_VARIABLE:
920 default:
921 Status = EFI_INVALID_PARAMETER;
922 break;
923 }
924
925 return Status;
926 }
927
928
929 /**
930 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
931
932 @param Storage The Storage to receive the settings.
933 @param ConfigResp The <ConfigResp> to be converted.
934
935 @retval EFI_SUCCESS Convert success.
936 @retval EFI_INVALID_PARAMETER Incorrect storage type.
937
938 **/
939 EFI_STATUS
940 ConfigRespToStorage (
941 IN FORMSET_STORAGE *Storage,
942 IN CHAR16 *ConfigResp
943 )
944 {
945 EFI_STATUS Status;
946 EFI_STRING Progress;
947 UINTN BufferSize;
948 CHAR16 *StrPtr;
949 CHAR16 *Name;
950 CHAR16 *Value;
951
952 Status = EFI_SUCCESS;
953
954 switch (Storage->Type) {
955 case EFI_HII_VARSTORE_BUFFER:
956 BufferSize = Storage->Size;
957 Status = mHiiConfigRouting->ConfigToBlock (
958 mHiiConfigRouting,
959 ConfigResp,
960 Storage->EditBuffer,
961 &BufferSize,
962 &Progress
963 );
964 break;
965
966 case EFI_HII_VARSTORE_NAME_VALUE:
967 StrPtr = StrStr (ConfigResp, L"&");
968 while (StrPtr != NULL) {
969 //
970 // Skip '&'
971 //
972 StrPtr = StrPtr + 1;
973 Name = StrPtr;
974 StrPtr = StrStr (StrPtr, L"=");
975 if (StrPtr == NULL) {
976 break;
977 }
978 *StrPtr = 0;
979
980 //
981 // Skip '='
982 //
983 StrPtr = StrPtr + 1;
984 Value = StrPtr;
985 StrPtr = StrStr (StrPtr, L"&");
986 if (StrPtr != NULL) {
987 *StrPtr = 0;
988 }
989 SetValueByName (Storage, Name, Value);
990 }
991 break;
992
993 case EFI_HII_VARSTORE_EFI_VARIABLE:
994 default:
995 Status = EFI_INVALID_PARAMETER;
996 break;
997 }
998
999 return Status;
1000 }
1001
1002
1003 /**
1004 Get Question's current Value.
1005
1006 @param FormSet FormSet data structure.
1007 @param Form Form data structure.
1008 @param Question Question to be initialized.
1009 @param Cached TRUE: get from Edit copy FALSE: get from original
1010 Storage
1011
1012 @retval EFI_SUCCESS The function completed successfully.
1013
1014 **/
1015 EFI_STATUS
1016 GetQuestionValue (
1017 IN FORM_BROWSER_FORMSET *FormSet,
1018 IN FORM_BROWSER_FORM *Form,
1019 IN OUT FORM_BROWSER_STATEMENT *Question,
1020 IN BOOLEAN Cached
1021 )
1022 {
1023 EFI_STATUS Status;
1024 BOOLEAN Enabled;
1025 BOOLEAN Pending;
1026 UINT8 *Dst;
1027 UINTN StorageWidth;
1028 EFI_TIME EfiTime;
1029 FORMSET_STORAGE *Storage;
1030 EFI_IFR_TYPE_VALUE *QuestionValue;
1031 CHAR16 *ConfigRequest;
1032 CHAR16 *Progress;
1033 CHAR16 *Result;
1034 CHAR16 *Value;
1035 UINTN Length;
1036 BOOLEAN IsBufferStorage;
1037 BOOLEAN IsString;
1038
1039 Status = EFI_SUCCESS;
1040
1041 //
1042 // Statement don't have storage, skip them
1043 //
1044 if (Question->QuestionId == 0) {
1045 return Status;
1046 }
1047
1048 //
1049 // Question value is provided by an Expression, evaluate it
1050 //
1051 if (Question->ValueExpression != NULL) {
1052 Status = EvaluateExpression (FormSet, Form, Question->ValueExpression);
1053 if (!EFI_ERROR (Status)) {
1054 CopyMem (&Question->HiiValue, &Question->ValueExpression->Result, sizeof (EFI_HII_VALUE));
1055 }
1056 return Status;
1057 }
1058
1059 //
1060 // Question value is provided by RTC
1061 //
1062 Storage = Question->Storage;
1063 QuestionValue = &Question->HiiValue.Value;
1064 if (Storage == NULL) {
1065 //
1066 // It's a Question without storage, or RTC date/time
1067 //
1068 if (Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) {
1069 //
1070 // Date and time define the same Flags bit
1071 //
1072 switch (Question->Flags & EFI_QF_DATE_STORAGE) {
1073 case QF_DATE_STORAGE_TIME:
1074 Status = gRT->GetTime (&EfiTime, NULL);
1075 break;
1076
1077 case QF_DATE_STORAGE_WAKEUP:
1078 Status = gRT->GetWakeupTime (&Enabled, &Pending, &EfiTime);
1079 break;
1080
1081 case QF_DATE_STORAGE_NORMAL:
1082 default:
1083 //
1084 // For date/time without storage
1085 //
1086 return EFI_SUCCESS;
1087 }
1088
1089 if (EFI_ERROR (Status)) {
1090 return Status;
1091 }
1092
1093 if (Question->Operand == EFI_IFR_DATE_OP) {
1094 QuestionValue->date.Year = EfiTime.Year;
1095 QuestionValue->date.Month = EfiTime.Month;
1096 QuestionValue->date.Day = EfiTime.Day;
1097 } else {
1098 QuestionValue->time.Hour = EfiTime.Hour;
1099 QuestionValue->time.Minute = EfiTime.Minute;
1100 QuestionValue->time.Second = EfiTime.Second;
1101 }
1102 }
1103
1104 return EFI_SUCCESS;
1105 }
1106
1107 //
1108 // Question value is provided by EFI variable
1109 //
1110 StorageWidth = Question->StorageWidth;
1111 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1112 if (Question->BufferValue != NULL) {
1113 Dst = Question->BufferValue;
1114 } else {
1115 Dst = (UINT8 *) QuestionValue;
1116 }
1117
1118 Status = gRT->GetVariable (
1119 Question->VariableName,
1120 &Storage->Guid,
1121 NULL,
1122 &StorageWidth,
1123 Dst
1124 );
1125 //
1126 // Always return success, even this EFI variable doesn't exist
1127 //
1128 return EFI_SUCCESS;
1129 }
1130
1131 //
1132 // Question Value is provided by Buffer Storage or NameValue Storage
1133 //
1134 if (Question->BufferValue != NULL) {
1135 //
1136 // This Question is password or orderedlist
1137 //
1138 Dst = Question->BufferValue;
1139 } else {
1140 //
1141 // Other type of Questions
1142 //
1143 Dst = (UINT8 *) &Question->HiiValue.Value;
1144 }
1145
1146 IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);
1147 IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE);
1148 if (Cached) {
1149 if (IsBufferStorage) {
1150 //
1151 // Copy from storage Edit buffer
1152 //
1153 CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);
1154 } else {
1155 Status = GetValueByName (Storage, Question->VariableName, &Value);
1156 if (EFI_ERROR (Status)) {
1157 return Status;
1158 }
1159
1160 if (IsString) {
1161 //
1162 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1163 //
1164 Length = StorageWidth + sizeof (CHAR16);
1165 Status = ConfigStringToUnicode ((CHAR16 *) Dst, &Length, Value);
1166 } else {
1167 Status = HexStringToBuf (Dst, &StorageWidth, Value, NULL);
1168 }
1169
1170 gBS->FreePool (Value);
1171 }
1172 } else {
1173 //
1174 // Request current settings from Configuration Driver
1175 //
1176 if (FormSet->ConfigAccess == NULL) {
1177 return EFI_NOT_FOUND;
1178 }
1179
1180 //
1181 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1182 // <ConfigHdr> + "&" + <VariableName>
1183 //
1184 if (IsBufferStorage) {
1185 Length = StrLen (Storage->ConfigHdr);
1186 Length += StrLen (Question->BlockName);
1187 } else {
1188 Length = StrLen (Storage->ConfigHdr);
1189 Length += StrLen (Question->VariableName) + 1;
1190 }
1191 ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));
1192 ASSERT (ConfigRequest != NULL);
1193
1194 StrCpy (ConfigRequest, Storage->ConfigHdr);
1195 if (IsBufferStorage) {
1196 StrCat (ConfigRequest, Question->BlockName);
1197 } else {
1198 StrCat (ConfigRequest, L"&");
1199 StrCat (ConfigRequest, Question->VariableName);
1200 }
1201
1202 Status = FormSet->ConfigAccess->ExtractConfig (
1203 FormSet->ConfigAccess,
1204 ConfigRequest,
1205 &Progress,
1206 &Result
1207 );
1208 if (EFI_ERROR (Status)) {
1209 return Status;
1210 }
1211
1212 //
1213 // Skip <ConfigRequest>
1214 //
1215 Value = Result + Length;
1216 if (IsBufferStorage) {
1217 //
1218 // Skip "&VALUE"
1219 //
1220 Value = Value + 6;
1221 }
1222 if (*Value != '=') {
1223 gBS->FreePool (Result);
1224 return EFI_NOT_FOUND;
1225 }
1226 //
1227 // Skip '=', point to value
1228 //
1229 Value = Value + 1;
1230 if (!IsBufferStorage && IsString) {
1231 //
1232 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1233 //
1234 Length = StorageWidth + sizeof (CHAR16);
1235 Status = ConfigStringToUnicode ((CHAR16 *) Dst, &Length, Value);
1236 } else {
1237 Status = HexStringToBuf (Dst, &StorageWidth, Value, NULL);
1238 if (EFI_ERROR (Status)) {
1239 gBS->FreePool (Result);
1240 return Status;
1241 }
1242 }
1243
1244 //
1245 // Synchronize Edit Buffer
1246 //
1247 if (IsBufferStorage) {
1248 CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Dst, StorageWidth);
1249 } else {
1250 SetValueByName (Storage, Question->VariableName, Value);
1251 }
1252 gBS->FreePool (Result);
1253 }
1254
1255 return Status;
1256 }
1257
1258
1259 /**
1260 Save Question Value to edit copy(cached) or Storage(uncached).
1261
1262 @param FormSet FormSet data structure.
1263 @param Form Form data structure.
1264 @param Question Pointer to the Question.
1265 @param Cached TRUE: set to Edit copy FALSE: set to original
1266 Storage
1267
1268 @retval EFI_SUCCESS The function completed successfully.
1269
1270 **/
1271 EFI_STATUS
1272 SetQuestionValue (
1273 IN FORM_BROWSER_FORMSET *FormSet,
1274 IN FORM_BROWSER_FORM *Form,
1275 IN OUT FORM_BROWSER_STATEMENT *Question,
1276 IN BOOLEAN Cached
1277 )
1278 {
1279 EFI_STATUS Status;
1280 BOOLEAN Enabled;
1281 BOOLEAN Pending;
1282 UINT8 *Src;
1283 EFI_TIME EfiTime;
1284 UINTN BufferLen;
1285 UINTN StorageWidth;
1286 FORMSET_STORAGE *Storage;
1287 EFI_IFR_TYPE_VALUE *QuestionValue;
1288 CHAR16 *ConfigResp;
1289 CHAR16 *Progress;
1290 CHAR16 *Value;
1291 UINTN Length;
1292 BOOLEAN IsBufferStorage;
1293 BOOLEAN IsString;
1294
1295 Status = EFI_SUCCESS;
1296
1297 //
1298 // Statement don't have storage, skip them
1299 //
1300 if (Question->QuestionId == 0) {
1301 return Status;
1302 }
1303
1304 //
1305 // If Question value is provided by an Expression, then it is read only
1306 //
1307 if (Question->ValueExpression != NULL) {
1308 return Status;
1309 }
1310
1311 //
1312 // Question value is provided by RTC
1313 //
1314 Storage = Question->Storage;
1315 QuestionValue = &Question->HiiValue.Value;
1316 if (Storage == NULL) {
1317 //
1318 // It's a Question without storage, or RTC date/time
1319 //
1320 if (Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) {
1321 //
1322 // Date and time define the same Flags bit
1323 //
1324 switch (Question->Flags & EFI_QF_DATE_STORAGE) {
1325 case QF_DATE_STORAGE_TIME:
1326 Status = gRT->GetTime (&EfiTime, NULL);
1327 break;
1328
1329 case QF_DATE_STORAGE_WAKEUP:
1330 Status = gRT->GetWakeupTime (&Enabled, &Pending, &EfiTime);
1331 break;
1332
1333 case QF_DATE_STORAGE_NORMAL:
1334 default:
1335 //
1336 // For date/time without storage
1337 //
1338 return EFI_SUCCESS;
1339 }
1340
1341 if (EFI_ERROR (Status)) {
1342 return Status;
1343 }
1344
1345 if (Question->Operand == EFI_IFR_DATE_OP) {
1346 EfiTime.Year = QuestionValue->date.Year;
1347 EfiTime.Month = QuestionValue->date.Month;
1348 EfiTime.Day = QuestionValue->date.Day;
1349 } else {
1350 EfiTime.Hour = QuestionValue->time.Hour;
1351 EfiTime.Minute = QuestionValue->time.Minute;
1352 EfiTime.Second = QuestionValue->time.Second;
1353 }
1354
1355 if ((Question->Flags & EFI_QF_DATE_STORAGE) == QF_DATE_STORAGE_TIME) {
1356 Status = gRT->SetTime (&EfiTime);
1357 } else {
1358 Status = gRT->SetWakeupTime (TRUE, &EfiTime);
1359 }
1360 }
1361
1362 return Status;
1363 }
1364
1365 //
1366 // Question value is provided by EFI variable
1367 //
1368 StorageWidth = Question->StorageWidth;
1369 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1370 if (Question->BufferValue != NULL) {
1371 Src = Question->BufferValue;
1372 } else {
1373 Src = (UINT8 *) QuestionValue;
1374 }
1375
1376 Status = gRT->SetVariable (
1377 Question->VariableName,
1378 &Storage->Guid,
1379 Storage->Attributes,
1380 StorageWidth,
1381 Src
1382 );
1383 return Status;
1384 }
1385
1386 //
1387 // Question Value is provided by Buffer Storage or NameValue Storage
1388 //
1389 if (Question->BufferValue != NULL) {
1390 Src = Question->BufferValue;
1391 } else {
1392 Src = (UINT8 *) &Question->HiiValue.Value;
1393 }
1394
1395 IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);
1396 IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE);
1397 if (IsBufferStorage) {
1398 //
1399 // Copy to storage edit buffer
1400 //
1401 CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);
1402 } else {
1403 if (IsString) {
1404 //
1405 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1406 //
1407 Value = NULL;
1408 BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);
1409 Value = AllocateZeroPool (BufferLen);
1410 ASSERT (Value != NULL);
1411 Status = UnicodeToConfigString (Value, &BufferLen, (CHAR16 *) Src);
1412 ASSERT_EFI_ERROR (Status);
1413 } else {
1414 BufferLen = StorageWidth * 2 + 1;
1415 Value = AllocateZeroPool (BufferLen * sizeof (CHAR16));
1416 ASSERT (Value != NULL);
1417 BufToHexString (Value, &BufferLen, Src, StorageWidth);
1418 ToLower (Value);
1419 }
1420
1421 Status = SetValueByName (Storage, Question->VariableName, Value);
1422 gBS->FreePool (Value);
1423 }
1424
1425 if (!Cached) {
1426 //
1427 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1428 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1429 //
1430 if (IsBufferStorage) {
1431 Length = StrLen (Question->BlockName) + 7;
1432 } else {
1433 Length = StrLen (Question->VariableName) + 2;
1434 }
1435 if (!IsBufferStorage && IsString) {
1436 Length += (StrLen ((CHAR16 *) Src) * 4);
1437 } else {
1438 Length += (StorageWidth * 2);
1439 }
1440 ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));
1441 ASSERT (ConfigResp != NULL);
1442
1443 StrCpy (ConfigResp, Storage->ConfigHdr);
1444 if (IsBufferStorage) {
1445 StrCat (ConfigResp, Question->BlockName);
1446 StrCat (ConfigResp, L"&VALUE=");
1447 } else {
1448 StrCat (ConfigResp, L"&");
1449 StrCat (ConfigResp, Question->VariableName);
1450 StrCat (ConfigResp, L"=");
1451 }
1452
1453 Value = ConfigResp + StrLen (ConfigResp);
1454 if (!IsBufferStorage && IsString) {
1455 //
1456 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1457 //
1458 BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);
1459 Status = UnicodeToConfigString (Value, &BufferLen, (CHAR16 *) Src);
1460 ASSERT_EFI_ERROR (Status);
1461 } else {
1462 BufferLen = StorageWidth * 2 + 1;
1463 BufToHexString (Value, &BufferLen, Src, StorageWidth);
1464 ToLower (Value);
1465 }
1466
1467 //
1468 // Submit Question Value to Configuration Driver
1469 //
1470 if (FormSet->ConfigAccess != NULL) {
1471 Status = FormSet->ConfigAccess->RouteConfig (
1472 FormSet->ConfigAccess,
1473 ConfigResp,
1474 &Progress
1475 );
1476 if (EFI_ERROR (Status)) {
1477 gBS->FreePool (ConfigResp);
1478 return Status;
1479 }
1480 }
1481 gBS->FreePool (ConfigResp);
1482
1483 //
1484 // Synchronize shadow Buffer
1485 //
1486 SynchronizeStorage (Storage);
1487 }
1488
1489 return Status;
1490 }
1491
1492
1493 /**
1494 Perform inconsistent check for a Form.
1495
1496 @param FormSet FormSet data structure.
1497 @param Form Form data structure.
1498 @param Question The Question to be validated.
1499 @param Type Validation type: InConsistent or NoSubmit
1500
1501 @retval EFI_SUCCESS Form validation pass.
1502 @retval other Form validation failed.
1503
1504 **/
1505 EFI_STATUS
1506 ValidateQuestion (
1507 IN FORM_BROWSER_FORMSET *FormSet,
1508 IN FORM_BROWSER_FORM *Form,
1509 IN FORM_BROWSER_STATEMENT *Question,
1510 IN UINTN Type
1511 )
1512 {
1513 EFI_STATUS Status;
1514 LIST_ENTRY *Link;
1515 LIST_ENTRY *ListHead;
1516 EFI_STRING PopUp;
1517 EFI_INPUT_KEY Key;
1518 FORM_EXPRESSION *Expression;
1519
1520 if (Type == EFI_HII_EXPRESSION_INCONSISTENT_IF) {
1521 ListHead = &Question->InconsistentListHead;
1522 } else if (Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) {
1523 ListHead = &Question->NoSubmitListHead;
1524 } else {
1525 return EFI_UNSUPPORTED;
1526 }
1527
1528 Link = GetFirstNode (ListHead);
1529 while (!IsNull (ListHead, Link)) {
1530 Expression = FORM_EXPRESSION_FROM_LINK (Link);
1531
1532 //
1533 // Evaluate the expression
1534 //
1535 Status = EvaluateExpression (FormSet, Form, Expression);
1536 if (EFI_ERROR (Status)) {
1537 return Status;
1538 }
1539
1540 if (Expression->Result.Value.b) {
1541 //
1542 // Condition meet, show up error message
1543 //
1544 if (Expression->Error != 0) {
1545 PopUp = GetToken (Expression->Error, FormSet->HiiHandle);
1546 do {
1547 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, PopUp, gPressEnter, gEmptyString);
1548 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1549 gBS->FreePool (PopUp);
1550 }
1551
1552 return EFI_NOT_READY;
1553 }
1554
1555 Link = GetNextNode (ListHead, Link);
1556 }
1557
1558 return EFI_SUCCESS;
1559 }
1560
1561
1562 /**
1563 Perform NoSubmit check for a Form.
1564
1565 @param FormSet FormSet data structure.
1566 @param Form Form data structure.
1567
1568 @retval EFI_SUCCESS Form validation pass.
1569 @retval other Form validation failed.
1570
1571 **/
1572 EFI_STATUS
1573 NoSubmitCheck (
1574 IN FORM_BROWSER_FORMSET *FormSet,
1575 IN FORM_BROWSER_FORM *Form
1576 )
1577 {
1578 EFI_STATUS Status;
1579 LIST_ENTRY *Link;
1580 FORM_BROWSER_STATEMENT *Question;
1581
1582 Link = GetFirstNode (&Form->StatementListHead);
1583 while (!IsNull (&Form->StatementListHead, Link)) {
1584 Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1585
1586 Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_NO_SUBMIT_IF);
1587 if (EFI_ERROR (Status)) {
1588 return Status;
1589 }
1590
1591 Link = GetNextNode (&Form->StatementListHead, Link);
1592 }
1593
1594 return EFI_SUCCESS;
1595 }
1596
1597
1598 /**
1599 Submit a Form.
1600
1601 @param FormSet FormSet data structure.
1602 @param Form Form data structure.
1603
1604 @retval EFI_SUCCESS The function completed successfully.
1605
1606 **/
1607 EFI_STATUS
1608 SubmitForm (
1609 IN FORM_BROWSER_FORMSET *FormSet,
1610 IN FORM_BROWSER_FORM *Form
1611 )
1612 {
1613 EFI_STATUS Status;
1614 LIST_ENTRY *Link;
1615 EFI_STRING ConfigResp;
1616 EFI_STRING Progress;
1617 FORMSET_STORAGE *Storage;
1618
1619 //
1620 // Validate the Form by NoSubmit check
1621 //
1622 Status = NoSubmitCheck (FormSet, Form);
1623 if (EFI_ERROR (Status)) {
1624 return Status;
1625 }
1626
1627 //
1628 // Submit Buffer storage or Name/Value storage
1629 //
1630 Link = GetFirstNode (&FormSet->StorageListHead);
1631 while (!IsNull (&FormSet->StorageListHead, Link)) {
1632 Storage = FORMSET_STORAGE_FROM_LINK (Link);
1633 Link = GetNextNode (&FormSet->StorageListHead, Link);
1634
1635 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1636 continue;
1637 }
1638
1639 //
1640 // Skip if there is no RequestElement
1641 //
1642 if (Storage->ElementCount == 0) {
1643 continue;
1644 }
1645
1646 //
1647 // Prepare <ConfigResp>
1648 //
1649 Status = StorageToConfigResp (Storage, &ConfigResp);
1650 if (EFI_ERROR (Status)) {
1651 return Status;
1652 }
1653
1654 //
1655 // Send <ConfigResp> to Configuration Driver
1656 //
1657 if (FormSet->ConfigAccess != NULL) {
1658 Status = FormSet->ConfigAccess->RouteConfig (
1659 FormSet->ConfigAccess,
1660 ConfigResp,
1661 &Progress
1662 );
1663 if (EFI_ERROR (Status)) {
1664 gBS->FreePool (ConfigResp);
1665 return Status;
1666 }
1667 }
1668 gBS->FreePool (ConfigResp);
1669
1670 //
1671 // Config success, update storage shadow Buffer
1672 //
1673 SynchronizeStorage (Storage);
1674 }
1675
1676 gNvUpdateRequired = FALSE;
1677
1678 return EFI_SUCCESS;
1679 }
1680
1681
1682 /**
1683 Reset Question to its default value.
1684
1685 @param FormSet The form set.
1686 @param Form The form.
1687 @param Question The question.
1688 @param DefaultId The Class of the default.
1689
1690 @retval EFI_SUCCESS Question is reset to default value.
1691
1692 **/
1693 EFI_STATUS
1694 GetQuestionDefault (
1695 IN FORM_BROWSER_FORMSET *FormSet,
1696 IN FORM_BROWSER_FORM *Form,
1697 IN FORM_BROWSER_STATEMENT *Question,
1698 IN UINT16 DefaultId
1699 )
1700 {
1701 EFI_STATUS Status;
1702 LIST_ENTRY *Link;
1703 QUESTION_DEFAULT *Default;
1704 QUESTION_OPTION *Option;
1705 EFI_HII_VALUE *HiiValue;
1706 UINT8 Index;
1707
1708 Status = EFI_SUCCESS;
1709
1710 //
1711 // Statement don't have storage, skip them
1712 //
1713 if (Question->QuestionId == 0) {
1714 return Status;
1715 }
1716
1717 //
1718 // There are three ways to specify default value for a Question:
1719 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1720 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1721 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1722 //
1723 HiiValue = &Question->HiiValue;
1724
1725 //
1726 // EFI_IFR_DEFAULT has highest priority
1727 //
1728 if (!IsListEmpty (&Question->DefaultListHead)) {
1729 Link = GetFirstNode (&Question->DefaultListHead);
1730 while (!IsNull (&Question->DefaultListHead, Link)) {
1731 Default = QUESTION_DEFAULT_FROM_LINK (Link);
1732
1733 if (Default->DefaultId == DefaultId) {
1734 if (Default->ValueExpression != NULL) {
1735 //
1736 // Default is provided by an Expression, evaluate it
1737 //
1738 Status = EvaluateExpression (FormSet, Form, Default->ValueExpression);
1739 if (EFI_ERROR (Status)) {
1740 return Status;
1741 }
1742
1743 CopyMem (HiiValue, &Default->ValueExpression->Result, sizeof (EFI_HII_VALUE));
1744 } else {
1745 //
1746 // Default value is embedded in EFI_IFR_DEFAULT
1747 //
1748 CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE));
1749 }
1750
1751 return EFI_SUCCESS;
1752 }
1753
1754 Link = GetNextNode (&Question->DefaultListHead, Link);
1755 }
1756 }
1757
1758 //
1759 // EFI_ONE_OF_OPTION
1760 //
1761 if ((Question->Operand == EFI_IFR_ONE_OF_OP) && !IsListEmpty (&Question->OptionListHead)) {
1762 if (DefaultId <= EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
1763 //
1764 // OneOfOption could only provide Standard and Manufacturing default
1765 //
1766 Link = GetFirstNode (&Question->OptionListHead);
1767 while (!IsNull (&Question->OptionListHead, Link)) {
1768 Option = QUESTION_OPTION_FROM_LINK (Link);
1769
1770 if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT) != 0)) ||
1771 ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT_MFG) != 0))
1772 ) {
1773 CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));
1774
1775 return EFI_SUCCESS;
1776 }
1777
1778 Link = GetNextNode (&Question->OptionListHead, Link);
1779 }
1780 }
1781 }
1782
1783 //
1784 // EFI_IFR_CHECKBOX - lowest priority
1785 //
1786 if (Question->Operand == EFI_IFR_CHECKBOX_OP) {
1787 if (DefaultId <= EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
1788 //
1789 // Checkbox could only provide Standard and Manufacturing default
1790 //
1791 if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT) != 0)) ||
1792 ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) != 0))
1793 ) {
1794 HiiValue->Value.b = TRUE;
1795 } else {
1796 HiiValue->Value.b = FALSE;
1797 }
1798
1799 return EFI_SUCCESS;
1800 }
1801 }
1802
1803 //
1804 // For Questions without default
1805 //
1806 switch (Question->Operand) {
1807 case EFI_IFR_NUMERIC_OP:
1808 //
1809 // Take minimal value as numeric's default value
1810 //
1811 HiiValue->Value.u64 = Question->Minimum;
1812 break;
1813
1814 case EFI_IFR_ONE_OF_OP:
1815 //
1816 // Take first oneof option as oneof's default value
1817 //
1818 Link = GetFirstNode (&Question->OptionListHead);
1819 if (!IsNull (&Question->OptionListHead, Link)) {
1820 Option = QUESTION_OPTION_FROM_LINK (Link);
1821 CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));
1822 }
1823 break;
1824
1825 case EFI_IFR_ORDERED_LIST_OP:
1826 //
1827 // Take option sequence in IFR as ordered list's default value
1828 //
1829 Index = 0;
1830 Link = GetFirstNode (&Question->OptionListHead);
1831 while (!IsNull (&Question->OptionListHead, Link)) {
1832 Option = QUESTION_OPTION_FROM_LINK (Link);
1833
1834 Question->BufferValue[Index] = Option->Value.Value.u8;
1835
1836 Index++;
1837 if (Index >= Question->MaxContainers) {
1838 break;
1839 }
1840
1841 Link = GetNextNode (&Question->OptionListHead, Link);
1842 }
1843 break;
1844
1845 default:
1846 Status = EFI_NOT_FOUND;
1847 break;
1848 }
1849
1850 return Status;
1851 }
1852
1853
1854 /**
1855 Reset Questions in a Form to their default value.
1856
1857 @param FormSet FormSet data structure.
1858 @param Form The Form which to be reset.
1859 @param DefaultId The Class of the default.
1860
1861 @retval EFI_SUCCESS The function completed successfully.
1862
1863 **/
1864 EFI_STATUS
1865 ExtractFormDefault (
1866 IN FORM_BROWSER_FORMSET *FormSet,
1867 IN FORM_BROWSER_FORM *Form,
1868 IN UINT16 DefaultId
1869 )
1870 {
1871 EFI_STATUS Status;
1872 LIST_ENTRY *Link;
1873 FORM_BROWSER_STATEMENT *Question;
1874
1875 Link = GetFirstNode (&Form->StatementListHead);
1876 while (!IsNull (&Form->StatementListHead, Link)) {
1877 Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1878 Link = GetNextNode (&Form->StatementListHead, Link);
1879
1880 //
1881 // Reset Question to its default value
1882 //
1883 Status = GetQuestionDefault (FormSet, Form, Question, DefaultId);
1884 if (EFI_ERROR (Status)) {
1885 continue;
1886 }
1887
1888 //
1889 // Synchronize Buffer storage's Edit buffer
1890 //
1891 if ((Question->Storage != NULL) &&
1892 (Question->Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE)) {
1893 SetQuestionValue (FormSet, Form, Question, TRUE);
1894 }
1895 }
1896
1897 return EFI_SUCCESS;
1898 }
1899
1900
1901 /**
1902 Initialize Question's Edit copy from Storage.
1903
1904 @param FormSet FormSet data structure.
1905 @param Form Form data structure.
1906
1907 @retval EFI_SUCCESS The function completed successfully.
1908
1909 **/
1910 EFI_STATUS
1911 LoadFormConfig (
1912 IN FORM_BROWSER_FORMSET *FormSet,
1913 IN FORM_BROWSER_FORM *Form
1914 )
1915 {
1916 EFI_STATUS Status;
1917 LIST_ENTRY *Link;
1918 FORM_BROWSER_STATEMENT *Question;
1919
1920 Link = GetFirstNode (&Form->StatementListHead);
1921 while (!IsNull (&Form->StatementListHead, Link)) {
1922 Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1923
1924 //
1925 // Initialize local copy of Value for each Question
1926 //
1927 Status = GetQuestionValue (FormSet, Form, Question, TRUE);
1928 if (EFI_ERROR (Status)) {
1929 return Status;
1930 }
1931
1932 Link = GetNextNode (&Form->StatementListHead, Link);
1933 }
1934
1935 return EFI_SUCCESS;
1936 }
1937
1938
1939 /**
1940 Fill storage's edit copy with settings requested from Configuration Driver.
1941
1942 @param FormSet FormSet data structure.
1943 @param Storage Buffer Storage.
1944
1945 @retval EFI_SUCCESS The function completed successfully.
1946
1947 **/
1948 EFI_STATUS
1949 LoadStorage (
1950 IN FORM_BROWSER_FORMSET *FormSet,
1951 IN FORMSET_STORAGE *Storage
1952 )
1953 {
1954 EFI_STATUS Status;
1955 EFI_STRING Progress;
1956 EFI_STRING Result;
1957 CHAR16 *StrPtr;
1958
1959 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1960 return EFI_SUCCESS;
1961 }
1962
1963 if (FormSet->ConfigAccess == NULL) {
1964 return EFI_NOT_FOUND;
1965 }
1966
1967 if (Storage->ElementCount == 0) {
1968 //
1969 // Skip if there is no RequestElement
1970 //
1971 return EFI_SUCCESS;
1972 }
1973
1974 //
1975 // Request current settings from Configuration Driver
1976 //
1977 Status = FormSet->ConfigAccess->ExtractConfig (
1978 FormSet->ConfigAccess,
1979 Storage->ConfigRequest,
1980 &Progress,
1981 &Result
1982 );
1983 if (EFI_ERROR (Status)) {
1984 return Status;
1985 }
1986
1987 //
1988 // Convert Result from <ConfigAltResp> to <ConfigResp>
1989 //
1990 StrPtr = StrStr (Result, L"ALTCFG");
1991 if (StrPtr != NULL) {
1992 *StrPtr = L'\0';
1993 }
1994
1995 Status = ConfigRespToStorage (Storage, Result);
1996 gBS->FreePool (Result);
1997 return Status;
1998 }
1999
2000
2001 /**
2002 Get current setting of Questions.
2003
2004 @param FormSet FormSet data structure.
2005
2006 @retval EFI_SUCCESS The function completed successfully.
2007
2008 **/
2009 EFI_STATUS
2010 InitializeCurrentSetting (
2011 IN OUT FORM_BROWSER_FORMSET *FormSet
2012 )
2013 {
2014 LIST_ENTRY *Link;
2015 FORMSET_STORAGE *Storage;
2016 FORM_BROWSER_FORM *Form;
2017 EFI_STATUS Status;
2018
2019 //
2020 // Extract default from IFR binary
2021 //
2022 Link = GetFirstNode (&FormSet->FormListHead);
2023 while (!IsNull (&FormSet->FormListHead, Link)) {
2024 Form = FORM_BROWSER_FORM_FROM_LINK (Link);
2025
2026 Status = ExtractFormDefault (FormSet, Form, EFI_HII_DEFAULT_CLASS_STANDARD);
2027
2028 Link = GetNextNode (&FormSet->FormListHead, Link);
2029 }
2030
2031 //
2032 // Request current settings from Configuration Driver
2033 //
2034 Link = GetFirstNode (&FormSet->StorageListHead);
2035 while (!IsNull (&FormSet->StorageListHead, Link)) {
2036 Storage = FORMSET_STORAGE_FROM_LINK (Link);
2037
2038 Status = LoadStorage (FormSet, Storage);
2039
2040 //
2041 // Now Edit Buffer is filled with default values(lower priority) and current
2042 // settings(higher priority), sychronize it to shadow Buffer
2043 //
2044 if (!EFI_ERROR (Status)) {
2045 SynchronizeStorage (Storage);
2046 }
2047
2048 Link = GetNextNode (&FormSet->StorageListHead, Link);
2049 }
2050
2051 return EFI_SUCCESS;
2052 }
2053
2054
2055 /**
2056 Fetch the Ifr binary data of a FormSet.
2057
2058 @param Handle PackageList Handle
2059 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2060 GUID), take the first FormSet found in package
2061 list.
2062 @param BinaryLength The length of the FormSet IFR binary.
2063 @param BinaryData The buffer designed to receive the FormSet.
2064
2065 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2066 BufferLength was updated.
2067 @retval EFI_INVALID_PARAMETER The handle is unknown.
2068 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2069 be found with the requested FormId.
2070
2071 **/
2072 EFI_STATUS
2073 GetIfrBinaryData (
2074 IN EFI_HII_HANDLE Handle,
2075 IN OUT EFI_GUID *FormSetGuid,
2076 OUT UINTN *BinaryLength,
2077 OUT UINT8 **BinaryData
2078 )
2079 {
2080 EFI_STATUS Status;
2081 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
2082 UINTN BufferSize;
2083 UINT8 *Package;
2084 UINT8 *OpCodeData;
2085 UINT32 Offset;
2086 UINT32 Offset2;
2087 BOOLEAN ReturnDefault;
2088 UINT32 PackageListLength;
2089 EFI_HII_PACKAGE_HEADER PackageHeader;
2090
2091 OpCodeData = NULL;
2092 Package = NULL;
2093 ZeroMem (&PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));;
2094
2095 //
2096 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2097 //
2098 if (FormSetGuid == NULL || CompareGuid (FormSetGuid, &gZeroGuid)) {
2099 ReturnDefault = TRUE;
2100 } else {
2101 ReturnDefault = FALSE;
2102 }
2103
2104 //
2105 // Get HII PackageList
2106 //
2107 BufferSize = 0;
2108 HiiPackageList = NULL;
2109 Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);
2110 if (Status == EFI_BUFFER_TOO_SMALL) {
2111 HiiPackageList = AllocatePool (BufferSize);
2112 ASSERT (HiiPackageList != NULL);
2113
2114 Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);
2115 }
2116 if (EFI_ERROR (Status)) {
2117 return Status;
2118 }
2119
2120 //
2121 // Get Form package from this HII package List
2122 //
2123 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
2124 Offset2 = 0;
2125 CopyMem (&PackageListLength, &HiiPackageList->PackageLength, sizeof (UINT32));
2126
2127 while (Offset < PackageListLength) {
2128 Package = ((UINT8 *) HiiPackageList) + Offset;
2129 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
2130
2131 if (PackageHeader.Type == EFI_HII_PACKAGE_FORM) {
2132 //
2133 // Search FormSet in this Form Package
2134 //
2135 Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);
2136 while (Offset2 < PackageHeader.Length) {
2137 OpCodeData = Package + Offset2;
2138
2139 if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {
2140 //
2141 // Check whether return default FormSet
2142 //
2143 if (ReturnDefault) {
2144 break;
2145 }
2146
2147 //
2148 // FormSet GUID is specified, check it
2149 //
2150 if (CompareGuid (FormSetGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {
2151 break;
2152 }
2153 }
2154
2155 Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
2156 }
2157
2158 if (Offset2 < PackageHeader.Length) {
2159 //
2160 // Target formset found
2161 //
2162 break;
2163 }
2164 }
2165
2166 Offset += PackageHeader.Length;
2167 }
2168
2169 if (Offset >= PackageListLength) {
2170 //
2171 // Form package not found in this Package List
2172 //
2173 gBS->FreePool (HiiPackageList);
2174 return EFI_NOT_FOUND;
2175 }
2176
2177 if (ReturnDefault && FormSetGuid != NULL) {
2178 //
2179 // Return the default FormSet GUID
2180 //
2181 CopyMem (FormSetGuid, &((EFI_IFR_FORM_SET *) OpCodeData)->Guid, sizeof (EFI_GUID));
2182 }
2183
2184 //
2185 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2186 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2187 // of the Form Package.
2188 //
2189 *BinaryLength = PackageHeader.Length - Offset2;
2190 *BinaryData = AllocateCopyPool (*BinaryLength, OpCodeData);
2191
2192 gBS->FreePool (HiiPackageList);
2193
2194 if (*BinaryData == NULL) {
2195 return EFI_OUT_OF_RESOURCES;
2196 }
2197
2198 return EFI_SUCCESS;
2199 }
2200
2201
2202 /**
2203 Initialize the internal data structure of a FormSet.
2204
2205 @param Handle PackageList Handle
2206 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2207 GUID), take the first FormSet found in package
2208 list.
2209 @param FormSet FormSet data structure.
2210
2211 @retval EFI_SUCCESS The function completed successfully.
2212 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2213
2214 **/
2215 EFI_STATUS
2216 InitializeFormSet (
2217 IN EFI_HII_HANDLE Handle,
2218 IN OUT EFI_GUID *FormSetGuid,
2219 OUT FORM_BROWSER_FORMSET *FormSet
2220 )
2221 {
2222 EFI_STATUS Status;
2223 EFI_HANDLE DriverHandle;
2224 UINT16 Index;
2225
2226 Status = GetIfrBinaryData (Handle, FormSetGuid, &FormSet->IfrBinaryLength, &FormSet->IfrBinaryData);
2227 if (EFI_ERROR (Status)) {
2228 return Status;
2229 }
2230
2231 FormSet->HiiHandle = Handle;
2232 CopyMem (&FormSet->Guid, FormSetGuid, sizeof (EFI_GUID));
2233
2234 //
2235 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2236 //
2237 Status = mHiiDatabase->GetPackageListHandle (mHiiDatabase, Handle, &DriverHandle);
2238 if (EFI_ERROR (Status)) {
2239 return Status;
2240 }
2241 FormSet->DriverHandle = DriverHandle;
2242 Status = gBS->HandleProtocol (
2243 DriverHandle,
2244 &gEfiHiiConfigAccessProtocolGuid,
2245 (VOID **) &FormSet->ConfigAccess
2246 );
2247 if (EFI_ERROR (Status)) {
2248 //
2249 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2250 // list, then there will be no configuration action required
2251 //
2252 FormSet->ConfigAccess = NULL;
2253 }
2254
2255 //
2256 // Parse the IFR binary OpCodes
2257 //
2258 Status = ParseOpCodes (FormSet);
2259 if (EFI_ERROR (Status)) {
2260 return Status;
2261 }
2262
2263 gClassOfVfr = FormSet->SubClass;
2264 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {
2265 FrontPageHandle = FormSet->HiiHandle;
2266 }
2267
2268 //
2269 // Match GUID to find out the function key setting. If match fail, use the default setting.
2270 //
2271 for (Index = 0; Index < sizeof (gFunctionKeySettingTable) / sizeof (FUNCTIION_KEY_SETTING); Index++) {
2272 if (CompareGuid (&FormSet->Guid, &(gFunctionKeySettingTable[Index].FormSetGuid))) {
2273 //
2274 // Update the function key setting.
2275 //
2276 gFunctionKeySetting = gFunctionKeySettingTable[Index].KeySetting;
2277 //
2278 // Function key prompt can not be displayed if the function key has been disabled.
2279 //
2280 if ((gFunctionKeySetting & FUNCTION_ONE) != FUNCTION_ONE) {
2281 gFunctionOneString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2282 }
2283
2284 if ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO) {
2285 gFunctionTwoString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2286 }
2287
2288 if ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE) {
2289 gFunctionNineString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2290 }
2291
2292 if ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN) {
2293 gFunctionTenString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2294 }
2295 }
2296 }
2297
2298 return Status;
2299 }