From 1a2aa2c6e2fafad3438414f55ad1e1af60186bb4 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 21 Nov 2017 18:37:12 +0100 Subject: [PATCH 1/8] insert macs to list --- files/mac_list | 2 ++ src/include/datastorage.h | 13 ++++++++ src/main.c | 1 - src/storage/datastorage.c | 63 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 files/mac_list diff --git a/files/mac_list b/files/mac_list new file mode 100644 index 0000000..8a35cbc --- /dev/null +++ b/files/mac_list @@ -0,0 +1,2 @@ +a4:2b:b0:de:f1:fd +f0:79:60:1c:26:f0 diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 93f845f..d375738 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -13,9 +13,22 @@ #define ETH_ALEN 6 #endif +/* Mac */ + +// ---------------- Defines ------------------- +#define MAC_LIST_LENGTH 100 + +// ---------------- Structs ---------------- +uint8_t mac_list[MAC_LIST_LENGTH][ETH_ALEN]; + +// ---------------- Functions ---------- +void insert_macs_from_file(); + /* Metric */ +struct probe_metric_s dawn_metric; + // ---------------- Structs ---------------- struct probe_metric_s { int ht_support; diff --git a/src/main.c b/src/main.c index dba35be..947a67e 100644 --- a/src/main.c +++ b/src/main.c @@ -108,7 +108,6 @@ int main(int argc, char **argv) { sigaction(SIGTERM, &newSigAction, NULL); /* catch term signal */ sigaction(SIGINT, &newSigAction, NULL); /* catch interrupt signal */ - gcrypt_init(); gcrypt_set_key_and_iv(shared_key, iv); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index c8eda89..bc44789 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -41,9 +41,12 @@ int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_ int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]); +int mac_in_maclist(uint8_t mac[]); + int probe_entry_last = -1; int client_entry_last = -1; int ap_entry_last = -1; +int mac_list_entry_last = -1; void remove_probe_array_cb(struct uloop_timeout *t); @@ -134,7 +137,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) { } int kick_client(struct client_s client_entry) { - return better_ap_available(client_entry.bssid_addr, client_entry.client_addr); + return !mac_in_maclist(client_entry.client_addr) && better_ap_available(client_entry.bssid_addr, client_entry.client_addr); } void kick_clients(uint8_t bssid[], uint32_t id) { @@ -600,6 +603,64 @@ void insert_client_to_array(client entry) { pthread_mutex_unlock(&client_array_mutex); } +void insert_macs_from_file() +{ + FILE * fp; + char * line = NULL; + size_t len = 0; + ssize_t read; + + fp = fopen("/etc/config/dawn", "r"); + if (fp == NULL) + exit(EXIT_FAILURE); + + while ((read = getline(&line, &len, fp)) != -1) { + printf("Retrieved line of length %zu :\n", read); + printf("%s", line); + + int tmp_int_mac[ETH_ALEN]; + sscanf(line, MACSTR, STR2MAC(tmp_int_mac)); + + for (int i = 0; i < ETH_ALEN; ++i) { + mac_list[mac_list_entry_last][i] = (uint8_t) tmp_int_mac[i]; + } + } + + printf("Printing MAC List:\n"); + for(int i = 0; i <= mac_list_entry_last; i++) + { + char mac_buf_target[20]; + sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[0])); + printf("%d: %s\n", i, mac_buf_target); + } + + fclose(fp); + if (line) + free(line); + exit(EXIT_SUCCESS); +} + +int mac_in_maclist(uint8_t mac[]) +{ + for(int i = 0; i <= mac_list_entry_last; i++) + { + if(mac_is_equal(mac, mac_list[i])) + { + return 1; + } + } + return 0; +} + + + + + + + + + + node *delete_probe_req(node **ret_remove, node *head, uint8_t bssid_addr[], uint8_t client_addr[]); From 2a9d87698836644427c6c2d2a0fd129f6c0465bc Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 15:11:43 +0100 Subject: [PATCH 2/8] add function to main --- src/main.c | 2 ++ src/storage/datastorage.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 947a67e..1d4805e 100644 --- a/src/main.c +++ b/src/main.c @@ -136,6 +136,8 @@ int main(int argc, char **argv) { init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); + insert_macs_from_file(); + dawn_init_ubus(ubus_socket, opt_hostapd_dir); return 0; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index bc44789..ce47b42 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -610,7 +610,7 @@ void insert_macs_from_file() size_t len = 0; ssize_t read; - fp = fopen("/etc/config/dawn", "r"); + fp = fopen("/etc/dawn/mac_list", "r"); if (fp == NULL) exit(EXIT_FAILURE); @@ -621,6 +621,7 @@ void insert_macs_from_file() int tmp_int_mac[ETH_ALEN]; sscanf(line, MACSTR, STR2MAC(tmp_int_mac)); + mac_list_entry_last++; for (int i = 0; i < ETH_ALEN; ++i) { mac_list[mac_list_entry_last][i] = (uint8_t) tmp_int_mac[i]; } @@ -630,7 +631,7 @@ void insert_macs_from_file() for(int i = 0; i <= mac_list_entry_last; i++) { char mac_buf_target[20]; - sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[0])); + sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[i])); printf("%d: %s\n", i, mac_buf_target); } From 4c16b53e5d9411afaac3be2b02d3655d6964b007 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 16:10:32 +0100 Subject: [PATCH 3/8] add object --- src/utils/ubus.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 33e7488..27f4d41 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -473,6 +473,8 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { //ubus_call_umdns(); + ubus_add_oject(); + uloop_run(); close_socket(); @@ -686,4 +688,60 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) { send_string_enc(str); return 0; +} + +enum { + MAC_ADDR, + __ADD_DEL_MAC_MAX +}; + +static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = { + [MAC_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, +}; + +static const struct ubus_method dawn_methods[] = { + UBUS_METHOD("hello", test_hello, add_del_policy), +}; + +static struct ubus_object_type dawn_object_type = + UBUS_OBJECT_TYPE("test", dawn_methods); + +static struct ubus_object dawn_object = { + .name = "dawn", + .type = &dawn_object_type, + .methods = dawn_methods, + .n_methods = ARRAY_SIZE(dawn_methods), +}; + +static int +add_mac(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { + + struct blob_attr *tb[__ADD_DEL_MAC_MAX]; + uint8_t addr[ETH_ALEN]; + + blobmsg_parse(add_del_policy, __ADD_DEL_MAC_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[MAC_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + printf("ADDED SOME MAC!\n"); +} + +static void ubus_add_oject(void) +{ + int ret; + + ret = ubus_add_object(ctx, &dawn_object); + if (ret) + fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret)); + + /*ret = ubus_register_subscriber(ctx, &test_event); + if (ret) + fprintf(stderr, "Failed to add watch handler: %s\n", ubus_strerror(ret)); + */ } \ No newline at end of file From 8eaba2697452e72fb48351f475415a3bf967dfea Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 22 Nov 2017 16:11:35 +0100 Subject: [PATCH 4/8] add object --- src/include/datastorage.h | 1 + src/include/utils.h | 2 ++ src/storage/datastorage.c | 17 ++++++++++++++++- src/utils/ubus.c | 17 +++++++++++++---- src/utils/utils.c | 16 ++++++++++++++++ 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index d375738..dce9263 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -23,6 +23,7 @@ uint8_t mac_list[MAC_LIST_LENGTH][ETH_ALEN]; // ---------------- Functions ---------- void insert_macs_from_file(); +int insert_to_maclist(uint8_t mac[]); /* Metric */ diff --git a/src/include/utils.h b/src/include/utils.h index ec0e87a..e07a776 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -15,4 +15,6 @@ int hwaddr_aton(const char *txt, uint8_t *addr); int convert_mac(char *in, char *out); +void write_mac_to_file(char* path, uint8_t addr[]); + #endif \ No newline at end of file diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index ce47b42..2eb08f4 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -638,9 +638,24 @@ void insert_macs_from_file() fclose(fp); if (line) free(line); - exit(EXIT_SUCCESS); + //exit(EXIT_SUCCESS); } +int insert_to_maclist(uint8_t mac[]) +{ + if(mac_in_maclist(mac)) + { + return 0; + } + + mac_list_entry_last++; + for (int i = 0; i < ETH_ALEN; ++i) { + mac_list[mac_list_entry_last][i] = mac[i]; + } + return 0; +} + + int mac_in_maclist(uint8_t mac[]) { for(int i = 0; i <= mac_list_entry_last; i++) diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 27f4d41..caba791 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -136,9 +136,15 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir); static int ubus_get_clients(); +static int +add_mac(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); + int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); void hostapd_array_delete(uint32_t id); +static void ubus_add_oject(); int hostapd_array_check_id(uint32_t id) { @@ -700,11 +706,11 @@ static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = { }; static const struct ubus_method dawn_methods[] = { - UBUS_METHOD("hello", test_hello, add_del_policy), + UBUS_METHOD("add_mac", add_mac, add_del_policy), }; static struct ubus_object_type dawn_object_type = - UBUS_OBJECT_TYPE("test", dawn_methods); + UBUS_OBJECT_TYPE("dawn", dawn_methods); static struct ubus_object dawn_object = { .name = "dawn", @@ -729,10 +735,13 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj, if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr)) return UBUS_STATUS_INVALID_ARGUMENT; - printf("ADDED SOME MAC!\n"); + insert_to_maclist(addr); + write_mac_to_file("/etc/dawn/mac_list", addr); + + return 0; } -static void ubus_add_oject(void) +static void ubus_add_oject() { int ret; diff --git a/src/utils/utils.c b/src/utils/utils.c index 323d4b2..8af0488 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -44,3 +44,19 @@ int convert_mac(char *in, char *out) { return 0; } +void write_mac_to_file(char* path, uint8_t addr[]) +{ + FILE *f = fopen(path, "a"); + if (f == NULL) + { + printf("Error opening file!\n"); + exit(1); + } + + char mac_buf[20]; + sprintf(mac_buf, MACSTR, MAC2STR(addr)); + + fprintf(f, "%s\n", mac_buf); + + fclose(f); +} \ No newline at end of file From cfde7b7c97af4964d2e46948f2cad372700da121 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 16:21:00 +0100 Subject: [PATCH 5/8] add get_hearing_map call --- src/include/datastorage.h | 4 ++++ src/include/ubus.h | 4 ++-- src/main.c | 2 +- src/storage/datastorage.c | 35 +++++++++++++++++++++++++++++++++++ src/utils/ubus.c | 26 +++++++++++++++++++++----- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 492bce6..efe3580 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -8,6 +8,8 @@ #include #include #include +#include + #ifndef ETH_ALEN #define ETH_ALEN 6 @@ -189,6 +191,8 @@ void print_ap_array(); ap ap_array_get_ap(uint8_t bssid_addr[]); +int build_hearing_map_sort_client(struct blob_buf *b); + /* Utils */ // ---------------- Defines ------------------- diff --git a/src/include/ubus.h b/src/include/ubus.h index 5c169fc..7788cb0 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -6,8 +6,6 @@ #include "datastorage.h" -#define MIN_PROBE_REQ 2 // TODO: Parse from config file... - int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir); int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req); @@ -34,4 +32,6 @@ void update_hostapd_sockets(struct uloop_timeout *t); void add_client_update_timer(time_t time); +void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr); + #endif diff --git a/src/main.c b/src/main.c index 0942347..694e075 100644 --- a/src/main.c +++ b/src/main.c @@ -102,7 +102,7 @@ int main(int argc, char **argv) { init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast); - insert_macs_from_file(); + //insert_macs_from_file(); dawn_init_ubus(ubus_socket, hostapd_dir_glob); return 0; diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index b35c6ac..7c8c0ff 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -68,6 +68,41 @@ struct uloop_timeout ap_timeout = { .cb = remove_ap_array_cb }; +int build_hearing_map_sort_client(struct blob_buf *b) +{ + pthread_mutex_lock(&probe_array_mutex); + + void *client_list, *ap_list; + char ap_mac_buf[20]; + char client_mac_buf[20]; + + blob_buf_init(b, 0); + int i; + for (i = 0; i <= probe_entry_last; i++) { + int k; + sprintf(client_mac_buf, MACSTR, MAC2STR(probe_array[i].client_addr)); + client_list = blobmsg_open_table(b, client_mac_buf); + for (k = i; i <= probe_entry_last; k++){ + if(!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) + { + i = k - 1; + break; + } + sprintf(ap_mac_buf, MACSTR, MAC2STR(probe_array[k].bssid_addr)); + ap_list = blobmsg_open_table(b, ap_mac_buf); + blobmsg_add_u32(b, "signal", probe_array[k].signal); + blobmsg_add_u32(b, "freq", probe_array[k].freq); + blobmsg_add_u8(b, "ht_support", probe_array[k].ht_support); + blobmsg_add_u8(b, "vht_support", probe_array[k].vht_support); + blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k])); + blobmsg_close_table(b, ap_list); + } + blobmsg_close_table(b, client_list); + } + pthread_mutex_unlock(&probe_array_mutex); + return 0; +} + int eval_probe_metric(struct probe_entry_s probe_entry) { int score = 0; diff --git a/src/utils/ubus.c b/src/utils/ubus.c index d12be7b..a69fef7 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -142,7 +142,11 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg); -int hostapd_array_check_id(uint32_t id); +static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); + + int hostapd_array_check_id(uint32_t id); void hostapd_array_insert(uint32_t id); @@ -199,8 +203,7 @@ void hostapd_array_delete(uint32_t id) { } -static void -blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) { +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); @@ -483,6 +486,7 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) { uloop_run(); + close_socket(); ubus_free(ctx); @@ -715,6 +719,9 @@ static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = { static const struct ubus_method dawn_methods[] = { UBUS_METHOD("add_mac", add_mac, add_del_policy), + UBUS_METHOD_NOARG("get_hearing_map", get_hearing_map) + //UBUS_METHOD_NOARG("get_aps"); + //UBUS_METHOD_NOARG("get_clients"); }; static struct ubus_object_type dawn_object_type = @@ -727,8 +734,7 @@ static struct ubus_object dawn_object = { .n_methods = ARRAY_SIZE(dawn_methods), }; -static int -add_mac(struct ubus_context *ctx, struct ubus_object *obj, +static int add_mac(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { @@ -749,6 +755,15 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { + + build_hearing_map_sort_client(&b); + ubus_send_reply(ctx, req, b.head); + return 0; +} + static void ubus_add_oject() { int ret; @@ -756,6 +771,7 @@ static void ubus_add_oject() ret = ubus_add_object(ctx, &dawn_object); if (ret) fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret)); + printf("ADDED UBUS OBJECT!!!\n"); /*ret = ubus_register_subscriber(ctx, &test_event); if (ret) From 9eddd6323391ddddf64b8c54d1687152560de9ff Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 17:18:49 +0100 Subject: [PATCH 6/8] cleanup main --- src/main.c | 77 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/src/main.c b/src/main.c index 694e075..5e73b5f 100644 --- a/src/main.c +++ b/src/main.c @@ -8,19 +8,16 @@ #include "networksocket.h" #include "ubus.h" #include "dawn_uci.h" -#include "dawn_uci.h" #include "crypto.h" -#define BUFSIZE 17 -#define BUFSIZE_DIR 256 - void daemon_shutdown(); void signal_handler(int sig); -struct sigaction newSigAction; +struct sigaction signal_action; void daemon_shutdown() { + // kill threads close_socket(); uci_clear(); @@ -36,50 +33,24 @@ void daemon_shutdown() { } void signal_handler(int sig) { - printf("SOME SIGNAL RECEIVED!\n"); switch (sig) { case SIGHUP: + daemon_shutdown(); break; case SIGINT: + daemon_shutdown(); + break; case SIGTERM: daemon_shutdown(); exit(EXIT_SUCCESS); - break; default: + daemon_shutdown(); break; } } -int main(int argc, char **argv) { - //free_counter = 0; - - const char *ubus_socket = NULL; - // int ch; - - argc -= optind; - argv += optind; - - newSigAction.sa_handler = signal_handler; - sigemptyset(&newSigAction.sa_mask); - newSigAction.sa_flags = 0; - - sigaction(SIGHUP, &newSigAction, NULL); - sigaction(SIGTERM, &newSigAction, NULL); - sigaction(SIGINT, &newSigAction, NULL); - - uci_init(); - struct network_config_s net_config = uci_get_dawn_network(); - printf("Broadcst bla: %s\n", net_config.broadcast_ip); - - gcrypt_init(); - gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); - - struct time_config_s time_config = uci_get_time_config(); - timeout_config = time_config; // TODO: Refactor... - - hostapd_dir_glob = uci_get_dawn_hostapd_dir(); - sort_string = (char*) uci_get_dawn_sort_order(); - +int init_mutex() +{ if (pthread_mutex_init(&list_mutex, NULL) != 0) { printf("\n mutex init failed\n"); return 1; @@ -99,6 +70,38 @@ int main(int argc, char **argv) { printf("\n mutex init failed\n"); return 1; } + return 0; +} + +int main(int argc, char **argv) { + + const char *ubus_socket = NULL; + + argc -= optind; + argv += optind; + + // connect signals + signal_action.sa_handler = signal_handler; + sigemptyset(&signal_action.sa_mask); + signal_action.sa_flags = 0; + sigaction(SIGHUP, &signal_action, NULL); + sigaction(SIGTERM, &signal_action, NULL); + sigaction(SIGINT, &signal_action, NULL); + + uci_init(); + struct network_config_s net_config = uci_get_dawn_network(); + printf("Broadcst bla: %s\n", net_config.broadcast_ip); + + gcrypt_init(); + gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); + + struct time_config_s time_config = uci_get_time_config(); + timeout_config = time_config; // TODO: Refactor... + + hostapd_dir_glob = uci_get_dawn_hostapd_dir(); + sort_string = (char*) uci_get_dawn_sort_order(); + + init_mutex(); init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast); From 389be8fca12c33ab8a5595ba793c51e79c12cf42 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 17:25:18 +0100 Subject: [PATCH 7/8] fix maclist --- src/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 5e73b5f..4252b4f 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,8 @@ void daemon_shutdown(); void signal_handler(int sig); +int init_mutex(); + struct sigaction signal_action; void daemon_shutdown() { @@ -105,7 +107,7 @@ int main(int argc, char **argv) { init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast); - //insert_macs_from_file(); + insert_macs_from_file(); dawn_init_ubus(ubus_socket, hostapd_dir_glob); return 0; From 590de3617f85d3e98d106144e048b6b30928b76a Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 17:37:36 +0100 Subject: [PATCH 8/8] fix maclist --- src/storage/datastorage.c | 14 +++++++++++++- src/utils/ubus.c | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 7c8c0ff..5ec49f5 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -94,6 +94,17 @@ int build_hearing_map_sort_client(struct blob_buf *b) blobmsg_add_u32(b, "freq", probe_array[k].freq); blobmsg_add_u8(b, "ht_support", probe_array[k].ht_support); blobmsg_add_u8(b, "vht_support", probe_array[k].vht_support); + + ap ap_entry = ap_array_get_ap(probe_array[k].bssid_addr); + + // check if ap entry is available + if (mac_is_equal(ap_entry.bssid_addr, probe_array[k].bssid_addr)) { + blobmsg_add_u32(b, "channel_utilization", ap_entry.channel_utilization); + blobmsg_add_u32(b, "num_sta", ap_entry.station_count); + blobmsg_add_u32(b, "ht", ap_entry.ht); + blobmsg_add_u32(b, "vht", ap_entry.vht); + } + blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k])); blobmsg_close_table(b, ap_list); } @@ -747,13 +758,14 @@ int insert_to_maclist(uint8_t mac[]) { if(mac_in_maclist(mac)) { - return 0; + return -1; } mac_list_entry_last++; for (int i = 0; i < ETH_ALEN; ++i) { mac_list[mac_list_entry_last][i] = mac[i]; } + return 0; } diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a69fef7..30c99f4 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -749,8 +749,10 @@ static int add_mac(struct ubus_context *ctx, struct ubus_object *obj, if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr)) return UBUS_STATUS_INVALID_ARGUMENT; - insert_to_maclist(addr); - write_mac_to_file("/etc/dawn/mac_list", addr); + if(insert_to_maclist(addr) == 0) + { + write_mac_to_file("/etc/dawn/mac_list", addr); + } return 0; }