]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/String.c
Update HiiCompareLanguage() function to use GetBestLanguage() API to do RFC4646 langu...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / String.c
1 /** @file
2 Implementation for EFI_HII_STRING_PROTOCOL.
3
4
5 Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include "HiiDatabase.h"
18
19 CHAR16 mLanguageWindow[16] = {
20 0x0000, 0x0080, 0x0100, 0x0300,
21 0x2000, 0x2080, 0x2100, 0x3000,
22 0x0080, 0x00C0, 0x0400, 0x0600,
23 0x0900, 0x3040, 0x30A0, 0xFF00
24 };
25
26
27 /**
28 This function checks whether a global font info is referred by local
29 font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create
30 a HII_FONT_INFO to refer it locally.
31
32 This is a internal function.
33
34
35 @param Private Hii database private structure.
36 @param StringPackage HII string package instance.
37 @param FontId Font identifer, which must be unique within the string package.
38 @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to
39 the same EFI_FONT_INFO is permitted. Otherwise it
40 is not allowed.
41 @param GlobalFontInfo Input a global font info which specify a
42 EFI_FONT_INFO.
43 @param LocalFontInfo Output a local font info which refers to a
44 EFI_FONT_INFO.
45
46 @retval TRUE Already referred before calling this function.
47 @retval FALSE Not referred before calling this function.
48
49 **/
50 BOOLEAN
51 ReferFontInfoLocally (
52 IN HII_DATABASE_PRIVATE_DATA *Private,
53 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,
54 IN UINT8 FontId,
55 IN BOOLEAN DuplicateEnable,
56 IN HII_GLOBAL_FONT_INFO *GlobalFontInfo,
57 OUT HII_FONT_INFO **LocalFontInfo
58 )
59 {
60 HII_FONT_INFO *LocalFont;
61 LIST_ENTRY *Link;
62
63 ASSERT (Private != NULL && StringPackage != NULL && GlobalFontInfo != NULL && LocalFontInfo != NULL);
64
65 if (!DuplicateEnable) {
66 for (Link = StringPackage->FontInfoList.ForwardLink;
67 Link != &StringPackage->FontInfoList;
68 Link = Link->ForwardLink
69 ) {
70 LocalFont = CR (Link, HII_FONT_INFO, Entry, HII_FONT_INFO_SIGNATURE);
71 if (LocalFont->GlobalEntry == &GlobalFontInfo->Entry) {
72 //
73 // Already referred by local font info list, return directly.
74 //
75 *LocalFontInfo = LocalFont;
76 return TRUE;
77 }
78 }
79 }
80 // FontId identifies EFI_FONT_INFO in local string package uniquely.
81 // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies
82 // EFI_FONT_INFO uniquely in whole hii database.
83 //
84 LocalFont = (HII_FONT_INFO *) AllocateZeroPool (sizeof (HII_FONT_INFO));
85 ASSERT (LocalFont != NULL);
86
87 LocalFont->Signature = HII_FONT_INFO_SIGNATURE;
88 LocalFont->FontId = FontId;
89 LocalFont->GlobalEntry = &GlobalFontInfo->Entry;
90 InsertTailList (&StringPackage->FontInfoList, &LocalFont->Entry);
91
92 *LocalFontInfo = LocalFont;
93 return FALSE;
94 }
95
96
97 /**
98 Convert Ascii string text to unicode string test.
99
100 This is a internal function.
101
102
103 @param StringDest Buffer to store the string text. If it is NULL,
104 only the size will be returned.
105 @param StringSrc Points to current null-terminated string.
106 @param BufferSize Length of the buffer.
107
108 @retval EFI_SUCCESS The string text was outputed successfully.
109 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
110 text. BufferSize is updated to the required buffer
111 size.
112
113 **/
114 EFI_STATUS
115 ConvertToUnicodeText (
116 OUT EFI_STRING StringDest,
117 IN CHAR8 *StringSrc,
118 IN OUT UINTN *BufferSize
119 )
120 {
121 UINTN StringSize;
122 UINTN Index;
123
124 ASSERT (StringSrc != NULL && BufferSize != NULL);
125
126 StringSize = AsciiStrSize (StringSrc) * 2;
127 if (*BufferSize < StringSize || StringDest == NULL) {
128 *BufferSize = StringSize;
129 return EFI_BUFFER_TOO_SMALL;
130 }
131
132 for (Index = 0; Index < AsciiStrLen (StringSrc); Index++) {
133 StringDest[Index] = (CHAR16) StringSrc[Index];
134 }
135
136 StringDest[Index] = 0;
137 return EFI_SUCCESS;
138 }
139
140
141 /**
142 Calculate the size of StringSrc and output it. If StringDest is not NULL,
143 copy string text from src to dest.
144
145 This is a internal function.
146
147 @param StringDest Buffer to store the string text. If it is NULL,
148 only the size will be returned.
149 @param StringSrc Points to current null-terminated string.
150 @param BufferSize Length of the buffer.
151
152 @retval EFI_SUCCESS The string text was outputed successfully.
153 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
154 text. BufferSize is updated to the required buffer
155 size.
156
157 **/
158 EFI_STATUS
159 GetUnicodeStringTextOrSize (
160 OUT EFI_STRING StringDest, OPTIONAL
161 IN UINT8 *StringSrc,
162 IN OUT UINTN *BufferSize
163 )
164 {
165 UINTN StringSize;
166 UINT8 *StringPtr;
167
168 ASSERT (StringSrc != NULL && BufferSize != NULL);
169
170 StringSize = sizeof (CHAR16);
171 StringPtr = StringSrc;
172 while (ReadUnaligned16 ((UINT16 *) StringPtr) != 0) {
173 StringSize += sizeof (CHAR16);
174 StringPtr += sizeof (CHAR16);
175 }
176
177 if (*BufferSize < StringSize) {
178 *BufferSize = StringSize;
179 return EFI_BUFFER_TOO_SMALL;
180 }
181 if (StringDest != NULL) {
182 CopyMem (StringDest, StringSrc, StringSize);
183 }
184
185 *BufferSize = StringSize;
186 return EFI_SUCCESS;
187 }
188
189
190 /**
191 Copy string font info to a buffer.
192
193 This is a internal function.
194
195 @param StringPackage Hii string package instance.
196 @param FontId Font identifier which is unique in a string
197 package.
198 @param StringFontInfo Buffer to record the output font info. It's
199 caller's responsibility to free this buffer.
200
201 @retval EFI_SUCCESS The string font is outputed successfully.
202 @retval EFI_NOT_FOUND The specified font id does not exist.
203
204 **/
205 EFI_STATUS
206 GetStringFontInfo (
207 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,
208 IN UINT8 FontId,
209 OUT EFI_FONT_INFO **StringFontInfo
210 )
211 {
212 LIST_ENTRY *Link;
213 HII_FONT_INFO *FontInfo;
214 HII_GLOBAL_FONT_INFO *GlobalFont;
215
216 ASSERT (StringFontInfo != NULL && StringPackage != NULL);
217
218 for (Link = StringPackage->FontInfoList.ForwardLink; Link != &StringPackage->FontInfoList; Link = Link->ForwardLink) {
219 FontInfo = CR (Link, HII_FONT_INFO, Entry, HII_FONT_INFO_SIGNATURE);
220 if (FontInfo->FontId == FontId) {
221 GlobalFont = CR (FontInfo->GlobalEntry, HII_GLOBAL_FONT_INFO, Entry, HII_GLOBAL_FONT_INFO_SIGNATURE);
222 *StringFontInfo = (EFI_FONT_INFO *) AllocateZeroPool (GlobalFont->FontInfoSize);
223 if (*StringFontInfo == NULL) {
224 return EFI_OUT_OF_RESOURCES;
225 }
226 CopyMem (*StringFontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize);
227 return EFI_SUCCESS;
228 }
229 }
230
231 return EFI_NOT_FOUND;
232 }
233
234
235 /**
236 Parse all string blocks to find a String block specified by StringId.
237 If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks
238 within this string package and backup its information. If LastStringId is
239 specified, the string id of last string block will also be output.
240 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_STRING).
241
242 @param Private Hii database private structure.
243 @param StringPackage Hii string package instance.
244 @param StringId The string's id, which is unique within
245 PackageList.
246 @param BlockType Output the block type of found string block.
247 @param StringBlockAddr Output the block address of found string block.
248 @param StringTextOffset Offset, relative to the found block address, of
249 the string text information.
250 @param LastStringId Output the last string id when StringId = 0 or StringId = -1.
251 @param StartStringId The first id in the skip block which StringId in the block.
252
253 @retval EFI_SUCCESS The string text and font is retrieved
254 successfully.
255 @retval EFI_NOT_FOUND The specified text or font info can not be found
256 out.
257 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
258 task.
259
260 **/
261 EFI_STATUS
262 FindStringBlock (
263 IN HII_DATABASE_PRIVATE_DATA *Private,
264 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,
265 IN EFI_STRING_ID StringId,
266 OUT UINT8 *BlockType, OPTIONAL
267 OUT UINT8 **StringBlockAddr, OPTIONAL
268 OUT UINTN *StringTextOffset, OPTIONAL
269 OUT EFI_STRING_ID *LastStringId, OPTIONAL
270 OUT EFI_STRING_ID *StartStringId OPTIONAL
271 )
272 {
273 UINT8 *BlockHdr;
274 EFI_STRING_ID CurrentStringId;
275 UINTN BlockSize;
276 UINTN Index;
277 UINT8 *StringTextPtr;
278 UINTN Offset;
279 HII_FONT_INFO *LocalFont;
280 EFI_FONT_INFO *FontInfo;
281 HII_GLOBAL_FONT_INFO *GlobalFont;
282 UINTN FontInfoSize;
283 UINT16 StringCount;
284 UINT16 SkipCount;
285 EFI_HII_FONT_STYLE FontStyle;
286 UINT16 FontSize;
287 UINT8 Length8;
288 EFI_HII_SIBT_EXT2_BLOCK Ext2;
289 UINT8 FontId;
290 UINT32 Length32;
291 UINTN StringSize;
292 CHAR16 Zero;
293
294 ASSERT (StringPackage != NULL);
295 ASSERT (StringPackage->Signature == HII_STRING_PACKAGE_SIGNATURE);
296
297 CurrentStringId = 1;
298
299 if (StringId != (EFI_STRING_ID) (-1) && StringId != 0) {
300 ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);
301 if (StringId > StringPackage->MaxStringId) {
302 return EFI_NOT_FOUND;
303 }
304 } else {
305 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
306 if (StringId == 0 && LastStringId != NULL) {
307 *LastStringId = StringPackage->MaxStringId;
308 return EFI_SUCCESS;
309 }
310 }
311
312 ZeroMem (&Zero, sizeof (CHAR16));
313
314 //
315 // Parse the string blocks to get the string text and font.
316 //
317 BlockHdr = StringPackage->StringBlock;
318 BlockSize = 0;
319 Offset = 0;
320 while (*BlockHdr != EFI_HII_SIBT_END) {
321 switch (*BlockHdr) {
322 case EFI_HII_SIBT_STRING_SCSU:
323 Offset = sizeof (EFI_HII_STRING_BLOCK);
324 StringTextPtr = BlockHdr + Offset;
325 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);
326 CurrentStringId++;
327 break;
328
329 case EFI_HII_SIBT_STRING_SCSU_FONT:
330 Offset = sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - sizeof (UINT8);
331 StringTextPtr = BlockHdr + Offset;
332 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);
333 CurrentStringId++;
334 break;
335
336 case EFI_HII_SIBT_STRINGS_SCSU:
337 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
338 StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8);
339 BlockSize += StringTextPtr - BlockHdr;
340
341 for (Index = 0; Index < StringCount; Index++) {
342 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
343 if (CurrentStringId == StringId) {
344 *BlockType = *BlockHdr;
345 *StringBlockAddr = BlockHdr;
346 *StringTextOffset = StringTextPtr - BlockHdr;
347 return EFI_SUCCESS;
348 }
349 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);
350 CurrentStringId++;
351 }
352 break;
353
354 case EFI_HII_SIBT_STRINGS_SCSU_FONT:
355 CopyMem (
356 &StringCount,
357 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
358 sizeof (UINT16)
359 );
360 StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8);
361 BlockSize += StringTextPtr - BlockHdr;
362
363 for (Index = 0; Index < StringCount; Index++) {
364 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
365 if (CurrentStringId == StringId) {
366 *BlockType = *BlockHdr;
367 *StringBlockAddr = BlockHdr;
368 *StringTextOffset = StringTextPtr - BlockHdr;
369 return EFI_SUCCESS;
370 }
371 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);
372 CurrentStringId++;
373 }
374 break;
375
376 case EFI_HII_SIBT_STRING_UCS2:
377 Offset = sizeof (EFI_HII_STRING_BLOCK);
378 StringTextPtr = BlockHdr + Offset;
379 //
380 // Use StringSize to store the size of the specified string, including the NULL
381 // terminator.
382 //
383 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
384 BlockSize += Offset + StringSize;
385 CurrentStringId++;
386 break;
387
388 case EFI_HII_SIBT_STRING_UCS2_FONT:
389 Offset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);
390 StringTextPtr = BlockHdr + Offset;
391 //
392 // Use StrSize to store the size of the specified string, including the NULL
393 // terminator.
394 //
395 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
396 BlockSize += Offset + StringSize;
397 CurrentStringId++;
398 break;
399
400 case EFI_HII_SIBT_STRINGS_UCS2:
401 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeof (CHAR16);
402 StringTextPtr = BlockHdr + Offset;
403 BlockSize += Offset;
404 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
405 for (Index = 0; Index < StringCount; Index++) {
406 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
407 BlockSize += StringSize;
408 if (CurrentStringId == StringId) {
409 *BlockType = *BlockHdr;
410 *StringBlockAddr = BlockHdr;
411 *StringTextOffset = StringTextPtr - BlockHdr;
412 return EFI_SUCCESS;
413 }
414 StringTextPtr = StringTextPtr + StringSize;
415 CurrentStringId++;
416 }
417 break;
418
419 case EFI_HII_SIBT_STRINGS_UCS2_FONT:
420 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - sizeof (CHAR16);
421 StringTextPtr = BlockHdr + Offset;
422 BlockSize += Offset;
423 CopyMem (
424 &StringCount,
425 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
426 sizeof (UINT16)
427 );
428 for (Index = 0; Index < StringCount; Index++) {
429 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
430 BlockSize += StringSize;
431 if (CurrentStringId == StringId) {
432 *BlockType = *BlockHdr;
433 *StringBlockAddr = BlockHdr;
434 *StringTextOffset = StringTextPtr - BlockHdr;
435 return EFI_SUCCESS;
436 }
437 StringTextPtr = StringTextPtr + StringSize;
438 CurrentStringId++;
439 }
440 break;
441
442 case EFI_HII_SIBT_DUPLICATE:
443 if (CurrentStringId == StringId) {
444 //
445 // Incoming StringId is an id of a duplicate string block.
446 // Update the StringId to be the previous string block.
447 // Go back to the header of string block to search.
448 //
449 CopyMem (
450 &StringId,
451 BlockHdr + sizeof (EFI_HII_STRING_BLOCK),
452 sizeof (EFI_STRING_ID)
453 );
454 ASSERT (StringId != CurrentStringId);
455 CurrentStringId = 1;
456 BlockSize = 0;
457 } else {
458 BlockSize += sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK);
459 CurrentStringId++;
460 }
461 break;
462
463 case EFI_HII_SIBT_SKIP1:
464 SkipCount = (UINT16) (*(BlockHdr + sizeof (EFI_HII_STRING_BLOCK)));
465 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
466 BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK);
467 break;
468
469 case EFI_HII_SIBT_SKIP2:
470 CopyMem (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
471 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
472 BlockSize += sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
473 break;
474
475 case EFI_HII_SIBT_EXT1:
476 CopyMem (
477 &Length8,
478 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
479 sizeof (UINT8)
480 );
481 BlockSize += Length8;
482 break;
483
484 case EFI_HII_SIBT_EXT2:
485 CopyMem (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK));
486 if (Ext2.BlockType2 == EFI_HII_SIBT_FONT && StringId == (EFI_STRING_ID) (-1)) {
487 //
488 // Find the relationship between global font info and the font info of
489 // this EFI_HII_SIBT_FONT block then backup its information in local package.
490 //
491 BlockHdr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);
492 CopyMem (&FontId, BlockHdr, sizeof (UINT8));
493 BlockHdr += sizeof (UINT8);
494 CopyMem (&FontSize, BlockHdr, sizeof (UINT16));
495 BlockHdr += sizeof (UINT16);
496 CopyMem (&FontStyle, BlockHdr, sizeof (EFI_HII_FONT_STYLE));
497 BlockHdr += sizeof (EFI_HII_FONT_STYLE);
498 GetUnicodeStringTextOrSize (NULL, BlockHdr, &StringSize);
499
500 FontInfoSize = sizeof (EFI_FONT_INFO) - sizeof (CHAR16) + StringSize;
501 FontInfo = (EFI_FONT_INFO *) AllocateZeroPool (FontInfoSize);
502 if (FontInfo == NULL) {
503 return EFI_OUT_OF_RESOURCES;
504 }
505 FontInfo->FontStyle = FontStyle;
506 FontInfo->FontSize = FontSize;
507 CopyMem (FontInfo->FontName, BlockHdr, StringSize);
508
509 //
510 // If find the corresponding global font info, save the relationship.
511 // Otherwise ignore this EFI_HII_SIBT_FONT block.
512 //
513 if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont)) {
514 ReferFontInfoLocally (Private, StringPackage, FontId, TRUE, GlobalFont, &LocalFont);
515 }
516
517 //
518 // Since string package tool set FontId initially to 0 and increases it
519 // progressively by one, StringPackage->FondId always represents an unique
520 // and available FontId.
521 //
522 StringPackage->FontId++;
523
524 FreePool (FontInfo);
525 }
526
527 BlockSize += Ext2.Length;
528
529 break;
530
531 case EFI_HII_SIBT_EXT4:
532 CopyMem (
533 &Length32,
534 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
535 sizeof (UINT32)
536 );
537
538 BlockSize += Length32;
539 break;
540
541 default:
542 break;
543 }
544
545 if (StringId > 0 && StringId != (EFI_STRING_ID)(-1)) {
546 ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);
547 *BlockType = *BlockHdr;
548 *StringBlockAddr = BlockHdr;
549 *StringTextOffset = Offset;
550
551 if (StringId == CurrentStringId - 1) {
552 //
553 // if only one skip item, return EFI_NOT_FOUND.
554 //
555 if(*BlockType == EFI_HII_SIBT_SKIP2 || *BlockType == EFI_HII_SIBT_SKIP1) {
556 return EFI_NOT_FOUND;
557 } else {
558 return EFI_SUCCESS;
559 }
560 }
561
562 if (StringId < CurrentStringId - 1) {
563 return EFI_NOT_FOUND;
564 }
565 }
566 BlockHdr = StringPackage->StringBlock + BlockSize;
567 if (StartStringId != NULL) {
568 *StartStringId = CurrentStringId;
569 }
570 }
571
572 //
573 // Get last string ID
574 //
575 if (StringId == (EFI_STRING_ID) (-1)) {
576 *LastStringId = (EFI_STRING_ID) (CurrentStringId - 1);
577 return EFI_SUCCESS;
578 }
579
580 return EFI_NOT_FOUND;
581 }
582
583
584 /**
585 Parse all string blocks to get a string specified by StringId.
586
587 This is a internal function.
588
589 @param Private Hii database private structure.
590 @param StringPackage Hii string package instance.
591 @param StringId The string's id, which is unique within
592 PackageList.
593 @param String Points to retrieved null-terminated string.
594 @param StringSize On entry, points to the size of the buffer pointed
595 to by String, in bytes. On return, points to the
596 length of the string, in bytes.
597 @param StringFontInfo If not NULL, allocate a buffer to record the
598 output font info. It's caller's responsibility to
599 free this buffer.
600
601 @retval EFI_SUCCESS The string text and font is retrieved
602 successfully.
603 @retval EFI_NOT_FOUND The specified text or font info can not be found
604 out.
605 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
606 hold the string.
607
608 **/
609 EFI_STATUS
610 GetStringWorker (
611 IN HII_DATABASE_PRIVATE_DATA *Private,
612 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,
613 IN EFI_STRING_ID StringId,
614 OUT EFI_STRING String,
615 IN OUT UINTN *StringSize, OPTIONAL
616 OUT EFI_FONT_INFO **StringFontInfo OPTIONAL
617 )
618 {
619 UINT8 *StringTextPtr;
620 UINT8 BlockType;
621 UINT8 *StringBlockAddr;
622 UINTN StringTextOffset;
623 EFI_STATUS Status;
624 UINT8 FontId;
625
626 ASSERT (StringPackage != NULL);
627 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
628
629 //
630 // Find the specified string block
631 //
632 Status = FindStringBlock (
633 Private,
634 StringPackage,
635 StringId,
636 &BlockType,
637 &StringBlockAddr,
638 &StringTextOffset,
639 NULL,
640 NULL
641 );
642 if (EFI_ERROR (Status)) {
643 return Status;
644 }
645
646 if (StringSize == NULL) {
647 //
648 // String text buffer is not requested
649 //
650 return EFI_SUCCESS;
651 }
652
653 //
654 // Get the string text.
655 //
656 StringTextPtr = StringBlockAddr + StringTextOffset;
657 switch (BlockType) {
658 case EFI_HII_SIBT_STRING_SCSU:
659 case EFI_HII_SIBT_STRING_SCSU_FONT:
660 case EFI_HII_SIBT_STRINGS_SCSU:
661 case EFI_HII_SIBT_STRINGS_SCSU_FONT:
662 Status = ConvertToUnicodeText (String, (CHAR8 *) StringTextPtr, StringSize);
663 break;
664 case EFI_HII_SIBT_STRING_UCS2:
665 case EFI_HII_SIBT_STRING_UCS2_FONT:
666 case EFI_HII_SIBT_STRINGS_UCS2:
667 case EFI_HII_SIBT_STRINGS_UCS2_FONT:
668 Status = GetUnicodeStringTextOrSize (String, StringTextPtr, StringSize);
669 break;
670 default:
671 return EFI_NOT_FOUND;
672 }
673 if (EFI_ERROR (Status)) {
674 return Status;
675 }
676
677 //
678 // Get the string font. The FontId 0 is the default font for those string blocks which
679 // do not specify a font identifier. If default font is not specified, return NULL.
680 //
681 if (StringFontInfo != NULL) {
682 switch (BlockType) {
683 case EFI_HII_SIBT_STRING_SCSU_FONT:
684 case EFI_HII_SIBT_STRINGS_SCSU_FONT:
685 case EFI_HII_SIBT_STRING_UCS2_FONT:
686 case EFI_HII_SIBT_STRINGS_UCS2_FONT:
687 FontId = *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK));
688 break;
689 default:
690 FontId = 0;
691 }
692 Status = GetStringFontInfo (StringPackage, FontId, StringFontInfo);
693 if (Status == EFI_NOT_FOUND) {
694 *StringFontInfo = NULL;
695 }
696 }
697
698 return EFI_SUCCESS;
699 }
700
701 /**
702 If GetStringBlock find the StringId's string is not saved in the exist string block,
703 this function will create the UCS2 string block to save the string; also split the
704 skip block into two or one skip block.
705
706 This is a internal function.
707
708 @param StringPackage Hii string package instance.
709 @param StartStringId The first id in the skip block which StringId in the block.
710 @param StringId The string's id, which is unique within
711 PackageList.
712 @param BlockType Output the block type of found string block.
713 @param StringBlockAddr Output the block address of found string block.
714 @param FontBlock whether this string block has font info.
715
716 @retval EFI_SUCCESS The string font is outputed successfully.
717 @retval EFI_OUT_OF_RESOURCES NO resource for the memory to save the new string block.
718
719 **/
720 EFI_STATUS
721 InsertLackStringBlock (
722 IN OUT HII_STRING_PACKAGE_INSTANCE *StringPackage,
723 IN EFI_STRING_ID StartStringId,
724 IN EFI_STRING_ID StringId,
725 IN OUT UINT8 *BlockType,
726 IN OUT UINT8 **StringBlockAddr,
727 IN BOOLEAN FontBlock
728 )
729 {
730 UINT8 *BlockPtr;
731 UINT8 *StringBlock;
732 UINT32 SkipLen;
733 UINT32 OldBlockSize;
734 UINT32 NewBlockSize;
735 UINT32 FrontSkipNum;
736 UINT32 NewUCSBlockLen;
737 UINT8 *OldStringAddr;
738 UINT32 IdCount;
739
740 FrontSkipNum = 0;
741 SkipLen = 0;
742 OldStringAddr = *StringBlockAddr;
743
744 ASSERT (*BlockType == EFI_HII_SIBT_SKIP1 || *BlockType == EFI_HII_SIBT_SKIP2);
745 //
746 // Old skip block size.
747 //
748 if (*BlockType == EFI_HII_SIBT_SKIP1) {
749 SkipLen = sizeof (EFI_HII_SIBT_SKIP1_BLOCK);
750 IdCount = *(UINT8*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));
751 } else {
752 SkipLen = sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
753 IdCount = *(UINT16*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));
754 }
755
756 //
757 // New create UCS or UCS2 block size.
758 //
759 if (FontBlock) {
760 NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK);
761 } else {
762 NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);
763 }
764
765 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;
766
767 if (StartStringId == StringId) {
768 //
769 // New block + [Skip block]
770 //
771 if (IdCount > 1) {
772 NewBlockSize = OldBlockSize + NewUCSBlockLen;
773 } else {
774 NewBlockSize = OldBlockSize + NewUCSBlockLen - SkipLen;
775 }
776 } else if (StartStringId + IdCount - 1 == StringId){
777 //
778 // Skip block + New block
779 //
780 NewBlockSize = OldBlockSize + NewUCSBlockLen;
781 FrontSkipNum = StringId - StartStringId;
782 } else {
783 //
784 // Skip block + New block + [Skip block]
785 //
786 NewBlockSize = OldBlockSize + NewUCSBlockLen + SkipLen;
787 FrontSkipNum = StringId - StartStringId;
788 }
789
790 StringBlock = (UINT8 *) AllocateZeroPool (NewBlockSize);
791 if (StringBlock == NULL) {
792 return EFI_OUT_OF_RESOURCES;
793 }
794
795 //
796 // Copy old block in front of skip block.
797 //
798 CopyMem (StringBlock, StringPackage->StringBlock, OldStringAddr - StringPackage->StringBlock);
799 BlockPtr = StringBlock + (OldStringAddr - StringPackage->StringBlock);
800
801 if (FrontSkipNum > 0) {
802 *BlockPtr = *BlockType;
803 if (*BlockType == EFI_HII_SIBT_SKIP1) {
804 *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) FrontSkipNum;
805 } else {
806 *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) FrontSkipNum;
807 }
808 BlockPtr += SkipLen;
809 }
810
811 //
812 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
813 //
814 *StringBlockAddr = BlockPtr;
815 if (FontBlock) {
816 *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;
817 } else {
818 *BlockPtr = EFI_HII_SIBT_STRING_UCS2;
819 }
820 BlockPtr += NewUCSBlockLen;
821
822 if (IdCount > FrontSkipNum + 1) {
823 *BlockPtr = *BlockType;
824 if (*BlockType == EFI_HII_SIBT_SKIP1) {
825 *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) (IdCount - FrontSkipNum - 1);
826 } else {
827 *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) (IdCount - FrontSkipNum - 1);
828 }
829 BlockPtr += SkipLen;
830 }
831
832 //
833 // Append a EFI_HII_SIBT_END block to the end.
834 //
835 CopyMem (BlockPtr, OldStringAddr + SkipLen, OldBlockSize - (OldStringAddr - StringPackage->StringBlock) - SkipLen);
836
837 if (FontBlock) {
838 *BlockType = EFI_HII_SIBT_STRING_UCS2_FONT;
839 } else {
840 *BlockType = EFI_HII_SIBT_STRING_UCS2;
841 }
842 FreePool (StringPackage->StringBlock);
843 StringPackage->StringBlock = StringBlock;
844 StringPackage->StringPkgHdr->Header.Length += NewBlockSize - OldBlockSize;
845
846 return EFI_SUCCESS;
847 }
848
849 /**
850 Parse all string blocks to set a String specified by StringId.
851
852 This is a internal function.
853
854 @param Private HII database driver private structure.
855 @param StringPackage HII string package instance.
856 @param StringId The string's id, which is unique within
857 PackageList.
858 @param String Points to the new null-terminated string.
859 @param StringFontInfo Points to the input font info.
860
861 @retval EFI_SUCCESS The string was updated successfully.
862 @retval EFI_NOT_FOUND The string specified by StringId is not in the
863 database.
864 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
865 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
866 current database.
867 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
868 task.
869
870 **/
871 EFI_STATUS
872 SetStringWorker (
873 IN HII_DATABASE_PRIVATE_DATA *Private,
874 IN OUT HII_STRING_PACKAGE_INSTANCE *StringPackage,
875 IN EFI_STRING_ID StringId,
876 IN EFI_STRING String,
877 IN EFI_FONT_INFO *StringFontInfo OPTIONAL
878 )
879 {
880 UINT8 *StringTextPtr;
881 UINT8 BlockType;
882 UINT8 *StringBlockAddr;
883 UINTN StringTextOffset;
884 EFI_STATUS Status;
885 UINT8 *Block;
886 UINT8 *BlockPtr;
887 UINTN BlockSize;
888 UINTN OldBlockSize;
889 HII_FONT_INFO *LocalFont;
890 HII_GLOBAL_FONT_INFO *GlobalFont;
891 BOOLEAN Referred;
892 EFI_HII_SIBT_EXT2_BLOCK Ext2;
893 UINTN StringSize;
894 UINTN TmpSize;
895 EFI_STRING_ID StartStringId;
896
897 StartStringId = 0;
898 ASSERT (Private != NULL && StringPackage != NULL && String != NULL);
899 ASSERT (Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
900 //
901 // Find the specified string block
902 //
903 Status = FindStringBlock (
904 Private,
905 StringPackage,
906 StringId,
907 &BlockType,
908 &StringBlockAddr,
909 &StringTextOffset,
910 NULL,
911 &StartStringId
912 );
913 if (EFI_ERROR (Status) && (BlockType == EFI_HII_SIBT_SKIP1 || BlockType == EFI_HII_SIBT_SKIP2)) {
914 Status = InsertLackStringBlock(StringPackage,
915 StartStringId,
916 StringId,
917 &BlockType,
918 &StringBlockAddr,
919 (BOOLEAN)(StringFontInfo != NULL)
920 );
921 if (EFI_ERROR (Status)) {
922 return Status;
923 }
924 if (StringFontInfo != NULL) {
925 StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);
926 } else {
927 StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16);
928 }
929 }
930
931 LocalFont = NULL;
932 GlobalFont = NULL;
933 Referred = FALSE;
934
935 //
936 // The input StringFontInfo should exist in current database if specified.
937 //
938 if (StringFontInfo != NULL) {
939 if (!IsFontInfoExisted (Private, StringFontInfo, NULL, NULL, &GlobalFont)) {
940 return EFI_INVALID_PARAMETER;
941 } else {
942 Referred = ReferFontInfoLocally (
943 Private,
944 StringPackage,
945 StringPackage->FontId,
946 FALSE,
947 GlobalFont,
948 &LocalFont
949 );
950 if (!Referred) {
951 StringPackage->FontId++;
952 }
953 }
954 //
955 // Update the FontId of the specified string block to input font info.
956 //
957 switch (BlockType) {
958 case EFI_HII_SIBT_STRING_SCSU_FONT:
959 case EFI_HII_SIBT_STRINGS_SCSU_FONT:
960 case EFI_HII_SIBT_STRING_UCS2_FONT:
961 case EFI_HII_SIBT_STRINGS_UCS2_FONT:
962 *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK)) = LocalFont->FontId;
963 break;
964 default:
965 //
966 // When modify the font info of these blocks, the block type should be updated
967 // to contain font info thus the whole structure should be revised.
968 // It is recommended to use tool to modify the block type not in the code.
969 //
970 return EFI_UNSUPPORTED;
971 }
972 }
973
974 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;
975
976 //
977 // Set the string text and font.
978 //
979 StringTextPtr = StringBlockAddr + StringTextOffset;
980 switch (BlockType) {
981 case EFI_HII_SIBT_STRING_SCSU:
982 case EFI_HII_SIBT_STRING_SCSU_FONT:
983 case EFI_HII_SIBT_STRINGS_SCSU:
984 case EFI_HII_SIBT_STRINGS_SCSU_FONT:
985 BlockSize = OldBlockSize + StrLen (String);
986 BlockSize -= AsciiStrSize ((CHAR8 *) StringTextPtr);
987 Block = AllocateZeroPool (BlockSize);
988 if (Block == NULL) {
989 return EFI_OUT_OF_RESOURCES;
990 }
991
992 CopyMem (Block, StringPackage->StringBlock, StringTextPtr - StringPackage->StringBlock);
993 BlockPtr = Block + (StringTextPtr - StringPackage->StringBlock);
994
995 while (*String != 0) {
996 *BlockPtr++ = (CHAR8) *String++;
997 }
998 *BlockPtr++ = 0;
999
1000
1001 TmpSize = OldBlockSize - (StringTextPtr - StringPackage->StringBlock) - AsciiStrSize ((CHAR8 *) StringTextPtr);
1002 CopyMem (
1003 BlockPtr,
1004 StringTextPtr + AsciiStrSize ((CHAR8 *)StringTextPtr),
1005 TmpSize
1006 );
1007
1008 FreePool (StringPackage->StringBlock);
1009 StringPackage->StringBlock = Block;
1010 StringPackage->StringPkgHdr->Header.Length += (UINT32) (BlockSize - OldBlockSize);
1011 break;
1012
1013 case EFI_HII_SIBT_STRING_UCS2:
1014 case EFI_HII_SIBT_STRING_UCS2_FONT:
1015 case EFI_HII_SIBT_STRINGS_UCS2:
1016 case EFI_HII_SIBT_STRINGS_UCS2_FONT:
1017 //
1018 // Use StrSize to store the size of the specified string, including the NULL
1019 // terminator.
1020 //
1021 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
1022
1023 BlockSize = OldBlockSize + StrSize (String) - StringSize;
1024 Block = AllocateZeroPool (BlockSize);
1025 if (Block == NULL) {
1026 return EFI_OUT_OF_RESOURCES;
1027 }
1028
1029 CopyMem (Block, StringPackage->StringBlock, StringTextPtr - StringPackage->StringBlock);
1030 BlockPtr = Block + (StringTextPtr - StringPackage->StringBlock);
1031
1032 CopyMem (BlockPtr, String, StrSize (String));
1033 BlockPtr += StrSize (String);
1034
1035 CopyMem (
1036 BlockPtr,
1037 StringTextPtr + StringSize,
1038 OldBlockSize - (StringTextPtr - StringPackage->StringBlock) - StringSize
1039 );
1040
1041 FreePool (StringPackage->StringBlock);
1042 StringPackage->StringBlock = Block;
1043 StringPackage->StringPkgHdr->Header.Length += (UINT32) (BlockSize - OldBlockSize);
1044 break;
1045
1046 default:
1047 return EFI_NOT_FOUND;
1048 }
1049
1050 //
1051 // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming
1052 // StringFontInfo does not exist in current string package.
1053 //
1054 // This new block does not impact on the value of StringId.
1055 //
1056 //
1057 if (StringFontInfo == NULL || Referred) {
1058 return EFI_SUCCESS;
1059 }
1060
1061 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;
1062 BlockSize = OldBlockSize + sizeof (EFI_HII_SIBT_FONT_BLOCK) - sizeof (CHAR16) +
1063 StrSize (GlobalFont->FontInfo->FontName);
1064
1065 Block = AllocateZeroPool (BlockSize);
1066 if (Block == NULL) {
1067 return EFI_OUT_OF_RESOURCES;
1068 }
1069
1070 BlockPtr = Block;
1071 Ext2.Header.BlockType = EFI_HII_SIBT_EXT2;
1072 Ext2.BlockType2 = EFI_HII_SIBT_FONT;
1073 Ext2.Length = (UINT16) (BlockSize - OldBlockSize);
1074 CopyMem (BlockPtr, &Ext2, sizeof (EFI_HII_SIBT_EXT2_BLOCK));
1075 BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);
1076
1077 *BlockPtr = LocalFont->FontId;
1078 BlockPtr += sizeof (UINT8);
1079 CopyMem (BlockPtr, &GlobalFont->FontInfo->FontSize, sizeof (UINT16));
1080 BlockPtr += sizeof (UINT16);
1081 CopyMem (BlockPtr, &GlobalFont->FontInfo->FontStyle, sizeof (UINT32));
1082 BlockPtr += sizeof (UINT32);
1083 CopyMem (
1084 BlockPtr,
1085 GlobalFont->FontInfo->FontName,
1086 StrSize (GlobalFont->FontInfo->FontName)
1087 );
1088 BlockPtr += StrSize (GlobalFont->FontInfo->FontName);
1089
1090 CopyMem (BlockPtr, StringPackage->StringBlock, OldBlockSize);
1091
1092 FreePool (StringPackage->StringBlock);
1093 StringPackage->StringBlock = Block;
1094 StringPackage->StringPkgHdr->Header.Length += Ext2.Length;
1095
1096 return EFI_SUCCESS;
1097
1098 }
1099
1100
1101 /**
1102 This function adds the string String to the group of strings owned by PackageList, with the
1103 specified font information StringFontInfo and returns a new string id.
1104 The new string identifier is guaranteed to be unique within the package list.
1105 That new string identifier is reserved for all languages in the package list.
1106
1107
1108 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1109 @param PackageList Handle of the package list where this string will
1110 be added.
1111 @param StringId On return, contains the new strings id, which is
1112 unique within PackageList.
1113 @param Language Points to the language for the new string.
1114 @param LanguageName Points to the printable language name to associate
1115 with the passed in Language field.If LanguageName
1116 is not NULL and the string package header's
1117 LanguageName associated with a given Language is
1118 not zero, the LanguageName being passed in will
1119 be ignored.
1120 @param String Points to the new null-terminated string.
1121 @param StringFontInfo Points to the new string's font information or
1122 NULL if the string should have the default system
1123 font, size and style.
1124
1125 @retval EFI_SUCCESS The new string was added successfully.
1126 @retval EFI_NOT_FOUND The specified PackageList could not be found in
1127 database.
1128 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
1129 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is
1130 NULL.
1131 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1132 current database.
1133
1134 **/
1135 EFI_STATUS
1136 EFIAPI
1137 HiiNewString (
1138 IN CONST EFI_HII_STRING_PROTOCOL *This,
1139 IN EFI_HII_HANDLE PackageList,
1140 OUT EFI_STRING_ID *StringId,
1141 IN CONST CHAR8 *Language,
1142 IN CONST CHAR16 *LanguageName, OPTIONAL
1143 IN CONST EFI_STRING String,
1144 IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL
1145 )
1146 {
1147 EFI_STATUS Status;
1148 LIST_ENTRY *Link;
1149 HII_DATABASE_PRIVATE_DATA *Private;
1150 HII_DATABASE_RECORD *DatabaseRecord;
1151 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
1152 HII_STRING_PACKAGE_INSTANCE *StringPackage;
1153 UINT32 HeaderSize;
1154 UINT32 BlockSize;
1155 UINT32 OldBlockSize;
1156 UINT8 *StringBlock;
1157 UINT8 *BlockPtr;
1158 UINT32 Ucs2BlockSize;
1159 UINT32 FontBlockSize;
1160 UINT32 Ucs2FontBlockSize;
1161 EFI_HII_SIBT_EXT2_BLOCK Ext2;
1162 HII_FONT_INFO *LocalFont;
1163 HII_GLOBAL_FONT_INFO *GlobalFont;
1164 EFI_STRING_ID NewStringId;
1165 EFI_STRING_ID NextStringId;
1166 EFI_STRING_ID Index;
1167 HII_STRING_PACKAGE_INSTANCE *MatchStringPackage;
1168 BOOLEAN NewStringPackageCreated;
1169
1170
1171 if (This == NULL || String == NULL || StringId == NULL || Language == NULL || PackageList == NULL) {
1172 return EFI_INVALID_PARAMETER;
1173 }
1174
1175 if (!IsHiiHandleValid (PackageList)) {
1176 return EFI_NOT_FOUND;
1177 }
1178
1179 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1180 GlobalFont = NULL;
1181
1182 //
1183 // If StringFontInfo specify a paritcular font, it should exist in current database.
1184 //
1185 if (StringFontInfo != NULL) {
1186 if (!IsFontInfoExisted (Private, (EFI_FONT_INFO *) StringFontInfo, NULL, NULL, &GlobalFont)) {
1187 return EFI_INVALID_PARAMETER;
1188 }
1189 }
1190
1191 //
1192 // Get the matching package list.
1193 //
1194 PackageListNode = NULL;
1195 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
1196 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
1197 if (DatabaseRecord->Handle == PackageList) {
1198 PackageListNode = DatabaseRecord->PackageList;
1199 break;
1200 }
1201 }
1202 if (PackageListNode == NULL) {
1203 return EFI_NOT_FOUND;
1204 }
1205
1206 Status = EFI_SUCCESS;
1207 NewStringPackageCreated = FALSE;
1208 NewStringId = 0;
1209 NextStringId = 0;
1210 StringPackage = NULL;
1211 MatchStringPackage = NULL;
1212 for (Link = PackageListNode->StringPkgHdr.ForwardLink;
1213 Link != &PackageListNode->StringPkgHdr;
1214 Link = Link->ForwardLink
1215 ) {
1216 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1217 //
1218 // Create a string block and corresponding font block if exists, then append them
1219 // to the end of the string package.
1220 //
1221 Status = FindStringBlock (
1222 Private,
1223 StringPackage,
1224 0,
1225 NULL,
1226 NULL,
1227 NULL,
1228 &NextStringId,
1229 NULL
1230 );
1231 if (EFI_ERROR (Status)) {
1232 goto Done;
1233 }
1234 //
1235 // Make sure that new StringId is same in all String Packages for the different language.
1236 //
1237 if (NewStringId != 0 && NewStringId != NextStringId) {
1238 ASSERT (FALSE);
1239 Status = EFI_INVALID_PARAMETER;
1240 goto Done;
1241 }
1242 NewStringId = NextStringId;
1243 //
1244 // Get the matched string package with language.
1245 //
1246 if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {
1247 MatchStringPackage = StringPackage;
1248 } else {
1249 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;
1250 //
1251 // Create a blank EFI_HII_SIBT_STRING_UCS2_BLOCK to reserve new string ID.
1252 //
1253 Ucs2BlockSize = (UINT32) sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);
1254
1255 StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2BlockSize);
1256 if (StringBlock == NULL) {
1257 Status = EFI_OUT_OF_RESOURCES;
1258 goto Done;
1259 }
1260 //
1261 // Copy original string blocks, except the EFI_HII_SIBT_END.
1262 //
1263 CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));
1264 //
1265 // Create a blank EFI_HII_SIBT_STRING_UCS2 block
1266 //
1267 BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);
1268 *BlockPtr = EFI_HII_SIBT_STRING_UCS2;
1269 BlockPtr += sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);
1270
1271 //
1272 // Append a EFI_HII_SIBT_END block to the end.
1273 //
1274 *BlockPtr = EFI_HII_SIBT_END;
1275 FreePool (StringPackage->StringBlock);
1276 StringPackage->StringBlock = StringBlock;
1277 StringPackage->StringPkgHdr->Header.Length += Ucs2BlockSize;
1278 PackageListNode->PackageListHdr.PackageLength += Ucs2BlockSize;
1279 }
1280 }
1281 if (NewStringId == 0) {
1282 //
1283 // No string package is found.
1284 // Create new string package. StringId 1 is reserved for Language Name string.
1285 //
1286 *StringId = 2;
1287 } else {
1288 //
1289 // Set new StringId
1290 //
1291 *StringId = (EFI_STRING_ID) (NewStringId + 1);
1292 }
1293
1294 if (MatchStringPackage != NULL) {
1295 StringPackage = MatchStringPackage;
1296 } else {
1297 //
1298 // LanguageName is required to create a new string package.
1299 //
1300 if (LanguageName == NULL) {
1301 Status = EFI_INVALID_PARAMETER;
1302 goto Done;
1303 }
1304
1305 StringPackage = AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE));
1306 if (StringPackage == NULL) {
1307 Status = EFI_OUT_OF_RESOURCES;
1308 goto Done;
1309 }
1310
1311 StringPackage->Signature = HII_STRING_PACKAGE_SIGNATURE;
1312 StringPackage->MaxStringId = *StringId;
1313 StringPackage->FontId = 0;
1314 InitializeListHead (&StringPackage->FontInfoList);
1315
1316 //
1317 // Fill in the string package header
1318 //
1319 HeaderSize = (UINT32) (AsciiStrSize ((CHAR8 *) Language) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR));
1320 StringPackage->StringPkgHdr = AllocateZeroPool (HeaderSize);
1321 if (StringPackage->StringPkgHdr == NULL) {
1322 FreePool (StringPackage);
1323 Status = EFI_OUT_OF_RESOURCES;
1324 goto Done;
1325 }
1326 StringPackage->StringPkgHdr->Header.Type = EFI_HII_PACKAGE_STRINGS;
1327 StringPackage->StringPkgHdr->HdrSize = HeaderSize;
1328 StringPackage->StringPkgHdr->StringInfoOffset = HeaderSize;
1329 CopyMem (StringPackage->StringPkgHdr->LanguageWindow, mLanguageWindow, 16 * sizeof (CHAR16));
1330 StringPackage->StringPkgHdr->LanguageName = 1;
1331 AsciiStrCpy (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language);
1332
1333 //
1334 // Calculate the length of the string blocks, including string block to record
1335 // printable language full name and EFI_HII_SIBT_END_BLOCK.
1336 //
1337 Ucs2BlockSize = (UINT32) (StrSize ((CHAR16 *) LanguageName) +
1338 (*StringId - 1) * sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16));
1339
1340 BlockSize = Ucs2BlockSize + sizeof (EFI_HII_SIBT_END_BLOCK);
1341 StringPackage->StringBlock = (UINT8 *) AllocateZeroPool (BlockSize);
1342 if (StringPackage->StringBlock == NULL) {
1343 FreePool (StringPackage->StringPkgHdr);
1344 FreePool (StringPackage);
1345 Status = EFI_OUT_OF_RESOURCES;
1346 goto Done;
1347 }
1348
1349 //
1350 // Insert the string block of printable language full name
1351 //
1352 BlockPtr = StringPackage->StringBlock;
1353 *BlockPtr = EFI_HII_SIBT_STRING_UCS2;
1354 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);
1355 CopyMem (BlockPtr, (EFI_STRING) LanguageName, StrSize ((EFI_STRING) LanguageName));
1356 BlockPtr += StrSize ((EFI_STRING) LanguageName);
1357 for (Index = 2; Index <= *StringId - 1; Index ++) {
1358 *BlockPtr = EFI_HII_SIBT_STRING_UCS2;
1359 BlockPtr += sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);
1360 }
1361 //
1362 // Insert the end block
1363 //
1364 *BlockPtr = EFI_HII_SIBT_END;
1365
1366 //
1367 // Append this string package node to string package array in this package list.
1368 //
1369 StringPackage->StringPkgHdr->Header.Length = HeaderSize + BlockSize;
1370 PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length;
1371 InsertTailList (&PackageListNode->StringPkgHdr, &StringPackage->StringEntry);
1372 NewStringPackageCreated = TRUE;
1373 }
1374
1375 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;
1376
1377 if (StringFontInfo == NULL) {
1378 //
1379 // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.
1380 //
1381 Ucs2BlockSize = (UINT32) (StrSize (String) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK)
1382 - sizeof (CHAR16));
1383
1384 StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2BlockSize);
1385 if (StringBlock == NULL) {
1386 Status = EFI_OUT_OF_RESOURCES;
1387 goto Done;
1388 }
1389 //
1390 // Copy original string blocks, except the EFI_HII_SIBT_END.
1391 //
1392 CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));
1393 //
1394 // Create a EFI_HII_SIBT_STRING_UCS2 block
1395 //
1396 BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);
1397 *BlockPtr = EFI_HII_SIBT_STRING_UCS2;
1398 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);
1399 CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));
1400 BlockPtr += StrSize ((EFI_STRING) String);
1401
1402 //
1403 // Append a EFI_HII_SIBT_END block to the end.
1404 //
1405 *BlockPtr = EFI_HII_SIBT_END;
1406 FreePool (StringPackage->StringBlock);
1407 StringPackage->StringBlock = StringBlock;
1408 StringPackage->StringPkgHdr->Header.Length += Ucs2BlockSize;
1409 PackageListNode->PackageListHdr.PackageLength += Ucs2BlockSize;
1410
1411 } else {
1412 //
1413 // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK
1414 // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block
1415 // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING
1416 // _UCS2_FONT block.
1417 //
1418 Ucs2FontBlockSize = (UINT32) (StrSize (String) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) -
1419 sizeof (CHAR16));
1420 if (ReferFontInfoLocally (Private, StringPackage, StringPackage->FontId, FALSE, GlobalFont, &LocalFont)) {
1421 //
1422 // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.
1423 //
1424 StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2FontBlockSize);
1425 if (StringBlock == NULL) {
1426 Status = EFI_OUT_OF_RESOURCES;
1427 goto Done;
1428 }
1429 //
1430 // Copy original string blocks, except the EFI_HII_SIBT_END.
1431 //
1432 CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));
1433 //
1434 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1435 //
1436 BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);
1437 *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;
1438 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);
1439 *BlockPtr = LocalFont->FontId;
1440 BlockPtr += sizeof (UINT8);
1441 CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));
1442 BlockPtr += StrSize ((EFI_STRING) String);
1443
1444 //
1445 // Append a EFI_HII_SIBT_END block to the end.
1446 //
1447 *BlockPtr = EFI_HII_SIBT_END;
1448 FreePool (StringPackage->StringBlock);
1449 StringPackage->StringBlock = StringBlock;
1450 StringPackage->StringPkgHdr->Header.Length += Ucs2FontBlockSize;
1451 PackageListNode->PackageListHdr.PackageLength += Ucs2FontBlockSize;
1452
1453 } else {
1454 //
1455 // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so
1456 // create a EFI_HII_SIBT_FONT block to record the font info, then generate
1457 // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.
1458 //
1459 FontBlockSize = (UINT32) (StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName) +
1460 sizeof (EFI_HII_SIBT_FONT_BLOCK) - sizeof (CHAR16));
1461 StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + FontBlockSize + Ucs2FontBlockSize);
1462 if (StringBlock == NULL) {
1463 Status = EFI_OUT_OF_RESOURCES;
1464 goto Done;
1465 }
1466 //
1467 // Copy original string blocks, except the EFI_HII_SIBT_END.
1468 //
1469 CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));
1470
1471 //
1472 // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string
1473 // package instance for future reference.
1474 //
1475 BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);
1476
1477 Ext2.Header.BlockType = EFI_HII_SIBT_EXT2;
1478 Ext2.BlockType2 = EFI_HII_SIBT_FONT;
1479 Ext2.Length = (UINT16) FontBlockSize;
1480 CopyMem (BlockPtr, &Ext2, sizeof (EFI_HII_SIBT_EXT2_BLOCK));
1481 BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);
1482
1483 *BlockPtr = LocalFont->FontId;
1484 BlockPtr += sizeof (UINT8);
1485 CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontSize, sizeof (UINT16));
1486 BlockPtr += sizeof (UINT16);
1487 CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontStyle, sizeof (EFI_HII_FONT_STYLE));
1488 BlockPtr += sizeof (EFI_HII_FONT_STYLE);
1489 CopyMem (
1490 BlockPtr,
1491 &((EFI_FONT_INFO *) StringFontInfo)->FontName,
1492 StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName)
1493 );
1494 BlockPtr += StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName);
1495 //
1496 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1497 //
1498 *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;
1499 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);
1500 *BlockPtr = LocalFont->FontId;
1501 BlockPtr += sizeof (UINT8);
1502 CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));
1503 BlockPtr += StrSize ((EFI_STRING) String);
1504
1505 //
1506 // Append a EFI_HII_SIBT_END block to the end.
1507 //
1508 *BlockPtr = EFI_HII_SIBT_END;
1509 FreePool (StringPackage->StringBlock);
1510 StringPackage->StringBlock = StringBlock;
1511 StringPackage->StringPkgHdr->Header.Length += FontBlockSize + Ucs2FontBlockSize;
1512 PackageListNode->PackageListHdr.PackageLength += FontBlockSize + Ucs2FontBlockSize;
1513
1514 //
1515 // Increase the FontId to make it unique since we already add
1516 // a EFI_HII_SIBT_FONT block to this string package.
1517 //
1518 StringPackage->FontId++;
1519 }
1520 }
1521
1522 Done:
1523 if (!EFI_ERROR (Status) && NewStringPackageCreated) {
1524 //
1525 // Trigger any registered notification function for new string package
1526 //
1527 Status = InvokeRegisteredFunction (
1528 Private,
1529 EFI_HII_DATABASE_NOTIFY_NEW_PACK,
1530 (VOID *) StringPackage,
1531 EFI_HII_PACKAGE_STRINGS,
1532 PackageList
1533 );
1534 }
1535
1536 if (!EFI_ERROR (Status)) {
1537 //
1538 // Update MaxString Id to new StringId
1539 //
1540 for (Link = PackageListNode->StringPkgHdr.ForwardLink;
1541 Link != &PackageListNode->StringPkgHdr;
1542 Link = Link->ForwardLink
1543 ) {
1544 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1545 StringPackage->MaxStringId = *StringId;
1546 }
1547 } else if (NewStringPackageCreated) {
1548 //
1549 // Free the allocated new string Package when new string can't be added.
1550 //
1551 RemoveEntryList (&StringPackage->StringEntry);
1552 FreePool (StringPackage->StringBlock);
1553 FreePool (StringPackage->StringPkgHdr);
1554 FreePool (StringPackage);
1555 }
1556
1557 return Status;
1558 }
1559
1560
1561 /**
1562 This function retrieves the string specified by StringId which is associated
1563 with the specified PackageList in the language Language and copies it into
1564 the buffer specified by String.
1565
1566 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1567 @param Language Points to the language for the retrieved string.
1568 @param PackageList The package list in the HII database to search for
1569 the specified string.
1570 @param StringId The string's id, which is unique within
1571 PackageList.
1572 @param String Points to the new null-terminated string.
1573 @param StringSize On entry, points to the size of the buffer pointed
1574 to by String, in bytes. On return, points to the
1575 length of the string, in bytes.
1576 @param StringFontInfo If not NULL, points to the string's font
1577 information. It's caller's responsibility to free
1578 this buffer.
1579
1580 @retval EFI_SUCCESS The string was returned successfully.
1581 @retval EFI_NOT_FOUND The string specified by StringId is not available.
1582 @retval EFI_NOT_FOUND The string specified by StringId is available but
1583 not in the specified language.
1584 The specified PackageList is not in the database.
1585 @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but
1586 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
1587 hold the string.
1588 @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL.
1589 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
1590 request.
1591
1592 **/
1593 EFI_STATUS
1594 EFIAPI
1595 HiiGetString (
1596 IN CONST EFI_HII_STRING_PROTOCOL *This,
1597 IN CONST CHAR8 *Language,
1598 IN EFI_HII_HANDLE PackageList,
1599 IN EFI_STRING_ID StringId,
1600 OUT EFI_STRING String,
1601 IN OUT UINTN *StringSize,
1602 OUT EFI_FONT_INFO **StringFontInfo OPTIONAL
1603 )
1604 {
1605 EFI_STATUS Status;
1606 LIST_ENTRY *Link;
1607 HII_DATABASE_PRIVATE_DATA *Private;
1608 HII_DATABASE_RECORD *DatabaseRecord;
1609 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
1610 HII_STRING_PACKAGE_INSTANCE *StringPackage;
1611
1612 if (This == NULL || Language == NULL || StringId < 1 || StringSize == NULL || PackageList == NULL) {
1613 return EFI_INVALID_PARAMETER;
1614 }
1615
1616 if (String == NULL && *StringSize != 0) {
1617 return EFI_INVALID_PARAMETER;
1618 }
1619
1620 if (!IsHiiHandleValid (PackageList)) {
1621 return EFI_NOT_FOUND;
1622 }
1623
1624 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1625 PackageListNode = NULL;
1626
1627 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
1628 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
1629 if (DatabaseRecord->Handle == PackageList) {
1630 PackageListNode = DatabaseRecord->PackageList;
1631 break;
1632 }
1633 }
1634
1635 if (PackageListNode != NULL) {
1636 //
1637 // First search: to match the StringId in the specified language.
1638 //
1639 for (Link = PackageListNode->StringPkgHdr.ForwardLink;
1640 Link != &PackageListNode->StringPkgHdr;
1641 Link = Link->ForwardLink
1642 ) {
1643 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1644 if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {
1645 Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo);
1646 if (Status != EFI_NOT_FOUND) {
1647 return Status;
1648 }
1649 }
1650 }
1651 //
1652 // Second search: to match the StringId in other available languages if exist.
1653 //
1654 for (Link = PackageListNode->StringPkgHdr.ForwardLink;
1655 Link != &PackageListNode->StringPkgHdr;
1656 Link = Link->ForwardLink
1657 ) {
1658 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1659 Status = GetStringWorker (Private, StringPackage, StringId, NULL, NULL, NULL);
1660 if (!EFI_ERROR (Status)) {
1661 return EFI_INVALID_LANGUAGE;
1662 }
1663 }
1664 }
1665
1666 return EFI_NOT_FOUND;
1667 }
1668
1669
1670
1671 /**
1672 This function updates the string specified by StringId in the specified PackageList to the text
1673 specified by String and, optionally, the font information specified by StringFontInfo.
1674
1675 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1676 @param PackageList The package list containing the strings.
1677 @param StringId The string's id, which is unique within
1678 PackageList.
1679 @param Language Points to the language for the updated string.
1680 @param String Points to the new null-terminated string.
1681 @param StringFontInfo Points to the string's font information or NULL if
1682 the string font information is not changed.
1683
1684 @retval EFI_SUCCESS The string was updated successfully.
1685 @retval EFI_NOT_FOUND The string specified by StringId is not in the
1686 database.
1687 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
1688 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1689 current database.
1690 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
1691 task.
1692
1693 **/
1694 EFI_STATUS
1695 EFIAPI
1696 HiiSetString (
1697 IN CONST EFI_HII_STRING_PROTOCOL *This,
1698 IN EFI_HII_HANDLE PackageList,
1699 IN EFI_STRING_ID StringId,
1700 IN CONST CHAR8 *Language,
1701 IN CONST EFI_STRING String,
1702 IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL
1703 )
1704 {
1705 EFI_STATUS Status;
1706 LIST_ENTRY *Link;
1707 HII_DATABASE_PRIVATE_DATA *Private;
1708 HII_DATABASE_RECORD *DatabaseRecord;
1709 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
1710 HII_STRING_PACKAGE_INSTANCE *StringPackage;
1711 UINT32 OldPackageLen;
1712
1713 if (This == NULL || Language == NULL || StringId < 1 || String == NULL || PackageList == NULL) {
1714 return EFI_INVALID_PARAMETER;
1715 }
1716
1717 if (!IsHiiHandleValid (PackageList)) {
1718 return EFI_NOT_FOUND;
1719 }
1720
1721 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1722 PackageListNode = NULL;
1723
1724 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
1725 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
1726 if (DatabaseRecord->Handle == PackageList) {
1727 PackageListNode = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (DatabaseRecord->PackageList);
1728 }
1729 }
1730
1731 if (PackageListNode != NULL) {
1732 for (Link = PackageListNode->StringPkgHdr.ForwardLink;
1733 Link != &PackageListNode->StringPkgHdr;
1734 Link = Link->ForwardLink
1735 ) {
1736 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1737 if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {
1738 OldPackageLen = StringPackage->StringPkgHdr->Header.Length;
1739 Status = SetStringWorker (
1740 Private,
1741 StringPackage,
1742 StringId,
1743 (EFI_STRING) String,
1744 (EFI_FONT_INFO *) StringFontInfo
1745 );
1746 if (EFI_ERROR (Status)) {
1747 return Status;
1748 }
1749 PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length - OldPackageLen;
1750 return EFI_SUCCESS;
1751 }
1752 }
1753 }
1754
1755 return EFI_NOT_FOUND;
1756 }
1757
1758
1759
1760 /**
1761 This function returns the list of supported languages, in the format specified
1762 in Appendix M of UEFI 2.1 spec.
1763
1764 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1765 @param PackageList The package list to examine.
1766 @param Languages Points to the buffer to hold the returned string.
1767 @param LanguagesSize On entry, points to the size of the buffer pointed
1768 to by Languages, in bytes. On return, points to
1769 the length of Languages, in bytes.
1770
1771 @retval EFI_SUCCESS The languages were returned successfully.
1772 @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL.
1773 @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of
1774 supported languages. LanguageSize is updated to
1775 contain the required size.
1776 @retval EFI_NOT_FOUND Could not find string package in specified
1777 packagelist.
1778
1779 **/
1780 EFI_STATUS
1781 EFIAPI
1782 HiiGetLanguages (
1783 IN CONST EFI_HII_STRING_PROTOCOL *This,
1784 IN EFI_HII_HANDLE PackageList,
1785 IN OUT CHAR8 *Languages,
1786 IN OUT UINTN *LanguagesSize
1787 )
1788 {
1789 LIST_ENTRY *Link;
1790 HII_DATABASE_PRIVATE_DATA *Private;
1791 HII_DATABASE_RECORD *DatabaseRecord;
1792 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
1793 HII_STRING_PACKAGE_INSTANCE *StringPackage;
1794 UINTN ResultSize;
1795
1796 if (This == NULL || Languages == NULL || LanguagesSize == NULL || PackageList == NULL) {
1797 return EFI_INVALID_PARAMETER;
1798 }
1799 if (!IsHiiHandleValid (PackageList)) {
1800 return EFI_NOT_FOUND;
1801 }
1802
1803 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1804
1805 PackageListNode = NULL;
1806 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
1807 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
1808 if (DatabaseRecord->Handle == PackageList) {
1809 PackageListNode = DatabaseRecord->PackageList;
1810 break;
1811 }
1812 }
1813 if (PackageListNode == NULL) {
1814 return EFI_NOT_FOUND;
1815 }
1816
1817 //
1818 // Search the languages in the specified packagelist.
1819 //
1820 ResultSize = 0;
1821 for (Link = PackageListNode->StringPkgHdr.ForwardLink;
1822 Link != &PackageListNode->StringPkgHdr;
1823 Link = Link->ForwardLink
1824 ) {
1825 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1826 ResultSize += AsciiStrSize (StringPackage->StringPkgHdr->Language);
1827 if (ResultSize <= *LanguagesSize) {
1828 AsciiStrCpy (Languages, StringPackage->StringPkgHdr->Language);
1829 Languages += AsciiStrSize (StringPackage->StringPkgHdr->Language);
1830 *(Languages - 1) = L';';
1831 }
1832 }
1833 if (ResultSize == 0) {
1834 return EFI_NOT_FOUND;
1835 }
1836
1837 if (*LanguagesSize < ResultSize) {
1838 *LanguagesSize = ResultSize;
1839 return EFI_BUFFER_TOO_SMALL;
1840 }
1841
1842 *(Languages - 1) = 0;
1843 return EFI_SUCCESS;
1844 }
1845
1846
1847 /**
1848 Each string package has associated with it a single primary language and zero
1849 or more secondary languages. This routine returns the secondary languages
1850 associated with a package list.
1851
1852 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1853 @param PackageList The package list to examine.
1854 @param FirstLanguage Points to the primary language.
1855 @param SecondaryLanguages Points to the buffer to hold the returned list of
1856 secondary languages for the specified
1857 FirstLanguage. If there are no secondary
1858 languages, the function returns successfully, but
1859 this is set to NULL.
1860 @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed
1861 to by SecondaryLanguages, in bytes. On return,
1862 points to the length of SecondaryLanguages in bytes.
1863
1864 @retval EFI_SUCCESS Secondary languages were correctly returned.
1865 @retval EFI_INVALID_PARAMETER FirstLanguage or SecondaryLanguages or
1866 SecondaryLanguagesSize was NULL.
1867 @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is
1868 too small to hold the returned information.
1869 SecondLanguageSize is updated to hold the size of
1870 the buffer required.
1871 @retval EFI_INVALID_LANGUAGE The language specified by FirstLanguage is not
1872 present in the specified package list.
1873 @retval EFI_NOT_FOUND The specified PackageList is not in the Database.
1874
1875 **/
1876 EFI_STATUS
1877 EFIAPI
1878 HiiGetSecondaryLanguages (
1879 IN CONST EFI_HII_STRING_PROTOCOL *This,
1880 IN EFI_HII_HANDLE PackageList,
1881 IN CONST CHAR8 *FirstLanguage,
1882 IN OUT CHAR8 *SecondaryLanguages,
1883 IN OUT UINTN *SecondaryLanguagesSize
1884 )
1885 {
1886 LIST_ENTRY *Link;
1887 LIST_ENTRY *Link1;
1888 HII_DATABASE_PRIVATE_DATA *Private;
1889 HII_DATABASE_RECORD *DatabaseRecord;
1890 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;
1891 HII_STRING_PACKAGE_INSTANCE *StringPackage;
1892 CHAR8 *Languages;
1893 UINTN ResultSize;
1894
1895 if (This == NULL || PackageList == NULL || FirstLanguage == NULL) {
1896 return EFI_INVALID_PARAMETER;
1897 }
1898 if (SecondaryLanguages == NULL || SecondaryLanguagesSize == NULL) {
1899 return EFI_INVALID_PARAMETER;
1900 }
1901 if (!IsHiiHandleValid (PackageList)) {
1902 return EFI_NOT_FOUND;
1903 }
1904
1905 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1906
1907 PackageListNode = NULL;
1908 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
1909 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
1910 if (DatabaseRecord->Handle == PackageList) {
1911 PackageListNode = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (DatabaseRecord->PackageList);
1912 break;
1913 }
1914 }
1915 if (PackageListNode == NULL) {
1916 return EFI_NOT_FOUND;
1917 }
1918
1919 Languages = NULL;
1920 ResultSize = 0;
1921 for (Link1 = PackageListNode->StringPkgHdr.ForwardLink;
1922 Link1 != &PackageListNode->StringPkgHdr;
1923 Link1 = Link1->ForwardLink
1924 ) {
1925 StringPackage = CR (Link1, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
1926 if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) FirstLanguage)) {
1927 Languages = StringPackage->StringPkgHdr->Language;
1928 //
1929 // Language is a series of ';' terminated strings, first one is primary
1930 // language and following with other secondary languages or NULL if no
1931 // secondary languages any more.
1932 //
1933 Languages = AsciiStrStr (Languages, ";");
1934 if (Languages == NULL) {
1935 break;
1936 }
1937 Languages++;
1938
1939 ResultSize = AsciiStrSize (Languages);
1940 if (ResultSize <= *SecondaryLanguagesSize) {
1941 AsciiStrCpy (SecondaryLanguages, Languages);
1942 } else {
1943 *SecondaryLanguagesSize = ResultSize;
1944 return EFI_BUFFER_TOO_SMALL;
1945 }
1946
1947 return EFI_SUCCESS;
1948 }
1949 }
1950
1951 return EFI_INVALID_LANGUAGE;
1952 }
1953
1954 /**
1955 Compare whether two names of languages are identical.
1956
1957 @param Language1 Name of language 1
1958 @param Language2 Name of language 2
1959
1960 @retval TRUE same
1961 @retval FALSE not same
1962
1963 **/
1964 BOOLEAN
1965 HiiCompareLanguage (
1966 IN CHAR8 *Language1,
1967 IN CHAR8 *Language2
1968 )
1969 {
1970 if (GetBestLanguage (Language1, FALSE, Language2, NULL) != NULL) {
1971 return TRUE;
1972 }
1973
1974 return FALSE;
1975 }