diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-26 03:37:32 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-26 03:37:32 +0000 |
commit | 6e5620cc471f0ba3fe5b25b5fcd18e46d2f0e6af (patch) | |
tree | 264fd080f0e61d7dd7c291788c49084562b95e78 /contrib/package/iwinfo/src/iwinfo_nl80211.c | |
parent | 6c7535292be50625ce01d10d2c7e2512e605cf9f (diff) |
libiwinfo: fix freq/channel detection for secondary bss
Diffstat (limited to 'contrib/package/iwinfo/src/iwinfo_nl80211.c')
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_nl80211.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/contrib/package/iwinfo/src/iwinfo_nl80211.c b/contrib/package/iwinfo/src/iwinfo_nl80211.c index b5ab5ba070..5d1add9689 100644 --- a/contrib/package/iwinfo/src/iwinfo_nl80211.c +++ b/contrib/package/iwinfo/src/iwinfo_nl80211.c @@ -400,9 +400,26 @@ out: return rv; } +static inline int nl80211_readint(const char *path) +{ + int fd; + int rv = -1; + char buffer[16]; + + if( (fd = open(path, O_RDONLY)) > -1 ) + { + if( read(fd, buffer, sizeof(buffer)) > 0 ) + rv = atoi(buffer); + + close(fd); + } + + return rv; +} + static char * nl80211_phy2ifname(const char *ifname) { - int fd, phyidx = -1; + int fd, ifidx = -1, cifidx = -1, phyidx = -1; char buffer[64]; static char nif[IFNAMSIZ] = { 0 }; @@ -423,19 +440,18 @@ static char * nl80211_phy2ifname(const char *ifname) snprintf(buffer, sizeof(buffer), "/sys/class/net/%s/phy80211/index", e->d_name); - if( (fd = open(buffer, O_RDONLY)) > 0 ) + if( nl80211_readint(buffer) == phyidx ) { - if( (read(fd, buffer, sizeof(buffer)) > 0) && - (atoi(buffer) == phyidx) ) + snprintf(buffer, sizeof(buffer), + "/sys/class/net/%s/ifindex", e->d_name); + + if( (cifidx = nl80211_readint(buffer)) >= 0 && + ((ifidx < 0) || (cifidx < ifidx)) ) { + ifidx = cifidx; strncpy(nif, e->d_name, sizeof(nif)); } - - close(fd); } - - if( nif[0] ) - break; } closedir(d); @@ -586,12 +602,28 @@ int nl80211_get_bssid(const char *ifname, char *buf) int nl80211_get_channel(const char *ifname, int *buf) { - return wext_get_channel(ifname, buf); + char *first; + + if( wext_get_channel(ifname, buf) && + NULL != (first = nl80211_phy2ifname(nl80211_ifname2phy(ifname))) ) + { + return wext_get_channel(first, buf); + } + + return -1; } int nl80211_get_frequency(const char *ifname, int *buf) { - return wext_get_frequency(ifname, buf); + char *first; + + if( wext_get_channel(ifname, buf) && + NULL != (first = nl80211_phy2ifname(nl80211_ifname2phy(ifname))) ) + { + return wext_get_frequency(first, buf); + } + + return -1; } int nl80211_get_txpower(const char *ifname, int *buf) |