]>
Commit | Line | Data |
---|---|---|
a432c703 | 1 | /** @file\r |
2 | Module produce UC on top of UC2.\r | |
3 | \r | |
4 | UEFI 2.1 specification supersedes Inte's EFI Specification 1.10.\r | |
5 | UNICODE_COLLATION_PROTOCOL defined in Inte's EFI Specification 1.10 is replaced by\r | |
6 | EFI_UNICODE_COLLATION_PROTOCOL in UEFI 2.1.\r | |
7 | This module produces UC on top of UC2. This module is used on platform when both of\r | |
8 | these two conditions are true:\r | |
9 | 1) EFI 1.10 module consuming UC present\r | |
10 | 2) And the rest of modules on the platform produce UC2\r | |
11 | \r | |
4f077902 | 12 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
584d5652 | 13 | This program and the accompanying materials\r |
a432c703 | 14 | are licensed and made available under the terms and conditions of the BSD License\r |
15 | which accompanies this distribution. The full text of the license may be found at\r | |
16 | http://opensource.org/licenses/bsd-license.php\r | |
17 | \r | |
18 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
19 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
20 | Module Name:\r | |
21 | \r | |
22 | **/\r | |
23 | \r | |
24 | #include <PiDxe.h>\r | |
25 | #include <Protocol/UnicodeCollation.h>\r | |
26 | #include <Library/BaseLib.h>\r | |
27 | #include <Library/DebugLib.h>\r | |
28 | #include <Library/UefiBootServicesTableLib.h>\r | |
29 | #include <Library/UefiDriverEntryPoint.h>\r | |
30 | #include <Library/UefiLib.h>\r | |
31 | #include <Library/MemoryAllocationLib.h>\r | |
32 | #include <Library/HiiLib.h>\r | |
ad5a96ab | 33 | #include <Library/BaseMemoryLib.h>\r |
7c9d25ae | 34 | #include <Library/LanguageLib.h>\r |
a432c703 | 35 | \r |
36 | /**\r | |
4f077902 | 37 | Performs a case-insensitive comparison of two Null-terminated strings.\r |
a432c703 | 38 | \r |
39 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
40 | @param Str1 A pointer to a Null-terminated string.\r |
41 | @param Str2 A pointer to a Null-terminated string.\r | |
a432c703 | 42 | \r |
43 | @retval 0 Str1 is equivalent to Str2\r | |
44 | @retval > 0 Str1 is lexically greater than Str2\r | |
45 | @retval < 0 Str1 is lexically less than Str2\r | |
46 | \r | |
47 | **/\r | |
48 | INTN\r | |
49 | EFIAPI\r | |
50 | StriColl (\r | |
51 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
52 | IN CHAR16 *Str1,\r | |
53 | IN CHAR16 *Str2\r | |
e00e1d46 | 54 | );\r |
a432c703 | 55 | \r |
56 | /**\r | |
4f077902 SZ |
57 | Converts all the characters in a Null-terminated string to \r |
58 | lower case characters.\r | |
a432c703 | 59 | \r |
60 | @param This Protocol instance pointer.\r | |
4f077902 | 61 | @param Str A pointer to a Null-terminated string.\r |
a432c703 | 62 | \r |
63 | **/\r | |
64 | VOID\r | |
65 | EFIAPI\r | |
66 | StrLwr (\r | |
67 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
68 | IN OUT CHAR16 *Str\r | |
e00e1d46 | 69 | );\r |
a432c703 | 70 | \r |
71 | /**\r | |
4f077902 SZ |
72 | Converts all the characters in a Null-terminated string to upper\r |
73 | case characters.\r | |
a432c703 | 74 | \r |
75 | @param This Protocol instance pointer.\r | |
4f077902 | 76 | @param Str A pointer to a Null-terminated string.\r |
a432c703 | 77 | \r |
78 | **/\r | |
79 | VOID\r | |
80 | EFIAPI\r | |
81 | StrUpr (\r | |
82 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
83 | IN OUT CHAR16 *Str\r | |
e00e1d46 | 84 | );\r |
a432c703 | 85 | \r |
86 | /**\r | |
4f077902 SZ |
87 | Performs a case-insensitive comparison of a Null-terminated\r |
88 | pattern string and a Null-terminated string.\r | |
a432c703 | 89 | \r |
90 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
91 | @param String A pointer to a Null-terminated string.\r |
92 | @param Pattern A pointer to a Null-terminated pattern string.\r | |
a432c703 | 93 | \r |
94 | @retval TRUE Pattern was found in String.\r | |
95 | @retval FALSE Pattern was not found in String.\r | |
96 | \r | |
97 | **/\r | |
98 | BOOLEAN\r | |
99 | EFIAPI\r | |
100 | MetaiMatch (\r | |
101 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
102 | IN CHAR16 *String,\r | |
103 | IN CHAR16 *Pattern\r | |
e00e1d46 | 104 | );\r |
a432c703 | 105 | \r |
106 | /**\r | |
4f077902 | 107 | Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.\r |
a432c703 | 108 | \r |
109 | @param This Protocol instance pointer.\r | |
110 | @param FatSize The size of the string Fat in bytes.\r | |
111 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
112 | name using an OEM character set.\r | |
4f077902 SZ |
113 | @param String A pointer to a Null-terminated string. The string must\r |
114 | be preallocated to hold FatSize characters.\r | |
a432c703 | 115 | \r |
116 | **/\r | |
117 | VOID\r | |
118 | EFIAPI\r | |
119 | FatToStr (\r | |
120 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
121 | IN UINTN FatSize,\r | |
122 | IN CHAR8 *Fat,\r | |
123 | OUT CHAR16 *String\r | |
e00e1d46 | 124 | );\r |
a432c703 | 125 | \r |
126 | /**\r | |
4f077902 | 127 | Converts a Null-terminated string to legal characters in a FAT \r |
a432c703 | 128 | filename using an OEM character set. \r |
129 | \r | |
130 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
131 | @param String A pointer to a Null-terminated string. The string must\r |
132 | be preallocated to hold FatSize characters.\r | |
a432c703 | 133 | @param FatSize The size of the string Fat in bytes.\r |
134 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
135 | name using an OEM character set.\r | |
136 | \r | |
137 | @retval TRUE Fat is a Long File Name\r | |
138 | @retval FALSE Fat is an 8.3 file name\r | |
139 | \r | |
140 | **/\r | |
141 | BOOLEAN\r | |
142 | EFIAPI\r | |
143 | StrToFat (\r | |
144 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
145 | IN CHAR16 *String,\r | |
146 | IN UINTN FatSize,\r | |
147 | OUT CHAR8 *Fat\r | |
e00e1d46 | 148 | );\r |
a432c703 | 149 | \r |
a3a83173 | 150 | #define UC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '_')\r |
a432c703 | 151 | \r |
152 | typedef struct {\r | |
153 | UINT32 Signature;\r | |
26a76fbc LG |
154 | EFI_UNICODE_COLLATION_PROTOCOL Uc;\r |
155 | EFI_UNICODE_COLLATION_PROTOCOL *Uc2;\r | |
a432c703 | 156 | } UC_PRIVATE_DATA;\r |
157 | \r | |
26a76fbc | 158 | #define UC_PRIVATE_DATA_FROM_THIS(a) CR (a, UC_PRIVATE_DATA, Uc, UC_PRIVATE_DATA_SIGNATURE)\r |
a432c703 | 159 | \r |
160 | //\r | |
161 | // Firmware Volume Protocol template\r | |
162 | //\r | |
163 | EFI_EVENT mUcRegistration;\r | |
164 | \r | |
165 | UC_PRIVATE_DATA gUCPrivateDataTemplate = {\r | |
166 | UC_PRIVATE_DATA_SIGNATURE,\r | |
167 | {\r | |
168 | StriColl,\r | |
169 | MetaiMatch,\r | |
170 | StrLwr,\r | |
171 | StrUpr,\r | |
172 | FatToStr,\r | |
173 | StrToFat,\r | |
174 | NULL\r | |
175 | },\r | |
176 | NULL\r | |
177 | };\r | |
178 | \r | |
179 | //\r | |
180 | // Module globals\r | |
181 | //\r | |
26a76fbc LG |
182 | /**\r |
183 | This notification function is invoked when an instance of the\r | |
184 | EFI_UNICODE_COLLATION_PROTOCOL2 is produced. It installs another instance of the\r | |
185 | EFI_UNICODE_COLLATION_PROTOCOL on the same handle.\r | |
a432c703 | 186 | \r |
26a76fbc LG |
187 | @param Event The event that occured\r |
188 | @param Context Context of event. Not used in this nofication function.\r | |
189 | \r | |
190 | **/\r | |
a432c703 | 191 | VOID\r |
192 | EFIAPI\r | |
193 | Uc2NotificationEvent (\r | |
194 | IN EFI_EVENT Event,\r | |
195 | IN VOID *Context\r | |
196 | )\r | |
197 | {\r | |
198 | EFI_STATUS Status;\r | |
199 | UINTN BufferSize;\r | |
200 | EFI_HANDLE Handle;\r | |
201 | UC_PRIVATE_DATA *Private;\r | |
202 | EFI_UNICODE_COLLATION_PROTOCOL *Uc2;\r | |
203 | \r | |
204 | while (TRUE) {\r | |
205 | BufferSize = sizeof (Handle);\r | |
206 | Status = gBS->LocateHandle (\r | |
207 | ByRegisterNotify,\r | |
208 | &gEfiUnicodeCollation2ProtocolGuid,\r | |
209 | mUcRegistration,\r | |
210 | &BufferSize,\r | |
211 | &Handle\r | |
212 | );\r | |
213 | if (EFI_ERROR (Status)) {\r | |
214 | //\r | |
215 | // Exit Path of While Loop....\r | |
216 | //\r | |
217 | break;\r | |
218 | }\r | |
219 | \r | |
220 | //\r | |
221 | // Skip this handle if the Firmware Volume Protocol is already installed\r | |
222 | //\r | |
223 | Status = gBS->HandleProtocol (\r | |
224 | Handle,\r | |
225 | &gEfiUnicodeCollationProtocolGuid,\r | |
226 | (VOID **)&Uc2\r | |
227 | );\r | |
228 | if (!EFI_ERROR (Status)) {\r | |
229 | continue;\r | |
230 | }\r | |
231 | \r | |
232 | //\r | |
233 | // Allocate private data structure\r | |
234 | //\r | |
235 | Private = AllocateCopyPool (sizeof (UC_PRIVATE_DATA), &gUCPrivateDataTemplate);\r | |
236 | if (Private == NULL) {\r | |
237 | continue;\r | |
238 | }\r | |
239 | \r | |
240 | //\r | |
241 | // Retrieve the UC Protocol\r | |
242 | //\r | |
243 | Status = gBS->HandleProtocol (\r | |
244 | Handle,\r | |
245 | &gEfiUnicodeCollation2ProtocolGuid,\r | |
26a76fbc | 246 | (VOID **)&Private->Uc2\r |
a432c703 | 247 | );\r |
248 | ASSERT_EFI_ERROR (Status);\r | |
249 | \r | |
250 | //\r | |
251 | // Fill in rest of private data structure\r | |
252 | //\r | |
26a76fbc | 253 | Private->Uc.SupportedLanguages = ConvertLanguagesRfc4646ToIso639 (Private->Uc2->SupportedLanguages);\r |
a432c703 | 254 | \r |
26a76fbc | 255 | if (Private->Uc.SupportedLanguages != NULL) {\r |
a432c703 | 256 | \r |
257 | //\r | |
258 | // Install Firmware Volume Protocol onto same handle\r | |
259 | //\r | |
260 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
261 | &Handle,\r | |
262 | &gEfiUnicodeCollationProtocolGuid,\r | |
26a76fbc | 263 | &Private->Uc,\r |
a432c703 | 264 | NULL\r |
265 | );\r | |
266 | ASSERT_EFI_ERROR (Status);\r | |
267 | }\r | |
268 | }\r | |
269 | }\r | |
270 | \r | |
271 | \r | |
272 | /**\r | |
273 | The user Entry Point for DXE driver. The user code starts with this function\r | |
274 | as the real entry point for the image goes into a library that calls this \r | |
275 | function.\r | |
276 | \r | |
277 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
278 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
279 | \r | |
280 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
281 | @retval other Some error occurs when executing this entry point.\r | |
282 | \r | |
283 | **/\r | |
284 | EFI_STATUS\r | |
285 | EFIAPI\r | |
286 | InitializeUC (\r | |
287 | IN EFI_HANDLE ImageHandle,\r | |
288 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
289 | )\r | |
290 | {\r | |
291 | EfiCreateProtocolNotifyEvent (\r | |
185be2e0 | 292 | &gEfiUnicodeCollation2ProtocolGuid,\r |
a432c703 | 293 | TPL_CALLBACK,\r |
294 | Uc2NotificationEvent,\r | |
295 | NULL,\r | |
296 | &mUcRegistration\r | |
297 | );\r | |
298 | return EFI_SUCCESS;\r | |
299 | }\r | |
300 | \r | |
301 | \r | |
302 | /**\r | |
4f077902 | 303 | Performs a case-insensitive comparison of two Null-terminated strings.\r |
a432c703 | 304 | \r |
305 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
306 | @param Str1 A pointer to a Null-terminated string.\r |
307 | @param Str2 A pointer to a Null-terminated string.\r | |
a432c703 | 308 | \r |
309 | @retval 0 Str1 is equivalent to Str2\r | |
310 | @retval > 0 Str1 is lexically greater than Str2\r | |
311 | @retval < 0 Str1 is lexically less than Str2\r | |
312 | \r | |
313 | **/\r | |
314 | INTN\r | |
315 | EFIAPI\r | |
316 | StriColl (\r | |
317 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
318 | IN CHAR16 *Str1,\r | |
319 | IN CHAR16 *Str2\r | |
320 | )\r | |
321 | {\r | |
322 | UC_PRIVATE_DATA *Private;\r | |
323 | \r | |
324 | Private = UC_PRIVATE_DATA_FROM_THIS (This);\r | |
325 | \r | |
26a76fbc | 326 | return Private->Uc2->StriColl (Private->Uc2, Str1, Str2);\r |
a432c703 | 327 | }\r |
328 | \r | |
329 | \r | |
330 | /**\r | |
4f077902 SZ |
331 | Converts all the characters in a Null-terminated string to \r |
332 | lower case characters.\r | |
a432c703 | 333 | \r |
334 | @param This Protocol instance pointer.\r | |
4f077902 | 335 | @param Str A pointer to a Null-terminated string.\r |
a432c703 | 336 | \r |
337 | **/\r | |
338 | VOID\r | |
339 | EFIAPI\r | |
340 | StrLwr (\r | |
341 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
342 | IN OUT CHAR16 *Str\r | |
343 | )\r | |
344 | {\r | |
345 | UC_PRIVATE_DATA *Private;\r | |
346 | \r | |
347 | Private = UC_PRIVATE_DATA_FROM_THIS (This);\r | |
348 | \r | |
26a76fbc | 349 | Private->Uc2->StrLwr (Private->Uc2, Str);\r |
a432c703 | 350 | }\r |
351 | \r | |
352 | \r | |
353 | /**\r | |
4f077902 SZ |
354 | Converts all the characters in a Null-terminated string to upper\r |
355 | case characters.\r | |
a432c703 | 356 | \r |
357 | @param This Protocol instance pointer.\r | |
4f077902 | 358 | @param Str A pointer to a Null-terminated string.\r |
a432c703 | 359 | \r |
360 | **/\r | |
361 | VOID\r | |
362 | EFIAPI\r | |
363 | StrUpr (\r | |
364 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
365 | IN OUT CHAR16 *Str\r | |
366 | )\r | |
367 | {\r | |
368 | UC_PRIVATE_DATA *Private;\r | |
369 | \r | |
370 | Private = UC_PRIVATE_DATA_FROM_THIS (This);\r | |
371 | \r | |
26a76fbc | 372 | Private->Uc2->StrUpr (Private->Uc2, Str);\r |
a432c703 | 373 | }\r |
374 | \r | |
375 | /**\r | |
4f077902 SZ |
376 | Performs a case-insensitive comparison of a Null-terminated\r |
377 | pattern string and a Null-terminated string.\r | |
a432c703 | 378 | \r |
379 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
380 | @param String A pointer to a Null-terminated string.\r |
381 | @param Pattern A pointer to a Null-terminated pattern string.\r | |
a432c703 | 382 | \r |
383 | @retval TRUE Pattern was found in String.\r | |
384 | @retval FALSE Pattern was not found in String.\r | |
385 | \r | |
386 | **/\r | |
387 | BOOLEAN\r | |
388 | EFIAPI\r | |
389 | MetaiMatch (\r | |
390 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
391 | IN CHAR16 *String,\r | |
392 | IN CHAR16 *Pattern\r | |
393 | )\r | |
394 | {\r | |
395 | UC_PRIVATE_DATA *Private;\r | |
396 | \r | |
397 | Private = UC_PRIVATE_DATA_FROM_THIS (This);\r | |
398 | \r | |
26a76fbc | 399 | return Private->Uc2->MetaiMatch (Private->Uc2, String, Pattern);\r |
a432c703 | 400 | }\r |
401 | \r | |
402 | \r | |
403 | /**\r | |
4f077902 | 404 | Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.\r |
a432c703 | 405 | \r |
406 | @param This Protocol instance pointer.\r | |
407 | @param FatSize The size of the string Fat in bytes.\r | |
408 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
4f077902 SZ |
409 | name using an 8-bit OEM character set.\r |
410 | @param String A pointer to a Null-terminated string. The string must\r | |
411 | be preallocated to hold FatSize characters.\r | |
a432c703 | 412 | \r |
413 | **/\r | |
414 | VOID\r | |
415 | EFIAPI\r | |
416 | FatToStr (\r | |
417 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
418 | IN UINTN FatSize,\r | |
419 | IN CHAR8 *Fat,\r | |
420 | OUT CHAR16 *String\r | |
421 | )\r | |
422 | {\r | |
423 | UC_PRIVATE_DATA *Private;\r | |
424 | \r | |
425 | Private = UC_PRIVATE_DATA_FROM_THIS (This);\r | |
426 | \r | |
26a76fbc | 427 | Private->Uc2->FatToStr (Private->Uc2, FatSize, Fat, String);\r |
a432c703 | 428 | }\r |
429 | \r | |
430 | \r | |
431 | /**\r | |
4f077902 | 432 | Converts a Null-terminated string to legal characters in a FAT \r |
a432c703 | 433 | filename using an OEM character set. \r |
434 | \r | |
435 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
436 | @param String A pointer to a Null-terminated string. The string must\r |
437 | be preallocated to hold FatSize characters.\r | |
a432c703 | 438 | @param FatSize The size of the string Fat in bytes.\r |
439 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
440 | name using an OEM character set.\r | |
441 | \r | |
442 | @retval TRUE Fat is a Long File Name\r | |
443 | @retval FALSE Fat is an 8.3 file name\r | |
444 | \r | |
445 | **/\r | |
446 | BOOLEAN\r | |
447 | EFIAPI\r | |
448 | StrToFat (\r | |
449 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
450 | IN CHAR16 *String,\r | |
451 | IN UINTN FatSize,\r | |
452 | OUT CHAR8 *Fat\r | |
453 | )\r | |
454 | {\r | |
455 | UC_PRIVATE_DATA *Private;\r | |
456 | \r | |
457 | Private = UC_PRIVATE_DATA_FROM_THIS (This);\r | |
458 | \r | |
26a76fbc | 459 | return Private->Uc2->StrToFat (Private->Uc2, String, FatSize, Fat);\r |
a432c703 | 460 | }\r |
461 | \r |