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 DevicePathData Binary of a UEFI device path.
66 @retval EFI_NOT_FOUND The device path is not invalid.
67 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
68 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
69 @retval EFI_SUCCESS The device path is retrieved and translated to
76 OUT UINT8
**DevicePathData
81 UINT8
*DevicePathBuffer
;
85 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
88 if (String
== NULL
|| DevicePathData
== NULL
) {
89 return EFI_INVALID_PARAMETER
;
93 // Find the 'PATH=' of <PathHdr> and skip it.
95 for (; (*String
!= 0 && StrnCmp (String
, L
"PATH=", StrLen (L
"PATH=")) != 0); String
++);
97 return EFI_INVALID_PARAMETER
;
100 // Check whether path data does exist.
102 String
+= StrLen (L
"PATH=");
104 return EFI_INVALID_PARAMETER
;
109 // The content between 'PATH=' of <ConfigHdr> and '&' of next element
110 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding
111 // of UEFI device path.
113 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
115 // Check DevicePath Length
117 if (((Length
+ 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
118 return EFI_NOT_FOUND
;
122 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
123 // as the device path resides in RAM memory.
124 // Translate the data into binary.
126 DevicePathBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
127 if (DevicePathBuffer
== NULL
) {
128 return EFI_OUT_OF_RESOURCES
;
132 // Convert DevicePath
134 ZeroMem (TemStr
, sizeof (TemStr
));
135 for (Index
= 0; Index
< Length
; Index
++) {
136 TemStr
[0] = PathHdr
[Index
];
137 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
138 if ((Index
& 1) == 0) {
139 DevicePathBuffer
[Index
/2] = DigitUint8
;
141 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
146 // Validate DevicePath
148 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) DevicePathBuffer
;
149 while (!IsDevicePathEnd (DevicePath
)) {
150 if ((DevicePath
->Type
== 0) || (DevicePath
->SubType
== 0) || (DevicePathNodeLength (DevicePath
) < sizeof (EFI_DEVICE_PATH_PROTOCOL
))) {
152 // Invalid device path
154 FreePool (DevicePathBuffer
);
155 return EFI_NOT_FOUND
;
157 DevicePath
= NextDevicePathNode (DevicePath
);
161 // return the device path
163 *DevicePathData
= DevicePathBuffer
;
168 Converts the unicode character of the string from uppercase to lowercase.
169 This is a internal function.
171 @param Str String to be converted
177 IN EFI_STRING ConfigString
183 ASSERT (ConfigString
!= NULL
);
186 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
188 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
189 if (*String
== L
'=') {
191 } else if (*String
== L
'&') {
193 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
194 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
202 Generate a sub string then output it.
204 This is a internal function.
206 @param String A constant string which is the prefix of the to be
207 generated string, e.g. GUID=
209 @param BufferLen The length of the Buffer in bytes.
211 @param Buffer Points to a buffer which will be converted to be the
212 content of the generated string.
214 @param Flag If 1, the buffer contains data for the value of GUID or PATH stored in
215 UINT8 *; if 2, the buffer contains unicode string for the value of NAME;
216 if 3, the buffer contains other data.
218 @param SubStr Points to the output string. It's caller's
219 responsibility to free this buffer.
225 IN CONST EFI_STRING String
,
229 OUT EFI_STRING
*SubStr
234 EFI_STRING StringHeader
;
240 ASSERT (String
!= NULL
&& SubStr
!= NULL
);
242 if (Buffer
== NULL
) {
243 *SubStr
= AllocateCopyPool (StrSize (String
), String
);
244 ASSERT (*SubStr
!= NULL
);
249 // Header + Data + '&' + '\0'
251 Length
= StrLen (String
) + BufferLen
* 2 + 1 + 1;
252 Str
= AllocateZeroPool (Length
* sizeof (CHAR16
));
253 ASSERT (Str
!= NULL
);
255 StrCpy (Str
, String
);
256 Length
= (BufferLen
* 2 + 1) * sizeof (CHAR16
);
258 StringHeader
= Str
+ StrLen (String
);
259 TemString
= (CHAR16
*) StringHeader
;
264 // Convert Buffer to Hex String in reverse order
266 TemBuffer
= ((UINT8
*) Buffer
);
267 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
++) {
268 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
273 // Check buffer is enough
275 TemName
= (CHAR16
*) Buffer
;
276 ASSERT ((BufferLen
* 2 + 1) >= (StrLen (TemName
) * 4 + 1));
278 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
280 for (; *TemName
!= L
'\0'; TemName
++) {
281 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
286 // Convert Buffer to Hex String
288 TemBuffer
= ((UINT8
*) Buffer
) + BufferLen
- 1;
289 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
--) {
290 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
298 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
308 Retrieve the <ConfigBody> from String then output it.
310 This is a internal function.
312 @param String A sub string of a configuration string in
313 <MultiConfigAltResp> format.
314 @param ConfigBody Points to the output string. It's caller's
315 responsibility to free this buffer.
317 @retval EFI_INVALID_PARAMETER There is no form package in current hii database.
318 @retval EFI_OUT_OF_RESOURCES Not enough memory to finish this operation.
319 @retval EFI_SUCCESS All existing storage is exported.
324 IN EFI_STRING String
,
325 OUT EFI_STRING
*ConfigBody
332 if (String
== NULL
|| ConfigBody
== NULL
) {
333 return EFI_INVALID_PARAMETER
;
337 // The setting information should start OFFSET, not ALTCFG.
339 if (StrnCmp (String
, L
"&ALTCFG=", StrLen (L
"&ALTCFG=")) == 0) {
340 return EFI_INVALID_PARAMETER
;
343 TmpPtr
= StrStr (String
, L
"GUID=");
344 if (TmpPtr
== NULL
) {
346 // It is the last <ConfigResp> of the incoming configuration string.
348 Result
= AllocateCopyPool (StrSize (String
), String
);
349 if (Result
== NULL
) {
350 return EFI_OUT_OF_RESOURCES
;
352 *ConfigBody
= Result
;
357 Length
= TmpPtr
- String
;
358 Result
= AllocateCopyPool (Length
* sizeof (CHAR16
), String
);
359 if (Result
== NULL
) {
360 return EFI_OUT_OF_RESOURCES
;
363 *(Result
+ Length
- 1) = 0;
364 *ConfigBody
= Result
;
369 Append a string to a multi-string format.
371 This is a internal function.
373 @param MultiString String in <MultiConfigRequest>,
374 <MultiConfigAltResp>, or <MultiConfigResp>. On
375 input, the buffer length of this string is
376 MAX_STRING_LENGTH. On output, the buffer length
378 @param AppendString NULL-terminated Unicode string.
380 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
381 @retval EFI_SUCCESS AppendString is append to the end of MultiString
385 AppendToMultiString (
386 IN OUT EFI_STRING
*MultiString
,
387 IN EFI_STRING AppendString
390 UINTN AppendStringSize
;
391 UINTN MultiStringSize
;
393 if (MultiString
== NULL
|| *MultiString
== NULL
|| AppendString
== NULL
) {
394 return EFI_INVALID_PARAMETER
;
397 AppendStringSize
= StrSize (AppendString
);
398 MultiStringSize
= StrSize (*MultiString
);
401 // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.
403 if (MultiStringSize
+ AppendStringSize
> MAX_STRING_LENGTH
||
404 MultiStringSize
> MAX_STRING_LENGTH
) {
405 *MultiString
= (EFI_STRING
) ReallocatePool (
407 MultiStringSize
+ AppendStringSize
,
408 (VOID
*) (*MultiString
)
410 ASSERT (*MultiString
!= NULL
);
413 // Append the incoming string
415 StrCat (*MultiString
, AppendString
);
422 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
424 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
426 This is a internal function.
428 @param StringPtr String in <BlockConfig> format and points to the
429 first character of <Number>.
430 @param Number The output value. Caller takes the responsibility
432 @param Len Length of the <Number>, in characters.
434 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
436 @retval EFI_SUCCESS Value of <Number> is outputted in Number
442 IN EFI_STRING StringPtr
,
456 ASSERT (StringPtr
!= NULL
&& Number
!= NULL
&& Len
!= NULL
);
457 ASSERT (*StringPtr
!= L
'\0');
462 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
465 *Len
= StringPtr
- TmpPtr
;
468 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
470 Status
= EFI_OUT_OF_RESOURCES
;
473 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
474 *(Str
+ *Len
) = L
'\0';
476 Length
= (Length
+ 1) / 2;
477 Buf
= (UINT8
*) AllocateZeroPool (Length
);
479 Status
= EFI_OUT_OF_RESOURCES
;
484 ZeroMem (TemStr
, sizeof (TemStr
));
485 for (Index
= 0; Index
< Length
; Index
++) {
486 TemStr
[0] = Str
[Length
- Index
- 1];
487 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
488 if ((Index
& 1) == 0) {
489 Buf
[Index
/2] = DigitUint8
;
491 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
496 Status
= EFI_SUCCESS
;
507 This function merges DefaultAltCfgResp string into AltCfgResp string for
508 the missing AltCfgId in AltCfgResq.
510 @param AltCfgResp Pointer to a null-terminated Unicode string in
511 <ConfigAltResp> format. The default value string
512 will be merged into it.
513 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
514 <MultiConfigAltResp> format. The default value
515 string may contain more than one ConfigAltResp
516 string for the different varstore buffer.
518 @retval EFI_SUCCESS The merged string returns.
519 @retval EFI_INVALID_PARAMETER *AltCfgResp is to NULL.
524 IN OUT EFI_STRING
*AltCfgResp
,
525 IN EFI_STRING DefaultAltCfgResp
528 EFI_STRING StringPtrDefault
;
529 EFI_STRING StringPtrEnd
;
531 EFI_STRING StringPtr
;
532 EFI_STRING AltConfigHdr
;
534 UINTN SizeAltCfgResp
;
536 if (*AltCfgResp
== NULL
) {
537 return EFI_INVALID_PARAMETER
;
541 // Get the requestr ConfigHdr
544 StringPtr
= *AltCfgResp
;
547 // Find <ConfigHdr> GUID=...&NAME=...&PATH=...
549 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
550 return EFI_INVALID_PARAMETER
;
552 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
555 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
558 if (*StringPtr
== L
'\0') {
559 return EFI_INVALID_PARAMETER
;
561 StringPtr
+= StrLen (L
"&PATH=");
562 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
565 HeaderLength
= StringPtr
- *AltCfgResp
;
568 // Construct AltConfigHdr string "&<ConfigHdr>&ALTCFG=XXXX\0"
569 // |1| StrLen (ConfigHdr) | 8 | 4 | 1 |
571 AltConfigHdr
= AllocateZeroPool ((1 + HeaderLength
+ 8 + 4 + 1) * sizeof (CHAR16
));
572 if (AltConfigHdr
== NULL
) {
573 return EFI_OUT_OF_RESOURCES
;
575 StrCpy (AltConfigHdr
, L
"&");
576 StrnCat (AltConfigHdr
, *AltCfgResp
, HeaderLength
);
577 StrCat (AltConfigHdr
, L
"&ALTCFG=");
578 HeaderLength
= StrLen (AltConfigHdr
);
580 StringPtrDefault
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
581 while (StringPtrDefault
!= NULL
) {
585 StrnCat (AltConfigHdr
, StringPtrDefault
+ HeaderLength
, 4);
586 StringPtr
= StrStr (*AltCfgResp
, AltConfigHdr
);
589 // Append the found default value string to the input AltCfgResp
591 if (StringPtr
== NULL
) {
592 StringPtrEnd
= StrStr (StringPtrDefault
+ 1, L
"&GUID");
593 SizeAltCfgResp
= StrSize (*AltCfgResp
);
594 if (StringPtrEnd
== NULL
) {
596 // No more default string is found.
598 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
600 SizeAltCfgResp
+ StrSize (StringPtrDefault
),
601 (VOID
*) (*AltCfgResp
)
603 if (*AltCfgResp
== NULL
) {
604 FreePool (AltConfigHdr
);
605 return EFI_OUT_OF_RESOURCES
;
607 StrCat (*AltCfgResp
, StringPtrDefault
);
610 TempChar
= *StringPtrEnd
;
611 *StringPtrEnd
= L
'\0';
612 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
614 SizeAltCfgResp
+ StrSize (StringPtrDefault
),
615 (VOID
*) (*AltCfgResp
)
617 if (*AltCfgResp
== NULL
) {
618 FreePool (AltConfigHdr
);
619 return EFI_OUT_OF_RESOURCES
;
621 StrCat (*AltCfgResp
, StringPtrDefault
);
622 *StringPtrEnd
= TempChar
;
627 // Find next AltCfg String
629 *(AltConfigHdr
+ HeaderLength
) = L
'\0';
630 StringPtrDefault
= StrStr (StringPtrDefault
+ 1, AltConfigHdr
);
633 FreePool (AltConfigHdr
);
638 This function finds the matched DefaultName for the input DefaultId
640 @param DefaultIdArray Array stores the map table between DefaultId and DefaultName.
641 @param VarDefaultId Default Id
642 @param VarDefaultName Default Name string ID for the input default ID.
644 @retval EFI_SUCCESS The mapped default name string ID is found.
645 @retval EFI_NOT_FOUND The mapped default name string ID is not found.
649 IN IFR_DEFAULT_DATA
*DefaultIdArray
,
650 IN UINT16 VarDefaultId
,
651 OUT EFI_STRING_ID
*VarDefaultName
655 IFR_DEFAULT_DATA
*DefaultData
;
657 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
658 DefaultData
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
659 if (DefaultData
->DefaultId
== VarDefaultId
) {
660 *VarDefaultName
= DefaultData
->DefaultName
;
665 return EFI_NOT_FOUND
;
669 This function inserts new DefaultValueData into the BlockData DefaultValue array.
671 @param BlockData The BlockData is updated to add new default value.
672 @param DefaultValueData The DefaultValue is added.
677 IN IFR_BLOCK_DATA
*BlockData
,
678 IN IFR_DEFAULT_DATA
*DefaultValueData
682 IFR_DEFAULT_DATA
*DefaultValueArray
;
684 for (Link
= BlockData
->DefaultValueEntry
.ForwardLink
; Link
!= &BlockData
->DefaultValueEntry
; Link
= Link
->ForwardLink
) {
685 DefaultValueArray
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
686 if (DefaultValueArray
->DefaultId
== DefaultValueData
->DefaultId
) {
687 if (DefaultValueData
->OpCode
== EFI_IFR_DEFAULT_OP
) {
689 // Update the default value array in BlockData.
691 DefaultValueArray
->Value
= DefaultValueData
->Value
;
692 } else if (DefaultValueArray
->OpCode
!= EFI_IFR_DEFAULT_OP
) {
694 // Update the default value array in BlockData.
696 DefaultValueArray
->Value
= DefaultValueData
->Value
;
698 FreePool (DefaultValueData
);
700 } else if (DefaultValueArray
->DefaultId
> DefaultValueData
->DefaultId
) {
702 // Insert new default value data in the front of this default value array.
704 InsertTailList (Link
, &DefaultValueData
->Entry
);
710 // Insert new default value data in tail.
712 InsertTailList (Link
, &DefaultValueData
->Entry
);
717 This function inserts new BlockData into the block link
719 @param BlockLink The list entry points to block array.
720 @param BlockData The point to BlockData is added.
725 IN LIST_ENTRY
*BlockLink
,
726 IN IFR_BLOCK_DATA
**BlockData
730 IFR_BLOCK_DATA
*BlockArray
;
731 IFR_BLOCK_DATA
*BlockSingleData
;
733 BlockSingleData
= *BlockData
;
736 // Insert block data in its Offset and Width order.
738 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
739 BlockArray
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
740 if (BlockArray
->Offset
== BlockSingleData
->Offset
) {
741 if (BlockArray
->Width
> BlockSingleData
->Width
) {
743 // Insert this block data in the front of block array
745 InsertTailList (Link
, &BlockSingleData
->Entry
);
749 if (BlockArray
->Width
== BlockSingleData
->Width
) {
751 // The same block array has been added.
753 FreePool (BlockSingleData
);
754 *BlockData
= BlockArray
;
757 } else if (BlockArray
->Offset
> BlockSingleData
->Offset
) {
759 // Insert new block data in the front of block array
761 InsertTailList (Link
, &BlockSingleData
->Entry
);
767 // Add new block data into the tail.
769 InsertTailList (Link
, &BlockSingleData
->Entry
);
774 This function checks VarOffset and VarWidth is in the block range.
776 @param BlockArray The block array is to be checked.
777 @param VarOffset Offset of var to the structure
778 @param VarWidth Width of var.
780 @retval TRUE This Var is in the block range.
781 @retval FALSE This Var is not in the block range.
785 IN IFR_BLOCK_DATA
*RequestBlockArray
,
791 IFR_BLOCK_DATA
*BlockData
;
794 // No Request Block array, all vars are got.
796 if (RequestBlockArray
== NULL
) {
801 // Check the input var is in the request block range.
803 for (Link
= RequestBlockArray
->Entry
.ForwardLink
; Link
!= &RequestBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
804 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
805 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
814 This function parses Form Package to get the block array and the default
815 value array according to the request ConfigHdr.
817 @param Package Pointer to the form package data.
818 @param PackageLength Length of the pacakge.
819 @param ConfigHdr Request string ConfigHdr. If it is NULL,
820 the first found varstore will be as ConfigHdr.
821 @param RequestBlockArray The block array is retrieved from the request string.
822 @param VarStorageData VarStorage structure contains the got block and default value.
823 @param PIfrDefaultIdArray Point to the got default id and default name array.
825 @retval EFI_SUCCESS The block array and the default value array are got.
826 @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges
828 @retval EFI_OUT_OF_RESOURCES No enough memory.
834 IN UINT32 PackageLenth
,
835 IN EFI_STRING ConfigHdr
,
836 IN IFR_BLOCK_DATA
*RequestBlockArray
,
837 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
838 OUT IFR_DEFAULT_DATA
*DefaultIdArray
843 EFI_IFR_VARSTORE
*IfrVarStore
;
844 EFI_IFR_OP_HEADER
*IfrOpHdr
;
845 EFI_IFR_ONE_OF
*IfrOneOf
;
846 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
847 EFI_IFR_DEFAULT
*IfrDefault
;
848 EFI_IFR_ORDERED_LIST
*IfrOrderedList
;
849 EFI_IFR_CHECKBOX
*IfrCheckBox
;
850 EFI_IFR_PASSWORD
*IfrPassword
;
851 EFI_IFR_STRING
*IfrString
;
852 IFR_DEFAULT_DATA
*DefaultData
;
853 IFR_BLOCK_DATA
*BlockData
;
854 CHAR16
*VarStoreName
;
857 EFI_STRING_ID VarDefaultName
;
865 Status
= EFI_SUCCESS
;
873 // Go through the form package to parse OpCode one by one.
875 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
876 while (IfrOffset
< PackageLenth
) {
877 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (Package
+ IfrOffset
);
879 switch (IfrOpHdr
->OpCode
) {
880 case EFI_IFR_VARSTORE_OP
:
882 // VarStore is found. Don't need to search any more.
884 if (VarStorageData
->Size
!= 0) {
889 // Get the requied varstore information
890 // Add varstore by Guid and Name in ConfigHdr
891 // Make sure Offset is in varstore size and varstoreid
893 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
894 VarStoreName
= AllocateZeroPool (AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
) * sizeof (CHAR16
));
895 if (VarStoreName
== NULL
) {
896 Status
= EFI_OUT_OF_RESOURCES
;
899 AsciiStrToUnicodeStr ((CHAR8
*) IfrVarStore
->Name
, VarStoreName
);
901 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &IfrVarStore
->Guid
, 1, &GuidStr
);
902 GenerateSubStr (L
"NAME=", StrLen (VarStoreName
) * sizeof (CHAR16
), (VOID
*) VarStoreName
, 2, &NameStr
);
903 LengthString
= StrLen (GuidStr
);
904 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
905 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
906 if (TempStr
== NULL
) {
909 FreePool (VarStoreName
);
910 Status
= EFI_OUT_OF_RESOURCES
;
913 StrCpy (TempStr
, GuidStr
);
914 StrCat (TempStr
, NameStr
);
915 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
917 // Find the matched VarStore
919 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
);
920 VarStorageData
->VarStoreId
= IfrVarStore
->VarStoreId
;
921 VarStorageData
->Size
= IfrVarStore
->Size
;
922 VarStorageData
->Name
= VarStoreName
;
925 // No found, free the allocated memory
927 FreePool (VarStoreName
);
930 // Free alllocated temp string.
937 case EFI_IFR_DEFAULTSTORE_OP
:
939 // Add new the map between default id and default name.
941 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
942 if (DefaultData
== NULL
) {
943 Status
= EFI_OUT_OF_RESOURCES
;
946 DefaultData
->DefaultId
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
;
947 DefaultData
->DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
948 InsertTailList (&DefaultIdArray
->Entry
, &DefaultData
->Entry
);
952 case EFI_IFR_FORM_OP
:
954 // No matched varstore is found and directly return.
956 if (VarStorageData
->Size
== 0) {
957 Status
= EFI_SUCCESS
;
962 case EFI_IFR_ONE_OF_OP
:
963 case EFI_IFR_NUMERIC_OP
:
965 // Numeric and OneOf has the same opcode structure.
969 // Numeric and OneOf question is not in IFR Form. This IFR form is not valid.
971 if (VarStorageData
->Size
== 0) {
972 Status
= EFI_INVALID_PARAMETER
;
976 // Check whether this question is for the requested varstore.
978 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
979 if (IfrOneOf
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
984 // Get Offset/Width by Question header and OneOf Flags
986 VarOffset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
987 VarWidth
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
989 // Check whether this question is in requested block array.
991 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
993 // This question is not in the requested string. Skip it.
999 // Check this var question is in the var storage
1001 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1002 Status
= EFI_INVALID_PARAMETER
;
1009 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1010 if (BlockData
== NULL
) {
1011 Status
= EFI_OUT_OF_RESOURCES
;
1014 BlockData
->Offset
= VarOffset
;
1015 BlockData
->Width
= VarWidth
;
1016 BlockData
->QuestionId
= IfrOneOf
->Question
.QuestionId
;
1017 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1018 BlockData
->Scope
= IfrOpHdr
->Scope
;
1019 InitializeListHead (&BlockData
->DefaultValueEntry
);
1021 // Add Block Data into VarStorageData BlockEntry
1023 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1026 case EFI_IFR_ORDERED_LIST_OP
:
1028 // offset by question header
1029 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type
1030 // no default value and default id, how to define its default value?
1034 // OrderedList question is not in IFR Form. This IFR form is not valid.
1036 if (VarStorageData
->Size
== 0) {
1037 Status
= EFI_INVALID_PARAMETER
;
1041 // Check whether this question is for the requested varstore.
1043 IfrOrderedList
= (EFI_IFR_ORDERED_LIST
*) IfrOpHdr
;
1044 if (IfrOrderedList
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1049 // Get Offset/Width by Question header and OneOf Flags
1051 VarOffset
= IfrOrderedList
->Question
.VarStoreInfo
.VarOffset
;
1052 VarWidth
= IfrOrderedList
->MaxContainers
;
1055 // Check whether this question is in requested block array.
1057 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1059 // This question is not in the requested string. Skip it.
1065 // Check this var question is in the var storage
1067 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1068 Status
= EFI_INVALID_PARAMETER
;
1075 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1076 if (BlockData
== NULL
) {
1077 Status
= EFI_OUT_OF_RESOURCES
;
1080 BlockData
->Offset
= VarOffset
;
1081 BlockData
->Width
= VarWidth
;
1082 BlockData
->QuestionId
= IfrOrderedList
->Question
.QuestionId
;
1083 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1084 BlockData
->Scope
= IfrOpHdr
->Scope
;
1085 InitializeListHead (&BlockData
->DefaultValueEntry
);
1088 // Add Block Data into VarStorageData BlockEntry
1090 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1093 case EFI_IFR_CHECKBOX_OP
:
1095 // EFI_IFR_DEFAULT_OP
1096 // offset by question header
1097 // width is 1 sizeof (BOOLEAN)
1098 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.
1099 // value by DefaultOption
1100 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
1104 // CheckBox question is not in IFR Form. This IFR form is not valid.
1106 if (VarStorageData
->Size
== 0) {
1107 Status
= EFI_INVALID_PARAMETER
;
1111 // Check whether this question is for the requested varstore.
1113 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1114 if (IfrCheckBox
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1119 // Get Offset/Width by Question header and OneOf Flags
1121 VarOffset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1122 VarWidth
= sizeof (BOOLEAN
);
1125 // Check whether this question is in requested block array.
1127 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1129 // This question is not in the requested string. Skip it.
1135 // Check this var question is in the var storage
1137 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1138 Status
= EFI_INVALID_PARAMETER
;
1145 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1146 if (BlockData
== NULL
) {
1147 Status
= EFI_OUT_OF_RESOURCES
;
1150 BlockData
->Offset
= VarOffset
;
1151 BlockData
->Width
= VarWidth
;
1152 BlockData
->QuestionId
= IfrCheckBox
->Question
.QuestionId
;
1153 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1154 BlockData
->Scope
= IfrOpHdr
->Scope
;
1155 InitializeListHead (&BlockData
->DefaultValueEntry
);
1157 // Add Block Data into VarStorageData BlockEntry
1159 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1162 // Add default value by CheckBox Flags
1164 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) == EFI_IFR_CHECKBOX_DEFAULT
) {
1166 // Set standard ID to Manufacture ID and Get DefaultName String ID
1168 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1169 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1170 if (EFI_ERROR (Status
)) {
1174 // Prepare new DefaultValue
1176 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1177 if (DefaultData
== NULL
) {
1178 Status
= EFI_OUT_OF_RESOURCES
;
1181 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1182 DefaultData
->DefaultId
= VarDefaultId
;
1183 DefaultData
->DefaultName
= VarDefaultName
;
1184 DefaultData
->Value
= 1;
1186 // Add DefaultValue into current BlockData
1188 InsertDefaultValue (BlockData
, DefaultData
);
1191 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) == EFI_IFR_CHECKBOX_DEFAULT_MFG
) {
1193 // Set standard ID to Manufacture ID and Get DefaultName String ID
1195 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1196 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1197 if (EFI_ERROR (Status
)) {
1201 // Prepare new DefaultValue
1203 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1204 if (DefaultData
== NULL
) {
1205 Status
= EFI_OUT_OF_RESOURCES
;
1208 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1209 DefaultData
->DefaultId
= VarDefaultId
;
1210 DefaultData
->DefaultName
= VarDefaultName
;
1211 DefaultData
->Value
= 1;
1213 // Add DefaultValue into current BlockData
1215 InsertDefaultValue (BlockData
, DefaultData
);
1219 case EFI_IFR_STRING_OP
:
1221 // offset by question header
1222 // width MaxSize * sizeof (CHAR16)
1223 // no default value, only block array
1227 // String question is not in IFR Form. This IFR form is not valid.
1229 if (VarStorageData
->Size
== 0) {
1230 Status
= EFI_INVALID_PARAMETER
;
1234 // Check whether this question is for the requested varstore.
1236 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1237 if (IfrString
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1242 // Get Offset/Width by Question header and OneOf Flags
1244 VarOffset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1245 VarWidth
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1248 // Check whether this question is in requested block array.
1250 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1252 // This question is not in the requested string. Skip it.
1258 // Check this var question is in the var storage
1260 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1261 Status
= EFI_INVALID_PARAMETER
;
1268 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1269 if (BlockData
== NULL
) {
1270 Status
= EFI_OUT_OF_RESOURCES
;
1273 BlockData
->Offset
= VarOffset
;
1274 BlockData
->Width
= VarWidth
;
1275 BlockData
->QuestionId
= IfrString
->Question
.QuestionId
;
1276 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1277 InitializeListHead (&BlockData
->DefaultValueEntry
);
1280 // Add Block Data into VarStorageData BlockEntry
1282 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1285 // No default value for string.
1290 case EFI_IFR_PASSWORD_OP
:
1292 // offset by question header
1293 // width MaxSize * sizeof (CHAR16)
1294 // no default value, only block array
1298 // Password question is not in IFR Form. This IFR form is not valid.
1300 if (VarStorageData
->Size
== 0) {
1301 Status
= EFI_INVALID_PARAMETER
;
1305 // Check whether this question is for the requested varstore.
1307 IfrPassword
= (EFI_IFR_PASSWORD
*) IfrOpHdr
;
1308 if (IfrPassword
->Question
.VarStoreId
!= VarStorageData
->VarStoreId
) {
1313 // Get Offset/Width by Question header and OneOf Flags
1315 VarOffset
= IfrPassword
->Question
.VarStoreInfo
.VarOffset
;
1316 VarWidth
= (UINT16
) (IfrPassword
->MaxSize
* sizeof (UINT16
));
1319 // Check whether this question is in requested block array.
1321 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
)) {
1323 // This question is not in the requested string. Skip it.
1329 // Check this var question is in the var storage
1331 if ((VarOffset
+ VarWidth
) > VarStorageData
->Size
) {
1332 Status
= EFI_INVALID_PARAMETER
;
1339 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1340 if (BlockData
== NULL
) {
1341 Status
= EFI_OUT_OF_RESOURCES
;
1344 BlockData
->Offset
= VarOffset
;
1345 BlockData
->Width
= VarWidth
;
1346 BlockData
->QuestionId
= IfrPassword
->Question
.QuestionId
;
1347 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
1348 InitializeListHead (&BlockData
->DefaultValueEntry
);
1351 // Add Block Data into VarStorageData BlockEntry
1353 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
1356 // No default value for string.
1361 case EFI_IFR_ONE_OF_OPTION_OP
:
1363 // No matched block data is ignored.
1365 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1369 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1370 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1372 // Get ordered list option data type.
1374 if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_8
|| IfrOneOfOption
->Type
== EFI_IFR_TYPE_BOOLEAN
) {
1376 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_16
) {
1378 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_32
) {
1380 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_64
) {
1384 // Invalid ordered list option data type.
1386 Status
= EFI_INVALID_PARAMETER
;
1390 // Calculate Ordered list QuestionId width.
1392 BlockData
->Width
= (UINT16
) (BlockData
->Width
* VarWidth
);
1397 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) {
1399 // Set standard ID to Manufacture ID and Get DefaultName String ID
1401 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1402 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1403 if (EFI_ERROR (Status
)) {
1407 // Prepare new DefaultValue
1409 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1410 if (DefaultData
== NULL
) {
1411 Status
= EFI_OUT_OF_RESOURCES
;
1414 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1415 DefaultData
->DefaultId
= VarDefaultId
;
1416 DefaultData
->DefaultName
= VarDefaultName
;
1417 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1419 // Add DefaultValue into current BlockData
1421 InsertDefaultValue (BlockData
, DefaultData
);
1424 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
) {
1426 // Set default ID to Manufacture ID and Get DefaultName String ID
1428 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
1429 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1430 if (EFI_ERROR (Status
)) {
1434 // Prepare new DefaultValue
1436 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1437 if (DefaultData
== NULL
) {
1438 Status
= EFI_OUT_OF_RESOURCES
;
1441 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1442 DefaultData
->DefaultId
= VarDefaultId
;
1443 DefaultData
->DefaultName
= VarDefaultName
;
1444 DefaultData
->Value
= IfrOneOfOption
->Value
.u64
;
1446 // Add DefaultValue into current BlockData
1448 InsertDefaultValue (BlockData
, DefaultData
);
1452 case EFI_IFR_DEFAULT_OP
:
1454 // Update Current BlockData to the default value.
1456 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
1458 // No matched block data is ignored.
1463 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1465 // OrderedList Opcode is no default value.
1470 // Get the DefaultId and DefaultName String ID
1472 IfrDefault
= (EFI_IFR_DEFAULT
*) IfrOpHdr
;
1473 VarDefaultId
= IfrDefault
->DefaultId
;
1474 Status
= FindDefaultName (DefaultIdArray
, VarDefaultId
, &VarDefaultName
);
1475 if (EFI_ERROR (Status
)) {
1479 // Prepare new DefaultValue
1481 DefaultData
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1482 if (DefaultData
== NULL
) {
1483 Status
= EFI_OUT_OF_RESOURCES
;
1486 DefaultData
->OpCode
= IfrOpHdr
->OpCode
;
1487 DefaultData
->DefaultId
= VarDefaultId
;
1488 DefaultData
->DefaultName
= VarDefaultName
;
1489 DefaultData
->Value
= IfrDefault
->Value
.u64
;
1491 // Add DefaultValue into current BlockData
1493 InsertDefaultValue (BlockData
, DefaultData
);
1495 case EFI_IFR_END_OP
:
1497 // End Opcode is for Var question.
1499 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1504 if (BlockData
!= NULL
&& BlockData
->Scope
> 0) {
1505 BlockData
->Scope
= (UINT8
) (BlockData
->Scope
+ IfrOpHdr
->Scope
);
1510 IfrOffset
+= IfrOpHdr
->Length
;
1518 This function gets the full request string and full default value string by
1519 parsing IFR data in HII form packages.
1521 When Request points to NULL string, the request string and default value string
1522 for each varstore in form package will return.
1524 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1525 @param DevicePath Device Path which Hii Config Access Protocol is registered.
1526 @param Request Pointer to a null-terminated Unicode string in
1527 <ConfigRequest> format. When it doesn't contain
1528 any RequestElement, it will be updated to return
1529 the full RequestElement retrieved from IFR data.
1530 If it points to NULL, the request string for the first
1531 varstore in form package will be merged into a
1532 <MultiConfigRequest> format string and return.
1533 @param AltCfgResp Pointer to a null-terminated Unicode string in
1534 <ConfigAltResp> format. When the pointer is to NULL,
1535 the full default value string retrieved from IFR data
1536 will return. When the pinter is to a string, the
1537 full default value string retrieved from IFR data
1538 will be merged into the input string and return.
1539 When Request points to NULL, the default value string
1540 for each varstore in form package will be merged into
1541 a <MultiConfigAltResp> format string and return.
1542 @param PointerProgress Optional parameter, it can be be NULL.
1543 When it is not NULL, if Request is NULL, it returns NULL.
1544 On return, points to a character in the Request
1545 string. Points to the string's null terminator if
1546 request was successful. Points to the most recent
1547 & before the first failing name / value pair (or
1548 the beginning of the string if the failure is in
1549 the first name / value pair) if the request was
1551 @retval EFI_SUCCESS The Results string is set to the full request string.
1552 And AltCfgResp contains all default value string.
1553 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
1554 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string
1555 can't be found in Form package.
1556 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.
1557 @retval EFI_INVALID_PARAMETER Request points to NULL.
1562 GetFullStringFromHiiFormPackages (
1563 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1564 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1565 IN OUT EFI_STRING
*Request
,
1566 IN OUT EFI_STRING
*AltCfgResp
,
1567 OUT EFI_STRING
*PointerProgress OPTIONAL
1571 UINT8
*HiiFormPackage
;
1574 IFR_BLOCK_DATA
*RequestBlockArray
;
1575 IFR_BLOCK_DATA
*BlockData
;
1576 IFR_BLOCK_DATA
*NextBlockData
;
1577 IFR_DEFAULT_DATA
*DefaultValueData
;
1578 IFR_DEFAULT_DATA
*DefaultId
;
1579 IFR_DEFAULT_DATA
*DefaultIdArray
;
1580 IFR_VARSTORAGE_DATA
*VarStorageData
;
1581 EFI_STRING DefaultAltCfgResp
;
1582 EFI_STRING FullConfigRequest
;
1583 EFI_STRING ConfigHdr
;
1587 EFI_STRING StringPtr
;
1588 EFI_STRING Progress
;
1594 LIST_ENTRY
*LinkData
;
1595 LIST_ENTRY
*LinkDefault
;
1598 if (DataBaseRecord
== NULL
|| DevicePath
== NULL
|| Request
== NULL
|| AltCfgResp
== NULL
) {
1599 return EFI_INVALID_PARAMETER
;
1603 // Initialize the local variables.
1605 RequestBlockArray
= NULL
;
1606 DefaultIdArray
= NULL
;
1607 VarStorageData
= NULL
;
1608 DefaultAltCfgResp
= NULL
;
1609 FullConfigRequest
= NULL
;
1614 HiiFormPackage
= NULL
;
1618 Progress
= *Request
;
1621 // 0. Get Hii Form Package by HiiHandle
1623 Status
= ExportFormPackages (
1625 DataBaseRecord
->Handle
,
1626 DataBaseRecord
->PackageList
,
1632 if (EFI_ERROR (Status
)) {
1636 HiiFormPackage
= AllocatePool (ResultSize
);
1637 if (HiiFormPackage
== NULL
) {
1638 Status
= EFI_OUT_OF_RESOURCES
;
1643 // Get HiiFormPackage by HiiHandle
1645 PackageSize
= ResultSize
;
1647 Status
= ExportFormPackages (
1649 DataBaseRecord
->Handle
,
1650 DataBaseRecord
->PackageList
,
1656 if (EFI_ERROR (Status
)) {
1661 // 1. Get the request block array by Request String when Request string containts the block array.
1664 if (*Request
!= NULL
) {
1665 StringPtr
= *Request
;
1669 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1670 Status
= EFI_INVALID_PARAMETER
;
1673 StringPtr
+= StrLen (L
"GUID=");
1674 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1677 if (*StringPtr
== L
'\0') {
1678 Status
= EFI_INVALID_PARAMETER
;
1681 StringPtr
+= StrLen (L
"&NAME=");
1682 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1685 if (*StringPtr
== L
'\0') {
1686 Status
= EFI_INVALID_PARAMETER
;
1689 StringPtr
+= StrLen (L
"&PATH=");
1690 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1694 // Check the following string &OFFSET=
1696 if (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) != 0) {
1697 Progress
= StringPtr
;
1698 Status
= EFI_INVALID_PARAMETER
;
1700 } else if (*StringPtr
== L
'\0') {
1702 // No request block is found.
1707 if (StringPtr
!= NULL
) {
1709 // Init RequestBlockArray
1711 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1712 if (RequestBlockArray
== NULL
) {
1713 Status
= EFI_OUT_OF_RESOURCES
;
1716 InitializeListHead (&RequestBlockArray
->Entry
);
1719 // Get the request Block array from the request string
1724 // Parse each <RequestElement> if exists
1725 // Only <BlockName> format is supported by this help function.
1726 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1728 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1730 // Skip the OFFSET string
1732 Progress
= StringPtr
;
1733 StringPtr
+= StrLen (L
"&OFFSET=");
1737 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1738 if (EFI_ERROR (Status
)) {
1745 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1747 FreePool (TmpBuffer
);
1749 StringPtr
+= Length
;
1750 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1751 Status
= EFI_INVALID_PARAMETER
;
1754 StringPtr
+= StrLen (L
"&WIDTH=");
1759 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1760 if (EFI_ERROR (Status
)) {
1767 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1769 FreePool (TmpBuffer
);
1771 StringPtr
+= Length
;
1772 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1773 Status
= EFI_INVALID_PARAMETER
;
1780 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1781 if (BlockData
== NULL
) {
1782 Status
= EFI_OUT_OF_RESOURCES
;
1785 BlockData
->Offset
= Offset
;
1786 BlockData
->Width
= Width
;
1787 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
1790 // Skip &VALUE string if &VALUE does exists.
1792 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) == 0) {
1793 StringPtr
+= StrLen (L
"&VALUE=");
1798 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1799 if (EFI_ERROR (Status
)) {
1800 Status
= EFI_INVALID_PARAMETER
;
1804 StringPtr
+= Length
;
1805 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1806 Status
= EFI_INVALID_PARAMETER
;
1811 // If '\0', parsing is finished.
1813 if (*StringPtr
== 0) {
1819 // Merge the requested block data.
1821 Link
= RequestBlockArray
->Entry
.ForwardLink
;
1822 while ((Link
!= &RequestBlockArray
->Entry
) && (Link
->ForwardLink
!= &RequestBlockArray
->Entry
)) {
1823 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1824 NextBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1825 if ((NextBlockData
->Offset
>= BlockData
->Offset
) && (NextBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1826 if ((NextBlockData
->Offset
+ NextBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1827 BlockData
->Width
= (UINT16
) (NextBlockData
->Offset
+ NextBlockData
->Width
- BlockData
->Offset
);
1829 RemoveEntryList (Link
->ForwardLink
);
1830 FreePool (NextBlockData
);
1833 Link
= Link
->ForwardLink
;
1838 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
1842 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
1844 DefaultIdArray
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1845 if (DefaultIdArray
== NULL
) {
1846 Status
= EFI_OUT_OF_RESOURCES
;
1849 InitializeListHead (&DefaultIdArray
->Entry
);
1852 // Initialize VarStorageData to store the var store Block and Default value information.
1854 VarStorageData
= (IFR_VARSTORAGE_DATA
*) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA
));
1855 if (VarStorageData
== NULL
) {
1856 Status
= EFI_OUT_OF_RESOURCES
;
1859 InitializeListHead (&VarStorageData
->Entry
);
1860 InitializeListHead (&VarStorageData
->BlockEntry
);
1863 // Parse the opcode in form pacakge to get the default setting.
1865 Status
= ParseIfrData (HiiFormPackage
, (UINT32
) PackageSize
, *Request
, RequestBlockArray
, VarStorageData
, DefaultIdArray
);
1866 if (EFI_ERROR (Status
)) {
1871 // No requested varstore in IFR data and directly return
1873 if (VarStorageData
->Size
== 0) {
1874 Status
= EFI_SUCCESS
;
1879 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
1883 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
1885 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
1886 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
1889 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
1890 (VOID
*) DevicePath
,
1894 Length
= StrLen (GuidStr
);
1895 Length
= Length
+ StrLen (NameStr
);
1896 Length
= Length
+ StrLen (PathStr
) + 1;
1897 ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1898 if (ConfigHdr
== NULL
) {
1899 Status
= EFI_OUT_OF_RESOURCES
;
1902 StrCpy (ConfigHdr
, GuidStr
);
1903 StrCat (ConfigHdr
, NameStr
);
1904 StrCat (ConfigHdr
, PathStr
);
1907 // Remove the last character L'&'
1909 *(ConfigHdr
+ StrLen (ConfigHdr
) - 1) = L
'\0';
1911 if (RequestBlockArray
== NULL
) {
1913 // Append VarStorageData BlockEntry into *Request string
1914 // Now support only one varstore in a form package.
1918 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
1919 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
1923 // Compute the length of the entire request starting with <ConfigHdr> and a
1927 Length
= StrLen (ConfigHdr
) + 1;
1929 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1931 // Add <BlockName> length for each Offset/Width pair
1933 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
1934 // | 8 | 4 | 7 | 4 |
1937 Length
= Length
+ (8 + 4 + 7 + 4);
1941 // No any request block data is found. The request string can't be constructed.
1944 Status
= EFI_SUCCESS
;
1949 // Allocate buffer for the entire <ConfigRequest>
1951 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
1952 if (FullConfigRequest
== NULL
) {
1953 Status
= EFI_OUT_OF_RESOURCES
;
1956 StringPtr
= FullConfigRequest
;
1959 // Start with <ConfigHdr>
1961 StrCpy (StringPtr
, ConfigHdr
);
1962 StringPtr
+= StrLen (StringPtr
);
1965 // Loop through all the Offset/Width pairs and append them to ConfigRequest
1967 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
1968 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1970 // Append &OFFSET=XXXX&WIDTH=YYYY\0
1974 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1975 L
"&OFFSET=%04X&WIDTH=%04X",
1979 StringPtr
+= StrLen (StringPtr
);
1982 // Set to the got full request string.
1984 HiiToLower (FullConfigRequest
);
1985 if (*Request
!= NULL
) {
1986 FreePool (*Request
);
1988 *Request
= FullConfigRequest
;
1992 // 4. Construct Default Value string in AltResp according to request element.
1993 // Go through all VarStorageData Entry and get the DefaultId array for each one
1994 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
1998 // Add length for <ConfigHdr> + '\0'
2000 Length
= StrLen (ConfigHdr
) + 1;
2002 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
2003 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
2005 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
2006 // |1| StrLen (ConfigHdr) | 8 | 4 |
2008 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
2010 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
2011 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
2012 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
2013 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
2014 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
2016 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
2017 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
2019 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
2027 // No default value is found. The default string doesn't exist.
2030 Status
= EFI_SUCCESS
;
2035 // Allocate buffer for the entire <DefaultAltCfgResp>
2037 DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
2038 if (DefaultAltCfgResp
== NULL
) {
2039 Status
= EFI_OUT_OF_RESOURCES
;
2042 StringPtr
= DefaultAltCfgResp
;
2045 // Start with <ConfigHdr>
2047 StrCpy (StringPtr
, ConfigHdr
);
2048 StringPtr
+= StrLen (StringPtr
);
2050 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
2051 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
2053 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
2054 // |1| StrLen (ConfigHdr) | 8 | 4 |
2058 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
2061 DefaultId
->DefaultName
2063 StringPtr
+= StrLen (StringPtr
);
2065 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
2066 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
2067 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
2068 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
2069 if (DefaultValueData
->DefaultId
== DefaultId
->DefaultId
) {
2071 // Add <BlockConfig>
2072 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
2076 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
2077 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
2081 StringPtr
+= StrLen (StringPtr
);
2084 // Convert Value to a hex string in "%x" format
2085 // NOTE: This is in the opposite byte that GUID and PATH use
2087 Width
= BlockData
->Width
;
2088 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
2089 for (; Width
> 0; Width
--) {
2090 StringPtr
+= UnicodeValueToString (StringPtr
, PREFIX_ZERO
| RADIX_HEX
, TmpBuffer
[Width
- 1], 2);
2096 HiiToLower (DefaultAltCfgResp
);
2099 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.
2101 if (*AltCfgResp
!= NULL
&& DefaultAltCfgResp
!= NULL
) {
2102 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
2103 FreePool (DefaultAltCfgResp
);
2104 } else if (*AltCfgResp
== NULL
) {
2105 *AltCfgResp
= DefaultAltCfgResp
;
2109 if (RequestBlockArray
!= NULL
) {
2111 // Free Link Array RequestBlockArray
2113 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
2114 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2115 RemoveEntryList (&BlockData
->Entry
);
2116 FreePool (BlockData
);
2119 FreePool (RequestBlockArray
);
2122 if (VarStorageData
!= NULL
) {
2124 // Free link array VarStorageData
2126 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
2127 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2128 RemoveEntryList (&BlockData
->Entry
);
2130 // Free default value link array
2132 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
2133 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
2134 RemoveEntryList (&DefaultValueData
->Entry
);
2135 FreePool (DefaultValueData
);
2137 FreePool (BlockData
);
2139 FreePool (VarStorageData
);
2142 if (DefaultIdArray
!= NULL
) {
2144 // Free DefaultId Array
2146 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
2147 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
2148 RemoveEntryList (&DefaultId
->Entry
);
2149 FreePool (DefaultId
);
2151 FreePool (DefaultIdArray
);
2155 // Free the allocated string
2157 if (GuidStr
!= NULL
) {
2160 if (NameStr
!= NULL
) {
2163 if (PathStr
!= NULL
) {
2166 if (ConfigHdr
!= NULL
) {
2167 FreePool (ConfigHdr
);
2171 // Free Pacakge data
2173 if (HiiFormPackage
!= NULL
) {
2174 FreePool (HiiFormPackage
);
2177 if (PointerProgress
!= NULL
) {
2178 if (*Request
== NULL
) {
2179 *PointerProgress
= NULL
;
2180 } else if (EFI_ERROR (Status
)) {
2181 *PointerProgress
= Progress
;
2183 *PointerProgress
= *Request
+ StrLen (*Request
);
2191 This function allows a caller to extract the current configuration
2192 for one or more named elements from one or more drivers.
2194 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2196 @param Request A null-terminated Unicode string in
2197 <MultiConfigRequest> format.
2198 @param Progress On return, points to a character in the Request
2199 string. Points to the string's null terminator if
2200 request was successful. Points to the most recent
2201 & before the first failing name / value pair (or
2202 the beginning of the string if the failure is in
2203 the first name / value pair) if the request was
2205 @param Results Null-terminated Unicode string in
2206 <MultiConfigAltResp> format which has all values
2207 filled in for the names in the Request string.
2208 String to be allocated by the called function.
2210 @retval EFI_SUCCESS The Results string is filled with the values
2211 corresponding to all requested names.
2212 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2213 results that must be stored awaiting possible
2215 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
2216 Progress set to the "G" in "GUID" of the routing
2217 header that doesn't match. Note: There is no
2218 requirement that all routing data be validated
2219 before any configuration extraction.
2220 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
2221 parameter would result in this type of error. The
2222 Progress parameter is set to NULL.
2223 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
2224 before the error or the beginning of the string.
2225 @retval EFI_INVALID_PARAMETER Unknown name. Progress points to the & before the
2231 HiiConfigRoutingExtractConfig (
2232 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2233 IN CONST EFI_STRING Request
,
2234 OUT EFI_STRING
*Progress
,
2235 OUT EFI_STRING
*Results
2238 HII_DATABASE_PRIVATE_DATA
*Private
;
2239 EFI_STRING StringPtr
;
2240 EFI_STRING ConfigRequest
;
2242 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2243 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2246 HII_DATABASE_RECORD
*Database
;
2247 UINT8
*DevicePathPkg
;
2248 UINT8
*CurrentDevicePath
;
2249 EFI_HANDLE DriverHandle
;
2250 EFI_HII_HANDLE HiiHandle
;
2251 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2252 EFI_STRING AccessProgress
;
2253 EFI_STRING AccessResults
;
2254 EFI_STRING DefaultResults
;
2255 BOOLEAN FirstElement
;
2256 BOOLEAN IfrDataParsedFlag
;
2258 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
2259 return EFI_INVALID_PARAMETER
;
2262 if (Request
== NULL
) {
2264 return EFI_INVALID_PARAMETER
;
2267 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2268 StringPtr
= Request
;
2269 *Progress
= StringPtr
;
2270 DefaultResults
= NULL
;
2271 ConfigRequest
= NULL
;
2272 Status
= EFI_SUCCESS
;
2273 AccessResults
= NULL
;
2275 IfrDataParsedFlag
= FALSE
;
2278 // The first element of <MultiConfigRequest> should be
2279 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2281 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2282 return EFI_INVALID_PARAMETER
;
2285 FirstElement
= TRUE
;
2288 // Allocate a fix length of memory to store Results. Reallocate memory for
2289 // Results if this fix length is insufficient.
2291 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2292 if (*Results
== NULL
) {
2293 return EFI_OUT_OF_RESOURCES
;
2296 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2298 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
2299 // or most recent & before the error.
2301 if (StringPtr
== Request
) {
2302 *Progress
= StringPtr
;
2304 *Progress
= StringPtr
- 1;
2308 // Process each <ConfigRequest> of <MultiConfigRequest>
2310 Length
= CalculateConfigStringLen (StringPtr
);
2311 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2312 if (ConfigRequest
== NULL
) {
2313 Status
= EFI_OUT_OF_RESOURCES
;
2316 *(ConfigRequest
+ Length
) = 0;
2319 // Get the UEFI device path
2321 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
2322 if (EFI_ERROR (Status
)) {
2327 // Find driver which matches the routing data.
2329 DriverHandle
= NULL
;
2332 for (Link
= Private
->DatabaseList
.ForwardLink
;
2333 Link
!= &Private
->DatabaseList
;
2334 Link
= Link
->ForwardLink
2336 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2337 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2338 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2342 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
2344 DriverHandle
= Database
->DriverHandle
;
2345 HiiHandle
= Database
->Handle
;
2352 // Try to find driver handle by device path.
2354 if (DriverHandle
== NULL
) {
2355 TempDevicePath
= DevicePath
;
2356 Status
= gBS
->LocateDevicePath (
2357 &gEfiDevicePathProtocolGuid
,
2361 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2363 // Routing data does not match any known driver.
2364 // Set Progress to the 'G' in "GUID" of the routing header.
2366 *Progress
= StringPtr
;
2367 Status
= EFI_NOT_FOUND
;
2373 // Check whether ConfigRequest contains request string OFFSET/WIDTH
2375 IfrDataParsedFlag
= FALSE
;
2376 if ((HiiHandle
!= NULL
) && (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
)) {
2378 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
2380 IfrDataParsedFlag
= TRUE
;
2381 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, &AccessProgress
);
2382 if (EFI_ERROR (Status
)) {
2384 // AccessProgress indicates the parsing progress on <ConfigRequest>.
2385 // Map it to the progress on <MultiConfigRequest> then return it.
2387 *Progress
= StrStr (StringPtr
, AccessProgress
);
2391 // Not any request block is found.
2393 if (StrStr (ConfigRequest
, L
"&OFFSET=") == NULL
) {
2394 AccessResults
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
2395 goto NextConfigString
;
2400 // Call corresponding ConfigAccess protocol to extract settings
2402 Status
= gBS
->HandleProtocol (
2404 &gEfiHiiConfigAccessProtocolGuid
,
2405 (VOID
**) &ConfigAccess
2407 ASSERT_EFI_ERROR (Status
);
2409 Status
= ConfigAccess
->ExtractConfig (
2415 if (EFI_ERROR (Status
)) {
2417 // AccessProgress indicates the parsing progress on <ConfigRequest>.
2418 // Map it to the progress on <MultiConfigRequest> then return it.
2420 *Progress
= StrStr (StringPtr
, AccessProgress
);
2425 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2426 // which seperates the first <ConfigAltResp> and the following ones.
2428 ASSERT (*AccessProgress
== 0);
2431 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2433 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
) {
2434 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
2435 ASSERT_EFI_ERROR (Status
);
2438 FreePool (DevicePath
);
2441 if (DefaultResults
!= NULL
) {
2442 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2443 ASSERT_EFI_ERROR (Status
);
2444 FreePool (DefaultResults
);
2445 DefaultResults
= NULL
;
2449 if (!FirstElement
) {
2450 Status
= AppendToMultiString (Results
, L
"&");
2451 ASSERT_EFI_ERROR (Status
);
2454 Status
= AppendToMultiString (Results
, AccessResults
);
2455 ASSERT_EFI_ERROR (Status
);
2457 FirstElement
= FALSE
;
2459 FreePool (AccessResults
);
2460 AccessResults
= NULL
;
2461 FreePool (ConfigRequest
);
2462 ConfigRequest
= NULL
;
2465 // Go to next <ConfigRequest> (skip '&').
2467 StringPtr
+= Length
;
2468 if (*StringPtr
== 0) {
2469 *Progress
= StringPtr
;
2477 if (EFI_ERROR (Status
)) {
2478 FreePool (*Results
);
2482 if (ConfigRequest
!= NULL
) {
2483 FreePool (ConfigRequest
);
2486 if (AccessResults
!= NULL
) {
2487 FreePool (AccessResults
);
2490 if (DefaultResults
!= NULL
) {
2491 FreePool (DefaultResults
);
2494 if (DevicePath
!= NULL
) {
2495 FreePool (DevicePath
);
2503 This function allows the caller to request the current configuration for the
2504 entirety of the current HII database and returns the data in a
2505 null-terminated Unicode string.
2507 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2509 @param Results Null-terminated Unicode string in
2510 <MultiConfigAltResp> format which has all values
2511 filled in for the names in the Request string.
2512 String to be allocated by the called function.
2513 De-allocation is up to the caller.
2515 @retval EFI_SUCCESS The Results string is filled with the values
2516 corresponding to all requested names.
2517 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2518 results that must be stored awaiting possible
2520 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
2521 parameter would result in this type of error.
2526 HiiConfigRoutingExportConfig (
2527 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2528 OUT EFI_STRING
*Results
2532 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2533 EFI_STRING AccessResults
;
2534 EFI_STRING Progress
;
2535 EFI_STRING StringPtr
;
2536 EFI_STRING ConfigRequest
;
2538 EFI_HANDLE
*ConfigAccessHandles
;
2539 UINTN NumberConfigAccessHandles
;
2540 BOOLEAN FirstElement
;
2541 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2542 EFI_HII_HANDLE HiiHandle
;
2543 EFI_STRING DefaultResults
;
2544 HII_DATABASE_PRIVATE_DATA
*Private
;
2546 HII_DATABASE_RECORD
*Database
;
2547 UINT8
*DevicePathPkg
;
2548 UINT8
*CurrentDevicePath
;
2549 BOOLEAN IfrDataParsedFlag
;
2551 if (This
== NULL
|| Results
== NULL
) {
2552 return EFI_INVALID_PARAMETER
;
2555 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2558 // Allocate a fix length of memory to store Results. Reallocate memory for
2559 // Results if this fix length is insufficient.
2561 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2562 if (*Results
== NULL
) {
2563 return EFI_OUT_OF_RESOURCES
;
2566 NumberConfigAccessHandles
= 0;
2567 Status
= gBS
->LocateHandleBuffer (
2569 &gEfiHiiConfigAccessProtocolGuid
,
2571 &NumberConfigAccessHandles
,
2572 &ConfigAccessHandles
2574 if (EFI_ERROR (Status
)) {
2578 FirstElement
= TRUE
;
2580 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
2581 Status
= gBS
->HandleProtocol (
2582 ConfigAccessHandles
[Index
],
2583 &gEfiHiiConfigAccessProtocolGuid
,
2584 (VOID
**) &ConfigAccess
2586 if (EFI_ERROR (Status
)) {
2591 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
2593 IfrDataParsedFlag
= FALSE
;
2596 DefaultResults
= NULL
;
2598 ConfigRequest
= NULL
;
2599 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
2600 if (DevicePath
!= NULL
) {
2601 for (Link
= Private
->DatabaseList
.ForwardLink
;
2602 Link
!= &Private
->DatabaseList
;
2603 Link
= Link
->ForwardLink
2605 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2606 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2607 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2611 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
2613 HiiHandle
= Database
->Handle
;
2620 Status
= ConfigAccess
->ExtractConfig (
2626 if (EFI_ERROR (Status
)) {
2628 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2630 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
2631 IfrDataParsedFlag
= TRUE
;
2632 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
2634 // Get the full request string to get the Current setting again.
2636 if (!EFI_ERROR (Status
) && ConfigRequest
!= NULL
) {
2637 Status
= ConfigAccess
->ExtractConfig (
2643 FreePool (ConfigRequest
);
2645 Status
= EFI_NOT_FOUND
;
2650 if (!EFI_ERROR (Status
)) {
2652 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
2654 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
2655 StringPtr
= StrStr (AccessResults
, L
"&GUID=");
2656 if (StringPtr
!= NULL
) {
2659 if (StrStr (AccessResults
, L
"&OFFSET=") != NULL
) {
2660 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &AccessResults
, &DefaultResults
, NULL
);
2661 ASSERT_EFI_ERROR (Status
);
2663 if (StringPtr
!= NULL
) {
2668 // Merge the default sting from IFR code into the got setting from driver.
2670 if (DefaultResults
!= NULL
) {
2671 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
2672 ASSERT_EFI_ERROR (Status
);
2673 FreePool (DefaultResults
);
2674 DefaultResults
= NULL
;
2678 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
2679 // which seperates the first <ConfigAltResp> and the following ones.
2681 if (!FirstElement
) {
2682 Status
= AppendToMultiString (Results
, L
"&");
2683 ASSERT_EFI_ERROR (Status
);
2686 Status
= AppendToMultiString (Results
, AccessResults
);
2687 ASSERT_EFI_ERROR (Status
);
2689 FirstElement
= FALSE
;
2691 FreePool (AccessResults
);
2692 AccessResults
= NULL
;
2695 FreePool (ConfigAccessHandles
);
2702 This function processes the results of processing forms and routes it to the
2703 appropriate handlers or storage.
2705 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2707 @param Configuration A null-terminated Unicode string in
2708 <MulltiConfigResp> format.
2709 @param Progress A pointer to a string filled in with the offset of
2710 the most recent & before the first failing name /
2711 value pair (or the beginning of the string if the
2712 failure is in the first name / value pair) or the
2713 terminating NULL if all was successful.
2715 @retval EFI_SUCCESS The results have been distributed or are awaiting
2717 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
2718 results that must be stored awaiting possible
2720 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
2721 would result in this type of error.
2722 @retval EFI_NOT_FOUND Target for the specified routing data was not
2728 HiiConfigRoutingRouteConfig (
2729 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2730 IN CONST EFI_STRING Configuration
,
2731 OUT EFI_STRING
*Progress
2734 HII_DATABASE_PRIVATE_DATA
*Private
;
2735 EFI_STRING StringPtr
;
2736 EFI_STRING ConfigResp
;
2739 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2740 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2742 HII_DATABASE_RECORD
*Database
;
2743 UINT8
*DevicePathPkg
;
2744 UINT8
*CurrentDevicePath
;
2745 EFI_HANDLE DriverHandle
;
2746 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
2747 EFI_STRING AccessProgress
;
2749 if (This
== NULL
|| Progress
== NULL
) {
2750 return EFI_INVALID_PARAMETER
;
2753 if (Configuration
== NULL
) {
2755 return EFI_INVALID_PARAMETER
;
2758 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2759 StringPtr
= Configuration
;
2760 *Progress
= StringPtr
;
2763 // The first element of <MultiConfigResp> should be
2764 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
2766 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2767 return EFI_INVALID_PARAMETER
;
2770 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
2772 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
2773 // or most recent & before the error.
2775 if (StringPtr
== Configuration
) {
2776 *Progress
= StringPtr
;
2778 *Progress
= StringPtr
- 1;
2782 // Process each <ConfigResp> of <MultiConfigResp>
2784 Length
= CalculateConfigStringLen (StringPtr
);
2785 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
2786 if (ConfigResp
== NULL
) {
2787 return EFI_OUT_OF_RESOURCES
;
2790 // Append '\0' to the end of ConfigRequest
2792 *(ConfigResp
+ Length
) = 0;
2795 // Get the UEFI device path
2797 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
2798 if (EFI_ERROR (Status
)) {
2799 FreePool (ConfigResp
);
2804 // Find driver which matches the routing data.
2806 DriverHandle
= NULL
;
2807 for (Link
= Private
->DatabaseList
.ForwardLink
;
2808 Link
!= &Private
->DatabaseList
;
2809 Link
= Link
->ForwardLink
2811 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
2813 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
2814 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
2818 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
2820 DriverHandle
= Database
->DriverHandle
;
2827 // Try to find driver handle by device path.
2829 if (DriverHandle
== NULL
) {
2830 TempDevicePath
= DevicePath
;
2831 Status
= gBS
->LocateDevicePath (
2832 &gEfiDevicePathProtocolGuid
,
2836 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
2838 // Routing data does not match any known driver.
2839 // Set Progress to the 'G' in "GUID" of the routing header.
2841 FreePool (DevicePath
);
2842 *Progress
= StringPtr
;
2843 FreePool (ConfigResp
);
2844 return EFI_NOT_FOUND
;
2848 FreePool (DevicePath
);
2851 // Call corresponding ConfigAccess protocol to route settings
2853 Status
= gBS
->HandleProtocol (
2855 &gEfiHiiConfigAccessProtocolGuid
,
2856 (VOID
**) &ConfigAccess
2858 ASSERT_EFI_ERROR (Status
);
2860 Status
= ConfigAccess
->RouteConfig (
2866 if (EFI_ERROR (Status
)) {
2868 // AccessProgress indicates the parsing progress on <ConfigResp>.
2869 // Map it to the progress on <MultiConfigResp> then return it.
2871 *Progress
= StrStr (StringPtr
, AccessProgress
);
2873 FreePool (ConfigResp
);
2877 FreePool (ConfigResp
);
2881 // Go to next <ConfigResp> (skip '&').
2883 StringPtr
+= Length
;
2884 if (*StringPtr
== 0) {
2885 *Progress
= StringPtr
;
2898 This helper function is to be called by drivers to map configuration data
2899 stored in byte array ("block") formats such as UEFI Variables into current
2900 configuration strings.
2902 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
2904 @param ConfigRequest A null-terminated Unicode string in
2905 <ConfigRequest> format.
2906 @param Block Array of bytes defining the block's configuration.
2907 @param BlockSize Length in bytes of Block.
2908 @param Config Filled-in configuration string. String allocated
2909 by the function. Returned only if call is
2910 successful. It is <ConfigResp> string format.
2911 @param Progress A pointer to a string filled in with the offset of
2912 the most recent & before the first failing
2913 name/value pair (or the beginning of the string if
2914 the failure is in the first name / value pair) or
2915 the terminating NULL if all was successful.
2917 @retval EFI_SUCCESS The request succeeded. Progress points to the null
2918 terminator at the end of the ConfigRequest
2920 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
2921 points to the first character of ConfigRequest.
2922 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
2923 Block parameter would result in this type of
2924 error. Progress points to the first character of
2926 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
2927 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
2928 Block is left updated and Progress points at
2929 the "&" preceding the first non-<BlockName>.
2935 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
2936 IN CONST EFI_STRING ConfigRequest
,
2937 IN CONST UINT8
*Block
,
2938 IN CONST UINTN BlockSize
,
2939 OUT EFI_STRING
*Config
,
2940 OUT EFI_STRING
*Progress
2943 HII_DATABASE_PRIVATE_DATA
*Private
;
2944 EFI_STRING StringPtr
;
2952 EFI_STRING ValueStr
;
2953 EFI_STRING ConfigElement
;
2958 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
2959 return EFI_INVALID_PARAMETER
;
2962 if (Block
== NULL
|| ConfigRequest
== NULL
) {
2963 *Progress
= ConfigRequest
;
2964 return EFI_INVALID_PARAMETER
;
2968 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2969 ASSERT (Private
!= NULL
);
2971 StringPtr
= ConfigRequest
;
2974 ConfigElement
= NULL
;
2977 // Allocate a fix length of memory to store Results. Reallocate memory for
2978 // Results if this fix length is insufficient.
2980 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
2981 if (*Config
== NULL
) {
2982 return EFI_OUT_OF_RESOURCES
;
2988 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2989 *Progress
= StringPtr
;
2990 Status
= EFI_INVALID_PARAMETER
;
2993 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
2996 if (*StringPtr
== 0) {
2997 *Progress
= StringPtr
- 1;
2998 Status
= EFI_INVALID_PARAMETER
;
3002 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
3005 if (*StringPtr
== 0) {
3006 *Progress
= StringPtr
- 1;
3007 Status
= EFI_INVALID_PARAMETER
;
3016 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
3018 Length
= StringPtr
- ConfigRequest
;
3019 CopyMem (*Config
, ConfigRequest
, Length
* sizeof (CHAR16
));
3022 // Parse each <RequestElement> if exists
3023 // Only <BlockName> format is supported by this help function.
3024 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
3026 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
3028 // Back up the header of one <BlockName>
3032 StringPtr
+= StrLen (L
"OFFSET=");
3036 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3037 if (Status
== EFI_OUT_OF_RESOURCES
) {
3038 *Progress
= ConfigRequest
;
3045 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3047 FreePool (TmpBuffer
);
3049 StringPtr
+= Length
;
3050 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3051 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
3052 Status
= EFI_INVALID_PARAMETER
;
3055 StringPtr
+= StrLen (L
"&WIDTH=");
3060 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3061 if (Status
== EFI_OUT_OF_RESOURCES
) {
3062 *Progress
= ConfigRequest
;
3069 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3071 FreePool (TmpBuffer
);
3073 StringPtr
+= Length
;
3074 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3075 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
3076 Status
= EFI_INVALID_PARAMETER
;
3081 // Calculate Value and convert it to hex string.
3083 if (Offset
+ Width
> BlockSize
) {
3084 *Progress
= StringPtr
;
3085 Status
= EFI_DEVICE_ERROR
;
3089 Value
= (UINT8
*) AllocateZeroPool (Width
);
3090 if (Value
== NULL
) {
3091 *Progress
= ConfigRequest
;
3092 Status
= EFI_OUT_OF_RESOURCES
;
3096 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
3098 Length
= Width
* 2 + 1;
3099 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
3100 if (ValueStr
== NULL
) {
3101 *Progress
= ConfigRequest
;
3102 Status
= EFI_OUT_OF_RESOURCES
;
3106 TemString
= ValueStr
;
3107 TemBuffer
= Value
+ Width
- 1;
3108 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
3109 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
3116 // Build a ConfigElement
3118 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
3119 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
3120 if (ConfigElement
== NULL
) {
3121 Status
= EFI_OUT_OF_RESOURCES
;
3124 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
3125 if (*StringPtr
== 0) {
3126 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
3128 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
3129 StrCat (ConfigElement
, L
"VALUE=");
3130 StrCat (ConfigElement
, ValueStr
);
3132 AppendToMultiString (Config
, ConfigElement
);
3134 FreePool (ConfigElement
);
3135 FreePool (ValueStr
);
3136 ConfigElement
= NULL
;
3140 // If '\0', parsing is finished. Otherwise skip '&' to continue
3142 if (*StringPtr
== 0) {
3145 AppendToMultiString (Config
, L
"&");
3150 if (*StringPtr
!= 0) {
3151 *Progress
= StringPtr
- 1;
3152 Status
= EFI_INVALID_PARAMETER
;
3156 HiiToLower (*Config
);
3157 *Progress
= StringPtr
;
3161 if (*Config
!= NULL
) {
3165 if (ValueStr
!= NULL
) {
3166 FreePool (ValueStr
);
3168 if (Value
!= NULL
) {
3171 if (ConfigElement
!= NULL
) {
3172 FreePool (ConfigElement
);
3181 This helper function is to be called by drivers to map configuration strings
3182 to configurations stored in byte array ("block") formats such as UEFI Variables.
3184 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3186 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
3187 format. It can be ConfigAltResp format string.
3188 @param Block A possibly null array of bytes representing the
3189 current block. Only bytes referenced in the
3190 ConfigResp string in the block are modified. If
3191 this parameter is null or if the *BlockSize
3192 parameter is (on input) shorter than required by
3193 the Configuration string, only the BlockSize
3194 parameter is updated and an appropriate status
3195 (see below) is returned.
3196 @param BlockSize The length of the Block in units of UINT8. On
3197 input, this is the size of the Block. On output,
3198 if successful, contains the index of the last
3199 modified byte in the Block.
3200 @param Progress On return, points to an element of the ConfigResp
3201 string filled in with the offset of the most
3202 recent '&' before the first failing name / value
3203 pair (or the beginning of the string if the
3204 failure is in the first name / value pair) or the
3205 terminating NULL if all was successful.
3207 @retval EFI_SUCCESS The request succeeded. Progress points to the null
3208 terminator at the end of the ConfigResp string.
3209 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
3210 points to the first character of ConfigResp.
3211 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
3212 Block parameter would result in this type of
3213 error. Progress points to the first character of
3215 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
3216 value pair. Block is left updated and
3217 Progress points at the '&' preceding the first
3224 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3225 IN CONST EFI_STRING ConfigResp
,
3226 IN OUT UINT8
*Block
,
3227 IN OUT UINTN
*BlockSize
,
3228 OUT EFI_STRING
*Progress
3231 HII_DATABASE_PRIVATE_DATA
*Private
;
3232 EFI_STRING StringPtr
;
3241 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
3242 return EFI_INVALID_PARAMETER
;
3245 if (ConfigResp
== NULL
|| Block
== NULL
) {
3246 *Progress
= ConfigResp
;
3247 return EFI_INVALID_PARAMETER
;
3250 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
3251 ASSERT (Private
!= NULL
);
3253 StringPtr
= ConfigResp
;
3254 BufferSize
= *BlockSize
;
3260 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3261 *Progress
= StringPtr
;
3262 Status
= EFI_INVALID_PARAMETER
;
3265 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
3268 if (*StringPtr
== 0) {
3269 *Progress
= StringPtr
;
3270 Status
= EFI_INVALID_PARAMETER
;
3274 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
3277 if (*StringPtr
== 0) {
3278 *Progress
= StringPtr
;
3279 Status
= EFI_INVALID_PARAMETER
;
3288 // Parse each <ConfigElement> if exists
3289 // Only <BlockConfig> format is supported by this help function.
3290 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
3292 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
3293 StringPtr
+= StrLen (L
"OFFSET=");
3297 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3298 if (EFI_ERROR (Status
)) {
3299 *Progress
= ConfigResp
;
3306 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3308 FreePool (TmpBuffer
);
3310 StringPtr
+= Length
;
3311 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3312 *Progress
= StringPtr
- Length
- StrLen (L
"OFFSET=") - 1;
3313 Status
= EFI_INVALID_PARAMETER
;
3316 StringPtr
+= StrLen (L
"&WIDTH=");
3321 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3322 if (Status
== EFI_OUT_OF_RESOURCES
) {
3323 *Progress
= ConfigResp
;
3330 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
3332 FreePool (TmpBuffer
);
3334 StringPtr
+= Length
;
3335 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
3336 *Progress
= StringPtr
- Length
- StrLen (L
"&WIDTH=");
3337 Status
= EFI_INVALID_PARAMETER
;
3340 StringPtr
+= StrLen (L
"&VALUE=");
3345 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
3346 if (EFI_ERROR (Status
)) {
3347 *Progress
= ConfigResp
;
3351 StringPtr
+= Length
;
3352 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3353 *Progress
= StringPtr
- Length
- 7;
3354 Status
= EFI_INVALID_PARAMETER
;
3359 // Update the Block with configuration info
3362 if (Offset
+ Width
> BufferSize
) {
3363 return EFI_DEVICE_ERROR
;
3366 CopyMem (Block
+ Offset
, Value
, Width
);
3367 *BlockSize
= Offset
+ Width
- 1;
3373 // If '\0', parsing is finished. Otherwise skip '&' to continue
3375 if (*StringPtr
== 0) {
3383 // The input string is ConfigAltResp format.
3385 if ((*StringPtr
!= 0) && (StrnCmp (StringPtr
, L
"&GUID=", StrLen (L
"&GUID=")) != 0)) {
3386 *Progress
= StringPtr
- 1;
3387 Status
= EFI_INVALID_PARAMETER
;
3391 *Progress
= StringPtr
+ StrLen (StringPtr
);
3396 if (Value
!= NULL
) {
3404 This helper function is to be called by drivers to extract portions of
3405 a larger configuration string.
3407 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3409 @param Configuration A null-terminated Unicode string in
3410 <MultiConfigAltResp> format. It is <ConfigAltResp> format.
3411 @param Guid A pointer to the GUID value to search for in the
3412 routing portion of the ConfigResp string when
3413 retrieving the requested data. If Guid is NULL,
3414 then all GUID values will be searched for.
3415 @param Name A pointer to the NAME value to search for in the
3416 routing portion of the ConfigResp string when
3417 retrieving the requested data. If Name is NULL,
3418 then all Name values will be searched for.
3419 @param DevicePath A pointer to the PATH value to search for in the
3420 routing portion of the ConfigResp string when
3421 retrieving the requested data. If DevicePath is
3422 NULL, then all DevicePath values will be searched
3424 @param AltCfgId A pointer to the ALTCFG value to search for in the
3425 routing portion of the ConfigResp string when
3426 retrieving the requested data. If this parameter
3427 is NULL, then the current setting will be
3429 @param AltCfgResp A pointer to a buffer which will be allocated by
3430 the function which contains the retrieved string
3431 as requested. This buffer is only allocated if
3432 the call was successful. It is <ConfigResp> format.
3434 @retval EFI_SUCCESS The request succeeded. The requested data was
3435 extracted and placed in the newly allocated
3437 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
3438 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
3439 @retval EFI_NOT_FOUND Target for the specified routing data was not
3446 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3447 IN CONST EFI_STRING Configuration
,
3448 IN CONST EFI_GUID
*Guid
,
3449 IN CONST EFI_STRING Name
,
3450 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3451 IN CONST UINT16
*AltCfgId
,
3452 OUT EFI_STRING
*AltCfgResp
3456 EFI_STRING StringPtr
;
3457 EFI_STRING HdrStart
;
3464 EFI_STRING AltIdStr
;
3481 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
3482 return EFI_INVALID_PARAMETER
;
3485 StringPtr
= Configuration
;
3486 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3487 return EFI_INVALID_PARAMETER
;
3491 // Generate the sub string for later matching.
3493 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
3496 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
3497 (VOID
*) DevicePath
,
3501 if (AltCfgId
!= NULL
) {
3502 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
3505 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
3507 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
3510 while (*StringPtr
!= 0) {
3512 // Try to match the GUID
3515 TmpPtr
= StrStr (StringPtr
, GuidStr
);
3516 if (TmpPtr
== NULL
) {
3517 Status
= EFI_NOT_FOUND
;
3523 // Jump to <NameHdr>
3526 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
3528 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
3529 if (StringPtr
== NULL
) {
3530 Status
= EFI_NOT_FOUND
;
3538 // Try to match the NAME
3540 if (GuidFlag
&& !NameFlag
) {
3541 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
3545 // Jump to <PathHdr>
3548 StringPtr
+= StrLen (NameStr
);
3550 StringPtr
= StrStr (StringPtr
, L
"PATH=");
3551 if (StringPtr
== NULL
) {
3552 Status
= EFI_NOT_FOUND
;
3561 // Try to match the DevicePath
3563 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
3564 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
3569 // Jump to '&' before <DescHdr> or <ConfigBody>
3571 if (DevicePath
!= NULL
) {
3572 StringPtr
+= StrLen (PathStr
);
3574 StringPtr
= StrStr (StringPtr
, L
"&");
3575 if (StringPtr
== NULL
) {
3576 Status
= EFI_NOT_FOUND
;
3587 // Try to match the AltCfgId
3589 if (GuidFlag
&& NameFlag
&& PathFlag
) {
3590 if (AltCfgId
== NULL
) {
3592 // Return Current Setting when AltCfgId is NULL.
3594 Status
= OutputConfigBody (StringPtr
, &Result
);
3598 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
3600 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
3606 // Skip AltIdStr and &
3608 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
3609 Status
= OutputConfigBody (StringPtr
, &Result
);
3615 Status
= EFI_NOT_FOUND
;
3619 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
3621 // Copy the <ConfigHdr> and <ConfigBody>
3623 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
3624 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3625 if (*AltCfgResp
== NULL
) {
3626 Status
= EFI_OUT_OF_RESOURCES
;
3628 StrnCpy (*AltCfgResp
, HdrStart
, HdrEnd
- HdrStart
);
3629 StrCat (*AltCfgResp
, Result
);
3630 Status
= EFI_SUCCESS
;
3634 if (GuidStr
!= NULL
) {
3637 if (NameStr
!= NULL
) {
3640 if (PathStr
!= NULL
) {
3643 if (AltIdStr
!= NULL
) {
3644 FreePool (AltIdStr
);
3646 if (Result
!= NULL
) {