From 061a477a205ecea1f99b3f581313f67fbfa9c88d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 18:29:20 +0100 Subject: [PATCH 1/5] fix if own station is already connected --- src/storage/datastorage.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index f5a2365..f75c2e6 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -271,14 +271,21 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar return ((int)ap_entry_own.station_count - 1) > (int)ap_entry_to_compre.station_count; } else { + int sta_count = ap_entry_own.station_count; int sta_count_to_compare = ap_entry_to_compre.station_count; + if(is_connected(bssid_addr_own, client_addr)) + { + printf("OWN IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); + sta_count--; + } + if(is_connected(bssid_addr_to_compare, client_addr)) { - printf("IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); + printf("COMPARE IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); sta_count_to_compare--; } - return (int)ap_entry_own.station_count > sta_count_to_compare; + return sta_count > sta_count_to_compare; } /* From 50167ac917c1aacff5c7bb51a81f942943fda4a2 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 19:01:30 +0100 Subject: [PATCH 2/5] refactor compare station count --- src/storage/datastorage.c | 43 ++++++++++++--------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index f75c2e6..3cf5ee9 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -267,39 +267,22 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar printf("Comparing own %d to %d\n", ap_entry_own.station_count, ap_entry_to_compre.station_count); - if (automatic_kick) { - return ((int)ap_entry_own.station_count - 1) > (int)ap_entry_to_compre.station_count; - } else { - - int sta_count = ap_entry_own.station_count; - int sta_count_to_compare = ap_entry_to_compre.station_count; - if(is_connected(bssid_addr_own, client_addr)) - { - printf("OWN IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); - sta_count--; - } - - if(is_connected(bssid_addr_to_compare, client_addr)) - { - printf("COMPARE IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); - sta_count_to_compare--; - } - - return sta_count > sta_count_to_compare; - } - - /* - int own_count = ap_entry_own.station_count; - if(automatic_kick) + int sta_count = ap_entry_own.station_count; + int sta_count_to_compare = ap_entry_to_compre.station_count; + if(is_connected(bssid_addr_own, client_addr)) { - own_count--; - } - if (is_connected(bssid_addr_to_compare, client_addr)) - { - own_count--; + printf("OWN IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); + sta_count--; } - return own_count > ap_entry_to_compre.station_count;*/ + if(is_connected(bssid_addr_to_compare, client_addr)) + { + printf("COMPARE IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); + sta_count_to_compare--; + } + printf("AFTER: Comparing own %d to %d\n", sta_count, sta_count_to_compare); + + return sta_count > sta_count_to_compare; } return 0; From a49dfdabcf55f21b71c007ad61084a1cb66bb73b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 31 Dec 2017 12:11:38 +0100 Subject: [PATCH 3/5] fix ubus calls --- src/storage/datastorage.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 3cf5ee9..39e963b 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -74,7 +74,6 @@ 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; @@ -116,7 +115,7 @@ int build_hearing_map_sort_client(struct blob_buf *b) 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++) { + for (k = i; k <= 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)) { @@ -159,8 +158,6 @@ int build_hearing_map_sort_client(struct blob_buf *b) int build_network_overview(struct blob_buf *b) { - pthread_mutex_lock(&probe_array_mutex); - void *client_list, *ap_list, *ssid_list; char ap_mac_buf[20]; char client_mac_buf[20]; @@ -191,7 +188,7 @@ int build_network_overview(struct blob_buf *b) sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr)); ap_list = blobmsg_open_table(b, ap_mac_buf); printf("AP MAC BUF: %s\n", ap_mac_buf); - for (k = i; i <= client_entry_last; k++){ + for (k = i; k <= client_entry_last; k++){ if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) { i = k - 1; @@ -209,7 +206,6 @@ int build_network_overview(struct blob_buf *b) } blobmsg_close_table(b, ssid_list); } - pthread_mutex_unlock(&probe_array_mutex); return 0; } From 8e2ee4ee7c682b27bc70cc3be5c8261fee50e5ca Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 1 Jan 2018 15:07:34 +0100 Subject: [PATCH 4/5] fix ubus call --- src/storage/datastorage.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 39e963b..4e18629 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -130,7 +130,11 @@ int build_hearing_map_sort_client(struct blob_buf *b) if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) { i = k - 1; break; + } else if(k == probe_entry_last) + { + i = k; } + 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); @@ -193,6 +197,9 @@ int build_network_overview(struct blob_buf *b) { i = k - 1; break; + } else if(k == client_entry_last) + { + i = k; } sprintf(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr)); From 4daa5daa7faaeed09ac0e7fbf648eaa1227864be Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 1 Jan 2018 15:20:17 +0100 Subject: [PATCH 5/5] set negative score to -2 and only compare station count ... --- src/storage/datastorage.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 4e18629..b595d99 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -237,7 +237,7 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { score += (probe_entry.signal <= dawn_metric.low_rssi_val) ? dawn_metric.low_rssi : 0; if(score < 0) - score = 0; + score = -2; // -1 already used... printf("SCORE: %d of:\n", score); print_probe_entry(probe_entry); @@ -353,12 +353,15 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat } 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, probe_array[k].client_addr, automatic_kick)) { - return 1; + // only compare if score is bigger or euqal 0 + if(own_score >= 0) { + + // if ap have same value but station count is different... + if (compare_station_count(bssid_addr, probe_array[k].bssid_addr, probe_array[k].client_addr, + automatic_kick)) { + return 1; + } } - - } } return 0;