summaryrefslogtreecommitdiffstats
path: root/package/network/utils/iwinfo/src/iwinfo_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'package/network/utils/iwinfo/src/iwinfo_utils.c')
-rw-r--r--package/network/utils/iwinfo/src/iwinfo_utils.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/package/network/utils/iwinfo/src/iwinfo_utils.c b/package/network/utils/iwinfo/src/iwinfo_utils.c
index 6616f1489..b6760c348 100644
--- a/package/network/utils/iwinfo/src/iwinfo_utils.c
+++ b/package/network/utils/iwinfo/src/iwinfo_utils.c
@@ -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;
}