iwinfo: move builtin hardware database to /usr/share/libiwinfo/hardware.txt
[openwrt.git] / package / network / utils / iwinfo / src / iwinfo_utils.c
index 6616f14..b6760c3 100644 (file)
@@ -129,27 +129,46 @@ void iwinfo_close(void)
 
 struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id)
 {
-       const struct iwinfo_hardware_entry *e;
+       FILE *db;
+       char buf[256] = { 0 };
+       static struct iwinfo_hardware_entry e;
 
-       for (e = IWINFO_HARDWARE_ENTRIES; e->vendor_name; e++)
+       if (!(db = fopen(IWINFO_HARDWARE_FILE, "r")))
+               return NULL;
+
+       while (fgets(buf, sizeof(buf) - 1, db) != NULL)
        {
-               if ((e->vendor_id != 0xffff) && (e->vendor_id != id->vendor_id))
+               memset(&e, 0, sizeof(e));
+
+               if (sscanf(buf, "%hx %hx %hx %hx %hd %hd \"%63[^\"]\" \"%63[^\"]\"",
+                              &e.vendor_id, &e.device_id,
+                              &e.subsystem_vendor_id, &e.subsystem_device_id,
+                              &e.txpower_offset, &e.frequency_offset,
+                              e.vendor_name, e.device_name) < 8)
+                       continue;
+
+               if ((e.vendor_id != 0xffff) && (e.vendor_id != id->vendor_id))
                        continue;
 
-               if ((e->device_id != 0xffff) && (e->device_id != id->device_id))
+               if ((e.device_id != 0xffff) && (e.device_id != id->device_id))
                        continue;
 
-               if ((e->subsystem_vendor_id != 0xffff) &&
-                       (e->subsystem_vendor_id != id->subsystem_vendor_id))
+               if ((e.subsystem_vendor_id != 0xffff) &&
+                       (e.subsystem_vendor_id != id->subsystem_vendor_id))
                        continue;
 
-               if ((e->subsystem_device_id != 0xffff) &&
-                       (e->subsystem_device_id != id->subsystem_device_id))
+               if ((e.subsystem_device_id != 0xffff) &&
+                       (e.subsystem_device_id != id->subsystem_device_id))
                        continue;
 
-               return (struct iwinfo_hardware_entry *)e;
+               break;
        }
 
+       fclose(db);
+
+       if (e.device_name[0])
+               return &e;
+
        return NULL;
 }