3 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include "MiscSubclassDriver.h"
16 Check whether the language is supported for given HII handle
18 @param HiiHandle The HII package list handle.
19 @param Offset The offest of current lanague in the supported languages.
20 @param CurrentLang The language code.
22 @retval TRUE Supported.
23 @retval FALSE Not Supported.
28 CurrentLanguageMatch (
29 IN EFI_HII_HANDLE HiiHandle
,
31 OUT CHAR8
*CurrentLang
41 Languages
= HiiGetSupportedLanguages (HiiHandle
);
42 if (Languages
== NULL
) {
46 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&CurrentLang
, NULL
);
47 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
48 BestLanguage
= GetBestLanguage (
51 (CurrentLang
!= NULL
) ? CurrentLang
: "",
55 if (BestLanguage
!= NULL
) {
57 // Find the best matching RFC 4646 language, compute the offset.
59 CompareLength
= AsciiStrLen (BestLanguage
);
60 for (MatchLang
= Languages
, (*Offset
) = 0; MatchLang
!= '\0'; (*Offset
)++) {
62 // Seek to the end of current match language.
64 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
66 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
68 // Find the current best Language in the supported languages
73 // best language match be in the supported language.
75 ASSERT (*EndMatchLang
== ';');
76 MatchLang
= EndMatchLang
+ 1;
78 FreePool (BestLanguage
);
82 if (CurrentLang
!= NULL
) {
83 FreePool (CurrentLang
);
90 Get next language from language code list (with separator ';').
92 @param LangCode Input: point to first language in the list. On
93 Otput: point to next language in the list, or
94 NULL if no more language in the list.
95 @param Lang The first language in the list.
101 IN OUT CHAR8
**LangCode
,
108 ASSERT (LangCode
!= NULL
);
109 ASSERT (*LangCode
!= NULL
);
110 ASSERT (Lang
!= NULL
);
113 StringPtr
= *LangCode
;
114 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
118 CopyMem (Lang
, StringPtr
, Index
);
121 if (StringPtr
[Index
] == ';') {
124 *LangCode
= StringPtr
+ Index
;
128 This function returns the number of supported languages on HiiHandle.
130 @param HiiHandle The HII package list handle.
132 @retval The number of supported languages.
137 GetSupportedLanguageNumber (
138 IN EFI_HII_HANDLE HiiHandle
143 CHAR8
*LanguageString
;
146 Languages
= HiiGetSupportedLanguages (HiiHandle
);
147 if (Languages
== NULL
) {
152 Lang
= AllocatePool (AsciiStrSize (Languages
));
154 LanguageString
= Languages
;
155 while (*LanguageString
!= 0) {
156 GetNextLanguage (&LanguageString
, Lang
);
161 FreePool (Languages
);
167 This function makes boot time changes to the contents of the
168 MiscNumberOfInstallableLanguages (Type 13).
170 @param RecordData Pointer to copy of RecordData from the Data Table.
172 @retval EFI_SUCCESS All parameters were valid.
173 @retval EFI_UNSUPPORTED Unexpected RecordType value.
174 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
177 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
180 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
181 CHAR8
*OptionalStrStart
;
184 EFI_SMBIOS_HANDLE SmbiosHandle
;
185 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
186 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
188 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
191 // First check for invalid parameters.
193 if (RecordData
== NULL
) {
194 return EFI_INVALID_PARAMETER
;
197 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
200 // Try to check if current langcode matches with the langcodes in installed languages
202 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
203 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
204 LangStrLen
= AsciiStrLen(CurrentLang
);
207 // Two zeros following the last string.
209 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
210 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
212 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
213 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
215 // Make handle chosen by smbios protocol.add automatically.
217 SmbiosRecord
->Hdr
.Handle
= 0;
219 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
220 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
221 SmbiosRecord
->CurrentLanguages
= 1;
222 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
223 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
225 // Now we have got the full smbios record, call smbios protocol to add this record.
227 Status
= AddSmbiosRecord (Smbios
, &SmbiosHandle
, (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
);
229 FreePool(SmbiosRecord
);