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
This commit is contained in:
Ian Clowes 2022-01-05 16:08:50 +01:00 committed by Nick Hainke
parent 94b2bc42a1
commit b0aa1c0d15

View file

@ -89,54 +89,52 @@ int get_bandwidth_iwinfo(struct dawn_mac client_addr, float *rx_rate, float *tx_
struct dirent *entry; struct dirent *entry;
dirp = opendir(hostapd_dir_glob); // error handling? dirp = opendir(hostapd_dir_glob); // error handling?
if (!dirp) { 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; return 0;
} }
else
{
fprintf(stderr,"[BANDWIDTH INFO] Opened %s\n", hostapd_dir_glob);
}
int sucess = 0; int sucess = 0;
while ((entry = readdir(dirp)) != NULL) { while (!sucess && ((entry = readdir(dirp)) != NULL)) {
if (entry->d_type == DT_SOCK) { if (entry->d_type == DT_SOCK) {
if (get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate)) { fprintf(stdout,"[BANDWIDTH INFO] Trying %s\n", entry->d_name);
sucess = 1; sucess = get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate);
break;
}
} }
} }
closedir(dirp); closedir(dirp);
return sucess; return sucess;
} }
int get_bandwidth(const char *ifname, struct dawn_mac client_addr, float *rx_rate, float *tx_rate) { int get_bandwidth(const char *ifname, struct dawn_mac client_addr, float *rx_rate, float *tx_rate) {
int ret = 0;
int i, len; if (strcmp(ifname, "global") != 0)
char buf[IWINFO_BUFSIZE]; {
struct iwinfo_assoclist_entry *e; const struct iwinfo_ops* iw = iwinfo_backend(ifname);
const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE];
if (strcmp(ifname, "global") == 0) int len;
return 0; if (iw->assoclist(ifname, buf, &len) == 0 && len > 0)
iw = iwinfo_backend(ifname); {
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)) { ret = 1;
iwinfo_finish(); }
return 0; e++;
} 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;
} }
iwinfo_finish();
} }
iwinfo_finish();
return 0; return ret;
} }
int get_rssi_iwinfo(struct dawn_mac client_addr) { int get_rssi_iwinfo(struct dawn_mac client_addr) {