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>
36 /// The size of a 3 character ISO639 language code.
38 #define ISO_639_2_ENTRY_SIZE 3
42 Performs a case-insensitive comparison of two Null-terminated Unicode
45 @param This Protocol instance pointer.
46 @param Str1 A pointer to a Null-terminated Unicode string.
47 @param Str2 A pointer to a Null-terminated Unicode string.
49 @retval 0 Str1 is equivalent to Str2
50 @retval > 0 Str1 is lexically greater than Str2
51 @retval < 0 Str1 is lexically less than Str2
57 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
63 Converts all the Unicode characters in a Null-terminated Unicode string to
64 lower case Unicode characters.
66 @param This Protocol instance pointer.
67 @param Str A pointer to a Null-terminated Unicode string.
73 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
78 Converts all the Unicode characters in a Null-terminated Unicode string to upper
79 case Unicode characters.
81 @param This Protocol instance pointer.
82 @param Str A pointer to a Null-terminated Unicode string.
88 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
93 Performs a case-insensitive comparison of a Null-terminated Unicode
94 pattern string and a Null-terminated Unicode string.
96 @param This Protocol instance pointer.
97 @param String A pointer to a Null-terminated Unicode string.
98 @param Pattern A pointer to a Null-terminated Unicode pattern string.
100 @retval TRUE Pattern was found in String.
101 @retval FALSE Pattern was not found in String.
107 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
113 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
116 @param This Protocol instance pointer.
117 @param FatSize The size of the string Fat in bytes.
118 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
119 name using an OEM character set.
120 @param String A pointer to a Null-terminated Unicode string. The string must
121 be preallocated to hold FatSize Unicode characters.
127 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
134 Converts a Null-terminated Unicode string to legal characters in a FAT
135 filename using an OEM character set.
137 @param This Protocol instance pointer.
138 @param String A pointer to a Null-terminated Unicode string. The string must
139 be preallocated to hold FatSize Unicode characters.
140 @param FatSize The size of the string Fat in bytes.
141 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
142 name using an OEM character set.
144 @retval TRUE Fat is a Long File Name
145 @retval FALSE Fat is an 8.3 file name
151 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
157 #define UC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '_')
161 EFI_UNICODE_COLLATION_PROTOCOL UC
;
162 EFI_UNICODE_COLLATION_PROTOCOL
*UC2
;
165 #define UC_PRIVATE_DATA_FROM_THIS(a) CR (a, UC_PRIVATE_DATA, UC, UC_PRIVATE_DATA_SIGNATURE)
168 // Firmware Volume Protocol template
170 EFI_EVENT mUcRegistration
;
172 UC_PRIVATE_DATA gUCPrivateDataTemplate
= {
173 UC_PRIVATE_DATA_SIGNATURE
,
192 Uc2NotificationEvent (
200 UC_PRIVATE_DATA
*Private
;
201 EFI_UNICODE_COLLATION_PROTOCOL
*Uc2
;
204 BufferSize
= sizeof (Handle
);
205 Status
= gBS
->LocateHandle (
207 &gEfiUnicodeCollation2ProtocolGuid
,
212 if (EFI_ERROR (Status
)) {
214 // Exit Path of While Loop....
220 // Skip this handle if the Firmware Volume Protocol is already installed
222 Status
= gBS
->HandleProtocol (
224 &gEfiUnicodeCollationProtocolGuid
,
227 if (!EFI_ERROR (Status
)) {
232 // Allocate private data structure
234 Private
= AllocateCopyPool (sizeof (UC_PRIVATE_DATA
), &gUCPrivateDataTemplate
);
235 if (Private
== NULL
) {
240 // Retrieve the UC Protocol
242 Status
= gBS
->HandleProtocol (
244 &gEfiUnicodeCollation2ProtocolGuid
,
245 (VOID
**)&Private
->UC2
247 ASSERT_EFI_ERROR (Status
);
250 // Fill in rest of private data structure
252 Private
->UC
.SupportedLanguages
= AllocateZeroPool (ISO_639_2_ENTRY_SIZE
+ 1);
253 Status
= ConvertRfc3066LanguageToIso639Language (Private
->UC2
->SupportedLanguages
, Private
->UC
.SupportedLanguages
);
255 if (!EFI_ERROR (Status
)) {
258 // Install Firmware Volume Protocol onto same handle
260 Status
= gBS
->InstallMultipleProtocolInterfaces (
262 &gEfiUnicodeCollationProtocolGuid
,
266 ASSERT_EFI_ERROR (Status
);
273 The user Entry Point for DXE driver. The user code starts with this function
274 as the real entry point for the image goes into a library that calls this
277 @param[in] ImageHandle The firmware allocated handle for the EFI image.
278 @param[in] SystemTable A pointer to the EFI System Table.
280 @retval EFI_SUCCESS The entry point is executed successfully.
281 @retval other Some error occurs when executing this entry point.
287 IN EFI_HANDLE ImageHandle
,
288 IN EFI_SYSTEM_TABLE
*SystemTable
291 EfiCreateProtocolNotifyEvent (
292 &gEfiUnicodeCollation2ProtocolGuid
,
294 Uc2NotificationEvent
,
303 Performs a case-insensitive comparison of two Null-terminated Unicode
306 @param This Protocol instance pointer.
307 @param Str1 A pointer to a Null-terminated Unicode string.
308 @param Str2 A pointer to a Null-terminated Unicode string.
310 @retval 0 Str1 is equivalent to Str2
311 @retval > 0 Str1 is lexically greater than Str2
312 @retval < 0 Str1 is lexically less than Str2
318 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
323 UC_PRIVATE_DATA
*Private
;
325 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
327 return Private
->UC2
->StriColl (Private
->UC2
, Str1
, Str2
);
332 Converts all the Unicode characters in a Null-terminated Unicode string to
333 lower case Unicode characters.
335 @param This Protocol instance pointer.
336 @param Str A pointer to a Null-terminated Unicode string.
342 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
346 UC_PRIVATE_DATA
*Private
;
348 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
350 Private
->UC2
->StrLwr (Private
->UC2
, Str
);
355 Converts all the Unicode characters in a Null-terminated Unicode string to upper
356 case Unicode characters.
358 @param This Protocol instance pointer.
359 @param Str A pointer to a Null-terminated Unicode string.
365 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
369 UC_PRIVATE_DATA
*Private
;
371 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
373 Private
->UC2
->StrUpr (Private
->UC2
, Str
);
377 Performs a case-insensitive comparison of a Null-terminated Unicode
378 pattern string and a Null-terminated Unicode string.
380 @param This Protocol instance pointer.
381 @param String A pointer to a Null-terminated Unicode string.
382 @param Pattern A pointer to a Null-terminated Unicode pattern string.
384 @retval TRUE Pattern was found in String.
385 @retval FALSE Pattern was not found in String.
391 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
396 UC_PRIVATE_DATA
*Private
;
398 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
400 return Private
->UC2
->MetaiMatch (Private
->UC2
, String
, Pattern
);
405 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
408 @param This Protocol instance pointer.
409 @param FatSize The size of the string Fat in bytes.
410 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
411 name using an OEM character set.
412 @param String A pointer to a Null-terminated Unicode string. The string must
413 be preallocated to hold FatSize Unicode characters.
419 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
425 UC_PRIVATE_DATA
*Private
;
427 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
429 Private
->UC2
->FatToStr (Private
->UC2
, FatSize
, Fat
, String
);
434 Converts a Null-terminated Unicode string to legal characters in a FAT
435 filename using an OEM character set.
437 @param This Protocol instance pointer.
438 @param String A pointer to a Null-terminated Unicode string. The string must
439 be preallocated to hold FatSize Unicode characters.
440 @param FatSize The size of the string Fat in bytes.
441 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
442 name using an OEM character set.
444 @retval TRUE Fat is a Long File Name
445 @retval FALSE Fat is an 8.3 file name
451 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
457 UC_PRIVATE_DATA
*Private
;
459 Private
= UC_PRIVATE_DATA_FROM_THIS (This
);
461 return Private
->UC2
->StrToFat (Private
->UC2
, String
, FatSize
, Fat
);