2 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 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 necessary 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 ConfigString 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 StrCpyS (Str
, Length
, String
);
257 StringHeader
= Str
+ StrLen (String
);
258 TemString
= (CHAR16
*) StringHeader
;
263 // Convert Buffer to Hex String in reverse order
265 TemBuffer
= ((UINT8
*) Buffer
);
266 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
++) {
267 UnicodeValueToStringS (
269 sizeof (CHAR16
) * (Length
- StrnLenS (Str
, Length
)),
270 PREFIX_ZERO
| RADIX_HEX
,
274 TemString
+= StrnLenS (TemString
, Length
- StrnLenS (Str
, Length
));
279 // Check buffer is enough
281 TemName
= (CHAR16
*) Buffer
;
282 ASSERT ((BufferLen
* 2 + 1) >= (StrLen (TemName
) * 4 + 1));
284 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
286 for (; *TemName
!= L
'\0'; TemName
++) {
287 UnicodeValueToStringS (
289 sizeof (CHAR16
) * (Length
- StrnLenS (Str
, Length
)),
290 PREFIX_ZERO
| RADIX_HEX
,
294 TemString
+= StrnLenS (TemString
, Length
- StrnLenS (Str
, Length
));
299 // Convert Buffer to Hex String
301 TemBuffer
= ((UINT8
*) Buffer
) + BufferLen
- 1;
302 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
--) {
303 UnicodeValueToStringS (
305 sizeof (CHAR16
) * (Length
- StrnLenS (Str
, Length
)),
306 PREFIX_ZERO
| RADIX_HEX
,
310 TemString
+= StrnLenS (TemString
, Length
- StrnLenS (Str
, Length
));
318 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
320 StrCatS (Str
, Length
, L
"&");
328 Retrieve the <ConfigBody> from String then output it.
330 This is a internal function.
332 @param String A sub string of a configuration string in
333 <MultiConfigAltResp> format.
334 @param ConfigBody Points to the output string. It's caller's
335 responsibility to free this buffer.
337 @retval EFI_INVALID_PARAMETER There is no form package in current hii database.
338 @retval EFI_OUT_OF_RESOURCES Not enough memory to finish this operation.
339 @retval EFI_SUCCESS All existing storage is exported.
344 IN EFI_STRING String
,
345 OUT EFI_STRING
*ConfigBody
352 if (String
== NULL
|| ConfigBody
== NULL
) {
353 return EFI_INVALID_PARAMETER
;
357 // The setting information should start OFFSET, not ALTCFG.
359 if (StrnCmp (String
, L
"&ALTCFG=", StrLen (L
"&ALTCFG=")) == 0) {
360 return EFI_INVALID_PARAMETER
;
363 TmpPtr
= StrStr (String
, L
"GUID=");
364 if (TmpPtr
== NULL
) {
366 // It is the last <ConfigResp> of the incoming configuration string.
368 Result
= AllocateCopyPool (StrSize (String
), String
);
369 if (Result
== NULL
) {
370 return EFI_OUT_OF_RESOURCES
;
372 *ConfigBody
= Result
;
377 Length
= TmpPtr
- String
;
379 return EFI_NOT_FOUND
;
381 Result
= AllocateCopyPool (Length
* sizeof (CHAR16
), String
);
382 if (Result
== NULL
) {
383 return EFI_OUT_OF_RESOURCES
;
386 *(Result
+ Length
- 1) = 0;
387 *ConfigBody
= Result
;
392 Append a string to a multi-string format.
394 This is a internal function.
396 @param MultiString String in <MultiConfigRequest>,
397 <MultiConfigAltResp>, or <MultiConfigResp>. On
398 input, the buffer length of this string is
399 MAX_STRING_LENGTH. On output, the buffer length
401 @param AppendString NULL-terminated Unicode string.
403 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
404 @retval EFI_SUCCESS AppendString is append to the end of MultiString
408 AppendToMultiString (
409 IN OUT EFI_STRING
*MultiString
,
410 IN EFI_STRING AppendString
413 UINTN AppendStringSize
;
414 UINTN MultiStringSize
;
417 if (MultiString
== NULL
|| *MultiString
== NULL
|| AppendString
== NULL
) {
418 return EFI_INVALID_PARAMETER
;
421 AppendStringSize
= StrSize (AppendString
);
422 MultiStringSize
= StrSize (*MultiString
);
423 MaxLen
= MAX_STRING_LENGTH
/ sizeof (CHAR16
);
426 // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.
428 if (MultiStringSize
+ AppendStringSize
> MAX_STRING_LENGTH
||
429 MultiStringSize
> MAX_STRING_LENGTH
) {
430 *MultiString
= (EFI_STRING
) ReallocatePool (
432 MultiStringSize
+ AppendStringSize
,
433 (VOID
*) (*MultiString
)
435 MaxLen
= (MultiStringSize
+ AppendStringSize
) / sizeof (CHAR16
);
436 ASSERT (*MultiString
!= NULL
);
439 // Append the incoming string
441 StrCatS (*MultiString
, MaxLen
, AppendString
);
448 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
450 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
452 This is a internal function.
454 @param StringPtr String in <BlockConfig> format and points to the
455 first character of <Number>.
456 @param Number The output value. Caller takes the responsibility
458 @param Len Length of the <Number>, in characters.
460 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary
462 @retval EFI_SUCCESS Value of <Number> is outputted in Number
468 IN EFI_STRING StringPtr
,
482 if (StringPtr
== NULL
|| *StringPtr
== L
'\0' || Number
== NULL
|| Len
== NULL
) {
483 return EFI_INVALID_PARAMETER
;
489 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
492 *Len
= StringPtr
- TmpPtr
;
495 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
497 Status
= EFI_OUT_OF_RESOURCES
;
500 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
501 *(Str
+ *Len
) = L
'\0';
503 Length
= (Length
+ 1) / 2;
504 Buf
= (UINT8
*) AllocateZeroPool (Length
);
506 Status
= EFI_OUT_OF_RESOURCES
;
511 ZeroMem (TemStr
, sizeof (TemStr
));
512 for (Index
= 0; Index
< Length
; Index
++) {
513 TemStr
[0] = Str
[Length
- Index
- 1];
514 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
515 if ((Index
& 1) == 0) {
516 Buf
[Index
/2] = DigitUint8
;
518 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
523 Status
= EFI_SUCCESS
;
534 To find the BlockName in the string with same value.
536 @param String Pointer to a Null-terminated Unicode string.
537 @param BlockName Pointer to a Null-terminated Unicode string to search for.
538 @param Buffer Pointer to the value correspond to the BlockName.
539 @param Found The Block whether has been found.
540 @param BufferLen The length of the buffer.
542 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures.
543 @retval EFI_SUCCESS The function finishes successfully.
547 FindSameBlockElement(
548 IN EFI_STRING String
,
549 IN EFI_STRING BlockName
,
562 BlockPtr
= StrStr (String
, BlockName
);
564 while (BlockPtr
!= NULL
) {
565 BlockPtr
+= StrLen (BlockName
);
566 Status
= GetValueOfNumber (BlockPtr
, &TempBuffer
, &Length
);
567 if (EFI_ERROR (Status
)) {
570 ASSERT (TempBuffer
!= NULL
);
571 if ((BufferLen
== Length
) && (0 == CompareMem (Buffer
, TempBuffer
, Length
))) {
573 FreePool (TempBuffer
);
577 FreePool (TempBuffer
);
579 BlockPtr
= StrStr (BlockPtr
+ 1, BlockName
);
586 Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>
587 in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.
589 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
590 <MultiConfigAltResp> format. The default value
591 string may contain more than one ConfigAltResp
592 string for the different varstore buffer.
593 @param ConfigAltResp Pointer to a null-terminated Unicode string in
594 <ConfigAltResp> format.
595 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.
596 @param ConfigAltRespChanged Whether the ConfigAltResp has been changed.
598 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures.
599 @retval EFI_SUCCESS The function finishes successfully.
603 CompareBlockElementDefault (
604 IN EFI_STRING DefaultAltCfgResp
,
605 IN OUT EFI_STRING
*ConfigAltResp
,
606 IN EFI_STRING AltConfigHdr
,
607 IN OUT BOOLEAN
*ConfigAltRespChanged
612 EFI_STRING BlockPtrStart
;
613 EFI_STRING StringPtr
;
614 EFI_STRING AppendString
;
615 EFI_STRING AltConfigHdrPtr
;
625 // Make BlockPtr point to the first <BlockConfig> with AltConfigHdr in DefaultAltCfgResp.
627 AltConfigHdrPtr
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
628 ASSERT (AltConfigHdrPtr
!= NULL
);
629 BlockPtr
= StrStr (AltConfigHdrPtr
, L
"&OFFSET=");
631 // Make StringPtr point to the AltConfigHdr in ConfigAltResp.
633 StringPtr
= StrStr (*ConfigAltResp
, AltConfigHdr
);
634 ASSERT (StringPtr
!= NULL
);
636 while (BlockPtr
!= NULL
) {
638 // Find the "&OFFSET=<Number>" block and get the value of the Number with AltConfigHdr in DefaultAltCfgResp.
640 BlockPtrStart
= BlockPtr
;
641 BlockPtr
+= StrLen (L
"&OFFSET=");
642 Status
= GetValueOfNumber (BlockPtr
, &TempBuffer
, &OffsetLength
);
643 if (EFI_ERROR (Status
)) {
644 Status
= EFI_OUT_OF_RESOURCES
;
648 // To find the same "&OFFSET=<Number>" block in ConfigAltResp.
650 Status
= FindSameBlockElement (StringPtr
, L
"&OFFSET=", TempBuffer
, &FoundOffset
, OffsetLength
);
651 if (TempBuffer
!= NULL
) {
652 FreePool (TempBuffer
);
655 if (EFI_ERROR (Status
)) {
656 Status
= EFI_OUT_OF_RESOURCES
;
661 // Don't find the same "&OFFSET=<Number>" block in ConfigAltResp.
662 // Calculate the size of <BlockConfig>.
663 // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number>.
665 BlockPtr
= StrStr (BlockPtr
+ 1, L
"&OFFSET=");
666 if (BlockPtr
!= NULL
) {
667 AppendSize
= (BlockPtr
- BlockPtrStart
) * sizeof (CHAR16
);
669 AppendSize
= StrSize (BlockPtrStart
);
672 // Copy the <BlockConfig> to AppendString.
674 if (AppendString
== NULL
) {
675 AppendString
= (EFI_STRING
) AllocateZeroPool (AppendSize
+ sizeof (CHAR16
));
676 StrnCatS (AppendString
, AppendSize
/ sizeof (CHAR16
) + 1, BlockPtrStart
, AppendSize
/ sizeof (CHAR16
));
678 TotalSize
= StrSize (AppendString
) + AppendSize
+ sizeof (CHAR16
);
679 AppendString
= (EFI_STRING
) ReallocatePool (
680 StrSize (AppendString
),
684 if (AppendString
== NULL
) {
685 Status
= EFI_OUT_OF_RESOURCES
;
688 StrnCatS (AppendString
, TotalSize
/ sizeof (CHAR16
), BlockPtrStart
, AppendSize
/ sizeof (CHAR16
));
692 // To find next "&OFFSET=<Number>" block with AltConfigHdr in DefaultAltCfgResp.
694 BlockPtr
= StrStr (BlockPtr
+ 1, L
"&OFFSET=");
698 if (AppendString
!= NULL
) {
700 // Reallocate ConfigAltResp to copy the AppendString.
702 TotalSize
= StrSize (*ConfigAltResp
) + StrSize (AppendString
) + sizeof (CHAR16
);
703 *ConfigAltResp
= (EFI_STRING
) ReallocatePool (
704 StrSize (*ConfigAltResp
),
708 if (*ConfigAltResp
== NULL
) {
709 Status
= EFI_OUT_OF_RESOURCES
;
712 StrCatS (*ConfigAltResp
, TotalSize
/ sizeof (CHAR16
), AppendString
);
713 *ConfigAltRespChanged
= TRUE
;
716 Status
= EFI_SUCCESS
;
719 if (AppendString
!= NULL
) {
720 FreePool (AppendString
);
727 Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>
728 in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.
730 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
731 <MultiConfigAltResp> format. The default value
732 string may contain more than one ConfigAltResp
733 string for the different varstore buffer.
734 @param ConfigAltResp Pointer to a null-terminated Unicode string in
735 <ConfigAltResp> format.
736 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.
737 @param ConfigAltRespChanged Whether the ConfigAltResp has been changed.
739 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures.
740 @retval EFI_SUCCESS The function finishes successfully.
744 CompareNameElementDefault (
745 IN EFI_STRING DefaultAltCfgResp
,
746 IN OUT EFI_STRING
*ConfigAltResp
,
747 IN EFI_STRING AltConfigHdr
,
748 IN OUT BOOLEAN
*ConfigAltRespChanged
752 EFI_STRING NvConfigPtr
;
753 EFI_STRING NvConfigStart
;
754 EFI_STRING NvConfigValuePtr
;
755 EFI_STRING StringPtr
;
756 EFI_STRING NvConfigExist
;
757 EFI_STRING AppendString
;
763 NvConfigExist
= NULL
;
765 // Make NvConfigPtr point to the first <NvConfig> with AltConfigHdr in DefaultAltCfgResp.
767 NvConfigPtr
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
768 ASSERT (NvConfigPtr
!= NULL
);
769 NvConfigPtr
= StrStr (NvConfigPtr
+ StrLen(AltConfigHdr
),L
"&");
771 // Make StringPtr point to the first <NvConfig> with AltConfigHdr in ConfigAltResp.
773 StringPtr
= StrStr (*ConfigAltResp
, AltConfigHdr
);
774 ASSERT (StringPtr
!= NULL
);
775 StringPtr
= StrStr (StringPtr
+ StrLen (AltConfigHdr
), L
"&");
776 ASSERT (StringPtr
!= NULL
);
778 while (NvConfigPtr
!= NULL
) {
780 // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number>.
781 // Get the <Label> with AltConfigHdr in DefaultAltCfgResp.
783 NvConfigStart
= NvConfigPtr
;
784 NvConfigValuePtr
= StrStr (NvConfigPtr
+ 1, L
"=");
785 ASSERT (NvConfigValuePtr
!= NULL
);
786 TempChar
= *NvConfigValuePtr
;
787 *NvConfigValuePtr
= L
'\0';
789 // Get the <Label> with AltConfigHdr in ConfigAltResp.
791 NvConfigExist
= StrStr (StringPtr
, NvConfigPtr
);
792 if (NvConfigExist
== NULL
) {
794 // Don't find same <Label> in ConfigAltResp.
795 // Calculate the size of <NvConfig>.
797 *NvConfigValuePtr
= TempChar
;
798 NvConfigPtr
= StrStr (NvConfigPtr
+ 1, L
"&");
799 if (NvConfigPtr
!= NULL
) {
800 AppendSize
= (NvConfigPtr
- NvConfigStart
) * sizeof (CHAR16
);
802 AppendSize
= StrSize (NvConfigStart
);
805 // Copy the <NvConfig> to AppendString.
807 if (AppendString
== NULL
) {
808 AppendString
= (EFI_STRING
) AllocateZeroPool (AppendSize
+ sizeof (CHAR16
));
809 StrnCatS (AppendString
, AppendSize
/ sizeof (CHAR16
) + 1, NvConfigStart
, AppendSize
/ sizeof (CHAR16
));
811 TotalSize
= StrSize (AppendString
) + AppendSize
+ sizeof (CHAR16
);
812 AppendString
= (EFI_STRING
) ReallocatePool (
813 StrSize (AppendString
),
817 if (AppendString
== NULL
) {
818 Status
= EFI_OUT_OF_RESOURCES
;
821 StrnCatS (AppendString
, TotalSize
/ sizeof (CHAR16
), NvConfigStart
, AppendSize
/ sizeof (CHAR16
));
825 // To find next <Label> in DefaultAltCfgResp.
827 *NvConfigValuePtr
= TempChar
;
828 NvConfigPtr
= StrStr (NvConfigPtr
+ 1, L
"&");
831 if (AppendString
!= NULL
) {
833 // Reallocate ConfigAltResp to copy the AppendString.
835 TotalSize
= StrSize (*ConfigAltResp
) + StrSize (AppendString
) + sizeof (CHAR16
);
836 *ConfigAltResp
= (EFI_STRING
) ReallocatePool (
837 StrSize (*ConfigAltResp
),
838 StrSize (*ConfigAltResp
) + StrSize (AppendString
) + sizeof (CHAR16
),
841 if (*ConfigAltResp
== NULL
) {
842 Status
= EFI_OUT_OF_RESOURCES
;
845 StrCatS (*ConfigAltResp
, TotalSize
/ sizeof (CHAR16
), AppendString
);
846 *ConfigAltRespChanged
= TRUE
;
848 Status
= EFI_SUCCESS
;
851 if (AppendString
!= NULL
) {
852 FreePool (AppendString
);
858 Compare the <AltResp> in AltCfgResp and DefaultAltCfgResp, if the <AltResp>
859 in DefaultAltCfgResp but not in AltCfgResp,add it to the AltCfgResp.
861 @param AltCfgResp Pointer to a null-terminated Unicode string in
862 <ConfigAltResp> format.
863 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
864 <MultiConfigAltResp> format. The default value
865 string may contain more than one ConfigAltResp
866 string for the different varstore buffer.
867 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.
869 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary
871 @retval EFI_SUCCESS The function finishes successfully.
875 CompareAndMergeDefaultString (
876 IN OUT EFI_STRING
*AltCfgResp
,
877 IN EFI_STRING DefaultAltCfgResp
,
878 IN EFI_STRING AltConfigHdr
882 EFI_STRING AltCfgRespBackup
;
883 EFI_STRING AltConfigHdrPtr
;
884 EFI_STRING AltConfigHdrPtrNext
;
885 EFI_STRING ConfigAltResp
;
886 EFI_STRING StringPtr
;
887 EFI_STRING StringPtrNext
;
889 UINTN ReallocateSize
;
892 BOOLEAN ConfigAltRespChanged
;
894 Status
= EFI_OUT_OF_RESOURCES
;
896 AltConfigHdrPtrNext
= NULL
;
897 StringPtrNext
= NULL
;
898 ConfigAltResp
= NULL
;
899 AltCfgRespBackup
= NULL
;
902 ConfigAltRespChanged
= FALSE
;
905 //To find the <AltResp> with AltConfigHdr in DefaultAltCfgResp, ignore other <AltResp> which follow it.
907 AltConfigHdrPtr
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
908 ASSERT (AltConfigHdrPtr
!= NULL
);
909 AltConfigHdrPtrNext
= StrStr (AltConfigHdrPtr
+ 1, L
"&GUID");
910 if (AltConfigHdrPtrNext
!= NULL
) {
911 TempChar
= *AltConfigHdrPtrNext
;
912 *AltConfigHdrPtrNext
= L
'\0';
915 // To find the <AltResp> with AltConfigHdr in AltCfgResp, ignore other <AltResp> which follow it.
917 StringPtr
= StrStr (*AltCfgResp
, AltConfigHdr
);
918 StringPtrNext
= StrStr (StringPtr
+ 1, L
"&GUID");
919 if (StringPtrNext
!= NULL
) {
920 TempCharA
= *StringPtrNext
;
921 *StringPtrNext
= L
'\0';
924 // Copy the content of <ConfigAltResp> which contain current AltConfigHdr in AltCfgResp.
926 ConfigAltResp
= AllocateCopyPool (StrSize (*AltCfgResp
), *AltCfgResp
);
927 if (ConfigAltResp
== NULL
) {
931 // To find the <ConfigBody> with AltConfigHdr in DefaultAltCfgResp.
933 BlockPtr
= StrStr (AltConfigHdrPtr
, L
"&OFFSET=");
934 if (BlockPtr
!= NULL
) {
936 // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number> style.
937 // Call function CompareBlockElementDefault to compare the <BlockConfig> in DefaultAltCfgResp and ConfigAltResp.
938 // The ConfigAltResp which may contain the new <BlockConfig> get from DefaultAltCfgResp.
940 Status
= CompareBlockElementDefault (DefaultAltCfgResp
, &ConfigAltResp
, AltConfigHdr
, &ConfigAltRespChanged
);
941 if (EFI_ERROR(Status
)) {
946 // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number> style.
947 // Call function CompareNameElementDefault to compare the <NvConfig> in DefaultAltCfgResp and ConfigAltResp.
948 // The ConfigAltResp which may contain the new <NvConfig> get from DefaultAltCfgResp.
950 Status
= CompareNameElementDefault (DefaultAltCfgResp
, &ConfigAltResp
, AltConfigHdr
, &ConfigAltRespChanged
);
951 if (EFI_ERROR(Status
)) {
956 // Restore the AltCfgResp.
958 if (StringPtrNext
!= NULL
) {
959 *StringPtrNext
= TempCharA
;
963 // If the ConfigAltResp has no change,no need to update the content in AltCfgResp.
965 if (!ConfigAltRespChanged
) {
966 Status
= EFI_SUCCESS
;
970 // ConfigAltResp has been changed, need to update the content in AltCfgResp.
972 if (StringPtrNext
!= NULL
) {
973 ReallocateSize
= StrSize (ConfigAltResp
) + StrSize (StringPtrNext
) + sizeof (CHAR16
);
975 ReallocateSize
= StrSize (ConfigAltResp
) + sizeof (CHAR16
);
978 AltCfgRespBackup
= (EFI_STRING
) AllocateZeroPool (ReallocateSize
);
979 if (AltCfgRespBackup
== NULL
) {
983 StrCatS (AltCfgRespBackup
, ReallocateSize
/ sizeof (CHAR16
), ConfigAltResp
);
984 if (StringPtrNext
!= NULL
) {
985 StrCatS (AltCfgRespBackup
, ReallocateSize
/ sizeof (CHAR16
), StringPtrNext
);
988 FreePool (*AltCfgResp
);
989 *AltCfgResp
= AltCfgRespBackup
;
991 Status
= EFI_SUCCESS
;
994 if (ConfigAltResp
!= NULL
) {
995 FreePool(ConfigAltResp
);
998 // Restore the DefaultAltCfgResp.
1000 if ( AltConfigHdrPtrNext
!= NULL
) {
1001 *AltConfigHdrPtrNext
= TempChar
;
1002 AltConfigHdrPtrNext
= NULL
;
1009 This function merges DefaultAltCfgResp string into AltCfgResp string for
1010 the missing AltCfgId in AltCfgResq.
1012 @param AltCfgResp Pointer to a null-terminated Unicode string in
1013 <ConfigAltResp> format. The default value string
1014 will be merged into it.
1015 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
1016 <MultiConfigAltResp> format. The default value
1017 string may contain more than one ConfigAltResp
1018 string for the different varstore buffer.
1020 @retval EFI_SUCCESS The merged string returns.
1021 @retval EFI_INVALID_PARAMETER *AltCfgResp is to NULL.
1025 MergeDefaultString (
1026 IN OUT EFI_STRING
*AltCfgResp
,
1027 IN EFI_STRING DefaultAltCfgResp
1030 EFI_STRING StringPtrDefault
;
1031 EFI_STRING StringPtrEnd
;
1033 EFI_STRING StringPtr
;
1034 EFI_STRING AltConfigHdr
;
1036 UINTN SizeAltCfgResp
;
1040 if (*AltCfgResp
== NULL
) {
1041 return EFI_INVALID_PARAMETER
;
1045 // Get the request ConfigHdr
1048 StringPtr
= *AltCfgResp
;
1051 // Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1053 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1054 return EFI_INVALID_PARAMETER
;
1056 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1059 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1062 if (*StringPtr
== L
'\0') {
1063 return EFI_INVALID_PARAMETER
;
1065 StringPtr
+= StrLen (L
"&PATH=");
1066 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1069 HeaderLength
= StringPtr
- *AltCfgResp
;
1072 // Construct AltConfigHdr string "&<ConfigHdr>&ALTCFG=XXXX\0"
1073 // |1| StrLen (ConfigHdr) | 8 | 4 | 1 |
1075 MaxLen
= 1 + HeaderLength
+ 8 + 4 + 1;
1076 AltConfigHdr
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
1077 if (AltConfigHdr
== NULL
) {
1078 return EFI_OUT_OF_RESOURCES
;
1080 StrCpyS (AltConfigHdr
, MaxLen
, L
"&");
1081 StrnCatS (AltConfigHdr
, MaxLen
, *AltCfgResp
, HeaderLength
);
1082 StrCatS (AltConfigHdr
, MaxLen
, L
"&ALTCFG=");
1083 HeaderLength
= StrLen (AltConfigHdr
);
1085 StringPtrDefault
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
1086 while (StringPtrDefault
!= NULL
) {
1090 StrnCatS (AltConfigHdr
, MaxLen
, StringPtrDefault
+ HeaderLength
, 4);
1091 StringPtr
= StrStr (*AltCfgResp
, AltConfigHdr
);
1094 // Append the found default value string to the input AltCfgResp
1096 if (StringPtr
== NULL
) {
1097 StringPtrEnd
= StrStr (StringPtrDefault
+ 1, L
"&GUID");
1098 SizeAltCfgResp
= StrSize (*AltCfgResp
);
1099 if (StringPtrEnd
== NULL
) {
1101 // No more default string is found.
1103 TotalSize
= SizeAltCfgResp
+ StrSize (StringPtrDefault
);
1104 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
1107 (VOID
*) (*AltCfgResp
)
1109 if (*AltCfgResp
== NULL
) {
1110 FreePool (AltConfigHdr
);
1111 return EFI_OUT_OF_RESOURCES
;
1113 StrCatS (*AltCfgResp
, TotalSize
/ sizeof (CHAR16
), StringPtrDefault
);
1116 TempChar
= *StringPtrEnd
;
1117 *StringPtrEnd
= L
'\0';
1118 TotalSize
= SizeAltCfgResp
+ StrSize (StringPtrDefault
);
1119 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
1122 (VOID
*) (*AltCfgResp
)
1124 if (*AltCfgResp
== NULL
) {
1125 FreePool (AltConfigHdr
);
1126 return EFI_OUT_OF_RESOURCES
;
1128 StrCatS (*AltCfgResp
, TotalSize
/ sizeof (CHAR16
), StringPtrDefault
);
1129 *StringPtrEnd
= TempChar
;
1133 // The AltCfgResp contains <AltCfgResp>.
1134 // If the <ConfigElement> in <AltCfgResp> in the DefaultAltCfgResp but not in the
1135 // related <AltCfgResp> in AltCfgResp, merge it to AltCfgResp. else no need to merge.
1137 CompareAndMergeDefaultString (AltCfgResp
, DefaultAltCfgResp
, AltConfigHdr
);
1141 // Find next AltCfg String
1143 *(AltConfigHdr
+ HeaderLength
) = L
'\0';
1144 StringPtrDefault
= StrStr (StringPtrDefault
+ 1, AltConfigHdr
);
1147 FreePool (AltConfigHdr
);
1152 This function inserts new DefaultValueData into the BlockData DefaultValue array.
1154 @param BlockData The BlockData is updated to add new default value.
1155 @param DefaultValueData The DefaultValue is added.
1159 InsertDefaultValue (
1160 IN IFR_BLOCK_DATA
*BlockData
,
1161 IN IFR_DEFAULT_DATA
*DefaultValueData
1165 IFR_DEFAULT_DATA
*DefaultValueArray
;
1166 LIST_ENTRY
*DefaultLink
;
1168 DefaultLink
= &BlockData
->DefaultValueEntry
;
1170 for (Link
= DefaultLink
->ForwardLink
; Link
!= DefaultLink
; Link
= Link
->ForwardLink
) {
1171 DefaultValueArray
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1172 if (DefaultValueArray
->DefaultId
== DefaultValueData
->DefaultId
) {
1174 // DEFAULT_VALUE_FROM_OPCODE has high priority, DEFAULT_VALUE_FROM_DEFAULT has low priority.
1175 // When default types are DEFAULT_VALUE_FROM_OTHER_DEFAULT, the default value can be overrode.
1177 if ((DefaultValueData
->Type
> DefaultValueArray
->Type
) || (DefaultValueData
->Type
== DefaultValueArray
->Type
&& DefaultValueData
->Type
== DefaultValueFromOtherDefault
)) {
1179 // Update the default value array in BlockData.
1181 CopyMem (&DefaultValueArray
->Value
, &DefaultValueData
->Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1182 DefaultValueArray
->Type
= DefaultValueData
->Type
;
1183 DefaultValueArray
->Cleaned
= DefaultValueData
->Cleaned
;
1190 // Insert new default value data in tail.
1192 DefaultValueArray
= AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1193 ASSERT (DefaultValueArray
!= NULL
);
1194 CopyMem (DefaultValueArray
, DefaultValueData
, sizeof (IFR_DEFAULT_DATA
));
1195 InsertTailList (Link
, &DefaultValueArray
->Entry
);
1199 This function inserts new BlockData into the block link
1201 @param BlockLink The list entry points to block array.
1202 @param BlockData The point to BlockData is added.
1207 IN LIST_ENTRY
*BlockLink
,
1208 IN IFR_BLOCK_DATA
**BlockData
1212 IFR_BLOCK_DATA
*BlockArray
;
1213 IFR_BLOCK_DATA
*BlockSingleData
;
1215 BlockSingleData
= *BlockData
;
1217 if (BlockSingleData
->Name
!= NULL
) {
1218 InsertTailList (BlockLink
, &BlockSingleData
->Entry
);
1223 // Insert block data in its Offset and Width order.
1225 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
1226 BlockArray
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1227 if (BlockArray
->Offset
== BlockSingleData
->Offset
) {
1228 if ((BlockArray
->Width
> BlockSingleData
->Width
) || (BlockSingleData
->IsBitVar
&& BlockArray
->Width
== BlockSingleData
->Width
)) {
1230 // Insert this block data in the front of block array
1232 InsertTailList (Link
, &BlockSingleData
->Entry
);
1236 if ((!BlockSingleData
->IsBitVar
) && BlockArray
->Width
== BlockSingleData
->Width
) {
1238 // The same block array has been added.
1240 if (BlockSingleData
!= BlockArray
) {
1241 FreePool (BlockSingleData
);
1242 *BlockData
= BlockArray
;
1246 } else if (BlockArray
->Offset
> BlockSingleData
->Offset
) {
1248 // Insert new block data in the front of block array
1250 InsertTailList (Link
, &BlockSingleData
->Entry
);
1256 // Add new block data into the tail.
1258 InsertTailList (Link
, &BlockSingleData
->Entry
);
1262 Retrieves a pointer to the a Null-terminated ASCII string containing the list
1263 of languages that an HII handle in the HII Database supports. The returned
1264 string is allocated using AllocatePool(). The caller is responsible for freeing
1265 the returned string using FreePool(). The format of the returned string follows
1266 the language format assumed the HII Database.
1268 If HiiHandle is NULL, then ASSERT().
1270 @param[in] HiiHandle A handle that was previously registered in the HII Database.
1272 @retval NULL HiiHandle is not registered in the HII database
1273 @retval NULL There are not enough resources available to retrieve the supported
1275 @retval NULL The list of supported languages could not be retrieved.
1276 @retval Other A pointer to the Null-terminated ASCII string of supported languages.
1280 GetSupportedLanguages (
1281 IN EFI_HII_HANDLE HiiHandle
1286 CHAR8 TempSupportedLanguages
;
1287 CHAR8
*SupportedLanguages
;
1289 ASSERT (HiiHandle
!= NULL
);
1292 // Retrieve the size required for the supported languages buffer.
1295 Status
= mPrivate
.HiiString
.GetLanguages (&mPrivate
.HiiString
, HiiHandle
, &TempSupportedLanguages
, &LanguageSize
);
1298 // If GetLanguages() returns EFI_SUCCESS for a zero size,
1299 // then there are no supported languages registered for HiiHandle. If GetLanguages()
1300 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
1301 // in the HII Database
1303 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1305 // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database
1311 // Allocate the supported languages buffer.
1313 SupportedLanguages
= AllocateZeroPool (LanguageSize
);
1314 if (SupportedLanguages
== NULL
) {
1316 // Return NULL if allocation fails.
1322 // Retrieve the supported languages string
1324 Status
= mPrivate
.HiiString
.GetLanguages (&mPrivate
.HiiString
, HiiHandle
, SupportedLanguages
, &LanguageSize
);
1325 if (EFI_ERROR (Status
)) {
1327 // Free the buffer and return NULL if the supported languages can not be retrieved.
1329 FreePool (SupportedLanguages
);
1334 // Return the Null-terminated ASCII string of supported languages
1336 return SupportedLanguages
;
1340 Retrieves a string from a string package.
1342 If HiiHandle is NULL, then ASSERT().
1343 If StringId is 0, then ASSET.
1345 @param[in] HiiHandle A handle that was previously registered in the HII Database.
1346 @param[in] StringId The identifier of the string to retrieved from the string
1347 package associated with HiiHandle.
1349 @retval NULL The string specified by StringId is not present in the string package.
1350 @retval Other The string was returned.
1355 IN EFI_HII_HANDLE HiiHandle
,
1356 IN EFI_STRING_ID StringId
1363 CHAR8
*SupportedLanguages
;
1364 CHAR8
*PlatformLanguage
;
1365 CHAR8
*BestLanguage
;
1368 ASSERT (HiiHandle
!= NULL
);
1369 ASSERT (StringId
!= 0);
1372 // Initialize all allocated buffers to NULL
1374 SupportedLanguages
= NULL
;
1375 PlatformLanguage
= NULL
;
1376 BestLanguage
= NULL
;
1381 // Get the languages that the package specified by HiiHandle supports
1383 SupportedLanguages
= GetSupportedLanguages (HiiHandle
);
1384 if (SupportedLanguages
== NULL
) {
1389 // Get the current platform language setting
1391 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
1394 // Get the best matching language from SupportedLanguages
1396 BestLanguage
= GetBestLanguage (
1398 FALSE
, // RFC 4646 mode
1399 Language
, // Highest priority
1400 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Next highest priority
1401 SupportedLanguages
, // Lowest priority
1404 if (BestLanguage
== NULL
) {
1409 // Retrieve the size of the string in the string package for the BestLanguage
1412 Status
= mPrivate
.HiiString
.GetString (
1413 &mPrivate
.HiiString
,
1422 // If GetString() returns EFI_SUCCESS for a zero size,
1423 // then there are no supported languages registered for HiiHandle. If GetString()
1424 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
1425 // in the HII Database
1427 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1432 // Allocate a buffer for the return string
1434 String
= AllocateZeroPool (StringSize
);
1435 if (String
== NULL
) {
1440 // Retrieve the string from the string package
1442 Status
= mPrivate
.HiiString
.GetString (
1443 &mPrivate
.HiiString
,
1451 if (EFI_ERROR (Status
)) {
1453 // Free the buffer and return NULL if the supported languages can not be retrieved.
1461 // Free allocated buffers
1463 if (SupportedLanguages
!= NULL
) {
1464 FreePool (SupportedLanguages
);
1466 if (PlatformLanguage
!= NULL
) {
1467 FreePool (PlatformLanguage
);
1469 if (BestLanguage
!= NULL
) {
1470 FreePool (BestLanguage
);
1474 // Return the Null-terminated Unicode string
1480 This function checks VarOffset and VarWidth is in the block range.
1482 @param RequestBlockArray The block array is to be checked.
1483 @param VarOffset Offset of var to the structure
1484 @param VarWidth Width of var.
1485 @param IsNameValueType Whether this varstore is name/value varstore or not.
1486 @param HiiHandle Hii handle for this hii package.
1488 @retval TRUE This Var is in the block range.
1489 @retval FALSE This Var is not in the block range.
1493 IN IFR_BLOCK_DATA
*RequestBlockArray
,
1494 IN UINT16 VarOffset
,
1496 IN BOOLEAN IsNameValueType
,
1497 IN EFI_HII_HANDLE HiiHandle
1501 IFR_BLOCK_DATA
*BlockData
;
1505 // No Request Block array, all vars are got.
1507 if (RequestBlockArray
== NULL
) {
1512 // Check the input var is in the request block range.
1514 for (Link
= RequestBlockArray
->Entry
.ForwardLink
; Link
!= &RequestBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1515 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1517 if (IsNameValueType
) {
1518 Name
= InternalGetString (HiiHandle
, VarOffset
);
1519 ASSERT (Name
!= NULL
);
1521 if (StrnCmp (BlockData
->Name
, Name
, StrLen (Name
)) == 0) {
1527 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
1537 Get form package data from data base.
1539 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1540 @param HiiFormPackage The buffer saves the package data.
1541 @param PackageSize The buffer size of the package data.
1545 GetFormPackageData (
1546 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1547 IN OUT UINT8
**HiiFormPackage
,
1548 OUT UINTN
*PackageSize
1555 if (DataBaseRecord
== NULL
|| HiiFormPackage
== NULL
|| PackageSize
== NULL
) {
1556 return EFI_INVALID_PARAMETER
;
1562 // 0. Get Hii Form Package by HiiHandle
1564 Status
= ExportFormPackages (
1566 DataBaseRecord
->Handle
,
1567 DataBaseRecord
->PackageList
,
1573 if (EFI_ERROR (Status
)) {
1577 (*HiiFormPackage
) = AllocatePool (ResultSize
);
1578 if (*HiiFormPackage
== NULL
) {
1579 Status
= EFI_OUT_OF_RESOURCES
;
1584 // Get HiiFormPackage by HiiHandle
1588 Status
= ExportFormPackages (
1590 DataBaseRecord
->Handle
,
1591 DataBaseRecord
->PackageList
,
1597 if (EFI_ERROR (Status
)) {
1598 FreePool (*HiiFormPackage
);
1601 *PackageSize
= Size
;
1608 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.
1610 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1611 @param ConfigHdr Request string ConfigHdr. If it is NULL,
1612 the first found varstore will be as ConfigHdr.
1613 @param IsEfiVarstore Whether the request storage type is efi varstore type.
1614 @param EfiVarStore The efi varstore info which will return.
1618 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1619 IN EFI_STRING ConfigHdr
,
1620 OUT BOOLEAN
*IsEfiVarstore
,
1621 OUT EFI_IFR_VARSTORE_EFI
**EfiVarStore
1626 UINTN PackageOffset
;
1627 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1628 CHAR16
*VarStoreName
;
1634 UINT8
*HiiFormPackage
;
1636 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1637 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
1639 HiiFormPackage
= NULL
;
1641 Status
= EFI_SUCCESS
;
1645 *IsEfiVarstore
= FALSE
;
1647 Status
= GetFormPackageData(DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
1648 if (EFI_ERROR (Status
)) {
1652 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1653 PackageOffset
= IfrOffset
;
1654 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) HiiFormPackage
;
1656 while (IfrOffset
< PackageSize
) {
1658 // More than one form packages exist.
1660 if (PackageOffset
>= PackageHeader
->Length
) {
1662 // Process the new form package.
1664 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1665 IfrOffset
+= PackageOffset
;
1666 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1669 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1670 IfrOffset
+= IfrOpHdr
->Length
;
1671 PackageOffset
+= IfrOpHdr
->Length
;
1673 if (IfrOpHdr
->OpCode
== EFI_IFR_VARSTORE_EFI_OP
) {
1674 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1676 // If the length is small than the structure, this is from old efi
1677 // varstore definition. Old efi varstore get config directly from
1678 // GetVariable function.
1680 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1684 NameSize
= AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
);
1685 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1686 if (VarStoreName
== NULL
) {
1687 Status
= EFI_OUT_OF_RESOURCES
;
1690 AsciiStrToUnicodeStrS ((CHAR8
*) IfrEfiVarStore
->Name
, VarStoreName
, NameSize
);
1692 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &IfrEfiVarStore
->Guid
, 1, &GuidStr
);
1693 GenerateSubStr (L
"NAME=", StrLen (VarStoreName
) * sizeof (CHAR16
), (VOID
*) VarStoreName
, 2, &NameStr
);
1694 LengthString
= StrLen (GuidStr
);
1695 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
1696 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
1697 if (TempStr
== NULL
) {
1700 FreePool (VarStoreName
);
1701 Status
= EFI_OUT_OF_RESOURCES
;
1704 StrCpyS (TempStr
, LengthString
, GuidStr
);
1705 StrCatS (TempStr
, LengthString
, NameStr
);
1706 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
1707 *EfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) AllocateZeroPool (IfrOpHdr
->Length
);
1708 if (*EfiVarStore
== NULL
) {
1709 FreePool (VarStoreName
);
1713 Status
= EFI_OUT_OF_RESOURCES
;
1716 *IsEfiVarstore
= TRUE
;
1717 CopyMem (*EfiVarStore
, IfrEfiVarStore
, IfrOpHdr
->Length
);
1721 // Free allocated temp string.
1723 FreePool (VarStoreName
);
1729 // Already found the varstore, break;
1731 if (*IsEfiVarstore
) {
1737 if (HiiFormPackage
!= NULL
) {
1738 FreePool (HiiFormPackage
);
1745 Check whether the ConfigRequest string has the request elements.
1746 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.
1747 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.
1749 @param ConfigRequest The input config request string.
1751 @retval TRUE The input include config request elements.
1752 @retval FALSE The input string not includes.
1756 GetElementsFromRequest (
1757 IN EFI_STRING ConfigRequest
1760 EFI_STRING TmpRequest
;
1762 TmpRequest
= StrStr (ConfigRequest
, L
"PATH=");
1763 ASSERT (TmpRequest
!= NULL
);
1765 if ((StrStr (TmpRequest
, L
"&OFFSET=") != NULL
) || (StrStr (TmpRequest
, L
"&") != NULL
)) {
1773 Check whether the this varstore is the request varstore.
1775 @param VarstoreGuid Varstore guid.
1776 @param Name Varstore name.
1777 @param ConfigHdr Current configRequest info.
1779 @retval TRUE This varstore is the request one.
1780 @retval FALSE This varstore is not the request one.
1785 IN EFI_GUID
*VarstoreGuid
,
1787 IN CHAR16
*ConfigHdr
1801 // If ConfigHdr has name field and varstore not has name, return FALSE.
1803 if (Name
== NULL
&& ConfigHdr
!= NULL
&& StrStr (ConfigHdr
, L
"NAME=&") == NULL
) {
1807 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*)VarstoreGuid
, 1, &GuidStr
);
1809 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
1811 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
1813 LengthString
= StrLen (GuidStr
);
1814 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
1815 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
1816 if (TempStr
== NULL
) {
1820 StrCpyS (TempStr
, LengthString
, GuidStr
);
1821 StrCatS (TempStr
, LengthString
, NameStr
);
1823 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
1828 if (GuidStr
!= NULL
) {
1832 if (NameStr
!= NULL
) {
1836 if (TempStr
!= NULL
) {
1844 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.
1846 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1847 @param ConfigHdr Request string ConfigHdr. If it is NULL,
1848 the first found varstore will be as ConfigHdr.
1849 @retval TRUE This hii package is the request one.
1850 @retval FALSE This hii package is not the request one.
1854 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1855 IN EFI_STRING ConfigHdr
1860 UINTN PackageOffset
;
1861 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1862 CHAR16
*VarStoreName
;
1864 UINT8
*HiiFormPackage
;
1866 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1867 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
1868 EFI_IFR_VARSTORE
*IfrVarStore
;
1869 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueVarStore
;
1870 BOOLEAN FindVarstore
;
1872 HiiFormPackage
= NULL
;
1873 VarStoreName
= NULL
;
1874 Status
= EFI_SUCCESS
;
1875 FindVarstore
= FALSE
;
1877 Status
= GetFormPackageData(DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
1878 if (EFI_ERROR (Status
)) {
1882 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1883 PackageOffset
= IfrOffset
;
1884 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) HiiFormPackage
;
1886 while (IfrOffset
< PackageSize
) {
1888 // More than one form packages exist.
1890 if (PackageOffset
>= PackageHeader
->Length
) {
1892 // Process the new form package.
1894 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1895 IfrOffset
+= PackageOffset
;
1896 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1899 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1900 IfrOffset
+= IfrOpHdr
->Length
;
1901 PackageOffset
+= IfrOpHdr
->Length
;
1903 switch (IfrOpHdr
->OpCode
) {
1905 case EFI_IFR_VARSTORE_OP
:
1906 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1908 NameSize
= AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
);
1909 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1910 if (VarStoreName
== NULL
) {
1913 AsciiStrToUnicodeStrS ((CHAR8
*)IfrVarStore
->Name
, VarStoreName
, NameSize
);
1915 if (IsThisVarstore((VOID
*)&IfrVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1916 FindVarstore
= TRUE
;
1919 FreePool (VarStoreName
);
1920 VarStoreName
= NULL
;
1924 case EFI_IFR_VARSTORE_EFI_OP
:
1925 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1926 NameSize
= AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
);
1927 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1928 if (VarStoreName
== NULL
) {
1931 AsciiStrToUnicodeStrS ((CHAR8
*)IfrEfiVarStore
->Name
, VarStoreName
, NameSize
);
1933 if (IsThisVarstore (&IfrEfiVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1934 FindVarstore
= TRUE
;
1937 FreePool (VarStoreName
);
1938 VarStoreName
= NULL
;
1942 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1943 IfrNameValueVarStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
1945 if (IsThisVarstore (&IfrNameValueVarStore
->Guid
, NULL
, ConfigHdr
)) {
1946 FindVarstore
= TRUE
;
1951 case EFI_IFR_FORM_OP
:
1952 case EFI_IFR_FORM_MAP_OP
:
1954 // No matched varstore is found and directly return.
1963 if (HiiFormPackage
!= NULL
) {
1964 FreePool (HiiFormPackage
);
1967 if (VarStoreName
!= NULL
) {
1968 FreePool (VarStoreName
);
1971 return FindVarstore
;
1975 Check whether the this op code is required.
1977 @param RequestBlockArray The array includes all the request info or NULL.
1978 @param HiiHandle The hii handle for this form package.
1979 @param VarStorageData The varstore data structure.
1980 @param IfrOpHdr Ifr opcode header for this opcode.
1981 @param VarWidth The buffer width for this opcode.
1982 @param ReturnData The data block added for this opcode.
1983 @param IsBitVar Whether the the opcode refers to bit storage.
1985 @retval EFI_SUCCESS This opcode is required.
1986 @retval EFI_NOT_FOUND This opcode is not required.
1987 @retval Others Contain some error.
1991 IsThisOpcodeRequired (
1992 IN IFR_BLOCK_DATA
*RequestBlockArray
,
1993 IN EFI_HII_HANDLE HiiHandle
,
1994 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
1995 IN EFI_IFR_OP_HEADER
*IfrOpHdr
,
1997 OUT IFR_BLOCK_DATA
**ReturnData
,
2001 IFR_BLOCK_DATA
*BlockData
;
2003 EFI_STRING_ID NameId
;
2004 EFI_IFR_QUESTION_HEADER
*IfrQuestionHdr
;
2013 IfrQuestionHdr
= (EFI_IFR_QUESTION_HEADER
*)((CHAR8
*) IfrOpHdr
+ sizeof (EFI_IFR_OP_HEADER
));
2015 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2016 NameId
= IfrQuestionHdr
->VarStoreInfo
.VarName
;
2019 // Check whether this question is in requested block array.
2021 if (!BlockArrayCheck (RequestBlockArray
, NameId
, 0, TRUE
, HiiHandle
)) {
2023 // This question is not in the requested string. Skip it.
2025 return EFI_NOT_FOUND
;
2029 // Get the byte offset/with and bit offset/width
2032 BitOffset
= IfrQuestionHdr
->VarStoreInfo
.VarOffset
;
2033 BitWidth
= VarWidth
;
2034 VarOffset
= BitOffset
/ 8;
2036 // Use current bit width and the bit width before current bit (with same byte offset) to calculate the byte width.
2038 TotalBits
= BitOffset
% 8 + BitWidth
;
2039 VarWidth
= (TotalBits
% 8 == 0 ? TotalBits
/ 8: TotalBits
/ 8 + 1);
2041 VarOffset
= IfrQuestionHdr
->VarStoreInfo
.VarOffset
;
2042 BitWidth
= VarWidth
;
2043 BitOffset
= VarOffset
* 8;
2047 // Check whether this question is in requested block array.
2049 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
, FALSE
, HiiHandle
)) {
2051 // This question is not in the requested string. Skip it.
2053 return EFI_NOT_FOUND
;
2057 // Check this var question is in the var storage
2059 if (((VarOffset
+ VarWidth
) > VarStorageData
->Size
)) {
2060 return EFI_INVALID_PARAMETER
;
2064 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2065 if (BlockData
== NULL
) {
2066 return EFI_OUT_OF_RESOURCES
;
2069 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2070 BlockData
->Name
= InternalGetString(HiiHandle
, NameId
);
2072 BlockData
->Offset
= VarOffset
;
2075 BlockData
->Width
= VarWidth
;
2076 BlockData
->QuestionId
= IfrQuestionHdr
->QuestionId
;
2077 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
2078 BlockData
->Scope
= IfrOpHdr
->Scope
;
2079 BlockData
->IsBitVar
= IsBitVar
;
2080 BlockData
->BitOffset
= BitOffset
;
2081 BlockData
->BitWidth
= BitWidth
;
2082 InitializeListHead (&BlockData
->DefaultValueEntry
);
2084 // Add Block Data into VarStorageData BlockEntry
2086 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
2087 *ReturnData
= BlockData
;
2093 This function parses Form Package to get the block array and the default
2094 value array according to the request ConfigHdr.
2096 @param HiiHandle Hii Handle for this hii package.
2097 @param Package Pointer to the form package data.
2098 @param PackageLength Length of the package.
2099 @param ConfigHdr Request string ConfigHdr. If it is NULL,
2100 the first found varstore will be as ConfigHdr.
2101 @param RequestBlockArray The block array is retrieved from the request string.
2102 @param VarStorageData VarStorage structure contains the got block and default value.
2103 @param DefaultIdArray Point to the got default id and default name array.
2105 @retval EFI_SUCCESS The block array and the default value array are got.
2106 @retval EFI_INVALID_PARAMETER The varstore definition in the different form packages
2108 @retval EFI_OUT_OF_RESOURCES No enough memory.
2113 IN EFI_HII_HANDLE HiiHandle
,
2115 IN UINT32 PackageLength
,
2116 IN EFI_STRING ConfigHdr
,
2117 IN IFR_BLOCK_DATA
*RequestBlockArray
,
2118 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
2119 OUT IFR_DEFAULT_DATA
*DefaultIdArray
2124 UINTN PackageOffset
;
2125 EFI_IFR_VARSTORE
*IfrVarStore
;
2126 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
2127 EFI_IFR_OP_HEADER
*IfrOpHdr
;
2128 EFI_IFR_ONE_OF
*IfrOneOf
;
2129 EFI_IFR_REF4
*IfrRef
;
2130 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
2131 EFI_IFR_DEFAULT
*IfrDefault
;
2132 EFI_IFR_ORDERED_LIST
*IfrOrderedList
;
2133 EFI_IFR_CHECKBOX
*IfrCheckBox
;
2134 EFI_IFR_PASSWORD
*IfrPassword
;
2135 EFI_IFR_STRING
*IfrString
;
2136 EFI_IFR_DATE
*IfrDate
;
2137 EFI_IFR_TIME
*IfrTime
;
2138 IFR_DEFAULT_DATA DefaultData
;
2139 IFR_DEFAULT_DATA
*DefaultDataPtr
;
2140 IFR_BLOCK_DATA
*BlockData
;
2141 CHAR16
*VarStoreName
;
2144 UINT16 VarDefaultId
;
2145 BOOLEAN FirstOneOfOption
;
2146 BOOLEAN FirstOrderedList
;
2147 LIST_ENTRY
*LinkData
;
2148 LIST_ENTRY
*LinkDefault
;
2149 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueVarStore
;
2150 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
2151 EFI_VARSTORE_ID VarStoreId
;
2152 UINT16 SmallestDefaultId
;
2153 BOOLEAN SmallestIdFromFlag
;
2154 BOOLEAN FromOtherDefaultOpcode
;
2155 BOOLEAN QuestionReferBitField
;
2157 Status
= EFI_SUCCESS
;
2159 DefaultDataPtr
= NULL
;
2160 FirstOneOfOption
= FALSE
;
2162 FirstOrderedList
= FALSE
;
2163 VarStoreName
= NULL
;
2164 ZeroMem (&DefaultData
, sizeof (IFR_DEFAULT_DATA
));
2165 SmallestDefaultId
= 0xFFFF;
2166 FromOtherDefaultOpcode
= FALSE
;
2167 QuestionReferBitField
= FALSE
;
2170 // Go through the form package to parse OpCode one by one.
2172 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
2173 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) Package
;
2174 IfrOffset
= PackageOffset
;
2175 while (IfrOffset
< PackageLength
) {
2178 // More than one form package found.
2180 if (PackageOffset
>= PackageHeader
->Length
) {
2182 // Already found varstore for this request, break;
2184 if (VarStoreId
!= 0) {
2189 // Get next package header info.
2191 IfrOffset
+= sizeof (EFI_HII_PACKAGE_HEADER
);
2192 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
2193 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (Package
+ IfrOffset
);
2196 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (Package
+ IfrOffset
);
2197 switch (IfrOpHdr
->OpCode
) {
2198 case EFI_IFR_VARSTORE_OP
:
2200 // VarStore is found. Don't need to search any more.
2202 if (VarStoreId
!= 0) {
2206 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
2208 NameSize
= AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
);
2209 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
2210 if (VarStoreName
== NULL
) {
2211 Status
= EFI_OUT_OF_RESOURCES
;
2214 AsciiStrToUnicodeStrS ((CHAR8
*)IfrVarStore
->Name
, VarStoreName
, NameSize
);
2216 if (IsThisVarstore((VOID
*)&IfrVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
2218 // Find the matched VarStore
2220 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
);
2221 VarStorageData
->Size
= IfrVarStore
->Size
;
2222 VarStorageData
->Name
= VarStoreName
;
2223 VarStorageData
->Type
= EFI_HII_VARSTORE_BUFFER
;
2224 VarStoreId
= IfrVarStore
->VarStoreId
;
2226 FreePool (VarStoreName
);
2227 VarStoreName
= NULL
;
2231 case EFI_IFR_VARSTORE_EFI_OP
:
2233 // VarStore is found. Don't need to search any more.
2235 if (VarStoreId
!= 0) {
2239 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
2242 // If the length is small than the structure, this is from old efi
2243 // varstore definition. Old efi varstore get config directly from
2244 // GetVariable function.
2246 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
2250 NameSize
= AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
);
2251 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
2252 if (VarStoreName
== NULL
) {
2253 Status
= EFI_OUT_OF_RESOURCES
;
2256 AsciiStrToUnicodeStrS ((CHAR8
*)IfrEfiVarStore
->Name
, VarStoreName
, NameSize
);
2258 if (IsThisVarstore (&IfrEfiVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
2260 // Find the matched VarStore
2262 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrEfiVarStore
->Guid
);
2263 VarStorageData
->Size
= IfrEfiVarStore
->Size
;
2264 VarStorageData
->Name
= VarStoreName
;
2265 VarStorageData
->Type
= EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
;
2266 VarStoreId
= IfrEfiVarStore
->VarStoreId
;
2268 FreePool (VarStoreName
);
2269 VarStoreName
= NULL
;
2273 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
2275 // VarStore is found. Don't need to search any more.
2277 if (VarStoreId
!= 0) {
2281 IfrNameValueVarStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
2283 if (IsThisVarstore (&IfrNameValueVarStore
->Guid
, NULL
, ConfigHdr
)) {
2285 // Find the matched VarStore
2287 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrNameValueVarStore
->Guid
);
2288 VarStorageData
->Type
= EFI_HII_VARSTORE_NAME_VALUE
;
2289 VarStoreId
= IfrNameValueVarStore
->VarStoreId
;
2293 case EFI_IFR_DEFAULTSTORE_OP
:
2295 // Add new the map between default id and default name.
2297 DefaultDataPtr
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
2298 if (DefaultDataPtr
== NULL
) {
2299 Status
= EFI_OUT_OF_RESOURCES
;
2302 DefaultDataPtr
->DefaultId
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
;
2303 InsertTailList (&DefaultIdArray
->Entry
, &DefaultDataPtr
->Entry
);
2304 DefaultDataPtr
= NULL
;
2307 case EFI_IFR_FORM_OP
:
2308 case EFI_IFR_FORM_MAP_OP
:
2310 // No matched varstore is found and directly return.
2312 if ( VarStoreId
== 0) {
2313 Status
= EFI_SUCCESS
;
2318 case EFI_IFR_REF_OP
:
2320 // Ref question is not in IFR Form. This IFR form is not valid.
2322 if ( VarStoreId
== 0) {
2323 Status
= EFI_INVALID_PARAMETER
;
2327 // Check whether this question is for the requested varstore.
2329 IfrRef
= (EFI_IFR_REF4
*) IfrOpHdr
;
2330 if (IfrRef
->Question
.VarStoreId
!= VarStoreId
) {
2333 VarWidth
= (UINT16
) (sizeof (EFI_HII_REF
));
2336 // The BlockData may allocate by other opcode,need to clean.
2338 if (BlockData
!= NULL
){
2342 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, FALSE
);
2343 if (EFI_ERROR (Status
)) {
2344 if (Status
== EFI_NOT_FOUND
){
2346 //The opcode is not required,exit and parse other opcode.
2354 case EFI_IFR_ONE_OF_OP
:
2355 case EFI_IFR_NUMERIC_OP
:
2357 // Numeric and OneOf has the same opcode structure.
2361 // Numeric and OneOf question is not in IFR Form. This IFR form is not valid.
2363 if (VarStoreId
== 0) {
2364 Status
= EFI_INVALID_PARAMETER
;
2368 // Check whether this question is for the requested varstore.
2370 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
2371 if (IfrOneOf
->Question
.VarStoreId
!= VarStoreId
) {
2375 if (QuestionReferBitField
) {
2376 VarWidth
= IfrOneOf
->Flags
& EDKII_IFR_NUMERIC_SIZE_BIT
;
2378 VarWidth
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
2382 // The BlockData may allocate by other opcode,need to clean.
2384 if (BlockData
!= NULL
){
2388 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, QuestionReferBitField
);
2389 if (EFI_ERROR (Status
)) {
2390 if (Status
== EFI_NOT_FOUND
){
2392 //The opcode is not required,exit and parse other opcode.
2400 //when go to there,BlockData can't be NULLL.
2402 ASSERT (BlockData
!= NULL
);
2404 if (IfrOpHdr
->OpCode
== EFI_IFR_ONE_OF_OP
) {
2406 // Set this flag to TRUE for the first oneof option.
2408 FirstOneOfOption
= TRUE
;
2409 } else if (IfrOpHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) {
2411 // Numeric minimum value will be used as default value when no default is specified.
2413 DefaultData
.Type
= DefaultValueFromDefault
;
2414 if (QuestionReferBitField
) {
2416 // Since default value in bit field was stored as UINT32 type.
2418 CopyMem (&DefaultData
.Value
.u32
, &IfrOneOf
->data
.u32
.MinValue
, sizeof (UINT32
));
2420 switch (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
2421 case EFI_IFR_NUMERIC_SIZE_1
:
2422 DefaultData
.Value
.u8
= IfrOneOf
->data
.u8
.MinValue
;
2425 case EFI_IFR_NUMERIC_SIZE_2
:
2426 CopyMem (&DefaultData
.Value
.u16
, &IfrOneOf
->data
.u16
.MinValue
, sizeof (UINT16
));
2429 case EFI_IFR_NUMERIC_SIZE_4
:
2430 CopyMem (&DefaultData
.Value
.u32
, &IfrOneOf
->data
.u32
.MinValue
, sizeof (UINT32
));
2433 case EFI_IFR_NUMERIC_SIZE_8
:
2434 CopyMem (&DefaultData
.Value
.u64
, &IfrOneOf
->data
.u64
.MinValue
, sizeof (UINT64
));
2438 Status
= EFI_INVALID_PARAMETER
;
2443 // Set default value base on the DefaultId list get from IFR data.
2445 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2446 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2447 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2448 InsertDefaultValue (BlockData
, &DefaultData
);
2453 case EFI_IFR_ORDERED_LIST_OP
:
2455 // offset by question header
2456 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type
2459 FirstOrderedList
= TRUE
;
2461 // OrderedList question is not in IFR Form. This IFR form is not valid.
2463 if (VarStoreId
== 0) {
2464 Status
= EFI_INVALID_PARAMETER
;
2468 // Check whether this question is for the requested varstore.
2470 IfrOrderedList
= (EFI_IFR_ORDERED_LIST
*) IfrOpHdr
;
2471 if (IfrOrderedList
->Question
.VarStoreId
!= VarStoreId
) {
2475 VarWidth
= IfrOrderedList
->MaxContainers
;
2478 // The BlockData may allocate by other opcode,need to clean.
2480 if (BlockData
!= NULL
){
2484 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, FALSE
);
2485 if (EFI_ERROR (Status
)) {
2486 if (Status
== EFI_NOT_FOUND
){
2488 //The opcode is not required,exit and parse other opcode.
2496 case EFI_IFR_CHECKBOX_OP
:
2498 // EFI_IFR_DEFAULT_OP
2499 // offset by question header
2500 // width is 1 sizeof (BOOLEAN)
2501 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.
2502 // value by DefaultOption
2503 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
2507 // CheckBox question is not in IFR Form. This IFR form is not valid.
2509 if (VarStoreId
== 0) {
2510 Status
= EFI_INVALID_PARAMETER
;
2514 // Check whether this question is for the requested varstore.
2516 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
2517 if (IfrCheckBox
->Question
.VarStoreId
!= VarStoreId
) {
2520 VarWidth
= (UINT16
) sizeof (BOOLEAN
);
2523 // The BlockData may allocate by other opcode,need to clean.
2525 if (BlockData
!= NULL
){
2529 if (QuestionReferBitField
) {
2532 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, QuestionReferBitField
);
2533 if (EFI_ERROR (Status
)) {
2534 if (Status
== EFI_NOT_FOUND
){
2536 //The opcode is not required,exit and parse other opcode.
2544 //when go to there,BlockData can't be NULLL.
2546 ASSERT (BlockData
!= NULL
);
2548 SmallestIdFromFlag
= FALSE
;
2551 // Add default value for standard ID by CheckBox Flag
2553 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2555 // Prepare new DefaultValue
2557 DefaultData
.DefaultId
= VarDefaultId
;
2558 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) == EFI_IFR_CHECKBOX_DEFAULT
) {
2560 // When flag is set, default value is TRUE.
2562 DefaultData
.Type
= DefaultValueFromFlag
;
2563 if (QuestionReferBitField
) {
2564 DefaultData
.Value
.u32
= TRUE
;
2566 DefaultData
.Value
.b
= TRUE
;
2568 InsertDefaultValue (BlockData
, &DefaultData
);
2570 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
2572 // Record the SmallestDefaultId and update the SmallestIdFromFlag.
2574 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2575 SmallestIdFromFlag
= TRUE
;
2580 // Add default value for Manufacture ID by CheckBox Flag
2582 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2584 // Prepare new DefaultValue
2586 DefaultData
.DefaultId
= VarDefaultId
;
2587 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) == EFI_IFR_CHECKBOX_DEFAULT_MFG
) {
2589 // When flag is set, default value is TRUE.
2591 DefaultData
.Type
= DefaultValueFromFlag
;
2592 if (QuestionReferBitField
) {
2593 DefaultData
.Value
.u32
= TRUE
;
2595 DefaultData
.Value
.b
= TRUE
;
2597 InsertDefaultValue (BlockData
, &DefaultData
);
2599 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2601 // Record the SmallestDefaultId and update the SmallestIdFromFlag.
2603 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2604 SmallestIdFromFlag
= TRUE
;
2607 if (SmallestIdFromFlag
) {
2609 // When smallest default Id is given by the flag of CheckBox, set default value with TRUE for other default Id in the DefaultId list.
2611 DefaultData
.Type
= DefaultValueFromOtherDefault
;
2612 if (QuestionReferBitField
) {
2613 DefaultData
.Value
.u32
= TRUE
;
2615 DefaultData
.Value
.b
= TRUE
;
2618 // Set default value for all the default id in the DefaultId list.
2620 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2621 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2622 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2623 InsertDefaultValue (BlockData
, &DefaultData
);
2627 // When flag is not set, default value is FASLE.
2629 DefaultData
.Type
= DefaultValueFromDefault
;
2630 if (QuestionReferBitField
) {
2631 DefaultData
.Value
.u32
= FALSE
;
2633 DefaultData
.Value
.b
= FALSE
;
2636 // Set default value for all the default id in the DefaultId list.
2638 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2639 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2640 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2641 InsertDefaultValue (BlockData
, &DefaultData
);
2646 case EFI_IFR_DATE_OP
:
2648 // offset by question header
2649 // width MaxSize * sizeof (CHAR16)
2650 // no default value, only block array
2654 // Date question is not in IFR Form. This IFR form is not valid.
2656 if (VarStoreId
== 0) {
2657 Status
= EFI_INVALID_PARAMETER
;
2661 // Check whether this question is for the requested varstore.
2663 IfrDate
= (EFI_IFR_DATE
*) IfrOpHdr
;
2664 if (IfrDate
->Question
.VarStoreId
!= VarStoreId
) {
2669 // The BlockData may allocate by other opcode,need to clean.
2671 if (BlockData
!= NULL
){
2675 VarWidth
= (UINT16
) sizeof (EFI_HII_DATE
);
2676 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, FALSE
);
2677 if (EFI_ERROR (Status
)) {
2678 if (Status
== EFI_NOT_FOUND
){
2680 //The opcode is not required,exit and parse other opcode.
2688 case EFI_IFR_TIME_OP
:
2690 // offset by question header
2691 // width MaxSize * sizeof (CHAR16)
2692 // no default value, only block array
2696 // Time question is not in IFR Form. This IFR form is not valid.
2698 if (VarStoreId
== 0) {
2699 Status
= EFI_INVALID_PARAMETER
;
2703 // Check whether this question is for the requested varstore.
2705 IfrTime
= (EFI_IFR_TIME
*) IfrOpHdr
;
2706 if (IfrTime
->Question
.VarStoreId
!= VarStoreId
) {
2711 // The BlockData may allocate by other opcode,need to clean.
2713 if (BlockData
!= NULL
){
2717 VarWidth
= (UINT16
) sizeof (EFI_HII_TIME
);
2718 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, FALSE
);
2719 if (EFI_ERROR (Status
)) {
2720 if (Status
== EFI_NOT_FOUND
){
2722 //The opcode is not required,exit and parse other opcode.
2730 case EFI_IFR_STRING_OP
:
2732 // offset by question header
2733 // width MaxSize * sizeof (CHAR16)
2734 // no default value, only block array
2738 // String question is not in IFR Form. This IFR form is not valid.
2740 if (VarStoreId
== 0) {
2741 Status
= EFI_INVALID_PARAMETER
;
2745 // Check whether this question is for the requested varstore.
2747 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
2748 if (IfrString
->Question
.VarStoreId
!= VarStoreId
) {
2753 // The BlockData may allocate by other opcode,need to clean.
2755 if (BlockData
!= NULL
){
2759 VarWidth
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
2760 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, FALSE
);
2761 if (EFI_ERROR (Status
)) {
2762 if (Status
== EFI_NOT_FOUND
){
2764 //The opcode is not required,exit and parse other opcode.
2772 case EFI_IFR_PASSWORD_OP
:
2774 // offset by question header
2775 // width MaxSize * sizeof (CHAR16)
2776 // no default value, only block array
2780 // Password question is not in IFR Form. This IFR form is not valid.
2782 if (VarStoreId
== 0) {
2783 Status
= EFI_INVALID_PARAMETER
;
2787 // Check whether this question is for the requested varstore.
2789 IfrPassword
= (EFI_IFR_PASSWORD
*) IfrOpHdr
;
2790 if (IfrPassword
->Question
.VarStoreId
!= VarStoreId
) {
2795 // The BlockData may allocate by other opcode,need to clean.
2797 if (BlockData
!= NULL
){
2801 VarWidth
= (UINT16
) (IfrPassword
->MaxSize
* sizeof (UINT16
));
2802 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
, FALSE
);
2803 if (EFI_ERROR (Status
)) {
2804 if (Status
== EFI_NOT_FOUND
){
2806 //The opcode is not required,exit and parse other opcode.
2814 // No default value for string.
2819 case EFI_IFR_ONE_OF_OPTION_OP
:
2821 // No matched block data is ignored.
2823 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
2827 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
2828 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
2830 if (!FirstOrderedList
){
2834 // Get ordered list option data type.
2836 if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_8
|| IfrOneOfOption
->Type
== EFI_IFR_TYPE_BOOLEAN
) {
2838 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_16
) {
2840 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_32
) {
2842 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_64
) {
2846 // Invalid ordered list option data type.
2848 Status
= EFI_INVALID_PARAMETER
;
2849 if (BlockData
->Name
!= NULL
) {
2850 FreePool (BlockData
->Name
);
2852 FreePool (BlockData
);
2857 // Calculate Ordered list QuestionId width.
2859 BlockData
->Width
= (UINT16
) (BlockData
->Width
* VarWidth
);
2861 // Check whether this question is in requested block array.
2863 if (!BlockArrayCheck (RequestBlockArray
, BlockData
->Offset
, BlockData
->Width
, (BOOLEAN
)(BlockData
->Name
!= NULL
), HiiHandle
)) {
2865 // This question is not in the requested string. Skip it.
2867 if (BlockData
->Name
!= NULL
) {
2868 FreePool (BlockData
->Name
);
2870 FreePool (BlockData
);
2875 // Check this var question is in the var storage
2877 if ((BlockData
->Name
== NULL
) && ((BlockData
->Offset
+ BlockData
->Width
) > VarStorageData
->Size
)) {
2878 Status
= EFI_INVALID_PARAMETER
;
2879 if (BlockData
->Name
!= NULL
) {
2880 FreePool (BlockData
->Name
);
2882 FreePool (BlockData
);
2886 // Add Block Data into VarStorageData BlockEntry
2888 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
2890 FirstOrderedList
= FALSE
;
2896 // 1. Set default value for OneOf option when flag field has default attribute.
2897 // And set the default value with the smallest default id for other default id in the DefaultId list.
2899 if (((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) ||
2900 ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
)) {
2902 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
2903 // The first oneof option value will be used as default value when no default value is specified.
2905 FirstOneOfOption
= FALSE
;
2907 SmallestIdFromFlag
= FALSE
;
2909 // Prepare new DefaultValue
2911 DefaultData
.Type
= DefaultValueFromFlag
;
2912 CopyMem (&DefaultData
.Value
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2913 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) {
2914 DefaultData
.DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2915 InsertDefaultValue (BlockData
, &DefaultData
);
2916 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
2918 // Record the SmallestDefaultId and update the SmallestIdFromFlag.
2920 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2921 SmallestIdFromFlag
= TRUE
;
2924 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
) {
2925 DefaultData
.DefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2926 InsertDefaultValue (BlockData
, &DefaultData
);
2927 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2929 // Record the SmallestDefaultId and update the SmallestIdFromFlag.
2931 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2932 SmallestIdFromFlag
= TRUE
;
2936 if (SmallestIdFromFlag
) {
2938 // When smallest default Id is given by the flag of oneofOption, set this option value for other default Id in the DefaultId list.
2940 DefaultData
.Type
= DefaultValueFromOtherDefault
;
2942 // Set default value for other default id in the DefaultId list.
2944 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2945 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2946 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2947 InsertDefaultValue (BlockData
, &DefaultData
);
2953 // 2. Set as the default value when this is the first option.
2954 // The first oneof option value will be used as default value when no default value is specified.
2956 if (FirstOneOfOption
) {
2957 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
2958 FirstOneOfOption
= FALSE
;
2961 // Prepare new DefaultValue
2963 DefaultData
.Type
= DefaultValueFromDefault
;
2964 CopyMem (&DefaultData
.Value
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2965 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2966 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2967 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2968 InsertDefaultValue (BlockData
, &DefaultData
);
2973 case EFI_IFR_DEFAULT_OP
:
2975 // Update Current BlockData to the default value.
2977 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
2979 // No matched block data is ignored.
2985 // Get the DefaultId
2987 IfrDefault
= (EFI_IFR_DEFAULT
*) IfrOpHdr
;
2988 VarDefaultId
= IfrDefault
->DefaultId
;
2990 // Prepare new DefaultValue
2992 DefaultData
.Type
= DefaultValueFromOpcode
;
2993 DefaultData
.DefaultId
= VarDefaultId
;
2994 if (QuestionReferBitField
) {
2995 CopyMem (&DefaultData
.Value
.u32
, &IfrDefault
->Value
.u32
, sizeof (UINT32
));
2997 CopyMem (&DefaultData
.Value
, &IfrDefault
->Value
, IfrDefault
->Header
.Length
- OFFSET_OF (EFI_IFR_DEFAULT
, Value
));
3000 // If the value field is expression, set the cleaned flag.
3001 if (IfrDefault
->Type
== EFI_IFR_TYPE_OTHER
) {
3002 DefaultData
.Cleaned
= TRUE
;
3005 // Add DefaultValue into current BlockData
3007 InsertDefaultValue (BlockData
, &DefaultData
);
3010 // Set default value for other default id in the DefaultId list.
3011 // when SmallestDefaultId == VarDefaultId means there are two defaults with same default Id.
3012 // If the two defaults are both from default opcode, use the first default as the default value of other default Id.
3013 // If one from flag and the other form default opcode, use the default opcode value as the default value of other default Id.
3015 if ((SmallestDefaultId
> VarDefaultId
) || (SmallestDefaultId
== VarDefaultId
&& !FromOtherDefaultOpcode
)) {
3016 FromOtherDefaultOpcode
= TRUE
;
3017 SmallestDefaultId
= VarDefaultId
;
3018 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
3019 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
3020 if (DefaultDataPtr
->DefaultId
!= DefaultData
.DefaultId
){
3021 DefaultData
.Type
= DefaultValueFromOtherDefault
;
3022 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
3023 InsertDefaultValue (BlockData
, &DefaultData
);
3029 // After insert the default value, reset the cleaned value for next
3030 // time used. If not set here, need to set the value before every time.
3033 DefaultData
.Cleaned
= FALSE
;
3036 case EFI_IFR_END_OP
:
3038 // End Opcode is for Var question.
3040 QuestionReferBitField
= FALSE
;
3041 if (BlockData
!= NULL
) {
3042 if (BlockData
->Scope
> 0) {
3045 if (BlockData
->Scope
== 0) {
3048 // when finishing parsing a question, clean the SmallestDefaultId and GetDefaultFromDefaultOpcode.
3050 SmallestDefaultId
= 0xFFFF;
3051 FromOtherDefaultOpcode
= FALSE
;
3057 case EFI_IFR_GUID_OP
:
3058 if (CompareGuid ((EFI_GUID
*)((UINT8
*)IfrOpHdr
+ sizeof (EFI_IFR_OP_HEADER
)), &gEdkiiIfrBitVarstoreGuid
)) {
3059 QuestionReferBitField
= TRUE
;
3064 if (BlockData
!= NULL
) {
3065 if (BlockData
->Scope
> 0) {
3066 BlockData
->Scope
= (UINT8
) (BlockData
->Scope
+ IfrOpHdr
->Scope
);
3069 if (BlockData
->Scope
== 0) {
3076 IfrOffset
+= IfrOpHdr
->Length
;
3077 PackageOffset
+= IfrOpHdr
->Length
;
3081 //if Status == EFI_NOT_FOUND, just means the opcode is not required,not contain any error,
3082 //so set the Status to EFI_SUCCESS.
3084 if (Status
== EFI_NOT_FOUND
){
3085 Status
= EFI_SUCCESS
;
3089 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
3090 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
3091 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; ) {
3092 DefaultDataPtr
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
3093 LinkDefault
= LinkDefault
->ForwardLink
;
3094 if (DefaultDataPtr
->Cleaned
== TRUE
) {
3095 RemoveEntryList (&DefaultDataPtr
->Entry
);
3096 FreePool (DefaultDataPtr
);
3105 parse the configrequest string, get the elements.
3107 @param ConfigRequest The input configrequest string.
3108 @param Progress Return the progress data.
3110 @retval Block data pointer.
3114 IN EFI_STRING ConfigRequest
,
3115 OUT EFI_STRING
*Progress
3118 EFI_STRING StringPtr
;
3119 IFR_BLOCK_DATA
*BlockData
;
3120 IFR_BLOCK_DATA
*RequestBlockArray
;
3126 IFR_BLOCK_DATA
*NextBlockData
;
3132 // Init RequestBlockArray
3134 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
3135 if (RequestBlockArray
== NULL
) {
3138 InitializeListHead (&RequestBlockArray
->Entry
);
3141 // Get the request Block array from the request string
3146 // Parse each <RequestElement> if exists
3147 // Only <BlockName> format is supported by this help function.
3148 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
3150 StringPtr
= ConfigRequest
;
3151 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
3153 // Skip the OFFSET string
3155 *Progress
= StringPtr
;
3156 StringPtr
+= StrLen (L
"&OFFSET=");
3160 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3161 if (EFI_ERROR (Status
)) {
3168 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
3170 FreePool (TmpBuffer
);
3172 StringPtr
+= Length
;
3173 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
3176 StringPtr
+= StrLen (L
"&WIDTH=");
3181 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3182 if (EFI_ERROR (Status
)) {
3189 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
3191 FreePool (TmpBuffer
);
3193 StringPtr
+= Length
;
3194 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3201 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
3202 if (BlockData
== NULL
) {
3205 BlockData
->Offset
= Offset
;
3206 BlockData
->Width
= Width
;
3207 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
3210 // Skip &VALUE string if &VALUE does exists.
3212 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) == 0) {
3213 StringPtr
+= StrLen (L
"&VALUE=");
3218 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3219 if (EFI_ERROR (Status
)) {
3222 FreePool (TmpBuffer
);
3223 StringPtr
+= Length
;
3224 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3229 // If '\0', parsing is finished.
3231 if (*StringPtr
== 0) {
3237 // Merge the requested block data.
3239 Link
= RequestBlockArray
->Entry
.ForwardLink
;
3240 while ((Link
!= &RequestBlockArray
->Entry
) && (Link
->ForwardLink
!= &RequestBlockArray
->Entry
)) {
3241 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3242 NextBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3243 if ((NextBlockData
->Offset
>= BlockData
->Offset
) && (NextBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
3244 if ((NextBlockData
->Offset
+ NextBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
3245 BlockData
->Width
= (UINT16
) (NextBlockData
->Offset
+ NextBlockData
->Width
- BlockData
->Offset
);
3247 RemoveEntryList (Link
->ForwardLink
);
3248 FreePool (NextBlockData
);
3251 Link
= Link
->ForwardLink
;
3254 return RequestBlockArray
;
3257 if (RequestBlockArray
!= NULL
) {
3259 // Free Link Array RequestBlockArray
3261 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
3262 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3263 RemoveEntryList (&BlockData
->Entry
);
3264 FreePool (BlockData
);
3267 FreePool (RequestBlockArray
);
3274 parse the configrequest string, get the elements.
3276 @param ConfigRequest The input config request string.
3277 @param Progress Return the progress data.
3279 @retval return data block array.
3283 IN EFI_STRING ConfigRequest
,
3284 OUT EFI_STRING
*Progress
3287 EFI_STRING StringPtr
;
3289 IFR_BLOCK_DATA
*BlockData
;
3290 IFR_BLOCK_DATA
*RequestBlockArray
;
3293 StringPtr
= ConfigRequest
;
3296 // Init RequestBlockArray
3298 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
3299 if (RequestBlockArray
== NULL
) {
3302 InitializeListHead (&RequestBlockArray
->Entry
);
3305 // Get the request Block array from the request string
3309 // Parse each <RequestElement> if exists
3310 // Only <BlockName> format is supported by this help function.
3311 // <BlockName> ::= &'Name***=***
3313 while (StringPtr
!= NULL
&& *StringPtr
== L
'&') {
3315 *Progress
= StringPtr
;
3317 // Skip the L"&" string
3322 if ((NextTag
= StrStr (StringPtr
, L
"=")) != NULL
) {
3325 } else if ((NextTag
= StrStr (StringPtr
, L
"&")) != NULL
) {
3332 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
3333 if (BlockData
== NULL
) {
3340 BlockData
->Name
= AllocateCopyPool(StrSize (StringPtr
), StringPtr
);
3341 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
3345 // If has value, skip the value.
3347 StringPtr
= NextTag
+ 1;
3349 StringPtr
= StrStr (StringPtr
, L
"&");
3350 } else if (NextTag
!= NULL
) {
3352 // restore the '&' text.
3354 StringPtr
= NextTag
;
3359 return RequestBlockArray
;
3362 if (RequestBlockArray
!= NULL
) {
3364 // Free Link Array RequestBlockArray
3366 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
3367 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3368 RemoveEntryList (&BlockData
->Entry
);
3369 if (BlockData
->Name
!= NULL
) {
3370 FreePool (BlockData
->Name
);
3372 FreePool (BlockData
);
3375 FreePool (RequestBlockArray
);
3382 Generate ConfigRequest string base on the varstore info.
3384 @param ConfigHdr The config header for this varstore.
3385 @param VarStorageData The varstore info.
3386 @param Status Return Status.
3387 @param ConfigRequest The ConfigRequest info may be return.
3389 @retval TRUE Need to continue
3390 @retval Others NO need to continue or error occur.
3393 GenerateConfigRequest (
3394 IN CHAR16
*ConfigHdr
,
3395 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
3396 OUT EFI_STATUS
*Status
,
3397 IN OUT EFI_STRING
*ConfigRequest
3403 CHAR16
*FullConfigRequest
;
3405 IFR_BLOCK_DATA
*BlockData
;
3408 // Append VarStorageData BlockEntry into *Request string
3409 // Now support only one varstore in a form package.
3413 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
3414 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
3418 // Compute the length of the entire request starting with <ConfigHdr> and a
3422 Length
= StrLen (ConfigHdr
) + 1;
3424 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
3426 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3427 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3429 // Add <BlockName> length for each Name
3431 // <BlockName> ::= &Name1&Name2&...
3432 // |1| StrLen(Name1)
3434 Length
= Length
+ (1 + StrLen (BlockData
->Name
));
3437 // Add <BlockName> length for each Offset/Width pair
3439 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
3440 // | 8 | 4 | 7 | 4 |
3442 Length
= Length
+ (8 + 4 + 7 + 4);
3446 // No any request block data is found. The request string can't be constructed.
3449 *Status
= EFI_SUCCESS
;
3454 // Allocate buffer for the entire <ConfigRequest>
3456 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3457 if (FullConfigRequest
== NULL
) {
3458 *Status
= EFI_OUT_OF_RESOURCES
;
3461 StringPtr
= FullConfigRequest
;
3464 // Start with <ConfigHdr>
3466 StrCpyS (StringPtr
, Length
, ConfigHdr
);
3467 StringPtr
+= StrLen (StringPtr
);
3470 // Loop through all the Offset/Width pairs and append them to ConfigRequest
3472 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
3473 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3474 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3480 (1 + StrLen (BlockData
->Name
) + 1) * sizeof (CHAR16
),
3486 // Append &OFFSET=XXXX&WIDTH=YYYY\0
3490 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
3491 L
"&OFFSET=%04X&WIDTH=%04X",
3496 StringPtr
+= StrLen (StringPtr
);
3499 // Set to the got full request string.
3501 HiiToLower (FullConfigRequest
);
3503 if (*ConfigRequest
!= NULL
) {
3504 FreePool (*ConfigRequest
);
3506 *ConfigRequest
= FullConfigRequest
;
3512 Generate ConfigRequest Header base on the varstore info.
3514 @param VarStorageData The varstore info.
3515 @param DevicePath Device path for this varstore.
3516 @param ConfigHdr The config header for this varstore.
3518 @retval EFI_SUCCESS Generate the header success.
3519 @retval EFI_OUT_OF_RESOURCES Allocate buffer fail.
3523 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
3524 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3525 OUT EFI_STRING
*ConfigHdr
3534 Status
= EFI_SUCCESS
;
3540 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
3542 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
3543 if (VarStorageData
->Name
!= NULL
) {
3544 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
3546 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
3550 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
3551 (VOID
*) DevicePath
,
3555 Length
= StrLen (GuidStr
) + StrLen (NameStr
) + StrLen (PathStr
) + 1;
3556 if (VarStorageData
->Name
== NULL
) {
3560 *ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3561 if (*ConfigHdr
== NULL
) {
3562 Status
= EFI_OUT_OF_RESOURCES
;
3565 StrCpyS (*ConfigHdr
, Length
, GuidStr
);
3566 StrCatS (*ConfigHdr
, Length
, NameStr
);
3567 if (VarStorageData
->Name
== NULL
) {
3568 StrCatS (*ConfigHdr
, Length
, L
"&");
3570 StrCatS (*ConfigHdr
, Length
, PathStr
);
3573 // Remove the last character L'&'
3575 *(*ConfigHdr
+ StrLen (*ConfigHdr
) - 1) = L
'\0';
3578 if (GuidStr
!= NULL
) {
3582 if (NameStr
!= NULL
) {
3586 if (PathStr
!= NULL
) {
3595 Update the default value in the block data which is used as bit var store.
3598 A question value saved in a bit fied: bitoffset = 1; bitwidth = 2;default value = 1.
3599 And corresponding block data info: offset==0; width==1;currently the default value
3600 is saved as 1.Actually the default value 1 need to be set to bit field 1, so the
3601 default value of this block data shuold be:2.
3605 UINT8 Bit2 : 2; // Question saved in Bit2,so originalBlock info: offset = 0; width = 1;(byte level) defaul = 1.
3606 // (default value record for the bit field)
3610 After function UpdateDefaultValue,the Block info is: offset = 0; width = 1;(byte level) default = 2.
3611 (default value record for the Block)
3613 UpdateDefaultValue function update default value of bit var block based on the bit field info in the block.
3615 @param BlockLink The Link of the block data.
3619 UpdateDefaultValue (
3620 IN LIST_ENTRY
*BlockLink
3624 LIST_ENTRY
*ListEntry
;
3625 LIST_ENTRY
*LinkDefault
;
3626 IFR_BLOCK_DATA
*BlockData
;
3627 IFR_DEFAULT_DATA
*DefaultValueData
;
3630 UINT32 BitFieldDefaultValue
;
3632 for ( Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
3633 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3634 if (!BlockData
->IsBitVar
) {
3637 ListEntry
= &BlockData
->DefaultValueEntry
;
3639 // Update the default value in the block data with all existing default id.
3641 for (LinkDefault
= ListEntry
->ForwardLink
; LinkDefault
!= ListEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
3643 // Get the default data, and the value of the default data is for some field in the block.
3644 // Note: Default value for bit field question is stored as UINT32.
3646 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
3647 BitFieldDefaultValue
= DefaultValueData
->Value
.u32
;
3649 StartBit
= BlockData
->BitOffset
% 8;
3650 EndBit
= StartBit
+ BlockData
->BitWidth
- 1;
3653 // Set the bit field default value to related bit filed, then we will got the new default vaule for the block data.
3655 DefaultValueData
->Value
.u32
= BitFieldWrite32 (0, StartBit
, EndBit
, BitFieldDefaultValue
);
3661 Merge the default value in two block datas which have overlap region.
3663 For bit fields, their related block data may have overlap region, such as:
3666 UINT16 Bit1 : 6; // Question1 refer Bit1, Block1: offset = 0; width = 1;(byte level) default = 1
3667 UINT16 Bit2 : 5; // Question2 refer Bit2, Block2: offset = 0; width = 2;(byte level) default = 5
3668 // (default value record for the bit field)
3672 After function UpdateDefaultValue:
3673 Block1: offset = 0; width = 1;(byte level) default = 1
3674 Block2: offset = 0; width = 2;(byte level) default = 320 (5 * (2 << 6))
3675 (default value record for block)
3677 After function MergeBlockDefaultValue:
3678 Block1: offset = 0; width = 1;(byte level) default = 65
3679 Block2: offset = 0; width = 2;(byte level) default = 321
3680 (Block1 and Block2 has overlap region, merge the overlap value to Block1 and Blcok2)
3682 Block1 and Block2 have overlap byte region, but currntly the default value of Block1 only contains
3683 value of Bit1 (low 6 bits),the default value of Block2 only contains the value of Bit2 (middle 5 bits).
3685 This fuction merge the default value of these two blocks, and make the default value of block1
3686 also contain the value of lower 2 bits of the Bit2. And make the default value of Block2 also
3687 contain the default value of Bit1.
3689 We can get the total value of the whole block that just cover these two blocks(in this case is:
3690 block: offset =0; width =2;) then the value of block2 is same as block, the value of block1 is
3691 the first byte value of block.
3693 @param FirstBlock Point to the block date whose default value need to be merged.
3694 @param SecondBlock Point to the block date whose default value need to be merged.
3698 MergeBlockDefaultValue (
3699 IN OUT IFR_BLOCK_DATA
*FirstBlock
,
3700 IN OUT IFR_BLOCK_DATA
*SecondBlock
3703 LIST_ENTRY
*FirstListEntry
;
3704 LIST_ENTRY
*SecondListEntry
;
3705 LIST_ENTRY
*FirstDefaultLink
;
3706 LIST_ENTRY
*SecondDefaultLink
;
3707 IFR_DEFAULT_DATA
*FirstDefaultValueData
;
3708 IFR_DEFAULT_DATA
*SecondDefaultValueData
;
3709 UINT32
*FirstDefaultValue
;
3710 UINT32
*SecondDefaultValue
;
3712 UINT64 ShiftedValue
;
3715 FirstListEntry
= &FirstBlock
->DefaultValueEntry
;
3716 for (FirstDefaultLink
= FirstListEntry
->ForwardLink
; FirstDefaultLink
!= FirstListEntry
; FirstDefaultLink
= FirstDefaultLink
->ForwardLink
) {
3717 FirstDefaultValueData
= BASE_CR (FirstDefaultLink
, IFR_DEFAULT_DATA
, Entry
);
3718 SecondListEntry
= &SecondBlock
->DefaultValueEntry
;
3719 for (SecondDefaultLink
= SecondListEntry
->ForwardLink
; SecondDefaultLink
!= SecondListEntry
; SecondDefaultLink
= SecondDefaultLink
->ForwardLink
) {
3720 SecondDefaultValueData
= BASE_CR (SecondDefaultLink
, IFR_DEFAULT_DATA
, Entry
);
3721 if (FirstDefaultValueData
->DefaultId
!= SecondDefaultValueData
->DefaultId
) {
3725 // Find default value with same default id in the two blocks.
3726 // Note: Default value for bit field question is stored as UINT32 type.
3728 FirstDefaultValue
= &FirstDefaultValueData
->Value
.u32
;
3729 SecondDefaultValue
= &SecondDefaultValueData
->Value
.u32
;
3731 // 1. Get the default value of the whole blcok that can just cover FirstBlock and SecondBlock.
3732 // 2. Get the default value of FirstBlock and SecondBlock form the value of whole block based
3733 // on the offset and width of FirstBlock and SecondBlock.
3735 if (FirstBlock
->Offset
> SecondBlock
->Offset
) {
3736 OffsetShift
= FirstBlock
->Offset
- SecondBlock
->Offset
;
3737 ShiftedValue
= LShiftU64 ((UINT64
) (*FirstDefaultValue
), OffsetShift
* 8);
3738 TotalValue
= ShiftedValue
| (UINT64
) (*SecondDefaultValue
);
3739 *SecondDefaultValue
= (UINT32
) BitFieldRead64 (TotalValue
, 0, SecondBlock
->Width
* 8 -1);
3740 *FirstDefaultValue
= (UINT32
) BitFieldRead64 (TotalValue
, OffsetShift
* 8, OffsetShift
* 8 + FirstBlock
->Width
*8 -1);
3742 OffsetShift
= SecondBlock
->Offset
-FirstBlock
->Offset
;
3743 ShiftedValue
= LShiftU64 ((UINT64
) (*SecondDefaultValue
), OffsetShift
* 8);
3744 TotalValue
= ShiftedValue
| (UINT64
) (*FirstDefaultValue
);
3745 *FirstDefaultValue
= (UINT32
) BitFieldRead64 (TotalValue
, 0, FirstBlock
->Width
* 8 -1);
3746 *SecondDefaultValue
= (UINT32
) BitFieldRead64 (TotalValue
, OffsetShift
* 8, OffsetShift
* 8 + SecondBlock
->Width
*8 -1);
3754 Update the default value in the block data which used as Bit VarStore
3756 @param BlockLink The Link of the block data.
3760 UpdateBlockDataArray (
3761 IN LIST_ENTRY
*BlockLink
3765 LIST_ENTRY
*TempLink
;
3766 IFR_BLOCK_DATA
*BlockData
;
3767 IFR_BLOCK_DATA
*NextBlockData
;
3770 // 1. Update default value in BitVar block data.
3771 // Sine some block datas are used as BitVarStore, then the default value recored in the block
3772 // is for related bit field in the block. so we need to set the default value to the related bit
3773 // fields in the block data if the block data is used as bit varstore, then the default value of
3774 // the block will be updated.
3776 UpdateDefaultValue (BlockLink
);
3779 // 2.Update default value for overlap BitVar blcok datas.
3780 // For block datas have overlap region, we need to merge the default value in different blocks.
3782 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
3783 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3784 if (!BlockData
->IsBitVar
) {
3787 for (TempLink
= Link
->ForwardLink
; TempLink
!= BlockLink
; TempLink
= TempLink
->ForwardLink
) {
3788 NextBlockData
= BASE_CR (TempLink
, IFR_BLOCK_DATA
, Entry
);
3789 if (!NextBlockData
->IsBitVar
|| NextBlockData
->Offset
>= BlockData
->Offset
+ BlockData
->Width
|| BlockData
->Offset
>= NextBlockData
->Offset
+ NextBlockData
->Width
) {
3793 // Find two blocks are used as bit VarStore and have overlap region, so need to merge default value of these two blocks.
3795 MergeBlockDefaultValue (BlockData
, NextBlockData
);
3801 Generate ConfigAltResp string base on the varstore info.
3803 @param HiiHandle Hii Handle for this hii package.
3804 @param ConfigHdr The config header for this varstore.
3805 @param VarStorageData The varstore info.
3806 @param DefaultIdArray The Default id array.
3807 @param DefaultAltCfgResp The DefaultAltCfgResp info may be return.
3809 @retval TRUE Need to continue
3810 @retval Others NO need to continue or error occur.
3813 GenerateAltConfigResp (
3814 IN EFI_HII_HANDLE HiiHandle
,
3815 IN CHAR16
*ConfigHdr
,
3816 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
3817 IN IFR_DEFAULT_DATA
*DefaultIdArray
,
3818 IN OUT EFI_STRING
*DefaultAltCfgResp
3824 LIST_ENTRY
*LinkData
;
3825 LIST_ENTRY
*LinkDefault
;
3826 LIST_ENTRY
*ListEntry
;
3828 IFR_BLOCK_DATA
*BlockData
;
3829 IFR_DEFAULT_DATA
*DefaultId
;
3830 IFR_DEFAULT_DATA
*DefaultValueData
;
3833 CHAR16
*DefaultString
;
3838 DefaultString
= NULL
;
3840 // Add length for <ConfigHdr> + '\0'
3842 Length
= StrLen (ConfigHdr
) + 1;
3844 UpdateBlockDataArray (&VarStorageData
->BlockEntry
);
3846 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
3847 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
3849 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
3850 // |1| StrLen (ConfigHdr) | 8 | 4 |
3852 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
3854 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
3855 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
3856 ListEntry
= &BlockData
->DefaultValueEntry
;
3857 for (LinkDefault
= ListEntry
->ForwardLink
; LinkDefault
!= ListEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
3858 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
3859 if (DefaultValueData
->DefaultId
!= DefaultId
->DefaultId
) {
3862 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3864 // Add length for "&Name1=zzzzzzzzzzzz"
3867 Length
+= (1 + StrLen (BlockData
->Name
) + 1 + BlockData
->Width
* 2);
3870 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
3871 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
3873 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
3881 // No default value is found. The default string doesn't exist.
3888 // Allocate buffer for the entire <DefaultAltCfgResp>
3890 *DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3891 if (*DefaultAltCfgResp
== NULL
) {
3892 return EFI_OUT_OF_RESOURCES
;
3894 StringPtr
= *DefaultAltCfgResp
;
3897 // Start with <ConfigHdr>
3899 StrCpyS (StringPtr
, Length
, ConfigHdr
);
3900 StringPtr
+= StrLen (StringPtr
);
3902 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
3903 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
3905 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
3906 // |1| StrLen (ConfigHdr) | 8 | 4 |
3910 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
3913 DefaultId
->DefaultId
3915 StringPtr
+= StrLen (StringPtr
);
3917 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
3918 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
3919 ListEntry
= &BlockData
->DefaultValueEntry
;
3920 for (LinkDefault
= ListEntry
->ForwardLink
; LinkDefault
!= ListEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
3921 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
3922 if (DefaultValueData
->DefaultId
!= DefaultId
->DefaultId
) {
3925 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3928 (1 + StrLen (ConfigHdr
) + 1) * sizeof (CHAR16
),
3932 StringPtr
+= StrLen (StringPtr
);
3935 // Add <BlockConfig>
3936 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
3940 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
3941 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
3945 StringPtr
+= StrLen (StringPtr
);
3947 Width
= BlockData
->Width
;
3949 // Convert Value to a hex string in "%x" format
3950 // NOTE: This is in the opposite byte that GUID and PATH use
3952 if (BlockData
->OpCode
== EFI_IFR_STRING_OP
){
3953 DefaultString
= InternalGetString(HiiHandle
, DefaultValueData
->Value
.string
);
3954 TmpBuffer
= AllocateZeroPool (Width
);
3955 ASSERT (TmpBuffer
!= NULL
);
3956 if (DefaultString
!= NULL
) {
3957 StrSize
= StrLen(DefaultString
)* sizeof (CHAR16
);
3958 if (StrSize
> Width
) {
3961 CopyMem (TmpBuffer
, (UINT8
*) DefaultString
, StrSize
);
3964 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
3966 for (; Width
> 0 && (TmpBuffer
!= NULL
); Width
--) {
3967 UnicodeValueToStringS (
3969 Length
* sizeof (CHAR16
) - ((UINTN
)StringPtr
- (UINTN
)*DefaultAltCfgResp
),
3970 PREFIX_ZERO
| RADIX_HEX
,
3971 TmpBuffer
[Width
- 1],
3974 StringPtr
+= StrnLenS (StringPtr
, Length
- ((UINTN
)StringPtr
- (UINTN
)*DefaultAltCfgResp
) / sizeof (CHAR16
));
3976 if (DefaultString
!= NULL
){
3977 FreePool(DefaultString
);
3978 DefaultString
= NULL
;
3980 if (BlockData
->OpCode
== EFI_IFR_STRING_OP
&& TmpBuffer
!= NULL
) {
3981 FreePool(TmpBuffer
);
3988 HiiToLower (*DefaultAltCfgResp
);
3994 This function gets the full request string and full default value string by
3995 parsing IFR data in HII form packages.
3997 When Request points to NULL string, the request string and default value string
3998 for each varstore in form package will return.
4000 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
4001 @param DevicePath Device Path which Hii Config Access Protocol is registered.
4002 @param Request Pointer to a null-terminated Unicode string in
4003 <ConfigRequest> format. When it doesn't contain
4004 any RequestElement, it will be updated to return
4005 the full RequestElement retrieved from IFR data.
4006 If it points to NULL, the request string for the first
4007 varstore in form package will be merged into a
4008 <MultiConfigRequest> format string and return.
4009 @param AltCfgResp Pointer to a null-terminated Unicode string in
4010 <ConfigAltResp> format. When the pointer is to NULL,
4011 the full default value string retrieved from IFR data
4012 will return. When the pinter is to a string, the
4013 full default value string retrieved from IFR data
4014 will be merged into the input string and return.
4015 When Request points to NULL, the default value string
4016 for each varstore in form package will be merged into
4017 a <MultiConfigAltResp> format string and return.
4018 @param PointerProgress Optional parameter, it can be NULL.
4019 When it is not NULL, if Request is NULL, it returns NULL.
4020 On return, points to a character in the Request
4021 string. Points to the string's null terminator if
4022 request was successful. Points to the most recent
4023 & before the first failing name / value pair (or
4024 the beginning of the string if the failure is in
4025 the first name / value pair) if the request was
4027 @retval EFI_SUCCESS The Results string is set to the full request string.
4028 And AltCfgResp contains all default value string.
4029 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
4030 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string
4031 can't be found in Form package.
4032 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.
4033 @retval EFI_INVALID_PARAMETER Request points to NULL.
4038 GetFullStringFromHiiFormPackages (
4039 IN HII_DATABASE_RECORD
*DataBaseRecord
,
4040 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
4041 IN OUT EFI_STRING
*Request
,
4042 IN OUT EFI_STRING
*AltCfgResp
,
4043 OUT EFI_STRING
*PointerProgress OPTIONAL
4047 UINT8
*HiiFormPackage
;
4049 IFR_BLOCK_DATA
*RequestBlockArray
;
4050 IFR_BLOCK_DATA
*BlockData
;
4051 IFR_DEFAULT_DATA
*DefaultValueData
;
4052 IFR_DEFAULT_DATA
*DefaultId
;
4053 IFR_DEFAULT_DATA
*DefaultIdArray
;
4054 IFR_VARSTORAGE_DATA
*VarStorageData
;
4055 EFI_STRING DefaultAltCfgResp
;
4056 EFI_STRING ConfigHdr
;
4057 EFI_STRING StringPtr
;
4058 EFI_STRING Progress
;
4060 if (DataBaseRecord
== NULL
|| DevicePath
== NULL
|| Request
== NULL
|| AltCfgResp
== NULL
) {
4061 return EFI_INVALID_PARAMETER
;
4065 // Initialize the local variables.
4067 RequestBlockArray
= NULL
;
4068 DefaultIdArray
= NULL
;
4069 VarStorageData
= NULL
;
4070 DefaultAltCfgResp
= NULL
;
4072 HiiFormPackage
= NULL
;
4074 Progress
= *Request
;
4076 Status
= GetFormPackageData (DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
4077 if (EFI_ERROR (Status
)) {
4082 // 1. Get the request block array by Request String when Request string contains the block array.
4085 if (*Request
!= NULL
) {
4086 StringPtr
= *Request
;
4090 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4091 Status
= EFI_INVALID_PARAMETER
;
4094 StringPtr
+= StrLen (L
"GUID=");
4095 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
4098 if (*StringPtr
== L
'\0') {
4099 Status
= EFI_INVALID_PARAMETER
;
4102 StringPtr
+= StrLen (L
"&NAME=");
4103 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
4106 if (*StringPtr
== L
'\0') {
4107 Status
= EFI_INVALID_PARAMETER
;
4110 StringPtr
+= StrLen (L
"&PATH=");
4111 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
4115 if (*StringPtr
== L
'\0') {
4117 // No request block is found.
4124 // If StringPtr != NULL, get the request elements.
4126 if (StringPtr
!= NULL
) {
4127 if (StrStr (StringPtr
, L
"&OFFSET=") != NULL
) {
4128 RequestBlockArray
= GetBlockElement(StringPtr
, &Progress
);
4130 RequestBlockArray
= GetNameElement(StringPtr
, &Progress
);
4133 if (RequestBlockArray
== NULL
) {
4134 Status
= EFI_INVALID_PARAMETER
;
4140 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
4142 DefaultIdArray
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
4143 if (DefaultIdArray
== NULL
) {
4144 Status
= EFI_OUT_OF_RESOURCES
;
4147 InitializeListHead (&DefaultIdArray
->Entry
);
4150 // Initialize VarStorageData to store the var store Block and Default value information.
4152 VarStorageData
= (IFR_VARSTORAGE_DATA
*) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA
));
4153 if (VarStorageData
== NULL
) {
4154 Status
= EFI_OUT_OF_RESOURCES
;
4157 InitializeListHead (&VarStorageData
->Entry
);
4158 InitializeListHead (&VarStorageData
->BlockEntry
);
4161 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
4165 // Parse the opcode in form package to get the default setting.
4167 Status
= ParseIfrData (DataBaseRecord
->Handle
,
4169 (UINT32
) PackageSize
,
4174 if (EFI_ERROR (Status
)) {
4179 // No requested varstore in IFR data and directly return
4181 if (VarStorageData
->Type
== 0 && VarStorageData
->Name
== NULL
) {
4182 Status
= EFI_SUCCESS
;
4187 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
4189 Status
= GenerateHdr (VarStorageData
, DevicePath
, &ConfigHdr
);
4190 if (EFI_ERROR (Status
)) {
4194 if (RequestBlockArray
== NULL
) {
4195 if (!GenerateConfigRequest(ConfigHdr
, VarStorageData
, &Status
, Request
)) {
4201 // 4. Construct Default Value string in AltResp according to request element.
4202 // Go through all VarStorageData Entry and get the DefaultId array for each one
4203 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
4205 Status
= GenerateAltConfigResp (DataBaseRecord
->Handle
,ConfigHdr
, VarStorageData
, DefaultIdArray
, &DefaultAltCfgResp
);
4206 if (EFI_ERROR (Status
)) {
4211 // 5. Merge string into the input AltCfgResp if the input *AltCfgResp is not NULL.
4213 if (*AltCfgResp
!= NULL
&& DefaultAltCfgResp
!= NULL
) {
4214 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
4215 FreePool (DefaultAltCfgResp
);
4216 } else if (*AltCfgResp
== NULL
) {
4217 *AltCfgResp
= DefaultAltCfgResp
;
4221 if (RequestBlockArray
!= NULL
) {
4223 // Free Link Array RequestBlockArray
4225 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
4226 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
4227 RemoveEntryList (&BlockData
->Entry
);
4228 if (BlockData
->Name
!= NULL
) {
4229 FreePool (BlockData
->Name
);
4231 FreePool (BlockData
);
4234 FreePool (RequestBlockArray
);
4237 if (VarStorageData
!= NULL
) {
4239 // Free link array VarStorageData
4241 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
4242 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
4243 RemoveEntryList (&BlockData
->Entry
);
4244 if (BlockData
->Name
!= NULL
) {
4245 FreePool (BlockData
->Name
);
4248 // Free default value link array
4250 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
4251 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
4252 RemoveEntryList (&DefaultValueData
->Entry
);
4253 FreePool (DefaultValueData
);
4255 FreePool (BlockData
);
4257 if (VarStorageData
->Name
!= NULL
) {
4258 FreePool (VarStorageData
->Name
);
4259 VarStorageData
->Name
= NULL
;
4261 FreePool (VarStorageData
);
4264 if (DefaultIdArray
!= NULL
) {
4266 // Free DefaultId Array
4268 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
4269 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
4270 RemoveEntryList (&DefaultId
->Entry
);
4271 FreePool (DefaultId
);
4273 FreePool (DefaultIdArray
);
4277 // Free the allocated string
4279 if (ConfigHdr
!= NULL
) {
4280 FreePool (ConfigHdr
);
4284 // Free Package data
4286 if (HiiFormPackage
!= NULL
) {
4287 FreePool (HiiFormPackage
);
4290 if (PointerProgress
!= NULL
) {
4291 if (*Request
== NULL
) {
4292 *PointerProgress
= NULL
;
4293 } else if (EFI_ERROR (Status
)) {
4294 *PointerProgress
= *Request
;
4296 *PointerProgress
= *Request
+ StrLen (*Request
);
4304 This function gets the full request resp string by
4305 parsing IFR data in HII form packages.
4307 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4309 @param EfiVarStoreInfo The efi varstore info which is save in the EFI
4310 varstore data structure.
4311 @param Request Pointer to a null-terminated Unicode string in
4312 <ConfigRequest> format.
4313 @param RequestResp Pointer to a null-terminated Unicode string in
4314 <ConfigResp> format.
4315 @param AccessProgress On return, points to a character in the Request
4316 string. Points to the string's null terminator if
4317 request was successful. Points to the most recent
4318 & before the first failing name / value pair (or
4319 the beginning of the string if the failure is in
4320 the first name / value pair) if the request was
4323 @retval EFI_SUCCESS The Results string is set to the full request string.
4324 And AltCfgResp contains all default value string.
4325 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
4326 @retval EFI_INVALID_PARAMETER Request points to NULL.
4330 GetConfigRespFromEfiVarStore (
4331 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4332 IN EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
,
4333 IN EFI_STRING Request
,
4334 OUT EFI_STRING
*RequestResp
,
4335 OUT EFI_STRING
*AccessProgress
4339 EFI_STRING VarStoreName
;
4344 Status
= EFI_SUCCESS
;
4347 VarStoreName
= NULL
;
4348 *AccessProgress
= Request
;
4350 NameSize
= AsciiStrSize ((CHAR8
*)EfiVarStoreInfo
->Name
);
4351 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
4352 if (VarStoreName
== NULL
) {
4353 Status
= EFI_OUT_OF_RESOURCES
;
4356 AsciiStrToUnicodeStrS ((CHAR8
*) EfiVarStoreInfo
->Name
, VarStoreName
, NameSize
);
4359 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, NULL
);
4360 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
4364 VarStore
= AllocateZeroPool (BufferSize
);
4365 ASSERT (VarStore
!= NULL
);
4366 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, VarStore
);
4367 if (EFI_ERROR (Status
)) {
4371 Status
= HiiBlockToConfig(This
, Request
, VarStore
, BufferSize
, RequestResp
, AccessProgress
);
4372 if (EFI_ERROR (Status
)) {
4377 if (VarStoreName
!= NULL
) {
4378 FreePool (VarStoreName
);
4381 if (VarStore
!= NULL
) {
4382 FreePool (VarStore
);
4390 This function route the full request resp string for efi varstore.
4392 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4394 @param EfiVarStoreInfo The efi varstore info which is save in the EFI
4395 varstore data structure.
4396 @param RequestResp Pointer to a null-terminated Unicode string in
4397 <ConfigResp> format.
4398 @param Result Pointer to a null-terminated Unicode string in
4399 <ConfigResp> format.
4401 @retval EFI_SUCCESS The Results string is set to the full request string.
4402 And AltCfgResp contains all default value string.
4403 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
4404 @retval EFI_INVALID_PARAMETER Request points to NULL.
4408 RouteConfigRespForEfiVarStore (
4409 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4410 IN EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
,
4411 IN EFI_STRING RequestResp
,
4412 OUT EFI_STRING
*Result
4416 EFI_STRING VarStoreName
;
4422 Status
= EFI_SUCCESS
;
4425 VarStoreName
= NULL
;
4426 *Result
= RequestResp
;
4428 NameSize
= AsciiStrSize ((CHAR8
*)EfiVarStoreInfo
->Name
);
4429 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
4430 if (VarStoreName
== NULL
) {
4431 Status
= EFI_OUT_OF_RESOURCES
;
4434 AsciiStrToUnicodeStrS ((CHAR8
*) EfiVarStoreInfo
->Name
, VarStoreName
, NameSize
);
4436 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, NULL
);
4437 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
4438 DEBUG ((DEBUG_ERROR
, "The variable does not exist!"));
4442 BlockSize
= BufferSize
;
4443 VarStore
= AllocateZeroPool (BufferSize
);
4444 ASSERT (VarStore
!= NULL
);
4445 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, VarStore
);
4446 if (EFI_ERROR (Status
)) {
4450 Status
= HiiConfigToBlock(This
, RequestResp
, VarStore
, &BlockSize
, Result
);
4451 if (EFI_ERROR (Status
)) {
4455 Status
= gRT
->SetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, EfiVarStoreInfo
->Attributes
, BufferSize
, VarStore
);
4456 if (EFI_ERROR (Status
)) {
4457 *Result
= RequestResp
;
4462 if (VarStoreName
!= NULL
) {
4463 FreePool (VarStoreName
);
4466 if (VarStore
!= NULL
) {
4467 FreePool (VarStore
);
4474 Validate the config request elements.
4476 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format,
4477 without configHdr field.
4479 @retval CHAR16 * THE first Name/value pair not correct.
4480 @retval NULL Success parse the name/value pair
4483 OffsetWidthValidate (
4484 CHAR16
*ConfigElements
4490 StringPtr
= ConfigElements
;
4494 if (StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) != 0) {
4498 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
4501 if (*StringPtr
== L
'\0') {
4505 StringPtr
+= StrLen (L
"&WIDTH=");
4506 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) != 0) {
4510 if (*StringPtr
== L
'\0') {
4517 Validate the config request elements.
4519 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format,
4520 without configHdr field.
4522 @retval CHAR16 * THE first Name/value pair not correct.
4523 @retval NULL Success parse the name/value pair
4528 CHAR16
*ConfigElements
4534 StringPtr
= ConfigElements
;
4538 if (*StringPtr
!= L
'&') {
4543 StringPtr
= StrStr (StringPtr
, L
"&");
4545 if (StringPtr
== NULL
) {
4552 Validate the config request string.
4554 @param ConfigRequest A null-terminated Unicode string in <ConfigRequest> format.
4556 @retval CHAR16 * THE first element not correct.
4557 @retval NULL Success parse the name/value pair
4561 ConfigRequestValidate (
4562 CHAR16
*ConfigRequest
4565 BOOLEAN HasNameField
;
4568 HasNameField
= TRUE
;
4569 StringPtr
= ConfigRequest
;
4572 // Check <ConfigHdr>
4574 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4575 return ConfigRequest
;
4577 StringPtr
+= StrLen (L
"GUID=");
4578 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
4581 if (*StringPtr
== L
'\0') {
4582 return ConfigRequest
;
4584 StringPtr
+= StrLen (L
"&NAME=");
4585 if (*StringPtr
== L
'&') {
4586 HasNameField
= FALSE
;
4588 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
4591 if (*StringPtr
== L
'\0') {
4592 return ConfigRequest
;
4594 StringPtr
+= StrLen (L
"&PATH=");
4595 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
4599 if (*StringPtr
== L
'\0') {
4605 // Should be Buffer varstore, config request should be "OFFSET/Width" pairs.
4607 return OffsetWidthValidate(StringPtr
);
4610 // Should be Name/Value varstore, config request should be "&name1&name2..." pairs.
4612 return NameValueValidate(StringPtr
);
4617 This function allows a caller to extract the current configuration
4618 for one or more named elements from one or more drivers.
4620 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4622 @param Request A null-terminated Unicode string in
4623 <MultiConfigRequest> format.
4624 @param Progress On return, points to a character in the Request
4625 string. Points to the string's null terminator if
4626 request was successful. Points to the most recent
4627 & before the first failing name / value pair (or
4628 the beginning of the string if the failure is in
4629 the first name / value pair) if the request was
4631 @param Results Null-terminated Unicode string in
4632 <MultiConfigAltResp> format which has all values
4633 filled in for the names in the Request string.
4634 String to be allocated by the called function.
4636 @retval EFI_SUCCESS The Results string is filled with the values
4637 corresponding to all requested names.
4638 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
4639 results that must be stored awaiting possible
4641 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
4642 Progress set to the "G" in "GUID" of the routing
4643 header that doesn't match. Note: There is no
4644 requirement that all routing data be validated
4645 before any configuration extraction.
4646 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
4647 parameter would result in this type of error. The
4648 Progress parameter is set to NULL.
4649 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
4650 before the error or the beginning of the string.
4651 @retval EFI_INVALID_PARAMETER The ExtractConfig function of the underlying HII
4652 Configuration Access Protocol returned
4653 EFI_INVALID_PARAMETER. Progress set to most recent
4654 & before the error or the beginning of the string.
4659 HiiConfigRoutingExtractConfig (
4660 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4661 IN CONST EFI_STRING Request
,
4662 OUT EFI_STRING
*Progress
,
4663 OUT EFI_STRING
*Results
4666 HII_DATABASE_PRIVATE_DATA
*Private
;
4667 EFI_STRING StringPtr
;
4668 EFI_STRING ConfigRequest
;
4670 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
4671 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
4674 HII_DATABASE_RECORD
*Database
;
4675 UINT8
*DevicePathPkg
;
4676 UINT8
*CurrentDevicePath
;
4677 EFI_HANDLE DriverHandle
;
4678 EFI_HII_HANDLE HiiHandle
;
4679 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
4680 EFI_STRING AccessProgress
;
4681 EFI_STRING AccessResults
;
4682 EFI_STRING AccessProgressBackup
;
4683 EFI_STRING AccessResultsBackup
;
4684 EFI_STRING DefaultResults
;
4685 BOOLEAN FirstElement
;
4686 BOOLEAN IfrDataParsedFlag
;
4687 BOOLEAN IsEfiVarStore
;
4688 EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
;
4689 EFI_STRING ErrorPtr
;
4690 UINTN DevicePathSize
;
4691 UINTN ConigStringSize
;
4692 UINTN ConigStringSizeNewsize
;
4693 EFI_STRING ConfigStringPtr
;
4695 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
4696 return EFI_INVALID_PARAMETER
;
4699 if (Request
== NULL
) {
4701 return EFI_INVALID_PARAMETER
;
4704 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4705 StringPtr
= Request
;
4706 *Progress
= StringPtr
;
4707 DefaultResults
= NULL
;
4708 ConfigRequest
= NULL
;
4709 Status
= EFI_SUCCESS
;
4710 AccessResults
= NULL
;
4711 AccessProgress
= NULL
;
4712 AccessResultsBackup
= NULL
;
4713 AccessProgressBackup
= NULL
;
4715 IfrDataParsedFlag
= FALSE
;
4716 IsEfiVarStore
= FALSE
;
4717 EfiVarStoreInfo
= NULL
;
4720 // The first element of <MultiConfigRequest> should be
4721 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
4723 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4724 return EFI_INVALID_PARAMETER
;
4727 FirstElement
= TRUE
;
4730 // Allocate a fix length of memory to store Results. Reallocate memory for
4731 // Results if this fix length is insufficient.
4733 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
4734 if (*Results
== NULL
) {
4735 return EFI_OUT_OF_RESOURCES
;
4738 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
4740 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
4741 // or most recent & before the error.
4743 if (StringPtr
== Request
) {
4744 *Progress
= StringPtr
;
4746 *Progress
= StringPtr
- 1;
4750 // Process each <ConfigRequest> of <MultiConfigRequest>
4752 Length
= CalculateConfigStringLen (StringPtr
);
4753 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
4754 if (ConfigRequest
== NULL
) {
4755 Status
= EFI_OUT_OF_RESOURCES
;
4758 *(ConfigRequest
+ Length
) = 0;
4761 // Get the UEFI device path
4763 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
4764 if (EFI_ERROR (Status
)) {
4769 // Find driver which matches the routing data.
4771 DriverHandle
= NULL
;
4774 for (Link
= Private
->DatabaseList
.ForwardLink
;
4775 Link
!= &Private
->DatabaseList
;
4776 Link
= Link
->ForwardLink
4778 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
4779 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
4780 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
4781 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
4782 if ((CompareMem (DevicePath
,CurrentDevicePath
,DevicePathSize
) == 0) && IsThisPackageList(Database
, ConfigRequest
)) {
4783 DriverHandle
= Database
->DriverHandle
;
4784 HiiHandle
= Database
->Handle
;
4791 // Try to find driver handle by device path.
4793 if (DriverHandle
== NULL
) {
4794 TempDevicePath
= DevicePath
;
4795 Status
= gBS
->LocateDevicePath (
4796 &gEfiDevicePathProtocolGuid
,
4800 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
4802 // Routing data does not match any known driver.
4803 // Set Progress to the 'G' in "GUID" of the routing header.
4805 *Progress
= StringPtr
;
4806 Status
= EFI_NOT_FOUND
;
4812 // Validate ConfigRequest String.
4814 ErrorPtr
= ConfigRequestValidate(ConfigRequest
);
4815 if (ErrorPtr
!= NULL
) {
4816 *Progress
= StrStr (StringPtr
, ErrorPtr
);
4817 Status
= EFI_INVALID_PARAMETER
;
4822 // Check whether ConfigRequest contains request string.
4824 IfrDataParsedFlag
= FALSE
;
4825 if ((HiiHandle
!= NULL
) && !GetElementsFromRequest(ConfigRequest
)) {
4827 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
4829 IfrDataParsedFlag
= TRUE
;
4830 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, &AccessProgress
);
4831 if (EFI_ERROR (Status
)) {
4833 // AccessProgress indicates the parsing progress on <ConfigRequest>.
4834 // Map it to the progress on <MultiConfigRequest> then return it.
4836 ASSERT (AccessProgress
!= NULL
);
4837 *Progress
= StrStr (StringPtr
, AccessProgress
);
4841 // Not any request block is found.
4843 if (!GetElementsFromRequest(ConfigRequest
)) {
4844 AccessResults
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
4845 goto NextConfigString
;
4850 // Check whether this ConfigRequest is search from Efi varstore type storage.
4852 Status
= GetVarStoreType(Database
, ConfigRequest
, &IsEfiVarStore
, &EfiVarStoreInfo
);
4853 if (EFI_ERROR (Status
)) {
4857 if (IsEfiVarStore
) {
4859 // Call the GetVariable function to extract settings.
4861 Status
= GetConfigRespFromEfiVarStore(This
, EfiVarStoreInfo
, ConfigRequest
, &AccessResults
, &AccessProgress
);
4862 FreePool (EfiVarStoreInfo
);
4863 if (EFI_ERROR (Status
)) {
4865 // AccessProgress indicates the parsing progress on <ConfigRequest>.
4866 // Map it to the progress on <MultiConfigRequest> then return it.
4868 *Progress
= StrStr (StringPtr
, AccessProgress
);
4873 // For EfiVarstore, call corresponding ConfigAccess protocol to get the AltCfgResp from driver.
4875 Status
= gBS
->HandleProtocol (
4877 &gEfiHiiConfigAccessProtocolGuid
,
4878 (VOID
**) &ConfigAccess
4880 if (EFI_ERROR (Status
)) {
4882 // The driver has EfiVarStore, may not install ConfigAccess protocol.
4883 // So ignore the error status in this case.
4885 Status
= EFI_SUCCESS
;
4887 Status
= ConfigAccess
->ExtractConfig (
4890 &AccessProgressBackup
,
4891 &AccessResultsBackup
4893 if (!EFI_ERROR(Status
)) {
4895 //Merge the AltCfgResp in AccessResultsBackup to AccessResults
4897 if ((AccessResultsBackup
!= NULL
) && (StrStr (AccessResultsBackup
, L
"&ALTCFG=") != NULL
)) {
4898 ConigStringSize
= StrSize (AccessResults
);
4899 ConfigStringPtr
= StrStr (AccessResultsBackup
, L
"&GUID=");
4900 ConigStringSizeNewsize
= StrSize (ConfigStringPtr
) + ConigStringSize
+ sizeof (CHAR16
);
4901 AccessResults
= (EFI_STRING
) ReallocatePool (
4903 ConigStringSizeNewsize
,
4905 StrCatS (AccessResults
, ConigStringSizeNewsize
/ sizeof (CHAR16
), ConfigStringPtr
);
4909 // In the ExtractConfig function of some driver may not support EfiVarStore,
4910 // may return error status, just ignore the error status in this case.
4912 Status
= EFI_SUCCESS
;
4914 if (AccessResultsBackup
!= NULL
) {
4915 FreePool (AccessResultsBackup
);
4916 AccessResultsBackup
= NULL
;
4921 // Call corresponding ConfigAccess protocol to extract settings
4923 Status
= gBS
->HandleProtocol (
4925 &gEfiHiiConfigAccessProtocolGuid
,
4926 (VOID
**) &ConfigAccess
4928 if (EFI_ERROR (Status
)) {
4932 Status
= ConfigAccess
->ExtractConfig (
4939 if (EFI_ERROR (Status
)) {
4941 // AccessProgress indicates the parsing progress on <ConfigRequest>.
4942 // Map it to the progress on <MultiConfigRequest> then return it.
4944 *Progress
= StrStr (StringPtr
, AccessProgress
);
4949 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
4950 // which separates the first <ConfigAltResp> and the following ones.
4952 ASSERT (*AccessProgress
== 0);
4955 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
4957 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
) {
4958 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
4959 ASSERT_EFI_ERROR (Status
);
4962 FreePool (DevicePath
);
4965 if (DefaultResults
!= NULL
) {
4966 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
4967 ASSERT_EFI_ERROR (Status
);
4968 FreePool (DefaultResults
);
4969 DefaultResults
= NULL
;
4973 if (!FirstElement
) {
4974 Status
= AppendToMultiString (Results
, L
"&");
4975 ASSERT_EFI_ERROR (Status
);
4978 Status
= AppendToMultiString (Results
, AccessResults
);
4979 ASSERT_EFI_ERROR (Status
);
4981 FirstElement
= FALSE
;
4983 FreePool (AccessResults
);
4984 AccessResults
= NULL
;
4985 FreePool (ConfigRequest
);
4986 ConfigRequest
= NULL
;
4989 // Go to next <ConfigRequest> (skip '&').
4991 StringPtr
+= Length
;
4992 if (*StringPtr
== 0) {
4993 *Progress
= StringPtr
;
5001 if (EFI_ERROR (Status
)) {
5002 FreePool (*Results
);
5006 if (ConfigRequest
!= NULL
) {
5007 FreePool (ConfigRequest
);
5010 if (AccessResults
!= NULL
) {
5011 FreePool (AccessResults
);
5014 if (DefaultResults
!= NULL
) {
5015 FreePool (DefaultResults
);
5018 if (DevicePath
!= NULL
) {
5019 FreePool (DevicePath
);
5027 This function allows the caller to request the current configuration for the
5028 entirety of the current HII database and returns the data in a
5029 null-terminated Unicode string.
5031 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5033 @param Results Null-terminated Unicode string in
5034 <MultiConfigAltResp> format which has all values
5035 filled in for the entirety of the current HII
5036 database. String to be allocated by the called
5037 function. De-allocation is up to the caller.
5039 @retval EFI_SUCCESS The Results string is filled with the values
5040 corresponding to all requested names.
5041 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
5042 results that must be stored awaiting possible
5044 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
5045 parameter would result in this type of error.
5050 HiiConfigRoutingExportConfig (
5051 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
5052 OUT EFI_STRING
*Results
5056 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
5057 EFI_STRING AccessResults
;
5058 EFI_STRING Progress
;
5059 EFI_STRING StringPtr
;
5060 EFI_STRING ConfigRequest
;
5062 EFI_HANDLE
*ConfigAccessHandles
;
5063 UINTN NumberConfigAccessHandles
;
5064 BOOLEAN FirstElement
;
5065 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
5066 EFI_HII_HANDLE HiiHandle
;
5067 EFI_STRING DefaultResults
;
5068 HII_DATABASE_PRIVATE_DATA
*Private
;
5070 HII_DATABASE_RECORD
*Database
;
5071 UINT8
*DevicePathPkg
;
5072 UINT8
*CurrentDevicePath
;
5073 BOOLEAN IfrDataParsedFlag
;
5075 if (This
== NULL
|| Results
== NULL
) {
5076 return EFI_INVALID_PARAMETER
;
5079 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
5082 // Allocate a fix length of memory to store Results. Reallocate memory for
5083 // Results if this fix length is insufficient.
5085 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
5086 if (*Results
== NULL
) {
5087 return EFI_OUT_OF_RESOURCES
;
5090 NumberConfigAccessHandles
= 0;
5091 Status
= gBS
->LocateHandleBuffer (
5093 &gEfiHiiConfigAccessProtocolGuid
,
5095 &NumberConfigAccessHandles
,
5096 &ConfigAccessHandles
5098 if (EFI_ERROR (Status
)) {
5102 FirstElement
= TRUE
;
5104 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
5105 Status
= gBS
->HandleProtocol (
5106 ConfigAccessHandles
[Index
],
5107 &gEfiHiiConfigAccessProtocolGuid
,
5108 (VOID
**) &ConfigAccess
5110 if (EFI_ERROR (Status
)) {
5115 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
5117 IfrDataParsedFlag
= FALSE
;
5120 DefaultResults
= NULL
;
5122 ConfigRequest
= NULL
;
5123 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
5124 if (DevicePath
!= NULL
) {
5125 for (Link
= Private
->DatabaseList
.ForwardLink
;
5126 Link
!= &Private
->DatabaseList
;
5127 Link
= Link
->ForwardLink
5129 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
5130 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
5131 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
5135 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
5137 HiiHandle
= Database
->Handle
;
5144 Status
= ConfigAccess
->ExtractConfig (
5150 if (EFI_ERROR (Status
)) {
5152 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
5154 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
5155 IfrDataParsedFlag
= TRUE
;
5156 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
5158 // Get the full request string to get the Current setting again.
5160 if (!EFI_ERROR (Status
) && ConfigRequest
!= NULL
) {
5161 Status
= ConfigAccess
->ExtractConfig (
5167 FreePool (ConfigRequest
);
5169 Status
= EFI_NOT_FOUND
;
5174 if (!EFI_ERROR (Status
)) {
5176 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
5178 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
5179 StringPtr
= StrStr (AccessResults
, L
"&GUID=");
5180 if (StringPtr
!= NULL
) {
5183 if (GetElementsFromRequest (AccessResults
)) {
5184 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &AccessResults
, &DefaultResults
, NULL
);
5185 ASSERT_EFI_ERROR (Status
);
5187 if (StringPtr
!= NULL
) {
5192 // Merge the default sting from IFR code into the got setting from driver.
5194 if (DefaultResults
!= NULL
) {
5195 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
5196 ASSERT_EFI_ERROR (Status
);
5197 FreePool (DefaultResults
);
5198 DefaultResults
= NULL
;
5202 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
5203 // which separates the first <ConfigAltResp> and the following ones.
5205 if (!FirstElement
) {
5206 Status
= AppendToMultiString (Results
, L
"&");
5207 ASSERT_EFI_ERROR (Status
);
5210 Status
= AppendToMultiString (Results
, AccessResults
);
5211 ASSERT_EFI_ERROR (Status
);
5213 FirstElement
= FALSE
;
5215 FreePool (AccessResults
);
5216 AccessResults
= NULL
;
5219 FreePool (ConfigAccessHandles
);
5226 This function processes the results of processing forms and routes it to the
5227 appropriate handlers or storage.
5229 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5231 @param Configuration A null-terminated Unicode string in
5232 <MulltiConfigResp> format.
5233 @param Progress A pointer to a string filled in with the offset of
5234 the most recent & before the first failing name /
5235 value pair (or the beginning of the string if the
5236 failure is in the first name / value pair) or the
5237 terminating NULL if all was successful.
5239 @retval EFI_SUCCESS The results have been distributed or are awaiting
5241 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
5242 results that must be stored awaiting possible
5244 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
5245 would result in this type of error.
5246 @retval EFI_NOT_FOUND Target for the specified routing data was not
5252 HiiConfigRoutingRouteConfig (
5253 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
5254 IN CONST EFI_STRING Configuration
,
5255 OUT EFI_STRING
*Progress
5258 HII_DATABASE_PRIVATE_DATA
*Private
;
5259 EFI_STRING StringPtr
;
5260 EFI_STRING ConfigResp
;
5263 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
5264 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
5266 HII_DATABASE_RECORD
*Database
;
5267 UINT8
*DevicePathPkg
;
5268 UINT8
*CurrentDevicePath
;
5269 EFI_HANDLE DriverHandle
;
5270 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
5271 EFI_STRING AccessProgress
;
5272 EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
;
5273 BOOLEAN IsEfiVarstore
;
5274 UINTN DevicePathSize
;
5276 if (This
== NULL
|| Progress
== NULL
) {
5277 return EFI_INVALID_PARAMETER
;
5280 if (Configuration
== NULL
) {
5282 return EFI_INVALID_PARAMETER
;
5285 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
5286 StringPtr
= Configuration
;
5287 *Progress
= StringPtr
;
5289 AccessProgress
= NULL
;
5290 EfiVarStoreInfo
= NULL
;
5291 IsEfiVarstore
= FALSE
;
5294 // The first element of <MultiConfigResp> should be
5295 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
5297 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
5298 return EFI_INVALID_PARAMETER
;
5301 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
5303 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
5304 // or most recent & before the error.
5306 if (StringPtr
== Configuration
) {
5307 *Progress
= StringPtr
;
5309 *Progress
= StringPtr
- 1;
5313 // Process each <ConfigResp> of <MultiConfigResp>
5315 Length
= CalculateConfigStringLen (StringPtr
);
5316 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
5317 if (ConfigResp
== NULL
) {
5318 return EFI_OUT_OF_RESOURCES
;
5321 // Append '\0' to the end of ConfigRequest
5323 *(ConfigResp
+ Length
) = 0;
5326 // Get the UEFI device path
5328 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
5329 if (EFI_ERROR (Status
)) {
5330 FreePool (ConfigResp
);
5335 // Find driver which matches the routing data.
5337 DriverHandle
= NULL
;
5338 for (Link
= Private
->DatabaseList
.ForwardLink
;
5339 Link
!= &Private
->DatabaseList
;
5340 Link
= Link
->ForwardLink
5342 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
5344 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
5345 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
5346 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
5347 if ((CompareMem (DevicePath
,CurrentDevicePath
,DevicePathSize
) == 0) && IsThisPackageList(Database
, ConfigResp
)) {
5348 DriverHandle
= Database
->DriverHandle
;
5355 // Try to find driver handle by device path.
5357 if (DriverHandle
== NULL
) {
5358 TempDevicePath
= DevicePath
;
5359 Status
= gBS
->LocateDevicePath (
5360 &gEfiDevicePathProtocolGuid
,
5364 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
5366 // Routing data does not match any known driver.
5367 // Set Progress to the 'G' in "GUID" of the routing header.
5369 FreePool (DevicePath
);
5370 *Progress
= StringPtr
;
5371 FreePool (ConfigResp
);
5372 return EFI_NOT_FOUND
;
5376 FreePool (DevicePath
);
5379 // Check whether this ConfigRequest is search from Efi varstore type storage.
5381 Status
= GetVarStoreType(Database
, ConfigResp
, &IsEfiVarstore
, &EfiVarStoreInfo
);
5382 if (EFI_ERROR (Status
)) {
5386 if (IsEfiVarstore
) {
5388 // Call the SetVariable function to route settings.
5390 Status
= RouteConfigRespForEfiVarStore(This
, EfiVarStoreInfo
, ConfigResp
, &AccessProgress
);
5391 FreePool (EfiVarStoreInfo
);
5394 // Call corresponding ConfigAccess protocol to route settings
5396 Status
= gBS
->HandleProtocol (
5398 &gEfiHiiConfigAccessProtocolGuid
,
5399 (VOID
**) &ConfigAccess
5401 if (EFI_ERROR (Status
)) {
5402 *Progress
= StringPtr
;
5403 FreePool (ConfigResp
);
5404 return EFI_NOT_FOUND
;
5407 Status
= ConfigAccess
->RouteConfig (
5413 if (EFI_ERROR (Status
)) {
5414 ASSERT (AccessProgress
!= NULL
);
5416 // AccessProgress indicates the parsing progress on <ConfigResp>.
5417 // Map it to the progress on <MultiConfigResp> then return it.
5419 *Progress
= StrStr (StringPtr
, AccessProgress
);
5421 FreePool (ConfigResp
);
5425 FreePool (ConfigResp
);
5429 // Go to next <ConfigResp> (skip '&').
5431 StringPtr
+= Length
;
5432 if (*StringPtr
== 0) {
5433 *Progress
= StringPtr
;
5446 This helper function is to be called by drivers to map configuration data
5447 stored in byte array ("block") formats such as UEFI Variables into current
5448 configuration strings.
5450 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5452 @param ConfigRequest A null-terminated Unicode string in
5453 <ConfigRequest> format.
5454 @param Block Array of bytes defining the block's configuration.
5455 @param BlockSize Length in bytes of Block.
5456 @param Config Filled-in configuration string. String allocated
5457 by the function. Returned only if call is
5458 successful. It is <ConfigResp> string format.
5459 @param Progress A pointer to a string filled in with the offset of
5460 the most recent & before the first failing
5461 name/value pair (or the beginning of the string if
5462 the failure is in the first name / value pair) or
5463 the terminating NULL if all was successful.
5465 @retval EFI_SUCCESS The request succeeded. Progress points to the null
5466 terminator at the end of the ConfigRequest
5468 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
5469 points to the first character of ConfigRequest.
5470 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
5471 Block parameter would result in this type of
5472 error. Progress points to the first character of
5474 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
5475 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
5476 Block is left updated and Progress points at
5477 the "&" preceding the first non-<BlockName>.
5483 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
5484 IN CONST EFI_STRING ConfigRequest
,
5485 IN CONST UINT8
*Block
,
5486 IN CONST UINTN BlockSize
,
5487 OUT EFI_STRING
*Config
,
5488 OUT EFI_STRING
*Progress
5491 HII_DATABASE_PRIVATE_DATA
*Private
;
5492 EFI_STRING StringPtr
;
5500 EFI_STRING ValueStr
;
5501 EFI_STRING ConfigElement
;
5509 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
5510 return EFI_INVALID_PARAMETER
;
5513 if (Block
== NULL
|| ConfigRequest
== NULL
) {
5514 *Progress
= ConfigRequest
;
5515 return EFI_INVALID_PARAMETER
;
5519 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
5520 ASSERT (Private
!= NULL
);
5522 StringPtr
= ConfigRequest
;
5525 ConfigElement
= NULL
;
5528 // Allocate a fix length of memory to store Results. Reallocate memory for
5529 // Results if this fix length is insufficient.
5531 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
5532 if (*Config
== NULL
) {
5533 return EFI_OUT_OF_RESOURCES
;
5539 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
5540 *Progress
= StringPtr
;
5541 Status
= EFI_INVALID_PARAMETER
;
5544 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
5547 if (*StringPtr
== 0) {
5548 *Progress
= StringPtr
- 1;
5549 Status
= EFI_INVALID_PARAMETER
;
5553 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
5556 if (*StringPtr
== 0) {
5557 *Progress
= StringPtr
;
5559 AppendToMultiString(Config
, ConfigRequest
);
5560 HiiToLower (*Config
);
5570 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
5572 TemChar
= *StringPtr
;
5574 AppendToMultiString(Config
, ConfigRequest
);
5575 *StringPtr
= TemChar
;
5578 // Parse each <RequestElement> if exists
5579 // Only <BlockName> format is supported by this help function.
5580 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
5582 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
5584 // Back up the header of one <BlockName>
5588 StringPtr
+= StrLen (L
"OFFSET=");
5592 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5593 if (EFI_ERROR (Status
)) {
5594 *Progress
= TmpPtr
- 1;
5601 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5603 FreePool (TmpBuffer
);
5605 StringPtr
+= Length
;
5606 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
5607 *Progress
= TmpPtr
- 1;
5608 Status
= EFI_INVALID_PARAMETER
;
5611 StringPtr
+= StrLen (L
"&WIDTH=");
5616 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5617 if (EFI_ERROR (Status
)) {
5618 *Progress
= TmpPtr
- 1;
5625 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5627 FreePool (TmpBuffer
);
5629 StringPtr
+= Length
;
5630 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
5631 *Progress
= TmpPtr
- 1;
5632 Status
= EFI_INVALID_PARAMETER
;
5637 // Calculate Value and convert it to hex string.
5639 if (Offset
+ Width
> BlockSize
) {
5640 *Progress
= StringPtr
;
5641 Status
= EFI_DEVICE_ERROR
;
5645 Value
= (UINT8
*) AllocateZeroPool (Width
);
5646 if (Value
== NULL
) {
5647 *Progress
= ConfigRequest
;
5648 Status
= EFI_OUT_OF_RESOURCES
;
5652 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
5654 Length
= Width
* 2 + 1;
5655 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
5656 if (ValueStr
== NULL
) {
5657 *Progress
= ConfigRequest
;
5658 Status
= EFI_OUT_OF_RESOURCES
;
5662 TemString
= ValueStr
;
5663 TemBuffer
= Value
+ Width
- 1;
5664 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
5665 UnicodeValueToStringS (
5667 Length
* sizeof (CHAR16
) - ((UINTN
)TemString
- (UINTN
)ValueStr
),
5668 PREFIX_ZERO
| RADIX_HEX
,
5672 TemString
+= StrnLenS (TemString
, Length
- ((UINTN
)TemString
- (UINTN
)ValueStr
) / sizeof (CHAR16
));
5679 // Build a ConfigElement
5681 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
5682 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
5683 if (ConfigElement
== NULL
) {
5684 Status
= EFI_OUT_OF_RESOURCES
;
5687 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
5688 if (*StringPtr
== 0) {
5689 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
5691 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
5692 StrCatS (ConfigElement
, Length
, L
"VALUE=");
5693 StrCatS (ConfigElement
, Length
, ValueStr
);
5695 AppendToMultiString (Config
, ConfigElement
);
5697 FreePool (ConfigElement
);
5698 FreePool (ValueStr
);
5699 ConfigElement
= NULL
;
5703 // If '\0', parsing is finished. Otherwise skip '&' to continue
5705 if (*StringPtr
== 0) {
5708 AppendToMultiString (Config
, L
"&");
5713 if (*StringPtr
!= 0) {
5714 *Progress
= StringPtr
- 1;
5715 Status
= EFI_INVALID_PARAMETER
;
5719 HiiToLower (*Config
);
5720 *Progress
= StringPtr
;
5724 if (*Config
!= NULL
) {
5728 if (ValueStr
!= NULL
) {
5729 FreePool (ValueStr
);
5731 if (Value
!= NULL
) {
5734 if (ConfigElement
!= NULL
) {
5735 FreePool (ConfigElement
);
5744 This helper function is to be called by drivers to map configuration strings
5745 to configurations stored in byte array ("block") formats such as UEFI Variables.
5747 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5749 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
5751 @param Block A possibly null array of bytes representing the
5752 current block. Only bytes referenced in the
5753 ConfigResp string in the block are modified. If
5754 this parameter is null or if the *BlockSize
5755 parameter is (on input) shorter than required by
5756 the Configuration string, only the BlockSize
5757 parameter is updated and an appropriate status
5758 (see below) is returned.
5759 @param BlockSize The length of the Block in units of UINT8. On
5760 input, this is the size of the Block. On output,
5761 if successful, contains the largest index of the
5762 modified byte in the Block, or the required buffer
5763 size if the Block is not large enough.
5764 @param Progress On return, points to an element of the ConfigResp
5765 string filled in with the offset of the most
5766 recent '&' before the first failing name / value
5767 pair (or the beginning of the string if the
5768 failure is in the first name / value pair) or the
5769 terminating NULL if all was successful.
5771 @retval EFI_SUCCESS The request succeeded. Progress points to the null
5772 terminator at the end of the ConfigResp string.
5773 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
5774 points to the first character of ConfigResp.
5775 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
5776 Block parameter would result in this type of
5777 error. Progress points to the first character of
5779 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
5780 value pair. Block is left updated and
5781 Progress points at the '&' preceding the first
5783 @retval EFI_BUFFER_TOO_SMALL Block not large enough. Progress undefined.
5784 BlockSize is updated with the required buffer size.
5785 @retval EFI_NOT_FOUND Target for the specified routing data was not found.
5786 Progress points to the "G" in "GUID" of the errant
5793 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
5794 IN CONST EFI_STRING ConfigResp
,
5795 IN OUT UINT8
*Block
,
5796 IN OUT UINTN
*BlockSize
,
5797 OUT EFI_STRING
*Progress
5800 HII_DATABASE_PRIVATE_DATA
*Private
;
5801 EFI_STRING StringPtr
;
5814 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
5815 return EFI_INVALID_PARAMETER
;
5818 *Progress
= ConfigResp
;
5819 if (ConfigResp
== NULL
) {
5820 return EFI_INVALID_PARAMETER
;
5823 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
5824 ASSERT (Private
!= NULL
);
5826 StringPtr
= ConfigResp
;
5827 BufferSize
= *BlockSize
;
5834 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
5835 *Progress
= StringPtr
;
5836 Status
= EFI_INVALID_PARAMETER
;
5839 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
5842 if (*StringPtr
== 0) {
5843 *Progress
= StringPtr
;
5844 Status
= EFI_INVALID_PARAMETER
;
5848 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
5851 if (*StringPtr
== 0) {
5852 *Progress
= StringPtr
;
5853 Status
= EFI_INVALID_PARAMETER
;
5858 // Parse each <ConfigElement> if exists
5859 // Only '&'<BlockConfig> format is supported by this help function.
5860 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
5862 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
5864 StringPtr
+= StrLen (L
"&OFFSET=");
5868 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5869 if (EFI_ERROR (Status
)) {
5877 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5879 FreePool (TmpBuffer
);
5881 StringPtr
+= Length
;
5882 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
5884 Status
= EFI_INVALID_PARAMETER
;
5887 StringPtr
+= StrLen (L
"&WIDTH=");
5892 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5893 if (EFI_ERROR (Status
)) {
5901 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5903 FreePool (TmpBuffer
);
5905 StringPtr
+= Length
;
5906 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
5908 Status
= EFI_INVALID_PARAMETER
;
5911 StringPtr
+= StrLen (L
"&VALUE=");
5916 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
5917 if (EFI_ERROR (Status
)) {
5922 StringPtr
+= Length
;
5923 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
5925 Status
= EFI_INVALID_PARAMETER
;
5930 // Update the Block with configuration info
5932 if ((Block
!= NULL
) && (Offset
+ Width
<= BufferSize
)) {
5933 CopyMem (Block
+ Offset
, Value
, Width
);
5935 if (Offset
+ Width
> MaxBlockSize
) {
5936 MaxBlockSize
= Offset
+ Width
;
5943 // If '\0', parsing is finished.
5945 if (*StringPtr
== 0) {
5951 // The input string is not ConfigResp format, return error.
5953 if (*StringPtr
!= 0) {
5954 *Progress
= StringPtr
;
5955 Status
= EFI_INVALID_PARAMETER
;
5959 *Progress
= StringPtr
+ StrLen (StringPtr
);
5960 *BlockSize
= MaxBlockSize
- 1;
5962 if (MaxBlockSize
> BufferSize
) {
5963 *BlockSize
= MaxBlockSize
;
5964 if (Block
!= NULL
) {
5965 return EFI_BUFFER_TOO_SMALL
;
5969 if (Block
== NULL
) {
5970 *Progress
= ConfigResp
;
5971 return EFI_INVALID_PARAMETER
;
5978 if (Value
!= NULL
) {
5986 This helper function is to be called by drivers to extract portions of
5987 a larger configuration string.
5989 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5991 @param Configuration A null-terminated Unicode string in
5992 <MultiConfigAltResp> format.
5993 @param Guid A pointer to the GUID value to search for in the
5994 routing portion of the ConfigResp string when
5995 retrieving the requested data. If Guid is NULL,
5996 then all GUID values will be searched for.
5997 @param Name A pointer to the NAME value to search for in the
5998 routing portion of the ConfigResp string when
5999 retrieving the requested data. If Name is NULL,
6000 then all Name values will be searched for.
6001 @param DevicePath A pointer to the PATH value to search for in the
6002 routing portion of the ConfigResp string when
6003 retrieving the requested data. If DevicePath is
6004 NULL, then all DevicePath values will be searched
6006 @param AltCfgId A pointer to the ALTCFG value to search for in the
6007 routing portion of the ConfigResp string when
6008 retrieving the requested data. If this parameter
6009 is NULL, then the current setting will be
6011 @param AltCfgResp A pointer to a buffer which will be allocated by
6012 the function which contains the retrieved string
6013 as requested. This buffer is only allocated if
6014 the call was successful. It is <ConfigResp> format.
6016 @retval EFI_SUCCESS The request succeeded. The requested data was
6017 extracted and placed in the newly allocated
6019 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
6020 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
6021 @retval EFI_NOT_FOUND Target for the specified routing data was not
6028 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
6029 IN CONST EFI_STRING Configuration
,
6030 IN CONST EFI_GUID
*Guid
,
6031 IN CONST EFI_STRING Name
,
6032 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
6033 IN CONST UINT16
*AltCfgId
,
6034 OUT EFI_STRING
*AltCfgResp
6038 EFI_STRING StringPtr
;
6039 EFI_STRING HdrStart
;
6046 EFI_STRING AltIdStr
;
6063 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
6064 return EFI_INVALID_PARAMETER
;
6067 StringPtr
= Configuration
;
6068 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
6069 return EFI_INVALID_PARAMETER
;
6073 // Generate the sub string for later matching.
6075 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
6078 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
6079 (VOID
*) DevicePath
,
6083 if (AltCfgId
!= NULL
) {
6084 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
6087 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
6089 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
6092 while (*StringPtr
!= 0) {
6094 // Try to match the GUID
6097 TmpPtr
= StrStr (StringPtr
, GuidStr
);
6098 if (TmpPtr
== NULL
) {
6099 Status
= EFI_NOT_FOUND
;
6105 // Jump to <NameHdr>
6108 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
6110 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
6111 if (StringPtr
== NULL
) {
6112 Status
= EFI_NOT_FOUND
;
6120 // Try to match the NAME
6122 if (GuidFlag
&& !NameFlag
) {
6123 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
6127 // Jump to <PathHdr>
6130 StringPtr
+= StrLen (NameStr
);
6132 StringPtr
= StrStr (StringPtr
, L
"PATH=");
6133 if (StringPtr
== NULL
) {
6134 Status
= EFI_NOT_FOUND
;
6143 // Try to match the DevicePath
6145 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
6146 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
6151 // Jump to '&' before <DescHdr> or <ConfigBody>
6153 if (DevicePath
!= NULL
) {
6154 StringPtr
+= StrLen (PathStr
);
6156 StringPtr
= StrStr (StringPtr
, L
"&");
6157 if (StringPtr
== NULL
) {
6158 Status
= EFI_NOT_FOUND
;
6169 // Try to match the AltCfgId
6171 if (GuidFlag
&& NameFlag
&& PathFlag
) {
6172 if (AltCfgId
== NULL
) {
6174 // Return Current Setting when AltCfgId is NULL.
6176 Status
= OutputConfigBody (StringPtr
, &Result
);
6180 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
6182 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
6188 // Skip AltIdStr and &
6190 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
6191 Status
= OutputConfigBody (StringPtr
, &Result
);
6197 Status
= EFI_NOT_FOUND
;
6201 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
6203 // Copy the <ConfigHdr> and <ConfigBody>
6205 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
6206 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
6207 if (*AltCfgResp
== NULL
) {
6208 Status
= EFI_OUT_OF_RESOURCES
;
6210 StrnCpyS (*AltCfgResp
, Length
, HdrStart
, HdrEnd
- HdrStart
);
6211 StrCatS (*AltCfgResp
, Length
, Result
);
6212 Status
= EFI_SUCCESS
;
6216 if (GuidStr
!= NULL
) {
6219 if (NameStr
!= NULL
) {
6222 if (PathStr
!= NULL
) {
6225 if (AltIdStr
!= NULL
) {
6226 FreePool (AltIdStr
);
6228 if (Result
!= NULL
) {