diff --git a/src/include/datastorage.h b/src/include/datastorage.h index f648858..06a1325 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -45,6 +45,7 @@ typedef struct client_s { uint8_t vht; uint8_t wps; uint8_t mfp; + time_t time; uint32_t aid; } client; @@ -57,6 +58,8 @@ typedef struct client_s { struct client_s client_array[ARRAY_CLIENT_LEN]; pthread_mutex_t client_array_mutex; +void insert_client_to_array(client entry); + void client_array_insert(client entry); client* client_array_delete(client entry); void print_client_array(); diff --git a/src/main.c b/src/main.c index e03d91e..1b18b5f 100644 --- a/src/main.c +++ b/src/main.c @@ -53,10 +53,17 @@ int main(int argc, char **argv) { return 1; } + if (pthread_mutex_init(&client_array_mutex, NULL) != 0) { + printf("\n mutex init failed\n"); + return 1; + } + init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 0); pthread_t tid; pthread_create(&tid, NULL, &remove_array_thread, NULL); + + //pthread_create(&tid, NULL, &remove_thread, NULL); dawn_init_ubus(ubus_socket, opt_hostapd_dir); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 5865fcf..a9a3210 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -76,7 +76,7 @@ void client_array_insert(client entry) int i; for(i = 0; i <= client_entry_last; i++) { - if(!client_array_go_next("bs", 2, entry, client_array[i])) + if(!client_array_go_next("bc", 2, entry, client_array[i])) { break; } @@ -254,7 +254,20 @@ void *remove_array_thread(void *arg) { return 0; } +void insert_client_to_array(client entry) +{ + pthread_mutex_lock(&client_array_mutex); + entry.time = time(0); + printf("Deleting Client:\n"); + client_array_delete(entry); + printf("Inserting Client:\n"); + client_array_insert(entry); + printf("Inseted Client\n"); + + + pthread_mutex_unlock(&client_array_mutex); +} diff --git a/src/utils/ubus.c b/src/utils/ubus.c index cb33a74..a9fb831 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -287,6 +287,8 @@ dump_client(struct blob_attr **tb, uint8_t client_addr[], const char* bssid_addr client_entry.aid = blobmsg_get_u32(tb[CLIENT_AID]); } + insert_client_to_array(client_entry); + printf("Dumped Client!\n"); }