From 3b51bfbaf600edd68660e1daa809f830190b9b50 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Sat, 8 Jan 2022 23:26:03 +0100 Subject: [PATCH] local-node: obtain channel + op-class In order to send passive beacon-requests, channel and op-class of nodes are required. Obtain this information per local-node from hostapd. Signed-off-by: David Bauer --- local_node.c | 34 ++++++++++++++++++++++++++++++++++ node.h | 1 + parse.c | 7 +++++++ remote.c | 4 ++++ remote.h | 4 ++++ usteer.h | 2 ++ 6 files changed, 52 insertions(+) diff --git a/local_node.c b/local_node.c index 6f2d6a7..e441266 100644 --- a/local_node.c +++ b/local_node.c @@ -342,6 +342,36 @@ usteer_local_node_list_cb(struct ubus_request *req, int type, struct blob_attr * usteer_local_node_set_assoc(ln, tb[MSG_CLIENTS]); } +static void +usteer_local_node_status_cb(struct ubus_request *req, int type, struct blob_attr *msg) +{ + enum { + MSG_FREQ, + MSG_CHANNEL, + MSG_OP_CLASS, + __MSG_MAX, + }; + static struct blobmsg_policy policy[__MSG_MAX] = { + [MSG_FREQ] = { "freq", BLOBMSG_TYPE_INT32 }, + [MSG_CHANNEL] = { "channel", BLOBMSG_TYPE_INT32 }, + [MSG_OP_CLASS] = { "op_class", BLOBMSG_TYPE_INT32 }, + }; + struct blob_attr *tb[__MSG_MAX]; + struct usteer_local_node *ln; + struct usteer_node *node; + + ln = container_of(req, struct usteer_local_node, req); + node = &ln->node; + + blobmsg_parse(policy, __MSG_MAX, tb, blob_data(msg), blob_len(msg)); + if (tb[MSG_FREQ]) + node->freq = blobmsg_get_u32(tb[MSG_FREQ]); + if (tb[MSG_CHANNEL]) + node->channel = blobmsg_get_u32(tb[MSG_CHANNEL]); + if (tb[MSG_FREQ]) + node->op_class = blobmsg_get_u32(tb[MSG_OP_CLASS]); +} + static void usteer_local_node_rrm_nr_cb(struct ubus_request *req, int type, struct blob_attr *msg) { @@ -438,6 +468,10 @@ usteer_local_node_state_next(struct uloop_timeout *timeout) ubus_invoke_async(ubus_ctx, ln->obj_id, "get_clients", b.head, &ln->req); ln->req.data_cb = usteer_local_node_list_cb; break; + case REQ_STATUS: + ubus_invoke_async(ubus_ctx, ln->obj_id, "get_status", b.head, &ln->req); + ln->req.data_cb = usteer_local_node_status_cb; + break; case REQ_RRM_SET_LIST: usteer_local_node_prepare_rrm_set(ln); ubus_invoke_async(ubus_ctx, ln->obj_id, "rrm_nr_set", b.head, &ln->req); diff --git a/node.h b/node.h index 05c32ae..6d5f8fd 100644 --- a/node.h +++ b/node.h @@ -25,6 +25,7 @@ enum local_req_state { REQ_IDLE, REQ_CLIENTS, + REQ_STATUS, REQ_RRM_SET_LIST, REQ_RRM_GET_OWN, __REQ_MAX diff --git a/parse.c b/parse.c index b0b7bc2..2aa3716 100644 --- a/parse.c +++ b/parse.c @@ -64,6 +64,8 @@ bool parse_apmsg_node(struct apmsg_node *msg, struct blob_attr *data) [APMSG_NODE_LOAD] = { .type = BLOB_ATTR_INT32 }, [APMSG_NODE_RRM_NR] = { .type = BLOB_ATTR_NESTED }, [APMSG_NODE_NODE_INFO] = { .type = BLOB_ATTR_NESTED }, + [APMSG_NODE_CHANNEL] = { .type = BLOB_ATTR_INT32 }, + [APMSG_NODE_OP_CLASS] = { .type = BLOB_ATTR_INT32 }, }; struct blob_attr *tb[__APMSG_NODE_MAX]; struct blob_attr *cur; @@ -90,6 +92,11 @@ bool parse_apmsg_node(struct apmsg_node *msg, struct blob_attr *data) msg->max_assoc = get_int32(tb[APMSG_NODE_MAX_ASSOC]); msg->rrm_nr = NULL; + if (tb[APMSG_NODE_CHANNEL] && tb[APMSG_NODE_OP_CLASS]) { + msg->channel = blob_get_int32(tb[APMSG_NODE_CHANNEL]); + msg->op_class = blob_get_int32(tb[APMSG_NODE_OP_CLASS]); + } + cur = tb[APMSG_NODE_RRM_NR]; if (cur && blob_len(cur) >= sizeof(struct blob_attr) && blob_len(cur) >= blob_pad_len(blob_data(cur))) { diff --git a/remote.c b/remote.c index cb4f3dd..bad5f8b 100644 --- a/remote.c +++ b/remote.c @@ -287,6 +287,8 @@ interface_add_node(struct usteer_remote_host *host, struct blob_attr *data) node = interface_get_node(host, msg.name); node->check = 0; node->node.freq = msg.freq; + node->node.channel = msg.channel; + node->node.op_class = msg.op_class; node->node.n_assoc = msg.n_assoc; node->node.max_assoc = msg.max_assoc; node->node.noise = msg.noise; @@ -565,6 +567,8 @@ static void usteer_send_node(struct usteer_node *node, struct sta_info *sta) blob_put_int32(&buf, APMSG_NODE_LOAD, node->load); blob_put_int32(&buf, APMSG_NODE_N_ASSOC, node->n_assoc); blob_put_int32(&buf, APMSG_NODE_MAX_ASSOC, node->max_assoc); + blob_put_int32(&buf, APMSG_NODE_OP_CLASS, node->op_class); + blob_put_int32(&buf, APMSG_NODE_CHANNEL, node->channel); blob_put(&buf, APMSG_NODE_BSSID, node->bssid, sizeof(node->bssid)); if (node->rrm_nr) { r = blob_nest_start(&buf, APMSG_NODE_RRM_NR); diff --git a/remote.h b/remote.h index 9361b25..a1486e7 100644 --- a/remote.h +++ b/remote.h @@ -49,6 +49,8 @@ enum { APMSG_NODE_RRM_NR, APMSG_NODE_NODE_INFO, APMSG_NODE_BSSID, + APMSG_NODE_CHANNEL, + APMSG_NODE_OP_CLASS, __APMSG_NODE_MAX }; @@ -57,6 +59,8 @@ struct apmsg_node { const char *ssid; const char *bssid; int freq; + int channel; + int op_class; int n_assoc; int max_assoc; int noise; diff --git a/usteer.h b/usteer.h index f4ba800..23c9e41 100644 --- a/usteer.h +++ b/usteer.h @@ -83,6 +83,8 @@ struct usteer_node { bool disabled; int freq; + int channel; + int op_class; int noise; int n_assoc; int max_assoc; -- 2.30.2