New delete function

This commit is contained in:
PolynomialDivision 2017-07-29 16:52:18 +02:00
parent 16dfa3238e
commit 0944faed7f
5 changed files with 34 additions and 21 deletions

View file

@ -66,7 +66,7 @@ pthread_mutex_t client_array_mutex;
void insert_client_to_array(client entry);
void kick_clients(uint8_t bssid[]);
void kick_clients(uint8_t bssid[], uint32_t id);
void client_array_insert(client entry);

View file

@ -8,8 +8,9 @@
int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir);
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);
int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id);
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);
void *update_clients_thread(void *arg);
void *kick_clients_thread(void *arg);

View file

@ -101,7 +101,7 @@ void *receive_msg(void *args) {
*/
if (strstr(str, "clients") != NULL) {
parse_to_clients(b.head, 0);
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);

View file

@ -47,11 +47,11 @@ int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_e
struct probe_metric_s metric = {
.ht_support = 0,
.vht_support = 100,
.vht_support = 0,
.n_ht_support = 0,
.n_ht_support = 0,
.rssi = 0,
.freq = 0}; // this is for testing
.freq = 100}; // this is for testing
int score = 0;
@ -85,7 +85,7 @@ int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_e
//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;
score += (probe_entry.freq > 5000) ? metric.freq : 0;
//score += (client_entry.signal > -60) ? metric.freq : 0;
@ -141,7 +141,7 @@ int kick_client(struct client_s client_entry) {
return 0;
}
void kick_clients(uint8_t bssid[]) {
void kick_clients(uint8_t bssid[], uint32_t id) {
pthread_mutex_lock(&client_array_mutex);
pthread_mutex_lock(&probe_array_mutex);
@ -164,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_interface(id, client_array[j].client_addr, 5, 1, 60000);
} else {
printf("STAAAY CLIENT!!!!!!!!!!!!!\n");
}

View file

@ -14,7 +14,7 @@
#include "utils.h"
static struct ubus_context *ctx;
static struct ubus_context *ctx_clients;
static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */
static struct ubus_subscriber hostapd_event;
static struct blob_buf b;
@ -200,7 +200,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
// deny access
if (!decide_function(&tmp_probe)) {
printf("MAC WILL BE DECLINED!!!");
return UBUS_STATUS_UNKNOWN_ERROR;
return UBUS_STATUS_CONNECTION_FAILED;
}
printf("MAC WILL BE ACCEPDTED!!!");
@ -356,7 +356,7 @@ 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) {
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");
@ -377,11 +377,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);
kick_clients(bssid, id);
printf("[CLIENTS] : KickED Clients\n");
}*/
}
}
return 0;
@ -394,7 +394,7 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
if (!msg)
return;
parse_to_clients(msg, 1);
parse_to_clients(msg, 1, req->peer);
char *str = blobmsg_format_json(msg, true);
send_string(str);
@ -439,24 +439,24 @@ void *kick_clients_thread(void *arg) {
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);
//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);
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) {
void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) {
/* Problem:
On which interface is the client?
First send to all ifaces to ban client... xD
@ -487,4 +487,16 @@ void del_client(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uin
}
}
}
}
void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) {
blob_buf_init(&b, 0);
blobmsg_add_macaddr(&b, "addr", client_addr);
blobmsg_add_u32(&b, "reason", reason);
blobmsg_add_u8(&b, "deauth", deauth);
blobmsg_add_u32(&b, "ban_time", ban_time);
int timeout = 1;
ubus_invoke(ctx_clients, id, "del_client", b.head, NULL, NULL, timeout * 1000);
}