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 - 2011, Intel Corporation. All rights reserved.<BR>
6 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
, PasswordMaxSize
) != 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
305 Update names of Name/Value storage to current language.
307 @param PrivateData Points to the driver private data.
309 @retval EFI_SUCCESS All names are successfully updated.
310 @retval EFI_NOT_FOUND Failed to get Name from HII database.
315 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
321 // Get Name/Value name string of current language
323 for (Index
= 0; Index
< NAME_VALUE_NAME_NUMBER
; Index
++) {
324 PrivateData
->NameValueName
[Index
] = HiiGetString (
325 PrivateData
->HiiHandle
[0],
326 PrivateData
->NameStringId
[Index
],
329 if (PrivateData
->NameValueName
[Index
] == NULL
) {
330 return EFI_NOT_FOUND
;
339 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
341 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
343 This is a internal function.
345 @param StringPtr String in <BlockConfig> format and points to the
346 first character of <Number>.
347 @param Number The output value. Caller takes the responsibility
349 @param Len Length of the <Number>, in characters.
351 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
353 @retval EFI_SUCCESS Value of <Number> is outputted in Number
359 IN EFI_STRING StringPtr
,
373 if (StringPtr
== NULL
|| *StringPtr
== L
'\0' || Number
== NULL
|| Len
== NULL
) {
374 return EFI_INVALID_PARAMETER
;
380 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
383 *Len
= StringPtr
- TmpPtr
;
386 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
388 Status
= EFI_OUT_OF_RESOURCES
;
391 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
392 *(Str
+ *Len
) = L
'\0';
394 Length
= (Length
+ 1) / 2;
395 Buf
= (UINT8
*) AllocateZeroPool (Length
);
397 Status
= EFI_OUT_OF_RESOURCES
;
402 ZeroMem (TemStr
, sizeof (TemStr
));
403 for (Index
= 0; Index
< Length
; Index
++) {
404 TemStr
[0] = Str
[Length
- Index
- 1];
405 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
406 if ((Index
& 1) == 0) {
407 Buf
[Index
/2] = DigitUint8
;
409 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
414 Status
= EFI_SUCCESS
;
425 Create altcfg string.
427 @param Result The request result string.
428 @param ConfigHdr The request head info. <ConfigHdr> format.
429 @param Offset The offset of the parameter int he structure.
430 @param Width The width of the parameter.
433 @retval The string with altcfg info append at the end.
437 IN EFI_STRING Result
,
438 IN EFI_STRING ConfigHdr
,
443 EFI_STRING StringPtr
;
447 NewLen
= StrLen (Result
);
449 // String Len = ConfigResp + AltConfig + AltConfig + 1("\0")
451 NewLen
= (NewLen
+ ((1 + StrLen (ConfigHdr
) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16
);
452 StringPtr
= AllocateZeroPool (NewLen
);
453 if (StringPtr
== NULL
) {
458 if (Result
!= NULL
) {
459 StrCpy (StringPtr
, Result
);
460 StringPtr
+= StrLen (Result
);
466 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
469 EFI_HII_DEFAULT_CLASS_STANDARD
471 StringPtr
+= StrLen (StringPtr
);
475 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
476 L
"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
479 DEFAULT_CLASS_STANDARD_VALUE
481 StringPtr
+= StrLen (StringPtr
);
485 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
488 EFI_HII_DEFAULT_CLASS_MANUFACTURING
490 StringPtr
+= StrLen (StringPtr
);
494 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
495 L
"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
498 DEFAULT_CLASS_MANUFACTURING_VALUE
500 StringPtr
+= StrLen (StringPtr
);
506 Check whether need to add the altcfg string. if need to add, add the altcfg
509 @param RequestResult The request result string.
510 @param ConfigRequestHdr The request head info. <ConfigHdr> format.
515 IN OUT EFI_STRING
*RequestResult
,
516 IN EFI_STRING ConfigRequestHdr
519 EFI_STRING StringPtr
;
530 StringPtr
= *RequestResult
;
531 StringPtr
= StrStr (StringPtr
, L
"OFFSET");
532 BlockSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
533 ValueOffset
= OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION
, GetDefaultValueFromAccess
);
534 ValueWidth
= sizeof (((DRIVER_SAMPLE_CONFIGURATION
*)0)->GetDefaultValueFromAccess
);
536 if (StringPtr
== NULL
) {
540 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
542 // Back up the header of one <BlockName>
546 StringPtr
+= StrLen (L
"OFFSET=");
550 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
551 if (EFI_ERROR (Status
)) {
558 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
560 FreePool (TmpBuffer
);
563 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
566 StringPtr
+= StrLen (L
"&WIDTH=");
571 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
572 if (EFI_ERROR (Status
)) {
579 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
581 FreePool (TmpBuffer
);
584 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
587 StringPtr
+= StrLen (L
"&VALUE=");
592 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
593 if (EFI_ERROR (Status
)) {
599 // Calculate Value and convert it to hex string.
601 if (Offset
+ Width
> BlockSize
) {
605 if (Offset
<= ValueOffset
&& Offset
+ Width
>= ValueOffset
+ ValueWidth
) {
606 *RequestResult
= CreateAltCfgString(*RequestResult
, ConfigRequestHdr
, ValueOffset
, ValueWidth
);
613 This function allows a caller to extract the current configuration for one
614 or more named elements from the target driver.
616 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
617 @param Request A null-terminated Unicode string in
618 <ConfigRequest> format.
619 @param Progress On return, points to a character in the Request
620 string. Points to the string's null terminator if
621 request was successful. Points to the most recent
622 '&' before the first failing name/value pair (or
623 the beginning of the string if the failure is in
624 the first name/value pair) if the request was not
626 @param Results A null-terminated Unicode string in
627 <ConfigAltResp> format which has all values filled
628 in for the names in the Request string. String to
629 be allocated by the called function.
631 @retval EFI_SUCCESS The Results is filled with the requested values.
632 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
633 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
634 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
641 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
642 IN CONST EFI_STRING Request
,
643 OUT EFI_STRING
*Progress
,
644 OUT EFI_STRING
*Results
649 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
650 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
651 EFI_STRING ConfigRequest
;
652 EFI_STRING ConfigRequestHdr
;
658 BOOLEAN AllocatedRequest
;
660 if (Progress
== NULL
|| Results
== NULL
) {
661 return EFI_INVALID_PARAMETER
;
664 // Initialize the local variables.
666 ConfigRequestHdr
= NULL
;
667 ConfigRequest
= NULL
;
670 AllocatedRequest
= FALSE
;
672 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
673 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
676 // Get Buffer Storage data from EFI variable.
677 // Try to get the current setting from variable.
679 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
680 Status
= gRT
->GetVariable (
685 &PrivateData
->Configuration
687 if (EFI_ERROR (Status
)) {
688 return EFI_NOT_FOUND
;
691 if (Request
== NULL
) {
693 // Request is set to NULL, construct full request string.
697 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
698 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
700 ConfigRequestHdr
= HiiConstructConfigHdr (&mFormSetGuid
, VariableName
, PrivateData
->DriverHandle
[0]);
701 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
702 ConfigRequest
= AllocateZeroPool (Size
);
703 ASSERT (ConfigRequest
!= NULL
);
704 AllocatedRequest
= TRUE
;
705 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
706 FreePool (ConfigRequestHdr
);
707 ConfigRequestHdr
= NULL
;
710 // Check routing data in <ConfigHdr>.
711 // Note: if only one Storage is used, then this checking could be skipped.
713 if (!HiiIsConfigHdrMatch (Request
, &mFormSetGuid
, NULL
)) {
714 return EFI_NOT_FOUND
;
717 // Set Request to the unified request string.
719 ConfigRequest
= Request
;
721 // Check whether Request includes Request Element.
723 if (StrStr (Request
, L
"OFFSET") == NULL
) {
725 // Check Request Element does exist in Reques String
727 StrPointer
= StrStr (Request
, L
"PATH");
728 if (StrPointer
== NULL
) {
729 return EFI_INVALID_PARAMETER
;
731 if (StrStr (StrPointer
, L
"&") == NULL
) {
732 Size
= (StrLen (Request
) + 32 + 1) * sizeof (CHAR16
);
733 ConfigRequest
= AllocateZeroPool (Size
);
734 ASSERT (ConfigRequest
!= NULL
);
735 AllocatedRequest
= TRUE
;
736 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", Request
, (UINT64
)BufferSize
);
742 // Check if requesting Name/Value storage
744 if (StrStr (ConfigRequest
, L
"OFFSET") == NULL
) {
746 // Update Name/Value storage Names
748 Status
= LoadNameValueNames (PrivateData
);
749 if (EFI_ERROR (Status
)) {
754 // Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
755 // <Request> ::=<ConfigHdr>&Name0&Name1&Name2
756 // <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
758 BufferSize
= (StrLen (ConfigRequest
) +
759 1 + sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2 +
760 1 + sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2 +
761 1 + sizeof (PrivateData
->Configuration
.NameValueVar2
) * 2 + 1) * sizeof (CHAR16
);
762 *Results
= AllocateZeroPool (BufferSize
);
763 ASSERT (*Results
!= NULL
);
764 StrCpy (*Results
, ConfigRequest
);
768 // Append value of NameValueVar0, type is UINT8
770 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[0])) != NULL
) {
771 Value
+= StrLen (PrivateData
->NameValueName
[0]);
772 ValueStrLen
= ((sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2) + 1);
773 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
775 BackupChar
= Value
[ValueStrLen
];
777 Value
+= UnicodeValueToString (
779 PREFIX_ZERO
| RADIX_HEX
,
780 PrivateData
->Configuration
.NameValueVar0
,
781 sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2
787 // Append value of NameValueVar1, type is UINT16
789 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[1])) != NULL
) {
790 Value
+= StrLen (PrivateData
->NameValueName
[1]);
791 ValueStrLen
= ((sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2) + 1);
792 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
794 BackupChar
= Value
[ValueStrLen
];
796 Value
+= UnicodeValueToString (
798 PREFIX_ZERO
| RADIX_HEX
,
799 PrivateData
->Configuration
.NameValueVar1
,
800 sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2
806 // Append value of NameValueVar2, type is CHAR16 *
808 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[2])) != NULL
) {
809 Value
+= StrLen (PrivateData
->NameValueName
[2]);
810 ValueStrLen
= StrLen (PrivateData
->Configuration
.NameValueVar2
) * 4 + 1;
811 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
815 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
817 StrPointer
= (CHAR16
*) PrivateData
->Configuration
.NameValueVar2
;
818 for (; *StrPointer
!= L
'\0'; StrPointer
++) {
819 Value
+= UnicodeValueToString (Value
, PREFIX_ZERO
| RADIX_HEX
, *StrPointer
, 4);
823 Status
= EFI_SUCCESS
;
826 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
828 Status
= HiiConfigRouting
->BlockToConfig (
831 (UINT8
*) &PrivateData
->Configuration
,
836 if (!EFI_ERROR (Status
)) {
837 ConfigRequestHdr
= HiiConstructConfigHdr (&mFormSetGuid
, VariableName
, PrivateData
->DriverHandle
[0]);
838 AppendAltCfgString(Results
, ConfigRequestHdr
);
843 // Free the allocated config request string.
845 if (AllocatedRequest
) {
846 FreePool (ConfigRequest
);
849 if (ConfigRequestHdr
!= NULL
) {
850 FreePool (ConfigRequestHdr
);
853 // Set Progress string to the original request string.
855 if (Request
== NULL
) {
857 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
858 *Progress
= Request
+ StrLen (Request
);
866 This function processes the results of changes in configuration.
868 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
869 @param Configuration A null-terminated Unicode string in <ConfigResp>
871 @param Progress A pointer to a string filled in with the offset of
872 the most recent '&' before the first failing
873 name/value pair (or the beginning of the string if
874 the failure is in the first name/value pair) or
875 the terminating NULL if all was successful.
877 @retval EFI_SUCCESS The Results is processed successfully.
878 @retval EFI_INVALID_PARAMETER Configuration is NULL.
879 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
886 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
887 IN CONST EFI_STRING Configuration
,
888 OUT EFI_STRING
*Progress
893 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
894 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
903 if (Configuration
== NULL
|| Progress
== NULL
) {
904 return EFI_INVALID_PARAMETER
;
907 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
908 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
909 *Progress
= Configuration
;
912 // Check routing data in <ConfigHdr>.
913 // Note: if only one Storage is used, then this checking could be skipped.
915 if (!HiiIsConfigHdrMatch (Configuration
, &mFormSetGuid
, NULL
)) {
916 return EFI_NOT_FOUND
;
920 // Get Buffer Storage data from EFI variable
922 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
923 Status
= gRT
->GetVariable (
928 &PrivateData
->Configuration
930 if (EFI_ERROR (Status
)) {
935 // Check if configuring Name/Value storage
937 if (StrStr (Configuration
, L
"OFFSET") == NULL
) {
939 // Update Name/Value storage Names
941 Status
= LoadNameValueNames (PrivateData
);
942 if (EFI_ERROR (Status
)) {
947 // Convert value for NameValueVar0
949 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[0])) != NULL
) {
953 Value
+= StrLen (PrivateData
->NameValueName
[0]);
958 StrPtr
= StrStr (Value
, L
"&");
959 if (StrPtr
== NULL
) {
960 StrPtr
= Value
+ StrLen (Value
);
963 // Convert Value to Buffer data
965 DataBuffer
= (UINT8
*) &PrivateData
->Configuration
.NameValueVar0
;
966 ZeroMem (TemStr
, sizeof (TemStr
));
967 for (Index
= 0, StrPtr
--; StrPtr
>= Value
; StrPtr
--, Index
++) {
969 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
970 if ((Index
& 1) == 0) {
971 DataBuffer
[Index
/2] = DigitUint8
;
973 DataBuffer
[Index
/2] = (UINT8
) ((UINT8
) (DigitUint8
<< 4) + DataBuffer
[Index
/2]);
979 // Convert value for NameValueVar1
981 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[1])) != NULL
) {
985 Value
+= StrLen (PrivateData
->NameValueName
[1]);
990 StrPtr
= StrStr (Value
, L
"&");
991 if (StrPtr
== NULL
) {
992 StrPtr
= Value
+ StrLen (Value
);
995 // Convert Value to Buffer data
997 DataBuffer
= (UINT8
*) &PrivateData
->Configuration
.NameValueVar1
;
998 ZeroMem (TemStr
, sizeof (TemStr
));
999 for (Index
= 0, StrPtr
--; StrPtr
>= Value
; StrPtr
--, Index
++) {
1000 TemStr
[0] = *StrPtr
;
1001 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1002 if ((Index
& 1) == 0) {
1003 DataBuffer
[Index
/2] = DigitUint8
;
1005 DataBuffer
[Index
/2] = (UINT8
) ((UINT8
) (DigitUint8
<< 4) + DataBuffer
[Index
/2]);
1011 // Convert value for NameValueVar2
1013 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[2])) != NULL
) {
1017 Value
+= StrLen (PrivateData
->NameValueName
[2]);
1022 StrPtr
= StrStr (Value
, L
"&");
1023 if (StrPtr
== NULL
) {
1024 StrPtr
= Value
+ StrLen (Value
);
1027 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1029 StrBuffer
= (CHAR16
*) PrivateData
->Configuration
.NameValueVar2
;
1030 ZeroMem (TemStr
, sizeof (TemStr
));
1031 while (Value
< StrPtr
) {
1032 StrnCpy (TemStr
, Value
, 4);
1033 *(StrBuffer
++) = (CHAR16
) StrHexToUint64 (TemStr
);
1040 // Store Buffer Storage back to EFI variable
1042 Status
= gRT
->SetVariable(
1045 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1046 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1047 &PrivateData
->Configuration
1054 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
1056 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
1057 Status
= HiiConfigRouting
->ConfigToBlock (
1060 (UINT8
*) &PrivateData
->Configuration
,
1064 if (EFI_ERROR (Status
)) {
1069 // Store Buffer Storage back to EFI variable
1071 Status
= gRT
->SetVariable(
1074 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1075 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1076 &PrivateData
->Configuration
1084 This function processes the results of changes in configuration.
1086 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1087 @param Action Specifies the type of action taken by the browser.
1088 @param QuestionId A unique value which is sent to the original
1089 exporting driver so that it can identify the type
1091 @param Type The type of value for the question.
1092 @param Value A pointer to the data being sent to the original
1094 @param ActionRequest On return, points to the action requested by the
1097 @retval EFI_SUCCESS The callback successfully handled the action.
1098 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1099 variable and its data.
1100 @retval EFI_DEVICE_ERROR The variable could not be saved.
1101 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1108 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1109 IN EFI_BROWSER_ACTION Action
,
1110 IN EFI_QUESTION_ID QuestionId
,
1112 IN EFI_IFR_TYPE_VALUE
*Value
,
1113 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1116 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
1119 VOID
*StartOpCodeHandle
;
1120 VOID
*OptionsOpCodeHandle
;
1121 EFI_IFR_GUID_LABEL
*StartLabel
;
1122 VOID
*EndOpCodeHandle
;
1123 EFI_IFR_GUID_LABEL
*EndLabel
;
1125 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
1128 if (((Value
== NULL
) && (Action
!= EFI_BROWSER_ACTION_FORM_OPEN
) && (Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
))||
1129 (ActionRequest
== NULL
)) {
1130 return EFI_INVALID_PARAMETER
;
1134 Status
= EFI_SUCCESS
;
1135 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
1138 case EFI_BROWSER_ACTION_FORM_OPEN
:
1140 if (QuestionId
== 0x1234) {
1142 // Sample CallBack for UEFI FORM_OPEN action:
1143 // Add Save action into Form 3 when Form 1 is opened.
1144 // This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.
1146 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
1149 // Initialize the container for dynamic opcodes
1151 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1152 ASSERT (StartOpCodeHandle
!= NULL
);
1155 // Create Hii Extend Label OpCode as the start opcode
1157 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1158 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1159 StartLabel
->Number
= LABEL_UPDATE2
;
1161 HiiCreateActionOpCode (
1162 StartOpCodeHandle
, // Container for dynamic created opcodes
1163 0x1238, // Question ID
1164 STRING_TOKEN(STR_SAVE_TEXT
), // Prompt text
1165 STRING_TOKEN(STR_SAVE_TEXT
), // Help text
1166 EFI_IFR_FLAG_CALLBACK
, // Question flag
1167 0 // Action String ID
1171 PrivateData
->HiiHandle
[0], // HII handle
1172 &mFormSetGuid
, // Formset GUID
1174 StartOpCodeHandle
, // Label for where to insert opcodes
1178 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1183 case EFI_BROWSER_ACTION_FORM_CLOSE
:
1185 if (QuestionId
== 0x5678) {
1187 // Sample CallBack for UEFI FORM_CLOSE action:
1188 // Show up a pop-up to specify Form 3 will be closed when exit Form 3.
1192 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1195 L
"You are going to leave third Form!",
1196 L
"Press ESC or ENTER to continue ...",
1200 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1205 case EFI_BROWSER_ACTION_RETRIEVE
:
1207 if (QuestionId
== 0x1111) {
1209 // EfiVarstore question takes sample action (print value as debug information)
1210 // after read/write question.
1213 Status
= gRT
->GetVariable(
1220 ASSERT_EFI_ERROR (Status
);
1221 DEBUG ((DEBUG_INFO
, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar
, MyVarSize
));
1226 case EFI_BROWSER_ACTION_DEFAULT_STANDARD
:
1228 switch (QuestionId
) {
1230 Value
->u8
= DEFAULT_CLASS_STANDARD_VALUE
;
1234 Status
= EFI_UNSUPPORTED
;
1240 case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
:
1242 switch (QuestionId
) {
1244 Value
->u8
= DEFAULT_CLASS_MANUFACTURING_VALUE
;
1248 Status
= EFI_UNSUPPORTED
;
1254 case EFI_BROWSER_ACTION_CHANGING
:
1256 switch (QuestionId
) {
1259 // Initialize the container for dynamic opcodes
1261 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1262 ASSERT (StartOpCodeHandle
!= NULL
);
1264 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
1265 ASSERT (EndOpCodeHandle
!= NULL
);
1268 // Create Hii Extend Label OpCode as the start opcode
1270 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1271 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1272 StartLabel
->Number
= LABEL_UPDATE1
;
1275 // Create Hii Extend Label OpCode as the end opcode
1277 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1278 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1279 EndLabel
->Number
= LABEL_END
;
1281 HiiCreateActionOpCode (
1282 StartOpCodeHandle
, // Container for dynamic created opcodes
1283 0x1237, // Question ID
1284 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
1285 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
1286 EFI_IFR_FLAG_CALLBACK
, // Question flag
1287 0 // Action String ID
1291 // Create Option OpCode
1293 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
1294 ASSERT (OptionsOpCodeHandle
!= NULL
);
1296 HiiCreateOneOfOptionOpCode (
1297 OptionsOpCodeHandle
,
1298 STRING_TOKEN (STR_BOOT_OPTION1
),
1300 EFI_IFR_NUMERIC_SIZE_1
,
1304 HiiCreateOneOfOptionOpCode (
1305 OptionsOpCodeHandle
,
1306 STRING_TOKEN (STR_BOOT_OPTION2
),
1308 EFI_IFR_NUMERIC_SIZE_1
,
1313 // Prepare initial value for the dynamic created oneof Question
1315 PrivateData
->Configuration
.DynamicOneof
= 2;
1316 Status
= gRT
->SetVariable(
1319 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1320 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1321 &PrivateData
->Configuration
1325 // Set initial vlaue of dynamic created oneof Question in Form Browser
1327 Configuration
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION
));
1328 ASSERT (Configuration
!= NULL
);
1329 if (HiiGetBrowserData (&mFormSetGuid
, VariableName
, sizeof (DRIVER_SAMPLE_CONFIGURATION
), (UINT8
*) Configuration
)) {
1330 Configuration
->DynamicOneof
= 2;
1333 // Update uncommitted data of Browser
1338 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1339 (UINT8
*) Configuration
,
1343 FreePool (Configuration
);
1345 HiiCreateOneOfOpCode (
1346 StartOpCodeHandle
, // Container for dynamic created opcodes
1347 0x8001, // Question ID (or call it "key")
1348 CONFIGURATION_VARSTORE_ID
, // VarStore ID
1349 (UINT16
) DYNAMIC_ONE_OF_VAR_OFFSET
, // Offset in Buffer Storage
1350 STRING_TOKEN (STR_ONE_OF_PROMPT
), // Question prompt text
1351 STRING_TOKEN (STR_ONE_OF_HELP
), // Question help text
1352 EFI_IFR_FLAG_CALLBACK
, // Question flag
1353 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question Value
1354 OptionsOpCodeHandle
, // Option Opcode list
1355 NULL
// Default Opcode is NULl
1358 HiiCreateOrderedListOpCode (
1359 StartOpCodeHandle
, // Container for dynamic created opcodes
1360 0x8002, // Question ID
1361 CONFIGURATION_VARSTORE_ID
, // VarStore ID
1362 (UINT16
) DYNAMIC_ORDERED_LIST_VAR_OFFSET
, // Offset in Buffer Storage
1363 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question prompt text
1364 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question help text
1365 EFI_IFR_FLAG_RESET_REQUIRED
, // Question flag
1366 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
1367 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question value
1368 5, // Maximum container
1369 OptionsOpCodeHandle
, // Option Opcode list
1370 NULL
// Default Opcode is NULl
1373 HiiCreateTextOpCode (
1375 STRING_TOKEN(STR_TEXT_SAMPLE_HELP
),
1376 STRING_TOKEN(STR_TEXT_SAMPLE_HELP
),
1377 STRING_TOKEN(STR_TEXT_SAMPLE_STRING
)
1380 HiiCreateDateOpCode (
1385 STRING_TOKEN(STR_DATE_SAMPLE_HELP
),
1386 STRING_TOKEN(STR_DATE_SAMPLE_HELP
),
1388 QF_DATE_STORAGE_TIME
,
1392 HiiCreateTimeOpCode (
1397 STRING_TOKEN(STR_TIME_SAMPLE_HELP
),
1398 STRING_TOKEN(STR_TIME_SAMPLE_HELP
),
1400 QF_TIME_STORAGE_TIME
,
1404 HiiCreateGotoOpCode (
1405 StartOpCodeHandle
, // Container for dynamic created opcodes
1406 1, // Target Form ID
1407 STRING_TOKEN (STR_GOTO_FORM1
), // Prompt text
1408 STRING_TOKEN (STR_GOTO_HELP
), // Help text
1410 0x8003 // Question ID
1414 PrivateData
->HiiHandle
[0], // HII handle
1415 &mFormSetGuid
, // Formset GUID
1417 StartOpCodeHandle
, // Label for where to insert opcodes
1418 EndOpCodeHandle
// Replace data
1421 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1422 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1423 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1428 // We will reach here once the Question is refreshed
1432 // Initialize the container for dynamic opcodes
1434 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1435 ASSERT (StartOpCodeHandle
!= NULL
);
1438 // Create Hii Extend Label OpCode as the start opcode
1440 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1441 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1442 StartLabel
->Number
= LABEL_UPDATE2
;
1444 HiiCreateActionOpCode (
1445 StartOpCodeHandle
, // Container for dynamic created opcodes
1446 0x1237, // Question ID
1447 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
1448 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
1449 EFI_IFR_FLAG_CALLBACK
, // Question flag
1450 0 // Action String ID
1454 PrivateData
->HiiHandle
[0], // HII handle
1455 &mFormSetGuid
, // Formset GUID
1457 StartOpCodeHandle
, // Label for where to insert opcodes
1461 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1464 // Refresh the Question value
1466 PrivateData
->Configuration
.DynamicRefresh
++;
1467 Status
= gRT
->SetVariable(
1470 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1471 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1472 &PrivateData
->Configuration
1476 // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
1477 // the first statement in Form 3 be suppressed
1481 Status
= gRT
->SetVariable(
1484 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1492 // User press "Exit now", request Browser to exit
1494 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1499 // User press "Save now", request Browser to save the uncommitted data.
1501 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1506 // User press "Submit current form and Exit now", request Browser to submit current form and exit
1508 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1513 // User press "Discard current form now", request Browser to discard the uncommitted data.
1515 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD
;
1520 // User press "Submit current form now", request Browser to save the uncommitted data.
1522 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1527 // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.
1529 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1534 // Only used to update the state.
1536 if ((Type
== EFI_IFR_TYPE_STRING
) && (Value
->string
== 0) &&
1537 (PrivateData
->PasswordState
== BROWSER_STATE_SET_PASSWORD
)) {
1538 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
1539 return EFI_INVALID_PARAMETER
;
1543 // When try to set a new password, user will be chanlleged with old password.
1544 // The Callback is responsible for validating old password input by user,
1545 // If Callback return EFI_SUCCESS, it indicates validation pass.
1547 switch (PrivateData
->PasswordState
) {
1548 case BROWSER_STATE_VALIDATE_PASSWORD
:
1549 Status
= ValidatePassword (PrivateData
, Value
->string
);
1550 if (Status
== EFI_SUCCESS
) {
1551 PrivateData
->PasswordState
= BROWSER_STATE_SET_PASSWORD
;
1555 case BROWSER_STATE_SET_PASSWORD
:
1556 Status
= SetPassword (PrivateData
, Value
->string
);
1557 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
1568 // EfiVarstore question takes sample action (print value as debug information)
1569 // after read/write question.
1572 Status
= gRT
->GetVariable(
1579 ASSERT_EFI_ERROR (Status
);
1580 DEBUG ((DEBUG_INFO
, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar
, MyVarSize
));
1588 Status
= EFI_UNSUPPORTED
;
1596 Main entry for this driver.
1598 @param ImageHandle Image handle this driver.
1599 @param SystemTable Pointer to SystemTable.
1601 @retval EFI_SUCESS This function always complete successfully.
1607 IN EFI_HANDLE ImageHandle
,
1608 IN EFI_SYSTEM_TABLE
*SystemTable
1612 EFI_HII_HANDLE HiiHandle
[2];
1613 EFI_SCREEN_DESCRIPTOR Screen
;
1614 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1615 EFI_HII_STRING_PROTOCOL
*HiiString
;
1616 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1617 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1620 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
1622 EFI_STRING ConfigRequestHdr
;
1625 // Initialize the local variables.
1627 ConfigRequestHdr
= NULL
;
1629 // Initialize screen dimensions for SendForm().
1630 // Remove 3 characters from top and bottom
1632 ZeroMem (&Screen
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1633 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Screen
.RightColumn
, &Screen
.BottomRow
);
1636 Screen
.BottomRow
= Screen
.BottomRow
- 3;
1639 // Initialize driver private data
1641 PrivateData
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA
));
1642 if (PrivateData
== NULL
) {
1643 return EFI_OUT_OF_RESOURCES
;
1646 PrivateData
->Signature
= DRIVER_SAMPLE_PRIVATE_SIGNATURE
;
1648 PrivateData
->ConfigAccess
.ExtractConfig
= ExtractConfig
;
1649 PrivateData
->ConfigAccess
.RouteConfig
= RouteConfig
;
1650 PrivateData
->ConfigAccess
.Callback
= DriverCallback
;
1651 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
1654 // Locate Hii Database protocol
1656 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &HiiDatabase
);
1657 if (EFI_ERROR (Status
)) {
1660 PrivateData
->HiiDatabase
= HiiDatabase
;
1663 // Locate HiiString protocol
1665 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
1666 if (EFI_ERROR (Status
)) {
1669 PrivateData
->HiiString
= HiiString
;
1672 // Locate Formbrowser2 protocol
1674 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &FormBrowser2
);
1675 if (EFI_ERROR (Status
)) {
1678 PrivateData
->FormBrowser2
= FormBrowser2
;
1681 // Locate ConfigRouting protocol
1683 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &HiiConfigRouting
);
1684 if (EFI_ERROR (Status
)) {
1687 PrivateData
->HiiConfigRouting
= HiiConfigRouting
;
1689 Status
= gBS
->InstallMultipleProtocolInterfaces (
1691 &gEfiDevicePathProtocolGuid
,
1692 &mHiiVendorDevicePath0
,
1693 &gEfiHiiConfigAccessProtocolGuid
,
1694 &PrivateData
->ConfigAccess
,
1697 ASSERT_EFI_ERROR (Status
);
1699 PrivateData
->DriverHandle
[0] = DriverHandle
[0];
1702 // Publish our HII data
1704 HiiHandle
[0] = HiiAddPackages (
1707 DriverSampleStrings
,
1711 if (HiiHandle
[0] == NULL
) {
1712 return EFI_OUT_OF_RESOURCES
;
1715 PrivateData
->HiiHandle
[0] = HiiHandle
[0];
1718 // Publish another Fromset
1720 Status
= gBS
->InstallMultipleProtocolInterfaces (
1722 &gEfiDevicePathProtocolGuid
,
1723 &mHiiVendorDevicePath1
,
1726 ASSERT_EFI_ERROR (Status
);
1728 PrivateData
->DriverHandle
[1] = DriverHandle
[1];
1730 HiiHandle
[1] = HiiAddPackages (
1733 DriverSampleStrings
,
1737 if (HiiHandle
[1] == NULL
) {
1738 DriverSampleUnload (ImageHandle
);
1739 return EFI_OUT_OF_RESOURCES
;
1742 PrivateData
->HiiHandle
[1] = HiiHandle
[1];
1745 // Very simple example of how one would update a string that is already
1746 // in the HII database
1748 NewString
= L
"700 Mhz";
1750 if (HiiSetString (HiiHandle
[0], STRING_TOKEN (STR_CPU_STRING2
), NewString
, NULL
) == 0) {
1751 DriverSampleUnload (ImageHandle
);
1752 return EFI_OUT_OF_RESOURCES
;
1755 HiiSetString (HiiHandle
[0], 0, NewString
, NULL
);
1758 // Initialize Name/Value name String ID
1760 PrivateData
->NameStringId
[0] = STR_NAME_VALUE_VAR_NAME0
;
1761 PrivateData
->NameStringId
[1] = STR_NAME_VALUE_VAR_NAME1
;
1762 PrivateData
->NameStringId
[2] = STR_NAME_VALUE_VAR_NAME2
;
1765 // Initialize configuration data
1767 Configuration
= &PrivateData
->Configuration
;
1768 ZeroMem (Configuration
, sizeof (DRIVER_SAMPLE_CONFIGURATION
));
1771 // Try to read NV config EFI variable first
1773 ConfigRequestHdr
= HiiConstructConfigHdr (&mFormSetGuid
, VariableName
, DriverHandle
[0]);
1774 ASSERT (ConfigRequestHdr
!= NULL
);
1776 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
1777 Status
= gRT
->GetVariable (VariableName
, &mFormSetGuid
, NULL
, &BufferSize
, Configuration
);
1778 if (EFI_ERROR (Status
)) {
1780 // Store zero data Buffer Storage to EFI variable
1782 Status
= gRT
->SetVariable(
1785 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1786 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1789 ASSERT (Status
== EFI_SUCCESS
);
1791 // EFI variable for NV config doesn't exit, we should build this variable
1792 // based on default values stored in IFR
1794 ActionFlag
= HiiSetToDefaults (ConfigRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
1795 ASSERT (ActionFlag
);
1798 // EFI variable does exist and Validate Current Setting
1800 ActionFlag
= HiiValidateSettings (ConfigRequestHdr
);
1801 ASSERT (ActionFlag
);
1804 FreePool (ConfigRequestHdr
);
1808 // In default, this driver is built into Flash device image,
1809 // the following code doesn't run.
1813 // Example of how to display only the item we sent to HII
1814 // When this driver is not built into Flash device image,
1815 // it need to call SendForm to show front page by itself.
1817 if (DISPLAY_ONLY_MY_ITEM
<= 1) {
1819 // Have the browser pull out our copy of the data, and only display our data
1821 Status
= FormBrowser2
->SendForm (
1823 &(HiiHandle
[DISPLAY_ONLY_MY_ITEM
]),
1831 HiiRemovePackages (HiiHandle
[0]);
1833 HiiRemovePackages (HiiHandle
[1]);
1840 Unloads the application and its installed protocol.
1842 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1844 @retval EFI_SUCCESS The image has been unloaded.
1848 DriverSampleUnload (
1849 IN EFI_HANDLE ImageHandle
1854 ASSERT (PrivateData
!= NULL
);
1856 if (DriverHandle
[0] != NULL
) {
1857 gBS
->UninstallMultipleProtocolInterfaces (
1859 &gEfiDevicePathProtocolGuid
,
1860 &mHiiVendorDevicePath0
,
1861 &gEfiHiiConfigAccessProtocolGuid
,
1862 &PrivateData
->ConfigAccess
,
1865 DriverHandle
[0] = NULL
;
1868 if (DriverHandle
[1] != NULL
) {
1869 gBS
->UninstallMultipleProtocolInterfaces (
1871 &gEfiDevicePathProtocolGuid
,
1872 &mHiiVendorDevicePath1
,
1875 DriverHandle
[1] = NULL
;
1878 if (PrivateData
->HiiHandle
[0] != NULL
) {
1879 HiiRemovePackages (PrivateData
->HiiHandle
[0]);
1882 if (PrivateData
->HiiHandle
[1] != NULL
) {
1883 HiiRemovePackages (PrivateData
->HiiHandle
[1]);
1886 for (Index
= 0; Index
< NAME_VALUE_NAME_NUMBER
; Index
++) {
1887 if (PrivateData
->NameValueName
[Index
] != NULL
) {
1888 FreePool (PrivateData
->NameValueName
[Index
]);
1891 FreePool (PrivateData
);