2 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.
4 Copyright (c) 2007 - 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"
17 extern HII_DATABASE_PRIVATE_DATA mPrivate
;
20 Calculate the number of Unicode characters of the incoming Configuration string,
21 not including NULL terminator.
23 This is a internal function.
25 @param String String in <MultiConfigRequest> or
26 <MultiConfigResp> format.
28 @return The number of Unicode characters.
32 CalculateConfigStringLen (
39 // "GUID=" should be the first element of incoming string.
41 ASSERT (String
!= NULL
);
42 ASSERT (StrnCmp (String
, L
"GUID=", StrLen (L
"GUID=")) == 0);
45 // The beginning of next <ConfigRequest>/<ConfigResp> should be "&GUID=".
46 // Will meet '\0' if there is only one <ConfigRequest>/<ConfigResp>.
48 TmpPtr
= StrStr (String
, L
"&GUID=");
50 return StrLen (String
);
53 return (TmpPtr
- String
);
58 Convert the hex UNICODE %02x encoding of a UEFI device path to binary
59 from <PathHdr> of <ConfigHdr>.
61 This is a internal function.
63 @param String UEFI configuration string
64 @param DevicePathData Binary of a UEFI device path.
66 @retval EFI_NOT_FOUND The device path is not invalid.
67 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
68 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
69 @retval EFI_SUCCESS The device path is retrieved and translated to
76 OUT UINT8
**DevicePathData
81 UINT8
*DevicePathBuffer
;
85 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
88 if (String
== NULL
|| DevicePathData
== NULL
) {
89 return EFI_INVALID_PARAMETER
;
93 // Find the 'PATH=' of <PathHdr> and skip it.
95 for (; (*String
!= 0 && StrnCmp (String
, L
"PATH=", StrLen (L
"PATH=")) != 0); String
++);
97 return EFI_INVALID_PARAMETER
;
100 // Check whether path data does exist.
102 String
+= StrLen (L
"PATH=");
104 return EFI_INVALID_PARAMETER
;
109 // The content between 'PATH=' of <ConfigHdr> and '&' of next element
110 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding
111 // of UEFI device path.
113 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
115 // Check DevicePath Length
117 if (((Length
+ 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
118 return EFI_NOT_FOUND
;
122 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
123 // as the device path resides in RAM memory.
124 // Translate the data into binary.
126 DevicePathBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
127 if (DevicePathBuffer
== NULL
) {
128 return EFI_OUT_OF_RESOURCES
;
132 // Convert DevicePath
134 ZeroMem (TemStr
, sizeof (TemStr
));
135 for (Index
= 0; Index
< Length
; Index
++) {
136 TemStr
[0] = PathHdr
[Index
];
137 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
138 if ((Index
& 1) == 0) {
139 DevicePathBuffer
[Index
/2] = DigitUint8
;
141 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
146 // Validate DevicePath
148 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) DevicePathBuffer
;
149 while (!IsDevicePathEnd (DevicePath
)) {
150 if ((DevicePath
->Type
== 0) || (DevicePath
->SubType
== 0) || (DevicePathNodeLength (DevicePath
) < sizeof (EFI_DEVICE_PATH_PROTOCOL
))) {
152 // Invalid device path
154 FreePool (DevicePathBuffer
);
155 return EFI_NOT_FOUND
;
157 DevicePath
= NextDevicePathNode (DevicePath
);
161 // return the device path
163 *DevicePathData
= DevicePathBuffer
;
168 Converts the unicode character of the string from uppercase to lowercase.
169 This is a internal function.
171 @param ConfigString String to be converted
177 IN EFI_STRING ConfigString
183 ASSERT (ConfigString
!= NULL
);
186 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
188 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
189 if (*String
== L
'=') {
191 } else if (*String
== L
'&') {
193 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
194 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
202 Generate a sub string then output it.
204 This is a internal function.
206 @param String A constant string which is the prefix of the to be
207 generated string, e.g. GUID=
209 @param BufferLen The length of the Buffer in bytes.
211 @param Buffer Points to a buffer which will be converted to be the
212 content of the generated string.
214 @param Flag If 1, the buffer contains data for the value of GUID or PATH stored in
215 UINT8 *; if 2, the buffer contains unicode string for the value of NAME;
216 if 3, the buffer contains other data.
218 @param SubStr Points to the output string. It's caller's
219 responsibility to free this buffer.
225 IN CONST EFI_STRING String
,
229 OUT EFI_STRING
*SubStr
234 EFI_STRING StringHeader
;
240 ASSERT (String
!= NULL
&& SubStr
!= NULL
);
242 if (Buffer
== NULL
) {
243 *SubStr
= AllocateCopyPool (StrSize (String
), String
);
244 ASSERT (*SubStr
!= NULL
);
249 // Header + Data + '&' + '\0'
251 Length
= StrLen (String
) + BufferLen
* 2 + 1 + 1;
252 Str
= AllocateZeroPool (Length
* sizeof (CHAR16
));
253 ASSERT (Str
!= NULL
);
255 StrCpyS (Str
, Length
, String
);
257 StringHeader
= Str
+ StrLen (String
);
258 TemString
= (CHAR16
*) StringHeader
;
263 // Convert Buffer to Hex String in reverse order
265 TemBuffer
= ((UINT8
*) Buffer
);
266 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
++) {
267 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
272 // Check buffer is enough
274 TemName
= (CHAR16
*) Buffer
;
275 ASSERT ((BufferLen
* 2 + 1) >= (StrLen (TemName
) * 4 + 1));
277 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
279 for (; *TemName
!= L
'\0'; TemName
++) {
280 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
285 // Convert Buffer to Hex String
287 TemBuffer
= ((UINT8
*) Buffer
) + BufferLen
- 1;
288 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
--) {
289 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
297 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
299 StrCatS (Str
, Length
, L
"&");
307 Retrieve the <ConfigBody> from String then output it.
309 This is a internal function.
311 @param String A sub string of a configuration string in
312 <MultiConfigAltResp> format.
313 @param ConfigBody Points to the output string. It's caller's
314 responsibility to free this buffer.
316 @retval EFI_INVALID_PARAMETER There is no form package in current hii database.
317 @retval EFI_OUT_OF_RESOURCES Not enough memory to finish this operation.
318 @retval EFI_SUCCESS All existing storage is exported.
323 IN EFI_STRING String
,
324 OUT EFI_STRING
*ConfigBody
331 if (String
== NULL
|| ConfigBody
== NULL
) {
332 return EFI_INVALID_PARAMETER
;
336 // The setting information should start OFFSET, not ALTCFG.
338 if (StrnCmp (String
, L
"&ALTCFG=", StrLen (L
"&ALTCFG=")) == 0) {
339 return EFI_INVALID_PARAMETER
;
342 TmpPtr
= StrStr (String
, L
"GUID=");
343 if (TmpPtr
== NULL
) {
345 // It is the last <ConfigResp> of the incoming configuration string.
347 Result
= AllocateCopyPool (StrSize (String
), String
);
348 if (Result
== NULL
) {
349 return EFI_OUT_OF_RESOURCES
;
351 *ConfigBody
= Result
;
356 Length
= TmpPtr
- String
;
358 return EFI_NOT_FOUND
;
360 Result
= AllocateCopyPool (Length
* sizeof (CHAR16
), String
);
361 if (Result
== NULL
) {
362 return EFI_OUT_OF_RESOURCES
;
365 *(Result
+ Length
- 1) = 0;
366 *ConfigBody
= Result
;
371 Append a string to a multi-string format.
373 This is a internal function.
375 @param MultiString String in <MultiConfigRequest>,
376 <MultiConfigAltResp>, or <MultiConfigResp>. On
377 input, the buffer length of this string is
378 MAX_STRING_LENGTH. On output, the buffer length
380 @param AppendString NULL-terminated Unicode string.
382 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
383 @retval EFI_SUCCESS AppendString is append to the end of MultiString
387 AppendToMultiString (
388 IN OUT EFI_STRING
*MultiString
,
389 IN EFI_STRING AppendString
392 UINTN AppendStringSize
;
393 UINTN MultiStringSize
;
396 if (MultiString
== NULL
|| *MultiString
== NULL
|| AppendString
== NULL
) {
397 return EFI_INVALID_PARAMETER
;
400 AppendStringSize
= StrSize (AppendString
);
401 MultiStringSize
= StrSize (*MultiString
);
402 MaxLen
= MAX_STRING_LENGTH
/ sizeof (CHAR16
);
405 // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.
407 if (MultiStringSize
+ AppendStringSize
> MAX_STRING_LENGTH
||
408 MultiStringSize
> MAX_STRING_LENGTH
) {
409 *MultiString
= (EFI_STRING
) ReallocatePool (
411 MultiStringSize
+ AppendStringSize
,
412 (VOID
*) (*MultiString
)
414 MaxLen
= (MultiStringSize
+ AppendStringSize
) / sizeof (CHAR16
);
415 ASSERT (*MultiString
!= NULL
);
418 // Append the incoming string
420 StrCatS (*MultiString
, MaxLen
, AppendString
);
427 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
429 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
431 This is a internal function.
433 @param StringPtr String in <BlockConfig> format and points to the
434 first character of <Number>.
435 @param Number The output value. Caller takes the responsibility
437 @param Len Length of the <Number>, in characters.
439 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
441 @retval EFI_SUCCESS Value of <Number> is outputted in Number
447 IN EFI_STRING StringPtr
,
461 if (StringPtr
== NULL
|| *StringPtr
== L
'\0' || Number
== NULL
|| Len
== NULL
) {
462 return EFI_INVALID_PARAMETER
;
468 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
471 *Len
= StringPtr
- TmpPtr
;
474 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
476 Status
= EFI_OUT_OF_RESOURCES
;
479 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
480 *(Str
+ *Len
) = L
'\0';
482 Length
= (Length
+ 1) / 2;
483 Buf
= (UINT8
*) AllocateZeroPool (Length
);
485 Status
= EFI_OUT_OF_RESOURCES
;
490 ZeroMem (TemStr
, sizeof (TemStr
));
491 for (Index
= 0; Index
< Length
; Index
++) {
492 TemStr
[0] = Str
[Length
- Index
- 1];
493 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
494 if ((Index
& 1) == 0) {
495 Buf
[Index
/2] = DigitUint8
;
497 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
502 Status
= EFI_SUCCESS
;
513 This function merges DefaultAltCfgResp string into AltCfgResp string for
514 the missing AltCfgId in AltCfgResq.
516 @param AltCfgResp Pointer to a null-terminated Unicode string in
517 <ConfigAltResp> format. The default value string
518 will be merged into it.
519 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
520 <MultiConfigAltResp> format. The default value
521 string may contain more than one ConfigAltResp
522 string for the different varstore buffer.
524 @retval EFI_SUCCESS The merged string returns.
525 @retval EFI_INVALID_PARAMETER *AltCfgResp is to NULL.
530 IN OUT EFI_STRING
*AltCfgResp
,
531 IN EFI_STRING DefaultAltCfgResp
534 EFI_STRING StringPtrDefault
;
535 EFI_STRING StringPtrEnd
;
537 EFI_STRING StringPtr
;
538 EFI_STRING AltConfigHdr
;
540 UINTN SizeAltCfgResp
;
544 if (*AltCfgResp
== NULL
) {
545 return EFI_INVALID_PARAMETER
;
549 // Get the requestr ConfigHdr
552 StringPtr
= *AltCfgResp
;
555 // Find <ConfigHdr> GUID=...&NAME=...&PATH=...
557 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
558 return EFI_INVALID_PARAMETER
;
560 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
563 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
566 if (*StringPtr
== L
'\0') {
567 return EFI_INVALID_PARAMETER
;
569 StringPtr
+= StrLen (L
"&PATH=");
570 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
573 HeaderLength
= StringPtr
- *AltCfgResp
;
576 // Construct AltConfigHdr string "&<ConfigHdr>&ALTCFG=XXXX\0"
577 // |1| StrLen (ConfigHdr) | 8 | 4 | 1 |
579 MaxLen
= 1 + HeaderLength
+ 8 + 4 + 1;
580 AltConfigHdr
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
581 if (AltConfigHdr
== NULL
) {
582 return EFI_OUT_OF_RESOURCES
;
584 StrCpyS (AltConfigHdr
, MaxLen
, L
"&");
585 StrnCatS (AltConfigHdr
, MaxLen
, *AltCfgResp
, HeaderLength
);
586 StrCatS (AltConfigHdr
, MaxLen
, L
"&ALTCFG=");
587 HeaderLength
= StrLen (AltConfigHdr
);
589 StringPtrDefault
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
590 while (StringPtrDefault
!= NULL
) {
594 StrnCatS (AltConfigHdr
, MaxLen
, StringPtrDefault
+ HeaderLength
, 4);
595 StringPtr
= StrStr (*AltCfgResp
, AltConfigHdr
);
598 // Append the found default value string to the input AltCfgResp
600 if (StringPtr
== NULL
) {
601 StringPtrEnd
= StrStr (StringPtrDefault
+ 1, L
"&GUID");
602 SizeAltCfgResp
= StrSize (*AltCfgResp
);
603 TotalSize
= SizeAltCfgResp
+ StrSize (StringPtrDefault
);
604 if (StringPtrEnd
== NULL
) {
606 // No more default string is found.
608 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
611 (VOID
*) (*AltCfgResp
)
613 if (*AltCfgResp
== NULL
) {
614 FreePool (AltConfigHdr
);
615 return EFI_OUT_OF_RESOURCES
;
617 StrCatS (*AltCfgResp
, TotalSize
/ sizeof (CHAR16
), StringPtrDefault
);
620 TempChar
= *StringPtrEnd
;
621 *StringPtrEnd
= L
'\0';
622 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
625 (VOID
*) (*AltCfgResp
)
627 if (*AltCfgResp
== NULL
) {
628 FreePool (AltConfigHdr
);
629 return EFI_OUT_OF_RESOURCES
;
631 StrCatS (*AltCfgResp
, TotalSize
/ sizeof (CHAR16
), StringPtrDefault
);
632 *StringPtrEnd
= TempChar
;
637 // Find next AltCfg String
639 *(AltConfigHdr
+ HeaderLength
) = L
'\0';
640 StringPtrDefault
= StrStr (StringPtrDefault
+ 1, AltConfigHdr
);
643 FreePool (AltConfigHdr
);
648 This function inserts new DefaultValueData into the BlockData DefaultValue array.
650 @param BlockData The BlockData is updated to add new default value.
651 @param DefaultValueData The DefaultValue is added.
656 IN IFR_BLOCK_DATA
*BlockData
,
657 IN IFR_DEFAULT_DATA
*DefaultValueData
661 IFR_DEFAULT_DATA
*DefaultValueArray
;
662 LIST_ENTRY
*DefaultLink
;
664 DefaultLink
= &BlockData
->DefaultValueEntry
;
666 for (Link
= DefaultLink
->ForwardLink
; Link
!= DefaultLink
; Link
= Link
->ForwardLink
) {
667 DefaultValueArray
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
668 if (DefaultValueArray
->DefaultId
== DefaultValueData
->DefaultId
) {
670 // DEFAULT_VALUE_FROM_OPCODE has high priority, DEFAULT_VALUE_FROM_DEFAULT has low priority.
672 if (DefaultValueData
->Type
> DefaultValueArray
->Type
) {
674 // Update the default value array in BlockData.
676 CopyMem (&DefaultValueArray
->Value
, &DefaultValueData
->Value
, sizeof (EFI_IFR_TYPE_VALUE
));
677 DefaultValueArray
->Type
= DefaultValueData
->Type
;
678 DefaultValueArray
->Cleaned
= DefaultValueData
->Cleaned
;
685 // Insert new default value data in tail.
687 DefaultValueArray
= AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
688 ASSERT (DefaultValueArray
!= NULL
);
689 CopyMem (DefaultValueArray
, DefaultValueData
, sizeof (IFR_DEFAULT_DATA
));
690 InsertTailList (Link
, &DefaultValueArray
->Entry
);
694 This function inserts new BlockData into the block link
696 @param BlockLink The list entry points to block array.
697 @param BlockData The point to BlockData is added.
702 IN LIST_ENTRY
*BlockLink
,
703 IN IFR_BLOCK_DATA
**BlockData
707 IFR_BLOCK_DATA
*BlockArray
;
708 IFR_BLOCK_DATA
*BlockSingleData
;
710 BlockSingleData
= *BlockData
;
712 if (BlockSingleData
->Name
!= NULL
) {
713 InsertTailList (BlockLink
, &BlockSingleData
->Entry
);
718 // Insert block data in its Offset and Width order.
720 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
721 BlockArray
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
722 if (BlockArray
->Offset
== BlockSingleData
->Offset
) {
723 if (BlockArray
->Width
> BlockSingleData
->Width
) {
725 // Insert this block data in the front of block array
727 InsertTailList (Link
, &BlockSingleData
->Entry
);
731 if (BlockArray
->Width
== BlockSingleData
->Width
) {
733 // The same block array has been added.
735 if (BlockSingleData
!= BlockArray
) {
736 FreePool (BlockSingleData
);
737 *BlockData
= BlockArray
;
741 } else if (BlockArray
->Offset
> BlockSingleData
->Offset
) {
743 // Insert new block data in the front of block array
745 InsertTailList (Link
, &BlockSingleData
->Entry
);
751 // Add new block data into the tail.
753 InsertTailList (Link
, &BlockSingleData
->Entry
);
757 Retrieves a pointer to the a Null-terminated ASCII string containing the list
758 of languages that an HII handle in the HII Database supports. The returned
759 string is allocated using AllocatePool(). The caller is responsible for freeing
760 the returned string using FreePool(). The format of the returned string follows
761 the language format assumed the HII Database.
763 If HiiHandle is NULL, then ASSERT().
765 @param[in] HiiHandle A handle that was previously registered in the HII Database.
767 @retval NULL HiiHandle is not registered in the HII database
768 @retval NULL There are not enough resources available to retrieve the suported
770 @retval NULL The list of suported languages could not be retrieved.
771 @retval Other A pointer to the Null-terminated ASCII string of supported languages.
775 GetSupportedLanguages (
776 IN EFI_HII_HANDLE HiiHandle
781 CHAR8 TempSupportedLanguages
;
782 CHAR8
*SupportedLanguages
;
784 ASSERT (HiiHandle
!= NULL
);
787 // Retrieve the size required for the supported languages buffer.
790 Status
= mPrivate
.HiiString
.GetLanguages (&mPrivate
.HiiString
, HiiHandle
, &TempSupportedLanguages
, &LanguageSize
);
793 // If GetLanguages() returns EFI_SUCCESS for a zero size,
794 // then there are no supported languages registered for HiiHandle. If GetLanguages()
795 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
796 // in the HII Database
798 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
800 // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database
806 // Allocate the supported languages buffer.
808 SupportedLanguages
= AllocateZeroPool (LanguageSize
);
809 if (SupportedLanguages
== NULL
) {
811 // Return NULL if allocation fails.
817 // Retrieve the supported languages string
819 Status
= mPrivate
.HiiString
.GetLanguages (&mPrivate
.HiiString
, HiiHandle
, SupportedLanguages
, &LanguageSize
);
820 if (EFI_ERROR (Status
)) {
822 // Free the buffer and return NULL if the supported languages can not be retrieved.
824 FreePool (SupportedLanguages
);
829 // Return the Null-terminated ASCII string of supported languages
831 return SupportedLanguages
;
835 Retrieves a string from a string package.
837 If HiiHandle is NULL, then ASSERT().
838 If StringId is 0, then ASSET.
840 @param[in] HiiHandle A handle that was previously registered in the HII Database.
841 @param[in] StringId The identifier of the string to retrieved from the string
842 package associated with HiiHandle.
844 @retval NULL The string specified by StringId is not present in the string package.
845 @retval Other The string was returned.
850 IN EFI_HII_HANDLE HiiHandle
,
851 IN EFI_STRING_ID StringId
858 CHAR8
*SupportedLanguages
;
859 CHAR8
*PlatformLanguage
;
863 ASSERT (HiiHandle
!= NULL
);
864 ASSERT (StringId
!= 0);
867 // Initialize all allocated buffers to NULL
869 SupportedLanguages
= NULL
;
870 PlatformLanguage
= NULL
;
876 // Get the languages that the package specified by HiiHandle supports
878 SupportedLanguages
= GetSupportedLanguages (HiiHandle
);
879 if (SupportedLanguages
== NULL
) {
884 // Get the current platform language setting
886 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
889 // Get the best matching language from SupportedLanguages
891 BestLanguage
= GetBestLanguage (
893 FALSE
, // RFC 4646 mode
894 Language
, // Highest priority
895 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Next highest priority
896 SupportedLanguages
, // Lowest priority
899 if (BestLanguage
== NULL
) {
904 // Retrieve the size of the string in the string package for the BestLanguage
907 Status
= mPrivate
.HiiString
.GetString (
917 // If GetString() returns EFI_SUCCESS for a zero size,
918 // then there are no supported languages registered for HiiHandle. If GetString()
919 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
920 // in the HII Database
922 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
927 // Allocate a buffer for the return string
929 String
= AllocateZeroPool (StringSize
);
930 if (String
== NULL
) {
935 // Retrieve the string from the string package
937 Status
= mPrivate
.HiiString
.GetString (
946 if (EFI_ERROR (Status
)) {
948 // Free the buffer and return NULL if the supported languages can not be retrieved.
956 // Free allocated buffers
958 if (SupportedLanguages
!= NULL
) {
959 FreePool (SupportedLanguages
);
961 if (PlatformLanguage
!= NULL
) {
962 FreePool (PlatformLanguage
);
964 if (BestLanguage
!= NULL
) {
965 FreePool (BestLanguage
);
969 // Return the Null-terminated Unicode string
975 This function checks VarOffset and VarWidth is in the block range.
977 @param RequestBlockArray The block array is to be checked.
978 @param VarOffset Offset of var to the structure
979 @param VarWidth Width of var.
980 @param IsNameValueType Whether this varstore is name/value varstore or not.
981 @param HiiHandle Hii handle for this hii package.
983 @retval TRUE This Var is in the block range.
984 @retval FALSE This Var is not in the block range.
988 IN IFR_BLOCK_DATA
*RequestBlockArray
,
991 IN BOOLEAN IsNameValueType
,
992 IN EFI_HII_HANDLE HiiHandle
996 IFR_BLOCK_DATA
*BlockData
;
1000 // No Request Block array, all vars are got.
1002 if (RequestBlockArray
== NULL
) {
1007 // Check the input var is in the request block range.
1009 for (Link
= RequestBlockArray
->Entry
.ForwardLink
; Link
!= &RequestBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1010 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1012 if (IsNameValueType
) {
1013 Name
= InternalGetString (HiiHandle
, VarOffset
);
1014 ASSERT (Name
!= NULL
);
1016 if (StrnCmp (BlockData
->Name
, Name
, StrLen (Name
)) == 0) {
1022 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
1032 Get form package data from data base.
1034 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1035 @param HiiFormPackage The buffer saves the package data.
1036 @param PackageSize The buffer size of the package data.
1040 GetFormPackageData (
1041 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1042 IN OUT UINT8
**HiiFormPackage
,
1043 OUT UINTN
*PackageSize
1050 if (DataBaseRecord
== NULL
|| HiiFormPackage
== NULL
|| PackageSize
== NULL
) {
1051 return EFI_INVALID_PARAMETER
;
1057 // 0. Get Hii Form Package by HiiHandle
1059 Status
= ExportFormPackages (
1061 DataBaseRecord
->Handle
,
1062 DataBaseRecord
->PackageList
,
1068 if (EFI_ERROR (Status
)) {
1072 (*HiiFormPackage
) = AllocatePool (ResultSize
);
1073 if (*HiiFormPackage
== NULL
) {
1074 Status
= EFI_OUT_OF_RESOURCES
;
1079 // Get HiiFormPackage by HiiHandle
1083 Status
= ExportFormPackages (
1085 DataBaseRecord
->Handle
,
1086 DataBaseRecord
->PackageList
,
1092 if (EFI_ERROR (Status
)) {
1093 FreePool (*HiiFormPackage
);
1096 *PackageSize
= Size
;
1103 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.
1105 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1106 @param ConfigHdr Request string ConfigHdr. If it is NULL,
1107 the first found varstore will be as ConfigHdr.
1108 @param IsEfiVarstore Whether the request storage type is efi varstore type.
1109 @param EfiVarStore The efi varstore info which will return.
1113 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1114 IN EFI_STRING ConfigHdr
,
1115 OUT BOOLEAN
*IsEfiVarstore
,
1116 OUT EFI_IFR_VARSTORE_EFI
**EfiVarStore
1121 UINTN PackageOffset
;
1122 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1123 CHAR16
*VarStoreName
;
1128 UINT8
*HiiFormPackage
;
1130 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1131 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
1133 HiiFormPackage
= NULL
;
1135 Status
= EFI_SUCCESS
;
1139 *IsEfiVarstore
= FALSE
;
1141 Status
= GetFormPackageData(DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
1142 if (EFI_ERROR (Status
)) {
1146 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1147 PackageOffset
= IfrOffset
;
1148 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) HiiFormPackage
;
1150 while (IfrOffset
< PackageSize
) {
1152 // More than one form packages exist.
1154 if (PackageOffset
>= PackageHeader
->Length
) {
1156 // Process the new form package.
1158 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1159 IfrOffset
+= PackageOffset
;
1160 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1163 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1164 IfrOffset
+= IfrOpHdr
->Length
;
1165 PackageOffset
+= IfrOpHdr
->Length
;
1167 if (IfrOpHdr
->OpCode
== EFI_IFR_VARSTORE_EFI_OP
) {
1168 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1170 // If the length is small than the structure, this is from old efi
1171 // varstore definition. Old efi varstore get config directly from
1172 // GetVariable function.
1174 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1178 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
) * sizeof (CHAR16
));
1179 if (VarStoreName
== NULL
) {
1180 Status
= EFI_OUT_OF_RESOURCES
;
1183 AsciiStrToUnicodeStr ((CHAR8
*) IfrEfiVarStore
->Name
, VarStoreName
);
1185 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &IfrEfiVarStore
->Guid
, 1, &GuidStr
);
1186 GenerateSubStr (L
"NAME=", StrLen (VarStoreName
) * sizeof (CHAR16
), (VOID
*) VarStoreName
, 2, &NameStr
);
1187 LengthString
= StrLen (GuidStr
);
1188 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
1189 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
1190 if (TempStr
== NULL
) {
1193 FreePool (VarStoreName
);
1194 Status
= EFI_OUT_OF_RESOURCES
;
1197 StrCpyS (TempStr
, LengthString
, GuidStr
);
1198 StrCatS (TempStr
, LengthString
, NameStr
);
1199 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
1200 *EfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) AllocateZeroPool (IfrOpHdr
->Length
);
1201 if (*EfiVarStore
== NULL
) {
1202 FreePool (VarStoreName
);
1206 Status
= EFI_OUT_OF_RESOURCES
;
1209 *IsEfiVarstore
= TRUE
;
1210 CopyMem (*EfiVarStore
, IfrEfiVarStore
, IfrOpHdr
->Length
);
1214 // Free alllocated temp string.
1216 FreePool (VarStoreName
);
1222 // Already found the varstore, break;
1224 if (*IsEfiVarstore
) {
1230 if (HiiFormPackage
!= NULL
) {
1231 FreePool (HiiFormPackage
);
1238 Check whether the ConfigRequest string has the request elements.
1239 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.
1240 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.
1242 @param ConfigRequest The input config request string.
1244 @retval TRUE The input include config request elements.
1245 @retval FALSE The input string not includes.
1249 GetElementsFromRequest (
1250 IN EFI_STRING ConfigRequest
1253 EFI_STRING TmpRequest
;
1255 TmpRequest
= StrStr (ConfigRequest
, L
"PATH=");
1256 ASSERT (TmpRequest
!= NULL
);
1258 if ((StrStr (TmpRequest
, L
"&OFFSET=") != NULL
) || (StrStr (TmpRequest
, L
"&") != NULL
)) {
1266 Check whether the this varstore is the request varstore.
1268 @param VarstoreGuid Varstore guid.
1269 @param Name Varstore name.
1270 @param ConfigHdr Current configRequest info.
1272 @retval TRUE This varstore is the requst one.
1273 @retval FALSE This varstore is not the requst one.
1278 IN EFI_GUID
*VarstoreGuid
,
1280 IN CHAR16
*ConfigHdr
1294 // If ConfigHdr has name field and varstore not has name, return FALSE.
1296 if (Name
== NULL
&& ConfigHdr
!= NULL
&& StrStr (ConfigHdr
, L
"NAME=&") == NULL
) {
1300 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*)VarstoreGuid
, 1, &GuidStr
);
1302 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
1304 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
1306 LengthString
= StrLen (GuidStr
);
1307 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
1308 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
1309 if (TempStr
== NULL
) {
1313 StrCpyS (TempStr
, LengthString
, GuidStr
);
1314 StrCatS (TempStr
, LengthString
, NameStr
);
1316 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
1321 if (GuidStr
!= NULL
) {
1325 if (NameStr
!= NULL
) {
1329 if (TempStr
!= NULL
) {
1337 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.
1339 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1340 @param ConfigHdr Request string ConfigHdr. If it is NULL,
1341 the first found varstore will be as ConfigHdr.
1342 @retval TRUE This hii package is the reqeust one.
1343 @retval FALSE This hii package is not the reqeust one.
1347 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1348 IN EFI_STRING ConfigHdr
1353 UINTN PackageOffset
;
1354 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1355 CHAR16
*VarStoreName
;
1356 UINT8
*HiiFormPackage
;
1358 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1359 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
1360 EFI_IFR_VARSTORE
*IfrVarStore
;
1361 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueVarStore
;
1362 BOOLEAN FindVarstore
;
1364 HiiFormPackage
= NULL
;
1365 VarStoreName
= NULL
;
1366 Status
= EFI_SUCCESS
;
1367 FindVarstore
= FALSE
;
1369 Status
= GetFormPackageData(DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
1370 if (EFI_ERROR (Status
)) {
1374 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1375 PackageOffset
= IfrOffset
;
1376 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) HiiFormPackage
;
1378 while (IfrOffset
< PackageSize
) {
1380 // More than one form packages exist.
1382 if (PackageOffset
>= PackageHeader
->Length
) {
1384 // Process the new form package.
1386 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1387 IfrOffset
+= PackageOffset
;
1388 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1391 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1392 IfrOffset
+= IfrOpHdr
->Length
;
1393 PackageOffset
+= IfrOpHdr
->Length
;
1395 switch (IfrOpHdr
->OpCode
) {
1397 case EFI_IFR_VARSTORE_OP
:
1398 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1400 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
) * sizeof (CHAR16
));
1401 if (VarStoreName
== NULL
) {
1404 AsciiStrToUnicodeStr ((CHAR8
*)IfrVarStore
->Name
, VarStoreName
);
1406 if (IsThisVarstore((VOID
*)&IfrVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1407 FindVarstore
= TRUE
;
1412 case EFI_IFR_VARSTORE_EFI_OP
:
1413 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1414 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
) * sizeof (CHAR16
));
1415 if (VarStoreName
== NULL
) {
1418 AsciiStrToUnicodeStr ((CHAR8
*)IfrEfiVarStore
->Name
, VarStoreName
);
1420 if (IsThisVarstore (&IfrEfiVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1421 FindVarstore
= TRUE
;
1426 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1427 IfrNameValueVarStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
1429 if (IsThisVarstore (&IfrNameValueVarStore
->Guid
, NULL
, ConfigHdr
)) {
1430 FindVarstore
= TRUE
;
1435 case EFI_IFR_FORM_OP
:
1436 case EFI_IFR_FORM_MAP_OP
:
1438 // No matched varstore is found and directly return.
1447 if (HiiFormPackage
!= NULL
) {
1448 FreePool (HiiFormPackage
);
1451 if (VarStoreName
!= NULL
) {
1452 FreePool (VarStoreName
);
1455 return FindVarstore
;
1459 Check whether the this op code is required.
1461 @param RequestBlockArray The array includes all the request info or NULL.
1462 @param HiiHandle The hii handle for this form package.
1463 @param VarStorageData The varstore data strucure.
1464 @param IfrOpHdr Ifr opcode header for this opcode.
1465 @param VarWidth The buffer width for this opcode.
1466 @param ReturnData The data block added for this opcode.
1468 @retval EFI_SUCCESS This opcode is required.
1469 @retval Others This opcode is not required or error occur.
1473 IsThisOpcodeRequired (
1474 IN IFR_BLOCK_DATA
*RequestBlockArray
,
1475 IN EFI_HII_HANDLE HiiHandle
,
1476 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
1477 IN EFI_IFR_OP_HEADER
*IfrOpHdr
,
1479 OUT IFR_BLOCK_DATA
**ReturnData
1482 IFR_BLOCK_DATA
*BlockData
;
1484 EFI_STRING_ID NameId
;
1485 EFI_IFR_QUESTION_HEADER
*IfrQuestionHdr
;
1489 IfrQuestionHdr
= (EFI_IFR_QUESTION_HEADER
*)((CHAR8
*) IfrOpHdr
+ sizeof (EFI_IFR_OP_HEADER
));
1491 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
1492 NameId
= IfrQuestionHdr
->VarStoreInfo
.VarName
;
1495 // Check whether this question is in requested block array.
1497 if (!BlockArrayCheck (RequestBlockArray
, NameId
, 0, TRUE
, HiiHandle
)) {
1499 // This question is not in the requested string. Skip it.
1504 VarOffset
= IfrQuestionHdr
->VarStoreInfo
.VarOffset
;
1507 // Check whether this question is in requested block array.
1509 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
, FALSE
, HiiHandle
)) {
1511 // This question is not in the requested string. Skip it.
1517 // Check this var question is in the var storage
1519 if (((VarOffset
+ VarWidth
) > VarStorageData
->Size
)) {
1520 return EFI_INVALID_PARAMETER
;
1524 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1525 if (BlockData
== NULL
) {
1526 return EFI_OUT_OF_RESOURCES
;
1529 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
1530 BlockData
->Name
= InternalGetString(HiiHandle
, NameId
);
1532 BlockData
->Offset
= VarOffset
;
1535 BlockData
->Width
= VarWidth
;
1536 BlockData
->QuestionId
= IfrQuestionHdr
->QuestionId
;
1537 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1538 BlockData
->Scope
= IfrOpHdr
->Scope
;
1539 InitializeListHead (&BlockData
->DefaultValueEntry
);
1541 // Add Block Data into VarStorageData BlockEntry
1543 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1544 *ReturnData
= BlockData
;
1550 This function parses Form Package to get the block array and the default
1551 value array according to the request ConfigHdr.
1553 @param HiiHandle Hii Handle for this hii package.
1554 @param Package Pointer to the form package data.
1555 @param PackageLength Length of the pacakge.
1556 @param ConfigHdr Request string ConfigHdr. If it is NULL,
1557 the first found varstore will be as ConfigHdr.
1558 @param RequestBlockArray The block array is retrieved from the request string.
1559 @param VarStorageData VarStorage structure contains the got block and default value.
1560 @param DefaultIdArray Point to the got default id and default name array.
1562 @retval EFI_SUCCESS The block array and the default value array are got.
1563 @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges
1565 @retval EFI_OUT_OF_RESOURCES No enough memory.
1570 IN EFI_HII_HANDLE HiiHandle
,
1572 IN UINT32 PackageLength
,
1573 IN EFI_STRING ConfigHdr
,
1574 IN IFR_BLOCK_DATA
*RequestBlockArray
,
1575 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
1576 OUT IFR_DEFAULT_DATA
*DefaultIdArray
1581 UINTN PackageOffset
;
1582 EFI_IFR_VARSTORE
*IfrVarStore
;
1583 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1584 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1585 EFI_IFR_ONE_OF
*IfrOneOf
;
1586 EFI_IFR_REF4
*IfrRef
;
1587 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
1588 EFI_IFR_DEFAULT
*IfrDefault
;
1589 EFI_IFR_ORDERED_LIST
*IfrOrderedList
;
1590 EFI_IFR_CHECKBOX
*IfrCheckBox
;
1591 EFI_IFR_PASSWORD
*IfrPassword
;
1592 EFI_IFR_STRING
*IfrString
;
1593 EFI_IFR_DATE
*IfrDate
;
1594 EFI_IFR_TIME
*IfrTime
;
1595 IFR_DEFAULT_DATA DefaultData
;
1596 IFR_DEFAULT_DATA
*DefaultDataPtr
;
1597 IFR_BLOCK_DATA
*BlockData
;
1598 CHAR16
*VarStoreName
;
1600 UINT16 VarDefaultId
;
1601 BOOLEAN FirstOneOfOption
;
1602 LIST_ENTRY
*LinkData
;
1603 LIST_ENTRY
*LinkDefault
;
1604 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueVarStore
;
1605 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
1606 EFI_VARSTORE_ID VarStoreId
;
1608 Status
= EFI_SUCCESS
;
1610 DefaultDataPtr
= NULL
;
1611 FirstOneOfOption
= FALSE
;
1613 ZeroMem (&DefaultData
, sizeof (IFR_DEFAULT_DATA
));
1616 // Go through the form package to parse OpCode one by one.
1618 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1619 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) Package
;
1620 IfrOffset
= PackageOffset
;
1621 while (IfrOffset
< PackageLength
) {
1624 // More than one form package found.
1626 if (PackageOffset
>= PackageHeader
->Length
) {
1628 // Already found varstore for this request, break;
1630 if (VarStoreId
!= 0) {
1635 // Get next package header info.
1637 IfrOffset
+= sizeof (EFI_HII_PACKAGE_HEADER
);
1638 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1639 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (Package
+ IfrOffset
);
1642 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (Package
+ IfrOffset
);
1643 switch (IfrOpHdr
->OpCode
) {
1644 case EFI_IFR_VARSTORE_OP
:
1646 // VarStore is found. Don't need to search any more.
1648 if (VarStoreId
!= 0) {
1652 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1654 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
) * sizeof (CHAR16
));
1655 if (VarStoreName
== NULL
) {
1656 Status
= EFI_OUT_OF_RESOURCES
;
1659 AsciiStrToUnicodeStr ((CHAR8
*)IfrVarStore
->Name
, VarStoreName
);
1661 if (IsThisVarstore((VOID
*)&IfrVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1663 // Find the matched VarStore
1665 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
);
1666 VarStorageData
->Size
= IfrVarStore
->Size
;
1667 VarStorageData
->Name
= VarStoreName
;
1668 VarStorageData
->Type
= EFI_HII_VARSTORE_BUFFER
;
1669 VarStoreId
= IfrVarStore
->VarStoreId
;
1673 case EFI_IFR_VARSTORE_EFI_OP
:
1675 // VarStore is found. Don't need to search any more.
1677 if (VarStoreId
!= 0) {
1681 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1684 // If the length is small than the structure, this is from old efi
1685 // varstore definition. Old efi varstore get config directly from
1686 // GetVariable function.
1688 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1692 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
) * sizeof (CHAR16
));
1693 if (VarStoreName
== NULL
) {
1694 Status
= EFI_OUT_OF_RESOURCES
;
1697 AsciiStrToUnicodeStr ((CHAR8
*)IfrEfiVarStore
->Name
, VarStoreName
);
1699 if (IsThisVarstore (&IfrEfiVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1701 // Find the matched VarStore
1703 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrEfiVarStore
->Guid
);
1704 VarStorageData
->Size
= IfrEfiVarStore
->Size
;
1705 VarStorageData
->Name
= VarStoreName
;
1706 VarStorageData
->Type
= EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
;
1707 VarStoreId
= IfrEfiVarStore
->VarStoreId
;
1711 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1713 // VarStore is found. Don't need to search any more.
1715 if (VarStoreId
!= 0) {
1719 IfrNameValueVarStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
1721 if (IsThisVarstore (&IfrNameValueVarStore
->Guid
, NULL
, ConfigHdr
)) {
1723 // Find the matched VarStore
1725 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrNameValueVarStore
->Guid
);
1726 VarStorageData
->Type
= EFI_HII_VARSTORE_NAME_VALUE
;
1727 VarStoreId
= IfrNameValueVarStore
->VarStoreId
;
1731 case EFI_IFR_DEFAULTSTORE_OP
:
1733 // Add new the map between default id and default name.
1735 DefaultDataPtr
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1736 if (DefaultDataPtr
== NULL
) {
1737 Status
= EFI_OUT_OF_RESOURCES
;
1740 DefaultDataPtr
->DefaultId
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
;
1741 InsertTailList (&DefaultIdArray
->Entry
, &DefaultDataPtr
->Entry
);
1742 DefaultDataPtr
= NULL
;
1745 case EFI_IFR_FORM_OP
:
1746 case EFI_IFR_FORM_MAP_OP
:
1748 // No matched varstore is found and directly return.
1750 if ( VarStoreId
== 0) {
1751 Status
= EFI_SUCCESS
;
1756 case EFI_IFR_REF_OP
:
1758 // Ref question is not in IFR Form. This IFR form is not valid.
1760 if ( VarStoreId
== 0) {
1761 Status
= EFI_INVALID_PARAMETER
;
1765 // Check whether this question is for the requested varstore.
1767 IfrRef
= (EFI_IFR_REF4
*) IfrOpHdr
;
1768 if (IfrRef
->Question
.VarStoreId
!= VarStoreId
) {
1771 VarWidth
= (UINT16
) (sizeof (EFI_HII_REF
));
1773 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
1774 if (EFI_ERROR (Status
)) {
1779 case EFI_IFR_ONE_OF_OP
:
1780 case EFI_IFR_NUMERIC_OP
:
1782 // Numeric and OneOf has the same opcode structure.
1786 // Numeric and OneOf question is not in IFR Form. This IFR form is not valid.
1788 if (VarStoreId
== 0) {
1789 Status
= EFI_INVALID_PARAMETER
;
1793 // Check whether this question is for the requested varstore.
1795 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1796 if (IfrOneOf
->Question
.VarStoreId
!= VarStoreId
) {
1799 VarWidth
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1801 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
1802 if (EFI_ERROR (Status
)) {
1806 if (BlockData
== NULL
) {
1808 // BlockData == NULL means this opcode is not in the requst array.
1813 if (IfrOpHdr
->OpCode
== EFI_IFR_ONE_OF_OP
) {
1815 // Set this flag to TRUE for the first oneof option.
1817 FirstOneOfOption
= TRUE
;
1818 } else if (IfrOpHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) {
1820 // Numeric minimum value will be used as default value when no default is specified.
1822 DefaultData
.Type
= DefaultValueFromDefault
;
1823 switch (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1824 case EFI_IFR_NUMERIC_SIZE_1
:
1825 DefaultData
.Value
.u8
= IfrOneOf
->data
.u8
.MinValue
;
1828 case EFI_IFR_NUMERIC_SIZE_2
:
1829 CopyMem (&DefaultData
.Value
.u16
, &IfrOneOf
->data
.u16
.MinValue
, sizeof (UINT16
));
1832 case EFI_IFR_NUMERIC_SIZE_4
:
1833 CopyMem (&DefaultData
.Value
.u32
, &IfrOneOf
->data
.u32
.MinValue
, sizeof (UINT32
));
1836 case EFI_IFR_NUMERIC_SIZE_8
:
1837 CopyMem (&DefaultData
.Value
.u64
, &IfrOneOf
->data
.u64
.MinValue
, sizeof (UINT64
));
1841 Status
= EFI_INVALID_PARAMETER
;
1845 // Set default value base on the DefaultId list get from IFR data.
1847 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
1848 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
1849 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
1850 InsertDefaultValue (BlockData
, &DefaultData
);
1855 case EFI_IFR_ORDERED_LIST_OP
:
1857 // offset by question header
1858 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type
1859 // no default value and default id, how to define its default value?
1863 // OrderedList question is not in IFR Form. This IFR form is not valid.
1865 if (VarStoreId
== 0) {
1866 Status
= EFI_INVALID_PARAMETER
;
1870 // Check whether this question is for the requested varstore.
1872 IfrOrderedList
= (EFI_IFR_ORDERED_LIST
*) IfrOpHdr
;
1873 if (IfrOrderedList
->Question
.VarStoreId
!= VarStoreId
) {
1877 VarWidth
= IfrOrderedList
->MaxContainers
;
1878 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
1879 if (EFI_ERROR (Status
)) {
1884 case EFI_IFR_CHECKBOX_OP
:
1886 // EFI_IFR_DEFAULT_OP
1887 // offset by question header
1888 // width is 1 sizeof (BOOLEAN)
1889 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.
1890 // value by DefaultOption
1891 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
1895 // CheckBox question is not in IFR Form. This IFR form is not valid.
1897 if (VarStoreId
== 0) {
1898 Status
= EFI_INVALID_PARAMETER
;
1902 // Check whether this question is for the requested varstore.
1904 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1905 if (IfrCheckBox
->Question
.VarStoreId
!= VarStoreId
) {
1908 VarWidth
= (UINT16
) sizeof (BOOLEAN
);
1909 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
1910 if (EFI_ERROR (Status
)) {
1914 if (BlockData
== NULL
) {
1916 // BlockData == NULL means this opcode is not in the requst array.
1922 // Add default value for standard ID by CheckBox Flag
1924 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1926 // Prepare new DefaultValue
1928 DefaultData
.DefaultId
= VarDefaultId
;
1929 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) == EFI_IFR_CHECKBOX_DEFAULT
) {
1931 // When flag is set, defautl value is TRUE.
1933 DefaultData
.Type
= DefaultValueFromFlag
;
1934 DefaultData
.Value
.b
= TRUE
;
1937 // When flag is not set, defautl value is FASLE.
1939 DefaultData
.Type
= DefaultValueFromDefault
;
1940 DefaultData
.Value
.b
= FALSE
;
1943 // Add DefaultValue into current BlockData
1945 InsertDefaultValue (BlockData
, &DefaultData
);
1948 // Add default value for Manufacture ID by CheckBox Flag
1950 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1952 // Prepare new DefaultValue
1954 DefaultData
.DefaultId
= VarDefaultId
;
1955 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) == EFI_IFR_CHECKBOX_DEFAULT_MFG
) {
1957 // When flag is set, defautl value is TRUE.
1959 DefaultData
.Type
= DefaultValueFromFlag
;
1960 DefaultData
.Value
.b
= TRUE
;
1963 // When flag is not set, defautl value is FASLE.
1965 DefaultData
.Type
= DefaultValueFromDefault
;
1966 DefaultData
.Value
.b
= FALSE
;
1969 // Add DefaultValue into current BlockData
1971 InsertDefaultValue (BlockData
, &DefaultData
);
1974 case EFI_IFR_DATE_OP
:
1976 // offset by question header
1977 // width MaxSize * sizeof (CHAR16)
1978 // no default value, only block array
1982 // Date question is not in IFR Form. This IFR form is not valid.
1984 if (VarStoreId
== 0) {
1985 Status
= EFI_INVALID_PARAMETER
;
1989 // Check whether this question is for the requested varstore.
1991 IfrDate
= (EFI_IFR_DATE
*) IfrOpHdr
;
1992 if (IfrDate
->Question
.VarStoreId
!= VarStoreId
) {
1996 VarWidth
= (UINT16
) sizeof (EFI_HII_DATE
);
1997 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
1998 if (EFI_ERROR (Status
)) {
2003 case EFI_IFR_TIME_OP
:
2005 // offset by question header
2006 // width MaxSize * sizeof (CHAR16)
2007 // no default value, only block array
2011 // Time question is not in IFR Form. This IFR form is not valid.
2013 if (VarStoreId
== 0) {
2014 Status
= EFI_INVALID_PARAMETER
;
2018 // Check whether this question is for the requested varstore.
2020 IfrTime
= (EFI_IFR_TIME
*) IfrOpHdr
;
2021 if (IfrTime
->Question
.VarStoreId
!= VarStoreId
) {
2025 VarWidth
= (UINT16
) sizeof (EFI_HII_TIME
);
2026 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2027 if (EFI_ERROR (Status
)) {
2032 case EFI_IFR_STRING_OP
:
2034 // offset by question header
2035 // width MaxSize * sizeof (CHAR16)
2036 // no default value, only block array
2040 // String question is not in IFR Form. This IFR form is not valid.
2042 if (VarStoreId
== 0) {
2043 Status
= EFI_INVALID_PARAMETER
;
2047 // Check whether this question is for the requested varstore.
2049 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
2050 if (IfrString
->Question
.VarStoreId
!= VarStoreId
) {
2054 VarWidth
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
2055 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2056 if (EFI_ERROR (Status
)) {
2061 // No default value for string.
2066 case EFI_IFR_PASSWORD_OP
:
2068 // offset by question header
2069 // width MaxSize * sizeof (CHAR16)
2070 // no default value, only block array
2074 // Password question is not in IFR Form. This IFR form is not valid.
2076 if (VarStoreId
== 0) {
2077 Status
= EFI_INVALID_PARAMETER
;
2081 // Check whether this question is for the requested varstore.
2083 IfrPassword
= (EFI_IFR_PASSWORD
*) IfrOpHdr
;
2084 if (IfrPassword
->Question
.VarStoreId
!= VarStoreId
) {
2088 VarWidth
= (UINT16
) (IfrPassword
->MaxSize
* sizeof (UINT16
));
2089 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2090 if (EFI_ERROR (Status
)) {
2095 // No default value for string.
2100 case EFI_IFR_ONE_OF_OPTION_OP
:
2102 // No matched block data is ignored.
2104 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
2108 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
2109 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
2111 // Get ordered list option data type.
2113 if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_8
|| IfrOneOfOption
->Type
== EFI_IFR_TYPE_BOOLEAN
) {
2115 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_16
) {
2117 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_32
) {
2119 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_64
) {
2123 // Invalid ordered list option data type.
2125 Status
= EFI_INVALID_PARAMETER
;
2126 if (BlockData
->Name
!= NULL
) {
2127 FreePool (BlockData
->Name
);
2129 FreePool (BlockData
);
2134 // Calculate Ordered list QuestionId width.
2136 BlockData
->Width
= (UINT16
) (BlockData
->Width
* VarWidth
);
2138 // Check whether this question is in requested block array.
2140 if (!BlockArrayCheck (RequestBlockArray
, BlockData
->Offset
, BlockData
->Width
, (BOOLEAN
)(BlockData
->Name
!= NULL
), HiiHandle
)) {
2142 // This question is not in the requested string. Skip it.
2144 if (BlockData
->Name
!= NULL
) {
2145 FreePool (BlockData
->Name
);
2147 FreePool (BlockData
);
2152 // Check this var question is in the var storage
2154 if ((BlockData
->Name
== NULL
) && ((BlockData
->Offset
+ BlockData
->Width
) > VarStorageData
->Size
)) {
2155 Status
= EFI_INVALID_PARAMETER
;
2156 if (BlockData
->Name
!= NULL
) {
2157 FreePool (BlockData
->Name
);
2159 FreePool (BlockData
);
2163 // Add Block Data into VarStorageData BlockEntry
2165 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
2167 // No default data for OrderedList.
2174 // 1. Set default value for OneOf option when flag field has default attribute.
2176 if (((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) ||
2177 ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
)) {
2179 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
2180 // The first oneof option value will be used as default value when no default value is specified.
2182 FirstOneOfOption
= FALSE
;
2184 // Prepare new DefaultValue
2186 DefaultData
.Type
= DefaultValueFromFlag
;
2187 CopyMem (&DefaultData
.Value
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2188 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) {
2189 DefaultData
.DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2190 InsertDefaultValue (BlockData
, &DefaultData
);
2192 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
) {
2193 DefaultData
.DefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2194 InsertDefaultValue (BlockData
, &DefaultData
);
2199 // 2. Set as the default value when this is the first option.
2200 // The first oneof option value will be used as default value when no default value is specified.
2202 if (FirstOneOfOption
) {
2203 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
2204 FirstOneOfOption
= FALSE
;
2207 // Prepare new DefaultValue
2209 DefaultData
.Type
= DefaultValueFromDefault
;
2210 CopyMem (&DefaultData
.Value
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2211 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2212 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2213 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2214 InsertDefaultValue (BlockData
, &DefaultData
);
2219 case EFI_IFR_DEFAULT_OP
:
2221 // Update Current BlockData to the default value.
2223 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
2225 // No matched block data is ignored.
2230 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
2232 // OrderedList Opcode is no default value.
2237 // Get the DefaultId
2239 IfrDefault
= (EFI_IFR_DEFAULT
*) IfrOpHdr
;
2240 VarDefaultId
= IfrDefault
->DefaultId
;
2242 // Prepare new DefaultValue
2244 DefaultData
.Type
= DefaultValueFromOpcode
;
2245 DefaultData
.DefaultId
= VarDefaultId
;
2246 CopyMem (&DefaultData
.Value
, &IfrDefault
->Value
, IfrDefault
->Header
.Length
- OFFSET_OF (EFI_IFR_DEFAULT
, Value
));
2248 // If the value field is expression, set the cleaned flag.
2249 if (IfrDefault
->Type
== EFI_IFR_TYPE_OTHER
) {
2250 DefaultData
.Cleaned
= TRUE
;
2253 // Add DefaultValue into current BlockData
2255 InsertDefaultValue (BlockData
, &DefaultData
);
2258 // After insert the default value, reset the cleaned value for next
2259 // time used. If not set here, need to set the value before everytime
2262 DefaultData
.Cleaned
= FALSE
;
2265 case EFI_IFR_END_OP
:
2267 // End Opcode is for Var question.
2269 if (BlockData
!= NULL
) {
2270 if (BlockData
->Scope
> 0) {
2273 if (BlockData
->Scope
== 0) {
2281 if (BlockData
!= NULL
) {
2282 if (BlockData
->Scope
> 0) {
2283 BlockData
->Scope
= (UINT8
) (BlockData
->Scope
+ IfrOpHdr
->Scope
);
2286 if (BlockData
->Scope
== 0) {
2293 IfrOffset
+= IfrOpHdr
->Length
;
2294 PackageOffset
+= IfrOpHdr
->Length
;
2298 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
2299 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
2300 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; ) {
2301 DefaultDataPtr
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
2302 LinkDefault
= LinkDefault
->ForwardLink
;
2303 if (DefaultDataPtr
->Cleaned
== TRUE
) {
2304 RemoveEntryList (&DefaultDataPtr
->Entry
);
2305 FreePool (DefaultDataPtr
);
2314 parse the configrequest string, get the elements.
2316 @param ConfigRequest The input configrequest string.
2317 @param Progress Return the progress data.
2319 @retval Block data pointer.
2323 IN EFI_STRING ConfigRequest
,
2324 OUT EFI_STRING
*Progress
2327 EFI_STRING StringPtr
;
2328 IFR_BLOCK_DATA
*BlockData
;
2329 IFR_BLOCK_DATA
*RequestBlockArray
;
2335 IFR_BLOCK_DATA
*NextBlockData
;
2341 // Init RequestBlockArray
2343 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2344 if (RequestBlockArray
== NULL
) {
2347 InitializeListHead (&RequestBlockArray
->Entry
);
2350 // Get the request Block array from the request string
2355 // Parse each <RequestElement> if exists
2356 // Only <BlockName> format is supported by this help function.
2357 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
2359 StringPtr
= ConfigRequest
;
2360 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
2362 // Skip the OFFSET string
2364 *Progress
= StringPtr
;
2365 StringPtr
+= StrLen (L
"&OFFSET=");
2369 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2370 if (EFI_ERROR (Status
)) {
2377 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
2379 FreePool (TmpBuffer
);
2381 StringPtr
+= Length
;
2382 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
2385 StringPtr
+= StrLen (L
"&WIDTH=");
2390 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2391 if (EFI_ERROR (Status
)) {
2398 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
2400 FreePool (TmpBuffer
);
2402 StringPtr
+= Length
;
2403 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
2410 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2411 if (BlockData
== NULL
) {
2414 BlockData
->Offset
= Offset
;
2415 BlockData
->Width
= Width
;
2416 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
2419 // Skip &VALUE string if &VALUE does exists.
2421 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) == 0) {
2422 StringPtr
+= StrLen (L
"&VALUE=");
2427 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2428 if (EFI_ERROR (Status
)) {
2432 StringPtr
+= Length
;
2433 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
2438 // If '\0', parsing is finished.
2440 if (*StringPtr
== 0) {
2446 // Merge the requested block data.
2448 Link
= RequestBlockArray
->Entry
.ForwardLink
;
2449 while ((Link
!= &RequestBlockArray
->Entry
) && (Link
->ForwardLink
!= &RequestBlockArray
->Entry
)) {
2450 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
2451 NextBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2452 if ((NextBlockData
->Offset
>= BlockData
->Offset
) && (NextBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
2453 if ((NextBlockData
->Offset
+ NextBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
2454 BlockData
->Width
= (UINT16
) (NextBlockData
->Offset
+ NextBlockData
->Width
- BlockData
->Offset
);
2456 RemoveEntryList (Link
->ForwardLink
);
2457 FreePool (NextBlockData
);
2460 Link
= Link
->ForwardLink
;
2463 return RequestBlockArray
;
2466 if (RequestBlockArray
!= NULL
) {
2468 // Free Link Array RequestBlockArray
2470 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
2471 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2472 RemoveEntryList (&BlockData
->Entry
);
2473 FreePool (BlockData
);
2476 FreePool (RequestBlockArray
);
2483 parse the configrequest string, get the elements.
2485 @param ConfigRequest The input config request string.
2486 @param Progress Return the progress data.
2488 @retval return data block array.
2492 IN EFI_STRING ConfigRequest
,
2493 OUT EFI_STRING
*Progress
2496 EFI_STRING StringPtr
;
2498 IFR_BLOCK_DATA
*BlockData
;
2499 IFR_BLOCK_DATA
*RequestBlockArray
;
2502 StringPtr
= ConfigRequest
;
2505 // Init RequestBlockArray
2507 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2508 if (RequestBlockArray
== NULL
) {
2511 InitializeListHead (&RequestBlockArray
->Entry
);
2514 // Get the request Block array from the request string
2518 // Parse each <RequestElement> if exists
2519 // Only <BlockName> format is supported by this help function.
2520 // <BlockName> ::= &'Name***=***
2522 while (StringPtr
!= NULL
&& *StringPtr
== L
'&') {
2524 *Progress
= StringPtr
;
2526 // Skip the L"&" string
2531 if ((NextTag
= StrStr (StringPtr
, L
"=")) != NULL
) {
2534 } else if ((NextTag
= StrStr (StringPtr
, L
"&")) != NULL
) {
2541 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2542 if (BlockData
== NULL
) {
2549 BlockData
->Name
= AllocateCopyPool(StrSize (StringPtr
), StringPtr
);
2550 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
2554 // If has value, skip the value.
2556 StringPtr
= NextTag
+ 1;
2558 StringPtr
= StrStr (StringPtr
, L
"&");
2559 } else if (NextTag
!= NULL
) {
2561 // restore the '&' text.
2563 StringPtr
= NextTag
;
2568 return RequestBlockArray
;
2571 if (RequestBlockArray
!= NULL
) {
2573 // Free Link Array RequestBlockArray
2575 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
2576 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2577 RemoveEntryList (&BlockData
->Entry
);
2578 if (BlockData
->Name
!= NULL
) {
2579 FreePool (BlockData
->Name
);
2581 FreePool (BlockData
);
2584 FreePool (RequestBlockArray
);
2591 Generate ConfigRequest string base on the varstore info.
2593 @param ConfigHdr The config header for this varstore.
2594 @param VarStorageData The varstore info.
2595 @param Status Return Status.
2596 @param ConfigRequest The ConfigRequest info may be return.
2598 @retval TRUE Need to continue
2599 @retval Others NO need to continue or error occur.
2602 GenerateConfigRequest (
2603 IN CHAR16
*ConfigHdr
,
2604 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
2605 OUT EFI_STATUS
*Status
,
2606 IN OUT EFI_STRING
*ConfigRequest
2612 CHAR16
*FullConfigRequest
;
2614 IFR_BLOCK_DATA
*BlockData
;
2617 // Append VarStorageData BlockEntry into *Request string
2618 // Now support only one varstore in a form package.
2622 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
2623 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
2627 // Compute the length of the entire request starting with <ConfigHdr> and a
2631 Length
= StrLen (ConfigHdr
) + 1;
2633 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
2635 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
2636 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2638 // Add <BlockName> length for each Name
2640 // <BlockName> ::= &Name1&Name2&...
2641 // |1| StrLen(Name1)
2643 Length
= Length
+ (1 + StrLen (BlockData
->Name
));
2646 // Add <BlockName> length for each Offset/Width pair
2648 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
2649 // | 8 | 4 | 7 | 4 |
2651 Length
= Length
+ (8 + 4 + 7 + 4);
2655 // No any request block data is found. The request string can't be constructed.
2658 *Status
= EFI_SUCCESS
;
2663 // Allocate buffer for the entire <ConfigRequest>
2665 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
2666 if (FullConfigRequest
== NULL
) {
2667 *Status
= EFI_OUT_OF_RESOURCES
;
2670 StringPtr
= FullConfigRequest
;
2673 // Start with <ConfigHdr>
2675 StrCpyS (StringPtr
, Length
, ConfigHdr
);
2676 StringPtr
+= StrLen (StringPtr
);
2679 // Loop through all the Offset/Width pairs and append them to ConfigRequest
2681 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
2682 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
2683 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2689 (1 + StrLen (BlockData
->Name
) + 1) * sizeof (CHAR16
),
2695 // Append &OFFSET=XXXX&WIDTH=YYYY\0
2699 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
2700 L
"&OFFSET=%04X&WIDTH=%04X",
2705 StringPtr
+= StrLen (StringPtr
);
2708 // Set to the got full request string.
2710 HiiToLower (FullConfigRequest
);
2712 if (*ConfigRequest
!= NULL
) {
2713 FreePool (*ConfigRequest
);
2715 *ConfigRequest
= FullConfigRequest
;
2721 Generate ConfigRequest Header base on the varstore info.
2723 @param VarStorageData The varstore info.
2724 @param DevicePath Device path for this varstore.
2725 @param ConfigHdr The config header for this varstore.
2727 @retval EFI_SUCCESS Generate the header success.
2728 @retval EFI_OUT_OF_RESOURCES Allocate buffer fail.
2732 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
2733 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
2734 OUT EFI_STRING
*ConfigHdr
2743 Status
= EFI_SUCCESS
;
2749 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
2751 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
2752 if (VarStorageData
->Name
!= NULL
) {
2753 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
2755 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
2759 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
2760 (VOID
*) DevicePath
,
2764 Length
= StrLen (GuidStr
) + StrLen (NameStr
) + StrLen (PathStr
) + 1;
2765 if (VarStorageData
->Name
== NULL
) {
2769 *ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
2770 if (*ConfigHdr
== NULL
) {
2771 Status
= EFI_OUT_OF_RESOURCES
;
2774 StrCpyS (*ConfigHdr
, Length
, GuidStr
);
2775 StrCatS (*ConfigHdr
, Length
, NameStr
);
2776 if (VarStorageData
->Name
== NULL
) {
2777 StrCatS (*ConfigHdr
, Length
, L
"&");
2779 StrCatS (*ConfigHdr
, Length
, PathStr
);
2782 // Remove the last character L'&'
2784 *(*ConfigHdr
+ StrLen (*ConfigHdr
) - 1) = L
'\0';
2787 if (GuidStr
!= NULL
) {
2791 if (NameStr
!= NULL
) {
2795 if (PathStr
!= NULL
) {
2803 Get Data buffer size based on data type.
2805 @param ValueType The input data type.
2807 @retval The data buffer size for the input type.
2814 UINT16 StorageWidth
;
2816 switch (ValueType
) {
2817 case EFI_IFR_NUMERIC_SIZE_1
:
2818 case EFI_IFR_TYPE_BOOLEAN
:
2819 StorageWidth
= (UINT16
) sizeof (UINT8
);
2822 case EFI_IFR_NUMERIC_SIZE_2
:
2823 StorageWidth
= (UINT16
) sizeof (UINT16
);
2826 case EFI_IFR_NUMERIC_SIZE_4
:
2827 StorageWidth
= (UINT16
) sizeof (UINT32
);
2830 case EFI_IFR_NUMERIC_SIZE_8
:
2831 StorageWidth
= (UINT16
) sizeof (UINT64
);
2834 case EFI_IFR_TYPE_TIME
:
2835 StorageWidth
= (UINT16
) sizeof (EFI_IFR_TIME
);
2838 case EFI_IFR_TYPE_DATE
:
2839 StorageWidth
= (UINT16
) sizeof (EFI_IFR_DATE
);
2847 return StorageWidth
;
2851 Generate ConfigAltResp string base on the varstore info.
2853 @param ConfigHdr The config header for this varstore.
2854 @param VarStorageData The varstore info.
2855 @param DefaultIdArray The Default id array.
2856 @param DefaultAltCfgResp The DefaultAltCfgResp info may be return.
2858 @retval TRUE Need to continue
2859 @retval Others NO need to continue or error occur.
2862 GenerateAltConfigResp (
2863 IN CHAR16
*ConfigHdr
,
2864 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
2865 IN IFR_DEFAULT_DATA
*DefaultIdArray
,
2866 IN OUT EFI_STRING
*DefaultAltCfgResp
2872 LIST_ENTRY
*LinkData
;
2873 LIST_ENTRY
*LinkDefault
;
2874 LIST_ENTRY
*ListEntry
;
2876 IFR_BLOCK_DATA
*BlockData
;
2877 IFR_DEFAULT_DATA
*DefaultId
;
2878 IFR_DEFAULT_DATA
*DefaultValueData
;
2886 // Add length for <ConfigHdr> + '\0'
2888 Length
= StrLen (ConfigHdr
) + 1;
2890 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
2891 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
2893 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
2894 // |1| StrLen (ConfigHdr) | 8 | 4 |
2896 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
2898 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
2899 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
2900 ListEntry
= &BlockData
->DefaultValueEntry
;
2901 for (LinkDefault
= ListEntry
->ForwardLink
; LinkDefault
!= ListEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
2902 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
2903 if (DefaultValueData
->DefaultId
!= DefaultId
->DefaultId
) {
2906 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2908 // Add length for "&Name1=zzzzzzzzzzzz"
2911 Length
+= (1 + StrLen (BlockData
->Name
) + 1 + BlockData
->Width
* 2);
2914 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
2915 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
2917 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
2925 // No default value is found. The default string doesn't exist.
2932 // Allocate buffer for the entire <DefaultAltCfgResp>
2934 *DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
2935 if (*DefaultAltCfgResp
== NULL
) {
2936 return EFI_OUT_OF_RESOURCES
;
2938 StringPtr
= *DefaultAltCfgResp
;
2941 // Start with <ConfigHdr>
2943 StrCpyS (StringPtr
, Length
, ConfigHdr
);
2944 StringPtr
+= StrLen (StringPtr
);
2946 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
2947 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
2949 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
2950 // |1| StrLen (ConfigHdr) | 8 | 4 |
2954 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
2957 DefaultId
->DefaultId
2959 StringPtr
+= StrLen (StringPtr
);
2961 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
2962 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
2963 ListEntry
= &BlockData
->DefaultValueEntry
;
2964 for (LinkDefault
= ListEntry
->ForwardLink
; LinkDefault
!= ListEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
2965 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
2966 if (DefaultValueData
->DefaultId
!= DefaultId
->DefaultId
) {
2969 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2972 (1 + StrLen (ConfigHdr
) + 1) * sizeof (CHAR16
),
2976 StringPtr
+= StrLen (StringPtr
);
2979 // Add <BlockConfig>
2980 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
2984 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
2985 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
2989 StringPtr
+= StrLen (StringPtr
);
2991 Width
= BlockData
->Width
;
2993 // Convert Value to a hex string in "%x" format
2994 // NOTE: This is in the opposite byte that GUID and PATH use
2996 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
2997 for (; Width
> 0; Width
--) {
2998 StringPtr
+= UnicodeValueToString (StringPtr
, PREFIX_ZERO
| RADIX_HEX
, TmpBuffer
[Width
- 1], 2);
3004 HiiToLower (*DefaultAltCfgResp
);
3010 This function gets the full request string and full default value string by
3011 parsing IFR data in HII form packages.
3013 When Request points to NULL string, the request string and default value string
3014 for each varstore in form package will return.
3016 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
3017 @param DevicePath Device Path which Hii Config Access Protocol is registered.
3018 @param Request Pointer to a null-terminated Unicode string in
3019 <ConfigRequest> format. When it doesn't contain
3020 any RequestElement, it will be updated to return
3021 the full RequestElement retrieved from IFR data.
3022 If it points to NULL, the request string for the first
3023 varstore in form package will be merged into a
3024 <MultiConfigRequest> format string and return.
3025 @param AltCfgResp Pointer to a null-terminated Unicode string in
3026 <ConfigAltResp> format. When the pointer is to NULL,
3027 the full default value string retrieved from IFR data
3028 will return. When the pinter is to a string, the
3029 full default value string retrieved from IFR data
3030 will be merged into the input string and return.
3031 When Request points to NULL, the default value string
3032 for each varstore in form package will be merged into
3033 a <MultiConfigAltResp> format string and return.
3034 @param PointerProgress Optional parameter, it can be be NULL.
3035 When it is not NULL, if Request is NULL, it returns NULL.
3036 On return, points to a character in the Request
3037 string. Points to the string's null terminator if
3038 request was successful. Points to the most recent
3039 & before the first failing name / value pair (or
3040 the beginning of the string if the failure is in
3041 the first name / value pair) if the request was
3043 @retval EFI_SUCCESS The Results string is set to the full request string.
3044 And AltCfgResp contains all default value string.
3045 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
3046 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string
3047 can't be found in Form package.
3048 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.
3049 @retval EFI_INVALID_PARAMETER Request points to NULL.
3054 GetFullStringFromHiiFormPackages (
3055 IN HII_DATABASE_RECORD
*DataBaseRecord
,
3056 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3057 IN OUT EFI_STRING
*Request
,
3058 IN OUT EFI_STRING
*AltCfgResp
,
3059 OUT EFI_STRING
*PointerProgress OPTIONAL
3063 UINT8
*HiiFormPackage
;
3065 IFR_BLOCK_DATA
*RequestBlockArray
;
3066 IFR_BLOCK_DATA
*BlockData
;
3067 IFR_DEFAULT_DATA
*DefaultValueData
;
3068 IFR_DEFAULT_DATA
*DefaultId
;
3069 IFR_DEFAULT_DATA
*DefaultIdArray
;
3070 IFR_VARSTORAGE_DATA
*VarStorageData
;
3071 EFI_STRING DefaultAltCfgResp
;
3072 EFI_STRING ConfigHdr
;
3073 EFI_STRING StringPtr
;
3074 EFI_STRING Progress
;
3076 if (DataBaseRecord
== NULL
|| DevicePath
== NULL
|| Request
== NULL
|| AltCfgResp
== NULL
) {
3077 return EFI_INVALID_PARAMETER
;
3081 // Initialize the local variables.
3083 RequestBlockArray
= NULL
;
3084 DefaultIdArray
= NULL
;
3085 VarStorageData
= NULL
;
3086 DefaultAltCfgResp
= NULL
;
3088 HiiFormPackage
= NULL
;
3090 Progress
= *Request
;
3092 Status
= GetFormPackageData (DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
3093 if (EFI_ERROR (Status
)) {
3098 // 1. Get the request block array by Request String when Request string containts the block array.
3101 if (*Request
!= NULL
) {
3102 StringPtr
= *Request
;
3106 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3107 Status
= EFI_INVALID_PARAMETER
;
3110 StringPtr
+= StrLen (L
"GUID=");
3111 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
3114 if (*StringPtr
== L
'\0') {
3115 Status
= EFI_INVALID_PARAMETER
;
3118 StringPtr
+= StrLen (L
"&NAME=");
3119 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
3122 if (*StringPtr
== L
'\0') {
3123 Status
= EFI_INVALID_PARAMETER
;
3126 StringPtr
+= StrLen (L
"&PATH=");
3127 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
3131 if (*StringPtr
== L
'\0') {
3133 // No request block is found.
3140 // If StringPtr != NULL, get the request elements.
3142 if (StringPtr
!= NULL
) {
3143 if (StrStr (StringPtr
, L
"&OFFSET=") != NULL
) {
3144 RequestBlockArray
= GetBlockElement(StringPtr
, &Progress
);
3146 RequestBlockArray
= GetNameElement(StringPtr
, &Progress
);
3149 if (RequestBlockArray
== NULL
) {
3150 Status
= EFI_INVALID_PARAMETER
;
3156 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
3158 DefaultIdArray
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
3159 if (DefaultIdArray
== NULL
) {
3160 Status
= EFI_OUT_OF_RESOURCES
;
3163 InitializeListHead (&DefaultIdArray
->Entry
);
3166 // Initialize VarStorageData to store the var store Block and Default value information.
3168 VarStorageData
= (IFR_VARSTORAGE_DATA
*) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA
));
3169 if (VarStorageData
== NULL
) {
3170 Status
= EFI_OUT_OF_RESOURCES
;
3173 InitializeListHead (&VarStorageData
->Entry
);
3174 InitializeListHead (&VarStorageData
->BlockEntry
);
3177 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
3181 // Parse the opcode in form pacakge to get the default setting.
3183 Status
= ParseIfrData (DataBaseRecord
->Handle
,
3185 (UINT32
) PackageSize
,
3190 if (EFI_ERROR (Status
)) {
3195 // No requested varstore in IFR data and directly return
3197 if (VarStorageData
->Type
== 0 && VarStorageData
->Name
== NULL
) {
3198 Status
= EFI_SUCCESS
;
3203 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
3205 Status
= GenerateHdr (VarStorageData
, DevicePath
, &ConfigHdr
);
3206 if (EFI_ERROR (Status
)) {
3210 if (RequestBlockArray
== NULL
) {
3211 if (!GenerateConfigRequest(ConfigHdr
, VarStorageData
, &Status
, Request
)) {
3217 // 4. Construct Default Value string in AltResp according to request element.
3218 // Go through all VarStorageData Entry and get the DefaultId array for each one
3219 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
3221 Status
= GenerateAltConfigResp (ConfigHdr
, VarStorageData
, DefaultIdArray
, &DefaultAltCfgResp
);
3222 if (EFI_ERROR (Status
)) {
3227 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.
3229 if (*AltCfgResp
!= NULL
&& DefaultAltCfgResp
!= NULL
) {
3230 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
3231 FreePool (DefaultAltCfgResp
);
3232 } else if (*AltCfgResp
== NULL
) {
3233 *AltCfgResp
= DefaultAltCfgResp
;
3237 if (RequestBlockArray
!= NULL
) {
3239 // Free Link Array RequestBlockArray
3241 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
3242 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3243 RemoveEntryList (&BlockData
->Entry
);
3244 if (BlockData
->Name
!= NULL
) {
3245 FreePool (BlockData
->Name
);
3247 FreePool (BlockData
);
3250 FreePool (RequestBlockArray
);
3253 if (VarStorageData
!= NULL
) {
3255 // Free link array VarStorageData
3257 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
3258 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3259 RemoveEntryList (&BlockData
->Entry
);
3260 if (BlockData
->Name
!= NULL
) {
3261 FreePool (BlockData
->Name
);
3264 // Free default value link array
3266 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
3267 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
3268 RemoveEntryList (&DefaultValueData
->Entry
);
3269 FreePool (DefaultValueData
);
3271 FreePool (BlockData
);
3273 FreePool (VarStorageData
);
3276 if (DefaultIdArray
!= NULL
) {
3278 // Free DefaultId Array
3280 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
3281 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
3282 RemoveEntryList (&DefaultId
->Entry
);
3283 FreePool (DefaultId
);
3285 FreePool (DefaultIdArray
);
3289 // Free the allocated string
3291 if (ConfigHdr
!= NULL
) {
3292 FreePool (ConfigHdr
);
3296 // Free Pacakge data
3298 if (HiiFormPackage
!= NULL
) {
3299 FreePool (HiiFormPackage
);
3302 if (PointerProgress
!= NULL
) {
3303 if (*Request
== NULL
) {
3304 *PointerProgress
= NULL
;
3305 } else if (EFI_ERROR (Status
)) {
3306 *PointerProgress
= *Request
;
3308 *PointerProgress
= *Request
+ StrLen (*Request
);
3316 This function gets the full request resp string by
3317 parsing IFR data in HII form packages.
3319 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3321 @param EfiVarStoreInfo The efi varstore info which is save in the EFI
3322 varstore data structure.
3323 @param Request Pointer to a null-terminated Unicode string in
3324 <ConfigRequest> format.
3325 @param RequestResp Pointer to a null-terminated Unicode string in
3326 <ConfigResp> format.
3327 @param AccessProgress On return, points to a character in the Request
3328 string. Points to the string's null terminator if
3329 request was successful. Points to the most recent
3330 & before the first failing name / value pair (or
3331 the beginning of the string if the failure is in
3332 the first name / value pair) if the request was
3335 @retval EFI_SUCCESS The Results string is set to the full request string.
3336 And AltCfgResp contains all default value string.
3337 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
3338 @retval EFI_INVALID_PARAMETER Request points to NULL.
3342 GetConfigRespFromEfiVarStore (
3343 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3344 IN EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
,
3345 IN EFI_STRING Request
,
3346 OUT EFI_STRING
*RequestResp
,
3347 OUT EFI_STRING
*AccessProgress
3351 EFI_STRING VarStoreName
;
3355 Status
= EFI_SUCCESS
;
3358 VarStoreName
= NULL
;
3359 *AccessProgress
= Request
;
3361 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)EfiVarStoreInfo
->Name
) * sizeof (CHAR16
));
3362 if (VarStoreName
== NULL
) {
3363 Status
= EFI_OUT_OF_RESOURCES
;
3366 AsciiStrToUnicodeStr ((CHAR8
*) EfiVarStoreInfo
->Name
, VarStoreName
);
3369 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, NULL
);
3370 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3374 VarStore
= AllocateZeroPool (BufferSize
);
3375 ASSERT (VarStore
!= NULL
);
3376 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, VarStore
);
3377 if (EFI_ERROR (Status
)) {
3381 Status
= HiiBlockToConfig(This
, Request
, VarStore
, BufferSize
, RequestResp
, AccessProgress
);
3382 if (EFI_ERROR (Status
)) {
3387 if (VarStoreName
!= NULL
) {
3388 FreePool (VarStoreName
);
3391 if (VarStore
!= NULL
) {
3392 FreePool (VarStore
);
3400 This function route the full request resp string for efi varstore.
3402 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3404 @param EfiVarStoreInfo The efi varstore info which is save in the EFI
3405 varstore data structure.
3406 @param RequestResp Pointer to a null-terminated Unicode string in
3407 <ConfigResp> format.
3408 @param Result Pointer to a null-terminated Unicode string in
3409 <ConfigResp> format.
3411 @retval EFI_SUCCESS The Results string is set to the full request string.
3412 And AltCfgResp contains all default value string.
3413 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
3414 @retval EFI_INVALID_PARAMETER Request points to NULL.
3418 RouteConfigRespForEfiVarStore (
3419 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3420 IN EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
,
3421 IN EFI_STRING RequestResp
,
3422 OUT EFI_STRING
*Result
3426 EFI_STRING VarStoreName
;
3431 Status
= EFI_SUCCESS
;
3434 VarStoreName
= NULL
;
3436 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)EfiVarStoreInfo
->Name
) * sizeof (CHAR16
));
3437 if (VarStoreName
== NULL
) {
3438 Status
= EFI_OUT_OF_RESOURCES
;
3441 AsciiStrToUnicodeStr ((CHAR8
*) EfiVarStoreInfo
->Name
, VarStoreName
);
3443 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, NULL
);
3444 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3448 BlockSize
= BufferSize
;
3449 VarStore
= AllocateZeroPool (BufferSize
);
3450 ASSERT (VarStore
!= NULL
);
3451 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, VarStore
);
3452 if (EFI_ERROR (Status
)) {
3456 Status
= HiiConfigToBlock(This
, RequestResp
, VarStore
, &BlockSize
, Result
);
3457 if (EFI_ERROR (Status
)) {
3461 Status
= gRT
->SetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, EfiVarStoreInfo
->Attributes
, BufferSize
, VarStore
);
3462 if (EFI_ERROR (Status
)) {
3467 if (VarStoreName
!= NULL
) {
3468 FreePool (VarStoreName
);
3471 if (VarStore
!= NULL
) {
3472 FreePool (VarStore
);
3479 Validate the config request elements.
3481 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format,
3482 without configHdr field.
3484 @retval CHAR16 * THE first Name/value pair not correct.
3485 @retval NULL Success parse the name/value pair
3488 OffsetWidthValidate (
3489 CHAR16
*ConfigElements
3495 StringPtr
= ConfigElements
;
3499 if (StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) != 0) {
3503 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3506 if (*StringPtr
== L
'\0') {
3510 StringPtr
+= StrLen (L
"&WIDTH=");
3511 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) != 0) {
3515 if (*StringPtr
== L
'\0') {
3522 Validate the config request elements.
3524 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format,
3525 without configHdr field.
3527 @retval CHAR16 * THE first Name/value pair not correct.
3528 @retval NULL Success parse the name/value pair
3533 CHAR16
*ConfigElements
3539 StringPtr
= ConfigElements
;
3543 if (*StringPtr
!= L
'&') {
3548 StringPtr
= StrStr (StringPtr
, L
"&");
3550 if (StringPtr
== NULL
) {
3557 Validate the config request string.
3559 @param ConfigRequest A null-terminated Unicode string in <ConfigRequest> format.
3561 @retval CHAR16 * THE first element not correct.
3562 @retval NULL Success parse the name/value pair
3566 ConfigRequestValidate (
3567 CHAR16
*ConfigRequest
3570 BOOLEAN HasNameField
;
3573 HasNameField
= TRUE
;
3574 StringPtr
= ConfigRequest
;
3577 // Check <ConfigHdr>
3579 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3580 return ConfigRequest
;
3582 StringPtr
+= StrLen (L
"GUID=");
3583 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
3586 if (*StringPtr
== L
'\0') {
3587 return ConfigRequest
;
3589 StringPtr
+= StrLen (L
"&NAME=");
3590 if (*StringPtr
== L
'&') {
3591 HasNameField
= FALSE
;
3593 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
3596 if (*StringPtr
== L
'\0') {
3597 return ConfigRequest
;
3599 StringPtr
+= StrLen (L
"&PATH=");
3600 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
3604 if (*StringPtr
== L
'\0') {
3610 // Should be Buffer varstore, config request should be "OFFSET/Width" pairs.
3612 return OffsetWidthValidate(StringPtr
);
3615 // Should be Name/Value varstore, config request should be "&name1&name2..." pairs.
3617 return NameValueValidate(StringPtr
);
3622 This function allows a caller to extract the current configuration
3623 for one or more named elements from one or more drivers.
3625 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3627 @param Request A null-terminated Unicode string in
3628 <MultiConfigRequest> format.
3629 @param Progress On return, points to a character in the Request
3630 string. Points to the string's null terminator if
3631 request was successful. Points to the most recent
3632 & before the first failing name / value pair (or
3633 the beginning of the string if the failure is in
3634 the first name / value pair) if the request was
3636 @param Results Null-terminated Unicode string in
3637 <MultiConfigAltResp> format which has all values
3638 filled in for the names in the Request string.
3639 String to be allocated by the called function.
3641 @retval EFI_SUCCESS The Results string is filled with the values
3642 corresponding to all requested names.
3643 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
3644 results that must be stored awaiting possible
3646 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
3647 Progress set to the "G" in "GUID" of the routing
3648 header that doesn't match. Note: There is no
3649 requirement that all routing data be validated
3650 before any configuration extraction.
3651 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
3652 parameter would result in this type of error. The
3653 Progress parameter is set to NULL.
3654 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
3655 before the error or the beginning of the string.
3656 @retval EFI_INVALID_PARAMETER The ExtractConfig function of the underlying HII
3657 Configuration Access Protocol returned
3658 EFI_INVALID_PARAMETER. Progress set to most recent
3659 & before the error or the beginning of the string.
3664 HiiConfigRoutingExtractConfig (
3665 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3666 IN CONST EFI_STRING Request
,
3667 OUT EFI_STRING
*Progress
,
3668 OUT EFI_STRING
*Results
3671 HII_DATABASE_PRIVATE_DATA
*Private
;
3672 EFI_STRING StringPtr
;
3673 EFI_STRING ConfigRequest
;
3675 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
3676 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
3679 HII_DATABASE_RECORD
*Database
;
3680 UINT8
*DevicePathPkg
;
3681 UINT8
*CurrentDevicePath
;
3682 EFI_HANDLE DriverHandle
;
3683 EFI_HII_HANDLE HiiHandle
;
3684 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
3685 EFI_STRING AccessProgress
;
3686 EFI_STRING AccessResults
;
3687 EFI_STRING DefaultResults
;
3688 BOOLEAN FirstElement
;
3689 BOOLEAN IfrDataParsedFlag
;
3690 BOOLEAN IsEfiVarStore
;
3691 EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
;
3692 EFI_STRING ErrorPtr
;
3693 UINTN DevicePathSize
;
3695 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
3696 return EFI_INVALID_PARAMETER
;
3699 if (Request
== NULL
) {
3701 return EFI_INVALID_PARAMETER
;
3704 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
3705 StringPtr
= Request
;
3706 *Progress
= StringPtr
;
3707 DefaultResults
= NULL
;
3708 ConfigRequest
= NULL
;
3709 Status
= EFI_SUCCESS
;
3710 AccessResults
= NULL
;
3711 AccessProgress
= NULL
;
3713 IfrDataParsedFlag
= FALSE
;
3714 IsEfiVarStore
= FALSE
;
3715 EfiVarStoreInfo
= NULL
;
3718 // The first element of <MultiConfigRequest> should be
3719 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
3721 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3722 return EFI_INVALID_PARAMETER
;
3725 FirstElement
= TRUE
;
3728 // Allocate a fix length of memory to store Results. Reallocate memory for
3729 // Results if this fix length is insufficient.
3731 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
3732 if (*Results
== NULL
) {
3733 return EFI_OUT_OF_RESOURCES
;
3736 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
3738 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
3739 // or most recent & before the error.
3741 if (StringPtr
== Request
) {
3742 *Progress
= StringPtr
;
3744 *Progress
= StringPtr
- 1;
3748 // Process each <ConfigRequest> of <MultiConfigRequest>
3750 Length
= CalculateConfigStringLen (StringPtr
);
3751 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
3752 if (ConfigRequest
== NULL
) {
3753 Status
= EFI_OUT_OF_RESOURCES
;
3756 *(ConfigRequest
+ Length
) = 0;
3759 // Get the UEFI device path
3761 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
3762 if (EFI_ERROR (Status
)) {
3767 // Find driver which matches the routing data.
3769 DriverHandle
= NULL
;
3772 for (Link
= Private
->DatabaseList
.ForwardLink
;
3773 Link
!= &Private
->DatabaseList
;
3774 Link
= Link
->ForwardLink
3776 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
3777 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
3778 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
3779 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
3780 if ((CompareMem (DevicePath
,CurrentDevicePath
,DevicePathSize
) == 0) && IsThisPackageList(Database
, ConfigRequest
)) {
3781 DriverHandle
= Database
->DriverHandle
;
3782 HiiHandle
= Database
->Handle
;
3789 // Try to find driver handle by device path.
3791 if (DriverHandle
== NULL
) {
3792 TempDevicePath
= DevicePath
;
3793 Status
= gBS
->LocateDevicePath (
3794 &gEfiDevicePathProtocolGuid
,
3798 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
3800 // Routing data does not match any known driver.
3801 // Set Progress to the 'G' in "GUID" of the routing header.
3803 *Progress
= StringPtr
;
3804 Status
= EFI_NOT_FOUND
;
3810 // Validate ConfigRequest String.
3812 ErrorPtr
= ConfigRequestValidate(ConfigRequest
);
3813 if (ErrorPtr
!= NULL
) {
3814 *Progress
= StrStr (StringPtr
, ErrorPtr
);
3815 Status
= EFI_INVALID_PARAMETER
;
3820 // Check whether ConfigRequest contains request string.
3822 IfrDataParsedFlag
= FALSE
;
3823 if ((HiiHandle
!= NULL
) && !GetElementsFromRequest(ConfigRequest
)) {
3825 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
3827 IfrDataParsedFlag
= TRUE
;
3828 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, &AccessProgress
);
3829 if (EFI_ERROR (Status
)) {
3831 // AccessProgress indicates the parsing progress on <ConfigRequest>.
3832 // Map it to the progress on <MultiConfigRequest> then return it.
3834 ASSERT (AccessProgress
!= NULL
);
3835 *Progress
= StrStr (StringPtr
, AccessProgress
);
3839 // Not any request block is found.
3841 if (!GetElementsFromRequest(ConfigRequest
)) {
3842 AccessResults
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
3843 goto NextConfigString
;
3848 // Check whether this ConfigRequest is search from Efi varstore type storage.
3850 Status
= GetVarStoreType(Database
, ConfigRequest
, &IsEfiVarStore
, &EfiVarStoreInfo
);
3851 if (EFI_ERROR (Status
)) {
3855 if (IsEfiVarStore
) {
3857 // Call the GetVariable function to extract settings.
3859 Status
= GetConfigRespFromEfiVarStore(This
, EfiVarStoreInfo
, ConfigRequest
, &AccessResults
, &AccessProgress
);
3860 FreePool (EfiVarStoreInfo
);
3863 // Call corresponding ConfigAccess protocol to extract settings
3865 Status
= gBS
->HandleProtocol (
3867 &gEfiHiiConfigAccessProtocolGuid
,
3868 (VOID
**) &ConfigAccess
3870 ASSERT_EFI_ERROR (Status
);
3872 Status
= ConfigAccess
->ExtractConfig (
3879 if (EFI_ERROR (Status
)) {
3881 // AccessProgress indicates the parsing progress on <ConfigRequest>.
3882 // Map it to the progress on <MultiConfigRequest> then return it.
3884 *Progress
= StrStr (StringPtr
, AccessProgress
);
3889 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
3890 // which seperates the first <ConfigAltResp> and the following ones.
3892 ASSERT (*AccessProgress
== 0);
3895 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
3897 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
) {
3898 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
3899 ASSERT_EFI_ERROR (Status
);
3902 FreePool (DevicePath
);
3905 if (DefaultResults
!= NULL
) {
3906 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
3907 ASSERT_EFI_ERROR (Status
);
3908 FreePool (DefaultResults
);
3909 DefaultResults
= NULL
;
3913 if (!FirstElement
) {
3914 Status
= AppendToMultiString (Results
, L
"&");
3915 ASSERT_EFI_ERROR (Status
);
3918 Status
= AppendToMultiString (Results
, AccessResults
);
3919 ASSERT_EFI_ERROR (Status
);
3921 FirstElement
= FALSE
;
3923 FreePool (AccessResults
);
3924 AccessResults
= NULL
;
3925 FreePool (ConfigRequest
);
3926 ConfigRequest
= NULL
;
3929 // Go to next <ConfigRequest> (skip '&').
3931 StringPtr
+= Length
;
3932 if (*StringPtr
== 0) {
3933 *Progress
= StringPtr
;
3941 if (EFI_ERROR (Status
)) {
3942 FreePool (*Results
);
3946 if (ConfigRequest
!= NULL
) {
3947 FreePool (ConfigRequest
);
3950 if (AccessResults
!= NULL
) {
3951 FreePool (AccessResults
);
3954 if (DefaultResults
!= NULL
) {
3955 FreePool (DefaultResults
);
3958 if (DevicePath
!= NULL
) {
3959 FreePool (DevicePath
);
3967 This function allows the caller to request the current configuration for the
3968 entirety of the current HII database and returns the data in a
3969 null-terminated Unicode string.
3971 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3973 @param Results Null-terminated Unicode string in
3974 <MultiConfigAltResp> format which has all values
3975 filled in for the entirety of the current HII
3976 database. String to be allocated by the called
3977 function. De-allocation is up to the caller.
3979 @retval EFI_SUCCESS The Results string is filled with the values
3980 corresponding to all requested names.
3981 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
3982 results that must be stored awaiting possible
3984 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
3985 parameter would result in this type of error.
3990 HiiConfigRoutingExportConfig (
3991 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3992 OUT EFI_STRING
*Results
3996 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
3997 EFI_STRING AccessResults
;
3998 EFI_STRING Progress
;
3999 EFI_STRING StringPtr
;
4000 EFI_STRING ConfigRequest
;
4002 EFI_HANDLE
*ConfigAccessHandles
;
4003 UINTN NumberConfigAccessHandles
;
4004 BOOLEAN FirstElement
;
4005 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
4006 EFI_HII_HANDLE HiiHandle
;
4007 EFI_STRING DefaultResults
;
4008 HII_DATABASE_PRIVATE_DATA
*Private
;
4010 HII_DATABASE_RECORD
*Database
;
4011 UINT8
*DevicePathPkg
;
4012 UINT8
*CurrentDevicePath
;
4013 BOOLEAN IfrDataParsedFlag
;
4015 if (This
== NULL
|| Results
== NULL
) {
4016 return EFI_INVALID_PARAMETER
;
4019 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4022 // Allocate a fix length of memory to store Results. Reallocate memory for
4023 // Results if this fix length is insufficient.
4025 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
4026 if (*Results
== NULL
) {
4027 return EFI_OUT_OF_RESOURCES
;
4030 NumberConfigAccessHandles
= 0;
4031 Status
= gBS
->LocateHandleBuffer (
4033 &gEfiHiiConfigAccessProtocolGuid
,
4035 &NumberConfigAccessHandles
,
4036 &ConfigAccessHandles
4038 if (EFI_ERROR (Status
)) {
4042 FirstElement
= TRUE
;
4044 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
4045 Status
= gBS
->HandleProtocol (
4046 ConfigAccessHandles
[Index
],
4047 &gEfiHiiConfigAccessProtocolGuid
,
4048 (VOID
**) &ConfigAccess
4050 if (EFI_ERROR (Status
)) {
4055 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
4057 IfrDataParsedFlag
= FALSE
;
4060 DefaultResults
= NULL
;
4062 ConfigRequest
= NULL
;
4063 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
4064 if (DevicePath
!= NULL
) {
4065 for (Link
= Private
->DatabaseList
.ForwardLink
;
4066 Link
!= &Private
->DatabaseList
;
4067 Link
= Link
->ForwardLink
4069 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
4070 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
4071 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
4075 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
4077 HiiHandle
= Database
->Handle
;
4084 Status
= ConfigAccess
->ExtractConfig (
4090 if (EFI_ERROR (Status
)) {
4092 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
4094 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
4095 IfrDataParsedFlag
= TRUE
;
4096 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
4098 // Get the full request string to get the Current setting again.
4100 if (!EFI_ERROR (Status
) && ConfigRequest
!= NULL
) {
4101 Status
= ConfigAccess
->ExtractConfig (
4107 FreePool (ConfigRequest
);
4109 Status
= EFI_NOT_FOUND
;
4114 if (!EFI_ERROR (Status
)) {
4116 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
4118 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
4119 StringPtr
= StrStr (AccessResults
, L
"&GUID=");
4120 if (StringPtr
!= NULL
) {
4123 if (GetElementsFromRequest (AccessResults
)) {
4124 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &AccessResults
, &DefaultResults
, NULL
);
4125 ASSERT_EFI_ERROR (Status
);
4127 if (StringPtr
!= NULL
) {
4132 // Merge the default sting from IFR code into the got setting from driver.
4134 if (DefaultResults
!= NULL
) {
4135 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
4136 ASSERT_EFI_ERROR (Status
);
4137 FreePool (DefaultResults
);
4138 DefaultResults
= NULL
;
4142 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
4143 // which seperates the first <ConfigAltResp> and the following ones.
4145 if (!FirstElement
) {
4146 Status
= AppendToMultiString (Results
, L
"&");
4147 ASSERT_EFI_ERROR (Status
);
4150 Status
= AppendToMultiString (Results
, AccessResults
);
4151 ASSERT_EFI_ERROR (Status
);
4153 FirstElement
= FALSE
;
4155 FreePool (AccessResults
);
4156 AccessResults
= NULL
;
4159 FreePool (ConfigAccessHandles
);
4166 This function processes the results of processing forms and routes it to the
4167 appropriate handlers or storage.
4169 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4171 @param Configuration A null-terminated Unicode string in
4172 <MulltiConfigResp> format.
4173 @param Progress A pointer to a string filled in with the offset of
4174 the most recent & before the first failing name /
4175 value pair (or the beginning of the string if the
4176 failure is in the first name / value pair) or the
4177 terminating NULL if all was successful.
4179 @retval EFI_SUCCESS The results have been distributed or are awaiting
4181 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
4182 results that must be stored awaiting possible
4184 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
4185 would result in this type of error.
4186 @retval EFI_NOT_FOUND Target for the specified routing data was not
4192 HiiConfigRoutingRouteConfig (
4193 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4194 IN CONST EFI_STRING Configuration
,
4195 OUT EFI_STRING
*Progress
4198 HII_DATABASE_PRIVATE_DATA
*Private
;
4199 EFI_STRING StringPtr
;
4200 EFI_STRING ConfigResp
;
4203 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
4204 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
4206 HII_DATABASE_RECORD
*Database
;
4207 UINT8
*DevicePathPkg
;
4208 UINT8
*CurrentDevicePath
;
4209 EFI_HANDLE DriverHandle
;
4210 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
4211 EFI_STRING AccessProgress
;
4212 EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
;
4213 BOOLEAN IsEfiVarstore
;
4214 UINTN DevicePathSize
;
4216 if (This
== NULL
|| Progress
== NULL
) {
4217 return EFI_INVALID_PARAMETER
;
4220 if (Configuration
== NULL
) {
4222 return EFI_INVALID_PARAMETER
;
4225 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4226 StringPtr
= Configuration
;
4227 *Progress
= StringPtr
;
4229 AccessProgress
= NULL
;
4230 EfiVarStoreInfo
= NULL
;
4231 IsEfiVarstore
= FALSE
;
4234 // The first element of <MultiConfigResp> should be
4235 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
4237 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4238 return EFI_INVALID_PARAMETER
;
4241 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
4243 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
4244 // or most recent & before the error.
4246 if (StringPtr
== Configuration
) {
4247 *Progress
= StringPtr
;
4249 *Progress
= StringPtr
- 1;
4253 // Process each <ConfigResp> of <MultiConfigResp>
4255 Length
= CalculateConfigStringLen (StringPtr
);
4256 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
4257 if (ConfigResp
== NULL
) {
4258 return EFI_OUT_OF_RESOURCES
;
4261 // Append '\0' to the end of ConfigRequest
4263 *(ConfigResp
+ Length
) = 0;
4266 // Get the UEFI device path
4268 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
4269 if (EFI_ERROR (Status
)) {
4270 FreePool (ConfigResp
);
4275 // Find driver which matches the routing data.
4277 DriverHandle
= NULL
;
4278 for (Link
= Private
->DatabaseList
.ForwardLink
;
4279 Link
!= &Private
->DatabaseList
;
4280 Link
= Link
->ForwardLink
4282 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
4284 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
4285 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
4286 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
4287 if ((CompareMem (DevicePath
,CurrentDevicePath
,DevicePathSize
) == 0) && IsThisPackageList(Database
, ConfigResp
)) {
4288 DriverHandle
= Database
->DriverHandle
;
4295 // Try to find driver handle by device path.
4297 if (DriverHandle
== NULL
) {
4298 TempDevicePath
= DevicePath
;
4299 Status
= gBS
->LocateDevicePath (
4300 &gEfiDevicePathProtocolGuid
,
4304 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
4306 // Routing data does not match any known driver.
4307 // Set Progress to the 'G' in "GUID" of the routing header.
4309 FreePool (DevicePath
);
4310 *Progress
= StringPtr
;
4311 FreePool (ConfigResp
);
4312 return EFI_NOT_FOUND
;
4316 FreePool (DevicePath
);
4319 // Check whether this ConfigRequest is search from Efi varstore type storage.
4321 Status
= GetVarStoreType(Database
, ConfigResp
, &IsEfiVarstore
, &EfiVarStoreInfo
);
4322 if (EFI_ERROR (Status
)) {
4326 if (IsEfiVarstore
) {
4328 // Call the SetVariable function to route settings.
4330 Status
= RouteConfigRespForEfiVarStore(This
, EfiVarStoreInfo
, ConfigResp
, &AccessProgress
);
4331 FreePool (EfiVarStoreInfo
);
4334 // Call corresponding ConfigAccess protocol to route settings
4336 Status
= gBS
->HandleProtocol (
4338 &gEfiHiiConfigAccessProtocolGuid
,
4339 (VOID
**) &ConfigAccess
4341 ASSERT_EFI_ERROR (Status
);
4343 Status
= ConfigAccess
->RouteConfig (
4349 if (EFI_ERROR (Status
)) {
4350 ASSERT (AccessProgress
!= NULL
);
4352 // AccessProgress indicates the parsing progress on <ConfigResp>.
4353 // Map it to the progress on <MultiConfigResp> then return it.
4355 *Progress
= StrStr (StringPtr
, AccessProgress
);
4357 FreePool (ConfigResp
);
4361 FreePool (ConfigResp
);
4365 // Go to next <ConfigResp> (skip '&').
4367 StringPtr
+= Length
;
4368 if (*StringPtr
== 0) {
4369 *Progress
= StringPtr
;
4382 This helper function is to be called by drivers to map configuration data
4383 stored in byte array ("block") formats such as UEFI Variables into current
4384 configuration strings.
4386 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4388 @param ConfigRequest A null-terminated Unicode string in
4389 <ConfigRequest> format.
4390 @param Block Array of bytes defining the block's configuration.
4391 @param BlockSize Length in bytes of Block.
4392 @param Config Filled-in configuration string. String allocated
4393 by the function. Returned only if call is
4394 successful. It is <ConfigResp> string format.
4395 @param Progress A pointer to a string filled in with the offset of
4396 the most recent & before the first failing
4397 name/value pair (or the beginning of the string if
4398 the failure is in the first name / value pair) or
4399 the terminating NULL if all was successful.
4401 @retval EFI_SUCCESS The request succeeded. Progress points to the null
4402 terminator at the end of the ConfigRequest
4404 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
4405 points to the first character of ConfigRequest.
4406 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
4407 Block parameter would result in this type of
4408 error. Progress points to the first character of
4410 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
4411 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
4412 Block is left updated and Progress points at
4413 the "&" preceding the first non-<BlockName>.
4419 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4420 IN CONST EFI_STRING ConfigRequest
,
4421 IN CONST UINT8
*Block
,
4422 IN CONST UINTN BlockSize
,
4423 OUT EFI_STRING
*Config
,
4424 OUT EFI_STRING
*Progress
4427 HII_DATABASE_PRIVATE_DATA
*Private
;
4428 EFI_STRING StringPtr
;
4436 EFI_STRING ValueStr
;
4437 EFI_STRING ConfigElement
;
4445 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
4446 return EFI_INVALID_PARAMETER
;
4449 if (Block
== NULL
|| ConfigRequest
== NULL
) {
4450 *Progress
= ConfigRequest
;
4451 return EFI_INVALID_PARAMETER
;
4455 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4456 ASSERT (Private
!= NULL
);
4458 StringPtr
= ConfigRequest
;
4461 ConfigElement
= NULL
;
4464 // Allocate a fix length of memory to store Results. Reallocate memory for
4465 // Results if this fix length is insufficient.
4467 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
4468 if (*Config
== NULL
) {
4469 return EFI_OUT_OF_RESOURCES
;
4475 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4476 *Progress
= StringPtr
;
4477 Status
= EFI_INVALID_PARAMETER
;
4480 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
4483 if (*StringPtr
== 0) {
4484 *Progress
= StringPtr
- 1;
4485 Status
= EFI_INVALID_PARAMETER
;
4489 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
4492 if (*StringPtr
== 0) {
4493 *Progress
= StringPtr
;
4495 AppendToMultiString(Config
, ConfigRequest
);
4496 HiiToLower (*Config
);
4506 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
4508 TemChar
= *StringPtr
;
4510 AppendToMultiString(Config
, ConfigRequest
);
4511 *StringPtr
= TemChar
;
4514 // Parse each <RequestElement> if exists
4515 // Only <BlockName> format is supported by this help function.
4516 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
4518 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
4520 // Back up the header of one <BlockName>
4524 StringPtr
+= StrLen (L
"OFFSET=");
4528 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
4529 if (EFI_ERROR (Status
)) {
4530 *Progress
= TmpPtr
- 1;
4537 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
4539 FreePool (TmpBuffer
);
4541 StringPtr
+= Length
;
4542 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
4543 *Progress
= TmpPtr
- 1;
4544 Status
= EFI_INVALID_PARAMETER
;
4547 StringPtr
+= StrLen (L
"&WIDTH=");
4552 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
4553 if (EFI_ERROR (Status
)) {
4554 *Progress
= TmpPtr
- 1;
4561 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
4563 FreePool (TmpBuffer
);
4565 StringPtr
+= Length
;
4566 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
4567 *Progress
= TmpPtr
- 1;
4568 Status
= EFI_INVALID_PARAMETER
;
4573 // Calculate Value and convert it to hex string.
4575 if (Offset
+ Width
> BlockSize
) {
4576 *Progress
= StringPtr
;
4577 Status
= EFI_DEVICE_ERROR
;
4581 Value
= (UINT8
*) AllocateZeroPool (Width
);
4582 if (Value
== NULL
) {
4583 *Progress
= ConfigRequest
;
4584 Status
= EFI_OUT_OF_RESOURCES
;
4588 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
4590 Length
= Width
* 2 + 1;
4591 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
4592 if (ValueStr
== NULL
) {
4593 *Progress
= ConfigRequest
;
4594 Status
= EFI_OUT_OF_RESOURCES
;
4598 TemString
= ValueStr
;
4599 TemBuffer
= Value
+ Width
- 1;
4600 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
4601 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
4608 // Build a ConfigElement
4610 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
4611 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
4612 if (ConfigElement
== NULL
) {
4613 Status
= EFI_OUT_OF_RESOURCES
;
4616 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
4617 if (*StringPtr
== 0) {
4618 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
4620 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
4621 StrCatS (ConfigElement
, Length
, L
"VALUE=");
4622 StrCatS (ConfigElement
, Length
, ValueStr
);
4624 AppendToMultiString (Config
, ConfigElement
);
4626 FreePool (ConfigElement
);
4627 FreePool (ValueStr
);
4628 ConfigElement
= NULL
;
4632 // If '\0', parsing is finished. Otherwise skip '&' to continue
4634 if (*StringPtr
== 0) {
4637 AppendToMultiString (Config
, L
"&");
4642 if (*StringPtr
!= 0) {
4643 *Progress
= StringPtr
- 1;
4644 Status
= EFI_INVALID_PARAMETER
;
4648 HiiToLower (*Config
);
4649 *Progress
= StringPtr
;
4653 if (*Config
!= NULL
) {
4657 if (ValueStr
!= NULL
) {
4658 FreePool (ValueStr
);
4660 if (Value
!= NULL
) {
4663 if (ConfigElement
!= NULL
) {
4664 FreePool (ConfigElement
);
4673 This helper function is to be called by drivers to map configuration strings
4674 to configurations stored in byte array ("block") formats such as UEFI Variables.
4676 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4678 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
4680 @param Block A possibly null array of bytes representing the
4681 current block. Only bytes referenced in the
4682 ConfigResp string in the block are modified. If
4683 this parameter is null or if the *BlockSize
4684 parameter is (on input) shorter than required by
4685 the Configuration string, only the BlockSize
4686 parameter is updated and an appropriate status
4687 (see below) is returned.
4688 @param BlockSize The length of the Block in units of UINT8. On
4689 input, this is the size of the Block. On output,
4690 if successful, contains the largest index of the
4691 modified byte in the Block, or the required buffer
4692 size if the Block is not large enough.
4693 @param Progress On return, points to an element of the ConfigResp
4694 string filled in with the offset of the most
4695 recent '&' before the first failing name / value
4696 pair (or the beginning of the string if the
4697 failure is in the first name / value pair) or the
4698 terminating NULL if all was successful.
4700 @retval EFI_SUCCESS The request succeeded. Progress points to the null
4701 terminator at the end of the ConfigResp string.
4702 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
4703 points to the first character of ConfigResp.
4704 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
4705 Block parameter would result in this type of
4706 error. Progress points to the first character of
4708 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
4709 value pair. Block is left updated and
4710 Progress points at the '&' preceding the first
4712 @retval EFI_BUFFER_TOO_SMALL Block not large enough. Progress undefined.
4713 BlockSize is updated with the required buffer size.
4714 @retval EFI_NOT_FOUND Target for the specified routing data was not found.
4715 Progress points to the "G" in "GUID" of the errant
4722 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4723 IN CONST EFI_STRING ConfigResp
,
4724 IN OUT UINT8
*Block
,
4725 IN OUT UINTN
*BlockSize
,
4726 OUT EFI_STRING
*Progress
4729 HII_DATABASE_PRIVATE_DATA
*Private
;
4730 EFI_STRING StringPtr
;
4743 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
4744 return EFI_INVALID_PARAMETER
;
4747 *Progress
= ConfigResp
;
4748 if (ConfigResp
== NULL
) {
4749 return EFI_INVALID_PARAMETER
;
4752 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4753 ASSERT (Private
!= NULL
);
4755 StringPtr
= ConfigResp
;
4756 BufferSize
= *BlockSize
;
4763 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4764 *Progress
= StringPtr
;
4765 Status
= EFI_INVALID_PARAMETER
;
4768 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
4771 if (*StringPtr
== 0) {
4772 *Progress
= StringPtr
;
4773 Status
= EFI_INVALID_PARAMETER
;
4777 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
4780 if (*StringPtr
== 0) {
4781 *Progress
= StringPtr
;
4782 Status
= EFI_INVALID_PARAMETER
;
4787 // Parse each <ConfigElement> if exists
4788 // Only '&'<BlockConfig> format is supported by this help function.
4789 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
4791 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
4793 StringPtr
+= StrLen (L
"&OFFSET=");
4797 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
4798 if (EFI_ERROR (Status
)) {
4806 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
4808 FreePool (TmpBuffer
);
4810 StringPtr
+= Length
;
4811 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
4813 Status
= EFI_INVALID_PARAMETER
;
4816 StringPtr
+= StrLen (L
"&WIDTH=");
4821 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
4822 if (EFI_ERROR (Status
)) {
4830 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
4832 FreePool (TmpBuffer
);
4834 StringPtr
+= Length
;
4835 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
4837 Status
= EFI_INVALID_PARAMETER
;
4840 StringPtr
+= StrLen (L
"&VALUE=");
4845 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
4846 if (EFI_ERROR (Status
)) {
4851 StringPtr
+= Length
;
4852 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
4854 Status
= EFI_INVALID_PARAMETER
;
4859 // Update the Block with configuration info
4861 if ((Block
!= NULL
) && (Offset
+ Width
<= BufferSize
)) {
4862 CopyMem (Block
+ Offset
, Value
, Width
);
4864 if (Offset
+ Width
> MaxBlockSize
) {
4865 MaxBlockSize
= Offset
+ Width
;
4872 // If '\0', parsing is finished.
4874 if (*StringPtr
== 0) {
4880 // The input string is not ConfigResp format, return error.
4882 if (*StringPtr
!= 0) {
4883 *Progress
= StringPtr
;
4884 Status
= EFI_INVALID_PARAMETER
;
4888 *Progress
= StringPtr
+ StrLen (StringPtr
);
4889 *BlockSize
= MaxBlockSize
- 1;
4891 if (MaxBlockSize
> BufferSize
) {
4892 *BlockSize
= MaxBlockSize
;
4893 if (Block
!= NULL
) {
4894 return EFI_BUFFER_TOO_SMALL
;
4898 if (Block
== NULL
) {
4899 *Progress
= ConfigResp
;
4900 return EFI_INVALID_PARAMETER
;
4907 if (Value
!= NULL
) {
4915 This helper function is to be called by drivers to extract portions of
4916 a larger configuration string.
4918 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4920 @param Configuration A null-terminated Unicode string in
4921 <MultiConfigAltResp> format.
4922 @param Guid A pointer to the GUID value to search for in the
4923 routing portion of the ConfigResp string when
4924 retrieving the requested data. If Guid is NULL,
4925 then all GUID values will be searched for.
4926 @param Name A pointer to the NAME value to search for in the
4927 routing portion of the ConfigResp string when
4928 retrieving the requested data. If Name is NULL,
4929 then all Name values will be searched for.
4930 @param DevicePath A pointer to the PATH value to search for in the
4931 routing portion of the ConfigResp string when
4932 retrieving the requested data. If DevicePath is
4933 NULL, then all DevicePath values will be searched
4935 @param AltCfgId A pointer to the ALTCFG value to search for in the
4936 routing portion of the ConfigResp string when
4937 retrieving the requested data. If this parameter
4938 is NULL, then the current setting will be
4940 @param AltCfgResp A pointer to a buffer which will be allocated by
4941 the function which contains the retrieved string
4942 as requested. This buffer is only allocated if
4943 the call was successful. It is <ConfigResp> format.
4945 @retval EFI_SUCCESS The request succeeded. The requested data was
4946 extracted and placed in the newly allocated
4948 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
4949 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
4950 @retval EFI_NOT_FOUND Target for the specified routing data was not
4957 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4958 IN CONST EFI_STRING Configuration
,
4959 IN CONST EFI_GUID
*Guid
,
4960 IN CONST EFI_STRING Name
,
4961 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
4962 IN CONST UINT16
*AltCfgId
,
4963 OUT EFI_STRING
*AltCfgResp
4967 EFI_STRING StringPtr
;
4968 EFI_STRING HdrStart
;
4975 EFI_STRING AltIdStr
;
4992 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
4993 return EFI_INVALID_PARAMETER
;
4996 StringPtr
= Configuration
;
4997 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4998 return EFI_INVALID_PARAMETER
;
5002 // Generate the sub string for later matching.
5004 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
5007 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
5008 (VOID
*) DevicePath
,
5012 if (AltCfgId
!= NULL
) {
5013 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
5016 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
5018 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
5021 while (*StringPtr
!= 0) {
5023 // Try to match the GUID
5026 TmpPtr
= StrStr (StringPtr
, GuidStr
);
5027 if (TmpPtr
== NULL
) {
5028 Status
= EFI_NOT_FOUND
;
5034 // Jump to <NameHdr>
5037 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
5039 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
5040 if (StringPtr
== NULL
) {
5041 Status
= EFI_NOT_FOUND
;
5049 // Try to match the NAME
5051 if (GuidFlag
&& !NameFlag
) {
5052 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
5056 // Jump to <PathHdr>
5059 StringPtr
+= StrLen (NameStr
);
5061 StringPtr
= StrStr (StringPtr
, L
"PATH=");
5062 if (StringPtr
== NULL
) {
5063 Status
= EFI_NOT_FOUND
;
5072 // Try to match the DevicePath
5074 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
5075 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
5080 // Jump to '&' before <DescHdr> or <ConfigBody>
5082 if (DevicePath
!= NULL
) {
5083 StringPtr
+= StrLen (PathStr
);
5085 StringPtr
= StrStr (StringPtr
, L
"&");
5086 if (StringPtr
== NULL
) {
5087 Status
= EFI_NOT_FOUND
;
5098 // Try to match the AltCfgId
5100 if (GuidFlag
&& NameFlag
&& PathFlag
) {
5101 if (AltCfgId
== NULL
) {
5103 // Return Current Setting when AltCfgId is NULL.
5105 Status
= OutputConfigBody (StringPtr
, &Result
);
5109 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
5111 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
5117 // Skip AltIdStr and &
5119 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
5120 Status
= OutputConfigBody (StringPtr
, &Result
);
5126 Status
= EFI_NOT_FOUND
;
5130 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
5132 // Copy the <ConfigHdr> and <ConfigBody>
5134 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
5135 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
5136 if (*AltCfgResp
== NULL
) {
5137 Status
= EFI_OUT_OF_RESOURCES
;
5139 StrnCpyS (*AltCfgResp
, Length
, HdrStart
, HdrEnd
- HdrStart
);
5140 StrCatS (*AltCfgResp
, Length
, Result
);
5141 Status
= EFI_SUCCESS
;
5145 if (GuidStr
!= NULL
) {
5148 if (NameStr
!= NULL
) {
5151 if (PathStr
!= NULL
) {
5154 if (AltIdStr
!= NULL
) {
5155 FreePool (AltIdStr
);
5157 if (Result
!= NULL
) {