Skip to content

Commit cc571b4

Browse files
committed
Add original and selected versions in 'smbios_decode' output
1 parent 162fc8a commit cc571b4

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

smbios_decode.c

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,34 @@ static void hexdump( FILE *output, const uint8_t *buffer, size_t size )
9797

9898
bool printSMBIOS( struct ParserContext *parser, FILE *output )
9999
{
100-
int version;
101-
if (smbios_get_version(parser, &version, NULL) != SMBERR_OK)
100+
int sversion, oversion;
101+
if (smbios_get_version(parser, &sversion, &oversion) != SMBERR_OK)
102102
return false;
103103

104-
fprintf(output, "SMBIOS version %d.%d\n", version >> 8, version & 0xFF);
104+
fprintf(output, "Selected version: %d.%d\n", sversion >> 8, sversion & 0xFF);
105+
fprintf(output, " SMBIOS version: %d.%d\n", oversion >> 8, oversion & 0xFF);
105106

106107
const struct Entry *entry = NULL;
108+
int result = 0;
107109
while (true)
108110
{
109-
if (smbios_next(parser, &entry) != SMBERR_OK)
111+
result = smbios_next(parser, &entry);
112+
if (result != SMBERR_OK)
110113
break;
111114

112115
fprintf(output, "Handle 0x%04X, DMI type %d, %d bytes\n", (int) entry->handle, (int) entry->type, (int) entry->length);
113116

114117
if (entry->type == TYPE_BIOS_INFO)
115118
{
116-
if (version >= SMBIOS_2_0)
119+
if (sversion >= SMBIOS_2_0)
117120
{
118121
fprintf(output, "\tVendor: %s\n", entry->data.bios_info.Vendor);
119122
fprintf(output, "\tBIOSVersion: %s\n", entry->data.bios_info.BIOSVersion);
120123
fprintf(output, "\tBIOSStartingSegment: %X\n", (int) entry->data.bios_info.BIOSStartingAddressSegment);
121124
fprintf(output, "\tBIOSReleaseDate: %s\n", entry->data.bios_info.BIOSReleaseDate);
122125
fprintf(output, "\tBIOSROMSize: %d KiB\n", ((int) entry->data.bios_info.BIOSROMSize + 1) * 64);
123126
}
124-
if (version >= SMBIOS_2_4)
127+
if (sversion >= SMBIOS_2_4)
125128
{
126129
fprintf(output, "\tSystemBIOSMajorRelease: %d\n", (int) entry->data.bios_info.SystemBIOSMajorRelease);
127130
fprintf(output, "\tSystemBIOSMinorRelease: %d\n", (int) entry->data.bios_info.SystemBIOSMinorRelease);
@@ -133,21 +136,21 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
133136
else
134137
if (entry->type == TYPE_SYSTEM_INFO)
135138
{
136-
if (version >= SMBIOS_2_0)
139+
if (sversion >= SMBIOS_2_0)
137140
{
138141
fprintf(output, "\tManufacturer: %s\n", entry->data.system_info.Manufacturer);
139142
fprintf(output, "\tProductName: %s\n", entry->data.system_info.ProductName);
140143
fprintf(output, "\tVersion: %s\n", entry->data.system_info.Version);
141144
fprintf(output, "\tSerialNumber: %s\n", entry->data.system_info.SerialNumber);
142145
}
143-
if (version >= SMBIOS_2_1)
146+
if (sversion >= SMBIOS_2_1)
144147
{
145148
fputs("\tUUID:", output);
146149
for (int i = 0; i < 16; ++i)
147150
fprintf(output, " %02X", entry->data.system_info.UUID[i]);
148151
fputs("\n", output);
149152
}
150-
if (version >= SMBIOS_2_4)
153+
if (sversion >= SMBIOS_2_4)
151154
{
152155
fprintf(output, "\tSKUNumber: %s\n", entry->data.system_info.SKUNumber);
153156
fprintf(output, "\tFamily: %s\n", entry->data.system_info.Family);
@@ -157,7 +160,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
157160
else
158161
if (entry->type == TYPE_BASEBOARD_INFO)
159162
{
160-
if (version >= SMBIOS_2_0)
163+
if (sversion >= SMBIOS_2_0)
161164
{
162165
fprintf(output, "\tManufacturer: %s\n", entry->data.baseboard_info.Manufacturer);
163166
fprintf(output, "\tProduct Name: %s\n", entry->data.baseboard_info.Product);
@@ -173,19 +176,19 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
173176
else
174177
if (entry->type == TYPE_SYSTEM_ENCLOSURE)
175178
{
176-
if (version >= SMBIOS_2_0)
179+
if (sversion >= SMBIOS_2_0)
177180
{
178181
fprintf(output, "\tManufacturer: %s\n", entry->data.system_enclosure.Manufacturer);
179182
fprintf(output, "\tVersion: %s\n", entry->data.system_enclosure.Version);
180183
fprintf(output, "\tSerialNumber: %s\n", entry->data.system_enclosure.SerialNumber);
181184
fprintf(output, "\tAssetTag: %s\n", entry->data.system_enclosure.AssetTag);
182185
}
183-
if (version >= SMBIOS_2_3)
186+
if (sversion >= SMBIOS_2_3)
184187
{
185188
fprintf(output, "\tContainedCount: %d\n", (int) entry->data.system_enclosure.ContainedElementCount);
186189
fprintf(output, "\tContainedLength: %d\n", (int) entry->data.system_enclosure.ContainedElementRecordLength);
187190
}
188-
if (version >= SMBIOS_2_7)
191+
if (sversion >= SMBIOS_2_7)
189192
{
190193
fprintf(output, "\tSKUNumber: %s\n", entry->data.system_enclosure.SKUNumber);
191194
}
@@ -194,7 +197,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
194197
else
195198
if (entry->type == TYPE_PROCESSOR_INFO)
196199
{
197-
if (version >= SMBIOS_2_0)
200+
if (sversion >= SMBIOS_2_0)
198201
{
199202
fprintf(output, "\tSocketDesignation: %s\n", entry->data.processor_info.SocketDesignation);
200203
fprintf(output, "\tProcessorType: %d\n", (int) entry->data.processor_info.ProcessorType);
@@ -212,29 +215,29 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
212215
fprintf(output, "\tStatus: %d\n", entry->data.processor_info.Status);
213216
fprintf(output, "\tProcessorUpgrade: %d\n", entry->data.processor_info.ProcessorUpgrade);
214217
}
215-
if (version >= SMBIOS_2_1)
218+
if (sversion >= SMBIOS_2_1)
216219
{
217220
fprintf(output, "\tL1CacheHandle: %d\n", entry->data.processor_info.L1CacheHandle);
218221
fprintf(output, "\tL2CacheHandle: %d\n", entry->data.processor_info.L2CacheHandle);
219222
fprintf(output, "\tL3CacheHandle: %d\n", entry->data.processor_info.L3CacheHandle);
220223
}
221-
if (version >= SMBIOS_2_3)
224+
if (sversion >= SMBIOS_2_3)
222225
{
223226
fprintf(output, "\tSerialNumber: %s\n", entry->data.processor_info.SerialNumber);
224227
fprintf(output, "\tAssetTagNumber: %s\n", entry->data.processor_info.AssetTagNumber);
225228
fprintf(output, "\tPartNumber: %s\n", entry->data.processor_info.PartNumber);
226229
}
227-
if (version >= SMBIOS_2_3)
230+
if (sversion >= SMBIOS_2_3)
228231
{
229232
fprintf(output, "\tSerialNumber: %s\n", entry->data.processor_info.SerialNumber);
230233
fprintf(output, "\tAssetTagNumber: %s\n", entry->data.processor_info.AssetTagNumber);
231234
fprintf(output, "\tPartNumber: %s\n", entry->data.processor_info.PartNumber);
232235
}
233-
if (version >= SMBIOS_2_6)
236+
if (sversion >= SMBIOS_2_6)
234237
{
235238
fprintf(output, "\tProcessorFamily2: %d\n", entry->data.processor_info.ProcessorFamily2);
236239
}
237-
if (version >= SMBIOS_3_0)
240+
if (sversion >= SMBIOS_3_0)
238241
{
239242
fprintf(output, "\tCoreCount2: %d\n", entry->data.processor_info.CoreCount2);
240243
fprintf(output, "\tCoreEnabled2: %d\n", entry->data.processor_info.CoreEnabled2);
@@ -245,14 +248,14 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
245248
else
246249
if (entry->type == TYPE_SYSTEM_SLOT)
247250
{
248-
if (version >= SMBIOS_2_0)
251+
if (sversion >= SMBIOS_2_0)
249252
{
250253
fprintf(output, "\tSlotDesignation: %s\n", entry->data.system_slot.SlotDesignation);
251254
fprintf(output, "\tSlotType: %d\n", (int) entry->data.system_slot.SlotType);
252255
fprintf(output, "\tSlotDataBusWidth: %d\n", (int) entry->data.system_slot.SlotDataBusWidth);
253256
fprintf(output, "\tSlotID: %d\n", (int) entry->data.system_slot.SlotID);
254257
}
255-
if (version >= SMBIOS_2_6)
258+
if (sversion >= SMBIOS_2_6)
256259
{
257260
fprintf(output, "\tSegmentGroupNumber: %d\n", entry->data.system_slot.SegmentGroupNumber);
258261
fprintf(output, "\tBusNumber: %d\n", (int) entry->data.system_slot.BusNumber);
@@ -262,7 +265,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
262265
else
263266
if (entry->type == TYPE_PHYSICAL_MEMORY_ARRAY)
264267
{
265-
if (version >= SMBIOS_2_1)
268+
if (sversion >= SMBIOS_2_1)
266269
{
267270
fprintf(output, "\tUse: %d\n", (int) entry->data.physical_memory_array.Use);
268271
fprintf(output, "\tNumberDevices: %d\n", entry->data.physical_memory_array.NumberDevices);
@@ -274,12 +277,12 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
274277
else
275278
if (entry->type == TYPE_MEMORY_DEVICE)
276279
{
277-
if (version >= SMBIOS_2_1)
280+
if (sversion >= SMBIOS_2_1)
278281
{
279282
fprintf(output, "\tDeviceLocator: %s\n", entry->data.memory_device.DeviceLocator);
280283
fprintf(output, "\tBankLocator: %s\n", entry->data.memory_device.BankLocator);
281284
}
282-
if (version >= SMBIOS_2_3)
285+
if (sversion >= SMBIOS_2_3)
283286
{
284287
fprintf(output, "\tSpeed: %d MHz\n", entry->data.memory_device.Speed);
285288
fprintf(output, "\tManufacturer: %s\n", entry->data.memory_device.Manufacturer);
@@ -289,7 +292,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
289292
fprintf(output, "\tSize: %d MiB\n", entry->data.memory_device.Size);
290293
fprintf(output, "\tExtendedSize: %d MiB\n", entry->data.memory_device.ExtendedSize);
291294
}
292-
if (version >= SMBIOS_2_7)
295+
if (sversion >= SMBIOS_2_7)
293296
{
294297
fprintf(output, "\tConfiguredClockSpeed: %d\n", entry->data.memory_device.ConfiguredClockSpeed);
295298
}
@@ -298,7 +301,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
298301
else
299302
if (entry->type == TYPE_OEM_STRINGS)
300303
{
301-
if (version >= SMBIOS_2_0)
304+
if (sversion >= SMBIOS_2_0)
302305
{
303306
fprintf(output, "Count: %d\n", (int) entry->data.oem_strings.Count);
304307
fputs("\tStrings:\n", output);
@@ -310,7 +313,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
310313
else
311314
if (entry->type == TYPE_PORT_CONNECTOR)
312315
{
313-
if (version >= SMBIOS_2_0)
316+
if (sversion >= SMBIOS_2_0)
314317
{
315318
fprintf(output, "\tInternalReferenceDesignator: %s\n", entry->data.port_connector.InternalReferenceDesignator);
316319
fprintf(output, "\tInternalConnectorType: %d\n", (int) entry->data.port_connector.InternalConnectorType);
@@ -323,14 +326,14 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
323326
else
324327
if (entry->type == TYPE_MEMORY_ARRAY_MAPPED_ADDRESS)
325328
{
326-
if (version >= SMBIOS_2_1)
329+
if (sversion >= SMBIOS_2_1)
327330
{
328331
fprintf(output, "\tStartingAddress: %0X\n", entry->data.memory_array_mapped_address.StartingAddress);
329332
fprintf(output, "\tEndingAddress: %0X\n", entry->data.memory_array_mapped_address.EndingAddress);
330333
fprintf(output, "\tMemoryArrayHandle: %0X\n", entry->data.memory_array_mapped_address.MemoryArrayHandle);
331334
fprintf(output, "\tPartitionWidth: %0X\n", (int) entry->data.memory_array_mapped_address.PartitionWidth);
332335
}
333-
if (version >= SMBIOS_2_7)
336+
if (sversion >= SMBIOS_2_7)
334337
{
335338
fprintf(output, "\tExtendedStartingAddress: %lX\n", entry->data.memory_array_mapped_address.ExtendedStartingAddress);
336339
fprintf(output, "\tExtendedEndingAddress: %lX\n", entry->data.memory_array_mapped_address.ExtendedEndingAddress);
@@ -340,7 +343,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
340343
else
341344
if (entry->type == TYPE_MEMORY_DEVICE_MAPPED_ADDRESS)
342345
{
343-
if (version >= SMBIOS_2_1)
346+
if (sversion >= SMBIOS_2_1)
344347
{
345348
fprintf(output, "\tStartingAddress: %d\n", entry->data.memory_device_mapped_address.StartingAddress);
346349
fprintf(output, "\tEndingAddress: %d\n", entry->data.memory_device_mapped_address.EndingAddress);
@@ -350,7 +353,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
350353
fprintf(output, "\tInterleavePosition: %d\n", (int) entry->data.memory_device_mapped_address.InterleavePosition);
351354
fprintf(output, "\tInterleavedDataDepth: %d\n", (int) entry->data.memory_device_mapped_address.InterleavedDataDepth);
352355
}
353-
if (version >= SMBIOS_2_7)
356+
if (sversion >= SMBIOS_2_7)
354357
{
355358
fprintf(output, "\tExtendedStartingAddress: %ld\n", entry->data.memory_device_mapped_address.ExtendedStartingAddress);
356359
fprintf(output, "\tExtendedEndingAddress: %ld\n", entry->data.memory_device_mapped_address.ExtendedEndingAddress);
@@ -360,7 +363,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
360363
else
361364
if (entry->type == TYPE_MANAGEMENT_DEVICE)
362365
{
363-
if (version >= SMBIOS_2_0)
366+
if (sversion >= SMBIOS_2_0)
364367
{
365368
fprintf(output, "\tDescription: %s\n", entry->data.management_device.Description);
366369
fprintf(output, "\tType: %d\n", (int) entry->data.management_device.Type);
@@ -372,7 +375,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
372375
else
373376
if (entry->type == TYPE_MANAGEMENT_DEVICE_COMPONENT)
374377
{
375-
if (version >= SMBIOS_2_0)
378+
if (sversion >= SMBIOS_2_0)
376379
{
377380
fprintf(output, "\tDescription: %s\n", entry->data.management_device_component.Description);
378381
fprintf(output, "\tManagementDeviceHandle: %d\n", (int) entry->data.management_device_component.ManagementDeviceHandle);
@@ -384,7 +387,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
384387
else
385388
if (entry->type == TYPE_MANAGEMENT_DEVICE_THRESHOLD_DATA)
386389
{
387-
if (version >= SMBIOS_2_0)
390+
if (sversion >= SMBIOS_2_0)
388391
{
389392
fprintf(output, "\tLowerThresholdNonCritical: %d\n", entry->data.management_device_threshold_data.LowerThresholdNonCritical);
390393
fprintf(output, "\tUpperThresholdNonCritical: %d\n", entry->data.management_device_threshold_data.UpperThresholdNonCritical);
@@ -398,7 +401,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
398401
else
399402
if (entry->type == TYPE_ONBOARD_DEVICES_EXTENDED_INFO)
400403
{
401-
if (version >= SMBIOS_2_0)
404+
if (sversion >= SMBIOS_2_0)
402405
{
403406
fprintf(output, "\tReferenceDesignation: %s\n", entry->data.onboard_devices_extended_info.ReferenceDesignation);
404407
fprintf(output, "\tDeviceType: %d\n", (int) entry->data.onboard_devices_extended_info.DeviceType);
@@ -412,7 +415,7 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
412415
else
413416
if (entry->type == TYPE_SYSTEM_BOOT_INFO)
414417
{
415-
if (version >= SMBIOS_2_0)
418+
if (sversion >= SMBIOS_2_0)
416419
{
417420
fprintf(output, "\tBootStatus:\n\t\t");
418421
if ((entry->length - 10) > 0)
@@ -452,6 +455,11 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
452455
}
453456
}
454457

458+
if (result != SMBERR_END_OF_STREAM)
459+
{
460+
fputs("Invalid SMBIOS data", output);
461+
}
462+
455463
return true;
456464
}
457465

0 commit comments

Comments
 (0)