From b0aa1c0d15caf7363d5babbe8838674964a3ad88 Mon Sep 17 00:00:00 2001 From: Ian Clowes Date: Wed, 5 Jan 2022 16:08:50 +0100 Subject: [PATCH] dawn_iwinfo: fix bug in use of get_bandwidth_iwinfo Fixed bug in use of get_bandwidth_iwinfo() in AP kicking Fix rounding of transmission rate calculations in get_bandwidth_iwinfo() Restructure of get_bandwidth() while finding bug --- src/utils/dawn_iwinfo.c | 60 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 32595e8..a70b090 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -89,54 +89,52 @@ int get_bandwidth_iwinfo(struct dawn_mac client_addr, float *rx_rate, float *tx_ struct dirent *entry; dirp = opendir(hostapd_dir_glob); // error handling? if (!dirp) { - fprintf(stderr, "[BANDWIDTH INFO] Failed to open %s\n", hostapd_dir_glob); + fprintf(stderr,"[BANDWIDTH INFO] Failed to open %s\n", hostapd_dir_glob); return 0; } + else + { + fprintf(stderr,"[BANDWIDTH INFO] Opened %s\n", hostapd_dir_glob); + } int sucess = 0; - while ((entry = readdir(dirp)) != NULL) { + while (!sucess && ((entry = readdir(dirp)) != NULL)) { if (entry->d_type == DT_SOCK) { - if (get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate)) { - sucess = 1; - break; - } + fprintf(stdout,"[BANDWIDTH INFO] Trying %s\n", entry->d_name); + sucess = get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate); } } closedir(dirp); return sucess; } + int get_bandwidth(const char *ifname, struct dawn_mac client_addr, float *rx_rate, float *tx_rate) { + int ret = 0; - int i, len; - char buf[IWINFO_BUFSIZE]; - struct iwinfo_assoclist_entry *e; - const struct iwinfo_ops *iw; - if (strcmp(ifname, "global") == 0) - return 0; - iw = iwinfo_backend(ifname); + if (strcmp(ifname, "global") != 0) + { + const struct iwinfo_ops* iw = iwinfo_backend(ifname); + char buf[IWINFO_BUFSIZE]; + int len; + if (iw->assoclist(ifname, buf, &len) == 0 && len > 0) + { + struct iwinfo_assoclist_entry* e = (struct iwinfo_assoclist_entry*)buf; + for (int i = 0; ret == 0 && i < len; i += sizeof(struct iwinfo_assoclist_entry)) { + if (mac_is_equal(client_addr.u8, e->mac)) { + *rx_rate = e->rx_rate.rate / 1000.0; + *tx_rate = e->tx_rate.rate / 1000.0; - if (iw->assoclist(ifname, buf, &len)) { - iwinfo_finish(); - return 0; - } else if (len <= 0) { - iwinfo_finish(); - return 0; - } - - for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) { - e = (struct iwinfo_assoclist_entry *) &buf[i]; - - if (mac_is_equal(client_addr.u8, e->mac)) { - *rx_rate = e->rx_rate.rate / 1000; - *tx_rate = e->tx_rate.rate / 1000; - iwinfo_finish(); - return 1; + ret = 1; + } + e++; + } } + iwinfo_finish(); } - iwinfo_finish(); - return 0; + + return ret; } int get_rssi_iwinfo(struct dawn_mac client_addr) {