sta: add sta_connection_state enum
Make the connection state of a sta-info more readable by introducing an enum for the STA connection state. Also switch come comparison cases to use the explicit enum values to make the code more readable. Signed-off-by: David Bauer <mail@david-bauer.net>
This commit is contained in:
10
local_node.c
10
local_node.c
@@ -153,7 +153,7 @@ usteer_local_node_assoc_update(struct sta_info *si, struct blob_attr *data)
|
|||||||
|
|
||||||
blobmsg_parse(policy, __MSG_MAX, tb, blobmsg_data(data), blobmsg_data_len(data));
|
blobmsg_parse(policy, __MSG_MAX, tb, blobmsg_data(data), blobmsg_data_len(data));
|
||||||
if (tb[MSG_ASSOC] && blobmsg_get_u8(tb[MSG_ASSOC]))
|
if (tb[MSG_ASSOC] && blobmsg_get_u8(tb[MSG_ASSOC]))
|
||||||
si->connected = 1;
|
si->connected = STA_CONNECTED;
|
||||||
|
|
||||||
if (si->node->freq < 4000)
|
if (si->node->freq < 4000)
|
||||||
si->sta->seen_2ghz = 1;
|
si->sta->seen_2ghz = 1;
|
||||||
@@ -174,7 +174,7 @@ usteer_local_node_set_assoc(struct usteer_local_node *ln, struct blob_attr *cl)
|
|||||||
|
|
||||||
list_for_each_entry(si, &node->sta_info, node_list) {
|
list_for_each_entry(si, &node->sta_info, node_list) {
|
||||||
if (si->connected)
|
if (si->connected)
|
||||||
si->connected = 2;
|
si->connected = STA_DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
blobmsg_for_each_attr(cur, cl, rem) {
|
blobmsg_for_each_attr(cur, cl, rem) {
|
||||||
@@ -193,17 +193,17 @@ usteer_local_node_set_assoc(struct usteer_local_node *ln, struct blob_attr *cl)
|
|||||||
h->update_sta(node, si);
|
h->update_sta(node, si);
|
||||||
}
|
}
|
||||||
usteer_local_node_assoc_update(si, cur);
|
usteer_local_node_assoc_update(si, cur);
|
||||||
if (si->connected == 1)
|
if (si->connected == STA_CONNECTED)
|
||||||
n_assoc++;
|
n_assoc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
node->n_assoc = n_assoc;
|
node->n_assoc = n_assoc;
|
||||||
|
|
||||||
list_for_each_entry(si, &node->sta_info, node_list) {
|
list_for_each_entry(si, &node->sta_info, node_list) {
|
||||||
if (si->connected != 2)
|
if (si->connected != STA_DISCONNECTED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
si->connected = 0;
|
si->connected = STA_NOT_CONNECTED;
|
||||||
usteer_sta_info_update_timeout(si, config.local_sta_timeout);
|
usteer_sta_info_update_timeout(si, config.local_sta_timeout);
|
||||||
MSG(VERBOSE, "station "MAC_ADDR_FMT" disconnected from node %s\n",
|
MSG(VERBOSE, "station "MAC_ADDR_FMT" disconnected from node %s\n",
|
||||||
MAC_ADDR_DATA(si->sta->addr), usteer_node_name(node));
|
MAC_ADDR_DATA(si->sta->addr), usteer_node_name(node));
|
||||||
|
6
policy.c
6
policy.c
@@ -334,7 +334,7 @@ usteer_local_node_roam_check(struct usteer_local_node *ln, struct uevent *ev)
|
|||||||
min_signal = snr_to_signal(&ln->node, min_signal);
|
min_signal = snr_to_signal(&ln->node, min_signal);
|
||||||
|
|
||||||
list_for_each_entry(si, &ln->node.sta_info, node_list) {
|
list_for_each_entry(si, &ln->node.sta_info, node_list) {
|
||||||
if (!si->connected || si->signal >= min_signal ||
|
if (si->connected != STA_CONNECTED || si->signal >= min_signal ||
|
||||||
current_time - si->roam_kick < config.roam_trigger_interval) {
|
current_time - si->roam_kick < config.roam_trigger_interval) {
|
||||||
usteer_roam_set_state(si, ROAM_TRIGGER_IDLE, ev);
|
usteer_roam_set_state(si, ROAM_TRIGGER_IDLE, ev);
|
||||||
continue;
|
continue;
|
||||||
@@ -365,7 +365,7 @@ usteer_local_node_snr_kick(struct usteer_local_node *ln)
|
|||||||
ev.threshold.ref = min_signal;
|
ev.threshold.ref = min_signal;
|
||||||
|
|
||||||
list_for_each_entry(si, &ln->node.sta_info, node_list) {
|
list_for_each_entry(si, &ln->node.sta_info, node_list) {
|
||||||
if (!si->connected)
|
if (si->connected != STA_CONNECTED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (si->signal >= min_signal)
|
if (si->signal >= min_signal)
|
||||||
@@ -434,7 +434,7 @@ usteer_local_node_kick(struct usteer_local_node *ln)
|
|||||||
list_for_each_entry(si, &ln->node.sta_info, node_list) {
|
list_for_each_entry(si, &ln->node.sta_info, node_list) {
|
||||||
struct sta_info *tmp;
|
struct sta_info *tmp;
|
||||||
|
|
||||||
if (!si->connected)
|
if (si->connected != STA_CONNECTED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (is_more_kickable(kick1, si))
|
if (is_more_kickable(kick1, si))
|
||||||
|
4
sta.c
4
sta.c
@@ -111,7 +111,7 @@ usteer_sta_info_get(struct sta *sta, struct usteer_node *node, bool *create)
|
|||||||
void
|
void
|
||||||
usteer_sta_info_update_timeout(struct sta_info *si, int timeout)
|
usteer_sta_info_update_timeout(struct sta_info *si, int timeout)
|
||||||
{
|
{
|
||||||
if (si->connected == 1)
|
if (si->connected == STA_CONNECTED)
|
||||||
usteer_timeout_cancel(&tq, &si->timeout);
|
usteer_timeout_cancel(&tq, &si->timeout);
|
||||||
else if (timeout > 0)
|
else if (timeout > 0)
|
||||||
usteer_timeout_set(&tq, &si->timeout, timeout);
|
usteer_timeout_set(&tq, &si->timeout, timeout);
|
||||||
@@ -145,7 +145,7 @@ void
|
|||||||
usteer_sta_info_update(struct sta_info *si, int signal, bool avg)
|
usteer_sta_info_update(struct sta_info *si, int signal, bool avg)
|
||||||
{
|
{
|
||||||
/* ignore probe request signal when connected */
|
/* ignore probe request signal when connected */
|
||||||
if (si->connected == 1 && si->signal != NO_SIGNAL && !avg)
|
if (si->connected == STA_CONNECTED && si->signal != NO_SIGNAL && !avg)
|
||||||
signal = NO_SIGNAL;
|
signal = NO_SIGNAL;
|
||||||
|
|
||||||
if (signal != NO_SIGNAL)
|
if (signal != NO_SIGNAL)
|
||||||
|
2
ubus.c
2
ubus.c
@@ -540,7 +540,7 @@ void usteer_ubus_kick_client(struct sta_info *si)
|
|||||||
blobmsg_add_u32(&b, "reason", config.load_kick_reason_code);
|
blobmsg_add_u32(&b, "reason", config.load_kick_reason_code);
|
||||||
blobmsg_add_u8(&b, "deauth", 1);
|
blobmsg_add_u8(&b, "deauth", 1);
|
||||||
ubus_invoke(ubus_ctx, ln->obj_id, "del_client", b.head, NULL, 0, 100);
|
ubus_invoke(ubus_ctx, ln->obj_id, "del_client", b.head, NULL, 0, 100);
|
||||||
si->connected = 0;
|
si->connected = STA_NOT_CONNECTED;
|
||||||
si->roam_kick = current_time;
|
si->roam_kick = current_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
usteer.h
6
usteer.h
@@ -54,6 +54,12 @@ enum usteer_node_type {
|
|||||||
NODE_TYPE_REMOTE,
|
NODE_TYPE_REMOTE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum usteer_sta_connection_state {
|
||||||
|
STA_NOT_CONNECTED = 0,
|
||||||
|
STA_CONNECTED = 1,
|
||||||
|
STA_DISCONNECTED = 2,
|
||||||
|
};
|
||||||
|
|
||||||
struct sta_info;
|
struct sta_info;
|
||||||
struct usteer_local_node;
|
struct usteer_local_node;
|
||||||
struct usteer_remote_host;
|
struct usteer_remote_host;
|
||||||
|
Reference in New Issue
Block a user