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