]>
Commit | Line | Data |
---|---|---|
03e6b4b2 | 1 | /** @file\r |
2 | Module produce UC2 on top of UC.\r | |
3 | \r | |
4 | UEFI 2.1 specification supersedes Inte's EFI Specification 1.10.\r | |
5 | EFI_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 UC2 on top of UC. This module is used on platform when both of\r | |
8 | these two conditions are true:\r | |
9 | 1) EFI 1.10 module producing UC present\r | |
10 | 2) And the rest of modules on the platform consume UC2\r | |
11 | \r | |
12 | Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r | |
13 | All rights reserved. This program and the accompanying materials\r | |
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 |
ad5a96ab | 35 | \r |
03e6b4b2 | 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 |
03e6b4b2 | 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 |
03e6b4b2 | 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 |
03e6b4b2 | 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 |
03e6b4b2 | 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 |
03e6b4b2 | 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 |
03e6b4b2 | 151 | \r |
a3a83173 | 152 | #define UC2_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '2')\r |
03e6b4b2 | 153 | \r |
154 | typedef struct {\r | |
155 | UINT32 Signature;\r | |
156 | EFI_UNICODE_COLLATION_PROTOCOL UC2;\r | |
157 | EFI_UNICODE_COLLATION_PROTOCOL *UC;\r | |
158 | } UC2_PRIVATE_DATA;\r | |
159 | \r | |
29ec49a5 | 160 | #define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, UC2, UC2_PRIVATE_DATA_SIGNATURE)\r |
03e6b4b2 | 161 | \r |
162 | //\r | |
163 | // Firmware Volume Protocol template\r | |
164 | //\r | |
165 | EFI_EVENT mUc2Registration;\r | |
166 | \r | |
167 | UC2_PRIVATE_DATA gUC2PrivateDataTemplate = {\r | |
168 | UC2_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 | |
184 | \r | |
185 | VOID\r | |
186 | EFIAPI\r | |
cd289975 | 187 | UcNotificationEvent (\r |
03e6b4b2 | 188 | IN EFI_EVENT Event,\r |
189 | IN VOID *Context\r | |
190 | )\r | |
191 | {\r | |
192 | EFI_STATUS Status;\r | |
193 | UINTN BufferSize;\r | |
194 | EFI_HANDLE Handle;\r | |
195 | UC2_PRIVATE_DATA *Private;\r | |
196 | EFI_UNICODE_COLLATION_PROTOCOL *Uc2;\r | |
197 | \r | |
198 | while (TRUE) {\r | |
199 | BufferSize = sizeof (Handle);\r | |
200 | Status = gBS->LocateHandle (\r | |
201 | ByRegisterNotify,\r | |
202 | &gEfiUnicodeCollationProtocolGuid,\r | |
203 | mUc2Registration,\r | |
204 | &BufferSize,\r | |
205 | &Handle\r | |
206 | );\r | |
207 | if (EFI_ERROR (Status)) {\r | |
208 | //\r | |
209 | // Exit Path of While Loop....\r | |
210 | //\r | |
211 | break;\r | |
212 | }\r | |
213 | \r | |
214 | //\r | |
215 | // Skip this handle if the Firmware Volume Protocol is already installed\r | |
216 | //\r | |
217 | Status = gBS->HandleProtocol (\r | |
218 | Handle,\r | |
219 | &gEfiUnicodeCollation2ProtocolGuid,\r | |
220 | (VOID **)&Uc2\r | |
221 | );\r | |
222 | if (!EFI_ERROR (Status)) {\r | |
223 | continue;\r | |
224 | }\r | |
225 | \r | |
226 | //\r | |
227 | // Allocate private data structure\r | |
228 | //\r | |
229 | Private = AllocateCopyPool (sizeof (UC2_PRIVATE_DATA), &gUC2PrivateDataTemplate);\r | |
230 | if (Private == NULL) {\r | |
231 | continue;\r | |
232 | }\r | |
233 | \r | |
234 | //\r | |
235 | // Retrieve the UC Protocol\r | |
236 | //\r | |
237 | Status = gBS->HandleProtocol (\r | |
238 | Handle,\r | |
239 | &gEfiUnicodeCollationProtocolGuid,\r | |
240 | (VOID **)&Private->UC\r | |
241 | );\r | |
242 | ASSERT_EFI_ERROR (Status);\r | |
243 | \r | |
244 | //\r | |
245 | // Fill in rest of private data structure\r | |
246 | //\r | |
7c9d25ae | 247 | Private->UC2.SupportedLanguages = ConvertLanguagesIso639ToRfc4646 (Private->UC->SupportedLanguages);\r |
0b09813f | 248 | if (Private->UC2.SupportedLanguages != NULL) {\r |
03e6b4b2 | 249 | \r |
250 | //\r | |
251 | // Install Firmware Volume Protocol onto same handle\r | |
252 | //\r | |
253 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
254 | &Handle,\r | |
255 | &gEfiUnicodeCollation2ProtocolGuid,\r | |
256 | &Private->UC2,\r | |
257 | NULL\r | |
258 | );\r | |
259 | ASSERT_EFI_ERROR (Status);\r | |
260 | }\r | |
261 | }\r | |
262 | }\r | |
263 | \r | |
264 | \r | |
265 | /**\r | |
266 | The user Entry Point for DXE driver. The user code starts with this function\r | |
267 | as the real entry point for the image goes into a library that calls this \r | |
268 | function.\r | |
269 | \r | |
270 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
271 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
272 | \r | |
273 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
274 | @retval other Some error occurs when executing this entry point.\r | |
275 | \r | |
276 | **/\r | |
277 | EFI_STATUS\r | |
278 | EFIAPI\r | |
279 | InitializeUC2 (\r | |
280 | IN EFI_HANDLE ImageHandle,\r | |
281 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
282 | )\r | |
283 | {\r | |
284 | EfiCreateProtocolNotifyEvent (\r | |
285 | &gEfiUnicodeCollationProtocolGuid,\r | |
286 | TPL_CALLBACK,\r | |
cd289975 | 287 | UcNotificationEvent,\r |
03e6b4b2 | 288 | NULL,\r |
289 | &mUc2Registration\r | |
290 | );\r | |
291 | return EFI_SUCCESS;\r | |
292 | }\r | |
293 | \r | |
294 | \r | |
295 | /**\r | |
296 | Performs a case-insensitive comparison of two Null-terminated Unicode \r | |
297 | strings.\r | |
298 | \r | |
299 | @param This Protocol instance pointer.\r | |
300 | @param Str1 A pointer to a Null-terminated Unicode string.\r | |
301 | @param Str2 A pointer to a Null-terminated Unicode string.\r | |
302 | \r | |
303 | @retval 0 Str1 is equivalent to Str2\r | |
304 | @retval > 0 Str1 is lexically greater than Str2\r | |
305 | @retval < 0 Str1 is lexically less than Str2\r | |
306 | \r | |
307 | **/\r | |
308 | INTN\r | |
309 | EFIAPI\r | |
310 | StriColl (\r | |
311 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
312 | IN CHAR16 *Str1,\r | |
313 | IN CHAR16 *Str2\r | |
314 | )\r | |
315 | {\r | |
316 | UC2_PRIVATE_DATA *Private;\r | |
317 | \r | |
318 | Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r | |
319 | \r | |
320 | return Private->UC->StriColl (Private->UC, Str1, Str2);\r | |
321 | }\r | |
322 | \r | |
323 | \r | |
324 | /**\r | |
325 | Converts all the Unicode characters in a Null-terminated Unicode string to \r | |
326 | lower case Unicode characters.\r | |
327 | \r | |
328 | @param This Protocol instance pointer.\r | |
329 | @param Str A pointer to a Null-terminated Unicode string.\r | |
330 | \r | |
331 | **/\r | |
332 | VOID\r | |
333 | EFIAPI\r | |
334 | StrLwr (\r | |
335 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
336 | IN OUT CHAR16 *Str\r | |
337 | )\r | |
338 | {\r | |
339 | UC2_PRIVATE_DATA *Private;\r | |
340 | \r | |
341 | Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r | |
342 | \r | |
343 | Private->UC->StrLwr (Private->UC, Str);\r | |
344 | }\r | |
345 | \r | |
346 | \r | |
347 | /**\r | |
348 | Converts all the Unicode characters in a Null-terminated Unicode string to upper\r | |
349 | case Unicode characters.\r | |
350 | \r | |
351 | @param This Protocol instance pointer.\r | |
352 | @param Str A pointer to a Null-terminated Unicode string.\r | |
353 | \r | |
354 | **/\r | |
355 | VOID\r | |
356 | EFIAPI\r | |
357 | StrUpr (\r | |
358 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
359 | IN OUT CHAR16 *Str\r | |
360 | )\r | |
361 | {\r | |
362 | UC2_PRIVATE_DATA *Private;\r | |
363 | \r | |
364 | Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r | |
365 | \r | |
366 | Private->UC->StrUpr (Private->UC, Str);\r | |
367 | }\r | |
368 | \r | |
369 | /**\r | |
370 | Performs a case-insensitive comparison of a Null-terminated Unicode \r | |
371 | pattern string and a Null-terminated Unicode string.\r | |
372 | \r | |
373 | @param This Protocol instance pointer.\r | |
374 | @param String A pointer to a Null-terminated Unicode string.\r | |
375 | @param Pattern A pointer to a Null-terminated Unicode pattern string.\r | |
376 | \r | |
377 | @retval TRUE Pattern was found in String.\r | |
378 | @retval FALSE Pattern was not found in String.\r | |
379 | \r | |
380 | **/\r | |
381 | BOOLEAN\r | |
382 | EFIAPI\r | |
383 | MetaiMatch (\r | |
384 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
385 | IN CHAR16 *String,\r | |
386 | IN CHAR16 *Pattern\r | |
387 | )\r | |
388 | {\r | |
389 | UC2_PRIVATE_DATA *Private;\r | |
390 | \r | |
391 | Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r | |
392 | \r | |
393 | return Private->UC->MetaiMatch (Private->UC, String, Pattern);\r | |
394 | }\r | |
395 | \r | |
396 | \r | |
397 | /**\r | |
398 | Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r | |
399 | Unicode string.\r | |
400 | \r | |
401 | @param This Protocol instance pointer.\r | |
402 | @param FatSize The size of the string Fat in bytes.\r | |
403 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
404 | name using an OEM character set.\r | |
405 | @param String A pointer to a Null-terminated Unicode string. The string must\r | |
406 | be preallocated to hold FatSize Unicode characters.\r | |
407 | \r | |
408 | **/\r | |
409 | VOID\r | |
410 | EFIAPI\r | |
411 | FatToStr (\r | |
412 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
413 | IN UINTN FatSize,\r | |
414 | IN CHAR8 *Fat,\r | |
415 | OUT CHAR16 *String\r | |
416 | )\r | |
417 | {\r | |
418 | UC2_PRIVATE_DATA *Private;\r | |
419 | \r | |
420 | Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r | |
421 | \r | |
422 | Private->UC->FatToStr (Private->UC, FatSize, Fat, String);\r | |
423 | }\r | |
424 | \r | |
425 | \r | |
426 | /**\r | |
427 | Converts a Null-terminated Unicode string to legal characters in a FAT \r | |
428 | filename using an OEM character set. \r | |
429 | \r | |
430 | @param This Protocol instance pointer.\r | |
431 | @param String A pointer to a Null-terminated Unicode string. The string must\r | |
432 | be preallocated to hold FatSize Unicode characters.\r | |
433 | @param FatSize The size of the string Fat in bytes.\r | |
434 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
435 | name using an OEM character set.\r | |
436 | \r | |
437 | @retval TRUE Fat is a Long File Name\r | |
438 | @retval FALSE Fat is an 8.3 file name\r | |
439 | \r | |
440 | **/\r | |
441 | BOOLEAN\r | |
442 | EFIAPI\r | |
443 | StrToFat (\r | |
444 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
445 | IN CHAR16 *String,\r | |
446 | IN UINTN FatSize,\r | |
447 | OUT CHAR8 *Fat\r | |
448 | )\r | |
449 | {\r | |
450 | UC2_PRIVATE_DATA *Private;\r | |
451 | \r | |
452 | Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r | |
453 | \r | |
454 | return Private->UC->StrToFat (Private->UC, String, FatSize, Fat);\r | |
455 | }\r | |
456 | \r |