3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 MiscNumberOfInstallableLanguagesFunction.c
21 This driver parses the mSmbiosMiscDataTable structure and reports
27 #include "CommonHeader.h"
29 #include "MiscSubclassDriver.h"
32 Check whether the language is supported for given HII handle
34 @param HiiHandle The HII package list handle.
35 @param Offset The offest of current lanague in the supported languages.
36 @param CurrentLang The language code.
38 @retval TRUE Supported.
39 @retval FALSE Not Supported.
44 CurrentLanguageMatch (
45 IN EFI_HII_HANDLE HiiHandle
,
47 OUT CHAR8
*CurrentLang
57 Languages
= HiiGetSupportedLanguages (HiiHandle
);
58 if (Languages
== NULL
) {
62 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
63 DefaultLang
= (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
);
64 BestLanguage
= GetBestLanguage (
67 (CurrentLang
!= NULL
) ? CurrentLang
: "",
71 if (BestLanguage
!= NULL
) {
73 // Find the best matching RFC 4646 language, compute the offset.
75 CompareLength
= AsciiStrLen (BestLanguage
);
76 for (MatchLang
= Languages
, (*Offset
) = 0; MatchLang
!= '\0'; (*Offset
)++) {
78 // Seek to the end of current match language.
80 for (EndMatchLang
= MatchLang
; *EndMatchLang
!= '\0' && *EndMatchLang
!= ';'; EndMatchLang
++);
82 if ((EndMatchLang
== MatchLang
+ CompareLength
) && AsciiStrnCmp(MatchLang
, BestLanguage
, CompareLength
) == 0) {
84 // Find the current best Language in the supported languages
89 // best language match be in the supported language.
91 ASSERT (*EndMatchLang
== ';');
92 MatchLang
= EndMatchLang
+ 1;
94 FreePool (BestLanguage
);
98 if (CurrentLang
!= NULL
) {
99 FreePool (CurrentLang
);
106 Get next language from language code list (with separator ';').
108 @param LangCode Input: point to first language in the list. On
109 Otput: point to next language in the list, or
110 NULL if no more language in the list.
111 @param Lang The first language in the list.
117 IN OUT CHAR8
**LangCode
,
124 ASSERT (LangCode
!= NULL
);
125 ASSERT (*LangCode
!= NULL
);
126 ASSERT (Lang
!= NULL
);
129 StringPtr
= *LangCode
;
130 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
134 CopyMem (Lang
, StringPtr
, Index
);
137 if (StringPtr
[Index
] == ';') {
140 *LangCode
= StringPtr
+ Index
;
144 This function returns the number of supported languages on HiiHandle.
146 @param HiiHandle The HII package list handle.
148 @retval The number of supported languages.
153 GetSupportedLanguageNumber (
154 IN EFI_HII_HANDLE HiiHandle
159 CHAR8
*LanguageString
;
162 Languages
= HiiGetSupportedLanguages (HiiHandle
);
163 if (Languages
== NULL
) {
168 Lang
= AllocatePool (AsciiStrSize (Languages
));
170 LanguageString
= Languages
;
171 while (*LanguageString
!= 0) {
172 GetNextLanguage (&LanguageString
, Lang
);
177 FreePool (Languages
);
183 This function makes boot time changes to the contents of the
184 MiscNumberOfInstallableLanguages (Type 13).
186 @param RecordData Pointer to copy of RecordData from the Data Table.
188 @retval EFI_SUCCESS All parameters were valid.
189 @retval EFI_UNSUPPORTED Unexpected RecordType value.
190 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
193 MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages
)
196 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
197 CHAR8
*OptionalStrStart
;
200 EFI_SMBIOS_HANDLE SmbiosHandle
;
201 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
202 EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*ForType13InputData
;
204 ForType13InputData
= (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES
*)RecordData
;
207 // First check for invalid parameters.
209 if (RecordData
== NULL
) {
210 return EFI_INVALID_PARAMETER
;
213 ForType13InputData
->NumberOfInstallableLanguages
= GetSupportedLanguageNumber (mHiiHandle
);
216 // Try to check if current langcode matches with the langcodes in installed languages
218 ZeroMem(CurrentLang
, SMBIOS_STRING_MAX_LENGTH
+ 1);
219 CurrentLanguageMatch (mHiiHandle
, &Offset
, CurrentLang
);
220 LangStrLen
= AsciiStrLen(CurrentLang
);
223 // Two zeros following the last string.
225 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
226 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
228 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION
;
229 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
232 // Make handle chosen by smbios protocol.add automatically.
234 SmbiosRecord
->Hdr
.Handle
= 0;
236 SmbiosRecord
->InstallableLanguages
= (UINT8
)ForType13InputData
->NumberOfInstallableLanguages
;
237 SmbiosRecord
->Flags
= (UINT8
)ForType13InputData
->LanguageFlags
.AbbreviatedLanguageFormat
;
238 SmbiosRecord
->CurrentLanguages
= 1;
239 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
240 AsciiStrCpy(OptionalStrStart
, CurrentLang
);
243 // Now we have got the full smbios record, call smbios protocol to add this record.
245 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
246 Status
= Smbios
-> Add(
250 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
252 FreePool(SmbiosRecord
);