2 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.
4 Copyright (c) 2007 - 2016, 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 neccesary structures.
69 @retval EFI_SUCCESS The device path is retrieved and translated to
76 OUT UINT8
**DevicePathData
81 UINT8
*DevicePathBuffer
;
85 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
88 if (String
== NULL
|| DevicePathData
== NULL
) {
89 return EFI_INVALID_PARAMETER
;
93 // Find the 'PATH=' of <PathHdr> and skip it.
95 for (; (*String
!= 0 && StrnCmp (String
, L
"PATH=", StrLen (L
"PATH=")) != 0); String
++);
97 return EFI_INVALID_PARAMETER
;
100 // Check whether path data does exist.
102 String
+= StrLen (L
"PATH=");
104 return EFI_INVALID_PARAMETER
;
109 // The content between 'PATH=' of <ConfigHdr> and '&' of next element
110 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding
111 // of UEFI device path.
113 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
115 // Check DevicePath Length
117 if (((Length
+ 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
118 return EFI_NOT_FOUND
;
122 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
123 // as the device path resides in RAM memory.
124 // Translate the data into binary.
126 DevicePathBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
127 if (DevicePathBuffer
== NULL
) {
128 return EFI_OUT_OF_RESOURCES
;
132 // Convert DevicePath
134 ZeroMem (TemStr
, sizeof (TemStr
));
135 for (Index
= 0; Index
< Length
; Index
++) {
136 TemStr
[0] = PathHdr
[Index
];
137 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
138 if ((Index
& 1) == 0) {
139 DevicePathBuffer
[Index
/2] = DigitUint8
;
141 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
146 // Validate DevicePath
148 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) DevicePathBuffer
;
149 while (!IsDevicePathEnd (DevicePath
)) {
150 if ((DevicePath
->Type
== 0) || (DevicePath
->SubType
== 0) || (DevicePathNodeLength (DevicePath
) < sizeof (EFI_DEVICE_PATH_PROTOCOL
))) {
152 // Invalid device path
154 FreePool (DevicePathBuffer
);
155 return EFI_NOT_FOUND
;
157 DevicePath
= NextDevicePathNode (DevicePath
);
161 // return the device path
163 *DevicePathData
= DevicePathBuffer
;
168 Converts the unicode character of the string from uppercase to lowercase.
169 This is a internal function.
171 @param 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 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
272 // Check buffer is enough
274 TemName
= (CHAR16
*) Buffer
;
275 ASSERT ((BufferLen
* 2 + 1) >= (StrLen (TemName
) * 4 + 1));
277 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
279 for (; *TemName
!= L
'\0'; TemName
++) {
280 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemName
, 4);
285 // Convert Buffer to Hex String
287 TemBuffer
= ((UINT8
*) Buffer
) + BufferLen
- 1;
288 for (Index
= 0; Index
< BufferLen
; Index
++, TemBuffer
--) {
289 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
297 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
299 StrCatS (Str
, Length
, L
"&");
307 Retrieve the <ConfigBody> from String then output it.
309 This is a internal function.
311 @param String A sub string of a configuration string in
312 <MultiConfigAltResp> format.
313 @param ConfigBody Points to the output string. It's caller's
314 responsibility to free this buffer.
316 @retval EFI_INVALID_PARAMETER There is no form package in current hii database.
317 @retval EFI_OUT_OF_RESOURCES Not enough memory to finish this operation.
318 @retval EFI_SUCCESS All existing storage is exported.
323 IN EFI_STRING String
,
324 OUT EFI_STRING
*ConfigBody
331 if (String
== NULL
|| ConfigBody
== NULL
) {
332 return EFI_INVALID_PARAMETER
;
336 // The setting information should start OFFSET, not ALTCFG.
338 if (StrnCmp (String
, L
"&ALTCFG=", StrLen (L
"&ALTCFG=")) == 0) {
339 return EFI_INVALID_PARAMETER
;
342 TmpPtr
= StrStr (String
, L
"GUID=");
343 if (TmpPtr
== NULL
) {
345 // It is the last <ConfigResp> of the incoming configuration string.
347 Result
= AllocateCopyPool (StrSize (String
), String
);
348 if (Result
== NULL
) {
349 return EFI_OUT_OF_RESOURCES
;
351 *ConfigBody
= Result
;
356 Length
= TmpPtr
- String
;
358 return EFI_NOT_FOUND
;
360 Result
= AllocateCopyPool (Length
* sizeof (CHAR16
), String
);
361 if (Result
== NULL
) {
362 return EFI_OUT_OF_RESOURCES
;
365 *(Result
+ Length
- 1) = 0;
366 *ConfigBody
= Result
;
371 Append a string to a multi-string format.
373 This is a internal function.
375 @param MultiString String in <MultiConfigRequest>,
376 <MultiConfigAltResp>, or <MultiConfigResp>. On
377 input, the buffer length of this string is
378 MAX_STRING_LENGTH. On output, the buffer length
380 @param AppendString NULL-terminated Unicode string.
382 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
383 @retval EFI_SUCCESS AppendString is append to the end of MultiString
387 AppendToMultiString (
388 IN OUT EFI_STRING
*MultiString
,
389 IN EFI_STRING AppendString
392 UINTN AppendStringSize
;
393 UINTN MultiStringSize
;
396 if (MultiString
== NULL
|| *MultiString
== NULL
|| AppendString
== NULL
) {
397 return EFI_INVALID_PARAMETER
;
400 AppendStringSize
= StrSize (AppendString
);
401 MultiStringSize
= StrSize (*MultiString
);
402 MaxLen
= MAX_STRING_LENGTH
/ sizeof (CHAR16
);
405 // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.
407 if (MultiStringSize
+ AppendStringSize
> MAX_STRING_LENGTH
||
408 MultiStringSize
> MAX_STRING_LENGTH
) {
409 *MultiString
= (EFI_STRING
) ReallocatePool (
411 MultiStringSize
+ AppendStringSize
,
412 (VOID
*) (*MultiString
)
414 MaxLen
= (MultiStringSize
+ AppendStringSize
) / sizeof (CHAR16
);
415 ASSERT (*MultiString
!= NULL
);
418 // Append the incoming string
420 StrCatS (*MultiString
, MaxLen
, AppendString
);
427 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
429 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
431 This is a internal function.
433 @param StringPtr String in <BlockConfig> format and points to the
434 first character of <Number>.
435 @param Number The output value. Caller takes the responsibility
437 @param Len Length of the <Number>, in characters.
439 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
441 @retval EFI_SUCCESS Value of <Number> is outputted in Number
447 IN EFI_STRING StringPtr
,
461 if (StringPtr
== NULL
|| *StringPtr
== L
'\0' || Number
== NULL
|| Len
== NULL
) {
462 return EFI_INVALID_PARAMETER
;
468 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
471 *Len
= StringPtr
- TmpPtr
;
474 Str
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
476 Status
= EFI_OUT_OF_RESOURCES
;
479 CopyMem (Str
, TmpPtr
, *Len
* sizeof (CHAR16
));
480 *(Str
+ *Len
) = L
'\0';
482 Length
= (Length
+ 1) / 2;
483 Buf
= (UINT8
*) AllocateZeroPool (Length
);
485 Status
= EFI_OUT_OF_RESOURCES
;
490 ZeroMem (TemStr
, sizeof (TemStr
));
491 for (Index
= 0; Index
< Length
; Index
++) {
492 TemStr
[0] = Str
[Length
- Index
- 1];
493 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
494 if ((Index
& 1) == 0) {
495 Buf
[Index
/2] = DigitUint8
;
497 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
502 Status
= EFI_SUCCESS
;
513 To find the BlockName in the string with same value.
515 @param String Pointer to a Null-terminated Unicode string.
516 @param BlockName Pointer to a Null-terminated Unicode string to search for.
517 @param Buffer Pointer to the value correspond to the BlockName.
518 @param Found The Block whether has been found.
519 @param BufferLen The length of the buffer.
521 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures.
522 @retval EFI_SUCCESS The function finishes successfully.
526 FindSameBlockElement(
527 IN EFI_STRING String
,
528 IN EFI_STRING BlockName
,
541 BlockPtr
= StrStr (String
, BlockName
);
543 while (BlockPtr
!= NULL
) {
544 BlockPtr
+= StrLen (BlockName
);
545 Status
= GetValueOfNumber (BlockPtr
, &TempBuffer
, &Length
);
546 if (EFI_ERROR (Status
)) {
549 ASSERT (TempBuffer
!= NULL
);
550 if ((BufferLen
== Length
) && (0 == CompareMem (Buffer
, TempBuffer
, Length
))) {
552 FreePool (TempBuffer
);
556 FreePool (TempBuffer
);
558 BlockPtr
= StrStr (BlockPtr
+ 1, BlockName
);
565 Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>
566 in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.
568 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
569 <MultiConfigAltResp> format. The default value
570 string may contain more than one ConfigAltResp
571 string for the different varstore buffer.
572 @param ConfigAltResp Pointer to a null-terminated Unicode string in
573 <ConfigAltResp> format.
574 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.
575 @param ConfigAltRespChanged Whether the ConfigAltResp has been changed.
577 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures.
578 @retval EFI_SUCCESS The function finishes successfully.
582 CompareBlockElementDefault (
583 IN EFI_STRING DefaultAltCfgResp
,
584 IN OUT EFI_STRING
*ConfigAltResp
,
585 IN EFI_STRING AltConfigHdr
,
586 IN OUT BOOLEAN
*ConfigAltRespChanged
591 EFI_STRING BlockPtrStart
;
592 EFI_STRING StringPtr
;
593 EFI_STRING AppendString
;
594 EFI_STRING AltConfigHdrPtr
;
604 // Make BlockPtr point to the first <BlockConfig> with AltConfigHdr in DefaultAltCfgResp.
606 AltConfigHdrPtr
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
607 ASSERT (AltConfigHdrPtr
!= NULL
);
608 BlockPtr
= StrStr (AltConfigHdrPtr
, L
"&OFFSET=");
610 // Make StringPtr point to the AltConfigHdr in ConfigAltResp.
612 StringPtr
= StrStr (*ConfigAltResp
, AltConfigHdr
);
613 ASSERT (StringPtr
!= NULL
);
615 while (BlockPtr
!= NULL
) {
617 // Find the "&OFFSET=<Number>" block and get the value of the Number with AltConfigHdr in DefaultAltCfgResp.
619 BlockPtrStart
= BlockPtr
;
620 BlockPtr
+= StrLen (L
"&OFFSET=");
621 Status
= GetValueOfNumber (BlockPtr
, &TempBuffer
, &OffsetLength
);
622 if (EFI_ERROR (Status
)) {
623 Status
= EFI_OUT_OF_RESOURCES
;
627 // To find the same "&OFFSET=<Number>" block in ConfigAltResp.
629 Status
= FindSameBlockElement (StringPtr
, L
"&OFFSET=", TempBuffer
, &FoundOffset
, OffsetLength
);
630 if (TempBuffer
!= NULL
) {
631 FreePool (TempBuffer
);
634 if (EFI_ERROR (Status
)) {
635 Status
= EFI_OUT_OF_RESOURCES
;
640 // Don't find the same "&OFFSET=<Number>" block in ConfigAltResp.
641 // Calculate the size of <BlockConfig>.
642 // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number>.
644 BlockPtr
= StrStr (BlockPtr
+ 1, L
"&OFFSET=");
645 if (BlockPtr
!= NULL
) {
646 AppendSize
= (BlockPtr
- BlockPtrStart
) * sizeof (CHAR16
);
648 AppendSize
= StrSize (BlockPtrStart
);
651 // Copy the <BlockConfig> to AppendString.
653 if (AppendString
== NULL
) {
654 AppendString
= (EFI_STRING
) AllocateZeroPool (AppendSize
+ sizeof (CHAR16
));
655 StrnCatS (AppendString
, AppendSize
/ sizeof (CHAR16
) + 1, BlockPtrStart
, AppendSize
/ sizeof (CHAR16
));
657 TotalSize
= StrSize (AppendString
) + AppendSize
+ sizeof (CHAR16
);
658 AppendString
= (EFI_STRING
) ReallocatePool (
659 StrSize (AppendString
),
663 if (AppendString
== NULL
) {
664 Status
= EFI_OUT_OF_RESOURCES
;
667 StrnCatS (AppendString
, TotalSize
/ sizeof (CHAR16
), BlockPtrStart
, AppendSize
/ sizeof (CHAR16
));
671 // To find next "&OFFSET=<Number>" block with AltConfigHdr in DefaultAltCfgResp.
673 BlockPtr
= StrStr (BlockPtr
+ 1, L
"&OFFSET=");
677 if (AppendString
!= NULL
) {
679 // Reallocate ConfigAltResp to copy the AppendString.
681 TotalSize
= StrSize (*ConfigAltResp
) + StrSize (AppendString
) + sizeof (CHAR16
);
682 *ConfigAltResp
= (EFI_STRING
) ReallocatePool (
683 StrSize (*ConfigAltResp
),
687 if (*ConfigAltResp
== NULL
) {
688 Status
= EFI_OUT_OF_RESOURCES
;
691 StrCatS (*ConfigAltResp
, TotalSize
/ sizeof (CHAR16
), AppendString
);
692 *ConfigAltRespChanged
= TRUE
;
695 Status
= EFI_SUCCESS
;
698 if (AppendString
!= NULL
) {
699 FreePool (AppendString
);
706 Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>
707 in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.
709 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
710 <MultiConfigAltResp> format. The default value
711 string may contain more than one ConfigAltResp
712 string for the different varstore buffer.
713 @param ConfigAltResp Pointer to a null-terminated Unicode string in
714 <ConfigAltResp> format.
715 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.
716 @param ConfigAltRespChanged Whether the ConfigAltResp has been changed.
718 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures.
719 @retval EFI_SUCCESS The function finishes successfully.
723 CompareNameElementDefault (
724 IN EFI_STRING DefaultAltCfgResp
,
725 IN OUT EFI_STRING
*ConfigAltResp
,
726 IN EFI_STRING AltConfigHdr
,
727 IN OUT BOOLEAN
*ConfigAltRespChanged
731 EFI_STRING NvConfigPtr
;
732 EFI_STRING NvConfigStart
;
733 EFI_STRING NvConfigValuePtr
;
734 EFI_STRING StringPtr
;
735 EFI_STRING NvConfigExist
;
736 EFI_STRING AppendString
;
742 NvConfigExist
= NULL
;
744 // Make NvConfigPtr point to the first <NvConfig> with AltConfigHdr in DefaultAltCfgResp.
746 NvConfigPtr
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
747 ASSERT (NvConfigPtr
!= NULL
);
748 NvConfigPtr
= StrStr (NvConfigPtr
+ StrLen(AltConfigHdr
),L
"&");
750 // Make StringPtr point to the first <NvConfig> with AltConfigHdr in ConfigAltResp.
752 StringPtr
= StrStr (*ConfigAltResp
, AltConfigHdr
);
753 ASSERT (StringPtr
!= NULL
);
754 StringPtr
= StrStr (StringPtr
+ StrLen (AltConfigHdr
), L
"&");
755 ASSERT (StringPtr
!= NULL
);
757 while (NvConfigPtr
!= NULL
) {
759 // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number>.
760 // Get the <Label> with AltConfigHdr in DefaultAltCfgResp.
762 NvConfigStart
= NvConfigPtr
;
763 NvConfigValuePtr
= StrStr (NvConfigPtr
+ 1, L
"=");
764 ASSERT (NvConfigValuePtr
!= NULL
);
765 TempChar
= *NvConfigValuePtr
;
766 *NvConfigValuePtr
= L
'\0';
768 // Get the <Label> with AltConfigHdr in ConfigAltResp.
770 NvConfigExist
= StrStr (StringPtr
, NvConfigPtr
);
771 if (NvConfigExist
== NULL
) {
773 // Don't find same <Label> in ConfigAltResp.
774 // Calculate the size of <NvConfig>.
776 *NvConfigValuePtr
= TempChar
;
777 NvConfigPtr
= StrStr (NvConfigPtr
+ 1, L
"&");
778 if (NvConfigPtr
!= NULL
) {
779 AppendSize
= (NvConfigPtr
- NvConfigStart
) * sizeof (CHAR16
);
781 AppendSize
= StrSize (NvConfigStart
);
784 // Copy the <NvConfig> to AppendString.
786 if (AppendString
== NULL
) {
787 AppendString
= (EFI_STRING
) AllocateZeroPool (AppendSize
+ sizeof (CHAR16
));
788 StrnCatS (AppendString
, AppendSize
/ sizeof (CHAR16
) + 1, NvConfigStart
, AppendSize
/ sizeof (CHAR16
));
790 TotalSize
= StrSize (AppendString
) + AppendSize
+ sizeof (CHAR16
);
791 AppendString
= (EFI_STRING
) ReallocatePool (
792 StrSize (AppendString
),
796 if (AppendString
== NULL
) {
797 Status
= EFI_OUT_OF_RESOURCES
;
800 StrnCatS (AppendString
, TotalSize
/ sizeof (CHAR16
), NvConfigStart
, AppendSize
/ sizeof (CHAR16
));
804 // To find next <Label> in DefaultAltCfgResp.
806 *NvConfigValuePtr
= TempChar
;
807 NvConfigPtr
= StrStr (NvConfigPtr
+ 1, L
"&");
810 if (AppendString
!= NULL
) {
812 // Reallocate ConfigAltResp to copy the AppendString.
814 TotalSize
= StrSize (*ConfigAltResp
) + StrSize (AppendString
) + sizeof (CHAR16
);
815 *ConfigAltResp
= (EFI_STRING
) ReallocatePool (
816 StrSize (*ConfigAltResp
),
817 StrSize (*ConfigAltResp
) + StrSize (AppendString
) + sizeof (CHAR16
),
820 if (*ConfigAltResp
== NULL
) {
821 Status
= EFI_OUT_OF_RESOURCES
;
824 StrCatS (*ConfigAltResp
, TotalSize
/ sizeof (CHAR16
), AppendString
);
825 *ConfigAltRespChanged
= TRUE
;
827 Status
= EFI_SUCCESS
;
830 if (AppendString
!= NULL
) {
831 FreePool (AppendString
);
837 Compare the <AltResp> in AltCfgResp and DefaultAltCfgResp, if the <AltResp>
838 in DefaultAltCfgResp but not in AltCfgResp,add it to the AltCfgResp.
840 @param AltCfgResp Pointer to a null-terminated Unicode string in
841 <ConfigAltResp> format.
842 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
843 <MultiConfigAltResp> format. The default value
844 string may contain more than one ConfigAltResp
845 string for the different varstore buffer.
846 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.
848 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
850 @retval EFI_SUCCESS The function finishes successfully.
854 CompareAndMergeDefaultString (
855 IN OUT EFI_STRING
*AltCfgResp
,
856 IN EFI_STRING DefaultAltCfgResp
,
857 IN EFI_STRING AltConfigHdr
861 EFI_STRING AltCfgRespBackup
;
862 EFI_STRING AltConfigHdrPtr
;
863 EFI_STRING AltConfigHdrPtrNext
;
864 EFI_STRING ConfigAltResp
;
865 EFI_STRING StringPtr
;
866 EFI_STRING StringPtrNext
;
868 UINTN ReallocateSize
;
871 BOOLEAN ConfigAltRespChanged
;
873 Status
= EFI_OUT_OF_RESOURCES
;
875 AltConfigHdrPtrNext
= NULL
;
876 StringPtrNext
= NULL
;
877 ConfigAltResp
= NULL
;
878 AltCfgRespBackup
= NULL
;
881 ConfigAltRespChanged
= FALSE
;
884 //To find the <AltResp> with AltConfigHdr in DefaultAltCfgResp, ignore other <AltResp> which follow it.
886 AltConfigHdrPtr
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
887 ASSERT (AltConfigHdrPtr
!= NULL
);
888 AltConfigHdrPtrNext
= StrStr (AltConfigHdrPtr
+ 1, L
"&GUID");
889 if (AltConfigHdrPtrNext
!= NULL
) {
890 TempChar
= *AltConfigHdrPtrNext
;
891 *AltConfigHdrPtrNext
= L
'\0';
894 // To find the <AltResp> with AltConfigHdr in AltCfgResp, ignore other <AltResp> which follow it.
896 StringPtr
= StrStr (*AltCfgResp
, AltConfigHdr
);
897 StringPtrNext
= StrStr (StringPtr
+ 1, L
"&GUID");
898 if (StringPtrNext
!= NULL
) {
899 TempCharA
= *StringPtrNext
;
900 *StringPtrNext
= L
'\0';
903 // Copy the content of <ConfigAltResp> which contain current AltConfigHdr in AltCfgResp.
905 ConfigAltResp
= AllocateCopyPool (StrSize (*AltCfgResp
), *AltCfgResp
);
906 if (ConfigAltResp
== NULL
) {
910 // To find the <ConfigBody> with AltConfigHdr in DefaultAltCfgResp.
912 BlockPtr
= StrStr (AltConfigHdrPtr
, L
"&OFFSET=");
913 if (BlockPtr
!= NULL
) {
915 // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number> style.
916 // Call function CompareBlockElementDefault to compare the <BlockConfig> in DefaultAltCfgResp and ConfigAltResp.
917 // The ConfigAltResp which may contain the new <BlockConfig> get from DefaultAltCfgResp.
919 Status
= CompareBlockElementDefault (DefaultAltCfgResp
, &ConfigAltResp
, AltConfigHdr
, &ConfigAltRespChanged
);
920 if (EFI_ERROR(Status
)) {
925 // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number> style.
926 // Call function CompareNameElementDefault to compare the <NvConfig> in DefaultAltCfgResp and ConfigAltResp.
927 // The ConfigAltResp which may contain the new <NvConfig> get from DefaultAltCfgResp.
929 Status
= CompareNameElementDefault (DefaultAltCfgResp
, &ConfigAltResp
, AltConfigHdr
, &ConfigAltRespChanged
);
930 if (EFI_ERROR(Status
)) {
935 // Restore the AltCfgResp.
937 if (StringPtrNext
!= NULL
) {
938 *StringPtrNext
= TempCharA
;
942 // If the ConfigAltResp has no change,no need to update the content in AltCfgResp.
944 if (!ConfigAltRespChanged
) {
945 Status
= EFI_SUCCESS
;
949 // ConfigAltResp has been changed, need to update the content in AltCfgResp.
951 if (StringPtrNext
!= NULL
) {
952 ReallocateSize
= StrSize (ConfigAltResp
) + StrSize (StringPtrNext
) + sizeof (CHAR16
);
954 ReallocateSize
= StrSize (ConfigAltResp
) + sizeof (CHAR16
);
957 AltCfgRespBackup
= (EFI_STRING
) AllocateZeroPool (ReallocateSize
);
958 if (AltCfgRespBackup
== NULL
) {
962 StrCatS (AltCfgRespBackup
, ReallocateSize
/ sizeof (CHAR16
), ConfigAltResp
);
963 if (StringPtrNext
!= NULL
) {
964 StrCatS (AltCfgRespBackup
, ReallocateSize
/ sizeof (CHAR16
), StringPtrNext
);
967 FreePool (*AltCfgResp
);
968 *AltCfgResp
= AltCfgRespBackup
;
970 Status
= EFI_SUCCESS
;
973 if (ConfigAltResp
!= NULL
) {
974 FreePool(ConfigAltResp
);
977 // Restore the DefaultAltCfgResp.
979 if ( AltConfigHdrPtrNext
!= NULL
) {
980 *AltConfigHdrPtrNext
= TempChar
;
981 AltConfigHdrPtrNext
= NULL
;
988 This function merges DefaultAltCfgResp string into AltCfgResp string for
989 the missing AltCfgId in AltCfgResq.
991 @param AltCfgResp Pointer to a null-terminated Unicode string in
992 <ConfigAltResp> format. The default value string
993 will be merged into it.
994 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in
995 <MultiConfigAltResp> format. The default value
996 string may contain more than one ConfigAltResp
997 string for the different varstore buffer.
999 @retval EFI_SUCCESS The merged string returns.
1000 @retval EFI_INVALID_PARAMETER *AltCfgResp is to NULL.
1004 MergeDefaultString (
1005 IN OUT EFI_STRING
*AltCfgResp
,
1006 IN EFI_STRING DefaultAltCfgResp
1009 EFI_STRING StringPtrDefault
;
1010 EFI_STRING StringPtrEnd
;
1012 EFI_STRING StringPtr
;
1013 EFI_STRING AltConfigHdr
;
1015 UINTN SizeAltCfgResp
;
1019 if (*AltCfgResp
== NULL
) {
1020 return EFI_INVALID_PARAMETER
;
1024 // Get the requestr ConfigHdr
1027 StringPtr
= *AltCfgResp
;
1030 // Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1032 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1033 return EFI_INVALID_PARAMETER
;
1035 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1038 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1041 if (*StringPtr
== L
'\0') {
1042 return EFI_INVALID_PARAMETER
;
1044 StringPtr
+= StrLen (L
"&PATH=");
1045 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1048 HeaderLength
= StringPtr
- *AltCfgResp
;
1051 // Construct AltConfigHdr string "&<ConfigHdr>&ALTCFG=XXXX\0"
1052 // |1| StrLen (ConfigHdr) | 8 | 4 | 1 |
1054 MaxLen
= 1 + HeaderLength
+ 8 + 4 + 1;
1055 AltConfigHdr
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
1056 if (AltConfigHdr
== NULL
) {
1057 return EFI_OUT_OF_RESOURCES
;
1059 StrCpyS (AltConfigHdr
, MaxLen
, L
"&");
1060 StrnCatS (AltConfigHdr
, MaxLen
, *AltCfgResp
, HeaderLength
);
1061 StrCatS (AltConfigHdr
, MaxLen
, L
"&ALTCFG=");
1062 HeaderLength
= StrLen (AltConfigHdr
);
1064 StringPtrDefault
= StrStr (DefaultAltCfgResp
, AltConfigHdr
);
1065 while (StringPtrDefault
!= NULL
) {
1069 StrnCatS (AltConfigHdr
, MaxLen
, StringPtrDefault
+ HeaderLength
, 4);
1070 StringPtr
= StrStr (*AltCfgResp
, AltConfigHdr
);
1073 // Append the found default value string to the input AltCfgResp
1075 if (StringPtr
== NULL
) {
1076 StringPtrEnd
= StrStr (StringPtrDefault
+ 1, L
"&GUID");
1077 SizeAltCfgResp
= StrSize (*AltCfgResp
);
1078 if (StringPtrEnd
== NULL
) {
1080 // No more default string is found.
1082 TotalSize
= SizeAltCfgResp
+ StrSize (StringPtrDefault
);
1083 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
1086 (VOID
*) (*AltCfgResp
)
1088 if (*AltCfgResp
== NULL
) {
1089 FreePool (AltConfigHdr
);
1090 return EFI_OUT_OF_RESOURCES
;
1092 StrCatS (*AltCfgResp
, TotalSize
/ sizeof (CHAR16
), StringPtrDefault
);
1095 TempChar
= *StringPtrEnd
;
1096 *StringPtrEnd
= L
'\0';
1097 TotalSize
= SizeAltCfgResp
+ StrSize (StringPtrDefault
);
1098 *AltCfgResp
= (EFI_STRING
) ReallocatePool (
1101 (VOID
*) (*AltCfgResp
)
1103 if (*AltCfgResp
== NULL
) {
1104 FreePool (AltConfigHdr
);
1105 return EFI_OUT_OF_RESOURCES
;
1107 StrCatS (*AltCfgResp
, TotalSize
/ sizeof (CHAR16
), StringPtrDefault
);
1108 *StringPtrEnd
= TempChar
;
1112 // The AltCfgResp contains <AltCfgResp>.
1113 // If the <ConfigElement> in <AltCfgResp> in the DefaultAltCfgResp but not in the
1114 // related <AltCfgResp> in AltCfgResp, merge it to AltCfgResp. else no need to merge.
1116 CompareAndMergeDefaultString (AltCfgResp
, DefaultAltCfgResp
, AltConfigHdr
);
1120 // Find next AltCfg String
1122 *(AltConfigHdr
+ HeaderLength
) = L
'\0';
1123 StringPtrDefault
= StrStr (StringPtrDefault
+ 1, AltConfigHdr
);
1126 FreePool (AltConfigHdr
);
1131 This function inserts new DefaultValueData into the BlockData DefaultValue array.
1133 @param BlockData The BlockData is updated to add new default value.
1134 @param DefaultValueData The DefaultValue is added.
1138 InsertDefaultValue (
1139 IN IFR_BLOCK_DATA
*BlockData
,
1140 IN IFR_DEFAULT_DATA
*DefaultValueData
1144 IFR_DEFAULT_DATA
*DefaultValueArray
;
1145 LIST_ENTRY
*DefaultLink
;
1147 DefaultLink
= &BlockData
->DefaultValueEntry
;
1149 for (Link
= DefaultLink
->ForwardLink
; Link
!= DefaultLink
; Link
= Link
->ForwardLink
) {
1150 DefaultValueArray
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
1151 if (DefaultValueArray
->DefaultId
== DefaultValueData
->DefaultId
) {
1153 // DEFAULT_VALUE_FROM_OPCODE has high priority, DEFAULT_VALUE_FROM_DEFAULT has low priority.
1155 if (DefaultValueData
->Type
> DefaultValueArray
->Type
) {
1157 // Update the default value array in BlockData.
1159 CopyMem (&DefaultValueArray
->Value
, &DefaultValueData
->Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1160 DefaultValueArray
->Type
= DefaultValueData
->Type
;
1161 DefaultValueArray
->Cleaned
= DefaultValueData
->Cleaned
;
1168 // Insert new default value data in tail.
1170 DefaultValueArray
= AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
1171 ASSERT (DefaultValueArray
!= NULL
);
1172 CopyMem (DefaultValueArray
, DefaultValueData
, sizeof (IFR_DEFAULT_DATA
));
1173 InsertTailList (Link
, &DefaultValueArray
->Entry
);
1177 This function inserts new BlockData into the block link
1179 @param BlockLink The list entry points to block array.
1180 @param BlockData The point to BlockData is added.
1185 IN LIST_ENTRY
*BlockLink
,
1186 IN IFR_BLOCK_DATA
**BlockData
1190 IFR_BLOCK_DATA
*BlockArray
;
1191 IFR_BLOCK_DATA
*BlockSingleData
;
1193 BlockSingleData
= *BlockData
;
1195 if (BlockSingleData
->Name
!= NULL
) {
1196 InsertTailList (BlockLink
, &BlockSingleData
->Entry
);
1201 // Insert block data in its Offset and Width order.
1203 for (Link
= BlockLink
->ForwardLink
; Link
!= BlockLink
; Link
= Link
->ForwardLink
) {
1204 BlockArray
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1205 if (BlockArray
->Offset
== BlockSingleData
->Offset
) {
1206 if (BlockArray
->Width
> BlockSingleData
->Width
) {
1208 // Insert this block data in the front of block array
1210 InsertTailList (Link
, &BlockSingleData
->Entry
);
1214 if (BlockArray
->Width
== BlockSingleData
->Width
) {
1216 // The same block array has been added.
1218 if (BlockSingleData
!= BlockArray
) {
1219 FreePool (BlockSingleData
);
1220 *BlockData
= BlockArray
;
1224 } else if (BlockArray
->Offset
> BlockSingleData
->Offset
) {
1226 // Insert new block data in the front of block array
1228 InsertTailList (Link
, &BlockSingleData
->Entry
);
1234 // Add new block data into the tail.
1236 InsertTailList (Link
, &BlockSingleData
->Entry
);
1240 Retrieves a pointer to the a Null-terminated ASCII string containing the list
1241 of languages that an HII handle in the HII Database supports. The returned
1242 string is allocated using AllocatePool(). The caller is responsible for freeing
1243 the returned string using FreePool(). The format of the returned string follows
1244 the language format assumed the HII Database.
1246 If HiiHandle is NULL, then ASSERT().
1248 @param[in] HiiHandle A handle that was previously registered in the HII Database.
1250 @retval NULL HiiHandle is not registered in the HII database
1251 @retval NULL There are not enough resources available to retrieve the suported
1253 @retval NULL The list of suported languages could not be retrieved.
1254 @retval Other A pointer to the Null-terminated ASCII string of supported languages.
1258 GetSupportedLanguages (
1259 IN EFI_HII_HANDLE HiiHandle
1264 CHAR8 TempSupportedLanguages
;
1265 CHAR8
*SupportedLanguages
;
1267 ASSERT (HiiHandle
!= NULL
);
1270 // Retrieve the size required for the supported languages buffer.
1273 Status
= mPrivate
.HiiString
.GetLanguages (&mPrivate
.HiiString
, HiiHandle
, &TempSupportedLanguages
, &LanguageSize
);
1276 // If GetLanguages() returns EFI_SUCCESS for a zero size,
1277 // then there are no supported languages registered for HiiHandle. If GetLanguages()
1278 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
1279 // in the HII Database
1281 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1283 // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database
1289 // Allocate the supported languages buffer.
1291 SupportedLanguages
= AllocateZeroPool (LanguageSize
);
1292 if (SupportedLanguages
== NULL
) {
1294 // Return NULL if allocation fails.
1300 // Retrieve the supported languages string
1302 Status
= mPrivate
.HiiString
.GetLanguages (&mPrivate
.HiiString
, HiiHandle
, SupportedLanguages
, &LanguageSize
);
1303 if (EFI_ERROR (Status
)) {
1305 // Free the buffer and return NULL if the supported languages can not be retrieved.
1307 FreePool (SupportedLanguages
);
1312 // Return the Null-terminated ASCII string of supported languages
1314 return SupportedLanguages
;
1318 Retrieves a string from a string package.
1320 If HiiHandle is NULL, then ASSERT().
1321 If StringId is 0, then ASSET.
1323 @param[in] HiiHandle A handle that was previously registered in the HII Database.
1324 @param[in] StringId The identifier of the string to retrieved from the string
1325 package associated with HiiHandle.
1327 @retval NULL The string specified by StringId is not present in the string package.
1328 @retval Other The string was returned.
1333 IN EFI_HII_HANDLE HiiHandle
,
1334 IN EFI_STRING_ID StringId
1341 CHAR8
*SupportedLanguages
;
1342 CHAR8
*PlatformLanguage
;
1343 CHAR8
*BestLanguage
;
1346 ASSERT (HiiHandle
!= NULL
);
1347 ASSERT (StringId
!= 0);
1350 // Initialize all allocated buffers to NULL
1352 SupportedLanguages
= NULL
;
1353 PlatformLanguage
= NULL
;
1354 BestLanguage
= NULL
;
1359 // Get the languages that the package specified by HiiHandle supports
1361 SupportedLanguages
= GetSupportedLanguages (HiiHandle
);
1362 if (SupportedLanguages
== NULL
) {
1367 // Get the current platform language setting
1369 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
1372 // Get the best matching language from SupportedLanguages
1374 BestLanguage
= GetBestLanguage (
1376 FALSE
, // RFC 4646 mode
1377 Language
, // Highest priority
1378 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Next highest priority
1379 SupportedLanguages
, // Lowest priority
1382 if (BestLanguage
== NULL
) {
1387 // Retrieve the size of the string in the string package for the BestLanguage
1390 Status
= mPrivate
.HiiString
.GetString (
1391 &mPrivate
.HiiString
,
1400 // If GetString() returns EFI_SUCCESS for a zero size,
1401 // then there are no supported languages registered for HiiHandle. If GetString()
1402 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
1403 // in the HII Database
1405 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1410 // Allocate a buffer for the return string
1412 String
= AllocateZeroPool (StringSize
);
1413 if (String
== NULL
) {
1418 // Retrieve the string from the string package
1420 Status
= mPrivate
.HiiString
.GetString (
1421 &mPrivate
.HiiString
,
1429 if (EFI_ERROR (Status
)) {
1431 // Free the buffer and return NULL if the supported languages can not be retrieved.
1439 // Free allocated buffers
1441 if (SupportedLanguages
!= NULL
) {
1442 FreePool (SupportedLanguages
);
1444 if (PlatformLanguage
!= NULL
) {
1445 FreePool (PlatformLanguage
);
1447 if (BestLanguage
!= NULL
) {
1448 FreePool (BestLanguage
);
1452 // Return the Null-terminated Unicode string
1458 This function checks VarOffset and VarWidth is in the block range.
1460 @param RequestBlockArray The block array is to be checked.
1461 @param VarOffset Offset of var to the structure
1462 @param VarWidth Width of var.
1463 @param IsNameValueType Whether this varstore is name/value varstore or not.
1464 @param HiiHandle Hii handle for this hii package.
1466 @retval TRUE This Var is in the block range.
1467 @retval FALSE This Var is not in the block range.
1471 IN IFR_BLOCK_DATA
*RequestBlockArray
,
1472 IN UINT16 VarOffset
,
1474 IN BOOLEAN IsNameValueType
,
1475 IN EFI_HII_HANDLE HiiHandle
1479 IFR_BLOCK_DATA
*BlockData
;
1483 // No Request Block array, all vars are got.
1485 if (RequestBlockArray
== NULL
) {
1490 // Check the input var is in the request block range.
1492 for (Link
= RequestBlockArray
->Entry
.ForwardLink
; Link
!= &RequestBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1493 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1495 if (IsNameValueType
) {
1496 Name
= InternalGetString (HiiHandle
, VarOffset
);
1497 ASSERT (Name
!= NULL
);
1499 if (StrnCmp (BlockData
->Name
, Name
, StrLen (Name
)) == 0) {
1505 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
1515 Get form package data from data base.
1517 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1518 @param HiiFormPackage The buffer saves the package data.
1519 @param PackageSize The buffer size of the package data.
1523 GetFormPackageData (
1524 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1525 IN OUT UINT8
**HiiFormPackage
,
1526 OUT UINTN
*PackageSize
1533 if (DataBaseRecord
== NULL
|| HiiFormPackage
== NULL
|| PackageSize
== NULL
) {
1534 return EFI_INVALID_PARAMETER
;
1540 // 0. Get Hii Form Package by HiiHandle
1542 Status
= ExportFormPackages (
1544 DataBaseRecord
->Handle
,
1545 DataBaseRecord
->PackageList
,
1551 if (EFI_ERROR (Status
)) {
1555 (*HiiFormPackage
) = AllocatePool (ResultSize
);
1556 if (*HiiFormPackage
== NULL
) {
1557 Status
= EFI_OUT_OF_RESOURCES
;
1562 // Get HiiFormPackage by HiiHandle
1566 Status
= ExportFormPackages (
1568 DataBaseRecord
->Handle
,
1569 DataBaseRecord
->PackageList
,
1575 if (EFI_ERROR (Status
)) {
1576 FreePool (*HiiFormPackage
);
1579 *PackageSize
= Size
;
1586 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.
1588 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1589 @param ConfigHdr Request string ConfigHdr. If it is NULL,
1590 the first found varstore will be as ConfigHdr.
1591 @param IsEfiVarstore Whether the request storage type is efi varstore type.
1592 @param EfiVarStore The efi varstore info which will return.
1596 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1597 IN EFI_STRING ConfigHdr
,
1598 OUT BOOLEAN
*IsEfiVarstore
,
1599 OUT EFI_IFR_VARSTORE_EFI
**EfiVarStore
1604 UINTN PackageOffset
;
1605 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1606 CHAR16
*VarStoreName
;
1612 UINT8
*HiiFormPackage
;
1614 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1615 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
1617 HiiFormPackage
= NULL
;
1619 Status
= EFI_SUCCESS
;
1623 *IsEfiVarstore
= FALSE
;
1625 Status
= GetFormPackageData(DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
1626 if (EFI_ERROR (Status
)) {
1630 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1631 PackageOffset
= IfrOffset
;
1632 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) HiiFormPackage
;
1634 while (IfrOffset
< PackageSize
) {
1636 // More than one form packages exist.
1638 if (PackageOffset
>= PackageHeader
->Length
) {
1640 // Process the new form package.
1642 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1643 IfrOffset
+= PackageOffset
;
1644 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1647 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1648 IfrOffset
+= IfrOpHdr
->Length
;
1649 PackageOffset
+= IfrOpHdr
->Length
;
1651 if (IfrOpHdr
->OpCode
== EFI_IFR_VARSTORE_EFI_OP
) {
1652 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1654 // If the length is small than the structure, this is from old efi
1655 // varstore definition. Old efi varstore get config directly from
1656 // GetVariable function.
1658 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1662 NameSize
= AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
);
1663 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1664 if (VarStoreName
== NULL
) {
1665 Status
= EFI_OUT_OF_RESOURCES
;
1668 AsciiStrToUnicodeStrS ((CHAR8
*) IfrEfiVarStore
->Name
, VarStoreName
, NameSize
);
1670 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &IfrEfiVarStore
->Guid
, 1, &GuidStr
);
1671 GenerateSubStr (L
"NAME=", StrLen (VarStoreName
) * sizeof (CHAR16
), (VOID
*) VarStoreName
, 2, &NameStr
);
1672 LengthString
= StrLen (GuidStr
);
1673 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
1674 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
1675 if (TempStr
== NULL
) {
1678 FreePool (VarStoreName
);
1679 Status
= EFI_OUT_OF_RESOURCES
;
1682 StrCpyS (TempStr
, LengthString
, GuidStr
);
1683 StrCatS (TempStr
, LengthString
, NameStr
);
1684 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
1685 *EfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) AllocateZeroPool (IfrOpHdr
->Length
);
1686 if (*EfiVarStore
== NULL
) {
1687 FreePool (VarStoreName
);
1691 Status
= EFI_OUT_OF_RESOURCES
;
1694 *IsEfiVarstore
= TRUE
;
1695 CopyMem (*EfiVarStore
, IfrEfiVarStore
, IfrOpHdr
->Length
);
1699 // Free alllocated temp string.
1701 FreePool (VarStoreName
);
1707 // Already found the varstore, break;
1709 if (*IsEfiVarstore
) {
1715 if (HiiFormPackage
!= NULL
) {
1716 FreePool (HiiFormPackage
);
1723 Check whether the ConfigRequest string has the request elements.
1724 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.
1725 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.
1727 @param ConfigRequest The input config request string.
1729 @retval TRUE The input include config request elements.
1730 @retval FALSE The input string not includes.
1734 GetElementsFromRequest (
1735 IN EFI_STRING ConfigRequest
1738 EFI_STRING TmpRequest
;
1740 TmpRequest
= StrStr (ConfigRequest
, L
"PATH=");
1741 ASSERT (TmpRequest
!= NULL
);
1743 if ((StrStr (TmpRequest
, L
"&OFFSET=") != NULL
) || (StrStr (TmpRequest
, L
"&") != NULL
)) {
1751 Check whether the this varstore is the request varstore.
1753 @param VarstoreGuid Varstore guid.
1754 @param Name Varstore name.
1755 @param ConfigHdr Current configRequest info.
1757 @retval TRUE This varstore is the requst one.
1758 @retval FALSE This varstore is not the requst one.
1763 IN EFI_GUID
*VarstoreGuid
,
1765 IN CHAR16
*ConfigHdr
1779 // If ConfigHdr has name field and varstore not has name, return FALSE.
1781 if (Name
== NULL
&& ConfigHdr
!= NULL
&& StrStr (ConfigHdr
, L
"NAME=&") == NULL
) {
1785 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*)VarstoreGuid
, 1, &GuidStr
);
1787 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
1789 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
1791 LengthString
= StrLen (GuidStr
);
1792 LengthString
= LengthString
+ StrLen (NameStr
) + 1;
1793 TempStr
= AllocateZeroPool (LengthString
* sizeof (CHAR16
));
1794 if (TempStr
== NULL
) {
1798 StrCpyS (TempStr
, LengthString
, GuidStr
);
1799 StrCatS (TempStr
, LengthString
, NameStr
);
1801 if (ConfigHdr
== NULL
|| StrnCmp (ConfigHdr
, TempStr
, StrLen (TempStr
)) == 0) {
1806 if (GuidStr
!= NULL
) {
1810 if (NameStr
!= NULL
) {
1814 if (TempStr
!= NULL
) {
1822 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.
1824 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
1825 @param ConfigHdr Request string ConfigHdr. If it is NULL,
1826 the first found varstore will be as ConfigHdr.
1827 @retval TRUE This hii package is the reqeust one.
1828 @retval FALSE This hii package is not the reqeust one.
1832 IN HII_DATABASE_RECORD
*DataBaseRecord
,
1833 IN EFI_STRING ConfigHdr
1838 UINTN PackageOffset
;
1839 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1840 CHAR16
*VarStoreName
;
1842 UINT8
*HiiFormPackage
;
1844 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1845 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
1846 EFI_IFR_VARSTORE
*IfrVarStore
;
1847 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueVarStore
;
1848 BOOLEAN FindVarstore
;
1850 HiiFormPackage
= NULL
;
1851 VarStoreName
= NULL
;
1852 Status
= EFI_SUCCESS
;
1853 FindVarstore
= FALSE
;
1855 Status
= GetFormPackageData(DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
1856 if (EFI_ERROR (Status
)) {
1860 IfrOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1861 PackageOffset
= IfrOffset
;
1862 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) HiiFormPackage
;
1864 while (IfrOffset
< PackageSize
) {
1866 // More than one form packages exist.
1868 if (PackageOffset
>= PackageHeader
->Length
) {
1870 // Process the new form package.
1872 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
1873 IfrOffset
+= PackageOffset
;
1874 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1877 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (HiiFormPackage
+ IfrOffset
);
1878 IfrOffset
+= IfrOpHdr
->Length
;
1879 PackageOffset
+= IfrOpHdr
->Length
;
1881 switch (IfrOpHdr
->OpCode
) {
1883 case EFI_IFR_VARSTORE_OP
:
1884 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1886 NameSize
= AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
);
1887 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1888 if (VarStoreName
== NULL
) {
1891 AsciiStrToUnicodeStrS ((CHAR8
*)IfrVarStore
->Name
, VarStoreName
, NameSize
);
1893 if (IsThisVarstore((VOID
*)&IfrVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1894 FindVarstore
= TRUE
;
1897 FreePool (VarStoreName
);
1898 VarStoreName
= NULL
;
1902 case EFI_IFR_VARSTORE_EFI_OP
:
1903 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1904 NameSize
= AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
);
1905 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
1906 if (VarStoreName
== NULL
) {
1909 AsciiStrToUnicodeStrS ((CHAR8
*)IfrEfiVarStore
->Name
, VarStoreName
, NameSize
);
1911 if (IsThisVarstore (&IfrEfiVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
1912 FindVarstore
= TRUE
;
1915 FreePool (VarStoreName
);
1916 VarStoreName
= NULL
;
1920 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1921 IfrNameValueVarStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
1923 if (IsThisVarstore (&IfrNameValueVarStore
->Guid
, NULL
, ConfigHdr
)) {
1924 FindVarstore
= TRUE
;
1929 case EFI_IFR_FORM_OP
:
1930 case EFI_IFR_FORM_MAP_OP
:
1932 // No matched varstore is found and directly return.
1941 if (HiiFormPackage
!= NULL
) {
1942 FreePool (HiiFormPackage
);
1945 if (VarStoreName
!= NULL
) {
1946 FreePool (VarStoreName
);
1949 return FindVarstore
;
1953 Check whether the this op code is required.
1955 @param RequestBlockArray The array includes all the request info or NULL.
1956 @param HiiHandle The hii handle for this form package.
1957 @param VarStorageData The varstore data strucure.
1958 @param IfrOpHdr Ifr opcode header for this opcode.
1959 @param VarWidth The buffer width for this opcode.
1960 @param ReturnData The data block added for this opcode.
1962 @retval EFI_SUCCESS This opcode is required.
1963 @retval EFI_NOT_FOUND This opcode is not required.
1964 @retval Others Contain some error.
1968 IsThisOpcodeRequired (
1969 IN IFR_BLOCK_DATA
*RequestBlockArray
,
1970 IN EFI_HII_HANDLE HiiHandle
,
1971 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
1972 IN EFI_IFR_OP_HEADER
*IfrOpHdr
,
1974 OUT IFR_BLOCK_DATA
**ReturnData
1977 IFR_BLOCK_DATA
*BlockData
;
1979 EFI_STRING_ID NameId
;
1980 EFI_IFR_QUESTION_HEADER
*IfrQuestionHdr
;
1984 IfrQuestionHdr
= (EFI_IFR_QUESTION_HEADER
*)((CHAR8
*) IfrOpHdr
+ sizeof (EFI_IFR_OP_HEADER
));
1986 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
1987 NameId
= IfrQuestionHdr
->VarStoreInfo
.VarName
;
1990 // Check whether this question is in requested block array.
1992 if (!BlockArrayCheck (RequestBlockArray
, NameId
, 0, TRUE
, HiiHandle
)) {
1994 // This question is not in the requested string. Skip it.
1996 return EFI_NOT_FOUND
;
1999 VarOffset
= IfrQuestionHdr
->VarStoreInfo
.VarOffset
;
2002 // Check whether this question is in requested block array.
2004 if (!BlockArrayCheck (RequestBlockArray
, VarOffset
, VarWidth
, FALSE
, HiiHandle
)) {
2006 // This question is not in the requested string. Skip it.
2008 return EFI_NOT_FOUND
;
2012 // Check this var question is in the var storage
2014 if (((VarOffset
+ VarWidth
) > VarStorageData
->Size
)) {
2015 return EFI_INVALID_PARAMETER
;
2019 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2020 if (BlockData
== NULL
) {
2021 return EFI_OUT_OF_RESOURCES
;
2024 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
2025 BlockData
->Name
= InternalGetString(HiiHandle
, NameId
);
2027 BlockData
->Offset
= VarOffset
;
2030 BlockData
->Width
= VarWidth
;
2031 BlockData
->QuestionId
= IfrQuestionHdr
->QuestionId
;
2032 BlockData
->OpCode
= IfrOpHdr
->OpCode
;
2033 BlockData
->Scope
= IfrOpHdr
->Scope
;
2034 InitializeListHead (&BlockData
->DefaultValueEntry
);
2036 // Add Block Data into VarStorageData BlockEntry
2038 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
2039 *ReturnData
= BlockData
;
2045 This function parses Form Package to get the block array and the default
2046 value array according to the request ConfigHdr.
2048 @param HiiHandle Hii Handle for this hii package.
2049 @param Package Pointer to the form package data.
2050 @param PackageLength Length of the pacakge.
2051 @param ConfigHdr Request string ConfigHdr. If it is NULL,
2052 the first found varstore will be as ConfigHdr.
2053 @param RequestBlockArray The block array is retrieved from the request string.
2054 @param VarStorageData VarStorage structure contains the got block and default value.
2055 @param DefaultIdArray Point to the got default id and default name array.
2057 @retval EFI_SUCCESS The block array and the default value array are got.
2058 @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges
2060 @retval EFI_OUT_OF_RESOURCES No enough memory.
2065 IN EFI_HII_HANDLE HiiHandle
,
2067 IN UINT32 PackageLength
,
2068 IN EFI_STRING ConfigHdr
,
2069 IN IFR_BLOCK_DATA
*RequestBlockArray
,
2070 IN OUT IFR_VARSTORAGE_DATA
*VarStorageData
,
2071 OUT IFR_DEFAULT_DATA
*DefaultIdArray
2076 UINTN PackageOffset
;
2077 EFI_IFR_VARSTORE
*IfrVarStore
;
2078 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
2079 EFI_IFR_OP_HEADER
*IfrOpHdr
;
2080 EFI_IFR_ONE_OF
*IfrOneOf
;
2081 EFI_IFR_REF4
*IfrRef
;
2082 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
2083 EFI_IFR_DEFAULT
*IfrDefault
;
2084 EFI_IFR_ORDERED_LIST
*IfrOrderedList
;
2085 EFI_IFR_CHECKBOX
*IfrCheckBox
;
2086 EFI_IFR_PASSWORD
*IfrPassword
;
2087 EFI_IFR_STRING
*IfrString
;
2088 EFI_IFR_DATE
*IfrDate
;
2089 EFI_IFR_TIME
*IfrTime
;
2090 IFR_DEFAULT_DATA DefaultData
;
2091 IFR_DEFAULT_DATA
*DefaultDataPtr
;
2092 IFR_BLOCK_DATA
*BlockData
;
2093 CHAR16
*VarStoreName
;
2096 UINT16 VarDefaultId
;
2097 BOOLEAN FirstOneOfOption
;
2098 BOOLEAN FirstOrderedList
;
2099 LIST_ENTRY
*LinkData
;
2100 LIST_ENTRY
*LinkDefault
;
2101 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueVarStore
;
2102 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
2103 EFI_VARSTORE_ID VarStoreId
;
2105 Status
= EFI_SUCCESS
;
2107 DefaultDataPtr
= NULL
;
2108 FirstOneOfOption
= FALSE
;
2110 FirstOrderedList
= FALSE
;
2111 VarStoreName
= NULL
;
2112 ZeroMem (&DefaultData
, sizeof (IFR_DEFAULT_DATA
));
2115 // Go through the form package to parse OpCode one by one.
2117 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
2118 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) Package
;
2119 IfrOffset
= PackageOffset
;
2120 while (IfrOffset
< PackageLength
) {
2123 // More than one form package found.
2125 if (PackageOffset
>= PackageHeader
->Length
) {
2127 // Already found varstore for this request, break;
2129 if (VarStoreId
!= 0) {
2134 // Get next package header info.
2136 IfrOffset
+= sizeof (EFI_HII_PACKAGE_HEADER
);
2137 PackageOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
2138 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (Package
+ IfrOffset
);
2141 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (Package
+ IfrOffset
);
2142 switch (IfrOpHdr
->OpCode
) {
2143 case EFI_IFR_VARSTORE_OP
:
2145 // VarStore is found. Don't need to search any more.
2147 if (VarStoreId
!= 0) {
2151 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
2153 NameSize
= AsciiStrSize ((CHAR8
*)IfrVarStore
->Name
);
2154 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
2155 if (VarStoreName
== NULL
) {
2156 Status
= EFI_OUT_OF_RESOURCES
;
2159 AsciiStrToUnicodeStrS ((CHAR8
*)IfrVarStore
->Name
, VarStoreName
, NameSize
);
2161 if (IsThisVarstore((VOID
*)&IfrVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
2163 // Find the matched VarStore
2165 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
);
2166 VarStorageData
->Size
= IfrVarStore
->Size
;
2167 VarStorageData
->Name
= VarStoreName
;
2168 VarStorageData
->Type
= EFI_HII_VARSTORE_BUFFER
;
2169 VarStoreId
= IfrVarStore
->VarStoreId
;
2171 FreePool (VarStoreName
);
2172 VarStoreName
= NULL
;
2176 case EFI_IFR_VARSTORE_EFI_OP
:
2178 // VarStore is found. Don't need to search any more.
2180 if (VarStoreId
!= 0) {
2184 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
2187 // If the length is small than the structure, this is from old efi
2188 // varstore definition. Old efi varstore get config directly from
2189 // GetVariable function.
2191 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
2195 NameSize
= AsciiStrSize ((CHAR8
*)IfrEfiVarStore
->Name
);
2196 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
2197 if (VarStoreName
== NULL
) {
2198 Status
= EFI_OUT_OF_RESOURCES
;
2201 AsciiStrToUnicodeStrS ((CHAR8
*)IfrEfiVarStore
->Name
, VarStoreName
, NameSize
);
2203 if (IsThisVarstore (&IfrEfiVarStore
->Guid
, VarStoreName
, ConfigHdr
)) {
2205 // Find the matched VarStore
2207 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrEfiVarStore
->Guid
);
2208 VarStorageData
->Size
= IfrEfiVarStore
->Size
;
2209 VarStorageData
->Name
= VarStoreName
;
2210 VarStorageData
->Type
= EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
;
2211 VarStoreId
= IfrEfiVarStore
->VarStoreId
;
2213 FreePool (VarStoreName
);
2214 VarStoreName
= NULL
;
2218 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
2220 // VarStore is found. Don't need to search any more.
2222 if (VarStoreId
!= 0) {
2226 IfrNameValueVarStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
2228 if (IsThisVarstore (&IfrNameValueVarStore
->Guid
, NULL
, ConfigHdr
)) {
2230 // Find the matched VarStore
2232 CopyGuid (&VarStorageData
->Guid
, (EFI_GUID
*) (VOID
*) &IfrNameValueVarStore
->Guid
);
2233 VarStorageData
->Type
= EFI_HII_VARSTORE_NAME_VALUE
;
2234 VarStoreId
= IfrNameValueVarStore
->VarStoreId
;
2238 case EFI_IFR_DEFAULTSTORE_OP
:
2240 // Add new the map between default id and default name.
2242 DefaultDataPtr
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
2243 if (DefaultDataPtr
== NULL
) {
2244 Status
= EFI_OUT_OF_RESOURCES
;
2247 DefaultDataPtr
->DefaultId
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
;
2248 InsertTailList (&DefaultIdArray
->Entry
, &DefaultDataPtr
->Entry
);
2249 DefaultDataPtr
= NULL
;
2252 case EFI_IFR_FORM_OP
:
2253 case EFI_IFR_FORM_MAP_OP
:
2255 // No matched varstore is found and directly return.
2257 if ( VarStoreId
== 0) {
2258 Status
= EFI_SUCCESS
;
2263 case EFI_IFR_REF_OP
:
2265 // Ref question is not in IFR Form. This IFR form is not valid.
2267 if ( VarStoreId
== 0) {
2268 Status
= EFI_INVALID_PARAMETER
;
2272 // Check whether this question is for the requested varstore.
2274 IfrRef
= (EFI_IFR_REF4
*) IfrOpHdr
;
2275 if (IfrRef
->Question
.VarStoreId
!= VarStoreId
) {
2278 VarWidth
= (UINT16
) (sizeof (EFI_HII_REF
));
2281 // The BlockData may allocate by other opcode,need to clean.
2283 if (BlockData
!= NULL
){
2287 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2288 if (EFI_ERROR (Status
)) {
2289 if (Status
== EFI_NOT_FOUND
){
2291 //The opcode is not required,exit and parse other opcode.
2299 case EFI_IFR_ONE_OF_OP
:
2300 case EFI_IFR_NUMERIC_OP
:
2302 // Numeric and OneOf has the same opcode structure.
2306 // Numeric and OneOf question is not in IFR Form. This IFR form is not valid.
2308 if (VarStoreId
== 0) {
2309 Status
= EFI_INVALID_PARAMETER
;
2313 // Check whether this question is for the requested varstore.
2315 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
2316 if (IfrOneOf
->Question
.VarStoreId
!= VarStoreId
) {
2319 VarWidth
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
2322 // The BlockData may allocate by other opcode,need to clean.
2324 if (BlockData
!= NULL
){
2328 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2329 if (EFI_ERROR (Status
)) {
2330 if (Status
== EFI_NOT_FOUND
){
2332 //The opcode is not required,exit and parse other opcode.
2340 //when go to there,BlockData can't be NULLL.
2342 ASSERT (BlockData
!= NULL
);
2344 if (IfrOpHdr
->OpCode
== EFI_IFR_ONE_OF_OP
) {
2346 // Set this flag to TRUE for the first oneof option.
2348 FirstOneOfOption
= TRUE
;
2349 } else if (IfrOpHdr
->OpCode
== EFI_IFR_NUMERIC_OP
) {
2351 // Numeric minimum value will be used as default value when no default is specified.
2353 DefaultData
.Type
= DefaultValueFromDefault
;
2354 switch (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
2355 case EFI_IFR_NUMERIC_SIZE_1
:
2356 DefaultData
.Value
.u8
= IfrOneOf
->data
.u8
.MinValue
;
2359 case EFI_IFR_NUMERIC_SIZE_2
:
2360 CopyMem (&DefaultData
.Value
.u16
, &IfrOneOf
->data
.u16
.MinValue
, sizeof (UINT16
));
2363 case EFI_IFR_NUMERIC_SIZE_4
:
2364 CopyMem (&DefaultData
.Value
.u32
, &IfrOneOf
->data
.u32
.MinValue
, sizeof (UINT32
));
2367 case EFI_IFR_NUMERIC_SIZE_8
:
2368 CopyMem (&DefaultData
.Value
.u64
, &IfrOneOf
->data
.u64
.MinValue
, sizeof (UINT64
));
2372 Status
= EFI_INVALID_PARAMETER
;
2376 // Set default value base on the DefaultId list get from IFR data.
2378 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2379 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2380 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2381 InsertDefaultValue (BlockData
, &DefaultData
);
2386 case EFI_IFR_ORDERED_LIST_OP
:
2388 // offset by question header
2389 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type
2392 FirstOrderedList
= TRUE
;
2394 // OrderedList question is not in IFR Form. This IFR form is not valid.
2396 if (VarStoreId
== 0) {
2397 Status
= EFI_INVALID_PARAMETER
;
2401 // Check whether this question is for the requested varstore.
2403 IfrOrderedList
= (EFI_IFR_ORDERED_LIST
*) IfrOpHdr
;
2404 if (IfrOrderedList
->Question
.VarStoreId
!= VarStoreId
) {
2408 VarWidth
= IfrOrderedList
->MaxContainers
;
2411 // The BlockData may allocate by other opcode,need to clean.
2413 if (BlockData
!= NULL
){
2417 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2418 if (EFI_ERROR (Status
)) {
2419 if (Status
== EFI_NOT_FOUND
){
2421 //The opcode is not required,exit and parse other opcode.
2429 case EFI_IFR_CHECKBOX_OP
:
2431 // EFI_IFR_DEFAULT_OP
2432 // offset by question header
2433 // width is 1 sizeof (BOOLEAN)
2434 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.
2435 // value by DefaultOption
2436 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
2440 // CheckBox question is not in IFR Form. This IFR form is not valid.
2442 if (VarStoreId
== 0) {
2443 Status
= EFI_INVALID_PARAMETER
;
2447 // Check whether this question is for the requested varstore.
2449 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
2450 if (IfrCheckBox
->Question
.VarStoreId
!= VarStoreId
) {
2453 VarWidth
= (UINT16
) sizeof (BOOLEAN
);
2456 // The BlockData may allocate by other opcode,need to clean.
2458 if (BlockData
!= NULL
){
2462 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2463 if (EFI_ERROR (Status
)) {
2464 if (Status
== EFI_NOT_FOUND
){
2466 //The opcode is not required,exit and parse other opcode.
2474 //when go to there,BlockData can't be NULLL.
2476 ASSERT (BlockData
!= NULL
);
2479 // Add default value for standard ID by CheckBox Flag
2481 VarDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2483 // Prepare new DefaultValue
2485 DefaultData
.DefaultId
= VarDefaultId
;
2486 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) == EFI_IFR_CHECKBOX_DEFAULT
) {
2488 // When flag is set, defautl value is TRUE.
2490 DefaultData
.Type
= DefaultValueFromFlag
;
2491 DefaultData
.Value
.b
= TRUE
;
2494 // When flag is not set, defautl value is FASLE.
2496 DefaultData
.Type
= DefaultValueFromDefault
;
2497 DefaultData
.Value
.b
= FALSE
;
2500 // Add DefaultValue into current BlockData
2502 InsertDefaultValue (BlockData
, &DefaultData
);
2505 // Add default value for Manufacture ID by CheckBox Flag
2507 VarDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2509 // Prepare new DefaultValue
2511 DefaultData
.DefaultId
= VarDefaultId
;
2512 if ((IfrCheckBox
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) == EFI_IFR_CHECKBOX_DEFAULT_MFG
) {
2514 // When flag is set, defautl value is TRUE.
2516 DefaultData
.Type
= DefaultValueFromFlag
;
2517 DefaultData
.Value
.b
= TRUE
;
2520 // When flag is not set, defautl value is FASLE.
2522 DefaultData
.Type
= DefaultValueFromDefault
;
2523 DefaultData
.Value
.b
= FALSE
;
2526 // Add DefaultValue into current BlockData
2528 InsertDefaultValue (BlockData
, &DefaultData
);
2531 case EFI_IFR_DATE_OP
:
2533 // offset by question header
2534 // width MaxSize * sizeof (CHAR16)
2535 // no default value, only block array
2539 // Date question is not in IFR Form. This IFR form is not valid.
2541 if (VarStoreId
== 0) {
2542 Status
= EFI_INVALID_PARAMETER
;
2546 // Check whether this question is for the requested varstore.
2548 IfrDate
= (EFI_IFR_DATE
*) IfrOpHdr
;
2549 if (IfrDate
->Question
.VarStoreId
!= VarStoreId
) {
2554 // The BlockData may allocate by other opcode,need to clean.
2556 if (BlockData
!= NULL
){
2560 VarWidth
= (UINT16
) sizeof (EFI_HII_DATE
);
2561 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2562 if (EFI_ERROR (Status
)) {
2563 if (Status
== EFI_NOT_FOUND
){
2565 //The opcode is not required,exit and parse other opcode.
2573 case EFI_IFR_TIME_OP
:
2575 // offset by question header
2576 // width MaxSize * sizeof (CHAR16)
2577 // no default value, only block array
2581 // Time question is not in IFR Form. This IFR form is not valid.
2583 if (VarStoreId
== 0) {
2584 Status
= EFI_INVALID_PARAMETER
;
2588 // Check whether this question is for the requested varstore.
2590 IfrTime
= (EFI_IFR_TIME
*) IfrOpHdr
;
2591 if (IfrTime
->Question
.VarStoreId
!= VarStoreId
) {
2596 // The BlockData may allocate by other opcode,need to clean.
2598 if (BlockData
!= NULL
){
2602 VarWidth
= (UINT16
) sizeof (EFI_HII_TIME
);
2603 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2604 if (EFI_ERROR (Status
)) {
2605 if (Status
== EFI_NOT_FOUND
){
2607 //The opcode is not required,exit and parse other opcode.
2615 case EFI_IFR_STRING_OP
:
2617 // offset by question header
2618 // width MaxSize * sizeof (CHAR16)
2619 // no default value, only block array
2623 // String question is not in IFR Form. This IFR form is not valid.
2625 if (VarStoreId
== 0) {
2626 Status
= EFI_INVALID_PARAMETER
;
2630 // Check whether this question is for the requested varstore.
2632 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
2633 if (IfrString
->Question
.VarStoreId
!= VarStoreId
) {
2638 // The BlockData may allocate by other opcode,need to clean.
2640 if (BlockData
!= NULL
){
2644 VarWidth
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
2645 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2646 if (EFI_ERROR (Status
)) {
2647 if (Status
== EFI_NOT_FOUND
){
2649 //The opcode is not required,exit and parse other opcode.
2657 case EFI_IFR_PASSWORD_OP
:
2659 // offset by question header
2660 // width MaxSize * sizeof (CHAR16)
2661 // no default value, only block array
2665 // Password question is not in IFR Form. This IFR form is not valid.
2667 if (VarStoreId
== 0) {
2668 Status
= EFI_INVALID_PARAMETER
;
2672 // Check whether this question is for the requested varstore.
2674 IfrPassword
= (EFI_IFR_PASSWORD
*) IfrOpHdr
;
2675 if (IfrPassword
->Question
.VarStoreId
!= VarStoreId
) {
2680 // The BlockData may allocate by other opcode,need to clean.
2682 if (BlockData
!= NULL
){
2686 VarWidth
= (UINT16
) (IfrPassword
->MaxSize
* sizeof (UINT16
));
2687 Status
= IsThisOpcodeRequired(RequestBlockArray
, HiiHandle
, VarStorageData
, IfrOpHdr
, VarWidth
, &BlockData
);
2688 if (EFI_ERROR (Status
)) {
2689 if (Status
== EFI_NOT_FOUND
){
2691 //The opcode is not required,exit and parse other opcode.
2699 // No default value for string.
2704 case EFI_IFR_ONE_OF_OPTION_OP
:
2706 // No matched block data is ignored.
2708 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
2712 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
2713 if (BlockData
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
2715 if (!FirstOrderedList
){
2719 // Get ordered list option data type.
2721 if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_8
|| IfrOneOfOption
->Type
== EFI_IFR_TYPE_BOOLEAN
) {
2723 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_16
) {
2725 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_32
) {
2727 } else if (IfrOneOfOption
->Type
== EFI_IFR_TYPE_NUM_SIZE_64
) {
2731 // Invalid ordered list option data type.
2733 Status
= EFI_INVALID_PARAMETER
;
2734 if (BlockData
->Name
!= NULL
) {
2735 FreePool (BlockData
->Name
);
2737 FreePool (BlockData
);
2742 // Calculate Ordered list QuestionId width.
2744 BlockData
->Width
= (UINT16
) (BlockData
->Width
* VarWidth
);
2746 // Check whether this question is in requested block array.
2748 if (!BlockArrayCheck (RequestBlockArray
, BlockData
->Offset
, BlockData
->Width
, (BOOLEAN
)(BlockData
->Name
!= NULL
), HiiHandle
)) {
2750 // This question is not in the requested string. Skip it.
2752 if (BlockData
->Name
!= NULL
) {
2753 FreePool (BlockData
->Name
);
2755 FreePool (BlockData
);
2760 // Check this var question is in the var storage
2762 if ((BlockData
->Name
== NULL
) && ((BlockData
->Offset
+ BlockData
->Width
) > VarStorageData
->Size
)) {
2763 Status
= EFI_INVALID_PARAMETER
;
2764 if (BlockData
->Name
!= NULL
) {
2765 FreePool (BlockData
->Name
);
2767 FreePool (BlockData
);
2771 // Add Block Data into VarStorageData BlockEntry
2773 InsertBlockData (&VarStorageData
->BlockEntry
, &BlockData
);
2775 FirstOrderedList
= FALSE
;
2781 // 1. Set default value for OneOf option when flag field has default attribute.
2783 if (((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) ||
2784 ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
)) {
2786 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
2787 // The first oneof option value will be used as default value when no default value is specified.
2789 FirstOneOfOption
= FALSE
;
2791 // Prepare new DefaultValue
2793 DefaultData
.Type
= DefaultValueFromFlag
;
2794 CopyMem (&DefaultData
.Value
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2795 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT
) == EFI_IFR_OPTION_DEFAULT
) {
2796 DefaultData
.DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2797 InsertDefaultValue (BlockData
, &DefaultData
);
2799 if ((IfrOneOfOption
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) == EFI_IFR_OPTION_DEFAULT_MFG
) {
2800 DefaultData
.DefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2801 InsertDefaultValue (BlockData
, &DefaultData
);
2806 // 2. Set as the default value when this is the first option.
2807 // The first oneof option value will be used as default value when no default value is specified.
2809 if (FirstOneOfOption
) {
2810 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
2811 FirstOneOfOption
= FALSE
;
2814 // Prepare new DefaultValue
2816 DefaultData
.Type
= DefaultValueFromDefault
;
2817 CopyMem (&DefaultData
.Value
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2818 for (LinkData
= DefaultIdArray
->Entry
.ForwardLink
; LinkData
!= &DefaultIdArray
->Entry
; LinkData
= LinkData
->ForwardLink
) {
2819 DefaultDataPtr
= BASE_CR (LinkData
, IFR_DEFAULT_DATA
, Entry
);
2820 DefaultData
.DefaultId
= DefaultDataPtr
->DefaultId
;
2821 InsertDefaultValue (BlockData
, &DefaultData
);
2826 case EFI_IFR_DEFAULT_OP
:
2828 // Update Current BlockData to the default value.
2830 if (BlockData
== NULL
|| BlockData
->Scope
== 0) {
2832 // No matched block data is ignored.
2838 // Get the DefaultId
2840 IfrDefault
= (EFI_IFR_DEFAULT
*) IfrOpHdr
;
2841 VarDefaultId
= IfrDefault
->DefaultId
;
2843 // Prepare new DefaultValue
2845 DefaultData
.Type
= DefaultValueFromOpcode
;
2846 DefaultData
.DefaultId
= VarDefaultId
;
2847 CopyMem (&DefaultData
.Value
, &IfrDefault
->Value
, IfrDefault
->Header
.Length
- OFFSET_OF (EFI_IFR_DEFAULT
, Value
));
2849 // If the value field is expression, set the cleaned flag.
2850 if (IfrDefault
->Type
== EFI_IFR_TYPE_OTHER
) {
2851 DefaultData
.Cleaned
= TRUE
;
2854 // Add DefaultValue into current BlockData
2856 InsertDefaultValue (BlockData
, &DefaultData
);
2859 // After insert the default value, reset the cleaned value for next
2860 // time used. If not set here, need to set the value before everytime
2863 DefaultData
.Cleaned
= FALSE
;
2866 case EFI_IFR_END_OP
:
2868 // End Opcode is for Var question.
2870 if (BlockData
!= NULL
) {
2871 if (BlockData
->Scope
> 0) {
2874 if (BlockData
->Scope
== 0) {
2882 if (BlockData
!= NULL
) {
2883 if (BlockData
->Scope
> 0) {
2884 BlockData
->Scope
= (UINT8
) (BlockData
->Scope
+ IfrOpHdr
->Scope
);
2887 if (BlockData
->Scope
== 0) {
2894 IfrOffset
+= IfrOpHdr
->Length
;
2895 PackageOffset
+= IfrOpHdr
->Length
;
2899 //if Status == EFI_NOT_FOUND, just means the opcode is not required,not contain any error,
2900 //so set the Status to EFI_SUCCESS.
2902 if (Status
== EFI_NOT_FOUND
){
2903 Status
= EFI_SUCCESS
;
2907 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
2908 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
2909 for (LinkDefault
= BlockData
->DefaultValueEntry
.ForwardLink
; LinkDefault
!= &BlockData
->DefaultValueEntry
; ) {
2910 DefaultDataPtr
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
2911 LinkDefault
= LinkDefault
->ForwardLink
;
2912 if (DefaultDataPtr
->Cleaned
== TRUE
) {
2913 RemoveEntryList (&DefaultDataPtr
->Entry
);
2914 FreePool (DefaultDataPtr
);
2923 parse the configrequest string, get the elements.
2925 @param ConfigRequest The input configrequest string.
2926 @param Progress Return the progress data.
2928 @retval Block data pointer.
2932 IN EFI_STRING ConfigRequest
,
2933 OUT EFI_STRING
*Progress
2936 EFI_STRING StringPtr
;
2937 IFR_BLOCK_DATA
*BlockData
;
2938 IFR_BLOCK_DATA
*RequestBlockArray
;
2944 IFR_BLOCK_DATA
*NextBlockData
;
2950 // Init RequestBlockArray
2952 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2953 if (RequestBlockArray
== NULL
) {
2956 InitializeListHead (&RequestBlockArray
->Entry
);
2959 // Get the request Block array from the request string
2964 // Parse each <RequestElement> if exists
2965 // Only <BlockName> format is supported by this help function.
2966 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
2968 StringPtr
= ConfigRequest
;
2969 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
2971 // Skip the OFFSET string
2973 *Progress
= StringPtr
;
2974 StringPtr
+= StrLen (L
"&OFFSET=");
2978 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
2979 if (EFI_ERROR (Status
)) {
2986 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
2988 FreePool (TmpBuffer
);
2990 StringPtr
+= Length
;
2991 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
2994 StringPtr
+= StrLen (L
"&WIDTH=");
2999 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3000 if (EFI_ERROR (Status
)) {
3007 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
3009 FreePool (TmpBuffer
);
3011 StringPtr
+= Length
;
3012 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3019 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
3020 if (BlockData
== NULL
) {
3023 BlockData
->Offset
= Offset
;
3024 BlockData
->Width
= Width
;
3025 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
3028 // Skip &VALUE string if &VALUE does exists.
3030 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) == 0) {
3031 StringPtr
+= StrLen (L
"&VALUE=");
3036 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
3037 if (EFI_ERROR (Status
)) {
3040 FreePool (TmpBuffer
);
3041 StringPtr
+= Length
;
3042 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
3047 // If '\0', parsing is finished.
3049 if (*StringPtr
== 0) {
3055 // Merge the requested block data.
3057 Link
= RequestBlockArray
->Entry
.ForwardLink
;
3058 while ((Link
!= &RequestBlockArray
->Entry
) && (Link
->ForwardLink
!= &RequestBlockArray
->Entry
)) {
3059 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3060 NextBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3061 if ((NextBlockData
->Offset
>= BlockData
->Offset
) && (NextBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
3062 if ((NextBlockData
->Offset
+ NextBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
3063 BlockData
->Width
= (UINT16
) (NextBlockData
->Offset
+ NextBlockData
->Width
- BlockData
->Offset
);
3065 RemoveEntryList (Link
->ForwardLink
);
3066 FreePool (NextBlockData
);
3069 Link
= Link
->ForwardLink
;
3072 return RequestBlockArray
;
3075 if (RequestBlockArray
!= NULL
) {
3077 // Free Link Array RequestBlockArray
3079 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
3080 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3081 RemoveEntryList (&BlockData
->Entry
);
3082 FreePool (BlockData
);
3085 FreePool (RequestBlockArray
);
3092 parse the configrequest string, get the elements.
3094 @param ConfigRequest The input config request string.
3095 @param Progress Return the progress data.
3097 @retval return data block array.
3101 IN EFI_STRING ConfigRequest
,
3102 OUT EFI_STRING
*Progress
3105 EFI_STRING StringPtr
;
3107 IFR_BLOCK_DATA
*BlockData
;
3108 IFR_BLOCK_DATA
*RequestBlockArray
;
3111 StringPtr
= ConfigRequest
;
3114 // Init RequestBlockArray
3116 RequestBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
3117 if (RequestBlockArray
== NULL
) {
3120 InitializeListHead (&RequestBlockArray
->Entry
);
3123 // Get the request Block array from the request string
3127 // Parse each <RequestElement> if exists
3128 // Only <BlockName> format is supported by this help function.
3129 // <BlockName> ::= &'Name***=***
3131 while (StringPtr
!= NULL
&& *StringPtr
== L
'&') {
3133 *Progress
= StringPtr
;
3135 // Skip the L"&" string
3140 if ((NextTag
= StrStr (StringPtr
, L
"=")) != NULL
) {
3143 } else if ((NextTag
= StrStr (StringPtr
, L
"&")) != NULL
) {
3150 BlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
3151 if (BlockData
== NULL
) {
3158 BlockData
->Name
= AllocateCopyPool(StrSize (StringPtr
), StringPtr
);
3159 InsertBlockData (&RequestBlockArray
->Entry
, &BlockData
);
3163 // If has value, skip the value.
3165 StringPtr
= NextTag
+ 1;
3167 StringPtr
= StrStr (StringPtr
, L
"&");
3168 } else if (NextTag
!= NULL
) {
3170 // restore the '&' text.
3172 StringPtr
= NextTag
;
3177 return RequestBlockArray
;
3180 if (RequestBlockArray
!= NULL
) {
3182 // Free Link Array RequestBlockArray
3184 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
3185 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3186 RemoveEntryList (&BlockData
->Entry
);
3187 if (BlockData
->Name
!= NULL
) {
3188 FreePool (BlockData
->Name
);
3190 FreePool (BlockData
);
3193 FreePool (RequestBlockArray
);
3200 Generate ConfigRequest string base on the varstore info.
3202 @param ConfigHdr The config header for this varstore.
3203 @param VarStorageData The varstore info.
3204 @param Status Return Status.
3205 @param ConfigRequest The ConfigRequest info may be return.
3207 @retval TRUE Need to continue
3208 @retval Others NO need to continue or error occur.
3211 GenerateConfigRequest (
3212 IN CHAR16
*ConfigHdr
,
3213 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
3214 OUT EFI_STATUS
*Status
,
3215 IN OUT EFI_STRING
*ConfigRequest
3221 CHAR16
*FullConfigRequest
;
3223 IFR_BLOCK_DATA
*BlockData
;
3226 // Append VarStorageData BlockEntry into *Request string
3227 // Now support only one varstore in a form package.
3231 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package
3232 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig
3236 // Compute the length of the entire request starting with <ConfigHdr> and a
3240 Length
= StrLen (ConfigHdr
) + 1;
3242 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
3244 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3245 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3247 // Add <BlockName> length for each Name
3249 // <BlockName> ::= &Name1&Name2&...
3250 // |1| StrLen(Name1)
3252 Length
= Length
+ (1 + StrLen (BlockData
->Name
));
3255 // Add <BlockName> length for each Offset/Width pair
3257 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
3258 // | 8 | 4 | 7 | 4 |
3260 Length
= Length
+ (8 + 4 + 7 + 4);
3264 // No any request block data is found. The request string can't be constructed.
3267 *Status
= EFI_SUCCESS
;
3272 // Allocate buffer for the entire <ConfigRequest>
3274 FullConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3275 if (FullConfigRequest
== NULL
) {
3276 *Status
= EFI_OUT_OF_RESOURCES
;
3279 StringPtr
= FullConfigRequest
;
3282 // Start with <ConfigHdr>
3284 StrCpyS (StringPtr
, Length
, ConfigHdr
);
3285 StringPtr
+= StrLen (StringPtr
);
3288 // Loop through all the Offset/Width pairs and append them to ConfigRequest
3290 for (Link
= VarStorageData
->BlockEntry
.ForwardLink
; Link
!= &VarStorageData
->BlockEntry
; Link
= Link
->ForwardLink
) {
3291 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
3292 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3298 (1 + StrLen (BlockData
->Name
) + 1) * sizeof (CHAR16
),
3304 // Append &OFFSET=XXXX&WIDTH=YYYY\0
3308 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
3309 L
"&OFFSET=%04X&WIDTH=%04X",
3314 StringPtr
+= StrLen (StringPtr
);
3317 // Set to the got full request string.
3319 HiiToLower (FullConfigRequest
);
3321 if (*ConfigRequest
!= NULL
) {
3322 FreePool (*ConfigRequest
);
3324 *ConfigRequest
= FullConfigRequest
;
3330 Generate ConfigRequest Header base on the varstore info.
3332 @param VarStorageData The varstore info.
3333 @param DevicePath Device path for this varstore.
3334 @param ConfigHdr The config header for this varstore.
3336 @retval EFI_SUCCESS Generate the header success.
3337 @retval EFI_OUT_OF_RESOURCES Allocate buffer fail.
3341 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
3342 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3343 OUT EFI_STRING
*ConfigHdr
3352 Status
= EFI_SUCCESS
;
3358 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle
3360 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) &VarStorageData
->Guid
, 1, &GuidStr
);
3361 if (VarStorageData
->Name
!= NULL
) {
3362 GenerateSubStr (L
"NAME=", StrLen (VarStorageData
->Name
) * sizeof (CHAR16
), (VOID
*) VarStorageData
->Name
, 2, &NameStr
);
3364 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
3368 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
3369 (VOID
*) DevicePath
,
3373 Length
= StrLen (GuidStr
) + StrLen (NameStr
) + StrLen (PathStr
) + 1;
3374 if (VarStorageData
->Name
== NULL
) {
3378 *ConfigHdr
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3379 if (*ConfigHdr
== NULL
) {
3380 Status
= EFI_OUT_OF_RESOURCES
;
3383 StrCpyS (*ConfigHdr
, Length
, GuidStr
);
3384 StrCatS (*ConfigHdr
, Length
, NameStr
);
3385 if (VarStorageData
->Name
== NULL
) {
3386 StrCatS (*ConfigHdr
, Length
, L
"&");
3388 StrCatS (*ConfigHdr
, Length
, PathStr
);
3391 // Remove the last character L'&'
3393 *(*ConfigHdr
+ StrLen (*ConfigHdr
) - 1) = L
'\0';
3396 if (GuidStr
!= NULL
) {
3400 if (NameStr
!= NULL
) {
3404 if (PathStr
!= NULL
) {
3412 Get Data buffer size based on data type.
3414 @param ValueType The input data type.
3416 @retval The data buffer size for the input type.
3423 UINT16 StorageWidth
;
3425 switch (ValueType
) {
3426 case EFI_IFR_NUMERIC_SIZE_1
:
3427 case EFI_IFR_TYPE_BOOLEAN
:
3428 StorageWidth
= (UINT16
) sizeof (UINT8
);
3431 case EFI_IFR_NUMERIC_SIZE_2
:
3432 StorageWidth
= (UINT16
) sizeof (UINT16
);
3435 case EFI_IFR_NUMERIC_SIZE_4
:
3436 StorageWidth
= (UINT16
) sizeof (UINT32
);
3439 case EFI_IFR_NUMERIC_SIZE_8
:
3440 StorageWidth
= (UINT16
) sizeof (UINT64
);
3443 case EFI_IFR_TYPE_TIME
:
3444 StorageWidth
= (UINT16
) sizeof (EFI_IFR_TIME
);
3447 case EFI_IFR_TYPE_DATE
:
3448 StorageWidth
= (UINT16
) sizeof (EFI_IFR_DATE
);
3456 return StorageWidth
;
3460 Generate ConfigAltResp string base on the varstore info.
3462 @param HiiHandle Hii Handle for this hii package.
3463 @param ConfigHdr The config header for this varstore.
3464 @param VarStorageData The varstore info.
3465 @param DefaultIdArray The Default id array.
3466 @param DefaultAltCfgResp The DefaultAltCfgResp info may be return.
3468 @retval TRUE Need to continue
3469 @retval Others NO need to continue or error occur.
3472 GenerateAltConfigResp (
3473 IN EFI_HII_HANDLE HiiHandle
,
3474 IN CHAR16
*ConfigHdr
,
3475 IN IFR_VARSTORAGE_DATA
*VarStorageData
,
3476 IN IFR_DEFAULT_DATA
*DefaultIdArray
,
3477 IN OUT EFI_STRING
*DefaultAltCfgResp
3483 LIST_ENTRY
*LinkData
;
3484 LIST_ENTRY
*LinkDefault
;
3485 LIST_ENTRY
*ListEntry
;
3487 IFR_BLOCK_DATA
*BlockData
;
3488 IFR_DEFAULT_DATA
*DefaultId
;
3489 IFR_DEFAULT_DATA
*DefaultValueData
;
3492 CHAR16
*DefaultString
;
3496 DefaultString
= NULL
;
3498 // Add length for <ConfigHdr> + '\0'
3500 Length
= StrLen (ConfigHdr
) + 1;
3502 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
3503 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
3505 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
3506 // |1| StrLen (ConfigHdr) | 8 | 4 |
3508 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
3510 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
3511 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
3512 ListEntry
= &BlockData
->DefaultValueEntry
;
3513 for (LinkDefault
= ListEntry
->ForwardLink
; LinkDefault
!= ListEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
3514 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
3515 if (DefaultValueData
->DefaultId
!= DefaultId
->DefaultId
) {
3518 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3520 // Add length for "&Name1=zzzzzzzzzzzz"
3523 Length
+= (1 + StrLen (BlockData
->Name
) + 1 + BlockData
->Width
* 2);
3526 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
3527 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
3529 Length
+= (8 + 4 + 7 + 4 + 7 + BlockData
->Width
* 2);
3537 // No default value is found. The default string doesn't exist.
3544 // Allocate buffer for the entire <DefaultAltCfgResp>
3546 *DefaultAltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
3547 if (*DefaultAltCfgResp
== NULL
) {
3548 return EFI_OUT_OF_RESOURCES
;
3550 StringPtr
= *DefaultAltCfgResp
;
3553 // Start with <ConfigHdr>
3555 StrCpyS (StringPtr
, Length
, ConfigHdr
);
3556 StringPtr
+= StrLen (StringPtr
);
3558 for (Link
= DefaultIdArray
->Entry
.ForwardLink
; Link
!= &DefaultIdArray
->Entry
; Link
= Link
->ForwardLink
) {
3559 DefaultId
= BASE_CR (Link
, IFR_DEFAULT_DATA
, Entry
);
3561 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"
3562 // |1| StrLen (ConfigHdr) | 8 | 4 |
3566 (1 + StrLen (ConfigHdr
) + 8 + 4 + 1) * sizeof (CHAR16
),
3569 DefaultId
->DefaultId
3571 StringPtr
+= StrLen (StringPtr
);
3573 for (LinkData
= VarStorageData
->BlockEntry
.ForwardLink
; LinkData
!= &VarStorageData
->BlockEntry
; LinkData
= LinkData
->ForwardLink
) {
3574 BlockData
= BASE_CR (LinkData
, IFR_BLOCK_DATA
, Entry
);
3575 ListEntry
= &BlockData
->DefaultValueEntry
;
3576 for (LinkDefault
= ListEntry
->ForwardLink
; LinkDefault
!= ListEntry
; LinkDefault
= LinkDefault
->ForwardLink
) {
3577 DefaultValueData
= BASE_CR (LinkDefault
, IFR_DEFAULT_DATA
, Entry
);
3578 if (DefaultValueData
->DefaultId
!= DefaultId
->DefaultId
) {
3581 if (VarStorageData
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
3584 (1 + StrLen (ConfigHdr
) + 1) * sizeof (CHAR16
),
3588 StringPtr
+= StrLen (StringPtr
);
3591 // Add <BlockConfig>
3592 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
3596 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16
),
3597 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
3601 StringPtr
+= StrLen (StringPtr
);
3603 Width
= BlockData
->Width
;
3605 // Convert Value to a hex string in "%x" format
3606 // NOTE: This is in the opposite byte that GUID and PATH use
3608 if (BlockData
->OpCode
== EFI_IFR_STRING_OP
){
3609 DefaultString
= InternalGetString(HiiHandle
, DefaultValueData
->Value
.string
);
3610 TmpBuffer
= (UINT8
*) DefaultString
;
3612 TmpBuffer
= (UINT8
*) &(DefaultValueData
->Value
);
3614 for (; Width
> 0 && (TmpBuffer
!= NULL
); Width
--) {
3615 StringPtr
+= UnicodeValueToString (StringPtr
, PREFIX_ZERO
| RADIX_HEX
, TmpBuffer
[Width
- 1], 2);
3617 if (DefaultString
!= NULL
){
3618 FreePool(DefaultString
);
3619 DefaultString
= NULL
;
3625 HiiToLower (*DefaultAltCfgResp
);
3631 This function gets the full request string and full default value string by
3632 parsing IFR data in HII form packages.
3634 When Request points to NULL string, the request string and default value string
3635 for each varstore in form package will return.
3637 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
3638 @param DevicePath Device Path which Hii Config Access Protocol is registered.
3639 @param Request Pointer to a null-terminated Unicode string in
3640 <ConfigRequest> format. When it doesn't contain
3641 any RequestElement, it will be updated to return
3642 the full RequestElement retrieved from IFR data.
3643 If it points to NULL, the request string for the first
3644 varstore in form package will be merged into a
3645 <MultiConfigRequest> format string and return.
3646 @param AltCfgResp Pointer to a null-terminated Unicode string in
3647 <ConfigAltResp> format. When the pointer is to NULL,
3648 the full default value string retrieved from IFR data
3649 will return. When the pinter is to a string, the
3650 full default value string retrieved from IFR data
3651 will be merged into the input string and return.
3652 When Request points to NULL, the default value string
3653 for each varstore in form package will be merged into
3654 a <MultiConfigAltResp> format string and return.
3655 @param PointerProgress Optional parameter, it can be be NULL.
3656 When it is not NULL, if Request is NULL, it returns NULL.
3657 On return, points to a character in the Request
3658 string. Points to the string's null terminator if
3659 request was successful. Points to the most recent
3660 & before the first failing name / value pair (or
3661 the beginning of the string if the failure is in
3662 the first name / value pair) if the request was
3664 @retval EFI_SUCCESS The Results string is set to the full request string.
3665 And AltCfgResp contains all default value string.
3666 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
3667 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string
3668 can't be found in Form package.
3669 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.
3670 @retval EFI_INVALID_PARAMETER Request points to NULL.
3675 GetFullStringFromHiiFormPackages (
3676 IN HII_DATABASE_RECORD
*DataBaseRecord
,
3677 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
3678 IN OUT EFI_STRING
*Request
,
3679 IN OUT EFI_STRING
*AltCfgResp
,
3680 OUT EFI_STRING
*PointerProgress OPTIONAL
3684 UINT8
*HiiFormPackage
;
3686 IFR_BLOCK_DATA
*RequestBlockArray
;
3687 IFR_BLOCK_DATA
*BlockData
;
3688 IFR_DEFAULT_DATA
*DefaultValueData
;
3689 IFR_DEFAULT_DATA
*DefaultId
;
3690 IFR_DEFAULT_DATA
*DefaultIdArray
;
3691 IFR_VARSTORAGE_DATA
*VarStorageData
;
3692 EFI_STRING DefaultAltCfgResp
;
3693 EFI_STRING ConfigHdr
;
3694 EFI_STRING StringPtr
;
3695 EFI_STRING Progress
;
3697 if (DataBaseRecord
== NULL
|| DevicePath
== NULL
|| Request
== NULL
|| AltCfgResp
== NULL
) {
3698 return EFI_INVALID_PARAMETER
;
3702 // Initialize the local variables.
3704 RequestBlockArray
= NULL
;
3705 DefaultIdArray
= NULL
;
3706 VarStorageData
= NULL
;
3707 DefaultAltCfgResp
= NULL
;
3709 HiiFormPackage
= NULL
;
3711 Progress
= *Request
;
3713 Status
= GetFormPackageData (DataBaseRecord
, &HiiFormPackage
, &PackageSize
);
3714 if (EFI_ERROR (Status
)) {
3719 // 1. Get the request block array by Request String when Request string containts the block array.
3722 if (*Request
!= NULL
) {
3723 StringPtr
= *Request
;
3727 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
3728 Status
= EFI_INVALID_PARAMETER
;
3731 StringPtr
+= StrLen (L
"GUID=");
3732 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
3735 if (*StringPtr
== L
'\0') {
3736 Status
= EFI_INVALID_PARAMETER
;
3739 StringPtr
+= StrLen (L
"&NAME=");
3740 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
3743 if (*StringPtr
== L
'\0') {
3744 Status
= EFI_INVALID_PARAMETER
;
3747 StringPtr
+= StrLen (L
"&PATH=");
3748 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
3752 if (*StringPtr
== L
'\0') {
3754 // No request block is found.
3761 // If StringPtr != NULL, get the request elements.
3763 if (StringPtr
!= NULL
) {
3764 if (StrStr (StringPtr
, L
"&OFFSET=") != NULL
) {
3765 RequestBlockArray
= GetBlockElement(StringPtr
, &Progress
);
3767 RequestBlockArray
= GetNameElement(StringPtr
, &Progress
);
3770 if (RequestBlockArray
== NULL
) {
3771 Status
= EFI_INVALID_PARAMETER
;
3777 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
3779 DefaultIdArray
= (IFR_DEFAULT_DATA
*) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA
));
3780 if (DefaultIdArray
== NULL
) {
3781 Status
= EFI_OUT_OF_RESOURCES
;
3784 InitializeListHead (&DefaultIdArray
->Entry
);
3787 // Initialize VarStorageData to store the var store Block and Default value information.
3789 VarStorageData
= (IFR_VARSTORAGE_DATA
*) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA
));
3790 if (VarStorageData
== NULL
) {
3791 Status
= EFI_OUT_OF_RESOURCES
;
3794 InitializeListHead (&VarStorageData
->Entry
);
3795 InitializeListHead (&VarStorageData
->BlockEntry
);
3798 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
3802 // Parse the opcode in form pacakge to get the default setting.
3804 Status
= ParseIfrData (DataBaseRecord
->Handle
,
3806 (UINT32
) PackageSize
,
3811 if (EFI_ERROR (Status
)) {
3816 // No requested varstore in IFR data and directly return
3818 if (VarStorageData
->Type
== 0 && VarStorageData
->Name
== NULL
) {
3819 Status
= EFI_SUCCESS
;
3824 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.
3826 Status
= GenerateHdr (VarStorageData
, DevicePath
, &ConfigHdr
);
3827 if (EFI_ERROR (Status
)) {
3831 if (RequestBlockArray
== NULL
) {
3832 if (!GenerateConfigRequest(ConfigHdr
, VarStorageData
, &Status
, Request
)) {
3838 // 4. Construct Default Value string in AltResp according to request element.
3839 // Go through all VarStorageData Entry and get the DefaultId array for each one
3840 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody
3842 Status
= GenerateAltConfigResp (DataBaseRecord
->Handle
,ConfigHdr
, VarStorageData
, DefaultIdArray
, &DefaultAltCfgResp
);
3843 if (EFI_ERROR (Status
)) {
3848 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.
3850 if (*AltCfgResp
!= NULL
&& DefaultAltCfgResp
!= NULL
) {
3851 Status
= MergeDefaultString (AltCfgResp
, DefaultAltCfgResp
);
3852 FreePool (DefaultAltCfgResp
);
3853 } else if (*AltCfgResp
== NULL
) {
3854 *AltCfgResp
= DefaultAltCfgResp
;
3858 if (RequestBlockArray
!= NULL
) {
3860 // Free Link Array RequestBlockArray
3862 while (!IsListEmpty (&RequestBlockArray
->Entry
)) {
3863 BlockData
= BASE_CR (RequestBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3864 RemoveEntryList (&BlockData
->Entry
);
3865 if (BlockData
->Name
!= NULL
) {
3866 FreePool (BlockData
->Name
);
3868 FreePool (BlockData
);
3871 FreePool (RequestBlockArray
);
3874 if (VarStorageData
!= NULL
) {
3876 // Free link array VarStorageData
3878 while (!IsListEmpty (&VarStorageData
->BlockEntry
)) {
3879 BlockData
= BASE_CR (VarStorageData
->BlockEntry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
3880 RemoveEntryList (&BlockData
->Entry
);
3881 if (BlockData
->Name
!= NULL
) {
3882 FreePool (BlockData
->Name
);
3885 // Free default value link array
3887 while (!IsListEmpty (&BlockData
->DefaultValueEntry
)) {
3888 DefaultValueData
= BASE_CR (BlockData
->DefaultValueEntry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
3889 RemoveEntryList (&DefaultValueData
->Entry
);
3890 FreePool (DefaultValueData
);
3892 FreePool (BlockData
);
3894 if (VarStorageData
->Name
!= NULL
) {
3895 FreePool (VarStorageData
->Name
);
3896 VarStorageData
->Name
= NULL
;
3898 FreePool (VarStorageData
);
3901 if (DefaultIdArray
!= NULL
) {
3903 // Free DefaultId Array
3905 while (!IsListEmpty (&DefaultIdArray
->Entry
)) {
3906 DefaultId
= BASE_CR (DefaultIdArray
->Entry
.ForwardLink
, IFR_DEFAULT_DATA
, Entry
);
3907 RemoveEntryList (&DefaultId
->Entry
);
3908 FreePool (DefaultId
);
3910 FreePool (DefaultIdArray
);
3914 // Free the allocated string
3916 if (ConfigHdr
!= NULL
) {
3917 FreePool (ConfigHdr
);
3921 // Free Pacakge data
3923 if (HiiFormPackage
!= NULL
) {
3924 FreePool (HiiFormPackage
);
3927 if (PointerProgress
!= NULL
) {
3928 if (*Request
== NULL
) {
3929 *PointerProgress
= NULL
;
3930 } else if (EFI_ERROR (Status
)) {
3931 *PointerProgress
= *Request
;
3933 *PointerProgress
= *Request
+ StrLen (*Request
);
3941 This function gets the full request resp string by
3942 parsing IFR data in HII form packages.
3944 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
3946 @param EfiVarStoreInfo The efi varstore info which is save in the EFI
3947 varstore data structure.
3948 @param Request Pointer to a null-terminated Unicode string in
3949 <ConfigRequest> format.
3950 @param RequestResp Pointer to a null-terminated Unicode string in
3951 <ConfigResp> format.
3952 @param AccessProgress On return, points to a character in the Request
3953 string. Points to the string's null terminator if
3954 request was successful. Points to the most recent
3955 & before the first failing name / value pair (or
3956 the beginning of the string if the failure is in
3957 the first name / value pair) if the request was
3960 @retval EFI_SUCCESS The Results string is set to the full request string.
3961 And AltCfgResp contains all default value string.
3962 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
3963 @retval EFI_INVALID_PARAMETER Request points to NULL.
3967 GetConfigRespFromEfiVarStore (
3968 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
3969 IN EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
,
3970 IN EFI_STRING Request
,
3971 OUT EFI_STRING
*RequestResp
,
3972 OUT EFI_STRING
*AccessProgress
3976 EFI_STRING VarStoreName
;
3981 Status
= EFI_SUCCESS
;
3984 VarStoreName
= NULL
;
3985 *AccessProgress
= Request
;
3987 NameSize
= AsciiStrSize ((CHAR8
*)EfiVarStoreInfo
->Name
);
3988 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
3989 if (VarStoreName
== NULL
) {
3990 Status
= EFI_OUT_OF_RESOURCES
;
3993 AsciiStrToUnicodeStrS ((CHAR8
*) EfiVarStoreInfo
->Name
, VarStoreName
, NameSize
);
3996 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, NULL
);
3997 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
4001 VarStore
= AllocateZeroPool (BufferSize
);
4002 ASSERT (VarStore
!= NULL
);
4003 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, VarStore
);
4004 if (EFI_ERROR (Status
)) {
4008 Status
= HiiBlockToConfig(This
, Request
, VarStore
, BufferSize
, RequestResp
, AccessProgress
);
4009 if (EFI_ERROR (Status
)) {
4014 if (VarStoreName
!= NULL
) {
4015 FreePool (VarStoreName
);
4018 if (VarStore
!= NULL
) {
4019 FreePool (VarStore
);
4027 This function route the full request resp string for efi varstore.
4029 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4031 @param EfiVarStoreInfo The efi varstore info which is save in the EFI
4032 varstore data structure.
4033 @param RequestResp Pointer to a null-terminated Unicode string in
4034 <ConfigResp> format.
4035 @param Result Pointer to a null-terminated Unicode string in
4036 <ConfigResp> format.
4038 @retval EFI_SUCCESS The Results string is set to the full request string.
4039 And AltCfgResp contains all default value string.
4040 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.
4041 @retval EFI_INVALID_PARAMETER Request points to NULL.
4045 RouteConfigRespForEfiVarStore (
4046 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4047 IN EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
,
4048 IN EFI_STRING RequestResp
,
4049 OUT EFI_STRING
*Result
4053 EFI_STRING VarStoreName
;
4059 Status
= EFI_SUCCESS
;
4062 VarStoreName
= NULL
;
4063 *Result
= RequestResp
;
4065 NameSize
= AsciiStrSize ((CHAR8
*)EfiVarStoreInfo
->Name
);
4066 VarStoreName
= AllocateZeroPool (NameSize
* sizeof (CHAR16
));
4067 if (VarStoreName
== NULL
) {
4068 Status
= EFI_OUT_OF_RESOURCES
;
4071 AsciiStrToUnicodeStrS ((CHAR8
*) EfiVarStoreInfo
->Name
, VarStoreName
, NameSize
);
4073 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, NULL
);
4074 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
4075 DEBUG ((DEBUG_ERROR
, "The variable does not exist!"));
4079 BlockSize
= BufferSize
;
4080 VarStore
= AllocateZeroPool (BufferSize
);
4081 ASSERT (VarStore
!= NULL
);
4082 Status
= gRT
->GetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, NULL
, &BufferSize
, VarStore
);
4083 if (EFI_ERROR (Status
)) {
4087 Status
= HiiConfigToBlock(This
, RequestResp
, VarStore
, &BlockSize
, Result
);
4088 if (EFI_ERROR (Status
)) {
4092 Status
= gRT
->SetVariable (VarStoreName
, &EfiVarStoreInfo
->Guid
, EfiVarStoreInfo
->Attributes
, BufferSize
, VarStore
);
4093 if (EFI_ERROR (Status
)) {
4094 *Result
= RequestResp
;
4099 if (VarStoreName
!= NULL
) {
4100 FreePool (VarStoreName
);
4103 if (VarStore
!= NULL
) {
4104 FreePool (VarStore
);
4111 Validate the config request elements.
4113 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format,
4114 without configHdr field.
4116 @retval CHAR16 * THE first Name/value pair not correct.
4117 @retval NULL Success parse the name/value pair
4120 OffsetWidthValidate (
4121 CHAR16
*ConfigElements
4127 StringPtr
= ConfigElements
;
4131 if (StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) != 0) {
4135 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
4138 if (*StringPtr
== L
'\0') {
4142 StringPtr
+= StrLen (L
"&WIDTH=");
4143 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) != 0) {
4147 if (*StringPtr
== L
'\0') {
4154 Validate the config request elements.
4156 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format,
4157 without configHdr field.
4159 @retval CHAR16 * THE first Name/value pair not correct.
4160 @retval NULL Success parse the name/value pair
4165 CHAR16
*ConfigElements
4171 StringPtr
= ConfigElements
;
4175 if (*StringPtr
!= L
'&') {
4180 StringPtr
= StrStr (StringPtr
, L
"&");
4182 if (StringPtr
== NULL
) {
4189 Validate the config request string.
4191 @param ConfigRequest A null-terminated Unicode string in <ConfigRequest> format.
4193 @retval CHAR16 * THE first element not correct.
4194 @retval NULL Success parse the name/value pair
4198 ConfigRequestValidate (
4199 CHAR16
*ConfigRequest
4202 BOOLEAN HasNameField
;
4205 HasNameField
= TRUE
;
4206 StringPtr
= ConfigRequest
;
4209 // Check <ConfigHdr>
4211 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4212 return ConfigRequest
;
4214 StringPtr
+= StrLen (L
"GUID=");
4215 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
4218 if (*StringPtr
== L
'\0') {
4219 return ConfigRequest
;
4221 StringPtr
+= StrLen (L
"&NAME=");
4222 if (*StringPtr
== L
'&') {
4223 HasNameField
= FALSE
;
4225 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
4228 if (*StringPtr
== L
'\0') {
4229 return ConfigRequest
;
4231 StringPtr
+= StrLen (L
"&PATH=");
4232 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
4236 if (*StringPtr
== L
'\0') {
4242 // Should be Buffer varstore, config request should be "OFFSET/Width" pairs.
4244 return OffsetWidthValidate(StringPtr
);
4247 // Should be Name/Value varstore, config request should be "&name1&name2..." pairs.
4249 return NameValueValidate(StringPtr
);
4254 This function allows a caller to extract the current configuration
4255 for one or more named elements from one or more drivers.
4257 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4259 @param Request A null-terminated Unicode string in
4260 <MultiConfigRequest> format.
4261 @param Progress On return, points to a character in the Request
4262 string. Points to the string's null terminator if
4263 request was successful. Points to the most recent
4264 & before the first failing name / value pair (or
4265 the beginning of the string if the failure is in
4266 the first name / value pair) if the request was
4268 @param Results Null-terminated Unicode string in
4269 <MultiConfigAltResp> format which has all values
4270 filled in for the names in the Request string.
4271 String to be allocated by the called function.
4273 @retval EFI_SUCCESS The Results string is filled with the values
4274 corresponding to all requested names.
4275 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
4276 results that must be stored awaiting possible
4278 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.
4279 Progress set to the "G" in "GUID" of the routing
4280 header that doesn't match. Note: There is no
4281 requirement that all routing data be validated
4282 before any configuration extraction.
4283 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request
4284 parameter would result in this type of error. The
4285 Progress parameter is set to NULL.
4286 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &
4287 before the error or the beginning of the string.
4288 @retval EFI_INVALID_PARAMETER The ExtractConfig function of the underlying HII
4289 Configuration Access Protocol returned
4290 EFI_INVALID_PARAMETER. Progress set to most recent
4291 & before the error or the beginning of the string.
4296 HiiConfigRoutingExtractConfig (
4297 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4298 IN CONST EFI_STRING Request
,
4299 OUT EFI_STRING
*Progress
,
4300 OUT EFI_STRING
*Results
4303 HII_DATABASE_PRIVATE_DATA
*Private
;
4304 EFI_STRING StringPtr
;
4305 EFI_STRING ConfigRequest
;
4307 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
4308 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
4311 HII_DATABASE_RECORD
*Database
;
4312 UINT8
*DevicePathPkg
;
4313 UINT8
*CurrentDevicePath
;
4314 EFI_HANDLE DriverHandle
;
4315 EFI_HII_HANDLE HiiHandle
;
4316 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
4317 EFI_STRING AccessProgress
;
4318 EFI_STRING AccessResults
;
4319 EFI_STRING AccessProgressBackup
;
4320 EFI_STRING AccessResultsBackup
;
4321 EFI_STRING DefaultResults
;
4322 BOOLEAN FirstElement
;
4323 BOOLEAN IfrDataParsedFlag
;
4324 BOOLEAN IsEfiVarStore
;
4325 EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
;
4326 EFI_STRING ErrorPtr
;
4327 UINTN DevicePathSize
;
4328 UINTN ConigStringSize
;
4329 UINTN ConigStringSizeNewsize
;
4330 EFI_STRING ConfigStringPtr
;
4332 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
4333 return EFI_INVALID_PARAMETER
;
4336 if (Request
== NULL
) {
4338 return EFI_INVALID_PARAMETER
;
4341 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4342 StringPtr
= Request
;
4343 *Progress
= StringPtr
;
4344 DefaultResults
= NULL
;
4345 ConfigRequest
= NULL
;
4346 Status
= EFI_SUCCESS
;
4347 AccessResults
= NULL
;
4348 AccessProgress
= NULL
;
4349 AccessResultsBackup
= NULL
;
4350 AccessProgressBackup
= NULL
;
4352 IfrDataParsedFlag
= FALSE
;
4353 IsEfiVarStore
= FALSE
;
4354 EfiVarStoreInfo
= NULL
;
4357 // The first element of <MultiConfigRequest> should be
4358 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
4360 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4361 return EFI_INVALID_PARAMETER
;
4364 FirstElement
= TRUE
;
4367 // Allocate a fix length of memory to store Results. Reallocate memory for
4368 // Results if this fix length is insufficient.
4370 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
4371 if (*Results
== NULL
) {
4372 return EFI_OUT_OF_RESOURCES
;
4375 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
4377 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>
4378 // or most recent & before the error.
4380 if (StringPtr
== Request
) {
4381 *Progress
= StringPtr
;
4383 *Progress
= StringPtr
- 1;
4387 // Process each <ConfigRequest> of <MultiConfigRequest>
4389 Length
= CalculateConfigStringLen (StringPtr
);
4390 ConfigRequest
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
4391 if (ConfigRequest
== NULL
) {
4392 Status
= EFI_OUT_OF_RESOURCES
;
4395 *(ConfigRequest
+ Length
) = 0;
4398 // Get the UEFI device path
4400 Status
= GetDevicePath (ConfigRequest
, (UINT8
**) &DevicePath
);
4401 if (EFI_ERROR (Status
)) {
4406 // Find driver which matches the routing data.
4408 DriverHandle
= NULL
;
4411 for (Link
= Private
->DatabaseList
.ForwardLink
;
4412 Link
!= &Private
->DatabaseList
;
4413 Link
= Link
->ForwardLink
4415 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
4416 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
4417 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
4418 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
4419 if ((CompareMem (DevicePath
,CurrentDevicePath
,DevicePathSize
) == 0) && IsThisPackageList(Database
, ConfigRequest
)) {
4420 DriverHandle
= Database
->DriverHandle
;
4421 HiiHandle
= Database
->Handle
;
4428 // Try to find driver handle by device path.
4430 if (DriverHandle
== NULL
) {
4431 TempDevicePath
= DevicePath
;
4432 Status
= gBS
->LocateDevicePath (
4433 &gEfiDevicePathProtocolGuid
,
4437 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
4439 // Routing data does not match any known driver.
4440 // Set Progress to the 'G' in "GUID" of the routing header.
4442 *Progress
= StringPtr
;
4443 Status
= EFI_NOT_FOUND
;
4449 // Validate ConfigRequest String.
4451 ErrorPtr
= ConfigRequestValidate(ConfigRequest
);
4452 if (ErrorPtr
!= NULL
) {
4453 *Progress
= StrStr (StringPtr
, ErrorPtr
);
4454 Status
= EFI_INVALID_PARAMETER
;
4459 // Check whether ConfigRequest contains request string.
4461 IfrDataParsedFlag
= FALSE
;
4462 if ((HiiHandle
!= NULL
) && !GetElementsFromRequest(ConfigRequest
)) {
4464 // Get the full request string from IFR when HiiPackage is registered to HiiHandle
4466 IfrDataParsedFlag
= TRUE
;
4467 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, &AccessProgress
);
4468 if (EFI_ERROR (Status
)) {
4470 // AccessProgress indicates the parsing progress on <ConfigRequest>.
4471 // Map it to the progress on <MultiConfigRequest> then return it.
4473 ASSERT (AccessProgress
!= NULL
);
4474 *Progress
= StrStr (StringPtr
, AccessProgress
);
4478 // Not any request block is found.
4480 if (!GetElementsFromRequest(ConfigRequest
)) {
4481 AccessResults
= AllocateCopyPool (StrSize (ConfigRequest
), ConfigRequest
);
4482 goto NextConfigString
;
4487 // Check whether this ConfigRequest is search from Efi varstore type storage.
4489 Status
= GetVarStoreType(Database
, ConfigRequest
, &IsEfiVarStore
, &EfiVarStoreInfo
);
4490 if (EFI_ERROR (Status
)) {
4494 if (IsEfiVarStore
) {
4496 // Call the GetVariable function to extract settings.
4498 Status
= GetConfigRespFromEfiVarStore(This
, EfiVarStoreInfo
, ConfigRequest
, &AccessResults
, &AccessProgress
);
4499 FreePool (EfiVarStoreInfo
);
4500 if (EFI_ERROR (Status
)) {
4502 // AccessProgress indicates the parsing progress on <ConfigRequest>.
4503 // Map it to the progress on <MultiConfigRequest> then return it.
4505 *Progress
= StrStr (StringPtr
, AccessProgress
);
4510 // For EfiVarstore, call corresponding ConfigAccess protocol to get the AltCfgResp from driver.
4512 Status
= gBS
->HandleProtocol (
4514 &gEfiHiiConfigAccessProtocolGuid
,
4515 (VOID
**) &ConfigAccess
4517 if (EFI_ERROR (Status
)) {
4519 // The driver has EfiVarStore, may not install ConfigAccess protocol.
4520 // So ignore the error status in this case.
4522 Status
= EFI_SUCCESS
;
4524 Status
= ConfigAccess
->ExtractConfig (
4527 &AccessProgressBackup
,
4528 &AccessResultsBackup
4530 if (!EFI_ERROR(Status
)) {
4532 //Merge the AltCfgResp in AccessResultsBackup to AccessResults
4534 if ((AccessResultsBackup
!= NULL
) && (StrStr (AccessResultsBackup
, L
"&ALTCFG=") != NULL
)) {
4535 ConigStringSize
= StrSize (AccessResults
);
4536 ConfigStringPtr
= StrStr (AccessResultsBackup
, L
"&GUID=");
4537 ConigStringSizeNewsize
= StrSize (ConfigStringPtr
) + ConigStringSize
+ sizeof (CHAR16
);
4538 AccessResults
= (EFI_STRING
) ReallocatePool (
4540 ConigStringSizeNewsize
,
4542 StrCatS (AccessResults
, ConigStringSizeNewsize
/ sizeof (CHAR16
), ConfigStringPtr
);
4546 // In the ExtractConfig function of some driver may not support EfiVarStore,
4547 // may return error status, just ignore the error status in this case.
4549 Status
= EFI_SUCCESS
;
4551 if (AccessResultsBackup
!= NULL
) {
4552 FreePool (AccessResultsBackup
);
4553 AccessResultsBackup
= NULL
;
4558 // Call corresponding ConfigAccess protocol to extract settings
4560 Status
= gBS
->HandleProtocol (
4562 &gEfiHiiConfigAccessProtocolGuid
,
4563 (VOID
**) &ConfigAccess
4565 if (EFI_ERROR (Status
)) {
4569 Status
= ConfigAccess
->ExtractConfig (
4576 if (EFI_ERROR (Status
)) {
4578 // AccessProgress indicates the parsing progress on <ConfigRequest>.
4579 // Map it to the progress on <MultiConfigRequest> then return it.
4581 *Progress
= StrStr (StringPtr
, AccessProgress
);
4586 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
4587 // which seperates the first <ConfigAltResp> and the following ones.
4589 ASSERT (*AccessProgress
== 0);
4592 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
4594 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
) {
4595 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
4596 ASSERT_EFI_ERROR (Status
);
4599 FreePool (DevicePath
);
4602 if (DefaultResults
!= NULL
) {
4603 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
4604 ASSERT_EFI_ERROR (Status
);
4605 FreePool (DefaultResults
);
4606 DefaultResults
= NULL
;
4610 if (!FirstElement
) {
4611 Status
= AppendToMultiString (Results
, L
"&");
4612 ASSERT_EFI_ERROR (Status
);
4615 Status
= AppendToMultiString (Results
, AccessResults
);
4616 ASSERT_EFI_ERROR (Status
);
4618 FirstElement
= FALSE
;
4620 FreePool (AccessResults
);
4621 AccessResults
= NULL
;
4622 FreePool (ConfigRequest
);
4623 ConfigRequest
= NULL
;
4626 // Go to next <ConfigRequest> (skip '&').
4628 StringPtr
+= Length
;
4629 if (*StringPtr
== 0) {
4630 *Progress
= StringPtr
;
4638 if (EFI_ERROR (Status
)) {
4639 FreePool (*Results
);
4643 if (ConfigRequest
!= NULL
) {
4644 FreePool (ConfigRequest
);
4647 if (AccessResults
!= NULL
) {
4648 FreePool (AccessResults
);
4651 if (DefaultResults
!= NULL
) {
4652 FreePool (DefaultResults
);
4655 if (DevicePath
!= NULL
) {
4656 FreePool (DevicePath
);
4664 This function allows the caller to request the current configuration for the
4665 entirety of the current HII database and returns the data in a
4666 null-terminated Unicode string.
4668 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4670 @param Results Null-terminated Unicode string in
4671 <MultiConfigAltResp> format which has all values
4672 filled in for the entirety of the current HII
4673 database. String to be allocated by the called
4674 function. De-allocation is up to the caller.
4676 @retval EFI_SUCCESS The Results string is filled with the values
4677 corresponding to all requested names.
4678 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
4679 results that must be stored awaiting possible
4681 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results
4682 parameter would result in this type of error.
4687 HiiConfigRoutingExportConfig (
4688 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4689 OUT EFI_STRING
*Results
4693 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
4694 EFI_STRING AccessResults
;
4695 EFI_STRING Progress
;
4696 EFI_STRING StringPtr
;
4697 EFI_STRING ConfigRequest
;
4699 EFI_HANDLE
*ConfigAccessHandles
;
4700 UINTN NumberConfigAccessHandles
;
4701 BOOLEAN FirstElement
;
4702 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
4703 EFI_HII_HANDLE HiiHandle
;
4704 EFI_STRING DefaultResults
;
4705 HII_DATABASE_PRIVATE_DATA
*Private
;
4707 HII_DATABASE_RECORD
*Database
;
4708 UINT8
*DevicePathPkg
;
4709 UINT8
*CurrentDevicePath
;
4710 BOOLEAN IfrDataParsedFlag
;
4712 if (This
== NULL
|| Results
== NULL
) {
4713 return EFI_INVALID_PARAMETER
;
4716 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4719 // Allocate a fix length of memory to store Results. Reallocate memory for
4720 // Results if this fix length is insufficient.
4722 *Results
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
4723 if (*Results
== NULL
) {
4724 return EFI_OUT_OF_RESOURCES
;
4727 NumberConfigAccessHandles
= 0;
4728 Status
= gBS
->LocateHandleBuffer (
4730 &gEfiHiiConfigAccessProtocolGuid
,
4732 &NumberConfigAccessHandles
,
4733 &ConfigAccessHandles
4735 if (EFI_ERROR (Status
)) {
4739 FirstElement
= TRUE
;
4741 for (Index
= 0; Index
< NumberConfigAccessHandles
; Index
++) {
4742 Status
= gBS
->HandleProtocol (
4743 ConfigAccessHandles
[Index
],
4744 &gEfiHiiConfigAccessProtocolGuid
,
4745 (VOID
**) &ConfigAccess
4747 if (EFI_ERROR (Status
)) {
4752 // Get DevicePath and HiiHandle for this ConfigAccess driver handle
4754 IfrDataParsedFlag
= FALSE
;
4757 DefaultResults
= NULL
;
4759 ConfigRequest
= NULL
;
4760 DevicePath
= DevicePathFromHandle (ConfigAccessHandles
[Index
]);
4761 if (DevicePath
!= NULL
) {
4762 for (Link
= Private
->DatabaseList
.ForwardLink
;
4763 Link
!= &Private
->DatabaseList
;
4764 Link
= Link
->ForwardLink
4766 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
4767 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
4768 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
4772 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
)
4774 HiiHandle
= Database
->Handle
;
4781 Status
= ConfigAccess
->ExtractConfig (
4787 if (EFI_ERROR (Status
)) {
4789 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
4791 if (HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
4792 IfrDataParsedFlag
= TRUE
;
4793 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &ConfigRequest
, &DefaultResults
, NULL
);
4795 // Get the full request string to get the Current setting again.
4797 if (!EFI_ERROR (Status
) && ConfigRequest
!= NULL
) {
4798 Status
= ConfigAccess
->ExtractConfig (
4804 FreePool (ConfigRequest
);
4806 Status
= EFI_NOT_FOUND
;
4811 if (!EFI_ERROR (Status
)) {
4813 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
4815 if (!IfrDataParsedFlag
&& HiiHandle
!= NULL
&& DevicePath
!= NULL
) {
4816 StringPtr
= StrStr (AccessResults
, L
"&GUID=");
4817 if (StringPtr
!= NULL
) {
4820 if (GetElementsFromRequest (AccessResults
)) {
4821 Status
= GetFullStringFromHiiFormPackages (Database
, DevicePath
, &AccessResults
, &DefaultResults
, NULL
);
4822 ASSERT_EFI_ERROR (Status
);
4824 if (StringPtr
!= NULL
) {
4829 // Merge the default sting from IFR code into the got setting from driver.
4831 if (DefaultResults
!= NULL
) {
4832 Status
= MergeDefaultString (&AccessResults
, DefaultResults
);
4833 ASSERT_EFI_ERROR (Status
);
4834 FreePool (DefaultResults
);
4835 DefaultResults
= NULL
;
4839 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'
4840 // which seperates the first <ConfigAltResp> and the following ones.
4842 if (!FirstElement
) {
4843 Status
= AppendToMultiString (Results
, L
"&");
4844 ASSERT_EFI_ERROR (Status
);
4847 Status
= AppendToMultiString (Results
, AccessResults
);
4848 ASSERT_EFI_ERROR (Status
);
4850 FirstElement
= FALSE
;
4852 FreePool (AccessResults
);
4853 AccessResults
= NULL
;
4856 FreePool (ConfigAccessHandles
);
4863 This function processes the results of processing forms and routes it to the
4864 appropriate handlers or storage.
4866 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
4868 @param Configuration A null-terminated Unicode string in
4869 <MulltiConfigResp> format.
4870 @param Progress A pointer to a string filled in with the offset of
4871 the most recent & before the first failing name /
4872 value pair (or the beginning of the string if the
4873 failure is in the first name / value pair) or the
4874 terminating NULL if all was successful.
4876 @retval EFI_SUCCESS The results have been distributed or are awaiting
4878 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the
4879 results that must be stored awaiting possible
4881 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter
4882 would result in this type of error.
4883 @retval EFI_NOT_FOUND Target for the specified routing data was not
4889 HiiConfigRoutingRouteConfig (
4890 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
4891 IN CONST EFI_STRING Configuration
,
4892 OUT EFI_STRING
*Progress
4895 HII_DATABASE_PRIVATE_DATA
*Private
;
4896 EFI_STRING StringPtr
;
4897 EFI_STRING ConfigResp
;
4900 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
4901 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
4903 HII_DATABASE_RECORD
*Database
;
4904 UINT8
*DevicePathPkg
;
4905 UINT8
*CurrentDevicePath
;
4906 EFI_HANDLE DriverHandle
;
4907 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
4908 EFI_STRING AccessProgress
;
4909 EFI_IFR_VARSTORE_EFI
*EfiVarStoreInfo
;
4910 BOOLEAN IsEfiVarstore
;
4911 UINTN DevicePathSize
;
4913 if (This
== NULL
|| Progress
== NULL
) {
4914 return EFI_INVALID_PARAMETER
;
4917 if (Configuration
== NULL
) {
4919 return EFI_INVALID_PARAMETER
;
4922 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
4923 StringPtr
= Configuration
;
4924 *Progress
= StringPtr
;
4926 AccessProgress
= NULL
;
4927 EfiVarStoreInfo
= NULL
;
4928 IsEfiVarstore
= FALSE
;
4931 // The first element of <MultiConfigResp> should be
4932 // <GuidHdr>, which is in 'GUID='<Guid> syntax.
4934 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
4935 return EFI_INVALID_PARAMETER
;
4938 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) == 0) {
4940 // If parsing error, set Progress to the beginning of the <MultiConfigResp>
4941 // or most recent & before the error.
4943 if (StringPtr
== Configuration
) {
4944 *Progress
= StringPtr
;
4946 *Progress
= StringPtr
- 1;
4950 // Process each <ConfigResp> of <MultiConfigResp>
4952 Length
= CalculateConfigStringLen (StringPtr
);
4953 ConfigResp
= AllocateCopyPool ((Length
+ 1) * sizeof (CHAR16
), StringPtr
);
4954 if (ConfigResp
== NULL
) {
4955 return EFI_OUT_OF_RESOURCES
;
4958 // Append '\0' to the end of ConfigRequest
4960 *(ConfigResp
+ Length
) = 0;
4963 // Get the UEFI device path
4965 Status
= GetDevicePath (ConfigResp
, (UINT8
**) &DevicePath
);
4966 if (EFI_ERROR (Status
)) {
4967 FreePool (ConfigResp
);
4972 // Find driver which matches the routing data.
4974 DriverHandle
= NULL
;
4975 for (Link
= Private
->DatabaseList
.ForwardLink
;
4976 Link
!= &Private
->DatabaseList
;
4977 Link
= Link
->ForwardLink
4979 Database
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
4981 if ((DevicePathPkg
= Database
->PackageList
->DevicePathPkg
) != NULL
) {
4982 CurrentDevicePath
= DevicePathPkg
+ sizeof (EFI_HII_PACKAGE_HEADER
);
4983 DevicePathSize
= GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) CurrentDevicePath
);
4984 if ((CompareMem (DevicePath
,CurrentDevicePath
,DevicePathSize
) == 0) && IsThisPackageList(Database
, ConfigResp
)) {
4985 DriverHandle
= Database
->DriverHandle
;
4992 // Try to find driver handle by device path.
4994 if (DriverHandle
== NULL
) {
4995 TempDevicePath
= DevicePath
;
4996 Status
= gBS
->LocateDevicePath (
4997 &gEfiDevicePathProtocolGuid
,
5001 if (EFI_ERROR (Status
) || (DriverHandle
== NULL
)) {
5003 // Routing data does not match any known driver.
5004 // Set Progress to the 'G' in "GUID" of the routing header.
5006 FreePool (DevicePath
);
5007 *Progress
= StringPtr
;
5008 FreePool (ConfigResp
);
5009 return EFI_NOT_FOUND
;
5013 FreePool (DevicePath
);
5016 // Check whether this ConfigRequest is search from Efi varstore type storage.
5018 Status
= GetVarStoreType(Database
, ConfigResp
, &IsEfiVarstore
, &EfiVarStoreInfo
);
5019 if (EFI_ERROR (Status
)) {
5023 if (IsEfiVarstore
) {
5025 // Call the SetVariable function to route settings.
5027 Status
= RouteConfigRespForEfiVarStore(This
, EfiVarStoreInfo
, ConfigResp
, &AccessProgress
);
5028 FreePool (EfiVarStoreInfo
);
5031 // Call corresponding ConfigAccess protocol to route settings
5033 Status
= gBS
->HandleProtocol (
5035 &gEfiHiiConfigAccessProtocolGuid
,
5036 (VOID
**) &ConfigAccess
5038 if (EFI_ERROR (Status
)) {
5039 *Progress
= StringPtr
;
5040 FreePool (ConfigResp
);
5041 return EFI_NOT_FOUND
;
5044 Status
= ConfigAccess
->RouteConfig (
5050 if (EFI_ERROR (Status
)) {
5051 ASSERT (AccessProgress
!= NULL
);
5053 // AccessProgress indicates the parsing progress on <ConfigResp>.
5054 // Map it to the progress on <MultiConfigResp> then return it.
5056 *Progress
= StrStr (StringPtr
, AccessProgress
);
5058 FreePool (ConfigResp
);
5062 FreePool (ConfigResp
);
5066 // Go to next <ConfigResp> (skip '&').
5068 StringPtr
+= Length
;
5069 if (*StringPtr
== 0) {
5070 *Progress
= StringPtr
;
5083 This helper function is to be called by drivers to map configuration data
5084 stored in byte array ("block") formats such as UEFI Variables into current
5085 configuration strings.
5087 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5089 @param ConfigRequest A null-terminated Unicode string in
5090 <ConfigRequest> format.
5091 @param Block Array of bytes defining the block's configuration.
5092 @param BlockSize Length in bytes of Block.
5093 @param Config Filled-in configuration string. String allocated
5094 by the function. Returned only if call is
5095 successful. It is <ConfigResp> string format.
5096 @param Progress A pointer to a string filled in with the offset of
5097 the most recent & before the first failing
5098 name/value pair (or the beginning of the string if
5099 the failure is in the first name / value pair) or
5100 the terminating NULL if all was successful.
5102 @retval EFI_SUCCESS The request succeeded. Progress points to the null
5103 terminator at the end of the ConfigRequest
5105 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
5106 points to the first character of ConfigRequest.
5107 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or
5108 Block parameter would result in this type of
5109 error. Progress points to the first character of
5111 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.
5112 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.
5113 Block is left updated and Progress points at
5114 the "&" preceding the first non-<BlockName>.
5120 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
5121 IN CONST EFI_STRING ConfigRequest
,
5122 IN CONST UINT8
*Block
,
5123 IN CONST UINTN BlockSize
,
5124 OUT EFI_STRING
*Config
,
5125 OUT EFI_STRING
*Progress
5128 HII_DATABASE_PRIVATE_DATA
*Private
;
5129 EFI_STRING StringPtr
;
5137 EFI_STRING ValueStr
;
5138 EFI_STRING ConfigElement
;
5146 if (This
== NULL
|| Progress
== NULL
|| Config
== NULL
) {
5147 return EFI_INVALID_PARAMETER
;
5150 if (Block
== NULL
|| ConfigRequest
== NULL
) {
5151 *Progress
= ConfigRequest
;
5152 return EFI_INVALID_PARAMETER
;
5156 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
5157 ASSERT (Private
!= NULL
);
5159 StringPtr
= ConfigRequest
;
5162 ConfigElement
= NULL
;
5165 // Allocate a fix length of memory to store Results. Reallocate memory for
5166 // Results if this fix length is insufficient.
5168 *Config
= (EFI_STRING
) AllocateZeroPool (MAX_STRING_LENGTH
);
5169 if (*Config
== NULL
) {
5170 return EFI_OUT_OF_RESOURCES
;
5176 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
5177 *Progress
= StringPtr
;
5178 Status
= EFI_INVALID_PARAMETER
;
5181 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
5184 if (*StringPtr
== 0) {
5185 *Progress
= StringPtr
- 1;
5186 Status
= EFI_INVALID_PARAMETER
;
5190 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
5193 if (*StringPtr
== 0) {
5194 *Progress
= StringPtr
;
5196 AppendToMultiString(Config
, ConfigRequest
);
5197 HiiToLower (*Config
);
5207 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>
5209 TemChar
= *StringPtr
;
5211 AppendToMultiString(Config
, ConfigRequest
);
5212 *StringPtr
= TemChar
;
5215 // Parse each <RequestElement> if exists
5216 // Only <BlockName> format is supported by this help function.
5217 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>
5219 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"OFFSET=", StrLen (L
"OFFSET=")) == 0) {
5221 // Back up the header of one <BlockName>
5225 StringPtr
+= StrLen (L
"OFFSET=");
5229 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5230 if (EFI_ERROR (Status
)) {
5231 *Progress
= TmpPtr
- 1;
5238 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5240 FreePool (TmpBuffer
);
5242 StringPtr
+= Length
;
5243 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
5244 *Progress
= TmpPtr
- 1;
5245 Status
= EFI_INVALID_PARAMETER
;
5248 StringPtr
+= StrLen (L
"&WIDTH=");
5253 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5254 if (EFI_ERROR (Status
)) {
5255 *Progress
= TmpPtr
- 1;
5262 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5264 FreePool (TmpBuffer
);
5266 StringPtr
+= Length
;
5267 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
5268 *Progress
= TmpPtr
- 1;
5269 Status
= EFI_INVALID_PARAMETER
;
5274 // Calculate Value and convert it to hex string.
5276 if (Offset
+ Width
> BlockSize
) {
5277 *Progress
= StringPtr
;
5278 Status
= EFI_DEVICE_ERROR
;
5282 Value
= (UINT8
*) AllocateZeroPool (Width
);
5283 if (Value
== NULL
) {
5284 *Progress
= ConfigRequest
;
5285 Status
= EFI_OUT_OF_RESOURCES
;
5289 CopyMem (Value
, (UINT8
*) Block
+ Offset
, Width
);
5291 Length
= Width
* 2 + 1;
5292 ValueStr
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
5293 if (ValueStr
== NULL
) {
5294 *Progress
= ConfigRequest
;
5295 Status
= EFI_OUT_OF_RESOURCES
;
5299 TemString
= ValueStr
;
5300 TemBuffer
= Value
+ Width
- 1;
5301 for (Index
= 0; Index
< Width
; Index
++, TemBuffer
--) {
5302 TemString
+= UnicodeValueToString (TemString
, PREFIX_ZERO
| RADIX_HEX
, *TemBuffer
, 2);
5309 // Build a ConfigElement
5311 Length
+= StringPtr
- TmpPtr
+ 1 + StrLen (L
"VALUE=");
5312 ConfigElement
= (EFI_STRING
) AllocateZeroPool (Length
* sizeof (CHAR16
));
5313 if (ConfigElement
== NULL
) {
5314 Status
= EFI_OUT_OF_RESOURCES
;
5317 CopyMem (ConfigElement
, TmpPtr
, (StringPtr
- TmpPtr
+ 1) * sizeof (CHAR16
));
5318 if (*StringPtr
== 0) {
5319 *(ConfigElement
+ (StringPtr
- TmpPtr
)) = L
'&';
5321 *(ConfigElement
+ (StringPtr
- TmpPtr
) + 1) = 0;
5322 StrCatS (ConfigElement
, Length
, L
"VALUE=");
5323 StrCatS (ConfigElement
, Length
, ValueStr
);
5325 AppendToMultiString (Config
, ConfigElement
);
5327 FreePool (ConfigElement
);
5328 FreePool (ValueStr
);
5329 ConfigElement
= NULL
;
5333 // If '\0', parsing is finished. Otherwise skip '&' to continue
5335 if (*StringPtr
== 0) {
5338 AppendToMultiString (Config
, L
"&");
5343 if (*StringPtr
!= 0) {
5344 *Progress
= StringPtr
- 1;
5345 Status
= EFI_INVALID_PARAMETER
;
5349 HiiToLower (*Config
);
5350 *Progress
= StringPtr
;
5354 if (*Config
!= NULL
) {
5358 if (ValueStr
!= NULL
) {
5359 FreePool (ValueStr
);
5361 if (Value
!= NULL
) {
5364 if (ConfigElement
!= NULL
) {
5365 FreePool (ConfigElement
);
5374 This helper function is to be called by drivers to map configuration strings
5375 to configurations stored in byte array ("block") formats such as UEFI Variables.
5377 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5379 @param ConfigResp A null-terminated Unicode string in <ConfigResp>
5381 @param Block A possibly null array of bytes representing the
5382 current block. Only bytes referenced in the
5383 ConfigResp string in the block are modified. If
5384 this parameter is null or if the *BlockSize
5385 parameter is (on input) shorter than required by
5386 the Configuration string, only the BlockSize
5387 parameter is updated and an appropriate status
5388 (see below) is returned.
5389 @param BlockSize The length of the Block in units of UINT8. On
5390 input, this is the size of the Block. On output,
5391 if successful, contains the largest index of the
5392 modified byte in the Block, or the required buffer
5393 size if the Block is not large enough.
5394 @param Progress On return, points to an element of the ConfigResp
5395 string filled in with the offset of the most
5396 recent '&' before the first failing name / value
5397 pair (or the beginning of the string if the
5398 failure is in the first name / value pair) or the
5399 terminating NULL if all was successful.
5401 @retval EFI_SUCCESS The request succeeded. Progress points to the null
5402 terminator at the end of the ConfigResp string.
5403 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress
5404 points to the first character of ConfigResp.
5405 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or
5406 Block parameter would result in this type of
5407 error. Progress points to the first character of
5409 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /
5410 value pair. Block is left updated and
5411 Progress points at the '&' preceding the first
5413 @retval EFI_BUFFER_TOO_SMALL Block not large enough. Progress undefined.
5414 BlockSize is updated with the required buffer size.
5415 @retval EFI_NOT_FOUND Target for the specified routing data was not found.
5416 Progress points to the "G" in "GUID" of the errant
5423 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
5424 IN CONST EFI_STRING ConfigResp
,
5425 IN OUT UINT8
*Block
,
5426 IN OUT UINTN
*BlockSize
,
5427 OUT EFI_STRING
*Progress
5430 HII_DATABASE_PRIVATE_DATA
*Private
;
5431 EFI_STRING StringPtr
;
5444 if (This
== NULL
|| BlockSize
== NULL
|| Progress
== NULL
) {
5445 return EFI_INVALID_PARAMETER
;
5448 *Progress
= ConfigResp
;
5449 if (ConfigResp
== NULL
) {
5450 return EFI_INVALID_PARAMETER
;
5453 Private
= CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
5454 ASSERT (Private
!= NULL
);
5456 StringPtr
= ConfigResp
;
5457 BufferSize
= *BlockSize
;
5464 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
5465 *Progress
= StringPtr
;
5466 Status
= EFI_INVALID_PARAMETER
;
5469 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"PATH=", StrLen (L
"PATH=")) != 0) {
5472 if (*StringPtr
== 0) {
5473 *Progress
= StringPtr
;
5474 Status
= EFI_INVALID_PARAMETER
;
5478 while (*StringPtr
!= L
'&' && *StringPtr
!= 0) {
5481 if (*StringPtr
== 0) {
5482 *Progress
= StringPtr
;
5483 Status
= EFI_INVALID_PARAMETER
;
5488 // Parse each <ConfigElement> if exists
5489 // Only '&'<BlockConfig> format is supported by this help function.
5490 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>
5492 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
5494 StringPtr
+= StrLen (L
"&OFFSET=");
5498 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5499 if (EFI_ERROR (Status
)) {
5507 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5509 FreePool (TmpBuffer
);
5511 StringPtr
+= Length
;
5512 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
5514 Status
= EFI_INVALID_PARAMETER
;
5517 StringPtr
+= StrLen (L
"&WIDTH=");
5522 Status
= GetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
5523 if (EFI_ERROR (Status
)) {
5531 (((Length
+ 1) / 2) < sizeof (UINTN
)) ? ((Length
+ 1) / 2) : sizeof (UINTN
)
5533 FreePool (TmpBuffer
);
5535 StringPtr
+= Length
;
5536 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
5538 Status
= EFI_INVALID_PARAMETER
;
5541 StringPtr
+= StrLen (L
"&VALUE=");
5546 Status
= GetValueOfNumber (StringPtr
, &Value
, &Length
);
5547 if (EFI_ERROR (Status
)) {
5552 StringPtr
+= Length
;
5553 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
5555 Status
= EFI_INVALID_PARAMETER
;
5560 // Update the Block with configuration info
5562 if ((Block
!= NULL
) && (Offset
+ Width
<= BufferSize
)) {
5563 CopyMem (Block
+ Offset
, Value
, Width
);
5565 if (Offset
+ Width
> MaxBlockSize
) {
5566 MaxBlockSize
= Offset
+ Width
;
5573 // If '\0', parsing is finished.
5575 if (*StringPtr
== 0) {
5581 // The input string is not ConfigResp format, return error.
5583 if (*StringPtr
!= 0) {
5584 *Progress
= StringPtr
;
5585 Status
= EFI_INVALID_PARAMETER
;
5589 *Progress
= StringPtr
+ StrLen (StringPtr
);
5590 *BlockSize
= MaxBlockSize
- 1;
5592 if (MaxBlockSize
> BufferSize
) {
5593 *BlockSize
= MaxBlockSize
;
5594 if (Block
!= NULL
) {
5595 return EFI_BUFFER_TOO_SMALL
;
5599 if (Block
== NULL
) {
5600 *Progress
= ConfigResp
;
5601 return EFI_INVALID_PARAMETER
;
5608 if (Value
!= NULL
) {
5616 This helper function is to be called by drivers to extract portions of
5617 a larger configuration string.
5619 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL
5621 @param Configuration A null-terminated Unicode string in
5622 <MultiConfigAltResp> format.
5623 @param Guid A pointer to the GUID value to search for in the
5624 routing portion of the ConfigResp string when
5625 retrieving the requested data. If Guid is NULL,
5626 then all GUID values will be searched for.
5627 @param Name A pointer to the NAME value to search for in the
5628 routing portion of the ConfigResp string when
5629 retrieving the requested data. If Name is NULL,
5630 then all Name values will be searched for.
5631 @param DevicePath A pointer to the PATH value to search for in the
5632 routing portion of the ConfigResp string when
5633 retrieving the requested data. If DevicePath is
5634 NULL, then all DevicePath values will be searched
5636 @param AltCfgId A pointer to the ALTCFG value to search for in the
5637 routing portion of the ConfigResp string when
5638 retrieving the requested data. If this parameter
5639 is NULL, then the current setting will be
5641 @param AltCfgResp A pointer to a buffer which will be allocated by
5642 the function which contains the retrieved string
5643 as requested. This buffer is only allocated if
5644 the call was successful. It is <ConfigResp> format.
5646 @retval EFI_SUCCESS The request succeeded. The requested data was
5647 extracted and placed in the newly allocated
5649 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.
5650 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
5651 @retval EFI_NOT_FOUND Target for the specified routing data was not
5658 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*This
,
5659 IN CONST EFI_STRING Configuration
,
5660 IN CONST EFI_GUID
*Guid
,
5661 IN CONST EFI_STRING Name
,
5662 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
5663 IN CONST UINT16
*AltCfgId
,
5664 OUT EFI_STRING
*AltCfgResp
5668 EFI_STRING StringPtr
;
5669 EFI_STRING HdrStart
;
5676 EFI_STRING AltIdStr
;
5693 if (This
== NULL
|| Configuration
== NULL
|| AltCfgResp
== NULL
) {
5694 return EFI_INVALID_PARAMETER
;
5697 StringPtr
= Configuration
;
5698 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
5699 return EFI_INVALID_PARAMETER
;
5703 // Generate the sub string for later matching.
5705 GenerateSubStr (L
"GUID=", sizeof (EFI_GUID
), (VOID
*) Guid
, 1, &GuidStr
);
5708 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*) DevicePath
),
5709 (VOID
*) DevicePath
,
5713 if (AltCfgId
!= NULL
) {
5714 GenerateSubStr (L
"ALTCFG=", sizeof (UINT16
), (VOID
*) AltCfgId
, 3, &AltIdStr
);
5717 GenerateSubStr (L
"NAME=", StrLen (Name
) * sizeof (CHAR16
), (VOID
*) Name
, 2, &NameStr
);
5719 GenerateSubStr (L
"NAME=", 0, NULL
, 2, &NameStr
);
5722 while (*StringPtr
!= 0) {
5724 // Try to match the GUID
5727 TmpPtr
= StrStr (StringPtr
, GuidStr
);
5728 if (TmpPtr
== NULL
) {
5729 Status
= EFI_NOT_FOUND
;
5735 // Jump to <NameHdr>
5738 StringPtr
= TmpPtr
+ StrLen (GuidStr
);
5740 StringPtr
= StrStr (TmpPtr
, L
"NAME=");
5741 if (StringPtr
== NULL
) {
5742 Status
= EFI_NOT_FOUND
;
5750 // Try to match the NAME
5752 if (GuidFlag
&& !NameFlag
) {
5753 if (StrnCmp (StringPtr
, NameStr
, StrLen (NameStr
)) != 0) {
5757 // Jump to <PathHdr>
5760 StringPtr
+= StrLen (NameStr
);
5762 StringPtr
= StrStr (StringPtr
, L
"PATH=");
5763 if (StringPtr
== NULL
) {
5764 Status
= EFI_NOT_FOUND
;
5773 // Try to match the DevicePath
5775 if (GuidFlag
&& NameFlag
&& !PathFlag
) {
5776 if (StrnCmp (StringPtr
, PathStr
, StrLen (PathStr
)) != 0) {
5781 // Jump to '&' before <DescHdr> or <ConfigBody>
5783 if (DevicePath
!= NULL
) {
5784 StringPtr
+= StrLen (PathStr
);
5786 StringPtr
= StrStr (StringPtr
, L
"&");
5787 if (StringPtr
== NULL
) {
5788 Status
= EFI_NOT_FOUND
;
5799 // Try to match the AltCfgId
5801 if (GuidFlag
&& NameFlag
&& PathFlag
) {
5802 if (AltCfgId
== NULL
) {
5804 // Return Current Setting when AltCfgId is NULL.
5806 Status
= OutputConfigBody (StringPtr
, &Result
);
5810 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.
5812 if (StrnCmp (StringPtr
, AltIdStr
, StrLen (AltIdStr
)) != 0) {
5818 // Skip AltIdStr and &
5820 StringPtr
= StringPtr
+ StrLen (AltIdStr
);
5821 Status
= OutputConfigBody (StringPtr
, &Result
);
5827 Status
= EFI_NOT_FOUND
;
5831 if (!EFI_ERROR (Status
) && (Result
!= NULL
)) {
5833 // Copy the <ConfigHdr> and <ConfigBody>
5835 Length
= HdrEnd
- HdrStart
+ StrLen (Result
) + 1;
5836 *AltCfgResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
5837 if (*AltCfgResp
== NULL
) {
5838 Status
= EFI_OUT_OF_RESOURCES
;
5840 StrnCpyS (*AltCfgResp
, Length
, HdrStart
, HdrEnd
- HdrStart
);
5841 StrCatS (*AltCfgResp
, Length
, Result
);
5842 Status
= EFI_SUCCESS
;
5846 if (GuidStr
!= NULL
) {
5849 if (NameStr
!= NULL
) {
5852 if (PathStr
!= NULL
) {
5855 if (AltIdStr
!= NULL
) {
5856 FreePool (AltIdStr
);
5858 if (Result
!= NULL
) {