3 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
8 #include "MiscSubclassDriver.h"
10 Check whether the language is supported for given HII handle
12 @param HiiHandle The HII package list handle.
13 @param Offset The offest of current lanague in the supported languages.
14 @param CurrentLang The language code.
16 @retval TRUE Supported.
17 @retval FALSE Not Supported.
22 CurrentLanguageMatch (
23 IN EFI_HII_HANDLE HiiHandle
,
25 OUT CHAR8
*CurrentLang
35 Languages
= HiiGetSupportedLanguages (HiiHandle
);
36 if (Languages
== NULL
) {
40 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&CurrentLang
, NULL
);
41 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
42 BestLanguage
= GetBestLanguage (
45 (CurrentLang
!= NULL
) ? CurrentLang
: "",
49 if (BestLanguage
!= NULL
) {
51 // Find the best matching RFC 4646 language, compute the offset.
53 CompareLength
= AsciiStrLen (BestLanguage
);
54 for (MatchLang
= Languages
, (*Offset
) = 0; MatchLang
!= '\0'; (*Offset
)++) {
56 // Seek to the end of current match language.
58 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
60 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
62 // Find the current best Language in the supported languages
67 // best language match be in the supported language.
69 ASSERT (*EndMatchLang
== ';');
70 MatchLang
= EndMatchLang
+ 1;
72 FreePool (BestLanguage
);
76 if (CurrentLang
!= NULL
) {
77 FreePool (CurrentLang
);
84 Get next language from language code list (with separator ';').
86 @param LangCode Input: point to first language in the list. On
87 Otput: point to next language in the list, or
88 NULL if no more language in the list.
89 @param Lang The first language in the list.
95 IN OUT CHAR8
**LangCode
,
102 ASSERT (LangCode
!= NULL
);
103 ASSERT (*LangCode
!= NULL
);
104 ASSERT (Lang
!= NULL
);
107 StringPtr
= *LangCode
;
108 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
112 CopyMem (Lang
, StringPtr
, Index
);
115 if (StringPtr
[Index
] == ';') {
118 *LangCode
= StringPtr
+ Index
;
122 This function returns the number of supported languages on HiiHandle.
124 @param HiiHandle The HII package list handle.
126 @retval The number of supported languages.
131 GetSupportedLanguageNumber (
132 IN EFI_HII_HANDLE HiiHandle
137 CHAR8
*LanguageString
;
140 Languages
= HiiGetSupportedLanguages (HiiHandle
);
141 if (Languages
== NULL
) {
146 Lang
= AllocatePool (AsciiStrSize (Languages
));
148 LanguageString
= Languages
;
149 while (*LanguageString
!= 0) {
150 GetNextLanguage (&LanguageString
, Lang
);
155 FreePool (Languages
);
161 This function makes boot time changes to the contents of the
162 MiscNumberOfInstallableLanguages (Type 13).
164 @param RecordData Pointer to copy of RecordData from the Data Table.
166 @retval EFI_SUCCESS All parameters were valid.
167 @retval EFI_UNSUPPORTED Unexpected RecordType value.
168 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
171 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
174 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
175 CHAR8
*OptionalStrStart
;
178 EFI_SMBIOS_HANDLE SmbiosHandle
;
179 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
180 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
182 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
185 // First check for invalid parameters.
187 if (RecordData
== NULL
) {
188 return EFI_INVALID_PARAMETER
;
191 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
194 // Try to check if current langcode matches with the langcodes in installed languages
196 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
197 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
198 LangStrLen
= AsciiStrLen(CurrentLang
);
201 // Two zeros following the last string.
203 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
204 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
206 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
207 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
209 // Make handle chosen by smbios protocol.add automatically.
211 SmbiosRecord
->Hdr
.Handle
= 0;
213 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
214 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
215 SmbiosRecord
->CurrentLanguages
= 1;
216 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
217 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
219 // Now we have got the full smbios record, call smbios protocol to add this record.
221 Status
= AddSmbiosRecord (Smbios
, &SmbiosHandle
, (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
);
223 FreePool(SmbiosRecord
);