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
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
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.
17 #include "DriverSample.h"
19 #define DISPLAY_ONLY_MY_ITEM 0x0002
21 EFI_GUID mFormSetGuid
= FORMSET_GUID
;
22 EFI_GUID mInventoryGuid
= INVENTORY_GUID
;
24 CHAR16 VariableName
[] = L
"MyIfrNVData";
26 EFI_HANDLE DriverHandle
[2] = {NULL
, NULL
};
27 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
= NULL
;
29 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0
= {
35 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
36 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
40 // {C153B68D-EBFC-488e-B110-662867745B87}
42 { 0xc153b68d, 0xebfc, 0x488e, { 0xb1, 0x10, 0x66, 0x28, 0x67, 0x74, 0x5b, 0x87 } }
46 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
48 (UINT8
) (END_DEVICE_PATH_LENGTH
),
49 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
54 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1
= {
60 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
61 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
65 // {06F37F07-0C48-40e9-8436-0A08A0BB76B0}
67 { 0x6f37f07, 0xc48, 0x40e9, { 0x84, 0x36, 0xa, 0x8, 0xa0, 0xbb, 0x76, 0xb0 } }
71 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
73 (UINT8
) (END_DEVICE_PATH_LENGTH
),
74 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
80 Encode the password using a simple algorithm.
82 @param Password The string to be encoded.
83 @param MaxSize The size of the string.
98 Buffer
= AllocateZeroPool (MaxSize
);
99 ASSERT (Buffer
!= NULL
);
101 for (Index
= 0; Key
[Index
] != 0; Index
++) {
102 for (Loop
= 0; Loop
< (UINT8
) (MaxSize
/ 2); Loop
++) {
103 Buffer
[Loop
] = (CHAR16
) (Password
[Loop
] ^ Key
[Index
]);
107 CopyMem (Password
, Buffer
, MaxSize
);
114 Validate the user's password.
116 @param PrivateData This driver's private context data.
117 @param StringId The user's input.
119 @retval EFI_SUCCESS The user's input matches the password.
120 @retval EFI_NOT_READY The user's input does not match the password.
124 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
125 IN EFI_STRING_ID StringId
132 CHAR16
*EncodedPassword
;
136 // Get encoded password first
138 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
139 Status
= gRT
->GetVariable (
144 &PrivateData
->Configuration
146 if (EFI_ERROR (Status
)) {
148 // Old password not exist, prompt for new password
155 // Check whether we have any old password set
157 for (Index
= 0; Index
< 20; Index
++) {
158 if (PrivateData
->Configuration
.WhatIsThePassword2
[Index
] != 0) {
165 // Old password not exist, return EFI_SUCCESS to prompt for new password
171 // Get user input password
173 Password
= HiiGetString (PrivateData
->HiiHandle
[0], StringId
, NULL
);
174 if (Password
== NULL
) {
175 return EFI_NOT_READY
;
177 if (StrLen (Password
) > 20) {
179 return EFI_NOT_READY
;
183 // Validate old password
185 EncodedPassword
= AllocateZeroPool (21 * sizeof (CHAR16
));
186 ASSERT (EncodedPassword
!= NULL
);
187 StrnCpy (EncodedPassword
, Password
, 21);
188 EncodePassword (EncodedPassword
, 20 * sizeof (CHAR16
));
189 if (CompareMem (EncodedPassword
, PrivateData
->Configuration
.WhatIsThePassword2
, 20 * sizeof (CHAR16
)) != 0) {
191 // Old password mismatch, return EFI_NOT_READY to prompt for error message
193 Status
= EFI_NOT_READY
;
195 Status
= EFI_SUCCESS
;
199 FreePool (EncodedPassword
);
205 Encode the password using a simple algorithm.
207 @param PrivateData This driver's private context data.
208 @param StringId The password from User.
210 @retval EFI_SUCESS The operation is successful.
211 @return Other value if gRT->SetVariable () fails.
216 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
217 IN EFI_STRING_ID StringId
222 CHAR16
*TempPassword
;
224 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
228 // Get Buffer Storage data from EFI variable
230 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
231 Status
= gRT
->GetVariable (
236 &PrivateData
->Configuration
238 if (EFI_ERROR (Status
)) {
243 // Get user input password
245 Password
= &PrivateData
->Configuration
.WhatIsThePassword2
[0];
246 PasswordSize
= sizeof (PrivateData
->Configuration
.WhatIsThePassword2
);
247 ZeroMem (Password
, PasswordSize
);
249 TempPassword
= HiiGetString (PrivateData
->HiiHandle
[0], StringId
, NULL
);
250 if (TempPassword
== NULL
) {
251 return EFI_NOT_READY
;
253 if (StrLen (TempPassword
) > PasswordSize
/ sizeof (CHAR16
)) {
254 FreePool (TempPassword
);
255 return EFI_NOT_READY
;
257 StrnCpy (Password
, TempPassword
, PasswordSize
/ sizeof (CHAR16
));
258 FreePool (TempPassword
);
261 // Retrive uncommitted data from Browser
263 Configuration
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION
));
264 ASSERT (Configuration
!= NULL
);
265 if (HiiGetBrowserData (&mFormSetGuid
, VariableName
, sizeof (DRIVER_SAMPLE_CONFIGURATION
), (UINT8
*) Configuration
)) {
267 // Update password's clear text in the screen
269 CopyMem (Configuration
->PasswordClearText
, Password
, PasswordSize
);
272 // Update uncommitted data of Browser
277 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
278 (UINT8
*) Configuration
,
284 // Free Configuration Buffer
286 FreePool (Configuration
);
292 EncodePassword (Password
, PasswordSize
);
293 Status
= gRT
->SetVariable(
296 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
297 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
298 &PrivateData
->Configuration
305 This function allows a caller to extract the current configuration for one
306 or more named elements from the target driver.
308 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
309 @param Request A null-terminated Unicode string in
310 <ConfigRequest> format.
311 @param Progress On return, points to a character in the Request
312 string. Points to the string's null terminator if
313 request was successful. Points to the most recent
314 '&' before the first failing name/value pair (or
315 the beginning of the string if the failure is in
316 the first name/value pair) if the request was not
318 @param Results A null-terminated Unicode string in
319 <ConfigAltResp> format which has all values filled
320 in for the names in the Request string. String to
321 be allocated by the called function.
323 @retval EFI_SUCCESS The Results is filled with the requested values.
324 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
325 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
326 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
333 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
334 IN CONST EFI_STRING Request
,
335 OUT EFI_STRING
*Progress
,
336 OUT EFI_STRING
*Results
341 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
342 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
344 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
345 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
349 // Get Buffer Storage data from EFI variable
351 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
352 Status
= gRT
->GetVariable (
357 &PrivateData
->Configuration
359 if (EFI_ERROR (Status
)) {
363 if (Request
== NULL
) {
365 // Request is set to NULL, return all configurable elements together with ALTCFG
367 *Results
= HiiConstructConfigAltResp (
370 PrivateData
->DriverHandle
[0],
371 &PrivateData
->Configuration
,
373 VfrMyIfrNVDataBlockName
,
374 STRING_TOKEN (STR_STANDARD_DEFAULT_PROMPT
),
375 VfrMyIfrNVDataDefault0000
,
376 STRING_TOKEN (STR_MANUFACTURE_DEFAULT_PROMPT
),
377 VfrMyIfrNVDataDefault0001
,
383 // No matched storage is found.
385 if (*Results
== NULL
) {
386 return EFI_NOT_FOUND
;
393 // Check routing data in <ConfigHdr>.
394 // Note: if only one Storage is used, then this checking could be skipped.
396 if (!HiiIsConfigHdrMatch (Request
, &mFormSetGuid
, VariableName
)) {
398 return EFI_NOT_FOUND
;
402 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
404 Status
= HiiConfigRouting
->BlockToConfig (
407 (UINT8
*) &PrivateData
->Configuration
,
417 This function processes the results of changes in configuration.
419 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
420 @param Configuration A null-terminated Unicode string in <ConfigResp>
422 @param Progress A pointer to a string filled in with the offset of
423 the most recent '&' before the first failing
424 name/value pair (or the beginning of the string if
425 the failure is in the first name/value pair) or
426 the terminating NULL if all was successful.
428 @retval EFI_SUCCESS The Results is processed successfully.
429 @retval EFI_INVALID_PARAMETER Configuration is NULL.
430 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
437 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
438 IN CONST EFI_STRING Configuration
,
439 OUT EFI_STRING
*Progress
444 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
445 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
447 if (Configuration
== NULL
) {
448 return EFI_INVALID_PARAMETER
;
451 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
452 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
454 // Check routing data in <ConfigHdr>.
455 // Note: if only one Storage is used, then this checking could be skipped.
457 if (!HiiIsConfigHdrMatch (Configuration
, &mFormSetGuid
, VariableName
)) {
458 *Progress
= Configuration
;
459 return EFI_NOT_FOUND
;
463 // Get Buffer Storage data from EFI variable
465 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
466 Status
= gRT
->GetVariable (
471 &PrivateData
->Configuration
473 if (EFI_ERROR (Status
)) {
478 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
480 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
481 Status
= HiiConfigRouting
->ConfigToBlock (
484 (UINT8
*) &PrivateData
->Configuration
,
488 if (EFI_ERROR (Status
)) {
493 // Store Buffer Storage back to EFI variable
495 Status
= gRT
->SetVariable(
498 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
499 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
500 &PrivateData
->Configuration
508 This function processes the results of changes in configuration.
510 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
511 @param Action Specifies the type of action taken by the browser.
512 @param QuestionId A unique value which is sent to the original
513 exporting driver so that it can identify the type
515 @param Type The type of value for the question.
516 @param Value A pointer to the data being sent to the original
518 @param ActionRequest On return, points to the action requested by the
521 @retval EFI_SUCCESS The callback successfully handled the action.
522 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
523 variable and its data.
524 @retval EFI_DEVICE_ERROR The variable could not be saved.
525 @retval EFI_UNSUPPORTED The specified Action is not supported by the
532 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
533 IN EFI_BROWSER_ACTION Action
,
534 IN EFI_QUESTION_ID QuestionId
,
536 IN EFI_IFR_TYPE_VALUE
*Value
,
537 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
540 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
543 VOID
*StartOpCodeHandle
;
544 VOID
*OptionsOpCodeHandle
;
545 EFI_IFR_GUID_LABEL
*StartLabel
;
546 VOID
*EndOpCodeHandle
;
547 EFI_IFR_GUID_LABEL
*EndLabel
;
549 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
550 return EFI_INVALID_PARAMETER
;
553 Status
= EFI_SUCCESS
;
554 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
556 switch (QuestionId
) {
559 // Initialize the container for dynamic opcodes
561 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
562 ASSERT (StartOpCodeHandle
!= NULL
);
564 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
565 ASSERT (EndOpCodeHandle
!= NULL
);
568 // Create Hii Extend Label OpCode as the start opcode
570 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
571 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
572 StartLabel
->Number
= LABEL_UPDATE1
;
575 // Create Hii Extend Label OpCode as the end opcode
577 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
578 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
579 EndLabel
->Number
= LABEL_END
;
581 HiiCreateActionOpCode (
582 StartOpCodeHandle
, // Container for dynamic created opcodes
583 0x1237, // Question ID
584 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
585 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
586 EFI_IFR_FLAG_CALLBACK
, // Question flag
587 0 // Action String ID
591 // Create Option OpCode
593 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
594 ASSERT (OptionsOpCodeHandle
!= NULL
);
596 HiiCreateOneOfOptionOpCode (
598 STRING_TOKEN (STR_BOOT_OPTION1
),
600 EFI_IFR_NUMERIC_SIZE_1
,
604 HiiCreateOneOfOptionOpCode (
606 STRING_TOKEN (STR_BOOT_OPTION2
),
608 EFI_IFR_NUMERIC_SIZE_1
,
613 // Prepare initial value for the dynamic created oneof Question
615 PrivateData
->Configuration
.DynamicOneof
= 2;
616 Status
= gRT
->SetVariable(
619 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
620 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
621 &PrivateData
->Configuration
624 HiiCreateOneOfOpCode (
625 StartOpCodeHandle
, // Container for dynamic created opcodes
626 0x8001, // Question ID (or call it "key")
627 CONFIGURATION_VARSTORE_ID
, // VarStore ID
628 (UINT16
) DYNAMIC_ONE_OF_VAR_OFFSET
, // Offset in Buffer Storage
629 STRING_TOKEN (STR_ONE_OF_PROMPT
), // Question prompt text
630 STRING_TOKEN (STR_ONE_OF_HELP
), // Question help text
631 EFI_IFR_FLAG_CALLBACK
, // Question flag
632 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question Value
633 OptionsOpCodeHandle
, // Option Opcode list
634 NULL
// Default Opcode is NULl
637 HiiCreateOrderedListOpCode (
638 StartOpCodeHandle
, // Container for dynamic created opcodes
639 0x8002, // Question ID
640 CONFIGURATION_VARSTORE_ID
, // VarStore ID
641 (UINT16
) DYNAMIC_ORDERED_LIST_VAR_OFFSET
, // Offset in Buffer Storage
642 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question prompt text
643 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question help text
644 EFI_IFR_FLAG_RESET_REQUIRED
, // Question flag
645 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
646 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question value
647 5, // Maximum container
648 OptionsOpCodeHandle
, // Option Opcode list
649 NULL
// Default Opcode is NULl
652 HiiCreateGotoOpCode (
653 StartOpCodeHandle
, // Container for dynamic created opcodes
655 STRING_TOKEN (STR_GOTO_FORM1
), // Prompt text
656 STRING_TOKEN (STR_GOTO_HELP
), // Help text
658 0x8003 // Question ID
662 PrivateData
->HiiHandle
[0], // HII handle
663 &mFormSetGuid
, // Formset GUID
665 StartOpCodeHandle
, // Label for where to insert opcodes
666 EndOpCodeHandle
// Replace data
669 HiiFreeOpCodeHandle (StartOpCodeHandle
);
670 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
675 // We will reach here once the Question is refreshed
679 // Initialize the container for dynamic opcodes
681 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
682 ASSERT (StartOpCodeHandle
!= NULL
);
685 // Create Hii Extend Label OpCode as the start opcode
687 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
688 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
689 StartLabel
->Number
= LABEL_UPDATE2
;
691 HiiCreateActionOpCode (
692 StartOpCodeHandle
, // Container for dynamic created opcodes
693 0x1237, // Question ID
694 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
695 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
696 EFI_IFR_FLAG_CALLBACK
, // Question flag
697 0 // Action String ID
701 PrivateData
->HiiHandle
[0], // HII handle
702 &mFormSetGuid
, // Formset GUID
704 StartOpCodeHandle
, // Label for where to insert opcodes
708 HiiFreeOpCodeHandle (StartOpCodeHandle
);
711 // Refresh the Question value
713 PrivateData
->Configuration
.DynamicRefresh
++;
714 Status
= gRT
->SetVariable(
717 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
718 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
719 &PrivateData
->Configuration
723 // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
724 // the first statement in Form 3 be suppressed
727 Status
= gRT
->SetVariable(
730 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
738 // User press "Exit now", request Browser to exit
740 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
745 // User press "Save now", request Browser to save the uncommitted data.
747 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
752 // When try to set a new password, user will be chanlleged with old password.
753 // The Callback is responsible for validating old password input by user,
754 // If Callback return EFI_SUCCESS, it indicates validation pass.
756 switch (PrivateData
->PasswordState
) {
757 case BROWSER_STATE_VALIDATE_PASSWORD
:
758 Status
= ValidatePassword (PrivateData
, Value
->string
);
759 if (Status
== EFI_SUCCESS
) {
760 PrivateData
->PasswordState
= BROWSER_STATE_SET_PASSWORD
;
764 case BROWSER_STATE_SET_PASSWORD
:
765 Status
= SetPassword (PrivateData
, Value
->string
);
766 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
783 Main entry for this driver.
785 @param ImageHandle Image handle this driver.
786 @param SystemTable Pointer to SystemTable.
788 @retval EFI_SUCESS This function always complete successfully.
794 IN EFI_HANDLE ImageHandle
,
795 IN EFI_SYSTEM_TABLE
*SystemTable
799 EFI_HII_HANDLE HiiHandle
[2];
800 EFI_SCREEN_DESCRIPTOR Screen
;
801 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
802 EFI_HII_STRING_PROTOCOL
*HiiString
;
803 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
804 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
807 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
808 BOOLEAN ExtractIfrDefault
;
811 // Initialize the library and our protocol.
815 // Initialize screen dimensions for SendForm().
816 // Remove 3 characters from top and bottom
818 ZeroMem (&Screen
, sizeof (EFI_SCREEN_DESCRIPTOR
));
819 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Screen
.RightColumn
, &Screen
.BottomRow
);
822 Screen
.BottomRow
= Screen
.BottomRow
- 3;
825 // Initialize driver private data
827 PrivateData
= AllocatePool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA
));
828 if (PrivateData
== NULL
) {
829 return EFI_OUT_OF_RESOURCES
;
832 PrivateData
->Signature
= DRIVER_SAMPLE_PRIVATE_SIGNATURE
;
834 PrivateData
->ConfigAccess
.ExtractConfig
= ExtractConfig
;
835 PrivateData
->ConfigAccess
.RouteConfig
= RouteConfig
;
836 PrivateData
->ConfigAccess
.Callback
= DriverCallback
;
837 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
840 // Locate Hii Database protocol
842 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &HiiDatabase
);
843 if (EFI_ERROR (Status
)) {
846 PrivateData
->HiiDatabase
= HiiDatabase
;
849 // Locate HiiString protocol
851 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
852 if (EFI_ERROR (Status
)) {
855 PrivateData
->HiiString
= HiiString
;
858 // Locate Formbrowser2 protocol
860 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &FormBrowser2
);
861 if (EFI_ERROR (Status
)) {
864 PrivateData
->FormBrowser2
= FormBrowser2
;
867 // Locate ConfigRouting protocol
869 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &HiiConfigRouting
);
870 if (EFI_ERROR (Status
)) {
873 PrivateData
->HiiConfigRouting
= HiiConfigRouting
;
875 Status
= gBS
->InstallMultipleProtocolInterfaces (
877 &gEfiDevicePathProtocolGuid
,
878 &mHiiVendorDevicePath0
,
879 &gEfiHiiConfigAccessProtocolGuid
,
880 &PrivateData
->ConfigAccess
,
883 ASSERT_EFI_ERROR (Status
);
885 PrivateData
->DriverHandle
[0] = DriverHandle
[0];
888 // Publish our HII data
890 HiiHandle
[0] = HiiAddPackages (
897 if (HiiHandle
[0] == NULL
) {
898 return EFI_OUT_OF_RESOURCES
;
901 PrivateData
->HiiHandle
[0] = HiiHandle
[0];
904 // Publish another Fromset
906 Status
= gBS
->InstallMultipleProtocolInterfaces (
908 &gEfiDevicePathProtocolGuid
,
909 &mHiiVendorDevicePath1
,
912 ASSERT_EFI_ERROR (Status
);
914 PrivateData
->DriverHandle
[1] = DriverHandle
[1];
916 HiiHandle
[1] = HiiAddPackages (
923 if (HiiHandle
[1] == NULL
) {
924 return EFI_OUT_OF_RESOURCES
;
927 PrivateData
->HiiHandle
[1] = HiiHandle
[1];
930 // Very simple example of how one would update a string that is already
931 // in the HII database
933 NewString
= L
"700 Mhz";
935 if (HiiSetString (HiiHandle
[0], STRING_TOKEN (STR_CPU_STRING2
), NewString
, NULL
) == 0) {
936 return EFI_OUT_OF_RESOURCES
;
940 // Initialize configuration data
942 Configuration
= &PrivateData
->Configuration
;
943 ZeroMem (Configuration
, sizeof (DRIVER_SAMPLE_CONFIGURATION
));
946 // Try to read NV config EFI variable first
948 ExtractIfrDefault
= TRUE
;
949 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
950 Status
= gRT
->GetVariable (VariableName
, &mFormSetGuid
, NULL
, &BufferSize
, Configuration
);
951 if (!EFI_ERROR (Status
) && (BufferSize
== sizeof (DRIVER_SAMPLE_CONFIGURATION
))) {
952 ExtractIfrDefault
= FALSE
;
955 if (ExtractIfrDefault
) {
957 // EFI variable for NV config doesn't exit, we should build this variable
958 // based on default values stored in IFR
960 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
961 Status
= HiiIfrLibExtractDefault (Configuration
, &BufferSize
, 1, VfrMyIfrNVDataDefault0000
);
963 if (!EFI_ERROR (Status
)) {
967 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
968 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
975 // Default this driver is built into Flash device image,
976 // the following code doesn't run.
980 // Example of how to display only the item we sent to HII
981 // When this driver is not built into Flash device image,
982 // it need to call SendForm to show front page by itself.
984 if (DISPLAY_ONLY_MY_ITEM
<= 1) {
986 // Have the browser pull out our copy of the data, and only display our data
988 Status
= FormBrowser2
->SendForm (
990 &(HiiHandle
[DISPLAY_ONLY_MY_ITEM
]),
998 HiiRemovePackages (HiiHandle
[0]);
1000 HiiRemovePackages (HiiHandle
[1]);
1007 Unloads the application and its installed protocol.
1009 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1011 @retval EFI_SUCCESS The image has been unloaded.
1015 DriverSampleUnload (
1016 IN EFI_HANDLE ImageHandle
1019 if (DriverHandle
[0] != NULL
) {
1020 gBS
->UninstallMultipleProtocolInterfaces (
1022 &gEfiDevicePathProtocolGuid
,
1023 &mHiiVendorDevicePath0
,
1024 &gEfiHiiConfigAccessProtocolGuid
,
1025 &PrivateData
->ConfigAccess
,
1030 if (DriverHandle
[1] != NULL
) {
1031 gBS
->UninstallMultipleProtocolInterfaces (
1033 &gEfiDevicePathProtocolGuid
,
1034 &mHiiVendorDevicePath1
,
1039 if (PrivateData
->HiiHandle
[0] != NULL
) {
1040 HiiRemovePackages (PrivateData
->HiiHandle
[0]);
1043 if (PrivateData
->HiiHandle
[1] != NULL
) {
1044 HiiRemovePackages (PrivateData
->HiiHandle
[1]);
1047 if (PrivateData
!= NULL
) {
1048 FreePool (PrivateData
);