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