]>
Commit | Line | Data |
---|---|---|
949f388f | 1 | /** @file\r |
2 | This driver parses the mSmbiosMiscDataTable structure and reports\r | |
3 | any generated data.\r | |
4 | \r | |
2bfd90f9 | 5 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r |
949f388f | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "MiscSubClassDriver.h"\r | |
17 | /*++\r | |
18 | Check whether the language is supported for given HII handle\r | |
19 | \r | |
20 | @param HiiHandle The HII package list handle.\r | |
21 | @param Offset The offest of current lanague in the supported languages.\r | |
22 | @param CurrentLang The language code.\r | |
23 | \r | |
24 | @retval TRUE Supported.\r | |
25 | @retval FALSE Not Supported.\r | |
26 | \r | |
27 | **/\r | |
28 | VOID\r | |
29 | EFIAPI\r | |
30 | CurrentLanguageMatch (\r | |
31 | IN EFI_HII_HANDLE HiiHandle,\r | |
32 | OUT UINT16 *Offset,\r | |
33 | OUT CHAR8 *CurrentLang\r | |
34 | )\r | |
35 | {\r | |
36 | CHAR8 *DefaultLang;\r | |
37 | CHAR8 *BestLanguage;\r | |
38 | CHAR8 *Languages;\r | |
39 | CHAR8 *MatchLang;\r | |
40 | CHAR8 *EndMatchLang;\r | |
41 | UINTN CompareLength;\r | |
d18d8a1d | 42 | \r |
949f388f | 43 | Languages = HiiGetSupportedLanguages (HiiHandle);\r |
44 | if (Languages == NULL) {\r | |
45 | return;\r | |
46 | }\r | |
47 | \r | |
48 | CurrentLang = GetEfiGlobalVariable (L"PlatformLang");\r | |
49 | DefaultLang = (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang);\r | |
50 | BestLanguage = GetBestLanguage (\r | |
51 | Languages,\r | |
52 | FALSE,\r | |
53 | (CurrentLang != NULL) ? CurrentLang : "",\r | |
54 | DefaultLang,\r | |
55 | NULL\r | |
56 | );\r | |
57 | if (BestLanguage != NULL) {\r | |
58 | //\r | |
59 | // Find the best matching RFC 4646 language, compute the offset.\r | |
60 | //\r | |
61 | CompareLength = AsciiStrLen (BestLanguage);\r | |
62 | for (MatchLang = Languages, (*Offset) = 0; MatchLang != '\0'; (*Offset)++) {\r | |
63 | //\r | |
d18d8a1d | 64 | // Seek to the end of current match language.\r |
949f388f | 65 | //\r |
66 | for (EndMatchLang = MatchLang; *EndMatchLang != '\0' && *EndMatchLang != ';'; EndMatchLang++);\r | |
d18d8a1d | 67 | \r |
949f388f | 68 | if ((EndMatchLang == MatchLang + CompareLength) && AsciiStrnCmp(MatchLang, BestLanguage, CompareLength) == 0) {\r |
69 | //\r | |
70 | // Find the current best Language in the supported languages\r | |
71 | //\r | |
72 | break;\r | |
73 | }\r | |
74 | //\r | |
75 | // best language match be in the supported language.\r | |
76 | //\r | |
77 | ASSERT (*EndMatchLang == ';');\r | |
78 | MatchLang = EndMatchLang + 1;\r | |
79 | }\r | |
80 | FreePool (BestLanguage);\r | |
81 | }\r | |
82 | \r | |
83 | FreePool (Languages);\r | |
84 | if (CurrentLang != NULL) {\r | |
85 | FreePool (CurrentLang);\r | |
86 | }\r | |
87 | return ;\r | |
88 | }\r | |
89 | \r | |
90 | \r | |
91 | /**\r | |
92 | Get next language from language code list (with separator ';').\r | |
93 | \r | |
94 | @param LangCode Input: point to first language in the list. On\r | |
95 | Otput: point to next language in the list, or\r | |
96 | NULL if no more language in the list.\r | |
97 | @param Lang The first language in the list.\r | |
98 | \r | |
99 | **/\r | |
100 | VOID\r | |
101 | EFIAPI\r | |
102 | GetNextLanguage (\r | |
103 | IN OUT CHAR8 **LangCode,\r | |
104 | OUT CHAR8 *Lang\r | |
105 | )\r | |
106 | {\r | |
107 | UINTN Index;\r | |
108 | CHAR8 *StringPtr;\r | |
109 | \r | |
110 | ASSERT (LangCode != NULL);\r | |
111 | ASSERT (*LangCode != NULL);\r | |
112 | ASSERT (Lang != NULL);\r | |
113 | \r | |
114 | Index = 0;\r | |
115 | StringPtr = *LangCode;\r | |
116 | while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {\r | |
117 | Index++;\r | |
118 | }\r | |
119 | \r | |
120 | CopyMem (Lang, StringPtr, Index);\r | |
121 | Lang[Index] = 0;\r | |
122 | \r | |
123 | if (StringPtr[Index] == ';') {\r | |
124 | Index++;\r | |
125 | }\r | |
126 | *LangCode = StringPtr + Index;\r | |
127 | }\r | |
128 | \r | |
129 | /**\r | |
130 | This function returns the number of supported languages on HiiHandle.\r | |
131 | \r | |
132 | @param HiiHandle The HII package list handle.\r | |
133 | \r | |
134 | @retval The number of supported languages.\r | |
135 | \r | |
136 | **/\r | |
137 | UINT16\r | |
138 | EFIAPI\r | |
139 | GetSupportedLanguageNumber (\r | |
140 | IN EFI_HII_HANDLE HiiHandle\r | |
141 | )\r | |
142 | {\r | |
143 | CHAR8 *Lang;\r | |
144 | CHAR8 *Languages;\r | |
145 | CHAR8 *LanguageString;\r | |
146 | UINT16 LangNumber;\r | |
d18d8a1d | 147 | \r |
949f388f | 148 | Languages = HiiGetSupportedLanguages (HiiHandle);\r |
149 | if (Languages == NULL) {\r | |
150 | return 0;\r | |
151 | }\r | |
152 | \r | |
153 | LangNumber = 0;\r | |
154 | Lang = AllocatePool (AsciiStrSize (Languages));\r | |
155 | if (Lang != NULL) {\r | |
156 | LanguageString = Languages;\r | |
157 | while (*LanguageString != 0) {\r | |
158 | GetNextLanguage (&LanguageString, Lang);\r | |
159 | LangNumber++;\r | |
160 | }\r | |
161 | FreePool (Lang);\r | |
162 | }\r | |
163 | FreePool (Languages);\r | |
164 | return LangNumber;\r | |
165 | }\r | |
166 | \r | |
167 | \r | |
168 | /**\r | |
169 | This function makes boot time changes to the contents of the\r | |
170 | MiscNumberOfInstallableLanguages (Type 13).\r | |
171 | \r | |
172 | @param RecordData Pointer to copy of RecordData from the Data Table.\r | |
173 | \r | |
174 | @retval EFI_SUCCESS All parameters were valid.\r | |
175 | @retval EFI_UNSUPPORTED Unexpected RecordType value.\r | |
176 | @retval EFI_INVALID_PARAMETER Invalid parameter was found.\r | |
177 | \r | |
178 | **/\r | |
179 | MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages)\r | |
180 | {\r | |
181 | UINTN LangStrLen;\r | |
182 | CHAR8 CurrentLang[SMBIOS_STRING_MAX_LENGTH + 1];\r | |
183 | CHAR8 *OptionalStrStart;\r | |
184 | UINT16 Offset;\r | |
185 | EFI_STATUS Status;\r | |
186 | EFI_SMBIOS_HANDLE SmbiosHandle;\r | |
187 | SMBIOS_TABLE_TYPE13 *SmbiosRecord;\r | |
188 | EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES *ForType13InputData;\r | |
d18d8a1d | 189 | \r |
949f388f | 190 | ForType13InputData = (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES *)RecordData;\r |
191 | \r | |
192 | //\r | |
193 | // First check for invalid parameters.\r | |
194 | //\r | |
195 | if (RecordData == NULL) {\r | |
196 | return EFI_INVALID_PARAMETER;\r | |
197 | }\r | |
d18d8a1d | 198 | \r |
949f388f | 199 | ForType13InputData->NumberOfInstallableLanguages = GetSupportedLanguageNumber (mHiiHandle);\r |
200 | \r | |
201 | //\r | |
202 | // Try to check if current langcode matches with the langcodes in installed languages\r | |
203 | //\r | |
204 | ZeroMem(CurrentLang, SMBIOS_STRING_MAX_LENGTH + 1);\r | |
205 | CurrentLanguageMatch (mHiiHandle, &Offset, CurrentLang);\r | |
206 | LangStrLen = AsciiStrLen(CurrentLang);\r | |
207 | \r | |
208 | //\r | |
209 | // Two zeros following the last string.\r | |
210 | //\r | |
211 | SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);\r | |
212 | ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);\r | |
213 | \r | |
214 | SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION;\r | |
215 | SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE13);\r | |
216 | //\r | |
217 | // Make handle chosen by smbios protocol.add automatically.\r | |
218 | //\r | |
d18d8a1d | 219 | SmbiosRecord->Hdr.Handle = 0;\r |
949f388f | 220 | \r |
221 | SmbiosRecord->InstallableLanguages = (UINT8)ForType13InputData->NumberOfInstallableLanguages;\r | |
222 | SmbiosRecord->Flags = (UINT8)ForType13InputData->LanguageFlags.AbbreviatedLanguageFormat;\r | |
223 | SmbiosRecord->CurrentLanguages = 1;\r | |
224 | OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r | |
225 | AsciiStrCpy(OptionalStrStart, CurrentLang);\r | |
226 | //\r | |
227 | // Now we have got the full smbios record, call smbios protocol to add this record.\r | |
228 | //\r | |
2bfd90f9 SZ |
229 | Status = AddSmbiosRecord (Smbios, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord);\r |
230 | \r | |
949f388f | 231 | FreePool(SmbiosRecord);\r |
232 | return Status;\r | |
233 | }\r |