2 Module produce UC on top of UC2.
4 UEFI 2.1 specification supersedes Inte's EFI Specification 1.10.
5 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 UC on top of UC2. This module is used on platform when both of
8 these two conditions are true:
9 1) EFI 1.10 module consuming UC present
10 2) And the rest of modules on the platform produce 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 RFC4646 to ISO639-2.
188 @param LanguageRfc4646 RFC4646 language code.
189 @param LanguageIso639 ISO639-2 language code.
191 @retval EFI_SUCCESS Language code converted.
192 @retval EFI_NOT_FOUND Language code not found.
197 ConvertRfc4646LanguageToIso639Language (
198 IN CHAR8
*LanguageRfc4646
,
199 OUT CHAR8
*LanguageIso639
204 if ((LanguageRfc4646
[2] != '-') && (LanguageRfc4646
[2] != 0)) {
205 CopyMem (LanguageIso639
, LanguageRfc4646
, 3);
209 for (Index
= 0; Iso639ToRfc4646ConversionTable
[Index
] != 0; Index
+= 5) {
210 if (CompareMem (LanguageRfc4646
, &Iso639ToRfc4646ConversionTable
[Index
+ 3], 2) == 0) {
211 CopyMem (LanguageIso639
, &Iso639ToRfc4646ConversionTable
[Index
], 3);
216 return EFI_NOT_FOUND
;
220 Performs a case-insensitive comparison of two Null-terminated Unicode
223 @param This Protocol instance pointer.
224 @param Str1 A pointer to a Null-terminated Unicode string.
225 @param Str2 A pointer to a Null-terminated Unicode string.
227 @retval 0 Str1 is equivalent to Str2
228 @retval > 0 Str1 is lexically greater than Str2
229 @retval < 0 Str1 is lexically less than Str2
235 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
241 Converts all the Unicode characters in a Null-terminated Unicode string to
242 lower case Unicode characters.
244 @param This Protocol instance pointer.
245 @param Str A pointer to a Null-terminated Unicode string.
251 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
256 Converts all the Unicode characters in a Null-terminated Unicode string to upper
257 case Unicode characters.
259 @param This Protocol instance pointer.
260 @param Str A pointer to a Null-terminated Unicode string.
266 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
271 Performs a case-insensitive comparison of a Null-terminated Unicode
272 pattern string and a Null-terminated Unicode string.
274 @param This Protocol instance pointer.
275 @param String A pointer to a Null-terminated Unicode string.
276 @param Pattern A pointer to a Null-terminated Unicode pattern string.
278 @retval TRUE Pattern was found in String.
279 @retval FALSE Pattern was not found in String.
285 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
291 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
294 @param This Protocol instance pointer.
295 @param FatSize The size of the string Fat in bytes.
296 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
297 name using an OEM character set.
298 @param String A pointer to a Null-terminated Unicode string. The string must
299 be preallocated to hold FatSize Unicode characters.
305 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
312 Converts a Null-terminated Unicode string to legal characters in a FAT
313 filename using an OEM character set.
315 @param This Protocol instance pointer.
316 @param String A pointer to a Null-terminated Unicode string. The string must
317 be preallocated to hold FatSize Unicode characters.
318 @param FatSize The size of the string Fat in bytes.
319 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
320 name using an OEM character set.
322 @retval TRUE Fat is a Long File Name
323 @retval FALSE Fat is an 8.3 file name
329 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
335 #define UC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '_')
339 EFI_UNICODE_COLLATION_PROTOCOL UC
;
340 EFI_UNICODE_COLLATION_PROTOCOL
*UC2
;
343 #define UC_PRIVATE_DATA_FROM_THIS(a) CR (a, UC_PRIVATE_DATA, UC, UC_PRIVATE_DATA_SIGNATURE)
346 // Firmware Volume Protocol template
348 EFI_EVENT mUcRegistration
;
350 UC_PRIVATE_DATA gUCPrivateDataTemplate
= {
351 UC_PRIVATE_DATA_SIGNATURE
,
370 Uc2NotificationEvent (
378 UC_PRIVATE_DATA
*Private
;
379 EFI_UNICODE_COLLATION_PROTOCOL
*Uc2
;
382 BufferSize
= sizeof (Handle
);
383 Status
= gBS
->LocateHandle (
385 &gEfiUnicodeCollation2ProtocolGuid
,
390 if (EFI_ERROR (Status
)) {
392 // Exit Path of While Loop....
398 // Skip this handle if the Firmware Volume Protocol is already installed
400 Status
= gBS
->HandleProtocol (
402 &gEfiUnicodeCollationProtocolGuid
,
405 if (!EFI_ERROR (Status
)) {
410 // Allocate private data structure
412 Private
= AllocateCopyPool (sizeof (UC_PRIVATE_DATA
), &gUCPrivateDataTemplate
);
413 if (Private
== NULL
) {
418 // Retrieve the UC Protocol
420 Status
= gBS
->HandleProtocol (
422 &gEfiUnicodeCollation2ProtocolGuid
,
423 (VOID
**)&Private
->UC2
425 ASSERT_EFI_ERROR (Status
);
428 // Fill in rest of private data structure
430 Private
->UC
.SupportedLanguages
= AllocateZeroPool (ISO_639_2_ENTRY_SIZE
+ 1);
431 Status
= ConvertRfc4646LanguageToIso639Language (Private
->UC2
->SupportedLanguages
, Private
->UC
.SupportedLanguages
);
433 if (!EFI_ERROR (Status
)) {
436 // Install Firmware Volume Protocol onto same handle
438 Status
= gBS
->InstallMultipleProtocolInterfaces (
440 &gEfiUnicodeCollationProtocolGuid
,
444 ASSERT_EFI_ERROR (Status
);
451 The user Entry Point for DXE driver. The user code starts with this function
452 as the real entry point for the image goes into a library that calls this
455 @param[in] ImageHandle The firmware allocated handle for the EFI image.
456 @param[in] SystemTable A pointer to the EFI System Table.
458 @retval EFI_SUCCESS The entry point is executed successfully.
459 @retval other Some error occurs when executing this entry point.
465 IN EFI_HANDLE ImageHandle
,
466 IN EFI_SYSTEM_TABLE
*SystemTable
469 EfiCreateProtocolNotifyEvent (
470 &gEfiUnicodeCollation2ProtocolGuid
,
472 Uc2NotificationEvent
,
481 Performs a case-insensitive comparison of two Null-terminated Unicode
484 @param This Protocol instance pointer.
485 @param Str1 A pointer to a Null-terminated Unicode string.
486 @param Str2 A pointer to a Null-terminated Unicode string.
488 @retval 0 Str1 is equivalent to Str2
489 @retval > 0 Str1 is lexically greater than Str2
490 @retval < 0 Str1 is lexically less than Str2
496 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
501 UC_PRIVATE_DATA
*Private
;
503 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
505 return Private
->UC2
->StriColl (Private
->UC2
, Str1
, Str2
);
510 Converts all the Unicode characters in a Null-terminated Unicode string to
511 lower case Unicode characters.
513 @param This Protocol instance pointer.
514 @param Str A pointer to a Null-terminated Unicode string.
520 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
524 UC_PRIVATE_DATA
*Private
;
526 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
528 Private
->UC2
->StrLwr (Private
->UC2
, Str
);
533 Converts all the Unicode characters in a Null-terminated Unicode string to upper
534 case Unicode characters.
536 @param This Protocol instance pointer.
537 @param Str A pointer to a Null-terminated Unicode string.
543 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
547 UC_PRIVATE_DATA
*Private
;
549 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
551 Private
->UC2
->StrUpr (Private
->UC2
, Str
);
555 Performs a case-insensitive comparison of a Null-terminated Unicode
556 pattern string and a Null-terminated Unicode string.
558 @param This Protocol instance pointer.
559 @param String A pointer to a Null-terminated Unicode string.
560 @param Pattern A pointer to a Null-terminated Unicode pattern string.
562 @retval TRUE Pattern was found in String.
563 @retval FALSE Pattern was not found in String.
569 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
574 UC_PRIVATE_DATA
*Private
;
576 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
578 return Private
->UC2
->MetaiMatch (Private
->UC2
, String
, Pattern
);
583 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
586 @param This Protocol instance pointer.
587 @param FatSize The size of the string Fat in bytes.
588 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
589 name using an OEM character set.
590 @param String A pointer to a Null-terminated Unicode string. The string must
591 be preallocated to hold FatSize Unicode characters.
597 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
603 UC_PRIVATE_DATA
*Private
;
605 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
607 Private
->UC2
->FatToStr (Private
->UC2
, FatSize
, Fat
, String
);
612 Converts a Null-terminated Unicode string to legal characters in a FAT
613 filename using an OEM character set.
615 @param This Protocol instance pointer.
616 @param String A pointer to a Null-terminated Unicode string. The string must
617 be preallocated to hold FatSize Unicode characters.
618 @param FatSize The size of the string Fat in bytes.
619 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
620 name using an OEM character set.
622 @retval TRUE Fat is a Long File Name
623 @retval FALSE Fat is an 8.3 file name
629 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
635 UC_PRIVATE_DATA
*Private
;
637 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
639 return Private
->UC2
->StrToFat (Private
->UC2
, String
, FatSize
, Fat
);