TianoCore EDK2 master
Loading...
Searching...
No Matches
MiscNumberOfInstallableLanguagesFunction.c
Go to the documentation of this file.
1
12#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15#include <Library/HiiLib.h>
17#include <Library/OemMiscLib.h>
18#include <Library/PrintLib.h>
20
21#include "SmbiosMisc.h"
22
32VOID
33EFIAPI
35 IN OUT CHAR8 **LangCode,
36 OUT CHAR8 *Lang
37 )
38{
39 UINTN Index;
40 CHAR8 *StringPtr;
41
42 if ((LangCode == NULL) || (*LangCode == NULL) || (Lang == NULL)) {
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
59 *LangCode = StringPtr + Index;
60}
61
70UINT16
71EFIAPI
73 IN EFI_HII_HANDLE HiiHandle
74 )
75{
76 CHAR8 *Lang;
77 CHAR8 *Languages;
78 CHAR8 *LanguageString;
79 UINT16 LangNumber;
80
81 Languages = HiiGetSupportedLanguages (HiiHandle);
82 if (Languages == NULL) {
83 return 0;
84 }
85
86 LangNumber = 0;
87 Lang = AllocatePool (AsciiStrSize (Languages));
88 if (Lang != NULL) {
89 LanguageString = Languages;
90 while (*LanguageString != 0) {
91 GetNextLanguage (&LanguageString, Lang);
92 LangNumber++;
93 }
94
95 FreePool (Lang);
96 }
97
98 FreePool (Languages);
99 return LangNumber;
100}
101
114SMBIOS_MISC_TABLE_FUNCTION (MiscNumberOfInstallableLanguages) {
115 UINTN LangStrLen;
116 CHAR8 CurrentLang[SMBIOS_STRING_MAX_LENGTH + 1];
117 CHAR8 *OptionalStrStart;
118 EFI_STATUS Status;
119 SMBIOS_TABLE_TYPE13 *SmbiosRecord;
120 SMBIOS_TABLE_TYPE13 *InputData;
121
122 InputData = NULL;
123
124 //
125 // First check for invalid parameters.
126 //
127 if (RecordData == NULL) {
128 return EFI_INVALID_PARAMETER;
129 }
130
131 InputData = (SMBIOS_TABLE_TYPE13 *)RecordData;
132
133 InputData->InstallableLanguages = GetSupportedLanguageNumber (mSmbiosMiscHiiHandle);
134
135 //
136 // Try to check if current langcode matches with the langcodes in installed languages
137 //
138 ZeroMem (CurrentLang, SMBIOS_STRING_MAX_LENGTH - 1);
139 (VOID)AsciiStrCpyS (CurrentLang, SMBIOS_STRING_MAX_LENGTH - 1, "en|US|iso8859-1");
140 LangStrLen = AsciiStrLen (CurrentLang);
141
142 //
143 // Two zeros following the last string.
144 //
145 SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);
146 if (SmbiosRecord == NULL) {
147 return EFI_OUT_OF_RESOURCES;
148 }
149
150 (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE13));
151
152 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE13);
153
154 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
155 (VOID)AsciiStrCpyS (OptionalStrStart, SMBIOS_STRING_MAX_LENGTH - 1, CurrentLang);
156 //
157 // Now we have got the full smbios record, call smbios protocol to add this record.
158 //
159 Status = SmbiosMiscAddRecord ((UINT8 *)SmbiosRecord, NULL);
160 if (EFI_ERROR (Status)) {
161 DEBUG ((
162 DEBUG_ERROR,
163 "[%a]:[%dL] Smbios Type13 Table Log Failed! %r \n",
164 __func__,
165 DEBUG_LINE_NUMBER,
166 Status
167 ));
168 }
169
170 FreePool (SmbiosRecord);
171 return Status;
172}
UINT64 UINTN
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
Definition: SafeString.c:1797
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
CHAR8 *EFIAPI HiiGetSupportedLanguages(IN EFI_HII_HANDLE HiiHandle)
Definition: HiiLanguage.c:31
#define SMBIOS_STRING_MAX_LENGTH
Definition: SmBios.h:37
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT16 EFIAPI GetSupportedLanguageNumber(IN EFI_HII_HANDLE HiiHandle)
VOID EFIAPI GetNextLanguage(IN OUT CHAR8 **LangCode, OUT CHAR8 *Lang)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS SmbiosMiscAddRecord(IN UINT8 *Buffer, IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle OPTIONAL)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HII_HANDLE