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