summaryrefslogtreecommitdiffstats
path: root/dmidecodemodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmidecodemodule.c')
-rw-r--r--dmidecodemodule.c75
1 files changed, 71 insertions, 4 deletions
diff --git a/dmidecodemodule.c b/dmidecodemodule.c
index 278a13c..4748e40 100644
--- a/dmidecodemodule.c
+++ b/dmidecodemodule.c
@@ -3,17 +3,84 @@
static PyObject* dmidecode_get(PyObject *self, char* section) {
bzero(buffer, 50000);
- PyObject *list = PyList_New(0);
+ //Py_Initialize();
+ //if(!Py_IsInitialized())
+ // return NULL;
+ int argc = 3;
char *argv[4];
argv[0] = "dmidecode";
argv[1] = "--type";
argv[2] = section;
argv[3] = NULL;
- submain(3, argv);
- PyList_Append(list, PyUnicode_Splitlines(Py_BuildValue("s", buffer), 1));
- return list;
+ int ret=0; /* Returned value */
+ int found=0;
+ size_t fp;
+ int efi;
+ u8 *buf;
+
+ if(sizeof(u8)!=1 || sizeof(u16)!=2 || sizeof(u32)!=4 || '\0'!=0) {
+ fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);
+ exit(255);
+ }
+
+ /* Set default option values */
+ opt.devmem = DEFAULT_MEM_DEV;
+ opt.flags=0;
+ opt.type = NULL;
+ opt.type=parse_opt_type(opt.type, section);
+ if(opt.type==NULL) return -1;
+
+ /* First try EFI (ia64, Intel-based Mac) */
+ efi = address_from_efi(&fp);
+ switch(efi) {
+ case EFI_NOT_FOUND:
+ //. XXX
+ goto memory_scan;
+ case EFI_NO_SMBIOS:
+ ret = 1;
+ goto exit_free;
+ }
+
+ if((buf=mem_chunk(fp, 0x20, opt.devmem))==NULL) {
+ ret = 1;
+ goto exit_free;
+ }
+
+ if(smbios_decode(buf, opt.devmem)) found++;
+
+ goto done;
+
+memory_scan:
+ /* Fallback to memory scan (x86, x86_64) */
+ if((buf=mem_chunk(0xF0000, 0x10000, opt.devmem))==NULL) {
+ ret = 1;
+ goto exit_free;
+ }
+
+ for(fp=0; fp<=0xFFF0; fp+=16) {
+ if(memcmp(buf+fp, "_SM_", 4)==0 && fp<=0xFFE0) {
+ if(smbios_decode(buf+fp, opt.devmem)) found++;
+ fp+=16;
+ } else if(memcmp(buf+fp, "_DMI_", 5)==0) {
+ if(legacy_decode(buf+fp, opt.devmem)) found++;
+ }
+ }
+
+done:
+ free(buf);
+
+ if(!found && !(opt.flags & FLAG_QUIET))
+ catsprintf(buffer, "# No SMBIOS nor DMI entry point found, sorry.\n");
+
+exit_free:
+ //Py_Finalize();
+
+ //. FIXME: Why does this cause crash?
+ free(opt.type);
+
+ return PyUnicode_Splitlines(Py_BuildValue("s", buffer), 1);
}
static PyObject* dmidecode_get_bios(PyObject *self, PyObject *args) { return dmidecode_get(self, "bios"); }