2 Implementation of interfaces function for EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL.
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "HiiDatabase.h"
18 extern HII_DATABASE_PRIVATE_DATA mPrivate
;
21 Convert the hex UNICODE %02x encoding of a UEFI device path to binary
22 from <PathHdr> of <MultiKeywordRequest>.
24 This is a internal function.
26 @param String MultiKeywordRequest string.
27 @param DevicePathData Binary of a UEFI device path.
28 @param NextString string follow the possible PathHdr string.
30 @retval EFI_INVALID_PARAMETER The device path is not valid or the incoming parameter is invalid.
31 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
32 @retval EFI_SUCCESS The device path is retrieved and translated to binary format.
33 The Input string not include PathHdr section.
39 OUT UINT8
**DevicePathData
,
40 OUT EFI_STRING
*NextString
45 UINT8
*DevicePathBuffer
;
49 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
51 ASSERT (NextString
!= NULL
&& DevicePathData
!= NULL
);
54 // KeywordRequest == NULL case.
57 *DevicePathData
= NULL
;
65 if (*String
== L
'&') {
70 // Find the 'PATH=' of <PathHdr>.
72 if (StrnCmp (String
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
73 if (StrnCmp (String
, L
"KEYWORD=", StrLen (L
"KEYWORD=")) != 0) {
74 return EFI_INVALID_PARAMETER
;
77 // Not include PathHdr, return success and DevicePath = NULL.
79 *DevicePathData
= NULL
;
86 // Check whether path data does exist.
88 String
+= StrLen (L
"PATH=");
90 return EFI_INVALID_PARAMETER
;
95 // The content between 'PATH=' of <ConfigHdr> and '&' of next element
96 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding
97 // of UEFI device path.
99 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
102 // Save the return next keyword string value.
104 *NextString
= String
;
107 // Check DevicePath Length
109 if (((Length
+ 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
110 return EFI_INVALID_PARAMETER
;
114 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
115 // as the device path resides in RAM memory.
116 // Translate the data into binary.
118 DevicePathBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
119 if (DevicePathBuffer
== NULL
) {
120 return EFI_OUT_OF_RESOURCES
;
124 // Convert DevicePath
126 ZeroMem (TemStr
, sizeof (TemStr
));
127 for (Index
= 0; Index
< Length
; Index
++) {
128 TemStr
[0] = PathHdr
[Index
];
129 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
130 if ((Index
& 1) == 0) {
131 DevicePathBuffer
[Index
/2] = DigitUint8
;
133 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
138 // Validate DevicePath
140 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) DevicePathBuffer
;
141 while (!IsDevicePathEnd (DevicePath
)) {
142 if ((DevicePath
->Type
== 0) || (DevicePath
->SubType
== 0) || (DevicePathNodeLength (DevicePath
) < sizeof (EFI_DEVICE_PATH_PROTOCOL
))) {
144 // Invalid device path
146 FreePool (DevicePathBuffer
);
147 return EFI_INVALID_PARAMETER
;
149 DevicePath
= NextDevicePathNode (DevicePath
);
153 // return the device path
155 *DevicePathData
= DevicePathBuffer
;
161 Get NameSpace from the input NameSpaceId string.
163 This is a internal function.
165 @param String <NameSpaceId> format string.
166 @param NameSpace Return the name space string.
167 @param NextString Return the next string follow namespace.
169 @retval EFI_SUCCESS Get the namespace string success.
170 @retval EFI_INVALID_PARAMETER The NameSpaceId string not follow spec definition.
175 IN EFI_STRING String
,
176 OUT CHAR8
**NameSpace
,
177 OUT EFI_STRING
*NextString
182 ASSERT (NameSpace
!= NULL
);
187 // Input NameSpaceId == NULL
189 if (String
== NULL
) {
191 if (NextString
!= NULL
) {
198 // Skip '&' if exist.
200 if (*String
== L
'&') {
204 if (StrnCmp (String
, L
"NAMESPACE=", StrLen (L
"NAMESPACE=")) != 0) {
205 return EFI_INVALID_PARAMETER
;
207 String
+= StrLen (L
"NAMESPACE=");
209 TmpPtr
= StrStr (String
, L
"&");
210 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 *NameSpace
= AllocatePool (StrLen (String
) + 1);
222 if (*NameSpace
== NULL
) {
223 return EFI_OUT_OF_RESOURCES
;
225 UnicodeStrToAsciiStr (String
, *NameSpace
);
227 if (TmpPtr
!= NULL
) {
235 Get Keyword from the input KeywordRequest string.
237 This is a internal function.
239 @param String KeywordRequestformat string.
240 @param Keyword return the extract keyword string.
241 @param NextString return the next string follow this keyword sectin.
243 @retval EFI_SUCCESS Success to get the keyword string.
244 @retval EFI_INVALID_PARAMETER Parsr the input string return error.
249 IN EFI_STRING String
,
250 OUT EFI_STRING
*Keyword
,
251 OUT EFI_STRING
*NextString
256 ASSERT ((Keyword
!= NULL
) && (NextString
!= NULL
));
261 // KeywordRequest == NULL case.
263 if (String
== NULL
) {
270 // Skip '&' if exist.
272 if (*String
== L
'&') {
276 if (StrnCmp (String
, L
"KEYWORD=", StrLen (L
"KEYWORD=")) != 0) {
277 return EFI_INVALID_PARAMETER
;
280 String
+= StrLen (L
"KEYWORD=");
282 TmpPtr
= StrStr (String
, L
"&");
283 if (TmpPtr
!= NULL
) {
286 *NextString
= String
+ StrLen (String
);
288 *Keyword
= AllocateCopyPool (StrSize (String
), String
);
289 if (*Keyword
== NULL
) {
290 return EFI_OUT_OF_RESOURCES
;
293 if (TmpPtr
!= NULL
) {
301 Get value from the input KeywordRequest string.
303 This is a internal function.
305 @param String KeywordRequestformat string.
306 @param Value return the extract value string.
307 @param NextString return the next string follow this keyword sectin.
309 @retval EFI_SUCCESS Success to get the keyword string.
310 @retval EFI_INVALID_PARAMETER Parsr the input string return error.
315 IN EFI_STRING String
,
316 OUT EFI_STRING
*Value
,
317 OUT EFI_STRING
*NextString
322 ASSERT ((Value
!= NULL
) && (NextString
!= NULL
) && (String
!= NULL
));
325 // Skip '&' if exist.
327 if (*String
== L
'&') {
331 if (StrnCmp (String
, L
"VALUE=", StrLen (L
"VALUE=")) != 0) {
332 return EFI_INVALID_PARAMETER
;
335 String
+= StrLen (L
"VALUE=");
337 TmpPtr
= StrStr (String
, L
"&");
338 if (TmpPtr
!= NULL
) {
341 *NextString
= String
+ StrLen (String
);
343 *Value
= AllocateCopyPool (StrSize (String
), String
);
344 if (*Value
== NULL
) {
345 return EFI_OUT_OF_RESOURCES
;
348 if (TmpPtr
!= NULL
) {
356 Get filter from the input KeywordRequest string.
358 This is a internal function.
360 @param String KeywordRequestformat string.
361 @param FilterFlags return the filter condition.
362 @param NextString return the next string follow this keyword sectin.
364 @retval EFI_SUCCESS Success to get the keyword string.
365 @retval EFI_INVALID_PARAMETER Parsr the input string return error.
370 IN EFI_STRING String
,
371 OUT UINT8
*FilterFlags
,
372 OUT EFI_STRING
*NextString
379 ASSERT ((FilterFlags
!= NULL
) && (NextString
!= NULL
));
382 // String end, no filter section.
384 if (String
== NULL
) {
393 // Skip '&' if exist.
395 if (*String
== L
'&') {
399 if (StrnCmp (String
, L
"ReadOnly", StrLen (L
"ReadOnly")) == 0) {
401 // Find ReadOnly filter.
403 *FilterFlags
|= EFI_KEYWORD_FILTER_READONY
;
404 String
+= StrLen (L
"ReadOnly");
405 } else if (StrnCmp (String
, L
"ReadWrite", StrLen (L
"ReadWrite")) == 0) {
407 // Find ReadWrite filter.
409 *FilterFlags
|= EFI_KEYWORD_FILTER_REAWRITE
;
410 String
+= StrLen (L
"ReadWrite");
411 } else if (StrnCmp (String
, L
"Buffer", StrLen (L
"Buffer")) == 0) {
413 // Find Buffer Filter.
415 *FilterFlags
|= EFI_KEYWORD_FILTER_BUFFER
;
416 String
+= StrLen (L
"Buffer");
417 } else if (StrnCmp (String
, L
"Numeric", StrLen (L
"Numeric")) == 0) {
419 // Find Numeric Filter
421 String
+= StrLen (L
"Numeric");
422 if (*String
!= L
':') {
423 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC
;
428 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_1
;
431 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_2
;
434 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_4
;
437 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_8
;
447 // Check whether other filter item defined by Platform.
449 if ((StrnCmp (String
, L
"&PATH", StrLen (L
"&PATH")) == 0) ||
450 (StrnCmp (String
, L
"&KEYWORD", StrLen (L
"&KEYWORD")) == 0)) {
452 // New KeywordRequest start, no platform defined filter.
456 // Platform defined filter rule.
457 // Just skip platform defined filter rule, return success.
459 PathPtr
= StrStr(String
, L
"&PATH");
460 KeywordPtr
= StrStr(String
, L
"&KEYWORD");
461 if (PathPtr
!= NULL
&& KeywordPtr
!= NULL
) {
463 // If both sections exist, return the first follow string.
465 String
= KeywordPtr
> PathPtr
? PathPtr
: KeywordPtr
;
466 } else if (PathPtr
!= NULL
) {
468 // Should not exist PathPtr != NULL && KeywordPtr == NULL case.
471 } else if (KeywordPtr
!= NULL
) {
473 // Just to the next keyword section.
478 // Only has paltform defined filter section, just skip it.
480 String
+= StrLen (String
);
486 *NextString
= String
;
492 Extract Readonly flag from opcode.
494 This is a internal function.
496 @param OpCodeData Input opcode for this question.
498 @retval TRUE This question is readonly.
499 @retval FALSE This question is not readonly.
503 ExtractReadOnlyFromOpCode (
507 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
509 ASSERT (OpCodeData
!= NULL
);
511 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
513 return (QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) != 0;
517 Create a circuit to check the filter section.
519 This is a internal function.
521 @param OpCodeData The questin binary ifr data.
522 @param KeywordRequest KeywordRequestformat string.
523 @param NextString return the next string follow this keyword sectin.
524 @param ReadOnly Return whether this question is read only.
526 @retval KEYWORD_HANDLER_NO_ERROR Success validate.
527 @retval KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED Validate fail.
532 IN UINT8
*OpCodeData
,
533 IN CHAR16
*KeywordRequest
,
534 OUT CHAR16
**NextString
,
535 OUT BOOLEAN
*ReadOnly
541 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
542 EFI_IFR_OP_HEADER
*OpCodeHdr
;
546 RetVal
= KEYWORD_HANDLER_NO_ERROR
;
547 StringPtr
= KeywordRequest
;
549 OpCodeHdr
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
550 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
551 if (OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) {
552 Flags
= *(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
) + sizeof (EFI_IFR_QUESTION_HEADER
));
558 // Get ReadOnly flag from Question.
560 *ReadOnly
= ExtractReadOnlyFromOpCode(OpCodeData
);
562 while (ExtractFilter (StringPtr
, &FilterFlags
, &NextFilter
)) {
563 switch (FilterFlags
) {
564 case EFI_KEYWORD_FILTER_READONY
:
565 if ((QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) == 0) {
566 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
571 case EFI_KEYWORD_FILTER_REAWRITE
:
572 if ((QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) != 0) {
573 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
578 case EFI_KEYWORD_FILTER_BUFFER
:
580 // Only these three opcode use numeric value type.
582 if (OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_CHECKBOX_OP
) {
583 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
588 case EFI_KEYWORD_FILTER_NUMERIC
:
589 if (OpCodeHdr
->OpCode
!= EFI_IFR_ONE_OF_OP
&& OpCodeHdr
->OpCode
!= EFI_IFR_NUMERIC_OP
&& OpCodeHdr
->OpCode
!= EFI_IFR_CHECKBOX_OP
) {
590 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
595 case EFI_KEYWORD_FILTER_NUMERIC_1
:
596 case EFI_KEYWORD_FILTER_NUMERIC_2
:
597 case EFI_KEYWORD_FILTER_NUMERIC_4
:
598 case EFI_KEYWORD_FILTER_NUMERIC_8
:
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
;
605 // For numeric and oneof, it has flags field to specify the detail numeric type.
607 if (OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) {
608 switch (Flags
& EFI_IFR_NUMERIC_SIZE
) {
609 case EFI_IFR_NUMERIC_SIZE_1
:
610 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_1
) {
611 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
616 case EFI_IFR_NUMERIC_SIZE_2
:
617 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_2
) {
618 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
623 case EFI_IFR_NUMERIC_SIZE_4
:
624 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_4
) {
625 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
630 case EFI_IFR_NUMERIC_SIZE_8
:
631 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_8
) {
632 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
650 // Jump to the next filter.
652 StringPtr
= NextFilter
;
657 // The current filter which is processing.
659 *NextString
= StringPtr
;
665 Get HII_DATABASE_RECORD from the input device path info.
667 This is a internal function.
669 @param DevicePath UEFI device path protocol.
671 @retval Internal data base record.
674 HII_DATABASE_RECORD
*
675 GetRecordFromDevicePath (
676 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
680 UINT8
*DevicePathPkg
;
681 UINT8
*CurrentDevicePath
;
682 UINTN DevicePathSize
;
683 HII_DATABASE_RECORD
*TempDatabase
;
685 ASSERT (DevicePath
!= NULL
);
687 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
688 TempDatabase
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
689 DevicePathPkg
= TempDatabase
->PackageList
->DevicePathPkg
;
690 if (DevicePathPkg
!= NULL
) {
691 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
692 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
693 if ((CompareMem (DevicePath
, CurrentDevicePath
, DevicePathSize
) == 0)) {
703 Calculate the size of StringSrc and output it. Also copy string text from src
706 This is a internal function.
708 @param StringSrc Points to current null-terminated string.
709 @param BufferSize Length of the buffer.
710 @param StringDest Buffer to store the string text.
712 @retval EFI_SUCCESS The string text was outputed successfully.
713 @retval EFI_OUT_OF_RESOURCES Out of resource.
717 GetUnicodeStringTextAndSize (
719 OUT UINTN
*BufferSize
,
720 OUT EFI_STRING
*StringDest
726 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
&& StringDest
!= NULL
);
728 StringSize
= sizeof (CHAR16
);
729 StringPtr
= StringSrc
;
730 while (ReadUnaligned16 ((UINT16
*) StringPtr
) != 0) {
731 StringSize
+= sizeof (CHAR16
);
732 StringPtr
+= sizeof (CHAR16
);
735 *StringDest
= AllocatePool (StringSize
);
736 if (*StringDest
== NULL
) {
737 return EFI_OUT_OF_RESOURCES
;
740 CopyMem (*StringDest
, StringSrc
, StringSize
);
742 *BufferSize
= StringSize
;
747 Find the string id for the input keyword.
749 @param StringPackage Hii string package instance.
750 @param KeywordValue Input keyword value.
751 @param StringId The string's id, which is unique within PackageList.
754 @retval EFI_SUCCESS The string text and font is retrieved
756 @retval EFI_NOT_FOUND The specified text or font info can not be found
758 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
762 GetStringIdFromString (
763 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
764 IN CHAR16
*KeywordValue
,
765 OUT EFI_STRING_ID
*StringId
769 EFI_STRING_ID CurrentStringId
;
772 UINT8
*StringTextPtr
;
777 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
781 CHAR8
*AsciiKeywordValue
;
784 ASSERT (StringPackage
!= NULL
&& KeywordValue
!= NULL
&& StringId
!= NULL
);
785 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
788 Status
= EFI_SUCCESS
;
790 BlockHdr
= StringPackage
->StringBlock
;
795 // Make a ascii keyword value for later use.
797 AsciiKeywordValue
= AllocatePool (StrLen (KeywordValue
) + 1);
798 if (AsciiKeywordValue
== NULL
) {
799 return EFI_OUT_OF_RESOURCES
;
801 UnicodeStrToAsciiStr(KeywordValue
, AsciiKeywordValue
);
803 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
805 case EFI_HII_SIBT_STRING_SCSU
:
806 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
807 StringTextPtr
= BlockHdr
+ Offset
;
808 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
809 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
810 *StringId
= CurrentStringId
;
816 case EFI_HII_SIBT_STRING_SCSU_FONT
:
817 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
818 StringTextPtr
= BlockHdr
+ Offset
;
819 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
820 *StringId
= CurrentStringId
;
823 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
827 case EFI_HII_SIBT_STRINGS_SCSU
:
828 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
829 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
830 BlockSize
+= StringTextPtr
- BlockHdr
;
832 for (Index
= 0; Index
< StringCount
; Index
++) {
833 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
834 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
835 *StringId
= CurrentStringId
;
838 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
843 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
846 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
849 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
850 BlockSize
+= StringTextPtr
- BlockHdr
;
852 for (Index
= 0; Index
< StringCount
; Index
++) {
853 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
854 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
855 *StringId
= CurrentStringId
;
858 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
863 case EFI_HII_SIBT_STRING_UCS2
:
864 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
865 StringTextPtr
= BlockHdr
+ Offset
;
867 // Use StringSize to store the size of the specified string, including the NULL
870 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
871 if (EFI_ERROR (Status
)) {
875 if (StrCmp(KeywordValue
, String
) == 0) {
876 *StringId
= CurrentStringId
;
879 BlockSize
+= Offset
+ StringSize
;
883 case EFI_HII_SIBT_STRING_UCS2_FONT
:
884 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
885 StringTextPtr
= BlockHdr
+ Offset
;
887 // Use StringSize to store the size of the specified string, including the NULL
890 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
891 if (EFI_ERROR (Status
)) {
895 if (StrCmp(KeywordValue
, String
) == 0) {
896 *StringId
= CurrentStringId
;
899 BlockSize
+= Offset
+ StringSize
;
903 case EFI_HII_SIBT_STRINGS_UCS2
:
904 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
905 StringTextPtr
= BlockHdr
+ Offset
;
907 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
908 for (Index
= 0; Index
< StringCount
; Index
++) {
909 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
910 if (EFI_ERROR (Status
)) {
914 BlockSize
+= StringSize
;
915 if (StrCmp(KeywordValue
, String
) == 0) {
916 *StringId
= CurrentStringId
;
919 StringTextPtr
= StringTextPtr
+ StringSize
;
924 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
925 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
926 StringTextPtr
= BlockHdr
+ Offset
;
930 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
933 for (Index
= 0; Index
< StringCount
; Index
++) {
934 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
935 if (EFI_ERROR (Status
)) {
939 BlockSize
+= StringSize
;
940 if (StrCmp(KeywordValue
, String
) == 0) {
941 *StringId
= CurrentStringId
;
944 StringTextPtr
= StringTextPtr
+ StringSize
;
949 case EFI_HII_SIBT_DUPLICATE
:
950 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
954 case EFI_HII_SIBT_SKIP1
:
955 SkipCount
= (UINT16
) (*(UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
956 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
957 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
960 case EFI_HII_SIBT_SKIP2
:
961 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
962 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
963 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
966 case EFI_HII_SIBT_EXT1
:
969 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
972 BlockSize
+= Length8
;
975 case EFI_HII_SIBT_EXT2
:
976 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
977 BlockSize
+= Ext2
.Length
;
980 case EFI_HII_SIBT_EXT4
:
983 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
987 BlockSize
+= Length32
;
994 if (String
!= NULL
) {
999 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
1002 Status
= EFI_NOT_FOUND
;
1005 if (AsciiKeywordValue
!= NULL
) {
1006 FreePool (AsciiKeywordValue
);
1008 if (String
!= NULL
) {
1015 Find the next valid string id for the input string id.
1017 @param StringPackage Hii string package instance.
1018 @param StringId The current string id which is already got.
1019 1 means just begin to get the string id.
1020 @param KeywordValue Return the string for the next string id.
1023 @retval EFI_STRING_ID Not 0 means a valid stringid found.
1024 0 means not found a valid string id.
1028 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
1029 IN EFI_STRING_ID StringId
,
1030 OUT EFI_STRING
*KeywordValue
1034 EFI_STRING_ID CurrentStringId
;
1037 UINT8
*StringTextPtr
;
1042 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
1048 ASSERT (StringPackage
!= NULL
);
1049 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
1051 CurrentStringId
= 1;
1056 // Parse the string blocks to get the string text and font.
1058 BlockHdr
= StringPackage
->StringBlock
;
1061 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
1062 switch (*BlockHdr
) {
1063 case EFI_HII_SIBT_STRING_SCSU
:
1064 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
1065 StringTextPtr
= BlockHdr
+ Offset
;
1068 *KeywordValue
= AllocatePool (AsciiStrSize ((CHAR8
*) StringTextPtr
) * sizeof (CHAR16
));
1069 if (*KeywordValue
== NULL
) {
1072 AsciiStrToUnicodeStr ((CHAR8
*) StringTextPtr
, *KeywordValue
);
1073 return CurrentStringId
;
1074 } else if (CurrentStringId
== StringId
) {
1078 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1082 case EFI_HII_SIBT_STRING_SCSU_FONT
:
1083 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
1084 StringTextPtr
= BlockHdr
+ Offset
;
1087 *KeywordValue
= AllocatePool (AsciiStrSize ((CHAR8
*) StringTextPtr
) * sizeof (CHAR16
));
1088 if (*KeywordValue
== NULL
) {
1091 AsciiStrToUnicodeStr ((CHAR8
*) StringTextPtr
, *KeywordValue
);
1092 return CurrentStringId
;
1093 } else if (CurrentStringId
== StringId
) {
1097 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1101 case EFI_HII_SIBT_STRINGS_SCSU
:
1102 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1103 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
1104 BlockSize
+= StringTextPtr
- BlockHdr
;
1106 for (Index
= 0; Index
< StringCount
; Index
++) {
1108 *KeywordValue
= AllocatePool (AsciiStrSize ((CHAR8
*) StringTextPtr
) * sizeof (CHAR16
));
1109 if (*KeywordValue
== NULL
) {
1112 AsciiStrToUnicodeStr ((CHAR8
*) StringTextPtr
, *KeywordValue
);
1113 return CurrentStringId
;
1114 } else if (CurrentStringId
== StringId
) {
1118 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1119 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1124 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
1127 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1130 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
1131 BlockSize
+= StringTextPtr
- BlockHdr
;
1133 for (Index
= 0; Index
< StringCount
; Index
++) {
1135 *KeywordValue
= AllocatePool (AsciiStrSize ((CHAR8
*) StringTextPtr
) * sizeof (CHAR16
));
1136 if (*KeywordValue
== NULL
) {
1139 AsciiStrToUnicodeStr ((CHAR8
*) StringTextPtr
, *KeywordValue
);
1140 return CurrentStringId
;
1141 } else if (CurrentStringId
== StringId
) {
1145 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1146 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1151 case EFI_HII_SIBT_STRING_UCS2
:
1152 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
1153 StringTextPtr
= BlockHdr
+ Offset
;
1155 // Use StringSize to store the size of the specified string, including the NULL
1158 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1159 if (FindString
&& (String
!= NULL
) && (*String
!= L
'\0')) {
1161 // String protocol use this type for the string id which has value for other package.
1162 // It will allocate an empty string block for this string id. so here we also check
1163 // *String != L'\0' to prohibit this case.
1165 *KeywordValue
= String
;
1166 return CurrentStringId
;
1167 } else if (CurrentStringId
== StringId
) {
1171 BlockSize
+= Offset
+ StringSize
;
1175 case EFI_HII_SIBT_STRING_UCS2_FONT
:
1176 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
1177 StringTextPtr
= BlockHdr
+ Offset
;
1179 // Use StringSize to store the size of the specified string, including the NULL
1182 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1184 *KeywordValue
= String
;
1185 return CurrentStringId
;
1186 } else if (CurrentStringId
== StringId
) {
1190 BlockSize
+= Offset
+ StringSize
;
1194 case EFI_HII_SIBT_STRINGS_UCS2
:
1195 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
1196 StringTextPtr
= BlockHdr
+ Offset
;
1197 BlockSize
+= Offset
;
1198 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1199 for (Index
= 0; Index
< StringCount
; Index
++) {
1200 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1203 *KeywordValue
= String
;
1204 return CurrentStringId
;
1205 } else if (CurrentStringId
== StringId
) {
1209 BlockSize
+= StringSize
;
1210 StringTextPtr
= StringTextPtr
+ StringSize
;
1215 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
1216 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
1217 StringTextPtr
= BlockHdr
+ Offset
;
1218 BlockSize
+= Offset
;
1221 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1224 for (Index
= 0; Index
< StringCount
; Index
++) {
1225 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1227 *KeywordValue
= String
;
1228 return CurrentStringId
;
1229 } else if (CurrentStringId
== StringId
) {
1233 BlockSize
+= StringSize
;
1234 StringTextPtr
= StringTextPtr
+ StringSize
;
1239 case EFI_HII_SIBT_DUPLICATE
:
1240 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
1244 case EFI_HII_SIBT_SKIP1
:
1245 SkipCount
= (UINT16
) (*(UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
1246 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
1247 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
1250 case EFI_HII_SIBT_SKIP2
:
1251 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1252 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
1253 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
1256 case EFI_HII_SIBT_EXT1
:
1259 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1262 BlockSize
+= Length8
;
1265 case EFI_HII_SIBT_EXT2
:
1266 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1267 BlockSize
+= Ext2
.Length
;
1270 case EFI_HII_SIBT_EXT4
:
1273 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1277 BlockSize
+= Length32
;
1284 if (String
!= NULL
) {
1289 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
1296 Get string package from the input NameSpace string.
1298 This is a internal function.
1300 @param DatabaseRecord HII_DATABASE_RECORD format string.
1301 @param NameSpace NameSpace format string.
1302 @param KeywordValue Keyword value.
1303 @param StringId String Id for this keyword.
1305 @retval KEYWORD_HANDLER_NO_ERROR Get String id succes.
1306 @retval KEYWORD_HANDLER_KEYWORD_NOT_FOUND Not found the string id in the string package.
1307 @retval KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND Not found the string package for this namespace.
1308 @retval KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR Out of resource error.
1312 GetStringIdFromRecord (
1313 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1314 IN CHAR8
**NameSpace
,
1315 IN CHAR16
*KeywordValue
,
1316 OUT EFI_STRING_ID
*StringId
1320 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1321 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1326 ASSERT (DatabaseRecord
!= NULL
&& NameSpace
!= NULL
&& KeywordValue
!= NULL
);
1328 PackageListNode
= DatabaseRecord
->PackageList
;
1329 RetVal
= KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
1331 if (*NameSpace
!= NULL
) {
1334 Name
= UEFI_CONFIG_LANG
;
1337 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->StringPkgHdr
; Link
= Link
->ForwardLink
) {
1338 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1340 if (AsciiStrnCmp(Name
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (Name
)) == 0) {
1341 Status
= GetStringIdFromString (StringPackage
, KeywordValue
, StringId
);
1342 if (EFI_ERROR (Status
)) {
1343 return KEYWORD_HANDLER_KEYWORD_NOT_FOUND
;
1345 if (*NameSpace
== NULL
) {
1346 *NameSpace
= AllocateCopyPool (AsciiStrSize (StringPackage
->StringPkgHdr
->Language
), StringPackage
->StringPkgHdr
->Language
);
1347 if (*NameSpace
== NULL
) {
1348 return KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
1351 return KEYWORD_HANDLER_NO_ERROR
;
1360 Tell whether this Operand is an Statement OpCode.
1362 @param Operand Operand of an IFR OpCode.
1364 @retval TRUE This is an Statement OpCode.
1365 @retval FALSE Not an Statement OpCode.
1373 if ((Operand
== EFI_IFR_SUBTITLE_OP
) ||
1374 (Operand
== EFI_IFR_TEXT_OP
) ||
1375 (Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1376 (Operand
== EFI_IFR_REF_OP
) ||
1377 (Operand
== EFI_IFR_ACTION_OP
) ||
1378 (Operand
== EFI_IFR_NUMERIC_OP
) ||
1379 (Operand
== EFI_IFR_ORDERED_LIST_OP
) ||
1380 (Operand
== EFI_IFR_CHECKBOX_OP
) ||
1381 (Operand
== EFI_IFR_STRING_OP
) ||
1382 (Operand
== EFI_IFR_PASSWORD_OP
) ||
1383 (Operand
== EFI_IFR_DATE_OP
) ||
1384 (Operand
== EFI_IFR_TIME_OP
) ||
1385 (Operand
== EFI_IFR_GUID_OP
) ||
1386 (Operand
== EFI_IFR_ONE_OF_OP
)) {
1394 Tell whether this Operand is an Statement OpCode.
1396 @param Operand Operand of an IFR OpCode.
1398 @retval TRUE This is an Statement OpCode.
1399 @retval FALSE Not an Statement OpCode.
1407 if ((Operand
== EFI_IFR_VARSTORE_OP
) ||
1408 (Operand
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) ||
1409 (Operand
== EFI_IFR_VARSTORE_EFI_OP
)) {
1417 Base on the prompt string id to find the question.
1419 @param FormPackage The input form package.
1420 @param KeywordStrId The input prompt string id for one question.
1422 @retval the opcode for the question.
1426 FindQuestionFromStringId (
1427 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1428 IN EFI_STRING_ID KeywordStrId
1433 EFI_IFR_STATEMENT_HEADER
*StatementHeader
;
1434 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1437 ASSERT (FormPackage
!= NULL
);
1439 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1441 while (Offset
< FormDataLen
) {
1442 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1443 OpCodeHeader
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
1445 if (IsStatementOpCode(OpCodeHeader
->OpCode
)) {
1446 StatementHeader
= (EFI_IFR_STATEMENT_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
1447 if (StatementHeader
->Prompt
== KeywordStrId
) {
1452 Offset
+= OpCodeHeader
->Length
;
1459 Base on the varstore id to find the storage info.
1461 @param FormPackage The input form package.
1462 @param VarStoreId The input storage id.
1464 @retval the opcode for the storage.
1468 FindStorageFromVarId (
1469 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1470 IN EFI_VARSTORE_ID VarStoreId
1475 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1478 ASSERT (FormPackage
!= NULL
);
1480 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1482 while (Offset
< FormDataLen
) {
1483 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1484 OpCodeHeader
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
1486 if (IsStorageOpCode(OpCodeHeader
->OpCode
)) {
1487 switch (OpCodeHeader
->OpCode
) {
1488 case EFI_IFR_VARSTORE_OP
:
1489 if (VarStoreId
== ((EFI_IFR_VARSTORE
*) OpCodeData
)->VarStoreId
) {
1494 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1495 if (VarStoreId
== ((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->VarStoreId
) {
1500 case EFI_IFR_VARSTORE_EFI_OP
:
1501 if (VarStoreId
== ((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->VarStoreId
) {
1511 Offset
+= OpCodeHeader
->Length
;
1518 Get width info for one question.
1520 @param OpCodeData The input opcode for one question.
1522 @retval the width info for one question.
1527 IN UINT8
*OpCodeData
1530 UINT8
*NextOpCodeData
;
1532 ASSERT (OpCodeData
!= NULL
);
1534 switch (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
) {
1535 case EFI_IFR_REF_OP
:
1536 return (UINT16
) sizeof (EFI_HII_REF
);
1538 case EFI_IFR_ONE_OF_OP
:
1539 case EFI_IFR_NUMERIC_OP
:
1540 switch (((EFI_IFR_ONE_OF
*) OpCodeData
)->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1541 case EFI_IFR_NUMERIC_SIZE_1
:
1542 return (UINT16
) sizeof (UINT8
);
1544 case EFI_IFR_NUMERIC_SIZE_2
:
1545 return (UINT16
) sizeof (UINT16
);
1547 case EFI_IFR_NUMERIC_SIZE_4
:
1548 return (UINT16
) sizeof (UINT32
);
1550 case EFI_IFR_NUMERIC_SIZE_8
:
1551 return (UINT16
) sizeof (UINT64
);
1558 case EFI_IFR_ORDERED_LIST_OP
:
1559 NextOpCodeData
= OpCodeData
+ ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->Header
.Length
;
1561 // OneOfOption must follow the orderedlist opcode.
1563 ASSERT (((EFI_IFR_OP_HEADER
*) NextOpCodeData
)->OpCode
== EFI_IFR_ONE_OF_OPTION_OP
);
1564 switch (((EFI_IFR_ONE_OF_OPTION
*) NextOpCodeData
)->Type
) {
1565 case EFI_IFR_TYPE_NUM_SIZE_8
:
1566 return (UINT16
) sizeof (UINT8
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1568 case EFI_IFR_TYPE_NUM_SIZE_16
:
1569 return (UINT16
) sizeof (UINT16
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1571 case EFI_IFR_TYPE_NUM_SIZE_32
:
1572 return (UINT16
) sizeof (UINT32
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1574 case EFI_IFR_TYPE_NUM_SIZE_64
:
1575 return (UINT16
) sizeof (UINT64
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1582 case EFI_IFR_CHECKBOX_OP
:
1583 return (UINT16
) sizeof (BOOLEAN
);
1585 case EFI_IFR_PASSWORD_OP
:
1586 case EFI_IFR_STRING_OP
:
1587 return (UINT16
)((UINTN
) ((EFI_IFR_STRING
*) OpCodeData
)->MaxSize
* sizeof (CHAR16
));
1589 case EFI_IFR_DATE_OP
:
1590 return (UINT16
) sizeof (EFI_HII_DATE
);
1592 case EFI_IFR_TIME_OP
:
1593 return (UINT16
) sizeof (EFI_HII_TIME
);
1602 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
1603 hex digits that appear between a '=' and a '&' in a config string.
1605 If ConfigString is NULL, then ASSERT().
1607 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
1609 @return Pointer to the Null-terminated Unicode result string.
1614 InternalLowerConfigString (
1615 IN EFI_STRING ConfigString
1621 ASSERT (ConfigString
!= NULL
);
1624 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1626 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
1627 if (*String
== L
'=') {
1629 } else if (*String
== L
'&') {
1631 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
1632 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
1636 return ConfigString
;
1640 Allocates and returns a Null-terminated Unicode <ConfigHdr> string.
1642 The format of a <ConfigHdr> is as follows:
1644 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
1646 @param[in] OpCodeData The opcode for the storage.
1647 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
1648 that is the routing information PATH. Each byte of
1649 the Device Path associated with DriverHandle is converted
1650 to a 2 Unicode character hexidecimal string.
1652 @retval NULL DriverHandle does not support the Device Path Protocol.
1653 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
1657 ConstructConfigHdr (
1658 IN UINT8
*OpCodeData
,
1659 IN EFI_HANDLE DriverHandle
1663 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1664 UINTN DevicePathSize
;
1666 CHAR16
*ReturnString
;
1674 ASSERT (OpCodeData
!= NULL
);
1676 switch (((EFI_IFR_OP_HEADER
*)OpCodeData
)->OpCode
) {
1677 case EFI_IFR_VARSTORE_OP
:
1678 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE
*) OpCodeData
)->Guid
;
1679 AsciiName
= (CHAR8
*) ((EFI_IFR_VARSTORE
*) OpCodeData
)->Name
;
1682 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1683 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->Guid
;
1687 case EFI_IFR_VARSTORE_EFI_OP
:
1688 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Guid
;
1689 AsciiName
= (CHAR8
*) ((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Name
;
1699 if (AsciiName
!= NULL
) {
1700 Name
= AllocateZeroPool (AsciiStrSize (AsciiName
) * 2);
1701 ASSERT (Name
!= NULL
);
1702 AsciiStrToUnicodeStr(AsciiName
, Name
);
1708 // Compute the length of Name in Unicode characters.
1709 // If Name is NULL, then the length is 0.
1713 NameLength
= StrLen (Name
);
1719 // Retrieve DevicePath Protocol associated with DriverHandle
1721 if (DriverHandle
!= NULL
) {
1722 DevicePath
= DevicePathFromHandle (DriverHandle
);
1723 if (DevicePath
== NULL
) {
1727 // Compute the size of the device path in bytes
1729 DevicePathSize
= GetDevicePathSize (DevicePath
);
1733 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
1734 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
1736 MaxLen
= 5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1;
1737 String
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
1738 if (String
== NULL
) {
1743 // Start with L"GUID="
1745 StrCpyS (String
, MaxLen
, L
"GUID=");
1746 ReturnString
= String
;
1747 String
+= StrLen (String
);
1751 // Append Guid converted to <HexCh>32
1753 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
1754 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
1761 StrCpyS (String
, MaxLen
, L
"&NAME=");
1762 String
+= StrLen (String
);
1766 // Append Name converted to <Char>NameLength
1768 for (; *Name
!= L
'\0'; Name
++) {
1769 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
1776 StrCpyS (String
, MaxLen
, L
"&PATH=");
1777 String
+= StrLen (String
);
1780 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
1782 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
1783 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
1787 // Null terminate the Unicode string
1792 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1794 return InternalLowerConfigString (ReturnString
);
1798 Generate the Config request element for one question.
1800 @param Name The name info for one question.
1801 @param Offset The offset info for one question.
1802 @param Width The width info for one question.
1804 @return Pointer to the Null-terminated Unicode request element string.
1808 ConstructRequestElement (
1819 // Add <BlockName> length for each Name
1821 // <BlockName> ::= Name + \0
1824 Length
= StrLen (Name
) + 1;
1827 // Add <BlockName> length for each Offset/Width pair
1829 // <BlockName> ::= OFFSET=1234&WIDTH=1234 + \0
1830 // | 7 | 4 | 7 | 4 | 1
1832 Length
= (7 + 4 + 7 + 4 + 1);
1836 // Allocate buffer for the entire <ConfigRequest>
1838 StringPtr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1839 ASSERT (StringPtr
!= NULL
);
1847 (StrLen (Name
) + 1) * sizeof (CHAR16
),
1853 // Append OFFSET=XXXX&WIDTH=YYYY\0
1857 (7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1858 L
"OFFSET=%04X&WIDTH=%04X",
1868 Get string value for question's name field.
1870 @param DatabaseRecord HII_DATABASE_RECORD format string.
1871 @param NameId The string id for the name field.
1873 @retval Name string.
1878 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1879 IN EFI_STRING_ID NameId
1883 CHAR8
*PlatformLanguage
;
1884 CHAR8
*SupportedLanguages
;
1885 CHAR8
*BestLanguage
;
1891 BestLanguage
= NULL
;
1892 PlatformLanguage
= NULL
;
1893 SupportedLanguages
= NULL
;
1895 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
1896 SupportedLanguages
= GetSupportedLanguages(DatabaseRecord
->Handle
);
1899 // Get the best matching language from SupportedLanguages
1901 BestLanguage
= GetBestLanguage (
1903 FALSE
, // RFC 4646 mode
1904 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Highest priority
1905 SupportedLanguages
, // Lowest priority
1908 if (BestLanguage
== NULL
) {
1909 BestLanguage
= AllocateCopyPool (AsciiStrLen ("en-US"), "en-US");
1910 ASSERT (BestLanguage
!= NULL
);
1914 Status
= mPrivate
.HiiString
.GetString (
1915 &mPrivate
.HiiString
,
1917 DatabaseRecord
->Handle
,
1923 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1927 Name
= AllocateZeroPool (StringSize
);
1932 Status
= mPrivate
.HiiString
.GetString (
1933 &mPrivate
.HiiString
,
1935 DatabaseRecord
->Handle
,
1942 if (EFI_ERROR (Status
)) {
1949 if (SupportedLanguages
!= NULL
) {
1950 FreePool(SupportedLanguages
);
1952 if (BestLanguage
!= NULL
) {
1953 FreePool (BestLanguage
);
1955 if (PlatformLanguage
!= NULL
) {
1956 FreePool (PlatformLanguage
);
1963 Base on the input parameter to generate the ConfigRequest string.
1965 This is a internal function.
1967 @param DatabaseRecord HII_DATABASE_RECORD format string.
1968 @param KeywordStrId Keyword string id.
1969 @param OpCodeData The IFR data for this question.
1970 @param ConfigRequest Return the generate ConfigRequest string.
1972 @retval EFI_SUCCESS Generate ConfigResp string success.
1973 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
1974 @retval EFI_NOT_FOUND Not found the question which use this string id
1975 as the prompt string id.
1978 ExtractConfigRequest (
1979 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1980 IN EFI_STRING_ID KeywordStrId
,
1981 OUT UINT8
**OpCodeData
,
1982 OUT EFI_STRING
*ConfigRequest
1986 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1987 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
1988 EFI_IFR_QUESTION_HEADER
*Header
;
1995 CHAR16
*RequestElement
;
1999 ASSERT (DatabaseRecord
!= NULL
&& OpCodeData
!= NULL
&& ConfigRequest
!= NULL
);
2006 PackageListNode
= DatabaseRecord
->PackageList
;
2009 // Search the languages in the specified packagelist.
2011 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2012 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2014 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2015 if (OpCode
!= NULL
) {
2016 *OpCodeData
= OpCode
;
2017 Header
= (EFI_IFR_QUESTION_HEADER
*) (OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2019 // Header->VarStoreId == 0 means no storage for this question.
2021 ASSERT (Header
->VarStoreId
!= 0);
2022 DEBUG ((EFI_D_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2024 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2025 ASSERT (Storage
!= NULL
);
2027 if (((EFI_IFR_OP_HEADER
*) Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2028 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2030 Offset
= Header
->VarStoreInfo
.VarOffset
;
2031 Width
= GetWidth (OpCode
);
2033 RequestElement
= ConstructRequestElement(Name
, Offset
, Width
);
2034 ConfigHdr
= ConstructConfigHdr(Storage
, DatabaseRecord
->DriverHandle
);
2035 ASSERT (ConfigHdr
!= NULL
);
2037 MaxLen
= StrLen (ConfigHdr
) + 1 + StrLen(RequestElement
) + 1;
2038 *ConfigRequest
= AllocatePool (MaxLen
* sizeof (CHAR16
));
2039 if (*ConfigRequest
== NULL
) {
2040 FreePool (ConfigHdr
);
2041 FreePool (RequestElement
);
2042 return EFI_OUT_OF_RESOURCES
;
2044 StringPtr
= *ConfigRequest
;
2046 StrCpyS (StringPtr
, MaxLen
, ConfigHdr
);
2047 StringPtr
+= StrLen (StringPtr
);
2052 StrCpyS (StringPtr
, MaxLen
, RequestElement
);
2053 StringPtr
+= StrLen (StringPtr
);
2056 FreePool (ConfigHdr
);
2057 FreePool (RequestElement
);
2063 return EFI_NOT_FOUND
;
2067 Base on the input parameter to generate the ConfigResp string.
2069 This is a internal function.
2071 @param DatabaseRecord HII_DATABASE_RECORD format string.
2072 @param KeywordStrId Keyword string id.
2073 @param ValueElement The value for the question which use keyword string id
2074 as the prompt string id.
2075 @param OpCodeData The IFR data for this question.
2076 @param ConfigResp Return the generate ConfigResp string.
2078 @retval EFI_SUCCESS Generate ConfigResp string success.
2079 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
2080 @retval EFI_NOT_FOUND Not found the question which use this string id
2081 as the prompt string id.
2085 IN HII_DATABASE_RECORD
*DatabaseRecord
,
2086 IN EFI_STRING_ID KeywordStrId
,
2087 IN EFI_STRING ValueElement
,
2088 OUT UINT8
**OpCodeData
,
2089 OUT EFI_STRING
*ConfigResp
2093 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2094 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
2095 EFI_IFR_QUESTION_HEADER
*Header
;
2102 CHAR16
*RequestElement
;
2106 ASSERT ((DatabaseRecord
!= NULL
) && (OpCodeData
!= NULL
) && (ConfigResp
!= NULL
) && (ValueElement
!= NULL
));
2113 PackageListNode
= DatabaseRecord
->PackageList
;
2116 // Search the languages in the specified packagelist.
2118 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2119 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2121 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2122 if (OpCode
!= NULL
) {
2123 *OpCodeData
= OpCode
;
2124 Header
= (EFI_IFR_QUESTION_HEADER
*) (OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2126 // Header->VarStoreId == 0 means no storage for this question.
2128 ASSERT (Header
->VarStoreId
!= 0);
2129 DEBUG ((EFI_D_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2131 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2132 ASSERT (Storage
!= NULL
);
2134 if (((EFI_IFR_OP_HEADER
*) Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2135 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2137 Offset
= Header
->VarStoreInfo
.VarOffset
;
2138 Width
= GetWidth (OpCode
);
2140 RequestElement
= ConstructRequestElement(Name
, Offset
, Width
);
2142 ConfigHdr
= ConstructConfigHdr(Storage
, DatabaseRecord
->DriverHandle
);
2143 ASSERT (ConfigHdr
!= NULL
);
2145 MaxLen
= StrLen (ConfigHdr
) + 1 + StrLen(RequestElement
) + 1 + StrLen (L
"VALUE=") + StrLen(ValueElement
) + 1;
2146 *ConfigResp
= AllocatePool (MaxLen
* sizeof (CHAR16
));
2147 if (*ConfigResp
== NULL
) {
2148 FreePool (ConfigHdr
);
2149 FreePool (RequestElement
);
2150 return EFI_OUT_OF_RESOURCES
;
2152 StringPtr
= *ConfigResp
;
2154 StrCpyS (StringPtr
, MaxLen
, ConfigHdr
);
2155 StringPtr
+= StrLen (StringPtr
);
2160 StrCpyS (StringPtr
, MaxLen
, RequestElement
);
2161 StringPtr
+= StrLen (StringPtr
);
2166 StrCpyS (StringPtr
, MaxLen
, L
"VALUE=");
2167 StringPtr
+= StrLen (StringPtr
);
2169 StrCpyS (StringPtr
, MaxLen
, ValueElement
);
2170 StringPtr
+= StrLen (StringPtr
);
2173 FreePool (ConfigHdr
);
2174 FreePool (RequestElement
);
2180 return EFI_NOT_FOUND
;
2184 Get the Value section from the Hii driver.
2186 This is a internal function.
2188 @param ConfigRequest The input ConfigRequest string.
2189 @param ValueElement The respond Value section from the hii driver.
2191 @retval Misc value The error status return from ExtractConfig function.
2192 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated
2193 @retval EFI_SUCCESS Get the value section success.
2197 ExtractValueFromDriver (
2198 IN CHAR16
*ConfigRequest
,
2199 OUT CHAR16
**ValueElement
2204 EFI_STRING Progress
;
2208 ASSERT ((ConfigRequest
!= NULL
) && (ValueElement
!= NULL
));
2210 Status
= mPrivate
.ConfigRouting
.ExtractConfig (
2211 &mPrivate
.ConfigRouting
,
2212 (EFI_STRING
) ConfigRequest
,
2216 if (EFI_ERROR (Status
)) {
2221 // Find Value Section and return it.
2223 StringPtr
= StrStr (Result
, L
"&VALUE=");
2224 ASSERT (StringPtr
!= NULL
);
2225 StringEnd
= StrStr (StringPtr
+ 1, L
"&");
2226 if (StringEnd
!= NULL
) {
2230 *ValueElement
= AllocateCopyPool (StrSize (StringPtr
), StringPtr
);
2231 if (*ValueElement
== NULL
) {
2232 return EFI_OUT_OF_RESOURCES
;
2235 if (StringEnd
!= NULL
) {
2244 Get EFI_STRING_ID info from the input device path, namespace and keyword.
2246 This is a internal function.
2248 @param DevicePath Input device path info.
2249 @param NameSpace NameSpace format string.
2250 @param KeywordData Keyword used to get string id.
2251 @param ProgressErr Return extra error type.
2252 @param KeywordStringId Return EFI_STRING_ID.
2253 @param DataBaseRecord DataBase record data for this driver.
2255 @retval EFI_INVALID_PARAMETER Can't find the database record base on the input device path or namespace.
2256 @retval EFI_NOT_FOUND Can't find the EFI_STRING_ID for the keyword.
2257 @retval EFI_SUCCESS Find the EFI_STRING_ID.
2261 GetStringIdFromDatabase (
2262 IN EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
2263 IN CHAR8
**NameSpace
,
2264 IN CHAR16
*KeywordData
,
2265 OUT UINT32
*ProgressErr
,
2266 OUT EFI_STRING_ID
*KeywordStringId
,
2267 OUT HII_DATABASE_RECORD
**DataBaseRecord
2270 HII_DATABASE_RECORD
*Record
;
2272 BOOLEAN FindNameSpace
;
2273 EFI_DEVICE_PATH_PROTOCOL
*DestDevicePath
;
2274 UINT8
*DevicePathPkg
;
2275 UINTN DevicePathSize
;
2277 ASSERT ((NameSpace
!= NULL
) && (KeywordData
!= NULL
) && (ProgressErr
!= NULL
) && (KeywordStringId
!= NULL
) && (DataBaseRecord
!= NULL
));
2279 FindNameSpace
= FALSE
;
2281 if (*DevicePath
!= NULL
) {
2283 // Get DataBaseRecord from device path protocol.
2285 Record
= GetRecordFromDevicePath(*DevicePath
);
2286 if (Record
== NULL
) {
2288 // Can't find the DatabaseRecord base on the input device path info.
2289 // NEED TO CONFIRM the return ProgressErr.
2291 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2292 return EFI_INVALID_PARAMETER
;
2296 // Get string id from the record.
2298 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2299 switch (*ProgressErr
) {
2300 case KEYWORD_HANDLER_NO_ERROR
:
2301 *DataBaseRecord
= Record
;
2304 case KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
:
2305 return EFI_INVALID_PARAMETER
;
2308 ASSERT (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
);
2309 return EFI_NOT_FOUND
;
2313 // Find driver which matches the routing data.
2315 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
2316 Record
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2318 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2319 if (*ProgressErr
== KEYWORD_HANDLER_NO_ERROR
) {
2320 *DataBaseRecord
= Record
;
2322 if ((DevicePathPkg
= Record
->PackageList
->DevicePathPkg
) != NULL
) {
2323 DestDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) (DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
));
2324 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DestDevicePath
);
2325 *DevicePath
= AllocateCopyPool (DevicePathSize
, DestDevicePath
);
2326 if (*DevicePath
== NULL
) {
2327 return EFI_OUT_OF_RESOURCES
;
2331 // Need to verify this ASSERT.
2337 } else if (*ProgressErr
== KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
) {
2338 return EFI_OUT_OF_RESOURCES
;
2339 } else if (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
) {
2340 FindNameSpace
= TRUE
;
2345 // When PathHdr not input, if ever find the namespace, will return KEYWORD_HANDLER_KEYWORD_NOT_FOUND.
2346 // This is a bit more progress than KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND.
2348 if (FindNameSpace
) {
2349 return EFI_NOT_FOUND
;
2351 return EFI_INVALID_PARAMETER
;
2357 Genereate the KeywordResp String.
2359 <KeywordResp> ::= <NameSpaceId><PathHdr>'&'<Keyword>'&VALUE='<Number>['&READONLY']
2361 @param NameSpace NameSpace format string.
2362 @param DevicePath Input device path info.
2363 @param KeywordData Keyword used to get string id.
2364 @param ValueStr The value section for the keyword.
2365 @param ReadOnly Whether this value is readonly.
2366 @param KeywordResp Return the point to the KeywordResp string.
2368 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2369 @retval EFI_SUCCESS Generate the KeywordResp string.
2373 GenerateKeywordResp (
2374 IN CHAR8
*NameSpace
,
2375 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
2376 IN EFI_STRING KeywordData
,
2377 IN EFI_STRING ValueStr
,
2378 IN BOOLEAN ReadOnly
,
2379 OUT EFI_STRING
*KeywordResp
2385 CHAR16
*UnicodeNameSpace
;
2387 ASSERT ((NameSpace
!= NULL
) && (DevicePath
!= NULL
) && (KeywordData
!= NULL
) && (ValueStr
!= NULL
) && (KeywordResp
!= NULL
));
2390 // 1. Calculate the string length.
2393 // 1.1 NameSpaceId size.
2394 // 'NAMESPACE='<String>
2396 RespStrLen
= 10 + AsciiStrLen (NameSpace
);
2397 UnicodeNameSpace
= AllocatePool ((AsciiStrLen (NameSpace
) + 1) * sizeof (CHAR16
));
2398 if (UnicodeNameSpace
== NULL
) {
2399 return EFI_OUT_OF_RESOURCES
;
2401 AsciiStrToUnicodeStr(NameSpace
, UnicodeNameSpace
);
2404 // 1.2 PathHdr size.
2405 // PATH=<UEFI binary Device Path represented as hex number>'&'
2406 // Attention: The output include the '&' at the end.
2410 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
2411 (VOID
*) DevicePath
,
2415 RespStrLen
+= StrLen (PathHdr
);
2418 // 1.3 Keyword setion.
2419 // 'KEYWORD='<String>[':'<DecCh>(1/4)]
2421 RespStrLen
+= 8 + StrLen (KeywordData
);
2424 // 1.4 Value section.
2425 // ValueStr = '&VALUE='<Number>
2427 RespStrLen
+= StrLen (ValueStr
);
2430 // 1.5 ReadOnly Section.
2438 // 2. Allocate the buffer and create the KeywordResp string include '\0'.
2441 *KeywordResp
= AllocatePool (RespStrLen
* sizeof (CHAR16
));
2442 if (*KeywordResp
== NULL
) {
2443 if (UnicodeNameSpace
!= NULL
) {
2444 FreePool (UnicodeNameSpace
);
2447 return EFI_OUT_OF_RESOURCES
;
2449 RespStr
= *KeywordResp
;
2452 // 2.1 Copy NameSpaceId section.
2454 StrCpyS (RespStr
, RespStrLen
, L
"NAMESPACE=");
2455 RespStr
+= StrLen (RespStr
);
2456 StrCpyS (RespStr
, RespStrLen
, UnicodeNameSpace
);
2457 RespStr
+= StrLen (RespStr
);
2460 // 2.2 Copy PathHdr section.
2462 StrCpyS (RespStr
, RespStrLen
, PathHdr
);
2463 RespStr
+= StrLen (RespStr
);
2466 // 2.3 Copy Keyword section.
2468 StrCpyS (RespStr
, RespStrLen
, L
"KEYWORD=");
2469 RespStr
+= StrLen (RespStr
);
2470 StrCpyS (RespStr
, RespStrLen
, KeywordData
);
2471 RespStr
+= StrLen (RespStr
);
2474 // 2.4 Copy the Value section.
2476 StrCpyS (RespStr
, RespStrLen
, ValueStr
);
2477 RespStr
+= StrLen (RespStr
);
2480 // 2.5 Copy ReadOnly section if exist.
2483 StrCpyS (RespStr
, RespStrLen
, L
"&READONLY");
2484 RespStr
+= StrLen (RespStr
);
2492 if (UnicodeNameSpace
!= NULL
) {
2493 FreePool (UnicodeNameSpace
);
2495 if (PathHdr
!= NULL
) {
2503 Merge the KeywordResp String to MultiKeywordResp string.
2505 This is a internal function.
2507 @param MultiKeywordResp The existed multikeywordresp string.
2508 @param KeywordResp The input keywordResp string.
2510 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2511 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2515 MergeToMultiKeywordResp (
2516 IN OUT EFI_STRING
*MultiKeywordResp
,
2517 IN EFI_STRING
*KeywordResp
2520 UINTN MultiKeywordRespLen
;
2521 EFI_STRING StringPtr
;
2523 if (*MultiKeywordResp
== NULL
) {
2524 *MultiKeywordResp
= *KeywordResp
;
2525 *KeywordResp
= NULL
;
2529 MultiKeywordRespLen
= (StrLen (*MultiKeywordResp
) + 1 + StrLen (*KeywordResp
) + 1) * sizeof (CHAR16
);
2531 StringPtr
= AllocateCopyPool (MultiKeywordRespLen
, *MultiKeywordResp
);
2532 if (StringPtr
== NULL
) {
2533 return EFI_OUT_OF_RESOURCES
;
2536 FreePool (*MultiKeywordResp
);
2537 *MultiKeywordResp
= StringPtr
;
2539 StringPtr
+= StrLen (StringPtr
);
2544 StrCpyS (StringPtr
, MultiKeywordRespLen
/ sizeof (CHAR16
), *KeywordResp
);
2550 Enumerate all keyword in the system.
2552 If error occur when parse one keyword, just skip it and parse the next one.
2554 This is a internal function.
2556 @param NameSpace The namespace used to search the string.
2557 @param MultiResp Return the MultiKeywordResp string for the system.
2558 @param ProgressErr Return the error status.
2560 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2561 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2562 @retval EFI_NOT_FOUND No keyword found.
2566 EnumerateAllKeywords (
2567 IN CHAR8
*NameSpace
,
2568 OUT EFI_STRING
*MultiResp
,
2569 OUT UINT32
*ProgressErr
2573 LIST_ENTRY
*StringLink
;
2574 UINT8
*DevicePathPkg
;
2576 HII_DATABASE_RECORD
*DataBaseRecord
;
2577 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2578 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
2579 CHAR8
*LocalNameSpace
;
2580 EFI_STRING_ID NextStringId
;
2583 CHAR16
*ConfigRequest
;
2584 CHAR16
*ValueElement
;
2585 CHAR16
*KeywordResp
;
2586 CHAR16
*MultiKeywordResp
;
2587 CHAR16
*KeywordData
;
2589 BOOLEAN FindKeywordPackages
;
2591 DataBaseRecord
= NULL
;
2592 Status
= EFI_SUCCESS
;
2593 MultiKeywordResp
= NULL
;
2595 LocalNameSpace
= NULL
;
2596 ConfigRequest
= NULL
;
2597 ValueElement
= NULL
;
2599 FindKeywordPackages
= FALSE
;
2601 if (NameSpace
== NULL
) {
2602 NameSpace
= UEFI_CONFIG_LANG
;
2606 // Find driver which matches the routing data.
2608 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
2609 DataBaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2610 if ((DevicePathPkg
= DataBaseRecord
->PackageList
->DevicePathPkg
) != NULL
) {
2611 DevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2613 PackageListNode
= DataBaseRecord
->PackageList
;
2615 for (StringLink
= PackageListNode
->StringPkgHdr
.ForwardLink
; StringLink
!= &PackageListNode
->StringPkgHdr
; StringLink
= StringLink
->ForwardLink
) {
2616 StringPackage
= CR (StringLink
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
2619 // Check whether has keyword string package.
2621 if (AsciiStrnCmp(NameSpace
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (NameSpace
)) == 0) {
2622 FindKeywordPackages
= TRUE
;
2624 // Keep the NameSpace string.
2626 LocalNameSpace
= AllocateCopyPool (AsciiStrSize (StringPackage
->StringPkgHdr
->Language
), StringPackage
->StringPkgHdr
->Language
);
2627 if (LocalNameSpace
== NULL
) {
2628 return EFI_OUT_OF_RESOURCES
;
2632 // 1 means just begin the enumerate the valid string ids.
2633 // StringId == 1 is always used to save the language for this string package.
2634 // Any valid string start from 2. so here initial it to 1.
2639 // Enumerate all valid stringid in the package.
2641 while ((NextStringId
= GetNextStringId (StringPackage
, NextStringId
, &KeywordData
)) != 0) {
2643 // 3.3 Construct the ConfigRequest string.
2645 Status
= ExtractConfigRequest (DataBaseRecord
, NextStringId
, &OpCode
, &ConfigRequest
);
2646 if (EFI_ERROR (Status
)) {
2648 // If can't generate ConfigRequest for this question, skip it and start the next.
2654 // 3.4 Extract Value for the input keyword.
2656 Status
= ExtractValueFromDriver(ConfigRequest
, &ValueElement
);
2657 if (EFI_ERROR (Status
)) {
2658 if (Status
!= EFI_OUT_OF_RESOURCES
) {
2660 // If can't generate ConfigRequest for this question, skip it and start the next.
2665 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2671 // Extract readonly flag from opcode.
2673 ReadOnly
= ExtractReadOnlyFromOpCode(OpCode
);
2676 // 5. Generate KeywordResp string.
2678 ASSERT (DevicePath
!= NULL
);
2679 Status
= GenerateKeywordResp(LocalNameSpace
, (EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
, KeywordData
, ValueElement
, ReadOnly
, &KeywordResp
);
2680 if (Status
!= EFI_SUCCESS
) {
2682 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2688 // 6. Merge to the MultiKeywordResp string.
2690 Status
= MergeToMultiKeywordResp(&MultiKeywordResp
, &KeywordResp
);
2691 if (EFI_ERROR (Status
)) {
2696 // Clean the temp buffer to later use again.
2698 if (ConfigRequest
!= NULL
) {
2699 FreePool (ConfigRequest
);
2700 ConfigRequest
= NULL
;
2702 if (ValueElement
!= NULL
) {
2703 FreePool (ValueElement
);
2704 ValueElement
= NULL
;
2706 if (KeywordResp
!= NULL
) {
2707 FreePool (KeywordResp
);
2712 if (LocalNameSpace
!= NULL
) {
2713 FreePool (LocalNameSpace
);
2714 LocalNameSpace
= NULL
;
2721 // return the already get MultiKeywordString even error occured.
2723 if (MultiKeywordResp
== NULL
) {
2724 Status
= EFI_NOT_FOUND
;
2725 if (!FindKeywordPackages
) {
2726 *ProgressErr
= KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
2728 *ProgressErr
= KEYWORD_HANDLER_KEYWORD_NOT_FOUND
;
2731 Status
= EFI_SUCCESS
;
2733 *MultiResp
= MultiKeywordResp
;
2736 if (LocalNameSpace
!= NULL
) {
2737 FreePool (LocalNameSpace
);
2739 if (ConfigRequest
!= NULL
) {
2740 FreePool (ConfigRequest
);
2742 if (ValueElement
!= NULL
) {
2743 FreePool (ValueElement
);
2751 This function accepts a <MultiKeywordResp> formatted string, finds the associated
2752 keyword owners, creates a <MultiConfigResp> string from it and forwards it to the
2753 EFI_HII_ROUTING_PROTOCOL.RouteConfig function.
2755 If there is an issue in resolving the contents of the KeywordString, then the
2756 function returns an error and also sets the Progress and ProgressErr with the
2757 appropriate information about where the issue occurred and additional data about
2758 the nature of the issue.
2760 In the case when KeywordString containing multiple keywords, when an EFI_NOT_FOUND
2761 error is generated during processing the second or later keyword element, the system
2762 storage associated with earlier keywords is not modified. All elements of the
2763 KeywordString must successfully pass all tests for format and access prior to making
2764 any modifications to storage.
2766 In the case when EFI_DEVICE_ERROR is returned from the processing of a KeywordString
2767 containing multiple keywords, the state of storage associated with earlier keywords
2771 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
2773 @param KeywordString A null-terminated string in <MultiKeywordResp> format.
2775 @param Progress On return, points to a character in the KeywordString.
2776 Points to the string's NULL terminator if the request
2777 was successful. Points to the most recent '&' before
2778 the first failing string element if the request was
2781 @param ProgressErr If during the processing of the KeywordString there was
2782 a failure, this parameter gives additional information
2783 about the possible source of the problem. The various
2784 errors are defined in "Related Definitions" below.
2787 @retval EFI_SUCCESS The specified action was completed successfully.
2789 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
2790 1. KeywordString is NULL.
2791 2. Parsing of the KeywordString resulted in an
2792 error. See Progress and ProgressErr for more data.
2794 @retval EFI_NOT_FOUND An element of the KeywordString was not found.
2795 See ProgressErr for more data.
2797 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2798 See ProgressErr for more data.
2800 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr
2803 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
2809 EfiConfigKeywordHandlerSetData (
2810 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
2811 IN CONST EFI_STRING KeywordString
,
2812 OUT EFI_STRING
*Progress
,
2813 OUT UINT32
*ProgressErr
2819 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2820 CHAR16
*NextStringPtr
;
2821 CHAR16
*KeywordData
;
2822 EFI_STRING_ID KeywordStringId
;
2824 HII_DATABASE_RECORD
*DataBaseRecord
;
2827 CHAR16
*MultiConfigResp
;
2828 CHAR16
*ValueElement
;
2830 EFI_STRING InternalProgress
;
2832 CHAR16
*KeywordStartPos
;
2834 if (This
== NULL
|| Progress
== NULL
|| ProgressErr
== NULL
|| KeywordString
== NULL
) {
2835 return EFI_INVALID_PARAMETER
;
2838 *Progress
= KeywordString
;
2839 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
2840 Status
= EFI_SUCCESS
;
2841 MultiConfigResp
= NULL
;
2845 ValueElement
= NULL
;
2847 KeywordStartPos
= NULL
;
2848 KeywordStringId
= 0;
2851 // Use temp string to avoid changing input string buffer.
2853 TempString
= AllocateCopyPool (StrSize (KeywordString
), KeywordString
);
2854 ASSERT (TempString
!= NULL
);
2855 StringPtr
= TempString
;
2857 while ((StringPtr
!= NULL
) && (*StringPtr
!= L
'\0')) {
2859 // 1. Get NameSpace from NameSpaceId keyword.
2861 Status
= ExtractNameSpace (StringPtr
, &NameSpace
, &NextStringPtr
);
2862 if (EFI_ERROR (Status
)) {
2863 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2866 ASSERT (NameSpace
!= NULL
);
2868 // 1.1 Check whether the input namespace is valid.
2870 if (AsciiStrnCmp(NameSpace
, UEFI_CONFIG_LANG
, AsciiStrLen (UEFI_CONFIG_LANG
)) != 0) {
2871 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2872 Status
= EFI_INVALID_PARAMETER
;
2876 StringPtr
= NextStringPtr
;
2879 // 2. Get possible Device Path info from KeywordString.
2881 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
2882 if (EFI_ERROR (Status
)) {
2883 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2886 StringPtr
= NextStringPtr
;
2889 // 3. Extract keyword from the KeywordRequest string.
2891 KeywordStartPos
= StringPtr
;
2892 Status
= ExtractKeyword(StringPtr
, &KeywordData
, &NextStringPtr
);
2893 if (EFI_ERROR (Status
)) {
2895 // Can't find Keyword base on the input device path info.
2897 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2898 Status
= EFI_INVALID_PARAMETER
;
2901 StringPtr
= NextStringPtr
;
2904 // 4. Extract Value from the KeywordRequest string.
2906 Status
= ExtractValue (StringPtr
, &ValueElement
, &NextStringPtr
);
2907 if (EFI_ERROR (Status
)) {
2909 // Can't find Value base on the input device path info.
2911 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2912 Status
= EFI_INVALID_PARAMETER
;
2915 StringPtr
= NextStringPtr
;
2918 // 5. Find ReadOnly filter.
2920 if ((StringPtr
!= NULL
) && StrnCmp (StringPtr
, L
"&ReadOnly", StrLen (L
"&ReadOnly")) == 0) {
2922 StringPtr
+= StrLen (L
"&ReadOnly");
2928 // 6. Get EFI_STRING_ID for the input keyword.
2930 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
2931 if (EFI_ERROR (Status
)) {
2932 *ProgressErr
= RetVal
;
2937 // 7. Construct the ConfigRequest string.
2939 Status
= ExtractConfigResp (DataBaseRecord
, KeywordStringId
, ValueElement
, &OpCode
, &ConfigResp
);
2940 if (EFI_ERROR (Status
)) {
2945 // 8. Check the readonly flag.
2947 if (ExtractReadOnlyFromOpCode (OpCode
) != ReadOnly
) {
2948 *ProgressErr
= KEYWORD_HANDLER_ACCESS_NOT_PERMITTED
;
2949 Status
= EFI_ACCESS_DENIED
;
2954 // 9. Merge to the MultiKeywordResp string.
2956 Status
= MergeToMultiKeywordResp(&MultiConfigResp
, &ConfigResp
);
2957 if (EFI_ERROR (Status
)) {
2962 // 10. Clean the temp buffer point.
2964 FreePool (NameSpace
);
2965 FreePool (DevicePath
);
2966 FreePool (KeywordData
);
2967 FreePool (ValueElement
);
2971 ValueElement
= NULL
;
2972 if (ConfigResp
!= NULL
) {
2973 FreePool (ConfigResp
);
2976 KeywordStartPos
= NULL
;
2980 // 11. Set value to driver.
2982 Status
= mPrivate
.ConfigRouting
.RouteConfig(
2983 &mPrivate
.ConfigRouting
,
2984 (EFI_STRING
) MultiConfigResp
,
2987 if (EFI_ERROR (Status
)) {
2988 Status
= EFI_DEVICE_ERROR
;
2992 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
2995 if (KeywordStartPos
!= NULL
) {
2996 *Progress
= KeywordString
+ (KeywordStartPos
- TempString
);
2998 *Progress
= KeywordString
+ (StringPtr
- TempString
);
3001 ASSERT (TempString
!= NULL
);
3002 FreePool (TempString
);
3003 if (NameSpace
!= NULL
) {
3004 FreePool (NameSpace
);
3006 if (DevicePath
!= NULL
) {
3007 FreePool (DevicePath
);
3009 if (KeywordData
!= NULL
) {
3010 FreePool (KeywordData
);
3012 if (ValueElement
!= NULL
) {
3013 FreePool (ValueElement
);
3015 if (ConfigResp
!= NULL
) {
3016 FreePool (ConfigResp
);
3018 if (MultiConfigResp
!= NULL
&& MultiConfigResp
!= ConfigResp
) {
3019 FreePool (MultiConfigResp
);
3027 This function accepts a <MultiKeywordRequest> formatted string, finds the underlying
3028 keyword owners, creates a <MultiConfigRequest> string from it and forwards it to the
3029 EFI_HII_ROUTING_PROTOCOL.ExtractConfig function.
3031 If there is an issue in resolving the contents of the KeywordString, then the function
3032 returns an EFI_INVALID_PARAMETER and also set the Progress and ProgressErr with the
3033 appropriate information about where the issue occurred and additional data about the
3034 nature of the issue.
3036 In the case when KeywordString is NULL, or contains multiple keywords, or when
3037 EFI_NOT_FOUND is generated while processing the keyword elements, the Results string
3038 contains values returned for all keywords processed prior to the keyword generating the
3039 error but no values for the keyword with error or any following keywords.
3042 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
3044 @param NameSpaceId A null-terminated string containing the platform configuration
3045 language to search through in the system. If a NULL is passed
3046 in, then it is assumed that any platform configuration language
3047 with the prefix of "x-UEFI-" are searched.
3049 @param KeywordString A null-terminated string in <MultiKeywordRequest> format. If a
3050 NULL is passed in the KeywordString field, all of the known
3051 keywords in the system for the NameSpaceId specified are
3052 returned in the Results field.
3054 @param Progress On return, points to a character in the KeywordString. Points
3055 to the string's NULL terminator if the request was successful.
3056 Points to the most recent '&' before the first failing string
3057 element if the request was not successful.
3059 @param ProgressErr If during the processing of the KeywordString there was a
3060 failure, this parameter gives additional information about the
3061 possible source of the problem. See the definitions in SetData()
3062 for valid value definitions.
3064 @param Results A null-terminated string in <MultiKeywordResp> format is returned
3065 which has all the values filled in for the keywords in the
3066 KeywordString. This is a callee-allocated field, and must be freed
3067 by the caller after being used.
3069 @retval EFI_SUCCESS The specified action was completed successfully.
3071 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
3072 1.Progress, ProgressErr, or Resuts is NULL.
3073 2.Parsing of the KeywordString resulted in an error. See
3074 Progress and ProgressErr for more data.
3077 @retval EFI_NOT_FOUND An element of the KeywordString was not found. See
3078 ProgressErr for more data.
3080 @retval EFI_NOT_FOUND The NamespaceId specified was not found. See ProgressErr
3083 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated. See
3084 ProgressErr for more data.
3086 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr for
3089 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
3095 EfiConfigKeywordHandlerGetData (
3096 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
3097 IN CONST EFI_STRING NameSpaceId
, OPTIONAL
3098 IN CONST EFI_STRING KeywordString
, OPTIONAL
3099 OUT EFI_STRING
*Progress
,
3100 OUT UINT32
*ProgressErr
,
3101 OUT EFI_STRING
*Results
3106 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
3107 HII_DATABASE_RECORD
*DataBaseRecord
;
3109 CHAR16
*NextStringPtr
;
3110 CHAR16
*KeywordData
;
3111 EFI_STRING_ID KeywordStringId
;
3113 CHAR16
*ConfigRequest
;
3114 CHAR16
*ValueElement
;
3117 CHAR16
*KeywordResp
;
3118 CHAR16
*MultiKeywordResp
;
3121 if (This
== NULL
|| Progress
== NULL
|| ProgressErr
== NULL
|| Results
== NULL
) {
3122 return EFI_INVALID_PARAMETER
;
3125 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
3126 Status
= EFI_SUCCESS
;
3130 ConfigRequest
= NULL
;
3131 StringPtr
= KeywordString
;
3133 MultiKeywordResp
= NULL
;
3134 KeywordStringId
= 0;
3138 // Use temp string to avoid changing input string buffer.
3140 if (NameSpaceId
!= NULL
) {
3141 TempString
= AllocateCopyPool (StrSize (NameSpaceId
), NameSpaceId
);
3142 ASSERT (TempString
!= NULL
);
3145 // 1. Get NameSpace from NameSpaceId keyword.
3147 Status
= ExtractNameSpace (TempString
, &NameSpace
, NULL
);
3148 if (TempString
!= NULL
) {
3149 FreePool (TempString
);
3152 if (EFI_ERROR (Status
)) {
3153 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3157 // 1.1 Check whether the input namespace is valid.
3159 if (NameSpace
!= NULL
){
3160 if (AsciiStrnCmp(NameSpace
, UEFI_CONFIG_LANG
, AsciiStrLen (UEFI_CONFIG_LANG
)) != 0) {
3161 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3162 return EFI_INVALID_PARAMETER
;
3166 if (KeywordString
!= NULL
) {
3168 // Use temp string to avoid changing input string buffer.
3170 TempString
= AllocateCopyPool (StrSize (KeywordString
), KeywordString
);
3171 ASSERT (TempString
!= NULL
);
3172 StringPtr
= TempString
;
3174 while (*StringPtr
!= L
'\0') {
3176 // 2. Get possible Device Path info from KeywordString.
3178 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
3179 if (EFI_ERROR (Status
)) {
3180 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3183 StringPtr
= NextStringPtr
;
3187 // 3. Process Keyword section from the input keywordRequest string.
3189 // 3.1 Extract keyword from the KeywordRequest string.
3191 Status
= ExtractKeyword(StringPtr
, &KeywordData
, &NextStringPtr
);
3192 if (EFI_ERROR (Status
)) {
3194 // Can't find Keyword base on the input device path info.
3196 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3197 Status
= EFI_INVALID_PARAMETER
;
3202 // 3.2 Get EFI_STRING_ID for the input keyword.
3204 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
3205 if (EFI_ERROR (Status
)) {
3206 *ProgressErr
= RetVal
;
3211 // 3.3 Construct the ConfigRequest string.
3213 Status
= ExtractConfigRequest (DataBaseRecord
, KeywordStringId
, &OpCode
, &ConfigRequest
);
3214 if (EFI_ERROR (Status
)) {
3219 // 3.4 Extract Value for the input keyword.
3221 Status
= ExtractValueFromDriver(ConfigRequest
, &ValueElement
);
3222 if (EFI_ERROR (Status
)) {
3223 if (Status
!= EFI_OUT_OF_RESOURCES
) {
3224 Status
= EFI_DEVICE_ERROR
;
3228 StringPtr
= NextStringPtr
;
3231 // 4. Process the possible filter section.
3233 RetVal
= ValidateFilter (OpCode
, StringPtr
, &NextStringPtr
, &ReadOnly
);
3234 if (RetVal
!= KEYWORD_HANDLER_NO_ERROR
) {
3235 *ProgressErr
= RetVal
;
3236 Status
= EFI_INVALID_PARAMETER
;
3239 StringPtr
= NextStringPtr
;
3243 // 5. Generate KeywordResp string.
3245 Status
= GenerateKeywordResp(NameSpace
, DevicePath
, KeywordData
, ValueElement
, ReadOnly
, &KeywordResp
);
3246 if (Status
!= EFI_SUCCESS
) {
3251 // 6. Merge to the MultiKeywordResp string.
3253 Status
= MergeToMultiKeywordResp(&MultiKeywordResp
, &KeywordResp
);
3254 if (EFI_ERROR (Status
)) {
3259 // 7. Update return value.
3261 *Results
= MultiKeywordResp
;
3264 // 8. Clean the temp buffer.
3266 FreePool (DevicePath
);
3267 FreePool (KeywordData
);
3268 FreePool (ValueElement
);
3269 FreePool (ConfigRequest
);
3272 ValueElement
= NULL
;
3273 ConfigRequest
= NULL
;
3274 if (KeywordResp
!= NULL
) {
3275 FreePool (KeywordResp
);
3281 // Enumerate all keyword in the system.
3283 Status
= EnumerateAllKeywords(NameSpace
, &MultiKeywordResp
, ProgressErr
);
3284 if (EFI_ERROR (Status
)) {
3287 *Results
= MultiKeywordResp
;
3290 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
3293 *Progress
= KeywordString
+ (StringPtr
- TempString
);
3295 if (TempString
!= NULL
) {
3296 FreePool (TempString
);
3298 if (NameSpace
!= NULL
) {
3299 FreePool (NameSpace
);
3301 if (DevicePath
!= NULL
) {
3302 FreePool (DevicePath
);
3304 if (KeywordData
!= NULL
) {
3305 FreePool (KeywordData
);