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";
25 EFI_HANDLE DriverHandle
[2] = {NULL
, NULL
};
26 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
= NULL
;
28 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0
= {
34 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
35 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
39 // {C153B68D-EBFC-488e-B110-662867745B87}
41 { 0xc153b68d, 0xebfc, 0x488e, { 0xb1, 0x10, 0x66, 0x28, 0x67, 0x74, 0x5b, 0x87 } }
45 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
47 (UINT8
) (END_DEVICE_PATH_LENGTH
),
48 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
53 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1
= {
59 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
60 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
64 // {06F37F07-0C48-40e9-8436-0A08A0BB76B0}
66 { 0x6f37f07, 0xc48, 0x40e9, { 0x84, 0x36, 0xa, 0x8, 0xa0, 0xbb, 0x76, 0xb0 } }
70 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
72 (UINT8
) (END_DEVICE_PATH_LENGTH
),
73 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
79 Encode the password using a simple algorithm.
81 @param Password The string to be encoded.
82 @param MaxSize The size of the string.
97 Buffer
= AllocateZeroPool (MaxSize
);
98 ASSERT (Buffer
!= NULL
);
100 for (Index
= 0; Key
[Index
] != 0; Index
++) {
101 for (Loop
= 0; Loop
< (UINT8
) (MaxSize
/ 2); Loop
++) {
102 Buffer
[Loop
] = (CHAR16
) (Password
[Loop
] ^ Key
[Index
]);
106 CopyMem (Password
, Buffer
, MaxSize
);
113 Validate the user's password.
115 @param PrivateData This driver's private context data.
116 @param StringId The user's input.
118 @retval EFI_SUCCESS The user's input matches the password.
119 @retval EFI_NOT_READY The user's input does not match the password.
123 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
124 IN EFI_STRING_ID StringId
130 UINTN PasswordMaxSize
;
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
154 PasswordMaxSize
= sizeof (PrivateData
->Configuration
.WhatIsThePassword2
);
156 // Check whether we have any old password set
158 for (Index
= 0; Index
< PasswordMaxSize
/ sizeof (UINT16
); Index
++) {
159 if (PrivateData
->Configuration
.WhatIsThePassword2
[Index
] != 0) {
166 // Old password not exist, return EFI_SUCCESS to prompt for new password
172 // Get user input password
174 Password
= HiiGetString (PrivateData
->HiiHandle
[0], StringId
, NULL
);
175 if (Password
== NULL
) {
176 return EFI_NOT_READY
;
178 if (StrSize (Password
) > PasswordMaxSize
) {
180 return EFI_NOT_READY
;
184 // Validate old password
186 EncodedPassword
= AllocateZeroPool (PasswordMaxSize
);
187 ASSERT (EncodedPassword
!= NULL
);
188 StrnCpy (EncodedPassword
, Password
, StrLen (Password
));
189 EncodePassword (EncodedPassword
, StrLen (EncodedPassword
) * sizeof (CHAR16
));
190 if (CompareMem (EncodedPassword
, PrivateData
->Configuration
.WhatIsThePassword2
, StrLen (EncodedPassword
) * sizeof (CHAR16
)) != 0) {
192 // Old password mismatch, return EFI_NOT_READY to prompt for error message
194 Status
= EFI_NOT_READY
;
196 Status
= EFI_SUCCESS
;
200 FreePool (EncodedPassword
);
206 Encode the password using a simple algorithm.
208 @param PrivateData This driver's private context data.
209 @param StringId The password from User.
211 @retval EFI_SUCESS The operation is successful.
212 @return Other value if gRT->SetVariable () fails.
217 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
218 IN EFI_STRING_ID StringId
223 CHAR16
*TempPassword
;
225 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
229 // Get Buffer Storage data from EFI variable
231 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
232 Status
= gRT
->GetVariable (
237 &PrivateData
->Configuration
239 if (EFI_ERROR (Status
)) {
244 // Get user input password
246 Password
= &PrivateData
->Configuration
.WhatIsThePassword2
[0];
247 PasswordSize
= sizeof (PrivateData
->Configuration
.WhatIsThePassword2
);
248 ZeroMem (Password
, PasswordSize
);
250 TempPassword
= HiiGetString (PrivateData
->HiiHandle
[0], StringId
, NULL
);
251 if (TempPassword
== NULL
) {
252 return EFI_NOT_READY
;
254 if (StrSize (TempPassword
) > PasswordSize
) {
255 FreePool (TempPassword
);
256 return EFI_NOT_READY
;
258 StrnCpy (Password
, TempPassword
, StrLen (TempPassword
));
259 FreePool (TempPassword
);
262 // Retrive uncommitted data from Browser
264 Configuration
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION
));
265 ASSERT (Configuration
!= NULL
);
266 if (HiiGetBrowserData (&mFormSetGuid
, VariableName
, sizeof (DRIVER_SAMPLE_CONFIGURATION
), (UINT8
*) Configuration
)) {
268 // Update password's clear text in the screen
270 CopyMem (Configuration
->PasswordClearText
, Password
, StrSize (Password
));
273 // Update uncommitted data of Browser
278 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
279 (UINT8
*) Configuration
,
285 // Free Configuration Buffer
287 FreePool (Configuration
);
293 EncodePassword (Password
, StrLen (Password
) * 2);
294 Status
= gRT
->SetVariable(
297 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
298 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
299 &PrivateData
->Configuration
306 This function allows a caller to extract the current configuration for one
307 or more named elements from the target driver.
309 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
310 @param Request A null-terminated Unicode string in
311 <ConfigRequest> format.
312 @param Progress On return, points to a character in the Request
313 string. Points to the string's null terminator if
314 request was successful. Points to the most recent
315 '&' before the first failing name/value pair (or
316 the beginning of the string if the failure is in
317 the first name/value pair) if the request was not
319 @param Results A null-terminated Unicode string in
320 <ConfigAltResp> format which has all values filled
321 in for the names in the Request string. String to
322 be allocated by the called function.
324 @retval EFI_SUCCESS The Results is filled with the requested values.
325 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
326 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
327 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
334 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
335 IN CONST EFI_STRING Request
,
336 OUT EFI_STRING
*Progress
,
337 OUT EFI_STRING
*Results
342 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
343 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
344 EFI_STRING ConfigRequest
;
345 EFI_STRING ConfigRequestHdr
;
348 if (Progress
== NULL
|| Results
== NULL
|| Request
== NULL
) {
349 return EFI_INVALID_PARAMETER
;
352 // Initialize the local variables.
354 ConfigRequestHdr
= NULL
;
355 ConfigRequest
= NULL
;
359 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
360 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
363 // Get Buffer Storage data from EFI variable.
364 // Try to get the current setting from variable.
366 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
367 Status
= gRT
->GetVariable (
372 &PrivateData
->Configuration
374 if (EFI_ERROR (Status
)) {
375 return EFI_NOT_FOUND
;
378 if (Request
== NULL
) {
380 // Request is set to NULL, construct full request string.
384 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
385 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
387 ConfigRequestHdr
= HiiConstructConfigHdr (&mFormSetGuid
, VariableName
, PrivateData
->DriverHandle
[0]);
388 Size
= (StrLen (ConfigRequest
) + 32 + 1) * sizeof (CHAR16
);
389 ConfigRequest
= AllocateZeroPool (Size
);
390 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
391 FreePool (ConfigRequestHdr
);
394 // Check routing data in <ConfigHdr>.
395 // Note: if only one Storage is used, then this checking could be skipped.
397 if (!HiiIsConfigHdrMatch (Request
, &mFormSetGuid
, VariableName
)) {
398 return EFI_NOT_FOUND
;
400 ConfigRequest
= Request
;
404 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
406 Status
= HiiConfigRouting
->BlockToConfig (
409 (UINT8
*) &PrivateData
->Configuration
,
415 if (Request
== NULL
) {
416 FreePool (ConfigRequest
);
425 This function processes the results of changes in configuration.
427 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
428 @param Configuration A null-terminated Unicode string in <ConfigResp>
430 @param Progress A pointer to a string filled in with the offset of
431 the most recent '&' before the first failing
432 name/value pair (or the beginning of the string if
433 the failure is in the first name/value pair) or
434 the terminating NULL if all was successful.
436 @retval EFI_SUCCESS The Results is processed successfully.
437 @retval EFI_INVALID_PARAMETER Configuration is NULL.
438 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
445 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
446 IN CONST EFI_STRING Configuration
,
447 OUT EFI_STRING
*Progress
452 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
453 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
455 if (Configuration
== NULL
|| Progress
== NULL
) {
456 return EFI_INVALID_PARAMETER
;
459 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
460 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
461 *Progress
= Configuration
;
464 // Check routing data in <ConfigHdr>.
465 // Note: if only one Storage is used, then this checking could be skipped.
467 if (!HiiIsConfigHdrMatch (Configuration
, &mFormSetGuid
, VariableName
)) {
468 return EFI_NOT_FOUND
;
472 // Get Buffer Storage data from EFI variable
474 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
475 Status
= gRT
->GetVariable (
480 &PrivateData
->Configuration
482 if (EFI_ERROR (Status
)) {
487 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
489 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
490 Status
= HiiConfigRouting
->ConfigToBlock (
493 (UINT8
*) &PrivateData
->Configuration
,
497 if (EFI_ERROR (Status
)) {
502 // Store Buffer Storage back to EFI variable
504 Status
= gRT
->SetVariable(
507 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
508 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
509 &PrivateData
->Configuration
517 This function processes the results of changes in configuration.
519 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
520 @param Action Specifies the type of action taken by the browser.
521 @param QuestionId A unique value which is sent to the original
522 exporting driver so that it can identify the type
524 @param Type The type of value for the question.
525 @param Value A pointer to the data being sent to the original
527 @param ActionRequest On return, points to the action requested by the
530 @retval EFI_SUCCESS The callback successfully handled the action.
531 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
532 variable and its data.
533 @retval EFI_DEVICE_ERROR The variable could not be saved.
534 @retval EFI_UNSUPPORTED The specified Action is not supported by the
541 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
542 IN EFI_BROWSER_ACTION Action
,
543 IN EFI_QUESTION_ID QuestionId
,
545 IN EFI_IFR_TYPE_VALUE
*Value
,
546 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
549 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
552 VOID
*StartOpCodeHandle
;
553 VOID
*OptionsOpCodeHandle
;
554 EFI_IFR_GUID_LABEL
*StartLabel
;
555 VOID
*EndOpCodeHandle
;
556 EFI_IFR_GUID_LABEL
*EndLabel
;
558 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
559 return EFI_INVALID_PARAMETER
;
562 if ((Type
== EFI_IFR_TYPE_STRING
) && (Value
->string
== 0)) {
563 return EFI_INVALID_PARAMETER
;
567 Status
= EFI_SUCCESS
;
568 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
570 switch (QuestionId
) {
573 // Initialize the container for dynamic opcodes
575 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
576 ASSERT (StartOpCodeHandle
!= NULL
);
578 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
579 ASSERT (EndOpCodeHandle
!= NULL
);
582 // Create Hii Extend Label OpCode as the start opcode
584 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
585 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
586 StartLabel
->Number
= LABEL_UPDATE1
;
589 // Create Hii Extend Label OpCode as the end opcode
591 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
592 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
593 EndLabel
->Number
= LABEL_END
;
595 HiiCreateActionOpCode (
596 StartOpCodeHandle
, // Container for dynamic created opcodes
597 0x1237, // Question ID
598 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
599 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
600 EFI_IFR_FLAG_CALLBACK
, // Question flag
601 0 // Action String ID
605 // Create Option OpCode
607 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
608 ASSERT (OptionsOpCodeHandle
!= NULL
);
610 HiiCreateOneOfOptionOpCode (
612 STRING_TOKEN (STR_BOOT_OPTION1
),
614 EFI_IFR_NUMERIC_SIZE_1
,
618 HiiCreateOneOfOptionOpCode (
620 STRING_TOKEN (STR_BOOT_OPTION2
),
622 EFI_IFR_NUMERIC_SIZE_1
,
627 // Prepare initial value for the dynamic created oneof Question
629 PrivateData
->Configuration
.DynamicOneof
= 2;
630 Status
= gRT
->SetVariable(
633 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
634 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
635 &PrivateData
->Configuration
638 HiiCreateOneOfOpCode (
639 StartOpCodeHandle
, // Container for dynamic created opcodes
640 0x8001, // Question ID (or call it "key")
641 CONFIGURATION_VARSTORE_ID
, // VarStore ID
642 (UINT16
) DYNAMIC_ONE_OF_VAR_OFFSET
, // Offset in Buffer Storage
643 STRING_TOKEN (STR_ONE_OF_PROMPT
), // Question prompt text
644 STRING_TOKEN (STR_ONE_OF_HELP
), // Question help text
645 EFI_IFR_FLAG_CALLBACK
, // Question flag
646 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question Value
647 OptionsOpCodeHandle
, // Option Opcode list
648 NULL
// Default Opcode is NULl
651 HiiCreateOrderedListOpCode (
652 StartOpCodeHandle
, // Container for dynamic created opcodes
653 0x8002, // Question ID
654 CONFIGURATION_VARSTORE_ID
, // VarStore ID
655 (UINT16
) DYNAMIC_ORDERED_LIST_VAR_OFFSET
, // Offset in Buffer Storage
656 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question prompt text
657 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question help text
658 EFI_IFR_FLAG_RESET_REQUIRED
, // Question flag
659 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
660 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question value
661 5, // Maximum container
662 OptionsOpCodeHandle
, // Option Opcode list
663 NULL
// Default Opcode is NULl
666 HiiCreateGotoOpCode (
667 StartOpCodeHandle
, // Container for dynamic created opcodes
669 STRING_TOKEN (STR_GOTO_FORM1
), // Prompt text
670 STRING_TOKEN (STR_GOTO_HELP
), // Help text
672 0x8003 // Question ID
676 PrivateData
->HiiHandle
[0], // HII handle
677 &mFormSetGuid
, // Formset GUID
679 StartOpCodeHandle
, // Label for where to insert opcodes
680 EndOpCodeHandle
// Replace data
683 HiiFreeOpCodeHandle (StartOpCodeHandle
);
684 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
689 // We will reach here once the Question is refreshed
693 // Initialize the container for dynamic opcodes
695 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
696 ASSERT (StartOpCodeHandle
!= NULL
);
699 // Create Hii Extend Label OpCode as the start opcode
701 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
702 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
703 StartLabel
->Number
= LABEL_UPDATE2
;
705 HiiCreateActionOpCode (
706 StartOpCodeHandle
, // Container for dynamic created opcodes
707 0x1237, // Question ID
708 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
709 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
710 EFI_IFR_FLAG_CALLBACK
, // Question flag
711 0 // Action String ID
715 PrivateData
->HiiHandle
[0], // HII handle
716 &mFormSetGuid
, // Formset GUID
718 StartOpCodeHandle
, // Label for where to insert opcodes
722 HiiFreeOpCodeHandle (StartOpCodeHandle
);
725 // Refresh the Question value
727 PrivateData
->Configuration
.DynamicRefresh
++;
728 Status
= gRT
->SetVariable(
731 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
732 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
733 &PrivateData
->Configuration
737 // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
738 // the first statement in Form 3 be suppressed
741 Status
= gRT
->SetVariable(
744 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
752 // User press "Exit now", request Browser to exit
754 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
759 // User press "Save now", request Browser to save the uncommitted data.
761 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
766 // When try to set a new password, user will be chanlleged with old password.
767 // The Callback is responsible for validating old password input by user,
768 // If Callback return EFI_SUCCESS, it indicates validation pass.
770 switch (PrivateData
->PasswordState
) {
771 case BROWSER_STATE_VALIDATE_PASSWORD
:
772 Status
= ValidatePassword (PrivateData
, Value
->string
);
773 if (Status
== EFI_SUCCESS
) {
774 PrivateData
->PasswordState
= BROWSER_STATE_SET_PASSWORD
;
778 case BROWSER_STATE_SET_PASSWORD
:
779 Status
= SetPassword (PrivateData
, Value
->string
);
780 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
797 Main entry for this driver.
799 @param ImageHandle Image handle this driver.
800 @param SystemTable Pointer to SystemTable.
802 @retval EFI_SUCESS This function always complete successfully.
808 IN EFI_HANDLE ImageHandle
,
809 IN EFI_SYSTEM_TABLE
*SystemTable
813 EFI_HII_HANDLE HiiHandle
[2];
814 EFI_SCREEN_DESCRIPTOR Screen
;
815 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
816 EFI_HII_STRING_PROTOCOL
*HiiString
;
817 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
818 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
821 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
823 EFI_STRING ConfigRequestHdr
;
826 // Initialize the local variables.
828 ConfigRequestHdr
= NULL
;
830 // Initialize screen dimensions for SendForm().
831 // Remove 3 characters from top and bottom
833 ZeroMem (&Screen
, sizeof (EFI_SCREEN_DESCRIPTOR
));
834 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Screen
.RightColumn
, &Screen
.BottomRow
);
837 Screen
.BottomRow
= Screen
.BottomRow
- 3;
840 // Initialize driver private data
842 PrivateData
= AllocatePool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA
));
843 if (PrivateData
== NULL
) {
844 return EFI_OUT_OF_RESOURCES
;
847 PrivateData
->Signature
= DRIVER_SAMPLE_PRIVATE_SIGNATURE
;
849 PrivateData
->ConfigAccess
.ExtractConfig
= ExtractConfig
;
850 PrivateData
->ConfigAccess
.RouteConfig
= RouteConfig
;
851 PrivateData
->ConfigAccess
.Callback
= DriverCallback
;
852 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
855 // Locate Hii Database protocol
857 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &HiiDatabase
);
858 if (EFI_ERROR (Status
)) {
861 PrivateData
->HiiDatabase
= HiiDatabase
;
864 // Locate HiiString protocol
866 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
867 if (EFI_ERROR (Status
)) {
870 PrivateData
->HiiString
= HiiString
;
873 // Locate Formbrowser2 protocol
875 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &FormBrowser2
);
876 if (EFI_ERROR (Status
)) {
879 PrivateData
->FormBrowser2
= FormBrowser2
;
882 // Locate ConfigRouting protocol
884 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &HiiConfigRouting
);
885 if (EFI_ERROR (Status
)) {
888 PrivateData
->HiiConfigRouting
= HiiConfigRouting
;
890 Status
= gBS
->InstallMultipleProtocolInterfaces (
892 &gEfiDevicePathProtocolGuid
,
893 &mHiiVendorDevicePath0
,
894 &gEfiHiiConfigAccessProtocolGuid
,
895 &PrivateData
->ConfigAccess
,
898 ASSERT_EFI_ERROR (Status
);
900 PrivateData
->DriverHandle
[0] = DriverHandle
[0];
903 // Publish our HII data
905 HiiHandle
[0] = HiiAddPackages (
912 if (HiiHandle
[0] == NULL
) {
913 return EFI_OUT_OF_RESOURCES
;
916 PrivateData
->HiiHandle
[0] = HiiHandle
[0];
919 // Publish another Fromset
921 Status
= gBS
->InstallMultipleProtocolInterfaces (
923 &gEfiDevicePathProtocolGuid
,
924 &mHiiVendorDevicePath1
,
927 ASSERT_EFI_ERROR (Status
);
929 PrivateData
->DriverHandle
[1] = DriverHandle
[1];
931 HiiHandle
[1] = HiiAddPackages (
938 if (HiiHandle
[1] == NULL
) {
939 return EFI_OUT_OF_RESOURCES
;
942 PrivateData
->HiiHandle
[1] = HiiHandle
[1];
945 // Very simple example of how one would update a string that is already
946 // in the HII database
948 NewString
= L
"700 Mhz";
950 if (HiiSetString (HiiHandle
[0], STRING_TOKEN (STR_CPU_STRING2
), NewString
, NULL
) == 0) {
951 return EFI_OUT_OF_RESOURCES
;
955 // Initialize configuration data
957 Configuration
= &PrivateData
->Configuration
;
958 ZeroMem (Configuration
, sizeof (DRIVER_SAMPLE_CONFIGURATION
));
961 // Try to read NV config EFI variable first
963 ConfigRequestHdr
= HiiConstructConfigHdr (&mFormSetGuid
, VariableName
, DriverHandle
[0]);
964 ASSERT (ConfigRequestHdr
!= NULL
);
966 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
967 Status
= gRT
->GetVariable (VariableName
, &mFormSetGuid
, NULL
, &BufferSize
, Configuration
);
968 if (EFI_ERROR (Status
)) {
970 // Store zero data Buffer Storage to EFI variable
972 Status
= gRT
->SetVariable(
975 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
976 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
979 ASSERT (Status
== EFI_SUCCESS
);
981 // EFI variable for NV config doesn't exit, we should build this variable
982 // based on default values stored in IFR
984 ActionFlag
= HiiSetToDefaults (ConfigRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
988 // EFI variable does exist and Validate Current Setting
990 ActionFlag
= HiiValidateSettings (ConfigRequestHdr
);
994 FreePool (ConfigRequestHdr
);
998 // In default, this driver is built into Flash device image,
999 // the following code doesn't run.
1003 // Example of how to display only the item we sent to HII
1004 // When this driver is not built into Flash device image,
1005 // it need to call SendForm to show front page by itself.
1007 if (DISPLAY_ONLY_MY_ITEM
<= 1) {
1009 // Have the browser pull out our copy of the data, and only display our data
1011 Status
= FormBrowser2
->SendForm (
1013 &(HiiHandle
[DISPLAY_ONLY_MY_ITEM
]),
1021 HiiRemovePackages (HiiHandle
[0]);
1023 HiiRemovePackages (HiiHandle
[1]);
1030 Unloads the application and its installed protocol.
1032 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1034 @retval EFI_SUCCESS The image has been unloaded.
1038 DriverSampleUnload (
1039 IN EFI_HANDLE ImageHandle
1042 if (DriverHandle
[0] != NULL
) {
1043 gBS
->UninstallMultipleProtocolInterfaces (
1045 &gEfiDevicePathProtocolGuid
,
1046 &mHiiVendorDevicePath0
,
1047 &gEfiHiiConfigAccessProtocolGuid
,
1048 &PrivateData
->ConfigAccess
,
1053 if (DriverHandle
[1] != NULL
) {
1054 gBS
->UninstallMultipleProtocolInterfaces (
1056 &gEfiDevicePathProtocolGuid
,
1057 &mHiiVendorDevicePath1
,
1062 if (PrivateData
->HiiHandle
[0] != NULL
) {
1063 HiiRemovePackages (PrivateData
->HiiHandle
[0]);
1066 if (PrivateData
->HiiHandle
[1] != NULL
) {
1067 HiiRemovePackages (PrivateData
->HiiHandle
[1]);
1070 if (PrivateData
!= NULL
) {
1071 FreePool (PrivateData
);