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>
36 /// The size of a 3 character ISO639 language code.
38 #define ISO_639_2_ENTRY_SIZE 3
41 Performs a case-insensitive comparison of two Null-terminated Unicode
44 @param This Protocol instance pointer.
45 @param Str1 A pointer to a Null-terminated Unicode string.
46 @param Str2 A pointer to a Null-terminated Unicode string.
48 @retval 0 Str1 is equivalent to Str2
49 @retval > 0 Str1 is lexically greater than Str2
50 @retval < 0 Str1 is lexically less than Str2
56 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
62 Converts all the Unicode characters in a Null-terminated Unicode string to
63 lower case Unicode characters.
65 @param This Protocol instance pointer.
66 @param Str A pointer to a Null-terminated Unicode string.
72 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
77 Converts all the Unicode characters in a Null-terminated Unicode string to upper
78 case Unicode characters.
80 @param This Protocol instance pointer.
81 @param Str A pointer to a Null-terminated Unicode string.
87 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
92 Performs a case-insensitive comparison of a Null-terminated Unicode
93 pattern string and a Null-terminated Unicode string.
95 @param This Protocol instance pointer.
96 @param String A pointer to a Null-terminated Unicode string.
97 @param Pattern A pointer to a Null-terminated Unicode pattern string.
99 @retval TRUE Pattern was found in String.
100 @retval FALSE Pattern was not found in String.
106 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
112 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
115 @param This Protocol instance pointer.
116 @param FatSize The size of the string Fat in bytes.
117 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
118 name using an OEM character set.
119 @param String A pointer to a Null-terminated Unicode string. The string must
120 be preallocated to hold FatSize Unicode characters.
126 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
133 Converts a Null-terminated Unicode string to legal characters in a FAT
134 filename using an OEM character set.
136 @param This Protocol instance pointer.
137 @param String A pointer to a Null-terminated Unicode string. The string must
138 be preallocated to hold FatSize Unicode characters.
139 @param FatSize The size of the string Fat in bytes.
140 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
141 name using an OEM character set.
143 @retval TRUE Fat is a Long File Name
144 @retval FALSE Fat is an 8.3 file name
150 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
156 #define UC2_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '2')
160 EFI_UNICODE_COLLATION_PROTOCOL UC2
;
161 EFI_UNICODE_COLLATION_PROTOCOL
*UC
;
164 #define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, UC2, UC2_PRIVATE_DATA_SIGNATURE)
167 // Firmware Volume Protocol template
169 EFI_EVENT mUc2Registration
;
171 UC2_PRIVATE_DATA gUC2PrivateDataTemplate
= {
172 UC2_PRIVATE_DATA_SIGNATURE
,
191 UcNotificationEvent (
199 UC2_PRIVATE_DATA
*Private
;
200 EFI_UNICODE_COLLATION_PROTOCOL
*Uc2
;
203 BufferSize
= sizeof (Handle
);
204 Status
= gBS
->LocateHandle (
206 &gEfiUnicodeCollationProtocolGuid
,
211 if (EFI_ERROR (Status
)) {
213 // Exit Path of While Loop....
219 // Skip this handle if the Firmware Volume Protocol is already installed
221 Status
= gBS
->HandleProtocol (
223 &gEfiUnicodeCollation2ProtocolGuid
,
226 if (!EFI_ERROR (Status
)) {
231 // Allocate private data structure
233 Private
= AllocateCopyPool (sizeof (UC2_PRIVATE_DATA
), &gUC2PrivateDataTemplate
);
234 if (Private
== NULL
) {
239 // Retrieve the UC Protocol
241 Status
= gBS
->HandleProtocol (
243 &gEfiUnicodeCollationProtocolGuid
,
244 (VOID
**)&Private
->UC
246 ASSERT_EFI_ERROR (Status
);
249 // Fill in rest of private data structure
251 Private
->UC2
.SupportedLanguages
= ConvertIso639LanguageToRfc3066Language (Private
->UC
->SupportedLanguages
);
252 if (Private
->UC2
.SupportedLanguages
!= NULL
) {
255 // Install Firmware Volume Protocol onto same handle
257 Status
= gBS
->InstallMultipleProtocolInterfaces (
259 &gEfiUnicodeCollation2ProtocolGuid
,
263 ASSERT_EFI_ERROR (Status
);
270 The user Entry Point for DXE driver. The user code starts with this function
271 as the real entry point for the image goes into a library that calls this
274 @param[in] ImageHandle The firmware allocated handle for the EFI image.
275 @param[in] SystemTable A pointer to the EFI System Table.
277 @retval EFI_SUCCESS The entry point is executed successfully.
278 @retval other Some error occurs when executing this entry point.
284 IN EFI_HANDLE ImageHandle
,
285 IN EFI_SYSTEM_TABLE
*SystemTable
288 EfiCreateProtocolNotifyEvent (
289 &gEfiUnicodeCollationProtocolGuid
,
300 Performs a case-insensitive comparison of two Null-terminated Unicode
303 @param This Protocol instance pointer.
304 @param Str1 A pointer to a Null-terminated Unicode string.
305 @param Str2 A pointer to a Null-terminated Unicode string.
307 @retval 0 Str1 is equivalent to Str2
308 @retval > 0 Str1 is lexically greater than Str2
309 @retval < 0 Str1 is lexically less than Str2
315 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
320 UC2_PRIVATE_DATA
*Private
;
322 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
324 return Private
->UC
->StriColl (Private
->UC
, Str1
, Str2
);
329 Converts all the Unicode characters in a Null-terminated Unicode string to
330 lower case Unicode characters.
332 @param This Protocol instance pointer.
333 @param Str A pointer to a Null-terminated Unicode string.
339 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
343 UC2_PRIVATE_DATA
*Private
;
345 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
347 Private
->UC
->StrLwr (Private
->UC
, Str
);
352 Converts all the Unicode characters in a Null-terminated Unicode string to upper
353 case Unicode characters.
355 @param This Protocol instance pointer.
356 @param Str A pointer to a Null-terminated Unicode string.
362 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
366 UC2_PRIVATE_DATA
*Private
;
368 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
370 Private
->UC
->StrUpr (Private
->UC
, Str
);
374 Performs a case-insensitive comparison of a Null-terminated Unicode
375 pattern string and a Null-terminated Unicode string.
377 @param This Protocol instance pointer.
378 @param String A pointer to a Null-terminated Unicode string.
379 @param Pattern A pointer to a Null-terminated Unicode pattern string.
381 @retval TRUE Pattern was found in String.
382 @retval FALSE Pattern was not found in String.
388 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
393 UC2_PRIVATE_DATA
*Private
;
395 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
397 return Private
->UC
->MetaiMatch (Private
->UC
, String
, Pattern
);
402 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
405 @param This Protocol instance pointer.
406 @param FatSize The size of the string Fat in bytes.
407 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
408 name using an OEM character set.
409 @param String A pointer to a Null-terminated Unicode string. The string must
410 be preallocated to hold FatSize Unicode characters.
416 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
422 UC2_PRIVATE_DATA
*Private
;
424 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
426 Private
->UC
->FatToStr (Private
->UC
, FatSize
, Fat
, String
);
431 Converts a Null-terminated Unicode string to legal characters in a FAT
432 filename using an OEM character set.
434 @param This Protocol instance pointer.
435 @param String A pointer to a Null-terminated Unicode string. The string must
436 be preallocated to hold FatSize Unicode characters.
437 @param FatSize The size of the string Fat in bytes.
438 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
439 name using an OEM character set.
441 @retval TRUE Fat is a Long File Name
442 @retval FALSE Fat is an 8.3 file name
448 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
454 UC2_PRIVATE_DATA
*Private
;
456 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
458 return Private
->UC
->StrToFat (Private
->UC
, String
, FatSize
, Fat
);