3 Copyright (c) 2009, Intel Corporation. All rights reserved. <BR>
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
15 MiscNumberOfInstallableLanguagesFunction.c
19 This driver parses the mSmbiosMiscDataTable structure and reports
24 #include "MiscSubClassDriver.h"
26 Check whether the language is supported for given HII handle
28 @param HiiHandle The HII package list handle.
29 @param Offset The offest of current lanague in the supported languages.
30 @param CurrentLang The language code.
32 @retval TRUE Supported.
33 @retval FALSE Not Supported.
38 CurrentLanguageMatch (
39 IN EFI_HII_HANDLE HiiHandle
,
41 OUT CHAR8
*CurrentLang
51 Languages
= HiiGetSupportedLanguages (HiiHandle
);
52 if (Languages
== NULL
) {
56 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
57 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
58 BestLanguage
= GetBestLanguage (
61 (CurrentLang
!= NULL
) ? CurrentLang
: "",
65 if (BestLanguage
!= NULL
) {
67 // Find the best matching RFC 4646 language, compute the offset.
69 CompareLength
= AsciiStrLen (BestLanguage
);
70 for (MatchLang
= Languages
, (*Offset
) = 0; MatchLang
!= '\0'; (*Offset
)++) {
72 // Seek to the end of current match language.
74 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
76 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
78 // Find the current best Language in the supported languages
83 // best language match be in the supported language.
85 ASSERT (*EndMatchLang
== ';');
86 MatchLang
= EndMatchLang
+ 1;
88 FreePool (BestLanguage
);
92 if (CurrentLang
!= NULL
) {
93 FreePool (CurrentLang
);
100 Get next language from language code list (with separator ';').
102 @param LangCode Input: point to first language in the list. On
103 Otput: point to next language in the list, or
104 NULL if no more language in the list.
105 @param Lang The first language in the list.
111 IN OUT CHAR8
**LangCode
,
118 ASSERT (LangCode
!= NULL
);
119 ASSERT (*LangCode
!= NULL
);
120 ASSERT (Lang
!= NULL
);
123 StringPtr
= *LangCode
;
124 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
128 CopyMem (Lang
, StringPtr
, Index
);
131 if (StringPtr
[Index
] == ';') {
134 *LangCode
= StringPtr
+ Index
;
138 This function returns the number of supported languages on HiiHandle.
140 @param HiiHandle The HII package list handle.
142 @retval The number of supported languages.
147 GetSupportedLanguageNumber (
148 IN EFI_HII_HANDLE HiiHandle
153 CHAR8
*LanguageString
;
156 Languages
= HiiGetSupportedLanguages (HiiHandle
);
157 if (Languages
== NULL
) {
162 Lang
= AllocatePool (AsciiStrSize (Languages
));
164 LanguageString
= Languages
;
165 while (*LanguageString
!= 0) {
166 GetNextLanguage (&LanguageString
, Lang
);
171 FreePool (Languages
);
177 This function makes boot time changes to the contents of the
178 MiscNumberOfInstallableLanguages (Type 13).
180 @param RecordData Pointer to copy of RecordData from the Data Table.
182 @retval EFI_SUCCESS All parameters were valid.
183 @retval EFI_UNSUPPORTED Unexpected RecordType value.
184 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
187 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
190 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
191 CHAR8
*OptionalStrStart
;
194 EFI_SMBIOS_HANDLE SmbiosHandle
;
195 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
196 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
198 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
201 // First check for invalid parameters.
203 if (RecordData
== NULL
) {
204 return EFI_INVALID_PARAMETER
;
207 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
210 // Try to check if current langcode matches with the langcodes in installed languages
212 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
213 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
214 LangStrLen
= AsciiStrLen(CurrentLang
);
217 // Two zeros following the last string.
219 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
220 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
222 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
223 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
225 // Make handle chosen by smbios protocol.add automatically.
227 SmbiosRecord
->Hdr
.Handle
= 0;
229 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
230 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
231 SmbiosRecord
->CurrentLanguages
= 1;
232 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
233 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
235 // Now we have got the full smbios record, call smbios protocol to add this record.
238 Status
= Smbios
-> Add(
242 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
244 FreePool(SmbiosRecord
);