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