]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r | |
3 | \r | |
4 | Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | \r | |
16 | #include "HiiDatabase.h"\r | |
17 | extern HII_DATABASE_PRIVATE_DATA mPrivate;\r | |
18 | \r | |
19 | /**\r | |
20 | Calculate the number of Unicode characters of the incoming Configuration string,\r | |
21 | not including NULL terminator.\r | |
22 | \r | |
23 | This is a internal function.\r | |
24 | \r | |
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 | |
31 | UINTN\r | |
32 | CalculateConfigStringLen (\r | |
33 | IN EFI_STRING String\r | |
34 | )\r | |
35 | {\r | |
36 | EFI_STRING TmpPtr;\r | |
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 | |
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 | |
47 | // \r | |
48 | TmpPtr = StrStr (String, L"&GUID=");\r | |
49 | if (TmpPtr == NULL) {\r | |
50 | return StrLen (String);\r | |
51 | }\r | |
52 | \r | |
53 | return (TmpPtr - String);\r | |
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 | |
61 | This is a internal function.\r | |
62 | \r | |
63 | @param String UEFI configuration string\r | |
64 | @param DevicePathData Binary of a UEFI device path.\r | |
65 | \r | |
66 | @retval EFI_NOT_FOUND The device path is not invalid.\r | |
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 | |
73 | EFI_STATUS\r | |
74 | GetDevicePath (\r | |
75 | IN EFI_STRING String,\r | |
76 | OUT UINT8 **DevicePathData\r | |
77 | )\r | |
78 | {\r | |
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 | |
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 | |
99 | //\r | |
100 | // Check whether path data does exist.\r | |
101 | //\r | |
102 | String += StrLen (L"PATH=");\r | |
103 | if (*String == 0) {\r | |
104 | return EFI_INVALID_PARAMETER;\r | |
105 | }\r | |
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 | |
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 | |
119 | }\r | |
120 | \r | |
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 | |
125 | //\r | |
126 | DevicePathBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);\r | |
127 | if (DevicePathBuffer == NULL) {\r | |
128 | return EFI_OUT_OF_RESOURCES;\r | |
129 | }\r | |
130 | \r | |
131 | //\r | |
132 | // Convert DevicePath\r | |
133 | //\r | |
134 | ZeroMem (TemStr, sizeof (TemStr));\r | |
135 | for (Index = 0; Index < Length; Index ++) {\r | |
136 | TemStr[0] = PathHdr[Index];\r | |
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 | |
144 | \r | |
145 | //\r | |
146 | // Validate DevicePath\r | |
147 | //\r | |
148 | DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DevicePathBuffer;\r | |
149 | while (!IsDevicePathEnd (DevicePath)) {\r | |
150 | if ((DevicePath->Type == 0) || (DevicePath->SubType == 0) || (DevicePathNodeLength (DevicePath) < sizeof (EFI_DEVICE_PATH_PROTOCOL))) {\r | |
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 | |
159 | \r | |
160 | //\r | |
161 | // return the device path\r | |
162 | //\r | |
163 | *DevicePathData = DevicePathBuffer;\r | |
164 | return EFI_SUCCESS;\r | |
165 | }\r | |
166 | \r | |
167 | /**\r | |
168 | Converts the unicode character of the string from uppercase to lowercase.\r | |
169 | This is a internal function.\r | |
170 | \r | |
171 | @param ConfigString String to be converted\r | |
172 | \r | |
173 | **/\r | |
174 | VOID\r | |
175 | EFIAPI\r | |
176 | HiiToLower (\r | |
177 | IN EFI_STRING ConfigString\r | |
178 | )\r | |
179 | {\r | |
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 | |
195 | }\r | |
196 | }\r | |
197 | \r | |
198 | return;\r | |
199 | }\r | |
200 | \r | |
201 | /**\r | |
202 | Generate a sub string then output it.\r | |
203 | \r | |
204 | This is a internal function.\r | |
205 | \r | |
206 | @param String A constant string which is the prefix of the to be\r | |
207 | generated string, e.g. GUID=\r | |
208 | \r | |
209 | @param BufferLen The length of the Buffer in bytes.\r | |
210 | \r | |
211 | @param Buffer Points to a buffer which will be converted to be the \r | |
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 | |
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 | |
223 | VOID\r | |
224 | GenerateSubStr (\r | |
225 | IN CONST EFI_STRING String,\r | |
226 | IN UINTN BufferLen,\r | |
227 | IN VOID *Buffer,\r | |
228 | IN UINT8 Flag,\r | |
229 | OUT EFI_STRING *SubStr\r | |
230 | )\r | |
231 | {\r | |
232 | UINTN Length;\r | |
233 | EFI_STRING Str;\r | |
234 | EFI_STRING StringHeader;\r | |
235 | CHAR16 *TemString;\r | |
236 | CHAR16 *TemName;\r | |
237 | UINT8 *TemBuffer;\r | |
238 | UINTN Index;\r | |
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 | |
245 | return ;\r | |
246 | }\r | |
247 | \r | |
248 | //\r | |
249 | // Header + Data + '&' + '\0'\r | |
250 | //\r | |
251 | Length = StrLen (String) + BufferLen * 2 + 1 + 1;\r | |
252 | Str = AllocateZeroPool (Length * sizeof (CHAR16));\r | |
253 | ASSERT (Str != NULL);\r | |
254 | \r | |
255 | StrCpy (Str, String);\r | |
256 | Length = (BufferLen * 2 + 1) * sizeof (CHAR16);\r | |
257 | \r | |
258 | StringHeader = Str + StrLen (String);\r | |
259 | TemString = (CHAR16 *) StringHeader;\r | |
260 | \r | |
261 | switch (Flag) {\r | |
262 | case 1:\r | |
263 | //\r | |
264 | // Convert Buffer to Hex String in reverse order\r | |
265 | //\r | |
266 | TemBuffer = ((UINT8 *) Buffer);\r | |
267 | for (Index = 0; Index < BufferLen; Index ++, TemBuffer ++) {\r | |
268 | TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r | |
269 | }\r | |
270 | break;\r | |
271 | case 2:\r | |
272 | //\r | |
273 | // Check buffer is enough\r | |
274 | //\r | |
275 | TemName = (CHAR16 *) Buffer;\r | |
276 | ASSERT ((BufferLen * 2 + 1) >= (StrLen (TemName) * 4 + 1));\r | |
277 | //\r | |
278 | // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r | |
279 | //\r | |
280 | for (; *TemName != L'\0'; TemName++) {\r | |
281 | TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r | |
282 | }\r | |
283 | break;\r | |
284 | case 3:\r | |
285 | //\r | |
286 | // Convert Buffer to Hex String\r | |
287 | //\r | |
288 | TemBuffer = ((UINT8 *) Buffer) + BufferLen - 1;\r | |
289 | for (Index = 0; Index < BufferLen; Index ++, TemBuffer --) {\r | |
290 | TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r | |
291 | }\r | |
292 | break;\r | |
293 | default:\r | |
294 | break;\r | |
295 | }\r | |
296 | \r | |
297 | //\r | |
298 | // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r | |
299 | //\r | |
300 | StrCat (Str, L"&"); \r | |
301 | HiiToLower (Str);\r | |
302 | \r | |
303 | *SubStr = Str;\r | |
304 | }\r | |
305 | \r | |
306 | \r | |
307 | /**\r | |
308 | Retrieve the <ConfigBody> from String then output it.\r | |
309 | \r | |
310 | This is a internal function.\r | |
311 | \r | |
312 | @param String A sub string of a configuration string in\r | |
313 | <MultiConfigAltResp> format.\r | |
314 | @param ConfigBody Points to the output string. It's caller's\r | |
315 | responsibility to free this buffer.\r | |
316 | \r | |
317 | @retval EFI_INVALID_PARAMETER There is no form package in current hii database.\r | |
318 | @retval EFI_OUT_OF_RESOURCES Not enough memory to finish this operation.\r | |
319 | @retval EFI_SUCCESS All existing storage is exported.\r | |
320 | \r | |
321 | **/\r | |
322 | EFI_STATUS\r | |
323 | OutputConfigBody (\r | |
324 | IN EFI_STRING String,\r | |
325 | OUT EFI_STRING *ConfigBody\r | |
326 | )\r | |
327 | {\r | |
328 | EFI_STRING TmpPtr;\r | |
329 | EFI_STRING Result;\r | |
330 | UINTN Length;\r | |
331 | \r | |
332 | if (String == NULL || ConfigBody == NULL) {\r | |
333 | return EFI_INVALID_PARAMETER;\r | |
334 | }\r | |
335 | \r | |
336 | //\r | |
337 | // The setting information should start OFFSET, not ALTCFG.\r | |
338 | //\r | |
339 | if (StrnCmp (String, L"&ALTCFG=", StrLen (L"&ALTCFG=")) == 0) {\r | |
340 | return EFI_INVALID_PARAMETER;\r | |
341 | }\r | |
342 | \r | |
343 | TmpPtr = StrStr (String, L"GUID=");\r | |
344 | if (TmpPtr == NULL) {\r | |
345 | //\r | |
346 | // It is the last <ConfigResp> of the incoming configuration string.\r | |
347 | //\r | |
348 | Result = AllocateCopyPool (StrSize (String), String);\r | |
349 | if (Result == NULL) {\r | |
350 | return EFI_OUT_OF_RESOURCES;\r | |
351 | } else {\r | |
352 | *ConfigBody = Result;\r | |
353 | return EFI_SUCCESS;\r | |
354 | }\r | |
355 | }\r | |
356 | \r | |
357 | Length = TmpPtr - String;\r | |
358 | Result = AllocateCopyPool (Length * sizeof (CHAR16), String);\r | |
359 | if (Result == NULL) {\r | |
360 | return EFI_OUT_OF_RESOURCES;\r | |
361 | }\r | |
362 | \r | |
363 | *(Result + Length - 1) = 0;\r | |
364 | *ConfigBody = Result;\r | |
365 | return EFI_SUCCESS;\r | |
366 | }\r | |
367 | \r | |
368 | /**\r | |
369 | Append a string to a multi-string format.\r | |
370 | \r | |
371 | This is a internal function.\r | |
372 | \r | |
373 | @param MultiString String in <MultiConfigRequest>,\r | |
374 | <MultiConfigAltResp>, or <MultiConfigResp>. On\r | |
375 | input, the buffer length of this string is\r | |
376 | MAX_STRING_LENGTH. On output, the buffer length\r | |
377 | might be updated.\r | |
378 | @param AppendString NULL-terminated Unicode string.\r | |
379 | \r | |
380 | @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.\r | |
381 | @retval EFI_SUCCESS AppendString is append to the end of MultiString\r | |
382 | \r | |
383 | **/\r | |
384 | EFI_STATUS\r | |
385 | AppendToMultiString (\r | |
386 | IN OUT EFI_STRING *MultiString,\r | |
387 | IN EFI_STRING AppendString\r | |
388 | )\r | |
389 | {\r | |
390 | UINTN AppendStringSize;\r | |
391 | UINTN MultiStringSize;\r | |
392 | \r | |
393 | if (MultiString == NULL || *MultiString == NULL || AppendString == NULL) {\r | |
394 | return EFI_INVALID_PARAMETER;\r | |
395 | }\r | |
396 | \r | |
397 | AppendStringSize = StrSize (AppendString);\r | |
398 | MultiStringSize = StrSize (*MultiString);\r | |
399 | \r | |
400 | //\r | |
401 | // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.\r | |
402 | //\r | |
403 | if (MultiStringSize + AppendStringSize > MAX_STRING_LENGTH ||\r | |
404 | MultiStringSize > MAX_STRING_LENGTH) {\r | |
405 | *MultiString = (EFI_STRING) ReallocatePool (\r | |
406 | MultiStringSize,\r | |
407 | MultiStringSize + AppendStringSize,\r | |
408 | (VOID *) (*MultiString)\r | |
409 | );\r | |
410 | ASSERT (*MultiString != NULL);\r | |
411 | }\r | |
412 | //\r | |
413 | // Append the incoming string\r | |
414 | //\r | |
415 | StrCat (*MultiString, AppendString);\r | |
416 | \r | |
417 | return EFI_SUCCESS;\r | |
418 | }\r | |
419 | \r | |
420 | \r | |
421 | /**\r | |
422 | Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET\r | |
423 | or WIDTH or VALUE.\r | |
424 | <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>\r | |
425 | \r | |
426 | This is a internal function.\r | |
427 | \r | |
428 | @param StringPtr String in <BlockConfig> format and points to the\r | |
429 | first character of <Number>.\r | |
430 | @param Number The output value. Caller takes the responsibility\r | |
431 | to free memory.\r | |
432 | @param Len Length of the <Number>, in characters.\r | |
433 | \r | |
434 | @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary\r | |
435 | structures.\r | |
436 | @retval EFI_SUCCESS Value of <Number> is outputted in Number\r | |
437 | successfully.\r | |
438 | \r | |
439 | **/\r | |
440 | EFI_STATUS\r | |
441 | GetValueOfNumber (\r | |
442 | IN EFI_STRING StringPtr,\r | |
443 | OUT UINT8 **Number,\r | |
444 | OUT UINTN *Len\r | |
445 | )\r | |
446 | {\r | |
447 | EFI_STRING TmpPtr;\r | |
448 | UINTN Length;\r | |
449 | EFI_STRING Str;\r | |
450 | UINT8 *Buf;\r | |
451 | EFI_STATUS Status;\r | |
452 | UINT8 DigitUint8;\r | |
453 | UINTN Index;\r | |
454 | CHAR16 TemStr[2];\r | |
455 | \r | |
456 | if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) {\r | |
457 | return EFI_INVALID_PARAMETER;\r | |
458 | }\r | |
459 | \r | |
460 | Buf = NULL;\r | |
461 | \r | |
462 | TmpPtr = StringPtr;\r | |
463 | while (*StringPtr != L'\0' && *StringPtr != L'&') {\r | |
464 | StringPtr++;\r | |
465 | }\r | |
466 | *Len = StringPtr - TmpPtr;\r | |
467 | Length = *Len + 1;\r | |
468 | \r | |
469 | Str = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));\r | |
470 | if (Str == NULL) {\r | |
471 | Status = EFI_OUT_OF_RESOURCES;\r | |
472 | goto Exit;\r | |
473 | }\r | |
474 | CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));\r | |
475 | *(Str + *Len) = L'\0';\r | |
476 | \r | |
477 | Length = (Length + 1) / 2;\r | |
478 | Buf = (UINT8 *) AllocateZeroPool (Length);\r | |
479 | if (Buf == NULL) {\r | |
480 | Status = EFI_OUT_OF_RESOURCES;\r | |
481 | goto Exit;\r | |
482 | }\r | |
483 | \r | |
484 | Length = *Len;\r | |
485 | ZeroMem (TemStr, sizeof (TemStr));\r | |
486 | for (Index = 0; Index < Length; Index ++) {\r | |
487 | TemStr[0] = Str[Length - Index - 1];\r | |
488 | DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r | |
489 | if ((Index & 1) == 0) {\r | |
490 | Buf [Index/2] = DigitUint8;\r | |
491 | } else {\r | |
492 | Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);\r | |
493 | }\r | |
494 | }\r | |
495 | \r | |
496 | *Number = Buf;\r | |
497 | Status = EFI_SUCCESS;\r | |
498 | \r | |
499 | Exit:\r | |
500 | if (Str != NULL) {\r | |
501 | FreePool (Str);\r | |
502 | }\r | |
503 | \r | |
504 | return Status;\r | |
505 | }\r | |
506 | \r | |
507 | /**\r | |
508 | This function merges DefaultAltCfgResp string into AltCfgResp string for\r | |
509 | the missing AltCfgId in AltCfgResq.\r | |
510 | \r | |
511 | @param AltCfgResp Pointer to a null-terminated Unicode string in\r | |
512 | <ConfigAltResp> format. The default value string \r | |
513 | will be merged into it. \r | |
514 | @param DefaultAltCfgResp Pointer to a null-terminated Unicode string in\r | |
515 | <MultiConfigAltResp> format. The default value \r | |
516 | string may contain more than one ConfigAltResp\r | |
517 | string for the different varstore buffer.\r | |
518 | \r | |
519 | @retval EFI_SUCCESS The merged string returns.\r | |
520 | @retval EFI_INVALID_PARAMETER *AltCfgResp is to NULL.\r | |
521 | **/\r | |
522 | EFI_STATUS\r | |
523 | EFIAPI\r | |
524 | MergeDefaultString (\r | |
525 | IN OUT EFI_STRING *AltCfgResp,\r | |
526 | IN EFI_STRING DefaultAltCfgResp\r | |
527 | )\r | |
528 | {\r | |
529 | EFI_STRING StringPtrDefault;\r | |
530 | EFI_STRING StringPtrEnd;\r | |
531 | CHAR16 TempChar;\r | |
532 | EFI_STRING StringPtr;\r | |
533 | EFI_STRING AltConfigHdr;\r | |
534 | UINTN HeaderLength;\r | |
535 | UINTN SizeAltCfgResp;\r | |
536 | \r | |
537 | if (*AltCfgResp == NULL) {\r | |
538 | return EFI_INVALID_PARAMETER;\r | |
539 | }\r | |
540 | \r | |
541 | //\r | |
542 | // Get the requestr ConfigHdr\r | |
543 | //\r | |
544 | SizeAltCfgResp = 0;\r | |
545 | StringPtr = *AltCfgResp;\r | |
546 | \r | |
547 | //\r | |
548 | // Find <ConfigHdr> GUID=...&NAME=...&PATH=...\r | |
549 | //\r | |
550 | if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r | |
551 | return EFI_INVALID_PARAMETER;\r | |
552 | }\r | |
553 | while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) {\r | |
554 | StringPtr++;\r | |
555 | }\r | |
556 | while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) {\r | |
557 | StringPtr++;\r | |
558 | }\r | |
559 | if (*StringPtr == L'\0') {\r | |
560 | return EFI_INVALID_PARAMETER;\r | |
561 | }\r | |
562 | StringPtr += StrLen (L"&PATH=");\r | |
563 | while (*StringPtr != L'\0' && *StringPtr != L'&') {\r | |
564 | StringPtr ++;\r | |
565 | }\r | |
566 | HeaderLength = StringPtr - *AltCfgResp;\r | |
567 | \r | |
568 | //\r | |
569 | // Construct AltConfigHdr string "&<ConfigHdr>&ALTCFG=XXXX\0"\r | |
570 | // |1| StrLen (ConfigHdr) | 8 | 4 | 1 |\r | |
571 | //\r | |
572 | AltConfigHdr = AllocateZeroPool ((1 + HeaderLength + 8 + 4 + 1) * sizeof (CHAR16));\r | |
573 | if (AltConfigHdr == NULL) {\r | |
574 | return EFI_OUT_OF_RESOURCES;\r | |
575 | }\r | |
576 | StrCpy (AltConfigHdr, L"&");\r | |
577 | StrnCat (AltConfigHdr, *AltCfgResp, HeaderLength);\r | |
578 | StrCat (AltConfigHdr, L"&ALTCFG=");\r | |
579 | HeaderLength = StrLen (AltConfigHdr);\r | |
580 | \r | |
581 | StringPtrDefault = StrStr (DefaultAltCfgResp, AltConfigHdr);\r | |
582 | while (StringPtrDefault != NULL) {\r | |
583 | //\r | |
584 | // Get AltCfg Name\r | |
585 | //\r | |
586 | StrnCat (AltConfigHdr, StringPtrDefault + HeaderLength, 4);\r | |
587 | StringPtr = StrStr (*AltCfgResp, AltConfigHdr); \r | |
588 | \r | |
589 | //\r | |
590 | // Append the found default value string to the input AltCfgResp\r | |
591 | // \r | |
592 | if (StringPtr == NULL) {\r | |
593 | StringPtrEnd = StrStr (StringPtrDefault + 1, L"&GUID");\r | |
594 | SizeAltCfgResp = StrSize (*AltCfgResp);\r | |
595 | if (StringPtrEnd == NULL) {\r | |
596 | //\r | |
597 | // No more default string is found.\r | |
598 | //\r | |
599 | *AltCfgResp = (EFI_STRING) ReallocatePool (\r | |
600 | SizeAltCfgResp,\r | |
601 | SizeAltCfgResp + StrSize (StringPtrDefault),\r | |
602 | (VOID *) (*AltCfgResp)\r | |
603 | );\r | |
604 | if (*AltCfgResp == NULL) {\r | |
605 | FreePool (AltConfigHdr);\r | |
606 | return EFI_OUT_OF_RESOURCES;\r | |
607 | }\r | |
608 | StrCat (*AltCfgResp, StringPtrDefault);\r | |
609 | break;\r | |
610 | } else {\r | |
611 | TempChar = *StringPtrEnd;\r | |
612 | *StringPtrEnd = L'\0';\r | |
613 | *AltCfgResp = (EFI_STRING) ReallocatePool (\r | |
614 | SizeAltCfgResp,\r | |
615 | SizeAltCfgResp + StrSize (StringPtrDefault),\r | |
616 | (VOID *) (*AltCfgResp)\r | |
617 | );\r | |
618 | if (*AltCfgResp == NULL) {\r | |
619 | FreePool (AltConfigHdr);\r | |
620 | return EFI_OUT_OF_RESOURCES;\r | |
621 | }\r | |
622 | StrCat (*AltCfgResp, StringPtrDefault);\r | |
623 | *StringPtrEnd = TempChar;\r | |
624 | }\r | |
625 | }\r | |
626 | \r | |
627 | //\r | |
628 | // Find next AltCfg String\r | |
629 | //\r | |
630 | *(AltConfigHdr + HeaderLength) = L'\0';\r | |
631 | StringPtrDefault = StrStr (StringPtrDefault + 1, AltConfigHdr); \r | |
632 | }\r | |
633 | \r | |
634 | FreePool (AltConfigHdr);\r | |
635 | return EFI_SUCCESS; \r | |
636 | }\r | |
637 | \r | |
638 | /**\r | |
639 | This function inserts new DefaultValueData into the BlockData DefaultValue array.\r | |
640 | \r | |
641 | @param BlockData The BlockData is updated to add new default value.\r | |
642 | @param DefaultValueData The DefaultValue is added.\r | |
643 | \r | |
644 | **/\r | |
645 | VOID\r | |
646 | InsertDefaultValue (\r | |
647 | IN IFR_BLOCK_DATA *BlockData,\r | |
648 | IN IFR_DEFAULT_DATA *DefaultValueData\r | |
649 | )\r | |
650 | {\r | |
651 | LIST_ENTRY *Link;\r | |
652 | IFR_DEFAULT_DATA *DefaultValueArray;\r | |
653 | \r | |
654 | for (Link = BlockData->DefaultValueEntry.ForwardLink; Link != &BlockData->DefaultValueEntry; Link = Link->ForwardLink) {\r | |
655 | DefaultValueArray = BASE_CR (Link, IFR_DEFAULT_DATA, Entry);\r | |
656 | if (DefaultValueArray->DefaultId == DefaultValueData->DefaultId) {\r | |
657 | if (DefaultValueData->OpCode == EFI_IFR_DEFAULT_OP) {\r | |
658 | //\r | |
659 | // Update the default value array in BlockData.\r | |
660 | //\r | |
661 | DefaultValueArray->Value = DefaultValueData->Value;\r | |
662 | } else if (DefaultValueArray->OpCode != EFI_IFR_DEFAULT_OP) {\r | |
663 | //\r | |
664 | // Update the default value array in BlockData.\r | |
665 | //\r | |
666 | DefaultValueArray->Value = DefaultValueData->Value;\r | |
667 | }\r | |
668 | FreePool (DefaultValueData);\r | |
669 | return;\r | |
670 | } else if (DefaultValueArray->DefaultId > DefaultValueData->DefaultId) {\r | |
671 | //\r | |
672 | // Insert new default value data in the front of this default value array.\r | |
673 | //\r | |
674 | InsertTailList (Link, &DefaultValueData->Entry);\r | |
675 | return;\r | |
676 | }\r | |
677 | }\r | |
678 | \r | |
679 | //\r | |
680 | // Insert new default value data in tail.\r | |
681 | //\r | |
682 | InsertTailList (Link, &DefaultValueData->Entry);\r | |
683 | return;\r | |
684 | }\r | |
685 | \r | |
686 | /**\r | |
687 | This function inserts new BlockData into the block link\r | |
688 | \r | |
689 | @param BlockLink The list entry points to block array.\r | |
690 | @param BlockData The point to BlockData is added.\r | |
691 | \r | |
692 | **/\r | |
693 | VOID\r | |
694 | InsertBlockData (\r | |
695 | IN LIST_ENTRY *BlockLink,\r | |
696 | IN IFR_BLOCK_DATA **BlockData\r | |
697 | )\r | |
698 | {\r | |
699 | LIST_ENTRY *Link;\r | |
700 | IFR_BLOCK_DATA *BlockArray;\r | |
701 | IFR_BLOCK_DATA *BlockSingleData;\r | |
702 | \r | |
703 | BlockSingleData = *BlockData;\r | |
704 | \r | |
705 | //\r | |
706 | // Insert block data in its Offset and Width order.\r | |
707 | //\r | |
708 | for (Link = BlockLink->ForwardLink; Link != BlockLink; Link = Link->ForwardLink) {\r | |
709 | BlockArray = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r | |
710 | if (BlockArray->Offset == BlockSingleData->Offset) {\r | |
711 | if (BlockArray->Width > BlockSingleData->Width) {\r | |
712 | //\r | |
713 | // Insert this block data in the front of block array\r | |
714 | //\r | |
715 | InsertTailList (Link, &BlockSingleData->Entry);\r | |
716 | return;\r | |
717 | }\r | |
718 | \r | |
719 | if (BlockArray->Width == BlockSingleData->Width) {\r | |
720 | //\r | |
721 | // The same block array has been added.\r | |
722 | //\r | |
723 | FreePool (BlockSingleData);\r | |
724 | *BlockData = BlockArray;\r | |
725 | return;\r | |
726 | }\r | |
727 | } else if (BlockArray->Offset > BlockSingleData->Offset) {\r | |
728 | //\r | |
729 | // Insert new block data in the front of block array \r | |
730 | //\r | |
731 | InsertTailList (Link, &BlockSingleData->Entry);\r | |
732 | return;\r | |
733 | }\r | |
734 | }\r | |
735 | \r | |
736 | //\r | |
737 | // Add new block data into the tail.\r | |
738 | //\r | |
739 | InsertTailList (Link, &BlockSingleData->Entry);\r | |
740 | return; \r | |
741 | }\r | |
742 | \r | |
743 | /**\r | |
744 | This function checks VarOffset and VarWidth is in the block range.\r | |
745 | \r | |
746 | @param RequestBlockArray The block array is to be checked. \r | |
747 | @param VarOffset Offset of var to the structure\r | |
748 | @param VarWidth Width of var.\r | |
749 | \r | |
750 | @retval TRUE This Var is in the block range.\r | |
751 | @retval FALSE This Var is not in the block range.\r | |
752 | **/\r | |
753 | BOOLEAN\r | |
754 | BlockArrayCheck (\r | |
755 | IN IFR_BLOCK_DATA *RequestBlockArray,\r | |
756 | IN UINT16 VarOffset,\r | |
757 | IN UINT16 VarWidth\r | |
758 | )\r | |
759 | {\r | |
760 | LIST_ENTRY *Link;\r | |
761 | IFR_BLOCK_DATA *BlockData;\r | |
762 | \r | |
763 | //\r | |
764 | // No Request Block array, all vars are got.\r | |
765 | //\r | |
766 | if (RequestBlockArray == NULL) {\r | |
767 | return TRUE;\r | |
768 | }\r | |
769 | \r | |
770 | //\r | |
771 | // Check the input var is in the request block range.\r | |
772 | //\r | |
773 | for (Link = RequestBlockArray->Entry.ForwardLink; Link != &RequestBlockArray->Entry; Link = Link->ForwardLink) {\r | |
774 | BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r | |
775 | if ((VarOffset >= BlockData->Offset) && ((VarOffset + VarWidth) <= (BlockData->Offset + BlockData->Width))) {\r | |
776 | return TRUE;\r | |
777 | }\r | |
778 | }\r | |
779 | \r | |
780 | return FALSE;\r | |
781 | }\r | |
782 | \r | |
783 | /**\r | |
784 | This function parses Form Package to get the block array and the default\r | |
785 | value array according to the request ConfigHdr.\r | |
786 | \r | |
787 | @param Package Pointer to the form package data.\r | |
788 | @param PackageLength Length of the pacakge.\r | |
789 | @param ConfigHdr Request string ConfigHdr. If it is NULL,\r | |
790 | the first found varstore will be as ConfigHdr.\r | |
791 | @param RequestBlockArray The block array is retrieved from the request string.\r | |
792 | @param VarStorageData VarStorage structure contains the got block and default value.\r | |
793 | @param PIfrDefaultIdArray Point to the got default id and default name array.\r | |
794 | \r | |
795 | @retval EFI_SUCCESS The block array and the default value array are got.\r | |
796 | @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges\r | |
797 | are conflicted. \r | |
798 | @retval EFI_OUT_OF_RESOURCES No enough memory.\r | |
799 | **/\r | |
800 | EFI_STATUS\r | |
801 | EFIAPI\r | |
802 | ParseIfrData (\r | |
803 | IN UINT8 *Package,\r | |
804 | IN UINT32 PackageLength,\r | |
805 | IN EFI_STRING ConfigHdr,\r | |
806 | IN IFR_BLOCK_DATA *RequestBlockArray,\r | |
807 | IN OUT IFR_VARSTORAGE_DATA *VarStorageData,\r | |
808 | OUT IFR_DEFAULT_DATA *DefaultIdArray\r | |
809 | )\r | |
810 | {\r | |
811 | EFI_STATUS Status;\r | |
812 | UINTN IfrOffset;\r | |
813 | EFI_IFR_VARSTORE *IfrVarStore;\r | |
814 | EFI_IFR_OP_HEADER *IfrOpHdr;\r | |
815 | EFI_IFR_ONE_OF *IfrOneOf;\r | |
816 | EFI_IFR_ONE_OF_OPTION *IfrOneOfOption;\r | |
817 | EFI_IFR_DEFAULT *IfrDefault;\r | |
818 | EFI_IFR_ORDERED_LIST *IfrOrderedList;\r | |
819 | EFI_IFR_CHECKBOX *IfrCheckBox;\r | |
820 | EFI_IFR_PASSWORD *IfrPassword;\r | |
821 | EFI_IFR_STRING *IfrString;\r | |
822 | IFR_DEFAULT_DATA *DefaultData;\r | |
823 | IFR_BLOCK_DATA *BlockData;\r | |
824 | CHAR16 *VarStoreName;\r | |
825 | UINT16 VarOffset;\r | |
826 | UINT16 VarWidth;\r | |
827 | EFI_STRING_ID VarDefaultName;\r | |
828 | UINT16 VarDefaultId;\r | |
829 | EFI_STRING GuidStr;\r | |
830 | EFI_STRING NameStr;\r | |
831 | EFI_STRING TempStr;\r | |
832 | UINTN LengthString;\r | |
833 | BOOLEAN FirstOneOfOption;\r | |
834 | \r | |
835 | LengthString = 0;\r | |
836 | Status = EFI_SUCCESS;\r | |
837 | GuidStr = NULL;\r | |
838 | NameStr = NULL;\r | |
839 | TempStr = NULL;\r | |
840 | BlockData = NULL;\r | |
841 | DefaultData = NULL;\r | |
842 | VarDefaultName = 0;\r | |
843 | FirstOneOfOption = FALSE;\r | |
844 | \r | |
845 | //\r | |
846 | // Go through the form package to parse OpCode one by one.\r | |
847 | //\r | |
848 | IfrOffset = sizeof (EFI_HII_PACKAGE_HEADER);\r | |
849 | while (IfrOffset < PackageLength) {\r | |
850 | IfrOpHdr = (EFI_IFR_OP_HEADER *) (Package + IfrOffset);\r | |
851 | \r | |
852 | switch (IfrOpHdr->OpCode) {\r | |
853 | case EFI_IFR_VARSTORE_OP:\r | |
854 | //\r | |
855 | // VarStore is found. Don't need to search any more.\r | |
856 | //\r | |
857 | if (VarStorageData->Size != 0) {\r | |
858 | break;\r | |
859 | }\r | |
860 | \r | |
861 | //\r | |
862 | // Get the requied varstore information\r | |
863 | // Add varstore by Guid and Name in ConfigHdr\r | |
864 | // Make sure Offset is in varstore size and varstoreid\r | |
865 | //\r | |
866 | IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr;\r | |
867 | VarStoreName = AllocateZeroPool (AsciiStrSize ((CHAR8 *)IfrVarStore->Name) * sizeof (CHAR16));\r | |
868 | if (VarStoreName == NULL) {\r | |
869 | Status = EFI_OUT_OF_RESOURCES;\r | |
870 | goto Done;\r | |
871 | }\r | |
872 | AsciiStrToUnicodeStr ((CHAR8 *) IfrVarStore->Name, VarStoreName);\r | |
873 | \r | |
874 | GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) &IfrVarStore->Guid, 1, &GuidStr);\r | |
875 | GenerateSubStr (L"NAME=", StrLen (VarStoreName) * sizeof (CHAR16), (VOID *) VarStoreName, 2, &NameStr);\r | |
876 | LengthString = StrLen (GuidStr);\r | |
877 | LengthString = LengthString + StrLen (NameStr) + 1;\r | |
878 | TempStr = AllocateZeroPool (LengthString * sizeof (CHAR16));\r | |
879 | if (TempStr == NULL) {\r | |
880 | FreePool (GuidStr);\r | |
881 | FreePool (NameStr);\r | |
882 | FreePool (VarStoreName);\r | |
883 | Status = EFI_OUT_OF_RESOURCES;\r | |
884 | goto Done;\r | |
885 | }\r | |
886 | StrCpy (TempStr, GuidStr);\r | |
887 | StrCat (TempStr, NameStr);\r | |
888 | if (ConfigHdr == NULL || StrnCmp (ConfigHdr, TempStr, StrLen (TempStr)) == 0) {\r | |
889 | //\r | |
890 | // Find the matched VarStore\r | |
891 | //\r | |
892 | CopyGuid (&VarStorageData->Guid, (EFI_GUID *) (VOID *) &IfrVarStore->Guid);\r | |
893 | VarStorageData->VarStoreId = IfrVarStore->VarStoreId;\r | |
894 | VarStorageData->Size = IfrVarStore->Size;\r | |
895 | VarStorageData->Name = VarStoreName;\r | |
896 | } else {\r | |
897 | //\r | |
898 | // No found, free the allocated memory \r | |
899 | //\r | |
900 | FreePool (VarStoreName);\r | |
901 | }\r | |
902 | //\r | |
903 | // Free alllocated temp string.\r | |
904 | //\r | |
905 | FreePool (GuidStr);\r | |
906 | FreePool (NameStr);\r | |
907 | FreePool (TempStr);\r | |
908 | break;\r | |
909 | \r | |
910 | case EFI_IFR_DEFAULTSTORE_OP:\r | |
911 | //\r | |
912 | // Add new the map between default id and default name.\r | |
913 | //\r | |
914 | DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
915 | if (DefaultData == NULL) {\r | |
916 | Status = EFI_OUT_OF_RESOURCES;\r | |
917 | goto Done;\r | |
918 | }\r | |
919 | DefaultData->DefaultId = ((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultId;\r | |
920 | InsertTailList (&DefaultIdArray->Entry, &DefaultData->Entry);\r | |
921 | DefaultData = NULL;\r | |
922 | break;\r | |
923 | \r | |
924 | case EFI_IFR_FORM_OP:\r | |
925 | case EFI_IFR_FORM_MAP_OP:\r | |
926 | //\r | |
927 | // No matched varstore is found and directly return.\r | |
928 | //\r | |
929 | if (VarStorageData->Size == 0) {\r | |
930 | Status = EFI_SUCCESS;\r | |
931 | goto Done;\r | |
932 | }\r | |
933 | break;\r | |
934 | \r | |
935 | case EFI_IFR_ONE_OF_OP:\r | |
936 | case EFI_IFR_NUMERIC_OP:\r | |
937 | //\r | |
938 | // Numeric and OneOf has the same opcode structure.\r | |
939 | //\r | |
940 | \r | |
941 | //\r | |
942 | // Numeric and OneOf question is not in IFR Form. This IFR form is not valid. \r | |
943 | //\r | |
944 | if (VarStorageData->Size == 0) {\r | |
945 | Status = EFI_INVALID_PARAMETER;\r | |
946 | goto Done;\r | |
947 | }\r | |
948 | //\r | |
949 | // Check whether this question is for the requested varstore.\r | |
950 | //\r | |
951 | IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr;\r | |
952 | if (IfrOneOf->Question.VarStoreId != VarStorageData->VarStoreId) {\r | |
953 | break;\r | |
954 | }\r | |
955 | \r | |
956 | //\r | |
957 | // Get Offset/Width by Question header and OneOf Flags\r | |
958 | //\r | |
959 | VarOffset = IfrOneOf->Question.VarStoreInfo.VarOffset;\r | |
960 | VarWidth = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r | |
961 | //\r | |
962 | // Check whether this question is in requested block array.\r | |
963 | //\r | |
964 | if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth)) {\r | |
965 | //\r | |
966 | // This question is not in the requested string. Skip it.\r | |
967 | //\r | |
968 | break;\r | |
969 | }\r | |
970 | \r | |
971 | //\r | |
972 | // Check this var question is in the var storage \r | |
973 | //\r | |
974 | if ((VarOffset + VarWidth) > VarStorageData->Size) {\r | |
975 | Status = EFI_INVALID_PARAMETER;\r | |
976 | goto Done;\r | |
977 | }\r | |
978 | \r | |
979 | //\r | |
980 | // Set Block Data\r | |
981 | //\r | |
982 | BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r | |
983 | if (BlockData == NULL) {\r | |
984 | Status = EFI_OUT_OF_RESOURCES;\r | |
985 | goto Done;\r | |
986 | }\r | |
987 | BlockData->Offset = VarOffset;\r | |
988 | BlockData->Width = VarWidth;\r | |
989 | BlockData->QuestionId = IfrOneOf->Question.QuestionId;\r | |
990 | BlockData->OpCode = IfrOpHdr->OpCode;\r | |
991 | BlockData->Scope = IfrOpHdr->Scope;\r | |
992 | InitializeListHead (&BlockData->DefaultValueEntry);\r | |
993 | //\r | |
994 | // Add Block Data into VarStorageData BlockEntry\r | |
995 | //\r | |
996 | InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r | |
997 | \r | |
998 | if (IfrOpHdr->OpCode == EFI_IFR_ONE_OF_OP) {\r | |
999 | //\r | |
1000 | // Set this flag to TRUE for the first oneof option.\r | |
1001 | //\r | |
1002 | FirstOneOfOption = TRUE;\r | |
1003 | } else if (IfrOpHdr->OpCode == EFI_IFR_NUMERIC_OP) {\r | |
1004 | //\r | |
1005 | // Numeric minimum value will be used as default value when no default is specified. \r | |
1006 | //\r | |
1007 | \r | |
1008 | //\r | |
1009 | // Set standard ID\r | |
1010 | //\r | |
1011 | VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r | |
1012 | //\r | |
1013 | // Prepare new DefaultValue\r | |
1014 | //\r | |
1015 | DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
1016 | if (DefaultData == NULL) {\r | |
1017 | Status = EFI_OUT_OF_RESOURCES;\r | |
1018 | goto Done;\r | |
1019 | }\r | |
1020 | DefaultData->OpCode = IfrOpHdr->OpCode;\r | |
1021 | DefaultData->DefaultId = VarDefaultId;\r | |
1022 | \r | |
1023 | switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {\r | |
1024 | case EFI_IFR_NUMERIC_SIZE_1:\r | |
1025 | DefaultData->Value = (UINT64) IfrOneOf->data.u8.MinValue;\r | |
1026 | break;\r | |
1027 | \r | |
1028 | case EFI_IFR_NUMERIC_SIZE_2:\r | |
1029 | CopyMem (&DefaultData->Value, &IfrOneOf->data.u16.MinValue, sizeof (UINT16));\r | |
1030 | break;\r | |
1031 | \r | |
1032 | case EFI_IFR_NUMERIC_SIZE_4:\r | |
1033 | CopyMem (&DefaultData->Value, &IfrOneOf->data.u32.MinValue, sizeof (UINT32));\r | |
1034 | break;\r | |
1035 | \r | |
1036 | case EFI_IFR_NUMERIC_SIZE_8:\r | |
1037 | CopyMem (&DefaultData->Value, &IfrOneOf->data.u64.MinValue, sizeof (UINT64));\r | |
1038 | break;\r | |
1039 | }\r | |
1040 | //\r | |
1041 | // Add DefaultValue into current BlockData\r | |
1042 | //\r | |
1043 | InsertDefaultValue (BlockData, DefaultData); \r | |
1044 | }\r | |
1045 | break;\r | |
1046 | \r | |
1047 | case EFI_IFR_ORDERED_LIST_OP:\r | |
1048 | //\r | |
1049 | // offset by question header\r | |
1050 | // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type\r | |
1051 | // no default value and default id, how to define its default value?\r | |
1052 | //\r | |
1053 | \r | |
1054 | //\r | |
1055 | // OrderedList question is not in IFR Form. This IFR form is not valid. \r | |
1056 | //\r | |
1057 | if (VarStorageData->Size == 0) {\r | |
1058 | Status = EFI_INVALID_PARAMETER;\r | |
1059 | goto Done;\r | |
1060 | }\r | |
1061 | //\r | |
1062 | // Check whether this question is for the requested varstore.\r | |
1063 | //\r | |
1064 | IfrOrderedList = (EFI_IFR_ORDERED_LIST *) IfrOpHdr;\r | |
1065 | if (IfrOrderedList->Question.VarStoreId != VarStorageData->VarStoreId) {\r | |
1066 | BlockData = NULL;\r | |
1067 | break;\r | |
1068 | }\r | |
1069 | \r | |
1070 | //\r | |
1071 | // Get Offset/Width by Question header and OneOf Flags\r | |
1072 | //\r | |
1073 | VarOffset = IfrOrderedList->Question.VarStoreInfo.VarOffset;\r | |
1074 | VarWidth = IfrOrderedList->MaxContainers;\r | |
1075 | \r | |
1076 | //\r | |
1077 | // Set Block Data\r | |
1078 | //\r | |
1079 | BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r | |
1080 | if (BlockData == NULL) {\r | |
1081 | Status = EFI_OUT_OF_RESOURCES;\r | |
1082 | goto Done;\r | |
1083 | }\r | |
1084 | BlockData->Offset = VarOffset;\r | |
1085 | BlockData->Width = VarWidth;\r | |
1086 | BlockData->QuestionId = IfrOrderedList->Question.QuestionId;\r | |
1087 | BlockData->OpCode = IfrOpHdr->OpCode;\r | |
1088 | BlockData->Scope = IfrOpHdr->Scope;\r | |
1089 | InitializeListHead (&BlockData->DefaultValueEntry);\r | |
1090 | break;\r | |
1091 | \r | |
1092 | case EFI_IFR_CHECKBOX_OP:\r | |
1093 | //\r | |
1094 | // EFI_IFR_DEFAULT_OP\r | |
1095 | // offset by question header\r | |
1096 | // width is 1 sizeof (BOOLEAN)\r | |
1097 | // default id by CheckBox Flags if CheckBox flags (Default or Mau) is set, the default value is 1 to be set.\r | |
1098 | // value by DefaultOption\r | |
1099 | // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.\r | |
1100 | // \r | |
1101 | \r | |
1102 | //\r | |
1103 | // CheckBox question is not in IFR Form. This IFR form is not valid. \r | |
1104 | //\r | |
1105 | if (VarStorageData->Size == 0) {\r | |
1106 | Status = EFI_INVALID_PARAMETER;\r | |
1107 | goto Done;\r | |
1108 | }\r | |
1109 | //\r | |
1110 | // Check whether this question is for the requested varstore.\r | |
1111 | //\r | |
1112 | IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr;\r | |
1113 | if (IfrCheckBox->Question.VarStoreId != VarStorageData->VarStoreId) {\r | |
1114 | break;\r | |
1115 | }\r | |
1116 | \r | |
1117 | //\r | |
1118 | // Get Offset/Width by Question header and OneOf Flags\r | |
1119 | //\r | |
1120 | VarOffset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r | |
1121 | VarWidth = (UINT16) sizeof (BOOLEAN);\r | |
1122 | \r | |
1123 | //\r | |
1124 | // Check whether this question is in requested block array.\r | |
1125 | //\r | |
1126 | if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth)) {\r | |
1127 | //\r | |
1128 | // This question is not in the requested string. Skip it.\r | |
1129 | //\r | |
1130 | break;\r | |
1131 | }\r | |
1132 | \r | |
1133 | //\r | |
1134 | // Check this var question is in the var storage \r | |
1135 | //\r | |
1136 | if ((VarOffset + VarWidth) > VarStorageData->Size) {\r | |
1137 | Status = EFI_INVALID_PARAMETER;\r | |
1138 | goto Done;\r | |
1139 | }\r | |
1140 | \r | |
1141 | //\r | |
1142 | // Set Block Data\r | |
1143 | //\r | |
1144 | BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r | |
1145 | if (BlockData == NULL) {\r | |
1146 | Status = EFI_OUT_OF_RESOURCES;\r | |
1147 | goto Done;\r | |
1148 | }\r | |
1149 | BlockData->Offset = VarOffset;\r | |
1150 | BlockData->Width = VarWidth;\r | |
1151 | BlockData->QuestionId = IfrCheckBox->Question.QuestionId;\r | |
1152 | BlockData->OpCode = IfrOpHdr->OpCode;\r | |
1153 | BlockData->Scope = IfrOpHdr->Scope;\r | |
1154 | InitializeListHead (&BlockData->DefaultValueEntry);\r | |
1155 | //\r | |
1156 | // Add Block Data into VarStorageData BlockEntry\r | |
1157 | //\r | |
1158 | InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r | |
1159 | \r | |
1160 | //\r | |
1161 | // Add default value by CheckBox Flags \r | |
1162 | //\r | |
1163 | if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT) == EFI_IFR_CHECKBOX_DEFAULT) {\r | |
1164 | //\r | |
1165 | // Set standard ID to Manufacture ID\r | |
1166 | //\r | |
1167 | VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r | |
1168 | //\r | |
1169 | // Prepare new DefaultValue\r | |
1170 | //\r | |
1171 | DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
1172 | if (DefaultData == NULL) {\r | |
1173 | Status = EFI_OUT_OF_RESOURCES;\r | |
1174 | goto Done;\r | |
1175 | }\r | |
1176 | DefaultData->OpCode = IfrOpHdr->OpCode;\r | |
1177 | DefaultData->DefaultId = VarDefaultId;\r | |
1178 | DefaultData->Value = 1;\r | |
1179 | //\r | |
1180 | // Add DefaultValue into current BlockData\r | |
1181 | //\r | |
1182 | InsertDefaultValue (BlockData, DefaultData);\r | |
1183 | }\r | |
1184 | \r | |
1185 | if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) == EFI_IFR_CHECKBOX_DEFAULT_MFG) {\r | |
1186 | //\r | |
1187 | // Set standard ID to Manufacture ID\r | |
1188 | //\r | |
1189 | VarDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r | |
1190 | //\r | |
1191 | // Prepare new DefaultValue\r | |
1192 | //\r | |
1193 | DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
1194 | if (DefaultData == NULL) {\r | |
1195 | Status = EFI_OUT_OF_RESOURCES;\r | |
1196 | goto Done;\r | |
1197 | }\r | |
1198 | DefaultData->OpCode = IfrOpHdr->OpCode;\r | |
1199 | DefaultData->DefaultId = VarDefaultId;\r | |
1200 | DefaultData->Value = 1;\r | |
1201 | //\r | |
1202 | // Add DefaultValue into current BlockData\r | |
1203 | //\r | |
1204 | InsertDefaultValue (BlockData, DefaultData);\r | |
1205 | }\r | |
1206 | break;\r | |
1207 | \r | |
1208 | case EFI_IFR_STRING_OP:\r | |
1209 | //\r | |
1210 | // offset by question header\r | |
1211 | // width MaxSize * sizeof (CHAR16)\r | |
1212 | // no default value, only block array\r | |
1213 | //\r | |
1214 | \r | |
1215 | //\r | |
1216 | // String question is not in IFR Form. This IFR form is not valid. \r | |
1217 | //\r | |
1218 | if (VarStorageData->Size == 0) {\r | |
1219 | Status = EFI_INVALID_PARAMETER;\r | |
1220 | goto Done;\r | |
1221 | }\r | |
1222 | //\r | |
1223 | // Check whether this question is for the requested varstore.\r | |
1224 | //\r | |
1225 | IfrString = (EFI_IFR_STRING *) IfrOpHdr;\r | |
1226 | if (IfrString->Question.VarStoreId != VarStorageData->VarStoreId) {\r | |
1227 | break;\r | |
1228 | }\r | |
1229 | \r | |
1230 | //\r | |
1231 | // Get Offset/Width by Question header and OneOf Flags\r | |
1232 | //\r | |
1233 | VarOffset = IfrString->Question.VarStoreInfo.VarOffset;\r | |
1234 | VarWidth = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r | |
1235 | \r | |
1236 | //\r | |
1237 | // Check whether this question is in requested block array.\r | |
1238 | //\r | |
1239 | if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth)) {\r | |
1240 | //\r | |
1241 | // This question is not in the requested string. Skip it.\r | |
1242 | //\r | |
1243 | break;\r | |
1244 | }\r | |
1245 | \r | |
1246 | //\r | |
1247 | // Check this var question is in the var storage \r | |
1248 | //\r | |
1249 | if ((VarOffset + VarWidth) > VarStorageData->Size) {\r | |
1250 | Status = EFI_INVALID_PARAMETER;\r | |
1251 | goto Done;\r | |
1252 | }\r | |
1253 | \r | |
1254 | //\r | |
1255 | // Set Block Data\r | |
1256 | //\r | |
1257 | BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r | |
1258 | if (BlockData == NULL) {\r | |
1259 | Status = EFI_OUT_OF_RESOURCES;\r | |
1260 | goto Done;\r | |
1261 | }\r | |
1262 | BlockData->Offset = VarOffset;\r | |
1263 | BlockData->Width = VarWidth;\r | |
1264 | BlockData->QuestionId = IfrString->Question.QuestionId;\r | |
1265 | BlockData->OpCode = IfrOpHdr->OpCode;\r | |
1266 | InitializeListHead (&BlockData->DefaultValueEntry);\r | |
1267 | \r | |
1268 | //\r | |
1269 | // Add Block Data into VarStorageData BlockEntry\r | |
1270 | //\r | |
1271 | InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r | |
1272 | \r | |
1273 | //\r | |
1274 | // No default value for string.\r | |
1275 | //\r | |
1276 | BlockData = NULL;\r | |
1277 | break;\r | |
1278 | \r | |
1279 | case EFI_IFR_PASSWORD_OP:\r | |
1280 | //\r | |
1281 | // offset by question header\r | |
1282 | // width MaxSize * sizeof (CHAR16)\r | |
1283 | // no default value, only block array\r | |
1284 | //\r | |
1285 | \r | |
1286 | //\r | |
1287 | // Password question is not in IFR Form. This IFR form is not valid. \r | |
1288 | //\r | |
1289 | if (VarStorageData->Size == 0) {\r | |
1290 | Status = EFI_INVALID_PARAMETER;\r | |
1291 | goto Done;\r | |
1292 | }\r | |
1293 | //\r | |
1294 | // Check whether this question is for the requested varstore.\r | |
1295 | //\r | |
1296 | IfrPassword = (EFI_IFR_PASSWORD *) IfrOpHdr;\r | |
1297 | if (IfrPassword->Question.VarStoreId != VarStorageData->VarStoreId) {\r | |
1298 | break;\r | |
1299 | }\r | |
1300 | \r | |
1301 | //\r | |
1302 | // Get Offset/Width by Question header and OneOf Flags\r | |
1303 | //\r | |
1304 | VarOffset = IfrPassword->Question.VarStoreInfo.VarOffset;\r | |
1305 | VarWidth = (UINT16) (IfrPassword->MaxSize * sizeof (UINT16));\r | |
1306 | \r | |
1307 | //\r | |
1308 | // Check whether this question is in requested block array.\r | |
1309 | //\r | |
1310 | if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth)) {\r | |
1311 | //\r | |
1312 | // This question is not in the requested string. Skip it.\r | |
1313 | //\r | |
1314 | break;\r | |
1315 | }\r | |
1316 | \r | |
1317 | //\r | |
1318 | // Check this var question is in the var storage \r | |
1319 | //\r | |
1320 | if ((VarOffset + VarWidth) > VarStorageData->Size) {\r | |
1321 | Status = EFI_INVALID_PARAMETER;\r | |
1322 | goto Done;\r | |
1323 | }\r | |
1324 | \r | |
1325 | //\r | |
1326 | // Set Block Data\r | |
1327 | //\r | |
1328 | BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r | |
1329 | if (BlockData == NULL) {\r | |
1330 | Status = EFI_OUT_OF_RESOURCES;\r | |
1331 | goto Done;\r | |
1332 | }\r | |
1333 | BlockData->Offset = VarOffset;\r | |
1334 | BlockData->Width = VarWidth;\r | |
1335 | BlockData->QuestionId = IfrPassword->Question.QuestionId;\r | |
1336 | BlockData->OpCode = IfrOpHdr->OpCode;\r | |
1337 | InitializeListHead (&BlockData->DefaultValueEntry);\r | |
1338 | \r | |
1339 | //\r | |
1340 | // Add Block Data into VarStorageData BlockEntry\r | |
1341 | //\r | |
1342 | InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r | |
1343 | \r | |
1344 | //\r | |
1345 | // No default value for string.\r | |
1346 | //\r | |
1347 | BlockData = NULL;\r | |
1348 | break;\r | |
1349 | \r | |
1350 | case EFI_IFR_ONE_OF_OPTION_OP:\r | |
1351 | //\r | |
1352 | // No matched block data is ignored.\r | |
1353 | //\r | |
1354 | if (BlockData == NULL || BlockData->Scope == 0) {\r | |
1355 | break;\r | |
1356 | }\r | |
1357 | \r | |
1358 | IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr;\r | |
1359 | if (BlockData->OpCode == EFI_IFR_ORDERED_LIST_OP) {\r | |
1360 | //\r | |
1361 | // Get ordered list option data type.\r | |
1362 | //\r | |
1363 | if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_8 || IfrOneOfOption->Type == EFI_IFR_TYPE_BOOLEAN) {\r | |
1364 | VarWidth = 1;\r | |
1365 | } else if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_16) {\r | |
1366 | VarWidth = 2;\r | |
1367 | } else if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_32) {\r | |
1368 | VarWidth = 4;\r | |
1369 | } else if (IfrOneOfOption->Type == EFI_IFR_TYPE_NUM_SIZE_64) {\r | |
1370 | VarWidth = 8;\r | |
1371 | } else {\r | |
1372 | //\r | |
1373 | // Invalid ordered list option data type.\r | |
1374 | //\r | |
1375 | Status = EFI_INVALID_PARAMETER;\r | |
1376 | FreePool (BlockData);\r | |
1377 | goto Done;\r | |
1378 | }\r | |
1379 | \r | |
1380 | //\r | |
1381 | // Calculate Ordered list QuestionId width.\r | |
1382 | //\r | |
1383 | BlockData->Width = (UINT16) (BlockData->Width * VarWidth);\r | |
1384 | //\r | |
1385 | // Check whether this question is in requested block array.\r | |
1386 | //\r | |
1387 | if (!BlockArrayCheck (RequestBlockArray, BlockData->Offset, BlockData->Width)) {\r | |
1388 | //\r | |
1389 | // This question is not in the requested string. Skip it.\r | |
1390 | //\r | |
1391 | FreePool (BlockData);\r | |
1392 | BlockData = NULL;\r | |
1393 | break;\r | |
1394 | }\r | |
1395 | //\r | |
1396 | // Check this var question is in the var storage \r | |
1397 | //\r | |
1398 | if ((BlockData->Offset + BlockData->Width) > VarStorageData->Size) {\r | |
1399 | Status = EFI_INVALID_PARAMETER;\r | |
1400 | FreePool (BlockData);\r | |
1401 | goto Done;\r | |
1402 | }\r | |
1403 | //\r | |
1404 | // Add Block Data into VarStorageData BlockEntry\r | |
1405 | //\r | |
1406 | InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r | |
1407 | //\r | |
1408 | // No default data for OrderedList.\r | |
1409 | //\r | |
1410 | BlockData = NULL;\r | |
1411 | break;\r | |
1412 | }\r | |
1413 | \r | |
1414 | if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) ||\r | |
1415 | (BlockData->OpCode == EFI_IFR_ONE_OF_OP && FirstOneOfOption)) {\r | |
1416 | //\r | |
1417 | // This flag is used to specify whether this option is the first. Set it to FALSE for the following options. \r | |
1418 | // The first oneof option value will be used as default value when no default value is specified. \r | |
1419 | //\r | |
1420 | FirstOneOfOption = FALSE;\r | |
1421 | //\r | |
1422 | // Set standard ID to Manufacture ID\r | |
1423 | //\r | |
1424 | VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r | |
1425 | //\r | |
1426 | // Prepare new DefaultValue\r | |
1427 | //\r | |
1428 | DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
1429 | if (DefaultData == NULL) {\r | |
1430 | Status = EFI_OUT_OF_RESOURCES;\r | |
1431 | goto Done;\r | |
1432 | }\r | |
1433 | DefaultData->OpCode = IfrOpHdr->OpCode;\r | |
1434 | DefaultData->DefaultId = VarDefaultId;\r | |
1435 | DefaultData->Value = IfrOneOfOption->Value.u64;\r | |
1436 | //\r | |
1437 | // Add DefaultValue into current BlockData\r | |
1438 | //\r | |
1439 | InsertDefaultValue (BlockData, DefaultData);\r | |
1440 | }\r | |
1441 | \r | |
1442 | if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG) {\r | |
1443 | //\r | |
1444 | // Set default ID to Manufacture ID\r | |
1445 | //\r | |
1446 | VarDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r | |
1447 | //\r | |
1448 | // Prepare new DefaultValue\r | |
1449 | //\r | |
1450 | DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
1451 | if (DefaultData == NULL) {\r | |
1452 | Status = EFI_OUT_OF_RESOURCES;\r | |
1453 | goto Done;\r | |
1454 | }\r | |
1455 | DefaultData->OpCode = IfrOpHdr->OpCode;\r | |
1456 | DefaultData->DefaultId = VarDefaultId;\r | |
1457 | DefaultData->Value = IfrOneOfOption->Value.u64;\r | |
1458 | //\r | |
1459 | // Add DefaultValue into current BlockData\r | |
1460 | //\r | |
1461 | InsertDefaultValue (BlockData, DefaultData);\r | |
1462 | }\r | |
1463 | break;\r | |
1464 | \r | |
1465 | case EFI_IFR_DEFAULT_OP:\r | |
1466 | //\r | |
1467 | // Update Current BlockData to the default value.\r | |
1468 | //\r | |
1469 | if (BlockData == NULL || BlockData->Scope == 0) {\r | |
1470 | //\r | |
1471 | // No matched block data is ignored. \r | |
1472 | //\r | |
1473 | break;\r | |
1474 | }\r | |
1475 | \r | |
1476 | if (BlockData->OpCode == EFI_IFR_ORDERED_LIST_OP) {\r | |
1477 | //\r | |
1478 | // OrderedList Opcode is no default value.\r | |
1479 | //\r | |
1480 | break;\r | |
1481 | }\r | |
1482 | //\r | |
1483 | // Get the DefaultId\r | |
1484 | //\r | |
1485 | IfrDefault = (EFI_IFR_DEFAULT *) IfrOpHdr;\r | |
1486 | VarDefaultId = IfrDefault->DefaultId;\r | |
1487 | //\r | |
1488 | // Prepare new DefaultValue\r | |
1489 | //\r | |
1490 | DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
1491 | if (DefaultData == NULL) {\r | |
1492 | Status = EFI_OUT_OF_RESOURCES;\r | |
1493 | goto Done;\r | |
1494 | }\r | |
1495 | DefaultData->OpCode = IfrOpHdr->OpCode;\r | |
1496 | DefaultData->DefaultId = VarDefaultId;\r | |
1497 | DefaultData->Value = IfrDefault->Value.u64;\r | |
1498 | //\r | |
1499 | // Add DefaultValue into current BlockData\r | |
1500 | //\r | |
1501 | InsertDefaultValue (BlockData, DefaultData);\r | |
1502 | break;\r | |
1503 | case EFI_IFR_END_OP:\r | |
1504 | //\r | |
1505 | // End Opcode is for Var question.\r | |
1506 | //\r | |
1507 | if (BlockData != NULL && BlockData->Scope > 0) {\r | |
1508 | BlockData->Scope--;\r | |
1509 | }\r | |
1510 | break;\r | |
1511 | default:\r | |
1512 | if (BlockData != NULL && BlockData->Scope > 0) {\r | |
1513 | BlockData->Scope = (UINT8) (BlockData->Scope + IfrOpHdr->Scope);\r | |
1514 | }\r | |
1515 | break;\r | |
1516 | }\r | |
1517 | \r | |
1518 | IfrOffset += IfrOpHdr->Length;\r | |
1519 | }\r | |
1520 | \r | |
1521 | Done:\r | |
1522 | return Status; \r | |
1523 | }\r | |
1524 | \r | |
1525 | /**\r | |
1526 | This function gets the full request string and full default value string by \r | |
1527 | parsing IFR data in HII form packages. \r | |
1528 | \r | |
1529 | When Request points to NULL string, the request string and default value string \r | |
1530 | for each varstore in form package will return. \r | |
1531 | \r | |
1532 | @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.\r | |
1533 | @param DevicePath Device Path which Hii Config Access Protocol is registered.\r | |
1534 | @param Request Pointer to a null-terminated Unicode string in\r | |
1535 | <ConfigRequest> format. When it doesn't contain\r | |
1536 | any RequestElement, it will be updated to return \r | |
1537 | the full RequestElement retrieved from IFR data.\r | |
1538 | If it points to NULL, the request string for the first\r | |
1539 | varstore in form package will be merged into a\r | |
1540 | <MultiConfigRequest> format string and return. \r | |
1541 | @param AltCfgResp Pointer to a null-terminated Unicode string in\r | |
1542 | <ConfigAltResp> format. When the pointer is to NULL,\r | |
1543 | the full default value string retrieved from IFR data\r | |
1544 | will return. When the pinter is to a string, the\r | |
1545 | full default value string retrieved from IFR data\r | |
1546 | will be merged into the input string and return.\r | |
1547 | When Request points to NULL, the default value string \r | |
1548 | for each varstore in form package will be merged into \r | |
1549 | a <MultiConfigAltResp> format string and return.\r | |
1550 | @param PointerProgress Optional parameter, it can be be NULL. \r | |
1551 | When it is not NULL, if Request is NULL, it returns NULL. \r | |
1552 | On return, points to a character in the Request\r | |
1553 | string. Points to the string's null terminator if\r | |
1554 | request was successful. Points to the most recent\r | |
1555 | & before the first failing name / value pair (or\r | |
1556 | the beginning of the string if the failure is in\r | |
1557 | the first name / value pair) if the request was\r | |
1558 | not successful.\r | |
1559 | @retval EFI_SUCCESS The Results string is set to the full request string.\r | |
1560 | And AltCfgResp contains all default value string.\r | |
1561 | @retval EFI_OUT_OF_RESOURCES Not enough memory for the return string.\r | |
1562 | @retval EFI_NOT_FOUND The varstore (Guid and Name) in Request string \r | |
1563 | can't be found in Form package.\r | |
1564 | @retval EFI_NOT_FOUND HiiPackage can't be got on the input HiiHandle.\r | |
1565 | @retval EFI_INVALID_PARAMETER Request points to NULL.\r | |
1566 | \r | |
1567 | **/\r | |
1568 | EFI_STATUS\r | |
1569 | EFIAPI\r | |
1570 | GetFullStringFromHiiFormPackages (\r | |
1571 | IN HII_DATABASE_RECORD *DataBaseRecord,\r | |
1572 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
1573 | IN OUT EFI_STRING *Request,\r | |
1574 | IN OUT EFI_STRING *AltCfgResp,\r | |
1575 | OUT EFI_STRING *PointerProgress OPTIONAL\r | |
1576 | )\r | |
1577 | {\r | |
1578 | EFI_STATUS Status;\r | |
1579 | UINT8 *HiiFormPackage;\r | |
1580 | UINTN PackageSize;\r | |
1581 | UINTN ResultSize;\r | |
1582 | IFR_BLOCK_DATA *RequestBlockArray;\r | |
1583 | IFR_BLOCK_DATA *BlockData;\r | |
1584 | IFR_BLOCK_DATA *NextBlockData;\r | |
1585 | IFR_DEFAULT_DATA *DefaultValueData;\r | |
1586 | IFR_DEFAULT_DATA *DefaultId;\r | |
1587 | IFR_DEFAULT_DATA *DefaultIdArray;\r | |
1588 | IFR_VARSTORAGE_DATA *VarStorageData;\r | |
1589 | EFI_STRING DefaultAltCfgResp;\r | |
1590 | EFI_STRING FullConfigRequest;\r | |
1591 | EFI_STRING ConfigHdr;\r | |
1592 | EFI_STRING GuidStr;\r | |
1593 | EFI_STRING NameStr;\r | |
1594 | EFI_STRING PathStr;\r | |
1595 | EFI_STRING StringPtr;\r | |
1596 | EFI_STRING Progress;\r | |
1597 | UINTN Length;\r | |
1598 | UINT8 *TmpBuffer;\r | |
1599 | UINT16 Offset;\r | |
1600 | UINT16 Width;\r | |
1601 | LIST_ENTRY *Link;\r | |
1602 | LIST_ENTRY *LinkData;\r | |
1603 | LIST_ENTRY *LinkDefault;\r | |
1604 | BOOLEAN DataExist;\r | |
1605 | \r | |
1606 | if (DataBaseRecord == NULL || DevicePath == NULL || Request == NULL || AltCfgResp == NULL) {\r | |
1607 | return EFI_INVALID_PARAMETER;\r | |
1608 | }\r | |
1609 | \r | |
1610 | //\r | |
1611 | // Initialize the local variables.\r | |
1612 | //\r | |
1613 | RequestBlockArray = NULL;\r | |
1614 | DefaultIdArray = NULL;\r | |
1615 | VarStorageData = NULL;\r | |
1616 | DefaultAltCfgResp = NULL;\r | |
1617 | FullConfigRequest = NULL;\r | |
1618 | ConfigHdr = NULL;\r | |
1619 | GuidStr = NULL;\r | |
1620 | NameStr = NULL;\r | |
1621 | PathStr = NULL;\r | |
1622 | HiiFormPackage = NULL;\r | |
1623 | ResultSize = 0;\r | |
1624 | PackageSize = 0;\r | |
1625 | DataExist = FALSE;\r | |
1626 | Progress = *Request;\r | |
1627 | \r | |
1628 | //\r | |
1629 | // 0. Get Hii Form Package by HiiHandle\r | |
1630 | //\r | |
1631 | Status = ExportFormPackages (\r | |
1632 | &mPrivate, \r | |
1633 | DataBaseRecord->Handle, \r | |
1634 | DataBaseRecord->PackageList, \r | |
1635 | 0, \r | |
1636 | PackageSize, \r | |
1637 | HiiFormPackage,\r | |
1638 | &ResultSize\r | |
1639 | );\r | |
1640 | if (EFI_ERROR (Status)) {\r | |
1641 | return Status;\r | |
1642 | }\r | |
1643 | \r | |
1644 | HiiFormPackage = AllocatePool (ResultSize);\r | |
1645 | if (HiiFormPackage == NULL) {\r | |
1646 | Status = EFI_OUT_OF_RESOURCES;\r | |
1647 | goto Done;\r | |
1648 | }\r | |
1649 | \r | |
1650 | //\r | |
1651 | // Get HiiFormPackage by HiiHandle\r | |
1652 | //\r | |
1653 | PackageSize = ResultSize;\r | |
1654 | ResultSize = 0;\r | |
1655 | Status = ExportFormPackages (\r | |
1656 | &mPrivate, \r | |
1657 | DataBaseRecord->Handle, \r | |
1658 | DataBaseRecord->PackageList, \r | |
1659 | 0,\r | |
1660 | PackageSize, \r | |
1661 | HiiFormPackage,\r | |
1662 | &ResultSize\r | |
1663 | );\r | |
1664 | if (EFI_ERROR (Status)) {\r | |
1665 | goto Done;\r | |
1666 | }\r | |
1667 | \r | |
1668 | //\r | |
1669 | // 1. Get the request block array by Request String when Request string containts the block array.\r | |
1670 | //\r | |
1671 | StringPtr = NULL;\r | |
1672 | if (*Request != NULL) {\r | |
1673 | StringPtr = *Request;\r | |
1674 | //\r | |
1675 | // Jump <ConfigHdr>\r | |
1676 | //\r | |
1677 | if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r | |
1678 | Status = EFI_INVALID_PARAMETER;\r | |
1679 | goto Done;\r | |
1680 | }\r | |
1681 | StringPtr += StrLen (L"GUID=");\r | |
1682 | while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) {\r | |
1683 | StringPtr++;\r | |
1684 | }\r | |
1685 | if (*StringPtr == L'\0') {\r | |
1686 | Status = EFI_INVALID_PARAMETER;\r | |
1687 | goto Done;\r | |
1688 | }\r | |
1689 | StringPtr += StrLen (L"&NAME=");\r | |
1690 | while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) {\r | |
1691 | StringPtr++;\r | |
1692 | }\r | |
1693 | if (*StringPtr == L'\0') {\r | |
1694 | Status = EFI_INVALID_PARAMETER;\r | |
1695 | goto Done;\r | |
1696 | }\r | |
1697 | StringPtr += StrLen (L"&PATH=");\r | |
1698 | while (*StringPtr != L'\0' && *StringPtr != L'&') {\r | |
1699 | StringPtr ++;\r | |
1700 | }\r | |
1701 | //\r | |
1702 | // Check the following string &OFFSET=\r | |
1703 | //\r | |
1704 | if (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) != 0) {\r | |
1705 | Progress = StringPtr;\r | |
1706 | Status = EFI_INVALID_PARAMETER;\r | |
1707 | goto Done;\r | |
1708 | } else if (*StringPtr == L'\0') {\r | |
1709 | //\r | |
1710 | // No request block is found.\r | |
1711 | //\r | |
1712 | StringPtr = NULL;\r | |
1713 | }\r | |
1714 | }\r | |
1715 | if (StringPtr != NULL) {\r | |
1716 | //\r | |
1717 | // Init RequestBlockArray\r | |
1718 | //\r | |
1719 | RequestBlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r | |
1720 | if (RequestBlockArray == NULL) {\r | |
1721 | Status = EFI_OUT_OF_RESOURCES;\r | |
1722 | goto Done;\r | |
1723 | }\r | |
1724 | InitializeListHead (&RequestBlockArray->Entry);\r | |
1725 | \r | |
1726 | //\r | |
1727 | // Get the request Block array from the request string\r | |
1728 | // Offset and Width\r | |
1729 | //\r | |
1730 | \r | |
1731 | //\r | |
1732 | // Parse each <RequestElement> if exists\r | |
1733 | // Only <BlockName> format is supported by this help function.\r | |
1734 | // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>\r | |
1735 | //\r | |
1736 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) {\r | |
1737 | //\r | |
1738 | // Skip the OFFSET string\r | |
1739 | //\r | |
1740 | Progress = StringPtr;\r | |
1741 | StringPtr += StrLen (L"&OFFSET=");\r | |
1742 | //\r | |
1743 | // Get Offset\r | |
1744 | //\r | |
1745 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r | |
1746 | if (EFI_ERROR (Status)) {\r | |
1747 | goto Done;\r | |
1748 | }\r | |
1749 | Offset = 0;\r | |
1750 | CopyMem (\r | |
1751 | &Offset,\r | |
1752 | TmpBuffer,\r | |
1753 | (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r | |
1754 | );\r | |
1755 | FreePool (TmpBuffer);\r | |
1756 | \r | |
1757 | StringPtr += Length;\r | |
1758 | if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r | |
1759 | Status = EFI_INVALID_PARAMETER;\r | |
1760 | goto Done;\r | |
1761 | }\r | |
1762 | StringPtr += StrLen (L"&WIDTH=");\r | |
1763 | \r | |
1764 | //\r | |
1765 | // Get Width\r | |
1766 | //\r | |
1767 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r | |
1768 | if (EFI_ERROR (Status)) {\r | |
1769 | goto Done;\r | |
1770 | }\r | |
1771 | Width = 0;\r | |
1772 | CopyMem (\r | |
1773 | &Width,\r | |
1774 | TmpBuffer,\r | |
1775 | (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r | |
1776 | );\r | |
1777 | FreePool (TmpBuffer);\r | |
1778 | \r | |
1779 | StringPtr += Length;\r | |
1780 | if (*StringPtr != 0 && *StringPtr != L'&') {\r | |
1781 | Status = EFI_INVALID_PARAMETER;\r | |
1782 | goto Done;\r | |
1783 | }\r | |
1784 | \r | |
1785 | //\r | |
1786 | // Set Block Data\r | |
1787 | //\r | |
1788 | BlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r | |
1789 | if (BlockData == NULL) {\r | |
1790 | Status = EFI_OUT_OF_RESOURCES;\r | |
1791 | goto Done;\r | |
1792 | }\r | |
1793 | BlockData->Offset = Offset;\r | |
1794 | BlockData->Width = Width;\r | |
1795 | InsertBlockData (&RequestBlockArray->Entry, &BlockData);\r | |
1796 | \r | |
1797 | //\r | |
1798 | // Skip &VALUE string if &VALUE does exists.\r | |
1799 | //\r | |
1800 | if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) == 0) {\r | |
1801 | StringPtr += StrLen (L"&VALUE=");\r | |
1802 | \r | |
1803 | //\r | |
1804 | // Get Value\r | |
1805 | //\r | |
1806 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r | |
1807 | if (EFI_ERROR (Status)) {\r | |
1808 | Status = EFI_INVALID_PARAMETER;\r | |
1809 | goto Done;\r | |
1810 | }\r | |
1811 | \r | |
1812 | StringPtr += Length;\r | |
1813 | if (*StringPtr != 0 && *StringPtr != L'&') {\r | |
1814 | Status = EFI_INVALID_PARAMETER;\r | |
1815 | goto Done;\r | |
1816 | }\r | |
1817 | }\r | |
1818 | //\r | |
1819 | // If '\0', parsing is finished. \r | |
1820 | //\r | |
1821 | if (*StringPtr == 0) {\r | |
1822 | break;\r | |
1823 | }\r | |
1824 | }\r | |
1825 | \r | |
1826 | //\r | |
1827 | // Merge the requested block data.\r | |
1828 | //\r | |
1829 | Link = RequestBlockArray->Entry.ForwardLink;\r | |
1830 | while ((Link != &RequestBlockArray->Entry) && (Link->ForwardLink != &RequestBlockArray->Entry)) {\r | |
1831 | BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r | |
1832 | NextBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry);\r | |
1833 | if ((NextBlockData->Offset >= BlockData->Offset) && (NextBlockData->Offset <= (BlockData->Offset + BlockData->Width))) {\r | |
1834 | if ((NextBlockData->Offset + NextBlockData->Width) > (BlockData->Offset + BlockData->Width)) {\r | |
1835 | BlockData->Width = (UINT16) (NextBlockData->Offset + NextBlockData->Width - BlockData->Offset);\r | |
1836 | }\r | |
1837 | RemoveEntryList (Link->ForwardLink);\r | |
1838 | FreePool (NextBlockData);\r | |
1839 | continue;\r | |
1840 | }\r | |
1841 | Link = Link->ForwardLink; \r | |
1842 | }\r | |
1843 | }\r | |
1844 | \r | |
1845 | //\r | |
1846 | // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.\r | |
1847 | //\r | |
1848 | \r | |
1849 | //\r | |
1850 | // Initialize DefaultIdArray to store the map between DeaultId and DefaultName\r | |
1851 | //\r | |
1852 | DefaultIdArray = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r | |
1853 | if (DefaultIdArray == NULL) {\r | |
1854 | Status = EFI_OUT_OF_RESOURCES;\r | |
1855 | goto Done;\r | |
1856 | }\r | |
1857 | InitializeListHead (&DefaultIdArray->Entry);\r | |
1858 | \r | |
1859 | //\r | |
1860 | // Initialize VarStorageData to store the var store Block and Default value information.\r | |
1861 | //\r | |
1862 | VarStorageData = (IFR_VARSTORAGE_DATA *) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA));\r | |
1863 | if (VarStorageData == NULL) {\r | |
1864 | Status = EFI_OUT_OF_RESOURCES;\r | |
1865 | goto Done;\r | |
1866 | }\r | |
1867 | InitializeListHead (&VarStorageData->Entry);\r | |
1868 | InitializeListHead (&VarStorageData->BlockEntry);\r | |
1869 | \r | |
1870 | //\r | |
1871 | // Parse the opcode in form pacakge to get the default setting.\r | |
1872 | //\r | |
1873 | Status = ParseIfrData (HiiFormPackage, (UINT32) PackageSize, *Request, RequestBlockArray, VarStorageData, DefaultIdArray);\r | |
1874 | if (EFI_ERROR (Status)) {\r | |
1875 | goto Done;\r | |
1876 | }\r | |
1877 | \r | |
1878 | //\r | |
1879 | // No requested varstore in IFR data and directly return\r | |
1880 | //\r | |
1881 | if (VarStorageData->Size == 0) {\r | |
1882 | Status = EFI_SUCCESS;\r | |
1883 | goto Done;\r | |
1884 | }\r | |
1885 | \r | |
1886 | //\r | |
1887 | // 3. Construct Request Element (Block Name) for 2.1 and 2.2 case.\r | |
1888 | //\r | |
1889 | \r | |
1890 | //\r | |
1891 | // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..." by VarStorageData Guid, Name and DriverHandle\r | |
1892 | //\r | |
1893 | GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) &VarStorageData->Guid, 1, &GuidStr);\r | |
1894 | GenerateSubStr (L"NAME=", StrLen (VarStorageData->Name) * sizeof (CHAR16), (VOID *) VarStorageData->Name, 2, &NameStr);\r | |
1895 | GenerateSubStr (\r | |
1896 | L"PATH=",\r | |
1897 | GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),\r | |
1898 | (VOID *) DevicePath,\r | |
1899 | 1,\r | |
1900 | &PathStr\r | |
1901 | );\r | |
1902 | Length = StrLen (GuidStr);\r | |
1903 | Length = Length + StrLen (NameStr);\r | |
1904 | Length = Length + StrLen (PathStr) + 1;\r | |
1905 | ConfigHdr = AllocateZeroPool (Length * sizeof (CHAR16));\r | |
1906 | if (ConfigHdr == NULL) {\r | |
1907 | Status = EFI_OUT_OF_RESOURCES;\r | |
1908 | goto Done; \r | |
1909 | }\r | |
1910 | StrCpy (ConfigHdr, GuidStr);\r | |
1911 | StrCat (ConfigHdr, NameStr);\r | |
1912 | StrCat (ConfigHdr, PathStr);\r | |
1913 | \r | |
1914 | //\r | |
1915 | // Remove the last character L'&'\r | |
1916 | //\r | |
1917 | *(ConfigHdr + StrLen (ConfigHdr) - 1) = L'\0';\r | |
1918 | \r | |
1919 | if (RequestBlockArray == NULL) {\r | |
1920 | //\r | |
1921 | // Append VarStorageData BlockEntry into *Request string\r | |
1922 | // Now support only one varstore in a form package.\r | |
1923 | //\r | |
1924 | \r | |
1925 | //\r | |
1926 | // Go through all VarStorageData Entry and get BlockEntry for each one for the multiple varstore in a single form package\r | |
1927 | // Then construct them all to return MultiRequest string : ConfigHdr BlockConfig\r | |
1928 | //\r | |
1929 | \r | |
1930 | //\r | |
1931 | // Compute the length of the entire request starting with <ConfigHdr> and a \r | |
1932 | // Null-terminator\r | |
1933 | //\r | |
1934 | DataExist = FALSE;\r | |
1935 | Length = StrLen (ConfigHdr) + 1;\r | |
1936 | \r | |
1937 | for (Link = VarStorageData->BlockEntry.ForwardLink; Link != &VarStorageData->BlockEntry; Link = Link->ForwardLink) {\r | |
1938 | //\r | |
1939 | // Add <BlockName> length for each Offset/Width pair\r | |
1940 | //\r | |
1941 | // <BlockName> ::= &OFFSET=1234&WIDTH=1234\r | |
1942 | // | 8 | 4 | 7 | 4 |\r | |
1943 | //\r | |
1944 | DataExist = TRUE;\r | |
1945 | Length = Length + (8 + 4 + 7 + 4);\r | |
1946 | }\r | |
1947 | \r | |
1948 | //\r | |
1949 | // No any request block data is found. The request string can't be constructed.\r | |
1950 | //\r | |
1951 | if (!DataExist) {\r | |
1952 | Status = EFI_SUCCESS;\r | |
1953 | goto Done;\r | |
1954 | }\r | |
1955 | \r | |
1956 | //\r | |
1957 | // Allocate buffer for the entire <ConfigRequest>\r | |
1958 | //\r | |
1959 | FullConfigRequest = AllocateZeroPool (Length * sizeof (CHAR16));\r | |
1960 | if (FullConfigRequest == NULL) {\r | |
1961 | Status = EFI_OUT_OF_RESOURCES;\r | |
1962 | goto Done;\r | |
1963 | }\r | |
1964 | StringPtr = FullConfigRequest;\r | |
1965 | \r | |
1966 | //\r | |
1967 | // Start with <ConfigHdr>\r | |
1968 | //\r | |
1969 | StrCpy (StringPtr, ConfigHdr);\r | |
1970 | StringPtr += StrLen (StringPtr);\r | |
1971 | \r | |
1972 | //\r | |
1973 | // Loop through all the Offset/Width pairs and append them to ConfigRequest\r | |
1974 | //\r | |
1975 | for (Link = VarStorageData->BlockEntry.ForwardLink; Link != &VarStorageData->BlockEntry; Link = Link->ForwardLink) {\r | |
1976 | BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r | |
1977 | //\r | |
1978 | // Append &OFFSET=XXXX&WIDTH=YYYY\0\r | |
1979 | //\r | |
1980 | UnicodeSPrint (\r | |
1981 | StringPtr, \r | |
1982 | (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16), \r | |
1983 | L"&OFFSET=%04X&WIDTH=%04X", \r | |
1984 | BlockData->Offset, \r | |
1985 | BlockData->Width\r | |
1986 | );\r | |
1987 | StringPtr += StrLen (StringPtr);\r | |
1988 | }\r | |
1989 | //\r | |
1990 | // Set to the got full request string.\r | |
1991 | //\r | |
1992 | HiiToLower (FullConfigRequest);\r | |
1993 | if (*Request != NULL) {\r | |
1994 | FreePool (*Request);\r | |
1995 | }\r | |
1996 | *Request = FullConfigRequest;\r | |
1997 | }\r | |
1998 | \r | |
1999 | //\r | |
2000 | // 4. Construct Default Value string in AltResp according to request element.\r | |
2001 | // Go through all VarStorageData Entry and get the DefaultId array for each one\r | |
2002 | // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody\r | |
2003 | //\r | |
2004 | DataExist = FALSE;\r | |
2005 | //\r | |
2006 | // Add length for <ConfigHdr> + '\0'\r | |
2007 | //\r | |
2008 | Length = StrLen (ConfigHdr) + 1;\r | |
2009 | \r | |
2010 | for (Link = DefaultIdArray->Entry.ForwardLink; Link != &DefaultIdArray->Entry; Link = Link->ForwardLink) {\r | |
2011 | DefaultId = BASE_CR (Link, IFR_DEFAULT_DATA, Entry);\r | |
2012 | //\r | |
2013 | // Add length for "&<ConfigHdr>&ALTCFG=XXXX"\r | |
2014 | // |1| StrLen (ConfigHdr) | 8 | 4 |\r | |
2015 | //\r | |
2016 | Length += (1 + StrLen (ConfigHdr) + 8 + 4);\r | |
2017 | \r | |
2018 | for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {\r | |
2019 | BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);\r | |
2020 | for (LinkDefault = BlockData->DefaultValueEntry.ForwardLink; LinkDefault != &BlockData->DefaultValueEntry; LinkDefault = LinkDefault->ForwardLink) {\r | |
2021 | DefaultValueData = BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry);\r | |
2022 | if (DefaultValueData->DefaultId == DefaultId->DefaultId) {\r | |
2023 | //\r | |
2024 | // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"\r | |
2025 | // | 8 | 4 | 7 | 4 | 7 | Width * 2 |\r | |
2026 | //\r | |
2027 | Length += (8 + 4 + 7 + 4 + 7 + BlockData->Width * 2);\r | |
2028 | DataExist = TRUE;\r | |
2029 | }\r | |
2030 | }\r | |
2031 | }\r | |
2032 | }\r | |
2033 | \r | |
2034 | //\r | |
2035 | // No default value is found. The default string doesn't exist.\r | |
2036 | //\r | |
2037 | if (!DataExist) {\r | |
2038 | Status = EFI_SUCCESS;\r | |
2039 | goto Done;\r | |
2040 | }\r | |
2041 | \r | |
2042 | //\r | |
2043 | // Allocate buffer for the entire <DefaultAltCfgResp>\r | |
2044 | //\r | |
2045 | DefaultAltCfgResp = AllocateZeroPool (Length * sizeof (CHAR16));\r | |
2046 | if (DefaultAltCfgResp == NULL) {\r | |
2047 | Status = EFI_OUT_OF_RESOURCES;\r | |
2048 | goto Done;\r | |
2049 | }\r | |
2050 | StringPtr = DefaultAltCfgResp;\r | |
2051 | \r | |
2052 | //\r | |
2053 | // Start with <ConfigHdr>\r | |
2054 | //\r | |
2055 | StrCpy (StringPtr, ConfigHdr);\r | |
2056 | StringPtr += StrLen (StringPtr);\r | |
2057 | \r | |
2058 | for (Link = DefaultIdArray->Entry.ForwardLink; Link != &DefaultIdArray->Entry; Link = Link->ForwardLink) {\r | |
2059 | DefaultId = BASE_CR (Link, IFR_DEFAULT_DATA, Entry);\r | |
2060 | //\r | |
2061 | // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX\0"\r | |
2062 | // |1| StrLen (ConfigHdr) | 8 | 4 |\r | |
2063 | //\r | |
2064 | UnicodeSPrint (\r | |
2065 | StringPtr, \r | |
2066 | (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), \r | |
2067 | L"&%s&ALTCFG=%04X", \r | |
2068 | ConfigHdr, \r | |
2069 | DefaultId->DefaultId\r | |
2070 | );\r | |
2071 | StringPtr += StrLen (StringPtr);\r | |
2072 | \r | |
2073 | for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {\r | |
2074 | BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);\r | |
2075 | for (LinkDefault = BlockData->DefaultValueEntry.ForwardLink; LinkDefault != &BlockData->DefaultValueEntry; LinkDefault = LinkDefault->ForwardLink) {\r | |
2076 | DefaultValueData = BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry);\r | |
2077 | if (DefaultValueData->DefaultId == DefaultId->DefaultId) {\r | |
2078 | //\r | |
2079 | // Add <BlockConfig>\r | |
2080 | // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>\r | |
2081 | //\r | |
2082 | UnicodeSPrint (\r | |
2083 | StringPtr, \r | |
2084 | (8 + 4 + 7 + 4 + 7 + 1) * sizeof (CHAR16),\r | |
2085 | L"&OFFSET=%04X&WIDTH=%04X&VALUE=", \r | |
2086 | BlockData->Offset, \r | |
2087 | BlockData->Width\r | |
2088 | );\r | |
2089 | StringPtr += StrLen (StringPtr);\r | |
2090 | \r | |
2091 | //\r | |
2092 | // Convert Value to a hex string in "%x" format\r | |
2093 | // NOTE: This is in the opposite byte that GUID and PATH use\r | |
2094 | //\r | |
2095 | Width = BlockData->Width;\r | |
2096 | TmpBuffer = (UINT8 *) &(DefaultValueData->Value);\r | |
2097 | for (; Width > 0; Width--) {\r | |
2098 | StringPtr += UnicodeValueToString (StringPtr, PREFIX_ZERO | RADIX_HEX, TmpBuffer[Width - 1], 2);\r | |
2099 | }\r | |
2100 | }\r | |
2101 | }\r | |
2102 | }\r | |
2103 | }\r | |
2104 | HiiToLower (DefaultAltCfgResp);\r | |
2105 | \r | |
2106 | //\r | |
2107 | // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL.\r | |
2108 | //\r | |
2109 | if (*AltCfgResp != NULL && DefaultAltCfgResp != NULL) {\r | |
2110 | Status = MergeDefaultString (AltCfgResp, DefaultAltCfgResp);\r | |
2111 | FreePool (DefaultAltCfgResp);\r | |
2112 | } else if (*AltCfgResp == NULL) {\r | |
2113 | *AltCfgResp = DefaultAltCfgResp;\r | |
2114 | }\r | |
2115 | \r | |
2116 | Done:\r | |
2117 | if (RequestBlockArray != NULL) {\r | |
2118 | //\r | |
2119 | // Free Link Array RequestBlockArray\r | |
2120 | //\r | |
2121 | while (!IsListEmpty (&RequestBlockArray->Entry)) {\r | |
2122 | BlockData = BASE_CR (RequestBlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);\r | |
2123 | RemoveEntryList (&BlockData->Entry);\r | |
2124 | FreePool (BlockData);\r | |
2125 | }\r | |
2126 | \r | |
2127 | FreePool (RequestBlockArray);\r | |
2128 | }\r | |
2129 | \r | |
2130 | if (VarStorageData != NULL) {\r | |
2131 | //\r | |
2132 | // Free link array VarStorageData\r | |
2133 | //\r | |
2134 | while (!IsListEmpty (&VarStorageData->BlockEntry)) {\r | |
2135 | BlockData = BASE_CR (VarStorageData->BlockEntry.ForwardLink, IFR_BLOCK_DATA, Entry);\r | |
2136 | RemoveEntryList (&BlockData->Entry);\r | |
2137 | //\r | |
2138 | // Free default value link array\r | |
2139 | //\r | |
2140 | while (!IsListEmpty (&BlockData->DefaultValueEntry)) {\r | |
2141 | DefaultValueData = BASE_CR (BlockData->DefaultValueEntry.ForwardLink, IFR_DEFAULT_DATA, Entry);\r | |
2142 | RemoveEntryList (&DefaultValueData->Entry);\r | |
2143 | FreePool (DefaultValueData);\r | |
2144 | }\r | |
2145 | FreePool (BlockData);\r | |
2146 | }\r | |
2147 | FreePool (VarStorageData);\r | |
2148 | }\r | |
2149 | \r | |
2150 | if (DefaultIdArray != NULL) {\r | |
2151 | //\r | |
2152 | // Free DefaultId Array\r | |
2153 | //\r | |
2154 | while (!IsListEmpty (&DefaultIdArray->Entry)) {\r | |
2155 | DefaultId = BASE_CR (DefaultIdArray->Entry.ForwardLink, IFR_DEFAULT_DATA, Entry);\r | |
2156 | RemoveEntryList (&DefaultId->Entry);\r | |
2157 | FreePool (DefaultId);\r | |
2158 | }\r | |
2159 | FreePool (DefaultIdArray);\r | |
2160 | }\r | |
2161 | \r | |
2162 | //\r | |
2163 | // Free the allocated string \r | |
2164 | //\r | |
2165 | if (GuidStr != NULL) {\r | |
2166 | FreePool (GuidStr);\r | |
2167 | }\r | |
2168 | if (NameStr != NULL) {\r | |
2169 | FreePool (NameStr);\r | |
2170 | }\r | |
2171 | if (PathStr != NULL) {\r | |
2172 | FreePool (PathStr);\r | |
2173 | }\r | |
2174 | if (ConfigHdr != NULL) {\r | |
2175 | FreePool (ConfigHdr);\r | |
2176 | }\r | |
2177 | \r | |
2178 | //\r | |
2179 | // Free Pacakge data\r | |
2180 | //\r | |
2181 | if (HiiFormPackage != NULL) {\r | |
2182 | FreePool (HiiFormPackage);\r | |
2183 | }\r | |
2184 | \r | |
2185 | if (PointerProgress != NULL) {\r | |
2186 | if (*Request == NULL) {\r | |
2187 | *PointerProgress = NULL;\r | |
2188 | } else if (EFI_ERROR (Status)) {\r | |
2189 | *PointerProgress = Progress;\r | |
2190 | } else {\r | |
2191 | *PointerProgress = *Request + StrLen (*Request);\r | |
2192 | }\r | |
2193 | }\r | |
2194 | \r | |
2195 | return Status;\r | |
2196 | }\r | |
2197 | \r | |
2198 | /**\r | |
2199 | This function allows a caller to extract the current configuration\r | |
2200 | for one or more named elements from one or more drivers.\r | |
2201 | \r | |
2202 | @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r | |
2203 | instance.\r | |
2204 | @param Request A null-terminated Unicode string in\r | |
2205 | <MultiConfigRequest> format.\r | |
2206 | @param Progress On return, points to a character in the Request\r | |
2207 | string. Points to the string's null terminator if\r | |
2208 | request was successful. Points to the most recent\r | |
2209 | & before the first failing name / value pair (or\r | |
2210 | the beginning of the string if the failure is in\r | |
2211 | the first name / value pair) if the request was\r | |
2212 | not successful.\r | |
2213 | @param Results Null-terminated Unicode string in\r | |
2214 | <MultiConfigAltResp> format which has all values\r | |
2215 | filled in for the names in the Request string.\r | |
2216 | String to be allocated by the called function.\r | |
2217 | \r | |
2218 | @retval EFI_SUCCESS The Results string is filled with the values\r | |
2219 | corresponding to all requested names.\r | |
2220 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the\r | |
2221 | results that must be stored awaiting possible\r | |
2222 | future protocols.\r | |
2223 | @retval EFI_NOT_FOUND Routing data doesn't match any known driver.\r | |
2224 | Progress set to the "G" in "GUID" of the routing\r | |
2225 | header that doesn't match. Note: There is no\r | |
2226 | requirement that all routing data be validated\r | |
2227 | before any configuration extraction.\r | |
2228 | @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Request\r | |
2229 | parameter would result in this type of error. The\r | |
2230 | Progress parameter is set to NULL.\r | |
2231 | @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent &\r | |
2232 | before the error or the beginning of the string.\r | |
2233 | @retval EFI_INVALID_PARAMETER Unknown name. Progress points to the & before the\r | |
2234 | name in question.\r | |
2235 | \r | |
2236 | **/\r | |
2237 | EFI_STATUS\r | |
2238 | EFIAPI\r | |
2239 | HiiConfigRoutingExtractConfig (\r | |
2240 | IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r | |
2241 | IN CONST EFI_STRING Request,\r | |
2242 | OUT EFI_STRING *Progress,\r | |
2243 | OUT EFI_STRING *Results\r | |
2244 | )\r | |
2245 | {\r | |
2246 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
2247 | EFI_STRING StringPtr;\r | |
2248 | EFI_STRING ConfigRequest;\r | |
2249 | UINTN Length;\r | |
2250 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
2251 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
2252 | EFI_STATUS Status;\r | |
2253 | LIST_ENTRY *Link;\r | |
2254 | HII_DATABASE_RECORD *Database;\r | |
2255 | UINT8 *DevicePathPkg;\r | |
2256 | UINT8 *CurrentDevicePath;\r | |
2257 | EFI_HANDLE DriverHandle;\r | |
2258 | EFI_HII_HANDLE HiiHandle;\r | |
2259 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
2260 | EFI_STRING AccessProgress;\r | |
2261 | EFI_STRING AccessResults;\r | |
2262 | EFI_STRING DefaultResults;\r | |
2263 | BOOLEAN FirstElement;\r | |
2264 | BOOLEAN IfrDataParsedFlag;\r | |
2265 | \r | |
2266 | if (This == NULL || Progress == NULL || Results == NULL) {\r | |
2267 | return EFI_INVALID_PARAMETER;\r | |
2268 | }\r | |
2269 | \r | |
2270 | if (Request == NULL) {\r | |
2271 | *Progress = NULL;\r | |
2272 | return EFI_INVALID_PARAMETER;\r | |
2273 | }\r | |
2274 | \r | |
2275 | Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
2276 | StringPtr = Request;\r | |
2277 | *Progress = StringPtr;\r | |
2278 | DefaultResults = NULL;\r | |
2279 | ConfigRequest = NULL;\r | |
2280 | Status = EFI_SUCCESS;\r | |
2281 | AccessResults = NULL;\r | |
2282 | DevicePath = NULL;\r | |
2283 | IfrDataParsedFlag = FALSE;\r | |
2284 | \r | |
2285 | //\r | |
2286 | // The first element of <MultiConfigRequest> should be\r | |
2287 | // <GuidHdr>, which is in 'GUID='<Guid> syntax.\r | |
2288 | //\r | |
2289 | if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r | |
2290 | return EFI_INVALID_PARAMETER;\r | |
2291 | }\r | |
2292 | \r | |
2293 | FirstElement = TRUE;\r | |
2294 | \r | |
2295 | //\r | |
2296 | // Allocate a fix length of memory to store Results. Reallocate memory for\r | |
2297 | // Results if this fix length is insufficient.\r | |
2298 | //\r | |
2299 | *Results = (EFI_STRING) AllocateZeroPool (MAX_STRING_LENGTH);\r | |
2300 | if (*Results == NULL) {\r | |
2301 | return EFI_OUT_OF_RESOURCES;\r | |
2302 | }\r | |
2303 | \r | |
2304 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) == 0) {\r | |
2305 | //\r | |
2306 | // If parsing error, set Progress to the beginning of the <MultiConfigRequest>\r | |
2307 | // or most recent & before the error.\r | |
2308 | //\r | |
2309 | if (StringPtr == Request) {\r | |
2310 | *Progress = StringPtr;\r | |
2311 | } else {\r | |
2312 | *Progress = StringPtr - 1;\r | |
2313 | }\r | |
2314 | \r | |
2315 | //\r | |
2316 | // Process each <ConfigRequest> of <MultiConfigRequest>\r | |
2317 | //\r | |
2318 | Length = CalculateConfigStringLen (StringPtr);\r | |
2319 | ConfigRequest = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), StringPtr);\r | |
2320 | if (ConfigRequest == NULL) {\r | |
2321 | Status = EFI_OUT_OF_RESOURCES;\r | |
2322 | goto Done;\r | |
2323 | }\r | |
2324 | *(ConfigRequest + Length) = 0;\r | |
2325 | \r | |
2326 | //\r | |
2327 | // Get the UEFI device path\r | |
2328 | //\r | |
2329 | Status = GetDevicePath (ConfigRequest, (UINT8 **) &DevicePath);\r | |
2330 | if (EFI_ERROR (Status)) {\r | |
2331 | goto Done;\r | |
2332 | }\r | |
2333 | \r | |
2334 | //\r | |
2335 | // Find driver which matches the routing data.\r | |
2336 | //\r | |
2337 | DriverHandle = NULL;\r | |
2338 | HiiHandle = NULL;\r | |
2339 | Database = NULL;\r | |
2340 | for (Link = Private->DatabaseList.ForwardLink;\r | |
2341 | Link != &Private->DatabaseList;\r | |
2342 | Link = Link->ForwardLink\r | |
2343 | ) {\r | |
2344 | Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
2345 | if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r | |
2346 | CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r | |
2347 | if (CompareMem (\r | |
2348 | DevicePath,\r | |
2349 | CurrentDevicePath,\r | |
2350 | GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath)\r | |
2351 | ) == 0) {\r | |
2352 | DriverHandle = Database->DriverHandle;\r | |
2353 | HiiHandle = Database->Handle;\r | |
2354 | break;\r | |
2355 | }\r | |
2356 | }\r | |
2357 | }\r | |
2358 | \r | |
2359 | //\r | |
2360 | // Try to find driver handle by device path.\r | |
2361 | //\r | |
2362 | if (DriverHandle == NULL) {\r | |
2363 | TempDevicePath = DevicePath;\r | |
2364 | Status = gBS->LocateDevicePath (\r | |
2365 | &gEfiDevicePathProtocolGuid,\r | |
2366 | &TempDevicePath,\r | |
2367 | &DriverHandle\r | |
2368 | );\r | |
2369 | if (EFI_ERROR (Status) || (DriverHandle == NULL)) {\r | |
2370 | //\r | |
2371 | // Routing data does not match any known driver.\r | |
2372 | // Set Progress to the 'G' in "GUID" of the routing header.\r | |
2373 | //\r | |
2374 | *Progress = StringPtr;\r | |
2375 | Status = EFI_NOT_FOUND;\r | |
2376 | goto Done;\r | |
2377 | }\r | |
2378 | }\r | |
2379 | \r | |
2380 | //\r | |
2381 | // Check whether ConfigRequest contains request string OFFSET/WIDTH\r | |
2382 | //\r | |
2383 | IfrDataParsedFlag = FALSE;\r | |
2384 | if ((HiiHandle != NULL) && (StrStr (ConfigRequest, L"&OFFSET=") == NULL)) {\r | |
2385 | //\r | |
2386 | // Get the full request string from IFR when HiiPackage is registered to HiiHandle \r | |
2387 | //\r | |
2388 | IfrDataParsedFlag = TRUE;\r | |
2389 | Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, &AccessProgress);\r | |
2390 | if (EFI_ERROR (Status)) {\r | |
2391 | //\r | |
2392 | // AccessProgress indicates the parsing progress on <ConfigRequest>.\r | |
2393 | // Map it to the progress on <MultiConfigRequest> then return it.\r | |
2394 | //\r | |
2395 | *Progress = StrStr (StringPtr, AccessProgress);\r | |
2396 | goto Done;\r | |
2397 | }\r | |
2398 | //\r | |
2399 | // Not any request block is found.\r | |
2400 | //\r | |
2401 | if (StrStr (ConfigRequest, L"&OFFSET=") == NULL) {\r | |
2402 | AccessResults = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest);\r | |
2403 | goto NextConfigString;\r | |
2404 | }\r | |
2405 | }\r | |
2406 | \r | |
2407 | //\r | |
2408 | // Call corresponding ConfigAccess protocol to extract settings\r | |
2409 | //\r | |
2410 | Status = gBS->HandleProtocol (\r | |
2411 | DriverHandle,\r | |
2412 | &gEfiHiiConfigAccessProtocolGuid,\r | |
2413 | (VOID **) &ConfigAccess\r | |
2414 | );\r | |
2415 | ASSERT_EFI_ERROR (Status);\r | |
2416 | \r | |
2417 | Status = ConfigAccess->ExtractConfig (\r | |
2418 | ConfigAccess,\r | |
2419 | ConfigRequest,\r | |
2420 | &AccessProgress,\r | |
2421 | &AccessResults\r | |
2422 | );\r | |
2423 | if (EFI_ERROR (Status)) {\r | |
2424 | //\r | |
2425 | // AccessProgress indicates the parsing progress on <ConfigRequest>.\r | |
2426 | // Map it to the progress on <MultiConfigRequest> then return it.\r | |
2427 | //\r | |
2428 | *Progress = StrStr (StringPtr, AccessProgress);\r | |
2429 | goto Done;\r | |
2430 | }\r | |
2431 | \r | |
2432 | //\r | |
2433 | // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'\r | |
2434 | // which seperates the first <ConfigAltResp> and the following ones.\r | |
2435 | //\r | |
2436 | ASSERT (*AccessProgress == 0);\r | |
2437 | \r | |
2438 | //\r | |
2439 | // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle \r | |
2440 | //\r | |
2441 | if (!IfrDataParsedFlag && HiiHandle != NULL) {\r | |
2442 | Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, NULL);\r | |
2443 | ASSERT_EFI_ERROR (Status);\r | |
2444 | }\r | |
2445 | \r | |
2446 | FreePool (DevicePath);\r | |
2447 | DevicePath = NULL;\r | |
2448 | \r | |
2449 | if (DefaultResults != NULL) {\r | |
2450 | Status = MergeDefaultString (&AccessResults, DefaultResults);\r | |
2451 | ASSERT_EFI_ERROR (Status);\r | |
2452 | FreePool (DefaultResults);\r | |
2453 | DefaultResults = NULL;\r | |
2454 | }\r | |
2455 | \r | |
2456 | NextConfigString: \r | |
2457 | if (!FirstElement) {\r | |
2458 | Status = AppendToMultiString (Results, L"&");\r | |
2459 | ASSERT_EFI_ERROR (Status);\r | |
2460 | }\r | |
2461 | \r | |
2462 | Status = AppendToMultiString (Results, AccessResults);\r | |
2463 | ASSERT_EFI_ERROR (Status);\r | |
2464 | \r | |
2465 | FirstElement = FALSE;\r | |
2466 | \r | |
2467 | FreePool (AccessResults);\r | |
2468 | AccessResults = NULL;\r | |
2469 | FreePool (ConfigRequest);\r | |
2470 | ConfigRequest = NULL;\r | |
2471 | \r | |
2472 | //\r | |
2473 | // Go to next <ConfigRequest> (skip '&').\r | |
2474 | //\r | |
2475 | StringPtr += Length;\r | |
2476 | if (*StringPtr == 0) {\r | |
2477 | *Progress = StringPtr;\r | |
2478 | break;\r | |
2479 | }\r | |
2480 | \r | |
2481 | StringPtr++;\r | |
2482 | }\r | |
2483 | \r | |
2484 | Done:\r | |
2485 | if (EFI_ERROR (Status)) {\r | |
2486 | FreePool (*Results);\r | |
2487 | *Results = NULL;\r | |
2488 | }\r | |
2489 | \r | |
2490 | if (ConfigRequest != NULL) {\r | |
2491 | FreePool (ConfigRequest);\r | |
2492 | }\r | |
2493 | \r | |
2494 | if (AccessResults != NULL) {\r | |
2495 | FreePool (AccessResults);\r | |
2496 | }\r | |
2497 | \r | |
2498 | if (DefaultResults != NULL) {\r | |
2499 | FreePool (DefaultResults);\r | |
2500 | }\r | |
2501 | \r | |
2502 | if (DevicePath != NULL) {\r | |
2503 | FreePool (DevicePath);\r | |
2504 | } \r | |
2505 | \r | |
2506 | return Status;\r | |
2507 | }\r | |
2508 | \r | |
2509 | \r | |
2510 | /**\r | |
2511 | This function allows the caller to request the current configuration for the\r | |
2512 | entirety of the current HII database and returns the data in a\r | |
2513 | null-terminated Unicode string.\r | |
2514 | \r | |
2515 | @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r | |
2516 | instance.\r | |
2517 | @param Results Null-terminated Unicode string in\r | |
2518 | <MultiConfigAltResp> format which has all values\r | |
2519 | filled in for the names in the Request string.\r | |
2520 | String to be allocated by the called function.\r | |
2521 | De-allocation is up to the caller.\r | |
2522 | \r | |
2523 | @retval EFI_SUCCESS The Results string is filled with the values\r | |
2524 | corresponding to all requested names.\r | |
2525 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the\r | |
2526 | results that must be stored awaiting possible\r | |
2527 | future protocols.\r | |
2528 | @retval EFI_INVALID_PARAMETER For example, passing in a NULL for the Results\r | |
2529 | parameter would result in this type of error.\r | |
2530 | \r | |
2531 | **/\r | |
2532 | EFI_STATUS\r | |
2533 | EFIAPI\r | |
2534 | HiiConfigRoutingExportConfig (\r | |
2535 | IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r | |
2536 | OUT EFI_STRING *Results\r | |
2537 | )\r | |
2538 | {\r | |
2539 | EFI_STATUS Status;\r | |
2540 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
2541 | EFI_STRING AccessResults;\r | |
2542 | EFI_STRING Progress;\r | |
2543 | EFI_STRING StringPtr;\r | |
2544 | EFI_STRING ConfigRequest;\r | |
2545 | UINTN Index;\r | |
2546 | EFI_HANDLE *ConfigAccessHandles;\r | |
2547 | UINTN NumberConfigAccessHandles;\r | |
2548 | BOOLEAN FirstElement;\r | |
2549 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
2550 | EFI_HII_HANDLE HiiHandle;\r | |
2551 | EFI_STRING DefaultResults;\r | |
2552 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
2553 | LIST_ENTRY *Link;\r | |
2554 | HII_DATABASE_RECORD *Database;\r | |
2555 | UINT8 *DevicePathPkg;\r | |
2556 | UINT8 *CurrentDevicePath;\r | |
2557 | BOOLEAN IfrDataParsedFlag;\r | |
2558 | \r | |
2559 | if (This == NULL || Results == NULL) {\r | |
2560 | return EFI_INVALID_PARAMETER;\r | |
2561 | }\r | |
2562 | \r | |
2563 | Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
2564 | \r | |
2565 | //\r | |
2566 | // Allocate a fix length of memory to store Results. Reallocate memory for\r | |
2567 | // Results if this fix length is insufficient.\r | |
2568 | //\r | |
2569 | *Results = (EFI_STRING) AllocateZeroPool (MAX_STRING_LENGTH);\r | |
2570 | if (*Results == NULL) {\r | |
2571 | return EFI_OUT_OF_RESOURCES;\r | |
2572 | }\r | |
2573 | \r | |
2574 | NumberConfigAccessHandles = 0;\r | |
2575 | Status = gBS->LocateHandleBuffer (\r | |
2576 | ByProtocol,\r | |
2577 | &gEfiHiiConfigAccessProtocolGuid,\r | |
2578 | NULL,\r | |
2579 | &NumberConfigAccessHandles,\r | |
2580 | &ConfigAccessHandles\r | |
2581 | );\r | |
2582 | if (EFI_ERROR (Status)) {\r | |
2583 | return Status;\r | |
2584 | }\r | |
2585 | \r | |
2586 | FirstElement = TRUE;\r | |
2587 | \r | |
2588 | for (Index = 0; Index < NumberConfigAccessHandles; Index++) {\r | |
2589 | Status = gBS->HandleProtocol (\r | |
2590 | ConfigAccessHandles[Index],\r | |
2591 | &gEfiHiiConfigAccessProtocolGuid,\r | |
2592 | (VOID **) &ConfigAccess\r | |
2593 | );\r | |
2594 | if (EFI_ERROR (Status)) {\r | |
2595 | continue;\r | |
2596 | }\r | |
2597 | \r | |
2598 | //\r | |
2599 | // Get DevicePath and HiiHandle for this ConfigAccess driver handle\r | |
2600 | //\r | |
2601 | IfrDataParsedFlag = FALSE;\r | |
2602 | Progress = NULL;\r | |
2603 | HiiHandle = NULL;\r | |
2604 | DefaultResults = NULL;\r | |
2605 | Database = NULL;\r | |
2606 | ConfigRequest = NULL;\r | |
2607 | DevicePath = DevicePathFromHandle (ConfigAccessHandles[Index]);\r | |
2608 | if (DevicePath != NULL) {\r | |
2609 | for (Link = Private->DatabaseList.ForwardLink;\r | |
2610 | Link != &Private->DatabaseList;\r | |
2611 | Link = Link->ForwardLink\r | |
2612 | ) {\r | |
2613 | Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
2614 | if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r | |
2615 | CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r | |
2616 | if (CompareMem (\r | |
2617 | DevicePath,\r | |
2618 | CurrentDevicePath,\r | |
2619 | GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath)\r | |
2620 | ) == 0) {\r | |
2621 | HiiHandle = Database->Handle;\r | |
2622 | break;\r | |
2623 | }\r | |
2624 | }\r | |
2625 | }\r | |
2626 | }\r | |
2627 | \r | |
2628 | Status = ConfigAccess->ExtractConfig (\r | |
2629 | ConfigAccess,\r | |
2630 | NULL,\r | |
2631 | &Progress,\r | |
2632 | &AccessResults\r | |
2633 | );\r | |
2634 | if (EFI_ERROR (Status)) {\r | |
2635 | //\r | |
2636 | // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle \r | |
2637 | //\r | |
2638 | if (HiiHandle != NULL && DevicePath != NULL) {\r | |
2639 | IfrDataParsedFlag = TRUE;\r | |
2640 | Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults, NULL);\r | |
2641 | //\r | |
2642 | // Get the full request string to get the Current setting again.\r | |
2643 | //\r | |
2644 | if (!EFI_ERROR (Status) && ConfigRequest != NULL) {\r | |
2645 | Status = ConfigAccess->ExtractConfig (\r | |
2646 | ConfigAccess,\r | |
2647 | ConfigRequest,\r | |
2648 | &Progress,\r | |
2649 | &AccessResults\r | |
2650 | );\r | |
2651 | FreePool (ConfigRequest);\r | |
2652 | } else {\r | |
2653 | Status = EFI_NOT_FOUND;\r | |
2654 | }\r | |
2655 | }\r | |
2656 | }\r | |
2657 | \r | |
2658 | if (!EFI_ERROR (Status)) {\r | |
2659 | //\r | |
2660 | // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle \r | |
2661 | //\r | |
2662 | if (!IfrDataParsedFlag && HiiHandle != NULL && DevicePath != NULL) {\r | |
2663 | StringPtr = StrStr (AccessResults, L"&GUID=");\r | |
2664 | if (StringPtr != NULL) {\r | |
2665 | *StringPtr = 0;\r | |
2666 | }\r | |
2667 | if (StrStr (AccessResults, L"&OFFSET=") != NULL) {\r | |
2668 | Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &AccessResults, &DefaultResults, NULL);\r | |
2669 | ASSERT_EFI_ERROR (Status);\r | |
2670 | }\r | |
2671 | if (StringPtr != NULL) {\r | |
2672 | *StringPtr = L'&';\r | |
2673 | }\r | |
2674 | }\r | |
2675 | //\r | |
2676 | // Merge the default sting from IFR code into the got setting from driver.\r | |
2677 | //\r | |
2678 | if (DefaultResults != NULL) {\r | |
2679 | Status = MergeDefaultString (&AccessResults, DefaultResults);\r | |
2680 | ASSERT_EFI_ERROR (Status);\r | |
2681 | FreePool (DefaultResults);\r | |
2682 | DefaultResults = NULL;\r | |
2683 | }\r | |
2684 | \r | |
2685 | //\r | |
2686 | // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'\r | |
2687 | // which seperates the first <ConfigAltResp> and the following ones. \r | |
2688 | //\r | |
2689 | if (!FirstElement) {\r | |
2690 | Status = AppendToMultiString (Results, L"&");\r | |
2691 | ASSERT_EFI_ERROR (Status);\r | |
2692 | }\r | |
2693 | \r | |
2694 | Status = AppendToMultiString (Results, AccessResults);\r | |
2695 | ASSERT_EFI_ERROR (Status);\r | |
2696 | \r | |
2697 | FirstElement = FALSE;\r | |
2698 | \r | |
2699 | FreePool (AccessResults);\r | |
2700 | AccessResults = NULL;\r | |
2701 | }\r | |
2702 | }\r | |
2703 | FreePool (ConfigAccessHandles);\r | |
2704 | \r | |
2705 | return EFI_SUCCESS; \r | |
2706 | }\r | |
2707 | \r | |
2708 | \r | |
2709 | /**\r | |
2710 | This function processes the results of processing forms and routes it to the\r | |
2711 | appropriate handlers or storage.\r | |
2712 | \r | |
2713 | @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r | |
2714 | instance.\r | |
2715 | @param Configuration A null-terminated Unicode string in\r | |
2716 | <MulltiConfigResp> format.\r | |
2717 | @param Progress A pointer to a string filled in with the offset of\r | |
2718 | the most recent & before the first failing name /\r | |
2719 | value pair (or the beginning of the string if the\r | |
2720 | failure is in the first name / value pair) or the\r | |
2721 | terminating NULL if all was successful.\r | |
2722 | \r | |
2723 | @retval EFI_SUCCESS The results have been distributed or are awaiting\r | |
2724 | distribution.\r | |
2725 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the\r | |
2726 | results that must be stored awaiting possible\r | |
2727 | future protocols.\r | |
2728 | @retval EFI_INVALID_PARAMETER Passing in a NULL for the Configuration parameter\r | |
2729 | would result in this type of error.\r | |
2730 | @retval EFI_NOT_FOUND Target for the specified routing data was not\r | |
2731 | found.\r | |
2732 | \r | |
2733 | **/\r | |
2734 | EFI_STATUS\r | |
2735 | EFIAPI\r | |
2736 | HiiConfigRoutingRouteConfig (\r | |
2737 | IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r | |
2738 | IN CONST EFI_STRING Configuration,\r | |
2739 | OUT EFI_STRING *Progress\r | |
2740 | )\r | |
2741 | {\r | |
2742 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
2743 | EFI_STRING StringPtr;\r | |
2744 | EFI_STRING ConfigResp;\r | |
2745 | UINTN Length;\r | |
2746 | EFI_STATUS Status;\r | |
2747 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
2748 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
2749 | LIST_ENTRY *Link;\r | |
2750 | HII_DATABASE_RECORD *Database;\r | |
2751 | UINT8 *DevicePathPkg;\r | |
2752 | UINT8 *CurrentDevicePath;\r | |
2753 | EFI_HANDLE DriverHandle;\r | |
2754 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
2755 | EFI_STRING AccessProgress;\r | |
2756 | \r | |
2757 | if (This == NULL || Progress == NULL) {\r | |
2758 | return EFI_INVALID_PARAMETER;\r | |
2759 | }\r | |
2760 | \r | |
2761 | if (Configuration == NULL) {\r | |
2762 | *Progress = NULL;\r | |
2763 | return EFI_INVALID_PARAMETER;\r | |
2764 | }\r | |
2765 | \r | |
2766 | Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
2767 | StringPtr = Configuration;\r | |
2768 | *Progress = StringPtr;\r | |
2769 | \r | |
2770 | //\r | |
2771 | // The first element of <MultiConfigResp> should be\r | |
2772 | // <GuidHdr>, which is in 'GUID='<Guid> syntax.\r | |
2773 | //\r | |
2774 | if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r | |
2775 | return EFI_INVALID_PARAMETER;\r | |
2776 | }\r | |
2777 | \r | |
2778 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) == 0) {\r | |
2779 | //\r | |
2780 | // If parsing error, set Progress to the beginning of the <MultiConfigResp>\r | |
2781 | // or most recent & before the error.\r | |
2782 | //\r | |
2783 | if (StringPtr == Configuration) {\r | |
2784 | *Progress = StringPtr;\r | |
2785 | } else {\r | |
2786 | *Progress = StringPtr - 1;\r | |
2787 | }\r | |
2788 | \r | |
2789 | //\r | |
2790 | // Process each <ConfigResp> of <MultiConfigResp>\r | |
2791 | //\r | |
2792 | Length = CalculateConfigStringLen (StringPtr);\r | |
2793 | ConfigResp = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), StringPtr);\r | |
2794 | if (ConfigResp == NULL) {\r | |
2795 | return EFI_OUT_OF_RESOURCES;\r | |
2796 | }\r | |
2797 | //\r | |
2798 | // Append '\0' to the end of ConfigRequest\r | |
2799 | //\r | |
2800 | *(ConfigResp + Length) = 0;\r | |
2801 | \r | |
2802 | //\r | |
2803 | // Get the UEFI device path\r | |
2804 | //\r | |
2805 | Status = GetDevicePath (ConfigResp, (UINT8 **) &DevicePath);\r | |
2806 | if (EFI_ERROR (Status)) {\r | |
2807 | FreePool (ConfigResp);\r | |
2808 | return Status;\r | |
2809 | }\r | |
2810 | \r | |
2811 | //\r | |
2812 | // Find driver which matches the routing data.\r | |
2813 | //\r | |
2814 | DriverHandle = NULL;\r | |
2815 | for (Link = Private->DatabaseList.ForwardLink;\r | |
2816 | Link != &Private->DatabaseList;\r | |
2817 | Link = Link->ForwardLink\r | |
2818 | ) {\r | |
2819 | Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
2820 | \r | |
2821 | if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r | |
2822 | CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r | |
2823 | if (CompareMem (\r | |
2824 | DevicePath,\r | |
2825 | CurrentDevicePath,\r | |
2826 | GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath)\r | |
2827 | ) == 0) {\r | |
2828 | DriverHandle = Database->DriverHandle;\r | |
2829 | break;\r | |
2830 | }\r | |
2831 | }\r | |
2832 | }\r | |
2833 | \r | |
2834 | //\r | |
2835 | // Try to find driver handle by device path.\r | |
2836 | //\r | |
2837 | if (DriverHandle == NULL) {\r | |
2838 | TempDevicePath = DevicePath;\r | |
2839 | Status = gBS->LocateDevicePath (\r | |
2840 | &gEfiDevicePathProtocolGuid,\r | |
2841 | &TempDevicePath,\r | |
2842 | &DriverHandle\r | |
2843 | );\r | |
2844 | if (EFI_ERROR (Status) || (DriverHandle == NULL)) {\r | |
2845 | //\r | |
2846 | // Routing data does not match any known driver.\r | |
2847 | // Set Progress to the 'G' in "GUID" of the routing header.\r | |
2848 | //\r | |
2849 | FreePool (DevicePath);\r | |
2850 | *Progress = StringPtr;\r | |
2851 | FreePool (ConfigResp);\r | |
2852 | return EFI_NOT_FOUND;\r | |
2853 | }\r | |
2854 | }\r | |
2855 | \r | |
2856 | FreePool (DevicePath);\r | |
2857 | \r | |
2858 | //\r | |
2859 | // Call corresponding ConfigAccess protocol to route settings\r | |
2860 | //\r | |
2861 | Status = gBS->HandleProtocol (\r | |
2862 | DriverHandle,\r | |
2863 | &gEfiHiiConfigAccessProtocolGuid,\r | |
2864 | (VOID **) &ConfigAccess\r | |
2865 | );\r | |
2866 | ASSERT_EFI_ERROR (Status);\r | |
2867 | \r | |
2868 | Status = ConfigAccess->RouteConfig (\r | |
2869 | ConfigAccess,\r | |
2870 | ConfigResp,\r | |
2871 | &AccessProgress\r | |
2872 | );\r | |
2873 | \r | |
2874 | if (EFI_ERROR (Status)) {\r | |
2875 | //\r | |
2876 | // AccessProgress indicates the parsing progress on <ConfigResp>.\r | |
2877 | // Map it to the progress on <MultiConfigResp> then return it.\r | |
2878 | //\r | |
2879 | *Progress = StrStr (StringPtr, AccessProgress);\r | |
2880 | \r | |
2881 | FreePool (ConfigResp);\r | |
2882 | return Status;\r | |
2883 | }\r | |
2884 | \r | |
2885 | FreePool (ConfigResp);\r | |
2886 | ConfigResp = NULL;\r | |
2887 | \r | |
2888 | //\r | |
2889 | // Go to next <ConfigResp> (skip '&').\r | |
2890 | //\r | |
2891 | StringPtr += Length;\r | |
2892 | if (*StringPtr == 0) {\r | |
2893 | *Progress = StringPtr;\r | |
2894 | break;\r | |
2895 | }\r | |
2896 | \r | |
2897 | StringPtr++;\r | |
2898 | \r | |
2899 | }\r | |
2900 | \r | |
2901 | return EFI_SUCCESS;\r | |
2902 | }\r | |
2903 | \r | |
2904 | \r | |
2905 | /**\r | |
2906 | This helper function is to be called by drivers to map configuration data\r | |
2907 | stored in byte array ("block") formats such as UEFI Variables into current\r | |
2908 | configuration strings.\r | |
2909 | \r | |
2910 | @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r | |
2911 | instance.\r | |
2912 | @param ConfigRequest A null-terminated Unicode string in\r | |
2913 | <ConfigRequest> format.\r | |
2914 | @param Block Array of bytes defining the block's configuration.\r | |
2915 | @param BlockSize Length in bytes of Block.\r | |
2916 | @param Config Filled-in configuration string. String allocated\r | |
2917 | by the function. Returned only if call is\r | |
2918 | successful. It is <ConfigResp> string format.\r | |
2919 | @param Progress A pointer to a string filled in with the offset of\r | |
2920 | the most recent & before the first failing\r | |
2921 | name/value pair (or the beginning of the string if\r | |
2922 | the failure is in the first name / value pair) or\r | |
2923 | the terminating NULL if all was successful.\r | |
2924 | \r | |
2925 | @retval EFI_SUCCESS The request succeeded. Progress points to the null\r | |
2926 | terminator at the end of the ConfigRequest\r | |
2927 | string.\r | |
2928 | @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress\r | |
2929 | points to the first character of ConfigRequest.\r | |
2930 | @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigRequest or\r | |
2931 | Block parameter would result in this type of\r | |
2932 | error. Progress points to the first character of\r | |
2933 | ConfigRequest.\r | |
2934 | @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.\r | |
2935 | @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted string.\r | |
2936 | Block is left updated and Progress points at\r | |
2937 | the "&" preceding the first non-<BlockName>.\r | |
2938 | \r | |
2939 | **/\r | |
2940 | EFI_STATUS\r | |
2941 | EFIAPI\r | |
2942 | HiiBlockToConfig (\r | |
2943 | IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r | |
2944 | IN CONST EFI_STRING ConfigRequest,\r | |
2945 | IN CONST UINT8 *Block,\r | |
2946 | IN CONST UINTN BlockSize,\r | |
2947 | OUT EFI_STRING *Config,\r | |
2948 | OUT EFI_STRING *Progress\r | |
2949 | )\r | |
2950 | {\r | |
2951 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
2952 | EFI_STRING StringPtr;\r | |
2953 | UINTN Length;\r | |
2954 | EFI_STATUS Status;\r | |
2955 | EFI_STRING TmpPtr;\r | |
2956 | UINT8 *TmpBuffer;\r | |
2957 | UINTN Offset;\r | |
2958 | UINTN Width;\r | |
2959 | UINT8 *Value;\r | |
2960 | EFI_STRING ValueStr;\r | |
2961 | EFI_STRING ConfigElement;\r | |
2962 | UINTN Index;\r | |
2963 | UINT8 *TemBuffer;\r | |
2964 | CHAR16 *TemString;\r | |
2965 | \r | |
2966 | if (This == NULL || Progress == NULL || Config == NULL) {\r | |
2967 | return EFI_INVALID_PARAMETER;\r | |
2968 | }\r | |
2969 | \r | |
2970 | if (Block == NULL || ConfigRequest == NULL) {\r | |
2971 | *Progress = ConfigRequest;\r | |
2972 | return EFI_INVALID_PARAMETER;\r | |
2973 | }\r | |
2974 | \r | |
2975 | \r | |
2976 | Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
2977 | ASSERT (Private != NULL);\r | |
2978 | \r | |
2979 | StringPtr = ConfigRequest;\r | |
2980 | ValueStr = NULL;\r | |
2981 | Value = NULL;\r | |
2982 | ConfigElement = NULL;\r | |
2983 | \r | |
2984 | //\r | |
2985 | // Allocate a fix length of memory to store Results. Reallocate memory for\r | |
2986 | // Results if this fix length is insufficient.\r | |
2987 | //\r | |
2988 | *Config = (EFI_STRING) AllocateZeroPool (MAX_STRING_LENGTH);\r | |
2989 | if (*Config == NULL) {\r | |
2990 | return EFI_OUT_OF_RESOURCES;\r | |
2991 | }\r | |
2992 | \r | |
2993 | //\r | |
2994 | // Jump <ConfigHdr>\r | |
2995 | //\r | |
2996 | if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r | |
2997 | *Progress = StringPtr;\r | |
2998 | Status = EFI_INVALID_PARAMETER;\r | |
2999 | goto Exit;\r | |
3000 | }\r | |
3001 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"PATH=", StrLen (L"PATH=")) != 0) {\r | |
3002 | StringPtr++;\r | |
3003 | }\r | |
3004 | if (*StringPtr == 0) {\r | |
3005 | *Progress = StringPtr - 1;\r | |
3006 | Status = EFI_INVALID_PARAMETER;\r | |
3007 | goto Exit;\r | |
3008 | }\r | |
3009 | \r | |
3010 | while (*StringPtr != L'&' && *StringPtr != 0) {\r | |
3011 | StringPtr++;\r | |
3012 | }\r | |
3013 | if (*StringPtr == 0) {\r | |
3014 | *Progress = StringPtr - 1;\r | |
3015 | Status = EFI_INVALID_PARAMETER;\r | |
3016 | goto Exit;\r | |
3017 | }\r | |
3018 | //\r | |
3019 | // Skip '&'\r | |
3020 | //\r | |
3021 | StringPtr++;\r | |
3022 | \r | |
3023 | //\r | |
3024 | // Copy <ConfigHdr> and an additional '&' to <ConfigResp>\r | |
3025 | //\r | |
3026 | Length = StringPtr - ConfigRequest;\r | |
3027 | CopyMem (*Config, ConfigRequest, Length * sizeof (CHAR16));\r | |
3028 | \r | |
3029 | //\r | |
3030 | // Parse each <RequestElement> if exists\r | |
3031 | // Only <BlockName> format is supported by this help function.\r | |
3032 | // <BlockName> ::= 'OFFSET='<Number>&'WIDTH='<Number>\r | |
3033 | //\r | |
3034 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {\r | |
3035 | //\r | |
3036 | // Back up the header of one <BlockName>\r | |
3037 | //\r | |
3038 | TmpPtr = StringPtr;\r | |
3039 | \r | |
3040 | StringPtr += StrLen (L"OFFSET=");\r | |
3041 | //\r | |
3042 | // Get Offset\r | |
3043 | //\r | |
3044 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r | |
3045 | if (EFI_ERROR (Status)) {\r | |
3046 | *Progress = ConfigRequest;\r | |
3047 | goto Exit;\r | |
3048 | }\r | |
3049 | Offset = 0;\r | |
3050 | CopyMem (\r | |
3051 | &Offset,\r | |
3052 | TmpBuffer,\r | |
3053 | (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r | |
3054 | );\r | |
3055 | FreePool (TmpBuffer);\r | |
3056 | \r | |
3057 | StringPtr += Length;\r | |
3058 | if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r | |
3059 | *Progress = StringPtr - Length - StrLen (L"OFFSET=") - 1;\r | |
3060 | Status = EFI_INVALID_PARAMETER;\r | |
3061 | goto Exit;\r | |
3062 | }\r | |
3063 | StringPtr += StrLen (L"&WIDTH=");\r | |
3064 | \r | |
3065 | //\r | |
3066 | // Get Width\r | |
3067 | //\r | |
3068 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r | |
3069 | if (EFI_ERROR (Status)) {\r | |
3070 | *Progress = ConfigRequest;\r | |
3071 | goto Exit;\r | |
3072 | }\r | |
3073 | Width = 0;\r | |
3074 | CopyMem (\r | |
3075 | &Width,\r | |
3076 | TmpBuffer,\r | |
3077 | (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r | |
3078 | );\r | |
3079 | FreePool (TmpBuffer);\r | |
3080 | \r | |
3081 | StringPtr += Length;\r | |
3082 | if (*StringPtr != 0 && *StringPtr != L'&') {\r | |
3083 | *Progress = StringPtr - Length - StrLen (L"&WIDTH=");\r | |
3084 | Status = EFI_INVALID_PARAMETER;\r | |
3085 | goto Exit;\r | |
3086 | }\r | |
3087 | \r | |
3088 | //\r | |
3089 | // Calculate Value and convert it to hex string.\r | |
3090 | //\r | |
3091 | if (Offset + Width > BlockSize) {\r | |
3092 | *Progress = StringPtr;\r | |
3093 | Status = EFI_DEVICE_ERROR;\r | |
3094 | goto Exit;\r | |
3095 | }\r | |
3096 | \r | |
3097 | Value = (UINT8 *) AllocateZeroPool (Width);\r | |
3098 | if (Value == NULL) {\r | |
3099 | *Progress = ConfigRequest;\r | |
3100 | Status = EFI_OUT_OF_RESOURCES;\r | |
3101 | goto Exit;\r | |
3102 | }\r | |
3103 | \r | |
3104 | CopyMem (Value, (UINT8 *) Block + Offset, Width);\r | |
3105 | \r | |
3106 | Length = Width * 2 + 1;\r | |
3107 | ValueStr = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));\r | |
3108 | if (ValueStr == NULL) {\r | |
3109 | *Progress = ConfigRequest;\r | |
3110 | Status = EFI_OUT_OF_RESOURCES;\r | |
3111 | goto Exit;\r | |
3112 | }\r | |
3113 | \r | |
3114 | TemString = ValueStr;\r | |
3115 | TemBuffer = Value + Width - 1;\r | |
3116 | for (Index = 0; Index < Width; Index ++, TemBuffer --) {\r | |
3117 | TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r | |
3118 | }\r | |
3119 | \r | |
3120 | FreePool (Value);\r | |
3121 | Value = NULL;\r | |
3122 | \r | |
3123 | //\r | |
3124 | // Build a ConfigElement\r | |
3125 | //\r | |
3126 | Length += StringPtr - TmpPtr + 1 + StrLen (L"VALUE=");\r | |
3127 | ConfigElement = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));\r | |
3128 | if (ConfigElement == NULL) {\r | |
3129 | Status = EFI_OUT_OF_RESOURCES;\r | |
3130 | goto Exit;\r | |
3131 | }\r | |
3132 | CopyMem (ConfigElement, TmpPtr, (StringPtr - TmpPtr + 1) * sizeof (CHAR16));\r | |
3133 | if (*StringPtr == 0) {\r | |
3134 | *(ConfigElement + (StringPtr - TmpPtr)) = L'&';\r | |
3135 | }\r | |
3136 | *(ConfigElement + (StringPtr - TmpPtr) + 1) = 0;\r | |
3137 | StrCat (ConfigElement, L"VALUE=");\r | |
3138 | StrCat (ConfigElement, ValueStr);\r | |
3139 | \r | |
3140 | AppendToMultiString (Config, ConfigElement);\r | |
3141 | \r | |
3142 | FreePool (ConfigElement);\r | |
3143 | FreePool (ValueStr);\r | |
3144 | ConfigElement = NULL;\r | |
3145 | ValueStr = NULL;\r | |
3146 | \r | |
3147 | //\r | |
3148 | // If '\0', parsing is finished. Otherwise skip '&' to continue\r | |
3149 | //\r | |
3150 | if (*StringPtr == 0) {\r | |
3151 | break;\r | |
3152 | }\r | |
3153 | AppendToMultiString (Config, L"&");\r | |
3154 | StringPtr++;\r | |
3155 | \r | |
3156 | }\r | |
3157 | \r | |
3158 | if (*StringPtr != 0) {\r | |
3159 | *Progress = StringPtr - 1;\r | |
3160 | Status = EFI_INVALID_PARAMETER;\r | |
3161 | goto Exit;\r | |
3162 | }\r | |
3163 | \r | |
3164 | HiiToLower (*Config);\r | |
3165 | *Progress = StringPtr;\r | |
3166 | return EFI_SUCCESS;\r | |
3167 | \r | |
3168 | Exit:\r | |
3169 | if (*Config != NULL) {\r | |
3170 | FreePool (*Config);\r | |
3171 | *Config = NULL;\r | |
3172 | }\r | |
3173 | if (ValueStr != NULL) {\r | |
3174 | FreePool (ValueStr);\r | |
3175 | }\r | |
3176 | if (Value != NULL) {\r | |
3177 | FreePool (Value);\r | |
3178 | }\r | |
3179 | if (ConfigElement != NULL) {\r | |
3180 | FreePool (ConfigElement);\r | |
3181 | }\r | |
3182 | \r | |
3183 | return Status;\r | |
3184 | \r | |
3185 | }\r | |
3186 | \r | |
3187 | \r | |
3188 | /**\r | |
3189 | This helper function is to be called by drivers to map configuration strings\r | |
3190 | to configurations stored in byte array ("block") formats such as UEFI Variables.\r | |
3191 | \r | |
3192 | @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r | |
3193 | instance.\r | |
3194 | @param ConfigResp A null-terminated Unicode string in <ConfigResp>\r | |
3195 | format.\r | |
3196 | @param Block A possibly null array of bytes representing the\r | |
3197 | current block. Only bytes referenced in the\r | |
3198 | ConfigResp string in the block are modified. If\r | |
3199 | this parameter is null or if the *BlockSize\r | |
3200 | parameter is (on input) shorter than required by\r | |
3201 | the Configuration string, only the BlockSize\r | |
3202 | parameter is updated and an appropriate status\r | |
3203 | (see below) is returned.\r | |
3204 | @param BlockSize The length of the Block in units of UINT8. On\r | |
3205 | input, this is the size of the Block. On output,\r | |
3206 | if successful, contains the index of the last\r | |
3207 | modified byte in the Block.\r | |
3208 | @param Progress On return, points to an element of the ConfigResp\r | |
3209 | string filled in with the offset of the most\r | |
3210 | recent '&' before the first failing name / value\r | |
3211 | pair (or the beginning of the string if the\r | |
3212 | failure is in the first name / value pair) or the\r | |
3213 | terminating NULL if all was successful.\r | |
3214 | \r | |
3215 | @retval EFI_SUCCESS The request succeeded. Progress points to the null\r | |
3216 | terminator at the end of the ConfigResp string.\r | |
3217 | @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate Config. Progress\r | |
3218 | points to the first character of ConfigResp.\r | |
3219 | @retval EFI_INVALID_PARAMETER Passing in a NULL for the ConfigResp or\r | |
3220 | Block parameter would result in this type of\r | |
3221 | error. Progress points to the first character of\r | |
3222 | ConfigResp.\r | |
3223 | @retval EFI_INVALID_PARAMETER Encountered non <BlockName> formatted name /\r | |
3224 | value pair. Block is left updated and\r | |
3225 | Progress points at the '&' preceding the first\r | |
3226 | non-<BlockName>.\r | |
3227 | @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined.\r | |
3228 | @retval EFI_NOT_FOUND Target for the specified routing data was not found.\r | |
3229 | Progress points to the "G" in "GUID" of the errant\r | |
3230 | routing data.\r | |
3231 | \r | |
3232 | **/\r | |
3233 | EFI_STATUS\r | |
3234 | EFIAPI\r | |
3235 | HiiConfigToBlock (\r | |
3236 | IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r | |
3237 | IN CONST EFI_STRING ConfigResp,\r | |
3238 | IN OUT UINT8 *Block,\r | |
3239 | IN OUT UINTN *BlockSize,\r | |
3240 | OUT EFI_STRING *Progress\r | |
3241 | )\r | |
3242 | {\r | |
3243 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
3244 | EFI_STRING StringPtr;\r | |
3245 | UINTN Length;\r | |
3246 | EFI_STATUS Status;\r | |
3247 | UINT8 *TmpBuffer;\r | |
3248 | UINTN Offset;\r | |
3249 | UINTN Width;\r | |
3250 | UINT8 *Value;\r | |
3251 | UINTN BufferSize;\r | |
3252 | UINTN MaxBlockSize;\r | |
3253 | \r | |
3254 | if (This == NULL || BlockSize == NULL || Progress == NULL) {\r | |
3255 | return EFI_INVALID_PARAMETER;\r | |
3256 | }\r | |
3257 | \r | |
3258 | *Progress = ConfigResp;\r | |
3259 | if (ConfigResp == NULL) {\r | |
3260 | return EFI_INVALID_PARAMETER;\r | |
3261 | }\r | |
3262 | \r | |
3263 | Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
3264 | ASSERT (Private != NULL);\r | |
3265 | \r | |
3266 | StringPtr = ConfigResp;\r | |
3267 | BufferSize = *BlockSize;\r | |
3268 | Value = NULL;\r | |
3269 | MaxBlockSize = 0;\r | |
3270 | \r | |
3271 | //\r | |
3272 | // Jump <ConfigHdr>\r | |
3273 | //\r | |
3274 | if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r | |
3275 | *Progress = StringPtr;\r | |
3276 | Status = EFI_INVALID_PARAMETER;\r | |
3277 | goto Exit;\r | |
3278 | }\r | |
3279 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"PATH=", StrLen (L"PATH=")) != 0) {\r | |
3280 | StringPtr++;\r | |
3281 | }\r | |
3282 | if (*StringPtr == 0) {\r | |
3283 | *Progress = StringPtr;\r | |
3284 | Status = EFI_INVALID_PARAMETER;\r | |
3285 | goto Exit;\r | |
3286 | }\r | |
3287 | \r | |
3288 | while (*StringPtr != L'&' && *StringPtr != 0) {\r | |
3289 | StringPtr++;\r | |
3290 | }\r | |
3291 | if (*StringPtr == 0) {\r | |
3292 | *Progress = StringPtr;\r | |
3293 | Status = EFI_INVALID_PARAMETER;\r | |
3294 | goto Exit;\r | |
3295 | }\r | |
3296 | //\r | |
3297 | // Skip '&'\r | |
3298 | //\r | |
3299 | StringPtr++;\r | |
3300 | \r | |
3301 | //\r | |
3302 | // Parse each <ConfigElement> if exists\r | |
3303 | // Only <BlockConfig> format is supported by this help function.\r | |
3304 | // <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE='<Number>\r | |
3305 | //\r | |
3306 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {\r | |
3307 | StringPtr += StrLen (L"OFFSET=");\r | |
3308 | //\r | |
3309 | // Get Offset\r | |
3310 | //\r | |
3311 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r | |
3312 | if (EFI_ERROR (Status)) {\r | |
3313 | *Progress = ConfigResp;\r | |
3314 | goto Exit;\r | |
3315 | }\r | |
3316 | Offset = 0;\r | |
3317 | CopyMem (\r | |
3318 | &Offset,\r | |
3319 | TmpBuffer,\r | |
3320 | (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r | |
3321 | );\r | |
3322 | FreePool (TmpBuffer);\r | |
3323 | \r | |
3324 | StringPtr += Length;\r | |
3325 | if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r | |
3326 | *Progress = StringPtr - Length - StrLen (L"OFFSET=") - 1;\r | |
3327 | Status = EFI_INVALID_PARAMETER;\r | |
3328 | goto Exit;\r | |
3329 | }\r | |
3330 | StringPtr += StrLen (L"&WIDTH=");\r | |
3331 | \r | |
3332 | //\r | |
3333 | // Get Width\r | |
3334 | //\r | |
3335 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r | |
3336 | if (EFI_ERROR (Status)) {\r | |
3337 | *Progress = ConfigResp;\r | |
3338 | goto Exit;\r | |
3339 | }\r | |
3340 | Width = 0;\r | |
3341 | CopyMem (\r | |
3342 | &Width,\r | |
3343 | TmpBuffer,\r | |
3344 | (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r | |
3345 | );\r | |
3346 | FreePool (TmpBuffer);\r | |
3347 | \r | |
3348 | StringPtr += Length;\r | |
3349 | if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {\r | |
3350 | *Progress = StringPtr - Length - StrLen (L"&WIDTH=");\r | |
3351 | Status = EFI_INVALID_PARAMETER;\r | |
3352 | goto Exit;\r | |
3353 | }\r | |
3354 | StringPtr += StrLen (L"&VALUE=");\r | |
3355 | \r | |
3356 | //\r | |
3357 | // Get Value\r | |
3358 | //\r | |
3359 | Status = GetValueOfNumber (StringPtr, &Value, &Length);\r | |
3360 | if (EFI_ERROR (Status)) {\r | |
3361 | *Progress = ConfigResp;\r | |
3362 | goto Exit;\r | |
3363 | }\r | |
3364 | \r | |
3365 | StringPtr += Length;\r | |
3366 | if (*StringPtr != 0 && *StringPtr != L'&') {\r | |
3367 | *Progress = StringPtr - Length - 7;\r | |
3368 | Status = EFI_INVALID_PARAMETER;\r | |
3369 | goto Exit;\r | |
3370 | }\r | |
3371 | \r | |
3372 | //\r | |
3373 | // Update the Block with configuration info\r | |
3374 | //\r | |
3375 | if ((Block != NULL) && (Offset + Width <= BufferSize)) {\r | |
3376 | CopyMem (Block + Offset, Value, Width);\r | |
3377 | }\r | |
3378 | if (Offset + Width > MaxBlockSize) {\r | |
3379 | MaxBlockSize = Offset + Width;\r | |
3380 | }\r | |
3381 | \r | |
3382 | FreePool (Value);\r | |
3383 | Value = NULL;\r | |
3384 | \r | |
3385 | //\r | |
3386 | // If '\0', parsing is finished. Otherwise skip '&' to continue\r | |
3387 | //\r | |
3388 | if (*StringPtr == 0) {\r | |
3389 | break;\r | |
3390 | }\r | |
3391 | \r | |
3392 | StringPtr++;\r | |
3393 | }\r | |
3394 | \r | |
3395 | //\r | |
3396 | // The input string is ConfigAltResp format.\r | |
3397 | //\r | |
3398 | if ((*StringPtr != 0) && (StrnCmp (StringPtr, L"&GUID=", StrLen (L"&GUID=")) != 0)) {\r | |
3399 | *Progress = StringPtr - 1;\r | |
3400 | Status = EFI_INVALID_PARAMETER;\r | |
3401 | goto Exit;\r | |
3402 | }\r | |
3403 | \r | |
3404 | *Progress = StringPtr + StrLen (StringPtr);\r | |
3405 | *BlockSize = MaxBlockSize - 1;\r | |
3406 | \r | |
3407 | if (MaxBlockSize > BufferSize) {\r | |
3408 | *BlockSize = MaxBlockSize;\r | |
3409 | if (Block != NULL) {\r | |
3410 | return EFI_DEVICE_ERROR;\r | |
3411 | }\r | |
3412 | }\r | |
3413 | \r | |
3414 | if (Block == NULL) {\r | |
3415 | *Progress = ConfigResp;\r | |
3416 | return EFI_INVALID_PARAMETER;\r | |
3417 | }\r | |
3418 | \r | |
3419 | return EFI_SUCCESS;\r | |
3420 | \r | |
3421 | Exit:\r | |
3422 | \r | |
3423 | if (Value != NULL) {\r | |
3424 | FreePool (Value);\r | |
3425 | }\r | |
3426 | return Status;\r | |
3427 | }\r | |
3428 | \r | |
3429 | \r | |
3430 | /**\r | |
3431 | This helper function is to be called by drivers to extract portions of\r | |
3432 | a larger configuration string.\r | |
3433 | \r | |
3434 | @param This A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r | |
3435 | instance.\r | |
3436 | @param Configuration A null-terminated Unicode string in\r | |
3437 | <MultiConfigAltResp> format.\r | |
3438 | @param Guid A pointer to the GUID value to search for in the\r | |
3439 | routing portion of the ConfigResp string when\r | |
3440 | retrieving the requested data. If Guid is NULL,\r | |
3441 | then all GUID values will be searched for.\r | |
3442 | @param Name A pointer to the NAME value to search for in the\r | |
3443 | routing portion of the ConfigResp string when\r | |
3444 | retrieving the requested data. If Name is NULL,\r | |
3445 | then all Name values will be searched for.\r | |
3446 | @param DevicePath A pointer to the PATH value to search for in the\r | |
3447 | routing portion of the ConfigResp string when\r | |
3448 | retrieving the requested data. If DevicePath is\r | |
3449 | NULL, then all DevicePath values will be searched\r | |
3450 | for.\r | |
3451 | @param AltCfgId A pointer to the ALTCFG value to search for in the\r | |
3452 | routing portion of the ConfigResp string when\r | |
3453 | retrieving the requested data. If this parameter\r | |
3454 | is NULL, then the current setting will be\r | |
3455 | retrieved.\r | |
3456 | @param AltCfgResp A pointer to a buffer which will be allocated by\r | |
3457 | the function which contains the retrieved string\r | |
3458 | as requested. This buffer is only allocated if\r | |
3459 | the call was successful. It is <ConfigResp> format.\r | |
3460 | \r | |
3461 | @retval EFI_SUCCESS The request succeeded. The requested data was\r | |
3462 | extracted and placed in the newly allocated\r | |
3463 | AltCfgResp buffer.\r | |
3464 | @retval EFI_OUT_OF_RESOURCES Not enough memory to allocate AltCfgResp.\r | |
3465 | @retval EFI_INVALID_PARAMETER Any parameter is invalid.\r | |
3466 | @retval EFI_NOT_FOUND Target for the specified routing data was not\r | |
3467 | found.\r | |
3468 | \r | |
3469 | **/\r | |
3470 | EFI_STATUS\r | |
3471 | EFIAPI\r | |
3472 | HiiGetAltCfg (\r | |
3473 | IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,\r | |
3474 | IN CONST EFI_STRING Configuration,\r | |
3475 | IN CONST EFI_GUID *Guid,\r | |
3476 | IN CONST EFI_STRING Name,\r | |
3477 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
3478 | IN CONST UINT16 *AltCfgId,\r | |
3479 | OUT EFI_STRING *AltCfgResp\r | |
3480 | )\r | |
3481 | {\r | |
3482 | EFI_STATUS Status;\r | |
3483 | EFI_STRING StringPtr;\r | |
3484 | EFI_STRING HdrStart;\r | |
3485 | EFI_STRING HdrEnd;\r | |
3486 | EFI_STRING TmpPtr;\r | |
3487 | UINTN Length;\r | |
3488 | EFI_STRING GuidStr;\r | |
3489 | EFI_STRING NameStr;\r | |
3490 | EFI_STRING PathStr;\r | |
3491 | EFI_STRING AltIdStr;\r | |
3492 | EFI_STRING Result;\r | |
3493 | BOOLEAN GuidFlag;\r | |
3494 | BOOLEAN NameFlag;\r | |
3495 | BOOLEAN PathFlag;\r | |
3496 | \r | |
3497 | HdrStart = NULL;\r | |
3498 | HdrEnd = NULL;\r | |
3499 | GuidStr = NULL;\r | |
3500 | NameStr = NULL;\r | |
3501 | PathStr = NULL;\r | |
3502 | AltIdStr = NULL;\r | |
3503 | Result = NULL;\r | |
3504 | GuidFlag = FALSE;\r | |
3505 | NameFlag = FALSE;\r | |
3506 | PathFlag = FALSE;\r | |
3507 | \r | |
3508 | if (This == NULL || Configuration == NULL || AltCfgResp == NULL) {\r | |
3509 | return EFI_INVALID_PARAMETER;\r | |
3510 | }\r | |
3511 | \r | |
3512 | StringPtr = Configuration;\r | |
3513 | if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r | |
3514 | return EFI_INVALID_PARAMETER;\r | |
3515 | }\r | |
3516 | \r | |
3517 | //\r | |
3518 | // Generate the sub string for later matching.\r | |
3519 | //\r | |
3520 | GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) Guid, 1, &GuidStr);\r | |
3521 | GenerateSubStr (\r | |
3522 | L"PATH=",\r | |
3523 | GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),\r | |
3524 | (VOID *) DevicePath,\r | |
3525 | 1,\r | |
3526 | &PathStr\r | |
3527 | );\r | |
3528 | if (AltCfgId != NULL) {\r | |
3529 | GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (VOID *) AltCfgId, 3, &AltIdStr); \r | |
3530 | }\r | |
3531 | if (Name != NULL) {\r | |
3532 | GenerateSubStr (L"NAME=", StrLen (Name) * sizeof (CHAR16), (VOID *) Name, 2, &NameStr); \r | |
3533 | } else {\r | |
3534 | GenerateSubStr (L"NAME=", 0, NULL, 2, &NameStr);\r | |
3535 | }\r | |
3536 | \r | |
3537 | while (*StringPtr != 0) {\r | |
3538 | //\r | |
3539 | // Try to match the GUID\r | |
3540 | //\r | |
3541 | if (!GuidFlag) {\r | |
3542 | TmpPtr = StrStr (StringPtr, GuidStr);\r | |
3543 | if (TmpPtr == NULL) {\r | |
3544 | Status = EFI_NOT_FOUND;\r | |
3545 | goto Exit;\r | |
3546 | }\r | |
3547 | HdrStart = TmpPtr;\r | |
3548 | \r | |
3549 | //\r | |
3550 | // Jump to <NameHdr>\r | |
3551 | //\r | |
3552 | if (Guid != NULL) {\r | |
3553 | StringPtr = TmpPtr + StrLen (GuidStr);\r | |
3554 | } else {\r | |
3555 | StringPtr = StrStr (TmpPtr, L"NAME=");\r | |
3556 | if (StringPtr == NULL) {\r | |
3557 | Status = EFI_NOT_FOUND;\r | |
3558 | goto Exit;\r | |
3559 | }\r | |
3560 | }\r | |
3561 | GuidFlag = TRUE;\r | |
3562 | }\r | |
3563 | \r | |
3564 | //\r | |
3565 | // Try to match the NAME\r | |
3566 | //\r | |
3567 | if (GuidFlag && !NameFlag) {\r | |
3568 | if (StrnCmp (StringPtr, NameStr, StrLen (NameStr)) != 0) {\r | |
3569 | GuidFlag = FALSE;\r | |
3570 | } else {\r | |
3571 | //\r | |
3572 | // Jump to <PathHdr>\r | |
3573 | //\r | |
3574 | if (Name != NULL) {\r | |
3575 | StringPtr += StrLen (NameStr);\r | |
3576 | } else {\r | |
3577 | StringPtr = StrStr (StringPtr, L"PATH=");\r | |
3578 | if (StringPtr == NULL) {\r | |
3579 | Status = EFI_NOT_FOUND;\r | |
3580 | goto Exit;\r | |
3581 | }\r | |
3582 | }\r | |
3583 | NameFlag = TRUE;\r | |
3584 | }\r | |
3585 | }\r | |
3586 | \r | |
3587 | //\r | |
3588 | // Try to match the DevicePath\r | |
3589 | //\r | |
3590 | if (GuidFlag && NameFlag && !PathFlag) {\r | |
3591 | if (StrnCmp (StringPtr, PathStr, StrLen (PathStr)) != 0) {\r | |
3592 | GuidFlag = FALSE;\r | |
3593 | NameFlag = FALSE;\r | |
3594 | } else {\r | |
3595 | //\r | |
3596 | // Jump to '&' before <DescHdr> or <ConfigBody>\r | |
3597 | //\r | |
3598 | if (DevicePath != NULL) {\r | |
3599 | StringPtr += StrLen (PathStr);\r | |
3600 | } else {\r | |
3601 | StringPtr = StrStr (StringPtr, L"&");\r | |
3602 | if (StringPtr == NULL) {\r | |
3603 | Status = EFI_NOT_FOUND;\r | |
3604 | goto Exit;\r | |
3605 | }\r | |
3606 | StringPtr ++;\r | |
3607 | }\r | |
3608 | PathFlag = TRUE;\r | |
3609 | HdrEnd = StringPtr;\r | |
3610 | }\r | |
3611 | }\r | |
3612 | \r | |
3613 | //\r | |
3614 | // Try to match the AltCfgId\r | |
3615 | //\r | |
3616 | if (GuidFlag && NameFlag && PathFlag) {\r | |
3617 | if (AltCfgId == NULL) {\r | |
3618 | //\r | |
3619 | // Return Current Setting when AltCfgId is NULL.\r | |
3620 | //\r | |
3621 | Status = OutputConfigBody (StringPtr, &Result);\r | |
3622 | goto Exit;\r | |
3623 | }\r | |
3624 | //\r | |
3625 | // Search the <ConfigAltResp> to get the <AltResp> with AltCfgId.\r | |
3626 | //\r | |
3627 | if (StrnCmp (StringPtr, AltIdStr, StrLen (AltIdStr)) != 0) {\r | |
3628 | GuidFlag = FALSE;\r | |
3629 | NameFlag = FALSE;\r | |
3630 | PathFlag = FALSE;\r | |
3631 | } else {\r | |
3632 | //\r | |
3633 | // Skip AltIdStr and &\r | |
3634 | //\r | |
3635 | StringPtr = StringPtr + StrLen (AltIdStr);\r | |
3636 | Status = OutputConfigBody (StringPtr, &Result);\r | |
3637 | goto Exit;\r | |
3638 | }\r | |
3639 | }\r | |
3640 | }\r | |
3641 | \r | |
3642 | Status = EFI_NOT_FOUND;\r | |
3643 | \r | |
3644 | Exit:\r | |
3645 | *AltCfgResp = NULL;\r | |
3646 | if (!EFI_ERROR (Status) && (Result != NULL)) {\r | |
3647 | //\r | |
3648 | // Copy the <ConfigHdr> and <ConfigBody>\r | |
3649 | //\r | |
3650 | Length = HdrEnd - HdrStart + StrLen (Result) + 1;\r | |
3651 | *AltCfgResp = AllocateZeroPool (Length * sizeof (CHAR16));\r | |
3652 | if (*AltCfgResp == NULL) {\r | |
3653 | Status = EFI_OUT_OF_RESOURCES;\r | |
3654 | } else {\r | |
3655 | StrnCpy (*AltCfgResp, HdrStart, HdrEnd - HdrStart);\r | |
3656 | StrCat (*AltCfgResp, Result);\r | |
3657 | Status = EFI_SUCCESS;\r | |
3658 | }\r | |
3659 | }\r | |
3660 | \r | |
3661 | if (GuidStr != NULL) {\r | |
3662 | FreePool (GuidStr);\r | |
3663 | }\r | |
3664 | if (NameStr != NULL) {\r | |
3665 | FreePool (NameStr);\r | |
3666 | }\r | |
3667 | if (PathStr != NULL) {\r | |
3668 | FreePool (PathStr);\r | |
3669 | }\r | |
3670 | if (AltIdStr != NULL) {\r | |
3671 | FreePool (AltIdStr);\r | |
3672 | }\r | |
3673 | if (Result != NULL) {\r | |
3674 | FreePool (Result);\r | |
3675 | }\r | |
3676 | \r | |
3677 | return Status;\r | |
3678 | \r | |
3679 | }\r | |
3680 | \r | |
3681 | \r |