diff --git a/src/include/datastorage.h b/src/include/datastorage.h index d50f39f..e509e3d 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -27,49 +27,43 @@ typedef struct probe_entry_s { int counter; } probe_entry; -/* - static const struct { - const char *name; - uint32_t flag; - } sta_flags[] = { - { "auth", WLAN_STA_AUTH }, - { "assoc", WLAN_STA_ASSOC }, - { "authorized", WLAN_STA_AUTHORIZED }, - { "preauth", WLAN_STA_PREAUTH }, - { "wds", WLAN_STA_WDS }, - { "wmm", WLAN_STA_WMM }, - { "ht", WLAN_STA_HT }, - { "vht", WLAN_STA_VHT }, - { "wps", WLAN_STA_WPS }, - { "mfp", WLAN_STA_MFP }, - }; -*/ - typedef struct { uint32_t freq; } client_request; -typedef struct { - uint8_t mac[ETH_ALEN]; - uint32_t freq; - uint32_t auth; - uint32_t assoc; - uint32_t authorized; - uint32_t preauth; - uint32_t wds; - uint32_t wmm; - uint32_t ht; - uint32_t vht; - uint32_t wps; - uint32_t mfp; +typedef struct client_s { + uint8_t bssid_addr[ETH_ALEN]; + uint8_t client_addr[ETH_ALEN]; + uint8_t freq; + uint8_t auth; + uint8_t assoc; + uint8_t authorized; + uint8_t preauth; + uint8_t wds; + uint8_t wmm; + uint8_t ht; + uint8_t vht; + uint8_t wps; + uint8_t mfp; + uint32_t aid; } client; // Array + +#define ARRAY_CLIENT_LEN 1000 + +struct probe_entry_s client_array[ARRAY_CLIENT_LEN]; +pthread_mutex_t client_array_mutex; + +void client_array_insert(client entry); +client* client_array_delete(client entry); + #define ARRAY_LEN 1000 struct probe_entry_s probe_array[ARRAY_LEN]; +pthread_mutex_t probe_array_mutex; void insert_to_array(probe_entry entry, int inc_counter); void probe_array_insert(probe_entry entry); @@ -77,9 +71,6 @@ probe_entry* probe_array_delete(probe_entry entry); void print_array(); void *remove_array_thread(void *arg); -pthread_mutex_t probe_array_mutex; - - diff --git a/src/include/utils.h b/src/include/utils.h index 0b38086..f739fae 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -2,6 +2,8 @@ #define __DAWN_UTILS_H #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] +#define STR2MAC(a) &(a)[0], &(a)[1], &(a)[2], &(a)[3], &(a)[4], &(a)[5] + static int hex_to_bin(char ch) { if ((ch >= '0') && (ch <= '9')) return ch - '0'; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 31d6788..ac67168 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -12,6 +12,76 @@ void print_probe_entry(probe_entry entry); void remove_old_probe_entries(time_t current_time, long long int threshold); int probe_entry_last = -1; +int client_entry_last = -1; + +void client_array_insert(client entry) +{ + /* + if(client_entry_last == -1) + { + probe_array[0] = entry; + client_entry_last++; + return; + } + + int i; + for(i = 0; i <= client_entry_last; i++) + { + if(!go_next(sort_string, SORT_NUM, entry, probe_array[i])) + { + break; + } + } + for(int j = client_entry_last; j >= i; j--) + { + if(j + 1 <= ARRAY_LEN) + { + probe_array[j + 1] = probe_array[j]; + } + } + probe_array[i] = entry; + + if(client_entry_last < ARRAY_LEN) + { + client_entry_last++; + }*/ +} + +client* client_array_delete(client entry) +{ + /* + int i; + int found_in_array = 0; + client* tmp = NULL; + + if(probe_entry_last == -1) + { + return NULL; + } + + for(i = 0; i <= client_entry_last; i++) + { + if(mac_is_equal(entry.bssid_addr, probe_array[i].bssid_addr) && + mac_is_equal(entry.client_addr, probe_array[i].client_addr)) + { + found_in_array = 1; + tmp = &probe_array[i]; + break; + } + } + + for(int j = i; j <= client_entry_last; j++) + { + probe_array[j] = probe_array[j + 1]; + } + + if(client_entry_last > -1 && found_in_array) + { + client_entry_last--; + } + return tmp;*/ + return NULL; +} void probe_array_insert(probe_entry entry) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 99fbe8d..9c3fe60 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -35,12 +35,14 @@ static const struct blobmsg_policy prob_policy[__PROB_MAX] = { enum { CLIENT_TABLE, + CLIENT_TABLE_BSSID, CLIENT_TABLE_FREQ, __CLIENT_TABLE_MAX, }; static const struct blobmsg_policy client_table_policy[__CLIENT_TABLE_MAX] = { [CLIENT_TABLE] = {.name = "clients", .type = BLOBMSG_TYPE_TABLE}, + [CLIENT_TABLE_BSSID] = {.name = "bssid", .type = BLOBMSG_TYPE_STRING}, [CLIENT_TABLE_FREQ] = {.name = "freq", .type = BLOBMSG_TYPE_INT32}, }; @@ -229,31 +231,69 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { } static void -dump_client(struct blob_attr **tb) +dump_client(struct blob_attr **tb, uint8_t client_addr[], const char* bssid_addr, uint32_t freq) { printf("DUMPING CLIENT:\n"); + client client_entry; + + hwaddr_aton(bssid_addr, client_entry.bssid_addr); + + memcpy(client_entry.client_addr, client_addr, ETH_ALEN * sizeof(uint8_t)); + + char mac_buf_client[20]; + char mac_buf_ap[20]; + + sprintf(mac_buf_ap, "%x:%x:%x:%x:%x:%x", MAC2STR(client_entry.bssid_addr)); + sprintf(mac_buf_client, "%x:%x:%x:%x:%x:%x", MAC2STR(client_entry.client_addr)); + printf("Testing client mac: %s\n", client_entry.client_addr); + + printf("Client Address: %s\n", mac_buf_client); + printf("AP Address: %s\n", mac_buf_ap); + + + //hwaddr_aton(client_addr, client_entry.client_addr); + if (tb[CLIENT_AUTH]) { - printf("AUTH: %d\n", blobmsg_get_u8(tb[CLIENT_AUTH])); + client_entry.auth = blobmsg_get_u8(tb[CLIENT_AUTH]); } if (tb[CLIENT_ASSOC]) { - printf("ASSOC: %d\n", blobmsg_get_u8(tb[CLIENT_ASSOC])); + client_entry.assoc = blobmsg_get_u8(tb[CLIENT_ASSOC]); + } + if(tb[CLIENT_AUTHORIZED]) + { + client_entry.authorized = blobmsg_get_u8(tb[CLIENT_AUTHORIZED]); + } + if(tb[CLIENT_PREAUTH]){ + client_entry.preauth = blobmsg_get_u8(tb[CLIENT_PREAUTH]); + } + if(tb[CLIENT_WDS]){ + client_entry.wds = blobmsg_get_u8(tb[CLIENT_WDS]); + } + if(tb[CLIENT_WMM]){ + client_entry.wmm = blobmsg_get_u8(tb[CLIENT_WMM]); + } + if(tb[CLIENT_HT]){ + client_entry.ht = blobmsg_get_u8(tb[CLIENT_HT]); + } + if(tb[CLIENT_VHT]){ + client_entry.vht = blobmsg_get_u8(tb[CLIENT_VHT]); + } + if(tb[CLIENT_WPS]){ + client_entry.wps = blobmsg_get_u8(tb[CLIENT_WPS]); + } + if(tb[CLIENT_MFP]){ + client_entry.mfp = blobmsg_get_u8(tb[CLIENT_MFP]); + } + if(tb[CLIENT_AID]){ + client_entry.aid = blobmsg_get_u32(tb[CLIENT_AID]); } - if(tb[CLIENT_PREAUTH]){ - printf("Preauth: %d\n", blobmsg_get_u8(tb[CLIENT_PREAUTH])); - } - if(tb[CLIENT_HT]){ - printf("HT: %d\n", blobmsg_get_u8(tb[CLIENT_HT])); - } - if(tb[CLIENT_HT]){ - printf("AID: %d\n", blobmsg_get_u32(tb[CLIENT_AID])); - } printf("Dumped Client!\n"); } static void -dump_client_table(struct blob_attr *head, int len) +dump_client_table(struct blob_attr *head, int len, const char* bssid_addr, uint32_t freq) { struct blob_attr *attr; struct blobmsg_hdr *hdr; @@ -267,7 +307,13 @@ dump_client_table(struct blob_attr *head, int len) char* str = blobmsg_format_json_indent(attr, true, -1); printf("%s\n", str); - dump_client(tb); + int tmp_int_mac[ETH_ALEN]; + uint8_t tmp_mac[ETH_ALEN]; + sscanf((char*)hdr->name, "%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]; + + dump_client(tb, tmp_mac, bssid_addr, freq); } } @@ -276,8 +322,10 @@ static int parse_to_clients(struct blob_attr *msg) { blobmsg_parse(client_table_policy, __CLIENT_TABLE_MAX, tb, blob_data(msg), blob_len(msg)); - if (tb[CLIENT_TABLE]) { - dump_client_table(blobmsg_data(tb[CLIENT_TABLE]), blobmsg_data_len(tb[CLIENT_TABLE])); + + + if (tb[CLIENT_TABLE] && tb[CLIENT_TABLE_BSSID] && tb[CLIENT_TABLE_FREQ]) { + 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])); } printf("Parsing client request success!!!\n");