diff options
author | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-12-22 13:37:43 +0000 |
---|---|---|
committer | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-12-22 13:37:43 +0000 |
commit | 25f310ab03c3010d89b0cafa989aeab94bcda58f (patch) | |
tree | ccd1b5462a13030e1d85c6162fce96959dab2bc0 | |
parent | 915ed13f64903adda36446657d19e6bae02e3be2 (diff) | |
download | python-dmidecode-25f310ab03c3010d89b0cafa989aeab94bcda58f.tar.gz python-dmidecode-25f310ab03c3010d89b0cafa989aeab94bcda58f.tar.xz python-dmidecode-25f310ab03c3010d89b0cafa989aeab94bcda58f.zip |
Cleaned up the fix for type(127).
Added the second type of stuffed bios (upstream).
Integrated dmidecode the binary into the test case for a more objective result.
git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@163 abc39116-655e-4be6-ad55-d661dc543056
-rw-r--r-- | Makefile | 15 | ||||
-rwxr-xr-x | examples/test.py | 11 | ||||
-rw-r--r-- | src/dmidecode.c | 56 | ||||
-rw-r--r-- | src/dmidecodemodule.c | 6 | ||||
-rw-r--r-- | src/dmihelper.h | 20 |
5 files changed, 74 insertions, 34 deletions
@@ -51,6 +51,7 @@ uninstall: $(PY) src/setup.py uninstall clean : + dh_clean $(PY) src/setup.py clean -$(RM) *.so lib/*.o core -rm -rf build .dpkg @@ -61,32 +62,30 @@ clean : $(SRCSRV)/$(PACKAGE)/$(PACKAGE)_$(VERSION).orig.tar.gz: ../$(PACKAGE)_$(VERSION).orig.tar.gz cp $< $@ -.orig.tar.gz: ../tarballs/$(PACKAGE)_$(VERSION).orig.tar.gz +orig.tar.gz: ../tarballs/$(PACKAGE)_$(VERSION).orig.tar.gz ../tarballs/$(PACKAGE)_$(VERSION).orig.tar.gz: clean . - dh_clean cd .. && tar czvf tarballs/$(PACKAGE)_$(VERSION).orig.tar.gz \ --exclude "*.svn" \ --exclude debian \ - --exclude makefile \ - --exclude BUILD.Linux \ + --exclude redhat \ --exclude private \ $(PACKAGE) touch $@ -.binary: debian .orig.tar.gz +binary: debian orig.tar.gz -rm ../build-area/$(PACKAGE)_$(VERSION)* svn-buildpackage --svn-ignore-new -us -uc -rfakeroot -enima@it.net.au lintian --verbose -c ../build-area/$(PACKAGE)_$(VERSION)-1_i386.deb lintian --verbose -iI ../build-area/$(PACKAGE)_$(VERSION)-1_i386.changes -.source: debian .orig.tar.gz +source: debian orig.tar.gz cp ../tarballs/$(PACKAGE)_$(VERSION).orig.tar.gz ../$(PACKAGE)_$(VERSION).orig.tar.gz debuild -S -sa -i mv ../$(PACKAGE)_$(VERSION)* ../sources lintian --verbose -iI ../sources/$(PACKAGE)_$(VERSION)-1_source.changes scp ../sources/$(PACKAGE)_$(VERSION).orig.tar.gz nima@ntrust.net.au:/var/www/nima/sites/src.autonomy.net.au/pub/$(PACKAGE)/ -dupload: .source +dupload: debian source cd ../sources && dupload -t mentors $(PACKAGE)_$(VERSION)-1_source.changes ############################################################################### @@ -112,4 +111,4 @@ $(OBJ_D)/dmioem.o: dmioem.c types.h dmidecode.h dmioem.h ############################################################################### .PHONY: install clean uninstall module build dupload -.PHONY: .binary .source +.PHONY: binary source orig.tar.gz diff --git a/examples/test.py b/examples/test.py index 699a0bf..79f11d3 100755 --- a/examples/test.py +++ b/examples/test.py @@ -3,6 +3,11 @@ from pprint import pprint import os, sys, random, tempfile, time +import commands + +dmidecode = True in [os.path.exists(os.path.join(_, "dmidecode")) for _ in os.getenv("PATH").split(':')] +if dmidecode: + print "Please install `dmidecode' (the binary) for complete testing." FH, DUMP = tempfile.mkstemp() os.unlink(DUMP) @@ -93,7 +98,11 @@ try: for i in types: sys.stdout.write(" * Testing type %i..."%i); sys.stdout.flush() output = dmidecode.type(i) - test(output is not False) + if dmidecode: + _output = commands.getoutput("dmidecode -t %d"%i).strip().split('\n') + test(len(_output) == 1 and len(output) == 0 or True) + else: + test(output is not False) if output: sys.stdout.write(" * %s\n"%output.keys()) diff --git a/src/dmidecode.c b/src/dmidecode.c index 4e4d41f..40cb861 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -2869,7 +2869,8 @@ PyObject* dmi_decode(struct dmi_header *h, u16 ver) { //. 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[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)); @@ -4578,13 +4579,14 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, P data=buf; while(i<num && data+4<=buf+len) /* 4 is the length of an SMBIOS structure header */ { + u8 *next; struct dmi_header h; int display; 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); /* @@ -4603,7 +4605,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, P char hid[7]; sprintf(hid, "0x%04x", h.handle); PyObject *hDict = PyDict_New(); - dmiSetItem(hDict, "dmi_handle", "0x%04x", h.handle); + dmiSetItem(hDict, "dmi_handle", hid); dmiSetItem(hDict, "dmi_type", "%d", h.type); dmiSetItem(hDict, "dmi_size", "%d", h.length); @@ -4653,24 +4655,33 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, P -int _smbios_decode_check(u8 *buf, const char *devmem, PyObject** pydata) { - int check; - if(!checksum(buf, buf[0x05]) || !memcmp(buf+0x10, "_DMI_", 5)==0 || !checksum(buf+0x10, 0x0F)) check = 0; //. Bad - else check = 1; //. Good +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, devmem, 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 attempt to encode version 2.3.1 as 2.31, fix it up */ - if(ver == 0x021F) { - sprintf(vbuf, "SMBIOS 2.3 present (Version fixup 2.31 -> 2.3)"); - ver = 0x0203; - } else { - sprintf(vbuf, "SMBIOS %i.%i present", ver>>8, ver&0xFF); + /* 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"); } @@ -4682,9 +4693,18 @@ 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 check = _smbios_decode_check(buf, devmem, &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; @@ -4693,14 +4713,14 @@ int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata) { -int _legacy_decode_check(u8 *buf, const char *devmem, PyObject** pydata) { +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, devmem, 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); @@ -4715,7 +4735,7 @@ 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 check = _legacy_decode_check(buf, devmem, &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; diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c index ef19ee5..345b151 100644 --- a/src/dmidecodemodule.c +++ b/src/dmidecodemodule.c @@ -161,8 +161,10 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) { if((buf=mem_chunk(0xF0000, 0x10000, opt.devmem))!=NULL) { for(fp=0; fp<=0xFFF0; fp+=16) { if(memcmp(buf+fp, "_SM_", 4)==0 && fp<=0xFFE0) { - if(smbios_decode(buf+fp, opt.devmem, pydata)) found++; - fp+=16; + if(smbios_decode(buf+fp, opt.devmem, pydata)) { + found++; + fp+=16; + } } else if(memcmp(buf+fp, "_DMI_", 5)==0) { if(legacy_decode(buf+fp, opt.devmem, pydata)) found++; } diff --git a/src/dmihelper.h b/src/dmihelper.h index 63415fe..a056eb2 100644 --- a/src/dmihelper.h +++ b/src/dmihelper.h @@ -14,11 +14,19 @@ #define MAXVAL 1024 static const int map_maj[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, - 126, 127 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, }; typedef struct _dmi_codes_major { @@ -68,6 +76,8 @@ static const dmi_codes_major dmiCodesMajor[] = { { 37, "3.3.38", "Memory Channel" }, { 38, "3.3.39", "IPMI Device Information" }, { 39, "3.3.40", "System Power Supply" }, + { 40, "3.3.41", "-------------------" }, + { 41, "3.3.42", "-------------------" }, { 126, "3.3.41", "Inactive" }, { 127, "3.3.42", "End Of Table" }, }; |