• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
4 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
5 Copyright (c) 2015, Linaro Limited. 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
10 
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.
13 
14 Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
15 **/
16 
17 /* Modify list
18 DATA        AUTHOR            REASON
19 */
20 
21 #include "SmbiosMisc.h"
22 
23 /**
24   Get next language from language code list (with separator ';').
25 
26   @param  LangCode       Input: point to first language in the list. On
27                          Otput: point to next language in the list, or
28                                 NULL if no more language in the list.
29   @param  Lang           The first language in the list.
30 
31 **/
32 VOID
33 EFIAPI
GetNextLanguage(IN OUT CHAR8 ** LangCode,OUT CHAR8 * Lang)34 GetNextLanguage (
35   IN OUT CHAR8      **LangCode,
36   OUT CHAR8         *Lang
37   )
38 {
39   UINTN  Index;
40   CHAR8  *StringPtr;
41 
42   if(NULL == LangCode || NULL == *LangCode || NULL == Lang) {
43     return;
44   }
45 
46   Index     = 0;
47   StringPtr = *LangCode;
48   while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {
49     Index++;
50   }
51 
52   (VOID)CopyMem(Lang, StringPtr, Index);
53   Lang[Index] = 0;
54 
55   if (StringPtr[Index] == ';') {
56     Index++;
57   }
58   *LangCode = StringPtr + Index;
59 }
60 
61 /**
62   This function returns the number of supported languages on HiiHandle.
63 
64   @param   HiiHandle    The HII package list handle.
65 
66   @retval  The number of supported languages.
67 
68 **/
69 UINT16
70 EFIAPI
GetSupportedLanguageNumber(IN EFI_HII_HANDLE HiiHandle)71 GetSupportedLanguageNumber (
72   IN EFI_HII_HANDLE    HiiHandle
73   )
74 {
75   CHAR8   *Lang;
76   CHAR8   *Languages;
77   CHAR8   *LanguageString;
78   UINT16  LangNumber;
79 
80   Languages = HiiGetSupportedLanguages (HiiHandle);
81   if (Languages == NULL) {
82     return 0;
83   }
84 
85   LangNumber = 0;
86   Lang = AllocatePool (AsciiStrSize (Languages));
87   if (Lang != NULL) {
88     LanguageString = Languages;
89     while (*LanguageString != 0) {
90       GetNextLanguage (&LanguageString, Lang);
91       LangNumber++;
92     }
93     FreePool (Lang);
94   }
95   FreePool (Languages);
96   return LangNumber;
97 }
98 
99 
100 /**
101   This function makes boot time changes to the contents of the
102   MiscNumberOfInstallableLanguages (Type 13).
103 
104   @param  RecordData                 Pointer to copy of RecordData from the Data Table.
105 
106   @retval EFI_SUCCESS                All parameters were valid.
107   @retval EFI_UNSUPPORTED            Unexpected RecordType value.
108   @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
109 
110 **/
MISC_SMBIOS_TABLE_FUNCTION(MiscNumberOfInstallableLanguages)111 MISC_SMBIOS_TABLE_FUNCTION(MiscNumberOfInstallableLanguages)
112 {
113   UINTN                                     LangStrLen;
114   CHAR8                                     CurrentLang[SMBIOS_STRING_MAX_LENGTH + 1];
115   CHAR8                                     *OptionalStrStart;
116   EFI_STATUS                                Status;
117   EFI_SMBIOS_HANDLE                         SmbiosHandle;
118   SMBIOS_TABLE_TYPE13                       *SmbiosRecord;
119   SMBIOS_TABLE_TYPE13                       *InputData = NULL;;
120 
121   //
122   // First check for invalid parameters.
123   //
124   if (RecordData == NULL) {
125     return EFI_INVALID_PARAMETER;
126   }
127 
128   InputData = (SMBIOS_TABLE_TYPE13 *)RecordData;
129 
130   InputData->InstallableLanguages = GetSupportedLanguageNumber (mHiiHandle);
131 
132   //
133   // Try to check if current langcode matches with the langcodes in installed languages
134   //
135   ZeroMem(CurrentLang, SMBIOS_STRING_MAX_LENGTH - 1);
136   (VOID)AsciiStrCpyS(CurrentLang, SMBIOS_STRING_MAX_LENGTH - 1, "en|US|iso8859-1");
137   LangStrLen = AsciiStrLen(CurrentLang);
138 
139   //
140   // Two zeros following the last string.
141   //
142   SmbiosRecord = AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);
143   if(NULL == SmbiosRecord) {
144     return EFI_OUT_OF_RESOURCES;
145   }
146 
147   (VOID)CopyMem(SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE13));
148 
149   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE13);
150 
151   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
152   (VOID)AsciiStrCpyS(OptionalStrStart, SMBIOS_STRING_MAX_LENGTH - 1, CurrentLang);
153   //
154   // Now we have got the full smbios record, call smbios protocol to add this record.
155   //
156   Status = LogSmbiosData((UINT8*)SmbiosRecord, &SmbiosHandle);
157   if(EFI_ERROR(Status)) {
158     DEBUG((EFI_D_ERROR, "[%a]:[%dL] Smbios Type13 Table Log Failed! %r \n", __FUNCTION__, __LINE__, Status));
159   }
160 
161   FreePool(SmbiosRecord);
162   return Status;
163 }
164