From 805dced32cbb2eef1f2b639100faef3bb0482e29 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 1 Apr 2009 16:10:55 +0200 Subject: Added indenting tool for C code and reindented *.[ch] files --- src/dmidecode.c | 9007 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 4801 insertions(+), 4206 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 40cb861..d687c81 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1,3 +1,4 @@ + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DMI Decode @@ -84,6 +85,7 @@ static const char *out_of_spec = ""; static const char *bad_index = ""; + #define BAD_INDEX PyString_FromString("") #define OUT_OF_SPEC PyString_FromString("") @@ -91,292 +93,330 @@ static const char *bad_index = ""; ** Type-independant Stuff */ -static PyObject *dmi_string_py(const struct dmi_header *dm, u8 s) { - char *bp=(char *)dm->data; - size_t i, len; - - PyObject *data; - - if(s==0) data = PyString_FromString("Not Specified"); - else { - bp += dm->length; - while(s>1 && *bp) { bp += strlen(bp); bp++; s--; } - - if(!*bp) data = BAD_INDEX; - else { - /* ASCII filtering */ - len=strlen(bp); - for(i=0; idata; - size_t i, len; - - if(s == 0) return "Not Specified"; - - bp += dm->length; - while(s>1 && *bp) { - bp+=strlen(bp); - bp++; - s--; - } - - if(!*bp) return bad_index; - - /* ASCII filtering */ - len = strlen(bp); - for(i=0; i0x99 || (value&0x0F)>0x09) return 0; - if(valuehigh) return 0; - return 1; -} - -PyObject* dmi_dump(struct dmi_header *h) { - int row, i; - const char *s; - - PyObject *data = PyDict_New(); - PyObject *data1 = PyList_New(0); - for(row=0; row<((h->length-1)>>4)+1; row++) { - for(i=0; i<16 && ilength-(row<<4); i++) - PyList_Append(data1, PyString_FromFormat("0x%02x", (h->data)[(row<<4)+i])); - } - PyDict_SetItemString(data, "Header and Data", data1); - - if((h->data)[h->length] || (h->data)[h->length+1]) { - i=1; - PyObject *data2 = PyList_New(0); - while((s=dmi_string(h, i++))!=bad_index) { - //. FIXME: DUMP - /* - if(opt.flags & FLAG_DUMP) { - int j, l = strlen(s)+1; - for(row=0; row<((l-1)>>4)+1; row++) { - for(j=0; j<16 && jdata; + size_t i, len; + + PyObject *data; + + if(s == 0) + data = PyString_FromString("Not Specified"); + else { + bp += dm->length; + while(s > 1 && *bp) { + bp += strlen(bp); + bp++; + s--; + } + + if(!*bp) + data = BAD_INDEX; + else { + /* ASCII filtering */ + len = strlen(bp); + for(i = 0; i < len; i++) + if(bp[i] < 32 || bp[i] == 127) + bp[i] = '.'; + data = PyString_FromString(bp); + } + } + return data; +} + +const char *dmi_string(const struct dmi_header *dm, u8 s) +{ + char *bp = (char *)dm->data; + size_t i, len; + + if(s == 0) + return "Not Specified"; + + bp += dm->length; + while(s > 1 && *bp) { + bp += strlen(bp); + bp++; + s--; + } + + if(!*bp) + return bad_index; + + /* ASCII filtering */ + len = strlen(bp); + for(i = 0; i < len; i++) + if(bp[i] < 32 || bp[i] == 127) + bp[i] = '.'; + + return bp; +} + +static const char *dmi_smbios_structure_type(u8 code) +{ + static const char *type[] = { + "BIOS", /* 0 */ + "System", + "Base Board", + "Chassis", + "Processor", + "Memory Controller", + "Memory Module", + "Cache", + "Port Connector", + "System Slots", + "On Board Devices", + "OEM Strings", + "System Configuration Options", + "BIOS Language", + "Group Associations", + "System Event Log", + "Physical Memory Array", + "Memory Device", + "32-bit Memory Error", + "Memory Array Mapped Address", + "Memory Device Mapped Address", + "Built-in Pointing Device", + "Portable Battery", + "System Reset", + "Hardware Security", + "System Power Controls", + "Voltage Probe", + "Cooling Device", + "Temperature Probe", + "Electrical Current Probe", + "Out-of-band Remote Access", + "Boot Integrity Services", + "System Boot", + "64-bit Memory Error", + "Management Device", + "Management Device Component", + "Management Device Threshold Data", + "Memory Channel", + "IPMI Device", + "Power Supply" /* 39 */ + }; + + if(code <= 39) + return (type[code]); + return out_of_spec; +} + +static int dmi_bcd_range(u8 value, u8 low, u8 high) +{ + if(value > 0x99 || (value & 0x0F) > 0x09) + return 0; + if(value < low || value > high) + return 0; + return 1; +} + +PyObject *dmi_dump(struct dmi_header * h) +{ + int row, i; + const char *s; + + PyObject *data = PyDict_New(); + PyObject *data1 = PyList_New(0); + + for(row = 0; row < ((h->length - 1) >> 4) + 1; row++) { + for(i = 0; i < 16 && i < h->length - (row << 4); i++) + PyList_Append(data1, + PyString_FromFormat("0x%02x", (h->data)[(row << 4) + i])); } - fprintf(stderr, "\"%s\"|", s); - } - else fprintf(stderr, "%s|", s); - */ - PyList_Append(data1, PyString_FromFormat("%s", s)); - } - PyDict_SetItemString(data, "Strings", data2); - } - return data; + PyDict_SetItemString(data, "Header and Data", data1); + + if((h->data)[h->length] || (h->data)[h->length + 1]) { + i = 1; + PyObject *data2 = PyList_New(0); + + while((s = dmi_string(h, i++)) != bad_index) { + //. FIXME: DUMP + /* + * if(opt.flags & FLAG_DUMP) { + * int j, l = strlen(s)+1; + * for(row=0; row<((l-1)>>4)+1; row++) { + * for(j=0; j<16 && j>10); +static PyObject *dmi_bios_runtime_size(u32 code) +{ + if(code & 0x000003FF) + return PyString_FromFormat("%i bytes", code); + else + return PyString_FromFormat("%i kB", code >> 10); } /* 3.3.1.1 */ -static PyObject* dmi_bios_characteristics(u64 code) { - static const char *characteristics[] = { - "BIOS characteristics not supported", /* 3 */ - "ISA is supported", - "MCA is supported", - "EISA is supported", - "PCI is supported", - "PC Card (PCMCIA) is supported", - "PNP is supported", - "APM is supported", - "BIOS is upgradeable", - "BIOS shadowing is allowed", - "VLB is supported", - "ESCD support is available", - "Boot from CD is supported", - "Selectable boot is supported", - "BIOS ROM is socketed", - "Boot from PC Card (PCMCIA) is supported", - "EDD is supported", - "Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)", - "Japanese floppy for Toshiba 1.2 MB is supported (int 13h)", - "5.25\"/360 KB floppy services are supported (int 13h)", - "5.25\"/1.2 MB floppy services are supported (int 13h)", - "3.5\"/720 KB floppy services are supported (int 13h)", - "3.5\"/2.88 MB floppy services are supported (int 13h)", - "Print screen service is supported (int 5h)", - "8042 keyboard services are supported (int 9h)", - "Serial services are supported (int 14h)", - "Printer services are supported (int 17h)", - "CGA/mono video services are supported (int 10h)", - "NEC PC-98" /* 31 */ - }; - - PyObject *data; - if(code.l&(1<<3)) { - data = PyString_FromString(characteristics[0]); - } else { - int i; - data = PyDict_New(); - for(i=4; i<=31; i++) - PyDict_SetItemString(data, characteristics[i-3], code.l&(1<= 0x0206) - return PyString_FromFormat("%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", - p[3], p[2], p[1], p[0], p[5], p[4], p[7], p[6], - p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] - ); - else - return PyString_FromFormat("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], - p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] - ); +PyObject *dmi_system_uuid_py(const u8 * p, u16 ver) +{ + int only0xFF = 1, only0x00 = 1; + int i; + + for(i = 0; i < 16 && (only0x00 || only0xFF); i++) { + if(p[i] != 0x00) + only0x00 = 0; + if(p[i] != 0xFF) + only0xFF = 0; + } + + if(only0xFF) + return PyString_FromString("Not Present"); + + if(only0x00) + return PyString_FromString("Not Settable"); + + /* + * As off version 2.6 of the SMBIOS specification, the first 3 + * fields of the UUID are supposed to be encoded on little-endian. + * The specification says that this is the defacto standard, + * however I've seen systems following RFC 4122 instead and use + * network byte order, so I am reluctant to apply the byte-swapping + * for older versions. + */ + if(ver >= 0x0206) + return + PyString_FromFormat + ("%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", p[3], + p[2], p[1], p[0], p[5], p[4], p[7], p[6], p[8], p[9], p[10], p[11], p[12], + p[13], p[14], p[15] + ); + else + return + PyString_FromFormat + ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", p[0], + p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], + p[13], p[14], p[15] + ); } /* 3.3.2.1 */ -static PyObject *dmi_system_wake_up_type(u8 code) { - static const char *type[]={ - "Reserved", /* 0x00 */ - "Other", - "Unknown", - "APM Timer", - "Modem Ring", - "LAN Remote", - "Power Switch", - "PCI PME#", - "AC Power Restored" /* 0x08 */ - }; - - if(code<=0x08) return PyString_FromString(type[code]); - return OUT_OF_SPEC; +static PyObject *dmi_system_wake_up_type(u8 code) +{ + static const char *type[] = { + "Reserved", /* 0x00 */ + "Other", + "Unknown", + "APM Timer", + "Modem Ring", + "LAN Remote", + "Power Switch", + "PCI PME#", + "AC Power Restored" /* 0x08 */ + }; + + if(code <= 0x08) + return PyString_FromString(type[code]); + return OUT_OF_SPEC; } /******************************************************************************* @@ -384,64 +424,72 @@ static PyObject *dmi_system_wake_up_type(u8 code) { */ /* 3.3.3.1 */ -static PyObject *dmi_base_board_features(u8 code) { - static const char *features[] = { - "Board is a hosting board", /* 0 */ - "Board requires at least one daughter board", - "Board is removable", - "Board is replaceable", - "Board is hot swappable" /* 4 */ - }; - - PyObject *data; - if((code&0x1F)==0) data = Py_None; - else { - int i; - data = PyList_New(5); - for(i=0; i<=4; i++) { - if(code&(1<=0x01 && code<=0x0D) - return PyString_FromString(type[code-0x01]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_base_board_handles(u8 count, const u8 *p) { - int i; - - PyObject *dict = PyDict_New(); - PyObject *list = PyList_New(count); - - for(i=0; i= 0x01 && code <= 0x0D) + return PyString_FromString(type[code - 0x01]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_base_board_handles(u8 count, const u8 * p) +{ + int i; + + PyObject *dict = PyDict_New(); + PyObject *list = PyList_New(count); + + for(i = 0; i < count; i++) + PyList_SET_ITEM(list, i, PyString_FromFormat("0x%04x", WORD(p + sizeof(u16) * i))); + + PyDict_SetItemString(dict, "Contained Object Handles", list); + Py_DECREF(list); + + return dict; } /******************************************************************************* @@ -449,732 +497,796 @@ static PyObject *dmi_base_board_handles(u8 count, const u8 *p) { */ /* 3.3.4.1 */ -const char *dmi_chassis_type(u8 code) { - static const char *type[] = { - "Other", /* 0x01 */ - "Unknown", - "Desktop", - "Low Profile Desktop", - "Pizza Box", - "Mini Tower", - "Tower", - "Portable", - "Laptop", - "Notebook", - "Hand Held", - "Docking Station", - "All In One", - "Sub Notebook", - "Space-saving", - "Lunch Box", - "Main Server Chassis", /* CIM_Chassis.ChassisPackageType says "Main System Chassis" */ - "Expansion Chassis", - "Sub Chassis", - "Bus Expansion Chassis", - "Peripheral Chassis", - "RAID Chassis", - "Rack Mount Chassis", - "Sealed-case PC", - "Multi-system", - "CompactPCI", - "AdvancedTCA", /* 0x1B */ - "Blade", - "Blade Enclosing" /* 0x1D */ - }; - - if(code>=0x01 && code<=0x1B) - return type[code-0x01]; - return out_of_spec; -} - -static PyObject *dmi_chassis_type_py(u8 code) { - return PyString_FromString(dmi_chassis_type(code)); -} - -static PyObject *dmi_chassis_lock(u8 code) { - static const char *lock[] = { - "Not Present", /* 0x00 */ - "Present" /* 0x01 */ - }; - - return PyString_FromString(lock[code]); +const char *dmi_chassis_type(u8 code) +{ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "Desktop", + "Low Profile Desktop", + "Pizza Box", + "Mini Tower", + "Tower", + "Portable", + "Laptop", + "Notebook", + "Hand Held", + "Docking Station", + "All In One", + "Sub Notebook", + "Space-saving", + "Lunch Box", + "Main Server Chassis", /* CIM_Chassis.ChassisPackageType says "Main System Chassis" */ + "Expansion Chassis", + "Sub Chassis", + "Bus Expansion Chassis", + "Peripheral Chassis", + "RAID Chassis", + "Rack Mount Chassis", + "Sealed-case PC", + "Multi-system", + "CompactPCI", + "AdvancedTCA", /* 0x1B */ + "Blade", + "Blade Enclosing" /* 0x1D */ + }; + + if(code >= 0x01 && code <= 0x1B) + return type[code - 0x01]; + return out_of_spec; +} + +static PyObject *dmi_chassis_type_py(u8 code) +{ + return PyString_FromString(dmi_chassis_type(code)); +} + +static PyObject *dmi_chassis_lock(u8 code) +{ + static const char *lock[] = { + "Not Present", /* 0x00 */ + "Present" /* 0x01 */ + }; + + return PyString_FromString(lock[code]); } /* 3.3.4.2 */ -static PyObject *dmi_chassis_state(u8 code) { - static const char *state[]={ - "Other", /* 0x01 */ - "Unknown", - "Safe", /* master.mif says OK */ - "Warning", - "Critical", - "Non-recoverable" /* 0x06 */ - }; +static PyObject *dmi_chassis_state(u8 code) +{ + static const char *state[] = { + "Other", /* 0x01 */ + "Unknown", + "Safe", /* master.mif says OK */ + "Warning", + "Critical", + "Non-recoverable" /* 0x06 */ + }; - if(code>=0x01 && code<=0x06) - return PyString_FromString(state[code-0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x06) + return PyString_FromString(state[code - 0x01]); + return OUT_OF_SPEC; } /* 3.3.4.3 */ -static const char *dmi_chassis_security_status(u8 code) { - static const char *status[]={ - "Other", /* 0x01 */ - "Unknown", - "None", - "External Interface Locked Out", - "External Interface Enabled" /* 0x05 */ - }; +static const char *dmi_chassis_security_status(u8 code) +{ + static const char *status[] = { + "Other", /* 0x01 */ + "Unknown", + "None", + "External Interface Locked Out", + "External Interface Enabled" /* 0x05 */ + }; - if(code>=0x01 && code<=0x05) - return(status[code-0x01]); - return out_of_spec; + if(code >= 0x01 && code <= 0x05) + return (status[code - 0x01]); + return out_of_spec; } -static PyObject *dmi_chassis_height(u8 code) { - if(code==0x00) return PyString_FromString("Unspecified"); - else return PyString_FromFormat("%i U", code); +static PyObject *dmi_chassis_height(u8 code) +{ + if(code == 0x00) + return PyString_FromString("Unspecified"); + else + return PyString_FromFormat("%i U", code); } -static PyObject *dmi_chassis_power_cords(u8 code) { - if(code==0x00) return PyString_FromString("Unspecified"); - else return PyString_FromFormat("%i", code); +static PyObject *dmi_chassis_power_cords(u8 code) +{ + if(code == 0x00) + return PyString_FromString("Unspecified"); + else + return PyString_FromFormat("%i", code); } -static PyObject *dmi_chassis_elements(u8 count, u8 len, const u8 *p) { - int i; +static PyObject *dmi_chassis_elements(u8 count, u8 len, const u8 * p) +{ + int i; + + PyObject *data = PyDict_New(); + + PyDict_SetItemString(data, "Contained Elements", PyInt_FromLong(count)); - PyObject *data = PyDict_New(); - PyDict_SetItemString(data, "Contained Elements", PyInt_FromLong(count)); + PyObject *_key, *_val; - PyObject *_key, *_val; - for(i=0; i=0x03) { + for(i = 0; i < count; i++) { + if(len >= 0x03) { - _key = PyString_FromFormat("%s", - p[i*len]&0x80? - dmi_smbios_structure_type(p[i*len]&0x7F): - PyString_AS_STRING(dmi_base_board_type(p[i*len]&0x7F)) - ); + _key = PyString_FromFormat("%s", + p[i * len] & 0x80 ? + dmi_smbios_structure_type(p[i * len] & 0x7F) : + PyString_AS_STRING(dmi_base_board_type + (p[i * len] & 0x7F)) + ); - if (p[1+i*len]==p[2+i*len]) _val = PyString_FromFormat("%i", p[1+i*len]); - else _val = PyString_FromFormat("%i-%i", p[1+i*len], p[2+i*len]); + if(p[1 + i * len] == p[2 + i * len]) + _val = PyString_FromFormat("%i", p[1 + i * len]); + else + _val = PyString_FromFormat("%i-%i", p[1 + i * len], p[2 + i * len]); - PyDict_SetItem(data, _key, _val); + PyDict_SetItem(data, _key, _val); - Py_DECREF(_key); - Py_DECREF(_val); - } - } + Py_DECREF(_key); + Py_DECREF(_val); + } + } - return data; + return data; } /******************************************************************************* ** 3.3.5 Processor Information (Type 4) */ -static PyObject *dmi_processor_type(u8 code) { - /* 3.3.5.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Central Processor", - "Math Processor", - "DSP Processor", - "Video Processor" /* 0x06 */ - }; - - if(code>=0x01 && code<=0x06) return PyString_FromString(type[code-0x01]); - return OUT_OF_SPEC; -} - -static const char *dmi_processor_family(const struct dmi_header *h) { - const u8 *data = h->data; - unsigned int i, low, high; - u16 code; - - /* 3.3.5.2 */ - static struct { - int value; - const char *name; - } family2[] = { - { 0x01, "Other" }, - { 0x02, "Unknown" }, - { 0x03, "8086" }, - { 0x04, "80286" }, - { 0x05, "80386" }, - { 0x06, "80486" }, - { 0x07, "8087" }, - { 0x08, "80287" }, - { 0x09, "80387" }, - { 0x0A, "80487" }, - { 0x0B, "Pentium" }, - { 0x0C, "Pentium Pro" }, - { 0x0D, "Pentium II" }, - { 0x0E, "Pentium MMX" }, - { 0x0F, "Celeron" }, - { 0x10, "Pentium II Xeon" }, - { 0x11, "Pentium III" }, - { 0x12, "M1" }, - { 0x13, "M2" }, - { 0x14, "Celeron M" }, /* From CIM_Processor.Family */ - { 0x15, "Pentium 4 HT" }, /* From CIM_Processor.Family */ - - { 0x18, "Duron" }, - { 0x19, "K5" }, - { 0x1A, "K6" }, - { 0x1B, "K6-2" }, - { 0x1C, "K6-3" }, - { 0x1D, "Athlon" }, - { 0x1E, "AMD29000" }, - { 0x1F, "K6-2+" }, - { 0x20, "Power PC" }, - { 0x21, "Power PC 601" }, - { 0x22, "Power PC 603" }, - { 0x23, "Power PC 603+" }, - { 0x24, "Power PC 604" }, - { 0x25, "Power PC 620" }, - { 0x26, "Power PC x704" }, - { 0x27, "Power PC 750" }, - { 0x28, "Core Duo" }, /* From CIM_Processor.Family */ - { 0x29, "Core Duo Mobile" }, /* From CIM_Processor.Family */ - { 0x2A, "Core Solo Mobile" }, /* From CIM_Processor.Family */ - { 0x2B, "Atom" }, /* From CIM_Processor.Family */ - - { 0x30, "Alpha" }, - { 0x31, "Alpha 21064" }, - { 0x32, "Alpha 21066" }, - { 0x33, "Alpha 21164" }, - { 0x34, "Alpha 21164PC" }, - { 0x35, "Alpha 21164a" }, - { 0x36, "Alpha 21264" }, - { 0x37, "Alpha 21364" }, - - { 0x40, "MIPS" }, - { 0x41, "MIPS R4000" }, - { 0x42, "MIPS R4200" }, - { 0x43, "MIPS R4400" }, - { 0x44, "MIPS R4600" }, - { 0x45, "MIPS R10000" }, - - { 0x50, "SPARC" }, - { 0x51, "SuperSPARC" }, - { 0x52, "MicroSPARC II" }, - { 0x53, "MicroSPARC IIep" }, - { 0x54, "UltraSPARC" }, - { 0x55, "UltraSPARC II" }, - { 0x56, "UltraSPARC IIi" }, - { 0x57, "UltraSPARC III" }, - { 0x58, "UltraSPARC IIIi" }, - - { 0x60, "68040" }, - { 0x61, "68xxx" }, - { 0x62, "68000" }, - { 0x63, "68010" }, - { 0x64, "68020" }, - { 0x65, "68030" }, - - { 0x70, "Hobbit" }, - - { 0x78, "Crusoe TM5000" }, - { 0x79, "Crusoe TM3000" }, - { 0x7A, "Efficeon TM8000" }, - - { 0x80, "Weitek" }, - - { 0x82, "Itanium" }, - { 0x83, "Athlon 64" }, - { 0x84, "Opteron" }, - { 0x85, "Sempron" }, - { 0x86, "Turion 64" }, - { 0x87, "Dual-Core Opteron" }, - { 0x88, "Athlon 64 X2" }, - { 0x89, "Turion 64 X2" }, - { 0x8A, "Quad-Core Opteron" }, /* From CIM_Processor.Family */ - { 0x8B, "Third-Generation Opteron" }, /* From CIM_Processor.Family */ - { 0x8C, "Phenom FX" }, /* From CIM_Processor.Family */ - { 0x8D, "Phenom X4" }, /* From CIM_Processor.Family */ - { 0x8E, "Phenom X2" }, /* From CIM_Processor.Family */ - { 0x8F, "Athlon X2" }, /* From CIM_Processor.Family */ - { 0x90, "PA-RISC" }, - { 0x91, "PA-RISC 8500" }, - { 0x92, "PA-RISC 8000" }, - { 0x93, "PA-RISC 7300LC" }, - { 0x94, "PA-RISC 7200" }, - { 0x95, "PA-RISC 7100LC" }, - { 0x96, "PA-RISC 7100" }, - - { 0xA0, "V30" }, - { 0xA1, "Quad-Core Xeon 3200" }, /* From CIM_Processor.Family */ - { 0xA2, "Dual-Core Xeon 3000" }, /* From CIM_Processor.Family */ - { 0xA3, "Quad-Core Xeon 5300" }, /* From CIM_Processor.Family */ - { 0xA4, "Dual-Core Xeon 5100" }, /* From CIM_Processor.Family */ - { 0xA5, "Dual-Core Xeon 5000" }, /* From CIM_Processor.Family */ - { 0xA6, "Dual-Core Xeon LV" }, /* From CIM_Processor.Family */ - { 0xA7, "Dual-Core Xeon ULV" }, /* From CIM_Processor.Family */ - { 0xA8, "Dual-Core Xeon 7100" }, /* From CIM_Processor.Family */ - { 0xA9, "Quad-Core Xeon 5400" }, /* From CIM_Processor.Family */ - { 0xAA, "Quad-Core Xeon" }, /* From CIM_Processor.Family */ - - { 0xB0, "Pentium III Xeon" }, - { 0xB1, "Pentium III Speedstep" }, - { 0xB2, "Pentium 4" }, - { 0xB3, "Xeon" }, - { 0xB4, "AS400" }, - { 0xB5, "Xeon MP" }, - { 0xB6, "Athlon XP" }, - { 0xB7, "Athlon MP" }, - { 0xB8, "Itanium 2" }, - { 0xB9, "Pentium M" }, - { 0xBA, "Celeron D" }, - { 0xBB, "Pentium D" }, - { 0xBC, "Pentium EE" }, - { 0xBD, "Core Solo" }, - /* 0xBE handled as a special case */ - { 0xBF, "Core 2 Duo" }, - { 0xC0, "Core 2 Solo" }, /* From CIM_Processor.Family */ - { 0xC1, "Core 2 Extreme" }, /* From CIM_Processor.Family */ - { 0xC2, "Core 2 Quad" }, /* From CIM_Processor.Family */ - { 0xC3, "Core 2 Extreme Mobile" }, /* From CIM_Processor.Family */ - { 0xC4, "Core 2 Duo Mobile" }, /* From CIM_Processor.Family */ - { 0xC5, "Core 2 Solo Mobile" }, /* From CIM_Processor.Family */ - - { 0xC8, "IBM390" }, - { 0xC9, "G4" }, - { 0xCA, "G5" }, - { 0xCB, "ESA/390 G6" }, - { 0xCC, "z/Architectur" }, - - { 0xD2, "C7-M" }, - { 0xD3, "C7-D" }, - { 0xD4, "C7" }, - { 0xD5, "Eden" }, - - { 0xFA, "i860" }, - { 0xFB, "i960" }, - - { 0x104, "SH-3" }, - { 0x105, "SH-4" }, - - { 0x118, "ARM" }, - { 0x119, "StrongARM" }, - - { 0x12C, "6x86" }, - { 0x12D, "MediaGX" }, - { 0x12E, "MII" }, - - { 0x140, "WinChip" }, - - { 0x15E, "DSP" }, - - { 0x1F4, "Video Processor" }, - }; - - /* Linear Search - Slow - for(i=0; ilength>=0x2A)?WORD(data+0x28):data[0x06]; - - /* Special case for ambiguous value 0xBE */ - if(code == 0xBE) { - const char *manufacturer = dmi_string(h, data[0x07]); - - /* Best bet based on manufacturer string */ - if(strstr(manufacturer, "Intel") != NULL || strncasecmp(manufacturer, "Intel", 5) == 0) - return "Core 2"; - if(strstr(manufacturer, "AMD") != NULL || strncasecmp(manufacturer, "AMD", 3) == 0) - return "K7"; - return "Core 2 or K7"; - } - - /* Perform a binary search */ - low = 0; - high = ARRAY_SIZE(family2) - 1; - while(1) { - i = (low + high) / 2; - if (family2[i].value == code) return family2[i].name; - if (low == high) /* Not found */ return out_of_spec; - if (code < family2[i].value) high = i; - else low = i + 1; - } - - return out_of_spec; -} - -static PyObject *dmi_processor_id(u8 type, const u8 *p, const char *version) { - PyObject *data = PyDict_New(); - - /* Intel AP-485 revision 31, table 3-4 */ - static const char *flags[32]={ - "FPU (Floating-point unit on-chip)", /* 0 */ - "VME (Virtual mode extension)", - "DE (Debugging extension)", - "PSE (Page size extension)", - "TSC (Time stamp counter)", - "MSR (Model specific registers)", - "PAE (Physical address extension)", - "MCE (Machine check exception)", - "CX8 (CMPXCHG8 instruction supported)", - "APIC (On-chip APIC hardware supported)", - NULL, /* 10 */ - "SEP (Fast system call)", - "MTRR (Memory type range registers)", - "PGE (Page global enable)", - "MCA (Machine check architecture)", - "CMOV (Conditional move instruction supported)", - "PAT (Page attribute table)", - "PSE-36 (36-bit page size extension)", - "PSN (Processor serial number present and enabled)", - "CLFSH (CLFLUSH instruction supported)", - NULL, /* 20 */ - "DS (Debug store)", - "ACPI (ACPI supported)", - "MMX (MMX technology supported)", - "FXSR (Fast floating-point save and restore)", - "SSE (Streaming SIMD extensions)", - "SSE2 (Streaming SIMD extensions 2)", - "SS (Self-snoop)", - "HTT (Hyper-threading technology)", - "TM (Thermal monitor supported)", - "IA64 (IA64 capabilities)", - "PBE (Pending break enabled)" /* 31 */ - }; - /* - ** Extra flags are now returned in the ECX register when one calls - ** the CPUID instruction. Their meaning is explained in table 3-5, but - ** DMI doesn't support this yet. - */ - u32 eax, edx; - int sig=0; - - /* - ** This might help learn about new processors supporting the - ** CPUID instruction or another form of identification. - */ - - //. TODO: PyString_FromFormat does not support %x (yet?)... - PyDict_SetItemString(data, "ID", - PyString_FromFormat("%02x %02x %02x %02x %02x %02x %02x %02x", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] - ) - ); - - if(type==0x05) /* 80386 */ { - u16 dx=WORD(p); - /* - ** 80386 have a different signature. - */ - PyDict_SetItemString(data, "Signature", - PyString_FromFormat( - "Type %i, Family %i, Major Stepping %i, Minor Stepping %i", - dx>>12, (dx>>8)&0xF, (dx>>4)&0xF, dx&0xF - ) - ); - return data; - } - - if(type==0x06) /* 80486 */ { - u16 dx=WORD(p); - /* - ** Not all 80486 CPU support the CPUID instruction, we have to find - ** wether the one we have here does or not. Note that this trick - ** works only because we know that 80486 must be little-endian. - */ - if((dx&0x0F00)==0x0400 - &&((dx&0x00F0)==0x0040 || (dx&0x00F0)>=0x0070) - &&((dx&0x000F)>=0x0003)) sig=1; - else { - PyDict_SetItemString(data, "Signature", - PyString_FromFormat( - "Type %i, Family %i, Model %i, Stepping %i", - (dx>>12)&0x3, (dx>>8)&0xF, (dx>>4)&0xF, dx&0xF - ) - ); - return data; - } - } else if( - ( - type >= 0x0B && type <= 0x15) /* Intel, Cyrix */ - || (type >= 0x28 && type <= 0x2B) /* Intel */ - || (type >= 0xA1 && type <= 0xAA) /* Intel */ - || (type >= 0xB0 && type <= 0xB3) /* Intel */ - || type == 0xB5 /* Intel */ - || (type >= 0xB9 && type <= 0xC5) /* Intel */ - || (type >= 0xD2 && type <= 0xD5) /* VIA */ - ) sig=1; - else if( - ( - type >= 0x18 && type <= 0x1D) /* AMD */ - || type == 0x1F /* AMD */ - || (type >= 0x83 && type <= 0x8F) /* AMD */ - || (type >= 0xB6 && type <= 0xB7) /* AMD */ - || (type >= 0xE6 && type <= 0xEB) /* AMD */ - ) sig=2; - else if(type==0x01 || type==0x02) { - /* - ** Some X86-class CPU have family "Other" or "Unknown". In this case, - ** we use the version string to determine if they are known to - ** support the CPUID instruction. - */ - if( - strncmp(version, "Pentium III MMX", 15) == 0 - || strncmp(version, "Intel(R) Core(TM)2", 18) == 0 - || strncmp(version, "Intel(R) Pentium(R)", 19) == 0 - || strcmp(version, "Genuine Intel(R) CPU U1400") == 0 - ) sig = 1; - else if( - strncmp(version, "AMD Athlon(TM)", 14) == 0 - || strncmp(version, "AMD Opteron(tm)", 15) == 0 - || strncmp(version, "Dual-Core AMD Opteron(tm)", 25) == 0 - ) sig = 2; - else return data; - } else /* not X86-class */ return data; - - eax=DWORD(p); - edx=DWORD(p+4); - switch(sig) { - case 1: /* Intel */ - PyDict_SetItemString(data, "Signature", - PyString_FromFormat( - "Type %i, Family %i, Model %i, Stepping %i", - (eax>>12)&0x3, ((eax>>20)&0xFF)+((eax>>8)&0x0F), - ((eax>>12)&0xF0)+((eax>>4)&0x0F), eax&0xF - ) - ); - break; - case 2: /* AMD, publication #25481 revision 2.28 */ - PyDict_SetItemString(data, "Signature", - PyString_FromFormat( - "Family %i, Model %i, Stepping %i", - ((eax>>8)&0xF)+(((eax>>8)&0xF)==0xF?(eax>>20)&0xFF:0), - ((eax>>4)&0xF)|(((eax>>8)&0xF)==0xF?(eax>>12)&0xF0:0), - eax&0xF - ) - ); - break; - } - - edx=DWORD(p+4); - if((edx&0xFFEFFBFF)==0) PyDict_SetItemString(data, "Flags", Py_None); - else { - int i; - PyObject *subdata = PyDict_New(); - for(i=0; i<=31; i++) - if(flags[i]!=NULL) - PyDict_SetItemString(subdata, flags[i], (edx&(1<= 0x01 && code <= 0x06) + return PyString_FromString(type[code - 0x01]); + return OUT_OF_SPEC; +} + +static const char *dmi_processor_family(const struct dmi_header *h) +{ + const u8 *data = h->data; + unsigned int i, low, high; + u16 code; + + /* 3.3.5.2 */ + static struct { + int value; + const char *name; + } family2[] = { + /* *INDENT-OFF* */ + { 0x01, "Other" }, + { 0x02, "Unknown" }, + { 0x03, "8086" }, + { 0x04, "80286" }, + { 0x05, "80386" }, + { 0x06, "80486" }, + { 0x07, "8087" }, + { 0x08, "80287" }, + { 0x09, "80387" }, + { 0x0A, "80487" }, + { 0x0B, "Pentium" }, + { 0x0C, "Pentium Pro" }, + { 0x0D, "Pentium II" }, + { 0x0E, "Pentium MMX" }, + { 0x0F, "Celeron" }, + { 0x10, "Pentium II Xeon" }, + { 0x11, "Pentium III" }, + { 0x12, "M1" }, + { 0x13, "M2" }, + { 0x14, "Celeron M" }, /* From CIM_Processor.Family */ + { 0x15, "Pentium 4 HT" }, /* From CIM_Processor.Family */ + + { 0x18, "Duron" }, + { 0x19, "K5" }, + { 0x1A, "K6" }, + { 0x1B, "K6-2" }, + { 0x1C, "K6-3" }, + { 0x1D, "Athlon" }, + { 0x1E, "AMD29000" }, + { 0x1F, "K6-2+" }, + { 0x20, "Power PC" }, + { 0x21, "Power PC 601" }, + { 0x22, "Power PC 603" }, + { 0x23, "Power PC 603+" }, + { 0x24, "Power PC 604" }, + { 0x25, "Power PC 620" }, + { 0x26, "Power PC x704" }, + { 0x27, "Power PC 750" }, + { 0x28, "Core Duo" }, /* From CIM_Processor.Family */ + { 0x29, "Core Duo Mobile" }, /* From CIM_Processor.Family */ + { 0x2A, "Core Solo Mobile" }, /* From CIM_Processor.Family */ + { 0x2B, "Atom" }, /* From CIM_Processor.Family */ + + { 0x30, "Alpha" }, + { 0x31, "Alpha 21064" }, + { 0x32, "Alpha 21066" }, + { 0x33, "Alpha 21164" }, + { 0x34, "Alpha 21164PC" }, + { 0x35, "Alpha 21164a" }, + { 0x36, "Alpha 21264" }, + { 0x37, "Alpha 21364" }, + + { 0x40, "MIPS" }, + { 0x41, "MIPS R4000" }, + { 0x42, "MIPS R4200" }, + { 0x43, "MIPS R4400" }, + { 0x44, "MIPS R4600" }, + { 0x45, "MIPS R10000" }, + + { 0x50, "SPARC" }, + { 0x51, "SuperSPARC" }, + { 0x52, "MicroSPARC II" }, + { 0x53, "MicroSPARC IIep" }, + { 0x54, "UltraSPARC" }, + { 0x55, "UltraSPARC II" }, + { 0x56, "UltraSPARC IIi" }, + { 0x57, "UltraSPARC III" }, + { 0x58, "UltraSPARC IIIi" }, + + { 0x60, "68040" }, + { 0x61, "68xxx" }, + { 0x62, "68000" }, + { 0x63, "68010" }, + { 0x64, "68020" }, + { 0x65, "68030" }, + + { 0x70, "Hobbit" }, + + { 0x78, "Crusoe TM5000" }, + { 0x79, "Crusoe TM3000" }, + { 0x7A, "Efficeon TM8000" }, + + { 0x80, "Weitek" }, + + { 0x82, "Itanium" }, + { 0x83, "Athlon 64" }, + { 0x84, "Opteron" }, + { 0x85, "Sempron" }, + { 0x86, "Turion 64" }, + { 0x87, "Dual-Core Opteron" }, + { 0x88, "Athlon 64 X2" }, + { 0x89, "Turion 64 X2" }, + { 0x8A, "Quad-Core Opteron" }, /* From CIM_Processor.Family */ + { 0x8B, "Third-Generation Opteron" }, /* From CIM_Processor.Family */ + { 0x8C, "Phenom FX" }, /* From CIM_Processor.Family */ + { 0x8D, "Phenom X4" }, /* From CIM_Processor.Family */ + { 0x8E, "Phenom X2" }, /* From CIM_Processor.Family */ + { 0x8F, "Athlon X2" }, /* From CIM_Processor.Family */ + { 0x90, "PA-RISC" }, + { 0x91, "PA-RISC 8500" }, + { 0x92, "PA-RISC 8000" }, + { 0x93, "PA-RISC 7300LC" }, + { 0x94, "PA-RISC 7200" }, + { 0x95, "PA-RISC 7100LC" }, + { 0x96, "PA-RISC 7100" }, + + { 0xA0, "V30" }, + { 0xA1, "Quad-Core Xeon 3200" }, /* From CIM_Processor.Family */ + { 0xA2, "Dual-Core Xeon 3000" }, /* From CIM_Processor.Family */ + { 0xA3, "Quad-Core Xeon 5300" }, /* From CIM_Processor.Family */ + { 0xA4, "Dual-Core Xeon 5100" }, /* From CIM_Processor.Family */ + { 0xA5, "Dual-Core Xeon 5000" }, /* From CIM_Processor.Family */ + { 0xA6, "Dual-Core Xeon LV" }, /* From CIM_Processor.Family */ + { 0xA7, "Dual-Core Xeon ULV" }, /* From CIM_Processor.Family */ + { 0xA8, "Dual-Core Xeon 7100" }, /* From CIM_Processor.Family */ + { 0xA9, "Quad-Core Xeon 5400" }, /* From CIM_Processor.Family */ + { 0xAA, "Quad-Core Xeon" }, /* From CIM_Processor.Family */ + + { 0xB0, "Pentium III Xeon" }, + { 0xB1, "Pentium III Speedstep" }, + { 0xB2, "Pentium 4" }, + { 0xB3, "Xeon" }, + { 0xB4, "AS400" }, + { 0xB5, "Xeon MP" }, + { 0xB6, "Athlon XP" }, + { 0xB7, "Athlon MP" }, + { 0xB8, "Itanium 2" }, + { 0xB9, "Pentium M" }, + { 0xBA, "Celeron D" }, + { 0xBB, "Pentium D" }, + { 0xBC, "Pentium EE" }, + { 0xBD, "Core Solo" }, + /* 0xBE handled as a special case */ + { 0xBF, "Core 2 Duo" }, + { 0xC0, "Core 2 Solo" }, /* From CIM_Processor.Family */ + { 0xC1, "Core 2 Extreme" }, /* From CIM_Processor.Family */ + { 0xC2, "Core 2 Quad" }, /* From CIM_Processor.Family */ + { 0xC3, "Core 2 Extreme Mobile" }, /* From CIM_Processor.Family */ + { 0xC4, "Core 2 Duo Mobile" }, /* From CIM_Processor.Family */ + { 0xC5, "Core 2 Solo Mobile" }, /* From CIM_Processor.Family */ + + { 0xC8, "IBM390" }, + { 0xC9, "G4" }, + { 0xCA, "G5" }, + { 0xCB, "ESA/390 G6" }, + { 0xCC, "z/Architectur" }, + + { 0xD2, "C7-M" }, + { 0xD3, "C7-D" }, + { 0xD4, "C7" }, + { 0xD5, "Eden" }, + + { 0xFA, "i860" }, + { 0xFB, "i960" }, + + { 0x104, "SH-3" }, + { 0x105, "SH-4" }, + + { 0x118, "ARM" }, + { 0x119, "StrongARM" }, + + { 0x12C, "6x86" }, + { 0x12D, "MediaGX" }, + { 0x12E, "MII" }, + + { 0x140, "WinChip" }, + + { 0x15E, "DSP" }, + + { 0x1F4, "Video Processor" }, + /* *INDENT-ON* */ + }; + + /* Linear Search - Slow + * for(i=0; ilength >= 0x2A) ? WORD(data + 0x28) : data[0x06]; + + /* Special case for ambiguous value 0xBE */ + if(code == 0xBE) { + const char *manufacturer = dmi_string(h, data[0x07]); + + /* Best bet based on manufacturer string */ + if(strstr(manufacturer, "Intel") != NULL || + strncasecmp(manufacturer, "Intel", 5) == 0) + return "Core 2"; + if(strstr(manufacturer, "AMD") != NULL || strncasecmp(manufacturer, "AMD", 3) == 0) + return "K7"; + return "Core 2 or K7"; + } + + /* Perform a binary search */ + low = 0; + high = ARRAY_SIZE(family2) - 1; + while(1) { + i = (low + high) / 2; + if(family2[i].value == code) + return family2[i].name; + if(low == high) /* Not found */ + return out_of_spec; + if(code < family2[i].value) + high = i; + else + low = i + 1; + } + + return out_of_spec; +} + +static PyObject *dmi_processor_id(u8 type, const u8 * p, const char *version) +{ + PyObject *data = PyDict_New(); + + /* Intel AP-485 revision 31, table 3-4 */ + static const char *flags[32] = { + "FPU (Floating-point unit on-chip)", /* 0 */ + "VME (Virtual mode extension)", + "DE (Debugging extension)", + "PSE (Page size extension)", + "TSC (Time stamp counter)", + "MSR (Model specific registers)", + "PAE (Physical address extension)", + "MCE (Machine check exception)", + "CX8 (CMPXCHG8 instruction supported)", + "APIC (On-chip APIC hardware supported)", + NULL, /* 10 */ + "SEP (Fast system call)", + "MTRR (Memory type range registers)", + "PGE (Page global enable)", + "MCA (Machine check architecture)", + "CMOV (Conditional move instruction supported)", + "PAT (Page attribute table)", + "PSE-36 (36-bit page size extension)", + "PSN (Processor serial number present and enabled)", + "CLFSH (CLFLUSH instruction supported)", + NULL, /* 20 */ + "DS (Debug store)", + "ACPI (ACPI supported)", + "MMX (MMX technology supported)", + "FXSR (Fast floating-point save and restore)", + "SSE (Streaming SIMD extensions)", + "SSE2 (Streaming SIMD extensions 2)", + "SS (Self-snoop)", + "HTT (Hyper-threading technology)", + "TM (Thermal monitor supported)", + "IA64 (IA64 capabilities)", + "PBE (Pending break enabled)" /* 31 */ + }; + /* + ** Extra flags are now returned in the ECX register when one calls + ** the CPUID instruction. Their meaning is explained in table 3-5, but + ** DMI doesn't support this yet. + */ + u32 eax, edx; + int sig = 0; + + /* + ** This might help learn about new processors supporting the + ** CPUID instruction or another form of identification. + */ + + //. TODO: PyString_FromFormat does not support %x (yet?)... + PyDict_SetItemString(data, "ID", + PyString_FromFormat("%02x %02x %02x %02x %02x %02x %02x %02x", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] + ) + ); + + if(type == 0x05) { /* 80386 */ + u16 dx = WORD(p); + + /* + ** 80386 have a different signature. + */ + PyDict_SetItemString(data, "Signature", + PyString_FromFormat + ("Type %i, Family %i, Major Stepping %i, Minor Stepping %i", + dx >> 12, (dx >> 8) & 0xF, (dx >> 4) & 0xF, dx & 0xF) + ); + return data; + } + + if(type == 0x06) { /* 80486 */ + u16 dx = WORD(p); + + /* + ** Not all 80486 CPU support the CPUID instruction, we have to find + ** wether the one we have here does or not. Note that this trick + ** works only because we know that 80486 must be little-endian. + */ + if((dx & 0x0F00) == 0x0400 && ((dx & 0x00F0) == 0x0040 || (dx & 0x00F0) >= 0x0070) + && ((dx & 0x000F) >= 0x0003)) + sig = 1; + else { + PyDict_SetItemString(data, "Signature", + PyString_FromFormat + ("Type %i, Family %i, Model %i, Stepping %i", + (dx >> 12) & 0x3, (dx >> 8) & 0xF, (dx >> 4) & 0xF, + dx & 0xF) + ); + return data; + } + } else if((type >= 0x0B && type <= 0x15) /* Intel, Cyrix */ + ||(type >= 0x28 && type <= 0x2B) /* Intel */ + ||(type >= 0xA1 && type <= 0xAA) /* Intel */ + ||(type >= 0xB0 && type <= 0xB3) /* Intel */ + ||type == 0xB5 /* Intel */ + || (type >= 0xB9 && type <= 0xC5) /* Intel */ + ||(type >= 0xD2 && type <= 0xD5) /* VIA */ + ) + sig = 1; + else if((type >= 0x18 && type <= 0x1D) /* AMD */ + ||type == 0x1F /* AMD */ + || (type >= 0x83 && type <= 0x8F) /* AMD */ + ||(type >= 0xB6 && type <= 0xB7) /* AMD */ + ||(type >= 0xE6 && type <= 0xEB) /* AMD */ + ) + sig = 2; + else if(type == 0x01 || type == 0x02) { + /* + ** Some X86-class CPU have family "Other" or "Unknown". In this case, + ** we use the version string to determine if they are known to + ** support the CPUID instruction. + */ + if(strncmp(version, "Pentium III MMX", 15) == 0 + || strncmp(version, "Intel(R) Core(TM)2", 18) == 0 + || strncmp(version, "Intel(R) Pentium(R)", 19) == 0 + || strcmp(version, "Genuine Intel(R) CPU U1400") == 0) + sig = 1; + else if(strncmp(version, "AMD Athlon(TM)", 14) == 0 + || strncmp(version, "AMD Opteron(tm)", 15) == 0 + || strncmp(version, "Dual-Core AMD Opteron(tm)", 25) == 0) + sig = 2; + else + return data; + } else /* not X86-class */ + return data; + + eax = DWORD(p); + edx = DWORD(p + 4); + switch (sig) { + case 1: /* Intel */ + PyDict_SetItemString(data, "Signature", + PyString_FromFormat + ("Type %i, Family %i, Model %i, Stepping %i", + (eax >> 12) & 0x3, ((eax >> 20) & 0xFF) + ((eax >> 8) & 0x0F), + ((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F), eax & 0xF) + ); + break; + case 2: /* AMD, publication #25481 revision 2.28 */ + PyDict_SetItemString(data, "Signature", + PyString_FromFormat("Family %i, Model %i, Stepping %i", + ((eax >> 8) & 0xF) + (((eax >> 8) & 0xF) == + 0xF ? (eax >> 20) & + 0xFF : 0), + ((eax >> 4) & 0xF) | (((eax >> 8) & 0xF) == + 0xF ? (eax >> 12) & + 0xF0 : 0), eax & 0xF) + ); + break; + } + + edx = DWORD(p + 4); + if((edx & 0xFFEFFBFF) == 0) + PyDict_SetItemString(data, "Flags", Py_None); + else { + int i; + PyObject *subdata = PyDict_New(); + + for(i = 0; i <= 31; i++) + if(flags[i] != NULL) + PyDict_SetItemString(subdata, flags[i], + (edx & (1 << i)) ? Py_True : Py_False); + PyDict_SetItemString(data, "Flags", subdata); + Py_DECREF(subdata); + } + + return data; } /* 3.3.5.4 */ -static PyObject *dmi_processor_voltage(u8 code) { - static const char *voltage[]={ - "5.0 V", /* 0 */ - "3.3 V", - "2.9 V" /* 2 */ - }; - int i; - - PyObject *data; - if(code&0x80) data = PyString_FromFormat("%.1f V", (float)(code&0x7f)/10); - else { - data = PyDict_New(); - for(i=0; i<=2; i++) - PyDict_SetItemString(data, voltage[i], (code&(1<=0x01 && code<=0x15) return PyString_FromString(upgrade[code-0x01]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_processor_cache(u16 code, const char *level, u16 ver) { - PyObject *data; - if(code==0xFFFF) { - if(ver>=0x0203) data = PyString_FromString("Not Provided"); - else data = PyString_FromFormat("No %s Cache", level); - } else data = PyString_FromFormat("0x%04x", code); - return data; +static PyObject *dmi_processor_voltage(u8 code) +{ + static const char *voltage[] = { + "5.0 V", /* 0 */ + "3.3 V", + "2.9 V" /* 2 */ + }; + int i; + + PyObject *data; + + if(code & 0x80) + data = PyString_FromFormat("%.1f V", (float)(code & 0x7f) / 10); + else { + data = PyDict_New(); + for(i = 0; i <= 2; i++) + PyDict_SetItemString(data, voltage[i], + (code & (1 << i) ? Py_True : Py_False)); + if(code == 0x00) + PyDict_SetItemString(data, "VOLTAGE", PyString_FromString("Unknown")); + } + return data; +} + +int dmi_processor_frequency(const u8 * p) +{ + u16 code = WORD(p); + + if(code) + return code; //. Value measured in MHz + else + return -1; //. Unknown +} +static PyObject *dmi_processor_frequency_py(const u8 * p) +{ + return PyInt_FromLong(dmi_processor_frequency(p)); +} + +static const char *dmi_processor_status(u8 code) +{ + static const char *status[] = { + "Unknown", /* 0x00 */ + "Enabled", + "Disabled By User", + "Disabled By BIOS", + "Idle", /* 0x04 */ + "Other" /* 0x07 */ + }; + + if(code <= 0x04) + return status[code]; + if(code == 0x07) + return status[0x05]; + return out_of_spec; +} + +static PyObject *dmi_processor_upgrade(u8 code) +{ + /* 3.3.5.5 */ + static const char *upgrade[] = { + "Other", /* 0x01 */ + "Unknown", + "Daughter Board", + "ZIF Socket", + "Replaceable Piggy Back", + "None", + "LIF Socket", + "Slot 1", + "Slot 2", + "370-pin Socket", + "Slot A", + "Slot M", + "Socket 423", + "Socket A (Socket 462)", + "Socket 478", + "Socket 754", + "Socket 940", + "Socket 939", + "Socket mPGA604", + "Socket LGA771", + "Socket LGA775", /* 0x15 */ + "Socket S1", + "Socket AM2", + "Socket F (1207)" /* 0x18 */ + }; + + if(code >= 0x01 && code <= 0x15) + return PyString_FromString(upgrade[code - 0x01]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_processor_cache(u16 code, const char *level, u16 ver) +{ + PyObject *data; + + if(code == 0xFFFF) { + if(ver >= 0x0203) + data = PyString_FromString("Not Provided"); + else + data = PyString_FromFormat("No %s Cache", level); + } else + data = PyString_FromFormat("0x%04x", code); + return data; } /* 3.3.5.9 */ -static PyObject *dmi_processor_characteristics(u16 code) { - static const char *characteristics[]={ - "64-bit capable" /* 2 */ - }; - - PyObject *data; - if((code&0x0004)==0) { - data = Py_None; - } else { - data = PyList_New(1); - int i; - for(i=2; i<=2; i++) - if(code&(1<=0x01 && code<=0x08) return(PyString_FromString(method[code-0x01])); - return OUT_OF_SPEC; +static PyObject *dmi_memory_controller_ed_method(u8 code) +{ + /* 3.3.6.1 */ + static const char *method[] = { + "Other", /* 0x01 */ + "Unknown", + "None", + "8-bit Parity", + "32-bit ECC", + "64-bit ECC", + "128-bit ECC", + "CRC" /* 0x08 */ + }; + + if(code >= 0x01 && code <= 0x08) + return (PyString_FromString(method[code - 0x01])); + return OUT_OF_SPEC; } /* 3.3.6.2 */ -static PyObject *dmi_memory_controller_ec_capabilities(u8 code) { - static const char *capabilities[]={ - "Other", /* 0 */ - "Unknown", - "None", - "Single-bit Error Correcting", - "Double-bit Error Correcting", - "Error Scrubbing" /* 5 */ - }; - - PyObject *data = Py_None; - if((code&0x3F)==0) return Py_None; - else { - int i; - - data = PyList_New(6); - for(i=0; i<=5; i++) - if(code&(1<=0x01 && code<=0x07) return PyString_FromString(interleave[code-0x01]); - return OUT_OF_SPEC; +static PyObject *dmi_memory_controller_ec_capabilities(u8 code) +{ + static const char *capabilities[] = { + "Other", /* 0 */ + "Unknown", + "None", + "Single-bit Error Correcting", + "Double-bit Error Correcting", + "Error Scrubbing" /* 5 */ + }; + + PyObject *data = Py_None; + + if((code & 0x3F) == 0) + return Py_None; + else { + int i; + + data = PyList_New(6); + for(i = 0; i <= 5; i++) + if(code & (1 << i)) + PyList_SET_ITEM(data, i, PyString_FromString(capabilities[i])); + else + PyList_SET_ITEM(data, i, Py_None); + } + return data; +} + +static PyObject *dmi_memory_controller_interleave(u8 code) +{ + /* 3.3.6.3 */ + static const char *interleave[] = { + "Other", /* 0x01 */ + "Unknown", + "One-way Interleave", + "Two-way Interleave", + "Four-way Interleave", + "Eight-way Interleave", + "Sixteen-way Interleave" /* 0x07 */ + }; + + if(code >= 0x01 && code <= 0x07) + return PyString_FromString(interleave[code - 0x01]); + return OUT_OF_SPEC; } /* 3.3.6.4 */ -static PyObject *dmi_memory_controller_speeds(u16 code) { - const char *speeds[]={ - "Other", /* 0 */ - "Unknown", - "70 ns", - "60 ns", - "50 ns" /* 4 */ - }; - - PyObject *data; - if((code&0x001F)!=0) data = Py_None; - else { - int i; - - data = PyList_New(5); - for(i=0; i<=4; i++) - if(code&(1<>4)); - if((code&0x0F)!=0x0F) PyList_Append(data, PyInt_FromLong(code&0x0F)); - } - return data; -} - -static PyObject *dmi_memory_module_speed(u8 code) { - if(code==0) return PyString_FromString("Unknown"); - else return PyString_FromFormat("%i ns", code); +static PyObject *dmi_memory_module_types(u16 code) +{ + static const char *types[] = { + "Other", /* 0 */ + "Unknown", + "Standard", + "FPM", + "EDO", + "Parity", + "ECC", + "SIMM", + "DIMM", + "Burst EDO", + "SDRAM" /* 10 */ + }; + + PyObject *data; + + if((code & 0x07FF) == 0) + data = Py_None; + else { + int i; + + data = PyList_New(11); + for(i = 0; i <= 10; i++) + if(code & (1 << i)) + PyList_SET_ITEM(data, i, PyString_FromString(types[i])); + else + PyList_SET_ITEM(data, i, Py_None); + } + return data; +} + +static PyObject *dmi_memory_module_connections(u8 code) +{ + PyObject *data; + + if(code == 0xFF) + data = Py_None; + else { + data = PyList_New(0); + if((code & 0xF0) != 0xF0) + PyList_Append(data, PyInt_FromLong(code >> 4)); + if((code & 0x0F) != 0x0F) + PyList_Append(data, PyInt_FromLong(code & 0x0F)); + } + return data; +} + +static PyObject *dmi_memory_module_speed(u8 code) +{ + if(code == 0) + return PyString_FromString("Unknown"); + else + return PyString_FromFormat("%i ns", code); } /* 3.3.7.2 */ -static PyObject *dmi_memory_module_size(u8 code) { - PyObject *data = PyDict_New(); - int check_conn = 1; - - switch(code&0x7F) { - case 0x7D: - PyDict_SetItemString(data, "Size", PyString_FromString("Not Determinable")); - break; - case 0x7E: - PyDict_SetItemString(data, "Size", PyString_FromString("Disabled")); - break; - case 0x7F: - PyDict_SetItemString(data, "Size", PyString_FromString("Not Installed")); - check_conn = 0; - default: - PyDict_SetItemString(data, "Size", PyString_FromFormat("%i MB", 1<<(code&0x7F))); - } - - if(check_conn) { - if(code&0x80) PyDict_SetItemString(data, "Connection", PyString_FromString("Double-bank")); - else PyDict_SetItemString(data, "Connection", PyString_FromString("Single-bank")); - } - return data; -} - -static PyObject *dmi_memory_module_error(u8 code) { - PyObject *data = NULL; - if(code&(1<<2)) data = Py_None; //. TODO: sprintf(_, "See Event Log"); - else { - if((code&0x03)==0) data = Py_True; - if(code&(1<<0)) data = PyString_FromString("Uncorrectable Errors"); - if(code&(1<<1)) data = PyString_FromString("Correctable Errors"); - } - return data; +static PyObject *dmi_memory_module_size(u8 code) +{ + PyObject *data = PyDict_New(); + int check_conn = 1; + + switch (code & 0x7F) { + case 0x7D: + PyDict_SetItemString(data, "Size", PyString_FromString("Not Determinable")); + break; + case 0x7E: + PyDict_SetItemString(data, "Size", PyString_FromString("Disabled")); + break; + case 0x7F: + PyDict_SetItemString(data, "Size", PyString_FromString("Not Installed")); + check_conn = 0; + default: + PyDict_SetItemString(data, "Size", + PyString_FromFormat("%i MB", 1 << (code & 0x7F))); + } + + if(check_conn) { + if(code & 0x80) + PyDict_SetItemString(data, "Connection", + PyString_FromString("Double-bank")); + else + PyDict_SetItemString(data, "Connection", + PyString_FromString("Single-bank")); + } + return data; +} + +static PyObject *dmi_memory_module_error(u8 code) +{ + PyObject *data = NULL; + + if(code & (1 << 2)) + data = Py_None; //. TODO: sprintf(_, "See Event Log"); + else { + if((code & 0x03) == 0) + data = Py_True; + if(code & (1 << 0)) + data = PyString_FromString("Uncorrectable Errors"); + if(code & (1 << 1)) + data = PyString_FromString("Correctable Errors"); + } + return data; } /******************************************************************************* ** 3.3.8 Cache Information (Type 7) */ -static PyObject *dmi_cache_mode(u8 code) { - static const char *mode[]={ - "Write Through", /* 0x00 */ - "Write Back", - "Varies With Memory Address", - "Unknown" /* 0x03 */ - }; +static PyObject *dmi_cache_mode(u8 code) +{ + static const char *mode[] = { + "Write Through", /* 0x00 */ + "Write Back", + "Varies With Memory Address", + "Unknown" /* 0x03 */ + }; - return PyString_FromString(mode[code]); + return PyString_FromString(mode[code]); } -static PyObject *dmi_cache_location(u8 code) { - static const char *location[4]={ - "Internal", /* 0x00 */ - "External", - NULL, /* 0x02 */ - "Unknown" /* 0x03 */ - }; +static PyObject *dmi_cache_location(u8 code) +{ + static const char *location[4] = { + "Internal", /* 0x00 */ + "External", + NULL, /* 0x02 */ + "Unknown" /* 0x03 */ + }; + + PyObject *data; - PyObject *data; - if(location[code]!=NULL) data = PyString_FromString(location[code]); - else data = OUT_OF_SPEC; - return data; + if(location[code] != NULL) + data = PyString_FromString(location[code]); + else + data = OUT_OF_SPEC; + return data; } -static PyObject *dmi_cache_size(u16 code) { - PyObject *data; - if(code&0x8000) data = PyString_FromFormat("%i KB", (code&0x7FFF)<<6); - else data = PyString_FromFormat("%i KB", code); - return data; +static PyObject *dmi_cache_size(u16 code) +{ + PyObject *data; + + if(code & 0x8000) + data = PyString_FromFormat("%i KB", (code & 0x7FFF) << 6); + else + data = PyString_FromFormat("%i KB", code); + return data; } /* 3.3.8.2 */ -static PyObject *dmi_cache_types(u16 code) { - static const char *types[] = { - "Other", /* 0 */ - "Unknown", - "Non-burst", - "Burst", - "Pipeline Burst", - "Synchronous", - "Asynchronous" /* 6 */ - }; - PyObject *data; - - if((code&0x007F)==0) data = Py_None; - else { - int i; - - data = PyList_New(7); - for(i=0; i<=6; i++) - if(code&(1<=0x01 && code<=0x06) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_cache_type(u8 code) { - /* 3.3.8.4 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Instruction", - "Data", - "Unified" /* 0x05 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x05) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_cache_associativity(u8 code) { - /* 3.3.8.5 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Direct Mapped", - "2-way Set-associative", - "4-way Set-associative", - "Fully Associative", - "8-way Set-associative", - "16-way Set-associative" /* 0x08 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x08) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; +static PyObject *dmi_cache_types(u16 code) +{ + static const char *types[] = { + "Other", /* 0 */ + "Unknown", + "Non-burst", + "Burst", + "Pipeline Burst", + "Synchronous", + "Asynchronous" /* 6 */ + }; + PyObject *data; + + if((code & 0x007F) == 0) + data = Py_None; + else { + int i; + + data = PyList_New(7); + for(i = 0; i <= 6; i++) + if(code & (1 << i)) + PyList_SET_ITEM(data, i, PyString_FromString(types[i])); + else + PyList_SET_ITEM(data, i, Py_None); + } + return data; +} + +static PyObject *dmi_cache_ec_type(u8 code) +{ + /* 3.3.8.3 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "None", + "Parity", + "Single-bit ECC", + "Multi-bit ECC" /* 0x06 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x06) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_cache_type(u8 code) +{ + /* 3.3.8.4 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "Instruction", + "Data", + "Unified" /* 0x05 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x05) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_cache_associativity(u8 code) +{ + /* 3.3.8.5 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "Direct Mapped", + "2-way Set-associative", + "4-way Set-associative", + "Fully Associative", + "8-way Set-associative", + "16-way Set-associative" /* 0x08 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x08) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; } /******************************************************************************* ** 3.3.9 Port Connector Information (Type 8) */ -static PyObject *dmi_port_connector_type(u8 code) { - /* 3.3.9.2 */ - static const char *type[] = { - "None", /* 0x00 */ - "Centronics", - "Mini Centronics", - "Proprietary", - "DB-25 male", - "DB-25 female", - "DB-15 male", - "DB-15 female", - "DB-9 male", - "DB-9 female", - "RJ-11", - "RJ-45", - "50 Pin MiniSCSI", - "Mini DIN", - "Micro DIN", - "PS/2", - "Infrared", - "HP-HIL", - "Access Bus (USB)", - "SSA SCSI", - "Circular DIN-8 male", - "Circular DIN-8 female", - "On Board IDE", - "On Board Floppy", - "9 Pin Dual Inline (pin 10 cut)", - "25 Pin Dual Inline (pin 26 cut)", - "50 Pin Dual Inline", - "68 Pin Dual Inline", - "On Board Sound Input From CD-ROM", - "Mini Centronics Type-14", - "Mini Centronics Type-26", - "Mini Jack (headphones)", - "BNC", - "IEEE 1394", - "SAS/SATA Plug Receptacle" /* 0x22 */ - }; - static const char *type_0xA0[]={ - "PC-98", /* 0xA0 */ - "PC-98 Hireso", - "PC-H98", - "PC-98 Note", - "PC-98 Full" /* 0xA4 */ - }; - - if(code<=0x22) return PyString_FromString(type[code]); - if(code>=0xA0 && code<=0xA4) return PyString_FromString(type_0xA0[code-0xA0]); - if(code==0xFF) return PyString_FromString("Other"); - return OUT_OF_SPEC; -} - -static PyObject *dmi_port_type(u8 code) { - /* 3.3.9.3 */ - static const char *type[] = { - "None", /* 0x00 */ - "Parallel Port XT/AT Compatible", - "Parallel Port PS/2", - "Parallel Port ECP", - "Parallel Port EPP", - "Parallel Port ECP/EPP", - "Serial Port XT/AT Compatible", - "Serial Port 16450 Compatible", - "Serial Port 16550 Compatible", - "Serial Port 16550A Compatible", - "SCSI Port", - "MIDI Port", - "Joystick Port", - "Keyboard Port", - "Mouse Port", - "SSA SCSI", - "USB", - "Firewire (IEEE P1394)", - "PCMCIA Type I", - "PCMCIA Type II", - "PCMCIA Type III", - "Cardbus", - "Access Bus Port", - "SCSI II", - "SCSI Wide", - "PC-98", - "PC-98 Hireso", - "PC-H98", - "Video Port", - "Audio Port", - "Modem Port", - "Network Port", - "SATA", - "SAS" /* 0x21 */ - }; - static const char *type_0xA0[]={ - "8251 Compatible", /* 0xA0 */ - "8251 FIFO Compatible" /* 0xA1 */ - }; - - if(code<=0x21) return PyString_FromString(type[code]); - if(code>=0xA0 && code<=0xA1) return PyString_FromString(type_0xA0[code-0xA0]); - if(code==0xFF) return PyString_FromString("Other"); - return OUT_OF_SPEC; +static PyObject *dmi_port_connector_type(u8 code) +{ + /* 3.3.9.2 */ + static const char *type[] = { + "None", /* 0x00 */ + "Centronics", + "Mini Centronics", + "Proprietary", + "DB-25 male", + "DB-25 female", + "DB-15 male", + "DB-15 female", + "DB-9 male", + "DB-9 female", + "RJ-11", + "RJ-45", + "50 Pin MiniSCSI", + "Mini DIN", + "Micro DIN", + "PS/2", + "Infrared", + "HP-HIL", + "Access Bus (USB)", + "SSA SCSI", + "Circular DIN-8 male", + "Circular DIN-8 female", + "On Board IDE", + "On Board Floppy", + "9 Pin Dual Inline (pin 10 cut)", + "25 Pin Dual Inline (pin 26 cut)", + "50 Pin Dual Inline", + "68 Pin Dual Inline", + "On Board Sound Input From CD-ROM", + "Mini Centronics Type-14", + "Mini Centronics Type-26", + "Mini Jack (headphones)", + "BNC", + "IEEE 1394", + "SAS/SATA Plug Receptacle" /* 0x22 */ + }; + static const char *type_0xA0[] = { + "PC-98", /* 0xA0 */ + "PC-98 Hireso", + "PC-H98", + "PC-98 Note", + "PC-98 Full" /* 0xA4 */ + }; + + if(code <= 0x22) + return PyString_FromString(type[code]); + if(code >= 0xA0 && code <= 0xA4) + return PyString_FromString(type_0xA0[code - 0xA0]); + if(code == 0xFF) + return PyString_FromString("Other"); + return OUT_OF_SPEC; +} + +static PyObject *dmi_port_type(u8 code) +{ + /* 3.3.9.3 */ + static const char *type[] = { + "None", /* 0x00 */ + "Parallel Port XT/AT Compatible", + "Parallel Port PS/2", + "Parallel Port ECP", + "Parallel Port EPP", + "Parallel Port ECP/EPP", + "Serial Port XT/AT Compatible", + "Serial Port 16450 Compatible", + "Serial Port 16550 Compatible", + "Serial Port 16550A Compatible", + "SCSI Port", + "MIDI Port", + "Joystick Port", + "Keyboard Port", + "Mouse Port", + "SSA SCSI", + "USB", + "Firewire (IEEE P1394)", + "PCMCIA Type I", + "PCMCIA Type II", + "PCMCIA Type III", + "Cardbus", + "Access Bus Port", + "SCSI II", + "SCSI Wide", + "PC-98", + "PC-98 Hireso", + "PC-H98", + "Video Port", + "Audio Port", + "Modem Port", + "Network Port", + "SATA", + "SAS" /* 0x21 */ + }; + static const char *type_0xA0[] = { + "8251 Compatible", /* 0xA0 */ + "8251 FIFO Compatible" /* 0xA1 */ + }; + + if(code <= 0x21) + return PyString_FromString(type[code]); + if(code >= 0xA0 && code <= 0xA1) + return PyString_FromString(type_0xA0[code - 0xA0]); + if(code == 0xFF) + return PyString_FromString("Other"); + return OUT_OF_SPEC; } /******************************************************************************* ** 3.3.10 System Slots (Type 9) */ -static PyObject *dmi_slot_type(u8 code) { - /* 3.3.10.1 */ - static const char *type[] = { - "Other", /* 0x01 */ - "Unknown", - "ISA", - "MCA", - "EISA", - "PCI", - "PC Card (PCMCIA)", - "VLB", - "Proprietary", - "Processor Card", - "Proprietary Memory Card", - "I/O Riser Card", - "NuBus", - "PCI-66", - "AGP", - "AGP 2x", - "AGP 4x", - "PCI-X", - "AGP 8x" /* 0x13 */ - }; - static const char *type_0xA0[]={ - "PC-98/C20", /* 0xA0 */ - "PC-98/C24", - "PC-98/E", - "PC-98/Local Bus", - "PC-98/Card", - "PCI Express", - "PCI Express x1", - "PCI Express x2", - "PCI Express x4", - "PCI Express x8", - "PCI Express x16" /* 0xAA */ - }; - - if(code>=0x01 && code<=0x13) return PyString_FromString(type[code-0x01]); - if(code>=0xA0 && code<=0xAA) return PyString_FromString(type_0xA0[code-0xA0]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_slot_bus_width(u8 code) { - /* 3.3.10.2 */ - static const char *width[]={ - "", /* 0x01, "Other" */ - "", /* "Unknown" */ - "8-bit ", - "16-bit ", - "32-bit ", - "64-bit ", - "128-bit ", - "x1 ", - "x2 ", - "x4 ", - "x8 ", - "x12 ", - "x16 ", - "x32 " /* 0x0E */ - }; - - if(code>=0x01 && code<=0x0E) return PyString_FromString(width[code-0x01]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_slot_current_usage(u8 code) { - /* 3.3.10.3 */ - static const char *usage[]={ - "Other", /* 0x01 */ - "Unknown", - "Available", - "In Use" /* 0x04 */ - }; - - if(code>=0x01 && code<=0x04) return PyString_FromString(usage[code-0x01]); - return OUT_OF_SPEC; +static PyObject *dmi_slot_type(u8 code) +{ + /* 3.3.10.1 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "ISA", + "MCA", + "EISA", + "PCI", + "PC Card (PCMCIA)", + "VLB", + "Proprietary", + "Processor Card", + "Proprietary Memory Card", + "I/O Riser Card", + "NuBus", + "PCI-66", + "AGP", + "AGP 2x", + "AGP 4x", + "PCI-X", + "AGP 8x" /* 0x13 */ + }; + static const char *type_0xA0[] = { + "PC-98/C20", /* 0xA0 */ + "PC-98/C24", + "PC-98/E", + "PC-98/Local Bus", + "PC-98/Card", + "PCI Express", + "PCI Express x1", + "PCI Express x2", + "PCI Express x4", + "PCI Express x8", + "PCI Express x16" /* 0xAA */ + }; + + if(code >= 0x01 && code <= 0x13) + return PyString_FromString(type[code - 0x01]); + if(code >= 0xA0 && code <= 0xAA) + return PyString_FromString(type_0xA0[code - 0xA0]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_slot_bus_width(u8 code) +{ + /* 3.3.10.2 */ + static const char *width[] = { + "", /* 0x01, "Other" */ + "", /* "Unknown" */ + "8-bit ", + "16-bit ", + "32-bit ", + "64-bit ", + "128-bit ", + "x1 ", + "x2 ", + "x4 ", + "x8 ", + "x12 ", + "x16 ", + "x32 " /* 0x0E */ + }; + + if(code >= 0x01 && code <= 0x0E) + return PyString_FromString(width[code - 0x01]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_slot_current_usage(u8 code) +{ + /* 3.3.10.3 */ + static const char *usage[] = { + "Other", /* 0x01 */ + "Unknown", + "Available", + "In Use" /* 0x04 */ + }; + + if(code >= 0x01 && code <= 0x04) + return PyString_FromString(usage[code - 0x01]); + return OUT_OF_SPEC; } /* 3.3.1O.4 */ -static PyObject *dmi_slot_length(u8 code) { - static const char *length[]={ - "Other", /* 0x01 */ - "Unknown", - "Short", - "Long" /* 0x04 */ - }; +static PyObject *dmi_slot_length(u8 code) +{ + static const char *length[] = { + "Other", /* 0x01 */ + "Unknown", + "Short", + "Long" /* 0x04 */ + }; - if(code>=0x01 && code<=0x04) - return PyString_FromString(length[code-0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x04) + return PyString_FromString(length[code - 0x01]); + return OUT_OF_SPEC; } /* 3.3.10.5 */ -static PyObject *dmi_slot_id(u8 code1, u8 code2, u8 type) { - PyObject *data; - switch(type) { - case 0x04: /* MCA */ - data = PyString_FromFormat("%i", code1); - break; - case 0x05: /* EISA */ - data = PyString_FromFormat("%i", code1); - break; - case 0x06: /* PCI */ - case 0x0E: /* PCI */ - case 0x0F: /* AGP */ - case 0x10: /* AGP */ - case 0x11: /* AGP */ - case 0x12: /* PCI-X */ - case 0x13: /* AGP */ - case 0xA5: /* PCI Express */ - data = PyString_FromFormat("%i", code1); - break; - case 0x07: /* PCMCIA */ - data = PyString_FromFormat("Adapter %i, Socket %i", code1, code2); - break; - default: - data = Py_None; - } - return data; -} - -static PyObject *dmi_slot_characteristics(u8 code1, u8 code2) { - /* 3.3.10.6 */ - static const char *characteristics1[]={ - "5.0 V is provided", /* 1 */ - "3.3 V is provided", - "Opening is shared", - "PC Card-16 is supported", - "Cardbus is supported", - "Zoom Video is supported", - "Modem ring resume is supported" /* 7 */ - }; - - /* 3.3.10.7 */ - static const char *characteristics2[]={ - "PME signal is supported", /* 0 */ - "Hot-plug devices are supported", - "SMBus signal is supported" /* 2 */ - }; - - PyObject *data; - if(code1&(1<<0)) data = PyString_FromString("Unknown"); - else if((code1&0xFE)==0 && (code2&0x07)==0) data = Py_None; - else { - int i; - - data = PyList_New(7+3); - for(i=1; i<=7; i++) { - if(code1&(1<> 3, code3 & 0x7); - else data = Py_None; - return data; +static PyObject *dmi_slot_id(u8 code1, u8 code2, u8 type) +{ + PyObject *data; + + switch (type) { + case 0x04: /* MCA */ + data = PyString_FromFormat("%i", code1); + break; + case 0x05: /* EISA */ + data = PyString_FromFormat("%i", code1); + break; + case 0x06: /* PCI */ + case 0x0E: /* PCI */ + case 0x0F: /* AGP */ + case 0x10: /* AGP */ + case 0x11: /* AGP */ + case 0x12: /* PCI-X */ + case 0x13: /* AGP */ + case 0xA5: /* PCI Express */ + data = PyString_FromFormat("%i", code1); + break; + case 0x07: /* PCMCIA */ + data = PyString_FromFormat("Adapter %i, Socket %i", code1, code2); + break; + default: + data = Py_None; + } + return data; +} + +static PyObject *dmi_slot_characteristics(u8 code1, u8 code2) +{ + /* 3.3.10.6 */ + static const char *characteristics1[] = { + "5.0 V is provided", /* 1 */ + "3.3 V is provided", + "Opening is shared", + "PC Card-16 is supported", + "Cardbus is supported", + "Zoom Video is supported", + "Modem ring resume is supported" /* 7 */ + }; + + /* 3.3.10.7 */ + static const char *characteristics2[] = { + "PME signal is supported", /* 0 */ + "Hot-plug devices are supported", + "SMBus signal is supported" /* 2 */ + }; + + PyObject *data; + + if(code1 & (1 << 0)) + data = PyString_FromString("Unknown"); + else if((code1 & 0xFE) == 0 && (code2 & 0x07) == 0) + data = Py_None; + else { + int i; + + data = PyList_New(7 + 3); + for(i = 1; i <= 7; i++) { + if(code1 & (1 << i)) + PyList_SET_ITEM(data, i - 1, + PyString_FromString(characteristics1[i - 1])); + else + PyList_SET_ITEM(data, i - 1, Py_None); + } + for(i = 0; i <= 2; i++) { + if(code2 & (1 << i)) + PyList_SET_ITEM(data, 7 + i, + PyString_FromString(characteristics2[i])); + else + PyList_SET_ITEM(data, 7 + i, Py_None); + } + } + return data; +} + +static PyObject *dmi_slot_segment_bus_func(u16 code1, u8 code2, u8 code3) +{ + /* 3.3.10.8 */ + PyObject *data; + + if(!(code1 == 0xFFFF && code2 == 0xFF && code3 == 0xFF)) + data = + PyString_FromFormat("%04x:%02x:%02x.%x", code1, code2, code3 >> 3, code3 & 0x7); + else + data = Py_None; + return data; } /******************************************************************************* ** 3.3.11 On Board Devices Information (Type 10) */ -static const char *dmi_on_board_devices_type(u8 code) { - /* 3.3.11.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Video", - "SCSI Controller", - "Ethernet", - "Token Ring", - "Sound", - "PATA Controller", - "SATA Controller", - "SAS Controller" /* 0x0A */ - }; - - if(code>=0x01 && code<=0x0A) return type[code-0x01]; - return out_of_spec; -} - -static PyObject *dmi_on_board_devices(struct dmi_header *h) { - PyObject *data = NULL; - u8 *p = h->data+4; - u8 count = (h->length-0x04)/2; - int i; - - if((data = PyList_New(count))) { - PyObject *_pydict; - PyObject *_val; - for(i=0; i= 0x01 && code <= 0x0A) + return type[code - 0x01]; + return out_of_spec; +} + +static PyObject *dmi_on_board_devices(struct dmi_header *h) +{ + PyObject *data = NULL; + u8 *p = h->data + 4; + u8 count = (h->length - 0x04) / 2; + int i; + + if((data = PyList_New(count))) { + PyObject *_pydict; + PyObject *_val; + + for(i = 0; i < count; i++) { + _pydict = PyDict_New(); + + _val = PyString_FromString(dmi_on_board_devices_type(p[2 * i] & 0x7F)); + PyDict_SetItemString(_pydict, "Type", _val); + Py_DECREF(_val); + + _val = p[2 * i] & 0x80 ? Py_True : Py_False; + PyDict_SetItemString(_pydict, "Enabled", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, p[2 * i + 1]); + PyDict_SetItemString(_pydict, "Description", _val); + Py_DECREF(_val); + + PyList_SET_ITEM(data, i, _pydict); + } + } + + assert(data != NULL); + Py_INCREF(data); + return data; } /******************************************************************************* * 3.3.12 OEM Strings (Type 11) */ -static PyObject *dmi_oem_strings(struct dmi_header *h) { - u8 *p=h->data+4; - u8 count=p[0x00]; - int i; +static PyObject *dmi_oem_strings(struct dmi_header *h) +{ + u8 *p = h->data + 4; + u8 count = p[0x00]; + int i; - PyObject *data = PyDict_New(); - PyObject *val; + PyObject *data = PyDict_New(); + PyObject *val; - for(i=1; i<=count; i++) { - val = dmi_string_py(h, i); - PyDict_SetItem(data, PyInt_FromLong(i), val); - Py_DECREF(val); - } + for(i = 1; i <= count; i++) { + val = dmi_string_py(h, i); + PyDict_SetItem(data, PyInt_FromLong(i), val); + Py_DECREF(val); + } - return data; + return data; } /******************************************************************************* ** 3.3.13 System Configuration Options (Type 12) */ -static PyObject *dmi_system_configuration_options(struct dmi_header *h) { - u8 *p=h->data+4; - u8 count=p[0x00]; - int i; +static PyObject *dmi_system_configuration_options(struct dmi_header *h) +{ + u8 *p = h->data + 4; + u8 count = p[0x00]; + int i; + + PyObject *data = PyDict_New(); + PyObject *val; - PyObject *data = PyDict_New(); - PyObject *val; - for(i=1; i<=count; i++) { - val = dmi_string_py(h, i); - PyDict_SetItem(data, PyInt_FromLong(i), val); - Py_DECREF(val); - } + for(i = 1; i <= count; i++) { + val = dmi_string_py(h, i); + PyDict_SetItem(data, PyInt_FromLong(i), val); + Py_DECREF(val); + } - return data; + return data; } /******************************************************************************* ** 3.3.14 BIOS Language Information (Type 13) */ -static PyObject *dmi_bios_languages(struct dmi_header *h) { - u8 *p = h->data+4; - u8 count = p[0x00]; - int i; +static PyObject *dmi_bios_languages(struct dmi_header *h) +{ + u8 *p = h->data + 4; + u8 count = p[0x00]; + int i; + + PyObject *data = PyList_New(count + 1); - PyObject *data = PyList_New(count + 1); - for(i=1; i<=count; i++) - PyList_SET_ITEM(data, i, dmi_string_py(h, i)); + for(i = 1; i <= count; i++) + PyList_SET_ITEM(data, i, dmi_string_py(h, i)); - return data; + return data; } /******************************************************************************* ** 3.3.15 Group Associations (Type 14) */ -static PyObject *dmi_group_associations_items(u8 count, const u8 *p) { - int i; +static PyObject *dmi_group_associations_items(u8 count, const u8 * p) +{ + int i; + + PyObject *data = PyList_New(count); + PyObject *val; - PyObject *data = PyList_New(count); - PyObject *val; - for(i=0; i=0x80) return "OEM-specific"; - return out_of_spec; -} - -static PyObject *dmi_event_log_status_py(u8 code) { - static const char *valid[]={ - "Invalid", /* 0 */ - "Valid" /* 1 */ - }; - static const char *full[]={ - "Not Full", /* 0 */ - "Full" /* 1 */ - }; - - return PyString_FromFormat("%s, %s", valid[(code>>0)&1], full[(code>>1)&1]); -} - -static PyObject *dmi_event_log_address_py(u8 method, const u8 *p) { - /* 3.3.16.3 */ - switch(method) { - case 0x00: - case 0x01: - case 0x02: - return PyString_FromFormat("Index 0x%04x, Data 0x%04x", WORD(p), WORD(p+2)); - break; - case 0x03: - return PyString_FromFormat("0x%08x", DWORD(p)); - break; - case 0x04: - return PyString_FromFormat("0x%04x", WORD(p)); - break; - default: - return PyString_FromString("Unknown"); - } -} - -static const char *dmi_event_log_header_type(u8 code) { - static const char *type[]={ - "No Header", /* 0x00 */ - "Type 1" /* 0x01 */ - }; - - if(code<=0x01) return type[code]; - if(code>=0x80) return "OEM-specific"; - return out_of_spec; -} - -static PyObject *dmi_event_log_descriptor_type(u8 code) { - /* 3.3.16.6.1 */ - static const char *type[]={ - NULL, /* 0x00 */ - "Single-bit ECC memory error", - "Multi-bit ECC memory error", - "Parity memory error", - "Bus timeout", - "I/O channel block", - "Software NMI", - "POST memory resize", - "POST error", - "PCI parity error", - "PCI system error", - "CPU failure", - "EISA failsafe timer timeout", - "Correctable memory log disabled", - "Logging disabled", - NULL, /* 0x0F */ - "System limit exceeded", - "Asynchronous hardware timer expired", - "System configuration information", - "Hard disk information", - "System reconfigured", - "Uncorrectable CPU-complex error", - "Log area reset/cleared", - "System boot" /* 0x17 */ - }; - - const char *data; - if(code<=0x17 && type[code]!=NULL) data = type[code]; - else if(code>=0x80 && code<=0xFE) data = "OEM-specific"; - else if(code==0xFF) data = "End of log"; - else data = out_of_spec; - return PyString_FromString(data); -} - -static PyObject *dmi_event_log_descriptor_format(u8 code) { - /* 3.3.16.6.2 */ - static const char *format[]={ - "None", /* 0x00 */ - "Handle", - "Multiple-event", - "Multiple-event handle", - "POST results bitmap", - "System management", - "Multiple-event system management" /* 0x06 */ - }; - - const char *data; - if(code<=0x06) data = format[code]; - else if(code>=0x80) data = "OEM-specific"; - else data = out_of_spec; - return PyString_FromString(data); -} - -static PyObject *dmi_event_log_descriptors(u8 count, const u8 len, const u8 *p) { - /* 3.3.16.1 */ - int i; - - PyObject* data; - data = PyList_New(count); - for(i=0; i=0x02) { - PyObject *subdata = PyDict_New(); - PyDict_SetItemString(subdata, "Descriptor", dmi_event_log_descriptor_type(p[i*len])); - PyDict_SetItemString(subdata, "Data Format", dmi_event_log_descriptor_format(p[i*len+1])); - PyList_SET_ITEM(data, i, subdata); - } - } - return data; +static const char *dmi_event_log_method(u8 code) +{ + static const char *method[] = { + "Indexed I/O, one 8-bit index port, one 8-bit data port", /* 0x00 */ + "Indexed I/O, two 8-bit index ports, one 8-bit data port", + "Indexed I/O, one 16-bit index port, one 8-bit data port", + "Memory-mapped physical 32-bit address", + "General-purpose non-volatile data functions" /* 0x04 */ + }; + + if(code <= 0x04) + return method[code]; + if(code >= 0x80) + return "OEM-specific"; + return out_of_spec; +} + +static PyObject *dmi_event_log_status_py(u8 code) +{ + static const char *valid[] = { + "Invalid", /* 0 */ + "Valid" /* 1 */ + }; + static const char *full[] = { + "Not Full", /* 0 */ + "Full" /* 1 */ + }; + + return PyString_FromFormat("%s, %s", valid[(code >> 0) & 1], full[(code >> 1) & 1]); +} + +static PyObject *dmi_event_log_address_py(u8 method, const u8 * p) +{ + /* 3.3.16.3 */ + switch (method) { + case 0x00: + case 0x01: + case 0x02: + return PyString_FromFormat("Index 0x%04x, Data 0x%04x", WORD(p), WORD(p + 2)); + break; + case 0x03: + return PyString_FromFormat("0x%08x", DWORD(p)); + break; + case 0x04: + return PyString_FromFormat("0x%04x", WORD(p)); + break; + default: + return PyString_FromString("Unknown"); + } +} + +static const char *dmi_event_log_header_type(u8 code) +{ + static const char *type[] = { + "No Header", /* 0x00 */ + "Type 1" /* 0x01 */ + }; + + if(code <= 0x01) + return type[code]; + if(code >= 0x80) + return "OEM-specific"; + return out_of_spec; +} + +static PyObject *dmi_event_log_descriptor_type(u8 code) +{ + /* 3.3.16.6.1 */ + static const char *type[] = { + NULL, /* 0x00 */ + "Single-bit ECC memory error", + "Multi-bit ECC memory error", + "Parity memory error", + "Bus timeout", + "I/O channel block", + "Software NMI", + "POST memory resize", + "POST error", + "PCI parity error", + "PCI system error", + "CPU failure", + "EISA failsafe timer timeout", + "Correctable memory log disabled", + "Logging disabled", + NULL, /* 0x0F */ + "System limit exceeded", + "Asynchronous hardware timer expired", + "System configuration information", + "Hard disk information", + "System reconfigured", + "Uncorrectable CPU-complex error", + "Log area reset/cleared", + "System boot" /* 0x17 */ + }; + + const char *data; + + if(code <= 0x17 && type[code] != NULL) + data = type[code]; + else if(code >= 0x80 && code <= 0xFE) + data = "OEM-specific"; + else if(code == 0xFF) + data = "End of log"; + else + data = out_of_spec; + return PyString_FromString(data); +} + +static PyObject *dmi_event_log_descriptor_format(u8 code) +{ + /* 3.3.16.6.2 */ + static const char *format[] = { + "None", /* 0x00 */ + "Handle", + "Multiple-event", + "Multiple-event handle", + "POST results bitmap", + "System management", + "Multiple-event system management" /* 0x06 */ + }; + + const char *data; + + if(code <= 0x06) + data = format[code]; + else if(code >= 0x80) + data = "OEM-specific"; + else + data = out_of_spec; + return PyString_FromString(data); +} + +static PyObject *dmi_event_log_descriptors(u8 count, const u8 len, const u8 * p) +{ + /* 3.3.16.1 */ + int i; + + PyObject *data; + + data = PyList_New(count); + for(i = 0; i < count; i++) { + if(len >= 0x02) { + PyObject *subdata = PyDict_New(); + + PyDict_SetItemString(subdata, "Descriptor", + dmi_event_log_descriptor_type(p[i * len])); + PyDict_SetItemString(subdata, "Data Format", + dmi_event_log_descriptor_format(p[i * len + 1])); + PyList_SET_ITEM(data, i, subdata); + } + } + return data; } /******************************************************************************* ** 3.3.17 Physical Memory Array (Type 16) */ -static PyObject *dmi_memory_array_location(u8 code) { - /* 3.3.17.1 */ - static const char *location[]={ - "Other", /* 0x01 */ - "Unknown", - "System Board Or Motherboard", - "ISA Add-on Card", - "EISA Add-on Card", - "PCI Add-on Card", - "MCA Add-on Card", - "PCMCIA Add-on Card", - "Proprietary Add-on Card", - "NuBus" /* 0x0A, master.mif says 16 */ - }; - static const char *location_0xA0[]={ - "PC-98/C20 Add-on Card", /* 0xA0 */ - "PC-98/C24 Add-on Card", - "PC-98/E Add-on Card", - "PC-98/Local Bus Add-on Card", - "PC-98/Card Slot Add-on Card" /* 0xA4, from master.mif */ - }; - - if(code>=0x01 && code<=0x0A) return PyString_FromString(location[code-0x01]); - if(code>=0xA0 && code<=0xA4) return PyString_FromString(location_0xA0[code-0xA0]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_memory_array_use(u8 code) { - /* 3.3.17.2 */ - static const char *use[]={ - "Other", /* 0x01 */ - "Unknown", - "System Memory", - "Video Memory", - "Flash Memory", - "Non-volatile RAM", - "Cache Memory" /* 0x07 */ - }; - - if(code>=0x01 && code<=0x07) return PyString_FromString(use[code-0x01]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_memory_array_ec_type(u8 code) { - /* 3.3.17.3 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "None", - "Parity", - "Single-bit ECC", - "Multi-bit ECC", - "CRC" /* 0x07 */ - }; - - if(code>=0x01 && code<=0x07) return PyString_FromString(type[code-0x01]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_memory_array_capacity(u32 code) { - PyObject *data; - if(code==0x8000000) data = PyString_FromString("Unknown"); - else { - if((code&0x000FFFFF)==0) data = PyString_FromFormat("%i GB", code>>20); - else if((code&0x000003FF)==0) data = PyString_FromFormat("%i MB", code>>10); - else data = PyString_FromFormat("%i kB", code); - } - return data; -} - -static PyObject *dmi_memory_array_error_handle(u16 code) { - PyObject *data; - if(code==0xFFFE) data = PyString_FromString("Not Provided"); - else if(code==0xFFFF) data = PyString_FromString("No Error"); - else data = PyString_FromFormat("0x%04x", code); - return data; +static PyObject *dmi_memory_array_location(u8 code) +{ + /* 3.3.17.1 */ + static const char *location[] = { + "Other", /* 0x01 */ + "Unknown", + "System Board Or Motherboard", + "ISA Add-on Card", + "EISA Add-on Card", + "PCI Add-on Card", + "MCA Add-on Card", + "PCMCIA Add-on Card", + "Proprietary Add-on Card", + "NuBus" /* 0x0A, master.mif says 16 */ + }; + static const char *location_0xA0[] = { + "PC-98/C20 Add-on Card", /* 0xA0 */ + "PC-98/C24 Add-on Card", + "PC-98/E Add-on Card", + "PC-98/Local Bus Add-on Card", + "PC-98/Card Slot Add-on Card" /* 0xA4, from master.mif */ + }; + + if(code >= 0x01 && code <= 0x0A) + return PyString_FromString(location[code - 0x01]); + if(code >= 0xA0 && code <= 0xA4) + return PyString_FromString(location_0xA0[code - 0xA0]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_memory_array_use(u8 code) +{ + /* 3.3.17.2 */ + static const char *use[] = { + "Other", /* 0x01 */ + "Unknown", + "System Memory", + "Video Memory", + "Flash Memory", + "Non-volatile RAM", + "Cache Memory" /* 0x07 */ + }; + + if(code >= 0x01 && code <= 0x07) + return PyString_FromString(use[code - 0x01]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_memory_array_ec_type(u8 code) +{ + /* 3.3.17.3 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "None", + "Parity", + "Single-bit ECC", + "Multi-bit ECC", + "CRC" /* 0x07 */ + }; + + if(code >= 0x01 && code <= 0x07) + return PyString_FromString(type[code - 0x01]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_memory_array_capacity(u32 code) +{ + PyObject *data; + + if(code == 0x8000000) + data = PyString_FromString("Unknown"); + else { + if((code & 0x000FFFFF) == 0) + data = PyString_FromFormat("%i GB", code >> 20); + else if((code & 0x000003FF) == 0) + data = PyString_FromFormat("%i MB", code >> 10); + else + data = PyString_FromFormat("%i kB", code); + } + return data; +} + +static PyObject *dmi_memory_array_error_handle(u16 code) +{ + PyObject *data; + + if(code == 0xFFFE) + data = PyString_FromString("Not Provided"); + else if(code == 0xFFFF) + data = PyString_FromString("No Error"); + else + data = PyString_FromFormat("0x%04x", code); + return data; } /******************************************************************************* ** 3.3.18 Memory Device (Type 17) */ -static PyObject *dmi_memory_device_width(u16 code) { - /* - ** If no memory module is present, width may be 0 - */ - PyObject *data; - if(code==0xFFFF || code==0) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%i bits", code); - return data; -} - -static PyObject *dmi_memory_device_size(u16 code) { - PyObject *data = NULL; - if(code==0) data = Py_None; //. No Module Installed - else if(code==0xFFFF) data = PyString_FromString("Unknown"); //. Unknown - else { - //. Keeping this as String rather than Int as it has KB and MB representations... - if(code&0x8000) data = PyString_FromFormat("%d KB", code&0x7FFF); - else data = PyString_FromFormat("%d MB", code); - } - return data; -} - -static PyObject *dmi_memory_device_form_factor(u8 code) { - /* 3.3.18.1 */ - static const char *form_factor[]={ - "Other", /* 0x01 */ - "Unknown", - "SIMM", - "SIP", - "Chip", - "DIP", - "ZIP", - "Proprietary Card", - "DIMM", - "TSOP", - "Row Of Chips", - "RIMM", - "SODIMM", - "SRIMM", - "FB-DIMM" /* 0x0F */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x0F) return data = PyString_FromString(form_factor[code-0x01]); - return data = OUT_OF_SPEC; -} - -static PyObject *dmi_memory_device_set(u8 code) { - PyObject *data; - if(code==0) data = Py_None; - else if(code==0xFF) data = PyString_FromString("Unknown"); - else data = PyInt_FromLong(code); - return data; -} - -static PyObject *dmi_memory_device_type(u8 code) { - /* 3.3.18.2 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "DRAM", - "EDRAM", - "VRAM", - "SRAM", - "RAM", - "ROM", - "Flash", - "EEPROM", - "FEPROM", - "EPROM", - "CDRAM", - "3DRAM", - "SDRAM", - "SGRAM", - "RDRAM", - "DDR", - "DDR2", - "DDR2 FB-DIMM" /* 0x14 */ - }; - - if(code>=0x01 && code<=0x14) return PyString_FromString(type[code-0x01]); - return OUT_OF_SPEC; -} - -static PyObject *dmi_memory_device_type_detail(u16 code) { - /* 3.3.18.3 */ - static const char *detail[]={ - "Other", /* 1 */ - "Unknown", - "Fast-paged", - "Static Column", - "Pseudo-static", - "RAMBus", - "Synchronous", - "CMOS", - "EDO", - "Window DRAM", - "Cache DRAM", - "Non-Volatile" /* 12 */ - }; - - PyObject *data; - if((code&0x1FFE)==0) data = Py_None; - else { - int i; - - data = PyList_New(12); - for(i=1; i<=12; i++) - if(code&(1<= 0x01 && code <= 0x0F) + return data = PyString_FromString(form_factor[code - 0x01]); + return data = OUT_OF_SPEC; +} + +static PyObject *dmi_memory_device_set(u8 code) +{ + PyObject *data; + + if(code == 0) + data = Py_None; + else if(code == 0xFF) + data = PyString_FromString("Unknown"); + else + data = PyInt_FromLong(code); + return data; +} + +static PyObject *dmi_memory_device_type(u8 code) +{ + /* 3.3.18.2 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "DRAM", + "EDRAM", + "VRAM", + "SRAM", + "RAM", + "ROM", + "Flash", + "EEPROM", + "FEPROM", + "EPROM", + "CDRAM", + "3DRAM", + "SDRAM", + "SGRAM", + "RDRAM", + "DDR", + "DDR2", + "DDR2 FB-DIMM" /* 0x14 */ + }; + + if(code >= 0x01 && code <= 0x14) + return PyString_FromString(type[code - 0x01]); + return OUT_OF_SPEC; +} + +static PyObject *dmi_memory_device_type_detail(u16 code) +{ + /* 3.3.18.3 */ + static const char *detail[] = { + "Other", /* 1 */ + "Unknown", + "Fast-paged", + "Static Column", + "Pseudo-static", + "RAMBus", + "Synchronous", + "CMOS", + "EDO", + "Window DRAM", + "Cache DRAM", + "Non-Volatile" /* 12 */ + }; + + PyObject *data; + + if((code & 0x1FFE) == 0) + data = Py_None; + else { + int i; + + data = PyList_New(12); + for(i = 1; i <= 12; i++) + if(code & (1 << i)) + PyList_SET_ITEM(data, i - 1, PyString_FromString(detail[i - 1])); + else + PyList_SET_ITEM(data, i - 1, Py_None); + } + return data; +} + +static PyObject *dmi_memory_device_speed(u16 code) +{ + PyObject *data; + + if(code == 0) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%i MHz (%.1f ns)", code, (float)1000 / code); + return data; } /******************************************************************************* * 3.3.19 32-bit Memory Error Information (Type 18) */ -static PyObject *dmi_memory_error_type(u8 code) { - /* 3.3.19.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "OK", - "Bad Read", - "Parity Error", - "Single-bit Error", - "Double-bit Error", - "Multi-bit Error", - "Nibble Error", - "Checksum Error", - "CRC Error", - "Corrected Single-bit Error", - "Corrected Error", - "Uncorrectable Error" /* 0x0E */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x0E) data = PyString_FromString(type[code-0x01]); - data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_memory_error_granularity(u8 code) { - /* 3.3.19.2 */ - static const char *granularity[]={ - "Other", /* 0x01 */ - "Unknown", - "Device Level", - "Memory Partition Level" /* 0x04 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x04) data = PyString_FromString(granularity[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_memory_error_operation(u8 code) { - /* 3.3.19.3 */ - static const char *operation[]={ - "Other", /* 0x01 */ - "Unknown", - "Read", - "Write", - "Partial Write" /* 0x05 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x05) data = PyString_FromString(operation[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_memory_error_syndrome(u32 code) { - PyObject *data; - if(code==0x00000000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("0x%08x", code); - return data; -} - -static PyObject *dmi_32bit_memory_error_address(u32 code) { - PyObject *data; - if(code==0x80000000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("0x%08x", code); - return data; +static PyObject *dmi_memory_error_type(u8 code) +{ + /* 3.3.19.1 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "OK", + "Bad Read", + "Parity Error", + "Single-bit Error", + "Double-bit Error", + "Multi-bit Error", + "Nibble Error", + "Checksum Error", + "CRC Error", + "Corrected Single-bit Error", + "Corrected Error", + "Uncorrectable Error" /* 0x0E */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x0E) + data = PyString_FromString(type[code - 0x01]); + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_memory_error_granularity(u8 code) +{ + /* 3.3.19.2 */ + static const char *granularity[] = { + "Other", /* 0x01 */ + "Unknown", + "Device Level", + "Memory Partition Level" /* 0x04 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x04) + data = PyString_FromString(granularity[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_memory_error_operation(u8 code) +{ + /* 3.3.19.3 */ + static const char *operation[] = { + "Other", /* 0x01 */ + "Unknown", + "Read", + "Write", + "Partial Write" /* 0x05 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x05) + data = PyString_FromString(operation[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_memory_error_syndrome(u32 code) +{ + PyObject *data; + + if(code == 0x00000000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("0x%08x", code); + return data; +} + +static PyObject *dmi_32bit_memory_error_address(u32 code) +{ + PyObject *data; + + if(code == 0x80000000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("0x%08x", code); + return data; } /******************************************************************************* ** 3.3.20 Memory Array Mapped Address (Type 19) */ -static PyObject *dmi_mapped_address_size(u32 code) { - PyObject *data; - if(code==0) data = PyString_FromString("Invalid"); - else if((code&0x000FFFFF)==0) data = PyString_FromFormat("%i GB", code>>20); - else if((code&0x000003FF)==0) data = PyString_FromFormat("%i MB", code>>10); - else data = PyString_FromFormat("%i kB", code); - return data; +static PyObject *dmi_mapped_address_size(u32 code) +{ + PyObject *data; + + if(code == 0) + data = PyString_FromString("Invalid"); + else if((code & 0x000FFFFF) == 0) + data = PyString_FromFormat("%i GB", code >> 20); + else if((code & 0x000003FF) == 0) + data = PyString_FromFormat("%i MB", code >> 10); + else + data = PyString_FromFormat("%i kB", code); + return data; } /******************************************************************************* ** 3.3.21 Memory Device Mapped Address (Type 20) */ -static PyObject *dmi_mapped_address_row_position(u8 code) { - PyObject *data; - if(code==0) data = OUT_OF_SPEC; - else if(code==0xFF) data = PyString_FromString("Unknown"); - else data = PyInt_FromLong(code); - return data; +static PyObject *dmi_mapped_address_row_position(u8 code) +{ + PyObject *data; + + if(code == 0) + data = OUT_OF_SPEC; + else if(code == 0xFF) + data = PyString_FromString("Unknown"); + else + data = PyInt_FromLong(code); + return data; } -static PyObject *dmi_mapped_address_interleave_position(u8 code) { - PyObject *data; - if(code!=0) { - data = PyDict_New(); - PyDict_SetItemString(data, "Interleave Position", (code==0xFF)?PyString_FromString("Unknown"):PyInt_FromLong(code)); - } else data = Py_None; - return data; +static PyObject *dmi_mapped_address_interleave_position(u8 code) +{ + PyObject *data; + + if(code != 0) { + data = PyDict_New(); + PyDict_SetItemString(data, "Interleave Position", + (code == + 0xFF) ? PyString_FromString("Unknown") : + PyInt_FromLong(code)); + } else + data = Py_None; + return data; } -static PyObject *dmi_mapped_address_interleaved_data_depth(u8 code) { - PyObject *data; - if(code!=0) { - data = PyDict_New(); - PyDict_SetItemString(data, "Interleave Data Depth", (code==0xFF)?PyString_FromString("Unknown"):PyInt_FromLong(code)); - } else data = Py_None; - return data; +static PyObject *dmi_mapped_address_interleaved_data_depth(u8 code) +{ + PyObject *data; + + if(code != 0) { + data = PyDict_New(); + PyDict_SetItemString(data, "Interleave Data Depth", + (code == + 0xFF) ? PyString_FromString("Unknown") : + PyInt_FromLong(code)); + } else + data = Py_None; + return data; } /******************************************************************************* ** 3.3.22 Built-in Pointing Device (Type 21) */ -static PyObject *dmi_pointing_device_type(u8 code) { - /* 3.3.22.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Mouse", - "Track Ball", - "Track Point", - "Glide Point", - "Touch Pad", - "Touch Screen", - "Optical Sensor" /* 0x09 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x09) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_pointing_device_interface(u8 code) { - /* 3.3.22.2 */ - static const char *interface[]={ - "Other", /* 0x01 */ - "Unknown", - "Serial", - "PS/2", - "Infrared", - "HIP-HIL", - "Bus Mouse", - "ADB (Apple Desktop Bus)" /* 0x08 */ - }; - static const char *interface_0xA0[]={ - "Bus Mouse DB-9", /* 0xA0 */ - "Bus Mouse Micro DIN", - "USB" /* 0xA2 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x08) data = PyString_FromString(interface[code-0x01]); - else if(code>=0xA0 && code<=0xA2) data = PyString_FromString(interface_0xA0[code-0xA0]); - else data = OUT_OF_SPEC; - return data; +static PyObject *dmi_pointing_device_type(u8 code) +{ + /* 3.3.22.1 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "Mouse", + "Track Ball", + "Track Point", + "Glide Point", + "Touch Pad", + "Touch Screen", + "Optical Sensor" /* 0x09 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x09) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_pointing_device_interface(u8 code) +{ + /* 3.3.22.2 */ + static const char *interface[] = { + "Other", /* 0x01 */ + "Unknown", + "Serial", + "PS/2", + "Infrared", + "HIP-HIL", + "Bus Mouse", + "ADB (Apple Desktop Bus)" /* 0x08 */ + }; + static const char *interface_0xA0[] = { + "Bus Mouse DB-9", /* 0xA0 */ + "Bus Mouse Micro DIN", + "USB" /* 0xA2 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x08) + data = PyString_FromString(interface[code - 0x01]); + else if(code >= 0xA0 && code <= 0xA2) + data = PyString_FromString(interface_0xA0[code - 0xA0]); + else + data = OUT_OF_SPEC; + return data; } /******************************************************************************* ** 3.3.23 Portable Battery (Type 22) */ -static PyObject *dmi_battery_chemistry(u8 code) { - /* 3.3.23.1 */ - static const char *chemistry[]={ - "Other", /* 0x01 */ - "Unknown", - "Lead Acid", - "Nickel Cadmium", - "Nickel Metal Hydride", - "Lithium Ion", - "Zinc Air", - "Lithium Polymer" /* 0x08 */ - }; - PyObject *data; +static PyObject *dmi_battery_chemistry(u8 code) +{ + /* 3.3.23.1 */ + static const char *chemistry[] = { + "Other", /* 0x01 */ + "Unknown", + "Lead Acid", + "Nickel Cadmium", + "Nickel Metal Hydride", + "Lithium Ion", + "Zinc Air", + "Lithium Polymer" /* 0x08 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x08) + data = PyString_FromString(chemistry[code - 0x01]); + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_battery_capacity(u16 code, u8 multiplier) +{ + PyObject *data; - if(code>=0x01 && code<=0x08) data = PyString_FromString(chemistry[code-0x01]); - data = OUT_OF_SPEC; - return data; + if(code == 0) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%i mWh", code * multiplier); + return data; } -static PyObject *dmi_battery_capacity(u16 code, u8 multiplier) { - PyObject *data; - if(code==0) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%i mWh", code*multiplier); - return data; -} +static PyObject *dmi_battery_voltage(u16 code) +{ + PyObject *data; -static PyObject *dmi_battery_voltage(u16 code) { - PyObject *data; - if(code==0) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%i mV", code); - return data; + if(code == 0) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%i mV", code); + return data; } -static PyObject *dmi_battery_maximum_error(u8 code) { - PyObject *data; - if(code==0xFF) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%i%%", code); - return data; +static PyObject *dmi_battery_maximum_error(u8 code) +{ + PyObject *data; + + if(code == 0xFF) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%i%%", code); + return data; } /******************************************************************************* ** 3.3.24 System Reset (Type 23) */ -static PyObject *dmi_system_reset_boot_option(u8 code) { - static const char *option[]={ - "Operating System", /* 0x1 */ - "System Utilities", - "Do Not Reboot" /* 0x3 */ - }; - PyObject *data; +static PyObject *dmi_system_reset_boot_option(u8 code) +{ + static const char *option[] = { + "Operating System", /* 0x1 */ + "System Utilities", + "Do Not Reboot" /* 0x3 */ + }; + PyObject *data; - if(code>=0x1) data = PyString_FromString(option[code-0x1]); - else data = OUT_OF_SPEC; - return data; + if(code >= 0x1) + data = PyString_FromString(option[code - 0x1]); + else + data = OUT_OF_SPEC; + return data; } -static PyObject *dmi_system_reset_count(u16 code) { - PyObject *data; - if(code==0xFFFF) data = PyString_FromString("Unknown"); - else data = PyInt_FromLong(code); - return data; +static PyObject *dmi_system_reset_count(u16 code) +{ + PyObject *data; + + if(code == 0xFFFF) + data = PyString_FromString("Unknown"); + else + data = PyInt_FromLong(code); + return data; } -static PyObject *dmi_system_reset_timer(u16 code) { - PyObject *data; - if(code==0xFFFF) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%i min", code); - return data; +static PyObject *dmi_system_reset_timer(u16 code) +{ + PyObject *data; + + if(code == 0xFFFF) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%i min", code); + return data; } /******************************************************************************* * 3.3.25 Hardware Security (Type 24) */ -static PyObject *dmi_hardware_security_status(u8 code) { - static const char *status[]={ - "Disabled", /* 0x00 */ - "Enabled", - "Not Implemented", - "Unknown" /* 0x03 */ - }; +static PyObject *dmi_hardware_security_status(u8 code) +{ + static const char *status[] = { + "Disabled", /* 0x00 */ + "Enabled", + "Not Implemented", + "Unknown" /* 0x03 */ + }; - return PyString_FromString(status[code]); + return PyString_FromString(status[code]); } /******************************************************************************* ** 3.3.26 System Power Controls (Type 25) */ -static PyObject *dmi_power_controls_power_on(const u8 *p) { - /* 3.3.26.1 */ - PyObject *data = PyList_New(5); - - PyList_SET_ITEM(data, 0, dmi_bcd_range(p[0], 0x01, 0x12)?PyString_FromFormat(" %02x", p[0]):PyString_FromString(" *")); - PyList_SET_ITEM(data, 1, dmi_bcd_range(p[1], 0x01, 0x31)?PyString_FromFormat("-%02x", p[1]):PyString_FromString("-*")); - PyList_SET_ITEM(data, 2, dmi_bcd_range(p[2], 0x00, 0x23)?PyString_FromFormat(" %02x", p[2]):PyString_FromString(" *")); - PyList_SET_ITEM(data, 3, dmi_bcd_range(p[3], 0x00, 0x59)?PyString_FromFormat(":%02x", p[3]):PyString_FromString(":*")); - PyList_SET_ITEM(data, 4, dmi_bcd_range(p[4], 0x00, 0x59)?PyString_FromFormat(":%02x", p[4]):PyString_FromString(":*")); - - return data; +static PyObject *dmi_power_controls_power_on(const u8 * p) +{ + /* 3.3.26.1 */ + PyObject *data = PyList_New(5); + + PyList_SET_ITEM(data, 0, + dmi_bcd_range(p[0], 0x01, 0x12) ? PyString_FromFormat(" %02x", + p[0]) : + PyString_FromString(" *")); + PyList_SET_ITEM(data, 1, + dmi_bcd_range(p[1], 0x01, 0x31) ? PyString_FromFormat("-%02x", + p[1]) : + PyString_FromString("-*")); + PyList_SET_ITEM(data, 2, + dmi_bcd_range(p[2], 0x00, 0x23) ? PyString_FromFormat(" %02x", + p[2]) : + PyString_FromString(" *")); + PyList_SET_ITEM(data, 3, + dmi_bcd_range(p[3], 0x00, 0x59) ? PyString_FromFormat(":%02x", + p[3]) : + PyString_FromString(":*")); + PyList_SET_ITEM(data, 4, + dmi_bcd_range(p[4], 0x00, 0x59) ? PyString_FromFormat(":%02x", + p[4]) : + PyString_FromString(":*")); + + return data; } /******************************************************************************* * 3.3.27 Voltage Probe (Type 26) */ -static PyObject *dmi_voltage_probe_location(u8 code) { - /* 3.3.27.1 */ - static const char *location[]={ - "Other", /* 0x01 */ - "Unknown", - "Processor", - "Disk", - "Peripheral Bay", - "System Management Module", - "Motherboard", - "Memory Module", - "Processor Module", - "Power Unit", - "Add-in Card" /* 0x0B */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x0B) data = PyString_FromString(location[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_probe_status(u8 code) { - /* 3.3.27.1 */ - static const char *status[]={ - "Other", /* 0x01 */ - "Unknown", - "OK", - "Non-critical", - "Critical", - "Non-recoverable" /* 0x06 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x06) data = PyString_FromString(status[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_voltage_probe_value(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.3f V", (float)(i16)code/1000); - return data; -} - -static PyObject *dmi_voltage_probe_resolution(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.1f mV", (float)code/10); - return data; -} - -static PyObject *dmi_probe_accuracy(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.2f%%", (float)code/100); - return data; +static PyObject *dmi_voltage_probe_location(u8 code) +{ + /* 3.3.27.1 */ + static const char *location[] = { + "Other", /* 0x01 */ + "Unknown", + "Processor", + "Disk", + "Peripheral Bay", + "System Management Module", + "Motherboard", + "Memory Module", + "Processor Module", + "Power Unit", + "Add-in Card" /* 0x0B */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x0B) + data = PyString_FromString(location[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_probe_status(u8 code) +{ + /* 3.3.27.1 */ + static const char *status[] = { + "Other", /* 0x01 */ + "Unknown", + "OK", + "Non-critical", + "Critical", + "Non-recoverable" /* 0x06 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x06) + data = PyString_FromString(status[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_voltage_probe_value(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.3f V", (float)(i16) code / 1000); + return data; +} + +static PyObject *dmi_voltage_probe_resolution(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.1f mV", (float)code / 10); + return data; +} + +static PyObject *dmi_probe_accuracy(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.2f%%", (float)code / 100); + return data; } /******************************************************************************* ** 3.3.28 Cooling Device (Type 27) */ -static PyObject *dmi_cooling_device_type(u8 code) { - /* 3.3.28.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Fan", - "Centrifugal Blower", - "Chip Fan", - "Cabinet Fan", - "Power Supply Fan", - "Heat Pipe", - "Integrated Refrigeration" /* 0x09 */ - }; - static const char *type_0x10[]={ - "Active Cooling", /* 0x10, master.mif says 32 */ - "Passive Cooling" /* 0x11, master.mif says 33 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x09) data = PyString_FromString(type[code-0x01]); - else if(code>=0x10 && code<=0x11) data = PyString_FromString(type_0x10[code-0x10]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_cooling_device_speed(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown Or Non-rotating"); - else data = PyString_FromFormat("%i rpm", code); - return data; +static PyObject *dmi_cooling_device_type(u8 code) +{ + /* 3.3.28.1 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "Fan", + "Centrifugal Blower", + "Chip Fan", + "Cabinet Fan", + "Power Supply Fan", + "Heat Pipe", + "Integrated Refrigeration" /* 0x09 */ + }; + static const char *type_0x10[] = { + "Active Cooling", /* 0x10, master.mif says 32 */ + "Passive Cooling" /* 0x11, master.mif says 33 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x09) + data = PyString_FromString(type[code - 0x01]); + else if(code >= 0x10 && code <= 0x11) + data = PyString_FromString(type_0x10[code - 0x10]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_cooling_device_speed(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown Or Non-rotating"); + else + data = PyString_FromFormat("%i rpm", code); + return data; } /******************************************************************************* ** 3.3.29 Temperature Probe (Type 28) */ -static PyObject *dmi_temperature_probe_location(u8 code) { - /* 3.3.29.1 */ - static const char *location[]={ - "Other", /* 0x01 */ - "Unknown", - "Processor", - "Disk", - "Peripheral Bay", - "System Management Module", /* master.mif says SMB Master */ - "Motherboard", - "Memory Module", - "Processor Module", - "Power Unit", - "Add-in Card", - "Front Panel Board", - "Back Panel Board", - "Power System Board", - "Drive Back Plane" /* 0x0F */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x0F) data = PyString_FromString(location[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_temperature_probe_value(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.1f deg C", (float)(i16)code/10); - return data; -} - -static PyObject *dmi_temperature_probe_resolution(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.3f deg C", (float)code/1000); - return data; +static PyObject *dmi_temperature_probe_location(u8 code) +{ + /* 3.3.29.1 */ + static const char *location[] = { + "Other", /* 0x01 */ + "Unknown", + "Processor", + "Disk", + "Peripheral Bay", + "System Management Module", /* master.mif says SMB Master */ + "Motherboard", + "Memory Module", + "Processor Module", + "Power Unit", + "Add-in Card", + "Front Panel Board", + "Back Panel Board", + "Power System Board", + "Drive Back Plane" /* 0x0F */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x0F) + data = PyString_FromString(location[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_temperature_probe_value(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.1f deg C", (float)(i16) code / 10); + return data; +} + +static PyObject *dmi_temperature_probe_resolution(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.3f deg C", (float)code / 1000); + return data; } /******************************************************************************* ** 3.3.30 Electrical Current Probe (Type 29) */ -static PyObject *dmi_current_probe_value(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.3f A", (float)(i16)code/1000); - return data; +static PyObject *dmi_current_probe_value(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.3f A", (float)(i16) code / 1000); + return data; } -static PyObject *dmi_current_probe_resolution(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.1f mA", (float)code/10); - return data; +static PyObject *dmi_current_probe_resolution(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.1f mA", (float)code / 10); + return data; } /******************************************************************************* ** 3.3.33 System Boot Information (Type 32) */ -static PyObject *dmi_system_boot_status(u8 code) { - static const char *status[]={ - "No errors detected", /* 0 */ - "No bootable media", - "Operating system failed to load", - "Firmware-detected hardware failure", - "Operating system-detected hardware failure", - "User-requested boot", - "System security violation", - "Previously-requested image", - "System watchdog timer expired" /* 8 */ - }; - PyObject *data; - - if(code<=8) data = PyString_FromString(status[code]); - else if(code>=128 && code<=191) data = PyString_FromString("OEM-specific"); - else if(code>=192) data = PyString_FromString("Product-specific"); - else data = OUT_OF_SPEC; - return data; +static PyObject *dmi_system_boot_status(u8 code) +{ + static const char *status[] = { + "No errors detected", /* 0 */ + "No bootable media", + "Operating system failed to load", + "Firmware-detected hardware failure", + "Operating system-detected hardware failure", + "User-requested boot", + "System security violation", + "Previously-requested image", + "System watchdog timer expired" /* 8 */ + }; + PyObject *data; + + if(code <= 8) + data = PyString_FromString(status[code]); + else if(code >= 128 && code <= 191) + data = PyString_FromString("OEM-specific"); + else if(code >= 192) + data = PyString_FromString("Product-specific"); + else + data = OUT_OF_SPEC; + return data; } /******************************************************************************* ** 3.3.34 64-bit Memory Error Information (Type 33) */ -static PyObject *dmi_64bit_memory_error_address(u64 code) { - PyObject *data; - if(code.h==0x80000000 && code.l==0x00000000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("0x%08x%08x", code.h, code.l); - return data; +static PyObject *dmi_64bit_memory_error_address(u64 code) +{ + PyObject *data; + + if(code.h == 0x80000000 && code.l == 0x00000000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("0x%08x%08x", code.h, code.l); + return data; } /******************************************************************************* ** 3.3.35 Management Device (Type 34) */ -static PyObject *dmi_management_device_type(u8 code) { - /* 3.3.35.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "LM75", - "LM78", - "LM79", - "LM80", - "LM81", - "ADM9240", - "DS1780", - "MAX1617", - "GL518SM", - "W83781D", - "HT82H791" /* 0x0D */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x0D) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_management_device_address_type(u8 code) { - /* 3.3.35.2 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "I/O Port", - "Memory", - "SMBus" /* 0x05 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x05) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; +static PyObject *dmi_management_device_type(u8 code) +{ + /* 3.3.35.1 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "LM75", + "LM78", + "LM79", + "LM80", + "LM81", + "ADM9240", + "DS1780", + "MAX1617", + "GL518SM", + "W83781D", + "HT82H791" /* 0x0D */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x0D) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_management_device_address_type(u8 code) +{ + /* 3.3.35.2 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "I/O Port", + "Memory", + "SMBus" /* 0x05 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x05) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; } /******************************************************************************* ** 3.3.38 Memory Channel (Type 37) */ -static PyObject *dmi_memory_channel_type(u8 code) { - /* 3.3.38.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "RamBus", - "SyncLink" /* 0x04 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x04) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_memory_channel_devices(u8 count, const u8 *p) { - PyObject *data = PyDict_New(); - PyObject *subdata, *val; - int i; +static PyObject *dmi_memory_channel_type(u8 code) +{ + /* 3.3.38.1 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "RamBus", + "SyncLink" /* 0x04 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x04) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_memory_channel_devices(u8 count, const u8 * p) +{ + PyObject *data = PyDict_New(); + PyObject *subdata, *val; + int i; - for(i=1; i<=count; i++) { - subdata = PyList_New(2); + for(i = 1; i <= count; i++) { + subdata = PyList_New(2); - val = PyString_FromFormat("Load: %i", p[3*i]); - PyList_SET_ITEM(subdata, 0, val); - Py_DECREF(val); + val = PyString_FromFormat("Load: %i", p[3 * i]); + PyList_SET_ITEM(subdata, 0, val); + Py_DECREF(val); - val = PyString_FromFormat("Handle: 0x%04x", WORD(p+3*i+1)); - PyList_SET_ITEM(subdata, 1, val); - Py_DECREF(val); + val = PyString_FromFormat("Handle: 0x%04x", WORD(p + 3 * i + 1)); + PyList_SET_ITEM(subdata, 1, val); + Py_DECREF(val); - PyDict_SetItem(data, PyInt_FromLong(i), subdata); - Py_DECREF(subdata); - } - return data; + PyDict_SetItem(data, PyInt_FromLong(i), subdata); + Py_DECREF(subdata); + } + return data; } /******************************************************************************* ** 3.3.39 IPMI Device Information (Type 38) */ -static PyObject *dmi_ipmi_interface_type(u8 code) { - /* 3.3.39.1 and IPMI 2.0, appendix C1, table C1-2 */ - static const char *type[]={ - "Unknown", /* 0x00 */ - "KCS (Keyboard Control Style)", - "SMIC (Server Management Interface Chip)", - "BT (Block Transfer)", - "SSIF (SMBus System Interface)" /* 0x04 */ - }; - PyObject *data; - - if(code<=0x04) data = PyString_FromString(type[code]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_ipmi_base_address(u8 type, const u8 *p, u8 lsb) { - PyObject *data; - if(type==0x04) /* SSIF */ { - data = PyString_FromFormat("0x%02x (SMBus)", (*p)>>1); - } else { - u64 address=QWORD(p); - data = PyString_FromFormat("0x%08x%08x (%s)", address.h, (address.l&~1)|lsb, address.l&1?"I/O":"Memory-mapped"); - } - return data; -} - -static PyObject *dmi_ipmi_register_spacing(u8 code) { - /* IPMI 2.0, appendix C1, table C1-1 */ - static const char *spacing[]={ - "Successive Byte Boundaries", /* 0x00 */ - "32-bit Boundaries", - "16-byte Boundaries" /* 0x02 */ - }; - PyObject *data; - - if(code<=0x02) return data = PyString_FromString(spacing[code]); - return data = OUT_OF_SPEC; +static PyObject *dmi_ipmi_interface_type(u8 code) +{ + /* 3.3.39.1 and IPMI 2.0, appendix C1, table C1-2 */ + static const char *type[] = { + "Unknown", /* 0x00 */ + "KCS (Keyboard Control Style)", + "SMIC (Server Management Interface Chip)", + "BT (Block Transfer)", + "SSIF (SMBus System Interface)" /* 0x04 */ + }; + PyObject *data; + + if(code <= 0x04) + data = PyString_FromString(type[code]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_ipmi_base_address(u8 type, const u8 * p, u8 lsb) +{ + PyObject *data; + + if(type == 0x04) { /* SSIF */ + data = PyString_FromFormat("0x%02x (SMBus)", (*p) >> 1); + } else { + u64 address = QWORD(p); + + data = + PyString_FromFormat("0x%08x%08x (%s)", address.h, (address.l & ~1) | lsb, + address.l & 1 ? "I/O" : "Memory-mapped"); + } + return data; +} + +static PyObject *dmi_ipmi_register_spacing(u8 code) +{ + /* IPMI 2.0, appendix C1, table C1-1 */ + static const char *spacing[] = { + "Successive Byte Boundaries", /* 0x00 */ + "32-bit Boundaries", + "16-byte Boundaries" /* 0x02 */ + }; + PyObject *data; + + if(code <= 0x02) + return data = PyString_FromString(spacing[code]); + return data = OUT_OF_SPEC; } /******************************************************************************* ** 3.3.40 System Power Supply (Type 39) */ -static PyObject *dmi_power_supply_power(u16 code) { - PyObject *data; - if(code==0x8000) data = PyString_FromString("Unknown"); - else data = PyString_FromFormat("%.3f W", (float)code/1000); - return data; -} - -static PyObject *dmi_power_supply_type(u8 code) { - /* 3.3.40.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Linear", - "Switching", - "Battery", - "UPS", - "Converter", - "Regulator" /* 0x08 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x08) data = PyString_FromString(type[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_power_supply_status(u8 code) { - /* 3.3.40.1 */ - static const char *status[]={ - "Other", /* 0x01 */ - "Unknown", - "OK", - "Non-critical", - "Critical" /* 0x05 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x05) data = PyString_FromString(status[code-0x01]); - else data = OUT_OF_SPEC; - return data; -} - -static PyObject *dmi_power_supply_range_switching(u8 code) { - /* 3.3.40.1 */ - static const char *switching[]={ - "Other", /* 0x01 */ - "Unknown", - "Manual", - "Auto-switch", - "Wide Range", - "N/A" /* 0x06 */ - }; - PyObject *data; - - if(code>=0x01 && code<=0x06) data = PyString_FromString(switching[code-0x01]); - else data = OUT_OF_SPEC; - return data; +static PyObject *dmi_power_supply_power(u16 code) +{ + PyObject *data; + + if(code == 0x8000) + data = PyString_FromString("Unknown"); + else + data = PyString_FromFormat("%.3f W", (float)code / 1000); + return data; +} + +static PyObject *dmi_power_supply_type(u8 code) +{ + /* 3.3.40.1 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "Linear", + "Switching", + "Battery", + "UPS", + "Converter", + "Regulator" /* 0x08 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x08) + data = PyString_FromString(type[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_power_supply_status(u8 code) +{ + /* 3.3.40.1 */ + static const char *status[] = { + "Other", /* 0x01 */ + "Unknown", + "OK", + "Non-critical", + "Critical" /* 0x05 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x05) + data = PyString_FromString(status[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; +} + +static PyObject *dmi_power_supply_range_switching(u8 code) +{ + /* 3.3.40.1 */ + static const char *switching[] = { + "Other", /* 0x01 */ + "Unknown", + "Manual", + "Auto-switch", + "Wide Range", + "N/A" /* 0x06 */ + }; + PyObject *data; + + if(code >= 0x01 && code <= 0x06) + data = PyString_FromString(switching[code - 0x01]); + else + data = OUT_OF_SPEC; + return data; } /* @@ -2803,1638 +3243,1751 @@ static PyObject *dmi_power_supply_range_switching(u8 code) { ** whether it's worth the effort. */ -static PyObject *dmi_additional_info(const struct dmi_header *h, const char *prefix) { - u8 *p = h->data + 4; - u8 count = *p++; - u8 length; - int i, offset = 5; - PyObject *data = PyList_New(count); - - for(i=0; ilength < offset + 1) break; - length = p[0x00]; - if (length < 0x05 || h->length < offset + length) break; - - PyDict_SetItemString(subdata, - "Referenced Handle", - PyString_FromFormat("0x%04x", WORD(p + 0x01)) - ); - - PyDict_SetItemString(subdata, - "Referenced Offset", - PyString_FromFormat("0x%02x", p[0x03]) - ); - - PyDict_SetItemString(subdata, - "String", - dmi_string_py(h, p[0x04]) - ); - - PyObject *_val; - switch (length - 0x05) { - case 1: - _val = PyString_FromFormat("0x%02x", p[0x05]); - break; - case 2: - _val = PyString_FromFormat("0x%04x", WORD(p + 0x05)); - break; - case 4: - _val = PyString_FromFormat("0x%08x", DWORD(p + 0x05)); - break; - default: - _val = PyString_FromString("Unexpected size"); - break; - } - PyDict_SetItemString(subdata, "Value", _val); - Py_DECREF(_val); - - p += length; - offset += length; - PyList_SET_ITEM(data, i, subdata); - } - return data; +static PyObject *dmi_additional_info(const struct dmi_header *h, const char *prefix) +{ + u8 *p = h->data + 4; + u8 count = *p++; + u8 length; + int i, offset = 5; + PyObject *data = PyList_New(count); + + for(i = 0; i < count; i++) { + PyObject *subdata = PyDict_New(); + + /* Check for short entries */ + if(h->length < offset + 1) + break; + length = p[0x00]; + if(length < 0x05 || h->length < offset + length) + break; + + PyDict_SetItemString(subdata, + "Referenced Handle", + PyString_FromFormat("0x%04x", WORD(p + 0x01)) + ); + + PyDict_SetItemString(subdata, + "Referenced Offset", PyString_FromFormat("0x%02x", p[0x03]) + ); + + PyDict_SetItemString(subdata, "String", dmi_string_py(h, p[0x04]) + ); + + PyObject *_val; + + switch (length - 0x05) { + case 1: + _val = PyString_FromFormat("0x%02x", p[0x05]); + break; + case 2: + _val = PyString_FromFormat("0x%04x", WORD(p + 0x05)); + break; + case 4: + _val = PyString_FromFormat("0x%08x", DWORD(p + 0x05)); + break; + default: + _val = PyString_FromString("Unexpected size"); + break; + } + PyDict_SetItemString(subdata, "Value", _val); + Py_DECREF(_val); + + p += length; + offset += length; + PyList_SET_ITEM(data, i, subdata); + } + return data; } /******************************************************************************* ** Main */ -PyObject* dmi_decode(struct dmi_header *h, u16 ver) { - - const u8 *data = h->data; - - //. 0xF1 --> 0xF100 - //int minor = h->type<<8; - char _[2048]; bzero(_, 2048); - //dmi_codes_major *dmiMajor = (dmi_codes_major *)&dmiCodesMajor[map_maj[h->type]]; - dmi_codes_major *dmiMajor = (dmi_codes_major *)&dmiCodesMajor[h->type]; - PyObject *pylist = PyDict_New(); - PyDict_SetItemString(pylist, "id", PyString_FromString(dmiMajor->id)); - PyDict_SetItemString(pylist, "desc", PyString_FromString(dmiMajor->desc)); - PyObject *_val; //. A Temporary pointer (value) - PyObject *_key; //. Another temporary pointer (key) - PyObject *caseData = PyDict_New(); - - switch(h->type) { - - case 0: /* 3.3.1 BIOS Information */ - - if(h->length<0x12) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Vendor", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Release Date", _val); - Py_DECREF(_val); - - /* - * On IA-64, the BIOS base address will read 0 because - * there is no BIOS. Skip the base address and the - * runtime size in this case. - */ - if(WORD(data+0x06)!=0) { - _val = PyString_FromFormat("0x%04x0", WORD(data+0x06)); - PyDict_SetItemString(caseData, "Address", _val); - Py_DECREF(_val); - - _val = dmi_bios_runtime_size((0x10000-WORD(data+0x06))<<4); - PyDict_SetItemString(caseData, "Runtime Size", _val); - Py_DECREF(_val); - } - - _val = PyString_FromFormat("%i kB", (data[0x09]+1)<<6); - PyDict_SetItemString(caseData, "ROM Size", _val); - Py_DECREF(_val); - - _val = dmi_bios_characteristics(QWORD(data+0x0A)); - PyDict_SetItemString(caseData, "Characteristics", _val); - Py_DECREF(_val); - - if(h->length<0x13) break; - _val = dmi_bios_characteristics_x1(data[0x12]); - PyDict_SetItemString(caseData, "Characteristics x1", _val); - Py_DECREF(_val); - - if(h->length<0x14) break; - _val = dmi_bios_characteristics_x2(data[0x13]); - PyDict_SetItemString(caseData, "Characteristics x2", _val); - Py_DECREF(_val); - - if(h->length<0x18) break; - - if(data[0x14]!=0xFF && data[0x15]!=0xFF) { - _val = PyString_FromFormat("%i.%i", data[0x14], data[0x15]); - PyDict_SetItemString(caseData, "BIOS Revision", _val); - Py_DECREF(_val); - } - - if(data[0x16]!=0xFF && data[0x17]!=0xFF) { - _val = PyString_FromFormat("%i.%i", data[0x16], data[0x17]); - PyDict_SetItemString(caseData, "Firmware Revision", _val); - Py_DECREF(_val); - } - - break; - - case 1: /* 3.3.2 System Information */ - - if(h->length<0x08) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Product Name", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); - - if(h->length<0x19) break; - _val = dmi_system_uuid_py(data+0x08, ver); - PyDict_SetItemString(caseData, "UUID", _val); - Py_DECREF(_val); - - _val = dmi_system_wake_up_type(data[0x18]); - PyDict_SetItemString(caseData, "Wake-Up Type", _val); - Py_DECREF(_val); - - if(h->length<0x1B) break; - _val = dmi_string_py(h, data[0x19]); - PyDict_SetItemString(caseData, "SKU Number", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x1A]); - PyDict_SetItemString(caseData, "Family", _val); - Py_DECREF(_val); - break; - - case 2: /* 3.3.3 Base Board Information */ - - if(h->length<0x08) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Product Name", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); - - if(h->length<0x0F) break; - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - - _val = dmi_base_board_features(data[0x09]); - PyDict_SetItemString(caseData, "Features", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x0A]); - PyDict_SetItemString(caseData, "Location In Chassis", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data+0x0B)); - PyDict_SetItemString(caseData, "Chassis Handle", _val); - Py_DECREF(_val); - - _val = dmi_base_board_type(data[0x0D]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - if(h->length<0x0F+data[0x0E]*sizeof(u16)) break; - _val = dmi_base_board_handles(data[0x0E], data+0x0F); - PyDict_SetItemString(caseData, "Type ???", _val); - Py_DECREF(_val); - break; - - case 3: /* 3.3.4 Chassis Information */ - - if(h->length<0x09) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_chassis_type_py(data[0x05]&0x7F); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_chassis_lock(data[0x05]>>7); - PyDict_SetItemString(caseData, "Lock", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - - if(h->length<0x0D) break; - _val = dmi_chassis_state(data[0x09]); - PyDict_SetItemString(caseData, "Boot-Up State", _val); - Py_DECREF(_val); - - _val = dmi_chassis_state(data[0x0A]); - PyDict_SetItemString(caseData, "Power Supply State", _val); - Py_DECREF(_val); - - _val = dmi_chassis_state(data[0x0B]); - PyDict_SetItemString(caseData, "Thermal State", _val); - Py_DECREF(_val); - - _val = PyString_FromString(dmi_chassis_security_status(data[0x0C])); - PyDict_SetItemString(caseData, "Security Status", _val); - Py_DECREF(_val); - - if(h->length<0x11) break; - _val = PyString_FromFormat("0x%08x", DWORD(data+0x0D)); - PyDict_SetItemString(caseData, "OEM Information", _val); - Py_DECREF(_val); - - if(h->length<0x13) break; - _val = dmi_chassis_height(data[0x11]); - PyDict_SetItemString(caseData, "Height", _val); - Py_DECREF(_val); - - _val = dmi_chassis_power_cords(data[0x12]); - PyDict_SetItemString(caseData, "Number Of Power Cords", _val); - Py_DECREF(_val); - - if(h->length < 0x15) break; - if(h->length<0x15+data[0x13]*data[0x14]) break; - _val = dmi_chassis_elements(data[0x13], data[0x14], data+0x15); - PyDict_SetItemString(caseData, "Elements", _val); - Py_DECREF(_val); - - break; - - - case 4: /* 3.3.5 Processor Information */ - - if(h->length<0x1A) break; - - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Socket Designation", _val); - Py_DECREF(_val); - - _val = dmi_processor_type(data[0x05]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = PyString_FromString(dmi_processor_family(h)); - PyDict_SetItemString(caseData, "Family", _val); - Py_DECREF(_val); - - _val = dmi_processor_id(data[0x06], data+8, dmi_string(h, data[0x10])); - PyDict_SetItemString(_val, "Vendor", dmi_string_py(h, data[0x07])); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x10]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - - _val = dmi_processor_voltage(data[0x11]); - PyDict_SetItemString(caseData, "Voltage", _val); - Py_DECREF(_val); - - _val = dmi_processor_frequency_py(data+0x12); - PyDict_SetItemString(caseData, "External Clock", _val); - Py_DECREF(_val); - - _val = dmi_processor_frequency_py(data+0x14); - PyDict_SetItemString(caseData, "Max Speed", _val); - Py_DECREF(_val); - - _val = dmi_processor_frequency_py(data+0x16); - PyDict_SetItemString(caseData, "Current Speed", _val); - Py_DECREF(_val); - - if(data[0x18]&(1<<6)) { - _val = PyString_FromFormat("Populated:%s", dmi_processor_status(data[0x18]&0x07)); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - } else { - _val = PyString_FromString("Populated:No"); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - } - _val = dmi_processor_upgrade(data[0x19]); - PyDict_SetItemString(caseData, "Upgrade", _val); - Py_DECREF(_val); - - if(h->length<0x20) break; - _val = dmi_processor_cache(WORD(data+0x1A), "L1", ver); - PyDict_SetItemString(caseData, "L1 Cache Handle", _val); - Py_DECREF(_val); - - _val = dmi_processor_cache(WORD(data+0x1C), "L2", ver); - PyDict_SetItemString(caseData, "L2 Cache Handle", _val); - Py_DECREF(_val); - - _val = dmi_processor_cache(WORD(data+0x1E), "L3", ver); - PyDict_SetItemString(caseData, "L3 Cache Handle", _val); - Py_DECREF(_val); - - if(h->length<0x23) break; - _val = dmi_string_py(h, data[0x20]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x21]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x22]); - PyDict_SetItemString(caseData, "Part Number", _val); - Py_DECREF(_val); - - if(h->length<0x28) break; - if(data[0x23]!=0) { - _val = PyString_FromFormat("%i", data[0x23]); - PyDict_SetItemString(caseData, "Core Count", _val); - Py_DECREF(_val); - } - - if(data[0x24]!=0) { - _val = PyString_FromFormat("%i", data[0x24]); - PyDict_SetItemString(caseData, "Core Enabled", _val); - Py_DECREF(_val); - } - - if(data[0x25]!=0) { - _val = PyString_FromFormat("%i", data[0x25]); - PyDict_SetItemString(caseData, "Thread Count", _val); - Py_DECREF(_val); - } - - _val = dmi_processor_characteristics(WORD(data+0x26)); - PyDict_SetItemString(caseData, "Characteristics", _val); - Py_DECREF(_val); - break; - - case 5: /* 3.3.6 Memory Controller Information */ - - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - - if(h->length<0x0F) break; - _val = dmi_memory_controller_ed_method(data[0x04]); - PyDict_SetItemString(caseData, "Error Detecting Method", _val); - Py_DECREF(_val); - - _val = dmi_memory_controller_ec_capabilities(data[0x05]); - PyDict_SetItemString(caseData, "Error Correcting Capabilities", _val); - Py_DECREF(_val); - - _val = dmi_memory_controller_interleave(data[0x06]); - PyDict_SetItemString(caseData, "Supported Interleave", _val); - Py_DECREF(_val); - - _val = dmi_memory_controller_interleave(data[0x07]); - PyDict_SetItemString(caseData, "Current Interleave", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%i MB", 1<length<0x0F+data[0x0E]*sizeof(u16)) break; - _val = dmi_memory_controller_slots(data[0x0E], data+0x0F); - PyDict_SetItemString(caseData, "Associated Memory Sluts", _val); - Py_DECREF(_val); - - if(h->length<0x10+data[0x0E]*sizeof(u16)) break; - _val = dmi_memory_controller_ec_capabilities(data[0x0F+data[0x0E]*sizeof(u16)]); - PyDict_SetItemString(caseData, "Enabled Error Correcting Capabilities", _val); - Py_DECREF(_val); - break; - - case 6: /* 3.3.7 Memory Module Information */ - - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - - if(h->length<0x0C) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Socket Designation", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_connections(data[0x05]); - PyDict_SetItemString(caseData, "Bank Connections", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_speed(data[0x06]); - PyDict_SetItemString(caseData, "Current Speed", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_types(WORD(data+0x07)); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_size(data[0x09]); - PyDict_SetItemString(caseData, "Installed Size", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_size(data[0x0A]); - PyDict_SetItemString(caseData, "Enabled Size", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_error(data[0x0B]); - PyDict_SetItemString(caseData, "Error Status", _val); - Py_DECREF(_val); - break; - - case 7: /* 3.3.8 Cache Information */ - - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - - if(h->length<0x0F) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Socket Designation", _val); - Py_DECREF(_val); - - _val = PyDict_New(); - PyDict_SetItemString(_val, "Enabled", WORD(data+0x05)&0x0080?Py_True:Py_False); - PyDict_SetItemString(_val, "Socketed", WORD(data+0x05)&0x0008?Py_True:Py_False); - PyDict_SetItemString(_val, "Level", PyInt_FromLong((WORD(data+0x05)&0x0007)+1)); - PyDict_SetItemString(caseData, "Configuration" , _val); - Py_DECREF(_val); - - _val = dmi_cache_mode((WORD(data+0x05)>>8)&0x0003); - PyDict_SetItemString(caseData, "Operational Mode", _val); - Py_DECREF(_val); - - _val = dmi_cache_location((WORD(data+0x05)>>5)&0x0003); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_cache_size(WORD(data+0x09)); - PyDict_SetItemString(caseData, "Installed Size", _val); - Py_DECREF(_val); - - _val = dmi_cache_size(WORD(data+0x07)); - PyDict_SetItemString(caseData, "Maximum Size", _val); - Py_DECREF(_val); - - _val = dmi_cache_types(WORD(data+0x0B)); - PyDict_SetItemString(caseData, "Supported SRAM Types", _val); - Py_DECREF(_val); - - _val = dmi_cache_types(WORD(data+0x0D)); - PyDict_SetItemString(caseData, "Installed SRAM Type", _val); - Py_DECREF(_val); - - if(h->length<0x13) break; - _val = dmi_memory_module_speed(data[0x0F]); - PyDict_SetItemString(caseData, "Speed", _val); - Py_DECREF(_val); - - _val = dmi_cache_ec_type(data[0x10]); - PyDict_SetItemString(caseData, "Error Correction Type", _val); - Py_DECREF(_val); - - _val = dmi_cache_type(data[0x11]); - PyDict_SetItemString(caseData, "System Type", _val); - Py_DECREF(_val); - - _val = dmi_cache_associativity(data[0x12]); - PyDict_SetItemString(caseData, "Associativity", _val); - Py_DECREF(_val); - - break; - - case 8: /* 3.3.9 Port Connector Information */ - - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - - if(h->length<0x09) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Internal Reference Designator", _val); - Py_DECREF(_val); - - _val = dmi_port_connector_type(data[0x05]); - PyDict_SetItemString(caseData, "Internal Connector Type", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "External Reference Designator", _val); - Py_DECREF(_val); - - _val = dmi_port_connector_type(data[0x07]); - PyDict_SetItemString(caseData, "External Connector Type", _val); - Py_DECREF(_val); - - _val = dmi_port_type(data[0x08]); - PyDict_SetItemString(caseData, "Port Type", _val); - Py_DECREF(_val); - - break; - - case 9: /* 3.3.10 System Slots */ - - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - - if(h->length<0x0C) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Designation", _val); - Py_DECREF(_val); - - _val = dmi_slot_bus_width(data[0x06]); - PyDict_SetItemString(caseData, "Type:SlotBusWidth", _val); - Py_DECREF(_val); - _val = dmi_slot_type(data[0x05]); - PyDict_SetItemString(caseData, "Type:SlotType", _val); - Py_DECREF(_val); - - _val = dmi_slot_current_usage(data[0x07]); - PyDict_SetItemString(caseData, "Current Usage", _val); - Py_DECREF(_val); - - _val = dmi_slot_length(data[0x08]); - PyDict_SetItemString(caseData, "SlotLength", _val); - Py_DECREF(_val); - _val = dmi_slot_id(data[0x09], data[0x0A], data[0x05]); - PyDict_SetItemString(caseData, "SlotId", _val); - Py_DECREF(_val); - - _val = (h->length<0x0D)?dmi_slot_characteristics(data[0x0B], 0x00):dmi_slot_characteristics(data[0x0B], data[0x0C]); - PyDict_SetItemString(caseData, "Characteristics", _val); - Py_DECREF(_val); - break; - - case 10: /* 3.3.11 On Board Devices Information */ - - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - - break; - - case 11: /* 3.3.12 OEM Strings */ - - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - - if(h->length<0x05) break; - _val = dmi_oem_strings(h); - PyDict_SetItemString(caseData, "Strings", _val); - Py_DECREF(_val); - - break; - - case 12: /* 3.3.13 System Configuration Options */ - - if(h->length<0x05) break; - _val = dmi_system_configuration_options(h); - PyDict_SetItemString(caseData, "Options", _val); - Py_DECREF(_val); - - break; - - case 13: /* 3.3.14 BIOS Language Information */ - - if(h->length<0x16) break; - _val = PyString_FromFormat("%i", data[0x04]); - PyDict_SetItemString(caseData, "Installable Languages", _val); - Py_DECREF(_val); - - _val = dmi_bios_languages(h); - PyList_SET_ITEM(_val, 0, dmi_string_py(h, data[0x15])); - PyDict_SetItemString(caseData, "Currently Installed Language", _val); - Py_DECREF(_val); - - break; - - case 14: /* 3.3.15 Group Associations */ - - if(h->length<0x05) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Name", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%i", (h->length-0x05)/3); - PyDict_SetItemString(caseData, "Items", _val); - Py_DECREF(_val); - - _val = dmi_group_associations_items((h->length-0x05)/3, data+0x05); - PyDict_SetItemString(caseData, "Items2", _val); //. FIXME: Title - Py_DECREF(_val); - break; - - case 15: /* 3.3.16 System Event Log */ - - if(h->length<0x14) break; - _val = PyString_FromFormat("%i bytes", WORD(data+0x04)); - PyDict_SetItemString(caseData, "Area Length", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data+0x06)); - PyDict_SetItemString(caseData, "Header Start Offset", _val); - Py_DECREF(_val); - - if(WORD(data+0x08)-WORD(data+0x06)) { - _val = PyString_FromFormat("%i byte%s", WORD(data+0x08)-WORD(data+0x06), WORD(data+0x08)-WORD(data+0x06)>1?"s":""); - PyDict_SetItemString(caseData, "Header Length", _val); - Py_DECREF(_val); - } - - _val = PyString_FromFormat("0x%04x", WORD(data+0x08)); - PyDict_SetItemString(caseData, "Data Start Offset", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%s", dmi_event_log_method(data[0x0A])); - PyDict_SetItemString(caseData, "Access Method", _val); - Py_DECREF(_val); - - _val = dmi_event_log_address_py(data[0x0A], data+0x10); - PyDict_SetItemString(caseData, "Access Address", _val); - Py_DECREF(_val); - - _val = dmi_event_log_status_py(data[0x0B]); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%08x", DWORD(data+0x0C)); - PyDict_SetItemString(caseData, "Change Token", _val); - Py_DECREF(_val); - - if(h->length<0x17) break; - _val = PyString_FromFormat("%s", dmi_event_log_header_type(data[0x14])); - PyDict_SetItemString(caseData, "Header Format", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%i", data[0x15]); - PyDict_SetItemString(caseData, "Supported Log Type Descriptors", _val); - Py_DECREF(_val); - - if(h->length<0x17+data[0x15]*data[0x16]) break; - _val = dmi_event_log_descriptors(data[0x15], data[0x16], data+0x17); - PyDict_SetItemString(caseData, "DMI Event Log Descriptors", _val); - Py_DECREF(_val); - - break; - - case 16: /* 3.3.17 Physical Memory Array */ - - if(h->length<0x0F) break; - _val = dmi_memory_array_location(data[0x04]); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_use(data[0x05]); - PyDict_SetItemString(caseData, "Use", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_ec_type(data[0x06]); - PyDict_SetItemString(caseData, "Error Correction Type", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_capacity(DWORD(data+0x07)); - PyDict_SetItemString(caseData, "Maximum Capacity", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_error_handle(WORD(data+0x0B)); - PyDict_SetItemString(caseData, "Error Information Handle", _val); - Py_DECREF(_val); - - _val = PyInt_FromLong(WORD(data+0x0D)); - PyDict_SetItemString(caseData, "Number Of Devices", _val); - Py_DECREF(_val); - break; - - - case 17: /* 3.3.18 Memory Device */ - - if(h->length<0x15) break; - _val = PyString_FromFormat("0x%04x", WORD(data+0x04)); - PyDict_SetItemString(caseData, "Array Handle", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_error_handle(WORD(data+0x06)); - PyDict_SetItemString(caseData, "Error Information Handle", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_width(WORD(data+0x08)); - PyDict_SetItemString(caseData, "Total Width", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_width(WORD(data+0x0A)); - PyDict_SetItemString(caseData, "Data Width", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_size(WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Size", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_form_factor(data[0x0E]); - PyDict_SetItemString(caseData, "Form Factor", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_set(data[0x0F]); - PyDict_SetItemString(caseData, "Set", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x10]); - PyDict_SetItemString(caseData, "Locator", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x11]); - PyDict_SetItemString(caseData, "Bank Locator", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_type(data[0x12]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_type_detail(WORD(data+0x13)); - PyDict_SetItemString(caseData, "Type Detail", _val); - Py_DECREF(_val); - - if(h->length<0x17) break; - _val = dmi_memory_device_speed(WORD(data+0x15)); - PyDict_SetItemString(caseData, "Speed", _val); - Py_DECREF(_val); - - if(h->length<0x1B) break; - _val = dmi_string_py(h, data[0x17]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x18]); - PyDict_SetItemString(caseData,"Serial Number" , _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x19]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x1A]); - PyDict_SetItemString(caseData, "Part Number", _val); - Py_DECREF(_val); - break; - - case 18: /* 3.3.19 32-bit Memory Error Information */ - - if(h->length<0x17) break; - _val = dmi_memory_error_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_memory_error_granularity(data[0x05]); - PyDict_SetItemString(caseData, "Granularity", _val); - Py_DECREF(_val); - - _val = dmi_memory_error_operation(data[0x06]); - PyDict_SetItemString(caseData, "Operation", _val); - Py_DECREF(_val); - - _val = dmi_memory_error_syndrome(DWORD(data+0x07)); - PyDict_SetItemString(caseData, "Vendor Syndrome", _val); - Py_DECREF(_val); - - _val = dmi_32bit_memory_error_address(DWORD(data+0x0B)); - PyDict_SetItemString(caseData, "Memory Array Address", _val); - Py_DECREF(_val); - - _val = dmi_32bit_memory_error_address(DWORD(data+0x0F)); - PyDict_SetItemString(caseData, "Device Address", _val); - Py_DECREF(_val); - - _val = dmi_32bit_memory_error_address(DWORD(data+0x13)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); - break; - - case 19: /* 3.3.20 Memory Array Mapped Address */ - - if(h->length<0x0F) break; - _val = PyString_FromFormat("0x%08x%03x", DWORD(data+0x04)>>2, (DWORD(data+0x04)&0x3)<<10); - PyDict_SetItemString(caseData, "Starting Address", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%08x%03x", DWORD(data+0x08)>>2, ((DWORD(data+0x08)&0x3)<<10)+0x3FF); - PyDict_SetItemString(caseData, "Ending Address", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_size(DWORD(data+0x08)-DWORD(data+0x04)+1); - PyDict_SetItemString(caseData, "Range Size", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Physical Array Handle", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%i", data[0x0F]); - PyDict_SetItemString(caseData, "Partition Width", _val); - Py_DECREF(_val); - break; - - case 20: /* 3.3.21 Memory Device Mapped Address */ - - if(h->length<0x13) break; - _val = PyString_FromFormat("0x%08x%03x", DWORD(data+0x04)>>2, (DWORD(data+0x04)&0x3)<<10); - PyDict_SetItemString(caseData, "Starting Address", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%08x%03x", DWORD(data+0x08)>>2, ((DWORD(data+0x08)&0x3)<<10)+0x3FF); - PyDict_SetItemString(caseData, "Ending Address", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_size(DWORD(data+0x08)-DWORD(data+0x04)+1); - PyDict_SetItemString(caseData, "Range Size", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Physical Device Handle", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data+0x0E)); - PyDict_SetItemString(caseData, "Memory Array Mapped Address Handle", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_row_position(data[0x10]); - PyDict_SetItemString(caseData, "Partition Row Position", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_interleave_position(data[0x11]); - PyDict_SetItemString(caseData, ">>>", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_interleaved_data_depth(data[0x12]); - PyDict_SetItemString(caseData, ">>>", _val); - Py_DECREF(_val); - break; - - case 21: /* 3.3.22 Built-in Pointing Device */ - - if(h->length<0x07) break; - _val = dmi_pointing_device_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_pointing_device_interface(data[0x05]); - PyDict_SetItemString(caseData, "Interface", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%i", data[0x06]); - PyDict_SetItemString(caseData, "Buttons", _val); - Py_DECREF(_val); - break; - - case 22: /* 3.3.23 Portable Battery */ - - if(h->length<0x10) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - if(data[0x06] || h->length<0x1A) { - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Manufacture Date", _val); - Py_DECREF(_val); - } - - if(data[0x07] || h->length<0x1A) { - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); - } - - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Name", _val); - Py_DECREF(_val); - - if(data[0x09]!=0x02 || h->length<0x1A) { - _val = dmi_battery_chemistry(data[0x09]); - PyDict_SetItemString(caseData, "Chemistry", _val); - Py_DECREF(_val); - } - _val = (h->length<0x1A)?dmi_battery_capacity(WORD(data+0x0A), 1):dmi_battery_capacity(WORD(data+0x0A), data[0x15]); - PyDict_SetItemString(caseData, "Design Capacity", _val); - Py_DECREF(_val); - - _val = dmi_battery_voltage(WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Design Voltage", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x0E]); - PyDict_SetItemString(caseData, "SBDS Version", _val); - Py_DECREF(_val); - - _val = dmi_battery_maximum_error(data[0x0F]); - PyDict_SetItemString(caseData, "Maximum Error", _val); - Py_DECREF(_val); - - if(h->length<0x1A) break; - if(data[0x07]==0) { - _val = PyString_FromFormat("%04x", WORD(data+0x10)); - PyDict_SetItemString(caseData, "SBDS Serial Number", _val); - Py_DECREF(_val); - } - if(data[0x06]==0) { - _val = PyString_FromFormat("%i-%02u-%02u", 1980+(WORD(data+0x12)>>9), (WORD(data+0x12)>>5)&0x0F, WORD(data+0x12)&0x1F); - PyDict_SetItemString(caseData, "SBDS Manufacture Date", _val); - Py_DECREF(_val); - } - if(data[0x09]==0x02) { - _val = dmi_string_py(h, data[0x14]); - PyDict_SetItemString(caseData, "SBDS Chemistry", _val); - Py_DECREF(_val); - } - - _val = PyString_FromFormat("0x%08x", DWORD(data+0x16)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); - break; - - case 23: /* 3.3.24 System Reset */ - - if(h->length<0x0D) break; - _val = PyString_FromFormat("%s", data[0x04]&(1<<0)?"Enabled":"Disabled"); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%s", data[0x04]&(1<<5)?"Present":"Not Present"); - PyDict_SetItemString(caseData, "Watchdog Timer", _val); - Py_DECREF(_val); - - if(!(data[0x04]&(1<<5))) break; - _val = dmi_system_reset_boot_option((data[0x04]>>1)&0x3); - PyDict_SetItemString(caseData, "Boot Option", _val); - Py_DECREF(_val); - - _val = dmi_system_reset_boot_option((data[0x04]>>3)&0x3); - PyDict_SetItemString(caseData, "Boot Option On Limit", _val); - Py_DECREF(_val); - - _val = dmi_system_reset_count(WORD(data+0x05)); - PyDict_SetItemString(caseData, "Reset Count", _val); - Py_DECREF(_val); - - _val = dmi_system_reset_count(WORD(data+0x07)); - PyDict_SetItemString(caseData, "Reset Limit", _val); - Py_DECREF(_val); - - _val = dmi_system_reset_timer(WORD(data+0x09)); - PyDict_SetItemString(caseData, "Timer Interval", _val); - Py_DECREF(_val); - - _val = dmi_system_reset_timer(WORD(data+0x0B)); - PyDict_SetItemString(caseData, "Timeout", _val); - Py_DECREF(_val); - - break; - - case 24: /* 3.3.25 Hardware Security */ - - if(h->length<0x05) break; - _val = dmi_hardware_security_status(data[0x04]>>6); - PyDict_SetItemString(caseData, "Power-On Password Status", _val); - Py_DECREF(_val); - - _val = dmi_hardware_security_status((data[0x04]>>4)&0x3); - PyDict_SetItemString(caseData, "Keyboard Password Status", _val); - Py_DECREF(_val); - - _val = dmi_hardware_security_status((data[0x04]>>2)&0x3); - PyDict_SetItemString(caseData, "Administrator Password Status", _val); - Py_DECREF(_val); - - _val = dmi_hardware_security_status(data[0x04]&0x3); - PyDict_SetItemString(caseData, "Front Panel Reset Status", _val); - Py_DECREF(_val); +PyObject *dmi_decode(struct dmi_header * h, u16 ver) +{ - break; + const u8 *data = h->data; + + //. 0xF1 --> 0xF100 + //int minor = h->type<<8; + char _[2048]; + + bzero(_, 2048); + //dmi_codes_major *dmiMajor = (dmi_codes_major *)&dmiCodesMajor[map_maj[h->type]]; + dmi_codes_major *dmiMajor = (dmi_codes_major *) & dmiCodesMajor[h->type]; + PyObject *pylist = PyDict_New(); + + PyDict_SetItemString(pylist, "id", PyString_FromString(dmiMajor->id)); + PyDict_SetItemString(pylist, "desc", PyString_FromString(dmiMajor->desc)); + PyObject *_val; //. A Temporary pointer (value) + PyObject *_key; //. Another temporary pointer (key) + PyObject *caseData = PyDict_New(); + + switch (h->type) { + + case 0: /* 3.3.1 BIOS Information */ + + if(h->length < 0x12) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Vendor", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x05]); + PyDict_SetItemString(caseData, "Version", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x08]); + PyDict_SetItemString(caseData, "Release Date", _val); + Py_DECREF(_val); + + /* + * On IA-64, the BIOS base address will read 0 because + * there is no BIOS. Skip the base address and the + * runtime size in this case. + */ + if(WORD(data + 0x06) != 0) { + _val = PyString_FromFormat("0x%04x0", WORD(data + 0x06)); + PyDict_SetItemString(caseData, "Address", _val); + Py_DECREF(_val); + + _val = dmi_bios_runtime_size((0x10000 - WORD(data + 0x06)) << 4); + PyDict_SetItemString(caseData, "Runtime Size", _val); + Py_DECREF(_val); + } + + _val = PyString_FromFormat("%i kB", (data[0x09] + 1) << 6); + PyDict_SetItemString(caseData, "ROM Size", _val); + Py_DECREF(_val); + + _val = dmi_bios_characteristics(QWORD(data + 0x0A)); + PyDict_SetItemString(caseData, "Characteristics", _val); + Py_DECREF(_val); + + if(h->length < 0x13) + break; + _val = dmi_bios_characteristics_x1(data[0x12]); + PyDict_SetItemString(caseData, "Characteristics x1", _val); + Py_DECREF(_val); + + if(h->length < 0x14) + break; + _val = dmi_bios_characteristics_x2(data[0x13]); + PyDict_SetItemString(caseData, "Characteristics x2", _val); + Py_DECREF(_val); + + if(h->length < 0x18) + break; + + if(data[0x14] != 0xFF && data[0x15] != 0xFF) { + _val = PyString_FromFormat("%i.%i", data[0x14], data[0x15]); + PyDict_SetItemString(caseData, "BIOS Revision", _val); + Py_DECREF(_val); + } + + if(data[0x16] != 0xFF && data[0x17] != 0xFF) { + _val = PyString_FromFormat("%i.%i", data[0x16], data[0x17]); + PyDict_SetItemString(caseData, "Firmware Revision", _val); + Py_DECREF(_val); + } + + break; + + case 1: /* 3.3.2 System Information */ + + if(h->length < 0x08) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Manufacturer", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x05]); + PyDict_SetItemString(caseData, "Product Name", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x06]); + PyDict_SetItemString(caseData, "Version", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x07]); + PyDict_SetItemString(caseData, "Serial Number", _val); + Py_DECREF(_val); + + if(h->length < 0x19) + break; + _val = dmi_system_uuid_py(data + 0x08, ver); + PyDict_SetItemString(caseData, "UUID", _val); + Py_DECREF(_val); + + _val = dmi_system_wake_up_type(data[0x18]); + PyDict_SetItemString(caseData, "Wake-Up Type", _val); + Py_DECREF(_val); + + if(h->length < 0x1B) + break; + _val = dmi_string_py(h, data[0x19]); + PyDict_SetItemString(caseData, "SKU Number", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x1A]); + PyDict_SetItemString(caseData, "Family", _val); + Py_DECREF(_val); + break; + + case 2: /* 3.3.3 Base Board Information */ + + if(h->length < 0x08) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Manufacturer", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x05]); + PyDict_SetItemString(caseData, "Product Name", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x06]); + PyDict_SetItemString(caseData, "Version", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x07]); + PyDict_SetItemString(caseData, "Serial Number", _val); + Py_DECREF(_val); + + if(h->length < 0x0F) + break; + _val = dmi_string_py(h, data[0x08]); + PyDict_SetItemString(caseData, "Asset Tag", _val); + Py_DECREF(_val); + + _val = dmi_base_board_features(data[0x09]); + PyDict_SetItemString(caseData, "Features", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x0A]); + PyDict_SetItemString(caseData, "Location In Chassis", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%04x", WORD(data + 0x0B)); + PyDict_SetItemString(caseData, "Chassis Handle", _val); + Py_DECREF(_val); + + _val = dmi_base_board_type(data[0x0D]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + if(h->length < 0x0F + data[0x0E] * sizeof(u16)) + break; + _val = dmi_base_board_handles(data[0x0E], data + 0x0F); + PyDict_SetItemString(caseData, "Type ???", _val); + Py_DECREF(_val); + break; + + case 3: /* 3.3.4 Chassis Information */ + + if(h->length < 0x09) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Manufacturer", _val); + Py_DECREF(_val); + + _val = dmi_chassis_type_py(data[0x05] & 0x7F); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = dmi_chassis_lock(data[0x05] >> 7); + PyDict_SetItemString(caseData, "Lock", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x06]); + PyDict_SetItemString(caseData, "Version", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x07]); + PyDict_SetItemString(caseData, "Serial Number", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x08]); + PyDict_SetItemString(caseData, "Asset Tag", _val); + Py_DECREF(_val); + + if(h->length < 0x0D) + break; + _val = dmi_chassis_state(data[0x09]); + PyDict_SetItemString(caseData, "Boot-Up State", _val); + Py_DECREF(_val); + + _val = dmi_chassis_state(data[0x0A]); + PyDict_SetItemString(caseData, "Power Supply State", _val); + Py_DECREF(_val); + + _val = dmi_chassis_state(data[0x0B]); + PyDict_SetItemString(caseData, "Thermal State", _val); + Py_DECREF(_val); + + _val = PyString_FromString(dmi_chassis_security_status(data[0x0C])); + PyDict_SetItemString(caseData, "Security Status", _val); + Py_DECREF(_val); + + if(h->length < 0x11) + break; + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x0D)); + PyDict_SetItemString(caseData, "OEM Information", _val); + Py_DECREF(_val); + + if(h->length < 0x13) + break; + _val = dmi_chassis_height(data[0x11]); + PyDict_SetItemString(caseData, "Height", _val); + Py_DECREF(_val); + + _val = dmi_chassis_power_cords(data[0x12]); + PyDict_SetItemString(caseData, "Number Of Power Cords", _val); + Py_DECREF(_val); + + if(h->length < 0x15) + break; + if(h->length < 0x15 + data[0x13] * data[0x14]) + break; + _val = dmi_chassis_elements(data[0x13], data[0x14], data + 0x15); + PyDict_SetItemString(caseData, "Elements", _val); + Py_DECREF(_val); + + break; + + case 4: /* 3.3.5 Processor Information */ + + if(h->length < 0x1A) + break; + + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Socket Designation", _val); + Py_DECREF(_val); + + _val = dmi_processor_type(data[0x05]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = PyString_FromString(dmi_processor_family(h)); + PyDict_SetItemString(caseData, "Family", _val); + Py_DECREF(_val); + + _val = dmi_processor_id(data[0x06], data + 8, dmi_string(h, data[0x10])); + PyDict_SetItemString(_val, "Vendor", dmi_string_py(h, data[0x07])); + PyDict_SetItemString(caseData, "Manufacturer", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x10]); + PyDict_SetItemString(caseData, "Version", _val); + Py_DECREF(_val); + + _val = dmi_processor_voltage(data[0x11]); + PyDict_SetItemString(caseData, "Voltage", _val); + Py_DECREF(_val); + + _val = dmi_processor_frequency_py(data + 0x12); + PyDict_SetItemString(caseData, "External Clock", _val); + Py_DECREF(_val); + + _val = dmi_processor_frequency_py(data + 0x14); + PyDict_SetItemString(caseData, "Max Speed", _val); + Py_DECREF(_val); + + _val = dmi_processor_frequency_py(data + 0x16); + PyDict_SetItemString(caseData, "Current Speed", _val); + Py_DECREF(_val); + + if(data[0x18] & (1 << 6)) { + _val = + PyString_FromFormat("Populated:%s", + dmi_processor_status(data[0x18] & 0x07)); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); + } else { + _val = PyString_FromString("Populated:No"); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); + } + _val = dmi_processor_upgrade(data[0x19]); + PyDict_SetItemString(caseData, "Upgrade", _val); + Py_DECREF(_val); + + if(h->length < 0x20) + break; + _val = dmi_processor_cache(WORD(data + 0x1A), "L1", ver); + PyDict_SetItemString(caseData, "L1 Cache Handle", _val); + Py_DECREF(_val); + + _val = dmi_processor_cache(WORD(data + 0x1C), "L2", ver); + PyDict_SetItemString(caseData, "L2 Cache Handle", _val); + Py_DECREF(_val); + + _val = dmi_processor_cache(WORD(data + 0x1E), "L3", ver); + PyDict_SetItemString(caseData, "L3 Cache Handle", _val); + Py_DECREF(_val); + + if(h->length < 0x23) + break; + _val = dmi_string_py(h, data[0x20]); + PyDict_SetItemString(caseData, "Serial Number", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x21]); + PyDict_SetItemString(caseData, "Asset Tag", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x22]); + PyDict_SetItemString(caseData, "Part Number", _val); + Py_DECREF(_val); + + if(h->length < 0x28) + break; + if(data[0x23] != 0) { + _val = PyString_FromFormat("%i", data[0x23]); + PyDict_SetItemString(caseData, "Core Count", _val); + Py_DECREF(_val); + } + + if(data[0x24] != 0) { + _val = PyString_FromFormat("%i", data[0x24]); + PyDict_SetItemString(caseData, "Core Enabled", _val); + Py_DECREF(_val); + } + + if(data[0x25] != 0) { + _val = PyString_FromFormat("%i", data[0x25]); + PyDict_SetItemString(caseData, "Thread Count", _val); + Py_DECREF(_val); + } + + _val = dmi_processor_characteristics(WORD(data + 0x26)); + PyDict_SetItemString(caseData, "Characteristics", _val); + Py_DECREF(_val); + break; + + case 5: /* 3.3.6 Memory Controller Information */ + + PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + + if(h->length < 0x0F) + break; + _val = dmi_memory_controller_ed_method(data[0x04]); + PyDict_SetItemString(caseData, "Error Detecting Method", _val); + Py_DECREF(_val); + + _val = dmi_memory_controller_ec_capabilities(data[0x05]); + PyDict_SetItemString(caseData, "Error Correcting Capabilities", _val); + Py_DECREF(_val); + + _val = dmi_memory_controller_interleave(data[0x06]); + PyDict_SetItemString(caseData, "Supported Interleave", _val); + Py_DECREF(_val); + + _val = dmi_memory_controller_interleave(data[0x07]); + PyDict_SetItemString(caseData, "Current Interleave", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i MB", 1 << data[0x08]); + PyDict_SetItemString(caseData, "Maximum Memory Module Size", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i MB", data[0x0E] * (1 << data[0x08])); + PyDict_SetItemString(caseData, "Maximum Total Memory Size", _val); + Py_DECREF(_val); + + _val = dmi_memory_controller_speeds(WORD(data + 0x09)); + PyDict_SetItemString(caseData, "Supported Speeds", _val); + Py_DECREF(_val); + + _val = dmi_memory_module_types(WORD(data + 0x0B)); + PyDict_SetItemString(caseData, "Supported Memory Types", _val); + Py_DECREF(_val); + + _val = dmi_processor_voltage(data[0x0D]); + PyDict_SetItemString(caseData, "Memory Module Voltage", _val); + Py_DECREF(_val); + + if(h->length < 0x0F + data[0x0E] * sizeof(u16)) + break; + _val = dmi_memory_controller_slots(data[0x0E], data + 0x0F); + PyDict_SetItemString(caseData, "Associated Memory Sluts", _val); + Py_DECREF(_val); + + if(h->length < 0x10 + data[0x0E] * sizeof(u16)) + break; + _val = dmi_memory_controller_ec_capabilities(data[0x0F + data[0x0E] * sizeof(u16)]); + PyDict_SetItemString(caseData, "Enabled Error Correcting Capabilities", _val); + Py_DECREF(_val); + break; + + case 6: /* 3.3.7 Memory Module Information */ + + PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + + if(h->length < 0x0C) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Socket Designation", _val); + Py_DECREF(_val); + + _val = dmi_memory_module_connections(data[0x05]); + PyDict_SetItemString(caseData, "Bank Connections", _val); + Py_DECREF(_val); + + _val = dmi_memory_module_speed(data[0x06]); + PyDict_SetItemString(caseData, "Current Speed", _val); + Py_DECREF(_val); + + _val = dmi_memory_module_types(WORD(data + 0x07)); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = dmi_memory_module_size(data[0x09]); + PyDict_SetItemString(caseData, "Installed Size", _val); + Py_DECREF(_val); + + _val = dmi_memory_module_size(data[0x0A]); + PyDict_SetItemString(caseData, "Enabled Size", _val); + Py_DECREF(_val); + + _val = dmi_memory_module_error(data[0x0B]); + PyDict_SetItemString(caseData, "Error Status", _val); + Py_DECREF(_val); + break; + + case 7: /* 3.3.8 Cache Information */ - case 25: /* 3.3.26 System Power Controls */ + PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - if(h->length<0x09) break; - _val = dmi_power_controls_power_on(data+0x04); - PyDict_SetItemString(caseData, "Next Scheduled Power-on", _val); - Py_DECREF(_val); + if(h->length < 0x0F) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Socket Designation", _val); + Py_DECREF(_val); - break; + _val = PyDict_New(); + PyDict_SetItemString(_val, "Enabled", + WORD(data + 0x05) & 0x0080 ? Py_True : Py_False); + PyDict_SetItemString(_val, "Socketed", + WORD(data + 0x05) & 0x0008 ? Py_True : Py_False); + PyDict_SetItemString(_val, "Level", + PyInt_FromLong((WORD(data + 0x05) & 0x0007) + 1)); + PyDict_SetItemString(caseData, "Configuration", _val); + Py_DECREF(_val); + + _val = dmi_cache_mode((WORD(data + 0x05) >> 8) & 0x0003); + PyDict_SetItemString(caseData, "Operational Mode", _val); + Py_DECREF(_val); + + _val = dmi_cache_location((WORD(data + 0x05) >> 5) & 0x0003); + PyDict_SetItemString(caseData, "Location", _val); + Py_DECREF(_val); + + _val = dmi_cache_size(WORD(data + 0x09)); + PyDict_SetItemString(caseData, "Installed Size", _val); + Py_DECREF(_val); + + _val = dmi_cache_size(WORD(data + 0x07)); + PyDict_SetItemString(caseData, "Maximum Size", _val); + Py_DECREF(_val); - case 26: /* 3.3.27 Voltage Probe */ + _val = dmi_cache_types(WORD(data + 0x0B)); + PyDict_SetItemString(caseData, "Supported SRAM Types", _val); + Py_DECREF(_val); - if(h->length<0x14) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); + _val = dmi_cache_types(WORD(data + 0x0D)); + PyDict_SetItemString(caseData, "Installed SRAM Type", _val); + Py_DECREF(_val); - _val = dmi_voltage_probe_location(data[0x05]&0x1f); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); + if(h->length < 0x13) + break; + _val = dmi_memory_module_speed(data[0x0F]); + PyDict_SetItemString(caseData, "Speed", _val); + Py_DECREF(_val); - _val = dmi_probe_status(data[0x05]>>5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + _val = dmi_cache_ec_type(data[0x10]); + PyDict_SetItemString(caseData, "Error Correction Type", _val); + Py_DECREF(_val); - _val = dmi_voltage_probe_value(WORD(data+0x06)); - PyDict_SetItemString(caseData, "Maximum Value", _val); - Py_DECREF(_val); + _val = dmi_cache_type(data[0x11]); + PyDict_SetItemString(caseData, "System Type", _val); + Py_DECREF(_val); - _val = dmi_voltage_probe_value(WORD(data+0x08)); - PyDict_SetItemString(caseData, "Minimum Value", _val); - Py_DECREF(_val); + _val = dmi_cache_associativity(data[0x12]); + PyDict_SetItemString(caseData, "Associativity", _val); + Py_DECREF(_val); - _val = dmi_voltage_probe_resolution(WORD(data+0x0A)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + break; - _val = dmi_voltage_probe_value(WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Tolerance", _val); - Py_DECREF(_val); + case 8: /* 3.3.9 Port Connector Information */ - _val = dmi_probe_accuracy(WORD(data+0x0E)); - PyDict_SetItemString(caseData, "Accuracy", _val); - Py_DECREF(_val); + PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - _val = PyString_FromFormat("0x%08x", DWORD(data+0x10)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + if(h->length < 0x09) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Internal Reference Designator", _val); + Py_DECREF(_val); - if(h->length<0x16) break; - _val = dmi_voltage_probe_value(WORD(data+0x14)); - PyDict_SetItemString(caseData, "Nominal Value", _val); - Py_DECREF(_val); + _val = dmi_port_connector_type(data[0x05]); + PyDict_SetItemString(caseData, "Internal Connector Type", _val); + Py_DECREF(_val); - break; + _val = dmi_string_py(h, data[0x06]); + PyDict_SetItemString(caseData, "External Reference Designator", _val); + Py_DECREF(_val); - case 27: /* 3.3.28 Cooling Device */ + _val = dmi_port_connector_type(data[0x07]); + PyDict_SetItemString(caseData, "External Connector Type", _val); + Py_DECREF(_val); - if(h->length<0x0C) break; - if(WORD(data+0x04)!=0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data+0x04)); - PyDict_SetItemString(caseData, "Temperature Probe Handle", _val); - Py_DECREF(_val); - } + _val = dmi_port_type(data[0x08]); + PyDict_SetItemString(caseData, "Port Type", _val); + Py_DECREF(_val); - _val = dmi_cooling_device_type(data[0x06]&0x1f); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + break; - _val = dmi_probe_status(data[0x06]>>5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + case 9: /* 3.3.10 System Slots */ - if(data[0x07]!=0x00) { - _val = PyString_FromFormat("%i", data[0x07]); - PyDict_SetItemString(caseData, "Cooling Unit Group", _val); - Py_DECREF(_val); - } + PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - _val = PyString_FromFormat("0x%08x", DWORD(data+0x08)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + if(h->length < 0x0C) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Designation", _val); + Py_DECREF(_val); - if(h->length<0x0E) break; - _val = dmi_cooling_device_speed(WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Nominal Speed", _val); - Py_DECREF(_val); + _val = dmi_slot_bus_width(data[0x06]); + PyDict_SetItemString(caseData, "Type:SlotBusWidth", _val); + Py_DECREF(_val); + _val = dmi_slot_type(data[0x05]); + PyDict_SetItemString(caseData, "Type:SlotType", _val); + Py_DECREF(_val); - break; + _val = dmi_slot_current_usage(data[0x07]); + PyDict_SetItemString(caseData, "Current Usage", _val); + Py_DECREF(_val); - case 28: /* 3.3.29 Temperature Probe */ + _val = dmi_slot_length(data[0x08]); + PyDict_SetItemString(caseData, "SlotLength", _val); + Py_DECREF(_val); + _val = dmi_slot_id(data[0x09], data[0x0A], data[0x05]); + PyDict_SetItemString(caseData, "SlotId", _val); + Py_DECREF(_val); - if(h->length<0x14) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); + _val = + (h->length < 0x0D) ? dmi_slot_characteristics(data[0x0B], + 0x00) : + dmi_slot_characteristics(data[0x0B], data[0x0C]); + PyDict_SetItemString(caseData, "Characteristics", _val); + Py_DECREF(_val); + break; - _val = dmi_temperature_probe_location(data[0x05]&0x1F); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); + case 10: /* 3.3.11 On Board Devices Information */ - _val = dmi_probe_status(data[0x05]>>5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - _val = dmi_temperature_probe_value(WORD(data+0x06)); - PyDict_SetItemString(caseData, "Maximum Value", _val); - Py_DECREF(_val); + break; - _val = dmi_temperature_probe_value(WORD(data+0x08)); - PyDict_SetItemString(caseData, "Minimum Value", _val); - Py_DECREF(_val); + case 11: /* 3.3.12 OEM Strings */ - _val = dmi_temperature_probe_resolution(WORD(data+0x0A)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); - _val = dmi_temperature_probe_value(WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Tolerance", _val); - Py_DECREF(_val); + if(h->length < 0x05) + break; + _val = dmi_oem_strings(h); + PyDict_SetItemString(caseData, "Strings", _val); + Py_DECREF(_val); - _val = dmi_probe_accuracy(WORD(data+0x0E)); - PyDict_SetItemString(caseData, "Accuracy", _val); - Py_DECREF(_val); + break; - _val = PyString_FromFormat("0x%08x", DWORD(data+0x10)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + case 12: /* 3.3.13 System Configuration Options */ - if(h->length<0x16) break; - _val = dmi_temperature_probe_value(WORD(data+0x14)); - PyDict_SetItemString(caseData, "Nominal Value", _val); - Py_DECREF(_val); + if(h->length < 0x05) + break; + _val = dmi_system_configuration_options(h); + PyDict_SetItemString(caseData, "Options", _val); + Py_DECREF(_val); - break; + break; - case 29: /* 3.3.30 Electrical Current Probe */ + case 13: /* 3.3.14 BIOS Language Information */ - if(h->length<0x14) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); + if(h->length < 0x16) + break; + _val = PyString_FromFormat("%i", data[0x04]); + PyDict_SetItemString(caseData, "Installable Languages", _val); + Py_DECREF(_val); - _val = dmi_voltage_probe_location(data[5]&0x1F); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); + _val = dmi_bios_languages(h); + PyList_SET_ITEM(_val, 0, dmi_string_py(h, data[0x15])); + PyDict_SetItemString(caseData, "Currently Installed Language", _val); + Py_DECREF(_val); + + break; - _val = dmi_probe_status(data[0x05]>>5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + case 14: /* 3.3.15 Group Associations */ - _val = dmi_current_probe_value(WORD(data+0x06)); - PyDict_SetItemString(caseData, "Maximum Value", _val); - Py_DECREF(_val); + if(h->length < 0x05) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Name", _val); + Py_DECREF(_val); - _val = dmi_current_probe_value(WORD(data+0x08)); - PyDict_SetItemString(caseData, "Minimum Value", _val); - Py_DECREF(_val); + _val = PyString_FromFormat("%i", (h->length - 0x05) / 3); + PyDict_SetItemString(caseData, "Items", _val); + Py_DECREF(_val); + + _val = dmi_group_associations_items((h->length - 0x05) / 3, data + 0x05); + PyDict_SetItemString(caseData, "Items2", _val); //. FIXME: Title + Py_DECREF(_val); + break; - _val = dmi_current_probe_resolution(WORD(data+0x0A)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + case 15: /* 3.3.16 System Event Log */ - _val = dmi_current_probe_value(WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Tolerance", _val); - Py_DECREF(_val); + if(h->length < 0x14) + break; + _val = PyString_FromFormat("%i bytes", WORD(data + 0x04)); + PyDict_SetItemString(caseData, "Area Length", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%04x", WORD(data + 0x06)); + PyDict_SetItemString(caseData, "Header Start Offset", _val); + Py_DECREF(_val); + + if(WORD(data + 0x08) - WORD(data + 0x06)) { + _val = + PyString_FromFormat("%i byte%s", WORD(data + 0x08) - WORD(data + 0x06), + WORD(data + 0x08) - WORD(data + 0x06) > + 1 ? "s" : ""); + PyDict_SetItemString(caseData, "Header Length", _val); + Py_DECREF(_val); + } - _val = dmi_probe_accuracy(WORD(data+0x0E)); - PyDict_SetItemString(caseData, "Accuracy", _val); - Py_DECREF(_val); + _val = PyString_FromFormat("0x%04x", WORD(data + 0x08)); + PyDict_SetItemString(caseData, "Data Start Offset", _val); + Py_DECREF(_val); - _val = PyString_FromFormat("0x%08x", DWORD(data+0x10)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + _val = PyString_FromFormat("%s", dmi_event_log_method(data[0x0A])); + PyDict_SetItemString(caseData, "Access Method", _val); + Py_DECREF(_val); - if(h->length<0x16) break; - _val = dmi_current_probe_value(WORD(data+0x14)); - PyDict_SetItemString(caseData, "Nominal Value", _val); - Py_DECREF(_val); + _val = dmi_event_log_address_py(data[0x0A], data + 0x10); + PyDict_SetItemString(caseData, "Access Address", _val); + Py_DECREF(_val); - break; + _val = dmi_event_log_status_py(data[0x0B]); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); - case 30: /* 3.3.31 Out-of-band Remote Access */ + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Change Token", _val); + Py_DECREF(_val); - if(h->length<0x06) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer Name", _val); - Py_DECREF(_val); + if(h->length < 0x17) + break; + _val = PyString_FromFormat("%s", dmi_event_log_header_type(data[0x14])); + PyDict_SetItemString(caseData, "Header Format", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i", data[0x15]); + PyDict_SetItemString(caseData, "Supported Log Type Descriptors", _val); + Py_DECREF(_val); + + if(h->length < 0x17 + data[0x15] * data[0x16]) + break; + _val = dmi_event_log_descriptors(data[0x15], data[0x16], data + 0x17); + PyDict_SetItemString(caseData, "DMI Event Log Descriptors", _val); + Py_DECREF(_val); + + break; + + case 16: /* 3.3.17 Physical Memory Array */ + + if(h->length < 0x0F) + break; + _val = dmi_memory_array_location(data[0x04]); + PyDict_SetItemString(caseData, "Location", _val); + Py_DECREF(_val); + + _val = dmi_memory_array_use(data[0x05]); + PyDict_SetItemString(caseData, "Use", _val); + Py_DECREF(_val); + + _val = dmi_memory_array_ec_type(data[0x06]); + PyDict_SetItemString(caseData, "Error Correction Type", _val); + Py_DECREF(_val); + + _val = dmi_memory_array_capacity(DWORD(data + 0x07)); + PyDict_SetItemString(caseData, "Maximum Capacity", _val); + Py_DECREF(_val); + + _val = dmi_memory_array_error_handle(WORD(data + 0x0B)); + PyDict_SetItemString(caseData, "Error Information Handle", _val); + Py_DECREF(_val); + + _val = PyInt_FromLong(WORD(data + 0x0D)); + PyDict_SetItemString(caseData, "Number Of Devices", _val); + Py_DECREF(_val); + break; + + case 17: /* 3.3.18 Memory Device */ + + if(h->length < 0x15) + break; + _val = PyString_FromFormat("0x%04x", WORD(data + 0x04)); + PyDict_SetItemString(caseData, "Array Handle", _val); + Py_DECREF(_val); + + _val = dmi_memory_array_error_handle(WORD(data + 0x06)); + PyDict_SetItemString(caseData, "Error Information Handle", _val); + Py_DECREF(_val); + + _val = dmi_memory_device_width(WORD(data + 0x08)); + PyDict_SetItemString(caseData, "Total Width", _val); + Py_DECREF(_val); + + _val = dmi_memory_device_width(WORD(data + 0x0A)); + PyDict_SetItemString(caseData, "Data Width", _val); + Py_DECREF(_val); + + _val = dmi_memory_device_size(WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Size", _val); + Py_DECREF(_val); + + _val = dmi_memory_device_form_factor(data[0x0E]); + PyDict_SetItemString(caseData, "Form Factor", _val); + Py_DECREF(_val); + + _val = dmi_memory_device_set(data[0x0F]); + PyDict_SetItemString(caseData, "Set", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x10]); + PyDict_SetItemString(caseData, "Locator", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x11]); + PyDict_SetItemString(caseData, "Bank Locator", _val); + Py_DECREF(_val); + + _val = dmi_memory_device_type(data[0x12]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = dmi_memory_device_type_detail(WORD(data + 0x13)); + PyDict_SetItemString(caseData, "Type Detail", _val); + Py_DECREF(_val); + + if(h->length < 0x17) + break; + _val = dmi_memory_device_speed(WORD(data + 0x15)); + PyDict_SetItemString(caseData, "Speed", _val); + Py_DECREF(_val); + + if(h->length < 0x1B) + break; + _val = dmi_string_py(h, data[0x17]); + PyDict_SetItemString(caseData, "Manufacturer", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x18]); + PyDict_SetItemString(caseData, "Serial Number", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x19]); + PyDict_SetItemString(caseData, "Asset Tag", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x1A]); + PyDict_SetItemString(caseData, "Part Number", _val); + Py_DECREF(_val); + break; + + case 18: /* 3.3.19 32-bit Memory Error Information */ + + if(h->length < 0x17) + break; + _val = dmi_memory_error_type(data[0x04]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = dmi_memory_error_granularity(data[0x05]); + PyDict_SetItemString(caseData, "Granularity", _val); + Py_DECREF(_val); + + _val = dmi_memory_error_operation(data[0x06]); + PyDict_SetItemString(caseData, "Operation", _val); + Py_DECREF(_val); + + _val = dmi_memory_error_syndrome(DWORD(data + 0x07)); + PyDict_SetItemString(caseData, "Vendor Syndrome", _val); + Py_DECREF(_val); + + _val = dmi_32bit_memory_error_address(DWORD(data + 0x0B)); + PyDict_SetItemString(caseData, "Memory Array Address", _val); + Py_DECREF(_val); + + _val = dmi_32bit_memory_error_address(DWORD(data + 0x0F)); + PyDict_SetItemString(caseData, "Device Address", _val); + Py_DECREF(_val); + + _val = dmi_32bit_memory_error_address(DWORD(data + 0x13)); + PyDict_SetItemString(caseData, "Resolution", _val); + Py_DECREF(_val); + break; + + case 19: /* 3.3.20 Memory Array Mapped Address */ + + if(h->length < 0x0F) + break; + _val = + PyString_FromFormat("0x%08x%03x", DWORD(data + 0x04) >> 2, + (DWORD(data + 0x04) & 0x3) << 10); + PyDict_SetItemString(caseData, "Starting Address", _val); + Py_DECREF(_val); + + _val = + PyString_FromFormat("0x%08x%03x", DWORD(data + 0x08) >> 2, + ((DWORD(data + 0x08) & 0x3) << 10) + 0x3FF); + PyDict_SetItemString(caseData, "Ending Address", _val); + Py_DECREF(_val); + + _val = dmi_mapped_address_size(DWORD(data + 0x08) - DWORD(data + 0x04) + 1); + PyDict_SetItemString(caseData, "Range Size", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%04x", WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Physical Array Handle", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i", data[0x0F]); + PyDict_SetItemString(caseData, "Partition Width", _val); + Py_DECREF(_val); + break; + + case 20: /* 3.3.21 Memory Device Mapped Address */ + + if(h->length < 0x13) + break; + _val = + PyString_FromFormat("0x%08x%03x", DWORD(data + 0x04) >> 2, + (DWORD(data + 0x04) & 0x3) << 10); + PyDict_SetItemString(caseData, "Starting Address", _val); + Py_DECREF(_val); + + _val = + PyString_FromFormat("0x%08x%03x", DWORD(data + 0x08) >> 2, + ((DWORD(data + 0x08) & 0x3) << 10) + 0x3FF); + PyDict_SetItemString(caseData, "Ending Address", _val); + Py_DECREF(_val); + + _val = dmi_mapped_address_size(DWORD(data + 0x08) - DWORD(data + 0x04) + 1); + PyDict_SetItemString(caseData, "Range Size", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%04x", WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Physical Device Handle", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%04x", WORD(data + 0x0E)); + PyDict_SetItemString(caseData, "Memory Array Mapped Address Handle", _val); + Py_DECREF(_val); + + _val = dmi_mapped_address_row_position(data[0x10]); + PyDict_SetItemString(caseData, "Partition Row Position", _val); + Py_DECREF(_val); + + _val = dmi_mapped_address_interleave_position(data[0x11]); + PyDict_SetItemString(caseData, ">>>", _val); + Py_DECREF(_val); + + _val = dmi_mapped_address_interleaved_data_depth(data[0x12]); + PyDict_SetItemString(caseData, ">>>", _val); + Py_DECREF(_val); + break; + + case 21: /* 3.3.22 Built-in Pointing Device */ + + if(h->length < 0x07) + break; + _val = dmi_pointing_device_type(data[0x04]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = dmi_pointing_device_interface(data[0x05]); + PyDict_SetItemString(caseData, "Interface", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i", data[0x06]); + PyDict_SetItemString(caseData, "Buttons", _val); + Py_DECREF(_val); + break; + + case 22: /* 3.3.23 Portable Battery */ + + if(h->length < 0x10) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Location", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x05]); + PyDict_SetItemString(caseData, "Manufacturer", _val); + Py_DECREF(_val); + + if(data[0x06] || h->length < 0x1A) { + _val = dmi_string_py(h, data[0x06]); + PyDict_SetItemString(caseData, "Manufacture Date", _val); + Py_DECREF(_val); + } + + if(data[0x07] || h->length < 0x1A) { + _val = dmi_string_py(h, data[0x07]); + PyDict_SetItemString(caseData, "Serial Number", _val); + Py_DECREF(_val); + } + + _val = dmi_string_py(h, data[0x08]); + PyDict_SetItemString(caseData, "Name", _val); + Py_DECREF(_val); + + if(data[0x09] != 0x02 || h->length < 0x1A) { + _val = dmi_battery_chemistry(data[0x09]); + PyDict_SetItemString(caseData, "Chemistry", _val); + Py_DECREF(_val); + } + _val = + (h->length < 0x1A) ? dmi_battery_capacity(WORD(data + 0x0A), + 1) : dmi_battery_capacity(WORD(data + + 0x0A), + data[0x15]); + PyDict_SetItemString(caseData, "Design Capacity", _val); + Py_DECREF(_val); + + _val = dmi_battery_voltage(WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Design Voltage", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x0E]); + PyDict_SetItemString(caseData, "SBDS Version", _val); + Py_DECREF(_val); + + _val = dmi_battery_maximum_error(data[0x0F]); + PyDict_SetItemString(caseData, "Maximum Error", _val); + Py_DECREF(_val); + + if(h->length < 0x1A) + break; + if(data[0x07] == 0) { + _val = PyString_FromFormat("%04x", WORD(data + 0x10)); + PyDict_SetItemString(caseData, "SBDS Serial Number", _val); + Py_DECREF(_val); + } + if(data[0x06] == 0) { + _val = + PyString_FromFormat("%i-%02u-%02u", 1980 + (WORD(data + 0x12) >> 9), + (WORD(data + 0x12) >> 5) & 0x0F, + WORD(data + 0x12) & 0x1F); + PyDict_SetItemString(caseData, "SBDS Manufacture Date", _val); + Py_DECREF(_val); + } + if(data[0x09] == 0x02) { + _val = dmi_string_py(h, data[0x14]); + PyDict_SetItemString(caseData, "SBDS Chemistry", _val); + Py_DECREF(_val); + } + + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x16)); + PyDict_SetItemString(caseData, "OEM-specific Information", _val); + Py_DECREF(_val); + break; + + case 23: /* 3.3.24 System Reset */ + + if(h->length < 0x0D) + break; + _val = PyString_FromFormat("%s", data[0x04] & (1 << 0) ? "Enabled" : "Disabled"); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%s", data[0x04] & (1 << 5) ? "Present" : "Not Present"); + PyDict_SetItemString(caseData, "Watchdog Timer", _val); + Py_DECREF(_val); + + if(!(data[0x04] & (1 << 5))) + break; + _val = dmi_system_reset_boot_option((data[0x04] >> 1) & 0x3); + PyDict_SetItemString(caseData, "Boot Option", _val); + Py_DECREF(_val); + + _val = dmi_system_reset_boot_option((data[0x04] >> 3) & 0x3); + PyDict_SetItemString(caseData, "Boot Option On Limit", _val); + Py_DECREF(_val); + + _val = dmi_system_reset_count(WORD(data + 0x05)); + PyDict_SetItemString(caseData, "Reset Count", _val); + Py_DECREF(_val); + + _val = dmi_system_reset_count(WORD(data + 0x07)); + PyDict_SetItemString(caseData, "Reset Limit", _val); + Py_DECREF(_val); + + _val = dmi_system_reset_timer(WORD(data + 0x09)); + PyDict_SetItemString(caseData, "Timer Interval", _val); + Py_DECREF(_val); + + _val = dmi_system_reset_timer(WORD(data + 0x0B)); + PyDict_SetItemString(caseData, "Timeout", _val); + Py_DECREF(_val); + + break; + + case 24: /* 3.3.25 Hardware Security */ + + if(h->length < 0x05) + break; + _val = dmi_hardware_security_status(data[0x04] >> 6); + PyDict_SetItemString(caseData, "Power-On Password Status", _val); + Py_DECREF(_val); + + _val = dmi_hardware_security_status((data[0x04] >> 4) & 0x3); + PyDict_SetItemString(caseData, "Keyboard Password Status", _val); + Py_DECREF(_val); + + _val = dmi_hardware_security_status((data[0x04] >> 2) & 0x3); + PyDict_SetItemString(caseData, "Administrator Password Status", _val); + Py_DECREF(_val); + + _val = dmi_hardware_security_status(data[0x04] & 0x3); + PyDict_SetItemString(caseData, "Front Panel Reset Status", _val); + Py_DECREF(_val); + + break; + + case 25: /* 3.3.26 System Power Controls */ + + if(h->length < 0x09) + break; + _val = dmi_power_controls_power_on(data + 0x04); + PyDict_SetItemString(caseData, "Next Scheduled Power-on", _val); + Py_DECREF(_val); + + break; + + case 26: /* 3.3.27 Voltage Probe */ + + if(h->length < 0x14) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Description", _val); + Py_DECREF(_val); + + _val = dmi_voltage_probe_location(data[0x05] & 0x1f); + PyDict_SetItemString(caseData, "Location", _val); + Py_DECREF(_val); + + _val = dmi_probe_status(data[0x05] >> 5); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); + + _val = dmi_voltage_probe_value(WORD(data + 0x06)); + PyDict_SetItemString(caseData, "Maximum Value", _val); + Py_DECREF(_val); - _val = data[0x05]&(1<<0)?Py_True:Py_False; - PyDict_SetItemString(caseData, "Inbound Connection Enabled", _val); - Py_DECREF(_val); + _val = dmi_voltage_probe_value(WORD(data + 0x08)); + PyDict_SetItemString(caseData, "Minimum Value", _val); + Py_DECREF(_val); - _val = data[0x05]&(1<<1)?Py_True:Py_False; - PyDict_SetItemString(caseData, "Outbound Connection Enabled", _val); - Py_DECREF(_val); - break; + _val = dmi_voltage_probe_resolution(WORD(data + 0x0A)); + PyDict_SetItemString(caseData, "Resolution", _val); + Py_DECREF(_val); - case 31: /* 3.3.32 Boot Integrity Services Entry Point */ + _val = dmi_voltage_probe_value(WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Tolerance", _val); + Py_DECREF(_val); - break; + _val = dmi_probe_accuracy(WORD(data + 0x0E)); + PyDict_SetItemString(caseData, "Accuracy", _val); + Py_DECREF(_val); - case 32: /* 3.3.33 System Boot Information */ + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x10)); + PyDict_SetItemString(caseData, "OEM-specific Information", _val); + Py_DECREF(_val); - if(h->length<0x0B) break; - _val = dmi_system_boot_status(data[0x0A]); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + if(h->length < 0x16) + break; + _val = dmi_voltage_probe_value(WORD(data + 0x14)); + PyDict_SetItemString(caseData, "Nominal Value", _val); + Py_DECREF(_val); - break; + break; - case 33: /* 3.3.34 64-bit Memory Error Information */ - if(h->length<0x1F) break; + case 27: /* 3.3.28 Cooling Device */ - _val = dmi_memory_error_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + if(h->length < 0x0C) + break; + if(WORD(data + 0x04) != 0xFFFF) { + _val = PyString_FromFormat("0x%04x", WORD(data + 0x04)); + PyDict_SetItemString(caseData, "Temperature Probe Handle", _val); + Py_DECREF(_val); + } - _val = dmi_memory_error_granularity(data[0x05]); - PyDict_SetItemString(caseData, "Granularity", _val); - Py_DECREF(_val); + _val = dmi_cooling_device_type(data[0x06] & 0x1f); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); - _val = dmi_memory_error_operation(data[0x06]); - PyDict_SetItemString(caseData, "Operation", _val); - Py_DECREF(_val); + _val = dmi_probe_status(data[0x06] >> 5); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); - _val = dmi_memory_error_syndrome(DWORD(data+0x07)); - PyDict_SetItemString(caseData, "Vendor Syndrome", _val); - Py_DECREF(_val); + if(data[0x07] != 0x00) { + _val = PyString_FromFormat("%i", data[0x07]); + PyDict_SetItemString(caseData, "Cooling Unit Group", _val); + Py_DECREF(_val); + } - _val = dmi_64bit_memory_error_address(QWORD(data+0x0B)); - PyDict_SetItemString(caseData, "Memory Array Address", _val); - Py_DECREF(_val); + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x08)); + PyDict_SetItemString(caseData, "OEM-specific Information", _val); + Py_DECREF(_val); - _val = dmi_64bit_memory_error_address(QWORD(data+0x13)); - PyDict_SetItemString(caseData, "Device Address", _val); - Py_DECREF(_val); + if(h->length < 0x0E) + break; + _val = dmi_cooling_device_speed(WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Nominal Speed", _val); + Py_DECREF(_val); - _val = dmi_32bit_memory_error_address(DWORD(data+0x1B)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + break; - break; + case 28: /* 3.3.29 Temperature Probe */ - case 34: /* 3.3.35 Management Device */ + if(h->length < 0x14) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Description", _val); + Py_DECREF(_val); - if(h->length<0x0B) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); + _val = dmi_temperature_probe_location(data[0x05] & 0x1F); + PyDict_SetItemString(caseData, "Location", _val); + Py_DECREF(_val); + + _val = dmi_probe_status(data[0x05] >> 5); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); - _val = dmi_management_device_type(data[0x05]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + _val = dmi_temperature_probe_value(WORD(data + 0x06)); + PyDict_SetItemString(caseData, "Maximum Value", _val); + Py_DECREF(_val); - _val = PyString_FromFormat("0x%08x", DWORD(data+0x06)); - PyDict_SetItemString(caseData, "Address", _val); - Py_DECREF(_val); + _val = dmi_temperature_probe_value(WORD(data + 0x08)); + PyDict_SetItemString(caseData, "Minimum Value", _val); + Py_DECREF(_val); - _val = dmi_management_device_address_type(data[0x0A]); - PyDict_SetItemString(caseData, "Address Type", _val); - Py_DECREF(_val); + _val = dmi_temperature_probe_resolution(WORD(data + 0x0A)); + PyDict_SetItemString(caseData, "Resolution", _val); + Py_DECREF(_val); - break; + _val = dmi_temperature_probe_value(WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Tolerance", _val); + Py_DECREF(_val); - case 35: /* 3.3.36 Management Device Component */ + _val = dmi_probe_accuracy(WORD(data + 0x0E)); + PyDict_SetItemString(caseData, "Accuracy", _val); + Py_DECREF(_val); - if(h->length<0x0B) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x10)); + PyDict_SetItemString(caseData, "OEM-specific Information", _val); + Py_DECREF(_val); - _val = PyString_FromFormat("0x%04x", WORD(data+0x05)); - PyDict_SetItemString(caseData, "Management Device Handle", _val); - Py_DECREF(_val); + if(h->length < 0x16) + break; + _val = dmi_temperature_probe_value(WORD(data + 0x14)); + PyDict_SetItemString(caseData, "Nominal Value", _val); + Py_DECREF(_val); - _val = PyString_FromFormat("0x%04x", WORD(data+0x07)); - PyDict_SetItemString(caseData, "Component Handle", _val); - Py_DECREF(_val); + break; - if(WORD(data+0x09)!=0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data+0x09)); - PyDict_SetItemString(caseData, "Threshold Handle", _val); - Py_DECREF(_val); - } + case 29: /* 3.3.30 Electrical Current Probe */ - break; + if(h->length < 0x14) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Description", _val); + Py_DECREF(_val); - case 36: /* 3.3.37 Management Device Threshold Data */ + _val = dmi_voltage_probe_location(data[5] & 0x1F); + PyDict_SetItemString(caseData, "Location", _val); + Py_DECREF(_val); - if(h->length<0x10) break; - if(WORD(data+0x04)!=0x8000) { - _val = PyString_FromFormat("%d", (i16)WORD(data+0x04)); - PyDict_SetItemString(caseData, "Lower Non-critical Threshold", _val); - Py_DECREF(_val); - } - if(WORD(data+0x06)!=0x8000) { - _val = PyString_FromFormat("%d", (i16)WORD(data+0x06)); - PyDict_SetItemString(caseData, "Upper Non-critical Threshold", _val); - Py_DECREF(_val); - } - if(WORD(data+0x08)!=0x8000) { - _val = PyString_FromFormat("%d", (i16)WORD(data+0x08)); - PyDict_SetItemString(caseData, "Lower Critical Threshold", _val); - Py_DECREF(_val); - } - if(WORD(data+0x0A)!=0x8000) { - _val = PyString_FromFormat("%d", (i16)WORD(data+0x0A)); - PyDict_SetItemString(caseData, "Upper Critical Threshold", _val); - Py_DECREF(_val); - } - if(WORD(data+0x0C)!=0x8000) { - _val = PyString_FromFormat("%d", (i16)WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Lower Non-recoverable Threshold", _val); - Py_DECREF(_val); - } - if(WORD(data+0x0E)!=0x8000) { - _val = PyString_FromFormat("%d", (i16)WORD(data+0x0E)); - PyDict_SetItemString(caseData, "Upper Non-recoverable Threshold", _val); - Py_DECREF(_val); - } + _val = dmi_probe_status(data[0x05] >> 5); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); - break; + _val = dmi_current_probe_value(WORD(data + 0x06)); + PyDict_SetItemString(caseData, "Maximum Value", _val); + Py_DECREF(_val); - case 37: /* 3.3.38 Memory Channel */ + _val = dmi_current_probe_value(WORD(data + 0x08)); + PyDict_SetItemString(caseData, "Minimum Value", _val); + Py_DECREF(_val); - if(h->length<0x07) break; - _val = dmi_memory_channel_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + _val = dmi_current_probe_resolution(WORD(data + 0x0A)); + PyDict_SetItemString(caseData, "Resolution", _val); + Py_DECREF(_val); - _val = PyString_FromFormat("%i", data[0x05]); - PyDict_SetItemString(caseData, "Maximal Load", _val); - Py_DECREF(_val); + _val = dmi_current_probe_value(WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Tolerance", _val); + Py_DECREF(_val); - _val = PyString_FromFormat("%i", data[0x06]); - PyDict_SetItemString(caseData, "Devices", _val); - Py_DECREF(_val); + _val = dmi_probe_accuracy(WORD(data + 0x0E)); + PyDict_SetItemString(caseData, "Accuracy", _val); + Py_DECREF(_val); - if(h->length<0x07+3*data[0x06]) break; - _val = dmi_memory_channel_devices(data[0x06], data+0x07); - PyDict_SetItemString(caseData, ">>>", _val); - Py_DECREF(_val); + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x10)); + PyDict_SetItemString(caseData, "OEM-specific Information", _val); + Py_DECREF(_val); - break; + if(h->length < 0x16) + break; + _val = dmi_current_probe_value(WORD(data + 0x14)); + PyDict_SetItemString(caseData, "Nominal Value", _val); + Py_DECREF(_val); - case 38: /* 3.3.39 IPMI Device Information */ - /* - * We use the word "Version" instead of "Revision", conforming to - * the IPMI specification. - */ + break; - if(h->length<0x10) break; - _val = dmi_ipmi_interface_type(data[0x04]); - PyDict_SetItemString(caseData, "Interface Type", _val); - Py_DECREF(_val); + case 30: /* 3.3.31 Out-of-band Remote Access */ - _val = PyString_FromFormat("%i.%i", data[0x05]>>4, data[0x05]&0x0F); - PyDict_SetItemString(caseData, "Specification Version", _val); - Py_DECREF(_val); + if(h->length < 0x06) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Manufacturer Name", _val); + Py_DECREF(_val); - _val = PyString_FromFormat("0x%02x", data[0x06]>>1); - PyDict_SetItemString(caseData, "I2C Slave Address", _val); - Py_DECREF(_val); + _val = data[0x05] & (1 << 0) ? Py_True : Py_False; + PyDict_SetItemString(caseData, "Inbound Connection Enabled", _val); + Py_DECREF(_val); - if(data[0x07]!=0xFF) { - _val = PyString_FromFormat("%i", data[0x07]); - PyDict_SetItemString(caseData, "NV Storage Device Address", _val); - Py_DECREF(_val); - } else { - _val = Py_None; - PyDict_SetItemString(caseData, "NV Storage Device: Not Present", _val); - Py_DECREF(_val); - } + _val = data[0x05] & (1 << 1) ? Py_True : Py_False; + PyDict_SetItemString(caseData, "Outbound Connection Enabled", _val); + Py_DECREF(_val); + break; - _val = dmi_ipmi_base_address(data[0x04], data+0x08, h->length<0x12?0:(data[0x10]>>5)&1); - PyDict_SetItemString(caseData, "Base Address", _val); - Py_DECREF(_val); + case 31: /* 3.3.32 Boot Integrity Services Entry Point */ - if(h->length<0x12) break; - if(data[0x04]!=0x04) { - _val = dmi_ipmi_register_spacing(data[0x10]>>6); - PyDict_SetItemString(caseData, "Register Spacing", _val); - Py_DECREF(_val); + break; - if(data[0x10]&(1<<3)) { - _val = PyString_FromFormat("%s", data[0x10]&(1<<1)?"Active High":"Active Low"); - PyDict_SetItemString(caseData, "Interrupt Polarity", _val); - Py_DECREF(_val); + case 32: /* 3.3.33 System Boot Information */ - _val = PyString_FromFormat("%s", data[0x10]&(1<<0)?"Level":"Edge"); - PyDict_SetItemString(caseData, "Interrupt Trigger Mode", _val); - Py_DECREF(_val); + if(h->length < 0x0B) + break; + _val = dmi_system_boot_status(data[0x0A]); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); + + break; + + case 33: /* 3.3.34 64-bit Memory Error Information */ + if(h->length < 0x1F) + break; + + _val = dmi_memory_error_type(data[0x04]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = dmi_memory_error_granularity(data[0x05]); + PyDict_SetItemString(caseData, "Granularity", _val); + Py_DECREF(_val); + + _val = dmi_memory_error_operation(data[0x06]); + PyDict_SetItemString(caseData, "Operation", _val); + Py_DECREF(_val); + + _val = dmi_memory_error_syndrome(DWORD(data + 0x07)); + PyDict_SetItemString(caseData, "Vendor Syndrome", _val); + Py_DECREF(_val); + + _val = dmi_64bit_memory_error_address(QWORD(data + 0x0B)); + PyDict_SetItemString(caseData, "Memory Array Address", _val); + Py_DECREF(_val); + + _val = dmi_64bit_memory_error_address(QWORD(data + 0x13)); + PyDict_SetItemString(caseData, "Device Address", _val); + Py_DECREF(_val); + + _val = dmi_32bit_memory_error_address(DWORD(data + 0x1B)); + PyDict_SetItemString(caseData, "Resolution", _val); + Py_DECREF(_val); + + break; + + case 34: /* 3.3.35 Management Device */ + + if(h->length < 0x0B) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Description", _val); + Py_DECREF(_val); + + _val = dmi_management_device_type(data[0x05]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%08x", DWORD(data + 0x06)); + PyDict_SetItemString(caseData, "Address", _val); + Py_DECREF(_val); + + _val = dmi_management_device_address_type(data[0x0A]); + PyDict_SetItemString(caseData, "Address Type", _val); + Py_DECREF(_val); + + break; + + case 35: /* 3.3.36 Management Device Component */ + + if(h->length < 0x0B) + break; + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(caseData, "Description", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%04x", WORD(data + 0x05)); + PyDict_SetItemString(caseData, "Management Device Handle", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%04x", WORD(data + 0x07)); + PyDict_SetItemString(caseData, "Component Handle", _val); + Py_DECREF(_val); + + if(WORD(data + 0x09) != 0xFFFF) { + _val = PyString_FromFormat("0x%04x", WORD(data + 0x09)); + PyDict_SetItemString(caseData, "Threshold Handle", _val); + Py_DECREF(_val); + } + + break; + + case 36: /* 3.3.37 Management Device Threshold Data */ + + if(h->length < 0x10) + break; + if(WORD(data + 0x04) != 0x8000) { + _val = PyString_FromFormat("%d", (i16) WORD(data + 0x04)); + PyDict_SetItemString(caseData, "Lower Non-critical Threshold", _val); + Py_DECREF(_val); + } + if(WORD(data + 0x06) != 0x8000) { + _val = PyString_FromFormat("%d", (i16) WORD(data + 0x06)); + PyDict_SetItemString(caseData, "Upper Non-critical Threshold", _val); + Py_DECREF(_val); + } + if(WORD(data + 0x08) != 0x8000) { + _val = PyString_FromFormat("%d", (i16) WORD(data + 0x08)); + PyDict_SetItemString(caseData, "Lower Critical Threshold", _val); + Py_DECREF(_val); + } + if(WORD(data + 0x0A) != 0x8000) { + _val = PyString_FromFormat("%d", (i16) WORD(data + 0x0A)); + PyDict_SetItemString(caseData, "Upper Critical Threshold", _val); + Py_DECREF(_val); + } + if(WORD(data + 0x0C) != 0x8000) { + _val = PyString_FromFormat("%d", (i16) WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Lower Non-recoverable Threshold", _val); + Py_DECREF(_val); + } + if(WORD(data + 0x0E) != 0x8000) { + _val = PyString_FromFormat("%d", (i16) WORD(data + 0x0E)); + PyDict_SetItemString(caseData, "Upper Non-recoverable Threshold", _val); + Py_DECREF(_val); + } + + break; + + case 37: /* 3.3.38 Memory Channel */ + + if(h->length < 0x07) + break; + _val = dmi_memory_channel_type(data[0x04]); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i", data[0x05]); + PyDict_SetItemString(caseData, "Maximal Load", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i", data[0x06]); + PyDict_SetItemString(caseData, "Devices", _val); + Py_DECREF(_val); + + if(h->length < 0x07 + 3 * data[0x06]) + break; + _val = dmi_memory_channel_devices(data[0x06], data + 0x07); + PyDict_SetItemString(caseData, ">>>", _val); + Py_DECREF(_val); + + break; + + case 38: /* 3.3.39 IPMI Device Information */ + /* + * We use the word "Version" instead of "Revision", conforming to + * the IPMI specification. + */ + + if(h->length < 0x10) + break; + _val = dmi_ipmi_interface_type(data[0x04]); + PyDict_SetItemString(caseData, "Interface Type", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%i.%i", data[0x05] >> 4, data[0x05] & 0x0F); + PyDict_SetItemString(caseData, "Specification Version", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("0x%02x", data[0x06] >> 1); + PyDict_SetItemString(caseData, "I2C Slave Address", _val); + Py_DECREF(_val); + + if(data[0x07] != 0xFF) { + _val = PyString_FromFormat("%i", data[0x07]); + PyDict_SetItemString(caseData, "NV Storage Device Address", _val); + Py_DECREF(_val); + } else { + _val = Py_None; + PyDict_SetItemString(caseData, "NV Storage Device: Not Present", _val); + Py_DECREF(_val); + } + + _val = + dmi_ipmi_base_address(data[0x04], data + 0x08, + h->length < 0x12 ? 0 : (data[0x10] >> 5) & 1); + PyDict_SetItemString(caseData, "Base Address", _val); + Py_DECREF(_val); + + if(h->length < 0x12) + break; + if(data[0x04] != 0x04) { + _val = dmi_ipmi_register_spacing(data[0x10] >> 6); + PyDict_SetItemString(caseData, "Register Spacing", _val); + Py_DECREF(_val); + + if(data[0x10] & (1 << 3)) { + _val = + PyString_FromFormat("%s", + data[0x10] & (1 << 1) ? "Active High" : + "Active Low"); + PyDict_SetItemString(caseData, "Interrupt Polarity", _val); + Py_DECREF(_val); + + _val = + PyString_FromFormat("%s", + data[0x10] & (1 << 0) ? "Level" : "Edge"); + PyDict_SetItemString(caseData, "Interrupt Trigger Mode", _val); + Py_DECREF(_val); + } + } + if(data[0x11] != 0x00) { + _val = PyString_FromFormat("%x", data[0x11]); + PyDict_SetItemString(caseData, "Interrupt Number", _val); + Py_DECREF(_val); + } + break; + + case 39: /* 3.3.40 System Power Supply */ + + if(h->length < 0x10) + break; + if(data[0x04] != 0x00) { + _val = PyString_FromFormat("%i", data[0x04]); + PyDict_SetItemString(caseData, "Power Unit Group", _val); + Py_DECREF(_val); + } + + _val = dmi_string_py(h, data[0x05]); + PyDict_SetItemString(caseData, "Location", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x06]); + PyDict_SetItemString(caseData, "Name", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x07]); + PyDict_SetItemString(caseData, "Manufacturer", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x08]); + PyDict_SetItemString(caseData, "Serial Numberr", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x09]); + PyDict_SetItemString(caseData, "Asset Tag", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x0A]); + PyDict_SetItemString(caseData, "Model Part Number", _val); + Py_DECREF(_val); + + _val = dmi_string_py(h, data[0x0B]); + PyDict_SetItemString(caseData, "Revision", _val); + Py_DECREF(_val); + + _val = dmi_power_supply_power(WORD(data + 0x0C)); + PyDict_SetItemString(caseData, "Max Power Capacity", _val); + Py_DECREF(_val); + + if(WORD(data + 0x0E) & (1 << 1)) { + _val = dmi_power_supply_status((WORD(data + 0x0E) >> 7) & 0x07); + PyDict_SetItemString(caseData, "Status Present", _val); + Py_DECREF(_val); + } else { + _val = PyString_FromString("Not Present"); + PyDict_SetItemString(caseData, "Status", _val); + Py_DECREF(_val); + } + _val = dmi_power_supply_type((WORD(data + 0x0E) >> 10) & 0x0F); + PyDict_SetItemString(caseData, "Type", _val); + Py_DECREF(_val); + + _val = dmi_power_supply_range_switching((WORD(data + 0x0E) >> 3) & 0x0F); + PyDict_SetItemString(caseData, "Input Voltage Range Switching", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%s", WORD(data + 0x0E) & (1 << 2) ? "No" : "Yes"); + PyDict_SetItemString(caseData, "Plugged", _val); + Py_DECREF(_val); + + _val = PyString_FromFormat("%s", WORD(data + 0x0E) & (1 << 0) ? "Yes" : "No"); + PyDict_SetItemString(caseData, "Hot Replaceable", _val); + Py_DECREF(_val); + + if(h->length < 0x16) + break; + if(WORD(data + 0x10) != 0xFFFF) { + _val = PyString_FromFormat("0x%04x", WORD(data + 0x10)); + PyDict_SetItemString(caseData, "Input Voltage Probe Handle", _val); + Py_DECREF(_val); + } + + if(WORD(data + 0x12) != 0xFFFF) { + _val = PyString_FromFormat("0x%04x", WORD(data + 0x12)); + PyDict_SetItemString(caseData, "Cooling Device Handle", _val); + Py_DECREF(_val); + } + + if(WORD(data + 0x14) != 0xFFFF) { + _val = PyString_FromFormat("0x%04x", WORD(data + 0x14)); + PyDict_SetItemString(caseData, "Input Current Probe Handle", _val); + Py_DECREF(_val); + } + + break; + + case 40: /* 3.3.41 Additional Information */ + if(h->length < 0x0B) + break; + _key = PyString_FromFormat("Additional Information"); + _val = dmi_additional_info(h, ""); + PyDict_SetItem(caseData, _key, _val); + Py_DECREF(_key); + Py_DECREF(_val); + break; + + case 41: /* 3.3.42 Onboard Device Extended Information */ + if(h->length < 0x0B) + break; + PyObject *subdata = PyDict_New(); + + _val = dmi_string_py(h, data[0x04]); + PyDict_SetItemString(subdata, "Reference Designation", _val); + Py_DECREF(_val); + + _val = PyString_FromString(dmi_on_board_devices_type(data[0x05] & 0x7F)); + PyDict_SetItemString(subdata, "Type", _val); + Py_DECREF(_val); + + _val = PyString_FromString(data[0x05] & 0x80 ? "Enabled" : "Disabled"); + PyDict_SetItemString(subdata, "Status", _val); + Py_DECREF(_val); + + _val = PyInt_FromLong(data[0x06]); + PyDict_SetItemString(subdata, "Type Instance", _val); + Py_DECREF(_val); + + _val = dmi_slot_segment_bus_func(WORD(data + 0x07), data[0x09], data[0x0A]); + PyDict_SetItemString(subdata, "Bus Address", _val); + Py_DECREF(_val); + + PyDict_SetItemString(caseData, "Onboard Device", subdata); + Py_DECREF(subdata); + break; + + case 126: /* 3.3.43 Inactive */ + _val = Py_None; + PyDict_SetItemString(caseData, "Inactive", _val); + Py_DECREF(_val); + break; + + case 127: /* 3.3.44 End Of Table */ + _val = Py_None; + PyDict_SetItemString(caseData, "End Of Table", _val); + Py_DECREF(_val); + break; + + default: + if(dmi_decode_oem(h)) + break; + _key = PyString_FromFormat("%s Type", h->type >= 128 ? "OEM-specific" : "Unknown"); + _val = dmi_dump(h); + PyDict_SetItem(caseData, _key, _val); + Py_DECREF(_key); + Py_DECREF(_val); } - } - if(data[0x11]!=0x00) { - _val = PyString_FromFormat("%x", data[0x11]); - PyDict_SetItemString(caseData, "Interrupt Number", _val); - Py_DECREF(_val); - } - break; - - case 39: /* 3.3.40 System Power Supply */ - - if(h->length<0x10) break; - if(data[0x04]!=0x00) { - _val = PyString_FromFormat("%i", data[0x04]); - PyDict_SetItemString(caseData, "Power Unit Group", _val); - Py_DECREF(_val); - } - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Name", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Serial Numberr", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x09]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - _val = dmi_string_py(h, data[0x0A]); - PyDict_SetItemString(caseData, "Model Part Number", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x0B]); - PyDict_SetItemString(caseData, "Revision", _val); - Py_DECREF(_val); + Py_INCREF(caseData); + return caseData; +} - _val = dmi_power_supply_power(WORD(data+0x0C)); - PyDict_SetItemString(caseData, "Max Power Capacity", _val); - Py_DECREF(_val); +void to_dmi_header(struct dmi_header *h, u8 * data) +{ + h->type = data[0]; + h->length = data[1]; + h->handle = WORD(data + 2); + h->data = data; +} - if(WORD(data+0x0E)&(1<<1)) { - _val = dmi_power_supply_status((WORD(data+0x0E)>>7)&0x07); - PyDict_SetItemString(caseData, "Status Present", _val); - Py_DECREF(_val); - } else { - _val = PyString_FromString("Not Present"); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - } - _val = dmi_power_supply_type((WORD(data+0x0E)>>10)&0x0F); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_power_supply_range_switching((WORD(data+0x0E)>>3)&0x0F); - PyDict_SetItemString(caseData, "Input Voltage Range Switching", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%s", WORD(data+0x0E)&(1<<2)?"No":"Yes"); - PyDict_SetItemString(caseData, "Plugged", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%s", WORD(data+0x0E)&(1<<0)?"Yes":"No"); - PyDict_SetItemString(caseData, "Hot Replaceable", _val); - Py_DECREF(_val); - - if(h->length<0x16) break; - if(WORD(data+0x10)!=0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data+0x10)); - PyDict_SetItemString(caseData, "Input Voltage Probe Handle", _val); - Py_DECREF(_val); - } +static void dmi_table_string_py(const struct dmi_header *h, const u8 * data, PyObject * hDict, + u16 ver) +{ + int key; + u8 offset = opt.string->offset; - if(WORD(data+0x12)!=0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data+0x12)); - PyDict_SetItemString(caseData, "Cooling Device Handle", _val); - Py_DECREF(_val); - } + if(offset >= h->length) + return; - if(WORD(data+0x14)!=0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data+0x14)); - PyDict_SetItemString(caseData, "Input Current Probe Handle", _val); + //. TODO: These should have more meaningful dictionary names + key = (opt.string->type << 8) | offset; + PyObject *_val; + + switch (key) { + case 0x108: + _val = dmi_system_uuid_py(data + offset, ver); + PyDict_SetItemString(hDict, "0x108", _val); + break; + case 0x305: + _val = dmi_chassis_type_py(data[offset]); + PyDict_SetItemString(hDict, "0x305", _val); + case 0x406: + _val = PyString_FromString(dmi_processor_family(h)); + PyDict_SetItemString(hDict, "0x406", _val); + break; + case 0x416: + _val = dmi_processor_frequency_py((u8 *) data + offset); + PyDict_SetItemString(hDict, "0x416", _val); + break; + default: + _val = dmi_string_py(h, data[offset]); + PyDict_SetItemString(hDict, "0x???", _val); + } Py_DECREF(_val); - } - - break; - - case 40: /* 3.3.41 Additional Information */ - if(h->length < 0x0B) break; - _key = PyString_FromFormat("Additional Information"); - _val = dmi_additional_info(h, ""); - PyDict_SetItem(caseData, _key, _val); - Py_DECREF(_key); - Py_DECREF(_val); - break; - - case 41: /* 3.3.42 Onboard Device Extended Information */ - if (h->length < 0x0B) break; - PyObject *subdata = PyDict_New(); - - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(subdata, "Reference Designation", _val); - Py_DECREF(_val); - - _val = PyString_FromString(dmi_on_board_devices_type(data[0x05] & 0x7F)); - PyDict_SetItemString(subdata, "Type", _val); - Py_DECREF(_val); - - _val = PyString_FromString(data[0x05]&0x80 ? "Enabled" : "Disabled"); - PyDict_SetItemString(subdata, "Status", _val); - Py_DECREF(_val); - - _val = PyInt_FromLong(data[0x06]); - PyDict_SetItemString(subdata, "Type Instance", _val); - Py_DECREF(_val); - - _val = dmi_slot_segment_bus_func(WORD(data + 0x07), data[0x09], data[0x0A]); - PyDict_SetItemString(subdata, "Bus Address", _val); - Py_DECREF(_val); - - PyDict_SetItemString(caseData, "Onboard Device", subdata); - Py_DECREF(subdata); - break; - - case 126: /* 3.3.43 Inactive */ - _val = Py_None; - PyDict_SetItemString(caseData, "Inactive", _val); - Py_DECREF(_val); - break; - - case 127: /* 3.3.44 End Of Table */ - _val = Py_None; - PyDict_SetItemString(caseData, "End Of Table", _val); - Py_DECREF(_val); - break; - - default: - if(dmi_decode_oem(h)) break; - _key = PyString_FromFormat("%s Type", h->type>=128?"OEM-specific":"Unknown"); - _val = dmi_dump(h); - PyDict_SetItem(caseData, _key, _val); - Py_DECREF(_key); - Py_DECREF(_val); - } - - Py_INCREF(caseData); - return caseData; -} - -void to_dmi_header(struct dmi_header *h, u8 *data) { - h->type=data[0]; - h->length=data[1]; - h->handle=WORD(data+2); - h->data=data; -} - -static void dmi_table_string_py(const struct dmi_header *h, const u8 *data, PyObject *hDict, u16 ver) { - int key; - u8 offset = opt.string->offset; - - if (offset >= h->length) return; - - //. TODO: These should have more meaningful dictionary names - key = (opt.string->type << 8) | offset; - PyObject *_val; - switch(key) { - case 0x108: - _val = dmi_system_uuid_py(data+offset, ver); - PyDict_SetItemString(hDict, "0x108", _val); - break; - case 0x305: - _val = dmi_chassis_type_py(data[offset]); - PyDict_SetItemString(hDict, "0x305", _val); - case 0x406: - _val = PyString_FromString(dmi_processor_family(h)); - PyDict_SetItemString(hDict, "0x406", _val); - break; - case 0x416: - _val = dmi_processor_frequency_py((u8 *)data + offset); - PyDict_SetItemString(hDict, "0x416", _val); - break; - default: - _val = dmi_string_py(h, data[offset]); - PyDict_SetItemString(hDict, "0x???", _val); - } - Py_DECREF(_val); } /* @@ -4459,327 +5012,369 @@ static void dmi_table_dump(u32 base, u16 len, const char *devmem) * as this is where we will put it in the output file. We adjust the * DMI checksum appropriately. The SMBIOS checksum needs no adjustment. */ -static void overwrite_dmi_address(u8 *buf) { - buf[0x05] += buf[0x08] + buf[0x09] + buf[0x0A] + buf[0x0B] - 32; - buf[0x08] = 32; - buf[0x09] = 0; - buf[0x0A] = 0; - buf[0x0B] = 0; +static void overwrite_dmi_address(u8 * buf) +{ + buf[0x05] += buf[0x08] + buf[0x09] + buf[0x0A] + buf[0x0B] - 32; + buf[0x08] = 32; + buf[0x09] = 0; + buf[0x0A] = 0; + buf[0x0B] = 0; } - #define NON_LEGACY 0 #define LEGACY 1 -int dumpling(u8 *buf, const char *dumpfile, u8 mode) { - u32 base; - u16 len; - if(mode == NON_LEGACY) { - if(!checksum(buf, buf[0x05]) || !memcmp(buf+0x10, "_DMI_", 5)==0 || !checksum(buf+0x10, 0x0F)) return 0; - base = DWORD(buf+0x18); - len = WORD(buf+0x16); - } else { - if(!checksum(buf, 0x0F)) return 0; - base = DWORD(buf+0x08); - len = WORD(buf+0x06); - } - - u8 *buff; - if((buff = mem_chunk(base, len, DEFAULT_MEM_DEV)) != NULL) { - //. Part 1. - printf("# Writing %d bytes to %s.\n", len, dumpfile); - write_dump(32, len, buff, dumpfile, 0); - free(buff); - - //. Part 2. - if(mode != LEGACY) { - u8 crafted[32]; - memcpy(crafted, buf, 32); - overwrite_dmi_address(crafted+0x10); - printf("# Writing %d bytes to %s.\n", crafted[0x05], dumpfile); - write_dump(0, crafted[0x05], crafted, dumpfile, 1); - } else { - u8 crafted[16]; - memcpy(crafted, buf, 16); - overwrite_dmi_address(crafted); - printf("# Writing %d bytes to %s.\n", 0x0F, dumpfile); - write_dump(0, 0x0F, crafted, dumpfile, 1); - } - } else { - fprintf(stderr, "Failed to read table, sorry.\n"); - } - - //. TODO: Cleanup - return 1; -} - -int dump(const char *dumpfile) { - /* On success, return found, otherwise return -1 */ - int ret=0; - int found=0; - size_t fp; - int efi; - u8 *buf; - - /* First try EFI (ia64, Intel-based Mac) */ - efi = address_from_efi(&fp); - if(efi == EFI_NOT_FOUND) { - /* Fallback to memory scan (x86, x86_64) */ - if((buf=mem_chunk(0xF0000, 0x10000, DEFAULT_MEM_DEV))!=NULL) { - for(fp=0; fp<=0xFFF0; fp+=16) { - if(memcmp(buf+fp, "_SM_", 4)==0 && fp<=0xFFE0) { - if(dumpling(buf+fp, dumpfile, NON_LEGACY)) found++; - fp+=16; - } else if(memcmp(buf+fp, "_DMI_", 5)==0) { - if(dumpling(buf+fp, dumpfile, LEGACY)) found++; +int dumpling(u8 * buf, const char *dumpfile, u8 mode) +{ + u32 base; + u16 len; + + if(mode == NON_LEGACY) { + if(!checksum(buf, buf[0x05]) || !memcmp(buf + 0x10, "_DMI_", 5) == 0 || + !checksum(buf + 0x10, 0x0F)) + return 0; + base = DWORD(buf + 0x18); + len = WORD(buf + 0x16); + } else { + if(!checksum(buf, 0x0F)) + return 0; + base = DWORD(buf + 0x08); + len = WORD(buf + 0x06); } - } - } else ret = -1; - } else if(efi == EFI_NO_SMBIOS) { - ret = -1; - } else { - if((buf=mem_chunk(fp, 0x20, DEFAULT_MEM_DEV))==NULL) ret = -1; - else if(dumpling(buf, dumpfile, NON_LEGACY)) found++; - } - - if(ret==0) { - free(buf); - //. TODO: Exception - //dmiSetItem(pydata, "detect", "No SMBIOS nor DMI entry point found, sorry G."); - if(!found) ret = -1; - } + u8 *buff; + + if((buff = mem_chunk(base, len, DEFAULT_MEM_DEV)) != NULL) { + //. Part 1. + printf("# Writing %d bytes to %s.\n", len, dumpfile); + write_dump(32, len, buff, dumpfile, 0); + free(buff); + + //. Part 2. + if(mode != LEGACY) { + u8 crafted[32]; + + memcpy(crafted, buf, 32); + overwrite_dmi_address(crafted + 0x10); + printf("# Writing %d bytes to %s.\n", crafted[0x05], dumpfile); + write_dump(0, crafted[0x05], crafted, dumpfile, 1); + } else { + u8 crafted[16]; + + memcpy(crafted, buf, 16); + overwrite_dmi_address(crafted); + printf("# Writing %d bytes to %s.\n", 0x0F, dumpfile); + write_dump(0, 0x0F, crafted, dumpfile, 1); + } + } else { + fprintf(stderr, "Failed to read table, sorry.\n"); + } - return ret==0?found:ret; + //. TODO: Cleanup + return 1; } +int dump(const char *dumpfile) +{ + /* On success, return found, otherwise return -1 */ + int ret = 0; + int found = 0; + size_t fp; + int efi; + u8 *buf; + /* First try EFI (ia64, Intel-based Mac) */ + efi = address_from_efi(&fp); + if(efi == EFI_NOT_FOUND) { + /* Fallback to memory scan (x86, x86_64) */ + if((buf = mem_chunk(0xF0000, 0x10000, DEFAULT_MEM_DEV)) != NULL) { + for(fp = 0; fp <= 0xFFF0; fp += 16) { + if(memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) { + if(dumpling(buf + fp, dumpfile, NON_LEGACY)) + found++; + fp += 16; + } else if(memcmp(buf + fp, "_DMI_", 5) == 0) { + if(dumpling(buf + fp, dumpfile, LEGACY)) + found++; + } + } + } else + ret = -1; + } else if(efi == EFI_NO_SMBIOS) { + ret = -1; + } else { + if((buf = mem_chunk(fp, 0x20, DEFAULT_MEM_DEV)) == NULL) + ret = -1; + else if(dumpling(buf, dumpfile, NON_LEGACY)) + found++; + } + + if(ret == 0) { + free(buf); -static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, PyObject *pydata) { - u8 *buf; - u8 *data; - int i=0; + //. TODO: Exception + //dmiSetItem(pydata, "detect", "No SMBIOS nor DMI entry point found, sorry G."); + if(!found) + ret = -1; + } + + return ret == 0 ? found : ret; +} - if(opt.type==NULL) { - dmiSetItem(pydata, "dmi_table_size", "%i structures occupying %i bytes", num, len); - /* TODO DUMP - if (!(opt.flags & FLAG_FROM_DUMP)) - dmiSetItem(pydata, "dmi_table_base", "Table at 0x%08x", base); - */ - dmiSetItem(pydata, "dmi_table_base", "Table at 0x%08x", base); - } +static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, PyObject * pydata) +{ + u8 *buf; + u8 *data; + int i = 0; + + if(opt.type == NULL) { + dmiSetItem(pydata, "dmi_table_size", "%i structures occupying %i bytes", num, len); + /* TODO DUMP + * if (!(opt.flags & FLAG_FROM_DUMP)) + * dmiSetItem(pydata, "dmi_table_base", "Table at 0x%08x", base); + */ + dmiSetItem(pydata, "dmi_table_base", "Table at 0x%08x", base); + } - if((buf=mem_chunk(base, len, devmem))==NULL) { - fprintf(stderr, "Table is unreachable, sorry." + if((buf = mem_chunk(base, len, devmem)) == NULL) { + fprintf(stderr, "Table is unreachable, sorry." #ifndef USE_MMAP - "Try compiling dmidecode with -DUSE_MMAP."; + "Try compiling dmidecode with -DUSE_MMAP."; #endif - "\n"); - return; - } + "\n"); + return; + } - data=buf; - while(i39 && h.type<=127) - && !opt.string); - - /* - ** If a short entry is found (less than 4 bytes), not only it - ** is invalid, but we cannot reliably locate the next entry. - ** Better stop at this point, and let the user know his/her - ** table is broken. - */ - if(h.length<4) { - fprintf(stderr, "Invalid entry length (%i). DMI table is broken! Stop.", (unsigned int)h.length); - break; - } - - /* In quiet mode (FLAG_QUIET - removed for python-dmidecode all together), stop decoding at end of table marker */ - - char hid[7]; - sprintf(hid, "0x%04x", h.handle); - PyObject *hDict = PyDict_New(); - dmiSetItem(hDict, "dmi_handle", hid); - dmiSetItem(hDict, "dmi_type", "%d", h.type); - dmiSetItem(hDict, "dmi_size", "%d", h.length); - - /* assign vendor for vendor-specific decodes later */ - if(h.type==0 && h.length>=5) - dmi_set_vendor(dmi_string(&h, data[0x04])); - - /* look for the next handle */ - next=data+h.length; - while(next-buf+1"); - } else if(opt.string!=NULL && opt.string->type==h.type) { - dmi_table_string_py(&h, data, hDict, ver); - } - - data=next; - i++; - } - - if(i!=num) - fprintf(stderr, "Wrong DMI structures count: %d announced, only %d decoded.\n", num, i); - if(data-buf!=len) - fprintf(stderr, "Wrong DMI structures length: %d bytes announced, structures occupy %d bytes.\n", - len, (unsigned int)(data-buf)); - - free(buf); -} - - - - -int _smbios_decode_check(u8 *buf) { - int check = (!checksum(buf, buf[0x05]) || memcmp(buf + 0x10, "_DMI_", 5)!=0 || !checksum(buf+0x10, 0x0F)) ? 0 : 1; - return check; -} -int smbios_decode_set_version(u8 *buf, const char *devmem, PyObject** pydata) { - int check = _smbios_decode_check(buf); - char vbuf[64]; bzero(vbuf, 64); - if(check == 1) { - u16 ver = (buf[0x06] << 8) + buf[0x07]; - /* Some BIOS report weird SMBIOS version, fix that up */ - int _m, _M; - _m = 0; - _M = 0; - switch(ver) { - case 0x021F: - _m = 31; - _M = 3; - ver = 0x0203; - break; - case 0x0233: - _m = 51; - _M = 6; - ver = 0x0206; - break; - } - if(_m || _M) sprintf(vbuf, "SMBIOS %i.%i present (Version fixup 2.%d -> 2.%d)", ver>>8, ver&0xFF, _m, _M); - else sprintf(vbuf, "SMBIOS %i.%i present", ver>>8, ver&0xFF); - } else if(check == 0) { - sprintf(vbuf, "No SMBIOS nor DMI entry point found"); - } - if(check == 1) { - if(*pydata) { Py_DECREF(*pydata); } - *pydata = PyString_FromString(vbuf); - Py_INCREF(*pydata); - } - return check; -} -int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata) { - int check = _smbios_decode_check(buf); - if(check == 1) { - u16 ver = (buf[0x06] << 8) + buf[0x07]; - switch(ver) { - case 0x021F: - ver = 0x0203; - break; - case 0x0233: - ver = 0x0206; - break; - } - //printf(">>%d @ %d, %d<<\n", DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C)); - dmi_table(DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C), ver, devmem, pydata); - } - return check; -} - - - - -int _legacy_decode_check(u8 *buf) { - int check; - if(!checksum(buf, 0x0F)) check = 0; //. Bad - else check = 1; //. Good - return check; -} -int legacy_decode_set_version(u8 *buf, const char *devmem, PyObject** pydata) { - int check = _legacy_decode_check(buf); - char vbuf[64]; bzero(vbuf, 64); - if(check == 1) { - sprintf(vbuf, "Legacy DMI %i.%i present", buf[0x0E]>>4, buf[0x0E]&0x0F); - } else if(check == 0) { - sprintf(vbuf, "No SMBIOS nor DMI entry point found"); - } - if(check == 1) { - if(*pydata) { Py_DECREF(*pydata); } - *pydata = PyString_FromString(vbuf); - Py_INCREF(*pydata); - } - return check; -} -int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata) { - int check = _legacy_decode_check(buf); - if(check == 1) - dmi_table(DWORD(buf+0x08), WORD(buf+0x06), WORD(buf+0x0C), ((buf[0x0E]&0xF0)<<4)+(buf[0x0E]&0x0F), devmem, pydata); - return check; + && !opt.string); + + /* + ** If a short entry is found (less than 4 bytes), not only it + ** is invalid, but we cannot reliably locate the next entry. + ** Better stop at this point, and let the user know his/her + ** table is broken. + */ + if(h.length < 4) { + fprintf(stderr, "Invalid entry length (%i). DMI table is broken! Stop.", + (unsigned int)h.length); + break; + } + + /* In quiet mode (FLAG_QUIET - removed for python-dmidecode all together), stop decoding at end of table marker */ + + char hid[7]; + + sprintf(hid, "0x%04x", h.handle); + PyObject *hDict = PyDict_New(); + + dmiSetItem(hDict, "dmi_handle", hid); + dmiSetItem(hDict, "dmi_type", "%d", h.type); + dmiSetItem(hDict, "dmi_size", "%d", h.length); + + /* assign vendor for vendor-specific decodes later */ + if(h.type == 0 && h.length >= 5) + dmi_set_vendor(dmi_string(&h, data[0x04])); + + /* look for the next handle */ + next = data + h.length; + while(next - buf + 1 < len && (next[0] != 0 || next[1] != 0)) + next++; + + next += 2; + + if(display) { + if(next - buf <= len) { + /* TODO: ... + * if(opt.flags & FLAG_DUMP) { + * PyDict_SetItem(hDict, PyString_FromString("lookup"), dmi_dump(&h)); + * } else { + * //. TODO: //. Is the value of `i' important?... + * //. TODO: PyDict_SetItem(hDict, PyInt_FromLong(i), dmi_decode(&h, ver)); + * //. TODO: ...removed and replaced with `data'... + * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); + * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); + * } */ + PyDict_SetItem(hDict, PyString_FromString("data"), + dmi_decode(&h, ver)); + PyDict_SetItem(pydata, PyString_FromString(hid), hDict); + } else + fprintf(stderr, ""); + } else if(opt.string != NULL && opt.string->type == h.type) { + dmi_table_string_py(&h, data, hDict, ver); + } + + data = next; + i++; + } + + if(i != num) + fprintf(stderr, "Wrong DMI structures count: %d announced, only %d decoded.\n", num, + i); + if(data - buf != len) + fprintf(stderr, + "Wrong DMI structures length: %d bytes announced, structures occupy %d bytes.\n", + len, (unsigned int)(data - buf)); + + free(buf); +} + +int _smbios_decode_check(u8 * buf) +{ + int check = (!checksum(buf, buf[0x05]) || memcmp(buf + 0x10, "_DMI_", 5) != 0 || + !checksum(buf + 0x10, 0x0F)) ? 0 : 1; + return check; +} +int smbios_decode_set_version(u8 * buf, const char *devmem, PyObject ** pydata) +{ + int check = _smbios_decode_check(buf); + char vbuf[64]; + + bzero(vbuf, 64); + if(check == 1) { + u16 ver = (buf[0x06] << 8) + buf[0x07]; + + /* Some BIOS report weird SMBIOS version, fix that up */ + int _m, _M; + + _m = 0; + _M = 0; + switch (ver) { + case 0x021F: + _m = 31; + _M = 3; + ver = 0x0203; + break; + case 0x0233: + _m = 51; + _M = 6; + ver = 0x0206; + break; + } + if(_m || _M) + sprintf(vbuf, "SMBIOS %i.%i present (Version fixup 2.%d -> 2.%d)", ver >> 8, + ver & 0xFF, _m, _M); + else + sprintf(vbuf, "SMBIOS %i.%i present", ver >> 8, ver & 0xFF); + } else if(check == 0) { + sprintf(vbuf, "No SMBIOS nor DMI entry point found"); + } + if(check == 1) { + if(*pydata) { + Py_DECREF(*pydata); + } + *pydata = PyString_FromString(vbuf); + Py_INCREF(*pydata); + } + return check; +} +int smbios_decode(u8 * buf, const char *devmem, PyObject * pydata) +{ + int check = _smbios_decode_check(buf); + + if(check == 1) { + u16 ver = (buf[0x06] << 8) + buf[0x07]; + + switch (ver) { + case 0x021F: + ver = 0x0203; + break; + case 0x0233: + ver = 0x0206; + break; + } + //printf(">>%d @ %d, %d<<\n", DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C)); + dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, + pydata); + } + return check; } +int _legacy_decode_check(u8 * buf) +{ + int check; + if(!checksum(buf, 0x0F)) + check = 0; //. Bad + else + check = 1; //. Good + return check; +} +int legacy_decode_set_version(u8 * buf, const char *devmem, PyObject ** pydata) +{ + int check = _legacy_decode_check(buf); + char vbuf[64]; + + bzero(vbuf, 64); + if(check == 1) { + sprintf(vbuf, "Legacy DMI %i.%i present", buf[0x0E] >> 4, buf[0x0E] & 0x0F); + } else if(check == 0) { + sprintf(vbuf, "No SMBIOS nor DMI entry point found"); + } + if(check == 1) { + if(*pydata) { + Py_DECREF(*pydata); + } + *pydata = PyString_FromString(vbuf); + Py_INCREF(*pydata); + } + return check; +} +int legacy_decode(u8 * buf, const char *devmem, PyObject * pydata) +{ + int check = _legacy_decode_check(buf); + if(check == 1) + dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), + ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, pydata); + return check; +} /******************************************************************************* ** Probe for EFI interface */ -int address_from_efi(size_t *address) { - FILE *efi_systab; - const char *filename; - char linebuf[64]; - int ret; - - *address = 0; /* Prevent compiler warning */ - - /* - ** Linux <= 2.6.6: /proc/efi/systab - ** Linux >= 2.6.7: /sys/firmware/efi/systab - */ - if((efi_systab=fopen(filename="/sys/firmware/efi/systab", "r"))==NULL - && (efi_systab=fopen(filename="/proc/efi/systab", "r"))==NULL) { - /* No EFI interface, fallback to memory scan */ - return EFI_NOT_FOUND; - } - ret=EFI_NO_SMBIOS; - while((fgets(linebuf, sizeof(linebuf)-1, efi_systab))!=NULL) { - char *addrp=strchr(linebuf, '='); - *(addrp++)='\0'; - if(strcmp(linebuf, "SMBIOS")==0) { - *address=strtoul(addrp, NULL, 0); - printf("# SMBIOS entry point at 0x%08lx\n", (unsigned long)*address); - ret=0; - break; - } - } - if(fclose(efi_systab)!=0) - perror(filename); - - if(ret==EFI_NO_SMBIOS) - fprintf(stderr, "%s: SMBIOS entry point missing\n", filename); - - return ret; +int address_from_efi(size_t * address) +{ + FILE *efi_systab; + const char *filename; + char linebuf[64]; + int ret; + + *address = 0; /* Prevent compiler warning */ + + /* + ** Linux <= 2.6.6: /proc/efi/systab + ** Linux >= 2.6.7: /sys/firmware/efi/systab + */ + if((efi_systab = fopen(filename = "/sys/firmware/efi/systab", "r")) == NULL + && (efi_systab = fopen(filename = "/proc/efi/systab", "r")) == NULL) { + /* No EFI interface, fallback to memory scan */ + return EFI_NOT_FOUND; + } + ret = EFI_NO_SMBIOS; + while((fgets(linebuf, sizeof(linebuf) - 1, efi_systab)) != NULL) { + char *addrp = strchr(linebuf, '='); + + *(addrp++) = '\0'; + if(strcmp(linebuf, "SMBIOS") == 0) { + *address = strtoul(addrp, NULL, 0); + printf("# SMBIOS entry point at 0x%08lx\n", (unsigned long)*address); + ret = 0; + break; + } + } + if(fclose(efi_systab) != 0) + perror(filename); + + if(ret == EFI_NO_SMBIOS) + fprintf(stderr, "%s: SMBIOS entry point missing\n", filename); + + return ret; } -- cgit From 0cdb1cbffae8237635b991993ee4467e2753dafa Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 7 Apr 2009 09:27:47 +0200 Subject: Checked in a work in progress - Python dict -> XML Does not compile yet --- src/dmidecode.c | 2364 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 1244 insertions(+), 1120 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index d687c81..907fe57 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -70,11 +70,13 @@ #include #include #include +#include #include "version.h" #include "config.h" #include "types.h" #include "util.h" +#include "dmixml.h" #include "dmidecode.h" #include "dmioem.h" @@ -151,54 +153,75 @@ const char *dmi_string(const struct dmi_header *dm, u8 s) return bp; } -static const char *dmi_smbios_structure_type(u8 code) +xmlNode *dmi_smbios_structure_type(xmlNode *node, u8 code) { - static const char *type[] = { - "BIOS", /* 0 */ - "System", - "Base Board", - "Chassis", - "Processor", - "Memory Controller", - "Memory Module", - "Cache", - "Port Connector", - "System Slots", - "On Board Devices", - "OEM Strings", - "System Configuration Options", - "BIOS Language", - "Group Associations", - "System Event Log", - "Physical Memory Array", - "Memory Device", - "32-bit Memory Error", - "Memory Array Mapped Address", - "Memory Device Mapped Address", - "Built-in Pointing Device", - "Portable Battery", - "System Reset", - "Hardware Security", - "System Power Controls", - "Voltage Probe", - "Cooling Device", - "Temperature Probe", - "Electrical Current Probe", - "Out-of-band Remote Access", - "Boot Integrity Services", - "System Boot", - "64-bit Memory Error", - "Management Device", - "Management Device Component", - "Management Device Threshold Data", - "Memory Channel", - "IPMI Device", - "Power Supply" /* 39 */ + static struct { + const char *descr; + const char *tagname; + const char *attrname; + const char *attrvalue; + } types[] = { + /* *INDENT-OFF* */ + {"BIOS", "BIOS", NULL, NULL}, /* 0 */ + {"System", "System", NULL, NULL}, + {"Base Board", "BaseBoard", NULL, NULL}, + {"Chassis", "Chassis", NULL, NULL}, + {"Processor", "Processor", NULL, NULL}, + {"Memory Controller", "Memory", "type", "controller"}, + {"Memory Module", "Memory", "type", "module"}, + {"Cache", "Cache", NULL, NULL}, + {"Port Connector", "PortConnectors", NULL, NULL}, + {"System Slots", "Slots", NULL, NULL}, + {"On Board Devices", "OnBoardDevices", NULL, NULL}, + {"OEM Strings", "OEMstrings", NULL, NULL}, + {"System Configuration Options", "SysConfigOpts", NULL, NULL}, + {"BIOS Language", "BIOS", "type", "language"}, + {"Group Associations", "GroupAssociations", NULL, NULL}, + {"System Event Log", "EventLog", NULL, NULL}, + {"Physical Memory Array", "PhysicalMemoryArray", NULL, NULL}, + {"Memory Device", "Memory", "type", "device"}, + {"32-bit Memory Error", "MemoryError", "bit", "32"}, + {"Memory Array Mapped Address", "MemoryAddressMap", "type", "MemoryArray"}, + {"Memory Device Mapped Address", "MemoryAddressMap", "type", "Device"}, + {"Built-in Pointing Device", "BuiltinPointingDevice",NULL, NULL}, + {"Portable Battery", "PortableBattery", NULL, NULL}, + {"System Reset", "SystemReset", NULL, NULL}, + {"Hardware Security", "HWsecurity", NULL, NULL}, + {"System Power Controls", "SysPowerCtrl", NULL, NULL}, + {"Voltage Probe", "Probe", "type", "Voltage"}, + {"Cooling Device", "CoolingDevice", NULL, NULL}, + {"Temperature Probe", "Probe", "type", "Temperature"}, + {"Electrical Current Probe", "Probe", "type", "ElectricalCurrent"}, + {"Out-of-band Remote Access", "RemoteAccess", NULL, NULL}, + {"Boot Integrity Services", "BootIntegritySrv", NULL, NULL}, + {"System Boot", "SystemBoot", NULL, NULL}, + {"64-bit Memory Error", "MemoryError", "bit", "64"}, + {"Management Device", "ManagementDevice", NULL, NULL}, + {"Management Device Component", "ManagementDevice", "type", "component"}, + {"Management Device Threshold Data","ManagementDevice", "type", "Threshold Data"}, + {"Memory Channel", "MemoryChannel", NULL, NULL}, + {"IPMI Device", "IPMIdevice", NULL, NULL}, + {"Power Supply", "PowerSupply", NULL, NULL} /* 39 */ + /* *INDENT-ON* */ }; + xmlNode *type_n = NULL; + + if(code <= 39) { + type_n = xmlNewChild(node, NULL, (xmlChar *)types[code].tagname, NULL); + assert( type_n != NULL ); + + dmixml_AddAttribute(type_n, "flags", "0x%04x", code); + dmixml_AddTextChild(type_n, "Description", "%s", types[code].descr); - if(code <= 39) - return (type[code]); - return out_of_spec; + if( (types[code].attrname != NULL) && (types[code].attrvalue != NULL) ) { + dmixml_AddAttribute(type_n, types[code].attrname, "%s", types[code].attrvalue); + } + } else { + type_n = xmlNewChild(node, NULL, (xmlChar *) "UnknownSMBiosType", NULL); + dmixml_AddAttribute(type_n, "flags", "0x%04x", code); + } + + return type_n; } static int dmi_bcd_range(u8 value, u8 low, u8 high) @@ -262,7 +285,7 @@ static PyObject *dmi_bios_runtime_size(u32 code) } /* 3.3.1.1 */ -static PyObject *dmi_bios_characteristics(u64 code) +void dmi_bios_characteristics(xmlNode *node, u64 code) { static const char *characteristics[] = { "BIOS characteristics not supported", /* 3 */ @@ -295,25 +318,28 @@ static PyObject *dmi_bios_characteristics(u64 code) "CGA/mono video services are supported (int 10h)", "NEC PC-98" /* 31 */ }; - - PyObject *data; + dmixml_AddAttribute(node, "dmispec", "3.3.1.1"); + dmixml_AddAttribute(node, "flags", "0x%04x", code); if(code.l & (1 << 3)) { - data = PyString_FromString(characteristics[0]); + dmixml_AddAttribute(node, "unavailable", "1"); + dmixml_AddTextContent(node, characteristics[0]); } else { - int i; + int i = 0; + xmlNode *flags_n = xmlNewChild(node, NULL, (xmlChar *) "flags", NULL); + assert( flags_n != NULL ); - data = PyDict_New(); for(i = 4; i <= 31; i++) - PyDict_SetItemString(data, characteristics[i - 3], - code.l & (1 << i) ? Py_True : Py_False); + if( code.l & (1 << i) ) { + dmixml_AddTextChild(flags_n, "flag", characteristics[i - 3]); + } } - return data; } /* 3.3.1.2.1 */ -static PyObject *dmi_bios_characteristics_x1(u8 code) +void dmi_bios_characteristics_x1(xmlNode *node, u8 code) { + int i = 0; static const char *characteristics[] = { "ACPI", /* 0 */ "USB legacy", @@ -325,42 +351,45 @@ static PyObject *dmi_bios_characteristics_x1(u8 code) "Smart battery" /* 7 */ }; - int i; - PyObject *data = PyDict_New(); - - for(i = 0; i <= 7; i++) - PyDict_SetItemString(data, characteristics[i], - code & (1 << i) ? Py_True : Py_False); - return data; + dmixml_AddAttribute(node, "dmispec", "3.3.1.2.1"); + dmixml_AddAttribute(node, "flags", "0x%04x", code); + for(i = 0; i <= 7; i++) { + if( code.l & (1 << i) ) { + dmixml_AddTextChild(node, "characteristic", characteristics[i]); + } + } } /* 3.3.1.2.2 */ -static PyObject *dmi_bios_characteristics_x2(u8 code) +void dmi_bios_characteristics_x2(xmlNode *node, u8 code) { + int i = 0; static const char *characteristics[] = { "BIOS boot specification", /* 0 */ "Function key-initiated network boot", "Targeted content distribution" /* 2 */ }; - int i; - PyObject *data = PyDict_New(); + dmixml_AddAttribute(node, "dmispec", "3.3.1.2.2"); + dmixml_AddAttribute(node, "flags", "0x%04x", code); - for(i = 0; i <= 2; i++) - PyDict_SetItemString(data, characteristics[i], - code & (1 << i) ? Py_True : Py_False); - return data; + for(i = 0; i <= 2; i++) { + if( code.l & (1 << i) ) { + dmixml_AddTextChild(node, "characteristic", characteristics[i]); + } + } } /******************************************************************************* ** 3.3.2 System Information (Type 1) */ -PyObject *dmi_system_uuid_py(const u8 * p, u16 ver) +void dmi_system_uuid(xmlNode *node, const u8 * p, u16 ver) { int only0xFF = 1, only0x00 = 1; int i; + xmlNode *uuid_n = NULL; for(i = 0; i < 16 && (only0x00 || only0xFF); i++) { if(p[i] != 0x00) @@ -369,11 +398,20 @@ PyObject *dmi_system_uuid_py(const u8 * p, u16 ver) only0xFF = 0; } - if(only0xFF) - return PyString_FromString("Not Present"); + uuid_n = xmlNewChild(node, NULL, (xmlChar *) "SystemUUID", NULL); + dmixml_AddAttribute(uuid_n, "dmispec", "3.3.2"); + + if(only0xFF ) { + dmixml_AddAttribute(uuid_n, "unavailable", "1"); + dmixml_AddTextContent(uuid_n, "Not Present"); + return; + } - if(only0x00) - return PyString_FromString("Not Settable"); + if(only0x00){ + dmixml_AddAttribute(uuid_n, "unavailable", "1"); + dmixml_AddTextContent(uuid_n,"Not Settable"); + return; + } /* * As off version 2.6 of the SMBIOS specification, the first 3 @@ -383,24 +421,21 @@ PyObject *dmi_system_uuid_py(const u8 * p, u16 ver) * network byte order, so I am reluctant to apply the byte-swapping * for older versions. */ - if(ver >= 0x0206) - return - PyString_FromFormat - ("%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", p[3], - p[2], p[1], p[0], p[5], p[4], p[7], p[6], p[8], p[9], p[10], p[11], p[12], - p[13], p[14], p[15] - ); - else - return - PyString_FromFormat - ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", p[0], - p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], - p[13], p[14], p[15] - ); + if(ver >= 0x0206) { + dmixml_AddTextContent(uuid_n, + "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", + p[3], p[2], p[1], p[0], p[5], p[4], p[7], p[6], p[8], p[9], p[10], + p[11], p[12], p[13], p[14], p[15]); + } else { + dmixml_AddTextContent(uuid_n, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], + p[11], p[12], p[13], p[14], p[15]); + } } /* 3.3.2.1 */ -static PyObject *dmi_system_wake_up_type(u8 code) +void dmi_system_wake_up_type(xmlNode *node, u8 code) { static const char *type[] = { "Reserved", /* 0x00 */ @@ -413,10 +448,16 @@ static PyObject *dmi_system_wake_up_type(u8 code) "PCI PME#", "AC Power Restored" /* 0x08 */ }; + xmlNode *swut_n = xmlNewChild(node, NULL, (xmlChar *) "SystemWakeUpType", NULL); + assert( swut_n != NULL ); + dmixml_AddAttribute(swut_n, "dmispec", "3.3.2.1"); + dmixml_AddAttribute(swut_n, "flags", "0x%04x", code); - if(code <= 0x08) - return PyString_FromString(type[code]); - return OUT_OF_SPEC; + if(code <= 0x08) { + dmixml_AddTextContent(swut_n, type[code]); + } else { + dmixml_AddAttribute(swut_n, "outofspec", "1"); + } } /******************************************************************************* @@ -424,7 +465,7 @@ static PyObject *dmi_system_wake_up_type(u8 code) */ /* 3.3.3.1 */ -static PyObject *dmi_base_board_features(u8 code) +void dmi_base_board_features(xmlNode *node, u8 code) { static const char *features[] = { "Board is a hosting board", /* 0 */ @@ -434,25 +475,25 @@ static PyObject *dmi_base_board_features(u8 code) "Board is hot swappable" /* 4 */ }; - PyObject *data; + xmlNode *feat_n = xmlNewChild(node, NULL, (xmlChar *) "Features", NULL); + assert( feat_n != NULL ); + dmixml_AddAttribute(feat_n, "dmispec", "3.3.3.1"); + dmixml_AddAttribute(feat_n, "flags", "0x%04x", code); - if((code & 0x1F) == 0) - data = Py_None; - else { + if((code & 0x1F) != 0) { int i; - data = PyList_New(5); for(i = 0; i <= 4; i++) { - if(code & (1 << i)) - PyList_SET_ITEM(data, i, PyString_FromString(features[i])); - else - PyList_SET_ITEM(data, i, Py_None); + if(code & (1 << i)) { + dmixml_AddTextChild(feat_n, "feature", features[i]); + } } + } else { + dmixml_AddAttribute(feat_n, "unavailable", "1"); } - return data; } -static PyObject *dmi_base_board_type(u8 code) +void dmi_base_board_type(xmlNode *node, const char *tagname, u8 code) { /* 3.3.3.2 */ static const char *type[] = { @@ -470,26 +511,33 @@ static PyObject *dmi_base_board_type(u8 code) "Processor+I/O Module", "Interconnect Board" /* 0x0D */ }; + xmlNode *type_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( type_n != NULL ); + dmixml_AddAttribute(type_n, "dmispec", "3.3.3.2"); + dmixml_AddAttribute(type_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x0D) - return PyString_FromString(type[code - 0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x0D) { + dmixml_AddTextContent(type_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(type_n, "unavailable", "1"); + } } -static PyObject *dmi_base_board_handles(u8 count, const u8 * p) +void dmi_base_board_handles(xmlNode *node, u8 count, const u8 * p) { int i; + xmlNode *dict_n = NULL; - PyObject *dict = PyDict_New(); - PyObject *list = PyList_New(count); - - for(i = 0; i < count; i++) - PyList_SET_ITEM(list, i, PyString_FromFormat("0x%04x", WORD(p + sizeof(u16) * i))); + dict_n = xmlNewChild(node, NULL, (xmlChar *) "ContainedObjectHandles", NULL); + assert( dict_n != NULL ); - PyDict_SetItemString(dict, "Contained Object Handles", list); - Py_DECREF(list); + dmixml_AddAttribute(dict_n, "count", "%i", count); - return dict; + for(i = 0; i < count; i++) { + xmlNode *elmt_n = xmlNewChild(dict_n, NULL, (xmlChar *) "Handle", NULL); + assert( elmt_n != NULL ); + dmixml_AddTextContent(elmt_n, "0x%04x", WORD(p + sizeof(u16) * i)); + } } /******************************************************************************* @@ -497,7 +545,7 @@ static PyObject *dmi_base_board_handles(u8 count, const u8 * p) */ /* 3.3.4.1 */ -const char *dmi_chassis_type(u8 code) +void dmi_chassis_type(xmlNode *node, u8 code) { static const char *type[] = { "Other", /* 0x01 */ @@ -530,29 +578,34 @@ const char *dmi_chassis_type(u8 code) "Blade", "Blade Enclosing" /* 0x1D */ }; - - if(code >= 0x01 && code <= 0x1B) - return type[code - 0x01]; - return out_of_spec; -} - -static PyObject *dmi_chassis_type_py(u8 code) -{ - return PyString_FromString(dmi_chassis_type(code)); + xmlNode *type_n = xmlNewChild(node, NULL, (xmlChar *)"ChassisType", NULL); + assert( type_n != NULL ); + dmixml_AddAttribute(type_n, "dmispec", "3.3.4.1"); + dmixml_AddAttribute(type_n, "flags", "0x%04x", code); + + if(code >= 0x01 && code <= 0x1B) { + dmixml_AddAttribute(type_n, "available", "1"); + dmixml_AddTextContent(type_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(type_n, "available", "0"); + } } -static PyObject *dmi_chassis_lock(u8 code) +void dmi_chassis_lock(xmlNode *node, u8 code) { static const char *lock[] = { "Not Present", /* 0x00 */ "Present" /* 0x01 */ }; - - return PyString_FromString(lock[code]); + xmlNode *lock_n = xmlNewChild(node, NULL, (xmlChar *) "ChassisLock", NULL); + assert( lock_n != NULL ); + dmixml_AddAttribute(lock_n, "dmispec", "3.3.4"); + dmixml_AddAttribute(lock_n, "flags", "0x%04x", code); + dmixml_AddTextContent(lock_n, "%s", lock[code]); } /* 3.3.4.2 */ -static PyObject *dmi_chassis_state(u8 code) +void dmi_chassis_state(xmlNode *node, const char *tagname, u8 code) { static const char *state[] = { "Other", /* 0x01 */ @@ -562,14 +615,20 @@ static PyObject *dmi_chassis_state(u8 code) "Critical", "Non-recoverable" /* 0x06 */ }; + xmlNode *state_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( state_n != NULL ); + dmixml_AddAttribute(state_n, "dmispec", "3.3.4.2"); + dmixml_AddAttribute(state_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x06) - return PyString_FromString(state[code - 0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x06) { + dmixml_AddTextContent(state_n, "%s", state[code - 0x01]); + } else { + dmixml_AddAttribute(state_n, "unavailable", "1"); + } } /* 3.3.4.3 */ -static const char *dmi_chassis_security_status(u8 code) +void dmi_chassis_security_status(xmlNode *node, u8 code) { static const char *status[] = { "Other", /* 0x01 */ @@ -578,68 +637,77 @@ static const char *dmi_chassis_security_status(u8 code) "External Interface Locked Out", "External Interface Enabled" /* 0x05 */ }; + xmlNode *secstat_n = xmlNewChild(node, NULL, (xmlChar *) "SecurityStatus", NULL); + assert( secstat_n != NULL ); + dmixml_AddAttribute(secstat_n, "dmispec", "3.3.4.3"); + dmixml_AddAttribute(secstat_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x05) - return (status[code - 0x01]); - return out_of_spec; + if(code >= 0x01 && code <= 0x05) { + dmixml_AddTextContent(secstat_n, "%s", status[code - 0x01]); + } else { + dmixml_AddAttribute(secstat_n, "unavailable", "1"); + } } -static PyObject *dmi_chassis_height(u8 code) +void dmi_chassis_height(xmlNode *node, u8 code) { - if(code == 0x00) - return PyString_FromString("Unspecified"); - else - return PyString_FromFormat("%i U", code); + xmlNode *hght_n = xmlNewChild(node, NULL, (xmlChar *) "ChassisHeight", NULL); + assert( hght_n != NULL ); + + if(code == 0x00) { + dmixml_AddAttribute(hght_n, "unspecified", "1"); + } else { + dmixml_AddAttribute(hght_n, "unit", "U"); + dmixml_AddTextContent(hght_n, "%i", code); + } } -static PyObject *dmi_chassis_power_cords(u8 code) +void dmi_chassis_power_cords(xmlNode *node, u8 code) { - if(code == 0x00) - return PyString_FromString("Unspecified"); - else - return PyString_FromFormat("%i", code); + xmlNode *pwrc_n = xmlNewChild(node, NULL, (xmlChar *) "PowerCords", NULL); + assert( pwrc_n != NULL ); + + if(code == 0x00) { + dmixml_AddAttribute(pwrc_n, "unspecified", "1"); + } else { + dmixml_AddTextContent(pwrc_n, "%i", code); + } } -static PyObject *dmi_chassis_elements(u8 count, u8 len, const u8 * p) +void dmi_chassis_elements(xmlNode *node, u8 count, u8 len, const u8 * p) { int i; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "ChassisElements", NULL); + assert( data_n != NULL ); - PyObject *data = PyDict_New(); - - PyDict_SetItemString(data, "Contained Elements", PyInt_FromLong(count)); - - PyObject *_key, *_val; + dmixml_AddAttribute(data_n, "count", "%i", count); for(i = 0; i < count; i++) { if(len >= 0x03) { + xmlNode *key_n = NULL; - _key = PyString_FromFormat("%s", - p[i * len] & 0x80 ? - dmi_smbios_structure_type(p[i * len] & 0x7F) : - PyString_AS_STRING(dmi_base_board_type - (p[i * len] & 0x7F)) - ); - - if(p[1 + i * len] == p[2 + i * len]) - _val = PyString_FromFormat("%i", p[1 + i * len]); - else - _val = PyString_FromFormat("%i-%i", p[1 + i * len], p[2 + i * len]); - - PyDict_SetItem(data, _key, _val); + if( p[i * len] & 0x80 ) { + key_n = dmi_smbios_structure_type(data_n, p[i * len] & 0x7F); + } else { + key_n = xmlNewChild(data_n, NULL, (xmlChar *) "BaseboardElement", NULL); + dmi_base_board_type(key_n, "Description", p[i * len] & 0x7F); + } + assert( key_n != NULL ); - Py_DECREF(_key); - Py_DECREF(_val); + if(p[1 + i * len] == p[2 + i * len]) { + dmixml_AddTextChild(key_n, "Value", "%i", p[1 + i * len]); + } else { + dmixml_AddTextChild(key_n, "Value", "%i-%i", p[1 + i * len], p[2 + i * len]); + } } } - - return data; } /******************************************************************************* ** 3.3.5 Processor Information (Type 4) */ -static PyObject *dmi_processor_type(u8 code) +void dmi_processor_type(xmlNode *node, u8 code) { /* 3.3.5.1 */ static const char *type[] = { @@ -650,13 +718,18 @@ static PyObject *dmi_processor_type(u8 code) "DSP Processor", "Video Processor" /* 0x06 */ }; - - if(code >= 0x01 && code <= 0x06) - return PyString_FromString(type[code - 0x01]); - return OUT_OF_SPEC; + xmlNode *proct_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); + assert( proct_n != NULL ); + dmixml_AddAttribute(proct_n, "dmispec", "3.3.5"); + dmixml_AddAttribute(proct_n, "flags", "0x%04x", code); + if(code >= 0x01 && code <= 0x06) { + dmixml_AddTextContent(proct_n, type[code - 0x01]); + } else { + dmixml_AddAttribute(proct_n, "outofspec", "1"); + } } -static const char *dmi_processor_family(const struct dmi_header *h) +void dmi_processor_family(xmlNode *node, const struct dmi_header *h) { const u8 *data = h->data; unsigned int i, low, high; @@ -847,19 +920,32 @@ static const char *dmi_processor_family(const struct dmi_header *h) * return family2[i].name; */ + xmlNode *family_n = xmlNewChild(node, NULL, (xmlChar *) "Family", NULL); + assert( family_n != NULL ); + dmixml_AddAttribute(family_n, "dmispec", "3.3.3.5"); + code = (data[0x06] == 0xFE && h->length >= 0x2A) ? WORD(data + 0x28) : data[0x06]; + dmixml_AddAttribute(family_n, "flags", "0x%04x", code); + /* Special case for ambiguous value 0xBE */ if(code == 0xBE) { const char *manufacturer = dmi_string(h, data[0x07]); /* Best bet based on manufacturer string */ if(strstr(manufacturer, "Intel") != NULL || - strncasecmp(manufacturer, "Intel", 5) == 0) - return "Core 2"; - if(strstr(manufacturer, "AMD") != NULL || strncasecmp(manufacturer, "AMD", 3) == 0) - return "K7"; - return "Core 2 or K7"; + strncasecmp(manufacturer, "Intel", 5) == 0) { + dmixml_AddTextContent(family_n, "Core 2"); + return; + } + + if(strstr(manufacturer, "AMD") != NULL + || strncasecmp(manufacturer, "AMD", 3) == 0) { + dmixml_AddTextContent(family_n, "K7"); + return; + } + dmixml_AddTextContent(family_n, "Core 2 or K7"); + return; } /* Perform a binary search */ @@ -867,58 +953,73 @@ static const char *dmi_processor_family(const struct dmi_header *h) high = ARRAY_SIZE(family2) - 1; while(1) { i = (low + high) / 2; - if(family2[i].value == code) - return family2[i].name; - if(low == high) /* Not found */ - return out_of_spec; + if(family2[i].value == code) { + dmixml_AddTextContent(family_n, family2[i].name); + return; + } + + if(low == high) { /* Not found */ + dmixml_AddAttribute(family_n, "outofspec", "1"); + return; + } + if(code < family2[i].value) high = i; else low = i + 1; } - return out_of_spec; + dmixml_AddAttribute(family_n, "outofspec", "1"); } -static PyObject *dmi_processor_id(u8 type, const u8 * p, const char *version) +xmlNode *dmi_processor_id(xmlNode *node, u8 type, const u8 * p, const char *version) { - PyObject *data = PyDict_New(); - /* Intel AP-485 revision 31, table 3-4 */ - static const char *flags[32] = { - "FPU (Floating-point unit on-chip)", /* 0 */ - "VME (Virtual mode extension)", - "DE (Debugging extension)", - "PSE (Page size extension)", - "TSC (Time stamp counter)", - "MSR (Model specific registers)", - "PAE (Physical address extension)", - "MCE (Machine check exception)", - "CX8 (CMPXCHG8 instruction supported)", - "APIC (On-chip APIC hardware supported)", - NULL, /* 10 */ - "SEP (Fast system call)", - "MTRR (Memory type range registers)", - "PGE (Page global enable)", - "MCA (Machine check architecture)", - "CMOV (Conditional move instruction supported)", - "PAT (Page attribute table)", - "PSE-36 (36-bit page size extension)", - "PSN (Processor serial number present and enabled)", - "CLFSH (CLFLUSH instruction supported)", - NULL, /* 20 */ - "DS (Debug store)", - "ACPI (ACPI supported)", - "MMX (MMX technology supported)", - "FXSR (Fast floating-point save and restore)", - "SSE (Streaming SIMD extensions)", - "SSE2 (Streaming SIMD extensions 2)", - "SS (Self-snoop)", - "HTT (Hyper-threading technology)", - "TM (Thermal monitor supported)", - "IA64 (IA64 capabilities)", - "PBE (Pending break enabled)" /* 31 */ + static struct _cpuflags { + const char *flag; + const char *descr; + } flags[] = { + /* *INDENT-OFF* */ + {"FPU", "Floating-point unit on-chip"}, /* 0 */ + {"VME", "Virtual mode extension"}, + {"DE", "Debugging extension"}, + {"PSE", "Page size extension"}, + {"TSC", "Time stamp counter"}, + {"MSR", "Model specific registers"}, + {"PAE", "Physical address extension"}, + {"MCE", "Machine check exception"}, + {"CX8", "CMPXCHG8 instruction supported"}, + {"APIC", "On-chip APIC hardware supported"}, + {NULL, NULL}, /* 10 */ + {"SEP", "Fast system call"}, + {"MTRR", "Memory type range registers"}, + {"PGE", "Page global enable"}, + {"MCA", "Machine check architecture"}, + {"CMOV", "Conditional move instruction supported"}, + {"PAT", "Page attribute table"}, + {"PSE-36", "36-bit page size extension"}, + {"PSN", "Processor serial number present and enabled"}, + {"CLFSH", "CLFLUSH instruction supported"}, + {NULL, NULL }, /* 20 */ + {"DS", "Debug store"}, + {"ACPI", "ACPI supported"}, + {"MMX", "MMX technology supported"}, + {"FXSR", "Fast floating-point save and restore"}, + {"SSE", "Streaming SIMD extensions"}, + {"SSE2", "Streaming SIMD extensions 2"}, + {"SS", "Self-snoop"}, + {"HTT", "Hyper-threading technology"}, + {"TM", "Thermal monitor supported"}, + {"IA64", "IA64 capabilities"}, + {"PBE", "Pending break enabled"} /* 31 */ + /* *INDENT-ON* */ }; + + xmlNode *flags_n = NULL; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "CPUCore", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.5"); + /* ** Extra flags are now returned in the ECX register when one calls ** the CPUID instruction. Their meaning is explained in table 3-5, but @@ -933,11 +1034,9 @@ static PyObject *dmi_processor_id(u8 type, const u8 * p, const char *version) */ //. TODO: PyString_FromFormat does not support %x (yet?)... - PyDict_SetItemString(data, "ID", - PyString_FromFormat("%02x %02x %02x %02x %02x %02x %02x %02x", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] - ) - ); + dmixml_AddTextChild(data_n, "ID", + "%02x %02x %02x %02x %02x %02x %02x %02x", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); if(type == 0x05) { /* 80386 */ u16 dx = WORD(p); @@ -945,12 +1044,10 @@ static PyObject *dmi_processor_id(u8 type, const u8 * p, const char *version) /* ** 80386 have a different signature. */ - PyDict_SetItemString(data, "Signature", - PyString_FromFormat - ("Type %i, Family %i, Major Stepping %i, Minor Stepping %i", - dx >> 12, (dx >> 8) & 0xF, (dx >> 4) & 0xF, dx & 0xF) - ); - return data; + dmixml_AddTextChild(data_n, "Signature", + "Type %i, Family %i, Major Stepping %i, Minor Stepping %i", + dx >> 12, (dx >> 8) & 0xF, (dx >> 4) & 0xF, dx & 0xF); + return data_n; } if(type == 0x06) { /* 80486 */ @@ -961,17 +1058,16 @@ static PyObject *dmi_processor_id(u8 type, const u8 * p, const char *version) ** wether the one we have here does or not. Note that this trick ** works only because we know that 80486 must be little-endian. */ - if((dx & 0x0F00) == 0x0400 && ((dx & 0x00F0) == 0x0040 || (dx & 0x00F0) >= 0x0070) - && ((dx & 0x000F) >= 0x0003)) + if( (dx & 0x0F00) == 0x0400 + && ((dx & 0x00F0) == 0x0040 || (dx & 0x00F0) >= 0x0070) + && ((dx & 0x000F) >= 0x0003) ) { sig = 1; - else { - PyDict_SetItemString(data, "Signature", - PyString_FromFormat - ("Type %i, Family %i, Model %i, Stepping %i", - (dx >> 12) & 0x3, (dx >> 8) & 0xF, (dx >> 4) & 0xF, - dx & 0xF) - ); - return data; + } else { + dmixml_AddTextChild(data_n, "Signature", + "Type %i, Family %i, Model %i, Stepping %i", + (dx >> 12) & 0x3, (dx >> 8) & 0xF, (dx >> 4) & 0xF, + dx & 0xF); + return data_n; } } else if((type >= 0x0B && type <= 0x15) /* Intel, Cyrix */ ||(type >= 0x28 && type <= 0x2B) /* Intel */ @@ -980,16 +1076,20 @@ static PyObject *dmi_processor_id(u8 type, const u8 * p, const char *version) ||type == 0xB5 /* Intel */ || (type >= 0xB9 && type <= 0xC5) /* Intel */ ||(type >= 0xD2 && type <= 0xD5) /* VIA */ - ) + ) { + sig = 1; - else if((type >= 0x18 && type <= 0x1D) /* AMD */ + + } else if((type >= 0x18 && type <= 0x1D) /* AMD */ ||type == 0x1F /* AMD */ || (type >= 0x83 && type <= 0x8F) /* AMD */ ||(type >= 0xB6 && type <= 0xB7) /* AMD */ ||(type >= 0xE6 && type <= 0xEB) /* AMD */ - ) + ) { + sig = 2; - else if(type == 0x01 || type == 0x02) { + + } else if(type == 0x01 || type == 0x02) { /* ** Some X86-class CPU have family "Other" or "Unknown". In this case, ** we use the version string to determine if they are known to @@ -998,82 +1098,87 @@ static PyObject *dmi_processor_id(u8 type, const u8 * p, const char *version) if(strncmp(version, "Pentium III MMX", 15) == 0 || strncmp(version, "Intel(R) Core(TM)2", 18) == 0 || strncmp(version, "Intel(R) Pentium(R)", 19) == 0 - || strcmp(version, "Genuine Intel(R) CPU U1400") == 0) + || strcmp(version, "Genuine Intel(R) CPU U1400") == 0 + ) { + sig = 1; - else if(strncmp(version, "AMD Athlon(TM)", 14) == 0 - || strncmp(version, "AMD Opteron(tm)", 15) == 0 - || strncmp(version, "Dual-Core AMD Opteron(tm)", 25) == 0) + + } else if(strncmp(version, "AMD Athlon(TM)", 14) == 0 + || strncmp(version, "AMD Opteron(tm)", 15) == 0 + || strncmp(version, "Dual-Core AMD Opteron(tm)", 25) == 0) { + sig = 2; - else - return data; - } else /* not X86-class */ - return data; + + } else { + return data_n; + } + } else { /* not X86-class */ + return data_n; + } eax = DWORD(p); edx = DWORD(p + 4); switch (sig) { case 1: /* Intel */ - PyDict_SetItemString(data, "Signature", - PyString_FromFormat - ("Type %i, Family %i, Model %i, Stepping %i", - (eax >> 12) & 0x3, ((eax >> 20) & 0xFF) + ((eax >> 8) & 0x0F), - ((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F), eax & 0xF) - ); + dmixml_AddTextChild(data_n, "Signature", + "Type %i, Family %i, Model %i, Stepping %i", + (eax >> 12) & 0x3, ((eax >> 20) & 0xFF) + ((eax >> 8) & 0x0F), + ((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F), eax & 0xF); break; case 2: /* AMD, publication #25481 revision 2.28 */ - PyDict_SetItemString(data, "Signature", - PyString_FromFormat("Family %i, Model %i, Stepping %i", - ((eax >> 8) & 0xF) + (((eax >> 8) & 0xF) == - 0xF ? (eax >> 20) & - 0xFF : 0), - ((eax >> 4) & 0xF) | (((eax >> 8) & 0xF) == - 0xF ? (eax >> 12) & - 0xF0 : 0), eax & 0xF) - ); + dmixml_AddTextChild(data_n, "Signature", + "Family %i, Model %i, Stepping %i", + ((eax >> 8) & 0xF) + (((eax >> 8) & 0xF) == 0xF + ? (eax >> 20) & 0xFF : 0), + ((eax >> 4) & 0xF) | (((eax >> 8) & 0xF) == 0xF + ? (eax >> 12) & 0xF0 : 0), + eax & 0xF); break; } edx = DWORD(p + 4); - if((edx & 0xFFEFFBFF) == 0) - PyDict_SetItemString(data, "Flags", Py_None); - else { + flags_n = xmlNewChild(data_n, NULL, (xmlChar *) "cpu_flags", NULL); + if((edx & 0xFFEFFBFF) != 0) { int i; - PyObject *subdata = PyDict_New(); - for(i = 0; i <= 31; i++) - if(flags[i] != NULL) - PyDict_SetItemString(subdata, flags[i], - (edx & (1 << i)) ? Py_True : Py_False); - PyDict_SetItemString(data, "Flags", subdata); - Py_DECREF(subdata); + for(i = 0; i <= 31; i++) { + // Only add those flags which are present + if( (flags[i].flag != NULL) && (edx & (1 << i)) ) { + xmlNode *flg_n = dmixml_AddTextChild(flags_n, "flag", "%s", flags[i].descr); + dmixml_AddAttribute(flg_n, "flag", "%s", flags[i].flag); + } + } } - - return data; + return data_n; } /* 3.3.5.4 */ -static PyObject *dmi_processor_voltage(u8 code) +void dmi_processor_voltage(xmlNode *node, u8 code) { static const char *voltage[] = { - "5.0 V", /* 0 */ - "3.3 V", - "2.9 V" /* 2 */ + "5.0", /* 0 */ + "3.3", + "2.9" /* 2 */ }; int i; - - PyObject *data; - - if(code & 0x80) - data = PyString_FromFormat("%.1f V", (float)(code & 0x7f) / 10); - else { - data = PyDict_New(); - for(i = 0; i <= 2; i++) - PyDict_SetItemString(data, voltage[i], - (code & (1 << i) ? Py_True : Py_False)); - if(code == 0x00) - PyDict_SetItemString(data, "VOLTAGE", PyString_FromString("Unknown")); + xmlNode *vltg_n = xmlNewChild(node, NULL, (xmlChar *) "Voltages", NULL); + assert( vltg_n != NULL ); + dmixml_AddAttribute(vltg_n, "dmispec", "3.3.5.4"); + dmixml_AddAttribute(vltg_n, "flags", "0x%04x", code); + + if(code & 0x80) { + dmixml_AddTextChild(vltg_n, "Voltage", "%.1f", (float)(code & 0x7f) / 10); + dmixml_AddAttribute(vltg_n, "unit", "V"); + } else if( code == 0x00 ) { + dmixml_AddAttribute(vltg_n, "unknown_value", "1"); + } else { + for(i = 0; i <= 2; i++) { + if( code & (1 << i) ) { + xmlNode *v_n = dmixml_AddTextChild(vltg_n, "Voltage", "%s", voltage[i]); + dmixml_AddAttribute(v_n, "unit", "V"); + } + } } - return data; } int dmi_processor_frequency(const u8 * p) @@ -1085,12 +1190,8 @@ int dmi_processor_frequency(const u8 * p) else return -1; //. Unknown } -static PyObject *dmi_processor_frequency_py(const u8 * p) -{ - return PyInt_FromLong(dmi_processor_frequency(p)); -} -static const char *dmi_processor_status(u8 code) +void dmi_processor_status(xmlNode *node, u8 code) { static const char *status[] = { "Unknown", /* 0x00 */ @@ -1100,15 +1201,21 @@ static const char *dmi_processor_status(u8 code) "Idle", /* 0x04 */ "Other" /* 0x07 */ }; + xmlNode *prst_n = xmlNewChild(node, NULL, (xmlChar *) "Populated", NULL); + assert( prst_n != NULL ); - if(code <= 0x04) - return status[code]; - if(code == 0x07) - return status[0x05]; - return out_of_spec; + dmixml_AddAttribute(prst_n, "flags", "0x%04x", code); + + if(code <= 0x04) { + dmixml_AddTextContent(prst_n, "%s", status[code]); + } else if( code == 0x07 ) { + dmixml_AddTextContent(prst_n, "%s", status[5]); + } else { + dmixml_AddAttribute(prst_n, "outofspec", "1"); + } } -static PyObject *dmi_processor_upgrade(u8 code) +void dmi_processor_upgrade(xmlNode *node, u8 code) { /* 3.3.5.5 */ static const char *upgrade[] = { @@ -1137,54 +1244,69 @@ static PyObject *dmi_processor_upgrade(u8 code) "Socket AM2", "Socket F (1207)" /* 0x18 */ }; + xmlNode *upgr_n = xmlNewChild(node, NULL, (xmlChar *) "Upgrade", NULL); + assert( upgr_n != NULL ); + dmixml_AddAttribute(upgr_n, "dmispec", "3.3.5.5"); + dmixml_AddAttribute(upgr_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x15) - return PyString_FromString(upgrade[code - 0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x15) { + dmixml_AddTextContent(upgr_n, "%s", upgrade[code - 0x01]); + } else { + dmixml_AddAttribute(upgr_n, "outofspec", "1"); + } } -static PyObject *dmi_processor_cache(u16 code, const char *level, u16 ver) +void dmi_processor_cache(xmlNode *cache_n, u16 code, u16 ver) { - PyObject *data; + assert( cache_n != NULL ); + + dmixml_AddAttribute(cache_n, "flags", "0x%04x", code); + dmixml_AddAttribute(cache_n, "ver", "0x%04x", ver); if(code == 0xFFFF) { - if(ver >= 0x0203) - data = PyString_FromString("Not Provided"); - else - data = PyString_FromFormat("No %s Cache", level); - } else - data = PyString_FromFormat("0x%04x", code); - return data; + if(ver >= 0x0203) { + dmixml_AddAttribute(cache_n, "provided", "0"); + dmixml_AddAttribute(cache_n, "available", "1"); + } else { + dmixml_AddAttribute(cache_n, "available", "0"); + } + } else { + dmixml_AddAttribute(cache_n, "provided", "1"); + dmixml_AddAttribute(cache_n, "available", "1"); + dmixml_AddTextChild(cache_n, "Handle", "0x%04x", code); + } } /* 3.3.5.9 */ -static PyObject *dmi_processor_characteristics(u16 code) +void dmi_processor_characteristics(xmlNode *node, u16 code) { static const char *characteristics[] = { + NULL, + "Unknown" /* 1 */ "64-bit capable" /* 2 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Characteristics", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.5.9"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if((code & 0x0004) == 0) { - data = Py_None; - } else { - data = PyList_New(1); + if((code & 0x0004) != 0) { int i; - for(i = 2; i <= 2; i++) - if(code & (1 << i)) - PyList_SET_ITEM(data, 0, - PyString_FromString(characteristics[i - 2])); + for(i = 1; i <= 2; i++) { + if(code & (1 << i)) { + dmixml_AddTextChild(data_n, "Flag", "%s", characteristics[i - 1]); + } + } } - return data; } /******************************************************************************* ** 3.3.6 Memory Controller Information (Type 5) */ -static PyObject *dmi_memory_controller_ed_method(u8 code) +void dmi_memory_controller_ed_method(xmlNode *node, u8 code) { /* 3.3.6.1 */ static const char *method[] = { @@ -1197,14 +1319,20 @@ static PyObject *dmi_memory_controller_ed_method(u8 code) "128-bit ECC", "CRC" /* 0x08 */ }; + xmlNode *ercm_n = xmlNewChild(node, NULL, (xmlChar *) "CorrectionMethod", NULL); + assert( ercm_n != NULL ); + dmixml_AddAttribute(ercm_n, "dmispec", "3.3.6.1"); + dmixml_AddAttribute(ercm_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x08) - return (PyString_FromString(method[code - 0x01])); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x08) { + dmixml_AddTextContent(ercm_n, method[code - 0x01]); + } else { + dmixml_AddAttribute(ercm_n, "outofspec", "1"); + } } /* 3.3.6.2 */ -static PyObject *dmi_memory_controller_ec_capabilities(u8 code) +void dmi_memory_controller_ec_capabilities(xmlNode *node, const char *tagname, u8 code) { static const char *capabilities[] = { "Other", /* 0 */ @@ -1215,24 +1343,24 @@ static PyObject *dmi_memory_controller_ec_capabilities(u8 code) "Error Scrubbing" /* 5 */ }; - PyObject *data = Py_None; + xmlNode *cap_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( cap_n != NULL ); + dmixml_AddAttribute(cap_n, "dmispec", "3.3.6.2"); + dmixml_AddAttribute(cap_n, "flags", "0x%04x", code); - if((code & 0x3F) == 0) - return Py_None; - else { + if((code & 0x3F) != 0) { int i; - - data = PyList_New(6); - for(i = 0; i <= 5; i++) - if(code & (1 << i)) - PyList_SET_ITEM(data, i, PyString_FromString(capabilities[i])); - else - PyList_SET_ITEM(data, i, Py_None); + for(i = 0; i <= 5; i++) { + if(code & (1 << i)) { + xmlNode *c_n = dmixml_AddTextChild(cap_n, "Capability", "%s", capabilities[i]); + assert( c_n != NULL ); + dmixml_AddAttribute(c_n, "index", "%i", i); + } + } } - return data; } -static PyObject *dmi_memory_controller_interleave(u8 code) +void dmi_memory_controller_interleave(xmlNode *node, const char *tagname, u8 code) { /* 3.3.6.3 */ static const char *interleave[] = { @@ -1244,49 +1372,62 @@ static PyObject *dmi_memory_controller_interleave(u8 code) "Eight-way Interleave", "Sixteen-way Interleave" /* 0x07 */ }; + xmlNode *mci_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( mci_n != NULL ); + dmixml_AddAttribute(mci_n, "dmispec", "3.3.6.3"); + dmixml_AddAttribute(mci_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x07) - return PyString_FromString(interleave[code - 0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x07) { + dmixml_AddTextContent(mci_n, interleave[code - 0x01]); + } else { + dmixml_AddAttribute(mci_n, "outofspec", "1"); + } } /* 3.3.6.4 */ -static PyObject *dmi_memory_controller_speeds(u16 code) +void dmi_memory_controller_speeds(xmlNode *node, u16 code) { - const char *speeds[] = { - "Other", /* 0 */ - "Unknown", - "70 ns", - "60 ns", - "50 ns" /* 4 */ + static struct { + const char *value; + const char *unit; + } const speeds[] = { + {"Other", NULL}, /* 0 */ + {"Unknown", NULL}, + {"70", "ns"}, + {"60", "ns"}, + {"50", "ns"} /* 4 */ }; + xmlNode *mcs_n = xmlNewChild(node, NULL, (xmlChar *) "SupportedSpeeds", NULL); + assert( mcs_n != NULL ); + dmixml_AddAttribute(mcs_n, "dmispec", "3.3.6.4"); + dmixml_AddAttribute(mcs_n, "flags", "0x%04x", code); - PyObject *data; - - if((code & 0x001F) != 0) - data = Py_None; - else { + if((code & 0x001F) == 0) { int i; - - data = PyList_New(5); - for(i = 0; i <= 4; i++) - if(code & (1 << i)) - PyList_SET_ITEM(data, i, PyString_FromString(speeds[i])); - else - PyList_SET_ITEM(data, i, Py_None); + for(i = 0; i <= 4; i++) { + if(code & (1 << i)) { + xmlNode *ms_n = dmixml_AddTextChild(mcs_n, "Speed", "%s", speeds[i].value); + assert( ms_n != NULL ); + dmixml_AddAttribute(ms_n, "index", "%i", i); + if( speeds[i].unit != NULL ) { + dmixml_AddAttribute(ms_n, "unit", speeds[i].unit); + } + ms_n = NULL; + } + } } - return data; } -static PyObject *dmi_memory_controller_slots(u8 count, const u8 * p) +void dmi_memory_controller_slots(xmlNode *node, u8 count, const u8 * p) { int i; + xmlNode *mslts_n = xmlNewChild(node, NULL, (xmlChar *) "AssociatedMemorySlots", NULL); + assert( mslts_n != NULL ); - PyObject *data = PyList_New(count); - - for(i = 0; i < count; i++) - PyList_SET_ITEM(data, i, PyString_FromFormat("0x%04x:", WORD(p + sizeof(u16) * i))); - return data; + for(i = 0; i < count; i++) { + xmlNode *sl_n = dmixml_AddTextChild(mslts_n, "Slot", "0x%04x:", WORD(p + sizeof(u16) * i)); + dmixml_AddAttribute(sl_n, "index", "%i", i); + } } /******************************************************************************* @@ -1294,7 +1435,7 @@ static PyObject *dmi_memory_controller_slots(u8 count, const u8 * p) */ /* 3.3.7.1 */ -static PyObject *dmi_memory_module_types(u16 code) +void dmi_memory_module_types(xmlNode *node, const char *tagname, u16 code) { static const char *types[] = { "Other", /* 0 */ @@ -1309,101 +1450,109 @@ static PyObject *dmi_memory_module_types(u16 code) "Burst EDO", "SDRAM" /* 10 */ }; + xmlNode *mmt_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( mmt_n != NULL ); + dmixml_AddAttribute(mmt_n, "dmispec", "3.3.7.1"); + dmixml_AddAttribute(mmt_n, "flags", "0x%04x", code); - PyObject *data; - - if((code & 0x07FF) == 0) - data = Py_None; - else { + if((code & 0x07FF) != 0) { int i; - data = PyList_New(11); - for(i = 0; i <= 10; i++) - if(code & (1 << i)) - PyList_SET_ITEM(data, i, PyString_FromString(types[i])); - else - PyList_SET_ITEM(data, i, Py_None); + for(i = 0; i <= 10; i++) { + if(code & (1 << i)) { + xmlNode *mt_n = dmixml_AddTextChild(mmt_n, "ModuleType", types[i]); + assert( mt_n != NULL ); + dmixml_AddAttribute(mt_n, "index", "%i", i); + } + } } - return data; } -static PyObject *dmi_memory_module_connections(u8 code) +void dmi_memory_module_connections(xmlNode *node, u8 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "BankConnections", NULL); + assert( data_n != NULL ); - if(code == 0xFF) - data = Py_None; - else { - data = PyList_New(0); - if((code & 0xF0) != 0xF0) - PyList_Append(data, PyInt_FromLong(code >> 4)); - if((code & 0x0F) != 0x0F) - PyList_Append(data, PyInt_FromLong(code & 0x0F)); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code != 0xFF) { + if((code & 0xF0) != 0xF0) { + dmixml_AddTextContent(data_n, "%ld", (code >> 4)); + } + if((code & 0x0F) != 0x0F) { + dmixml_AddTextContent(data_n, "%ld", (code & 0x0F)); + } } - return data; } -static PyObject *dmi_memory_module_speed(u8 code) +void dmi_memory_module_speed(xmlNode *node, const char *tagname, u8 code) { - if(code == 0) - return PyString_FromString("Unknown"); - else - return PyString_FromFormat("%i ns", code); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + + dmixml_AddAttribute(data_n, "code", "0x%04x", code); + + if(code != 0) { + dmixml_AddAttribute(data_n, "unit", "ns"); + dmixml_AddTextContent(data_n, "%i", code); + } } /* 3.3.7.2 */ -static PyObject *dmi_memory_module_size(u8 code) +void dmi_memory_module_size(xmlNode *node, const char *tagname, u8 code) { - PyObject *data = PyDict_New(); int check_conn = 1; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + + dmixml_AddAttribute(data_n, "dmispec", "3.3.7.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); switch (code & 0x7F) { case 0x7D: - PyDict_SetItemString(data, "Size", PyString_FromString("Not Determinable")); + dmixml_AddAttribute(data_n, "Error", "Size not determinable"); break; case 0x7E: - PyDict_SetItemString(data, "Size", PyString_FromString("Disabled")); + dmixml_AddAttribute(data_n, "Error", "Disabled"); break; case 0x7F: - PyDict_SetItemString(data, "Size", PyString_FromString("Not Installed")); + dmixml_AddAttribute(data_n, "installed", "0"); check_conn = 0; default: - PyDict_SetItemString(data, "Size", - PyString_FromFormat("%i MB", 1 << (code & 0x7F))); + dmixml_AddAttribute(data_n, "installed", "1"); + dmixml_AddAttribute(data_n, "unit", "MB"); + dmixml_AddTextContent(data_n, "%i", 1 << (code & 0x7F)); } if(check_conn) { - if(code & 0x80) - PyDict_SetItemString(data, "Connection", - PyString_FromString("Double-bank")); - else - PyDict_SetItemString(data, "Connection", - PyString_FromString("Single-bank")); + dmixml_AddAttribute(data_n, "Connection", ((code & 0x80) ? "Double-bank" : "Single-bank")); } - return data; } -static PyObject *dmi_memory_module_error(u8 code) +void dmi_memory_module_error(xmlNode *node, u8 code) { - PyObject *data = NULL; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "ModuleErrorStatus", NULL); + assert( data_n != NULL ); - if(code & (1 << 2)) - data = Py_None; //. TODO: sprintf(_, "See Event Log"); - else { - if((code & 0x03) == 0) - data = Py_True; - if(code & (1 << 0)) - data = PyString_FromString("Uncorrectable Errors"); - if(code & (1 << 1)) - data = PyString_FromString("Correctable Errors"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if( !(code & (1 << 2)) ) { + if((code & 0x03) == 0) { + dmixml_AddAttribute(data_n, "Error", "1"); + } + if(code & (1 << 0)) { + dmixml_AddTextContent(data_n, "Uncorrectable Errors"); + } + if(code & (1 << 1)) { + dmixml_AddTextContent(data_n, "Correctable Errors"); + } } - return data; } /******************************************************************************* ** 3.3.8 Cache Information (Type 7) */ -static PyObject *dmi_cache_mode(u8 code) +static const char *dmi_cache_mode(u8 code) { static const char *mode[] = { "Write Through", /* 0x00 */ @@ -1412,10 +1561,10 @@ static PyObject *dmi_cache_mode(u8 code) "Unknown" /* 0x03 */ }; - return PyString_FromString(mode[code]); + return mode[code]; } -static PyObject *dmi_cache_location(u8 code) +void dmi_cache_location(xmlNode *node, u8 code) { static const char *location[4] = { "Internal", /* 0x00 */ @@ -1424,28 +1573,36 @@ static PyObject *dmi_cache_location(u8 code) "Unknown" /* 0x03 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "CacheLocation", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.8"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(location[code] != NULL) - data = PyString_FromString(location[code]); - else - data = OUT_OF_SPEC; - return data; + if(location[code] != NULL) { + dmixml_AddTextContent(data_n, location[code]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_cache_size(u16 code) +void dmi_cache_size(xmlNode *node, const char *tagname, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "CacheLocation", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.8"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code & 0x8000) - data = PyString_FromFormat("%i KB", (code & 0x7FFF) << 6); - else - data = PyString_FromFormat("%i KB", code); - return data; + if(code & 0x8000) { + dmixml_AddAttribute(data_n, "unit", "KB"); + dmixml_AddTextContent(data_n, "%i", (code & 0x7FFF) << 6); + } else { + dmixml_AddAttribute(data_n, "unit", "KB"); + dmixml_AddTextContent(data_n, "%i", code); + } } /* 3.3.8.2 */ -static PyObject *dmi_cache_types(u16 code) +void dmi_cache_types(xmlNode *node, const char *tagname, u16 code) { static const char *types[] = { "Other", /* 0 */ @@ -1456,24 +1613,25 @@ static PyObject *dmi_cache_types(u16 code) "Synchronous", "Asynchronous" /* 6 */ }; - PyObject *data; - if((code & 0x007F) == 0) - data = Py_None; - else { - int i; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.8.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - data = PyList_New(7); - for(i = 0; i <= 6; i++) - if(code & (1 << i)) - PyList_SET_ITEM(data, i, PyString_FromString(types[i])); - else - PyList_SET_ITEM(data, i, Py_None); + + if((code & 0x007F) != 0) { + int i; + for(i = 0; i <= 6; i++) { + if(code & (1 << i)) { + xmlNode *n = dmixml_AddTextContent(data_n, "%s", types[i]); + dmixml_AddAttribute(n, "index", "%i", i); + } + } } - return data; } -static PyObject *dmi_cache_ec_type(u8 code) +void dmi_cache_ec_type(xmlNode *node, u8 code) { /* 3.3.8.3 */ static const char *type[] = { @@ -1484,16 +1642,19 @@ static PyObject *dmi_cache_ec_type(u8 code) "Single-bit ECC", "Multi-bit ECC" /* 0x06 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "ErrorCorrectionType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.8.3"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x06) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x06) { + dmixml_AddTextContent(data_n, type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_cache_type(u8 code) +void dmi_cache_type(xmlNode *node, u8 code) { /* 3.3.8.4 */ static const char *type[] = { @@ -1503,16 +1664,19 @@ static PyObject *dmi_cache_type(u8 code) "Data", "Unified" /* 0x05 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "SystemType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.8.4"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x05) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x05) { + dmixml_AddTextContent(data_n, type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_cache_associativity(u8 code) +void dmi_cache_associativity(xmlNode *node, u8 code) { /* 3.3.8.5 */ static const char *type[] = { @@ -1525,20 +1689,23 @@ static PyObject *dmi_cache_associativity(u8 code) "8-way Set-associative", "16-way Set-associative" /* 0x08 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Associativity", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.8.5"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x08) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x08) { + dmixml_AddTextContent(data_n, type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /******************************************************************************* ** 3.3.9 Port Connector Information (Type 8) */ -static PyObject *dmi_port_connector_type(u8 code) +void dmi_port_connector_type(xmlNode *node, const char *tpref, u8 code) { /* 3.3.9.2 */ static const char *type[] = { @@ -1586,16 +1753,24 @@ static PyObject *dmi_port_connector_type(u8 code) "PC-98 Full" /* 0xA4 */ }; - if(code <= 0x22) - return PyString_FromString(type[code]); - if(code >= 0xA0 && code <= 0xA4) - return PyString_FromString(type_0xA0[code - 0xA0]); - if(code == 0xFF) - return PyString_FromString("Other"); - return OUT_OF_SPEC; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Connector", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.9.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + dmixml_AddAttribute(data_n, "type", "%s", tpref); + + if(code <= 0x22) { + dmixml_AddTextContent(data_n, type[code]); + } else if(code >= 0xA0 && code <= 0xA4) { + dmixml_AddTextContent(data_n, type_0xA0[code - 0xA0]); + } else if(code == 0xFF) { + dmixml_AddTextContent(data_n, "Other"); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_port_type(u8 code) +void dmi_port_type(xmlNode *node, u8 code) { /* 3.3.9.3 */ static const char *type[] = { @@ -1639,20 +1814,27 @@ static PyObject *dmi_port_type(u8 code) "8251 FIFO Compatible" /* 0xA1 */ }; - if(code <= 0x21) - return PyString_FromString(type[code]); - if(code >= 0xA0 && code <= 0xA1) - return PyString_FromString(type_0xA0[code - 0xA0]); - if(code == 0xFF) - return PyString_FromString("Other"); - return OUT_OF_SPEC; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "PortType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.9.3"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code <= 0x21) { + dmixml_AddTextContent(data_n, type[code]); + } else if(code >= 0xA0 && code <= 0xA1) { + dmixml_AddTextContent(data_n, type_0xA0[code - 0xA0]); + } else if(code == 0xFF) { + dmixml_AddTextContent(data_n, "Other"); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /******************************************************************************* ** 3.3.10 System Slots (Type 9) */ -static PyObject *dmi_slot_type(u8 code) +void dmi_slot_type(xmlNode *node, u8 code) { /* 3.3.10.1 */ static const char *type[] = { @@ -1689,15 +1871,21 @@ static PyObject *dmi_slot_type(u8 code) "PCI Express x8", "PCI Express x16" /* 0xAA */ }; - - if(code >= 0x01 && code <= 0x13) - return PyString_FromString(type[code - 0x01]); - if(code >= 0xA0 && code <= 0xAA) - return PyString_FromString(type_0xA0[code - 0xA0]); - return OUT_OF_SPEC; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "SlotType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.10.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code >= 0x01 && code <= 0x13) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else if(code >= 0xA0 && code <= 0xAA) { + dmixml_AddTextContent(data_n, "%s", type_0xA0[code - 0xA0]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_slot_bus_width(u8 code) +void dmi_slot_bus_width(xmlNode *node, u8 code) { /* 3.3.10.2 */ static const char *width[] = { @@ -1716,13 +1904,19 @@ static PyObject *dmi_slot_bus_width(u8 code) "x16 ", "x32 " /* 0x0E */ }; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "SlotWidth", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.10.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x0E) - return PyString_FromString(width[code - 0x01]); - return OUT_OF_SPEC; + if( (code >= 0x01) && (code <= 0x0E) ) { + dmixml_AddTextContent(data_n, "%s", width[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_slot_current_usage(u8 code) +void dmi_slot_current_usage(xmlNode *node, u8 code) { /* 3.3.10.3 */ static const char *usage[] = { @@ -1732,13 +1926,21 @@ static PyObject *dmi_slot_current_usage(u8 code) "In Use" /* 0x04 */ }; - if(code >= 0x01 && code <= 0x04) - return PyString_FromString(usage[code - 0x01]); - return OUT_OF_SPEC; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "CurrentUsage", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.10.3"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + + if(code >= 0x01 && code <= 0x04) { + dmixml_AddTextContent(data_n, usage[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /* 3.3.1O.4 */ -static PyObject *dmi_slot_length(u8 code) +void dmi_slot_length(xmlNode *node, u8 code) { static const char *length[] = { "Other", /* 0x01 */ @@ -1747,22 +1949,28 @@ static PyObject *dmi_slot_length(u8 code) "Long" /* 0x04 */ }; - if(code >= 0x01 && code <= 0x04) - return PyString_FromString(length[code - 0x01]); - return OUT_OF_SPEC; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "SlotLength", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.10.4"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code >= 0x01 && code <= 0x04) { + dmixml_AddTextContent(data_n, length[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /* 3.3.10.5 */ -static PyObject *dmi_slot_id(u8 code1, u8 code2, u8 type) +void dmi_slot_id(xmlNode *node, u8 code1, u8 code2, u8 type) { - PyObject *data; - + dmixml_AddAttribute(node, "dmispec", "3.3.10.5"); switch (type) { case 0x04: /* MCA */ - data = PyString_FromFormat("%i", code1); + dmixml_AddAttribute(node, "id", "%i", code1); break; case 0x05: /* EISA */ - data = PyString_FromFormat("%i", code1); + dmixml_AddAttribute(node, "id", "%i", code1); break; case 0x06: /* PCI */ case 0x0E: /* PCI */ @@ -1772,18 +1980,18 @@ static PyObject *dmi_slot_id(u8 code1, u8 code2, u8 type) case 0x12: /* PCI-X */ case 0x13: /* AGP */ case 0xA5: /* PCI Express */ - data = PyString_FromFormat("%i", code1); + dmixml_AddAttribute(node, "id", "%i", code1); break; case 0x07: /* PCMCIA */ - data = PyString_FromFormat("Adapter %i, Socket %i", code1, code2); + dmixml_AddAttribute(node, "adapter", "%i", code1); + dmixml_AddAttribute(node, "id", "%i", code2); break; default: - data = Py_None; + break; } - return data; } -static PyObject *dmi_slot_characteristics(u8 code1, u8 code2) +void dmi_slot_characteristics(xmlNode *node, u8 code1, u8 code2) { /* 3.3.10.6 */ static const char *characteristics1[] = { @@ -1802,33 +2010,36 @@ static PyObject *dmi_slot_characteristics(u8 code1, u8 code2) "Hot-plug devices are supported", "SMBus signal is supported" /* 2 */ }; - - PyObject *data; - - if(code1 & (1 << 0)) - data = PyString_FromString("Unknown"); - else if((code1 & 0xFE) == 0 && (code2 & 0x07) == 0) - data = Py_None; - else { + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "SlotCharacteristics", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.10.6"); + dmixml_AddAttribute(data_n, "flags1", "0x%04x", code1); + dmixml_AddAttribute(data_n, "flags2", "0x%04x", code2); + + if(code1 & (1 << 0)) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else if((code1 & 0xFE) == 0 && (code2 & 0x07) == 0) { + // Nothing - empty tag + } else { int i; - data = PyList_New(7 + 3); for(i = 1; i <= 7; i++) { - if(code1 & (1 << i)) - PyList_SET_ITEM(data, i - 1, - PyString_FromString(characteristics1[i - 1])); - else - PyList_SET_ITEM(data, i - 1, Py_None); + if(code1 & (1 << i)) { + xmlNode *c_n = dmixml_AddTextChild(data_n, "Characteristic", "%s", + characteristics1[i - 1]); + dmixml_AddAttribute(c_n, "index", "%i", i); + c_n = NULL; + } } for(i = 0; i <= 2; i++) { - if(code2 & (1 << i)) - PyList_SET_ITEM(data, 7 + i, - PyString_FromString(characteristics2[i])); - else - PyList_SET_ITEM(data, 7 + i, Py_None); + if(code2 & (1 << i)) { + xmlNode *c_n = dmixml_AddTextChild(data_n, "Characteristic", "%s", + characteristics2[i]); + dmixml_AddAttribute(c_n, "index", "%i", i); + c_n = NULL; + } } } - return data; } static PyObject *dmi_slot_segment_bus_func(u16 code1, u8 code2, u8 code3) @@ -1848,7 +2059,7 @@ static PyObject *dmi_slot_segment_bus_func(u16 code1, u8 code2, u8 code3) ** 3.3.11 On Board Devices Information (Type 10) */ -static const char *dmi_on_board_devices_type(u8 code) +static const char *dmi_on_board_devices_type(xmlNode *node, u8 code) { /* 3.3.11.1 */ static const char *type[] = { @@ -1864,133 +2075,126 @@ static const char *dmi_on_board_devices_type(u8 code) "SAS Controller" /* 0x0A */ }; - if(code >= 0x01 && code <= 0x0A) - return type[code - 0x01]; - return out_of_spec; + dmixml_AddAttribute(node, "dmispec", "3.3.11.1"); + dmixml_AddAttribute(node, "flags", "0x%04x", code); + + if(code >= 0x01 && code <= 0x0A) { + dmixml_AddTextChild(node, "Type", "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(node, "outofspec", "1"); + } } -static PyObject *dmi_on_board_devices(struct dmi_header *h) +void dmi_on_board_devices(xmlNode *node, const char *tagname, struct dmi_header *h) { - PyObject *data = NULL; u8 *p = h->data + 4; u8 count = (h->length - 0x04) / 2; int i; - if((data = PyList_New(count))) { - PyObject *_pydict; - PyObject *_val; - - for(i = 0; i < count; i++) { - _pydict = PyDict_New(); - - _val = PyString_FromString(dmi_on_board_devices_type(p[2 * i] & 0x7F)); - PyDict_SetItemString(_pydict, "Type", _val); - Py_DECREF(_val); - - _val = p[2 * i] & 0x80 ? Py_True : Py_False; - PyDict_SetItemString(_pydict, "Enabled", _val); - Py_DECREF(_val); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.11"); - _val = dmi_string_py(h, p[2 * i + 1]); - PyDict_SetItemString(_pydict, "Description", _val); - Py_DECREF(_val); + for(i = 0; i < count; i++) { + xmlNode *dev_n = xmlNewChild(data_n, NULL, (xmlChar *) "Device", NULL); + assert( dev_n != NULL ); - PyList_SET_ITEM(data, i, _pydict); - } + dmi_on_board_devices_type(dev_n, p[2 * i] & 0x7F); + dmixml_AddAttribute(dev_n, "Enabled", "%i", ((p[2 * i] & 0x80) ? 1 : 0)); + dmixml_AddTextChild(dev_n, "Description", "%s", dmi_string(h, p[2 * i + 1])); + dev_n = NULL; } - - assert(data != NULL); - Py_INCREF(data); - return data; } /******************************************************************************* * 3.3.12 OEM Strings (Type 11) */ -static PyObject *dmi_oem_strings(struct dmi_header *h) +void dmi_oem_strings(xmlNode *node, struct dmi_header *h) { u8 *p = h->data + 4; u8 count = p[0x00]; int i; - PyObject *data = PyDict_New(); - PyObject *val; + dmixml_AddAttribute(node, "dmispec", "3.3.12"); + dmixml_AddAttribute(node, "count", "%i", count); for(i = 1; i <= count; i++) { - val = dmi_string_py(h, i); - PyDict_SetItem(data, PyInt_FromLong(i), val); - Py_DECREF(val); + xmlNode *str_n = dmixml_AddTextChild(node, "Record", "%s", dmi_string(h, i)); + assert( str_n != NULL ); + dmixml_AddAttribute(str_n, "index", "%i", i); } - - return data; } /******************************************************************************* ** 3.3.13 System Configuration Options (Type 12) */ -static PyObject *dmi_system_configuration_options(struct dmi_header *h) +void dmi_system_configuration_options(xmlNode *node, struct dmi_header *h) { u8 *p = h->data + 4; u8 count = p[0x00]; int i; - PyObject *data = PyDict_New(); - PyObject *val; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Options", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.13"); + dmixml_AddAttribute(data_n, "count", "%i", count); for(i = 1; i <= count; i++) { - val = dmi_string_py(h, i); - PyDict_SetItem(data, PyInt_FromLong(i), val); - Py_DECREF(val); - } + xmlNode *o_n = dmixml_AddTextChild(data_n, "Option", "%s", dmi_string(h, i)); + assert( o_n != NULL ); - return data; + dmixml_AddAttribute(o_n, "index", "%ld", i); + } } /******************************************************************************* ** 3.3.14 BIOS Language Information (Type 13) */ -static PyObject *dmi_bios_languages(struct dmi_header *h) +void dmi_bios_languages(xmlNode *node, struct dmi_header *h) { u8 *p = h->data + 4; u8 count = p[0x00]; int i; - PyObject *data = PyList_New(count + 1); - - for(i = 1; i <= count; i++) - PyList_SET_ITEM(data, i, dmi_string_py(h, i)); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Installed", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.14"); + dmixml_AddAttribute(data_n, "count", "%i", count); - return data; + for(i = 1; i <= count; i++) { + xmlNode *l_n = dmixml_AddTextChild(data_n, "Language", "%s", dmi_string_py(h, i)); + assert( l_n != NULL ); + dmixml_AddAttribute(l_n, "index", "%i", i); + } } /******************************************************************************* ** 3.3.15 Group Associations (Type 14) */ -static PyObject *dmi_group_associations_items(u8 count, const u8 * p) +void dmi_group_associations_items(xmlNode *node, u8 count, const u8 * p) { - int i; - - PyObject *data = PyList_New(count); - PyObject *val; + dmixml_AddAttribute(node, "dmispec", "3.3.15"); + dmixml_AddAttribute(node, "items", "%i", count); + int i; for(i = 0; i < count; i++) { - val = PyString_FromFormat("0x%04x (%s)", - WORD(p + 3 * i + 1), dmi_smbios_structure_type(p[3 * i]) - ); - PyList_SET_ITEM(data, i, val); + xmlNode *grp_n = xmlNewChild(node, NULL, (xmlChar *) "Group", NULL); + assert( grp_n != NULL ); + + dmixml_AddAttribute(grp_n, "handle", "0x%04x", WORD(p + 3 * i + 1)); + dmi_smbios_structure_type(grp_n, p[3 * i]); } - return data; } /******************************************************************************* ** 3.3.16 System Event Log (Type 15) */ -static const char *dmi_event_log_method(u8 code) +void dmi_event_log_method(xmlNode *node, u8 code) { static const char *method[] = { "Indexed I/O, one 8-bit index port, one 8-bit data port", /* 0x00 */ @@ -2000,14 +2204,22 @@ static const char *dmi_event_log_method(u8 code) "General-purpose non-volatile data functions" /* 0x04 */ }; - if(code <= 0x04) - return method[code]; - if(code >= 0x80) - return "OEM-specific"; - return out_of_spec; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "AccessMethod", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.16"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code <= 0x04) { + dmixml_AddTextContent(data_n, "%s", method[code]); + } else if(code >= 0x80){ + dmixml_AddTextContent(data_n, "OEM-specific"); + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_event_log_status_py(u8 code) +void dmi_event_log_status(xmlNode *node, u8 code) { static const char *valid[] = { "Invalid", /* 0 */ @@ -2018,44 +2230,64 @@ static PyObject *dmi_event_log_status_py(u8 code) "Full" /* 1 */ }; - return PyString_FromFormat("%s, %s", valid[(code >> 0) & 1], full[(code >> 1) & 1]); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Status", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.16"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + // FIXME: Should we use 0/1 instead of strings? + dmixml_AddAttribute(data_n, "Full", "%s", full[(code >> 1) & 1]); + dmixml_AddAttribute(data_n, "Valid", "%s", valid[(code >> 0) & 1]); } -static PyObject *dmi_event_log_address_py(u8 method, const u8 * p) +void dmi_event_log_address(xmlNode *node, u8 method, const u8 * p) { + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Address", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.16.3"); + dmixml_AddAttribute(data_n, "method", "0x%04x", method); + /* 3.3.16.3 */ switch (method) { case 0x00: case 0x01: case 0x02: - return PyString_FromFormat("Index 0x%04x, Data 0x%04x", WORD(p), WORD(p + 2)); + dmixml_AddAttribute(data_n, "Index", "0x%04x", WORD(p)); + dmixml_AddAttribute(data_n, "Data", "0x%04x", WORD(p + 2)); break; case 0x03: - return PyString_FromFormat("0x%08x", DWORD(p)); + dmixml_AddAttribute(data_n, "Data", "0x%08x", DWORD(p)); break; case 0x04: - return PyString_FromFormat("0x%04x", WORD(p)); + dmixml_AddAttribute(data_n, "Data", "0x%04x", WORD(p)); break; default: - return PyString_FromString("Unknown"); + dmixml_AddAttribute(data_n, "unknown", "1"); } } -static const char *dmi_event_log_header_type(u8 code) +void dmi_event_log_header_type(xmlNode *node, u8 code) { static const char *type[] = { "No Header", /* 0x00 */ "Type 1" /* 0x01 */ }; - if(code <= 0x01) - return type[code]; - if(code >= 0x80) - return "OEM-specific"; - return out_of_spec; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Format", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.16"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code <= 0x01) { + dmixml_AddTextContent(data_n, type[code]); + } else if(code >= 0x80) { + dmixml_AddTextContent(data_n, "OEM-specific"); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_event_log_descriptor_type(u8 code) +void dmi_event_log_descriptor_type(xmlNode *node, u8 code) { /* 3.3.16.6.1 */ static const char *type[] = { @@ -2085,20 +2317,23 @@ static PyObject *dmi_event_log_descriptor_type(u8 code) "System boot" /* 0x17 */ }; - const char *data; - - if(code <= 0x17 && type[code] != NULL) - data = type[code]; - else if(code >= 0x80 && code <= 0xFE) - data = "OEM-specific"; - else if(code == 0xFF) - data = "End of log"; - else - data = out_of_spec; - return PyString_FromString(data); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Descriptor", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.16.6.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code <= 0x17 && type[code] != NULL) { + dmixml_AddTextContent(data_n, "%s", type[code]); + } else if(code >= 0x80 && code <= 0xFE) { + dmixml_AddTextContent(data_n, "OEM-specific"); + } else if(code == 0xFF) { + dmixml_AddTextContent(data_n, "End of log"); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_event_log_descriptor_format(u8 code) +void dmi_event_log_descriptor_format(xmlNode *node, u8 code) { /* 3.3.16.6.2 */ static const char *format[] = { @@ -2111,37 +2346,36 @@ static PyObject *dmi_event_log_descriptor_format(u8 code) "Multiple-event system management" /* 0x06 */ }; - const char *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Format", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.16.6.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code <= 0x06) - data = format[code]; - else if(code >= 0x80) - data = "OEM-specific"; - else - data = out_of_spec; - return PyString_FromString(data); + if(code <= 0x06) { + dmixml_AddTextContent(data_n, format[code]); + } else if(code >= 0x80) { + dmixml_AddTextContent(data_n, "OEM-specific"); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_event_log_descriptors(u8 count, const u8 len, const u8 * p) +void dmi_event_log_descriptors(xmlNode *node, u8 count, const u8 len, const u8 * p) { /* 3.3.16.1 */ int i; - PyObject *data; + dmixml_AddAttribute(node, "dmispec", "3.3.16.1"); - data = PyList_New(count); for(i = 0; i < count; i++) { if(len >= 0x02) { - PyObject *subdata = PyDict_New(); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "LogType", NULL); + assert( data_n != NULL ); - PyDict_SetItemString(subdata, "Descriptor", - dmi_event_log_descriptor_type(p[i * len])); - PyDict_SetItemString(subdata, "Data Format", - dmi_event_log_descriptor_format(p[i * len + 1])); - PyList_SET_ITEM(data, i, subdata); + dmi_event_log_descriptor_type(data_n, p[i * len]); + dmi_event_log_descriptor_format(data_n, p[i * len + 1]); } } - return data; } /******************************************************************************* @@ -3303,256 +3537,191 @@ static PyObject *dmi_additional_info(const struct dmi_header *h, const char *pre ** Main */ -PyObject *dmi_decode(struct dmi_header * h, u16 ver) +void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) { - const u8 *data = h->data; - + xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL; //. 0xF1 --> 0xF100 //int minor = h->type<<8; - char _[2048]; - bzero(_, 2048); //dmi_codes_major *dmiMajor = (dmi_codes_major *)&dmiCodesMajor[map_maj[h->type]]; - dmi_codes_major *dmiMajor = (dmi_codes_major *) & dmiCodesMajor[h->type]; - PyObject *pylist = PyDict_New(); + dmi_codes_major *dmiMajor = (dmi_codes_major *) &dmiCodesMajor[h->type]; - PyDict_SetItemString(pylist, "id", PyString_FromString(dmiMajor->id)); - PyDict_SetItemString(pylist, "desc", PyString_FromString(dmiMajor->desc)); - PyObject *_val; //. A Temporary pointer (value) - PyObject *_key; //. Another temporary pointer (key) - PyObject *caseData = PyDict_New(); + dmixml_AddAttribute(handle_n, "id", "%s", dmiMajor->id); + dmixml_AddAttribute(handle_n, "type", "%s", h->type); + dmixml_AddTextChild(handle_n, "description", "%s", dmiMajor->desc); switch (h->type) { - case 0: /* 3.3.1 BIOS Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOS", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.1"); if(h->length < 0x12) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Vendor", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Release Date", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Vendor", "%s", data[0x04]); + dmixml_AddTextChild(sect_n, "Version", "%s", data[0x05]); + dmixml_AddTextChild(sect_n, "ReleaseDate", "%s", data[0x08]); /* * On IA-64, the BIOS base address will read 0 because * there is no BIOS. Skip the base address and the * runtime size in this case. */ - if(WORD(data + 0x06) != 0) { - _val = PyString_FromFormat("0x%04x0", WORD(data + 0x06)); - PyDict_SetItemString(caseData, "Address", _val); - Py_DECREF(_val); - _val = dmi_bios_runtime_size((0x10000 - WORD(data + 0x06)) << 4); - PyDict_SetItemString(caseData, "Runtime Size", _val); - Py_DECREF(_val); + if(WORD(data + 0x06) != 0) { + dmixml_AddTextChild(sect_n, "Address", "0x%04x0", WORD(data + 0x06)); + dmixml_AddTextChild(sect_n, "RuntimeSize", "%s", + dmi_bios_runtime_size((0x10000 - WORD(data + 0x06)) << 4)); } - _val = PyString_FromFormat("%i kB", (data[0x09] + 1) << 6); - PyDict_SetItemString(caseData, "ROM Size", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "ROMsize", "%i kB", (data[0x09] + 1) << 6); - _val = dmi_bios_characteristics(QWORD(data + 0x0A)); - PyDict_SetItemString(caseData, "Characteristics", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Characteristics", NULL); + assert( sub_n != NULL ); + + dmixml_AddAttribute(sub_n, "level", "0"); + dmi_bios_characteristics(sub_n, QWORD(data + 0x0A)); + sub_n = NULL; if(h->length < 0x13) break; - _val = dmi_bios_characteristics_x1(data[0x12]); - PyDict_SetItemString(caseData, "Characteristics x1", _val); - Py_DECREF(_val); + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Characteristics", NULL); + assert( sub_n != NULL ); + + dmixml_AddAttribute(sub_n, "level", "x1"); + dmi_bios_characteristics_x1(sub_n, data[0x12]); if(h->length < 0x14) break; - _val = dmi_bios_characteristics_x2(data[0x13]); - PyDict_SetItemString(caseData, "Characteristics x2", _val); - Py_DECREF(_val); + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Characteristics", NULL); + assert( sub_n != NULL ); + + dmixml_AddAttribute(sub_n, "level", "x2"); + dmi_bios_characteristics_x2(sub_n, data[0x13]); + sub_n = NULL; if(h->length < 0x18) break; if(data[0x14] != 0xFF && data[0x15] != 0xFF) { - _val = PyString_FromFormat("%i.%i", data[0x14], data[0x15]); - PyDict_SetItemString(caseData, "BIOS Revision", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "BIOSrevision", "%i.%i", data[0x14], data[0x15]); } if(data[0x16] != 0xFF && data[0x17] != 0xFF) { - _val = PyString_FromFormat("%i.%i", data[0x16], data[0x17]); - PyDict_SetItemString(caseData, "Firmware Revision", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "FirmwareRevision", "%i.%i", data[0x16], data[0x17]); } - + sect_n = NULL; break; case 1: /* 3.3.2 System Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemInformation", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.2"); if(h->length < 0x08) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Product Name", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x04])); + dmixml_AddTextChild(sect_n, "ProductName", "%s", dmi_string(h, data[0x05])); + dmixml_AddTextChild(sect_n, "Version", "%s", dmi_string(h, data[0x06])); + dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); if(h->length < 0x19) break; - _val = dmi_system_uuid_py(data + 0x08, ver); - PyDict_SetItemString(caseData, "UUID", _val); - Py_DECREF(_val); - _val = dmi_system_wake_up_type(data[0x18]); - PyDict_SetItemString(caseData, "Wake-Up Type", _val); - Py_DECREF(_val); + dmi_system_uuid(sect_n, data + 0x08, ver); + + dmi_system_wake_up_type(sect_n, data[0x18]); if(h->length < 0x1B) break; - _val = dmi_string_py(h, data[0x19]); - PyDict_SetItemString(caseData, "SKU Number", _val); - Py_DECREF(_val); - _val = dmi_string_py(h, data[0x1A]); - PyDict_SetItemString(caseData, "Family", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SKUnumber", "%s", dmi_string(h, data[0x19])); + dmixml_AddTextChild(sect_n, "Family", "%s", dmi_string(h, data[0x1A])); + sect_n = NULL; break; case 2: /* 3.3.3 Base Board Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Baseboard", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.3"); if(h->length < 0x08) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Product Name", _val); - Py_DECREF(_val); - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x04])); + dmixml_AddTextChild(sect_n, "ProductName", "%s", dmi_string(h, data[0x05])); + dmixml_AddTextChild(sect_n, "Version", "%s", dmi_string(h, data[0x06])); + dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); if(h->length < 0x0F) break; - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - _val = dmi_base_board_features(data[0x09]); - PyDict_SetItemString(caseData, "Features", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x08])); - _val = dmi_string_py(h, data[0x0A]); - PyDict_SetItemString(caseData, "Location In Chassis", _val); - Py_DECREF(_val); + dmi_base_board_features(sect_n, data[0x09]); - _val = PyString_FromFormat("0x%04x", WORD(data + 0x0B)); - PyDict_SetItemString(caseData, "Chassis Handle", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "ChassisLocation", "%s", dmi_string(h, data[0x0A])); + dmixml_AddTextChild(sect_n, "ChassisHandle", "0x%04x", WORD(data + 0x0B)); - _val = dmi_base_board_type(data[0x0D]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + dmi_base_board_type(sect_n, "Type", data[0x0D]); if(h->length < 0x0F + data[0x0E] * sizeof(u16)) break; - _val = dmi_base_board_handles(data[0x0E], data + 0x0F); - PyDict_SetItemString(caseData, "Type ???", _val); - Py_DECREF(_val); + + dmi_base_board_handles(sect_n, data[0x0E], data + 0x0F); + sect_n = NULL; break; case 3: /* 3.3.4 Chassis Information */ + sect_n= xmlNewChild(handle_n, NULL, (xmlChar *) "Chassis", NULL); + assert( sect_n != NULL ); if(h->length < 0x09) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_chassis_type_py(data[0x05] & 0x7F); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_chassis_lock(data[0x05] >> 7); - PyDict_SetItemString(caseData, "Lock", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x04])); + dmi_chassis_type(sect_n, data[0x05] & 0x7F); + dmi_chassis_lock(sect_n, data[0x05] >> 7); + dmixml_AddTextChild(sect_n, "Version", "%s", dmi_string(h, data[0x06])); + dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); + dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x08])); if(h->length < 0x0D) break; - _val = dmi_chassis_state(data[0x09]); - PyDict_SetItemString(caseData, "Boot-Up State", _val); - Py_DECREF(_val); - _val = dmi_chassis_state(data[0x0A]); - PyDict_SetItemString(caseData, "Power Supply State", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "ChassisStates", NULL); + assert( sub_n != NULL ); - _val = dmi_chassis_state(data[0x0B]); - PyDict_SetItemString(caseData, "Thermal State", _val); - Py_DECREF(_val); + dmi_chassis_state(sub_n, "BootUp", data[0x09]); + dmi_chassis_state(sub_n, "PowerSupply", data[0x0A]); + dmi_chassis_state(sub_n, "Thermal", data[0x0B]); - _val = PyString_FromString(dmi_chassis_security_status(data[0x0C])); - PyDict_SetItemString(caseData, "Security Status", _val); - Py_DECREF(_val); + dmi_chassis_security_status(sect_n, data[0x0C]); if(h->length < 0x11) break; - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x0D)); - PyDict_SetItemString(caseData, "OEM Information", _val); - Py_DECREF(_val); + + dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x0D)); if(h->length < 0x13) break; - _val = dmi_chassis_height(data[0x11]); - PyDict_SetItemString(caseData, "Height", _val); - Py_DECREF(_val); - _val = dmi_chassis_power_cords(data[0x12]); - PyDict_SetItemString(caseData, "Number Of Power Cords", _val); - Py_DECREF(_val); + dmi_chassis_height(sect_n, data[0x11]); + dmi_chassis_power_cords(sect_n, data[0x12]); if(h->length < 0x15) break; + if(h->length < 0x15 + data[0x13] * data[0x14]) break; - _val = dmi_chassis_elements(data[0x13], data[0x14], data + 0x15); - PyDict_SetItemString(caseData, "Elements", _val); - Py_DECREF(_val); + dmi_chassis_elements(sect_n, data[0x13], data[0x14], data + 0x15); + sect_n = NULL; break; case 4: /* 3.3.5 Processor Information */ @@ -3560,452 +3729,408 @@ PyObject *dmi_decode(struct dmi_header * h, u16 ver) if(h->length < 0x1A) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Socket Designation", _val); - Py_DECREF(_val); - - _val = dmi_processor_type(data[0x05]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Processor", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.5"); - _val = PyString_FromString(dmi_processor_family(h)); - PyDict_SetItemString(caseData, "Family", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SocketDesignation", "%s", dmi_string(h, data[0x04])); + dmi_processor_type(sect_n, data[0x05]); + dmi_processor_family(sect_n, h); - _val = dmi_processor_id(data[0x06], data + 8, dmi_string(h, data[0x10])); - PyDict_SetItemString(_val, "Vendor", dmi_string_py(h, data[0x07])); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); + dmi_processor_id(sect_n, data[0x06], data + 8, dmi_string(h, data[0x10])); - _val = dmi_string_py(h, data[0x10]); - PyDict_SetItemString(caseData, "Version", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Manufacturer", NULL); + assert( sub_n != NULL ); + dmixml_AddTextChild(sub_n, "Vendor", dmi_string(h, data[0x07])); - _val = dmi_processor_voltage(data[0x11]); - PyDict_SetItemString(caseData, "Voltage", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "Version", dmi_string(h, data[0x10])); + dmi_processor_voltage(sub_n, data[0x11]); + sub_n = NULL; - _val = dmi_processor_frequency_py(data + 0x12); - PyDict_SetItemString(caseData, "External Clock", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Frequencies", NULL); + assert( sub_n != NULL ); - _val = dmi_processor_frequency_py(data + 0x14); - PyDict_SetItemString(caseData, "Max Speed", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "ExternalClock", "%i", dmi_processor_frequency(data + 0x12)); + dmixml_AddTextChild(sub_n, "MaxSpeed", "%i", dmi_processor_frequency(data + 0x14)); + dmixml_AddTextChild(sub_n, "CurrentSpeed", "%i", dmi_processor_frequency(data + 0x16)); - _val = dmi_processor_frequency_py(data + 0x16); - PyDict_SetItemString(caseData, "Current Speed", _val); - Py_DECREF(_val); + /* TODO: Should CurrentSpeed be renamed to BootSpeed? Specification + * says this about Current Speed: + * + * This field identifies the processor's speed at + * system boot and the Processor ID field implies the + * processor's additional speed characteristics (i.e. single + * speed or multiple speed). + */ if(data[0x18] & (1 << 6)) { - _val = - PyString_FromFormat("Populated:%s", - dmi_processor_status(data[0x18] & 0x07)); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sect_n, "populated", "1"); + dmi_processor_status(sect_n, data[0x18] & 0x07); } else { - _val = PyString_FromString("Populated:No"); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sect_n, "populated", "0"); } - _val = dmi_processor_upgrade(data[0x19]); - PyDict_SetItemString(caseData, "Upgrade", _val); - Py_DECREF(_val); + + dmi_processor_upgrade(sect_n, data[0x19]); if(h->length < 0x20) break; - _val = dmi_processor_cache(WORD(data + 0x1A), "L1", ver); - PyDict_SetItemString(caseData, "L1 Cache Handle", _val); - Py_DECREF(_val); - _val = dmi_processor_cache(WORD(data + 0x1C), "L2", ver); - PyDict_SetItemString(caseData, "L2 Cache Handle", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Cache", NULL); + assert( sub_n != NULL ); - _val = dmi_processor_cache(WORD(data + 0x1E), "L3", ver); - PyDict_SetItemString(caseData, "L3 Cache Handle", _val); - Py_DECREF(_val); + sub2_n = xmlNewChild(sub_n, NULL, (xmlChar *) "Level", NULL); + assert( sub2_n != NULL ); + + dmixml_AddAttribute(sub2_n, "level", "1"); + dmi_processor_cache(sub2_n, WORD(data + 0x1A), ver); + sub2_n = NULL; + + + sub2_n = xmlNewChild(sub_n, NULL, (xmlChar *) "Level", NULL); + assert( sub2_n != NULL ); + + dmixml_AddAttribute(sub2_n, "level", "2"); + dmi_processor_cache(sub2_n, WORD(data + 0x1C), ver); + sub2_n = NULL; + + sub2_n = xmlNewChild(sub_n, NULL, (xmlChar *) "Level", NULL); + assert( sub2_n != NULL ); + + dmixml_AddAttribute(sub2_n, "level", "3"); + dmi_processor_cache(sub2_n, WORD(data + 0x1E), ver); + sub2_n = NULL; + sub_n = NULL; if(h->length < 0x23) break; - _val = dmi_string_py(h, data[0x20]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x21]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - _val = dmi_string_py(h, data[0x22]); - PyDict_SetItemString(caseData, "Part Number", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x20])); + dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x21])); + dmixml_AddTextChild(sect_n, "PartNumber", "%s", dmi_string(h, data[0x22])); if(h->length < 0x28) break; + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Cores", NULL); + assert( cores_n != NULL ); + if(data[0x23] != 0) { - _val = PyString_FromFormat("%i", data[0x23]); - PyDict_SetItemString(caseData, "Core Count", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "CoreCount", "%i", data[0x23]); } if(data[0x24] != 0) { - _val = PyString_FromFormat("%i", data[0x24]); - PyDict_SetItemString(caseData, "Core Enabled", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "CoresEnabled", "%i", data[0x24]); } if(data[0x25] != 0) { - _val = PyString_FromFormat("%i", data[0x25]); - PyDict_SetItemString(caseData, "Thread Count", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "ThreadCount", "%i", data[0x25]); } - _val = dmi_processor_characteristics(WORD(data + 0x26)); - PyDict_SetItemString(caseData, "Characteristics", _val); - Py_DECREF(_val); + dmi_processor_characteristics(sub_n, WORD(data + 0x26)); + sub_n = NULL; + sect_n = NULL; break; case 5: /* 3.3.6 Memory Controller Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryController", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.6"); - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0F) break; - _val = dmi_memory_controller_ed_method(data[0x04]); - PyDict_SetItemString(caseData, "Error Detecting Method", _val); - Py_DECREF(_val); - - _val = dmi_memory_controller_ec_capabilities(data[0x05]); - PyDict_SetItemString(caseData, "Error Correcting Capabilities", _val); - Py_DECREF(_val); - - _val = dmi_memory_controller_interleave(data[0x06]); - PyDict_SetItemString(caseData, "Supported Interleave", _val); - Py_DECREF(_val); - _val = dmi_memory_controller_interleave(data[0x07]); - PyDict_SetItemString(caseData, "Current Interleave", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "ErrorCorrection", NULL); + assert( errc_n != NULL ); - _val = PyString_FromFormat("%i MB", 1 << data[0x08]); - PyDict_SetItemString(caseData, "Maximum Memory Module Size", _val); - Py_DECREF(_val); + dmi_memory_controller_ed_method(sub_n, data[0x04]); + dmi_memory_controller_ec_capabilities(sub_n, "Capabilities", data[0x05]); + sub_n = NULL; - _val = PyString_FromFormat("%i MB", data[0x0E] * (1 << data[0x08])); - PyDict_SetItemString(caseData, "Maximum Total Memory Size", _val); - Py_DECREF(_val); + dmi_memory_controller_interleave(sect_n, "SupportedInterleave", data[0x06]); + dmi_memory_controller_interleave(sect_n, "CurrentInterleave", data[0x07]); - _val = dmi_memory_controller_speeds(WORD(data + 0x09)); - PyDict_SetItemString(caseData, "Supported Speeds", _val); - Py_DECREF(_val); + sub_n = dmixml_AddTextChild(sect_n, "MaxMemoryModuleSize", + "%i", (1 << data[0x08])); + dmixml_AddAttribute(sub_n, "unit", "MB"); + sub_n = NULL; - _val = dmi_memory_module_types(WORD(data + 0x0B)); - PyDict_SetItemString(caseData, "Supported Memory Types", _val); - Py_DECREF(_val); + sub_n = dmixml_AddTextChild(sect_n, "MaxTotalMemorySize", + "%i", data[0x0E] * (1 << data[0x08])); + dmixml_AddAttribute(sub_n, "unit", "MB"); + sub_n = NULL; - _val = dmi_processor_voltage(data[0x0D]); - PyDict_SetItemString(caseData, "Memory Module Voltage", _val); - Py_DECREF(_val); + dmi_memory_controller_speeds(sect_n, WORD(data + 0x09)); + dmi_memory_module_types(sect_n, "SupportedTypes", WORD(data + 0x0B)); + dmi_processor_voltage(sect_n, data[0x0D]); if(h->length < 0x0F + data[0x0E] * sizeof(u16)) break; - _val = dmi_memory_controller_slots(data[0x0E], data + 0x0F); - PyDict_SetItemString(caseData, "Associated Memory Sluts", _val); - Py_DECREF(_val); + + dmi_memory_controller_slots(sect_n, data[0x0E], data + 0x0F); if(h->length < 0x10 + data[0x0E] * sizeof(u16)) break; - _val = dmi_memory_controller_ec_capabilities(data[0x0F + data[0x0E] * sizeof(u16)]); - PyDict_SetItemString(caseData, "Enabled Error Correcting Capabilities", _val); - Py_DECREF(_val); + + dmi_memory_controller_ec_capabilities(sect_n, "EnabledErrorCorrection", + data[0x0F + data[0x0E] * sizeof(u16)]); + sect_n = NULL; break; case 6: /* 3.3.7 Memory Module Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryModule", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.7"); - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0C) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Socket Designation", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_connections(data[0x05]); - PyDict_SetItemString(caseData, "Bank Connections", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_speed(data[0x06]); - PyDict_SetItemString(caseData, "Current Speed", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_types(WORD(data + 0x07)); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_memory_module_size(data[0x09]); - PyDict_SetItemString(caseData, "Installed Size", _val); - Py_DECREF(_val); - _val = dmi_memory_module_size(data[0x0A]); - PyDict_SetItemString(caseData, "Enabled Size", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SocketDesignation", "%s", dmi_string(h, data[0x04])); + dmi_memory_module_connections(sect_n, data[0x05]); + dmi_memory_module_speed(sect_n, "ModuleSpeed", data[0x06]); + dmi_memory_module_types(sect_n, "Type", WORD(data + 0x07)); - _val = dmi_memory_module_error(data[0x0B]); - PyDict_SetItemString(caseData, "Error Status", _val); - Py_DECREF(_val); + dmi_memory_module_size(sect_n, "InstalledSize", data[0x09]); + dmi_memory_module_size(sect_n, "EnabledSize", data[0x0A]); + dmi_memory_module_error(sect_n, data[0x0B]); + sect_n = NULL; break; case 7: /* 3.3.8 Cache Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Cache", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.8"); - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0F) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Socket Designation", _val); - Py_DECREF(_val); - _val = PyDict_New(); - PyDict_SetItemString(_val, "Enabled", - WORD(data + 0x05) & 0x0080 ? Py_True : Py_False); - PyDict_SetItemString(_val, "Socketed", - WORD(data + 0x05) & 0x0008 ? Py_True : Py_False); - PyDict_SetItemString(_val, "Level", - PyInt_FromLong((WORD(data + 0x05) & 0x0007) + 1)); - PyDict_SetItemString(caseData, "Configuration", _val); - Py_DECREF(_val); - - _val = dmi_cache_mode((WORD(data + 0x05) >> 8) & 0x0003); - PyDict_SetItemString(caseData, "Operational Mode", _val); - Py_DECREF(_val); - - _val = dmi_cache_location((WORD(data + 0x05) >> 5) & 0x0003); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_cache_size(WORD(data + 0x09)); - PyDict_SetItemString(caseData, "Installed Size", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SocketDesignation", dmi_string(h, data[0x04])); + dmixml_AddAttribute(sect_n, "Enabled", "%i", (WORD(data + 0x05) & 0x0080 ? 1 : 0)); + dmixml_AddAttribute(sect_n, "Socketed", "%i", (WORD(data + 0x05) & 0x0008 ? 1 : 0)); + dmixml_AddAttribute(sect_n, "Level", "%ld", ((WORD(data + 0x05) & 0x0007) + 1)); - _val = dmi_cache_size(WORD(data + 0x07)); - PyDict_SetItemString(caseData, "Maximum Size", _val); - Py_DECREF(_val); + sub_n = dmixml_AddTextChild(sect_n, "OperationalMode", "%s", + dmi_cache_mode((WORD(data + 0x05) >> 8) & 0x0003)); + dmixml_AddAttribute(sub_n, "flags", "0x%04x", (WORD(data + 0x05) >> 8) & 0x0003); - _val = dmi_cache_types(WORD(data + 0x0B)); - PyDict_SetItemString(caseData, "Supported SRAM Types", _val); - Py_DECREF(_val); + dmi_cache_location(sect_n, (WORD(data + 0x05) >> 5) & 0x0003); + dmi_cache_size(sect_n, "InstalledSize", WORD(data + 0x09)); + dmi_cache_size(sect_n, "MaximumSize", WORD(data + 0x07)); - _val = dmi_cache_types(WORD(data + 0x0D)); - PyDict_SetItemString(caseData, "Installed SRAM Type", _val); - Py_DECREF(_val); + dmi_cache_types(sect_n, "SupportedSRAMtypes", WORD(data + 0x0B)); + dmi_cache_types(sect_n, "InstalledSRAMtypes", WORD(data + 0x0D)); if(h->length < 0x13) break; - _val = dmi_memory_module_speed(data[0x0F]); - PyDict_SetItemString(caseData, "Speed", _val); - Py_DECREF(_val); - - _val = dmi_cache_ec_type(data[0x10]); - PyDict_SetItemString(caseData, "Error Correction Type", _val); - Py_DECREF(_val); - _val = dmi_cache_type(data[0x11]); - PyDict_SetItemString(caseData, "System Type", _val); - Py_DECREF(_val); - - _val = dmi_cache_associativity(data[0x12]); - PyDict_SetItemString(caseData, "Associativity", _val); - Py_DECREF(_val); + dmi_memory_module_speed(sect_n, "Speed", data[0x0F]); + dmi_cache_ec_type(sect_n, data[0x10]); + dmi_cache_type(sect_n, data[0x11]); + dmi_cache_associativity(sect_n, data[0x12]); + sect_n = NULL; break; case 8: /* 3.3.9 Port Connector Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Connector", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.9"); - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x09) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Internal Reference Designator", _val); - Py_DECREF(_val); - _val = dmi_port_connector_type(data[0x05]); - PyDict_SetItemString(caseData, "Internal Connector Type", _val); - Py_DECREF(_val); + sub_n = dmixml_AddTextChild(sect_n, "DesignatorRef", dmi_string(h, data[0x04])); + assert( sub_n != NULL ); + dmixml_AddAttribute(sub_n, "type", "internal"); + sub_n = NULL; - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "External Reference Designator", _val); - Py_DECREF(_val); + dmi_port_connector_type(sect_n, "internal", data[0x05]); - _val = dmi_port_connector_type(data[0x07]); - PyDict_SetItemString(caseData, "External Connector Type", _val); - Py_DECREF(_val); + sub_n = dmixml_AddTextChild(sect_n, "DesignatorRef", dmi_string(h, data[0x06])); + assert( sub_n != NULL ); + dmixml_AddAttribute(sub_n, "type", "external"); + sub_n = NULL; - _val = dmi_port_type(data[0x08]); - PyDict_SetItemString(caseData, "Port Type", _val); - Py_DECREF(_val); + dmi_port_connector_type(sect_n, "external", data[0x07]); + dmi_port_type(sect_n, data[0x08]); + sect_n = NULL; break; case 9: /* 3.3.10 System Slots */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Connector", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.10"); - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0C) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Designation", _val); - Py_DECREF(_val); - _val = dmi_slot_bus_width(data[0x06]); - PyDict_SetItemString(caseData, "Type:SlotBusWidth", _val); - Py_DECREF(_val); - _val = dmi_slot_type(data[0x05]); - PyDict_SetItemString(caseData, "Type:SlotType", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Designation", "%s", dmi_string(h, data[0x04])); - _val = dmi_slot_current_usage(data[0x07]); - PyDict_SetItemString(caseData, "Current Usage", _val); - Py_DECREF(_val); + dmi_slot_bus_width(sect_n, data[0x06]); + dmi_slot_type(sect_n, data[0x05]); + dmi_slot_current_usage(sect_n, data[0x07]); + dmi_slot_length(sect_n, data[0x08]); + dmi_slot_id(sect_n, data[0x09], data[0x0A], data[0x05]); - _val = dmi_slot_length(data[0x08]); - PyDict_SetItemString(caseData, "SlotLength", _val); - Py_DECREF(_val); - _val = dmi_slot_id(data[0x09], data[0x0A], data[0x05]); - PyDict_SetItemString(caseData, "SlotId", _val); - Py_DECREF(_val); + if( h->length < 0x0D ) { + dmi_slot_characteristics(sect_n, data[0x0B], 0x00); + } else { + dmi_slot_characteristics(sect_n, data[0x0B], data[0x0C]); + } - _val = - (h->length < 0x0D) ? dmi_slot_characteristics(data[0x0B], - 0x00) : - dmi_slot_characteristics(data[0x0B], data[0x0C]); - PyDict_SetItemString(caseData, "Characteristics", _val); - Py_DECREF(_val); + sect_n = NULL; break; case 10: /* 3.3.11 On Board Devices Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OnBoardDevices", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.11"); - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); + sect_n = NULL; break; case 11: /* 3.3.12 OEM Strings */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OEMstrings", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.12"); - PyDict_SetItemString(caseData, "dmi_on_board_devices", dmi_on_board_devices(h)); + dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x05) break; - _val = dmi_oem_strings(h); - PyDict_SetItemString(caseData, "Strings", _val); - Py_DECREF(_val); + dmi_oem_strings(sect_n, h); + + sect_n = NULL; break; case 12: /* 3.3.13 System Configuration Options */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemConfig", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.13"); if(h->length < 0x05) break; - _val = dmi_system_configuration_options(h); - PyDict_SetItemString(caseData, "Options", _val); - Py_DECREF(_val); + dmi_system_configuration_options(sect_n, h); + + sect_n = NULL; break; case 13: /* 3.3.14 BIOS Language Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOSlanguage", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.14"); if(h->length < 0x16) break; - _val = PyString_FromFormat("%i", data[0x04]); - PyDict_SetItemString(caseData, "Installable Languages", _val); - Py_DECREF(_val); - _val = dmi_bios_languages(h); - PyList_SET_ITEM(_val, 0, dmi_string_py(h, data[0x15])); - PyDict_SetItemString(caseData, "Currently Installed Language", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sect_n, "installable_languages", "%i", data[0x04]); + + dmi_bios_languages(sect_n, h); + sect_n = NULL; break; case 14: /* 3.3.15 Group Associations */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "GroupAssociations", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.15"); if(h->length < 0x05) break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Name", _val); - Py_DECREF(_val); - _val = PyString_FromFormat("%i", (h->length - 0x05) / 3); - PyDict_SetItemString(caseData, "Items", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Name", "%s", dmi_string(h, data[0x04])); - _val = dmi_group_associations_items((h->length - 0x05) / 3, data + 0x05); - PyDict_SetItemString(caseData, "Items2", _val); //. FIXME: Title - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Groups", NULL); + assert( sub_n != NULL ); + dmi_group_associations_items(sub_n, (h->length - 0x05) / 3, data + 0x05); + + sect_n = NULL; break; case 15: /* 3.3.16 System Event Log */ + // SysEventLog - sect_n + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SysEventLog", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.16"); if(h->length < 0x14) break; - _val = PyString_FromFormat("%i bytes", WORD(data + 0x04)); - PyDict_SetItemString(caseData, "Area Length", _val); - Py_DECREF(_val); - _val = PyString_FromFormat("0x%04x", WORD(data + 0x06)); - PyDict_SetItemString(caseData, "Header Start Offset", _val); - Py_DECREF(_val); + dmi_event_log_status(sect_n, data[0x0B]); - if(WORD(data + 0x08) - WORD(data + 0x06)) { - _val = - PyString_FromFormat("%i byte%s", WORD(data + 0x08) - WORD(data + 0x06), - WORD(data + 0x08) - WORD(data + 0x06) > - 1 ? "s" : ""); - PyDict_SetItemString(caseData, "Header Length", _val); - Py_DECREF(_val); - } + // SysEventLog/Access - sub + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Access", NULL); + assert( sub_n != NULL ); - _val = PyString_FromFormat("0x%04x", WORD(data + 0x08)); - PyDict_SetItemString(caseData, "Data Start Offset", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "AreaLength", "%i", WORD(data + 0x04)); + dmi_event_log_method(sub_n, data[0x0A]); + dmi_event_log_address(sub_n, data[0x0A], data + 0x10); - _val = PyString_FromFormat("%s", dmi_event_log_method(data[0x0A])); - PyDict_SetItemString(caseData, "Access Method", _val); - Py_DECREF(_val); + // SysEventLog/Access/Header - sub2 + sub2_n = xmlNewChild(sub_n, NULL, (xmlChar *) "Header", NULL); + assert( sub2_n != NULL ); - _val = dmi_event_log_address_py(data[0x0A], data + 0x10); - PyDict_SetItemString(caseData, "Access Address", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub2_n, "OffsetStart", "0x%04x", WORD(data + 0x06)); - _val = dmi_event_log_status_py(data[0x0B]); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + if((WORD(data + 0x08) - WORD(data + 0x06)) >= 0) { + dmixml_AddTextChild(sub2_n, "Length", "%i", WORD(data + 0x08) - WORD(data + 0x06)); + } - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Change Token", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub2_n, "DataOffset", "0x%04x", WORD(data + 0x08)); + dmixml_AddTextChild(sub2_n, "ChangeToken", "0x%08x", DWORD(data + 0x0C)); if(h->length < 0x17) break; - _val = PyString_FromFormat("%s", dmi_event_log_header_type(data[0x14])); - PyDict_SetItemString(caseData, "Header Format", _val); - Py_DECREF(_val); - _val = PyString_FromFormat("%i", data[0x15]); - PyDict_SetItemString(caseData, "Supported Log Type Descriptors", _val); - Py_DECREF(_val); + // SysEventLog/Access/Header/Format - sub2_n + dmi_event_log_header_type(sub2_n, data[0x14]); + + sub2_n = NULL; + sub_n = NULL; + + // SysEventLog/LogTypes - resuing sub_n + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "LogTypes", NULL); + assert( sub_n != NULL ); + + // SysEventLog/LogTypes/@count + dmixml_AddAttribute(sub_n, "count", "%i", data[0x15]); if(h->length < 0x17 + data[0x15] * data[0x16]) break; - _val = dmi_event_log_descriptors(data[0x15], data[0x16], data + 0x17); - PyDict_SetItemString(caseData, "DMI Event Log Descriptors", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "length", "%i", data[0x16]); + + // SysEventLog/LogTypes/LogType + dmi_event_log_descriptors(sub_n, data[0x15], data[0x16], data + 0x17); + + sub_n = NULL; + sect_n = NULL; break; case 16: /* 3.3.17 Physical Memory Array */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "PhysicalMemoryArray", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.17"); if(h->length < 0x0F) break; + + /* ** BOOKMARK ** */ + _val = dmi_memory_array_location(data[0x04]); PyDict_SetItemString(caseData, "Location", _val); Py_DECREF(_val); @@ -4941,9 +5066,6 @@ PyObject *dmi_decode(struct dmi_header * h, u16 ver) Py_DECREF(_key); Py_DECREF(_val); } - - Py_INCREF(caseData); - return caseData; } void to_dmi_header(struct dmi_header *h, u8 * data) @@ -5120,13 +5242,14 @@ int dump(const char *dumpfile) return ret == 0 ? found : ret; } -static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, PyObject * pydata) +static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) { u8 *buf; u8 *data; int i = 0; if(opt.type == NULL) { + /* FIXME: How to interpret this section in XML? */ dmiSetItem(pydata, "dmi_table_size", "%i structures occupying %i bytes", num, len); /* TODO DUMP * if (!(opt.flags & FLAG_FROM_DUMP)) @@ -5153,7 +5276,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, P to_dmi_header(&h, data); display = ((opt.type == NULL || opt.type[h.type]) -// && !(h.type>39 && h.type<=127) + // && !(h.type>39 && h.type<=127) && !opt.string); /* @@ -5168,26 +5291,27 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, P break; } - /* In quiet mode (FLAG_QUIET - removed for python-dmidecode all together), stop decoding at end of table marker */ - - char hid[7]; - - sprintf(hid, "0x%04x", h.handle); - PyObject *hDict = PyDict_New(); + /* In quiet mode (FLAG_QUIET - removed for python-dmidecode all together), + * stop decoding at end of table marker + */ - dmiSetItem(hDict, "dmi_handle", hid); - dmiSetItem(hDict, "dmi_type", "%d", h.type); - dmiSetItem(hDict, "dmi_size", "%d", h.length); + xmlNode *handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "dmi_handle", NULL); + assert( handle_n != NULL ); + dmixml_AddAttribute(handle_n, "id", "0x%04x%c", h.handle); + dmixml_AddAttribute(handle_n, "type", "%d", h.type); + dmixml_AddAttribute(handle_n, "size", "%d", h.length); /* assign vendor for vendor-specific decodes later */ - if(h.type == 0 && h.length >= 5) + if(h.type == 0 && h.length >= 5) { + /* FIXME: Need XML API */ dmi_set_vendor(dmi_string(&h, data[0x04])); + } /* look for the next handle */ next = data + h.length; - while(next - buf + 1 < len && (next[0] != 0 || next[1] != 0)) + while(next - buf + 1 < len && (next[0] != 0 || next[1] != 0)) { next++; - + } next += 2; if(display) { @@ -5202,12 +5326,11 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, P * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); * } */ - PyDict_SetItem(hDict, PyString_FromString("data"), - dmi_decode(&h, ver)); - PyDict_SetItem(pydata, PyString_FromString(hid), hDict); + dmi_decode(handle_n, &h, ver); } else fprintf(stderr, ""); } else if(opt.string != NULL && opt.string->type == h.type) { + // <<<---- ** Need to handle this as well ** dmi_table_string_py(&h, data, hDict, ver); } @@ -5275,7 +5398,8 @@ int smbios_decode_set_version(u8 * buf, const char *devmem, PyObject ** pydata) } return check; } -int smbios_decode(u8 * buf, const char *devmem, PyObject * pydata) + +int smbios_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) { int check = _smbios_decode_check(buf); @@ -5292,7 +5416,7 @@ int smbios_decode(u8 * buf, const char *devmem, PyObject * pydata) } //printf(">>%d @ %d, %d<<\n", DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C)); dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, - pydata); + xmlnode); } return check; } -- cgit From 612445e94781f14af65490b52c898b9eaa5f5e85 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 8 Apr 2009 19:02:03 +0200 Subject: Ported most functions to XML interface Still do not compile --- src/dmidecode.c | 2592 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 1315 insertions(+), 1277 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 907fe57..773a673 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -5,6 +5,7 @@ * * Copyright 2000-2002 Alan Cox * Copyright 2002-2008 Jean Delvare + * Copyright 2009 David Sommerseth * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -63,9 +64,9 @@ /* #undef NDEBUG -#include */ +#include #include #include #include @@ -95,37 +96,6 @@ static const char *bad_index = ""; ** Type-independant Stuff */ -static PyObject *dmi_string_py(const struct dmi_header *dm, u8 s) -{ - char *bp = (char *)dm->data; - size_t i, len; - - PyObject *data; - - if(s == 0) - data = PyString_FromString("Not Specified"); - else { - bp += dm->length; - while(s > 1 && *bp) { - bp += strlen(bp); - bp++; - s--; - } - - if(!*bp) - data = BAD_INDEX; - else { - /* ASCII filtering */ - len = strlen(bp); - for(i = 0; i < len; i++) - if(bp[i] < 32 || bp[i] == 127) - bp[i] = '.'; - data = PyString_FromString(bp); - } - } - return data; -} - const char *dmi_string(const struct dmi_header *dm, u8 s) { char *bp = (char *)dm->data; @@ -233,25 +203,36 @@ static int dmi_bcd_range(u8 value, u8 low, u8 high) return 1; } -PyObject *dmi_dump(struct dmi_header * h) +void dmi_dump(xmlNode *node, struct dmi_header * h) { int row, i; const char *s; + xmlNode *dump_n = NULL, *row_n = NULL; + char *tmp_s = NULL; - PyObject *data = PyDict_New(); - PyObject *data1 = PyList_New(0); + dump_n = xmlNewChild(node, NULL, (xmlChar *) "HeaderAndData", NULL); + assert( dump_n != NULL ); + tmp_s = (char *) malloc((h->length * 2) + 2); for(row = 0; row < ((h->length - 1) >> 4) + 1; row++) { - for(i = 0; i < 16 && i < h->length - (row << 4); i++) - PyList_Append(data1, - PyString_FromFormat("0x%02x", (h->data)[(row << 4) + i])); + memset(tmp_s, 0, (h->length * 2) + 2); + + for(i = 0; i < (16 && i < h->length - (row << 4)); i++) { + snprintf(tmp_s + strlen(tmp_s), (h->length * 2)-strlen(tmp_s), + "0x%02x", (h->data)[(row << 4) + i]); + } + row_n = dmixml_AddTextChild(dump_n, "Row", "%s", tmp_s); + dmixml_AddAttribute(row_n, "index", "%i", row); + row_n = NULL; } - PyDict_SetItemString(data, "Header and Data", data1); + free(tmp_s); tmp_s = NULL; + dump_n = NULL; + + dump_n = xmlNewChild(node, NULL, (xmlChar *) "Strings", NULL); + assert( dump_n != NULL ); if((h->data)[h->length] || (h->data)[h->length + 1]) { i = 1; - PyObject *data2 = PyList_New(0); - while((s = dmi_string(h, i++)) != bad_index) { //. FIXME: DUMP /* @@ -265,23 +246,31 @@ PyObject *dmi_dump(struct dmi_header * h) * } * else fprintf(stderr, "%s|", s); */ - PyList_Append(data1, PyString_FromFormat("%s", s)); + row_n = dmixml_AddTextChild(dump_n, "String", "%s", s); + dmixml_AddAttribute(row_n, "index", "%i", i); + row_n = NULL; } - PyDict_SetItemString(data, "Strings", data2); } - return data; + dump_n = NULL; } /******************************************************************************* ** 3.3.1 BIOS Information (Type 0) */ -static PyObject *dmi_bios_runtime_size(u32 code) +void dmi_bios_runtime_size(xmlNode *node, u32 code) { - if(code & 0x000003FF) - return PyString_FromFormat("%i bytes", code); - else - return PyString_FromFormat("%i kB", code >> 10); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "RuntimeSize", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code & 0x000003FF) { + dmixml_AddAttribute(data_n, "unit", "bytes"); + dmixml_AddTextContent(data_n, "%i", code); + } else { + dmixml_AddAttribute(data_n, "unit", "KB"); + dmixml_AddTextContent(data_n, "%i", code >> 10); + } } /* 3.3.1.1 */ @@ -321,7 +310,7 @@ void dmi_bios_characteristics(xmlNode *node, u64 code) dmixml_AddAttribute(node, "dmispec", "3.3.1.1"); dmixml_AddAttribute(node, "flags", "0x%04x", code); - if(code.l & (1 << 3)) { + if(code.l&(1<<3)) { dmixml_AddAttribute(node, "unavailable", "1"); dmixml_AddTextContent(node, characteristics[0]); } else { @@ -2042,24 +2031,23 @@ void dmi_slot_characteristics(xmlNode *node, u8 code1, u8 code2) } } -static PyObject *dmi_slot_segment_bus_func(u16 code1, u8 code2, u8 code3) +void dmi_slot_segment_bus_func(xmlNode *node, u16 code1, u8 code2, u8 code3) { /* 3.3.10.8 */ - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "BusAddress", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.10.8"); - if(!(code1 == 0xFFFF && code2 == 0xFF && code3 == 0xFF)) - data = - PyString_FromFormat("%04x:%02x:%02x.%x", code1, code2, code3 >> 3, code3 & 0x7); - else - data = Py_None; - return data; + if(!(code1 == 0xFFFF && code2 == 0xFF && code3 == 0xFF)) { + dmixml_AddTextContent(data_n, "%04x:%02x:%02x.%x", code1, code2, code3 >> 3, code3 & 0x7); + } } /******************************************************************************* ** 3.3.11 On Board Devices Information (Type 10) */ -static const char *dmi_on_board_devices_type(xmlNode *node, u8 code) +void dmi_on_board_devices_type(xmlNode *node, u8 code) { /* 3.3.11.1 */ static const char *type[] = { @@ -2165,7 +2153,7 @@ void dmi_bios_languages(xmlNode *node, struct dmi_header *h) dmixml_AddAttribute(data_n, "count", "%i", count); for(i = 1; i <= count; i++) { - xmlNode *l_n = dmixml_AddTextChild(data_n, "Language", "%s", dmi_string_py(h, i)); + xmlNode *l_n = dmixml_AddTextChild(data_n, "Language", "%s", dmi_string(h, i)); assert( l_n != NULL ); dmixml_AddAttribute(l_n, "index", "%i", i); } @@ -2382,7 +2370,7 @@ void dmi_event_log_descriptors(xmlNode *node, u8 count, const u8 len, const u8 * ** 3.3.17 Physical Memory Array (Type 16) */ -static PyObject *dmi_memory_array_location(u8 code) +void dmi_memory_array_location(xmlNode *node, u8 code) { /* 3.3.17.1 */ static const char *location[] = { @@ -2405,14 +2393,21 @@ static PyObject *dmi_memory_array_location(u8 code) "PC-98/Card Slot Add-on Card" /* 0xA4, from master.mif */ }; - if(code >= 0x01 && code <= 0x0A) - return PyString_FromString(location[code - 0x01]); - if(code >= 0xA0 && code <= 0xA4) - return PyString_FromString(location_0xA0[code - 0xA0]); - return OUT_OF_SPEC; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Location", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.17.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code >= 0x01 && code <= 0x0A) { + dmixml_AddTextContent(data_n, location[code - 0x01]); + } else if(code >= 0xA0 && code <= 0xA4) { + dmixml_AddTextContent(data_n, location_0xA0[code - 0xA0]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_array_use(u8 code) +void dmi_memory_array_use(xmlNode *node, u8 code) { /* 3.3.17.2 */ static const char *use[] = { @@ -2424,13 +2419,19 @@ static PyObject *dmi_memory_array_use(u8 code) "Non-volatile RAM", "Cache Memory" /* 0x07 */ }; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Use", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.17.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x07) - return PyString_FromString(use[code - 0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x07) { + dmixml_AddTextContent(data_n, use[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_array_ec_type(u8 code) +void dmi_memory_array_ec_type(xmlNode *node, u8 code) { /* 3.3.17.3 */ static const char *type[] = { @@ -2443,78 +2444,92 @@ static PyObject *dmi_memory_array_ec_type(u8 code) "CRC" /* 0x07 */ }; - if(code >= 0x01 && code <= 0x07) - return PyString_FromString(type[code - 0x01]); - return OUT_OF_SPEC; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "ErrorCorrectionType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.17.3"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code >= 0x01 && code <= 0x07) { + dmixml_AddTextContent(data_n, type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_array_capacity(u32 code) +void dmi_memory_array_capacity(xmlNode *node, u32 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "MaxCapacity", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000000) - data = PyString_FromString("Unknown"); - else { - if((code & 0x000FFFFF) == 0) - data = PyString_FromFormat("%i GB", code >> 20); - else if((code & 0x000003FF) == 0) - data = PyString_FromFormat("%i MB", code >> 10); - else - data = PyString_FromFormat("%i kB", code); + if(code == 0x8000000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + if((code & 0x000FFFFF) == 0) { + dmixml_AddAttribute(data_n, "unit", "GB"); + dmixml_AddTextContent(data_n, "%i", code >> 20); + } else if((code & 0x000003FF) == 0) { + dmixml_AddAttribute(data_n, "unit", "MB"); + dmixml_AddTextContent(data_n, "%i", code >> 10); + } else { + dmixml_AddAttribute(data_n, "unit", "KB"); + dmixml_AddTextContent(data_n, "%i", code); + } } - return data; } -static PyObject *dmi_memory_array_error_handle(u16 code) +void dmi_memory_array_error_handle(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "ErrorInfoHandle", NULL); + assert( data_n != NULL ); - if(code == 0xFFFE) - data = PyString_FromString("Not Provided"); - else if(code == 0xFFFF) - data = PyString_FromString("No Error"); - else - data = PyString_FromFormat("0x%04x", code); - return data; + if(code == 0xFFFE) { + dmixml_AddAttribute(data_n, "not_provided", "1"); + } else if(code == 0xFFFF) { + dmixml_AddAttribute(data_n, "no_error", "1"); + } else { + dmixml_AddTextContent(data_n, "0x%04x", code); + } } /******************************************************************************* ** 3.3.18 Memory Device (Type 17) */ -static PyObject *dmi_memory_device_width(u16 code) +void dmi_memory_device_width(xmlNode *node, const char *tagname, u16 code) { /* ** If no memory module is present, width may be 0 */ - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); - if(code == 0xFFFF || code == 0) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%i bits", code); - return data; + if(code == 0xFFFF || code == 0) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "bit"); + dmixml_AddTextContent(data_n, "%i", code); + } } -static PyObject *dmi_memory_device_size(u16 code) +void dmi_memory_device_size(xmlNode *node, u16 code) { - PyObject *data = NULL; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Size", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0) - data = Py_None; //. No Module Installed - else if(code == 0xFFFF) - data = PyString_FromString("Unknown"); //. Unknown - else { + if(code == 0) { + dmixml_AddAttribute(data_n, "empty", "1"); + } else if(code == 0xFFFF) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { //. Keeping this as String rather than Int as it has KB and MB representations... - if(code & 0x8000) - data = PyString_FromFormat("%d KB", code & 0x7FFF); - else - data = PyString_FromFormat("%d MB", code); + dmixml_AddAttribute(data_n, "unit", "%s", (code & 0x8000 ? "KB" : "MB")); + dmixml_AddTextContent(data_n, "%d", (code & 0x8000 ? code & 0x7FFF : code)); } - return data; } -static PyObject *dmi_memory_device_form_factor(u8 code) +void dmi_memory_device_form_factor(xmlNode *node, u8 code) { /* 3.3.18.1 */ static const char *form_factor[] = { @@ -2534,27 +2549,32 @@ static PyObject *dmi_memory_device_form_factor(u8 code) "SRIMM", "FB-DIMM" /* 0x0F */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "FormFactor", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.18.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x0F) - return data = PyString_FromString(form_factor[code - 0x01]); - return data = OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x0F) { + dmixml_AddTextContent(data_n, "%s", form_factor[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_device_set(u8 code) +void dmi_memory_device_set(xmlNode *node, u8 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Set", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0) - data = Py_None; - else if(code == 0xFF) - data = PyString_FromString("Unknown"); - else - data = PyInt_FromLong(code); - return data; + if(code == 0xFF) { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } else if( code > 0 ) { + dmixml_AddTextContent(data_n, "%ld", code); + } } -static PyObject *dmi_memory_device_type(u8 code) +void dmi_memory_device_type(xmlNode *node, u8 code) { /* 3.3.18.2 */ static const char *type[] = { @@ -2579,13 +2599,19 @@ static PyObject *dmi_memory_device_type(u8 code) "DDR2", "DDR2 FB-DIMM" /* 0x14 */ }; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.18.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x14) - return PyString_FromString(type[code - 0x01]); - return OUT_OF_SPEC; + if(code >= 0x01 && code <= 0x14) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_device_type_detail(u16 code) +void dmi_memory_device_type_detail(xmlNode *node, u16 code) { /* 3.3.18.3 */ static const char *detail[] = { @@ -2602,40 +2628,43 @@ static PyObject *dmi_memory_device_type_detail(u16 code) "Cache DRAM", "Non-Volatile" /* 12 */ }; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "TypeDetails", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.18.3"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - PyObject *data; - - if((code & 0x1FFE) == 0) - data = Py_None; - else { + if((code & 0x1FFE) != 0) { int i; - - data = PyList_New(12); - for(i = 1; i <= 12; i++) - if(code & (1 << i)) - PyList_SET_ITEM(data, i - 1, PyString_FromString(detail[i - 1])); - else - PyList_SET_ITEM(data, i - 1, Py_None); + for(i = 1; i <= 12; i++) { + if(code & (1 << i)) { + xmlNode *td_n = dmixml_AddTextChild(data_n, "flag", "%s", detail[i - 1]); + assert( td_n != NULL ); + dmixml_AddAttribute(td_n, "index", "%i", i); + } + } } - return data; } -static PyObject *dmi_memory_device_speed(u16 code) +void dmi_memory_device_speed(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Speed", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%i MHz (%.1f ns)", code, (float)1000 / code); - return data; + if(code == 0) { + dmixml_AddAttribute(data_n, "unkown", "1"); + } else { + dmixml_AddAttribute(data_n, "speed_ns", "%.1f ns", (float) 1000 / code); + dmixml_AddAttribute(data_n, "unit", "MHz"); + dmixml_AddTextContent(data_n, "%i", code); + } } /******************************************************************************* * 3.3.19 32-bit Memory Error Information (Type 18) */ -static PyObject *dmi_memory_error_type(u8 code) +void dmi_memory_error_type(xmlNode *node, u8 code) { /* 3.3.19.1 */ static const char *type[] = { @@ -2654,15 +2683,19 @@ static PyObject *dmi_memory_error_type(u8 code) "Corrected Error", "Uncorrectable Error" /* 0x0E */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.19.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x0E) - data = PyString_FromString(type[code - 0x01]); - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x0E) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_error_granularity(u8 code) +void dmi_memory_error_granularity(xmlNode *node, u8 code) { /* 3.3.19.2 */ static const char *granularity[] = { @@ -2671,16 +2704,19 @@ static PyObject *dmi_memory_error_granularity(u8 code) "Device Level", "Memory Partition Level" /* 0x04 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Granularity", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.19.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x04) - data = PyString_FromString(granularity[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x04) { + dmixml_AddTextContent(data_n, "%s", granularity[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_error_operation(u8 code) +void dmi_memory_error_operation(xmlNode *node, u8 code) { /* 3.3.19.3 */ static const char *operation[] = { @@ -2690,108 +2726,114 @@ static PyObject *dmi_memory_error_operation(u8 code) "Write", "Partial Write" /* 0x05 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Operation", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.19.3"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x05) - data = PyString_FromString(operation[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x05) { + dmixml_AddTextContent(data_n, "%s", operation[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_error_syndrome(u32 code) +void dmi_memory_error_syndrome(xmlNode *node, u32 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "VendorSyndrome", NULL); + assert( data_n != NULL ); - if(code == 0x00000000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("0x%08x", code); - return data; + if(code == 0x00000000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddTextContent(data_n, "0x%08x", code); + } } -static PyObject *dmi_32bit_memory_error_address(u32 code) +void dmi_32bit_memory_error_address(xmlNode *node, char *tagname, u32 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); - if(code == 0x80000000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("0x%08x", code); - return data; + if(code == 0x80000000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddTextContent(data_n, "0x%08x", code); + } } /******************************************************************************* ** 3.3.20 Memory Array Mapped Address (Type 19) */ -static PyObject *dmi_mapped_address_size(u32 code) +void dmi_mapped_address_size(xmlNode *node, u32 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "RangeSize", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.19.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0) - data = PyString_FromString("Invalid"); - else if((code & 0x000FFFFF) == 0) - data = PyString_FromFormat("%i GB", code >> 20); - else if((code & 0x000003FF) == 0) - data = PyString_FromFormat("%i MB", code >> 10); - else - data = PyString_FromFormat("%i kB", code); - return data; + if(code == 0) { + dmixml_AddAttribute(data_n, "invalid", "1"); + } else if((code & 0x000FFFFF) == 0) { + dmixml_AddAttribute(data_n, "unit", "GB"); + dmixml_AddTextContent(data_n, "%i", code >> 20); + } else if((code & 0x000003FF) == 0) { + dmixml_AddAttribute(data_n, "unit", "MB"); + dmixml_AddTextContent(data_n, "%i", code >> 10); + } else { + dmixml_AddAttribute(data_n, "unit", "KB"); + dmixml_AddTextContent(data_n, "%i", code); + } } /******************************************************************************* ** 3.3.21 Memory Device Mapped Address (Type 20) */ -static PyObject *dmi_mapped_address_row_position(u8 code) +void dmi_mapped_address_row_position(xmlNode *node, u8 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "PartitionRowPosition", NULL); + assert( data_n != NULL ); - if(code == 0) - data = OUT_OF_SPEC; - else if(code == 0xFF) - data = PyString_FromString("Unknown"); - else - data = PyInt_FromLong(code); - return data; + if(code == 0) { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } else if(code == 0xFF) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddTextContent(data_n, "%ld", code); + } } -static PyObject *dmi_mapped_address_interleave_position(u8 code) +void dmi_mapped_address_interleave_position(xmlNode *node, u8 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "InterleavePosition", NULL); + assert( data_n != NULL ); - if(code != 0) { - data = PyDict_New(); - PyDict_SetItemString(data, "Interleave Position", - (code == - 0xFF) ? PyString_FromString("Unknown") : - PyInt_FromLong(code)); - } else - data = Py_None; - return data; + if( code <= 0xFE ) { + dmixml_AddTextContent(data_n, "%i", code); + } else { + dmixml_AddAttribute(data_n, "unknown", "1"); + } } -static PyObject *dmi_mapped_address_interleaved_data_depth(u8 code) +void dmi_mapped_address_interleaved_data_depth(xmlNode *node, u8 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "InterleaveDataDepth", NULL); + assert( data_n != NULL ); - if(code != 0) { - data = PyDict_New(); - PyDict_SetItemString(data, "Interleave Data Depth", - (code == - 0xFF) ? PyString_FromString("Unknown") : - PyInt_FromLong(code)); - } else - data = Py_None; - return data; + if( code < 0xFF ) { + dmixml_AddTextContent(data_n, "%i", code); + } else { + dmixml_AddAttribute(data_n, "unknown", "1"); + } } /******************************************************************************* ** 3.3.22 Built-in Pointing Device (Type 21) */ -static PyObject *dmi_pointing_device_type(u8 code) +void dmi_pointing_device_type(xmlNode *node, u8 code) { /* 3.3.22.1 */ static const char *type[] = { @@ -2805,16 +2847,19 @@ static PyObject *dmi_pointing_device_type(u8 code) "Touch Screen", "Optical Sensor" /* 0x09 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "DeviceType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.22.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x09) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x09) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_pointing_device_interface(u8 code) +void dmi_pointing_device_interface(xmlNode *node, u8 code) { /* 3.3.22.2 */ static const char *interface[] = { @@ -2832,22 +2877,25 @@ static PyObject *dmi_pointing_device_interface(u8 code) "Bus Mouse Micro DIN", "USB" /* 0xA2 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "DeviceInterface", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.22.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x08) - data = PyString_FromString(interface[code - 0x01]); - else if(code >= 0xA0 && code <= 0xA2) - data = PyString_FromString(interface_0xA0[code - 0xA0]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x08) { + dmixml_AddTextContent(data_n, interface[code - 0x01]); + } else if(code >= 0xA0 && code <= 0xA2) { + dmixml_AddTextContent(data_n, interface_0xA0[code - 0xA0]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /******************************************************************************* ** 3.3.23 Portable Battery (Type 22) */ -static PyObject *dmi_battery_chemistry(u8 code) +void dmi_battery_chemistry(xmlNode *node, u8 code) { /* 3.3.23.1 */ static const char *chemistry[] = { @@ -2860,94 +2908,110 @@ static PyObject *dmi_battery_chemistry(u8 code) "Zinc Air", "Lithium Polymer" /* 0x08 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "BatteryChemistry", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.22.2"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x08) - data = PyString_FromString(chemistry[code - 0x01]); - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x08) { + dmixml_AddTextContent(data_n, "%s", chemistry[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_battery_capacity(u16 code, u8 multiplier) +void dmi_battery_capacity(xmlNode *node, u16 code, u8 multiplier) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "DesignCapacity", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "value", "0x%04x", code); + dmixml_AddAttribute(data_n, "multiplier", "0x%04x", multiplier); - if(code == 0) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%i mWh", code * multiplier); - return data; + if(code != 0) { + dmixml_AddAttribute(data_n, "unit", "mWh"); + dmixml_AddTextContent(data_n, "%i", code * multiplier); + } } -static PyObject *dmi_battery_voltage(u16 code) +void dmi_battery_voltage(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "DesignVoltage", NULL); + assert( data_n != NULL ); - if(code == 0) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%i mV", code); - return data; + if(code == 0) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "mV"); + dmixml_AddTextContent(data_n, "%i", code); + } } -static PyObject *dmi_battery_maximum_error(u8 code) +void dmi_battery_maximum_error(xmlNode *node, u8 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "MaximumError", NULL); + assert( data_n != NULL ); - if(code == 0xFF) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%i%%", code); - return data; + if(code == 0xFF) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddTextContent(data_n, "%i%%", code); + } } /******************************************************************************* ** 3.3.24 System Reset (Type 23) */ -static PyObject *dmi_system_reset_boot_option(u8 code) +void dmi_system_reset_boot_option(xmlNode *node, const char *tagname, u8 code) { static const char *option[] = { "Operating System", /* 0x1 */ "System Utilities", "Do Not Reboot" /* 0x3 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x1) - data = PyString_FromString(option[code - 0x1]); - else - data = OUT_OF_SPEC; - return data; + if( (code > 0) && (code < 4) ) { + dmixml_AddTextContent(data_n, option[code - 0x1]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_system_reset_count(u16 code) +void dmi_system_reset_count(xmlNode *node, const char *tagname, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0xFFFF) - data = PyString_FromString("Unknown"); - else - data = PyInt_FromLong(code); - return data; + if(code == 0xFFFF) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddTextContent(data_n, "%ld", code); + } } -static PyObject *dmi_system_reset_timer(u16 code) +void dmi_system_reset_timer(xmlNode *node, const char *tagname, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0xFFFF) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%i min", code); - return data; + if(code == 0xFFFF) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "min"); + dmixml_AddTextContent(data_n, "%i", code); + } } /******************************************************************************* * 3.3.25 Hardware Security (Type 24) */ -static PyObject *dmi_hardware_security_status(u8 code) +void dmi_hardware_security_status(xmlNode *node, const char *tagname, u8 code) { static const char *status[] = { "Disabled", /* 0x00 */ @@ -2955,48 +3019,45 @@ static PyObject *dmi_hardware_security_status(u8 code) "Not Implemented", "Unknown" /* 0x03 */ }; - - return PyString_FromString(status[code]); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + dmixml_AddTextContent(data_n, "%s", status[code]); } /******************************************************************************* ** 3.3.26 System Power Controls (Type 25) */ -static PyObject *dmi_power_controls_power_on(const u8 * p) +#define DMI_POWER_CTRL_TIME_STR(dest, variant, data) \ + if( variant ) { snprintf(dest, 3, "%02x", data); } \ + else { snprintf(dest, 3, "*"); } \ + +void dmi_power_controls_power_on(xmlNode *node, const char *tagname, const u8 * p) { /* 3.3.26.1 */ - PyObject *data = PyList_New(5); - - PyList_SET_ITEM(data, 0, - dmi_bcd_range(p[0], 0x01, 0x12) ? PyString_FromFormat(" %02x", - p[0]) : - PyString_FromString(" *")); - PyList_SET_ITEM(data, 1, - dmi_bcd_range(p[1], 0x01, 0x31) ? PyString_FromFormat("-%02x", - p[1]) : - PyString_FromString("-*")); - PyList_SET_ITEM(data, 2, - dmi_bcd_range(p[2], 0x00, 0x23) ? PyString_FromFormat(" %02x", - p[2]) : - PyString_FromString(" *")); - PyList_SET_ITEM(data, 3, - dmi_bcd_range(p[3], 0x00, 0x59) ? PyString_FromFormat(":%02x", - p[3]) : - PyString_FromString(":*")); - PyList_SET_ITEM(data, 4, - dmi_bcd_range(p[4], 0x00, 0x59) ? PyString_FromFormat(":%02x", - p[4]) : - PyString_FromString(":*")); - - return data; + char timestr[5][5]; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.26.1"); + dmixml_AddAttribute(data_n, "flags", "0x%08x", p); + + DMI_POWER_CTRL_TIME_STR(timestr[0], dmi_bcd_range(p[0], 0x01, 0x12), p[0]) + DMI_POWER_CTRL_TIME_STR(timestr[1], dmi_bcd_range(p[1], 0x01, 0x31), p[1]) + DMI_POWER_CTRL_TIME_STR(timestr[2], dmi_bcd_range(p[2], 0x01, 0x23), p[2]) + DMI_POWER_CTRL_TIME_STR(timestr[3], dmi_bcd_range(p[3], 0x01, 0x59), p[3]) + DMI_POWER_CTRL_TIME_STR(timestr[4], dmi_bcd_range(p[4], 0x01, 0x59), p[4]) + + dmixml_AddTextContent(data_n, "%s-%s %s:%s:%s", + timestr[0], timestr[1], + timestr[2], timestr[3], timestr[4]); } /******************************************************************************* * 3.3.27 Voltage Probe (Type 26) */ -static PyObject *dmi_voltage_probe_location(u8 code) +void dmi_voltage_probe_location(xmlNode *node, u8 code) { /* 3.3.27.1 */ static const char *location[] = { @@ -3012,16 +3073,19 @@ static PyObject *dmi_voltage_probe_location(u8 code) "Power Unit", "Add-in Card" /* 0x0B */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Location", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.27.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x0B) - data = PyString_FromString(location[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x0B) { + dmixml_AddTextContent(data_n, "%s", location[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_probe_status(u8 code) +void dmi_probe_status(xmlNode *node, u8 code) { /* 3.3.27.1 */ static const char *status[] = { @@ -3032,53 +3096,65 @@ static PyObject *dmi_probe_status(u8 code) "Critical", "Non-recoverable" /* 0x06 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Status", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.27.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x06) - data = PyString_FromString(status[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x06) { + dmixml_AddTextContent(data_n, "%s", status[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_voltage_probe_value(u16 code) +void dmi_voltage_probe_value(xmlNode *node, const char *tagname, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.3f V", (float)(i16) code / 1000); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "V"); + dmixml_AddTextContent(data_n, "%.3f", (float)(i16) code / 1000); + } } -static PyObject *dmi_voltage_probe_resolution(u16 code) +void dmi_voltage_probe_resolution(xmlNode *node, u16 code) { - PyObject *data; - - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.1f mV", (float)code / 10); - return data; -} + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Resolution", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); -static PyObject *dmi_probe_accuracy(u16 code) + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "mV"); + dmixml_AddTextContent(data_n, "%.1f", (float) code / 10); + } +} + +void dmi_probe_accuracy(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Accuracy", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.2f%%", (float)code / 100); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "%%"); + dmixml_AddTextContent(data_n, "%.2f", (float)code / 100); + } } /******************************************************************************* ** 3.3.28 Cooling Device (Type 27) */ -static PyObject *dmi_cooling_device_type(u8 code) +void dmi_cooling_device_type(xmlNode *node, u8 code) { /* 3.3.28.1 */ static const char *type[] = { @@ -3096,33 +3172,39 @@ static PyObject *dmi_cooling_device_type(u8 code) "Active Cooling", /* 0x10, master.mif says 32 */ "Passive Cooling" /* 0x11, master.mif says 33 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.28.1", code); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x09) - data = PyString_FromString(type[code - 0x01]); - else if(code >= 0x10 && code <= 0x11) - data = PyString_FromString(type_0x10[code - 0x10]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x09) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else if(code >= 0x10 && code <= 0x11) { + dmixml_AddTextContent(data_n, "%s", type_0x10[code - 0x10]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_cooling_device_speed(u16 code) +void dmi_cooling_device_speed(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "NominalSpeed", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown Or Non-rotating"); - else - data = PyString_FromFormat("%i rpm", code); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } + + dmixml_AddAttribute(data_n, "unit", "rpm"); + dmixml_AddTextContent(data_n, "%i", code); } /******************************************************************************* ** 3.3.29 Temperature Probe (Type 28) */ -static PyObject *dmi_temperature_probe_location(u8 code) +void dmi_temperature_probe_location(xmlNode *node, u8 code) { /* 3.3.29.1 */ static const char *location[] = { @@ -3142,68 +3224,83 @@ static PyObject *dmi_temperature_probe_location(u8 code) "Power System Board", "Drive Back Plane" /* 0x0F */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Location", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.29.1", code); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x0F) - data = PyString_FromString(location[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x0F) { + dmixml_AddTextChild(node, "%s", location[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_temperature_probe_value(u16 code) +void dmi_temperature_probe_value(xmlNode *node, const char *tagname, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.1f deg C", (float)(i16) code / 10); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "C"); + dmixml_AddTextContent(data_n, "%.1f", (float)(i16) code / 10); + } } -static PyObject *dmi_temperature_probe_resolution(u16 code) +void dmi_temperature_probe_resolution(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Resolution", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.3f deg C", (float)code / 1000); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "C"); + dmixml_AddTextContent(data_n, "%.3f deg C", (float)code / 1000); + } } /******************************************************************************* ** 3.3.30 Electrical Current Probe (Type 29) */ -static PyObject *dmi_current_probe_value(u16 code) +void dmi_current_probe_value(xmlNode *node, const char *tagname, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.3f A", (float)(i16) code / 1000); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "A"); + dmixml_AddTextContent(data_n, "%.3f", (float)(i16) code / 1000); + } } -static PyObject *dmi_current_probe_resolution(u16 code) +void dmi_current_probe_resolution(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Resolution", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.1f mA", (float)code / 10); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "mA"); + dmixml_AddTextContent(data_n, "%.1f A", (float)code / 10); + } } /******************************************************************************* ** 3.3.33 System Boot Information (Type 32) */ -static PyObject *dmi_system_boot_status(u8 code) +void dmi_system_boot_status(xmlNode *node, u8 code) { static const char *status[] = { "No errors detected", /* 0 */ @@ -3216,39 +3313,42 @@ static PyObject *dmi_system_boot_status(u8 code) "Previously-requested image", "System watchdog timer expired" /* 8 */ }; - PyObject *data; - - if(code <= 8) - data = PyString_FromString(status[code]); - else if(code >= 128 && code <= 191) - data = PyString_FromString("OEM-specific"); - else if(code >= 192) - data = PyString_FromString("Product-specific"); - else - data = OUT_OF_SPEC; - return data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Status", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + + if(code <= 8) { + dmixml_AddTextContent(data_n, "%s", status[code]); + } else if(code >= 128 && code <= 191) { + dmixml_AddTextContent(data_n, "OEM-specific"); + } else if(code >= 192) { + dmixml_AddTextContent(data_n, "Product-specific"); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /******************************************************************************* ** 3.3.34 64-bit Memory Error Information (Type 33) */ -static PyObject *dmi_64bit_memory_error_address(u64 code) +void dmi_64bit_memory_error_address(xmlNode *node, const char *tagname, u64 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); + assert( data_n != NULL ); - if(code.h == 0x80000000 && code.l == 0x00000000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("0x%08x%08x", code.h, code.l); - return data; + if(code.h == 0x80000000 && code.l == 0x00000000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddTextContent(data_n, "0x%08x%08x", code.h, code.l); + } } /******************************************************************************* ** 3.3.35 Management Device (Type 34) */ -static PyObject *dmi_management_device_type(u8 code) +void dmi_management_device_type(xmlNode *node, u8 code) { /* 3.3.35.1 */ static const char *type[] = { @@ -3266,16 +3366,19 @@ static PyObject *dmi_management_device_type(u8 code) "W83781D", "HT82H791" /* 0x0D */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.35.1", code); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x0D) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x0D) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_management_device_address_type(u8 code) +void dmi_management_device_address_type(xmlNode *node, u8 code) { /* 3.3.35.2 */ static const char *type[] = { @@ -3285,20 +3388,23 @@ static PyObject *dmi_management_device_address_type(u8 code) "Memory", "SMBus" /* 0x05 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "AddressType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.35.2", code); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x05) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x05) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /******************************************************************************* ** 3.3.38 Memory Channel (Type 37) */ -static PyObject *dmi_memory_channel_type(u8 code) +void dmi_memory_channel_type(xmlNode *node, u8 code) { /* 3.3.38.1 */ static const char *type[] = { @@ -3307,43 +3413,36 @@ static PyObject *dmi_memory_channel_type(u8 code) "RamBus", "SyncLink" /* 0x04 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.38.1", code); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x04) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x04) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_memory_channel_devices(u8 count, const u8 * p) +void dmi_memory_channel_devices(xmlNode *node, u8 count, const u8 * p) { - PyObject *data = PyDict_New(); - PyObject *subdata, *val; int i; for(i = 1; i <= count; i++) { - subdata = PyList_New(2); - - val = PyString_FromFormat("Load: %i", p[3 * i]); - PyList_SET_ITEM(subdata, 0, val); - Py_DECREF(val); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Device", NULL); + assert( data_n != NULL ); - val = PyString_FromFormat("Handle: 0x%04x", WORD(p + 3 * i + 1)); - PyList_SET_ITEM(subdata, 1, val); - Py_DECREF(val); - - PyDict_SetItem(data, PyInt_FromLong(i), subdata); - Py_DECREF(subdata); + dmixml_AddAttribute(data_n, "Load", "%i", p[3 * i]); + dmixml_AddAttribute(data_n, "Handle", "0x%04x", WORD(p + 3 * i + 1)); } - return data; } /******************************************************************************* ** 3.3.39 IPMI Device Information (Type 38) */ -static PyObject *dmi_ipmi_interface_type(u8 code) +void dmi_ipmi_interface_type(xmlNode *node, u8 code) { /* 3.3.39.1 and IPMI 2.0, appendix C1, table C1-2 */ static const char *type[] = { @@ -3353,32 +3452,36 @@ static PyObject *dmi_ipmi_interface_type(u8 code) "BT (Block Transfer)", "SSIF (SMBus System Interface)" /* 0x04 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "InterfaceType", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.39.1", code); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code <= 0x04) - data = PyString_FromString(type[code]); - else - data = OUT_OF_SPEC; - return data; + if(code <= 0x04) { + dmixml_AddTextContent(data_n, "%s", type[code]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_ipmi_base_address(u8 type, const u8 * p, u8 lsb) +void dmi_ipmi_base_address(xmlNode *node, u8 type, const u8 * p, u8 lsb) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "BaseAddress", NULL); + assert( data_n != NULL ); if(type == 0x04) { /* SSIF */ - data = PyString_FromFormat("0x%02x (SMBus)", (*p) >> 1); + dmixml_AddAttribute(data_n, "interface", "SMBus-SSIF"); + dmixml_AddTextContent(data_n, "0x%02x", (*p) >> 1); } else { u64 address = QWORD(p); - - data = - PyString_FromFormat("0x%08x%08x (%s)", address.h, (address.l & ~1) | lsb, - address.l & 1 ? "I/O" : "Memory-mapped"); + dmixml_AddAttribute(data_n, "interface", "%s", + address.l & 1 ? "I/O" : "Memory-mapped"); + dmixml_AddTextContent(data_n, "0x%08x%08x", + address.h, (address.l & ~1) | lsb); } - return data; } -static PyObject *dmi_ipmi_register_spacing(u8 code) +void dmi_ipmi_register_spacing(xmlNode *node, u8 code) { /* IPMI 2.0, appendix C1, table C1-1 */ static const char *spacing[] = { @@ -3386,29 +3489,36 @@ static PyObject *dmi_ipmi_register_spacing(u8 code) "32-bit Boundaries", "16-byte Boundaries" /* 0x02 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "RegisterSpacing", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code <= 0x02) - return data = PyString_FromString(spacing[code]); - return data = OUT_OF_SPEC; + if(code <= 0x02) { + dmixml_AddTextContent(data_n, "%s", spacing[code]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /******************************************************************************* ** 3.3.40 System Power Supply (Type 39) */ -static PyObject *dmi_power_supply_power(u16 code) +void dmi_power_supply_power(xmlNode *node, u16 code) { - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "MaxPowerCapacity", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code == 0x8000) - data = PyString_FromString("Unknown"); - else - data = PyString_FromFormat("%.3f W", (float)code / 1000); - return data; + if(code == 0x8000) { + dmixml_AddAttribute(data_n, "unknown", "1"); + } else { + dmixml_AddAttribute(data_n, "unit", "W"); + dmixml_AddTextContent(data_n, "%.3f", (float)code / 1000); + } } -static PyObject *dmi_power_supply_type(u8 code) +void dmi_power_supply_type(xmlNode *node, u8 code) { /* 3.3.40.1 */ static const char *type[] = { @@ -3421,16 +3531,19 @@ static PyObject *dmi_power_supply_type(u8 code) "Converter", "Regulator" /* 0x08 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.40.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x08) - data = PyString_FromString(type[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x08) { + dmixml_AddTextContent(data_n, "%s", type[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_power_supply_status(u8 code) +void dmi_power_supply_status(xmlNode *node, u8 code) { /* 3.3.40.1 */ static const char *status[] = { @@ -3440,16 +3553,20 @@ static PyObject *dmi_power_supply_status(u8 code) "Non-critical", "Critical" /* 0x05 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Status", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.40.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); + dmixml_AddAttribute(data_n, "present", "1"); - if(code >= 0x01 && code <= 0x05) - data = PyString_FromString(status[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x05) { + dmixml_AddTextContent(data_n, "%s", status[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } -static PyObject *dmi_power_supply_range_switching(u8 code) +void dmi_power_supply_range_switching(xmlNode *node, u8 code) { /* 3.3.40.1 */ static const char *switching[] = { @@ -3460,13 +3577,16 @@ static PyObject *dmi_power_supply_range_switching(u8 code) "Wide Range", "N/A" /* 0x06 */ }; - PyObject *data; + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "VoltageRangeSwitching", NULL); + assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "dmispec", "3.3.40.1"); + dmixml_AddAttribute(data_n, "flags", "0x%04x", code); - if(code >= 0x01 && code <= 0x06) - data = PyString_FromString(switching[code - 0x01]); - else - data = OUT_OF_SPEC; - return data; + if(code >= 0x01 && code <= 0x06) { + dmixml_AddTextContent(data_n, "%s", switching[code - 0x01]); + } else { + dmixml_AddAttribute(data_n, "outofspec", "1"); + } } /* @@ -3477,60 +3597,55 @@ static PyObject *dmi_power_supply_range_switching(u8 code) ** whether it's worth the effort. */ -static PyObject *dmi_additional_info(const struct dmi_header *h, const char *prefix) +void dmi_additional_info(xmlNode *node, const struct dmi_header *h) { u8 *p = h->data + 4; u8 count = *p++; u8 length; int i, offset = 5; - PyObject *data = PyList_New(count); + + assert( node != NULL ); for(i = 0; i < count; i++) { - PyObject *subdata = PyDict_New(); + xmlNode *data_n = NULL, *str_n = NULL, *val_n = NULL; /* Check for short entries */ - if(h->length < offset + 1) + if(h->length < offset + 1) { break; + } + length = p[0x00]; if(length < 0x05 || h->length < offset + length) break; - PyDict_SetItemString(subdata, - "Referenced Handle", - PyString_FromFormat("0x%04x", WORD(p + 0x01)) - ); + data_n = xmlNewChild(node, NULL, (xmlChar *) "Record", NULL); + assert( data_n != NULL ); - PyDict_SetItemString(subdata, - "Referenced Offset", PyString_FromFormat("0x%02x", p[0x03]) - ); + dmixml_AddAttribute(data_n, "index", "%i", i); + dmixml_AddAttribute(data_n, "ReferenceHandle", "0x%04x", WORD(p + 0x01)); + dmixml_AddAttribute(data_n, "ReferenceOffset", "0x%02x", p[0x03]); - PyDict_SetItemString(subdata, "String", dmi_string_py(h, p[0x04]) - ); - - PyObject *_val; + str_n = dmixml_AddTextChild(data_n, "String", "%s", dmi_string(h, p[0x04])); switch (length - 0x05) { case 1: - _val = PyString_FromFormat("0x%02x", p[0x05]); + dmixml_AddTextChild(data_n, "Value", "0x%02x", p[0x05]); break; case 2: - _val = PyString_FromFormat("0x%04x", WORD(p + 0x05)); + dmixml_AddTextChild(data_n, "Value", "0x%04x", WORD(p + 0x05)); break; case 4: - _val = PyString_FromFormat("0x%08x", DWORD(p + 0x05)); + dmixml_AddTextChild(data_n, "Value", "0x%08x", DWORD(p + 0x05)); break; default: - _val = PyString_FromString("Unexpected size"); + val_n = xmlNewChild(data_n, NULL, (xmlChar *) "Value", NULL); + dmixml_AddAttribute(val_n, "unexpected_size", "1"); break; } - PyDict_SetItemString(subdata, "Value", _val); - Py_DECREF(_val); p += length; offset += length; - PyList_SET_ITEM(data, i, subdata); } - return data; } /******************************************************************************* @@ -3553,12 +3668,14 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) switch (h->type) { case 0: /* 3.3.1 BIOS Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOS", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOSinformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.1"); - if(h->length < 0x12) + if(h->length < 0x12) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "Vendor", "%s", data[0x04]); dmixml_AddTextChild(sect_n, "Version", "%s", data[0x05]); @@ -3572,11 +3689,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) if(WORD(data + 0x06) != 0) { dmixml_AddTextChild(sect_n, "Address", "0x%04x0", WORD(data + 0x06)); - dmixml_AddTextChild(sect_n, "RuntimeSize", "%s", - dmi_bios_runtime_size((0x10000 - WORD(data + 0x06)) << 4)); + dmi_bios_runtime_size(sect_n, (0x10000 - WORD(data + 0x06)) << 4); } - dmixml_AddTextChild(sect_n, "ROMsize", "%i kB", (data[0x09] + 1) << 6); + dmixml_AddTextChild(sect_n, "ROMsize", "%i KB", (data[0x09] + 1) << 6); sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Characteristics", NULL); assert( sub_n != NULL ); @@ -3585,17 +3701,22 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_bios_characteristics(sub_n, QWORD(data + 0x0A)); sub_n = NULL; - if(h->length < 0x13) + if(h->length < 0x13) { + sect_n = NULL; break; + } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Characteristics", NULL); assert( sub_n != NULL ); dmixml_AddAttribute(sub_n, "level", "x1"); dmi_bios_characteristics_x1(sub_n, data[0x12]); + sub_n = NULL; - if(h->length < 0x14) + if(h->length < 0x14) { + sect_n = NULL; break; + } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Characteristics", NULL); assert( sub_n != NULL ); @@ -3604,8 +3725,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_bios_characteristics_x2(sub_n, data[0x13]); sub_n = NULL; - if(h->length < 0x18) + if(h->length < 0x18) { + sect_n = NULL; break; + } if(data[0x14] != 0xFF && data[0x15] != 0xFF) { dmixml_AddTextChild(sect_n, "BIOSrevision", "%i.%i", data[0x14], data[0x15]); @@ -3622,44 +3745,55 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.2"); - if(h->length < 0x08) + if(h->length < 0x08) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x04])); dmixml_AddTextChild(sect_n, "ProductName", "%s", dmi_string(h, data[0x05])); dmixml_AddTextChild(sect_n, "Version", "%s", dmi_string(h, data[0x06])); dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); - if(h->length < 0x19) + if(h->length < 0x19) { + sect_n = NULL; break; + } dmi_system_uuid(sect_n, data + 0x08, ver); dmi_system_wake_up_type(sect_n, data[0x18]); - if(h->length < 0x1B) + if(h->length < 0x1B) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "SKUnumber", "%s", dmi_string(h, data[0x19])); dmixml_AddTextChild(sect_n, "Family", "%s", dmi_string(h, data[0x1A])); + sect_n = NULL; break; case 2: /* 3.3.3 Base Board Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Baseboard", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BaseboardInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.3"); - if(h->length < 0x08) + if(h->length < 0x08) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x04])); dmixml_AddTextChild(sect_n, "ProductName", "%s", dmi_string(h, data[0x05])); dmixml_AddTextChild(sect_n, "Version", "%s", dmi_string(h, data[0x06])); dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); - if(h->length < 0x0F) + if(h->length < 0x0F) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x08])); @@ -3670,19 +3804,23 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_base_board_type(sect_n, "Type", data[0x0D]); - if(h->length < 0x0F + data[0x0E] * sizeof(u16)) + if(h->length < 0x0F + data[0x0E] * sizeof(u16)) { + sect_n = NULL; break; + } dmi_base_board_handles(sect_n, data[0x0E], data + 0x0F); sect_n = NULL; break; case 3: /* 3.3.4 Chassis Information */ - sect_n= xmlNewChild(handle_n, NULL, (xmlChar *) "Chassis", NULL); + sect_n= xmlNewChild(handle_n, NULL, (xmlChar *) "ChassisInformation", NULL); assert( sect_n != NULL ); - if(h->length < 0x09) + if(h->length < 0x09) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x04])); dmi_chassis_type(sect_n, data[0x05] & 0x7F); @@ -3691,8 +3829,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x08])); - if(h->length < 0x0D) + if(h->length < 0x0D) { + sect_n = NULL; break; + } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "ChassisStates", NULL); assert( sub_n != NULL ); @@ -3700,39 +3840,44 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_chassis_state(sub_n, "BootUp", data[0x09]); dmi_chassis_state(sub_n, "PowerSupply", data[0x0A]); dmi_chassis_state(sub_n, "Thermal", data[0x0B]); + sub_n = NULL; dmi_chassis_security_status(sect_n, data[0x0C]); - if(h->length < 0x11) + if(h->length < 0x11) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x0D)); - if(h->length < 0x13) + if(h->length < 0x13) { + sect_n = NULL; break; + } dmi_chassis_height(sect_n, data[0x11]); dmi_chassis_power_cords(sect_n, data[0x12]); - if(h->length < 0x15) - break; - - if(h->length < 0x15 + data[0x13] * data[0x14]) + if((h->length < 0x15) || (h->length < 0x15 + data[0x13] * data[0x14])){ + sect_n = NULL; break; + } dmi_chassis_elements(sect_n, data[0x13], data[0x14], data + 0x15); sect_n = NULL; break; case 4: /* 3.3.5 Processor Information */ - - if(h->length < 0x1A) - break; - - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Processor", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ProcessorInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.5"); + if(h->length < 0x1A) { + sect_n = NULL; + break; + } + dmixml_AddTextChild(sect_n, "SocketDesignation", "%s", dmi_string(h, data[0x04])); dmi_processor_type(sect_n, data[0x05]); dmi_processor_family(sect_n, h); @@ -3753,6 +3898,7 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sub_n, "ExternalClock", "%i", dmi_processor_frequency(data + 0x12)); dmixml_AddTextChild(sub_n, "MaxSpeed", "%i", dmi_processor_frequency(data + 0x14)); dmixml_AddTextChild(sub_n, "CurrentSpeed", "%i", dmi_processor_frequency(data + 0x16)); + sub_n = NULL; /* TODO: Should CurrentSpeed be renamed to BootSpeed? Specification * says this about Current Speed: @@ -3772,8 +3918,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_processor_upgrade(sect_n, data[0x19]); - if(h->length < 0x20) + if(h->length < 0x20) { + sect_n = NULL; break; + } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Cache", NULL); assert( sub_n != NULL ); @@ -3801,15 +3949,19 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) sub2_n = NULL; sub_n = NULL; - if(h->length < 0x23) + if(h->length < 0x23) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x20])); dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x21])); dmixml_AddTextChild(sect_n, "PartNumber", "%s", dmi_string(h, data[0x22])); - if(h->length < 0x28) + if(h->length < 0x28) { + sect_n = NULL; break; + } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Cores", NULL); assert( cores_n != NULL ); @@ -3828,18 +3980,21 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_processor_characteristics(sub_n, WORD(data + 0x26)); sub_n = NULL; + sect_n = NULL; break; case 5: /* 3.3.6 Memory Controller Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryController", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryControllerInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.6"); dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0F) + if(h->length < 0x0F) { + sect_n = NULL; break; + } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "ErrorCorrection", NULL); assert( errc_n != NULL ); @@ -3865,13 +4020,17 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_memory_module_types(sect_n, "SupportedTypes", WORD(data + 0x0B)); dmi_processor_voltage(sect_n, data[0x0D]); - if(h->length < 0x0F + data[0x0E] * sizeof(u16)) + if(h->length < 0x0F + data[0x0E] * sizeof(u16)) { + sect_n = NULL; break; + } dmi_memory_controller_slots(sect_n, data[0x0E], data + 0x0F); - if(h->length < 0x10 + data[0x0E] * sizeof(u16)) + if(h->length < 0x10 + data[0x0E] * sizeof(u16)) { + sect_n = NULL; break; + } dmi_memory_controller_ec_capabilities(sect_n, "EnabledErrorCorrection", data[0x0F + data[0x0E] * sizeof(u16)]); @@ -3879,14 +4038,16 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; case 6: /* 3.3.7 Memory Module Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryModule", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryModuleInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.7"); dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0C) + if(h->length < 0x0C) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "SocketDesignation", "%s", dmi_string(h, data[0x04])); dmi_memory_module_connections(sect_n, data[0x05]); @@ -3900,14 +4061,16 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; case 7: /* 3.3.8 Cache Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Cache", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "CacheInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.8"); dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0F) + if(h->length < 0x0F) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "SocketDesignation", dmi_string(h, data[0x04])); dmixml_AddAttribute(sect_n, "Enabled", "%i", (WORD(data + 0x05) & 0x0080 ? 1 : 0)); @@ -3917,6 +4080,7 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) sub_n = dmixml_AddTextChild(sect_n, "OperationalMode", "%s", dmi_cache_mode((WORD(data + 0x05) >> 8) & 0x0003)); dmixml_AddAttribute(sub_n, "flags", "0x%04x", (WORD(data + 0x05) >> 8) & 0x0003); + sub_n = NULL; dmi_cache_location(sect_n, (WORD(data + 0x05) >> 5) & 0x0003); dmi_cache_size(sect_n, "InstalledSize", WORD(data + 0x09)); @@ -3925,8 +4089,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_cache_types(sect_n, "SupportedSRAMtypes", WORD(data + 0x0B)); dmi_cache_types(sect_n, "InstalledSRAMtypes", WORD(data + 0x0D)); - if(h->length < 0x13) + if(h->length < 0x13) { + sect_n = NULL; break; + } dmi_memory_module_speed(sect_n, "Speed", data[0x0F]); dmi_cache_ec_type(sect_n, data[0x10]); @@ -3937,14 +4103,16 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; case 8: /* 3.3.9 Port Connector Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Connector", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "PortConnectorInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.9"); dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x09) + if(h->length < 0x09) { + sect_n = NULL; break; + } sub_n = dmixml_AddTextChild(sect_n, "DesignatorRef", dmi_string(h, data[0x04])); assert( sub_n != NULL ); @@ -3965,14 +4133,16 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; case 9: /* 3.3.10 System Slots */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Connector", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemSlots", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.10"); dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0C) + if(h->length < 0x0C) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "Designation", "%s", dmi_string(h, data[0x04])); @@ -3992,7 +4162,7 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; case 10: /* 3.3.11 On Board Devices Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OnBoardDevices", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OnBoardDevicesInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.11"); @@ -4008,8 +4178,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x05) + if(h->length < 0x05) { + sect_n = NULL; break; + } dmi_oem_strings(sect_n, h); @@ -4017,12 +4189,14 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; case 12: /* 3.3.13 System Configuration Options */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemConfig", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemConfigurationOptions", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.13"); - if(h->length < 0x05) + if(h->length < 0x05) { + sect_n = NULL; break; + } dmi_system_configuration_options(sect_n, h); @@ -4030,12 +4204,14 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; case 13: /* 3.3.14 BIOS Language Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOSlanguage", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOSlanguageInformation", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.14"); - if(h->length < 0x16) + if(h->length < 0x16) { + sect_n = NULL; break; + } dmixml_AddAttribute(sect_n, "installable_languages", "%i", data[0x04]); @@ -4049,26 +4225,31 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.15"); - if(h->length < 0x05) + if(h->length < 0x05) { + sect_n = NULL; break; + } dmixml_AddTextChild(sect_n, "Name", "%s", dmi_string(h, data[0x04])); sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Groups", NULL); assert( sub_n != NULL ); dmi_group_associations_items(sub_n, (h->length - 0x05) / 3, data + 0x05); + sub_n = NULL; sect_n = NULL; break; case 15: /* 3.3.16 System Event Log */ // SysEventLog - sect_n - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SysEventLog", NULL); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemEventLog", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.16"); - if(h->length < 0x14) + if(h->length < 0x14) { + sect_n = NULL; break; + } dmi_event_log_status(sect_n, data[0x0B]); @@ -4093,8 +4274,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sub2_n, "DataOffset", "0x%04x", WORD(data + 0x08)); dmixml_AddTextChild(sub2_n, "ChangeToken", "0x%08x", DWORD(data + 0x0C)); - if(h->length < 0x17) + if(h->length < 0x17) { + sect_n = NULL; break; + } // SysEventLog/Access/Header/Format - sub2_n dmi_event_log_header_type(sub2_n, data[0x14]); @@ -4109,15 +4292,17 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) // SysEventLog/LogTypes/@count dmixml_AddAttribute(sub_n, "count", "%i", data[0x15]); - if(h->length < 0x17 + data[0x15] * data[0x16]) + if(h->length < 0x17 + data[0x15] * data[0x16]) { + sect_n = NULL; break; + } dmixml_AddAttribute(sub_n, "length", "%i", data[0x16]); // SysEventLog/LogTypes/LogType dmi_event_log_descriptors(sub_n, data[0x15], data[0x16], data + 0x17); - sub_n = NULL; + sect_n = NULL; break; @@ -4126,730 +4311,589 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "3.3.17"); - if(h->length < 0x0F) + if(h->length < 0x0F) { + sect_n = NULL; break; + } - /* ** BOOKMARK ** */ - - _val = dmi_memory_array_location(data[0x04]); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_use(data[0x05]); - PyDict_SetItemString(caseData, "Use", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_ec_type(data[0x06]); - PyDict_SetItemString(caseData, "Error Correction Type", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_capacity(DWORD(data + 0x07)); - PyDict_SetItemString(caseData, "Maximum Capacity", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_error_handle(WORD(data + 0x0B)); - PyDict_SetItemString(caseData, "Error Information Handle", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sect_n, "NumDevices", "%ld", WORD(data + 0x0D)); + dmi_memory_array_location(sect_n, data[0x04]); + dmi_memory_array_use(sect_n, data[0x05]); + dmi_memory_array_ec_type(sect_n, data[0x06]); + dmi_memory_array_capacity(sect_n, DWORD(data + 0x07)); + dmi_memory_array_error_handle(sect_n, WORD(data + 0x0B)); - _val = PyInt_FromLong(WORD(data + 0x0D)); - PyDict_SetItemString(caseData, "Number Of Devices", _val); - Py_DECREF(_val); + sect_n = NULL; break; case 17: /* 3.3.18 Memory Device */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryDevice", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.18"); - if(h->length < 0x15) + if(h->length < 0x15) { + sect_n = NULL; break; - _val = PyString_FromFormat("0x%04x", WORD(data + 0x04)); - PyDict_SetItemString(caseData, "Array Handle", _val); - Py_DECREF(_val); - - _val = dmi_memory_array_error_handle(WORD(data + 0x06)); - PyDict_SetItemString(caseData, "Error Information Handle", _val); - Py_DECREF(_val); - - _val = dmi_memory_device_width(WORD(data + 0x08)); - PyDict_SetItemString(caseData, "Total Width", _val); - Py_DECREF(_val); + } - _val = dmi_memory_device_width(WORD(data + 0x0A)); - PyDict_SetItemString(caseData, "Data Width", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sect_n, "ArrayHandle", "0x%04x", WORD(data + 0x04)); + dmi_memory_array_error_handle(sect_n, WORD(data + 0x06)); - _val = dmi_memory_device_size(WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Size", _val); - Py_DECREF(_val); + dmi_memory_device_width(sect_n, "TotalWidth", WORD(data + 0x08)); + dmi_memory_device_width(sect_n, "DataWidth", WORD(data + 0x0A)); + dmi_memory_device_size(sect_n, WORD(data + 0x0C)); + dmi_memory_device_form_factor(sect_n, data[0x0E]); + dmi_memory_device_set(sect_n, data[0x0F]); + dmixml_AddTextChild(sect_n, "Locator", dmi_string(h, data[0x10])); + dmixml_AddTextChild(sect_n, "BankLocator", dmi_string(h, data[0x11])); - _val = dmi_memory_device_form_factor(data[0x0E]); - PyDict_SetItemString(caseData, "Form Factor", _val); - Py_DECREF(_val); + dmi_memory_device_type(sect_n, data[0x12]); + dmi_memory_device_type_detail(sect_n, WORD(data + 0x13)); - _val = dmi_memory_device_set(data[0x0F]); - PyDict_SetItemString(caseData, "Set", _val); - Py_DECREF(_val); + if(h->length < 0x17) { + sect_n = NULL; + break; + } - _val = dmi_string_py(h, data[0x10]); - PyDict_SetItemString(caseData, "Locator", _val); - Py_DECREF(_val); + dmi_memory_device_speed(sect_n, WORD(data + 0x15)); - _val = dmi_string_py(h, data[0x11]); - PyDict_SetItemString(caseData, "Bank Locator", _val); - Py_DECREF(_val); + if(h->length < 0x1B) { + sect_n = NULL; + break; + } - _val = dmi_memory_device_type(data[0x12]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x17])); + dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x18])); + dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x19])); + dmixml_AddTextChild(sect_n, "PartNumber", "%s", dmi_string(h, data[0x1A])); - _val = dmi_memory_device_type_detail(WORD(data + 0x13)); - PyDict_SetItemString(caseData, "Type Detail", _val); - Py_DECREF(_val); + sect_n = NULL; + break; - if(h->length < 0x17) - break; - _val = dmi_memory_device_speed(WORD(data + 0x15)); - PyDict_SetItemString(caseData, "Speed", _val); - Py_DECREF(_val); + case 18: /* 3.3.19 32-bit Memory Error Information */ + case 33: /* 3.3.34 64-bit Memory Error Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryErrorInfo", NULL); + assert( sect_n != NULL ); - if(h->length < 0x1B) - break; - _val = dmi_string_py(h, data[0x17]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); + if( h->type == 18 ) { + dmixml_AddAttribute(sect_n, "dmispec", "3.3.19"); + dmixml_AddAttribute(sect_n, "bits", "32"); + } else { + dmixml_AddAttribute(sect_n, "dmispec", "3.3.34"); + dmixml_AddAttribute(sect_n, "bits", "64"); + } - _val = dmi_string_py(h, data[0x18]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); + if( ((h->type == 18) && (h->length < 0x17)) /* 32-bit */ + || ((h->type == 33) && (h->length < 0x1F)) ) /* 64-bit */ + { + sect_n = NULL; + break; + } - _val = dmi_string_py(h, data[0x19]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); + dmi_memory_error_type(sect_n, data[0x04]); + dmi_memory_error_granularity(sect_n, data[0x05]); + dmi_memory_error_operation(sect_n, data[0x06]); + dmi_memory_error_syndrome(sect_n, DWORD(data + 0x07)); + + if( h->type == 18 ) { + /* 32-bit */ + dmi_32bit_memory_error_address(sect_n, "MemArrayAddr", DWORD(data + 0x0B)); + dmi_32bit_memory_error_address(sect_n, "DeviceAddr", DWORD(data + 0x0F)); + dmi_32bit_memory_error_address(sect_n, "Resolution", DWORD(data + 0x13)); + } else if( h->type == 33 ) { + /* 64-bit */ + dmi_64bit_memory_error_address(sect_n, "MemArrayAddr", QWORD(data + 0x0B)); + dmi_64bit_memory_error_address(sect_n, "DeviceAddr", QWORD(data + 0x13)); + dmi_32bit_memory_error_address(sect_n, "Resolution", DWORD(data + 0x1B)); + } - _val = dmi_string_py(h, data[0x1A]); - PyDict_SetItemString(caseData, "Part Number", _val); - Py_DECREF(_val); + sect_n = NULL; break; - case 18: /* 3.3.19 32-bit Memory Error Information */ + case 19: /* 3.3.20 Memory Array Mapped Address */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryArrayMappedAddress", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.20"); - if(h->length < 0x17) + if(h->length < 0x0F) { + sect_n = NULL; break; - _val = dmi_memory_error_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + } - _val = dmi_memory_error_granularity(data[0x05]); - PyDict_SetItemString(caseData, "Granularity", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "StartAddress", "0x%08x%03x", + (DWORD(data + 0x04) >> 2), + (DWORD(data + 0x04) & 0x3) << 10); + dmixml_AddTextChild(sect_n, "EndAddress", "0x%08x%03x", + (DWORD(data + 0x08) >> 2), + ((DWORD(data + 0x08) & 0x3) << 10) + 0x3FF); + dmi_mapped_address_size(sect_n, DWORD(data + 0x08) - DWORD(data + 0x04) + 1); + dmixml_AddTextChild(sect_n, "PhysicalArrayHandle", "0x%04x", WORD(data + 0x0C)); + dmixml_AddTextChild(sect_n, "PartitionWidth", "%i", data[0x0F]); - _val = dmi_memory_error_operation(data[0x06]); - PyDict_SetItemString(caseData, "Operation", _val); - Py_DECREF(_val); + sect_n = NULL; + break; - _val = dmi_memory_error_syndrome(DWORD(data + 0x07)); - PyDict_SetItemString(caseData, "Vendor Syndrome", _val); - Py_DECREF(_val); + case 20: /* 3.3.21 Memory Device Mapped Address */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryDeviceMappedAddress", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.21"); - _val = dmi_32bit_memory_error_address(DWORD(data + 0x0B)); - PyDict_SetItemString(caseData, "Memory Array Address", _val); - Py_DECREF(_val); + if(h->length < 0x13) { + sect_n = NULL; + break; + } - _val = dmi_32bit_memory_error_address(DWORD(data + 0x0F)); - PyDict_SetItemString(caseData, "Device Address", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "StartAddress", "0x%08x%03x", + (DWORD(data + 0x04) >> 2), + (DWORD(data + 0x04) & 0x3) << 10); - _val = dmi_32bit_memory_error_address(DWORD(data + 0x13)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); - break; + dmixml_AddTextChild(sect_n, "EndAddress", "0x%08x%03x", + (DWORD(data + 0x08) >> 2), + ((DWORD(data + 0x08) & 0x3) << 10) + 0x3FF); - case 19: /* 3.3.20 Memory Array Mapped Address */ + dmi_mapped_address_size(sect_n, DWORD(data + 0x08) - DWORD(data + 0x04) + 1); - if(h->length < 0x0F) - break; - _val = - PyString_FromFormat("0x%08x%03x", DWORD(data + 0x04) >> 2, - (DWORD(data + 0x04) & 0x3) << 10); - PyDict_SetItemString(caseData, "Starting Address", _val); - Py_DECREF(_val); - - _val = - PyString_FromFormat("0x%08x%03x", DWORD(data + 0x08) >> 2, - ((DWORD(data + 0x08) & 0x3) << 10) + 0x3FF); - PyDict_SetItemString(caseData, "Ending Address", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_size(DWORD(data + 0x08) - DWORD(data + 0x04) + 1); - PyDict_SetItemString(caseData, "Range Size", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Physical Array Handle", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%i", data[0x0F]); - PyDict_SetItemString(caseData, "Partition Width", _val); - Py_DECREF(_val); - break; + dmixml_AddTextChild(sect_n, "PhysicalDeviceHandle", "0x%04x", WORD(data + 0x0C)); + dmixml_AddTextChild(sect_n, "MemArrayMappedAddrHandle", "0x%04x", WORD(data + 0x0E)); - case 20: /* 3.3.21 Memory Device Mapped Address */ + dmi_mapped_address_row_position(sect_n, data[0x10]); - if(h->length < 0x13) - break; - _val = - PyString_FromFormat("0x%08x%03x", DWORD(data + 0x04) >> 2, - (DWORD(data + 0x04) & 0x3) << 10); - PyDict_SetItemString(caseData, "Starting Address", _val); - Py_DECREF(_val); - - _val = - PyString_FromFormat("0x%08x%03x", DWORD(data + 0x08) >> 2, - ((DWORD(data + 0x08) & 0x3) << 10) + 0x3FF); - PyDict_SetItemString(caseData, "Ending Address", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_size(DWORD(data + 0x08) - DWORD(data + 0x04) + 1); - PyDict_SetItemString(caseData, "Range Size", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Physical Device Handle", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data + 0x0E)); - PyDict_SetItemString(caseData, "Memory Array Mapped Address Handle", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_row_position(data[0x10]); - PyDict_SetItemString(caseData, "Partition Row Position", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_interleave_position(data[0x11]); - PyDict_SetItemString(caseData, ">>>", _val); - Py_DECREF(_val); - - _val = dmi_mapped_address_interleaved_data_depth(data[0x12]); - PyDict_SetItemString(caseData, ">>>", _val); - Py_DECREF(_val); + dmi_mapped_address_interleave_position(sect_n, data[0x11]); + dmi_mapped_address_interleaved_data_depth(sect_n, data[0x12]); + + sect_n = NULL; break; case 21: /* 3.3.22 Built-in Pointing Device */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BuiltInPointingDevice", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.22"); - if(h->length < 0x07) + if(h->length < 0x07) { + sect_n = NULL; break; - _val = dmi_pointing_device_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + } - _val = dmi_pointing_device_interface(data[0x05]); - PyDict_SetItemString(caseData, "Interface", _val); - Py_DECREF(_val); + dmi_pointing_device_type(sect_n, data[0x04]); + dmi_pointing_device_interface(sect_n, data[0x05]); + dmixml_AddTextContent(sect_n, "Buttons", "%i", data[0x06]); - _val = PyString_FromFormat("%i", data[0x06]); - PyDict_SetItemString(caseData, "Buttons", _val); - Py_DECREF(_val); + sect_n = NULL; break; case 22: /* 3.3.23 Portable Battery */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "PortableBattery", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.23"); - if(h->length < 0x10) + if(h->length < 0x10) { + sect_n = NULL; break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); + } - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Location", "%s", dmi_string(h, data[0x04])); + dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x05])); if(data[0x06] || h->length < 0x1A) { - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Manufacture Date", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "ManufactureDate", "%s", dmi_string(h, data[0x06])); } if(data[0x07] || h->length < 0x1A) { - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Serial Number", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); } - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Name", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Name", "%s", dmi_string(h, data[0x08])); if(data[0x09] != 0x02 || h->length < 0x1A) { - _val = dmi_battery_chemistry(data[0x09]); - PyDict_SetItemString(caseData, "Chemistry", _val); - Py_DECREF(_val); - } - _val = - (h->length < 0x1A) ? dmi_battery_capacity(WORD(data + 0x0A), - 1) : dmi_battery_capacity(WORD(data + - 0x0A), - data[0x15]); - PyDict_SetItemString(caseData, "Design Capacity", _val); - Py_DECREF(_val); - - _val = dmi_battery_voltage(WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Design Voltage", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x0E]); - PyDict_SetItemString(caseData, "SBDS Version", _val); - Py_DECREF(_val); - - _val = dmi_battery_maximum_error(data[0x0F]); - PyDict_SetItemString(caseData, "Maximum Error", _val); - Py_DECREF(_val); - - if(h->length < 0x1A) + dmi_battery_chemistry(sect_n, data[0x09]); + } + + dmi_battery_capacity(sect_n, WORD(data + 0x0A), (h->length < 0x1A ? 1 : data[0x15])); + dmi_battery_voltage(sect_n, WORD(data + 0x0C)); + dmixml_AddTextChild(sect_n, "SBDSversion", "%s", dmi_string(h, data[0x0E])); + + dmi_battery_maximum_error(sect_n, data[0x0F]); + + if(h->length < 0x1A) { + sect_n = NULL; break; + } + if(data[0x07] == 0) { - _val = PyString_FromFormat("%04x", WORD(data + 0x10)); - PyDict_SetItemString(caseData, "SBDS Serial Number", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SBDSserialNumber", "%04x", WORD(data + 0x10)); } if(data[0x06] == 0) { - _val = - PyString_FromFormat("%i-%02u-%02u", 1980 + (WORD(data + 0x12) >> 9), - (WORD(data + 0x12) >> 5) & 0x0F, - WORD(data + 0x12) & 0x1F); - PyDict_SetItemString(caseData, "SBDS Manufacture Date", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SBDSmanufactureDate", "%i-%02u-%02u", + 1980 + (WORD(data + 0x12) >> 9), + (WORD(data + 0x12) >> 5) & 0x0F, + (WORD(data + 0x12) & 0x1F)); } if(data[0x09] == 0x02) { - _val = dmi_string_py(h, data[0x14]); - PyDict_SetItemString(caseData, "SBDS Chemistry", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "SBDSchemistry", "%s", dmi_string(h, data[0x14])); } - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x16)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "OEMinformation", "%s", "0x%08x", DWORD(data + 0x16)); + + sect_n = NULL; break; case 23: /* 3.3.24 System Reset */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemReset", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.24"); - if(h->length < 0x0D) + if(h->length < 0x0D) { + sect_n = NULL; break; - _val = PyString_FromFormat("%s", data[0x04] & (1 << 0) ? "Enabled" : "Disabled"); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("%s", data[0x04] & (1 << 5) ? "Present" : "Not Present"); - PyDict_SetItemString(caseData, "Watchdog Timer", _val); - Py_DECREF(_val); + } - if(!(data[0x04] & (1 << 5))) - break; - _val = dmi_system_reset_boot_option((data[0x04] >> 1) & 0x3); - PyDict_SetItemString(caseData, "Boot Option", _val); - Py_DECREF(_val); + sub_n = dmixml_AddTextChild(sect_n, "Status", "%s", + data[0x04] & (1 << 0) ? "Enabled" : "Disabled"); + dmixml_AddAttribute(sub_n, "enabled", "%i", data[0x04] & (1 << 0) ? 1 : 0); + sub_n = NULL; - _val = dmi_system_reset_boot_option((data[0x04] >> 3) & 0x3); - PyDict_SetItemString(caseData, "Boot Option On Limit", _val); - Py_DECREF(_val); + sub_n = dmixml_AddTextChild(sect_n, "WatchdogTimer", "%s", + data[0x04] & (1 << 5) ? "Present" : "Not Present"); + dmixml_AddAttribute(sub_n, "present", "%i", data[0x04] & (1 << 5) ? 1 : 0); + sub_n = NULL; - _val = dmi_system_reset_count(WORD(data + 0x05)); - PyDict_SetItemString(caseData, "Reset Count", _val); - Py_DECREF(_val); + if(!(data[0x04] & (1 << 5))) { + sect_n = NULL; + break; + } - _val = dmi_system_reset_count(WORD(data + 0x07)); - PyDict_SetItemString(caseData, "Reset Limit", _val); - Py_DECREF(_val); + dmi_system_reset_boot_option(sect_n, "BootOption", (data[0x04] >> 1) & 0x3); + dmi_system_reset_boot_option(sect_n, "BootOptionOnLimit", (data[0x04] >> 3) & 0x3); - _val = dmi_system_reset_timer(WORD(data + 0x09)); - PyDict_SetItemString(caseData, "Timer Interval", _val); - Py_DECREF(_val); + dmi_system_reset_count(sect_n, "ResetCount", WORD(data + 0x05)); + dmi_system_reset_count(sect_n, "ResetLimit", WORD(data + 0x07)); - _val = dmi_system_reset_timer(WORD(data + 0x0B)); - PyDict_SetItemString(caseData, "Timeout", _val); - Py_DECREF(_val); + dmi_system_reset_timer(sect_n, "TimerInterval", WORD(data + 0x09)); + dmi_system_reset_timer(sect_n, "Timeout", WORD(data + 0x0B)); + sect_n = NULL; break; case 24: /* 3.3.25 Hardware Security */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "HardwareSecurity", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.25"); - if(h->length < 0x05) + if(h->length < 0x05) { + sect_n = NULL; break; - _val = dmi_hardware_security_status(data[0x04] >> 6); - PyDict_SetItemString(caseData, "Power-On Password Status", _val); - Py_DECREF(_val); - - _val = dmi_hardware_security_status((data[0x04] >> 4) & 0x3); - PyDict_SetItemString(caseData, "Keyboard Password Status", _val); - Py_DECREF(_val); - - _val = dmi_hardware_security_status((data[0x04] >> 2) & 0x3); - PyDict_SetItemString(caseData, "Administrator Password Status", _val); - Py_DECREF(_val); + } - _val = dmi_hardware_security_status(data[0x04] & 0x3); - PyDict_SetItemString(caseData, "Front Panel Reset Status", _val); - Py_DECREF(_val); + dmi_hardware_security_status(sect_n, "PowerOnPassword", data[0x04] >> 6); + dmi_hardware_security_status(sect_n, "KeyboardPassword", (data[0x04] >> 4) & 0x3); + dmi_hardware_security_status(sect_n, "AdministratorPassword", (data[0x04] >> 2) & 0x3); + dmi_hardware_security_status(sect_n, "FronPanelReset", data[0x04] & 0x3); + sect_n = NULL; break; case 25: /* 3.3.26 System Power Controls */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemPowerControls", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.26"); - if(h->length < 0x09) + if(h->length < 0x09) { + sect_n = NULL; break; - _val = dmi_power_controls_power_on(data + 0x04); - PyDict_SetItemString(caseData, "Next Scheduled Power-on", _val); - Py_DECREF(_val); + } + dmi_power_controls_power_on(sect_n, "NextSchedPowerOn", data + 0x04); + + sect_n = NULL; break; case 26: /* 3.3.27 Voltage Probe */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "VoltageProbe", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.27"); - if(h->length < 0x14) + if(h->length < 0x14) { + sect_n = NULL; break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); - - _val = dmi_voltage_probe_location(data[0x05] & 0x1f); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_probe_status(data[0x05] >> 5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - - _val = dmi_voltage_probe_value(WORD(data + 0x06)); - PyDict_SetItemString(caseData, "Maximum Value", _val); - Py_DECREF(_val); + } - _val = dmi_voltage_probe_value(WORD(data + 0x08)); - PyDict_SetItemString(caseData, "Minimum Value", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Description", "%s", dmi_string(h, data[0x04])); - _val = dmi_voltage_probe_resolution(WORD(data + 0x0A)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + dmi_voltage_probe_location(sect_n, data[0x05] & 0x1f); + dmi_probe_status(sect_n, data[0x05] >> 5); - _val = dmi_voltage_probe_value(WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Tolerance", _val); - Py_DECREF(_val); + dmi_voltage_probe_value(sect_n, "MaxValue", WORD(data + 0x06)); + dmi_voltage_probe_value(sect_n, "MinValue", WORD(data + 0x08)); + dmi_voltage_probe_resolution(sect_n, WORD(data + 0x0A)); + dmi_voltage_probe_value(sect_n, "Tolerance", WORD(data + 0x0C)); - _val = dmi_probe_accuracy(WORD(data + 0x0E)); - PyDict_SetItemString(caseData, "Accuracy", _val); - Py_DECREF(_val); + dmi_probe_accuracy(sect_n, WORD(data + 0x0E)); - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x10)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x10)); - if(h->length < 0x16) + if(h->length < 0x16) { + sect_n = NULL; break; - _val = dmi_voltage_probe_value(WORD(data + 0x14)); - PyDict_SetItemString(caseData, "Nominal Value", _val); - Py_DECREF(_val); + } + dmi_voltage_probe_value(sect_n, "NominalValue", WORD(data + 0x14)); + + sect_n = NULL; break; case 27: /* 3.3.28 Cooling Device */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "CoolingDevice", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.28"); - if(h->length < 0x0C) + if(h->length < 0x0C) { + sect_n = NULL; break; - if(WORD(data + 0x04) != 0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data + 0x04)); - PyDict_SetItemString(caseData, "Temperature Probe Handle", _val); - Py_DECREF(_val); } - _val = dmi_cooling_device_type(data[0x06] & 0x1f); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + if(WORD(data + 0x04) != 0xFFFF) { + dmixml_AddTextContent(sect_n, "TemperatureProbeHandle", "0x%04x", WORD(data + 0x04)); + } - _val = dmi_probe_status(data[0x06] >> 5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + dmi_cooling_device_type(sect_n, data[0x06] & 0x1f); + dmi_probe_status(sect_n, data[0x06] >> 5); if(data[0x07] != 0x00) { - _val = PyString_FromFormat("%i", data[0x07]); - PyDict_SetItemString(caseData, "Cooling Unit Group", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "UnitGroup", "%i", data[0x07]); } - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x08)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x08)); - if(h->length < 0x0E) + if(h->length < 0x0E) { + sect_n = NULL; break; - _val = dmi_cooling_device_speed(WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Nominal Speed", _val); - Py_DECREF(_val); + } + + dmi_cooling_device_speed(sect_n, WORD(data + 0x0C)); + sect_n = NULL; break; case 28: /* 3.3.29 Temperature Probe */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "TemperatureProbe", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.29"); - if(h->length < 0x14) + if(h->length < 0x14) { + sect_n = NULL; break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); - - _val = dmi_temperature_probe_location(data[0x05] & 0x1F); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_probe_status(data[0x05] >> 5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - - _val = dmi_temperature_probe_value(WORD(data + 0x06)); - PyDict_SetItemString(caseData, "Maximum Value", _val); - Py_DECREF(_val); - - _val = dmi_temperature_probe_value(WORD(data + 0x08)); - PyDict_SetItemString(caseData, "Minimum Value", _val); - Py_DECREF(_val); - - _val = dmi_temperature_probe_resolution(WORD(data + 0x0A)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + } - _val = dmi_temperature_probe_value(WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Tolerance", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Description", "%s", dmi_string(h, data[0x04])); + dmi_temperature_probe_location(sect_n,data[0x05] & 0x1F); + dmi_probe_status(sect_n, data[0x05] >> 5); - _val = dmi_probe_accuracy(WORD(data + 0x0E)); - PyDict_SetItemString(caseData, "Accuracy", _val); - Py_DECREF(_val); + dmi_temperature_probe_value(sect_n, "MaxValue", WORD(data + 0x06)); + dmi_temperature_probe_value(sect_n, "MinValue", WORD(data + 0x08)); + dmi_temperature_probe_resolution(sect_n, WORD(data + 0x0A)); + dmi_temperature_probe_value(sect_n, "Tolerance", WORD(data + 0x0C)); + dmi_probe_accuracy(sect_n, WORD(data + 0x0E)); - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x10)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x10)); - if(h->length < 0x16) + if(h->length < 0x16) { + sect_n = NULL; break; - _val = dmi_temperature_probe_value(WORD(data + 0x14)); - PyDict_SetItemString(caseData, "Nominal Value", _val); - Py_DECREF(_val); + } + + dmi_temperature_probe_value(sect_n, "NominalValue", WORD(data + 0x14)); + sect_n = NULL; break; case 29: /* 3.3.30 Electrical Current Probe */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ElectricalCurrentProbe", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.30"); - if(h->length < 0x14) + if(h->length < 0x14) { + sect_n = NULL; break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); - - _val = dmi_voltage_probe_location(data[5] & 0x1F); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_probe_status(data[0x05] >> 5); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - - _val = dmi_current_probe_value(WORD(data + 0x06)); - PyDict_SetItemString(caseData, "Maximum Value", _val); - Py_DECREF(_val); - - _val = dmi_current_probe_value(WORD(data + 0x08)); - PyDict_SetItemString(caseData, "Minimum Value", _val); - Py_DECREF(_val); + } - _val = dmi_current_probe_resolution(WORD(data + 0x0A)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Description", dmi_string(h, data[0x04])); + dmi_voltage_probe_location(sect_n, data[5] & 0x1F); + dmi_probe_status(sect_n, data[0x05] >> 5); - _val = dmi_current_probe_value(WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Tolerance", _val); - Py_DECREF(_val); + dmi_current_probe_value(sect_n, "MaxValue", WORD(data + 0x06)); + dmi_current_probe_value(sect_n, "MinValue", WORD(data + 0x08)); + dmi_current_probe_resolution(sect_n, WORD(data + 0x0A)); + dmi_current_probe_value(sect_n, "Tolerance", WORD(data + 0x0C)); - _val = dmi_probe_accuracy(WORD(data + 0x0E)); - PyDict_SetItemString(caseData, "Accuracy", _val); - Py_DECREF(_val); + dmi_probe_accuracy(sect_n, WORD(data + 0x0E)); - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x10)); - PyDict_SetItemString(caseData, "OEM-specific Information", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x10)); - if(h->length < 0x16) + if(h->length < 0x16) { + sect_n = NULL; break; - _val = dmi_current_probe_value(WORD(data + 0x14)); - PyDict_SetItemString(caseData, "Nominal Value", _val); - Py_DECREF(_val); + } + dmi_current_probe_value(sect_n, "NominalValue", WORD(data + 0x14)); + + sect_n = NULL; break; case 30: /* 3.3.31 Out-of-band Remote Access */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OutOfBandRemoteAccess", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.31"); - if(h->length < 0x06) + if(h->length < 0x06) { + sect_n = NULL; break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Manufacturer Name", _val); - Py_DECREF(_val); + } - _val = data[0x05] & (1 << 0) ? Py_True : Py_False; - PyDict_SetItemString(caseData, "Inbound Connection Enabled", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "ManufacturerName", "%s", dmi_string(h, data[0x04])); + dmixml_AddAttribute(sect_n, "InboundConnectionEnabled", "%i", data[0x05] & (1 << 0) ? 1 : 0); + dmixml_AddAttribute(sect_n, "OutboundConnectionEnabled", "%i", data[0x05] & (1 << 1) ? 1 : 0); - _val = data[0x05] & (1 << 1) ? Py_True : Py_False; - PyDict_SetItemString(caseData, "Outbound Connection Enabled", _val); - Py_DECREF(_val); + sect_n = NULL; break; case 31: /* 3.3.32 Boot Integrity Services Entry Point */ - + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BootIntegrityServiceEntryPoint", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.32"); + dmixml_AddAttribute(sect_n, "NOT_IMPLEMENTED", "1"); break; case 32: /* 3.3.33 System Boot Information */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemBootInformation", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.33"); - if(h->length < 0x0B) - break; - _val = dmi_system_boot_status(data[0x0A]); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); - - break; - - case 33: /* 3.3.34 64-bit Memory Error Information */ - if(h->length < 0x1F) + if(h->length < 0x0B) { + sect_n = NULL; break; + } - _val = dmi_memory_error_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = dmi_memory_error_granularity(data[0x05]); - PyDict_SetItemString(caseData, "Granularity", _val); - Py_DECREF(_val); - - _val = dmi_memory_error_operation(data[0x06]); - PyDict_SetItemString(caseData, "Operation", _val); - Py_DECREF(_val); - - _val = dmi_memory_error_syndrome(DWORD(data + 0x07)); - PyDict_SetItemString(caseData, "Vendor Syndrome", _val); - Py_DECREF(_val); - - _val = dmi_64bit_memory_error_address(QWORD(data + 0x0B)); - PyDict_SetItemString(caseData, "Memory Array Address", _val); - Py_DECREF(_val); - - _val = dmi_64bit_memory_error_address(QWORD(data + 0x13)); - PyDict_SetItemString(caseData, "Device Address", _val); - Py_DECREF(_val); - - _val = dmi_32bit_memory_error_address(DWORD(data + 0x1B)); - PyDict_SetItemString(caseData, "Resolution", _val); - Py_DECREF(_val); + dmi_system_boot_status(sect_n, data[0x0A]); + sect_n = NULL; break; case 34: /* 3.3.35 Management Device */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ManagementDevice", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.35"); - if(h->length < 0x0B) + if(h->length < 0x0B) { + sect_n = NULL; break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); - - _val = dmi_management_device_type(data[0x05]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%08x", DWORD(data + 0x06)); - PyDict_SetItemString(caseData, "Address", _val); - Py_DECREF(_val); + } - _val = dmi_management_device_address_type(data[0x0A]); - PyDict_SetItemString(caseData, "Address Type", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Description", "%s", dmi_string(h, data[0x04])); + dmi_management_device_type(sect_n, data[0x05]); + dmixml_AddTextChild(sect_n, "Address", "0x%08x", DWORD(data + 0x06)); + dmi_management_device_address_type(sect_n, data[0x0A]); + sect_n = NULL; break; case 35: /* 3.3.36 Management Device Component */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ManagementDeviceComponent", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.36"); - if(h->length < 0x0B) + if(h->length < 0x0B) { + sect_n = NULL; break; - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(caseData, "Description", _val); - Py_DECREF(_val); - - _val = PyString_FromFormat("0x%04x", WORD(data + 0x05)); - PyDict_SetItemString(caseData, "Management Device Handle", _val); - Py_DECREF(_val); + } - _val = PyString_FromFormat("0x%04x", WORD(data + 0x07)); - PyDict_SetItemString(caseData, "Component Handle", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Description", dmi_string(h, data[0x04])); + dmixml_AddTextChild(sect_n, "ManagementDeviceHandle", "0x%04x", WORD(data + 0x05)); + dmixml_AddTextChild(sect_n, "ComponentHandle", "0x%04x", WORD(data + 0x07)); if(WORD(data + 0x09) != 0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data + 0x09)); - PyDict_SetItemString(caseData, "Threshold Handle", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "ThresholdHandle", "0x%04x", WORD(data + 0x09)); } + sect_n = NULL; break; case 36: /* 3.3.37 Management Device Threshold Data */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ManagementDeviceThresholdData", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.37"); - if(h->length < 0x10) + if(h->length < 0x10) { + sect_n = NULL; break; + } + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Thresholds", NULL); + assert( sub_n != NULL ); + dmixml_AddAttribute(sub_n, "mode", "non-critical"); + if(WORD(data + 0x04) != 0x8000) { - _val = PyString_FromFormat("%d", (i16) WORD(data + 0x04)); - PyDict_SetItemString(caseData, "Lower Non-critical Threshold", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Lower", "%d", (i16) WORD(data + 0x04)); } if(WORD(data + 0x06) != 0x8000) { - _val = PyString_FromFormat("%d", (i16) WORD(data + 0x06)); - PyDict_SetItemString(caseData, "Upper Non-critical Threshold", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Upper", "%d", (i16) WORD(data + 0x06)); } + sub_n = NULL; + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Thresholds", NULL); + assert( sub_n != NULL ); + dmixml_AddAttribute(sub_n, "mode", "critical"); + if(WORD(data + 0x08) != 0x8000) { - _val = PyString_FromFormat("%d", (i16) WORD(data + 0x08)); - PyDict_SetItemString(caseData, "Lower Critical Threshold", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Lower", "%d", (i16) WORD(data + 0x08)); } if(WORD(data + 0x0A) != 0x8000) { - _val = PyString_FromFormat("%d", (i16) WORD(data + 0x0A)); - PyDict_SetItemString(caseData, "Upper Critical Threshold", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Upper", "%d", (i16) WORD(data + 0x0A)); + } + sub_n = NULL; + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Thresholds", NULL); + assert( sub_n != NULL ); + dmixml_AddAttribute(sub_n, "mode", "non-recoverable"); + if(WORD(data + 0x0C) != 0x8000) { - _val = PyString_FromFormat("%d", (i16) WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Lower Non-recoverable Threshold", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Lower", "%d", (i16) WORD(data + 0x0C)); } if(WORD(data + 0x0E) != 0x8000) { - _val = PyString_FromFormat("%d", (i16) WORD(data + 0x0E)); - PyDict_SetItemString(caseData, "Upper Non-recoverable Threshold", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Upper", "%d", (i16) WORD(data + 0x0E)); } + sub_n = NULL; + sect_n = NULL; break; case 37: /* 3.3.38 Memory Channel */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryChannel", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.38"); - if(h->length < 0x07) + if(h->length < 0x07) { + sect_n = NULL; break; - _val = dmi_memory_channel_type(data[0x04]); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); + } - _val = PyString_FromFormat("%i", data[0x05]); - PyDict_SetItemString(caseData, "Maximal Load", _val); - Py_DECREF(_val); + dmi_memory_channel_type(sect_n, data[0x04]); + dmixml_AddTextChild(sect_n, "MaxLoad", "%i", data[0x05]); - _val = PyString_FromFormat("%i", data[0x06]); - PyDict_SetItemString(caseData, "Devices", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Devices", NULL); + assert( sub_n != NULL ); + dmixml_AddAttribute(sub_n, "devices", "%i", data[0x06]); - if(h->length < 0x07 + 3 * data[0x06]) + if(h->length < 0x07 + 3 * data[0x06]) { + sub_n = NULL; + sect_n = NULL; break; - _val = dmi_memory_channel_devices(data[0x06], data + 0x07); - PyDict_SetItemString(caseData, ">>>", _val); - Py_DECREF(_val); + } + dmi_memory_channel_devices(sub_n, data[0x06], data + 0x07); + sub_n = NULL; + + sect_n = NULL; break; case 38: /* 3.3.39 IPMI Device Information */ @@ -4857,214 +4901,197 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) * We use the word "Version" instead of "Revision", conforming to * the IPMI specification. */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "IPMIdeviceInformation", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.39"); - if(h->length < 0x10) + if(h->length < 0x10) { + sect_n = NULL; break; - _val = dmi_ipmi_interface_type(data[0x04]); - PyDict_SetItemString(caseData, "Interface Type", _val); - Py_DECREF(_val); + } + + dmi_ipmi_interface_type(sect_n, data[0x04]); - _val = PyString_FromFormat("%i.%i", data[0x05] >> 4, data[0x05] & 0x0F); - PyDict_SetItemString(caseData, "Specification Version", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sect_n, "spec_version", "%i.%i", data[0x05] >> 4, data[0x05] & 0x0F); + dmixml_AddAttribute(sect_n, "I2CslaveAddr", "0x%02x", data[0x06] >> 1); - _val = PyString_FromFormat("0x%02x", data[0x06] >> 1); - PyDict_SetItemString(caseData, "I2C Slave Address", _val); - Py_DECREF(_val); + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "NVstorageDevice", NULL); + assert( sub_n != NULL ); if(data[0x07] != 0xFF) { - _val = PyString_FromFormat("%i", data[0x07]); - PyDict_SetItemString(caseData, "NV Storage Device Address", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Address", "%i", data[0x07]); } else { - _val = Py_None; - PyDict_SetItemString(caseData, "NV Storage Device: Not Present", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "NotPresent", "1"); } + sub_n = NULL; - _val = - dmi_ipmi_base_address(data[0x04], data + 0x08, - h->length < 0x12 ? 0 : (data[0x10] >> 5) & 1); - PyDict_SetItemString(caseData, "Base Address", _val); - Py_DECREF(_val); + dmi_ipmi_base_address(sect_n, data[0x04], data + 0x08, + h->length < 0x12 ? 0 : (data[0x10] >> 5) & 1); - if(h->length < 0x12) + if(h->length < 0x12) { + sect_n = NULL; break; + } + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Interrupt", NULL); + assert( sub_n != NULL ); + if(data[0x04] != 0x04) { - _val = dmi_ipmi_register_spacing(data[0x10] >> 6); - PyDict_SetItemString(caseData, "Register Spacing", _val); - Py_DECREF(_val); + dmi_ipmi_register_spacing(sect_n, data[0x10] >> 6); if(data[0x10] & (1 << 3)) { - _val = - PyString_FromFormat("%s", - data[0x10] & (1 << 1) ? "Active High" : - "Active Low"); - PyDict_SetItemString(caseData, "Interrupt Polarity", _val); - Py_DECREF(_val); - - _val = - PyString_FromFormat("%s", - data[0x10] & (1 << 0) ? "Level" : "Edge"); - PyDict_SetItemString(caseData, "Interrupt Trigger Mode", _val); - Py_DECREF(_val); + sub2_n = dmixml_AddTextChild(sub_n, "Polarity", "%s", + data[0x10] & (1 << 1) ? "Active High" : "Active Low"); + assert( sub2_n != NULL ); + dmixml_AddAttribute(sub2_n, "active_high", "%i", data[0x10] & (1 << 1) ? 1: 0); + sub2_n = NULL; + + dmixml_AddTextChild(sub_n, "TriggerMode", "%s", + data[0x10] & (1 << 0) ? "Level" : "Edge"); } } if(data[0x11] != 0x00) { - _val = PyString_FromFormat("%x", data[0x11]); - PyDict_SetItemString(caseData, "Interrupt Number", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "InterruptNumber", "%x", data[0x11]); } + sub_n = NULL; + + sect_n = NULL; break; case 39: /* 3.3.40 System Power Supply */ + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemPowerSupply", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.40"); - if(h->length < 0x10) + if(h->length < 0x10) { + sect_n = NULL; break; - if(data[0x04] != 0x00) { - _val = PyString_FromFormat("%i", data[0x04]); - PyDict_SetItemString(caseData, "Power Unit Group", _val); - Py_DECREF(_val); } - _val = dmi_string_py(h, data[0x05]); - PyDict_SetItemString(caseData, "Location", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x06]); - PyDict_SetItemString(caseData, "Name", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x07]); - PyDict_SetItemString(caseData, "Manufacturer", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x08]); - PyDict_SetItemString(caseData, "Serial Numberr", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x09]); - PyDict_SetItemString(caseData, "Asset Tag", _val); - Py_DECREF(_val); - - _val = dmi_string_py(h, data[0x0A]); - PyDict_SetItemString(caseData, "Model Part Number", _val); - Py_DECREF(_val); + if(data[0x04] != 0x00) { + dmixml_AddAttribute(sect_n, "UnitGroup", "%i", data[0x04]); + } - _val = dmi_string_py(h, data[0x0B]); - PyDict_SetItemString(caseData, "Revision", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "Location", "%s", dmi_string(h, data[0x05])); + dmixml_AddTextChild(sect_n, "Name", "%s", dmi_string(h, data[0x06])); + dmixml_AddTextChild(sect_n, "Manufacturer", "%s", dmi_string(h, data[0x07])); + dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x08])); + dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x09])); + dmixml_AddTextChild(sect_n, "ModelPartNumber", "%s", dmi_string(h, data[0x0A])); + dmixml_AddTextChild(sect_n, "Revision", "%s", dmi_string(h, data[0x0B])); - _val = dmi_power_supply_power(WORD(data + 0x0C)); - PyDict_SetItemString(caseData, "Max Power Capacity", _val); - Py_DECREF(_val); + dmi_power_supply_power(sect_n, WORD(data + 0x0C)); if(WORD(data + 0x0E) & (1 << 1)) { - _val = dmi_power_supply_status((WORD(data + 0x0E) >> 7) & 0x07); - PyDict_SetItemString(caseData, "Status Present", _val); - Py_DECREF(_val); + dmi_power_supply_status(sect_n, (WORD(data + 0x0E) >> 7) & 0x07); } else { - _val = PyString_FromString("Not Present"); - PyDict_SetItemString(caseData, "Status", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Status", NULL); + assert( sub_n != NULL ); + dmixml_AddAttribute(sub_n, "present", "0"); + sub_n = NULL; } - _val = dmi_power_supply_type((WORD(data + 0x0E) >> 10) & 0x0F); - PyDict_SetItemString(caseData, "Type", _val); - Py_DECREF(_val); - _val = dmi_power_supply_range_switching((WORD(data + 0x0E) >> 3) & 0x0F); - PyDict_SetItemString(caseData, "Input Voltage Range Switching", _val); - Py_DECREF(_val); + dmi_power_supply_type(sect_n, (WORD(data + 0x0E) >> 10) & 0x0F); + + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Input", NULL); + assert( sub_n != NULL ); - _val = PyString_FromFormat("%s", WORD(data + 0x0E) & (1 << 2) ? "No" : "Yes"); - PyDict_SetItemString(caseData, "Plugged", _val); - Py_DECREF(_val); + dmi_power_supply_range_switching(sub_n, (WORD(data + 0x0E) >> 3) & 0x0F); - _val = PyString_FromFormat("%s", WORD(data + 0x0E) & (1 << 0) ? "Yes" : "No"); - PyDict_SetItemString(caseData, "Hot Replaceable", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Plugged", "%i", WORD(data + 0x0E) & (1 << 2) ? 0 : 1); + dmixml_AddAttribute(sub_n, "HotReplacable", "%i", WORD(data + 0x0E) & (1 << 0) ? 1 : 0); - if(h->length < 0x16) + if(h->length < 0x16) { + sub_n = NULL; + sect_n = NULL; break; + } + if(WORD(data + 0x10) != 0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data + 0x10)); - PyDict_SetItemString(caseData, "Input Voltage Probe Handle", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "ProbeHandle", "0x%04x", WORD(data + 0x10)); } if(WORD(data + 0x12) != 0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data + 0x12)); - PyDict_SetItemString(caseData, "Cooling Device Handle", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "CoolingDeviceHandle", "0x%04x", WORD(data + 0x12)); } if(WORD(data + 0x14) != 0xFFFF) { - _val = PyString_FromFormat("0x%04x", WORD(data + 0x14)); - PyDict_SetItemString(caseData, "Input Current Probe Handle", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sub_n, "CurrentProbeHandle", "0x%04x", WORD(data + 0x14)); } + sub_n = NULL; + sect_n = NULL; break; case 40: /* 3.3.41 Additional Information */ - if(h->length < 0x0B) + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "AdditionalInformation", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.41"); + + if(h->length < 0x0B) { + sect_n = NULL; break; - _key = PyString_FromFormat("Additional Information"); - _val = dmi_additional_info(h, ""); - PyDict_SetItem(caseData, _key, _val); - Py_DECREF(_key); - Py_DECREF(_val); + } + + dmi_additional_info(sect_n, h); + + sect_n = NULL; break; case 41: /* 3.3.42 Onboard Device Extended Information */ - if(h->length < 0x0B) - break; - PyObject *subdata = PyDict_New(); - - _val = dmi_string_py(h, data[0x04]); - PyDict_SetItemString(subdata, "Reference Designation", _val); - Py_DECREF(_val); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OnboardDeviceExtendedInformation", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.42"); - _val = PyString_FromString(dmi_on_board_devices_type(data[0x05] & 0x7F)); - PyDict_SetItemString(subdata, "Type", _val); - Py_DECREF(_val); + if(h->length < 0x0B) { + sect_n = NULL; + break; + } - _val = PyString_FromString(data[0x05] & 0x80 ? "Enabled" : "Disabled"); - PyDict_SetItemString(subdata, "Status", _val); - Py_DECREF(_val); + dmixml_AddTextChild(sect_n, "ReferenceDesignation", "%s", dmi_string(h, data[0x04])); - _val = PyInt_FromLong(data[0x06]); - PyDict_SetItemString(subdata, "Type Instance", _val); - Py_DECREF(_val); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "OnboardDevice", NULL); + dmi_on_board_devices_type(sub_n, data[0x05] & 0x7F); - _val = dmi_slot_segment_bus_func(WORD(data + 0x07), data[0x09], data[0x0A]); - PyDict_SetItemString(subdata, "Bus Address", _val); - Py_DECREF(_val); + dmixml_AddAttribute(sub_n, "Enabled", "%i", data[0x05] & 0x80 ? 1 : 0); + dmixml_AddAttribute(sub_n, "TypeInstance", "%ld", data[0x06]); + dmi_slot_segment_bus_func(sub_n, WORD(data + 0x07), data[0x09], data[0x0A]); + sub_n = NULL; - PyDict_SetItemString(caseData, "Onboard Device", subdata); - Py_DECREF(subdata); + sect_n = NULL; break; case 126: /* 3.3.43 Inactive */ - _val = Py_None; - PyDict_SetItemString(caseData, "Inactive", _val); - Py_DECREF(_val); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Inactive", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.43"); + + sect_n = NULL; break; case 127: /* 3.3.44 End Of Table */ - _val = Py_None; - PyDict_SetItemString(caseData, "End Of Table", _val); - Py_DECREF(_val); + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "EndOfTable", NULL); + assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "dmispec", "3.3.44"); + sect_n = NULL; + break; default: if(dmi_decode_oem(h)) break; - _key = PyString_FromFormat("%s Type", h->type >= 128 ? "OEM-specific" : "Unknown"); - _val = dmi_dump(h); - PyDict_SetItem(caseData, _key, _val); - Py_DECREF(_key); - Py_DECREF(_val); + + sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "DMIdump", NULL); + assert( sect_n != NULL ); + + dmixml_AddAttribute(sect_n, "Type", "%i", h->type); + dmixml_AddAttribute(sect_n, "InfoType", "%s", h->type >= 128 ? "OEM-specific" : "Unknown"); + + dmi_dump(sect_n, h); + + sect_n = NULL; + break; } } @@ -5076,40 +5103,45 @@ void to_dmi_header(struct dmi_header *h, u8 * data) h->data = data; } -static void dmi_table_string_py(const struct dmi_header *h, const u8 * data, PyObject * hDict, - u16 ver) +void dmi_table_string(const struct dmi_header *h, const u8 *data, xmlNode *node, u16 ver) { int key; u8 offset = opt.string->offset; + xmlNode *dmi_n = NULL; if(offset >= h->length) return; //. TODO: These should have more meaningful dictionary names key = (opt.string->type << 8) | offset; - PyObject *_val; switch (key) { case 0x108: - _val = dmi_system_uuid_py(data + offset, ver); - PyDict_SetItemString(hDict, "0x108", _val); + dmi_system_uuid(node, data + offset, ver); + dmixml_AddAttribute(node, "DMItype", "0x108"); break; + case 0x305: - _val = dmi_chassis_type_py(data[offset]); - PyDict_SetItemString(hDict, "0x305", _val); + dmi_chassis_type(node, data[offset]); + dmixml_AddAttribute(node, "DMItype", "0x305"); + // FIXME: Missing break? + case 0x406: - _val = PyString_FromString(dmi_processor_family(h)); - PyDict_SetItemString(hDict, "0x406", _val); + dmi_processor_family(node, h); + dmixml_AddAttribute(node, "DMItype", "0x406"); break; + case 0x416: - _val = dmi_processor_frequency_py((u8 *) data + offset); - PyDict_SetItemString(hDict, "0x416", _val); + dmi_n = dmixml_AddTextChild(node, "ProcessorFrequency", "%s", + dmi_processor_frequency((u8 *) data + offset)); + dmixml_AddAttribute(dmi_n, "DMItype", "0x416"); + dmi_n = NULL; break; + default: - _val = dmi_string_py(h, data[offset]); - PyDict_SetItemString(hDict, "0x???", _val); + dmi_n = dmixml_AddTextChild(node, "Unknown", "%s", dmi_string(h, data[offset])); + dmixml_AddAttribute(dmi_n, "DMItype", "0x%03x", key); } - Py_DECREF(_val); } /* @@ -5249,13 +5281,19 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x int i = 0; if(opt.type == NULL) { - /* FIXME: How to interpret this section in XML? */ - dmiSetItem(pydata, "dmi_table_size", "%i structures occupying %i bytes", num, len); + xmlNode *info_n = NULL; + + info_n = dmixml_AddTextChild(xmlnode, "DMIinfo", "%i structures occupying %i bytes", num, len); + dmixml_AddAttribute(info_n, "dmi_structures", "%i", num); + dmixml_AddAttribute(info_n, "dmi_size", "%i", len); + /* TODO DUMP * if (!(opt.flags & FLAG_FROM_DUMP)) - * dmiSetItem(pydata, "dmi_table_base", "Table at 0x%08x", base); + * dmixml_AddAttribute(info_n, "dmi_table_base", "0x%08x", base); */ - dmiSetItem(pydata, "dmi_table_base", "Table at 0x%08x", base); + + dmixml_AddAttribute(info_n, "dmi_table_base", "0x%08x", base); + info_n = NULL; } if((buf = mem_chunk(base, len, devmem)) == NULL) { @@ -5295,15 +5333,15 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x * stop decoding at end of table marker */ - xmlNode *handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "dmi_handle", NULL); + xmlNode *handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMIentry", NULL); assert( handle_n != NULL ); - dmixml_AddAttribute(handle_n, "id", "0x%04x%c", h.handle); + + dmixml_AddAttribute(handle_n, "handle", "0x%04x%c", h.handle); dmixml_AddAttribute(handle_n, "type", "%d", h.type); dmixml_AddAttribute(handle_n, "size", "%d", h.length); /* assign vendor for vendor-specific decodes later */ if(h.type == 0 && h.length >= 5) { - /* FIXME: Need XML API */ dmi_set_vendor(dmi_string(&h, data[0x04])); } @@ -5331,7 +5369,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x fprintf(stderr, ""); } else if(opt.string != NULL && opt.string->type == h.type) { // <<<---- ** Need to handle this as well ** - dmi_table_string_py(&h, data, hDict, ver); + dmi_table_string(&h, data, handle_n, ver); } data = next; @@ -5451,13 +5489,13 @@ int legacy_decode_set_version(u8 * buf, const char *devmem, PyObject ** pydata) } return check; } -int legacy_decode(u8 * buf, const char *devmem, PyObject * pydata) +int legacy_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) { int check = _legacy_decode_check(buf); if(check == 1) dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), - ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, pydata); + ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, xmlnode); return check; } -- cgit From 581b015c91a3b364b1c1324bed775bfd2ce99dbd Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 9 Apr 2009 11:49:50 +0200 Subject: Made it compile --- src/dmidecode.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 773a673..c146969 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -86,11 +86,6 @@ #define EFI_NOT_FOUND (-1) #define EFI_NO_SMBIOS (-2) -static const char *out_of_spec = ""; -static const char *bad_index = ""; - -#define BAD_INDEX PyString_FromString("") -#define OUT_OF_SPEC PyString_FromString("") /******************************************************************************* ** Type-independant Stuff @@ -112,7 +107,7 @@ const char *dmi_string(const struct dmi_header *dm, u8 s) } if(!*bp) - return bad_index; + return NULL; /* ASCII filtering */ len = strlen(bp); @@ -233,7 +228,7 @@ void dmi_dump(xmlNode *node, struct dmi_header * h) if((h->data)[h->length] || (h->data)[h->length + 1]) { i = 1; - while((s = dmi_string(h, i++)) != bad_index) { + while((s = dmi_string(h, i++)) != NULL) { //. FIXME: DUMP /* * if(opt.flags & FLAG_DUMP) { @@ -344,7 +339,7 @@ void dmi_bios_characteristics_x1(xmlNode *node, u8 code) dmixml_AddAttribute(node, "flags", "0x%04x", code); for(i = 0; i <= 7; i++) { - if( code.l & (1 << i) ) { + if( code & (1 << i) ) { dmixml_AddTextChild(node, "characteristic", characteristics[i]); } } @@ -364,7 +359,7 @@ void dmi_bios_characteristics_x2(xmlNode *node, u8 code) dmixml_AddAttribute(node, "flags", "0x%04x", code); for(i = 0; i <= 2; i++) { - if( code.l & (1 << i) ) { + if( code & (1 << i) ) { dmixml_AddTextChild(node, "characteristic", characteristics[i]); } } -- cgit From 95b156e3d8a6b82bddb5516735e82355f5dee50a Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 9 Apr 2009 12:12:56 +0200 Subject: Removed all Python dependencies in dmidecode.[ch] --- src/dmidecode.c | 59 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index c146969..f6f4283 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -60,8 +60,6 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include - /* #undef NDEBUG */ @@ -5388,12 +5386,14 @@ int _smbios_decode_check(u8 * buf) !checksum(buf + 0x10, 0x0F)) ? 0 : 1; return check; } -int smbios_decode_set_version(u8 * buf, const char *devmem, PyObject ** pydata) + +int smbios_decode_set_version(u8 * buf, const char *devmem, xmlNode *node) { int check = _smbios_decode_check(buf); - char vbuf[64]; - bzero(vbuf, 64); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "SMBIOSversion", NULL); + assert( data_n != NULL ); + if(check == 1) { u16 ver = (buf[0x06] << 8) + buf[0x07]; @@ -5414,20 +5414,18 @@ int smbios_decode_set_version(u8 * buf, const char *devmem, PyObject ** pydata) ver = 0x0206; break; } - if(_m || _M) - sprintf(vbuf, "SMBIOS %i.%i present (Version fixup 2.%d -> 2.%d)", ver >> 8, - ver & 0xFF, _m, _M); - else - sprintf(vbuf, "SMBIOS %i.%i present", ver >> 8, ver & 0xFF); - } else if(check == 0) { - sprintf(vbuf, "No SMBIOS nor DMI entry point found"); - } - if(check == 1) { - if(*pydata) { - Py_DECREF(*pydata); + if(_m || _M) { + dmixml_AddTextContent(data_n, "SMBIOS %i.%i present (Version fixup 2.%d -> 2.%d)", + ver >> 8, ver & 0xFF, _m, _M); + dmixml_AddAttribute(data_n, "version", "%i.%i", ver >> 8, ver & 0xFF); + dmixml_AddAttribute(data_n, "fixup_version", "2.%d_2.%d", _m, _M); + } else { + dmixml_AddTextContent(data_n, "SMBIOS %i.%i present", ver >> 8, ver & 0xFF); + dmixml_AddAttribute(data_n, "version", "%i.%i", ver >> 8, ver & 0xFF); } - *pydata = PyString_FromString(vbuf); - Py_INCREF(*pydata); + } else if(check == 0) { + dmixml_AddTextContent(data_n, "No SMBIOS nor DMI entry point found"); + dmixml_AddAttribute(data_n, "unknown", "1"); } return check; } @@ -5464,26 +5462,27 @@ int _legacy_decode_check(u8 * buf) check = 1; //. Good return check; } -int legacy_decode_set_version(u8 * buf, const char *devmem, PyObject ** pydata) + +int legacy_decode_set_version(u8 * buf, const char *devmem, xmlNode *node) { int check = _legacy_decode_check(buf); - char vbuf[64]; - bzero(vbuf, 64); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "LegacyDMI", NULL); + assert( data_n != NULL ); + if(check == 1) { - sprintf(vbuf, "Legacy DMI %i.%i present", buf[0x0E] >> 4, buf[0x0E] & 0x0F); + dmixml_AddTextContent(data_n, "Legacy DMI %i.%i present", + buf[0x0E] >> 4, buf[0x0E] & 0x0F); + dmixml_AddAttribute(data_n, "version", "%i.%i", + buf[0x0E] >> 4, buf[0x0E] & 0x0F); } else if(check == 0) { - sprintf(vbuf, "No SMBIOS nor DMI entry point found"); - } - if(check == 1) { - if(*pydata) { - Py_DECREF(*pydata); - } - *pydata = PyString_FromString(vbuf); - Py_INCREF(*pydata); + dmixml_AddTextContent(data_n, "No SMBIOS nor DMI entry point found"); + dmixml_AddAttribute(data_n, "unknown", "1"); } + return check; } + int legacy_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) { int check = _legacy_decode_check(buf); -- cgit From 92ea3b07784853558d93391dbc364c69463cd61d Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 10 Apr 2009 11:28:41 +0200 Subject: Fixed wrong string handling of DMI data, which caused SEGV --- src/dmidecode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index f6f4283..9c00e63 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3656,7 +3656,7 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_codes_major *dmiMajor = (dmi_codes_major *) &dmiCodesMajor[h->type]; dmixml_AddAttribute(handle_n, "id", "%s", dmiMajor->id); - dmixml_AddAttribute(handle_n, "type", "%s", h->type); + dmixml_AddAttribute(handle_n, "type", "%i", h->type); dmixml_AddTextChild(handle_n, "description", "%s", dmiMajor->desc); switch (h->type) { @@ -3670,9 +3670,9 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) break; } - dmixml_AddTextChild(sect_n, "Vendor", "%s", data[0x04]); - dmixml_AddTextChild(sect_n, "Version", "%s", data[0x05]); - dmixml_AddTextChild(sect_n, "ReleaseDate", "%s", data[0x08]); + dmixml_AddTextChild(sect_n, "Vendor", "%s", dmi_string(h, data[0x04])); + dmixml_AddTextChild(sect_n, "Version", "%s", dmi_string(h, data[0x05])); + dmixml_AddTextChild(sect_n, "ReleaseDate", "%s", dmi_string(h, data[0x08])); /* * On IA-64, the BIOS base address will read 0 because -- cgit From 38c943db697b13e5f9be020a0729f58b7366e932 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 10 Apr 2009 13:52:47 +0200 Subject: Cleaned up the XML data --- src/dmidecode.c | 361 +++++--------------------------------------------------- 1 file changed, 32 insertions(+), 329 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 9c00e63..c348380 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -702,8 +702,8 @@ void dmi_processor_type(xmlNode *node, u8 code) }; xmlNode *proct_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL); assert( proct_n != NULL ); - dmixml_AddAttribute(proct_n, "dmispec", "3.3.5"); dmixml_AddAttribute(proct_n, "flags", "0x%04x", code); + if(code >= 0x01 && code <= 0x06) { dmixml_AddTextContent(proct_n, type[code - 0x01]); } else { @@ -1000,7 +1000,6 @@ xmlNode *dmi_processor_id(xmlNode *node, u8 type, const u8 * p, const char *vers xmlNode *flags_n = NULL; xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "CPUCore", NULL); assert( data_n != NULL ); - dmixml_AddAttribute(data_n, "dmispec", "3.3.5"); /* ** Extra flags are now returned in the ECX register when one calls @@ -1149,8 +1148,8 @@ void dmi_processor_voltage(xmlNode *node, u8 code) dmixml_AddAttribute(vltg_n, "flags", "0x%04x", code); if(code & 0x80) { - dmixml_AddTextChild(vltg_n, "Voltage", "%.1f", (float)(code & 0x7f) / 10); - dmixml_AddAttribute(vltg_n, "unit", "V"); + xmlNode *v_n = dmixml_AddTextChild(vltg_n, "Voltage", "%.1f", (float)(code & 0x7f) / 10); + dmixml_AddAttribute(v_n, "unit", "V"); } else if( code == 0x00 ) { dmixml_AddAttribute(vltg_n, "unknown_value", "1"); } else { @@ -1242,10 +1241,10 @@ void dmi_processor_cache(xmlNode *cache_n, u16 code, u16 ver) { assert( cache_n != NULL ); - dmixml_AddAttribute(cache_n, "flags", "0x%04x", code); dmixml_AddAttribute(cache_n, "ver", "0x%04x", ver); if(code == 0xFFFF) { + dmixml_AddAttribute(cache_n, "flags", "0x%04x", code); if(ver >= 0x0203) { dmixml_AddAttribute(cache_n, "provided", "0"); dmixml_AddAttribute(cache_n, "available", "1"); @@ -1255,7 +1254,7 @@ void dmi_processor_cache(xmlNode *cache_n, u16 code, u16 ver) } else { dmixml_AddAttribute(cache_n, "provided", "1"); dmixml_AddAttribute(cache_n, "available", "1"); - dmixml_AddTextChild(cache_n, "Handle", "0x%04x", code); + dmixml_AddAttribute(cache_n, "Handle", "0x%04x", code); } } @@ -3645,7 +3644,7 @@ void dmi_additional_info(xmlNode *node, const struct dmi_header *h) ** Main */ -void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) +xmlNode *dmi_decode(struct dmi_header * h, u16 ver) { const u8 *data = h->data; xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL; @@ -3655,18 +3654,17 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) //dmi_codes_major *dmiMajor = (dmi_codes_major *)&dmiCodesMajor[map_maj[h->type]]; dmi_codes_major *dmiMajor = (dmi_codes_major *) &dmiCodesMajor[h->type]; - dmixml_AddAttribute(handle_n, "id", "%s", dmiMajor->id); - dmixml_AddAttribute(handle_n, "type", "%i", h->type); - dmixml_AddTextChild(handle_n, "description", "%s", dmiMajor->desc); + + sect_n = xmlNewNode(NULL, (xmlChar *) dmiMajor->tagname); + assert( sect_n != NULL ); + + dmixml_AddAttribute(sect_n, "id", "%s", dmiMajor->id); + dmixml_AddAttribute(sect_n, "type", "%i", h->type); + dmixml_AddTextChild(sect_n, "description", "%s", dmiMajor->desc); switch (h->type) { case 0: /* 3.3.1 BIOS Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOSinformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.1"); - if(h->length < 0x12) { - sect_n = NULL; break; } @@ -3695,7 +3693,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) sub_n = NULL; if(h->length < 0x13) { - sect_n = NULL; break; } @@ -3707,7 +3704,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) sub_n = NULL; if(h->length < 0x14) { - sect_n = NULL; break; } @@ -3719,7 +3715,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) sub_n = NULL; if(h->length < 0x18) { - sect_n = NULL; break; } @@ -3730,16 +3725,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) if(data[0x16] != 0xFF && data[0x17] != 0xFF) { dmixml_AddTextChild(sect_n, "FirmwareRevision", "%i.%i", data[0x16], data[0x17]); } - sect_n = NULL; break; case 1: /* 3.3.2 System Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.2"); - if(h->length < 0x08) { - sect_n = NULL; break; } @@ -3749,7 +3738,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); if(h->length < 0x19) { - sect_n = NULL; break; } @@ -3758,23 +3746,15 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_system_wake_up_type(sect_n, data[0x18]); if(h->length < 0x1B) { - sect_n = NULL; break; } dmixml_AddTextChild(sect_n, "SKUnumber", "%s", dmi_string(h, data[0x19])); dmixml_AddTextChild(sect_n, "Family", "%s", dmi_string(h, data[0x1A])); - - sect_n = NULL; break; case 2: /* 3.3.3 Base Board Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BaseboardInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.3"); - if(h->length < 0x08) { - sect_n = NULL; break; } @@ -3784,7 +3764,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x07])); if(h->length < 0x0F) { - sect_n = NULL; break; } @@ -3798,20 +3777,14 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_base_board_type(sect_n, "Type", data[0x0D]); if(h->length < 0x0F + data[0x0E] * sizeof(u16)) { - sect_n = NULL; break; } dmi_base_board_handles(sect_n, data[0x0E], data + 0x0F); - sect_n = NULL; break; case 3: /* 3.3.4 Chassis Information */ - sect_n= xmlNewChild(handle_n, NULL, (xmlChar *) "ChassisInformation", NULL); - assert( sect_n != NULL ); - if(h->length < 0x09) { - sect_n = NULL; break; } @@ -3823,7 +3796,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x08])); if(h->length < 0x0D) { - sect_n = NULL; break; } @@ -3838,14 +3810,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_chassis_security_status(sect_n, data[0x0C]); if(h->length < 0x11) { - sect_n = NULL; break; } dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x0D)); if(h->length < 0x13) { - sect_n = NULL; break; } @@ -3853,21 +3823,14 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_chassis_power_cords(sect_n, data[0x12]); if((h->length < 0x15) || (h->length < 0x15 + data[0x13] * data[0x14])){ - sect_n = NULL; break; } dmi_chassis_elements(sect_n, data[0x13], data[0x14], data + 0x15); - sect_n = NULL; break; case 4: /* 3.3.5 Processor Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ProcessorInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.5"); - if(h->length < 0x1A) { - sect_n = NULL; break; } @@ -3912,7 +3875,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_processor_upgrade(sect_n, data[0x19]); if(h->length < 0x20) { - sect_n = NULL; break; } @@ -3943,7 +3905,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) sub_n = NULL; if(h->length < 0x23) { - sect_n = NULL; break; } @@ -3952,7 +3913,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "PartNumber", "%s", dmi_string(h, data[0x22])); if(h->length < 0x28) { - sect_n = NULL; break; } @@ -3973,19 +3933,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_processor_characteristics(sub_n, WORD(data + 0x26)); sub_n = NULL; - - sect_n = NULL; break; case 5: /* 3.3.6 Memory Controller Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryControllerInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.6"); - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0F) { - sect_n = NULL; break; } @@ -4014,31 +3967,23 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_processor_voltage(sect_n, data[0x0D]); if(h->length < 0x0F + data[0x0E] * sizeof(u16)) { - sect_n = NULL; break; } dmi_memory_controller_slots(sect_n, data[0x0E], data + 0x0F); if(h->length < 0x10 + data[0x0E] * sizeof(u16)) { - sect_n = NULL; break; } dmi_memory_controller_ec_capabilities(sect_n, "EnabledErrorCorrection", data[0x0F + data[0x0E] * sizeof(u16)]); - sect_n = NULL; break; case 6: /* 3.3.7 Memory Module Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryModuleInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.7"); - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0C) { - sect_n = NULL; break; } @@ -4050,18 +3995,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_memory_module_size(sect_n, "InstalledSize", data[0x09]); dmi_memory_module_size(sect_n, "EnabledSize", data[0x0A]); dmi_memory_module_error(sect_n, data[0x0B]); - sect_n = NULL; break; case 7: /* 3.3.8 Cache Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "CacheInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.8"); - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0F) { - sect_n = NULL; break; } @@ -4083,7 +4022,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_cache_types(sect_n, "InstalledSRAMtypes", WORD(data + 0x0D)); if(h->length < 0x13) { - sect_n = NULL; break; } @@ -4091,19 +4029,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_cache_ec_type(sect_n, data[0x10]); dmi_cache_type(sect_n, data[0x11]); dmi_cache_associativity(sect_n, data[0x12]); - - sect_n = NULL; break; case 8: /* 3.3.9 Port Connector Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "PortConnectorInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.9"); - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x09) { - sect_n = NULL; break; } @@ -4121,19 +4052,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_port_connector_type(sect_n, "external", data[0x07]); dmi_port_type(sect_n, data[0x08]); - - sect_n = NULL; break; case 9: /* 3.3.10 System Slots */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemSlots", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.10"); - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x0C) { - sect_n = NULL; break; } @@ -4150,76 +4074,42 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) } else { dmi_slot_characteristics(sect_n, data[0x0B], data[0x0C]); } - - sect_n = NULL; break; case 10: /* 3.3.11 On Board Devices Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OnBoardDevicesInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.11"); - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - - sect_n = NULL; break; case 11: /* 3.3.12 OEM Strings */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OEMstrings", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.12"); - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); if(h->length < 0x05) { - sect_n = NULL; break; } dmi_oem_strings(sect_n, h); - - sect_n = NULL; break; case 12: /* 3.3.13 System Configuration Options */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemConfigurationOptions", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.13"); - if(h->length < 0x05) { - sect_n = NULL; break; } dmi_system_configuration_options(sect_n, h); - - sect_n = NULL; break; case 13: /* 3.3.14 BIOS Language Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BIOSlanguageInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.14"); - if(h->length < 0x16) { - sect_n = NULL; break; } dmixml_AddAttribute(sect_n, "installable_languages", "%i", data[0x04]); dmi_bios_languages(sect_n, h); - - sect_n = NULL; break; case 14: /* 3.3.15 Group Associations */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "GroupAssociations", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.15"); - if(h->length < 0x05) { - sect_n = NULL; break; } @@ -4229,18 +4119,11 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) assert( sub_n != NULL ); dmi_group_associations_items(sub_n, (h->length - 0x05) / 3, data + 0x05); sub_n = NULL; - - sect_n = NULL; break; case 15: /* 3.3.16 System Event Log */ // SysEventLog - sect_n - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemEventLog", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.16"); - if(h->length < 0x14) { - sect_n = NULL; break; } @@ -4268,7 +4151,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sub2_n, "ChangeToken", "0x%08x", DWORD(data + 0x0C)); if(h->length < 0x17) { - sect_n = NULL; break; } @@ -4286,7 +4168,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddAttribute(sub_n, "count", "%i", data[0x15]); if(h->length < 0x17 + data[0x15] * data[0x16]) { - sect_n = NULL; break; } @@ -4295,17 +4176,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) // SysEventLog/LogTypes/LogType dmi_event_log_descriptors(sub_n, data[0x15], data[0x16], data + 0x17); sub_n = NULL; - - sect_n = NULL; break; case 16: /* 3.3.17 Physical Memory Array */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "PhysicalMemoryArray", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.17"); - if(h->length < 0x0F) { - sect_n = NULL; break; } @@ -4315,17 +4189,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_memory_array_ec_type(sect_n, data[0x06]); dmi_memory_array_capacity(sect_n, DWORD(data + 0x07)); dmi_memory_array_error_handle(sect_n, WORD(data + 0x0B)); - - sect_n = NULL; break; case 17: /* 3.3.18 Memory Device */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryDevice", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.18"); - if(h->length < 0x15) { - sect_n = NULL; break; } @@ -4344,14 +4211,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_memory_device_type_detail(sect_n, WORD(data + 0x13)); if(h->length < 0x17) { - sect_n = NULL; break; } dmi_memory_device_speed(sect_n, WORD(data + 0x15)); if(h->length < 0x1B) { - sect_n = NULL; break; } @@ -4359,27 +4224,19 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "SerialNumber", "%s", dmi_string(h, data[0x18])); dmixml_AddTextChild(sect_n, "AssetTag", "%s", dmi_string(h, data[0x19])); dmixml_AddTextChild(sect_n, "PartNumber", "%s", dmi_string(h, data[0x1A])); - - sect_n = NULL; break; case 18: /* 3.3.19 32-bit Memory Error Information */ case 33: /* 3.3.34 64-bit Memory Error Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryErrorInfo", NULL); - assert( sect_n != NULL ); - if( h->type == 18 ) { - dmixml_AddAttribute(sect_n, "dmispec", "3.3.19"); dmixml_AddAttribute(sect_n, "bits", "32"); } else { - dmixml_AddAttribute(sect_n, "dmispec", "3.3.34"); dmixml_AddAttribute(sect_n, "bits", "64"); } if( ((h->type == 18) && (h->length < 0x17)) /* 32-bit */ || ((h->type == 33) && (h->length < 0x1F)) ) /* 64-bit */ { - sect_n = NULL; break; } @@ -4399,17 +4256,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_64bit_memory_error_address(sect_n, "DeviceAddr", QWORD(data + 0x13)); dmi_32bit_memory_error_address(sect_n, "Resolution", DWORD(data + 0x1B)); } - - sect_n = NULL; break; case 19: /* 3.3.20 Memory Array Mapped Address */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryArrayMappedAddress", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.20"); - if(h->length < 0x0F) { - sect_n = NULL; break; } @@ -4422,17 +4272,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_mapped_address_size(sect_n, DWORD(data + 0x08) - DWORD(data + 0x04) + 1); dmixml_AddTextChild(sect_n, "PhysicalArrayHandle", "0x%04x", WORD(data + 0x0C)); dmixml_AddTextChild(sect_n, "PartitionWidth", "%i", data[0x0F]); - - sect_n = NULL; break; case 20: /* 3.3.21 Memory Device Mapped Address */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryDeviceMappedAddress", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.21"); - if(h->length < 0x13) { - sect_n = NULL; break; } @@ -4453,34 +4296,20 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_mapped_address_interleave_position(sect_n, data[0x11]); dmi_mapped_address_interleaved_data_depth(sect_n, data[0x12]); - - sect_n = NULL; break; case 21: /* 3.3.22 Built-in Pointing Device */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BuiltInPointingDevice", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.22"); - if(h->length < 0x07) { - sect_n = NULL; break; } dmi_pointing_device_type(sect_n, data[0x04]); dmi_pointing_device_interface(sect_n, data[0x05]); dmixml_AddTextContent(sect_n, "Buttons", "%i", data[0x06]); - - sect_n = NULL; break; case 22: /* 3.3.23 Portable Battery */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "PortableBattery", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.23"); - if(h->length < 0x10) { - sect_n = NULL; break; } @@ -4508,7 +4337,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_battery_maximum_error(sect_n, data[0x0F]); if(h->length < 0x1A) { - sect_n = NULL; break; } @@ -4526,17 +4354,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) } dmixml_AddTextChild(sect_n, "OEMinformation", "%s", "0x%08x", DWORD(data + 0x16)); - - sect_n = NULL; break; case 23: /* 3.3.24 System Reset */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemReset", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.24"); - if(h->length < 0x0D) { - sect_n = NULL; break; } @@ -4551,7 +4372,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) sub_n = NULL; if(!(data[0x04] & (1 << 5))) { - sect_n = NULL; break; } @@ -4563,17 +4383,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_system_reset_timer(sect_n, "TimerInterval", WORD(data + 0x09)); dmi_system_reset_timer(sect_n, "Timeout", WORD(data + 0x0B)); - - sect_n = NULL; break; case 24: /* 3.3.25 Hardware Security */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "HardwareSecurity", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.25"); - if(h->length < 0x05) { - sect_n = NULL; break; } @@ -4582,31 +4395,20 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_hardware_security_status(sect_n, "AdministratorPassword", (data[0x04] >> 2) & 0x3); dmi_hardware_security_status(sect_n, "FronPanelReset", data[0x04] & 0x3); - sect_n = NULL; break; case 25: /* 3.3.26 System Power Controls */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemPowerControls", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.26"); - if(h->length < 0x09) { - sect_n = NULL; break; } dmi_power_controls_power_on(sect_n, "NextSchedPowerOn", data + 0x04); - - sect_n = NULL; break; case 26: /* 3.3.27 Voltage Probe */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "VoltageProbe", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.27"); + dmixml_AddAttribute(sect_n, "probetype", "Voltage"); if(h->length < 0x14) { - sect_n = NULL; break; } @@ -4625,22 +4427,14 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x10)); if(h->length < 0x16) { - sect_n = NULL; break; } dmi_voltage_probe_value(sect_n, "NominalValue", WORD(data + 0x14)); - - sect_n = NULL; break; case 27: /* 3.3.28 Cooling Device */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "CoolingDevice", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.28"); - if(h->length < 0x0C) { - sect_n = NULL; break; } @@ -4658,22 +4452,16 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x08)); if(h->length < 0x0E) { - sect_n = NULL; break; } dmi_cooling_device_speed(sect_n, WORD(data + 0x0C)); - - sect_n = NULL; break; case 28: /* 3.3.29 Temperature Probe */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "TemperatureProbe", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.29"); + dmixml_AddAttribute(sect_n, "probetype", "Temperature"); if(h->length < 0x14) { - sect_n = NULL; break; } @@ -4690,22 +4478,16 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x10)); if(h->length < 0x16) { - sect_n = NULL; break; } dmi_temperature_probe_value(sect_n, "NominalValue", WORD(data + 0x14)); - - sect_n = NULL; break; case 29: /* 3.3.30 Electrical Current Probe */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ElectricalCurrentProbe", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.30"); + dmixml_AddAttribute(sect_n, "probetype", "Electrical Current"); if(h->length < 0x14) { - sect_n = NULL; break; } @@ -4723,61 +4505,38 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x10)); if(h->length < 0x16) { - sect_n = NULL; break; } dmi_current_probe_value(sect_n, "NominalValue", WORD(data + 0x14)); - - sect_n = NULL; break; case 30: /* 3.3.31 Out-of-band Remote Access */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OutOfBandRemoteAccess", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.31"); - if(h->length < 0x06) { - sect_n = NULL; break; } dmixml_AddTextChild(sect_n, "ManufacturerName", "%s", dmi_string(h, data[0x04])); dmixml_AddAttribute(sect_n, "InboundConnectionEnabled", "%i", data[0x05] & (1 << 0) ? 1 : 0); dmixml_AddAttribute(sect_n, "OutboundConnectionEnabled", "%i", data[0x05] & (1 << 1) ? 1 : 0); - - sect_n = NULL; break; case 31: /* 3.3.32 Boot Integrity Services Entry Point */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "BootIntegrityServiceEntryPoint", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.32"); dmixml_AddAttribute(sect_n, "NOT_IMPLEMENTED", "1"); break; case 32: /* 3.3.33 System Boot Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemBootInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.33"); - if(h->length < 0x0B) { - sect_n = NULL; break; } dmi_system_boot_status(sect_n, data[0x0A]); - - sect_n = NULL; break; case 34: /* 3.3.35 Management Device */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ManagementDevice", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.35"); + dmixml_AddAttribute(sect_n, "mgmtype", ""); if(h->length < 0x0B) { - sect_n = NULL; break; } @@ -4785,17 +4544,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmi_management_device_type(sect_n, data[0x05]); dmixml_AddTextChild(sect_n, "Address", "0x%08x", DWORD(data + 0x06)); dmi_management_device_address_type(sect_n, data[0x0A]); - - sect_n = NULL; break; case 35: /* 3.3.36 Management Device Component */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ManagementDeviceComponent", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.36"); + dmixml_AddAttribute(sect_n, "mgmtype", "Component"); if(h->length < 0x0B) { - sect_n = NULL; break; } @@ -4806,17 +4560,12 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) if(WORD(data + 0x09) != 0xFFFF) { dmixml_AddTextChild(sect_n, "ThresholdHandle", "0x%04x", WORD(data + 0x09)); } - - sect_n = NULL; break; case 36: /* 3.3.37 Management Device Threshold Data */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "ManagementDeviceThresholdData", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.37"); + dmixml_AddAttribute(sect_n, "mgmtype", "Threshold Data"); if(h->length < 0x10) { - sect_n = NULL; break; } @@ -4856,17 +4605,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddAttribute(sub_n, "Upper", "%d", (i16) WORD(data + 0x0E)); } sub_n = NULL; - - sect_n = NULL; break; case 37: /* 3.3.38 Memory Channel */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "MemoryChannel", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.38"); - if(h->length < 0x07) { - sect_n = NULL; break; } @@ -4879,14 +4621,11 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) if(h->length < 0x07 + 3 * data[0x06]) { sub_n = NULL; - sect_n = NULL; break; } dmi_memory_channel_devices(sub_n, data[0x06], data + 0x07); sub_n = NULL; - - sect_n = NULL; break; case 38: /* 3.3.39 IPMI Device Information */ @@ -4894,12 +4633,7 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) * We use the word "Version" instead of "Revision", conforming to * the IPMI specification. */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "IPMIdeviceInformation", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.39"); - if(h->length < 0x10) { - sect_n = NULL; break; } @@ -4923,7 +4657,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) h->length < 0x12 ? 0 : (data[0x10] >> 5) & 1); if(h->length < 0x12) { - sect_n = NULL; break; } @@ -4948,17 +4681,10 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sub_n, "InterruptNumber", "%x", data[0x11]); } sub_n = NULL; - - sect_n = NULL; break; case 39: /* 3.3.40 System Power Supply */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "SystemPowerSupply", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.40"); - if(h->length < 0x10) { - sect_n = NULL; break; } @@ -4997,7 +4723,6 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) if(h->length < 0x16) { sub_n = NULL; - sect_n = NULL; break; } @@ -5014,31 +4739,24 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) } sub_n = NULL; - sect_n = NULL; break; case 40: /* 3.3.41 Additional Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "AdditionalInformation", NULL); - assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "subtype", "AdditionalInformation"); dmixml_AddAttribute(sect_n, "dmispec", "3.3.41"); if(h->length < 0x0B) { - sect_n = NULL; break; } dmi_additional_info(sect_n, h); - - sect_n = NULL; break; case 41: /* 3.3.42 Onboard Device Extended Information */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "OnboardDeviceExtendedInformation", NULL); - assert( sect_n != NULL ); + dmixml_AddAttribute(sect_n, "subtype", "OnboardDeviceExtendedInformation"); dmixml_AddAttribute(sect_n, "dmispec", "3.3.42"); if(h->length < 0x0B) { - sect_n = NULL; break; } @@ -5051,41 +4769,26 @@ void dmi_decode(xmlNode *handle_n, struct dmi_header * h, u16 ver) dmixml_AddAttribute(sub_n, "TypeInstance", "%ld", data[0x06]); dmi_slot_segment_bus_func(sub_n, WORD(data + 0x07), data[0x09], data[0x0A]); sub_n = NULL; - - sect_n = NULL; break; case 126: /* 3.3.43 Inactive */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "Inactive", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.43"); - - sect_n = NULL; - break; - case 127: /* 3.3.44 End Of Table */ - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "EndOfTable", NULL); - assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "dmispec", "3.3.44"); - sect_n = NULL; - break; default: if(dmi_decode_oem(h)) break; - sect_n = xmlNewChild(handle_n, NULL, (xmlChar *) "DMIdump", NULL); + sect_n = xmlNewChild(sect_n, NULL, (xmlChar *) "DMIdump", NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "Type", "%i", h->type); dmixml_AddAttribute(sect_n, "InfoType", "%s", h->type >= 128 ? "OEM-specific" : "Unknown"); dmi_dump(sect_n, h); - - sect_n = NULL; break; } + return sect_n; } void to_dmi_header(struct dmi_header *h, u8 * data) @@ -5326,13 +5029,6 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x * stop decoding at end of table marker */ - xmlNode *handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMIentry", NULL); - assert( handle_n != NULL ); - - dmixml_AddAttribute(handle_n, "handle", "0x%04x%c", h.handle); - dmixml_AddAttribute(handle_n, "type", "%d", h.type); - dmixml_AddAttribute(handle_n, "size", "%d", h.length); - /* assign vendor for vendor-specific decodes later */ if(h.type == 0 && h.length >= 5) { dmi_set_vendor(dmi_string(&h, data[0x04])); @@ -5345,6 +5041,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x } next += 2; + xmlNode *handle_n = NULL; if(display) { if(next - buf <= len) { /* TODO: ... @@ -5357,13 +5054,19 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); * } */ - dmi_decode(handle_n, &h, ver); + handle_n = dmi_decode(&h, ver); } else fprintf(stderr, ""); } else if(opt.string != NULL && opt.string->type == h.type) { - // <<<---- ** Need to handle this as well ** + handle_n = xmlNewNode(NULL, (xmlChar *) "DMItable"); + assert( handle_n != NULL ); dmi_table_string(&h, data, handle_n, ver); } + if( handle_n != NULL ) { + dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle); + dmixml_AddAttribute(handle_n, "size", "%d", h.length); + xmlAddChild(xmlnode, handle_n); + } data = next; i++; -- cgit From 8c5015cfd169bbec89974e57b04da3985425e6cd Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 14 Apr 2009 14:21:48 +0200 Subject: More XML cleanup --- src/dmidecode.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index c348380..1087df2 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -311,10 +311,10 @@ void dmi_bios_characteristics(xmlNode *node, u64 code) xmlNode *flags_n = xmlNewChild(node, NULL, (xmlChar *) "flags", NULL); assert( flags_n != NULL ); - for(i = 4; i <= 31; i++) - if( code.l & (1 << i) ) { - dmixml_AddTextChild(flags_n, "flag", characteristics[i - 3]); - } + for(i = 4; i <= 31; i++) { + xmlNode *flg_n = dmixml_AddTextChild(flags_n, "flag", characteristics[i - 3]); + dmixml_AddAttribute(flg_n, "enabled", "%i", (code.l & (1 << i) ? 1 : 0 )); + } } } @@ -337,9 +337,8 @@ void dmi_bios_characteristics_x1(xmlNode *node, u8 code) dmixml_AddAttribute(node, "flags", "0x%04x", code); for(i = 0; i <= 7; i++) { - if( code & (1 << i) ) { - dmixml_AddTextChild(node, "characteristic", characteristics[i]); - } + xmlNode *chr_n = dmixml_AddTextChild(node, "characteristic", characteristics[i]); + dmixml_AddAttribute(chr_n, "enabled", "%i", (code & (1 << i) ? 1: 0)); } } @@ -357,9 +356,8 @@ void dmi_bios_characteristics_x2(xmlNode *node, u8 code) dmixml_AddAttribute(node, "flags", "0x%04x", code); for(i = 0; i <= 2; i++) { - if( code & (1 << i) ) { - dmixml_AddTextChild(node, "characteristic", characteristics[i]); - } + xmlNode *chr_n = dmixml_AddTextChild(node, "characteristic", characteristics[i]); + dmixml_AddAttribute(chr_n, "enabled", "%i", (code & (1 << i) ? 1: 0)); } } @@ -3658,7 +3656,7 @@ xmlNode *dmi_decode(struct dmi_header * h, u16 ver) sect_n = xmlNewNode(NULL, (xmlChar *) dmiMajor->tagname); assert( sect_n != NULL ); - dmixml_AddAttribute(sect_n, "id", "%s", dmiMajor->id); + dmixml_AddAttribute(sect_n, "dmispec", "%s", dmiMajor->id); dmixml_AddAttribute(sect_n, "type", "%i", h->type); dmixml_AddTextChild(sect_n, "description", "%s", dmiMajor->desc); -- cgit From a3047723df9b66b6a56bcc72a469a129bbaf4d54 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 29 Apr 2009 18:28:02 +0200 Subject: dmidecode: Moved ROMsize size unit into tag attribute --- src/dmidecode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 1087df2..491183d 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3681,7 +3681,9 @@ xmlNode *dmi_decode(struct dmi_header * h, u16 ver) dmi_bios_runtime_size(sect_n, (0x10000 - WORD(data + 0x06)) << 4); } - dmixml_AddTextChild(sect_n, "ROMsize", "%i KB", (data[0x09] + 1) << 6); + sub_n = dmixml_AddTextChild(sect_n, "ROMsize", "%i", (data[0x09] + 1) << 6); + dmixml_AddAttribute(sub_n, "unit", "KB"); + sub_n = NULL; sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Characteristics", NULL); assert( sub_n != NULL ); -- cgit From 27b3d2281f4b7677e908ef2505bd649305b5ac78 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 30 Apr 2009 18:24:49 +0200 Subject: Began completing the rewrite of needed dmidecodemodule changes --- src/dmidecode.c | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 491183d..bdb0758 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3642,7 +3642,7 @@ void dmi_additional_info(xmlNode *node, const struct dmi_header *h) ** Main */ -xmlNode *dmi_decode(struct dmi_header * h, u16 ver) +xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) { const u8 *data = h->data; xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL; @@ -3652,8 +3652,7 @@ xmlNode *dmi_decode(struct dmi_header * h, u16 ver) //dmi_codes_major *dmiMajor = (dmi_codes_major *)&dmiCodesMajor[map_maj[h->type]]; dmi_codes_major *dmiMajor = (dmi_codes_major *) &dmiCodesMajor[h->type]; - - sect_n = xmlNewNode(NULL, (xmlChar *) dmiMajor->tagname); + sect_n = xmlNewChild(prnt_n, NULL, (xmlChar *) dmiMajor->tagname, NULL); assert( sect_n != NULL ); dmixml_AddAttribute(sect_n, "dmispec", "%s", dmiMajor->id); @@ -4799,45 +4798,50 @@ void to_dmi_header(struct dmi_header *h, u8 * data) h->data = data; } -void dmi_table_string(const struct dmi_header *h, const u8 *data, xmlNode *node, u16 ver) +xmlNode *dmi_table_string(xmlNode *prnt_n, const struct dmi_header *h, const u8 *data, u16 ver) { int key; u8 offset = opt.string->offset; - xmlNode *dmi_n = NULL; + xmlNode *handle_n = NULL, *dmi_n = NULL; if(offset >= h->length) - return; + return NULL; + + handle_n = xmlNewChild(prnt_n, NULL, (xmlChar *) "DMItable", NULL); + assert( handle_n != NULL ); //. TODO: These should have more meaningful dictionary names key = (opt.string->type << 8) | offset; switch (key) { case 0x108: - dmi_system_uuid(node, data + offset, ver); - dmixml_AddAttribute(node, "DMItype", "0x108"); + dmi_system_uuid(handle_n, data + offset, ver); + dmixml_AddAttribute(handle_n, "DMItype", "0x108"); break; case 0x305: - dmi_chassis_type(node, data[offset]); - dmixml_AddAttribute(node, "DMItype", "0x305"); + dmi_chassis_type(handle_n, data[offset]); + dmixml_AddAttribute(handle_n, "DMItype", "0x305"); // FIXME: Missing break? case 0x406: - dmi_processor_family(node, h); - dmixml_AddAttribute(node, "DMItype", "0x406"); + dmi_processor_family(handle_n, h); + dmixml_AddAttribute(handle_n, "DMItype", "0x406"); break; case 0x416: - dmi_n = dmixml_AddTextChild(node, "ProcessorFrequency", "%s", + dmi_n = dmixml_AddTextChild(handle_n, "ProcessorFrequency", "%s", dmi_processor_frequency((u8 *) data + offset)); dmixml_AddAttribute(dmi_n, "DMItype", "0x416"); dmi_n = NULL; break; default: - dmi_n = dmixml_AddTextChild(node, "Unknown", "%s", dmi_string(h, data[offset])); + dmi_n = dmixml_AddTextChild(handle_n, "Unknown", "%s", dmi_string(h, data[offset])); dmixml_AddAttribute(dmi_n, "DMItype", "0x%03x", key); } + + return handle_n; } /* @@ -5054,18 +5058,15 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); * } */ - handle_n = dmi_decode(&h, ver); + handle_n = dmi_decode(xmlnode, &h, ver); } else fprintf(stderr, ""); } else if(opt.string != NULL && opt.string->type == h.type) { - handle_n = xmlNewNode(NULL, (xmlChar *) "DMItable"); - assert( handle_n != NULL ); - dmi_table_string(&h, data, handle_n, ver); + handle_n = dmi_table_string(xmlnode, &h, data, ver); } if( handle_n != NULL ) { dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle); dmixml_AddAttribute(handle_n, "size", "%d", h.length); - xmlAddChild(xmlnode, handle_n); } data = next; @@ -5090,13 +5091,15 @@ int _smbios_decode_check(u8 * buf) return check; } -int smbios_decode_set_version(u8 * buf, const char *devmem, xmlNode *node) +xmlNode *smbios_decode_set_version(u8 * buf, const char *devmem) { int check = _smbios_decode_check(buf); - xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "SMBIOSversion", NULL); + xmlNode *data_n = xmlNewNode(NULL, (xmlChar *) "DMIversion"); assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "type", "SMBIOS"); + if(check == 1) { u16 ver = (buf[0x06] << 8) + buf[0x07]; @@ -5130,7 +5133,7 @@ int smbios_decode_set_version(u8 * buf, const char *devmem, xmlNode *node) dmixml_AddTextContent(data_n, "No SMBIOS nor DMI entry point found"); dmixml_AddAttribute(data_n, "unknown", "1"); } - return check; + return data_n; } int smbios_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) @@ -5166,13 +5169,15 @@ int _legacy_decode_check(u8 * buf) return check; } -int legacy_decode_set_version(u8 * buf, const char *devmem, xmlNode *node) +xmlNode *legacy_decode_set_version(u8 * buf, const char *devmem) { int check = _legacy_decode_check(buf); - xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "LegacyDMI", NULL); + xmlNode *data_n = xmlNewNode(NULL, (xmlChar *) "DMIversion"); assert( data_n != NULL ); + dmixml_AddAttribute(data_n, "type", "legacy"); + if(check == 1) { dmixml_AddTextContent(data_n, "Legacy DMI %i.%i present", buf[0x0E] >> 4, buf[0x0E] & 0x0F); @@ -5183,7 +5188,7 @@ int legacy_decode_set_version(u8 * buf, const char *devmem, xmlNode *node) dmixml_AddAttribute(data_n, "unknown", "1"); } - return check; + return data_n; } int legacy_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) -- cgit From baf01ef0ad9635e506171d66c0e7ffa8c8c45ae1 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 13 May 2009 11:22:47 +0200 Subject: Corrected minor errors in ProcessorInfo XML tags --- src/dmidecode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index bdb0758..bf7af1b 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1252,7 +1252,7 @@ void dmi_processor_cache(xmlNode *cache_n, u16 code, u16 ver) } else { dmixml_AddAttribute(cache_n, "provided", "1"); dmixml_AddAttribute(cache_n, "available", "1"); - dmixml_AddAttribute(cache_n, "Handle", "0x%04x", code); + dmixml_AddAttribute(cache_n, "handle", "0x%04x", code); } } @@ -3844,9 +3844,10 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) dmixml_AddTextChild(sub_n, "Vendor", dmi_string(h, data[0x07])); dmixml_AddTextChild(sub_n, "Version", dmi_string(h, data[0x10])); - dmi_processor_voltage(sub_n, data[0x11]); sub_n = NULL; + dmi_processor_voltage(sect_n, data[0x11]); + sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Frequencies", NULL); assert( sub_n != NULL ); -- cgit From 03bdcc92ff93e58a9befa5c9439b0cd656e57ccc Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 13 May 2009 11:44:15 +0200 Subject: Add all CPU flags, and mark them as available or not This is to preserve backwards compatibility --- src/dmidecode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index bf7af1b..4a14992 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1121,9 +1121,10 @@ xmlNode *dmi_processor_id(xmlNode *node, u8 type, const u8 * p, const char *vers int i; for(i = 0; i <= 31; i++) { - // Only add those flags which are present - if( (flags[i].flag != NULL) && (edx & (1 << i)) ) { + if( flags[i].flag != NULL ) { xmlNode *flg_n = dmixml_AddTextChild(flags_n, "flag", "%s", flags[i].descr); + dmixml_AddAttribute(flg_n, "available", "%i", + (edx & (1 << i) ? 1 : 0)); dmixml_AddAttribute(flg_n, "flag", "%s", flags[i].flag); } } @@ -3870,6 +3871,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) dmi_processor_status(sect_n, data[0x18] & 0x07); } else { dmixml_AddAttribute(sect_n, "populated", "0"); + dmi_processor_status(sect_n, data[0x18] & 0x07); } dmi_processor_upgrade(sect_n, data[0x19]); -- cgit From 40cd1a7ac2f912eb8be659a0c9dbadf5a0b22f14 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 13 May 2009 17:22:04 +0200 Subject: Mark CPU as Populated = 'No' when not present --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 4a14992..422287c 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3871,7 +3871,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) dmi_processor_status(sect_n, data[0x18] & 0x07); } else { dmixml_AddAttribute(sect_n, "populated", "0"); - dmi_processor_status(sect_n, data[0x18] & 0x07); + dmixml_AddTextChild(sect_n, "Populated", "No"); } dmi_processor_upgrade(sect_n, data[0x19]); -- cgit From fff6c8a1cd328ebce904b7fab4bdc642596a8ef5 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 14 May 2009 17:11:55 +0200 Subject: Remove 'ns' from the speed_ns attribute in memory section --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 422287c..da6b72b 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -2645,7 +2645,7 @@ void dmi_memory_device_speed(xmlNode *node, u16 code) if(code == 0) { dmixml_AddAttribute(data_n, "unkown", "1"); } else { - dmixml_AddAttribute(data_n, "speed_ns", "%.1f ns", (float) 1000 / code); + dmixml_AddAttribute(data_n, "speed_ns", "%.1f", (float) 1000 / code); dmixml_AddAttribute(data_n, "unit", "MHz"); dmixml_AddTextContent(data_n, "%i", code); } -- cgit From a8d6f0ee846d03d10c188080af69c10567887b56 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 15 May 2009 11:20:07 +0200 Subject: Fixed some errors in decoding "3.3.5.9 Processor Characteristics" Fixes regression in parsing introduced when rewriting dmidecode to use libxml2 --- src/dmidecode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index da6b72b..d0efb8e 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1261,8 +1261,7 @@ void dmi_processor_cache(xmlNode *cache_n, u16 code, u16 ver) void dmi_processor_characteristics(xmlNode *node, u16 code) { static const char *characteristics[] = { - NULL, - "Unknown" /* 1 */ + "Unknown", /* 1 */ "64-bit capable" /* 2 */ }; -- cgit From b694abeb522f93aa842d16720a3aa1f98ad2aa84 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 15 May 2009 11:55:25 +0200 Subject: Reorganised attributes in SystemSlots tag This part of the XML result was not valid due to duplicated tag attributes. Moved some of this specifications from the SystemSlots tag to its own SlotID tag, with even more details. --- src/dmidecode.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index d0efb8e..bb145b8 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1941,15 +1941,51 @@ void dmi_slot_length(xmlNode *node, u8 code) } /* 3.3.10.5 */ +void inline set_slottype(xmlNode *node, u8 type) { + switch (type) { + case 0x04: /* MCA */ + dmixml_AddAttribute(node, "slottype", "MCA"); + break; + case 0x05: /* EISA */ + dmixml_AddAttribute(node, "slottype", "EISA"); + break; + case 0x06: /* PCI */ + case 0x0E: /* PCI */ + dmixml_AddAttribute(node, "slottype", "PCI"); + break; + case 0x0F: /* AGP */ + case 0x10: /* AGP */ + case 0x11: /* AGP */ + case 0x13: /* AGP */ + dmixml_AddAttribute(node, "slottype", ""); + break; + case 0x12: /* PCI-X */ + dmixml_AddAttribute(node, "slottype", "PCI-X"); + break; + case 0xA5: /* PCI Express */ + dmixml_AddAttribute(node, "slottype", "PCI Express"); + break; + case 0x07: /* PCMCIA */ + dmixml_AddAttribute(node, "slottype", "PCMCIA"); + break; + default: + break; + } +} + void dmi_slot_id(xmlNode *node, u8 code1, u8 code2, u8 type) { - dmixml_AddAttribute(node, "dmispec", "3.3.10.5"); + xmlNode *slotid_n = xmlNewChild(node, NULL, (xmlChar *) "SlotID", NULL); + dmixml_AddAttribute(slotid_n, "dmispec", "3.3.10.5"); + dmixml_AddAttribute(slotid_n, "flags1", "0x%04x", code1); + dmixml_AddAttribute(slotid_n, "flags2", "0x%04x", code2); + dmixml_AddAttribute(slotid_n, "type", "0x%04x", type); switch (type) { case 0x04: /* MCA */ - dmixml_AddAttribute(node, "id", "%i", code1); + dmixml_AddAttribute(slotid_n, "id", "%i", code1); break; case 0x05: /* EISA */ - dmixml_AddAttribute(node, "id", "%i", code1); + dmixml_AddAttribute(slotid_n, "id", "%i", code1); break; case 0x06: /* PCI */ case 0x0E: /* PCI */ @@ -1959,15 +1995,16 @@ void dmi_slot_id(xmlNode *node, u8 code1, u8 code2, u8 type) case 0x12: /* PCI-X */ case 0x13: /* AGP */ case 0xA5: /* PCI Express */ - dmixml_AddAttribute(node, "id", "%i", code1); + dmixml_AddAttribute(slotid_n, "id", "%i", code1); break; case 0x07: /* PCMCIA */ - dmixml_AddAttribute(node, "adapter", "%i", code1); - dmixml_AddAttribute(node, "id", "%i", code2); + dmixml_AddAttribute(slotid_n, "adapter", "%i", code1); + dmixml_AddAttribute(slotid_n, "id", "%i", code2); break; default: break; } + set_slottype(slotid_n, type); } void dmi_slot_characteristics(xmlNode *node, u8 code1, u8 code2) -- cgit From b20e017f0b09e6f8946db04b0acef69e62fcf114 Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Wed, 20 May 2009 22:19:23 +1000 Subject: Fixed some ugly, unattractive and unhealthy code These hangover lines must have crept in at the early stages of the initial conversion of dmidecode to python-dmidecode. Fixed. --- src/dmidecode.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index bb145b8..37fb6a0 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3974,8 +3974,6 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) break; case 5: /* 3.3.6 Memory Controller Information */ - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0F) { break; } @@ -4019,8 +4017,6 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) break; case 6: /* 3.3.7 Memory Module Information */ - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0C) { break; } @@ -4036,8 +4032,6 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) break; case 7: /* 3.3.8 Cache Information */ - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0F) { break; } @@ -4070,8 +4064,6 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) break; case 8: /* 3.3.9 Port Connector Information */ - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x09) { break; } @@ -4093,8 +4085,6 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) break; case 9: /* 3.3.10 System Slots */ - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x0C) { break; } @@ -4119,8 +4109,6 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) break; case 11: /* 3.3.12 OEM Strings */ - dmi_on_board_devices(sect_n, "dmi_on_board_devices", h); - if(h->length < 0x05) { break; } -- cgit From 9f34b97089fe7fb14c6877cc426658c06f04cb9e Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 19 May 2009 11:56:41 +0200 Subject: Fixed some errors in the XML layout on CacheInfo --- src/dmidecode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 37fb6a0..e507689 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1566,7 +1566,7 @@ void dmi_cache_location(xmlNode *node, u8 code) void dmi_cache_size(xmlNode *node, const char *tagname, u16 code) { - xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "CacheLocation", NULL); + xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) tagname, NULL); assert( data_n != NULL ); dmixml_AddAttribute(data_n, "dmispec", "3.3.8"); dmixml_AddAttribute(data_n, "flags", "0x%04x", code); @@ -1603,8 +1603,8 @@ void dmi_cache_types(xmlNode *node, const char *tagname, u16 code) int i; for(i = 0; i <= 6; i++) { if(code & (1 << i)) { - xmlNode *n = dmixml_AddTextContent(data_n, "%s", types[i]); - dmixml_AddAttribute(n, "index", "%i", i); + xmlNode *n = dmixml_AddTextChild(data_n, "CacheType", "%s", types[i]); + dmixml_AddAttribute(n, "index", "%i", i+1); } } } -- cgit From 5900424cc4a3ba70b79a6f2c31cf2d738b4e0217 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 19 May 2009 16:39:10 +0200 Subject: Use correct index value for /dmidecode/SystemSlots/SlotCharacteristics/Characteristic/@index --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index e507689..6cee5cf 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -2051,7 +2051,7 @@ void dmi_slot_characteristics(xmlNode *node, u8 code1, u8 code2) if(code2 & (1 << i)) { xmlNode *c_n = dmixml_AddTextChild(data_n, "Characteristic", "%s", characteristics2[i]); - dmixml_AddAttribute(c_n, "index", "%i", i); + dmixml_AddAttribute(c_n, "index", "%i", i+8); c_n = NULL; } } -- cgit From ff36dbbc2804858ad7229e1b6bda51fc2250133d Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 19 May 2009 17:09:48 +0200 Subject: Changed the node content of /dmidecode/ProcessorInfo/CPUCore/cpu_flags/flag to maintain backwards compatibility The old python-dmidecode uses the format '{flag} ({description})'. This format is now used is well as contents for the cpu_flags/flag text nodes. --- src/dmidecode.c | 60 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 6cee5cf..7abec47 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -960,38 +960,38 @@ xmlNode *dmi_processor_id(xmlNode *node, u8 type, const u8 * p, const char *vers const char *descr; } flags[] = { /* *INDENT-OFF* */ - {"FPU", "Floating-point unit on-chip"}, /* 0 */ - {"VME", "Virtual mode extension"}, - {"DE", "Debugging extension"}, - {"PSE", "Page size extension"}, - {"TSC", "Time stamp counter"}, - {"MSR", "Model specific registers"}, - {"PAE", "Physical address extension"}, - {"MCE", "Machine check exception"}, - {"CX8", "CMPXCHG8 instruction supported"}, - {"APIC", "On-chip APIC hardware supported"}, + {"FPU", "FPU (Floating-point unit on-chip)"}, /* 0 */ + {"VME", "VME (Virtual mode extension)"}, + {"DE", "DE (Debugging extension)"}, + {"PSE", "PSE (Page size extension)"}, + {"TSC", "TSC (Time stamp counter)"}, + {"MSR", "MSR (Model specific registers)"}, + {"PAE", "PAE (Physical address extension)"}, + {"MCE", "MCE (Machine check exception)"}, + {"CX8", "CX8 (CMPXCHG8 instruction supported)"}, + {"APIC", "APIC (On-chip APIC hardware supported)"}, {NULL, NULL}, /* 10 */ - {"SEP", "Fast system call"}, - {"MTRR", "Memory type range registers"}, - {"PGE", "Page global enable"}, - {"MCA", "Machine check architecture"}, - {"CMOV", "Conditional move instruction supported"}, - {"PAT", "Page attribute table"}, - {"PSE-36", "36-bit page size extension"}, - {"PSN", "Processor serial number present and enabled"}, - {"CLFSH", "CLFLUSH instruction supported"}, + {"SEP", "SEP (Fast system call)"}, + {"MTRR", "MTRR (Memory type range registers)"}, + {"PGE", "PGE (Page global enable)"}, + {"MCA", "MCA (Machine check architecture)"}, + {"CMOV", "CMOV (Conditional move instruction supported)"}, + {"PAT", "PAT (Page attribute table)"}, + {"PSE-36", "PSE-36 (36-bit page size extension)"}, + {"PSN", "PSN (Processor serial number present and enabled)"}, + {"CLFSH", "CLFLUSH (CLFLUSH instruction supported)"}, {NULL, NULL }, /* 20 */ - {"DS", "Debug store"}, - {"ACPI", "ACPI supported"}, - {"MMX", "MMX technology supported"}, - {"FXSR", "Fast floating-point save and restore"}, - {"SSE", "Streaming SIMD extensions"}, - {"SSE2", "Streaming SIMD extensions 2"}, - {"SS", "Self-snoop"}, - {"HTT", "Hyper-threading technology"}, - {"TM", "Thermal monitor supported"}, - {"IA64", "IA64 capabilities"}, - {"PBE", "Pending break enabled"} /* 31 */ + {"DS", "DS (Debug store)"}, + {"ACPI", "ACPI (ACPI supported)"}, + {"MMX", "MMX (MMX technology supported)"}, + {"FXSR", "FXSR (Fast floating-point save and restore)"}, + {"SSE", "SSE (Streaming SIMD extensions)"}, + {"SSE2", "SSE2 (Streaming SIMD extensions 2)"}, + {"SS", "SS (Self-snoop)"}, + {"HTT", "HTT (Hyper-threading technology)"}, + {"TM", "TM (Thermal monitor supported)"}, + {"IA64", "IA64 (IA64 capabilities)"}, + {"PBE", "PBE (Pending break enabled)"} /* 31 */ /* *INDENT-ON* */ }; -- cgit From cd387fa3d1929505299d1df733fae890aacc75bc Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Thu, 21 May 2009 08:20:29 +1000 Subject: Update copyright notice --- src/dmidecode.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 7abec47..48f5df0 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -52,18 +52,15 @@ * http://www.intel.com/design/archives/wfm/downloads/bisspec.htm * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * DMI Decode Python Module (Extension) + * DMI Decode Python module & libxml2 (Extension) * - * Copyright: 2007-2008 Nima Talebi + * Copyright: 2007-2009 Nima Talebi + * Copyright: 2009 David Sommerseth * License: GPLv3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* -#undef NDEBUG -*/ - #include #include #include -- cgit From d06d776adb0fef9504bd7662760e4cd0971fb748 Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Fri, 22 May 2009 23:49:55 +1000 Subject: Reversioned, relicensed, and rejigged The version is of now, v3.10.6. The version major field has been upped due to the newly added XML functionality. The version has been reverted to GPLv2. Some headers have been cleaned up, copyright notices added etc. Credits given where due. --- src/dmidecode.c | 76 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 34 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 48f5df0..1f4dbd9 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1,32 +1,48 @@ +/*. ******* coding:utf-8 AUTOHEADER START v1.1 ******* + *. vim: fileencoding=utf-8 syntax=c sw=2 ts=2 et + *. + *. © 2007-2009 Nima Talebi + *. © 2009 David Sommerseth + *. © 2002-2008 Jean Delvare + *. © 2000-2002 Alan Cox + *. + *. This file is part of Python DMI-Decode. + *. + *. Python DMI-Decode is free software: you can redistribute it and/or modify + *. it under the terms of the GNU General Public License as published by + *. the Free Software Foundation, either version 2 of the License, or + *. (at your option) any later version. + *. + *. Python DMI-Decode is distributed in the hope that it will be useful, + *. but WITHOUT ANY WARRANTY; without even the implied warranty of + *. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *. GNU General Public License for more details. + *. + *. You should have received a copy of the GNU General Public License + *. along with Python DMI-Decode. If not, see . + *. + *. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + *. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + *. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + *. EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + *. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + *. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + *. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + *. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + *. OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + *. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *. + *. ADAPTED M. STONE & T. PARKER DISCLAIMER: THIS SOFTWARE COULD RESULT IN INJURY + *. AND/OR DEATH, AND AS SUCH, IT SHOULD NOT BE BUILT, INSTALLED OR USED BY ANYONE. + *. + *. $AutoHeaderSerial::20090522 $ + *. ******* AUTOHEADER END v1.1 ******* */ + /* - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DMI Decode * - * Copyright 2000-2002 Alan Cox - * Copyright 2002-2008 Jean Delvare - * Copyright 2009 David Sommerseth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For the avoidance of doubt the "preferred form" of this code is one which - * is in an open unpatent encumbered format. Where cryptographic key signing - * forms part of the process of creating an executable the information - * including keys needed to generate an equivalently functional executable - * are deemed to be part of the source code. - * * Unless specified otherwise, all references are aimed at the "System * Management BIOS Reference Specification, Version 2.6" document, * available from http://www.dmtf.org/standards/smbios/. @@ -51,14 +67,7 @@ * - BIOS Integrity Services Application Programming Interface version 1.0 * http://www.intel.com/design/archives/wfm/downloads/bisspec.htm * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * DMI Decode Python module & libxml2 (Extension) - * - * Copyright: 2007-2009 Nima Talebi - * Copyright: 2009 David Sommerseth - * License: GPLv3 - * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include @@ -81,7 +90,6 @@ #define EFI_NOT_FOUND (-1) #define EFI_NO_SMBIOS (-2) - /******************************************************************************* ** Type-independant Stuff */ -- cgit From 1bd60ee4c38615f2f1aac873d95cde0e6fae7b1e Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Sat, 23 May 2009 13:14:42 +1000 Subject: Fixed minor bug which prevented debug builds --- src/dmidecode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 1f4dbd9..9a0baa8 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3960,7 +3960,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "Cores", NULL); - assert( cores_n != NULL ); + assert( sub_n != NULL ); if(data[0x23] != 0) { dmixml_AddTextChild(sub_n, "CoreCount", "%i", data[0x23]); @@ -3984,7 +3984,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) } sub_n = xmlNewChild(sect_n, NULL, (xmlChar *) "ErrorCorrection", NULL); - assert( errc_n != NULL ); + assert( sub_n != NULL ); dmi_memory_controller_ed_method(sub_n, data[0x04]); dmi_memory_controller_ec_capabilities(sub_n, "Capabilities", data[0x05]); -- cgit From a18a72fab2a622077d5257003b09be30ab283339 Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Sat, 23 May 2009 14:37:01 +1000 Subject: More cleanup Don't write to stdout unless in debug mode (with respect to writing to memory devices. Added the xml datafile to setup (distutils). Updated test case (incorporating color and cleaning up tests). --- src/dmidecode.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 9a0baa8..de6fb2a 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -4931,7 +4931,9 @@ int dumpling(u8 * buf, const char *dumpfile, u8 mode) if((buff = mem_chunk(base, len, DEFAULT_MEM_DEV)) != NULL) { //. Part 1. +#ifdef NDEBUG printf("# Writing %d bytes to %s.\n", len, dumpfile); +#endif write_dump(32, len, buff, dumpfile, 0); free(buff); @@ -4941,14 +4943,18 @@ int dumpling(u8 * buf, const char *dumpfile, u8 mode) memcpy(crafted, buf, 32); overwrite_dmi_address(crafted + 0x10); +#ifdef NDEBUG printf("# Writing %d bytes to %s.\n", crafted[0x05], dumpfile); +#endif write_dump(0, crafted[0x05], crafted, dumpfile, 1); } else { u8 crafted[16]; memcpy(crafted, buf, 16); overwrite_dmi_address(crafted); +#ifdef NDEBUG printf("# Writing %d bytes to %s.\n", 0x0F, dumpfile); +#endif write_dump(0, 0x0F, crafted, dumpfile, 1); } } else { -- cgit From 788272fc9a0c027ecfec16ed3e746558cf988c92 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 3 Jun 2009 11:56:23 +0200 Subject: Renamed *_set_version() functions to a more proper *_get_version() function names Also changed dmiMAP_ParseMappingXML(...) to dmiMAP_ParseMappingXML_GroupName(...). In the dmidecode_get(...) function. This is just a quick fix for making it compile. It's also needed to implement usage of dmiMAP_ParseMappingXML_TypeID(...) as well. --- src/dmidecode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index de6fb2a..11dbd50 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -5129,7 +5129,7 @@ int _smbios_decode_check(u8 * buf) return check; } -xmlNode *smbios_decode_set_version(u8 * buf, const char *devmem) +xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem) { int check = _smbios_decode_check(buf); @@ -5207,7 +5207,7 @@ int _legacy_decode_check(u8 * buf) return check; } -xmlNode *legacy_decode_set_version(u8 * buf, const char *devmem) +xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem) { int check = _legacy_decode_check(buf); -- cgit From 62ae0e75016b31aa3062f296ed070e0610f0b98f Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 3 Jun 2009 15:22:23 +0200 Subject: Removed some dead code --- src/dmidecode.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 11dbd50..d2f340f 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -5004,7 +5004,6 @@ int dump(const char *dumpfile) free(buf); //. TODO: Exception - //dmiSetItem(pydata, "detect", "No SMBIOS nor DMI entry point found, sorry G."); if(!found) ret = -1; } -- cgit From a05daf8fde753404511e9f247ab4e9ac9a75bf1a Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 3 Jun 2009 20:40:47 +0200 Subject: Rewrote bigger parts to avoid global variables as much as possible --- src/dmidecode.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index d2f340f..4a978a9 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -201,7 +201,7 @@ static int dmi_bcd_range(u8 value, u8 low, u8 high) return 1; } -void dmi_dump(xmlNode *node, struct dmi_header * h) +void dmi_dump(options *opt, xmlNode *node, struct dmi_header * h) { int row, i; const char *s; @@ -234,7 +234,7 @@ void dmi_dump(xmlNode *node, struct dmi_header * h) while((s = dmi_string(h, i++)) != NULL) { //. FIXME: DUMP /* - * if(opt.flags & FLAG_DUMP) { + * if(opt->flags & FLAG_DUMP) { * int j, l = strlen(s)+1; * for(row=0; row<((l-1)>>4)+1; row++) { * for(j=0; j<16 && jdata; xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL; @@ -4816,7 +4816,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) dmixml_AddAttribute(sect_n, "Type", "%i", h->type); dmixml_AddAttribute(sect_n, "InfoType", "%s", h->type >= 128 ? "OEM-specific" : "Unknown"); - dmi_dump(sect_n, h); + dmi_dump(opt, sect_n, h); break; } return sect_n; @@ -4830,10 +4830,10 @@ void to_dmi_header(struct dmi_header *h, u8 * data) h->data = data; } -xmlNode *dmi_table_string(xmlNode *prnt_n, const struct dmi_header *h, const u8 *data, u16 ver) +xmlNode *dmi_table_string(options *opt, xmlNode *prnt_n, const struct dmi_header *h, const u8 *data, u16 ver) { int key; - u8 offset = opt.string->offset; + u8 offset = opt->string->offset; xmlNode *handle_n = NULL, *dmi_n = NULL; if(offset >= h->length) @@ -4843,7 +4843,7 @@ xmlNode *dmi_table_string(xmlNode *prnt_n, const struct dmi_header *h, const u8 assert( handle_n != NULL ); //. TODO: These should have more meaningful dictionary names - key = (opt.string->type << 8) | offset; + key = (opt->string->type << 8) | offset; switch (key) { case 0x108: @@ -4877,7 +4877,7 @@ xmlNode *dmi_table_string(xmlNode *prnt_n, const struct dmi_header *h, const u8 } /* -static void dmi_table_dump(u32 base, u16 len, const char *devmem) +static void dmi_table_dump(options *opt, u32 base, u16 len, const char *devmem) { u8 *buf; @@ -4887,8 +4887,8 @@ static void dmi_table_dump(u32 base, u16 len, const char *devmem) return; } - printf("# Writing %d bytes to %s.\n", len, PyString_AS_STRING(opt.dumpfile)); - write_dump(32, len, buf, PyString_AS_STRING(opt.dumpfile), 0); + printf("# Writing %d bytes to %s.\n", len, opt->dumpfile); + write_dump(32, len, buf, opt->dumpfile, 0); free(buf); } */ @@ -5011,13 +5011,13 @@ int dump(const char *dumpfile) return ret == 0 ? found : ret; } -static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) +static void dmi_table(options *opt, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) { u8 *buf; u8 *data; int i = 0; - if(opt.type == NULL) { + if(opt->type == NULL) { xmlNode *info_n = NULL; info_n = dmixml_AddTextChild(xmlnode, "DMIinfo", "%i structures occupying %i bytes", num, len); @@ -5025,7 +5025,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x dmixml_AddAttribute(info_n, "dmi_size", "%i", len); /* TODO DUMP - * if (!(opt.flags & FLAG_FROM_DUMP)) + * if (!(opt->flags & FLAG_FROM_DUMP)) * dmixml_AddAttribute(info_n, "dmi_table_base", "0x%08x", base); */ @@ -5050,9 +5050,9 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x int display; to_dmi_header(&h, data); - display = ((opt.type == NULL || opt.type[h.type]) + display = ((opt->type == NULL || opt->type[h.type]) // && !(h.type>39 && h.type<=127) - && !opt.string); + && !opt->string); /* ** If a short entry is found (less than 4 bytes), not only it @@ -5086,7 +5086,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x if(display) { if(next - buf <= len) { /* TODO: ... - * if(opt.flags & FLAG_DUMP) { + * if(opt->flags & FLAG_DUMP) { * PyDict_SetItem(hDict, PyString_FromString("lookup"), dmi_dump(&h)); * } else { * //. TODO: //. Is the value of `i' important?... @@ -5095,11 +5095,11 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, x * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); * } */ - handle_n = dmi_decode(xmlnode, &h, ver); + handle_n = dmi_decode(opt, xmlnode, &h, ver); } else fprintf(stderr, ""); - } else if(opt.string != NULL && opt.string->type == h.type) { - handle_n = dmi_table_string(xmlnode, &h, data, ver); + } else if(opt->string != NULL && opt->string->type == h.type) { + handle_n = dmi_table_string(opt, xmlnode, &h, data, ver); } if( handle_n != NULL ) { dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle); @@ -5173,7 +5173,7 @@ xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int smbios_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) +int smbios_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode) { int check = _smbios_decode_check(buf); @@ -5189,7 +5189,7 @@ int smbios_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) break; } //printf(">>%d @ %d, %d<<\n", DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C)); - dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, + dmi_table(opt, DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, xmlnode); } return check; @@ -5228,12 +5228,12 @@ xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int legacy_decode(u8 * buf, const char *devmem, xmlNode *xmlnode) +int legacy_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode) { int check = _legacy_decode_check(buf); if(check == 1) - dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), + dmi_table(opt, DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, xmlnode); return check; } -- cgit From 63e6c57e448d9dcc795cb14e89de6eb51f1033f6 Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Thu, 4 Jun 2009 09:49:56 +1000 Subject: Removal of more deprecated/unused code. --- src/dmidecode.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 4a978a9..8f2c545 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3691,7 +3691,6 @@ xmlNode *dmi_decode(options *opt, xmlNode *prnt_n, struct dmi_header * h, u16 ve //. 0xF1 --> 0xF100 //int minor = h->type<<8; - //dmi_codes_major *dmiMajor = (dmi_codes_major *)&dmiCodesMajor[map_maj[h->type]]; dmi_codes_major *dmiMajor = (dmi_codes_major *) &dmiCodesMajor[h->type]; sect_n = xmlNewChild(prnt_n, NULL, (xmlChar *) dmiMajor->tagname, NULL); -- cgit From adc4191973b177f557d9a851d558d09cde841efe Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 4 Jun 2009 15:21:21 +0200 Subject: Avoid passing the option struct to dmidecode.c functions --- src/dmidecode.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 8f2c545..974d6e3 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -201,7 +201,7 @@ static int dmi_bcd_range(u8 value, u8 low, u8 high) return 1; } -void dmi_dump(options *opt, xmlNode *node, struct dmi_header * h) +void dmi_dump(xmlNode *node, struct dmi_header * h) { int row, i; const char *s; @@ -234,6 +234,9 @@ void dmi_dump(options *opt, xmlNode *node, struct dmi_header * h) while((s = dmi_string(h, i++)) != NULL) { //. FIXME: DUMP /* + * opt->flags will need to be transported to the function somehow + * when this feature is implemented completely. + * * if(opt->flags & FLAG_DUMP) { * int j, l = strlen(s)+1; * for(row=0; row<((l-1)>>4)+1; row++) { @@ -3684,7 +3687,7 @@ void dmi_additional_info(xmlNode *node, const struct dmi_header *h) ** Main */ -xmlNode *dmi_decode(options *opt, xmlNode *prnt_n, struct dmi_header * h, u16 ver) +xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) { const u8 *data = h->data; xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL; @@ -4815,7 +4818,7 @@ xmlNode *dmi_decode(options *opt, xmlNode *prnt_n, struct dmi_header * h, u16 ve dmixml_AddAttribute(sect_n, "Type", "%i", h->type); dmixml_AddAttribute(sect_n, "InfoType", "%s", h->type >= 128 ? "OEM-specific" : "Unknown"); - dmi_dump(opt, sect_n, h); + dmi_dump(sect_n, h); break; } return sect_n; @@ -4829,10 +4832,11 @@ void to_dmi_header(struct dmi_header *h, u8 * data) h->data = data; } -xmlNode *dmi_table_string(options *opt, xmlNode *prnt_n, const struct dmi_header *h, const u8 *data, u16 ver) +xmlNode *dmi_table_string(const struct string_keyword *opt_string, xmlNode *prnt_n, + const struct dmi_header *h, const u8 *data, u16 ver) { int key; - u8 offset = opt->string->offset; + u8 offset = opt_string->offset; xmlNode *handle_n = NULL, *dmi_n = NULL; if(offset >= h->length) @@ -4842,7 +4846,7 @@ xmlNode *dmi_table_string(options *opt, xmlNode *prnt_n, const struct dmi_header assert( handle_n != NULL ); //. TODO: These should have more meaningful dictionary names - key = (opt->string->type << 8) | offset; + key = (opt_string->type << 8) | offset; switch (key) { case 0x108: @@ -5010,13 +5014,14 @@ int dump(const char *dumpfile) return ret == 0 ? found : ret; } -static void dmi_table(options *opt, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) +static void dmi_table(u8 *type, const struct string_keyword *opt_string, + u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) { u8 *buf; u8 *data; int i = 0; - if(opt->type == NULL) { + if(type == NULL) { xmlNode *info_n = NULL; info_n = dmixml_AddTextChild(xmlnode, "DMIinfo", "%i structures occupying %i bytes", num, len); @@ -5049,9 +5054,8 @@ static void dmi_table(options *opt, u32 base, u16 len, u16 num, u16 ver, const c int display; to_dmi_header(&h, data); - display = ((opt->type == NULL || opt->type[h.type]) - // && !(h.type>39 && h.type<=127) - && !opt->string); + display = ((type == NULL || type[h.type]) // FIXME: Is this check correct? + && !opt_string); /* ** If a short entry is found (less than 4 bytes), not only it @@ -5094,11 +5098,11 @@ static void dmi_table(options *opt, u32 base, u16 len, u16 num, u16 ver, const c * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); * } */ - handle_n = dmi_decode(opt, xmlnode, &h, ver); + handle_n = dmi_decode(xmlnode, &h, ver); } else fprintf(stderr, ""); - } else if(opt->string != NULL && opt->string->type == h.type) { - handle_n = dmi_table_string(opt, xmlnode, &h, data, ver); + } else if(opt_string != NULL && opt_string->type == h.type) { + handle_n = dmi_table_string(opt_string, xmlnode, &h, data, ver); } if( handle_n != NULL ) { dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle); @@ -5172,7 +5176,8 @@ xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int smbios_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode) +int smbios_decode(u8 *type, const struct string_keyword *opt_string, + u8 *buf, const char *devmem, xmlNode *xmlnode) { int check = _smbios_decode_check(buf); @@ -5188,7 +5193,7 @@ int smbios_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode) break; } //printf(">>%d @ %d, %d<<\n", DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C)); - dmi_table(opt, DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, + dmi_table(type, opt_string, DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, xmlnode); } return check; @@ -5227,12 +5232,13 @@ xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int legacy_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode) +int legacy_decode(u8 *type, const struct string_keyword *opt_string, + u8 *buf, const char *devmem, xmlNode *xmlnode) { int check = _legacy_decode_check(buf); if(check == 1) - dmi_table(opt, DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), + dmi_table(type, opt_string, DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, xmlnode); return check; } -- cgit From 2cf4f28f6fc671478003b31c03b93e070eee9942 Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Fri, 5 Jun 2009 01:42:07 +1000 Subject: Further removal of deprecated functions Removed the `dmi_table_string' function, and `const struct string_keyword *string' from the `options' struct. Also modified the function calls that are now free of this, namely, `legacy_decode' and `smbios_decode'. --- src/dmidecode.c | 65 ++++++--------------------------------------------------- 1 file changed, 6 insertions(+), 59 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 974d6e3..fbc151a 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -4832,53 +4832,6 @@ void to_dmi_header(struct dmi_header *h, u8 * data) h->data = data; } -xmlNode *dmi_table_string(const struct string_keyword *opt_string, xmlNode *prnt_n, - const struct dmi_header *h, const u8 *data, u16 ver) -{ - int key; - u8 offset = opt_string->offset; - xmlNode *handle_n = NULL, *dmi_n = NULL; - - if(offset >= h->length) - return NULL; - - handle_n = xmlNewChild(prnt_n, NULL, (xmlChar *) "DMItable", NULL); - assert( handle_n != NULL ); - - //. TODO: These should have more meaningful dictionary names - key = (opt_string->type << 8) | offset; - - switch (key) { - case 0x108: - dmi_system_uuid(handle_n, data + offset, ver); - dmixml_AddAttribute(handle_n, "DMItype", "0x108"); - break; - - case 0x305: - dmi_chassis_type(handle_n, data[offset]); - dmixml_AddAttribute(handle_n, "DMItype", "0x305"); - // FIXME: Missing break? - - case 0x406: - dmi_processor_family(handle_n, h); - dmixml_AddAttribute(handle_n, "DMItype", "0x406"); - break; - - case 0x416: - dmi_n = dmixml_AddTextChild(handle_n, "ProcessorFrequency", "%s", - dmi_processor_frequency((u8 *) data + offset)); - dmixml_AddAttribute(dmi_n, "DMItype", "0x416"); - dmi_n = NULL; - break; - - default: - dmi_n = dmixml_AddTextChild(handle_n, "Unknown", "%s", dmi_string(h, data[offset])); - dmixml_AddAttribute(dmi_n, "DMItype", "0x%03x", key); - } - - return handle_n; -} - /* static void dmi_table_dump(options *opt, u32 base, u16 len, const char *devmem) { @@ -5014,8 +4967,7 @@ int dump(const char *dumpfile) return ret == 0 ? found : ret; } -static void dmi_table(u8 *type, const struct string_keyword *opt_string, - u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) +static void dmi_table(u8 *type, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) { u8 *buf; u8 *data; @@ -5054,8 +5006,7 @@ static void dmi_table(u8 *type, const struct string_keyword *opt_string, int display; to_dmi_header(&h, data); - display = ((type == NULL || type[h.type]) // FIXME: Is this check correct? - && !opt_string); + display = (type == NULL || type[h.type]) // FIXME: Is this check correct? /* ** If a short entry is found (less than 4 bytes), not only it @@ -5101,8 +5052,6 @@ static void dmi_table(u8 *type, const struct string_keyword *opt_string, handle_n = dmi_decode(xmlnode, &h, ver); } else fprintf(stderr, ""); - } else if(opt_string != NULL && opt_string->type == h.type) { - handle_n = dmi_table_string(opt_string, xmlnode, &h, data, ver); } if( handle_n != NULL ) { dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle); @@ -5176,8 +5125,7 @@ xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int smbios_decode(u8 *type, const struct string_keyword *opt_string, - u8 *buf, const char *devmem, xmlNode *xmlnode) +int smbios_decode(u8 *type, u8 *buf, const char *devmem, xmlNode *xmlnode) { int check = _smbios_decode_check(buf); @@ -5193,7 +5141,7 @@ int smbios_decode(u8 *type, const struct string_keyword *opt_string, break; } //printf(">>%d @ %d, %d<<\n", DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C)); - dmi_table(type, opt_string, DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, + dmi_table(type, DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem, xmlnode); } return check; @@ -5232,13 +5180,12 @@ xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int legacy_decode(u8 *type, const struct string_keyword *opt_string, - u8 *buf, const char *devmem, xmlNode *xmlnode) +int legacy_decode(u8 *type, u8 *buf, const char *devmem, xmlNode *xmlnode) { int check = _legacy_decode_check(buf); if(check == 1) - dmi_table(type, opt_string, DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), + dmi_table(type, DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C), ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, xmlnode); return check; } -- cgit From 842f44f4efff348367ff9be5972def06d899b77b Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 4 Jun 2009 17:40:01 +0200 Subject: Fixed compiling issues after commit 2cf4f28f6fc671478003b31c03b93e070eee9942 Also cleaned up a little bit more, removed more unneeded stuff. --- src/dmidecode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index fbc151a..0f77e67 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -5003,10 +5003,8 @@ static void dmi_table(u8 *type, u32 base, u16 len, u16 num, u16 ver, const char u8 *next; struct dmi_header h; - int display; to_dmi_header(&h, data); - display = (type == NULL || type[h.type]) // FIXME: Is this check correct? /* ** If a short entry is found (less than 4 bytes), not only it @@ -5037,7 +5035,7 @@ static void dmi_table(u8 *type, u32 base, u16 len, u16 num, u16 ver, const char next += 2; xmlNode *handle_n = NULL; - if(display) { + if( type == NULL || type[h.type] ) { // FIXME: Is this check correct? if(next - buf <= len) { /* TODO: ... * if(opt->flags & FLAG_DUMP) { -- cgit From 2dce918111e8ef477942cd5ecf8340ddf39c1b5b Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 4 Jun 2009 17:59:23 +0200 Subject: More cleanup --- src/dmidecode.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 0f77e67..d55a697 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -4832,23 +4832,6 @@ void to_dmi_header(struct dmi_header *h, u8 * data) h->data = data; } -/* -static void dmi_table_dump(options *opt, u32 base, u16 len, const char *devmem) -{ - u8 *buf; - - if ((buf = mem_chunk(base, len, devmem)) == NULL) - { - fprintf(stderr, "Failed to read table, sorry.\n"); - return; - } - - printf("# Writing %d bytes to %s.\n", len, opt->dumpfile); - write_dump(32, len, buf, opt->dumpfile, 0); - free(buf); -} -*/ - /* * Build a crafted entry point with table address hard-coded to 32, * as this is where we will put it in the output file. We adjust the -- cgit From bfbac44bd8c0fcddcdcfade6a15313560c9cc6eb Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 9 Jun 2009 16:48:15 +0200 Subject: Big rewrite again, simplified the usage of opt->type Instead of building up an u8 array with 255 cells where we only use one cell at the time now, just pass the type id value as an int the whole way through. --- src/dmidecode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index d55a697..0fca9c9 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -90,6 +90,7 @@ #define EFI_NOT_FOUND (-1) #define EFI_NO_SMBIOS (-2) + /******************************************************************************* ** Type-independant Stuff */ @@ -4950,13 +4951,13 @@ int dump(const char *dumpfile) return ret == 0 ? found : ret; } -static void dmi_table(u8 *type, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) +static void dmi_table(int type, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) { u8 *buf; u8 *data; int i = 0; - if(type == NULL) { + if( type == -1 ) { xmlNode *info_n = NULL; info_n = dmixml_AddTextChild(xmlnode, "DMIinfo", "%i structures occupying %i bytes", num, len); @@ -5018,7 +5019,7 @@ static void dmi_table(u8 *type, u32 base, u16 len, u16 num, u16 ver, const char next += 2; xmlNode *handle_n = NULL; - if( type == NULL || type[h.type] ) { // FIXME: Is this check correct? + if( h.type == type ) { if(next - buf <= len) { /* TODO: ... * if(opt->flags & FLAG_DUMP) { @@ -5106,7 +5107,7 @@ xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int smbios_decode(u8 *type, u8 *buf, const char *devmem, xmlNode *xmlnode) +int smbios_decode(int type, u8 *buf, const char *devmem, xmlNode *xmlnode) { int check = _smbios_decode_check(buf); @@ -5161,7 +5162,7 @@ xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem) return data_n; } -int legacy_decode(u8 *type, u8 *buf, const char *devmem, xmlNode *xmlnode) +int legacy_decode(int type, u8 *buf, const char *devmem, xmlNode *xmlnode) { int check = _legacy_decode_check(buf); -- cgit From b3f5e9f97e283f2f23f36251b971458f805c6893 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 11 Jun 2009 09:50:31 +0200 Subject: Fixed error in XML data for dmi_temperature_probe_location(...) --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 0fca9c9..f819adf 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3266,7 +3266,7 @@ void dmi_temperature_probe_location(xmlNode *node, u8 code) dmixml_AddAttribute(data_n, "flags", "0x%04x", code); if(code >= 0x01 && code <= 0x0F) { - dmixml_AddTextChild(node, "%s", location[code - 0x01]); + dmixml_AddTextContent(data_n, "%s", location[code - 0x01]); } else { dmixml_AddAttribute(data_n, "outofspec", "1"); } -- cgit From 9864a51dafd953c497210b6f11e49bb299080dc8 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 11 Jun 2009 10:50:31 +0200 Subject: Fixed crashes and unexpected behaviour on unknown DMI/SMBIOS types Also provide more useful information, both on unsupported types and types not found on the hardware --- src/dmidecode.c | 65 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 18 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index f819adf..63b8040 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3688,15 +3688,13 @@ void dmi_additional_info(xmlNode *node, const struct dmi_header *h) ** Main */ -xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) +xmlNode *dmi_decode(xmlNode *prnt_n, dmi_codes_major *dmiMajor, struct dmi_header * h, u16 ver) { const u8 *data = h->data; xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL; //. 0xF1 --> 0xF100 //int minor = h->type<<8; - dmi_codes_major *dmiMajor = (dmi_codes_major *) &dmiCodesMajor[h->type]; - sect_n = xmlNewChild(prnt_n, NULL, (xmlChar *) dmiMajor->tagname, NULL); assert( sect_n != NULL ); @@ -4942,20 +4940,33 @@ int dump(const char *dumpfile) if(ret == 0) { free(buf); - - //. TODO: Exception - if(!found) + if(!found) { ret = -1; + } } return ret == 0 ? found : ret; } + +dmi_codes_major *find_dmiMajor(const struct dmi_header *h) +{ + int i = 0; + + for( i = 0; dmiCodesMajor[i].id != NULL; i++ ) { + if( h->type == dmiCodesMajor[i].code ) { + return (dmi_codes_major *)&dmiCodesMajor[i]; + } + } + return NULL; +} + static void dmi_table(int type, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) { u8 *buf; u8 *data; int i = 0; + int decoding_done = 0; if( type == -1 ) { xmlNode *info_n = NULL; @@ -5021,29 +5032,47 @@ static void dmi_table(int type, u32 base, u16 len, u16 num, u16 ver, const char xmlNode *handle_n = NULL; if( h.type == type ) { if(next - buf <= len) { + dmi_codes_major *dmiMajor = NULL; /* TODO: ... * if(opt->flags & FLAG_DUMP) { * PyDict_SetItem(hDict, PyString_FromString("lookup"), dmi_dump(&h)); - * } else { - * //. TODO: //. Is the value of `i' important?... - * //. TODO: PyDict_SetItem(hDict, PyInt_FromLong(i), dmi_decode(&h, ver)); - * //. TODO: ...removed and replaced with `data'... - * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); - * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); * } */ - handle_n = dmi_decode(xmlnode, &h, ver); - } else - fprintf(stderr, ""); - } - if( handle_n != NULL ) { + + dmiMajor = find_dmiMajor(&h); + if( dmiMajor != NULL ) { + handle_n = dmi_decode(xmlnode, dmiMajor, &h, ver); + } else { + handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMImessage", NULL); + assert( handle_n != NULL ); + dmixml_AddTextContent(handle_n, "DMI/SMBIOS type 0x%02X is not supported " + "by dmidecode", h.type); + dmixml_AddAttribute(handle_n, "type", "%i", h.type); + dmixml_AddAttribute(handle_n, "unsupported", "1"); + } + } else { + handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMIerror", NULL); + assert( handle_n != NULL ); + dmixml_AddTextContent(handle_n, "Data is truncated"); + dmixml_AddAttribute(handle_n, "type", "%i", h.type); + dmixml_AddAttribute(handle_n, "truncated", "1"); + } dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle); dmixml_AddAttribute(handle_n, "size", "%d", h.length); + decoding_done = 1; } - data = next; i++; } + if( decoding_done == 0 ) { + xmlNode *handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMImessage", NULL); + assert( handle_n != NULL ); + dmixml_AddTextContent(handle_n, "DMI/SMBIOS type 0x%02X is not found on this hardware", + type); + dmixml_AddAttribute(handle_n, "type", "%i", type); + dmixml_AddAttribute(handle_n, "notfound", "1"); + } + if(i != num) fprintf(stderr, "Wrong DMI structures count: %d announced, only %d decoded.\n", num, i); -- cgit From ad581a625904993404878b06804106fe5d8caf67 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 11 Jun 2009 11:01:55 +0200 Subject: Renamed to to avoid confusion with the tag --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 63b8040..3900770 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3700,7 +3700,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, dmi_codes_major *dmiMajor, struct dmi_heade dmixml_AddAttribute(sect_n, "dmispec", "%s", dmiMajor->id); dmixml_AddAttribute(sect_n, "type", "%i", h->type); - dmixml_AddTextChild(sect_n, "description", "%s", dmiMajor->desc); + dmixml_AddTextChild(sect_n, "DMIdescription", "%s", dmiMajor->desc); switch (h->type) { case 0: /* 3.3.1 BIOS Information */ -- cgit From d3e1e163a21a55ca8f3daf1d4eb0549851b28361 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 11 Jun 2009 18:56:10 +0200 Subject: Fixed an XML formatting issue - dmispec attribute was duplicated in --- src/dmidecode.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 3900770..e5e4a4b 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -2140,7 +2140,6 @@ void dmi_oem_strings(xmlNode *node, struct dmi_header *h) u8 count = p[0x00]; int i; - dmixml_AddAttribute(node, "dmispec", "3.3.12"); dmixml_AddAttribute(node, "count", "%i", count); for(i = 1; i <= count; i++) { -- cgit From 27f81037d82585b29ed09db2f6d7ed1e30db7dd1 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 12 Jun 2009 18:10:44 +0200 Subject: Fixed another XML formatting error in dmidecode.c --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index e5e4a4b..003e9ff 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -4336,7 +4336,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, dmi_codes_major *dmiMajor, struct dmi_heade dmi_pointing_device_type(sect_n, data[0x04]); dmi_pointing_device_interface(sect_n, data[0x05]); - dmixml_AddTextContent(sect_n, "Buttons", "%i", data[0x06]); + dmixml_AddTextChild(sect_n, "Buttons", "%i", data[0x06]); break; case 22: /* 3.3.23 Portable Battery */ -- cgit From 3849ca0a4abf5eb661758e1341a6e595d3013c2c Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 18 Jun 2009 14:53:29 +0200 Subject: Splitted out SMBIOS/DMI dump functions from dmidecode.c to separate files --- src/dmidecode.c | 164 +------------------------------------------------------- 1 file changed, 2 insertions(+), 162 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 003e9ff..9a35ecb 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -84,13 +84,11 @@ #include "dmixml.h" #include "dmidecode.h" #include "dmioem.h" +#include "efi.h" +#include "dmidump.h" #include "dmihelper.h" -#define EFI_NOT_FOUND (-1) -#define EFI_NO_SMBIOS (-2) - - /******************************************************************************* ** Type-independant Stuff */ @@ -4830,123 +4828,6 @@ void to_dmi_header(struct dmi_header *h, u8 * data) h->data = data; } -/* - * Build a crafted entry point with table address hard-coded to 32, - * as this is where we will put it in the output file. We adjust the - * DMI checksum appropriately. The SMBIOS checksum needs no adjustment. - */ -static void overwrite_dmi_address(u8 * buf) -{ - buf[0x05] += buf[0x08] + buf[0x09] + buf[0x0A] + buf[0x0B] - 32; - buf[0x08] = 32; - buf[0x09] = 0; - buf[0x0A] = 0; - buf[0x0B] = 0; -} - -#define NON_LEGACY 0 -#define LEGACY 1 -int dumpling(u8 * buf, const char *dumpfile, u8 mode) -{ - u32 base; - u16 len; - - if(mode == NON_LEGACY) { - if(!checksum(buf, buf[0x05]) || !memcmp(buf + 0x10, "_DMI_", 5) == 0 || - !checksum(buf + 0x10, 0x0F)) - return 0; - base = DWORD(buf + 0x18); - len = WORD(buf + 0x16); - } else { - if(!checksum(buf, 0x0F)) - return 0; - base = DWORD(buf + 0x08); - len = WORD(buf + 0x06); - } - - u8 *buff; - - if((buff = mem_chunk(base, len, DEFAULT_MEM_DEV)) != NULL) { - //. Part 1. -#ifdef NDEBUG - printf("# Writing %d bytes to %s.\n", len, dumpfile); -#endif - write_dump(32, len, buff, dumpfile, 0); - free(buff); - - //. Part 2. - if(mode != LEGACY) { - u8 crafted[32]; - - memcpy(crafted, buf, 32); - overwrite_dmi_address(crafted + 0x10); -#ifdef NDEBUG - printf("# Writing %d bytes to %s.\n", crafted[0x05], dumpfile); -#endif - write_dump(0, crafted[0x05], crafted, dumpfile, 1); - } else { - u8 crafted[16]; - - memcpy(crafted, buf, 16); - overwrite_dmi_address(crafted); -#ifdef NDEBUG - printf("# Writing %d bytes to %s.\n", 0x0F, dumpfile); -#endif - write_dump(0, 0x0F, crafted, dumpfile, 1); - } - } else { - fprintf(stderr, "Failed to read table, sorry.\n"); - } - - //. TODO: Cleanup - return 1; -} - -int dump(const char *dumpfile) -{ - /* On success, return found, otherwise return -1 */ - int ret = 0; - int found = 0; - size_t fp; - int efi; - u8 *buf; - - /* First try EFI (ia64, Intel-based Mac) */ - efi = address_from_efi(&fp); - if(efi == EFI_NOT_FOUND) { - /* Fallback to memory scan (x86, x86_64) */ - if((buf = mem_chunk(0xF0000, 0x10000, DEFAULT_MEM_DEV)) != NULL) { - for(fp = 0; fp <= 0xFFF0; fp += 16) { - if(memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) { - if(dumpling(buf + fp, dumpfile, NON_LEGACY)) - found++; - fp += 16; - } else if(memcmp(buf + fp, "_DMI_", 5) == 0) { - if(dumpling(buf + fp, dumpfile, LEGACY)) - found++; - } - } - } else - ret = -1; - } else if(efi == EFI_NO_SMBIOS) { - ret = -1; - } else { - if((buf = mem_chunk(fp, 0x20, DEFAULT_MEM_DEV)) == NULL) - ret = -1; - else if(dumpling(buf, dumpfile, NON_LEGACY)) - found++; - } - - if(ret == 0) { - free(buf); - if(!found) { - ret = -1; - } - } - - return ret == 0 ? found : ret; -} - dmi_codes_major *find_dmiMajor(const struct dmi_header *h) { @@ -5200,44 +5081,3 @@ int legacy_decode(int type, u8 *buf, const char *devmem, xmlNode *xmlnode) return check; } -/******************************************************************************* -** Probe for EFI interface -*/ -int address_from_efi(size_t * address) -{ - FILE *efi_systab; - const char *filename; - char linebuf[64]; - int ret; - - *address = 0; /* Prevent compiler warning */ - - /* - ** Linux <= 2.6.6: /proc/efi/systab - ** Linux >= 2.6.7: /sys/firmware/efi/systab - */ - if((efi_systab = fopen(filename = "/sys/firmware/efi/systab", "r")) == NULL - && (efi_systab = fopen(filename = "/proc/efi/systab", "r")) == NULL) { - /* No EFI interface, fallback to memory scan */ - return EFI_NOT_FOUND; - } - ret = EFI_NO_SMBIOS; - while((fgets(linebuf, sizeof(linebuf) - 1, efi_systab)) != NULL) { - char *addrp = strchr(linebuf, '='); - - *(addrp++) = '\0'; - if(strcmp(linebuf, "SMBIOS") == 0) { - *address = strtoul(addrp, NULL, 0); - printf("# SMBIOS entry point at 0x%08lx\n", (unsigned long)*address); - ret = 0; - break; - } - } - if(fclose(efi_systab) != 0) - perror(filename); - - if(ret == EFI_NO_SMBIOS) - fprintf(stderr, "%s: SMBIOS entry point missing\n", filename); - - return ret; -} -- cgit From 6bd9742784fb487463449e41330cdd102e0a5df1 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 2 Jul 2009 17:10:30 +0200 Subject: Completed python XML map for TypeMap 0x05 --- src/dmidecode.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 9a35ecb..41f882c 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1160,10 +1160,11 @@ void dmi_processor_voltage(xmlNode *node, u8 code) dmixml_AddAttribute(vltg_n, "unknown_value", "1"); } else { for(i = 0; i <= 2; i++) { - if( code & (1 << i) ) { - xmlNode *v_n = dmixml_AddTextChild(vltg_n, "Voltage", "%s", voltage[i]); - dmixml_AddAttribute(v_n, "unit", "V"); - } + xmlNode *v_n = dmixml_AddTextChild(vltg_n, "Voltage", "%s", voltage[i]); + dmixml_AddAttribute(v_n, "key_compound", "%s V", voltage[i]); + dmixml_AddAttribute(v_n, "available", "%i", (code & (1 << i) ? 1 : 0)); + dmixml_AddAttribute(v_n, "unit", "V"); + v_n = NULL; } } } @@ -1340,7 +1341,7 @@ void dmi_memory_controller_ec_capabilities(xmlNode *node, const char *tagname, u if(code & (1 << i)) { xmlNode *c_n = dmixml_AddTextChild(cap_n, "Capability", "%s", capabilities[i]); assert( c_n != NULL ); - dmixml_AddAttribute(c_n, "index", "%i", i); + dmixml_AddAttribute(c_n, "index", "%i", i+1); } } } @@ -1411,7 +1412,7 @@ void dmi_memory_controller_slots(xmlNode *node, u8 count, const u8 * p) assert( mslts_n != NULL ); for(i = 0; i < count; i++) { - xmlNode *sl_n = dmixml_AddTextChild(mslts_n, "Slot", "0x%04x:", WORD(p + sizeof(u16) * i)); + xmlNode *sl_n = dmixml_AddTextChild(mslts_n, "Slot", "0x%x:", WORD(p + sizeof(u16) * i)); dmixml_AddAttribute(sl_n, "index", "%i", i); } } @@ -1448,7 +1449,7 @@ void dmi_memory_module_types(xmlNode *node, const char *tagname, u16 code) if(code & (1 << i)) { xmlNode *mt_n = dmixml_AddTextChild(mmt_n, "ModuleType", types[i]); assert( mt_n != NULL ); - dmixml_AddAttribute(mt_n, "index", "%i", i); + dmixml_AddAttribute(mt_n, "index", "%i", i+1); } } } -- cgit From fd0d07610740a4899461daa1a3ea2cf8dd5ef7bb Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 2 Jul 2009 17:47:48 +0200 Subject: Completed python XML map for TypeMap 0x06 --- src/dmidecode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 41f882c..33730c3 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -1464,10 +1464,10 @@ void dmi_memory_module_connections(xmlNode *node, u8 code) if(code != 0xFF) { if((code & 0xF0) != 0xF0) { - dmixml_AddTextContent(data_n, "%ld", (code >> 4)); + dmixml_AddTextChild(data_n, "Connection", "%ld", (code >> 4)); } if((code & 0x0F) != 0x0F) { - dmixml_AddTextContent(data_n, "%ld", (code & 0x0F)); + dmixml_AddTextChild(data_n, "Connection", "%ld", (code & 0x0F)); } } } -- cgit From 7663721800f7428aafad5ee6072763f05c7c0fde Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 2 Jul 2009 19:06:35 +0200 Subject: Completed python XML map for TypeMap 0x16 --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index 33730c3..d4d8e9a 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -4383,7 +4383,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, dmi_codes_major *dmiMajor, struct dmi_heade dmixml_AddTextChild(sect_n, "SBDSchemistry", "%s", dmi_string(h, data[0x14])); } - dmixml_AddTextChild(sect_n, "OEMinformation", "%s", "0x%08x", DWORD(data + 0x16)); + dmixml_AddTextChild(sect_n, "OEMinformation", "0x%08x", DWORD(data + 0x16)); break; case 23: /* 3.3.24 System Reset */ -- cgit From 4331297215914119a225a8501300c200d700cd3f Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 2 Jul 2009 19:38:26 +0200 Subject: Completed python XML map for TypeMap 0x1C --- src/dmidecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmidecode.c') diff --git a/src/dmidecode.c b/src/dmidecode.c index d4d8e9a..aa2332d 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3294,7 +3294,7 @@ void dmi_temperature_probe_resolution(xmlNode *node, u16 code) dmixml_AddAttribute(data_n, "unknown", "1"); } else { dmixml_AddAttribute(data_n, "unit", "C"); - dmixml_AddTextContent(data_n, "%.3f deg C", (float)code / 1000); + dmixml_AddTextContent(data_n, "%.3f", (float)code / 1000); } } -- cgit