From 0ae70ccc281f27538cbc1fd797b39ed85c84148d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 17 Jul 2017 16:42:57 +0200 Subject: [PATCH] Add delete client call --- src/include/ubus.h | 1 + src/network/networksocket.c | 2 +- src/utils/ubus.c | 60 ++++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/include/ubus.h b/src/include/ubus.h index 419c0a0..df59b71 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -8,6 +8,7 @@ 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); +void del_client(const uint8_t* client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); void *update_clients_thread(void *arg); char* hostapd_dir_glob; diff --git a/src/network/networksocket.c b/src/network/networksocket.c index 1344500..39760de 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -102,7 +102,7 @@ void *receive_msg(void *args) { int send_string(char *msg) { int msglen = strlen(msg); - printf("Sending string!\n"); + printf("Sending string! %s\n", msg); if (sendto( sock, msg, msglen, diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 2a6a3d7..fd76f16 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -15,6 +15,7 @@ static struct ubus_context *ctx; static struct ubus_subscriber hostapd_event; +static struct blob_buf b; enum { PROB_BSSID_ADDR, @@ -229,7 +230,17 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { subscribe_to_hostapd_interfaces(hostapd_dir); - ubus_get_clients(); + //ubus_get_clients(); + + printf("Deleting Client\n"); + //"78:02:f8:bc:ac:0b" + + int tmp_int_mac[ETH_ALEN]; + uint8_t tmp_mac[ETH_ALEN]; + sscanf("78:02:f8:bc:ac:0b", "%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]; + del_client(tmp_mac, 5, 1, 60000); uloop_run(); @@ -292,6 +303,8 @@ dump_client(struct blob_attr **tb, uint8_t client_addr[], const char* bssid_addr } insert_client_to_array(client_entry); + + // void del_client(const uint8_t client_addr[], uint32_t reason, uint8_t deauth, uint32_t ban_time) } static void @@ -372,4 +385,49 @@ void *update_clients_thread(void *arg) ubus_get_clients(); } return 0; +} + +/* 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) +{ + char *s; + + s = blobmsg_alloc_string_buffer(buf, name, 20); + sprintf(s, MACSTR, MAC2STR(addr)); + blobmsg_add_string_buffer(buf); +} + +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? + First send to all ifaces to ban client... xD + Maybe Hashmap? + */ + + 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); + + DIR *dirp; + struct dirent *entry; + dirp = opendir(hostapd_dir_glob); // error handling? + 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, hostapd_iface, &id); + if(!ret) + { + int timeout = 1; + ubus_invoke(ctx, id, "del_client", b.head, NULL, NULL, timeout * 1000); + } + } + } } \ No newline at end of file