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 if (*AltCfgResp
== NULL
) {
581 FreePool (AltConfigHdr
);
582 return EFI_OUT_OF_RESOURCES
;
584 StrCat (*AltCfgResp
, StringPtrDefault
);
587 TempChar
= *StringPtrEnd
;
588 *StringPtrEnd
= L
'\0';
589 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
591 SizeAltCfgResp
+ StrSize (StringPtrDefault
),
592 (VOID
*) (*AltCfgResp
)
594 StrCat (*AltCfgResp
, StringPtrDefault
);
595 *StringPtrEnd
= TempChar
;
600 // Find next AltCfg String
602 *(AltConfigHdr
+ HeaderLength
) = L
'\0';
603 StringPtrDefault
= StrStr (StringPtrDefault
+ 1, AltConfigHdr
);
606 FreePool (AltConfigHdr
);
611 This function finds the matched DefaultName for the input DefaultId
613 @param DefaultIdArray Array stores the map table between DefaultId and DefaultName.
614 @param VarDefaultId Default Id
615 @param VarDefaultName Default Name string ID for the input default ID.
617 @retval EFI_SUCCESS The mapped default name string ID is found.
618 @retval EFI_NOT_FOUND The mapped default name string ID is not found.
622 IN IFR_DEFAULT_DATA
*DefaultIdArray
,
623 IN UINT16 VarDefaultId
,
624 OUT EFI_STRING_ID
*VarDefaultName
628 IFR_DEFAULT_DATA
*DefaultData
;
630 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
631 DefaultData
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
632 if (DefaultData
->DefaultId
== VarDefaultId
) {
633 *VarDefaultName
= DefaultData
->DefaultName
;
638 return EFI_NOT_FOUND
;
642 This function inserts new DefaultValueData into the BlockData DefaultValue array.
644 @param BlockData The BlockData is updated to add new default value.
645 @param DefaultValueData The DefaultValue is added.
650 IN IFR_BLOCK_DATA
*BlockData
,
651 IN IFR_DEFAULT_DATA
*DefaultValueData
655 IFR_DEFAULT_DATA
*DefaultValueArray
;
657 for (Link
= BlockData
->DefaultValueEntry
.ForwardLink
; Link
!= &BlockData
->DefaultValueEntry
; Link
= Link
->ForwardLink
) {
658 DefaultValueArray
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
659 if (DefaultValueArray
->DefaultId
== DefaultValueData
->DefaultId
) {
661 // Update the default value array in BlockData.
663 DefaultValueArray
->Value
= DefaultValueData
->Value
;
664 FreePool (DefaultValueData
);
666 } else if (DefaultValueArray
->DefaultId
> DefaultValueData
->DefaultId
) {
668 // Insert new default value data in the front of this default value array.
670 InsertTailList (Link
, &DefaultValueData
->Entry
);
676 // Insert new default value data in tail.
678 InsertTailList (Link
, &DefaultValueData
->Entry
);
683 This function inserts new BlockData into the block link
685 @param BlockLink The list entry points to block array.
686 @param BlockData The point to BlockData is added.
691 IN LIST_ENTRY
*BlockLink
,
692 IN IFR_BLOCK_DATA
**BlockData
696 IFR_BLOCK_DATA
*BlockArray
;
697 IFR_BLOCK_DATA
*BlockSingleData
;
699 BlockSingleData
= *BlockData
;
702 // Insert block data in its Offset and Width order.
704 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
705 BlockArray
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
706 if (BlockArray
->Offset
== BlockSingleData
->Offset
) {
707 if (BlockArray
->Width
> BlockSingleData
->Width
) {
709 // Insert this block data in the front of block array
711 InsertTailList (Link
, &BlockSingleData
->Entry
);
715 if (BlockArray
->Width
== BlockSingleData
->Width
) {
717 // The same block array has been added.
719 FreePool (BlockSingleData
);
720 *BlockData
= BlockArray
;
723 } else if (BlockArray
->Offset
> BlockSingleData
->Offset
) {
725 // Insert new block data in the front of block array
727 InsertTailList (Link
, &BlockSingleData
->Entry
);
733 // Add new block data into the tail.
735 InsertTailList (Link
, &BlockSingleData
->Entry
);
740 This function checks VarOffset and VarWidth is in the block range.
742 @param BlockArray The block array is to be checked.
743 @param VarOffset Offset of var to the structure
744 @param VarWidth Width of var.
746 @retval TRUE This Var is in the block range.
747 @retval FALSE This Var is not in the block range.
751 IN IFR_BLOCK_DATA
*RequestBlockArray
,
757 IFR_BLOCK_DATA
*BlockData
;
760 // No Request Block array, all vars are got.
762 if (RequestBlockArray
== NULL
) {
767 // Check the input var is in the request block range.
769 for (Link
= RequestBlockArray
->Entry
.ForwardLink
; Link
!= &RequestBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
770 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
771 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
780 This function parses Form Package to get the block array and the default
781 value array according to the request ConfigHdr.
783 @param Package Pointer to the form package data.
784 @param PackageLength Length of the pacakge.
785 @param ConfigHdr Request string ConfigHdr. If it is NULL,
786 the first found varstore will be as ConfigHdr.
787 @param RequestBlockArray The block array is retrieved from the request string.
788 @param VarStorageData VarStorage structure contains the got block and default value.
789 @param PIfrDefaultIdArray Point to the got default id and default name array.
791 @retval EFI_SUCCESS The block array and the default value array are got.
792 @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges
794 @retval EFI_OUT_OF_RESOURCES No enough memory.
800 IN UINT32 PackageLenth
,
801 IN EFI_STRING ConfigHdr
,
802 IN IFR_BLOCK_DATA
*RequestBlockArray
,
803 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
804 OUT IFR_DEFAULT_DATA
*DefaultIdArray
809 EFI_IFR_VARSTORE
*IfrVarStore
;
810 EFI_IFR_OP_HEADER
*IfrOpHdr
;
811 EFI_IFR_ONE_OF
*IfrOneOf
;
812 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
813 EFI_IFR_DEFAULT
*IfrDefault
;
814 EFI_IFR_ORDERED_LIST
*IfrOrderedList
;
815 EFI_IFR_CHECKBOX
*IfrCheckBox
;
816 EFI_IFR_PASSWORD
*IfrPassword
;
817 EFI_IFR_STRING
*IfrString
;
818 IFR_DEFAULT_DATA
*DefaultData
;
819 IFR_BLOCK_DATA
*BlockData
;
820 CHAR16
*VarStoreName
;
823 EFI_STRING_ID VarDefaultName
;
831 Status
= EFI_SUCCESS
;
839 // Go through the form package to parse OpCode one by one.
841 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
842 while (IfrOffset
< PackageLenth
) {
843 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (Package
+ IfrOffset
);
845 switch (IfrOpHdr
->OpCode
) {
846 case EFI_IFR_VARSTORE_OP
:
848 // VarStore is found. Don't need to search any more.
850 if (VarStorageData
->Size
!= 0) {
855 // Get the requied varstore information
856 // Add varstore by Guid and Name in ConfigHdr
857 // Make sure Offset is in varstore size and varstoreid
859 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
860 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
) * sizeof (CHAR16
));
861 if (VarStoreName
== NULL
) {
862 Status
= EFI_OUT_OF_RESOURCES
;
865 AsciiStrToUnicodeStr ((CHAR8
*) IfrVarStore
->Name
, VarStoreName
);
867 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &IfrVarStore
->Guid
, 1, &GuidStr
);
868 GenerateSubStr (L
"NAME=", StrLen (VarStoreName
) * sizeof (CHAR16
), (VOID
*) VarStoreName
, 2, &NameStr
);
869 LengthString
= StrLen (GuidStr
);
870 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
871 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
872 if (TempStr
== NULL
) {
875 FreePool (VarStoreName
);
876 Status
= EFI_OUT_OF_RESOURCES
;
879 StrCpy (TempStr
, GuidStr
);
880 StrCat (TempStr
, NameStr
);
881 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
883 // Find the matched VarStore
885 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
);
886 VarStorageData
->VarStoreId
= IfrVarStore
->VarStoreId
;
887 VarStorageData
->Size
= IfrVarStore
->Size
;
888 VarStorageData
->Name
= VarStoreName
;
891 // No found, free the allocated memory
893 FreePool (VarStoreName
);
896 // Free alllocated temp string.
903 case EFI_IFR_DEFAULTSTORE_OP
:
905 // Add new the map between default id and default name.
907 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
908 if (DefaultData
== NULL
) {
909 Status
= EFI_OUT_OF_RESOURCES
;
912 DefaultData
->DefaultId
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
;
913 DefaultData
->DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
914 InsertTailList (&DefaultIdArray
->Entry
, &DefaultData
->Entry
);
918 case EFI_IFR_FORM_OP
:
920 // No matched varstore is found and directly return.
922 if (VarStorageData
->Size
== 0) {
923 Status
= EFI_SUCCESS
;
928 case EFI_IFR_ONE_OF_OP
:
929 case EFI_IFR_NUMERIC_OP
:
931 // Numeric and OneOf has the same opcode structure.
935 // Numeric and OneOf question is not in IFR Form. This IFR form is not valid.
937 if (VarStorageData
->Size
== 0) {
938 Status
= EFI_INVALID_PARAMETER
;
942 // Check whether this question is for the requested varstore.
944 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
945 if (IfrOneOf
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
950 // Get Offset/Width by Question header and OneOf Flags
952 VarOffset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
953 VarWidth
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
955 // Check whether this question is in requested block array.
957 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
959 // This question is not in the requested string. Skip it.
965 // Check this var question is in the var storage
967 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
968 Status
= EFI_INVALID_PARAMETER
;
975 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
976 if (BlockData
== NULL
) {
977 Status
= EFI_OUT_OF_RESOURCES
;
980 BlockData
->Offset
= VarOffset
;
981 BlockData
->Width
= VarWidth
;
982 BlockData
->QuestionId
= IfrOneOf
->Question
.QuestionId
;
983 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
984 BlockData
->Scope
= IfrOpHdr
->Scope
;
985 InitializeListHead (&BlockData
->DefaultValueEntry
);
987 // Add Block Data into VarStorageData BlockEntry
989 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
992 case EFI_IFR_ORDERED_LIST_OP
:
994 // offset by question header
995 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type
996 // no default value and default id, how to define its default value?
1000 // OrderedList question is not in IFR Form. This IFR form is not valid.
1002 if (VarStorageData
->Size
== 0) {
1003 Status
= EFI_INVALID_PARAMETER
;
1007 // Check whether this question is for the requested varstore.
1009 IfrOrderedList
= (EFI_IFR_ORDERED_LIST
*) IfrOpHdr
;
1010 if (IfrOrderedList
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1015 // Get Offset/Width by Question header and OneOf Flags
1017 VarOffset
= IfrOrderedList
->Question
.VarStoreInfo
.VarOffset
;
1018 VarWidth
= IfrOrderedList
->MaxContainers
;
1021 // Check whether this question is in requested block array.
1023 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1025 // This question is not in the requested string. Skip it.
1031 // Check this var question is in the var storage
1033 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1034 Status
= EFI_INVALID_PARAMETER
;
1041 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1042 if (BlockData
== NULL
) {
1043 Status
= EFI_OUT_OF_RESOURCES
;
1046 BlockData
->Offset
= VarOffset
;
1047 BlockData
->Width
= VarWidth
;
1048 BlockData
->QuestionId
= IfrOrderedList
->Question
.QuestionId
;
1049 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1050 BlockData
->Scope
= IfrOpHdr
->Scope
;
1051 InitializeListHead (&BlockData
->DefaultValueEntry
);
1054 // Add Block Data into VarStorageData BlockEntry
1056 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1059 case EFI_IFR_CHECKBOX_OP
:
1061 // EFI_IFR_DEFAULT_OP
1062 // offset by question header
1063 // width is 1 sizeof (BOOLEAN)
1064 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.
1065 // value by DefaultOption
1066 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
1070 // CheckBox question is not in IFR Form. This IFR form is not valid.
1072 if (VarStorageData
->Size
== 0) {
1073 Status
= EFI_INVALID_PARAMETER
;
1077 // Check whether this question is for the requested varstore.
1079 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1080 if (IfrCheckBox
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1085 // Get Offset/Width by Question header and OneOf Flags
1087 VarOffset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1088 VarWidth
= sizeof (BOOLEAN
);
1091 // Check whether this question is in requested block array.
1093 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1095 // This question is not in the requested string. Skip it.
1101 // Check this var question is in the var storage
1103 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1104 Status
= EFI_INVALID_PARAMETER
;
1111 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1112 if (BlockData
== NULL
) {
1113 Status
= EFI_OUT_OF_RESOURCES
;
1116 BlockData
->Offset
= VarOffset
;
1117 BlockData
->Width
= VarWidth
;
1118 BlockData
->QuestionId
= IfrCheckBox
->Question
.QuestionId
;
1119 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1120 BlockData
->Scope
= IfrOpHdr
->Scope
;
1121 InitializeListHead (&BlockData
->DefaultValueEntry
);
1123 // Add Block Data into VarStorageData BlockEntry
1125 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1128 // Add default value by CheckBox Flags
1130 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) == EFI_IFR_CHECKBOX_DEFAULT
) {
1132 // Set standard ID to Manufacture ID and Get DefaultName String ID
1134 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1135 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1136 if (EFI_ERROR (Status
)) {
1140 // Prepare new DefaultValue
1142 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1143 if (DefaultData
== NULL
) {
1144 Status
= EFI_OUT_OF_RESOURCES
;
1147 DefaultData
->DefaultId
= VarDefaultId
;
1148 DefaultData
->DefaultName
= VarDefaultName
;
1149 DefaultData
->Value
= 1;
1151 // Add DefaultValue into current BlockData
1153 InsertDefaultValue (BlockData
, DefaultData
);
1156 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) == EFI_IFR_CHECKBOX_DEFAULT_MFG
) {
1158 // Set standard ID to Manufacture ID and Get DefaultName String ID
1160 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1161 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1162 if (EFI_ERROR (Status
)) {
1166 // Prepare new DefaultValue
1168 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1169 if (DefaultData
== NULL
) {
1170 Status
= EFI_OUT_OF_RESOURCES
;
1173 DefaultData
->DefaultId
= VarDefaultId
;
1174 DefaultData
->DefaultName
= VarDefaultName
;
1175 DefaultData
->Value
= 1;
1177 // Add DefaultValue into current BlockData
1179 InsertDefaultValue (BlockData
, DefaultData
);
1183 case EFI_IFR_STRING_OP
:
1185 // offset by question header
1186 // width MaxSize * sizeof (CHAR16)
1187 // no default value, only block array
1191 // String question is not in IFR Form. This IFR form is not valid.
1193 if (VarStorageData
->Size
== 0) {
1194 Status
= EFI_INVALID_PARAMETER
;
1198 // Check whether this question is for the requested varstore.
1200 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1201 if (IfrString
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1206 // Get Offset/Width by Question header and OneOf Flags
1208 VarOffset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1209 VarWidth
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1212 // Check whether this question is in requested block array.
1214 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1216 // This question is not in the requested string. Skip it.
1222 // Check this var question is in the var storage
1224 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1225 Status
= EFI_INVALID_PARAMETER
;
1232 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1233 if (BlockData
== NULL
) {
1234 Status
= EFI_OUT_OF_RESOURCES
;
1237 BlockData
->Offset
= VarOffset
;
1238 BlockData
->Width
= VarWidth
;
1239 BlockData
->QuestionId
= IfrString
->Question
.QuestionId
;
1240 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1241 InitializeListHead (&BlockData
->DefaultValueEntry
);
1244 // Add Block Data into VarStorageData BlockEntry
1246 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1249 // No default value for string.
1254 case EFI_IFR_PASSWORD_OP
:
1256 // offset by question header
1257 // width MaxSize * sizeof (CHAR16)
1258 // no default value, only block array
1262 // Password question is not in IFR Form. This IFR form is not valid.
1264 if (VarStorageData
->Size
== 0) {
1265 Status
= EFI_INVALID_PARAMETER
;
1269 // Check whether this question is for the requested varstore.
1271 IfrPassword
= (EFI_IFR_PASSWORD
*) IfrOpHdr
;
1272 if (IfrPassword
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1277 // Get Offset/Width by Question header and OneOf Flags
1279 VarOffset
= IfrPassword
->Question
.VarStoreInfo
.VarOffset
;
1280 VarWidth
= (UINT16
) (IfrPassword
->MaxSize
* sizeof (UINT16
));
1283 // Check whether this question is in requested block array.
1285 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1287 // This question is not in the requested string. Skip it.
1293 // Check this var question is in the var storage
1295 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1296 Status
= EFI_INVALID_PARAMETER
;
1303 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1304 if (BlockData
== NULL
) {
1305 Status
= EFI_OUT_OF_RESOURCES
;
1308 BlockData
->Offset
= VarOffset
;
1309 BlockData
->Width
= VarWidth
;
1310 BlockData
->QuestionId
= IfrPassword
->Question
.QuestionId
;
1311 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1312 InitializeListHead (&BlockData
->DefaultValueEntry
);
1315 // Add Block Data into VarStorageData BlockEntry
1317 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1320 // No default value for string.
1325 case EFI_IFR_ONE_OF_OPTION_OP
:
1327 // No matched block data is ignored.
1329 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1333 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1334 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1336 // Get ordered list option data type.
1338 if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_8
|| IfrOneOfOption
->Type
== EFI_IFR_TYPE_BOOLEAN
) {
1340 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_16
) {
1342 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_32
) {
1344 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_64
) {
1348 // Invalid ordered list option data type.
1350 Status
= EFI_INVALID_PARAMETER
;
1354 // Calculate Ordered list QuestionId width.
1356 BlockData
->Width
= (UINT16
) (BlockData
->Width
* VarWidth
);
1361 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) {
1363 // Set standard ID to Manufacture ID and Get DefaultName String ID
1365 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1366 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1367 if (EFI_ERROR (Status
)) {
1371 // Prepare new DefaultValue
1373 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1374 if (DefaultData
== NULL
) {
1375 Status
= EFI_OUT_OF_RESOURCES
;
1378 DefaultData
->DefaultId
= VarDefaultId
;
1379 DefaultData
->DefaultName
= VarDefaultName
;
1380 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1382 // Add DefaultValue into current BlockData
1384 InsertDefaultValue (BlockData
, DefaultData
);
1387 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
) {
1389 // Set default ID to Manufacture ID and Get DefaultName String ID
1391 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1392 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1393 if (EFI_ERROR (Status
)) {
1397 // Prepare new DefaultValue
1399 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1400 if (DefaultData
== NULL
) {
1401 Status
= EFI_OUT_OF_RESOURCES
;
1404 DefaultData
->DefaultId
= VarDefaultId
;
1405 DefaultData
->DefaultName
= VarDefaultName
;
1406 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1408 // Add DefaultValue into current BlockData
1410 InsertDefaultValue (BlockData
, DefaultData
);
1414 case EFI_IFR_DEFAULT_OP
:
1416 // Update Current BlockData to the default value.
1418 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1420 // No matched block data is ignored.
1425 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1427 // OrderedList Opcode is no default value.
1432 // Get the DefaultId and DefaultName String ID
1434 IfrDefault
= (EFI_IFR_DEFAULT
*) IfrOpHdr
;
1435 VarDefaultId
= IfrDefault
->DefaultId
;
1436 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1437 if (EFI_ERROR (Status
)) {
1441 // Prepare new DefaultValue
1443 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1444 if (DefaultData
== NULL
) {
1445 Status
= EFI_OUT_OF_RESOURCES
;
1448 DefaultData
->DefaultId
= VarDefaultId
;
1449 DefaultData
->DefaultName
= VarDefaultName
;
1450 DefaultData
->Value
= IfrDefault
->Value
.u64
;
1452 // Add DefaultValue into current BlockData
1454 InsertDefaultValue (BlockData
, DefaultData
);
1456 case EFI_IFR_END_OP
:
1458 // End Opcode is for Var question.
1460 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1465 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1466 BlockData
->Scope
= (UINT8
) (BlockData
->Scope
+ IfrOpHdr
->Scope
);
1471 IfrOffset
+= IfrOpHdr
->Length
;
1479 This function gets the full request string and full default value string by
1480 parsing IFR data in HII form packages.
1482 When Request points to NULL string, the request string and default value string
1483 for each varstore in form package will return.
1485 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1486 @param DevicePath Device Path which Hii Config Access Protocol is registered.
1487 @param Request Pointer to a null-terminated Unicode string in
1488 <ConfigRequest> format. When it doesn't contain
1489 any RequestElement, it will be updated to return
1490 the full RequestElement retrieved from IFR data.
1491 If it points to NULL, the request string for the first
1492 varstore in form package will be merged into a
1493 <MultiConfigRequest> format string and return.
1494 @param AltCfgResp Pointer to a null-terminated Unicode string in
1495 <ConfigAltResp> format. When the pointer is to NULL,
1496 the full default value string retrieved from IFR data
1497 will return. When the pinter is to a string, the
1498 full default value string retrieved from IFR data
1499 will be merged into the input string and return.
1500 When Request points to NULL, the default value string
1501 for each varstore in form package will be merged into
1502 a <MultiConfigAltResp> format string and return.
1503 @retval EFI_SUCCESS The Results string is set to the full request string.
1504 And AltCfgResp contains all default value string.
1505 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
1506 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string
1507 can't be found in Form package.
1508 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.
1509 @retval EFI_INVALID_PARAMETER *Request points to NULL.
1514 GetFullStringFromHiiFormPackages (
1515 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1516 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1517 IN OUT EFI_STRING
*Request
,
1518 IN OUT EFI_STRING
*AltCfgResp
1522 UINT8
*HiiFormPackage
;
1525 IFR_BLOCK_DATA
*RequestBlockArray
;
1526 IFR_BLOCK_DATA
*BlockData
;
1527 IFR_BLOCK_DATA
*NextBlockData
;
1528 IFR_DEFAULT_DATA
*DefaultValueData
;
1529 IFR_DEFAULT_DATA
*DefaultId
;
1530 IFR_DEFAULT_DATA
*DefaultIdArray
;
1531 IFR_VARSTORAGE_DATA
*VarStorageData
;
1532 EFI_STRING DefaultAltCfgResp
;
1533 EFI_STRING FullConfigRequest
;
1534 EFI_STRING ConfigHdr
;
1538 EFI_STRING StringPtr
;
1544 LIST_ENTRY
*LinkData
;
1545 LIST_ENTRY
*LinkDefault
;
1548 // Initialize the local variables.
1550 RequestBlockArray
= NULL
;
1551 DefaultIdArray
= NULL
;
1552 VarStorageData
= NULL
;
1553 DefaultAltCfgResp
= NULL
;
1554 FullConfigRequest
= NULL
;
1559 HiiFormPackage
= NULL
;
1564 // 0. Get Hii Form Package by HiiHandle
1566 Status
= ExportFormPackages (
1568 DataBaseRecord
->Handle
,
1569 DataBaseRecord
->PackageList
,
1575 if (EFI_ERROR (Status
)) {
1579 HiiFormPackage
= AllocatePool (ResultSize
);
1580 if (HiiFormPackage
== NULL
) {
1581 Status
= EFI_OUT_OF_RESOURCES
;
1586 // Get HiiFormPackage by HiiHandle
1588 PackageSize
= ResultSize
;
1590 Status
= ExportFormPackages (
1592 DataBaseRecord
->Handle
,
1593 DataBaseRecord
->PackageList
,
1599 if (EFI_ERROR (Status
)) {
1604 // 1. Get the request block array by Request String when Request string containts the block array.
1607 if (*Request
!= NULL
) {
1608 StringPtr
= StrStr (*Request
, L
"&OFFSET=");
1610 if (StringPtr
!= NULL
) {
1612 // Init RequestBlockArray
1614 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1615 if (RequestBlockArray
== NULL
) {
1616 Status
= EFI_OUT_OF_RESOURCES
;
1619 InitializeListHead (&RequestBlockArray
->Entry
);
1622 // Get the request Block array from the request string
1627 // Parse each <RequestElement> if exists
1628 // Only <BlockName> format is supported by this help function.
1629 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1631 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1633 // Skip the OFFSET string
1635 StringPtr
+= StrLen (L
"&OFFSET=");
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 (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1653 Status
= EFI_INVALID_PARAMETER
;
1656 StringPtr
+= StrLen (L
"&WIDTH=");
1661 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1662 if (EFI_ERROR (Status
)) {
1669 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1671 FreePool (TmpBuffer
);
1673 StringPtr
+= Length
;
1674 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1675 Status
= EFI_INVALID_PARAMETER
;
1682 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1683 if (BlockData
== NULL
) {
1684 Status
= EFI_OUT_OF_RESOURCES
;
1687 BlockData
->Offset
= Offset
;
1688 BlockData
->Width
= Width
;
1689 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
1692 // If '\0', parsing is finished.
1694 if (*StringPtr
== 0) {
1700 // Merge the requested block data.
1702 Link
= RequestBlockArray
->Entry
.ForwardLink
;
1703 while ((Link
!= &RequestBlockArray
->Entry
) && (Link
->ForwardLink
!= &RequestBlockArray
->Entry
)) {
1704 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1705 NextBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1706 if ((NextBlockData
->Offset
>= BlockData
->Offset
) && (NextBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1707 if ((NextBlockData
->Offset
+ NextBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1708 BlockData
->Width
= (UINT16
) (NextBlockData
->Offset
+ NextBlockData
->Width
- BlockData
->Offset
);
1710 RemoveEntryList (Link
->ForwardLink
);
1711 FreePool (NextBlockData
);
1714 Link
= Link
->ForwardLink
;
1719 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
1723 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
1725 DefaultIdArray
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1726 if (DefaultIdArray
== NULL
) {
1727 Status
= EFI_OUT_OF_RESOURCES
;
1730 InitializeListHead (&DefaultIdArray
->Entry
);
1733 // Initialize VarStorageData to store the var store Block and Default value information.
1735 VarStorageData
= (IFR_VARSTORAGE_DATA
*) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA
));
1736 if (VarStorageData
== NULL
) {
1737 Status
= EFI_OUT_OF_RESOURCES
;
1740 InitializeListHead (&VarStorageData
->Entry
);
1741 InitializeListHead (&VarStorageData
->BlockEntry
);
1744 // Parse the opcode in form pacakge to get the default setting.
1746 Status
= ParseIfrData (HiiFormPackage
, (UINT32
) PackageSize
, *Request
, RequestBlockArray
, VarStorageData
, DefaultIdArray
);
1747 if (EFI_ERROR (Status
)) {
1752 // No requested varstore in IFR data and directly return
1754 if (VarStorageData
->Size
== 0) {
1759 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
1763 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
1765 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
1766 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
1769 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
1770 (VOID
*) DevicePath
,
1774 Length
= StrLen (GuidStr
);
1775 Length
= Length
+ StrLen (NameStr
);
1776 Length
= Length
+ StrLen (PathStr
) + 1;
1777 ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1778 if (ConfigHdr
== NULL
) {
1779 Status
= EFI_OUT_OF_RESOURCES
;
1782 StrCpy (ConfigHdr
, GuidStr
);
1783 StrCat (ConfigHdr
, NameStr
);
1784 StrCat (ConfigHdr
, PathStr
);
1787 // Remove the last character L'&'
1789 *(ConfigHdr
+ StrLen (ConfigHdr
) - 1) = L
'\0';
1791 if (RequestBlockArray
== NULL
) {
1793 // Append VarStorageData BlockEntry into *Request string
1794 // Now support only one varstore in a form package.
1798 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
1799 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
1803 // Compute the length of the entire request starting with <ConfigHdr> and a
1806 Length
= StrLen (ConfigHdr
) + 1;
1808 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1810 // Add <BlockName> length for each Offset/Width pair
1812 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
1813 // | 8 | 4 | 7 | 4 |
1815 Length
= Length
+ (8 + 4 + 7 + 4);
1819 // Allocate buffer for the entire <ConfigRequest>
1821 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1822 if (FullConfigRequest
== NULL
) {
1825 StringPtr
= FullConfigRequest
;
1828 // Start with <ConfigHdr>
1830 StrCpy (StringPtr
, ConfigHdr
);
1831 StringPtr
+= StrLen (StringPtr
);
1834 // Loop through all the Offset/Width pairs and append them to ConfigRequest
1836 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1837 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1839 // Append &OFFSET=XXXX&WIDTH=YYYY\0
1843 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1844 L
"&OFFSET=%04X&WIDTH=%04X",
1848 StringPtr
+= StrLen (StringPtr
);
1851 // Set to the got full request string.
1853 HiiToLower (FullConfigRequest
);
1854 if (*Request
!= NULL
) {
1855 FreePool (*Request
);
1857 *Request
= FullConfigRequest
;
1861 // 4. Construct Default Value string in AltResp according to request element.
1862 // Go through all VarStorageData Entry and get the DefaultId array for each one
1863 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
1867 // Add length for <ConfigHdr> + '\0'
1869 Length
= StrLen (ConfigHdr
) + 1;
1871 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1872 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1874 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
1875 // |1| StrLen (ConfigHdr) | 8 | 4 |
1877 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
1879 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1880 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1881 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1882 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1883 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1885 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
1886 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
1888 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
1895 // Allocate buffer for the entire <DefaultAltCfgResp>
1897 DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1898 if (DefaultAltCfgResp
== NULL
) {
1901 StringPtr
= DefaultAltCfgResp
;
1904 // Start with <ConfigHdr>
1906 StrCpy (StringPtr
, ConfigHdr
);
1907 StringPtr
+= StrLen (StringPtr
);
1909 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1910 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1912 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
1913 // |1| StrLen (ConfigHdr) | 8 | 4 |
1917 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
1920 DefaultId
->DefaultName
1922 StringPtr
+= StrLen (StringPtr
);
1924 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1925 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1926 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1927 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1928 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1930 // Add <BlockConfig>
1931 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
1935 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
1936 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
1940 StringPtr
+= StrLen (StringPtr
);
1943 // Convert Value to a hex string in "%x" format
1944 // NOTE: This is in the opposite byte that GUID and PATH use
1946 Width
= BlockData
->Width
;
1947 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
1948 for (; Width
> 0; Width
--) {
1949 StringPtr
+= UnicodeValueToString (StringPtr
, PREFIX_ZERO
| RADIX_HEX
, TmpBuffer
[Width
- 1], 2);
1955 HiiToLower (DefaultAltCfgResp
);
1958 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.
1960 if (*AltCfgResp
!= NULL
) {
1961 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
1962 FreePool (DefaultAltCfgResp
);
1964 *AltCfgResp
= DefaultAltCfgResp
;
1968 if (RequestBlockArray
!= NULL
) {
1970 // Free Link Array RequestBlockArray
1972 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
1973 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1974 RemoveEntryList (&BlockData
->Entry
);
1975 FreePool (BlockData
);
1978 FreePool (RequestBlockArray
);
1981 if (VarStorageData
!= NULL
) {
1983 // Free link array VarStorageData
1985 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
1986 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1987 RemoveEntryList (&BlockData
->Entry
);
1989 // Free default value link array
1991 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
1992 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
1993 RemoveEntryList (&DefaultValueData
->Entry
);
1994 FreePool (DefaultValueData
);
1996 FreePool (BlockData
);
1998 FreePool (VarStorageData
);
2001 if (DefaultIdArray
!= NULL
) {
2003 // Free DefaultId Array
2005 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
2006 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
2007 RemoveEntryList (&DefaultId
->Entry
);
2008 FreePool (DefaultId
);
2010 FreePool (DefaultIdArray
);
2014 // Free the allocated string
2016 if (GuidStr
!= NULL
) {
2019 if (NameStr
!= NULL
) {
2022 if (PathStr
!= NULL
) {
2025 if (ConfigHdr
!= NULL
) {
2026 FreePool (ConfigHdr
);
2030 // Free Pacakge data
2032 if (HiiFormPackage
!= NULL
) {
2033 FreePool (HiiFormPackage
);
2040 This function allows a caller to extract the current configuration
2041 for one or more named elements from one or more drivers.
2043 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2045 @param Request A null-terminated Unicode string in
2046 <MultiConfigRequest> format.
2047 @param Progress On return, points to a character in the Request
2048 string. Points to the string's null terminator if
2049 request was successful. Points to the most recent
2050 & before the first failing name / value pair (or
2051 the beginning of the string if the failure is in
2052 the first name / value pair) if the request was
2054 @param Results Null-terminated Unicode string in
2055 <MultiConfigAltResp> format which has all values
2056 filled in for the names in the Request string.
2057 String to be allocated by the called function.
2059 @retval EFI_SUCCESS The Results string is filled with the values
2060 corresponding to all requested names.
2061 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2062 results that must be stored awaiting possible
2064 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
2065 Progress set to the "G" in "GUID" of the routing
2066 header that doesn't match. Note: There is no
2067 requirement that all routing data be validated
2068 before any configuration extraction.
2069 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
2070 parameter would result in this type of error. The
2071 Progress parameter is set to NULL.
2072 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
2073 before the error or the beginning of the string.
2074 @retval EFI_INVALID_PARAMETER Unknown name. Progress points to the & before the
2080 HiiConfigRoutingExtractConfig (
2081 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2082 IN CONST EFI_STRING Request
,
2083 OUT EFI_STRING
*Progress
,
2084 OUT EFI_STRING
*Results
2087 HII_DATABASE_PRIVATE_DATA
*Private
;
2088 EFI_STRING StringPtr
;
2089 EFI_STRING ConfigRequest
;
2091 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2092 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2095 HII_DATABASE_RECORD
*Database
;
2096 UINT8
*DevicePathPkg
;
2097 UINT8
*CurrentDevicePath
;
2098 EFI_HANDLE DriverHandle
;
2099 EFI_HII_HANDLE HiiHandle
;
2100 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2101 EFI_STRING AccessProgress
;
2102 EFI_STRING AccessResults
;
2103 EFI_STRING DefaultResults
;
2104 BOOLEAN FirstElement
;
2105 UINTN DevicePathLength
;
2107 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
2108 return EFI_INVALID_PARAMETER
;
2111 if (Request
== NULL
) {
2113 return EFI_INVALID_PARAMETER
;
2116 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2117 StringPtr
= Request
;
2118 *Progress
= StringPtr
;
2119 DefaultResults
= NULL
;
2120 ConfigRequest
= NULL
;
2121 Status
= EFI_SUCCESS
;
2122 AccessResults
= NULL
;
2126 // The first element of <MultiConfigRequest> should be
2127 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2129 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2130 return EFI_INVALID_PARAMETER
;
2133 FirstElement
= TRUE
;
2136 // Allocate a fix length of memory to store Results. Reallocate memory for
2137 // Results if this fix length is insufficient.
2139 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2140 if (*Results
== NULL
) {
2141 return EFI_OUT_OF_RESOURCES
;
2144 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2146 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
2147 // or most recent & before the error.
2149 if (StringPtr
== Request
) {
2150 *Progress
= StringPtr
;
2152 *Progress
= StringPtr
- 1;
2156 // Process each <ConfigRequest> of <MultiConfigRequest>
2158 Length
= CalculateConfigStringLen (StringPtr
);
2159 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2160 if (ConfigRequest
== NULL
) {
2161 Status
= EFI_OUT_OF_RESOURCES
;
2164 *(ConfigRequest
+ Length
) = 0;
2167 // Get the UEFI device path
2169 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
2170 if (EFI_ERROR (Status
)) {
2175 // Find driver which matches the routing data.
2177 DriverHandle
= NULL
;
2180 DevicePathLength
= GetDevicePathSize (DevicePath
);
2181 for (Link
= Private
->DatabaseList
.ForwardLink
;
2182 Link
!= &Private
->DatabaseList
;
2183 Link
= Link
->ForwardLink
2185 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2187 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2188 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2189 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2195 DriverHandle
= Database
->DriverHandle
;
2196 HiiHandle
= Database
->Handle
;
2203 // Try to find driver handle by device path.
2205 if (DriverHandle
== NULL
) {
2206 TempDevicePath
= DevicePath
;
2207 Status
= gBS
->LocateDevicePath (
2208 &gEfiDevicePathProtocolGuid
,
2212 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2214 // Routing data does not match any known driver.
2215 // Set Progress to the 'G' in "GUID" of the routing header.
2217 *Progress
= StringPtr
;
2218 Status
= EFI_NOT_FOUND
;
2224 // Check whether ConfigRequest contains request string OFFSET/WIDTH
2226 if ((HiiHandle
!= NULL
) && (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
)) {
2228 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
2230 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
);
2231 if (EFI_ERROR (Status
)) {
2235 // Not any request block is found.
2237 if (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
) {
2238 AccessResults
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
2239 goto NextConfigString
;
2244 // Call corresponding ConfigAccess protocol to extract settings
2246 Status
= gBS
->HandleProtocol (
2248 &gEfiHiiConfigAccessProtocolGuid
,
2249 (VOID
**) &ConfigAccess
2251 ASSERT_EFI_ERROR (Status
);
2253 Status
= ConfigAccess
->ExtractConfig (
2259 if (EFI_ERROR (Status
)) {
2261 // AccessProgress indicates the parsing progress on <ConfigRequest>.
2262 // Map it to the progress on <MultiConfigRequest> then return it.
2264 *Progress
= StrStr (StringPtr
, AccessProgress
);
2269 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2270 // which seperates the first <ConfigAltResp> and the following ones.
2272 ASSERT (*AccessProgress
== 0);
2275 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2277 if (HiiHandle
!= NULL
) {
2278 if (DefaultResults
== NULL
) {
2279 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &AccessResults
);
2281 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2284 FreePool (DevicePath
);
2287 if (EFI_ERROR (Status
)) {
2292 // Free the allocated memory.
2294 if (DefaultResults
!= NULL
) {
2295 FreePool (DefaultResults
);
2296 DefaultResults
= NULL
;
2300 if (!FirstElement
) {
2301 Status
= AppendToMultiString (Results
, L
"&");
2302 ASSERT_EFI_ERROR (Status
);
2305 Status
= AppendToMultiString (Results
, AccessResults
);
2306 ASSERT_EFI_ERROR (Status
);
2308 FirstElement
= FALSE
;
2310 FreePool (AccessResults
);
2311 AccessResults
= NULL
;
2312 FreePool (ConfigRequest
);
2313 ConfigRequest
= NULL
;
2316 // Go to next <ConfigRequest> (skip '&').
2318 StringPtr
+= Length
;
2319 if (*StringPtr
== 0) {
2320 *Progress
= StringPtr
;
2328 if (EFI_ERROR (Status
)) {
2329 FreePool (*Results
);
2333 if (ConfigRequest
!= NULL
) {
2334 FreePool (ConfigRequest
);
2337 if (AccessResults
!= NULL
) {
2338 FreePool (AccessResults
);
2341 if (DefaultResults
!= NULL
) {
2342 FreePool (DefaultResults
);
2345 if (DevicePath
!= NULL
) {
2346 FreePool (DevicePath
);
2354 This function allows the caller to request the current configuration for the
2355 entirety of the current HII database and returns the data in a
2356 null-terminated Unicode string.
2358 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2360 @param Results Null-terminated Unicode string in
2361 <MultiConfigAltResp> format which has all values
2362 filled in for the names in the Request string.
2363 String to be allocated by the called function.
2364 De-allocation is up to the caller.
2366 @retval EFI_SUCCESS The Results string is filled with the values
2367 corresponding to all requested names.
2368 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2369 results that must be stored awaiting possible
2371 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
2372 parameter would result in this type of error.
2377 HiiConfigRoutingExportConfig (
2378 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2379 OUT EFI_STRING
*Results
2383 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2384 EFI_STRING AccessResults
;
2385 EFI_STRING Progress
;
2386 EFI_STRING ConfigRequest
;
2388 EFI_HANDLE
*ConfigAccessHandles
;
2389 UINTN NumberConfigAccessHandles
;
2390 BOOLEAN FirstElement
;
2391 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2392 EFI_HII_HANDLE HiiHandle
;
2393 EFI_STRING DefaultResults
;
2394 HII_DATABASE_PRIVATE_DATA
*Private
;
2396 HII_DATABASE_RECORD
*Database
;
2397 UINT8
*DevicePathPkg
;
2398 UINT8
*CurrentDevicePath
;
2399 UINTN DevicePathLength
;
2401 if (This
== NULL
|| Results
== NULL
) {
2402 return EFI_INVALID_PARAMETER
;
2405 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2408 // Allocate a fix length of memory to store Results. Reallocate memory for
2409 // Results if this fix length is insufficient.
2411 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2412 if (*Results
== NULL
) {
2413 return EFI_OUT_OF_RESOURCES
;
2416 NumberConfigAccessHandles
= 0;
2417 Status
= gBS
->LocateHandleBuffer (
2419 &gEfiHiiConfigAccessProtocolGuid
,
2421 &NumberConfigAccessHandles
,
2422 &ConfigAccessHandles
2424 if (EFI_ERROR (Status
)) {
2428 FirstElement
= TRUE
;
2430 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
2431 Status
= gBS
->HandleProtocol (
2432 ConfigAccessHandles
[Index
],
2433 &gEfiHiiConfigAccessProtocolGuid
,
2434 (VOID
**) &ConfigAccess
2436 if (EFI_ERROR (Status
)) {
2441 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
2445 ConfigRequest
= NULL
;
2446 DefaultResults
= NULL
;
2448 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
2449 DevicePathLength
= GetDevicePathSize (DevicePath
);
2450 if (DevicePath
!= NULL
) {
2451 for (Link
= Private
->DatabaseList
.ForwardLink
;
2452 Link
!= &Private
->DatabaseList
;
2453 Link
= Link
->ForwardLink
2455 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2456 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2457 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2458 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2464 HiiHandle
= Database
->Handle
;
2472 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2474 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
2475 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
);
2478 // Can't parse IFR data to get the request string and default string.
2480 if (EFI_ERROR (Status
)) {
2481 ConfigRequest
= NULL
;
2482 DefaultResults
= NULL
;
2485 Status
= ConfigAccess
->ExtractConfig (
2491 if (!EFI_ERROR (Status
)) {
2493 // Merge the default sting from IFR code into the got setting from driver.
2495 if (DefaultResults
!= NULL
) {
2496 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2497 ASSERT_EFI_ERROR (Status
);
2498 FreePool (DefaultResults
);
2499 DefaultResults
= NULL
;
2503 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2504 // which seperates the first <ConfigAltResp> and the following ones.
2506 if (!FirstElement
) {
2507 Status
= AppendToMultiString (Results
, L
"&");
2508 ASSERT_EFI_ERROR (Status
);
2511 Status
= AppendToMultiString (Results
, AccessResults
);
2512 ASSERT_EFI_ERROR (Status
);
2514 FirstElement
= FALSE
;
2516 FreePool (AccessResults
);
2517 AccessResults
= NULL
;
2520 FreePool (ConfigAccessHandles
);
2527 This function processes the results of processing forms and routes it to the
2528 appropriate handlers or storage.
2530 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2532 @param Configuration A null-terminated Unicode string in
2533 <MulltiConfigResp> format.
2534 @param Progress A pointer to a string filled in with the offset of
2535 the most recent & before the first failing name /
2536 value pair (or the beginning of the string if the
2537 failure is in the first name / value pair) or the
2538 terminating NULL if all was successful.
2540 @retval EFI_SUCCESS The results have been distributed or are awaiting
2542 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2543 results that must be stored awaiting possible
2545 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
2546 would result in this type of error.
2547 @retval EFI_NOT_FOUND Target for the specified routing data was not
2553 HiiConfigRoutingRouteConfig (
2554 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2555 IN CONST EFI_STRING Configuration
,
2556 OUT EFI_STRING
*Progress
2559 HII_DATABASE_PRIVATE_DATA
*Private
;
2560 EFI_STRING StringPtr
;
2561 EFI_STRING ConfigResp
;
2564 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2565 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2567 HII_DATABASE_RECORD
*Database
;
2568 UINT8
*DevicePathPkg
;
2569 UINT8
*CurrentDevicePath
;
2570 EFI_HANDLE DriverHandle
;
2571 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2572 EFI_STRING AccessProgress
;
2573 UINTN DevicePathLength
;
2575 if (This
== NULL
|| Progress
== NULL
) {
2576 return EFI_INVALID_PARAMETER
;
2579 if (Configuration
== NULL
) {
2581 return EFI_INVALID_PARAMETER
;
2584 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2585 StringPtr
= Configuration
;
2586 *Progress
= StringPtr
;
2589 // The first element of <MultiConfigResp> should be
2590 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2592 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2593 return EFI_INVALID_PARAMETER
;
2596 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2598 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
2599 // or most recent & before the error.
2601 if (StringPtr
== Configuration
) {
2602 *Progress
= StringPtr
;
2604 *Progress
= StringPtr
- 1;
2608 // Process each <ConfigResp> of <MultiConfigResp>
2610 Length
= CalculateConfigStringLen (StringPtr
);
2611 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2612 if (ConfigResp
== NULL
) {
2613 return EFI_OUT_OF_RESOURCES
;
2616 // Append '\0' to the end of ConfigRequest
2618 *(ConfigResp
+ Length
) = 0;
2621 // Get the UEFI device path
2623 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
2624 if (EFI_ERROR (Status
)) {
2625 FreePool (ConfigResp
);
2630 // Find driver which matches the routing data.
2632 DriverHandle
= NULL
;
2633 DevicePathLength
= GetDevicePathSize (DevicePath
);
2634 for (Link
= Private
->DatabaseList
.ForwardLink
;
2635 Link
!= &Private
->DatabaseList
;
2636 Link
= Link
->ForwardLink
2638 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2640 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2641 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2642 if ((DevicePathLength
== GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)) &&
2648 DriverHandle
= Database
->DriverHandle
;
2655 // Try to find driver handle by device path.
2657 if (DriverHandle
== NULL
) {
2658 TempDevicePath
= DevicePath
;
2659 Status
= gBS
->LocateDevicePath (
2660 &gEfiDevicePathProtocolGuid
,
2664 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2666 // Routing data does not match any known driver.
2667 // Set Progress to the 'G' in "GUID" of the routing header.
2669 FreePool (DevicePath
);
2670 *Progress
= StringPtr
;
2671 FreePool (ConfigResp
);
2672 return EFI_NOT_FOUND
;
2676 FreePool (DevicePath
);
2679 // Call corresponding ConfigAccess protocol to route settings
2681 Status
= gBS
->HandleProtocol (
2683 &gEfiHiiConfigAccessProtocolGuid
,
2684 (VOID
**) &ConfigAccess
2686 ASSERT_EFI_ERROR (Status
);
2688 Status
= ConfigAccess
->RouteConfig (
2694 if (EFI_ERROR (Status
)) {
2696 // AccessProgress indicates the parsing progress on <ConfigResp>.
2697 // Map it to the progress on <MultiConfigResp> then return it.
2699 *Progress
= StrStr (StringPtr
, AccessProgress
);
2701 FreePool (ConfigResp
);
2705 FreePool (ConfigResp
);
2709 // Go to next <ConfigResp> (skip '&').
2711 StringPtr
+= Length
;
2712 if (*StringPtr
== 0) {
2713 *Progress
= StringPtr
;
2726 This helper function is to be called by drivers to map configuration data
2727 stored in byte array ("block") formats such as UEFI Variables into current
2728 configuration strings.
2730 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2732 @param ConfigRequest A null-terminated Unicode string in
2733 <ConfigRequest> format.
2734 @param Block Array of bytes defining the block's configuration.
2735 @param BlockSize Length in bytes of Block.
2736 @param Config Filled-in configuration string. String allocated
2737 by the function. Returned only if call is
2738 successful. It is <ConfigResp> string format.
2739 @param Progress A pointer to a string filled in with the offset of
2740 the most recent & before the first failing
2741 name/value pair (or the beginning of the string if
2742 the failure is in the first name / value pair) or
2743 the terminating NULL if all was successful.
2745 @retval EFI_SUCCESS The request succeeded. Progress points to the null
2746 terminator at the end of the ConfigRequest
2748 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
2749 points to the first character of ConfigRequest.
2750 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
2751 Block parameter would result in this type of
2752 error. Progress points to the first character of
2754 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
2755 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
2756 Block is left updated and Progress points at
2757 the "&" preceding the first non-<BlockName>.
2763 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2764 IN CONST EFI_STRING ConfigRequest
,
2765 IN CONST UINT8
*Block
,
2766 IN CONST UINTN BlockSize
,
2767 OUT EFI_STRING
*Config
,
2768 OUT EFI_STRING
*Progress
2771 HII_DATABASE_PRIVATE_DATA
*Private
;
2772 EFI_STRING StringPtr
;
2780 EFI_STRING ValueStr
;
2781 EFI_STRING ConfigElement
;
2786 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
2787 return EFI_INVALID_PARAMETER
;
2790 if (Block
== NULL
|| ConfigRequest
== NULL
) {
2791 *Progress
= ConfigRequest
;
2792 return EFI_INVALID_PARAMETER
;
2796 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2797 ASSERT (Private
!= NULL
);
2799 StringPtr
= ConfigRequest
;
2802 ConfigElement
= NULL
;
2805 // Allocate a fix length of memory to store Results. Reallocate memory for
2806 // Results if this fix length is insufficient.
2808 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2809 if (*Config
== NULL
) {
2810 return EFI_OUT_OF_RESOURCES
;
2816 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2817 *Progress
= StringPtr
;
2818 Status
= EFI_INVALID_PARAMETER
;
2821 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
2824 if (*StringPtr
== 0) {
2825 *Progress
= StringPtr
- 1;
2826 Status
= EFI_INVALID_PARAMETER
;
2830 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
2833 if (*StringPtr
== 0) {
2834 *Progress
= StringPtr
- 1;
2835 Status
= EFI_INVALID_PARAMETER
;
2844 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
2846 Length
= StringPtr
- ConfigRequest
;
2847 CopyMem (*Config
, ConfigRequest
, Length
* sizeof (CHAR16
));
2850 // Parse each <RequestElement> if exists
2851 // Only <BlockName> format is supported by this help function.
2852 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
2854 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
2856 // Back up the header of one <BlockName>
2860 StringPtr
+= StrLen (L
"OFFSET=");
2864 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2865 if (Status
== EFI_OUT_OF_RESOURCES
) {
2866 *Progress
= ConfigRequest
;
2873 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2875 FreePool (TmpBuffer
);
2877 StringPtr
+= Length
;
2878 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
2879 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
2880 Status
= EFI_INVALID_PARAMETER
;
2883 StringPtr
+= StrLen (L
"&WIDTH=");
2888 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2889 if (Status
== EFI_OUT_OF_RESOURCES
) {
2890 *Progress
= ConfigRequest
;
2897 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2899 FreePool (TmpBuffer
);
2901 StringPtr
+= Length
;
2902 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
2903 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
2904 Status
= EFI_INVALID_PARAMETER
;
2909 // Calculate Value and convert it to hex string.
2911 if (Offset
+ Width
> BlockSize
) {
2912 *Progress
= StringPtr
;
2913 Status
= EFI_DEVICE_ERROR
;
2917 Value
= (UINT8
*) AllocateZeroPool (Width
);
2918 if (Value
== NULL
) {
2919 *Progress
= ConfigRequest
;
2920 Status
= EFI_OUT_OF_RESOURCES
;
2924 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
2926 Length
= Width
* 2 + 1;
2927 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2928 if (ValueStr
== NULL
) {
2929 *Progress
= ConfigRequest
;
2930 Status
= EFI_OUT_OF_RESOURCES
;
2934 TemString
= ValueStr
;
2935 TemBuffer
= Value
+ Width
- 1;
2936 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
2937 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
2944 // Build a ConfigElement
2946 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
2947 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2948 if (ConfigElement
== NULL
) {
2949 Status
= EFI_OUT_OF_RESOURCES
;
2952 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
2953 if (*StringPtr
== 0) {
2954 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
2956 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
2957 StrCat (ConfigElement
, L
"VALUE=");
2958 StrCat (ConfigElement
, ValueStr
);
2960 AppendToMultiString (Config
, ConfigElement
);
2962 FreePool (ConfigElement
);
2963 FreePool (ValueStr
);
2964 ConfigElement
= NULL
;
2968 // If '\0', parsing is finished. Otherwise skip '&' to continue
2970 if (*StringPtr
== 0) {
2973 AppendToMultiString (Config
, L
"&");
2978 if (*StringPtr
!= 0) {
2979 *Progress
= StringPtr
- 1;
2980 Status
= EFI_INVALID_PARAMETER
;
2984 HiiToLower (*Config
);
2985 *Progress
= StringPtr
;
2989 if (*Config
!= NULL
) {
2993 if (ValueStr
!= NULL
) {
2994 FreePool (ValueStr
);
2996 if (Value
!= NULL
) {
2999 if (ConfigElement
!= NULL
) {
3000 FreePool (ConfigElement
);
3009 This helper function is to be called by drivers to map configuration strings
3010 to configurations stored in byte array ("block") formats such as UEFI Variables.
3012 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3014 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
3015 format. It can be ConfigAltResp format string.
3016 @param Block A possibly null array of bytes representing the
3017 current block. Only bytes referenced in the
3018 ConfigResp string in the block are modified. If
3019 this parameter is null or if the *BlockSize
3020 parameter is (on input) shorter than required by
3021 the Configuration string, only the BlockSize
3022 parameter is updated and an appropriate status
3023 (see below) is returned.
3024 @param BlockSize The length of the Block in units of UINT8. On
3025 input, this is the size of the Block. On output,
3026 if successful, contains the index of the last
3027 modified byte in the Block.
3028 @param Progress On return, points to an element of the ConfigResp
3029 string filled in with the offset of the most
3030 recent '&' before the first failing name / value
3031 pair (or the beginning of the string if the
3032 failure is in the first name / value pair) or the
3033 terminating NULL if all was successful.
3035 @retval EFI_SUCCESS The request succeeded. Progress points to the null
3036 terminator at the end of the ConfigResp string.
3037 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
3038 points to the first character of ConfigResp.
3039 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
3040 Block parameter would result in this type of
3041 error. Progress points to the first character of
3043 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
3044 value pair. Block is left updated and
3045 Progress points at the '&' preceding the first
3052 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3053 IN CONST EFI_STRING ConfigResp
,
3054 IN OUT UINT8
*Block
,
3055 IN OUT UINTN
*BlockSize
,
3056 OUT EFI_STRING
*Progress
3059 HII_DATABASE_PRIVATE_DATA
*Private
;
3060 EFI_STRING StringPtr
;
3069 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
3070 return EFI_INVALID_PARAMETER
;
3073 if (ConfigResp
== NULL
|| Block
== NULL
) {
3074 *Progress
= ConfigResp
;
3075 return EFI_INVALID_PARAMETER
;
3078 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
3079 ASSERT (Private
!= NULL
);
3081 StringPtr
= ConfigResp
;
3082 BufferSize
= *BlockSize
;
3088 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3089 *Progress
= StringPtr
;
3090 Status
= EFI_INVALID_PARAMETER
;
3093 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
3096 if (*StringPtr
== 0) {
3097 *Progress
= StringPtr
;
3098 Status
= EFI_INVALID_PARAMETER
;
3102 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
3105 if (*StringPtr
== 0) {
3106 *Progress
= StringPtr
;
3107 Status
= EFI_INVALID_PARAMETER
;
3116 // Parse each <ConfigElement> if exists
3117 // Only <BlockConfig> format is supported by this help function.
3118 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
3120 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
3121 StringPtr
+= StrLen (L
"OFFSET=");
3125 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3126 if (EFI_ERROR (Status
)) {
3127 *Progress
= ConfigResp
;
3134 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3136 FreePool (TmpBuffer
);
3138 StringPtr
+= Length
;
3139 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3140 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
3141 Status
= EFI_INVALID_PARAMETER
;
3144 StringPtr
+= StrLen (L
"&WIDTH=");
3149 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3150 if (Status
== EFI_OUT_OF_RESOURCES
) {
3151 *Progress
= ConfigResp
;
3158 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3160 FreePool (TmpBuffer
);
3162 StringPtr
+= Length
;
3163 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
3164 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
3165 Status
= EFI_INVALID_PARAMETER
;
3168 StringPtr
+= StrLen (L
"&VALUE=");
3173 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
3174 if (EFI_ERROR (Status
)) {
3175 *Progress
= ConfigResp
;
3179 StringPtr
+= Length
;
3180 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3181 *Progress
= StringPtr
- Length
- 7;
3182 Status
= EFI_INVALID_PARAMETER
;
3187 // Update the Block with configuration info
3190 if (Offset
+ Width
> BufferSize
) {
3191 return EFI_DEVICE_ERROR
;
3194 CopyMem (Block
+ Offset
, Value
, Width
);
3195 *BlockSize
= Offset
+ Width
- 1;
3201 // If '\0', parsing is finished. Otherwise skip '&' to continue
3203 if (*StringPtr
== 0) {
3211 // The input string is ConfigAltResp format.
3213 if ((*StringPtr
!= 0) && (StrnCmp (StringPtr
, L
"&GUID=", StrLen (L
"&GUID=")) != 0)) {
3214 *Progress
= StringPtr
- 1;
3215 Status
= EFI_INVALID_PARAMETER
;
3219 *Progress
= StringPtr
;
3224 if (Value
!= NULL
) {
3232 This helper function is to be called by drivers to extract portions of
3233 a larger configuration string.
3235 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3237 @param Configuration A null-terminated Unicode string in
3238 <MultiConfigAltResp> format. It is <ConfigAltResp> format.
3239 @param Guid A pointer to the GUID value to search for in the
3240 routing portion of the ConfigResp string when
3241 retrieving the requested data. If Guid is NULL,
3242 then all GUID values will be searched for.
3243 @param Name A pointer to the NAME value to search for in the
3244 routing portion of the ConfigResp string when
3245 retrieving the requested data. If Name is NULL,
3246 then all Name values will be searched for.
3247 @param DevicePath A pointer to the PATH value to search for in the
3248 routing portion of the ConfigResp string when
3249 retrieving the requested data. If DevicePath is
3250 NULL, then all DevicePath values will be searched
3252 @param AltCfgId A pointer to the ALTCFG value to search for in the
3253 routing portion of the ConfigResp string when
3254 retrieving the requested data. If this parameter
3255 is NULL, then the current setting will be
3257 @param AltCfgResp A pointer to a buffer which will be allocated by
3258 the function which contains the retrieved string
3259 as requested. This buffer is only allocated if
3260 the call was successful. It is <ConfigResp> format.
3262 @retval EFI_SUCCESS The request succeeded. The requested data was
3263 extracted and placed in the newly allocated
3265 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
3266 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
3267 @retval EFI_NOT_FOUND Target for the specified routing data was not
3274 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3275 IN CONST EFI_STRING Configuration
,
3276 IN CONST EFI_GUID
*Guid
,
3277 IN CONST EFI_STRING Name
,
3278 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3279 IN CONST UINT16
*AltCfgId
,
3280 OUT EFI_STRING
*AltCfgResp
3284 EFI_STRING StringPtr
;
3285 EFI_STRING HdrStart
;
3292 EFI_STRING AltIdStr
;
3309 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
3310 return EFI_INVALID_PARAMETER
;
3313 StringPtr
= Configuration
;
3314 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3315 return EFI_INVALID_PARAMETER
;
3319 // Generate the sub string for later matching.
3321 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
3324 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
3325 (VOID
*) DevicePath
,
3329 if (AltCfgId
!= NULL
) {
3330 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
3333 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
3335 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
3338 while (*StringPtr
!= 0) {
3340 // Try to match the GUID
3343 TmpPtr
= StrStr (StringPtr
, GuidStr
);
3344 if (TmpPtr
== NULL
) {
3345 Status
= EFI_NOT_FOUND
;
3351 // Jump to <NameHdr>
3354 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
3356 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
3357 if (StringPtr
== NULL
) {
3358 Status
= EFI_NOT_FOUND
;
3366 // Try to match the NAME
3368 if (GuidFlag
&& !NameFlag
) {
3369 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
3373 // Jump to <PathHdr>
3376 StringPtr
+= StrLen (NameStr
);
3378 StringPtr
= StrStr (StringPtr
, L
"PATH=");
3379 if (StringPtr
== NULL
) {
3380 Status
= EFI_NOT_FOUND
;
3389 // Try to match the DevicePath
3391 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
3392 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
3397 // Jump to '&' before <DescHdr> or <ConfigBody>
3399 if (DevicePath
!= NULL
) {
3400 StringPtr
+= StrLen (PathStr
);
3402 StringPtr
= StrStr (StringPtr
, L
"&");
3403 if (StringPtr
== NULL
) {
3404 Status
= EFI_NOT_FOUND
;
3415 // Try to match the AltCfgId
3417 if (GuidFlag
&& NameFlag
&& PathFlag
) {
3418 if (AltCfgId
== NULL
) {
3420 // Return Current Setting when AltCfgId is NULL.
3422 Status
= OutputConfigBody (StringPtr
, &Result
);
3426 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
3428 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
3434 // Skip AltIdStr and &
3436 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
3437 Status
= OutputConfigBody (StringPtr
, &Result
);
3443 Status
= EFI_NOT_FOUND
;
3447 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
3449 // Copy the <ConfigHdr> and <ConfigBody>
3451 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
3452 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3453 if (*AltCfgResp
== NULL
) {
3454 Status
= EFI_OUT_OF_RESOURCES
;
3456 StrnCpy (*AltCfgResp
, HdrStart
, HdrEnd
- HdrStart
);
3457 StrCat (*AltCfgResp
, Result
);
3458 Status
= EFI_SUCCESS
;
3462 if (GuidStr
!= NULL
) {
3465 if (NameStr
!= NULL
) {
3468 if (PathStr
!= NULL
) {
3471 if (AltIdStr
!= NULL
) {
3472 FreePool (AltIdStr
);
3474 if (Result
!= NULL
) {