From 3071d84acd38b2a275565781c46d140dbd1d5a6e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 17:39:39 +0100 Subject: [PATCH 01/14] some changes --- src/include/dawn_iwinfo.h | 2 ++ src/main.c | 3 +++ src/storage/datastorage.c | 24 +++++++++++++++++++++--- src/utils/dawn_iwinfo.c | 25 ++++++++++++++++++++++--- src/utils/ubus.c | 31 ++++++++++--------------------- 5 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/include/dawn_iwinfo.h b/src/include/dawn_iwinfo.h index 215d817..4a1c95b 100644 --- a/src/include/dawn_iwinfo.h +++ b/src/include/dawn_iwinfo.h @@ -10,4 +10,6 @@ int get_rssi_iwinfo(__uint8_t *client_addr); int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); +int get_essid(const char *ifname, uint8_t *bssid_addr); + #endif //DAWN_RSSI_H diff --git a/src/main.c b/src/main.c index 4252b4f..bc190d1 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ #include "ubus.h" #include "dawn_uci.h" #include "crypto.h" +#include "dawn_iwinfo.h" void daemon_shutdown(); @@ -97,6 +98,8 @@ int main(int argc, char **argv) { gcrypt_init(); gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); + get_essid("wlan0", NULL); + struct time_config_s time_config = uci_get_time_config(); timeout_config = time_config; // TODO: Refactor... diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index dfc36b8..1905673 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -43,7 +43,8 @@ int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]); int mac_in_maclist(uint8_t mac[]); -int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, int automatic_kick); +int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr, + int automatic_kick); int probe_entry_last = -1; int client_entry_last = -1; @@ -173,7 +174,8 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { return score; } -int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, int automatic_kick) { +int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr, + int automatic_kick) { ap ap_entry_own = ap_array_get_ap(bssid_addr_own); ap ap_entry_to_compre = ap_array_get_ap(bssid_addr_to_compare); @@ -188,6 +190,19 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar } else { return ap_entry_own.station_count > ap_entry_to_compre.station_count; } + + /* + int own_count = ap_entry_own.station_count; + if(automatic_kick) + { + own_count--; + } + if (is_connected(bssid_addr_to_compare, client_addr)) + { + own_count--; + } + + return own_count > ap_entry_to_compre.station_count;*/ } return 0; @@ -247,10 +262,13 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat return 1; } if (dawn_metric.use_station_count && own_score == score_to_compare) { + // if ap have same value but station count is different... - if (compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick)) { + if (compare_station_count(bssid_addr, probe_array[k].bssid_addr, NULL, automatic_kick)) { return 1; } + + } } return 0; diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 7984f31..48768fe 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -15,10 +15,29 @@ int parse_rssi(char *iwinfo_string); int get_rssi(const char *ifname, uint8_t *client_addr); -int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate); +int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate); #define IWINFO_BUFSIZE 24 * 1024 +#define IWINFO_ESSID_MAX_SIZE 32 + +int get_essid(const char *ifname, uint8_t *bssid_addr) +{ + struct iwinfo_assoclist_entry *e; + const struct iwinfo_ops *iw; + + iw = iwinfo_backend(ifname); + + char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; + + if (iw->ssid(ifname, buf)) + memset(buf, 0, sizeof(buf)); + + printf("ESSID is: %s\n", buf); +} + + + int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) { DIR *dirp; @@ -33,7 +52,7 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { - if (get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) { + if (get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate)) { sucess = 1; break; } @@ -43,7 +62,7 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) return sucess; } -int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate) { +int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate) { int i, len; char buf[IWINFO_BUFSIZE]; diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 5645f3d..fe013f2 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -246,13 +246,17 @@ void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t * static int decide_function(probe_entry *prob_req) { - // TODO: Refactor... printf("COUNTER: %d\n", prob_req->counter); if (prob_req->counter < dawn_metric.min_probe_count) { return 0; } + if(!dawn_metric.eval_probe_req) + { + return 1; + } + if (better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) { return 0; } @@ -368,6 +372,9 @@ static int handle_auth_req(struct blob_attr *msg) { return UBUS_STATUS_UNKNOWN_ERROR; } + // maybe add here if a client is already connected... + // delay problems... + printf("ALLOW AUTH!\n"); return 0; } @@ -382,31 +389,13 @@ static int handle_assoc_req(struct blob_attr *msg) { static int handle_probe_req(struct blob_attr *msg) { //printf("[WC] Parse Probe Request\n"); probe_entry prob_req; + probe_entry tmp_prob_req; if(parse_to_probe_req(msg, &prob_req) == 0) { - insert_to_array(prob_req, 1); + tmp_prob_req = insert_to_array(prob_req, 1); //print_probe_array(); send_blob_attr_via_network(msg, "probe"); } - //insert_to_list(prob_req, 1); - //probe_entry tmp_probe = - probe_entry tmp_prob_req = insert_to_array(prob_req, 1); - - // send probe via network - /*char *str; - str = blobmsg_format_json(msg, true); - send_string_enc(str); - - printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str);*/ - - - //print_probe_array(); - - // deny access - - if (!dawn_metric.eval_probe_req) { - return 0; - } if (!decide_function(&tmp_prob_req)) { //printf("MAC WILL BE DECLINED!!!\n"); From 78922b1be93d1f68a2fd015876a7881c911d4e0a Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 17:40:43 +0100 Subject: [PATCH 02/14] some changes --- src/utils/dawn_iwinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 48768fe..93d6f7c 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -23,7 +23,7 @@ int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, floa int get_essid(const char *ifname, uint8_t *bssid_addr) { - struct iwinfo_assoclist_entry *e; + //struct iwinfo_assoclist_entry *e; const struct iwinfo_ops *iw; iw = iwinfo_backend(ifname); From 5e068e7762c1139c6ae6911ec79e329526a87514 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 17:41:19 +0100 Subject: [PATCH 03/14] some changes --- src/utils/dawn_iwinfo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 93d6f7c..4928de0 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -34,6 +34,7 @@ int get_essid(const char *ifname, uint8_t *bssid_addr) memset(buf, 0, sizeof(buf)); printf("ESSID is: %s\n", buf); + return 0; } From 9e63f62530bcea147b861bbae93b6f0e40900d9c Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 17:48:31 +0100 Subject: [PATCH 04/14] add bssid --- src/utils/dawn_iwinfo.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 4928de0..d94cc83 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -33,7 +33,13 @@ int get_essid(const char *ifname, uint8_t *bssid_addr) if (iw->ssid(ifname, buf)) memset(buf, 0, sizeof(buf)); + static char buf_bssid[18] = { 0 }; + if (iw->bssid(ifname, buf_bssid)) + snprintf(buf, sizeof(buf), "00:00:00:00:00:00"); + printf("ESSID is: %s\n", buf); + printf("BSSID is: %s\n", buf_bssid); + return 0; } From 796d140698190c31d2807e2e443f17b92defb46b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 18:26:18 +0100 Subject: [PATCH 05/14] compare essid --- src/include/datastorage.h | 1 + src/include/dawn_iwinfo.h | 2 +- src/main.c | 2 -- src/storage/datastorage.c | 11 +++++++ src/utils/dawn_iwinfo.c | 67 ++++++++++++++++++++++++++++++--------- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 8d1267e..a1f4fca 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -161,6 +161,7 @@ typedef struct ap_s { uint32_t channel_utilization; time_t time; uint32_t station_count; + // essid } ap; // ---------------- Defines ---------------- diff --git a/src/include/dawn_iwinfo.h b/src/include/dawn_iwinfo.h index 4a1c95b..0da0733 100644 --- a/src/include/dawn_iwinfo.h +++ b/src/include/dawn_iwinfo.h @@ -10,6 +10,6 @@ int get_rssi_iwinfo(__uint8_t *client_addr); int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); -int get_essid(const char *ifname, uint8_t *bssid_addr); +int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare); #endif //DAWN_RSSI_H diff --git a/src/main.c b/src/main.c index bc190d1..7fc15e5 100644 --- a/src/main.c +++ b/src/main.c @@ -98,8 +98,6 @@ int main(int argc, char **argv) { gcrypt_init(); gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); - get_essid("wlan0", NULL); - struct time_config_s time_config = uci_get_time_config(); timeout_config = time_config; // TODO: Refactor... diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 1905673..ba75903 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -255,6 +255,17 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat continue; } + // check if same essid!!! + if(compare_essid(bssid_addr, probe_array[k].bssid_addr) != 0) + { + printf("ESSID ARE NOT THE SAME!\n"); + continue; + } else + { + printf("ESSID ARE THE SAME!\n"); + } + + printf("Calculating score to compare!\n"); score_to_compare = eval_probe_metric(probe_array[k]); diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index d94cc83..969631f 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -21,30 +21,67 @@ int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, floa #define IWINFO_ESSID_MAX_SIZE 32 -int get_essid(const char *ifname, uint8_t *bssid_addr) + +int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) { - //struct iwinfo_assoclist_entry *e; const struct iwinfo_ops *iw; - iw = iwinfo_backend(ifname); + char mac_buf[20]; + char mac_buf_to_compare[20]; + sprintf(mac_buf, MACSTR, MAC2STR(bssid_addr)); + sprintf(mac_buf_to_compare, MACSTR, MAC2STR(bssid_addr_to_compare)); - char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; + DIR *dirp; + struct dirent *entry; + dirp = opendir(hostapd_dir_glob); // error handling? + if (!dirp) { + fprintf(stderr, "No hostapd sockets!\n"); + return 0; + } - if (iw->ssid(ifname, buf)) - memset(buf, 0, sizeof(buf)); + char* essid = NULL; + char* essid_to_compare = NULL; - static char buf_bssid[18] = { 0 }; - if (iw->bssid(ifname, buf_bssid)) - snprintf(buf, sizeof(buf), "00:00:00:00:00:00"); + char buf_essid[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; + char buf_essid_to_compare[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; - printf("ESSID is: %s\n", buf); - printf("BSSID is: %s\n", buf_bssid); - - return 0; + while ((entry = readdir(dirp)) != NULL) { + if (entry->d_type == DT_SOCK) { + + iw = iwinfo_backend(entry->d_name); + + static char buf_bssid[18] = { 0 }; + if (iw->bssid(entry->d_name, buf_bssid)) + snprintf(buf_bssid, sizeof(buf_bssid), "00:00:00:00:00:00"); + + if(strcmp(mac_buf, buf_bssid)) + { + + if (iw->ssid(entry->d_type, buf_essid)) + memset(buf_essid, 0, sizeof(buf_essid)); + essid = buf_essid; + } + + if(strcmp(mac_buf_to_compare, buf_bssid)) + { + if (iw->ssid(entry->d_type, buf_essid_to_compare)) + memset(buf_essid_to_compare, 0, sizeof(buf_essid_to_compare)); + essid_to_compare = buf_essid_to_compare; + } + } + } + closedir(dirp); + + printf("Comparing: %s with %s\n", essid, essid_to_compare); + + if(strcmp(essid, essid_to_compare)) + { + return 0; + } + + return -1; } - - int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) { DIR *dirp; From 63420db54dc9289071c3f32be23bdf062e6f1783 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 18:30:09 +0100 Subject: [PATCH 06/14] compare essid --- src/utils/dawn_iwinfo.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 969631f..a5ae378 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -45,7 +45,7 @@ int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) char buf_essid[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; char buf_essid_to_compare[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; - while ((entry = readdir(dirp)) != NULL) { + while ((entry = readdir(dirp)) != NULL && (essid == NULL || essid_to_compare == NULL)) { if (entry->d_type == DT_SOCK) { iw = iwinfo_backend(entry->d_name); @@ -57,14 +57,14 @@ int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) if(strcmp(mac_buf, buf_bssid)) { - if (iw->ssid(entry->d_type, buf_essid)) + if (iw->ssid(entry->d_name, buf_essid)) memset(buf_essid, 0, sizeof(buf_essid)); essid = buf_essid; } if(strcmp(mac_buf_to_compare, buf_bssid)) { - if (iw->ssid(entry->d_type, buf_essid_to_compare)) + if (iw->ssid(entry->d_name, buf_essid_to_compare)) memset(buf_essid_to_compare, 0, sizeof(buf_essid_to_compare)); essid_to_compare = buf_essid_to_compare; } @@ -74,6 +74,11 @@ int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) printf("Comparing: %s with %s\n", essid, essid_to_compare); + if(essid == NULL || essid_to_compare == NULL) + { + return -1; + } + if(strcmp(essid, essid_to_compare)) { return 0; From 9492d5c620a8330bd07f23ea0cbb002afc832093 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 18:36:18 +0100 Subject: [PATCH 07/14] compare essids --- src/utils/dawn_iwinfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index a5ae378..6b0fc6f 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -54,7 +54,7 @@ int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) if (iw->bssid(entry->d_name, buf_bssid)) snprintf(buf_bssid, sizeof(buf_bssid), "00:00:00:00:00:00"); - if(strcmp(mac_buf, buf_bssid)) + if(strcmp(mac_buf, buf_bssid) == 0) { if (iw->ssid(entry->d_name, buf_essid)) @@ -62,7 +62,7 @@ int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) essid = buf_essid; } - if(strcmp(mac_buf_to_compare, buf_bssid)) + if(strcmp(mac_buf_to_compare, buf_bssid) == 0) { if (iw->ssid(entry->d_name, buf_essid_to_compare)) memset(buf_essid_to_compare, 0, sizeof(buf_essid_to_compare)); @@ -79,7 +79,7 @@ int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) return -1; } - if(strcmp(essid, essid_to_compare)) + if(strcmp(essid, essid_to_compare) == 0) { return 0; } From fe5e6849b88a2294761a560f9bf2fccb3989a5fe Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 19:04:06 +0100 Subject: [PATCH 08/14] change back to broadcast --- files/dawn.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 4009ec7..94d35a9 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,7 +1,7 @@ config network - option broadcast_ip '225.0.0.37' + option broadcast_ip '10.0.0.255' option broadcast_port '1025' - option multicast '1' + option multicast '0' option shared_key 'Niiiiiiiiiiiiiik' option iv 'Niiiiiiiiiiiiiik' From 5e6c0ed78f4fe0475d0eb64062b760ae467a2c47 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 19:59:46 +0100 Subject: [PATCH 09/14] parse from ubus call --- src/include/datastorage.h | 4 +++- src/storage/datastorage.c | 4 ++-- src/utils/ubus.c | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index a1f4fca..58d83c4 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -109,6 +109,8 @@ typedef struct auth_entry_s assoc_entry; // ---------------- Defines ---------------- #define PROBE_ARRAY_LEN 1000 +#define SSID_MAX_LEN 32 + // ---------------- Global variables ---------------- struct probe_entry_s probe_array[PROBE_ARRAY_LEN]; pthread_mutex_t probe_array_mutex; @@ -161,7 +163,7 @@ typedef struct ap_s { uint32_t channel_utilization; time_t time; uint32_t station_count; - // essid + uint8_t ssid[SSID_MAX_LEN]; } ap; // ---------------- Defines ---------------- diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index ba75903..f5980c8 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -1189,8 +1189,8 @@ void print_ap_entry(ap entry) { char mac_buf_ap[20]; sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); - printf("bssid_addr: %s, freq: %d, ht: %d, vht: %d, chan_utilz: %d\n", - mac_buf_ap, entry.freq, entry.ht, entry.vht, entry.channel_utilization); + printf("ssid: %s, bssid_addr: %s, freq: %d, ht: %d, vht: %d, chan_utilz: %d\n", + entry.ssid, mac_buf_ap, entry.freq, entry.ht, entry.vht, entry.channel_utilization); } void print_ap_array() { diff --git a/src/utils/ubus.c b/src/utils/ubus.c index fe013f2..d2b198e 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -105,6 +105,7 @@ static const struct blobmsg_policy prob_policy[__PROB_MAX] = { enum { CLIENT_TABLE, CLIENT_TABLE_BSSID, + CLIENT_TABLE_SSID, CLIENT_TABLE_FREQ, CLIENT_TABLE_HT, CLIENT_TABLE_VHT, @@ -116,6 +117,7 @@ enum { static const struct blobmsg_policy client_table_policy[__CLIENT_TABLE_MAX] = { [CLIENT_TABLE] = {.name = "clients", .type = BLOBMSG_TYPE_TABLE}, [CLIENT_TABLE_BSSID] = {.name = "bssid", .type = BLOBMSG_TYPE_STRING}, + [CLIENT_TABLE_SSID] = {.name = "ssid", .type = BLOBMSG_TYPE_STRING}, [CLIENT_TABLE_FREQ] = {.name = "freq", .type = BLOBMSG_TYPE_INT32}, [CLIENT_TABLE_HT] = {.name = "ht_supported", .type = BLOBMSG_TYPE_INT8}, [CLIENT_TABLE_VHT] = {.name = "vht_supported", .type = BLOBMSG_TYPE_INT8}, @@ -766,6 +768,7 @@ int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) { ap_entry.ht = blobmsg_get_u8(tb[CLIENT_TABLE_HT]); ap_entry.vht = blobmsg_get_u8(tb[CLIENT_TABLE_VHT]); ap_entry.channel_utilization = blobmsg_get_u32(tb[CLIENT_TABLE_CHAN_UTIL]); + strcpy((char*)ap_entry.ssid, blobmsg_get_string(tb[CLIENT_TABLE_SSID])); if (tb[CLIENT_TABLE_NUM_STA]) { ap_entry.station_count = blobmsg_get_u32(tb[CLIENT_TABLE_NUM_STA]); From 8691dc55f5d5f8a7c86534c34099c98d4622af60 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 20:50:49 +0100 Subject: [PATCH 10/14] compare essid --- src/include/dawn_iwinfo.h | 2 +- src/include/utils.h | 2 + src/storage/datastorage.c | 113 +++++++++++++++++++++++++------------- src/utils/dawn_iwinfo.c | 2 +- src/utils/utils.c | 18 ++++++ 5 files changed, 96 insertions(+), 41 deletions(-) diff --git a/src/include/dawn_iwinfo.h b/src/include/dawn_iwinfo.h index 0da0733..36cec7a 100644 --- a/src/include/dawn_iwinfo.h +++ b/src/include/dawn_iwinfo.h @@ -10,6 +10,6 @@ int get_rssi_iwinfo(__uint8_t *client_addr); int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); -int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare); +int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare); #endif //DAWN_RSSI_H diff --git a/src/include/utils.h b/src/include/utils.h index e07a776..efc874b 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -17,4 +17,6 @@ int convert_mac(char *in, char *out); void write_mac_to_file(char* path, uint8_t addr[]); +int string_is_greater(uint8_t* str, uint8_t* str_2); + #endif \ No newline at end of file diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index f5980c8..7ae1722 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -46,6 +46,8 @@ int mac_in_maclist(uint8_t mac[]); int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr, int automatic_kick); +int compare_ssid(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare); + int probe_entry_last = -1; int client_entry_last = -1; int ap_entry_last = -1; @@ -73,43 +75,62 @@ int build_hearing_map_sort_client(struct blob_buf *b) { pthread_mutex_lock(&probe_array_mutex); - void *client_list, *ap_list; + void *client_list, *ap_list, *ssid_list; char ap_mac_buf[20]; char client_mac_buf[20]; blob_buf_init(b, 0); - int i; - for (i = 0; i <= probe_entry_last; i++) { - int k; - sprintf(client_mac_buf, MACSTR, MAC2STR(probe_array[i].client_addr)); - client_list = blobmsg_open_table(b, client_mac_buf); - for (k = i; i <= probe_entry_last; k++){ - if(!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) + int m; + for (m = 0; m <= ap_entry_last; m++) { + printf("COMPARING!\n"); + if(m > 0) + { + if(strcmp((char*)ap_array[m].ssid, (char*)ap_array[m-1].ssid) == 0) { - i = k - 1; - break; + continue; } - sprintf(ap_mac_buf, MACSTR, MAC2STR(probe_array[k].bssid_addr)); - ap_list = blobmsg_open_table(b, ap_mac_buf); - blobmsg_add_u32(b, "signal", probe_array[k].signal); - blobmsg_add_u32(b, "freq", probe_array[k].freq); - blobmsg_add_u8(b, "ht_support", probe_array[k].ht_support); - blobmsg_add_u8(b, "vht_support", probe_array[k].vht_support); - - ap ap_entry = ap_array_get_ap(probe_array[k].bssid_addr); - - // check if ap entry is available - if (mac_is_equal(ap_entry.bssid_addr, probe_array[k].bssid_addr)) { - blobmsg_add_u32(b, "channel_utilization", ap_entry.channel_utilization); - blobmsg_add_u32(b, "num_sta", ap_entry.station_count); - blobmsg_add_u32(b, "ht", ap_entry.ht); - blobmsg_add_u32(b, "vht", ap_entry.vht); - } - - blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k])); - blobmsg_close_table(b, ap_list); } - blobmsg_close_table(b, client_list); + printf("OPEN TABLE!!!\n"); + ssid_list = blobmsg_open_table(b, (char*)ap_array[m].ssid); + + int i; + for (i = 0; i <= probe_entry_last; i++) { + if(!mac_is_equal(ap_array[m].bssid_addr, probe_array[i].bssid_addr)) + { + continue; + } + + int k; + sprintf(client_mac_buf, MACSTR, MAC2STR(probe_array[i].client_addr)); + client_list = blobmsg_open_table(b, client_mac_buf); + for (k = i; i <= probe_entry_last; k++) { + if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) { + i = k - 1; + break; + } + sprintf(ap_mac_buf, MACSTR, MAC2STR(probe_array[k].bssid_addr)); + ap_list = blobmsg_open_table(b, ap_mac_buf); + blobmsg_add_u32(b, "signal", probe_array[k].signal); + blobmsg_add_u32(b, "freq", probe_array[k].freq); + blobmsg_add_u8(b, "ht_support", probe_array[k].ht_support); + blobmsg_add_u8(b, "vht_support", probe_array[k].vht_support); + + ap ap_entry = ap_array_get_ap(probe_array[k].bssid_addr); + + // check if ap entry is available + if (mac_is_equal(ap_entry.bssid_addr, probe_array[k].bssid_addr)) { + blobmsg_add_u32(b, "channel_utilization", ap_entry.channel_utilization); + blobmsg_add_u32(b, "num_sta", ap_entry.station_count); + blobmsg_add_u32(b, "ht", ap_entry.ht); + blobmsg_add_u32(b, "vht", ap_entry.vht); + } + + blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k])); + blobmsg_close_table(b, ap_list); + } + blobmsg_close_table(b, client_list); + } + blobmsg_close_table(b, ssid_list); } pthread_mutex_unlock(&probe_array_mutex); return 0; @@ -174,6 +195,18 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { return score; } +int compare_ssid(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare) { + ap ap_entry_own = ap_array_get_ap(bssid_addr_own); + ap ap_entry_to_compre = ap_array_get_ap(bssid_addr_to_compare); + + if (mac_is_equal(ap_entry_own.bssid_addr, bssid_addr_own) && + mac_is_equal(ap_entry_to_compre.bssid_addr, bssid_addr_to_compare)) + { + return (strcmp((char*)ap_entry_own.ssid, (char*)ap_entry_to_compre.ssid) == 0); + } + return 0; +} + int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr, int automatic_kick) { @@ -255,14 +288,10 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat continue; } - // check if same essid!!! - if(compare_essid(bssid_addr, probe_array[k].bssid_addr) != 0) + // check if same ssid! + if(!compare_ssid(bssid_addr, probe_array[k].bssid_addr)) { - printf("ESSID ARE NOT THE SAME!\n"); continue; - } else - { - printf("ESSID ARE THE SAME!\n"); } @@ -620,12 +649,12 @@ ap ap_array_get_ap(uint8_t bssid_addr[]) { return ret; } - pthread_mutex_lock(&ap_array_mutex); int i; for (i = 0; i <= ap_entry_last; i++) { - if (mac_is_equal(bssid_addr, ap_array[i].bssid_addr) || mac_is_greater(ap_array[i].bssid_addr, bssid_addr)) { + if (mac_is_equal(bssid_addr, ap_array[i].bssid_addr)){ + //|| mac_is_greater(ap_array[i].bssid_addr, bssid_addr)) { break; } } @@ -644,9 +673,15 @@ void ap_array_insert(ap entry) { int i; for (i = 0; i <= ap_entry_last; i++) { - if (!mac_is_greater(entry.bssid_addr, ap_array[i].bssid_addr)) { + if (mac_is_greater(entry.bssid_addr, ap_array[i].bssid_addr) && + strcmp((char*)entry.ssid, (char*)ap_array[i].ssid) == 0) { + continue; + } + + if(!string_is_greater(entry.ssid, ap_array[i].ssid)){ break; } + } for (int j = ap_entry_last; j >= i; j--) { if (j + 1 <= ARRAY_AP_LEN) { diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 6b0fc6f..29b55cd 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -22,7 +22,7 @@ int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, floa #define IWINFO_ESSID_MAX_SIZE 32 -int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) +int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) { const struct iwinfo_ops *iw; diff --git a/src/utils/utils.c b/src/utils/utils.c index 8af0488..f49403e 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -1,6 +1,24 @@ #include "utils.h" #include "ubus.h" +int string_is_greater(uint8_t* str, uint8_t* str_2) { + + int length_1 = strlen((char*)str); + int length_2 = strlen((char*)str_2); + + int length = length_1 < length_2 ? length_1 : length_2; + + for (int i = 0; i < length; i++) { + if (str[i] > str_2[i]) { + return 1; + } + if (str[i] < str_2[i]) { + return 0; + } + } + return length_1 > length_2; +} + int hex_to_bin(char ch) { if ((ch >= '0') && (ch <= '9')) return ch - '0'; ch = tolower(ch); From 2d5607b4fc5500241a7fff123f989ea985c099ef Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 24 Dec 2017 20:14:12 +0100 Subject: [PATCH 11/14] print hearing map --- src/storage/datastorage.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 7ae1722..e0d3b80 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -73,6 +73,8 @@ struct uloop_timeout ap_timeout = { int build_hearing_map_sort_client(struct blob_buf *b) { + print_probe_array(); + pthread_mutex_lock(&probe_array_mutex); void *client_list, *ap_list, *ssid_list; From 66a9898eb614589bc26e550b8c9305b2e8a2a51f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 24 Dec 2017 20:35:12 +0100 Subject: [PATCH 12/14] fix hearingmap ubus call --- src/storage/datastorage.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index e0d3b80..9b90bfa 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -97,7 +97,18 @@ int build_hearing_map_sort_client(struct blob_buf *b) int i; for (i = 0; i <= probe_entry_last; i++) { - if(!mac_is_equal(ap_array[m].bssid_addr, probe_array[i].bssid_addr)) + /*if(!mac_is_equal(ap_array[m].bssid_addr, probe_array[i].bssid_addr)) + { + continue; + }*/ + + ap ap_entry_i = ap_array_get_ap(probe_array[i].bssid_addr); + + if (!mac_is_equal(ap_entry_i.bssid_addr, probe_array[i].bssid_addr)) { + continue; + } + + if(strcmp((char*)ap_entry_i.ssid, (char*)ap_array[m].ssid) != 0) { continue; } @@ -106,6 +117,17 @@ int build_hearing_map_sort_client(struct blob_buf *b) sprintf(client_mac_buf, MACSTR, MAC2STR(probe_array[i].client_addr)); client_list = blobmsg_open_table(b, client_mac_buf); for (k = i; i <= probe_entry_last; k++) { + ap ap_entry = ap_array_get_ap(probe_array[k].bssid_addr); + + if (!mac_is_equal(ap_entry.bssid_addr, probe_array[k].bssid_addr)) { + continue; + } + + if(strcmp((char*)ap_entry.ssid, (char*)ap_array[m].ssid) != 0) + { + continue; + } + if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) { i = k - 1; break; @@ -117,15 +139,12 @@ int build_hearing_map_sort_client(struct blob_buf *b) blobmsg_add_u8(b, "ht_support", probe_array[k].ht_support); blobmsg_add_u8(b, "vht_support", probe_array[k].vht_support); - ap ap_entry = ap_array_get_ap(probe_array[k].bssid_addr); // check if ap entry is available - if (mac_is_equal(ap_entry.bssid_addr, probe_array[k].bssid_addr)) { - blobmsg_add_u32(b, "channel_utilization", ap_entry.channel_utilization); - blobmsg_add_u32(b, "num_sta", ap_entry.station_count); - blobmsg_add_u32(b, "ht", ap_entry.ht); - blobmsg_add_u32(b, "vht", ap_entry.vht); - } + blobmsg_add_u32(b, "channel_utilization", ap_entry.channel_utilization); + blobmsg_add_u32(b, "num_sta", ap_entry.station_count); + blobmsg_add_u32(b, "ht", ap_entry.ht); + blobmsg_add_u32(b, "vht", ap_entry.vht); blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k])); blobmsg_close_table(b, ap_list); From e6e28e3b84b49a2279f334766c7fd93ad7a4472f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 24 Dec 2017 20:54:37 +0100 Subject: [PATCH 13/14] change sort string --- files/dawn.config | 2 +- src/storage/datastorage.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 94d35a9..5feddda 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -6,7 +6,7 @@ config network option iv 'Niiiiiiiiiiiiiik' config ordering - option sort_order 'csfb' + option sort_order 'cbfs' config hostapd option hostapd_dir '/var/run/hostapd' diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 9b90bfa..ed59c9a 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -127,7 +127,7 @@ int build_hearing_map_sort_client(struct blob_buf *b) { continue; } - + if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) { i = k - 1; break; From e6e63380afaabbda874cfd8814d4e00a59243cb9 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 24 Dec 2017 21:15:55 +0100 Subject: [PATCH 14/14] fix ap delete --- src/storage/datastorage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index ed59c9a..c7765fc 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -744,7 +744,7 @@ ap ap_array_delete(ap entry) { } void remove_old_client_entries(time_t current_time, long long int threshold) { - for (int i = 0; i < probe_entry_last; i++) { + for (int i = 0; i < client_entry_last; i++) { if (client_array[i].time < current_time - threshold) { client_array_delete(client_array[i]); } @@ -761,7 +761,7 @@ void remove_old_probe_entries(time_t current_time, long long int threshold) { } void remove_old_ap_entries(time_t current_time, long long int threshold) { - for (int i = 0; i < probe_entry_last; i++) { + for (int i = 0; i < ap_entry_last; i++) { if (ap_array[i].time < current_time - threshold) { ap_array_delete(ap_array[i]); }