]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c
MdeModulePkg: Clean up source files
[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 - 2018, 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 = ReallocatePool (
2547 StrSize (*MultiKeywordResp),
2548 MultiKeywordRespLen,
2549 *MultiKeywordResp
2550 );
2551 if (StringPtr == NULL) {
2552 return EFI_OUT_OF_RESOURCES;
2553 }
2554
2555 *MultiKeywordResp = StringPtr;
2556
2557 StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), L"&");
2558
2559 StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), *KeywordResp);
2560
2561 return EFI_SUCCESS;
2562 }
2563
2564 /**
2565 Enumerate all keyword in the system.
2566
2567 If error occur when parse one keyword, just skip it and parse the next one.
2568
2569 This is a internal function.
2570
2571 @param NameSpace The namespace used to search the string.
2572 @param MultiResp Return the MultiKeywordResp string for the system.
2573 @param ProgressErr Return the error status.
2574
2575 @retval EFI_OUT_OF_RESOURCES The memory can't be allocated.
2576 @retval EFI_SUCCESS Generate the MultiKeywordResp string.
2577 @retval EFI_NOT_FOUND No keyword found.
2578
2579 **/
2580 EFI_STATUS
2581 EnumerateAllKeywords (
2582 IN CHAR8 *NameSpace,
2583 OUT EFI_STRING *MultiResp,
2584 OUT UINT32 *ProgressErr
2585 )
2586 {
2587 LIST_ENTRY *Link;
2588 LIST_ENTRY *StringLink;
2589 UINT8 *DevicePathPkg;
2590 UINT8 *DevicePath;
2591 HII_DATABASE_RECORD *DataBaseRecord;
2592 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
2593 HII_STRING_PACKAGE_INSTANCE *StringPackage;
2594 CHAR8 *LocalNameSpace;
2595 EFI_STRING_ID NextStringId;
2596 EFI_STATUS Status;
2597 UINT8 *OpCode;
2598 CHAR16 *ConfigRequest;
2599 CHAR16 *ValueElement;
2600 CHAR16 *KeywordResp;
2601 CHAR16 *MultiKeywordResp;
2602 CHAR16 *KeywordData;
2603 BOOLEAN ReadOnly;
2604 BOOLEAN FindKeywordPackages;
2605
2606 DataBaseRecord = NULL;
2607 Status = EFI_SUCCESS;
2608 MultiKeywordResp = NULL;
2609 DevicePath = NULL;
2610 LocalNameSpace = NULL;
2611 ConfigRequest = NULL;
2612 ValueElement = NULL;
2613 KeywordResp = NULL;
2614 FindKeywordPackages = FALSE;
2615
2616 if (NameSpace == NULL) {
2617 NameSpace = UEFI_CONFIG_LANG;
2618 }
2619
2620 //
2621 // Find driver which matches the routing data.
2622 //
2623 for (Link = mPrivate.DatabaseList.ForwardLink; Link != &mPrivate.DatabaseList; Link = Link->ForwardLink) {
2624 DataBaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
2625 if ((DevicePathPkg = DataBaseRecord->PackageList->DevicePathPkg) != NULL) {
2626 DevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);
2627 }
2628 PackageListNode = DataBaseRecord->PackageList;
2629
2630 for (StringLink = PackageListNode->StringPkgHdr.ForwardLink; StringLink != &PackageListNode->StringPkgHdr; StringLink = StringLink->ForwardLink) {
2631 StringPackage = CR (StringLink, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
2632
2633 //
2634 // Check whether has keyword string package.
2635 //
2636 if (AsciiStrnCmp(NameSpace, StringPackage->StringPkgHdr->Language, AsciiStrLen (NameSpace)) == 0) {
2637 FindKeywordPackages = TRUE;
2638 //
2639 // Keep the NameSpace string.
2640 //
2641 LocalNameSpace = AllocateCopyPool (AsciiStrSize (StringPackage->StringPkgHdr->Language), StringPackage->StringPkgHdr->Language);
2642 if (LocalNameSpace == NULL) {
2643 return EFI_OUT_OF_RESOURCES;
2644 }
2645
2646 //
2647 // 1 means just begin the enumerate the valid string ids.
2648 // StringId == 1 is always used to save the language for this string package.
2649 // Any valid string start from 2. so here initial it to 1.
2650 //
2651 NextStringId = 1;
2652
2653 //
2654 // Enumerate all valid stringid in the package.
2655 //
2656 while ((NextStringId = GetNextStringId (StringPackage, NextStringId, &KeywordData)) != 0) {
2657 //
2658 // 3.3 Construct the ConfigRequest string.
2659 //
2660 Status = ExtractConfigRequest (DataBaseRecord, NextStringId, &OpCode, &ConfigRequest);
2661 if (EFI_ERROR (Status)) {
2662 //
2663 // If can't generate ConfigRequest for this question, skip it and start the next.
2664 //
2665 goto Error;
2666 }
2667
2668 //
2669 // 3.4 Extract Value for the input keyword.
2670 //
2671 Status = ExtractValueFromDriver(ConfigRequest, &ValueElement);
2672 if (EFI_ERROR (Status)) {
2673 if (Status != EFI_OUT_OF_RESOURCES) {
2674 //
2675 // If can't generate ConfigRequest for this question, skip it and start the next.
2676 //
2677 goto Error;
2678 }
2679 //
2680 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2681 //
2682 goto Done;
2683 }
2684
2685 //
2686 // Extract readonly flag from opcode.
2687 //
2688 ReadOnly = ExtractReadOnlyFromOpCode(OpCode);
2689
2690 //
2691 // 5. Generate KeywordResp string.
2692 //
2693 ASSERT (DevicePath != NULL);
2694 Status = GenerateKeywordResp(LocalNameSpace, (EFI_DEVICE_PATH_PROTOCOL *)DevicePath, KeywordData, ValueElement, ReadOnly, &KeywordResp);
2695 if (Status != EFI_SUCCESS) {
2696 //
2697 // If EFI_OUT_OF_RESOURCES error occur, no need to continue.
2698 //
2699 goto Done;
2700 }
2701
2702 //
2703 // 6. Merge to the MultiKeywordResp string.
2704 //
2705 Status = MergeToMultiKeywordResp(&MultiKeywordResp, &KeywordResp);
2706 if (EFI_ERROR (Status)) {
2707 goto Done;
2708 }
2709 Error:
2710 //
2711 // Clean the temp buffer to later use again.
2712 //
2713 if (ConfigRequest != NULL) {
2714 FreePool (ConfigRequest);
2715 ConfigRequest = NULL;
2716 }
2717 if (ValueElement != NULL) {
2718 FreePool (ValueElement);
2719 ValueElement = NULL;
2720 }
2721 if (KeywordResp != NULL) {
2722 FreePool (KeywordResp);
2723 KeywordResp = NULL;
2724 }
2725 }
2726
2727 if (LocalNameSpace != NULL) {
2728 FreePool (LocalNameSpace);
2729 LocalNameSpace = NULL;
2730 }
2731 }
2732 }
2733 }
2734
2735 //
2736 // return the already get MultiKeywordString even error occurred.
2737 //
2738 if (MultiKeywordResp == NULL) {
2739 Status = EFI_NOT_FOUND;
2740 if (!FindKeywordPackages) {
2741 *ProgressErr = KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND;
2742 } else {
2743 *ProgressErr = KEYWORD_HANDLER_KEYWORD_NOT_FOUND;
2744 }
2745 } else {
2746 Status = EFI_SUCCESS;
2747 }
2748 *MultiResp = MultiKeywordResp;
2749
2750 Done:
2751 if (LocalNameSpace != NULL) {
2752 FreePool (LocalNameSpace);
2753 }
2754 if (ConfigRequest != NULL) {
2755 FreePool (ConfigRequest);
2756 }
2757 if (ValueElement != NULL) {
2758 FreePool (ValueElement);
2759 }
2760
2761 return Status;
2762 }
2763
2764 /**
2765
2766 This function accepts a <MultiKeywordResp> formatted string, finds the associated
2767 keyword owners, creates a <MultiConfigResp> string from it and forwards it to the
2768 EFI_HII_ROUTING_PROTOCOL.RouteConfig function.
2769
2770 If there is an issue in resolving the contents of the KeywordString, then the
2771 function returns an error and also sets the Progress and ProgressErr with the
2772 appropriate information about where the issue occurred and additional data about
2773 the nature of the issue.
2774
2775 In the case when KeywordString containing multiple keywords, when an EFI_NOT_FOUND
2776 error is generated during processing the second or later keyword element, the system
2777 storage associated with earlier keywords is not modified. All elements of the
2778 KeywordString must successfully pass all tests for format and access prior to making
2779 any modifications to storage.
2780
2781 In the case when EFI_DEVICE_ERROR is returned from the processing of a KeywordString
2782 containing multiple keywords, the state of storage associated with earlier keywords
2783 is undefined.
2784
2785
2786 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
2787
2788 @param KeywordString A null-terminated string in <MultiKeywordResp> format.
2789
2790 @param Progress On return, points to a character in the KeywordString.
2791 Points to the string's NULL terminator if the request
2792 was successful. Points to the most recent '&' before
2793 the first failing name / value pair (or the beginning
2794 of the string if the failure is in the first name / value
2795 pair) if the request was not successful.
2796
2797 @param ProgressErr If during the processing of the KeywordString there was
2798 a failure, this parameter gives additional information
2799 about the possible source of the problem. The various
2800 errors are defined in "Related Definitions" below.
2801
2802
2803 @retval EFI_SUCCESS The specified action was completed successfully.
2804
2805 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
2806 1. KeywordString is NULL.
2807 2. Parsing of the KeywordString resulted in an
2808 error. See Progress and ProgressErr for more data.
2809
2810 @retval EFI_NOT_FOUND An element of the KeywordString was not found.
2811 See ProgressErr for more data.
2812
2813 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2814 See ProgressErr for more data.
2815
2816 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr
2817 for more data.
2818
2819 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
2820 for more data.
2821
2822 **/
2823 EFI_STATUS
2824 EFIAPI
2825 EfiConfigKeywordHandlerSetData (
2826 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *This,
2827 IN CONST EFI_STRING KeywordString,
2828 OUT EFI_STRING *Progress,
2829 OUT UINT32 *ProgressErr
2830 )
2831 {
2832 CHAR8 *NameSpace;
2833 EFI_STATUS Status;
2834 CHAR16 *StringPtr;
2835 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
2836 CHAR16 *NextStringPtr;
2837 CHAR16 *KeywordData;
2838 EFI_STRING_ID KeywordStringId;
2839 UINT32 RetVal;
2840 HII_DATABASE_RECORD *DataBaseRecord;
2841 UINT8 *OpCode;
2842 CHAR16 *ConfigResp;
2843 CHAR16 *MultiConfigResp;
2844 CHAR16 *ValueElement;
2845 BOOLEAN ReadOnly;
2846 EFI_STRING InternalProgress;
2847 CHAR16 *TempString;
2848 CHAR16 *KeywordStartPos;
2849
2850 if (This == NULL || Progress == NULL || ProgressErr == NULL || KeywordString == NULL) {
2851 return EFI_INVALID_PARAMETER;
2852 }
2853
2854 *Progress = KeywordString;
2855 *ProgressErr = KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR;
2856 Status = EFI_SUCCESS;
2857 MultiConfigResp = NULL;
2858 NameSpace = NULL;
2859 DevicePath = NULL;
2860 KeywordData = NULL;
2861 ValueElement = NULL;
2862 ConfigResp = NULL;
2863 KeywordStartPos = NULL;
2864 KeywordStringId = 0;
2865
2866 //
2867 // Use temp string to avoid changing input string buffer.
2868 //
2869 TempString = AllocateCopyPool (StrSize (KeywordString), KeywordString);
2870 ASSERT (TempString != NULL);
2871 StringPtr = TempString;
2872
2873 while ((StringPtr != NULL) && (*StringPtr != L'\0')) {
2874 //
2875 // 1. Get NameSpace from NameSpaceId keyword.
2876 //
2877 Status = ExtractNameSpace (StringPtr, &NameSpace, &NextStringPtr);
2878 if (EFI_ERROR (Status)) {
2879 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2880 goto Done;
2881 }
2882 ASSERT (NameSpace != NULL);
2883 //
2884 // 1.1 Check whether the input namespace is valid.
2885 //
2886 if (AsciiStrnCmp(NameSpace, UEFI_CONFIG_LANG, AsciiStrLen (UEFI_CONFIG_LANG)) != 0) {
2887 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2888 Status = EFI_INVALID_PARAMETER;
2889 goto Done;
2890 }
2891
2892 StringPtr = NextStringPtr;
2893
2894 //
2895 // 2. Get possible Device Path info from KeywordString.
2896 //
2897 Status = ExtractDevicePath (StringPtr, (UINT8 **)&DevicePath, &NextStringPtr);
2898 if (EFI_ERROR (Status)) {
2899 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2900 goto Done;
2901 }
2902 StringPtr = NextStringPtr;
2903
2904 //
2905 // 3. Extract keyword from the KeywordRequest string.
2906 //
2907 KeywordStartPos = StringPtr;
2908 Status = ExtractKeyword(StringPtr, &KeywordData, &NextStringPtr);
2909 if (EFI_ERROR (Status)) {
2910 //
2911 // Can't find Keyword base on the input device path info.
2912 //
2913 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2914 Status = EFI_INVALID_PARAMETER;
2915 goto Done;
2916 }
2917 StringPtr = NextStringPtr;
2918
2919 //
2920 // 4. Extract Value from the KeywordRequest string.
2921 //
2922 Status = ExtractValue (StringPtr, &ValueElement, &NextStringPtr);
2923 if (EFI_ERROR (Status)) {
2924 //
2925 // Can't find Value base on the input device path info.
2926 //
2927 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
2928 Status = EFI_INVALID_PARAMETER;
2929 goto Done;
2930 }
2931 StringPtr = NextStringPtr;
2932
2933 //
2934 // 5. Find READONLY tag.
2935 //
2936 if ((StringPtr != NULL) && StrnCmp (StringPtr, L"&READONLY", StrLen (L"&READONLY")) == 0) {
2937 ReadOnly = TRUE;
2938 StringPtr += StrLen (L"&READONLY");
2939 } else {
2940 ReadOnly = FALSE;
2941 }
2942
2943 //
2944 // 6. Get EFI_STRING_ID for the input keyword.
2945 //
2946 Status = GetStringIdFromDatabase (&DevicePath, &NameSpace, KeywordData, &RetVal, &KeywordStringId, &DataBaseRecord);
2947 if (EFI_ERROR (Status)) {
2948 *ProgressErr = RetVal;
2949 goto Done;
2950 }
2951
2952 //
2953 // 7. Construct the ConfigRequest string.
2954 //
2955 Status = ExtractConfigResp (DataBaseRecord, KeywordStringId, ValueElement, &OpCode, &ConfigResp);
2956 if (EFI_ERROR (Status)) {
2957 goto Done;
2958 }
2959
2960 //
2961 // 8. Check the readonly flag.
2962 //
2963 if (ExtractReadOnlyFromOpCode (OpCode) != ReadOnly) {
2964 //
2965 // Extracting readonly flag form opcode and extracting "READONLY" tag form KeywordString should have the same results.
2966 // If not, the input KeywordString must be incorrect, return the error status to caller.
2967 //
2968 *ProgressErr = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;
2969 Status = EFI_INVALID_PARAMETER;
2970 goto Done;
2971 }
2972 if (ReadOnly) {
2973 *ProgressErr = KEYWORD_HANDLER_ACCESS_NOT_PERMITTED;
2974 Status = EFI_ACCESS_DENIED;
2975 goto Done;
2976 }
2977
2978 //
2979 // 9. Merge to the MultiKeywordResp string.
2980 //
2981 Status = MergeToMultiKeywordResp(&MultiConfigResp, &ConfigResp);
2982 if (EFI_ERROR (Status)) {
2983 goto Done;
2984 }
2985
2986 //
2987 // 10. Clean the temp buffer point.
2988 //
2989 FreePool (NameSpace);
2990 FreePool (DevicePath);
2991 FreePool (KeywordData);
2992 FreePool (ValueElement);
2993 NameSpace = NULL;
2994 DevicePath = NULL;
2995 KeywordData = NULL;
2996 ValueElement = NULL;
2997 if (ConfigResp != NULL) {
2998 FreePool (ConfigResp);
2999 ConfigResp = NULL;
3000 }
3001 KeywordStartPos = NULL;
3002 }
3003
3004 //
3005 // 11. Set value to driver.
3006 //
3007 Status = mPrivate.ConfigRouting.RouteConfig(
3008 &mPrivate.ConfigRouting,
3009 (EFI_STRING) MultiConfigResp,
3010 &InternalProgress
3011 );
3012 if (EFI_ERROR (Status)) {
3013 Status = EFI_DEVICE_ERROR;
3014 goto Done;
3015 }
3016
3017 *ProgressErr = KEYWORD_HANDLER_NO_ERROR;
3018
3019 Done:
3020 if (KeywordStartPos != NULL) {
3021 *Progress = KeywordString + (KeywordStartPos - TempString);
3022 } else {
3023 *Progress = KeywordString + (StringPtr - TempString);
3024 }
3025
3026 ASSERT (TempString != NULL);
3027 FreePool (TempString);
3028 if (NameSpace != NULL) {
3029 FreePool (NameSpace);
3030 }
3031 if (DevicePath != NULL) {
3032 FreePool (DevicePath);
3033 }
3034 if (KeywordData != NULL) {
3035 FreePool (KeywordData);
3036 }
3037 if (ValueElement != NULL) {
3038 FreePool (ValueElement);
3039 }
3040 if (ConfigResp != NULL) {
3041 FreePool (ConfigResp);
3042 }
3043 if (MultiConfigResp != NULL && MultiConfigResp != ConfigResp) {
3044 FreePool (MultiConfigResp);
3045 }
3046
3047 return Status;
3048 }
3049
3050 /**
3051
3052 This function accepts a <MultiKeywordRequest> formatted string, finds the underlying
3053 keyword owners, creates a <MultiConfigRequest> string from it and forwards it to the
3054 EFI_HII_ROUTING_PROTOCOL.ExtractConfig function.
3055
3056 If there is an issue in resolving the contents of the KeywordString, then the function
3057 returns an EFI_INVALID_PARAMETER and also set the Progress and ProgressErr with the
3058 appropriate information about where the issue occurred and additional data about the
3059 nature of the issue.
3060
3061 In the case when KeywordString is NULL, or contains multiple keywords, or when
3062 EFI_NOT_FOUND is generated while processing the keyword elements, the Results string
3063 contains values returned for all keywords processed prior to the keyword generating the
3064 error but no values for the keyword with error or any following keywords.
3065
3066
3067 @param This Pointer to the EFI_KEYWORD_HANDLER _PROTOCOL instance.
3068
3069 @param NameSpaceId A null-terminated string containing the platform configuration
3070 language to search through in the system. If a NULL is passed
3071 in, then it is assumed that any platform configuration language
3072 with the prefix of "x-UEFI-" are searched.
3073
3074 @param KeywordString A null-terminated string in <MultiKeywordRequest> format. If a
3075 NULL is passed in the KeywordString field, all of the known
3076 keywords in the system for the NameSpaceId specified are
3077 returned in the Results field.
3078
3079 @param Progress On return, points to a character in the KeywordString. Points
3080 to the string's NULL terminator if the request was successful.
3081 Points to the most recent '&' before the first failing name / value
3082 pair (or the beginning of the string if the failure is in the first
3083 name / value pair) if the request was not successful.
3084
3085 @param ProgressErr If during the processing of the KeywordString there was a
3086 failure, this parameter gives additional information about the
3087 possible source of the problem. See the definitions in SetData()
3088 for valid value definitions.
3089
3090 @param Results A null-terminated string in <MultiKeywordResp> format is returned
3091 which has all the values filled in for the keywords in the
3092 KeywordString. This is a callee-allocated field, and must be freed
3093 by the caller after being used.
3094
3095 @retval EFI_SUCCESS The specified action was completed successfully.
3096
3097 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
3098 1.Progress, ProgressErr, or Results is NULL.
3099 2.Parsing of the KeywordString resulted in an error. See
3100 Progress and ProgressErr for more data.
3101
3102
3103 @retval EFI_NOT_FOUND An element of the KeywordString was not found. See
3104 ProgressErr for more data.
3105
3106 @retval EFI_NOT_FOUND The NamespaceId specified was not found. See ProgressErr
3107 for more data.
3108
3109 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated. See
3110 ProgressErr for more data.
3111
3112 @retval EFI_ACCESS_DENIED The action violated system policy. See ProgressErr for
3113 more data.
3114
3115 @retval EFI_DEVICE_ERROR An unexpected system error occurred. See ProgressErr
3116 for more data.
3117
3118 **/
3119 EFI_STATUS
3120 EFIAPI
3121 EfiConfigKeywordHandlerGetData (
3122 IN EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *This,
3123 IN CONST EFI_STRING NameSpaceId, OPTIONAL
3124 IN CONST EFI_STRING KeywordString, OPTIONAL
3125 OUT EFI_STRING *Progress,
3126 OUT UINT32 *ProgressErr,
3127 OUT EFI_STRING *Results
3128 )
3129 {
3130 CHAR8 *NameSpace;
3131 EFI_STATUS Status;
3132 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
3133 HII_DATABASE_RECORD *DataBaseRecord;
3134 CHAR16 *StringPtr;
3135 CHAR16 *NextStringPtr;
3136 CHAR16 *KeywordData;
3137 EFI_STRING_ID KeywordStringId;
3138 UINT8 *OpCode;
3139 CHAR16 *ConfigRequest;
3140 CHAR16 *ValueElement;
3141 UINT32 RetVal;
3142 BOOLEAN ReadOnly;
3143 CHAR16 *KeywordResp;
3144 CHAR16 *MultiKeywordResp;
3145 CHAR16 *TempString;
3146
3147 if (This == NULL || Progress == NULL || ProgressErr == NULL || Results == NULL) {
3148 return EFI_INVALID_PARAMETER;
3149 }
3150
3151 *ProgressErr = KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR;
3152 Status = EFI_SUCCESS;
3153 DevicePath = NULL;
3154 NameSpace = NULL;
3155 KeywordData = NULL;
3156 ConfigRequest= NULL;
3157 StringPtr = KeywordString;
3158 ReadOnly = FALSE;
3159 MultiKeywordResp = NULL;
3160 KeywordStringId = 0;
3161 TempString = NULL;
3162
3163 //
3164 // Use temp string to avoid changing input string buffer.
3165 //
3166 if (NameSpaceId != NULL) {
3167 TempString = AllocateCopyPool (StrSize (NameSpaceId), NameSpaceId);
3168 ASSERT (TempString != NULL);
3169 }
3170 //
3171 // 1. Get NameSpace from NameSpaceId keyword.
3172 //
3173 Status = ExtractNameSpace (TempString, &NameSpace, NULL);
3174 if (TempString != NULL) {
3175 FreePool (TempString);
3176 TempString = NULL;
3177 }
3178 if (EFI_ERROR (Status)) {
3179 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3180 return Status;
3181 }
3182 //
3183 // 1.1 Check whether the input namespace is valid.
3184 //
3185 if (NameSpace != NULL){
3186 if (AsciiStrnCmp(NameSpace, UEFI_CONFIG_LANG, AsciiStrLen (UEFI_CONFIG_LANG)) != 0) {
3187 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3188 return EFI_INVALID_PARAMETER;
3189 }
3190 }
3191
3192 if (KeywordString != NULL) {
3193 //
3194 // Use temp string to avoid changing input string buffer.
3195 //
3196 TempString = AllocateCopyPool (StrSize (KeywordString), KeywordString);
3197 ASSERT (TempString != NULL);
3198 StringPtr = TempString;
3199
3200 while (*StringPtr != L'\0') {
3201 //
3202 // 2. Get possible Device Path info from KeywordString.
3203 //
3204 Status = ExtractDevicePath (StringPtr, (UINT8 **)&DevicePath, &NextStringPtr);
3205 if (EFI_ERROR (Status)) {
3206 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3207 goto Done;
3208 }
3209 StringPtr = NextStringPtr;
3210
3211
3212 //
3213 // 3. Process Keyword section from the input keywordRequest string.
3214 //
3215 // 3.1 Extract keyword from the KeywordRequest string.
3216 //
3217 Status = ExtractKeyword(StringPtr, &KeywordData, &NextStringPtr);
3218 if (EFI_ERROR (Status)) {
3219 //
3220 // Can't find Keyword base on the input device path info.
3221 //
3222 *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING;
3223 Status = EFI_INVALID_PARAMETER;
3224 goto Done;
3225 }
3226
3227 //
3228 // 3.2 Get EFI_STRING_ID for the input keyword.
3229 //
3230 Status = GetStringIdFromDatabase (&DevicePath, &NameSpace, KeywordData, &RetVal, &KeywordStringId, &DataBaseRecord);
3231 if (EFI_ERROR (Status)) {
3232 *ProgressErr = RetVal;
3233 goto Done;
3234 }
3235
3236 //
3237 // 3.3 Construct the ConfigRequest string.
3238 //
3239 Status = ExtractConfigRequest (DataBaseRecord, KeywordStringId, &OpCode, &ConfigRequest);
3240 if (EFI_ERROR (Status)) {
3241 goto Done;
3242 }
3243
3244 //
3245 // 3.4 Extract Value for the input keyword.
3246 //
3247 Status = ExtractValueFromDriver(ConfigRequest, &ValueElement);
3248 if (EFI_ERROR (Status)) {
3249 if (Status != EFI_OUT_OF_RESOURCES) {
3250 Status = EFI_DEVICE_ERROR;
3251 }
3252 goto Done;
3253 }
3254 StringPtr = NextStringPtr;
3255
3256 //
3257 // 4. Process the possible filter section.
3258 //
3259 RetVal = ValidateFilter (OpCode, StringPtr, &NextStringPtr, &ReadOnly);
3260 if (RetVal != KEYWORD_HANDLER_NO_ERROR) {
3261 *ProgressErr = RetVal;
3262 Status = EFI_INVALID_PARAMETER;
3263 goto Done;
3264 }
3265 StringPtr = NextStringPtr;
3266
3267
3268 //
3269 // 5. Generate KeywordResp string.
3270 //
3271 Status = GenerateKeywordResp(NameSpace, DevicePath, KeywordData, ValueElement, ReadOnly, &KeywordResp);
3272 if (Status != EFI_SUCCESS) {
3273 goto Done;
3274 }
3275
3276 //
3277 // 6. Merge to the MultiKeywordResp string.
3278 //
3279 Status = MergeToMultiKeywordResp(&MultiKeywordResp, &KeywordResp);
3280 if (EFI_ERROR (Status)) {
3281 goto Done;
3282 }
3283
3284 //
3285 // 7. Update return value.
3286 //
3287 *Results = MultiKeywordResp;
3288
3289 //
3290 // 8. Clean the temp buffer.
3291 //
3292 FreePool (DevicePath);
3293 FreePool (KeywordData);
3294 FreePool (ValueElement);
3295 FreePool (ConfigRequest);
3296 DevicePath = NULL;
3297 KeywordData = NULL;
3298 ValueElement = NULL;
3299 ConfigRequest = NULL;
3300 if (KeywordResp != NULL) {
3301 FreePool (KeywordResp);
3302 KeywordResp = NULL;
3303 }
3304 }
3305 } else {
3306 //
3307 // Enumerate all keyword in the system.
3308 //
3309 Status = EnumerateAllKeywords(NameSpace, &MultiKeywordResp, ProgressErr);
3310 if (EFI_ERROR (Status)) {
3311 goto Done;
3312 }
3313 *Results = MultiKeywordResp;
3314 }
3315
3316 *ProgressErr = KEYWORD_HANDLER_NO_ERROR;
3317
3318 Done:
3319 *Progress = KeywordString + (StringPtr - TempString);
3320
3321 if (TempString != NULL) {
3322 FreePool (TempString);
3323 }
3324 if (NameSpace != NULL) {
3325 FreePool (NameSpace);
3326 }
3327 if (DevicePath != NULL) {
3328 FreePool (DevicePath);
3329 }
3330 if (KeywordData != NULL) {
3331 FreePool (KeywordData);
3332 }
3333
3334 return Status;
3335 }