2 This driver parses the mSmbiosMiscDataTable structure and reports
5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "MiscSubClassDriver.h"
12 Check whether the language is supported for given HII handle
14 @param HiiHandle The HII package list handle.
15 @param Offset The offest of current lanague in the supported languages.
16 @param CurrentLang The language code.
18 @retval TRUE Supported.
19 @retval FALSE Not Supported.
24 CurrentLanguageMatch (
25 IN EFI_HII_HANDLE HiiHandle
,
27 OUT CHAR8
*CurrentLang
37 Languages
= HiiGetSupportedLanguages (HiiHandle
);
38 if (Languages
== NULL
) {
42 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
43 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
44 BestLanguage
= GetBestLanguage (
47 (CurrentLang
!= NULL
) ? CurrentLang
: "",
51 if (BestLanguage
!= NULL
) {
53 // Find the best matching RFC 4646 language, compute the offset.
55 CompareLength
= AsciiStrLen (BestLanguage
);
56 for (MatchLang
= Languages
, (*Offset
) = 0; MatchLang
!= '\0'; (*Offset
)++) {
58 // Seek to the end of current match language.
60 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
62 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
64 // Find the current best Language in the supported languages
69 // best language match be in the supported language.
71 ASSERT (*EndMatchLang
== ';');
72 MatchLang
= EndMatchLang
+ 1;
74 FreePool (BestLanguage
);
78 if (CurrentLang
!= NULL
) {
79 FreePool (CurrentLang
);
86 Get next language from language code list (with separator ';').
88 @param LangCode Input: point to first language in the list. On
89 Otput: point to next language in the list, or
90 NULL if no more language in the list.
91 @param Lang The first language in the list.
97 IN OUT CHAR8
**LangCode
,
104 ASSERT (LangCode
!= NULL
);
105 ASSERT (*LangCode
!= NULL
);
106 ASSERT (Lang
!= NULL
);
109 StringPtr
= *LangCode
;
110 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
114 CopyMem (Lang
, StringPtr
, Index
);
117 if (StringPtr
[Index
] == ';') {
120 *LangCode
= StringPtr
+ Index
;
124 This function returns the number of supported languages on HiiHandle.
126 @param HiiHandle The HII package list handle.
128 @retval The number of supported languages.
133 GetSupportedLanguageNumber (
134 IN EFI_HII_HANDLE HiiHandle
139 CHAR8
*LanguageString
;
142 Languages
= HiiGetSupportedLanguages (HiiHandle
);
143 if (Languages
== NULL
) {
148 Lang
= AllocatePool (AsciiStrSize (Languages
));
150 LanguageString
= Languages
;
151 while (*LanguageString
!= 0) {
152 GetNextLanguage (&LanguageString
, Lang
);
157 FreePool (Languages
);
163 This function makes boot time changes to the contents of the
164 MiscNumberOfInstallableLanguages (Type 13).
166 @param RecordData Pointer to copy of RecordData from the Data Table.
168 @retval EFI_SUCCESS All parameters were valid.
169 @retval EFI_UNSUPPORTED Unexpected RecordType value.
170 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
173 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
176 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
177 CHAR8
*OptionalStrStart
;
180 EFI_SMBIOS_HANDLE SmbiosHandle
;
181 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
182 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
184 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
187 // First check for invalid parameters.
189 if (RecordData
== NULL
) {
190 return EFI_INVALID_PARAMETER
;
193 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
196 // Try to check if current langcode matches with the langcodes in installed languages
198 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
199 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
200 LangStrLen
= AsciiStrLen(CurrentLang
);
203 // Two zeros following the last string.
205 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
206 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
208 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
209 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
211 // Make handle chosen by smbios protocol.add automatically.
213 SmbiosRecord
->Hdr
.Handle
= 0;
215 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
216 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
217 SmbiosRecord
->CurrentLanguages
= 1;
218 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
219 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
221 // Now we have got the full smbios record, call smbios protocol to add this record.
223 Status
= AddSmbiosRecord (Smbios
, &SmbiosHandle
, (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
);
225 FreePool(SmbiosRecord
);