2 This driver parses the mSmbiosMiscDataTable structure and reports
5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "MiscSubClassDriver.h"
18 Check whether the language is supported for given HII handle
20 @param HiiHandle The HII package list handle.
21 @param Offset The offest of current lanague in the supported languages.
22 @param CurrentLang The language code.
24 @retval TRUE Supported.
25 @retval FALSE Not Supported.
30 CurrentLanguageMatch (
31 IN EFI_HII_HANDLE HiiHandle
,
33 OUT CHAR8
*CurrentLang
43 Languages
= HiiGetSupportedLanguages (HiiHandle
);
44 if (Languages
== NULL
) {
48 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
49 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
50 BestLanguage
= GetBestLanguage (
53 (CurrentLang
!= NULL
) ? CurrentLang
: "",
57 if (BestLanguage
!= NULL
) {
59 // Find the best matching RFC 4646 language, compute the offset.
61 CompareLength
= AsciiStrLen (BestLanguage
);
62 for (MatchLang
= Languages
, (*Offset
) = 0; MatchLang
!= '\0'; (*Offset
)++) {
64 // Seek to the end of current match language.
66 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
68 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
70 // Find the current best Language in the supported languages
75 // best language match be in the supported language.
77 ASSERT (*EndMatchLang
== ';');
78 MatchLang
= EndMatchLang
+ 1;
80 FreePool (BestLanguage
);
84 if (CurrentLang
!= NULL
) {
85 FreePool (CurrentLang
);
92 Get next language from language code list (with separator ';').
94 @param LangCode Input: point to first language in the list. On
95 Otput: point to next language in the list, or
96 NULL if no more language in the list.
97 @param Lang The first language in the list.
103 IN OUT CHAR8
**LangCode
,
110 ASSERT (LangCode
!= NULL
);
111 ASSERT (*LangCode
!= NULL
);
112 ASSERT (Lang
!= NULL
);
115 StringPtr
= *LangCode
;
116 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
120 CopyMem (Lang
, StringPtr
, Index
);
123 if (StringPtr
[Index
] == ';') {
126 *LangCode
= StringPtr
+ Index
;
130 This function returns the number of supported languages on HiiHandle.
132 @param HiiHandle The HII package list handle.
134 @retval The number of supported languages.
139 GetSupportedLanguageNumber (
140 IN EFI_HII_HANDLE HiiHandle
145 CHAR8
*LanguageString
;
148 Languages
= HiiGetSupportedLanguages (HiiHandle
);
149 if (Languages
== NULL
) {
154 Lang
= AllocatePool (AsciiStrSize (Languages
));
156 LanguageString
= Languages
;
157 while (*LanguageString
!= 0) {
158 GetNextLanguage (&LanguageString
, Lang
);
163 FreePool (Languages
);
169 This function makes boot time changes to the contents of the
170 MiscNumberOfInstallableLanguages (Type 13).
172 @param RecordData Pointer to copy of RecordData from the Data Table.
174 @retval EFI_SUCCESS All parameters were valid.
175 @retval EFI_UNSUPPORTED Unexpected RecordType value.
176 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
179 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
182 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
183 CHAR8
*OptionalStrStart
;
186 EFI_SMBIOS_HANDLE SmbiosHandle
;
187 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
188 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
190 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
193 // First check for invalid parameters.
195 if (RecordData
== NULL
) {
196 return EFI_INVALID_PARAMETER
;
199 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
202 // Try to check if current langcode matches with the langcodes in installed languages
204 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
205 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
206 LangStrLen
= AsciiStrLen(CurrentLang
);
209 // Two zeros following the last string.
211 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
212 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
214 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
215 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
217 // Make handle chosen by smbios protocol.add automatically.
219 SmbiosRecord
->Hdr
.Handle
= 0;
221 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
222 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
223 SmbiosRecord
->CurrentLanguages
= 1;
224 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
225 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
227 // Now we have got the full smbios record, call smbios protocol to add this record.
229 Status
= AddSmbiosRecord (Smbios
, &SmbiosHandle
, (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
);
231 FreePool(SmbiosRecord
);