This commit is contained in:
PolynomialDivision 2017-07-25 20:52:39 +02:00
parent a63fe45662
commit bfa99147cd
6 changed files with 72 additions and 24 deletions

View file

@ -14,7 +14,7 @@
#endif
#define SORT_NUM 5
#define TIME_THRESHOLD 600 // every minute
#define TIME_THRESHOLD 30 // every minute
// Probe entrys
typedef struct probe_entry_s {
@ -56,8 +56,10 @@ typedef struct client_s {
// Array
#define ARRAY_CLIENT_LEN 1000
#define TIME_THRESHOLD_CLIENT 10
#define TIME_THRESHOLD_CLIENT_UPDATE 5
#define TIME_THRESHOLD_CLIENT 30
#define TIME_THRESHOLD_CLIENT_UPDATE 10
#define TIME_THRESHOLD_CLIENT_KICK 60
struct client_s client_array[ARRAY_CLIENT_LEN];
pthread_mutex_t client_array_mutex;

View file

@ -11,6 +11,7 @@ int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req);
int parse_to_clients(struct blob_attr *msg, int do_kick);
void del_client(const uint8_t* client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time);
void *update_clients_thread(void *arg);
void *kick_clients_thread(void *arg);
char* hostapd_dir_glob;

View file

@ -59,18 +59,19 @@ 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, 1);
pthread_t tid_probe;
pthread_create(&tid_probe, NULL, &remove_array_thread, NULL);
//pthread_t tid_probe;
//pthread_create(&tid_probe, NULL, &remove_array_thread, NULL);
pthread_t tid_client;
pthread_create(&tid_client, NULL, &remove_client_array_thread, NULL);
//pthread_t tid_client;
// pthread_create(&tid_client, NULL, &remove_client_array_thread, NULL);
pthread_t tid_get_client;
pthread_create(&tid_get_client, NULL, &update_clients_thread, NULL);
pthread_t tid_kick_clients;
pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL);
//pthread_create(&tid, NULL, &remove_thread, NULL);

View file

