From 04ef308f8ca2803aa23e66f7740c9ee48ffe4b7d Mon Sep 17 00:00:00 2001 From: David Bauer Date: Fri, 21 Jan 2022 22:31:49 +0100 Subject: [PATCH] local-node: save beacon-reports Add received beacon-reports from STAs to the measurement database. Signed-off-by: David Bauer --- local_node.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/local_node.c b/local_node.c index 25387ab..29eb33d 100644 --- a/local_node.c +++ b/local_node.c @@ -143,6 +143,56 @@ usteer_handle_bss_tm_query(struct usteer_local_node *ln, struct blob_attr *msg) return 1; } +static int +usteer_local_node_handle_beacon_report(struct usteer_local_node *ln, struct blob_attr *msg) +{ + enum { + BR_ADDRESS, + BR_BSSID, + BR_RCPI, + BR_RSNI, + __BR_MAX + }; + struct blobmsg_policy policy[__BR_MAX] = { + [BR_ADDRESS] = { .name = "address", .type = BLOBMSG_TYPE_STRING }, + [BR_BSSID] = { .name = "bssid", .type = BLOBMSG_TYPE_STRING }, + [BR_RCPI] = { .name = "rcpi", .type = BLOBMSG_TYPE_INT16 }, + [BR_RSNI] = { .name = "rsni", .type = BLOBMSG_TYPE_INT16 }, + }; + struct blob_attr *tb[__BR_MAX]; + + struct usteer_beacon_report br; + struct usteer_node *node; + uint8_t *addr; + struct sta *sta; + + blobmsg_parse(policy, __BR_MAX, tb, blob_data(msg), blob_len(msg)); + if (!tb[BR_ADDRESS] || !tb[BR_BSSID] || !tb[BR_RCPI] || !tb[BR_RSNI]) + return 0; + + addr = (uint8_t *) ether_aton(blobmsg_get_string(tb[BR_ADDRESS])); + if (!addr) + return 0; + + sta = usteer_sta_get(addr, false); + if (!sta) + return 0; + + addr = (uint8_t *) ether_aton(blobmsg_get_string(tb[BR_BSSID])); + if (!addr) + return 0; + + node = usteer_node_by_bssid(addr); + if (!node) + return 0; + + br.rcpi = (uint8_t)blobmsg_get_u16(tb[BR_RCPI]); + br.rsni = (uint8_t)blobmsg_get_u16(tb[BR_RSNI]); + + usteer_measurement_report_add_beacon_report(sta, node, &br, current_time); + return 0; +} + static int usteer_handle_event(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -178,6 +228,8 @@ usteer_handle_event(struct ubus_context *ctx, struct ubus_object *obj, if(!strcmp(method, "bss-transition-query")) { return usteer_handle_bss_tm_query(ln, msg); + } else if(!strcmp(method, "beacon-report")) { + return usteer_local_node_handle_beacon_report(ln, msg); } for (i = 0; i < ARRAY_SIZE(event_types); i++) { -- 2.30.2