]>
Commit | Line | Data |
---|---|---|
4259256b | 1 | /**@file\r |
ee3428bb | 2 | Framework to UEFI 2.1 HII Thunk. The driver consume UEFI HII protocols\r |
3 | to produce a Framework HII protocol.\r | |
4259256b | 4 | \r |
ee3428bb | 5 | Copyright (c) 2008, Intel Corporation\r |
4259256b | 6 | All rights reserved. This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "HiiDatabase.h"\r | |
d4775f2a | 17 | #include "HiiHandle.h"\r |
4259256b | 18 | \r |
0368663f | 19 | HII_THUNK_PRIVATE_DATA *mHiiThunkPrivateData;\r |
20 | \r | |
21 | HII_THUNK_PRIVATE_DATA mHiiThunkPrivateDataTempate = {\r | |
22 | HII_THUNK_PRIVATE_DATA_SIGNATURE,\r | |
23 | (EFI_HANDLE) NULL,\r | |
24 | {\r | |
4259256b | 25 | HiiNewPack,\r |
26 | HiiRemovePack,\r | |
27 | HiiFindHandles,\r | |
28 | HiiExportDatabase,\r | |
29 | \r | |
30 | HiiTestString,\r | |
31 | HiiGetGlyph,\r | |
32 | HiiGlyphToBlt,\r | |
33 | \r | |
34 | HiiNewString,\r | |
35 | HiiGetPrimaryLanguages,\r | |
36 | HiiGetSecondaryLanguages,\r | |
cdaf7905 | 37 | HiiThunkGetString,\r |
4259256b | 38 | HiiResetStrings,\r |
39 | HiiGetLine,\r | |
40 | HiiGetForms,\r | |
41 | HiiGetDefaultImage,\r | |
cdaf7905 | 42 | HiiThunkUpdateForm,\r |
4259256b | 43 | \r |
44 | HiiGetKeyboardLayout\r | |
45 | },\r | |
0368663f | 46 | \r |
4259256b | 47 | {\r |
a3318eaf | 48 | ///\r |
49 | /// HiiHandleLinkList\r | |
50 | ///\r | |
51 | NULL, NULL \r | |
4259256b | 52 | },\r |
53 | };\r | |
54 | \r | |
137c54ac | 55 | EFI_FORMBROWSER_THUNK_PRIVATE_DATA mBrowserThunkPrivateDataTemplate = {\r |
56 | EFI_FORMBROWSER_THUNK_PRIVATE_DATA_SIGNATURE,\r | |
57 | (EFI_HANDLE) NULL,\r | |
0368663f | 58 | (HII_THUNK_PRIVATE_DATA *) NULL,\r |
137c54ac | 59 | {\r |
60 | ThunkSendForm,\r | |
61 | ThunkCreatePopUp\r | |
62 | }\r | |
63 | };\r | |
64 | \r | |
65 | \r | |
59336178 | 66 | CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabase;\r |
59336178 | 67 | CONST EFI_HII_IMAGE_PROTOCOL *mHiiImageProtocol;\r |
68 | CONST EFI_HII_STRING_PROTOCOL *mHiiStringProtocol;\r | |
133a9dfb | 69 | CONST EFI_HII_FONT_PROTOCOL *mHiiFontProtocol;\r |
59336178 | 70 | CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRoutingProtocol;\r |
0368663f | 71 | CONST EFI_FORM_BROWSER2_PROTOCOL *mFormBrowser2Protocol;\r |
ebbd2793 | 72 | \r |
ea58467b | 73 | \r |
3321fa09 | 74 | /**\r |
75 | This routine initializes the HII Database.\r | |
76 | \r | |
77 | @param ImageHandle Image handle for PCD DXE driver.\r | |
78 | @param SystemTable Pointer to SystemTable.\r | |
ea58467b | 79 | \r |
3321fa09 | 80 | @retval EFI_SUCCESS The entry point alwasy return successfully.\r |
81 | **/\r | |
4259256b | 82 | EFI_STATUS\r |
83 | EFIAPI\r | |
84 | InitializeHiiDatabase (\r | |
85 | IN EFI_HANDLE ImageHandle,\r | |
86 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
87 | )\r | |
4259256b | 88 | {\r |
0368663f | 89 | HII_THUNK_PRIVATE_DATA *Private;\r |
90 | EFI_HANDLE Handle;\r | |
91 | EFI_STATUS Status;\r | |
92 | UINTN BufferLength;\r | |
93 | EFI_HII_HANDLE *Buffer;\r | |
94 | UINTN Index;\r | |
d4775f2a | 95 | HII_THUNK_CONTEXT *ThunkContext;\r |
0368663f | 96 | \r |
4259256b | 97 | \r |
962045a2 | 98 | ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiCompatibilityProtocolGuid);\r |
99 | ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiFormBrowserCompatibilityProtocolGuid);\r | |
4259256b | 100 | \r |
0368663f | 101 | Private = AllocateCopyPool (sizeof (HII_THUNK_PRIVATE_DATA), &mHiiThunkPrivateDataTempate);\r |
102 | ASSERT (Private != NULL);\r | |
103 | InitializeListHead (&Private->ThunkContextListHead);\r | |
4259256b | 104 | \r |
d4775f2a | 105 | InitHiiHandleDatabase ();\r |
106 | \r | |
0368663f | 107 | mHiiThunkPrivateData = Private;\r |
ea58467b | 108 | \r |
4259256b | 109 | Status = gBS->LocateProtocol (\r |
110 | &gEfiHiiDatabaseProtocolGuid,\r | |
111 | NULL,\r | |
59336178 | 112 | (VOID **) &mHiiDatabase\r |
4259256b | 113 | );\r |
114 | ASSERT_EFI_ERROR (Status);\r | |
115 | \r | |
116 | Status = gBS->LocateProtocol (\r | |
0368663f | 117 | &gEfiHiiStringProtocolGuid,\r |
4259256b | 118 | NULL,\r |
0368663f | 119 | (VOID **) &mHiiStringProtocol\r |
4259256b | 120 | );\r |
121 | ASSERT_EFI_ERROR (Status);\r | |
122 | \r | |
133a9dfb | 123 | Status = gBS->LocateProtocol (\r |
124 | &gEfiHiiFontProtocolGuid,\r | |
125 | NULL,\r | |
126 | (VOID **) &mHiiFontProtocol\r | |
127 | );\r | |
128 | ASSERT_EFI_ERROR (Status);\r | |
129 | \r | |
4259256b | 130 | Status = gBS->LocateProtocol (\r |
0368663f | 131 | &gEfiHiiConfigRoutingProtocolGuid,\r |
4259256b | 132 | NULL,\r |
0368663f | 133 | (VOID **) &mHiiConfigRoutingProtocol\r |
4259256b | 134 | );\r |
135 | ASSERT_EFI_ERROR (Status);\r | |
136 | \r | |
4259256b | 137 | \r |
ebbd2793 | 138 | Status = gBS->LocateProtocol (\r |
0368663f | 139 | &gEfiFormBrowser2ProtocolGuid,\r |
ebbd2793 | 140 | NULL,\r |
0368663f | 141 | (VOID **) &mFormBrowser2Protocol\r |
ebbd2793 | 142 | );\r |
143 | ASSERT_EFI_ERROR (Status);\r | |
144 | \r | |
0368663f | 145 | \r |
146 | \r | |
147 | \r | |
4259256b | 148 | //\r |
149 | // Install protocol interface\r | |
150 | //\r | |
4259256b | 151 | Status = gBS->InstallProtocolInterface (\r |
0368663f | 152 | &Private->Handle,\r |
962045a2 | 153 | &gEfiHiiCompatibilityProtocolGuid,\r |
4259256b | 154 | EFI_NATIVE_INTERFACE,\r |
0368663f | 155 | (VOID *) &Private->Hii\r |
4259256b | 156 | );\r |
157 | ASSERT_EFI_ERROR (Status);\r | |
158 | \r | |
cb7d01c0 | 159 | Status = ListPackageLists (EFI_HII_PACKAGE_STRINGS, NULL, &BufferLength, &Buffer);\r |
0368663f | 160 | if (Status == EFI_SUCCESS) {\r |
161 | for (Index = 0; Index < BufferLength / sizeof (EFI_HII_HANDLE); Index++) {\r | |
d4775f2a | 162 | ThunkContext = CreateThunkContextForUefiHiiHandle (Buffer[Index]);\r |
163 | ASSERT (ThunkContext!= NULL);\r | |
164 | \r | |
165 | InsertTailList (&Private->ThunkContextListHead, &ThunkContext->Link);\r | |
0368663f | 166 | }\r |
167 | \r | |
168 | FreePool (Buffer);\r | |
169 | }\r | |
ea58467b | 170 | \r |
171 | Status = mHiiDatabase->RegisterPackageNotify (\r | |
172 | mHiiDatabase,\r | |
173 | EFI_HII_PACKAGE_STRINGS,\r | |
174 | NULL,\r | |
0368663f | 175 | NewOrAddPackNotify,\r |
ea58467b | 176 | EFI_HII_DATABASE_NOTIFY_NEW_PACK,\r |
0368663f | 177 | &Handle\r |
ea58467b | 178 | );\r |
179 | ASSERT_EFI_ERROR (Status);\r | |
180 | \r | |
181 | Status = mHiiDatabase->RegisterPackageNotify (\r | |
182 | mHiiDatabase,\r | |
183 | EFI_HII_PACKAGE_STRINGS,\r | |
184 | NULL,\r | |
0368663f | 185 | NewOrAddPackNotify,\r |
186 | EFI_HII_DATABASE_NOTIFY_ADD_PACK,\r | |
187 | &Handle\r | |
188 | );\r | |
189 | ASSERT_EFI_ERROR (Status);\r | |
190 | \r | |
191 | Status = mHiiDatabase->RegisterPackageNotify (\r | |
192 | mHiiDatabase,\r | |
4dd76ade | 193 | EFI_HII_PACKAGE_FORMS,\r |
0368663f | 194 | NULL,\r |
195 | NewOrAddPackNotify,\r | |
196 | EFI_HII_DATABASE_NOTIFY_NEW_PACK,\r | |
197 | &Handle\r | |
198 | );\r | |
199 | ASSERT_EFI_ERROR (Status);\r | |
200 | \r | |
201 | Status = mHiiDatabase->RegisterPackageNotify (\r | |
202 | mHiiDatabase,\r | |
4dd76ade | 203 | EFI_HII_PACKAGE_FORMS,\r |
0368663f | 204 | NULL,\r |
205 | NewOrAddPackNotify,\r | |
ea58467b | 206 | EFI_HII_DATABASE_NOTIFY_ADD_PACK,\r |
0368663f | 207 | &Handle\r |
ea58467b | 208 | );\r |
209 | ASSERT_EFI_ERROR (Status);\r | |
210 | \r | |
211 | Status = mHiiDatabase->RegisterPackageNotify (\r | |
212 | mHiiDatabase,\r | |
213 | EFI_HII_PACKAGE_STRINGS,\r | |
214 | NULL,\r | |
215 | RemovePackNotify,\r | |
216 | EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,\r | |
0368663f | 217 | &Handle\r |
ea58467b | 218 | );\r |
219 | ASSERT_EFI_ERROR (Status);\r | |
220 | \r | |
a235abd2 | 221 | InitSetBrowserStrings ();\r |
222 | \r | |
0368663f | 223 | mBrowserThunkPrivateDataTemplate.ThunkPrivate = Private;\r |
137c54ac | 224 | Status = gBS->InstallProtocolInterface (\r |
225 | &mBrowserThunkPrivateDataTemplate.Handle,\r | |
962045a2 | 226 | &gEfiFormBrowserCompatibilityProtocolGuid,\r |
137c54ac | 227 | EFI_NATIVE_INTERFACE,\r |
228 | (VOID *) &mBrowserThunkPrivateDataTemplate.FormBrowser\r | |
229 | );\r | |
230 | ASSERT_EFI_ERROR (Status);\r | |
231 | \r | |
4259256b | 232 | return Status;\r |
233 | }\r | |
234 | \r | |
3321fa09 | 235 | /**\r |
236 | Determines the handles that are currently active in the database.\r | |
237 | \r | |
238 | This function determines the handles that are currently active in the database. \r | |
239 | For example, a program wishing to create a Setup-like configuration utility would use this call \r | |
240 | to determine the handles that are available. It would then use calls defined in the forms section \r | |
241 | below to extract forms and then interpret them.\r | |
242 | \r | |
243 | @param This A pointer to the EFI_HII_PROTOCOL instance.\r | |
244 | @param HandleBufferLength On input, a pointer to the length of the handle buffer. \r | |
245 | On output, the length of the handle buffer that is required for the handles found.\r | |
246 | @param Handle An array of EFI_HII_HANDLE instances returned. \r | |
247 | Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack() in the Packages section.\r | |
248 | \r | |
249 | @retval EFI_SUCCESS Handle was updated successfully.\r | |
250 | \r | |
251 | @retval EFI_BUFFER_TOO_SMALL The HandleBufferLength parameter indicates that Handle is too small \r | |
252 | to support the number of handles. HandleBufferLength is updated with a value that \r | |
253 | will enable the data to fit.\r | |
254 | **/\r | |
4259256b | 255 | EFI_STATUS\r |
256 | EFIAPI\r | |
257 | HiiFindHandles (\r | |
258 | IN EFI_HII_PROTOCOL *This,\r | |
259 | IN OUT UINT16 *HandleBufferLength,\r | |
260 | OUT FRAMEWORK_EFI_HII_HANDLE Handle[1]\r | |
261 | )\r | |
4259256b | 262 | {\r |
ea58467b | 263 | UINT16 Count;\r |
0368663f | 264 | LIST_ENTRY *Link;\r |
265 | HII_THUNK_CONTEXT *ThunkContext;\r | |
266 | HII_THUNK_PRIVATE_DATA *Private;\r | |
ea58467b | 267 | \r |
268 | if (HandleBufferLength == NULL) {\r | |
269 | return EFI_INVALID_PARAMETER;\r | |
270 | }\r | |
271 | \r | |
0368663f | 272 | Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This); \r |
ea58467b | 273 | \r |
0368663f | 274 | //\r |
275 | // Count the number of handles.\r | |
276 | //\r | |
ea58467b | 277 | Count = 0;\r |
0368663f | 278 | Link = GetFirstNode (&Private->ThunkContextListHead);\r |
279 | while (!IsNull (&Private->ThunkContextListHead, Link)) {\r | |
ea58467b | 280 | Count++;\r |
0368663f | 281 | Link = GetNextNode (&Private->ThunkContextListHead, Link);\r |
ea58467b | 282 | }\r |
283 | \r | |
284 | if (Count > *HandleBufferLength) {\r | |
5990ace9 | 285 | *HandleBufferLength = (UINT16) (Count * sizeof (FRAMEWORK_EFI_HII_HANDLE));\r |
ea58467b | 286 | return EFI_BUFFER_TOO_SMALL;\r |
287 | }\r | |
288 | \r | |
0368663f | 289 | //\r |
290 | // Output the handles.\r | |
291 | //\r | |
ea58467b | 292 | Count = 0;\r |
0368663f | 293 | Link = GetFirstNode (&Private->ThunkContextListHead);\r |
294 | while (!IsNull (&Private->ThunkContextListHead, Link)) {\r | |
295 | \r | |
296 | ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r | |
297 | Handle[Count] = ThunkContext->FwHiiHandle;\r | |
ea58467b | 298 | \r |
ea58467b | 299 | Count++;\r |
0368663f | 300 | Link = GetNextNode (&Private->ThunkContextListHead, Link);\r |
301 | \r | |
302 | }\r | |
ea58467b | 303 | \r |
5990ace9 | 304 | *HandleBufferLength = (UINT16) (Count * sizeof (FRAMEWORK_EFI_HII_HANDLE));\r |
4259256b | 305 | return EFI_SUCCESS;\r |
306 | }\r | |
307 | \r | |
0368663f | 308 | EFI_STATUS\r |
309 | LangCodes3066To639 (\r | |
310 | IN CHAR8 *LangCodes3066,\r | |
311 | IN CHAR8 **LangCodes639\r | |
312 | )\r | |
313 | {\r | |
314 | CHAR8 *AsciiLangCodes;\r | |
0b09813f | 315 | CHAR8 *Lang;\r |
0368663f | 316 | UINTN Index;\r |
317 | UINTN Count;\r | |
318 | EFI_STATUS Status;\r | |
319 | \r | |
320 | ASSERT (LangCodes3066 != NULL);\r | |
321 | ASSERT (LangCodes639 != NULL);\r | |
322 | \r | |
0b09813f | 323 | //\r |
324 | // Allocate working buffer to contain substring of LangCodes3066.\r | |
325 | //\r | |
326 | Lang = AllocatePool (AsciiStrSize (LangCodes3066));\r | |
62c236c0 | 327 | if (Lang == NULL) {\r |
0b09813f | 328 | return EFI_OUT_OF_RESOURCES;\r |
329 | }\r | |
330 | \r | |
0368663f | 331 | //\r |
332 | // Count the number of RFC 3066 language codes.\r | |
333 | //\r | |
334 | Index = 0;\r | |
335 | AsciiLangCodes = LangCodes3066;\r | |
336 | while (AsciiStrLen (AsciiLangCodes) != 0) {\r | |
337 | HiiLibGetNextLanguage (&AsciiLangCodes, Lang);\r | |
338 | Index++;\r | |
339 | }\r | |
340 | \r | |
341 | Count = Index;\r | |
342 | \r | |
343 | //\r | |
344 | // \r | |
345 | //\r | |
346 | *LangCodes639 = AllocateZeroPool (ISO_639_2_ENTRY_SIZE * Count + 1);\r | |
347 | if (*LangCodes639 == NULL) {\r | |
0b09813f | 348 | Status = EFI_OUT_OF_RESOURCES;\r |
349 | goto Done;\r | |
0368663f | 350 | }\r |
351 | \r | |
352 | AsciiLangCodes = LangCodes3066;\r | |
353 | \r | |
354 | for (Index = 0; Index < Count; Index++) {\r | |
355 | HiiLibGetNextLanguage (&AsciiLangCodes, Lang);\r | |
356 | Status = ConvertRfc3066LanguageToIso639Language (Lang, *LangCodes639 + Index * ISO_639_2_ENTRY_SIZE);\r | |
357 | ASSERT_EFI_ERROR (Status);\r | |
358 | }\r | |
359 | \r | |
0b09813f | 360 | Status = EFI_SUCCESS;\r |
361 | \r | |
362 | Done:\r | |
363 | FreePool (Lang);\r | |
364 | return Status;\r | |
0368663f | 365 | }\r |
366 | \r | |
3321fa09 | 367 | /**\r |
368 | Allows a program to determine the primary languages that are supported on a given handle.\r | |
369 | \r | |
370 | This routine is intended to be used by drivers to query the interface database for supported languages. \r | |
371 | This routine returns a string of concatenated 3-byte language identifiers, one per string package associated with the handle.\r | |
372 | \r | |
373 | @param This A pointer to the EFI_HII_PROTOCOL instance.\r | |
374 | @param Handle The handle on which the strings reside. Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack() \r | |
375 | in the Packages section.\r | |
376 | @param LanguageString A string allocated by GetPrimaryLanguages() that contains a list of all primary languages \r | |
377 | registered on the handle. The routine will not return the three-spaces language identifier used in \r | |
378 | other functions to indicate non-language-specific strings.\r | |
379 | \r | |
380 | @reval EFI_SUCCESS LanguageString was correctly returned.\r | |
381 | \r | |
382 | @reval EFI_INVALID_PARAMETER The Handle was unknown.\r | |
383 | **/\r | |
4259256b | 384 | EFI_STATUS\r |
385 | EFIAPI\r | |
386 | HiiGetPrimaryLanguages (\r | |
3321fa09 | 387 | IN EFI_HII_PROTOCOL *This,\r |
388 | IN FRAMEWORK_EFI_HII_HANDLE Handle,\r | |
389 | OUT EFI_STRING *LanguageString\r | |
4259256b | 390 | )\r |
4259256b | 391 | {\r |
0368663f | 392 | HII_THUNK_PRIVATE_DATA *Private;\r |
ee3428bb | 393 | EFI_HII_HANDLE UefiHiiHandle;\r |
0368663f | 394 | CHAR8 *LangCodes3066;\r |
395 | CHAR16 *UnicodeLangCodes639;\r | |
396 | CHAR8 *LangCodes639;\r | |
397 | EFI_STATUS Status;\r | |
ee3428bb | 398 | \r |
0368663f | 399 | Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r |
ee3428bb | 400 | \r |
0368663f | 401 | UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r |
ee3428bb | 402 | if (UefiHiiHandle == NULL) {\r |
403 | return EFI_INVALID_PARAMETER;\r | |
404 | }\r | |
405 | \r | |
cb7d01c0 | 406 | LangCodes3066 = HiiGetSupportedLanguages (UefiHiiHandle);\r |
ee3428bb | 407 | \r |
0368663f | 408 | if (LangCodes3066 == NULL) {\r |
ee3428bb | 409 | return EFI_INVALID_PARAMETER;\r |
410 | }\r | |
411 | \r | |
0368663f | 412 | \r |
413 | LangCodes639 = NULL;\r | |
414 | Status = LangCodes3066To639 (LangCodes3066, &LangCodes639);\r | |
415 | if (EFI_ERROR (Status)) {\r | |
416 | goto Done;\r | |
417 | }\r | |
418 | \r | |
419 | UnicodeLangCodes639 = AllocateZeroPool (AsciiStrSize (LangCodes639) * sizeof (CHAR16));\r | |
420 | if (UnicodeLangCodes639 == NULL) {\r | |
421 | Status = EFI_OUT_OF_RESOURCES;\r | |
422 | goto Done;\r | |
ee3428bb | 423 | }\r |
424 | \r | |
425 | //\r | |
0368663f | 426 | // The language returned is in RFC 639-2 format.\r |
ee3428bb | 427 | //\r |
0368663f | 428 | AsciiStrToUnicodeStr (LangCodes639, UnicodeLangCodes639);\r |
429 | *LanguageString = UnicodeLangCodes639;\r | |
ee3428bb | 430 | \r |
0368663f | 431 | Done:\r |
432 | FreePool (LangCodes3066);\r | |
7001eaf8 | 433 | if (LangCodes639 != NULL) {\r |
434 | FreePool (LangCodes639);\r | |
435 | }\r | |
0368663f | 436 | \r |
437 | return Status;\r | |
4259256b | 438 | }\r |
439 | \r | |
cb7d01c0 | 440 | /**\r |
441 | This function returns the list of supported 2nd languages, in the format specified\r | |
442 | in UEFI specification Appendix M.\r | |
443 | \r | |
444 | If HiiHandle is not a valid Handle in the HII database, then ASSERT.\r | |
445 | If not enough resource to complete the operation, then ASSERT.\r | |
446 | \r | |
447 | @param HiiHandle The HII package list handle.\r | |
448 | @param FirstLanguage Pointer to language name buffer.\r | |
449 | \r | |
450 | @return The supported languages.\r | |
451 | \r | |
452 | **/\r | |
453 | CHAR8 *\r | |
454 | EFIAPI\r | |
455 | HiiGetSupportedSecondaryLanguages (\r | |
456 | IN EFI_HII_HANDLE HiiHandle,\r | |
457 | IN CONST CHAR8 *FirstLanguage\r | |
458 | )\r | |
459 | {\r | |
460 | EFI_STATUS Status;\r | |
461 | UINTN BufferSize;\r | |
462 | CHAR8 *LanguageString;\r | |
463 | \r | |
464 | ASSERT (HiiHandle != NULL);\r | |
465 | \r | |
466 | //\r | |
467 | // Collect current supported 2nd Languages for given HII handle\r | |
468 | // First try allocate 4K buffer to store the current supported 2nd languages.\r | |
469 | //\r | |
470 | BufferSize = 0x1000;\r | |
471 | LanguageString = AllocateZeroPool (BufferSize);\r | |
472 | if (LanguageString == NULL) {\r | |
473 | return NULL;\r | |
474 | }\r | |
475 | \r | |
476 | Status = mHiiStringProtocol->GetSecondaryLanguages (mHiiStringProtocol, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r | |
477 | ASSERT (Status != EFI_NOT_FOUND);\r | |
478 | \r | |
479 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
480 | FreePool (LanguageString);\r | |
481 | LanguageString = AllocateZeroPool (BufferSize);\r | |
482 | if (LanguageString == NULL) {\r | |
483 | return NULL;\r | |
484 | }\r | |
485 | \r | |
486 | Status = mHiiStringProtocol->GetSecondaryLanguages (mHiiStringProtocol, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r | |
487 | }\r | |
488 | \r | |
489 | if (EFI_ERROR (Status)) {\r | |
490 | LanguageString = NULL;\r | |
491 | }\r | |
492 | \r | |
493 | return LanguageString;\r | |
494 | }\r | |
0368663f | 495 | \r |
3321fa09 | 496 | /**\r |
497 | Allows a program to determine which secondary languages are supported on a given handle for a given primary language\r | |
0368663f | 498 | \r |
3321fa09 | 499 | This routine is intended to be used by drivers to query the interface database for supported languages. \r |
500 | This routine returns a string of concatenated 3-byte language identifiers, one per string package associated with the handle.\r | |
501 | \r | |
502 | @param This A pointer to the EFI_HII_PROTOCOL instance.\r | |
503 | @param Handle The handle on which the strings reside. Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack() \r | |
504 | in the Packages section.\r | |
505 | @param PrimaryLanguage Pointer to a NULL-terminated string containing a single ISO 639-2 language identifier, indicating \r | |
506 | the primary language.\r | |
507 | @param LanguageString A string allocated by GetSecondaryLanguages() containing a list of all secondary languages registered \r | |
508 | on the handle. The routine will not return the three-spaces language identifier used in other functions \r | |
509 | to indicate non-language-specific strings, nor will it return the primary language. This function succeeds \r | |
510 | but returns a NULL LanguageString if there are no secondary languages associated with the input Handle and \r | |
511 | PrimaryLanguage pair. Type EFI_STRING is defined in String.\r | |
512 | \r | |
513 | @reval EFI_SUCCESS LanguageString was correctly returned.\r | |
514 | @reval EFI_INVALID_PARAMETER The Handle was unknown.\r | |
515 | **/\r | |
4259256b | 516 | EFI_STATUS\r |
517 | EFIAPI\r | |
518 | HiiGetSecondaryLanguages (\r | |
0368663f | 519 | IN EFI_HII_PROTOCOL *This,\r |
520 | IN FRAMEWORK_EFI_HII_HANDLE Handle,\r | |
521 | IN CHAR16 *PrimaryLanguage,\r | |
522 | OUT EFI_STRING *LanguageString\r | |
4259256b | 523 | )\r |
4259256b | 524 | {\r |
0b09813f | 525 | HII_THUNK_PRIVATE_DATA *Private;\r |
ee3428bb | 526 | EFI_HII_HANDLE UefiHiiHandle;\r |
0b09813f | 527 | CHAR8 *PrimaryLang3066;\r |
0368663f | 528 | CHAR8 *PrimaryLang639;\r |
529 | CHAR8 *SecLangCodes3066;\r | |
530 | CHAR8 *SecLangCodes639;\r | |
531 | CHAR16 *UnicodeSecLangCodes639;\r | |
532 | EFI_STATUS Status;\r | |
ee3428bb | 533 | \r |
0368663f | 534 | Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r |
ee3428bb | 535 | \r |
0b09813f | 536 | SecLangCodes639 = NULL;\r |
537 | SecLangCodes3066 = NULL;\r | |
538 | PrimaryLang3066 = NULL;\r | |
0368663f | 539 | UnicodeSecLangCodes639 = NULL;\r |
540 | \r | |
541 | UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r | |
ee3428bb | 542 | if (UefiHiiHandle == NULL) {\r |
543 | return EFI_INVALID_PARAMETER;\r | |
544 | }\r | |
545 | \r | |
0368663f | 546 | PrimaryLang639 = AllocateZeroPool (StrLen (PrimaryLanguage) + 1);\r |
547 | if (PrimaryLang639 == NULL) {\r | |
548 | Status = EFI_OUT_OF_RESOURCES;\r | |
549 | goto Done;\r | |
550 | }\r | |
ee3428bb | 551 | \r |
0368663f | 552 | UnicodeStrToAsciiStr (PrimaryLanguage, PrimaryLang639);\r |
ee3428bb | 553 | \r |
0b09813f | 554 | PrimaryLang3066 = ConvertIso639LanguageToRfc3066Language (PrimaryLang639);\r |
555 | ASSERT_EFI_ERROR (PrimaryLang3066 != NULL);\r | |
ee3428bb | 556 | \r |
cb7d01c0 | 557 | SecLangCodes3066 = HiiGetSupportedSecondaryLanguages (UefiHiiHandle, PrimaryLang3066);\r |
0368663f | 558 | \r |
559 | if (SecLangCodes3066 == NULL) {\r | |
560 | Status = EFI_INVALID_PARAMETER;\r | |
561 | goto Done;\r | |
ee3428bb | 562 | }\r |
563 | \r | |
0368663f | 564 | Status = LangCodes3066To639 (SecLangCodes3066, &SecLangCodes639);\r |
565 | if (EFI_ERROR (Status)) {\r | |
566 | goto Done;\r | |
567 | }\r | |
568 | \r | |
569 | UnicodeSecLangCodes639 = AllocateZeroPool (AsciiStrSize (SecLangCodes639) * sizeof (CHAR16));\r | |
570 | if (UnicodeSecLangCodes639 == NULL) {\r | |
571 | Status = EFI_OUT_OF_RESOURCES;\r | |
572 | goto Done;\r | |
ee3428bb | 573 | }\r |
574 | \r | |
575 | //\r | |
576 | // The language returned is in RFC 3066 format.\r | |
577 | //\r | |
0368663f | 578 | *LanguageString = AsciiStrToUnicodeStr (SecLangCodes639, UnicodeSecLangCodes639);\r |
ee3428bb | 579 | \r |
0368663f | 580 | Done:\r |
7001eaf8 | 581 | if (PrimaryLang639 != NULL) {\r |
582 | FreePool (PrimaryLang639);\r | |
583 | }\r | |
0b09813f | 584 | \r |
7001eaf8 | 585 | if (SecLangCodes639 != NULL) {\r |
586 | FreePool (SecLangCodes639);\r | |
587 | }\r | |
0b09813f | 588 | \r |
589 | if (PrimaryLang3066 != NULL) {\r | |
590 | FreePool (PrimaryLang3066);\r | |
591 | }\r | |
592 | \r | |
7001eaf8 | 593 | if (SecLangCodes3066 != NULL) {\r |
594 | FreePool (SecLangCodes3066);\r | |
595 | }\r | |
596 | if (UnicodeSecLangCodes639 != NULL) {\r | |
597 | FreePool (UnicodeSecLangCodes639);\r | |
598 | }\r | |
0368663f | 599 | \r |
600 | return Status;\r | |
137c54ac | 601 | }\r |
4259256b | 602 | \r |
0368663f | 603 | \r |