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.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/package/network/utils/iwinfo/src/iwinfo_utils.c b/package/network/utils/iwinfo/src/iwinfo_utils.c
index 164e51f84..1a831f3ac 100644
--- a/package/network/utils/iwinfo/src/iwinfo_utils.c
+++ b/package/network/utils/iwinfo/src/iwinfo_utils.c
@@ -28,7 +28,7 @@ static int ioctl_socket = -1;
static int iwinfo_ioctl_socket(void)
{
/* Prepare socket */
- if( ioctl_socket == -1 )
+ if (ioctl_socket == -1)
{
ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC);
@@ -82,7 +82,7 @@ int iwinfo_ifup(const char *ifname)
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
- if( iwinfo_ioctl(SIOCGIFFLAGS, &ifr) )
+ if (iwinfo_ioctl(SIOCGIFFLAGS, &ifr))
return 0;
ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
@@ -96,7 +96,7 @@ int iwinfo_ifdown(const char *ifname)
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
- if( iwinfo_ioctl(SIOCGIFFLAGS, &ifr) )
+ if (iwinfo_ioctl(SIOCGIFFLAGS, &ifr))
return 0;
ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING);
@@ -110,7 +110,7 @@ int iwinfo_ifmac(const char *ifname)
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
- if( iwinfo_ioctl(SIOCGIFHWADDR, &ifr) )
+ if (iwinfo_ioctl(SIOCGIFHWADDR, &ifr))
return 0;
ifr.ifr_hwaddr.sa_data[1]++;
@@ -121,34 +121,52 @@ int iwinfo_ifmac(const char *ifname)
void iwinfo_close(void)
{
- if( ioctl_socket > -1 )
+ if (ioctl_socket > -1)
close(ioctl_socket);
+
+ ioctl_socket = -1;
}
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, *rv = NULL;
+
+ if (!(db = fopen(IWINFO_HARDWARE_FILE, "r")))
+ return NULL;
- for (e = IWINFO_HARDWARE_ENTRIES; e->vendor_name; e++)
+ 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->device_id != 0xffff) && (e->device_id != id->device_id))
+ if ((e.vendor_id != 0xffff) && (e.vendor_id != id->vendor_id))
continue;
- if ((e->subsystem_vendor_id != 0xffff) &&
- (e->subsystem_vendor_id != id->subsystem_vendor_id))
+ if ((e.device_id != 0xffff) && (e.device_id != id->device_id))
continue;
- if ((e->subsystem_device_id != 0xffff) &&
- (e->subsystem_device_id != id->subsystem_device_id))
+ if ((e.subsystem_vendor_id != 0xffff) &&
+ (e.subsystem_vendor_id != id->subsystem_vendor_id))
continue;
- return (struct iwinfo_hardware_entry *)e;
+ if ((e.subsystem_device_id != 0xffff) &&
+ (e.subsystem_device_id != id->subsystem_device_id))
+ continue;
+
+ rv = &e;
+ break;
}
- return NULL;
+ fclose(db);
+ return rv;
}
int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id)