mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
add get_hearing_map call
This commit is contained in:
parent
a78891d0df
commit
cfde7b7c97
5 changed files with 63 additions and 8 deletions
|
@ -8,6 +8,8 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <libubox/blobmsg_json.h>
|
||||
|
||||
|
||||
#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 -------------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue