2 This driver parses the mSmbiosMiscDataTable structure and reports
5 Copyright (c) 2013-2015 Intel Corporation.
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "CommonHeader.h"
21 #include "SmbiosMisc.h"
23 Check whether the language is supported for given HII handle
25 @param HiiHandle The HII package list handle.
26 @param Offset The offest of current lanague in the supported languages.
27 @param CurrentLang The language code.
29 @retval TRUE Supported.
30 @retval FALSE Not Supported.
35 CurrentLanguageMatch (
36 IN EFI_HII_HANDLE HiiHandle
,
38 OUT CHAR8
*CurrentLang
49 Languages
= HiiGetSupportedLanguages (HiiHandle
);
50 if (Languages
== NULL
) {
55 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
56 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
57 BestLanguage
= GetBestLanguage (
60 (CurrentLang
!= NULL
) ? CurrentLang
: "",
64 if (BestLanguage
!= NULL
) {
66 // 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
;
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
214 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
215 LangMatch
= CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
216 LangStrLen
= AsciiStrLen(CurrentLang
);
219 // Two zeros following the last string.
221 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
222 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
224 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
225 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
);
237 // Now we have got the full smbios record, call smbios protocol to add this record.
239 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
240 Status
= Smbios
-> Add(
244 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
246 FreePool(SmbiosRecord
);