Adding upstream version 4.00~pre53+dfsg.
[syslinux-debian/hramrach.git] / com32 / gpllib / dmi / dmi.c
blobd333b9ab3c86eaa90079834e6fcb7885772fcae8
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2006 Erwan Velu - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
12 * conditions:
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
29 #include <stdio.h>
30 #include <string.h>
31 #include "dmi/dmi.h"
33 const char *out_of_spec = "<OUT OF SPEC>";
34 const char *bad_index = "<BAD INDEX>";
37 * Misc. util stuff
41 * 3.3.11 On Board Devices Information (Type 10)
44 static const char *dmi_on_board_devices_type(uint8_t code)
46 /* 3.3.11.1 */
47 static const char *type[] = {
48 "Other", /* 0x01 */
49 "Unknown",
50 "Video",
51 "SCSI Controller",
52 "Ethernet",
53 "Token Ring",
54 "Sound",
55 "PATA Controller",
56 "SATA Controller",
57 "SAS Controller" /* 0x0A */
60 if (code >= 0x01 && code <= 0x0A)
61 return type[code - 0x01];
62 return out_of_spec;
65 static void dmi_on_board_devices(struct dmi_header *h, s_dmi * dmi)
67 uint8_t *p = h->data + 4;
68 uint8_t count = (h->length - 0x04) / 2;
69 unsigned int i;
71 for (i = 0;
72 i < count
73 && i <
74 sizeof dmi->base_board.devices_information /
75 sizeof *dmi->base_board.devices_information; i++) {
76 strncpy(dmi->base_board.devices_information[i].type,
77 dmi_on_board_devices_type(p[2 * i] & 0x7F),
78 sizeof dmi->base_board.devices_information[i].type);
79 dmi->base_board.devices_information[i].status = p[2 * i] & 0x80;
80 strncpy(dmi->base_board.devices_information[i].description,
81 dmi_string(h, p[2 * i + 1]),
82 sizeof dmi->base_board.devices_information[i].description);
87 * 3.3.24 System Reset (Type 23)
90 static const char *dmi_system_reset_boot_option(uint8_t code)
92 static const char *option[] = {
93 "Operating System", /* 0x1 */
94 "System Utilities",
95 "Do Not Reboot" /* 0x3 */
98 if (code >= 0x1)
99 return option[code - 0x1];
100 return out_of_spec;
103 static void dmi_system_reset_count(uint16_t code, char *array)
105 if (code == 0xFFFF)
106 strncpy(array, "Unknown", sizeof array);
107 else
108 snprintf(array, sizeof array, "%u", code);
111 static void dmi_system_reset_timer(uint16_t code, char *array)
113 if (code == 0xFFFF)
114 strncpy(array, "Unknown", sizeof array);
115 else
116 snprintf(array, sizeof array, "%u min", code);
120 * 3.3.25 Hardware Security (Type 24)
123 static const char *dmi_hardware_security_status(uint8_t code)
125 static const char *status[] = {
126 "Disabled", /* 0x00 */
127 "Enabled",
128 "Not Implemented",
129 "Unknown" /* 0x03 */
132 return status[code];
136 * 3.3.12 OEM Strings (Type 11)
139 static void dmi_oem_strings(struct dmi_header *h, const char *prefix,
140 s_dmi * dmi)
142 uint8_t *p = h->data + 4;
143 uint8_t count = p[0x00];
144 int i;
146 for (i = 1; i <= count; i++)
147 snprintf(dmi->oem_strings, OEM_STRINGS_SIZE, "%s %s %s\n",
148 dmi->oem_strings, prefix, dmi_string(h, i));
152 * 3.3.13 System Configuration Options (Type 12)
154 static void dmi_system_configuration_options(struct dmi_header *h,
155 const char *prefix, s_dmi * dmi)
157 uint8_t *p = h->data + 4;
158 uint8_t count = p[0x00];
159 int i;
161 for (i = 1; i <= count; i++)
162 snprintf(dmi->system.configuration_options,
163 SYSTEM_CONFIGURATION_OPTIONS_SIZE, "%s %s %s\n",
164 dmi->system.configuration_options, prefix, dmi_string(h, i));
167 static void dmi_system_boot_status(uint8_t code, char *array)
169 static const char *status[] = {
170 "No errors detected", /* 0 */
171 "No bootable media",
172 "Operating system failed to load",
173 "Firmware-detected hardware failure",
174 "Operating system-detected hardware failure",
175 "User-requested boot",
176 "System security violation",
177 "Previously-requested image",
178 "System watchdog timer expired" /* 8 */
181 if (code <= 8)
182 strncpy(array, status[code], SYSTEM_BOOT_STATUS_SIZE);
183 if (code >= 128 && code <= 191)
184 strncpy(array, "OEM-specific", SYSTEM_BOOT_STATUS_SIZE);
185 if (code >= 192)
186 strncpy(array, "Product-specific", SYSTEM_BOOT_STATUS_SIZE);
189 void dmi_bios_runtime_size(uint32_t code, s_dmi * dmi)
191 if (code & 0x000003FF) {
192 dmi->bios.runtime_size = code;
193 strncpy(dmi->bios.runtime_size_unit, "bytes",
194 sizeof(dmi->bios.runtime_size_unit));
195 } else {
196 dmi->bios.runtime_size = code >> 10;
197 strncpy(dmi->bios.runtime_size_unit, "KB",
198 sizeof(dmi->bios.runtime_size_unit));
203 void dmi_bios_characteristics(uint64_t code, s_dmi * dmi)
205 int i;
207 * This isn't very clear what this bit is supposed to mean
209 //if(code.l&(1<<3))
210 if (code && (1 << 3)) {
211 ((bool *) (&dmi->bios.characteristics))[0] = true;
212 return;
215 for (i = 4; i <= 31; i++)
216 //if(code.l&(1<<i))
217 if (code & (1 << i))
218 ((bool *) (&dmi->bios.characteristics))[i - 3] = true;
221 void dmi_bios_characteristics_x1(uint8_t code, s_dmi * dmi)
223 int i;
225 for (i = 0; i <= 7; i++)
226 if (code & (1 << i))
227 ((bool *) (&dmi->bios.characteristics_x1))[i] = true;
230 void dmi_bios_characteristics_x2(uint8_t code, s_dmi * dmi)
232 int i;
234 for (i = 0; i <= 2; i++)
235 if (code & (1 << i))
236 ((bool *) (&dmi->bios.characteristics_x2))[i] = true;
239 void dmi_system_uuid(uint8_t * p, s_dmi * dmi)
241 int only0xFF = 1, only0x00 = 1;
242 int i;
244 for (i = 0; i < 16 && (only0x00 || only0xFF); i++) {
245 if (p[i] != 0x00)
246 only0x00 = 0;
247 if (p[i] != 0xFF)
248 only0xFF = 0;
251 if (only0xFF) {
252 sprintf(dmi->system.uuid, "Not Present");
253 return;
255 if (only0x00) {
256 sprintf(dmi->system.uuid, "Not Settable");
257 return;
260 sprintf(dmi->system.uuid,
261 "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
262 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10],
263 p[11], p[12], p[13], p[14], p[15]);
266 void dmi_system_wake_up_type(uint8_t code, s_dmi * dmi)
268 /* 3.3.2.1 */
269 static const char *type[] = {
270 "Reserved", /* 0x00 */
271 "Other",
272 "Unknown",
273 "APM Timer",
274 "Modem Ring",
275 "LAN Remote",
276 "Power Switch",
277 "PCI PME#",
278 "AC Power Restored" /* 0x08 */
281 if (code <= 0x08) {
282 strncpy(dmi->system.wakeup_type, type[code],
283 sizeof(dmi->system.wakeup_type));
284 } else {
285 strncpy(dmi->system.wakeup_type, out_of_spec,
286 sizeof(dmi->system.wakeup_type));
288 return;
291 static void dmi_base_board_features(uint8_t code, s_dmi * dmi)
293 if ((code & 0x1F) != 0) {
294 int i;
296 for (i = 0; i <= 4; i++)
297 if (code & (1 << i))
298 ((bool *) (&dmi->base_board.features))[i] = true;
302 static void dmi_processor_voltage(uint8_t code, s_dmi * dmi)
304 /* 3.3.5.4 */
305 static const uint16_t voltage[] = {
306 5000,
307 3300,
308 2900
310 int i;
312 if (code & 0x80)
313 dmi->processor.voltage_mv = (code & 0x7f) * 100;
314 else {
315 for (i = 0; i <= 2; i++)
316 if (code & (1 << i))
317 dmi->processor.voltage_mv = voltage[i];
321 static void dmi_processor_id(uint8_t type, uint8_t * p, const char *version,
322 s_dmi * dmi)
325 * Extra flags are now returned in the ECX register when one calls
326 * the CPUID instruction. Their meaning is explained in table 6, but
327 * DMI doesn't support this yet.
329 uint32_t eax, edx;
330 int sig = 0;
333 * This might help learn about new processors supporting the
334 * CPUID instruction or another form of identification.
336 sprintf(dmi->processor.id, "ID: %02X %02X %02X %02X %02X %02X %02X %02X\n",
337 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
339 if (type == 0x05) { /* 80386 */
340 uint16_t dx = WORD(p);
342 * 80386 have a different signature.
344 dmi->processor.signature.type = (dx >> 12);
345 dmi->processor.signature.family = ((dx >> 8) & 0xF);
346 dmi->processor.signature.stepping = (dx >> 4) & 0xF;
347 dmi->processor.signature.minor_stepping = (dx & 0xF);
348 return;
350 if (type == 0x06) { /* 80486 */
351 uint16_t dx = WORD(p);
353 * Not all 80486 CPU support the CPUID instruction, we have to find
354 * wether the one we have here does or not. Note that this trick
355 * works only because we know that 80486 must be little-endian.
357 if ((dx & 0x0F00) == 0x0400
358 && ((dx & 0x00F0) == 0x0040 || (dx & 0x00F0) >= 0x0070)
359 && ((dx & 0x000F) >= 0x0003))
360 sig = 1;
361 else {
362 dmi->processor.signature.type = ((dx >> 12) & 0x3);
363 dmi->processor.signature.family = ((dx >> 8) & 0xF);
364 dmi->processor.signature.model = ((dx >> 4) & 0xF);
365 dmi->processor.signature.stepping = (dx & 0xF);
366 return;
368 } else if ((type >= 0x0B && type <= 0x13) /* Intel, Cyrix */
369 ||(type >= 0xB0 && type <= 0xB3) /* Intel */
370 ||type == 0xB5 /* Intel */
371 || type == 0xB9) /* Intel */
372 sig = 1;
373 else if ((type >= 0x18 && type <= 0x1D) /* AMD */
374 ||type == 0x1F /* AMD */
375 || (type >= 0xB6 && type <= 0xB7) /* AMD */
376 ||(type >= 0x83 && type <= 0x85)) /* AMD */
377 sig = 2;
378 else if (type == 0x01 || type == 0x02) {
380 * Some X86-class CPU have family "Other" or "Unknown". In this case,
381 * we use the version string to determine if they are known to
382 * support the CPUID instruction.
384 if (strncmp(version, "Pentium III MMX", 15) == 0)
385 sig = 1;
386 else if (strncmp(version, "AMD Athlon(TM)", 14) == 0
387 || strncmp(version, "AMD Opteron(tm)", 15) == 0)
388 sig = 2;
389 else
390 return;
391 } else /* not X86-class */
392 return;
394 eax = DWORD(p);
395 edx = DWORD(p + 4);
396 switch (sig) {
397 case 1: /* Intel */
398 dmi->processor.signature.type = ((eax >> 12) & 0x3);
399 dmi->processor.signature.family =
400 (((eax >> 16) & 0xFF0) + ((eax >> 8) & 0x00F));
401 dmi->processor.signature.model =
402 (((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F));
403 dmi->processor.signature.stepping = (eax & 0xF);
404 break;
405 case 2: /* AMD */
406 dmi->processor.signature.family =
407 (((eax >> 8) & 0xF) == 0xF ? (eax >> 20) & 0xFF : (eax >> 8) & 0xF);
408 dmi->processor.signature.model =
409 (((eax >> 4) & 0xF) == 0xF ? (eax >> 16) & 0xF : (eax >> 4) & 0xF);
410 dmi->processor.signature.stepping = (eax & 0xF);
411 break;
414 edx = DWORD(p + 4);
415 if ((edx & 0x3FF7FDFF) != 0) {
416 int i;
417 for (i = 0; i <= 31; i++)
418 if (cpu_flags_strings[i] != NULL && edx & (1 << i))
419 ((bool *) (&dmi->processor.cpu_flags))[i] = true;
423 void to_dmi_header(struct dmi_header *h, uint8_t * data)
425 h->type = data[0];
426 h->length = data[1];
427 h->handle = WORD(data + 2);
428 h->data = data;
431 const char *dmi_string(struct dmi_header *dm, uint8_t s)
433 char *bp = (char *)dm->data;
434 size_t i, len;
436 if (s == 0)
437 return "Not Specified";
439 bp += dm->length;
440 while (s > 1 && *bp) {
441 bp += strlen(bp);
442 bp++;
443 s--;
446 if (!*bp)
447 return bad_index;
449 /* ASCII filtering */
450 len = strlen(bp);
451 for (i = 0; i < len; i++)
452 if (bp[i] < 32 || bp[i] == 127)
453 bp[i] = '.';
455 return bp;
458 int checksum(uint8_t * buf, int len)
460 uint8_t sum = 0;
461 int a;
463 for (a = 0; a < len; a++)
464 sum += buf[a];
465 return (sum == 0);
468 static int smbios_decode(s_dmi * dmi, uint8_t * buf)
471 dmi->dmitable.ver = (buf[0x06] << 8) + buf[0x07];
472 /* Some BIOS report weird SMBIOS version, fix that up */
473 switch (dmi->dmitable.ver) {
474 case 0x021F:
475 dmi->dmitable.ver = 0x0203;
476 break;
477 case 0x0233:
478 dmi->dmitable.ver = 0x0206;
479 break;
481 dmi->dmitable.major_version = dmi->dmitable.ver >> 8;
482 dmi->dmitable.minor_version = dmi->dmitable.ver & 0xFF;
484 return DMI_TABLE_PRESENT;
487 static int legacy_decode(s_dmi * dmi, uint8_t * buf)
489 dmi->dmitable.num = buf[13] << 8 | buf[12];
490 dmi->dmitable.len = buf[7] << 8 | buf[6];
491 dmi->dmitable.base = buf[11] << 24 | buf[10] << 16 | buf[9] << 8 | buf[8];
493 /* Version already found? */
494 if (dmi->dmitable.ver > 0)
495 return DMI_TABLE_PRESENT;
497 dmi->dmitable.ver = (buf[0x06] << 8) + buf[0x07];
500 * DMI version 0.0 means that the real version is taken from
501 * the SMBIOS version, which we don't know at this point.
503 if (buf[14] != 0) {
504 dmi->dmitable.major_version = buf[14] >> 4;
505 dmi->dmitable.minor_version = buf[14] & 0x0F;
506 } else {
507 dmi->dmitable.major_version = 0;
508 dmi->dmitable.minor_version = 0;
510 return DMI_TABLE_PRESENT;
513 int dmi_iterate(s_dmi * dmi)
515 uint8_t *p, *q;
516 int found = 0;
518 /* Cleaning structures */
519 memset(&dmi->base_board, 0, sizeof(s_base_board));
520 memset(&dmi->battery, 0, sizeof(s_battery));
521 memset(&dmi->bios, 0, sizeof(s_bios));
522 memset(&dmi->chassis, 0, sizeof(s_chassis));
523 for (int i = 0; i < MAX_DMI_MEMORY_ITEMS; i++)
524 memset(&dmi->memory[i], 0, sizeof(s_memory));
525 memset(&dmi->processor, 0, sizeof(s_processor));
526 memset(&dmi->system, 0, sizeof(s_system));
528 /* Until we found this elements in the dmitable, we consider them as not filled */
529 dmi->base_board.filled = false;
530 dmi->battery.filled = false;
531 dmi->bios.filled = false;
532 dmi->chassis.filled = false;
533 for (int i = 0; i < MAX_DMI_MEMORY_ITEMS; i++)
534 dmi->memory[i].filled = false;
535 dmi->processor.filled = false;
536 dmi->system.filled = false;
538 p = (uint8_t *) 0xF0000; /* The start address to look at the dmi table */
539 /* The anchor-string is 16-bytes aligned */
540 for (q = p; q < p + 0x10000; q += 16) {
541 /* To validate the presence of SMBIOS:
542 * + the overall checksum must be correct
543 * + the intermediate anchor-string must be _DMI_
544 * + the intermediate checksum must be correct
546 if (memcmp(q, "_SM_", 4) == 0 &&
547 checksum(q, q[0x05]) &&
548 memcmp(q + 0x10, "_DMI_", 5) == 0 && checksum(q + 0x10, 0x0F)) {
549 /* Do not return, legacy_decode will need to be called
550 * on the intermediate structure to get the table length
551 * and address
553 smbios_decode(dmi, q);
554 } else if (memcmp(q, "_DMI_", 5) == 0 && checksum(q, 0x0F)) {
555 found = 1;
556 legacy_decode(dmi, q);
560 if (found)
561 return DMI_TABLE_PRESENT;
563 dmi->dmitable.base = 0;
564 dmi->dmitable.num = 0;
565 dmi->dmitable.ver = 0;
566 dmi->dmitable.len = 0;
567 return -ENODMITABLE;
570 void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi * dmi)
572 uint8_t *data = h->data;
575 * Note: DMI types 37, 38 and 39 are untested
577 switch (h->type) {
578 case 0: /* 3.3.1 BIOS Information */
579 if (h->length < 0x12)
580 break;
581 dmi->bios.filled = true;
582 strncpy(dmi->bios.vendor, dmi_string(h, data[0x04]),
583 sizeof(dmi->bios.vendor));
584 strncpy(dmi->bios.version, dmi_string(h, data[0x05]),
585 sizeof(dmi->bios.version));
586 strncpy(dmi->bios.release_date, dmi_string(h, data[0x08]),
587 sizeof(dmi->bios.release_date));
588 dmi->bios.address = WORD(data + 0x06);
589 dmi_bios_runtime_size((0x10000 - WORD(data + 0x06)) << 4, dmi);
590 dmi->bios.rom_size = (data[0x09] + 1) << 6;
591 strncpy(dmi->bios.rom_size_unit, "kB", sizeof(dmi->bios.rom_size_unit));
592 dmi_bios_characteristics(QWORD(data + 0x0A), dmi);
594 if (h->length < 0x13)
595 break;
596 dmi_bios_characteristics_x1(data[0x12], dmi);
597 if (h->length < 0x14)
598 break;
599 dmi_bios_characteristics_x2(data[0x13], dmi);
600 if (h->length < 0x18)
601 break;
602 if (data[0x14] != 0xFF && data[0x15] != 0xFF)
603 snprintf(dmi->bios.bios_revision, sizeof(dmi->bios.bios_revision),
604 "%u.%u", data[0x14], data[0x15]);
605 if (data[0x16] != 0xFF && data[0x17] != 0xFF)
606 snprintf(dmi->bios.firmware_revision,
607 sizeof(dmi->bios.firmware_revision), "%u.%u", data[0x16],
608 data[0x17]);
609 break;
610 case 1: /* 3.3.2 System Information */
611 if (h->length < 0x08)
612 break;
613 dmi->system.filled = true;
614 strncpy(dmi->system.manufacturer, dmi_string(h, data[0x04]),
615 sizeof(dmi->system.manufacturer));
616 strncpy(dmi->system.product_name, dmi_string(h, data[0x05]),
617 sizeof(dmi->system.product_name));
618 strncpy(dmi->system.version, dmi_string(h, data[0x06]),
619 sizeof(dmi->system.version));
620 strncpy(dmi->system.serial, dmi_string(h, data[0x07]),
621 sizeof(dmi->system.serial));
622 if (h->length < 0x19)
623 break;
624 dmi_system_uuid(data + 0x08, dmi);
625 dmi_system_wake_up_type(data[0x18], dmi);
626 if (h->length < 0x1B)
627 break;
628 strncpy(dmi->system.sku_number, dmi_string(h, data[0x19]),
629 sizeof(dmi->system.sku_number));
630 strncpy(dmi->system.family, dmi_string(h, data[0x1A]),
631 sizeof(dmi->system.family));
632 break;
634 case 2: /* 3.3.3 Base Board Information */
635 if (h->length < 0x08)
636 break;
637 dmi->base_board.filled = true;
638 strncpy(dmi->base_board.manufacturer, dmi_string(h, data[0x04]),
639 sizeof(dmi->base_board.manufacturer));
640 strncpy(dmi->base_board.product_name, dmi_string(h, data[0x05]),
641 sizeof(dmi->base_board.product_name));
642 strncpy(dmi->base_board.version, dmi_string(h, data[0x06]),
643 sizeof(dmi->base_board.version));
644 strncpy(dmi->base_board.serial, dmi_string(h, data[0x07]),
645 sizeof(dmi->base_board.serial));
646 if (h->length < 0x0F)
647 break;
648 strncpy(dmi->base_board.asset_tag, dmi_string(h, data[0x08]),
649 sizeof(dmi->base_board.asset_tag));
650 dmi_base_board_features(data[0x09], dmi);
651 strncpy(dmi->base_board.location, dmi_string(h, data[0x0A]),
652 sizeof(dmi->base_board.location));
653 strncpy(dmi->base_board.type, dmi_string(h, data[0x0D]),
654 sizeof(dmi->base_board.type));
655 if (h->length < 0x0F + data[0x0E] * sizeof(uint16_t))
656 break;
657 break;
658 case 3: /* 3.3.4 Chassis Information */
659 if (h->length < 0x09)
660 break;
661 dmi->chassis.filled = true;
662 strncpy(dmi->chassis.manufacturer, dmi_string(h, data[0x04]),
663 sizeof(dmi->chassis.manufacturer));
664 strncpy(dmi->chassis.type, dmi_chassis_type(data[0x05] & 0x7F),
665 sizeof(dmi->chassis.type));
666 strncpy(dmi->chassis.lock, dmi_chassis_lock(data[0x05] >> 7),
667 sizeof(dmi->chassis.lock));
668 strncpy(dmi->chassis.version, dmi_string(h, data[0x06]),
669 sizeof(dmi->chassis.version));
670 strncpy(dmi->chassis.serial, dmi_string(h, data[0x07]),
671 sizeof(dmi->chassis.serial));
672 strncpy(dmi->chassis.asset_tag, dmi_string(h, data[0x08]),
673 sizeof(dmi->chassis.asset_tag));
674 if (h->length < 0x0D)
675 break;
676 strncpy(dmi->chassis.boot_up_state, dmi_chassis_state(data[0x09]),
677 sizeof(dmi->chassis.boot_up_state));
678 strncpy(dmi->chassis.power_supply_state,
679 dmi_chassis_state(data[0x0A]),
680 sizeof(dmi->chassis.power_supply_state));
681 strncpy(dmi->chassis.thermal_state,
682 dmi_chassis_state(data[0x0B]),
683 sizeof(dmi->chassis.thermal_state));
684 strncpy(dmi->chassis.security_status,
685 dmi_chassis_security_status(data[0x0C]),
686 sizeof(dmi->chassis.security_status));
687 if (h->length < 0x11)
688 break;
689 snprintf(dmi->chassis.oem_information,
690 sizeof(dmi->chassis.oem_information), "0x%08X",
691 DWORD(data + 0x0D));
692 if (h->length < 0x15)
693 break;
694 dmi->chassis.height = data[0x11];
695 dmi->chassis.nb_power_cords = data[0x12];
696 break;
697 case 4: /* 3.3.5 Processor Information */
698 if (h->length < 0x1A)
699 break;
700 dmi->processor.filled = true;
701 strncpy(dmi->processor.socket_designation,
702 dmi_string(h, data[0x04]),
703 sizeof(dmi->processor.socket_designation));
704 strncpy(dmi->processor.type,
705 dmi_processor_type(data[0x05]), sizeof(dmi->processor.type));
706 strncpy(dmi->processor.manufacturer,
707 dmi_string(h, data[0x07]), sizeof(dmi->processor.manufacturer));
708 strncpy(dmi->processor.family,
709 dmi_processor_family(data[0x06],
710 dmi->processor.manufacturer),
711 sizeof(dmi->processor.family));
712 dmi_processor_id(data[0x06], data + 8, dmi_string(h, data[0x10]), dmi);
713 strncpy(dmi->processor.version,
714 dmi_string(h, data[0x10]), sizeof(dmi->processor.version));
715 dmi_processor_voltage(data[0x11], dmi);
716 dmi->processor.external_clock = WORD(data + 0x12);
717 dmi->processor.max_speed = WORD(data + 0x14);
718 dmi->processor.current_speed = WORD(data + 0x16);
719 if (data[0x18] & (1 << 6))
720 strncpy(dmi->processor.status,
721 dmi_processor_status(data[0x18] & 0x07),
722 sizeof(dmi->processor.status));
723 else
724 sprintf(dmi->processor.status, "Unpopulated");
725 strncpy(dmi->processor.upgrade,
726 dmi_processor_upgrade(data[0x19]),
727 sizeof(dmi->processor.upgrade));
728 if (h->length < 0x20)
729 break;
730 dmi_processor_cache(WORD(data + 0x1A), "L1", ver,
731 dmi->processor.cache1);
732 dmi_processor_cache(WORD(data + 0x1C), "L2", ver,
733 dmi->processor.cache2);
734 dmi_processor_cache(WORD(data + 0x1E), "L3", ver,
735 dmi->processor.cache3);
736 if (h->length < 0x23)
737 break;
738 strncpy(dmi->processor.serial, dmi_string(h, data[0x20]),
739 sizeof(dmi->processor.serial));
740 strncpy(dmi->processor.asset_tag, dmi_string(h, data[0x21]),
741 sizeof(dmi->processor.asset_tag));
742 strncpy(dmi->processor.part_number, dmi_string(h, data[0x22]),
743 sizeof(dmi->processor.part_number));
744 break;
745 case 6: /* 3.3.7 Memory Module Information */
746 if (h->length < 0x0C)
747 break;
748 dmi->memory_module_count++;
749 s_memory_module *module =
750 &dmi->memory_module[dmi->memory_module_count - 1];
751 dmi->memory_module[dmi->memory_module_count - 1].filled = true;
752 strncpy(module->socket_designation, dmi_string(h, data[0x04]),
753 sizeof(module->socket_designation));
754 dmi_memory_module_connections(data[0x05], module->bank_connections);
755 dmi_memory_module_speed(data[0x06], module->speed);
756 dmi_memory_module_types(WORD(data + 0x07), " ", module->type);
757 dmi_memory_module_size(data[0x09], module->installed_size);
758 dmi_memory_module_size(data[0x0A], module->enabled_size);
759 dmi_memory_module_error(data[0x0B], "\t\t", module->error_status);
760 break;
761 case 7: /* 3.3.8 Cache Information */
762 if (h->length < 0x0F)
763 break;
764 dmi->cache_count++;
765 if (dmi->cache_count > MAX_DMI_CACHE_ITEMS)
766 break;
767 strncpy(dmi->cache[dmi->cache_count - 1].socket_designation,
768 dmi_string(h, data[0x04]),
769 sizeof(dmi->cache[dmi->cache_count - 1].socket_designation));
770 snprintf(dmi->cache[dmi->cache_count - 1].configuration,
771 sizeof(dmi->cache[dmi->cache_count - 1].configuration),
772 "%s, %s, %u",
773 WORD(data + 0x05) & 0x0080 ? "Enabled" : "Disabled",
774 WORD(data +
775 0x05) & 0x0008 ? "Socketed" : "Not Socketed",
776 (WORD(data + 0x05) & 0x0007) + 1);
777 strncpy(dmi->cache[dmi->cache_count - 1].mode,
778 dmi_cache_mode((WORD(data + 0x05) >> 8) & 0x0003),
779 sizeof(dmi->cache[dmi->cache_count - 1].mode));
780 strncpy(dmi->cache[dmi->cache_count - 1].location,
781 dmi_cache_location((WORD(data + 0x05) >> 5) & 0x0003),
782 sizeof(dmi->cache[dmi->cache_count - 1].location));
783 dmi->cache[dmi->cache_count - 1].installed_size =
784 dmi_cache_size(WORD(data + 0x09));
785 dmi->cache[dmi->cache_count - 1].max_size =
786 dmi_cache_size(WORD(data + 0x07));
787 dmi_cache_types(WORD(data + 0x0B), " ",
788 dmi->cache[dmi->cache_count - 1].supported_sram_types);
789 dmi_cache_types(WORD(data + 0x0D), " ",
790 dmi->cache[dmi->cache_count - 1].installed_sram_types);
791 if (h->length < 0x13)
792 break;
793 dmi->cache[dmi->cache_count - 1].speed = data[0x0F]; /* ns */
794 strncpy(dmi->cache[dmi->cache_count - 1].error_correction_type,
795 dmi_cache_ec_type(data[0x10]),
796 sizeof(dmi->cache[dmi->cache_count - 1].error_correction_type));
797 strncpy(dmi->cache[dmi->cache_count - 1].system_type,
798 dmi_cache_type(data[0x11]),
799 sizeof(dmi->cache[dmi->cache_count - 1].system_type));
800 strncpy(dmi->cache[dmi->cache_count - 1].associativity,
801 dmi_cache_associativity(data[0x12]),
802 sizeof(dmi->cache[dmi->cache_count - 1].associativity));
803 break;
804 case 10: /* 3.3.11 On Board Devices Information */
805 dmi_on_board_devices(h, dmi);
806 break;
807 case 11: /* 3.3.12 OEM Strings */
808 if (h->length < 0x05)
809 break;
810 dmi_oem_strings(h, "\t", dmi);
811 break;
812 case 12: /* 3.3.13 System Configuration Options */
813 if (h->length < 0x05)
814 break;
815 dmi_system_configuration_options(h, "\t", dmi);
816 break;
817 case 17: /* 3.3.18 Memory Device */
818 if (h->length < 0x15)
819 break;
820 dmi->memory_count++;
821 if (dmi->memory_count > MAX_DMI_MEMORY_ITEMS)
822 break;
823 s_memory *mem = &dmi->memory[dmi->memory_count - 1];
824 dmi->memory[dmi->memory_count - 1].filled = true;
825 dmi_memory_array_error_handle(WORD(data + 0x06), mem->error);
826 dmi_memory_device_width(WORD(data + 0x08), mem->total_width);
827 dmi_memory_device_width(WORD(data + 0x0A), mem->data_width);
828 dmi_memory_device_size(WORD(data + 0x0C), mem->size);
829 strncpy(mem->form_factor,
830 dmi_memory_device_form_factor(data[0x0E]),
831 sizeof(mem->form_factor));
832 dmi_memory_device_set(data[0x0F], mem->device_set);
833 strncpy(mem->device_locator, dmi_string(h, data[0x10]),
834 sizeof(mem->device_locator));
835 strncpy(mem->bank_locator, dmi_string(h, data[0x11]),
836 sizeof(mem->bank_locator));
837 strncpy(mem->type, dmi_memory_device_type(data[0x12]),
838 sizeof(mem->type));
839 dmi_memory_device_type_detail(WORD(data + 0x13), mem->type_detail);
840 if (h->length < 0x17)
841 break;
842 dmi_memory_device_speed(WORD(data + 0x15), mem->speed);
843 if (h->length < 0x1B)
844 break;
845 strncpy(mem->manufacturer, dmi_string(h, data[0x17]),
846 sizeof(mem->manufacturer));
847 strncpy(mem->serial, dmi_string(h, data[0x18]), sizeof(mem->serial));
848 strncpy(mem->asset_tag, dmi_string(h, data[0x19]),
849 sizeof(mem->asset_tag));
850 strncpy(mem->part_number, dmi_string(h, data[0x1A]),
851 sizeof(mem->part_number));
852 break;
853 case 22: /* 3.3.23 Portable Battery */
854 if (h->length < 0x10)
855 break;
856 dmi->battery.filled = true;
857 strncpy(dmi->battery.location, dmi_string(h, data[0x04]),
858 sizeof(dmi->battery.location));
859 strncpy(dmi->battery.manufacturer, dmi_string(h, data[0x05]),
860 sizeof(dmi->battery.manufacturer));
861 if (data[0x06] || h->length < 0x1A)
862 strncpy(dmi->battery.manufacture_date,
863 dmi_string(h, data[0x06]),
864 sizeof(dmi->battery.manufacture_date));
865 if (data[0x07] || h->length < 0x1A)
866 strncpy(dmi->battery.serial, dmi_string(h, data[0x07]),
867 sizeof(dmi->battery.serial));
868 strncpy(dmi->battery.name, dmi_string(h, data[0x08]),
869 sizeof(dmi->battery.name));
870 if (data[0x09] != 0x02 || h->length < 0x1A)
871 strncpy(dmi->battery.chemistry,
872 dmi_battery_chemistry(data[0x09]),
873 sizeof(dmi->battery.chemistry));
874 if (h->length < 0x1A)
875 dmi_battery_capacity(WORD(data + 0x0A), 1,
876 dmi->battery.design_capacity);
877 else
878 dmi_battery_capacity(WORD(data + 0x0A), data[0x15],
879 dmi->battery.design_capacity);
880 dmi_battery_voltage(WORD(data + 0x0C), dmi->battery.design_voltage);
881 strncpy(dmi->battery.sbds, dmi_string(h, data[0x0E]),
882 sizeof(dmi->battery.sbds));
883 dmi_battery_maximum_error(data[0x0F], dmi->battery.maximum_error);
884 if (h->length < 0x1A)
885 break;
886 if (data[0x07] == 0)
887 sprintf(dmi->battery.sbds_serial, "%04X", WORD(data + 0x10));
888 if (data[0x06] == 0)
889 sprintf(dmi->battery.sbds_manufacture_date, "%u-%02u-%02u",
890 1980 + (WORD(data + 0x12) >> 9),
891 (WORD(data + 0x12) >> 5) & 0x0F, WORD(data + 0x12) & 0x1F);
892 if (data[0x09] == 0x02)
893 strncpy(dmi->battery.sbds_chemistry, dmi_string(h, data[0x14]),
894 sizeof(dmi->battery.sbds_chemistry));
895 // sprintf(dmi->battery.oem_info,"0x%08X",DWORD(h, data+0x16));
896 break;
897 case 23: /* 3.3.24 System Reset */
898 if (h->length < 0x0D)
899 break;
900 dmi->system.system_reset.filled = true;
901 dmi->system.system_reset.status = data[0x04] & (1 << 0);
902 dmi->system.system_reset.watchdog = data[0x04] & (1 << 5);
903 if (!(data[0x04] & (1 << 5)))
904 break;
905 strncpy(dmi->system.system_reset.boot_option,
906 dmi_system_reset_boot_option((data[0x04] >> 1) & 0x3),
907 sizeof dmi->system.system_reset.boot_option);
908 strncpy(dmi->system.system_reset.boot_option_on_limit,
909 dmi_system_reset_boot_option((data[0x04] >> 3) & 0x3),
910 sizeof dmi->system.system_reset.boot_option_on_limit);
911 dmi_system_reset_count(WORD(data + 0x05),
912 dmi->system.system_reset.reset_count);
913 dmi_system_reset_count(WORD(data + 0x07),
914 dmi->system.system_reset.reset_limit);
915 dmi_system_reset_timer(WORD(data + 0x09),
916 dmi->system.system_reset.timer_interval);
917 dmi_system_reset_timer(WORD(data + 0x0B),
918 dmi->system.system_reset.timeout);
919 break;
920 case 24: /* 3.3.25 Hardware Security */
921 if (h->length < 0x05)
922 break;
923 dmi->hardware_security.filled = true;
924 strncpy(dmi->hardware_security.power_on_passwd_status,
925 dmi_hardware_security_status(data[0x04] >> 6),
926 sizeof dmi->hardware_security.power_on_passwd_status);
927 strncpy(dmi->hardware_security.keyboard_passwd_status,
928 dmi_hardware_security_status((data[0x04] >> 4) & 0x3),
929 sizeof dmi->hardware_security.keyboard_passwd_status);
930 strncpy(dmi->hardware_security.administrator_passwd_status,
931 dmi_hardware_security_status((data[0x04] >> 2) & 0x3),
932 sizeof dmi->hardware_security.administrator_passwd_status);
933 strncpy(dmi->hardware_security.front_panel_reset_status,
934 dmi_hardware_security_status(data[0x04] & 0x3),
935 sizeof dmi->hardware_security.front_panel_reset_status);
936 break;
937 case 32: /* 3.3.33 System Boot Information */
938 if (h->length < 0x0B)
939 break;
940 dmi_system_boot_status(data[0x0A], dmi->system.system_boot_status);
941 case 38: /* 3.3.39 IPMI Device Information */
942 if (h->length < 0x10)
943 break;
944 dmi->ipmi.filled = true;
945 snprintf(dmi->ipmi.interface_type,
946 sizeof(dmi->ipmi.interface_type), "%s",
947 dmi_ipmi_interface_type(data[0x04]));
948 dmi->ipmi.major_specification_version = data[0x05] >> 4;
949 dmi->ipmi.minor_specification_version = data[0x05] & 0x0F;
950 dmi->ipmi.I2C_slave_address = data[0x06] >> 1;
951 if (data[0x07] != 0xFF)
952 dmi->ipmi.nv_address = data[0x07];
953 else
954 dmi->ipmi.nv_address = 0; /* Not Present */
955 dmi_ipmi_base_address(data[0x04], data + 0x08, &dmi->ipmi);
956 if (h->length < 0x12)
957 break;
958 if (data[0x11] != 0x00) {
959 dmi->ipmi.irq = data[0x11];
961 break;
965 void parse_dmitable(s_dmi * dmi)
967 int i = 0;
968 uint8_t *data = NULL;
969 uint8_t buf[dmi->dmitable.len];
970 memcpy(buf, (int *)dmi->dmitable.base, sizeof(uint8_t) * dmi->dmitable.len);
971 data = buf;
972 dmi->memory_count = 0;
973 while (i < dmi->dmitable.num && data + 4 <= buf + dmi->dmitable.len) { /* 4 is the length of an SMBIOS structure header */
974 uint8_t *next;
975 struct dmi_header h;
976 to_dmi_header(&h, data);
978 * If a short entry is found (less than 4 bytes), not only it
979 * is invalid, but we cannot reliably locate the next entry.
980 * Better stop at this point, and let the user know his/her
981 * table is broken.
983 if (h.length < 4) {
984 printf
985 ("Invalid entry length (%u). DMI table is broken! Stop.\n\n",
986 (unsigned int)h.length);
987 break;
990 /* loo for the next handle */
991 next = data + h.length;
992 while (next - buf + 1 < dmi->dmitable.len
993 && (next[0] != 0 || next[1] != 0))
994 next++;
995 next += 2;
996 if (next - buf <= dmi->dmitable.len) {
997 dmi_decode(&h, dmi->dmitable.ver, dmi);
999 data = next;
1000 i++;