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 - 2011, Intel Corporation. All rights reserved.<BR>
13 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 strings.
39 @param This Protocol instance pointer.
40 @param Str1 A pointer to a Null-terminated string.
41 @param Str2 A pointer to a Null-terminated string.
43 @retval 0 Str1 is equivalent to Str2
44 @retval > 0 Str1 is lexically greater than Str2
45 @retval < 0 Str1 is lexically less than Str2
51 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
57 Converts all the characters in a Null-terminated string to
58 lower case characters.
60 @param This Protocol instance pointer.
61 @param Str A pointer to a Null-terminated string.
67 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
72 Converts all the characters in a Null-terminated string to upper
75 @param This Protocol instance pointer.
76 @param Str A pointer to a Null-terminated string.
82 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
87 Performs a case-insensitive comparison of a Null-terminated
88 pattern string and a Null-terminated string.
90 @param This Protocol instance pointer.
91 @param String A pointer to a Null-terminated string.
92 @param Pattern A pointer to a Null-terminated pattern string.
94 @retval TRUE Pattern was found in String.
95 @retval FALSE Pattern was not found in String.
101 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
107 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.
109 @param This Protocol instance pointer.
110 @param FatSize The size of the string Fat in bytes.
111 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
112 name using an OEM character set.
113 @param String A pointer to a Null-terminated string. The string must
114 be preallocated to hold FatSize characters.
120 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
127 Converts a Null-terminated string to legal characters in a FAT
128 filename using an OEM character set.
130 @param This Protocol instance pointer.
131 @param String A pointer to a Null-terminated string. The string must
132 be preallocated to hold FatSize characters.
133 @param FatSize The size of the string Fat in bytes.
134 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
135 name using an OEM character set.
137 @retval TRUE Fat is a Long File Name
138 @retval FALSE Fat is an 8.3 file name
144 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
150 #define UC2_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '2')
154 EFI_UNICODE_COLLATION_PROTOCOL Uc2
;
155 EFI_UNICODE_COLLATION_PROTOCOL
*Uc
;
158 #define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, Uc2, UC2_PRIVATE_DATA_SIGNATURE)
161 // Firmware Volume Protocol template
163 EFI_EVENT mUc2Registration
;
165 UC2_PRIVATE_DATA gUC2PrivateDataTemplate
= {
166 UC2_PRIVATE_DATA_SIGNATURE
,
183 This notification function is invoked when an instance of the
184 EFI_UNICODE_COLLATION_PROTOCOL is produced. It installs another instance of the
185 EFI_UNICODE_COLLATION_PROTOCOL2 on the same handle.
187 @param Event The event that occured
188 @param Context Context of event. Not used in this nofication function.
193 UcNotificationEvent (
201 UC2_PRIVATE_DATA
*Private
;
202 EFI_UNICODE_COLLATION_PROTOCOL
*Uc2
;
205 BufferSize
= sizeof (Handle
);
206 Status
= gBS
->LocateHandle (
208 &gEfiUnicodeCollationProtocolGuid
,
213 if (EFI_ERROR (Status
)) {
215 // Exit Path of While Loop....
221 // Skip this handle if the Firmware Volume Protocol is already installed
223 Status
= gBS
->HandleProtocol (
225 &gEfiUnicodeCollation2ProtocolGuid
,
228 if (!EFI_ERROR (Status
)) {
233 // Allocate private data structure
235 Private
= AllocateCopyPool (sizeof (UC2_PRIVATE_DATA
), &gUC2PrivateDataTemplate
);
236 if (Private
== NULL
) {
241 // Retrieve the UC Protocol
243 Status
= gBS
->HandleProtocol (
245 &gEfiUnicodeCollationProtocolGuid
,
246 (VOID
**)&Private
->Uc
248 ASSERT_EFI_ERROR (Status
);
251 // Fill in rest of private data structure
253 Private
->Uc2
.SupportedLanguages
= ConvertLanguagesIso639ToRfc4646 (Private
->Uc
->SupportedLanguages
);
254 if (Private
->Uc2
.SupportedLanguages
!= NULL
) {
257 // Install UC2 Protocol onto same handle
259 Status
= gBS
->InstallMultipleProtocolInterfaces (
261 &gEfiUnicodeCollation2ProtocolGuid
,
265 ASSERT_EFI_ERROR (Status
);
272 The user Entry Point for DXE driver. The user code starts with this function
273 as the real entry point for the image goes into a library that calls this
276 @param[in] ImageHandle The firmware allocated handle for the EFI image.
277 @param[in] SystemTable A pointer to the EFI System Table.
279 @retval EFI_SUCCESS The entry point is executed successfully.
280 @retval other Some error occurs when executing this entry point.
286 IN EFI_HANDLE ImageHandle
,
287 IN EFI_SYSTEM_TABLE
*SystemTable
290 EfiCreateProtocolNotifyEvent (
291 &gEfiUnicodeCollationProtocolGuid
,
302 Performs a case-insensitive comparison of two Null-terminated strings.
304 @param This Protocol instance pointer.
305 @param Str1 A pointer to a Null-terminated string.
306 @param Str2 A pointer to a Null-terminated string.
308 @retval 0 Str1 is equivalent to Str2
309 @retval > 0 Str1 is lexically greater than Str2
310 @retval < 0 Str1 is lexically less than Str2
316 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
321 UC2_PRIVATE_DATA
*Private
;
323 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
325 return Private
->Uc
->StriColl (Private
->Uc
, Str1
, Str2
);
330 Converts all the characters in a Null-terminated string to
331 lower case characters.
333 @param This Protocol instance pointer.
334 @param Str A pointer to a Null-terminated string.
340 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
344 UC2_PRIVATE_DATA
*Private
;
346 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
348 Private
->Uc
->StrLwr (Private
->Uc
, Str
);
353 Converts all the characters in a Null-terminated string to upper
356 @param This Protocol instance pointer.
357 @param Str A pointer to a Null-terminated string.
363 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
367 UC2_PRIVATE_DATA
*Private
;
369 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
371 Private
->Uc
->StrUpr (Private
->Uc
, Str
);
375 Performs a case-insensitive comparison of a Null-terminated
376 pattern string and a Null-terminated string.
378 @param This Protocol instance pointer.
379 @param String A pointer to a Null-terminated string.
380 @param Pattern A pointer to a Null-terminated pattern string.
382 @retval TRUE Pattern was found in String.
383 @retval FALSE Pattern was not found in String.
389 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
394 UC2_PRIVATE_DATA
*Private
;
396 Private
= UC2_PRIVATE_DATA_FROM_THIS (This
);
398 return Private
->Uc
->MetaiMatch (Private
->Uc
, String
, Pattern
);
403 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.
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 8-bit OEM character set.
409 @param String A pointer to a Null-terminated string. The string must
410 be preallocated to hold FatSize 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 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 string. The string must
436 be preallocated to hold FatSize 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
);