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 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
1737 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
1739 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
1740 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
1743 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
1744 (VOID
*) DevicePath
,
1748 Length
= StrLen (GuidStr
);
1749 Length
= Length
+ StrLen (NameStr
);
1750 Length
= Length
+ StrLen (PathStr
) + 1;
1751 ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1752 if (ConfigHdr
== NULL
) {
1753 Status
= EFI_OUT_OF_RESOURCES
;
1756 StrCpy (ConfigHdr
, GuidStr
);
1757 StrCat (ConfigHdr
, NameStr
);
1758 StrCat (ConfigHdr
, PathStr
);
1761 // Remove the last character L'&'
1763 *(ConfigHdr
+ StrLen (ConfigHdr
) - 1) = L
'\0';
1765 if (RequestBlockArray
== NULL
) {
1767 // Append VarStorageData BlockEntry into *Request string
1768 // Now support only one varstore in a form package.
1772 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
1773 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
1777 // Compute the length of the entire request starting with <ConfigHdr> and a
1780 Length
= StrLen (ConfigHdr
) + 1;
1782 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1784 // Add <BlockName> length for each Offset/Width pair
1786 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
1787 // | 8 | 4 | 7 | 4 |
1789 Length
= Length
+ (8 + 4 + 7 + 4);
1793 // Allocate buffer for the entire <ConfigRequest>
1795 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1796 if (FullConfigRequest
== NULL
) {
1799 StringPtr
= FullConfigRequest
;
1802 // Start with <ConfigHdr>
1804 StrCpy (StringPtr
, ConfigHdr
);
1805 StringPtr
+= StrLen (StringPtr
);
1808 // Loop through all the Offset/Width pairs and append them to ConfigRequest
1810 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1811 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1813 // Append &OFFSET=XXXX&WIDTH=YYYY\0
1817 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1818 L
"&OFFSET=%04X&WIDTH=%04X",
1822 StringPtr
+= StrLen (StringPtr
);
1825 // Set to the got full request string.
1827 HiiToLower (FullConfigRequest
);
1828 if (*Request
!= NULL
) {
1829 FreePool (*Request
);
1831 *Request
= FullConfigRequest
;
1835 // 4. Construct Default Value string in AltResp according to request element.
1836 // Go through all VarStorageData Entry and get the DefaultId array for each one
1837 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
1841 // Add length for <ConfigHdr> + '\0'
1843 Length
= StrLen (ConfigHdr
) + 1;
1845 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1846 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1848 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
1849 // |1| StrLen (ConfigHdr) | 8 | 4 |
1851 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
1853 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1854 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1855 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1856 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1857 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1859 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
1860 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
1862 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
1869 // Allocate buffer for the entire <DefaultAltCfgResp>
1871 DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1872 if (DefaultAltCfgResp
== NULL
) {
1875 StringPtr
= DefaultAltCfgResp
;
1878 // Start with <ConfigHdr>
1880 StrCpy (StringPtr
, ConfigHdr
);
1881 StringPtr
+= StrLen (StringPtr
);
1883 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1884 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1886 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
1887 // |1| StrLen (ConfigHdr) | 8 | 4 |
1891 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
1894 DefaultId
->DefaultName
1896 StringPtr
+= StrLen (StringPtr
);
1898 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1899 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1900 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1901 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1902 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1904 // Add <BlockConfig>
1905 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
1909 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
1910 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
1914 StringPtr
+= StrLen (StringPtr
);
1917 // Convert Value to a hex string in "%x" format
1918 // NOTE: This is in the opposite byte that GUID and PATH use
1920 Width
= BlockData
->Width
;
1921 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
1922 for (; Width
> 0; Width
--) {
1923 StringPtr
+= UnicodeValueToString (StringPtr
, PREFIX_ZERO
| RADIX_HEX
, TmpBuffer
[Width
- 1], 2);
1929 HiiToLower (DefaultAltCfgResp
);
1932 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.
1934 if (*AltCfgResp
!= NULL
) {
1935 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
1936 FreePool (DefaultAltCfgResp
);
1938 *AltCfgResp
= DefaultAltCfgResp
;
1942 if (RequestBlockArray
!= NULL
) {
1944 // Free Link Array RequestBlockArray
1946 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
1947 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1948 RemoveEntryList (&BlockData
->Entry
);
1949 FreePool (BlockData
);
1952 FreePool (RequestBlockArray
);
1955 if (VarStorageData
!= NULL
) {
1957 // Free link array VarStorageData
1959 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
1960 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1961 RemoveEntryList (&BlockData
->Entry
);
1963 // Free default value link array
1965 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
1966 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
1967 RemoveEntryList (&DefaultValueData
->Entry
);
1968 FreePool (DefaultValueData
);
1970 FreePool (BlockData
);
1972 FreePool (VarStorageData
);
1975 if (DefaultIdArray
!= NULL
) {
1977 // Free DefaultId Array
1979 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
1980 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
1981 RemoveEntryList (&DefaultId
->Entry
);
1982 FreePool (DefaultId
);
1984 FreePool (DefaultIdArray
);
1988 // Free the allocated string
1990 if (GuidStr
!= NULL
) {
1993 if (NameStr
!= NULL
) {
1996 if (PathStr
!= NULL
) {
1999 if (ConfigHdr
!= NULL
) {
2000 FreePool (ConfigHdr
);
2004 // Free Pacakge data
2006 if (HiiPackageList
!= NULL
) {
2007 FreePool (HiiPackageList
);
2014 This function allows a caller to extract the current configuration
2015 for one or more named elements from one or more drivers.
2017 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2019 @param Request A null-terminated Unicode string in
2020 <MultiConfigRequest> format.
2021 @param Progress On return, points to a character in the Request
2022 string. Points to the string's null terminator if
2023 request was successful. Points to the most recent
2024 & before the first failing name / value pair (or
2025 the beginning of the string if the failure is in
2026 the first name / value pair) if the request was
2028 @param Results Null-terminated Unicode string in
2029 <MultiConfigAltResp> format which has all values
2030 filled in for the names in the Request string.
2031 String to be allocated by the called function.
2033 @retval EFI_SUCCESS The Results string is filled with the values
2034 corresponding to all requested names.
2035 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2036 results that must be stored awaiting possible
2038 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
2039 Progress set to the "G" in "GUID" of the routing
2040 header that doesn't match. Note: There is no
2041 requirement that all routing data be validated
2042 before any configuration extraction.
2043 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
2044 parameter would result in this type of error. The
2045 Progress parameter is set to NULL.
2046 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
2047 before the error or the beginning of the string.
2048 @retval EFI_INVALID_PARAMETER Unknown name. Progress points to the & before the
2054 HiiConfigRoutingExtractConfig (
2055 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2056 IN CONST EFI_STRING Request
,
2057 OUT EFI_STRING
*Progress
,
2058 OUT EFI_STRING
*Results
2061 HII_DATABASE_PRIVATE_DATA
*Private
;
2062 EFI_STRING StringPtr
;
2063 EFI_STRING ConfigRequest
;
2065 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2066 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2069 HII_DATABASE_RECORD
*Database
;
2070 UINT8
*DevicePathPkg
;
2071 UINT8
*CurrentDevicePath
;
2072 EFI_HANDLE DriverHandle
;
2073 EFI_HII_HANDLE HiiHandle
;
2074 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2075 EFI_STRING AccessProgress
;
2076 EFI_STRING AccessResults
;
2077 EFI_STRING DefaultResults
;
2078 BOOLEAN FirstElement
;
2079 UINTN DevicePathLength
;
2081 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
2082 return EFI_INVALID_PARAMETER
;
2085 if (Request
== NULL
) {
2087 return EFI_INVALID_PARAMETER
;
2090 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2091 StringPtr
= Request
;
2092 *Progress
= StringPtr
;
2093 DefaultResults
= NULL
;
2094 ConfigRequest
= NULL
;
2095 Status
= EFI_SUCCESS
;
2096 AccessResults
= NULL
;
2100 // The first element of <MultiConfigRequest> should be
2101 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2103 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2104 return EFI_INVALID_PARAMETER
;
2107 FirstElement
= TRUE
;
2110 // Allocate a fix length of memory to store Results. Reallocate memory for
2111 // Results if this fix length is insufficient.
2113 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2114 if (*Results
== NULL
) {
2115 return EFI_OUT_OF_RESOURCES
;
2118 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2120 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
2121 // or most recent & before the error.
2123 if (StringPtr
== Request
) {
2124 *Progress
= StringPtr
;
2126 *Progress
= StringPtr
- 1;
2130 // Process each <ConfigRequest> of <MultiConfigRequest>
2132 Length
= CalculateConfigStringLen (StringPtr
);
2133 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2134 if (ConfigRequest
== NULL
) {
2135 Status
= EFI_OUT_OF_RESOURCES
;
2138 *(ConfigRequest
+ Length
) = 0;
2141 // Get the UEFI device path
2143 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
2144 if (EFI_ERROR (Status
)) {
2149 // Find driver which matches the routing data.
2151 DriverHandle
= NULL
;
2153 DevicePathLength
= GetDevicePathSize (DevicePath
);
2154 for (Link
= Private
->DatabaseList
.ForwardLink
;
2155 Link
!= &Private
->DatabaseList
;
2156 Link
= Link
->ForwardLink
2158 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2160 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2161 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2162 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2168 DriverHandle
= Database
->DriverHandle
;
2169 HiiHandle
= Database
->Handle
;
2176 // Try to find driver handle by device path.
2178 if (DriverHandle
== NULL
) {
2179 TempDevicePath
= DevicePath
;
2180 Status
= gBS
->LocateDevicePath (
2181 &gEfiDevicePathProtocolGuid
,
2185 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2187 // Routing data does not match any known driver.
2188 // Set Progress to the 'G' in "GUID" of the routing header.
2190 *Progress
= StringPtr
;
2191 Status
= EFI_NOT_FOUND
;
2197 // Check whether ConfigRequest contains request string OFFSET/WIDTH
2199 if ((HiiHandle
!= NULL
) && (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
)) {
2201 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
2203 Status
= GetFullStringFromHiiFormPackages (HiiHandle
, DevicePath
, &ConfigRequest
, &DefaultResults
);
2204 if (EFI_ERROR (Status
)) {
2210 // Call corresponding ConfigAccess protocol to extract settings
2212 Status
= gBS
->HandleProtocol (
2214 &gEfiHiiConfigAccessProtocolGuid
,
2215 (VOID
**) &ConfigAccess
2217 ASSERT_EFI_ERROR (Status
);
2219 Status
= ConfigAccess
->ExtractConfig (
2225 if (EFI_ERROR (Status
)) {
2227 // AccessProgress indicates the parsing progress on <ConfigRequest>.
2228 // Map it to the progress on <MultiConfigRequest> then return it.
2230 *Progress
= StrStr (StringPtr
, AccessProgress
);
2235 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2236 // which seperates the first <ConfigAltResp> and the following ones.
2238 ASSERT (*AccessProgress
== 0);
2241 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2243 if (HiiHandle
!= NULL
) {
2244 if (DefaultResults
== NULL
) {
2245 Status
= GetFullStringFromHiiFormPackages (HiiHandle
, DevicePath
, &ConfigRequest
, &AccessResults
);
2247 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2250 FreePool (DevicePath
);
2253 if (EFI_ERROR (Status
)) {
2258 // Free the allocated memory.
2260 if (DefaultResults
!= NULL
) {
2261 FreePool (DefaultResults
);
2262 DefaultResults
= NULL
;
2265 if (!FirstElement
) {
2266 Status
= AppendToMultiString (Results
, L
"&");
2267 ASSERT_EFI_ERROR (Status
);
2270 Status
= AppendToMultiString (Results
, AccessResults
);
2271 ASSERT_EFI_ERROR (Status
);
2273 FirstElement
= FALSE
;
2275 FreePool (AccessResults
);
2276 AccessResults
= NULL
;
2277 FreePool (ConfigRequest
);
2278 ConfigRequest
= NULL
;
2281 // Go to next <ConfigRequest> (skip '&').
2283 StringPtr
+= Length
;
2284 if (*StringPtr
== 0) {
2285 *Progress
= StringPtr
;
2293 if (EFI_ERROR (Status
)) {
2294 FreePool (*Results
);
2297 if (ConfigRequest
!= NULL
) {
2298 FreePool (ConfigRequest
);
2301 if (AccessResults
!= NULL
) {
2302 FreePool (AccessResults
);
2305 if (DefaultResults
!= NULL
) {
2306 FreePool (DefaultResults
);
2309 if (DevicePath
!= NULL
) {
2310 FreePool (DevicePath
);
2318 This function allows the caller to request the current configuration for the
2319 entirety of the current HII database and returns the data in a
2320 null-terminated Unicode string.
2322 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2324 @param Results Null-terminated Unicode string in
2325 <MultiConfigAltResp> format which has all values
2326 filled in for the names in the Request string.
2327 String to be allocated by the called function.
2328 De-allocation is up to the caller.
2330 @retval EFI_SUCCESS The Results string is filled with the values
2331 corresponding to all requested names.
2332 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2333 results that must be stored awaiting possible
2335 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
2336 parameter would result in this type of error.
2341 HiiConfigRoutingExportConfig (
2342 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2343 OUT EFI_STRING
*Results
2347 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2348 EFI_STRING AccessResults
;
2349 EFI_STRING Progress
;
2350 EFI_STRING ConfigRequest
;
2352 EFI_HANDLE
*ConfigAccessHandles
;
2353 UINTN NumberConfigAccessHandles
;
2354 BOOLEAN FirstElement
;
2355 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2356 EFI_HII_HANDLE HiiHandle
;
2357 EFI_STRING DefaultResults
;
2358 HII_DATABASE_PRIVATE_DATA
*Private
;
2360 HII_DATABASE_RECORD
*Database
;
2361 UINT8
*DevicePathPkg
;
2362 UINT8
*CurrentDevicePath
;
2363 UINTN DevicePathLength
;
2365 if (This
== NULL
|| Results
== NULL
) {
2366 return EFI_INVALID_PARAMETER
;
2369 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2372 // Allocate a fix length of memory to store Results. Reallocate memory for
2373 // Results if this fix length is insufficient.
2375 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2376 if (*Results
== NULL
) {
2377 return EFI_OUT_OF_RESOURCES
;
2380 NumberConfigAccessHandles
= 0;
2381 Status
= gBS
->LocateHandleBuffer (
2383 &gEfiHiiConfigAccessProtocolGuid
,
2385 &NumberConfigAccessHandles
,
2386 &ConfigAccessHandles
2388 if (EFI_ERROR (Status
)) {
2392 FirstElement
= TRUE
;
2394 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
2395 Status
= gBS
->HandleProtocol (
2396 ConfigAccessHandles
[Index
],
2397 &gEfiHiiConfigAccessProtocolGuid
,
2398 (VOID
**) &ConfigAccess
2400 if (EFI_ERROR (Status
)) {
2405 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
2409 ConfigRequest
= NULL
;
2410 DefaultResults
= NULL
;
2411 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
2412 DevicePathLength
= GetDevicePathSize (DevicePath
);
2413 if (DevicePath
!= NULL
) {
2414 for (Link
= Private
->DatabaseList
.ForwardLink
;
2415 Link
!= &Private
->DatabaseList
;
2416 Link
= Link
->ForwardLink
2418 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2419 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2420 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2421 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2427 HiiHandle
= Database
->Handle
;
2435 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2437 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
2438 Status
= GetFullStringFromHiiFormPackages (HiiHandle
, DevicePath
, &ConfigRequest
, &DefaultResults
);
2441 // Can't parse IFR data to get the request string and default string.
2443 if (EFI_ERROR (Status
)) {
2444 ConfigRequest
= NULL
;
2445 DefaultResults
= NULL
;
2448 Status
= ConfigAccess
->ExtractConfig (
2454 if (!EFI_ERROR (Status
)) {
2456 // Merge the default sting from IFR code into the got setting from driver.
2458 if (DefaultResults
!= NULL
) {
2459 MergeDefaultString (&AccessResults
, DefaultResults
);
2460 FreePool (DefaultResults
);
2464 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2465 // which seperates the first <ConfigAltResp> and the following ones.
2467 if (!FirstElement
) {
2468 Status
= AppendToMultiString (Results
, L
"&");
2469 ASSERT_EFI_ERROR (Status
);
2472 Status
= AppendToMultiString (Results
, AccessResults
);
2473 ASSERT_EFI_ERROR (Status
);
2475 FirstElement
= FALSE
;
2477 FreePool (AccessResults
);
2478 AccessResults
= NULL
;
2481 FreePool (ConfigAccessHandles
);
2488 This function processes the results of processing forms and routes it to the
2489 appropriate handlers or storage.
2491 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2493 @param Configuration A null-terminated Unicode string in
2494 <MulltiConfigResp> format.
2495 @param Progress A pointer to a string filled in with the offset of
2496 the most recent & before the first failing name /
2497 value pair (or the beginning of the string if the
2498 failure is in the first name / value pair) or the
2499 terminating NULL if all was successful.
2501 @retval EFI_SUCCESS The results have been distributed or are awaiting
2503 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2504 results that must be stored awaiting possible
2506 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
2507 would result in this type of error.
2508 @retval EFI_NOT_FOUND Target for the specified routing data was not
2514 HiiConfigRoutingRouteConfig (
2515 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2516 IN CONST EFI_STRING Configuration
,
2517 OUT EFI_STRING
*Progress
2520 HII_DATABASE_PRIVATE_DATA
*Private
;
2521 EFI_STRING StringPtr
;
2522 EFI_STRING ConfigResp
;
2525 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2526 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2528 HII_DATABASE_RECORD
*Database
;
2529 UINT8
*DevicePathPkg
;
2530 UINT8
*CurrentDevicePath
;
2531 EFI_HANDLE DriverHandle
;
2532 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2533 EFI_STRING AccessProgress
;
2534 UINTN DevicePathLength
;
2536 if (This
== NULL
|| Progress
== NULL
) {
2537 return EFI_INVALID_PARAMETER
;
2540 if (Configuration
== NULL
) {
2542 return EFI_INVALID_PARAMETER
;
2545 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2546 StringPtr
= Configuration
;
2547 *Progress
= StringPtr
;
2550 // The first element of <MultiConfigResp> should be
2551 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2553 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2554 return EFI_INVALID_PARAMETER
;
2557 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2559 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
2560 // or most recent & before the error.
2562 if (StringPtr
== Configuration
) {
2563 *Progress
= StringPtr
;
2565 *Progress
= StringPtr
- 1;
2569 // Process each <ConfigResp> of <MultiConfigResp>
2571 Length
= CalculateConfigStringLen (StringPtr
);
2572 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2573 if (ConfigResp
== NULL
) {
2574 return EFI_OUT_OF_RESOURCES
;
2577 // Append '\0' to the end of ConfigRequest
2579 *(ConfigResp
+ Length
) = 0;
2582 // Get the UEFI device path
2584 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
2585 if (EFI_ERROR (Status
)) {
2586 FreePool (ConfigResp
);
2591 // Find driver which matches the routing data.
2593 DriverHandle
= NULL
;
2594 DevicePathLength
= GetDevicePathSize (DevicePath
);
2595 for (Link
= Private
->DatabaseList
.ForwardLink
;
2596 Link
!= &Private
->DatabaseList
;
2597 Link
= Link
->ForwardLink
2599 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2601 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2602 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2603 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2609 DriverHandle
= Database
->DriverHandle
;
2616 // Try to find driver handle by device path.
2618 if (DriverHandle
== NULL
) {
2619 TempDevicePath
= DevicePath
;
2620 Status
= gBS
->LocateDevicePath (
2621 &gEfiDevicePathProtocolGuid
,
2625 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2627 // Routing data does not match any known driver.
2628 // Set Progress to the 'G' in "GUID" of the routing header.
2630 FreePool (DevicePath
);
2631 *Progress
= StringPtr
;
2632 FreePool (ConfigResp
);
2633 return EFI_NOT_FOUND
;
2637 FreePool (DevicePath
);
2640 // Call corresponding ConfigAccess protocol to route settings
2642 Status
= gBS
->HandleProtocol (
2644 &gEfiHiiConfigAccessProtocolGuid
,
2645 (VOID
**) &ConfigAccess
2647 ASSERT_EFI_ERROR (Status
);
2649 Status
= ConfigAccess
->RouteConfig (
2655 if (EFI_ERROR (Status
)) {
2657 // AccessProgress indicates the parsing progress on <ConfigResp>.
2658 // Map it to the progress on <MultiConfigResp> then return it.
2660 *Progress
= StrStr (StringPtr
, AccessProgress
);
2662 FreePool (ConfigResp
);
2666 FreePool (ConfigResp
);
2670 // Go to next <ConfigResp> (skip '&').
2672 StringPtr
+= Length
;
2673 if (*StringPtr
== 0) {
2674 *Progress
= StringPtr
;
2687 This helper function is to be called by drivers to map configuration data
2688 stored in byte array ("block") formats such as UEFI Variables into current
2689 configuration strings.
2691 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2693 @param ConfigRequest A null-terminated Unicode string in
2694 <ConfigRequest> format.
2695 @param Block Array of bytes defining the block's configuration.
2696 @param BlockSize Length in bytes of Block.
2697 @param Config Filled-in configuration string. String allocated
2698 by the function. Returned only if call is
2699 successful. It is <ConfigResp> string format.
2700 @param Progress A pointer to a string filled in with the offset of
2701 the most recent & before the first failing
2702 name/value pair (or the beginning of the string if
2703 the failure is in the first name / value pair) or
2704 the terminating NULL if all was successful.
2706 @retval EFI_SUCCESS The request succeeded. Progress points to the null
2707 terminator at the end of the ConfigRequest
2709 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
2710 points to the first character of ConfigRequest.
2711 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
2712 Block parameter would result in this type of
2713 error. Progress points to the first character of
2715 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
2716 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
2717 Block is left updated and Progress points at
2718 the "&" preceding the first non-<BlockName>.
2724 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2725 IN CONST EFI_STRING ConfigRequest
,
2726 IN CONST UINT8
*Block
,
2727 IN CONST UINTN BlockSize
,
2728 OUT EFI_STRING
*Config
,
2729 OUT EFI_STRING
*Progress
2732 HII_DATABASE_PRIVATE_DATA
*Private
;
2733 EFI_STRING StringPtr
;
2741 EFI_STRING ValueStr
;
2742 EFI_STRING ConfigElement
;
2747 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
2748 return EFI_INVALID_PARAMETER
;
2751 if (Block
== NULL
|| ConfigRequest
== NULL
) {
2752 *Progress
= ConfigRequest
;
2753 return EFI_INVALID_PARAMETER
;
2757 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2758 ASSERT (Private
!= NULL
);
2760 StringPtr
= ConfigRequest
;
2763 ConfigElement
= NULL
;
2766 // Allocate a fix length of memory to store Results. Reallocate memory for
2767 // Results if this fix length is insufficient.
2769 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2770 if (*Config
== NULL
) {
2771 return EFI_OUT_OF_RESOURCES
;
2777 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2778 *Progress
= StringPtr
;
2779 Status
= EFI_INVALID_PARAMETER
;
2782 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
2785 if (*StringPtr
== 0) {
2786 *Progress
= StringPtr
;
2787 Status
= EFI_INVALID_PARAMETER
;
2791 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
2794 if (*StringPtr
== 0) {
2795 *Progress
= StringPtr
;
2796 Status
= EFI_INVALID_PARAMETER
;
2805 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
2807 Length
= StringPtr
- ConfigRequest
;
2808 CopyMem (*Config
, ConfigRequest
, Length
* sizeof (CHAR16
));
2811 // Parse each <RequestElement> if exists
2812 // Only <BlockName> format is supported by this help function.
2813 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
2815 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
2817 // Back up the header of one <BlockName>
2821 StringPtr
+= StrLen (L
"OFFSET=");
2825 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2826 if (Status
== EFI_OUT_OF_RESOURCES
) {
2827 *Progress
= ConfigRequest
;
2834 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2836 FreePool (TmpBuffer
);
2838 StringPtr
+= Length
;
2839 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
2840 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
2841 Status
= EFI_INVALID_PARAMETER
;
2844 StringPtr
+= StrLen (L
"&WIDTH=");
2849 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2850 if (Status
== EFI_OUT_OF_RESOURCES
) {
2851 *Progress
= ConfigRequest
;
2858 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2860 FreePool (TmpBuffer
);
2862 StringPtr
+= Length
;
2863 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
2864 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
2865 Status
= EFI_INVALID_PARAMETER
;
2870 // Calculate Value and convert it to hex string.
2872 if (Offset
+ Width
> BlockSize
) {
2873 *Progress
= StringPtr
;
2874 Status
= EFI_DEVICE_ERROR
;
2878 Value
= (UINT8
*) AllocateZeroPool (Width
);
2879 if (Value
== NULL
) {
2880 *Progress
= ConfigRequest
;
2881 Status
= EFI_OUT_OF_RESOURCES
;
2885 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
2887 Length
= Width
* 2 + 1;
2888 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2889 if (ValueStr
== NULL
) {
2890 *Progress
= ConfigRequest
;
2891 Status
= EFI_OUT_OF_RESOURCES
;
2895 TemString
= ValueStr
;
2896 TemBuffer
= Value
+ Width
- 1;
2897 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
2898 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
2905 // Build a ConfigElement
2907 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
2908 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2909 if (ConfigElement
== NULL
) {
2910 Status
= EFI_OUT_OF_RESOURCES
;
2913 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
2914 if (*StringPtr
== 0) {
2915 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
2917 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
2918 StrCat (ConfigElement
, L
"VALUE=");
2919 StrCat (ConfigElement
, ValueStr
);
2921 AppendToMultiString (Config
, ConfigElement
);
2923 FreePool (ConfigElement
);
2924 FreePool (ValueStr
);
2925 ConfigElement
= NULL
;
2929 // If '\0', parsing is finished. Otherwise skip '&' to continue
2931 if (*StringPtr
== 0) {
2934 AppendToMultiString (Config
, L
"&");
2939 if (*StringPtr
!= 0) {
2940 *Progress
= StringPtr
- 1;
2941 Status
= EFI_INVALID_PARAMETER
;
2945 HiiToLower (*Config
);
2946 *Progress
= StringPtr
;
2951 if (ValueStr
!= NULL
) {
2952 FreePool (ValueStr
);
2954 if (Value
!= NULL
) {
2957 if (ConfigElement
!= NULL
) {
2958 FreePool (ConfigElement
);
2967 This helper function is to be called by drivers to map configuration strings
2968 to configurations stored in byte array ("block") formats such as UEFI Variables.
2970 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2972 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
2973 format. It can be ConfigAltResp format string.
2974 @param Block A possibly null array of bytes representing the
2975 current block. Only bytes referenced in the
2976 ConfigResp string in the block are modified. If
2977 this parameter is null or if the *BlockSize
2978 parameter is (on input) shorter than required by
2979 the Configuration string, only the BlockSize
2980 parameter is updated and an appropriate status
2981 (see below) is returned.
2982 @param BlockSize The length of the Block in units of UINT8. On
2983 input, this is the size of the Block. On output,
2984 if successful, contains the index of the last
2985 modified byte in the Block.
2986 @param Progress On return, points to an element of the ConfigResp
2987 string filled in with the offset of the most
2988 recent '&' before the first failing name / value
2989 pair (or the beginning of the string if the
2990 failure is in the first name / value pair) or the
2991 terminating NULL if all was successful.
2993 @retval EFI_SUCCESS The request succeeded. Progress points to the null
2994 terminator at the end of the ConfigResp string.
2995 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
2996 points to the first character of ConfigResp.
2997 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
2998 Block parameter would result in this type of
2999 error. Progress points to the first character of
3001 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
3002 value pair. Block is left updated and
3003 Progress points at the '&' preceding the first
3010 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3011 IN CONST EFI_STRING ConfigResp
,
3012 IN OUT UINT8
*Block
,
3013 IN OUT UINTN
*BlockSize
,
3014 OUT EFI_STRING
*Progress
3017 HII_DATABASE_PRIVATE_DATA
*Private
;
3018 EFI_STRING StringPtr
;
3027 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
3028 return EFI_INVALID_PARAMETER
;
3031 if (ConfigResp
== NULL
|| Block
== NULL
) {
3032 *Progress
= ConfigResp
;
3033 return EFI_INVALID_PARAMETER
;
3036 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
3037 ASSERT (Private
!= NULL
);
3039 StringPtr
= ConfigResp
;
3040 BufferSize
= *BlockSize
;
3046 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3047 *Progress
= StringPtr
;
3048 Status
= EFI_INVALID_PARAMETER
;
3051 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
3054 if (*StringPtr
== 0) {
3055 *Progress
= StringPtr
;
3056 Status
= EFI_INVALID_PARAMETER
;
3060 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
3063 if (*StringPtr
== 0) {
3064 *Progress
= StringPtr
;
3065 Status
= EFI_INVALID_PARAMETER
;
3074 // Parse each <ConfigElement> if exists
3075 // Only <BlockConfig> format is supported by this help function.
3076 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
3078 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
3079 StringPtr
+= StrLen (L
"OFFSET=");
3083 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3084 if (EFI_ERROR (Status
)) {
3085 *Progress
= ConfigResp
;
3092 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3094 FreePool (TmpBuffer
);
3096 StringPtr
+= Length
;
3097 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3098 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
3099 Status
= EFI_INVALID_PARAMETER
;
3102 StringPtr
+= StrLen (L
"&WIDTH=");
3107 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3108 if (Status
== EFI_OUT_OF_RESOURCES
) {
3109 *Progress
= ConfigResp
;
3116 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3118 FreePool (TmpBuffer
);
3120 StringPtr
+= Length
;
3121 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
3122 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
3123 Status
= EFI_INVALID_PARAMETER
;
3126 StringPtr
+= StrLen (L
"&VALUE=");
3131 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
3132 if (EFI_ERROR (Status
)) {
3133 *Progress
= ConfigResp
;
3137 StringPtr
+= Length
;
3138 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3139 *Progress
= StringPtr
- Length
- 7;
3140 Status
= EFI_INVALID_PARAMETER
;
3145 // Update the Block with configuration info
3148 if (Offset
+ Width
> BufferSize
) {
3149 return EFI_DEVICE_ERROR
;
3152 CopyMem (Block
+ Offset
, Value
, Width
);
3153 *BlockSize
= Offset
+ Width
- 1;
3159 // If '\0', parsing is finished. Otherwise skip '&' to continue
3161 if (*StringPtr
== 0) {
3169 // The input string is ConfigAltResp format.
3171 if ((*StringPtr
!= 0) && (StrnCmp (StringPtr
, L
"&GUID=", StrLen (L
"&GUID=")) != 0)) {
3172 *Progress
= StringPtr
- 1;
3173 Status
= EFI_INVALID_PARAMETER
;
3177 *Progress
= StringPtr
;
3182 if (Value
!= NULL
) {
3190 This helper function is to be called by drivers to extract portions of
3191 a larger configuration string.
3193 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3195 @param Configuration A null-terminated Unicode string in
3196 <MultiConfigAltResp> format. It is <ConfigAltResp> format.
3197 @param Guid A pointer to the GUID value to search for in the
3198 routing portion of the ConfigResp string when
3199 retrieving the requested data. If Guid is NULL,
3200 then all GUID values will be searched for.
3201 @param Name A pointer to the NAME value to search for in the
3202 routing portion of the ConfigResp string when
3203 retrieving the requested data. If Name is NULL,
3204 then all Name values will be searched for.
3205 @param DevicePath A pointer to the PATH value to search for in the
3206 routing portion of the ConfigResp string when
3207 retrieving the requested data. If DevicePath is
3208 NULL, then all DevicePath values will be searched
3210 @param AltCfgId A pointer to the ALTCFG value to search for in the
3211 routing portion of the ConfigResp string when
3212 retrieving the requested data. If this parameter
3213 is NULL, then the current setting will be
3215 @param AltCfgResp A pointer to a buffer which will be allocated by
3216 the function which contains the retrieved string
3217 as requested. This buffer is only allocated if
3218 the call was successful. It is <ConfigResp> format.
3220 @retval EFI_SUCCESS The request succeeded. The requested data was
3221 extracted and placed in the newly allocated
3223 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
3224 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
3225 @retval EFI_NOT_FOUND Target for the specified routing data was not
3232 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3233 IN CONST EFI_STRING Configuration
,
3234 IN CONST EFI_GUID
*Guid
,
3235 IN CONST EFI_STRING Name
,
3236 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3237 IN CONST UINT16
*AltCfgId
,
3238 OUT EFI_STRING
*AltCfgResp
3242 EFI_STRING StringPtr
;
3243 EFI_STRING HdrStart
;
3250 EFI_STRING AltIdStr
;
3267 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
3268 return EFI_INVALID_PARAMETER
;
3271 StringPtr
= Configuration
;
3272 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3273 return EFI_INVALID_PARAMETER
;
3277 // Generate the sub string for later matching.
3279 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
3282 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
3283 (VOID
*) DevicePath
,
3287 if (AltCfgId
!= NULL
) {
3288 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
3291 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
3293 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
3296 while (*StringPtr
!= 0) {
3298 // Try to match the GUID
3301 TmpPtr
= StrStr (StringPtr
, GuidStr
);
3302 if (TmpPtr
== NULL
) {
3303 Status
= EFI_NOT_FOUND
;
3309 // Jump to <NameHdr>
3312 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
3314 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
3315 if (StringPtr
== NULL
) {
3316 Status
= EFI_NOT_FOUND
;
3324 // Try to match the NAME
3326 if (GuidFlag
&& !NameFlag
) {
3327 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
3331 // Jump to <PathHdr>
3334 StringPtr
+= StrLen (NameStr
);
3336 StringPtr
= StrStr (StringPtr
, L
"PATH=");
3337 if (StringPtr
== NULL
) {
3338 Status
= EFI_NOT_FOUND
;
3347 // Try to match the DevicePath
3349 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
3350 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
3355 // Jump to '&' before <DescHdr> or <ConfigBody>
3357 if (DevicePath
!= NULL
) {
3358 StringPtr
+= StrLen (PathStr
);
3360 StringPtr
= StrStr (StringPtr
, L
"&");
3361 if (StringPtr
== NULL
) {
3362 Status
= EFI_NOT_FOUND
;
3373 // Try to match the AltCfgId
3375 if (GuidFlag
&& NameFlag
&& PathFlag
) {
3376 if (AltCfgId
== NULL
) {
3378 // Return Current Setting when AltCfgId is NULL.
3380 Status
= OutputConfigBody (StringPtr
, &Result
);
3384 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
3386 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
3392 // Skip AltIdStr and &
3394 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
3395 Status
= OutputConfigBody (StringPtr
, &Result
);
3401 Status
= EFI_NOT_FOUND
;
3405 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
3407 // Copy the <ConfigHdr> and <ConfigBody>
3409 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
3410 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3411 if (*AltCfgResp
== NULL
) {
3412 Status
= EFI_OUT_OF_RESOURCES
;
3414 StrnCpy (*AltCfgResp
, HdrStart
, HdrEnd
- HdrStart
);
3415 StrCat (*AltCfgResp
, Result
);
3416 Status
= EFI_SUCCESS
;
3420 if (GuidStr
!= NULL
) {
3423 if (NameStr
!= NULL
) {
3426 if (PathStr
!= NULL
) {
3429 if (AltIdStr
!= NULL
) {
3430 FreePool (AltIdStr
);
3432 if (Result
!= NULL
) {