]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
1) Add BufToHexString, HexStringToBuf and IsHexDigit to BaseLib.
[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
567 //
568 // Initialize screen dimensions for SendForm().
569 // Remove 3 characters from top and bottom
570 //
571 ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
572 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);
573
574 Screen.TopRow = 3;
575 Screen.BottomRow = Screen.BottomRow - 3;
576
577 //
578 // Initialize driver private data
579 //
580 PrivateData = AllocatePool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
581 if (PrivateData == NULL) {
582 return EFI_OUT_OF_RESOURCES;
583 }
584
585 PrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;
586
587 PrivateData->ConfigAccess.ExtractConfig = ExtractConfig;
588 PrivateData->ConfigAccess.RouteConfig = RouteConfig;
589 PrivateData->ConfigAccess.Callback = DriverCallback;
590 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
591
592 //
593 // Locate Hii Database protocol
594 //
595 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase);
596 if (EFI_ERROR (Status)) {
597 return Status;
598 }
599 PrivateData->HiiDatabase = HiiDatabase;
600
601 //
602 // Locate HiiString protocol
603 //
604 Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString);
605 if (EFI_ERROR (Status)) {
606 return Status;
607 }
608 PrivateData->HiiString = HiiString;
609
610 //
611 // Locate Formbrowser2 protocol
612 //
613 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
614 if (EFI_ERROR (Status)) {
615 return Status;
616 }
617 PrivateData->FormBrowser2 = FormBrowser2;
618
619 //
620 // Locate ConfigRouting protocol
621 //
622 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);
623 if (EFI_ERROR (Status)) {
624 return Status;
625 }
626 PrivateData->HiiConfigRouting = HiiConfigRouting;
627
628 //
629 // Install Config Access protocol
630 //
631 Status = HiiLibCreateHiiDriverHandle (&DriverHandle[0]);
632 if (EFI_ERROR (Status)) {
633 return Status;
634 }
635 PrivateData->DriverHandle[0] = DriverHandle[0];
636
637 Status = gBS->InstallProtocolInterface (
638 &DriverHandle[0],
639 &gEfiHiiConfigAccessProtocolGuid,
640 EFI_NATIVE_INTERFACE,
641 &PrivateData->ConfigAccess
642 );
643 ASSERT_EFI_ERROR (Status);
644
645 //
646 // Publish our HII data
647 //
648 PackageList = HiiLibPreparePackageList (
649 2,
650 &mFormSetGuid,
651 DriverSampleStrings,
652 VfrBin
653 );
654 if (PackageList == NULL) {
655 return EFI_OUT_OF_RESOURCES;
656 }
657
658 Status = HiiDatabase->NewPackageList (
659 HiiDatabase,
660 PackageList,
661 DriverHandle[0],
662 &HiiHandle[0]
663 );
664 gBS->FreePool (PackageList);
665 if (EFI_ERROR (Status)) {
666 return Status;
667 }
668 PrivateData->HiiHandle[0] = HiiHandle[0];
669
670 //
671 // Publish another Fromset
672 //
673 Status = HiiLibCreateHiiDriverHandle (&DriverHandle[1]);
674 if (EFI_ERROR (Status)) {
675 return Status;
676 }
677 PrivateData->DriverHandle[1] = DriverHandle[1];
678
679 PackageList = HiiLibPreparePackageList (
680 2,
681 &mInventoryGuid,
682 DriverSampleStrings,
683 InventoryBin
684 );
685 if (PackageList == NULL) {
686 return EFI_OUT_OF_RESOURCES;
687 }
688
689 Status = HiiDatabase->NewPackageList (
690 HiiDatabase,
691 PackageList,
692 DriverHandle[1],
693 &HiiHandle[1]
694 );
695 gBS->FreePool (PackageList);
696 if (EFI_ERROR (Status)) {
697 return Status;
698 }
699 PrivateData->HiiHandle[1] = HiiHandle[1];
700
701 //
702 // Very simple example of how one would update a string that is already
703 // in the HII database
704 //
705 NewString = L"700 Mhz";
706
707 Status = HiiLibSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString);
708 if (EFI_ERROR (Status)) {
709 return Status;
710 }
711
712 //
713 // Initialize configuration data
714 //
715 Configuration = &PrivateData->Configuration;
716 ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));
717
718 //
719 // Try to read NV config EFI variable first
720 //
721 ExtractIfrDefault = TRUE;
722 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
723 Status = gRT->GetVariable (VariableName, &mFormSetGuid, NULL, &BufferSize, Configuration);
724 if (!EFI_ERROR (Status) && (BufferSize == sizeof (DRIVER_SAMPLE_CONFIGURATION))) {
725 ExtractIfrDefault = FALSE;
726 }
727
728 if (ExtractIfrDefault) {
729 //
730 // EFI variable for NV config doesn't exit, we should build this variable
731 // based on default values stored in IFR
732 //
733 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
734 Status = IfrLibExtractDefault (Configuration, &BufferSize, 1, VfrMyIfrNVDataDefault0000);
735
736 if (!EFI_ERROR (Status)) {
737 gRT->SetVariable(
738 VariableName,
739 &mFormSetGuid,
740 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
741 sizeof (DRIVER_SAMPLE_CONFIGURATION),
742 Configuration
743 );
744 }
745 }
746
747 //
748 // Example of how to display only the item we sent to HII
749 //
750 if (DISPLAY_ONLY_MY_ITEM == 0x0001) {
751 //
752 // Have the browser pull out our copy of the data, and only display our data
753 //
754 // Status = FormConfig->SendForm (FormConfig, TRUE, HiiHandle, NULL, NULL, NULL, &Screen, NULL);
755 //
756 Status = FormBrowser2->SendForm (
757 FormBrowser2,
758 HiiHandle,
759 1,
760 NULL,
761 0,
762 NULL,
763 NULL
764 );
765 SavedStatus = Status;
766
767 Status = HiiDatabase->RemovePackageList (HiiDatabase, HiiHandle[0]);
768 if (EFI_ERROR (Status)) {
769 return Status;
770 }
771
772 Status = HiiDatabase->RemovePackageList (HiiDatabase, HiiHandle[1]);
773 if (EFI_ERROR (Status)) {
774 return Status;
775 }
776
777 return SavedStatus;
778 } else {
779 //
780 // Have the browser pull out all the data in the HII Database and display it.
781 //
782 // Status = FormConfig->SendForm (FormConfig, TRUE, 0, NULL, NULL, NULL, NULL, NULL);
783 //
784 }
785
786 return EFI_SUCCESS;
787 }