return;
ubus_abort_request(ubus_ctx, &ln->req);
+ uloop_timeout_cancel(&ln->req_timer);
ln->req_state = REQ_IDLE;
}
+static void
+usteer_local_node_pending_bss_tm_free(struct usteer_local_node *ln)
+{
+ struct usteer_bss_tm_query *query, *tmp;
+
+ list_for_each_entry_safe(query, tmp, &ln->bss_tm_queries, list) {
+ list_del(&query->list);
+ free(query);
+ }
+}
+
static void
usteer_free_node(struct ubus_context *ctx, struct usteer_local_node *ln)
{
h->free_node(&ln->node);
}
+ usteer_local_node_pending_bss_tm_free(ln);
usteer_local_node_state_reset(ln);
usteer_sta_node_cleanup(&ln->node);
- uloop_timeout_cancel(&ln->req_timer);
uloop_timeout_cancel(&ln->update);
+ uloop_timeout_cancel(&ln->bss_tm_queries_timeout);
avl_delete(&local_nodes, &ln->node.avl);
ubus_unregister_subscriber(ctx, &ln->ev);
+ kvlist_free(&ln->node_info);
free(ln);
}
usteer_free_node(ctx, ln);
}
+static int
+usteer_handle_bss_tm_query(struct usteer_local_node *ln, struct blob_attr *msg)
+{
+ enum {
+ BSS_TM_QUERY_ADDRESS,
+ BSS_TM_QUERY_DIALOG_TOKEN,
+ BSS_TM_QUERY_CANDIDATE_LIST,
+ __BSS_TM_QUERY_MAX
+ };
+ struct blobmsg_policy policy[__BSS_TM_QUERY_MAX] = {
+ [BSS_TM_QUERY_ADDRESS] = { .name = "address", .type = BLOBMSG_TYPE_STRING },
+ [BSS_TM_QUERY_DIALOG_TOKEN] = { .name = "dialog-token", .type = BLOBMSG_TYPE_INT8 },
+ [BSS_TM_QUERY_CANDIDATE_LIST] = { .name = "candidate-list", .type = BLOBMSG_TYPE_STRING },
+ };
+ struct blob_attr *tb[__BSS_TM_QUERY_MAX];
+ struct usteer_bss_tm_query *query;
+ uint8_t *sta_addr;
+
+ blobmsg_parse(policy, __BSS_TM_QUERY_MAX, tb, blob_data(msg), blob_len(msg));
+
+ if (!tb[BSS_TM_QUERY_ADDRESS] || !tb[BSS_TM_QUERY_DIALOG_TOKEN])
+ return 0;
+
+ query = calloc(1, sizeof(*query));
+ if (!query)
+ return 0;
+
+ query->dialog_token = blobmsg_get_u8(tb[BSS_TM_QUERY_DIALOG_TOKEN]);
+
+ sta_addr = (uint8_t *) ether_aton(blobmsg_get_string(tb[BSS_TM_QUERY_ADDRESS]));
+ if (!sta_addr)
+ return 0;
+
+ memcpy(query->sta_addr, sta_addr, 6);
+
+ list_add(&query->list, &ln->bss_tm_queries);
+ uloop_timeout_set(&ln->bss_tm_queries_timeout, 1);
+
+ return 1;
+}
+
static int
usteer_handle_event(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
usteer_update_time();
+ ln = container_of(obj, struct usteer_local_node, ev.obj);
+
+ if(!strcmp(method, "bss-transition-query")) {
+ return usteer_handle_bss_tm_query(ln, msg);
+ }
+
for (i = 0; i < ARRAY_SIZE(event_types); i++) {
if (strcmp(method, event_types[i]) != 0)
continue;
[MSG_ASSOC] = { "assoc", BLOBMSG_TYPE_BOOL },
};
struct blob_attr *tb[__MSG_MAX];
+ struct usteer_remote_node *rn;
+ struct sta_info *remote_si;
blobmsg_parse(policy, __MSG_MAX, tb, blobmsg_data(data), blobmsg_data_len(data));
- if (tb[MSG_ASSOC] && blobmsg_get_u8(tb[MSG_ASSOC]))
- si->connected = 1;
+ if (tb[MSG_ASSOC] && blobmsg_get_u8(tb[MSG_ASSOC])) {
+ if (si->connected == STA_NOT_CONNECTED) {
+ /* New connection. Check if STA roamed. */
+ for_each_remote_node(rn) {
+ remote_si = usteer_sta_info_get(si->sta, &rn->node, NULL);
+ if (!remote_si)
+ continue;
+
+ if (current_time - remote_si->last_connected < config.roam_process_timeout) {
+ rn->node.roam_events.source++;
+ /* Don't abort looking for roam sources here.
+ * The client might have roamed via another node
+ * within the roam-timeout.
+ */
+ }
+ }
+ }
+ si->connected = STA_CONNECTED;
+ }
+}
- if (si->node->freq < 4000)
- si->sta->seen_2ghz = 1;
- else
- si->sta->seen_5ghz = 1;
+static void
+usteer_local_node_update_sta_rrm(const uint8_t *addr, struct blob_attr *client_attr)
+{
+ static const struct blobmsg_policy rrm_policy = {
+ .name = "rrm",
+ .type = BLOBMSG_TYPE_ARRAY,
+ };
+ struct blob_attr *sta_blob = NULL;
+ struct sta *sta;
+
+ if (!addr)
+ return;
+
+ /* Don't create the STA */
+ sta = usteer_sta_get(addr, false);
+ if (!sta)
+ return;
+
+ blobmsg_parse(&rrm_policy, 1, &sta_blob, blobmsg_data(client_attr), blobmsg_data_len(client_attr));
+ if (!sta_blob)
+ return;
+
+ sta->rrm = blobmsg_get_u32(blobmsg_data(sta_blob));
}
static void
int n_assoc = 0;
int rem;
+ usteer_update_time();
+
list_for_each_entry(si, &node->sta_info, node_list) {
if (si->connected)
- si->connected = 2;
+ si->connected = STA_DISCONNECTED;
}
blobmsg_for_each_attr(cur, cl, rem) {
h->update_sta(node, si);
}
usteer_local_node_assoc_update(si, cur);
- if (si->connected == 1)
+ if (si->connected == STA_CONNECTED) {
+ si->last_connected = current_time;
n_assoc++;
+ }
+
+ /* Read RRM information */
+ usteer_local_node_update_sta_rrm(addr, cur);
}
node->n_assoc = n_assoc;
list_for_each_entry(si, &node->sta_info, node_list) {
- if (si->connected != 2)
+ if (si->connected != STA_DISCONNECTED)
continue;
- si->connected = 0;
- usteer_sta_info_update_timeout(si, config.local_sta_timeout);
+ usteer_sta_disconnected(si);
MSG(VERBOSE, "station "MAC_ADDR_FMT" disconnected from node %s\n",
MAC_ADDR_DATA(si->sta->addr), usteer_node_name(node));
}
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)
{
uloop_timeout_set(&ln->req_timer, 1);
}
-static void
+static bool
usteer_add_rrm_data(struct usteer_local_node *ln, struct usteer_node *node)
{
if (node == &ln->node)
- return;
+ return false;
if (!node->rrm_nr)
- return;
+ return false;
+ /* Remote node only adds same SSID. Required for local-node. */
if (strcmp(ln->node.ssid, node->ssid) != 0)
- return;
+ return false;
blobmsg_add_field(&b, BLOBMSG_TYPE_ARRAY, "",
blobmsg_data(node->rrm_nr),
blobmsg_data_len(node->rrm_nr));
+
+ return true;
}
static void
usteer_local_node_prepare_rrm_set(struct usteer_local_node *ln)
{
- struct usteer_remote_node *rn;
- struct usteer_node *node;
+ struct usteer_node *node, *last_remote_neighbor = NULL;
+ int i = 0;
void *c;
c = blobmsg_open_array(&b, "list");
- avl_for_each_element(&local_nodes, node, avl)
- usteer_add_rrm_data(ln, node);
- avl_for_each_element(&remote_nodes, rn, avl)
- usteer_add_rrm_data(ln, &rn->node);
+ for_each_local_node(node) {
+ if (i >= config.max_neighbor_reports)
+ break;
+ if (usteer_add_rrm_data(ln, node))
+ i++;
+ }
+
+ while (i < config.max_neighbor_reports) {
+ node = usteer_node_get_next_neighbor(&ln->node, last_remote_neighbor);
+ if (!node) {
+ /* No more nodes available */
+ break;
+ }
+
+ last_remote_neighbor = node;
+ if (usteer_add_rrm_data(ln, node))
+ i++;
+ }
+
blobmsg_close_array(&b, c);
}
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);
uloop_timeout_set(timeout, config.local_sta_update);
}
+static void
+usteer_local_node_process_bss_tm_queries(struct uloop_timeout *timeout)
+{
+ struct usteer_bss_tm_query *query, *tmp;
+ struct usteer_local_node *ln;
+ struct usteer_node *node;
+ struct sta_info *si;
+ struct sta *sta;
+
+ uint8_t validity_period = 100; /* ~ 10 seconds */
+
+ ln = container_of(timeout, struct usteer_local_node, bss_tm_queries_timeout);
+ node = &ln->node;
+
+ list_for_each_entry_safe(query, tmp, &ln->bss_tm_queries, list) {
+ sta = usteer_sta_get(query->sta_addr, false);
+ if (!sta)
+ continue;
+
+ si = usteer_sta_info_get(sta, node, false);
+ if (!si)
+ continue;
+
+ usteer_ubus_bss_transition_request(si, query->dialog_token, false, false, validity_period);
+ }
+
+ /* Free pending queries we can not handle */
+ usteer_local_node_pending_bss_tm_free(ln);
+}
+
static struct usteer_local_node *
usteer_get_node(struct ubus_context *ctx, const char *name)
{
ln = calloc_a(sizeof(*ln), &str, strlen(name) + 1);
node = &ln->node;
node->type = NODE_TYPE_LOCAL;
+ node->created = current_time;
node->avl.key = strcpy(str, name);
ln->ev.remove_cb = usteer_handle_remove;
ln->ev.cb = usteer_handle_event;
ln->req_timer.cb = usteer_local_node_state_next;
ubus_register_subscriber(ctx, &ln->ev);
avl_insert(&local_nodes, &node->avl);
- uloop_timeout_set(&ln->update, 1);
+ kvlist_init(&ln->node_info, kvlist_blob_len);
INIT_LIST_HEAD(&node->sta_info);
+ ln->bss_tm_queries_timeout.cb = usteer_local_node_process_bss_tm_queries;
+ INIT_LIST_HEAD(&ln->bss_tm_queries);
return ln;
}
val = alloca(strlen(node_up_script) + strlen(ln->iface) + 8);
sprintf(val, "%s '%s'", node_up_script, ln->iface);
if (system(val))
- fprintf(stderr, "failed to execute %s\n", val);
+ MSG(INFO, "failed to execute %s\n", val);
+}
+
+static void
+usteer_check_node_enabled(struct usteer_local_node *ln)
+{
+ bool ssid_disabled = config.ssid_list;
+ struct blob_attr *cur;
+ int rem;
+
+ blobmsg_for_each_attr(cur, config.ssid_list, rem) {
+ if (strcmp(blobmsg_get_string(cur), ln->node.ssid) != 0)
+ continue;
+
+ ssid_disabled = false;
+ break;
+ }
+
+ if (ln->node.disabled == ssid_disabled)
+ return;
+
+ ln->node.disabled = ssid_disabled;
+
+ if (ssid_disabled) {
+ MSG(INFO, "Disconnecting from local node %s\n", usteer_node_name(&ln->node));
+ usteer_local_node_state_reset(ln);
+ usteer_sta_node_cleanup(&ln->node);
+ uloop_timeout_cancel(&ln->update);
+ ubus_unsubscribe(ubus_ctx, &ln->ev, ln->obj_id);
+ return;
+ }
+
+ MSG(INFO, "Connecting to local node %s\n", usteer_node_name(&ln->node));
+ ubus_subscribe(ubus_ctx, &ln->ev, ln->obj_id);
+ uloop_timeout_set(&ln->update, 1);
+ usteer_node_run_update_script(&ln->node);
}
static void
if (strncmp(name, "hostapd.", iface - name) != 0)
return;
- MSG(INFO, "Connecting to local node %s\n", name);
+ MSG(INFO, "Creating local node %s\n", name);
ln = usteer_get_node(ctx, name);
ln->obj_id = id;
ln->iface = usteer_node_name(&ln->node) + offset;
- ln->ifindex = if_nametoindex(iface);
+ ln->ifindex = if_nametoindex(ln->iface);
blob_buf_init(&b, 0);
blobmsg_add_u32(&b, "notify_response", 1);
blobmsg_add_u8(&b, "bss_transition", 1);
ubus_invoke(ctx, id, "bss_mgmt_enable", b.head, NULL, NULL, 1000);
- ubus_subscribe(ctx, &ln->ev, id);
-
list_for_each_entry(h, &node_handlers, list) {
if (!h->init_node)
continue;
h->init_node(&ln->node);
}
- usteer_node_run_update_script(&ln->node);
+ ln->node.disabled = true;
+ usteer_check_node_enabled(ln);
}
static void
node_up_script = strdup(val);
- avl_for_each_element(&local_nodes, node, avl)
+ for_each_local_node(node)
usteer_node_run_update_script(node);
}
blobmsg_add_string(buf, "node_up_script", node_up_script);
}
+void config_set_ssid_list(struct blob_attr *data)
+{
+ struct usteer_local_node *ln;
+
+ free(config.ssid_list);
+
+ if (data && blobmsg_len(data))
+ config.ssid_list = blob_memdup(data);
+ else
+ config.ssid_list = NULL;
+
+ avl_for_each_element(&local_nodes, ln, node.avl)
+ usteer_check_node_enabled(ln);
+}
+
+void config_get_ssid_list(struct blob_buf *buf)
+{
+ if (config.ssid_list)
+ blobmsg_add_blob(buf, config.ssid_list);
+}
+
void
usteer_local_nodes_init(struct ubus_context *ctx)
{