3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 MiscNumberOfInstallableLanguagesFunction.c
16 This driver parses the mSmbiosMiscDataTable structure and reports
22 #include "CommonHeader.h"
24 #include "MiscSubclassDriver.h"
27 Check whether the language is supported for given HII handle
29 @param HiiHandle The HII package list handle.
30 @param Offset The offest of current lanague in the supported languages.
31 @param CurrentLang The language code.
33 @retval TRUE Supported.
34 @retval FALSE Not Supported.
39 CurrentLanguageMatch (
40 IN EFI_HII_HANDLE HiiHandle
,
42 OUT CHAR8
*CurrentLang
52 Languages
= HiiGetSupportedLanguages (HiiHandle
);
53 if (Languages
== NULL
) {
57 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
58 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
59 BestLanguage
= GetBestLanguage (
62 (CurrentLang
!= NULL
) ? CurrentLang
: "",
66 if (BestLanguage
!= NULL
) {
68 // Find the best matching RFC 4646 language, compute the offset.
70 CompareLength
= AsciiStrLen (BestLanguage
);
71 for (MatchLang
= Languages
, (*Offset
) = 0; MatchLang
!= '\0'; (*Offset
)++) {
73 // Seek to the end of current match language.
75 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
77 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
79 // Find the current best Language in the supported languages
84 // best language match be in the supported language.
86 ASSERT (*EndMatchLang
== ';');
87 MatchLang
= EndMatchLang
+ 1;
89 FreePool (BestLanguage
);
93 if (CurrentLang
!= NULL
) {
94 FreePool (CurrentLang
);
101 Get next language from language code list (with separator ';').
103 @param LangCode Input: point to first language in the list. On
104 Otput: point to next language in the list, or
105 NULL if no more language in the list.
106 @param Lang The first language in the list.
112 IN OUT CHAR8
**LangCode
,
119 ASSERT (LangCode
!= NULL
);
120 ASSERT (*LangCode
!= NULL
);
121 ASSERT (Lang
!= NULL
);
124 StringPtr
= *LangCode
;
125 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
129 CopyMem (Lang
, StringPtr
, Index
);
132 if (StringPtr
[Index
] == ';') {
135 *LangCode
= StringPtr
+ Index
;
139 This function returns the number of supported languages on HiiHandle.
141 @param HiiHandle The HII package list handle.
143 @retval The number of supported languages.
148 GetSupportedLanguageNumber (
149 IN EFI_HII_HANDLE HiiHandle
154 CHAR8
*LanguageString
;
157 Languages
= HiiGetSupportedLanguages (HiiHandle
);
158 if (Languages
== NULL
) {
163 Lang
= AllocatePool (AsciiStrSize (Languages
));
165 LanguageString
= Languages
;
166 while (*LanguageString
!= 0) {
167 GetNextLanguage (&LanguageString
, Lang
);
172 FreePool (Languages
);
178 This function makes boot time changes to the contents of the
179 MiscNumberOfInstallableLanguages (Type 13).
181 @param RecordData Pointer to copy of RecordData from the Data Table.
183 @retval EFI_SUCCESS All parameters were valid.
184 @retval EFI_UNSUPPORTED Unexpected RecordType value.
185 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
188 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
191 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
192 CHAR8
*OptionalStrStart
;
195 EFI_SMBIOS_HANDLE SmbiosHandle
;
196 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
197 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
199 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
202 // First check for invalid parameters.
204 if (RecordData
== NULL
) {
205 return EFI_INVALID_PARAMETER
;
208 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
211 // Try to check if current langcode matches with the langcodes in installed languages
213 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
214 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
215 LangStrLen
= AsciiStrLen(CurrentLang
);
218 // Two zeros following the last string.
220 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
221 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
223 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
224 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
227 // Make handle chosen by smbios protocol.add automatically.
229 SmbiosRecord
->Hdr
.Handle
= 0;
231 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
232 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
233 SmbiosRecord
->CurrentLanguages
= 1;
234 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
235 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
238 // Now we have got the full smbios record, call smbios protocol to add this record.
240 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
241 Status
= Smbios
-> Add(
245 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
247 FreePool(SmbiosRecord
);