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>
34 #include <Library/LanguageLib.h>
37 Performs a case-insensitive comparison of two Null-terminated Unicode
40 @param This Protocol instance pointer.
41 @param Str1 A pointer to a Null-terminated Unicode string.
42 @param Str2 A pointer to a Null-terminated Unicode string.
44 @retval 0 Str1 is equivalent to Str2
45 @retval > 0 Str1 is lexically greater than Str2
46 @retval < 0 Str1 is lexically less than Str2
52 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
58 Converts all the Unicode characters in a Null-terminated Unicode string to
59 lower case Unicode characters.
61 @param This Protocol instance pointer.
62 @param Str A pointer to a Null-terminated Unicode string.
68 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
73 Converts all the Unicode characters in a Null-terminated Unicode string to upper
74 case Unicode characters.
76 @param This Protocol instance pointer.
77 @param Str A pointer to a Null-terminated Unicode string.
83 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
88 Performs a case-insensitive comparison of a Null-terminated Unicode
89 pattern string and a Null-terminated Unicode string.
91 @param This Protocol instance pointer.
92 @param String A pointer to a Null-terminated Unicode string.
93 @param Pattern A pointer to a Null-terminated Unicode pattern string.
95 @retval TRUE Pattern was found in String.
96 @retval FALSE Pattern was not found in String.
102 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
108 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
111 @param This Protocol instance pointer.
112 @param FatSize The size of the string Fat in bytes.
113 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
114 name using an OEM character set.
115 @param String A pointer to a Null-terminated Unicode string. The string must
116 be preallocated to hold FatSize Unicode characters.
122 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
129 Converts a Null-terminated Unicode string to legal characters in a FAT
130 filename using an OEM character set.
132 @param This Protocol instance pointer.
133 @param String A pointer to a Null-terminated Unicode string. The string must
134 be preallocated to hold FatSize Unicode characters.
135 @param FatSize The size of the string Fat in bytes.
136 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
137 name using an OEM character set.
139 @retval TRUE Fat is a Long File Name
140 @retval FALSE Fat is an 8.3 file name
146 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
152 #define UC2_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '2')
156 EFI_UNICODE_COLLATION_PROTOCOL UC2
;
157 EFI_UNICODE_COLLATION_PROTOCOL
*UC
;
160 #define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, UC2, UC2_PRIVATE_DATA_SIGNATURE)
163 // Firmware Volume Protocol template
165 EFI_EVENT mUc2Registration
;
167 UC2_PRIVATE_DATA gUC2PrivateDataTemplate
= {
168 UC2_PRIVATE_DATA_SIGNATURE
,
187 UcNotificationEvent (
195 UC2_PRIVATE_DATA
*Private
;
196 EFI_UNICODE_COLLATION_PROTOCOL
*Uc2
;
199 BufferSize
= sizeof (Handle
);
200 Status
= gBS
->LocateHandle (
202 &gEfiUnicodeCollationProtocolGuid
,
207 if (EFI_ERROR (Status
)) {
209 // Exit Path of While Loop....
215 // Skip this handle if the Firmware Volume Protocol is already installed
217 Status
= gBS
->HandleProtocol (
219 &gEfiUnicodeCollation2ProtocolGuid
,
222 if (!EFI_ERROR (Status
)) {
227 // Allocate private data structure
229 Private
= AllocateCopyPool (sizeof (UC2_PRIVATE_DATA
), &gUC2PrivateDataTemplate
);
230 if (Private
== NULL
) {
235 // Retrieve the UC Protocol
237 Status
= gBS
->HandleProtocol (
239 &gEfiUnicodeCollationProtocolGuid
,
240 (VOID
**)&Private
->UC
242 ASSERT_EFI_ERROR (Status
);
245 // Fill in rest of private data structure
247 Private
->UC2
.SupportedLanguages
= ConvertLanguagesIso639ToRfc4646 (Private
->UC
->SupportedLanguages
);
248 if (Private
->UC2
.SupportedLanguages
!= NULL
) {
251 // Install Firmware Volume Protocol onto same handle
253 Status
= gBS
->InstallMultipleProtocolInterfaces (
255 &gEfiUnicodeCollation2ProtocolGuid
,
259 ASSERT_EFI_ERROR (Status
);
266 The user Entry Point for DXE driver. The user code starts with this function
267 as the real entry point for the image goes into a library that calls this
270 @param[in] ImageHandle The firmware allocated handle for the EFI image.
271 @param[in] SystemTable A pointer to the EFI System Table.
273 @retval EFI_SUCCESS The entry point is executed successfully.
274 @retval other Some error occurs when executing this entry point.
280 IN EFI_HANDLE ImageHandle
,
281 IN EFI_SYSTEM_TABLE
*SystemTable
284 EfiCreateProtocolNotifyEvent (
285 &gEfiUnicodeCollationProtocolGuid
,
296 Performs a case-insensitive comparison of two Null-terminated Unicode
299 @param This Protocol instance pointer.
300 @param Str1 A pointer to a Null-terminated Unicode string.
301 @param Str2 A pointer to a Null-terminated Unicode string.
303 @retval 0 Str1 is equivalent to Str2
304 @retval > 0 Str1 is lexically greater than Str2
305 @retval < 0 Str1 is lexically less than Str2
311 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
316 UC2_PRIVATE_DATA
*Private
;
318 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
320 return Private
->UC
->StriColl (Private
->UC
, Str1
, Str2
);
325 Converts all the Unicode characters in a Null-terminated Unicode string to
326 lower case Unicode characters.
328 @param This Protocol instance pointer.
329 @param Str A pointer to a Null-terminated Unicode string.
335 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
339 UC2_PRIVATE_DATA
*Private
;
341 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
343 Private
->UC
->StrLwr (Private
->UC
, Str
);
348 Converts all the Unicode characters in a Null-terminated Unicode string to upper
349 case Unicode characters.
351 @param This Protocol instance pointer.
352 @param Str A pointer to a Null-terminated Unicode string.
358 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
362 UC2_PRIVATE_DATA
*Private
;
364 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
366 Private
->UC
->StrUpr (Private
->UC
, Str
);
370 Performs a case-insensitive comparison of a Null-terminated Unicode
371 pattern string and a Null-terminated Unicode string.
373 @param This Protocol instance pointer.
374 @param String A pointer to a Null-terminated Unicode string.
375 @param Pattern A pointer to a Null-terminated Unicode pattern string.
377 @retval TRUE Pattern was found in String.
378 @retval FALSE Pattern was not found in String.
384 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
389 UC2_PRIVATE_DATA
*Private
;
391 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
393 return Private
->UC
->MetaiMatch (Private
->UC
, String
, Pattern
);
398 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
401 @param This Protocol instance pointer.
402 @param FatSize The size of the string Fat in bytes.
403 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
404 name using an OEM character set.
405 @param String A pointer to a Null-terminated Unicode string. The string must
406 be preallocated to hold FatSize Unicode characters.
412 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
418 UC2_PRIVATE_DATA
*Private
;
420 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
422 Private
->UC
->FatToStr (Private
->UC
, FatSize
, Fat
, String
);
427 Converts a Null-terminated Unicode string to legal characters in a FAT
428 filename using an OEM character set.
430 @param This Protocol instance pointer.
431 @param String A pointer to a Null-terminated Unicode string. The string must
432 be preallocated to hold FatSize Unicode characters.
433 @param FatSize The size of the string Fat in bytes.
434 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
435 name using an OEM character set.
437 @retval TRUE Fat is a Long File Name
438 @retval FALSE Fat is an 8.3 file name
444 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
450 UC2_PRIVATE_DATA
*Private
;
452 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
454 return Private
->UC
->StrToFat (Private
->UC
, String
, FatSize
, Fat
);