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