2 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.
4 Copyright (c) 2007 - 2008, Intel Corporation
5 All rights reserved. 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 DevicePath binary of a UEFI device path.
66 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
67 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
68 @retval EFI_SUCCESS The device path is retrieved and translated to
75 OUT UINT8
**DevicePath
80 EFI_STRING DevicePathString
;
81 UINT8
*DevicePathBuffer
;
86 if (String
== NULL
|| DevicePath
== NULL
) {
87 return EFI_INVALID_PARAMETER
;
91 // Find the 'PATH=' of <PathHdr> and skip it.
93 for (; (*String
!= 0 && StrnCmp (String
, L
"PATH=", StrLen (L
"PATH=")) != 0); String
++);
95 return EFI_INVALID_PARAMETER
;
98 String
+= StrLen (L
"PATH=");
102 // The content between 'PATH=' of <ConfigHdr> and '&' of next element
103 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding
104 // of UEFI device path.
106 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
107 DevicePathString
= (EFI_STRING
) AllocateZeroPool ((Length
+ 1) * sizeof (CHAR16
));
108 if (DevicePathString
== NULL
) {
109 return EFI_OUT_OF_RESOURCES
;
111 StrnCpy (DevicePathString
, PathHdr
, Length
);
112 *(DevicePathString
+ Length
) = 0;
115 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
116 // as the device path resides in RAM memory.
117 // Translate the data into binary.
119 DevicePathBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
120 if (DevicePathBuffer
== NULL
) {
121 FreePool (DevicePathString
);
122 return EFI_OUT_OF_RESOURCES
;
125 ZeroMem (TemStr
, sizeof (TemStr
));
126 for (Index
= 0; DevicePathString
[Index
] != L
'\0'; Index
++) {
127 TemStr
[0] = DevicePathString
[Index
];
128 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
129 if ((Index
& 1) == 0) {
130 DevicePathBuffer
[Index
/2] = DigitUint8
;
132 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
136 FreePool (DevicePathString
);
138 *DevicePath
= DevicePathBuffer
;
145 Converts the unicode character of the string from uppercase to lowercase.
146 This is a internal function.
148 @param Str String to be converted
154 IN EFI_STRING ConfigString
160 ASSERT (ConfigString
!= NULL
);
163 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
165 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
166 if (*String
== L
'=') {
168 } else if (*String
== L
'&') {
170 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
171 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
179 Generate a sub string then output it.
181 This is a internal function.
183 @param String A constant string which is the prefix of the to be
184 generated string, e.g. GUID=
186 @param BufferLen The length of the Buffer in bytes.
188 @param Buffer Points to a buffer which will be converted to be the
189 content of the generated string.
191 @param Flag If 1, the buffer contains data for the value of GUID or PATH stored in
192 UINT8 *; if 2, the buffer contains unicode string for the value of NAME;
193 if 3, the buffer contains other data.
195 @param SubStr Points to the output string. It's caller's
196 responsibility to free this buffer.
202 IN CONST EFI_STRING String
,
206 OUT EFI_STRING
*SubStr
211 EFI_STRING StringHeader
;
217 ASSERT (String
!= NULL
&& SubStr
!= NULL
);
219 if (Buffer
== NULL
) {
220 *SubStr
= AllocateCopyPool (StrSize (String
), String
);
221 ASSERT (*SubStr
!= NULL
);
226 // Header + Data + '&' + '\0'
228 Length
= StrLen (String
) + BufferLen
* 2 + 1 + 1;
229 Str
= AllocateZeroPool (Length
* sizeof (CHAR16
));
230 ASSERT (Str
!= NULL
);
232 StrCpy (Str
, String
);
233 Length
= (BufferLen
* 2 + 1) * sizeof (CHAR16
);
235 StringHeader
= Str
+ StrLen (String
);
236 TemString
= (CHAR16
*) StringHeader
;
241 // Convert Buffer to Hex String in reverse order
243 TemBuffer
= ((UINT8
*) Buffer
);
244 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
++) {
245 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
250 // Check buffer is enough
252 TemName
= (CHAR16
*) Buffer
;
253 ASSERT ((BufferLen
* 2 + 1) >= (StrLen (TemName
) * 4 + 1));
255 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
257 for (; *TemName
!= L
'\0'; TemName
++) {
258 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
263 // Convert Buffer to Hex String
265 TemBuffer
= ((UINT8
*) Buffer
) + BufferLen
- 1;
266 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
--) {
267 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
275 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
285 Retrieve the <ConfigBody> from String then output it.
287 This is a internal function.
289 @param String A sub string of a configuration string in
290 <MultiConfigAltResp> format.
291 @param ConfigBody Points to the output string. It's caller's
292 responsibility to free this buffer.
294 @retval EFI_INVALID_PARAMETER There is no form package in current hii database.
295 @retval EFI_OUT_OF_RESOURCES Not enough memory to finish this operation.
296 @retval EFI_SUCCESS All existing storage is exported.
301 IN EFI_STRING String
,
302 OUT EFI_STRING
*ConfigBody
309 if (String
== NULL
|| ConfigBody
== NULL
) {
310 return EFI_INVALID_PARAMETER
;
314 // The setting information should start OFFSET, not ALTCFG.
316 if (StrnCmp (String
, L
"&ALTCFG=", StrLen (L
"&ALTCFG=")) == 0) {
317 return EFI_INVALID_PARAMETER
;
320 TmpPtr
= StrStr (String
, L
"GUID=");
321 if (TmpPtr
== NULL
) {
323 // It is the last <ConfigResp> of the incoming configuration string.
325 Result
= AllocateCopyPool (StrSize (String
), String
);
326 if (Result
== NULL
) {
327 return EFI_OUT_OF_RESOURCES
;
329 *ConfigBody
= Result
;
334 Length
= TmpPtr
- String
;
335 Result
= AllocateCopyPool (Length
* sizeof (CHAR16
), String
);
336 if (Result
== NULL
) {
337 return EFI_OUT_OF_RESOURCES
;
340 *(Result
+ Length
- 1) = 0;
341 *ConfigBody
= Result
;
346 Append a string to a multi-string format.
348 This is a internal function.
350 @param MultiString String in <MultiConfigRequest>,
351 <MultiConfigAltResp>, or <MultiConfigResp>. On
352 input, the buffer length of this string is
353 MAX_STRING_LENGTH. On output, the buffer length
355 @param AppendString NULL-terminated Unicode string.
357 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
358 @retval EFI_SUCCESS AppendString is append to the end of MultiString
362 AppendToMultiString (
363 IN OUT EFI_STRING
*MultiString
,
364 IN EFI_STRING AppendString
367 UINTN AppendStringSize
;
368 UINTN MultiStringSize
;
370 if (MultiString
== NULL
|| *MultiString
== NULL
|| AppendString
== NULL
) {
371 return EFI_INVALID_PARAMETER
;
374 AppendStringSize
= StrSize (AppendString
);
375 MultiStringSize
= StrSize (*MultiString
);
378 // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.
380 if (MultiStringSize
+ AppendStringSize
> MAX_STRING_LENGTH
||
381 MultiStringSize
> MAX_STRING_LENGTH
) {
382 *MultiString
= (EFI_STRING
) ReallocatePool (
384 MultiStringSize
+ AppendStringSize
,
385 (VOID
*) (*MultiString
)
387 ASSERT (*MultiString
!= NULL
);
390 // Append the incoming string
392 StrCat (*MultiString
, AppendString
);
399 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
401 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
403 This is a internal function.
405 @param StringPtr String in <BlockConfig> format and points to the
406 first character of <Number>.
407 @param Number The output value. Caller takes the responsibility
409 @param Len Length of the <Number>, in characters.
411 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
413 @retval EFI_SUCCESS Value of <Number> is outputted in Number
419 IN EFI_STRING StringPtr
,
433 ASSERT (StringPtr
!= NULL
&& Number
!= NULL
&& Len
!= NULL
);
434 ASSERT (*StringPtr
!= L
'\0');
439 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
442 *Len
= StringPtr
- TmpPtr
;
445 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
447 Status
= EFI_OUT_OF_RESOURCES
;
450 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
451 *(Str
+ *Len
) = L
'\0';
453 Length
= (Length
+ 1) / 2;
454 Buf
= (UINT8
*) AllocateZeroPool (Length
);
456 Status
= EFI_OUT_OF_RESOURCES
;
461 ZeroMem (TemStr
, sizeof (TemStr
));
462 for (Index
= 0; Index
< Length
; Index
++) {
463 TemStr
[0] = Str
[Length
- Index
- 1];
464 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
465 if ((Index
& 1) == 0) {
466 Buf
[Index
/2] = DigitUint8
;
468 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
473 Status
= EFI_SUCCESS
;
484 This function merges DefaultAltCfgResp string into AltCfgResp string for
485 the missing AltCfgId in AltCfgResq.
487 @param AltCfgResp Pointer to a null-terminated Unicode string in
488 <ConfigAltResp> format. The default value string
489 will be merged into it.
490 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
491 <MultiConfigAltResp> format. The default value
492 string may contain more than one ConfigAltResp
493 string for the different varstore buffer.
495 @retval EFI_SUCCESS The merged string returns.
496 @retval EFI_INVALID_PARAMETER *AltCfgResp is to NULL.
501 IN OUT EFI_STRING
*AltCfgResp
,
502 IN EFI_STRING DefaultAltCfgResp
505 EFI_STRING StringPtrDefault
;
506 EFI_STRING StringPtrEnd
;
508 EFI_STRING StringPtr
;
509 EFI_STRING AltConfigHdr
;
511 UINTN SizeAltCfgResp
;
513 if (*AltCfgResp
== NULL
) {
514 return EFI_INVALID_PARAMETER
;
518 // Get the requestr ConfigHdr
521 StringPtr
= *AltCfgResp
;
524 // Find <ConfigHdr> GUID=...&NAME=...&PATH=...
526 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
527 return EFI_INVALID_PARAMETER
;
529 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
532 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
535 if (*StringPtr
== L
'\0') {
536 return EFI_INVALID_PARAMETER
;
538 StringPtr
+= StrLen (L
"&PATH=");
539 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
542 HeaderLength
= StringPtr
- *AltCfgResp
;
545 // Construct AltConfigHdr string "&<ConfigHdr>&ALTCFG=XXXX\0"
546 // |1| StrLen (ConfigHdr) | 8 | 4 | 1 |
548 AltConfigHdr
= AllocateZeroPool ((1 + HeaderLength
+ 8 + 4 + 1) * sizeof (CHAR16
));
549 if (AltConfigHdr
== NULL
) {
550 return EFI_OUT_OF_RESOURCES
;
552 StrCpy (AltConfigHdr
, L
"&");
553 StrnCat (AltConfigHdr
, *AltCfgResp
, HeaderLength
);
554 StrCat (AltConfigHdr
, L
"&ALTCFG=");
555 HeaderLength
= StrLen (AltConfigHdr
);
557 StringPtrDefault
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
558 while (StringPtrDefault
!= NULL
) {
562 StrnCat (AltConfigHdr
, StringPtrDefault
+ HeaderLength
, 4);
563 StringPtr
= StrStr (*AltCfgResp
, AltConfigHdr
);
566 // Append the found default value string to the input AltCfgResp
568 if (StringPtr
== NULL
) {
569 StringPtrEnd
= StrStr (StringPtrDefault
+ 1, L
"&GUID");
570 SizeAltCfgResp
= StrSize (*AltCfgResp
);
571 if (StringPtrEnd
== NULL
) {
573 // No more default string is found.
575 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
577 SizeAltCfgResp
+ StrSize (StringPtrDefault
),
578 (VOID
*) (*AltCfgResp
)
580 StrCat (*AltCfgResp
, StringPtrDefault
);
583 TempChar
= *StringPtrEnd
;
584 *StringPtrEnd
= L
'\0';
585 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
587 SizeAltCfgResp
+ StrSize (StringPtrDefault
),
588 (VOID
*) (*AltCfgResp
)
590 StrCat (*AltCfgResp
, StringPtrDefault
);
591 *StringPtrEnd
= TempChar
;
596 // Find next AltCfg String
598 *(AltConfigHdr
+ HeaderLength
) = L
'\0';
599 StringPtrDefault
= StrStr (StringPtrDefault
+ 1, AltConfigHdr
);
606 This function finds the matched DefaultName for the input DefaultId
608 @param DefaultIdArray Array stores the map table between DefaultId and DefaultName.
609 @param VarDefaultId Default Id
610 @param VarDefaultName Default Name string ID for the input default ID.
612 @retval EFI_SUCCESS The mapped default name string ID is found.
613 @retval EFI_NOT_FOUND The mapped default name string ID is not found.
617 IN IFR_DEFAULT_DATA
*DefaultIdArray
,
618 IN UINT16 VarDefaultId
,
619 OUT EFI_STRING_ID
*VarDefaultName
623 IFR_DEFAULT_DATA
*DefaultData
;
625 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
626 DefaultData
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
627 if (DefaultData
->DefaultId
== VarDefaultId
) {
628 *VarDefaultName
= DefaultData
->DefaultName
;
633 return EFI_NOT_FOUND
;
637 This function inserts new DefaultValueData into the BlockData DefaultValue array.
639 @param BlockData The BlockData is updated to add new default value.
640 @param DefaultValueData The DefaultValue is added.
645 IN IFR_BLOCK_DATA
*BlockData
,
646 IN IFR_DEFAULT_DATA
*DefaultValueData
650 IFR_DEFAULT_DATA
*DefaultValueArray
;
652 for (Link
= BlockData
->DefaultValueEntry
.ForwardLink
; Link
!= &BlockData
->DefaultValueEntry
; Link
= Link
->ForwardLink
) {
653 DefaultValueArray
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
654 if (DefaultValueArray
->DefaultId
== DefaultValueData
->DefaultId
) {
656 // Update the default value array in BlockData.
658 DefaultValueArray
->Value
= DefaultValueData
->Value
;
659 FreePool (DefaultValueData
);
661 } else if (DefaultValueArray
->DefaultId
> DefaultValueData
->DefaultId
) {
663 // Insert new default value data in the front of this default value array.
665 InsertTailList (Link
, &DefaultValueData
->Entry
);
671 // Insert new default value data in tail.
673 InsertTailList (Link
, &DefaultValueData
->Entry
);
678 This function inserts new BlockData into the block link
680 @param BlockLink The list entry points to block array.
681 @param BlockData The point to BlockData is added.
686 IN LIST_ENTRY
*BlockLink
,
687 IN IFR_BLOCK_DATA
**BlockData
691 IFR_BLOCK_DATA
*BlockArray
;
692 IFR_BLOCK_DATA
*BlockSingleData
;
694 BlockSingleData
= *BlockData
;
697 // Insert block data in its Offset and Width order.
699 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
700 BlockArray
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
701 if (BlockArray
->Offset
== BlockSingleData
->Offset
) {
702 if (BlockArray
->Width
> BlockSingleData
->Width
) {
704 // Insert this block data in the front of block array
706 InsertTailList (Link
, &BlockSingleData
->Entry
);
710 if (BlockArray
->Width
== BlockSingleData
->Width
) {
712 // The same block array has been added.
714 FreePool (BlockSingleData
);
715 *BlockData
= BlockArray
;
718 } else if (BlockArray
->Offset
> BlockSingleData
->Offset
) {
720 // Insert new block data in the front of block array
722 InsertTailList (Link
, &BlockSingleData
->Entry
);
728 // Add new block data into the tail.
730 InsertTailList (Link
, &BlockSingleData
->Entry
);
735 This function checks VarOffset and VarWidth is in the block range.
737 @param BlockArray The block array is to be checked.
738 @param VarOffset Offset of var to the structure
739 @param VarWidth Width of var.
741 @retval TRUE This Var is in the block range.
742 @retval FALSE This Var is not in the block range.
746 IN IFR_BLOCK_DATA
*RequestBlockArray
,
752 IFR_BLOCK_DATA
*BlockData
;
755 // No Request Block array, all vars are got.
757 if (RequestBlockArray
== NULL
) {
762 // Check the input var is in the request block range.
764 for (Link
= RequestBlockArray
->Entry
.ForwardLink
; Link
!= &RequestBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
765 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
766 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
775 This function parses Form Package to get the block array and the default
776 value array according to the request ConfigHdr.
778 @param Package Pointer to the form package data.
779 @param PackageLength Length of the pacakge.
780 @param ConfigHdr Request string ConfigHdr. If it is NULL,
781 the first found varstore will be as ConfigHdr.
782 @param RequestBlockArray The block array is retrieved from the request string.
783 @param VarStorageData VarStorage structure contains the got block and default value.
784 @param PIfrDefaultIdArray Point to the got default id and default name array.
786 @retval EFI_SUCCESS The block array and the default value array are got.
787 @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges
789 @retval EFI_OUT_OF_RESOURCES No enough memory.
795 IN UINT32 PackageLenth
,
796 IN EFI_STRING ConfigHdr
,
797 IN IFR_BLOCK_DATA
*RequestBlockArray
,
798 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
799 OUT IFR_DEFAULT_DATA
**PIfrDefaultIdArray
804 EFI_IFR_VARSTORE
*IfrVarStore
;
805 EFI_IFR_OP_HEADER
*IfrOpHdr
;
806 EFI_IFR_ONE_OF
*IfrOneOf
;
807 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
808 EFI_IFR_DEFAULT
*IfrDefault
;
809 EFI_IFR_ORDERED_LIST
*IfrOrderedList
;
810 EFI_IFR_CHECKBOX
*IfrCheckBox
;
811 EFI_IFR_PASSWORD
*IfrPassword
;
812 EFI_IFR_STRING
*IfrString
;
813 IFR_DEFAULT_DATA
*DefaultIdArray
;
814 IFR_DEFAULT_DATA
*DefaultData
;
815 IFR_BLOCK_DATA
*BlockData
;
816 CHAR16
*VarStoreName
;
819 EFI_STRING_ID VarDefaultName
;
827 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
830 Status
= EFI_SUCCESS
;
836 DefaultIdArray
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
837 if (DefaultIdArray
== NULL
) {
838 return EFI_OUT_OF_RESOURCES
;
840 InitializeListHead (&DefaultIdArray
->Entry
);
843 // Go through the form package to parse OpCode one by one.
845 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
846 while (IfrOffset
< PackageLenth
) {
847 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (Package
+ IfrOffset
);
849 switch (IfrOpHdr
->OpCode
) {
850 case EFI_IFR_VARSTORE_OP
:
852 // VarStore is found. Don't need to search any more.
854 if (VarStorageData
->Size
!= 0) {
859 // Get the requied varstore information
860 // Add varstore by Guid and Name in ConfigHdr
861 // Make sure Offset is in varstore size and varstoreid
863 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
864 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
) * sizeof (CHAR16
));
865 if (VarStoreName
== NULL
) {
866 Status
= EFI_OUT_OF_RESOURCES
;
869 AsciiStrToUnicodeStr ((CHAR8
*) IfrVarStore
->Name
, VarStoreName
);
871 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &IfrVarStore
->Guid
, 1, &GuidStr
);
872 GenerateSubStr (L
"NAME=", StrLen (VarStoreName
) * sizeof (CHAR16
), (VOID
*) VarStoreName
, 2, &NameStr
);
873 LengthString
= StrLen (GuidStr
);
874 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
875 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
876 if (TempStr
== NULL
) {
879 Status
= EFI_OUT_OF_RESOURCES
;
882 StrCpy (TempStr
, GuidStr
);
883 StrCat (TempStr
, NameStr
);
884 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
886 // Find the matched VarStore
888 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
);
889 VarStorageData
->VarStoreId
= IfrVarStore
->VarStoreId
;
890 VarStorageData
->Size
= IfrVarStore
->Size
;
891 VarStorageData
->Name
= VarStoreName
;
894 // No found, free the allocated memory
896 FreePool (VarStoreName
);
899 // Free alllocated temp string.
906 case EFI_IFR_DEFAULTSTORE_OP
:
908 // Add new the map between default id and default name.
910 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
911 if (DefaultData
== NULL
) {
912 Status
= EFI_OUT_OF_RESOURCES
;
915 DefaultData
->DefaultId
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
;
916 DefaultData
->DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
917 InsertTailList (&DefaultIdArray
->Entry
, &DefaultData
->Entry
);
921 case EFI_IFR_FORM_OP
:
923 // No matched varstore is found and directly return.
925 if (VarStorageData
->Size
== 0) {
926 Status
= EFI_SUCCESS
;
931 case EFI_IFR_ONE_OF_OP
:
932 case EFI_IFR_NUMERIC_OP
:
934 // Numeric and OneOf has the same opcode structure.
938 // Check whether this question is for the requested varstore.
940 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
941 if (IfrOneOf
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
946 // Get Offset/Width by Question header and OneOf Flags
948 VarOffset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
949 VarWidth
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
951 // Check whether this question is in requested block array.
953 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
955 // This question is not in the requested string. Skip it.
961 // Check this var question is in the var storage
963 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
964 Status
= EFI_INVALID_PARAMETER
;
971 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
972 if (BlockData
== NULL
) {
973 Status
= EFI_OUT_OF_RESOURCES
;
976 BlockData
->Offset
= VarOffset
;
977 BlockData
->Width
= VarWidth
;
978 BlockData
->QuestionId
= IfrOneOf
->Question
.QuestionId
;
979 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
980 BlockData
->Scope
= IfrOpHdr
->Scope
;
981 InitializeListHead (&BlockData
->DefaultValueEntry
);
983 // Add Block Data into VarStorageData BlockEntry
985 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
988 case EFI_IFR_ORDERED_LIST_OP
:
990 // offset by question header
991 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type
992 // no default value and default id, how to define its default value?
996 // Check whether this question is for the requested varstore.
998 IfrOrderedList
= (EFI_IFR_ORDERED_LIST
*) IfrOpHdr
;
999 if (IfrOrderedList
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1004 // Get Offset/Width by Question header and OneOf Flags
1006 VarOffset
= IfrOrderedList
->Question
.VarStoreInfo
.VarOffset
;
1007 VarWidth
= IfrOrderedList
->MaxContainers
;
1010 // Check whether this question is in requested block array.
1012 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1014 // This question is not in the requested string. Skip it.
1020 // Check this var question is in the var storage
1022 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1023 Status
= EFI_INVALID_PARAMETER
;
1030 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1031 if (BlockData
== NULL
) {
1032 Status
= EFI_OUT_OF_RESOURCES
;
1035 BlockData
->Offset
= VarOffset
;
1036 BlockData
->Width
= VarWidth
;
1037 BlockData
->QuestionId
= IfrOrderedList
->Question
.QuestionId
;
1038 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1039 BlockData
->Scope
= IfrOpHdr
->Scope
;
1040 InitializeListHead (&BlockData
->DefaultValueEntry
);
1043 // Add Block Data into VarStorageData BlockEntry
1045 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1048 case EFI_IFR_CHECKBOX_OP
:
1050 // EFI_IFR_DEFAULT_OP
1051 // offset by question header
1052 // width is 1 sizeof (BOOLEAN)
1053 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.
1054 // value by DefaultOption
1055 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
1059 // Check whether this question is for the requested varstore.
1061 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1062 if (IfrCheckBox
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1067 // Get Offset/Width by Question header and OneOf Flags
1069 VarOffset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1070 VarWidth
= sizeof (BOOLEAN
);
1073 // Check whether this question is in requested block array.
1075 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1077 // This question is not in the requested string. Skip it.
1083 // Check this var question is in the var storage
1085 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1086 Status
= EFI_INVALID_PARAMETER
;
1093 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1094 if (BlockData
== NULL
) {
1095 Status
= EFI_OUT_OF_RESOURCES
;
1098 BlockData
->Offset
= VarOffset
;
1099 BlockData
->Width
= VarWidth
;
1100 BlockData
->QuestionId
= IfrCheckBox
->Question
.QuestionId
;
1101 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1102 BlockData
->Scope
= IfrOpHdr
->Scope
;
1103 InitializeListHead (&BlockData
->DefaultValueEntry
);
1105 // Add Block Data into VarStorageData BlockEntry
1107 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1110 // Add default value by CheckBox Flags
1112 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) == EFI_IFR_CHECKBOX_DEFAULT
) {
1114 // Set standard ID to Manufacture ID and Get DefaultName String ID
1116 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1117 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1118 if (EFI_ERROR (Status
)) {
1122 // Prepare new DefaultValue
1124 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1125 if (DefaultData
== NULL
) {
1126 Status
= EFI_OUT_OF_RESOURCES
;
1129 DefaultData
->DefaultId
= VarDefaultId
;
1130 DefaultData
->DefaultName
= VarDefaultName
;
1131 DefaultData
->Value
= 1;
1133 // Add DefaultValue into current BlockData
1135 InsertDefaultValue (BlockData
, DefaultData
);
1138 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) == EFI_IFR_CHECKBOX_DEFAULT_MFG
) {
1140 // Set standard ID to Manufacture ID and Get DefaultName String ID
1142 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1143 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1144 if (EFI_ERROR (Status
)) {
1148 // Prepare new DefaultValue
1150 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1151 if (DefaultData
== NULL
) {
1152 Status
= EFI_OUT_OF_RESOURCES
;
1155 DefaultData
->DefaultId
= VarDefaultId
;
1156 DefaultData
->DefaultName
= VarDefaultName
;
1157 DefaultData
->Value
= 1;
1159 // Add DefaultValue into current BlockData
1161 InsertDefaultValue (BlockData
, DefaultData
);
1165 case EFI_IFR_STRING_OP
:
1167 // offset by question header
1168 // width MaxSize * sizeof (CHAR16)
1169 // no default value, only block array
1173 // Check whether this question is for the requested varstore.
1175 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1176 if (IfrString
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1181 // Get Offset/Width by Question header and OneOf Flags
1183 VarOffset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1184 VarWidth
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1187 // Check whether this question is in requested block array.
1189 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1191 // This question is not in the requested string. Skip it.
1197 // Check this var question is in the var storage
1199 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1200 Status
= EFI_INVALID_PARAMETER
;
1207 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1208 if (BlockData
== NULL
) {
1209 Status
= EFI_OUT_OF_RESOURCES
;
1212 BlockData
->Offset
= VarOffset
;
1213 BlockData
->Width
= VarWidth
;
1214 BlockData
->QuestionId
= IfrString
->Question
.QuestionId
;
1215 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1216 InitializeListHead (&BlockData
->DefaultValueEntry
);
1219 // Add Block Data into VarStorageData BlockEntry
1221 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1224 // No default value for string.
1229 case EFI_IFR_PASSWORD_OP
:
1231 // offset by question header
1232 // width MaxSize * sizeof (CHAR16)
1233 // no default value, only block array
1237 // Check whether this question is for the requested varstore.
1239 IfrPassword
= (EFI_IFR_PASSWORD
*) IfrOpHdr
;
1240 if (IfrPassword
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1245 // Get Offset/Width by Question header and OneOf Flags
1247 VarOffset
= IfrPassword
->Question
.VarStoreInfo
.VarOffset
;
1248 VarWidth
= (UINT16
) (IfrPassword
->MaxSize
* sizeof (UINT16
));
1251 // Check whether this question is in requested block array.
1253 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1255 // This question is not in the requested string. Skip it.
1261 // Check this var question is in the var storage
1263 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1264 Status
= EFI_INVALID_PARAMETER
;
1271 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1272 if (BlockData
== NULL
) {
1273 Status
= EFI_OUT_OF_RESOURCES
;
1276 BlockData
->Offset
= VarOffset
;
1277 BlockData
->Width
= VarWidth
;
1278 BlockData
->QuestionId
= IfrPassword
->Question
.QuestionId
;
1279 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1280 InitializeListHead (&BlockData
->DefaultValueEntry
);
1283 // Add Block Data into VarStorageData BlockEntry
1285 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1288 // No default value for string.
1293 case EFI_IFR_ONE_OF_OPTION_OP
:
1295 // No matched block data is ignored.
1297 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1301 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1302 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1304 // Get ordered list option data type.
1306 if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_8
|| IfrOneOfOption
->Type
== EFI_IFR_TYPE_BOOLEAN
) {
1308 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_16
) {
1310 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_32
) {
1312 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_64
) {
1316 // Invalid ordered list option data type.
1318 Status
= EFI_INVALID_PARAMETER
;
1322 // Calculate Ordered list QuestionId width.
1324 BlockData
->Width
= (UINT16
) (BlockData
->Width
* VarWidth
);
1329 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) {
1331 // Set standard ID to Manufacture ID and Get DefaultName String ID
1333 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1334 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1335 if (EFI_ERROR (Status
)) {
1339 // Prepare new DefaultValue
1341 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1342 if (DefaultData
== NULL
) {
1343 Status
= EFI_OUT_OF_RESOURCES
;
1346 DefaultData
->DefaultId
= VarDefaultId
;
1347 DefaultData
->DefaultName
= VarDefaultName
;
1348 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1350 // Add DefaultValue into current BlockData
1352 InsertDefaultValue (BlockData
, DefaultData
);
1355 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
) {
1357 // Set default ID to Manufacture ID and Get DefaultName String ID
1359 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1360 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1361 if (EFI_ERROR (Status
)) {
1365 // Prepare new DefaultValue
1367 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1368 if (DefaultData
== NULL
) {
1369 Status
= EFI_OUT_OF_RESOURCES
;
1372 DefaultData
->DefaultId
= VarDefaultId
;
1373 DefaultData
->DefaultName
= VarDefaultName
;
1374 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1376 // Add DefaultValue into current BlockData
1378 InsertDefaultValue (BlockData
, DefaultData
);
1382 case EFI_IFR_DEFAULT_OP
:
1384 // Update Current BlockData to the default value.
1386 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1388 // No matched block data is ignored.
1393 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1395 // OrderedList Opcode is no default value.
1400 // Get the DefaultId and DefaultName String ID
1402 IfrDefault
= (EFI_IFR_DEFAULT
*) IfrOpHdr
;
1403 VarDefaultId
= IfrDefault
->DefaultId
;
1404 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1405 if (EFI_ERROR (Status
)) {
1409 // Prepare new DefaultValue
1411 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1412 if (DefaultData
== NULL
) {
1413 Status
= EFI_OUT_OF_RESOURCES
;
1416 DefaultData
->DefaultId
= VarDefaultId
;
1417 DefaultData
->DefaultName
= VarDefaultName
;
1418 DefaultData
->Value
= IfrDefault
->Value
.u64
;
1420 // Add DefaultValue into current BlockData
1422 InsertDefaultValue (BlockData
, DefaultData
);
1424 case EFI_IFR_END_OP
:
1426 // End Opcode is for Var.
1428 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1433 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1434 BlockData
->Scope
= (UINT8
) (BlockData
->Scope
+ IfrOpHdr
->Scope
);
1439 IfrOffset
+= IfrOpHdr
->Length
;
1444 // Set the defualt ID array.
1446 *PIfrDefaultIdArray
= DefaultIdArray
;
1452 This function gets the full request string and full default value string by
1453 parsing IFR data in HII form packages.
1455 When Request points to NULL string, the request string and default value string
1456 for each varstore in form package will return.
1458 @param HiiHandle Hii Handle which Hii Packages are registered.
1459 @param DevicePath Device Path which Hii Config Access Protocol is registered.
1460 @param Request Pointer to a null-terminated Unicode string in
1461 <ConfigRequest> format. When it doesn't contain
1462 any RequestElement, it will be updated to return
1463 the full RequestElement retrieved from IFR data.
1464 If it points to NULL, the request string for the first
1465 varstore in form package will be merged into a
1466 <MultiConfigRequest> format string and return.
1467 @param AltCfgResp Pointer to a null-terminated Unicode string in
1468 <ConfigAltResp> format. When the pointer is to NULL,
1469 the full default value string retrieved from IFR data
1470 will return. When the pinter is to a string, the
1471 full default value string retrieved from IFR data
1472 will be merged into the input string and return.
1473 When Request points to NULL, the default value string
1474 for each varstore in form package will be merged into
1475 a <MultiConfigAltResp> format string and return.
1476 @retval EFI_SUCCESS The Results string is set to the full request string.
1477 And AltCfgResp contains all default value string.
1478 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
1479 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string
1480 can't be found in Form package.
1481 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.
1482 @retval EFI_INVALID_PARAMETER *Request points to NULL.
1487 GetFullStringFromHiiFormPackages (
1488 IN EFI_HII_HANDLE HiiHandle
,
1489 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1490 IN OUT EFI_STRING
*Request
,
1491 IN OUT EFI_STRING
*AltCfgResp
1495 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1496 UINT32 PackageListLength
;
1498 IFR_BLOCK_DATA
*RequestBlockArray
;
1499 IFR_BLOCK_DATA
*BlockData
;
1500 IFR_BLOCK_DATA
*NextBlockData
;
1501 IFR_DEFAULT_DATA
*DefaultValueData
;
1502 IFR_DEFAULT_DATA
*DefaultId
;
1503 IFR_DEFAULT_DATA
*DefaultIdArray
;
1504 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1505 UINT32 PackageOffset
;
1506 IFR_VARSTORAGE_DATA
*VarStorageData
;
1507 EFI_STRING DefaultAltCfgResp
;
1508 EFI_STRING FullConfigRequest
;
1509 EFI_STRING ConfigHdr
;
1513 EFI_STRING StringPtr
;
1519 LIST_ENTRY
*LinkData
;
1520 LIST_ENTRY
*LinkDefault
;
1523 // Initialize the local variables.
1525 RequestBlockArray
= NULL
;
1526 VarStorageData
= NULL
;
1527 DefaultAltCfgResp
= NULL
;
1528 FullConfigRequest
= NULL
;
1530 DefaultIdArray
= NULL
;
1536 // 1. Get HiiPackage by HiiHandle
1539 HiiPackageList
= NULL
;
1540 Status
= HiiExportPackageLists (&mPrivate
.HiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
1543 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1545 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1549 HiiPackageList
= AllocatePool (BufferSize
);
1550 if (HiiPackageList
== NULL
) {
1551 return EFI_OUT_OF_RESOURCES
;
1555 // Get PackageList on HiiHandle
1557 Status
= HiiExportPackageLists (&mPrivate
.HiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
1558 if (EFI_ERROR (Status
)) {
1563 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
1564 // 1) Request is NULL.
1565 // 2) Request is not NULL. And it doesn't contain any BlockArray.
1566 // 3) Request is not NULL. And it containts BlockArray.
1570 // Initialize VarStorageData to store the var store Block and Default value information.
1572 VarStorageData
= (IFR_VARSTORAGE_DATA
*) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA
));
1573 if (VarStorageData
== NULL
) {
1574 Status
= EFI_OUT_OF_RESOURCES
;
1578 InitializeListHead (&VarStorageData
->Entry
);
1579 InitializeListHead (&VarStorageData
->BlockEntry
);
1582 // Gte the request block array by Request String
1585 if (*Request
!= NULL
) {
1586 StringPtr
= StrStr (*Request
, L
"&OFFSET=");
1588 if (StringPtr
!= NULL
) {
1590 // Init RequestBlockArray
1592 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1593 if (RequestBlockArray
== NULL
) {
1594 Status
= EFI_OUT_OF_RESOURCES
;
1597 InitializeListHead (&RequestBlockArray
->Entry
);
1600 // Get the request Block array from the request string
1605 // Parse each <RequestElement> if exists
1606 // Only <BlockName> format is supported by this help function.
1607 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1609 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1611 // Skip the OFFSET string
1613 StringPtr
+= StrLen (L
"&OFFSET=");
1617 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1618 if (EFI_ERROR (Status
)) {
1625 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1627 FreePool (TmpBuffer
);
1629 StringPtr
+= Length
;
1630 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1631 Status
= EFI_INVALID_PARAMETER
;
1634 StringPtr
+= StrLen (L
"&WIDTH=");
1639 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1640 if (EFI_ERROR (Status
)) {
1647 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1649 FreePool (TmpBuffer
);
1651 StringPtr
+= Length
;
1652 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1653 Status
= EFI_INVALID_PARAMETER
;
1660 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1661 if (BlockData
== NULL
) {
1662 Status
= EFI_OUT_OF_RESOURCES
;
1665 BlockData
->Offset
= Offset
;
1666 BlockData
->Width
= Width
;
1667 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
1670 // If '\0', parsing is finished.
1672 if (*StringPtr
== 0) {
1678 // Merge the requested block data.
1680 Link
= RequestBlockArray
->Entry
.ForwardLink
;
1681 while ((Link
!= &RequestBlockArray
->Entry
) && (Link
->ForwardLink
!= &RequestBlockArray
->Entry
)) {
1682 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1683 NextBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1684 if ((NextBlockData
->Offset
>= BlockData
->Offset
) && (NextBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1685 if ((NextBlockData
->Offset
+ NextBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1686 BlockData
->Width
= (UINT16
) (NextBlockData
->Offset
+ NextBlockData
->Width
- BlockData
->Offset
);
1688 RemoveEntryList (Link
->ForwardLink
);
1689 FreePool (NextBlockData
);
1692 Link
= Link
->ForwardLink
;
1697 // Get the form package
1699 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1700 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
1701 while (PackageOffset
< PackageListLength
) {
1702 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1704 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1706 // Reset VarStorageData
1708 VarStorageData
->Size
= 0;
1709 VarStorageData
->VarStoreId
= 0;
1710 if (VarStorageData
->Name
!= NULL
) {
1711 FreePool (VarStorageData
->Name
);
1712 VarStorageData
->Name
= NULL
;
1716 // Parse the opcode in form package
1718 Status
= ParseIfrData ((UINT8
*) HiiPackageList
+ PackageOffset
, PacakgeHeader
.Length
, *Request
, RequestBlockArray
, VarStorageData
, &DefaultIdArray
);
1719 if (EFI_ERROR (Status
)) {
1724 // Only one form is in a pacakge list.
1729 PackageOffset
+= PacakgeHeader
.Length
;
1733 // No requested varstore in IFR data and directly return
1735 if (VarStorageData
->Size
== 0) {
1740 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
1744 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
1746 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
1747 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
1750 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
1751 (VOID
*) DevicePath
,
1755 Length
= StrLen (GuidStr
);
1756 Length
= Length
+ StrLen (NameStr
);
1757 Length
= Length
+ StrLen (PathStr
) + 1;
1758 ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1759 if (ConfigHdr
== NULL
) {
1760 Status
= EFI_OUT_OF_RESOURCES
;
1763 StrCpy (ConfigHdr
, GuidStr
);
1764 StrCat (ConfigHdr
, NameStr
);
1765 StrCat (ConfigHdr
, PathStr
);
1768 // Remove the last character L'&'
1770 *(ConfigHdr
+ StrLen (ConfigHdr
) - 1) = L
'\0';
1772 if (RequestBlockArray
== NULL
) {
1774 // Append VarStorageData BlockEntry into *Request string
1775 // Now support only one varstore in a form package.
1779 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
1780 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
1784 // Compute the length of the entire request starting with <ConfigHdr> and a
1787 Length
= StrLen (ConfigHdr
) + 1;
1789 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1791 // Add <BlockName> length for each Offset/Width pair
1793 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
1794 // | 8 | 4 | 7 | 4 |
1796 Length
= Length
+ (8 + 4 + 7 + 4);
1800 // Allocate buffer for the entire <ConfigRequest>
1802 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1803 if (FullConfigRequest
== NULL
) {
1806 StringPtr
= FullConfigRequest
;
1809 // Start with <ConfigHdr>
1811 StrCpy (StringPtr
, ConfigHdr
);
1812 StringPtr
+= StrLen (StringPtr
);
1815 // Loop through all the Offset/Width pairs and append them to ConfigRequest
1817 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1818 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1820 // Append &OFFSET=XXXX&WIDTH=YYYY\0
1824 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1825 L
"&OFFSET=%04X&WIDTH=%04X",
1829 StringPtr
+= StrLen (StringPtr
);
1832 // Set to the got full request string.
1834 HiiToLower (FullConfigRequest
);
1835 if (*Request
!= NULL
) {
1836 FreePool (*Request
);
1838 *Request
= FullConfigRequest
;
1842 // 4. Construct Default Value string in AltResp according to request element.
1843 // Go through all VarStorageData Entry and get the DefaultId array for each one
1844 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
1848 // Add length for <ConfigHdr> + '\0'
1850 Length
= StrLen (ConfigHdr
) + 1;
1852 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1853 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1855 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
1856 // |1| StrLen (ConfigHdr) | 8 | 4 |
1858 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
1860 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1861 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1862 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1863 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1864 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1866 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
1867 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
1869 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
1876 // Allocate buffer for the entire <DefaultAltCfgResp>
1878 DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1879 if (DefaultAltCfgResp
== NULL
) {
1882 StringPtr
= DefaultAltCfgResp
;
1885 // Start with <ConfigHdr>
1887 StrCpy (StringPtr
, ConfigHdr
);
1888 StringPtr
+= StrLen (StringPtr
);
1890 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1891 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1893 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
1894 // |1| StrLen (ConfigHdr) | 8 | 4 |
1898 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
1901 DefaultId
->DefaultName
1903 StringPtr
+= StrLen (StringPtr
);
1905 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1906 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1907 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1908 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1909 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1911 // Add <BlockConfig>
1912 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
1916 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
1917 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
1921 StringPtr
+= StrLen (StringPtr
);
1924 // Convert Value to a hex string in "%x" format
1925 // NOTE: This is in the opposite byte that GUID and PATH use
1927 Width
= BlockData
->Width
;
1928 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
1929 for (; Width
> 0; Width
--) {
1930 StringPtr
+= UnicodeValueToString (StringPtr
, PREFIX_ZERO
| RADIX_HEX
, TmpBuffer
[Width
- 1], 2);
1936 HiiToLower (DefaultAltCfgResp
);
1939 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.
1941 if (*AltCfgResp
!= NULL
) {
1942 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
1943 FreePool (DefaultAltCfgResp
);
1945 *AltCfgResp
= DefaultAltCfgResp
;
1949 if (RequestBlockArray
!= NULL
) {
1951 // Free Link Array RequestBlockArray
1953 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
1954 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1955 RemoveEntryList (&BlockData
->Entry
);
1956 FreePool (BlockData
);
1959 FreePool (RequestBlockArray
);
1962 if (VarStorageData
!= NULL
) {
1964 // Free link array VarStorageData
1966 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
1967 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1968 RemoveEntryList (&BlockData
->Entry
);
1970 // Free default value link array
1972 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
1973 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
1974 RemoveEntryList (&DefaultValueData
->Entry
);
1975 FreePool (DefaultValueData
);
1977 FreePool (BlockData
);
1979 FreePool (VarStorageData
);
1982 if (DefaultIdArray
!= NULL
) {
1984 // Free DefaultId Array
1986 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
1987 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
1988 RemoveEntryList (&DefaultId
->Entry
);
1989 FreePool (DefaultId
);
1991 FreePool (DefaultIdArray
);
1995 // Free the allocated string
1997 if (GuidStr
!= NULL
) {
2000 if (NameStr
!= NULL
) {
2003 if (PathStr
!= NULL
) {
2006 if (ConfigHdr
!= NULL
) {
2007 FreePool (ConfigHdr
);
2011 // Free Pacakge data
2013 if (HiiPackageList
!= NULL
) {
2014 FreePool (HiiPackageList
);
2021 This function allows a caller to extract the current configuration
2022 for one or more named elements from one or more drivers.
2024 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2026 @param Request A null-terminated Unicode string in
2027 <MultiConfigRequest> format.
2028 @param Progress On return, points to a character in the Request
2029 string. Points to the string's null terminator if
2030 request was successful. Points to the most recent
2031 & before the first failing name / value pair (or
2032 the beginning of the string if the failure is in
2033 the first name / value pair) if the request was
2035 @param Results Null-terminated Unicode string in
2036 <MultiConfigAltResp> format which has all values
2037 filled in for the names in the Request string.
2038 String to be allocated by the called function.
2040 @retval EFI_SUCCESS The Results string is filled with the values
2041 corresponding to all requested names.
2042 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2043 results that must be stored awaiting possible
2045 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
2046 Progress set to the "G" in "GUID" of the routing
2047 header that doesn't match. Note: There is no
2048 requirement that all routing data be validated
2049 before any configuration extraction.
2050 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
2051 parameter would result in this type of error. The
2052 Progress parameter is set to NULL.
2053 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
2054 before the error or the beginning of the string.
2055 @retval EFI_INVALID_PARAMETER Unknown name. Progress points to the & before the
2061 HiiConfigRoutingExtractConfig (
2062 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2063 IN CONST EFI_STRING Request
,
2064 OUT EFI_STRING
*Progress
,
2065 OUT EFI_STRING
*Results
2068 HII_DATABASE_PRIVATE_DATA
*Private
;
2069 EFI_STRING StringPtr
;
2070 EFI_STRING ConfigRequest
;
2072 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2073 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2076 HII_DATABASE_RECORD
*Database
;
2077 UINT8
*DevicePathPkg
;
2078 UINT8
*CurrentDevicePath
;
2079 EFI_HANDLE DriverHandle
;
2080 EFI_HII_HANDLE HiiHandle
;
2081 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2082 EFI_STRING AccessProgress
;
2083 EFI_STRING AccessResults
;
2084 EFI_STRING DefaultResults
;
2085 BOOLEAN FirstElement
;
2086 UINTN DevicePathLength
;
2088 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
2089 return EFI_INVALID_PARAMETER
;
2092 if (Request
== NULL
) {
2094 return EFI_INVALID_PARAMETER
;
2097 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2098 StringPtr
= Request
;
2099 *Progress
= StringPtr
;
2100 DefaultResults
= NULL
;
2101 ConfigRequest
= NULL
;
2102 Status
= EFI_SUCCESS
;
2103 AccessResults
= NULL
;
2107 // The first element of <MultiConfigRequest> should be
2108 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2110 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2111 return EFI_INVALID_PARAMETER
;
2114 FirstElement
= TRUE
;
2117 // Allocate a fix length of memory to store Results. Reallocate memory for
2118 // Results if this fix length is insufficient.
2120 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2121 if (*Results
== NULL
) {
2122 return EFI_OUT_OF_RESOURCES
;
2125 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2127 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
2128 // or most recent & before the error.
2130 if (StringPtr
== Request
) {
2131 *Progress
= StringPtr
;
2133 *Progress
= StringPtr
- 1;
2137 // Process each <ConfigRequest> of <MultiConfigRequest>
2139 Length
= CalculateConfigStringLen (StringPtr
);
2140 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2141 if (ConfigRequest
== NULL
) {
2142 Status
= EFI_OUT_OF_RESOURCES
;
2145 *(ConfigRequest
+ Length
) = 0;
2148 // Get the UEFI device path
2150 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
2151 if (EFI_ERROR (Status
)) {
2156 // Find driver which matches the routing data.
2158 DriverHandle
= NULL
;
2160 DevicePathLength
= GetDevicePathSize (DevicePath
);
2161 for (Link
= Private
->DatabaseList
.ForwardLink
;
2162 Link
!= &Private
->DatabaseList
;
2163 Link
= Link
->ForwardLink
2165 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2167 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2168 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2169 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2175 DriverHandle
= Database
->DriverHandle
;
2176 HiiHandle
= Database
->Handle
;
2183 // Try to find driver handle by device path.
2185 if (DriverHandle
== NULL
) {
2186 TempDevicePath
= DevicePath
;
2187 Status
= gBS
->LocateDevicePath (
2188 &gEfiDevicePathProtocolGuid
,
2192 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2194 // Routing data does not match any known driver.
2195 // Set Progress to the 'G' in "GUID" of the routing header.
2197 *Progress
= StringPtr
;
2198 Status
= EFI_NOT_FOUND
;
2204 // Check whether ConfigRequest contains request string OFFSET/WIDTH
2206 if ((HiiHandle
!= NULL
) && (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
)) {
2208 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
2210 Status
= GetFullStringFromHiiFormPackages (HiiHandle
, DevicePath
, &ConfigRequest
, &DefaultResults
);
2211 if (EFI_ERROR (Status
)) {
2215 // Not any request block is found.
2217 if (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
) {
2218 AccessResults
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
2219 goto NextConfigString
;
2224 // Call corresponding ConfigAccess protocol to extract settings
2226 Status
= gBS
->HandleProtocol (
2228 &gEfiHiiConfigAccessProtocolGuid
,
2229 (VOID
**) &ConfigAccess
2231 ASSERT_EFI_ERROR (Status
);
2233 Status
= ConfigAccess
->ExtractConfig (
2239 if (EFI_ERROR (Status
)) {
2241 // AccessProgress indicates the parsing progress on <ConfigRequest>.
2242 // Map it to the progress on <MultiConfigRequest> then return it.
2244 *Progress
= StrStr (StringPtr
, AccessProgress
);
2249 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2250 // which seperates the first <ConfigAltResp> and the following ones.
2252 ASSERT (*AccessProgress
== 0);
2255 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2257 if (HiiHandle
!= NULL
) {
2258 if (DefaultResults
== NULL
) {
2259 Status
= GetFullStringFromHiiFormPackages (HiiHandle
, DevicePath
, &ConfigRequest
, &AccessResults
);
2261 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2264 FreePool (DevicePath
);
2267 if (EFI_ERROR (Status
)) {
2272 // Free the allocated memory.
2274 if (DefaultResults
!= NULL
) {
2275 FreePool (DefaultResults
);
2276 DefaultResults
= NULL
;
2280 if (!FirstElement
) {
2281 Status
= AppendToMultiString (Results
, L
"&");
2282 ASSERT_EFI_ERROR (Status
);
2285 Status
= AppendToMultiString (Results
, AccessResults
);
2286 ASSERT_EFI_ERROR (Status
);
2288 FirstElement
= FALSE
;
2290 FreePool (AccessResults
);
2291 AccessResults
= NULL
;
2292 FreePool (ConfigRequest
);
2293 ConfigRequest
= NULL
;
2296 // Go to next <ConfigRequest> (skip '&').
2298 StringPtr
+= Length
;
2299 if (*StringPtr
== 0) {
2300 *Progress
= StringPtr
;
2308 if (EFI_ERROR (Status
)) {
2309 FreePool (*Results
);
2313 if (ConfigRequest
!= NULL
) {
2314 FreePool (ConfigRequest
);
2317 if (AccessResults
!= NULL
) {
2318 FreePool (AccessResults
);
2321 if (DefaultResults
!= NULL
) {
2322 FreePool (DefaultResults
);
2325 if (DevicePath
!= NULL
) {
2326 FreePool (DevicePath
);
2334 This function allows the caller to request the current configuration for the
2335 entirety of the current HII database and returns the data in a
2336 null-terminated Unicode string.
2338 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2340 @param Results Null-terminated Unicode string in
2341 <MultiConfigAltResp> format which has all values
2342 filled in for the names in the Request string.
2343 String to be allocated by the called function.
2344 De-allocation is up to the caller.
2346 @retval EFI_SUCCESS The Results string is filled with the values
2347 corresponding to all requested names.
2348 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2349 results that must be stored awaiting possible
2351 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
2352 parameter would result in this type of error.
2357 HiiConfigRoutingExportConfig (
2358 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2359 OUT EFI_STRING
*Results
2363 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2364 EFI_STRING AccessResults
;
2365 EFI_STRING Progress
;
2366 EFI_STRING ConfigRequest
;
2368 EFI_HANDLE
*ConfigAccessHandles
;
2369 UINTN NumberConfigAccessHandles
;
2370 BOOLEAN FirstElement
;
2371 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2372 EFI_HII_HANDLE HiiHandle
;
2373 EFI_STRING DefaultResults
;
2374 HII_DATABASE_PRIVATE_DATA
*Private
;
2376 HII_DATABASE_RECORD
*Database
;
2377 UINT8
*DevicePathPkg
;
2378 UINT8
*CurrentDevicePath
;
2379 UINTN DevicePathLength
;
2381 if (This
== NULL
|| Results
== NULL
) {
2382 return EFI_INVALID_PARAMETER
;
2385 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2388 // Allocate a fix length of memory to store Results. Reallocate memory for
2389 // Results if this fix length is insufficient.
2391 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2392 if (*Results
== NULL
) {
2393 return EFI_OUT_OF_RESOURCES
;
2396 NumberConfigAccessHandles
= 0;
2397 Status
= gBS
->LocateHandleBuffer (
2399 &gEfiHiiConfigAccessProtocolGuid
,
2401 &NumberConfigAccessHandles
,
2402 &ConfigAccessHandles
2404 if (EFI_ERROR (Status
)) {
2408 FirstElement
= TRUE
;
2410 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
2411 Status
= gBS
->HandleProtocol (
2412 ConfigAccessHandles
[Index
],
2413 &gEfiHiiConfigAccessProtocolGuid
,
2414 (VOID
**) &ConfigAccess
2416 if (EFI_ERROR (Status
)) {
2421 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
2425 ConfigRequest
= NULL
;
2426 DefaultResults
= NULL
;
2427 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
2428 DevicePathLength
= GetDevicePathSize (DevicePath
);
2429 if (DevicePath
!= NULL
) {
2430 for (Link
= Private
->DatabaseList
.ForwardLink
;
2431 Link
!= &Private
->DatabaseList
;
2432 Link
= Link
->ForwardLink
2434 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2435 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2436 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2437 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2443 HiiHandle
= Database
->Handle
;
2451 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2453 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
2454 Status
= GetFullStringFromHiiFormPackages (HiiHandle
, DevicePath
, &ConfigRequest
, &DefaultResults
);
2457 // Can't parse IFR data to get the request string and default string.
2459 if (EFI_ERROR (Status
)) {
2460 ConfigRequest
= NULL
;
2461 DefaultResults
= NULL
;
2464 Status
= ConfigAccess
->ExtractConfig (
2470 if (!EFI_ERROR (Status
)) {
2472 // Merge the default sting from IFR code into the got setting from driver.
2474 if (DefaultResults
!= NULL
) {
2475 MergeDefaultString (&AccessResults
, DefaultResults
);
2476 FreePool (DefaultResults
);
2480 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2481 // which seperates the first <ConfigAltResp> and the following ones.
2483 if (!FirstElement
) {
2484 Status
= AppendToMultiString (Results
, L
"&");
2485 ASSERT_EFI_ERROR (Status
);
2488 Status
= AppendToMultiString (Results
, AccessResults
);
2489 ASSERT_EFI_ERROR (Status
);
2491 FirstElement
= FALSE
;
2493 FreePool (AccessResults
);
2494 AccessResults
= NULL
;
2497 FreePool (ConfigAccessHandles
);
2504 This function processes the results of processing forms and routes it to the
2505 appropriate handlers or storage.
2507 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2509 @param Configuration A null-terminated Unicode string in
2510 <MulltiConfigResp> format.
2511 @param Progress A pointer to a string filled in with the offset of
2512 the most recent & before the first failing name /
2513 value pair (or the beginning of the string if the
2514 failure is in the first name / value pair) or the
2515 terminating NULL if all was successful.
2517 @retval EFI_SUCCESS The results have been distributed or are awaiting
2519 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2520 results that must be stored awaiting possible
2522 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
2523 would result in this type of error.
2524 @retval EFI_NOT_FOUND Target for the specified routing data was not
2530 HiiConfigRoutingRouteConfig (
2531 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2532 IN CONST EFI_STRING Configuration
,
2533 OUT EFI_STRING
*Progress
2536 HII_DATABASE_PRIVATE_DATA
*Private
;
2537 EFI_STRING StringPtr
;
2538 EFI_STRING ConfigResp
;
2541 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2542 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2544 HII_DATABASE_RECORD
*Database
;
2545 UINT8
*DevicePathPkg
;
2546 UINT8
*CurrentDevicePath
;
2547 EFI_HANDLE DriverHandle
;
2548 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2549 EFI_STRING AccessProgress
;
2550 UINTN DevicePathLength
;
2552 if (This
== NULL
|| Progress
== NULL
) {
2553 return EFI_INVALID_PARAMETER
;
2556 if (Configuration
== NULL
) {
2558 return EFI_INVALID_PARAMETER
;
2561 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2562 StringPtr
= Configuration
;
2563 *Progress
= StringPtr
;
2566 // The first element of <MultiConfigResp> should be
2567 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2569 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2570 return EFI_INVALID_PARAMETER
;
2573 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2575 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
2576 // or most recent & before the error.
2578 if (StringPtr
== Configuration
) {
2579 *Progress
= StringPtr
;
2581 *Progress
= StringPtr
- 1;
2585 // Process each <ConfigResp> of <MultiConfigResp>
2587 Length
= CalculateConfigStringLen (StringPtr
);
2588 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2589 if (ConfigResp
== NULL
) {
2590 return EFI_OUT_OF_RESOURCES
;
2593 // Append '\0' to the end of ConfigRequest
2595 *(ConfigResp
+ Length
) = 0;
2598 // Get the UEFI device path
2600 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
2601 if (EFI_ERROR (Status
)) {
2602 FreePool (ConfigResp
);
2607 // Find driver which matches the routing data.
2609 DriverHandle
= NULL
;
2610 DevicePathLength
= GetDevicePathSize (DevicePath
);
2611 for (Link
= Private
->DatabaseList
.ForwardLink
;
2612 Link
!= &Private
->DatabaseList
;
2613 Link
= Link
->ForwardLink
2615 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2617 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2618 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2619 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2625 DriverHandle
= Database
->DriverHandle
;
2632 // Try to find driver handle by device path.
2634 if (DriverHandle
== NULL
) {
2635 TempDevicePath
= DevicePath
;
2636 Status
= gBS
->LocateDevicePath (
2637 &gEfiDevicePathProtocolGuid
,
2641 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2643 // Routing data does not match any known driver.
2644 // Set Progress to the 'G' in "GUID" of the routing header.
2646 FreePool (DevicePath
);
2647 *Progress
= StringPtr
;
2648 FreePool (ConfigResp
);
2649 return EFI_NOT_FOUND
;
2653 FreePool (DevicePath
);
2656 // Call corresponding ConfigAccess protocol to route settings
2658 Status
= gBS
->HandleProtocol (
2660 &gEfiHiiConfigAccessProtocolGuid
,
2661 (VOID
**) &ConfigAccess
2663 ASSERT_EFI_ERROR (Status
);
2665 Status
= ConfigAccess
->RouteConfig (
2671 if (EFI_ERROR (Status
)) {
2673 // AccessProgress indicates the parsing progress on <ConfigResp>.
2674 // Map it to the progress on <MultiConfigResp> then return it.
2676 *Progress
= StrStr (StringPtr
, AccessProgress
);
2678 FreePool (ConfigResp
);
2682 FreePool (ConfigResp
);
2686 // Go to next <ConfigResp> (skip '&').
2688 StringPtr
+= Length
;
2689 if (*StringPtr
== 0) {
2690 *Progress
= StringPtr
;
2703 This helper function is to be called by drivers to map configuration data
2704 stored in byte array ("block") formats such as UEFI Variables into current
2705 configuration strings.
2707 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2709 @param ConfigRequest A null-terminated Unicode string in
2710 <ConfigRequest> format.
2711 @param Block Array of bytes defining the block's configuration.
2712 @param BlockSize Length in bytes of Block.
2713 @param Config Filled-in configuration string. String allocated
2714 by the function. Returned only if call is
2715 successful. It is <ConfigResp> string format.
2716 @param Progress A pointer to a string filled in with the offset of
2717 the most recent & before the first failing
2718 name/value pair (or the beginning of the string if
2719 the failure is in the first name / value pair) or
2720 the terminating NULL if all was successful.
2722 @retval EFI_SUCCESS The request succeeded. Progress points to the null
2723 terminator at the end of the ConfigRequest
2725 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
2726 points to the first character of ConfigRequest.
2727 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
2728 Block parameter would result in this type of
2729 error. Progress points to the first character of
2731 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
2732 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
2733 Block is left updated and Progress points at
2734 the "&" preceding the first non-<BlockName>.
2740 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2741 IN CONST EFI_STRING ConfigRequest
,
2742 IN CONST UINT8
*Block
,
2743 IN CONST UINTN BlockSize
,
2744 OUT EFI_STRING
*Config
,
2745 OUT EFI_STRING
*Progress
2748 HII_DATABASE_PRIVATE_DATA
*Private
;
2749 EFI_STRING StringPtr
;
2757 EFI_STRING ValueStr
;
2758 EFI_STRING ConfigElement
;
2763 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
2764 return EFI_INVALID_PARAMETER
;
2767 if (Block
== NULL
|| ConfigRequest
== NULL
) {
2768 *Progress
= ConfigRequest
;
2769 return EFI_INVALID_PARAMETER
;
2773 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2774 ASSERT (Private
!= NULL
);
2776 StringPtr
= ConfigRequest
;
2779 ConfigElement
= NULL
;
2782 // Allocate a fix length of memory to store Results. Reallocate memory for
2783 // Results if this fix length is insufficient.
2785 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2786 if (*Config
== NULL
) {
2787 return EFI_OUT_OF_RESOURCES
;
2793 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2794 *Progress
= StringPtr
;
2795 Status
= EFI_INVALID_PARAMETER
;
2798 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
2801 if (*StringPtr
== 0) {
2802 *Progress
= StringPtr
- 1;
2803 Status
= EFI_INVALID_PARAMETER
;
2807 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
2810 if (*StringPtr
== 0) {
2811 *Progress
= StringPtr
- 1;
2812 Status
= EFI_INVALID_PARAMETER
;
2821 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
2823 Length
= StringPtr
- ConfigRequest
;
2824 CopyMem (*Config
, ConfigRequest
, Length
* sizeof (CHAR16
));
2827 // Parse each <RequestElement> if exists
2828 // Only <BlockName> format is supported by this help function.
2829 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
2831 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
2833 // Back up the header of one <BlockName>
2837 StringPtr
+= StrLen (L
"OFFSET=");
2841 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2842 if (Status
== EFI_OUT_OF_RESOURCES
) {
2843 *Progress
= ConfigRequest
;
2850 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2852 FreePool (TmpBuffer
);
2854 StringPtr
+= Length
;
2855 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
2856 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
2857 Status
= EFI_INVALID_PARAMETER
;
2860 StringPtr
+= StrLen (L
"&WIDTH=");
2865 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2866 if (Status
== EFI_OUT_OF_RESOURCES
) {
2867 *Progress
= ConfigRequest
;
2874 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2876 FreePool (TmpBuffer
);
2878 StringPtr
+= Length
;
2879 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
2880 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
2881 Status
= EFI_INVALID_PARAMETER
;
2886 // Calculate Value and convert it to hex string.
2888 if (Offset
+ Width
> BlockSize
) {
2889 *Progress
= StringPtr
;
2890 Status
= EFI_DEVICE_ERROR
;
2894 Value
= (UINT8
*) AllocateZeroPool (Width
);
2895 if (Value
== NULL
) {
2896 *Progress
= ConfigRequest
;
2897 Status
= EFI_OUT_OF_RESOURCES
;
2901 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
2903 Length
= Width
* 2 + 1;
2904 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2905 if (ValueStr
== NULL
) {
2906 *Progress
= ConfigRequest
;
2907 Status
= EFI_OUT_OF_RESOURCES
;
2911 TemString
= ValueStr
;
2912 TemBuffer
= Value
+ Width
- 1;
2913 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
2914 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
2921 // Build a ConfigElement
2923 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
2924 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2925 if (ConfigElement
== NULL
) {
2926 Status
= EFI_OUT_OF_RESOURCES
;
2929 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
2930 if (*StringPtr
== 0) {
2931 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
2933 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
2934 StrCat (ConfigElement
, L
"VALUE=");
2935 StrCat (ConfigElement
, ValueStr
);
2937 AppendToMultiString (Config
, ConfigElement
);
2939 FreePool (ConfigElement
);
2940 FreePool (ValueStr
);
2941 ConfigElement
= NULL
;
2945 // If '\0', parsing is finished. Otherwise skip '&' to continue
2947 if (*StringPtr
== 0) {
2950 AppendToMultiString (Config
, L
"&");
2955 if (*StringPtr
!= 0) {
2956 *Progress
= StringPtr
- 1;
2957 Status
= EFI_INVALID_PARAMETER
;
2961 HiiToLower (*Config
);
2962 *Progress
= StringPtr
;
2966 if (*Config
!= NULL
) {
2970 if (ValueStr
!= NULL
) {
2971 FreePool (ValueStr
);
2973 if (Value
!= NULL
) {
2976 if (ConfigElement
!= NULL
) {
2977 FreePool (ConfigElement
);
2986 This helper function is to be called by drivers to map configuration strings
2987 to configurations stored in byte array ("block") formats such as UEFI Variables.
2989 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2991 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
2992 format. It can be ConfigAltResp format string.
2993 @param Block A possibly null array of bytes representing the
2994 current block. Only bytes referenced in the
2995 ConfigResp string in the block are modified. If
2996 this parameter is null or if the *BlockSize
2997 parameter is (on input) shorter than required by
2998 the Configuration string, only the BlockSize
2999 parameter is updated and an appropriate status
3000 (see below) is returned.
3001 @param BlockSize The length of the Block in units of UINT8. On
3002 input, this is the size of the Block. On output,
3003 if successful, contains the index of the last
3004 modified byte in the Block.
3005 @param Progress On return, points to an element of the ConfigResp
3006 string filled in with the offset of the most
3007 recent '&' before the first failing name / value
3008 pair (or the beginning of the string if the
3009 failure is in the first name / value pair) or the
3010 terminating NULL if all was successful.
3012 @retval EFI_SUCCESS The request succeeded. Progress points to the null
3013 terminator at the end of the ConfigResp string.
3014 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
3015 points to the first character of ConfigResp.
3016 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
3017 Block parameter would result in this type of
3018 error. Progress points to the first character of
3020 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
3021 value pair. Block is left updated and
3022 Progress points at the '&' preceding the first
3029 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3030 IN CONST EFI_STRING ConfigResp
,
3031 IN OUT UINT8
*Block
,
3032 IN OUT UINTN
*BlockSize
,
3033 OUT EFI_STRING
*Progress
3036 HII_DATABASE_PRIVATE_DATA
*Private
;
3037 EFI_STRING StringPtr
;
3046 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
3047 return EFI_INVALID_PARAMETER
;
3050 if (ConfigResp
== NULL
|| Block
== NULL
) {
3051 *Progress
= ConfigResp
;
3052 return EFI_INVALID_PARAMETER
;
3055 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
3056 ASSERT (Private
!= NULL
);
3058 StringPtr
= ConfigResp
;
3059 BufferSize
= *BlockSize
;
3065 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3066 *Progress
= StringPtr
;
3067 Status
= EFI_INVALID_PARAMETER
;
3070 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
3073 if (*StringPtr
== 0) {
3074 *Progress
= StringPtr
;
3075 Status
= EFI_INVALID_PARAMETER
;
3079 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
3082 if (*StringPtr
== 0) {
3083 *Progress
= StringPtr
;
3084 Status
= EFI_INVALID_PARAMETER
;
3093 // Parse each <ConfigElement> if exists
3094 // Only <BlockConfig> format is supported by this help function.
3095 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
3097 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
3098 StringPtr
+= StrLen (L
"OFFSET=");
3102 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3103 if (EFI_ERROR (Status
)) {
3104 *Progress
= ConfigResp
;
3111 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3113 FreePool (TmpBuffer
);
3115 StringPtr
+= Length
;
3116 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3117 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
3118 Status
= EFI_INVALID_PARAMETER
;
3121 StringPtr
+= StrLen (L
"&WIDTH=");
3126 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3127 if (Status
== EFI_OUT_OF_RESOURCES
) {
3128 *Progress
= ConfigResp
;
3135 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3137 FreePool (TmpBuffer
);
3139 StringPtr
+= Length
;
3140 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
3141 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
3142 Status
= EFI_INVALID_PARAMETER
;
3145 StringPtr
+= StrLen (L
"&VALUE=");
3150 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
3151 if (EFI_ERROR (Status
)) {
3152 *Progress
= ConfigResp
;
3156 StringPtr
+= Length
;
3157 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3158 *Progress
= StringPtr
- Length
- 7;
3159 Status
= EFI_INVALID_PARAMETER
;
3164 // Update the Block with configuration info
3167 if (Offset
+ Width
> BufferSize
) {
3168 return EFI_DEVICE_ERROR
;
3171 CopyMem (Block
+ Offset
, Value
, Width
);
3172 *BlockSize
= Offset
+ Width
- 1;
3178 // If '\0', parsing is finished. Otherwise skip '&' to continue
3180 if (*StringPtr
== 0) {
3188 // The input string is ConfigAltResp format.
3190 if ((*StringPtr
!= 0) && (StrnCmp (StringPtr
, L
"&GUID=", StrLen (L
"&GUID=")) != 0)) {
3191 *Progress
= StringPtr
- 1;
3192 Status
= EFI_INVALID_PARAMETER
;
3196 *Progress
= StringPtr
;
3201 if (Value
!= NULL
) {
3209 This helper function is to be called by drivers to extract portions of
3210 a larger configuration string.
3212 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3214 @param Configuration A null-terminated Unicode string in
3215 <MultiConfigAltResp> format. It is <ConfigAltResp> format.
3216 @param Guid A pointer to the GUID value to search for in the
3217 routing portion of the ConfigResp string when
3218 retrieving the requested data. If Guid is NULL,
3219 then all GUID values will be searched for.
3220 @param Name A pointer to the NAME value to search for in the
3221 routing portion of the ConfigResp string when
3222 retrieving the requested data. If Name is NULL,
3223 then all Name values will be searched for.
3224 @param DevicePath A pointer to the PATH value to search for in the
3225 routing portion of the ConfigResp string when
3226 retrieving the requested data. If DevicePath is
3227 NULL, then all DevicePath values will be searched
3229 @param AltCfgId A pointer to the ALTCFG value to search for in the
3230 routing portion of the ConfigResp string when
3231 retrieving the requested data. If this parameter
3232 is NULL, then the current setting will be
3234 @param AltCfgResp A pointer to a buffer which will be allocated by
3235 the function which contains the retrieved string
3236 as requested. This buffer is only allocated if
3237 the call was successful. It is <ConfigResp> format.
3239 @retval EFI_SUCCESS The request succeeded. The requested data was
3240 extracted and placed in the newly allocated
3242 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
3243 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
3244 @retval EFI_NOT_FOUND Target for the specified routing data was not
3251 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3252 IN CONST EFI_STRING Configuration
,
3253 IN CONST EFI_GUID
*Guid
,
3254 IN CONST EFI_STRING Name
,
3255 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3256 IN CONST UINT16
*AltCfgId
,
3257 OUT EFI_STRING
*AltCfgResp
3261 EFI_STRING StringPtr
;
3262 EFI_STRING HdrStart
;
3269 EFI_STRING AltIdStr
;
3286 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
3287 return EFI_INVALID_PARAMETER
;
3290 StringPtr
= Configuration
;
3291 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3292 return EFI_INVALID_PARAMETER
;
3296 // Generate the sub string for later matching.
3298 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
3301 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
3302 (VOID
*) DevicePath
,
3306 if (AltCfgId
!= NULL
) {
3307 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
3310 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
3312 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
3315 while (*StringPtr
!= 0) {
3317 // Try to match the GUID
3320 TmpPtr
= StrStr (StringPtr
, GuidStr
);
3321 if (TmpPtr
== NULL
) {
3322 Status
= EFI_NOT_FOUND
;
3328 // Jump to <NameHdr>
3331 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
3333 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
3334 if (StringPtr
== NULL
) {
3335 Status
= EFI_NOT_FOUND
;
3343 // Try to match the NAME
3345 if (GuidFlag
&& !NameFlag
) {
3346 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
3350 // Jump to <PathHdr>
3353 StringPtr
+= StrLen (NameStr
);
3355 StringPtr
= StrStr (StringPtr
, L
"PATH=");
3356 if (StringPtr
== NULL
) {
3357 Status
= EFI_NOT_FOUND
;
3366 // Try to match the DevicePath
3368 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
3369 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
3374 // Jump to '&' before <DescHdr> or <ConfigBody>
3376 if (DevicePath
!= NULL
) {
3377 StringPtr
+= StrLen (PathStr
);
3379 StringPtr
= StrStr (StringPtr
, L
"&");
3380 if (StringPtr
== NULL
) {
3381 Status
= EFI_NOT_FOUND
;
3392 // Try to match the AltCfgId
3394 if (GuidFlag
&& NameFlag
&& PathFlag
) {
3395 if (AltCfgId
== NULL
) {
3397 // Return Current Setting when AltCfgId is NULL.
3399 Status
= OutputConfigBody (StringPtr
, &Result
);
3403 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
3405 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
3411 // Skip AltIdStr and &
3413 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
3414 Status
= OutputConfigBody (StringPtr
, &Result
);
3420 Status
= EFI_NOT_FOUND
;
3424 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
3426 // Copy the <ConfigHdr> and <ConfigBody>
3428 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
3429 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3430 if (*AltCfgResp
== NULL
) {
3431 Status
= EFI_OUT_OF_RESOURCES
;
3433 StrnCpy (*AltCfgResp
, HdrStart
, HdrEnd
- HdrStart
);
3434 StrCat (*AltCfgResp
, Result
);
3435 Status
= EFI_SUCCESS
;
3439 if (GuidStr
!= NULL
) {
3442 if (NameStr
!= NULL
) {
3445 if (PathStr
!= NULL
) {
3448 if (AltIdStr
!= NULL
) {
3449 FreePool (AltIdStr
);
3451 if (Result
!= NULL
) {