blob: 3f267b0c5e3d600342e4383f3ed354f9430cd94d [file] [log] [blame]
developer66e89bc2024-04-23 14:50:01 +08001From 12fe53a7919abb791658bcc7a74b8131f0362300 Mon Sep 17 00:00:00 2001
2From: "fancy.liu" <fancy.liu@mediatek.com>
3Date: Thu, 28 Sep 2023 18:03:08 +0800
4Subject: [PATCH 078/104] mtk: hostapd: ACS: Add EHT320 and HT40- support, fix
5 issue
6
71. Add 6G EHT320 support;
82. Add 2.4G HT40- support;
93. Fix issue: selected best channel is out of channels;
10
11Signed-off-by: fancy.liu <fancy.liu@mediatek.com>
12---
13 src/ap/acs.c | 191 +++++++++++++++++++++++++++++++++------------------
14 1 file changed, 124 insertions(+), 67 deletions(-)
15
16diff --git a/src/ap/acs.c b/src/ap/acs.c
17index cfa4a7d27..1fa8b8e64 100644
18--- a/src/ap/acs.c
19+++ b/src/ap/acs.c
20@@ -245,6 +245,7 @@ enum bw_type {
21 ACS_BW40,
22 ACS_BW80,
23 ACS_BW160,
24+ ACS_BW320,
25 };
26
27 struct bw_item {
28@@ -286,10 +287,16 @@ static const struct bw_item bw_160[] = {
29 { 6435, 6575, 111 }, { 6595, 6735, 143 },
30 { 6755, 6895, 175 }, { 6915, 7055, 207 }, { -1, -1, -1 }
31 };
32+static const struct bw_item bw_320[] = {
33+ { 5955, 6255, 31 }, { 6115, 6415, 63 }, { 6275, 6575, 95 },
34+ { 6435, 6735, 127 }, { 6595, 6895, 159 }, { 6755, 7055, 191 },
35+ { -1, -1, -1 }
36+};
37 static const struct bw_item *bw_desc[] = {
38 [ACS_BW40] = bw_40,
39 [ACS_BW80] = bw_80,
40 [ACS_BW160] = bw_160,
41+ [ACS_BW320] = bw_320,
42 };
43
44
45@@ -769,10 +776,19 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
46 struct hostapd_channel_data **ideal_chan,
47 long double *ideal_factor)
48 {
49- struct hostapd_channel_data *chan, *adj_chan = NULL, *best;
50+ struct hostapd_channel_data *chan, *adj_chan = NULL, *tmp_chan = NULL, *best;
51 long double factor;
52 int i, j;
53 unsigned int k;
54+ int ht40_plus = 1, sec_ch_factor = 1;
55+
56+ if (is_24ghz_mode(mode->mode)) {
57+ ht40_plus = (iface->conf->secondary_channel == -1) ? 0 : 1;
58+ sec_ch_factor = (iface->conf->secondary_channel == -1) ? -1 : 1;
59+ }
60+
61+ wpa_printf(MSG_INFO, "%s:%d, bw(%u), n_chans(%d), num_channels(%d), sec_ch(%d)",
62+ __func__, __LINE__, bw, n_chans, mode->num_channels, iface->conf->secondary_channel);
63
64 for (i = 0; i < mode->num_channels; i++) {
65 double total_weight;
66@@ -780,6 +796,9 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
67 bool update_best = true;
68
69 best = chan = &mode->channels[i];
70+ wpa_printf(MSG_INFO,
71+ "ACS: Channel[%d] %d: interference_factor %Lg",
72+ i, chan->chan, chan->interference_factor);
73
74 /* Since in the current ACS implementation the first channel is
75 * always a primary channel, skip channels not available as
76@@ -811,7 +830,7 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
77 iface->conf->country[2] == 0x4f)
78 continue;
79
80- if (!chan_bw_allowed(chan, bw, 1, 1)) {
81+ if (!chan_bw_allowed(chan, bw, ht40_plus, 1)) {
82 wpa_printf(MSG_DEBUG,
83 "ACS: Channel %d: BW %u is not supported",
84 chan->chan, bw);
85@@ -832,7 +851,8 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
86 }
87
88 if (mode->mode == HOSTAPD_MODE_IEEE80211A &&
89- (iface->conf->ieee80211ac || iface->conf->ieee80211ax)) {
90+ (iface->conf->ieee80211ac || iface->conf->ieee80211ax ||
91+ iface->conf->ieee80211be)) {
92 if (hostapd_get_oper_chwidth(iface->conf) ==
93 CONF_OPER_CHWIDTH_80MHZ &&
94 !acs_usable_bw_chan(chan, ACS_BW80)) {
95@@ -850,63 +870,86 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
96 chan->chan);
97 continue;
98 }
99- }
100
101- factor = 0;
102- if (acs_usable_chan(chan))
103- factor = chan->interference_factor;
104- total_weight = 1;
105-
106- for (j = 1; j < n_chans; j++) {
107- adj_chan = acs_find_chan(iface, chan->freq + (j * 20));
108- if (!adj_chan)
109- break;
110-
111- if (!chan_bw_allowed(adj_chan, bw, 1, 0)) {
112+ if (iface->conf->ieee80211be &&
113+ hostapd_get_oper_chwidth(iface->conf) ==
114+ CONF_OPER_CHWIDTH_320MHZ &&
115+ !acs_usable_bw_chan(chan, ACS_BW320)) {
116 wpa_printf(MSG_DEBUG,
117- "ACS: PRI Channel %d: secondary channel %d BW %u is not supported",
118- chan->chan, adj_chan->chan, bw);
119- break;
120+ "ACS: Channel %d: not allowed as primary channel for 320 MHz bandwidth",
121+ chan->chan);
122+ continue;
123 }
124+ }
125
126- if (acs_usable_chan(adj_chan)) {
127- factor += adj_chan->interference_factor;
128+ factor = 0;
129+ total_weight = 0;
130+
131+ if (!is_24ghz_mode(mode->mode)) {
132+ /* If the AP is in the 5 GHz or 6 GHz band, lets prefer a less
133+ * crowded primary channel if one was found in the segment */
134+ if (acs_usable_chan(chan)) {
135+ factor += chan->interference_factor;
136 total_weight += 1;
137- } else {
138- update_best = false;
139 }
140
141- /* find the best channel in this segment */
142- if (update_best &&
143- adj_chan->interference_factor <
144- best->interference_factor)
145- best = adj_chan;
146- }
147+ for (j = 1; j < n_chans; j++) {
148+ adj_chan = acs_find_chan(iface, chan->freq + j * 20);
149+ if (!adj_chan)
150+ break;
151
152- if (j != n_chans) {
153- wpa_printf(MSG_DEBUG, "ACS: Channel %d: not enough bandwidth",
154- chan->chan);
155- continue;
156- }
157+ if (!is_in_chanlist(iface, adj_chan) || !is_in_freqlist(iface, adj_chan))
158+ break;
159
160- /* If the AP is in the 5 GHz or 6 GHz band, lets prefer a less
161- * crowded primary channel if one was found in the segment */
162- if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
163- chan != best) {
164- wpa_printf(MSG_DEBUG,
165- "ACS: promoting channel %d over %d (less interference %Lg/%Lg)",
166- best->chan, chan->chan,
167- chan->interference_factor,
168- best->interference_factor);
169- chan = best;
170- }
171+ if (!chan_bw_allowed(adj_chan, bw, 1, 0)) {
172+ wpa_printf(MSG_DEBUG,
173+ "ACS: PRI Channel %d: secondary channel %d BW %u is not supported",
174+ chan->chan, adj_chan->chan, bw);
175+ break;
176+ }
177+
178+ update_best = true;
179+ if (acs_usable_chan(adj_chan)) {
180+ factor += adj_chan->interference_factor;
181+ total_weight += 1;
182+ } else {
183+ update_best = false;
184+ }
185
186- /* 2.4 GHz has overlapping 20 MHz channels. Include adjacent
187- * channel interference factor. */
188- if (is_24ghz_mode(mode->mode)) {
189+ /* find the best channel in this segment */
190+ if (update_best &&
191+ adj_chan->interference_factor < best->interference_factor)
192+ best = adj_chan;
193+ }
194+
195+ if (j != n_chans) {
196+ wpa_printf(MSG_DEBUG, "ACS: Channel %d: not enough bandwidth",
197+ chan->chan);
198+ continue;
199+ }
200+
201+ if (chan != best) {
202+ wpa_printf(MSG_INFO,
203+ "ACS: promoting channel %d over %d (less interference %Lg/%Lg)",
204+ best->chan, chan->chan,
205+ chan->interference_factor,
206+ best->interference_factor);
207+ chan = best;
208+ }
209+ } else {
210 for (j = 0; j < n_chans; j++) {
211+ /* Will set primary_channel / secondary_channel(40M case) weight to 1 */
212+ tmp_chan = acs_find_chan(iface, chan->freq +
213+ (j * sec_ch_factor * 20));
214+ if (tmp_chan && acs_usable_chan(tmp_chan)) {
215+ factor += tmp_chan->interference_factor;
216+ total_weight += 1;
217+ }
218+
219+ /* 2.4 GHz has overlapping 20 MHz channels. Include adjacent channel
220+ interference factor, separately for primary/secondary channel. */
221 adj_chan = acs_find_chan(iface, chan->freq +
222- (j * 20) - 5);
223+ (j * sec_ch_factor * 20) - 5);
224 if (adj_chan && acs_usable_chan(adj_chan)) {
225 factor += ACS_ADJ_WEIGHT *
226 adj_chan->interference_factor;
227@@ -914,7 +957,7 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
228 }
229
230 adj_chan = acs_find_chan(iface, chan->freq +
231- (j * 20) - 10);
232+ (j * sec_ch_factor * 20) - 10);
233 if (adj_chan && acs_usable_chan(adj_chan)) {
234 factor += ACS_NEXT_ADJ_WEIGHT *
235 adj_chan->interference_factor;
236@@ -922,7 +965,7 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
237 }
238
239 adj_chan = acs_find_chan(iface, chan->freq +
240- (j * 20) + 5);
241+ (j * sec_ch_factor * 20) + 5);
242 if (adj_chan && acs_usable_chan(adj_chan)) {
243 factor += ACS_ADJ_WEIGHT *
244 adj_chan->interference_factor;
245@@ -930,7 +973,7 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
246 }
247
248 adj_chan = acs_find_chan(iface, chan->freq +
249- (j * 20) + 10);
250+ (j * sec_ch_factor * 20) + 10);
251 if (adj_chan && acs_usable_chan(adj_chan)) {
252 factor += ACS_NEXT_ADJ_WEIGHT *
253 adj_chan->interference_factor;
254@@ -939,7 +982,8 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
255 }
256 }
257
258- factor /= total_weight;
259+ if (total_weight)
260+ factor /= total_weight;
261
262 bias = NULL;
263 if (iface->conf->acs_chan_bias) {
264@@ -958,11 +1002,11 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface,
265
266 if (bias) {
267 factor *= bias->bias;
268- wpa_printf(MSG_DEBUG,
269+ wpa_printf(MSG_INFO,
270 "ACS: * channel %d: total interference = %Lg (%f bias)",
271 chan->chan, factor, bias->bias);
272 } else {
273- wpa_printf(MSG_DEBUG,
274+ wpa_printf(MSG_INFO,
275 "ACS: * channel %d: total interference = %Lg",
276 chan->chan, factor);
277 }
278@@ -1015,19 +1059,12 @@ acs_find_ideal_chan(struct hostapd_iface *iface)
279 goto bw_selected;
280 }
281
282- /* TODO: HT40- support */
283-
284- if (iface->conf->ieee80211n &&
285- iface->conf->secondary_channel == -1) {
286- wpa_printf(MSG_ERROR, "ACS: HT40- is not supported yet. Please try HT40+");
287- return NULL;
288- }
289-
290 if (iface->conf->ieee80211n &&
291 iface->conf->secondary_channel)
292 n_chans = 2;
293
294- if (iface->conf->ieee80211ac || iface->conf->ieee80211ax) {
295+ if (iface->conf->ieee80211ac || iface->conf->ieee80211ax ||
296+ iface->conf->ieee80211be) {
297 switch (hostapd_get_oper_chwidth(iface->conf)) {
298 case CONF_OPER_CHWIDTH_80MHZ:
299 n_chans = 4;
300@@ -1037,6 +1074,7 @@ acs_find_ideal_chan(struct hostapd_iface *iface)
301 break;
302 default:
303 break;
304+ /* 320 is supported only in 6GHz 11be mode */
305 }
306 }
307
308@@ -1057,7 +1095,7 @@ bw_selected:
309 }
310
311 if (ideal_chan) {
312- wpa_printf(MSG_DEBUG, "ACS: Ideal channel is %d (%d MHz) with total interference factor of %Lg",
313+ wpa_printf(MSG_INFO, "ACS: Ideal channel is %d (%d MHz) with total interference factor of %Lg",
314 ideal_chan->chan, ideal_chan->freq, ideal_factor);
315
316 #ifdef CONFIG_IEEE80211BE
317@@ -1072,6 +1110,21 @@ bw_selected:
318 return rand_chan;
319 }
320
321+static int acs_get_center_freq_320mhz(int channel)
322+{
323+ if (channel >= 1 && channel <= 45)
324+ return 31;
325+ else if (channel >= 49 && channel <= 77)
326+ return 63;
327+ else if (channel >= 81 && channel <= 109)
328+ return 95;
329+ else if (channel >= 113 && channel <= 141)
330+ return 127;
331+ else if (channel >= 145 && channel <= 173)
332+ return 159;
333+ else
334+ return 191;
335+}
336
337 static void acs_adjust_secondary(struct hostapd_iface *iface)
338 {
339@@ -1099,7 +1152,7 @@ static void acs_adjust_center_freq(struct hostapd_iface *iface)
340 {
341 int center;
342
343- wpa_printf(MSG_DEBUG, "ACS: Adjusting VHT center frequency");
344+ wpa_printf(MSG_DEBUG, "ACS: Adjusting center frequency");
345
346 switch (hostapd_get_oper_chwidth(iface->conf)) {
347 case CONF_OPER_CHWIDTH_USE_HT:
348@@ -1115,6 +1168,9 @@ static void acs_adjust_center_freq(struct hostapd_iface *iface)
349 case CONF_OPER_CHWIDTH_80MHZ:
350 center = acs_get_bw_center_chan(iface->freq, ACS_BW80);
351 break;
352+ case CONF_OPER_CHWIDTH_320MHZ:
353+ center = acs_get_center_freq_320mhz(iface->conf->channel);
354+ break;
355 case CONF_OPER_CHWIDTH_160MHZ:
356 center = acs_get_bw_center_chan(iface->freq, ACS_BW160);
357 break;
358@@ -1122,7 +1178,7 @@ static void acs_adjust_center_freq(struct hostapd_iface *iface)
359 /* TODO: How can this be calculated? Adjust
360 * acs_find_ideal_chan() */
361 wpa_printf(MSG_INFO,
362- "ACS: Only VHT20/40/80/160 is supported now");
363+ "ACS: Only VHT20/40/80/160 EHT320 is supported now");
364 return;
365 }
366
367@@ -1185,7 +1241,8 @@ static void acs_study(struct hostapd_iface *iface)
368 iface->conf->punct_bitmap = ideal_chan->punct_bitmap;
369 #endif /* CONFIG_IEEE80211BE */
370
371- if (iface->conf->ieee80211ac || iface->conf->ieee80211ax) {
372+ if (iface->conf->ieee80211ac || iface->conf->ieee80211ax ||
373+ iface->conf->ieee80211be) {
374 acs_adjust_secondary(iface);
375 acs_adjust_center_freq(iface);
376 }
377--
3782.39.2
379