@ -121,7 +121,7 @@ void *receive_msg(void *args) {
int send_string(char *msg) {
pthread_mutex_lock(&send_mutex);
int msglen = strlen(msg);
/*int msglen = strlen(msg);
//printf("Sending string! %s\n", msg);
if (sendto(sock,
msg,
@ -131,7 +131,7 @@ int send_string(char *msg) {
sizeof(addr)) < 0) {
perror("sendto()");
exit(EXIT_FAILURE);
}
}*/
pthread_mutex_unlock(&send_mutex);

View file

@ -64,19 +64,26 @@ int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_e
ap_supports_ht = client_entry.ht_supported;
ap_supports_vht = client_entry.vht_supported;
printf("AP Supports HT: %d\n", ap_supports_ht);
printf("AP Supports VHT: %d\n", ap_supports_vht);
client_supports_ht = probe_entry.ht_support;
client_supports_vht = probe_entry.vht_support;
printf("Clients Supports HT: %d\n", client_supports_ht);
printf("Clients Supports VHT: %d\n", client_supports_vht);
printf("Checking if client supports: AP_VHT: %d, CL_VHT: %d\n", ap_supports_vht, client_supports_vht);
if(ap_supports_vht && client_supports_vht){
printf("AAAHHHHHHHHHHH IDEAL!!!\n");
}
score += (ap_supports_vht && client_supports_vht) ? metric.vht_support : 0;
score += (ap_supports_ht && client_supports_ht) ? metric.ht_support : 0;
score += client_supports_vht ? metric.vht_support : metric.n_vht_support;
score += client_supports_ht ? metric.ht_support : metric.n_ht_support;
score += (!ap_supports_vht && !client_supports_vht) ? metric.n_vht_support : 0;
score += (!ap_supports_ht && !client_supports_ht) ? metric.n_ht_support : 0;
//score += !client_supports_vht ? metric.n_vht_support : 0;
//score += !client_supports_ht ? metric.n_ht_support : 0;
score += (client_entry.freq > 5000) ? metric.freq : 0;
@ -109,7 +116,8 @@ int kick_client(struct client_s client_entry) {
printf("[j] : %d\n",j);
if (!mac_is_equal(probe_array[j].client_addr, client_entry.client_addr)) {
// this shouldn't happen!
return 1; // kick client!
//return 1; // kick client!
return 0;
}
if (mac_is_equal(client_entry.bssid_addr, probe_array[j].bssid_addr)){
own_score = eval_probe_metric(client_entry, probe_array[j]);
@ -134,8 +142,8 @@ int kick_client(struct client_s client_entry) {
}
void kick_clients(uint8_t bssid[]) {
pthread_mutex_lock(&probe_array_mutex);
pthread_mutex_lock(&client_array_mutex);
pthread_mutex_lock(&probe_array_mutex);
// Seach for BSSID
int i;
@ -156,7 +164,7 @@ void kick_clients(uint8_t bssid[]) {
TODO: KICK ONLY FROM ONE BSSID?
*/
printf("KICKING CLIENT!!!!!!!!!!!!!\n");
del_client(client_array[j].client_addr, 5, 1, 60000);
//del_client(client_array[j].client_addr, 5, 1, 60000);
} else {
printf("STAAAY CLIENT!!!!!!!!!!!!!\n");
}
@ -225,13 +233,13 @@ void client_array_insert(client entry) {
}
}
for (int j = client_entry_last; j >= i; j--) {
if (j + 1 <= ARRAY_LEN) {
if (j + 1 <= ARRAY_CLIENT_LEN) {
client_array[j + 1] = client_array[j];
}
}
client_array[i] = entry;
if (client_entry_last < ARRAY_LEN) {
if (client_entry_last < ARRAY_CLIENT_LEN) {
client_entry_last++;
}
}

View file

@ -168,6 +168,13 @@ int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req) {
static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg) {
// TODO: Only handle probe request and NOT assoc, ...
if (strncmp(method, "probe", 5) != 0)
return 0;
printf("[WC] Parse Probe Request\n");
probe_entry prob_req;
parse_to_probe_req(msg, &prob_req);
//insert_to_list(prob_req, 1);
@ -179,6 +186,8 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
send_string(str);
printf("[WC] Hostapd-Probe: %s : %s\n", method, str);
printf("[WC] ParsED Probe Request\n");
//print_array();
@ -346,6 +355,8 @@ 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) {
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] &&
@ -353,7 +364,7 @@ int parse_to_clients(struct blob_attr *msg, int do_kick) {
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]),
blobmsg_get_u8(tb[CLIENT_TABLE_HT]), blobmsg_get_u8(tb[CLIENT_TABLE_VHT]));
printf("[CLIENTS] : ParseD Clients\n");
/* BSSID */
/*
* here i know my bssid to kick the clients
@ -362,9 +373,11 @@ int parse_to_clients(struct blob_attr *msg, int do_kick) {
uint8_t bssid[ETH_ALEN];
hwaddr_aton(blobmsg_data(tb[CLIENT_TABLE_BSSID]), bssid);
if(do_kick){
/*if(do_kick){
printf("[CLIENTS] : Kick Clients\n");
kick_clients(bssid);
}
printf("[CLIENTS] : KickED Clients\n");
}*/
}
return 0;
@ -404,12 +417,35 @@ static int ubus_get_clients() {
void *update_clients_thread(void *arg) {
while (1) {
sleep(TIME_THRESHOLD_CLIENT_UPDATE);
printf("[Thread] : Updating clients!\n");
printf("[Thread] : Kicking clients!\n");
ubus_get_clients();
}
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", "%x:%x:%x:%x:%x:%x", 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));
for(int i = 0; i < ETH_ALEN; ++i )
tmp_mac[i] = (uint8_t) tmp_int_mac[i];
kick_clients(tmp_mac);
}
return 0;
}
void del_client(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) {
/* Problem:
On which interface is the client?