TianoCore EDK2 master
Loading...
Searching...
No Matches
MiscChassisManufacturerFunction.c
Go to the documentation of this file.
1
15#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
18#include <Library/HiiLib.h>
20#include <Library/OemMiscLib.h>
21#include <Library/PrintLib.h>
23
24#include "SmbiosMisc.h"
25
38SMBIOS_MISC_TABLE_FUNCTION (MiscChassisManufacturer) {
39 CHAR8 *OptionalStrStart;
40 CHAR8 *StrStart;
41 UINT8 *SkuNumberField;
42 UINTN RecordLength;
43 UINTN ManuStrLen;
44 UINTN VerStrLen;
45 UINTN AssertTagStrLen;
46 UINTN SerialNumStrLen;
47 UINTN ChaNumStrLen;
48 EFI_STRING Manufacturer;
49 EFI_STRING Version;
50 EFI_STRING SerialNumber;
51 EFI_STRING AssertTag;
52 EFI_STRING ChassisSkuNumber;
53 EFI_STRING_ID TokenToGet;
54 SMBIOS_TABLE_TYPE3 *SmbiosRecord;
55 SMBIOS_TABLE_TYPE3 *InputData;
56 EFI_STATUS Status;
57
58 UINT8 ContainedElementCount;
59 CONTAINED_ELEMENT ContainedElements;
60 UINT8 ExtendLength;
61
62 ExtendLength = 0;
63
64 //
65 // First check for invalid parameters.
66 //
67 if (RecordData == NULL) {
68 return EFI_INVALID_PARAMETER;
69 }
70
71 InputData = (SMBIOS_TABLE_TYPE3 *)RecordData;
72
74 mSmbiosMiscHiiHandle,
75 STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG),
76 AssetTagType03
77 );
79 mSmbiosMiscHiiHandle,
80 STRING_TOKEN (STR_MISC_CHASSIS_SERIAL_NUMBER),
81 SerialNumberType03
82 );
84 mSmbiosMiscHiiHandle,
85 STRING_TOKEN (STR_MISC_CHASSIS_VERSION),
86 VersionType03
87 );
89 mSmbiosMiscHiiHandle,
90 STRING_TOKEN (STR_MISC_CHASSIS_MANUFACTURER),
91 ManufacturerType03
92 );
94 mSmbiosMiscHiiHandle,
95 STRING_TOKEN (STR_MISC_CHASSIS_SKU_NUMBER),
96 SkuNumberType03
97 );
98
99 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_MANUFACTURER);
100 Manufacturer = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
101 ManuStrLen = StrLen (Manufacturer);
102
103 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_VERSION);
104 Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
105 VerStrLen = StrLen (Version);
106
107 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_SERIAL_NUMBER);
108 SerialNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
109 SerialNumStrLen = StrLen (SerialNumber);
110
111 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG);
112 AssertTag = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
113 AssertTagStrLen = StrLen (AssertTag);
114
115 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_SKU_NUMBER);
116 ChassisSkuNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
117 ChaNumStrLen = StrLen (ChassisSkuNumber);
118
119 ContainedElementCount = InputData->ContainedElementCount;
120 ExtendLength = ContainedElementCount * sizeof (CONTAINED_ELEMENT);
121
122 //
123 // Two zeros following the last string.
124 //
125 RecordLength = sizeof (SMBIOS_TABLE_TYPE3) +
126 ExtendLength + 1 +
127 ManuStrLen + 1 +
128 VerStrLen + 1 +
129 SerialNumStrLen + 1 +
130 AssertTagStrLen + 1 +
131 ChaNumStrLen + 1 + 1;
132 SmbiosRecord = AllocateZeroPool (RecordLength);
133 if (SmbiosRecord == NULL) {
134 Status = EFI_OUT_OF_RESOURCES;
135 goto Exit;
136 }
137
138 (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE3));
139
140 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3) + ExtendLength + 1;
141
142 SmbiosRecord->Type = OemGetChassisType ();
143
144 // ContainedElements
145 ASSERT (ContainedElementCount < 2);
146 (VOID)CopyMem (SmbiosRecord + 1, &ContainedElements, ExtendLength);
147
148 // ChassisSkuNumber
149 SkuNumberField = (UINT8 *)SmbiosRecord +
150 sizeof (SMBIOS_TABLE_TYPE3) -
151 sizeof (CONTAINED_ELEMENT) + ExtendLength;
152
153 *SkuNumberField = 5;
154
155 OptionalStrStart = (CHAR8 *)((UINT8 *)SmbiosRecord + sizeof (SMBIOS_TABLE_TYPE3) +
156 ExtendLength + 1);
157 UnicodeStrToAsciiStrS (Manufacturer, OptionalStrStart, ManuStrLen + 1);
158 StrStart = OptionalStrStart + ManuStrLen + 1;
159 UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
160 StrStart += VerStrLen + 1;
161 UnicodeStrToAsciiStrS (SerialNumber, StrStart, SerialNumStrLen + 1);
162 StrStart += SerialNumStrLen + 1;
163 UnicodeStrToAsciiStrS (AssertTag, StrStart, AssertTagStrLen + 1);
164 StrStart += AssertTagStrLen + 1;
165 UnicodeStrToAsciiStrS (ChassisSkuNumber, StrStart, ChaNumStrLen + 1);
166
167 SmbiosRecord->BootupState = OemGetChassisBootupState ();
169 SmbiosRecord->ThermalState = OemGetChassisThermalState ();
171 SmbiosRecord->Height = OemGetChassisHeight ();
172 SmbiosRecord->NumberofPowerCords = OemGetChassisNumPowerCords ();
173
174 //
175 // Now we have got the full smbios record, call smbios protocol to add this record.
176 //
177 Status = SmbiosMiscAddRecord ((UINT8 *)SmbiosRecord, NULL);
178 if (EFI_ERROR (Status)) {
179 DEBUG ((
180 DEBUG_ERROR,
181 "[%a]:[%dL] Smbios Type03 Table Log Failed! %r \n",
182 __func__,
183 DEBUG_LINE_NUMBER,
184 Status
185 ));
186 }
187
188 FreePool (SmbiosRecord);
189
190Exit:
191 if (Manufacturer != NULL) {
192 FreePool (Manufacturer);
193 }
194
195 if (Version != NULL) {
196 FreePool (Version);
197 }
198
199 if (SerialNumber != NULL) {
200 FreePool (SerialNumber);
201 }
202
203 if (AssertTag != NULL) {
204 FreePool (AssertTag);
205 }
206
207 if (ChassisSkuNumber != NULL) {
208 FreePool (ChassisSkuNumber);
209 }
210
211 return 0;
212}
UINT64 UINTN
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2650
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STRING EFIAPI HiiGetPackageString(IN CONST EFI_GUID *PackageListGuid, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:171
#define NULL
Definition: Base.h:319
#define DEBUG(Expression)
Definition: DebugLib.h:434
MISC_CHASSIS_STATE EFIAPI OemGetChassisBootupState(VOID)
Definition: OemMiscLib.c:165
UINT8 EFIAPI OemGetChassisNumPowerCords(VOID)
Definition: OemMiscLib.c:235
VOID EFIAPI OemUpdateSmbiosInfo(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID TokenToUpdate, IN OEM_MISC_SMBIOS_HII_STRING_FIELD Field)
Definition: OemMiscLib.c:136
UINT8 EFIAPI OemGetChassisHeight(VOID)
Definition: OemMiscLib.c:221
MISC_CHASSIS_SECURITY_STATE EFIAPI OemGetChassisSecurityStatus(VOID)
Definition: OemMiscLib.c:207
MISC_CHASSIS_TYPE EFIAPI OemGetChassisType(VOID)
Definition: OemMiscLib.c:104
MISC_CHASSIS_STATE EFIAPI OemGetChassisPowerSupplyState(VOID)
Definition: OemMiscLib.c:179
MISC_CHASSIS_STATE EFIAPI OemGetChassisThermalState(VOID)
Definition: OemMiscLib.c:193
EFI_STATUS SmbiosMiscAddRecord(IN UINT8 *Buffer, IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle OPTIONAL)
VOID EFIAPI Exit(IN EFI_STATUS Status)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define STRING_TOKEN(t)
UINT8 SecurityStatus
The enumeration value from MISC_CHASSIS_SECURITY_STATE.
Definition: SmBios.h:500
UINT8 ThermalState
The enumeration value from MISC_CHASSIS_STATE.
Definition: SmBios.h:499
UINT8 BootupState
The enumeration value from MISC_CHASSIS_STATE.
Definition: SmBios.h:497
UINT8 PowerSupplyState
The enumeration value from MISC_CHASSIS_STATE.
Definition: SmBios.h:498