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
;
1325 ASSERT (DatabaseRecord
!= NULL
&& NameSpace
!= NULL
&& KeywordValue
!= NULL
);
1327 PackageListNode
= DatabaseRecord
->PackageList
;
1329 if (*NameSpace
!= NULL
) {
1332 Name
= UEFI_CONFIG_LANG
;
1335 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->StringPkgHdr
; Link
= Link
->ForwardLink
) {
1336 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1338 if (AsciiStrnCmp(Name
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (Name
)) == 0) {
1339 Status
= GetStringIdFromString (StringPackage
, KeywordValue
, StringId
);
1340 if (EFI_ERROR (Status
)) {
1341 return KEYWORD_HANDLER_KEYWORD_NOT_FOUND
;
1343 if (*NameSpace
== NULL
) {
1344 *NameSpace
= AllocateCopyPool (AsciiStrSize (StringPackage
->StringPkgHdr
->Language
), StringPackage
->StringPkgHdr
->Language
);
1345 if (*NameSpace
== NULL
) {
1346 return KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
1349 return KEYWORD_HANDLER_NO_ERROR
;
1354 return KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
1358 Tell whether this Operand is an Statement OpCode.
1360 @param Operand Operand of an IFR OpCode.
1362 @retval TRUE This is an Statement OpCode.
1363 @retval FALSE Not an Statement OpCode.
1371 if ((Operand
== EFI_IFR_SUBTITLE_OP
) ||
1372 (Operand
== EFI_IFR_TEXT_OP
) ||
1373 (Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1374 (Operand
== EFI_IFR_REF_OP
) ||
1375 (Operand
== EFI_IFR_ACTION_OP
) ||
1376 (Operand
== EFI_IFR_NUMERIC_OP
) ||
1377 (Operand
== EFI_IFR_ORDERED_LIST_OP
) ||
1378 (Operand
== EFI_IFR_CHECKBOX_OP
) ||
1379 (Operand
== EFI_IFR_STRING_OP
) ||
1380 (Operand
== EFI_IFR_PASSWORD_OP
) ||
1381 (Operand
== EFI_IFR_DATE_OP
) ||
1382 (Operand
== EFI_IFR_TIME_OP
) ||
1383 (Operand
== EFI_IFR_GUID_OP
) ||
1384 (Operand
== EFI_IFR_ONE_OF_OP
)) {
1392 Tell whether this Operand is an Statement OpCode.
1394 @param Operand Operand of an IFR OpCode.
1396 @retval TRUE This is an Statement OpCode.
1397 @retval FALSE Not an Statement OpCode.
1405 if ((Operand
== EFI_IFR_VARSTORE_OP
) ||
1406 (Operand
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) ||
1407 (Operand
== EFI_IFR_VARSTORE_EFI_OP
)) {
1415 Base on the prompt string id to find the question.
1417 @param FormPackage The input form package.
1418 @param KeywordStrId The input prompt string id for one question.
1420 @retval the opcode for the question.
1424 FindQuestionFromStringId (
1425 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1426 IN EFI_STRING_ID KeywordStrId
1431 EFI_IFR_STATEMENT_HEADER
*StatementHeader
;
1432 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1435 ASSERT (FormPackage
!= NULL
);
1437 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1439 while (Offset
< FormDataLen
) {
1440 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1441 OpCodeHeader
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
1443 if (IsStatementOpCode(OpCodeHeader
->OpCode
)) {
1444 StatementHeader
= (EFI_IFR_STATEMENT_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
1445 if (StatementHeader
->Prompt
== KeywordStrId
) {
1450 Offset
+= OpCodeHeader
->Length
;
1457 Base on the varstore id to find the storage info.
1459 @param FormPackage The input form package.
1460 @param VarStoreId The input storage id.
1462 @retval the opcode for the storage.
1466 FindStorageFromVarId (
1467 IN HII_IFR_PACKAGE_INSTANCE
*FormPackage
,
1468 IN EFI_VARSTORE_ID VarStoreId
1473 EFI_IFR_OP_HEADER
*OpCodeHeader
;
1476 ASSERT (FormPackage
!= NULL
);
1478 FormDataLen
= FormPackage
->FormPkgHdr
.Length
- sizeof (EFI_HII_PACKAGE_HEADER
);
1480 while (Offset
< FormDataLen
) {
1481 OpCodeData
= FormPackage
->IfrData
+ Offset
;
1482 OpCodeHeader
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
1484 if (IsStorageOpCode(OpCodeHeader
->OpCode
)) {
1485 switch (OpCodeHeader
->OpCode
) {
1486 case EFI_IFR_VARSTORE_OP
:
1487 if (VarStoreId
== ((EFI_IFR_VARSTORE
*) OpCodeData
)->VarStoreId
) {
1492 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1493 if (VarStoreId
== ((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->VarStoreId
) {
1498 case EFI_IFR_VARSTORE_EFI_OP
:
1499 if (VarStoreId
== ((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->VarStoreId
) {
1509 Offset
+= OpCodeHeader
->Length
;
1516 Get width info for one question.
1518 @param OpCodeData The input opcode for one question.
1520 @retval the width info for one question.
1525 IN UINT8
*OpCodeData
1528 UINT8
*NextOpCodeData
;
1530 ASSERT (OpCodeData
!= NULL
);
1532 switch (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
) {
1533 case EFI_IFR_REF_OP
:
1534 return (UINT16
) sizeof (EFI_HII_REF
);
1536 case EFI_IFR_ONE_OF_OP
:
1537 case EFI_IFR_NUMERIC_OP
:
1538 switch (((EFI_IFR_ONE_OF
*) OpCodeData
)->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1539 case EFI_IFR_NUMERIC_SIZE_1
:
1540 return (UINT16
) sizeof (UINT8
);
1542 case EFI_IFR_NUMERIC_SIZE_2
:
1543 return (UINT16
) sizeof (UINT16
);
1545 case EFI_IFR_NUMERIC_SIZE_4
:
1546 return (UINT16
) sizeof (UINT32
);
1548 case EFI_IFR_NUMERIC_SIZE_8
:
1549 return (UINT16
) sizeof (UINT64
);
1556 case EFI_IFR_ORDERED_LIST_OP
:
1557 NextOpCodeData
= OpCodeData
+ ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->Header
.Length
;
1559 // OneOfOption must follow the orderedlist opcode.
1561 ASSERT (((EFI_IFR_OP_HEADER
*) NextOpCodeData
)->OpCode
== EFI_IFR_ONE_OF_OPTION_OP
);
1562 switch (((EFI_IFR_ONE_OF_OPTION
*) NextOpCodeData
)->Type
) {
1563 case EFI_IFR_TYPE_NUM_SIZE_8
:
1564 return (UINT16
) sizeof (UINT8
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1566 case EFI_IFR_TYPE_NUM_SIZE_16
:
1567 return (UINT16
) sizeof (UINT16
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1569 case EFI_IFR_TYPE_NUM_SIZE_32
:
1570 return (UINT16
) sizeof (UINT32
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1572 case EFI_IFR_TYPE_NUM_SIZE_64
:
1573 return (UINT16
) sizeof (UINT64
) * ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1581 case EFI_IFR_CHECKBOX_OP
:
1582 return (UINT16
) sizeof (BOOLEAN
);
1584 case EFI_IFR_PASSWORD_OP
:
1585 case EFI_IFR_STRING_OP
:
1586 return (UINT16
)((UINTN
) ((EFI_IFR_STRING
*) OpCodeData
)->MaxSize
* sizeof (CHAR16
));
1588 case EFI_IFR_DATE_OP
:
1589 return (UINT16
) sizeof (EFI_HII_DATE
);
1591 case EFI_IFR_TIME_OP
:
1592 return (UINT16
) sizeof (EFI_HII_TIME
);
1601 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
1602 hex digits that appear between a '=' and a '&' in a config string.
1604 If ConfigString is NULL, then ASSERT().
1606 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
1608 @return Pointer to the Null-terminated Unicode result string.
1613 InternalLowerConfigString (
1614 IN EFI_STRING ConfigString
1620 ASSERT (ConfigString
!= NULL
);
1623 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1625 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
1626 if (*String
== L
'=') {
1628 } else if (*String
== L
'&') {
1630 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
1631 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
1635 return ConfigString
;
1639 Allocates and returns a Null-terminated Unicode <ConfigHdr> string.
1641 The format of a <ConfigHdr> is as follows:
1643 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
1645 @param[in] OpCodeData The opcode for the storage.
1646 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
1647 that is the routing information PATH. Each byte of
1648 the Device Path associated with DriverHandle is converted
1649 to a 2 Unicode character hexidecimal string.
1651 @retval NULL DriverHandle does not support the Device Path Protocol.
1652 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
1656 ConstructConfigHdr (
1657 IN UINT8
*OpCodeData
,
1658 IN EFI_HANDLE DriverHandle
1662 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1663 UINTN DevicePathSize
;
1665 CHAR16
*ReturnString
;
1672 ASSERT (OpCodeData
!= NULL
);
1674 switch (((EFI_IFR_OP_HEADER
*)OpCodeData
)->OpCode
) {
1675 case EFI_IFR_VARSTORE_OP
:
1676 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE
*) OpCodeData
)->Guid
;
1677 AsciiName
= (CHAR8
*) ((EFI_IFR_VARSTORE
*) OpCodeData
)->Name
;
1680 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1681 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->Guid
;
1685 case EFI_IFR_VARSTORE_EFI_OP
:
1686 Guid
= (EFI_GUID
*)(UINTN
*)&((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Guid
;
1687 AsciiName
= (CHAR8
*) ((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Name
;
1697 if (AsciiName
!= NULL
) {
1698 Name
= AllocateZeroPool (AsciiStrSize (AsciiName
) * 2);
1699 ASSERT (Name
!= NULL
);
1700 AsciiStrToUnicodeStr(AsciiName
, Name
);
1706 // Compute the length of Name in Unicode characters.
1707 // If Name is NULL, then the length is 0.
1711 NameLength
= StrLen (Name
);
1717 // Retrieve DevicePath Protocol associated with DriverHandle
1719 if (DriverHandle
!= NULL
) {
1720 DevicePath
= DevicePathFromHandle (DriverHandle
);
1721 if (DevicePath
== NULL
) {
1725 // Compute the size of the device path in bytes
1727 DevicePathSize
= GetDevicePathSize (DevicePath
);
1731 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
1732 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
1734 String
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
));
1735 if (String
== NULL
) {
1740 // Start with L"GUID="
1742 ReturnString
= StrCpy (String
, L
"GUID=");
1743 String
+= StrLen (String
);
1747 // Append Guid converted to <HexCh>32
1749 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
1750 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
1757 StrCpy (String
, L
"&NAME=");
1758 String
+= StrLen (String
);
1762 // Append Name converted to <Char>NameLength
1764 for (; *Name
!= L
'\0'; Name
++) {
1765 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
1772 StrCpy (String
, L
"&PATH=");
1773 String
+= StrLen (String
);
1776 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
1778 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
1779 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
1783 // Null terminate the Unicode string
1788 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1790 return InternalLowerConfigString (ReturnString
);
1794 Generate the Config request element for one question.
1796 @param Name The name info for one question.
1797 @param Offset The offset info for one question.
1798 @param Width The width info for one question.
1800 @return Pointer to the Null-terminated Unicode request element string.
1804 ConstructRequestElement (
1815 // Add <BlockName> length for each Name
1817 // <BlockName> ::= Name + \0
1820 Length
= StrLen (Name
) + 1;
1823 // Add <BlockName> length for each Offset/Width pair
1825 // <BlockName> ::= OFFSET=1234&WIDTH=1234 + \0
1826 // | 7 | 4 | 7 | 4 | 1
1828 Length
= (7 + 4 + 7 + 4 + 1);
1832 // Allocate buffer for the entire <ConfigRequest>
1834 StringPtr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1835 ASSERT (StringPtr
!= NULL
);
1843 (StrLen (Name
) + 1) * sizeof (CHAR16
),
1849 // Append OFFSET=XXXX&WIDTH=YYYY\0
1853 (7 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1854 L
"OFFSET=%04X&WIDTH=%04X",
1864 Get string value for question's name field.
1866 @param DatabaseRecord HII_DATABASE_RECORD format string.
1867 @param NameId The string id for the name field.
1869 @retval Name string.
1874 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1875 IN EFI_STRING_ID NameId
1879 CHAR8
*PlatformLanguage
;
1880 CHAR8
*SupportedLanguages
;
1881 CHAR8
*BestLanguage
;
1887 BestLanguage
= NULL
;
1888 PlatformLanguage
= NULL
;
1889 SupportedLanguages
= NULL
;
1891 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
1892 SupportedLanguages
= GetSupportedLanguages(DatabaseRecord
->Handle
);
1895 // Get the best matching language from SupportedLanguages
1897 BestLanguage
= GetBestLanguage (
1899 FALSE
, // RFC 4646 mode
1900 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Highest priority
1901 SupportedLanguages
, // Lowest priority
1904 if (BestLanguage
== NULL
) {
1905 BestLanguage
= AllocateCopyPool (AsciiStrLen ("en-US"), "en-US");
1906 ASSERT (BestLanguage
!= NULL
);
1910 Status
= mPrivate
.HiiString
.GetString (
1911 &mPrivate
.HiiString
,
1913 DatabaseRecord
->Handle
,
1919 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1923 Name
= AllocateZeroPool (StringSize
);
1928 Status
= mPrivate
.HiiString
.GetString (
1929 &mPrivate
.HiiString
,
1931 DatabaseRecord
->Handle
,
1938 if (EFI_ERROR (Status
)) {
1945 if (SupportedLanguages
!= NULL
) {
1946 FreePool(SupportedLanguages
);
1948 if (BestLanguage
!= NULL
) {
1949 FreePool (BestLanguage
);
1951 if (PlatformLanguage
!= NULL
) {
1952 FreePool (PlatformLanguage
);
1959 Base on the input parameter to generate the ConfigRequest string.
1961 This is a internal function.
1963 @param DatabaseRecord HII_DATABASE_RECORD format string.
1964 @param KeywordStrId Keyword string id.
1965 @param OpCodeData The IFR data for this question.
1966 @param ConfigRequest Return the generate ConfigRequest string.
1968 @retval EFI_SUCCESS Generate ConfigResp string success.
1969 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
1970 @retval EFI_NOT_FOUND Not found the question which use this string id
1971 as the prompt string id.
1974 ExtractConfigRequest (
1975 IN HII_DATABASE_RECORD
*DatabaseRecord
,
1976 IN EFI_STRING_ID KeywordStrId
,
1977 OUT UINT8
**OpCodeData
,
1978 OUT EFI_STRING
*ConfigRequest
1982 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1983 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
1984 EFI_IFR_QUESTION_HEADER
*Header
;
1991 CHAR16
*RequestElement
;
1995 ASSERT (DatabaseRecord
!= NULL
&& OpCodeData
!= NULL
&& ConfigRequest
!= NULL
);
2002 PackageListNode
= DatabaseRecord
->PackageList
;
2005 // Search the languages in the specified packagelist.
2007 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2008 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2010 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2011 if (OpCode
!= NULL
) {
2012 *OpCodeData
= OpCode
;
2013 Header
= (EFI_IFR_QUESTION_HEADER
*) (OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2015 // Header->VarStoreId == 0 means no storage for this question.
2017 ASSERT (Header
->VarStoreId
!= 0);
2018 DEBUG ((EFI_D_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2020 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2021 ASSERT (Storage
!= NULL
);
2023 if (((EFI_IFR_OP_HEADER
*) Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2024 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2026 Offset
= Header
->VarStoreInfo
.VarOffset
;
2027 Width
= GetWidth (OpCode
);
2029 RequestElement
= ConstructRequestElement(Name
, Offset
, Width
);
2030 ConfigHdr
= ConstructConfigHdr(Storage
, DatabaseRecord
->DriverHandle
);
2032 Length
= (StrLen (ConfigHdr
) + 1 + StrLen(RequestElement
) + 1) * sizeof (CHAR16
);
2033 *ConfigRequest
= AllocatePool (Length
);
2034 if (*ConfigRequest
== NULL
) {
2035 FreePool (ConfigHdr
);
2036 FreePool (RequestElement
);
2037 return EFI_OUT_OF_RESOURCES
;
2039 StringPtr
= *ConfigRequest
;
2041 StrCpy (StringPtr
, ConfigHdr
);
2042 StringPtr
+= StrLen (StringPtr
);
2047 StrCpy (StringPtr
, RequestElement
);
2048 StringPtr
+= StrLen (StringPtr
);
2051 FreePool (ConfigHdr
);
2052 FreePool (RequestElement
);
2058 return EFI_NOT_FOUND
;
2062 Base on the input parameter to generate the ConfigResp string.
2064 This is a internal function.
2066 @param DatabaseRecord HII_DATABASE_RECORD format string.
2067 @param KeywordStrId Keyword string id.
2068 @param ValueElement The value for the question which use keyword string id
2069 as the prompt string id.
2070 @param OpCodeData The IFR data for this question.
2071 @param ConfigResp Return the generate ConfigResp string.
2073 @retval EFI_SUCCESS Generate ConfigResp string success.
2074 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
2075 @retval EFI_NOT_FOUND Not found the question which use this string id
2076 as the prompt string id.
2080 IN HII_DATABASE_RECORD
*DatabaseRecord
,
2081 IN EFI_STRING_ID KeywordStrId
,
2082 IN EFI_STRING ValueElement
,
2083 OUT UINT8
**OpCodeData
,
2084 OUT EFI_STRING
*ConfigResp
2088 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2089 HII_IFR_PACKAGE_INSTANCE
*FormPackage
;
2090 EFI_IFR_QUESTION_HEADER
*Header
;
2097 CHAR16
*RequestElement
;
2101 ASSERT ((DatabaseRecord
!= NULL
) && (OpCodeData
!= NULL
) && (ConfigResp
!= NULL
) && (ValueElement
!= NULL
));
2108 PackageListNode
= DatabaseRecord
->PackageList
;
2111 // Search the languages in the specified packagelist.
2113 for (Link
= PackageListNode
->FormPkgHdr
.ForwardLink
; Link
!= &PackageListNode
->FormPkgHdr
; Link
= Link
->ForwardLink
) {
2114 FormPackage
= CR (Link
, HII_IFR_PACKAGE_INSTANCE
, IfrEntry
, HII_IFR_PACKAGE_SIGNATURE
);
2116 OpCode
= FindQuestionFromStringId (FormPackage
, KeywordStrId
);
2117 if (OpCode
!= NULL
) {
2118 *OpCodeData
= OpCode
;
2119 Header
= (EFI_IFR_QUESTION_HEADER
*) (OpCode
+ sizeof (EFI_IFR_OP_HEADER
));
2121 // Header->VarStoreId == 0 means no storage for this question.
2123 ASSERT (Header
->VarStoreId
!= 0);
2124 DEBUG ((EFI_D_INFO
, "Varstore Id: 0x%x\n", Header
->VarStoreId
));
2126 Storage
= FindStorageFromVarId (FormPackage
, Header
->VarStoreId
);
2127 ASSERT (Storage
!= NULL
);
2129 if (((EFI_IFR_OP_HEADER
*) Storage
)->OpCode
== EFI_IFR_VARSTORE_NAME_VALUE_OP
) {
2130 Name
= GetNameFromId (DatabaseRecord
, Header
->VarStoreInfo
.VarName
);
2132 Offset
= Header
->VarStoreInfo
.VarOffset
;
2133 Width
= GetWidth (OpCode
);
2135 RequestElement
= ConstructRequestElement(Name
, Offset
, Width
);
2137 ConfigHdr
= ConstructConfigHdr(Storage
, DatabaseRecord
->DriverHandle
);
2139 Length
= (StrLen (ConfigHdr
) + 1 + StrLen(RequestElement
) + 1 + StrLen (L
"VALUE=") + StrLen(ValueElement
) + 1) * sizeof (CHAR16
);
2140 *ConfigResp
= AllocatePool (Length
);
2141 if (*ConfigResp
== NULL
) {
2142 FreePool (ConfigHdr
);
2143 FreePool (RequestElement
);
2144 return EFI_OUT_OF_RESOURCES
;
2146 StringPtr
= *ConfigResp
;
2148 StrCpy (StringPtr
, ConfigHdr
);
2149 StringPtr
+= StrLen (StringPtr
);
2154 StrCpy (StringPtr
, RequestElement
);
2155 StringPtr
+= StrLen (StringPtr
);
2160 StrCpy (StringPtr
, L
"VALUE=");
2161 StringPtr
+= StrLen (StringPtr
);
2163 StrCpy (StringPtr
, ValueElement
);
2164 StringPtr
+= StrLen (StringPtr
);
2167 FreePool (ConfigHdr
);
2168 FreePool (RequestElement
);
2174 return EFI_NOT_FOUND
;
2178 Get the Value section from the Hii driver.
2180 This is a internal function.
2182 @param ConfigRequest The input ConfigRequest string.
2183 @param ValueElement The respond Value section from the hii driver.
2185 @retval Misc value The error status return from ExtractConfig function.
2186 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated
2187 @retval EFI_SUCCESS Get the value section success.
2191 ExtractValueFromDriver (
2192 IN CHAR16
*ConfigRequest
,
2193 OUT CHAR16
**ValueElement
2198 EFI_STRING Progress
;
2202 ASSERT ((ConfigRequest
!= NULL
) && (ValueElement
!= NULL
));
2204 Status
= mPrivate
.ConfigRouting
.ExtractConfig (
2205 &mPrivate
.ConfigRouting
,
2206 (EFI_STRING
) ConfigRequest
,
2210 if (EFI_ERROR (Status
)) {
2215 // Find Value Section and return it.
2217 StringPtr
= StrStr (Result
, L
"&VALUE=");
2218 ASSERT (StringPtr
!= NULL
);
2219 StringEnd
= StrStr (StringPtr
+ 1, L
"&");
2220 if (StringEnd
!= NULL
) {
2224 *ValueElement
= AllocateCopyPool (StrSize (StringPtr
), StringPtr
);
2225 if (*ValueElement
== NULL
) {
2226 return EFI_OUT_OF_RESOURCES
;
2229 if (StringEnd
!= NULL
) {
2238 Get EFI_STRING_ID info from the input device path, namespace and keyword.
2240 This is a internal function.
2242 @param DevicePath Input device path info.
2243 @param NameSpace NameSpace format string.
2244 @param KeywordData Keyword used to get string id.
2245 @param ProgressErr Return extra error type.
2246 @param KeywordStringId Return EFI_STRING_ID.
2247 @param DataBaseRecord DataBase record data for this driver.
2249 @retval EFI_INVALID_PARAMETER Can't find the database record base on the input device path or namespace.
2250 @retval EFI_NOT_FOUND Can't find the EFI_STRING_ID for the keyword.
2251 @retval EFI_SUCCESS Find the EFI_STRING_ID.
2255 GetStringIdFromDatabase (
2256 IN EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
2257 IN CHAR8
**NameSpace
,
2258 IN CHAR16
*KeywordData
,
2259 OUT UINT32
*ProgressErr
,
2260 OUT EFI_STRING_ID
*KeywordStringId
,
2261 OUT HII_DATABASE_RECORD
**DataBaseRecord
2264 HII_DATABASE_RECORD
*Record
;
2266 BOOLEAN FindNameSpace
;
2267 EFI_DEVICE_PATH_PROTOCOL
*DestDevicePath
;
2268 UINT8
*DevicePathPkg
;
2269 UINTN DevicePathSize
;
2271 ASSERT ((NameSpace
!= NULL
) && (KeywordData
!= NULL
) && (ProgressErr
!= NULL
) && (KeywordStringId
!= NULL
) && (DataBaseRecord
!= NULL
));
2273 FindNameSpace
= FALSE
;
2275 if (*DevicePath
!= NULL
) {
2277 // Get DataBaseRecord from device path protocol.
2279 Record
= GetRecordFromDevicePath(*DevicePath
);
2280 if (Record
== NULL
) {
2282 // Can't find the DatabaseRecord base on the input device path info.
2283 // NEED TO CONFIRM the return ProgressErr.
2285 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2286 return EFI_INVALID_PARAMETER
;
2290 // Get string id from the record.
2292 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2293 switch (*ProgressErr
) {
2294 case KEYWORD_HANDLER_NO_ERROR
:
2295 *DataBaseRecord
= Record
;
2298 case KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
:
2299 return EFI_INVALID_PARAMETER
;
2302 ASSERT (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
);
2303 return EFI_NOT_FOUND
;
2307 // Find driver which matches the routing data.
2309 for (Link
= mPrivate
.DatabaseList
.ForwardLink
; Link
!= &mPrivate
.DatabaseList
; Link
= Link
->ForwardLink
) {
2310 Record
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2312 *ProgressErr
= GetStringIdFromRecord (Record
, NameSpace
, KeywordData
, KeywordStringId
);
2313 if (*ProgressErr
== KEYWORD_HANDLER_NO_ERROR
) {
2314 *DataBaseRecord
= Record
;
2316 if ((DevicePathPkg
= Record
->PackageList
->DevicePathPkg
) != NULL
) {
2317 DestDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) (DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
));
2318 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DestDevicePath
);
2319 *DevicePath
= AllocateCopyPool (DevicePathSize
, DestDevicePath
);
2320 if (*DevicePath
== NULL
) {
2321 return EFI_OUT_OF_RESOURCES
;
2325 // Need to verify this ASSERT.
2331 } else if (*ProgressErr
== KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
) {
2332 return EFI_OUT_OF_RESOURCES
;
2333 } else if (*ProgressErr
== KEYWORD_HANDLER_KEYWORD_NOT_FOUND
) {
2334 FindNameSpace
= TRUE
;
2339 // When PathHdr not input, if ever find the namespace, will return KEYWORD_HANDLER_KEYWORD_NOT_FOUND.
2340 // This is a bit more progress than KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND.
2342 if (FindNameSpace
) {
2343 return EFI_NOT_FOUND
;
2345 return EFI_INVALID_PARAMETER
;
2351 Genereate the KeywordResp String.
2353 <KeywordResp> ::= <NameSpaceId><PathHdr>'&'<Keyword>'&VALUE='<Number>['&READONLY']
2355 @param NameSpace NameSpace format string.
2356 @param DevicePath Input device path info.
2357 @param KeywordData Keyword used to get string id.
2358 @param ValueStr The value section for the keyword.
2359 @param ReadOnly Whether this value is readonly.
2360 @param KeywordResp Return the point to the KeywordResp string.
2362 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2363 @retval EFI_SUCCESS Generate the KeywordResp string.
2367 GenerateKeywordResp (
2368 IN CHAR8
*NameSpace
,
2369 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
2370 IN EFI_STRING KeywordData
,
2371 IN EFI_STRING ValueStr
,
2372 IN BOOLEAN ReadOnly
,
2373 OUT EFI_STRING
*KeywordResp
2379 CHAR16
*UnicodeNameSpace
;
2381 ASSERT ((NameSpace
!= NULL
) && (DevicePath
!= NULL
) && (KeywordData
!= NULL
) && (ValueStr
!= NULL
) && (KeywordResp
!= NULL
));
2384 // 1. Calculate the string length.
2387 // 1.1 NameSpaceId size.
2388 // 'NAMESPACE='<String>
2390 RespStrLen
= 10 + AsciiStrLen (NameSpace
);
2391 UnicodeNameSpace
= AllocatePool ((AsciiStrLen (NameSpace
) + 1) * sizeof (CHAR16
));
2392 if (UnicodeNameSpace
== NULL
) {
2393 return EFI_OUT_OF_RESOURCES
;
2395 AsciiStrToUnicodeStr(NameSpace
, UnicodeNameSpace
);
2398 // 1.2 PathHdr size.
2399 // PATH=<UEFI binary Device Path represented as hex number>'&'
2400 // Attention: The output include the '&' at the end.
2404 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
2405 (VOID
*) DevicePath
,
2409 RespStrLen
+= StrLen (PathHdr
);
2412 // 1.3 Keyword setion.
2413 // 'KEYWORD='<String>[':'<DecCh>(1/4)]
2415 RespStrLen
+= 8 + StrLen (KeywordData
);
2418 // 1.4 Value section.
2419 // ValueStr = '&VALUE='<Number>
2421 RespStrLen
+= StrLen (ValueStr
);
2424 // 1.5 ReadOnly Section.
2432 // 2. Allocate the buffer and create the KeywordResp string.
2434 *KeywordResp
= AllocatePool ((RespStrLen
+ 1) * sizeof (CHAR16
));
2435 if (*KeywordResp
== NULL
) {
2436 if (UnicodeNameSpace
!= NULL
) {
2437 FreePool (UnicodeNameSpace
);
2440 return EFI_OUT_OF_RESOURCES
;
2442 RespStr
= *KeywordResp
;
2445 // 2.1 Copy NameSpaceId section.
2447 StrCpy (RespStr
, L
"NAMESPACE=");
2448 RespStr
+= StrLen (RespStr
);
2449 StrCpy (RespStr
, UnicodeNameSpace
);
2450 RespStr
+= StrLen (RespStr
);
2453 // 2.2 Copy PathHdr section.
2455 StrCpy (RespStr
, PathHdr
);
2456 RespStr
+= StrLen (RespStr
);
2459 // 2.3 Copy Keyword section.
2461 StrCpy (RespStr
, L
"KEYWORD=");
2462 RespStr
+= StrLen (RespStr
);
2463 StrCpy (RespStr
, KeywordData
);
2464 RespStr
+= StrLen (RespStr
);
2467 // 2.4 Copy the Value section.
2469 StrCpy (RespStr
, ValueStr
);
2470 RespStr
+= StrLen (RespStr
);
2473 // 2.5 Copy ReadOnly section if exist.
2476 StrCpy (RespStr
, L
"&READONLY");
2477 RespStr
+= StrLen (RespStr
);
2485 if (UnicodeNameSpace
!= NULL
) {
2486 FreePool (UnicodeNameSpace
);
2488 if (PathHdr
!= NULL
) {
2496 Merge the KeywordResp String to MultiKeywordResp string.
2498 This is a internal function.
2500 @param MultiKeywordResp The existed multikeywordresp string.
2501 @param KeywordResp The input keywordResp string.
2503 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2504 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2508 MergeToMultiKeywordResp (
2509 IN OUT EFI_STRING
*MultiKeywordResp
,
2510 IN EFI_STRING
*KeywordResp
2513 UINTN MultiKeywordRespLen
;
2514 EFI_STRING StringPtr
;
2516 if (*MultiKeywordResp
== NULL
) {
2517 *MultiKeywordResp
= *KeywordResp
;
2518 *KeywordResp
= NULL
;
2522 MultiKeywordRespLen
= (StrLen (*MultiKeywordResp
) + 1 + StrLen (*KeywordResp
) + 1) * sizeof (CHAR16
);
2524 StringPtr
= AllocateCopyPool (MultiKeywordRespLen
, *MultiKeywordResp
);
2525 if (StringPtr
== NULL
) {
2526 return EFI_OUT_OF_RESOURCES
;
2529 FreePool (*MultiKeywordResp
);
2530 *MultiKeywordResp
= StringPtr
;
2532 StringPtr
+= StrLen (StringPtr
);
2537 StrCpy (StringPtr
, *KeywordResp
);
2543 Enumerate all keyword in the system.
2545 If error occur when parse one keyword, just skip it and parse the next one.
2547 This is a internal function.
2549 @param NameSpace The namespace used to search the string.
2550 @param MultiResp Return the MultiKeywordResp string for the system.
2552 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2553 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2554 @retval EFI_NOT_FOUND No keyword found.
2558 EnumerateAllKeywords (
2559 IN CHAR8
*NameSpace
,
2560 OUT EFI_STRING
*MultiResp
2564 LIST_ENTRY
*StringLink
;
2565 UINT8
*DevicePathPkg
;
2567 HII_DATABASE_RECORD
*DataBaseRecord
;
2568 UINTN DevicePathSize
;
2569 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
2570 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
2571 CHAR8
*LocalNameSpace
;
2572 EFI_STRING_ID NextStringId
;
2575 CHAR16
*ConfigRequest
;
2576 CHAR16
*ValueElement
;
2577 CHAR16
*KeywordResp
;
2578 CHAR16
*MultiKeywordResp
;
2579 CHAR16
*KeywordData
;
2582 DataBaseRecord
= NULL
;
2584 Status
= EFI_SUCCESS
;
2585 MultiKeywordResp
= NULL
;
2587 LocalNameSpace
= NULL
;
2588 ConfigRequest
= NULL
;
2589 ValueElement
= NULL
;
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
);
2603 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
);
2605 PackageListNode
= DataBaseRecord
->PackageList
;
2607 for (StringLink
= PackageListNode
->StringPkgHdr
.ForwardLink
; StringLink
!= &PackageListNode
->StringPkgHdr
; StringLink
= StringLink
->ForwardLink
) {
2608 StringPackage
= CR (StringLink
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
2611 // Check whether has keyword string package.
2613 if (AsciiStrnCmp(NameSpace
, StringPackage
->StringPkgHdr
->Language
, AsciiStrLen (NameSpace
)) == 0) {
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 occured.
2714 if (MultiKeywordResp
== NULL
) {
2715 Status
= EFI_NOT_FOUND
;
2717 Status
= EFI_SUCCESS
;
2719 *MultiResp
= MultiKeywordResp
;
2722 if (LocalNameSpace
!= NULL
) {
2723 FreePool (LocalNameSpace
);
2725 if (ConfigRequest
!= NULL
) {
2726 FreePool (ConfigRequest
);
2728 if (ValueElement
!= NULL
) {
2729 FreePool (ValueElement
);
2737 This function accepts a <MultiKeywordResp> formatted string, finds the associated
2738 keyword owners, creates a <MultiConfigResp> string from it and forwards it to the
2739 EFI_HII_ROUTING_PROTOCOL.RouteConfig function.
2741 If there is an issue in resolving the contents of the KeywordString, then the
2742 function returns an error and also sets the Progress and ProgressErr with the
2743 appropriate information about where the issue occurred and additional data about
2744 the nature of the issue.
2746 In the case when KeywordString containing multiple keywords, when an EFI_NOT_FOUND
2747 error is generated during processing the second or later keyword element, the system
2748 storage associated with earlier keywords is not modified. All elements of the
2749 KeywordString must successfully pass all tests for format and access prior to making
2750 any modifications to storage.
2752 In the case when EFI_DEVICE_ERROR is returned from the processing of a KeywordString
2753 containing multiple keywords, the state of storage associated with earlier keywords
2757 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
2759 @param KeywordString A null-terminated string in <MultiKeywordResp> format.
2761 @param Progress On return, points to a character in the KeywordString.
2762 Points to the string's NULL terminator if the request
2763 was successful. Points to the most recent '&' before
2764 the first failing string element if the request was
2767 @param ProgressErr If during the processing of the KeywordString there was
2768 a failure, this parameter gives additional information
2769 about the possible source of the problem. The various
2770 errors are defined in "Related Definitions" below.
2773 @retval EFI_SUCCESS The specified action was completed successfully.
2775 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
2776 1. KeywordString is NULL.
2777 2. Parsing of the KeywordString resulted in an
2778 error. See Progress and ProgressErr for more data.
2780 @retval EFI_NOT_FOUND An element of the KeywordString was not found.
2781 See ProgressErr for more data.
2783 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2784 See ProgressErr for more data.
2786 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr
2789 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
2795 EfiConfigKeywordHandlerSetData (
2796 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
2797 IN CONST EFI_STRING KeywordString
,
2798 OUT EFI_STRING
*Progress
,
2799 OUT UINT32
*ProgressErr
2805 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2806 CHAR16
*NextStringPtr
;
2807 CHAR16
*KeywordData
;
2808 EFI_STRING_ID KeywordStringId
;
2810 HII_DATABASE_RECORD
*DataBaseRecord
;
2813 CHAR16
*MultiConfigResp
;
2814 CHAR16
*ValueElement
;
2816 EFI_STRING InternalProgress
;
2818 if (This
== NULL
|| Progress
== NULL
|| ProgressErr
== NULL
|| KeywordString
== NULL
) {
2819 return EFI_INVALID_PARAMETER
;
2822 *Progress
= KeywordString
;
2823 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
2824 Status
= EFI_SUCCESS
;
2825 StringPtr
= KeywordString
;
2826 MultiConfigResp
= NULL
;
2830 ValueElement
= NULL
;
2832 KeywordStringId
= 0;
2834 while ((StringPtr
!= NULL
) && (*StringPtr
!= L
'\0')) {
2836 // 1. Get NameSpace from NameSpaceId keyword.
2838 Status
= ExtractNameSpace (StringPtr
, &NameSpace
, &NextStringPtr
);
2839 if (EFI_ERROR (Status
)) {
2840 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2843 StringPtr
= NextStringPtr
;
2846 // 2. Get possible Device Path info from KeywordString.
2848 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
2849 if (EFI_ERROR (Status
)) {
2850 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2853 StringPtr
= NextStringPtr
;
2856 // 3. Extract keyword from the KeywordRequest string.
2858 Status
= ExtractKeyword(StringPtr
, &KeywordData
, &NextStringPtr
);
2859 if (EFI_ERROR (Status
)) {
2861 // Can't find Keyword base on the input device path info.
2863 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2864 Status
= EFI_INVALID_PARAMETER
;
2867 StringPtr
= NextStringPtr
;
2870 // 4. Extract Value from the KeywordRequest string.
2872 Status
= ExtractValue (StringPtr
, &ValueElement
, &NextStringPtr
);
2873 if (EFI_ERROR (Status
)) {
2875 // Can't find Value base on the input device path info.
2877 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
2878 Status
= EFI_INVALID_PARAMETER
;
2881 StringPtr
= NextStringPtr
;
2884 // 5. Find ReadOnly filter.
2886 if ((StringPtr
!= NULL
) && StrnCmp (StringPtr
, L
"&ReadOnly", StrLen (L
"&ReadOnly")) == 0) {
2888 StringPtr
+= StrLen (L
"&ReadOnly");
2894 // 6. Get EFI_STRING_ID for the input keyword.
2896 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
2897 if (EFI_ERROR (Status
)) {
2898 *ProgressErr
= RetVal
;
2903 // 7. Construct the ConfigRequest string.
2905 Status
= ExtractConfigResp (DataBaseRecord
, KeywordStringId
, ValueElement
, &OpCode
, &ConfigResp
);
2906 if (EFI_ERROR (Status
)) {
2911 // 8. Check the readonly flag.
2913 if (ExtractReadOnlyFromOpCode (OpCode
) != ReadOnly
) {
2914 *ProgressErr
= KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED
;
2915 Status
= EFI_INVALID_PARAMETER
;
2920 // 9. Merge to the MultiKeywordResp string.
2922 Status
= MergeToMultiKeywordResp(&MultiConfigResp
, &ConfigResp
);
2923 if (EFI_ERROR (Status
)) {
2928 // 10. Clean the temp buffer point.
2930 FreePool (NameSpace
);
2931 FreePool (DevicePath
);
2932 FreePool (KeywordData
);
2933 FreePool (ValueElement
);
2937 ValueElement
= NULL
;
2938 if (ConfigResp
!= NULL
) {
2939 FreePool (ConfigResp
);
2945 // 11. Set value to driver.
2947 Status
= mPrivate
.ConfigRouting
.RouteConfig(
2948 &mPrivate
.ConfigRouting
,
2949 (EFI_STRING
) MultiConfigResp
,
2952 if (EFI_ERROR (Status
)) {
2953 Status
= EFI_DEVICE_ERROR
;
2957 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
2960 if (NameSpace
!= NULL
) {
2961 FreePool (NameSpace
);
2963 if (DevicePath
!= NULL
) {
2964 FreePool (DevicePath
);
2966 if (KeywordData
!= NULL
) {
2967 FreePool (KeywordData
);
2969 if (ValueElement
!= NULL
) {
2970 FreePool (ValueElement
);
2972 if (ConfigResp
!= NULL
) {
2973 FreePool (ConfigResp
);
2975 if (MultiConfigResp
!= NULL
&& MultiConfigResp
!= ConfigResp
) {
2976 FreePool (MultiConfigResp
);
2978 *Progress
= StringPtr
;
2984 This function accepts a <MultiKeywordRequest> formatted string, finds the underlying
2985 keyword owners, creates a <MultiConfigRequest> string from it and forwards it to the
2986 EFI_HII_ROUTING_PROTOCOL.ExtractConfig function.
2988 If there is an issue in resolving the contents of the KeywordString, then the function
2989 returns an EFI_INVALID_PARAMETER and also set the Progress and ProgressErr with the
2990 appropriate information about where the issue occurred and additional data about the
2991 nature of the issue.
2993 In the case when KeywordString is NULL, or contains multiple keywords, or when
2994 EFI_NOT_FOUND is generated while processing the keyword elements, the Results string
2995 contains values returned for all keywords processed prior to the keyword generating the
2996 error but no values for the keyword with error or any following keywords.
2999 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
3001 @param NameSpaceId A null-terminated string containing the platform configuration
3002 language to search through in the system. If a NULL is passed
3003 in, then it is assumed that any platform configuration language
3004 with the prefix of "x-UEFI-" are searched.
3006 @param KeywordString A null-terminated string in <MultiKeywordRequest> format. If a
3007 NULL is passed in the KeywordString field, all of the known
3008 keywords in the system for the NameSpaceId specified are
3009 returned in the Results field.
3011 @param Progress On return, points to a character in the KeywordString. Points
3012 to the string's NULL terminator if the request was successful.
3013 Points to the most recent '&' before the first failing string
3014 element if the request was not successful.
3016 @param ProgressErr If during the processing of the KeywordString there was a
3017 failure, this parameter gives additional information about the
3018 possible source of the problem. See the definitions in SetData()
3019 for valid value definitions.
3021 @param Results A null-terminated string in <MultiKeywordResp> format is returned
3022 which has all the values filled in for the keywords in the
3023 KeywordString. This is a callee-allocated field, and must be freed
3024 by the caller after being used.
3026 @retval EFI_SUCCESS The specified action was completed successfully.
3028 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
3029 1.Progress, ProgressErr, or Resuts is NULL.
3030 2.Parsing of the KeywordString resulted in an error. See
3031 Progress and ProgressErr for more data.
3034 @retval EFI_NOT_FOUND An element of the KeywordString was not found. See
3035 ProgressErr for more data.
3037 @retval EFI_NOT_FOUND The NamespaceId specified was not found. See ProgressErr
3040 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated. See
3041 ProgressErr for more data.
3043 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr for
3046 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
3052 EfiConfigKeywordHandlerGetData (
3053 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
*This
,
3054 IN CONST EFI_STRING NameSpaceId
, OPTIONAL
3055 IN CONST EFI_STRING KeywordString
, OPTIONAL
3056 OUT EFI_STRING
*Progress
,
3057 OUT UINT32
*ProgressErr
,
3058 OUT EFI_STRING
*Results
3063 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
3064 HII_DATABASE_RECORD
*DataBaseRecord
;
3066 CHAR16
*NextStringPtr
;
3067 CHAR16
*KeywordData
;
3068 EFI_STRING_ID KeywordStringId
;
3070 CHAR16
*ConfigRequest
;
3071 CHAR16
*ValueElement
;
3074 CHAR16
*KeywordResp
;
3075 CHAR16
*MultiKeywordResp
;
3077 if (This
== NULL
|| Progress
== NULL
|| ProgressErr
== NULL
|| Results
== NULL
) {
3078 return EFI_INVALID_PARAMETER
;
3081 *ProgressErr
= KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR
;
3082 Status
= EFI_SUCCESS
;
3086 ConfigRequest
= NULL
;
3087 StringPtr
= KeywordString
;
3089 MultiKeywordResp
= NULL
;
3090 KeywordStringId
= 0;
3093 // 1. Get NameSpace from NameSpaceId keyword.
3095 Status
= ExtractNameSpace (NameSpaceId
, &NameSpace
, NULL
);
3096 if (EFI_ERROR (Status
)) {
3097 *ProgressErr
= KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND
;
3101 if (KeywordString
!= NULL
) {
3102 StringPtr
= KeywordString
;
3104 while (*StringPtr
!= L
'\0') {
3106 // 2. Get possible Device Path info from KeywordString.
3108 Status
= ExtractDevicePath (StringPtr
, (UINT8
**)&DevicePath
, &NextStringPtr
);
3109 if (EFI_ERROR (Status
)) {
3110 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3113 StringPtr
= NextStringPtr
;
3117 // 3. Process Keyword section from the input keywordRequest string.
3119 // 3.1 Extract keyword from the KeywordRequest string.
3121 Status
= ExtractKeyword(StringPtr
, &KeywordData
, &NextStringPtr
);
3122 if (EFI_ERROR (Status
)) {
3124 // Can't find Keyword base on the input device path info.
3126 *ProgressErr
= KEYWORD_HANDLER_MALFORMED_STRING
;
3127 Status
= EFI_INVALID_PARAMETER
;
3132 // 3.2 Get EFI_STRING_ID for the input keyword.
3134 Status
= GetStringIdFromDatabase (&DevicePath
, &NameSpace
, KeywordData
, &RetVal
, &KeywordStringId
, &DataBaseRecord
);
3135 if (EFI_ERROR (Status
)) {
3136 *ProgressErr
= RetVal
;
3141 // 3.3 Construct the ConfigRequest string.
3143 Status
= ExtractConfigRequest (DataBaseRecord
, KeywordStringId
, &OpCode
, &ConfigRequest
);
3144 if (EFI_ERROR (Status
)) {
3149 // 3.4 Extract Value for the input keyword.
3151 Status
= ExtractValueFromDriver(ConfigRequest
, &ValueElement
);
3152 if (EFI_ERROR (Status
)) {
3153 if (Status
!= EFI_OUT_OF_RESOURCES
) {
3154 Status
= EFI_DEVICE_ERROR
;
3158 StringPtr
= NextStringPtr
;
3161 // 4. Process the possible filter section.
3163 RetVal
= ValidateFilter (OpCode
, StringPtr
, &NextStringPtr
, &ReadOnly
);
3164 if (RetVal
!= KEYWORD_HANDLER_NO_ERROR
) {
3165 *ProgressErr
= RetVal
;
3166 Status
= EFI_INVALID_PARAMETER
;
3169 StringPtr
= NextStringPtr
;
3173 // 5. Generate KeywordResp string.
3175 Status
= GenerateKeywordResp(NameSpace
, DevicePath
, KeywordData
, ValueElement
, ReadOnly
, &KeywordResp
);
3176 if (Status
!= EFI_SUCCESS
) {
3181 // 6. Merge to the MultiKeywordResp string.
3183 Status
= MergeToMultiKeywordResp(&MultiKeywordResp
, &KeywordResp
);
3184 if (EFI_ERROR (Status
)) {
3189 // 7. Update return value.
3191 *Results
= MultiKeywordResp
;
3194 // 8. Clean the temp buffer.
3196 FreePool (DevicePath
);
3197 FreePool (KeywordData
);
3198 FreePool (ValueElement
);
3199 FreePool (ConfigRequest
);
3202 ValueElement
= NULL
;
3203 ConfigRequest
= NULL
;
3204 if (KeywordResp
!= NULL
) {
3205 FreePool (KeywordResp
);
3211 // Enumerate all keyword in the system.
3213 Status
= EnumerateAllKeywords(NameSpace
, &MultiKeywordResp
);
3214 if (EFI_ERROR (Status
)) {
3217 *Results
= MultiKeywordResp
;
3220 *ProgressErr
= KEYWORD_HANDLER_NO_ERROR
;
3223 if (NameSpace
!= NULL
) {
3224 FreePool (NameSpace
);
3226 if (DevicePath
!= NULL
) {
3227 FreePool (DevicePath
);
3229 if (KeywordData
!= NULL
) {
3230 FreePool (KeywordData
);
3232 *Progress
= StringPtr
;