]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[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 if (*Dest != NULL) {
728 FreePool (*Dest);
729 }
730 *Dest = AllocateCopyPool (StrSize (Src), Src);
731 ASSERT (*Dest != NULL);
732 }
733
734
735 /**
736 Allocate new memory and concatinate Source on the end of Destination.
737
738 @param Dest String to added to the end of.
739 @param Src String to concatinate.
740
741 **/
742 VOID
743 NewStringCat (
744 IN OUT CHAR16 **Dest,
745 IN CHAR16 *Src
746 )
747 {
748 CHAR16 *NewString;
749 UINTN TmpSize;
750
751 if (*Dest == NULL) {
752 NewStringCpy (Dest, Src);
753 return;
754 }
755
756 TmpSize = StrSize (*Dest);
757 NewString = AllocateZeroPool (TmpSize + StrSize (Src) - 1);
758 ASSERT (NewString != NULL);
759
760 StrCpy (NewString, *Dest);
761 StrCat (NewString, Src);
762
763 gBS->FreePool (*Dest);
764 *Dest = NewString;
765 }
766
767
768 /**
769 Synchronize Storage's Edit copy to Shadow copy.
770
771 @param Storage The Storage to be synchronized.
772
773 **/
774 VOID
775 SynchronizeStorage (
776 IN FORMSET_STORAGE *Storage
777 )
778 {
779 LIST_ENTRY *Link;
780 NAME_VALUE_NODE *Node;
781
782 switch (Storage->Type) {
783 case EFI_HII_VARSTORE_BUFFER:
784 CopyMem (Storage->Buffer, Storage->EditBuffer, Storage->Size);
785 break;
786
787 case EFI_HII_VARSTORE_NAME_VALUE:
788 Link = GetFirstNode (&Storage->NameValueListHead);
789 while (!IsNull (&Storage->NameValueListHead, Link)) {
790 Node = NAME_VALUE_NODE_FROM_LINK (Link);
791
792 NewStringCpy (&Node->Value, Node->EditValue);
793
794 Link = GetNextNode (&Storage->NameValueListHead, Link);
795 }
796 break;
797
798 case EFI_HII_VARSTORE_EFI_VARIABLE:
799 default:
800 break;
801 }
802 }
803
804
805 /**
806 Get Value for given Name from a NameValue Storage.
807
808 @param Storage The NameValue Storage.
809 @param Name The Name.
810 @param Value The retured Value.
811
812 @retval EFI_SUCCESS Value found for given Name.
813 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
814
815 **/
816 EFI_STATUS
817 GetValueByName (
818 IN FORMSET_STORAGE *Storage,
819 IN CHAR16 *Name,
820 IN OUT CHAR16 **Value
821 )
822 {
823 LIST_ENTRY *Link;
824 NAME_VALUE_NODE *Node;
825
826 *Value = NULL;
827
828 Link = GetFirstNode (&Storage->NameValueListHead);
829 while (!IsNull (&Storage->NameValueListHead, Link)) {
830 Node = NAME_VALUE_NODE_FROM_LINK (Link);
831
832 if (StrCmp (Name, Node->Name) == 0) {
833 NewStringCpy (Value, Node->EditValue);
834 return EFI_SUCCESS;
835 }
836
837 Link = GetNextNode (&Storage->NameValueListHead, Link);
838 }
839
840 return EFI_NOT_FOUND;
841 }
842
843
844 /**
845 Set Value of given Name in a NameValue Storage.
846
847 @param Storage The NameValue Storage.
848 @param Name The Name.
849 @param Value The Value to set.
850
851 @retval EFI_SUCCESS Value found for given Name.
852 @retval EFI_NOT_FOUND No such Name found in NameValue storage.
853
854 **/
855 EFI_STATUS
856 SetValueByName (
857 IN FORMSET_STORAGE *Storage,
858 IN CHAR16 *Name,
859 IN CHAR16 *Value
860 )
861 {
862 LIST_ENTRY *Link;
863 NAME_VALUE_NODE *Node;
864
865 Link = GetFirstNode (&Storage->NameValueListHead);
866 while (!IsNull (&Storage->NameValueListHead, Link)) {
867 Node = NAME_VALUE_NODE_FROM_LINK (Link);
868
869 if (StrCmp (Name, Node->Name) == 0) {
870 if (Node->EditValue != NULL) {
871 FreePool (Node->EditValue);
872 }
873 Node->EditValue = AllocateCopyPool (StrSize (Value), Value);
874 ASSERT (Node->EditValue != NULL);
875 return EFI_SUCCESS;
876 }
877
878 Link = GetNextNode (&Storage->NameValueListHead, Link);
879 }
880
881 return EFI_NOT_FOUND;
882 }
883
884
885 /**
886 Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
887
888 @param Storage The Storage to be conveted.
889 @param ConfigResp The returned <ConfigResp>.
890
891 @retval EFI_SUCCESS Convert success.
892 @retval EFI_INVALID_PARAMETER Incorrect storage type.
893
894 **/
895 EFI_STATUS
896 StorageToConfigResp (
897 IN FORMSET_STORAGE *Storage,
898 IN CHAR16 **ConfigResp
899 )
900 {
901 EFI_STATUS Status;
902 EFI_STRING Progress;
903 LIST_ENTRY *Link;
904 NAME_VALUE_NODE *Node;
905
906 Status = EFI_SUCCESS;
907
908 switch (Storage->Type) {
909 case EFI_HII_VARSTORE_BUFFER:
910 Status = mHiiConfigRouting->BlockToConfig (
911 mHiiConfigRouting,
912 Storage->ConfigRequest,
913 Storage->EditBuffer,
914 Storage->Size,
915 ConfigResp,
916 &Progress
917 );
918 break;
919
920 case EFI_HII_VARSTORE_NAME_VALUE:
921 *ConfigResp = NULL;
922 NewStringCat (ConfigResp, Storage->ConfigHdr);
923
924 Link = GetFirstNode (&Storage->NameValueListHead);
925 while (!IsNull (&Storage->NameValueListHead, Link)) {
926 Node = NAME_VALUE_NODE_FROM_LINK (Link);
927
928 NewStringCat (ConfigResp, L"&");
929 NewStringCat (ConfigResp, Node->Name);
930 NewStringCat (ConfigResp, L"=");
931 NewStringCat (ConfigResp, Node->EditValue);
932
933 Link = GetNextNode (&Storage->NameValueListHead, Link);
934 }
935 break;
936
937 case EFI_HII_VARSTORE_EFI_VARIABLE:
938 default:
939 Status = EFI_INVALID_PARAMETER;
940 break;
941 }
942
943 return Status;
944 }
945
946
947 /**
948 Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
949
950 @param Storage The Storage to receive the settings.
951 @param ConfigResp The <ConfigResp> to be converted.
952
953 @retval EFI_SUCCESS Convert success.
954 @retval EFI_INVALID_PARAMETER Incorrect storage type.
955
956 **/
957 EFI_STATUS
958 ConfigRespToStorage (
959 IN FORMSET_STORAGE *Storage,
960 IN CHAR16 *ConfigResp
961 )
962 {
963 EFI_STATUS Status;
964 EFI_STRING Progress;
965 UINTN BufferSize;
966 CHAR16 *StrPtr;
967 CHAR16 *Name;
968 CHAR16 *Value;
969
970 Status = EFI_SUCCESS;
971
972 switch (Storage->Type) {
973 case EFI_HII_VARSTORE_BUFFER:
974 BufferSize = Storage->Size;
975 Status = mHiiConfigRouting->ConfigToBlock (
976 mHiiConfigRouting,
977 ConfigResp,
978 Storage->EditBuffer,
979 &BufferSize,
980 &Progress
981 );
982 break;
983
984 case EFI_HII_VARSTORE_NAME_VALUE:
985 StrPtr = StrStr (ConfigResp, L"&");
986 while (StrPtr != NULL) {
987 //
988 // Skip '&'
989 //
990 StrPtr = StrPtr + 1;
991 Name = StrPtr;
992 StrPtr = StrStr (StrPtr, L"=");
993 if (StrPtr == NULL) {
994 break;
995 }
996 *StrPtr = 0;
997
998 //
999 // Skip '='
1000 //
1001 StrPtr = StrPtr + 1;
1002 Value = StrPtr;
1003 StrPtr = StrStr (StrPtr, L"&");
1004 if (StrPtr != NULL) {
1005 *StrPtr = 0;
1006 }
1007 SetValueByName (Storage, Name, Value);
1008 }
1009 break;
1010
1011 case EFI_HII_VARSTORE_EFI_VARIABLE:
1012 default:
1013 Status = EFI_INVALID_PARAMETER;
1014 break;
1015 }
1016
1017 return Status;
1018 }
1019
1020
1021 /**
1022 Get Question's current Value.
1023
1024 @param FormSet FormSet data structure.
1025 @param Form Form data structure.
1026 @param Question Question to be initialized.
1027 @param Cached TRUE: get from Edit copy FALSE: get from original
1028 Storage
1029
1030 @retval EFI_SUCCESS The function completed successfully.
1031
1032 **/
1033 EFI_STATUS
1034 GetQuestionValue (
1035 IN FORM_BROWSER_FORMSET *FormSet,
1036 IN FORM_BROWSER_FORM *Form,
1037 IN OUT FORM_BROWSER_STATEMENT *Question,
1038 IN BOOLEAN Cached
1039 )
1040 {
1041 EFI_STATUS Status;
1042 BOOLEAN Enabled;
1043 BOOLEAN Pending;
1044 UINT8 *Dst;
1045 UINTN StorageWidth;
1046 EFI_TIME EfiTime;
1047 FORMSET_STORAGE *Storage;
1048 EFI_IFR_TYPE_VALUE *QuestionValue;
1049 CHAR16 *ConfigRequest;
1050 CHAR16 *Progress;
1051 CHAR16 *Result;
1052 CHAR16 *Value;
1053 UINTN Length;
1054 BOOLEAN IsBufferStorage;
1055 BOOLEAN IsString;
1056
1057 Status = EFI_SUCCESS;
1058
1059 //
1060 // Statement don't have storage, skip them
1061 //
1062 if (Question->QuestionId == 0) {
1063 return Status;
1064 }
1065
1066 //
1067 // Question value is provided by an Expression, evaluate it
1068 //
1069 if (Question->ValueExpression != NULL) {
1070 Status = EvaluateExpression (FormSet, Form, Question->ValueExpression);
1071 if (!EFI_ERROR (Status)) {
1072 CopyMem (&Question->HiiValue, &Question->ValueExpression->Result, sizeof (EFI_HII_VALUE));
1073 }
1074 return Status;
1075 }
1076
1077 //
1078 // Question value is provided by RTC
1079 //
1080 Storage = Question->Storage;
1081 QuestionValue = &Question->HiiValue.Value;
1082 if (Storage == NULL) {
1083 //
1084 // It's a Question without storage, or RTC date/time
1085 //
1086 if (Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) {
1087 //
1088 // Date and time define the same Flags bit
1089 //
1090 switch (Question->Flags & EFI_QF_DATE_STORAGE) {
1091 case QF_DATE_STORAGE_TIME:
1092 Status = gRT->GetTime (&EfiTime, NULL);
1093 break;
1094
1095 case QF_DATE_STORAGE_WAKEUP:
1096 Status = gRT->GetWakeupTime (&Enabled, &Pending, &EfiTime);
1097 break;
1098
1099 case QF_DATE_STORAGE_NORMAL:
1100 default:
1101 //
1102 // For date/time without storage
1103 //
1104 return EFI_SUCCESS;
1105 }
1106
1107 if (EFI_ERROR (Status)) {
1108 return Status;
1109 }
1110
1111 if (Question->Operand == EFI_IFR_DATE_OP) {
1112 QuestionValue->date.Year = EfiTime.Year;
1113 QuestionValue->date.Month = EfiTime.Month;
1114 QuestionValue->date.Day = EfiTime.Day;
1115 } else {
1116 QuestionValue->time.Hour = EfiTime.Hour;
1117 QuestionValue->time.Minute = EfiTime.Minute;
1118 QuestionValue->time.Second = EfiTime.Second;
1119 }
1120 }
1121
1122 return EFI_SUCCESS;
1123 }
1124
1125 //
1126 // Question value is provided by EFI variable
1127 //
1128 StorageWidth = Question->StorageWidth;
1129 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1130 if (Question->BufferValue != NULL) {
1131 Dst = Question->BufferValue;
1132 } else {
1133 Dst = (UINT8 *) QuestionValue;
1134 }
1135
1136 Status = gRT->GetVariable (
1137 Question->VariableName,
1138 &Storage->Guid,
1139 NULL,
1140 &StorageWidth,
1141 Dst
1142 );
1143 //
1144 // Always return success, even this EFI variable doesn't exist
1145 //
1146 return EFI_SUCCESS;
1147 }
1148
1149 //
1150 // Question Value is provided by Buffer Storage or NameValue Storage
1151 //
1152 if (Question->BufferValue != NULL) {
1153 //
1154 // This Question is password or orderedlist
1155 //
1156 Dst = Question->BufferValue;
1157 } else {
1158 //
1159 // Other type of Questions
1160 //
1161 Dst = (UINT8 *) &Question->HiiValue.Value;
1162 }
1163
1164 IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);
1165 IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE);
1166 if (Cached) {
1167 if (IsBufferStorage) {
1168 //
1169 // Copy from storage Edit buffer
1170 //
1171 CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);
1172 } else {
1173 Status = GetValueByName (Storage, Question->VariableName, &Value);
1174 if (EFI_ERROR (Status)) {
1175 return Status;
1176 }
1177
1178 if (IsString) {
1179 //
1180 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1181 //
1182 Length = StorageWidth + sizeof (CHAR16);
1183 Status = ConfigStringToUnicode ((CHAR16 *) Dst, &Length, Value);
1184 } else {
1185 Status = HexStringToBuf (Dst, &StorageWidth, Value, NULL);
1186 }
1187
1188 gBS->FreePool (Value);
1189 }
1190 } else {
1191 //
1192 // Request current settings from Configuration Driver
1193 //
1194 if (FormSet->ConfigAccess == NULL) {
1195 return EFI_NOT_FOUND;
1196 }
1197
1198 //
1199 // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
1200 // <ConfigHdr> + "&" + <VariableName>
1201 //
1202 if (IsBufferStorage) {
1203 Length = StrLen (Storage->ConfigHdr);
1204 Length += StrLen (Question->BlockName);
1205 } else {
1206 Length = StrLen (Storage->ConfigHdr);
1207 Length += StrLen (Question->VariableName) + 1;
1208 }
1209 ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));
1210 ASSERT (ConfigRequest != NULL);
1211
1212 StrCpy (ConfigRequest, Storage->ConfigHdr);
1213 if (IsBufferStorage) {
1214 StrCat (ConfigRequest, Question->BlockName);
1215 } else {
1216 StrCat (ConfigRequest, L"&");
1217 StrCat (ConfigRequest, Question->VariableName);
1218 }
1219
1220 Status = FormSet->ConfigAccess->ExtractConfig (
1221 FormSet->ConfigAccess,
1222 ConfigRequest,
1223 &Progress,
1224 &Result
1225 );
1226 if (EFI_ERROR (Status)) {
1227 return Status;
1228 }
1229
1230 //
1231 // Skip <ConfigRequest>
1232 //
1233 Value = Result + Length;
1234 if (IsBufferStorage) {
1235 //
1236 // Skip "&VALUE"
1237 //
1238 Value = Value + 6;
1239 }
1240 if (*Value != '=') {
1241 gBS->FreePool (Result);
1242 return EFI_NOT_FOUND;
1243 }
1244 //
1245 // Skip '=', point to value
1246 //
1247 Value = Value + 1;
1248 if (!IsBufferStorage && IsString) {
1249 //
1250 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1251 //
1252 Length = StorageWidth + sizeof (CHAR16);
1253 Status = ConfigStringToUnicode ((CHAR16 *) Dst, &Length, Value);
1254 } else {
1255 Status = HexStringToBuf (Dst, &StorageWidth, Value, NULL);
1256 if (EFI_ERROR (Status)) {
1257 gBS->FreePool (Result);
1258 return Status;
1259 }
1260 }
1261
1262 //
1263 // Synchronize Edit Buffer
1264 //
1265 if (IsBufferStorage) {
1266 CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Dst, StorageWidth);
1267 } else {
1268 SetValueByName (Storage, Question->VariableName, Value);
1269 }
1270 gBS->FreePool (Result);
1271 }
1272
1273 return Status;
1274 }
1275
1276
1277 /**
1278 Save Question Value to edit copy(cached) or Storage(uncached).
1279
1280 @param FormSet FormSet data structure.
1281 @param Form Form data structure.
1282 @param Question Pointer to the Question.
1283 @param Cached TRUE: set to Edit copy FALSE: set to original
1284 Storage
1285
1286 @retval EFI_SUCCESS The function completed successfully.
1287
1288 **/
1289 EFI_STATUS
1290 SetQuestionValue (
1291 IN FORM_BROWSER_FORMSET *FormSet,
1292 IN FORM_BROWSER_FORM *Form,
1293 IN OUT FORM_BROWSER_STATEMENT *Question,
1294 IN BOOLEAN Cached
1295 )
1296 {
1297 EFI_STATUS Status;
1298 BOOLEAN Enabled;
1299 BOOLEAN Pending;
1300 UINT8 *Src;
1301 EFI_TIME EfiTime;
1302 UINTN BufferLen;
1303 UINTN StorageWidth;
1304 FORMSET_STORAGE *Storage;
1305 EFI_IFR_TYPE_VALUE *QuestionValue;
1306 CHAR16 *ConfigResp;
1307 CHAR16 *Progress;
1308 CHAR16 *Value;
1309 UINTN Length;
1310 BOOLEAN IsBufferStorage;
1311 BOOLEAN IsString;
1312
1313 Status = EFI_SUCCESS;
1314
1315 //
1316 // Statement don't have storage, skip them
1317 //
1318 if (Question->QuestionId == 0) {
1319 return Status;
1320 }
1321
1322 //
1323 // If Question value is provided by an Expression, then it is read only
1324 //
1325 if (Question->ValueExpression != NULL) {
1326 return Status;
1327 }
1328
1329 //
1330 // Question value is provided by RTC
1331 //
1332 Storage = Question->Storage;
1333 QuestionValue = &Question->HiiValue.Value;
1334 if (Storage == NULL) {
1335 //
1336 // It's a Question without storage, or RTC date/time
1337 //
1338 if (Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) {
1339 //
1340 // Date and time define the same Flags bit
1341 //
1342 switch (Question->Flags & EFI_QF_DATE_STORAGE) {
1343 case QF_DATE_STORAGE_TIME:
1344 Status = gRT->GetTime (&EfiTime, NULL);
1345 break;
1346
1347 case QF_DATE_STORAGE_WAKEUP:
1348 Status = gRT->GetWakeupTime (&Enabled, &Pending, &EfiTime);
1349 break;
1350
1351 case QF_DATE_STORAGE_NORMAL:
1352 default:
1353 //
1354 // For date/time without storage
1355 //
1356 return EFI_SUCCESS;
1357 }
1358
1359 if (EFI_ERROR (Status)) {
1360 return Status;
1361 }
1362
1363 if (Question->Operand == EFI_IFR_DATE_OP) {
1364 EfiTime.Year = QuestionValue->date.Year;
1365 EfiTime.Month = QuestionValue->date.Month;
1366 EfiTime.Day = QuestionValue->date.Day;
1367 } else {
1368 EfiTime.Hour = QuestionValue->time.Hour;
1369 EfiTime.Minute = QuestionValue->time.Minute;
1370 EfiTime.Second = QuestionValue->time.Second;
1371 }
1372
1373 if ((Question->Flags & EFI_QF_DATE_STORAGE) == QF_DATE_STORAGE_TIME) {
1374 Status = gRT->SetTime (&EfiTime);
1375 } else {
1376 Status = gRT->SetWakeupTime (TRUE, &EfiTime);
1377 }
1378 }
1379
1380 return Status;
1381 }
1382
1383 //
1384 // Question value is provided by EFI variable
1385 //
1386 StorageWidth = Question->StorageWidth;
1387 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1388 if (Question->BufferValue != NULL) {
1389 Src = Question->BufferValue;
1390 } else {
1391 Src = (UINT8 *) QuestionValue;
1392 }
1393
1394 Status = gRT->SetVariable (
1395 Question->VariableName,
1396 &Storage->Guid,
1397 Storage->Attributes,
1398 StorageWidth,
1399 Src
1400 );
1401 return Status;
1402 }
1403
1404 //
1405 // Question Value is provided by Buffer Storage or NameValue Storage
1406 //
1407 if (Question->BufferValue != NULL) {
1408 Src = Question->BufferValue;
1409 } else {
1410 Src = (UINT8 *) &Question->HiiValue.Value;
1411 }
1412
1413 IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);
1414 IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE);
1415 if (IsBufferStorage) {
1416 //
1417 // Copy to storage edit buffer
1418 //
1419 CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);
1420 } else {
1421 if (IsString) {
1422 //
1423 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1424 //
1425 Value = NULL;
1426 BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);
1427 Value = AllocateZeroPool (BufferLen);
1428 ASSERT (Value != NULL);
1429 Status = UnicodeToConfigString (Value, &BufferLen, (CHAR16 *) Src);
1430 ASSERT_EFI_ERROR (Status);
1431 } else {
1432 BufferLen = StorageWidth * 2 + 1;
1433 Value = AllocateZeroPool (BufferLen * sizeof (CHAR16));
1434 ASSERT (Value != NULL);
1435 BufToHexString (Value, &BufferLen, Src, StorageWidth);
1436 ToLower (Value);
1437 }
1438
1439 Status = SetValueByName (Storage, Question->VariableName, Value);
1440 gBS->FreePool (Value);
1441 }
1442
1443 if (!Cached) {
1444 //
1445 // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
1446 // <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
1447 //
1448 if (IsBufferStorage) {
1449 Length = StrLen (Question->BlockName) + 7;
1450 } else {
1451 Length = StrLen (Question->VariableName) + 2;
1452 }
1453 if (!IsBufferStorage && IsString) {
1454 Length += (StrLen ((CHAR16 *) Src) * 4);
1455 } else {
1456 Length += (StorageWidth * 2);
1457 }
1458 ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));
1459 ASSERT (ConfigResp != NULL);
1460
1461 StrCpy (ConfigResp, Storage->ConfigHdr);
1462 if (IsBufferStorage) {
1463 StrCat (ConfigResp, Question->BlockName);
1464 StrCat (ConfigResp, L"&VALUE=");
1465 } else {
1466 StrCat (ConfigResp, L"&");
1467 StrCat (ConfigResp, Question->VariableName);
1468 StrCat (ConfigResp, L"=");
1469 }
1470
1471 Value = ConfigResp + StrLen (ConfigResp);
1472 if (!IsBufferStorage && IsString) {
1473 //
1474 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1475 //
1476 BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);
1477 Status = UnicodeToConfigString (Value, &BufferLen, (CHAR16 *) Src);
1478 ASSERT_EFI_ERROR (Status);
1479 } else {
1480 BufferLen = StorageWidth * 2 + 1;
1481 BufToHexString (Value, &BufferLen, Src, StorageWidth);
1482 ToLower (Value);
1483 }
1484
1485 //
1486 // Submit Question Value to Configuration Driver
1487 //
1488 if (FormSet->ConfigAccess != NULL) {
1489 Status = FormSet->ConfigAccess->RouteConfig (
1490 FormSet->ConfigAccess,
1491 ConfigResp,
1492 &Progress
1493 );
1494 if (EFI_ERROR (Status)) {
1495 gBS->FreePool (ConfigResp);
1496 return Status;
1497 }
1498 }
1499 gBS->FreePool (ConfigResp);
1500
1501 //
1502 // Synchronize shadow Buffer
1503 //
1504 SynchronizeStorage (Storage);
1505 }
1506
1507 return Status;
1508 }
1509
1510
1511 /**
1512 Perform inconsistent check for a Form.
1513
1514 @param FormSet FormSet data structure.
1515 @param Form Form data structure.
1516 @param Question The Question to be validated.
1517 @param Type Validation type: InConsistent or NoSubmit
1518
1519 @retval EFI_SUCCESS Form validation pass.
1520 @retval other Form validation failed.
1521
1522 **/
1523 EFI_STATUS
1524 ValidateQuestion (
1525 IN FORM_BROWSER_FORMSET *FormSet,
1526 IN FORM_BROWSER_FORM *Form,
1527 IN FORM_BROWSER_STATEMENT *Question,
1528 IN UINTN Type
1529 )
1530 {
1531 EFI_STATUS Status;
1532 LIST_ENTRY *Link;
1533 LIST_ENTRY *ListHead;
1534 EFI_STRING PopUp;
1535 EFI_INPUT_KEY Key;
1536 FORM_EXPRESSION *Expression;
1537
1538 if (Type == EFI_HII_EXPRESSION_INCONSISTENT_IF) {
1539 ListHead = &Question->InconsistentListHead;
1540 } else if (Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) {
1541 ListHead = &Question->NoSubmitListHead;
1542 } else {
1543 return EFI_UNSUPPORTED;
1544 }
1545
1546 Link = GetFirstNode (ListHead);
1547 while (!IsNull (ListHead, Link)) {
1548 Expression = FORM_EXPRESSION_FROM_LINK (Link);
1549
1550 //
1551 // Evaluate the expression
1552 //
1553 Status = EvaluateExpression (FormSet, Form, Expression);
1554 if (EFI_ERROR (Status)) {
1555 return Status;
1556 }
1557
1558 if (Expression->Result.Value.b) {
1559 //
1560 // Condition meet, show up error message
1561 //
1562 if (Expression->Error != 0) {
1563 PopUp = GetToken (Expression->Error, FormSet->HiiHandle);
1564 do {
1565 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, PopUp, gPressEnter, gEmptyString);
1566 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1567 gBS->FreePool (PopUp);
1568 }
1569
1570 return EFI_NOT_READY;
1571 }
1572
1573 Link = GetNextNode (ListHead, Link);
1574 }
1575
1576 return EFI_SUCCESS;
1577 }
1578
1579
1580 /**
1581 Perform NoSubmit check for a Form.
1582
1583 @param FormSet FormSet data structure.
1584 @param Form Form data structure.
1585
1586 @retval EFI_SUCCESS Form validation pass.
1587 @retval other Form validation failed.
1588
1589 **/
1590 EFI_STATUS
1591 NoSubmitCheck (
1592 IN FORM_BROWSER_FORMSET *FormSet,
1593 IN FORM_BROWSER_FORM *Form
1594 )
1595 {
1596 EFI_STATUS Status;
1597 LIST_ENTRY *Link;
1598 FORM_BROWSER_STATEMENT *Question;
1599
1600 Link = GetFirstNode (&Form->StatementListHead);
1601 while (!IsNull (&Form->StatementListHead, Link)) {
1602 Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1603
1604 Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_NO_SUBMIT_IF);
1605 if (EFI_ERROR (Status)) {
1606 return Status;
1607 }
1608
1609 Link = GetNextNode (&Form->StatementListHead, Link);
1610 }
1611
1612 return EFI_SUCCESS;
1613 }
1614
1615
1616 /**
1617 Submit a Form.
1618
1619 @param FormSet FormSet data structure.
1620 @param Form Form data structure.
1621
1622 @retval EFI_SUCCESS The function completed successfully.
1623
1624 **/
1625 EFI_STATUS
1626 SubmitForm (
1627 IN FORM_BROWSER_FORMSET *FormSet,
1628 IN FORM_BROWSER_FORM *Form
1629 )
1630 {
1631 EFI_STATUS Status;
1632 LIST_ENTRY *Link;
1633 EFI_STRING ConfigResp;
1634 EFI_STRING Progress;
1635 FORMSET_STORAGE *Storage;
1636
1637 //
1638 // Validate the Form by NoSubmit check
1639 //
1640 Status = NoSubmitCheck (FormSet, Form);
1641 if (EFI_ERROR (Status)) {
1642 return Status;
1643 }
1644
1645 //
1646 // Submit Buffer storage or Name/Value storage
1647 //
1648 Link = GetFirstNode (&FormSet->StorageListHead);
1649 while (!IsNull (&FormSet->StorageListHead, Link)) {
1650 Storage = FORMSET_STORAGE_FROM_LINK (Link);
1651 Link = GetNextNode (&FormSet->StorageListHead, Link);
1652
1653 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1654 continue;
1655 }
1656
1657 //
1658 // Skip if there is no RequestElement
1659 //
1660 if (Storage->ElementCount == 0) {
1661 continue;
1662 }
1663
1664 //
1665 // Prepare <ConfigResp>
1666 //
1667 Status = StorageToConfigResp (Storage, &ConfigResp);
1668 if (EFI_ERROR (Status)) {
1669 return Status;
1670 }
1671
1672 //
1673 // Send <ConfigResp> to Configuration Driver
1674 //
1675 if (FormSet->ConfigAccess != NULL) {
1676 Status = FormSet->ConfigAccess->RouteConfig (
1677 FormSet->ConfigAccess,
1678 ConfigResp,
1679 &Progress
1680 );
1681 if (EFI_ERROR (Status)) {
1682 gBS->FreePool (ConfigResp);
1683 return Status;
1684 }
1685 }
1686 gBS->FreePool (ConfigResp);
1687
1688 //
1689 // Config success, update storage shadow Buffer
1690 //
1691 SynchronizeStorage (Storage);
1692 }
1693
1694 gNvUpdateRequired = FALSE;
1695
1696 return EFI_SUCCESS;
1697 }
1698
1699
1700 /**
1701 Reset Question to its default value.
1702
1703 @param FormSet The form set.
1704 @param Form The form.
1705 @param Question The question.
1706 @param DefaultId The Class of the default.
1707
1708 @retval EFI_SUCCESS Question is reset to default value.
1709
1710 **/
1711 EFI_STATUS
1712 GetQuestionDefault (
1713 IN FORM_BROWSER_FORMSET *FormSet,
1714 IN FORM_BROWSER_FORM *Form,
1715 IN FORM_BROWSER_STATEMENT *Question,
1716 IN UINT16 DefaultId
1717 )
1718 {
1719 EFI_STATUS Status;
1720 LIST_ENTRY *Link;
1721 QUESTION_DEFAULT *Default;
1722 QUESTION_OPTION *Option;
1723 EFI_HII_VALUE *HiiValue;
1724 UINT8 Index;
1725
1726 Status = EFI_SUCCESS;
1727
1728 //
1729 // Statement don't have storage, skip them
1730 //
1731 if (Question->QuestionId == 0) {
1732 return Status;
1733 }
1734
1735 //
1736 // There are three ways to specify default value for a Question:
1737 // 1, use nested EFI_IFR_DEFAULT (highest priority)
1738 // 2, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
1739 // 3, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
1740 //
1741 HiiValue = &Question->HiiValue;
1742
1743 //
1744 // EFI_IFR_DEFAULT has highest priority
1745 //
1746 if (!IsListEmpty (&Question->DefaultListHead)) {
1747 Link = GetFirstNode (&Question->DefaultListHead);
1748 while (!IsNull (&Question->DefaultListHead, Link)) {
1749 Default = QUESTION_DEFAULT_FROM_LINK (Link);
1750
1751 if (Default->DefaultId == DefaultId) {
1752 if (Default->ValueExpression != NULL) {
1753 //
1754 // Default is provided by an Expression, evaluate it
1755 //
1756 Status = EvaluateExpression (FormSet, Form, Default->ValueExpression);
1757 if (EFI_ERROR (Status)) {
1758 return Status;
1759 }
1760
1761 CopyMem (HiiValue, &Default->ValueExpression->Result, sizeof (EFI_HII_VALUE));
1762 } else {
1763 //
1764 // Default value is embedded in EFI_IFR_DEFAULT
1765 //
1766 CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE));
1767 }
1768
1769 return EFI_SUCCESS;
1770 }
1771
1772 Link = GetNextNode (&Question->DefaultListHead, Link);
1773 }
1774 }
1775
1776 //
1777 // EFI_ONE_OF_OPTION
1778 //
1779 if ((Question->Operand == EFI_IFR_ONE_OF_OP) && !IsListEmpty (&Question->OptionListHead)) {
1780 if (DefaultId <= EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
1781 //
1782 // OneOfOption could only provide Standard and Manufacturing default
1783 //
1784 Link = GetFirstNode (&Question->OptionListHead);
1785 while (!IsNull (&Question->OptionListHead, Link)) {
1786 Option = QUESTION_OPTION_FROM_LINK (Link);
1787
1788 if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT) != 0)) ||
1789 ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT_MFG) != 0))
1790 ) {
1791 CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));
1792
1793 return EFI_SUCCESS;
1794 }
1795
1796 Link = GetNextNode (&Question->OptionListHead, Link);
1797 }
1798 }
1799 }
1800
1801 //
1802 // EFI_IFR_CHECKBOX - lowest priority
1803 //
1804 if (Question->Operand == EFI_IFR_CHECKBOX_OP) {
1805 if (DefaultId <= EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
1806 //
1807 // Checkbox could only provide Standard and Manufacturing default
1808 //
1809 if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT) != 0)) ||
1810 ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) != 0))
1811 ) {
1812 HiiValue->Value.b = TRUE;
1813 } else {
1814 HiiValue->Value.b = FALSE;
1815 }
1816
1817 return EFI_SUCCESS;
1818 }
1819 }
1820
1821 //
1822 // For Questions without default
1823 //
1824 switch (Question->Operand) {
1825 case EFI_IFR_NUMERIC_OP:
1826 //
1827 // Take minimal value as numeric's default value
1828 //
1829 HiiValue->Value.u64 = Question->Minimum;
1830 break;
1831
1832 case EFI_IFR_ONE_OF_OP:
1833 //
1834 // Take first oneof option as oneof's default value
1835 //
1836 Link = GetFirstNode (&Question->OptionListHead);
1837 if (!IsNull (&Question->OptionListHead, Link)) {
1838 Option = QUESTION_OPTION_FROM_LINK (Link);
1839 CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));
1840 }
1841 break;
1842
1843 case EFI_IFR_ORDERED_LIST_OP:
1844 //
1845 // Take option sequence in IFR as ordered list's default value
1846 //
1847 Index = 0;
1848 Link = GetFirstNode (&Question->OptionListHead);
1849 while (!IsNull (&Question->OptionListHead, Link)) {
1850 Option = QUESTION_OPTION_FROM_LINK (Link);
1851
1852 Question->BufferValue[Index] = Option->Value.Value.u8;
1853
1854 Index++;
1855 if (Index >= Question->MaxContainers) {
1856 break;
1857 }
1858
1859 Link = GetNextNode (&Question->OptionListHead, Link);
1860 }
1861 break;
1862
1863 default:
1864 Status = EFI_NOT_FOUND;
1865 break;
1866 }
1867
1868 return Status;
1869 }
1870
1871
1872 /**
1873 Reset Questions in a Form to their default value.
1874
1875 @param FormSet FormSet data structure.
1876 @param Form The Form which to be reset.
1877 @param DefaultId The Class of the default.
1878
1879 @retval EFI_SUCCESS The function completed successfully.
1880
1881 **/
1882 EFI_STATUS
1883 ExtractFormDefault (
1884 IN FORM_BROWSER_FORMSET *FormSet,
1885 IN FORM_BROWSER_FORM *Form,
1886 IN UINT16 DefaultId
1887 )
1888 {
1889 EFI_STATUS Status;
1890 LIST_ENTRY *Link;
1891 FORM_BROWSER_STATEMENT *Question;
1892
1893 Link = GetFirstNode (&Form->StatementListHead);
1894 while (!IsNull (&Form->StatementListHead, Link)) {
1895 Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1896 Link = GetNextNode (&Form->StatementListHead, Link);
1897
1898 //
1899 // Reset Question to its default value
1900 //
1901 Status = GetQuestionDefault (FormSet, Form, Question, DefaultId);
1902 if (EFI_ERROR (Status)) {
1903 continue;
1904 }
1905
1906 //
1907 // Synchronize Buffer storage's Edit buffer
1908 //
1909 if ((Question->Storage != NULL) &&
1910 (Question->Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE)) {
1911 SetQuestionValue (FormSet, Form, Question, TRUE);
1912 }
1913 }
1914
1915 return EFI_SUCCESS;
1916 }
1917
1918
1919 /**
1920 Initialize Question's Edit copy from Storage.
1921
1922 @param FormSet FormSet data structure.
1923 @param Form Form data structure.
1924
1925 @retval EFI_SUCCESS The function completed successfully.
1926
1927 **/
1928 EFI_STATUS
1929 LoadFormConfig (
1930 IN FORM_BROWSER_FORMSET *FormSet,
1931 IN FORM_BROWSER_FORM *Form
1932 )
1933 {
1934 EFI_STATUS Status;
1935 LIST_ENTRY *Link;
1936 FORM_BROWSER_STATEMENT *Question;
1937
1938 Link = GetFirstNode (&Form->StatementListHead);
1939 while (!IsNull (&Form->StatementListHead, Link)) {
1940 Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1941
1942 //
1943 // Initialize local copy of Value for each Question
1944 //
1945 Status = GetQuestionValue (FormSet, Form, Question, TRUE);
1946 if (EFI_ERROR (Status)) {
1947 return Status;
1948 }
1949
1950 Link = GetNextNode (&Form->StatementListHead, Link);
1951 }
1952
1953 return EFI_SUCCESS;
1954 }
1955
1956
1957 /**
1958 Fill storage's edit copy with settings requested from Configuration Driver.
1959
1960 @param FormSet FormSet data structure.
1961 @param Storage Buffer Storage.
1962
1963 @retval EFI_SUCCESS The function completed successfully.
1964
1965 **/
1966 EFI_STATUS
1967 LoadStorage (
1968 IN FORM_BROWSER_FORMSET *FormSet,
1969 IN FORMSET_STORAGE *Storage
1970 )
1971 {
1972 EFI_STATUS Status;
1973 EFI_STRING Progress;
1974 EFI_STRING Result;
1975 CHAR16 *StrPtr;
1976
1977 if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
1978 return EFI_SUCCESS;
1979 }
1980
1981 if (FormSet->ConfigAccess == NULL) {
1982 return EFI_NOT_FOUND;
1983 }
1984
1985 if (Storage->ElementCount == 0) {
1986 //
1987 // Skip if there is no RequestElement
1988 //
1989 return EFI_SUCCESS;
1990 }
1991
1992 //
1993 // Request current settings from Configuration Driver
1994 //
1995 Status = FormSet->ConfigAccess->ExtractConfig (
1996 FormSet->ConfigAccess,
1997 Storage->ConfigRequest,
1998 &Progress,
1999 &Result
2000 );
2001 if (EFI_ERROR (Status)) {
2002 return Status;
2003 }
2004
2005 //
2006 // Convert Result from <ConfigAltResp> to <ConfigResp>
2007 //
2008 StrPtr = StrStr (Result, L"ALTCFG");
2009 if (StrPtr != NULL) {
2010 *StrPtr = L'\0';
2011 }
2012
2013 Status = ConfigRespToStorage (Storage, Result);
2014 gBS->FreePool (Result);
2015 return Status;
2016 }
2017
2018
2019 /**
2020 Get current setting of Questions.
2021
2022 @param FormSet FormSet data structure.
2023
2024 @retval EFI_SUCCESS The function completed successfully.
2025
2026 **/
2027 EFI_STATUS
2028 InitializeCurrentSetting (
2029 IN OUT FORM_BROWSER_FORMSET *FormSet
2030 )
2031 {
2032 LIST_ENTRY *Link;
2033 FORMSET_STORAGE *Storage;
2034 FORM_BROWSER_FORM *Form;
2035 EFI_STATUS Status;
2036
2037 //
2038 // Extract default from IFR binary
2039 //
2040 Link = GetFirstNode (&FormSet->FormListHead);
2041 while (!IsNull (&FormSet->FormListHead, Link)) {
2042 Form = FORM_BROWSER_FORM_FROM_LINK (Link);
2043
2044 Status = ExtractFormDefault (FormSet, Form, EFI_HII_DEFAULT_CLASS_STANDARD);
2045
2046 Link = GetNextNode (&FormSet->FormListHead, Link);
2047 }
2048
2049 //
2050 // Request current settings from Configuration Driver
2051 //
2052 Link = GetFirstNode (&FormSet->StorageListHead);
2053 while (!IsNull (&FormSet->StorageListHead, Link)) {
2054 Storage = FORMSET_STORAGE_FROM_LINK (Link);
2055
2056 Status = LoadStorage (FormSet, Storage);
2057
2058 //
2059 // Now Edit Buffer is filled with default values(lower priority) and current
2060 // settings(higher priority), sychronize it to shadow Buffer
2061 //
2062 if (!EFI_ERROR (Status)) {
2063 SynchronizeStorage (Storage);
2064 }
2065
2066 Link = GetNextNode (&FormSet->StorageListHead, Link);
2067 }
2068
2069 return EFI_SUCCESS;
2070 }
2071
2072
2073 /**
2074 Fetch the Ifr binary data of a FormSet.
2075
2076 @param Handle PackageList Handle
2077 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2078 GUID), take the first FormSet found in package
2079 list.
2080 @param BinaryLength The length of the FormSet IFR binary.
2081 @param BinaryData The buffer designed to receive the FormSet.
2082
2083 @retval EFI_SUCCESS Buffer filled with the requested FormSet.
2084 BufferLength was updated.
2085 @retval EFI_INVALID_PARAMETER The handle is unknown.
2086 @retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
2087 be found with the requested FormId.
2088
2089 **/
2090 EFI_STATUS
2091 GetIfrBinaryData (
2092 IN EFI_HII_HANDLE Handle,
2093 IN OUT EFI_GUID *FormSetGuid,
2094 OUT UINTN *BinaryLength,
2095 OUT UINT8 **BinaryData
2096 )
2097 {
2098 EFI_STATUS Status;
2099 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
2100 UINTN BufferSize;
2101 UINT8 *Package;
2102 UINT8 *OpCodeData;
2103 UINT32 Offset;
2104 UINT32 Offset2;
2105 BOOLEAN ReturnDefault;
2106 UINT32 PackageListLength;
2107 EFI_HII_PACKAGE_HEADER PackageHeader;
2108
2109 OpCodeData = NULL;
2110 Package = NULL;
2111 ZeroMem (&PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));;
2112
2113 //
2114 // if FormSetGuid is NULL or zero GUID, return first FormSet in the package list
2115 //
2116 if (FormSetGuid == NULL || CompareGuid (FormSetGuid, &gZeroGuid)) {
2117 ReturnDefault = TRUE;
2118 } else {
2119 ReturnDefault = FALSE;
2120 }
2121
2122 //
2123 // Get HII PackageList
2124 //
2125 BufferSize = 0;
2126 HiiPackageList = NULL;
2127 Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);
2128 if (Status == EFI_BUFFER_TOO_SMALL) {
2129 HiiPackageList = AllocatePool (BufferSize);
2130 ASSERT (HiiPackageList != NULL);
2131
2132 Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);
2133 }
2134 if (EFI_ERROR (Status)) {
2135 return Status;
2136 }
2137
2138 //
2139 // Get Form package from this HII package List
2140 //
2141 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
2142 Offset2 = 0;
2143 CopyMem (&PackageListLength, &HiiPackageList->PackageLength, sizeof (UINT32));
2144
2145 while (Offset < PackageListLength) {
2146 Package = ((UINT8 *) HiiPackageList) + Offset;
2147 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
2148
2149 if (PackageHeader.Type == EFI_HII_PACKAGE_FORM) {
2150 //
2151 // Search FormSet in this Form Package
2152 //
2153 Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);
2154 while (Offset2 < PackageHeader.Length) {
2155 OpCodeData = Package + Offset2;
2156
2157 if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {
2158 //
2159 // Check whether return default FormSet
2160 //
2161 if (ReturnDefault) {
2162 break;
2163 }
2164
2165 //
2166 // FormSet GUID is specified, check it
2167 //
2168 if (CompareGuid (FormSetGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {
2169 break;
2170 }
2171 }
2172
2173 Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
2174 }
2175
2176 if (Offset2 < PackageHeader.Length) {
2177 //
2178 // Target formset found
2179 //
2180 break;
2181 }
2182 }
2183
2184 Offset += PackageHeader.Length;
2185 }
2186
2187 if (Offset >= PackageListLength) {
2188 //
2189 // Form package not found in this Package List
2190 //
2191 gBS->FreePool (HiiPackageList);
2192 return EFI_NOT_FOUND;
2193 }
2194
2195 if (ReturnDefault && FormSetGuid != NULL) {
2196 //
2197 // Return the default FormSet GUID
2198 //
2199 CopyMem (FormSetGuid, &((EFI_IFR_FORM_SET *) OpCodeData)->Guid, sizeof (EFI_GUID));
2200 }
2201
2202 //
2203 // To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
2204 // in this FormSet; So, here just simply copy the data from start of a FormSet to the end
2205 // of the Form Package.
2206 //
2207 *BinaryLength = PackageHeader.Length - Offset2;
2208 *BinaryData = AllocateCopyPool (*BinaryLength, OpCodeData);
2209
2210 gBS->FreePool (HiiPackageList);
2211
2212 if (*BinaryData == NULL) {
2213 return EFI_OUT_OF_RESOURCES;
2214 }
2215
2216 return EFI_SUCCESS;
2217 }
2218
2219
2220 /**
2221 Initialize the internal data structure of a FormSet.
2222
2223 @param Handle PackageList Handle
2224 @param FormSetGuid GUID of a formset. If not specified (NULL or zero
2225 GUID), take the first FormSet found in package
2226 list.
2227 @param FormSet FormSet data structure.
2228
2229 @retval EFI_SUCCESS The function completed successfully.
2230 @retval EFI_NOT_FOUND The specified FormSet could not be found.
2231
2232 **/
2233 EFI_STATUS
2234 InitializeFormSet (
2235 IN EFI_HII_HANDLE Handle,
2236 IN OUT EFI_GUID *FormSetGuid,
2237 OUT FORM_BROWSER_FORMSET *FormSet
2238 )
2239 {
2240 EFI_STATUS Status;
2241 EFI_HANDLE DriverHandle;
2242 UINT16 Index;
2243
2244 Status = GetIfrBinaryData (Handle, FormSetGuid, &FormSet->IfrBinaryLength, &FormSet->IfrBinaryData);
2245 if (EFI_ERROR (Status)) {
2246 return Status;
2247 }
2248
2249 FormSet->HiiHandle = Handle;
2250 CopyMem (&FormSet->Guid, FormSetGuid, sizeof (EFI_GUID));
2251
2252 //
2253 // Retrieve ConfigAccess Protocol associated with this HiiPackageList
2254 //
2255 Status = mHiiDatabase->GetPackageListHandle (mHiiDatabase, Handle, &DriverHandle);
2256 if (EFI_ERROR (Status)) {
2257 return Status;
2258 }
2259 FormSet->DriverHandle = DriverHandle;
2260 Status = gBS->HandleProtocol (
2261 DriverHandle,
2262 &gEfiHiiConfigAccessProtocolGuid,
2263 (VOID **) &FormSet->ConfigAccess
2264 );
2265 if (EFI_ERROR (Status)) {
2266 //
2267 // Configuration Driver don't attach ConfigAccess protocol to its HII package
2268 // list, then there will be no configuration action required
2269 //
2270 FormSet->ConfigAccess = NULL;
2271 }
2272
2273 //
2274 // Parse the IFR binary OpCodes
2275 //
2276 Status = ParseOpCodes (FormSet);
2277 if (EFI_ERROR (Status)) {
2278 return Status;
2279 }
2280
2281 gClassOfVfr = FormSet->SubClass;
2282 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {
2283 FrontPageHandle = FormSet->HiiHandle;
2284 }
2285
2286 //
2287 // Match GUID to find out the function key setting. If match fail, use the default setting.
2288 //
2289 for (Index = 0; Index < sizeof (gFunctionKeySettingTable) / sizeof (FUNCTIION_KEY_SETTING); Index++) {
2290 if (CompareGuid (&FormSet->Guid, &(gFunctionKeySettingTable[Index].FormSetGuid))) {
2291 //
2292 // Update the function key setting.
2293 //
2294 gFunctionKeySetting = gFunctionKeySettingTable[Index].KeySetting;
2295 //
2296 // Function key prompt can not be displayed if the function key has been disabled.
2297 //
2298 if ((gFunctionKeySetting & FUNCTION_ONE) != FUNCTION_ONE) {
2299 gFunctionOneString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2300 }
2301
2302 if ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO) {
2303 gFunctionTwoString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2304 }
2305
2306 if ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE) {
2307 gFunctionNineString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2308 }
2309
2310 if ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN) {
2311 gFunctionTenString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2312 }
2313 }
2314 }
2315
2316 return Status;
2317 }