]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
MdeModulePkg/HiiDatabase: Refine HiiDrawImage()
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
CommitLineData
93e3992d 1/** @file\r
3cb3f198 2Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r
93e3992d 3\r
f447734e 4Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
93e3992d 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
93e3992d 13**/\r
14\r
15\r
16#include "HiiDatabase.h"\r
84f9a9ec 17extern HII_DATABASE_PRIVATE_DATA mPrivate;\r
93e3992d 18\r
93e3992d 19/**\r
20 Calculate the number of Unicode characters of the incoming Configuration string,\r
21 not including NULL terminator.\r
22\r
e90b081a 23 This is a internal function.\r
24\r
93e3992d 25 @param String String in <MultiConfigRequest> or\r
26 <MultiConfigResp> format.\r
27\r
28 @return The number of Unicode characters.\r
29\r
30**/\r
93e3992d 31UINTN\r
32CalculateConfigStringLen (\r
33 IN EFI_STRING String\r
34 )\r
35{\r
84f9a9ec 36 EFI_STRING TmpPtr;\r
93e3992d 37\r
38 //\r
39 // "GUID=" should be the first element of incoming string.\r
40 //\r
41 ASSERT (String != NULL);\r
42 ASSERT (StrnCmp (String, L"GUID=", StrLen (L"GUID=")) == 0);\r
43\r
93e3992d 44 //\r
45 // The beginning of next <ConfigRequest>/<ConfigResp> should be "&GUID=".\r
46 // Will meet '\0' if there is only one <ConfigRequest>/<ConfigResp>.\r
84f9a9ec
LG
47 // \r
48 TmpPtr = StrStr (String, L"&GUID=");\r
49 if (TmpPtr == NULL) {\r
50 return StrLen (String);\r
93e3992d 51 }\r
52\r
84f9a9ec 53 return (TmpPtr - String);\r
93e3992d 54}\r
55\r
56\r
57/**\r
58 Convert the hex UNICODE %02x encoding of a UEFI device path to binary\r
59 from <PathHdr> of <ConfigHdr>.\r
60\r
e90b081a 61 This is a internal function.\r
62\r
93e3992d 63 @param String UEFI configuration string\r
ae79d2f9 64 @param DevicePathData Binary of a UEFI device path.\r
93e3992d 65\r
ae79d2f9 66 @retval EFI_NOT_FOUND The device path is not invalid.\r
93e3992d 67 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.\r
68 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.\r
69 @retval EFI_SUCCESS The device path is retrieved and translated to\r
70 binary format.\r
71\r
72**/\r
93e3992d 73EFI_STATUS\r
74GetDevicePath (\r
75 IN EFI_STRING String,\r
ae79d2f9 76 OUT UINT8 **DevicePathData\r
93e3992d 77 )\r
78{\r
ae79d2f9
LG
79 UINTN Length;\r
80 EFI_STRING PathHdr;\r
81 UINT8 *DevicePathBuffer;\r
82 CHAR16 TemStr[2];\r
83 UINTN Index;\r
84 UINT8 DigitUint8;\r
85 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
86\r
87\r
88 if (String == NULL || DevicePathData == NULL) {\r
93e3992d 89 return EFI_INVALID_PARAMETER;\r
90 }\r
91\r
92 //\r
93 // Find the 'PATH=' of <PathHdr> and skip it.\r
94 //\r
95 for (; (*String != 0 && StrnCmp (String, L"PATH=", StrLen (L"PATH=")) != 0); String++);\r
96 if (*String == 0) {\r
97 return EFI_INVALID_PARAMETER;\r
98 }\r
ae79d2f9
LG
99 //\r
100 // Check whether path data does exist.\r
101 //\r
93e3992d 102 String += StrLen (L"PATH=");\r
ae79d2f9
LG
103 if (*String == 0) {\r
104 return EFI_INVALID_PARAMETER;\r
105 }\r
93e3992d 106 PathHdr = String;\r
107\r
108 //\r
109 // The content between 'PATH=' of <ConfigHdr> and '&' of next element\r
110 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding\r
111 // of UEFI device path.\r
112 //\r
113 for (Length = 0; *String != 0 && *String != L'&'; String++, Length++);\r
ae79d2f9
LG
114 //\r
115 // Check DevicePath Length\r
116 //\r
117 if (((Length + 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
118 return EFI_NOT_FOUND;\r
93e3992d 119 }\r
ae79d2f9 120 \r
93e3992d 121 //\r
122 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order\r
123 // as the device path resides in RAM memory.\r
124 // Translate the data into binary.\r
93e3992d 125 //\r
63d55bb9
LG
126 DevicePathBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);\r
127 if (DevicePathBuffer == NULL) {\r
93e3992d 128 return EFI_OUT_OF_RESOURCES;\r
129 }\r
ae79d2f9
LG
130 \r
131 //\r
132 // Convert DevicePath\r
133 //\r
63d55bb9 134 ZeroMem (TemStr, sizeof (TemStr));\r
ae79d2f9
LG
135 for (Index = 0; Index < Length; Index ++) {\r
136 TemStr[0] = PathHdr[Index];\r
63d55bb9
LG
137 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
138 if ((Index & 1) == 0) {\r
139 DevicePathBuffer [Index/2] = DigitUint8;\r
140 } else {\r
141 DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
142 }\r
143 }\r
63d55bb9 144 \r
ae79d2f9
LG
145 //\r
146 // Validate DevicePath\r
147 //\r
148 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DevicePathBuffer;\r
149 while (!IsDevicePathEnd (DevicePath)) {\r
91a306ee 150 if ((DevicePath->Type == 0) || (DevicePath->SubType == 0) || (DevicePathNodeLength (DevicePath) < sizeof (EFI_DEVICE_PATH_PROTOCOL))) {\r
ae79d2f9
LG
151 //\r
152 // Invalid device path\r
153 //\r
154 FreePool (DevicePathBuffer);\r
155 return EFI_NOT_FOUND;\r
156 }\r
157 DevicePath = NextDevicePathNode (DevicePath);\r
158 }\r
93e3992d 159\r
ae79d2f9
LG
160 //\r
161 // return the device path\r
162 //\r
163 *DevicePathData = DevicePathBuffer;\r
93e3992d 164 return EFI_SUCCESS;\r
93e3992d 165}\r
166\r
63d55bb9
LG
167/**\r
168 Converts the unicode character of the string from uppercase to lowercase.\r
169 This is a internal function.\r
170\r
aa75dfec 171 @param ConfigString String to be converted\r
63d55bb9
LG
172\r
173**/\r
174VOID\r
175EFIAPI\r
176HiiToLower (\r
84f9a9ec 177 IN EFI_STRING ConfigString\r
63d55bb9
LG
178 )\r
179{\r
84f9a9ec
LG
180 EFI_STRING String;\r
181 BOOLEAN Lower;\r
182\r
183 ASSERT (ConfigString != NULL);\r
184\r
185 //\r
186 // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r
187 //\r
188 for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) {\r
189 if (*String == L'=') {\r
190 Lower = TRUE;\r
191 } else if (*String == L'&') {\r
192 Lower = FALSE;\r
193 } else if (Lower && *String >= L'A' && *String <= L'F') {\r
194 *String = (CHAR16) (*String - L'A' + L'a');\r
63d55bb9
LG
195 }\r
196 }\r
84f9a9ec
LG
197\r
198 return;\r
63d55bb9 199}\r
93e3992d 200\r
93e3992d 201/**\r
202 Generate a sub string then output it.\r
203\r
e90b081a 204 This is a internal function.\r
205\r
93e3992d 206 @param String A constant string which is the prefix of the to be\r
207 generated string, e.g. GUID=\r
84f9a9ec 208\r
93e3992d 209 @param BufferLen The length of the Buffer in bytes.\r
84f9a9ec 210\r
813acf3a 211 @param Buffer Points to a buffer which will be converted to be the \r
84f9a9ec
LG
212 content of the generated string.\r
213\r
214 @param Flag If 1, the buffer contains data for the value of GUID or PATH stored in \r
215 UINT8 *; if 2, the buffer contains unicode string for the value of NAME;\r
216 if 3, the buffer contains other data.\r
217\r
93e3992d 218 @param SubStr Points to the output string. It's caller's\r
219 responsibility to free this buffer.\r
220\r
221\r
222**/\r
93e3992d 223VOID\r
224GenerateSubStr (\r
225 IN CONST EFI_STRING String,\r
226 IN UINTN BufferLen,\r
813acf3a 227 IN VOID *Buffer,\r
228 IN UINT8 Flag,\r
93e3992d 229 OUT EFI_STRING *SubStr\r
230 )\r
231{\r
232 UINTN Length;\r
233 EFI_STRING Str;\r
813acf3a 234 EFI_STRING StringHeader;\r
63d55bb9
LG
235 CHAR16 *TemString;\r
236 CHAR16 *TemName;\r
237 UINT8 *TemBuffer;\r
238 UINTN Index;\r
93e3992d 239\r
240 ASSERT (String != NULL && SubStr != NULL);\r
241\r
242 if (Buffer == NULL) {\r
243 *SubStr = AllocateCopyPool (StrSize (String), String);\r
244 ASSERT (*SubStr != NULL);\r
82e8c138 245 return;\r
93e3992d 246 }\r
84f9a9ec
LG
247 \r
248 //\r
249 // Header + Data + '&' + '\0'\r
250 //\r
813acf3a 251 Length = StrLen (String) + BufferLen * 2 + 1 + 1;\r
63d55bb9 252 Str = AllocateZeroPool (Length * sizeof (CHAR16));\r
93e3992d 253 ASSERT (Str != NULL);\r
254\r
5ad66ec6 255 StrCpyS (Str, Length, String);\r
93e3992d 256\r
813acf3a 257 StringHeader = Str + StrLen (String);\r
63d55bb9 258 TemString = (CHAR16 *) StringHeader;\r
813acf3a 259\r
260 switch (Flag) {\r
261 case 1:\r
63d55bb9
LG
262 //\r
263 // Convert Buffer to Hex String in reverse order\r
264 //\r
265 TemBuffer = ((UINT8 *) Buffer);\r
266 for (Index = 0; Index < BufferLen; Index ++, TemBuffer ++) {\r
267 TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
268 }\r
813acf3a 269 break;\r
270 case 2:\r
63d55bb9
LG
271 //\r
272 // Check buffer is enough\r
273 //\r
274 TemName = (CHAR16 *) Buffer;\r
84f9a9ec 275 ASSERT ((BufferLen * 2 + 1) >= (StrLen (TemName) * 4 + 1));\r
63d55bb9
LG
276 //\r
277 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
278 //\r
279 for (; *TemName != L'\0'; TemName++) {\r
280 TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
281 }\r
813acf3a 282 break;\r
283 case 3:\r
813acf3a 284 //\r
63d55bb9 285 // Convert Buffer to Hex String\r
813acf3a 286 //\r
63d55bb9
LG
287 TemBuffer = ((UINT8 *) Buffer) + BufferLen - 1;\r
288 for (Index = 0; Index < BufferLen; Index ++, TemBuffer --) {\r
289 TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
290 }\r
813acf3a 291 break;\r
292 default:\r
293 break;\r
294 }\r
93e3992d 295\r
63d55bb9
LG
296 //\r
297 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r
298 //\r
5ad66ec6 299 StrCatS (Str, Length, L"&"); \r
84f9a9ec 300 HiiToLower (Str);\r
93e3992d 301\r
302 *SubStr = Str;\r
303}\r
304\r
305\r
306/**\r
307 Retrieve the <ConfigBody> from String then output it.\r
308\r
e90b081a 309 This is a internal function.\r
310\r
93e3992d 311 @param String A sub string of a configuration string in\r
312 <MultiConfigAltResp> format.\r
313 @param ConfigBody Points to the output string. It's caller's\r
314 responsibility to free this buffer.\r
315\r
316 @retval EFI_INVALID_PARAMETER There is no form package in current hii database.\r
317 @retval EFI_OUT_OF_RESOURCES Not enough memory to finish this operation.\r
318 @retval EFI_SUCCESS All existing storage is exported.\r
319\r
320**/\r
93e3992d 321EFI_STATUS\r
322OutputConfigBody (\r
323 IN EFI_STRING String,\r
324 OUT EFI_STRING *ConfigBody\r
325 )\r
326{\r
327 EFI_STRING TmpPtr;\r
328 EFI_STRING Result;\r
329 UINTN Length;\r
330\r
331 if (String == NULL || ConfigBody == NULL) {\r
332 return EFI_INVALID_PARAMETER;\r
333 }\r
84f9a9ec
LG
334 \r
335 //\r
336 // The setting information should start OFFSET, not ALTCFG.\r
337 //\r
338 if (StrnCmp (String, L"&ALTCFG=", StrLen (L"&ALTCFG=")) == 0) {\r
339 return EFI_INVALID_PARAMETER;\r
340 }\r
93e3992d 341\r
342 TmpPtr = StrStr (String, L"GUID=");\r
343 if (TmpPtr == NULL) {\r
344 //\r
345 // It is the last <ConfigResp> of the incoming configuration string.\r
346 //\r
347 Result = AllocateCopyPool (StrSize (String), String);\r
348 if (Result == NULL) {\r
349 return EFI_OUT_OF_RESOURCES;\r
350 } else {\r
351 *ConfigBody = Result;\r
352 return EFI_SUCCESS;\r
353 }\r
354 }\r
355\r
356 Length = TmpPtr - String;\r
7248790e
ED
357 if (Length == 0) {\r
358 return EFI_NOT_FOUND;\r
359 }\r
93e3992d 360 Result = AllocateCopyPool (Length * sizeof (CHAR16), String);\r
361 if (Result == NULL) {\r
362 return EFI_OUT_OF_RESOURCES;\r
363 }\r
364\r
365 *(Result + Length - 1) = 0;\r
366 *ConfigBody = Result;\r
367 return EFI_SUCCESS;\r
93e3992d 368}\r
369\r
93e3992d 370/**\r
371 Append a string to a multi-string format.\r
372\r
e90b081a 373 This is a internal function.\r
374\r
93e3992d 375 @param MultiString String in <MultiConfigRequest>,\r
376 <MultiConfigAltResp>, or <MultiConfigResp>. On\r
377 input, the buffer length of this string is\r
378 MAX_STRING_LENGTH. On output, the buffer length\r
379 might be updated.\r
380 @param AppendString NULL-terminated Unicode string.\r
381\r
382 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.\r
383 @retval EFI_SUCCESS AppendString is append to the end of MultiString\r
384\r
385**/\r
93e3992d 386EFI_STATUS\r
387AppendToMultiString (\r
388 IN OUT EFI_STRING *MultiString,\r
389 IN EFI_STRING AppendString\r
390 )\r
391{\r
392 UINTN AppendStringSize;\r
393 UINTN MultiStringSize;\r
5ad66ec6 394 UINTN MaxLen;\r
93e3992d 395\r
396 if (MultiString == NULL || *MultiString == NULL || AppendString == NULL) {\r
397 return EFI_INVALID_PARAMETER;\r
398 }\r
84f9a9ec
LG
399\r
400 AppendStringSize = StrSize (AppendString);\r
401 MultiStringSize = StrSize (*MultiString);\r
5ad66ec6 402 MaxLen = MAX_STRING_LENGTH / sizeof (CHAR16);\r
84f9a9ec
LG
403\r
404 //\r
405 // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.\r
406 //\r
407 if (MultiStringSize + AppendStringSize > MAX_STRING_LENGTH ||\r
408 MultiStringSize > MAX_STRING_LENGTH) {\r
409 *MultiString = (EFI_STRING) ReallocatePool (\r
410 MultiStringSize,\r
411 MultiStringSize + AppendStringSize,\r
412 (VOID *) (*MultiString)\r
413 );\r
5ad66ec6 414 MaxLen = (MultiStringSize + AppendStringSize) / sizeof (CHAR16);\r
84f9a9ec
LG
415 ASSERT (*MultiString != NULL);\r
416 }\r
417 //\r
418 // Append the incoming string\r
419 //\r
5ad66ec6 420 StrCatS (*MultiString, MaxLen, AppendString);\r
84f9a9ec
LG
421\r
422 return EFI_SUCCESS;\r
423}\r
424\r
425\r
426/**\r
427 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET\r
428 or WIDTH or VALUE.\r
429 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>\r
430\r
431 This is a internal function.\r
432\r
433 @param StringPtr String in <BlockConfig> format and points to the\r
434 first character of <Number>.\r
435 @param Number The output value. Caller takes the responsibility\r
436 to free memory.\r
437 @param Len Length of the <Number>, in characters.\r
438\r
439 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary\r
440 structures.\r
441 @retval EFI_SUCCESS Value of <Number> is outputted in Number\r
442 successfully.\r
443\r
444**/\r
445EFI_STATUS\r
446GetValueOfNumber (\r
447 IN EFI_STRING StringPtr,\r
448 OUT UINT8 **Number,\r
449 OUT UINTN *Len\r
450 )\r
451{\r
452 EFI_STRING TmpPtr;\r
453 UINTN Length;\r
454 EFI_STRING Str;\r
455 UINT8 *Buf;\r
456 EFI_STATUS Status;\r
457 UINT8 DigitUint8;\r
458 UINTN Index;\r
459 CHAR16 TemStr[2];\r
460\r
3a530010
ED
461 if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) {\r
462 return EFI_INVALID_PARAMETER;\r
463 }\r
84f9a9ec
LG
464\r
465 Buf = NULL;\r
466\r
467 TmpPtr = StringPtr;\r
468 while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
469 StringPtr++;\r
470 }\r
471 *Len = StringPtr - TmpPtr;\r
472 Length = *Len + 1;\r
473\r
474 Str = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));\r
475 if (Str == NULL) {\r
476 Status = EFI_OUT_OF_RESOURCES;\r
477 goto Exit;\r
478 }\r
479 CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));\r
480 *(Str + *Len) = L'\0';\r
481\r
482 Length = (Length + 1) / 2;\r
483 Buf = (UINT8 *) AllocateZeroPool (Length);\r
484 if (Buf == NULL) {\r
485 Status = EFI_OUT_OF_RESOURCES;\r
486 goto Exit;\r
487 }\r
488 \r
489 Length = *Len;\r
490 ZeroMem (TemStr, sizeof (TemStr));\r
491 for (Index = 0; Index < Length; Index ++) {\r
492 TemStr[0] = Str[Length - Index - 1];\r
493 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
494 if ((Index & 1) == 0) {\r
495 Buf [Index/2] = DigitUint8;\r
496 } else {\r
497 Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);\r
498 }\r
499 }\r
500\r
501 *Number = Buf;\r
502 Status = EFI_SUCCESS;\r
503\r
504Exit:\r
505 if (Str != NULL) {\r
506 FreePool (Str);\r
507 }\r
508\r
509 return Status;\r
510}\r
511\r
74e8963c
DB
512/**\r
513 To find the BlockName in the string with same value.\r
514\r
515 @param String Pointer to a Null-terminated Unicode string.\r
516 @param BlockName Pointer to a Null-terminated Unicode string to search for.\r
517 @param Buffer Pointer to the value correspond to the BlockName.\r
518 @param Found The Block whether has been found.\r
519 @param BufferLen The length of the buffer.\r
520\r
521 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures.\r
522 @retval EFI_SUCCESS The function finishes successfully.\r
523\r
524**/\r
525EFI_STATUS\r
526FindSameBlockElement(\r
527 IN EFI_STRING String,\r
528 IN EFI_STRING BlockName,\r
529 IN UINT8 *Buffer,\r
530 OUT BOOLEAN *Found,\r
531 IN UINTN BufferLen\r
532 )\r
533{\r
534 EFI_STRING BlockPtr;\r
535 UINTN Length;\r
536 UINT8 *TempBuffer;\r
537 EFI_STATUS Status;\r
538\r
539 TempBuffer = NULL;\r
540 *Found = FALSE;\r
541 BlockPtr = StrStr (String, BlockName);\r
542\r
543 while (BlockPtr != NULL) {\r
544 BlockPtr += StrLen (BlockName);\r
545 Status = GetValueOfNumber (BlockPtr, &TempBuffer, &Length);\r
546 if (EFI_ERROR (Status)) {\r
547 return Status;\r
548 }\r
549 ASSERT (TempBuffer != NULL);\r
550 if ((BufferLen == Length) && (0 == CompareMem (Buffer, TempBuffer, Length))) {\r
551 *Found = TRUE;\r
a0b0cd73
DB
552 FreePool (TempBuffer);\r
553 TempBuffer = NULL;\r
74e8963c
DB
554 return EFI_SUCCESS;\r
555 } else {\r
556 FreePool (TempBuffer);\r
557 TempBuffer = NULL;\r
558 BlockPtr = StrStr (BlockPtr + 1, BlockName);\r
559 }\r
560 }\r
561 return EFI_SUCCESS;\r
562}\r
563\r
564/**\r
565 Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>\r
566 in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.\r
567\r
568 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in\r
569 <MultiConfigAltResp> format. The default value\r
570 string may contain more than one ConfigAltResp\r
571 string for the different varstore buffer.\r
572 @param ConfigAltResp Pointer to a null-terminated Unicode string in\r
573 <ConfigAltResp> format.\r
574 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.\r
575 @param ConfigAltRespChanged Whether the ConfigAltResp has been changed.\r
576\r
577 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures.\r
578 @retval EFI_SUCCESS The function finishes successfully.\r
579\r
580**/\r
581EFI_STATUS\r
582CompareBlockElementDefault (\r
583 IN EFI_STRING DefaultAltCfgResp,\r
584 IN OUT EFI_STRING *ConfigAltResp,\r
585 IN EFI_STRING AltConfigHdr,\r
586 IN OUT BOOLEAN *ConfigAltRespChanged\r
587)\r
588{\r
589 EFI_STATUS Status;\r
590 EFI_STRING BlockPtr;\r
591 EFI_STRING BlockPtrStart;\r
592 EFI_STRING StringPtr;\r
593 EFI_STRING AppendString;\r
594 EFI_STRING AltConfigHdrPtr;\r
595 UINT8 *TempBuffer;\r
596 UINTN OffsetLength;\r
597 UINTN AppendSize;\r
598 UINTN TotalSize;\r
599 BOOLEAN FoundOffset;\r
600\r
601 AppendString = NULL;\r
602 TempBuffer = NULL;\r
603 //\r
604 // Make BlockPtr point to the first <BlockConfig> with AltConfigHdr in DefaultAltCfgResp.\r
605 //\r
606 AltConfigHdrPtr = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
607 ASSERT (AltConfigHdrPtr != NULL);\r
608 BlockPtr = StrStr (AltConfigHdrPtr, L"&OFFSET=");\r
609 //\r
610 // Make StringPtr point to the AltConfigHdr in ConfigAltResp.\r
611 //\r
612 StringPtr = StrStr (*ConfigAltResp, AltConfigHdr);\r
613 ASSERT (StringPtr != NULL);\r
614\r
615 while (BlockPtr != NULL) {\r
616 //\r
617 // Find the "&OFFSET=<Number>" block and get the value of the Number with AltConfigHdr in DefaultAltCfgResp.\r
618 //\r
619 BlockPtrStart = BlockPtr;\r
620 BlockPtr += StrLen (L"&OFFSET=");\r
621 Status = GetValueOfNumber (BlockPtr, &TempBuffer, &OffsetLength);\r
622 if (EFI_ERROR (Status)) {\r
623 Status = EFI_OUT_OF_RESOURCES;\r
624 goto Exit;\r
625 }\r
626 //\r
627 // To find the same "&OFFSET=<Number>" block in ConfigAltResp.\r
628 //\r
629 Status = FindSameBlockElement (StringPtr, L"&OFFSET=", TempBuffer, &FoundOffset, OffsetLength);\r
630 if (TempBuffer != NULL) {\r
631 FreePool (TempBuffer);\r
632 TempBuffer = NULL;\r
633 }\r
634 if (EFI_ERROR (Status)) {\r
635 Status = EFI_OUT_OF_RESOURCES;\r
636 goto Exit;\r
637 }\r
638 if (!FoundOffset) {\r
639 //\r
640 // Don't find the same "&OFFSET=<Number>" block in ConfigAltResp.\r
641 // Calculate the size of <BlockConfig>.\r
642 // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number>.\r
643 //\r
644 BlockPtr = StrStr (BlockPtr + 1, L"&OFFSET=");\r
645 if (BlockPtr != NULL) {\r
646 AppendSize = (BlockPtr - BlockPtrStart) * sizeof (CHAR16);\r
647 } else {\r
648 AppendSize = StrSize (BlockPtrStart);\r
649 }\r
650 //\r
651 // Copy the <BlockConfig> to AppendString.\r
652 //\r
653 if (AppendString == NULL) {\r
654 AppendString = (EFI_STRING) AllocateZeroPool (AppendSize + sizeof (CHAR16));\r
655 StrnCatS (AppendString, AppendSize / sizeof (CHAR16) + 1, BlockPtrStart, AppendSize / sizeof (CHAR16));\r
656 } else {\r
657 TotalSize = StrSize (AppendString) + AppendSize + sizeof (CHAR16);\r
658 AppendString = (EFI_STRING) ReallocatePool (\r
659 StrSize (AppendString),\r
660 TotalSize,\r
661 AppendString\r
662 );\r
663 if (AppendString == NULL) {\r
664 Status = EFI_OUT_OF_RESOURCES;\r
665 goto Exit;\r
666 }\r
667 StrnCatS (AppendString, TotalSize / sizeof (CHAR16), BlockPtrStart, AppendSize / sizeof (CHAR16));\r
668 }\r
669 } else {\r
670 //\r
671 // To find next "&OFFSET=<Number>" block with AltConfigHdr in DefaultAltCfgResp.\r
672 //\r
673 BlockPtr = StrStr (BlockPtr + 1, L"&OFFSET=");\r
674 }\r
675 }\r
676\r
677 if (AppendString != NULL) {\r
678 //\r
679 // Reallocate ConfigAltResp to copy the AppendString.\r
680 //\r
681 TotalSize = StrSize (*ConfigAltResp) + StrSize (AppendString) + sizeof (CHAR16);\r
682 *ConfigAltResp = (EFI_STRING) ReallocatePool (\r
683 StrSize (*ConfigAltResp),\r
684 TotalSize,\r
685 *ConfigAltResp\r
686 );\r
687 if (*ConfigAltResp == NULL) {\r
688 Status = EFI_OUT_OF_RESOURCES;\r
689 goto Exit;\r
690 }\r
691 StrCatS (*ConfigAltResp, TotalSize / sizeof (CHAR16), AppendString);\r
692 *ConfigAltRespChanged = TRUE;\r
693 }\r
694\r
695 Status = EFI_SUCCESS;\r
696\r
697Exit:\r
698 if (AppendString != NULL) {\r
699 FreePool (AppendString);\r
700 }\r
701\r
702 return Status;\r
703}\r
704\r
705/**\r
706 Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>\r
707 in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.\r
708\r
709 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in\r
710 <MultiConfigAltResp> format. The default value\r
711 string may contain more than one ConfigAltResp\r
712 string for the different varstore buffer.\r
713 @param ConfigAltResp Pointer to a null-terminated Unicode string in\r
714 <ConfigAltResp> format.\r
715 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.\r
716 @param ConfigAltRespChanged Whether the ConfigAltResp has been changed.\r
717\r
718 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures.\r
719 @retval EFI_SUCCESS The function finishes successfully.\r
720\r
721**/\r
722EFI_STATUS\r
723CompareNameElementDefault (\r
724 IN EFI_STRING DefaultAltCfgResp,\r
725 IN OUT EFI_STRING *ConfigAltResp,\r
726 IN EFI_STRING AltConfigHdr,\r
727 IN OUT BOOLEAN *ConfigAltRespChanged\r
728)\r
729{\r
730 EFI_STATUS Status;\r
731 EFI_STRING NvConfigPtr;\r
732 EFI_STRING NvConfigStart;\r
733 EFI_STRING NvConfigValuePtr;\r
734 EFI_STRING StringPtr;\r
735 EFI_STRING NvConfigExist;\r
736 EFI_STRING AppendString;\r
737 CHAR16 TempChar;\r
738 UINTN AppendSize;\r
739 UINTN TotalSize;\r
740\r
741 AppendString = NULL;\r
742 NvConfigExist = NULL;\r
743 //\r
744 // Make NvConfigPtr point to the first <NvConfig> with AltConfigHdr in DefaultAltCfgResp.\r
745 //\r
746 NvConfigPtr = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
747 ASSERT (NvConfigPtr != NULL);\r
748 NvConfigPtr = StrStr (NvConfigPtr + StrLen(AltConfigHdr),L"&");\r
749 //\r
750 // Make StringPtr point to the first <NvConfig> with AltConfigHdr in ConfigAltResp.\r
751 //\r
752 StringPtr = StrStr (*ConfigAltResp, AltConfigHdr);\r
753 ASSERT (StringPtr != NULL);\r
754 StringPtr = StrStr (StringPtr + StrLen (AltConfigHdr), L"&");\r
755 ASSERT (StringPtr != NULL);\r
756\r
757 while (NvConfigPtr != NULL) {\r
758 //\r
759 // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number>.\r
760 // Get the <Label> with AltConfigHdr in DefaultAltCfgResp.\r
761 //\r
762 NvConfigStart = NvConfigPtr;\r
763 NvConfigValuePtr = StrStr (NvConfigPtr + 1, L"=");\r
764 ASSERT (NvConfigValuePtr != NULL);\r
765 TempChar = *NvConfigValuePtr;\r
766 *NvConfigValuePtr = L'\0';\r
767 //\r
768 // Get the <Label> with AltConfigHdr in ConfigAltResp.\r
769 //\r
770 NvConfigExist = StrStr (StringPtr, NvConfigPtr);\r
771 if (NvConfigExist == NULL) {\r
772 //\r
773 // Don't find same <Label> in ConfigAltResp.\r
774 // Calculate the size of <NvConfig>.\r
775 //\r
776 *NvConfigValuePtr = TempChar;\r
777 NvConfigPtr = StrStr (NvConfigPtr + 1, L"&");\r
778 if (NvConfigPtr != NULL) {\r
779 AppendSize = (NvConfigPtr - NvConfigStart) * sizeof (CHAR16);\r
780 } else {\r
781 AppendSize = StrSize (NvConfigStart);\r
782 }\r
783 //\r
784 // Copy the <NvConfig> to AppendString.\r
785 //\r
786 if (AppendString == NULL) {\r
787 AppendString = (EFI_STRING) AllocateZeroPool (AppendSize + sizeof (CHAR16));\r
788 StrnCatS (AppendString, AppendSize / sizeof (CHAR16) + 1, NvConfigStart, AppendSize / sizeof (CHAR16));\r
789 } else {\r
790 TotalSize = StrSize (AppendString) + AppendSize + sizeof (CHAR16);\r
791 AppendString = (EFI_STRING) ReallocatePool (\r
792 StrSize (AppendString),\r
793 TotalSize,\r
794 AppendString\r
795 );\r
796 if (AppendString == NULL) {\r
797 Status = EFI_OUT_OF_RESOURCES;\r
798 goto Exit;\r
799 }\r
800 StrnCatS (AppendString, TotalSize / sizeof (CHAR16), NvConfigStart, AppendSize / sizeof (CHAR16));\r
801 }\r
802 } else {\r
803 //\r
804 // To find next <Label> in DefaultAltCfgResp.\r
805 //\r
806 *NvConfigValuePtr = TempChar;\r
807 NvConfigPtr = StrStr (NvConfigPtr + 1, L"&");\r
808 }\r
809 }\r
810 if (AppendString != NULL) {\r
811 //\r
812 // Reallocate ConfigAltResp to copy the AppendString.\r
813 //\r
814 TotalSize = StrSize (*ConfigAltResp) + StrSize (AppendString) + sizeof (CHAR16);\r
815 *ConfigAltResp = (EFI_STRING) ReallocatePool (\r
816 StrSize (*ConfigAltResp),\r
817 StrSize (*ConfigAltResp) + StrSize (AppendString) + sizeof (CHAR16),\r
818 *ConfigAltResp\r
819 );\r
820 if (*ConfigAltResp == NULL) {\r
821 Status = EFI_OUT_OF_RESOURCES;\r
822 goto Exit;\r
823 }\r
824 StrCatS (*ConfigAltResp, TotalSize / sizeof (CHAR16), AppendString);\r
825 *ConfigAltRespChanged = TRUE;\r
826 }\r
827 Status = EFI_SUCCESS;\r
828\r
829Exit:\r
830 if (AppendString != NULL) {\r
831 FreePool (AppendString);\r
832 }\r
833 return Status;\r
834}\r
835\r
836/**\r
837 Compare the <AltResp> in AltCfgResp and DefaultAltCfgResp, if the <AltResp>\r
838 in DefaultAltCfgResp but not in AltCfgResp,add it to the AltCfgResp.\r
839\r
840 @param AltCfgResp Pointer to a null-terminated Unicode string in\r
841 <ConfigAltResp> format.\r
842 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in\r
843 <MultiConfigAltResp> format. The default value\r
844 string may contain more than one ConfigAltResp\r
845 string for the different varstore buffer.\r
846 @param AltConfigHdr Pointer to a Unicode string in <AltConfigHdr> format.\r
847\r
848 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary\r
849 structures.\r
850 @retval EFI_SUCCESS The function finishes successfully.\r
851\r
852**/\r
853EFI_STATUS\r
854CompareAndMergeDefaultString (\r
855 IN OUT EFI_STRING *AltCfgResp,\r
856 IN EFI_STRING DefaultAltCfgResp,\r
857 IN EFI_STRING AltConfigHdr\r
858 )\r
859{\r
860 EFI_STATUS Status;\r
861 EFI_STRING AltCfgRespBackup;\r
862 EFI_STRING AltConfigHdrPtr;\r
863 EFI_STRING AltConfigHdrPtrNext;\r
864 EFI_STRING ConfigAltResp;\r
865 EFI_STRING StringPtr;\r
866 EFI_STRING StringPtrNext;\r
867 EFI_STRING BlockPtr;\r
868 UINTN ReallocateSize;\r
869 CHAR16 TempChar;\r
870 CHAR16 TempCharA;\r
871 BOOLEAN ConfigAltRespChanged;\r
872\r
873 Status = EFI_OUT_OF_RESOURCES;\r
874 BlockPtr = NULL;\r
875 AltConfigHdrPtrNext = NULL;\r
876 StringPtrNext = NULL;\r
877 ConfigAltResp = NULL;\r
878 AltCfgRespBackup = NULL;\r
21d4f0d5
DB
879 TempChar = L'\0';\r
880 TempCharA = L'\0';\r
74e8963c
DB
881 ConfigAltRespChanged = FALSE;\r
882\r
883 //\r
884 //To find the <AltResp> with AltConfigHdr in DefaultAltCfgResp, ignore other <AltResp> which follow it.\r
885 //\r
886 AltConfigHdrPtr = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
887 ASSERT (AltConfigHdrPtr != NULL);\r
888 AltConfigHdrPtrNext = StrStr (AltConfigHdrPtr + 1, L"&GUID");\r
889 if (AltConfigHdrPtrNext != NULL) {\r
890 TempChar = *AltConfigHdrPtrNext;\r
891 *AltConfigHdrPtrNext = L'\0';\r
892 }\r
893 //\r
894 // To find the <AltResp> with AltConfigHdr in AltCfgResp, ignore other <AltResp> which follow it.\r
895 //\r
896 StringPtr = StrStr (*AltCfgResp, AltConfigHdr);\r
897 StringPtrNext = StrStr (StringPtr + 1, L"&GUID");\r
898 if (StringPtrNext != NULL) {\r
899 TempCharA = *StringPtrNext;\r
900 *StringPtrNext = L'\0';\r
901 }\r
902 //\r
903 // Copy the content of <ConfigAltResp> which contain current AltConfigHdr in AltCfgResp.\r
904 //\r
905 ConfigAltResp = AllocateCopyPool (StrSize (*AltCfgResp), *AltCfgResp);\r
906 if (ConfigAltResp == NULL) {\r
907 goto Exit;\r
908 }\r
909 //\r
910 // To find the <ConfigBody> with AltConfigHdr in DefaultAltCfgResp.\r
911 //\r
912 BlockPtr = StrStr (AltConfigHdrPtr, L"&OFFSET=");\r
913 if (BlockPtr != NULL) {\r
914 //\r
915 // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number> style.\r
916 // Call function CompareBlockElementDefault to compare the <BlockConfig> in DefaultAltCfgResp and ConfigAltResp.\r
917 // The ConfigAltResp which may contain the new <BlockConfig> get from DefaultAltCfgResp.\r
918 //\r
919 Status = CompareBlockElementDefault (DefaultAltCfgResp, &ConfigAltResp, AltConfigHdr, &ConfigAltRespChanged);\r
920 if (EFI_ERROR(Status)) {\r
921 goto Exit;\r
922 }\r
923 } else {\r
924 //\r
925 // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number> style.\r
926 // Call function CompareNameElementDefault to compare the <NvConfig> in DefaultAltCfgResp and ConfigAltResp.\r
927 // The ConfigAltResp which may contain the new <NvConfig> get from DefaultAltCfgResp.\r
928 //\r
929 Status = CompareNameElementDefault (DefaultAltCfgResp, &ConfigAltResp, AltConfigHdr, &ConfigAltRespChanged);\r
930 if (EFI_ERROR(Status)) {\r
931 goto Exit;\r
932 }\r
933 }\r
934 //\r
935 // Restore the AltCfgResp.\r
936 //\r
937 if (StringPtrNext != NULL) {\r
938 *StringPtrNext = TempCharA;\r
939 }\r
940\r
941 //\r
942 // If the ConfigAltResp has no change,no need to update the content in AltCfgResp.\r
943 //\r
e626a36c 944 if (!ConfigAltRespChanged) {\r
74e8963c
DB
945 Status = EFI_SUCCESS;\r
946 goto Exit;\r
947 }\r
948 //\r
949 // ConfigAltResp has been changed, need to update the content in AltCfgResp.\r
950 //\r
951 if (StringPtrNext != NULL) {\r
952 ReallocateSize = StrSize (ConfigAltResp) + StrSize (StringPtrNext) + sizeof (CHAR16);\r
953 } else {\r
954 ReallocateSize = StrSize (ConfigAltResp) + sizeof (CHAR16);\r
955 }\r
956\r
957 AltCfgRespBackup = (EFI_STRING) AllocateZeroPool (ReallocateSize);\r
958 if (AltCfgRespBackup == NULL) {\r
959 goto Exit;\r
960 }\r
961\r
962 StrCatS (AltCfgRespBackup, ReallocateSize / sizeof (CHAR16), ConfigAltResp);\r
963 if (StringPtrNext != NULL) {\r
964 StrCatS (AltCfgRespBackup, ReallocateSize / sizeof (CHAR16), StringPtrNext);\r
965 }\r
966\r
967 FreePool (*AltCfgResp);\r
968 *AltCfgResp = AltCfgRespBackup;\r
969\r
970 Status = EFI_SUCCESS;\r
971\r
972Exit:\r
973 if (ConfigAltResp != NULL) {\r
974 FreePool(ConfigAltResp);\r
975 }\r
976 //\r
977 // Restore the DefaultAltCfgResp.\r
978 //\r
979 if ( AltConfigHdrPtrNext != NULL) {\r
980 *AltConfigHdrPtrNext = TempChar;\r
981 AltConfigHdrPtrNext = NULL;\r
982 }\r
983\r
984 return Status;\r
985}\r
986\r
84f9a9ec
LG
987/**\r
988 This function merges DefaultAltCfgResp string into AltCfgResp string for\r
989 the missing AltCfgId in AltCfgResq.\r
990\r
991 @param AltCfgResp Pointer to a null-terminated Unicode string in\r
992 <ConfigAltResp> format. The default value string \r
993 will be merged into it. \r
994 @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in\r
995 <MultiConfigAltResp> format. The default value \r
996 string may contain more than one ConfigAltResp\r
997 string for the different varstore buffer.\r
998\r
999 @retval EFI_SUCCESS The merged string returns.\r
1000 @retval EFI_INVALID_PARAMETER *AltCfgResp is to NULL.\r
1001**/\r
1002EFI_STATUS\r
1003EFIAPI\r
1004MergeDefaultString (\r
1005 IN OUT EFI_STRING *AltCfgResp,\r
1006 IN EFI_STRING DefaultAltCfgResp\r
1007 )\r
1008{\r
1009 EFI_STRING StringPtrDefault;\r
1010 EFI_STRING StringPtrEnd;\r
1011 CHAR16 TempChar;\r
1012 EFI_STRING StringPtr;\r
1013 EFI_STRING AltConfigHdr;\r
1014 UINTN HeaderLength;\r
1015 UINTN SizeAltCfgResp;\r
5ad66ec6
DB
1016 UINTN MaxLen;\r
1017 UINTN TotalSize;\r
84f9a9ec
LG
1018 \r
1019 if (*AltCfgResp == NULL) {\r
1020 return EFI_INVALID_PARAMETER;\r
1021 }\r
1022 \r
1023 //\r
1024 // Get the requestr ConfigHdr\r
1025 //\r
1026 SizeAltCfgResp = 0;\r
1027 StringPtr = *AltCfgResp;\r
1028 \r
1029 //\r
1030 // Find <ConfigHdr> GUID=...&NAME=...&PATH=...\r
1031 //\r
1032 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
1033 return EFI_INVALID_PARAMETER;\r
1034 }\r
1035 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) {\r
1036 StringPtr++;\r
1037 }\r
1038 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) {\r
1039 StringPtr++;\r
1040 }\r
1041 if (*StringPtr == L'\0') {\r
1042 return EFI_INVALID_PARAMETER;\r
1043 }\r
1044 StringPtr += StrLen (L"&PATH=");\r
1045 while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
1046 StringPtr ++;\r
1047 }\r
1048 HeaderLength = StringPtr - *AltCfgResp;\r
1049\r
1050 //\r
1051 // Construct AltConfigHdr string "&<ConfigHdr>&ALTCFG=XXXX\0"\r
1052 // |1| StrLen (ConfigHdr) | 8 | 4 | 1 |\r
1053 //\r
5ad66ec6
DB
1054 MaxLen = 1 + HeaderLength + 8 + 4 + 1;\r
1055 AltConfigHdr = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
84f9a9ec
LG
1056 if (AltConfigHdr == NULL) {\r
1057 return EFI_OUT_OF_RESOURCES;\r
1058 }\r
5ad66ec6
DB
1059 StrCpyS (AltConfigHdr, MaxLen, L"&");\r
1060 StrnCatS (AltConfigHdr, MaxLen, *AltCfgResp, HeaderLength);\r
1061 StrCatS (AltConfigHdr, MaxLen, L"&ALTCFG=");\r
84f9a9ec
LG
1062 HeaderLength = StrLen (AltConfigHdr);\r
1063 \r
1064 StringPtrDefault = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
1065 while (StringPtrDefault != NULL) {\r
1066 //\r
1067 // Get AltCfg Name\r
1068 //\r
5ad66ec6 1069 StrnCatS (AltConfigHdr, MaxLen, StringPtrDefault + HeaderLength, 4);\r
84f9a9ec
LG
1070 StringPtr = StrStr (*AltCfgResp, AltConfigHdr); \r
1071 \r
1072 //\r
1073 // Append the found default value string to the input AltCfgResp\r
1074 // \r
1075 if (StringPtr == NULL) {\r
1076 StringPtrEnd = StrStr (StringPtrDefault + 1, L"&GUID");\r
1077 SizeAltCfgResp = StrSize (*AltCfgResp);\r
1078 if (StringPtrEnd == NULL) {\r
1079 //\r
1080 // No more default string is found.\r
1081 //\r
9b72af13 1082 TotalSize = SizeAltCfgResp + StrSize (StringPtrDefault);\r
84f9a9ec
LG
1083 *AltCfgResp = (EFI_STRING) ReallocatePool (\r
1084 SizeAltCfgResp,\r
5ad66ec6 1085 TotalSize,\r
84f9a9ec
LG
1086 (VOID *) (*AltCfgResp)\r
1087 );\r
8567300a
LG
1088 if (*AltCfgResp == NULL) {\r
1089 FreePool (AltConfigHdr);\r
1090 return EFI_OUT_OF_RESOURCES;\r
1091 }\r
5ad66ec6 1092 StrCatS (*AltCfgResp, TotalSize / sizeof (CHAR16), StringPtrDefault);\r
84f9a9ec
LG
1093 break;\r
1094 } else {\r
1095 TempChar = *StringPtrEnd;\r
1096 *StringPtrEnd = L'\0';\r
9b72af13 1097 TotalSize = SizeAltCfgResp + StrSize (StringPtrDefault);\r
84f9a9ec
LG
1098 *AltCfgResp = (EFI_STRING) ReallocatePool (\r
1099 SizeAltCfgResp,\r
5ad66ec6 1100 TotalSize,\r
84f9a9ec
LG
1101 (VOID *) (*AltCfgResp)\r
1102 );\r
6e3f5b2a
LG
1103 if (*AltCfgResp == NULL) {\r
1104 FreePool (AltConfigHdr);\r
1105 return EFI_OUT_OF_RESOURCES;\r
1106 }\r
5ad66ec6 1107 StrCatS (*AltCfgResp, TotalSize / sizeof (CHAR16), StringPtrDefault);\r
84f9a9ec
LG
1108 *StringPtrEnd = TempChar;\r
1109 }\r
74e8963c
DB
1110 } else {\r
1111 //\r
1112 // The AltCfgResp contains <AltCfgResp>.\r
1113 // If the <ConfigElement> in <AltCfgResp> in the DefaultAltCfgResp but not in the\r
1114 // related <AltCfgResp> in AltCfgResp, merge it to AltCfgResp. else no need to merge.\r
1115 //\r
1116 CompareAndMergeDefaultString (AltCfgResp, DefaultAltCfgResp, AltConfigHdr);\r
84f9a9ec
LG
1117 }\r
1118 \r
1119 //\r
1120 // Find next AltCfg String\r
8567300a 1121 //\r
84f9a9ec 1122 *(AltConfigHdr + HeaderLength) = L'\0';\r
82e8c138 1123 StringPtrDefault = StrStr (StringPtrDefault + 1, AltConfigHdr);\r
84f9a9ec 1124 }\r
8567300a
LG
1125 \r
1126 FreePool (AltConfigHdr);\r
84f9a9ec
LG
1127 return EFI_SUCCESS; \r
1128}\r
1129\r
84f9a9ec
LG
1130/**\r
1131 This function inserts new DefaultValueData into the BlockData DefaultValue array.\r
1132\r
1133 @param BlockData The BlockData is updated to add new default value.\r
1134 @param DefaultValueData The DefaultValue is added.\r
1135\r
1136**/\r
1137VOID\r
1138InsertDefaultValue (\r
1139 IN IFR_BLOCK_DATA *BlockData,\r
1140 IN IFR_DEFAULT_DATA *DefaultValueData\r
1141 )\r
1142{\r
1143 LIST_ENTRY *Link;\r
82e8c138
ED
1144 IFR_DEFAULT_DATA *DefaultValueArray; \r
1145 LIST_ENTRY *DefaultLink;\r
1146 \r
1147 DefaultLink = &BlockData->DefaultValueEntry;\r
84f9a9ec 1148\r
82e8c138 1149 for (Link = DefaultLink->ForwardLink; Link != DefaultLink; Link = Link->ForwardLink) {\r
84f9a9ec
LG
1150 DefaultValueArray = BASE_CR (Link, IFR_DEFAULT_DATA, Entry);\r
1151 if (DefaultValueArray->DefaultId == DefaultValueData->DefaultId) {\r
ef40f0f6
ED
1152 //\r
1153 // DEFAULT_VALUE_FROM_OPCODE has high priority, DEFAULT_VALUE_FROM_DEFAULT has low priority.\r
22f63ff6 1154 // When default types are DEFAULT_VALUE_FROM_OTHER_DEFAULT, the default value can be overrode.\r
ef40f0f6 1155 //\r
22f63ff6 1156 if ((DefaultValueData->Type > DefaultValueArray->Type) || (DefaultValueData->Type == DefaultValueArray->Type && DefaultValueData->Type == DefaultValueFromOtherDefault)) {\r
6e3f5b2a
LG
1157 //\r
1158 // Update the default value array in BlockData.\r
1159 //\r
e7fd76d1 1160 CopyMem (&DefaultValueArray->Value, &DefaultValueData->Value, sizeof (EFI_IFR_TYPE_VALUE));\r
ef40f0f6
ED
1161 DefaultValueArray->Type = DefaultValueData->Type;\r
1162 DefaultValueArray->Cleaned = DefaultValueData->Cleaned;\r
6e3f5b2a 1163 }\r
84f9a9ec 1164 return;\r
ef40f0f6 1165 } \r
84f9a9ec
LG
1166 }\r
1167\r
1168 //\r
1169 // Insert new default value data in tail.\r
1170 //\r
ef40f0f6
ED
1171 DefaultValueArray = AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r
1172 ASSERT (DefaultValueArray != NULL);\r
1173 CopyMem (DefaultValueArray, DefaultValueData, sizeof (IFR_DEFAULT_DATA));\r
1174 InsertTailList (Link, &DefaultValueArray->Entry);\r
84f9a9ec
LG
1175}\r
1176\r
1177/**\r
1178 This function inserts new BlockData into the block link\r
1179\r
82e8c138
ED
1180 @param BlockLink The list entry points to block array.\r
1181 @param BlockData The point to BlockData is added.\r
84f9a9ec
LG
1182 \r
1183**/\r
1184VOID\r
1185InsertBlockData (\r
1186 IN LIST_ENTRY *BlockLink,\r
1187 IN IFR_BLOCK_DATA **BlockData\r
1188 )\r
1189{\r
82e8c138
ED
1190 LIST_ENTRY *Link;\r
1191 IFR_BLOCK_DATA *BlockArray;\r
1192 IFR_BLOCK_DATA *BlockSingleData;\r
84f9a9ec
LG
1193\r
1194 BlockSingleData = *BlockData;\r
82e8c138
ED
1195\r
1196 if (BlockSingleData->Name != NULL) {\r
1197 InsertTailList (BlockLink, &BlockSingleData->Entry);\r
1198 return;\r
1199 }\r
1200\r
84f9a9ec
LG
1201 //\r
1202 // Insert block data in its Offset and Width order.\r
1203 //\r
1204 for (Link = BlockLink->ForwardLink; Link != BlockLink; Link = Link->ForwardLink) {\r
1205 BlockArray = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
1206 if (BlockArray->Offset == BlockSingleData->Offset) {\r
1207 if (BlockArray->Width > BlockSingleData->Width) {\r
1208 //\r
1209 // Insert this block data in the front of block array\r
1210 //\r
1211 InsertTailList (Link, &BlockSingleData->Entry);\r
1212 return;\r
1213 }\r
1214\r
1215 if (BlockArray->Width == BlockSingleData->Width) {\r
1216 //\r
1217 // The same block array has been added.\r
1218 //\r
82e8c138
ED
1219 if (BlockSingleData != BlockArray) {\r
1220 FreePool (BlockSingleData);\r
1221 *BlockData = BlockArray;\r
1222 }\r
84f9a9ec
LG
1223 return;\r
1224 }\r
1225 } else if (BlockArray->Offset > BlockSingleData->Offset) {\r
1226 //\r
1227 // Insert new block data in the front of block array \r
1228 //\r
1229 InsertTailList (Link, &BlockSingleData->Entry);\r
1230 return;\r
1231 }\r
1232 }\r
1233 \r
1234 //\r
1235 // Add new block data into the tail.\r
1236 //\r
82e8c138
ED
1237 InsertTailList (Link, &BlockSingleData->Entry); \r
1238}\r
1239\r
1240/**\r
1241 Retrieves a pointer to the a Null-terminated ASCII string containing the list \r
1242 of languages that an HII handle in the HII Database supports. The returned \r
1243 string is allocated using AllocatePool(). The caller is responsible for freeing\r
1244 the returned string using FreePool(). The format of the returned string follows\r
1245 the language format assumed the HII Database.\r
1246 \r
1247 If HiiHandle is NULL, then ASSERT().\r
1248\r
1249 @param[in] HiiHandle A handle that was previously registered in the HII Database.\r
1250\r
1251 @retval NULL HiiHandle is not registered in the HII database\r
1252 @retval NULL There are not enough resources available to retrieve the suported \r
1253 languages.\r
1254 @retval NULL The list of suported languages could not be retrieved.\r
1255 @retval Other A pointer to the Null-terminated ASCII string of supported languages.\r
1256\r
1257**/\r
1258CHAR8 *\r
1259GetSupportedLanguages (\r
1260 IN EFI_HII_HANDLE HiiHandle\r
1261 )\r
1262{\r
1263 EFI_STATUS Status;\r
1264 UINTN LanguageSize;\r
1265 CHAR8 TempSupportedLanguages;\r
1266 CHAR8 *SupportedLanguages;\r
1267\r
1268 ASSERT (HiiHandle != NULL);\r
1269\r
1270 //\r
1271 // Retrieve the size required for the supported languages buffer.\r
1272 //\r
1273 LanguageSize = 0;\r
1274 Status = mPrivate.HiiString.GetLanguages (&mPrivate.HiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);\r
1275\r
1276 //\r
1277 // If GetLanguages() returns EFI_SUCCESS for a zero size, \r
1278 // then there are no supported languages registered for HiiHandle. If GetLanguages() \r
1279 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present\r
1280 // in the HII Database\r
1281 //\r
1282 if (Status != EFI_BUFFER_TOO_SMALL) {\r
1283 //\r
1284 // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database\r
1285 //\r
1286 return NULL;\r
1287 }\r
1288\r
1289 //\r
1290 // Allocate the supported languages buffer.\r
1291 //\r
1292 SupportedLanguages = AllocateZeroPool (LanguageSize);\r
1293 if (SupportedLanguages == NULL) {\r
1294 //\r
1295 // Return NULL if allocation fails.\r
1296 //\r
1297 return NULL;\r
1298 }\r
1299\r
1300 //\r
1301 // Retrieve the supported languages string\r
1302 //\r
1303 Status = mPrivate.HiiString.GetLanguages (&mPrivate.HiiString, HiiHandle, SupportedLanguages, &LanguageSize);\r
1304 if (EFI_ERROR (Status)) {\r
1305 //\r
1306 // Free the buffer and return NULL if the supported languages can not be retrieved.\r
1307 //\r
1308 FreePool (SupportedLanguages);\r
1309 return NULL;\r
1310 }\r
1311\r
1312 //\r
1313 // Return the Null-terminated ASCII string of supported languages\r
1314 //\r
1315 return SupportedLanguages;\r
1316}\r
1317\r
1318/**\r
1319 Retrieves a string from a string package.\r
1320 \r
1321 If HiiHandle is NULL, then ASSERT().\r
1322 If StringId is 0, then ASSET.\r
1323\r
1324 @param[in] HiiHandle A handle that was previously registered in the HII Database.\r
1325 @param[in] StringId The identifier of the string to retrieved from the string \r
1326 package associated with HiiHandle.\r
1327\r
1328 @retval NULL The string specified by StringId is not present in the string package.\r
1329 @retval Other The string was returned.\r
1330\r
1331**/\r
1332EFI_STRING\r
1333InternalGetString (\r
1334 IN EFI_HII_HANDLE HiiHandle,\r
1335 IN EFI_STRING_ID StringId\r
1336 )\r
1337{\r
1338 EFI_STATUS Status;\r
1339 UINTN StringSize;\r
1340 CHAR16 TempString;\r
1341 EFI_STRING String;\r
1342 CHAR8 *SupportedLanguages;\r
1343 CHAR8 *PlatformLanguage;\r
1344 CHAR8 *BestLanguage;\r
1345 CHAR8 *Language;\r
1346\r
1347 ASSERT (HiiHandle != NULL);\r
1348 ASSERT (StringId != 0);\r
1349\r
1350 //\r
1351 // Initialize all allocated buffers to NULL\r
1352 // \r
1353 SupportedLanguages = NULL;\r
1354 PlatformLanguage = NULL;\r
1355 BestLanguage = NULL;\r
1356 String = NULL;\r
1357 Language = "";\r
1358\r
1359 //\r
1360 // Get the languages that the package specified by HiiHandle supports\r
1361 //\r
1362 SupportedLanguages = GetSupportedLanguages (HiiHandle);\r
1363 if (SupportedLanguages == NULL) {\r
1364 goto Error;\r
1365 }\r
1366\r
1367 //\r
1368 // Get the current platform language setting\r
1369 //\r
1370 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
1371\r
1372 //\r
1373 // Get the best matching language from SupportedLanguages\r
1374 //\r
1375 BestLanguage = GetBestLanguage (\r
1376 SupportedLanguages, \r
1377 FALSE, // RFC 4646 mode\r
1378 Language, // Highest priority \r
1379 PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority\r
1380 SupportedLanguages, // Lowest priority \r
1381 NULL\r
1382 );\r
1383 if (BestLanguage == NULL) {\r
1384 goto Error;\r
1385 }\r
1386\r
1387 //\r
1388 // Retrieve the size of the string in the string package for the BestLanguage\r
1389 //\r
1390 StringSize = 0;\r
1391 Status = mPrivate.HiiString.GetString (\r
1392 &mPrivate.HiiString,\r
1393 BestLanguage,\r
1394 HiiHandle,\r
1395 StringId,\r
1396 &TempString,\r
1397 &StringSize,\r
1398 NULL\r
1399 );\r
1400 //\r
1401 // If GetString() returns EFI_SUCCESS for a zero size, \r
1402 // then there are no supported languages registered for HiiHandle. If GetString() \r
1403 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present\r
1404 // in the HII Database\r
1405 //\r
1406 if (Status != EFI_BUFFER_TOO_SMALL) {\r
1407 goto Error;\r
1408 }\r
1409\r
1410 //\r
1411 // Allocate a buffer for the return string\r
1412 //\r
1413 String = AllocateZeroPool (StringSize);\r
1414 if (String == NULL) {\r
1415 goto Error;\r
1416 }\r
1417\r
1418 //\r
1419 // Retrieve the string from the string package\r
1420 //\r
1421 Status = mPrivate.HiiString.GetString (\r
1422 &mPrivate.HiiString,\r
1423 BestLanguage,\r
1424 HiiHandle,\r
1425 StringId,\r
1426 String,\r
1427 &StringSize,\r
1428 NULL\r
1429 );\r
1430 if (EFI_ERROR (Status)) {\r
1431 //\r
1432 // Free the buffer and return NULL if the supported languages can not be retrieved.\r
1433 //\r
1434 FreePool (String);\r
1435 String = NULL;\r
1436 }\r
1437\r
1438Error:\r
1439 //\r
1440 // Free allocated buffers\r
1441 //\r
1442 if (SupportedLanguages != NULL) {\r
1443 FreePool (SupportedLanguages);\r
1444 }\r
1445 if (PlatformLanguage != NULL) {\r
1446 FreePool (PlatformLanguage);\r
1447 }\r
1448 if (BestLanguage != NULL) {\r
1449 FreePool (BestLanguage);\r
1450 }\r
1451\r
1452 //\r
1453 // Return the Null-terminated Unicode string\r
1454 //\r
1455 return String;\r
84f9a9ec
LG
1456}\r
1457\r
1458/**\r
1459 This function checks VarOffset and VarWidth is in the block range.\r
1460\r
aa75dfec 1461 @param RequestBlockArray The block array is to be checked. \r
84f9a9ec
LG
1462 @param VarOffset Offset of var to the structure\r
1463 @param VarWidth Width of var.\r
82e8c138
ED
1464 @param IsNameValueType Whether this varstore is name/value varstore or not.\r
1465 @param HiiHandle Hii handle for this hii package.\r
84f9a9ec
LG
1466 \r
1467 @retval TRUE This Var is in the block range.\r
1468 @retval FALSE This Var is not in the block range.\r
1469**/\r
1470BOOLEAN\r
1471BlockArrayCheck (\r
1472 IN IFR_BLOCK_DATA *RequestBlockArray,\r
1473 IN UINT16 VarOffset,\r
82e8c138
ED
1474 IN UINT16 VarWidth,\r
1475 IN BOOLEAN IsNameValueType,\r
1476 IN EFI_HII_HANDLE HiiHandle\r
84f9a9ec
LG
1477 )\r
1478{\r
1479 LIST_ENTRY *Link;\r
1480 IFR_BLOCK_DATA *BlockData;\r
82e8c138
ED
1481 EFI_STRING Name;\r
1482\r
84f9a9ec
LG
1483 //\r
1484 // No Request Block array, all vars are got.\r
1485 //\r
1486 if (RequestBlockArray == NULL) {\r
1487 return TRUE;\r
1488 }\r
82e8c138 1489\r
84f9a9ec
LG
1490 //\r
1491 // Check the input var is in the request block range.\r
1492 //\r
1493 for (Link = RequestBlockArray->Entry.ForwardLink; Link != &RequestBlockArray->Entry; Link = Link->ForwardLink) {\r
1494 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
82e8c138
ED
1495\r
1496 if (IsNameValueType) {\r
1497 Name = InternalGetString (HiiHandle, VarOffset);\r
1498 ASSERT (Name != NULL);\r
1499\r
1500 if (StrnCmp (BlockData->Name, Name, StrLen (Name)) == 0) {\r
1501 FreePool (Name);\r
1502 return TRUE;\r
1503 }\r
1504 FreePool (Name);\r
1505 } else {\r
1506 if ((VarOffset >= BlockData->Offset) && ((VarOffset + VarWidth) <= (BlockData->Offset + BlockData->Width))) {\r
1507 return TRUE;\r
1508 }\r
84f9a9ec
LG
1509 }\r
1510 }\r
1511\r
1512 return FALSE;\r
1513}\r
1514\r
cce6230f
ED
1515/**\r
1516 Get form package data from data base.\r
1517\r
1518 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.\r
1519 @param HiiFormPackage The buffer saves the package data.\r
1520 @param PackageSize The buffer size of the package data.\r
1521\r
1522**/\r
1523EFI_STATUS\r
1524GetFormPackageData (\r
1525 IN HII_DATABASE_RECORD *DataBaseRecord,\r
1526 IN OUT UINT8 **HiiFormPackage,\r
1527 OUT UINTN *PackageSize\r
1528 )\r
1529{\r
1530 EFI_STATUS Status;\r
1531 UINTN Size;\r
1532 UINTN ResultSize;\r
1533\r
1534 if (DataBaseRecord == NULL || HiiFormPackage == NULL || PackageSize == NULL) {\r
1535 return EFI_INVALID_PARAMETER;\r
1536 }\r
1537\r
1538 Size = 0;\r
1539 ResultSize = 0;\r
1540 //\r
1541 // 0. Get Hii Form Package by HiiHandle\r
1542 //\r
1543 Status = ExportFormPackages (\r
1544 &mPrivate, \r
1545 DataBaseRecord->Handle, \r
1546 DataBaseRecord->PackageList, \r
1547 0, \r
1548 Size, \r
1549 HiiFormPackage,\r
1550 &ResultSize\r
1551 );\r
1552 if (EFI_ERROR (Status)) {\r
1553 return Status;\r
1554 }\r
1555 \r
1556 (*HiiFormPackage) = AllocatePool (ResultSize);\r
1557 if (*HiiFormPackage == NULL) {\r
1558 Status = EFI_OUT_OF_RESOURCES;\r
1559 return Status;\r
1560 }\r
1561\r
1562 //\r
1563 // Get HiiFormPackage by HiiHandle\r
1564 //\r
1565 Size = ResultSize;\r
1566 ResultSize = 0;\r
1567 Status = ExportFormPackages (\r
1568 &mPrivate, \r
1569 DataBaseRecord->Handle, \r
1570 DataBaseRecord->PackageList, \r
1571 0,\r
1572 Size, \r
1573 *HiiFormPackage,\r
1574 &ResultSize\r
1575 );\r
1576 if (EFI_ERROR (Status)) {\r
1577 FreePool (*HiiFormPackage);\r
1578 }\r
1579 \r
1580 *PackageSize = Size;\r
1581\r
1582 return Status;\r
1583}\r
1584\r
1585\r
1586/**\r
1587 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.\r
1588\r
1589 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.\r
1590 @param ConfigHdr Request string ConfigHdr. If it is NULL,\r
1591 the first found varstore will be as ConfigHdr.\r
1592 @param IsEfiVarstore Whether the request storage type is efi varstore type.\r
1593 @param EfiVarStore The efi varstore info which will return.\r
1594**/ \r
1595EFI_STATUS\r
1596GetVarStoreType (\r
1597 IN HII_DATABASE_RECORD *DataBaseRecord,\r
1598 IN EFI_STRING ConfigHdr,\r
1599 OUT BOOLEAN *IsEfiVarstore,\r
1600 OUT EFI_IFR_VARSTORE_EFI **EfiVarStore\r
cce6230f
ED
1601 )\r
1602{\r
1603 EFI_STATUS Status;\r
1604 UINTN IfrOffset;\r
22031c4f 1605 UINTN PackageOffset;\r
cce6230f
ED
1606 EFI_IFR_OP_HEADER *IfrOpHdr;\r
1607 CHAR16 *VarStoreName;\r
b68ccac1 1608 UINTN NameSize;\r
cce6230f
ED
1609 EFI_STRING GuidStr;\r
1610 EFI_STRING NameStr;\r
1611 EFI_STRING TempStr;\r
1612 UINTN LengthString; \r
1613 UINT8 *HiiFormPackage;\r
1614 UINTN PackageSize;\r
1615 EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;\r
22031c4f 1616 EFI_HII_PACKAGE_HEADER *PackageHeader;\r
cce6230f
ED
1617 \r
1618 HiiFormPackage = NULL;\r
1619 LengthString = 0;\r
1620 Status = EFI_SUCCESS;\r
1621 GuidStr = NULL;\r
1622 NameStr = NULL;\r
1623 TempStr = NULL;\r
dcdaee88 1624 *IsEfiVarstore = FALSE;\r
cce6230f
ED
1625\r
1626 Status = GetFormPackageData(DataBaseRecord, &HiiFormPackage, &PackageSize);\r
1627 if (EFI_ERROR (Status)) {\r
1628 return Status;\r
1629 }\r
1630\r
22031c4f
ED
1631 IfrOffset = sizeof (EFI_HII_PACKAGE_HEADER);\r
1632 PackageOffset = IfrOffset;\r
1633 PackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiFormPackage;\r
1634\r
cce6230f 1635 while (IfrOffset < PackageSize) {\r
22031c4f
ED
1636 //\r
1637 // More than one form packages exist.\r
1638 //\r
1639 if (PackageOffset >= PackageHeader->Length) {\r
1640 //\r
1641 // Process the new form package.\r
1642 //\r
1643 PackageOffset = sizeof (EFI_HII_PACKAGE_HEADER);\r
1644 IfrOffset += PackageOffset;\r
1645 PackageHeader = (EFI_HII_PACKAGE_HEADER *) (HiiFormPackage + IfrOffset);\r
1646 }\r
1647\r
1648 IfrOpHdr = (EFI_IFR_OP_HEADER *) (HiiFormPackage + IfrOffset);\r
cce6230f 1649 IfrOffset += IfrOpHdr->Length;\r
22031c4f 1650 PackageOffset += IfrOpHdr->Length;\r
cce6230f
ED
1651\r
1652 if (IfrOpHdr->OpCode == EFI_IFR_VARSTORE_EFI_OP ) {\r
1653 IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;\r
1654 //\r
1655 // If the length is small than the structure, this is from old efi \r
1656 // varstore definition. Old efi varstore get config directly from \r
1657 // GetVariable function.\r
1658 //\r
1659 if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) {\r
1660 continue;\r
1661 }\r
1662\r
b68ccac1
SZ
1663 NameSize = AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name);\r
1664 VarStoreName = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
cce6230f
ED
1665 if (VarStoreName == NULL) {\r
1666 Status = EFI_OUT_OF_RESOURCES;\r
1667 goto Done;\r
1668 }\r
b68ccac1 1669 AsciiStrToUnicodeStrS ((CHAR8 *) IfrEfiVarStore->Name, VarStoreName, NameSize);\r
cce6230f
ED
1670\r
1671 GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) &IfrEfiVarStore->Guid, 1, &GuidStr);\r
1672 GenerateSubStr (L"NAME=", StrLen (VarStoreName) * sizeof (CHAR16), (VOID *) VarStoreName, 2, &NameStr);\r
1673 LengthString = StrLen (GuidStr);\r
1674 LengthString = LengthString + StrLen (NameStr) + 1;\r
1675 TempStr = AllocateZeroPool (LengthString * sizeof (CHAR16));\r
1676 if (TempStr == NULL) {\r
1677 FreePool (GuidStr);\r
1678 FreePool (NameStr);\r
1679 FreePool (VarStoreName);\r
1680 Status = EFI_OUT_OF_RESOURCES;\r
1681 goto Done;\r
1682 }\r
5ad66ec6
DB
1683 StrCpyS (TempStr, LengthString, GuidStr);\r
1684 StrCatS (TempStr, LengthString, NameStr);\r
cce6230f
ED
1685 if (ConfigHdr == NULL || StrnCmp (ConfigHdr, TempStr, StrLen (TempStr)) == 0) {\r
1686 *EfiVarStore = (EFI_IFR_VARSTORE_EFI *) AllocateZeroPool (IfrOpHdr->Length);\r
1687 if (*EfiVarStore == NULL) {\r
1688 FreePool (VarStoreName);\r
1689 FreePool (GuidStr);\r
1690 FreePool (NameStr);\r
1691 FreePool (TempStr);\r
1692 Status = EFI_OUT_OF_RESOURCES;\r
1693 goto Done;\r
1694 }\r
1695 *IsEfiVarstore = TRUE;\r
1696 CopyMem (*EfiVarStore, IfrEfiVarStore, IfrOpHdr->Length);\r
1697 } \r
1698 \r
1699 //\r
1700 // Free alllocated temp string.\r
1701 //\r
1702 FreePool (VarStoreName);\r
1703 FreePool (GuidStr);\r
1704 FreePool (NameStr);\r
1705 FreePool (TempStr);\r
22031c4f
ED
1706\r
1707 //\r
1708 // Already found the varstore, break;\r
1709 //\r
1710 if (*IsEfiVarstore) {\r
1711 break;\r
1712 }\r
cce6230f
ED
1713 }\r
1714 }\r
1715Done:\r
1716 if (HiiFormPackage != NULL) {\r
1717 FreePool (HiiFormPackage);\r
1718 }\r
1719\r
1720 return Status;\r
1721}\r
1722\r
82e8c138
ED
1723/**\r
1724 Check whether the ConfigRequest string has the request elements.\r
1725 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.\r
1726 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.\r
1727\r
1728 @param ConfigRequest The input config request string.\r
1729\r
1730 @retval TRUE The input include config request elements.\r
1731 @retval FALSE The input string not includes.\r
1732\r
1733**/\r
1734BOOLEAN\r
1735GetElementsFromRequest (\r
1736 IN EFI_STRING ConfigRequest\r
1737 )\r
1738{\r
1739 EFI_STRING TmpRequest;\r
1740\r
1741 TmpRequest = StrStr (ConfigRequest, L"PATH=");\r
1742 ASSERT (TmpRequest != NULL);\r
1743\r
1744 if ((StrStr (TmpRequest, L"&OFFSET=") != NULL) || (StrStr (TmpRequest, L"&") != NULL)) {\r
1745 return TRUE;\r
1746 }\r
1747\r
1748 return FALSE;\r
1749}\r
1750\r
1751/**\r
1752 Check whether the this varstore is the request varstore.\r
1753\r
1754 @param VarstoreGuid Varstore guid.\r
1755 @param Name Varstore name.\r
1756 @param ConfigHdr Current configRequest info.\r
1757\r
1758 @retval TRUE This varstore is the requst one.\r
1759 @retval FALSE This varstore is not the requst one.\r
1760 \r
1761**/\r
1762BOOLEAN\r
1763IsThisVarstore (\r
1764 IN EFI_GUID *VarstoreGuid,\r
1765 IN CHAR16 *Name,\r
1766 IN CHAR16 *ConfigHdr\r
1767 )\r
1768{\r
1769 EFI_STRING GuidStr;\r
1770 EFI_STRING NameStr;\r
1771 EFI_STRING TempStr;\r
1772 UINTN LengthString;\r
1773 BOOLEAN RetVal;\r
1774\r
1775 RetVal = FALSE;\r
1776 GuidStr = NULL;\r
1777 TempStr = NULL;\r
1778\r
7248790e
ED
1779 //\r
1780 // If ConfigHdr has name field and varstore not has name, return FALSE.\r
1781 //\r
0f83ac34 1782 if (Name == NULL && ConfigHdr != NULL && StrStr (ConfigHdr, L"NAME=&") == NULL) {\r
7248790e
ED
1783 return FALSE;\r
1784 }\r
1785\r
82e8c138
ED
1786 GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *)VarstoreGuid, 1, &GuidStr);\r
1787 if (Name != NULL) {\r
1788 GenerateSubStr (L"NAME=", StrLen (Name) * sizeof (CHAR16), (VOID *) Name, 2, &NameStr);\r
1789 } else {\r
1790 GenerateSubStr (L"NAME=", 0, NULL, 2, &NameStr);\r
1791 }\r
1792 LengthString = StrLen (GuidStr);\r
1793 LengthString = LengthString + StrLen (NameStr) + 1;\r
1794 TempStr = AllocateZeroPool (LengthString * sizeof (CHAR16));\r
1795 if (TempStr == NULL) {\r
1796 goto Done;\r
1797 }\r
1798\r
5ad66ec6
DB
1799 StrCpyS (TempStr, LengthString, GuidStr);\r
1800 StrCatS (TempStr, LengthString, NameStr);\r
82e8c138
ED
1801\r
1802 if (ConfigHdr == NULL || StrnCmp (ConfigHdr, TempStr, StrLen (TempStr)) == 0) {\r
1803 RetVal = TRUE;\r
1804 }\r
1805\r
1806Done:\r
1807 if (GuidStr != NULL) {\r
1808 FreePool (GuidStr); \r
1809 }\r
1810\r
1811 if (NameStr != NULL) {\r
1812 FreePool (NameStr);\r
1813 }\r
1814\r
1815 if (TempStr != NULL) {\r
1816 FreePool (TempStr);\r
1817 }\r
1818\r
1819 return RetVal;\r
1820}\r
1821\r
7248790e
ED
1822/**\r
1823 This function parses Form Package to get the efi varstore info according to the request ConfigHdr.\r
1824\r
1825 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.\r
1826 @param ConfigHdr Request string ConfigHdr. If it is NULL,\r
1827 the first found varstore will be as ConfigHdr.\r
1828 @retval TRUE This hii package is the reqeust one.\r
1829 @retval FALSE This hii package is not the reqeust one.\r
1830**/ \r
1831BOOLEAN\r
1832IsThisPackageList (\r
1833 IN HII_DATABASE_RECORD *DataBaseRecord,\r
1834 IN EFI_STRING ConfigHdr\r
1835 )\r
1836{\r
1837 EFI_STATUS Status;\r
1838 UINTN IfrOffset;\r
1839 UINTN PackageOffset;\r
1840 EFI_IFR_OP_HEADER *IfrOpHdr;\r
1841 CHAR16 *VarStoreName;\r
b68ccac1 1842 UINTN NameSize;\r
7248790e
ED
1843 UINT8 *HiiFormPackage;\r
1844 UINTN PackageSize;\r
1845 EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;\r
1846 EFI_HII_PACKAGE_HEADER *PackageHeader;\r
1847 EFI_IFR_VARSTORE *IfrVarStore;\r
1848 EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueVarStore;\r
1849 BOOLEAN FindVarstore;\r
1850\r
1851 HiiFormPackage = NULL;\r
1852 VarStoreName = NULL;\r
1853 Status = EFI_SUCCESS;\r
1854 FindVarstore = FALSE;\r
1855\r
1856 Status = GetFormPackageData(DataBaseRecord, &HiiFormPackage, &PackageSize);\r
1857 if (EFI_ERROR (Status)) {\r
1858 return FALSE;\r
1859 }\r
1860\r
1861 IfrOffset = sizeof (EFI_HII_PACKAGE_HEADER);\r
1862 PackageOffset = IfrOffset;\r
1863 PackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiFormPackage;\r
1864\r
1865 while (IfrOffset < PackageSize) {\r
1866 //\r
1867 // More than one form packages exist.\r
1868 //\r
1869 if (PackageOffset >= PackageHeader->Length) {\r
1870 //\r
1871 // Process the new form package.\r
1872 //\r
1873 PackageOffset = sizeof (EFI_HII_PACKAGE_HEADER);\r
1874 IfrOffset += PackageOffset;\r
1875 PackageHeader = (EFI_HII_PACKAGE_HEADER *) (HiiFormPackage + IfrOffset);\r
1876 }\r
1877\r
1878 IfrOpHdr = (EFI_IFR_OP_HEADER *) (HiiFormPackage + IfrOffset);\r
1879 IfrOffset += IfrOpHdr->Length;\r
1880 PackageOffset += IfrOpHdr->Length;\r
1881\r
1882 switch (IfrOpHdr->OpCode) {\r
1883 \r
1884 case EFI_IFR_VARSTORE_OP:\r
1885 IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr;\r
1886\r
b68ccac1
SZ
1887 NameSize = AsciiStrSize ((CHAR8 *)IfrVarStore->Name);\r
1888 VarStoreName = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
7248790e
ED
1889 if (VarStoreName == NULL) {\r
1890 goto Done;\r
1891 }\r
b68ccac1 1892 AsciiStrToUnicodeStrS ((CHAR8 *)IfrVarStore->Name, VarStoreName, NameSize);\r
7248790e
ED
1893\r
1894 if (IsThisVarstore((VOID *)&IfrVarStore->Guid, VarStoreName, ConfigHdr)) {\r
1895 FindVarstore = TRUE;\r
1896 goto Done;\r
a0b0cd73
DB
1897 } else {\r
1898 FreePool (VarStoreName);\r
1899 VarStoreName = NULL;\r
7248790e
ED
1900 }\r
1901 break;\r
1902\r
1903 case EFI_IFR_VARSTORE_EFI_OP:\r
1904 IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;\r
b68ccac1
SZ
1905 NameSize = AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name);\r
1906 VarStoreName = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
7248790e
ED
1907 if (VarStoreName == NULL) {\r
1908 goto Done;\r
1909 }\r
b68ccac1 1910 AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name, VarStoreName, NameSize);\r
7248790e
ED
1911\r
1912 if (IsThisVarstore (&IfrEfiVarStore->Guid, VarStoreName, ConfigHdr)) {\r
1913 FindVarstore = TRUE;\r
1914 goto Done;\r
a0b0cd73
DB
1915 } else {\r
1916 FreePool (VarStoreName);\r
1917 VarStoreName = NULL;\r
7248790e
ED
1918 }\r
1919 break;\r
1920\r
1921 case EFI_IFR_VARSTORE_NAME_VALUE_OP:\r
1922 IfrNameValueVarStore = (EFI_IFR_VARSTORE_NAME_VALUE *) IfrOpHdr;\r
1923\r
1924 if (IsThisVarstore (&IfrNameValueVarStore->Guid, NULL, ConfigHdr)) {\r
1925 FindVarstore = TRUE;\r
1926 goto Done;\r
1927 }\r
1928 break;\r
1929 \r
1930 case EFI_IFR_FORM_OP:\r
1931 case EFI_IFR_FORM_MAP_OP:\r
1932 //\r
1933 // No matched varstore is found and directly return.\r
1934 //\r
1935 goto Done;\r
7248790e
ED
1936\r
1937 default:\r
1938 break;\r
1939 }\r
1940 }\r
7248790e
ED
1941Done:\r
1942 if (HiiFormPackage != NULL) {\r
1943 FreePool (HiiFormPackage);\r
1944 }\r
1945\r
1946 if (VarStoreName != NULL) {\r
1947 FreePool (VarStoreName);\r
1948 }\r
1949\r
1950 return FindVarstore;\r
1951}\r
1952\r
82e8c138
ED
1953/**\r
1954 Check whether the this op code is required.\r
1955\r
1956 @param RequestBlockArray The array includes all the request info or NULL.\r
1957 @param HiiHandle The hii handle for this form package.\r
1958 @param VarStorageData The varstore data strucure.\r
1959 @param IfrOpHdr Ifr opcode header for this opcode.\r
1960 @param VarWidth The buffer width for this opcode.\r
1961 @param ReturnData The data block added for this opcode.\r
1962\r
1963 @retval EFI_SUCCESS This opcode is required.\r
f447734e
DB
1964 @retval EFI_NOT_FOUND This opcode is not required.\r
1965 @retval Others Contain some error.\r
82e8c138
ED
1966 \r
1967**/\r
1968EFI_STATUS\r
1969IsThisOpcodeRequired (\r
1970 IN IFR_BLOCK_DATA *RequestBlockArray,\r
1971 IN EFI_HII_HANDLE HiiHandle,\r
1972 IN OUT IFR_VARSTORAGE_DATA *VarStorageData,\r
1973 IN EFI_IFR_OP_HEADER *IfrOpHdr,\r
1974 IN UINT16 VarWidth,\r
1975 OUT IFR_BLOCK_DATA **ReturnData\r
1976 )\r
1977{\r
1978 IFR_BLOCK_DATA *BlockData;\r
1979 UINT16 VarOffset;\r
1980 EFI_STRING_ID NameId;\r
1981 EFI_IFR_QUESTION_HEADER *IfrQuestionHdr;\r
1982\r
1983 NameId = 0;\r
1984 VarOffset = 0;\r
1985 IfrQuestionHdr = (EFI_IFR_QUESTION_HEADER *)((CHAR8 *) IfrOpHdr + sizeof (EFI_IFR_OP_HEADER));\r
1986\r
1987 if (VarStorageData->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
1988 NameId = IfrQuestionHdr->VarStoreInfo.VarName;\r
1989\r
1990 //\r
1991 // Check whether this question is in requested block array.\r
1992 //\r
1993 if (!BlockArrayCheck (RequestBlockArray, NameId, 0, TRUE, HiiHandle)) {\r
1994 //\r
1995 // This question is not in the requested string. Skip it.\r
1996 //\r
f447734e 1997 return EFI_NOT_FOUND;\r
82e8c138
ED
1998 }\r
1999 } else {\r
2000 VarOffset = IfrQuestionHdr->VarStoreInfo.VarOffset;\r
2001 \r
2002 //\r
2003 // Check whether this question is in requested block array.\r
2004 //\r
2005 if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth, FALSE, HiiHandle)) {\r
2006 //\r
2007 // This question is not in the requested string. Skip it.\r
2008 //\r
f447734e 2009 return EFI_NOT_FOUND;\r
82e8c138
ED
2010 }\r
2011\r
2012 //\r
2013 // Check this var question is in the var storage \r
2014 //\r
2015 if (((VarOffset + VarWidth) > VarStorageData->Size)) {\r
2016 return EFI_INVALID_PARAMETER;\r
2017 }\r
2018 }\r
2019\r
2020 BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
2021 if (BlockData == NULL) {\r
2022 return EFI_OUT_OF_RESOURCES;\r
2023 }\r
2024\r
2025 if (VarStorageData->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
2026 BlockData->Name = InternalGetString(HiiHandle, NameId);\r
2027 } else {\r
2028 BlockData->Offset = VarOffset;\r
2029 }\r
2030\r
2031 BlockData->Width = VarWidth;\r
2032 BlockData->QuestionId = IfrQuestionHdr->QuestionId;\r
2033 BlockData->OpCode = IfrOpHdr->OpCode;\r
2034 BlockData->Scope = IfrOpHdr->Scope;\r
2035 InitializeListHead (&BlockData->DefaultValueEntry);\r
2036 //\r
2037 // Add Block Data into VarStorageData BlockEntry\r
2038 //\r
2039 InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r
2040 *ReturnData = BlockData;\r
2041\r
2042 return EFI_SUCCESS;\r
2043}\r
2044\r
84f9a9ec
LG
2045/**\r
2046 This function parses Form Package to get the block array and the default\r
2047 value array according to the request ConfigHdr.\r
2048\r
82e8c138 2049 @param HiiHandle Hii Handle for this hii package.\r
84f9a9ec
LG
2050 @param Package Pointer to the form package data.\r
2051 @param PackageLength Length of the pacakge.\r
2052 @param ConfigHdr Request string ConfigHdr. If it is NULL,\r
2053 the first found varstore will be as ConfigHdr.\r
2054 @param RequestBlockArray The block array is retrieved from the request string.\r
2055 @param VarStorageData VarStorage structure contains the got block and default value.\r
82e8c138 2056 @param DefaultIdArray Point to the got default id and default name array.\r
84f9a9ec
LG
2057\r
2058 @retval EFI_SUCCESS The block array and the default value array are got.\r
2059 @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges\r
2060 are conflicted. \r
2061 @retval EFI_OUT_OF_RESOURCES No enough memory.\r
2062**/\r
2063EFI_STATUS\r
2064EFIAPI\r
2065ParseIfrData (\r
82e8c138 2066 IN EFI_HII_HANDLE HiiHandle,\r
84f9a9ec 2067 IN UINT8 *Package,\r
aa75dfec 2068 IN UINT32 PackageLength,\r
84f9a9ec
LG
2069 IN EFI_STRING ConfigHdr,\r
2070 IN IFR_BLOCK_DATA *RequestBlockArray,\r
2071 IN OUT IFR_VARSTORAGE_DATA *VarStorageData,\r
8567300a 2072 OUT IFR_DEFAULT_DATA *DefaultIdArray\r
84f9a9ec
LG
2073 )\r
2074{\r
2075 EFI_STATUS Status;\r
2076 UINTN IfrOffset;\r
22031c4f 2077 UINTN PackageOffset;\r
84f9a9ec 2078 EFI_IFR_VARSTORE *IfrVarStore;\r
cce6230f 2079 EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;\r
84f9a9ec
LG
2080 EFI_IFR_OP_HEADER *IfrOpHdr;\r
2081 EFI_IFR_ONE_OF *IfrOneOf;\r
e7fd76d1 2082 EFI_IFR_REF4 *IfrRef;\r
84f9a9ec
LG
2083 EFI_IFR_ONE_OF_OPTION *IfrOneOfOption;\r
2084 EFI_IFR_DEFAULT *IfrDefault;\r
2085 EFI_IFR_ORDERED_LIST *IfrOrderedList;\r
2086 EFI_IFR_CHECKBOX *IfrCheckBox;\r
2087 EFI_IFR_PASSWORD *IfrPassword;\r
2088 EFI_IFR_STRING *IfrString;\r
d9bbabfd
ED
2089 EFI_IFR_DATE *IfrDate;\r
2090 EFI_IFR_TIME *IfrTime;\r
ef40f0f6
ED
2091 IFR_DEFAULT_DATA DefaultData;\r
2092 IFR_DEFAULT_DATA *DefaultDataPtr;\r
84f9a9ec 2093 IFR_BLOCK_DATA *BlockData;\r
40ae09a2 2094 CHAR16 *VarStoreName;\r
b68ccac1 2095 UINTN NameSize;\r
40ae09a2
ED
2096 UINT16 VarWidth;\r
2097 UINT16 VarDefaultId;\r
40ae09a2 2098 BOOLEAN FirstOneOfOption;\r
9495c01e 2099 BOOLEAN FirstOrderedList;\r
40ae09a2
ED
2100 LIST_ENTRY *LinkData;\r
2101 LIST_ENTRY *LinkDefault;\r
2102 EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueVarStore;\r
22031c4f
ED
2103 EFI_HII_PACKAGE_HEADER *PackageHeader;\r
2104 EFI_VARSTORE_ID VarStoreId;\r
22f63ff6
DB
2105 UINT16 SmallestDefaultId;\r
2106 UINT16 SmallestIdFromFlag;\r
2107 BOOLEAN FromOtherDefaultOpcode;\r
40ae09a2 2108\r
40ae09a2 2109 Status = EFI_SUCCESS;\r
40ae09a2
ED
2110 BlockData = NULL;\r
2111 DefaultDataPtr = NULL;\r
2112 FirstOneOfOption = FALSE;\r
22031c4f 2113 VarStoreId = 0;\r
9495c01e 2114 FirstOrderedList = FALSE;\r
a0b0cd73 2115 VarStoreName = NULL;\r
ef40f0f6 2116 ZeroMem (&DefaultData, sizeof (IFR_DEFAULT_DATA));\r
22f63ff6
DB
2117 SmallestDefaultId = 0xFFFF;\r
2118 FromOtherDefaultOpcode = FALSE;\r
84f9a9ec
LG
2119\r
2120 //\r
2121 // Go through the form package to parse OpCode one by one.\r
2122 //\r
22031c4f
ED
2123 PackageOffset = sizeof (EFI_HII_PACKAGE_HEADER);\r
2124 PackageHeader = (EFI_HII_PACKAGE_HEADER *) Package;\r
2125 IfrOffset = PackageOffset;\r
aa75dfec 2126 while (IfrOffset < PackageLength) {\r
22031c4f
ED
2127\r
2128 //\r
2129 // More than one form package found.\r
2130 //\r
2131 if (PackageOffset >= PackageHeader->Length) {\r
2132 //\r
2133 // Already found varstore for this request, break;\r
2134 //\r
2135 if (VarStoreId != 0) {\r
2136 VarStoreId = 0;\r
2137 }\r
2138\r
2139 //\r
2140 // Get next package header info.\r
2141 //\r
2142 IfrOffset += sizeof (EFI_HII_PACKAGE_HEADER);\r
2143 PackageOffset = sizeof (EFI_HII_PACKAGE_HEADER);\r
2144 PackageHeader = (EFI_HII_PACKAGE_HEADER *) (Package + IfrOffset);\r
2145 }\r
2146\r
84f9a9ec 2147 IfrOpHdr = (EFI_IFR_OP_HEADER *) (Package + IfrOffset);\r
84f9a9ec
LG
2148 switch (IfrOpHdr->OpCode) {\r
2149 case EFI_IFR_VARSTORE_OP:\r
2150 //\r
2151 // VarStore is found. Don't need to search any more.\r
2152 //\r
22031c4f 2153 if (VarStoreId != 0) {\r
84f9a9ec
LG
2154 break;\r
2155 }\r
2156\r
84f9a9ec 2157 IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr;\r
82e8c138 2158\r
b68ccac1
SZ
2159 NameSize = AsciiStrSize ((CHAR8 *)IfrVarStore->Name);\r
2160 VarStoreName = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
84f9a9ec
LG
2161 if (VarStoreName == NULL) {\r
2162 Status = EFI_OUT_OF_RESOURCES;\r
2163 goto Done;\r
2164 }\r
b68ccac1 2165 AsciiStrToUnicodeStrS ((CHAR8 *)IfrVarStore->Name, VarStoreName, NameSize);\r
84f9a9ec 2166\r
82e8c138 2167 if (IsThisVarstore((VOID *)&IfrVarStore->Guid, VarStoreName, ConfigHdr)) {\r
84f9a9ec
LG
2168 //\r
2169 // Find the matched VarStore\r
2170 //\r
2171 CopyGuid (&VarStorageData->Guid, (EFI_GUID *) (VOID *) &IfrVarStore->Guid);\r
84f9a9ec
LG
2172 VarStorageData->Size = IfrVarStore->Size;\r
2173 VarStorageData->Name = VarStoreName;\r
82e8c138 2174 VarStorageData->Type = EFI_HII_VARSTORE_BUFFER;\r
22031c4f 2175 VarStoreId = IfrVarStore->VarStoreId;\r
a0b0cd73
DB
2176 } else {\r
2177 FreePool (VarStoreName);\r
2178 VarStoreName = NULL;\r
84f9a9ec 2179 }\r
84f9a9ec
LG
2180 break;\r
2181\r
cce6230f
ED
2182 case EFI_IFR_VARSTORE_EFI_OP:\r
2183 //\r
2184 // VarStore is found. Don't need to search any more.\r
2185 //\r
22031c4f 2186 if (VarStoreId != 0) {\r
cce6230f
ED
2187 break;\r
2188 }\r
2189\r
cce6230f
ED
2190 IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;\r
2191\r
2192 //\r
2193 // If the length is small than the structure, this is from old efi \r
2194 // varstore definition. Old efi varstore get config directly from \r
2195 // GetVariable function.\r
2196 // \r
2197 if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) {\r
2198 break;\r
2199 }\r
2200\r
b68ccac1
SZ
2201 NameSize = AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name);\r
2202 VarStoreName = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
cce6230f
ED
2203 if (VarStoreName == NULL) {\r
2204 Status = EFI_OUT_OF_RESOURCES;\r
2205 goto Done;\r
2206 }\r
b68ccac1 2207 AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name, VarStoreName, NameSize);\r
cce6230f 2208\r
82e8c138 2209 if (IsThisVarstore (&IfrEfiVarStore->Guid, VarStoreName, ConfigHdr)) {\r
cce6230f
ED
2210 //\r
2211 // Find the matched VarStore\r
2212 //\r
2213 CopyGuid (&VarStorageData->Guid, (EFI_GUID *) (VOID *) &IfrEfiVarStore->Guid);\r
cce6230f
ED
2214 VarStorageData->Size = IfrEfiVarStore->Size;\r
2215 VarStorageData->Name = VarStoreName;\r
82e8c138 2216 VarStorageData->Type = EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER;\r
22031c4f 2217 VarStoreId = IfrEfiVarStore->VarStoreId;\r
a0b0cd73
DB
2218 } else {\r
2219 FreePool (VarStoreName);\r
2220 VarStoreName = NULL;\r
cce6230f 2221 }\r
cce6230f
ED
2222 break;\r
2223\r
82e8c138 2224 case EFI_IFR_VARSTORE_NAME_VALUE_OP:\r
84f9a9ec 2225 //\r
82e8c138
ED
2226 // VarStore is found. Don't need to search any more.\r
2227 //\r
22031c4f 2228 if (VarStoreId != 0) {\r
82e8c138
ED
2229 break;\r
2230 }\r
2231\r
2232 IfrNameValueVarStore = (EFI_IFR_VARSTORE_NAME_VALUE *) IfrOpHdr;\r
2233\r
2234 if (IsThisVarstore (&IfrNameValueVarStore->Guid, NULL, ConfigHdr)) {\r
2235 //\r
2236 // Find the matched VarStore\r
2237 //\r
2238 CopyGuid (&VarStorageData->Guid, (EFI_GUID *) (VOID *) &IfrNameValueVarStore->Guid);\r
82e8c138 2239 VarStorageData->Type = EFI_HII_VARSTORE_NAME_VALUE;\r
22031c4f 2240 VarStoreId = IfrNameValueVarStore->VarStoreId;\r
82e8c138
ED
2241 }\r
2242 break;\r
2243\r
2244 case EFI_IFR_DEFAULTSTORE_OP:\r
2245 //\r
2246 // Add new the map between default id and default name.\r
84f9a9ec 2247 //\r
ef40f0f6
ED
2248 DefaultDataPtr = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r
2249 if (DefaultDataPtr == NULL) {\r
84f9a9ec
LG
2250 Status = EFI_OUT_OF_RESOURCES;\r
2251 goto Done;\r
2252 }\r
ef40f0f6
ED
2253 DefaultDataPtr->DefaultId = ((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultId;\r
2254 InsertTailList (&DefaultIdArray->Entry, &DefaultDataPtr->Entry);\r
2255 DefaultDataPtr = NULL;\r
84f9a9ec
LG
2256 break;\r
2257\r
2258 case EFI_IFR_FORM_OP:\r
2573712e 2259 case EFI_IFR_FORM_MAP_OP:\r
84f9a9ec
LG
2260 //\r
2261 // No matched varstore is found and directly return.\r
2262 //\r
22031c4f 2263 if ( VarStoreId == 0) {\r
84f9a9ec
LG
2264 Status = EFI_SUCCESS;\r
2265 goto Done;\r
2266 }\r
2267 break;\r
2268\r
e7fd76d1
ED
2269 case EFI_IFR_REF_OP:\r
2270 //\r
2271 // Ref question is not in IFR Form. This IFR form is not valid. \r
2272 //\r
22031c4f 2273 if ( VarStoreId == 0) {\r
e7fd76d1
ED
2274 Status = EFI_INVALID_PARAMETER;\r
2275 goto Done;\r
2276 }\r
2277 //\r
2278 // Check whether this question is for the requested varstore.\r
2279 //\r
2280 IfrRef = (EFI_IFR_REF4 *) IfrOpHdr;\r
22031c4f 2281 if (IfrRef->Question.VarStoreId != VarStoreId) {\r
e7fd76d1
ED
2282 break;\r
2283 }\r
e7fd76d1 2284 VarWidth = (UINT16) (sizeof (EFI_HII_REF));\r
e7fd76d1 2285\r
f447734e
DB
2286 //\r
2287 // The BlockData may allocate by other opcode,need to clean.\r
2288 //\r
2289 if (BlockData != NULL){\r
2290 BlockData = NULL;\r
2291 }\r
2292\r
82e8c138
ED
2293 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2294 if (EFI_ERROR (Status)) {\r
f447734e
DB
2295 if (Status == EFI_NOT_FOUND){\r
2296 //\r
2297 //The opcode is not required,exit and parse other opcode.\r
2298 //\r
2299 break;\r
2300 }\r
e7fd76d1
ED
2301 goto Done;\r
2302 }\r
e7fd76d1
ED
2303 break;\r
2304\r
84f9a9ec
LG
2305 case EFI_IFR_ONE_OF_OP:\r
2306 case EFI_IFR_NUMERIC_OP:\r
2307 //\r
2308 // Numeric and OneOf has the same opcode structure.\r
2309 //\r
2310\r
8567300a
LG
2311 //\r
2312 // Numeric and OneOf question is not in IFR Form. This IFR form is not valid. \r
2313 //\r
22031c4f 2314 if (VarStoreId == 0) {\r
8567300a
LG
2315 Status = EFI_INVALID_PARAMETER;\r
2316 goto Done;\r
2317 }\r
84f9a9ec
LG
2318 //\r
2319 // Check whether this question is for the requested varstore.\r
2320 //\r
2321 IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr;\r
22031c4f 2322 if (IfrOneOf->Question.VarStoreId != VarStoreId) {\r
84f9a9ec
LG
2323 break;\r
2324 }\r
84f9a9ec 2325 VarWidth = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r
84f9a9ec 2326\r
f447734e
DB
2327 //\r
2328 // The BlockData may allocate by other opcode,need to clean.\r
2329 //\r
2330 if (BlockData != NULL){\r
2331 BlockData = NULL;\r
2332 }\r
2333\r
82e8c138
ED
2334 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2335 if (EFI_ERROR (Status)) {\r
f447734e
DB
2336 if (Status == EFI_NOT_FOUND){\r
2337 //\r
2338 //The opcode is not required,exit and parse other opcode.\r
2339 //\r
2340 break;\r
2341 }\r
84f9a9ec
LG
2342 goto Done;\r
2343 }\r
82e8c138 2344\r
f447734e
DB
2345 //\r
2346 //when go to there,BlockData can't be NULLL.\r
2347 //\r
2348 ASSERT (BlockData != NULL);\r
82e8c138 2349\r
cf4c5a42
LG
2350 if (IfrOpHdr->OpCode == EFI_IFR_ONE_OF_OP) {\r
2351 //\r
2352 // Set this flag to TRUE for the first oneof option.\r
2353 //\r
2354 FirstOneOfOption = TRUE;\r
2355 } else if (IfrOpHdr->OpCode == EFI_IFR_NUMERIC_OP) {\r
2356 //\r
2357 // Numeric minimum value will be used as default value when no default is specified. \r
2358 //\r
eb5e7d3e 2359 DefaultData.Type = DefaultValueFromDefault;\r
cf4c5a42
LG
2360 switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {\r
2361 case EFI_IFR_NUMERIC_SIZE_1:\r
e7fd76d1 2362 DefaultData.Value.u8 = IfrOneOf->data.u8.MinValue;\r
cf4c5a42 2363 break;\r
82e8c138 2364\r
cf4c5a42 2365 case EFI_IFR_NUMERIC_SIZE_2:\r
e7fd76d1 2366 CopyMem (&DefaultData.Value.u16, &IfrOneOf->data.u16.MinValue, sizeof (UINT16));\r
cf4c5a42 2367 break;\r
82e8c138 2368\r
cf4c5a42 2369 case EFI_IFR_NUMERIC_SIZE_4:\r
e7fd76d1 2370 CopyMem (&DefaultData.Value.u32, &IfrOneOf->data.u32.MinValue, sizeof (UINT32));\r
cf4c5a42 2371 break;\r
82e8c138 2372\r
cf4c5a42 2373 case EFI_IFR_NUMERIC_SIZE_8:\r
e7fd76d1 2374 CopyMem (&DefaultData.Value.u64, &IfrOneOf->data.u64.MinValue, sizeof (UINT64));\r
cf4c5a42 2375 break;\r
82e8c138
ED
2376\r
2377 default:\r
2378 Status = EFI_INVALID_PARAMETER;\r
2379 goto Done;\r
cf4c5a42
LG
2380 }\r
2381 //\r
ef40f0f6
ED
2382 // Set default value base on the DefaultId list get from IFR data.\r
2383 // \r
2384 for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {\r
82e8c138 2385 DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry);\r
ef40f0f6
ED
2386 DefaultData.DefaultId = DefaultDataPtr->DefaultId;\r
2387 InsertDefaultValue (BlockData, &DefaultData);\r
2388 }\r
cf4c5a42 2389 }\r
84f9a9ec
LG
2390 break;\r
2391\r
2392 case EFI_IFR_ORDERED_LIST_OP:\r
2393 //\r
2394 // offset by question header\r
2395 // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type\r
84f9a9ec 2396 //\r
8567300a 2397\r
9495c01e 2398 FirstOrderedList = TRUE;\r
8567300a
LG
2399 //\r
2400 // OrderedList question is not in IFR Form. This IFR form is not valid. \r
2401 //\r
22031c4f 2402 if (VarStoreId == 0) {\r
8567300a
LG
2403 Status = EFI_INVALID_PARAMETER;\r
2404 goto Done;\r
2405 }\r
84f9a9ec
LG
2406 //\r
2407 // Check whether this question is for the requested varstore.\r
2408 //\r
2409 IfrOrderedList = (EFI_IFR_ORDERED_LIST *) IfrOpHdr;\r
22031c4f 2410 if (IfrOrderedList->Question.VarStoreId != VarStoreId) {\r
ff28420b 2411 BlockData = NULL;\r
84f9a9ec
LG
2412 break;\r
2413 }\r
84f9a9ec 2414 VarWidth = IfrOrderedList->MaxContainers;\r
f447734e
DB
2415\r
2416 //\r
2417 // The BlockData may allocate by other opcode,need to clean.\r
2418 //\r
2419 if (BlockData != NULL){\r
2420 BlockData = NULL;\r
2421 }\r
2422\r
82e8c138
ED
2423 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2424 if (EFI_ERROR (Status)) {\r
f447734e
DB
2425 if (Status == EFI_NOT_FOUND){\r
2426 //\r
2427 //The opcode is not required,exit and parse other opcode.\r
2428 //\r
2429 break;\r
2430 }\r
84f9a9ec
LG
2431 goto Done;\r
2432 }\r
84f9a9ec
LG
2433 break;\r
2434\r
2435 case EFI_IFR_CHECKBOX_OP:\r
2436 //\r
2437 // EFI_IFR_DEFAULT_OP\r
2438 // offset by question header\r
2439 // width is 1 sizeof (BOOLEAN)\r
2440 // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.\r
2441 // value by DefaultOption\r
2442 // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.\r
2443 // \r
2444\r
8567300a
LG
2445 //\r
2446 // CheckBox question is not in IFR Form. This IFR form is not valid. \r
2447 //\r
22031c4f 2448 if (VarStoreId == 0) {\r
8567300a
LG
2449 Status = EFI_INVALID_PARAMETER;\r
2450 goto Done;\r
2451 }\r
84f9a9ec
LG
2452 //\r
2453 // Check whether this question is for the requested varstore.\r
2454 //\r
2455 IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr;\r
22031c4f 2456 if (IfrCheckBox->Question.VarStoreId != VarStoreId) {\r
84f9a9ec
LG
2457 break;\r
2458 }\r
c9325700 2459 VarWidth = (UINT16) sizeof (BOOLEAN);\r
f447734e
DB
2460\r
2461 //\r
2462 // The BlockData may allocate by other opcode,need to clean.\r
2463 //\r
2464 if (BlockData != NULL){\r
2465 BlockData = NULL;\r
2466 }\r
2467\r
82e8c138
ED
2468 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2469 if (EFI_ERROR (Status)) {\r
f447734e
DB
2470 if (Status == EFI_NOT_FOUND){\r
2471 //\r
2472 //The opcode is not required,exit and parse other opcode.\r
2473 //\r
2474 break;\r
2475 }\r
82e8c138
ED
2476 goto Done;\r
2477 }\r
84f9a9ec 2478\r
f447734e
DB
2479 //\r
2480 //when go to there,BlockData can't be NULLL.\r
2481 //\r
2482 ASSERT (BlockData != NULL);\r
84f9a9ec 2483\r
22f63ff6
DB
2484 SmallestIdFromFlag = FALSE;\r
2485\r
84f9a9ec 2486 //\r
e9668a60 2487 // Add default value for standard ID by CheckBox Flag\r
84f9a9ec 2488 //\r
e9668a60
LG
2489 VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
2490 //\r
2491 // Prepare new DefaultValue\r
2492 //\r
ef40f0f6 2493 DefaultData.DefaultId = VarDefaultId;\r
84f9a9ec
LG
2494 if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT) == EFI_IFR_CHECKBOX_DEFAULT) {\r
2495 //\r
e9668a60 2496 // When flag is set, defautl value is TRUE.\r
84f9a9ec 2497 //\r
e7fd76d1
ED
2498 DefaultData.Type = DefaultValueFromFlag;\r
2499 DefaultData.Value.b = TRUE;\r
22f63ff6
DB
2500 InsertDefaultValue (BlockData, &DefaultData);\r
2501\r
2502 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_STANDARD) {\r
2503 //\r
2504 // Record the SmallestDefaultId and update the SmallestIdFromFlag.\r
2505 //\r
2506 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
2507 SmallestIdFromFlag = TRUE;\r
2508 }\r
84f9a9ec
LG
2509 }\r
2510\r
e9668a60
LG
2511 //\r
2512 // Add default value for Manufacture ID by CheckBox Flag\r
2513 //\r
2514 VarDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r
2515 //\r
2516 // Prepare new DefaultValue\r
2517 //\r
ef40f0f6 2518 DefaultData.DefaultId = VarDefaultId;\r
84f9a9ec
LG
2519 if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) == EFI_IFR_CHECKBOX_DEFAULT_MFG) {\r
2520 //\r
e9668a60 2521 // When flag is set, defautl value is TRUE.\r
84f9a9ec 2522 //\r
e7fd76d1
ED
2523 DefaultData.Type = DefaultValueFromFlag;\r
2524 DefaultData.Value.b = TRUE;\r
22f63ff6
DB
2525 InsertDefaultValue (BlockData, &DefaultData);\r
2526\r
2527 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_MANUFACTURING) {\r
2528 //\r
2529 // Record the SmallestDefaultId and update the SmallestIdFromFlag.\r
2530 //\r
2531 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r
2532 SmallestIdFromFlag = TRUE;\r
2533 }\r
2534 }\r
2535 if (SmallestIdFromFlag) {\r
2536 //\r
2537 // When smallest default Id is given by the flag of CheckBox, set defaut value with TRUE for other default Id in the DefaultId list.\r
2538 //\r
2539 DefaultData.Type = DefaultValueFromOtherDefault;\r
2540 DefaultData.Value.b = TRUE;\r
2541 //\r
2542 // Set default value for all the default id in the DefaultId list.\r
2543 //\r
2544 for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {\r
2545 DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry);\r
2546 DefaultData.DefaultId = DefaultDataPtr->DefaultId;\r
2547 InsertDefaultValue (BlockData, &DefaultData);\r
2548 }\r
e9668a60 2549 } else {\r
84f9a9ec 2550 //\r
e9668a60 2551 // When flag is not set, defautl value is FASLE.\r
84f9a9ec 2552 //\r
82e8c138 2553 DefaultData.Type = DefaultValueFromDefault;\r
e7fd76d1 2554 DefaultData.Value.b = FALSE;\r
22f63ff6
DB
2555 //\r
2556 // Set default value for all the default id in the DefaultId list.\r
2557 //\r
2558 for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {\r
2559 DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry);\r
2560 DefaultData.DefaultId = DefaultDataPtr->DefaultId;\r
2561 InsertDefaultValue (BlockData, &DefaultData);\r
2562 }\r
84f9a9ec
LG
2563 }\r
2564 break;\r
2565\r
d9bbabfd
ED
2566 case EFI_IFR_DATE_OP:\r
2567 //\r
2568 // offset by question header\r
2569 // width MaxSize * sizeof (CHAR16)\r
2570 // no default value, only block array\r
2571 //\r
2572\r
2573 //\r
2574 // Date question is not in IFR Form. This IFR form is not valid. \r
2575 //\r
22031c4f 2576 if (VarStoreId == 0) {\r
d9bbabfd
ED
2577 Status = EFI_INVALID_PARAMETER;\r
2578 goto Done;\r
2579 }\r
2580 //\r
2581 // Check whether this question is for the requested varstore.\r
2582 //\r
2583 IfrDate = (EFI_IFR_DATE *) IfrOpHdr;\r
22031c4f 2584 if (IfrDate->Question.VarStoreId != VarStoreId) {\r
d9bbabfd
ED
2585 break;\r
2586 }\r
2587\r
f447734e
DB
2588 //\r
2589 // The BlockData may allocate by other opcode,need to clean.\r
2590 //\r
2591 if (BlockData != NULL){\r
2592 BlockData = NULL;\r
2593 }\r
2594\r
d9bbabfd 2595 VarWidth = (UINT16) sizeof (EFI_HII_DATE);\r
82e8c138
ED
2596 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2597 if (EFI_ERROR (Status)) {\r
f447734e
DB
2598 if (Status == EFI_NOT_FOUND){\r
2599 //\r
2600 //The opcode is not required,exit and parse other opcode.\r
2601 //\r
2602 break;\r
2603 }\r
d9bbabfd
ED
2604 goto Done;\r
2605 }\r
d9bbabfd
ED
2606 break;\r
2607\r
2608 case EFI_IFR_TIME_OP:\r
2609 //\r
2610 // offset by question header\r
2611 // width MaxSize * sizeof (CHAR16)\r
2612 // no default value, only block array\r
2613 //\r
2614\r
2615 //\r
2616 // Time question is not in IFR Form. This IFR form is not valid. \r
2617 //\r
22031c4f 2618 if (VarStoreId == 0) {\r
d9bbabfd
ED
2619 Status = EFI_INVALID_PARAMETER;\r
2620 goto Done;\r
2621 }\r
2622 //\r
2623 // Check whether this question is for the requested varstore.\r
2624 //\r
2625 IfrTime = (EFI_IFR_TIME *) IfrOpHdr;\r
22031c4f 2626 if (IfrTime->Question.VarStoreId != VarStoreId) {\r
d9bbabfd
ED
2627 break;\r
2628 }\r
2629\r
f447734e
DB
2630 //\r
2631 // The BlockData may allocate by other opcode,need to clean.\r
2632 //\r
2633 if (BlockData != NULL){\r
2634 BlockData = NULL;\r
2635 }\r
2636\r
d9bbabfd 2637 VarWidth = (UINT16) sizeof (EFI_HII_TIME);\r
82e8c138
ED
2638 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2639 if (EFI_ERROR (Status)) {\r
f447734e
DB
2640 if (Status == EFI_NOT_FOUND){\r
2641 //\r
2642 //The opcode is not required,exit and parse other opcode.\r
2643 //\r
2644 break;\r
2645 }\r
d9bbabfd
ED
2646 goto Done;\r
2647 }\r
d9bbabfd
ED
2648 break;\r
2649\r
84f9a9ec
LG
2650 case EFI_IFR_STRING_OP:\r
2651 //\r
2652 // offset by question header\r
2653 // width MaxSize * sizeof (CHAR16)\r
2654 // no default value, only block array\r
2655 //\r
2656\r
8567300a
LG
2657 //\r
2658 // String question is not in IFR Form. This IFR form is not valid. \r
2659 //\r
22031c4f 2660 if (VarStoreId == 0) {\r
8567300a
LG
2661 Status = EFI_INVALID_PARAMETER;\r
2662 goto Done;\r
2663 }\r
84f9a9ec
LG
2664 //\r
2665 // Check whether this question is for the requested varstore.\r
2666 //\r
2667 IfrString = (EFI_IFR_STRING *) IfrOpHdr;\r
22031c4f 2668 if (IfrString->Question.VarStoreId != VarStoreId) {\r
84f9a9ec
LG
2669 break;\r
2670 }\r
84f9a9ec 2671\r
f447734e
DB
2672 //\r
2673 // The BlockData may allocate by other opcode,need to clean.\r
2674 //\r
2675 if (BlockData != NULL){\r
2676 BlockData = NULL;\r
2677 }\r
2678\r
82e8c138
ED
2679 VarWidth = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r
2680 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2681 if (EFI_ERROR (Status)) {\r
f447734e
DB
2682 if (Status == EFI_NOT_FOUND){\r
2683 //\r
2684 //The opcode is not required,exit and parse other opcode.\r
2685 //\r
2686 break;\r
2687 }\r
84f9a9ec
LG
2688 goto Done;\r
2689 }\r
84f9a9ec
LG
2690 break;\r
2691\r
2692 case EFI_IFR_PASSWORD_OP:\r
2693 //\r
2694 // offset by question header\r
2695 // width MaxSize * sizeof (CHAR16)\r
2696 // no default value, only block array\r
2697 //\r
2698\r
8567300a
LG
2699 //\r
2700 // Password question is not in IFR Form. This IFR form is not valid. \r
2701 //\r
22031c4f 2702 if (VarStoreId == 0) {\r
8567300a
LG
2703 Status = EFI_INVALID_PARAMETER;\r
2704 goto Done;\r
2705 }\r
84f9a9ec
LG
2706 //\r
2707 // Check whether this question is for the requested varstore.\r
2708 //\r
2709 IfrPassword = (EFI_IFR_PASSWORD *) IfrOpHdr;\r
22031c4f 2710 if (IfrPassword->Question.VarStoreId != VarStoreId) {\r
84f9a9ec
LG
2711 break;\r
2712 }\r
84f9a9ec 2713\r
f447734e
DB
2714 //\r
2715 // The BlockData may allocate by other opcode,need to clean.\r
2716 //\r
2717 if (BlockData != NULL){\r
2718 BlockData = NULL;\r
2719 }\r
2720\r
82e8c138
ED
2721 VarWidth = (UINT16) (IfrPassword->MaxSize * sizeof (UINT16));\r
2722 Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
2723 if (EFI_ERROR (Status)) {\r
f447734e
DB
2724 if (Status == EFI_NOT_FOUND){\r
2725 //\r
2726 //The opcode is not required,exit and parse other opcode.\r
2727 //\r
2728 break;\r
2729 }\r
84f9a9ec
LG
2730 goto Done;\r
2731 }\r
82e8c138 2732\r
84f9a9ec
LG
2733 //\r
2734 // No default value for string.\r
2735 //\r
2736 BlockData = NULL;\r
2737 break;\r
2738\r
2739 case EFI_IFR_ONE_OF_OPTION_OP:\r
2740 //\r
2741 // No matched block data is ignored.\r
2742 //\r
2743 if (BlockData == NULL || BlockData->Scope == 0) {\r
2744 break;\r
2745 }\r
82e8c138 2746\r
84f9a9ec
LG
2747 IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr;\r
2748 if (BlockData->OpCode == EFI_IFR_ORDERED_LIST_OP) {\r
9495c01e
DB
2749\r
2750 if (!FirstOrderedList){\r
2751 break;\r
2752 }\r
84f9a9ec
LG
2753 //\r
2754 // Get ordered list option data type.\r
2755 //\r
2756 if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_8 || IfrOneOfOption->Type == EFI_IFR_TYPE_BOOLEAN) {\r
2757 VarWidth = 1;\r
2758 } else if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_16) {\r
2759 VarWidth = 2;\r
2760 } else if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_32) {\r
2761 VarWidth = 4;\r
2762 } else if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_64) {\r
2763 VarWidth = 8;\r
2764 } else {\r
2765 //\r
2766 // Invalid ordered list option data type.\r
2767 //\r
2768 Status = EFI_INVALID_PARAMETER;\r
82e8c138
ED
2769 if (BlockData->Name != NULL) {\r
2770 FreePool (BlockData->Name);\r
2771 }\r
ff28420b 2772 FreePool (BlockData);\r
84f9a9ec
LG
2773 goto Done;\r
2774 }\r
ff28420b 2775\r
84f9a9ec
LG
2776 //\r
2777 // Calculate Ordered list QuestionId width.\r
2778 //\r
2779 BlockData->Width = (UINT16) (BlockData->Width * VarWidth);\r
ff28420b
LG
2780 //\r
2781 // Check whether this question is in requested block array.\r
2782 //\r
70066a82 2783 if (!BlockArrayCheck (RequestBlockArray, BlockData->Offset, BlockData->Width, (BOOLEAN)(BlockData->Name != NULL), HiiHandle)) {\r
ff28420b
LG
2784 //\r
2785 // This question is not in the requested string. Skip it.\r
2786 //\r
82e8c138
ED
2787 if (BlockData->Name != NULL) {\r
2788 FreePool (BlockData->Name);\r
2789 }\r
ff28420b
LG
2790 FreePool (BlockData);\r
2791 BlockData = NULL;\r
2792 break;\r
2793 }\r
2794 //\r
2795 // Check this var question is in the var storage \r
2796 //\r
82e8c138 2797 if ((BlockData->Name == NULL) && ((BlockData->Offset + BlockData->Width) > VarStorageData->Size)) {\r
ff28420b 2798 Status = EFI_INVALID_PARAMETER;\r
82e8c138
ED
2799 if (BlockData->Name != NULL) {\r
2800 FreePool (BlockData->Name);\r
2801 }\r
ff28420b
LG
2802 FreePool (BlockData);\r
2803 goto Done;\r
2804 }\r
2805 //\r
2806 // Add Block Data into VarStorageData BlockEntry\r
2807 //\r
2808 InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r
9495c01e
DB
2809\r
2810 FirstOrderedList = FALSE;\r
2811\r
84f9a9ec
LG
2812 break;\r
2813 }\r
2814\r
ef40f0f6
ED
2815 //\r
2816 // 1. Set default value for OneOf option when flag field has default attribute.\r
22f63ff6 2817 // And set the default value with the smallest default id for other default id in the DefaultId list.\r
ef40f0f6 2818 //\r
cf4c5a42 2819 if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) ||\r
ef40f0f6 2820 ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG)) {\r
cf4c5a42
LG
2821 //\r
2822 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options. \r
2823 // The first oneof option value will be used as default value when no default value is specified. \r
2824 //\r
2825 FirstOneOfOption = FALSE;\r
22f63ff6
DB
2826\r
2827 SmallestIdFromFlag = FALSE;\r
ef40f0f6 2828 \r
84f9a9ec
LG
2829 // Prepare new DefaultValue\r
2830 //\r
82e8c138 2831 DefaultData.Type = DefaultValueFromFlag;\r
a7f87053 2832 CopyMem (&DefaultData.Value, &IfrOneOfOption->Value, IfrOneOfOption->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value));\r
ef40f0f6
ED
2833 if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) {\r
2834 DefaultData.DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
2835 InsertDefaultValue (BlockData, &DefaultData);\r
22f63ff6
DB
2836 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_STANDARD) {\r
2837 //\r
2838 // Record the SmallestDefaultId and update the SmallestIdFromFlag.\r
2839 //\r
2840 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
2841 SmallestIdFromFlag = TRUE;\r
2842 }\r
2843 }\r
ef40f0f6
ED
2844 if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG) {\r
2845 DefaultData.DefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r
2846 InsertDefaultValue (BlockData, &DefaultData);\r
22f63ff6
DB
2847 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_MANUFACTURING) {\r
2848 //\r
2849 // Record the SmallestDefaultId and update the SmallestIdFromFlag.\r
2850 //\r
2851 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r
2852 SmallestIdFromFlag = TRUE;\r
2853 }\r
2854 }\r
2855\r
2856 if (SmallestIdFromFlag) {\r
2857 //\r
2858 // When smallest default Id is given by the flag of oneofOption, set this option value for other default Id in the DefaultId list.\r
2859 //\r
2860 DefaultData.Type = DefaultValueFromOtherDefault;\r
2861 //\r
2862 // Set default value for other default id in the DefaultId list.\r
2863 //\r
2864 for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {\r
2865 DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry);\r
2866 DefaultData.DefaultId = DefaultDataPtr->DefaultId;\r
2867 InsertDefaultValue (BlockData, &DefaultData);\r
2868 }\r
84f9a9ec 2869 }\r
ef40f0f6 2870 }\r
82e8c138 2871\r
ef40f0f6
ED
2872 //\r
2873 // 2. Set as the default value when this is the first option.\r
2874 // The first oneof option value will be used as default value when no default value is specified. \r
2875 //\r
2876 if (FirstOneOfOption) {\r
2877 // This flag is used to specify whether this option is the first. Set it to FALSE for the following options. \r
2878 FirstOneOfOption = FALSE;\r
2879 \r
84f9a9ec
LG
2880 //\r
2881 // Prepare new DefaultValue\r
ef40f0f6 2882 // \r
82e8c138 2883 DefaultData.Type = DefaultValueFromDefault;\r
a7f87053 2884 CopyMem (&DefaultData.Value, &IfrOneOfOption->Value, IfrOneOfOption->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value));\r
ef40f0f6
ED
2885 for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {\r
2886 DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry); \r
2887 DefaultData.DefaultId = DefaultDataPtr->DefaultId;\r
2888 InsertDefaultValue (BlockData, &DefaultData);\r
82e8c138 2889 }\r
84f9a9ec
LG
2890 }\r
2891 break;\r
2892\r
2893 case EFI_IFR_DEFAULT_OP:\r
2894 //\r
2895 // Update Current BlockData to the default value.\r
2896 //\r
2897 if (BlockData == NULL || BlockData->Scope == 0) {\r
2898 //\r
82e8c138 2899 // No matched block data is ignored.\r
84f9a9ec
LG
2900 //\r
2901 break;\r
2902 }\r
2903\r
84f9a9ec 2904 //\r
81b618fe 2905 // Get the DefaultId\r
84f9a9ec
LG
2906 //\r
2907 IfrDefault = (EFI_IFR_DEFAULT *) IfrOpHdr;\r
2908 VarDefaultId = IfrDefault->DefaultId;\r
84f9a9ec
LG
2909 //\r
2910 // Prepare new DefaultValue\r
2911 //\r
eb5e7d3e 2912 DefaultData.Type = DefaultValueFromOpcode;\r
ef40f0f6 2913 DefaultData.DefaultId = VarDefaultId;\r
23fe74dc 2914 CopyMem (&DefaultData.Value, &IfrDefault->Value, IfrDefault->Header.Length - OFFSET_OF (EFI_IFR_DEFAULT, Value));\r
82e8c138 2915\r
ef40f0f6
ED
2916 // If the value field is expression, set the cleaned flag.\r
2917 if (IfrDefault->Type == EFI_IFR_TYPE_OTHER) {\r
2918 DefaultData.Cleaned = TRUE;\r
84f9a9ec 2919 }\r
84f9a9ec
LG
2920 //\r
2921 // Add DefaultValue into current BlockData\r
2922 //\r
ef40f0f6 2923 InsertDefaultValue (BlockData, &DefaultData);\r
82e8c138 2924\r
22f63ff6
DB
2925 //\r
2926 // Set default value for other default id in the DefaultId list.\r
2927 // when SmallestDefaultId == VarDefaultId means there are two defaults with same default Id.\r
2928 // If the two defaults are both from default opcode, use the first default as the default value of other default Id.\r
2929 // If one from flag and the other form default opcode, use the default opcode value as the default value of other default Id.\r
2930 //\r
2931 if ((SmallestDefaultId > VarDefaultId) || (SmallestDefaultId == VarDefaultId && !FromOtherDefaultOpcode)) {\r
2932 FromOtherDefaultOpcode = TRUE;\r
2933 SmallestDefaultId = VarDefaultId;\r
2934 for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {\r
2935 DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry);\r
2936 if (DefaultDataPtr->DefaultId != DefaultData.DefaultId){\r
2937 DefaultData.Type = DefaultValueFromOtherDefault;\r
2938 DefaultData.DefaultId = DefaultDataPtr->DefaultId;\r
2939 InsertDefaultValue (BlockData, &DefaultData);\r
2940 }\r
2941 }\r
2942 }\r
2943\r
ef40f0f6
ED
2944 //\r
2945 // After insert the default value, reset the cleaned value for next \r
2946 // time used. If not set here, need to set the value before everytime \r
2947 // use it.\r
2948 //\r
2949 DefaultData.Cleaned = FALSE;\r
84f9a9ec 2950 break;\r
82e8c138 2951\r
84f9a9ec
LG
2952 case EFI_IFR_END_OP:\r
2953 //\r
8567300a 2954 // End Opcode is for Var question.\r
84f9a9ec 2955 //\r
7248790e
ED
2956 if (BlockData != NULL) {\r
2957 if (BlockData->Scope > 0) {\r
2958 BlockData->Scope--;\r
2959 }\r
2960 if (BlockData->Scope == 0) {\r
2961 BlockData = NULL;\r
22f63ff6
DB
2962 //\r
2963 // when finishing parsing a question, clean the SmallestDefaultId and GetDefaultFromDefaultOpcode.\r
2964 //\r
2965 SmallestDefaultId = 0xFFFF;\r
2966 FromOtherDefaultOpcode = FALSE;\r
7248790e 2967 }\r
84f9a9ec 2968 }\r
7248790e 2969\r
84f9a9ec 2970 break;\r
82e8c138 2971\r
84f9a9ec 2972 default:\r
7248790e
ED
2973 if (BlockData != NULL) {\r
2974 if (BlockData->Scope > 0) {\r
2975 BlockData->Scope = (UINT8) (BlockData->Scope + IfrOpHdr->Scope);\r
2976 }\r
2977\r
2978 if (BlockData->Scope == 0) {\r
2979 BlockData = NULL;\r
2980 }\r
84f9a9ec
LG
2981 }\r
2982 break;\r
2983 }\r
2984\r
22031c4f
ED
2985 IfrOffset += IfrOpHdr->Length;\r
2986 PackageOffset += IfrOpHdr->Length;\r
84f9a9ec
LG
2987 }\r
2988\r
f447734e
DB
2989 //\r
2990 //if Status == EFI_NOT_FOUND, just means the opcode is not required,not contain any error,\r
2991 //so set the Status to EFI_SUCCESS.\r
2992 //\r
2993 if (Status == EFI_NOT_FOUND){\r
2994 Status = EFI_SUCCESS;\r
2995 }\r
2996\r
84f9a9ec 2997Done:\r
ef40f0f6
ED
2998 for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {\r
2999 BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);\r
3000 for (LinkDefault = BlockData->DefaultValueEntry.ForwardLink; LinkDefault != &BlockData->DefaultValueEntry; ) {\r
3001 DefaultDataPtr = BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry);\r
3002 LinkDefault = LinkDefault->ForwardLink;\r
3003 if (DefaultDataPtr->Cleaned == TRUE) {\r
3004 RemoveEntryList (&DefaultDataPtr->Entry);\r
3005 FreePool (DefaultDataPtr);\r
3006 }\r
3007 }\r
3008 }\r
3009\r
82e8c138 3010 return Status;\r
84f9a9ec
LG
3011}\r
3012\r
3013/**\r
82e8c138 3014 parse the configrequest string, get the elements.\r
84f9a9ec 3015\r
82e8c138
ED
3016 @param ConfigRequest The input configrequest string.\r
3017 @param Progress Return the progress data.\r
3018\r
3019 @retval Block data pointer.\r
3020**/\r
3021IFR_BLOCK_DATA *\r
3022GetBlockElement (\r
3023 IN EFI_STRING ConfigRequest,\r
3024 OUT EFI_STRING *Progress\r
3025 )\r
3026{\r
3027 EFI_STRING StringPtr;\r
3028 IFR_BLOCK_DATA *BlockData;\r
3029 IFR_BLOCK_DATA *RequestBlockArray;\r
3030 EFI_STATUS Status;\r
3031 UINT8 *TmpBuffer;\r
3032 UINT16 Offset;\r
3033 UINT16 Width;\r
3034 LIST_ENTRY *Link;\r
3035 IFR_BLOCK_DATA *NextBlockData;\r
3036 UINTN Length;\r
3037\r
4e1005ec
ED
3038 TmpBuffer = NULL;\r
3039\r
82e8c138
ED
3040 //\r
3041 // Init RequestBlockArray\r
3042 //\r
3043 RequestBlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
3044 if (RequestBlockArray == NULL) {\r
3045 goto Done;\r
3046 }\r
3047 InitializeListHead (&RequestBlockArray->Entry);\r
3048\r
3049 //\r
3050 // Get the request Block array from the request string\r
3051 // Offset and Width\r
3052 //\r
3053\r
3054 //\r
3055 // Parse each <RequestElement> if exists\r
3056 // Only <BlockName> format is supported by this help function.\r
3057 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>\r
3058 //\r
3059 StringPtr = ConfigRequest;\r
3060 while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) {\r
3061 //\r
3062 // Skip the OFFSET string\r
3063 //\r
3064 *Progress = StringPtr;\r
3065 StringPtr += StrLen (L"&OFFSET=");\r
3066 //\r
3067 // Get Offset\r
3068 //\r
3069 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
3070 if (EFI_ERROR (Status)) {\r
3071 goto Done;\r
3072 }\r
3073 Offset = 0;\r
3074 CopyMem (\r
3075 &Offset,\r
3076 TmpBuffer,\r
3077 (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r
3078 );\r
3079 FreePool (TmpBuffer);\r
3080\r
3081 StringPtr += Length;\r
3082 if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
3083 goto Done;\r
3084 }\r
3085 StringPtr += StrLen (L"&WIDTH=");\r
3086\r
3087 //\r
3088 // Get Width\r
3089 //\r
3090 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
3091 if (EFI_ERROR (Status)) {\r
3092 goto Done;\r
3093 }\r
3094 Width = 0;\r
3095 CopyMem (\r
3096 &Width,\r
3097 TmpBuffer,\r
3098 (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r
3099 );\r
3100 FreePool (TmpBuffer);\r
3101\r
3102 StringPtr += Length;\r
3103 if (*StringPtr != 0 && *StringPtr != L'&') {\r
3104 goto Done;\r
3105 }\r
3106 \r
3107 //\r
3108 // Set Block Data\r
3109 //\r
3110 BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
3111 if (BlockData == NULL) {\r
3112 goto Done;\r
3113 }\r
3114 BlockData->Offset = Offset;\r
3115 BlockData->Width = Width;\r
3116 InsertBlockData (&RequestBlockArray->Entry, &BlockData);\r
3117\r
3118 //\r
3119 // Skip &VALUE string if &VALUE does exists.\r
3120 //\r
3121 if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) == 0) {\r
3122 StringPtr += StrLen (L"&VALUE=");\r
3123\r
3124 //\r
3125 // Get Value\r
3126 //\r
3127 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
3128 if (EFI_ERROR (Status)) {\r
3129 goto Done;\r
3130 }\r
a0b0cd73 3131 FreePool (TmpBuffer);\r
82e8c138
ED
3132 StringPtr += Length;\r
3133 if (*StringPtr != 0 && *StringPtr != L'&') {\r
3134 goto Done;\r
3135 }\r
3136 }\r
3137 //\r
3138 // If '\0', parsing is finished. \r
3139 //\r
3140 if (*StringPtr == 0) {\r
3141 break;\r
3142 }\r
3143 }\r
3144\r
3145 //\r
3146 // Merge the requested block data.\r
3147 //\r
3148 Link = RequestBlockArray->Entry.ForwardLink;\r
3149 while ((Link != &RequestBlockArray->Entry) && (Link->ForwardLink != &RequestBlockArray->Entry)) {\r
3150 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
3151 NextBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry);\r
3152 if ((NextBlockData->Offset >= BlockData->Offset) && (NextBlockData->Offset <= (BlockData->Offset + BlockData->Width))) {\r
3153 if ((NextBlockData->Offset + NextBlockData->Width) > (BlockData->Offset + BlockData->Width)) {\r
3154 BlockData->Width = (UINT16) (NextBlockData->Offset + NextBlockData->Width - BlockData->Offset);\r
3155 }\r
3156 RemoveEntryList (Link->ForwardLink);\r
3157 FreePool (NextBlockData);\r
3158 continue;\r
3159 }\r
3160 Link = Link->ForwardLink;\r
3161 }\r
3162\r
3163 return RequestBlockArray;\r
3164\r
3165Done:\r
3166 if (RequestBlockArray != NULL) {\r
3167 //\r
3168 // Free Link Array RequestBlockArray\r
3169 //\r
3170 while (!IsListEmpty (&RequestBlockArray->Entry)) {\r
3171 BlockData = BASE_CR (RequestBlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);\r
3172 RemoveEntryList (&BlockData->Entry);\r
3173 FreePool (BlockData);\r
3174 }\r
3175\r
3176 FreePool (RequestBlockArray);\r
3177 }\r
3178\r
3179 return NULL;\r
3180}\r
3181\r
3182/**\r
3183 parse the configrequest string, get the elements.\r
3184\r
3185 @param ConfigRequest The input config request string.\r
3186 @param Progress Return the progress data.\r
3187\r
3188 @retval return data block array.\r
3189**/\r
3190IFR_BLOCK_DATA *\r
3191GetNameElement (\r
3192 IN EFI_STRING ConfigRequest,\r
3193 OUT EFI_STRING *Progress\r
3194 )\r
3195{\r
3196 EFI_STRING StringPtr;\r
3197 EFI_STRING NextTag;\r
3198 IFR_BLOCK_DATA *BlockData;\r
3199 IFR_BLOCK_DATA *RequestBlockArray;\r
3200 BOOLEAN HasValue;\r
3201\r
3202 StringPtr = ConfigRequest;\r
3203\r
3204 //\r
3205 // Init RequestBlockArray\r
3206 //\r
3207 RequestBlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
3208 if (RequestBlockArray == NULL) {\r
3209 goto Done;\r
3210 }\r
3211 InitializeListHead (&RequestBlockArray->Entry);\r
3212\r
3213 //\r
3214 // Get the request Block array from the request string\r
3215 //\r
3216\r
3217 //\r
3218 // Parse each <RequestElement> if exists\r
3219 // Only <BlockName> format is supported by this help function.\r
3220 // <BlockName> ::= &'Name***=***\r
3221 //\r
3222 while (StringPtr != NULL && *StringPtr == L'&') {\r
3223\r
3224 *Progress = StringPtr;\r
3225 //\r
3226 // Skip the L"&" string\r
3227 //\r
3228 StringPtr += 1;\r
3229\r
3230 HasValue = FALSE;\r
3231 if ((NextTag = StrStr (StringPtr, L"=")) != NULL) {\r
3232 *NextTag = L'\0';\r
3233 HasValue = TRUE;\r
3234 } else if ((NextTag = StrStr (StringPtr, L"&")) != NULL) {\r
3235 *NextTag = L'\0';\r
3236 }\r
3237\r
3238 //\r
3239 // Set Block Data\r
3240 //\r
3241 BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
3242 if (BlockData == NULL) {\r
3243 goto Done;\r
3244 }\r
3245\r
3246 //\r
3247 // Get Name\r
3248 //\r
3249 BlockData->Name = AllocateCopyPool(StrSize (StringPtr), StringPtr);\r
3250 InsertBlockData (&RequestBlockArray->Entry, &BlockData);\r
3251\r
3252 if (HasValue) {\r
3253 //\r
3254 // If has value, skip the value.\r
3255 // \r
3256 StringPtr = NextTag + 1;\r
3257 *NextTag = L'=';\r
3258 StringPtr = StrStr (StringPtr, L"&");\r
3259 } else if (NextTag != NULL) {\r
3260 //\r
3261 // restore the '&' text.\r
3262 //\r
3263 StringPtr = NextTag;\r
3264 *NextTag = L'&';\r
3265 }\r
3266 }\r
3267\r
3268 return RequestBlockArray;\r
3269\r
3270Done:\r
3271 if (RequestBlockArray != NULL) {\r
3272 //\r
3273 // Free Link Array RequestBlockArray\r
3274 //\r
3275 while (!IsListEmpty (&RequestBlockArray->Entry)) {\r
3276 BlockData = BASE_CR (RequestBlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);\r
3277 RemoveEntryList (&BlockData->Entry);\r
3278 if (BlockData->Name != NULL) {\r
3279 FreePool (BlockData->Name);\r
3280 }\r
3281 FreePool (BlockData);\r
3282 }\r
3283\r
3284 FreePool (RequestBlockArray);\r
3285 }\r
3286\r
3287 return NULL;\r
3288}\r
3289\r
3290/**\r
3291 Generate ConfigRequest string base on the varstore info.\r
3292\r
3293 @param ConfigHdr The config header for this varstore.\r
3294 @param VarStorageData The varstore info.\r
3295 @param Status Return Status.\r
3296 @param ConfigRequest The ConfigRequest info may be return.\r
3297\r
3298 @retval TRUE Need to continue\r
3299 @retval Others NO need to continue or error occur.\r
3300**/\r
3301BOOLEAN\r
3302GenerateConfigRequest (\r
3303 IN CHAR16 *ConfigHdr,\r
3304 IN IFR_VARSTORAGE_DATA *VarStorageData,\r
3305 OUT EFI_STATUS *Status,\r
3306 IN OUT EFI_STRING *ConfigRequest\r
3307 )\r
3308{\r
3309 BOOLEAN DataExist;\r
3310 UINTN Length;\r
3311 LIST_ENTRY *Link;\r
3312 CHAR16 *FullConfigRequest;\r
3313 CHAR16 *StringPtr;\r
3314 IFR_BLOCK_DATA *BlockData;\r
3315\r
3316 //\r
3317 // Append VarStorageData BlockEntry into *Request string\r
3318 // Now support only one varstore in a form package.\r
3319 //\r
3320 \r
3321 //\r
3322 // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package\r
3323 // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig\r
3324 //\r
3325 \r
3326 //\r
3327 // Compute the length of the entire request starting with <ConfigHdr> and a \r
3328 // Null-terminator\r
3329 //\r
3330 DataExist = FALSE;\r
3331 Length = StrLen (ConfigHdr) + 1;\r
3332\r
3333 for (Link = VarStorageData->BlockEntry.ForwardLink; Link != &VarStorageData->BlockEntry; Link = Link->ForwardLink) {\r
3334 DataExist = TRUE;\r
3335 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
3336 if (VarStorageData->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
3337 //\r
3338 // Add <BlockName> length for each Name\r
3339 //\r
3340 // <BlockName> ::= &Name1&Name2&... \r
3341 // |1| StrLen(Name1)\r
3342 //\r
3343 Length = Length + (1 + StrLen (BlockData->Name));\r
3344 } else {\r
3345 //\r
3346 // Add <BlockName> length for each Offset/Width pair\r
3347 //\r
3348 // <BlockName> ::= &OFFSET=1234&WIDTH=1234\r
3349 // | 8 | 4 | 7 | 4 |\r
3350 //\r
3351 Length = Length + (8 + 4 + 7 + 4);\r
3352 }\r
3353 }\r
3354 //\r
3355 // No any request block data is found. The request string can't be constructed.\r
3356 //\r
3357 if (!DataExist) {\r
3358 *Status = EFI_SUCCESS;\r
3359 return FALSE;\r
3360 }\r
3361\r
3362 //\r
3363 // Allocate buffer for the entire <ConfigRequest>\r
3364 //\r
3365 FullConfigRequest = AllocateZeroPool (Length * sizeof (CHAR16));\r
3366 if (FullConfigRequest == NULL) {\r
3367 *Status = EFI_OUT_OF_RESOURCES;\r
3368 return FALSE;\r
3369 }\r
3370 StringPtr = FullConfigRequest;\r
3371\r
3372 //\r
3373 // Start with <ConfigHdr>\r
3374 //\r
5ad66ec6 3375 StrCpyS (StringPtr, Length, ConfigHdr);\r
82e8c138
ED
3376 StringPtr += StrLen (StringPtr);\r
3377\r
3378 //\r
3379 // Loop through all the Offset/Width pairs and append them to ConfigRequest\r
3380 //\r
3381 for (Link = VarStorageData->BlockEntry.ForwardLink; Link != &VarStorageData->BlockEntry; Link = Link->ForwardLink) {\r
3382 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
3383 if (VarStorageData->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
3384 //\r
3385 // Append &Name1\0\r
3386 //\r
3387 UnicodeSPrint (\r
3388 StringPtr,\r
3389 (1 + StrLen (BlockData->Name) + 1) * sizeof (CHAR16),\r
3390 L"&%s",\r
3391 BlockData->Name\r
3392 );\r
3393 } else {\r
3394 //\r
3395 // Append &OFFSET=XXXX&WIDTH=YYYY\0\r
3396 //\r
3397 UnicodeSPrint (\r
3398 StringPtr, \r
3399 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16), \r
3400 L"&OFFSET=%04X&WIDTH=%04X", \r
3401 BlockData->Offset, \r
3402 BlockData->Width\r
3403 );\r
3404 }\r
3405 StringPtr += StrLen (StringPtr);\r
3406 }\r
3407 //\r
3408 // Set to the got full request string.\r
3409 //\r
3410 HiiToLower (FullConfigRequest);\r
3411\r
3412 if (*ConfigRequest != NULL) {\r
3413 FreePool (*ConfigRequest);\r
3414 }\r
3415 *ConfigRequest = FullConfigRequest;\r
3416\r
3417 return TRUE;\r
3418}\r
3419\r
3420/**\r
3421 Generate ConfigRequest Header base on the varstore info.\r
3422\r
3423 @param VarStorageData The varstore info.\r
3424 @param DevicePath Device path for this varstore.\r
3425 @param ConfigHdr The config header for this varstore.\r
3426\r
3427 @retval EFI_SUCCESS Generate the header success.\r
3428 @retval EFI_OUT_OF_RESOURCES Allocate buffer fail.\r
3429**/\r
3430EFI_STATUS\r
3431GenerateHdr (\r
3432 IN IFR_VARSTORAGE_DATA *VarStorageData,\r
3433 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
3434 OUT EFI_STRING *ConfigHdr\r
3435 )\r
3436{\r
3437 EFI_STRING GuidStr;\r
3438 EFI_STRING NameStr;\r
3439 EFI_STRING PathStr;\r
3440 UINTN Length;\r
3441 EFI_STATUS Status;\r
3442\r
3443 Status = EFI_SUCCESS;\r
3444 NameStr = NULL;\r
3445 GuidStr = NULL;\r
3446 PathStr = NULL;\r
3447\r
3448 //\r
3449 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle\r
3450 //\r
3451 GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) &VarStorageData->Guid, 1, &GuidStr);\r
3452 if (VarStorageData->Name != NULL) {\r
3453 GenerateSubStr (L"NAME=", StrLen (VarStorageData->Name) * sizeof (CHAR16), (VOID *) VarStorageData->Name, 2, &NameStr);\r
3454 } else {\r
3455 GenerateSubStr (L"NAME=", 0, NULL, 2, &NameStr);\r
3456 }\r
3457 GenerateSubStr (\r
3458 L"PATH=",\r
3459 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),\r
3460 (VOID *) DevicePath,\r
3461 1,\r
3462 &PathStr\r
3463 );\r
3464 Length = StrLen (GuidStr) + StrLen (NameStr) + StrLen (PathStr) + 1;\r
3465 if (VarStorageData->Name == NULL) {\r
3466 Length += 1;\r
3467 }\r
3468\r
3469 *ConfigHdr = AllocateZeroPool (Length * sizeof (CHAR16));\r
3470 if (*ConfigHdr == NULL) {\r
3471 Status = EFI_OUT_OF_RESOURCES;\r
3472 goto Done;\r
3473 }\r
5ad66ec6
DB
3474 StrCpyS (*ConfigHdr, Length, GuidStr);\r
3475 StrCatS (*ConfigHdr, Length, NameStr);\r
82e8c138 3476 if (VarStorageData->Name == NULL) {\r
5ad66ec6 3477 StrCatS (*ConfigHdr, Length, L"&");\r
82e8c138 3478 }\r
5ad66ec6 3479 StrCatS (*ConfigHdr, Length, PathStr);\r
82e8c138
ED
3480\r
3481 //\r
3482 // Remove the last character L'&'\r
3483 //\r
3484 *(*ConfigHdr + StrLen (*ConfigHdr) - 1) = L'\0';\r
3485\r
3486Done:\r
3487 if (GuidStr != NULL) {\r
3488 FreePool (GuidStr);\r
3489 }\r
3490\r
3491 if (NameStr != NULL) {\r
3492 FreePool (NameStr);\r
3493 }\r
3494\r
3495 if (PathStr != NULL) {\r
3496 FreePool (PathStr);\r
3497 }\r
3498\r
3499 return Status;\r
3500}\r
3501\r
3502/**\r
3503 Get Data buffer size based on data type.\r
3504\r
3505 @param ValueType The input data type.\r
3506\r
3507 @retval The data buffer size for the input type.\r
3508**/\r
3509UINT16\r
3510GetStorageWidth (\r
3511 IN UINT8 ValueType\r
3512 )\r
3513{\r
3514 UINT16 StorageWidth;\r
3515\r
3516 switch (ValueType) {\r
3517 case EFI_IFR_NUMERIC_SIZE_1:\r
3518 case EFI_IFR_TYPE_BOOLEAN:\r
3519 StorageWidth = (UINT16) sizeof (UINT8);\r
3520 break;\r
3521\r
3522 case EFI_IFR_NUMERIC_SIZE_2:\r
3523 StorageWidth = (UINT16) sizeof (UINT16);\r
3524 break;\r
3525\r
3526 case EFI_IFR_NUMERIC_SIZE_4:\r
3527 StorageWidth = (UINT16) sizeof (UINT32);\r
3528 break;\r
3529\r
3530 case EFI_IFR_NUMERIC_SIZE_8:\r
3531 StorageWidth = (UINT16) sizeof (UINT64);\r
3532 break;\r
3533\r
3534 case EFI_IFR_TYPE_TIME:\r
3535 StorageWidth = (UINT16) sizeof (EFI_IFR_TIME);\r
3536 break;\r
3537\r
3538 case EFI_IFR_TYPE_DATE:\r
3539 StorageWidth = (UINT16) sizeof (EFI_IFR_DATE);\r
3540 break;\r
3541\r
3542 default:\r
3543 StorageWidth = 0;\r
3544 break;\r
3545 }\r
3546\r
3547 return StorageWidth;\r
3548}\r
3549\r
3550/**\r
3551 Generate ConfigAltResp string base on the varstore info.\r
3552\r
e68c776b 3553 @param HiiHandle Hii Handle for this hii package.\r
82e8c138
ED
3554 @param ConfigHdr The config header for this varstore.\r
3555 @param VarStorageData The varstore info.\r
3556 @param DefaultIdArray The Default id array.\r
3557 @param DefaultAltCfgResp The DefaultAltCfgResp info may be return.\r
3558\r
3559 @retval TRUE Need to continue\r
3560 @retval Others NO need to continue or error occur.\r
3561**/\r
3562EFI_STATUS\r
3563GenerateAltConfigResp (\r
e68c776b 3564 IN EFI_HII_HANDLE HiiHandle,\r
82e8c138
ED
3565 IN CHAR16 *ConfigHdr,\r
3566 IN IFR_VARSTORAGE_DATA *VarStorageData,\r
3567 IN IFR_DEFAULT_DATA *DefaultIdArray,\r
3568 IN OUT EFI_STRING *DefaultAltCfgResp\r
3569 )\r
3570{\r
3571 BOOLEAN DataExist;\r
3572 UINTN Length;\r
3573 LIST_ENTRY *Link;\r
3574 LIST_ENTRY *LinkData;\r
3575 LIST_ENTRY *LinkDefault;\r
3576 LIST_ENTRY *ListEntry;\r
3577 CHAR16 *StringPtr;\r
3578 IFR_BLOCK_DATA *BlockData;\r
3579 IFR_DEFAULT_DATA *DefaultId;\r
3580 IFR_DEFAULT_DATA *DefaultValueData;\r
3581 UINTN Width;\r
3582 UINT8 *TmpBuffer;\r
e68c776b 3583 CHAR16 *DefaultString;\r
82e8c138
ED
3584\r
3585 BlockData = NULL;\r
3586 DataExist = FALSE;\r
e68c776b 3587 DefaultString = NULL;\r
82e8c138
ED
3588 //\r
3589 // Add length for <ConfigHdr> + '\0'\r
3590 //\r
3591 Length = StrLen (ConfigHdr) + 1;\r
3592\r
3593 for (Link = DefaultIdArray->Entry.ForwardLink; Link != &DefaultIdArray->Entry; Link = Link->ForwardLink) {\r
3594 DefaultId = BASE_CR (Link, IFR_DEFAULT_DATA, Entry);\r
3595 //\r
3596 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"\r
3597 // |1| StrLen (ConfigHdr) | 8 | 4 |\r
3598 //\r
3599 Length += (1 + StrLen (ConfigHdr) + 8 + 4);\r
3600 \r
3601 for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {\r
3602 BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);\r
3603 ListEntry = &BlockData->DefaultValueEntry;\r
3604 for (LinkDefault = ListEntry->ForwardLink; LinkDefault != ListEntry; LinkDefault = LinkDefault->ForwardLink) {\r
3605 DefaultValueData = BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry);\r
3606 if (DefaultValueData->DefaultId != DefaultId->DefaultId) {\r
3607 continue;\r
3608 }\r
3609 if (VarStorageData->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
3610 //\r
3611 // Add length for "&Name1=zzzzzzzzzzzz"\r
3612 // |1|Name|1|Value|\r
3613 //\r
3614 Length += (1 + StrLen (BlockData->Name) + 1 + BlockData->Width * 2);\r
3615 } else {\r
3616 //\r
3617 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"\r
3618 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |\r
3619 //\r
3620 Length += (8 + 4 + 7 + 4 + 7 + BlockData->Width * 2);\r
3621 }\r
3622 DataExist = TRUE;\r
3623 }\r
3624 }\r
3625 }\r
3626 \r
3627 //\r
3628 // No default value is found. The default string doesn't exist.\r
3629 //\r
3630 if (!DataExist) {\r
3631 return EFI_SUCCESS;\r
3632 }\r
3633\r
3634 //\r
3635 // Allocate buffer for the entire <DefaultAltCfgResp>\r
3636 //\r
3637 *DefaultAltCfgResp = AllocateZeroPool (Length * sizeof (CHAR16));\r
3638 if (*DefaultAltCfgResp == NULL) {\r
3639 return EFI_OUT_OF_RESOURCES;\r
3640 }\r
3641 StringPtr = *DefaultAltCfgResp;\r
3642\r
3643 //\r
3644 // Start with <ConfigHdr>\r
3645 //\r
5ad66ec6 3646 StrCpyS (StringPtr, Length, ConfigHdr);\r
82e8c138
ED
3647 StringPtr += StrLen (StringPtr);\r
3648\r
3649 for (Link = DefaultIdArray->Entry.ForwardLink; Link != &DefaultIdArray->Entry; Link = Link->ForwardLink) {\r
3650 DefaultId = BASE_CR (Link, IFR_DEFAULT_DATA, Entry);\r
3651 //\r
3652 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"\r
3653 // |1| StrLen (ConfigHdr) | 8 | 4 |\r
3654 //\r
3655 UnicodeSPrint (\r
3656 StringPtr, \r
3657 (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), \r
3658 L"&%s&ALTCFG=%04X", \r
3659 ConfigHdr, \r
3660 DefaultId->DefaultId\r
3661 );\r
3662 StringPtr += StrLen (StringPtr);\r
3663\r
3664 for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {\r
3665 BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);\r
3666 ListEntry = &BlockData->DefaultValueEntry;\r
3667 for (LinkDefault = ListEntry->ForwardLink; LinkDefault != ListEntry; LinkDefault = LinkDefault->ForwardLink) {\r
3668 DefaultValueData = BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry);\r
3669 if (DefaultValueData->DefaultId != DefaultId->DefaultId) {\r
3670 continue;\r
3671 }\r
3672 if (VarStorageData->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
3673 UnicodeSPrint (\r
3674 StringPtr, \r
3675 (1 + StrLen (ConfigHdr) + 1) * sizeof (CHAR16), \r
3676 L"&%s=", \r
3677 BlockData->Name\r
3678 );\r
3679 StringPtr += StrLen (StringPtr);\r
3680 } else {\r
3681 //\r
3682 // Add <BlockConfig>\r
3683 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>\r
3684 //\r
3685 UnicodeSPrint (\r
3686 StringPtr, \r
3687 (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16),\r
3688 L"&OFFSET=%04X&WIDTH=%04X&VALUE=", \r
3689 BlockData->Offset, \r
3690 BlockData->Width\r
3691 );\r
3692 StringPtr += StrLen (StringPtr);\r
3693 }\r
3694 Width = BlockData->Width;\r
3695 //\r
3696 // Convert Value to a hex string in "%x" format\r
3697 // NOTE: This is in the opposite byte that GUID and PATH use\r
3698 //\r
e68c776b
DB
3699 if (BlockData->OpCode == EFI_IFR_STRING_OP){\r
3700 DefaultString = InternalGetString(HiiHandle, DefaultValueData->Value.string);\r
3701 TmpBuffer = (UINT8 *) DefaultString;\r
3702 } else {\r
3703 TmpBuffer = (UINT8 *) &(DefaultValueData->Value);\r
3704 }\r
3705 for (; Width > 0 && (TmpBuffer != NULL); Width--) {\r
82e8c138
ED
3706 StringPtr += UnicodeValueToString (StringPtr, PREFIX_ZERO | RADIX_HEX, TmpBuffer[Width - 1], 2);\r
3707 }\r
e68c776b
DB
3708 if (DefaultString != NULL){\r
3709 FreePool(DefaultString);\r
3710 DefaultString = NULL;\r
3711 }\r
82e8c138
ED
3712 }\r
3713 }\r
3714 }\r
3715\r
3716 HiiToLower (*DefaultAltCfgResp);\r
3717\r
3718 return EFI_SUCCESS;\r
3719}\r
3720\r
3721/**\r
3722 This function gets the full request string and full default value string by \r
3723 parsing IFR data in HII form packages. \r
3724 \r
3725 When Request points to NULL string, the request string and default value string \r
3726 for each varstore in form package will return. \r
3727\r
3728 @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.\r
3729 @param DevicePath Device Path which Hii Config Access Protocol is registered.\r
3730 @param Request Pointer to a null-terminated Unicode string in\r
3731 <ConfigRequest> format. When it doesn't contain\r
3732 any RequestElement, it will be updated to return \r
3733 the full RequestElement retrieved from IFR data.\r
3734 If it points to NULL, the request string for the first\r
3735 varstore in form package will be merged into a\r
3736 <MultiConfigRequest> format string and return. \r
3737 @param AltCfgResp Pointer to a null-terminated Unicode string in\r
3738 <ConfigAltResp> format. When the pointer is to NULL,\r
3739 the full default value string retrieved from IFR data\r
3740 will return. When the pinter is to a string, the\r
3741 full default value string retrieved from IFR data\r
3742 will be merged into the input string and return.\r
3743 When Request points to NULL, the default value string \r
3744 for each varstore in form package will be merged into \r
3745 a <MultiConfigAltResp> format string and return.\r
3746 @param PointerProgress Optional parameter, it can be be NULL. \r
3747 When it is not NULL, if Request is NULL, it returns NULL. \r
3748 On return, points to a character in the Request\r
3749 string. Points to the string's null terminator if\r
3750 request was successful. Points to the most recent\r
3751 & before the first failing name / value pair (or\r
ae79d2f9
LG
3752 the beginning of the string if the failure is in\r
3753 the first name / value pair) if the request was\r
3754 not successful.\r
84f9a9ec
LG
3755 @retval EFI_SUCCESS The Results string is set to the full request string.\r
3756 And AltCfgResp contains all default value string.\r
3757 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.\r
3758 @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string \r
3759 can't be found in Form package.\r
3760 @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.\r
ae79d2f9 3761 @retval EFI_INVALID_PARAMETER Request points to NULL.\r
84f9a9ec
LG
3762\r
3763**/\r
3764EFI_STATUS\r
3765EFIAPI\r
3766GetFullStringFromHiiFormPackages (\r
8567300a 3767 IN HII_DATABASE_RECORD *DataBaseRecord,\r
84f9a9ec
LG
3768 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
3769 IN OUT EFI_STRING *Request,\r
ae79d2f9
LG
3770 IN OUT EFI_STRING *AltCfgResp,\r
3771 OUT EFI_STRING *PointerProgress OPTIONAL\r
84f9a9ec
LG
3772 )\r
3773{\r
3774 EFI_STATUS Status;\r
8567300a
LG
3775 UINT8 *HiiFormPackage;\r
3776 UINTN PackageSize;\r
84f9a9ec
LG
3777 IFR_BLOCK_DATA *RequestBlockArray;\r
3778 IFR_BLOCK_DATA *BlockData;\r
84f9a9ec
LG
3779 IFR_DEFAULT_DATA *DefaultValueData;\r
3780 IFR_DEFAULT_DATA *DefaultId;\r
3781 IFR_DEFAULT_DATA *DefaultIdArray;\r
84f9a9ec
LG
3782 IFR_VARSTORAGE_DATA *VarStorageData;\r
3783 EFI_STRING DefaultAltCfgResp;\r
40ae09a2
ED
3784 EFI_STRING ConfigHdr;\r
3785 EFI_STRING StringPtr;\r
3786 EFI_STRING Progress;\r
40ae09a2
ED
3787\r
3788 if (DataBaseRecord == NULL || DevicePath == NULL || Request == NULL || AltCfgResp == NULL) {\r
3789 return EFI_INVALID_PARAMETER;\r
ae79d2f9
LG
3790 }\r
3791\r
84f9a9ec
LG
3792 //\r
3793 // Initialize the local variables.\r
3794 //\r
3795 RequestBlockArray = NULL;\r
8567300a 3796 DefaultIdArray = NULL;\r
84f9a9ec
LG
3797 VarStorageData = NULL;\r
3798 DefaultAltCfgResp = NULL;\r
40ae09a2
ED
3799 ConfigHdr = NULL;\r
3800 HiiFormPackage = NULL;\r
3801 PackageSize = 0;\r
40ae09a2
ED
3802 Progress = *Request;\r
3803\r
3804 Status = GetFormPackageData (DataBaseRecord, &HiiFormPackage, &PackageSize);\r
84f9a9ec 3805 if (EFI_ERROR (Status)) {\r
b572d3f0 3806 goto Done;\r
84f9a9ec
LG
3807 }\r
3808\r
3809 //\r
8567300a 3810 // 1. Get the request block array by Request String when Request string containts the block array.\r
84f9a9ec
LG
3811 //\r
3812 StringPtr = NULL;\r
3813 if (*Request != NULL) {\r
ae79d2f9
LG
3814 StringPtr = *Request;\r
3815 //\r
3816 // Jump <ConfigHdr>\r
3817 //\r
3818 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
3819 Status = EFI_INVALID_PARAMETER;\r
3820 goto Done;\r
3821 }\r
3822 StringPtr += StrLen (L"GUID=");\r
3823 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) {\r
3824 StringPtr++;\r
3825 }\r
3826 if (*StringPtr == L'\0') {\r
3827 Status = EFI_INVALID_PARAMETER;\r
3828 goto Done;\r
3829 }\r
3830 StringPtr += StrLen (L"&NAME=");\r
82e8c138
ED
3831 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) {\r
3832 StringPtr++;\r
6e3f5b2a 3833 }\r
82e8c138
ED
3834 if (*StringPtr == L'\0') {\r
3835 Status = EFI_INVALID_PARAMETER;\r
84f9a9ec
LG
3836 goto Done;\r
3837 }\r
82e8c138
ED
3838 StringPtr += StrLen (L"&PATH=");\r
3839 while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
3840 StringPtr ++;\r
3841 }\r
84f9a9ec 3842\r
82e8c138 3843 if (*StringPtr == L'\0') {\r
84f9a9ec 3844 //\r
82e8c138 3845 // No request block is found.\r
84f9a9ec 3846 //\r
82e8c138 3847 StringPtr = NULL;\r
84f9a9ec 3848 }\r
84f9a9ec 3849 }\r
82e8c138 3850\r
93e3992d 3851 //\r
82e8c138 3852 // If StringPtr != NULL, get the request elements.\r
93e3992d 3853 //\r
82e8c138
ED
3854 if (StringPtr != NULL) {\r
3855 if (StrStr (StringPtr, L"&OFFSET=") != NULL) {\r
3856 RequestBlockArray = GetBlockElement(StringPtr, &Progress);\r
3857 } else {\r
3858 RequestBlockArray = GetNameElement(StringPtr, &Progress);\r
3859 }\r
3860\r
3861 if (RequestBlockArray == NULL) {\r
3862 Status = EFI_INVALID_PARAMETER;\r
3863 goto Done;\r
84f9a9ec 3864 }\r
93e3992d 3865 }\r
82e8c138 3866\r
6e3f5b2a 3867 //\r
82e8c138 3868 // Initialize DefaultIdArray to store the map between DeaultId and DefaultName\r
6e3f5b2a 3869 //\r
82e8c138
ED
3870 DefaultIdArray = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r
3871 if (DefaultIdArray == NULL) {\r
3872 Status = EFI_OUT_OF_RESOURCES;\r
6e3f5b2a
LG
3873 goto Done;\r
3874 }\r
82e8c138 3875 InitializeListHead (&DefaultIdArray->Entry);\r
84f9a9ec 3876\r
93e3992d 3877 //\r
82e8c138 3878 // Initialize VarStorageData to store the var store Block and Default value information.\r
93e3992d 3879 //\r
82e8c138
ED
3880 VarStorageData = (IFR_VARSTORAGE_DATA *) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA));\r
3881 if (VarStorageData == NULL) {\r
6e3f5b2a 3882 Status = EFI_OUT_OF_RESOURCES;\r
84f9a9ec
LG
3883 goto Done;\r
3884 }\r
82e8c138
ED
3885 InitializeListHead (&VarStorageData->Entry);\r
3886 InitializeListHead (&VarStorageData->BlockEntry);\r
93e3992d 3887\r
84f9a9ec 3888 //\r
82e8c138 3889 // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.\r
84f9a9ec 3890 //\r
93e3992d 3891\r
82e8c138
ED
3892 //\r
3893 // Parse the opcode in form pacakge to get the default setting.\r
3894 //\r
3895 Status = ParseIfrData (DataBaseRecord->Handle,\r
3896 HiiFormPackage,\r
3897 (UINT32) PackageSize,\r
3898 *Request,\r
3899 RequestBlockArray,\r
3900 VarStorageData,\r
3901 DefaultIdArray);\r
3902 if (EFI_ERROR (Status)) {\r
3903 goto Done;\r
3904 }\r
84f9a9ec 3905\r
82e8c138
ED
3906 //\r
3907 // No requested varstore in IFR data and directly return\r
3908 //\r
22031c4f 3909 if (VarStorageData->Type == 0 && VarStorageData->Name == NULL) {\r
82e8c138
ED
3910 Status = EFI_SUCCESS;\r
3911 goto Done;\r
3912 }\r
3913\r
3914 //\r
3915 // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.\r
3916 //\r
3917 Status = GenerateHdr (VarStorageData, DevicePath, &ConfigHdr);\r
3918 if (EFI_ERROR (Status)) {\r
3919 goto Done;\r
3920 }\r
3921\r
3922 if (RequestBlockArray == NULL) {\r
3923 if (!GenerateConfigRequest(ConfigHdr, VarStorageData, &Status, Request)) {\r
3924 goto Done;\r
84f9a9ec 3925 }\r
93e3992d 3926 }\r
82e8c138
ED
3927\r
3928 //\r
3929 // 4. Construct Default Value string in AltResp according to request element.\r
3930 // Go through all VarStorageData Entry and get the DefaultId array for each one\r
3931 // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody\r
3932 //\r
e68c776b 3933 Status = GenerateAltConfigResp (DataBaseRecord->Handle,ConfigHdr, VarStorageData, DefaultIdArray, &DefaultAltCfgResp);\r
82e8c138
ED
3934 if (EFI_ERROR (Status)) {\r
3935 goto Done;\r
3936 }\r
93e3992d 3937\r
84f9a9ec
LG
3938 //\r
3939 // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.\r
3940 //\r
6e3f5b2a 3941 if (*AltCfgResp != NULL && DefaultAltCfgResp != NULL) {\r
84f9a9ec
LG
3942 Status = MergeDefaultString (AltCfgResp, DefaultAltCfgResp);\r
3943 FreePool (DefaultAltCfgResp);\r
6e3f5b2a
LG
3944 } else if (*AltCfgResp == NULL) {\r
3945 *AltCfgResp = DefaultAltCfgResp;\r
93e3992d 3946 }\r
93e3992d 3947\r
84f9a9ec
LG
3948Done:\r
3949 if (RequestBlockArray != NULL) {\r
3950 //\r
3951 // Free Link Array RequestBlockArray\r
3952 //\r
3953 while (!IsListEmpty (&RequestBlockArray->Entry)) {\r
3954 BlockData = BASE_CR (RequestBlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);\r
3955 RemoveEntryList (&BlockData->Entry);\r
82e8c138
ED
3956 if (BlockData->Name != NULL) {\r
3957 FreePool (BlockData->Name);\r
3958 }\r
84f9a9ec
LG
3959 FreePool (BlockData);\r
3960 }\r
3961\r
3962 FreePool (RequestBlockArray);\r
93e3992d 3963 }\r
82e8c138 3964\r
84f9a9ec
LG
3965 if (VarStorageData != NULL) {\r
3966 //\r
3967 // Free link array VarStorageData\r
3968 //\r
3969 while (!IsListEmpty (&VarStorageData->BlockEntry)) {\r
3970 BlockData = BASE_CR (VarStorageData->BlockEntry.ForwardLink, IFR_BLOCK_DATA, Entry);\r
3971 RemoveEntryList (&BlockData->Entry);\r
82e8c138
ED
3972 if (BlockData->Name != NULL) {\r
3973 FreePool (BlockData->Name);\r
3974 }\r
84f9a9ec
LG
3975 //\r
3976 // Free default value link array\r
3977 //\r
3978 while (!IsListEmpty (&BlockData->DefaultValueEntry)) {\r
3979 DefaultValueData = BASE_CR (BlockData->DefaultValueEntry.ForwardLink, IFR_DEFAULT_DATA, Entry);\r
3980 RemoveEntryList (&DefaultValueData->Entry);\r
3981 FreePool (DefaultValueData);\r
3982 }\r
3983 FreePool (BlockData);\r
63d55bb9 3984 }\r
a0b0cd73
DB
3985 if (VarStorageData ->Name != NULL) {\r
3986 FreePool (VarStorageData ->Name);\r
3987 VarStorageData ->Name = NULL;\r
3988 }\r
84f9a9ec 3989 FreePool (VarStorageData);\r
93e3992d 3990 }\r
3991\r
84f9a9ec
LG
3992 if (DefaultIdArray != NULL) {\r
3993 //\r
3994 // Free DefaultId Array\r
3995 //\r
3996 while (!IsListEmpty (&DefaultIdArray->Entry)) {\r
3997 DefaultId = BASE_CR (DefaultIdArray->Entry.ForwardLink, IFR_DEFAULT_DATA, Entry);\r
3998 RemoveEntryList (&DefaultId->Entry);\r
3999 FreePool (DefaultId);\r
4000 }\r
4001 FreePool (DefaultIdArray);\r
4002 }\r
82e8c138 4003\r
84f9a9ec
LG
4004 //\r
4005 // Free the allocated string \r
4006 //\r
84f9a9ec
LG
4007 if (ConfigHdr != NULL) {\r
4008 FreePool (ConfigHdr);\r
4009 }\r
93e3992d 4010\r
84f9a9ec
LG
4011 //\r
4012 // Free Pacakge data\r
4013 //\r
8567300a
LG
4014 if (HiiFormPackage != NULL) {\r
4015 FreePool (HiiFormPackage);\r
676df92c 4016 }\r
63d55bb9 4017\r
ae79d2f9
LG
4018 if (PointerProgress != NULL) {\r
4019 if (*Request == NULL) {\r
4020 *PointerProgress = NULL;\r
4021 } else if (EFI_ERROR (Status)) {\r
82e8c138 4022 *PointerProgress = *Request;\r
ae79d2f9
LG
4023 } else {\r
4024 *PointerProgress = *Request + StrLen (*Request);\r
4025 }\r
4026 }\r
4027\r
93e3992d 4028 return Status;\r
4029}\r
4030\r
cce6230f
ED
4031/**\r
4032 This function gets the full request resp string by \r
4033 parsing IFR data in HII form packages.\r
4034\r
4035 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
4036 instance.\r
4037 @param EfiVarStoreInfo The efi varstore info which is save in the EFI \r
4038 varstore data structure. \r
4039 @param Request Pointer to a null-terminated Unicode string in\r
4040 <ConfigRequest> format.\r
4041 @param RequestResp Pointer to a null-terminated Unicode string in\r
4042 <ConfigResp> format.\r
4043 @param AccessProgress On return, points to a character in the Request\r
4044 string. Points to the string's null terminator if\r
4045 request was successful. Points to the most recent\r
4046 & before the first failing name / value pair (or\r
4047 the beginning of the string if the failure is in\r
4048 the first name / value pair) if the request was\r
4049 not successful.\r
4050\r
4051 @retval EFI_SUCCESS The Results string is set to the full request string.\r
4052 And AltCfgResp contains all default value string.\r
4053 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.\r
4054 @retval EFI_INVALID_PARAMETER Request points to NULL.\r
4055\r
4056**/\r
4057EFI_STATUS\r
4058GetConfigRespFromEfiVarStore (\r
4059 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
4060 IN EFI_IFR_VARSTORE_EFI *EfiVarStoreInfo, \r
4061 IN EFI_STRING Request,\r
4062 OUT EFI_STRING *RequestResp,\r
4063 OUT EFI_STRING *AccessProgress\r
4064 )\r
4065{\r
4066 EFI_STATUS Status;\r
4067 EFI_STRING VarStoreName;\r
b68ccac1 4068 UINTN NameSize;\r
cce6230f
ED
4069 UINT8 *VarStore;\r
4070 UINTN BufferSize;\r
4071\r
7248790e
ED
4072 Status = EFI_SUCCESS;\r
4073 BufferSize = 0;\r
4074 VarStore = NULL;\r
4075 VarStoreName = NULL;\r
4076 *AccessProgress = Request;\r
b68ccac1
SZ
4077\r
4078 NameSize = AsciiStrSize ((CHAR8 *)EfiVarStoreInfo->Name);\r
4079 VarStoreName = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
cce6230f
ED
4080 if (VarStoreName == NULL) {\r
4081 Status = EFI_OUT_OF_RESOURCES;\r
4082 goto Done;\r
4083 }\r
b68ccac1 4084 AsciiStrToUnicodeStrS ((CHAR8 *) EfiVarStoreInfo->Name, VarStoreName, NameSize);\r
cce6230f
ED
4085 \r
4086 \r
4087 Status = gRT->GetVariable (VarStoreName, &EfiVarStoreInfo->Guid, NULL, &BufferSize, NULL);\r
4088 if (Status != EFI_BUFFER_TOO_SMALL) {\r
4089 goto Done;\r
4090 }\r
4091\r
4092 VarStore = AllocateZeroPool (BufferSize);\r
4093 ASSERT (VarStore != NULL);\r
4094 Status = gRT->GetVariable (VarStoreName, &EfiVarStoreInfo->Guid, NULL, &BufferSize, VarStore);\r
4095 if (EFI_ERROR (Status)) {\r
4096 goto Done;\r
4097 }\r
4098\r
4099 Status = HiiBlockToConfig(This, Request, VarStore, BufferSize, RequestResp, AccessProgress);\r
4100 if (EFI_ERROR (Status)) {\r
4101 goto Done;\r
4102 }\r
4103\r
4104Done:\r
4105 if (VarStoreName != NULL) {\r
4106 FreePool (VarStoreName);\r
4107 }\r
4108\r
4109 if (VarStore != NULL) {\r
4110 FreePool (VarStore);\r
4111 }\r
4112\r
4113 return Status;\r
4114}\r
4115\r
4116\r
4117/**\r
4118 This function route the full request resp string for efi varstore. \r
4119\r
4120 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
4121 instance.\r
4122 @param EfiVarStoreInfo The efi varstore info which is save in the EFI \r
4123 varstore data structure. \r
4124 @param RequestResp Pointer to a null-terminated Unicode string in\r
4125 <ConfigResp> format.\r
4126 @param Result Pointer to a null-terminated Unicode string in\r
4127 <ConfigResp> format.\r
4128 \r
4129 @retval EFI_SUCCESS The Results string is set to the full request string.\r
4130 And AltCfgResp contains all default value string.\r
4131 @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.\r
4132 @retval EFI_INVALID_PARAMETER Request points to NULL.\r
4133\r
4134**/\r
4135EFI_STATUS\r
4136RouteConfigRespForEfiVarStore (\r
4137 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
4138 IN EFI_IFR_VARSTORE_EFI *EfiVarStoreInfo, \r
4139 IN EFI_STRING RequestResp,\r
4140 OUT EFI_STRING *Result\r
4141 )\r
4142{\r
4143 EFI_STATUS Status;\r
4144 EFI_STRING VarStoreName;\r
b68ccac1 4145 UINTN NameSize;\r
f26b6a9c 4146 UINT8 *VarStore;\r
cce6230f
ED
4147 UINTN BufferSize;\r
4148 UINTN BlockSize;\r
4149\r
4150 Status = EFI_SUCCESS;\r
4151 BufferSize = 0;\r
4152 VarStore = NULL;\r
4153 VarStoreName = NULL;\r
237e849d 4154 *Result = RequestResp;\r
cce6230f 4155\r
b68ccac1
SZ
4156 NameSize = AsciiStrSize ((CHAR8 *)EfiVarStoreInfo->Name);\r
4157 VarStoreName = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
cce6230f
ED
4158 if (VarStoreName == NULL) {\r
4159 Status = EFI_OUT_OF_RESOURCES;\r
4160 goto Done;\r
4161 }\r
b68ccac1 4162 AsciiStrToUnicodeStrS ((CHAR8 *) EfiVarStoreInfo->Name, VarStoreName, NameSize);\r
cce6230f
ED
4163 \r
4164 Status = gRT->GetVariable (VarStoreName, &EfiVarStoreInfo->Guid, NULL, &BufferSize, NULL);\r
4165 if (Status != EFI_BUFFER_TOO_SMALL) {\r
237e849d 4166 DEBUG ((DEBUG_ERROR, "The variable does not exist!"));\r
cce6230f
ED
4167 goto Done;\r
4168 }\r
4169\r
4170 BlockSize = BufferSize;\r
4171 VarStore = AllocateZeroPool (BufferSize);\r
4172 ASSERT (VarStore != NULL);\r
4173 Status = gRT->GetVariable (VarStoreName, &EfiVarStoreInfo->Guid, NULL, &BufferSize, VarStore);\r
4174 if (EFI_ERROR (Status)) {\r
4175 goto Done;\r
4176 }\r
4177\r
4178 Status = HiiConfigToBlock(This, RequestResp, VarStore, &BlockSize, Result);\r
4179 if (EFI_ERROR (Status)) {\r
4180 goto Done;\r
4181 }\r
4182\r
4183 Status = gRT->SetVariable (VarStoreName, &EfiVarStoreInfo->Guid, EfiVarStoreInfo->Attributes, BufferSize, VarStore);\r
4184 if (EFI_ERROR (Status)) {\r
237e849d 4185 *Result = RequestResp;\r
cce6230f
ED
4186 goto Done;\r
4187 }\r
4188\r
4189Done:\r
4190 if (VarStoreName != NULL) {\r
4191 FreePool (VarStoreName);\r
4192 }\r
4193\r
4194 if (VarStore != NULL) {\r
4195 FreePool (VarStore);\r
4196 }\r
4197\r
4198 return Status;\r
4199}\r
4200\r
82e8c138
ED
4201/**\r
4202 Validate the config request elements.\r
4203\r
4204 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format, \r
4205 without configHdr field.\r
4206\r
4207 @retval CHAR16 * THE first Name/value pair not correct.\r
4208 @retval NULL Success parse the name/value pair\r
4209**/\r
4210CHAR16 *\r
4211OffsetWidthValidate (\r
4212 CHAR16 *ConfigElements\r
4213 )\r
4214{\r
4215 CHAR16 *StringPtr;\r
4216 CHAR16 *RetVal;\r
4217\r
4218 StringPtr = ConfigElements;\r
4219\r
4220 while (1) {\r
4221 RetVal = StringPtr;\r
4222 if (StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) != 0) {\r
4223 return RetVal;\r
4224 }\r
4225\r
4226 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
4227 StringPtr++;\r
4228 }\r
4229 if (*StringPtr == L'\0') {\r
4230 return RetVal;\r
4231 }\r
4232\r
4233 StringPtr += StrLen (L"&WIDTH=");\r
4234 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) != 0) {\r
4235 StringPtr ++;\r
4236 }\r
4237\r
4238 if (*StringPtr == L'\0') {\r
4239 return NULL;\r
4240 }\r
4241 }\r
4242}\r
4243\r
4244/**\r
4245 Validate the config request elements.\r
4246\r
4247 @param ConfigElements A null-terminated Unicode string in <ConfigRequest> format, \r
4248 without configHdr field.\r
4249\r
4250 @retval CHAR16 * THE first Name/value pair not correct.\r
4251 @retval NULL Success parse the name/value pair\r
4252\r
4253**/\r
4254CHAR16 *\r
4255NameValueValidate (\r
4256 CHAR16 *ConfigElements\r
4257 )\r
4258{\r
4259 CHAR16 *StringPtr;\r
4260 CHAR16 *RetVal;\r
4261\r
4262 StringPtr = ConfigElements;\r
4263\r
4264 while (1) {\r
4265 RetVal = StringPtr;\r
4266 if (*StringPtr != L'&') {\r
4267 return RetVal;\r
4268 }\r
4269 StringPtr += 1;\r
4270\r
4271 StringPtr = StrStr (StringPtr, L"&");\r
4272 \r
4273 if (StringPtr == NULL) {\r
4274 return NULL;\r
4275 }\r
4276 }\r
4277}\r
4278\r
4279/**\r
4280 Validate the config request string.\r
4281\r
4282 @param ConfigRequest A null-terminated Unicode string in <ConfigRequest> format.\r
4283\r
4284 @retval CHAR16 * THE first element not correct.\r
4285 @retval NULL Success parse the name/value pair\r
4286\r
4287**/\r
4288CHAR16 *\r
4289ConfigRequestValidate (\r
4290 CHAR16 *ConfigRequest\r
4291 )\r
4292{\r
4293 BOOLEAN HasNameField;\r
4294 CHAR16 *StringPtr;\r
4295\r
4296 HasNameField = TRUE;\r
4297 StringPtr = ConfigRequest;\r
4298\r
4299 //\r
4300 // Check <ConfigHdr>\r
4301 //\r
4302 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
4303 return ConfigRequest;\r
4304 }\r
4305 StringPtr += StrLen (L"GUID=");\r
4306 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) {\r
4307 StringPtr++;\r
4308 }\r
4309 if (*StringPtr == L'\0') {\r
4310 return ConfigRequest;\r
4311 }\r
4312 StringPtr += StrLen (L"&NAME=");\r
4313 if (*StringPtr == L'&') {\r
4314 HasNameField = FALSE;\r
4315 }\r
4316 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) {\r
4317 StringPtr++;\r
4318 }\r
4319 if (*StringPtr == L'\0') {\r
4320 return ConfigRequest;\r
4321 }\r
4322 StringPtr += StrLen (L"&PATH=");\r
4323 while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
4324 StringPtr ++;\r
4325 }\r
4326\r
4327 if (*StringPtr == L'\0') {\r
4328 return NULL;\r
4329 }\r
4330\r
4331 if (HasNameField) {\r
4332 //\r
4333 // Should be Buffer varstore, config request should be "OFFSET/Width" pairs.\r
4334 //\r
4335 return OffsetWidthValidate(StringPtr);\r
4336 } else {\r
4337 //\r
4338 // Should be Name/Value varstore, config request should be "&name1&name2..." pairs.\r
4339 //\r
4340 return NameValueValidate(StringPtr);\r
4341 }\r
4342}\r
4343\r
93e3992d 4344/**\r
4345 This function allows a caller to extract the current configuration\r
4346 for one or more named elements from one or more drivers.\r
4347\r
4348 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
4349 instance.\r
4350 @param Request A null-terminated Unicode string in\r
4351 <MultiConfigRequest> format.\r
4352 @param Progress On return, points to a character in the Request\r
4353 string. Points to the string's null terminator if\r
4354 request was successful. Points to the most recent\r
4355 & before the first failing name / value pair (or\r
4356 the beginning of the string if the failure is in\r
4357 the first name / value pair) if the request was\r
4358 not successful.\r
4359 @param Results Null-terminated Unicode string in\r
4360 <MultiConfigAltResp> format which has all values\r
4361 filled in for the names in the Request string.\r
4362 String to be allocated by the called function.\r
4363\r
4364 @retval EFI_SUCCESS The Results string is filled with the values\r
4365 corresponding to all requested names.\r
4366 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the\r
4367 results that must be stored awaiting possible\r
4368 future protocols.\r
4369 @retval EFI_NOT_FOUND Routing data doesn't match any known driver.\r
4370 Progress set to the "G" in "GUID" of the routing\r
4371 header that doesn't match. Note: There is no\r
4372 requirement that all routing data be validated\r
4373 before any configuration extraction.\r
4374 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request\r
4375 parameter would result in this type of error. The\r
4376 Progress parameter is set to NULL.\r
4377 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &\r
4378 before the error or the beginning of the string.\r
46c3efbb
ED
4379 @retval EFI_INVALID_PARAMETER The ExtractConfig function of the underlying HII\r
4380 Configuration Access Protocol returned \r
4381 EFI_INVALID_PARAMETER. Progress set to most recent\r
4382 & before the error or the beginning of the string.\r
93e3992d 4383\r
4384**/\r
4385EFI_STATUS\r
4386EFIAPI\r
4387HiiConfigRoutingExtractConfig (\r
4388 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
4389 IN CONST EFI_STRING Request,\r
4390 OUT EFI_STRING *Progress,\r
4391 OUT EFI_STRING *Results\r
4392 )\r
4393{\r
84f9a9ec 4394 HII_DATABASE_PRIVATE_DATA *Private;\r
93e3992d 4395 EFI_STRING StringPtr;\r
4396 EFI_STRING ConfigRequest;\r
4397 UINTN Length;\r
4398 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
326c6b71 4399 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
93e3992d 4400 EFI_STATUS Status;\r
84f9a9ec
LG
4401 LIST_ENTRY *Link;\r
4402 HII_DATABASE_RECORD *Database;\r
4403 UINT8 *DevicePathPkg;\r
4404 UINT8 *CurrentDevicePath;\r
93e3992d 4405 EFI_HANDLE DriverHandle;\r
84f9a9ec 4406 EFI_HII_HANDLE HiiHandle;\r
93e3992d 4407 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
4408 EFI_STRING AccessProgress;\r
4409 EFI_STRING AccessResults;\r
74e8963c
DB
4410 EFI_STRING AccessProgressBackup;\r
4411 EFI_STRING AccessResultsBackup;\r
84f9a9ec 4412 EFI_STRING DefaultResults;\r
8d00a0f1 4413 BOOLEAN FirstElement;\r
6e3f5b2a 4414 BOOLEAN IfrDataParsedFlag;\r
cce6230f 4415 BOOLEAN IsEfiVarStore;\r
82e8c138
ED
4416 EFI_IFR_VARSTORE_EFI *EfiVarStoreInfo;\r
4417 EFI_STRING ErrorPtr;\r
7248790e 4418 UINTN DevicePathSize;\r
74e8963c
DB
4419 UINTN ConigStringSize;\r
4420 UINTN ConigStringSizeNewsize;\r
4421 EFI_STRING ConfigStringPtr;\r
93e3992d 4422\r
4423 if (This == NULL || Progress == NULL || Results == NULL) {\r
4424 return EFI_INVALID_PARAMETER;\r
4425 }\r
4426\r
4427 if (Request == NULL) {\r
4428 *Progress = NULL;\r
4429 return EFI_INVALID_PARAMETER;\r
4430 }\r
4431\r
84f9a9ec 4432 Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
93e3992d 4433 StringPtr = Request;\r
4434 *Progress = StringPtr;\r
84f9a9ec
LG
4435 DefaultResults = NULL;\r
4436 ConfigRequest = NULL;\r
4437 Status = EFI_SUCCESS;\r
4438 AccessResults = NULL;\r
cce6230f 4439 AccessProgress = NULL;\r
74e8963c
DB
4440 AccessResultsBackup = NULL;\r
4441 AccessProgressBackup = NULL;\r
84f9a9ec 4442 DevicePath = NULL;\r
6e3f5b2a 4443 IfrDataParsedFlag = FALSE;\r
cce6230f
ED
4444 IsEfiVarStore = FALSE;\r
4445 EfiVarStoreInfo = NULL;\r
93e3992d 4446\r
4447 //\r
4448 // The first element of <MultiConfigRequest> should be\r
4449 // <GuidHdr>, which is in 'GUID='<Guid> syntax.\r
4450 //\r
4451 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
4452 return EFI_INVALID_PARAMETER;\r
4453 }\r
4454\r
8d00a0f1 4455 FirstElement = TRUE;\r
4456\r
93e3992d 4457 //\r
4458 // Allocate a fix length of memory to store Results. Reallocate memory for\r
4459 // Results if this fix length is insufficient.\r
4460 //\r
4461 *Results = (EFI_STRING) AllocateZeroPool (MAX_STRING_LENGTH);\r
4462 if (*Results == NULL) {\r
4463 return EFI_OUT_OF_RESOURCES;\r
4464 }\r
4465\r
4466 while (*StringPtr != 0 && StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) == 0) {\r
4467 //\r
4468 // If parsing error, set Progress to the beginning of the <MultiConfigRequest>\r
4469 // or most recent & before the error.\r
4470 //\r
4471 if (StringPtr == Request) {\r
4472 *Progress = StringPtr;\r
4473 } else {\r
4474 *Progress = StringPtr - 1;\r
4475 }\r
4476\r
4477 //\r
4478 // Process each <ConfigRequest> of <MultiConfigRequest>\r
4479 //\r
4480 Length = CalculateConfigStringLen (StringPtr);\r
4481 ConfigRequest = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), StringPtr);\r
4482 if (ConfigRequest == NULL) {\r
84f9a9ec
LG
4483 Status = EFI_OUT_OF_RESOURCES;\r
4484 goto Done;\r
93e3992d 4485 }\r
4486 *(ConfigRequest + Length) = 0;\r
4487\r
4488 //\r
4489 // Get the UEFI device path\r
4490 //\r
4491 Status = GetDevicePath (ConfigRequest, (UINT8 **) &DevicePath);\r
4492 if (EFI_ERROR (Status)) {\r
84f9a9ec 4493 goto Done;\r
93e3992d 4494 }\r
4495\r
4496 //\r
84f9a9ec
LG
4497 // Find driver which matches the routing data.\r
4498 //\r
4499 DriverHandle = NULL;\r
4500 HiiHandle = NULL;\r
8567300a 4501 Database = NULL;\r
84f9a9ec
LG
4502 for (Link = Private->DatabaseList.ForwardLink;\r
4503 Link != &Private->DatabaseList;\r
4504 Link = Link->ForwardLink\r
4505 ) {\r
4506 Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
84f9a9ec
LG
4507 if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r
4508 CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r
7248790e 4509 DevicePathSize = GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath);\r
8aaab674 4510 if ((CompareMem (DevicePath,CurrentDevicePath,DevicePathSize) == 0) && IsThisPackageList(Database, ConfigRequest)) {\r
84f9a9ec
LG
4511 DriverHandle = Database->DriverHandle;\r
4512 HiiHandle = Database->Handle;\r
4513 break;\r
4514 }\r
4515 }\r
4516 }\r
4517 \r
4518 //\r
4519 // Try to find driver handle by device path.\r
93e3992d 4520 //\r
84f9a9ec
LG
4521 if (DriverHandle == NULL) {\r
4522 TempDevicePath = DevicePath;\r
4523 Status = gBS->LocateDevicePath (\r
4524 &gEfiDevicePathProtocolGuid,\r
4525 &TempDevicePath,\r
4526 &DriverHandle\r
4527 );\r
4528 if (EFI_ERROR (Status) || (DriverHandle == NULL)) {\r
4529 //\r
4530 // Routing data does not match any known driver.\r
4531 // Set Progress to the 'G' in "GUID" of the routing header.\r
4532 //\r
4533 *Progress = StringPtr;\r
4534 Status = EFI_NOT_FOUND;\r
4535 goto Done;\r
4536 }\r
4537 }\r
82e8c138
ED
4538\r
4539 //\r
4540 // Validate ConfigRequest String.\r
4541 //\r
4542 ErrorPtr = ConfigRequestValidate(ConfigRequest);\r
4543 if (ErrorPtr != NULL) {\r
4544 *Progress = StrStr (StringPtr, ErrorPtr);\r
4545 Status = EFI_INVALID_PARAMETER;\r
4546 goto Done;\r
4547 }\r
4548\r
84f9a9ec 4549 //\r
82e8c138 4550 // Check whether ConfigRequest contains request string.\r
84f9a9ec 4551 //\r
6e3f5b2a 4552 IfrDataParsedFlag = FALSE;\r
82e8c138 4553 if ((HiiHandle != NULL) && !GetElementsFromRequest(ConfigRequest)) {\r
93e3992d 4554 //\r
84f9a9ec 4555 // Get the full request string from IFR when HiiPackage is registered to HiiHandle \r
93e3992d 4556 //\r
6e3f5b2a 4557 IfrDataParsedFlag = TRUE;\r
ae79d2f9 4558 Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, &AccessProgress);\r
84f9a9ec 4559 if (EFI_ERROR (Status)) {\r
ae79d2f9
LG
4560 //\r
4561 // AccessProgress indicates the parsing progress on <ConfigRequest>.\r
4562 // Map it to the progress on <MultiConfigRequest> then return it.\r
4563 //\r
82e8c138 4564 ASSERT (AccessProgress != NULL);\r
ae79d2f9 4565 *Progress = StrStr (StringPtr, AccessProgress);\r
84f9a9ec
LG
4566 goto Done;\r
4567 }\r
1f1cb2f2
LG
4568 //\r
4569 // Not any request block is found.\r
4570 //\r
82e8c138 4571 if (!GetElementsFromRequest(ConfigRequest)) {\r
76c24251 4572 AccessResults = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest);\r
1f1cb2f2
LG
4573 goto NextConfigString;\r
4574 }\r
93e3992d 4575 }\r
4576\r
4577 //\r
cce6230f 4578 // Check whether this ConfigRequest is search from Efi varstore type storage.\r
93e3992d 4579 //\r
cce6230f
ED
4580 Status = GetVarStoreType(Database, ConfigRequest, &IsEfiVarStore, &EfiVarStoreInfo);\r
4581 if (EFI_ERROR (Status)) {\r
4582 goto Done;\r
4583 }\r
4584 \r
4585 if (IsEfiVarStore) {\r
4586 //\r
4587 // Call the GetVariable function to extract settings.\r
4588 //\r
4589 Status = GetConfigRespFromEfiVarStore(This, EfiVarStoreInfo, ConfigRequest, &AccessResults, &AccessProgress);\r
82e8c138 4590 FreePool (EfiVarStoreInfo);\r
74e8963c
DB
4591 if (EFI_ERROR (Status)) {\r
4592 //\r
4593 // AccessProgress indicates the parsing progress on <ConfigRequest>.\r
4594 // Map it to the progress on <MultiConfigRequest> then return it.\r
4595 //\r
4596 *Progress = StrStr (StringPtr, AccessProgress);\r
4597 goto Done;\r
4598 }\r
4599\r
4600 //\r
4601 // For EfiVarstore, call corresponding ConfigAccess protocol to get the AltCfgResp from driver.\r
4602 //\r
4603 Status = gBS->HandleProtocol (\r
4604 DriverHandle,\r
4605 &gEfiHiiConfigAccessProtocolGuid,\r
4606 (VOID **) &ConfigAccess\r
4607 );\r
4608 if (EFI_ERROR (Status)) {\r
4609 //\r
4610 // The driver has EfiVarStore, may not install ConfigAccess protocol.\r
4611 // So ignore the error status in this case.\r
4612 //\r
4613 Status = EFI_SUCCESS;\r
4614 } else {\r
4615 Status = ConfigAccess->ExtractConfig (\r
4616 ConfigAccess,\r
4617 ConfigRequest,\r
4618 &AccessProgressBackup,\r
4619 &AccessResultsBackup\r
4620 );\r
4621 if (!EFI_ERROR(Status)) {\r
4622 //\r
4623 //Merge the AltCfgResp in AccessResultsBackup to AccessResults\r
4624 //\r
4625 if ((AccessResultsBackup != NULL) && (StrStr (AccessResultsBackup, L"&ALTCFG=") != NULL)) {\r
4626 ConigStringSize = StrSize (AccessResults);\r
4627 ConfigStringPtr = StrStr (AccessResultsBackup, L"&GUID=");\r
4628 ConigStringSizeNewsize = StrSize (ConfigStringPtr) + ConigStringSize + sizeof (CHAR16);\r
4629 AccessResults = (EFI_STRING) ReallocatePool (\r
4630 ConigStringSize,\r
4631 ConigStringSizeNewsize,\r
4632 AccessResults);\r
4633 StrCatS (AccessResults, ConigStringSizeNewsize / sizeof (CHAR16), ConfigStringPtr);\r
4634 }\r
4635 } else {\r
4636 //\r
4637 // In the ExtractConfig function of some driver may not support EfiVarStore,\r
4638 // may return error status, just ignore the error status in this case.\r
4639 //\r
4640 Status = EFI_SUCCESS;\r
4641 }\r
4642 if (AccessResultsBackup != NULL) {\r
4643 FreePool (AccessResultsBackup);\r
4644 AccessResultsBackup = NULL;\r
4645 }\r
4646 }\r
cce6230f
ED
4647 } else {\r
4648 //\r
4649 // Call corresponding ConfigAccess protocol to extract settings\r
4650 //\r
4651 Status = gBS->HandleProtocol (\r
4652 DriverHandle,\r
4653 &gEfiHiiConfigAccessProtocolGuid,\r
4654 (VOID **) &ConfigAccess\r
4655 );\r
a115a9ef
EC
4656 if (EFI_ERROR (Status)) {\r
4657 goto Done;\r
4658 }\r
93e3992d 4659\r
cce6230f
ED
4660 Status = ConfigAccess->ExtractConfig (\r
4661 ConfigAccess,\r
4662 ConfigRequest,\r
4663 &AccessProgress,\r
4664 &AccessResults\r
4665 );\r
4666 }\r
93e3992d 4667 if (EFI_ERROR (Status)) {\r
4668 //\r
4669 // AccessProgress indicates the parsing progress on <ConfigRequest>.\r
4670 // Map it to the progress on <MultiConfigRequest> then return it.\r
4671 //\r
8d00a0f1 4672 *Progress = StrStr (StringPtr, AccessProgress);\r
84f9a9ec 4673 goto Done;\r
93e3992d 4674 }\r
4675\r
4676 //\r
8d00a0f1 4677 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'\r
4678 // which seperates the first <ConfigAltResp> and the following ones.\r
93e3992d 4679 //\r
4680 ASSERT (*AccessProgress == 0);\r
8d00a0f1 4681\r
84f9a9ec
LG
4682 //\r
4683 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle \r
4684 //\r
ae79d2f9
LG
4685 if (!IfrDataParsedFlag && HiiHandle != NULL) {\r
4686 Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, NULL);\r
4687 ASSERT_EFI_ERROR (Status);\r
84f9a9ec 4688 }\r
ae79d2f9 4689\r
84f9a9ec
LG
4690 FreePool (DevicePath);\r
4691 DevicePath = NULL;\r
84f9a9ec 4692\r
ae79d2f9
LG
4693 if (DefaultResults != NULL) {\r
4694 Status = MergeDefaultString (&AccessResults, DefaultResults);\r
4695 ASSERT_EFI_ERROR (Status);\r
4696 FreePool (DefaultResults);\r
4697 DefaultResults = NULL;\r
4698 }\r
4699 \r
82e8c138 4700NextConfigString:\r
8d00a0f1 4701 if (!FirstElement) {\r
4702 Status = AppendToMultiString (Results, L"&");\r
4703 ASSERT_EFI_ERROR (Status);\r
4704 }\r
4705 \r
93e3992d 4706 Status = AppendToMultiString (Results, AccessResults);\r
4707 ASSERT_EFI_ERROR (Status);\r
8d00a0f1 4708\r
4709 FirstElement = FALSE;\r
84f9a9ec 4710\r
676df92c 4711 FreePool (AccessResults);\r
93e3992d 4712 AccessResults = NULL;\r
676df92c 4713 FreePool (ConfigRequest);\r
93e3992d 4714 ConfigRequest = NULL;\r
4715\r
4716 //\r
4717 // Go to next <ConfigRequest> (skip '&').\r
4718 //\r
4719 StringPtr += Length;\r
4720 if (*StringPtr == 0) {\r
4721 *Progress = StringPtr;\r
4722 break;\r
4723 }\r
4724\r
4725 StringPtr++;\r
93e3992d 4726 }\r
4727\r
84f9a9ec
LG
4728Done:\r
4729 if (EFI_ERROR (Status)) {\r
4730 FreePool (*Results);\r
6e3f5b2a 4731 *Results = NULL;\r
84f9a9ec
LG
4732 }\r
4733 \r
4734 if (ConfigRequest != NULL) {\r
4735 FreePool (ConfigRequest);\r
4736 }\r
4737 \r
4738 if (AccessResults != NULL) {\r
4739 FreePool (AccessResults);\r
4740 }\r
4741 \r
4742 if (DefaultResults != NULL) {\r
4743 FreePool (DefaultResults);\r
4744 }\r
4745 \r
4746 if (DevicePath != NULL) {\r
4747 FreePool (DevicePath);\r
4748 } \r
93e3992d 4749\r
84f9a9ec 4750 return Status;\r
93e3992d 4751}\r
4752\r
4753\r
4754/**\r
4755 This function allows the caller to request the current configuration for the\r
4756 entirety of the current HII database and returns the data in a\r
4757 null-terminated Unicode string.\r
4758\r
4759 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
4760 instance.\r
4761 @param Results Null-terminated Unicode string in\r
4762 <MultiConfigAltResp> format which has all values\r
c0a3c3da
ED
4763 filled in for the entirety of the current HII \r
4764 database. String to be allocated by the called \r
4765 function. De-allocation is up to the caller.\r
93e3992d 4766\r
4767 @retval EFI_SUCCESS The Results string is filled with the values\r
4768 corresponding to all requested names.\r
4769 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the\r
4770 results that must be stored awaiting possible\r
4771 future protocols.\r
4772 @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results\r
4773 parameter would result in this type of error.\r
4774\r
4775**/\r
4776EFI_STATUS\r
4777EFIAPI\r
4778HiiConfigRoutingExportConfig (\r
4779 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
4780 OUT EFI_STRING *Results\r
4781 )\r
4782{\r
93e3992d 4783 EFI_STATUS Status;\r
93e3992d 4784 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
84f9a9ec
LG
4785 EFI_STRING AccessResults;\r
4786 EFI_STRING Progress;\r
6e3f5b2a 4787 EFI_STRING StringPtr;\r
ae79d2f9 4788 EFI_STRING ConfigRequest;\r
8d00a0f1 4789 UINTN Index;\r
4790 EFI_HANDLE *ConfigAccessHandles;\r
4791 UINTN NumberConfigAccessHandles;\r
4792 BOOLEAN FirstElement;\r
84f9a9ec
LG
4793 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
4794 EFI_HII_HANDLE HiiHandle;\r
4795 EFI_STRING DefaultResults;\r
4796 HII_DATABASE_PRIVATE_DATA *Private;\r
4797 LIST_ENTRY *Link;\r
4798 HII_DATABASE_RECORD *Database;\r
4799 UINT8 *DevicePathPkg;\r
4800 UINT8 *CurrentDevicePath;\r
ae79d2f9 4801 BOOLEAN IfrDataParsedFlag;\r
93e3992d 4802\r
4803 if (This == NULL || Results == NULL) {\r
4804 return EFI_INVALID_PARAMETER;\r
4805 }\r
4806\r
84f9a9ec
LG
4807 Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
4808\r
93e3992d 4809 //\r
4810 // Allocate a fix length of memory to store Results. Reallocate memory for\r
4811 // Results if this fix length is insufficient.\r
4812 //\r
4813 *Results = (EFI_STRING) AllocateZeroPool (MAX_STRING_LENGTH);\r
4814 if (*Results == NULL) {\r
4815 return EFI_OUT_OF_RESOURCES;\r
4816 }\r
4817\r
8d00a0f1 4818 NumberConfigAccessHandles = 0;\r
4819 Status = gBS->LocateHandleBuffer (\r
4820 ByProtocol,\r
4821 &gEfiHiiConfigAccessProtocolGuid,\r
4822 NULL,\r
4823 &NumberConfigAccessHandles,\r
4824 &ConfigAccessHandles\r
4825 );\r
4826 if (EFI_ERROR (Status)) {\r
4827 return Status;\r
4828 }\r
93e3992d 4829\r
8d00a0f1 4830 FirstElement = TRUE;\r
93e3992d 4831\r
8d00a0f1 4832 for (Index = 0; Index < NumberConfigAccessHandles; Index++) {\r
93e3992d 4833 Status = gBS->HandleProtocol (\r
8d00a0f1 4834 ConfigAccessHandles[Index],\r
93e3992d 4835 &gEfiHiiConfigAccessProtocolGuid,\r
8d00a0f1 4836 (VOID **) &ConfigAccess\r
93e3992d 4837 );\r
8d00a0f1 4838 if (EFI_ERROR (Status)) {\r
4839 continue;\r
4840 }\r
93e3992d 4841\r
84f9a9ec
LG
4842 //\r
4843 // Get DevicePath and HiiHandle for this ConfigAccess driver handle\r
4844 //\r
ae79d2f9 4845 IfrDataParsedFlag = FALSE;\r
84f9a9ec
LG
4846 Progress = NULL;\r
4847 HiiHandle = NULL;\r
84f9a9ec 4848 DefaultResults = NULL;\r
8567300a 4849 Database = NULL;\r
ae79d2f9 4850 ConfigRequest = NULL;\r
84f9a9ec 4851 DevicePath = DevicePathFromHandle (ConfigAccessHandles[Index]);\r
84f9a9ec
LG
4852 if (DevicePath != NULL) {\r
4853 for (Link = Private->DatabaseList.ForwardLink;\r
4854 Link != &Private->DatabaseList;\r
4855 Link = Link->ForwardLink\r
4856 ) {\r
4857 Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
4858 if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r
4859 CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r
6e3f5b2a 4860 if (CompareMem (\r
84f9a9ec
LG
4861 DevicePath,\r
4862 CurrentDevicePath,\r
6e3f5b2a
LG
4863 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath)\r
4864 ) == 0) {\r
84f9a9ec
LG
4865 HiiHandle = Database->Handle;\r
4866 break;\r
4867 }\r
4868 }\r
4869 }\r
4870 }\r
4871\r
93e3992d 4872 Status = ConfigAccess->ExtractConfig (\r
4873 ConfigAccess,\r
6e3f5b2a 4874 NULL,\r
84f9a9ec 4875 &Progress,\r
93e3992d 4876 &AccessResults\r
4877 );\r
ae79d2f9 4878 if (EFI_ERROR (Status)) {\r
6e3f5b2a
LG
4879 //\r
4880 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle \r
4881 //\r
4882 if (HiiHandle != NULL && DevicePath != NULL) {\r
ae79d2f9
LG
4883 IfrDataParsedFlag = TRUE;\r
4884 Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, NULL);\r
4885 //\r
4886 // Get the full request string to get the Current setting again.\r
4887 //\r
4888 if (!EFI_ERROR (Status) && ConfigRequest != NULL) {\r
4889 Status = ConfigAccess->ExtractConfig (\r
4890 ConfigAccess,\r
4891 ConfigRequest,\r
4892 &Progress,\r
4893 &AccessResults\r
4894 );\r
4895 FreePool (ConfigRequest);\r
4896 } else {\r
4897 Status = EFI_NOT_FOUND;\r
4898 }\r
4899 }\r
4900 }\r
4901\r
4902 if (!EFI_ERROR (Status)) {\r
4903 //\r
4904 // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle \r
4905 //\r
4906 if (!IfrDataParsedFlag && HiiHandle != NULL && DevicePath != NULL) {\r
6e3f5b2a
LG
4907 StringPtr = StrStr (AccessResults, L"&GUID=");\r
4908 if (StringPtr != NULL) {\r
4909 *StringPtr = 0;\r
4910 }\r
82e8c138 4911 if (GetElementsFromRequest (AccessResults)) {\r
ae79d2f9
LG
4912 Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &AccessResults, &DefaultResults, NULL);\r
4913 ASSERT_EFI_ERROR (Status);\r
6e3f5b2a
LG
4914 }\r
4915 if (StringPtr != NULL) {\r
4916 *StringPtr = L'&';\r
4917 }\r
4918 }\r
84f9a9ec
LG
4919 //\r
4920 // Merge the default sting from IFR code into the got setting from driver.\r
4921 //\r
4922 if (DefaultResults != NULL) {\r
8567300a
LG
4923 Status = MergeDefaultString (&AccessResults, DefaultResults);\r
4924 ASSERT_EFI_ERROR (Status);\r
84f9a9ec 4925 FreePool (DefaultResults);\r
8567300a 4926 DefaultResults = NULL;\r
84f9a9ec
LG
4927 }\r
4928 \r
8d00a0f1 4929 //\r
4930 // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'\r
4931 // which seperates the first <ConfigAltResp> and the following ones. \r
4932 //\r
4933 if (!FirstElement) {\r
4934 Status = AppendToMultiString (Results, L"&");\r
4935 ASSERT_EFI_ERROR (Status);\r
676df92c 4936 }\r
8d00a0f1 4937 \r
4938 Status = AppendToMultiString (Results, AccessResults);\r
4939 ASSERT_EFI_ERROR (Status);\r
93e3992d 4940\r
8d00a0f1 4941 FirstElement = FALSE;\r
4942 \r
4943 FreePool (AccessResults);\r
4944 AccessResults = NULL;\r
4945 }\r
93e3992d 4946 }\r
f4113e1f 4947 FreePool (ConfigAccessHandles);\r
93e3992d 4948\r
8d00a0f1 4949 return EFI_SUCCESS; \r
93e3992d 4950}\r
4951\r
4952\r
4953/**\r
4954 This function processes the results of processing forms and routes it to the\r
4955 appropriate handlers or storage.\r
4956\r
4957 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
4958 instance.\r
4959 @param Configuration A null-terminated Unicode string in\r
4960 <MulltiConfigResp> format.\r
4961 @param Progress A pointer to a string filled in with the offset of\r
4962 the most recent & before the first failing name /\r
4963 value pair (or the beginning of the string if the\r
4964 failure is in the first name / value pair) or the\r
4965 terminating NULL if all was successful.\r
4966\r
4967 @retval EFI_SUCCESS The results have been distributed or are awaiting\r
4968 distribution.\r
4969 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the\r
4970 results that must be stored awaiting possible\r
4971 future protocols.\r
4972 @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter\r
4973 would result in this type of error.\r
4974 @retval EFI_NOT_FOUND Target for the specified routing data was not\r
4975 found.\r
4976\r
4977**/\r
4978EFI_STATUS\r
4979EFIAPI\r
813acf3a 4980HiiConfigRoutingRouteConfig (\r
93e3992d 4981 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
4982 IN CONST EFI_STRING Configuration,\r
4983 OUT EFI_STRING *Progress\r
4984 )\r
4985{\r
84f9a9ec 4986 HII_DATABASE_PRIVATE_DATA *Private;\r
93e3992d 4987 EFI_STRING StringPtr;\r
4988 EFI_STRING ConfigResp;\r
4989 UINTN Length;\r
4990 EFI_STATUS Status;\r
4991 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
326c6b71 4992 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
84f9a9ec
LG
4993 LIST_ENTRY *Link;\r
4994 HII_DATABASE_RECORD *Database;\r
4995 UINT8 *DevicePathPkg;\r
4996 UINT8 *CurrentDevicePath;\r
93e3992d 4997 EFI_HANDLE DriverHandle;\r
4998 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
4999 EFI_STRING AccessProgress;\r
cce6230f
ED
5000 EFI_IFR_VARSTORE_EFI *EfiVarStoreInfo;\r
5001 BOOLEAN IsEfiVarstore;\r
7248790e 5002 UINTN DevicePathSize;\r
93e3992d 5003\r
5004 if (This == NULL || Progress == NULL) {\r
5005 return EFI_INVALID_PARAMETER;\r
5006 }\r
5007\r
5008 if (Configuration == NULL) {\r
5009 *Progress = NULL;\r
5010 return EFI_INVALID_PARAMETER;\r
5011 }\r
5012\r
84f9a9ec 5013 Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
93e3992d 5014 StringPtr = Configuration;\r
5015 *Progress = StringPtr;\r
cce6230f
ED
5016 Database = NULL;\r
5017 AccessProgress = NULL;\r
5018 EfiVarStoreInfo= NULL;\r
5019 IsEfiVarstore = FALSE;\r
93e3992d 5020\r
5021 //\r
5022 // The first element of <MultiConfigResp> should be\r
5023 // <GuidHdr>, which is in 'GUID='<Guid> syntax.\r
5024 //\r
5025 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
5026 return EFI_INVALID_PARAMETER;\r
5027 }\r
5028\r
5029 while (*StringPtr != 0 && StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) == 0) {\r
5030 //\r
5031 // If parsing error, set Progress to the beginning of the <MultiConfigResp>\r
5032 // or most recent & before the error.\r
5033 //\r
5034 if (StringPtr == Configuration) {\r
5035 *Progress = StringPtr;\r
5036 } else {\r
5037 *Progress = StringPtr - 1;\r
5038 }\r
5039\r
5040 //\r
5041 // Process each <ConfigResp> of <MultiConfigResp>\r
5042 //\r
5043 Length = CalculateConfigStringLen (StringPtr);\r
5044 ConfigResp = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), StringPtr);\r
5045 if (ConfigResp == NULL) {\r
5046 return EFI_OUT_OF_RESOURCES;\r
5047 }\r
5048 //\r
5049 // Append '\0' to the end of ConfigRequest\r
5050 //\r
5051 *(ConfigResp + Length) = 0;\r
5052\r
5053 //\r
5054 // Get the UEFI device path\r
5055 //\r
5056 Status = GetDevicePath (ConfigResp, (UINT8 **) &DevicePath);\r
5057 if (EFI_ERROR (Status)) {\r
676df92c 5058 FreePool (ConfigResp);\r
93e3992d 5059 return Status;\r
5060 }\r
5061\r
5062 //\r
84f9a9ec
LG
5063 // Find driver which matches the routing data.\r
5064 //\r
5065 DriverHandle = NULL;\r
84f9a9ec
LG
5066 for (Link = Private->DatabaseList.ForwardLink;\r
5067 Link != &Private->DatabaseList;\r
5068 Link = Link->ForwardLink\r
5069 ) {\r
5070 Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
5071\r
5072 if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r
5073 CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r
7248790e 5074 DevicePathSize = GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath);\r
8aaab674 5075 if ((CompareMem (DevicePath,CurrentDevicePath,DevicePathSize) == 0) && IsThisPackageList(Database, ConfigResp)) {\r
84f9a9ec
LG
5076 DriverHandle = Database->DriverHandle;\r
5077 break;\r
5078 }\r
5079 }\r
5080 }\r
93e3992d 5081\r
84f9a9ec
LG
5082 //\r
5083 // Try to find driver handle by device path.\r
5084 //\r
5085 if (DriverHandle == NULL) {\r
5086 TempDevicePath = DevicePath;\r
5087 Status = gBS->LocateDevicePath (\r
5088 &gEfiDevicePathProtocolGuid,\r
5089 &TempDevicePath,\r
5090 &DriverHandle\r
5091 );\r
5092 if (EFI_ERROR (Status) || (DriverHandle == NULL)) {\r
5093 //\r
5094 // Routing data does not match any known driver.\r
5095 // Set Progress to the 'G' in "GUID" of the routing header.\r
5096 //\r
5097 FreePool (DevicePath);\r
5098 *Progress = StringPtr;\r
5099 FreePool (ConfigResp);\r
5100 return EFI_NOT_FOUND;\r
5101 }\r
93e3992d 5102 }\r
5103\r
84f9a9ec
LG
5104 FreePool (DevicePath);\r
5105\r
93e3992d 5106 //\r
cce6230f 5107 // Check whether this ConfigRequest is search from Efi varstore type storage.\r
93e3992d 5108 //\r
cce6230f
ED
5109 Status = GetVarStoreType(Database, ConfigResp, &IsEfiVarstore, &EfiVarStoreInfo);\r
5110 if (EFI_ERROR (Status)) {\r
5111 return Status;\r
5112 }\r
93e3992d 5113\r
cce6230f
ED
5114 if (IsEfiVarstore) {\r
5115 //\r
5116 // Call the SetVariable function to route settings.\r
5117 // \r
5118 Status = RouteConfigRespForEfiVarStore(This, EfiVarStoreInfo, ConfigResp, &AccessProgress);\r
5119 FreePool (EfiVarStoreInfo);\r
5120 } else {\r
5121 //\r
5122 // Call corresponding ConfigAccess protocol to route settings\r
5123 //\r
5124 Status = gBS->HandleProtocol (\r
5125 DriverHandle,\r
5126 &gEfiHiiConfigAccessProtocolGuid,\r
5127 (VOID **) &ConfigAccess\r
5128 );\r
1f9f60ad
DB
5129 if (EFI_ERROR (Status)) {\r
5130 *Progress = StringPtr;\r
5131 FreePool (ConfigResp);\r
5132 return EFI_NOT_FOUND;\r
5133 }\r
93e3992d 5134\r
cce6230f
ED
5135 Status = ConfigAccess->RouteConfig (\r
5136 ConfigAccess,\r
5137 ConfigResp,\r
5138 &AccessProgress\r
5139 );\r
5140 }\r
93e3992d 5141 if (EFI_ERROR (Status)) {\r
523f48e7 5142 ASSERT (AccessProgress != NULL);\r
93e3992d 5143 //\r
5144 // AccessProgress indicates the parsing progress on <ConfigResp>.\r
5145 // Map it to the progress on <MultiConfigResp> then return it.\r
5146 //\r
8d00a0f1 5147 *Progress = StrStr (StringPtr, AccessProgress);\r
93e3992d 5148\r
676df92c 5149 FreePool (ConfigResp);\r
93e3992d 5150 return Status;\r
5151 }\r
5152\r
676df92c 5153 FreePool (ConfigResp);\r
93e3992d 5154 ConfigResp = NULL;\r
5155\r
5156 //\r
5157 // Go to next <ConfigResp> (skip '&').\r
5158 //\r
5159 StringPtr += Length;\r
5160 if (*StringPtr == 0) {\r
5161 *Progress = StringPtr;\r
5162 break;\r
5163 }\r
5164\r
5165 StringPtr++;\r
5166\r
5167 }\r
5168\r
5169 return EFI_SUCCESS;\r
93e3992d 5170}\r
5171\r
5172\r
5173/**\r
5174 This helper function is to be called by drivers to map configuration data\r
5175 stored in byte array ("block") formats such as UEFI Variables into current\r
5176 configuration strings.\r
5177\r
5178 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
5179 instance.\r
5180 @param ConfigRequest A null-terminated Unicode string in\r
5181 <ConfigRequest> format.\r
5182 @param Block Array of bytes defining the block's configuration.\r
5183 @param BlockSize Length in bytes of Block.\r
5184 @param Config Filled-in configuration string. String allocated\r
5185 by the function. Returned only if call is\r
84f9a9ec 5186 successful. It is <ConfigResp> string format.\r
93e3992d 5187 @param Progress A pointer to a string filled in with the offset of\r
5188 the most recent & before the first failing\r
5189 name/value pair (or the beginning of the string if\r
5190 the failure is in the first name / value pair) or\r
5191 the terminating NULL if all was successful.\r
5192\r
5193 @retval EFI_SUCCESS The request succeeded. Progress points to the null\r
5194 terminator at the end of the ConfigRequest\r
5195 string.\r
5196 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress\r
5197 points to the first character of ConfigRequest.\r
5198 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or\r
5199 Block parameter would result in this type of\r
5200 error. Progress points to the first character of\r
5201 ConfigRequest.\r
5202 @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.\r
5203 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.\r
5204 Block is left updated and Progress points at\r
5205 the "&" preceding the first non-<BlockName>.\r
5206\r
5207**/\r
5208EFI_STATUS\r
5209EFIAPI\r
5210HiiBlockToConfig (\r
5211 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
5212 IN CONST EFI_STRING ConfigRequest,\r
5213 IN CONST UINT8 *Block,\r
5214 IN CONST UINTN BlockSize,\r
5215 OUT EFI_STRING *Config,\r
5216 OUT EFI_STRING *Progress\r
5217 )\r
5218{\r
84f9a9ec 5219 HII_DATABASE_PRIVATE_DATA *Private;\r
93e3992d 5220 EFI_STRING StringPtr;\r
5221 UINTN Length;\r
5222 EFI_STATUS Status;\r
5223 EFI_STRING TmpPtr;\r
5224 UINT8 *TmpBuffer;\r
5225 UINTN Offset;\r
5226 UINTN Width;\r
5227 UINT8 *Value;\r
5228 EFI_STRING ValueStr;\r
5229 EFI_STRING ConfigElement;\r
63d55bb9
LG
5230 UINTN Index;\r
5231 UINT8 *TemBuffer;\r
5232 CHAR16 *TemString;\r
41ff10dc 5233 CHAR16 TemChar;\r
93e3992d 5234\r
4e1005ec
ED
5235 TmpBuffer = NULL;\r
5236\r
93e3992d 5237 if (This == NULL || Progress == NULL || Config == NULL) {\r
5238 return EFI_INVALID_PARAMETER;\r
5239 }\r
5240\r
5241 if (Block == NULL || ConfigRequest == NULL) {\r
5242 *Progress = ConfigRequest;\r
5243 return EFI_INVALID_PARAMETER;\r
5244 }\r
5245\r
84f9a9ec
LG
5246\r
5247 Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
5248 ASSERT (Private != NULL);\r
5249\r
93e3992d 5250 StringPtr = ConfigRequest;\r
5251 ValueStr = NULL;\r
5252 Value = NULL;\r
5253 ConfigElement = NULL;\r
5254\r
5255 //\r
5256 // Allocate a fix length of memory to store Results. Reallocate memory for\r
5257 // Results if this fix length is insufficient.\r
5258 //\r
5259 *Config = (EFI_STRING) AllocateZeroPool (MAX_STRING_LENGTH);\r
5260 if (*Config == NULL) {\r
5261 return EFI_OUT_OF_RESOURCES;\r
5262 }\r
5263\r
5264 //\r
5265 // Jump <ConfigHdr>\r
5266 //\r
5267 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
5268 *Progress = StringPtr;\r
5269 Status = EFI_INVALID_PARAMETER;\r
5270 goto Exit;\r
5271 }\r
5272 while (*StringPtr != 0 && StrnCmp (StringPtr, L"PATH=", StrLen (L"PATH=")) != 0) {\r
5273 StringPtr++;\r
5274 }\r
5275 if (*StringPtr == 0) {\r
76c24251 5276 *Progress = StringPtr - 1;\r
93e3992d 5277 Status = EFI_INVALID_PARAMETER;\r
5278 goto Exit;\r
5279 }\r
08e6463a 5280\r
5281 while (*StringPtr != L'&' && *StringPtr != 0) {\r
5282 StringPtr++;\r
5283 }\r
5284 if (*StringPtr == 0) {\r
41ff10dc 5285 *Progress = StringPtr;\r
41ff10dc
ED
5286\r
5287 AppendToMultiString(Config, ConfigRequest);\r
5288 HiiToLower (*Config);\r
5289\r
96179cb3 5290 return EFI_SUCCESS;\r
08e6463a 5291 }\r
5292 //\r
5293 // Skip '&'\r
5294 //\r
5295 StringPtr++;\r
93e3992d 5296\r
5297 //\r
5298 // Copy <ConfigHdr> and an additional '&' to <ConfigResp>\r
5299 //\r
41ff10dc
ED
5300 TemChar = *StringPtr;\r
5301 *StringPtr = '\0';\r
5302 AppendToMultiString(Config, ConfigRequest);\r
5303 *StringPtr = TemChar;\r
93e3992d 5304\r
5305 //\r
5306 // Parse each <RequestElement> if exists\r
5307 // Only <BlockName> format is supported by this help function.\r
5308 // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>\r
5309 //\r
5310 while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {\r
5311 //\r
5312 // Back up the header of one <BlockName>\r
5313 //\r
5314 TmpPtr = StringPtr;\r
5315\r
5316 StringPtr += StrLen (L"OFFSET=");\r
5317 //\r
5318 // Get Offset\r
5319 //\r
5320 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
3a530010 5321 if (EFI_ERROR (Status)) {\r
46c3efbb 5322 *Progress = TmpPtr - 1;\r
93e3992d 5323 goto Exit;\r
5324 }\r
5325 Offset = 0;\r
5326 CopyMem (\r
5327 &Offset,\r
5328 TmpBuffer,\r
5329 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
5330 );\r
676df92c 5331 FreePool (TmpBuffer);\r
93e3992d 5332\r
5333 StringPtr += Length;\r
5334 if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
46c3efbb 5335 *Progress = TmpPtr - 1;\r
93e3992d 5336 Status = EFI_INVALID_PARAMETER;\r
5337 goto Exit;\r
5338 }\r
5339 StringPtr += StrLen (L"&WIDTH=");\r
5340\r
5341 //\r
5342 // Get Width\r
5343 //\r
5344 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
3a530010 5345 if (EFI_ERROR (Status)) {\r
46c3efbb 5346 *Progress = TmpPtr - 1;\r
93e3992d 5347 goto Exit;\r
5348 }\r
5349 Width = 0;\r
5350 CopyMem (\r
5351 &Width,\r
5352 TmpBuffer,\r
5353 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
5354 );\r
676df92c 5355 FreePool (TmpBuffer);\r
93e3992d 5356\r
5357 StringPtr += Length;\r
5358 if (*StringPtr != 0 && *StringPtr != L'&') {\r
46c3efbb 5359 *Progress = TmpPtr - 1;\r
93e3992d 5360 Status = EFI_INVALID_PARAMETER;\r
5361 goto Exit;\r
5362 }\r
5363\r
5364 //\r
5365 // Calculate Value and convert it to hex string.\r
5366 //\r
5367 if (Offset + Width > BlockSize) {\r
5368 *Progress = StringPtr;\r
5369 Status = EFI_DEVICE_ERROR;\r
5370 goto Exit;\r
5371 }\r
5372\r
5373 Value = (UINT8 *) AllocateZeroPool (Width);\r
5374 if (Value == NULL) {\r
5375 *Progress = ConfigRequest;\r
5376 Status = EFI_OUT_OF_RESOURCES;\r
5377 goto Exit;\r
5378 }\r
5379\r
5380 CopyMem (Value, (UINT8 *) Block + Offset, Width);\r
5381\r
5382 Length = Width * 2 + 1;\r
5383 ValueStr = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));\r
5384 if (ValueStr == NULL) {\r
5385 *Progress = ConfigRequest;\r
5386 Status = EFI_OUT_OF_RESOURCES;\r
5387 goto Exit;\r
5388 }\r
63d55bb9
LG
5389 \r
5390 TemString = ValueStr;\r
5391 TemBuffer = Value + Width - 1;\r
5392 for (Index = 0; Index < Width; Index ++, TemBuffer --) {\r
5393 TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
5394 }\r
813acf3a 5395\r
676df92c 5396 FreePool (Value);\r
93e3992d 5397 Value = NULL;\r
5398\r
5399 //\r
5400 // Build a ConfigElement\r
5401 //\r
5402 Length += StringPtr - TmpPtr + 1 + StrLen (L"VALUE=");\r
5403 ConfigElement = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));\r
5404 if (ConfigElement == NULL) {\r
5405 Status = EFI_OUT_OF_RESOURCES;\r
5406 goto Exit;\r
5407 }\r
5408 CopyMem (ConfigElement, TmpPtr, (StringPtr - TmpPtr + 1) * sizeof (CHAR16));\r
5409 if (*StringPtr == 0) {\r
5410 *(ConfigElement + (StringPtr - TmpPtr)) = L'&';\r
5411 }\r
5412 *(ConfigElement + (StringPtr - TmpPtr) + 1) = 0;\r
5ad66ec6
DB
5413 StrCatS (ConfigElement, Length, L"VALUE=");\r
5414 StrCatS (ConfigElement, Length, ValueStr);\r
93e3992d 5415\r
5416 AppendToMultiString (Config, ConfigElement);\r
5417\r
676df92c 5418 FreePool (ConfigElement);\r
5419 FreePool (ValueStr);\r
93e3992d 5420 ConfigElement = NULL;\r
5421 ValueStr = NULL;\r
5422\r
5423 //\r
5424 // If '\0', parsing is finished. Otherwise skip '&' to continue\r
5425 //\r
5426 if (*StringPtr == 0) {\r
5427 break;\r
5428 }\r
5429 AppendToMultiString (Config, L"&");\r
5430 StringPtr++;\r
5431\r
5432 }\r
5433\r
5434 if (*StringPtr != 0) {\r
5435 *Progress = StringPtr - 1;\r
5436 Status = EFI_INVALID_PARAMETER;\r
5437 goto Exit;\r
5438 }\r
84f9a9ec
LG
5439 \r
5440 HiiToLower (*Config);\r
93e3992d 5441 *Progress = StringPtr;\r
5442 return EFI_SUCCESS;\r
5443\r
5444Exit:\r
76c24251 5445 if (*Config != NULL) {\r
1f1cb2f2
LG
5446 FreePool (*Config);\r
5447 *Config = NULL;\r
76c24251 5448 }\r
676df92c 5449 if (ValueStr != NULL) {\r
5450 FreePool (ValueStr);\r
5451 }\r
5452 if (Value != NULL) {\r
5453 FreePool (Value);\r
5454 }\r
69367b5b 5455 if (ConfigElement != NULL) {\r
676df92c 5456 FreePool (ConfigElement);\r
5457 }\r
93e3992d 5458\r
5459 return Status;\r
5460\r
5461}\r
5462\r
5463\r
5464/**\r
5465 This helper function is to be called by drivers to map configuration strings\r
5466 to configurations stored in byte array ("block") formats such as UEFI Variables.\r
5467\r
5468 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
5469 instance.\r
5470 @param ConfigResp A null-terminated Unicode string in <ConfigResp>\r
771ececd 5471 format.\r
93e3992d 5472 @param Block A possibly null array of bytes representing the\r
5473 current block. Only bytes referenced in the\r
5474 ConfigResp string in the block are modified. If\r
5475 this parameter is null or if the *BlockSize\r
5476 parameter is (on input) shorter than required by\r
5477 the Configuration string, only the BlockSize\r
5478 parameter is updated and an appropriate status\r
5479 (see below) is returned.\r
5480 @param BlockSize The length of the Block in units of UINT8. On\r
5481 input, this is the size of the Block. On output,\r
c0a3c3da
ED
5482 if successful, contains the largest index of the\r
5483 modified byte in the Block, or the required buffer\r
5484 size if the Block is not large enough.\r
93e3992d 5485 @param Progress On return, points to an element of the ConfigResp\r
5486 string filled in with the offset of the most\r
5487 recent '&' before the first failing name / value\r
5488 pair (or the beginning of the string if the\r
5489 failure is in the first name / value pair) or the\r
5490 terminating NULL if all was successful.\r
5491\r
5492 @retval EFI_SUCCESS The request succeeded. Progress points to the null\r
5493 terminator at the end of the ConfigResp string.\r
5494 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress\r
5495 points to the first character of ConfigResp.\r
5496 @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or\r
5497 Block parameter would result in this type of\r
5498 error. Progress points to the first character of\r
5499 ConfigResp.\r
5500 @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /\r
5501 value pair. Block is left updated and\r
5502 Progress points at the '&' preceding the first\r
5503 non-<BlockName>.\r
c0a3c3da
ED
5504 @retval EFI_BUFFER_TOO_SMALL Block not large enough. Progress undefined. \r
5505 BlockSize is updated with the required buffer size.\r
09b79417
LG
5506 @retval EFI_NOT_FOUND Target for the specified routing data was not found.\r
5507 Progress points to the "G" in "GUID" of the errant\r
5508 routing data.\r
93e3992d 5509\r
5510**/\r
5511EFI_STATUS\r
5512EFIAPI\r
5513HiiConfigToBlock (\r
5514 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
5515 IN CONST EFI_STRING ConfigResp,\r
5516 IN OUT UINT8 *Block,\r
5517 IN OUT UINTN *BlockSize,\r
5518 OUT EFI_STRING *Progress\r
5519 )\r
5520{\r
5521 HII_DATABASE_PRIVATE_DATA *Private;\r
5522 EFI_STRING StringPtr;\r
46c3efbb 5523 EFI_STRING TmpPtr;\r
93e3992d 5524 UINTN Length;\r
5525 EFI_STATUS Status;\r
5526 UINT8 *TmpBuffer;\r
5527 UINTN Offset;\r
5528 UINTN Width;\r
5529 UINT8 *Value;\r
5530 UINTN BufferSize;\r
09b79417 5531 UINTN MaxBlockSize;\r
93e3992d 5532\r
4e1005ec
ED
5533 TmpBuffer = NULL;\r
5534\r
93e3992d 5535 if (This == NULL || BlockSize == NULL || Progress == NULL) {\r
5536 return EFI_INVALID_PARAMETER;\r
5537 }\r
5538\r
09b79417
LG
5539 *Progress = ConfigResp;\r
5540 if (ConfigResp == NULL) {\r
93e3992d 5541 return EFI_INVALID_PARAMETER;\r
5542 }\r
5543\r
5544 Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
5545 ASSERT (Private != NULL);\r
5546\r
5547 StringPtr = ConfigResp;\r
5548 BufferSize = *BlockSize;\r
5549 Value = NULL;\r
09b79417 5550 MaxBlockSize = 0;\r
93e3992d 5551\r
5552 //\r
5553 // Jump <ConfigHdr>\r
5554 //\r
5555 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
5556 *Progress = StringPtr;\r
5557 Status = EFI_INVALID_PARAMETER;\r
5558 goto Exit;\r
5559 }\r
5560 while (*StringPtr != 0 && StrnCmp (StringPtr, L"PATH=", StrLen (L"PATH=")) != 0) {\r
5561 StringPtr++;\r
5562 }\r
5563 if (*StringPtr == 0) {\r
5564 *Progress = StringPtr;\r
5565 Status = EFI_INVALID_PARAMETER;\r
5566 goto Exit;\r
5567 }\r
08e6463a 5568\r
5569 while (*StringPtr != L'&' && *StringPtr != 0) {\r
5570 StringPtr++;\r
5571 }\r
5572 if (*StringPtr == 0) {\r
5573 *Progress = StringPtr;\r
5574 Status = EFI_INVALID_PARAMETER;\r
5575 goto Exit;\r
5576 }\r
93e3992d 5577\r
5578 //\r
5579 // Parse each <ConfigElement> if exists\r
edae8d2d 5580 // Only '&'<BlockConfig> format is supported by this help function.\r
93e3992d 5581 // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>\r
5582 //\r
edae8d2d 5583 while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) {\r
46c3efbb 5584 TmpPtr = StringPtr;\r
edae8d2d 5585 StringPtr += StrLen (L"&OFFSET=");\r
93e3992d 5586 //\r
5587 // Get Offset\r
5588 //\r
5589 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
7c1bc8d6 5590 if (EFI_ERROR (Status)) {\r
46c3efbb 5591 *Progress = TmpPtr;\r
93e3992d 5592 goto Exit;\r
5593 }\r
5594 Offset = 0;\r
5595 CopyMem (\r
5596 &Offset,\r
5597 TmpBuffer,\r
5598 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
5599 );\r
676df92c 5600 FreePool (TmpBuffer);\r
93e3992d 5601\r
5602 StringPtr += Length;\r
5603 if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
46c3efbb 5604 *Progress = TmpPtr;\r
93e3992d 5605 Status = EFI_INVALID_PARAMETER;\r
5606 goto Exit;\r
5607 }\r
5608 StringPtr += StrLen (L"&WIDTH=");\r
5609\r
5610 //\r
5611 // Get Width\r
5612 //\r
5613 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
3a530010 5614 if (EFI_ERROR (Status)) {\r
46c3efbb 5615 *Progress = TmpPtr;\r
93e3992d 5616 goto Exit;\r
5617 }\r
5618 Width = 0;\r
5619 CopyMem (\r
5620 &Width,\r
5621 TmpBuffer,\r
5622 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
5623 );\r
676df92c 5624 FreePool (TmpBuffer);\r
93e3992d 5625\r
5626 StringPtr += Length;\r
5627 if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {\r
46c3efbb 5628 *Progress = TmpPtr;\r
93e3992d 5629 Status = EFI_INVALID_PARAMETER;\r
5630 goto Exit;\r
5631 }\r
5632 StringPtr += StrLen (L"&VALUE=");\r
5633\r
5634 //\r
5635 // Get Value\r
5636 //\r
5637 Status = GetValueOfNumber (StringPtr, &Value, &Length);\r
7c1bc8d6 5638 if (EFI_ERROR (Status)) {\r
46c3efbb 5639 *Progress = TmpPtr;\r
93e3992d 5640 goto Exit;\r
5641 }\r
5642\r
5643 StringPtr += Length;\r
5644 if (*StringPtr != 0 && *StringPtr != L'&') {\r
46c3efbb 5645 *Progress = TmpPtr;\r
93e3992d 5646 Status = EFI_INVALID_PARAMETER;\r
5647 goto Exit;\r
5648 }\r
5649\r
5650 //\r
5651 // Update the Block with configuration info\r
5652 //\r
09b79417
LG
5653 if ((Block != NULL) && (Offset + Width <= BufferSize)) {\r
5654 CopyMem (Block + Offset, Value, Width);\r
5655 }\r
5656 if (Offset + Width > MaxBlockSize) {\r
5657 MaxBlockSize = Offset + Width;\r
93e3992d 5658 }\r
93e3992d 5659\r
676df92c 5660 FreePool (Value);\r
93e3992d 5661 Value = NULL;\r
5662\r
5663 //\r
edae8d2d 5664 // If '\0', parsing is finished.\r
93e3992d 5665 //\r
5666 if (*StringPtr == 0) {\r
5667 break;\r
5668 }\r
93e3992d 5669 }\r
84f9a9ec
LG
5670 \r
5671 //\r
edae8d2d 5672 // The input string is not ConfigResp format, return error.\r
84f9a9ec 5673 //\r
edae8d2d
ED
5674 if (*StringPtr != 0) {\r
5675 *Progress = StringPtr;\r
93e3992d 5676 Status = EFI_INVALID_PARAMETER;\r
5677 goto Exit;\r
5678 }\r
5679\r
6e3f5b2a 5680 *Progress = StringPtr + StrLen (StringPtr);\r
09b79417
LG
5681 *BlockSize = MaxBlockSize - 1;\r
5682\r
5683 if (MaxBlockSize > BufferSize) {\r
5684 *BlockSize = MaxBlockSize;\r
9ac0640d 5685 if (Block != NULL) {\r
c0a3c3da 5686 return EFI_BUFFER_TOO_SMALL;\r
09b79417
LG
5687 }\r
5688 }\r
5689\r
9ac0640d
LG
5690 if (Block == NULL) {\r
5691 *Progress = ConfigResp;\r
5692 return EFI_INVALID_PARAMETER;\r
5693 }\r
5694\r
93e3992d 5695 return EFI_SUCCESS;\r
5696\r
5697Exit:\r
5698\r
676df92c 5699 if (Value != NULL) {\r
5700 FreePool (Value);\r
5701 }\r
93e3992d 5702 return Status;\r
5703}\r
5704\r
5705\r
5706/**\r
5707 This helper function is to be called by drivers to extract portions of\r
5708 a larger configuration string.\r
5709\r
5710 @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
5711 instance.\r
5712 @param Configuration A null-terminated Unicode string in\r
771ececd 5713 <MultiConfigAltResp> format.\r
93e3992d 5714 @param Guid A pointer to the GUID value to search for in the\r
5715 routing portion of the ConfigResp string when\r
5716 retrieving the requested data. If Guid is NULL,\r
5717 then all GUID values will be searched for.\r
5718 @param Name A pointer to the NAME value to search for in the\r
5719 routing portion of the ConfigResp string when\r
5720 retrieving the requested data. If Name is NULL,\r
5721 then all Name values will be searched for.\r
5722 @param DevicePath A pointer to the PATH value to search for in the\r
5723 routing portion of the ConfigResp string when\r
5724 retrieving the requested data. If DevicePath is\r
5725 NULL, then all DevicePath values will be searched\r
5726 for.\r
5727 @param AltCfgId A pointer to the ALTCFG value to search for in the\r
5728 routing portion of the ConfigResp string when\r
5729 retrieving the requested data. If this parameter\r
5730 is NULL, then the current setting will be\r
5731 retrieved.\r
5732 @param AltCfgResp A pointer to a buffer which will be allocated by\r
5733 the function which contains the retrieved string\r
5734 as requested. This buffer is only allocated if\r
84f9a9ec 5735 the call was successful. It is <ConfigResp> format.\r
93e3992d 5736\r
5737 @retval EFI_SUCCESS The request succeeded. The requested data was\r
5738 extracted and placed in the newly allocated\r
5739 AltCfgResp buffer.\r
5740 @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.\r
5741 @retval EFI_INVALID_PARAMETER Any parameter is invalid.\r
5742 @retval EFI_NOT_FOUND Target for the specified routing data was not\r
5743 found.\r
5744\r
5745**/\r
5746EFI_STATUS\r
5747EFIAPI\r
5748HiiGetAltCfg (\r
5749 IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r
5750 IN CONST EFI_STRING Configuration,\r
5751 IN CONST EFI_GUID *Guid,\r
5752 IN CONST EFI_STRING Name,\r
5753 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
5754 IN CONST UINT16 *AltCfgId,\r
5755 OUT EFI_STRING *AltCfgResp\r
5756 )\r
5757{\r
93e3992d 5758 EFI_STATUS Status;\r
5759 EFI_STRING StringPtr;\r
e90b081a 5760 EFI_STRING HdrStart;\r
5761 EFI_STRING HdrEnd;\r
93e3992d 5762 EFI_STRING TmpPtr;\r
5763 UINTN Length;\r
e90b081a 5764 EFI_STRING GuidStr;\r
5765 EFI_STRING NameStr;\r
5766 EFI_STRING PathStr;\r
5767 EFI_STRING AltIdStr;\r
5768 EFI_STRING Result;\r
5769 BOOLEAN GuidFlag;\r
5770 BOOLEAN NameFlag;\r
5771 BOOLEAN PathFlag;\r
5772\r
5773 HdrStart = NULL;\r
5774 HdrEnd = NULL;\r
5775 GuidStr = NULL;\r
5776 NameStr = NULL;\r
5777 PathStr = NULL;\r
5778 AltIdStr = NULL;\r
5779 Result = NULL;\r
5780 GuidFlag = FALSE;\r
5781 NameFlag = FALSE;\r
5782 PathFlag = FALSE;\r
93e3992d 5783\r
5784 if (This == NULL || Configuration == NULL || AltCfgResp == NULL) {\r
5785 return EFI_INVALID_PARAMETER;\r
5786 }\r
5787\r
5788 StringPtr = Configuration;\r
5789 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
5790 return EFI_INVALID_PARAMETER;\r
5791 }\r
5792\r
5793 //\r
5794 // Generate the sub string for later matching.\r
5795 //\r
813acf3a 5796 GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) Guid, 1, &GuidStr);\r
93e3992d 5797 GenerateSubStr (\r
5798 L"PATH=",\r
5799 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),\r
813acf3a 5800 (VOID *) DevicePath,\r
5801 1,\r
93e3992d 5802 &PathStr\r
5803 );\r
5804 if (AltCfgId != NULL) {\r
813acf3a 5805 GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (VOID *) AltCfgId, 3, &AltIdStr); \r
93e3992d 5806 }\r
5807 if (Name != NULL) {\r
813acf3a 5808 GenerateSubStr (L"NAME=", StrLen (Name) * sizeof (CHAR16), (VOID *) Name, 2, &NameStr); \r
93e3992d 5809 } else {\r
813acf3a 5810 GenerateSubStr (L"NAME=", 0, NULL, 2, &NameStr);\r
93e3992d 5811 }\r
5812\r
5813 while (*StringPtr != 0) {\r
5814 //\r
5815 // Try to match the GUID\r
5816 //\r
5817 if (!GuidFlag) {\r
5818 TmpPtr = StrStr (StringPtr, GuidStr);\r
5819 if (TmpPtr == NULL) {\r
5820 Status = EFI_NOT_FOUND;\r
5821 goto Exit;\r
5822 }\r
5823 HdrStart = TmpPtr;\r
5824\r
5825 //\r
5826 // Jump to <NameHdr>\r
5827 //\r
5828 if (Guid != NULL) {\r
5829 StringPtr = TmpPtr + StrLen (GuidStr);\r
5830 } else {\r
5831 StringPtr = StrStr (TmpPtr, L"NAME=");\r
5832 if (StringPtr == NULL) {\r
5833 Status = EFI_NOT_FOUND;\r
5834 goto Exit;\r
5835 }\r
5836 }\r
5837 GuidFlag = TRUE;\r
5838 }\r
5839\r
5840 //\r
5841 // Try to match the NAME\r
5842 //\r
5843 if (GuidFlag && !NameFlag) {\r
5844 if (StrnCmp (StringPtr, NameStr, StrLen (NameStr)) != 0) {\r
5845 GuidFlag = FALSE;\r
5846 } else {\r
5847 //\r
5848 // Jump to <PathHdr>\r
5849 //\r
5850 if (Name != NULL) {\r
5851 StringPtr += StrLen (NameStr);\r
5852 } else {\r
5853 StringPtr = StrStr (StringPtr, L"PATH=");\r
5854 if (StringPtr == NULL) {\r
5855 Status = EFI_NOT_FOUND;\r
5856 goto Exit;\r
5857 }\r
5858 }\r
5859 NameFlag = TRUE;\r
5860 }\r
5861 }\r
5862\r
5863 //\r
5864 // Try to match the DevicePath\r
5865 //\r
5866 if (GuidFlag && NameFlag && !PathFlag) {\r
5867 if (StrnCmp (StringPtr, PathStr, StrLen (PathStr)) != 0) {\r
5868 GuidFlag = FALSE;\r
5869 NameFlag = FALSE;\r
5870 } else {\r
5871 //\r
5872 // Jump to '&' before <DescHdr> or <ConfigBody>\r
5873 //\r
5874 if (DevicePath != NULL) {\r
5875 StringPtr += StrLen (PathStr);\r
5876 } else {\r
5877 StringPtr = StrStr (StringPtr, L"&");\r
5878 if (StringPtr == NULL) {\r
5879 Status = EFI_NOT_FOUND;\r
5880 goto Exit;\r
5881 }\r
84f9a9ec 5882 StringPtr ++;\r
93e3992d 5883 }\r
5884 PathFlag = TRUE;\r
84f9a9ec 5885 HdrEnd = StringPtr;\r
93e3992d 5886 }\r
5887 }\r
5888\r
5889 //\r
5890 // Try to match the AltCfgId\r
5891 //\r
5892 if (GuidFlag && NameFlag && PathFlag) {\r
5893 if (AltCfgId == NULL) {\r
5894 //\r
5895 // Return Current Setting when AltCfgId is NULL.\r
5896 //\r
5897 Status = OutputConfigBody (StringPtr, &Result);\r
5898 goto Exit;\r
5899 }\r
5900 //\r
5901 // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.\r
5902 //\r
5903 if (StrnCmp (StringPtr, AltIdStr, StrLen (AltIdStr)) != 0) {\r
5904 GuidFlag = FALSE;\r
5905 NameFlag = FALSE;\r
5906 PathFlag = FALSE;\r
5907 } else {\r
84f9a9ec
LG
5908 //\r
5909 // Skip AltIdStr and &\r
5910 //\r
5911 StringPtr = StringPtr + StrLen (AltIdStr);\r
5912 Status = OutputConfigBody (StringPtr, &Result);\r
93e3992d 5913 goto Exit;\r
5914 }\r
5915 }\r
5916 }\r
5917\r
5918 Status = EFI_NOT_FOUND;\r
5919\r
5920Exit:\r
76c24251 5921 *AltCfgResp = NULL;\r
bc166db3 5922 if (!EFI_ERROR (Status) && (Result != NULL)) {\r
93e3992d 5923 //\r
5924 // Copy the <ConfigHdr> and <ConfigBody>\r
5925 //\r
84f9a9ec 5926 Length = HdrEnd - HdrStart + StrLen (Result) + 1;\r
93e3992d 5927 *AltCfgResp = AllocateZeroPool (Length * sizeof (CHAR16));\r
5928 if (*AltCfgResp == NULL) {\r
5929 Status = EFI_OUT_OF_RESOURCES;\r
5930 } else {\r
5ad66ec6
DB
5931 StrnCpyS (*AltCfgResp, Length, HdrStart, HdrEnd - HdrStart);\r
5932 StrCatS (*AltCfgResp, Length, Result);\r
93e3992d 5933 Status = EFI_SUCCESS;\r
5934 }\r
5935 }\r
5936\r
676df92c 5937 if (GuidStr != NULL) {\r
5938 FreePool (GuidStr);\r
5939 }\r
5940 if (NameStr != NULL) {\r
5941 FreePool (NameStr);\r
5942 }\r
5943 if (PathStr != NULL) {\r
5944 FreePool (PathStr);\r
5945 }\r
5946 if (AltIdStr != NULL) {\r
5947 FreePool (AltIdStr);\r
5948 }\r
5949 if (Result != NULL) {\r
5950 FreePool (Result);\r
5951 }\r
93e3992d 5952\r
5953 return Status;\r
5954\r
93e3992d 5955}\r
5956\r
36fe40c2 5957\r