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 - 2016, 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 CHAR16 VariableName
[] = L
"MyIfrNVData";
22 CHAR16 MyEfiVar
[] = L
"MyEfiVar";
23 EFI_HANDLE DriverHandle
[2] = {NULL
, NULL
};
24 DRIVER_SAMPLE_PRIVATE_DATA
*mPrivateData
= NULL
;
27 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0
= {
33 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
34 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
37 DRIVER_SAMPLE_FORMSET_GUID
41 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
43 (UINT8
) (END_DEVICE_PATH_LENGTH
),
44 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
49 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1
= {
55 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
56 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
59 DRIVER_SAMPLE_INVENTORY_GUID
63 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
65 (UINT8
) (END_DEVICE_PATH_LENGTH
),
66 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
72 Set value of a data element in an Array by its Index.
74 @param Array The data array.
75 @param Type Type of the data in this array.
76 @param Index Zero based index for data in this array.
77 @param Value The value to be set.
89 ASSERT (Array
!= NULL
);
92 case EFI_IFR_TYPE_NUM_SIZE_8
:
93 *(((UINT8
*) Array
) + Index
) = (UINT8
) Value
;
96 case EFI_IFR_TYPE_NUM_SIZE_16
:
97 *(((UINT16
*) Array
) + Index
) = (UINT16
) Value
;
100 case EFI_IFR_TYPE_NUM_SIZE_32
:
101 *(((UINT32
*) Array
) + Index
) = (UINT32
) Value
;
104 case EFI_IFR_TYPE_NUM_SIZE_64
:
105 *(((UINT64
*) Array
) + Index
) = (UINT64
) Value
;
114 Add empty function for event process function.
116 @param Event The Event need to be process
117 @param Context The context of the event.
122 DriverSampleInternalEmptyFunction (
130 Notification function for keystrokes.
132 @param[in] KeyData The key that was pressed.
134 @retval EFI_SUCCESS The operation was successful.
138 NotificationFunction(
139 IN EFI_KEY_DATA
*KeyData
142 gBS
->SignalEvent (mEvent
);
148 Function to start monitoring for CTRL-C using SimpleTextInputEx.
150 @retval EFI_SUCCESS The feature is enabled.
151 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
155 InternalStartMonitor(
159 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*SimpleEx
;
160 EFI_KEY_DATA KeyData
;
165 EFI_HANDLE NotifyHandle
;
167 Status
= gBS
->LocateHandleBuffer (
169 &gEfiSimpleTextInputExProtocolGuid
,
174 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
175 Status
= gBS
->HandleProtocol (Handles
[HandleIndex
], &gEfiSimpleTextInputExProtocolGuid
, (VOID
**) &SimpleEx
);
176 ASSERT_EFI_ERROR (Status
);
178 KeyData
.KeyState
.KeyToggleState
= 0;
179 KeyData
.Key
.ScanCode
= 0;
180 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
181 KeyData
.Key
.UnicodeChar
= L
'c';
183 Status
= SimpleEx
->RegisterKeyNotify(
186 NotificationFunction
,
188 if (EFI_ERROR (Status
)) {
192 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
193 Status
= SimpleEx
->RegisterKeyNotify(
196 NotificationFunction
,
198 if (EFI_ERROR (Status
)) {
207 Function to stop monitoring for CTRL-C using SimpleTextInputEx.
209 @retval EFI_SUCCESS The feature is enabled.
210 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
218 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*SimpleEx
;
221 EFI_KEY_DATA KeyData
;
224 EFI_HANDLE NotifyHandle
;
226 Status
= gBS
->LocateHandleBuffer (
228 &gEfiSimpleTextInputExProtocolGuid
,
233 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
234 Status
= gBS
->HandleProtocol (Handles
[HandleIndex
], &gEfiSimpleTextInputExProtocolGuid
, (VOID
**) &SimpleEx
);
235 ASSERT_EFI_ERROR (Status
);
237 KeyData
.KeyState
.KeyToggleState
= 0;
238 KeyData
.Key
.ScanCode
= 0;
239 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
240 KeyData
.Key
.UnicodeChar
= L
'c';
242 Status
= SimpleEx
->RegisterKeyNotify(
245 NotificationFunction
,
247 if (!EFI_ERROR (Status
)) {
248 Status
= SimpleEx
->UnregisterKeyNotify (SimpleEx
, NotifyHandle
);
251 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
252 Status
= SimpleEx
->RegisterKeyNotify(
255 NotificationFunction
,
257 if (!EFI_ERROR (Status
)) {
258 Status
= SimpleEx
->UnregisterKeyNotify (SimpleEx
, NotifyHandle
);
266 Encode the password using a simple algorithm.
268 @param Password The string to be encoded.
269 @param MaxSize The size of the string.
283 Key
= L
"MAR10648567";
284 Buffer
= AllocateZeroPool (MaxSize
);
285 ASSERT (Buffer
!= NULL
);
287 for (Index
= 0; Key
[Index
] != 0; Index
++) {
288 for (Loop
= 0; Loop
< (UINT8
) (MaxSize
/ 2); Loop
++) {
289 Buffer
[Loop
] = (CHAR16
) (Password
[Loop
] ^ Key
[Index
]);
293 CopyMem (Password
, Buffer
, MaxSize
);
300 Validate the user's password.
302 @param PrivateData This driver's private context data.
303 @param StringId The user's input.
305 @retval EFI_SUCCESS The user's input matches the password.
306 @retval EFI_NOT_READY The user's input does not match the password.
310 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
311 IN EFI_STRING_ID StringId
317 UINTN PasswordMaxSize
;
319 CHAR16
*EncodedPassword
;
323 // Get encoded password first
325 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
326 Status
= gRT
->GetVariable (
328 &gDriverSampleFormSetGuid
,
331 &PrivateData
->Configuration
333 if (EFI_ERROR (Status
)) {
335 // Old password not exist, prompt for new password
341 PasswordMaxSize
= sizeof (PrivateData
->Configuration
.WhatIsThePassword2
);
343 // Check whether we have any old password set
345 for (Index
= 0; Index
< PasswordMaxSize
/ sizeof (UINT16
); Index
++) {
346 if (PrivateData
->Configuration
.WhatIsThePassword2
[Index
] != 0) {
353 // Old password not exist, return EFI_SUCCESS to prompt for new password
359 // Get user input password
361 Password
= HiiGetString (PrivateData
->HiiHandle
[0], StringId
, NULL
);
362 if (Password
== NULL
) {
363 return EFI_NOT_READY
;
365 if (StrSize (Password
) > PasswordMaxSize
) {
367 return EFI_NOT_READY
;
371 // Validate old password
373 EncodedPassword
= AllocateZeroPool (PasswordMaxSize
);
374 ASSERT (EncodedPassword
!= NULL
);
375 StrnCpyS (EncodedPassword
, PasswordMaxSize
/ sizeof (CHAR16
), Password
, StrLen (Password
));
376 EncodePassword (EncodedPassword
, StrLen (EncodedPassword
) * sizeof (CHAR16
));
377 if (CompareMem (EncodedPassword
, PrivateData
->Configuration
.WhatIsThePassword2
, PasswordMaxSize
) != 0) {
379 // Old password mismatch, return EFI_NOT_READY to prompt for error message
381 Status
= EFI_NOT_READY
;
383 Status
= EFI_SUCCESS
;
387 FreePool (EncodedPassword
);
393 Encode the password using a simple algorithm.
395 @param PrivateData This driver's private context data.
396 @param StringId The password from User.
398 @retval EFI_SUCESS The operation is successful.
399 @return Other value if gRT->SetVariable () fails.
404 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
405 IN EFI_STRING_ID StringId
410 CHAR16
*TempPassword
;
412 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
416 // Get Buffer Storage data from EFI variable
418 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
419 Status
= gRT
->GetVariable (
421 &gDriverSampleFormSetGuid
,
424 &PrivateData
->Configuration
426 if (EFI_ERROR (Status
)) {
431 // Get user input password
433 Password
= PrivateData
->Configuration
.WhatIsThePassword2
;
434 PasswordSize
= sizeof (PrivateData
->Configuration
.WhatIsThePassword2
);
435 ZeroMem (Password
, PasswordSize
);
437 TempPassword
= HiiGetString (PrivateData
->HiiHandle
[0], StringId
, NULL
);
438 if (TempPassword
== NULL
) {
439 return EFI_NOT_READY
;
441 if (StrSize (TempPassword
) > PasswordSize
) {
442 FreePool (TempPassword
);
443 return EFI_NOT_READY
;
445 StrnCpyS (Password
, PasswordSize
/ sizeof (CHAR16
), TempPassword
, StrLen (TempPassword
));
446 FreePool (TempPassword
);
449 // Retrive uncommitted data from Browser
451 Configuration
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION
));
452 ASSERT (Configuration
!= NULL
);
453 if (HiiGetBrowserData (&gDriverSampleFormSetGuid
, VariableName
, sizeof (DRIVER_SAMPLE_CONFIGURATION
), (UINT8
*) Configuration
)) {
455 // Update password's clear text in the screen
457 CopyMem (Configuration
->PasswordClearText
, Password
, StrSize (Password
));
460 // Update uncommitted data of Browser
463 &gDriverSampleFormSetGuid
,
465 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
466 (UINT8
*) Configuration
,
472 // Free Configuration Buffer
474 FreePool (Configuration
);
480 EncodePassword (Password
, StrLen (Password
) * 2);
481 Status
= gRT
->SetVariable(
483 &gDriverSampleFormSetGuid
,
484 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
485 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
486 &PrivateData
->Configuration
492 Update names of Name/Value storage to current language.
494 @param PrivateData Points to the driver private data.
496 @retval EFI_SUCCESS All names are successfully updated.
497 @retval EFI_NOT_FOUND Failed to get Name from HII database.
502 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
508 // Get Name/Value name string of current language
510 for (Index
= 0; Index
< NAME_VALUE_NAME_NUMBER
; Index
++) {
511 PrivateData
->NameValueName
[Index
] = HiiGetString (
512 PrivateData
->HiiHandle
[0],
513 PrivateData
->NameStringId
[Index
],
516 if (PrivateData
->NameValueName
[Index
] == NULL
) {
517 return EFI_NOT_FOUND
;
526 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
528 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
530 This is a internal function.
532 @param StringPtr String in <BlockConfig> format and points to the
533 first character of <Number>.
534 @param Number The output value. Caller takes the responsibility
536 @param Len Length of the <Number>, in characters.
538 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
540 @retval EFI_SUCCESS Value of <Number> is outputted in Number
546 IN EFI_STRING StringPtr
,
560 if (StringPtr
== NULL
|| *StringPtr
== L
'\0' || Number
== NULL
|| Len
== NULL
) {
561 return EFI_INVALID_PARAMETER
;
567 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
570 *Len
= StringPtr
- TmpPtr
;
573 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
575 Status
= EFI_OUT_OF_RESOURCES
;
578 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
579 *(Str
+ *Len
) = L
'\0';
581 Length
= (Length
+ 1) / 2;
582 Buf
= (UINT8
*) AllocateZeroPool (Length
);
584 Status
= EFI_OUT_OF_RESOURCES
;
589 ZeroMem (TemStr
, sizeof (TemStr
));
590 for (Index
= 0; Index
< Length
; Index
++) {
591 TemStr
[0] = Str
[Length
- Index
- 1];
592 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
593 if ((Index
& 1) == 0) {
594 Buf
[Index
/2] = DigitUint8
;
596 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
601 Status
= EFI_SUCCESS
;
612 Create altcfg string.
614 @param Result The request result string.
615 @param ConfigHdr The request head info. <ConfigHdr> format.
616 @param Offset The offset of the parameter int he structure.
617 @param Width The width of the parameter.
620 @retval The string with altcfg info append at the end.
624 IN EFI_STRING Result
,
625 IN EFI_STRING ConfigHdr
,
630 EFI_STRING StringPtr
;
634 NewLen
= StrLen (Result
);
636 // String Len = ConfigResp + AltConfig + AltConfig + 1("\0")
638 NewLen
= (NewLen
+ ((1 + StrLen (ConfigHdr
) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16
);
639 StringPtr
= AllocateZeroPool (NewLen
);
640 if (StringPtr
== NULL
) {
645 if (Result
!= NULL
) {
646 StrCpyS (StringPtr
, NewLen
/ sizeof (CHAR16
), Result
);
647 StringPtr
+= StrLen (Result
);
653 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
656 EFI_HII_DEFAULT_CLASS_STANDARD
658 StringPtr
+= StrLen (StringPtr
);
662 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
663 L
"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
666 DEFAULT_CLASS_STANDARD_VALUE
668 StringPtr
+= StrLen (StringPtr
);
672 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
675 EFI_HII_DEFAULT_CLASS_MANUFACTURING
677 StringPtr
+= StrLen (StringPtr
);
681 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
682 L
"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
685 DEFAULT_CLASS_MANUFACTURING_VALUE
687 StringPtr
+= StrLen (StringPtr
);
693 Check whether need to add the altcfg string. if need to add, add the altcfg
696 @param RequestResult The request result string.
697 @param ConfigRequestHdr The request head info. <ConfigHdr> format.
702 IN OUT EFI_STRING
*RequestResult
,
703 IN EFI_STRING ConfigRequestHdr
706 EFI_STRING StringPtr
;
717 StringPtr
= *RequestResult
;
718 StringPtr
= StrStr (StringPtr
, L
"OFFSET");
719 BlockSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
720 ValueOffset
= OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION
, GetDefaultValueFromAccess
);
721 ValueWidth
= sizeof (((DRIVER_SAMPLE_CONFIGURATION
*)0)->GetDefaultValueFromAccess
);
723 if (StringPtr
== NULL
) {
727 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
728 StringPtr
+= StrLen (L
"OFFSET=");
732 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
733 if (EFI_ERROR (Status
)) {
740 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
742 FreePool (TmpBuffer
);
745 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
748 StringPtr
+= StrLen (L
"&WIDTH=");
753 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
754 if (EFI_ERROR (Status
)) {
761 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
763 FreePool (TmpBuffer
);
766 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
769 StringPtr
+= StrLen (L
"&VALUE=");
774 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
775 if (EFI_ERROR (Status
)) {
781 // Calculate Value and convert it to hex string.
783 if (Offset
+ Width
> BlockSize
) {
787 if (Offset
<= ValueOffset
&& Offset
+ Width
>= ValueOffset
+ ValueWidth
) {
788 *RequestResult
= CreateAltCfgString(*RequestResult
, ConfigRequestHdr
, ValueOffset
, ValueWidth
);
795 This function allows a caller to extract the current configuration for one
796 or more named elements from the target driver.
798 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
799 @param Request A null-terminated Unicode string in
800 <ConfigRequest> format.
801 @param Progress On return, points to a character in the Request
802 string. Points to the string's null terminator if
803 request was successful. Points to the most recent
804 '&' before the first failing name/value pair (or
805 the beginning of the string if the failure is in
806 the first name/value pair) if the request was not
808 @param Results A null-terminated Unicode string in
809 <ConfigAltResp> format which has all values filled
810 in for the names in the Request string. String to
811 be allocated by the called function.
813 @retval EFI_SUCCESS The Results is filled with the requested values.
814 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
815 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
816 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
823 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
824 IN CONST EFI_STRING Request
,
825 OUT EFI_STRING
*Progress
,
826 OUT EFI_STRING
*Results
831 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
832 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
833 EFI_STRING ConfigRequest
;
834 EFI_STRING ConfigRequestHdr
;
840 BOOLEAN AllocatedRequest
;
842 if (Progress
== NULL
|| Results
== NULL
) {
843 return EFI_INVALID_PARAMETER
;
846 // Initialize the local variables.
848 ConfigRequestHdr
= NULL
;
849 ConfigRequest
= NULL
;
852 AllocatedRequest
= FALSE
;
854 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
855 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
858 // Get Buffer Storage data from EFI variable.
859 // Try to get the current setting from variable.
861 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
862 Status
= gRT
->GetVariable (
864 &gDriverSampleFormSetGuid
,
867 &PrivateData
->Configuration
869 if (EFI_ERROR (Status
)) {
870 return EFI_NOT_FOUND
;
873 if (Request
== NULL
) {
875 // Request is set to NULL, construct full request string.
879 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
880 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
882 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, VariableName
, PrivateData
->DriverHandle
[0]);
883 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
884 ConfigRequest
= AllocateZeroPool (Size
);
885 ASSERT (ConfigRequest
!= NULL
);
886 AllocatedRequest
= TRUE
;
887 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
888 FreePool (ConfigRequestHdr
);
889 ConfigRequestHdr
= NULL
;
892 // Check routing data in <ConfigHdr>.
893 // Note: if only one Storage is used, then this checking could be skipped.
895 if (!HiiIsConfigHdrMatch (Request
, &gDriverSampleFormSetGuid
, NULL
)) {
896 return EFI_NOT_FOUND
;
899 // Check whether request for EFI Varstore. EFI varstore get data
900 // through hii database, not support in this path.
902 if (HiiIsConfigHdrMatch(Request
, &gDriverSampleFormSetGuid
, MyEfiVar
)) {
903 return EFI_UNSUPPORTED
;
906 // Set Request to the unified request string.
908 ConfigRequest
= Request
;
910 // Check whether Request includes Request Element.
912 if (StrStr (Request
, L
"OFFSET") == NULL
) {
914 // Check Request Element does exist in Reques String
916 StrPointer
= StrStr (Request
, L
"PATH");
917 if (StrPointer
== NULL
) {
918 return EFI_INVALID_PARAMETER
;
920 if (StrStr (StrPointer
, L
"&") == NULL
) {
921 Size
= (StrLen (Request
) + 32 + 1) * sizeof (CHAR16
);
922 ConfigRequest
= AllocateZeroPool (Size
);
923 ASSERT (ConfigRequest
!= NULL
);
924 AllocatedRequest
= TRUE
;
925 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", Request
, (UINT64
)BufferSize
);
931 // Check if requesting Name/Value storage
933 if (StrStr (ConfigRequest
, L
"OFFSET") == NULL
) {
935 // Update Name/Value storage Names
937 Status
= LoadNameValueNames (PrivateData
);
938 if (EFI_ERROR (Status
)) {
943 // Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
944 // <Request> ::=<ConfigHdr>&Name0&Name1&Name2
945 // <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
947 BufferSize
= (StrLen (ConfigRequest
) +
948 1 + sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2 +
949 1 + sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2 +
950 1 + sizeof (PrivateData
->Configuration
.NameValueVar2
) * 2 + 1) * sizeof (CHAR16
);
951 *Results
= AllocateZeroPool (BufferSize
);
952 ASSERT (*Results
!= NULL
);
953 StrCpyS (*Results
, BufferSize
/ sizeof (CHAR16
), ConfigRequest
);
957 // Append value of NameValueVar0, type is UINT8
959 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[0])) != NULL
) {
960 Value
+= StrLen (PrivateData
->NameValueName
[0]);
961 ValueStrLen
= ((sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2) + 1);
962 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
964 BackupChar
= Value
[ValueStrLen
];
966 Value
+= UnicodeValueToString (
968 PREFIX_ZERO
| RADIX_HEX
,
969 PrivateData
->Configuration
.NameValueVar0
,
970 sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2
976 // Append value of NameValueVar1, type is UINT16
978 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[1])) != NULL
) {
979 Value
+= StrLen (PrivateData
->NameValueName
[1]);
980 ValueStrLen
= ((sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2) + 1);
981 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
983 BackupChar
= Value
[ValueStrLen
];
985 Value
+= UnicodeValueToString (
987 PREFIX_ZERO
| RADIX_HEX
,
988 PrivateData
->Configuration
.NameValueVar1
,
989 sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2
995 // Append value of NameValueVar2, type is CHAR16 *
997 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[2])) != NULL
) {
998 Value
+= StrLen (PrivateData
->NameValueName
[2]);
999 ValueStrLen
= StrLen (PrivateData
->Configuration
.NameValueVar2
) * 4 + 1;
1000 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
1004 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
1006 StrPointer
= (CHAR16
*) PrivateData
->Configuration
.NameValueVar2
;
1007 for (; *StrPointer
!= L
'\0'; StrPointer
++) {
1008 Value
+= UnicodeValueToString (Value
, PREFIX_ZERO
| RADIX_HEX
, *StrPointer
, 4);
1012 Status
= EFI_SUCCESS
;
1015 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1017 Status
= HiiConfigRouting
->BlockToConfig (
1020 (UINT8
*) &PrivateData
->Configuration
,
1025 if (!EFI_ERROR (Status
)) {
1026 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, VariableName
, PrivateData
->DriverHandle
[0]);
1027 AppendAltCfgString(Results
, ConfigRequestHdr
);
1032 // Free the allocated config request string.
1034 if (AllocatedRequest
) {
1035 FreePool (ConfigRequest
);
1038 if (ConfigRequestHdr
!= NULL
) {
1039 FreePool (ConfigRequestHdr
);
1042 // Set Progress string to the original request string.
1044 if (Request
== NULL
) {
1046 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1047 *Progress
= Request
+ StrLen (Request
);
1055 This function processes the results of changes in configuration.
1057 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1058 @param Configuration A null-terminated Unicode string in <ConfigResp>
1060 @param Progress A pointer to a string filled in with the offset of
1061 the most recent '&' before the first failing
1062 name/value pair (or the beginning of the string if
1063 the failure is in the first name/value pair) or
1064 the terminating NULL if all was successful.
1066 @retval EFI_SUCCESS The Results is processed successfully.
1067 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1068 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1075 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1076 IN CONST EFI_STRING Configuration
,
1077 OUT EFI_STRING
*Progress
1082 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
1083 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1092 if (Configuration
== NULL
|| Progress
== NULL
) {
1093 return EFI_INVALID_PARAMETER
;
1096 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
1097 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
1098 *Progress
= Configuration
;
1101 // Check routing data in <ConfigHdr>.
1102 // Note: if only one Storage is used, then this checking could be skipped.
1104 if (!HiiIsConfigHdrMatch (Configuration
, &gDriverSampleFormSetGuid
, NULL
)) {
1105 return EFI_NOT_FOUND
;
1109 // Check whether request for EFI Varstore. EFI varstore get data
1110 // through hii database, not support in this path.
1112 if (HiiIsConfigHdrMatch(Configuration
, &gDriverSampleFormSetGuid
, MyEfiVar
)) {
1113 return EFI_UNSUPPORTED
;
1117 // Get Buffer Storage data from EFI variable
1119 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
1120 Status
= gRT
->GetVariable (
1122 &gDriverSampleFormSetGuid
,
1125 &PrivateData
->Configuration
1127 if (EFI_ERROR (Status
)) {
1132 // Check if configuring Name/Value storage
1134 if (StrStr (Configuration
, L
"OFFSET") == NULL
) {
1136 // Update Name/Value storage Names
1138 Status
= LoadNameValueNames (PrivateData
);
1139 if (EFI_ERROR (Status
)) {
1144 // Convert value for NameValueVar0
1146 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[0])) != NULL
) {
1150 Value
+= StrLen (PrivateData
->NameValueName
[0]);
1155 StrPtr
= StrStr (Value
, L
"&");
1156 if (StrPtr
== NULL
) {
1157 StrPtr
= Value
+ StrLen (Value
);
1160 // Convert Value to Buffer data
1162 DataBuffer
= (UINT8
*) &PrivateData
->Configuration
.NameValueVar0
;
1163 ZeroMem (TemStr
, sizeof (TemStr
));
1164 for (Index
= 0, StrPtr
--; StrPtr
>= Value
; StrPtr
--, Index
++) {
1165 TemStr
[0] = *StrPtr
;
1166 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1167 if ((Index
& 1) == 0) {
1168 DataBuffer
[Index
/2] = DigitUint8
;
1170 DataBuffer
[Index
/2] = (UINT8
) ((UINT8
) (DigitUint8
<< 4) + DataBuffer
[Index
/2]);
1176 // Convert value for NameValueVar1
1178 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[1])) != NULL
) {
1182 Value
+= StrLen (PrivateData
->NameValueName
[1]);
1187 StrPtr
= StrStr (Value
, L
"&");
1188 if (StrPtr
== NULL
) {
1189 StrPtr
= Value
+ StrLen (Value
);
1192 // Convert Value to Buffer data
1194 DataBuffer
= (UINT8
*) &PrivateData
->Configuration
.NameValueVar1
;
1195 ZeroMem (TemStr
, sizeof (TemStr
));
1196 for (Index
= 0, StrPtr
--; StrPtr
>= Value
; StrPtr
--, Index
++) {
1197 TemStr
[0] = *StrPtr
;
1198 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1199 if ((Index
& 1) == 0) {
1200 DataBuffer
[Index
/2] = DigitUint8
;
1202 DataBuffer
[Index
/2] = (UINT8
) ((UINT8
) (DigitUint8
<< 4) + DataBuffer
[Index
/2]);
1208 // Convert value for NameValueVar2
1210 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[2])) != NULL
) {
1214 Value
+= StrLen (PrivateData
->NameValueName
[2]);
1219 StrPtr
= StrStr (Value
, L
"&");
1220 if (StrPtr
== NULL
) {
1221 StrPtr
= Value
+ StrLen (Value
);
1224 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1226 StrBuffer
= (CHAR16
*) PrivateData
->Configuration
.NameValueVar2
;
1227 ZeroMem (TemStr
, sizeof (TemStr
));
1228 while (Value
< StrPtr
) {
1229 StrnCpyS (TemStr
, sizeof (TemStr
) / sizeof (CHAR16
), Value
, 4);
1230 *(StrBuffer
++) = (CHAR16
) StrHexToUint64 (TemStr
);
1237 // Store Buffer Storage back to EFI variable
1239 Status
= gRT
->SetVariable(
1241 &gDriverSampleFormSetGuid
,
1242 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1243 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1244 &PrivateData
->Configuration
1251 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
1253 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
1254 Status
= HiiConfigRouting
->ConfigToBlock (
1257 (UINT8
*) &PrivateData
->Configuration
,
1261 if (EFI_ERROR (Status
)) {
1266 // Store Buffer Storage back to EFI variable
1268 Status
= gRT
->SetVariable(
1270 &gDriverSampleFormSetGuid
,
1271 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1272 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1273 &PrivateData
->Configuration
1281 This function processes the results of changes in configuration.
1283 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1284 @param Action Specifies the type of action taken by the browser.
1285 @param QuestionId A unique value which is sent to the original
1286 exporting driver so that it can identify the type
1288 @param Type The type of value for the question.
1289 @param Value A pointer to the data being sent to the original
1291 @param ActionRequest On return, points to the action requested by the
1294 @retval EFI_SUCCESS The callback successfully handled the action.
1295 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1296 variable and its data.
1297 @retval EFI_DEVICE_ERROR The variable could not be saved.
1298 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1305 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1306 IN EFI_BROWSER_ACTION Action
,
1307 IN EFI_QUESTION_ID QuestionId
,
1309 IN EFI_IFR_TYPE_VALUE
*Value
,
1310 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1313 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
1315 VOID
*StartOpCodeHandle
;
1316 VOID
*OptionsOpCodeHandle
;
1317 EFI_IFR_GUID_LABEL
*StartLabel
;
1318 VOID
*EndOpCodeHandle
;
1319 EFI_IFR_GUID_LABEL
*EndLabel
;
1321 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
1322 MY_EFI_VARSTORE_DATA
*EfiData
;
1324 EFI_STRING Progress
;
1331 if (((Value
== NULL
) && (Action
!= EFI_BROWSER_ACTION_FORM_OPEN
) && (Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
))||
1332 (ActionRequest
== NULL
)) {
1333 return EFI_INVALID_PARAMETER
;
1339 Status
= EFI_SUCCESS
;
1341 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
1344 case EFI_BROWSER_ACTION_FORM_OPEN
:
1346 if (QuestionId
== 0x1234) {
1348 // Sample CallBack for UEFI FORM_OPEN action:
1349 // Add Save action into Form 3 when Form 1 is opened.
1350 // This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.
1352 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
1355 // Initialize the container for dynamic opcodes
1357 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1358 ASSERT (StartOpCodeHandle
!= NULL
);
1361 // Create Hii Extend Label OpCode as the start opcode
1363 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1364 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1365 StartLabel
->Number
= LABEL_UPDATE2
;
1367 HiiCreateActionOpCode (
1368 StartOpCodeHandle
, // Container for dynamic created opcodes
1369 0x1238, // Question ID
1370 STRING_TOKEN(STR_SAVE_TEXT
), // Prompt text
1371 STRING_TOKEN(STR_SAVE_TEXT
), // Help text
1372 EFI_IFR_FLAG_CALLBACK
, // Question flag
1373 0 // Action String ID
1377 PrivateData
->HiiHandle
[0], // HII handle
1378 &gDriverSampleFormSetGuid
, // Formset GUID
1380 StartOpCodeHandle
, // Label for where to insert opcodes
1384 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1387 if (QuestionId
== 0x1247) {
1388 Status
= InternalStartMonitor ();
1389 ASSERT_EFI_ERROR (Status
);
1394 case EFI_BROWSER_ACTION_FORM_CLOSE
:
1396 if (QuestionId
== 0x5678) {
1398 // Sample CallBack for UEFI FORM_CLOSE action:
1399 // Show up a pop-up to specify Form 3 will be closed when exit Form 3.
1403 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1406 L
"You are going to leave third Form!",
1407 L
"Press ESC or ENTER to continue ...",
1411 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1414 if (QuestionId
== 0x1247) {
1415 Status
= InternalStopMonitor ();
1416 ASSERT_EFI_ERROR (Status
);
1421 case EFI_BROWSER_ACTION_RETRIEVE
:
1423 switch (QuestionId
) {
1425 if (Type
!= EFI_IFR_TYPE_REF
) {
1426 return EFI_INVALID_PARAMETER
;
1428 Value
->ref
.FormId
= 0x3;
1434 // We will reach here once the Question is refreshed
1438 // Initialize the container for dynamic opcodes
1440 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1441 ASSERT (StartOpCodeHandle
!= NULL
);
1444 // Create Hii Extend Label OpCode as the start opcode
1446 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1447 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1448 if (QuestionId
== 0x5678) {
1449 StartLabel
->Number
= LABEL_UPDATE2
;
1451 PrivateData
->Configuration
.DynamicRefresh
++;
1452 } else if (QuestionId
== 0x1247 ) {
1453 StartLabel
->Number
= LABEL_UPDATE3
;
1455 PrivateData
->Configuration
.RefreshGuidCount
++;
1458 HiiCreateActionOpCode (
1459 StartOpCodeHandle
, // Container for dynamic created opcodes
1460 0x1237, // Question ID
1461 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
1462 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
1463 EFI_IFR_FLAG_CALLBACK
, // Question flag
1464 0 // Action String ID
1468 PrivateData
->HiiHandle
[0], // HII handle
1469 &gDriverSampleFormSetGuid
, // Formset GUID
1471 StartOpCodeHandle
, // Label for where to insert opcodes
1475 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1478 // Refresh the Question value
1480 Status
= gRT
->SetVariable(
1482 &gDriverSampleFormSetGuid
,
1483 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1484 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1485 &PrivateData
->Configuration
1488 if (QuestionId
== 0x5678) {
1490 // Update uncommitted data of Browser
1492 EfiData
= AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA
));
1493 ASSERT (EfiData
!= NULL
);
1494 if (HiiGetBrowserData (&gDriverSampleFormSetGuid
, MyEfiVar
, sizeof (MY_EFI_VARSTORE_DATA
), (UINT8
*) EfiData
)) {
1495 EfiData
->Field8
= 111;
1497 &gDriverSampleFormSetGuid
,
1499 sizeof (MY_EFI_VARSTORE_DATA
),
1511 case EFI_BROWSER_ACTION_DEFAULT_STANDARD
:
1513 switch (QuestionId
) {
1515 Value
->u8
= DEFAULT_CLASS_STANDARD_VALUE
;
1519 for (Index
= 0; Index
< 3; Index
++) {
1520 SetArrayData (Value
, EFI_IFR_TYPE_NUM_SIZE_8
, Index
, BufferValue
--);
1525 Status
= EFI_UNSUPPORTED
;
1531 case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
:
1533 switch (QuestionId
) {
1535 Value
->u8
= DEFAULT_CLASS_MANUFACTURING_VALUE
;
1539 Status
= EFI_UNSUPPORTED
;
1545 case EFI_BROWSER_ACTION_CHANGING
:
1547 switch (QuestionId
) {
1550 if (Type
!= EFI_IFR_TYPE_REF
) {
1551 return EFI_INVALID_PARAMETER
;
1554 Value
->ref
.FormId
= 0x1234;
1559 // Initialize the container for dynamic opcodes
1561 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1562 ASSERT (StartOpCodeHandle
!= NULL
);
1564 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
1565 ASSERT (EndOpCodeHandle
!= NULL
);
1568 // Create Hii Extend Label OpCode as the start opcode
1570 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1571 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1572 StartLabel
->Number
= LABEL_UPDATE1
;
1575 // Create Hii Extend Label OpCode as the end opcode
1577 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1578 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1579 EndLabel
->Number
= LABEL_END
;
1581 HiiCreateActionOpCode (
1582 StartOpCodeHandle
, // Container for dynamic created opcodes
1583 0x1237, // Question ID
1584 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
1585 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
1586 EFI_IFR_FLAG_CALLBACK
, // Question flag
1587 0 // Action String ID
1591 // Create Option OpCode
1593 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
1594 ASSERT (OptionsOpCodeHandle
!= NULL
);
1596 HiiCreateOneOfOptionOpCode (
1597 OptionsOpCodeHandle
,
1598 STRING_TOKEN (STR_BOOT_OPTION1
),
1600 EFI_IFR_NUMERIC_SIZE_1
,
1604 HiiCreateOneOfOptionOpCode (
1605 OptionsOpCodeHandle
,
1606 STRING_TOKEN (STR_BOOT_OPTION2
),
1608 EFI_IFR_NUMERIC_SIZE_1
,
1613 // Prepare initial value for the dynamic created oneof Question
1615 PrivateData
->Configuration
.DynamicOneof
= 2;
1616 Status
= gRT
->SetVariable(
1618 &gDriverSampleFormSetGuid
,
1619 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1620 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1621 &PrivateData
->Configuration
1625 // Set initial vlaue of dynamic created oneof Question in Form Browser
1627 Configuration
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION
));
1628 ASSERT (Configuration
!= NULL
);
1629 if (HiiGetBrowserData (&gDriverSampleFormSetGuid
, VariableName
, sizeof (DRIVER_SAMPLE_CONFIGURATION
), (UINT8
*) Configuration
)) {
1630 Configuration
->DynamicOneof
= 2;
1633 // Update uncommitted data of Browser
1636 &gDriverSampleFormSetGuid
,
1638 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1639 (UINT8
*) Configuration
,
1643 FreePool (Configuration
);
1645 HiiCreateOneOfOpCode (
1646 StartOpCodeHandle
, // Container for dynamic created opcodes
1647 0x8001, // Question ID (or call it "key")
1648 CONFIGURATION_VARSTORE_ID
, // VarStore ID
1649 (UINT16
) DYNAMIC_ONE_OF_VAR_OFFSET
, // Offset in Buffer Storage
1650 STRING_TOKEN (STR_ONE_OF_PROMPT
), // Question prompt text
1651 STRING_TOKEN (STR_ONE_OF_HELP
), // Question help text
1652 EFI_IFR_FLAG_CALLBACK
, // Question flag
1653 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question Value
1654 OptionsOpCodeHandle
, // Option Opcode list
1655 NULL
// Default Opcode is NULl
1658 HiiCreateOrderedListOpCode (
1659 StartOpCodeHandle
, // Container for dynamic created opcodes
1660 0x8002, // Question ID
1661 CONFIGURATION_VARSTORE_ID
, // VarStore ID
1662 (UINT16
) DYNAMIC_ORDERED_LIST_VAR_OFFSET
, // Offset in Buffer Storage
1663 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question prompt text
1664 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question help text
1665 EFI_IFR_FLAG_RESET_REQUIRED
, // Question flag
1666 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
1667 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question value
1668 5, // Maximum container
1669 OptionsOpCodeHandle
, // Option Opcode list
1670 NULL
// Default Opcode is NULl
1673 HiiCreateTextOpCode (
1675 STRING_TOKEN(STR_TEXT_SAMPLE_HELP
),
1676 STRING_TOKEN(STR_TEXT_SAMPLE_HELP
),
1677 STRING_TOKEN(STR_TEXT_SAMPLE_STRING
)
1680 HiiCreateDateOpCode (
1685 STRING_TOKEN(STR_DATE_SAMPLE_HELP
),
1686 STRING_TOKEN(STR_DATE_SAMPLE_HELP
),
1688 QF_DATE_STORAGE_TIME
,
1692 HiiCreateTimeOpCode (
1697 STRING_TOKEN(STR_TIME_SAMPLE_HELP
),
1698 STRING_TOKEN(STR_TIME_SAMPLE_HELP
),
1700 QF_TIME_STORAGE_TIME
,
1704 HiiCreateGotoOpCode (
1705 StartOpCodeHandle
, // Container for dynamic created opcodes
1706 1, // Target Form ID
1707 STRING_TOKEN (STR_GOTO_FORM1
), // Prompt text
1708 STRING_TOKEN (STR_GOTO_HELP
), // Help text
1710 0x8003 // Question ID
1714 PrivateData
->HiiHandle
[0], // HII handle
1715 &gDriverSampleFormSetGuid
, // Formset GUID
1717 StartOpCodeHandle
, // Label for where to insert opcodes
1718 EndOpCodeHandle
// Replace data
1721 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1722 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1723 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1728 // Only used to update the state.
1730 if ((Type
== EFI_IFR_TYPE_STRING
) && (Value
->string
== 0) &&
1731 (PrivateData
->PasswordState
== BROWSER_STATE_SET_PASSWORD
)) {
1732 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
1733 return EFI_INVALID_PARAMETER
;
1737 // When try to set a new password, user will be chanlleged with old password.
1738 // The Callback is responsible for validating old password input by user,
1739 // If Callback return EFI_SUCCESS, it indicates validation pass.
1741 switch (PrivateData
->PasswordState
) {
1742 case BROWSER_STATE_VALIDATE_PASSWORD
:
1743 Status
= ValidatePassword (PrivateData
, Value
->string
);
1744 if (Status
== EFI_SUCCESS
) {
1745 PrivateData
->PasswordState
= BROWSER_STATE_SET_PASSWORD
;
1749 case BROWSER_STATE_SET_PASSWORD
:
1750 Status
= SetPassword (PrivateData
, Value
->string
);
1751 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
1766 case EFI_BROWSER_ACTION_CHANGED
:
1767 switch (QuestionId
) {
1770 // User press "Exit now", request Browser to exit
1772 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1777 // User press "Save now", request Browser to save the uncommitted data.
1779 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1785 // User press "Submit current form and Exit now", request Browser to submit current form and exit
1787 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1792 // User press "Discard current form now", request Browser to discard the uncommitted data.
1794 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD
;
1799 // User press "Submit current form now", request Browser to save the uncommitted data.
1801 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1807 // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.
1809 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1814 // 1. Check to see whether system support keyword.
1816 Status
= PrivateData
->HiiKeywordHandler
->GetData (PrivateData
->HiiKeywordHandler
,
1817 L
"NAMESPACE=x-UEFI-ns",
1818 L
"KEYWORD=iSCSIBootEnable",
1823 if (EFI_ERROR (Status
)) {
1826 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1829 L
"This system not support this keyword!",
1830 L
"Press ENTER to continue ...",
1834 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1836 Status
= EFI_SUCCESS
;
1841 // 2. If system support this keyword, just try to change value.
1845 // Change value from '0' to '1' or from '1' to '0'
1847 TmpStr
= StrStr (Results
, L
"&VALUE=");
1848 ASSERT (TmpStr
!= NULL
);
1849 TmpStr
+= StrLen (L
"&VALUE=");
1851 if (*TmpStr
== L
'0') {
1858 // 3. Call the keyword handler protocol to change the value.
1860 Status
= PrivateData
->HiiKeywordHandler
->SetData (PrivateData
->HiiKeywordHandler
,
1865 if (EFI_ERROR (Status
)) {
1868 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1871 L
"Set keyword to the system failed!",
1872 L
"Press ENTER to continue ...",
1876 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1878 Status
= EFI_SUCCESS
;
1888 case EFI_BROWSER_ACTION_SUBMITTED
:
1890 if (QuestionId
== 0x1250) {
1892 // Sample CallBack for EFI_BROWSER_ACTION_SUBMITTED action:
1893 // Show up a pop-up to show SUBMITTED callback has been triggered.
1897 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1900 L
"EfiVarstore value has been submitted!",
1901 L
"Press ESC or ENTER to continue ...",
1905 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1911 Status
= EFI_UNSUPPORTED
;
1919 Main entry for this driver.
1921 @param ImageHandle Image handle this driver.
1922 @param SystemTable Pointer to SystemTable.
1924 @retval EFI_SUCESS This function always complete successfully.
1930 IN EFI_HANDLE ImageHandle
,
1931 IN EFI_SYSTEM_TABLE
*SystemTable
1935 EFI_HII_HANDLE HiiHandle
[2];
1936 EFI_SCREEN_DESCRIPTOR Screen
;
1937 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1938 EFI_HII_STRING_PROTOCOL
*HiiString
;
1939 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1940 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1941 EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*HiiKeywordHandler
;
1944 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
1946 EFI_STRING ConfigRequestHdr
;
1947 EFI_STRING NameRequestHdr
;
1948 MY_EFI_VARSTORE_DATA
*VarStoreConfig
;
1949 EFI_INPUT_KEY HotKey
;
1950 EFI_FORM_BROWSER_EXTENSION_PROTOCOL
*FormBrowserEx
;
1953 // Initialize the local variables.
1955 ConfigRequestHdr
= NULL
;
1959 // Initialize screen dimensions for SendForm().
1960 // Remove 3 characters from top and bottom
1962 ZeroMem (&Screen
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1963 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Screen
.RightColumn
, &Screen
.BottomRow
);
1966 Screen
.BottomRow
= Screen
.BottomRow
- 3;
1969 // Initialize driver private data
1971 mPrivateData
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA
));
1972 if (mPrivateData
== NULL
) {
1973 return EFI_OUT_OF_RESOURCES
;
1976 mPrivateData
->Signature
= DRIVER_SAMPLE_PRIVATE_SIGNATURE
;
1978 mPrivateData
->ConfigAccess
.ExtractConfig
= ExtractConfig
;
1979 mPrivateData
->ConfigAccess
.RouteConfig
= RouteConfig
;
1980 mPrivateData
->ConfigAccess
.Callback
= DriverCallback
;
1981 mPrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
1984 // Locate Hii Database protocol
1986 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &HiiDatabase
);
1987 if (EFI_ERROR (Status
)) {
1990 mPrivateData
->HiiDatabase
= HiiDatabase
;
1993 // Locate HiiString protocol
1995 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
1996 if (EFI_ERROR (Status
)) {
1999 mPrivateData
->HiiString
= HiiString
;
2002 // Locate Formbrowser2 protocol
2004 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &FormBrowser2
);
2005 if (EFI_ERROR (Status
)) {
2008 mPrivateData
->FormBrowser2
= FormBrowser2
;
2011 // Locate ConfigRouting protocol
2013 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &HiiConfigRouting
);
2014 if (EFI_ERROR (Status
)) {
2017 mPrivateData
->HiiConfigRouting
= HiiConfigRouting
;
2020 // Locate keyword handler protocol
2022 Status
= gBS
->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid
, NULL
, (VOID
**) &HiiKeywordHandler
);
2023 if (EFI_ERROR (Status
)) {
2026 mPrivateData
->HiiKeywordHandler
= HiiKeywordHandler
;
2028 Status
= gBS
->InstallMultipleProtocolInterfaces (
2030 &gEfiDevicePathProtocolGuid
,
2031 &mHiiVendorDevicePath0
,
2032 &gEfiHiiConfigAccessProtocolGuid
,
2033 &mPrivateData
->ConfigAccess
,
2036 ASSERT_EFI_ERROR (Status
);
2038 mPrivateData
->DriverHandle
[0] = DriverHandle
[0];
2041 // Publish our HII data
2043 HiiHandle
[0] = HiiAddPackages (
2044 &gDriverSampleFormSetGuid
,
2046 DriverSampleStrings
,
2050 if (HiiHandle
[0] == NULL
) {
2051 return EFI_OUT_OF_RESOURCES
;
2054 mPrivateData
->HiiHandle
[0] = HiiHandle
[0];
2057 // Publish another Fromset
2059 Status
= gBS
->InstallMultipleProtocolInterfaces (
2061 &gEfiDevicePathProtocolGuid
,
2062 &mHiiVendorDevicePath1
,
2063 &gEfiHiiConfigAccessProtocolGuid
,
2064 &mPrivateData
->ConfigAccess
,
2067 ASSERT_EFI_ERROR (Status
);
2069 mPrivateData
->DriverHandle
[1] = DriverHandle
[1];
2071 HiiHandle
[1] = HiiAddPackages (
2072 &gDriverSampleInventoryGuid
,
2074 DriverSampleStrings
,
2078 if (HiiHandle
[1] == NULL
) {
2079 DriverSampleUnload (ImageHandle
);
2080 return EFI_OUT_OF_RESOURCES
;
2083 mPrivateData
->HiiHandle
[1] = HiiHandle
[1];
2086 // Update the device path string.
2088 NewString
= ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL
*)&mHiiVendorDevicePath0
, FALSE
, FALSE
);
2089 if (HiiSetString (HiiHandle
[0], STRING_TOKEN (STR_DEVICE_PATH
), NewString
, NULL
) == 0) {
2090 DriverSampleUnload (ImageHandle
);
2091 return EFI_OUT_OF_RESOURCES
;
2093 if (NewString
!= NULL
) {
2094 FreePool (NewString
);
2098 // Very simple example of how one would update a string that is already
2099 // in the HII database
2101 NewString
= L
"700 Mhz";
2103 if (HiiSetString (HiiHandle
[0], STRING_TOKEN (STR_CPU_STRING2
), NewString
, NULL
) == 0) {
2104 DriverSampleUnload (ImageHandle
);
2105 return EFI_OUT_OF_RESOURCES
;
2108 HiiSetString (HiiHandle
[0], 0, NewString
, NULL
);
2111 // Initialize Name/Value name String ID
2113 mPrivateData
->NameStringId
[0] = STR_NAME_VALUE_VAR_NAME0
;
2114 mPrivateData
->NameStringId
[1] = STR_NAME_VALUE_VAR_NAME1
;
2115 mPrivateData
->NameStringId
[2] = STR_NAME_VALUE_VAR_NAME2
;
2118 // Initialize configuration data
2120 Configuration
= &mPrivateData
->Configuration
;
2121 ZeroMem (Configuration
, sizeof (DRIVER_SAMPLE_CONFIGURATION
));
2124 // Try to read NV config EFI variable first
2126 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, VariableName
, DriverHandle
[0]);
2127 ASSERT (ConfigRequestHdr
!= NULL
);
2129 NameRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, NULL
, DriverHandle
[0]);
2130 ASSERT (NameRequestHdr
!= NULL
);
2132 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
2133 Status
= gRT
->GetVariable (VariableName
, &gDriverSampleFormSetGuid
, NULL
, &BufferSize
, Configuration
);
2134 if (EFI_ERROR (Status
)) {
2136 // Store zero data Buffer Storage to EFI variable
2138 Status
= gRT
->SetVariable(
2140 &gDriverSampleFormSetGuid
,
2141 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
2142 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
2145 if (EFI_ERROR (Status
)) {
2146 DriverSampleUnload (ImageHandle
);
2150 // EFI variable for NV config doesn't exit, we should build this variable
2151 // based on default values stored in IFR
2153 ActionFlag
= HiiSetToDefaults (NameRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2155 DriverSampleUnload (ImageHandle
);
2156 return EFI_INVALID_PARAMETER
;
2159 ActionFlag
= HiiSetToDefaults (ConfigRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2161 DriverSampleUnload (ImageHandle
);
2162 return EFI_INVALID_PARAMETER
;
2166 // EFI variable does exist and Validate Current Setting
2168 ActionFlag
= HiiValidateSettings (NameRequestHdr
);
2170 DriverSampleUnload (ImageHandle
);
2171 return EFI_INVALID_PARAMETER
;
2174 ActionFlag
= HiiValidateSettings (ConfigRequestHdr
);
2176 DriverSampleUnload (ImageHandle
);
2177 return EFI_INVALID_PARAMETER
;
2180 FreePool (ConfigRequestHdr
);
2183 // Initialize efi varstore configuration data
2185 VarStoreConfig
= &mPrivateData
->VarStoreConfig
;
2186 ZeroMem (VarStoreConfig
, sizeof (MY_EFI_VARSTORE_DATA
));
2188 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, MyEfiVar
, DriverHandle
[0]);
2189 ASSERT (ConfigRequestHdr
!= NULL
);
2191 BufferSize
= sizeof (MY_EFI_VARSTORE_DATA
);
2192 Status
= gRT
->GetVariable (MyEfiVar
, &gDriverSampleFormSetGuid
, NULL
, &BufferSize
, VarStoreConfig
);
2193 if (EFI_ERROR (Status
)) {
2195 // Store zero data to EFI variable Storage.
2197 Status
= gRT
->SetVariable(
2199 &gDriverSampleFormSetGuid
,
2200 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
2201 sizeof (MY_EFI_VARSTORE_DATA
),
2204 if (EFI_ERROR (Status
)) {
2205 DriverSampleUnload (ImageHandle
);
2209 // EFI variable for NV config doesn't exit, we should build this variable
2210 // based on default values stored in IFR
2212 ActionFlag
= HiiSetToDefaults (ConfigRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
2214 DriverSampleUnload (ImageHandle
);
2215 return EFI_INVALID_PARAMETER
;
2219 // EFI variable does exist and Validate Current Setting
2221 ActionFlag
= HiiValidateSettings (ConfigRequestHdr
);
2223 DriverSampleUnload (ImageHandle
);
2224 return EFI_INVALID_PARAMETER
;
2227 FreePool (ConfigRequestHdr
);
2229 Status
= gBS
->CreateEventEx (
2232 DriverSampleInternalEmptyFunction
,
2234 &gEfiIfrRefreshIdOpGuid
,
2237 ASSERT_EFI_ERROR (Status
);
2240 // Example of how to use BrowserEx protocol to register HotKey.
2242 Status
= gBS
->LocateProtocol (&gEfiFormBrowserExProtocolGuid
, NULL
, (VOID
**) &FormBrowserEx
);
2243 if (!EFI_ERROR (Status
)) {
2245 // First unregister the default hot key F9 and F10.
2247 HotKey
.UnicodeChar
= CHAR_NULL
;
2248 HotKey
.ScanCode
= SCAN_F9
;
2249 FormBrowserEx
->RegisterHotKey (&HotKey
, 0, 0, NULL
);
2250 HotKey
.ScanCode
= SCAN_F10
;
2251 FormBrowserEx
->RegisterHotKey (&HotKey
, 0, 0, NULL
);
2254 // Register the default HotKey F9 and F10 again.
2256 HotKey
.ScanCode
= SCAN_F10
;
2257 NewString
= HiiGetString (mPrivateData
->HiiHandle
[0], STRING_TOKEN (FUNCTION_TEN_STRING
), NULL
);
2258 ASSERT (NewString
!= NULL
);
2259 FormBrowserEx
->RegisterHotKey (&HotKey
, BROWSER_ACTION_SUBMIT
, 0, NewString
);
2260 HotKey
.ScanCode
= SCAN_F9
;
2261 NewString
= HiiGetString (mPrivateData
->HiiHandle
[0], STRING_TOKEN (FUNCTION_NINE_STRING
), NULL
);
2262 ASSERT (NewString
!= NULL
);
2263 FormBrowserEx
->RegisterHotKey (&HotKey
, BROWSER_ACTION_DEFAULT
, EFI_HII_DEFAULT_CLASS_STANDARD
, NewString
);
2267 // In default, this driver is built into Flash device image,
2268 // the following code doesn't run.
2272 // Example of how to display only the item we sent to HII
2273 // When this driver is not built into Flash device image,
2274 // it need to call SendForm to show front page by itself.
2276 if (DISPLAY_ONLY_MY_ITEM
<= 1) {
2278 // Have the browser pull out our copy of the data, and only display our data
2280 Status
= FormBrowser2
->SendForm (
2282 &(HiiHandle
[DISPLAY_ONLY_MY_ITEM
]),
2290 HiiRemovePackages (HiiHandle
[0]);
2292 HiiRemovePackages (HiiHandle
[1]);
2299 Unloads the application and its installed protocol.
2301 @param[in] ImageHandle Handle that identifies the image to be unloaded.
2303 @retval EFI_SUCCESS The image has been unloaded.
2307 DriverSampleUnload (
2308 IN EFI_HANDLE ImageHandle
2313 ASSERT (mPrivateData
!= NULL
);
2315 if (DriverHandle
[0] != NULL
) {
2316 gBS
->UninstallMultipleProtocolInterfaces (
2318 &gEfiDevicePathProtocolGuid
,
2319 &mHiiVendorDevicePath0
,
2320 &gEfiHiiConfigAccessProtocolGuid
,
2321 &mPrivateData
->ConfigAccess
,
2324 DriverHandle
[0] = NULL
;
2327 if (DriverHandle
[1] != NULL
) {
2328 gBS
->UninstallMultipleProtocolInterfaces (
2330 &gEfiDevicePathProtocolGuid
,
2331 &mHiiVendorDevicePath1
,
2332 &gEfiHiiConfigAccessProtocolGuid
,
2333 &mPrivateData
->ConfigAccess
,
2336 DriverHandle
[1] = NULL
;
2339 if (mPrivateData
->HiiHandle
[0] != NULL
) {
2340 HiiRemovePackages (mPrivateData
->HiiHandle
[0]);
2343 if (mPrivateData
->HiiHandle
[1] != NULL
) {
2344 HiiRemovePackages (mPrivateData
->HiiHandle
[1]);
2347 for (Index
= 0; Index
< NAME_VALUE_NAME_NUMBER
; Index
++) {
2348 if (mPrivateData
->NameValueName
[Index
] != NULL
) {
2349 FreePool (mPrivateData
->NameValueName
[Index
]);
2352 FreePool (mPrivateData
);
2353 mPrivateData
= NULL
;
2355 gBS
->CloseEvent (mEvent
);