From 7a1c7e29d4c01b7c4d0a9d2d8282940ed0ae7080 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 17 Jul 2017 21:46:41 +0200 Subject: [PATCH] Kick if rssi is not strong enough --- files/dawn.config | 4 +-- src/include/datastorage.h | 3 ++- src/include/ubus.h | 1 + src/main.c | 2 +- src/storage/datastorage.c | 51 +++++++++++++++++++++++++++++++++++++++ src/utils/ubus.c | 5 ++++ 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index cf1fa70..2eaef72 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,6 +1,6 @@ config 'settings' 'dawn' - option broadcast_ip '224.0.0.1' + option broadcast_ip '10.0.0.255' option broadcast_port '1025' - option sort_order 'cfsb' + option sort_order 'csfb' option hostapd_dir '/var/run/hostapd' option background '0' \ No newline at end of file diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 1bed488..c0af100 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -54,12 +54,13 @@ typedef struct client_s { #define ARRAY_CLIENT_LEN 1000 -#define TIME_THRESHOLD_CLIENT 60 +#define TIME_THRESHOLD_CLIENT 5 struct client_s client_array[ARRAY_CLIENT_LEN]; pthread_mutex_t client_array_mutex; void insert_client_to_array(client entry); +void kick_clients(uint8_t bssid[]); void client_array_insert(client entry); client* client_array_delete(client entry); diff --git a/src/include/ubus.h b/src/include/ubus.h index f814d27..e891973 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -1,6 +1,7 @@ #ifndef __DAWN_UBUS_H #define __DAWN_UBUS_H +#include #include "datastorage.h" #define MIN_PROBE_REQ 2 // TODO: Parse from config file... diff --git a/src/main.c b/src/main.c index bb2c095..09d4735 100644 --- a/src/main.c +++ b/src/main.c @@ -59,7 +59,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, 1); pthread_t tid_probe; pthread_create(&tid_probe, NULL, &remove_array_thread, NULL); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 0871a7b..ee84eaa 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -1,5 +1,7 @@ #include "datastorage.h" +#include "ubus.h" + #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] int go_next_help(char sort_order[], int i, probe_entry entry, @@ -16,10 +18,59 @@ int client_array_go_next(char sort_order[], int i, client entry, int client_array_go_next_help(char sort_order[], int i, client entry, client next_entry); void remove_old_client_entries(time_t current_time, long long int threshold); +int kick_client(uint8_t bssid[], uint8_t client[]); int probe_entry_last = -1; int client_entry_last = -1; +int kick_client(uint8_t bssid[], uint8_t client[]) +{ + int i; + for(i = 0; i <= client_entry_last; i++) + { + if(mac_is_equal(probe_array[i].client_addr, client)) + { + // check if bssid is first in list... + return (mac_is_equal(bssid, probe_array[i].bssid_addr)); + } + } + return 0; +} + +void kick_clients(uint8_t bssid[]) +{ + // Seach for BSSID + int i; + for(i = 0; i <= client_entry_last; i++) + { + if(mac_is_equal(client_array[i].bssid_addr, bssid)) + { + break; + } + } + + // Go threw clients + int j; + for(j = i; j <= client_entry_last; j++) + { + if(!mac_is_equal(client_array[j].bssid_addr, bssid)) + { + break; + } + if(kick_client(bssid, client_array[j].client_addr)) + { + /* + TODO: KICK ONLY FROM ONE BSSID? + */ + printf("KICKING CLIENT!!!!!!!!!!!!!\n"); + del_client(client_array[j].client_addr, 5, 1, 60000); + } else + { + printf("STAAAY CLIENT!!!!!!!!!!!!!\n"); + } + } +} + int client_array_go_next_help(char sort_order[], int i, client entry, client next_entry) { switch (sort_order[i]) { diff --git a/src/utils/ubus.c b/src/utils/ubus.c index cb7d405..cf9d4df 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -333,8 +333,13 @@ int parse_to_clients(struct blob_attr *msg) { dump_client_table(blobmsg_data(tb[CLIENT_TABLE]), blobmsg_data_len(tb[CLIENT_TABLE]), blobmsg_data(tb[CLIENT_TABLE_BSSID]), blobmsg_get_u32(tb[CLIENT_TABLE_FREQ])); /* BSSID */ + /* + * here i know my bssid to kick the clients + * seems a good idea ?! + */ uint8_t bssid[ETH_ALEN]; hwaddr_aton(blobmsg_data(tb[CLIENT_TABLE_BSSID]), bssid); + kick_clients(bssid); } return 0;