3 Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
14 MiscNumberOfInstallableLanguagesFunction.c
18 This driver parses the mSmbiosMiscDataTable structure and reports
24 #include "CommonHeader.h"
26 #include "MiscSubclassDriver.h"
29 Check whether the language is supported for given HII handle
31 @param HiiHandle The HII package list handle.
32 @param Offset The offest of current lanague in the supported languages.
33 @param CurrentLang The language code.
35 @retval TRUE Supported.
36 @retval FALSE Not Supported.
41 CurrentLanguageMatch (
42 IN EFI_HII_HANDLE HiiHandle
,
44 OUT CHAR8
*CurrentLang
54 Languages
= HiiGetSupportedLanguages (HiiHandle
);
55 if (Languages
== NULL
) {
59 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
60 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
61 BestLanguage
= GetBestLanguage (
64 (CurrentLang
!= NULL
) ? CurrentLang
: "",
68 if (BestLanguage
!= NULL
) {
70 // Find the best matching RFC 4646 language, compute the offset.
72 CompareLength
= AsciiStrLen (BestLanguage
);
73 for (MatchLang
= Languages
, (*Offset
) = 0; *MatchLang
!= '\0'; (*Offset
)++) {
75 // Seek to the end of current match language.
77 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
79 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
81 // Find the current best Language in the supported languages
86 // best language match be in the supported language.
88 ASSERT (*EndMatchLang
== ';');
89 MatchLang
= EndMatchLang
+ 1;
91 FreePool (BestLanguage
);
95 if (CurrentLang
!= NULL
) {
96 FreePool (CurrentLang
);
103 Get next language from language code list (with separator ';').
105 @param LangCode Input: point to first language in the list. On
106 Otput: point to next language in the list, or
107 NULL if no more language in the list.
108 @param Lang The first language in the list.
114 IN OUT CHAR8
**LangCode
,
121 ASSERT (LangCode
!= NULL
);
122 ASSERT (*LangCode
!= NULL
);
123 ASSERT (Lang
!= NULL
);
126 StringPtr
= *LangCode
;
127 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
131 CopyMem (Lang
, StringPtr
, Index
);
134 if (StringPtr
[Index
] == ';') {
137 *LangCode
= StringPtr
+ Index
;
141 This function returns the number of supported languages on HiiHandle.
143 @param HiiHandle The HII package list handle.
145 @retval The number of supported languages.
150 GetSupportedLanguageNumber (
151 IN EFI_HII_HANDLE HiiHandle
156 CHAR8
*LanguageString
;
159 Languages
= HiiGetSupportedLanguages (HiiHandle
);
160 if (Languages
== NULL
) {
165 Lang
= AllocatePool (AsciiStrSize (Languages
));
167 LanguageString
= Languages
;
168 while (*LanguageString
!= 0) {
169 GetNextLanguage (&LanguageString
, Lang
);
174 FreePool (Languages
);
180 This function makes boot time changes to the contents of the
181 MiscNumberOfInstallableLanguages (Type 13).
183 @param RecordData Pointer to copy of RecordData from the Data Table.
185 @retval EFI_SUCCESS All parameters were valid.
186 @retval EFI_UNSUPPORTED Unexpected RecordType value.
187 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
190 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
193 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
194 CHAR8
*OptionalStrStart
;
197 EFI_SMBIOS_HANDLE SmbiosHandle
;
198 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
199 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
201 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
204 // First check for invalid parameters.
206 if (RecordData
== NULL
) {
207 return EFI_INVALID_PARAMETER
;
210 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
213 // Try to check if current langcode matches with the langcodes in installed languages
215 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
216 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
217 LangStrLen
= AsciiStrLen(CurrentLang
);
220 // Two zeros following the last string.
222 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
223 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
225 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
226 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
229 // Make handle chosen by smbios protocol.add automatically.
231 SmbiosRecord
->Hdr
.Handle
= 0;
233 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
234 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
235 SmbiosRecord
->CurrentLanguages
= 1;
236 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
237 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
240 // Now we have got the full smbios record, call smbios protocol to add this record.
242 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
243 Status
= Smbios
-> Add(
247 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
249 FreePool(SmbiosRecord
);