diff options
author | Felix Fietkau <nbd@openwrt.org> | 2014-10-05 10:26:05 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-10-05 10:26:05 +0000 |
commit | bfacdd543b92213a6f47ae0a58ac170286c4610a (patch) | |
tree | 4a16b45229df0058e948a825c157dfa41ef227a9 /package/network/utils/iwinfo/src/iwinfo_nl80211.c | |
parent | 0d160a4d3e056fb277d139119c7a0dab54883dd5 (diff) | |
download | upstream-bfacdd543b92213a6f47ae0a58ac170286c4610a.tar.gz upstream-bfacdd543b92213a6f47ae0a58ac170286c4610a.tar.bz2 upstream-bfacdd543b92213a6f47ae0a58ac170286c4610a.zip |
iwinfo: fix handling of accessing nl80211 interfaces via radio*
look up device path via uci instead of assuming a direct phy index
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@42759 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/network/utils/iwinfo/src/iwinfo_nl80211.c')
-rw-r--r-- | package/network/utils/iwinfo/src/iwinfo_nl80211.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/package/network/utils/iwinfo/src/iwinfo_nl80211.c b/package/network/utils/iwinfo/src/iwinfo_nl80211.c index 7711b61102..66ace26101 100644 --- a/package/network/utils/iwinfo/src/iwinfo_nl80211.c +++ b/package/network/utils/iwinfo/src/iwinfo_nl80211.c @@ -23,6 +23,7 @@ */ #include <limits.h> +#include <glob.h> #include "iwinfo_nl80211.h" #define min(x, y) ((x) < (y)) ? (x) : (y) @@ -209,6 +210,51 @@ static struct nl80211_msg_conveyor * nl80211_ctl(int cmd, int flags) return nl80211_new(nls->nlctrl, cmd, flags); } +static int nl80211_phy_idx_from_uci(const char *name) +{ + struct uci_section *s; + const char *opt; + char buf[128]; + glob_t gl; + FILE *f = NULL; + int idx = -1; + int err; + + s = iwinfo_uci_get_radio(name, "mac80211"); + if (!s) + goto free; + + opt = uci_lookup_option_string(uci_ctx, s, "path"); + if (!opt) + goto free; + + snprintf(buf, sizeof(buf), "/sys/devices/%s/ieee80211/*/index", opt); + err = glob(buf, 0, NULL, &gl); + if (err) + goto free; + + if (gl.gl_pathc) + f = fopen(gl.gl_pathv[0], "r"); + + globfree(&gl); + + if (!f) + goto free; + + err = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + + if (err <= 0) + goto free; + + buf[err] = 0; + idx = atoi(buf); + +free: + iwinfo_uci_free(); + return idx; +} + static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname, int cmd, int flags) { @@ -224,7 +270,7 @@ static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname, if (!strncmp(ifname, "phy", 3)) phyidx = atoi(&ifname[3]); else if (!strncmp(ifname, "radio", 5)) - phyidx = atoi(&ifname[5]); + phyidx = nl80211_phy_idx_from_uci(ifname); else if (!strncmp(ifname, "mon.", 4)) ifidx = if_nametoindex(&ifname[4]); else @@ -510,7 +556,7 @@ static char * nl80211_phy2ifname(const char *ifname) else if (!strncmp(ifname, "phy", 3)) phyidx = atoi(&ifname[3]); else if (!strncmp(ifname, "radio", 5)) - phyidx = atoi(&ifname[5]); + phyidx = nl80211_phy_idx_from_uci(ifname); else return NULL; |