From d141721db22d659be8a15633b9ac7661c45afe97 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 19 Mar 2018 22:27:04 +0100 Subject: [PATCH] add expected throughput --- src/include/dawn_iwinfo.h | 4 ++++ src/storage/datastorage.c | 3 +++ src/utils/dawn_iwinfo.c | 50 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/src/include/dawn_iwinfo.h b/src/include/dawn_iwinfo.h index 36cec7a..089f0f7 100644 --- a/src/include/dawn_iwinfo.h +++ b/src/include/dawn_iwinfo.h @@ -8,8 +8,12 @@ int get_rssi_iwinfo(__uint8_t *client_addr); +int get_expected_throughput_iwinfo(uint8_t *client_addr); + int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare); +int get_expected_throughput(const char *ifname, uint8_t *client_addr); + #endif //DAWN_RSSI_H diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 9a0756d..d2c1d5d 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -418,6 +418,9 @@ void kick_clients(uint8_t bssid[], uint32_t id) { // update rssi int rssi = get_rssi_iwinfo(client_array[j].client_addr); + int exp_thr = get_expected_throughput_iwinfo(client_array[j].client_addr); + printf("Expectd throughput %d\n", exp_thr); + if (rssi != INT_MIN) { pthread_mutex_unlock(&probe_array_mutex); if (!probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) { diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 3153725..446ec60 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -183,5 +183,55 @@ int get_rssi(const char *ifname, uint8_t *client_addr) { return e->signal; } + return INT_MIN; +} + +int get_expected_throughput_iwinfo(__uint8_t *client_addr) { + + DIR *dirp; + struct dirent *entry; + dirp = opendir(hostapd_dir_glob); // error handling? + if (!dirp) { + fprintf(stderr, "[RSSI INFO] No hostapd sockets!\n"); + return INT_MIN; + } + + int exp_thr = INT_MIN; + + while ((entry = readdir(dirp)) != NULL) { + if (entry->d_type == DT_SOCK) { + exp_thr = get_rssi(entry->d_name, client_addr); + if (exp_thr != INT_MIN) + break; + } + } + closedir(dirp); + return exp_thr; +} + +int get_expected_throughput(const char *ifname, uint8_t *client_addr) { + + int i, len; + char buf[IWINFO_BUFSIZE]; + struct iwinfo_assoclist_entry *e; + const struct iwinfo_ops *iw; + + iw = iwinfo_backend(ifname); + + if (iw->assoclist(ifname, buf, &len)) { + printf("No information available\n"); + return INT_MIN; + } else if (len <= 0) { + printf("No station connected\n"); + return INT_MIN; + } + + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) { + e = (struct iwinfo_assoclist_entry *) &buf[i]; + + if (mac_is_equal(client_addr, e->mac)) + return e->thr; + } + return INT_MIN; } \ No newline at end of file