diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-04-30 10:16:35 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-04-30 10:16:35 +0000 |
commit | 087f4b2752b1d5d1e3f10bfb82ba4259aeec85e1 (patch) | |
tree | 3d7111080e05f2fe4ffb38993e84a919684aaff1 /contrib/package/iwinfo/src | |
parent | 4d7777f44da724d54553f9f26cdd6d6cb7c777af (diff) |
libiwinfo: fix signal, bitrate and assoclist for nl80211 wds ap mode
Diffstat (limited to 'contrib/package/iwinfo/src')
-rw-r--r-- | contrib/package/iwinfo/src/iwinfo_nl80211.c | 106 |
1 files changed, 68 insertions, 38 deletions
diff --git a/contrib/package/iwinfo/src/iwinfo_nl80211.c b/contrib/package/iwinfo/src/iwinfo_nl80211.c index 0f57d37f1d..5828ee98de 100644 --- a/contrib/package/iwinfo/src/iwinfo_nl80211.c +++ b/contrib/package/iwinfo/src/iwinfo_nl80211.c @@ -655,7 +655,7 @@ int nl80211_get_txpower(const char *ifname, int *buf) } -static int nl80211_get_signal_cb(struct nl_msg *msg, void *arg) +static int nl80211_fill_signal_cb(struct nl_msg *msg, void *arg) { int8_t dbm; int16_t mbit; @@ -719,29 +719,52 @@ static int nl80211_get_signal_cb(struct nl_msg *msg, void *arg) return NL_SKIP; } +static void nl80211_fill_signal(const char *ifname, struct nl80211_rssi_rate *r) +{ + DIR *d; + struct dirent *de; + struct nl80211_msg_conveyor *req; + + r->rssi = 0; + r->rate = 0; + + if ((d = opendir("/sys/class/net")) != NULL) + { + while ((de = readdir(d)) != NULL) + { + if (!strncmp(de->d_name, ifname, strlen(ifname)) && + (!de->d_name[strlen(ifname)] || + !strncmp(&de->d_name[strlen(ifname)], ".sta", 4))) + { + req = nl80211_msg(de->d_name, NL80211_CMD_GET_STATION, + NLM_F_DUMP); + + if (req) + { + nl80211_cb(req, nl80211_fill_signal_cb, r); + nl80211_send(req); + nl80211_free(req); + } + } + } + + closedir(d); + } +} + int nl80211_get_bitrate(const char *ifname, int *buf) { struct nl80211_rssi_rate rr; - struct nl80211_msg_conveyor *req; if( !wext_get_bitrate(ifname, buf) ) return 0; - req = nl80211_msg(ifname, NL80211_CMD_GET_STATION, NLM_F_DUMP); - if( req ) - { - rr.rssi = 0; - rr.rate = 0; + nl80211_fill_signal(ifname, &rr); - nl80211_cb(req, nl80211_get_signal_cb, &rr); - nl80211_send(req); - nl80211_free(req); - - if( rr.rate ) - { - *buf = (rr.rate * 100); - return 0; - } + if (rr.rate) + { + *buf = (rr.rate * 100); + return 0; } return -1; @@ -750,26 +773,16 @@ int nl80211_get_bitrate(const char *ifname, int *buf) int nl80211_get_signal(const char *ifname, int *buf) { struct nl80211_rssi_rate rr; - struct nl80211_msg_conveyor *req; if( !wext_get_signal(ifname, buf) ) return 0; - req = nl80211_msg(ifname, NL80211_CMD_GET_STATION, NLM_F_DUMP); - if( req ) - { - rr.rssi = 0; - rr.rate = 0; - - nl80211_cb(req, nl80211_get_signal_cb, &rr); - nl80211_send(req); - nl80211_free(req); + nl80211_fill_signal(ifname, &rr); - if( rr.rssi ) - { - *buf = rr.rssi; - return 0; - } + if (rr.rssi) + { + *buf = rr.rssi; + return 0; } return -1; @@ -1085,20 +1098,37 @@ static int nl80211_get_assoclist_cb(struct nl_msg *msg, void *arg) int nl80211_get_assoclist(const char *ifname, char *buf, int *len) { + DIR *d; + struct dirent *de; struct nl80211_assoc_count ac; struct nl80211_msg_conveyor *req; - nl80211_get_noise(ifname, &ac.noise); - - req = nl80211_msg(ifname, NL80211_CMD_GET_STATION, NLM_F_DUMP); - if( req ) + if ((d = opendir("/sys/class/net")) != NULL) { ac.count = 0; ac.entry = (struct iwinfo_assoclist_entry *)buf; - nl80211_cb(req, nl80211_get_assoclist_cb, &ac); - nl80211_send(req); - nl80211_free(req); + nl80211_get_noise(ifname, &ac.noise); + + while ((de = readdir(d)) != NULL) + { + if (!strncmp(de->d_name, ifname, strlen(ifname)) && + (!de->d_name[strlen(ifname)] || + !strncmp(&de->d_name[strlen(ifname)], ".sta", 4))) + { + req = nl80211_msg(de->d_name, NL80211_CMD_GET_STATION, + NLM_F_DUMP); + + if (req) + { + nl80211_cb(req, nl80211_get_assoclist_cb, &ac); + nl80211_send(req); + nl80211_free(req); + } + } + } + + closedir(d); *len = (ac.count * sizeof(struct iwinfo_assoclist_entry)); return 0; |