2 Implementation of interfaces function for EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL.
4 Copyright (c) 2015 - 2016, 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 necessary 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
183 ASSERT (NameSpace
!= NULL
);
188 // Input NameSpaceId == NULL
190 if (String
== NULL
) {
192 if (NextString
!= NULL
) {
199 // Skip '&' if exist.
201 if (*String
== L
'&') {
205 if (StrnCmp (String
, L
"NAMESPACE=", StrLen (L
"NAMESPACE=")) != 0) {
206 return EFI_INVALID_PARAMETER
;
208 String
+= StrLen (L
"NAMESPACE=");
210 TmpPtr
= StrStr (String
, L
"&");
211 if (TmpPtr
!= NULL
) {
214 if (NextString
!= NULL
) {
215 *NextString
= String
+ StrLen (String
);
219 // Input NameSpace is unicode string. The language in String package is ascii string.
220 // Here will convert the unicode string to ascii and save it.
222 NameSpaceSize
= StrLen (String
) + 1;
223 *NameSpace
= AllocatePool (NameSpaceSize
);
224 if (*NameSpace
== NULL
) {
225 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
) {
288 *NextString
= String
+ StrLen (String
);
290 *Keyword
= AllocateCopyPool (StrSize (String
), String
);
291 if (*Keyword
== NULL
) {
292 return EFI_OUT_OF_RESOURCES
;
295 if (TmpPtr
!= NULL
) {
303 Get value from the input KeywordRequest string.
305 This is a internal function.
307 @param String KeywordRequestformat string.
308 @param Value return the extract value string.
309 @param NextString return the next string follow this keyword section.
311 @retval EFI_SUCCESS Success to get the keyword string.
312 @retval EFI_INVALID_PARAMETER Parse the input string return error.
317 IN EFI_STRING String
,
318 OUT EFI_STRING
*Value
,
319 OUT EFI_STRING
*NextString
324 ASSERT ((Value
!= NULL
) && (NextString
!= NULL
) && (String
!= NULL
));
327 // Skip '&' if exist.
329 if (*String
== L
'&') {
333 if (StrnCmp (String
, L
"VALUE=", StrLen (L
"VALUE=")) != 0) {
334 return EFI_INVALID_PARAMETER
;
337 String
+= StrLen (L
"VALUE=");
339 TmpPtr
= StrStr (String
, L
"&");
340 if (TmpPtr
!= NULL
) {
343 *NextString
= String
+ StrLen (String
);
345 *Value
= AllocateCopyPool (StrSize (String
), String
);
346 if (*Value
== NULL
) {
347 return EFI_OUT_OF_RESOURCES
;
350 if (TmpPtr
!= NULL
) {
358 Get filter from the input KeywordRequest string.
360 This is a internal function.
362 @param String KeywordRequestformat string.
363 @param FilterFlags return the filter condition.
364 @param NextString return the next string follow this keyword section.
366 @retval EFI_SUCCESS Success to get the keyword string.
367 @retval EFI_INVALID_PARAMETER Parse the input string return error.
372 IN EFI_STRING String
,
373 OUT UINT8
*FilterFlags
,
374 OUT EFI_STRING
*NextString
381 ASSERT ((FilterFlags
!= NULL
) && (NextString
!= NULL
));
384 // String end, no filter section.
386 if (String
== NULL
) {
395 // Skip '&' if exist.
397 if (*String
== L
'&') {
401 if (StrnCmp (String
, L
"ReadOnly", StrLen (L
"ReadOnly")) == 0) {
403 // Find ReadOnly filter.
405 *FilterFlags
|= EFI_KEYWORD_FILTER_READONY
;
406 String
+= StrLen (L
"ReadOnly");
407 } else if (StrnCmp (String
, L
"ReadWrite", StrLen (L
"ReadWrite")) == 0) {
409 // Find ReadWrite filter.
411 *FilterFlags
|= EFI_KEYWORD_FILTER_REAWRITE
;
412 String
+= StrLen (L
"ReadWrite");
413 } else if (StrnCmp (String
, L
"Buffer", StrLen (L
"Buffer")) == 0) {
415 // Find Buffer Filter.
417 *FilterFlags
|= EFI_KEYWORD_FILTER_BUFFER
;
418 String
+= StrLen (L
"Buffer");
419 } else if (StrnCmp (String
, L
"Numeric", StrLen (L
"Numeric")) == 0) {
421 // Find Numeric Filter
423 String
+= StrLen (L
"Numeric");
424 if (*String
!= L
':') {
425 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC
;
430 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_1
;
433 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_2
;
436 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_4
;
439 *FilterFlags
|= EFI_KEYWORD_FILTER_NUMERIC_8
;
449 // Check whether other filter item defined by Platform.
451 if ((StrnCmp (String
, L
"&PATH", StrLen (L
"&PATH")) == 0) ||
452 (StrnCmp (String
, L
"&KEYWORD", StrLen (L
"&KEYWORD")) == 0)) {
454 // New KeywordRequest start, no platform defined filter.
458 // Platform defined filter rule.
459 // Just skip platform defined filter rule, return success.
461 PathPtr
= StrStr(String
, L
"&PATH");
462 KeywordPtr
= StrStr(String
, L
"&KEYWORD");
463 if (PathPtr
!= NULL
&& KeywordPtr
!= NULL
) {
465 // If both sections exist, return the first follow string.
467 String
= KeywordPtr
> PathPtr
? PathPtr
: KeywordPtr
;
468 } else if (PathPtr
!= NULL
) {
470 // Should not exist PathPtr != NULL && KeywordPtr == NULL case.
473 } else if (KeywordPtr
!= NULL
) {
475 // Just to the next keyword section.
480 // Only has platform defined filter section, just skip it.
482 String
+= StrLen (String
);
488 *NextString
= String
;
494 Extract Readonly flag from opcode.
496 This is a internal function.
498 @param OpCodeData Input opcode for this question.
500 @retval TRUE This question is readonly.
501 @retval FALSE This question is not readonly.
505 ExtractReadOnlyFromOpCode (
509 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
511 ASSERT (OpCodeData
!= NULL
);
513 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
515 return (QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) != 0;
519 Create a circuit to check the filter section.
521 This is a internal function.
523 @param OpCodeData The question binary ifr data.
524 @param KeywordRequest KeywordRequestformat string.
525 @param NextString return the next string follow this keyword section.
526 @param ReadOnly Return whether this question is read only.
528 @retval KEYWORD_HANDLER_NO_ERROR Success validate.
529 @retval KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED Validate fail.
534 IN UINT8
*OpCodeData
,
535 IN CHAR16
*KeywordRequest
,
536 OUT CHAR16
**NextString
,
537 OUT BOOLEAN
*ReadOnly
543 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
544 EFI_IFR_OP_HEADER
*OpCodeHdr
;
548 RetVal
= KEYWORD_HANDLER_NO_ERROR
;
549 StringPtr
= KeywordRequest
;
551 OpCodeHdr
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
552 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
553 if (OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) {
554 Flags
= *(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
) + sizeof (EFI_IFR_QUESTION_HEADER
));
560 // Get ReadOnly flag from Question.
562 *ReadOnly
= ExtractReadOnlyFromOpCode(OpCodeData
);
564 while (ExtractFilter (StringPtr
, &FilterFlags
, &NextFilter
)) {
565 switch (FilterFlags
) {
566 case EFI_KEYWORD_FILTER_READONY
:
567 if ((QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) == 0) {
568 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
573 case EFI_KEYWORD_FILTER_REAWRITE
:
574 if ((QuestionHdr
->Flags
& EFI_IFR_FLAG_READ_ONLY
) != 0) {
575 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
580 case EFI_KEYWORD_FILTER_BUFFER
:
582 // Only these three opcode use numeric value type.
584 if (OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_CHECKBOX_OP
) {
585 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
590 case EFI_KEYWORD_FILTER_NUMERIC
:
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
;
597 case EFI_KEYWORD_FILTER_NUMERIC_1
:
598 case EFI_KEYWORD_FILTER_NUMERIC_2
:
599 case EFI_KEYWORD_FILTER_NUMERIC_4
:
600 case EFI_KEYWORD_FILTER_NUMERIC_8
:
601 if (OpCodeHdr
->OpCode
!= EFI_IFR_ONE_OF_OP
&& OpCodeHdr
->OpCode
!= EFI_IFR_NUMERIC_OP
&& OpCodeHdr
->OpCode
!= EFI_IFR_CHECKBOX_OP
) {
602 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
607 // For numeric and oneof, it has flags field to specify the detail numeric type.
609 if (OpCodeHdr
->OpCode
== EFI_IFR_ONE_OF_OP
|| OpCodeHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) {
610 switch (Flags
& EFI_IFR_NUMERIC_SIZE
) {
611 case EFI_IFR_NUMERIC_SIZE_1
:
612 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_1
) {
613 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
618 case EFI_IFR_NUMERIC_SIZE_2
:
619 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_2
) {
620 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
625 case EFI_IFR_NUMERIC_SIZE_4
:
626 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_4
) {
627 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
632 case EFI_IFR_NUMERIC_SIZE_8
:
633 if (FilterFlags
!= EFI_KEYWORD_FILTER_NUMERIC_8
) {
634 RetVal
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
652 // Jump to the next filter.
654 StringPtr
= NextFilter
;
659 // The current filter which is processing.
661 *NextString
= StringPtr
;
667 Get HII_DATABASE_RECORD from the input device path info.
669 This is a internal function.
671 @param DevicePath UEFI device path protocol.
673 @retval Internal data base record.
676 HII_DATABASE_RECORD
*
677 GetRecordFromDevicePath (
678 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
682 UINT8
*DevicePathPkg
;
683 UINT8
*CurrentDevicePath
;
684 UINTN DevicePathSize
;
685 HII_DATABASE_RECORD
*TempDatabase
;
687 ASSERT (DevicePath
!= NULL
);
689 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
690 TempDatabase
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
691 DevicePathPkg
= TempDatabase
->PackageList
->DevicePathPkg
;
692 if (DevicePathPkg
!= NULL
) {
693 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
694 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
695 if ((CompareMem (DevicePath
, CurrentDevicePath
, DevicePathSize
) == 0)) {
705 Calculate the size of StringSrc and output it. Also copy string text from src
708 This is a internal function.
710 @param StringSrc Points to current null-terminated string.
711 @param BufferSize Length of the buffer.
712 @param StringDest Buffer to store the string text.
714 @retval EFI_SUCCESS The string text was outputted successfully.
715 @retval EFI_OUT_OF_RESOURCES Out of resource.
719 GetUnicodeStringTextAndSize (
721 OUT UINTN
*BufferSize
,
722 OUT EFI_STRING
*StringDest
728 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
&& StringDest
!= NULL
);
730 StringSize
= sizeof (CHAR16
);
731 StringPtr
= StringSrc
;
732 while (ReadUnaligned16 ((UINT16
*) StringPtr
) != 0) {
733 StringSize
+= sizeof (CHAR16
);
734 StringPtr
+= sizeof (CHAR16
);
737 *StringDest
= AllocatePool (StringSize
);
738 if (*StringDest
== NULL
) {
739 return EFI_OUT_OF_RESOURCES
;
742 CopyMem (*StringDest
, StringSrc
, StringSize
);
744 *BufferSize
= StringSize
;
749 Find the string id for the input keyword.
751 @param StringPackage Hii string package instance.
752 @param KeywordValue Input keyword value.
753 @param StringId The string's id, which is unique within PackageList.
756 @retval EFI_SUCCESS The string text and font is retrieved
758 @retval EFI_NOT_FOUND The specified text or font info can not be found
760 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
764 GetStringIdFromString (
765 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
766 IN CHAR16
*KeywordValue
,
767 OUT EFI_STRING_ID
*StringId
771 EFI_STRING_ID CurrentStringId
;
774 UINT8
*StringTextPtr
;
779 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
783 CHAR8
*AsciiKeywordValue
;
784 UINTN KeywordValueSize
;
787 ASSERT (StringPackage
!= NULL
&& KeywordValue
!= NULL
&& StringId
!= NULL
);
788 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
791 Status
= EFI_SUCCESS
;
793 BlockHdr
= StringPackage
->StringBlock
;
798 // Make a ascii keyword value for later use.
800 KeywordValueSize
= StrLen (KeywordValue
) + 1;
801 AsciiKeywordValue
= AllocatePool (KeywordValueSize
);
802 if (AsciiKeywordValue
== NULL
) {
803 return EFI_OUT_OF_RESOURCES
;
805 UnicodeStrToAsciiStrS (KeywordValue
, AsciiKeywordValue
, KeywordValueSize
);
807 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
809 case EFI_HII_SIBT_STRING_SCSU
:
810 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
811 StringTextPtr
= BlockHdr
+ Offset
;
812 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
813 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
814 *StringId
= CurrentStringId
;
820 case EFI_HII_SIBT_STRING_SCSU_FONT
:
821 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
822 StringTextPtr
= BlockHdr
+ Offset
;
823 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
824 *StringId
= CurrentStringId
;
827 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
831 case EFI_HII_SIBT_STRINGS_SCSU
:
832 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
833 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
834 BlockSize
+= StringTextPtr
- BlockHdr
;
836 for (Index
= 0; Index
< StringCount
; Index
++) {
837 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
838 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
839 *StringId
= CurrentStringId
;
842 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
847 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
850 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
853 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
854 BlockSize
+= StringTextPtr
- BlockHdr
;
856 for (Index
= 0; Index
< StringCount
; Index
++) {
857 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
858 if (AsciiStrCmp(AsciiKeywordValue
, (CHAR8
*) StringTextPtr
) == 0) {
859 *StringId
= CurrentStringId
;
862 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
867 case EFI_HII_SIBT_STRING_UCS2
:
868 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
869 StringTextPtr
= BlockHdr
+ Offset
;
871 // Use StringSize to store the size of the specified string, including the NULL
874 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
875 if (EFI_ERROR (Status
)) {
878 ASSERT (String
!= NULL
);
879 if (StrCmp(KeywordValue
, String
) == 0) {
880 *StringId
= CurrentStringId
;
883 BlockSize
+= Offset
+ StringSize
;
887 case EFI_HII_SIBT_STRING_UCS2_FONT
:
888 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
889 StringTextPtr
= BlockHdr
+ Offset
;
891 // Use StringSize to store the size of the specified string, including the NULL
894 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
895 if (EFI_ERROR (Status
)) {
898 ASSERT (String
!= NULL
);
899 if (StrCmp(KeywordValue
, String
) == 0) {
900 *StringId
= CurrentStringId
;
903 BlockSize
+= Offset
+ StringSize
;
907 case EFI_HII_SIBT_STRINGS_UCS2
:
908 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
909 StringTextPtr
= BlockHdr
+ Offset
;
911 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
912 for (Index
= 0; Index
< StringCount
; Index
++) {
913 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
914 if (EFI_ERROR (Status
)) {
917 ASSERT (String
!= NULL
);
918 BlockSize
+= StringSize
;
919 if (StrCmp(KeywordValue
, String
) == 0) {
920 *StringId
= CurrentStringId
;
923 StringTextPtr
= StringTextPtr
+ StringSize
;
928 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
929 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
930 StringTextPtr
= BlockHdr
+ Offset
;
934 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
937 for (Index
= 0; Index
< StringCount
; Index
++) {
938 Status
= GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
939 if (EFI_ERROR (Status
)) {
942 ASSERT (String
!= NULL
);
943 BlockSize
+= StringSize
;
944 if (StrCmp(KeywordValue
, String
) == 0) {
945 *StringId
= CurrentStringId
;
948 StringTextPtr
= StringTextPtr
+ StringSize
;
953 case EFI_HII_SIBT_DUPLICATE
:
954 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
958 case EFI_HII_SIBT_SKIP1
:
959 SkipCount
= (UINT16
) (*(UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
960 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
961 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
964 case EFI_HII_SIBT_SKIP2
:
965 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
966 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
967 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
970 case EFI_HII_SIBT_EXT1
:
973 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
976 BlockSize
+= Length8
;
979 case EFI_HII_SIBT_EXT2
:
980 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
981 BlockSize
+= Ext2
.Length
;
984 case EFI_HII_SIBT_EXT4
:
987 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
991 BlockSize
+= Length32
;
998 if (String
!= NULL
) {
1003 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
1006 Status
= EFI_NOT_FOUND
;
1009 if (AsciiKeywordValue
!= NULL
) {
1010 FreePool (AsciiKeywordValue
);
1012 if (String
!= NULL
) {
1019 Find the next valid string id for the input string id.
1021 @param StringPackage Hii string package instance.
1022 @param StringId The current string id which is already got.
1023 1 means just begin to get the string id.
1024 @param KeywordValue Return the string for the next string id.
1027 @retval EFI_STRING_ID Not 0 means a valid stringid found.
1028 0 means not found a valid string id.
1032 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
1033 IN EFI_STRING_ID StringId
,
1034 OUT EFI_STRING
*KeywordValue
1038 EFI_STRING_ID CurrentStringId
;
1041 UINT8
*StringTextPtr
;
1046 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
1052 ASSERT (StringPackage
!= NULL
);
1053 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
1055 CurrentStringId
= 1;
1060 // Parse the string blocks to get the string text and font.
1062 BlockHdr
= StringPackage
->StringBlock
;
1065 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
1066 switch (*BlockHdr
) {
1067 case EFI_HII_SIBT_STRING_SCSU
:
1068 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
1069 StringTextPtr
= BlockHdr
+ Offset
;
1072 StringSize
= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1073 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1074 if (*KeywordValue
== NULL
) {
1077 AsciiStrToUnicodeStrS ((CHAR8
*) StringTextPtr
, *KeywordValue
, StringSize
);
1078 return CurrentStringId
;
1079 } else if (CurrentStringId
== StringId
) {
1083 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1087 case EFI_HII_SIBT_STRING_SCSU_FONT
:
1088 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
1089 StringTextPtr
= BlockHdr
+ Offset
;
1092 StringSize
= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1093 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1094 if (*KeywordValue
== NULL
) {
1097 AsciiStrToUnicodeStrS ((CHAR8
*) StringTextPtr
, *KeywordValue
, StringSize
);
1098 return CurrentStringId
;
1099 } else if (CurrentStringId
== StringId
) {
1103 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1107 case EFI_HII_SIBT_STRINGS_SCSU
:
1108 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1109 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
1110 BlockSize
+= StringTextPtr
- BlockHdr
;
1112 for (Index
= 0; Index
< StringCount
; Index
++) {
1114 StringSize
= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1115 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1116 if (*KeywordValue
== NULL
) {
1119 AsciiStrToUnicodeStrS ((CHAR8
*) StringTextPtr
, *KeywordValue
, StringSize
);
1120 return CurrentStringId
;
1121 } else if (CurrentStringId
== StringId
) {
1125 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1126 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1131 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
1134 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1137 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
1138 BlockSize
+= StringTextPtr
- BlockHdr
;
1140 for (Index
= 0; Index
< StringCount
; Index
++) {
1142 StringSize
= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1143 *KeywordValue
= AllocatePool (StringSize
* sizeof (CHAR16
));
1144 if (*KeywordValue
== NULL
) {
1147 AsciiStrToUnicodeStrS ((CHAR8
*) StringTextPtr
, *KeywordValue
, StringSize
);
1148 return CurrentStringId
;
1149 } else if (CurrentStringId
== StringId
) {
1153 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
1154 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
1159 case EFI_HII_SIBT_STRING_UCS2
:
1160 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
1161 StringTextPtr
= BlockHdr
+ Offset
;
1163 // Use StringSize to store the size of the specified string, including the NULL
1166 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1167 if (FindString
&& (String
!= NULL
) && (*String
!= L
'\0')) {
1169 // String protocol use this type for the string id which has value for other package.
1170 // It will allocate an empty string block for this string id. so here we also check
1171 // *String != L'\0' to prohibit this case.
1173 *KeywordValue
= String
;
1174 return CurrentStringId
;
1175 } else if (CurrentStringId
== StringId
) {
1179 BlockSize
+= Offset
+ StringSize
;
1183 case EFI_HII_SIBT_STRING_UCS2_FONT
:
1184 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
1185 StringTextPtr
= BlockHdr
+ Offset
;
1187 // Use StringSize to store the size of the specified string, including the NULL
1190 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1192 *KeywordValue
= String
;
1193 return CurrentStringId
;
1194 } else if (CurrentStringId
== StringId
) {
1198 BlockSize
+= Offset
+ StringSize
;
1202 case EFI_HII_SIBT_STRINGS_UCS2
:
1203 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
1204 StringTextPtr
= BlockHdr
+ Offset
;
1205 BlockSize
+= Offset
;
1206 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1207 for (Index
= 0; Index
< StringCount
; Index
++) {
1208 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1211 *KeywordValue
= String
;
1212 return CurrentStringId
;
1213 } else if (CurrentStringId
== StringId
) {
1217 BlockSize
+= StringSize
;
1218 StringTextPtr
= StringTextPtr
+ StringSize
;
1223 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
1224 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
1225 StringTextPtr
= BlockHdr
+ Offset
;
1226 BlockSize
+= Offset
;
1229 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1232 for (Index
= 0; Index
< StringCount
; Index
++) {
1233 GetUnicodeStringTextAndSize (StringTextPtr
, &StringSize
, &String
);
1235 *KeywordValue
= String
;
1236 return CurrentStringId
;
1237 } else if (CurrentStringId
== StringId
) {
1241 BlockSize
+= StringSize
;
1242 StringTextPtr
= StringTextPtr
+ StringSize
;
1247 case EFI_HII_SIBT_DUPLICATE
:
1248 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
1252 case EFI_HII_SIBT_SKIP1
:
1253 SkipCount
= (UINT16
) (*(UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
1254 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
1255 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
1258 case EFI_HII_SIBT_SKIP2
:
1259 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
1260 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
1261 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
1264 case EFI_HII_SIBT_EXT1
:
1267 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1270 BlockSize
+= Length8
;
1273 case EFI_HII_SIBT_EXT2
:
1274 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1275 BlockSize
+= Ext2
.Length
;
1278 case EFI_HII_SIBT_EXT4
:
1281 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
1285 BlockSize
+= Length32
;
1292 if (String
!= NULL
) {
1297 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
1304 Get string package from the input NameSpace string.
1306 This is a internal function.
1308 @param DatabaseRecord HII_DATABASE_RECORD format string.
1309 @param NameSpace NameSpace format string.
1310 @param KeywordValue Keyword value.
1311 @param StringId String Id for this keyword.
1313 @retval KEYWORD_HANDLER_NO_ERROR Get String id successfully.
1314 @retval KEYWORD_HANDLER_KEYWORD_NOT_FOUND Not found the string id in the string package.
1315 @retval KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND Not found the string package for this namespace.
1316 @retval KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR Out of resource error.
1320 GetStringIdFromRecord (
1321 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1322 IN CHAR8
**NameSpace
,
1323 IN CHAR16
*KeywordValue
,
1324 OUT EFI_STRING_ID
*StringId
1328 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1329 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1334 ASSERT (DatabaseRecord
!= NULL
&& NameSpace
!= NULL
&& KeywordValue
!= NULL
);
1336 PackageListNode
= DatabaseRecord
->PackageList
;
1337 RetVal
= KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
1339 if (*NameSpace
!= NULL
) {
1342 Name
= UEFI_CONFIG_LANG
;
1345 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->StringPkgHdr
; Link
= Link
->ForwardLink
) {
1346 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1348 if (AsciiStrnCmp(Name
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (Name
)) == 0) {
1349 Status
= GetStringIdFromString (StringPackage
, KeywordValue
, StringId
);
1350 if (EFI_ERROR (Status
)) {
1351 return KEYWORD_HANDLER_KEYWORD_NOT_FOUND
;
1353 if (*NameSpace
== NULL
) {
1354 *NameSpace
= AllocateCopyPool (AsciiStrSize (StringPackage
->StringPkgHdr
->Language
), StringPackage
->StringPkgHdr
->Language
);
1355 if (*NameSpace
== NULL
) {
1356 return KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
1359 return KEYWORD_HANDLER_NO_ERROR
;
1368 Tell whether this Operand is an Statement OpCode.
1370 @param Operand Operand of an IFR OpCode.
1372 @retval TRUE This is an Statement OpCode.
1373 @retval FALSE Not an Statement OpCode.
1381 if ((Operand
== EFI_IFR_SUBTITLE_OP
) ||
1382 (Operand
== EFI_IFR_TEXT_OP
) ||
1383 (Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1384 (Operand
== EFI_IFR_REF_OP
) ||
1385 (Operand
== EFI_IFR_ACTION_OP
) ||
1386 (Operand
== EFI_IFR_NUMERIC_OP
) ||
1387 (Operand
== EFI_IFR_ORDERED_LIST_OP
) ||
1388 (Operand
== EFI_IFR_CHECKBOX_OP
) ||
1389 (Operand
== EFI_IFR_STRING_OP
) ||
1390 (Operand
== EFI_IFR_PASSWORD_OP
) ||
1391 (Operand
== EFI_IFR_DATE_OP
) ||
1392 (Operand
== EFI_IFR_TIME_OP
) ||
1393 (Operand
== EFI_IFR_GUID_OP
) ||
1394 (Operand
== EFI_IFR_ONE_OF_OP
)) {
1402 Tell whether this Operand is an Statement OpCode.
1404 @param Operand Operand of an IFR OpCode.
1406 @retval TRUE This is an Statement OpCode.
1407 @retval FALSE Not an Statement OpCode.
1415 if ((Operand
== EFI_IFR_VARSTORE_OP
) ||
1416 (Operand
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) ||
1417 (Operand
== EFI_IFR_VARSTORE_EFI_OP
)) {
1425 Base on the prompt string id to find the question.
1427 @param FormPackage The input form package.
1428 @param KeywordStrId The input prompt string id for one question.
1430 @retval the opcode for the question.
1434 FindQuestionFromStringId (
1435 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1436 IN EFI_STRING_ID KeywordStrId
1441 EFI_IFR_STATEMENT_HEADER
*StatementHeader
;
1442 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1445 ASSERT (FormPackage
!= NULL
);
1447 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1449 while (Offset
< FormDataLen
) {
1450 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1451 OpCodeHeader
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
1453 if (IsStatementOpCode(OpCodeHeader
->OpCode
)) {
1454 StatementHeader
= (EFI_IFR_STATEMENT_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
1455 if (StatementHeader
->Prompt
== KeywordStrId
) {
1460 Offset
+= OpCodeHeader
->Length
;
1467 Base on the varstore id to find the storage info.
1469 @param FormPackage The input form package.
1470 @param VarStoreId The input storage id.
1472 @retval the opcode for the storage.
1476 FindStorageFromVarId (
1477 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1478 IN EFI_VARSTORE_ID VarStoreId
1483 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1486 ASSERT (FormPackage
!= NULL
);
1488 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1490 while (Offset
< FormDataLen
) {
1491 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1492 OpCodeHeader
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
1494 if (IsStorageOpCode(OpCodeHeader
->OpCode
)) {
1495 switch (OpCodeHeader
->OpCode
) {
1496 case EFI_IFR_VARSTORE_OP
:
1497 if (VarStoreId
== ((EFI_IFR_VARSTORE
*) OpCodeData
)->VarStoreId
) {
1502 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1503 if (VarStoreId
== ((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->VarStoreId
) {
1508 case EFI_IFR_VARSTORE_EFI_OP
:
1509 if (VarStoreId
== ((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->VarStoreId
) {
1519 Offset
+= OpCodeHeader
->Length
;
1526 Get width info for one question.
1528 @param OpCodeData The input opcode for one question.
1530 @retval the width info for one question.
1535 IN UINT8
*OpCodeData
1538 UINT8
*NextOpCodeData
;
1540 ASSERT (OpCodeData
!= NULL
);
1542 switch (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
) {
1543 case EFI_IFR_REF_OP
:
1544 return (UINT16
) sizeof (EFI_HII_REF
);
1546 case EFI_IFR_ONE_OF_OP
:
1547 case EFI_IFR_NUMERIC_OP
:
1548 switch (((EFI_IFR_ONE_OF
*) OpCodeData
)->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1549 case EFI_IFR_NUMERIC_SIZE_1
:
1550 return (UINT16
) sizeof (UINT8
);
1552 case EFI_IFR_NUMERIC_SIZE_2
:
1553 return (UINT16
) sizeof (UINT16
);
1555 case EFI_IFR_NUMERIC_SIZE_4
:
1556 return (UINT16
) sizeof (UINT32
);
1558 case EFI_IFR_NUMERIC_SIZE_8
:
1559 return (UINT16
) sizeof (UINT64
);
1566 case EFI_IFR_ORDERED_LIST_OP
:
1567 NextOpCodeData
= OpCodeData
+ ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->Header
.Length
;
1569 // OneOfOption must follow the orderedlist opcode.
1571 ASSERT (((EFI_IFR_OP_HEADER
*) NextOpCodeData
)->OpCode
== EFI_IFR_ONE_OF_OPTION_OP
);
1572 switch (((EFI_IFR_ONE_OF_OPTION
*) NextOpCodeData
)->Type
) {
1573 case EFI_IFR_TYPE_NUM_SIZE_8
:
1574 return (UINT16
) sizeof (UINT8
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1576 case EFI_IFR_TYPE_NUM_SIZE_16
:
1577 return (UINT16
) sizeof (UINT16
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1579 case EFI_IFR_TYPE_NUM_SIZE_32
:
1580 return (UINT16
) sizeof (UINT32
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1582 case EFI_IFR_TYPE_NUM_SIZE_64
:
1583 return (UINT16
) sizeof (UINT64
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1590 case EFI_IFR_CHECKBOX_OP
:
1591 return (UINT16
) sizeof (BOOLEAN
);
1593 case EFI_IFR_PASSWORD_OP
:
1594 return (UINT16
)((UINTN
) ((EFI_IFR_PASSWORD
*) OpCodeData
)->MaxSize
* sizeof (CHAR16
));
1596 case EFI_IFR_STRING_OP
:
1597 return (UINT16
)((UINTN
) ((EFI_IFR_STRING
*) OpCodeData
)->MaxSize
* sizeof (CHAR16
));
1599 case EFI_IFR_DATE_OP
:
1600 return (UINT16
) sizeof (EFI_HII_DATE
);
1602 case EFI_IFR_TIME_OP
:
1603 return (UINT16
) sizeof (EFI_HII_TIME
);
1612 Converts all hex string characters in range ['A'..'F'] to ['a'..'f'] for
1613 hex digits that appear between a '=' and a '&' in a config string.
1615 If ConfigString is NULL, then ASSERT().
1617 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
1619 @return Pointer to the Null-terminated Unicode result string.
1624 InternalLowerConfigString (
1625 IN EFI_STRING ConfigString
1631 ASSERT (ConfigString
!= NULL
);
1634 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1636 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
1637 if (*String
== L
'=') {
1639 } else if (*String
== L
'&') {
1641 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
1642 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
1646 return ConfigString
;
1650 Allocates and returns a Null-terminated Unicode <ConfigHdr> string.
1652 The format of a <ConfigHdr> is as follows:
1654 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
1656 @param[in] OpCodeData The opcode for the storage.
1657 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
1658 that is the routing information PATH. Each byte of
1659 the Device Path associated with DriverHandle is converted
1660 to a 2 Unicode character hexadecimal string.
1662 @retval NULL DriverHandle does not support the Device Path Protocol.
1663 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
1667 ConstructConfigHdr (
1668 IN UINT8
*OpCodeData
,
1669 IN EFI_HANDLE DriverHandle
1673 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1674 UINTN DevicePathSize
;
1676 CHAR16
*ReturnString
;
1685 ASSERT (OpCodeData
!= NULL
);
1687 switch (((EFI_IFR_OP_HEADER
*)OpCodeData
)->OpCode
) {
1688 case EFI_IFR_VARSTORE_OP
:
1689 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE
*) OpCodeData
)->Guid
;
1690 AsciiName
= (CHAR8
*) ((EFI_IFR_VARSTORE
*) OpCodeData
)->Name
;
1693 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1694 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->Guid
;
1698 case EFI_IFR_VARSTORE_EFI_OP
:
1699 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Guid
;
1700 AsciiName
= (CHAR8
*) ((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Name
;
1710 if (AsciiName
!= NULL
) {
1711 NameSize
= AsciiStrSize (AsciiName
);
1712 Name
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1713 ASSERT (Name
!= NULL
);
1714 AsciiStrToUnicodeStrS (AsciiName
, Name
, NameSize
);
1720 // Compute the length of Name in Unicode characters.
1721 // If Name is NULL, then the length is 0.
1725 NameLength
= StrLen (Name
);
1731 // Retrieve DevicePath Protocol associated with DriverHandle
1733 if (DriverHandle
!= NULL
) {
1734 DevicePath
= DevicePathFromHandle (DriverHandle
);
1735 if (DevicePath
== NULL
) {
1739 // Compute the size of the device path in bytes
1741 DevicePathSize
= GetDevicePathSize (DevicePath
);
1745 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
1746 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
1748 MaxLen
= 5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1;
1749 String
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
1750 if (String
== NULL
) {
1755 // Start with L"GUID="
1757 StrCpyS (String
, MaxLen
, L
"GUID=");
1758 ReturnString
= String
;
1759 String
+= StrLen (String
);
1763 // Append Guid converted to <HexCh>32
1765 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
1766 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
1773 StrCatS (ReturnString
, MaxLen
, L
"&NAME=");
1774 String
+= StrLen (String
);
1778 // Append Name converted to <Char>NameLength
1780 for (; *Name
!= L
'\0'; Name
++) {
1781 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
1788 StrCatS (ReturnString
, MaxLen
, L
"&PATH=");
1789 String
+= StrLen (String
);
1792 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
1794 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
1795 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
1799 // Null terminate the Unicode string
1804 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1806 return InternalLowerConfigString (ReturnString
);
1810 Generate the Config request element for one question.
1812 @param Name The name info for one question.
1813 @param Offset The offset info for one question.
1814 @param Width The width info for one question.
1816 @return Pointer to the Null-terminated Unicode request element string.
1820 ConstructRequestElement (
1831 // Add <BlockName> length for each Name
1833 // <BlockName> ::= Name + \0
1836 Length
= StrLen (Name
) + 1;
1839 // Add <BlockName> length for each Offset/Width pair
1841 // <BlockName> ::= OFFSET=1234&WIDTH=1234 + \0
1842 // | 7 | 4 | 7 | 4 | 1
1844 Length
= (7 + 4 + 7 + 4 + 1);
1848 // Allocate buffer for the entire <ConfigRequest>
1850 StringPtr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1851 ASSERT (StringPtr
!= NULL
);
1859 (StrLen (Name
) + 1) * sizeof (CHAR16
),
1865 // Append OFFSET=XXXX&WIDTH=YYYY\0
1869 (7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1870 L
"OFFSET=%04X&WIDTH=%04X",
1880 Get string value for question's name field.
1882 @param DatabaseRecord HII_DATABASE_RECORD format string.
1883 @param NameId The string id for the name field.
1885 @retval Name string.
1890 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1891 IN EFI_STRING_ID NameId
1895 CHAR8
*PlatformLanguage
;
1896 CHAR8
*SupportedLanguages
;
1897 CHAR8
*BestLanguage
;
1903 BestLanguage
= NULL
;
1904 PlatformLanguage
= NULL
;
1905 SupportedLanguages
= NULL
;
1907 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
1908 SupportedLanguages
= GetSupportedLanguages(DatabaseRecord
->Handle
);
1911 // Get the best matching language from SupportedLanguages
1913 BestLanguage
= GetBestLanguage (
1915 FALSE
, // RFC 4646 mode
1916 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Highest priority
1917 SupportedLanguages
, // Lowest priority
1920 if (BestLanguage
== NULL
) {
1921 BestLanguage
= AllocateCopyPool (AsciiStrLen ("en-US"), "en-US");
1922 ASSERT (BestLanguage
!= NULL
);
1926 Status
= mPrivate
.HiiString
.GetString (
1927 &mPrivate
.HiiString
,
1929 DatabaseRecord
->Handle
,
1935 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1939 Name
= AllocateZeroPool (StringSize
);
1944 Status
= mPrivate
.HiiString
.GetString (
1945 &mPrivate
.HiiString
,
1947 DatabaseRecord
->Handle
,
1954 if (EFI_ERROR (Status
)) {
1961 if (SupportedLanguages
!= NULL
) {
1962 FreePool(SupportedLanguages
);
1964 if (BestLanguage
!= NULL
) {
1965 FreePool (BestLanguage
);
1967 if (PlatformLanguage
!= NULL
) {
1968 FreePool (PlatformLanguage
);
1975 Base on the input parameter to generate the ConfigRequest string.
1977 This is a internal function.
1979 @param DatabaseRecord HII_DATABASE_RECORD format string.
1980 @param KeywordStrId Keyword string id.
1981 @param OpCodeData The IFR data for this question.
1982 @param ConfigRequest Return the generate ConfigRequest string.
1984 @retval EFI_SUCCESS Generate ConfigResp string success.
1985 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
1986 @retval EFI_NOT_FOUND Not found the question which use this string id
1987 as the prompt string id.
1990 ExtractConfigRequest (
1991 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1992 IN EFI_STRING_ID KeywordStrId
,
1993 OUT UINT8
**OpCodeData
,
1994 OUT EFI_STRING
*ConfigRequest
1998 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1999 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
2000 EFI_IFR_QUESTION_HEADER
*Header
;
2007 CHAR16
*RequestElement
;
2011 ASSERT (DatabaseRecord
!= NULL
&& OpCodeData
!= NULL
&& ConfigRequest
!= NULL
);
2018 PackageListNode
= DatabaseRecord
->PackageList
;
2021 // Search the languages in the specified packagelist.
2023 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2024 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2026 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2027 if (OpCode
!= NULL
) {
2028 *OpCodeData
= OpCode
;
2029 Header
= (EFI_IFR_QUESTION_HEADER
*) (OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2031 // Header->VarStoreId == 0 means no storage for this question.
2033 ASSERT (Header
->VarStoreId
!= 0);
2034 DEBUG ((EFI_D_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2036 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2037 ASSERT (Storage
!= NULL
);
2039 if (((EFI_IFR_OP_HEADER
*) Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2040 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2042 Offset
= Header
->VarStoreInfo
.VarOffset
;
2043 Width
= GetWidth (OpCode
);
2045 RequestElement
= ConstructRequestElement(Name
, Offset
, Width
);
2046 ConfigHdr
= ConstructConfigHdr(Storage
, DatabaseRecord
->DriverHandle
);
2047 ASSERT (ConfigHdr
!= NULL
);
2049 MaxLen
= StrLen (ConfigHdr
) + 1 + StrLen(RequestElement
) + 1;
2050 *ConfigRequest
= AllocatePool (MaxLen
* sizeof (CHAR16
));
2051 if (*ConfigRequest
== NULL
) {
2052 FreePool (ConfigHdr
);
2053 FreePool (RequestElement
);
2054 return EFI_OUT_OF_RESOURCES
;
2056 StringPtr
= *ConfigRequest
;
2058 StrCpyS (StringPtr
, MaxLen
, ConfigHdr
);
2060 StrCatS (StringPtr
, MaxLen
, L
"&");
2062 StrCatS (StringPtr
, MaxLen
, RequestElement
);
2064 FreePool (ConfigHdr
);
2065 FreePool (RequestElement
);
2071 return EFI_NOT_FOUND
;
2075 Base on the input parameter to generate the ConfigResp string.
2077 This is a internal function.
2079 @param DatabaseRecord HII_DATABASE_RECORD format string.
2080 @param KeywordStrId Keyword string id.
2081 @param ValueElement The value for the question which use keyword string id
2082 as the prompt string id.
2083 @param OpCodeData The IFR data for this question.
2084 @param ConfigResp Return the generate ConfigResp string.
2086 @retval EFI_SUCCESS Generate ConfigResp string success.
2087 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
2088 @retval EFI_NOT_FOUND Not found the question which use this string id
2089 as the prompt string id.
2093 IN HII_DATABASE_RECORD
*DatabaseRecord
,
2094 IN EFI_STRING_ID KeywordStrId
,
2095 IN EFI_STRING ValueElement
,
2096 OUT UINT8
**OpCodeData
,
2097 OUT EFI_STRING
*ConfigResp
2101 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2102 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
2103 EFI_IFR_QUESTION_HEADER
*Header
;
2110 CHAR16
*RequestElement
;
2114 ASSERT ((DatabaseRecord
!= NULL
) && (OpCodeData
!= NULL
) && (ConfigResp
!= NULL
) && (ValueElement
!= NULL
));
2121 PackageListNode
= DatabaseRecord
->PackageList
;
2124 // Search the languages in the specified packagelist.
2126 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2127 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2129 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2130 if (OpCode
!= NULL
) {
2131 *OpCodeData
= OpCode
;
2132 Header
= (EFI_IFR_QUESTION_HEADER
*) (OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2134 // Header->VarStoreId == 0 means no storage for this question.
2136 ASSERT (Header
->VarStoreId
!= 0);
2137 DEBUG ((EFI_D_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2139 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2140 ASSERT (Storage
!= NULL
);
2142 if (((EFI_IFR_OP_HEADER
*) Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2143 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2145 Offset
= Header
->VarStoreInfo
.VarOffset
;
2146 Width
= GetWidth (OpCode
);
2148 RequestElement
= ConstructRequestElement(Name
, Offset
, Width
);
2150 ConfigHdr
= ConstructConfigHdr(Storage
, DatabaseRecord
->DriverHandle
);
2151 ASSERT (ConfigHdr
!= NULL
);
2153 MaxLen
= StrLen (ConfigHdr
) + 1 + StrLen(RequestElement
) + 1 + StrLen (L
"VALUE=") + StrLen(ValueElement
) + 1;
2154 *ConfigResp
= AllocatePool (MaxLen
* sizeof (CHAR16
));
2155 if (*ConfigResp
== NULL
) {
2156 FreePool (ConfigHdr
);
2157 FreePool (RequestElement
);
2158 return EFI_OUT_OF_RESOURCES
;
2160 StringPtr
= *ConfigResp
;
2162 StrCpyS (StringPtr
, MaxLen
, ConfigHdr
);
2164 StrCatS (StringPtr
, MaxLen
, L
"&");
2167 StrCatS (StringPtr
, MaxLen
, RequestElement
);
2169 StrCatS (StringPtr
, MaxLen
, L
"&");
2171 StrCatS (StringPtr
, MaxLen
, L
"VALUE=");
2173 StrCatS (StringPtr
, MaxLen
, ValueElement
);
2175 FreePool (ConfigHdr
);
2176 FreePool (RequestElement
);
2182 return EFI_NOT_FOUND
;
2186 Get the Value section from the Hii driver.
2188 This is a internal function.
2190 @param ConfigRequest The input ConfigRequest string.
2191 @param ValueElement The respond Value section from the hii driver.
2193 @retval Misc value The error status return from ExtractConfig function.
2194 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated
2195 @retval EFI_SUCCESS Get the value section success.
2199 ExtractValueFromDriver (
2200 IN CHAR16
*ConfigRequest
,
2201 OUT CHAR16
**ValueElement
2206 EFI_STRING Progress
;
2210 ASSERT ((ConfigRequest
!= NULL
) && (ValueElement
!= NULL
));
2212 Status
= mPrivate
.ConfigRouting
.ExtractConfig (
2213 &mPrivate
.ConfigRouting
,
2214 (EFI_STRING
) ConfigRequest
,
2218 if (EFI_ERROR (Status
)) {
2223 // Find Value Section and return it.
2225 StringPtr
= StrStr (Result
, L
"&VALUE=");
2226 ASSERT (StringPtr
!= NULL
);
2227 StringEnd
= StrStr (StringPtr
+ 1, L
"&");
2228 if (StringEnd
!= NULL
) {
2232 *ValueElement
= AllocateCopyPool (StrSize (StringPtr
), StringPtr
);
2233 if (*ValueElement
== NULL
) {
2234 return EFI_OUT_OF_RESOURCES
;
2237 if (StringEnd
!= NULL
) {
2246 Get EFI_STRING_ID info from the input device path, namespace and keyword.
2248 This is a internal function.
2250 @param DevicePath Input device path info.
2251 @param NameSpace NameSpace format string.
2252 @param KeywordData Keyword used to get string id.
2253 @param ProgressErr Return extra error type.
2254 @param KeywordStringId Return EFI_STRING_ID.
2255 @param DataBaseRecord DataBase record data for this driver.
2257 @retval EFI_INVALID_PARAMETER Can't find the database record base on the input device path or namespace.
2258 @retval EFI_NOT_FOUND Can't find the EFI_STRING_ID for the keyword.
2259 @retval EFI_SUCCESS Find the EFI_STRING_ID.
2263 GetStringIdFromDatabase (
2264 IN EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
2265 IN CHAR8
**NameSpace
,
2266 IN CHAR16
*KeywordData
,
2267 OUT UINT32
*ProgressErr
,
2268 OUT EFI_STRING_ID
*KeywordStringId
,
2269 OUT HII_DATABASE_RECORD
**DataBaseRecord
2272 HII_DATABASE_RECORD
*Record
;
2274 BOOLEAN FindNameSpace
;
2275 EFI_DEVICE_PATH_PROTOCOL
*DestDevicePath
;
2276 UINT8
*DevicePathPkg
;
2277 UINTN DevicePathSize
;
2279 ASSERT ((NameSpace
!= NULL
) && (KeywordData
!= NULL
) && (ProgressErr
!= NULL
) && (KeywordStringId
!= NULL
) && (DataBaseRecord
!= NULL
));
2281 FindNameSpace
= FALSE
;
2283 if (*DevicePath
!= NULL
) {
2285 // Get DataBaseRecord from device path protocol.
2287 Record
= GetRecordFromDevicePath(*DevicePath
);
2288 if (Record
== NULL
) {
2290 // Can't find the DatabaseRecord base on the input device path info.
2291 // NEED TO CONFIRM the return ProgressErr.
2293 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2294 return EFI_INVALID_PARAMETER
;
2298 // Get string id from the record.
2300 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2301 switch (*ProgressErr
) {
2302 case KEYWORD_HANDLER_NO_ERROR
:
2303 *DataBaseRecord
= Record
;
2306 case KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
:
2307 return EFI_INVALID_PARAMETER
;
2310 ASSERT (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
);
2311 return EFI_NOT_FOUND
;
2315 // Find driver which matches the routing data.
2317 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
2318 Record
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2320 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2321 if (*ProgressErr
== KEYWORD_HANDLER_NO_ERROR
) {
2322 *DataBaseRecord
= Record
;
2324 if ((DevicePathPkg
= Record
->PackageList
->DevicePathPkg
) != NULL
) {
2325 DestDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) (DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
));
2326 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DestDevicePath
);
2327 *DevicePath
= AllocateCopyPool (DevicePathSize
, DestDevicePath
);
2328 if (*DevicePath
== NULL
) {
2329 return EFI_OUT_OF_RESOURCES
;
2333 // Need to verify this ASSERT.
2339 } else if (*ProgressErr
== KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
) {
2340 return EFI_OUT_OF_RESOURCES
;
2341 } else if (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
) {
2342 FindNameSpace
= TRUE
;
2347 // When PathHdr not input, if ever find the namespace, will return KEYWORD_HANDLER_KEYWORD_NOT_FOUND.
2348 // This is a bit more progress than KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND.
2350 if (FindNameSpace
) {
2351 return EFI_NOT_FOUND
;
2353 return EFI_INVALID_PARAMETER
;
2359 Generate the KeywordResp String.
2361 <KeywordResp> ::= <NameSpaceId><PathHdr>'&'<Keyword>'&VALUE='<Number>['&READONLY']
2363 @param NameSpace NameSpace format string.
2364 @param DevicePath Input device path info.
2365 @param KeywordData Keyword used to get string id.
2366 @param ValueStr The value section for the keyword.
2367 @param ReadOnly Whether this value is readonly.
2368 @param KeywordResp Return the point to the KeywordResp string.
2370 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2371 @retval EFI_SUCCESS Generate the KeywordResp string.
2375 GenerateKeywordResp (
2376 IN CHAR8
*NameSpace
,
2377 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
2378 IN EFI_STRING KeywordData
,
2379 IN EFI_STRING ValueStr
,
2380 IN BOOLEAN ReadOnly
,
2381 OUT EFI_STRING
*KeywordResp
2387 CHAR16
*UnicodeNameSpace
;
2388 UINTN NameSpaceLength
;
2390 ASSERT ((NameSpace
!= NULL
) && (DevicePath
!= NULL
) && (KeywordData
!= NULL
) && (ValueStr
!= NULL
) && (KeywordResp
!= NULL
));
2393 // 1. Calculate the string length.
2396 // 1.1 NameSpaceId size.
2397 // 'NAMESPACE='<String>
2399 NameSpaceLength
= AsciiStrLen (NameSpace
);
2400 RespStrLen
= 10 + NameSpaceLength
;
2401 UnicodeNameSpace
= AllocatePool ((NameSpaceLength
+ 1) * sizeof (CHAR16
));
2402 if (UnicodeNameSpace
== NULL
) {
2403 return EFI_OUT_OF_RESOURCES
;
2405 AsciiStrToUnicodeStrS (NameSpace
, UnicodeNameSpace
, NameSpaceLength
+ 1);
2408 // 1.2 PathHdr size.
2409 // PATH=<UEFI binary Device Path represented as hex number>'&'
2410 // Attention: The output include the '&' at the end.
2414 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
2415 (VOID
*) DevicePath
,
2419 RespStrLen
+= StrLen (PathHdr
);
2422 // 1.3 Keyword section.
2423 // 'KEYWORD='<String>[':'<DecCh>(1/4)]
2425 RespStrLen
+= 8 + StrLen (KeywordData
);
2428 // 1.4 Value section.
2429 // ValueStr = '&VALUE='<Number>
2431 RespStrLen
+= StrLen (ValueStr
);
2434 // 1.5 ReadOnly Section.
2442 // 2. Allocate the buffer and create the KeywordResp string include '\0'.
2445 *KeywordResp
= AllocatePool (RespStrLen
* sizeof (CHAR16
));
2446 if (*KeywordResp
== NULL
) {
2447 if (UnicodeNameSpace
!= NULL
) {
2448 FreePool (UnicodeNameSpace
);
2451 return EFI_OUT_OF_RESOURCES
;
2453 RespStr
= *KeywordResp
;
2456 // 2.1 Copy NameSpaceId section.
2458 StrCpyS (RespStr
, RespStrLen
, L
"NAMESPACE=");
2460 StrCatS (RespStr
, RespStrLen
, UnicodeNameSpace
);
2463 // 2.2 Copy PathHdr section.
2465 StrCatS (RespStr
, RespStrLen
, PathHdr
);
2468 // 2.3 Copy Keyword section.
2470 StrCatS (RespStr
, RespStrLen
, L
"KEYWORD=");
2472 StrCatS (RespStr
, RespStrLen
, KeywordData
);
2475 // 2.4 Copy the Value section.
2477 StrCatS (RespStr
, RespStrLen
, ValueStr
);
2480 // 2.5 Copy ReadOnly section if exist.
2483 StrCatS (RespStr
, RespStrLen
, L
"&READONLY");
2486 if (UnicodeNameSpace
!= NULL
) {
2487 FreePool (UnicodeNameSpace
);
2489 if (PathHdr
!= NULL
) {
2497 Merge the KeywordResp String to MultiKeywordResp string.
2499 This is a internal function.
2501 @param MultiKeywordResp The existed multikeywordresp string.
2502 @param KeywordResp The input keywordResp string.
2504 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2505 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2509 MergeToMultiKeywordResp (
2510 IN OUT EFI_STRING
*MultiKeywordResp
,
2511 IN EFI_STRING
*KeywordResp
2514 UINTN MultiKeywordRespLen
;
2515 EFI_STRING StringPtr
;
2517 if (*MultiKeywordResp
== NULL
) {
2518 *MultiKeywordResp
= *KeywordResp
;
2519 *KeywordResp
= NULL
;
2523 MultiKeywordRespLen
= (StrLen (*MultiKeywordResp
) + 1 + StrLen (*KeywordResp
) + 1) * sizeof (CHAR16
);
2525 StringPtr
= AllocateCopyPool (MultiKeywordRespLen
, *MultiKeywordResp
);
2526 if (StringPtr
== NULL
) {
2527 return EFI_OUT_OF_RESOURCES
;
2530 FreePool (*MultiKeywordResp
);
2531 *MultiKeywordResp
= StringPtr
;
2533 StrCatS (StringPtr
, MultiKeywordRespLen
/ sizeof (CHAR16
), L
"&");
2535 StrCatS (StringPtr
, MultiKeywordRespLen
/ sizeof (CHAR16
), *KeywordResp
);
2541 Enumerate all keyword in the system.
2543 If error occur when parse one keyword, just skip it and parse the next one.
2545 This is a internal function.
2547 @param NameSpace The namespace used to search the string.
2548 @param MultiResp Return the MultiKeywordResp string for the system.
2549 @param ProgressErr Return the error status.
2551 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2552 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2553 @retval EFI_NOT_FOUND No keyword found.
2557 EnumerateAllKeywords (
2558 IN CHAR8
*NameSpace
,
2559 OUT EFI_STRING
*MultiResp
,
2560 OUT UINT32
*ProgressErr
2564 LIST_ENTRY
*StringLink
;
2565 UINT8
*DevicePathPkg
;
2567 HII_DATABASE_RECORD
*DataBaseRecord
;
2568 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2569 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
2570 CHAR8
*LocalNameSpace
;
2571 EFI_STRING_ID NextStringId
;
2574 CHAR16
*ConfigRequest
;
2575 CHAR16
*ValueElement
;
2576 CHAR16
*KeywordResp
;
2577 CHAR16
*MultiKeywordResp
;
2578 CHAR16
*KeywordData
;
2580 BOOLEAN FindKeywordPackages
;
2582 DataBaseRecord
= NULL
;
2583 Status
= EFI_SUCCESS
;
2584 MultiKeywordResp
= NULL
;
2586 LocalNameSpace
= NULL
;
2587 ConfigRequest
= NULL
;
2588 ValueElement
= NULL
;
2590 FindKeywordPackages
= FALSE
;
2592 if (NameSpace
== NULL
) {
2593 NameSpace
= UEFI_CONFIG_LANG
;
2597 // Find driver which matches the routing data.
2599 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
2600 DataBaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2601 if ((DevicePathPkg
= DataBaseRecord
->PackageList
->DevicePathPkg
) != NULL
) {
2602 DevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2604 PackageListNode
= DataBaseRecord
->PackageList
;
2606 for (StringLink
= PackageListNode
->StringPkgHdr
.ForwardLink
; StringLink
!= &PackageListNode
->StringPkgHdr
; StringLink
= StringLink
->ForwardLink
) {
2607 StringPackage
= CR (StringLink
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
2610 // Check whether has keyword string package.
2612 if (AsciiStrnCmp(NameSpace
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (NameSpace
)) == 0) {
2613 FindKeywordPackages
= TRUE
;
2615 // Keep the NameSpace string.
2617 LocalNameSpace
= AllocateCopyPool (AsciiStrSize (StringPackage
->StringPkgHdr
->Language
), StringPackage
->StringPkgHdr
->Language
);
2618 if (LocalNameSpace
== NULL
) {
2619 return EFI_OUT_OF_RESOURCES
;
2623 // 1 means just begin the enumerate the valid string ids.
2624 // StringId == 1 is always used to save the language for this string package.
2625 // Any valid string start from 2. so here initial it to 1.
2630 // Enumerate all valid stringid in the package.
2632 while ((NextStringId
= GetNextStringId (StringPackage
, NextStringId
, &KeywordData
)) != 0) {
2634 // 3.3 Construct the ConfigRequest string.
2636 Status
= ExtractConfigRequest (DataBaseRecord
, NextStringId
, &OpCode
, &ConfigRequest
);
2637 if (EFI_ERROR (Status
)) {
2639 // If can't generate ConfigRequest for this question, skip it and start the next.
2645 // 3.4 Extract Value for the input keyword.
2647 Status
= ExtractValueFromDriver(ConfigRequest
, &ValueElement
);
2648 if (EFI_ERROR (Status
)) {
2649 if (Status
!= EFI_OUT_OF_RESOURCES
) {
2651 // If can't generate ConfigRequest for this question, skip it and start the next.
2656 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2662 // Extract readonly flag from opcode.
2664 ReadOnly
= ExtractReadOnlyFromOpCode(OpCode
);
2667 // 5. Generate KeywordResp string.
2669 ASSERT (DevicePath
!= NULL
);
2670 Status
= GenerateKeywordResp(LocalNameSpace
, (EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
, KeywordData
, ValueElement
, ReadOnly
, &KeywordResp
);
2671 if (Status
!= EFI_SUCCESS
) {
2673 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2679 // 6. Merge to the MultiKeywordResp string.
2681 Status
= MergeToMultiKeywordResp(&MultiKeywordResp
, &KeywordResp
);
2682 if (EFI_ERROR (Status
)) {
2687 // Clean the temp buffer to later use again.
2689 if (ConfigRequest
!= NULL
) {
2690 FreePool (ConfigRequest
);
2691 ConfigRequest
= NULL
;
2693 if (ValueElement
!= NULL
) {
2694 FreePool (ValueElement
);
2695 ValueElement
= NULL
;
2697 if (KeywordResp
!= NULL
) {
2698 FreePool (KeywordResp
);
2703 if (LocalNameSpace
!= NULL
) {
2704 FreePool (LocalNameSpace
);
2705 LocalNameSpace
= NULL
;
2712 // return the already get MultiKeywordString even error occurred.
2714 if (MultiKeywordResp
== NULL
) {
2715 Status
= EFI_NOT_FOUND
;
2716 if (!FindKeywordPackages
) {
2717 *ProgressErr
= KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
2719 *ProgressErr
= KEYWORD_HANDLER_KEYWORD_NOT_FOUND
;
2722 Status
= EFI_SUCCESS
;
2724 *MultiResp
= MultiKeywordResp
;
2727 if (LocalNameSpace
!= NULL
) {
2728 FreePool (LocalNameSpace
);
2730 if (ConfigRequest
!= NULL
) {
2731 FreePool (ConfigRequest
);
2733 if (ValueElement
!= NULL
) {
2734 FreePool (ValueElement
);
2742 This function accepts a <MultiKeywordResp> formatted string, finds the associated
2743 keyword owners, creates a <MultiConfigResp> string from it and forwards it to the
2744 EFI_HII_ROUTING_PROTOCOL.RouteConfig function.
2746 If there is an issue in resolving the contents of the KeywordString, then the
2747 function returns an error and also sets the Progress and ProgressErr with the
2748 appropriate information about where the issue occurred and additional data about
2749 the nature of the issue.
2751 In the case when KeywordString containing multiple keywords, when an EFI_NOT_FOUND
2752 error is generated during processing the second or later keyword element, the system
2753 storage associated with earlier keywords is not modified. All elements of the
2754 KeywordString must successfully pass all tests for format and access prior to making
2755 any modifications to storage.
2757 In the case when EFI_DEVICE_ERROR is returned from the processing of a KeywordString
2758 containing multiple keywords, the state of storage associated with earlier keywords
2762 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
2764 @param KeywordString A null-terminated string in <MultiKeywordResp> format.
2766 @param Progress On return, points to a character in the KeywordString.
2767 Points to the string's NULL terminator if the request
2768 was successful. Points to the most recent '&' before
2769 the first failing name / value pair (or the beginning
2770 of the string if the failure is in the first name / value
2771 pair) if the request was not successful.
2773 @param ProgressErr If during the processing of the KeywordString there was
2774 a failure, this parameter gives additional information
2775 about the possible source of the problem. The various
2776 errors are defined in "Related Definitions" below.
2779 @retval EFI_SUCCESS The specified action was completed successfully.
2781 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
2782 1. KeywordString is NULL.
2783 2. Parsing of the KeywordString resulted in an
2784 error. See Progress and ProgressErr for more data.
2786 @retval EFI_NOT_FOUND An element of the KeywordString was not found.
2787 See ProgressErr for more data.
2789 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2790 See ProgressErr for more data.
2792 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr
2795 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
2801 EfiConfigKeywordHandlerSetData (
2802 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
2803 IN CONST EFI_STRING KeywordString
,
2804 OUT EFI_STRING
*Progress
,
2805 OUT UINT32
*ProgressErr
2811 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2812 CHAR16
*NextStringPtr
;
2813 CHAR16
*KeywordData
;
2814 EFI_STRING_ID KeywordStringId
;
2816 HII_DATABASE_RECORD
*DataBaseRecord
;
2819 CHAR16
*MultiConfigResp
;
2820 CHAR16
*ValueElement
;
2822 EFI_STRING InternalProgress
;
2824 CHAR16
*KeywordStartPos
;
2826 if (This
== NULL
|| Progress
== NULL
|| ProgressErr
== NULL
|| KeywordString
== NULL
) {
2827 return EFI_INVALID_PARAMETER
;
2830 *Progress
= KeywordString
;
2831 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
2832 Status
= EFI_SUCCESS
;
2833 MultiConfigResp
= NULL
;
2837 ValueElement
= NULL
;
2839 KeywordStartPos
= NULL
;
2840 KeywordStringId
= 0;
2843 // Use temp string to avoid changing input string buffer.
2845 TempString
= AllocateCopyPool (StrSize (KeywordString
), KeywordString
);
2846 ASSERT (TempString
!= NULL
);
2847 StringPtr
= TempString
;
2849 while ((StringPtr
!= NULL
) && (*StringPtr
!= L
'\0')) {
2851 // 1. Get NameSpace from NameSpaceId keyword.
2853 Status
= ExtractNameSpace (StringPtr
, &NameSpace
, &NextStringPtr
);
2854 if (EFI_ERROR (Status
)) {
2855 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2858 ASSERT (NameSpace
!= NULL
);
2860 // 1.1 Check whether the input namespace is valid.
2862 if (AsciiStrnCmp(NameSpace
, UEFI_CONFIG_LANG
, AsciiStrLen (UEFI_CONFIG_LANG
)) != 0) {
2863 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2864 Status
= EFI_INVALID_PARAMETER
;
2868 StringPtr
= NextStringPtr
;
2871 // 2. Get possible Device Path info from KeywordString.
2873 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
2874 if (EFI_ERROR (Status
)) {
2875 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2878 StringPtr
= NextStringPtr
;
2881 // 3. Extract keyword from the KeywordRequest string.
2883 KeywordStartPos
= StringPtr
;
2884 Status
= ExtractKeyword(StringPtr
, &KeywordData
, &NextStringPtr
);
2885 if (EFI_ERROR (Status
)) {
2887 // Can't find Keyword base on the input device path info.
2889 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2890 Status
= EFI_INVALID_PARAMETER
;
2893 StringPtr
= NextStringPtr
;
2896 // 4. Extract Value from the KeywordRequest string.
2898 Status
= ExtractValue (StringPtr
, &ValueElement
, &NextStringPtr
);
2899 if (EFI_ERROR (Status
)) {
2901 // Can't find Value base on the input device path info.
2903 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2904 Status
= EFI_INVALID_PARAMETER
;
2907 StringPtr
= NextStringPtr
;
2910 // 5. Find READONLY tag.
2912 if ((StringPtr
!= NULL
) && StrnCmp (StringPtr
, L
"&READONLY", StrLen (L
"&READONLY")) == 0) {
2914 StringPtr
+= StrLen (L
"&READONLY");
2920 // 6. Get EFI_STRING_ID for the input keyword.
2922 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
2923 if (EFI_ERROR (Status
)) {
2924 *ProgressErr
= RetVal
;
2929 // 7. Construct the ConfigRequest string.
2931 Status
= ExtractConfigResp (DataBaseRecord
, KeywordStringId
, ValueElement
, &OpCode
, &ConfigResp
);
2932 if (EFI_ERROR (Status
)) {
2937 // 8. Check the readonly flag.
2939 if (ExtractReadOnlyFromOpCode (OpCode
) != ReadOnly
) {
2941 // Extracting readonly flag form opcode and extracting "READONLY" tag form KeywordString should have the same results.
2942 // If not, the input KeywordString must be incorrect, return the error status to caller.
2944 *ProgressErr
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
2945 Status
= EFI_INVALID_PARAMETER
;
2949 *ProgressErr
= KEYWORD_HANDLER_ACCESS_NOT_PERMITTED
;
2950 Status
= EFI_ACCESS_DENIED
;
2955 // 9. Merge to the MultiKeywordResp string.
2957 Status
= MergeToMultiKeywordResp(&MultiConfigResp
, &ConfigResp
);
2958 if (EFI_ERROR (Status
)) {
2963 // 10. Clean the temp buffer point.
2965 FreePool (NameSpace
);
2966 FreePool (DevicePath
);
2967 FreePool (KeywordData
);
2968 FreePool (ValueElement
);
2972 ValueElement
= NULL
;
2973 if (ConfigResp
!= NULL
) {
2974 FreePool (ConfigResp
);
2977 KeywordStartPos
= NULL
;
2981 // 11. Set value to driver.
2983 Status
= mPrivate
.ConfigRouting
.RouteConfig(
2984 &mPrivate
.ConfigRouting
,
2985 (EFI_STRING
) MultiConfigResp
,
2988 if (EFI_ERROR (Status
)) {
2989 Status
= EFI_DEVICE_ERROR
;
2993 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
2996 if (KeywordStartPos
!= NULL
) {
2997 *Progress
= KeywordString
+ (KeywordStartPos
- TempString
);
2999 *Progress
= KeywordString
+ (StringPtr
- TempString
);
3002 ASSERT (TempString
!= NULL
);
3003 FreePool (TempString
);
3004 if (NameSpace
!= NULL
) {
3005 FreePool (NameSpace
);
3007 if (DevicePath
!= NULL
) {
3008 FreePool (DevicePath
);
3010 if (KeywordData
!= NULL
) {
3011 FreePool (KeywordData
);
3013 if (ValueElement
!= NULL
) {
3014 FreePool (ValueElement
);
3016 if (ConfigResp
!= NULL
) {
3017 FreePool (ConfigResp
);
3019 if (MultiConfigResp
!= NULL
&& MultiConfigResp
!= ConfigResp
) {
3020 FreePool (MultiConfigResp
);
3028 This function accepts a <MultiKeywordRequest> formatted string, finds the underlying
3029 keyword owners, creates a <MultiConfigRequest> string from it and forwards it to the
3030 EFI_HII_ROUTING_PROTOCOL.ExtractConfig function.
3032 If there is an issue in resolving the contents of the KeywordString, then the function
3033 returns an EFI_INVALID_PARAMETER and also set the Progress and ProgressErr with the
3034 appropriate information about where the issue occurred and additional data about the
3035 nature of the issue.
3037 In the case when KeywordString is NULL, or contains multiple keywords, or when
3038 EFI_NOT_FOUND is generated while processing the keyword elements, the Results string
3039 contains values returned for all keywords processed prior to the keyword generating the
3040 error but no values for the keyword with error or any following keywords.
3043 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
3045 @param NameSpaceId A null-terminated string containing the platform configuration
3046 language to search through in the system. If a NULL is passed
3047 in, then it is assumed that any platform configuration language
3048 with the prefix of "x-UEFI-" are searched.
3050 @param KeywordString A null-terminated string in <MultiKeywordRequest> format. If a
3051 NULL is passed in the KeywordString field, all of the known
3052 keywords in the system for the NameSpaceId specified are
3053 returned in the Results field.
3055 @param Progress On return, points to a character in the KeywordString. Points
3056 to the string's NULL terminator if the request was successful.
3057 Points to the most recent '&' before the first failing name / value
3058 pair (or the beginning of the string if the failure is in the first
3059 name / value pair) if the request was not successful.
3061 @param ProgressErr If during the processing of the KeywordString there was a
3062 failure, this parameter gives additional information about the
3063 possible source of the problem. See the definitions in SetData()
3064 for valid value definitions.
3066 @param Results A null-terminated string in <MultiKeywordResp> format is returned
3067 which has all the values filled in for the keywords in the
3068 KeywordString. This is a callee-allocated field, and must be freed
3069 by the caller after being used.
3071 @retval EFI_SUCCESS The specified action was completed successfully.
3073 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
3074 1.Progress, ProgressErr, or Results is NULL.
3075 2.Parsing of the KeywordString resulted in an error. See
3076 Progress and ProgressErr for more data.
3079 @retval EFI_NOT_FOUND An element of the KeywordString was not found. See
3080 ProgressErr for more data.
3082 @retval EFI_NOT_FOUND The NamespaceId specified was not found. See ProgressErr
3085 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated. See
3086 ProgressErr for more data.
3088 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr for
3091 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
3097 EfiConfigKeywordHandlerGetData (
3098 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
3099 IN CONST EFI_STRING NameSpaceId
, OPTIONAL
3100 IN CONST EFI_STRING KeywordString
, OPTIONAL
3101 OUT EFI_STRING
*Progress
,
3102 OUT UINT32
*ProgressErr
,
3103 OUT EFI_STRING
*Results
3108 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
3109 HII_DATABASE_RECORD
*DataBaseRecord
;
3111 CHAR16
*NextStringPtr
;
3112 CHAR16
*KeywordData
;
3113 EFI_STRING_ID KeywordStringId
;
3115 CHAR16
*ConfigRequest
;
3116 CHAR16
*ValueElement
;
3119 CHAR16
*KeywordResp
;
3120 CHAR16
*MultiKeywordResp
;
3123 if (This
== NULL
|| Progress
== NULL
|| ProgressErr
== NULL
|| Results
== NULL
) {
3124 return EFI_INVALID_PARAMETER
;
3127 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
3128 Status
= EFI_SUCCESS
;
3132 ConfigRequest
= NULL
;
3133 StringPtr
= KeywordString
;
3135 MultiKeywordResp
= NULL
;
3136 KeywordStringId
= 0;
3140 // Use temp string to avoid changing input string buffer.
3142 if (NameSpaceId
!= NULL
) {
3143 TempString
= AllocateCopyPool (StrSize (NameSpaceId
), NameSpaceId
);
3144 ASSERT (TempString
!= NULL
);
3147 // 1. Get NameSpace from NameSpaceId keyword.
3149 Status
= ExtractNameSpace (TempString
, &NameSpace
, NULL
);
3150 if (TempString
!= NULL
) {
3151 FreePool (TempString
);
3154 if (EFI_ERROR (Status
)) {
3155 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3159 // 1.1 Check whether the input namespace is valid.
3161 if (NameSpace
!= NULL
){
3162 if (AsciiStrnCmp(NameSpace
, UEFI_CONFIG_LANG
, AsciiStrLen (UEFI_CONFIG_LANG
)) != 0) {
3163 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3164 return EFI_INVALID_PARAMETER
;
3168 if (KeywordString
!= NULL
) {
3170 // Use temp string to avoid changing input string buffer.
3172 TempString
= AllocateCopyPool (StrSize (KeywordString
), KeywordString
);
3173 ASSERT (TempString
!= NULL
);
3174 StringPtr
= TempString
;
3176 while (*StringPtr
!= L
'\0') {
3178 // 2. Get possible Device Path info from KeywordString.
3180 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
3181 if (EFI_ERROR (Status
)) {
3182 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3185 StringPtr
= NextStringPtr
;
3189 // 3. Process Keyword section from the input keywordRequest string.
3191 // 3.1 Extract keyword from the KeywordRequest string.
3193 Status
= ExtractKeyword(StringPtr
, &KeywordData
, &NextStringPtr
);
3194 if (EFI_ERROR (Status
)) {
3196 // Can't find Keyword base on the input device path info.
3198 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3199 Status
= EFI_INVALID_PARAMETER
;
3204 // 3.2 Get EFI_STRING_ID for the input keyword.
3206 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
3207 if (EFI_ERROR (Status
)) {
3208 *ProgressErr
= RetVal
;
3213 // 3.3 Construct the ConfigRequest string.
3215 Status
= ExtractConfigRequest (DataBaseRecord
, KeywordStringId
, &OpCode
, &ConfigRequest
);
3216 if (EFI_ERROR (Status
)) {
3221 // 3.4 Extract Value for the input keyword.
3223 Status
= ExtractValueFromDriver(ConfigRequest
, &ValueElement
);
3224 if (EFI_ERROR (Status
)) {
3225 if (Status
!= EFI_OUT_OF_RESOURCES
) {
3226 Status
= EFI_DEVICE_ERROR
;
3230 StringPtr
= NextStringPtr
;
3233 // 4. Process the possible filter section.
3235 RetVal
= ValidateFilter (OpCode
, StringPtr
, &NextStringPtr
, &ReadOnly
);
3236 if (RetVal
!= KEYWORD_HANDLER_NO_ERROR
) {
3237 *ProgressErr
= RetVal
;
3238 Status
= EFI_INVALID_PARAMETER
;
3241 StringPtr
= NextStringPtr
;
3245 // 5. Generate KeywordResp string.
3247 Status
= GenerateKeywordResp(NameSpace
, DevicePath
, KeywordData
, ValueElement
, ReadOnly
, &KeywordResp
);
3248 if (Status
!= EFI_SUCCESS
) {
3253 // 6. Merge to the MultiKeywordResp string.
3255 Status
= MergeToMultiKeywordResp(&MultiKeywordResp
, &KeywordResp
);
3256 if (EFI_ERROR (Status
)) {
3261 // 7. Update return value.
3263 *Results
= MultiKeywordResp
;
3266 // 8. Clean the temp buffer.
3268 FreePool (DevicePath
);
3269 FreePool (KeywordData
);
3270 FreePool (ValueElement
);
3271 FreePool (ConfigRequest
);
3274 ValueElement
= NULL
;
3275 ConfigRequest
= NULL
;
3276 if (KeywordResp
!= NULL
) {
3277 FreePool (KeywordResp
);
3283 // Enumerate all keyword in the system.
3285 Status
= EnumerateAllKeywords(NameSpace
, &MultiKeywordResp
, ProgressErr
);
3286 if (EFI_ERROR (Status
)) {
3289 *Results
= MultiKeywordResp
;
3292 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
3295 *Progress
= KeywordString
+ (StringPtr
- TempString
);
3297 if (TempString
!= NULL
) {
3298 FreePool (TempString
);
3300 if (NameSpace
!= NULL
) {
3301 FreePool (NameSpace
);
3303 if (DevicePath
!= NULL
) {
3304 FreePool (DevicePath
);
3306 if (KeywordData
!= NULL
) {
3307 FreePool (KeywordData
);