From 6ac15a5bac4e2529cb9977e3cd639bf2ee58eb0c Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 19 Oct 2017 15:37:09 +0200 Subject: [PATCH 001/174] Prase rssi from iwinfo --- src/CMakeLists.txt | 2 +- src/include/rssi.h | 14 +++++++ src/include/ubus.h | 2 + src/include/utils.h | 1 + src/storage/datastorage.c | 76 +++++++++++++++++++++++++++++++++++++- src/utils/rssi.c | 78 +++++++++++++++++++++++++++++++++++++++ src/utils/ubus.c | 26 ++++++++++++- src/utils/utils.c | 22 ++++++++++- 8 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 src/include/rssi.h create mode 100644 src/utils/rssi.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d48466e..e9acdc3 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ SET(SOURCES crypto/base64.c include/base64.h - utils/utils.c) + utils/utils.c include/rssi.h utils/rssi.c) SET(LIBS ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto) diff --git a/src/include/rssi.h b/src/include/rssi.h new file mode 100644 index 0000000..d0c56ed --- /dev/null +++ b/src/include/rssi.h @@ -0,0 +1,14 @@ +// +// Created by nick on 19.10.17. +// + +#ifndef DAWN_RSSI_H +#define DAWN_RSSI_H + +#include +#include +#include + +int get_rssi_from_iwinfo(__uint8_t* client_addr); + +#endif //DAWN_RSSI_H diff --git a/src/include/ubus.h b/src/include/ubus.h index e2356bd..0395af6 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -28,4 +28,6 @@ char *hostapd_dir_glob; int ubus_call_umdns(); +int ubus_send_probe_via_network(struct probe_entry_s probe_entry); + #endif diff --git a/src/include/utils.h b/src/include/utils.h index 79f9863..941efe1 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -9,5 +9,6 @@ int hex_to_bin(char ch); int hwaddr_aton(const char *txt, uint8_t *addr); +int convert_mac(char* in, char* out); #endif \ No newline at end of file diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 52f897b..ce091d9 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -1,6 +1,9 @@ #include "datastorage.h" +#include + #include "ubus.h" +#include "rssi.h" #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] @@ -32,6 +35,10 @@ void remove_old_ap_entries(time_t current_time, long long int threshold); void print_ap_entry(ap entry); +int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t rssi); + +int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]); + int probe_entry_last = -1; int client_entry_last = -1; int ap_entry_last = -1; @@ -129,13 +136,29 @@ void kick_clients(uint8_t bssid[], uint32_t id) { if (!mac_is_equal(client_array[j].bssid_addr, bssid)) { break; } + + // update rssi + int rssi = get_rssi_from_iwinfo(client_array[j].client_addr); + if(rssi != INT_MIN) + { + printf("UPDATING RSSI!!!\n"); + pthread_mutex_unlock(&probe_array_mutex); + if(probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) + { + printf("RSSI UPDATED!!!\n"); + } + pthread_mutex_lock(&probe_array_mutex); + + } + if (kick_client(client_array[j]) > 0) { // TODO: Better debug output printf("KICKING CLIENT!!!!!!!!!!!!!\n"); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); } else if (kick_client(client_array[j]) == -1) { printf("Force client to reconnect!!!!!!!!!!!!!\n"); - del_client_interface(id, client_array[j].client_addr, 0, 0, 0); + printf("TRY TO READ RSSI!\n"); + //del_client_interface(id, client_array[j].client_addr, 0, 0, 0); } else { printf("STAAAY CLIENT!!!!!!!!!!!!!\n"); } @@ -145,6 +168,27 @@ void kick_clients(uint8_t bssid[], uint32_t id) { pthread_mutex_unlock(&client_array_mutex); } +int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]) +{ + int i; + int found_in_array = 0; + + if (client_entry_last == -1) { + return 0; + } + + for (i = 0; i <= client_entry_last; i++) { + + if ( mac_is_equal(bssid_addr, client_array[i].bssid_addr) && + mac_is_equal(client_addr, client_array[i].client_addr)) + { + found_in_array = 1; + break; + } + } + return found_in_array; +} + int client_array_go_next_help(char sort_order[], int i, client entry, client next_entry) { switch (sort_order[i]) { @@ -298,6 +342,33 @@ probe_entry probe_array_delete(probe_entry entry) { return tmp; } +int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t rssi) { + + printf("Try to find probe reqeuest...\n"); + + int updated = 0; + + if (probe_entry_last == -1) { + return 0; + } + + + pthread_mutex_lock(&probe_array_mutex); + for (int i = 0; i <= probe_entry_last; i++) { + if (mac_is_equal(bssid_addr, probe_array[i].bssid_addr) && + mac_is_equal(client_addr, probe_array[i].client_addr)) { + probe_array[i].signal = rssi; + updated = 1; + // TODO: Send updatet probe to others :'( + printf("NOW SENDING TO THE OTHERS!!!\n"); + ubus_send_probe_via_network(probe_array[i]); + } + } + pthread_mutex_unlock(&probe_array_mutex); + + return updated; +} + probe_entry probe_array_get_entry(uint8_t bssid_addr[], uint8_t client_addr[]) { int i; @@ -456,7 +527,8 @@ void remove_old_client_entries(time_t current_time, long long int threshold) { void remove_old_probe_entries(time_t current_time, long long int threshold) { for (int i = 0; i < probe_entry_last; i++) { if (probe_array[i].time < current_time - threshold) { - probe_array_delete(probe_array[i]); + if(!is_connected(probe_array[i].bssid_addr, probe_array[i].client_addr)) + probe_array_delete(probe_array[i]); } } } diff --git a/src/utils/rssi.c b/src/utils/rssi.c new file mode 100644 index 0000000..8523849 --- /dev/null +++ b/src/utils/rssi.c @@ -0,0 +1,78 @@ +#include "rssi.h" + +#include + +#include "utils.h" + +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] + +int call_iwinfo(char* client_addr); +int parse_rssi(char* iwinfo_string); + +int get_rssi_from_iwinfo(__uint8_t* client_addr) +{ + char mac_buf[20]; + sprintf(mac_buf, "%x:%x:%x:%x:%x:%x", MAC2STR(client_addr)); + char mac_buf_conv[20]; + + convert_mac(mac_buf, mac_buf_conv); + + return call_iwinfo(mac_buf_conv); +} + +int call_iwinfo(char* client_addr) +{ + FILE *fp; + char path[1035]; + + /* Open the command for reading. */ + + // TODO: refactor this + int rssi = INT_MIN; + int command_length = 68; + char iwinfo_command[command_length]; + char* first_command = "(iwinfo wlan0 assoc && iwinfo wlan1 assoc) | grep "; + size_t length_first_command = strlen(first_command); + memcpy(iwinfo_command, first_command, length_first_command); + memcpy(iwinfo_command + length_first_command, client_addr, strlen(client_addr)); + iwinfo_command[command_length - 1] = '\0'; + printf("iwinfo command:\n%s\n", iwinfo_command); + + + fp = popen(iwinfo_command, "r"); + if (fp == NULL) { + printf("Failed to run command\n" ); + exit(1); + } + + /* Read the output a line at a time - output it. */ + while (fgets(path, sizeof(path)-1, fp) != NULL) { + rssi = parse_rssi(path); + } + + /* close */ + pclose(fp); + + return rssi; +} + +int parse_rssi(char* iwinfo_string) +{ + char cut_1[] = " "; + char cut_2[] = "dBm"; + char *p_1 = strstr(iwinfo_string, cut_1); + char *p_2 = strstr(iwinfo_string, cut_2); + int rssi = INT_MIN; + if(p_1 != NULL && p_2 != NULL) + { + printf("Found substring: %s", p_2); + printf("Length: %d\n", p_2 - p_1); + int length = (int) (p_2 - p_1); + char dest[length + 1]; + memcpy(dest, p_1, (int) (p_2 - p_1)); + dest[length] = '\0'; + rssi = atoi(dest); + printf("After cutting:\n%s\nInt:%d\n", dest, rssi); + } + return rssi; +} \ No newline at end of file diff --git a/src/utils/ubus.c b/src/utils/ubus.c index c4e792d..d8544ae 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -611,7 +611,6 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr * printf("UMDNS:\n%s", str); } - int ubus_call_umdns() { u_int32_t id; @@ -622,5 +621,30 @@ int ubus_call_umdns() int timeout = 1; ubus_invoke(ctx_clients, id, "browse", NULL, ubus_umdns_cb, NULL, timeout * 1000); + return 0; +} + +int ubus_send_probe_via_network(struct probe_entry_s probe_entry) +{ + printf("Try to send new probe!!!\n"); + + static struct blob_buf b; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "bssid", probe_entry.bssid_addr); + blobmsg_add_macaddr(&b, "address", probe_entry.client_addr); + blobmsg_add_macaddr(&b, "target", probe_entry.target_addr); + blobmsg_add_u32(&b, "signal", probe_entry.signal); + blobmsg_add_u32(&b, "freq", probe_entry.freq); + blobmsg_add_u8(&b, "ht_support", probe_entry.ht_support); + blobmsg_add_u8(&b, "vht_support", probe_entry.vht_support); + + // send probe via network + char *str; + str = blobmsg_format_json(b.head, 1); + send_string_enc(str); + + printf("SENDING NEW PROBE!!!: %s\n", str); + return 0; } \ No newline at end of file diff --git a/src/utils/utils.c b/src/utils/utils.c index f200114..13c5da6 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -23,4 +23,24 @@ int hwaddr_aton(const char *txt, uint8_t *addr) { } return 0; -} \ No newline at end of file +} + +int convert_mac(char* in, char* out) { + int i,j = 0; + + for (i = 0; i < 6; i++) { + if(in[j+1] != ':' && in[j+1] != '\0') { + out[3 * i] = toupper(in[j]); + out[(3 * i) + 1] = toupper(in[j + 1]); + out[(3 * i) + 2] = in[j + 2]; + j+= 3; + } else { + out[3 * i] = '0'; + out[(3 * i) + 1] = toupper(in[j]); + out[(3 * i) + 2] = toupper(in[j+1]); + j += 2; + } + } + return 0; +} + From c41ff502b4130e0a7205df81be51104f37bad9d4 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 23 Oct 2017 15:23:12 +0200 Subject: [PATCH 002/174] improve debug msgs --- src/storage/datastorage.c | 19 ++++++++++++------- src/utils/rssi.c | 9 ++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index ce091d9..25efcb3 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -141,7 +141,6 @@ void kick_clients(uint8_t bssid[], uint32_t id) { int rssi = get_rssi_from_iwinfo(client_array[j].client_addr); if(rssi != INT_MIN) { - printf("UPDATING RSSI!!!\n"); pthread_mutex_unlock(&probe_array_mutex); if(probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) { @@ -151,16 +150,22 @@ void kick_clients(uint8_t bssid[], uint32_t id) { } + // better ap available if (kick_client(client_array[j]) > 0) { - // TODO: Better debug output - printf("KICKING CLIENT!!!!!!!!!!!!!\n"); + printf("Better AP available. Kicking client:\n"); + print_client_entry(client_array[j]); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); + + // no entry in probe array for own bssid } else if (kick_client(client_array[j]) == -1) { - printf("Force client to reconnect!!!!!!!!!!!!!\n"); - printf("TRY TO READ RSSI!\n"); - //del_client_interface(id, client_array[j].client_addr, 0, 0, 0); + printf("No Information about client. Force reconnect:\n"); + print_client_entry(client_array[j]); + del_client_interface(id, client_array[j].client_addr, 0, 0, 0); + + // ap is best } else { - printf("STAAAY CLIENT!!!!!!!!!!!!!\n"); + printf("AP is best. Client will stay:\n"); + print_client_entry(client_array[j]); } } diff --git a/src/utils/rssi.c b/src/utils/rssi.c index 8523849..0e54c93 100644 --- a/src/utils/rssi.c +++ b/src/utils/rssi.c @@ -22,12 +22,11 @@ int get_rssi_from_iwinfo(__uint8_t* client_addr) int call_iwinfo(char* client_addr) { + // TODO: REFACTOR THIS! USE NET LINK... LOOK AT IWINFO + FILE *fp; char path[1035]; - /* Open the command for reading. */ - - // TODO: refactor this int rssi = INT_MIN; int command_length = 68; char iwinfo_command[command_length]; @@ -38,7 +37,6 @@ int call_iwinfo(char* client_addr) iwinfo_command[command_length - 1] = '\0'; printf("iwinfo command:\n%s\n", iwinfo_command); - fp = popen(iwinfo_command, "r"); if (fp == NULL) { printf("Failed to run command\n" ); @@ -65,14 +63,11 @@ int parse_rssi(char* iwinfo_string) int rssi = INT_MIN; if(p_1 != NULL && p_2 != NULL) { - printf("Found substring: %s", p_2); - printf("Length: %d\n", p_2 - p_1); int length = (int) (p_2 - p_1); char dest[length + 1]; memcpy(dest, p_1, (int) (p_2 - p_1)); dest[length] = '\0'; rssi = atoi(dest); - printf("After cutting:\n%s\nInt:%d\n", dest, rssi); } return rssi; } \ No newline at end of file From 59a3de5f5ce11abfde27ebc671649f51d25687a0 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 23 Oct 2017 15:27:47 +0200 Subject: [PATCH 003/174] improve debug msgs --- 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 25efcb3..5a5eed1 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -142,9 +142,9 @@ void kick_clients(uint8_t bssid[], uint32_t id) { 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)) + if(!probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) { - printf("RSSI UPDATED!!!\n"); + printf("Failed to update RSSI!\n"); } pthread_mutex_lock(&probe_array_mutex); @@ -349,8 +349,6 @@ probe_entry probe_array_delete(probe_entry entry) { int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t rssi) { - printf("Try to find probe reqeuest...\n"); - int updated = 0; if (probe_entry_last == -1) { @@ -364,8 +362,6 @@ int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_ mac_is_equal(client_addr, probe_array[i].client_addr)) { probe_array[i].signal = rssi; updated = 1; - // TODO: Send updatet probe to others :'( - printf("NOW SENDING TO THE OTHERS!!!\n"); ubus_send_probe_via_network(probe_array[i]); } } From 2c0cab9ca2fc4d5884eb6f29e2905bdda948c85c Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 23 Oct 2017 15:38:45 +0200 Subject: [PATCH 004/174] remove comments --- src/include/rssi.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/include/rssi.h b/src/include/rssi.h index d0c56ed..fcb06f3 100644 --- a/src/include/rssi.h +++ b/src/include/rssi.h @@ -1,7 +1,3 @@ -// -// Created by nick on 19.10.17. -// - #ifndef DAWN_RSSI_H #define DAWN_RSSI_H From 377d0815e923634b1d2ec6f0cb658b42007eb622 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 23 Oct 2017 15:45:37 +0200 Subject: [PATCH 005/174] reformat code --- src/CMakeLists.txt | 48 ++++++++++++++-------------- src/crypto/crypto.c | 2 +- src/include/crypto.h | 5 ++- src/include/datastorage.h | 3 ++ src/include/rssi.h | 2 +- src/include/utils.h | 4 ++- src/main.c | 17 +++++----- src/network/networksocket.c | 4 +-- src/storage/datastorage.c | 44 ++++++++++++-------------- src/utils/dawn_uci.c | 62 ++++++++++++++++++------------------- src/utils/rssi.c | 23 ++++++-------- src/utils/ubus.c | 16 ++++------ src/utils/utils.c | 10 +++--- 13 files changed, 116 insertions(+), 124 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9acdc3..c2cbe83 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,46 +8,46 @@ ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-unknow SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") SET(SOURCES - main.c + main.c - storage/datastorage.c - include/datastorage.h + storage/datastorage.c + include/datastorage.h - network/networksocket.c - include/networksocket.h + network/networksocket.c + include/networksocket.h - network/broadcastsocket.c - include/broadcastsocket.h + network/broadcastsocket.c + include/broadcastsocket.h - network/multicastsocket.c - include/multicastsocket.h + network/multicastsocket.c + include/multicastsocket.h - utils/ubus.c - include/ubus.h + utils/ubus.c + include/ubus.h - include/utils.h + include/utils.h - utils/runopts.c - include/runopts.h + utils/runopts.c + include/runopts.h - utils/dawn_uci.c - include/dawn_uci.h + utils/dawn_uci.c + include/dawn_uci.h - crypto/crypto.c - include/crypto.h + crypto/crypto.c + include/crypto.h - crypto/base64.c - include/base64.h + crypto/base64.c + include/base64.h - utils/utils.c include/rssi.h utils/rssi.c) + utils/utils.c include/rssi.h utils/rssi.c) SET(LIBS - ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto) + ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto) ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h) TARGET_LINK_LIBRARIES(dawn ${LIBS}) INSTALL(TARGETS dawn - RUNTIME DESTINATION /usr/bin/ -) \ No newline at end of file + RUNTIME DESTINATION /usr/bin/ + ) \ No newline at end of file diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c index ab38eaa..00c0832 100644 --- a/src/crypto/crypto.c +++ b/src/crypto/crypto.c @@ -59,7 +59,7 @@ void gcrypt_set_key_and_iv(char *key, char *iv) { } // free out buffer after using! -char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int* out_length) { +char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length) { if (0U != (msg_length & 0xfU)) msg_length += 0x10U - (msg_length & 0xfU); diff --git a/src/include/crypto.h b/src/include/crypto.h index 794186f..8124b2d 100644 --- a/src/include/crypto.h +++ b/src/include/crypto.h @@ -12,7 +12,7 @@ void gcrypt_init(); void gcrypt_set_key_and_iv(char *key, char *iv); //char *gcrypt_encrypt_msg(char *msg, size_t msg_length); -char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int* out_length); +char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length); char *gcrypt_decrypt_msg(char *msg, size_t msg_length); @@ -31,8 +31,11 @@ void build_decoding_table(); void base64_cleanup(); int Base64decode_len(const char *bufcoded); + int Base64encode_len(int len); + int Base64encode(char *encoded, const char *string, int len); + int Base64decode(char *bufplain, const char *bufcoded); diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 6d5659d..889dcfc 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -101,8 +101,11 @@ struct ap_s ap_array[ARRAY_AP_LEN]; pthread_mutex_t ap_array_mutex; ap insert_to_ap_array(ap entry); + void print_ap_array(); + void *remove_ap_array_thread(void *arg); + ap ap_array_get_ap(uint8_t bssid_addr[]); // Array diff --git a/src/include/rssi.h b/src/include/rssi.h index fcb06f3..5f135d9 100644 --- a/src/include/rssi.h +++ b/src/include/rssi.h @@ -5,6 +5,6 @@ #include #include -int get_rssi_from_iwinfo(__uint8_t* client_addr); +int get_rssi_from_iwinfo(__uint8_t *client_addr); #endif //DAWN_RSSI_H diff --git a/src/include/utils.h b/src/include/utils.h index 941efe1..5b86370 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -8,7 +8,9 @@ #define STR2MAC(a) &(a)[0], &(a)[1], &(a)[2], &(a)[3], &(a)[4], &(a)[5] int hex_to_bin(char ch); + int hwaddr_aton(const char *txt, uint8_t *addr); -int convert_mac(char* in, char* out); + +int convert_mac(char *in, char *out); #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 4036535..33dd421 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ #include "crypto.h" #define _GNU_SOURCE + #include #include @@ -42,8 +43,7 @@ pthread_t tid_get_client; pthread_t tid_kick_clients; pthread_t tid_ap; -void daemon_shutdown() -{ +void daemon_shutdown() { // kill threads printf("Cancelling Threads!\n"); pthread_cancel(tid_probe); @@ -62,11 +62,9 @@ void daemon_shutdown() //printf("Free Counter: %d\n", free_counter); } -void signal_handler(int sig) -{ +void signal_handler(int sig) { printf("SOME SIGNAL RECEIVED!\n"); - switch(sig) - { + switch (sig) { case SIGHUP: //syslog(LOG_WARNING, "Received SIGHUP signal."); break; @@ -82,6 +80,7 @@ void signal_handler(int sig) break; } } + /* static void mtrace_init(void) { @@ -211,9 +210,9 @@ int main(int argc, char **argv) { init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); - pthread_create(&tid_probe, NULL, &remove_array_thread, (void*)&time_config.remove_probe); - pthread_create(&tid_client, NULL, &remove_client_array_thread, (void*)&time_config.remove_client); - pthread_create(&tid_get_client, NULL, &update_clients_thread, (void*)&time_config.update_client); + pthread_create(&tid_probe, NULL, &remove_array_thread, (void *) &time_config.remove_probe); + pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client); + pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); //pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL); //pthread_create(&tid_ap, NULL, &remove_ap_array_thread, NULL); diff --git a/src/network/networksocket.c b/src/network/networksocket.c index 24fa4a1..6258ae5 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -141,7 +141,7 @@ void *receive_msg_enc(void *args) { } //recv_string[recv_string_len] = '\0'; - char* base64_dec_str = malloc(Base64decode_len(recv_string)); + char *base64_dec_str = malloc(Base64decode_len(recv_string)); int base64_dec_length = Base64decode(base64_dec_str, recv_string); char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length); @@ -214,7 +214,7 @@ int send_string_enc(char *msg) { int length_enc; char *enc = gcrypt_encrypt_msg(msg, msglen + 1, &length_enc); - char* base64_enc_str = malloc(Base64encode_len(length_enc)); + char *base64_enc_str = malloc(Base64encode_len(length_enc)); size_t base64_enc_length = Base64encode(base64_enc_str, enc, length_enc); if (sendto(sock, diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 5a5eed1..2b7c0c4 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -50,7 +50,7 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { ap ap_entry = ap_array_get_ap(probe_entry.bssid_addr); // check if ap entry is available - if(mac_is_equal(ap_entry.bssid_addr, probe_entry.bssid_addr)) { + if (mac_is_equal(ap_entry.bssid_addr, probe_entry.bssid_addr)) { score += probe_entry.ht_support ? dawn_metric.ht_support : 0; score += !probe_entry.ht_support && !ap_entry.ht ? dawn_metric.no_ht_support : 0; score += probe_entry.vht_support ? dawn_metric.vht_support : 0; @@ -67,8 +67,7 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { return score; } -int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) -{ +int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) { int own_score = -1; // find first client entry in probe array @@ -95,8 +94,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) } // no entry for own ap - if(own_score == -1) - { + if (own_score == -1) { return -1; } @@ -106,7 +104,8 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) break; } if (!mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && - own_score < eval_probe_metric(probe_array[k])) // that's wrong! find client_entry OR write things in probe array struct! + own_score < + eval_probe_metric(probe_array[k])) // that's wrong! find client_entry OR write things in probe array struct! { return 1; } @@ -139,11 +138,9 @@ void kick_clients(uint8_t bssid[], uint32_t id) { // update rssi int rssi = get_rssi_from_iwinfo(client_array[j].client_addr); - if(rssi != INT_MIN) - { + 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)) - { + if (!probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) { printf("Failed to update RSSI!\n"); } pthread_mutex_lock(&probe_array_mutex); @@ -156,13 +153,13 @@ void kick_clients(uint8_t bssid[], uint32_t id) { print_client_entry(client_array[j]); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); - // no entry in probe array for own bssid + // no entry in probe array for own bssid } else if (kick_client(client_array[j]) == -1) { printf("No Information about client. Force reconnect:\n"); print_client_entry(client_array[j]); del_client_interface(id, client_array[j].client_addr, 0, 0, 0); - // ap is best + // ap is best } else { printf("AP is best. Client will stay:\n"); print_client_entry(client_array[j]); @@ -173,8 +170,7 @@ void kick_clients(uint8_t bssid[], uint32_t id) { pthread_mutex_unlock(&client_array_mutex); } -int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]) -{ +int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]) { int i; int found_in_array = 0; @@ -184,9 +180,8 @@ int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]) for (i = 0; i <= client_entry_last; i++) { - if ( mac_is_equal(bssid_addr, client_array[i].bssid_addr) && - mac_is_equal(client_addr, client_array[i].client_addr)) - { + if (mac_is_equal(bssid_addr, client_array[i].bssid_addr) && + mac_is_equal(client_addr, client_array[i].client_addr)) { found_in_array = 1; break; } @@ -450,12 +445,11 @@ ap ap_array_get_ap(uint8_t bssid_addr[]) { } - 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; } } @@ -474,7 +468,7 @@ 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)) { break; } } @@ -528,7 +522,7 @@ void remove_old_client_entries(time_t current_time, long long int threshold) { void remove_old_probe_entries(time_t current_time, long long int threshold) { for (int i = 0; i < probe_entry_last; i++) { if (probe_array[i].time < current_time - threshold) { - if(!is_connected(probe_array[i].bssid_addr, probe_array[i].client_addr)) + if (!is_connected(probe_array[i].bssid_addr, probe_array[i].client_addr)) probe_array_delete(probe_array[i]); } } @@ -543,8 +537,8 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) { } void *remove_array_thread(void *arg) { - printf("Removing thread with time: %lu\n", *(long int*)arg); - time_t time_treshold = *(time_t*)arg; + printf("Removing thread with time: %lu\n", *(long int *) arg); + time_t time_treshold = *(time_t *) arg; while (1) { sleep(time_treshold); pthread_mutex_lock(&probe_array_mutex); @@ -556,7 +550,7 @@ void *remove_array_thread(void *arg) { } void *remove_client_array_thread(void *arg) { - time_t time_treshold_client = *(time_t*)arg; + time_t time_treshold_client = *(time_t *) arg; printf("Removing client thread with time: %lu\n", time_treshold_client); while (1) { sleep(time_treshold_client); @@ -569,7 +563,7 @@ void *remove_client_array_thread(void *arg) { } void *remove_ap_array_thread(void *arg) { - time_t time_treshold_ap = *(time_t*)arg; + time_t time_treshold_ap = *(time_t *) arg; printf("Removing ap thread with time: %lu\n", time_treshold_ap); while (1) { sleep(time_treshold_ap); diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 3d3a06c..f93187c 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -20,40 +20,39 @@ dawn.metric.freq option remove_probe '120' */ -struct time_config_s uci_get_time_config() -{ +struct time_config_s uci_get_time_config() { struct time_config_s ret; struct uci_context *c; struct uci_ptr ptr; - c = uci_alloc_context (); + c = uci_alloc_context(); printf("Loading TImes!"); char tmp_update_client[] = "dawn.times.update_client"; - if (uci_lookup_ptr (c, &ptr, tmp_update_client, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_update_client, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.update_client = atoi(ptr.o->v.string); char tmp_remove_client[] = "dawn.times.remove_client"; - if (uci_lookup_ptr (c, &ptr, tmp_remove_client, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_remove_client, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.remove_client = atoi(ptr.o->v.string); char tmp_remove_probe[] = "dawn.times.remove_probe"; - if (uci_lookup_ptr (c, &ptr, tmp_remove_probe, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_remove_probe, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.remove_probe = atoi(ptr.o->v.string); printf("Times: %lu, %lu, %lu\n", ret.update_client, ret.remove_client, ret.remove_probe); @@ -63,95 +62,94 @@ struct time_config_s uci_get_time_config() return ret; } -struct probe_metric_s uci_get_dawn_metric() -{ +struct probe_metric_s uci_get_dawn_metric() { struct probe_metric_s ret; struct uci_context *c; struct uci_ptr ptr; - c = uci_alloc_context (); + c = uci_alloc_context(); char tmp_ht_support[] = "dawn.metric.ht_support"; - if (uci_lookup_ptr (c, &ptr, tmp_ht_support, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_ht_support, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.ht_support = atoi(ptr.o->v.string); char tmp_vht_support[] = "dawn.metric.vht_support"; - if (uci_lookup_ptr (c, &ptr, tmp_vht_support, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_vht_support, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.vht_support = atoi(ptr.o->v.string); char tmp_no_ht_support[] = "dawn.metric.no_ht_support"; - if (uci_lookup_ptr (c, &ptr, tmp_no_ht_support, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_no_ht_support, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.no_ht_support = atoi(ptr.o->v.string); char tmp_no_vht_support[] = "dawn.metric.no_vht_support"; - if (uci_lookup_ptr (c, &ptr, tmp_no_vht_support, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_no_vht_support, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.no_vht_support = atoi(ptr.o->v.string); char tmp_rssi[] = "dawn.metric.rssi"; - if (uci_lookup_ptr (c, &ptr, tmp_rssi, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_rssi, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.rssi = atoi(ptr.o->v.string); char tmp_freq[] = "dawn.metric.freq"; - if (uci_lookup_ptr (c, &ptr, tmp_freq, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_freq, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.freq = atoi(ptr.o->v.string); char tmp_util[] = "dawn.metric.chan_util"; - if (uci_lookup_ptr (c, &ptr, tmp_util, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_util, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.chan_util = atoi(ptr.o->v.string); char tmp_min_rssi[] = "dawn.metric.min_rssi"; - if (uci_lookup_ptr (c, &ptr, tmp_min_rssi, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_min_rssi, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.min_rssi = atoi(ptr.o->v.string); char tmp_max_chan_util[] = "dawn.metric.max_chan_util"; - if (uci_lookup_ptr (c, &ptr, tmp_max_chan_util, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.max_chan_util = atoi(ptr.o->v.string); printf("Try to load min_probe_count\n"); char tmp_min_probe_count[] = "dawn.metric.min_probe_count"; - if (uci_lookup_ptr (c, &ptr, tmp_min_probe_count, 1) != UCI_OK) { + if (uci_lookup_ptr(c, &ptr, tmp_min_probe_count, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } - if(ptr.o->type == UCI_TYPE_STRING) + if (ptr.o->type == UCI_TYPE_STRING) ret.min_probe_count = atoi(ptr.o->v.string); printf("Loaded metric: %d\n", ret.min_probe_count); diff --git a/src/utils/rssi.c b/src/utils/rssi.c index 0e54c93..afbb241 100644 --- a/src/utils/rssi.c +++ b/src/utils/rssi.c @@ -6,11 +6,11 @@ #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] -int call_iwinfo(char* client_addr); -int parse_rssi(char* iwinfo_string); +int call_iwinfo(char *client_addr); -int get_rssi_from_iwinfo(__uint8_t* client_addr) -{ +int parse_rssi(char *iwinfo_string); + +int get_rssi_from_iwinfo(__uint8_t *client_addr) { char mac_buf[20]; sprintf(mac_buf, "%x:%x:%x:%x:%x:%x", MAC2STR(client_addr)); char mac_buf_conv[20]; @@ -20,8 +20,7 @@ int get_rssi_from_iwinfo(__uint8_t* client_addr) return call_iwinfo(mac_buf_conv); } -int call_iwinfo(char* client_addr) -{ +int call_iwinfo(char *client_addr) { // TODO: REFACTOR THIS! USE NET LINK... LOOK AT IWINFO FILE *fp; @@ -30,7 +29,7 @@ int call_iwinfo(char* client_addr) int rssi = INT_MIN; int command_length = 68; char iwinfo_command[command_length]; - char* first_command = "(iwinfo wlan0 assoc && iwinfo wlan1 assoc) | grep "; + char *first_command = "(iwinfo wlan0 assoc && iwinfo wlan1 assoc) | grep "; size_t length_first_command = strlen(first_command); memcpy(iwinfo_command, first_command, length_first_command); memcpy(iwinfo_command + length_first_command, client_addr, strlen(client_addr)); @@ -39,12 +38,12 @@ int call_iwinfo(char* client_addr) fp = popen(iwinfo_command, "r"); if (fp == NULL) { - printf("Failed to run command\n" ); + printf("Failed to run command\n"); exit(1); } /* Read the output a line at a time - output it. */ - while (fgets(path, sizeof(path)-1, fp) != NULL) { + while (fgets(path, sizeof(path) - 1, fp) != NULL) { rssi = parse_rssi(path); } @@ -54,15 +53,13 @@ int call_iwinfo(char* client_addr) return rssi; } -int parse_rssi(char* iwinfo_string) -{ +int parse_rssi(char *iwinfo_string) { char cut_1[] = " "; char cut_2[] = "dBm"; char *p_1 = strstr(iwinfo_string, cut_1); char *p_2 = strstr(iwinfo_string, cut_2); int rssi = INT_MIN; - if(p_1 != NULL && p_2 != NULL) - { + if (p_1 != NULL && p_2 != NULL) { int length = (int) (p_2 - p_1); char dest[length + 1]; memcpy(dest, p_1, (int) (p_2 - p_1)); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index d8544ae..040ca87 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -283,18 +283,16 @@ static int handle_probe_req(struct blob_attr *msg) { static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - printf("METHOD new: %s\n",method); + printf("METHOD new: %s\n", method); // TODO: Only handle probe request and NOT assoc, ... if (strncmp(method, "probe", 5) == 0) { return handle_probe_req(msg); - } - else if (strncmp(method, "auth", 4) == 0) { + } else if (strncmp(method, "auth", 4) == 0) { return handle_auth_req(msg); - } - else if (strncmp(method, "assoc", 5) == 0) { + } else if (strncmp(method, "assoc", 5) == 0) { return handle_assoc_req(msg); } return 0; @@ -515,7 +513,7 @@ static int ubus_get_clients() { } void *update_clients_thread(void *arg) { - time_t time_update_client = *(time_t*)arg; + time_t time_update_client = *(time_t *) arg; printf("Update client thread with time: %lu\n", time_update_client); const char *ubus_socket = NULL; @@ -611,8 +609,7 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr * printf("UMDNS:\n%s", str); } -int ubus_call_umdns() -{ +int ubus_call_umdns() { u_int32_t id; if (ubus_lookup_id(ctx, "umdns", &id)) { fprintf(stderr, "Failed to look up test object for %s\n", "umdns"); @@ -624,8 +621,7 @@ int ubus_call_umdns() return 0; } -int ubus_send_probe_via_network(struct probe_entry_s probe_entry) -{ +int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { printf("Try to send new probe!!!\n"); static struct blob_buf b; diff --git a/src/utils/utils.c b/src/utils/utils.c index 13c5da6..323d4b2 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -25,19 +25,19 @@ int hwaddr_aton(const char *txt, uint8_t *addr) { return 0; } -int convert_mac(char* in, char* out) { - int i,j = 0; +int convert_mac(char *in, char *out) { + int i, j = 0; for (i = 0; i < 6; i++) { - if(in[j+1] != ':' && in[j+1] != '\0') { + if (in[j + 1] != ':' && in[j + 1] != '\0') { out[3 * i] = toupper(in[j]); out[(3 * i) + 1] = toupper(in[j + 1]); out[(3 * i) + 2] = in[j + 2]; - j+= 3; + j += 3; } else { out[3 * i] = '0'; out[(3 * i) + 1] = toupper(in[j]); - out[(3 * i) + 2] = toupper(in[j+1]); + out[(3 * i) + 2] = toupper(in[j + 1]); j += 2; } } From 7cbc5c98e0886a772189f9e2e748934fff655eca Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 23 Oct 2017 18:12:59 +0200 Subject: [PATCH 006/174] remove debug msgs --- src/utils/ubus.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 040ca87..6918cc8 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -622,7 +622,6 @@ int ubus_call_umdns() { } int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { - printf("Try to send new probe!!!\n"); static struct blob_buf b; @@ -640,7 +639,5 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { str = blobmsg_format_json(b.head, 1); send_string_enc(str); - printf("SENDING NEW PROBE!!!: %s\n", str); - return 0; } \ No newline at end of file From 2721ee54389050db9d7bcbd4e4d81f77e8e2de3d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 24 Oct 2017 16:09:30 +0200 Subject: [PATCH 007/174] enable decide function --- src/utils/ubus.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 6918cc8..8d7f9c8 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -131,7 +131,7 @@ blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) blobmsg_add_string_buffer(buf); } -/* + static int decide_function(probe_entry *prob_req) { // TODO: Refactor... //printf("COUNTER: %d\n", prob_req->counter); @@ -147,7 +147,8 @@ static int decide_function(probe_entry *prob_req) { return 1; } -*/ + + static void hostapd_handle_remove(struct ubus_context *ctx, struct ubus_subscriber *s, uint32_t id) { fprintf(stderr, "Object %08x went away\n", id); @@ -228,8 +229,6 @@ static int handle_auth_req(struct blob_attr *msg) { printf("Entry found\n"); print_probe_entry(tmp); - /* - // block if entry was not already found in probe database if(!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr))) { @@ -240,7 +239,7 @@ static int handle_auth_req(struct blob_attr *msg) { if (!decide_function(&tmp)) { printf("DENY AUTH\n"); return UBUS_STATUS_UNKNOWN_ERROR; - }*/ + } printf("ALLOW AUTH!\n"); return 0; From ad7c62f5212a82a7bd98145f65ddfe539a98c778 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 26 Oct 2017 17:44:10 +0200 Subject: [PATCH 008/174] change format of mac --- src/storage/datastorage.c | 20 ++++++++++---------- src/utils/rssi.c | 2 +- src/utils/ubus.c | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 2b7c0c4..1174a7e 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -435,7 +435,7 @@ ap ap_array_get_ap(uint8_t bssid_addr[]) { ap ret; char bssid_mac_string[20]; - sprintf(bssid_mac_string, "%x:%x:%x:%x:%x:%x", MAC2STR(bssid_addr)); + sprintf(bssid_mac_string, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(bssid_addr)); printf("Try to find: %s\n", bssid_mac_string); printf("in\n"); print_ap_array(); @@ -898,9 +898,9 @@ void print_probe_entry(probe_entry entry) { char mac_buf_client[20]; char mac_buf_target[20]; - sprintf(mac_buf_ap, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.client_addr)); - sprintf(mac_buf_target, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.target_addr)); + sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); + sprintf(mac_buf_target, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.target_addr)); printf( "bssid_addr: %s, client_addr: %s, signal: %d, freq: " @@ -913,9 +913,9 @@ void print_auth_entry(auth_entry entry) { char mac_buf_client[20]; char mac_buf_target[20]; - sprintf(mac_buf_ap, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.client_addr)); - sprintf(mac_buf_target, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.target_addr)); + sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); + sprintf(mac_buf_target, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.target_addr)); printf( "bssid_addr: %s, client_addr: %s, signal: %d, freq: " @@ -927,8 +927,8 @@ void print_client_entry(client entry) { char mac_buf_ap[20]; char mac_buf_client[20]; - sprintf(mac_buf_ap, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.client_addr)); + sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); printf("bssid_addr: %s, client_addr: %s, freq: %d, ht_supported: %d, vht_supported: %d, ht: %d, vht: %d\n", mac_buf_ap, mac_buf_client, entry.freq, entry.ht_supported, entry.vht_supported, entry.ht, entry.vht); @@ -946,7 +946,7 @@ void print_client_array() { void print_ap_entry(ap entry) { char mac_buf_ap[20]; - sprintf(mac_buf_ap, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", 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); } diff --git a/src/utils/rssi.c b/src/utils/rssi.c index afbb241..59dfead 100644 --- a/src/utils/rssi.c +++ b/src/utils/rssi.c @@ -12,7 +12,7 @@ int parse_rssi(char *iwinfo_string); int get_rssi_from_iwinfo(__uint8_t *client_addr) { char mac_buf[20]; - sprintf(mac_buf, "%x:%x:%x:%x:%x:%x", MAC2STR(client_addr)); + sprintf(mac_buf, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(client_addr)); char mac_buf_conv[20]; convert_mac(mac_buf, mac_buf_conv); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 8d7f9c8..a1716be 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -438,7 +438,7 @@ dump_client_table(struct blob_attr *head, int len, const char *bssid_addr, uint3 int tmp_int_mac[ETH_ALEN]; uint8_t tmp_mac[ETH_ALEN]; - sscanf((char *) hdr->name, "%x:%x:%x:%x:%x:%x", STR2MAC(tmp_int_mac)); + sscanf((char *) hdr->name, "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); for (int i = 0; i < ETH_ALEN; ++i) tmp_mac[i] = (uint8_t) tmp_int_mac[i]; @@ -535,12 +535,12 @@ void *kick_clients_thread(void *arg) { /* int tmp_int_mac[ETH_ALEN]; uint8_t tmp_mac[ETH_ALEN]; - sscanf("a4:2b:b0:de:f1:fd", "%x:%x:%x:%x:%x:%x", STR2MAC(tmp_int_mac)); + sscanf("a4:2b:b0:de:f1:fd", "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); for(int i = 0; i < ETH_ALEN; ++i ) tmp_mac[i] = (uint8_t) tmp_int_mac[i]; //kick_clients(tmp_mac); - sscanf("a4:2b:b0:de:f1:fe", "%x:%x:%x:%x:%x:%x", STR2MAC(tmp_int_mac)); + sscanf("a4:2b:b0:de:f1:fe", "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); for(int i = 0; i < ETH_ALEN; ++i ) tmp_mac[i] = (uint8_t) tmp_int_mac[i];*/ //kick_clients(tmp_mac); From a5c69a2ef00d52aa79161139910a4c47b179ce70 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 26 Oct 2017 17:53:28 +0200 Subject: [PATCH 009/174] replace string with define --- src/include/utils.h | 2 ++ src/storage/datastorage.c | 21 +++++++++++---------- src/utils/rssi.c | 2 +- src/utils/ubus.c | 8 +++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/include/utils.h b/src/include/utils.h index 5b86370..ec0e87a 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -7,6 +7,8 @@ #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] #define STR2MAC(a) &(a)[0], &(a)[1], &(a)[2], &(a)[3], &(a)[4], &(a)[5] +#define MACSTR "%02X:%02X:%02X:%02X:%02X:%02X" + int hex_to_bin(char ch); int hwaddr_aton(const char *txt, uint8_t *addr); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 1174a7e..672fd76 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -4,6 +4,7 @@ #include "ubus.h" #include "rssi.h" +#include "utils.h" #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] @@ -435,7 +436,7 @@ ap ap_array_get_ap(uint8_t bssid_addr[]) { ap ret; char bssid_mac_string[20]; - sprintf(bssid_mac_string, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(bssid_addr)); + sprintf(bssid_mac_string, MACSTR, MAC2STR(bssid_addr)); printf("Try to find: %s\n", bssid_mac_string); printf("in\n"); print_ap_array(); @@ -898,9 +899,9 @@ void print_probe_entry(probe_entry entry) { char mac_buf_client[20]; char mac_buf_target[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); - sprintf(mac_buf_target, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.target_addr)); + sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr)); + sprintf(mac_buf_target, MACSTR, MAC2STR(entry.target_addr)); printf( "bssid_addr: %s, client_addr: %s, signal: %d, freq: " @@ -913,9 +914,9 @@ void print_auth_entry(auth_entry entry) { char mac_buf_client[20]; char mac_buf_target[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); - sprintf(mac_buf_target, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.target_addr)); + sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr)); + sprintf(mac_buf_target, MACSTR, MAC2STR(entry.target_addr)); printf( "bssid_addr: %s, client_addr: %s, signal: %d, freq: " @@ -927,8 +928,8 @@ void print_client_entry(client entry) { char mac_buf_ap[20]; char mac_buf_client[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); + sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr)); printf("bssid_addr: %s, client_addr: %s, freq: %d, ht_supported: %d, vht_supported: %d, ht: %d, vht: %d\n", mac_buf_ap, mac_buf_client, entry.freq, entry.ht_supported, entry.vht_supported, entry.ht, entry.vht); @@ -946,7 +947,7 @@ void print_client_array() { void print_ap_entry(ap entry) { char mac_buf_ap[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); + 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); } diff --git a/src/utils/rssi.c b/src/utils/rssi.c index 59dfead..62d87a5 100644 --- a/src/utils/rssi.c +++ b/src/utils/rssi.c @@ -12,7 +12,7 @@ int parse_rssi(char *iwinfo_string); int get_rssi_from_iwinfo(__uint8_t *client_addr) { char mac_buf[20]; - sprintf(mac_buf, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(client_addr)); + sprintf(mac_buf, MACSTR, MAC2STR(client_addr)); char mac_buf_conv[20]; convert_mac(mac_buf, mac_buf_conv); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a1716be..b1110c2 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -119,8 +119,6 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir); static int ubus_get_clients(); -/* hostapd function */ -#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" static void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) { @@ -438,7 +436,7 @@ dump_client_table(struct blob_attr *head, int len, const char *bssid_addr, uint3 int tmp_int_mac[ETH_ALEN]; uint8_t tmp_mac[ETH_ALEN]; - sscanf((char *) hdr->name, "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); + sscanf((char *) hdr->name, MACSTR, STR2MAC(tmp_int_mac)); for (int i = 0; i < ETH_ALEN; ++i) tmp_mac[i] = (uint8_t) tmp_int_mac[i]; @@ -535,12 +533,12 @@ void *kick_clients_thread(void *arg) { /* int tmp_int_mac[ETH_ALEN]; uint8_t tmp_mac[ETH_ALEN]; - sscanf("a4:2b:b0:de:f1:fd", "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); + sscanf("a4:2b:b0:de:f1:fd", MACSTR, STR2MAC(tmp_int_mac)); for(int i = 0; i < ETH_ALEN; ++i ) tmp_mac[i] = (uint8_t) tmp_int_mac[i]; //kick_clients(tmp_mac); - sscanf("a4:2b:b0:de:f1:fe", "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); + sscanf("a4:2b:b0:de:f1:fe", MACSTR, STR2MAC(tmp_int_mac)); for(int i = 0; i < ETH_ALEN; ++i ) tmp_mac[i] = (uint8_t) tmp_int_mac[i];*/ //kick_clients(tmp_mac); From eadbaa2765895e99fef3545a67203906dbcca44b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 26 Oct 2017 20:56:47 +0200 Subject: [PATCH 010/174] get rssi from iwinfo lib --- src/include/rssi.h | 2 ++ src/main.c | 2 ++ src/utils/rssi.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/include/rssi.h b/src/include/rssi.h index 5f135d9..67bb7a0 100644 --- a/src/include/rssi.h +++ b/src/include/rssi.h @@ -7,4 +7,6 @@ int get_rssi_from_iwinfo(__uint8_t *client_addr); +int get_rssi_iwinfo(); + #endif //DAWN_RSSI_H diff --git a/src/main.c b/src/main.c index 33dd421..3b530fc 100644 --- a/src/main.c +++ b/src/main.c @@ -124,6 +124,8 @@ void free(void *p) int main(int argc, char **argv) { //free_counter = 0; + get_rssi_iwinfo(); + const char *ubus_socket = NULL; int ch; diff --git a/src/utils/rssi.c b/src/utils/rssi.c index 62d87a5..ef3d023 100644 --- a/src/utils/rssi.c +++ b/src/utils/rssi.c @@ -10,6 +10,37 @@ int call_iwinfo(char *client_addr); int parse_rssi(char *iwinfo_string); +#define IWINFO_BUFSIZE 24 * 1024 + +int get_rssi_iwinfo() +{ + int i, len; + char buf[IWINFO_BUFSIZE]; + struct iwinfo_assoclist_entry *e; + + const struct iwinfo_ops *iw = NULL; + iw = iwinfo_backend("wlan0"); + + if (iw->assoclist(ifname, buf, &len)) + { + printf("No information available\n"); + return; + } + else if (len <= 0) + { + printf("No station connected\n"); + return; + } + + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + { + e = (struct iwinfo_assoclist_entry *) &buf[i]; + + printf("iwinfo rssi: %d\n", e->signal); + } +} + + int get_rssi_from_iwinfo(__uint8_t *client_addr) { char mac_buf[20]; sprintf(mac_buf, MACSTR, MAC2STR(client_addr)); From 38052e76fbab112c6b5bc370602da0aadb88c653 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 26 Oct 2017 20:59:19 +0200 Subject: [PATCH 011/174] get rssi from iwinfo lib --- src/CMakeLists.txt | 2 +- src/include/rssi.h | 5 +- src/main.c | 3 +- src/storage/datastorage.c | 4 +- src/utils/rssi.c | 103 ++++++++++++++------------------------ 5 files changed, 44 insertions(+), 73 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2cbe83..9633969 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,7 +42,7 @@ SET(SOURCES utils/utils.c include/rssi.h utils/rssi.c) SET(LIBS - ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto) + ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto iwinfo) ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h) diff --git a/src/include/rssi.h b/src/include/rssi.h index 67bb7a0..863f25b 100644 --- a/src/include/rssi.h +++ b/src/include/rssi.h @@ -4,9 +4,8 @@ #include #include #include +#include -int get_rssi_from_iwinfo(__uint8_t *client_addr); - -int get_rssi_iwinfo(); +int get_rssi_iwinfo(__uint8_t *client_addr); #endif //DAWN_RSSI_H diff --git a/src/main.c b/src/main.c index 3b530fc..28cabbf 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,7 @@ #include "networksocket.h" #include "ubus.h" #include "dawn_uci.h" +#include "rssi.h" #define BUFSIZE 17 #define BUFSIZE_DIR 256 @@ -124,8 +125,6 @@ void free(void *p) int main(int argc, char **argv) { //free_counter = 0; - get_rssi_iwinfo(); - const char *ubus_socket = NULL; int ch; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 672fd76..6a3c72b 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -138,11 +138,13 @@ void kick_clients(uint8_t bssid[], uint32_t id) { } // update rssi - int rssi = get_rssi_from_iwinfo(client_array[j].client_addr); + int rssi = get_rssi_iwinfo(client_array[j].client_addr); 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)) { printf("Failed to update RSSI!\n"); + } else { + printf("RSSI UPDATED: RSSI: %d\n\n", rssi); } pthread_mutex_lock(&probe_array_mutex); diff --git a/src/utils/rssi.c b/src/utils/rssi.c index ef3d023..7474613 100644 --- a/src/utils/rssi.c +++ b/src/utils/rssi.c @@ -1,8 +1,11 @@ #include "rssi.h" #include +#include +#include #include "utils.h" +#include "ubus.h" #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] @@ -10,92 +13,60 @@ int call_iwinfo(char *client_addr); int parse_rssi(char *iwinfo_string); +int get_rssi(const char *ifname, uint8_t *client_addr); + #define IWINFO_BUFSIZE 24 * 1024 -int get_rssi_iwinfo() -{ +int get_rssi_iwinfo(__uint8_t *client_addr) { + + DIR *dirp; + struct dirent *entry; + dirp = opendir(hostapd_dir_glob); // error handling? + if (!dirp) { + fprintf(stderr, "No hostapd sockets!\n"); + return -1; + } + + int rssi = INT_MIN; + + while ((entry = readdir(dirp)) != NULL) { + if (entry->d_type == DT_SOCK) { + rssi = get_rssi(entry->d_name, client_addr); + if(rssi != INT_MIN) + break; + } + } + closedir(dirp); + return rssi; +} + +int get_rssi(const char *ifname, uint8_t *client_addr){ + int i, len; char buf[IWINFO_BUFSIZE]; struct iwinfo_assoclist_entry *e; + const struct iwinfo_ops *iw; - const struct iwinfo_ops *iw = NULL; - iw = iwinfo_backend("wlan0"); + iw = iwinfo_backend(ifname); if (iw->assoclist(ifname, buf, &len)) { printf("No information available\n"); - return; + return INT_MIN; } else if (len <= 0) { printf("No station connected\n"); - return; + return INT_MIN; } for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) { e = (struct iwinfo_assoclist_entry *) &buf[i]; - printf("iwinfo rssi: %d\n", e->signal); - } -} - - -int get_rssi_from_iwinfo(__uint8_t *client_addr) { - char mac_buf[20]; - sprintf(mac_buf, MACSTR, MAC2STR(client_addr)); - char mac_buf_conv[20]; - - convert_mac(mac_buf, mac_buf_conv); - - return call_iwinfo(mac_buf_conv); -} - -int call_iwinfo(char *client_addr) { - // TODO: REFACTOR THIS! USE NET LINK... LOOK AT IWINFO - - FILE *fp; - char path[1035]; - - int rssi = INT_MIN; - int command_length = 68; - char iwinfo_command[command_length]; - char *first_command = "(iwinfo wlan0 assoc && iwinfo wlan1 assoc) | grep "; - size_t length_first_command = strlen(first_command); - memcpy(iwinfo_command, first_command, length_first_command); - memcpy(iwinfo_command + length_first_command, client_addr, strlen(client_addr)); - iwinfo_command[command_length - 1] = '\0'; - printf("iwinfo command:\n%s\n", iwinfo_command); - - fp = popen(iwinfo_command, "r"); - if (fp == NULL) { - printf("Failed to run command\n"); - exit(1); + if(mac_is_equal(client_addr, e->mac)) + return e->signal; } - /* Read the output a line at a time - output it. */ - while (fgets(path, sizeof(path) - 1, fp) != NULL) { - rssi = parse_rssi(path); - } - - /* close */ - pclose(fp); - - return rssi; -} - -int parse_rssi(char *iwinfo_string) { - char cut_1[] = " "; - char cut_2[] = "dBm"; - char *p_1 = strstr(iwinfo_string, cut_1); - char *p_2 = strstr(iwinfo_string, cut_2); - int rssi = INT_MIN; - if (p_1 != NULL && p_2 != NULL) { - int length = (int) (p_2 - p_1); - char dest[length + 1]; - memcpy(dest, p_1, (int) (p_2 - p_1)); - dest[length] = '\0'; - rssi = atoi(dest); - } - return rssi; + return INT_MIN; } \ No newline at end of file From cd28708600898d2e42736cb910e18ff530b3c48a Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 28 Oct 2017 19:56:21 +0200 Subject: [PATCH 012/174] tidy up header --- src/include/datastorage.h | 98 +++++++++++++++++++++++---------------- src/main.c | 2 +- src/storage/datastorage.c | 8 ++-- src/utils/ubus.c | 4 +- 4 files changed, 64 insertions(+), 48 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 889dcfc..723476e 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -13,8 +13,10 @@ #define ETH_ALEN 6 #endif -struct probe_metric_s dawn_metric; +/* Metric */ + +// ---------------- Structs ---------------- struct probe_metric_s { int ht_support; int vht_support; @@ -34,10 +36,13 @@ struct time_config_s { time_t remove_probe; }; -#define SORT_NUM 5 -#define TIME_THRESHOLD 120 // every minute +// ---------------- Global variables ---------------- +struct probe_metric_s dawn_metric; -// Probe entrys + +/* Probe, Auth, Assoc */ + +// ---------------- Structs ---------------- typedef struct probe_entry_s { uint8_t bssid_addr[ETH_ALEN]; uint8_t client_addr[ETH_ALEN]; @@ -60,11 +65,33 @@ typedef struct auth_entry_s { typedef struct auth_entry_s assoc_entry; +// ---------------- Defines ---------------- +#define PROBE_ARRAY_LEN 1000 -typedef struct { - uint32_t freq; -} client_request; +// ---------------- Global variables ---------------- +struct probe_entry_s probe_array[PROBE_ARRAY_LEN]; +pthread_mutex_t probe_array_mutex; +// ---------------- Functions ---------------- +probe_entry insert_to_array(probe_entry entry, int inc_counter); + +void probe_array_insert(probe_entry entry); + +probe_entry probe_array_delete(probe_entry entry); + +probe_entry probe_array_get_entry(uint8_t bssid_addr[], uint8_t client_addr[]); + +void print_probe_array(); + +void print_probe_entry(probe_entry entry); + +void print_auth_entry(auth_entry entry); + +void *remove_probe_array_thread(void *arg); + +/* AP, Client */ + +// ---------------- Structs ---------------- typedef struct client_s { uint8_t bssid_addr[ETH_ALEN]; uint8_t client_addr[ETH_ALEN]; @@ -94,34 +121,21 @@ typedef struct ap_s { time_t time; } ap; -// Array +// ---------------- Defines ---------------- #define ARRAY_AP_LEN 50 #define TIME_THRESHOLD_AP 30 -struct ap_s ap_array[ARRAY_AP_LEN]; -pthread_mutex_t ap_array_mutex; - -ap insert_to_ap_array(ap entry); - -void print_ap_array(); - -void *remove_ap_array_thread(void *arg); - -ap ap_array_get_ap(uint8_t bssid_addr[]); - -// Array #define ARRAY_CLIENT_LEN 1000 #define TIME_THRESHOLD_CLIENT 30 #define TIME_THRESHOLD_CLIENT_UPDATE 10 #define TIME_THRESHOLD_CLIENT_KICK 60 - +// ---------------- Global variables ---------------- struct client_s client_array[ARRAY_CLIENT_LEN]; pthread_mutex_t client_array_mutex; +struct ap_s ap_array[ARRAY_AP_LEN]; +pthread_mutex_t ap_array_mutex; -int mac_is_equal(uint8_t addr1[], uint8_t addr2[]); - -int mac_is_greater(uint8_t addr1[], uint8_t addr2[]); - +// ---------------- Functions ---------------- void insert_client_to_array(client entry); void kick_clients(uint8_t bssid[], uint32_t id); @@ -136,31 +150,33 @@ void print_client_entry(client entry); void *remove_client_array_thread(void *arg); -#define ARRAY_LEN 1000 +ap insert_to_ap_array(ap entry); -struct probe_entry_s probe_array[ARRAY_LEN]; -pthread_mutex_t probe_array_mutex; +void print_ap_array(); -probe_entry insert_to_array(probe_entry entry, int inc_counter); +void *remove_ap_array_thread(void *arg); -void probe_array_insert(probe_entry entry); +ap ap_array_get_ap(uint8_t bssid_addr[]); -probe_entry probe_array_delete(probe_entry entry); +/* Utils */ -probe_entry probe_array_get_entry(uint8_t bssid_addr[], uint8_t client_addr[]); +// ---------------- Defines ------------------- +#define SORT_NUM 5 +#define TIME_THRESHOLD 120 // every minute + +// ---------------- Global variables ---------------- +char sort_string[SORT_NUM]; + +// ---------------- Functions ------------------- +int mac_is_equal(uint8_t addr1[], uint8_t addr2[]); + +int mac_is_greater(uint8_t addr1[], uint8_t addr2[]); int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]); -void print_array(); -void print_probe_entry(probe_entry entry); +/* List stuff */ -void print_auth_entry(auth_entry entry); - -void *remove_array_thread(void *arg); - - -// List typedef struct node { probe_entry data; struct node *ptr; @@ -180,6 +196,6 @@ void *remove_thread(void *arg); pthread_mutex_t list_mutex; node *probe_list_head; -char sort_string[SORT_NUM]; + #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 28cabbf..6ccd0c7 100644 --- a/src/main.c +++ b/src/main.c @@ -211,7 +211,7 @@ int main(int argc, char **argv) { init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); - pthread_create(&tid_probe, NULL, &remove_array_thread, (void *) &time_config.remove_probe); + pthread_create(&tid_probe, NULL, &remove_probe_array_thread, (void *) &time_config.remove_probe); pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client); pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); //pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 6a3c72b..f8c389c 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -306,13 +306,13 @@ void probe_array_insert(probe_entry entry) { } } for (int j = probe_entry_last; j >= i; j--) { - if (j + 1 <= ARRAY_LEN) { + if (j + 1 <= PROBE_ARRAY_LEN) { probe_array[j + 1] = probe_array[j]; } } probe_array[i] = entry; - if (probe_entry_last < ARRAY_LEN) { + if (probe_entry_last < PROBE_ARRAY_LEN) { probe_entry_last++; } } @@ -390,7 +390,7 @@ probe_entry probe_array_get_entry(uint8_t bssid_addr[], uint8_t client_addr[]) { return tmp; } -void print_array() { +void print_probe_array() { printf("------------------\n"); printf("Probe Entry Last: %d\n", probe_entry_last); for (int i = 0; i <= probe_entry_last; i++) { @@ -539,7 +539,7 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) { } } -void *remove_array_thread(void *arg) { +void *remove_probe_array_thread(void *arg) { printf("Removing thread with time: %lu\n", *(long int *) arg); time_t time_treshold = *(time_t *) arg; while (1) { diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b1110c2..63339fa 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -216,7 +216,7 @@ int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req) { static int handle_auth_req(struct blob_attr *msg) { - print_array(); + print_probe_array(); auth_entry auth_req; parse_to_auth_req(msg, &auth_req); printf("AUTH Entry: "); @@ -266,7 +266,7 @@ static int handle_probe_req(struct blob_attr *msg) { printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str); - print_array(); + print_probe_array(); /* // deny access if (!decide_function(&tmp_probe)) { From aa6f37c225ef585891edaf1bc7638887b5ee8f9b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 17 Nov 2017 11:10:28 +0100 Subject: [PATCH 013/174] add hostapd ubus array --- files/dawn.config | 1 + src/include/datastorage.h | 1 + src/include/ubus.h | 2 + src/main.c | 4 + src/utils/dawn_uci.c | 11 ++- src/utils/ubus.c | 173 ++++++++++++++++++++++++++------------ 6 files changed, 139 insertions(+), 53 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 95ae816..816506f 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -14,6 +14,7 @@ config settings times option update_client '50' option remove_client '120' option remove_probe '120' + option update_hostapd '10' config settings metric option ht_support '10' diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 723476e..1f50f6d 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -34,6 +34,7 @@ struct time_config_s { time_t update_client; time_t remove_client; time_t remove_probe; + time_t update_hostapd; }; // ---------------- Global variables ---------------- diff --git a/src/include/ubus.h b/src/include/ubus.h index 0395af6..182c049 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -30,4 +30,6 @@ int ubus_call_umdns(); int ubus_send_probe_via_network(struct probe_entry_s probe_entry); +void *update_hostapd_sockets(void *arg); + #endif diff --git a/src/main.c b/src/main.c index 6ccd0c7..6853dd5 100644 --- a/src/main.c +++ b/src/main.c @@ -41,6 +41,7 @@ struct sigaction newSigAction; pthread_t tid_probe; pthread_t tid_client; pthread_t tid_get_client; +pthread_t tid_update_hostapd_socks; pthread_t tid_kick_clients; pthread_t tid_ap; @@ -214,6 +215,9 @@ int main(int argc, char **argv) { pthread_create(&tid_probe, NULL, &remove_probe_array_thread, (void *) &time_config.remove_probe); pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client); pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); + pthread_create(&tid_update_hostapd_socks, NULL, &update_hostapd_sockets, &time_config.update_hostapd); + + //pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL); //pthread_create(&tid_ap, NULL, &remove_ap_array_thread, NULL); diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index f93187c..378284b 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -55,7 +55,16 @@ struct time_config_s uci_get_time_config() { if (ptr.o->type == UCI_TYPE_STRING) ret.remove_probe = atoi(ptr.o->v.string); - printf("Times: %lu, %lu, %lu\n", ret.update_client, ret.remove_client, ret.remove_probe); + char tmp_update_hostapd[] = "dawn.times.update_hostapd"; + if (uci_lookup_ptr(c, &ptr, tmp_update_hostapd, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.update_hostapd = atoi(ptr.o->v.string); + + + printf("Times: %lu, %lu, %lu %lu\n", ret.update_client, ret.remove_client, ret.remove_probe, ret.update_hostapd); uci_free_context(c); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 63339fa..5e38088 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -14,11 +14,17 @@ #include "utils.h" #include "dawn_uci.h" -static struct ubus_context *ctx; +static struct ubus_context *ctx = NULL; static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */ +static struct ubus_context *ctx_hostapd; + static struct ubus_subscriber hostapd_event; static struct blob_buf b; +#define MAX_HOSTAPD_SOCKETS 10 +uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS]; +int hostapd_sock_last = -1; + enum { AUTH_BSSID_ADDR, AUTH_CLIENT_ADDR, @@ -119,6 +125,62 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir); static int ubus_get_clients(); +int hostapd_array_check_id(uint32_t id); +void hostapd_array_insert(uint32_t id); +void hostapd_array_delete(uint32_t id); + +int hostapd_array_check_id(uint32_t id) +{ + for(int i = 0; i <= hostapd_sock_last; i++) + { + if(hostapd_sock_arr[i] == id) + { + return 1; + } + } + return 0; +} + + +void hostapd_array_insert(uint32_t id) +{ + if(hostapd_sock_last < MAX_HOSTAPD_SOCKETS) { + hostapd_sock_last++; + hostapd_sock_arr[hostapd_sock_last] = id; + } + + for(int i = 0; i <= hostapd_sock_last; i++) + { + printf("%d: %d\n",i,hostapd_sock_arr[i]); + } +} + +void hostapd_array_delete(uint32_t id) +{ + int i = 0; + int found_in_array = 0; + + if (hostapd_sock_last == -1) { + return; + } + + for(i = 0; i <= hostapd_sock_last; i++) + { + if(hostapd_sock_arr[i] == id) { + found_in_array = 1; + break; + } + } + + for (int j = i; j <= hostapd_sock_last; j++) { + hostapd_sock_arr[j] = hostapd_sock_arr[j + 1]; + } + + if (hostapd_sock_last > -1 && found_in_array) { + hostapd_sock_last--; + } + +} static void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) { @@ -150,6 +212,8 @@ static int decide_function(probe_entry *prob_req) { static void hostapd_handle_remove(struct ubus_context *ctx, struct ubus_subscriber *s, uint32_t id) { fprintf(stderr, "Object %08x went away\n", id); + //ubus_unsubscribe(ctx, &hostapd_event, id); + hostapd_array_delete(id); } int parse_to_auth_req(struct blob_attr *msg, auth_entry *auth_req) { @@ -298,17 +362,18 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, static int add_subscriber(char *name) { uint32_t id = 0; - if (ubus_lookup_id(ctx, name, &id)) { + if (ubus_lookup_id(ctx_hostapd, name, &id)) { fprintf(stderr, "Failed to look up test object for %s\n", name); return -1; } - // add callbacks - hostapd_event.remove_cb = hostapd_handle_remove; - hostapd_event.cb = hostapd_notify; - - int ret = ubus_subscribe(ctx, &hostapd_event, id); + if(hostapd_array_check_id(id)) + { + return 0; + } + int ret = ubus_subscribe(ctx_hostapd, &hostapd_event, id); + hostapd_array_insert(id); fprintf(stderr, "Watching object %08x: %s\n", id, ubus_strerror(ret)); return 0; @@ -318,10 +383,9 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { DIR *dirp; struct dirent *entry; - int ret = ubus_register_subscriber(ctx, &hostapd_event); - if (ret) { - fprintf(stderr, "Failed to add watch handler: %s\n", ubus_strerror(ret)); - return -1; + if(ctx_hostapd == NULL) + { + return 0; } dirp = opendir(hostapd_dir); // error handling? @@ -333,11 +397,34 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { if (entry->d_type == DT_SOCK) { char subscribe_name[256]; sprintf(subscribe_name, "hostapd.%s", entry->d_name); - printf("Subscribing to %s\n", subscribe_name); add_subscriber(subscribe_name); } } closedir(dirp); + return 0; +} + +static int subscribe_to_hostapd(char *hostapd_dir) { + + if(ctx_hostapd == NULL) + { + return 0; + } + + printf("Registering ubus event subscriber!\n"); + int ret = ubus_register_subscriber(ctx_hostapd, &hostapd_event); + if (ret) { + fprintf(stderr, "Failed to add watch handler: %s\n", ubus_strerror(ret)); + return -1; + } + + // add callbacks + hostapd_event.remove_cb = hostapd_handle_remove; + hostapd_event.cb = hostapd_notify; + + //subscribe_to_hostapd_interfaces(hostapd_dir); + + // free(hostapd_dir); // free string return 0; } @@ -359,7 +446,7 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { // set dawn metric dawn_metric = uci_get_dawn_metric(); - subscribe_to_hostapd_interfaces(hostapd_dir); + //subscribe_to_hostapd(hostapd_dir); //ubus_call_umdns(); @@ -485,27 +572,11 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ } static int ubus_get_clients() { - DIR *dirp; - struct dirent *entry; - - dirp = opendir(hostapd_dir_glob); // error handling? - if (!dirp) { - fprintf(stderr, "No hostapd sockets!\n"); - return -1; + for(int i = 0; i <= hostapd_sock_last; i++) + { + int timeout = 1; + ubus_invoke(ctx_clients, hostapd_sock_arr[i], "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000); } - while ((entry = readdir(dirp)) != NULL) { - if (entry->d_type == DT_SOCK) { - char hostapd_iface[256]; - uint32_t id; - sprintf(hostapd_iface, "hostapd.%s", entry->d_name); - int ret = ubus_lookup_id(ctx_clients, hostapd_iface, &id); - if (!ret) { - int timeout = 1; - ubus_invoke(ctx_clients, id, "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000); - } - } - } - closedir(dirp); return 0; } @@ -546,6 +617,19 @@ void *kick_clients_thread(void *arg) { return 0; } +void *update_hostapd_sockets(void *arg) { + time_t time_update_hostapd = *(time_t *) arg; + + printf("Update hostapd thread with time: %lu\n", time_update_hostapd); + const char *ubus_socket = NULL; + ctx_hostapd = ubus_connect(ubus_socket); + + subscribe_to_hostapd(hostapd_dir_glob); + while (1) { + subscribe_to_hostapd_interfaces(hostapd_dir_glob); + sleep(time_update_hostapd); + } +} void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) { /* Problem: @@ -563,26 +647,11 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint blobmsg_add_u8(&b, "deauth", deauth); blobmsg_add_u32(&b, "ban_time", ban_time); - DIR *dirp; - struct dirent *entry; - dirp = opendir(hostapd_dir_glob); // error handling? - if (!dirp) { - fprintf(stderr, "No hostapd sockets!\n"); - return; + for(int i = 0; i <= hostapd_sock_last; i++) + { + int timeout = 1; + ubus_invoke(ctx_clients, hostapd_sock_arr[i], "del_client", b.head, NULL, NULL, timeout * 1000); } - while ((entry = readdir(dirp)) != NULL) { - if (entry->d_type == DT_SOCK) { - char hostapd_iface[256]; - uint32_t id; - sprintf(hostapd_iface, "hostapd.%s", entry->d_name); - int ret = ubus_lookup_id(ctx_clients, hostapd_iface, &id); - if (!ret) { - int timeout = 1; - ubus_invoke(ctx_clients, id, "del_client", b.head, NULL, NULL, timeout * 1000); - } - } - } - closedir(dirp); } void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) { From e00e11b728bc8a56f719bc4bbfee2c0e2fd5d851 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 19 Nov 2017 20:29:13 +0100 Subject: [PATCH 014/174] clean up code --- src/include/ubus.h | 2 -- src/main.c | 55 +++------------------------------------------- src/utils/ubus.c | 24 -------------------- 3 files changed, 3 insertions(+), 78 deletions(-) diff --git a/src/include/ubus.h b/src/include/ubus.h index 182c049..9c6a2b6 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -22,8 +22,6 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint void *update_clients_thread(void *arg); -void *kick_clients_thread(void *arg); - char *hostapd_dir_glob; int ubus_call_umdns(); diff --git a/src/main.c b/src/main.c index 6853dd5..4d7ff8e 100644 --- a/src/main.c +++ b/src/main.c @@ -36,8 +36,6 @@ void signal_handler(int sig); struct sigaction newSigAction; -//int free_counter = 0; - pthread_t tid_probe; pthread_t tid_client; pthread_t tid_get_client; @@ -46,13 +44,13 @@ pthread_t tid_kick_clients; pthread_t tid_ap; void daemon_shutdown() { + // kill threads printf("Cancelling Threads!\n"); pthread_cancel(tid_probe); - //pthread_cancel(tid_client); + pthread_cancel(tid_client); pthread_cancel(tid_get_client); - //pthread_cancel(tid_kick_clients); - //pthread_cancel(tid_ap); + pthread_cancel(tid_update_hostapd_socks); // free ressources printf("Freeing mutex ressources\n"); @@ -83,46 +81,6 @@ void signal_handler(int sig) { } } -/* -static void mtrace_init(void) -{ - real_malloc = dlsym(RTLD_NEXT, "malloc"); - if (NULL == real_malloc) { - fprintf(stderr, "Error in `dlsym`: %s\n", dlerror()); - } - real_free = dlsym(RTLD_NEXT, "free"); - if (NULL == real_free) { - fprintf(stderr, "Error in `dlsym`: %s\n", dlerror()); - } -} - -void *malloc(size_t size) -{ - mtrace_init(); - if(real_malloc==NULL) { - mtrace_init(); - } - - void *p = NULL; - fprintf(stderr, "malloc(%d) = ", size); - p = real_malloc(size); - fprintf(stderr, "%p\n", p); - free_counter++; - return p; -} - -void free(void *p) -{ - mtrace_init(); - if(real_free==NULL) { - mtrace_init(); - } - p = real_free(p); - fprintf(stderr, "free: "); - fprintf(stderr, "%p\n", p); - free_counter--; -}*/ - int main(int argc, char **argv) { //free_counter = 0; @@ -217,14 +175,7 @@ int main(int argc, char **argv) { pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); pthread_create(&tid_update_hostapd_socks, NULL, &update_hostapd_sockets, &time_config.update_hostapd); - - //pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL); - //pthread_create(&tid_ap, NULL, &remove_ap_array_thread, NULL); - - //pthread_create(&tid, NULL, &remove_thread, NULL); - dawn_init_ubus(ubus_socket, opt_hostapd_dir); - //free_list(probe_list_head); return 0; } \ No newline at end of file diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 5e38088..1920e16 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -534,8 +534,6 @@ dump_client_table(struct blob_attr *head, int len, const char *bssid_addr, uint3 int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) { struct blob_attr *tb[__CLIENT_TABLE_MAX]; - //printf("[CLIENTS] : Parse Clients\n"); - blobmsg_parse(client_table_policy, __CLIENT_TABLE_MAX, tb, blob_data(msg), blob_len(msg)); if (tb[CLIENT_TABLE] && tb[CLIENT_TABLE_BSSID] && tb[CLIENT_TABLE_FREQ] && tb[CLIENT_TABLE_HT] && @@ -595,28 +593,6 @@ void *update_clients_thread(void *arg) { return 0; } -void *kick_clients_thread(void *arg) { - while (1) { - sleep(TIME_THRESHOLD_CLIENT_KICK); - printf("[Thread] : Updating clients!\n"); - // a4:2b:b0:de:f1:fd - // a4:2b:b0:de:f1:fe -/* - int tmp_int_mac[ETH_ALEN]; - uint8_t tmp_mac[ETH_ALEN]; - sscanf("a4:2b:b0:de:f1:fd", MACSTR, STR2MAC(tmp_int_mac)); - for(int i = 0; i < ETH_ALEN; ++i ) - tmp_mac[i] = (uint8_t) tmp_int_mac[i]; - //kick_clients(tmp_mac); - - sscanf("a4:2b:b0:de:f1:fe", MACSTR, STR2MAC(tmp_int_mac)); - for(int i = 0; i < ETH_ALEN; ++i ) - tmp_mac[i] = (uint8_t) tmp_int_mac[i];*/ - //kick_clients(tmp_mac); - } - return 0; -} - void *update_hostapd_sockets(void *arg) { time_t time_update_hostapd = *(time_t *) arg; From ed725710d767675f39d999fcf864756e531e0717 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 19 Nov 2017 20:40:03 +0100 Subject: [PATCH 015/174] remove prints --- src/include/ubus.h | 4 +++- src/main.c | 6 +++--- src/utils/ubus.c | 50 ++++++++++++++++++++++++++++------------------ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/include/ubus.h b/src/include/ubus.h index 9c6a2b6..ce91d3a 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -2,6 +2,8 @@ #define __DAWN_UBUS_H #include +#include + #include "datastorage.h" #define MIN_PROBE_REQ 2 // TODO: Parse from config file... @@ -28,6 +30,6 @@ int ubus_call_umdns(); int ubus_send_probe_via_network(struct probe_entry_s probe_entry); -void *update_hostapd_sockets(void *arg); +void update_hostapd_sockets(struct uloop_timeout *t); #endif diff --git a/src/main.c b/src/main.c index 4d7ff8e..b147250 100644 --- a/src/main.c +++ b/src/main.c @@ -39,7 +39,7 @@ struct sigaction newSigAction; pthread_t tid_probe; pthread_t tid_client; pthread_t tid_get_client; -pthread_t tid_update_hostapd_socks; +//pthread_t tid_update_hostapd_socks; pthread_t tid_kick_clients; pthread_t tid_ap; @@ -50,7 +50,7 @@ void daemon_shutdown() { pthread_cancel(tid_probe); pthread_cancel(tid_client); pthread_cancel(tid_get_client); - pthread_cancel(tid_update_hostapd_socks); + //pthread_cancel(tid_update_hostapd_socks); // free ressources printf("Freeing mutex ressources\n"); @@ -173,7 +173,7 @@ int main(int argc, char **argv) { pthread_create(&tid_probe, NULL, &remove_probe_array_thread, (void *) &time_config.remove_probe); pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client); pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); - pthread_create(&tid_update_hostapd_socks, NULL, &update_hostapd_sockets, &time_config.update_hostapd); + //pthread_create(&tid_update_hostapd_socks, NULL, &update_hostapd_sockets, &time_config.update_hostapd); dawn_init_ubus(ubus_socket, opt_hostapd_dir); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 1920e16..923424f 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -16,11 +17,15 @@ static struct ubus_context *ctx = NULL; static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */ -static struct ubus_context *ctx_hostapd; +//static struct ubus_context *ctx_hostapd; static struct ubus_subscriber hostapd_event; static struct blob_buf b; +struct uloop_timeout hostapd_timer = { + .cb = update_hostapd_sockets +}; + #define MAX_HOSTAPD_SOCKETS 10 uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS]; int hostapd_sock_last = -1; @@ -194,7 +199,7 @@ blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) static int decide_function(probe_entry *prob_req) { // TODO: Refactor... - //printf("COUNTER: %d\n", prob_req->counter); + printf("COUNTER: %d\n", prob_req->counter); if (prob_req->counter < dawn_metric.min_probe_count) { return 0; @@ -212,7 +217,7 @@ static int decide_function(probe_entry *prob_req) { static void hostapd_handle_remove(struct ubus_context *ctx, struct ubus_subscriber *s, uint32_t id) { fprintf(stderr, "Object %08x went away\n", id); - //ubus_unsubscribe(ctx, &hostapd_event, id); + ubus_unsubscribe(ctx, s, id); hostapd_array_delete(id); } @@ -330,7 +335,7 @@ static int handle_probe_req(struct blob_attr *msg) { printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str); - print_probe_array(); + //print_probe_array(); /* // deny access if (!decide_function(&tmp_probe)) { @@ -362,17 +367,19 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, static int add_subscriber(char *name) { uint32_t id = 0; - if (ubus_lookup_id(ctx_hostapd, name, &id)) { + printf("DOING LOOKUP!\n"); + if (ubus_lookup_id(ctx, name, &id)) { fprintf(stderr, "Failed to look up test object for %s\n", name); return -1; } + printf("Lookup success!\n"); if(hostapd_array_check_id(id)) { return 0; } - int ret = ubus_subscribe(ctx_hostapd, &hostapd_event, id); + int ret = ubus_subscribe(ctx, &hostapd_event, id); hostapd_array_insert(id); fprintf(stderr, "Watching object %08x: %s\n", id, ubus_strerror(ret)); @@ -383,7 +390,7 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { DIR *dirp; struct dirent *entry; - if(ctx_hostapd == NULL) + if(ctx == NULL) { return 0; } @@ -406,13 +413,13 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { static int subscribe_to_hostapd(char *hostapd_dir) { - if(ctx_hostapd == NULL) + if(ctx == NULL) { return 0; } printf("Registering ubus event subscriber!\n"); - int ret = ubus_register_subscriber(ctx_hostapd, &hostapd_event); + int ret = ubus_register_subscriber(ctx, &hostapd_event); if (ret) { fprintf(stderr, "Failed to add watch handler: %s\n", ubus_strerror(ret)); return -1; @@ -446,7 +453,9 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { // set dawn metric dawn_metric = uci_get_dawn_metric(); - //subscribe_to_hostapd(hostapd_dir); + subscribe_to_hostapd(hostapd_dir); + + uloop_timeout_add(&hostapd_timer); //ubus_call_umdns(); @@ -593,18 +602,21 @@ void *update_clients_thread(void *arg) { return 0; } -void *update_hostapd_sockets(void *arg) { - time_t time_update_hostapd = *(time_t *) arg; +void update_hostapd_sockets(struct uloop_timeout *t) { + //uloop_init(); + //time_t time_update_hostapd = *(time_t *) arg; - printf("Update hostapd thread with time: %lu\n", time_update_hostapd); - const char *ubus_socket = NULL; - ctx_hostapd = ubus_connect(ubus_socket); + //printf("Update hostapd thread with time: %lu\n", time_update_hostapd); + //const char *ubus_socket = NULL; + //ctx_hostapd = ubus_connect(ubus_socket); + //ubus_add_uloop(ctx_hostapd); + //uloop_run(); + uloop_timeout_set(&hostapd_timer, 1000); - subscribe_to_hostapd(hostapd_dir_glob); - while (1) { +// while (1) { subscribe_to_hostapd_interfaces(hostapd_dir_glob); - sleep(time_update_hostapd); - } +// sleep(time_update_hostapd); +// } } void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) { From 8e1262c7f80042f52b90d3388fe137ee2a6997d8 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 20 Nov 2017 11:37:41 +0100 Subject: [PATCH 016/174] change to ubus timeout --- src/include/datastorage.h | 2 ++ src/main.c | 1 + src/utils/ubus.c | 16 ++-------------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 1f50f6d..0a66b3f 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -37,6 +37,8 @@ struct time_config_s { time_t update_hostapd; }; +struct time_config_s timeout_config; + // ---------------- Global variables ---------------- struct probe_metric_s dawn_metric; diff --git a/src/main.c b/src/main.c index b147250..e26efbc 100644 --- a/src/main.c +++ b/src/main.c @@ -147,6 +147,7 @@ int main(int argc, char **argv) { gcrypt_set_key_and_iv(shared_key, iv); struct time_config_s time_config = uci_get_time_config(); + timeout_config = time_config; // TODO: Refactor... if (pthread_mutex_init(&list_mutex, NULL) != 0) { printf("\n mutex init failed\n"); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 923424f..7c75645 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -603,20 +603,8 @@ void *update_clients_thread(void *arg) { } void update_hostapd_sockets(struct uloop_timeout *t) { - //uloop_init(); - //time_t time_update_hostapd = *(time_t *) arg; - - //printf("Update hostapd thread with time: %lu\n", time_update_hostapd); - //const char *ubus_socket = NULL; - //ctx_hostapd = ubus_connect(ubus_socket); - //ubus_add_uloop(ctx_hostapd); - //uloop_run(); - uloop_timeout_set(&hostapd_timer, 1000); - -// while (1) { - subscribe_to_hostapd_interfaces(hostapd_dir_glob); -// sleep(time_update_hostapd); -// } + uloop_timeout_set(&hostapd_timer, timeout_config.update_hostapd); + subscribe_to_hostapd_interfaces(hostapd_dir_glob); } void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) { From 9c80d0542e57d97d785b3f95b23561575f59da93 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 20 Nov 2017 12:19:44 +0100 Subject: [PATCH 017/174] switch to ubloop --- files/dawn.config | 1 + src/include/datastorage.h | 4 +++ src/main.c | 14 +++++------ src/storage/datastorage.c | 51 +++++++++++++++++++++++++++++++++++++++ src/utils/dawn_uci.c | 7 ++++++ src/utils/ubus.c | 36 ++++++++++++++++----------- 6 files changed, 92 insertions(+), 21 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 816506f..4051456 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -14,6 +14,7 @@ config settings times option update_client '50' option remove_client '120' option remove_probe '120' + option remove_ap '460' option update_hostapd '10' config settings metric diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 0a66b3f..4e5dd02 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -8,6 +8,7 @@ #include #include #include +#include #ifndef ETH_ALEN #define ETH_ALEN 6 @@ -34,6 +35,7 @@ struct time_config_s { time_t update_client; time_t remove_client; time_t remove_probe; + time_t remove_ap; time_t update_hostapd; }; @@ -92,6 +94,8 @@ void print_auth_entry(auth_entry entry); void *remove_probe_array_thread(void *arg); +void uloop_add_data_cbs(); + /* AP, Client */ // ---------------- Structs ---------------- diff --git a/src/main.c b/src/main.c index e26efbc..fe69836 100644 --- a/src/main.c +++ b/src/main.c @@ -38,7 +38,7 @@ struct sigaction newSigAction; pthread_t tid_probe; pthread_t tid_client; -pthread_t tid_get_client; +//pthread_t tid_get_client; //pthread_t tid_update_hostapd_socks; pthread_t tid_kick_clients; pthread_t tid_ap; @@ -47,9 +47,9 @@ void daemon_shutdown() { // kill threads printf("Cancelling Threads!\n"); - pthread_cancel(tid_probe); - pthread_cancel(tid_client); - pthread_cancel(tid_get_client); + // pthread_cancel(tid_probe); + // pthread_cancel(tid_client); + //pthread_cancel(tid_get_client); //pthread_cancel(tid_update_hostapd_socks); // free ressources @@ -171,9 +171,9 @@ int main(int argc, char **argv) { init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); - pthread_create(&tid_probe, NULL, &remove_probe_array_thread, (void *) &time_config.remove_probe); - pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client); - pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); + //pthread_create(&tid_probe, NULL, &remove_probe_array_thread, (void *) &time_config.remove_probe); + //pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client); + //pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); //pthread_create(&tid_update_hostapd_socks, NULL, &update_hostapd_sockets, &time_config.update_hostapd); dawn_init_ubus(ubus_socket, opt_hostapd_dir); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index f8c389c..b7783fc 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -1,6 +1,7 @@ #include "datastorage.h" #include +#include #include "ubus.h" #include "rssi.h" @@ -44,6 +45,24 @@ int probe_entry_last = -1; int client_entry_last = -1; int ap_entry_last = -1; +void remove_probe_array_cb(struct uloop_timeout *t); + +struct uloop_timeout probe_timeout = { + .cb = remove_probe_array_cb +}; + +void remove_client_array_cb(struct uloop_timeout *t); + +struct uloop_timeout client_timeout = { + .cb = remove_client_array_cb +}; + +void remove_ap_array_cb(struct uloop_timeout *t); + +struct uloop_timeout ap_timeout = { + .cb = remove_ap_array_cb +}; + int eval_probe_metric(struct probe_entry_s probe_entry) { int score = 0; @@ -539,6 +558,13 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) { } } +void uloop_add_data_cbs() +{ + uloop_timeout_add(&probe_timeout); + uloop_timeout_add(&client_timeout); + uloop_timeout_add(&ap_timeout); +} + void *remove_probe_array_thread(void *arg) { printf("Removing thread with time: %lu\n", *(long int *) arg); time_t time_treshold = *(time_t *) arg; @@ -552,6 +578,14 @@ void *remove_probe_array_thread(void *arg) { return 0; } +void remove_probe_array_cb(struct uloop_timeout *t) { + pthread_mutex_lock(&probe_array_mutex); + printf("[Thread] : Removing old entries!\n"); + remove_old_probe_entries(time(0), timeout_config.remove_probe); + pthread_mutex_unlock(&probe_array_mutex); + uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000); +} + void *remove_client_array_thread(void *arg) { time_t time_treshold_client = *(time_t *) arg; printf("Removing client thread with time: %lu\n", time_treshold_client); @@ -565,6 +599,15 @@ void *remove_client_array_thread(void *arg) { return 0; } +void remove_client_array_cb(struct uloop_timeout *t) +{ + pthread_mutex_lock(&client_array_mutex); + printf("[Thread] : Removing old client entries!\n"); + remove_old_client_entries(time(0), timeout_config.update_client); + pthread_mutex_unlock(&client_array_mutex); + uloop_timeout_set(&client_timeout, timeout_config.update_client * 1000); +} + void *remove_ap_array_thread(void *arg) { time_t time_treshold_ap = *(time_t *) arg; printf("Removing ap thread with time: %lu\n", time_treshold_ap); @@ -578,6 +621,14 @@ void *remove_ap_array_thread(void *arg) { return 0; } +void remove_ap_array_cb(struct uloop_timeout *t) { + pthread_mutex_lock(&ap_array_mutex); + printf("[ULOOP] : Removing old ap entries!\n"); + remove_old_ap_entries(time(0), timeout_config.remove_ap); + pthread_mutex_unlock(&ap_array_mutex); + uloop_timeout_set(&ap_timeout, timeout_config.remove_ap * 1000); +} + void insert_client_to_array(client entry) { pthread_mutex_lock(&client_array_mutex); entry.time = time(0); diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 378284b..186578c 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -63,6 +63,13 @@ struct time_config_s uci_get_time_config() { if (ptr.o->type == UCI_TYPE_STRING) ret.update_hostapd = atoi(ptr.o->v.string); + char tmp_remove_ap[] = "dawn.times.remove_ap"; + if (uci_lookup_ptr(c, &ptr, tmp_remove_ap, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.remove_ap = atoi(ptr.o->v.string); printf("Times: %lu, %lu, %lu %lu\n", ret.update_client, ret.remove_client, ret.remove_probe, ret.update_hostapd); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 7c75645..b3d599e 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -14,6 +14,7 @@ #include "networksocket.h" #include "utils.h" #include "dawn_uci.h" +#include "datastorage.h" static struct ubus_context *ctx = NULL; static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */ @@ -22,10 +23,16 @@ static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange be static struct ubus_subscriber hostapd_event; static struct blob_buf b; +void update_clients(struct uloop_timeout *t); + struct uloop_timeout hostapd_timer = { .cb = update_hostapd_sockets }; +struct uloop_timeout client_timer = { + .cb = update_clients +}; + #define MAX_HOSTAPD_SOCKETS 10 uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS]; int hostapd_sock_last = -1; @@ -455,8 +462,19 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { subscribe_to_hostapd(hostapd_dir); + // update hostapd uloop_timeout_add(&hostapd_timer); + // remove probe + //uloop_timeout_add(&probe_timeout); + uloop_add_data_cbs(); + + // get clients + const char *ubus_socket_clients = NULL; + ctx_clients = ubus_connect(ubus_socket_clients); + uloop_timeout_add(&client_timer); + + //ubus_call_umdns(); uloop_run(); @@ -587,24 +605,14 @@ static int ubus_get_clients() { return 0; } -void *update_clients_thread(void *arg) { - time_t time_update_client = *(time_t *) arg; - printf("Update client thread with time: %lu\n", time_update_client); - - const char *ubus_socket = NULL; - ctx_clients = ubus_connect(ubus_socket); - - while (1) { - sleep(time_update_client); - printf("[Thread] : Kicking clients!\n"); - ubus_get_clients(); - } - return 0; +void update_clients(struct uloop_timeout *t) { + ubus_get_clients(); + uloop_timeout_set(&client_timer, timeout_config.update_client * 1000); } void update_hostapd_sockets(struct uloop_timeout *t) { - uloop_timeout_set(&hostapd_timer, timeout_config.update_hostapd); subscribe_to_hostapd_interfaces(hostapd_dir_glob); + uloop_timeout_set(&hostapd_timer, timeout_config.update_hostapd * 1000); } void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) { From bef2c699dd905150315f27b944b68a8b605dbd19 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 20 Nov 2017 19:05:07 +0100 Subject: [PATCH 018/174] remove old thread stuff --- src/main.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/main.c b/src/main.c index fe69836..4dea927 100644 --- a/src/main.c +++ b/src/main.c @@ -25,10 +25,7 @@ #define _GNU_SOURCE #include -#include - -//static void* (*real_malloc)(size_t)=NULL; -//static void* (*real_free)(void *p)=NULL; +#include s void daemon_shutdown(); @@ -36,21 +33,11 @@ void signal_handler(int sig); struct sigaction newSigAction; -pthread_t tid_probe; -pthread_t tid_client; -//pthread_t tid_get_client; -//pthread_t tid_update_hostapd_socks; -pthread_t tid_kick_clients; -pthread_t tid_ap; - void daemon_shutdown() { // kill threads printf("Cancelling Threads!\n"); - // pthread_cancel(tid_probe); - // pthread_cancel(tid_client); - //pthread_cancel(tid_get_client); - //pthread_cancel(tid_update_hostapd_socks); + uloop_cancelled = true; // free ressources printf("Freeing mutex ressources\n"); @@ -58,25 +45,19 @@ void daemon_shutdown() { pthread_mutex_destroy(&probe_array_mutex); pthread_mutex_destroy(&client_array_mutex); pthread_mutex_destroy(&ap_array_mutex); - - //printf("Free Counter: %d\n", free_counter); } void signal_handler(int sig) { printf("SOME SIGNAL RECEIVED!\n"); switch (sig) { case SIGHUP: - //syslog(LOG_WARNING, "Received SIGHUP signal."); break; case SIGINT: case SIGTERM: - //syslog(LOG_INFO, "Daemon exiting"); - //daemonShutdown(); daemon_shutdown(); exit(EXIT_SUCCESS); break; default: - //syslog(LOG_WARNING, "Unhandled signal %s", strsignal(sig)); break; } } @@ -171,11 +152,6 @@ int main(int argc, char **argv) { init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); - //pthread_create(&tid_probe, NULL, &remove_probe_array_thread, (void *) &time_config.remove_probe); - //pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client); - //pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client); - //pthread_create(&tid_update_hostapd_socks, NULL, &update_hostapd_sockets, &time_config.update_hostapd); - dawn_init_ubus(ubus_socket, opt_hostapd_dir); return 0; From 5705946da6da6f550575bb5ce1473d0ecc7ec489 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 20 Nov 2017 19:05:58 +0100 Subject: [PATCH 019/174] remove old thread stuff --- src/include/datastorage.h | 7 ------- src/main.c | 17 +---------------- src/storage/datastorage.c | 39 --------------------------------------- src/utils/ubus.c | 4 ---- 4 files changed, 1 insertion(+), 66 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 4e5dd02..93f845f 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -8,7 +8,6 @@ #include #include #include -#include #ifndef ETH_ALEN #define ETH_ALEN 6 @@ -92,8 +91,6 @@ void print_probe_entry(probe_entry entry); void print_auth_entry(auth_entry entry); -void *remove_probe_array_thread(void *arg); - void uloop_add_data_cbs(); /* AP, Client */ @@ -155,14 +152,10 @@ void print_client_array(); void print_client_entry(client entry); -void *remove_client_array_thread(void *arg); - ap insert_to_ap_array(ap entry); void print_ap_array(); -void *remove_ap_array_thread(void *arg); - ap ap_array_get_ap(uint8_t bssid_addr[]); /* Utils */ diff --git a/src/main.c b/src/main.c index 4dea927..dba35be 100644 --- a/src/main.c +++ b/src/main.c @@ -1,32 +1,18 @@ #include -#include - #include #include -#include -#include #include -#include #include -#include #include "datastorage.h" #include "networksocket.h" #include "ubus.h" #include "dawn_uci.h" -#include "rssi.h" +#include "crypto.h" #define BUFSIZE 17 #define BUFSIZE_DIR 256 - -#include "crypto.h" - -#define _GNU_SOURCE - -#include -#include s - void daemon_shutdown(); void signal_handler(int sig); @@ -34,7 +20,6 @@ void signal_handler(int sig); struct sigaction newSigAction; void daemon_shutdown() { - // kill threads printf("Cancelling Threads!\n"); uloop_cancelled = true; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index b7783fc..936f652 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -565,19 +565,6 @@ void uloop_add_data_cbs() uloop_timeout_add(&ap_timeout); } -void *remove_probe_array_thread(void *arg) { - printf("Removing thread with time: %lu\n", *(long int *) arg); - time_t time_treshold = *(time_t *) arg; - while (1) { - sleep(time_treshold); - pthread_mutex_lock(&probe_array_mutex); - printf("[Thread] : Removing old entries!\n"); - remove_old_probe_entries(time(0), time_treshold); - pthread_mutex_unlock(&probe_array_mutex); - } - return 0; -} - void remove_probe_array_cb(struct uloop_timeout *t) { pthread_mutex_lock(&probe_array_mutex); printf("[Thread] : Removing old entries!\n"); @@ -586,19 +573,6 @@ void remove_probe_array_cb(struct uloop_timeout *t) { uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000); } -void *remove_client_array_thread(void *arg) { - time_t time_treshold_client = *(time_t *) arg; - printf("Removing client thread with time: %lu\n", time_treshold_client); - while (1) { - sleep(time_treshold_client); - pthread_mutex_lock(&client_array_mutex); - printf("[Thread] : Removing old client entries!\n"); - remove_old_client_entries(time(0), time_treshold_client); - pthread_mutex_unlock(&client_array_mutex); - } - return 0; -} - void remove_client_array_cb(struct uloop_timeout *t) { pthread_mutex_lock(&client_array_mutex); @@ -608,19 +582,6 @@ void remove_client_array_cb(struct uloop_timeout *t) uloop_timeout_set(&client_timeout, timeout_config.update_client * 1000); } -void *remove_ap_array_thread(void *arg) { - time_t time_treshold_ap = *(time_t *) arg; - printf("Removing ap thread with time: %lu\n", time_treshold_ap); - while (1) { - sleep(time_treshold_ap); - pthread_mutex_lock(&ap_array_mutex); - printf("[Thread] : Removing old ap entries!\n"); - remove_old_ap_entries(time(0), time_treshold_ap); - pthread_mutex_unlock(&ap_array_mutex); - } - return 0; -} - void remove_ap_array_cb(struct uloop_timeout *t) { pthread_mutex_lock(&ap_array_mutex); printf("[ULOOP] : Removing old ap entries!\n"); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b3d599e..33e7488 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -18,7 +18,6 @@ static struct ubus_context *ctx = NULL; static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */ -//static struct ubus_context *ctx_hostapd; static struct ubus_subscriber hostapd_event; static struct blob_buf b; @@ -374,12 +373,10 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, static int add_subscriber(char *name) { uint32_t id = 0; - printf("DOING LOOKUP!\n"); if (ubus_lookup_id(ctx, name, &id)) { fprintf(stderr, "Failed to look up test object for %s\n", name); return -1; } - printf("Lookup success!\n"); if(hostapd_array_check_id(id)) { @@ -466,7 +463,6 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { uloop_timeout_add(&hostapd_timer); // remove probe - //uloop_timeout_add(&probe_timeout); uloop_add_data_cbs(); // get clients From eae48256b1a7cebeec493475501a211e5f369817 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 20 Nov 2017 19:36:44 +0100 Subject: [PATCH 020/174] remove prints --- src/utils/ubus.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b3d599e..d273bed 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -374,13 +374,11 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, static int add_subscriber(char *name) { uint32_t id = 0; - printf("DOING LOOKUP!\n"); if (ubus_lookup_id(ctx, name, &id)) { fprintf(stderr, "Failed to look up test object for %s\n", name); return -1; } - printf("Lookup success!\n"); - + if(hostapd_array_check_id(id)) { return 0; From 6eee1214a2fc60c6145031be3c85af622341447e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 20 Nov 2017 19:54:28 +0100 Subject: [PATCH 021/174] fix eval probe metric --- src/storage/datastorage.c | 4 ++-- src/utils/ubus.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 936f652..c8eda89 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -71,9 +71,9 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { // check if ap entry is available if (mac_is_equal(ap_entry.bssid_addr, probe_entry.bssid_addr)) { - score += probe_entry.ht_support ? dawn_metric.ht_support : 0; + score += probe_entry.ht_support && ap_entry.ht ? dawn_metric.ht_support : 0; score += !probe_entry.ht_support && !ap_entry.ht ? dawn_metric.no_ht_support : 0; - score += probe_entry.vht_support ? dawn_metric.vht_support : 0; + score += probe_entry.vht_support && ap_entry.vht ? dawn_metric.vht_support : 0; score += !probe_entry.vht_support && !ap_entry.vht ? dawn_metric.no_vht_support : 0; score += ap_entry.channel_utilization <= dawn_metric.max_chan_util ? dawn_metric.chan_util : 0; } diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 42f5573..33e7488 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -377,7 +377,7 @@ static int add_subscriber(char *name) { fprintf(stderr, "Failed to look up test object for %s\n", name); return -1; } - + if(hostapd_array_check_id(id)) { return 0; From 1a2aa2c6e2fafad3438414f55ad1e1af60186bb4 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 21 Nov 2017 18:37:12 +0100 Subject: [PATCH 022/174] insert macs to list --- files/mac_list | 2 ++ src/include/datastorage.h | 13 ++++++++ src/main.c | 1 - src/storage/datastorage.c | 63 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 files/mac_list diff --git a/files/mac_list b/files/mac_list new file mode 100644 index 0000000..8a35cbc --- /dev/null +++ b/files/mac_list @@ -0,0 +1,2 @@ +a4:2b:b0:de:f1:fd +f0:79:60:1c:26:f0 diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 93f845f..d375738 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -13,9 +13,22 @@ #define ETH_ALEN 6 #endif +/* Mac */ + +// ---------------- Defines ------------------- +#define MAC_LIST_LENGTH 100 + +// ---------------- Structs ---------------- +uint8_t mac_list[MAC_LIST_LENGTH][ETH_ALEN]; + +// ---------------- Functions ---------- +void insert_macs_from_file(); + /* Metric */ +struct probe_metric_s dawn_metric; + // ---------------- Structs ---------------- struct probe_metric_s { int ht_support; diff --git a/src/main.c b/src/main.c index dba35be..947a67e 100644 --- a/src/main.c +++ b/src/main.c @@ -108,7 +108,6 @@ int main(int argc, char **argv) { sigaction(SIGTERM, &newSigAction, NULL); /* catch term signal */ sigaction(SIGINT, &newSigAction, NULL); /* catch interrupt signal */ - gcrypt_init(); gcrypt_set_key_and_iv(shared_key, iv); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index c8eda89..bc44789 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -41,9 +41,12 @@ int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_ int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]); +int mac_in_maclist(uint8_t mac[]); + int probe_entry_last = -1; int client_entry_last = -1; int ap_entry_last = -1; +int mac_list_entry_last = -1; void remove_probe_array_cb(struct uloop_timeout *t); @@ -134,7 +137,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) { } int kick_client(struct client_s client_entry) { - return better_ap_available(client_entry.bssid_addr, client_entry.client_addr); + return !mac_in_maclist(client_entry.client_addr) && better_ap_available(client_entry.bssid_addr, client_entry.client_addr); } void kick_clients(uint8_t bssid[], uint32_t id) { @@ -600,6 +603,64 @@ void insert_client_to_array(client entry) { pthread_mutex_unlock(&client_array_mutex); } +void insert_macs_from_file() +{ + FILE * fp; + char * line = NULL; + size_t len = 0; + ssize_t read; + + fp = fopen("/etc/config/dawn", "r"); + if (fp == NULL) + exit(EXIT_FAILURE); + + while ((read = getline(&line, &len, fp)) != -1) { + printf("Retrieved line of length %zu :\n", read); + printf("%s", line); + + int tmp_int_mac[ETH_ALEN]; + sscanf(line, MACSTR, STR2MAC(tmp_int_mac)); + + for (int i = 0; i < ETH_ALEN; ++i) { + mac_list[mac_list_entry_last][i] = (uint8_t) tmp_int_mac[i]; + } + } + + printf("Printing MAC List:\n"); + for(int i = 0; i <= mac_list_entry_last; i++) + { + char mac_buf_target[20]; + sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[0])); + printf("%d: %s\n", i, mac_buf_target); + } + + fclose(fp); + if (line) + free(line); + exit(EXIT_SUCCESS); +} + +int mac_in_maclist(uint8_t mac[]) +{ + for(int i = 0; i <= mac_list_entry_last; i++) + { + if(mac_is_equal(mac, mac_list[i])) + { + return 1; + } + } + return 0; +} + + + + + + + + + + node *delete_probe_req(node **ret_remove, node *head, uint8_t bssid_addr[], uint8_t client_addr[]); From aa6f72e7ed2022ece20ef7f9109ffd1bf854c6f5 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 13:20:39 +0100 Subject: [PATCH 023/174] wait until socket can be bind --- src/network/broadcastsocket.c | 4 ++-- src/utils/ubus.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/network/broadcastsocket.c b/src/network/broadcastsocket.c index 152a7d8..b002046 100644 --- a/src/network/broadcastsocket.c +++ b/src/network/broadcastsocket.c @@ -32,10 +32,10 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_ addr->sin_addr.s_addr = inet_addr(_broadcast_ip); addr->sin_port = htons(_broadcast_port); - if (bind(sock, (struct sockaddr *) addr, sizeof(*addr)) < + while (bind(sock, (struct sockaddr *) addr, sizeof(*addr)) < 0) { fprintf(stderr, "Binding socket failed!\n"); - return -1; + sleep(1); } return sock; } \ No newline at end of file diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 33e7488..570ce00 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -607,6 +607,7 @@ void update_clients(struct uloop_timeout *t) { } void update_hostapd_sockets(struct uloop_timeout *t) { + printf("Updating hostapd sockets!\n"); subscribe_to_hostapd_interfaces(hostapd_dir_glob); uloop_timeout_set(&hostapd_timer, timeout_config.update_hostapd * 1000); } From 2a9d87698836644427c6c2d2a0fd129f6c0465bc Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 15:11:43 +0100 Subject: [PATCH 024/174] add function to main --- src/main.c | 2 ++ src/storage/datastorage.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 947a67e..1d4805e 100644 --- a/src/main.c +++ b/src/main.c @@ -136,6 +136,8 @@ int main(int argc, char **argv) { init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); + insert_macs_from_file(); + dawn_init_ubus(ubus_socket, opt_hostapd_dir); return 0; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index bc44789..ce47b42 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -610,7 +610,7 @@ void insert_macs_from_file() size_t len = 0; ssize_t read; - fp = fopen("/etc/config/dawn", "r"); + fp = fopen("/etc/dawn/mac_list", "r"); if (fp == NULL) exit(EXIT_FAILURE); @@ -621,6 +621,7 @@ void insert_macs_from_file() int tmp_int_mac[ETH_ALEN]; sscanf(line, MACSTR, STR2MAC(tmp_int_mac)); + mac_list_entry_last++; for (int i = 0; i < ETH_ALEN; ++i) { mac_list[mac_list_entry_last][i] = (uint8_t) tmp_int_mac[i]; } @@ -630,7 +631,7 @@ void insert_macs_from_file() for(int i = 0; i <= mac_list_entry_last; i++) { char mac_buf_target[20]; - sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[0])); + sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[i])); printf("%d: %s\n", i, mac_buf_target); } From 4c16b53e5d9411afaac3be2b02d3655d6964b007 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 16:10:32 +0100 Subject: [PATCH 025/174] add object --- src/utils/ubus.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 33e7488..27f4d41 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -473,6 +473,8 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { //ubus_call_umdns(); + ubus_add_oject(); + uloop_run(); close_socket(); @@ -686,4 +688,60 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { send_string_enc(str); return 0; +} + +enum { + MAC_ADDR, + __ADD_DEL_MAC_MAX +}; + +static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = { + [MAC_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, +}; + +static const struct ubus_method dawn_methods[] = { + UBUS_METHOD("hello", test_hello, add_del_policy), +}; + +static struct ubus_object_type dawn_object_type = + UBUS_OBJECT_TYPE("test", dawn_methods); + +static struct ubus_object dawn_object = { + .name = "dawn", + .type = &dawn_object_type, + .methods = dawn_methods, + .n_methods = ARRAY_SIZE(dawn_methods), +}; + +static int +add_mac(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { + + struct blob_attr *tb[__ADD_DEL_MAC_MAX]; + uint8_t addr[ETH_ALEN]; + + blobmsg_parse(add_del_policy, __ADD_DEL_MAC_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[MAC_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + printf("ADDED SOME MAC!\n"); +} + +static void ubus_add_oject(void) +{ + int ret; + + ret = ubus_add_object(ctx, &dawn_object); + if (ret) + fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret)); + + /*ret = ubus_register_subscriber(ctx, &test_event); + if (ret) + fprintf(stderr, "Failed to add watch handler: %s\n", ubus_strerror(ret)); + */ } \ No newline at end of file From 8eaba2697452e72fb48351f475415a3bf967dfea Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 16:11:35 +0100 Subject: [PATCH 026/174] add object --- src/include/datastorage.h | 1 + src/include/utils.h | 2 ++ src/storage/datastorage.c | 17 ++++++++++++++++- src/utils/ubus.c | 17 +++++++++++++---- src/utils/utils.c | 16 ++++++++++++++++ 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index d375738..dce9263 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -23,6 +23,7 @@ uint8_t mac_list[MAC_LIST_LENGTH][ETH_ALEN]; // ---------------- Functions ---------- void insert_macs_from_file(); +int insert_to_maclist(uint8_t mac[]); /* Metric */ diff --git a/src/include/utils.h b/src/include/utils.h index ec0e87a..e07a776 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -15,4 +15,6 @@ int hwaddr_aton(const char *txt, uint8_t *addr); int convert_mac(char *in, char *out); +void write_mac_to_file(char* path, uint8_t addr[]); + #endif \ No newline at end of file diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index ce47b42..2eb08f4 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -638,9 +638,24 @@ void insert_macs_from_file() fclose(fp); if (line) free(line); - exit(EXIT_SUCCESS); + //exit(EXIT_SUCCESS); } +int insert_to_maclist(uint8_t mac[]) +{ + if(mac_in_maclist(mac)) + { + return 0; + } + + mac_list_entry_last++; + for (int i = 0; i < ETH_ALEN; ++i) { + mac_list[mac_list_entry_last][i] = mac[i]; + } + return 0; +} + + int mac_in_maclist(uint8_t mac[]) { for(int i = 0; i <= mac_list_entry_last; i++) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 27f4d41..caba791 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -136,9 +136,15 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir); static int ubus_get_clients(); +static int +add_mac(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); + int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); void hostapd_array_delete(uint32_t id); +static void ubus_add_oject(); int hostapd_array_check_id(uint32_t id) { @@ -700,11 +706,11 @@ static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = { }; static const struct ubus_method dawn_methods[] = { - UBUS_METHOD("hello", test_hello, add_del_policy), + UBUS_METHOD("add_mac", add_mac, add_del_policy), }; static struct ubus_object_type dawn_object_type = - UBUS_OBJECT_TYPE("test", dawn_methods); + UBUS_OBJECT_TYPE("dawn", dawn_methods); static struct ubus_object dawn_object = { .name = "dawn", @@ -729,10 +735,13 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj, if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr)) return UBUS_STATUS_INVALID_ARGUMENT; - printf("ADDED SOME MAC!\n"); + insert_to_maclist(addr); + write_mac_to_file("/etc/dawn/mac_list", addr); + + return 0; } -static void ubus_add_oject(void) +static void ubus_add_oject() { int ret; diff --git a/src/utils/utils.c b/src/utils/utils.c index 323d4b2..8af0488 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -44,3 +44,19 @@ int convert_mac(char *in, char *out) { return 0; } +void write_mac_to_file(char* path, uint8_t addr[]) +{ + FILE *f = fopen(path, "a"); + if (f == NULL) + { + printf("Error opening file!\n"); + exit(1); + } + + char mac_buf[20]; + sprintf(mac_buf, MACSTR, MAC2STR(addr)); + + fprintf(f, "%s\n", mac_buf); + + fclose(f); +} \ No newline at end of file From c5ce7c77e2f44ef1282020713d80bbf0ee1b72de Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 20:49:04 +0100 Subject: [PATCH 027/174] add maclist file --- files/mac_list | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 files/mac_list diff --git a/files/mac_list b/files/mac_list new file mode 100644 index 0000000..e69de29 From 23987d68e7144615c4f5691f06d0173df9568e11 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 20:49:04 +0100 Subject: [PATCH 028/174] add maclist file --- files/dawn.config | 2 +- files/mac_list | 0 src/main.c | 2 +- src/network/multicastsocket.c | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 files/mac_list diff --git a/files/dawn.config b/files/dawn.config index 4051456..f6dcc67 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,5 +1,5 @@ config settings network - option broadcast_ip '10.0.0.255' + option broadcast_ip '226.94.1.1' option broadcast_port '1025' option shared_key 'Niiiiiiiiiiiiiik' option iv 'Niiiiiiiiiiiiiik' diff --git a/files/mac_list b/files/mac_list new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c b/src/main.c index dba35be..446ef6b 100644 --- a/src/main.c +++ b/src/main.c @@ -135,7 +135,7 @@ int main(int argc, char **argv) { return 1; } - init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); + init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 0); dawn_init_ubus(ubus_socket, opt_hostapd_dir); diff --git a/src/network/multicastsocket.c b/src/network/multicastsocket.c index 5fed812..a3e89b7 100644 --- a/src/network/multicastsocket.c +++ b/src/network/multicastsocket.c @@ -19,7 +19,7 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ memset(addr, 0, sizeof(*addr)); addr->sin_family = AF_INET; - addr->sin_addr.s_addr = htonl (INADDR_ANY); + addr->sin_addr.s_addr = inet_addr(_multicast_ip); addr->sin_port = htons (_multicast_port); if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { From 513535be4f7cf404d20357bdaabc1fa36c5dd3a0 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 7 Dec 2017 19:00:47 +0100 Subject: [PATCH 029/174] add multicast in config file --- files/dawn.config | 1 + files/dawn.init | 6 ++++++ src/main.c | 5 ++++- src/network/multicastsocket.c | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index f6dcc67..15c8836 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,6 +1,7 @@ config settings network option broadcast_ip '226.94.1.1' option broadcast_port '1025' + option multicast '1' option shared_key 'Niiiiiiiiiiiiiik' option iv 'Niiiiiiiiiiiiiik' diff --git a/files/dawn.init b/files/dawn.init index 7bc1f79..8e9a39c 100755 --- a/files/dawn.init +++ b/files/dawn.init @@ -28,6 +28,8 @@ start_service() config_get sort_order ordering sort_order config_get hostapd_dir hostapd hostapd_dir + config_get multicast network multicast + procd_open_instance echo "$PROG -p $broadcast_port -i $broadcast_ip -o $sort_order" procd_set_param command "$PROG" @@ -38,6 +40,10 @@ start_service() procd_append_param command -k "${shared_key}" procd_append_param command -v "${iv}" + if [ "${multicast}" -gt 0 ]; then + procd_append_param command -m + fi + procd_set_param stdout 1 procd_set_param stderr 1 diff --git a/src/main.c b/src/main.c index 446ef6b..a688a0a 100644 --- a/src/main.c +++ b/src/main.c @@ -59,6 +59,7 @@ int main(int argc, char **argv) { char shared_key[BUFSIZE_DIR]; char iv[BUFSIZE_DIR]; + int multicast = 0; while ((ch = getopt(argc, argv, "cs:p:i:b:o:h:i:k:v:")) != -1) { switch (ch) { @@ -90,6 +91,8 @@ int main(int argc, char **argv) { snprintf(iv, BUFSIZE_DIR, "%s", optarg); printf("IV: %s\n", iv); break; + case 'm': + multicast = 1; default: break; } @@ -135,7 +138,7 @@ int main(int argc, char **argv) { return 1; } - init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 0); + init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, multicast); dawn_init_ubus(ubus_socket, opt_hostapd_dir); diff --git a/src/network/multicastsocket.c b/src/network/multicastsocket.c index a3e89b7..0ff6a95 100644 --- a/src/network/multicastsocket.c +++ b/src/network/multicastsocket.c @@ -19,7 +19,7 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ memset(addr, 0, sizeof(*addr)); addr->sin_family = AF_INET; - addr->sin_addr.s_addr = inet_addr(_multicast_ip); + addr->sin_addr.s_addr = inet_addr(_multicast_ip); addr->sin_port = htons (_multicast_port); if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { From 3dd4fc30ec45e343c6acd4cfbf211a4cabddc7fe Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 7 Dec 2017 19:34:31 +0100 Subject: [PATCH 030/174] rewrite multicast setup --- src/include/multicastsocket.h | 2 ++ src/include/networksocket.h | 2 +- src/main.c | 1 + src/network/multicastsocket.c | 16 ++++++++++++++-- src/network/networksocket.c | 17 ++++++++++++----- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/include/multicastsocket.h b/src/include/multicastsocket.h index fe305e0..3b8e86d 100644 --- a/src/include/multicastsocket.h +++ b/src/include/multicastsocket.h @@ -3,4 +3,6 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_port, struct sockaddr_in *addr); +int remove_multicast_socket(int socket); + #endif diff --git a/src/include/networksocket.h b/src/include/networksocket.h index 5b04f3e..4e11724 100644 --- a/src/include/networksocket.h +++ b/src/include/networksocket.h @@ -5,7 +5,7 @@ pthread_mutex_t send_mutex; -int init_socket_runopts(char *_ip, char *_port, int broadcast_socket); +int init_socket_runopts(char *_ip, char *_port, int _multicast_socket); int send_string(char *msg); diff --git a/src/main.c b/src/main.c index a688a0a..e7a9a0a 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,7 @@ struct sigaction newSigAction; void daemon_shutdown() { // kill threads + close_socket(); printf("Cancelling Threads!\n"); uloop_cancelled = true; diff --git a/src/network/multicastsocket.c b/src/network/multicastsocket.c index 0ff6a95..b67499e 100644 --- a/src/network/multicastsocket.c +++ b/src/network/multicastsocket.c @@ -11,7 +11,7 @@ #include "multicastsocket.h" -static struct ip_mreq command; /* static ?! */ +static struct ip_mreq command; int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_port, struct sockaddr_in *addr) { int loop = 1; @@ -57,7 +57,7 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ command.imr_multiaddr.s_addr = inet_addr(_multicast_ip); command.imr_interface.s_addr = htonl (INADDR_ANY); if (command.imr_multiaddr.s_addr == -1) { - perror("224.0.0.1 ist keine Multicast-Adresse\n"); + perror("Wrong multicast address!\n"); exit(EXIT_FAILURE); } if (setsockopt(sock, @@ -67,4 +67,16 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ perror("setsockopt:IP_ADD_MEMBERSHIP"); } return sock; +} + +int remove_multicast_socket(int socket) +{ + if (setsockopt ( socket, + IPPROTO_IP, + IP_DROP_MEMBERSHIP, + &command, sizeof (command)) < 0 ) { + perror ("setsockopt:IP_DROP_MEMBERSHIP"); + return -1; + } + return 0; } \ No newline at end of file diff --git a/src/network/networksocket.c b/src/network/networksocket.c index 6258ae5..ed33e02 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -29,21 +29,23 @@ const char *ip; unsigned short port; char recv_string[MAX_RECV_STRING + 1]; int recv_string_len; +int multicast_socket; void *receive_msg(void *args); void *receive_msg_enc(void *args); -int init_socket_runopts(char *_ip, char *_port, int broadcast_socket) { +int init_socket_runopts(char *_ip, char *_port, int _multicast_socket) { port = atoi(_port); ip = _ip; + multicast_socket = _multicast_socket; - if (broadcast_socket) { - sock = setup_broadcast_socket(ip, port, &addr); - } else { + if (multicast_socket) { printf("Settingup multicastsocket!\n"); sock = setup_multicast_socket(ip, port, &addr); + } else { + sock = setup_broadcast_socket(ip, port, &addr); } pthread_t sniffer_thread; @@ -235,4 +237,9 @@ int send_string_enc(char *msg) { return 0; } -void close_socket() { close(sock); } +void close_socket() { + if(multicast_socket){ + remove_multicast_socket(sock); + } + close(sock); +} From 38bdf3e3dc967c1acea10751fee1327ae7128c4c Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 8 Dec 2017 21:09:43 +0100 Subject: [PATCH 031/174] remove not used dependecies --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9633969..589f2b8 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,7 +42,7 @@ SET(SOURCES utils/utils.c include/rssi.h utils/rssi.c) SET(LIBS - ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto iwinfo) + ubox ubus json-c blobmsg_json config uci gcrypt iwinfo) ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h) From d8c645c407e4a4954da477e5daa7dfbbc69a8763 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 8 Dec 2017 21:31:34 +0100 Subject: [PATCH 032/174] subscribe to hostapd interfaces --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 570ce00..f5924f8 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -433,7 +433,7 @@ static int subscribe_to_hostapd(char *hostapd_dir) { hostapd_event.remove_cb = hostapd_handle_remove; hostapd_event.cb = hostapd_notify; - //subscribe_to_hostapd_interfaces(hostapd_dir); + subscribe_to_hostapd_interfaces(hostapd_dir); // free(hostapd_dir); // free string From 059578448096087c362df22d2c14a973c83521de Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 10 Dec 2017 23:17:17 +0100 Subject: [PATCH 033/174] del client from array after kicking --- src/storage/datastorage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index c8eda89..152ed2c 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -174,6 +174,7 @@ void kick_clients(uint8_t bssid[], uint32_t id) { printf("Better AP available. Kicking client:\n"); print_client_entry(client_array[j]); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); + client_array_delete(client_array[j]); // no entry in probe array for own bssid } else if (kick_client(client_array[j]) == -1) { From fe848b8231f02e5e72c9c8bc09e583baec454a0f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 10 Dec 2017 23:28:38 +0100 Subject: [PATCH 034/174] schedule a client update --- src/include/ubus.h | 2 ++ src/storage/datastorage.c | 2 ++ src/utils/ubus.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/include/ubus.h b/src/include/ubus.h index ce91d3a..2f1d190 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -32,4 +32,6 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry); void update_hostapd_sockets(struct uloop_timeout *t); +void add_client_update_timer(time_t time); + #endif diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 152ed2c..5e2ccfe 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -175,6 +175,8 @@ void kick_clients(uint8_t bssid[], uint32_t id) { print_client_entry(client_array[j]); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); client_array_delete(client_array[j]); + add_client_update_timer(timeout_config.update_client * 1000 / 4); + break; // no entry in probe array for own bssid } else if (kick_client(client_array[j]) == -1) { diff --git a/src/utils/ubus.c b/src/utils/ubus.c index f5924f8..2d09677 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -24,13 +24,12 @@ static struct blob_buf b; void update_clients(struct uloop_timeout *t); -struct uloop_timeout hostapd_timer = { - .cb = update_hostapd_sockets -}; - struct uloop_timeout client_timer = { .cb = update_clients }; +struct uloop_timeout hostapd_timer = { + .cb = update_hostapd_sockets +}; #define MAX_HOSTAPD_SOCKETS 10 uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS]; @@ -140,6 +139,11 @@ int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); void hostapd_array_delete(uint32_t id); +void add_client_update_timer(time_t time) +{ + uloop_timeout_set(&client_timer, time); +} + int hostapd_array_check_id(uint32_t id) { for(int i = 0; i <= hostapd_sock_last; i++) From 1fb65e896d323900e32934181c6afa57299a82c0 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 10 Dec 2017 23:41:12 +0100 Subject: [PATCH 035/174] use chan util in config --- files/dawn.config | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 15c8836..52668ad 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,7 +1,7 @@ config settings network - option broadcast_ip '226.94.1.1' + option broadcast_ip '10.0.0.255' option broadcast_port '1025' - option multicast '1' + option multicast '0' option shared_key 'Niiiiiiiiiiiiiik' option iv 'Niiiiiiiiiiiiiik' @@ -25,7 +25,7 @@ config settings metric option no_vht_support '0' option rssi '10' option freq '50' - option chan_util '0' - option max_chan_util '100' + option chan_util '50' + option max_chan_util '150' option min_rssi '-60' option min_probe_count '5' From 56b0e4e0b018f870b66aea6fb9d3d481148379e7 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 10 Dec 2017 23:43:12 +0100 Subject: [PATCH 036/174] set min count down --- files/dawn.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index 52668ad..55b6b32 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -28,4 +28,4 @@ config settings metric option chan_util '50' option max_chan_util '150' option min_rssi '-60' - option min_probe_count '5' + option min_probe_count '2' From 9825ba64c85f4eea25511f279888c329e3a7df99 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 10:23:59 +0100 Subject: [PATCH 037/174] add comments --- src/storage/datastorage.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 5e2ccfe..206c594 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -175,6 +175,9 @@ void kick_clients(uint8_t bssid[], uint32_t id) { print_client_entry(client_array[j]); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); client_array_delete(client_array[j]); + + // don't delete clients in a row. use update function again... + // -> chan_util update, ... add_client_update_timer(timeout_config.update_client * 1000 / 4); break; From f2c6f15dfc095100a990a010315de263065d42b6 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 10:42:50 +0100 Subject: [PATCH 038/174] add a lowest rssi --- files/dawn.config | 4 +++- src/include/datastorage.h | 4 +++- src/storage/datastorage.c | 3 ++- src/utils/dawn_uci.c | 22 +++++++++++++++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 55b6b32..83e67c2 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -24,8 +24,10 @@ config settings metric option no_ht_support '0' option no_vht_support '0' option rssi '10' + option low_rssi '-500' option freq '50' option chan_util '50' option max_chan_util '150' - option min_rssi '-60' + option rssi_val '-60' + option low_rssi_val '-79' option min_probe_count '2' diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 93f845f..6371c6c 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -23,10 +23,12 @@ struct probe_metric_s { int no_ht_support; int no_vht_support; int rssi; + int low_rssi; int freq; int chan_util; int max_chan_util; - int min_rssi; + int rssi_val; + int low_rssi_val; int min_probe_count; }; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 206c594..5f4cfb2 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -79,7 +79,8 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { } score += (probe_entry.freq > 5000) ? dawn_metric.freq : 0; - score += (probe_entry.signal >= dawn_metric.min_rssi) ? dawn_metric.rssi : 0; + score += (probe_entry.signal >= dawn_metric.rssi_val) ? dawn_metric.rssi : 0; + score += (probe_entry.signal <= dawn_metric.low_rssi_val) ? dawn_metric.low_rssi : 0; printf("SCORE: %d\n", score); print_probe_entry(probe_entry); diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 186578c..687f3dc 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -142,13 +142,13 @@ struct probe_metric_s uci_get_dawn_metric() { if (ptr.o->type == UCI_TYPE_STRING) ret.chan_util = atoi(ptr.o->v.string); - char tmp_min_rssi[] = "dawn.metric.min_rssi"; - if (uci_lookup_ptr(c, &ptr, tmp_min_rssi, 1) != UCI_OK) { + char tmp_rssi_val[] = "dawn.metric.rssi_val"; + if (uci_lookup_ptr(c, &ptr, tmp_rssi_val, 1) != UCI_OK) { uci_perror(c, "uci_get_daw_metric Error"); return ret; } if (ptr.o->type == UCI_TYPE_STRING) - ret.min_rssi = atoi(ptr.o->v.string); + ret.rssi_val = atoi(ptr.o->v.string); char tmp_max_chan_util[] = "dawn.metric.max_chan_util"; if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util, 1) != UCI_OK) { @@ -168,6 +168,22 @@ struct probe_metric_s uci_get_dawn_metric() { if (ptr.o->type == UCI_TYPE_STRING) ret.min_probe_count = atoi(ptr.o->v.string); + char tmp_low_rssi[] = "dawn.metric.low_rssi"; + if (uci_lookup_ptr(c, &ptr, tmp_low_rssi, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.low_rssi = atoi(ptr.o->v.string); + + char tmp_low_rssi_val[] = "dawn.metric.low_rssi_val"; + if (uci_lookup_ptr(c, &ptr, tmp_low_rssi_val, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.low_rssi_val = atoi(ptr.o->v.string); + printf("Loaded metric: %d\n", ret.min_probe_count); uci_free_context(c); From 41deaf6d9c35879e1dc1672a5e81c56ea7ca17e1 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 12:06:02 +0100 Subject: [PATCH 039/174] don't kick with rx_rate higher threshold --- files/dawn.config | 1 + src/CMakeLists.txt | 2 +- src/include/datastorage.h | 1 + src/include/{rssi.h => dawn_iwinfo.h} | 2 + src/storage/datastorage.c | 17 +++- src/utils/dawn_iwinfo.c | 137 ++++++++++++++++++++++++++ src/utils/dawn_uci.c | 8 ++ src/utils/rssi.c | 72 -------------- 8 files changed, 166 insertions(+), 74 deletions(-) rename src/include/{rssi.h => dawn_iwinfo.h} (69%) create mode 100644 src/utils/dawn_iwinfo.c delete mode 100644 src/utils/rssi.c diff --git a/files/dawn.config b/files/dawn.config index 83e67c2..6a6efbc 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -31,3 +31,4 @@ config settings metric option rssi_val '-60' option low_rssi_val '-79' option min_probe_count '2' + option bandwith_threshold '6' diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 589f2b8..ae445a9 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ SET(SOURCES crypto/base64.c include/base64.h - utils/utils.c include/rssi.h utils/rssi.c) + utils/utils.c include/dawn_iwinfo.h utils/dawn_iwinfo.c) SET(LIBS ubox ubus json-c blobmsg_json config uci gcrypt iwinfo) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 6371c6c..979063c 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -30,6 +30,7 @@ struct probe_metric_s { int rssi_val; int low_rssi_val; int min_probe_count; + int bandwith_threshold; }; struct time_config_s { diff --git a/src/include/rssi.h b/src/include/dawn_iwinfo.h similarity index 69% rename from src/include/rssi.h rename to src/include/dawn_iwinfo.h index 863f25b..215d817 100644 --- a/src/include/rssi.h +++ b/src/include/dawn_iwinfo.h @@ -8,4 +8,6 @@ int get_rssi_iwinfo(__uint8_t *client_addr); +int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); + #endif //DAWN_RSSI_H diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 5f4cfb2..4c4d37f 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -4,7 +4,7 @@ #include #include "ubus.h" -#include "rssi.h" +#include "dawn_iwinfo.h" #include "utils.h" #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] @@ -174,6 +174,21 @@ void kick_clients(uint8_t bssid[], uint32_t id) { if (kick_client(client_array[j]) > 0) { printf("Better AP available. Kicking client:\n"); print_client_entry(client_array[j]); + printf("Check if client is active receiving!\n"); + + float rx_rate, tx_rate; + if(get_bandwidth_iwinfo(client_array[j].client_addr, &rx_rate, &tx_rate)) + { + // only use rx_rate for indicating if transmission is going on + // <= 6MBits <- probably no transmission + // tx_rate has always some weird value so don't use ist + if(rx_rate >= dawn_metric.bandwith_threshold){ + printf("Client is propaly in active transmisison. Don't kick! RxRate is: %f\n", rx_rate); + continue; + } + } + + del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); client_array_delete(client_array[j]); diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c new file mode 100644 index 0000000..a8c24a9 --- /dev/null +++ b/src/utils/dawn_iwinfo.c @@ -0,0 +1,137 @@ +#include "dawn_iwinfo.h" + +#include +#include +#include + +#include "utils.h" +#include "ubus.h" + +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] + +int call_iwinfo(char *client_addr); + +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); + +#define IWINFO_BUFSIZE 24 * 1024 + +int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) { + + DIR *dirp; + struct dirent *entry; + dirp = opendir(hostapd_dir_glob); // error handling? + if (!dirp) { + fprintf(stderr, "No hostapd sockets!\n"); + return 0; + } + + int sucess = 0; + + while ((entry = readdir(dirp)) != NULL) { + if (entry->d_type == DT_SOCK) { + if(get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) + sucess = 1; + break; + } + } + closedir(dirp); + return sucess; +} + +int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate){ + + 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 0; + } + else if (len <= 0) + { + printf("No station connected\n"); + 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, e->mac)) + { + //struct iwinfo_assoclist_entry * rx_rate = e->rx_rate; + //struct iwinfo_assoclist_entry * tx_rate = e->tx_rate; + *rx_rate = e->rx_rate.rate / 1000; + *tx_rate = e->tx_rate.rate / 1000; + return 1; + } + // return e->signal; + + + } + + return 0; +} + +int get_rssi_iwinfo(__uint8_t *client_addr) { + + DIR *dirp; + struct dirent *entry; + dirp = opendir(hostapd_dir_glob); // error handling? + if (!dirp) { + fprintf(stderr, "No hostapd sockets!\n"); + return INT_MIN; + } + + int rssi = INT_MIN; + + while ((entry = readdir(dirp)) != NULL) { + if (entry->d_type == DT_SOCK) { + rssi = get_rssi(entry->d_name, client_addr); + if(rssi != INT_MIN) + break; + } + } + closedir(dirp); + return rssi; +} + +int get_rssi(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->signal; + } + + return INT_MIN; +} \ No newline at end of file diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 687f3dc..f694084 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -184,6 +184,14 @@ struct probe_metric_s uci_get_dawn_metric() { if (ptr.o->type == UCI_TYPE_STRING) ret.low_rssi_val = atoi(ptr.o->v.string); + char tmp_bandwith_threshold[] = "dawn.metric.bandwith_threshold"; + if (uci_lookup_ptr(c, &ptr, tmp_bandwith_threshold, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.bandwith_threshold = atoi(ptr.o->v.string); + printf("Loaded metric: %d\n", ret.min_probe_count); uci_free_context(c); diff --git a/src/utils/rssi.c b/src/utils/rssi.c deleted file mode 100644 index 7474613..0000000 --- a/src/utils/rssi.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "rssi.h" - -#include -#include -#include - -#include "utils.h" -#include "ubus.h" - -#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] - -int call_iwinfo(char *client_addr); - -int parse_rssi(char *iwinfo_string); - -int get_rssi(const char *ifname, uint8_t *client_addr); - -#define IWINFO_BUFSIZE 24 * 1024 - -int get_rssi_iwinfo(__uint8_t *client_addr) { - - DIR *dirp; - struct dirent *entry; - dirp = opendir(hostapd_dir_glob); // error handling? - if (!dirp) { - fprintf(stderr, "No hostapd sockets!\n"); - return -1; - } - - int rssi = INT_MIN; - - while ((entry = readdir(dirp)) != NULL) { - if (entry->d_type == DT_SOCK) { - rssi = get_rssi(entry->d_name, client_addr); - if(rssi != INT_MIN) - break; - } - } - closedir(dirp); - return rssi; -} - -int get_rssi(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->signal; - } - - return INT_MIN; -} \ No newline at end of file From a001c9584080379012346c13d271d0420eb3de12 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 12:27:56 +0100 Subject: [PATCH 040/174] add print --- src/storage/datastorage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 4c4d37f..b32a551 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -187,7 +187,7 @@ void kick_clients(uint8_t bssid[], uint32_t id) { continue; } } - + printf("Client is propaly NOT in active transmisison. KICK! RxRate is: %f\n", rx_rate); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); client_array_delete(client_array[j]); From ff36ff63bb4d27b225667411e8d9c8ade95fcde7 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 12:29:14 +0100 Subject: [PATCH 041/174] spelling --- src/storage/datastorage.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index b32a551..a7d8a65 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -182,12 +182,12 @@ void kick_clients(uint8_t bssid[], uint32_t id) { // only use rx_rate for indicating if transmission is going on // <= 6MBits <- probably no transmission // tx_rate has always some weird value so don't use ist - if(rx_rate >= dawn_metric.bandwith_threshold){ - printf("Client is propaly in active transmisison. Don't kick! RxRate is: %f\n", rx_rate); + if(rx_rate > dawn_metric.bandwith_threshold){ + printf("Client is probably in active transmisison. Don't kick! RxRate is: %f\n", rx_rate); continue; } } - printf("Client is propaly NOT in active transmisison. KICK! RxRate is: %f\n", rx_rate); + printf("Client is probably NOT in active transmisison. KICK! RxRate is: %f\n", rx_rate); del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); client_array_delete(client_array[j]); From 2e13d106837889ff63cc4874d4b3757a3527eb6e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:00:37 +0100 Subject: [PATCH 042/174] fix get_bandwith function --- src/utils/dawn_iwinfo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index a8c24a9..7cacad6 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -34,8 +34,10 @@ 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)) + { sucess = 1; break; + } } } closedir(dirp); From 0c1527b8b596bd38c20e4863506808edb75b6b3b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:04:00 +0100 Subject: [PATCH 043/174] bandwith found --- 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 7cacad6..a99a339 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -35,6 +35,7 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) if (entry->d_type == DT_SOCK) { if(get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) { + // bandwith found sucess = 1; break; } From 8113bd379bae98e72d063c1c3864f4ead391aa0f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:08:21 +0100 Subject: [PATCH 044/174] add counter to debug --- src/utils/dawn_iwinfo.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index a99a339..bb13b0c 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -31,14 +31,17 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) int sucess = 0; + int count = 0; while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { + printf("TRY TO GET BANDWITH: %d\n", count); if(get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) { // bandwith found sucess = 1; break; } + count++; } } closedir(dirp); From d319c248784a57d12e950b8c39cd1c805d10a286 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:11:39 +0100 Subject: [PATCH 045/174] remove prints --- src/utils/dawn_iwinfo.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index bb13b0c..28ef62d 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -34,14 +34,11 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) int count = 0; while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { - printf("TRY TO GET BANDWITH: %d\n", count); if(get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) { - // bandwith found sucess = 1; break; } - count++; } } closedir(dirp); From 947ccb85f0b24234b503ecea6ec9161dd7f4a0e8 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:18:25 +0100 Subject: [PATCH 046/174] update config --- files/dawn.config | 10 +++++----- src/utils/dawn_iwinfo.c | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 6a6efbc..9d93de5 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,7 +1,7 @@ config settings network - option broadcast_ip '10.0.0.255' + option broadcast_ip '226.94.1.1' option broadcast_port '1025' - option multicast '0' + option multicast '1' option shared_key 'Niiiiiiiiiiiiiik' option iv 'Niiiiiiiiiiiiiik' @@ -12,7 +12,7 @@ config settings hostapd option hostapd_dir '/var/run/hostapd' config settings times - option update_client '50' + option update_client '10' option remove_client '120' option remove_probe '120' option remove_ap '460' @@ -25,10 +25,10 @@ config settings metric option no_vht_support '0' option rssi '10' option low_rssi '-500' - option freq '50' + option freq '100' option chan_util '50' option max_chan_util '150' option rssi_val '-60' - option low_rssi_val '-79' + option low_rssi_val '-80' option min_probe_count '2' option bandwith_threshold '6' diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 28ef62d..7cacad6 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -31,7 +31,6 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) int sucess = 0; - int count = 0; while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { if(get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) From edf60681ccf362ffb595161a93877c591ba04d2a Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:28:02 +0100 Subject: [PATCH 047/174] fix multicast --- src/network/multicastsocket.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/network/multicastsocket.c b/src/network/multicastsocket.c index b67499e..2f351cf 100644 --- a/src/network/multicastsocket.c +++ b/src/network/multicastsocket.c @@ -55,7 +55,6 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ /* Join the broadcast group: */ command.imr_multiaddr.s_addr = inet_addr(_multicast_ip); - command.imr_interface.s_addr = htonl (INADDR_ANY); if (command.imr_multiaddr.s_addr == -1) { perror("Wrong multicast address!\n"); exit(EXIT_FAILURE); From 49a9a8734fc0f286304f17f434e332dec59f21bd Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:41:36 +0100 Subject: [PATCH 048/174] fix multicast --- src/network/multicastsocket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/network/multicastsocket.c b/src/network/multicastsocket.c index 2f351cf..6e15244 100644 --- a/src/network/multicastsocket.c +++ b/src/network/multicastsocket.c @@ -54,7 +54,8 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ } /* Join the broadcast group: */ - command.imr_multiaddr.s_addr = inet_addr(_multicast_ip); + //command.imr_multiaddr.s_addr = inet_addr(_multicast_ip); + command.imr_interface.s_addr = htonl (INADDR_ANY); if (command.imr_multiaddr.s_addr == -1) { perror("Wrong multicast address!\n"); exit(EXIT_FAILURE); From 5153b0e0123fafebe34881f92dc778934f53bdc8 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:48:51 +0100 Subject: [PATCH 049/174] fix multicast --- src/network/multicastsocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/multicastsocket.c b/src/network/multicastsocket.c index 6e15244..b67499e 100644 --- a/src/network/multicastsocket.c +++ b/src/network/multicastsocket.c @@ -54,7 +54,7 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ } /* Join the broadcast group: */ - //command.imr_multiaddr.s_addr = inet_addr(_multicast_ip); + command.imr_multiaddr.s_addr = inet_addr(_multicast_ip); command.imr_interface.s_addr = htonl (INADDR_ANY); if (command.imr_multiaddr.s_addr == -1) { perror("Wrong multicast address!\n"); From bbb98af69c4aaae0917fcd360ccc3336c385cdb7 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 13:51:44 +0100 Subject: [PATCH 050/174] switch to broadcast --- files/dawn.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 9d93de5..cec4439 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,7 +1,7 @@ config settings network - option broadcast_ip '226.94.1.1' + 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 991b575fead47ea7128d25962c6153579b6e9656 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 16:39:39 +0100 Subject: [PATCH 051/174] add max chan utilization --- files/dawn.config | 4 +++- src/include/datastorage.h | 2 ++ src/storage/datastorage.c | 3 ++- src/utils/dawn_uci.c | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index cec4439..d233448 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -27,8 +27,10 @@ config settings metric option low_rssi '-500' option freq '100' option chan_util '50' - option max_chan_util '150' + option max_chan_util '-50' option rssi_val '-60' option low_rssi_val '-80' + option chan_util_val '70' + option max_chan_util_val '150' option min_probe_count '2' option bandwith_threshold '6' diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 979063c..c47e2a4 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -29,6 +29,8 @@ struct probe_metric_s { int max_chan_util; int rssi_val; int low_rssi_val; + int chan_util_val; + int max_chan_util_val; int min_probe_count; int bandwith_threshold; }; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index a7d8a65..9708e17 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -75,7 +75,8 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { score += !probe_entry.ht_support && !ap_entry.ht ? dawn_metric.no_ht_support : 0; score += probe_entry.vht_support && ap_entry.vht ? dawn_metric.vht_support : 0; score += !probe_entry.vht_support && !ap_entry.vht ? dawn_metric.no_vht_support : 0; - score += ap_entry.channel_utilization <= dawn_metric.max_chan_util ? dawn_metric.chan_util : 0; + score += ap_entry.channel_utilization <= dawn_metric.chan_util_val ? dawn_metric.chan_util : 0; + score += ap_entry.channel_utilization > dawn_metric.max_chan_util_val ? dawn_metric.max_chan_util : 0; } score += (probe_entry.freq > 5000) ? dawn_metric.freq : 0; diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index f694084..9ca9938 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -158,6 +158,23 @@ struct probe_metric_s uci_get_dawn_metric() { if (ptr.o->type == UCI_TYPE_STRING) ret.max_chan_util = atoi(ptr.o->v.string); + char tmp_chan_util_val[] = "dawn.metric.chan_util_val"; + if (uci_lookup_ptr(c, &ptr, tmp_chan_util_val, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.chan_util_val = atoi(ptr.o->v.string); + + + char tmp_max_chan_util_val[] = "dawn.metric.max_chan_util_val"; + if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util_val, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.max_chan_util_val = atoi(ptr.o->v.string); + printf("Try to load min_probe_count\n"); char tmp_min_probe_count[] = "dawn.metric.min_probe_count"; From 16e0e8d3b9744dcffa785e9391d0023801038343 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 19:11:26 +0100 Subject: [PATCH 052/174] increase chan utilization --- files/dawn.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index d233448..dc7ad5a 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -30,7 +30,7 @@ config settings metric option max_chan_util '-50' option rssi_val '-60' option low_rssi_val '-80' - option chan_util_val '70' - option max_chan_util_val '150' + option chan_util_val '140' + option max_chan_util_val '170' option min_probe_count '2' option bandwith_threshold '6' From 3f04c3efbf9ab0a5400c61dff7aad212b3990800 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 19:13:05 +0100 Subject: [PATCH 053/174] decrease timeout --- src/storage/datastorage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 9708e17..a80cccf 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -190,7 +190,7 @@ void kick_clients(uint8_t bssid[], uint32_t id) { } printf("Client is probably NOT in active transmisison. KICK! RxRate is: %f\n", rx_rate); - del_client_interface(id, client_array[j].client_addr, 5, 1, 60000); + del_client_interface(id, client_array[j].client_addr, 5, 1, 1000); client_array_delete(client_array[j]); // don't delete clients in a row. use update function again... From c7e4f58220afd91af32ae0c4fd1c0e6971bc3e10 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 19:39:28 +0100 Subject: [PATCH 054/174] increase update time --- files/dawn.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index dc7ad5a..1aadf29 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -12,7 +12,7 @@ config settings hostapd option hostapd_dir '/var/run/hostapd' config settings times - option update_client '10' + option update_client '50' option remove_client '120' option remove_probe '120' option remove_ap '460' From 9a38f825190c6881f31ac4feaa83da82053c28f5 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 22:05:29 +0100 Subject: [PATCH 055/174] fix multicast --- files/dawn.config | 4 ++-- src/main.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 1aadf29..817255c 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,7 +1,7 @@ config settings network - option broadcast_ip '10.0.0.255' + option broadcast_ip '225.0.0.37' option broadcast_port '1025' - option multicast '0' + option multicast '1' option shared_key 'Niiiiiiiiiiiiiik' option iv 'Niiiiiiiiiiiiiik' diff --git a/src/main.c b/src/main.c index e7a9a0a..bc24151 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) { char iv[BUFSIZE_DIR]; int multicast = 0; - while ((ch = getopt(argc, argv, "cs:p:i:b:o:h:i:k:v:")) != -1) { + while ((ch = getopt(argc, argv, "cs:p:i:b:o:h:i:k:v:m")) != -1) { switch (ch) { case 's': ubus_socket = optarg; @@ -94,6 +94,7 @@ int main(int argc, char **argv) { break; case 'm': multicast = 1; + break; default: break; } From 991d5ea5de07fbb7807805b4eb200a677cca361f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 12 Dec 2017 22:43:39 +0100 Subject: [PATCH 056/174] handle deauth --- src/utils/ubus.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 2d09677..15c961e 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -356,10 +356,17 @@ static int handle_probe_req(struct blob_attr *msg) { return 0; } +static int handle_deauth_req(struct blob_attr *msg) { + printf("RECEIVED DEAUTH REQUEST!\n"); + return 0; +} + static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - printf("METHOD new: %s\n", method); + char *str; + str = blobmsg_format_json(msg, true); + printf("METHOD new: %s : %s\n", method, str); // TODO: Only handle probe request and NOT assoc, ... @@ -370,6 +377,8 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, return handle_auth_req(msg); } else if (strncmp(method, "assoc", 5) == 0) { return handle_assoc_req(msg); + } else if (strncmp(method, "deauth", 6) == 0) { + return handle_deauth_req(msg); } return 0; } From 8edfad21b5fb917fdab4689ff9cc366c8235a45c Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 00:36:58 +0100 Subject: [PATCH 057/174] handle deauth --- src/include/datastorage.h | 5 ++++ src/include/ubus.h | 2 ++ src/utils/ubus.c | 49 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index c47e2a4..428782d 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -72,6 +72,11 @@ typedef struct auth_entry_s { uint32_t freq; } auth_entry; +typedef struct hostapd_notify_entry_s { + uint8_t bssid_addr[ETH_ALEN]; + uint8_t client_addr[ETH_ALEN]; +} hostapd_notify_entry; + typedef struct auth_entry_s assoc_entry; // ---------------- Defines ---------------- diff --git a/src/include/ubus.h b/src/include/ubus.h index 2f1d190..5537dde 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -18,6 +18,8 @@ int parse_to_assoc_req(struct blob_attr *msg, assoc_entry *assoc_req); int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id); +int parse_to_hostapd_notify(struct blob_attr *msg, hostapd_notify_entry *notify_req); + void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 15c961e..d3a63b4 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -35,6 +35,17 @@ struct uloop_timeout hostapd_timer = { uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS]; int hostapd_sock_last = -1; +enum { + HOSTAPD_NOTIFY_BSSID_ADDR, + HOSTAPD_NOTIFY_CLIENT_ADDR, + __HOSTAPD_NOTIFY_MAX, +}; + +static const struct blobmsg_policy hostapd_notify_policy[__HOSTAPD_NOTIFY_MAX] = { + [HOSTAPD_NOTIFY_BSSID_ADDR] = {.name = "bssid", .type = BLOBMSG_TYPE_STRING}, + [HOSTAPD_NOTIFY_CLIENT_ADDR] = {.name = "address", .type = BLOBMSG_TYPE_STRING}, +}; + enum { AUTH_BSSID_ADDR, AUTH_CLIENT_ADDR, @@ -231,6 +242,20 @@ static void hostapd_handle_remove(struct ubus_context *ctx, hostapd_array_delete(id); } +int parse_to_hostapd_notify(struct blob_attr *msg, hostapd_notify_entry *notify_req) { + struct blob_attr *tb[__HOSTAPD_NOTIFY_MAX]; + + blobmsg_parse(hostapd_notify_policy, __HOSTAPD_NOTIFY_MAX, tb, blob_data(msg), blob_len(msg)); + + if (hwaddr_aton(blobmsg_data(tb[HOSTAPD_NOTIFY_BSSID_ADDR]), notify_req->bssid_addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[HOSTAPD_NOTIFY_CLIENT_ADDR]), notify_req->client_addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + return 0; +} + int parse_to_auth_req(struct blob_attr *msg, auth_entry *auth_req) { struct blob_attr *tb[__AUTH_MAX]; @@ -357,7 +382,29 @@ static int handle_probe_req(struct blob_attr *msg) { } static int handle_deauth_req(struct blob_attr *msg) { - printf("RECEIVED DEAUTH REQUEST!\n"); + + hostapd_notify_entry notify_req; + parse_to_hostapd_notify(msg, ¬ify_req); + + client client_entry; + memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.client_addr, client_entry.client_addr, sizeof(uint8_t) * ETH_ALEN ); + + pthread_mutex_lock(&client_array_mutex); + client_array_delete(client_entry); + pthread_mutex_unlock(&client_array_mutex); + + blob_buf_init(&b, 0); + blobmsg_add_blob(&b, msg); + blobmsg_add_string(&b, "test", "test_attr"); + + + char *str; + str = blobmsg_format_json(b.head, true); + send_string_enc(str); + + printf("[WC] Hostapd-Probe: %s : %s\n", "deauth", str); + return 0; } From 59999d7b0f0c9c4ca7775c6121d83dc020740580 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 01:41:36 +0100 Subject: [PATCH 058/174] add new network json msg, fix a lot of memory leaks, etc. ... --- src/include/ubus.h | 4 + src/network/networksocket.c | 31 +------- src/utils/ubus.c | 152 +++++++++++++++++++++++++++++++++--- 3 files changed, 144 insertions(+), 43 deletions(-) diff --git a/src/include/ubus.h b/src/include/ubus.h index 5537dde..1fdb59d 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -36,4 +36,8 @@ void update_hostapd_sockets(struct uloop_timeout *t); void add_client_update_timer(time_t time); +int handle_network_msg(char* msg); + +int send_blob_attr_via_network(struct blob_attr *msg, char* method); + #endif diff --git a/src/network/networksocket.c b/src/network/networksocket.c index ed33e02..ecacc4f 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -148,37 +148,8 @@ void *receive_msg_enc(void *args) { char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length); - //printf("Free %s: %p\n","base64_dec_str", base64_dec_str); free(base64_dec_str); - - //printf("[WC] Network-Received: %s\n", dec); - - probe_entry prob_req; - struct blob_buf b; - - blob_buf_init(&b, 0); - blobmsg_add_json_from_string(&b, dec); - - char *str; - str = blobmsg_format_json(b.head, true); - - if (str == NULL) { - return 0; - } - - if (strlen(str) <= 0) { - return 0; - } - - if (strstr(str, "clients") != NULL) { - parse_to_clients(b.head, 0, 0); - } else if (strstr(str, "target") != NULL) { - if (parse_to_probe_req(b.head, &prob_req) == 0) { - insert_to_array(prob_req, 0); - } - } - // free encrypted string - //printf("Free %s: %p\n","dec", dec); + handle_network_msg(dec); free(dec); } } diff --git a/src/utils/ubus.c b/src/utils/ubus.c index d3a63b4..9a0f6e1 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -35,6 +35,17 @@ struct uloop_timeout hostapd_timer = { uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS]; int hostapd_sock_last = -1; +enum { + NETWORK_METHOD, + NETWORK_DATA, + __NETWORK_MAX, +}; + +static const struct blobmsg_policy network_policy[__NETWORK_MAX] = { + [NETWORK_METHOD] = {.name = "method", .type = BLOBMSG_TYPE_STRING}, + [NETWORK_DATA] = {.name = "data", .type = BLOBMSG_TYPE_STRING}, +}; + enum { HOSTAPD_NOTIFY_BSSID_ADDR, HOSTAPD_NOTIFY_CLIENT_ADDR, @@ -362,13 +373,15 @@ static int handle_probe_req(struct blob_attr *msg) { //probe_entry tmp_probe = insert_to_array(prob_req, 1); + send_blob_attr_via_network(msg, "probe"); // send probe via network - char *str; + /*char *str; str = blobmsg_format_json(msg, true); send_string_enc(str); - printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str); + printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str);*/ + //print_probe_array(); /* @@ -394,17 +407,108 @@ static int handle_deauth_req(struct blob_attr *msg) { client_array_delete(client_entry); pthread_mutex_unlock(&client_array_mutex); + printf("[WC] Deauth: %s\n", "deauth"); + + return 0; +} + +int handle_network_msg(char* msg) +{ + printf("HANDLING NETWORK MSG!\n"); + struct blob_attr *tb[__NETWORK_MAX]; + char *method; + char *data; + + printf("TO JSON NETWORK MSG!\n"); blob_buf_init(&b, 0); - blobmsg_add_blob(&b, msg); - blobmsg_add_string(&b, "test", "test_attr"); + blobmsg_add_json_from_string(&b, msg); + + printf("PARSING NETWORK MSG!\n"); + blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(b.head), blob_len(b.head)); + printf("PARSING FINISHED NETWORK MSG!\n"); + + if(!tb[NETWORK_METHOD] ||!tb[NETWORK_DATA] ) + { + return -1; + } + printf("GET STRING NETWORK MSG!\n"); + method = blobmsg_get_string(tb[NETWORK_METHOD]); + data = blobmsg_get_string(tb[NETWORK_DATA]); + printf("GET STRING FINISHED NETWORK MSG!\n"); + + blob_buf_init(&b, 0); + blobmsg_add_json_from_string(&b, data); + printf("JSON PARSING AGAIN FINISHED NETWORK MSG!\n"); + + printf("DO STRINGCOMPARE: %s : %s!\n", method, data); + if(!blob_len(b.head)) + { + printf("NULL?!\n"); + return -1; + } + + if(blob_len(b.head) <= 0) + { + printf("NULL?!\n"); + return -1; + } + + if(strlen(method) < 5) + { + printf("STRING IS LESS THAN 5!\n"); + return -1; + } + + if (strncmp(method, "probe", 5) == 0) { + probe_entry entry; + parse_to_probe_req(b.head, &entry); + probe_array_insert(entry); + } else if (strncmp(method, "clients", 5) == 0) { + printf("PARSING CLIENTS NETWORK MSG!\n"); + parse_to_clients(b.head, 0, 0); + } else if (strncmp(method, "deauth", 5) == 0) { + hostapd_notify_entry entry; + parse_to_hostapd_notify(b.head, &entry); + + client client_entry; + memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.client_addr, client_entry.client_addr, sizeof(uint8_t) * ETH_ALEN ); + + pthread_mutex_lock(&client_array_mutex); + client_array_delete(client_entry); + pthread_mutex_unlock(&client_array_mutex); + } + free(method); + free(data); + printf("HANDLING FINISHED NETWORK MSG!\n"); + return 0; +} +int send_blob_attr_via_network(struct blob_attr *msg, char* method) +{ + char *data_str; char *str; + printf("TO JSON\n"); + data_str = blobmsg_format_json(msg, true); + printf("JSON FINISHED\n"); + + printf("ADD STRINGS!\n"); + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "method", method); + blobmsg_add_string(&b, "data", data_str); + printf("ADD FINISHED!\n"); + + + //blobmsg_add_blob(&b, msg); + printf("TO JSON AGAIN\n"); str = blobmsg_format_json(b.head, true); + printf("TO JSON AGAIN FINISHED\n"); + printf("SENDING\n"); send_string_enc(str); - - printf("[WC] Hostapd-Probe: %s : %s\n", "deauth", str); - + printf("SENDING FINISHED!\n"); + free(str); + free(data_str); return 0; } @@ -414,6 +518,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, char *str; str = blobmsg_format_json(msg, true); printf("METHOD new: %s : %s\n", method, str); + free(str); // TODO: Only handle probe request and NOT assoc, ... @@ -617,6 +722,24 @@ dump_client_table(struct blob_attr *head, int len, const char *bssid_addr, uint3 int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) { struct blob_attr *tb[__CLIENT_TABLE_MAX]; + if(!msg) + { + return -1; + } + + if(!blob_data(msg)) + { + printf("DATA IS NULL!!!\n"); + return -1; + } + + printf("BLOB LEN: %d\n", blob_len(msg)); + if(blob_len(msg) <= 0) + { + printf("DATA IS NULL!!!\n"); + return -1; + } + blobmsg_parse(client_table_policy, __CLIENT_TABLE_MAX, tb, blob_data(msg), blob_len(msg)); if (tb[CLIENT_TABLE] && tb[CLIENT_TABLE_BSSID] && tb[CLIENT_TABLE_FREQ] && tb[CLIENT_TABLE_HT] && @@ -644,10 +767,14 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ if (!msg) return; + printf("PARSE TO CLIENTS!\n"); parse_to_clients(msg, 1, req->peer); - char *str = blobmsg_format_json(msg, true); - send_string_enc(str); + printf("SENDING CLIENTS VIA NETWORK\n"); + send_blob_attr_via_network(msg, "clients"); + printf("SEND CLIENTS FINISHED!\n"); + + print_client_array(); print_ap_array(); } @@ -730,6 +857,8 @@ int ubus_call_umdns() { int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { + printf("SENDING PROBE VIA NETWORK!\n"); + static struct blob_buf b; blob_buf_init(&b, 0); @@ -741,10 +870,7 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { blobmsg_add_u8(&b, "ht_support", probe_entry.ht_support); blobmsg_add_u8(&b, "vht_support", probe_entry.vht_support); - // send probe via network - char *str; - str = blobmsg_format_json(b.head, 1); - send_string_enc(str); + send_blob_attr_via_network(b.head, "probe"); return 0; } \ No newline at end of file From 93265f967bc6fd383fab7cc97f9c6676b7769929 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 09:51:50 +0100 Subject: [PATCH 059/174] add prints --- src/network/networksocket.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/network/networksocket.c b/src/network/networksocket.c index ecacc4f..3f5962f 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -146,8 +146,11 @@ void *receive_msg_enc(void *args) { char *base64_dec_str = malloc(Base64decode_len(recv_string)); int base64_dec_length = Base64decode(base64_dec_str, recv_string); + char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length); + printf("NETRWORK RECEIVED: %s\n", dec); + free(base64_dec_str); handle_network_msg(dec); free(dec); @@ -182,6 +185,10 @@ int send_string(char *msg) { int send_string_enc(char *msg) { pthread_mutex_lock(&send_mutex); + + printf("Sending string: %s\n", msg); + + size_t msglen = strlen(msg); int length_enc; From 37257bbd84fdc8c438ccabda7101fd1c1ab4a32c Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 09:57:59 +0100 Subject: [PATCH 060/174] add prints --- src/utils/ubus.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 9a0f6e1..facce06 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -432,8 +432,13 @@ int handle_network_msg(char* msg) return -1; } printf("GET STRING NETWORK MSG!\n"); - method = blobmsg_get_string(tb[NETWORK_METHOD]); - data = blobmsg_get_string(tb[NETWORK_DATA]); + //method = blobmsg_get_string(tb[NETWORK_METHOD]); + //data = blobmsg_get_string(tb[NETWORK_DATA]); + + method = blobmsg_data(tb[NETWORK_METHOD]); + data = blobmsg_data(tb[NETWORK_DATA]); + + printf("GET STRING FINISHED NETWORK MSG!\n"); blob_buf_init(&b, 0); From c332b2555c81b6763e7758f93a026fc102cde2b8 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:06:05 +0100 Subject: [PATCH 061/174] add prints --- src/utils/ubus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index facce06..40788a9 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -423,6 +423,8 @@ int handle_network_msg(char* msg) blob_buf_init(&b, 0); blobmsg_add_json_from_string(&b, msg); + printf("TO JSON AGAIN PARSING: %s\n",blobmsg_format_json(b.head, true)); + printf("PARSING NETWORK MSG!\n"); blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(b.head), blob_len(b.head)); printf("PARSING FINISHED NETWORK MSG!\n"); From 9f78b5b879f53e8f8947daefc6a2ee0ca359db47 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:10:28 +0100 Subject: [PATCH 062/174] add prints --- src/utils/ubus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 40788a9..ca69ddc 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -440,6 +440,8 @@ int handle_network_msg(char* msg) method = blobmsg_data(tb[NETWORK_METHOD]); data = blobmsg_data(tb[NETWORK_DATA]); + printf("METHOD! : %s\n", method); + printf("GET STRING FINISHED NETWORK MSG!\n"); From d99f3aed52906b56d41bcb18b3312d51f446c9de Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:12:12 +0100 Subject: [PATCH 063/174] add prints --- src/utils/ubus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index ca69ddc..4b8ecae 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -441,6 +441,7 @@ int handle_network_msg(char* msg) data = blobmsg_data(tb[NETWORK_DATA]); printf("METHOD! : %s\n", method); + printf("DATA: %s\n", data); printf("GET STRING FINISHED NETWORK MSG!\n"); From 1132e7f66d00040474eb48cae30daef4db08697f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:15:13 +0100 Subject: [PATCH 064/174] add data buff --- src/utils/ubus.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 4b8ecae..4bb9092 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -446,18 +446,19 @@ int handle_network_msg(char* msg) printf("GET STRING FINISHED NETWORK MSG!\n"); - blob_buf_init(&b, 0); - blobmsg_add_json_from_string(&b, data); + static struct blob_buf data_buf; + blob_buf_init(&data_buf, 0); + blobmsg_add_json_from_string(&data_buf, data); printf("JSON PARSING AGAIN FINISHED NETWORK MSG!\n"); printf("DO STRINGCOMPARE: %s : %s!\n", method, data); - if(!blob_len(b.head)) + if(!blob_len(data_buf.head)) { printf("NULL?!\n"); return -1; } - if(blob_len(b.head) <= 0) + if(blob_len(data_buf.head) <= 0) { printf("NULL?!\n"); return -1; @@ -471,14 +472,14 @@ int handle_network_msg(char* msg) if (strncmp(method, "probe", 5) == 0) { probe_entry entry; - parse_to_probe_req(b.head, &entry); + parse_to_probe_req(data_buf.head, &entry); probe_array_insert(entry); } else if (strncmp(method, "clients", 5) == 0) { printf("PARSING CLIENTS NETWORK MSG!\n"); - parse_to_clients(b.head, 0, 0); + parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { hostapd_notify_entry entry; - parse_to_hostapd_notify(b.head, &entry); + parse_to_hostapd_notify(data_buf.head, &entry); client client_entry; memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); From 7ac7f034540817d53ad8987e71c193a9982133a9 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:18:03 +0100 Subject: [PATCH 065/174] add network buff --- src/utils/ubus.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 4bb9092..f8eb323 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -414,19 +414,21 @@ static int handle_deauth_req(struct blob_attr *msg) { int handle_network_msg(char* msg) { + static struct blob_buf network_buf; + static struct blob_buf data_buf; printf("HANDLING NETWORK MSG!\n"); struct blob_attr *tb[__NETWORK_MAX]; char *method; char *data; printf("TO JSON NETWORK MSG!\n"); - blob_buf_init(&b, 0); - blobmsg_add_json_from_string(&b, msg); + blob_buf_init(&network_buf, 0); + blobmsg_add_json_from_string(&network_buf, msg); - printf("TO JSON AGAIN PARSING: %s\n",blobmsg_format_json(b.head, true)); + printf("TO JSON AGAIN PARSING: %s\n",blobmsg_format_json(network_buf.head, true)); printf("PARSING NETWORK MSG!\n"); - blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(b.head), blob_len(b.head)); + blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(network_buf.head), blob_len(network_buf.head)); printf("PARSING FINISHED NETWORK MSG!\n"); if(!tb[NETWORK_METHOD] ||!tb[NETWORK_DATA] ) @@ -446,7 +448,6 @@ int handle_network_msg(char* msg) printf("GET STRING FINISHED NETWORK MSG!\n"); - static struct blob_buf data_buf; blob_buf_init(&data_buf, 0); blobmsg_add_json_from_string(&data_buf, data); printf("JSON PARSING AGAIN FINISHED NETWORK MSG!\n"); From ae8d2166ac7981db3657c024573287430257b110 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:21:56 +0100 Subject: [PATCH 066/174] add network buff --- src/utils/ubus.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index f8eb323..ef0e3a6 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -22,6 +22,8 @@ static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange be static struct ubus_subscriber hostapd_event; static struct blob_buf b; + + void update_clients(struct uloop_timeout *t); struct uloop_timeout client_timer = { @@ -416,6 +418,7 @@ int handle_network_msg(char* msg) { static struct blob_buf network_buf; static struct blob_buf data_buf; + printf("HANDLING NETWORK MSG!\n"); struct blob_attr *tb[__NETWORK_MAX]; char *method; From 4ca5c91eb91ce4b1236abd86e83bca7ca62fd2b9 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:29:55 +0100 Subject: [PATCH 067/174] add send buffer --- src/utils/ubus.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index ef0e3a6..b7f0cf3 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -502,6 +502,7 @@ int handle_network_msg(char* msg) int send_blob_attr_via_network(struct blob_attr *msg, char* method) { + struct blob_buf b_send_network; char *data_str; char *str; printf("TO JSON\n"); @@ -509,15 +510,15 @@ int send_blob_attr_via_network(struct blob_attr *msg, char* method) printf("JSON FINISHED\n"); printf("ADD STRINGS!\n"); - blob_buf_init(&b, 0); - blobmsg_add_string(&b, "method", method); - blobmsg_add_string(&b, "data", data_str); + blob_buf_init(&b_send_network, 0); + blobmsg_add_string(&b_send_network, "method", method); + blobmsg_add_string(&b_send_network, "data", data_str); printf("ADD FINISHED!\n"); //blobmsg_add_blob(&b, msg); printf("TO JSON AGAIN\n"); - str = blobmsg_format_json(b.head, true); + str = blobmsg_format_json(b_send_network.head, true); printf("TO JSON AGAIN FINISHED\n"); printf("SENDING\n"); send_string_enc(str); From f5ed5db2dfa857fb8726a4f9c3b6ab5b36921a8f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:33:57 +0100 Subject: [PATCH 068/174] return in functions --- src/network/networksocket.c | 2 ++ src/utils/ubus.c | 1 + 2 files changed, 3 insertions(+) diff --git a/src/network/networksocket.c b/src/network/networksocket.c index 3f5962f..ac379d3 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -134,6 +134,8 @@ void *receive_msg_enc(void *args) { continue; } + return 0; + if (recv_string == NULL) { return 0; } diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b7f0cf3..f396437 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -502,6 +502,7 @@ int handle_network_msg(char* msg) int send_blob_attr_via_network(struct blob_attr *msg, char* method) { + return 0; struct blob_buf b_send_network; char *data_str; char *str; From f55756c9e8f905550651c0f45f0fd83282505a51 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:35:26 +0100 Subject: [PATCH 069/174] return in functions --- src/utils/ubus.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index f396437..b7f0cf3 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -502,7 +502,6 @@ int handle_network_msg(char* msg) int send_blob_attr_via_network(struct blob_attr *msg, char* method) { - return 0; struct blob_buf b_send_network; char *data_str; char *str; From 261a6807637771cbbe51faa124f0c5e4bf364341 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:37:16 +0100 Subject: [PATCH 070/174] return in functions --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b7f0cf3..67351a5 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -886,7 +886,7 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { blobmsg_add_u8(&b, "ht_support", probe_entry.ht_support); blobmsg_add_u8(&b, "vht_support", probe_entry.vht_support); - send_blob_attr_via_network(b.head, "probe"); + //send_blob_attr_via_network(b.head, "probe"); return 0; } \ No newline at end of file From eba090c1fbeed19a2944a4e3d790757ac8abff06 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:40:33 +0100 Subject: [PATCH 071/174] return in functions --- src/utils/ubus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 67351a5..41788c0 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -787,7 +787,7 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ parse_to_clients(msg, 1, req->peer); printf("SENDING CLIENTS VIA NETWORK\n"); - send_blob_attr_via_network(msg, "clients"); + //send_blob_attr_via_network(msg, "clients"); printf("SEND CLIENTS FINISHED!\n"); @@ -886,7 +886,7 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { blobmsg_add_u8(&b, "ht_support", probe_entry.ht_support); blobmsg_add_u8(&b, "vht_support", probe_entry.vht_support); - //send_blob_attr_via_network(b.head, "probe"); + send_blob_attr_via_network(b.head, "probe"); return 0; } \ No newline at end of file From e4a29767c323f403c07309b302cc4bf00c5b1680 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:41:30 +0100 Subject: [PATCH 072/174] return in functions --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 41788c0..a7bc18a 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -375,7 +375,7 @@ static int handle_probe_req(struct blob_attr *msg) { //probe_entry tmp_probe = insert_to_array(prob_req, 1); - send_blob_attr_via_network(msg, "probe"); + //send_blob_attr_via_network(msg, "probe"); // send probe via network /*char *str; From 579d97c57b3cc65850854686fc39b6363c91bb9b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:44:06 +0100 Subject: [PATCH 073/174] return in functions --- src/utils/ubus.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a7bc18a..62ecee8 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -375,7 +375,7 @@ static int handle_probe_req(struct blob_attr *msg) { //probe_entry tmp_probe = insert_to_array(prob_req, 1); - //send_blob_attr_via_network(msg, "probe"); + send_blob_attr_via_network(msg, "probe"); // send probe via network /*char *str; @@ -502,11 +502,17 @@ int handle_network_msg(char* msg) int send_blob_attr_via_network(struct blob_attr *msg, char* method) { + if(!msg) + { + return; + } + struct blob_buf b_send_network; char *data_str; char *str; printf("TO JSON\n"); data_str = blobmsg_format_json(msg, true); + printf("DATA STRING: %s", data_str); printf("JSON FINISHED\n"); printf("ADD STRINGS!\n"); From 0890c6de93a675ab2ce058c097d713ebd63d93cc Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:44:52 +0100 Subject: [PATCH 074/174] return in functions --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 62ecee8..3054473 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -504,7 +504,7 @@ int send_blob_attr_via_network(struct blob_attr *msg, char* method) { if(!msg) { - return; + return -1; } struct blob_buf b_send_network; From 8aa4b116ba295fc88163c894726ca309347f35b5 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:48:04 +0100 Subject: [PATCH 075/174] return in functions --- src/utils/ubus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 3054473..b338d20 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -512,7 +512,7 @@ int send_blob_attr_via_network(struct blob_attr *msg, char* method) char *str; printf("TO JSON\n"); data_str = blobmsg_format_json(msg, true); - printf("DATA STRING: %s", data_str); + printf("DATA STRING: %s\n", data_str); printf("JSON FINISHED\n"); printf("ADD STRINGS!\n"); @@ -529,8 +529,8 @@ int send_blob_attr_via_network(struct blob_attr *msg, char* method) printf("SENDING\n"); send_string_enc(str); printf("SENDING FINISHED!\n"); - free(str); - free(data_str); + //free(str); + //free(data_str); return 0; } From b52b77b833ab2ca2fdf29ce51f5d55f71675f7a9 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:50:01 +0100 Subject: [PATCH 076/174] return in functions --- src/utils/ubus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b338d20..b08a5d3 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -21,6 +21,8 @@ static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange be static struct ubus_subscriber hostapd_event; static struct blob_buf b; +static struct blob_buf b_send_network; + @@ -507,7 +509,6 @@ int send_blob_attr_via_network(struct blob_attr *msg, char* method) return -1; } - struct blob_buf b_send_network; char *data_str; char *str; printf("TO JSON\n"); From af75da8046945306a2c3622bbe750dd3fadf3b9b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:52:57 +0100 Subject: [PATCH 077/174] return in functions --- src/network/networksocket.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/network/networksocket.c b/src/network/networksocket.c index ac379d3..3f5962f 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -134,8 +134,6 @@ void *receive_msg_enc(void *args) { continue; } - return 0; - if (recv_string == NULL) { return 0; } From cafc7419719aa546258672ff1dfa91f23876cbd6 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:54:55 +0100 Subject: [PATCH 078/174] return in functions --- src/utils/ubus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b08a5d3..55f6179 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -22,6 +22,8 @@ static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange be static struct ubus_subscriber hostapd_event; static struct blob_buf b; static struct blob_buf b_send_network; +static struct blob_buf network_buf; +static struct blob_buf data_buf; @@ -418,8 +420,7 @@ static int handle_deauth_req(struct blob_attr *msg) { int handle_network_msg(char* msg) { - static struct blob_buf network_buf; - static struct blob_buf data_buf; + printf("HANDLING NETWORK MSG!\n"); struct blob_attr *tb[__NETWORK_MAX]; From 174b2a97cddfc726db8aa967c958c7ba224c5192 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:57:01 +0100 Subject: [PATCH 079/174] return in functions --- src/utils/ubus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 55f6179..87c9c42 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -882,6 +882,7 @@ int ubus_call_umdns() { int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { printf("SENDING PROBE VIA NETWORK!\n"); + return 0; static struct blob_buf b; From b9ac6227cade96eeb249e0026bb4840ef6503e84 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 10:58:34 +0100 Subject: [PATCH 080/174] return in functions --- src/utils/ubus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 87c9c42..d671820 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -379,7 +379,7 @@ static int handle_probe_req(struct blob_attr *msg) { //probe_entry tmp_probe = insert_to_array(prob_req, 1); - send_blob_attr_via_network(msg, "probe"); + //send_blob_attr_via_network(msg, "probe"); // send probe via network /*char *str; @@ -795,7 +795,7 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ parse_to_clients(msg, 1, req->peer); printf("SENDING CLIENTS VIA NETWORK\n"); - //send_blob_attr_via_network(msg, "clients"); + send_blob_attr_via_network(msg, "clients"); printf("SEND CLIENTS FINISHED!\n"); From dd9ccf3eb45733e1f181c07d3ae252ad3e65d8a5 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:00:28 +0100 Subject: [PATCH 081/174] return in functions --- src/network/networksocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/networksocket.c b/src/network/networksocket.c index 3f5962f..f419afc 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -152,7 +152,7 @@ void *receive_msg_enc(void *args) { printf("NETRWORK RECEIVED: %s\n", dec); free(base64_dec_str); - handle_network_msg(dec); + //handle_network_msg(dec); free(dec); } } From b17e4f4786ce74e35a67d35033362b01b00d53a1 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:02:35 +0100 Subject: [PATCH 082/174] return in functions --- src/network/networksocket.c | 2 +- src/utils/ubus.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/network/networksocket.c b/src/network/networksocket.c index f419afc..3f5962f 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -152,7 +152,7 @@ void *receive_msg_enc(void *args) { printf("NETRWORK RECEIVED: %s\n", dec); free(base64_dec_str); - //handle_network_msg(dec); + handle_network_msg(dec); free(dec); } } diff --git a/src/utils/ubus.c b/src/utils/ubus.c index d671820..3b30557 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -420,8 +420,6 @@ static int handle_deauth_req(struct blob_attr *msg) { int handle_network_msg(char* msg) { - - printf("HANDLING NETWORK MSG!\n"); struct blob_attr *tb[__NETWORK_MAX]; char *method; @@ -431,6 +429,8 @@ int handle_network_msg(char* msg) blob_buf_init(&network_buf, 0); blobmsg_add_json_from_string(&network_buf, msg); + return -1; + printf("TO JSON AGAIN PARSING: %s\n",blobmsg_format_json(network_buf.head, true)); printf("PARSING NETWORK MSG!\n"); From 2445e61a3fe15cb9aa82ce7754c76625055a059d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:05:03 +0100 Subject: [PATCH 083/174] return in functions --- src/utils/ubus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 3b30557..5ed4e09 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -429,14 +429,15 @@ int handle_network_msg(char* msg) blob_buf_init(&network_buf, 0); blobmsg_add_json_from_string(&network_buf, msg); - return -1; - printf("TO JSON AGAIN PARSING: %s\n",blobmsg_format_json(network_buf.head, true)); printf("PARSING NETWORK MSG!\n"); blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(network_buf.head), blob_len(network_buf.head)); printf("PARSING FINISHED NETWORK MSG!\n"); + return -1; + + if(!tb[NETWORK_METHOD] ||!tb[NETWORK_DATA] ) { return -1; From a7899bf787a106b43ec2966424e4c647a52e1e66 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:06:26 +0100 Subject: [PATCH 084/174] return in functions --- src/utils/ubus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 5ed4e09..a2f96a6 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -429,13 +429,13 @@ int handle_network_msg(char* msg) blob_buf_init(&network_buf, 0); blobmsg_add_json_from_string(&network_buf, msg); + printf("TO JSON AGAIN PARSING: %s\n",blobmsg_format_json(network_buf.head, true)); printf("PARSING NETWORK MSG!\n"); blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(network_buf.head), blob_len(network_buf.head)); printf("PARSING FINISHED NETWORK MSG!\n"); - return -1; if(!tb[NETWORK_METHOD] ||!tb[NETWORK_DATA] ) @@ -452,6 +452,8 @@ int handle_network_msg(char* msg) printf("METHOD! : %s\n", method); printf("DATA: %s\n", data); + return -1; + printf("GET STRING FINISHED NETWORK MSG!\n"); From de027cadf16f2a3c58aa8bfd1c41749d2613aeeb Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:07:27 +0100 Subject: [PATCH 085/174] return in functions --- src/utils/ubus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a2f96a6..e1b2a57 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -452,7 +452,6 @@ int handle_network_msg(char* msg) printf("METHOD! : %s\n", method); printf("DATA: %s\n", data); - return -1; printf("GET STRING FINISHED NETWORK MSG!\n"); @@ -461,6 +460,9 @@ int handle_network_msg(char* msg) blobmsg_add_json_from_string(&data_buf, data); printf("JSON PARSING AGAIN FINISHED NETWORK MSG!\n"); + return -1; + + printf("DO STRINGCOMPARE: %s : %s!\n", method, data); if(!blob_len(data_buf.head)) { From 732bbb84b18175ec01841befe9ee1d4c504e2f31 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:10:00 +0100 Subject: [PATCH 086/174] return in functions --- src/utils/ubus.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index e1b2a57..6d1bc7f 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -460,11 +460,9 @@ int handle_network_msg(char* msg) blobmsg_add_json_from_string(&data_buf, data); printf("JSON PARSING AGAIN FINISHED NETWORK MSG!\n"); - return -1; - printf("DO STRINGCOMPARE: %s : %s!\n", method, data); - if(!blob_len(data_buf.head)) + if(!data_buf.head) { printf("NULL?!\n"); return -1; From 4319a89c0fb95496fcf7454197c7d6d84595608f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:12:26 +0100 Subject: [PATCH 087/174] return in functions --- src/utils/ubus.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 6d1bc7f..4c2f638 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -481,13 +481,16 @@ int handle_network_msg(char* msg) } if (strncmp(method, "probe", 5) == 0) { + printf("METHOD PROBE\n"); probe_entry entry; parse_to_probe_req(data_buf.head, &entry); probe_array_insert(entry); } else if (strncmp(method, "clients", 5) == 0) { + printf("METHOD CLIENTS\n"); printf("PARSING CLIENTS NETWORK MSG!\n"); parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { + printf("METHOD DEAUTH\n"); hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); From 13f87a79c05a392cf21e56d60ab4b0851de2f5cb Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:14:21 +0100 Subject: [PATCH 088/174] return in functions --- src/utils/ubus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 4c2f638..25df27e 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -480,6 +480,8 @@ int handle_network_msg(char* msg) return -1; } + return -1; + if (strncmp(method, "probe", 5) == 0) { printf("METHOD PROBE\n"); probe_entry entry; From 6b3a955cfeb7d6058325ed099a3f516f3d1d407f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:17:10 +0100 Subject: [PATCH 089/174] return in functions --- src/utils/ubus.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 25df27e..408406f 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -480,8 +480,6 @@ int handle_network_msg(char* msg) return -1; } - return -1; - if (strncmp(method, "probe", 5) == 0) { printf("METHOD PROBE\n"); probe_entry entry; @@ -493,7 +491,7 @@ int handle_network_msg(char* msg) parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); - hostapd_notify_entry entry; + /*hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); client client_entry; @@ -502,7 +500,7 @@ int handle_network_msg(char* msg) pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); - pthread_mutex_unlock(&client_array_mutex); + pthread_mutex_unlock(&client_array_mutex);*/ } free(method); free(data); From 1ba2a52edeaa250ec9cd8cea970592647d642081 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:19:23 +0100 Subject: [PATCH 090/174] return in functions --- src/utils/ubus.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 408406f..cfb1c94 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -483,15 +483,15 @@ int handle_network_msg(char* msg) if (strncmp(method, "probe", 5) == 0) { printf("METHOD PROBE\n"); probe_entry entry; - parse_to_probe_req(data_buf.head, &entry); - probe_array_insert(entry); + //parse_to_probe_req(data_buf.head, &entry); + //probe_array_insert(entry); } else if (strncmp(method, "clients", 5) == 0) { printf("METHOD CLIENTS\n"); printf("PARSING CLIENTS NETWORK MSG!\n"); - parse_to_clients(data_buf.head, 0, 0); + //parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); - /*hostapd_notify_entry entry; + hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); client client_entry; @@ -500,7 +500,7 @@ int handle_network_msg(char* msg) pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); - pthread_mutex_unlock(&client_array_mutex);*/ + pthread_mutex_unlock(&client_array_mutex); } free(method); free(data); From 75d4e402a7bfd2c01b757cdffdc8c118f6f8a2be Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:20:11 +0100 Subject: [PATCH 091/174] return in functions --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index cfb1c94..be40997 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -482,7 +482,7 @@ int handle_network_msg(char* msg) if (strncmp(method, "probe", 5) == 0) { printf("METHOD PROBE\n"); - probe_entry entry; + //probe_entry entry; //parse_to_probe_req(data_buf.head, &entry); //probe_array_insert(entry); } else if (strncmp(method, "clients", 5) == 0) { From 30a54086f6d9c9dd9e2b1435605a2f370981eca9 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:21:31 +0100 Subject: [PATCH 092/174] return in functions --- src/utils/ubus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index be40997..f89b925 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -491,7 +491,7 @@ int handle_network_msg(char* msg) //parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); - hostapd_notify_entry entry; + /*hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); client client_entry; @@ -500,10 +500,10 @@ int handle_network_msg(char* msg) pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); - pthread_mutex_unlock(&client_array_mutex); + pthread_mutex_unlock(&client_array_mutex);*/ } - free(method); - free(data); + //free(method); + //free(data); printf("HANDLING FINISHED NETWORK MSG!\n"); return 0; } From 51fc50def7335c0d0ac189bc3872916fc0c7c123 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:23:14 +0100 Subject: [PATCH 093/174] return in functions --- src/utils/ubus.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index f89b925..74926a7 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -482,16 +482,16 @@ int handle_network_msg(char* msg) if (strncmp(method, "probe", 5) == 0) { printf("METHOD PROBE\n"); - //probe_entry entry; - //parse_to_probe_req(data_buf.head, &entry); - //probe_array_insert(entry); + probe_entry entry; + parse_to_probe_req(data_buf.head, &entry); + probe_array_insert(entry); } else if (strncmp(method, "clients", 5) == 0) { printf("METHOD CLIENTS\n"); printf("PARSING CLIENTS NETWORK MSG!\n"); - //parse_to_clients(data_buf.head, 0, 0); + parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); - /*hostapd_notify_entry entry; + hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); client client_entry; @@ -500,7 +500,7 @@ int handle_network_msg(char* msg) pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); - pthread_mutex_unlock(&client_array_mutex);*/ + pthread_mutex_unlock(&client_array_mutex); } //free(method); //free(data); From 6d371a451490230fdc5500f193012e5373ba8c49 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 11:35:12 +0100 Subject: [PATCH 094/174] return in functions --- src/utils/ubus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 74926a7..843ce93 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -379,7 +379,7 @@ static int handle_probe_req(struct blob_attr *msg) { //probe_entry tmp_probe = insert_to_array(prob_req, 1); - //send_blob_attr_via_network(msg, "probe"); + send_blob_attr_via_network(msg, "probe"); // send probe via network /*char *str; @@ -888,7 +888,6 @@ int ubus_call_umdns() { int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { printf("SENDING PROBE VIA NETWORK!\n"); - return 0; static struct blob_buf b; From 010445c4eefe59af054f0e2d7ce618ef576ab607 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 12:09:48 +0100 Subject: [PATCH 095/174] try fix probe request --- src/utils/ubus.c | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 843ce93..04cbc78 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -420,45 +420,28 @@ static int handle_deauth_req(struct blob_attr *msg) { int handle_network_msg(char* msg) { - printf("HANDLING NETWORK MSG!\n"); + printf("HANDLING NETWORK MSG: %s\n"); struct blob_attr *tb[__NETWORK_MAX]; char *method; char *data; - printf("TO JSON NETWORK MSG!\n"); blob_buf_init(&network_buf, 0); blobmsg_add_json_from_string(&network_buf, msg); - - printf("TO JSON AGAIN PARSING: %s\n",blobmsg_format_json(network_buf.head, true)); - - printf("PARSING NETWORK MSG!\n"); blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(network_buf.head), blob_len(network_buf.head)); - printf("PARSING FINISHED NETWORK MSG!\n"); - - if(!tb[NETWORK_METHOD] ||!tb[NETWORK_DATA] ) { return -1; } - printf("GET STRING NETWORK MSG!\n"); //method = blobmsg_get_string(tb[NETWORK_METHOD]); //data = blobmsg_get_string(tb[NETWORK_DATA]); method = blobmsg_data(tb[NETWORK_METHOD]); data = blobmsg_data(tb[NETWORK_DATA]); - printf("METHOD! : %s\n", method); - printf("DATA: %s\n", data); - - - - printf("GET STRING FINISHED NETWORK MSG!\n"); - blob_buf_init(&data_buf, 0); blobmsg_add_json_from_string(&data_buf, data); - printf("JSON PARSING AGAIN FINISHED NETWORK MSG!\n"); printf("DO STRINGCOMPARE: %s : %s!\n", method, data); @@ -483,14 +466,18 @@ int handle_network_msg(char* msg) if (strncmp(method, "probe", 5) == 0) { printf("METHOD PROBE\n"); probe_entry entry; - parse_to_probe_req(data_buf.head, &entry); - probe_array_insert(entry); + if(parse_to_probe_req(data_buf.head, &entry) == 0) + { + probe_array_insert(entry); + print_probe_array(); + } } else if (strncmp(method, "clients", 5) == 0) { printf("METHOD CLIENTS\n"); printf("PARSING CLIENTS NETWORK MSG!\n"); parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); + /* hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); @@ -500,7 +487,7 @@ int handle_network_msg(char* msg) pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); - pthread_mutex_unlock(&client_array_mutex); + pthread_mutex_unlock(&client_array_mutex);*/ } //free(method); //free(data); @@ -518,25 +505,15 @@ int send_blob_attr_via_network(struct blob_attr *msg, char* method) char *data_str; char *str; - printf("TO JSON\n"); data_str = blobmsg_format_json(msg, true); - printf("DATA STRING: %s\n", data_str); - printf("JSON FINISHED\n"); - - printf("ADD STRINGS!\n"); blob_buf_init(&b_send_network, 0); blobmsg_add_string(&b_send_network, "method", method); blobmsg_add_string(&b_send_network, "data", data_str); - printf("ADD FINISHED!\n"); //blobmsg_add_blob(&b, msg); - printf("TO JSON AGAIN\n"); str = blobmsg_format_json(b_send_network.head, true); - printf("TO JSON AGAIN FINISHED\n"); - printf("SENDING\n"); send_string_enc(str); - printf("SENDING FINISHED!\n"); //free(str); //free(data_str); return 0; @@ -797,13 +774,8 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ if (!msg) return; - printf("PARSE TO CLIENTS!\n"); parse_to_clients(msg, 1, req->peer); - - printf("SENDING CLIENTS VIA NETWORK\n"); send_blob_attr_via_network(msg, "clients"); - printf("SEND CLIENTS FINISHED!\n"); - print_client_array(); print_ap_array(); From 804fc0ca8d484c5f22c9bda3d0e7d0331f608d92 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 12:10:28 +0100 Subject: [PATCH 096/174] try fix probe request --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 04cbc78..732b1c6 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -420,7 +420,7 @@ static int handle_deauth_req(struct blob_attr *msg) { int handle_network_msg(char* msg) { - printf("HANDLING NETWORK MSG: %s\n"); + printf("HANDLING NETWORK MSG: %s\n", msg); struct blob_attr *tb[__NETWORK_MAX]; char *method; char *data; From 88152177d5fd468f351cc13cc0cf976db2c6eb8e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 12:17:03 +0100 Subject: [PATCH 097/174] try fix probe request --- src/utils/ubus.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 732b1c6..6be7878 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -374,12 +374,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; - parse_to_probe_req(msg, &prob_req); + if(parse_to_probe_req(msg, &prob_req) == 0) + { + insert_to_array(prob_req, 1); + send_blob_attr_via_network(msg, "probe"); + } //insert_to_list(prob_req, 1); //probe_entry tmp_probe = - insert_to_array(prob_req, 1); - - send_blob_attr_via_network(msg, "probe"); // send probe via network /*char *str; @@ -525,7 +526,9 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, char *str; str = blobmsg_format_json(msg, true); printf("METHOD new: %s : %s\n", method, str); - free(str); + + //TODO CHECK IF FREE IS CORREECT! + //free(str); // TODO: Only handle probe request and NOT assoc, ... From a6140a0a8d82e9b14e555683783e307113d2d315 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 12:23:01 +0100 Subject: [PATCH 098/174] print probe array --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 2d09677..f9b0c53 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -345,7 +345,7 @@ static int handle_probe_req(struct blob_attr *msg) { printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str); - //print_probe_array(); + print_probe_array(); /* // deny access if (!decide_function(&tmp_probe)) { From e18f42ae4db9ee0224ed8cb80b5bd2e7e32b0a09 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 12:19:21 +0100 Subject: [PATCH 099/174] try fix probe request --- src/utils/ubus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 6be7878..4a256aa 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -377,6 +377,7 @@ static int handle_probe_req(struct blob_attr *msg) { if(parse_to_probe_req(msg, &prob_req) == 0) { insert_to_array(prob_req, 1); + print_probe_array(); send_blob_attr_via_network(msg, "probe"); } //insert_to_list(prob_req, 1); @@ -469,7 +470,7 @@ int handle_network_msg(char* msg) probe_entry entry; if(parse_to_probe_req(data_buf.head, &entry) == 0) { - probe_array_insert(entry); + insert_to_array(entry, 0); print_probe_array(); } } else if (strncmp(method, "clients", 5) == 0) { From 9377c5ab6322264828cb74c4769df7a6ab15824e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 12:32:41 +0100 Subject: [PATCH 100/174] free string --- src/utils/ubus.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 4a256aa..b0d121e 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -24,6 +24,7 @@ static struct blob_buf b; static struct blob_buf b_send_network; static struct blob_buf network_buf; static struct blob_buf data_buf; +static struct blob_buf b_probe; @@ -529,7 +530,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, printf("METHOD new: %s : %s\n", method, str); //TODO CHECK IF FREE IS CORREECT! - //free(str); + free(str); // TODO: Only handle probe request and NOT assoc, ... @@ -740,14 +741,11 @@ int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) { if(!blob_data(msg)) { - printf("DATA IS NULL!!!\n"); return -1; } - printf("BLOB LEN: %d\n", blob_len(msg)); if(blob_len(msg) <= 0) { - printf("DATA IS NULL!!!\n"); return -1; } @@ -800,7 +798,6 @@ void update_clients(struct uloop_timeout *t) { } void update_hostapd_sockets(struct uloop_timeout *t) { - printf("Updating hostapd sockets!\n"); subscribe_to_hostapd_interfaces(hostapd_dir_glob); uloop_timeout_set(&hostapd_timer, timeout_config.update_hostapd * 1000); } @@ -865,18 +862,16 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { printf("SENDING PROBE VIA NETWORK!\n"); - static struct blob_buf b; + blob_buf_init(&b_probe, 0); + blobmsg_add_macaddr(&b_probe, "bssid", probe_entry.bssid_addr); + blobmsg_add_macaddr(&b_probe, "address", probe_entry.client_addr); + blobmsg_add_macaddr(&b_probe, "target", probe_entry.target_addr); + blobmsg_add_u32(&b_probe, "signal", probe_entry.signal); + blobmsg_add_u32(&b_probe, "freq", probe_entry.freq); + blobmsg_add_u8(&b_probe, "ht_support", probe_entry.ht_support); + blobmsg_add_u8(&b_probe, "vht_support", probe_entry.vht_support); - blob_buf_init(&b, 0); - blobmsg_add_macaddr(&b, "bssid", probe_entry.bssid_addr); - blobmsg_add_macaddr(&b, "address", probe_entry.client_addr); - blobmsg_add_macaddr(&b, "target", probe_entry.target_addr); - blobmsg_add_u32(&b, "signal", probe_entry.signal); - blobmsg_add_u32(&b, "freq", probe_entry.freq); - blobmsg_add_u8(&b, "ht_support", probe_entry.ht_support); - blobmsg_add_u8(&b, "vht_support", probe_entry.vht_support); - - send_blob_attr_via_network(b.head, "probe"); + send_blob_attr_via_network(b_probe.head, "probe"); return 0; } \ No newline at end of file From 155180692cb5b95eadcd31454d77ad3cc38d8380 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 19:51:43 +0100 Subject: [PATCH 101/174] remove prints --- src/storage/datastorage.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index a80cccf..4126702 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -83,7 +83,7 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { score += (probe_entry.signal >= dawn_metric.rssi_val) ? dawn_metric.rssi : 0; score += (probe_entry.signal <= dawn_metric.low_rssi_val) ? dawn_metric.low_rssi : 0; - printf("SCORE: %d\n", score); + printf("SCORE: %d of:\n", score); print_probe_entry(probe_entry); return score; @@ -481,9 +481,6 @@ ap ap_array_get_ap(uint8_t bssid_addr[]) { char bssid_mac_string[20]; sprintf(bssid_mac_string, MACSTR, MAC2STR(bssid_addr)); - printf("Try to find: %s\n", bssid_mac_string); - printf("in\n"); - print_ap_array(); if (ap_entry_last == -1) { return ret; From 3fc9dc41d7da33c4b0f623a814d97223d698b2f0 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 20:03:43 +0100 Subject: [PATCH 102/174] remove probe --- src/network/networksocket.c | 2 +- src/utils/ubus.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/network/networksocket.c b/src/network/networksocket.c index 3f5962f..7cf5f12 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -149,7 +149,7 @@ void *receive_msg_enc(void *args) { char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length); - printf("NETRWORK RECEIVED: %s\n", dec); + //printf("NETRWORK RECEIVED: %s\n", dec); free(base64_dec_str); handle_network_msg(dec); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index b0d121e..f5cfa97 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -447,27 +447,27 @@ int handle_network_msg(char* msg) blobmsg_add_json_from_string(&data_buf, data); - printf("DO STRINGCOMPARE: %s : %s!\n", method, data); + //printf("DO STRINGCOMPARE: %s : %s!\n", method, data); if(!data_buf.head) { - printf("NULL?!\n"); + //printf("NULL?!\n"); return -1; } if(blob_len(data_buf.head) <= 0) { - printf("NULL?!\n"); + //printf("NULL?!\n"); return -1; } if(strlen(method) < 5) { - printf("STRING IS LESS THAN 5!\n"); + //printf("STRING IS LESS THAN 5!\n"); return -1; } if (strncmp(method, "probe", 5) == 0) { - printf("METHOD PROBE\n"); + //printf("METHOD PROBE\n"); probe_entry entry; if(parse_to_probe_req(data_buf.head, &entry) == 0) { @@ -475,8 +475,8 @@ int handle_network_msg(char* msg) print_probe_array(); } } else if (strncmp(method, "clients", 5) == 0) { - printf("METHOD CLIENTS\n"); - printf("PARSING CLIENTS NETWORK MSG!\n"); + //printf("METHOD CLIENTS\n"); + //printf("PARSING CLIENTS NETWORK MSG!\n"); parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); @@ -494,7 +494,7 @@ int handle_network_msg(char* msg) } //free(method); //free(data); - printf("HANDLING FINISHED NETWORK MSG!\n"); + //printf("HANDLING FINISHED NETWORK MSG!\n"); return 0; } From 14c992118fd1e1c6b8d7065f5fac2822d2a46ef6 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 20:05:35 +0100 Subject: [PATCH 103/174] remove prints --- src/network/networksocket.c | 2 +- src/utils/ubus.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/networksocket.c b/src/network/networksocket.c index 7cf5f12..3f0a003 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -186,7 +186,7 @@ int send_string(char *msg) { int send_string_enc(char *msg) { pthread_mutex_lock(&send_mutex); - printf("Sending string: %s\n", msg); + //printf("Sending string: %s\n", msg); size_t msglen = strlen(msg); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index f5cfa97..281fa08 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -423,7 +423,7 @@ static int handle_deauth_req(struct blob_attr *msg) { int handle_network_msg(char* msg) { - printf("HANDLING NETWORK MSG: %s\n", msg); + //printf("HANDLING NETWORK MSG: %s\n", msg); struct blob_attr *tb[__NETWORK_MAX]; char *method; char *data; From 5f0221d08b011ae8b40d9e357a1ef8204fd757fd Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 13 Dec 2017 20:06:53 +0100 Subject: [PATCH 104/174] remove prints --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 281fa08..a46e0a9 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -527,7 +527,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, struct blob_attr *msg) { char *str; str = blobmsg_format_json(msg, true); - printf("METHOD new: %s : %s\n", method, str); + //printf("METHOD new: %s : %s\n", method, str); //TODO CHECK IF FREE IS CORREECT! free(str); From 6e1de11914904ebd3caaddd8ec3d24eb873abdde Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 14 Dec 2017 00:59:57 +0100 Subject: [PATCH 105/174] add print --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a46e0a9..281fa08 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -527,7 +527,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, struct blob_attr *msg) { char *str; str = blobmsg_format_json(msg, true); - //printf("METHOD new: %s : %s\n", method, str); + printf("METHOD new: %s : %s\n", method, str); //TODO CHECK IF FREE IS CORREECT! free(str); From e2a16404b1f3af767c32486ece697ea40cb1b76f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 15 Dec 2017 19:07:40 +0100 Subject: [PATCH 106/174] compare station count --- src/include/datastorage.h | 3 ++- src/storage/datastorage.c | 33 +++++++++++++++++++++++++++++++-- src/utils/ubus.c | 15 +++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index c47e2a4..86c1e73 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -128,6 +128,7 @@ typedef struct ap_s { uint8_t vht; uint32_t channel_utilization; time_t time; + uint32_t station_count; } ap; // ---------------- Defines ---------------- @@ -177,7 +178,7 @@ int mac_is_equal(uint8_t addr1[], uint8_t addr2[]); int mac_is_greater(uint8_t addr1[], uint8_t addr2[]); -int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]); +int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automatic_kick); /* List stuff */ diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index a80cccf..458a3e3 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -41,6 +41,8 @@ int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_ int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]); +int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, int automatic_kick); + int probe_entry_last = -1; int client_entry_last = -1; int ap_entry_last = -1; @@ -89,7 +91,28 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { return score; } -int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) { +int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, 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); + + // check if ap entry is available + 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) + ) { + printf("Comparing own %d to %d\n", ap_entry_own.station_count, ap_entry_to_compre.station_count); + if(automatic_kick){ + return (ap_entry_own.station_count - 1) > ap_entry_to_compre.station_count; + } else { + return ap_entry_own.station_count > ap_entry_to_compre.station_count; + } + } + + return 0; +} + + +int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automatic_kick) { int own_score = -1; // find first client entry in probe array @@ -131,12 +154,18 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) { { return 1; } + if (!mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && + own_score == eval_probe_metric(probe_array[k])) + { + // if ap have same value but station count is different... + return compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick); + } } return 0; } int kick_client(struct client_s client_entry) { - return better_ap_available(client_entry.bssid_addr, client_entry.client_addr); + return better_ap_available(client_entry.bssid_addr, client_entry.client_addr, 1); } void kick_clients(uint8_t bssid[], uint32_t id) { diff --git a/src/utils/ubus.c b/src/utils/ubus.c index f9b0c53..f10e047 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -80,6 +80,7 @@ enum { CLIENT_TABLE_HT, CLIENT_TABLE_VHT, CLIENT_TABLE_CHAN_UTIL, + CLIENT_TABLE_NUM_STA, __CLIENT_TABLE_MAX, }; @@ -90,6 +91,7 @@ static const struct blobmsg_policy client_table_policy[__CLIENT_TABLE_MAX] = { [CLIENT_TABLE_HT] = {.name = "ht_supported", .type = BLOBMSG_TYPE_INT8}, [CLIENT_TABLE_VHT] = {.name = "vht_supported", .type = BLOBMSG_TYPE_INT8}, [CLIENT_TABLE_CHAN_UTIL] = {.name = "channel_utilization", .type = BLOBMSG_TYPE_INT32}, + [CLIENT_TABLE_NUM_STA] = {.name = "num_sta", .type = BLOBMSG_TYPE_INT32}, }; enum { @@ -215,7 +217,7 @@ static int decide_function(probe_entry *prob_req) { return 0; } - if(better_ap_available(prob_req->bssid_addr, prob_req->client_addr)) + if(better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) { return 0; } @@ -345,7 +347,7 @@ static int handle_probe_req(struct blob_attr *msg) { printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str); - print_probe_array(); + //print_probe_array(); /* // deny access if (!decide_function(&tmp_probe)) { @@ -574,6 +576,15 @@ 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]); + + if(tb[CLIENT_TABLE_NUM_STA]) + { + ap_entry.station_count = blobmsg_get_u32(tb[CLIENT_TABLE_NUM_STA]); + } else + { + ap_entry.station_count = 0; + } + insert_to_ap_array(ap_entry); if (do_kick) { From 22cc461d527b4b73c39626aae230400970a1c25f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 15 Dec 2017 23:18:28 +0100 Subject: [PATCH 107/174] add ability of station count to config file --- src/include/datastorage.h | 1 + src/storage/datastorage.c | 2 +- src/utils/dawn_uci.c | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 86c1e73..6d7a6fd 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -33,6 +33,7 @@ struct probe_metric_s { int max_chan_util_val; int min_probe_count; int bandwith_threshold; + int use_station_count; }; struct time_config_s { diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 458a3e3..a07eae8 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -154,7 +154,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat { return 1; } - if (!mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && + if ( dawn_metric.use_station_count && !mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && own_score == eval_probe_metric(probe_array[k])) { // if ap have same value but station count is different... diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 9ca9938..05401a6 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -209,6 +209,14 @@ struct probe_metric_s uci_get_dawn_metric() { if (ptr.o->type == UCI_TYPE_STRING) ret.bandwith_threshold = atoi(ptr.o->v.string); + char tmp_use_station_count[] = "dawn.metric.use_station_count"; + if (uci_lookup_ptr(c, &ptr, tmp_use_station_count, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.use_station_count = atoi(ptr.o->v.string); + printf("Loaded metric: %d\n", ret.min_probe_count); uci_free_context(c); From 3b6f6e1fc4b6810b3a53eb2cb710e9031dc72e9b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 15 Dec 2017 23:18:28 +0100 Subject: [PATCH 108/174] add ability of station count to config file --- files/dawn.config | 53 ++++++++++++++++++++------------------- src/include/datastorage.h | 1 + src/storage/datastorage.c | 2 +- src/utils/dawn_uci.c | 8 ++++++ 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 817255c..91ef099 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,36 +1,37 @@ config settings network - option broadcast_ip '225.0.0.37' - option broadcast_port '1025' - option multicast '1' - option shared_key 'Niiiiiiiiiiiiiik' - option iv 'Niiiiiiiiiiiiiik' + option broadcast_ip '225.0.0.37' + option broadcast_port '1025' + option multicast '1' + option shared_key 'Niiiiiiiiiiiiiik' + option iv 'Niiiiiiiiiiiiiik' config settings ordering option sort_order 'csfb' config settings hostapd - option hostapd_dir '/var/run/hostapd' + option hostapd_dir '/var/run/hostapd' config settings times - option update_client '50' - option remove_client '120' - option remove_probe '120' - option remove_ap '460' - option update_hostapd '10' + option update_client '10' + option remove_client '120' + option remove_probe '120' + option remove_ap '460' + option update_hostapd '10' config settings metric - option ht_support '10' - option vht_support '50' - option no_ht_support '0' - option no_vht_support '0' - option rssi '10' - option low_rssi '-500' - option freq '100' - option chan_util '50' - option max_chan_util '-50' - option rssi_val '-60' - option low_rssi_val '-80' - option chan_util_val '140' - option max_chan_util_val '170' - option min_probe_count '2' - option bandwith_threshold '6' + option ht_support '10' + option vht_support '10' + option no_ht_support '0' + option no_vht_support '0' + option rssi '10' + option low_rssi '-500' + option freq '100' + option chan_util '50' + option max_chan_util '-50' + option rssi_val '-60' + option low_rssi_val '-80' + option chan_util_val '140' + option max_chan_util_val '170' + option min_probe_count '4' + option bandwith_threshold '6' + option use_station_count '1' diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 86c1e73..6d7a6fd 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -33,6 +33,7 @@ struct probe_metric_s { int max_chan_util_val; int min_probe_count; int bandwith_threshold; + int use_station_count; }; struct time_config_s { diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 458a3e3..a07eae8 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -154,7 +154,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat { return 1; } - if (!mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && + if ( dawn_metric.use_station_count && !mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && own_score == eval_probe_metric(probe_array[k])) { // if ap have same value but station count is different... diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 9ca9938..05401a6 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -209,6 +209,14 @@ struct probe_metric_s uci_get_dawn_metric() { if (ptr.o->type == UCI_TYPE_STRING) ret.bandwith_threshold = atoi(ptr.o->v.string); + char tmp_use_station_count[] = "dawn.metric.use_station_count"; + if (uci_lookup_ptr(c, &ptr, tmp_use_station_count, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.use_station_count = atoi(ptr.o->v.string); + printf("Loaded metric: %d\n", ret.min_probe_count); uci_free_context(c); From c6336b7c4819a4555ba8196f6af40c15f8c1e62c Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 16 Dec 2017 00:48:00 +0100 Subject: [PATCH 109/174] send first clientstring via network and then parse --- src/utils/ubus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index f10e047..bd2ada9 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -599,10 +599,11 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ if (!msg) return; - parse_to_clients(msg, 1, req->peer); - char *str = blobmsg_format_json(msg, true); send_string_enc(str); + + parse_to_clients(msg, 1, req->peer); + print_client_array(); print_ap_array(); } From 3b35ad46455fd3c8bf9a26e44d5cf9e337c95291 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 16 Dec 2017 17:47:04 +0100 Subject: [PATCH 110/174] don't use utilization --- files/dawn.config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 91ef099..a204eb8 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -20,14 +20,14 @@ config settings times config settings metric option ht_support '10' - option vht_support '10' + option vht_support '100' option no_ht_support '0' option no_vht_support '0' option rssi '10' option low_rssi '-500' option freq '100' - option chan_util '50' - option max_chan_util '-50' + option chan_util '0' + option max_chan_util '0' option rssi_val '-60' option low_rssi_val '-80' option chan_util_val '140' From 1787c8110fa48782a1b9a429211e3deb4d790388 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 17 Dec 2017 09:39:38 +0100 Subject: [PATCH 111/174] remove prints --- src/storage/datastorage.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index a07eae8..2dd33de 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -508,11 +508,11 @@ ap insert_to_ap_array(ap entry) { ap ap_array_get_ap(uint8_t bssid_addr[]) { ap ret; - char bssid_mac_string[20]; - sprintf(bssid_mac_string, MACSTR, MAC2STR(bssid_addr)); - printf("Try to find: %s\n", bssid_mac_string); - printf("in\n"); - print_ap_array(); + //char bssid_mac_string[20]; + //sprintf(bssid_mac_string, MACSTR, MAC2STR(bssid_addr)); + //printf("Try to find: %s\n", bssid_mac_string); + //printf("in\n"); + //print_ap_array(); if (ap_entry_last == -1) { return ret; From 9569a87ca5c36423be7e38c9925cb42ba0d32ae1 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 19 Dec 2017 10:48:59 +0100 Subject: [PATCH 112/174] add debug msgs --- src/storage/datastorage.c | 6 ++++++ src/utils/ubus.c | 1 + 2 files changed, 7 insertions(+) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 2dd33de..1cbcf86 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -171,6 +171,10 @@ int kick_client(struct client_s client_entry) { void kick_clients(uint8_t bssid[], uint32_t id) { pthread_mutex_lock(&client_array_mutex); pthread_mutex_lock(&probe_array_mutex); + printf("-------- KICKING CLIENS!!!---------\n"); + char mac_buf_ap[20]; + sprintf(mac_buf_ap, MACSTR, MAC2STR(bssid)); + printf("EVAL %s\n", mac_buf_ap); // Seach for BSSID int i; @@ -240,6 +244,8 @@ void kick_clients(uint8_t bssid[], uint32_t id) { } } + printf("---------------------------\n"); + pthread_mutex_unlock(&probe_array_mutex); pthread_mutex_unlock(&client_array_mutex); } diff --git a/src/utils/ubus.c b/src/utils/ubus.c index bd2ada9..5017262 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -619,6 +619,7 @@ static int ubus_get_clients() { void update_clients(struct uloop_timeout *t) { ubus_get_clients(); + // maybe to much?! don't set timer again... uloop_timeout_set(&client_timer, timeout_config.update_client * 1000); } From 8b1d45a80de7194fbf499b10f0123bf6344d8a7a Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 19 Dec 2017 13:21:28 +0100 Subject: [PATCH 113/174] improve device function --- files/dawn.config | 2 +- src/storage/datastorage.c | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index a204eb8..74f0c5e 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -32,6 +32,6 @@ config settings metric option low_rssi_val '-80' option chan_util_val '140' option max_chan_util_val '170' - option min_probe_count '4' + option min_probe_count '0' option bandwith_threshold '6' option use_station_count '1' diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 1cbcf86..2149cfa 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -133,6 +133,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat break; } if (mac_is_equal(bssid_addr, probe_array[j].bssid_addr)) { + printf("Calculating own score!\n"); own_score = eval_probe_metric(probe_array[j]); break; } @@ -145,17 +146,28 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat int k; for (k = i; k <= probe_entry_last; k++) { - if (!mac_is_equal(probe_array[k].client_addr, client_addr)) { + int score_to_compare; + + if (!mac_is_equal(probe_array[k].client_addr, client_addr)) + { break; } - if (!mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && - own_score < - eval_probe_metric(probe_array[k])) // that's wrong! find client_entry OR write things in probe array struct! + + if(mac_is_equal(bssid_addr, probe_array[k].bssid_addr)) + { + printf("Own Score! Skipping!\n"); + print_probe_entry(probe_array[k]); + continue; + } + + printf("Calculating score to compare!\n"); + score_to_compare = eval_probe_metric(probe_array[k]); + + if(own_score < score_to_compare) { return 1; } - if ( dawn_metric.use_station_count && !mac_is_equal(bssid_addr, probe_array[k].bssid_addr) && - own_score == eval_probe_metric(probe_array[k])) + if (dawn_metric.use_station_count && own_score == score_to_compare) { // if ap have same value but station count is different... return compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick); @@ -204,8 +216,10 @@ void kick_clients(uint8_t bssid[], uint32_t id) { } + int do_kick = kick_client(client_array[j]); + // better ap available - if (kick_client(client_array[j]) > 0) { + if (do_kick > 0) { printf("Better AP available. Kicking client:\n"); print_client_entry(client_array[j]); printf("Check if client is active receiving!\n"); @@ -232,7 +246,7 @@ void kick_clients(uint8_t bssid[], uint32_t id) { break; // no entry in probe array for own bssid - } else if (kick_client(client_array[j]) == -1) { + } else if (do_kick == -1) { printf("No Information about client. Force reconnect:\n"); print_client_entry(client_array[j]); del_client_interface(id, client_array[j].client_addr, 0, 0, 0); From c22b499e0ce0a7a4f18682427ccb615e7108d428 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 19 Dec 2017 13:49:37 +0100 Subject: [PATCH 114/174] reset files/ --- files/dawn.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index 74f0c5e..a204eb8 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -32,6 +32,6 @@ config settings metric option low_rssi_val '-80' option chan_util_val '140' option max_chan_util_val '170' - option min_probe_count '0' + option min_probe_count '4' option bandwith_threshold '6' option use_station_count '1' From 1375b7a736b8a54e79f7132fab56554c401578cf Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 19 Dec 2017 18:56:12 +0100 Subject: [PATCH 115/174] check probe requests --- src/utils/ubus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 5017262..a5b311c 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -337,7 +337,7 @@ static int handle_probe_req(struct blob_attr *msg) { parse_to_probe_req(msg, &prob_req); //insert_to_list(prob_req, 1); //probe_entry tmp_probe = - insert_to_array(prob_req, 1); + probe_entry tmp_prob_req = insert_to_array(prob_req, 1); // send probe via network @@ -348,12 +348,12 @@ static int handle_probe_req(struct blob_attr *msg) { printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str); //print_probe_array(); - /* + // deny access - if (!decide_function(&tmp_probe)) { + if (!decide_function(&tmp_prob_req)) { //printf("MAC WILL BE DECLINED!!!\n"); return UBUS_STATUS_UNKNOWN_ERROR; - }*/ + } //printf("MAC WILL BE ACCEPDTED!!!\n"); return 0; } From bd1c38c0ea80b524c3abce04588f625031af3dd9 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 19 Dec 2017 19:07:41 +0100 Subject: [PATCH 116/174] add option to deny on probe requests --- files/dawn.config | 1 + src/include/datastorage.h | 1 + src/utils/dawn_uci.c | 8 ++++++++ src/utils/ubus.c | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/files/dawn.config b/files/dawn.config index a204eb8..bcd4a52 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -35,3 +35,4 @@ config settings metric option min_probe_count '4' option bandwith_threshold '6' option use_station_count '1' + option eval_probe_req '1' \ No newline at end of file diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 6d7a6fd..2c1c65e 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -34,6 +34,7 @@ struct probe_metric_s { int min_probe_count; int bandwith_threshold; int use_station_count; + int eval_probe_req; }; struct time_config_s { diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 05401a6..150e995 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -217,6 +217,14 @@ struct probe_metric_s uci_get_dawn_metric() { if (ptr.o->type == UCI_TYPE_STRING) ret.use_station_count = atoi(ptr.o->v.string); + char tmp_eval_probe_req[] = "dawn.metric.eval_probe_req"; + if (uci_lookup_ptr(c, &ptr, tmp_eval_probe_req, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if (ptr.o->type == UCI_TYPE_STRING) + ret.eval_probe_req = atoi(ptr.o->v.string); + printf("Loaded metric: %d\n", ret.min_probe_count); uci_free_context(c); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a5b311c..9d28ec2 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -350,6 +350,12 @@ static int handle_probe_req(struct blob_attr *msg) { //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"); return UBUS_STATUS_UNKNOWN_ERROR; From 7a7519d420d4476b6736783c50b7e7dbe27a2a26 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 20 Dec 2017 18:26:30 +0100 Subject: [PATCH 117/174] don't return if ap is not lower! --- src/storage/datastorage.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 2149cfa..6eabe3e 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -170,7 +170,10 @@ 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... - return compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick); + if(compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick)) + { + return 1; + } } } return 0; From dc26e1a03a0a8bda003350eeb0f30a5eb9330bf9 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 21 Dec 2017 18:47:11 +0100 Subject: [PATCH 118/174] reformat code --- src/crypto/base64.c | 111 ++++++++++++++++------------------ src/network/broadcastsocket.c | 2 +- src/network/multicastsocket.c | 13 ++-- src/network/networksocket.c | 2 +- src/storage/datastorage.c | 32 ++++------ src/utils/dawn_iwinfo.c | 38 +++++------- src/utils/ubus.c | 62 +++++++------------ 7 files changed, 110 insertions(+), 150 deletions(-) diff --git a/src/crypto/base64.c b/src/crypto/base64.c index eec7d98..9bed459 100644 --- a/src/crypto/base64.c +++ b/src/crypto/base64.c @@ -88,28 +88,27 @@ /* aaaack but it's fast and const should make it shared text page. */ static const unsigned char pr2six[256] = -{ - /* ASCII table */ - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, - 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, - 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 -}; + { + /* ASCII table */ + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, + 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, + 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 + }; -int Base64decode_len(const char *bufcoded) -{ +int Base64decode_len(const char *bufcoded) { int nbytesdecoded; register const unsigned char *bufin; register int nprbytes; @@ -123,8 +122,7 @@ int Base64decode_len(const char *bufcoded) return nbytesdecoded + 1; } -int Base64decode(char *bufplain, const char *bufcoded) -{ +int Base64decode(char *bufplain, const char *bufcoded) { int nbytesdecoded; register const unsigned char *bufin; register unsigned char *bufout; @@ -139,28 +137,28 @@ int Base64decode(char *bufplain, const char *bufcoded) bufin = (const unsigned char *) bufcoded; while (nprbytes > 4) { - *(bufout++) = - (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); - *(bufout++) = - (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); - *(bufout++) = - (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); - bufin += 4; - nprbytes -= 4; + *(bufout++) = + (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); + *(bufout++) = + (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); + *(bufout++) = + (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); + bufin += 4; + nprbytes -= 4; } /* Note: (nprbytes == 1) would be an error, so just ingore that case */ if (nprbytes > 1) { - *(bufout++) = - (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); + *(bufout++) = + (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); } if (nprbytes > 2) { - *(bufout++) = - (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); + *(bufout++) = + (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); } if (nprbytes > 3) { - *(bufout++) = - (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); + *(bufout++) = + (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); } *(bufout++) = '\0'; @@ -169,39 +167,36 @@ int Base64decode(char *bufplain, const char *bufcoded) } static const char basis_64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -int Base64encode_len(int len) -{ +int Base64encode_len(int len) { return ((len + 2) / 3 * 4) + 1; } -int Base64encode(char *encoded, const char *string, int len) -{ +int Base64encode(char *encoded, const char *string, int len) { int i; char *p; p = encoded; for (i = 0; i < len - 2; i += 3) { - *p++ = basis_64[(string[i] >> 2) & 0x3F]; - *p++ = basis_64[((string[i] & 0x3) << 4) | - ((int) (string[i + 1] & 0xF0) >> 4)]; - *p++ = basis_64[((string[i + 1] & 0xF) << 2) | - ((int) (string[i + 2] & 0xC0) >> 6)]; - *p++ = basis_64[string[i + 2] & 0x3F]; - } - if (i < len) { - *p++ = basis_64[(string[i] >> 2) & 0x3F]; - if (i == (len - 1)) { - *p++ = basis_64[((string[i] & 0x3) << 4)]; - *p++ = '='; - } - else { + *p++ = basis_64[(string[i] >> 2) & 0x3F]; *p++ = basis_64[((string[i] & 0x3) << 4) | ((int) (string[i + 1] & 0xF0) >> 4)]; - *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; + *p++ = basis_64[((string[i + 1] & 0xF) << 2) | + ((int) (string[i + 2] & 0xC0) >> 6)]; + *p++ = basis_64[string[i + 2] & 0x3F]; } - *p++ = '='; + if (i < len) { + *p++ = basis_64[(string[i] >> 2) & 0x3F]; + if (i == (len - 1)) { + *p++ = basis_64[((string[i] & 0x3) << 4)]; + *p++ = '='; + } else { + *p++ = basis_64[((string[i] & 0x3) << 4) | + ((int) (string[i + 1] & 0xF0) >> 4)]; + *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; + } + *p++ = '='; } *p++ = '\0'; diff --git a/src/network/broadcastsocket.c b/src/network/broadcastsocket.c index b002046..7d6fc94 100644 --- a/src/network/broadcastsocket.c +++ b/src/network/broadcastsocket.c @@ -33,7 +33,7 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_ addr->sin_port = htons(_broadcast_port); while (bind(sock, (struct sockaddr *) addr, sizeof(*addr)) < - 0) { + 0) { fprintf(stderr, "Binding socket failed!\n"); sleep(1); } diff --git a/src/network/multicastsocket.c b/src/network/multicastsocket.c index b67499e..66664f2 100644 --- a/src/network/multicastsocket.c +++ b/src/network/multicastsocket.c @@ -69,13 +69,12 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_ return sock; } -int remove_multicast_socket(int socket) -{ - if (setsockopt ( socket, - IPPROTO_IP, - IP_DROP_MEMBERSHIP, - &command, sizeof (command)) < 0 ) { - perror ("setsockopt:IP_DROP_MEMBERSHIP"); +int remove_multicast_socket(int socket) { + if (setsockopt(socket, + IPPROTO_IP, + IP_DROP_MEMBERSHIP, + &command, sizeof(command)) < 0) { + perror("setsockopt:IP_DROP_MEMBERSHIP"); return -1; } return 0; diff --git a/src/network/networksocket.c b/src/network/networksocket.c index ed33e02..a4a975e 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -238,7 +238,7 @@ int send_string_enc(char *msg) { } void close_socket() { - if(multicast_socket){ + if (multicast_socket) { remove_multicast_socket(sock); } close(sock); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 6eabe3e..bc3ab08 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -98,10 +98,10 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar // check if ap entry is available 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) + && mac_is_equal(ap_entry_to_compre.bssid_addr, bssid_addr_to_compare) ) { printf("Comparing own %d to %d\n", ap_entry_own.station_count, ap_entry_to_compre.station_count); - if(automatic_kick){ + if (automatic_kick) { return (ap_entry_own.station_count - 1) > ap_entry_to_compre.station_count; } else { return ap_entry_own.station_count > ap_entry_to_compre.station_count; @@ -148,30 +148,25 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat for (k = i; k <= probe_entry_last; k++) { int score_to_compare; - if (!mac_is_equal(probe_array[k].client_addr, client_addr)) - { + if (!mac_is_equal(probe_array[k].client_addr, client_addr)) { break; } - if(mac_is_equal(bssid_addr, probe_array[k].bssid_addr)) - { + if (mac_is_equal(bssid_addr, probe_array[k].bssid_addr)) { printf("Own Score! Skipping!\n"); print_probe_entry(probe_array[k]); continue; } - + printf("Calculating score to compare!\n"); score_to_compare = eval_probe_metric(probe_array[k]); - if(own_score < score_to_compare) - { + if (own_score < score_to_compare) { return 1; } - if (dawn_metric.use_station_count && own_score == score_to_compare) - { + 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, automatic_kick)) { return 1; } } @@ -228,12 +223,11 @@ void kick_clients(uint8_t bssid[], uint32_t id) { printf("Check if client is active receiving!\n"); float rx_rate, tx_rate; - if(get_bandwidth_iwinfo(client_array[j].client_addr, &rx_rate, &tx_rate)) - { + if (get_bandwidth_iwinfo(client_array[j].client_addr, &rx_rate, &tx_rate)) { // only use rx_rate for indicating if transmission is going on // <= 6MBits <- probably no transmission // tx_rate has always some weird value so don't use ist - if(rx_rate > dawn_metric.bandwith_threshold){ + if (rx_rate > dawn_metric.bandwith_threshold) { printf("Client is probably in active transmisison. Don't kick! RxRate is: %f\n", rx_rate); continue; } @@ -633,8 +627,7 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) { } } -void uloop_add_data_cbs() -{ +void uloop_add_data_cbs() { uloop_timeout_add(&probe_timeout); uloop_timeout_add(&client_timeout); uloop_timeout_add(&ap_timeout); @@ -648,8 +641,7 @@ void remove_probe_array_cb(struct uloop_timeout *t) { uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000); } -void remove_client_array_cb(struct uloop_timeout *t) -{ +void remove_client_array_cb(struct uloop_timeout *t) { pthread_mutex_lock(&client_array_mutex); printf("[Thread] : Removing old client entries!\n"); remove_old_client_entries(time(0), timeout_config.update_client); diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 7cacad6..7984f31 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -17,7 +17,7 @@ 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); -#define IWINFO_BUFSIZE 24 * 1024 +#define IWINFO_BUFSIZE 24 * 1024 int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) { @@ -33,8 +33,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_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) { sucess = 1; break; } @@ -44,7 +43,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_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate) { int i, len; char buf[IWINFO_BUFSIZE]; @@ -53,23 +52,18 @@ int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float iw = iwinfo_backend(ifname); - if (iw->assoclist(ifname, buf, &len)) - { + if (iw->assoclist(ifname, buf, &len)) { printf("No information available\n"); return 0; - } - else if (len <= 0) - { + } else if (len <= 0) { printf("No station connected\n"); return 0; } - for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) - { + 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)) - { + if (mac_is_equal(client_addr, e->mac)) { //struct iwinfo_assoclist_entry * rx_rate = e->rx_rate; //struct iwinfo_assoclist_entry * tx_rate = e->tx_rate; *rx_rate = e->rx_rate.rate / 1000; @@ -99,7 +93,7 @@ int get_rssi_iwinfo(__uint8_t *client_addr) { while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { rssi = get_rssi(entry->d_name, client_addr); - if(rssi != INT_MIN) + if (rssi != INT_MIN) break; } } @@ -107,7 +101,7 @@ int get_rssi_iwinfo(__uint8_t *client_addr) { return rssi; } -int get_rssi(const char *ifname, uint8_t *client_addr){ +int get_rssi(const char *ifname, uint8_t *client_addr) { int i, len; char buf[IWINFO_BUFSIZE]; @@ -116,23 +110,19 @@ int get_rssi(const char *ifname, uint8_t *client_addr){ iw = iwinfo_backend(ifname); - if (iw->assoclist(ifname, buf, &len)) - { + if (iw->assoclist(ifname, buf, &len)) { printf("No information available\n"); return INT_MIN; - } - else if (len <= 0) - { + } else if (len <= 0) { printf("No station connected\n"); return INT_MIN; } - for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) - { + 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->signal; + if (mac_is_equal(client_addr, e->mac)) + return e->signal; } return INT_MIN; diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 9d28ec2..415eadc 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -138,20 +138,18 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir); static int ubus_get_clients(); int hostapd_array_check_id(uint32_t id); + void hostapd_array_insert(uint32_t id); + void hostapd_array_delete(uint32_t id); -void add_client_update_timer(time_t time) -{ +void add_client_update_timer(time_t time) { uloop_timeout_set(&client_timer, time); } -int hostapd_array_check_id(uint32_t id) -{ - for(int i = 0; i <= hostapd_sock_last; i++) - { - if(hostapd_sock_arr[i] == id) - { +int hostapd_array_check_id(uint32_t id) { + for (int i = 0; i <= hostapd_sock_last; i++) { + if (hostapd_sock_arr[i] == id) { return 1; } } @@ -159,21 +157,18 @@ int hostapd_array_check_id(uint32_t id) } -void hostapd_array_insert(uint32_t id) -{ - if(hostapd_sock_last < MAX_HOSTAPD_SOCKETS) { +void hostapd_array_insert(uint32_t id) { + if (hostapd_sock_last < MAX_HOSTAPD_SOCKETS) { hostapd_sock_last++; hostapd_sock_arr[hostapd_sock_last] = id; } - for(int i = 0; i <= hostapd_sock_last; i++) - { - printf("%d: %d\n",i,hostapd_sock_arr[i]); + for (int i = 0; i <= hostapd_sock_last; i++) { + printf("%d: %d\n", i, hostapd_sock_arr[i]); } } -void hostapd_array_delete(uint32_t id) -{ +void hostapd_array_delete(uint32_t id) { int i = 0; int found_in_array = 0; @@ -181,9 +176,8 @@ void hostapd_array_delete(uint32_t id) return; } - for(i = 0; i <= hostapd_sock_last; i++) - { - if(hostapd_sock_arr[i] == id) { + for (i = 0; i <= hostapd_sock_last; i++) { + if (hostapd_sock_arr[i] == id) { found_in_array = 1; break; } @@ -217,8 +211,7 @@ static int decide_function(probe_entry *prob_req) { return 0; } - if(better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) - { + if (better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) { return 0; } @@ -309,8 +302,7 @@ static int handle_auth_req(struct blob_attr *msg) { print_probe_entry(tmp); // block if entry was not already found in probe database - if(!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr))) - { + if (!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr))) { printf("DENY AUTH!\n"); return UBUS_STATUS_UNKNOWN_ERROR; } @@ -351,8 +343,7 @@ static int handle_probe_req(struct blob_attr *msg) { // deny access - if(!dawn_metric.eval_probe_req) - { + if (!dawn_metric.eval_probe_req) { return 0; } @@ -390,8 +381,7 @@ static int add_subscriber(char *name) { return -1; } - if(hostapd_array_check_id(id)) - { + if (hostapd_array_check_id(id)) { return 0; } @@ -406,8 +396,7 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { DIR *dirp; struct dirent *entry; - if(ctx == NULL) - { + if (ctx == NULL) { return 0; } @@ -429,8 +418,7 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { static int subscribe_to_hostapd(char *hostapd_dir) { - if(ctx == NULL) - { + if (ctx == NULL) { return 0; } @@ -583,11 +571,9 @@ int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) { ap_entry.vht = blobmsg_get_u8(tb[CLIENT_TABLE_VHT]); ap_entry.channel_utilization = blobmsg_get_u32(tb[CLIENT_TABLE_CHAN_UTIL]); - if(tb[CLIENT_TABLE_NUM_STA]) - { + if (tb[CLIENT_TABLE_NUM_STA]) { ap_entry.station_count = blobmsg_get_u32(tb[CLIENT_TABLE_NUM_STA]); - } else - { + } else { ap_entry.station_count = 0; } @@ -615,8 +601,7 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ } static int ubus_get_clients() { - for(int i = 0; i <= hostapd_sock_last; i++) - { + for (int i = 0; i <= hostapd_sock_last; i++) { int timeout = 1; ubus_invoke(ctx_clients, hostapd_sock_arr[i], "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000); } @@ -651,8 +636,7 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint blobmsg_add_u8(&b, "deauth", deauth); blobmsg_add_u32(&b, "ban_time", ban_time); - for(int i = 0; i <= hostapd_sock_last; i++) - { + for (int i = 0; i <= hostapd_sock_last; i++) { int timeout = 1; ubus_invoke(ctx_clients, hostapd_sock_arr[i], "del_client", b.head, NULL, NULL, timeout * 1000); } From 7e46afec1c6d5ddb6faae05a490700292e4e54b1 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 21 Dec 2017 22:45:49 +0100 Subject: [PATCH 119/174] update config file --- files/dawn.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index bcd4a52..87edacb 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -23,8 +23,8 @@ config settings metric option vht_support '100' option no_ht_support '0' option no_vht_support '0' - option rssi '10' - option low_rssi '-500' + option rssi '0' + option low_rssi '0' option freq '100' option chan_util '0' option max_chan_util '0' From 8eb7d68e65ca71855f452c6559e4147c7437b36d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 10:56:03 +0100 Subject: [PATCH 120/174] use uci context --- files/dawn.config | 10 +- files/dawn.init | 43 +---- src/crypto/crypto.c | 2 +- src/include/crypto.h | 2 +- src/include/datastorage.h | 11 +- src/include/dawn_uci.h | 10 ++ src/include/networksocket.h | 2 +- src/include/ubus.h | 4 +- src/main.c | 70 ++------ src/network/networksocket.c | 4 +- src/utils/dawn_uci.c | 337 ++++++++++++++---------------------- src/utils/ubus.c | 8 +- 12 files changed, 183 insertions(+), 320 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 87edacb..4009ec7 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,24 +1,24 @@ -config settings network +config network option broadcast_ip '225.0.0.37' option broadcast_port '1025' option multicast '1' option shared_key 'Niiiiiiiiiiiiiik' option iv 'Niiiiiiiiiiiiiik' -config settings ordering +config ordering option sort_order 'csfb' -config settings hostapd +config hostapd option hostapd_dir '/var/run/hostapd' -config settings times +config times option update_client '10' option remove_client '120' option remove_probe '120' option remove_ap '460' option update_hostapd '10' -config settings metric +config metric option ht_support '10' option vht_support '100' option no_ht_support '0' diff --git a/files/dawn.init b/files/dawn.init index 8e9a39c..8e83253 100755 --- a/files/dawn.init +++ b/files/dawn.init @@ -11,51 +11,10 @@ NAME=dawn start_service() { echo "Starting Service..." - - local broadcast_ip - local broadcast_port - local sort_order - local hostapd_dir - local shared_key - local iv - - config_load "${NAME}" - config_get broadcast_ip network broadcast_ip - config_get broadcast_port network broadcast_port - config_get shared_key network shared_key - config_get iv network iv - - config_get sort_order ordering sort_order - config_get hostapd_dir hostapd hostapd_dir - - config_get multicast network multicast - procd_open_instance - echo "$PROG -p $broadcast_port -i $broadcast_ip -o $sort_order" - procd_set_param command "$PROG" - procd_append_param command -p "${broadcast_port}" - procd_append_param command -i "${broadcast_ip}" - procd_append_param command -o "${sort_order}" - procd_append_param command -h "${hostapd_dir}" - procd_append_param command -k "${shared_key}" - procd_append_param command -v "${iv}" - - if [ "${multicast}" -gt 0 ]; then - procd_append_param command -m - fi - + procd_set_param command $PROG procd_set_param stdout 1 procd_set_param stderr 1 - - echo "${command}" - - # procd_set_param respawn - - echo "Starting mdns" - procd_add_mdns "dawn" "udp" "${broadcast_port}" "daemon=dawn" "colour=fuschia" - - echo "MDNS Startet" - procd_close_instance echo "Dawn instance started!" } \ No newline at end of file diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c index 00c0832..50419d0 100644 --- a/src/crypto/crypto.c +++ b/src/crypto/crypto.c @@ -25,7 +25,7 @@ void gcrypt_init() { } } -void gcrypt_set_key_and_iv(char *key, char *iv) { +void gcrypt_set_key_and_iv(const char *key, const char *iv) { size_t keylen = gcry_cipher_get_algo_keylen(GCRY_CIPHER); size_t blklen = gcry_cipher_get_algo_blklen(GCRY_CIPHER); diff --git a/src/include/crypto.h b/src/include/crypto.h index 8124b2d..fd80314 100644 --- a/src/include/crypto.h +++ b/src/include/crypto.h @@ -9,7 +9,7 @@ char *unbase_64(unsigned char *input, int length); void gcrypt_init(); -void gcrypt_set_key_and_iv(char *key, char *iv); +void gcrypt_set_key_and_iv(const char *key, const char *iv); //char *gcrypt_encrypt_msg(char *msg, size_t msg_length); char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length); diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 2c1c65e..9705a27 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -45,6 +45,15 @@ struct time_config_s { time_t update_hostapd; }; +struct network_config_s { + const char* broadcast_ip; + int broadcast_port; + const char* multicast; + const char* shared_key; + const char* iv; + int bool_multicast; +}; + struct time_config_s timeout_config; // ---------------- Global variables ---------------- @@ -173,7 +182,7 @@ ap ap_array_get_ap(uint8_t bssid_addr[]); #define TIME_THRESHOLD 120 // every minute // ---------------- Global variables ---------------- -char sort_string[SORT_NUM]; +char* sort_string; // ---------------- Functions ------------------- int mac_is_equal(uint8_t addr1[], uint8_t addr2[]); diff --git a/src/include/dawn_uci.h b/src/include/dawn_uci.h index b2ee0cf..ed65d52 100644 --- a/src/include/dawn_uci.h +++ b/src/include/dawn_uci.h @@ -5,4 +5,14 @@ struct probe_metric_s uci_get_dawn_metric(); struct time_config_s uci_get_time_config(); +struct network_config_s uci_get_dawn_network(); + +const char* uci_get_dawn_hostapd_dir(); + +const char* uci_get_dawn_sort_order(); + +int uci_init(); + +int uci_clear(); + #endif //DAWN_UCI_H_H diff --git a/src/include/networksocket.h b/src/include/networksocket.h index 4e11724..4ab5a23 100644 --- a/src/include/networksocket.h +++ b/src/include/networksocket.h @@ -5,7 +5,7 @@ pthread_mutex_t send_mutex; -int init_socket_runopts(char *_ip, char *_port, int _multicast_socket); +int init_socket_runopts(const char *_ip, int _port, int _multicast_socket); int send_string(char *msg); diff --git a/src/include/ubus.h b/src/include/ubus.h index 2f1d190..5c169fc 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -8,7 +8,7 @@ #define MIN_PROBE_REQ 2 // TODO: Parse from config file... -int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir); +int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir); int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req); @@ -24,7 +24,7 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint void *update_clients_thread(void *arg); -char *hostapd_dir_glob; +const char *hostapd_dir_glob; int ubus_call_umdns(); diff --git a/src/main.c b/src/main.c index bc24151..84294d8 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ #include "networksocket.h" #include "ubus.h" #include "dawn_uci.h" +#include "dawn_uci.h" #include "crypto.h" #define BUFSIZE 17 @@ -22,6 +23,7 @@ struct sigaction newSigAction; void daemon_shutdown() { // kill threads close_socket(); + uci_clear(); printf("Cancelling Threads!\n"); uloop_cancelled = true; @@ -52,74 +54,32 @@ int main(int argc, char **argv) { //free_counter = 0; const char *ubus_socket = NULL; - int ch; - - char opt_broadcast_ip[BUFSIZE]; - char opt_broadcast_port[BUFSIZE]; - char opt_hostapd_dir[BUFSIZE_DIR]; - - char shared_key[BUFSIZE_DIR]; - char iv[BUFSIZE_DIR]; - int multicast = 0; - - while ((ch = getopt(argc, argv, "cs:p:i:b:o:h:i:k:v:m")) != -1) { - switch (ch) { - case 's': - ubus_socket = optarg; - break; - case 'p': - snprintf(opt_broadcast_port, BUFSIZE, "%s", optarg); - printf("broadcast port: %s\n", opt_broadcast_port); - break; - case 'i': - snprintf(opt_broadcast_ip, BUFSIZE, "%s", optarg); - printf("broadcast ip: %s\n", opt_broadcast_ip); - break; - case 'o': - snprintf(sort_string, SORT_NUM, "%s", optarg); - printf("sort string: %s\n", sort_string); - break; - case 'h': - snprintf(opt_hostapd_dir, BUFSIZE_DIR, "%s", optarg); - printf("hostapd dir: %s\n", opt_hostapd_dir); - hostapd_dir_glob = optarg; - break; - case 'k': - snprintf(shared_key, BUFSIZE_DIR, "%s", optarg); - printf("Key: %s\n", shared_key); - break; - case 'v': - snprintf(iv, BUFSIZE_DIR, "%s", optarg); - printf("IV: %s\n", iv); - break; - case 'm': - multicast = 1; - break; - default: - break; - } - } + // int ch; argc -= optind; argv += optind; - /* Set up a signal handler */ newSigAction.sa_handler = signal_handler; sigemptyset(&newSigAction.sa_mask); newSigAction.sa_flags = 0; - /* Signals to handle */ - sigaction(SIGHUP, &newSigAction, NULL); /* catch hangup signal */ - sigaction(SIGTERM, &newSigAction, NULL); /* catch term signal */ - sigaction(SIGINT, &newSigAction, NULL); /* catch interrupt signal */ + sigaction(SIGHUP, &newSigAction, NULL); + sigaction(SIGTERM, &newSigAction, NULL); + sigaction(SIGINT, &newSigAction, NULL); + uci_init(); + struct network_config_s net_config = uci_get_dawn_network(); + printf("Broadcst bla: %s\n", net_config.broadcast_ip); gcrypt_init(); - gcrypt_set_key_and_iv(shared_key, iv); + gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); struct time_config_s time_config = uci_get_time_config(); timeout_config = time_config; // TODO: Refactor... + hostapd_dir_glob = uci_get_dawn_hostapd_dir(); + sort_string = (char*) uci_get_dawn_sort_order(); + if (pthread_mutex_init(&list_mutex, NULL) != 0) { printf("\n mutex init failed\n"); return 1; @@ -140,9 +100,9 @@ int main(int argc, char **argv) { return 1; } - init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, multicast); + init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast); - dawn_init_ubus(ubus_socket, opt_hostapd_dir); + dawn_init_ubus(ubus_socket, hostapd_dir_glob); return 0; } \ No newline at end of file diff --git a/src/network/networksocket.c b/src/network/networksocket.c index a4a975e..4833431 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -35,9 +35,9 @@ void *receive_msg(void *args); void *receive_msg_enc(void *args); -int init_socket_runopts(char *_ip, char *_port, int _multicast_socket) { +int init_socket_runopts(const char *_ip, int _port, int _multicast_socket) { - port = atoi(_port); + port = _port; ip = _ip; multicast_socket = _multicast_socket; diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 150e995..71cdde3 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -4,76 +4,38 @@ #include "dawn_uci.h" -/* -dawn.metric.ht_support -dawn.metric.vht_support' -dawn.metric.rssi -dawn.metric.freq +static struct uci_context *uci_ctx; +static struct uci_package *uci_pkg; - */ - -/* - config settings times - option update_client '50' - option remove_client '120' - option remove_probe '120' - */ +// why is this not included in uci lib...?! +// fund here: https://github.com/br101/pingcheck/blob/master/uci.c +static int uci_lookup_option_int(struct uci_context *uci, struct uci_section *s, + const char *name) +{ + const char* str = uci_lookup_option_string(uci, s, name); + return str == NULL ? -1 : atoi(str); +} struct time_config_s uci_get_time_config() { struct time_config_s ret; - struct uci_context *c; - struct uci_ptr ptr; + printf("Loading Times!"); - c = uci_alloc_context(); + struct uci_element *e; + uci_foreach_element(&uci_pkg->sections, e) { + struct uci_section *s = uci_to_section(e); - printf("Loading TImes!"); - - - char tmp_update_client[] = "dawn.times.update_client"; - if (uci_lookup_ptr(c, &ptr, tmp_update_client, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; + if (strcmp(s->type, "times") == 0) + { + ret.update_client = uci_lookup_option_int(uci_ctx, s, "update_client"); + ret.remove_client = uci_lookup_option_int(uci_ctx, s, "remove_client"); + ret.remove_probe = uci_lookup_option_int(uci_ctx, s, "remove_probe"); + ret.update_hostapd = uci_lookup_option_int(uci_ctx, s, "update_hostapd"); + ret.remove_ap = uci_lookup_option_int(uci_ctx, s, "remove_ap"); + return ret; + } } - if (ptr.o->type == UCI_TYPE_STRING) - ret.update_client = atoi(ptr.o->v.string); - - char tmp_remove_client[] = "dawn.times.remove_client"; - if (uci_lookup_ptr(c, &ptr, tmp_remove_client, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.remove_client = atoi(ptr.o->v.string); - - char tmp_remove_probe[] = "dawn.times.remove_probe"; - if (uci_lookup_ptr(c, &ptr, tmp_remove_probe, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.remove_probe = atoi(ptr.o->v.string); - - char tmp_update_hostapd[] = "dawn.times.update_hostapd"; - if (uci_lookup_ptr(c, &ptr, tmp_update_hostapd, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.update_hostapd = atoi(ptr.o->v.string); - - char tmp_remove_ap[] = "dawn.times.remove_ap"; - if (uci_lookup_ptr(c, &ptr, tmp_remove_ap, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.remove_ap = atoi(ptr.o->v.string); - - printf("Times: %lu, %lu, %lu %lu\n", ret.update_client, ret.remove_client, ret.remove_probe, ret.update_hostapd); - - uci_free_context(c); return ret; } @@ -81,153 +43,116 @@ struct time_config_s uci_get_time_config() { struct probe_metric_s uci_get_dawn_metric() { struct probe_metric_s ret; - struct uci_context *c; - struct uci_ptr ptr; + struct uci_element *e; + uci_foreach_element(&uci_pkg->sections, e) { + struct uci_section *s = uci_to_section(e); - c = uci_alloc_context(); - - char tmp_ht_support[] = "dawn.metric.ht_support"; - if (uci_lookup_ptr(c, &ptr, tmp_ht_support, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; + if (strcmp(s->type, "metric") == 0) + { + ret.ht_support = uci_lookup_option_int(uci_ctx, s, "ht_support"); + ret.vht_support = uci_lookup_option_int(uci_ctx, s, "vht_support"); + ret.no_ht_support = uci_lookup_option_int(uci_ctx, s, "no_ht_support"); + ret.no_vht_support = uci_lookup_option_int(uci_ctx, s, "no_vht_support"); + ret.rssi = uci_lookup_option_int(uci_ctx, s, "rssi"); + ret.freq = uci_lookup_option_int(uci_ctx, s, "freq"); + ret.rssi_val = uci_lookup_option_int(uci_ctx, s, "rssi_val"); + ret.chan_util = uci_lookup_option_int(uci_ctx, s, "chan_util"); + ret.max_chan_util = uci_lookup_option_int(uci_ctx, s, "max_chan_util"); + ret.chan_util_val = uci_lookup_option_int(uci_ctx, s, "chan_util_val"); + ret.max_chan_util_val = uci_lookup_option_int(uci_ctx, s, "max_chan_util_val"); + ret.min_probe_count = uci_lookup_option_int(uci_ctx, s, "min_probe_count"); + ret.low_rssi = uci_lookup_option_int(uci_ctx, s, "low_rssi"); + ret.low_rssi_val = uci_lookup_option_int(uci_ctx, s, "low_rssi_val"); + ret.bandwith_threshold = uci_lookup_option_int(uci_ctx, s, "bandwith_threshold"); + ret.use_station_count = uci_lookup_option_int(uci_ctx, s, "use_station_count"); + ret.eval_probe_req = uci_lookup_option_int(uci_ctx, s, "eval_probe_req"); + return ret; + } } - if (ptr.o->type == UCI_TYPE_STRING) - ret.ht_support = atoi(ptr.o->v.string); - - char tmp_vht_support[] = "dawn.metric.vht_support"; - if (uci_lookup_ptr(c, &ptr, tmp_vht_support, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.vht_support = atoi(ptr.o->v.string); - - char tmp_no_ht_support[] = "dawn.metric.no_ht_support"; - if (uci_lookup_ptr(c, &ptr, tmp_no_ht_support, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.no_ht_support = atoi(ptr.o->v.string); - - char tmp_no_vht_support[] = "dawn.metric.no_vht_support"; - if (uci_lookup_ptr(c, &ptr, tmp_no_vht_support, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.no_vht_support = atoi(ptr.o->v.string); - - char tmp_rssi[] = "dawn.metric.rssi"; - if (uci_lookup_ptr(c, &ptr, tmp_rssi, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.rssi = atoi(ptr.o->v.string); - - char tmp_freq[] = "dawn.metric.freq"; - if (uci_lookup_ptr(c, &ptr, tmp_freq, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.freq = atoi(ptr.o->v.string); - - char tmp_util[] = "dawn.metric.chan_util"; - if (uci_lookup_ptr(c, &ptr, tmp_util, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.chan_util = atoi(ptr.o->v.string); - - char tmp_rssi_val[] = "dawn.metric.rssi_val"; - if (uci_lookup_ptr(c, &ptr, tmp_rssi_val, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.rssi_val = atoi(ptr.o->v.string); - - char tmp_max_chan_util[] = "dawn.metric.max_chan_util"; - if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.max_chan_util = atoi(ptr.o->v.string); - - char tmp_chan_util_val[] = "dawn.metric.chan_util_val"; - if (uci_lookup_ptr(c, &ptr, tmp_chan_util_val, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.chan_util_val = atoi(ptr.o->v.string); - - - char tmp_max_chan_util_val[] = "dawn.metric.max_chan_util_val"; - if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util_val, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.max_chan_util_val = atoi(ptr.o->v.string); - - - printf("Try to load min_probe_count\n"); - char tmp_min_probe_count[] = "dawn.metric.min_probe_count"; - if (uci_lookup_ptr(c, &ptr, tmp_min_probe_count, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.min_probe_count = atoi(ptr.o->v.string); - - char tmp_low_rssi[] = "dawn.metric.low_rssi"; - if (uci_lookup_ptr(c, &ptr, tmp_low_rssi, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.low_rssi = atoi(ptr.o->v.string); - - char tmp_low_rssi_val[] = "dawn.metric.low_rssi_val"; - if (uci_lookup_ptr(c, &ptr, tmp_low_rssi_val, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.low_rssi_val = atoi(ptr.o->v.string); - - char tmp_bandwith_threshold[] = "dawn.metric.bandwith_threshold"; - if (uci_lookup_ptr(c, &ptr, tmp_bandwith_threshold, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.bandwith_threshold = atoi(ptr.o->v.string); - - char tmp_use_station_count[] = "dawn.metric.use_station_count"; - if (uci_lookup_ptr(c, &ptr, tmp_use_station_count, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.use_station_count = atoi(ptr.o->v.string); - - char tmp_eval_probe_req[] = "dawn.metric.eval_probe_req"; - if (uci_lookup_ptr(c, &ptr, tmp_eval_probe_req, 1) != UCI_OK) { - uci_perror(c, "uci_get_daw_metric Error"); - return ret; - } - if (ptr.o->type == UCI_TYPE_STRING) - ret.eval_probe_req = atoi(ptr.o->v.string); - - printf("Loaded metric: %d\n", ret.min_probe_count); - - uci_free_context(c); return ret; +} + +struct network_config_s uci_get_dawn_network() { + struct network_config_s ret; + + struct uci_element *e; + uci_foreach_element(&uci_pkg->sections, e) { + struct uci_section *s = uci_to_section(e); + + if (strcmp(s->type, "network") == 0) + { + printf("Fronund network entry!\n"); + ret.broadcast_ip = uci_lookup_option_string(uci_ctx, s, "broadcast_ip"); + printf("BROADCAST: %s\n", ret.broadcast_ip); + ret.broadcast_port = uci_lookup_option_int(uci_ctx, s, "broadcast_port"); + ret.bool_multicast = uci_lookup_option_int(uci_ctx, s, "multicast"); + printf("multicast: %s\n", ret.broadcast_ip); + ret.shared_key = uci_lookup_option_string(uci_ctx, s, "shared_key"); + ret.iv = uci_lookup_option_string(uci_ctx, s, "iv"); + return ret; + } + } + + return ret; +} +const char* uci_get_dawn_hostapd_dir() { + struct uci_element *e; + uci_foreach_element(&uci_pkg->sections, e) + { + struct uci_section *s = uci_to_section(e); + + if (strcmp(s->type, "hostapd") == 0) { + return uci_lookup_option_string(uci_ctx, s, "hostapd_dir"); + } + } + return NULL; +} + +const char* uci_get_dawn_sort_order() { + struct uci_element *e; + uci_foreach_element(&uci_pkg->sections, e) { + struct uci_section *s = uci_to_section(e); + + if (strcmp(s->type, "ordering") == 0) + { + return uci_lookup_option_string(uci_ctx, s, "sort_order"); + } + } + return NULL; +} + +int uci_init() +{ + struct uci_context *ctx = uci_ctx; + + if (!ctx) { + ctx = uci_alloc_context(); + uci_ctx = ctx; + + ctx->flags &= ~UCI_FLAG_STRICT; + } else { + // shouldn't happen? + uci_pkg = uci_lookup_package(ctx, "dawn"); + if (uci_pkg) + uci_unload(ctx, uci_pkg); + } + + if (uci_load(ctx, "dawn", &uci_pkg)) + return -1; + + return 1; +} + +int uci_clear() +{ + if(uci_pkg != NULL) + { + uci_unload(uci_ctx, uci_pkg); + } + if(uci_ctx != NULL) + { + uci_free_context(uci_ctx); + } + return 1; } \ No newline at end of file diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 415eadc..28db0e5 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -133,7 +133,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, static int add_subscriber(char *name); -static int subscribe_to_hostapd_interfaces(char *hostapd_dir); +static int subscribe_to_hostapd_interfaces(const char *hostapd_dir); static int ubus_get_clients(); @@ -392,7 +392,7 @@ static int add_subscriber(char *name) { return 0; } -static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { +static int subscribe_to_hostapd_interfaces(const char *hostapd_dir) { DIR *dirp; struct dirent *entry; @@ -416,7 +416,7 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { return 0; } -static int subscribe_to_hostapd(char *hostapd_dir) { +static int subscribe_to_hostapd(const char *hostapd_dir) { if (ctx == NULL) { return 0; @@ -440,7 +440,7 @@ static int subscribe_to_hostapd(char *hostapd_dir) { return 0; } -int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { +int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) { uloop_init(); signal(SIGPIPE, SIG_IGN); From cfde7b7c97af4964d2e46948f2cad372700da121 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 16:21:00 +0100 Subject: [PATCH 121/174] add get_hearing_map call --- src/include/datastorage.h | 4 ++++ src/include/ubus.h | 4 ++-- src/main.c | 2 +- src/storage/datastorage.c | 35 +++++++++++++++++++++++++++++++++++ src/utils/ubus.c | 26 +++++++++++++++++++++----- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 492bce6..efe3580 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -8,6 +8,8 @@ #include #include #include +#include + #ifndef ETH_ALEN #define ETH_ALEN 6 @@ -189,6 +191,8 @@ void print_ap_array(); ap ap_array_get_ap(uint8_t bssid_addr[]); +int build_hearing_map_sort_client(struct blob_buf *b); + /* Utils */ // ---------------- Defines ------------------- diff --git a/src/include/ubus.h b/src/include/ubus.h index 5c169fc..7788cb0 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -6,8 +6,6 @@ #include "datastorage.h" -#define MIN_PROBE_REQ 2 // TODO: Parse from config file... - int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir); int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req); @@ -34,4 +32,6 @@ void update_hostapd_sockets(struct uloop_timeout *t); void add_client_update_timer(time_t time); +void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr); + #endif diff --git a/src/main.c b/src/main.c index 0942347..694e075 100644 --- a/src/main.c +++ b/src/main.c @@ -102,7 +102,7 @@ int main(int argc, char **argv) { init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast); - insert_macs_from_file(); + //insert_macs_from_file(); dawn_init_ubus(ubus_socket, hostapd_dir_glob); return 0; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index b35c6ac..7c8c0ff 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -68,6 +68,41 @@ struct uloop_timeout ap_timeout = { .cb = remove_ap_array_cb }; +int build_hearing_map_sort_client(struct blob_buf *b) +{ + pthread_mutex_lock(&probe_array_mutex); + + void *client_list, *ap_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)) + { + 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); + blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k])); + blobmsg_close_table(b, ap_list); + } + blobmsg_close_table(b, client_list); + } + pthread_mutex_unlock(&probe_array_mutex); + return 0; +} + int eval_probe_metric(struct probe_entry_s probe_entry) { int score = 0; diff --git a/src/utils/ubus.c b/src/utils/ubus.c index d12be7b..a69fef7 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -142,7 +142,11 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg); -int hostapd_array_check_id(uint32_t id); +static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); + + int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); @@ -199,8 +203,7 @@ void hostapd_array_delete(uint32_t id) { } -static void -blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) { +void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) { char *s; s = blobmsg_alloc_string_buffer(buf, name, 20); @@ -483,6 +486,7 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) { uloop_run(); + close_socket(); ubus_free(ctx); @@ -715,6 +719,9 @@ static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = { static const struct ubus_method dawn_methods[] = { UBUS_METHOD("add_mac", add_mac, add_del_policy), + UBUS_METHOD_NOARG("get_hearing_map", get_hearing_map) + //UBUS_METHOD_NOARG("get_aps"); + //UBUS_METHOD_NOARG("get_clients"); }; static struct ubus_object_type dawn_object_type = @@ -727,8 +734,7 @@ static struct ubus_object dawn_object = { .n_methods = ARRAY_SIZE(dawn_methods), }; -static int -add_mac(struct ubus_context *ctx, struct ubus_object *obj, +static int add_mac(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { @@ -749,6 +755,15 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { + + build_hearing_map_sort_client(&b); + ubus_send_reply(ctx, req, b.head); + return 0; +} + static void ubus_add_oject() { int ret; @@ -756,6 +771,7 @@ static void ubus_add_oject() ret = ubus_add_object(ctx, &dawn_object); if (ret) fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret)); + printf("ADDED UBUS OBJECT!!!\n"); /*ret = ubus_register_subscriber(ctx, &test_event); if (ret) From 9eddd6323391ddddf64b8c54d1687152560de9ff Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 17:18:49 +0100 Subject: [PATCH 122/174] cleanup main --- src/main.c | 77 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/src/main.c b/src/main.c index 694e075..5e73b5f 100644 --- a/src/main.c +++ b/src/main.c @@ -8,19 +8,16 @@ #include "networksocket.h" #include "ubus.h" #include "dawn_uci.h" -#include "dawn_uci.h" #include "crypto.h" -#define BUFSIZE 17 -#define BUFSIZE_DIR 256 - void daemon_shutdown(); void signal_handler(int sig); -struct sigaction newSigAction; +struct sigaction signal_action; void daemon_shutdown() { + // kill threads close_socket(); uci_clear(); @@ -36,50 +33,24 @@ void daemon_shutdown() { } void signal_handler(int sig) { - printf("SOME SIGNAL RECEIVED!\n"); switch (sig) { case SIGHUP: + daemon_shutdown(); break; case SIGINT: + daemon_shutdown(); + break; case SIGTERM: daemon_shutdown(); exit(EXIT_SUCCESS); - break; default: + daemon_shutdown(); break; } } -int main(int argc, char **argv) { - //free_counter = 0; - - const char *ubus_socket = NULL; - // int ch; - - argc -= optind; - argv += optind; - - newSigAction.sa_handler = signal_handler; - sigemptyset(&newSigAction.sa_mask); - newSigAction.sa_flags = 0; - - sigaction(SIGHUP, &newSigAction, NULL); - sigaction(SIGTERM, &newSigAction, NULL); - sigaction(SIGINT, &newSigAction, NULL); - - uci_init(); - struct network_config_s net_config = uci_get_dawn_network(); - printf("Broadcst bla: %s\n", net_config.broadcast_ip); - - gcrypt_init(); - gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); - - struct time_config_s time_config = uci_get_time_config(); - timeout_config = time_config; // TODO: Refactor... - - hostapd_dir_glob = uci_get_dawn_hostapd_dir(); - sort_string = (char*) uci_get_dawn_sort_order(); - +int init_mutex() +{ if (pthread_mutex_init(&list_mutex, NULL) != 0) { printf("\n mutex init failed\n"); return 1; @@ -99,6 +70,38 @@ int main(int argc, char **argv) { printf("\n mutex init failed\n"); return 1; } + return 0; +} + +int main(int argc, char **argv) { + + const char *ubus_socket = NULL; + + argc -= optind; + argv += optind; + + // connect signals + signal_action.sa_handler = signal_handler; + sigemptyset(&signal_action.sa_mask); + signal_action.sa_flags = 0; + sigaction(SIGHUP, &signal_action, NULL); + sigaction(SIGTERM, &signal_action, NULL); + sigaction(SIGINT, &signal_action, NULL); + + uci_init(); + struct network_config_s net_config = uci_get_dawn_network(); + printf("Broadcst bla: %s\n", net_config.broadcast_ip); + + gcrypt_init(); + gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); + + struct time_config_s time_config = uci_get_time_config(); + timeout_config = time_config; // TODO: Refactor... + + hostapd_dir_glob = uci_get_dawn_hostapd_dir(); + sort_string = (char*) uci_get_dawn_sort_order(); + + init_mutex(); init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast); From 389be8fca12c33ab8a5595ba793c51e79c12cf42 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 17:25:18 +0100 Subject: [PATCH 123/174] fix maclist --- src/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 5e73b5f..4252b4f 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,8 @@ void daemon_shutdown(); void signal_handler(int sig); +int init_mutex(); + struct sigaction signal_action; void daemon_shutdown() { @@ -105,7 +107,7 @@ int main(int argc, char **argv) { init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast); - //insert_macs_from_file(); + insert_macs_from_file(); dawn_init_ubus(ubus_socket, hostapd_dir_glob); return 0; From 590de3617f85d3e98d106144e048b6b30928b76a Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 17:37:36 +0100 Subject: [PATCH 124/174] fix maclist --- src/storage/datastorage.c | 14 +++++++++++++- src/utils/ubus.c | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 7c8c0ff..5ec49f5 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -94,6 +94,17 @@ int build_hearing_map_sort_client(struct blob_buf *b) 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); } @@ -747,13 +758,14 @@ int insert_to_maclist(uint8_t mac[]) { if(mac_in_maclist(mac)) { - return 0; + return -1; } mac_list_entry_last++; for (int i = 0; i < ETH_ALEN; ++i) { mac_list[mac_list_entry_last][i] = mac[i]; } + return 0; } diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a69fef7..30c99f4 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -749,8 +749,10 @@ static int add_mac(struct ubus_context *ctx, struct ubus_object *obj, if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr)) return UBUS_STATUS_INVALID_ARGUMENT; - insert_to_maclist(addr); - write_mac_to_file("/etc/dawn/mac_list", addr); + if(insert_to_maclist(addr) == 0) + { + write_mac_to_file("/etc/dawn/mac_list", addr); + } return 0; } From c259c29d1d0bb6e75ade954d179027489494aa1b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 18:08:05 +0100 Subject: [PATCH 125/174] fix client array --- src/storage/datastorage.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 5ec49f5..120d4d2 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -336,28 +336,10 @@ int client_array_go_next_help(char sort_order[], int i, client entry, case 'b': return mac_is_greater(entry.bssid_addr, next_entry.bssid_addr) && mac_is_equal(entry.client_addr, next_entry.client_addr); - break; - // client-mac case 'c': - return mac_is_greater(entry.client_addr, next_entry.client_addr); - break; - - // frequency - // mac is 5 ghz or 2.4 ghz? - // case 'f': - // return //entry.freq < next_entry.freq && - // entry.freq < 5000 && - // next_entry.freq >= 5000 && - // //entry.freq < 5 && - // mac_is_equal(entry.client_addr, next_entry.client_addr); - // break; - - // signal strength (RSSI) - //case 's': - // return entry.signal < next_entry.signal && - // mac_is_equal(entry.client_addr, next_entry.client_addr); - // break; + return mac_is_greater(entry.client_addr, next_entry.client_addr) && + mac_is_greater(entry.bssid_addr, next_entry.bssid_addr); default: return 0; From 3a127e990089d622e160bd0a7fd362b5b37f78e5 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 18:15:03 +0100 Subject: [PATCH 126/174] fix client array insert function --- src/storage/datastorage.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 120d4d2..a7e3a3b 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -334,17 +334,15 @@ int client_array_go_next_help(char sort_order[], int i, client entry, switch (sort_order[i]) { // bssid-mac case 'b': - return mac_is_greater(entry.bssid_addr, next_entry.bssid_addr) && - mac_is_equal(entry.client_addr, next_entry.client_addr); + return mac_is_greater(entry.bssid_addr, next_entry.bssid_addr); // client-mac case 'c': return mac_is_greater(entry.client_addr, next_entry.client_addr) && - mac_is_greater(entry.bssid_addr, next_entry.bssid_addr); - + mac_is_equal(entry.bssid_addr, next_entry.bssid_addr); default: - return 0; break; } + return 0; } int client_array_go_next(char sort_order[], int i, client entry, From 1be4ca829c90c80bd425cf937a4ba3aa1a24c837 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 18:26:23 +0100 Subject: [PATCH 127/174] add network overview --- src/include/datastorage.h | 2 ++ src/storage/datastorage.c | 33 +++++++++++++++++++++++++++++++++ src/utils/ubus.c | 19 +++++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index efe3580..da829f7 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -193,6 +193,8 @@ ap ap_array_get_ap(uint8_t bssid_addr[]); int build_hearing_map_sort_client(struct blob_buf *b); +int build_network_overview(struct blob_buf *b); + /* Utils */ // ---------------- Defines ------------------- diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index a7e3a3b..d1fddab 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -114,6 +114,39 @@ int build_hearing_map_sort_client(struct blob_buf *b) return 0; } +int build_network_overview(struct blob_buf *b) +{ + pthread_mutex_lock(&probe_array_mutex); + + void *client_list, *ap_list; + char ap_mac_buf[20]; + char client_mac_buf[20]; + + blob_buf_init(b, 0); + int i; + for (i = 0; i <= client_entry_last; i++) { + int k; + sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr)); + ap_list = blobmsg_open_table(b, ap_mac_buf); + for (k = i; i <= client_entry_last; k++){ + if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) + { + i = k - 1; + break; + } + sprintf(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr)); + client_list = blobmsg_open_table(b, client_mac_buf); + blobmsg_add_u32(b, "freq", client_array[k].freq); + blobmsg_add_u32(b, "ht", client_array[k].ht); + blobmsg_add_u32(b, "vht", client_array[k].vht); + blobmsg_close_table(b, client_list); + } + blobmsg_close_table(b, ap_list); + } + pthread_mutex_unlock(&probe_array_mutex); + return 0; +} + int eval_probe_metric(struct probe_entry_s probe_entry) { int score = 0; diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 30c99f4..17c7d13 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -146,7 +146,11 @@ static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg); - int hostapd_array_check_id(uint32_t id); +static int get_network(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); + +int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); @@ -719,7 +723,8 @@ static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = { static const struct ubus_method dawn_methods[] = { UBUS_METHOD("add_mac", add_mac, add_del_policy), - UBUS_METHOD_NOARG("get_hearing_map", get_hearing_map) + UBUS_METHOD_NOARG("get_hearing_map", get_hearing_map), + UBUS_METHOD_NOARG("get_network", get_network) //UBUS_METHOD_NOARG("get_aps"); //UBUS_METHOD_NOARG("get_clients"); }; @@ -766,6 +771,16 @@ static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, return 0; } + +static int get_network(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { + + build_network_overview(&b); + ubus_send_reply(ctx, req, b.head); + return 0; +} + static void ubus_add_oject() { int ret; From d137ec51177b11a1e68017e8c006fe7f7bdd2731 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 19:07:43 +0100 Subject: [PATCH 128/174] handle deauth correctly --- src/utils/ubus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 6151a53..5645f3d 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -493,6 +493,7 @@ int handle_network_msg(char* msg) parse_to_clients(data_buf.head, 0, 0); } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); + handle_deauth_req(data_buf.head); /* hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); @@ -555,6 +556,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, } else if (strncmp(method, "assoc", 5) == 0) { return handle_assoc_req(msg); } else if (strncmp(method, "deauth", 6) == 0) { + send_blob_attr_via_network(msg, "deauth"); return handle_deauth_req(msg); } return 0; From 3071d84acd38b2a275565781c46d140dbd1d5a6e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 17:39:39 +0100 Subject: [PATCH 129/174] 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 130/174] 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 131/174] 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 132/174] 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 133/174] 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 134/174] 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 135/174] 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 136/174] 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 137/174] 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 138/174] 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 139/174] 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 140/174] 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 141/174] 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 142/174] 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]); } From b0cffbe5e3fa81a04480024fb636cdac11be7589 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 25 Dec 2017 00:27:52 +0100 Subject: [PATCH 143/174] fix probe count --- 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 c7765fc..f21757e 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -240,9 +240,9 @@ 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 (ap_entry_own.station_count - 1) > ap_entry_to_compre.station_count; + return ((int)ap_entry_own.station_count - 1) > (int)ap_entry_to_compre.station_count; } else { - return ap_entry_own.station_count > ap_entry_to_compre.station_count; + return (int)ap_entry_own.station_count > (int)ap_entry_to_compre.station_count; } /* From b36b511a1d16206957d2513b52d949fa4abe6835 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 25 Dec 2017 12:10:44 +0100 Subject: [PATCH 144/174] fix station count compare --- src/storage/datastorage.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index f21757e..c45aa2a 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -239,10 +239,20 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar && mac_is_equal(ap_entry_to_compre.bssid_addr, bssid_addr_to_compare) ) { 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 { - return (int)ap_entry_own.station_count > (int)ap_entry_to_compre.station_count; + + int sta_count_to_compare = ap_entry_to_compre.station_count; + if(is_connected(bssid_addr_to_compare, client_addr)) + { + printf("IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); + sta_count_to_compare--; + } + + return (int)ap_entry_own.station_count > sta_count_to_compare; } /* @@ -325,7 +335,7 @@ 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, NULL, automatic_kick)) { + if (compare_station_count(bssid_addr, probe_array[k].bssid_addr, probe_array[k].client_addr, automatic_kick)) { return 1; } From b79fbb07574acc48edea021857d4b8d691262823 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 26 Dec 2017 10:50:23 +0100 Subject: [PATCH 145/174] sort get network overview ssid --- src/storage/datastorage.c | 58 +++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index c45aa2a..8d44fb1 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -161,30 +161,54 @@ int build_network_overview(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 <= client_entry_last; i++) { - int k; - sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr)); - ap_list = blobmsg_open_table(b, ap_mac_buf); - for (k = i; i <= client_entry_last; k++){ - if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_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(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr)); - client_list = blobmsg_open_table(b, client_mac_buf); - blobmsg_add_u32(b, "freq", client_array[k].freq); - blobmsg_add_u32(b, "ht", client_array[k].ht); - blobmsg_add_u32(b, "vht", client_array[k].vht); - blobmsg_close_table(b, client_list); } - blobmsg_close_table(b, ap_list); + + ssid_list = blobmsg_open_table(b, (char*)ap_array[m].ssid); + + blob_buf_init(b, 0); + int i; + for (i = 0; i <= client_entry_last; i++) { + int k; + sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr)); + ap_list = blobmsg_open_table(b, ap_mac_buf); + for (k = i; i <= client_entry_last; k++){ + ap ap_entry_i = ap_array_get_ap(probe_array[i].bssid_addr); + + if(strcmp((char*)ap_entry_i.ssid, (char*)ap_array[m].ssid) != 0) + { + continue; + } + + if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) + { + i = k - 1; + break; + } + + sprintf(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr)); + client_list = blobmsg_open_table(b, client_mac_buf); + blobmsg_add_u32(b, "freq", client_array[k].freq); + blobmsg_add_u32(b, "ht", client_array[k].ht); + blobmsg_add_u32(b, "vht", client_array[k].vht); + blobmsg_close_table(b, client_list); + } + blobmsg_close_table(b, ap_list); + } + blobmsg_close_table(b, ssid_list); } pthread_mutex_unlock(&probe_array_mutex); return 0; From a128121015b005edc7bacc64e3f94abfced1f503 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 26 Dec 2017 10:54:13 +0100 Subject: [PATCH 146/174] sort get network overview ssid --- src/storage/datastorage.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 8d44fb1..be06846 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -179,26 +179,24 @@ int build_network_overview(struct blob_buf *b) ssid_list = blobmsg_open_table(b, (char*)ap_array[m].ssid); - blob_buf_init(b, 0); int i; for (i = 0; i <= client_entry_last; i++) { + ap ap_entry_i = ap_array_get_ap(client_array[i].bssid_addr); + + if(strcmp((char*)ap_entry_i.ssid, (char*)ap_array[m].ssid) != 0) + { + continue; + } int k; sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr)); ap_list = blobmsg_open_table(b, ap_mac_buf); for (k = i; i <= client_entry_last; k++){ - ap ap_entry_i = ap_array_get_ap(probe_array[i].bssid_addr); - - if(strcmp((char*)ap_entry_i.ssid, (char*)ap_array[m].ssid) != 0) - { - continue; - } - if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) { i = k - 1; break; } - + sprintf(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr)); client_list = blobmsg_open_table(b, client_mac_buf); blobmsg_add_u32(b, "freq", client_array[k].freq); From 8cc3f0b0c5f468916027d5e5ef0ef4b4948b2455 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 26 Dec 2017 14:55:16 +0100 Subject: [PATCH 147/174] bla --- src/storage/datastorage.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index be06846..0fe44d0 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -427,6 +427,9 @@ void kick_clients(uint8_t bssid[], uint32_t id) { } printf("Client is probably NOT in active transmisison. KICK! RxRate is: %f\n", rx_rate); + + // here we should send a messsage to set the probe.count for all aps to the min that there is no delay between switching + del_client_interface(id, client_array[j].client_addr, 5, 1, 1000); client_array_delete(client_array[j]); @@ -606,6 +609,29 @@ probe_entry probe_array_delete(probe_entry entry) { return tmp; } +int probe_array_set_probe_count(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t probe_count) { + + int updated = 0; + + if (probe_entry_last == -1) { + return 0; + } + + + pthread_mutex_lock(&probe_array_mutex); + for (int i = 0; i <= probe_entry_last; i++) { + if (mac_is_equal(bssid_addr, probe_array[i].bssid_addr) && + mac_is_equal(client_addr, probe_array[i].client_addr)) { + probe_array[i].signal = rssi; + updated = 1; + ubus_send_probe_via_network(probe_array[i]); + } + } + pthread_mutex_unlock(&probe_array_mutex); + + return updated; +} + int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t rssi) { int updated = 0; From fbc3659920eb09f1985da6ee169fcb4813237627 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 26 Dec 2017 19:22:31 +0100 Subject: [PATCH 148/174] add set probecount --- src/include/datastorage.h | 2 ++ src/include/ubus.h | 2 ++ src/storage/datastorage.c | 17 ++++++++++------- src/utils/ubus.c | 38 +++++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 58d83c4..d1576c9 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -203,6 +203,8 @@ int build_hearing_map_sort_client(struct blob_buf *b); int build_network_overview(struct blob_buf *b); +int probe_array_set_all_probe_count(uint8_t client_addr[], uint32_t probe_count); + /* Utils */ // ---------------- Defines ------------------- diff --git a/src/include/ubus.h b/src/include/ubus.h index b06c916..b30fe8d 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -40,4 +40,6 @@ int send_blob_attr_via_network(struct blob_attr *msg, char* method); void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr); +int send_set_probe(uint8_t client_addr[]); + #endif diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 0fe44d0..9d1ba64 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -430,6 +430,8 @@ void kick_clients(uint8_t bssid[], uint32_t id) { // here we should send a messsage to set the probe.count for all aps to the min that there is no delay between switching + send_set_probe(client_array[j].client_addr); + del_client_interface(id, client_array[j].client_addr, 5, 1, 1000); client_array_delete(client_array[j]); @@ -609,7 +611,7 @@ probe_entry probe_array_delete(probe_entry entry) { return tmp; } -int probe_array_set_probe_count(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t probe_count) { +int probe_array_set_all_probe_count(uint8_t client_addr[], uint32_t probe_count) { int updated = 0; @@ -617,14 +619,15 @@ int probe_array_set_probe_count(uint8_t bssid_addr[], uint8_t client_addr[], uin return 0; } - pthread_mutex_lock(&probe_array_mutex); for (int i = 0; i <= probe_entry_last; i++) { - if (mac_is_equal(bssid_addr, probe_array[i].bssid_addr) && - mac_is_equal(client_addr, probe_array[i].client_addr)) { - probe_array[i].signal = rssi; - updated = 1; - ubus_send_probe_via_network(probe_array[i]); + if(mac_is_greater(client_addr, probe_array[i].client_addr)) + { + break; + } + + if (mac_is_equal(client_addr, probe_array[i].client_addr)) { + probe_array[i].counter = probe_count; } } pthread_mutex_unlock(&probe_array_mutex); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index d2b198e..4910338 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -181,6 +181,8 @@ static int get_network(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg); +static int handle_set_probe(struct blob_attr *msg); + int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); @@ -425,6 +427,20 @@ static int handle_deauth_req(struct blob_attr *msg) { return 0; } +static int handle_set_probe(struct blob_attr *msg) { + + hostapd_notify_entry notify_req; + parse_to_hostapd_notify(msg, ¬ify_req); + + client client_entry; + memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.client_addr, client_entry.client_addr, sizeof(uint8_t) * ETH_ALEN ); + + probe_array_set_all_probe_count(client_entry.client_addr, dawn_metric.min_probe_count); + + return 0; +} + int handle_network_msg(char* msg) { //printf("HANDLING NETWORK MSG: %s\n", msg); @@ -485,6 +501,12 @@ int handle_network_msg(char* msg) } else if (strncmp(method, "deauth", 5) == 0) { printf("METHOD DEAUTH\n"); handle_deauth_req(data_buf.head); + } else if (strncmp(method, "setprobe", 5) == 0) { + printf("SET PROBE!\n"); + handle_set_probe(data_buf.head); + } + + /* hostapd_notify_entry entry; parse_to_hostapd_notify(data_buf.head, &entry); @@ -496,7 +518,7 @@ int handle_network_msg(char* msg) pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); pthread_mutex_unlock(&client_array_mutex);*/ - } + //} //free(method); //free(data); //printf("HANDLING FINISHED NETWORK MSG!\n"); @@ -889,6 +911,20 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { return 0; } +int send_set_probe(uint8_t client_addr[]) +{ + + printf("SENDING SET PROBE VIA NETWORK!\n"); + + blob_buf_init(&b_probe, 0); + blobmsg_add_macaddr(&b_probe, "bssid", client_addr); + blobmsg_add_macaddr(&b_probe, "address", client_addr); + + send_blob_attr_via_network(b_probe.head, "set_probe"); + + return 0; +} + enum { MAC_ADDR, __ADD_DEL_MAC_MAX From 08f22537f015ec2d3c23b848d83fe51278ad3546 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 26 Dec 2017 20:29:37 +0100 Subject: [PATCH 149/174] fix setprobe --- src/utils/ubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 4910338..7845fc3 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -920,7 +920,7 @@ int send_set_probe(uint8_t client_addr[]) blobmsg_add_macaddr(&b_probe, "bssid", client_addr); blobmsg_add_macaddr(&b_probe, "address", client_addr); - send_blob_attr_via_network(b_probe.head, "set_probe"); + send_blob_attr_via_network(b_probe.head, "setprobe"); return 0; } From e8b43ebbb60452f9768974214ae41a4bc8b7dd7f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 26 Dec 2017 21:58:43 +0100 Subject: [PATCH 150/174] test set function --- src/storage/datastorage.c | 10 +++++----- src/utils/ubus.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 9d1ba64..8ff6693 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -621,13 +621,13 @@ int probe_array_set_all_probe_count(uint8_t client_addr[], uint32_t probe_count) pthread_mutex_lock(&probe_array_mutex); for (int i = 0; i <= probe_entry_last; i++) { - if(mac_is_greater(client_addr, probe_array[i].client_addr)) - { - break; - } - if (mac_is_equal(client_addr, probe_array[i].client_addr)) { + printf("SETTING MAC!!!\n"); probe_array[i].counter = probe_count; + }else if(!mac_is_greater(client_addr, probe_array[i].client_addr)) + { + printf("MAC NOT FOUND!!!\n"); + break; } } pthread_mutex_unlock(&probe_array_mutex); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 7845fc3..0c8fd28 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -415,8 +415,8 @@ static int handle_deauth_req(struct blob_attr *msg) { parse_to_hostapd_notify(msg, ¬ify_req); client client_entry; - memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); - memcpy(client_entry.client_addr, client_entry.client_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN ); pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); @@ -433,8 +433,11 @@ static int handle_set_probe(struct blob_attr *msg) { parse_to_hostapd_notify(msg, ¬ify_req); client client_entry; - memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); - memcpy(client_entry.client_addr, client_entry.client_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN ); + + printf("SETTING CLIENT MACS ENTRY!!!!\n"); + print_client_entry(client_entry); probe_array_set_all_probe_count(client_entry.client_addr, dawn_metric.min_probe_count); @@ -502,7 +505,7 @@ int handle_network_msg(char* msg) printf("METHOD DEAUTH\n"); handle_deauth_req(data_buf.head); } else if (strncmp(method, "setprobe", 5) == 0) { - printf("SET PROBE!\n"); + printf("HANDLING SET PROBE!\n"); handle_set_probe(data_buf.head); } @@ -981,6 +984,24 @@ static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, build_hearing_map_sort_client(&b); ubus_send_reply(ctx, req, b.head); + + int tmp_int_mac[ETH_ALEN]; + uint8_t tmp_mac[ETH_ALEN]; + sscanf("10:0B:A9:6D:33:90", MACSTR, STR2MAC(tmp_int_mac)); + for (int i = 0; i < ETH_ALEN; ++i) + tmp_mac[i] = (uint8_t) tmp_int_mac[i]; + + char mac_buf_target[20]; + sprintf(mac_buf_target, MACSTR, MAC2STR(tmp_mac)); + printf("SETTING PROBE COUNT OF MAC!!! %s\n", mac_buf_target); + + + + printf("SENDING MAP!\n"); + + + send_set_probe(tmp_mac); + return 0; } From 0d5c1bef11886d51f5c26d72280d039621e91814 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 26 Dec 2017 23:46:44 +0100 Subject: [PATCH 151/174] remove debug --- src/storage/datastorage.c | 2 +- src/utils/ubus.c | 21 --------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 8ff6693..e9636e3 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -429,7 +429,7 @@ void kick_clients(uint8_t bssid[], uint32_t id) { // here we should send a messsage to set the probe.count for all aps to the min that there is no delay between switching - + // the hearing map is full... send_set_probe(client_array[j].client_addr); del_client_interface(id, client_array[j].client_addr, 5, 1, 1000); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 0c8fd28..eb3d0b2 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -436,9 +436,6 @@ static int handle_set_probe(struct blob_attr *msg) { memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN ); - printf("SETTING CLIENT MACS ENTRY!!!!\n"); - print_client_entry(client_entry); - probe_array_set_all_probe_count(client_entry.client_addr, dawn_metric.min_probe_count); return 0; @@ -984,24 +981,6 @@ static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, build_hearing_map_sort_client(&b); ubus_send_reply(ctx, req, b.head); - - int tmp_int_mac[ETH_ALEN]; - uint8_t tmp_mac[ETH_ALEN]; - sscanf("10:0B:A9:6D:33:90", MACSTR, STR2MAC(tmp_int_mac)); - for (int i = 0; i < ETH_ALEN; ++i) - tmp_mac[i] = (uint8_t) tmp_int_mac[i]; - - char mac_buf_target[20]; - sprintf(mac_buf_target, MACSTR, MAC2STR(tmp_mac)); - printf("SETTING PROBE COUNT OF MAC!!! %s\n", mac_buf_target); - - - - printf("SENDING MAP!\n"); - - - send_set_probe(tmp_mac); - return 0; } From c7565d30697a866f25e799220129e1a65133256a Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 27 Dec 2017 00:22:25 +0100 Subject: [PATCH 152/174] fix handle deauth function --- src/utils/ubus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index d2b198e..3ff8cbc 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -413,8 +413,8 @@ static int handle_deauth_req(struct blob_attr *msg) { parse_to_hostapd_notify(msg, ¬ify_req); client client_entry; - memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); - memcpy(client_entry.client_addr, client_entry.client_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN ); + memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN ); pthread_mutex_lock(&client_array_mutex); client_array_delete(client_entry); From b9b3efe3504c43a30acf628d6245862ab35aa1f7 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 29 Dec 2017 19:39:14 +0100 Subject: [PATCH 153/174] send notify --- src/utils/ubus.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 3ff8cbc..4b3603e 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -540,6 +540,8 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, // TODO: Only handle probe request and NOT assoc, ... + respond_to_notify(req->peer); + if (strncmp(method, "probe", 5) == 0) { return handle_probe_req(msg); } else if (strncmp(method, "auth", 4) == 0) { @@ -971,4 +973,13 @@ static void ubus_add_oject() if (ret) fprintf(stderr, "Failed to add watch handler: %s\n", ubus_strerror(ret)); */ +} + + +static void respond_to_notify(uint32_t id) { + blob_buf_init(&b, 0); + blobmsg_add_u32(&b, "notify_response", 1234); + + int timeout = 1; + ubus_invoke(ctx, id, "notify_response", b.head, NULL, NULL, timeout * 1000); } \ No newline at end of file From 9f969e41acc19a5a6c29e166abc2fde825c6af78 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 29 Dec 2017 22:28:51 +0100 Subject: [PATCH 154/174] update remove clients to 15 --- files/dawn.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index 5feddda..5f4ae03 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -13,7 +13,7 @@ config hostapd config times option update_client '10' - option remove_client '120' + option remove_client '15' option remove_probe '120' option remove_ap '460' option update_hostapd '10' From b65652c92a73e36d62b5152cb2d4fd1c3971286e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 29 Dec 2017 22:29:53 +0100 Subject: [PATCH 155/174] set min probe count to 0 --- files/dawn.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index 5f4ae03..983afc8 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -32,7 +32,7 @@ config metric option low_rssi_val '-80' option chan_util_val '140' option max_chan_util_val '170' - option min_probe_count '4' + option min_probe_count '0' option bandwith_threshold '6' option use_station_count '1' option eval_probe_req '1' \ No newline at end of file From 3b380a5fd9eb80873ca9b1487d1641fdf152c6f0 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 29 Dec 2017 22:51:10 +0100 Subject: [PATCH 156/174] correct remove function --- src/storage/datastorage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index e9636e3..220a799 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -547,7 +547,7 @@ client *client_array_delete(client entry) { } } - for (int j = i; j <= client_entry_last; j++) { + for (int j = i; j < client_entry_last; j++) { client_array[j] = client_array[j + 1]; } From ade823145e5ea161bf5d949e0eea15a42300ae14 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 29 Dec 2017 23:19:36 +0100 Subject: [PATCH 157/174] fix remove functions --- src/storage/datastorage.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index be06846..145466d 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -542,7 +542,7 @@ client *client_array_delete(client entry) { } } - for (int j = i; j <= client_entry_last; j++) { + for (int j = i; j < client_entry_last; j++) { client_array[j] = client_array[j + 1]; } @@ -596,7 +596,7 @@ probe_entry probe_array_delete(probe_entry entry) { } } - for (int j = i; j <= probe_entry_last; j++) { + for (int j = i; j < probe_entry_last; j++) { probe_array[j] = probe_array[j + 1]; } @@ -765,7 +765,7 @@ ap ap_array_delete(ap entry) { } } - for (int j = i; j <= ap_entry_last; j++) { + for (int j = i; j < ap_entry_last; j++) { ap_array[j] = ap_array[j + 1]; } @@ -776,7 +776,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 < client_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]); } @@ -784,7 +784,7 @@ void remove_old_client_entries(time_t current_time, long long int threshold) { } void remove_old_probe_entries(time_t current_time, long long int threshold) { - for (int i = 0; i < probe_entry_last; i++) { + for (int i = 0; i <= probe_entry_last; i++) { if (probe_array[i].time < current_time - threshold) { if (!is_connected(probe_array[i].bssid_addr, probe_array[i].client_addr)) probe_array_delete(probe_array[i]); @@ -793,7 +793,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 < ap_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]); } From 5a4adde903d48d6aa7986b3d6d57e8233d928e01 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 12:47:36 +0100 Subject: [PATCH 158/174] clear maclist --- files/mac_list | 2 -- 1 file changed, 2 deletions(-) diff --git a/files/mac_list b/files/mac_list index 8a35cbc..e69de29 100644 --- a/files/mac_list +++ b/files/mac_list @@ -1,2 +0,0 @@ -a4:2b:b0:de:f1:fd -f0:79:60:1c:26:f0 From 73a36f34b3d0eaaaf64915eb1846633c18605dc5 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 13:23:58 +0100 Subject: [PATCH 159/174] low rssi and so on --- files/dawn.config | 2 +- src/storage/datastorage.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index 983afc8..21144b6 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -24,7 +24,7 @@ config metric option no_ht_support '0' option no_vht_support '0' option rssi '0' - option low_rssi '0' + option low_rssi '-500' option freq '100' option chan_util '0' option max_chan_util '0' diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index dc5d1ed..0cee332 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -235,6 +235,9 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { printf("SCORE: %d of:\n", score); print_probe_entry(probe_entry); + if(score < 0) + score = 0; + return score; } From 8ef4b81823fd35931e78b48f5a263169e7ae237d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 13:39:07 +0100 Subject: [PATCH 160/174] update min probe count --- files/dawn.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index 21144b6..a81923e 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -32,7 +32,7 @@ config metric option low_rssi_val '-80' option chan_util_val '140' option max_chan_util_val '170' - option min_probe_count '0' + option min_probe_count '4' option bandwith_threshold '6' option use_station_count '1' option eval_probe_req '1' \ No newline at end of file From 3456d526f3eca34776d66002452874e881b7a04f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 15:18:28 +0100 Subject: [PATCH 161/174] add debug output --- src/storage/datastorage.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 0cee332..f5a2365 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -190,6 +190,7 @@ int build_network_overview(struct blob_buf *b) int k; 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++){ if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) { @@ -232,12 +233,12 @@ int eval_probe_metric(struct probe_entry_s probe_entry) { score += (probe_entry.signal >= dawn_metric.rssi_val) ? dawn_metric.rssi : 0; score += (probe_entry.signal <= dawn_metric.low_rssi_val) ? dawn_metric.low_rssi : 0; - printf("SCORE: %d of:\n", score); - print_probe_entry(probe_entry); - if(score < 0) score = 0; + printf("SCORE: %d of:\n", score); + print_probe_entry(probe_entry); + return score; } From d31bfa5e07fa51be5d09fcd7e36537b53b339722 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 15:32:04 +0100 Subject: [PATCH 162/174] send notify response --- src/utils/ubus.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 72f5d85..9552119 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -188,9 +188,12 @@ int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); void hostapd_array_delete(uint32_t id); + static void ubus_add_oject(); -void add_client_update_timer(time_t time) { +static void respond_to_notify(uint32_t id); + + void add_client_update_timer(time_t time) { uloop_timeout_set(&client_timer, time); } From 64529d64149379c670326c6ad5b98e9827fffe17 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 15:43:38 +0100 Subject: [PATCH 163/174] use notify --- src/utils/ubus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 9552119..e7ca638 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -1016,8 +1016,9 @@ static void ubus_add_oject() static void respond_to_notify(uint32_t id) { + printf("SENDING NOTIFY!!!\n"); blob_buf_init(&b, 0); - blobmsg_add_u32(&b, "notify_response", 1234); + blobmsg_add_u32(&b, "notify_response", 0); int timeout = 1; ubus_invoke(ctx, id, "notify_response", b.head, NULL, NULL, timeout * 1000); From 061a477a205ecea1f99b3f581313f67fbfa9c88d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 30 Dec 2017 18:29:20 +0100 Subject: [PATCH 164/174] 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 165/174] 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 166/174] 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 167/174] 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 168/174] 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; From 66c3f005e65276f54451af64c7ad5e102ee9c179 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 4 Jan 2018 11:57:00 +0100 Subject: [PATCH 169/174] add files and so on --- files/dawn.config | 2 +- src/utils/ubus.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index a81923e..d8c27bc 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -32,7 +32,7 @@ config metric option low_rssi_val '-80' option chan_util_val '140' option max_chan_util_val '170' - option min_probe_count '4' + option min_probe_count '100' option bandwith_threshold '6' option use_station_count '1' option eval_probe_req '1' \ No newline at end of file diff --git a/src/utils/ubus.c b/src/utils/ubus.c index e7ca638..bb91980 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -596,6 +596,9 @@ static int add_subscriber(char *name) { hostapd_array_insert(id); fprintf(stderr, "Watching object %08x: %s\n", id, ubus_strerror(ret)); + // respond to notify... + respond_to_notify(id); + return 0; } @@ -1018,7 +1021,7 @@ static void ubus_add_oject() static void respond_to_notify(uint32_t id) { printf("SENDING NOTIFY!!!\n"); blob_buf_init(&b, 0); - blobmsg_add_u32(&b, "notify_response", 0); + blobmsg_add_u32(&b, "notify_response", 1); int timeout = 1; ubus_invoke(ctx, id, "notify_response", b.head, NULL, NULL, timeout * 1000); From c8bdc3472bfe960edcac0fe47d1990c1426a6e61 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 4 Jan 2018 12:08:26 +0100 Subject: [PATCH 170/174] use notify call --- files/dawn.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index d8c27bc..8cad0b0 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -32,7 +32,7 @@ config metric option low_rssi_val '-80' option chan_util_val '140' option max_chan_util_val '170' - option min_probe_count '100' + option min_probe_count '4' option bandwith_threshold '6' option use_station_count '1' - option eval_probe_req '1' \ No newline at end of file + option eval_probe_req '1' From 96ad652c27d42a9237804a6395a6b78286f3a23e Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 4 Jan 2018 12:12:43 +0100 Subject: [PATCH 171/174] remove code --- src/utils/ubus.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index bb91980..80feb64 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -193,7 +193,7 @@ static void ubus_add_oject(); static void respond_to_notify(uint32_t id); - void add_client_update_timer(time_t time) { +void add_client_update_timer(time_t time) { uloop_timeout_set(&client_timer, time); } @@ -565,8 +565,6 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, // TODO: Only handle probe request and NOT assoc, ... - respond_to_notify(req->peer); - if (strncmp(method, "probe", 5) == 0) { return handle_probe_req(msg); } else if (strncmp(method, "auth", 4) == 0) { From a643265a27440cd649332414852ccc20a0eca292 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 4 Jan 2018 12:58:59 +0100 Subject: [PATCH 172/174] return with reason code --- files/dawn.config | 2 +- src/utils/ubus.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 8cad0b0..04a4ffb 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -35,4 +35,4 @@ config metric option min_probe_count '4' option bandwith_threshold '6' option use_station_count '1' - option eval_probe_req '1' + option eval_probe_req '0' diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 80feb64..95f8cc7 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -9,6 +9,8 @@ #define ETH_ALEN 6 #endif +#define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17 + #include "ubus.h" #include "networksocket.h" @@ -371,12 +373,12 @@ static int handle_auth_req(struct blob_attr *msg) { // block if entry was not already found in probe database if (!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr))) { printf("DENY AUTH!\n"); - return UBUS_STATUS_UNKNOWN_ERROR; + return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; } if (!decide_function(&tmp)) { printf("DENY AUTH\n"); - return UBUS_STATUS_UNKNOWN_ERROR; + return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; } // maybe add here if a client is already connected... @@ -406,7 +408,7 @@ static int handle_probe_req(struct blob_attr *msg) { if (!decide_function(&tmp_prob_req)) { //printf("MAC WILL BE DECLINED!!!\n"); - return UBUS_STATUS_UNKNOWN_ERROR; + return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; } //printf("MAC WILL BE ACCEPDTED!!!\n"); return 0; From 8c68e2fe205a01b814e9d56e705b3b3e63aeb563 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 4 Jan 2018 13:05:17 +0100 Subject: [PATCH 173/174] respond with reason code --- files/dawn.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/dawn.config b/files/dawn.config index 04a4ffb..8cad0b0 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -35,4 +35,4 @@ config metric option min_probe_count '4' option bandwith_threshold '6' option use_station_count '1' - option eval_probe_req '0' + option eval_probe_req '1' From b279ca2191026b0989ad914fb770bcb7a76a2f26 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 4 Jan 2018 13:13:19 +0100 Subject: [PATCH 174/174] return with WLAN_STATUS_SUCCESS --- src/utils/ubus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 95f8cc7..1c2d403 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -9,6 +9,7 @@ #define ETH_ALEN 6 #endif +#define WLAN_STATUS_SUCCESS 0 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17 #include "ubus.h" @@ -385,7 +386,7 @@ static int handle_auth_req(struct blob_attr *msg) { // delay problems... printf("ALLOW AUTH!\n"); - return 0; + return WLAN_STATUS_SUCCESS; } static int handle_assoc_req(struct blob_attr *msg) { @@ -411,7 +412,7 @@ static int handle_probe_req(struct blob_attr *msg) { return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; } //printf("MAC WILL BE ACCEPDTED!!!\n"); - return 0; + return WLAN_STATUS_SUCCESS; } static int handle_deauth_req(struct blob_attr *msg) {