forked from NilsRo/usteer-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathband_steering.c
More file actions
136 lines (112 loc) · 4.26 KB
/
band_steering.c
File metadata and controls
136 lines (112 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) 2022 David Bauer <[email protected]>
*/
#include "usteer.h"
#include "node.h"
void usteer_band_steering_sta_update(struct sta_info *si)
{
if (si->connected == STA_NOT_CONNECTED) {
if (si->band_steering.signal_threshold != NO_SIGNAL) {
si->band_steering.signal_threshold = NO_SIGNAL;
}
return;
}
if (si->connected != STA_NOT_CONNECTED && si->band_steering.signal_threshold == NO_SIGNAL) {
si->band_steering.signal_threshold = si->signal;
MSG(DEBUG, "band steering station " MAC_ADDR_FMT " (%s) set threshold %d\n", MAC_ADDR_DATA(si->sta->addr), usteer_node_name(si->node), si->band_steering.signal_threshold);
return;
}
/* Adapt signal threshold to actual signal quality */
if (config.band_steering_threshold_enabled) {
if (si->signal < si->band_steering.signal_threshold) {
si->band_steering.signal_threshold--;
MSG(DEBUG, "band steering station " MAC_ADDR_FMT " (%s) reduce threshold %d, signal: %d\n", MAC_ADDR_DATA(si->sta->addr), usteer_node_name(si->node), si->band_steering.signal_threshold, si->signal);
}
if (si->signal < usteer_snr_to_signal(si->node, config.band_steering_min_snr) || si->signal < si->band_steering.signal_threshold + config.band_steering_signal_threshold)
si->band_steering.below_snr = true;
}
}
bool usteer_band_steering_is_target(struct usteer_local_node *ln, struct usteer_node *node)
{
if (&ln->node == node)
return false;
if (strcmp(ln->node.ssid, node->ssid))
return false;
if (node->freq < 4000)
return false;
if (!usteer_policy_node_below_max_assoc(node))
return false;
/* ToDo: Skip nodes with active load-kick */
return true;
}
static bool usteer_band_steering_has_target_iface(struct usteer_local_node *ln)
{
struct usteer_node *node;
for_each_local_node(node) {
if (usteer_band_steering_is_target(ln, node))
return true;
}
return false;
}
void usteer_band_steering_perform_steer(struct usteer_local_node *ln)
{
unsigned int min_count = DIV_ROUND_UP(config.band_steering_interval, config.local_sta_update);
struct sta_info *si;
uint32_t disassoc_timer;
uint32_t validity_period;
if (!config.band_steering_interval)
return;
/* Band-Steering is only available on 2.4 GHz interfaces */
if (ln->node.freq > 4000)
return;
/* Check if we have an interface we can steer to */
if (!usteer_band_steering_has_target_iface(ln))
return;
/* Only steer every interval */
if (ln->band_steering_interval < min_count) {
ln->band_steering_interval++;
return;
}
ln->band_steering_interval = 0;
list_for_each_entry(si, &ln->node.sta_info, node_list) {
/* Check if client is eligable to be steerd */
if (!usteer_policy_can_perform_roam(si))
continue;
/* Skip clients with insufficient SNR-state */
if (si->band_steering.below_snr) {
si->band_steering.below_snr = false;
continue;
}
/* Skip if in validity period */
if (current_time < si->roam_transition_request_validity_end)
continue;
if (si->bss_transition) {
si->roam_transition_request_validity_end = current_time + 10000;
validity_period = 10000 / usteer_local_node_get_beacon_interval(ln); /* ~ 10 seconds */
if (si->sta->aggressiveness >= 2) {
if (!si->kick_time)
si->kick_time = current_time + config.roam_kick_delay;
if (si->sta->aggressiveness >= 3)
disassoc_timer = (si->kick_time - current_time) / usteer_local_node_get_beacon_interval(ln);
else
disassoc_timer = 0;
usteer_ubus_band_steering_request(si, 0, true, disassoc_timer, true, validity_period);
} else
usteer_ubus_band_steering_request(si, 0, false, 0, true, validity_period);
}
si->band_steering.below_snr = false;
}
}