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 - 2017, 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 Notification function for keystrokes.
116 @param[in] KeyData The key that was pressed.
118 @retval EFI_SUCCESS The operation was successful.
122 NotificationFunction(
123 IN EFI_KEY_DATA
*KeyData
126 gBS
->SignalEvent (mEvent
);
132 Function to start monitoring for CTRL-C using SimpleTextInputEx.
134 @retval EFI_SUCCESS The feature is enabled.
135 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
139 InternalStartMonitor(
143 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*SimpleEx
;
144 EFI_KEY_DATA KeyData
;
149 EFI_HANDLE NotifyHandle
;
151 Status
= gBS
->LocateHandleBuffer (
153 &gEfiSimpleTextInputExProtocolGuid
,
158 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
159 Status
= gBS
->HandleProtocol (Handles
[HandleIndex
], &gEfiSimpleTextInputExProtocolGuid
, (VOID
**) &SimpleEx
);
160 ASSERT_EFI_ERROR (Status
);
162 KeyData
.KeyState
.KeyToggleState
= 0;
163 KeyData
.Key
.ScanCode
= 0;
164 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
165 KeyData
.Key
.UnicodeChar
= L
'c';
167 Status
= SimpleEx
->RegisterKeyNotify(
170 NotificationFunction
,
172 if (EFI_ERROR (Status
)) {
176 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
177 Status
= SimpleEx
->RegisterKeyNotify(
180 NotificationFunction
,
182 if (EFI_ERROR (Status
)) {
191 Function to stop monitoring for CTRL-C using SimpleTextInputEx.
193 @retval EFI_SUCCESS The feature is enabled.
194 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
202 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*SimpleEx
;
205 EFI_KEY_DATA KeyData
;
208 EFI_HANDLE NotifyHandle
;
210 Status
= gBS
->LocateHandleBuffer (
212 &gEfiSimpleTextInputExProtocolGuid
,
217 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
218 Status
= gBS
->HandleProtocol (Handles
[HandleIndex
], &gEfiSimpleTextInputExProtocolGuid
, (VOID
**) &SimpleEx
);
219 ASSERT_EFI_ERROR (Status
);
221 KeyData
.KeyState
.KeyToggleState
= 0;
222 KeyData
.Key
.ScanCode
= 0;
223 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
224 KeyData
.Key
.UnicodeChar
= L
'c';
226 Status
= SimpleEx
->RegisterKeyNotify(
229 NotificationFunction
,
231 if (!EFI_ERROR (Status
)) {
232 Status
= SimpleEx
->UnregisterKeyNotify (SimpleEx
, NotifyHandle
);
235 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
236 Status
= SimpleEx
->RegisterKeyNotify(
239 NotificationFunction
,
241 if (!EFI_ERROR (Status
)) {
242 Status
= SimpleEx
->UnregisterKeyNotify (SimpleEx
, NotifyHandle
);
249 Update names of Name/Value storage to current language.
251 @param PrivateData Points to the driver private data.
253 @retval EFI_SUCCESS All names are successfully updated.
254 @retval EFI_NOT_FOUND Failed to get Name from HII database.
259 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
265 // Get Name/Value name string of current language
267 for (Index
= 0; Index
< NAME_VALUE_NAME_NUMBER
; Index
++) {
268 PrivateData
->NameValueName
[Index
] = HiiGetString (
269 PrivateData
->HiiHandle
[0],
270 PrivateData
->NameStringId
[Index
],
273 if (PrivateData
->NameValueName
[Index
] == NULL
) {
274 return EFI_NOT_FOUND
;
283 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
285 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
287 This is a internal function.
289 @param StringPtr String in <BlockConfig> format and points to the
290 first character of <Number>.
291 @param Number The output value. Caller takes the responsibility
293 @param Len Length of the <Number>, in characters.
295 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
297 @retval EFI_SUCCESS Value of <Number> is outputted in Number
303 IN EFI_STRING StringPtr
,
317 if (StringPtr
== NULL
|| *StringPtr
== L
'\0' || Number
== NULL
|| Len
== NULL
) {
318 return EFI_INVALID_PARAMETER
;
324 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
327 *Len
= StringPtr
- TmpPtr
;
330 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
332 Status
= EFI_OUT_OF_RESOURCES
;
335 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
336 *(Str
+ *Len
) = L
'\0';
338 Length
= (Length
+ 1) / 2;
339 Buf
= (UINT8
*) AllocateZeroPool (Length
);
341 Status
= EFI_OUT_OF_RESOURCES
;
346 ZeroMem (TemStr
, sizeof (TemStr
));
347 for (Index
= 0; Index
< Length
; Index
++) {
348 TemStr
[0] = Str
[Length
- Index
- 1];
349 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
350 if ((Index
& 1) == 0) {
351 Buf
[Index
/2] = DigitUint8
;
353 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
358 Status
= EFI_SUCCESS
;
369 Create altcfg string.
371 @param Result The request result string.
372 @param ConfigHdr The request head info. <ConfigHdr> format.
373 @param Offset The offset of the parameter int he structure.
374 @param Width The width of the parameter.
377 @retval The string with altcfg info append at the end.
381 IN EFI_STRING Result
,
382 IN EFI_STRING ConfigHdr
,
387 EFI_STRING StringPtr
;
391 NewLen
= StrLen (Result
);
393 // String Len = ConfigResp + AltConfig + AltConfig + 1("\0")
395 NewLen
= (NewLen
+ ((1 + StrLen (ConfigHdr
) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16
);
396 StringPtr
= AllocateZeroPool (NewLen
);
397 if (StringPtr
== NULL
) {
402 if (Result
!= NULL
) {
403 StrCpyS (StringPtr
, NewLen
/ sizeof (CHAR16
), Result
);
404 StringPtr
+= StrLen (Result
);
410 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
413 EFI_HII_DEFAULT_CLASS_STANDARD
415 StringPtr
+= StrLen (StringPtr
);
419 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
420 L
"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
423 DEFAULT_CLASS_STANDARD_VALUE
425 StringPtr
+= StrLen (StringPtr
);
429 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
432 EFI_HII_DEFAULT_CLASS_MANUFACTURING
434 StringPtr
+= StrLen (StringPtr
);
438 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
439 L
"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
442 DEFAULT_CLASS_MANUFACTURING_VALUE
444 StringPtr
+= StrLen (StringPtr
);
450 Check whether need to add the altcfg string. if need to add, add the altcfg
453 @param RequestResult The request result string.
454 @param ConfigRequestHdr The request head info. <ConfigHdr> format.
459 IN OUT EFI_STRING
*RequestResult
,
460 IN EFI_STRING ConfigRequestHdr
463 EFI_STRING StringPtr
;
474 StringPtr
= *RequestResult
;
475 StringPtr
= StrStr (StringPtr
, L
"OFFSET");
476 BlockSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
477 ValueOffset
= OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION
, GetDefaultValueFromAccess
);
478 ValueWidth
= sizeof (((DRIVER_SAMPLE_CONFIGURATION
*)0)->GetDefaultValueFromAccess
);
480 if (StringPtr
== NULL
) {
484 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
485 StringPtr
+= StrLen (L
"OFFSET=");
489 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
490 if (EFI_ERROR (Status
)) {
497 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
499 FreePool (TmpBuffer
);
502 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
505 StringPtr
+= StrLen (L
"&WIDTH=");
510 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
511 if (EFI_ERROR (Status
)) {
518 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
520 FreePool (TmpBuffer
);
523 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
526 StringPtr
+= StrLen (L
"&VALUE=");
531 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
532 if (EFI_ERROR (Status
)) {
538 // Skip the character "&" before "OFFSET".
543 // Calculate Value and convert it to hex string.
545 if (Offset
+ Width
> BlockSize
) {
549 if (Offset
<= ValueOffset
&& Offset
+ Width
>= ValueOffset
+ ValueWidth
) {
550 *RequestResult
= CreateAltCfgString(*RequestResult
, ConfigRequestHdr
, ValueOffset
, ValueWidth
);
557 This function allows a caller to extract the current configuration for one
558 or more named elements from the target driver.
560 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
561 @param Request A null-terminated Unicode string in
562 <ConfigRequest> format.
563 @param Progress On return, points to a character in the Request
564 string. Points to the string's null terminator if
565 request was successful. Points to the most recent
566 '&' before the first failing name/value pair (or
567 the beginning of the string if the failure is in
568 the first name/value pair) if the request was not
570 @param Results A null-terminated Unicode string in
571 <ConfigAltResp> format which has all values filled
572 in for the names in the Request string. String to
573 be allocated by the called function.
575 @retval EFI_SUCCESS The Results is filled with the requested values.
576 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
577 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
578 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
585 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
586 IN CONST EFI_STRING Request
,
587 OUT EFI_STRING
*Progress
,
588 OUT EFI_STRING
*Results
593 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
594 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
595 EFI_STRING ConfigRequest
;
596 EFI_STRING ConfigRequestHdr
;
602 BOOLEAN AllocatedRequest
;
604 if (Progress
== NULL
|| Results
== NULL
) {
605 return EFI_INVALID_PARAMETER
;
608 // Initialize the local variables.
610 ConfigRequestHdr
= NULL
;
611 ConfigRequest
= NULL
;
614 AllocatedRequest
= FALSE
;
616 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
617 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
620 // Get Buffer Storage data from EFI variable.
621 // Try to get the current setting from variable.
623 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
624 Status
= gRT
->GetVariable (
626 &gDriverSampleFormSetGuid
,
629 &PrivateData
->Configuration
631 if (EFI_ERROR (Status
)) {
632 return EFI_NOT_FOUND
;
635 if (Request
== NULL
) {
637 // Request is set to NULL, construct full request string.
641 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
642 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
644 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, VariableName
, PrivateData
->DriverHandle
[0]);
645 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
646 ConfigRequest
= AllocateZeroPool (Size
);
647 ASSERT (ConfigRequest
!= NULL
);
648 AllocatedRequest
= TRUE
;
649 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
650 FreePool (ConfigRequestHdr
);
651 ConfigRequestHdr
= NULL
;
654 // Check routing data in <ConfigHdr>.
655 // Note: if only one Storage is used, then this checking could be skipped.
657 if (!HiiIsConfigHdrMatch (Request
, &gDriverSampleFormSetGuid
, NULL
)) {
658 return EFI_NOT_FOUND
;
661 // Check whether request for EFI Varstore. EFI varstore get data
662 // through hii database, not support in this path.
664 if (HiiIsConfigHdrMatch(Request
, &gDriverSampleFormSetGuid
, MyEfiVar
)) {
665 return EFI_UNSUPPORTED
;
668 // Set Request to the unified request string.
670 ConfigRequest
= Request
;
672 // Check whether Request includes Request Element.
674 if (StrStr (Request
, L
"OFFSET") == NULL
) {
676 // Check Request Element does exist in Reques String
678 StrPointer
= StrStr (Request
, L
"PATH");
679 if (StrPointer
== NULL
) {
680 return EFI_INVALID_PARAMETER
;
682 if (StrStr (StrPointer
, L
"&") == NULL
) {
683 Size
= (StrLen (Request
) + 32 + 1) * sizeof (CHAR16
);
684 ConfigRequest
= AllocateZeroPool (Size
);
685 ASSERT (ConfigRequest
!= NULL
);
686 AllocatedRequest
= TRUE
;
687 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", Request
, (UINT64
)BufferSize
);
693 // Check if requesting Name/Value storage
695 if (StrStr (ConfigRequest
, L
"OFFSET") == NULL
) {
697 // Update Name/Value storage Names
699 Status
= LoadNameValueNames (PrivateData
);
700 if (EFI_ERROR (Status
)) {
705 // Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
706 // <Request> ::=<ConfigHdr>&Name0&Name1&Name2
707 // <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
709 BufferSize
= (StrLen (ConfigRequest
) +
710 1 + sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2 +
711 1 + sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2 +
712 1 + sizeof (PrivateData
->Configuration
.NameValueVar2
) * 2 + 1) * sizeof (CHAR16
);
713 *Results
= AllocateZeroPool (BufferSize
);
714 ASSERT (*Results
!= NULL
);
715 StrCpyS (*Results
, BufferSize
/ sizeof (CHAR16
), ConfigRequest
);
719 // Append value of NameValueVar0, type is UINT8
721 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[0])) != NULL
) {
722 Value
+= StrLen (PrivateData
->NameValueName
[0]);
723 ValueStrLen
= ((sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2) + 1);
724 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
726 BackupChar
= Value
[ValueStrLen
];
728 Value
+= UnicodeValueToString (
730 PREFIX_ZERO
| RADIX_HEX
,
731 PrivateData
->Configuration
.NameValueVar0
,
732 sizeof (PrivateData
->Configuration
.NameValueVar0
) * 2
738 // Append value of NameValueVar1, type is UINT16
740 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[1])) != NULL
) {
741 Value
+= StrLen (PrivateData
->NameValueName
[1]);
742 ValueStrLen
= ((sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2) + 1);
743 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
745 BackupChar
= Value
[ValueStrLen
];
747 Value
+= UnicodeValueToString (
749 PREFIX_ZERO
| RADIX_HEX
,
750 PrivateData
->Configuration
.NameValueVar1
,
751 sizeof (PrivateData
->Configuration
.NameValueVar1
) * 2
757 // Append value of NameValueVar2, type is CHAR16 *
759 if ((Value
= StrStr (*Results
, PrivateData
->NameValueName
[2])) != NULL
) {
760 Value
+= StrLen (PrivateData
->NameValueName
[2]);
761 ValueStrLen
= StrLen (PrivateData
->Configuration
.NameValueVar2
) * 4 + 1;
762 CopyMem (Value
+ ValueStrLen
, Value
, StrSize (Value
));
766 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
768 StrPointer
= (CHAR16
*) PrivateData
->Configuration
.NameValueVar2
;
769 for (; *StrPointer
!= L
'\0'; StrPointer
++) {
770 Value
+= UnicodeValueToString (Value
, PREFIX_ZERO
| RADIX_HEX
, *StrPointer
, 4);
774 Status
= EFI_SUCCESS
;
777 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
779 Status
= HiiConfigRouting
->BlockToConfig (
782 (UINT8
*) &PrivateData
->Configuration
,
787 if (!EFI_ERROR (Status
)) {
788 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, VariableName
, PrivateData
->DriverHandle
[0]);
789 AppendAltCfgString(Results
, ConfigRequestHdr
);
794 // Free the allocated config request string.
796 if (AllocatedRequest
) {
797 FreePool (ConfigRequest
);
800 if (ConfigRequestHdr
!= NULL
) {
801 FreePool (ConfigRequestHdr
);
804 // Set Progress string to the original request string.
806 if (Request
== NULL
) {
808 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
809 *Progress
= Request
+ StrLen (Request
);
817 This function processes the results of changes in configuration.
819 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
820 @param Configuration A null-terminated Unicode string in <ConfigResp>
822 @param Progress A pointer to a string filled in with the offset of
823 the most recent '&' before the first failing
824 name/value pair (or the beginning of the string if
825 the failure is in the first name/value pair) or
826 the terminating NULL if all was successful.
828 @retval EFI_SUCCESS The Results is processed successfully.
829 @retval EFI_INVALID_PARAMETER Configuration is NULL.
830 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
837 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
838 IN CONST EFI_STRING Configuration
,
839 OUT EFI_STRING
*Progress
844 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
845 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
854 if (Configuration
== NULL
|| Progress
== NULL
) {
855 return EFI_INVALID_PARAMETER
;
858 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
859 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
860 *Progress
= Configuration
;
863 // Check routing data in <ConfigHdr>.
864 // Note: if only one Storage is used, then this checking could be skipped.
866 if (!HiiIsConfigHdrMatch (Configuration
, &gDriverSampleFormSetGuid
, NULL
)) {
867 return EFI_NOT_FOUND
;
871 // Check whether request for EFI Varstore. EFI varstore get data
872 // through hii database, not support in this path.
874 if (HiiIsConfigHdrMatch(Configuration
, &gDriverSampleFormSetGuid
, MyEfiVar
)) {
875 return EFI_UNSUPPORTED
;
879 // Get Buffer Storage data from EFI variable
881 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
882 Status
= gRT
->GetVariable (
884 &gDriverSampleFormSetGuid
,
887 &PrivateData
->Configuration
889 if (EFI_ERROR (Status
)) {
894 // Check if configuring Name/Value storage
896 if (StrStr (Configuration
, L
"OFFSET") == NULL
) {
898 // Update Name/Value storage Names
900 Status
= LoadNameValueNames (PrivateData
);
901 if (EFI_ERROR (Status
)) {
906 // Convert value for NameValueVar0
908 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[0])) != NULL
) {
912 Value
+= StrLen (PrivateData
->NameValueName
[0]);
917 StrPtr
= StrStr (Value
, L
"&");
918 if (StrPtr
== NULL
) {
919 StrPtr
= Value
+ StrLen (Value
);
922 // Convert Value to Buffer data
924 DataBuffer
= (UINT8
*) &PrivateData
->Configuration
.NameValueVar0
;
925 ZeroMem (TemStr
, sizeof (TemStr
));
926 for (Index
= 0, StrPtr
--; StrPtr
>= Value
; StrPtr
--, Index
++) {
928 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
929 if ((Index
& 1) == 0) {
930 DataBuffer
[Index
/2] = DigitUint8
;
932 DataBuffer
[Index
/2] = (UINT8
) ((UINT8
) (DigitUint8
<< 4) + DataBuffer
[Index
/2]);
938 // Convert value for NameValueVar1
940 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[1])) != NULL
) {
944 Value
+= StrLen (PrivateData
->NameValueName
[1]);
949 StrPtr
= StrStr (Value
, L
"&");
950 if (StrPtr
== NULL
) {
951 StrPtr
= Value
+ StrLen (Value
);
954 // Convert Value to Buffer data
956 DataBuffer
= (UINT8
*) &PrivateData
->Configuration
.NameValueVar1
;
957 ZeroMem (TemStr
, sizeof (TemStr
));
958 for (Index
= 0, StrPtr
--; StrPtr
>= Value
; StrPtr
--, Index
++) {
960 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
961 if ((Index
& 1) == 0) {
962 DataBuffer
[Index
/2] = DigitUint8
;
964 DataBuffer
[Index
/2] = (UINT8
) ((UINT8
) (DigitUint8
<< 4) + DataBuffer
[Index
/2]);
970 // Convert value for NameValueVar2
972 if ((Value
= StrStr (Configuration
, PrivateData
->NameValueName
[2])) != NULL
) {
976 Value
+= StrLen (PrivateData
->NameValueName
[2]);
981 StrPtr
= StrStr (Value
, L
"&");
982 if (StrPtr
== NULL
) {
983 StrPtr
= Value
+ StrLen (Value
);
986 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
988 StrBuffer
= (CHAR16
*) PrivateData
->Configuration
.NameValueVar2
;
989 ZeroMem (TemStr
, sizeof (TemStr
));
990 while (Value
< StrPtr
) {
991 StrnCpyS (TemStr
, sizeof (TemStr
) / sizeof (CHAR16
), Value
, 4);
992 *(StrBuffer
++) = (CHAR16
) StrHexToUint64 (TemStr
);
999 // Store Buffer Storage back to EFI variable
1001 Status
= gRT
->SetVariable(
1003 &gDriverSampleFormSetGuid
,
1004 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1005 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1006 &PrivateData
->Configuration
1013 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
1015 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
1016 Status
= HiiConfigRouting
->ConfigToBlock (
1019 (UINT8
*) &PrivateData
->Configuration
,
1023 if (EFI_ERROR (Status
)) {
1028 // Store Buffer Storage back to EFI variable
1030 Status
= gRT
->SetVariable(
1032 &gDriverSampleFormSetGuid
,
1033 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1034 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1035 &PrivateData
->Configuration
1043 This function processes the results of changes in configuration.
1045 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1046 @param Action Specifies the type of action taken by the browser.
1047 @param QuestionId A unique value which is sent to the original
1048 exporting driver so that it can identify the type
1050 @param Type The type of value for the question.
1051 @param Value A pointer to the data being sent to the original
1053 @param ActionRequest On return, points to the action requested by the
1056 @retval EFI_SUCCESS The callback successfully handled the action.
1057 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1058 variable and its data.
1059 @retval EFI_DEVICE_ERROR The variable could not be saved.
1060 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1067 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1068 IN EFI_BROWSER_ACTION Action
,
1069 IN EFI_QUESTION_ID QuestionId
,
1071 IN EFI_IFR_TYPE_VALUE
*Value
,
1072 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1075 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
1077 VOID
*StartOpCodeHandle
;
1078 VOID
*OptionsOpCodeHandle
;
1079 EFI_IFR_GUID_LABEL
*StartLabel
;
1080 VOID
*EndOpCodeHandle
;
1081 EFI_IFR_GUID_LABEL
*EndLabel
;
1083 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
1084 MY_EFI_VARSTORE_DATA
*EfiData
;
1086 EFI_STRING Progress
;
1093 if (((Value
== NULL
) && (Action
!= EFI_BROWSER_ACTION_FORM_OPEN
) && (Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
))||
1094 (ActionRequest
== NULL
)) {
1095 return EFI_INVALID_PARAMETER
;
1101 Status
= EFI_SUCCESS
;
1103 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
1106 case EFI_BROWSER_ACTION_FORM_OPEN
:
1108 if (QuestionId
== 0x1234) {
1110 // Sample CallBack for UEFI FORM_OPEN action:
1111 // Add Save action into Form 3 when Form 1 is opened.
1112 // This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.
1114 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
1117 // Initialize the container for dynamic opcodes
1119 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1120 ASSERT (StartOpCodeHandle
!= NULL
);
1123 // Create Hii Extend Label OpCode as the start opcode
1125 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1126 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1127 StartLabel
->Number
= LABEL_UPDATE2
;
1129 HiiCreateActionOpCode (
1130 StartOpCodeHandle
, // Container for dynamic created opcodes
1131 0x1238, // Question ID
1132 STRING_TOKEN(STR_SAVE_TEXT
), // Prompt text
1133 STRING_TOKEN(STR_SAVE_TEXT
), // Help text
1134 EFI_IFR_FLAG_CALLBACK
, // Question flag
1135 0 // Action String ID
1139 PrivateData
->HiiHandle
[0], // HII handle
1140 &gDriverSampleFormSetGuid
, // Formset GUID
1142 StartOpCodeHandle
, // Label for where to insert opcodes
1146 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1149 if (QuestionId
== 0x1247) {
1150 Status
= InternalStartMonitor ();
1151 ASSERT_EFI_ERROR (Status
);
1156 case EFI_BROWSER_ACTION_FORM_CLOSE
:
1158 if (QuestionId
== 0x5678) {
1160 // Sample CallBack for UEFI FORM_CLOSE action:
1161 // Show up a pop-up to specify Form 3 will be closed when exit Form 3.
1165 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1168 L
"You are going to leave third Form!",
1169 L
"Press ESC or ENTER to continue ...",
1173 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1176 if (QuestionId
== 0x1247) {
1177 Status
= InternalStopMonitor ();
1178 ASSERT_EFI_ERROR (Status
);
1183 case EFI_BROWSER_ACTION_RETRIEVE
:
1185 switch (QuestionId
) {
1187 if (Type
!= EFI_IFR_TYPE_REF
) {
1188 return EFI_INVALID_PARAMETER
;
1190 Value
->ref
.FormId
= 0x3;
1196 // We will reach here once the Question is refreshed
1200 // Initialize the container for dynamic opcodes
1202 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1203 ASSERT (StartOpCodeHandle
!= NULL
);
1206 // Create Hii Extend Label OpCode as the start opcode
1208 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1209 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1210 if (QuestionId
== 0x5678) {
1211 StartLabel
->Number
= LABEL_UPDATE2
;
1213 PrivateData
->Configuration
.DynamicRefresh
++;
1214 } else if (QuestionId
== 0x1247 ) {
1215 StartLabel
->Number
= LABEL_UPDATE3
;
1217 PrivateData
->Configuration
.RefreshGuidCount
++;
1220 HiiCreateActionOpCode (
1221 StartOpCodeHandle
, // Container for dynamic created opcodes
1222 0x1237, // Question ID
1223 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
1224 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
1225 EFI_IFR_FLAG_CALLBACK
, // Question flag
1226 0 // Action String ID
1230 PrivateData
->HiiHandle
[0], // HII handle
1231 &gDriverSampleFormSetGuid
, // Formset GUID
1233 StartOpCodeHandle
, // Label for where to insert opcodes
1237 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1240 // Refresh the Question value
1242 Status
= gRT
->SetVariable(
1244 &gDriverSampleFormSetGuid
,
1245 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1246 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1247 &PrivateData
->Configuration
1250 if (QuestionId
== 0x5678) {
1252 // Update uncommitted data of Browser
1254 EfiData
= AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA
));
1255 ASSERT (EfiData
!= NULL
);
1256 if (HiiGetBrowserData (&gDriverSampleFormSetGuid
, MyEfiVar
, sizeof (MY_EFI_VARSTORE_DATA
), (UINT8
*) EfiData
)) {
1257 EfiData
->Field8
= 111;
1259 &gDriverSampleFormSetGuid
,
1261 sizeof (MY_EFI_VARSTORE_DATA
),
1273 case EFI_BROWSER_ACTION_DEFAULT_STANDARD
:
1275 switch (QuestionId
) {
1277 Value
->u8
= DEFAULT_CLASS_STANDARD_VALUE
;
1281 for (Index
= 0; Index
< 3; Index
++) {
1282 SetArrayData (Value
, EFI_IFR_TYPE_NUM_SIZE_8
, Index
, BufferValue
--);
1287 Status
= EFI_UNSUPPORTED
;
1293 case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING
:
1295 switch (QuestionId
) {
1297 Value
->u8
= DEFAULT_CLASS_MANUFACTURING_VALUE
;
1301 Status
= EFI_UNSUPPORTED
;
1307 case EFI_BROWSER_ACTION_CHANGING
:
1309 switch (QuestionId
) {
1312 if (Type
!= EFI_IFR_TYPE_REF
) {
1313 return EFI_INVALID_PARAMETER
;
1316 Value
->ref
.FormId
= 0x1234;
1321 // Initialize the container for dynamic opcodes
1323 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1324 ASSERT (StartOpCodeHandle
!= NULL
);
1326 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
1327 ASSERT (EndOpCodeHandle
!= NULL
);
1330 // Create Hii Extend Label OpCode as the start opcode
1332 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1333 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1334 StartLabel
->Number
= LABEL_UPDATE1
;
1337 // Create Hii Extend Label OpCode as the end opcode
1339 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1340 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1341 EndLabel
->Number
= LABEL_END
;
1343 HiiCreateActionOpCode (
1344 StartOpCodeHandle
, // Container for dynamic created opcodes
1345 0x1237, // Question ID
1346 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
1347 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
1348 EFI_IFR_FLAG_CALLBACK
, // Question flag
1349 0 // Action String ID
1353 // Create Option OpCode
1355 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
1356 ASSERT (OptionsOpCodeHandle
!= NULL
);
1358 HiiCreateOneOfOptionOpCode (
1359 OptionsOpCodeHandle
,
1360 STRING_TOKEN (STR_BOOT_OPTION1
),
1362 EFI_IFR_NUMERIC_SIZE_1
,
1366 HiiCreateOneOfOptionOpCode (
1367 OptionsOpCodeHandle
,
1368 STRING_TOKEN (STR_BOOT_OPTION2
),
1370 EFI_IFR_NUMERIC_SIZE_1
,
1375 // Prepare initial value for the dynamic created oneof Question
1377 PrivateData
->Configuration
.DynamicOneof
= 2;
1378 Status
= gRT
->SetVariable(
1380 &gDriverSampleFormSetGuid
,
1381 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1382 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1383 &PrivateData
->Configuration
1387 // Set initial vlaue of dynamic created oneof Question in Form Browser
1389 Configuration
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION
));
1390 ASSERT (Configuration
!= NULL
);
1391 if (HiiGetBrowserData (&gDriverSampleFormSetGuid
, VariableName
, sizeof (DRIVER_SAMPLE_CONFIGURATION
), (UINT8
*) Configuration
)) {
1392 Configuration
->DynamicOneof
= 2;
1395 // Update uncommitted data of Browser
1398 &gDriverSampleFormSetGuid
,
1400 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1401 (UINT8
*) Configuration
,
1405 FreePool (Configuration
);
1407 HiiCreateOneOfOpCode (
1408 StartOpCodeHandle
, // Container for dynamic created opcodes
1409 0x8001, // Question ID (or call it "key")
1410 CONFIGURATION_VARSTORE_ID
, // VarStore ID
1411 (UINT16
) DYNAMIC_ONE_OF_VAR_OFFSET
, // Offset in Buffer Storage
1412 STRING_TOKEN (STR_ONE_OF_PROMPT
), // Question prompt text
1413 STRING_TOKEN (STR_ONE_OF_HELP
), // Question help text
1414 EFI_IFR_FLAG_CALLBACK
, // Question flag
1415 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question Value
1416 OptionsOpCodeHandle
, // Option Opcode list
1417 NULL
// Default Opcode is NULl
1420 HiiCreateOrderedListOpCode (
1421 StartOpCodeHandle
, // Container for dynamic created opcodes
1422 0x8002, // Question ID
1423 CONFIGURATION_VARSTORE_ID
, // VarStore ID
1424 (UINT16
) DYNAMIC_ORDERED_LIST_VAR_OFFSET
, // Offset in Buffer Storage
1425 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question prompt text
1426 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question help text
1427 EFI_IFR_FLAG_RESET_REQUIRED
, // Question flag
1428 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
1429 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question value
1430 5, // Maximum container
1431 OptionsOpCodeHandle
, // Option Opcode list
1432 NULL
// Default Opcode is NULl
1435 HiiCreateTextOpCode (
1437 STRING_TOKEN(STR_TEXT_SAMPLE_HELP
),
1438 STRING_TOKEN(STR_TEXT_SAMPLE_HELP
),
1439 STRING_TOKEN(STR_TEXT_SAMPLE_STRING
)
1442 HiiCreateDateOpCode (
1447 STRING_TOKEN(STR_DATE_SAMPLE_HELP
),
1448 STRING_TOKEN(STR_DATE_SAMPLE_HELP
),
1450 QF_DATE_STORAGE_TIME
,
1454 HiiCreateTimeOpCode (
1459 STRING_TOKEN(STR_TIME_SAMPLE_HELP
),
1460 STRING_TOKEN(STR_TIME_SAMPLE_HELP
),
1462 QF_TIME_STORAGE_TIME
,
1466 HiiCreateGotoOpCode (
1467 StartOpCodeHandle
, // Container for dynamic created opcodes
1468 1, // Target Form ID
1469 STRING_TOKEN (STR_GOTO_FORM1
), // Prompt text
1470 STRING_TOKEN (STR_GOTO_HELP
), // Help text
1472 0x8003 // Question ID
1476 PrivateData
->HiiHandle
[0], // HII handle
1477 &gDriverSampleFormSetGuid
, // Formset GUID
1479 StartOpCodeHandle
, // Label for where to insert opcodes
1480 EndOpCodeHandle
// Replace data
1483 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1484 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1485 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1494 case EFI_BROWSER_ACTION_CHANGED
:
1495 switch (QuestionId
) {
1498 // User press "Exit now", request Browser to exit
1500 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1505 // User press "Save now", request Browser to save the uncommitted data.
1507 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1513 // User press "Submit current form and Exit now", request Browser to submit current form and exit
1515 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1520 // User press "Discard current form now", request Browser to discard the uncommitted data.
1522 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD
;
1527 // User press "Submit current form now", request Browser to save the uncommitted data.
1529 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1535 // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.
1537 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1542 // 1. Check to see whether system support keyword.
1544 Status
= PrivateData
->HiiKeywordHandler
->GetData (PrivateData
->HiiKeywordHandler
,
1545 L
"NAMESPACE=x-UEFI-ns",
1546 L
"KEYWORD=iSCSIBootEnable",
1551 if (EFI_ERROR (Status
)) {
1554 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1557 L
"This system not support this keyword!",
1558 L
"Press ENTER to continue ...",
1562 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1564 Status
= EFI_SUCCESS
;
1569 // 2. If system support this keyword, just try to change value.
1573 // Change value from '0' to '1' or from '1' to '0'
1575 TmpStr
= StrStr (Results
, L
"&VALUE=");
1576 ASSERT (TmpStr
!= NULL
);
1577 TmpStr
+= StrLen (L
"&VALUE=");
1579 if (*TmpStr
== L
'0') {
1586 // 3. Call the keyword handler protocol to change the value.
1588 Status
= PrivateData
->HiiKeywordHandler
->SetData (PrivateData
->HiiKeywordHandler
,
1593 if (EFI_ERROR (Status
)) {
1596 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1599 L
"Set keyword to the system failed!",
1600 L
"Press ENTER to continue ...",
1604 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1606 Status
= EFI_SUCCESS
;
1616 case EFI_BROWSER_ACTION_SUBMITTED
:
1618 if (QuestionId
== 0x1250) {
1620 // Sample CallBack for EFI_BROWSER_ACTION_SUBMITTED action:
1621 // Show up a pop-up to show SUBMITTED callback has been triggered.
1625 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1628 L
"EfiVarstore value has been submitted!",
1629 L
"Press ESC or ENTER to continue ...",
1633 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1639 Status
= EFI_UNSUPPORTED
;
1647 Main entry for this driver.
1649 @param ImageHandle Image handle this driver.
1650 @param SystemTable Pointer to SystemTable.
1652 @retval EFI_SUCESS This function always complete successfully.
1658 IN EFI_HANDLE ImageHandle
,
1659 IN EFI_SYSTEM_TABLE
*SystemTable
1663 EFI_HII_HANDLE HiiHandle
[2];
1664 EFI_SCREEN_DESCRIPTOR Screen
;
1665 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1666 EFI_HII_STRING_PROTOCOL
*HiiString
;
1667 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1668 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1669 EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*HiiKeywordHandler
;
1672 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
1674 EFI_STRING ConfigRequestHdr
;
1675 EFI_STRING NameRequestHdr
;
1676 MY_EFI_VARSTORE_DATA
*VarStoreConfig
;
1677 EFI_INPUT_KEY HotKey
;
1678 EDKII_FORM_BROWSER_EXTENSION_PROTOCOL
*FormBrowserEx
;
1681 // Initialize the local variables.
1683 ConfigRequestHdr
= NULL
;
1687 // Initialize screen dimensions for SendForm().
1688 // Remove 3 characters from top and bottom
1690 ZeroMem (&Screen
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1691 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Screen
.RightColumn
, &Screen
.BottomRow
);
1694 Screen
.BottomRow
= Screen
.BottomRow
- 3;
1697 // Initialize driver private data
1699 mPrivateData
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA
));
1700 if (mPrivateData
== NULL
) {
1701 return EFI_OUT_OF_RESOURCES
;
1704 mPrivateData
->Signature
= DRIVER_SAMPLE_PRIVATE_SIGNATURE
;
1706 mPrivateData
->ConfigAccess
.ExtractConfig
= ExtractConfig
;
1707 mPrivateData
->ConfigAccess
.RouteConfig
= RouteConfig
;
1708 mPrivateData
->ConfigAccess
.Callback
= DriverCallback
;
1711 // Locate Hii Database protocol
1713 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &HiiDatabase
);
1714 if (EFI_ERROR (Status
)) {
1717 mPrivateData
->HiiDatabase
= HiiDatabase
;
1720 // Locate HiiString protocol
1722 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
1723 if (EFI_ERROR (Status
)) {
1726 mPrivateData
->HiiString
= HiiString
;
1729 // Locate Formbrowser2 protocol
1731 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &FormBrowser2
);
1732 if (EFI_ERROR (Status
)) {
1735 mPrivateData
->FormBrowser2
= FormBrowser2
;
1738 // Locate ConfigRouting protocol
1740 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &HiiConfigRouting
);
1741 if (EFI_ERROR (Status
)) {
1744 mPrivateData
->HiiConfigRouting
= HiiConfigRouting
;
1747 // Locate keyword handler protocol
1749 Status
= gBS
->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid
, NULL
, (VOID
**) &HiiKeywordHandler
);
1750 if (EFI_ERROR (Status
)) {
1753 mPrivateData
->HiiKeywordHandler
= HiiKeywordHandler
;
1755 Status
= gBS
->InstallMultipleProtocolInterfaces (
1757 &gEfiDevicePathProtocolGuid
,
1758 &mHiiVendorDevicePath0
,
1759 &gEfiHiiConfigAccessProtocolGuid
,
1760 &mPrivateData
->ConfigAccess
,
1763 ASSERT_EFI_ERROR (Status
);
1765 mPrivateData
->DriverHandle
[0] = DriverHandle
[0];
1768 // Publish our HII data
1770 HiiHandle
[0] = HiiAddPackages (
1771 &gDriverSampleFormSetGuid
,
1773 DriverSampleStrings
,
1777 if (HiiHandle
[0] == NULL
) {
1778 return EFI_OUT_OF_RESOURCES
;
1781 mPrivateData
->HiiHandle
[0] = HiiHandle
[0];
1784 // Publish another Fromset
1786 Status
= gBS
->InstallMultipleProtocolInterfaces (
1788 &gEfiDevicePathProtocolGuid
,
1789 &mHiiVendorDevicePath1
,
1790 &gEfiHiiConfigAccessProtocolGuid
,
1791 &mPrivateData
->ConfigAccess
,
1794 ASSERT_EFI_ERROR (Status
);
1796 mPrivateData
->DriverHandle
[1] = DriverHandle
[1];
1798 HiiHandle
[1] = HiiAddPackages (
1799 &gDriverSampleInventoryGuid
,
1801 DriverSampleStrings
,
1805 if (HiiHandle
[1] == NULL
) {
1806 DriverSampleUnload (ImageHandle
);
1807 return EFI_OUT_OF_RESOURCES
;
1810 mPrivateData
->HiiHandle
[1] = HiiHandle
[1];
1813 // Update the device path string.
1815 NewString
= ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL
*)&mHiiVendorDevicePath0
, FALSE
, FALSE
);
1816 if (HiiSetString (HiiHandle
[0], STRING_TOKEN (STR_DEVICE_PATH
), NewString
, NULL
) == 0) {
1817 DriverSampleUnload (ImageHandle
);
1818 return EFI_OUT_OF_RESOURCES
;
1820 if (NewString
!= NULL
) {
1821 FreePool (NewString
);
1825 // Very simple example of how one would update a string that is already
1826 // in the HII database
1828 NewString
= L
"700 Mhz";
1830 if (HiiSetString (HiiHandle
[0], STRING_TOKEN (STR_CPU_STRING2
), NewString
, NULL
) == 0) {
1831 DriverSampleUnload (ImageHandle
);
1832 return EFI_OUT_OF_RESOURCES
;
1835 HiiSetString (HiiHandle
[0], 0, NewString
, NULL
);
1838 // Initialize Name/Value name String ID
1840 mPrivateData
->NameStringId
[0] = STR_NAME_VALUE_VAR_NAME0
;
1841 mPrivateData
->NameStringId
[1] = STR_NAME_VALUE_VAR_NAME1
;
1842 mPrivateData
->NameStringId
[2] = STR_NAME_VALUE_VAR_NAME2
;
1845 // Initialize configuration data
1847 Configuration
= &mPrivateData
->Configuration
;
1848 ZeroMem (Configuration
, sizeof (DRIVER_SAMPLE_CONFIGURATION
));
1851 // Try to read NV config EFI variable first
1853 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, VariableName
, DriverHandle
[0]);
1854 ASSERT (ConfigRequestHdr
!= NULL
);
1856 NameRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, NULL
, DriverHandle
[0]);
1857 ASSERT (NameRequestHdr
!= NULL
);
1859 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
1860 Status
= gRT
->GetVariable (VariableName
, &gDriverSampleFormSetGuid
, NULL
, &BufferSize
, Configuration
);
1861 if (EFI_ERROR (Status
)) {
1863 // Store zero data Buffer Storage to EFI variable
1865 Status
= gRT
->SetVariable(
1867 &gDriverSampleFormSetGuid
,
1868 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1869 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
1872 if (EFI_ERROR (Status
)) {
1873 DriverSampleUnload (ImageHandle
);
1877 // EFI variable for NV config doesn't exit, we should build this variable
1878 // based on default values stored in IFR
1880 ActionFlag
= HiiSetToDefaults (NameRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
1882 DriverSampleUnload (ImageHandle
);
1883 return EFI_INVALID_PARAMETER
;
1886 ActionFlag
= HiiSetToDefaults (ConfigRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
1888 DriverSampleUnload (ImageHandle
);
1889 return EFI_INVALID_PARAMETER
;
1893 // EFI variable does exist and Validate Current Setting
1895 ActionFlag
= HiiValidateSettings (NameRequestHdr
);
1897 DriverSampleUnload (ImageHandle
);
1898 return EFI_INVALID_PARAMETER
;
1901 ActionFlag
= HiiValidateSettings (ConfigRequestHdr
);
1903 DriverSampleUnload (ImageHandle
);
1904 return EFI_INVALID_PARAMETER
;
1907 FreePool (ConfigRequestHdr
);
1910 // Initialize efi varstore configuration data
1912 VarStoreConfig
= &mPrivateData
->VarStoreConfig
;
1913 ZeroMem (VarStoreConfig
, sizeof (MY_EFI_VARSTORE_DATA
));
1915 ConfigRequestHdr
= HiiConstructConfigHdr (&gDriverSampleFormSetGuid
, MyEfiVar
, DriverHandle
[0]);
1916 ASSERT (ConfigRequestHdr
!= NULL
);
1918 BufferSize
= sizeof (MY_EFI_VARSTORE_DATA
);
1919 Status
= gRT
->GetVariable (MyEfiVar
, &gDriverSampleFormSetGuid
, NULL
, &BufferSize
, VarStoreConfig
);
1920 if (EFI_ERROR (Status
)) {
1922 // Store zero data to EFI variable Storage.
1924 Status
= gRT
->SetVariable(
1926 &gDriverSampleFormSetGuid
,
1927 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1928 sizeof (MY_EFI_VARSTORE_DATA
),
1931 if (EFI_ERROR (Status
)) {
1932 DriverSampleUnload (ImageHandle
);
1936 // EFI variable for NV config doesn't exit, we should build this variable
1937 // based on default values stored in IFR
1939 ActionFlag
= HiiSetToDefaults (ConfigRequestHdr
, EFI_HII_DEFAULT_CLASS_STANDARD
);
1941 DriverSampleUnload (ImageHandle
);
1942 return EFI_INVALID_PARAMETER
;
1946 // EFI variable does exist and Validate Current Setting
1948 ActionFlag
= HiiValidateSettings (ConfigRequestHdr
);
1950 DriverSampleUnload (ImageHandle
);
1951 return EFI_INVALID_PARAMETER
;
1954 FreePool (ConfigRequestHdr
);
1956 Status
= gBS
->CreateEventEx (
1959 EfiEventEmptyFunction
,
1961 &gEfiIfrRefreshIdOpGuid
,
1964 ASSERT_EFI_ERROR (Status
);
1967 // Example of how to use BrowserEx protocol to register HotKey.
1969 Status
= gBS
->LocateProtocol (&gEdkiiFormBrowserExProtocolGuid
, NULL
, (VOID
**) &FormBrowserEx
);
1970 if (!EFI_ERROR (Status
)) {
1972 // First unregister the default hot key F9 and F10.
1974 HotKey
.UnicodeChar
= CHAR_NULL
;
1975 HotKey
.ScanCode
= SCAN_F9
;
1976 FormBrowserEx
->RegisterHotKey (&HotKey
, 0, 0, NULL
);
1977 HotKey
.ScanCode
= SCAN_F10
;
1978 FormBrowserEx
->RegisterHotKey (&HotKey
, 0, 0, NULL
);
1981 // Register the default HotKey F9 and F10 again.
1983 HotKey
.ScanCode
= SCAN_F10
;
1984 NewString
= HiiGetString (mPrivateData
->HiiHandle
[0], STRING_TOKEN (FUNCTION_TEN_STRING
), NULL
);
1985 ASSERT (NewString
!= NULL
);
1986 FormBrowserEx
->RegisterHotKey (&HotKey
, BROWSER_ACTION_SUBMIT
, 0, NewString
);
1987 HotKey
.ScanCode
= SCAN_F9
;
1988 NewString
= HiiGetString (mPrivateData
->HiiHandle
[0], STRING_TOKEN (FUNCTION_NINE_STRING
), NULL
);
1989 ASSERT (NewString
!= NULL
);
1990 FormBrowserEx
->RegisterHotKey (&HotKey
, BROWSER_ACTION_DEFAULT
, EFI_HII_DEFAULT_CLASS_STANDARD
, NewString
);
1994 // In default, this driver is built into Flash device image,
1995 // the following code doesn't run.
1999 // Example of how to display only the item we sent to HII
2000 // When this driver is not built into Flash device image,
2001 // it need to call SendForm to show front page by itself.
2003 if (DISPLAY_ONLY_MY_ITEM
<= 1) {
2005 // Have the browser pull out our copy of the data, and only display our data
2007 Status
= FormBrowser2
->SendForm (
2009 &(HiiHandle
[DISPLAY_ONLY_MY_ITEM
]),
2017 HiiRemovePackages (HiiHandle
[0]);
2019 HiiRemovePackages (HiiHandle
[1]);
2026 Unloads the application and its installed protocol.
2028 @param[in] ImageHandle Handle that identifies the image to be unloaded.
2030 @retval EFI_SUCCESS The image has been unloaded.
2034 DriverSampleUnload (
2035 IN EFI_HANDLE ImageHandle
2040 ASSERT (mPrivateData
!= NULL
);
2042 if (DriverHandle
[0] != NULL
) {
2043 gBS
->UninstallMultipleProtocolInterfaces (
2045 &gEfiDevicePathProtocolGuid
,
2046 &mHiiVendorDevicePath0
,
2047 &gEfiHiiConfigAccessProtocolGuid
,
2048 &mPrivateData
->ConfigAccess
,
2051 DriverHandle
[0] = NULL
;
2054 if (DriverHandle
[1] != NULL
) {
2055 gBS
->UninstallMultipleProtocolInterfaces (
2057 &gEfiDevicePathProtocolGuid
,
2058 &mHiiVendorDevicePath1
,
2059 &gEfiHiiConfigAccessProtocolGuid
,
2060 &mPrivateData
->ConfigAccess
,
2063 DriverHandle
[1] = NULL
;
2066 if (mPrivateData
->HiiHandle
[0] != NULL
) {
2067 HiiRemovePackages (mPrivateData
->HiiHandle
[0]);
2070 if (mPrivateData
->HiiHandle
[1] != NULL
) {
2071 HiiRemovePackages (mPrivateData
->HiiHandle
[1]);
2074 for (Index
= 0; Index
< NAME_VALUE_NAME_NUMBER
; Index
++) {
2075 if (mPrivateData
->NameValueName
[Index
] != NULL
) {
2076 FreePool (mPrivateData
->NameValueName
[Index
]);
2079 FreePool (mPrivateData
);
2080 mPrivateData
= NULL
;
2082 gBS
->CloseEvent (mEvent
);