]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
Retire Extended HII library class.
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / DriverSample.c
1 /** @file
2 This is an example of how a driver might export data to the HII protocol to be
3 later utilized by the Setup Protocol
4
5 Copyright (c) 2004 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include "DriverSample.h"
18
19 #define DISPLAY_ONLY_MY_ITEM 0x0002
20
21 EFI_GUID mFormSetGuid = FORMSET_GUID;
22 EFI_GUID mInventoryGuid = INVENTORY_GUID;
23
24 CHAR16 VariableName[] = L"MyIfrNVData";
25
26 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
27 {
28 {
29 HARDWARE_DEVICE_PATH,
30 HW_VENDOR_DP,
31 {
32 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
33 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
34 }
35 },
36 //
37 // {C153B68D-EBFC-488e-B110-662867745B87}
38 //
39 { 0xc153b68d, 0xebfc, 0x488e, { 0xb1, 0x10, 0x66, 0x28, 0x67, 0x74, 0x5b, 0x87 } }
40 },
41 {
42 END_DEVICE_PATH_TYPE,
43 END_ENTIRE_DEVICE_PATH_SUBTYPE,
44 {
45 (UINT8) (END_DEVICE_PATH_LENGTH),
46 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
47 }
48 }
49 };
50
51 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath2 = {
52 {
53 {
54 HARDWARE_DEVICE_PATH,
55 HW_VENDOR_DP,
56 {
57 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
58 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
59 }
60 },
61 //
62 // {06F37F07-0C48-40e9-8436-0A08A0BB76B0}
63 //
64 { 0x6f37f07, 0xc48, 0x40e9, { 0x84, 0x36, 0xa, 0x8, 0xa0, 0xbb, 0x76, 0xb0 } }
65 },
66 {
67 END_DEVICE_PATH_TYPE,
68 END_ENTIRE_DEVICE_PATH_SUBTYPE,
69 {
70 (UINT8) (END_DEVICE_PATH_LENGTH),
71 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
72 }
73 }
74 };
75
76 /**
77 Encode the password using a simple algorithm.
78
79 @param Password The string to be encoded.
80 @param MaxSize The size of the string.
81
82 **/
83 VOID
84 EncodePassword (
85 IN CHAR16 *Password,
86 IN UINTN MaxSize
87 )
88 {
89 UINTN Index;
90 UINTN Loop;
91 CHAR16 *Buffer;
92 CHAR16 *Key;
93
94 Key = L"MAR10648567";
95 Buffer = AllocateZeroPool (MaxSize);
96 ASSERT (Buffer != NULL);
97
98 for (Index = 0; Key[Index] != 0; Index++) {
99 for (Loop = 0; Loop < (UINT8) (MaxSize / 2); Loop++) {
100 Buffer[Loop] = (CHAR16) (Password[Loop] ^ Key[Index]);
101 }
102 }
103
104 CopyMem (Password, Buffer, MaxSize);
105
106 FreePool (Buffer);
107 return ;
108 }
109
110 /**
111 Validate the user's password.
112
113 @param PrivateData This driver's private context data.
114 @param StringId The user's input.
115
116 @retval EFI_SUCCESS The user's input matches the password.
117 @retval EFI_NOT_READY The user's input does not match the password.
118 **/
119 EFI_STATUS
120 ValidatePassword (
121 IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
122 IN EFI_STRING_ID StringId
123 )
124 {
125 EFI_STATUS Status;
126 UINTN Index;
127 UINTN BufferSize;
128 CHAR16 *Password;
129 CHAR16 *EncodedPassword;
130 BOOLEAN OldPassword;
131
132 //
133 // Get encoded password first
134 //
135 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
136 Status = gRT->GetVariable (
137 VariableName,
138 &mFormSetGuid,
139 NULL,
140 &BufferSize,
141 &PrivateData->Configuration
142 );
143 if (EFI_ERROR (Status)) {
144 //
145 // Old password not exist, prompt for new password
146 //
147 return EFI_SUCCESS;
148 }
149
150 OldPassword = FALSE;
151 //
152 // Check whether we have any old password set
153 //
154 for (Index = 0; Index < 20; Index++) {
155 if (PrivateData->Configuration.WhatIsThePassword2[Index] != 0) {
156 OldPassword = TRUE;
157 break;
158 }
159 }
160 if (!OldPassword) {
161 //
162 // Old password not exist, return EFI_SUCCESS to prompt for new password
163 //
164 return EFI_SUCCESS;
165 }
166
167 //
168 // Get user input password
169 //
170 BufferSize = 21 * sizeof (CHAR16);
171 Password = AllocateZeroPool (BufferSize);
172 ASSERT (Password != NULL);
173
174 Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize);
175 if (EFI_ERROR (Status)) {
176 FreePool (Password);
177 return Status;
178 }
179
180 //
181 // Validate old password
182 //
183 EncodedPassword = AllocateCopyPool (21 * sizeof (CHAR16), Password);
184 ASSERT (EncodedPassword != NULL);
185 EncodePassword (EncodedPassword, 20 * sizeof (CHAR16));
186 if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, 20 * sizeof (CHAR16)) != 0) {
187 //
188 // Old password mismatch, return EFI_NOT_READY to prompt for error message
189 //
190 Status = EFI_NOT_READY;
191 } else {
192 Status = EFI_SUCCESS;
193 }
194
195 FreePool (Password);
196 FreePool (EncodedPassword);
197
198 return Status;
199 }
200
201 /**
202 Encode the password using a simple algorithm.
203
204 @param PrivateData This driver's private context data.
205 @param StringId The password from User.
206
207 @retval EFI_SUCESS The operation is successful.
208 @return Other value if gRT->SetVariable () fails.
209
210 **/
211 EFI_STATUS
212 SetPassword (
213 IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
214 IN EFI_STRING_ID StringId
215 )
216 {
217 EFI_STATUS Status;
218 UINTN BufferSize;
219 CHAR16 *Password;
220 UINTN PasswordSize;
221 DRIVER_SAMPLE_CONFIGURATION *Configuration;
222
223 //
224 // Get Buffer Storage data from EFI variable
225 //
226 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
227 Status = gRT->GetVariable (
228 VariableName,
229 &mFormSetGuid,
230 NULL,
231 &BufferSize,
232 &PrivateData->Configuration
233 );
234 if (EFI_ERROR (Status)) {
235 return Status;
236 }
237
238 //
239 // Get user input password
240 //
241 Password = &PrivateData->Configuration.WhatIsThePassword2[0];
242 PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
243
244 ZeroMem (Password, PasswordSize);
245 Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize);
246 if (EFI_ERROR (Status)) {
247 return Status;
248 }
249
250 //
251 // Retrive uncommitted data from Browser
252 //
253 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
254 Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
255 ASSERT (Configuration != NULL);
256 Status = GetBrowserData (&mFormSetGuid, VariableName, &BufferSize, (UINT8 *) Configuration);
257 if (!EFI_ERROR (Status)) {
258 //
259 // Update password's clear text in the screen
260 //
261 CopyMem (Configuration->PasswordClearText, Password, PasswordSize);
262
263 //
264 // Update uncommitted data of Browser
265 //
266 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
267 Status = SetBrowserData (
268 &mFormSetGuid,
269 VariableName,
270 BufferSize,
271 (UINT8 *) Configuration,
272 NULL
273 );
274 }
275 FreePool (Configuration);
276
277 //
278 // Set password
279 //
280 EncodePassword (Password, PasswordSize);
281 Status = gRT->SetVariable(
282 VariableName,
283 &mFormSetGuid,
284 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
285 sizeof (DRIVER_SAMPLE_CONFIGURATION),
286 &PrivateData->Configuration
287 );
288 return Status;
289 }
290
291
292 /**
293 This function allows a caller to extract the current configuration for one
294 or more named elements from the target driver.
295
296 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
297 @param Request A null-terminated Unicode string in
298 <ConfigRequest> format.
299 @param Progress On return, points to a character in the Request
300 string. Points to the string's null terminator if
301 request was successful. Points to the most recent
302 '&' before the first failing name/value pair (or
303 the beginning of the string if the failure is in
304 the first name/value pair) if the request was not
305 successful.
306 @param Results A null-terminated Unicode string in
307 <ConfigAltResp> format which has all values filled
308 in for the names in the Request string. String to
309 be allocated by the called function.
310
311 @retval EFI_SUCCESS The Results is filled with the requested values.
312 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
313 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
314 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
315 driver.
316
317 **/
318 EFI_STATUS
319 EFIAPI
320 ExtractConfig (
321 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
322 IN CONST EFI_STRING Request,
323 OUT EFI_STRING *Progress,
324 OUT EFI_STRING *Results
325 )
326 {
327 EFI_STATUS Status;
328 UINTN BufferSize;
329 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
330 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
331
332 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
333 HiiConfigRouting = PrivateData->HiiConfigRouting;
334
335 //
336 //
337 // Get Buffer Storage data from EFI variable
338 //
339 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
340 Status = gRT->GetVariable (
341 VariableName,
342 &mFormSetGuid,
343 NULL,
344 &BufferSize,
345 &PrivateData->Configuration
346 );
347 if (EFI_ERROR (Status)) {
348 return Status;
349 }
350
351 if (Request == NULL) {
352 //
353 // Request is set to NULL, return all configurable elements together with ALTCFG
354 //
355 Status = ConstructConfigAltResp (
356 NULL,
357 NULL,
358 Results,
359 &mFormSetGuid,
360 VariableName,
361 PrivateData->DriverHandle[0],
362 &PrivateData->Configuration,
363 BufferSize,
364 VfrMyIfrNVDataBlockName,
365 2,
366 STRING_TOKEN (STR_STANDARD_DEFAULT_PROMPT),
367 VfrMyIfrNVDataDefault0000,
368 STRING_TOKEN (STR_MANUFACTURE_DEFAULT_PROMPT),
369 VfrMyIfrNVDataDefault0001
370 );
371
372 return Status;
373 }
374
375 //
376 // Check routing data in <ConfigHdr>.
377 // Note: if only one Storage is used, then this checking could be skipped.
378 //
379 if (!IsConfigHdrMatch (Request, &mFormSetGuid, VariableName)) {
380 *Progress = Request;
381 return EFI_NOT_FOUND;
382 }
383
384 //
385 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
386 //
387 Status = HiiConfigRouting->BlockToConfig (
388 HiiConfigRouting,
389 Request,
390 (UINT8 *) &PrivateData->Configuration,
391 BufferSize,
392 Results,
393 Progress
394 );
395 return Status;
396 }
397
398
399 /**
400 This function processes the results of changes in configuration.
401
402 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
403 @param Configuration A null-terminated Unicode string in <ConfigResp>
404 format.
405 @param Progress A pointer to a string filled in with the offset of
406 the most recent '&' before the first failing
407 name/value pair (or the beginning of the string if
408 the failure is in the first name/value pair) or
409 the terminating NULL if all was successful.
410
411 @retval EFI_SUCCESS The Results is processed successfully.
412 @retval EFI_INVALID_PARAMETER Configuration is NULL.
413 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
414 driver.
415
416 **/
417 EFI_STATUS
418 EFIAPI
419 RouteConfig (
420 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
421 IN CONST EFI_STRING Configuration,
422 OUT EFI_STRING *Progress
423 )
424 {
425 EFI_STATUS Status;
426 UINTN BufferSize;
427 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
428 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
429
430 if (Configuration == NULL) {
431 return EFI_INVALID_PARAMETER;
432 }
433
434 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
435 HiiConfigRouting = PrivateData->HiiConfigRouting;
436
437 // Check routing data in <ConfigHdr>.
438 // Note: if only one Storage is used, then this checking could be skipped.
439 //
440 if (!IsConfigHdrMatch (Configuration, &mFormSetGuid, VariableName)) {
441 *Progress = Configuration;
442 return EFI_NOT_FOUND;
443 }
444
445 //
446 // Get Buffer Storage data from EFI variable
447 //
448 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
449 Status = gRT->GetVariable (
450 VariableName,
451 &mFormSetGuid,
452 NULL,
453 &BufferSize,
454 &PrivateData->Configuration
455 );
456 if (EFI_ERROR (Status)) {
457 return Status;
458 }
459
460 //
461 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
462 //
463 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
464 Status = HiiConfigRouting->ConfigToBlock (
465 HiiConfigRouting,
466 Configuration,
467 (UINT8 *) &PrivateData->Configuration,
468 &BufferSize,
469 Progress
470 );
471 if (EFI_ERROR (Status)) {
472 return Status;
473 }
474
475 //
476 // Store Buffer Storage back to EFI variable
477 //
478 Status = gRT->SetVariable(
479 VariableName,
480 &mFormSetGuid,
481 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
482 sizeof (DRIVER_SAMPLE_CONFIGURATION),
483 &PrivateData->Configuration
484 );
485
486 return Status;
487 }
488
489
490 /**
491 This function processes the results of changes in configuration.
492
493 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
494 @param Action Specifies the type of action taken by the browser.
495 @param QuestionId A unique value which is sent to the original
496 exporting driver so that it can identify the type
497 of data to expect.
498 @param Type The type of value for the question.
499 @param Value A pointer to the data being sent to the original
500 exporting driver.
501 @param ActionRequest On return, points to the action requested by the
502 callback function.
503
504 @retval EFI_SUCCESS The callback successfully handled the action.
505 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
506 variable and its data.
507 @retval EFI_DEVICE_ERROR The variable could not be saved.
508 @retval EFI_UNSUPPORTED The specified Action is not supported by the
509 callback.
510
511 **/
512 EFI_STATUS
513 EFIAPI
514 DriverCallback (
515 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
516 IN EFI_BROWSER_ACTION Action,
517 IN EFI_QUESTION_ID QuestionId,
518 IN UINT8 Type,
519 IN EFI_IFR_TYPE_VALUE *Value,
520 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
521 )
522 {
523 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
524 EFI_STATUS Status;
525 EFI_HII_UPDATE_DATA UpdateData;
526 IFR_OPTION *IfrOptionList;
527 UINT8 MyVar;
528
529 if ((Value == NULL) || (ActionRequest == NULL)) {
530 return EFI_INVALID_PARAMETER;
531 }
532
533 Status = EFI_SUCCESS;
534 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
535
536 switch (QuestionId) {
537 case 0x1234:
538 //
539 // Initialize the container for dynamic opcodes
540 //
541 IfrLibInitUpdateData (&UpdateData, 0x1000);
542
543 IfrOptionList = AllocatePool (2 * sizeof (IFR_OPTION));
544 ASSERT (IfrOptionList != NULL);
545
546 IfrOptionList[0].Flags = 0;
547 IfrOptionList[0].StringToken = STRING_TOKEN (STR_BOOT_OPTION1);
548 IfrOptionList[0].Value.u8 = 1;
549 IfrOptionList[1].Flags = EFI_IFR_OPTION_DEFAULT;
550 IfrOptionList[1].StringToken = STRING_TOKEN (STR_BOOT_OPTION2);
551 IfrOptionList[1].Value.u8 = 2;
552
553 CreateActionOpCode (
554 0x1237, // Question ID
555 STRING_TOKEN(STR_EXIT_TEXT), // Prompt text
556 STRING_TOKEN(STR_EXIT_TEXT), // Help text
557 EFI_IFR_FLAG_CALLBACK, // Question flag
558 0, // Action String ID
559 &UpdateData // Container for dynamic created opcodes
560 );
561
562 //
563 // Prepare initial value for the dynamic created oneof Question
564 //
565 PrivateData->Configuration.DynamicOneof = 2;
566 Status = gRT->SetVariable(
567 VariableName,
568 &mFormSetGuid,
569 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
570 sizeof (DRIVER_SAMPLE_CONFIGURATION),
571 &PrivateData->Configuration
572 );
573 CreateOneOfOpCode (
574 0x8001, // Question ID (or call it "key")
575 CONFIGURATION_VARSTORE_ID, // VarStore ID
576 (UINT16) DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage
577 STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text
578 STRING_TOKEN (STR_ONE_OF_HELP), // Question help text
579 EFI_IFR_FLAG_CALLBACK, // Question flag
580 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value
581 IfrOptionList, // Option list
582 2, // Number of options in Option list
583 &UpdateData // Container for dynamic created opcodes
584 );
585
586 CreateOrderedListOpCode (
587 0x8002, // Question ID
588 CONFIGURATION_VARSTORE_ID, // VarStore ID
589 (UINT16) DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage
590 STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text
591 STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text
592 EFI_IFR_FLAG_RESET_REQUIRED, // Question flag
593 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
594 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value
595 5, // Maximum container
596 IfrOptionList, // Option list
597 2, // Number of options in Option list
598 &UpdateData // Container for dynamic created opcodes
599 );
600
601 CreateGotoOpCode (
602 1, // Target Form ID
603 STRING_TOKEN (STR_GOTO_FORM1), // Prompt text
604 STRING_TOKEN (STR_GOTO_HELP), // Help text
605 0, // Question flag
606 0x8003, // Question ID
607 &UpdateData // Container for dynamic created opcodes
608 );
609
610 Status = IfrLibUpdateForm (
611 PrivateData->HiiHandle[0], // HII handle
612 &mFormSetGuid, // Formset GUID
613 0x1234, // Form ID
614 0x1234, // Label for where to insert opcodes
615 TRUE, // Append or replace
616 &UpdateData // Dynamic created opcodes
617 );
618 FreePool (IfrOptionList);
619 IfrLibFreeUpdateData (&UpdateData);
620 break;
621
622 case 0x5678:
623 //
624 // We will reach here once the Question is refreshed
625 //
626 IfrLibInitUpdateData (&UpdateData, 0x1000);
627
628 IfrOptionList = AllocatePool (2 * sizeof (IFR_OPTION));
629 ASSERT (IfrOptionList != NULL);
630
631 CreateActionOpCode (
632 0x1237, // Question ID
633 STRING_TOKEN(STR_EXIT_TEXT), // Prompt text
634 STRING_TOKEN(STR_EXIT_TEXT), // Help text
635 EFI_IFR_FLAG_CALLBACK, // Question flag
636 0, // Action String ID
637 &UpdateData // Container for dynamic created opcodes
638 );
639
640 Status = IfrLibUpdateForm (
641 PrivateData->HiiHandle[0], // HII handle
642 &mFormSetGuid, // Formset GUID
643 3, // Form ID
644 0x2234, // Label for where to insert opcodes
645 TRUE, // Append or replace
646 &UpdateData // Dynamic created opcodes
647 );
648 IfrLibFreeUpdateData (&UpdateData);
649
650 //
651 // Refresh the Question value
652 //
653 PrivateData->Configuration.DynamicRefresh++;
654 Status = gRT->SetVariable(
655 VariableName,
656 &mFormSetGuid,
657 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
658 sizeof (DRIVER_SAMPLE_CONFIGURATION),
659 &PrivateData->Configuration
660 );
661
662 //
663 // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
664 // the first statement in Form 3 be suppressed
665 //
666 MyVar = 111;
667 Status = gRT->SetVariable(
668 L"MyVar",
669 &mFormSetGuid,
670 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
671 1,
672 &MyVar
673 );
674 break;
675
676 case 0x1237:
677 //
678 // User press "Exit now", request Browser to exit
679 //
680 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
681 break;
682
683 case 0x1238:
684 //
685 // User press "Save now", request Browser to save the uncommitted data.
686 //
687 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
688 break;
689
690 case 0x2000:
691 //
692 // When try to set a new password, user will be chanlleged with old password.
693 // The Callback is responsible for validating old password input by user,
694 // If Callback return EFI_SUCCESS, it indicates validation pass.
695 //
696 switch (PrivateData->PasswordState) {
697 case BROWSER_STATE_VALIDATE_PASSWORD:
698 Status = ValidatePassword (PrivateData, Value->string);
699 if (Status == EFI_SUCCESS) {
700 PrivateData->PasswordState = BROWSER_STATE_SET_PASSWORD;
701 }
702 break;
703
704 case BROWSER_STATE_SET_PASSWORD:
705 Status = SetPassword (PrivateData, Value->string);
706 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
707 break;
708
709 default:
710 break;
711 }
712
713 break;
714
715 default:
716 break;
717 }
718
719 return Status;
720 }
721
722 /**
723 Main entry for this driver.
724
725 @param ImageHandle Image handle this driver.
726 @param SystemTable Pointer to SystemTable.
727
728 @retval EFI_SUCESS This function always complete successfully.
729
730 **/
731 EFI_STATUS
732 EFIAPI
733 DriverSampleInit (
734 IN EFI_HANDLE ImageHandle,
735 IN EFI_SYSTEM_TABLE *SystemTable
736 )
737 {
738 EFI_STATUS Status;
739 EFI_STATUS SavedStatus;
740 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
741 EFI_HII_HANDLE HiiHandle[2];
742 EFI_HANDLE DriverHandle[2] = {NULL, NULL};
743 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
744 EFI_SCREEN_DESCRIPTOR Screen;
745 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
746 EFI_HII_STRING_PROTOCOL *HiiString;
747 EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
748 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
749 CHAR16 *NewString;
750 UINTN BufferSize;
751 DRIVER_SAMPLE_CONFIGURATION *Configuration;
752 BOOLEAN ExtractIfrDefault;
753
754 //
755 // Initialize the library and our protocol.
756 //
757
758 //
759 // Initialize screen dimensions for SendForm().
760 // Remove 3 characters from top and bottom
761 //
762 ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
763 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);
764
765 Screen.TopRow = 3;
766 Screen.BottomRow = Screen.BottomRow - 3;
767
768 //
769 // Initialize driver private data
770 //
771 PrivateData = AllocatePool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
772 if (PrivateData == NULL) {
773 return EFI_OUT_OF_RESOURCES;
774 }
775
776 PrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;
777
778 PrivateData->ConfigAccess.ExtractConfig = ExtractConfig;
779 PrivateData->ConfigAccess.RouteConfig = RouteConfig;
780 PrivateData->ConfigAccess.Callback = DriverCallback;
781 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
782
783 //
784 // Locate Hii Database protocol
785 //
786 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase);
787 if (EFI_ERROR (Status)) {
788 return Status;
789 }
790 PrivateData->HiiDatabase = HiiDatabase;
791
792 //
793 // Locate HiiString protocol
794 //
795 Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString);
796 if (EFI_ERROR (Status)) {
797 return Status;
798 }
799 PrivateData->HiiString = HiiString;
800
801 //
802 // Locate Formbrowser2 protocol
803 //
804 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
805 if (EFI_ERROR (Status)) {
806 return Status;
807 }
808 PrivateData->FormBrowser2 = FormBrowser2;
809
810 //
811 // Locate ConfigRouting protocol
812 //
813 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);
814 if (EFI_ERROR (Status)) {
815 return Status;
816 }
817 PrivateData->HiiConfigRouting = HiiConfigRouting;
818
819 Status = gBS->InstallMultipleProtocolInterfaces (
820 &DriverHandle[0],
821 &gEfiDevicePathProtocolGuid,
822 &mHiiVendorDevicePath1,
823 &gEfiHiiConfigAccessProtocolGuid,
824 &PrivateData->ConfigAccess,
825 NULL
826 );
827 ASSERT_EFI_ERROR (Status);
828
829 PrivateData->DriverHandle[0] = DriverHandle[0];
830
831 //
832 // Publish our HII data
833 //
834 PackageList = HiiLibPreparePackageList (
835 2,
836 &mFormSetGuid,
837 DriverSampleStrings,
838 VfrBin
839 );
840 if (PackageList == NULL) {
841 return EFI_OUT_OF_RESOURCES;
842 }
843
844 Status = HiiDatabase->NewPackageList (
845 HiiDatabase,
846 PackageList,
847 DriverHandle[0],
848 &HiiHandle[0]
849 );
850 FreePool (PackageList);
851 if (EFI_ERROR (Status)) {
852 return Status;
853 }
854 PrivateData->HiiHandle[0] = HiiHandle[0];
855
856 //
857 // Publish another Fromset
858 //
859 Status = gBS->InstallMultipleProtocolInterfaces (
860 &DriverHandle[1],
861 &gEfiDevicePathProtocolGuid,
862 &mHiiVendorDevicePath2,
863 NULL
864 );
865 ASSERT_EFI_ERROR (Status);
866
867 PrivateData->DriverHandle[1] = DriverHandle[1];
868
869 PackageList = HiiLibPreparePackageList (
870 2,
871 &mInventoryGuid,
872 DriverSampleStrings,
873 InventoryBin
874 );
875 if (PackageList == NULL) {
876 return EFI_OUT_OF_RESOURCES;
877 }
878
879 Status = HiiDatabase->NewPackageList (
880 HiiDatabase,
881 PackageList,
882 DriverHandle[1],
883 &HiiHandle[1]
884 );
885 FreePool (PackageList);
886 if (EFI_ERROR (Status)) {
887 return Status;
888 }
889 PrivateData->HiiHandle[1] = HiiHandle[1];
890
891 //
892 // Very simple example of how one would update a string that is already
893 // in the HII database
894 //
895 NewString = L"700 Mhz";
896
897 Status = HiiLibSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString);
898 if (EFI_ERROR (Status)) {
899 return Status;
900 }
901
902 //
903 // Initialize configuration data
904 //
905 Configuration = &PrivateData->Configuration;
906 ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));
907
908 //
909 // Try to read NV config EFI variable first
910 //
911 ExtractIfrDefault = TRUE;
912 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
913 Status = gRT->GetVariable (VariableName, &mFormSetGuid, NULL, &BufferSize, Configuration);
914 if (!EFI_ERROR (Status) && (BufferSize == sizeof (DRIVER_SAMPLE_CONFIGURATION))) {
915 ExtractIfrDefault = FALSE;
916 }
917
918 if (ExtractIfrDefault) {
919 //
920 // EFI variable for NV config doesn't exit, we should build this variable
921 // based on default values stored in IFR
922 //
923 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
924 Status = IfrLibExtractDefault (Configuration, &BufferSize, 1, VfrMyIfrNVDataDefault0000);
925
926 if (!EFI_ERROR (Status)) {
927 gRT->SetVariable(
928 VariableName,
929 &mFormSetGuid,
930 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
931 sizeof (DRIVER_SAMPLE_CONFIGURATION),
932 Configuration
933 );
934 }
935 }
936
937 //
938 // Example of how to display only the item we sent to HII
939 //
940 if (DISPLAY_ONLY_MY_ITEM == 0x0001) {
941 //
942 // Have the browser pull out our copy of the data, and only display our data
943 //
944 // Status = FormConfig->SendForm (FormConfig, TRUE, HiiHandle, NULL, NULL, NULL, &Screen, NULL);
945 //
946 Status = FormBrowser2->SendForm (
947 FormBrowser2,
948 HiiHandle,
949 1,
950 NULL,
951 0,
952 NULL,
953 NULL
954 );
955 SavedStatus = Status;
956
957 Status = HiiDatabase->RemovePackageList (HiiDatabase, HiiHandle[0]);
958 if (EFI_ERROR (Status)) {
959 return Status;
960 }
961
962 Status = HiiDatabase->RemovePackageList (HiiDatabase, HiiHandle[1]);
963 if (EFI_ERROR (Status)) {
964 return Status;
965 }
966
967 return SavedStatus;
968 } else {
969 //
970 // Have the browser pull out all the data in the HII Database and display it.
971 //
972 // Status = FormConfig->SendForm (FormConfig, TRUE, 0, NULL, NULL, NULL, NULL, NULL);
973 //
974 }
975
976 return EFI_SUCCESS;
977 }