]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c
MdeModulePkg: Replace [Ascii|Unicode]ValueToString
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigKeywordHandler.c
1 /** @file
2 Implementation of interfaces function for EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL.
3
4 Copyright (c) 2015 - 2017, 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
18 extern HII_DATABASE_PRIVATE_DATA mPrivate;
19
20 /**
21 Convert the hex UNICODE %02x encoding of a UEFI device path to binary
22 from <PathHdr> of <MultiKeywordRequest>.
23
24 This is a internal function.
25
26 @param String MultiKeywordRequest string.
27 @param DevicePathData Binary of a UEFI device path.
28 @param NextString string follow the possible PathHdr string.
29
30 @retval EFI_INVALID_PARAMETER The device path is not valid or the incoming parameter is invalid.
31 @retval EFI_OUT_OF_RESOURCES Lake of resources to store necessary structures.
32 @retval EFI_SUCCESS The device path is retrieved and translated to binary format.
33 The Input string not include PathHdr section.
34
35 **/
36 EFI_STATUS
37 ExtractDevicePath (
38 IN EFI_STRING String,
39 OUT UINT8 **DevicePathData,
40 OUT EFI_STRING *NextString
41 )
42 {
43 UINTN Length;
44 EFI_STRING PathHdr;
45 UINT8 *DevicePathBuffer;
46 CHAR16 TemStr[2];
47 UINTN Index;
48 UINT8 DigitUint8;
49 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
50
51 ASSERT (NextString != NULL && DevicePathData != NULL);
52
53 //
54 // KeywordRequest == NULL case.
55 //
56 if (String == NULL) {
57 *DevicePathData = NULL;
58 *NextString = NULL;
59 return EFI_SUCCESS;
60 }
61
62 //
63 // Skip '&' if exist.
64 //
65 if (*String == L'&') {
66 String ++;
67 }
68
69 //
70 // Find the 'PATH=' of <PathHdr>.
71 //
72 if (StrnCmp (String, L"PATH=", StrLen (L"PATH=")) != 0) {
73 if (StrnCmp (String, L"KEYWORD=", StrLen (L"KEYWORD=")) != 0) {
74 return EFI_INVALID_PARAMETER;
75 } else {
76 //
77 // Not include PathHdr, return success and DevicePath = NULL.
78 //
79 *DevicePathData = NULL;
80 *NextString = String;
81 return EFI_SUCCESS;
82 }
83 }
84
85 //
86 // Check whether path data does exist.
87 //
88 String += StrLen (L"PATH=");
89 if (*String == 0) {
90 return EFI_INVALID_PARAMETER;
91 }
92 PathHdr = String;
93
94 //
95 // The content between 'PATH=' of <ConfigHdr> and '&' of next element
96 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding
97 // of UEFI device path.
98 //
99 for (Length = 0; *String != 0 && *String != L'&'; String++, Length++);
100
101 //
102 // Save the return next keyword string value.
103 //
104 *NextString = String;
105
106 //
107 // Check DevicePath Length
108 //
109 if (((Length + 1) / 2) < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
110 return EFI_INVALID_PARAMETER;
111 }
112
113 //
114 // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
115 // as the device path resides in RAM memory.
116 // Translate the data into binary.
117 //
118 DevicePathBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);
119 if (DevicePathBuffer == NULL) {
120 return EFI_OUT_OF_RESOURCES;
121 }
122
123 //
124 // Convert DevicePath
125 //
126 ZeroMem (TemStr, sizeof (TemStr));
127 for (Index = 0; Index < Length; Index ++) {
128 TemStr[0] = PathHdr[Index];
129 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
130 if ((Index & 1) == 0) {
131 DevicePathBuffer [Index/2] = DigitUint8;
132 } else {
133 DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);
134 }
135 }
136
137 //
138 // Validate DevicePath
139 //
140 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DevicePathBuffer;
141 while (!IsDevicePathEnd (DevicePath)) {
142 if ((DevicePath->Type == 0) || (DevicePath->SubType == 0) || (DevicePathNodeLength (DevicePath) < sizeof (EFI_DEVICE_PATH_PROTOCOL))) {
143 //
144 // Invalid device path
145 //
146 FreePool (DevicePathBuffer);
147 return EFI_INVALID_PARAMETER;
148 }
149 DevicePath = NextDevicePathNode (DevicePath);
150 }
151
152 //
153 // return the device path
154 //
155 *DevicePathData = DevicePathBuffer;
156
157 return EFI_SUCCESS;
158 }
159
160 /**
161 Get NameSpace from the input NameSpaceId string.
162
163 This is a internal function.
164
165 @param String <NameSpaceId> format string.
166 @param NameSpace Return the name space string.
167 @param NextString Return the next string follow namespace.
168
169 @retval EFI_SUCCESS Get the namespace string success.
170 @retval EFI_INVALID_PARAMETER The NameSpaceId string not follow spec definition.
171
172 **/
173 EFI_STATUS
174 ExtractNameSpace (
175 IN EFI_STRING String,
176 OUT CHAR8 **NameSpace,
177 OUT EFI_STRING *NextString
178 )
179 {
180 CHAR16 *TmpPtr;
181 UINTN NameSpaceSize;
182
183 ASSERT (NameSpace != NULL);
184
185 TmpPtr = NULL;
186
187 //
188 // Input NameSpaceId == NULL
189 //
190 if (String == NULL) {
191 *NameSpace = NULL;
192 if (NextString != NULL) {
193 *NextString = NULL;
194 }
195 return EFI_SUCCESS;
196 }
197
198 //
199 // Skip '&' if exist.
200 //
201 if (*String == L'&') {
202 String++;
203 }
204
205 if (StrnCmp (String, L"NAMESPACE=", StrLen (L"NAMESPACE=")) != 0) {
206 return EFI_INVALID_PARAMETER;
207 }
208 String += StrLen (L"NAMESPACE=");
209
210 TmpPtr = StrStr (String, L"&");
211 if (TmpPtr != NULL) {
212 *TmpPtr = 0;
213 }
214 if (NextString != NULL) {
215 *NextString = String + StrLen (String);
216 }
217
218 //
219 // Input NameSpace is unicode string. The language in String package is ascii string.
220 // Here will convert the unicode string to ascii and save it.
221 //
222 NameSpaceSize = StrLen (String) + 1;
223 *NameSpace = AllocatePool (NameSpaceSize);
224 if (*NameSpace == NULL) {
225 return EFI_OUT_OF_RESOURCES;
226 }
227 UnicodeStrToAsciiStrS (String, *NameSpace, NameSpaceSize);
228
229 if (TmpPtr != NULL) {
230 *TmpPtr = L'&';
231 }
232
233 return EFI_SUCCESS;
234 }
235
236 /**
237 Get Keyword from the input KeywordRequest string.
238
239 This is a internal function.
240
241 @param String KeywordRequestformat string.
242 @param Keyword return the extract keyword string.
243 @param NextString return the next string follow this keyword section.
244
245 @retval EFI_SUCCESS Success to get the keyword string.
246 @retval EFI_INVALID_PARAMETER Parse the input string return error.
247
248 **/
249 EFI_STATUS
250 ExtractKeyword (
251 IN EFI_STRING String,
252 OUT EFI_STRING *Keyword,
253 OUT EFI_STRING *NextString
254 )
255 {
256 EFI_STRING TmpPtr;
257
258 ASSERT ((Keyword != NULL) && (NextString != NULL));
259
260 TmpPtr = NULL;
261
262 //
263 // KeywordRequest == NULL case.
264 //
265 if (String == NULL) {
266 *Keyword = NULL;
267 *NextString = NULL;
268 return EFI_SUCCESS;
269 }
270
271 //
272 // Skip '&' if exist.
273 //
274 if (*String == L'&') {
275 String++;
276 }
277
278 if (StrnCmp (String, L"KEYWORD=", StrLen (L"KEYWORD=")) != 0) {
279 return EFI_INVALID_PARAMETER;
280 }
281
282 String += StrLen (L"KEYWORD=");
283
284 TmpPtr = StrStr (String, L"&");
285 if (TmpPtr != NULL) {
286 *TmpPtr = 0;
287 }
288 *NextString = String + StrLen (String);
289
290 *Keyword = AllocateCopyPool (StrSize (String), String);
291 if (*Keyword == NULL) {
292 return EFI_OUT_OF_RESOURCES;
293 }
294
295 if (TmpPtr != NULL) {
296 *TmpPtr = L'&';
297 }
298
299 return EFI_SUCCESS;
300 }
301
302 /**
303 Get value from the input KeywordRequest string.
304
305 This is a internal function.
306
307 @param String KeywordRequestformat string.
308 @param Value return the extract value string.
309 @param NextString return the next string follow this keyword section.
310
311 @retval EFI_SUCCESS Success to get the keyword string.
312 @retval EFI_INVALID_PARAMETER Parse the input string return error.
313
314 **/
315 EFI_STATUS
316 ExtractValue (
317 IN EFI_STRING String,
318 OUT EFI_STRING *Value,
319 OUT EFI_STRING *NextString
320 )
321 {
322 EFI_STRING TmpPtr;
323
324 ASSERT ((Value != NULL) && (NextString != NULL) && (String != NULL));
325
326 //
327 // Skip '&' if exist.
328 //
329 if (*String == L'&') {
330 String++;
331 }
332
333 if (StrnCmp (String, L"VALUE=", StrLen (L"VALUE=")) != 0) {
334 return EFI_INVALID_PARAMETER;
335 }
336
337 String += StrLen (L"VALUE=");
338
339 TmpPtr = StrStr (String, L"&");
340 if (TmpPtr != NULL) {
341 *TmpPtr = 0;
342 }
343 *NextString = String + StrLen (String);
344
345 *Value = AllocateCopyPool (StrSize (String), String);
346 if (*Value == NULL) {
347 return EFI_OUT_OF_RESOURCES;
348 }
349
350 if (TmpPtr != NULL) {
351 *TmpPtr = L'&';
352 }
353
354 return EFI_SUCCESS;
355 }
356
357 /**
358 Get filter from the input KeywordRequest string.
359
360 This is a internal function.
361
362 @param String KeywordRequestformat string.
363 @param FilterFlags return the filter condition.
364 @param NextString return the next string follow this keyword section.
365
366 @retval EFI_SUCCESS Success to get the keyword string.
367 @retval EFI_INVALID_PARAMETER Parse the input string return error.
368
369 **/
370 BOOLEAN
371 ExtractFilter (
372 IN EFI_STRING String,
373 OUT UINT8 *FilterFlags,
374 OUT EFI_STRING *NextString
375 )
376 {
377 CHAR16 *PathPtr;
378 CHAR16 *KeywordPtr;
379 BOOLEAN RetVal;
380
381 ASSERT ((FilterFlags != NULL) && (NextString != NULL));
382
383 //
384 // String end, no filter section.
385 //
386 if (String == NULL) {
387 *NextString = NULL;
388 return FALSE;
389 }
390
391 *FilterFlags = 0;
392 RetVal = TRUE;
393
394 //
395 // Skip '&' if exist.
396 //
397 if (*String == L'&') {
398 String++;
399 }
400
401 if (StrnCmp (String, L"ReadOnly", StrLen (L"ReadOnly")) == 0) {
402 //
403 // Find ReadOnly filter.
404 //
405 *FilterFlags |= EFI_KEYWORD_FILTER_READONY;
406 String += StrLen (L"ReadOnly");
407 } else if (StrnCmp (String, L"ReadWrite", StrLen (L"ReadWrite")) == 0) {
408 //
409 // Find ReadWrite filter.
410 //
411 *FilterFlags |= EFI_KEYWORD_FILTER_REAWRITE;
412 String += StrLen (L"ReadWrite");
413 } else if (StrnCmp (String, L"Buffer", StrLen (L"Buffer")) == 0) {
414 //
415 // Find Buffer Filter.
416 //
417 *FilterFlags |= EFI_KEYWORD_FILTER_BUFFER;
418 String += StrLen (L"Buffer");
419 } else if (StrnCmp (String, L"Numeric", StrLen (L"Numeric")) == 0) {
420 //
421 // Find Numeric Filter
422 //
423 String += StrLen (L"Numeric");
424 if (*String != L':') {
425 *FilterFlags |= EFI_KEYWORD_FILTER_NUMERIC;
426 } else {
427 String++;
428 switch (*String) {
429 case L'1':
430 *FilterFlags |= EFI_KEYWORD_FILTER_NUMERIC_1;
431 break;
432 case L'2':
433 *FilterFlags |= EFI_KEYWORD_FILTER_NUMERIC_2;
434 break;
435 case L'4':
436 *FilterFlags |= EFI_KEYWORD_FILTER_NUMERIC_4;
437 break;
438 case L'8':
439 *FilterFlags |= EFI_KEYWORD_FILTER_NUMERIC_8;
440 break;
441 default:
442 ASSERT (FALSE);
443 break;
444 }
445 String++;
446 }
447 } else {
448 //
449 // Check whether other filter item defined by Platform.
450 //
451 if ((StrnCmp (String, L"&PATH", StrLen (L"&PATH")) == 0) ||
452 (StrnCmp (String, L"&KEYWORD", StrLen (L"&KEYWORD")) == 0)) {
453 //
454 // New KeywordRequest start, no platform defined filter.
455 //
456 } else {
457 //
458 // Platform defined filter rule.
459 // Just skip platform defined filter rule, return success.
460 //
461 PathPtr = StrStr(String, L"&PATH");
462 KeywordPtr = StrStr(String, L"&KEYWORD");
463 if (PathPtr != NULL && KeywordPtr != NULL) {
464 //
465 // If both sections exist, return the first follow string.
466 //
467 String = KeywordPtr > PathPtr ? PathPtr : KeywordPtr;
468 } else if (PathPtr != NULL) {
469 //
470 // Should not exist PathPtr != NULL && KeywordPtr == NULL case.
471 //
472 ASSERT (FALSE);
473 } else if (KeywordPtr != NULL) {
474 //
475 // Just to the next keyword section.
476 //
477 String = KeywordPtr;
478 } else {
479 //
480 // Only has platform defined filter section, just skip it.
481 //
482 String += StrLen (String);
483 }
484 }
485 RetVal = FALSE;
486 }
487
488 *NextString = String;
489
490 return RetVal;
491 }
492
493 /**
494 Extract Readonly flag from opcode.
495
496 This is a internal function.
497
498 @param OpCodeData Input opcode for this question.
499
500 @retval TRUE This question is readonly.
501 @retval FALSE This question is not readonly.
502
503 **/
504 BOOLEAN
505 ExtractReadOnlyFromOpCode (
506 IN UINT8 *OpCodeData
507 )
508 {
509 EFI_IFR_QUESTION_HEADER *QuestionHdr;
510
511 ASSERT (OpCodeData != NULL);
512
513 QuestionHdr = (EFI_IFR_QUESTION_HEADER *) (OpCodeData + sizeof (EFI_IFR_OP_HEADER));
514
515 return (QuestionHdr->Flags & EFI_IFR_FLAG_READ_ONLY) != 0;
516 }
517
518 /**
519 Create a circuit to check the filter section.
520
521 This is a internal function.
522
523 @param OpCodeData The question binary ifr data.
524 @param KeywordRequest KeywordRequestformat string.
525 @param NextString return the next string follow this keyword section.
526 @param ReadOnly Return whether this question is read only.
527
528 @retval KEYWORD_HANDLER_NO_ERROR Success validate.
529 @retval KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED Validate fail.
530
531 **/
532 UINT32
533 ValidateFilter (
534 IN UINT8 *OpCodeData,
535 IN CHAR16 *KeywordRequest,
536 OUT CHAR16 **NextString,
537 OUT BOOLEAN *ReadOnly
538 )
539 {
540 CHAR16 *NextFilter;
541 CHAR16 *StringPtr;
542 UINT8 FilterFlags;
543 EFI_IFR_QUESTION_HEADER *QuestionHdr;
544 EFI_IFR_OP_HEADER *OpCodeHdr;
545 UINT8 Flags;
546 UINT32 RetVal;
547
548 RetVal = KEYWORD_HANDLER_NO_ERROR;
549 StringPtr = KeywordRequest;
550
551 OpCodeHdr = (EFI_IFR_OP_HEADER *) OpCodeData;
552 QuestionHdr = (EFI_IFR_QUESTION_HEADER *) (OpCodeData + sizeof (EFI_IFR_OP_HEADER));
553 if (OpCodeHdr->OpCode == EFI_IFR_ONE_OF_OP || OpCodeHdr->OpCode == EFI_IFR_NUMERIC_OP) {
554 Flags = *(OpCodeData + sizeof (EFI_IFR_OP_HEADER) + sizeof (EFI_IFR_QUESTION_HEADER));
555 } else {
556 Flags = 0;
557 }
558
559 //
560 // Get ReadOnly flag from Question.
561 //
562 *ReadOnly = ExtractReadOnlyFromOpCode(OpCodeData);
563
564 while (ExtractFilter (StringPtr, &FilterFlags, &NextFilter)) {
565 switch (FilterFlags) {
566 case EFI_KEYWORD_FILTER_READONY:
567 if ((QuestionHdr->Flags & EFI_IFR_FLAG_READ_ONLY) == 0) {
568 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
569 goto Done;
570 }
571 break;
572
573 case EFI_KEYWORD_FILTER_REAWRITE:
574 if ((QuestionHdr->Flags & EFI_IFR_FLAG_READ_ONLY) != 0) {
575 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
576 goto Done;
577 }
578 break;
579
580 case EFI_KEYWORD_FILTER_BUFFER:
581 //
582 // Only these three opcode use numeric value type.
583 //
584 if (OpCodeHdr->OpCode == EFI_IFR_ONE_OF_OP || OpCodeHdr->OpCode == EFI_IFR_NUMERIC_OP || OpCodeHdr->OpCode == EFI_IFR_CHECKBOX_OP) {
585 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
586 goto Done;
587 }
588 break;
589
590 case EFI_KEYWORD_FILTER_NUMERIC:
591 if (OpCodeHdr->OpCode != EFI_IFR_ONE_OF_OP && OpCodeHdr->OpCode != EFI_IFR_NUMERIC_OP && OpCodeHdr->OpCode != EFI_IFR_CHECKBOX_OP) {
592 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
593 goto Done;
594 }
595 break;
596
597 case EFI_KEYWORD_FILTER_NUMERIC_1:
598 case EFI_KEYWORD_FILTER_NUMERIC_2:
599 case EFI_KEYWORD_FILTER_NUMERIC_4:
600 case EFI_KEYWORD_FILTER_NUMERIC_8:
601 if (OpCodeHdr->OpCode != EFI_IFR_ONE_OF_OP && OpCodeHdr->OpCode != EFI_IFR_NUMERIC_OP && OpCodeHdr->OpCode != EFI_IFR_CHECKBOX_OP) {
602 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
603 goto Done;
604 }
605
606 //
607 // For numeric and oneof, it has flags field to specify the detail numeric type.
608 //
609 if (OpCodeHdr->OpCode == EFI_IFR_ONE_OF_OP || OpCodeHdr->OpCode == EFI_IFR_NUMERIC_OP) {
610 switch (Flags & EFI_IFR_NUMERIC_SIZE) {
611 case EFI_IFR_NUMERIC_SIZE_1:
612 if (FilterFlags != EFI_KEYWORD_FILTER_NUMERIC_1) {
613 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
614 goto Done;
615 }
616 break;
617
618 case EFI_IFR_NUMERIC_SIZE_2:
619 if (FilterFlags != EFI_KEYWORD_FILTER_NUMERIC_2) {
620 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
621 goto Done;
622 }
623 break;
624
625 case EFI_IFR_NUMERIC_SIZE_4:
626 if (FilterFlags != EFI_KEYWORD_FILTER_NUMERIC_4) {
627 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
628 goto Done;
629 }
630 break;
631
632 case EFI_IFR_NUMERIC_SIZE_8:
633 if (FilterFlags != EFI_KEYWORD_FILTER_NUMERIC_8) {
634 RetVal = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
635 goto Done;
636 }
637 break;
638
639 default:
640 ASSERT (FALSE);
641 break;
642 }
643 }
644 break;
645
646 default:
647 ASSERT (FALSE);
648 break;
649 }
650
651 //
652 // Jump to the next filter.
653 //
654 StringPtr = NextFilter;
655 }
656
657 Done:
658 //
659 // The current filter which is processing.
660 //
661 *NextString = StringPtr;
662
663 return RetVal;
664 }
665
666 /**
667 Get HII_DATABASE_RECORD from the input device path info.
668
669 This is a internal function.
670
671 @param DevicePath UEFI device path protocol.
672
673 @retval Internal data base record.
674
675 **/
676 HII_DATABASE_RECORD *
677 GetRecordFromDevicePath (
678 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
679 )
680 {
681 LIST_ENTRY *Link;
682 UINT8 *DevicePathPkg;
683 UINT8 *CurrentDevicePath;
684 UINTN DevicePathSize;
685 HII_DATABASE_RECORD *TempDatabase;
686
687 ASSERT (DevicePath != NULL);
688
689 for (Link = mPrivate.DatabaseList.ForwardLink; Link != &mPrivate.DatabaseList; Link = Link->ForwardLink) {
690 TempDatabase = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
691 DevicePathPkg = TempDatabase->PackageList->DevicePathPkg;
692 if (DevicePathPkg != NULL) {
693 CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);
694 DevicePathSize = GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) CurrentDevicePath);
695 if ((CompareMem (DevicePath, CurrentDevicePath, DevicePathSize) == 0)) {
696 return TempDatabase;
697 }
698 }
699 }
700
701 return NULL;
702 }
703
704 /**
705 Calculate the size of StringSrc and output it. Also copy string text from src
706 to dest.
707
708 This is a internal function.
709
710 @param StringSrc Points to current null-terminated string.
711 @param BufferSize Length of the buffer.
712 @param StringDest Buffer to store the string text.
713
714 @retval EFI_SUCCESS The string text was outputted successfully.
715 @retval EFI_OUT_OF_RESOURCES Out of resource.
716
717 **/
718 EFI_STATUS
719 GetUnicodeStringTextAndSize (
720 IN UINT8 *StringSrc,
721 OUT UINTN *BufferSize,
722 OUT EFI_STRING *StringDest
723 )
724 {
725 UINTN StringSize;
726 UINT8 *StringPtr;
727
728 ASSERT (StringSrc != NULL && BufferSize != NULL && StringDest != NULL);
729
730 StringSize = sizeof (CHAR16);
731 StringPtr = StringSrc;
732 while (ReadUnaligned16 ((UINT16 *) StringPtr) != 0) {
733 StringSize += sizeof (CHAR16);
734 StringPtr += sizeof (CHAR16);
735 }
736
737 *StringDest = AllocatePool (StringSize);
738 if (*StringDest == NULL) {
739 return EFI_OUT_OF_RESOURCES;
740 }
741
742 CopyMem (*StringDest, StringSrc, StringSize);
743
744 *BufferSize = StringSize;
745 return EFI_SUCCESS;
746 }
747
748 /**
749 Find the string id for the input keyword.
750
751 @param StringPackage Hii string package instance.
752 @param KeywordValue Input keyword value.
753 @param StringId The string's id, which is unique within PackageList.
754
755
756 @retval EFI_SUCCESS The string text and font is retrieved
757 successfully.
758 @retval EFI_NOT_FOUND The specified text or font info can not be found
759 out.
760 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
761 task.
762 **/
763 EFI_STATUS
764 GetStringIdFromString (
765 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,
766 IN CHAR16 *KeywordValue,
767 OUT EFI_STRING_ID *StringId
768 )
769 {
770 UINT8 *BlockHdr;
771 EFI_STRING_ID CurrentStringId;
772 UINTN BlockSize;
773 UINTN Index;
774 UINT8 *StringTextPtr;
775 UINTN Offset;
776 UINT16 StringCount;
777 UINT16 SkipCount;
778 UINT8 Length8;
779 EFI_HII_SIBT_EXT2_BLOCK Ext2;
780 UINT32 Length32;
781 UINTN StringSize;
782 CHAR16 *String;
783 CHAR8 *AsciiKeywordValue;
784 UINTN KeywordValueSize;
785 EFI_STATUS Status;
786
787 ASSERT (StringPackage != NULL && KeywordValue != NULL && StringId != NULL);
788 ASSERT (StringPackage->Signature == HII_STRING_PACKAGE_SIGNATURE);
789
790 CurrentStringId = 1;
791 Status = EFI_SUCCESS;
792 String = NULL;
793 BlockHdr = StringPackage->StringBlock;
794 BlockSize = 0;
795 Offset = 0;
796
797 //
798 // Make a ascii keyword value for later use.
799 //
800 KeywordValueSize = StrLen (KeywordValue) + 1;
801 AsciiKeywordValue = AllocatePool (KeywordValueSize);
802 if (AsciiKeywordValue == NULL) {
803 return EFI_OUT_OF_RESOURCES;
804 }
805 UnicodeStrToAsciiStrS (KeywordValue, AsciiKeywordValue, KeywordValueSize);
806
807 while (*BlockHdr != EFI_HII_SIBT_END) {
808 switch (*BlockHdr) {
809 case EFI_HII_SIBT_STRING_SCSU:
810 Offset = sizeof (EFI_HII_STRING_BLOCK);
811 StringTextPtr = BlockHdr + Offset;
812 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);
813 if (AsciiStrCmp(AsciiKeywordValue, (CHAR8 *) StringTextPtr) == 0) {
814 *StringId = CurrentStringId;
815 goto Done;
816 }
817 CurrentStringId++;
818 break;
819
820 case EFI_HII_SIBT_STRING_SCSU_FONT:
821 Offset = sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - sizeof (UINT8);
822 StringTextPtr = BlockHdr + Offset;
823 if (AsciiStrCmp(AsciiKeywordValue, (CHAR8 *) StringTextPtr) == 0) {
824 *StringId = CurrentStringId;
825 goto Done;
826 }
827 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);
828 CurrentStringId++;
829 break;
830
831 case EFI_HII_SIBT_STRINGS_SCSU:
832 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
833 StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8));
834 BlockSize += StringTextPtr - BlockHdr;
835
836 for (Index = 0; Index < StringCount; Index++) {
837 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
838 if (AsciiStrCmp(AsciiKeywordValue, (CHAR8 *) StringTextPtr) == 0) {
839 *StringId = CurrentStringId;
840 goto Done;
841 }
842 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);
843 CurrentStringId++;
844 }
845 break;
846
847 case EFI_HII_SIBT_STRINGS_SCSU_FONT:
848 CopyMem (
849 &StringCount,
850 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
851 sizeof (UINT16)
852 );
853 StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8));
854 BlockSize += StringTextPtr - BlockHdr;
855
856 for (Index = 0; Index < StringCount; Index++) {
857 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
858 if (AsciiStrCmp(AsciiKeywordValue, (CHAR8 *) StringTextPtr) == 0) {
859 *StringId = CurrentStringId;
860 goto Done;
861 }
862 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);
863 CurrentStringId++;
864 }
865 break;
866
867 case EFI_HII_SIBT_STRING_UCS2:
868 Offset = sizeof (EFI_HII_STRING_BLOCK);
869 StringTextPtr = BlockHdr + Offset;
870 //
871 // Use StringSize to store the size of the specified string, including the NULL
872 // terminator.
873 //
874 Status = GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
875 if (EFI_ERROR (Status)) {
876 goto Done;
877 }
878 ASSERT (String != NULL);
879 if (StrCmp(KeywordValue, String) == 0) {
880 *StringId = CurrentStringId;
881 goto Done;
882 }
883 BlockSize += Offset + StringSize;
884 CurrentStringId++;
885 break;
886
887 case EFI_HII_SIBT_STRING_UCS2_FONT:
888 Offset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);
889 StringTextPtr = BlockHdr + Offset;
890 //
891 // Use StringSize to store the size of the specified string, including the NULL
892 // terminator.
893 //
894 Status = GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
895 if (EFI_ERROR (Status)) {
896 goto Done;
897 }
898 ASSERT (String != NULL);
899 if (StrCmp(KeywordValue, String) == 0) {
900 *StringId = CurrentStringId;
901 goto Done;
902 }
903 BlockSize += Offset + StringSize;
904 CurrentStringId++;
905 break;
906
907 case EFI_HII_SIBT_STRINGS_UCS2:
908 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeof (CHAR16);
909 StringTextPtr = BlockHdr + Offset;
910 BlockSize += Offset;
911 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
912 for (Index = 0; Index < StringCount; Index++) {
913 Status = GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
914 if (EFI_ERROR (Status)) {
915 goto Done;
916 }
917 ASSERT (String != NULL);
918 BlockSize += StringSize;
919 if (StrCmp(KeywordValue, String) == 0) {
920 *StringId = CurrentStringId;
921 goto Done;
922 }
923 StringTextPtr = StringTextPtr + StringSize;
924 CurrentStringId++;
925 }
926 break;
927
928 case EFI_HII_SIBT_STRINGS_UCS2_FONT:
929 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - sizeof (CHAR16);
930 StringTextPtr = BlockHdr + Offset;
931 BlockSize += Offset;
932 CopyMem (
933 &StringCount,
934 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
935 sizeof (UINT16)
936 );
937 for (Index = 0; Index < StringCount; Index++) {
938 Status = GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
939 if (EFI_ERROR (Status)) {
940 goto Done;
941 }
942 ASSERT (String != NULL);
943 BlockSize += StringSize;
944 if (StrCmp(KeywordValue, String) == 0) {
945 *StringId = CurrentStringId;
946 goto Done;
947 }
948 StringTextPtr = StringTextPtr + StringSize;
949 CurrentStringId++;
950 }
951 break;
952
953 case EFI_HII_SIBT_DUPLICATE:
954 BlockSize += sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK);
955 CurrentStringId++;
956 break;
957
958 case EFI_HII_SIBT_SKIP1:
959 SkipCount = (UINT16) (*(UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK)));
960 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
961 BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK);
962 break;
963
964 case EFI_HII_SIBT_SKIP2:
965 CopyMem (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
966 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
967 BlockSize += sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
968 break;
969
970 case EFI_HII_SIBT_EXT1:
971 CopyMem (
972 &Length8,
973 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
974 sizeof (UINT8)
975 );
976 BlockSize += Length8;
977 break;
978
979 case EFI_HII_SIBT_EXT2:
980 CopyMem (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK));
981 BlockSize += Ext2.Length;
982 break;
983
984 case EFI_HII_SIBT_EXT4:
985 CopyMem (
986 &Length32,
987 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
988 sizeof (UINT32)
989 );
990
991 BlockSize += Length32;
992 break;
993
994 default:
995 break;
996 }
997
998 if (String != NULL) {
999 FreePool (String);
1000 String = NULL;
1001 }
1002
1003 BlockHdr = StringPackage->StringBlock + BlockSize;
1004 }
1005
1006 Status = EFI_NOT_FOUND;
1007
1008 Done:
1009 if (AsciiKeywordValue != NULL) {
1010 FreePool (AsciiKeywordValue);
1011 }
1012 if (String != NULL) {
1013 FreePool (String);
1014 }
1015 return Status;
1016 }
1017
1018 /**
1019 Find the next valid string id for the input string id.
1020
1021 @param StringPackage Hii string package instance.
1022 @param StringId The current string id which is already got.
1023 1 means just begin to get the string id.
1024 @param KeywordValue Return the string for the next string id.
1025
1026
1027 @retval EFI_STRING_ID Not 0 means a valid stringid found.
1028 0 means not found a valid string id.
1029 **/
1030 EFI_STRING_ID
1031 GetNextStringId (
1032 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,
1033 IN EFI_STRING_ID StringId,
1034 OUT EFI_STRING *KeywordValue
1035 )
1036 {
1037 UINT8 *BlockHdr;
1038 EFI_STRING_ID CurrentStringId;
1039 UINTN BlockSize;
1040 UINTN Index;
1041 UINT8 *StringTextPtr;
1042 UINTN Offset;
1043 UINT16 StringCount;
1044 UINT16 SkipCount;
1045 UINT8 Length8;
1046 EFI_HII_SIBT_EXT2_BLOCK Ext2;
1047 UINT32 Length32;
1048 BOOLEAN FindString;
1049 UINTN StringSize;
1050 CHAR16 *String;
1051
1052 ASSERT (StringPackage != NULL);
1053 ASSERT (StringPackage->Signature == HII_STRING_PACKAGE_SIGNATURE);
1054
1055 CurrentStringId = 1;
1056 FindString = FALSE;
1057 String = NULL;
1058
1059 //
1060 // Parse the string blocks to get the string text and font.
1061 //
1062 BlockHdr = StringPackage->StringBlock;
1063 BlockSize = 0;
1064 Offset = 0;
1065 while (*BlockHdr != EFI_HII_SIBT_END) {
1066 switch (*BlockHdr) {
1067 case EFI_HII_SIBT_STRING_SCSU:
1068 Offset = sizeof (EFI_HII_STRING_BLOCK);
1069 StringTextPtr = BlockHdr + Offset;
1070
1071 if (FindString) {
1072 StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);
1073 *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));
1074 if (*KeywordValue == NULL) {
1075 return 0;
1076 }
1077 AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);
1078 return CurrentStringId;
1079 } else if (CurrentStringId == StringId) {
1080 FindString = TRUE;
1081 }
1082
1083 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);
1084 CurrentStringId++;
1085 break;
1086
1087 case EFI_HII_SIBT_STRING_SCSU_FONT:
1088 Offset = sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - sizeof (UINT8);
1089 StringTextPtr = BlockHdr + Offset;
1090
1091 if (FindString) {
1092 StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);
1093 *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));
1094 if (*KeywordValue == NULL) {
1095 return 0;
1096 }
1097 AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);
1098 return CurrentStringId;
1099 } else if (CurrentStringId == StringId) {
1100 FindString = TRUE;
1101 }
1102
1103 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);
1104 CurrentStringId++;
1105 break;
1106
1107 case EFI_HII_SIBT_STRINGS_SCSU:
1108 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
1109 StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8));
1110 BlockSize += StringTextPtr - BlockHdr;
1111
1112 for (Index = 0; Index < StringCount; Index++) {
1113 if (FindString) {
1114 StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);
1115 *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));
1116 if (*KeywordValue == NULL) {
1117 return 0;
1118 }
1119 AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);
1120 return CurrentStringId;
1121 } else if (CurrentStringId == StringId) {
1122 FindString = TRUE;
1123 }
1124
1125 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
1126 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);
1127 CurrentStringId++;
1128 }
1129 break;
1130
1131 case EFI_HII_SIBT_STRINGS_SCSU_FONT:
1132 CopyMem (
1133 &StringCount,
1134 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
1135 sizeof (UINT16)
1136 );
1137 StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8));
1138 BlockSize += StringTextPtr - BlockHdr;
1139
1140 for (Index = 0; Index < StringCount; Index++) {
1141 if (FindString) {
1142 StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);
1143 *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));
1144 if (*KeywordValue == NULL) {
1145 return 0;
1146 }
1147 AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);
1148 return CurrentStringId;
1149 } else if (CurrentStringId == StringId) {
1150 FindString = TRUE;
1151 }
1152
1153 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
1154 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);
1155 CurrentStringId++;
1156 }
1157 break;
1158
1159 case EFI_HII_SIBT_STRING_UCS2:
1160 Offset = sizeof (EFI_HII_STRING_BLOCK);
1161 StringTextPtr = BlockHdr + Offset;
1162 //
1163 // Use StringSize to store the size of the specified string, including the NULL
1164 // terminator.
1165 //
1166 GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
1167 if (FindString && (String != NULL) && (*String != L'\0')) {
1168 //
1169 // String protocol use this type for the string id which has value for other package.
1170 // It will allocate an empty string block for this string id. so here we also check
1171 // *String != L'\0' to prohibit this case.
1172 //
1173 *KeywordValue = String;
1174 return CurrentStringId;
1175 } else if (CurrentStringId == StringId) {
1176 FindString = TRUE;
1177 }
1178
1179 BlockSize += Offset + StringSize;
1180 CurrentStringId++;
1181 break;
1182
1183 case EFI_HII_SIBT_STRING_UCS2_FONT:
1184 Offset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);
1185 StringTextPtr = BlockHdr + Offset;
1186 //
1187 // Use StringSize to store the size of the specified string, including the NULL
1188 // terminator.
1189 //
1190 GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
1191 if (FindString) {
1192 *KeywordValue = String;
1193 return CurrentStringId;
1194 } else if (CurrentStringId == StringId) {
1195 FindString = TRUE;
1196 }
1197
1198 BlockSize += Offset + StringSize;
1199 CurrentStringId++;
1200 break;
1201
1202 case EFI_HII_SIBT_STRINGS_UCS2:
1203 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeof (CHAR16);
1204 StringTextPtr = BlockHdr + Offset;
1205 BlockSize += Offset;
1206 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
1207 for (Index = 0; Index < StringCount; Index++) {
1208 GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
1209
1210 if (FindString) {
1211 *KeywordValue = String;
1212 return CurrentStringId;
1213 } else if (CurrentStringId == StringId) {
1214 FindString = TRUE;
1215 }
1216
1217 BlockSize += StringSize;
1218 StringTextPtr = StringTextPtr + StringSize;
1219 CurrentStringId++;
1220 }
1221 break;
1222
1223 case EFI_HII_SIBT_STRINGS_UCS2_FONT:
1224 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - sizeof (CHAR16);
1225 StringTextPtr = BlockHdr + Offset;
1226 BlockSize += Offset;
1227 CopyMem (
1228 &StringCount,
1229 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
1230 sizeof (UINT16)
1231 );
1232 for (Index = 0; Index < StringCount; Index++) {
1233 GetUnicodeStringTextAndSize (StringTextPtr, &StringSize, &String);
1234 if (FindString) {
1235 *KeywordValue = String;
1236 return CurrentStringId;
1237 } else if (CurrentStringId == StringId) {
1238 FindString = TRUE;
1239 }
1240
1241 BlockSize += StringSize;
1242 StringTextPtr = StringTextPtr + StringSize;
1243 CurrentStringId++;
1244 }
1245 break;
1246
1247 case EFI_HII_SIBT_DUPLICATE:
1248 BlockSize += sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK);
1249 CurrentStringId++;
1250 break;
1251
1252 case EFI_HII_SIBT_SKIP1:
1253 SkipCount = (UINT16) (*(UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK)));
1254 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
1255 BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK);
1256 break;
1257
1258 case EFI_HII_SIBT_SKIP2:
1259 CopyMem (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
1260 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
1261 BlockSize += sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
1262 break;
1263
1264 case EFI_HII_SIBT_EXT1:
1265 CopyMem (
1266 &Length8,
1267 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
1268 sizeof (UINT8)
1269 );
1270 BlockSize += Length8;
1271 break;
1272
1273 case EFI_HII_SIBT_EXT2:
1274 CopyMem (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK));
1275 BlockSize += Ext2.Length;
1276 break;
1277
1278 case EFI_HII_SIBT_EXT4:
1279 CopyMem (
1280 &Length32,
1281 (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
1282 sizeof (UINT32)
1283 );
1284
1285 BlockSize += Length32;
1286 break;
1287
1288 default:
1289 break;
1290 }
1291
1292 if (String != NULL) {
1293 FreePool (String);
1294 String = NULL;
1295 }
1296
1297 BlockHdr = StringPackage->StringBlock + BlockSize;
1298 }
1299
1300 return 0;
1301 }
1302
1303 /**
1304 Get string package from the input NameSpace string.
1305
1306 This is a internal function.
1307
1308 @param DatabaseRecord HII_DATABASE_RECORD format string.
1309 @param NameSpace NameSpace format string.
1310 @param KeywordValue Keyword value.
1311 @param StringId String Id for this keyword.
1312
1313 @retval KEYWORD_HANDLER_NO_ERROR Get String id successfully.
1314 @retval KEYWORD_HANDLER_KEYWORD_NOT_FOUND Not found the string id in the string package.
1315 @retval KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND Not found the string package for this namespace.
1316 @retval KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR Out of resource error.
1317
1318 **/
1319 UINT32
1320 GetStringIdFromRecord (
1321 IN HII_DATABASE_RECORD *DatabaseRecord,
1322 IN CHAR8 **NameSpace,
1323 IN CHAR16 *KeywordValue,
1324 OUT EFI_STRING_ID *StringId
1325 )
1326 {
1327 LIST_ENTRY *Link;
1328 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
1329 HII_STRING_PACKAGE_INSTANCE *StringPackage;
1330 EFI_STATUS Status;
1331 CHAR8 *Name;
1332 UINT32 RetVal;
1333
1334 ASSERT (DatabaseRecord != NULL && NameSpace != NULL && KeywordValue != NULL);
1335
1336 PackageListNode = DatabaseRecord->PackageList;
1337 RetVal = KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND;
1338
1339 if (*NameSpace != NULL) {
1340 Name = *NameSpace;
1341 } else {
1342 Name = UEFI_CONFIG_LANG;
1343 }
1344
1345 for (Link = PackageListNode->StringPkgHdr.ForwardLink; Link != &PackageListNode->StringPkgHdr; Link = Link->ForwardLink) {
1346 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1347
1348 if (AsciiStrnCmp(Name, StringPackage->StringPkgHdr->Language, AsciiStrLen (Name)) == 0) {
1349 Status = GetStringIdFromString (StringPackage, KeywordValue, StringId);
1350 if (EFI_ERROR (Status)) {
1351 return KEYWORD_HANDLER_KEYWORD_NOT_FOUND;
1352 } else {
1353 if (*NameSpace == NULL) {
1354 *NameSpace = AllocateCopyPool (AsciiStrSize (StringPackage->StringPkgHdr->Language), StringPackage->StringPkgHdr->Language);
1355 if (*NameSpace == NULL) {
1356 return KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR;
1357 }
1358 }
1359 return KEYWORD_HANDLER_NO_ERROR;
1360 }
1361 }
1362 }
1363
1364 return RetVal;
1365 }
1366
1367 /**
1368 Tell whether this Operand is an Statement OpCode.
1369
1370 @param Operand Operand of an IFR OpCode.
1371
1372 @retval TRUE This is an Statement OpCode.
1373 @retval FALSE Not an Statement OpCode.
1374
1375 **/
1376 BOOLEAN
1377 IsStatementOpCode (
1378 IN UINT8 Operand
1379 )
1380 {
1381 if ((Operand == EFI_IFR_SUBTITLE_OP) ||
1382 (Operand == EFI_IFR_TEXT_OP) ||
1383 (Operand == EFI_IFR_RESET_BUTTON_OP) ||
1384 (Operand == EFI_IFR_REF_OP) ||
1385 (Operand == EFI_IFR_ACTION_OP) ||
1386 (Operand == EFI_IFR_NUMERIC_OP) ||
1387 (Operand == EFI_IFR_ORDERED_LIST_OP) ||
1388 (Operand == EFI_IFR_CHECKBOX_OP) ||
1389 (Operand == EFI_IFR_STRING_OP) ||
1390 (Operand == EFI_IFR_PASSWORD_OP) ||
1391 (Operand == EFI_IFR_DATE_OP) ||
1392 (Operand == EFI_IFR_TIME_OP) ||
1393 (Operand == EFI_IFR_GUID_OP) ||
1394 (Operand == EFI_IFR_ONE_OF_OP)) {
1395 return TRUE;
1396 }
1397
1398 return FALSE;
1399 }
1400
1401 /**
1402 Tell whether this Operand is an Statement OpCode.
1403
1404 @param Operand Operand of an IFR OpCode.
1405
1406 @retval TRUE This is an Statement OpCode.
1407 @retval FALSE Not an Statement OpCode.
1408
1409 **/
1410 BOOLEAN
1411 IsStorageOpCode (
1412 IN UINT8 Operand
1413 )
1414 {
1415 if ((Operand == EFI_IFR_VARSTORE_OP) ||
1416 (Operand == EFI_IFR_VARSTORE_NAME_VALUE_OP) ||
1417 (Operand == EFI_IFR_VARSTORE_EFI_OP)) {
1418 return TRUE;
1419 }
1420
1421 return FALSE;
1422 }
1423
1424 /**
1425 Base on the prompt string id to find the question.
1426
1427 @param FormPackage The input form package.
1428 @param KeywordStrId The input prompt string id for one question.
1429
1430 @retval the opcode for the question.
1431
1432 **/
1433 UINT8 *
1434 FindQuestionFromStringId (
1435 IN HII_IFR_PACKAGE_INSTANCE *FormPackage,
1436 IN EFI_STRING_ID KeywordStrId
1437 )
1438 {
1439 UINT8 *OpCodeData;
1440 UINT32 Offset;
1441 EFI_IFR_STATEMENT_HEADER *StatementHeader;
1442 EFI_IFR_OP_HEADER *OpCodeHeader;
1443 UINT32 FormDataLen;
1444
1445 ASSERT (FormPackage != NULL);
1446
1447 FormDataLen = FormPackage->FormPkgHdr.Length - sizeof (EFI_HII_PACKAGE_HEADER);
1448 Offset = 0;
1449 while (Offset < FormDataLen) {
1450 OpCodeData = FormPackage->IfrData + Offset;
1451 OpCodeHeader = (EFI_IFR_OP_HEADER *) OpCodeData;
1452
1453 if (IsStatementOpCode(OpCodeHeader->OpCode)) {
1454 StatementHeader = (EFI_IFR_STATEMENT_HEADER *) (OpCodeData + sizeof (EFI_IFR_OP_HEADER));
1455 if (StatementHeader->Prompt == KeywordStrId) {
1456 return OpCodeData;
1457 }
1458 }
1459
1460 Offset += OpCodeHeader->Length;
1461 }
1462
1463 return NULL;
1464 }
1465
1466 /**
1467 Base on the varstore id to find the storage info.
1468
1469 @param FormPackage The input form package.
1470 @param VarStoreId The input storage id.
1471
1472 @retval the opcode for the storage.
1473
1474 **/
1475 UINT8 *
1476 FindStorageFromVarId (
1477 IN HII_IFR_PACKAGE_INSTANCE *FormPackage,
1478 IN EFI_VARSTORE_ID VarStoreId
1479 )
1480 {
1481 UINT8 *OpCodeData;
1482 UINT32 Offset;
1483 EFI_IFR_OP_HEADER *OpCodeHeader;
1484 UINT32 FormDataLen;
1485
1486 ASSERT (FormPackage != NULL);
1487
1488 FormDataLen = FormPackage->FormPkgHdr.Length - sizeof (EFI_HII_PACKAGE_HEADER);
1489 Offset = 0;
1490 while (Offset < FormDataLen) {
1491 OpCodeData = FormPackage->IfrData + Offset;
1492 OpCodeHeader = (EFI_IFR_OP_HEADER *) OpCodeData;
1493
1494 if (IsStorageOpCode(OpCodeHeader->OpCode)) {
1495 switch (OpCodeHeader->OpCode) {
1496 case EFI_IFR_VARSTORE_OP:
1497 if (VarStoreId == ((EFI_IFR_VARSTORE *) OpCodeData)->VarStoreId) {
1498 return OpCodeData;
1499 }
1500 break;
1501
1502 case EFI_IFR_VARSTORE_NAME_VALUE_OP:
1503 if (VarStoreId == ((EFI_IFR_VARSTORE_NAME_VALUE *) OpCodeData)->VarStoreId) {
1504 return OpCodeData;
1505 }
1506 break;
1507
1508 case EFI_IFR_VARSTORE_EFI_OP:
1509 if (VarStoreId == ((EFI_IFR_VARSTORE_EFI *) OpCodeData)->VarStoreId) {
1510 return OpCodeData;
1511 }
1512 break;
1513
1514 default:
1515 break;
1516 }
1517 }
1518
1519 Offset += OpCodeHeader->Length;
1520 }
1521
1522 return NULL;
1523 }
1524
1525 /**
1526 Get width info for one question.
1527
1528 @param OpCodeData The input opcode for one question.
1529
1530 @retval the width info for one question.
1531
1532 **/
1533 UINT16
1534 GetWidth (
1535 IN UINT8 *OpCodeData
1536 )
1537 {
1538 UINT8 *NextOpCodeData;
1539
1540 ASSERT (OpCodeData != NULL);
1541
1542 switch (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode) {
1543 case EFI_IFR_REF_OP:
1544 return (UINT16) sizeof (EFI_HII_REF);
1545
1546 case EFI_IFR_ONE_OF_OP:
1547 case EFI_IFR_NUMERIC_OP:
1548 switch (((EFI_IFR_ONE_OF *) OpCodeData)->Flags & EFI_IFR_NUMERIC_SIZE) {
1549 case EFI_IFR_NUMERIC_SIZE_1:
1550 return (UINT16) sizeof (UINT8);
1551
1552 case EFI_IFR_NUMERIC_SIZE_2:
1553 return (UINT16) sizeof (UINT16);
1554
1555 case EFI_IFR_NUMERIC_SIZE_4:
1556 return (UINT16) sizeof (UINT32);
1557
1558 case EFI_IFR_NUMERIC_SIZE_8:
1559 return (UINT16) sizeof (UINT64);
1560
1561 default:
1562 ASSERT (FALSE);
1563 return 0;
1564 }
1565
1566 case EFI_IFR_ORDERED_LIST_OP:
1567 NextOpCodeData = OpCodeData + ((EFI_IFR_ORDERED_LIST *) OpCodeData)->Header.Length;
1568 //
1569 // OneOfOption must follow the orderedlist opcode.
1570 //
1571 ASSERT (((EFI_IFR_OP_HEADER *) NextOpCodeData)->OpCode == EFI_IFR_ONE_OF_OPTION_OP);
1572 switch (((EFI_IFR_ONE_OF_OPTION *) NextOpCodeData)->Type) {
1573 case EFI_IFR_TYPE_NUM_SIZE_8:
1574 return (UINT16) sizeof (UINT8) * ((EFI_IFR_ORDERED_LIST *) OpCodeData)->MaxContainers;
1575
1576 case EFI_IFR_TYPE_NUM_SIZE_16:
1577 return (UINT16) sizeof (UINT16) * ((EFI_IFR_ORDERED_LIST *) OpCodeData)->MaxContainers ;
1578
1579 case EFI_IFR_TYPE_NUM_SIZE_32:
1580 return (UINT16) sizeof (UINT32) * ((EFI_IFR_ORDERED_LIST *) OpCodeData)->MaxContainers;
1581
1582 case EFI_IFR_TYPE_NUM_SIZE_64:
1583 return (UINT16) sizeof (UINT64) * ((EFI_IFR_ORDERED_LIST *) OpCodeData)->MaxContainers;
1584
1585 default:
1586 ASSERT (FALSE);
1587 return 0;
1588 }
1589
1590 case EFI_IFR_CHECKBOX_OP:
1591 return (UINT16) sizeof (BOOLEAN);
1592
1593 case EFI_IFR_PASSWORD_OP:
1594 return (UINT16)((UINTN) ((EFI_IFR_PASSWORD *) OpCodeData)->MaxSize * sizeof (CHAR16));
1595
1596 case EFI_IFR_STRING_OP:
1597 return (UINT16)((UINTN) ((EFI_IFR_STRING *) OpCodeData)->MaxSize * sizeof (CHAR16));
1598
1599 case EFI_IFR_DATE_OP:
1600 return (UINT16) sizeof (EFI_HII_DATE);
1601
1602 case EFI_IFR_TIME_OP:
1603 return (UINT16) sizeof (EFI_HII_TIME);
1604
1605 default:
1606 ASSERT (FALSE);
1607 return 0;
1608 }
1609 }
1610
1611 /**
1612 Converts all hex string characters in range ['A'..'F'] to ['a'..'f'] for
1613 hex digits that appear between a '=' and a '&' in a config string.
1614
1615 If ConfigString is NULL, then ASSERT().
1616
1617 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
1618
1619 @return Pointer to the Null-terminated Unicode result string.
1620
1621 **/
1622 EFI_STRING
1623 EFIAPI
1624 InternalLowerConfigString (
1625 IN EFI_STRING ConfigString
1626 )
1627 {
1628 EFI_STRING String;
1629 BOOLEAN Lower;
1630
1631 ASSERT (ConfigString != NULL);
1632
1633 //
1634 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1635 //
1636 for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) {
1637 if (*String == L'=') {
1638 Lower = TRUE;
1639 } else if (*String == L'&') {
1640 Lower = FALSE;
1641 } else if (Lower && *String >= L'A' && *String <= L'F') {
1642 *String = (CHAR16) (*String - L'A' + L'a');
1643 }
1644 }
1645
1646 return ConfigString;
1647 }
1648
1649 /**
1650 Allocates and returns a Null-terminated Unicode <ConfigHdr> string.
1651
1652 The format of a <ConfigHdr> is as follows:
1653
1654 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
1655
1656 @param[in] OpCodeData The opcode for the storage.
1657 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
1658 that is the routing information PATH. Each byte of
1659 the Device Path associated with DriverHandle is converted
1660 to a 2 Unicode character hexadecimal string.
1661
1662 @retval NULL DriverHandle does not support the Device Path Protocol.
1663 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
1664
1665 **/
1666 EFI_STRING
1667 ConstructConfigHdr (
1668 IN UINT8 *OpCodeData,
1669 IN EFI_HANDLE DriverHandle
1670 )
1671 {
1672 UINTN NameLength;
1673 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
1674 UINTN DevicePathSize;
1675 CHAR16 *String;
1676 CHAR16 *ReturnString;
1677 UINTN Index;
1678 UINT8 *Buffer;
1679 CHAR16 *Name;
1680 CHAR8 *AsciiName;
1681 UINTN NameSize;
1682 EFI_GUID *Guid;
1683 UINTN MaxLen;
1684
1685 ASSERT (OpCodeData != NULL);
1686
1687 switch (((EFI_IFR_OP_HEADER *)OpCodeData)->OpCode) {
1688 case EFI_IFR_VARSTORE_OP:
1689 Guid = (EFI_GUID *)(UINTN *)&((EFI_IFR_VARSTORE *) OpCodeData)->Guid;
1690 AsciiName = (CHAR8 *) ((EFI_IFR_VARSTORE *) OpCodeData)->Name;
1691 break;
1692
1693 case EFI_IFR_VARSTORE_NAME_VALUE_OP:
1694 Guid = (EFI_GUID *)(UINTN *)&((EFI_IFR_VARSTORE_NAME_VALUE *) OpCodeData)->Guid;
1695 AsciiName = NULL;
1696 break;
1697
1698 case EFI_IFR_VARSTORE_EFI_OP:
1699 Guid = (EFI_GUID *)(UINTN *)&((EFI_IFR_VARSTORE_EFI *) OpCodeData)->Guid;
1700 AsciiName = (CHAR8 *) ((EFI_IFR_VARSTORE_EFI *) OpCodeData)->Name;
1701 break;
1702
1703 default:
1704 ASSERT (FALSE);
1705 Guid = NULL;
1706 AsciiName = NULL;
1707 break;
1708 }
1709
1710 if (AsciiName != NULL) {
1711 NameSize = AsciiStrSize (AsciiName);
1712 Name = AllocateZeroPool (NameSize * sizeof (CHAR16));
1713 ASSERT (Name != NULL);
1714 AsciiStrToUnicodeStrS (AsciiName, Name, NameSize);
1715 } else {
1716 Name = NULL;
1717 }
1718
1719 //
1720 // Compute the length of Name in Unicode characters.
1721 // If Name is NULL, then the length is 0.
1722 //
1723 NameLength = 0;
1724 if (Name != NULL) {
1725 NameLength = StrLen (Name);
1726 }
1727
1728 DevicePath = NULL;
1729 DevicePathSize = 0;
1730 //
1731 // Retrieve DevicePath Protocol associated with DriverHandle
1732 //
1733 if (DriverHandle != NULL) {
1734 DevicePath = DevicePathFromHandle (DriverHandle);
1735 if (DevicePath == NULL) {
1736 return NULL;
1737 }
1738 //
1739 // Compute the size of the device path in bytes
1740 //
1741 DevicePathSize = GetDevicePathSize (DevicePath);
1742 }
1743
1744 //
1745 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
1746 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
1747 //
1748 MaxLen = 5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1;
1749 String = AllocateZeroPool (MaxLen * sizeof (CHAR16));
1750 if (String == NULL) {
1751 return NULL;
1752 }
1753
1754 //
1755 // Start with L"GUID="
1756 //
1757 StrCpyS (String, MaxLen, L"GUID=");
1758 ReturnString = String;
1759 String += StrLen (String);
1760
1761 if (Guid != NULL) {
1762 //
1763 // Append Guid converted to <HexCh>32
1764 //
1765 for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {
1766 UnicodeValueToStringS (
1767 String,
1768 MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),
1769 PREFIX_ZERO | RADIX_HEX,
1770 *(Buffer++),
1771 2
1772 );
1773 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));
1774 }
1775 }
1776
1777 //
1778 // Append L"&NAME="
1779 //
1780 StrCatS (ReturnString, MaxLen, L"&NAME=");
1781 String += StrLen (String);
1782
1783 if (Name != NULL) {
1784 //
1785 // Append Name converted to <Char>NameLength
1786 //
1787 for (; *Name != L'\0'; Name++) {
1788 UnicodeValueToStringS (
1789 String,
1790 MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),
1791 PREFIX_ZERO | RADIX_HEX,
1792 *Name,
1793 4
1794 );
1795 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));
1796 }
1797 }
1798
1799 //
1800 // Append L"&PATH="
1801 //
1802 StrCatS (ReturnString, MaxLen, L"&PATH=");
1803 String += StrLen (String);
1804
1805 //
1806 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
1807 //
1808 for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {
1809 UnicodeValueToStringS (
1810 String,
1811 MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),
1812 PREFIX_ZERO | RADIX_HEX,
1813 *(Buffer++),
1814 2
1815 );
1816 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));
1817 }
1818
1819 //
1820 // Null terminate the Unicode string
1821 //
1822 *String = L'\0';
1823
1824 //
1825 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
1826 //
1827 return InternalLowerConfigString (ReturnString);
1828 }
1829
1830 /**
1831 Generate the Config request element for one question.
1832
1833 @param Name The name info for one question.
1834 @param Offset The offset info for one question.
1835 @param Width The width info for one question.
1836
1837 @return Pointer to the Null-terminated Unicode request element string.
1838
1839 **/
1840 EFI_STRING
1841 ConstructRequestElement (
1842 IN CHAR16 *Name,
1843 IN UINT16 Offset,
1844 IN UINT16 Width
1845 )
1846 {
1847 CHAR16 *StringPtr;
1848 UINTN Length;
1849
1850 if (Name != NULL) {
1851 //
1852 // Add <BlockName> length for each Name
1853 //
1854 // <BlockName> ::= Name + \0
1855 // StrLen(Name) | 1
1856 //
1857 Length = StrLen (Name) + 1;
1858 } else {
1859 //
1860 // Add <BlockName> length for each Offset/Width pair
1861 //
1862 // <BlockName> ::= OFFSET=1234&WIDTH=1234 + \0
1863 // | 7 | 4 | 7 | 4 | 1
1864 //
1865 Length = (7 + 4 + 7 + 4 + 1);
1866 }
1867
1868 //
1869 // Allocate buffer for the entire <ConfigRequest>
1870 //
1871 StringPtr = AllocateZeroPool (Length * sizeof (CHAR16));
1872 ASSERT (StringPtr != NULL);
1873
1874 if (Name != NULL) {
1875 //
1876 // Append Name\0
1877 //
1878 UnicodeSPrint (
1879 StringPtr,
1880 (StrLen (Name) + 1) * sizeof (CHAR16),
1881 L"%s",
1882 Name
1883 );
1884 } else {
1885 //
1886 // Append OFFSET=XXXX&WIDTH=YYYY\0
1887 //
1888 UnicodeSPrint (
1889 StringPtr,
1890 (7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
1891 L"OFFSET=%04X&WIDTH=%04X",
1892 Offset,
1893 Width
1894 );
1895 }
1896
1897 return StringPtr;
1898 }
1899
1900 /**
1901 Get string value for question's name field.
1902
1903 @param DatabaseRecord HII_DATABASE_RECORD format string.
1904 @param NameId The string id for the name field.
1905
1906 @retval Name string.
1907
1908 **/
1909 CHAR16 *
1910 GetNameFromId (
1911 IN HII_DATABASE_RECORD *DatabaseRecord,
1912 IN EFI_STRING_ID NameId
1913 )
1914 {
1915 CHAR16 *Name;
1916 CHAR8 *PlatformLanguage;
1917 CHAR8 *SupportedLanguages;
1918 CHAR8 *BestLanguage;
1919 UINTN StringSize;
1920 CHAR16 TempString;
1921 EFI_STATUS Status;
1922
1923 Name = NULL;
1924 BestLanguage = NULL;
1925 PlatformLanguage = NULL;
1926 SupportedLanguages = NULL;
1927
1928 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);
1929 SupportedLanguages = GetSupportedLanguages(DatabaseRecord->Handle);
1930
1931 //
1932 // Get the best matching language from SupportedLanguages
1933 //
1934 BestLanguage = GetBestLanguage (
1935 SupportedLanguages,
1936 FALSE, // RFC 4646 mode
1937 PlatformLanguage != NULL ? PlatformLanguage : "", // Highest priority
1938 SupportedLanguages, // Lowest priority
1939 NULL
1940 );
1941 if (BestLanguage == NULL) {
1942 BestLanguage = AllocateCopyPool (AsciiStrLen ("en-US"), "en-US");
1943 ASSERT (BestLanguage != NULL);
1944 }
1945
1946 StringSize = 0;
1947 Status = mPrivate.HiiString.GetString (
1948 &mPrivate.HiiString,
1949 BestLanguage,
1950 DatabaseRecord->Handle,
1951 NameId,
1952 &TempString,
1953 &StringSize,
1954 NULL
1955 );
1956 if (Status != EFI_BUFFER_TOO_SMALL) {
1957 goto Done;
1958 }
1959
1960 Name = AllocateZeroPool (StringSize);
1961 if (Name == NULL) {
1962 goto Done;
1963 }
1964
1965 Status = mPrivate.HiiString.GetString (
1966 &mPrivate.HiiString,
1967 BestLanguage,
1968 DatabaseRecord->Handle,
1969 NameId,
1970 Name,
1971 &StringSize,
1972 NULL
1973 );
1974
1975 if (EFI_ERROR (Status)) {
1976 FreePool (Name);
1977 Name = NULL;
1978 goto Done;
1979 }
1980
1981 Done:
1982 if (SupportedLanguages != NULL) {
1983 FreePool(SupportedLanguages);
1984 }
1985 if (BestLanguage != NULL) {
1986 FreePool (BestLanguage);
1987 }
1988 if (PlatformLanguage != NULL) {
1989 FreePool (PlatformLanguage);
1990 }
1991
1992 return Name;
1993 }
1994
1995 /**
1996 Base on the input parameter to generate the ConfigRequest string.
1997
1998 This is a internal function.
1999
2000 @param DatabaseRecord HII_DATABASE_RECORD format string.
2001 @param KeywordStrId Keyword string id.
2002 @param OpCodeData The IFR data for this question.
2003 @param ConfigRequest Return the generate ConfigRequest string.
2004
2005 @retval EFI_SUCCESS Generate ConfigResp string success.
2006 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
2007 @retval EFI_NOT_FOUND Not found the question which use this string id
2008 as the prompt string id.
2009 **/
2010 EFI_STATUS
2011 ExtractConfigRequest (
2012 IN HII_DATABASE_RECORD *DatabaseRecord,
2013 IN EFI_STRING_ID KeywordStrId,
2014 OUT UINT8 **OpCodeData,
2015 OUT EFI_STRING *ConfigRequest
2016 )
2017 {
2018 LIST_ENTRY *Link;
2019 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
2020 HII_IFR_PACKAGE_INSTANCE *FormPackage;
2021 EFI_IFR_QUESTION_HEADER *Header;
2022 UINT8 *Storage;
2023 UINT8 *OpCode;
2024 CHAR16 *Name;
2025 UINT16 Offset;
2026 UINT16 Width;
2027 CHAR16 *ConfigHdr;
2028 CHAR16 *RequestElement;
2029 UINTN MaxLen;
2030 CHAR16 *StringPtr;
2031
2032 ASSERT (DatabaseRecord != NULL && OpCodeData != NULL && ConfigRequest != NULL);
2033
2034 OpCode = NULL;
2035 Name = NULL;
2036 Width = 0;
2037 Offset = 0;
2038
2039 PackageListNode = DatabaseRecord->PackageList;
2040
2041 //
2042 // Search the languages in the specified packagelist.
2043 //
2044 for (Link = PackageListNode->FormPkgHdr.ForwardLink; Link != &PackageListNode->FormPkgHdr; Link = Link->ForwardLink) {
2045 FormPackage = CR (Link, HII_IFR_PACKAGE_INSTANCE, IfrEntry, HII_IFR_PACKAGE_SIGNATURE);
2046
2047 OpCode = FindQuestionFromStringId (FormPackage, KeywordStrId);
2048 if (OpCode != NULL) {
2049 *OpCodeData = OpCode;
2050 Header = (EFI_IFR_QUESTION_HEADER *) (OpCode + sizeof (EFI_IFR_OP_HEADER));
2051 //
2052 // Header->VarStoreId == 0 means no storage for this question.
2053 //
2054 ASSERT (Header->VarStoreId != 0);
2055 DEBUG ((EFI_D_INFO, "Varstore Id: 0x%x\n", Header->VarStoreId));
2056
2057 Storage = FindStorageFromVarId (FormPackage, Header->VarStoreId);
2058 ASSERT (Storage != NULL);
2059
2060 if (((EFI_IFR_OP_HEADER *) Storage)->OpCode == EFI_IFR_VARSTORE_NAME_VALUE_OP) {
2061 Name = GetNameFromId (DatabaseRecord, Header->VarStoreInfo.VarName);
2062 } else {
2063 Offset = Header->VarStoreInfo.VarOffset;
2064 Width = GetWidth (OpCode);
2065 }
2066 RequestElement = ConstructRequestElement(Name, Offset, Width);
2067 ConfigHdr = ConstructConfigHdr(Storage, DatabaseRecord->DriverHandle);
2068 ASSERT (ConfigHdr != NULL);
2069
2070 MaxLen = StrLen (ConfigHdr) + 1 + StrLen(RequestElement) + 1;
2071 *ConfigRequest = AllocatePool (MaxLen * sizeof (CHAR16));
2072 if (*ConfigRequest == NULL) {
2073 FreePool (ConfigHdr);
2074 FreePool (RequestElement);
2075 return EFI_OUT_OF_RESOURCES;
2076 }
2077 StringPtr = *ConfigRequest;
2078
2079 StrCpyS (StringPtr, MaxLen, ConfigHdr);
2080
2081 StrCatS (StringPtr, MaxLen, L"&");
2082
2083 StrCatS (StringPtr, MaxLen, RequestElement);
2084
2085 FreePool (ConfigHdr);
2086 FreePool (RequestElement);
2087
2088 return EFI_SUCCESS;
2089 }
2090 }
2091
2092 return EFI_NOT_FOUND;
2093 }
2094
2095 /**
2096 Base on the input parameter to generate the ConfigResp string.
2097
2098 This is a internal function.
2099
2100 @param DatabaseRecord HII_DATABASE_RECORD format string.
2101 @param KeywordStrId Keyword string id.
2102 @param ValueElement The value for the question which use keyword string id
2103 as the prompt string id.
2104 @param OpCodeData The IFR data for this question.
2105 @param ConfigResp Return the generate ConfigResp string.
2106
2107 @retval EFI_SUCCESS Generate ConfigResp string success.
2108 @retval EFI_OUT_OF_RESOURCES System out of memory resource error.
2109 @retval EFI_NOT_FOUND Not found the question which use this string id
2110 as the prompt string id.
2111 **/
2112 EFI_STATUS
2113 ExtractConfigResp (
2114 IN HII_DATABASE_RECORD *DatabaseRecord,
2115 IN EFI_STRING_ID KeywordStrId,
2116 IN EFI_STRING ValueElement,
2117 OUT UINT8 **OpCodeData,
2118 OUT EFI_STRING *ConfigResp
2119 )
2120 {
2121 LIST_ENTRY *Link;
2122 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
2123 HII_IFR_PACKAGE_INSTANCE *FormPackage;
2124 EFI_IFR_QUESTION_HEADER *Header;
2125 UINT8 *Storage;
2126 UINT8 *OpCode;
2127 CHAR16 *Name;
2128 UINT16 Offset;
2129 UINT16 Width;
2130 CHAR16 *ConfigHdr;
2131 CHAR16 *RequestElement;
2132 UINTN MaxLen;
2133 CHAR16 *StringPtr;
2134
2135 ASSERT ((DatabaseRecord != NULL) && (OpCodeData != NULL) && (ConfigResp != NULL) && (ValueElement != NULL));
2136
2137 OpCode = NULL;
2138 Name = NULL;
2139 Width = 0;
2140 Offset = 0;
2141
2142 PackageListNode = DatabaseRecord->PackageList;
2143
2144 //
2145 // Search the languages in the specified packagelist.
2146 //
2147 for (Link = PackageListNode->FormPkgHdr.ForwardLink; Link != &PackageListNode->FormPkgHdr; Link = Link->ForwardLink) {
2148 FormPackage = CR (Link, HII_IFR_PACKAGE_INSTANCE, IfrEntry, HII_IFR_PACKAGE_SIGNATURE);
2149
2150 OpCode = FindQuestionFromStringId (FormPackage, KeywordStrId);
2151 if (OpCode != NULL) {
2152 *OpCodeData = OpCode;
2153 Header = (EFI_IFR_QUESTION_HEADER *) (OpCode + sizeof (EFI_IFR_OP_HEADER));
2154 //
2155 // Header->VarStoreId == 0 means no storage for this question.
2156 //
2157 ASSERT (Header->VarStoreId != 0);
2158 DEBUG ((EFI_D_INFO, "Varstore Id: 0x%x\n", Header->VarStoreId));
2159
2160 Storage = FindStorageFromVarId (FormPackage, Header->VarStoreId);
2161 ASSERT (Storage != NULL);
2162
2163 if (((EFI_IFR_OP_HEADER *) Storage)->OpCode == EFI_IFR_VARSTORE_NAME_VALUE_OP) {
2164 Name = GetNameFromId (DatabaseRecord, Header->VarStoreInfo.VarName);
2165 } else {
2166 Offset = Header->VarStoreInfo.VarOffset;
2167 Width = GetWidth (OpCode);
2168 }
2169 RequestElement = ConstructRequestElement(Name, Offset, Width);
2170
2171 ConfigHdr = ConstructConfigHdr(Storage, DatabaseRecord->DriverHandle);
2172 ASSERT (ConfigHdr != NULL);
2173
2174 MaxLen = StrLen (ConfigHdr) + 1 + StrLen(RequestElement) + 1 + StrLen (L"VALUE=") + StrLen(ValueElement) + 1;
2175 *ConfigResp = AllocatePool (MaxLen * sizeof (CHAR16));
2176 if (*ConfigResp == NULL) {
2177 FreePool (ConfigHdr);
2178 FreePool (RequestElement);
2179 return EFI_OUT_OF_RESOURCES;
2180 }
2181 StringPtr = *ConfigResp;
2182
2183 StrCpyS (StringPtr, MaxLen, ConfigHdr);
2184
2185 StrCatS (StringPtr, MaxLen, L"&");
2186
2187
2188 StrCatS (StringPtr, MaxLen, RequestElement);
2189
2190 StrCatS (StringPtr, MaxLen, L"&");
2191
2192 StrCatS (StringPtr, MaxLen, L"VALUE=");
2193
2194 StrCatS (StringPtr, MaxLen, ValueElement);
2195
2196 FreePool (ConfigHdr);
2197 FreePool (RequestElement);
2198
2199 return EFI_SUCCESS;
2200 }
2201 }
2202
2203 return EFI_NOT_FOUND;
2204 }
2205
2206 /**
2207 Get the Value section from the Hii driver.
2208
2209 This is a internal function.
2210
2211 @param ConfigRequest The input ConfigRequest string.
2212 @param ValueElement The respond Value section from the hii driver.
2213
2214 @retval Misc value The error status return from ExtractConfig function.
2215 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated
2216 @retval EFI_SUCCESS Get the value section success.
2217
2218 **/
2219 EFI_STATUS
2220 ExtractValueFromDriver (
2221 IN CHAR16 *ConfigRequest,
2222 OUT CHAR16 **ValueElement
2223 )
2224 {
2225 EFI_STATUS Status;
2226 EFI_STRING Result;
2227 EFI_STRING Progress;
2228 CHAR16 *StringPtr;
2229 CHAR16 *StringEnd;
2230
2231 ASSERT ((ConfigRequest != NULL) && (ValueElement != NULL));
2232
2233 Status = mPrivate.ConfigRouting.ExtractConfig (
2234 &mPrivate.ConfigRouting,
2235 (EFI_STRING) ConfigRequest,
2236 &Progress,
2237 &Result
2238 );
2239 if (EFI_ERROR (Status)) {
2240 return Status;
2241 }
2242
2243 //
2244 // Find Value Section and return it.
2245 //
2246 StringPtr = StrStr (Result, L"&VALUE=");
2247 ASSERT (StringPtr != NULL);
2248 StringEnd = StrStr (StringPtr + 1, L"&");
2249 if (StringEnd != NULL) {
2250 *StringEnd = L'\0';
2251 }
2252
2253 *ValueElement = AllocateCopyPool (StrSize (StringPtr), StringPtr);
2254 if (*ValueElement == NULL) {
2255 return EFI_OUT_OF_RESOURCES;
2256 }
2257
2258 if (StringEnd != NULL) {
2259 *StringEnd = L'&';
2260 }
2261 FreePool (Result);
2262
2263 return EFI_SUCCESS;
2264 }
2265
2266 /**
2267 Get EFI_STRING_ID info from the input device path, namespace and keyword.
2268
2269 This is a internal function.
2270
2271 @param DevicePath Input device path info.
2272 @param NameSpace NameSpace format string.
2273 @param KeywordData Keyword used to get string id.
2274 @param ProgressErr Return extra error type.
2275 @param KeywordStringId Return EFI_STRING_ID.
2276 @param DataBaseRecord DataBase record data for this driver.
2277
2278 @retval EFI_INVALID_PARAMETER Can't find the database record base on the input device path or namespace.
2279 @retval EFI_NOT_FOUND Can't find the EFI_STRING_ID for the keyword.
2280 @retval EFI_SUCCESS Find the EFI_STRING_ID.
2281
2282 **/
2283 EFI_STATUS
2284 GetStringIdFromDatabase (
2285 IN EFI_DEVICE_PATH_PROTOCOL **DevicePath,
2286 IN CHAR8 **NameSpace,
2287 IN CHAR16 *KeywordData,
2288 OUT UINT32 *ProgressErr,
2289 OUT EFI_STRING_ID *KeywordStringId,
2290 OUT HII_DATABASE_RECORD **DataBaseRecord
2291 )
2292 {
2293 HII_DATABASE_RECORD *Record;
2294 LIST_ENTRY *Link;
2295 BOOLEAN FindNameSpace;
2296 EFI_DEVICE_PATH_PROTOCOL *DestDevicePath;
2297 UINT8 *DevicePathPkg;
2298 UINTN DevicePathSize;
2299
2300 ASSERT ((NameSpace != NULL) && (KeywordData != NULL) && (ProgressErr != NULL) && (KeywordStringId != NULL) && (DataBaseRecord != NULL));
2301
2302 FindNameSpace = FALSE;
2303
2304 if (*DevicePath != NULL) {
2305 //
2306 // Get DataBaseRecord from device path protocol.
2307 //
2308 Record = GetRecordFromDevicePath(*DevicePath);
2309 if (Record == NULL) {
2310 //
2311 // Can't find the DatabaseRecord base on the input device path info.
2312 // NEED TO CONFIRM the return ProgressErr.
2313 //
2314 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2315 return EFI_INVALID_PARAMETER;
2316 }
2317
2318 //
2319 // Get string id from the record.
2320 //
2321 *ProgressErr = GetStringIdFromRecord (Record, NameSpace, KeywordData, KeywordStringId);
2322 switch (*ProgressErr) {
2323 case KEYWORD_HANDLER_NO_ERROR:
2324 *DataBaseRecord = Record;
2325 return EFI_SUCCESS;
2326
2327 case KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND:
2328 return EFI_INVALID_PARAMETER;
2329
2330 default:
2331 ASSERT (*ProgressErr == KEYWORD_HANDLER_KEYWORD_NOT_FOUND);
2332 return EFI_NOT_FOUND;
2333 }
2334 } else {
2335 //
2336 // Find driver which matches the routing data.
2337 //
2338 for (Link = mPrivate.DatabaseList.ForwardLink; Link != &mPrivate.DatabaseList; Link = Link->ForwardLink) {
2339 Record = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
2340
2341 *ProgressErr = GetStringIdFromRecord (Record, NameSpace, KeywordData, KeywordStringId);
2342 if (*ProgressErr == KEYWORD_HANDLER_NO_ERROR) {
2343 *DataBaseRecord = Record;
2344
2345 if ((DevicePathPkg = Record->PackageList->DevicePathPkg) != NULL) {
2346 DestDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) (DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER));
2347 DevicePathSize = GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DestDevicePath);
2348 *DevicePath = AllocateCopyPool (DevicePathSize, DestDevicePath);
2349 if (*DevicePath == NULL) {
2350 return EFI_OUT_OF_RESOURCES;
2351 }
2352 } else {
2353 //
2354 // Need to verify this ASSERT.
2355 //
2356 ASSERT (FALSE);
2357 }
2358
2359 return EFI_SUCCESS;
2360 } else if (*ProgressErr == KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR) {
2361 return EFI_OUT_OF_RESOURCES;
2362 } else if (*ProgressErr == KEYWORD_HANDLER_KEYWORD_NOT_FOUND) {
2363 FindNameSpace = TRUE;
2364 }
2365 }
2366
2367 //
2368 // When PathHdr not input, if ever find the namespace, will return KEYWORD_HANDLER_KEYWORD_NOT_FOUND.
2369 // This is a bit more progress than KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND.
2370 //
2371 if (FindNameSpace) {
2372 return EFI_NOT_FOUND;
2373 } else {
2374 return EFI_INVALID_PARAMETER;
2375 }
2376 }
2377 }
2378
2379 /**
2380 Generate the KeywordResp String.
2381
2382 <KeywordResp> ::= <NameSpaceId><PathHdr>'&'<Keyword>'&VALUE='<Number>['&READONLY']
2383
2384 @param NameSpace NameSpace format string.
2385 @param DevicePath Input device path info.
2386 @param KeywordData Keyword used to get string id.
2387 @param ValueStr The value section for the keyword.
2388 @param ReadOnly Whether this value is readonly.
2389 @param KeywordResp Return the point to the KeywordResp string.
2390
2391 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2392 @retval EFI_SUCCESS Generate the KeywordResp string.
2393
2394 **/
2395 EFI_STATUS
2396 GenerateKeywordResp (
2397 IN CHAR8 *NameSpace,
2398 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
2399 IN EFI_STRING KeywordData,
2400 IN EFI_STRING ValueStr,
2401 IN BOOLEAN ReadOnly,
2402 OUT EFI_STRING *KeywordResp
2403 )
2404 {
2405 UINTN RespStrLen;
2406 CHAR16 *RespStr;
2407 CHAR16 *PathHdr;
2408 CHAR16 *UnicodeNameSpace;
2409 UINTN NameSpaceLength;
2410
2411 ASSERT ((NameSpace != NULL) && (DevicePath != NULL) && (KeywordData != NULL) && (ValueStr != NULL) && (KeywordResp != NULL));
2412
2413 //
2414 // 1. Calculate the string length.
2415 //
2416 //
2417 // 1.1 NameSpaceId size.
2418 // 'NAMESPACE='<String>
2419 //
2420 NameSpaceLength = AsciiStrLen (NameSpace);
2421 RespStrLen = 10 + NameSpaceLength;
2422 UnicodeNameSpace = AllocatePool ((NameSpaceLength + 1) * sizeof (CHAR16));
2423 if (UnicodeNameSpace == NULL) {
2424 return EFI_OUT_OF_RESOURCES;
2425 }
2426 AsciiStrToUnicodeStrS (NameSpace, UnicodeNameSpace, NameSpaceLength + 1);
2427
2428 //
2429 // 1.2 PathHdr size.
2430 // PATH=<UEFI binary Device Path represented as hex number>'&'
2431 // Attention: The output include the '&' at the end.
2432 //
2433 GenerateSubStr (
2434 L"&PATH=",
2435 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),
2436 (VOID *) DevicePath,
2437 1,
2438 &PathHdr
2439 );
2440 RespStrLen += StrLen (PathHdr);
2441
2442 //
2443 // 1.3 Keyword section.
2444 // 'KEYWORD='<String>[':'<DecCh>(1/4)]
2445 //
2446 RespStrLen += 8 + StrLen (KeywordData);
2447
2448 //
2449 // 1.4 Value section.
2450 // ValueStr = '&VALUE='<Number>
2451 //
2452 RespStrLen += StrLen (ValueStr);
2453
2454 //
2455 // 1.5 ReadOnly Section.
2456 // '&READONLY'
2457 //
2458 if (ReadOnly) {
2459 RespStrLen += 9;
2460 }
2461
2462 //
2463 // 2. Allocate the buffer and create the KeywordResp string include '\0'.
2464 //
2465 RespStrLen += 1;
2466 *KeywordResp = AllocatePool (RespStrLen * sizeof (CHAR16));
2467 if (*KeywordResp == NULL) {
2468 if (UnicodeNameSpace != NULL) {
2469 FreePool (UnicodeNameSpace);
2470 }
2471
2472 return EFI_OUT_OF_RESOURCES;
2473 }
2474 RespStr = *KeywordResp;
2475
2476 //
2477 // 2.1 Copy NameSpaceId section.
2478 //
2479 StrCpyS (RespStr, RespStrLen, L"NAMESPACE=");
2480
2481 StrCatS (RespStr, RespStrLen, UnicodeNameSpace);
2482
2483 //
2484 // 2.2 Copy PathHdr section.
2485 //
2486 StrCatS (RespStr, RespStrLen, PathHdr);
2487
2488 //
2489 // 2.3 Copy Keyword section.
2490 //
2491 StrCatS (RespStr, RespStrLen, L"KEYWORD=");
2492
2493 StrCatS (RespStr, RespStrLen, KeywordData);
2494
2495 //
2496 // 2.4 Copy the Value section.
2497 //
2498 StrCatS (RespStr, RespStrLen, ValueStr);
2499
2500 //
2501 // 2.5 Copy ReadOnly section if exist.
2502 //
2503 if (ReadOnly) {
2504 StrCatS (RespStr, RespStrLen, L"&READONLY");
2505 }
2506
2507 if (UnicodeNameSpace != NULL) {
2508 FreePool (UnicodeNameSpace);
2509 }
2510 if (PathHdr != NULL) {
2511 FreePool (PathHdr);
2512 }
2513
2514 return EFI_SUCCESS;
2515 }
2516
2517 /**
2518 Merge the KeywordResp String to MultiKeywordResp string.
2519
2520 This is a internal function.
2521
2522 @param MultiKeywordResp The existed multikeywordresp string.
2523 @param KeywordResp The input keywordResp string.
2524
2525 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2526 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2527
2528 **/
2529 EFI_STATUS
2530 MergeToMultiKeywordResp (
2531 IN OUT EFI_STRING *MultiKeywordResp,
2532 IN EFI_STRING *KeywordResp
2533 )
2534 {
2535 UINTN MultiKeywordRespLen;
2536 EFI_STRING StringPtr;
2537
2538 if (*MultiKeywordResp == NULL) {
2539 *MultiKeywordResp = *KeywordResp;
2540 *KeywordResp = NULL;
2541 return EFI_SUCCESS;
2542 }
2543
2544 MultiKeywordRespLen = (StrLen (*MultiKeywordResp) + 1 + StrLen (*KeywordResp) + 1) * sizeof (CHAR16);
2545
2546 StringPtr = AllocateCopyPool (MultiKeywordRespLen, *MultiKeywordResp);
2547 if (StringPtr == NULL) {
2548 return EFI_OUT_OF_RESOURCES;
2549 }
2550
2551 FreePool (*MultiKeywordResp);
2552 *MultiKeywordResp = StringPtr;
2553
2554 StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), L"&");
2555
2556 StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), *KeywordResp);
2557
2558 return EFI_SUCCESS;
2559 }
2560
2561 /**
2562 Enumerate all keyword in the system.
2563
2564 If error occur when parse one keyword, just skip it and parse the next one.
2565
2566 This is a internal function.
2567
2568 @param NameSpace The namespace used to search the string.
2569 @param MultiResp Return the MultiKeywordResp string for the system.
2570 @param ProgressErr Return the error status.
2571
2572 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2573 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2574 @retval EFI_NOT_FOUND No keyword found.
2575
2576 **/
2577 EFI_STATUS
2578 EnumerateAllKeywords (
2579 IN CHAR8 *NameSpace,
2580 OUT EFI_STRING *MultiResp,
2581 OUT UINT32 *ProgressErr
2582 )
2583 {
2584 LIST_ENTRY *Link;
2585 LIST_ENTRY *StringLink;
2586 UINT8 *DevicePathPkg;
2587 UINT8 *DevicePath;
2588 HII_DATABASE_RECORD *DataBaseRecord;
2589 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
2590 HII_STRING_PACKAGE_INSTANCE *StringPackage;
2591 CHAR8 *LocalNameSpace;
2592 EFI_STRING_ID NextStringId;
2593 EFI_STATUS Status;
2594 UINT8 *OpCode;
2595 CHAR16 *ConfigRequest;
2596 CHAR16 *ValueElement;
2597 CHAR16 *KeywordResp;
2598 CHAR16 *MultiKeywordResp;
2599 CHAR16 *KeywordData;
2600 BOOLEAN ReadOnly;
2601 BOOLEAN FindKeywordPackages;
2602
2603 DataBaseRecord = NULL;
2604 Status = EFI_SUCCESS;
2605 MultiKeywordResp = NULL;
2606 DevicePath = NULL;
2607 LocalNameSpace = NULL;
2608 ConfigRequest = NULL;
2609 ValueElement = NULL;
2610 KeywordResp = NULL;
2611 FindKeywordPackages = FALSE;
2612
2613 if (NameSpace == NULL) {
2614 NameSpace = UEFI_CONFIG_LANG;
2615 }
2616
2617 //
2618 // Find driver which matches the routing data.
2619 //
2620 for (Link = mPrivate.DatabaseList.ForwardLink; Link != &mPrivate.DatabaseList; Link = Link->ForwardLink) {
2621 DataBaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
2622 if ((DevicePathPkg = DataBaseRecord->PackageList->DevicePathPkg) != NULL) {
2623 DevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);
2624 }
2625 PackageListNode = DataBaseRecord->PackageList;
2626
2627 for (StringLink = PackageListNode->StringPkgHdr.ForwardLink; StringLink != &PackageListNode->StringPkgHdr; StringLink = StringLink->ForwardLink) {
2628 StringPackage = CR (StringLink, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
2629
2630 //
2631 // Check whether has keyword string package.
2632 //
2633 if (AsciiStrnCmp(NameSpace, StringPackage->StringPkgHdr->Language, AsciiStrLen (NameSpace)) == 0) {
2634 FindKeywordPackages = TRUE;
2635 //
2636 // Keep the NameSpace string.
2637 //
2638 LocalNameSpace = AllocateCopyPool (AsciiStrSize (StringPackage->StringPkgHdr->Language), StringPackage->StringPkgHdr->Language);
2639 if (LocalNameSpace == NULL) {
2640 return EFI_OUT_OF_RESOURCES;
2641 }
2642
2643 //
2644 // 1 means just begin the enumerate the valid string ids.
2645 // StringId == 1 is always used to save the language for this string package.
2646 // Any valid string start from 2. so here initial it to 1.
2647 //
2648 NextStringId = 1;
2649
2650 //
2651 // Enumerate all valid stringid in the package.
2652 //
2653 while ((NextStringId = GetNextStringId (StringPackage, NextStringId, &KeywordData)) != 0) {
2654 //
2655 // 3.3 Construct the ConfigRequest string.
2656 //
2657 Status = ExtractConfigRequest (DataBaseRecord, NextStringId, &OpCode, &ConfigRequest);
2658 if (EFI_ERROR (Status)) {
2659 //
2660 // If can't generate ConfigRequest for this question, skip it and start the next.
2661 //
2662 goto Error;
2663 }
2664
2665 //
2666 // 3.4 Extract Value for the input keyword.
2667 //
2668 Status = ExtractValueFromDriver(ConfigRequest, &ValueElement);
2669 if (EFI_ERROR (Status)) {
2670 if (Status != EFI_OUT_OF_RESOURCES) {
2671 //
2672 // If can't generate ConfigRequest for this question, skip it and start the next.
2673 //
2674 goto Error;
2675 }
2676 //
2677 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2678 //
2679 goto Done;
2680 }
2681
2682 //
2683 // Extract readonly flag from opcode.
2684 //
2685 ReadOnly = ExtractReadOnlyFromOpCode(OpCode);
2686
2687 //
2688 // 5. Generate KeywordResp string.
2689 //
2690 ASSERT (DevicePath != NULL);
2691 Status = GenerateKeywordResp(LocalNameSpace, (EFI_DEVICE_PATH_PROTOCOL *)DevicePath, KeywordData, ValueElement, ReadOnly, &KeywordResp);
2692 if (Status != EFI_SUCCESS) {
2693 //
2694 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2695 //
2696 goto Done;
2697 }
2698
2699 //
2700 // 6. Merge to the MultiKeywordResp string.
2701 //
2702 Status = MergeToMultiKeywordResp(&MultiKeywordResp, &KeywordResp);
2703 if (EFI_ERROR (Status)) {
2704 goto Done;
2705 }
2706 Error:
2707 //
2708 // Clean the temp buffer to later use again.
2709 //
2710 if (ConfigRequest != NULL) {
2711 FreePool (ConfigRequest);
2712 ConfigRequest = NULL;
2713 }
2714 if (ValueElement != NULL) {
2715 FreePool (ValueElement);
2716 ValueElement = NULL;
2717 }
2718 if (KeywordResp != NULL) {
2719 FreePool (KeywordResp);
2720 KeywordResp = NULL;
2721 }
2722 }
2723
2724 if (LocalNameSpace != NULL) {
2725 FreePool (LocalNameSpace);
2726 LocalNameSpace = NULL;
2727 }
2728 }
2729 }
2730 }
2731
2732 //
2733 // return the already get MultiKeywordString even error occurred.
2734 //
2735 if (MultiKeywordResp == NULL) {
2736 Status = EFI_NOT_FOUND;
2737 if (!FindKeywordPackages) {
2738 *ProgressErr = KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND;
2739 } else {
2740 *ProgressErr = KEYWORD_HANDLER_KEYWORD_NOT_FOUND;
2741 }
2742 } else {
2743 Status = EFI_SUCCESS;
2744 }
2745 *MultiResp = MultiKeywordResp;
2746
2747 Done:
2748 if (LocalNameSpace != NULL) {
2749 FreePool (LocalNameSpace);
2750 }
2751 if (ConfigRequest != NULL) {
2752 FreePool (ConfigRequest);
2753 }
2754 if (ValueElement != NULL) {
2755 FreePool (ValueElement);
2756 }
2757
2758 return Status;
2759 }
2760
2761 /**
2762
2763 This function accepts a <MultiKeywordResp> formatted string, finds the associated
2764 keyword owners, creates a <MultiConfigResp> string from it and forwards it to the
2765 EFI_HII_ROUTING_PROTOCOL.RouteConfig function.
2766
2767 If there is an issue in resolving the contents of the KeywordString, then the
2768 function returns an error and also sets the Progress and ProgressErr with the
2769 appropriate information about where the issue occurred and additional data about
2770 the nature of the issue.
2771
2772 In the case when KeywordString containing multiple keywords, when an EFI_NOT_FOUND
2773 error is generated during processing the second or later keyword element, the system
2774 storage associated with earlier keywords is not modified. All elements of the
2775 KeywordString must successfully pass all tests for format and access prior to making
2776 any modifications to storage.
2777
2778 In the case when EFI_DEVICE_ERROR is returned from the processing of a KeywordString
2779 containing multiple keywords, the state of storage associated with earlier keywords
2780 is undefined.
2781
2782
2783 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
2784
2785 @param KeywordString A null-terminated string in <MultiKeywordResp> format.
2786
2787 @param Progress On return, points to a character in the KeywordString.
2788 Points to the string's NULL terminator if the request
2789 was successful. Points to the most recent '&' before
2790 the first failing name / value pair (or the beginning
2791 of the string if the failure is in the first name / value
2792 pair) if the request was not successful.
2793
2794 @param ProgressErr If during the processing of the KeywordString there was
2795 a failure, this parameter gives additional information
2796 about the possible source of the problem. The various
2797 errors are defined in "Related Definitions" below.
2798
2799
2800 @retval EFI_SUCCESS The specified action was completed successfully.
2801
2802 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
2803 1. KeywordString is NULL.
2804 2. Parsing of the KeywordString resulted in an
2805 error. See Progress and ProgressErr for more data.
2806
2807 @retval EFI_NOT_FOUND An element of the KeywordString was not found.
2808 See ProgressErr for more data.
2809
2810 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2811 See ProgressErr for more data.
2812
2813 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr
2814 for more data.
2815
2816 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
2817 for more data.
2818
2819 **/
2820 EFI_STATUS
2821 EFIAPI
2822 EfiConfigKeywordHandlerSetData (
2823 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *This,
2824 IN CONST EFI_STRING KeywordString,
2825 OUT EFI_STRING *Progress,
2826 OUT UINT32 *ProgressErr
2827 )
2828 {
2829 CHAR8 *NameSpace;
2830 EFI_STATUS Status;
2831 CHAR16 *StringPtr;
2832 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
2833 CHAR16 *NextStringPtr;
2834 CHAR16 *KeywordData;
2835 EFI_STRING_ID KeywordStringId;
2836 UINT32 RetVal;
2837 HII_DATABASE_RECORD *DataBaseRecord;
2838 UINT8 *OpCode;
2839 CHAR16 *ConfigResp;
2840 CHAR16 *MultiConfigResp;
2841 CHAR16 *ValueElement;
2842 BOOLEAN ReadOnly;
2843 EFI_STRING InternalProgress;
2844 CHAR16 *TempString;
2845 CHAR16 *KeywordStartPos;
2846
2847 if (This == NULL || Progress == NULL || ProgressErr == NULL || KeywordString == NULL) {
2848 return EFI_INVALID_PARAMETER;
2849 }
2850
2851 *Progress = KeywordString;
2852 *ProgressErr = KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR;
2853 Status = EFI_SUCCESS;
2854 MultiConfigResp = NULL;
2855 NameSpace = NULL;
2856 DevicePath = NULL;
2857 KeywordData = NULL;
2858 ValueElement = NULL;
2859 ConfigResp = NULL;
2860 KeywordStartPos = NULL;
2861 KeywordStringId = 0;
2862
2863 //
2864 // Use temp string to avoid changing input string buffer.
2865 //
2866 TempString = AllocateCopyPool (StrSize (KeywordString), KeywordString);
2867 ASSERT (TempString != NULL);
2868 StringPtr = TempString;
2869
2870 while ((StringPtr != NULL) && (*StringPtr != L'\0')) {
2871 //
2872 // 1. Get NameSpace from NameSpaceId keyword.
2873 //
2874 Status = ExtractNameSpace (StringPtr, &NameSpace, &NextStringPtr);
2875 if (EFI_ERROR (Status)) {
2876 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2877 goto Done;
2878 }
2879 ASSERT (NameSpace != NULL);
2880 //
2881 // 1.1 Check whether the input namespace is valid.
2882 //
2883 if (AsciiStrnCmp(NameSpace, UEFI_CONFIG_LANG, AsciiStrLen (UEFI_CONFIG_LANG)) != 0) {
2884 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2885 Status = EFI_INVALID_PARAMETER;
2886 goto Done;
2887 }
2888
2889 StringPtr = NextStringPtr;
2890
2891 //
2892 // 2. Get possible Device Path info from KeywordString.
2893 //
2894 Status = ExtractDevicePath (StringPtr, (UINT8 **)&DevicePath, &NextStringPtr);
2895 if (EFI_ERROR (Status)) {
2896 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2897 goto Done;
2898 }
2899 StringPtr = NextStringPtr;
2900
2901 //
2902 // 3. Extract keyword from the KeywordRequest string.
2903 //
2904 KeywordStartPos = StringPtr;
2905 Status = ExtractKeyword(StringPtr, &KeywordData, &NextStringPtr);
2906 if (EFI_ERROR (Status)) {
2907 //
2908 // Can't find Keyword base on the input device path info.
2909 //
2910 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2911 Status = EFI_INVALID_PARAMETER;
2912 goto Done;
2913 }
2914 StringPtr = NextStringPtr;
2915
2916 //
2917 // 4. Extract Value from the KeywordRequest string.
2918 //
2919 Status = ExtractValue (StringPtr, &ValueElement, &NextStringPtr);
2920 if (EFI_ERROR (Status)) {
2921 //
2922 // Can't find Value base on the input device path info.
2923 //
2924 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2925 Status = EFI_INVALID_PARAMETER;
2926 goto Done;
2927 }
2928 StringPtr = NextStringPtr;
2929
2930 //
2931 // 5. Find READONLY tag.
2932 //
2933 if ((StringPtr != NULL) && StrnCmp (StringPtr, L"&READONLY", StrLen (L"&READONLY")) == 0) {
2934 ReadOnly = TRUE;
2935 StringPtr += StrLen (L"&READONLY");
2936 } else {
2937 ReadOnly = FALSE;
2938 }
2939
2940 //
2941 // 6. Get EFI_STRING_ID for the input keyword.
2942 //
2943 Status = GetStringIdFromDatabase (&DevicePath, &NameSpace, KeywordData, &RetVal, &KeywordStringId, &DataBaseRecord);
2944 if (EFI_ERROR (Status)) {
2945 *ProgressErr = RetVal;
2946 goto Done;
2947 }
2948
2949 //
2950 // 7. Construct the ConfigRequest string.
2951 //
2952 Status = ExtractConfigResp (DataBaseRecord, KeywordStringId, ValueElement, &OpCode, &ConfigResp);
2953 if (EFI_ERROR (Status)) {
2954 goto Done;
2955 }
2956
2957 //
2958 // 8. Check the readonly flag.
2959 //
2960 if (ExtractReadOnlyFromOpCode (OpCode) != ReadOnly) {
2961 //
2962 // Extracting readonly flag form opcode and extracting "READONLY" tag form KeywordString should have the same results.
2963 // If not, the input KeywordString must be incorrect, return the error status to caller.
2964 //
2965 *ProgressErr = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
2966 Status = EFI_INVALID_PARAMETER;
2967 goto Done;
2968 }
2969 if (ReadOnly) {
2970 *ProgressErr = KEYWORD_HANDLER_ACCESS_NOT_PERMITTED;
2971 Status = EFI_ACCESS_DENIED;
2972 goto Done;
2973 }
2974
2975 //
2976 // 9. Merge to the MultiKeywordResp string.
2977 //
2978 Status = MergeToMultiKeywordResp(&MultiConfigResp, &ConfigResp);
2979 if (EFI_ERROR (Status)) {
2980 goto Done;
2981 }
2982
2983 //
2984 // 10. Clean the temp buffer point.
2985 //
2986 FreePool (NameSpace);
2987 FreePool (DevicePath);
2988 FreePool (KeywordData);
2989 FreePool (ValueElement);
2990 NameSpace = NULL;
2991 DevicePath = NULL;
2992 KeywordData = NULL;
2993 ValueElement = NULL;
2994 if (ConfigResp != NULL) {
2995 FreePool (ConfigResp);
2996 ConfigResp = NULL;
2997 }
2998 KeywordStartPos = NULL;
2999 }
3000
3001 //
3002 // 11. Set value to driver.
3003 //
3004 Status = mPrivate.ConfigRouting.RouteConfig(
3005 &mPrivate.ConfigRouting,
3006 (EFI_STRING) MultiConfigResp,
3007 &InternalProgress
3008 );
3009 if (EFI_ERROR (Status)) {
3010 Status = EFI_DEVICE_ERROR;
3011 goto Done;
3012 }
3013
3014 *ProgressErr = KEYWORD_HANDLER_NO_ERROR;
3015
3016 Done:
3017 if (KeywordStartPos != NULL) {
3018 *Progress = KeywordString + (KeywordStartPos - TempString);
3019 } else {
3020 *Progress = KeywordString + (StringPtr - TempString);
3021 }
3022
3023 ASSERT (TempString != NULL);
3024 FreePool (TempString);
3025 if (NameSpace != NULL) {
3026 FreePool (NameSpace);
3027 }
3028 if (DevicePath != NULL) {
3029 FreePool (DevicePath);
3030 }
3031 if (KeywordData != NULL) {
3032 FreePool (KeywordData);
3033 }
3034 if (ValueElement != NULL) {
3035 FreePool (ValueElement);
3036 }
3037 if (ConfigResp != NULL) {
3038 FreePool (ConfigResp);
3039 }
3040 if (MultiConfigResp != NULL && MultiConfigResp != ConfigResp) {
3041 FreePool (MultiConfigResp);
3042 }
3043
3044 return Status;
3045 }
3046
3047 /**
3048
3049 This function accepts a <MultiKeywordRequest> formatted string, finds the underlying
3050 keyword owners, creates a <MultiConfigRequest> string from it and forwards it to the
3051 EFI_HII_ROUTING_PROTOCOL.ExtractConfig function.
3052
3053 If there is an issue in resolving the contents of the KeywordString, then the function
3054 returns an EFI_INVALID_PARAMETER and also set the Progress and ProgressErr with the
3055 appropriate information about where the issue occurred and additional data about the
3056 nature of the issue.
3057
3058 In the case when KeywordString is NULL, or contains multiple keywords, or when
3059 EFI_NOT_FOUND is generated while processing the keyword elements, the Results string
3060 contains values returned for all keywords processed prior to the keyword generating the
3061 error but no values for the keyword with error or any following keywords.
3062
3063
3064 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
3065
3066 @param NameSpaceId A null-terminated string containing the platform configuration
3067 language to search through in the system. If a NULL is passed
3068 in, then it is assumed that any platform configuration language
3069 with the prefix of "x-UEFI-" are searched.
3070
3071 @param KeywordString A null-terminated string in <MultiKeywordRequest> format. If a
3072 NULL is passed in the KeywordString field, all of the known
3073 keywords in the system for the NameSpaceId specified are
3074 returned in the Results field.
3075
3076 @param Progress On return, points to a character in the KeywordString. Points
3077 to the string's NULL terminator if the request was successful.
3078 Points to the most recent '&' before the first failing name / value
3079 pair (or the beginning of the string if the failure is in the first
3080 name / value pair) if the request was not successful.
3081
3082 @param ProgressErr If during the processing of the KeywordString there was a
3083 failure, this parameter gives additional information about the
3084 possible source of the problem. See the definitions in SetData()
3085 for valid value definitions.
3086
3087 @param Results A null-terminated string in <MultiKeywordResp> format is returned
3088 which has all the values filled in for the keywords in the
3089 KeywordString. This is a callee-allocated field, and must be freed
3090 by the caller after being used.
3091
3092 @retval EFI_SUCCESS The specified action was completed successfully.
3093
3094 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
3095 1.Progress, ProgressErr, or Results is NULL.
3096 2.Parsing of the KeywordString resulted in an error. See
3097 Progress and ProgressErr for more data.
3098
3099
3100 @retval EFI_NOT_FOUND An element of the KeywordString was not found. See
3101 ProgressErr for more data.
3102
3103 @retval EFI_NOT_FOUND The NamespaceId specified was not found. See ProgressErr
3104 for more data.
3105
3106 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated. See
3107 ProgressErr for more data.
3108
3109 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr for
3110 more data.
3111
3112 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
3113 for more data.
3114
3115 **/
3116 EFI_STATUS
3117 EFIAPI
3118 EfiConfigKeywordHandlerGetData (
3119 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *This,
3120 IN CONST EFI_STRING NameSpaceId, OPTIONAL
3121 IN CONST EFI_STRING KeywordString, OPTIONAL
3122 OUT EFI_STRING *Progress,
3123 OUT UINT32 *ProgressErr,
3124 OUT EFI_STRING *Results
3125 )
3126 {
3127 CHAR8 *NameSpace;
3128 EFI_STATUS Status;
3129 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
3130 HII_DATABASE_RECORD *DataBaseRecord;
3131 CHAR16 *StringPtr;
3132 CHAR16 *NextStringPtr;
3133 CHAR16 *KeywordData;
3134 EFI_STRING_ID KeywordStringId;
3135 UINT8 *OpCode;
3136 CHAR16 *ConfigRequest;
3137 CHAR16 *ValueElement;
3138 UINT32 RetVal;
3139 BOOLEAN ReadOnly;
3140 CHAR16 *KeywordResp;
3141 CHAR16 *MultiKeywordResp;
3142 CHAR16 *TempString;
3143
3144 if (This == NULL || Progress == NULL || ProgressErr == NULL || Results == NULL) {
3145 return EFI_INVALID_PARAMETER;
3146 }
3147
3148 *ProgressErr = KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR;
3149 Status = EFI_SUCCESS;
3150 DevicePath = NULL;
3151 NameSpace = NULL;
3152 KeywordData = NULL;
3153 ConfigRequest= NULL;
3154 StringPtr = KeywordString;
3155 ReadOnly = FALSE;
3156 MultiKeywordResp = NULL;
3157 KeywordStringId = 0;
3158 TempString = NULL;
3159
3160 //
3161 // Use temp string to avoid changing input string buffer.
3162 //
3163 if (NameSpaceId != NULL) {
3164 TempString = AllocateCopyPool (StrSize (NameSpaceId), NameSpaceId);
3165 ASSERT (TempString != NULL);
3166 }
3167 //
3168 // 1. Get NameSpace from NameSpaceId keyword.
3169 //
3170 Status = ExtractNameSpace (TempString, &NameSpace, NULL);
3171 if (TempString != NULL) {
3172 FreePool (TempString);
3173 TempString = NULL;
3174 }
3175 if (EFI_ERROR (Status)) {
3176 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3177 return Status;
3178 }
3179 //
3180 // 1.1 Check whether the input namespace is valid.
3181 //
3182 if (NameSpace != NULL){
3183 if (AsciiStrnCmp(NameSpace, UEFI_CONFIG_LANG, AsciiStrLen (UEFI_CONFIG_LANG)) != 0) {
3184 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3185 return EFI_INVALID_PARAMETER;
3186 }
3187 }
3188
3189 if (KeywordString != NULL) {
3190 //
3191 // Use temp string to avoid changing input string buffer.
3192 //
3193 TempString = AllocateCopyPool (StrSize (KeywordString), KeywordString);
3194 ASSERT (TempString != NULL);
3195 StringPtr = TempString;
3196
3197 while (*StringPtr != L'\0') {
3198 //
3199 // 2. Get possible Device Path info from KeywordString.
3200 //
3201 Status = ExtractDevicePath (StringPtr, (UINT8 **)&DevicePath, &NextStringPtr);
3202 if (EFI_ERROR (Status)) {
3203 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3204 goto Done;
3205 }
3206 StringPtr = NextStringPtr;
3207
3208
3209 //
3210 // 3. Process Keyword section from the input keywordRequest string.
3211 //
3212 // 3.1 Extract keyword from the KeywordRequest string.
3213 //
3214 Status = ExtractKeyword(StringPtr, &KeywordData, &NextStringPtr);
3215 if (EFI_ERROR (Status)) {
3216 //
3217 // Can't find Keyword base on the input device path info.
3218 //
3219 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3220 Status = EFI_INVALID_PARAMETER;
3221 goto Done;
3222 }
3223
3224 //
3225 // 3.2 Get EFI_STRING_ID for the input keyword.
3226 //
3227 Status = GetStringIdFromDatabase (&DevicePath, &NameSpace, KeywordData, &RetVal, &KeywordStringId, &DataBaseRecord);
3228 if (EFI_ERROR (Status)) {
3229 *ProgressErr = RetVal;
3230 goto Done;
3231 }
3232
3233 //
3234 // 3.3 Construct the ConfigRequest string.
3235 //
3236 Status = ExtractConfigRequest (DataBaseRecord, KeywordStringId, &OpCode, &ConfigRequest);
3237 if (EFI_ERROR (Status)) {
3238 goto Done;
3239 }
3240
3241 //
3242 // 3.4 Extract Value for the input keyword.
3243 //
3244 Status = ExtractValueFromDriver(ConfigRequest, &ValueElement);
3245 if (EFI_ERROR (Status)) {
3246 if (Status != EFI_OUT_OF_RESOURCES) {
3247 Status = EFI_DEVICE_ERROR;
3248 }
3249 goto Done;
3250 }
3251 StringPtr = NextStringPtr;
3252
3253 //
3254 // 4. Process the possible filter section.
3255 //
3256 RetVal = ValidateFilter (OpCode, StringPtr, &NextStringPtr, &ReadOnly);
3257 if (RetVal != KEYWORD_HANDLER_NO_ERROR) {
3258 *ProgressErr = RetVal;
3259 Status = EFI_INVALID_PARAMETER;
3260 goto Done;
3261 }
3262 StringPtr = NextStringPtr;
3263
3264
3265 //
3266 // 5. Generate KeywordResp string.
3267 //
3268 Status = GenerateKeywordResp(NameSpace, DevicePath, KeywordData, ValueElement, ReadOnly, &KeywordResp);
3269 if (Status != EFI_SUCCESS) {
3270 goto Done;
3271 }
3272
3273 //
3274 // 6. Merge to the MultiKeywordResp string.
3275 //
3276 Status = MergeToMultiKeywordResp(&MultiKeywordResp, &KeywordResp);
3277 if (EFI_ERROR (Status)) {
3278 goto Done;
3279 }
3280
3281 //
3282 // 7. Update return value.
3283 //
3284 *Results = MultiKeywordResp;
3285
3286 //
3287 // 8. Clean the temp buffer.
3288 //
3289 FreePool (DevicePath);
3290 FreePool (KeywordData);
3291 FreePool (ValueElement);
3292 FreePool (ConfigRequest);
3293 DevicePath = NULL;
3294 KeywordData = NULL;
3295 ValueElement = NULL;
3296 ConfigRequest = NULL;
3297 if (KeywordResp != NULL) {
3298 FreePool (KeywordResp);
3299 KeywordResp = NULL;
3300 }
3301 }
3302 } else {
3303 //
3304 // Enumerate all keyword in the system.
3305 //
3306 Status = EnumerateAllKeywords(NameSpace, &MultiKeywordResp, ProgressErr);
3307 if (EFI_ERROR (Status)) {
3308 goto Done;
3309 }
3310 *Results = MultiKeywordResp;
3311 }
3312
3313 *ProgressErr = KEYWORD_HANDLER_NO_ERROR;
3314
3315 Done:
3316 *Progress = KeywordString + (StringPtr - TempString);
3317
3318 if (TempString != NULL) {
3319 FreePool (TempString);
3320 }
3321 if (NameSpace != NULL) {
3322 FreePool (NameSpace);
3323 }
3324 if (DevicePath != NULL) {
3325 FreePool (DevicePath);
3326 }
3327 if (KeywordData != NULL) {
3328 FreePool (KeywordData);
3329 }
3330
3331 return Status;
3332 }