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