]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
4cdbe5fb8808ea4086c8a7d1cc5e212a3792a1cc
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / DriverSample.c
1 /** @file
2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module Name:
12 DriverSample.c
13
14 Abstract:
15
16 This is an example of how a driver might export data to the HII protocol to be
17 later utilized by the Setup Protocol
18
19
20 **/
21
22
23 #include "DriverSample.h"
24
25 #define DISPLAY_ONLY_MY_ITEM 0x0002
26
27 EFI_GUID mFormSetGuid = FORMSET_GUID;
28 EFI_GUID mInventoryGuid = INVENTORY_GUID;
29
30 CHAR16 VariableName[] = L"MyIfrNVData";
31
32 VOID
33 EncodePassword (
34 IN CHAR16 *Password,
35 IN UINT8 MaxSize
36 )
37 {
38 UINTN Index;
39 UINTN Loop;
40 CHAR16 *Buffer;
41 CHAR16 *Key;
42
43 Key = L"MAR10648567";
44 Buffer = AllocateZeroPool (MaxSize);
45 ASSERT (Buffer != NULL);
46
47 for (Index = 0; Key[Index] != 0; Index++) {
48 for (Loop = 0; Loop < (UINT8) (MaxSize / 2); Loop++) {
49 Buffer[Loop] = (CHAR16) (Password[Loop] ^ Key[Index]);
50 }
51 }
52
53 CopyMem (Password, Buffer, MaxSize);
54
55 gBS->FreePool (Buffer);
56 return ;
57 }
58
59 EFI_STATUS
60 ValidatePassword (
61 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
62 EFI_STRING_ID StringId
63 )
64 {
65 EFI_STATUS Status;
66 UINTN Index;
67 UINTN BufferSize;
68 CHAR16 *Password;
69 CHAR16 *EncodedPassword;
70 BOOLEAN OldPassword;
71
72 //
73 // Get encoded password first
74 //
75 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
76 Status = gRT->GetVariable (
77 VariableName,
78 &mFormSetGuid,
79 NULL,
80 &BufferSize,
81 &PrivateData->Configuration
82 );
83 if (EFI_ERROR (Status)) {
84 //
85 // Old password not exist, prompt for new password
86 //
87 return EFI_SUCCESS;
88 }
89
90 OldPassword = FALSE;
91 //
92 // Check whether we have any old password set
93 //
94 for (Index = 0; Index < 20; Index++) {
95 if (PrivateData->Configuration.WhatIsThePassword2[Index] != 0) {
96 OldPassword = TRUE;
97 break;
98 }
99 }
100 if (!OldPassword) {
101 //
102 // Old password not exist, return EFI_SUCCESS to prompt for new password
103 //
104 return EFI_SUCCESS;
105 }
106
107 //
108 // Get user input password
109 //
110 BufferSize = 21 * sizeof (CHAR16);
111 Password = AllocateZeroPool (BufferSize);
112 ASSERT (Password != NULL);
113
114 Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize);
115 if (EFI_ERROR (Status)) {
116 gBS->FreePool (Password);
117 return Status;
118 }
119
120 //
121 // Validate old password
122 //
123 EncodedPassword = AllocateCopyPool (21 * sizeof (CHAR16), Password);
124 ASSERT (EncodedPassword != NULL);
125 EncodePassword (EncodedPassword, 20 * sizeof (CHAR16));
126 if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, 20 * sizeof (CHAR16)) != 0) {
127 //
128 // Old password mismatch, return EFI_NOT_READY to prompt for error message
129 //
130 Status = EFI_NOT_READY;
131 } else {
132 Status = EFI_SUCCESS;
133 }
134
135 gBS->FreePool (Password);
136 gBS->FreePool (EncodedPassword);
137
138 return Status;
139 }
140
141 EFI_STATUS
142 SetPassword (
143 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
144 EFI_STRING_ID StringId
145 )
146 {
147 EFI_STATUS Status;
148 UINTN BufferSize;
149 CHAR16 *Password;
150 DRIVER_SAMPLE_CONFIGURATION *Configuration;
151
152 //
153 // Get Buffer Storage data from EFI variable
154 //
155 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
156 Status = gRT->GetVariable (
157 VariableName,
158 &mFormSetGuid,
159 NULL,
160 &BufferSize,
161 &PrivateData->Configuration
162 );
163 if (EFI_ERROR (Status)) {
164 return Status;
165 }
166
167 //
168 // Get user input password
169 //
170 Password = &PrivateData->Configuration.WhatIsThePassword2[0];
171 ZeroMem (Password, 20 * sizeof (CHAR16));
172 Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize);
173 if (EFI_ERROR (Status)) {
174 return Status;
175 }
176
177 //
178 // Retrive uncommitted data from Browser
179 //
180 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
181 Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
182 ASSERT (Configuration != NULL);
183 Status = GetBrowserData (&mFormSetGuid, VariableName, &BufferSize, (UINT8 *) Configuration);
184 if (!EFI_ERROR (Status)) {
185 //
186 // Update password's clear text in the screen
187 //
188 CopyMem (Configuration->PasswordClearText, Password, 20 * sizeof (CHAR16));
189
190 //
191 // Update uncommitted data of Browser
192 //
193 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
194 Status = SetBrowserData (
195 &mFormSetGuid,
196 VariableName,
197 BufferSize,
198 (UINT8 *) Configuration,
199 NULL
200 );
201 }
202 gBS->FreePool (Configuration);
203
204 //
205 // Set password
206 //
207 EncodePassword (Password, 20 * sizeof (CHAR16));
208 Status = gRT->SetVariable(
209 VariableName,
210 &mFormSetGuid,
211 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
212 sizeof (DRIVER_SAMPLE_CONFIGURATION),
213 &PrivateData->Configuration
214 );
215 return Status;
216 }
217
218
219 /**
220 This function allows a caller to extract the current configuration for one
221 or more named elements from the target driver.
222
223 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
224 @param Request A null-terminated Unicode string in
225 <ConfigRequest> format.
226 @param Progress On return, points to a character in the Request
227 string. Points to the string's null terminator if
228 request was successful. Points to the most recent
229 '&' before the first failing name/value pair (or
230 the beginning of the string if the failure is in
231 the first name/value pair) if the request was not
232 successful.
233 @param Results A null-terminated Unicode string in
234 <ConfigAltResp> format which has all values filled
235 in for the names in the Request string. String to
236 be allocated by the called function.
237
238 @retval EFI_SUCCESS The Results is filled with the requested values.
239 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
240 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
241 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
242 driver.
243
244 **/
245 EFI_STATUS
246 EFIAPI
247 ExtractConfig (
248 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
249 IN CONST EFI_STRING Request,
250 OUT EFI_STRING *Progress,
251 OUT EFI_STRING *Results
252 )
253 {
254 EFI_STATUS Status;
255 UINTN BufferSize;
256 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
257 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
258
259 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
260 HiiConfigRouting = PrivateData->HiiConfigRouting;
261
262 //
263 // Get Buffer Storage data from EFI variable
264 //
265 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
266 Status = gRT->GetVariable (
267 VariableName,
268 &mFormSetGuid,
269 NULL,
270 &BufferSize,
271 &PrivateData->Configuration
272 );
273 if (EFI_ERROR (Status)) {
274 return Status;
275 }
276
277 //
278 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
279 //
280 Status = HiiConfigRouting->BlockToConfig (
281 HiiConfigRouting,
282 Request,
283 (UINT8 *) &PrivateData->Configuration,
284 BufferSize,
285 Results,
286 Progress
287 );
288 return Status;
289 }
290
291
292 /**
293 This function processes the results of changes in configuration.
294
295 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
296 @param Configuration A null-terminated Unicode string in <ConfigResp>
297 format.
298 @param Progress A pointer to a string filled in with the offset of
299 the most recent '&' before the first failing
300 name/value pair (or the beginning of the string if
301 the failure is in the first name/value pair) or
302 the terminating NULL if all was successful.
303
304 @retval EFI_SUCCESS The Results is processed successfully.
305 @retval EFI_INVALID_PARAMETER Configuration is NULL.
306 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
307 driver.
308
309 **/
310 EFI_STATUS
311 EFIAPI
312 RouteConfig (
313 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
314 IN CONST EFI_STRING Configuration,
315 OUT EFI_STRING *Progress
316 )
317 {
318 EFI_STATUS Status;
319 UINTN BufferSize;
320 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
321 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
322
323 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
324 HiiConfigRouting = PrivateData->HiiConfigRouting;
325
326 //
327 // Get Buffer Storage data from EFI variable
328 //
329 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
330 Status = gRT->GetVariable (
331 VariableName,
332 &mFormSetGuid,
333 NULL,
334 &BufferSize,
335 &PrivateData->Configuration
336 );
337 if (EFI_ERROR (Status)) {
338 return Status;
339 }
340
341 //
342 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
343 //
344 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
345 Status = HiiConfigRouting->ConfigToBlock (
346 HiiConfigRouting,
347 Configuration,
348 (UINT8 *) &PrivateData->Configuration,
349 &BufferSize,
350 Progress
351 );
352 if (EFI_ERROR (Status)) {
353 return Status;
354 }
355
356 //
357 // Store Buffer Storage back to EFI variable
358 //
359 Status = gRT->SetVariable(
360 VariableName,
361 &mFormSetGuid,
362 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
363 sizeof (DRIVER_SAMPLE_CONFIGURATION),
364 &PrivateData->Configuration
365 );
366
367 return Status;
368 }
369
370
371 /**
372 This function processes the results of changes in configuration.
373
374 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
375 @param Action Specifies the type of action taken by the browser.
376 @param QuestionId A unique value which is sent to the original
377 exporting driver so that it can identify the type
378 of data to expect.
379 @param Type The type of value for the question.
380 @param Value A pointer to the data being sent to the original
381 exporting driver.
382 @param ActionRequest On return, points to the action requested by the
383 callback function.
384
385 @retval EFI_SUCCESS The callback successfully handled the action.
386 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
387 variable and its data.
388 @retval EFI_DEVICE_ERROR The variable could not be saved.
389 @retval EFI_UNSUPPORTED The specified Action is not supported by the
390 callback.
391
392 **/
393 EFI_STATUS
394 EFIAPI
395 DriverCallback (
396 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
397 IN EFI_BROWSER_ACTION Action,
398 IN EFI_QUESTION_ID QuestionId,
399 IN UINT8 Type,
400 IN EFI_IFR_TYPE_VALUE *Value,
401 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
402 )
403 {
404 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
405 EFI_STATUS Status;
406 EFI_HII_UPDATE_DATA UpdateData;
407 IFR_OPTION *IfrOptionList;
408
409 if ((Value == NULL) || (ActionRequest == NULL)) {
410 return EFI_INVALID_PARAMETER;
411 }
412
413 Status = EFI_SUCCESS;
414 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
415
416 switch (QuestionId) {
417 case 0x1234:
418 //
419 // Create dynamic page for this interactive goto
420 //
421 UpdateData.BufferSize = 0x1000;
422 UpdateData.Offset = 0;
423 UpdateData.Data = AllocatePool (0x1000);
424 ASSERT (UpdateData.Data != NULL);
425
426 IfrOptionList = AllocatePool (2 * sizeof (IFR_OPTION));
427 ASSERT (IfrOptionList != NULL);
428
429 IfrOptionList[0].Flags = 0;
430 IfrOptionList[0].StringToken = STRING_TOKEN (STR_BOOT_OPTION1);
431 IfrOptionList[0].Value.u8 = 1;
432 IfrOptionList[1].Flags = EFI_IFR_OPTION_DEFAULT;
433 IfrOptionList[1].StringToken = STRING_TOKEN (STR_BOOT_OPTION2);
434 IfrOptionList[1].Value.u8 = 2;
435
436 CreateActionOpCode (
437 0x1237,
438 STRING_TOKEN(STR_EXIT_TEXT),
439 STRING_TOKEN(STR_EXIT_TEXT),
440 EFI_IFR_FLAG_CALLBACK,
441 0,
442 &UpdateData
443 );
444
445 CreateOneOfOpCode (
446 0x8001,
447 0,
448 0,
449 STRING_TOKEN (STR_ONE_OF_PROMPT),
450 STRING_TOKEN (STR_ONE_OF_HELP),
451 EFI_IFR_FLAG_CALLBACK,
452 EFI_IFR_NUMERIC_SIZE_1,
453 IfrOptionList,
454 2,
455 &UpdateData
456 );
457
458 CreateOrderedListOpCode (
459 0x8002,
460 0,
461 0,
462 STRING_TOKEN (STR_BOOT_OPTIONS),
463 STRING_TOKEN (STR_BOOT_OPTIONS),
464 EFI_IFR_FLAG_RESET_REQUIRED,
465 0,
466 EFI_IFR_NUMERIC_SIZE_1,
467 10,
468 IfrOptionList,
469 2,
470 &UpdateData
471 );
472
473 CreateGotoOpCode (
474 1,
475 STRING_TOKEN (STR_GOTO_FORM1),
476 STRING_TOKEN (STR_GOTO_HELP),
477 0,
478 0x8003,
479 &UpdateData
480 );
481
482 Status = IfrLibUpdateForm (
483 PrivateData->HiiHandle[0],
484 &mFormSetGuid,
485 0x1234,
486 0x1234,
487 TRUE,
488 &UpdateData
489 );
490 gBS->FreePool (IfrOptionList);
491 gBS->FreePool (UpdateData.Data);
492 break;
493
494 case 0x1237:
495 //
496 // User press "Exit now", request Browser to exit
497 //
498 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
499 break;
500
501 case 0x1238:
502 //
503 // User press "Save now", request Browser to save the uncommitted data.
504 //
505 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
506 break;
507
508 case 0x2000:
509 //
510 // When try to set a new password, user will be chanlleged with old password.
511 // The Callback is responsible for validating old password input by user,
512 // If Callback return EFI_SUCCESS, it indicates validation pass.
513 //
514 switch (PrivateData->PasswordState) {
515 case BROWSER_STATE_VALIDATE_PASSWORD:
516 Status = ValidatePassword (PrivateData, Value->string);
517 if (Status == EFI_SUCCESS) {
518 PrivateData->PasswordState = BROWSER_STATE_SET_PASSWORD;
519 }
520 break;
521
522 case BROWSER_STATE_SET_PASSWORD:
523 Status = SetPassword (PrivateData, Value->string);
524 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
525 break;
526
527 default:
528 break;
529 }
530
531 break;
532
533 default:
534 break;
535 }
536
537 return Status;
538 }
539
540 EFI_STATUS
541 EFIAPI
542 DriverSampleInit (
543 IN EFI_HANDLE ImageHandle,
544 IN EFI_SYSTEM_TABLE *SystemTable
545 )
546 {
547 EFI_STATUS Status;
548 EFI_STATUS SavedStatus;
549 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
550 EFI_HII_HANDLE HiiHandle[2];
551 EFI_HANDLE DriverHandle[2];
552 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
553 EFI_SCREEN_DESCRIPTOR Screen;
554 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
555 EFI_HII_STRING_PROTOCOL *HiiString;
556 EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
557 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
558 CHAR16 *NewString;
559 UINTN BufferSize;
560 DRIVER_SAMPLE_CONFIGURATION *Configuration;
561 BOOLEAN ExtractIfrDefault;
562
563 //
564 // Initialize the library and our protocol.
565 //
566 //@MT: EfiInitializeDriverLib (ImageHandle, SystemTable);
567
568 //
569 // Initialize screen dimensions for SendForm().
570 // Remove 3 characters from top and bottom
571 //
572 ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
573 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);
574
575 Screen.TopRow = 3;
576 Screen.BottomRow = Screen.BottomRow - 3;
577
578 //
579 // Initialize driver private data
580 //
581 PrivateData = AllocatePool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
582 if (PrivateData == NULL) {
583 return EFI_OUT_OF_RESOURCES;
584 }
585
586 PrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;
587
588 PrivateData->ConfigAccess.ExtractConfig = ExtractConfig;
589 PrivateData->ConfigAccess.RouteConfig = RouteConfig;
590 PrivateData->ConfigAccess.Callback = DriverCallback;
591 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
592
593 //
594 // Locate Hii Database protocol
595 //
596 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase);
597 if (EFI_ERROR (Status)) {
598 return Status;
599 }
600 PrivateData->HiiDatabase = HiiDatabase;
601
602 //
603 // Locate HiiString protocol
604 //
605 Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString);
606 if (EFI_ERROR (Status)) {
607 return Status;
608 }
609 PrivateData->HiiString = HiiString;
610
611 //
612 // Locate Formbrowser2 protocol
613 //
614 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
615 if (EFI_ERROR (Status)) {
616 return Status;
617 }
618 PrivateData->FormBrowser2 = FormBrowser2;
619
620 //
621 // Locate ConfigRouting protocol
622 //
623 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);
624 if (EFI_ERROR (Status)) {
625 return Status;
626 }
627 PrivateData->HiiConfigRouting = HiiConfigRouting;
628
629 //
630 // Install Config Access protocol
631 //
632 Status = HiiLibCreateHiiDriverHandle (&DriverHandle[0]);
633 if (EFI_ERROR (Status)) {
634 return Status;
635 }
636 PrivateData->DriverHandle[0] = DriverHandle[0];
637
638 Status = gBS->InstallProtocolInterface (
639 &DriverHandle[0],
640 &gEfiHiiConfigAccessProtocolGuid,
641 EFI_NATIVE_INTERFACE,
642 &PrivateData->ConfigAccess
643 );
644 ASSERT_EFI_ERROR (Status);
645
646 //
647 // Publish our HII data
648 //
649 PackageList = HiiLibPreparePackageList (
650 2,
651 &mFormSetGuid,
652 DriverSampleStrings,
653 VfrBin
654 );
655 if (PackageList == NULL) {
656 return EFI_OUT_OF_RESOURCES;
657 }
658
659 Status = HiiDatabase->NewPackageList (
660 HiiDatabase,
661 PackageList,
662 DriverHandle[0],
663 &HiiHandle[0]
664 );
665 gBS->FreePool (PackageList);
666 if (EFI_ERROR (Status)) {
667 return Status;
668 }
669 PrivateData->HiiHandle[0] = HiiHandle[0];
670
671 //
672 // Publish another Fromset
673 //
674 Status = HiiLibCreateHiiDriverHandle (&DriverHandle[1]);
675 if (EFI_ERROR (Status)) {
676 return Status;
677 }
678 PrivateData->DriverHandle[1] = DriverHandle[1];
679
680 PackageList = HiiLibPreparePackageList (
681 2,
682 &mInventoryGuid,
683 DriverSampleStrings,
684 InventoryBin
685 );
686 if (PackageList == NULL) {
687 return EFI_OUT_OF_RESOURCES;
688 }
689
690 Status = HiiDatabase->NewPackageList (
691 HiiDatabase,
692 PackageList,
693 DriverHandle[1],
694 &HiiHandle[1]
695 );
696 gBS->FreePool (PackageList);
697 if (EFI_ERROR (Status)) {
698 return Status;
699 }
700 PrivateData->HiiHandle[1] = HiiHandle[1];
701
702 //
703 // Very simple example of how one would update a string that is already
704 // in the HII database
705 //
706 NewString = L"700 Mhz";
707
708 Status = HiiLibSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString);
709 if (EFI_ERROR (Status)) {
710 return Status;
711 }
712
713 //
714 // Initialize configuration data
715 //
716 Configuration = &PrivateData->Configuration;
717 ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));
718
719 //
720 // Try to read NV config EFI variable first
721 //
722 ExtractIfrDefault = TRUE;
723 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
724 Status = gRT->GetVariable (VariableName, &mFormSetGuid, NULL, &BufferSize, Configuration);
725 if (!EFI_ERROR (Status) && (BufferSize == sizeof (DRIVER_SAMPLE_CONFIGURATION))) {
726 ExtractIfrDefault = FALSE;
727 }
728
729 if (ExtractIfrDefault) {
730 //
731 // EFI variable for NV config doesn't exit, we should build this variable
732 // based on default values stored in IFR
733 //
734 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
735 Status = IfrLibExtractDefault (Configuration, &BufferSize, 1, VfrMyIfrNVDataDefault0000);
736
737 if (!EFI_ERROR (Status)) {
738 gRT->SetVariable(
739 VariableName,
740 &mFormSetGuid,
741 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
742 sizeof (DRIVER_SAMPLE_CONFIGURATION),
743 Configuration
744 );
745 }
746 }
747
748 //
749 // Example of how to display only the item we sent to HII
750 //
751 if (DISPLAY_ONLY_MY_ITEM == 0x0001) {
752 //
753 // Have the browser pull out our copy of the data, and only display our data
754 //
755 // Status = FormConfig->SendForm (FormConfig, TRUE, HiiHandle, NULL, NULL, NULL, &Screen, NULL);
756 //
757 Status = FormBrowser2->SendForm (
758 FormBrowser2,
759 HiiHandle,
760 1,
761 NULL,
762 0,
763 NULL,
764 NULL
765 );
766 SavedStatus = Status;
767
768 Status = HiiDatabase->RemovePackageList (HiiDatabase, HiiHandle[0]);
769 if (EFI_ERROR (Status)) {
770 return Status;
771 }
772
773 Status = HiiDatabase->RemovePackageList (HiiDatabase, HiiHandle[1]);
774 if (EFI_ERROR (Status)) {
775 return Status;
776 }
777
778 return SavedStatus;
779 } else {
780 //
781 // Have the browser pull out all the data in the HII Database and display it.
782 //
783 // Status = FormConfig->SendForm (FormConfig, TRUE, 0, NULL, NULL, NULL, NULL, NULL);
784 //
785 }
786
787 return EFI_SUCCESS;
788 }