From 958e04e8a460b315e400f62abca2676d174c1485 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 25 Aug 2017 19:44:04 +0200 Subject: [PATCH] Parse AUTH and ASSOC --- src/include/datastorage.h | 13 ++++++++ src/include/ubus.h | 4 +++ src/storage/datastorage.c | 18 ++++++++++++ src/utils/ubus.c | 62 ++++++++++++++++++++++++++++++++------- 4 files changed, 87 insertions(+), 10 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 24778b6..e0fc8b3 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -40,6 +40,17 @@ typedef struct probe_entry_s { int counter; } probe_entry; +typedef struct auth_entry_s { + uint8_t bssid_addr[ETH_ALEN]; + uint8_t client_addr[ETH_ALEN]; + uint8_t target_addr[ETH_ALEN]; + uint32_t signal; + uint32_t freq; +} auth_entry; + +typedef struct auth_entry_s assoc_entry; + + typedef struct { uint32_t freq; } client_request; @@ -100,6 +111,8 @@ 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_array(); void *remove_array_thread(void *arg); diff --git a/src/include/ubus.h b/src/include/ubus.h index eb5cd27..20acdda 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -10,6 +10,10 @@ 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_auth_req(struct blob_attr *msg, auth_entry *auth_req); + +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); void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index a5328da..468031b 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -310,6 +310,24 @@ probe_entry probe_array_delete(probe_entry entry) { return tmp; } +probe_entry probe_array_get_entry(uint8_t bssid_addr[], uint8_t client_addr[]) { + int i; + probe_entry tmp; + + if (probe_entry_last == -1) { + return tmp; + } + + for (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)) { + tmp = probe_array[i]; + break; + } + } + return tmp; +} + void print_array() { printf("------------------\n"); printf("Probe Entry Last: %d\n", probe_entry_last); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 497c512..b14f53f 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -19,6 +19,23 @@ static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange be static struct ubus_subscriber hostapd_event; static struct blob_buf b; +enum { + AUTH_BSSID_ADDR, + AUTH_CLIENT_ADDR, + AUTH_TARGET_ADDR, + AUTH_SIGNAL, + AUTH_FREQ, + __AUTH_MAX, +}; + +static const struct blobmsg_policy auth_policy[__AUTH_MAX] = { + [AUTH_BSSID_ADDR] = {.name = "bssid", .type = BLOBMSG_TYPE_STRING}, + [AUTH_CLIENT_ADDR] = {.name = "address", .type = BLOBMSG_TYPE_STRING}, + [AUTH_TARGET_ADDR] = {.name = "target", .type = BLOBMSG_TYPE_STRING}, + [AUTH_SIGNAL] = {.name = "signal", .type = BLOBMSG_TYPE_INT32}, + [AUTH_FREQ] = {.name = "freq", .type = BLOBMSG_TYPE_INT32}, +}; + enum { PROB_BSSID_ADDR, PROB_CLIENT_ADDR, @@ -123,16 +140,6 @@ static int decide_function(probe_entry *prob_req) { return 0; } - /*int ret = - mac_first_in_probe_list(prob_req->bssid_addr, prob_req->client_addr); - if (ret) { - printf("Mac will be accepted!\n"); - } else { - printf("Mac will be declined!\n"); - } - return ret; - */ - // allow access return 1; } @@ -141,6 +148,35 @@ static void hostapd_handle_remove(struct ubus_context *ctx, fprintf(stderr, "Object %08x went away\n", id); } +int parse_to_auth_req(struct blob_attr *msg, auth_entry *auth_req) { + struct blob_attr *tb[__AUTH_MAX]; + + blobmsg_parse(auth_policy, __AUTH_MAX, tb, blob_data(msg), blob_len(msg)); + + if (hwaddr_aton(blobmsg_data(tb[AUTH_BSSID_ADDR]), auth_req->bssid_addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[AUTH_CLIENT_ADDR]), auth_req->client_addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[AUTH_TARGET_ADDR]), auth_req->target_addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[PROB_SIGNAL]) { + auth_req->signal = blobmsg_get_u32(tb[AUTH_SIGNAL]); + } + + if (tb[PROB_FREQ]) { + auth_req->freq = blobmsg_get_u32(tb[AUTH_FREQ]); + } + + return 0; +} + +int parse_to_assoc_req(struct blob_attr *msg, assoc_entry *assoc_req) { + return (parse_to_auth_req(msg, assoc_req)); +} + int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req) { struct blob_attr *tb[__PROB_MAX]; @@ -175,10 +211,16 @@ int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req) { } static int handle_auth_req(struct blob_attr *msg) { + auth_entry auth_req; + parse_to_auth_req(msg, &auth_req); + return 0; } static int handle_assoc_req(struct blob_attr *msg) { + assoc_entry assoc_req; + parse_to_auth_req(msg, &assoc_req); + return 0; }