From 1be4ca829c90c80bd425cf937a4ba3aa1a24c837 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 22 Dec 2017 18:26:23 +0100 Subject: [PATCH] add network overview --- src/include/datastorage.h | 2 ++ src/storage/datastorage.c | 33 +++++++++++++++++++++++++++++++++ src/utils/ubus.c | 19 +++++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index efe3580..da829f7 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -193,6 +193,8 @@ ap ap_array_get_ap(uint8_t bssid_addr[]); int build_hearing_map_sort_client(struct blob_buf *b); +int build_network_overview(struct blob_buf *b); + /* Utils */ // ---------------- Defines ------------------- diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index a7e3a3b..d1fddab 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -114,6 +114,39 @@ int build_hearing_map_sort_client(struct blob_buf *b) return 0; } +int build_network_overview(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 <= client_entry_last; i++) { + int k; + sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr)); + ap_list = blobmsg_open_table(b, ap_mac_buf); + for (k = i; i <= client_entry_last; k++){ + if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) + { + i = k - 1; + break; + } + sprintf(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr)); + client_list = blobmsg_open_table(b, client_mac_buf); + blobmsg_add_u32(b, "freq", client_array[k].freq); + blobmsg_add_u32(b, "ht", client_array[k].ht); + blobmsg_add_u32(b, "vht", client_array[k].vht); + blobmsg_close_table(b, client_list); + } + blobmsg_close_table(b, ap_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 30c99f4..17c7d13 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -146,7 +146,11 @@ 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); +static int get_network(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); @@ -719,7 +723,8 @@ 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_hearing_map", get_hearing_map), + UBUS_METHOD_NOARG("get_network", get_network) //UBUS_METHOD_NOARG("get_aps"); //UBUS_METHOD_NOARG("get_clients"); }; @@ -766,6 +771,16 @@ static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj, return 0; } + +static int get_network(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { + + build_network_overview(&b); + ubus_send_reply(ctx, req, b.head); + return 0; +} + static void ubus_add_oject() { int ret;