2 Module produce UC2 on top of UC.
4 UEFI 2.1 specification supersedes Inte's EFI Specification 1.10.
5 EFI_UNICODE_COLLATION_PROTOCOL defined in Inte's EFI Specification 1.10 is replaced by
6 EFI_UNICODE_COLLATION_PROTOCOL in UEFI 2.1.
7 This module produces UC2 on top of UC. This module is used on platform when both of
8 these two conditions are true:
9 1) EFI 1.10 module producing UC present
10 2) And the rest of modules on the platform consume UC2
12 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
13 All rights reserved. This program and the accompanying materials
14 are licensed and made available under the terms and conditions of the BSD License
15 which accompanies this distribution. The full text of the license may be found at
16 http://opensource.org/licenses/bsd-license.php
18 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
19 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 #include <Protocol/UnicodeCollation.h>
26 #include <Library/BaseLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/HiiLib.h>
33 #include <Library/BaseMemoryLib.h>
37 /// The size of a 3 character ISO639 language code.
39 #define ISO_639_2_ENTRY_SIZE 3
42 // Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
43 // Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
44 // The last 2 CHAR8 values are the ISO 639-1 code.
46 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc4646ConversionTable
[] =
186 Convert language code from ISO639-2 to RFC4646 and return the converted language.
187 Caller is responsible for freeing the allocated buffer.
189 LanguageIso639 contain a single ISO639-2 code such as
192 If LanguageIso639 is NULL, then ASSERT.
193 If LanguageRfc4646 is NULL, then ASSERT.
195 @param LanguageIso639 ISO639-2 language code.
197 @return the allocated buffer or NULL, if the language is not found.
202 ConvertIso639LanguageToRfc4646Language (
203 IN CONST CHAR8
*LanguageIso639
207 CHAR8
*Rfc4646Language
;
209 for (Index
= 0; Iso639ToRfc4646ConversionTable
[Index
] != 0; Index
+= 5) {
210 if (CompareMem (LanguageIso639
, &Iso639ToRfc4646ConversionTable
[Index
], 3) == 0) {
211 Rfc4646Language
= AllocateZeroPool (3);
212 if (Rfc4646Language
!= NULL
) {
213 Rfc4646Language
= CopyMem (Rfc4646Language
, &Iso639ToRfc4646ConversionTable
[Index
+ 3], 2);
215 return Rfc4646Language
;
223 Performs a case-insensitive comparison of two Null-terminated Unicode
226 @param This Protocol instance pointer.
227 @param Str1 A pointer to a Null-terminated Unicode string.
228 @param Str2 A pointer to a Null-terminated Unicode string.
230 @retval 0 Str1 is equivalent to Str2
231 @retval > 0 Str1 is lexically greater than Str2
232 @retval < 0 Str1 is lexically less than Str2
238 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
244 Converts all the Unicode characters in a Null-terminated Unicode string to
245 lower case Unicode characters.
247 @param This Protocol instance pointer.
248 @param Str A pointer to a Null-terminated Unicode string.
254 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
259 Converts all the Unicode characters in a Null-terminated Unicode string to upper
260 case Unicode characters.
262 @param This Protocol instance pointer.
263 @param Str A pointer to a Null-terminated Unicode string.
269 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
274 Performs a case-insensitive comparison of a Null-terminated Unicode
275 pattern string and a Null-terminated Unicode string.
277 @param This Protocol instance pointer.
278 @param String A pointer to a Null-terminated Unicode string.
279 @param Pattern A pointer to a Null-terminated Unicode pattern string.
281 @retval TRUE Pattern was found in String.
282 @retval FALSE Pattern was not found in String.
288 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
294 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
297 @param This Protocol instance pointer.
298 @param FatSize The size of the string Fat in bytes.
299 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
300 name using an OEM character set.
301 @param String A pointer to a Null-terminated Unicode string. The string must
302 be preallocated to hold FatSize Unicode characters.
308 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
315 Converts a Null-terminated Unicode string to legal characters in a FAT
316 filename using an OEM character set.
318 @param This Protocol instance pointer.
319 @param String A pointer to a Null-terminated Unicode string. The string must
320 be preallocated to hold FatSize Unicode characters.
321 @param FatSize The size of the string Fat in bytes.
322 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
323 name using an OEM character set.
325 @retval TRUE Fat is a Long File Name
326 @retval FALSE Fat is an 8.3 file name
332 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
338 #define UC2_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '2')
342 EFI_UNICODE_COLLATION_PROTOCOL UC2
;
343 EFI_UNICODE_COLLATION_PROTOCOL
*UC
;
346 #define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, UC2, UC2_PRIVATE_DATA_SIGNATURE)
349 // Firmware Volume Protocol template
351 EFI_EVENT mUc2Registration
;
353 UC2_PRIVATE_DATA gUC2PrivateDataTemplate
= {
354 UC2_PRIVATE_DATA_SIGNATURE
,
373 UcNotificationEvent (
381 UC2_PRIVATE_DATA
*Private
;
382 EFI_UNICODE_COLLATION_PROTOCOL
*Uc2
;
385 BufferSize
= sizeof (Handle
);
386 Status
= gBS
->LocateHandle (
388 &gEfiUnicodeCollationProtocolGuid
,
393 if (EFI_ERROR (Status
)) {
395 // Exit Path of While Loop....
401 // Skip this handle if the Firmware Volume Protocol is already installed
403 Status
= gBS
->HandleProtocol (
405 &gEfiUnicodeCollation2ProtocolGuid
,
408 if (!EFI_ERROR (Status
)) {
413 // Allocate private data structure
415 Private
= AllocateCopyPool (sizeof (UC2_PRIVATE_DATA
), &gUC2PrivateDataTemplate
);
416 if (Private
== NULL
) {
421 // Retrieve the UC Protocol
423 Status
= gBS
->HandleProtocol (
425 &gEfiUnicodeCollationProtocolGuid
,
426 (VOID
**)&Private
->UC
428 ASSERT_EFI_ERROR (Status
);
431 // Fill in rest of private data structure
433 Private
->UC2
.SupportedLanguages
= ConvertIso639LanguageToRfc4646Language (Private
->UC
->SupportedLanguages
);
434 if (Private
->UC2
.SupportedLanguages
!= NULL
) {
437 // Install Firmware Volume Protocol onto same handle
439 Status
= gBS
->InstallMultipleProtocolInterfaces (
441 &gEfiUnicodeCollation2ProtocolGuid
,
445 ASSERT_EFI_ERROR (Status
);
452 The user Entry Point for DXE driver. The user code starts with this function
453 as the real entry point for the image goes into a library that calls this
456 @param[in] ImageHandle The firmware allocated handle for the EFI image.
457 @param[in] SystemTable A pointer to the EFI System Table.
459 @retval EFI_SUCCESS The entry point is executed successfully.
460 @retval other Some error occurs when executing this entry point.
466 IN EFI_HANDLE ImageHandle
,
467 IN EFI_SYSTEM_TABLE
*SystemTable
470 EfiCreateProtocolNotifyEvent (
471 &gEfiUnicodeCollationProtocolGuid
,
482 Performs a case-insensitive comparison of two Null-terminated Unicode
485 @param This Protocol instance pointer.
486 @param Str1 A pointer to a Null-terminated Unicode string.
487 @param Str2 A pointer to a Null-terminated Unicode string.
489 @retval 0 Str1 is equivalent to Str2
490 @retval > 0 Str1 is lexically greater than Str2
491 @retval < 0 Str1 is lexically less than Str2
497 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
502 UC2_PRIVATE_DATA
*Private
;
504 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
506 return Private
->UC
->StriColl (Private
->UC
, Str1
, Str2
);
511 Converts all the Unicode characters in a Null-terminated Unicode string to
512 lower case Unicode characters.
514 @param This Protocol instance pointer.
515 @param Str A pointer to a Null-terminated Unicode string.
521 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
525 UC2_PRIVATE_DATA
*Private
;
527 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
529 Private
->UC
->StrLwr (Private
->UC
, Str
);
534 Converts all the Unicode characters in a Null-terminated Unicode string to upper
535 case Unicode characters.
537 @param This Protocol instance pointer.
538 @param Str A pointer to a Null-terminated Unicode string.
544 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
548 UC2_PRIVATE_DATA
*Private
;
550 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
552 Private
->UC
->StrUpr (Private
->UC
, Str
);
556 Performs a case-insensitive comparison of a Null-terminated Unicode
557 pattern string and a Null-terminated Unicode string.
559 @param This Protocol instance pointer.
560 @param String A pointer to a Null-terminated Unicode string.
561 @param Pattern A pointer to a Null-terminated Unicode pattern string.
563 @retval TRUE Pattern was found in String.
564 @retval FALSE Pattern was not found in String.
570 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
575 UC2_PRIVATE_DATA
*Private
;
577 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
579 return Private
->UC
->MetaiMatch (Private
->UC
, String
, Pattern
);
584 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
587 @param This Protocol instance pointer.
588 @param FatSize The size of the string Fat in bytes.
589 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
590 name using an OEM character set.
591 @param String A pointer to a Null-terminated Unicode string. The string must
592 be preallocated to hold FatSize Unicode characters.
598 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
604 UC2_PRIVATE_DATA
*Private
;
606 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
608 Private
->UC
->FatToStr (Private
->UC
, FatSize
, Fat
, String
);
613 Converts a Null-terminated Unicode string to legal characters in a FAT
614 filename using an OEM character set.
616 @param This Protocol instance pointer.
617 @param String A pointer to a Null-terminated Unicode string. The string must
618 be preallocated to hold FatSize Unicode characters.
619 @param FatSize The size of the string Fat in bytes.
620 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
621 name using an OEM character set.
623 @retval TRUE Fat is a Long File Name
624 @retval FALSE Fat is an 8.3 file name
630 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
636 UC2_PRIVATE_DATA
*Private
;
638 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
640 return Private
->UC
->StrToFat (Private
->UC
, String
, FatSize
, Fat
);