summaryrefslogtreecommitdiff
path: root/iwinfo_nl80211.c
diff options
context:
space:
mode:
authornbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2014-10-05 10:26:05 +0000
committerJo-Philipp Wich <jow@openwrt.org>2014-10-27 13:48:19 +0100
commitfe7133f7e5a4faca63b6d939c6d55d09d8c240fb (patch)
treeb9737f5b2831697c23a3128999d0f040ded5a94f /iwinfo_nl80211.c
parent8ae758db52957939eeb6bc1c7da7be9d0339d3aa (diff)
downloadiwinfo-fe7133f7e5a4faca63b6d939c6d55d09d8c240fb.tar.gz
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+ssh://svn.openwrt.org/openwrt/trunk@42759 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'iwinfo_nl80211.c')
-rw-r--r--iwinfo_nl80211.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index 7711b61..66ace26 100644
--- a/iwinfo_nl80211.c
+++ b/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;