2 Implementation of interfaces function for EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL.
4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "HiiDatabase.h"
11 extern HII_DATABASE_PRIVATE_DATA mPrivate
;
14 Convert the hex UNICODE %02x encoding of a UEFI device path to binary
15 from <PathHdr> of <MultiKeywordRequest>.
17 This is a internal function.
19 @param String MultiKeywordRequest string.
20 @param DevicePathData Binary of a UEFI device path.
21 @param NextString string follow the possible PathHdr string.
23 @retval EFI_INVALID_PARAMETER The device path is not valid or the incoming parameter is invalid.
24 @retval EFI_OUT_OF_RESOURCES Lake of resources to store necessary structures.
25 @retval EFI_SUCCESS The device path is retrieved and translated to binary format.
26 The Input string not include PathHdr section.
32 OUT UINT8
**DevicePathData
,
33 OUT EFI_STRING
*NextString
38 UINT8
*DevicePathBuffer
;
42 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
44 ASSERT (NextString
!= NULL
&& DevicePathData
!= NULL
);
47 // KeywordRequest == NULL case.
50 *DevicePathData
= NULL
;
58 if (*String
== L
'&') {
63 // Find the 'PATH=' of <PathHdr>.
65 if (StrnCmp (String
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
66 if (StrnCmp (String
, L
"KEYWORD=", StrLen (L
"KEYWORD=")) != 0) {
67 return EFI_INVALID_PARAMETER
;
70 // Not include PathHdr, return success and DevicePath = NULL.
72 *DevicePathData
= NULL
;
79 // Check whether path data does exist.
81 String
+= StrLen (L
"PATH=");
83 return EFI_INVALID_PARAMETER
;
89 // The content between 'PATH=' of <ConfigHdr> and '&' of next element
90 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding
91 // of UEFI device path.
93 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++) {
97 // Save the return next keyword string value.
102 // Check DevicePath Length
104 if (((Length
+ 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
105 return EFI_INVALID_PARAMETER
;
109 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
110 // as the device path resides in RAM memory.
111 // Translate the data into binary.
113 DevicePathBuffer
= (UINT8
*)AllocateZeroPool ((Length
+ 1) / 2);
114 if (DevicePathBuffer
== NULL
) {
115 return EFI_OUT_OF_RESOURCES
;
119 // Convert DevicePath
121 ZeroMem (TemStr
, sizeof (TemStr
));
122 for (Index
= 0; Index
< Length
; Index
++) {
123 TemStr
[0] = PathHdr
[Index
];
124 DigitUint8
= (UINT8
)StrHexToUint64 (TemStr
);
125 if ((Index
& 1) == 0) {
126 DevicePathBuffer
[Index
/2] = DigitUint8
;
128 DevicePathBuffer
[Index
/2] = (UINT8
)((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
133 // Validate DevicePath
135 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)DevicePathBuffer
;
136 while (!IsDevicePathEnd (DevicePath
)) {
137 if ((DevicePath
->Type
== 0) || (DevicePath
->SubType
== 0) || (DevicePathNodeLength (DevicePath
) < sizeof (EFI_DEVICE_PATH_PROTOCOL
))) {
139 // Invalid device path
141 FreePool (DevicePathBuffer
);
142 return EFI_INVALID_PARAMETER
;
145 DevicePath
= NextDevicePathNode (DevicePath
);
149 // return the device path
151 *DevicePathData
= DevicePathBuffer
;
157 Get NameSpace from the input NameSpaceId string.
159 This is a internal function.
161 @param String <NameSpaceId> format string.
162 @param NameSpace Return the name space string.
163 @param NextString Return the next string follow namespace.
165 @retval EFI_SUCCESS Get the namespace string success.
166 @retval EFI_INVALID_PARAMETER The NameSpaceId string not follow spec definition.
171 IN EFI_STRING String
,
172 OUT CHAR8
**NameSpace
,
173 OUT EFI_STRING
*NextString
179 ASSERT (NameSpace
!= NULL
);
184 // Input NameSpaceId == NULL
186 if (String
== NULL
) {
188 if (NextString
!= NULL
) {
196 // Skip '&' if exist.
198 if (*String
== L
'&') {
202 if (StrnCmp (String
, L
"NAMESPACE=", StrLen (L
"NAMESPACE=")) != 0) {
203 return EFI_INVALID_PARAMETER
;
206 String
+= StrLen (L
"NAMESPACE=");
208 TmpPtr
= StrStr (String
, L
"&");
209 if (TmpPtr
!= NULL
) {
213 if (NextString
!= NULL
) {
214 *NextString
= String
+ StrLen (String
);
218 // Input NameSpace is unicode string. The language in String package is ascii string.
219 // Here will convert the unicode string to ascii and save it.
221 NameSpaceSize
= StrLen (String
) + 1;
222 *NameSpace
= AllocatePool (NameSpaceSize
);
223 if (*NameSpace
== NULL
) {
224 return EFI_OUT_OF_RESOURCES
;
227 UnicodeStrToAsciiStrS (String
, *NameSpace
, NameSpaceSize
);
229 if (TmpPtr
!= NULL
) {
237 Get Keyword from the input KeywordRequest string.
239 This is a internal function.
241 @param String KeywordRequestformat string.
242 @param Keyword return the extract keyword string.
243 @param NextString return the next string follow this keyword section.
245 @retval EFI_SUCCESS Success to get the keyword string.
246 @retval EFI_INVALID_PARAMETER Parse the input string return error.
251 IN EFI_STRING String
,
252 OUT EFI_STRING
*Keyword
,
253 OUT EFI_STRING
*NextString
258 ASSERT ((Keyword
!= NULL
) && (NextString
!= NULL
));
263 // KeywordRequest == NULL case.
265 if (String
== NULL
) {
272 // Skip '&' if exist.
274 if (*String
== L
'&') {
278 if (StrnCmp (String
, L
"KEYWORD=", StrLen (L
"KEYWORD=")) != 0) {
279 return EFI_INVALID_PARAMETER
;
282 String
+= StrLen (L
"KEYWORD=");
284 TmpPtr
= StrStr (String
, L
"&");
285 if (TmpPtr
!= NULL
) {
289 *NextString
= String
+ StrLen (String
);
291 *Keyword
= AllocateCopyPool (StrSize (String
), String
);
292 if (*Keyword
== NULL
) {
293 return EFI_OUT_OF_RESOURCES
;
296 if (TmpPtr
!= NULL
) {
304 Get value from the input KeywordRequest string.
306 This is a internal function.
308 @param String KeywordRequestformat string.
309 @param Value return the extract value string.
310 @param NextString return the next string follow this keyword section.
312 @retval EFI_SUCCESS Success to get the keyword string.
313 @retval EFI_INVALID_PARAMETER Parse the input string return error.
318 IN EFI_STRING String
,
319 OUT EFI_STRING
*Value
,
320 OUT EFI_STRING
*NextString
325 ASSERT ((Value
!= NULL
) && (NextString
!= NULL
) && (String
!= NULL
));
328 // Skip '&' if exist.
330 if (*String
== L
'&') {
334 if (StrnCmp (String
, L
"VALUE=", StrLen (L
"VALUE=")) != 0) {
335 return EFI_INVALID_PARAMETER
;
338 String
+= StrLen (L
"VALUE=");
340 TmpPtr
= StrStr (String
, L
"&");
341 if (TmpPtr
!= NULL
) {
345 *NextString
= String
+ StrLen (String
);
347 *Value
= AllocateCopyPool (StrSize (String
), String
);
348 if (*Value
== NULL
) {
349 return EFI_OUT_OF_RESOURCES
;
352 if (TmpPtr
!= NULL
) {
360 Get filter from the input KeywordRequest string.
362 This is a internal function.
364 @param String KeywordRequestformat string.
365 @param FilterFlags return the filter condition.
366 @param NextString return the next string follow this keyword section.
368 @retval EFI_SUCCESS Success to get the keyword string.
369 @retval EFI_INVALID_PARAMETER Parse the input string return error.
374 IN EFI_STRING String
,
375 OUT UINT8
*FilterFlags
,
376 OUT EFI_STRING
*NextString
383 ASSERT ((FilterFlags
!= NULL
) && (NextString
!= NULL
));
386 // String end, no filter section.
388 if (String
== NULL
) {
397 // Skip '&' if exist.
399 if (*String
== L
'&') {
403 if (StrnCmp (String
, L
"ReadOnly", StrLen (L
"ReadOnly")) == 0) {
405 // Find ReadOnly filter.
407 *FilterFlags
|= EFI_KEYWORD_FILTER_READONY
;
408 String
+= StrLen (L
"ReadOnly");
409 } else if (StrnCmp (String
, L
"ReadWrite", StrLen (L
"ReadWrite")) == 0) {
411 // Find ReadWrite filter.
413 *FilterFlags
|= EFI_KEYWORD_FILTER_REAWRITE
;
414 String
+= StrLen (L
"ReadWrite");
415 } else if (StrnCmp (String
, L
"Buffer", StrLen (L
"Buffer")) == 0) {
417 // Find Buffer Filter.
419 *FilterFlags
|= EFI_KEYWORD_FILTER_BUFFER
;
420 String
+= StrLen (L
"Buffer");
421 } else if (StrnCmp (String
, L
"Numeric", StrLen (L
"Numeric")) == 0) {
423 // Find Numeric Filter
425 String
+= StrLen (L
"Numeric");
426 if (*String
!= L
':') {
427 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC
;
432 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_1
;
435 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_2
;
438 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_4
;
441 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_8
;
452 // Check whether other filter item defined by Platform.
454 if ((StrnCmp (String
, L
"&PATH", StrLen (L
"&PATH")) == 0) ||
455 (StrnCmp (String
, L
"&KEYWORD", StrLen (L
"&KEYWORD")) == 0))
458 // New KeywordRequest start, no platform defined filter.
462 // Platform defined filter rule.
463 // Just skip platform defined filter rule, return success.
465 PathPtr
= StrStr (String
, L
"&PATH");
466 KeywordPtr
= StrStr (String
, L
"&KEYWORD");
467 if ((PathPtr
!= NULL
) && (KeywordPtr
!= NULL
)) {
469 // If both sections exist, return the first follow string.
471 String
= KeywordPtr
> PathPtr
? PathPtr
: KeywordPtr
;
472 } else if (PathPtr
!= NULL
) {
474 // Should not exist PathPtr != NULL && KeywordPtr == NULL case.
477 } else if (KeywordPtr
!= NULL
) {
479 // Just to the next keyword section.
484 // Only has platform defined filter section, just skip it.
486 String
+= StrLen (String
);
493 *NextString
= String
;
499 Extract Readonly flag from opcode.
501 This is a internal function.
503 @param OpCodeData Input opcode for this question.
505 @retval TRUE This question is readonly.
506 @retval FALSE This question is not readonly.
510 ExtractReadOnlyFromOpCode (
514 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
516 ASSERT (OpCodeData
!= NULL
);
518 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
520 return (QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) != 0;
524 Create a circuit to check the filter section.
526 This is a internal function.
528 @param OpCodeData The question binary ifr data.
529 @param KeywordRequest KeywordRequestformat string.
530 @param NextString return the next string follow this keyword section.
531 @param ReadOnly Return whether this question is read only.
533 @retval KEYWORD_HANDLER_NO_ERROR Success validate.
534 @retval KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED Validate fail.
539 IN UINT8
*OpCodeData
,
540 IN CHAR16
*KeywordRequest
,
541 OUT CHAR16
**NextString
,
542 OUT BOOLEAN
*ReadOnly
548 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
549 EFI_IFR_OP_HEADER
*OpCodeHdr
;
553 RetVal
= KEYWORD_HANDLER_NO_ERROR
;
554 StringPtr
= KeywordRequest
;
556 OpCodeHdr
= (EFI_IFR_OP_HEADER
*)OpCodeData
;
557 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
558 if ((OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
) || (OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
)) {
559 Flags
= *(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
) + sizeof (EFI_IFR_QUESTION_HEADER
));
565 // Get ReadOnly flag from Question.
567 *ReadOnly
= ExtractReadOnlyFromOpCode (OpCodeData
);
569 while (ExtractFilter (StringPtr
, &FilterFlags
, &NextFilter
)) {
570 switch (FilterFlags
) {
571 case EFI_KEYWORD_FILTER_READONY
:
572 if ((QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) == 0) {
573 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
579 case EFI_KEYWORD_FILTER_REAWRITE
:
580 if ((QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) != 0) {
581 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
587 case EFI_KEYWORD_FILTER_BUFFER
:
589 // Only these three opcode use numeric value type.
591 if ((OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
) || (OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) || (OpCodeHdr
->OpCode
== EFI_IFR_CHECKBOX_OP
)) {
592 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
598 case EFI_KEYWORD_FILTER_NUMERIC
:
599 if ((OpCodeHdr
->OpCode
!= EFI_IFR_ONE_OF_OP
) && (OpCodeHdr
->OpCode
!= EFI_IFR_NUMERIC_OP
) && (OpCodeHdr
->OpCode
!= EFI_IFR_CHECKBOX_OP
)) {
600 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
606 case EFI_KEYWORD_FILTER_NUMERIC_1
:
607 case EFI_KEYWORD_FILTER_NUMERIC_2
:
608 case EFI_KEYWORD_FILTER_NUMERIC_4
:
609 case EFI_KEYWORD_FILTER_NUMERIC_8
:
610 if ((OpCodeHdr
->OpCode
!= EFI_IFR_ONE_OF_OP
) && (OpCodeHdr
->OpCode
!= EFI_IFR_NUMERIC_OP
) && (OpCodeHdr
->OpCode
!= EFI_IFR_CHECKBOX_OP
)) {
611 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
616 // For numeric and oneof, it has flags field to specify the detail numeric type.
618 if ((OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
) || (OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
)) {
619 switch (Flags
& EFI_IFR_NUMERIC_SIZE
) {
620 case EFI_IFR_NUMERIC_SIZE_1
:
621 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_1
) {
622 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
628 case EFI_IFR_NUMERIC_SIZE_2
:
629 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_2
) {
630 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
636 case EFI_IFR_NUMERIC_SIZE_4
:
637 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_4
) {
638 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
644 case EFI_IFR_NUMERIC_SIZE_8
:
645 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_8
) {
646 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
666 // Jump to the next filter.
668 StringPtr
= NextFilter
;
673 // The current filter which is processing.
675 *NextString
= StringPtr
;
681 Get HII_DATABASE_RECORD from the input device path info.
683 This is a internal function.
685 @param DevicePath UEFI device path protocol.
687 @retval Internal data base record.
690 HII_DATABASE_RECORD
*
691 GetRecordFromDevicePath (
692 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
696 UINT8
*DevicePathPkg
;
697 UINT8
*CurrentDevicePath
;
698 UINTN DevicePathSize
;
699 HII_DATABASE_RECORD
*TempDatabase
;
701 ASSERT (DevicePath
!= NULL
);
703 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
704 TempDatabase
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
705 DevicePathPkg
= TempDatabase
->PackageList
->DevicePathPkg
;
706 if (DevicePathPkg
!= NULL
) {
707 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
708 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)CurrentDevicePath
);
709 if ((CompareMem (DevicePath
, CurrentDevicePath
, DevicePathSize
) == 0)) {
719 Calculate the size of StringSrc and output it. Also copy string text from src
722 This is a internal function.
724 @param StringSrc Points to current null-terminated string.
725 @param BufferSize Length of the buffer.
726 @param StringDest Buffer to store the string text.
728 @retval EFI_SUCCESS The string text was outputted successfully.
729 @retval EFI_OUT_OF_RESOURCES Out of resource.
733 GetUnicodeStringTextAndSize (
735 OUT UINTN
*BufferSize
,
736 OUT EFI_STRING
*StringDest
742 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
&& StringDest
!= NULL
);
744 StringSize
= sizeof (CHAR16
);
745 StringPtr
= StringSrc
;
746 while (ReadUnaligned16 ((UINT16
*)StringPtr
) != 0) {
747 StringSize
+= sizeof (CHAR16
);
748 StringPtr
+= sizeof (CHAR16
);
751 *StringDest
= AllocatePool (StringSize
);
752 if (*StringDest
== NULL
) {
753 return EFI_OUT_OF_RESOURCES
;
756 CopyMem (*StringDest
, StringSrc
, StringSize
);
758 *BufferSize
= StringSize
;
763 Find the string id for the input keyword.
765 @param StringPackage Hii string package instance.
766 @param KeywordValue Input keyword value.
767 @param StringId The string's id, which is unique within PackageList.
770 @retval EFI_SUCCESS The string text and font is retrieved
772 @retval EFI_NOT_FOUND The specified text or font info can not be found
774 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
778 GetStringIdFromString (
779 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
780 IN CHAR16
*KeywordValue
,
781 OUT EFI_STRING_ID
*StringId
785 EFI_STRING_ID CurrentStringId
;
788 UINT8
*StringTextPtr
;
793 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
797 CHAR8
*AsciiKeywordValue
;
798 UINTN KeywordValueSize
;
801 ASSERT (StringPackage
!= NULL
&& KeywordValue
!= NULL
&& StringId
!= NULL
);
802 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
805 Status
= EFI_SUCCESS
;
807 BlockHdr
= StringPackage
->StringBlock
;
812 // Make a ascii keyword value for later use.
814 KeywordValueSize
= StrLen (KeywordValue
) + 1;
815 AsciiKeywordValue
= AllocatePool (KeywordValueSize
);
816 if (AsciiKeywordValue
== NULL
) {
817 return EFI_OUT_OF_RESOURCES
;
820 UnicodeStrToAsciiStrS (KeywordValue
, AsciiKeywordValue
, KeywordValueSize
);
822 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
824 case EFI_HII_SIBT_STRING_SCSU
:
825 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
826 StringTextPtr
= BlockHdr
+ Offset
;
827 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
828 if (AsciiStrCmp (AsciiKeywordValue
, (CHAR8
*)StringTextPtr
) == 0) {
829 *StringId
= CurrentStringId
;
836 case EFI_HII_SIBT_STRING_SCSU_FONT
:
837 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
838 StringTextPtr
= BlockHdr
+ Offset
;
839 if (AsciiStrCmp (AsciiKeywordValue
, (CHAR8
*)StringTextPtr
) == 0) {
840 *StringId
= CurrentStringId
;
844 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
848 case EFI_HII_SIBT_STRINGS_SCSU
:
849 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
850 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
851 BlockSize
+= StringTextPtr
- BlockHdr
;
853 for (Index
= 0; Index
< StringCount
; Index
++) {
854 BlockSize
+= AsciiStrSize ((CHAR8
*)StringTextPtr
);
855 if (AsciiStrCmp (AsciiKeywordValue
, (CHAR8
*)StringTextPtr
) == 0) {
856 *StringId
= CurrentStringId
;
860 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
866 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
869 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
872 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
873 BlockSize
+= StringTextPtr
- BlockHdr
;
875 for (Index
= 0; Index
< StringCount
; Index
++) {
876 BlockSize
+= AsciiStrSize ((CHAR8
*)StringTextPtr
);
877 if (AsciiStrCmp (AsciiKeywordValue
, (CHAR8
*)StringTextPtr
) == 0) {
878 *StringId
= CurrentStringId
;
882 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
888 case EFI_HII_SIBT_STRING_UCS2
:
889 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
890 StringTextPtr
= BlockHdr
+ Offset
;
892 // Use StringSize to store the size of the specified string, including the NULL
895 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
896 if (EFI_ERROR (Status
)) {
900 ASSERT (String
!= NULL
);
901 if (StrCmp (KeywordValue
, String
) == 0) {
902 *StringId
= CurrentStringId
;
906 BlockSize
+= Offset
+ StringSize
;
910 case EFI_HII_SIBT_STRING_UCS2_FONT
:
911 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
912 StringTextPtr
= BlockHdr
+ Offset
;
914 // Use StringSize to store the size of the specified string, including the NULL
917 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
918 if (EFI_ERROR (Status
)) {
922 ASSERT (String
!= NULL
);
923 if (StrCmp (KeywordValue
, String
) == 0) {
924 *StringId
= CurrentStringId
;
928 BlockSize
+= Offset
+ StringSize
;
932 case EFI_HII_SIBT_STRINGS_UCS2
:
933 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
934 StringTextPtr
= BlockHdr
+ Offset
;
936 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
937 for (Index
= 0; Index
< StringCount
; Index
++) {
938 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
939 if (EFI_ERROR (Status
)) {
943 ASSERT (String
!= NULL
);
944 BlockSize
+= StringSize
;
945 if (StrCmp (KeywordValue
, String
) == 0) {
946 *StringId
= CurrentStringId
;
950 StringTextPtr
= StringTextPtr
+ StringSize
;
956 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
957 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
958 StringTextPtr
= BlockHdr
+ Offset
;
962 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
965 for (Index
= 0; Index
< StringCount
; Index
++) {
966 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
967 if (EFI_ERROR (Status
)) {
971 ASSERT (String
!= NULL
);
972 BlockSize
+= StringSize
;
973 if (StrCmp (KeywordValue
, String
) == 0) {
974 *StringId
= CurrentStringId
;
978 StringTextPtr
= StringTextPtr
+ StringSize
;
984 case EFI_HII_SIBT_DUPLICATE
:
985 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
989 case EFI_HII_SIBT_SKIP1
:
990 SkipCount
= (UINT16
)(*(UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
991 CurrentStringId
= (UINT16
)(CurrentStringId
+ SkipCount
);
992 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
995 case EFI_HII_SIBT_SKIP2
:
996 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
997 CurrentStringId
= (UINT16
)(CurrentStringId
+ SkipCount
);
998 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
1001 case EFI_HII_SIBT_EXT1
:
1004 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1007 BlockSize
+= Length8
;
1010 case EFI_HII_SIBT_EXT2
:
1011 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1012 BlockSize
+= Ext2
.Length
;
1015 case EFI_HII_SIBT_EXT4
:
1018 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1022 BlockSize
+= Length32
;
1029 if (String
!= NULL
) {
1034 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
1037 Status
= EFI_NOT_FOUND
;
1040 if (AsciiKeywordValue
!= NULL
) {
1041 FreePool (AsciiKeywordValue
);
1044 if (String
!= NULL
) {
1052 Find the next valid string id for the input string id.
1054 @param StringPackage Hii string package instance.
1055 @param StringId The current string id which is already got.
1056 1 means just begin to get the string id.
1057 @param KeywordValue Return the string for the next string id.
1060 @retval EFI_STRING_ID Not 0 means a valid stringid found.
1061 0 means not found a valid string id.
1065 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
1066 IN EFI_STRING_ID StringId
,
1067 OUT EFI_STRING
*KeywordValue
1071 EFI_STRING_ID CurrentStringId
;
1074 UINT8
*StringTextPtr
;
1079 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
1085 ASSERT (StringPackage
!= NULL
);
1086 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
1088 CurrentStringId
= 1;
1093 // Parse the string blocks to get the string text and font.
1095 BlockHdr
= StringPackage
->StringBlock
;
1098 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
1099 switch (*BlockHdr
) {
1100 case EFI_HII_SIBT_STRING_SCSU
:
1101 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
1102 StringTextPtr
= BlockHdr
+ Offset
;
1105 StringSize
= AsciiStrSize ((CHAR8
*)StringTextPtr
);
1106 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1107 if (*KeywordValue
== NULL
) {
1111 AsciiStrToUnicodeStrS ((CHAR8
*)StringTextPtr
, *KeywordValue
, StringSize
);
1112 return CurrentStringId
;
1113 } else if (CurrentStringId
== StringId
) {
1117 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
1121 case EFI_HII_SIBT_STRING_SCSU_FONT
:
1122 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
1123 StringTextPtr
= BlockHdr
+ Offset
;
1126 StringSize
= AsciiStrSize ((CHAR8
*)StringTextPtr
);
1127 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1128 if (*KeywordValue
== NULL
) {
1132 AsciiStrToUnicodeStrS ((CHAR8
*)StringTextPtr
, *KeywordValue
, StringSize
);
1133 return CurrentStringId
;
1134 } else if (CurrentStringId
== StringId
) {
1138 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
1142 case EFI_HII_SIBT_STRINGS_SCSU
:
1143 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1144 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
1145 BlockSize
+= StringTextPtr
- BlockHdr
;
1147 for (Index
= 0; Index
< StringCount
; Index
++) {
1149 StringSize
= AsciiStrSize ((CHAR8
*)StringTextPtr
);
1150 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1151 if (*KeywordValue
== NULL
) {
1155 AsciiStrToUnicodeStrS ((CHAR8
*)StringTextPtr
, *KeywordValue
, StringSize
);
1156 return CurrentStringId
;
1157 } else if (CurrentStringId
== StringId
) {
1161 BlockSize
+= AsciiStrSize ((CHAR8
*)StringTextPtr
);
1162 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
1168 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
1171 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1174 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
1175 BlockSize
+= StringTextPtr
- BlockHdr
;
1177 for (Index
= 0; Index
< StringCount
; Index
++) {
1179 StringSize
= AsciiStrSize ((CHAR8
*)StringTextPtr
);
1180 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1181 if (*KeywordValue
== NULL
) {
1185 AsciiStrToUnicodeStrS ((CHAR8
*)StringTextPtr
, *KeywordValue
, StringSize
);
1186 return CurrentStringId
;
1187 } else if (CurrentStringId
== StringId
) {
1191 BlockSize
+= AsciiStrSize ((CHAR8
*)StringTextPtr
);
1192 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
);
1198 case EFI_HII_SIBT_STRING_UCS2
:
1199 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
1200 StringTextPtr
= BlockHdr
+ Offset
;
1202 // Use StringSize to store the size of the specified string, including the NULL
1205 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1206 if (FindString
&& (String
!= NULL
) && (*String
!= L
'\0')) {
1208 // String protocol use this type for the string id which has value for other package.
1209 // It will allocate an empty string block for this string id. so here we also check
1210 // *String != L'\0' to prohibit this case.
1212 *KeywordValue
= String
;
1213 return CurrentStringId
;
1214 } else if (CurrentStringId
== StringId
) {
1218 BlockSize
+= Offset
+ StringSize
;
1222 case EFI_HII_SIBT_STRING_UCS2_FONT
:
1223 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
1224 StringTextPtr
= BlockHdr
+ Offset
;
1226 // Use StringSize to store the size of the specified string, including the NULL
1229 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1231 *KeywordValue
= String
;
1232 return CurrentStringId
;
1233 } else if (CurrentStringId
== StringId
) {
1237 BlockSize
+= Offset
+ StringSize
;
1241 case EFI_HII_SIBT_STRINGS_UCS2
:
1242 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
1243 StringTextPtr
= BlockHdr
+ Offset
;
1244 BlockSize
+= Offset
;
1245 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1246 for (Index
= 0; Index
< StringCount
; Index
++) {
1247 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1250 *KeywordValue
= String
;
1251 return CurrentStringId
;
1252 } else if (CurrentStringId
== StringId
) {
1256 BlockSize
+= StringSize
;
1257 StringTextPtr
= StringTextPtr
+ StringSize
;
1263 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
1264 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
1265 StringTextPtr
= BlockHdr
+ Offset
;
1266 BlockSize
+= Offset
;
1269 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1272 for (Index
= 0; Index
< StringCount
; Index
++) {
1273 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1275 *KeywordValue
= String
;
1276 return CurrentStringId
;
1277 } else if (CurrentStringId
== StringId
) {
1281 BlockSize
+= StringSize
;
1282 StringTextPtr
= StringTextPtr
+ StringSize
;
1288 case EFI_HII_SIBT_DUPLICATE
:
1289 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
1293 case EFI_HII_SIBT_SKIP1
:
1294 SkipCount
= (UINT16
)(*(UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
1295 CurrentStringId
= (UINT16
)(CurrentStringId
+ SkipCount
);
1296 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
1299 case EFI_HII_SIBT_SKIP2
:
1300 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1301 CurrentStringId
= (UINT16
)(CurrentStringId
+ SkipCount
);
1302 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
1305 case EFI_HII_SIBT_EXT1
:
1308 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1311 BlockSize
+= Length8
;
1314 case EFI_HII_SIBT_EXT2
:
1315 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1316 BlockSize
+= Ext2
.Length
;
1319 case EFI_HII_SIBT_EXT4
:
1322 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1326 BlockSize
+= Length32
;
1333 if (String
!= NULL
) {
1338 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
1345 Get string package from the input NameSpace string.
1347 This is a internal function.
1349 @param DatabaseRecord HII_DATABASE_RECORD format string.
1350 @param NameSpace NameSpace format string.
1351 @param KeywordValue Keyword value.
1352 @param StringId String Id for this keyword.
1354 @retval KEYWORD_HANDLER_NO_ERROR Get String id successfully.
1355 @retval KEYWORD_HANDLER_KEYWORD_NOT_FOUND Not found the string id in the string package.
1356 @retval KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND Not found the string package for this namespace.
1357 @retval KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR Out of resource error.
1361 GetStringIdFromRecord (
1362 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1363 IN CHAR8
**NameSpace
,
1364 IN CHAR16
*KeywordValue
,
1365 OUT EFI_STRING_ID
*StringId
1369 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1370 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1375 ASSERT (DatabaseRecord
!= NULL
&& NameSpace
!= NULL
&& KeywordValue
!= NULL
);
1377 PackageListNode
= DatabaseRecord
->PackageList
;
1378 RetVal
= KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
1380 if (*NameSpace
!= NULL
) {
1383 Name
= UEFI_CONFIG_LANG
;
1386 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->StringPkgHdr
; Link
= Link
->ForwardLink
) {
1387 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1389 if (AsciiStrnCmp (Name
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (Name
)) == 0) {
1390 Status
= GetStringIdFromString (StringPackage
, KeywordValue
, StringId
);
1391 if (EFI_ERROR (Status
)) {
1392 return KEYWORD_HANDLER_KEYWORD_NOT_FOUND
;
1394 if (*NameSpace
== NULL
) {
1395 *NameSpace
= AllocateCopyPool (AsciiStrSize (StringPackage
->StringPkgHdr
->Language
), StringPackage
->StringPkgHdr
->Language
);
1396 if (*NameSpace
== NULL
) {
1397 return KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
1401 return KEYWORD_HANDLER_NO_ERROR
;
1410 Tell whether this Operand is an Statement OpCode.
1412 @param Operand Operand of an IFR OpCode.
1414 @retval TRUE This is an Statement OpCode.
1415 @retval FALSE Not an Statement OpCode.
1423 if ((Operand
== EFI_IFR_SUBTITLE_OP
) ||
1424 (Operand
== EFI_IFR_TEXT_OP
) ||
1425 (Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1426 (Operand
== EFI_IFR_REF_OP
) ||
1427 (Operand
== EFI_IFR_ACTION_OP
) ||
1428 (Operand
== EFI_IFR_NUMERIC_OP
) ||
1429 (Operand
== EFI_IFR_ORDERED_LIST_OP
) ||
1430 (Operand
== EFI_IFR_CHECKBOX_OP
) ||
1431 (Operand
== EFI_IFR_STRING_OP
) ||
1432 (Operand
== EFI_IFR_PASSWORD_OP
) ||
1433 (Operand
== EFI_IFR_DATE_OP
) ||
1434 (Operand
== EFI_IFR_TIME_OP
) ||
1435 (Operand
== EFI_IFR_GUID_OP
) ||
1436 (Operand
== EFI_IFR_ONE_OF_OP
))
1445 Tell whether this Operand is an Statement OpCode.
1447 @param Operand Operand of an IFR OpCode.
1449 @retval TRUE This is an Statement OpCode.
1450 @retval FALSE Not an Statement OpCode.
1458 if ((Operand
== EFI_IFR_VARSTORE_OP
) ||
1459 (Operand
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) ||
1460 (Operand
== EFI_IFR_VARSTORE_EFI_OP
))
1469 Base on the prompt string id to find the question.
1471 @param FormPackage The input form package.
1472 @param KeywordStrId The input prompt string id for one question.
1474 @retval the opcode for the question.
1478 FindQuestionFromStringId (
1479 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1480 IN EFI_STRING_ID KeywordStrId
1485 EFI_IFR_STATEMENT_HEADER
*StatementHeader
;
1486 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1489 ASSERT (FormPackage
!= NULL
);
1491 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1493 while (Offset
< FormDataLen
) {
1494 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1495 OpCodeHeader
= (EFI_IFR_OP_HEADER
*)OpCodeData
;
1497 if (IsStatementOpCode (OpCodeHeader
->OpCode
)) {
1498 StatementHeader
= (EFI_IFR_STATEMENT_HEADER
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
1499 if (StatementHeader
->Prompt
== KeywordStrId
) {
1504 Offset
+= OpCodeHeader
->Length
;
1511 Base on the varstore id to find the storage info.
1513 @param FormPackage The input form package.
1514 @param VarStoreId The input storage id.
1516 @retval the opcode for the storage.
1520 FindStorageFromVarId (
1521 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1522 IN EFI_VARSTORE_ID VarStoreId
1527 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1530 ASSERT (FormPackage
!= NULL
);
1532 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1534 while (Offset
< FormDataLen
) {
1535 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1536 OpCodeHeader
= (EFI_IFR_OP_HEADER
*)OpCodeData
;
1538 if (IsStorageOpCode (OpCodeHeader
->OpCode
)) {
1539 switch (OpCodeHeader
->OpCode
) {
1540 case EFI_IFR_VARSTORE_OP
:
1541 if (VarStoreId
== ((EFI_IFR_VARSTORE
*)OpCodeData
)->VarStoreId
) {
1547 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1548 if (VarStoreId
== ((EFI_IFR_VARSTORE_NAME_VALUE
*)OpCodeData
)->VarStoreId
) {
1554 case EFI_IFR_VARSTORE_EFI_OP
:
1555 if (VarStoreId
== ((EFI_IFR_VARSTORE_EFI
*)OpCodeData
)->VarStoreId
) {
1566 Offset
+= OpCodeHeader
->Length
;
1573 Get width info for one question.
1575 @param OpCodeData The input opcode for one question.
1577 @retval the width info for one question.
1582 IN UINT8
*OpCodeData
1585 UINT8
*NextOpCodeData
;
1587 ASSERT (OpCodeData
!= NULL
);
1589 switch (((EFI_IFR_OP_HEADER
*)OpCodeData
)->OpCode
) {
1590 case EFI_IFR_REF_OP
:
1591 return (UINT16
)sizeof (EFI_HII_REF
);
1593 case EFI_IFR_ONE_OF_OP
:
1594 case EFI_IFR_NUMERIC_OP
:
1595 switch (((EFI_IFR_ONE_OF
*)OpCodeData
)->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1596 case EFI_IFR_NUMERIC_SIZE_1
:
1597 return (UINT16
)sizeof (UINT8
);
1599 case EFI_IFR_NUMERIC_SIZE_2
:
1600 return (UINT16
)sizeof (UINT16
);
1602 case EFI_IFR_NUMERIC_SIZE_4
:
1603 return (UINT16
)sizeof (UINT32
);
1605 case EFI_IFR_NUMERIC_SIZE_8
:
1606 return (UINT16
)sizeof (UINT64
);
1613 case EFI_IFR_ORDERED_LIST_OP
:
1614 NextOpCodeData
= OpCodeData
+ ((EFI_IFR_ORDERED_LIST
*)OpCodeData
)->Header
.Length
;
1616 // OneOfOption must follow the orderedlist opcode.
1618 ASSERT (((EFI_IFR_OP_HEADER
*)NextOpCodeData
)->OpCode
== EFI_IFR_ONE_OF_OPTION_OP
);
1619 switch (((EFI_IFR_ONE_OF_OPTION
*)NextOpCodeData
)->Type
) {
1620 case EFI_IFR_TYPE_NUM_SIZE_8
:
1621 return (UINT16
)sizeof (UINT8
) * ((EFI_IFR_ORDERED_LIST
*)OpCodeData
)->MaxContainers
;
1623 case EFI_IFR_TYPE_NUM_SIZE_16
:
1624 return (UINT16
)sizeof (UINT16
) * ((EFI_IFR_ORDERED_LIST
*)OpCodeData
)->MaxContainers
;
1626 case EFI_IFR_TYPE_NUM_SIZE_32
:
1627 return (UINT16
)sizeof (UINT32
) * ((EFI_IFR_ORDERED_LIST
*)OpCodeData
)->MaxContainers
;
1629 case EFI_IFR_TYPE_NUM_SIZE_64
:
1630 return (UINT16
)sizeof (UINT64
) * ((EFI_IFR_ORDERED_LIST
*)OpCodeData
)->MaxContainers
;
1637 case EFI_IFR_CHECKBOX_OP
:
1638 return (UINT16
)sizeof (BOOLEAN
);
1640 case EFI_IFR_PASSWORD_OP
:
1641 return (UINT16
)((UINTN
)((EFI_IFR_PASSWORD
*)OpCodeData
)->MaxSize
* sizeof (CHAR16
));
1643 case EFI_IFR_STRING_OP
:
1644 return (UINT16
)((UINTN
)((EFI_IFR_STRING
*)OpCodeData
)->MaxSize
* sizeof (CHAR16
));
1646 case EFI_IFR_DATE_OP
:
1647 return (UINT16
)sizeof (EFI_HII_DATE
);
1649 case EFI_IFR_TIME_OP
:
1650 return (UINT16
)sizeof (EFI_HII_TIME
);
1659 Converts all hex string characters in range ['A'..'F'] to ['a'..'f'] for
1660 hex digits that appear between a '=' and a '&' in a config string.
1662 If ConfigString is NULL, then ASSERT().
1664 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
1666 @return Pointer to the Null-terminated Unicode result string.
1671 InternalLowerConfigString (
1672 IN EFI_STRING ConfigString
1678 ASSERT (ConfigString
!= NULL
);
1681 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1683 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
1684 if (*String
== L
'=') {
1686 } else if (*String
== L
'&') {
1688 } else if (Lower
&& (*String
>= L
'A') && (*String
<= L
'F')) {
1689 *String
= (CHAR16
)(*String
- L
'A' + L
'a');
1693 return ConfigString
;
1697 Allocates and returns a Null-terminated Unicode <ConfigHdr> string.
1699 The format of a <ConfigHdr> is as follows:
1701 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
1703 @param[in] OpCodeData The opcode for the storage.
1704 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
1705 that is the routing information PATH. Each byte of
1706 the Device Path associated with DriverHandle is converted
1707 to a 2 Unicode character hexadecimal string.
1709 @retval NULL DriverHandle does not support the Device Path Protocol.
1710 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
1714 ConstructConfigHdr (
1715 IN UINT8
*OpCodeData
,
1716 IN EFI_HANDLE DriverHandle
1720 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1721 UINTN DevicePathSize
;
1723 CHAR16
*ReturnString
;
1732 ASSERT (OpCodeData
!= NULL
);
1734 switch (((EFI_IFR_OP_HEADER
*)OpCodeData
)->OpCode
) {
1735 case EFI_IFR_VARSTORE_OP
:
1736 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE
*)OpCodeData
)->Guid
;
1737 AsciiName
= (CHAR8
*)((EFI_IFR_VARSTORE
*)OpCodeData
)->Name
;
1740 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1741 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_NAME_VALUE
*)OpCodeData
)->Guid
;
1745 case EFI_IFR_VARSTORE_EFI_OP
:
1746 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_EFI
*)OpCodeData
)->Guid
;
1747 AsciiName
= (CHAR8
*)((EFI_IFR_VARSTORE_EFI
*)OpCodeData
)->Name
;
1757 if (AsciiName
!= NULL
) {
1758 NameSize
= AsciiStrSize (AsciiName
);
1759 Name
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1760 ASSERT (Name
!= NULL
);
1761 AsciiStrToUnicodeStrS (AsciiName
, Name
, NameSize
);
1767 // Compute the length of Name in Unicode characters.
1768 // If Name is NULL, then the length is 0.
1772 NameLength
= StrLen (Name
);
1778 // Retrieve DevicePath Protocol associated with DriverHandle
1780 if (DriverHandle
!= NULL
) {
1781 DevicePath
= DevicePathFromHandle (DriverHandle
);
1782 if (DevicePath
== NULL
) {
1787 // Compute the size of the device path in bytes
1789 DevicePathSize
= GetDevicePathSize (DevicePath
);
1793 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
1794 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
1796 MaxLen
= 5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1;
1797 String
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
1798 if (String
== NULL
) {
1803 // Start with L"GUID="
1805 StrCpyS (String
, MaxLen
, L
"GUID=");
1806 ReturnString
= String
;
1807 String
+= StrLen (String
);
1811 // Append Guid converted to <HexCh>32
1813 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
1814 UnicodeValueToStringS (
1816 MaxLen
* sizeof (CHAR16
) - ((UINTN
)String
- (UINTN
)ReturnString
),
1817 PREFIX_ZERO
| RADIX_HEX
,
1821 String
+= StrnLenS (String
, MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
) / sizeof (CHAR16
));
1828 StrCatS (ReturnString
, MaxLen
, L
"&NAME=");
1829 String
+= StrLen (String
);
1833 // Append Name converted to <Char>NameLength
1835 for ( ; *Name
!= L
'\0'; Name
++) {
1836 UnicodeValueToStringS (
1838 MaxLen
* sizeof (CHAR16
) - ((UINTN
)String
- (UINTN
)ReturnString
),
1839 PREFIX_ZERO
| RADIX_HEX
,
1843 String
+= StrnLenS (String
, MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
) / sizeof (CHAR16
));
1850 StrCatS (ReturnString
, MaxLen
, L
"&PATH=");
1851 String
+= StrLen (String
);
1854 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
1856 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
1857 UnicodeValueToStringS (
1859 MaxLen
* sizeof (CHAR16
) - ((UINTN
)String
- (UINTN
)ReturnString
),
1860 PREFIX_ZERO
| RADIX_HEX
,
1864 String
+= StrnLenS (String
, MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
) / sizeof (CHAR16
));
1868 // Null terminate the Unicode string
1873 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1875 return InternalLowerConfigString (ReturnString
);
1879 Generate the Config request element for one question.
1881 @param Name The name info for one question.
1882 @param Offset The offset info for one question.
1883 @param Width The width info for one question.
1885 @return Pointer to the Null-terminated Unicode request element string.
1889 ConstructRequestElement (
1900 // Add <BlockName> length for each Name
1902 // <BlockName> ::= Name + \0
1905 Length
= StrLen (Name
) + 1;
1908 // Add <BlockName> length for each Offset/Width pair
1910 // <BlockName> ::= OFFSET=1234&WIDTH=1234 + \0
1911 // | 7 | 4 | 7 | 4 | 1
1913 Length
= (7 + 4 + 7 + 4 + 1);
1917 // Allocate buffer for the entire <ConfigRequest>
1919 StringPtr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1920 ASSERT (StringPtr
!= NULL
);
1928 (StrLen (Name
) + 1) * sizeof (CHAR16
),
1934 // Append OFFSET=XXXX&WIDTH=YYYY\0
1938 (7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1939 L
"OFFSET=%04X&WIDTH=%04X",
1949 Get string value for question's name field.
1951 @param DatabaseRecord HII_DATABASE_RECORD format string.
1952 @param NameId The string id for the name field.
1954 @retval Name string.
1959 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1960 IN EFI_STRING_ID NameId
1964 CHAR8
*PlatformLanguage
;
1965 CHAR8
*SupportedLanguages
;
1966 CHAR8
*BestLanguage
;
1972 BestLanguage
= NULL
;
1973 PlatformLanguage
= NULL
;
1974 SupportedLanguages
= NULL
;
1976 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
1977 SupportedLanguages
= GetSupportedLanguages (DatabaseRecord
->Handle
);
1980 // Get the best matching language from SupportedLanguages
1982 BestLanguage
= GetBestLanguage (
1984 FALSE
, // RFC 4646 mode
1985 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Highest priority
1986 SupportedLanguages
, // Lowest priority
1989 if (BestLanguage
== NULL
) {
1990 BestLanguage
= AllocateCopyPool (AsciiStrLen ("en-US"), "en-US");
1991 ASSERT (BestLanguage
!= NULL
);
1995 Status
= mPrivate
.HiiString
.GetString (
1996 &mPrivate
.HiiString
,
1998 DatabaseRecord
->Handle
,
2004 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
2008 Name
= AllocateZeroPool (StringSize
);
2013 Status
= mPrivate
.HiiString
.GetString (
2014 &mPrivate
.HiiString
,
2016 DatabaseRecord
->Handle
,
2023 if (EFI_ERROR (Status
)) {
2030 if (SupportedLanguages
!= NULL
) {
2031 FreePool (SupportedLanguages
);
2034 if (BestLanguage
!= NULL
) {
2035 FreePool (BestLanguage
);
2038 if (PlatformLanguage
!= NULL
) {
2039 FreePool (PlatformLanguage
);
2046 Base on the input parameter to generate the ConfigRequest string.
2048 This is a internal function.
2050 @param DatabaseRecord HII_DATABASE_RECORD format string.
2051 @param KeywordStrId Keyword string id.
2052 @param OpCodeData The IFR data for this question.
2053 @param ConfigRequest Return the generate ConfigRequest string.
2055 @retval EFI_SUCCESS Generate ConfigResp string success.
2056 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
2057 @retval EFI_NOT_FOUND Not found the question which use this string id
2058 as the prompt string id.
2061 ExtractConfigRequest (
2062 IN HII_DATABASE_RECORD
*DatabaseRecord
,
2063 IN EFI_STRING_ID KeywordStrId
,
2064 OUT UINT8
**OpCodeData
,
2065 OUT EFI_STRING
*ConfigRequest
2069 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2070 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
2071 EFI_IFR_QUESTION_HEADER
*Header
;
2078 CHAR16
*RequestElement
;
2082 ASSERT (DatabaseRecord
!= NULL
&& OpCodeData
!= NULL
&& ConfigRequest
!= NULL
);
2089 PackageListNode
= DatabaseRecord
->PackageList
;
2092 // Search the languages in the specified packagelist.
2094 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2095 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2097 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2098 if (OpCode
!= NULL
) {
2099 *OpCodeData
= OpCode
;
2100 Header
= (EFI_IFR_QUESTION_HEADER
*)(OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2102 // Header->VarStoreId == 0 means no storage for this question.
2104 ASSERT (Header
->VarStoreId
!= 0);
2105 DEBUG ((DEBUG_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2107 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2108 ASSERT (Storage
!= NULL
);
2110 if (((EFI_IFR_OP_HEADER
*)Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2111 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2113 Offset
= Header
->VarStoreInfo
.VarOffset
;
2114 Width
= GetWidth (OpCode
);
2117 RequestElement
= ConstructRequestElement (Name
, Offset
, Width
);
2118 ConfigHdr
= ConstructConfigHdr (Storage
, DatabaseRecord
->DriverHandle
);
2119 ASSERT (ConfigHdr
!= NULL
);
2121 MaxLen
= StrLen (ConfigHdr
) + 1 + StrLen (RequestElement
) + 1;
2122 *ConfigRequest
= AllocatePool (MaxLen
* sizeof (CHAR16
));
2123 if (*ConfigRequest
== NULL
) {
2124 FreePool (ConfigHdr
);
2125 FreePool (RequestElement
);
2126 return EFI_OUT_OF_RESOURCES
;
2129 StringPtr
= *ConfigRequest
;
2131 StrCpyS (StringPtr
, MaxLen
, ConfigHdr
);
2133 StrCatS (StringPtr
, MaxLen
, L
"&");
2135 StrCatS (StringPtr
, MaxLen
, RequestElement
);
2137 FreePool (ConfigHdr
);
2138 FreePool (RequestElement
);
2144 return EFI_NOT_FOUND
;
2148 Base on the input parameter to generate the ConfigResp string.
2150 This is a internal function.
2152 @param DatabaseRecord HII_DATABASE_RECORD format string.
2153 @param KeywordStrId Keyword string id.
2154 @param ValueElement The value for the question which use keyword string id
2155 as the prompt string id.
2156 @param OpCodeData The IFR data for this question.
2157 @param ConfigResp Return the generate ConfigResp string.
2159 @retval EFI_SUCCESS Generate ConfigResp string success.
2160 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
2161 @retval EFI_NOT_FOUND Not found the question which use this string id
2162 as the prompt string id.
2166 IN HII_DATABASE_RECORD
*DatabaseRecord
,
2167 IN EFI_STRING_ID KeywordStrId
,
2168 IN EFI_STRING ValueElement
,
2169 OUT UINT8
**OpCodeData
,
2170 OUT EFI_STRING
*ConfigResp
2174 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2175 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
2176 EFI_IFR_QUESTION_HEADER
*Header
;
2183 CHAR16
*RequestElement
;
2187 ASSERT ((DatabaseRecord
!= NULL
) && (OpCodeData
!= NULL
) && (ConfigResp
!= NULL
) && (ValueElement
!= NULL
));
2194 PackageListNode
= DatabaseRecord
->PackageList
;
2197 // Search the languages in the specified packagelist.
2199 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2200 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2202 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2203 if (OpCode
!= NULL
) {
2204 *OpCodeData
= OpCode
;
2205 Header
= (EFI_IFR_QUESTION_HEADER
*)(OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2207 // Header->VarStoreId == 0 means no storage for this question.
2209 ASSERT (Header
->VarStoreId
!= 0);
2210 DEBUG ((DEBUG_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2212 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2213 ASSERT (Storage
!= NULL
);
2215 if (((EFI_IFR_OP_HEADER
*)Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2216 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2218 Offset
= Header
->VarStoreInfo
.VarOffset
;
2219 Width
= GetWidth (OpCode
);
2222 RequestElement
= ConstructRequestElement (Name
, Offset
, Width
);
2224 ConfigHdr
= ConstructConfigHdr (Storage
, DatabaseRecord
->DriverHandle
);
2225 ASSERT (ConfigHdr
!= NULL
);
2227 MaxLen
= StrLen (ConfigHdr
) + 1 + StrLen (RequestElement
) + 1 + StrLen (L
"VALUE=") + StrLen (ValueElement
) + 1;
2228 *ConfigResp
= AllocatePool (MaxLen
* sizeof (CHAR16
));
2229 if (*ConfigResp
== NULL
) {
2230 FreePool (ConfigHdr
);
2231 FreePool (RequestElement
);
2232 return EFI_OUT_OF_RESOURCES
;
2235 StringPtr
= *ConfigResp
;
2237 StrCpyS (StringPtr
, MaxLen
, ConfigHdr
);
2239 StrCatS (StringPtr
, MaxLen
, L
"&");
2241 StrCatS (StringPtr
, MaxLen
, RequestElement
);
2243 StrCatS (StringPtr
, MaxLen
, L
"&");
2245 StrCatS (StringPtr
, MaxLen
, L
"VALUE=");
2247 StrCatS (StringPtr
, MaxLen
, ValueElement
);
2249 FreePool (ConfigHdr
);
2250 FreePool (RequestElement
);
2256 return EFI_NOT_FOUND
;
2260 Get the Value section from the Hii driver.
2262 This is a internal function.
2264 @param ConfigRequest The input ConfigRequest string.
2265 @param ValueElement The respond Value section from the hii driver.
2267 @retval Misc value The error status return from ExtractConfig function.
2268 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated
2269 @retval EFI_SUCCESS Get the value section success.
2273 ExtractValueFromDriver (
2274 IN CHAR16
*ConfigRequest
,
2275 OUT CHAR16
**ValueElement
2280 EFI_STRING Progress
;
2284 ASSERT ((ConfigRequest
!= NULL
) && (ValueElement
!= NULL
));
2286 Status
= mPrivate
.ConfigRouting
.ExtractConfig (
2287 &mPrivate
.ConfigRouting
,
2288 (EFI_STRING
)ConfigRequest
,
2292 if (EFI_ERROR (Status
)) {
2297 // Find Value Section and return it.
2299 StringPtr
= StrStr (Result
, L
"&VALUE=");
2300 ASSERT (StringPtr
!= NULL
);
2301 StringEnd
= StrStr (StringPtr
+ 1, L
"&");
2302 if (StringEnd
!= NULL
) {
2306 *ValueElement
= AllocateCopyPool (StrSize (StringPtr
), StringPtr
);
2307 if (*ValueElement
== NULL
) {
2308 return EFI_OUT_OF_RESOURCES
;
2311 if (StringEnd
!= NULL
) {
2321 Get EFI_STRING_ID info from the input device path, namespace and keyword.
2323 This is a internal function.
2325 @param DevicePath Input device path info.
2326 @param NameSpace NameSpace format string.
2327 @param KeywordData Keyword used to get string id.
2328 @param ProgressErr Return extra error type.
2329 @param KeywordStringId Return EFI_STRING_ID.
2330 @param DataBaseRecord DataBase record data for this driver.
2332 @retval EFI_INVALID_PARAMETER Can't find the database record base on the input device path or namespace.
2333 @retval EFI_NOT_FOUND Can't find the EFI_STRING_ID for the keyword.
2334 @retval EFI_SUCCESS Find the EFI_STRING_ID.
2338 GetStringIdFromDatabase (
2339 IN EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
2340 IN CHAR8
**NameSpace
,
2341 IN CHAR16
*KeywordData
,
2342 OUT UINT32
*ProgressErr
,
2343 OUT EFI_STRING_ID
*KeywordStringId
,
2344 OUT HII_DATABASE_RECORD
**DataBaseRecord
2347 HII_DATABASE_RECORD
*Record
;
2349 BOOLEAN FindNameSpace
;
2350 EFI_DEVICE_PATH_PROTOCOL
*DestDevicePath
;
2351 UINT8
*DevicePathPkg
;
2352 UINTN DevicePathSize
;
2354 ASSERT ((NameSpace
!= NULL
) && (KeywordData
!= NULL
) && (ProgressErr
!= NULL
) && (KeywordStringId
!= NULL
) && (DataBaseRecord
!= NULL
));
2356 FindNameSpace
= FALSE
;
2358 if (*DevicePath
!= NULL
) {
2360 // Get DataBaseRecord from device path protocol.
2362 Record
= GetRecordFromDevicePath (*DevicePath
);
2363 if (Record
== NULL
) {
2365 // Can't find the DatabaseRecord base on the input device path info.
2366 // NEED TO CONFIRM the return ProgressErr.
2368 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2369 return EFI_INVALID_PARAMETER
;
2373 // Get string id from the record.
2375 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2376 switch (*ProgressErr
) {
2377 case KEYWORD_HANDLER_NO_ERROR
:
2378 *DataBaseRecord
= Record
;
2381 case KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
:
2382 return EFI_INVALID_PARAMETER
;
2385 ASSERT (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
);
2386 return EFI_NOT_FOUND
;
2390 // Find driver which matches the routing data.
2392 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
2393 Record
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2395 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2396 if (*ProgressErr
== KEYWORD_HANDLER_NO_ERROR
) {
2397 *DataBaseRecord
= Record
;
2399 if ((DevicePathPkg
= Record
->PackageList
->DevicePathPkg
) != NULL
) {
2400 DestDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)(DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
));
2401 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)DestDevicePath
);
2402 *DevicePath
= AllocateCopyPool (DevicePathSize
, DestDevicePath
);
2403 if (*DevicePath
== NULL
) {
2404 return EFI_OUT_OF_RESOURCES
;
2408 // Need to verify this ASSERT.
2414 } else if (*ProgressErr
== KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
) {
2415 return EFI_OUT_OF_RESOURCES
;
2416 } else if (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
) {
2417 FindNameSpace
= TRUE
;
2422 // When PathHdr not input, if ever find the namespace, will return KEYWORD_HANDLER_KEYWORD_NOT_FOUND.
2423 // This is a bit more progress than KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND.
2425 if (FindNameSpace
) {
2426 return EFI_NOT_FOUND
;
2428 return EFI_INVALID_PARAMETER
;
2434 Generate the KeywordResp String.
2436 <KeywordResp> ::= <NameSpaceId><PathHdr>'&'<Keyword>'&VALUE='<Number>['&READONLY']
2438 @param NameSpace NameSpace format string.
2439 @param DevicePath Input device path info.
2440 @param KeywordData Keyword used to get string id.
2441 @param ValueStr The value section for the keyword.
2442 @param ReadOnly Whether this value is readonly.
2443 @param KeywordResp Return the point to the KeywordResp string.
2445 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2446 @retval EFI_SUCCESS Generate the KeywordResp string.
2450 GenerateKeywordResp (
2451 IN CHAR8
*NameSpace
,
2452 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
2453 IN EFI_STRING KeywordData
,
2454 IN EFI_STRING ValueStr
,
2455 IN BOOLEAN ReadOnly
,
2456 OUT EFI_STRING
*KeywordResp
2462 CHAR16
*UnicodeNameSpace
;
2463 UINTN NameSpaceLength
;
2465 ASSERT ((NameSpace
!= NULL
) && (DevicePath
!= NULL
) && (KeywordData
!= NULL
) && (ValueStr
!= NULL
) && (KeywordResp
!= NULL
));
2468 // 1. Calculate the string length.
2471 // 1.1 NameSpaceId size.
2472 // 'NAMESPACE='<String>
2474 NameSpaceLength
= AsciiStrLen (NameSpace
);
2475 RespStrLen
= 10 + NameSpaceLength
;
2476 UnicodeNameSpace
= AllocatePool ((NameSpaceLength
+ 1) * sizeof (CHAR16
));
2477 if (UnicodeNameSpace
== NULL
) {
2478 return EFI_OUT_OF_RESOURCES
;
2481 AsciiStrToUnicodeStrS (NameSpace
, UnicodeNameSpace
, NameSpaceLength
+ 1);
2484 // 1.2 PathHdr size.
2485 // PATH=<UEFI binary Device Path represented as hex number>'&'
2486 // Attention: The output include the '&' at the end.
2490 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
),
2495 RespStrLen
+= StrLen (PathHdr
);
2498 // 1.3 Keyword section.
2499 // 'KEYWORD='<String>[':'<DecCh>(1/4)]
2501 RespStrLen
+= 8 + StrLen (KeywordData
);
2504 // 1.4 Value section.
2505 // ValueStr = '&VALUE='<Number>
2507 RespStrLen
+= StrLen (ValueStr
);
2510 // 1.5 ReadOnly Section.
2518 // 2. Allocate the buffer and create the KeywordResp string include '\0'.
2521 *KeywordResp
= AllocatePool (RespStrLen
* sizeof (CHAR16
));
2522 if (*KeywordResp
== NULL
) {
2523 if (UnicodeNameSpace
!= NULL
) {
2524 FreePool (UnicodeNameSpace
);
2527 return EFI_OUT_OF_RESOURCES
;
2530 RespStr
= *KeywordResp
;
2533 // 2.1 Copy NameSpaceId section.
2535 StrCpyS (RespStr
, RespStrLen
, L
"NAMESPACE=");
2537 StrCatS (RespStr
, RespStrLen
, UnicodeNameSpace
);
2540 // 2.2 Copy PathHdr section.
2542 StrCatS (RespStr
, RespStrLen
, PathHdr
);
2545 // 2.3 Copy Keyword section.
2547 StrCatS (RespStr
, RespStrLen
, L
"KEYWORD=");
2549 StrCatS (RespStr
, RespStrLen
, KeywordData
);
2552 // 2.4 Copy the Value section.
2554 StrCatS (RespStr
, RespStrLen
, ValueStr
);
2557 // 2.5 Copy ReadOnly section if exist.
2560 StrCatS (RespStr
, RespStrLen
, L
"&READONLY");
2563 if (UnicodeNameSpace
!= NULL
) {
2564 FreePool (UnicodeNameSpace
);
2567 if (PathHdr
!= NULL
) {
2575 Merge the KeywordResp String to MultiKeywordResp string.
2577 This is a internal function.
2579 @param MultiKeywordResp The existed multikeywordresp string.
2580 @param KeywordResp The input keywordResp string.
2582 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2583 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2587 MergeToMultiKeywordResp (
2588 IN OUT EFI_STRING
*MultiKeywordResp
,
2589 IN EFI_STRING
*KeywordResp
2592 UINTN MultiKeywordRespLen
;
2593 EFI_STRING StringPtr
;
2595 if (*MultiKeywordResp
== NULL
) {
2596 *MultiKeywordResp
= *KeywordResp
;
2597 *KeywordResp
= NULL
;
2601 MultiKeywordRespLen
= (StrLen (*MultiKeywordResp
) + 1 + StrLen (*KeywordResp
) + 1) * sizeof (CHAR16
);
2603 StringPtr
= ReallocatePool (
2604 StrSize (*MultiKeywordResp
),
2605 MultiKeywordRespLen
,
2608 if (StringPtr
== NULL
) {
2609 return EFI_OUT_OF_RESOURCES
;
2612 *MultiKeywordResp
= StringPtr
;
2614 StrCatS (StringPtr
, MultiKeywordRespLen
/ sizeof (CHAR16
), L
"&");
2616 StrCatS (StringPtr
, MultiKeywordRespLen
/ sizeof (CHAR16
), *KeywordResp
);
2622 Enumerate all keyword in the system.
2624 If error occur when parse one keyword, just skip it and parse the next one.
2626 This is a internal function.
2628 @param NameSpace The namespace used to search the string.
2629 @param MultiResp Return the MultiKeywordResp string for the system.
2630 @param ProgressErr Return the error status.
2632 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2633 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2634 @retval EFI_NOT_FOUND No keyword found.
2638 EnumerateAllKeywords (
2639 IN CHAR8
*NameSpace
,
2640 OUT EFI_STRING
*MultiResp
,
2641 OUT UINT32
*ProgressErr
2645 LIST_ENTRY
*StringLink
;
2646 UINT8
*DevicePathPkg
;
2648 HII_DATABASE_RECORD
*DataBaseRecord
;
2649 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2650 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
2651 CHAR8
*LocalNameSpace
;
2652 EFI_STRING_ID NextStringId
;
2655 CHAR16
*ConfigRequest
;
2656 CHAR16
*ValueElement
;
2657 CHAR16
*KeywordResp
;
2658 CHAR16
*MultiKeywordResp
;
2659 CHAR16
*KeywordData
;
2661 BOOLEAN FindKeywordPackages
;
2663 DataBaseRecord
= NULL
;
2664 Status
= EFI_SUCCESS
;
2665 MultiKeywordResp
= NULL
;
2667 LocalNameSpace
= NULL
;
2668 ConfigRequest
= NULL
;
2669 ValueElement
= NULL
;
2671 FindKeywordPackages
= FALSE
;
2673 if (NameSpace
== NULL
) {
2674 NameSpace
= UEFI_CONFIG_LANG
;
2678 // Find driver which matches the routing data.
2680 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
2681 DataBaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2682 if ((DevicePathPkg
= DataBaseRecord
->PackageList
->DevicePathPkg
) != NULL
) {
2683 DevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2686 PackageListNode
= DataBaseRecord
->PackageList
;
2688 for (StringLink
= PackageListNode
->StringPkgHdr
.ForwardLink
; StringLink
!= &PackageListNode
->StringPkgHdr
; StringLink
= StringLink
->ForwardLink
) {
2689 StringPackage
= CR (StringLink
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
2692 // Check whether has keyword string package.
2694 if (AsciiStrnCmp (NameSpace
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (NameSpace
)) == 0) {
2695 FindKeywordPackages
= TRUE
;
2697 // Keep the NameSpace string.
2699 LocalNameSpace
= AllocateCopyPool (AsciiStrSize (StringPackage
->StringPkgHdr
->Language
), StringPackage
->StringPkgHdr
->Language
);
2700 if (LocalNameSpace
== NULL
) {
2701 return EFI_OUT_OF_RESOURCES
;
2705 // 1 means just begin the enumerate the valid string ids.
2706 // StringId == 1 is always used to save the language for this string package.
2707 // Any valid string start from 2. so here initial it to 1.
2712 // Enumerate all valid stringid in the package.
2714 while ((NextStringId
= GetNextStringId (StringPackage
, NextStringId
, &KeywordData
)) != 0) {
2716 // 3.3 Construct the ConfigRequest string.
2718 Status
= ExtractConfigRequest (DataBaseRecord
, NextStringId
, &OpCode
, &ConfigRequest
);
2719 if (EFI_ERROR (Status
)) {
2721 // If can't generate ConfigRequest for this question, skip it and start the next.
2727 // 3.4 Extract Value for the input keyword.
2729 Status
= ExtractValueFromDriver (ConfigRequest
, &ValueElement
);
2730 if (EFI_ERROR (Status
)) {
2731 if (Status
!= EFI_OUT_OF_RESOURCES
) {
2733 // If can't generate ConfigRequest for this question, skip it and start the next.
2739 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2745 // Extract readonly flag from opcode.
2747 ReadOnly
= ExtractReadOnlyFromOpCode (OpCode
);
2750 // 5. Generate KeywordResp string.
2752 ASSERT (DevicePath
!= NULL
);
2753 Status
= GenerateKeywordResp (LocalNameSpace
, (EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
, KeywordData
, ValueElement
, ReadOnly
, &KeywordResp
);
2754 if (Status
!= EFI_SUCCESS
) {
2756 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2762 // 6. Merge to the MultiKeywordResp string.
2764 Status
= MergeToMultiKeywordResp (&MultiKeywordResp
, &KeywordResp
);
2765 if (EFI_ERROR (Status
)) {
2771 // Clean the temp buffer to later use again.
2773 if (ConfigRequest
!= NULL
) {
2774 FreePool (ConfigRequest
);
2775 ConfigRequest
= NULL
;
2778 if (ValueElement
!= NULL
) {
2779 FreePool (ValueElement
);
2780 ValueElement
= NULL
;
2783 if (KeywordResp
!= NULL
) {
2784 FreePool (KeywordResp
);
2789 if (LocalNameSpace
!= NULL
) {
2790 FreePool (LocalNameSpace
);
2791 LocalNameSpace
= NULL
;
2798 // return the already get MultiKeywordString even error occurred.
2800 if (MultiKeywordResp
== NULL
) {
2801 Status
= EFI_NOT_FOUND
;
2802 if (!FindKeywordPackages
) {
2803 *ProgressErr
= KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
2805 *ProgressErr
= KEYWORD_HANDLER_KEYWORD_NOT_FOUND
;
2808 Status
= EFI_SUCCESS
;
2811 *MultiResp
= MultiKeywordResp
;
2814 if (LocalNameSpace
!= NULL
) {
2815 FreePool (LocalNameSpace
);
2818 if (ConfigRequest
!= NULL
) {
2819 FreePool (ConfigRequest
);
2822 if (ValueElement
!= NULL
) {
2823 FreePool (ValueElement
);
2831 This function accepts a <MultiKeywordResp> formatted string, finds the associated
2832 keyword owners, creates a <MultiConfigResp> string from it and forwards it to the
2833 EFI_HII_ROUTING_PROTOCOL.RouteConfig function.
2835 If there is an issue in resolving the contents of the KeywordString, then the
2836 function returns an error and also sets the Progress and ProgressErr with the
2837 appropriate information about where the issue occurred and additional data about
2838 the nature of the issue.
2840 In the case when KeywordString containing multiple keywords, when an EFI_NOT_FOUND
2841 error is generated during processing the second or later keyword element, the system
2842 storage associated with earlier keywords is not modified. All elements of the
2843 KeywordString must successfully pass all tests for format and access prior to making
2844 any modifications to storage.
2846 In the case when EFI_DEVICE_ERROR is returned from the processing of a KeywordString
2847 containing multiple keywords, the state of storage associated with earlier keywords
2851 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
2853 @param KeywordString A null-terminated string in <MultiKeywordResp> format.
2855 @param Progress On return, points to a character in the KeywordString.
2856 Points to the string's NULL terminator if the request
2857 was successful. Points to the most recent '&' before
2858 the first failing name / value pair (or the beginning
2859 of the string if the failure is in the first name / value
2860 pair) if the request was not successful.
2862 @param ProgressErr If during the processing of the KeywordString there was
2863 a failure, this parameter gives additional information
2864 about the possible source of the problem. The various
2865 errors are defined in "Related Definitions" below.
2868 @retval EFI_SUCCESS The specified action was completed successfully.
2870 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
2871 1. KeywordString is NULL.
2872 2. Parsing of the KeywordString resulted in an
2873 error. See Progress and ProgressErr for more data.
2875 @retval EFI_NOT_FOUND An element of the KeywordString was not found.
2876 See ProgressErr for more data.
2878 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2879 See ProgressErr for more data.
2881 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr
2884 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
2890 EfiConfigKeywordHandlerSetData (
2891 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
2892 IN CONST EFI_STRING KeywordString
,
2893 OUT EFI_STRING
*Progress
,
2894 OUT UINT32
*ProgressErr
2900 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2901 CHAR16
*NextStringPtr
;
2902 CHAR16
*KeywordData
;
2903 EFI_STRING_ID KeywordStringId
;
2905 HII_DATABASE_RECORD
*DataBaseRecord
;
2908 CHAR16
*MultiConfigResp
;
2909 CHAR16
*ValueElement
;
2911 EFI_STRING InternalProgress
;
2913 CHAR16
*KeywordStartPos
;
2915 if ((This
== NULL
) || (Progress
== NULL
) || (ProgressErr
== NULL
) || (KeywordString
== NULL
)) {
2916 return EFI_INVALID_PARAMETER
;
2919 *Progress
= KeywordString
;
2920 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
2921 Status
= EFI_SUCCESS
;
2922 MultiConfigResp
= NULL
;
2926 ValueElement
= NULL
;
2928 KeywordStartPos
= NULL
;
2929 KeywordStringId
= 0;
2932 // Use temp string to avoid changing input string buffer.
2934 TempString
= AllocateCopyPool (StrSize (KeywordString
), KeywordString
);
2935 ASSERT (TempString
!= NULL
);
2936 StringPtr
= TempString
;
2938 while ((StringPtr
!= NULL
) && (*StringPtr
!= L
'\0')) {
2940 // 1. Get NameSpace from NameSpaceId keyword.
2942 Status
= ExtractNameSpace (StringPtr
, &NameSpace
, &NextStringPtr
);
2943 if (EFI_ERROR (Status
)) {
2944 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2948 ASSERT (NameSpace
!= NULL
);
2950 // 1.1 Check whether the input namespace is valid.
2952 if (AsciiStrnCmp (NameSpace
, UEFI_CONFIG_LANG
, AsciiStrLen (UEFI_CONFIG_LANG
)) != 0) {
2953 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2954 Status
= EFI_INVALID_PARAMETER
;
2958 StringPtr
= NextStringPtr
;
2961 // 2. Get possible Device Path info from KeywordString.
2963 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
2964 if (EFI_ERROR (Status
)) {
2965 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2969 StringPtr
= NextStringPtr
;
2972 // 3. Extract keyword from the KeywordRequest string.
2974 KeywordStartPos
= StringPtr
;
2975 Status
= ExtractKeyword (StringPtr
, &KeywordData
, &NextStringPtr
);
2976 if (EFI_ERROR (Status
)) {
2978 // Can't find Keyword base on the input device path info.
2980 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2981 Status
= EFI_INVALID_PARAMETER
;
2985 StringPtr
= NextStringPtr
;
2988 // 4. Extract Value from the KeywordRequest string.
2990 Status
= ExtractValue (StringPtr
, &ValueElement
, &NextStringPtr
);
2991 if (EFI_ERROR (Status
)) {
2993 // Can't find Value base on the input device path info.
2995 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2996 Status
= EFI_INVALID_PARAMETER
;
3000 StringPtr
= NextStringPtr
;
3003 // 5. Find READONLY tag.
3005 if ((StringPtr
!= NULL
) && (StrnCmp (StringPtr
, L
"&READONLY", StrLen (L
"&READONLY")) == 0)) {
3007 StringPtr
+= StrLen (L
"&READONLY");
3013 // 6. Get EFI_STRING_ID for the input keyword.
3015 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
3016 if (EFI_ERROR (Status
)) {
3017 *ProgressErr
= RetVal
;
3022 // 7. Construct the ConfigRequest string.
3024 Status
= ExtractConfigResp (DataBaseRecord
, KeywordStringId
, ValueElement
, &OpCode
, &ConfigResp
);
3025 if (EFI_ERROR (Status
)) {
3030 // 8. Check the readonly flag.
3032 if (ExtractReadOnlyFromOpCode (OpCode
) != ReadOnly
) {
3034 // Extracting readonly flag form opcode and extracting "READONLY" tag form KeywordString should have the same results.
3035 // If not, the input KeywordString must be incorrect, return the error status to caller.
3037 *ProgressErr
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
3038 Status
= EFI_INVALID_PARAMETER
;
3043 *ProgressErr
= KEYWORD_HANDLER_ACCESS_NOT_PERMITTED
;
3044 Status
= EFI_ACCESS_DENIED
;
3049 // 9. Merge to the MultiKeywordResp string.
3051 Status
= MergeToMultiKeywordResp (&MultiConfigResp
, &ConfigResp
);
3052 if (EFI_ERROR (Status
)) {
3057 // 10. Clean the temp buffer point.
3059 FreePool (NameSpace
);
3060 FreePool (DevicePath
);
3061 FreePool (KeywordData
);
3062 FreePool (ValueElement
);
3066 ValueElement
= NULL
;
3067 if (ConfigResp
!= NULL
) {
3068 FreePool (ConfigResp
);
3072 KeywordStartPos
= NULL
;
3076 // 11. Set value to driver.
3078 Status
= mPrivate
.ConfigRouting
.RouteConfig (
3079 &mPrivate
.ConfigRouting
,
3080 (EFI_STRING
)MultiConfigResp
,
3083 if (EFI_ERROR (Status
)) {
3084 Status
= EFI_DEVICE_ERROR
;
3088 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
3091 if (KeywordStartPos
!= NULL
) {
3092 *Progress
= KeywordString
+ (KeywordStartPos
- TempString
);
3094 *Progress
= KeywordString
+ (StringPtr
- TempString
);
3097 ASSERT (TempString
!= NULL
);
3098 FreePool (TempString
);
3099 if (NameSpace
!= NULL
) {
3100 FreePool (NameSpace
);
3103 if (DevicePath
!= NULL
) {
3104 FreePool (DevicePath
);
3107 if (KeywordData
!= NULL
) {
3108 FreePool (KeywordData
);
3111 if (ValueElement
!= NULL
) {
3112 FreePool (ValueElement
);
3115 if (ConfigResp
!= NULL
) {
3116 FreePool (ConfigResp
);
3119 if ((MultiConfigResp
!= NULL
) && (MultiConfigResp
!= ConfigResp
)) {
3120 FreePool (MultiConfigResp
);
3128 This function accepts a <MultiKeywordRequest> formatted string, finds the underlying
3129 keyword owners, creates a <MultiConfigRequest> string from it and forwards it to the
3130 EFI_HII_ROUTING_PROTOCOL.ExtractConfig function.
3132 If there is an issue in resolving the contents of the KeywordString, then the function
3133 returns an EFI_INVALID_PARAMETER and also set the Progress and ProgressErr with the
3134 appropriate information about where the issue occurred and additional data about the
3135 nature of the issue.
3137 In the case when KeywordString is NULL, or contains multiple keywords, or when
3138 EFI_NOT_FOUND is generated while processing the keyword elements, the Results string
3139 contains values returned for all keywords processed prior to the keyword generating the
3140 error but no values for the keyword with error or any following keywords.
3143 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
3145 @param NameSpaceId A null-terminated string containing the platform configuration
3146 language to search through in the system. If a NULL is passed
3147 in, then it is assumed that any platform configuration language
3148 with the prefix of "x-UEFI-" are searched.
3150 @param KeywordString A null-terminated string in <MultiKeywordRequest> format. If a
3151 NULL is passed in the KeywordString field, all of the known
3152 keywords in the system for the NameSpaceId specified are
3153 returned in the Results field.
3155 @param Progress On return, points to a character in the KeywordString. Points
3156 to the string's NULL terminator if the request was successful.
3157 Points to the most recent '&' before the first failing name / value
3158 pair (or the beginning of the string if the failure is in the first
3159 name / value pair) if the request was not successful.
3161 @param ProgressErr If during the processing of the KeywordString there was a
3162 failure, this parameter gives additional information about the
3163 possible source of the problem. See the definitions in SetData()
3164 for valid value definitions.
3166 @param Results A null-terminated string in <MultiKeywordResp> format is returned
3167 which has all the values filled in for the keywords in the
3168 KeywordString. This is a callee-allocated field, and must be freed
3169 by the caller after being used.
3171 @retval EFI_SUCCESS The specified action was completed successfully.
3173 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
3174 1.Progress, ProgressErr, or Results is NULL.
3175 2.Parsing of the KeywordString resulted in an error. See
3176 Progress and ProgressErr for more data.
3179 @retval EFI_NOT_FOUND An element of the KeywordString was not found. See
3180 ProgressErr for more data.
3182 @retval EFI_NOT_FOUND The NamespaceId specified was not found. See ProgressErr
3185 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated. See
3186 ProgressErr for more data.
3188 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr for
3191 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
3197 EfiConfigKeywordHandlerGetData (
3198 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
3199 IN CONST EFI_STRING NameSpaceId OPTIONAL
,
3200 IN CONST EFI_STRING KeywordString OPTIONAL
,
3201 OUT EFI_STRING
*Progress
,
3202 OUT UINT32
*ProgressErr
,
3203 OUT EFI_STRING
*Results
3208 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
3209 HII_DATABASE_RECORD
*DataBaseRecord
;
3211 CHAR16
*NextStringPtr
;
3212 CHAR16
*KeywordData
;
3213 EFI_STRING_ID KeywordStringId
;
3215 CHAR16
*ConfigRequest
;
3216 CHAR16
*ValueElement
;
3219 CHAR16
*KeywordResp
;
3220 CHAR16
*MultiKeywordResp
;
3223 if ((This
== NULL
) || (Progress
== NULL
) || (ProgressErr
== NULL
) || (Results
== NULL
)) {
3224 return EFI_INVALID_PARAMETER
;
3227 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
3228 Status
= EFI_SUCCESS
;
3232 ConfigRequest
= NULL
;
3233 StringPtr
= KeywordString
;
3235 MultiKeywordResp
= NULL
;
3236 KeywordStringId
= 0;
3240 // Use temp string to avoid changing input string buffer.
3242 if (NameSpaceId
!= NULL
) {
3243 TempString
= AllocateCopyPool (StrSize (NameSpaceId
), NameSpaceId
);
3244 ASSERT (TempString
!= NULL
);
3248 // 1. Get NameSpace from NameSpaceId keyword.
3250 Status
= ExtractNameSpace (TempString
, &NameSpace
, NULL
);
3251 if (TempString
!= NULL
) {
3252 FreePool (TempString
);
3256 if (EFI_ERROR (Status
)) {
3257 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3262 // 1.1 Check whether the input namespace is valid.
3264 if (NameSpace
!= NULL
) {
3265 if (AsciiStrnCmp (NameSpace
, UEFI_CONFIG_LANG
, AsciiStrLen (UEFI_CONFIG_LANG
)) != 0) {
3266 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3267 return EFI_INVALID_PARAMETER
;
3271 if (KeywordString
!= NULL
) {
3273 // Use temp string to avoid changing input string buffer.
3275 TempString
= AllocateCopyPool (StrSize (KeywordString
), KeywordString
);
3276 ASSERT (TempString
!= NULL
);
3277 StringPtr
= TempString
;
3279 while (*StringPtr
!= L
'\0') {
3281 // 2. Get possible Device Path info from KeywordString.
3283 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
3284 if (EFI_ERROR (Status
)) {
3285 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3289 StringPtr
= NextStringPtr
;
3292 // 3. Process Keyword section from the input keywordRequest string.
3294 // 3.1 Extract keyword from the KeywordRequest string.
3296 Status
= ExtractKeyword (StringPtr
, &KeywordData
, &NextStringPtr
);
3297 if (EFI_ERROR (Status
)) {
3299 // Can't find Keyword base on the input device path info.
3301 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3302 Status
= EFI_INVALID_PARAMETER
;
3307 // 3.2 Get EFI_STRING_ID for the input keyword.
3309 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
3310 if (EFI_ERROR (Status
)) {
3311 *ProgressErr
= RetVal
;
3316 // 3.3 Construct the ConfigRequest string.
3318 Status
= ExtractConfigRequest (DataBaseRecord
, KeywordStringId
, &OpCode
, &ConfigRequest
);
3319 if (EFI_ERROR (Status
)) {
3324 // 3.4 Extract Value for the input keyword.
3326 Status
= ExtractValueFromDriver (ConfigRequest
, &ValueElement
);
3327 if (EFI_ERROR (Status
)) {
3328 if (Status
!= EFI_OUT_OF_RESOURCES
) {
3329 Status
= EFI_DEVICE_ERROR
;
3335 StringPtr
= NextStringPtr
;
3338 // 4. Process the possible filter section.
3340 RetVal
= ValidateFilter (OpCode
, StringPtr
, &NextStringPtr
, &ReadOnly
);
3341 if (RetVal
!= KEYWORD_HANDLER_NO_ERROR
) {
3342 *ProgressErr
= RetVal
;
3343 Status
= EFI_INVALID_PARAMETER
;
3347 StringPtr
= NextStringPtr
;
3350 // 5. Generate KeywordResp string.
3352 Status
= GenerateKeywordResp (NameSpace
, DevicePath
, KeywordData
, ValueElement
, ReadOnly
, &KeywordResp
);
3353 if (Status
!= EFI_SUCCESS
) {
3358 // 6. Merge to the MultiKeywordResp string.
3360 Status
= MergeToMultiKeywordResp (&MultiKeywordResp
, &KeywordResp
);
3361 if (EFI_ERROR (Status
)) {
3366 // 7. Update return value.
3368 *Results
= MultiKeywordResp
;
3371 // 8. Clean the temp buffer.
3373 FreePool (DevicePath
);
3374 FreePool (KeywordData
);
3375 FreePool (ValueElement
);
3376 FreePool (ConfigRequest
);
3379 ValueElement
= NULL
;
3380 ConfigRequest
= NULL
;
3381 if (KeywordResp
!= NULL
) {
3382 FreePool (KeywordResp
);
3388 // Enumerate all keyword in the system.
3390 Status
= EnumerateAllKeywords (NameSpace
, &MultiKeywordResp
, ProgressErr
);
3391 if (EFI_ERROR (Status
)) {
3395 *Results
= MultiKeywordResp
;
3398 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
3401 *Progress
= KeywordString
+ (StringPtr
- TempString
);
3403 if (TempString
!= NULL
) {
3404 FreePool (TempString
);
3407 if (NameSpace
!= NULL
) {
3408 FreePool (NameSpace
);
3411 if (DevicePath
!= NULL
) {
3412 FreePool (DevicePath
);
3415 if (KeywordData
!= NULL
) {
3416 FreePool (KeywordData
);