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 if (*AltCfgResp
== NULL
) {
595 FreePool (AltConfigHdr
);
596 return EFI_OUT_OF_RESOURCES
;
598 StrCat (*AltCfgResp
, StringPtrDefault
);
599 *StringPtrEnd
= TempChar
;
604 // Find next AltCfg String
606 *(AltConfigHdr
+ HeaderLength
) = L
'\0';
607 StringPtrDefault
= StrStr (StringPtrDefault
+ 1, AltConfigHdr
);
610 FreePool (AltConfigHdr
);
615 This function finds the matched DefaultName for the input DefaultId
617 @param DefaultIdArray Array stores the map table between DefaultId and DefaultName.
618 @param VarDefaultId Default Id
619 @param VarDefaultName Default Name string ID for the input default ID.
621 @retval EFI_SUCCESS The mapped default name string ID is found.
622 @retval EFI_NOT_FOUND The mapped default name string ID is not found.
626 IN IFR_DEFAULT_DATA
*DefaultIdArray
,
627 IN UINT16 VarDefaultId
,
628 OUT EFI_STRING_ID
*VarDefaultName
632 IFR_DEFAULT_DATA
*DefaultData
;
634 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
635 DefaultData
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
636 if (DefaultData
->DefaultId
== VarDefaultId
) {
637 *VarDefaultName
= DefaultData
->DefaultName
;
642 return EFI_NOT_FOUND
;
646 This function inserts new DefaultValueData into the BlockData DefaultValue array.
648 @param BlockData The BlockData is updated to add new default value.
649 @param DefaultValueData The DefaultValue is added.
654 IN IFR_BLOCK_DATA
*BlockData
,
655 IN IFR_DEFAULT_DATA
*DefaultValueData
659 IFR_DEFAULT_DATA
*DefaultValueArray
;
661 for (Link
= BlockData
->DefaultValueEntry
.ForwardLink
; Link
!= &BlockData
->DefaultValueEntry
; Link
= Link
->ForwardLink
) {
662 DefaultValueArray
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
663 if (DefaultValueArray
->DefaultId
== DefaultValueData
->DefaultId
) {
664 if (DefaultValueData
->OpCode
== EFI_IFR_DEFAULT_OP
) {
666 // Update the default value array in BlockData.
668 DefaultValueArray
->Value
= DefaultValueData
->Value
;
669 } else if (DefaultValueArray
->OpCode
!= EFI_IFR_DEFAULT_OP
) {
671 // Update the default value array in BlockData.
673 DefaultValueArray
->Value
= DefaultValueData
->Value
;
675 FreePool (DefaultValueData
);
677 } else if (DefaultValueArray
->DefaultId
> DefaultValueData
->DefaultId
) {
679 // Insert new default value data in the front of this default value array.
681 InsertTailList (Link
, &DefaultValueData
->Entry
);
687 // Insert new default value data in tail.
689 InsertTailList (Link
, &DefaultValueData
->Entry
);
694 This function inserts new BlockData into the block link
696 @param BlockLink The list entry points to block array.
697 @param BlockData The point to BlockData is added.
702 IN LIST_ENTRY
*BlockLink
,
703 IN IFR_BLOCK_DATA
**BlockData
707 IFR_BLOCK_DATA
*BlockArray
;
708 IFR_BLOCK_DATA
*BlockSingleData
;
710 BlockSingleData
= *BlockData
;
713 // Insert block data in its Offset and Width order.
715 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
716 BlockArray
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
717 if (BlockArray
->Offset
== BlockSingleData
->Offset
) {
718 if (BlockArray
->Width
> BlockSingleData
->Width
) {
720 // Insert this block data in the front of block array
722 InsertTailList (Link
, &BlockSingleData
->Entry
);
726 if (BlockArray
->Width
== BlockSingleData
->Width
) {
728 // The same block array has been added.
730 FreePool (BlockSingleData
);
731 *BlockData
= BlockArray
;
734 } else if (BlockArray
->Offset
> BlockSingleData
->Offset
) {
736 // Insert new block data in the front of block array
738 InsertTailList (Link
, &BlockSingleData
->Entry
);
744 // Add new block data into the tail.
746 InsertTailList (Link
, &BlockSingleData
->Entry
);
751 This function checks VarOffset and VarWidth is in the block range.
753 @param BlockArray The block array is to be checked.
754 @param VarOffset Offset of var to the structure
755 @param VarWidth Width of var.
757 @retval TRUE This Var is in the block range.
758 @retval FALSE This Var is not in the block range.
762 IN IFR_BLOCK_DATA
*RequestBlockArray
,
768 IFR_BLOCK_DATA
*BlockData
;
771 // No Request Block array, all vars are got.
773 if (RequestBlockArray
== NULL
) {
778 // Check the input var is in the request block range.
780 for (Link
= RequestBlockArray
->Entry
.ForwardLink
; Link
!= &RequestBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
781 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
782 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
791 This function parses Form Package to get the block array and the default
792 value array according to the request ConfigHdr.
794 @param Package Pointer to the form package data.
795 @param PackageLength Length of the pacakge.
796 @param ConfigHdr Request string ConfigHdr. If it is NULL,
797 the first found varstore will be as ConfigHdr.
798 @param RequestBlockArray The block array is retrieved from the request string.
799 @param VarStorageData VarStorage structure contains the got block and default value.
800 @param PIfrDefaultIdArray Point to the got default id and default name array.
802 @retval EFI_SUCCESS The block array and the default value array are got.
803 @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges
805 @retval EFI_OUT_OF_RESOURCES No enough memory.
811 IN UINT32 PackageLenth
,
812 IN EFI_STRING ConfigHdr
,
813 IN IFR_BLOCK_DATA
*RequestBlockArray
,
814 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
815 OUT IFR_DEFAULT_DATA
*DefaultIdArray
820 EFI_IFR_VARSTORE
*IfrVarStore
;
821 EFI_IFR_OP_HEADER
*IfrOpHdr
;
822 EFI_IFR_ONE_OF
*IfrOneOf
;
823 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
824 EFI_IFR_DEFAULT
*IfrDefault
;
825 EFI_IFR_ORDERED_LIST
*IfrOrderedList
;
826 EFI_IFR_CHECKBOX
*IfrCheckBox
;
827 EFI_IFR_PASSWORD
*IfrPassword
;
828 EFI_IFR_STRING
*IfrString
;
829 IFR_DEFAULT_DATA
*DefaultData
;
830 IFR_BLOCK_DATA
*BlockData
;
831 CHAR16
*VarStoreName
;
834 EFI_STRING_ID VarDefaultName
;
842 Status
= EFI_SUCCESS
;
850 // Go through the form package to parse OpCode one by one.
852 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
853 while (IfrOffset
< PackageLenth
) {
854 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (Package
+ IfrOffset
);
856 switch (IfrOpHdr
->OpCode
) {
857 case EFI_IFR_VARSTORE_OP
:
859 // VarStore is found. Don't need to search any more.
861 if (VarStorageData
->Size
!= 0) {
866 // Get the requied varstore information
867 // Add varstore by Guid and Name in ConfigHdr
868 // Make sure Offset is in varstore size and varstoreid
870 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
871 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
) * sizeof (CHAR16
));
872 if (VarStoreName
== NULL
) {
873 Status
= EFI_OUT_OF_RESOURCES
;
876 AsciiStrToUnicodeStr ((CHAR8
*) IfrVarStore
->Name
, VarStoreName
);
878 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &IfrVarStore
->Guid
, 1, &GuidStr
);
879 GenerateSubStr (L
"NAME=", StrLen (VarStoreName
) * sizeof (CHAR16
), (VOID
*) VarStoreName
, 2, &NameStr
);
880 LengthString
= StrLen (GuidStr
);
881 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
882 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
883 if (TempStr
== NULL
) {
886 FreePool (VarStoreName
);
887 Status
= EFI_OUT_OF_RESOURCES
;
890 StrCpy (TempStr
, GuidStr
);
891 StrCat (TempStr
, NameStr
);
892 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
894 // Find the matched VarStore
896 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
);
897 VarStorageData
->VarStoreId
= IfrVarStore
->VarStoreId
;
898 VarStorageData
->Size
= IfrVarStore
->Size
;
899 VarStorageData
->Name
= VarStoreName
;
902 // No found, free the allocated memory
904 FreePool (VarStoreName
);
907 // Free alllocated temp string.
914 case EFI_IFR_DEFAULTSTORE_OP
:
916 // Add new the map between default id and default name.
918 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
919 if (DefaultData
== NULL
) {
920 Status
= EFI_OUT_OF_RESOURCES
;
923 DefaultData
->DefaultId
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
;
924 DefaultData
->DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
925 InsertTailList (&DefaultIdArray
->Entry
, &DefaultData
->Entry
);
929 case EFI_IFR_FORM_OP
:
931 // No matched varstore is found and directly return.
933 if (VarStorageData
->Size
== 0) {
934 Status
= EFI_SUCCESS
;
939 case EFI_IFR_ONE_OF_OP
:
940 case EFI_IFR_NUMERIC_OP
:
942 // Numeric and OneOf has the same opcode structure.
946 // Numeric and OneOf question is not in IFR Form. This IFR form is not valid.
948 if (VarStorageData
->Size
== 0) {
949 Status
= EFI_INVALID_PARAMETER
;
953 // Check whether this question is for the requested varstore.
955 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
956 if (IfrOneOf
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
961 // Get Offset/Width by Question header and OneOf Flags
963 VarOffset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
964 VarWidth
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
966 // Check whether this question is in requested block array.
968 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
970 // This question is not in the requested string. Skip it.
976 // Check this var question is in the var storage
978 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
979 Status
= EFI_INVALID_PARAMETER
;
986 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
987 if (BlockData
== NULL
) {
988 Status
= EFI_OUT_OF_RESOURCES
;
991 BlockData
->Offset
= VarOffset
;
992 BlockData
->Width
= VarWidth
;
993 BlockData
->QuestionId
= IfrOneOf
->Question
.QuestionId
;
994 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
995 BlockData
->Scope
= IfrOpHdr
->Scope
;
996 InitializeListHead (&BlockData
->DefaultValueEntry
);
998 // Add Block Data into VarStorageData BlockEntry
1000 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1003 case EFI_IFR_ORDERED_LIST_OP
:
1005 // offset by question header
1006 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type
1007 // no default value and default id, how to define its default value?
1011 // OrderedList question is not in IFR Form. This IFR form is not valid.
1013 if (VarStorageData
->Size
== 0) {
1014 Status
= EFI_INVALID_PARAMETER
;
1018 // Check whether this question is for the requested varstore.
1020 IfrOrderedList
= (EFI_IFR_ORDERED_LIST
*) IfrOpHdr
;
1021 if (IfrOrderedList
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1026 // Get Offset/Width by Question header and OneOf Flags
1028 VarOffset
= IfrOrderedList
->Question
.VarStoreInfo
.VarOffset
;
1029 VarWidth
= IfrOrderedList
->MaxContainers
;
1032 // Check whether this question is in requested block array.
1034 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1036 // This question is not in the requested string. Skip it.
1042 // Check this var question is in the var storage
1044 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1045 Status
= EFI_INVALID_PARAMETER
;
1052 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1053 if (BlockData
== NULL
) {
1054 Status
= EFI_OUT_OF_RESOURCES
;
1057 BlockData
->Offset
= VarOffset
;
1058 BlockData
->Width
= VarWidth
;
1059 BlockData
->QuestionId
= IfrOrderedList
->Question
.QuestionId
;
1060 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1061 BlockData
->Scope
= IfrOpHdr
->Scope
;
1062 InitializeListHead (&BlockData
->DefaultValueEntry
);
1065 // Add Block Data into VarStorageData BlockEntry
1067 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1070 case EFI_IFR_CHECKBOX_OP
:
1072 // EFI_IFR_DEFAULT_OP
1073 // offset by question header
1074 // width is 1 sizeof (BOOLEAN)
1075 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.
1076 // value by DefaultOption
1077 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
1081 // CheckBox question is not in IFR Form. This IFR form is not valid.
1083 if (VarStorageData
->Size
== 0) {
1084 Status
= EFI_INVALID_PARAMETER
;
1088 // Check whether this question is for the requested varstore.
1090 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1091 if (IfrCheckBox
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1096 // Get Offset/Width by Question header and OneOf Flags
1098 VarOffset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1099 VarWidth
= sizeof (BOOLEAN
);
1102 // Check whether this question is in requested block array.
1104 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1106 // This question is not in the requested string. Skip it.
1112 // Check this var question is in the var storage
1114 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1115 Status
= EFI_INVALID_PARAMETER
;
1122 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1123 if (BlockData
== NULL
) {
1124 Status
= EFI_OUT_OF_RESOURCES
;
1127 BlockData
->Offset
= VarOffset
;
1128 BlockData
->Width
= VarWidth
;
1129 BlockData
->QuestionId
= IfrCheckBox
->Question
.QuestionId
;
1130 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1131 BlockData
->Scope
= IfrOpHdr
->Scope
;
1132 InitializeListHead (&BlockData
->DefaultValueEntry
);
1134 // Add Block Data into VarStorageData BlockEntry
1136 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1139 // Add default value by CheckBox Flags
1141 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) == EFI_IFR_CHECKBOX_DEFAULT
) {
1143 // Set standard ID to Manufacture ID and Get DefaultName String ID
1145 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1146 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1147 if (EFI_ERROR (Status
)) {
1151 // Prepare new DefaultValue
1153 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1154 if (DefaultData
== NULL
) {
1155 Status
= EFI_OUT_OF_RESOURCES
;
1158 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1159 DefaultData
->DefaultId
= VarDefaultId
;
1160 DefaultData
->DefaultName
= VarDefaultName
;
1161 DefaultData
->Value
= 1;
1163 // Add DefaultValue into current BlockData
1165 InsertDefaultValue (BlockData
, DefaultData
);
1168 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) == EFI_IFR_CHECKBOX_DEFAULT_MFG
) {
1170 // Set standard ID to Manufacture ID and Get DefaultName String ID
1172 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1173 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1174 if (EFI_ERROR (Status
)) {
1178 // Prepare new DefaultValue
1180 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1181 if (DefaultData
== NULL
) {
1182 Status
= EFI_OUT_OF_RESOURCES
;
1185 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1186 DefaultData
->DefaultId
= VarDefaultId
;
1187 DefaultData
->DefaultName
= VarDefaultName
;
1188 DefaultData
->Value
= 1;
1190 // Add DefaultValue into current BlockData
1192 InsertDefaultValue (BlockData
, DefaultData
);
1196 case EFI_IFR_STRING_OP
:
1198 // offset by question header
1199 // width MaxSize * sizeof (CHAR16)
1200 // no default value, only block array
1204 // String question is not in IFR Form. This IFR form is not valid.
1206 if (VarStorageData
->Size
== 0) {
1207 Status
= EFI_INVALID_PARAMETER
;
1211 // Check whether this question is for the requested varstore.
1213 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1214 if (IfrString
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1219 // Get Offset/Width by Question header and OneOf Flags
1221 VarOffset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1222 VarWidth
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1225 // Check whether this question is in requested block array.
1227 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1229 // This question is not in the requested string. Skip it.
1235 // Check this var question is in the var storage
1237 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1238 Status
= EFI_INVALID_PARAMETER
;
1245 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1246 if (BlockData
== NULL
) {
1247 Status
= EFI_OUT_OF_RESOURCES
;
1250 BlockData
->Offset
= VarOffset
;
1251 BlockData
->Width
= VarWidth
;
1252 BlockData
->QuestionId
= IfrString
->Question
.QuestionId
;
1253 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1254 InitializeListHead (&BlockData
->DefaultValueEntry
);
1257 // Add Block Data into VarStorageData BlockEntry
1259 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1262 // No default value for string.
1267 case EFI_IFR_PASSWORD_OP
:
1269 // offset by question header
1270 // width MaxSize * sizeof (CHAR16)
1271 // no default value, only block array
1275 // Password question is not in IFR Form. This IFR form is not valid.
1277 if (VarStorageData
->Size
== 0) {
1278 Status
= EFI_INVALID_PARAMETER
;
1282 // Check whether this question is for the requested varstore.
1284 IfrPassword
= (EFI_IFR_PASSWORD
*) IfrOpHdr
;
1285 if (IfrPassword
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1290 // Get Offset/Width by Question header and OneOf Flags
1292 VarOffset
= IfrPassword
->Question
.VarStoreInfo
.VarOffset
;
1293 VarWidth
= (UINT16
) (IfrPassword
->MaxSize
* sizeof (UINT16
));
1296 // Check whether this question is in requested block array.
1298 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1300 // This question is not in the requested string. Skip it.
1306 // Check this var question is in the var storage
1308 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1309 Status
= EFI_INVALID_PARAMETER
;
1316 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1317 if (BlockData
== NULL
) {
1318 Status
= EFI_OUT_OF_RESOURCES
;
1321 BlockData
->Offset
= VarOffset
;
1322 BlockData
->Width
= VarWidth
;
1323 BlockData
->QuestionId
= IfrPassword
->Question
.QuestionId
;
1324 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1325 InitializeListHead (&BlockData
->DefaultValueEntry
);
1328 // Add Block Data into VarStorageData BlockEntry
1330 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1333 // No default value for string.
1338 case EFI_IFR_ONE_OF_OPTION_OP
:
1340 // No matched block data is ignored.
1342 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1346 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1347 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1349 // Get ordered list option data type.
1351 if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_8
|| IfrOneOfOption
->Type
== EFI_IFR_TYPE_BOOLEAN
) {
1353 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_16
) {
1355 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_32
) {
1357 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_64
) {
1361 // Invalid ordered list option data type.
1363 Status
= EFI_INVALID_PARAMETER
;
1367 // Calculate Ordered list QuestionId width.
1369 BlockData
->Width
= (UINT16
) (BlockData
->Width
* VarWidth
);
1374 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) {
1376 // Set standard ID to Manufacture ID and Get DefaultName String ID
1378 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1379 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1380 if (EFI_ERROR (Status
)) {
1384 // Prepare new DefaultValue
1386 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1387 if (DefaultData
== NULL
) {
1388 Status
= EFI_OUT_OF_RESOURCES
;
1391 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1392 DefaultData
->DefaultId
= VarDefaultId
;
1393 DefaultData
->DefaultName
= VarDefaultName
;
1394 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1396 // Add DefaultValue into current BlockData
1398 InsertDefaultValue (BlockData
, DefaultData
);
1401 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
) {
1403 // Set default ID to Manufacture ID and Get DefaultName String ID
1405 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1406 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1407 if (EFI_ERROR (Status
)) {
1411 // Prepare new DefaultValue
1413 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1414 if (DefaultData
== NULL
) {
1415 Status
= EFI_OUT_OF_RESOURCES
;
1418 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1419 DefaultData
->DefaultId
= VarDefaultId
;
1420 DefaultData
->DefaultName
= VarDefaultName
;
1421 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1423 // Add DefaultValue into current BlockData
1425 InsertDefaultValue (BlockData
, DefaultData
);
1429 case EFI_IFR_DEFAULT_OP
:
1431 // Update Current BlockData to the default value.
1433 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1435 // No matched block data is ignored.
1440 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1442 // OrderedList Opcode is no default value.
1447 // Get the DefaultId and DefaultName String ID
1449 IfrDefault
= (EFI_IFR_DEFAULT
*) IfrOpHdr
;
1450 VarDefaultId
= IfrDefault
->DefaultId
;
1451 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1452 if (EFI_ERROR (Status
)) {
1456 // Prepare new DefaultValue
1458 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1459 if (DefaultData
== NULL
) {
1460 Status
= EFI_OUT_OF_RESOURCES
;
1463 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1464 DefaultData
->DefaultId
= VarDefaultId
;
1465 DefaultData
->DefaultName
= VarDefaultName
;
1466 DefaultData
->Value
= IfrDefault
->Value
.u64
;
1468 // Add DefaultValue into current BlockData
1470 InsertDefaultValue (BlockData
, DefaultData
);
1472 case EFI_IFR_END_OP
:
1474 // End Opcode is for Var question.
1476 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1481 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1482 BlockData
->Scope
= (UINT8
) (BlockData
->Scope
+ IfrOpHdr
->Scope
);
1487 IfrOffset
+= IfrOpHdr
->Length
;
1495 This function gets the full request string and full default value string by
1496 parsing IFR data in HII form packages.
1498 When Request points to NULL string, the request string and default value string
1499 for each varstore in form package will return.
1501 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1502 @param DevicePath Device Path which Hii Config Access Protocol is registered.
1503 @param Request Pointer to a null-terminated Unicode string in
1504 <ConfigRequest> format. When it doesn't contain
1505 any RequestElement, it will be updated to return
1506 the full RequestElement retrieved from IFR data.
1507 If it points to NULL, the request string for the first
1508 varstore in form package will be merged into a
1509 <MultiConfigRequest> format string and return.
1510 @param AltCfgResp Pointer to a null-terminated Unicode string in
1511 <ConfigAltResp> format. When the pointer is to NULL,
1512 the full default value string retrieved from IFR data
1513 will return. When the pinter is to a string, the
1514 full default value string retrieved from IFR data
1515 will be merged into the input string and return.
1516 When Request points to NULL, the default value string
1517 for each varstore in form package will be merged into
1518 a <MultiConfigAltResp> format string and return.
1519 @retval EFI_SUCCESS The Results string is set to the full request string.
1520 And AltCfgResp contains all default value string.
1521 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
1522 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string
1523 can't be found in Form package.
1524 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.
1525 @retval EFI_INVALID_PARAMETER *Request points to NULL.
1530 GetFullStringFromHiiFormPackages (
1531 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1532 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1533 IN OUT EFI_STRING
*Request
,
1534 IN OUT EFI_STRING
*AltCfgResp
1538 UINT8
*HiiFormPackage
;
1541 IFR_BLOCK_DATA
*RequestBlockArray
;
1542 IFR_BLOCK_DATA
*BlockData
;
1543 IFR_BLOCK_DATA
*NextBlockData
;
1544 IFR_DEFAULT_DATA
*DefaultValueData
;
1545 IFR_DEFAULT_DATA
*DefaultId
;
1546 IFR_DEFAULT_DATA
*DefaultIdArray
;
1547 IFR_VARSTORAGE_DATA
*VarStorageData
;
1548 EFI_STRING DefaultAltCfgResp
;
1549 EFI_STRING FullConfigRequest
;
1550 EFI_STRING ConfigHdr
;
1554 EFI_STRING StringPtr
;
1560 LIST_ENTRY
*LinkData
;
1561 LIST_ENTRY
*LinkDefault
;
1565 // Initialize the local variables.
1567 RequestBlockArray
= NULL
;
1568 DefaultIdArray
= NULL
;
1569 VarStorageData
= NULL
;
1570 DefaultAltCfgResp
= NULL
;
1571 FullConfigRequest
= NULL
;
1576 HiiFormPackage
= NULL
;
1582 // 0. Get Hii Form Package by HiiHandle
1584 Status
= ExportFormPackages (
1586 DataBaseRecord
->Handle
,
1587 DataBaseRecord
->PackageList
,
1593 if (EFI_ERROR (Status
)) {
1597 HiiFormPackage
= AllocatePool (ResultSize
);
1598 if (HiiFormPackage
== NULL
) {
1599 Status
= EFI_OUT_OF_RESOURCES
;
1604 // Get HiiFormPackage by HiiHandle
1606 PackageSize
= ResultSize
;
1608 Status
= ExportFormPackages (
1610 DataBaseRecord
->Handle
,
1611 DataBaseRecord
->PackageList
,
1617 if (EFI_ERROR (Status
)) {
1622 // 1. Get the request block array by Request String when Request string containts the block array.
1625 if (*Request
!= NULL
) {
1626 StringPtr
= StrStr (*Request
, L
"&OFFSET=");
1628 if (StringPtr
!= NULL
) {
1630 // Init RequestBlockArray
1632 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1633 if (RequestBlockArray
== NULL
) {
1634 Status
= EFI_OUT_OF_RESOURCES
;
1637 InitializeListHead (&RequestBlockArray
->Entry
);
1640 // Get the request Block array from the request string
1645 // Parse each <RequestElement> if exists
1646 // Only <BlockName> format is supported by this help function.
1647 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1649 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1651 // Skip the OFFSET string
1653 StringPtr
+= StrLen (L
"&OFFSET=");
1657 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1658 if (EFI_ERROR (Status
)) {
1665 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1667 FreePool (TmpBuffer
);
1669 StringPtr
+= Length
;
1670 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1671 Status
= EFI_INVALID_PARAMETER
;
1674 StringPtr
+= StrLen (L
"&WIDTH=");
1679 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1680 if (EFI_ERROR (Status
)) {
1687 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1689 FreePool (TmpBuffer
);
1691 StringPtr
+= Length
;
1692 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1693 Status
= EFI_INVALID_PARAMETER
;
1700 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1701 if (BlockData
== NULL
) {
1702 Status
= EFI_OUT_OF_RESOURCES
;
1705 BlockData
->Offset
= Offset
;
1706 BlockData
->Width
= Width
;
1707 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
1710 // Skip &VALUE string if &VALUE does exists.
1712 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) == 0) {
1713 StringPtr
+= StrLen (L
"&VALUE=");
1718 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1719 if (EFI_ERROR (Status
)) {
1720 Status
= EFI_INVALID_PARAMETER
;
1724 StringPtr
+= Length
;
1725 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1726 Status
= EFI_INVALID_PARAMETER
;
1731 // If '\0', parsing is finished.
1733 if (*StringPtr
== 0) {
1739 // Merge the requested block data.
1741 Link
= RequestBlockArray
->Entry
.ForwardLink
;
1742 while ((Link
!= &RequestBlockArray
->Entry
) && (Link
->ForwardLink
!= &RequestBlockArray
->Entry
)) {
1743 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1744 NextBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1745 if ((NextBlockData
->Offset
>= BlockData
->Offset
) && (NextBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1746 if ((NextBlockData
->Offset
+ NextBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1747 BlockData
->Width
= (UINT16
) (NextBlockData
->Offset
+ NextBlockData
->Width
- BlockData
->Offset
);
1749 RemoveEntryList (Link
->ForwardLink
);
1750 FreePool (NextBlockData
);
1753 Link
= Link
->ForwardLink
;
1758 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
1762 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
1764 DefaultIdArray
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1765 if (DefaultIdArray
== NULL
) {
1766 Status
= EFI_OUT_OF_RESOURCES
;
1769 InitializeListHead (&DefaultIdArray
->Entry
);
1772 // Initialize VarStorageData to store the var store Block and Default value information.
1774 VarStorageData
= (IFR_VARSTORAGE_DATA
*) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA
));
1775 if (VarStorageData
== NULL
) {
1776 Status
= EFI_OUT_OF_RESOURCES
;
1779 InitializeListHead (&VarStorageData
->Entry
);
1780 InitializeListHead (&VarStorageData
->BlockEntry
);
1783 // Parse the opcode in form pacakge to get the default setting.
1785 Status
= ParseIfrData (HiiFormPackage
, (UINT32
) PackageSize
, *Request
, RequestBlockArray
, VarStorageData
, DefaultIdArray
);
1786 if (EFI_ERROR (Status
)) {
1791 // No requested varstore in IFR data and directly return
1793 if (VarStorageData
->Size
== 0) {
1794 Status
= EFI_SUCCESS
;
1799 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
1803 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
1805 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
1806 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
1809 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
1810 (VOID
*) DevicePath
,
1814 Length
= StrLen (GuidStr
);
1815 Length
= Length
+ StrLen (NameStr
);
1816 Length
= Length
+ StrLen (PathStr
) + 1;
1817 ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1818 if (ConfigHdr
== NULL
) {
1819 Status
= EFI_OUT_OF_RESOURCES
;
1822 StrCpy (ConfigHdr
, GuidStr
);
1823 StrCat (ConfigHdr
, NameStr
);
1824 StrCat (ConfigHdr
, PathStr
);
1827 // Remove the last character L'&'
1829 *(ConfigHdr
+ StrLen (ConfigHdr
) - 1) = L
'\0';
1831 if (RequestBlockArray
== NULL
) {
1833 // Append VarStorageData BlockEntry into *Request string
1834 // Now support only one varstore in a form package.
1838 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
1839 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
1843 // Compute the length of the entire request starting with <ConfigHdr> and a
1847 Length
= StrLen (ConfigHdr
) + 1;
1849 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1851 // Add <BlockName> length for each Offset/Width pair
1853 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
1854 // | 8 | 4 | 7 | 4 |
1857 Length
= Length
+ (8 + 4 + 7 + 4);
1861 // No any request block data is found. The request string can't be constructed.
1864 Status
= EFI_SUCCESS
;
1869 // Allocate buffer for the entire <ConfigRequest>
1871 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1872 if (FullConfigRequest
== NULL
) {
1873 Status
= EFI_OUT_OF_RESOURCES
;
1876 StringPtr
= FullConfigRequest
;
1879 // Start with <ConfigHdr>
1881 StrCpy (StringPtr
, ConfigHdr
);
1882 StringPtr
+= StrLen (StringPtr
);
1885 // Loop through all the Offset/Width pairs and append them to ConfigRequest
1887 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1888 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1890 // Append &OFFSET=XXXX&WIDTH=YYYY\0
1894 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1895 L
"&OFFSET=%04X&WIDTH=%04X",
1899 StringPtr
+= StrLen (StringPtr
);
1902 // Set to the got full request string.
1904 HiiToLower (FullConfigRequest
);
1905 if (*Request
!= NULL
) {
1906 FreePool (*Request
);
1908 *Request
= FullConfigRequest
;
1912 // 4. Construct Default Value string in AltResp according to request element.
1913 // Go through all VarStorageData Entry and get the DefaultId array for each one
1914 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
1918 // Add length for <ConfigHdr> + '\0'
1920 Length
= StrLen (ConfigHdr
) + 1;
1922 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1923 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1925 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
1926 // |1| StrLen (ConfigHdr) | 8 | 4 |
1928 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
1930 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1931 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1932 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1933 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1934 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1936 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
1937 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
1939 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
1947 // No default value is found. The default string doesn't exist.
1950 Status
= EFI_SUCCESS
;
1955 // Allocate buffer for the entire <DefaultAltCfgResp>
1957 DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1958 if (DefaultAltCfgResp
== NULL
) {
1959 Status
= EFI_OUT_OF_RESOURCES
;
1962 StringPtr
= DefaultAltCfgResp
;
1965 // Start with <ConfigHdr>
1967 StrCpy (StringPtr
, ConfigHdr
);
1968 StringPtr
+= StrLen (StringPtr
);
1970 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
1971 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1973 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
1974 // |1| StrLen (ConfigHdr) | 8 | 4 |
1978 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
1981 DefaultId
->DefaultName
1983 StringPtr
+= StrLen (StringPtr
);
1985 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
1986 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
1987 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
1988 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
1989 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
1991 // Add <BlockConfig>
1992 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
1996 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
1997 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
2001 StringPtr
+= StrLen (StringPtr
);
2004 // Convert Value to a hex string in "%x" format
2005 // NOTE: This is in the opposite byte that GUID and PATH use
2007 Width
= BlockData
->Width
;
2008 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
2009 for (; Width
> 0; Width
--) {
2010 StringPtr
+= UnicodeValueToString (StringPtr
, PREFIX_ZERO
| RADIX_HEX
, TmpBuffer
[Width
- 1], 2);
2016 HiiToLower (DefaultAltCfgResp
);
2019 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.
2021 if (*AltCfgResp
!= NULL
&& DefaultAltCfgResp
!= NULL
) {
2022 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
2023 FreePool (DefaultAltCfgResp
);
2024 } else if (*AltCfgResp
== NULL
) {
2025 *AltCfgResp
= DefaultAltCfgResp
;
2029 if (RequestBlockArray
!= NULL
) {
2031 // Free Link Array RequestBlockArray
2033 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
2034 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2035 RemoveEntryList (&BlockData
->Entry
);
2036 FreePool (BlockData
);
2039 FreePool (RequestBlockArray
);
2042 if (VarStorageData
!= NULL
) {
2044 // Free link array VarStorageData
2046 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
2047 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2048 RemoveEntryList (&BlockData
->Entry
);
2050 // Free default value link array
2052 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
2053 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
2054 RemoveEntryList (&DefaultValueData
->Entry
);
2055 FreePool (DefaultValueData
);
2057 FreePool (BlockData
);
2059 FreePool (VarStorageData
);
2062 if (DefaultIdArray
!= NULL
) {
2064 // Free DefaultId Array
2066 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
2067 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
2068 RemoveEntryList (&DefaultId
->Entry
);
2069 FreePool (DefaultId
);
2071 FreePool (DefaultIdArray
);
2075 // Free the allocated string
2077 if (GuidStr
!= NULL
) {
2080 if (NameStr
!= NULL
) {
2083 if (PathStr
!= NULL
) {
2086 if (ConfigHdr
!= NULL
) {
2087 FreePool (ConfigHdr
);
2091 // Free Pacakge data
2093 if (HiiFormPackage
!= NULL
) {
2094 FreePool (HiiFormPackage
);
2101 This function allows a caller to extract the current configuration
2102 for one or more named elements from one or more drivers.
2104 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2106 @param Request A null-terminated Unicode string in
2107 <MultiConfigRequest> format.
2108 @param Progress On return, points to a character in the Request
2109 string. Points to the string's null terminator if
2110 request was successful. Points to the most recent
2111 & before the first failing name / value pair (or
2112 the beginning of the string if the failure is in
2113 the first name / value pair) if the request was
2115 @param Results Null-terminated Unicode string in
2116 <MultiConfigAltResp> format which has all values
2117 filled in for the names in the Request string.
2118 String to be allocated by the called function.
2120 @retval EFI_SUCCESS The Results string is filled with the values
2121 corresponding to all requested names.
2122 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2123 results that must be stored awaiting possible
2125 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
2126 Progress set to the "G" in "GUID" of the routing
2127 header that doesn't match. Note: There is no
2128 requirement that all routing data be validated
2129 before any configuration extraction.
2130 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
2131 parameter would result in this type of error. The
2132 Progress parameter is set to NULL.
2133 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
2134 before the error or the beginning of the string.
2135 @retval EFI_INVALID_PARAMETER Unknown name. Progress points to the & before the
2141 HiiConfigRoutingExtractConfig (
2142 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2143 IN CONST EFI_STRING Request
,
2144 OUT EFI_STRING
*Progress
,
2145 OUT EFI_STRING
*Results
2148 HII_DATABASE_PRIVATE_DATA
*Private
;
2149 EFI_STRING StringPtr
;
2150 EFI_STRING ConfigRequest
;
2152 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2153 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2156 HII_DATABASE_RECORD
*Database
;
2157 UINT8
*DevicePathPkg
;
2158 UINT8
*CurrentDevicePath
;
2159 EFI_HANDLE DriverHandle
;
2160 EFI_HII_HANDLE HiiHandle
;
2161 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2162 EFI_STRING AccessProgress
;
2163 EFI_STRING AccessResults
;
2164 EFI_STRING DefaultResults
;
2165 BOOLEAN FirstElement
;
2166 BOOLEAN IfrDataParsedFlag
;
2168 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
2169 return EFI_INVALID_PARAMETER
;
2172 if (Request
== NULL
) {
2174 return EFI_INVALID_PARAMETER
;
2177 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2178 StringPtr
= Request
;
2179 *Progress
= StringPtr
;
2180 DefaultResults
= NULL
;
2181 ConfigRequest
= NULL
;
2182 Status
= EFI_SUCCESS
;
2183 AccessResults
= NULL
;
2185 IfrDataParsedFlag
= FALSE
;
2188 // The first element of <MultiConfigRequest> should be
2189 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2191 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2192 return EFI_INVALID_PARAMETER
;
2195 FirstElement
= TRUE
;
2198 // Allocate a fix length of memory to store Results. Reallocate memory for
2199 // Results if this fix length is insufficient.
2201 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2202 if (*Results
== NULL
) {
2203 return EFI_OUT_OF_RESOURCES
;
2206 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2208 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
2209 // or most recent & before the error.
2211 if (StringPtr
== Request
) {
2212 *Progress
= StringPtr
;
2214 *Progress
= StringPtr
- 1;
2218 // Process each <ConfigRequest> of <MultiConfigRequest>
2220 Length
= CalculateConfigStringLen (StringPtr
);
2221 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2222 if (ConfigRequest
== NULL
) {
2223 Status
= EFI_OUT_OF_RESOURCES
;
2226 *(ConfigRequest
+ Length
) = 0;
2229 // Get the UEFI device path
2231 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
2232 if (EFI_ERROR (Status
)) {
2237 // Find driver which matches the routing data.
2239 DriverHandle
= NULL
;
2242 for (Link
= Private
->DatabaseList
.ForwardLink
;
2243 Link
!= &Private
->DatabaseList
;
2244 Link
= Link
->ForwardLink
2246 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2248 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2249 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2253 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
2255 DriverHandle
= Database
->DriverHandle
;
2256 HiiHandle
= Database
->Handle
;
2263 // Try to find driver handle by device path.
2265 if (DriverHandle
== NULL
) {
2266 TempDevicePath
= DevicePath
;
2267 Status
= gBS
->LocateDevicePath (
2268 &gEfiDevicePathProtocolGuid
,
2272 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2274 // Routing data does not match any known driver.
2275 // Set Progress to the 'G' in "GUID" of the routing header.
2277 *Progress
= StringPtr
;
2278 Status
= EFI_NOT_FOUND
;
2284 // Check whether ConfigRequest contains request string OFFSET/WIDTH
2286 IfrDataParsedFlag
= FALSE
;
2287 if ((HiiHandle
!= NULL
) && (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
)) {
2289 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
2291 IfrDataParsedFlag
= TRUE
;
2292 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
);
2293 if (EFI_ERROR (Status
)) {
2297 // Not any request block is found.
2299 if (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
) {
2300 AccessResults
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
2301 goto NextConfigString
;
2306 // Call corresponding ConfigAccess protocol to extract settings
2308 Status
= gBS
->HandleProtocol (
2310 &gEfiHiiConfigAccessProtocolGuid
,
2311 (VOID
**) &ConfigAccess
2313 ASSERT_EFI_ERROR (Status
);
2315 Status
= ConfigAccess
->ExtractConfig (
2321 if (EFI_ERROR (Status
)) {
2323 // AccessProgress indicates the parsing progress on <ConfigRequest>.
2324 // Map it to the progress on <MultiConfigRequest> then return it.
2326 *Progress
= StrStr (StringPtr
, AccessProgress
);
2331 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2332 // which seperates the first <ConfigAltResp> and the following ones.
2334 ASSERT (*AccessProgress
== 0);
2337 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2339 if (HiiHandle
!= NULL
) {
2340 if (!IfrDataParsedFlag
) {
2341 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &AccessResults
);
2342 } else if (DefaultResults
!= NULL
) {
2343 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2344 FreePool (DefaultResults
);
2345 DefaultResults
= NULL
;
2348 FreePool (DevicePath
);
2351 if (EFI_ERROR (Status
)) {
2356 if (!FirstElement
) {
2357 Status
= AppendToMultiString (Results
, L
"&");
2358 ASSERT_EFI_ERROR (Status
);
2361 Status
= AppendToMultiString (Results
, AccessResults
);
2362 ASSERT_EFI_ERROR (Status
);
2364 FirstElement
= FALSE
;
2366 FreePool (AccessResults
);
2367 AccessResults
= NULL
;
2368 FreePool (ConfigRequest
);
2369 ConfigRequest
= NULL
;
2372 // Go to next <ConfigRequest> (skip '&').
2374 StringPtr
+= Length
;
2375 if (*StringPtr
== 0) {
2376 *Progress
= StringPtr
;
2384 if (EFI_ERROR (Status
)) {
2385 FreePool (*Results
);
2389 if (ConfigRequest
!= NULL
) {
2390 FreePool (ConfigRequest
);
2393 if (AccessResults
!= NULL
) {
2394 FreePool (AccessResults
);
2397 if (DefaultResults
!= NULL
) {
2398 FreePool (DefaultResults
);
2401 if (DevicePath
!= NULL
) {
2402 FreePool (DevicePath
);
2410 This function allows the caller to request the current configuration for the
2411 entirety of the current HII database and returns the data in a
2412 null-terminated Unicode string.
2414 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2416 @param Results Null-terminated Unicode string in
2417 <MultiConfigAltResp> format which has all values
2418 filled in for the names in the Request string.
2419 String to be allocated by the called function.
2420 De-allocation is up to the caller.
2422 @retval EFI_SUCCESS The Results string is filled with the values
2423 corresponding to all requested names.
2424 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2425 results that must be stored awaiting possible
2427 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
2428 parameter would result in this type of error.
2433 HiiConfigRoutingExportConfig (
2434 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2435 OUT EFI_STRING
*Results
2439 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2440 EFI_STRING AccessResults
;
2441 EFI_STRING Progress
;
2442 EFI_STRING StringPtr
;
2444 EFI_HANDLE
*ConfigAccessHandles
;
2445 UINTN NumberConfigAccessHandles
;
2446 BOOLEAN FirstElement
;
2447 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2448 EFI_HII_HANDLE HiiHandle
;
2449 EFI_STRING DefaultResults
;
2450 HII_DATABASE_PRIVATE_DATA
*Private
;
2452 HII_DATABASE_RECORD
*Database
;
2453 UINT8
*DevicePathPkg
;
2454 UINT8
*CurrentDevicePath
;
2456 if (This
== NULL
|| Results
== NULL
) {
2457 return EFI_INVALID_PARAMETER
;
2460 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2463 // Allocate a fix length of memory to store Results. Reallocate memory for
2464 // Results if this fix length is insufficient.
2466 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2467 if (*Results
== NULL
) {
2468 return EFI_OUT_OF_RESOURCES
;
2471 NumberConfigAccessHandles
= 0;
2472 Status
= gBS
->LocateHandleBuffer (
2474 &gEfiHiiConfigAccessProtocolGuid
,
2476 &NumberConfigAccessHandles
,
2477 &ConfigAccessHandles
2479 if (EFI_ERROR (Status
)) {
2483 FirstElement
= TRUE
;
2485 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
2486 Status
= gBS
->HandleProtocol (
2487 ConfigAccessHandles
[Index
],
2488 &gEfiHiiConfigAccessProtocolGuid
,
2489 (VOID
**) &ConfigAccess
2491 if (EFI_ERROR (Status
)) {
2496 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
2500 DefaultResults
= NULL
;
2502 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
2503 if (DevicePath
!= NULL
) {
2504 for (Link
= Private
->DatabaseList
.ForwardLink
;
2505 Link
!= &Private
->DatabaseList
;
2506 Link
= Link
->ForwardLink
2508 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2509 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2510 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2514 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
2516 HiiHandle
= Database
->Handle
;
2523 Status
= ConfigAccess
->ExtractConfig (
2529 if (!EFI_ERROR (Status
)) {
2531 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2533 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
2534 StringPtr
= StrStr (AccessResults
, L
"&GUID=");
2535 if (StringPtr
!= NULL
) {
2538 if (StrStr (AccessResults
, L
"&OFFSET=") != NULL
) {
2539 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &AccessResults
, &DefaultResults
);
2541 if (StringPtr
!= NULL
) {
2546 // Merge the default sting from IFR code into the got setting from driver.
2548 if (DefaultResults
!= NULL
) {
2549 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2550 ASSERT_EFI_ERROR (Status
);
2551 FreePool (DefaultResults
);
2552 DefaultResults
= NULL
;
2556 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2557 // which seperates the first <ConfigAltResp> and the following ones.
2559 if (!FirstElement
) {
2560 Status
= AppendToMultiString (Results
, L
"&");
2561 ASSERT_EFI_ERROR (Status
);
2564 Status
= AppendToMultiString (Results
, AccessResults
);
2565 ASSERT_EFI_ERROR (Status
);
2567 FirstElement
= FALSE
;
2569 FreePool (AccessResults
);
2570 AccessResults
= NULL
;
2573 FreePool (ConfigAccessHandles
);
2580 This function processes the results of processing forms and routes it to the
2581 appropriate handlers or storage.
2583 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2585 @param Configuration A null-terminated Unicode string in
2586 <MulltiConfigResp> format.
2587 @param Progress A pointer to a string filled in with the offset of
2588 the most recent & before the first failing name /
2589 value pair (or the beginning of the string if the
2590 failure is in the first name / value pair) or the
2591 terminating NULL if all was successful.
2593 @retval EFI_SUCCESS The results have been distributed or are awaiting
2595 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2596 results that must be stored awaiting possible
2598 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
2599 would result in this type of error.
2600 @retval EFI_NOT_FOUND Target for the specified routing data was not
2606 HiiConfigRoutingRouteConfig (
2607 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2608 IN CONST EFI_STRING Configuration
,
2609 OUT EFI_STRING
*Progress
2612 HII_DATABASE_PRIVATE_DATA
*Private
;
2613 EFI_STRING StringPtr
;
2614 EFI_STRING ConfigResp
;
2617 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2618 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2620 HII_DATABASE_RECORD
*Database
;
2621 UINT8
*DevicePathPkg
;
2622 UINT8
*CurrentDevicePath
;
2623 EFI_HANDLE DriverHandle
;
2624 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2625 EFI_STRING AccessProgress
;
2627 if (This
== NULL
|| Progress
== NULL
) {
2628 return EFI_INVALID_PARAMETER
;
2631 if (Configuration
== NULL
) {
2633 return EFI_INVALID_PARAMETER
;
2636 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2637 StringPtr
= Configuration
;
2638 *Progress
= StringPtr
;
2641 // The first element of <MultiConfigResp> should be
2642 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2644 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2645 return EFI_INVALID_PARAMETER
;
2648 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2650 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
2651 // or most recent & before the error.
2653 if (StringPtr
== Configuration
) {
2654 *Progress
= StringPtr
;
2656 *Progress
= StringPtr
- 1;
2660 // Process each <ConfigResp> of <MultiConfigResp>
2662 Length
= CalculateConfigStringLen (StringPtr
);
2663 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2664 if (ConfigResp
== NULL
) {
2665 return EFI_OUT_OF_RESOURCES
;
2668 // Append '\0' to the end of ConfigRequest
2670 *(ConfigResp
+ Length
) = 0;
2673 // Get the UEFI device path
2675 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
2676 if (EFI_ERROR (Status
)) {
2677 FreePool (ConfigResp
);
2682 // Find driver which matches the routing data.
2684 DriverHandle
= NULL
;
2685 for (Link
= Private
->DatabaseList
.ForwardLink
;
2686 Link
!= &Private
->DatabaseList
;
2687 Link
= Link
->ForwardLink
2689 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2691 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2692 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2696 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
2698 DriverHandle
= Database
->DriverHandle
;
2705 // Try to find driver handle by device path.
2707 if (DriverHandle
== NULL
) {
2708 TempDevicePath
= DevicePath
;
2709 Status
= gBS
->LocateDevicePath (
2710 &gEfiDevicePathProtocolGuid
,
2714 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2716 // Routing data does not match any known driver.
2717 // Set Progress to the 'G' in "GUID" of the routing header.
2719 FreePool (DevicePath
);
2720 *Progress
= StringPtr
;
2721 FreePool (ConfigResp
);
2722 return EFI_NOT_FOUND
;
2726 FreePool (DevicePath
);
2729 // Call corresponding ConfigAccess protocol to route settings
2731 Status
= gBS
->HandleProtocol (
2733 &gEfiHiiConfigAccessProtocolGuid
,
2734 (VOID
**) &ConfigAccess
2736 ASSERT_EFI_ERROR (Status
);
2738 Status
= ConfigAccess
->RouteConfig (
2744 if (EFI_ERROR (Status
)) {
2746 // AccessProgress indicates the parsing progress on <ConfigResp>.
2747 // Map it to the progress on <MultiConfigResp> then return it.
2749 *Progress
= StrStr (StringPtr
, AccessProgress
);
2751 FreePool (ConfigResp
);
2755 FreePool (ConfigResp
);
2759 // Go to next <ConfigResp> (skip '&').
2761 StringPtr
+= Length
;
2762 if (*StringPtr
== 0) {
2763 *Progress
= StringPtr
;
2776 This helper function is to be called by drivers to map configuration data
2777 stored in byte array ("block") formats such as UEFI Variables into current
2778 configuration strings.
2780 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2782 @param ConfigRequest A null-terminated Unicode string in
2783 <ConfigRequest> format.
2784 @param Block Array of bytes defining the block's configuration.
2785 @param BlockSize Length in bytes of Block.
2786 @param Config Filled-in configuration string. String allocated
2787 by the function. Returned only if call is
2788 successful. It is <ConfigResp> string format.
2789 @param Progress A pointer to a string filled in with the offset of
2790 the most recent & before the first failing
2791 name/value pair (or the beginning of the string if
2792 the failure is in the first name / value pair) or
2793 the terminating NULL if all was successful.
2795 @retval EFI_SUCCESS The request succeeded. Progress points to the null
2796 terminator at the end of the ConfigRequest
2798 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
2799 points to the first character of ConfigRequest.
2800 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
2801 Block parameter would result in this type of
2802 error. Progress points to the first character of
2804 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
2805 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
2806 Block is left updated and Progress points at
2807 the "&" preceding the first non-<BlockName>.
2813 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2814 IN CONST EFI_STRING ConfigRequest
,
2815 IN CONST UINT8
*Block
,
2816 IN CONST UINTN BlockSize
,
2817 OUT EFI_STRING
*Config
,
2818 OUT EFI_STRING
*Progress
2821 HII_DATABASE_PRIVATE_DATA
*Private
;
2822 EFI_STRING StringPtr
;
2830 EFI_STRING ValueStr
;
2831 EFI_STRING ConfigElement
;
2836 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
2837 return EFI_INVALID_PARAMETER
;
2840 if (Block
== NULL
|| ConfigRequest
== NULL
) {
2841 *Progress
= ConfigRequest
;
2842 return EFI_INVALID_PARAMETER
;
2846 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2847 ASSERT (Private
!= NULL
);
2849 StringPtr
= ConfigRequest
;
2852 ConfigElement
= NULL
;
2855 // Allocate a fix length of memory to store Results. Reallocate memory for
2856 // Results if this fix length is insufficient.
2858 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2859 if (*Config
== NULL
) {
2860 return EFI_OUT_OF_RESOURCES
;
2866 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2867 *Progress
= StringPtr
;
2868 Status
= EFI_INVALID_PARAMETER
;
2871 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
2874 if (*StringPtr
== 0) {
2875 *Progress
= StringPtr
- 1;
2876 Status
= EFI_INVALID_PARAMETER
;
2880 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
2883 if (*StringPtr
== 0) {
2884 *Progress
= StringPtr
- 1;
2885 Status
= EFI_INVALID_PARAMETER
;
2894 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
2896 Length
= StringPtr
- ConfigRequest
;
2897 CopyMem (*Config
, ConfigRequest
, Length
* sizeof (CHAR16
));
2900 // Parse each <RequestElement> if exists
2901 // Only <BlockName> format is supported by this help function.
2902 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
2904 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
2906 // Back up the header of one <BlockName>
2910 StringPtr
+= StrLen (L
"OFFSET=");
2914 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2915 if (Status
== EFI_OUT_OF_RESOURCES
) {
2916 *Progress
= ConfigRequest
;
2923 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2925 FreePool (TmpBuffer
);
2927 StringPtr
+= Length
;
2928 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
2929 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
2930 Status
= EFI_INVALID_PARAMETER
;
2933 StringPtr
+= StrLen (L
"&WIDTH=");
2938 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2939 if (Status
== EFI_OUT_OF_RESOURCES
) {
2940 *Progress
= ConfigRequest
;
2947 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
2949 FreePool (TmpBuffer
);
2951 StringPtr
+= Length
;
2952 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
2953 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
2954 Status
= EFI_INVALID_PARAMETER
;
2959 // Calculate Value and convert it to hex string.
2961 if (Offset
+ Width
> BlockSize
) {
2962 *Progress
= StringPtr
;
2963 Status
= EFI_DEVICE_ERROR
;
2967 Value
= (UINT8
*) AllocateZeroPool (Width
);
2968 if (Value
== NULL
) {
2969 *Progress
= ConfigRequest
;
2970 Status
= EFI_OUT_OF_RESOURCES
;
2974 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
2976 Length
= Width
* 2 + 1;
2977 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2978 if (ValueStr
== NULL
) {
2979 *Progress
= ConfigRequest
;
2980 Status
= EFI_OUT_OF_RESOURCES
;
2984 TemString
= ValueStr
;
2985 TemBuffer
= Value
+ Width
- 1;
2986 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
2987 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
2994 // Build a ConfigElement
2996 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
2997 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
2998 if (ConfigElement
== NULL
) {
2999 Status
= EFI_OUT_OF_RESOURCES
;
3002 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
3003 if (*StringPtr
== 0) {
3004 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
3006 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
3007 StrCat (ConfigElement
, L
"VALUE=");
3008 StrCat (ConfigElement
, ValueStr
);
3010 AppendToMultiString (Config
, ConfigElement
);
3012 FreePool (ConfigElement
);
3013 FreePool (ValueStr
);
3014 ConfigElement
= NULL
;
3018 // If '\0', parsing is finished. Otherwise skip '&' to continue
3020 if (*StringPtr
== 0) {
3023 AppendToMultiString (Config
, L
"&");
3028 if (*StringPtr
!= 0) {
3029 *Progress
= StringPtr
- 1;
3030 Status
= EFI_INVALID_PARAMETER
;
3034 HiiToLower (*Config
);
3035 *Progress
= StringPtr
;
3039 if (*Config
!= NULL
) {
3043 if (ValueStr
!= NULL
) {
3044 FreePool (ValueStr
);
3046 if (Value
!= NULL
) {
3049 if (ConfigElement
!= NULL
) {
3050 FreePool (ConfigElement
);
3059 This helper function is to be called by drivers to map configuration strings
3060 to configurations stored in byte array ("block") formats such as UEFI Variables.
3062 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3064 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
3065 format. It can be ConfigAltResp format string.
3066 @param Block A possibly null array of bytes representing the
3067 current block. Only bytes referenced in the
3068 ConfigResp string in the block are modified. If
3069 this parameter is null or if the *BlockSize
3070 parameter is (on input) shorter than required by
3071 the Configuration string, only the BlockSize
3072 parameter is updated and an appropriate status
3073 (see below) is returned.
3074 @param BlockSize The length of the Block in units of UINT8. On
3075 input, this is the size of the Block. On output,
3076 if successful, contains the index of the last
3077 modified byte in the Block.
3078 @param Progress On return, points to an element of the ConfigResp
3079 string filled in with the offset of the most
3080 recent '&' before the first failing name / value
3081 pair (or the beginning of the string if the
3082 failure is in the first name / value pair) or the
3083 terminating NULL if all was successful.
3085 @retval EFI_SUCCESS The request succeeded. Progress points to the null
3086 terminator at the end of the ConfigResp string.
3087 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
3088 points to the first character of ConfigResp.
3089 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
3090 Block parameter would result in this type of
3091 error. Progress points to the first character of
3093 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
3094 value pair. Block is left updated and
3095 Progress points at the '&' preceding the first
3102 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3103 IN CONST EFI_STRING ConfigResp
,
3104 IN OUT UINT8
*Block
,
3105 IN OUT UINTN
*BlockSize
,
3106 OUT EFI_STRING
*Progress
3109 HII_DATABASE_PRIVATE_DATA
*Private
;
3110 EFI_STRING StringPtr
;
3119 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
3120 return EFI_INVALID_PARAMETER
;
3123 if (ConfigResp
== NULL
|| Block
== NULL
) {
3124 *Progress
= ConfigResp
;
3125 return EFI_INVALID_PARAMETER
;
3128 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
3129 ASSERT (Private
!= NULL
);
3131 StringPtr
= ConfigResp
;
3132 BufferSize
= *BlockSize
;
3138 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3139 *Progress
= StringPtr
;
3140 Status
= EFI_INVALID_PARAMETER
;
3143 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
3146 if (*StringPtr
== 0) {
3147 *Progress
= StringPtr
;
3148 Status
= EFI_INVALID_PARAMETER
;
3152 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
3155 if (*StringPtr
== 0) {
3156 *Progress
= StringPtr
;
3157 Status
= EFI_INVALID_PARAMETER
;
3166 // Parse each <ConfigElement> if exists
3167 // Only <BlockConfig> format is supported by this help function.
3168 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
3170 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
3171 StringPtr
+= StrLen (L
"OFFSET=");
3175 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3176 if (EFI_ERROR (Status
)) {
3177 *Progress
= ConfigResp
;
3184 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3186 FreePool (TmpBuffer
);
3188 StringPtr
+= Length
;
3189 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3190 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
3191 Status
= EFI_INVALID_PARAMETER
;
3194 StringPtr
+= StrLen (L
"&WIDTH=");
3199 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3200 if (Status
== EFI_OUT_OF_RESOURCES
) {
3201 *Progress
= ConfigResp
;
3208 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3210 FreePool (TmpBuffer
);
3212 StringPtr
+= Length
;
3213 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
3214 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
3215 Status
= EFI_INVALID_PARAMETER
;
3218 StringPtr
+= StrLen (L
"&VALUE=");
3223 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
3224 if (EFI_ERROR (Status
)) {
3225 *Progress
= ConfigResp
;
3229 StringPtr
+= Length
;
3230 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3231 *Progress
= StringPtr
- Length
- 7;
3232 Status
= EFI_INVALID_PARAMETER
;
3237 // Update the Block with configuration info
3240 if (Offset
+ Width
> BufferSize
) {
3241 return EFI_DEVICE_ERROR
;
3244 CopyMem (Block
+ Offset
, Value
, Width
);
3245 *BlockSize
= Offset
+ Width
- 1;
3251 // If '\0', parsing is finished. Otherwise skip '&' to continue
3253 if (*StringPtr
== 0) {
3261 // The input string is ConfigAltResp format.
3263 if ((*StringPtr
!= 0) && (StrnCmp (StringPtr
, L
"&GUID=", StrLen (L
"&GUID=")) != 0)) {
3264 *Progress
= StringPtr
- 1;
3265 Status
= EFI_INVALID_PARAMETER
;
3269 *Progress
= StringPtr
+ StrLen (StringPtr
);
3274 if (Value
!= NULL
) {
3282 This helper function is to be called by drivers to extract portions of
3283 a larger configuration string.
3285 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3287 @param Configuration A null-terminated Unicode string in
3288 <MultiConfigAltResp> format. It is <ConfigAltResp> format.
3289 @param Guid A pointer to the GUID value to search for in the
3290 routing portion of the ConfigResp string when
3291 retrieving the requested data. If Guid is NULL,
3292 then all GUID values will be searched for.
3293 @param Name A pointer to the NAME value to search for in the
3294 routing portion of the ConfigResp string when
3295 retrieving the requested data. If Name is NULL,
3296 then all Name values will be searched for.
3297 @param DevicePath A pointer to the PATH value to search for in the
3298 routing portion of the ConfigResp string when
3299 retrieving the requested data. If DevicePath is
3300 NULL, then all DevicePath values will be searched
3302 @param AltCfgId A pointer to the ALTCFG value to search for in the
3303 routing portion of the ConfigResp string when
3304 retrieving the requested data. If this parameter
3305 is NULL, then the current setting will be
3307 @param AltCfgResp A pointer to a buffer which will be allocated by
3308 the function which contains the retrieved string
3309 as requested. This buffer is only allocated if
3310 the call was successful. It is <ConfigResp> format.
3312 @retval EFI_SUCCESS The request succeeded. The requested data was
3313 extracted and placed in the newly allocated
3315 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
3316 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
3317 @retval EFI_NOT_FOUND Target for the specified routing data was not
3324 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3325 IN CONST EFI_STRING Configuration
,
3326 IN CONST EFI_GUID
*Guid
,
3327 IN CONST EFI_STRING Name
,
3328 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3329 IN CONST UINT16
*AltCfgId
,
3330 OUT EFI_STRING
*AltCfgResp
3334 EFI_STRING StringPtr
;
3335 EFI_STRING HdrStart
;
3342 EFI_STRING AltIdStr
;
3359 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
3360 return EFI_INVALID_PARAMETER
;
3363 StringPtr
= Configuration
;
3364 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3365 return EFI_INVALID_PARAMETER
;
3369 // Generate the sub string for later matching.
3371 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
3374 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
3375 (VOID
*) DevicePath
,
3379 if (AltCfgId
!= NULL
) {
3380 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
3383 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
3385 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
3388 while (*StringPtr
!= 0) {
3390 // Try to match the GUID
3393 TmpPtr
= StrStr (StringPtr
, GuidStr
);
3394 if (TmpPtr
== NULL
) {
3395 Status
= EFI_NOT_FOUND
;
3401 // Jump to <NameHdr>
3404 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
3406 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
3407 if (StringPtr
== NULL
) {
3408 Status
= EFI_NOT_FOUND
;
3416 // Try to match the NAME
3418 if (GuidFlag
&& !NameFlag
) {
3419 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
3423 // Jump to <PathHdr>
3426 StringPtr
+= StrLen (NameStr
);
3428 StringPtr
= StrStr (StringPtr
, L
"PATH=");
3429 if (StringPtr
== NULL
) {
3430 Status
= EFI_NOT_FOUND
;
3439 // Try to match the DevicePath
3441 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
3442 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
3447 // Jump to '&' before <DescHdr> or <ConfigBody>
3449 if (DevicePath
!= NULL
) {
3450 StringPtr
+= StrLen (PathStr
);
3452 StringPtr
= StrStr (StringPtr
, L
"&");
3453 if (StringPtr
== NULL
) {
3454 Status
= EFI_NOT_FOUND
;
3465 // Try to match the AltCfgId
3467 if (GuidFlag
&& NameFlag
&& PathFlag
) {
3468 if (AltCfgId
== NULL
) {
3470 // Return Current Setting when AltCfgId is NULL.
3472 Status
= OutputConfigBody (StringPtr
, &Result
);
3476 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
3478 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
3484 // Skip AltIdStr and &
3486 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
3487 Status
= OutputConfigBody (StringPtr
, &Result
);
3493 Status
= EFI_NOT_FOUND
;
3497 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
3499 // Copy the <ConfigHdr> and <ConfigBody>
3501 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
3502 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3503 if (*AltCfgResp
== NULL
) {
3504 Status
= EFI_OUT_OF_RESOURCES
;
3506 StrnCpy (*AltCfgResp
, HdrStart
, HdrEnd
- HdrStart
);
3507 StrCat (*AltCfgResp
, Result
);
3508 Status
= EFI_SUCCESS
;
3512 if (GuidStr
!= NULL
) {
3515 if (NameStr
!= NULL
) {
3518 if (PathStr
!= NULL
) {
3521 if (AltIdStr
!= NULL
) {
3522 FreePool (AltIdStr
);
3524 if (Result
!= NULL
) {