]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/common/hw_features_common.c
4f1c4935a4fa610940d50d752f369f0c72a41c12
[thirdparty/hostap.git] / src / common / hw_features_common.c
1 /*
2 * Common hostapd/wpa_supplicant HW features
3 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2015, Qualcomm Atheros, Inc.
5 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */
9
10 #include "includes.h"
11
12 #include "common.h"
13 #include "defs.h"
14 #include "ieee802_11_defs.h"
15 #include "ieee802_11_common.h"
16 #include "hw_features_common.h"
17
18
19 struct hostapd_channel_data * hw_get_channel_chan(struct hostapd_hw_modes *mode,
20 int chan, int *freq)
21 {
22 int i;
23
24 if (freq)
25 *freq = 0;
26
27 if (!mode)
28 return NULL;
29
30 for (i = 0; i < mode->num_channels; i++) {
31 struct hostapd_channel_data *ch = &mode->channels[i];
32 if (ch->chan == chan) {
33 if (freq)
34 *freq = ch->freq;
35 return ch;
36 }
37 }
38
39 return NULL;
40 }
41
42
43 struct hostapd_channel_data *
44 hw_get_channel_freq(enum hostapd_hw_mode mode, int freq, int *chan,
45 struct hostapd_hw_modes *hw_features, int num_hw_features)
46 {
47 int i, j;
48
49 if (chan)
50 *chan = 0;
51
52 if (!hw_features)
53 return NULL;
54
55 for (j = 0; j < num_hw_features; j++) {
56 struct hostapd_hw_modes *curr_mode = &hw_features[j];
57
58 if (curr_mode->mode != mode)
59 continue;
60 for (i = 0; i < curr_mode->num_channels; i++) {
61 struct hostapd_channel_data *ch =
62 &curr_mode->channels[i];
63
64 if (ch->freq == freq) {
65 if (chan)
66 *chan = ch->chan;
67 return ch;
68 }
69 }
70 }
71
72 return NULL;
73 }
74
75
76 int hw_get_freq(struct hostapd_hw_modes *mode, int chan)
77 {
78 int freq;
79
80 hw_get_channel_chan(mode, chan, &freq);
81
82 return freq;
83 }
84
85
86 int hw_get_chan(enum hostapd_hw_mode mode, int freq,
87 struct hostapd_hw_modes *hw_features, int num_hw_features)
88 {
89 int chan;
90
91 hw_get_channel_freq(mode, freq, &chan, hw_features, num_hw_features);
92
93 return chan;
94 }
95
96
97 int allowed_ht40_channel_pair(enum hostapd_hw_mode mode,
98 struct hostapd_channel_data *p_chan,
99 struct hostapd_channel_data *s_chan)
100 {
101 int ok, first;
102 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 140,
103 149, 157, 165, 184, 192 };
104 size_t k;
105 int ht40_plus, pri_chan, sec_chan;
106
107 if (!p_chan || !s_chan)
108 return 0;
109 pri_chan = p_chan->chan;
110 sec_chan = s_chan->chan;
111
112 ht40_plus = pri_chan < sec_chan;
113
114 if (pri_chan == sec_chan || !sec_chan) {
115 if (chan_pri_allowed(p_chan))
116 return 1; /* HT40 not used */
117
118 wpa_printf(MSG_ERROR, "Channel %d is not allowed as primary",
119 pri_chan);
120 return 0;
121 }
122
123 wpa_printf(MSG_DEBUG,
124 "HT40: control channel: %d (%d MHz), secondary channel: %d (%d MHz)",
125 pri_chan, p_chan->freq, sec_chan, s_chan->freq);
126
127 /* Verify that HT40 secondary channel is an allowed 20 MHz
128 * channel */
129 if ((s_chan->flag & HOSTAPD_CHAN_DISABLED) ||
130 (ht40_plus && !(p_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P)) ||
131 (!ht40_plus && !(p_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M))) {
132 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
133 sec_chan);
134 return 0;
135 }
136
137 /*
138 * Verify that HT40 primary,secondary channel pair is allowed per
139 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
140 * 2.4 GHz rules allow all cases where the secondary channel fits into
141 * the list of allowed channels (already checked above).
142 */
143 if (mode != HOSTAPD_MODE_IEEE80211A)
144 return 1;
145
146 first = pri_chan < sec_chan ? pri_chan : sec_chan;
147
148 ok = 0;
149 for (k = 0; k < ARRAY_SIZE(allowed); k++) {
150 if (first == allowed[k]) {
151 ok = 1;
152 break;
153 }
154 }
155 if (!ok) {
156 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
157 pri_chan, sec_chan);
158 return 0;
159 }
160
161 return 1;
162 }
163
164
165 void get_pri_sec_chan(struct wpa_scan_res *bss, int *pri_chan, int *sec_chan)
166 {
167 struct ieee80211_ht_operation *oper;
168 struct ieee802_11_elems elems;
169
170 *pri_chan = *sec_chan = 0;
171
172 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
173 if (elems.ht_operation) {
174 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
175 *pri_chan = oper->primary_chan;
176 if (oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
177 int sec = oper->ht_param &
178 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
179 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
180 *sec_chan = *pri_chan + 4;
181 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
182 *sec_chan = *pri_chan - 4;
183 }
184 }
185 }
186
187
188 int check_40mhz_5g(struct wpa_scan_results *scan_res,
189 struct hostapd_channel_data *pri_chan,
190 struct hostapd_channel_data *sec_chan)
191 {
192 int pri_bss, sec_bss;
193 int bss_pri_chan, bss_sec_chan;
194 size_t i;
195 int match;
196
197 if (!scan_res || !pri_chan || !sec_chan ||
198 pri_chan->freq == sec_chan->freq)
199 return 0;
200
201 /*
202 * Switch PRI/SEC channels if Beacons were detected on selected SEC
203 * channel, but not on selected PRI channel.
204 */
205 pri_bss = sec_bss = 0;
206 for (i = 0; i < scan_res->num; i++) {
207 struct wpa_scan_res *bss = scan_res->res[i];
208 if (bss->freq == pri_chan->freq)
209 pri_bss++;
210 else if (bss->freq == sec_chan->freq)
211 sec_bss++;
212 }
213 if (sec_bss && !pri_bss) {
214 wpa_printf(MSG_INFO,
215 "Switch own primary and secondary channel to get secondary channel with no Beacons from other BSSes");
216 return 2;
217 }
218
219 /*
220 * Match PRI/SEC channel with any existing HT40 BSS on the same
221 * channels that we are about to use (if already mixed order in
222 * existing BSSes, use own preference).
223 */
224 match = 0;
225 for (i = 0; i < scan_res->num; i++) {
226 struct wpa_scan_res *bss = scan_res->res[i];
227 get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
228 if (pri_chan->chan == bss_pri_chan &&
229 sec_chan->chan == bss_sec_chan) {
230 match = 1;
231 break;
232 }
233 }
234 if (!match) {
235 for (i = 0; i < scan_res->num; i++) {
236 struct wpa_scan_res *bss = scan_res->res[i];
237 get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
238 if (pri_chan->chan == bss_sec_chan &&
239 sec_chan->chan == bss_pri_chan) {
240 wpa_printf(MSG_INFO, "Switch own primary and "
241 "secondary channel due to BSS "
242 "overlap with " MACSTR,
243 MAC2STR(bss->bssid));
244 return 2;
245 }
246 }
247 }
248
249 return 1;
250 }
251
252
253 static int check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq, int start,
254 int end)
255 {
256 struct ieee802_11_elems elems;
257 struct ieee80211_ht_operation *oper;
258
259 if (bss->freq < start || bss->freq > end || bss->freq == pri_freq)
260 return 0;
261
262 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
263 if (!elems.ht_capabilities) {
264 wpa_printf(MSG_DEBUG, "Found overlapping legacy BSS: "
265 MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
266 return 1;
267 }
268
269 if (elems.ht_operation) {
270 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
271 if (oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)
272 return 0;
273
274 wpa_printf(MSG_DEBUG, "Found overlapping 20 MHz HT BSS: "
275 MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
276 return 1;
277 }
278 return 0;
279 }
280
281
282 /*
283 * Returns:
284 * 0: no impact
285 * 1: overlapping BSS
286 * 2: overlapping BSS with 40 MHz intolerant advertisement
287 */
288 int check_bss_coex_40mhz(struct wpa_scan_res *bss, int pri_freq, int sec_freq)
289 {
290 int affected_start, affected_end;
291 struct ieee802_11_elems elems;
292 int pri_chan, sec_chan;
293 int pri = bss->freq;
294 int sec = pri;
295
296 if (pri_freq == sec_freq)
297 return 1;
298
299 affected_start = (pri_freq + sec_freq) / 2 - 25;
300 affected_end = (pri_freq + sec_freq) / 2 + 25;
301
302 /* Check for overlapping 20 MHz BSS */
303 if (check_20mhz_bss(bss, pri_freq, affected_start, affected_end)) {
304 wpa_printf(MSG_DEBUG, "Overlapping 20 MHz BSS is found");
305 return 1;
306 }
307
308 get_pri_sec_chan(bss, &pri_chan, &sec_chan);
309
310 if (sec_chan) {
311 if (sec_chan < pri_chan)
312 sec = pri - 20;
313 else
314 sec = pri + 20;
315 }
316
317 if ((pri < affected_start || pri > affected_end) &&
318 (sec < affected_start || sec > affected_end))
319 return 0; /* not within affected channel range */
320
321 wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
322 " freq=%d pri=%d sec=%d",
323 MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
324
325 if (sec_chan) {
326 if (pri_freq != pri || sec_freq != sec) {
327 wpa_printf(MSG_DEBUG,
328 "40 MHz pri/sec mismatch with BSS "
329 MACSTR
330 " <%d,%d> (chan=%d%c) vs. <%d,%d>",
331 MAC2STR(bss->bssid),
332 pri, sec, pri_chan,
333 sec > pri ? '+' : '-',
334 pri_freq, sec_freq);
335 return 1;
336 }
337 }
338
339 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
340 if (elems.ht_capabilities) {
341 struct ieee80211_ht_capabilities *ht_cap =
342 (struct ieee80211_ht_capabilities *)
343 elems.ht_capabilities;
344
345 if (le_to_host16(ht_cap->ht_capabilities_info) &
346 HT_CAP_INFO_40MHZ_INTOLERANT) {
347 wpa_printf(MSG_DEBUG,
348 "40 MHz Intolerant is set on channel %d in BSS "
349 MACSTR, pri, MAC2STR(bss->bssid));
350 return 2;
351 }
352 }
353
354 return 0;
355 }
356
357
358 int check_40mhz_2g4(struct hostapd_hw_modes *mode,
359 struct wpa_scan_results *scan_res, int pri_chan,
360 int sec_chan)
361 {
362 int pri_freq, sec_freq;
363 size_t i;
364
365 if (!mode || !scan_res || !pri_chan || !sec_chan ||
366 pri_chan == sec_chan)
367 return 0;
368
369 pri_freq = hw_get_freq(mode, pri_chan);
370 sec_freq = hw_get_freq(mode, sec_chan);
371
372 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
373 (pri_freq + sec_freq) / 2 - 25,
374 (pri_freq + sec_freq) / 2 + 25);
375 for (i = 0; i < scan_res->num; i++) {
376 if (check_bss_coex_40mhz(scan_res->res[i], pri_freq, sec_freq))
377 return 0;
378 }
379
380 return 1;
381 }
382
383
384 int hostapd_set_freq_params(struct hostapd_freq_params *data,
385 enum hostapd_hw_mode mode,
386 int freq, int channel, int enable_edmg,
387 u8 edmg_channel, int ht_enabled,
388 int vht_enabled, int he_enabled,
389 int sec_channel_offset,
390 int oper_chwidth, int center_segment0,
391 int center_segment1, u32 vht_caps,
392 struct he_capabilities *he_cap)
393 {
394 if (!he_cap)
395 he_enabled = 0;
396 os_memset(data, 0, sizeof(*data));
397 data->mode = mode;
398 data->freq = freq;
399 data->channel = channel;
400 data->ht_enabled = ht_enabled;
401 data->vht_enabled = vht_enabled;
402 data->he_enabled = he_enabled;
403 data->sec_channel_offset = sec_channel_offset;
404 data->center_freq1 = freq + sec_channel_offset * 10;
405 data->center_freq2 = 0;
406 data->bandwidth = sec_channel_offset ? 40 : 20;
407
408 hostapd_encode_edmg_chan(enable_edmg, edmg_channel, channel,
409 &data->edmg);
410
411 if (is_6ghz_freq(freq)) {
412 if (!data->he_enabled) {
413 wpa_printf(MSG_ERROR,
414 "Can't set 6 GHz mode - HE isn't enabled");
415 return -1;
416 }
417
418 if (center_idx_to_bw_6ghz(channel) != 0) {
419 wpa_printf(MSG_ERROR,
420 "Invalid control channel for 6 GHz band");
421 return -1;
422 }
423
424 if (!center_segment0) {
425 if (center_segment1) {
426 wpa_printf(MSG_ERROR,
427 "Segment 0 center frequency isn't set");
428 return -1;
429 }
430
431 data->center_freq1 = data->freq;
432 data->bandwidth = 20;
433 } else {
434 int freq1, freq2 = 0;
435 int bw = center_idx_to_bw_6ghz(center_segment0);
436
437 if (bw < 0) {
438 wpa_printf(MSG_ERROR,
439 "Invalid center frequency index for 6 GHz");
440 return -1;
441 }
442
443 freq1 = ieee80211_chan_to_freq(NULL, 131,
444 center_segment0);
445 if (freq1 < 0) {
446 wpa_printf(MSG_ERROR,
447 "Invalid segment 0 center frequency for 6 GHz");
448 return -1;
449 }
450
451 if (center_segment1) {
452 if (center_idx_to_bw_6ghz(center_segment1) != 2 ||
453 bw != 2) {
454 wpa_printf(MSG_ERROR,
455 "6 GHz 80+80 MHz configuration doesn't use valid 80 MHz channels");
456 return -1;
457 }
458
459 freq2 = ieee80211_chan_to_freq(NULL, 131,
460 center_segment1);
461 if (freq2 < 0) {
462 wpa_printf(MSG_ERROR,
463 "Invalid segment 1 center frequency for UHB");
464 return -1;
465 }
466 }
467
468 data->bandwidth = (1 << (u8) bw) * 20;
469 data->center_freq1 = freq1;
470 data->center_freq2 = freq2;
471 }
472 data->ht_enabled = 0;
473 data->vht_enabled = 0;
474
475 return 0;
476 }
477
478 if (data->vht_enabled) switch (oper_chwidth) {
479 case CHANWIDTH_USE_HT:
480 if (center_segment1 ||
481 (center_segment0 != 0 &&
482 5000 + center_segment0 * 5 != data->center_freq1 &&
483 2407 + center_segment0 * 5 != data->center_freq1))
484 return -1;
485 break;
486 case CHANWIDTH_80P80MHZ:
487 if (!(vht_caps & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) {
488 wpa_printf(MSG_ERROR,
489 "80+80 channel width is not supported!");
490 return -1;
491 }
492 if (center_segment1 == center_segment0 + 4 ||
493 center_segment1 == center_segment0 - 4)
494 return -1;
495 data->center_freq2 = 5000 + center_segment1 * 5;
496 /* fall through */
497 case CHANWIDTH_80MHZ:
498 data->bandwidth = 80;
499 if ((oper_chwidth == CHANWIDTH_80MHZ &&
500 center_segment1) ||
501 (oper_chwidth == CHANWIDTH_80P80MHZ &&
502 !center_segment1) ||
503 !sec_channel_offset)
504 return -1;
505 if (!center_segment0) {
506 if (channel <= 48)
507 center_segment0 = 42;
508 else if (channel <= 64)
509 center_segment0 = 58;
510 else if (channel <= 112)
511 center_segment0 = 106;
512 else if (channel <= 128)
513 center_segment0 = 122;
514 else if (channel <= 144)
515 center_segment0 = 138;
516 else if (channel <= 161)
517 center_segment0 = 155;
518 data->center_freq1 = 5000 + center_segment0 * 5;
519 } else {
520 /*
521 * Note: HT/VHT config and params are coupled. Check if
522 * HT40 channel band is in VHT80 Pri channel band
523 * configuration.
524 */
525 if (center_segment0 == channel + 6 ||
526 center_segment0 == channel + 2 ||
527 center_segment0 == channel - 2 ||
528 center_segment0 == channel - 6)
529 data->center_freq1 = 5000 + center_segment0 * 5;
530 else
531 return -1;
532 }
533 break;
534 case CHANWIDTH_160MHZ:
535 data->bandwidth = 160;
536 if (!(vht_caps & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
537 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) {
538 wpa_printf(MSG_ERROR,
539 "160MHZ channel width is not supported!");
540 return -1;
541 }
542 if (center_segment1)
543 return -1;
544 if (!sec_channel_offset)
545 return -1;
546 /*
547 * Note: HT/VHT config and params are coupled. Check if
548 * HT40 channel band is in VHT160 channel band configuration.
549 */
550 if (center_segment0 == channel + 14 ||
551 center_segment0 == channel + 10 ||
552 center_segment0 == channel + 6 ||
553 center_segment0 == channel + 2 ||
554 center_segment0 == channel - 2 ||
555 center_segment0 == channel - 6 ||
556 center_segment0 == channel - 10 ||
557 center_segment0 == channel - 14)
558 data->center_freq1 = 5000 + center_segment0 * 5;
559 else
560 return -1;
561 break;
562 }
563
564 return 0;
565 }
566
567
568 void set_disable_ht40(struct ieee80211_ht_capabilities *htcaps,
569 int disabled)
570 {
571 /* Masking these out disables HT40 */
572 le16 msk = host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET |
573 HT_CAP_INFO_SHORT_GI40MHZ);
574
575 if (disabled)
576 htcaps->ht_capabilities_info &= ~msk;
577 else
578 htcaps->ht_capabilities_info |= msk;
579 }
580
581
582 #ifdef CONFIG_IEEE80211AC
583
584 static int _ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap,
585 const char *name)
586 {
587 u32 req_cap = conf & cap;
588
589 /*
590 * Make sure we support all requested capabilities.
591 * NOTE: We assume that 'cap' represents a capability mask,
592 * not a discrete value.
593 */
594 if ((hw & req_cap) != req_cap) {
595 wpa_printf(MSG_ERROR,
596 "Driver does not support configured VHT capability [%s]",
597 name);
598 return 0;
599 }
600 return 1;
601 }
602
603
604 static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 mask,
605 unsigned int shift,
606 const char *name)
607 {
608 u32 hw_max = hw & mask;
609 u32 conf_val = conf & mask;
610
611 if (conf_val > hw_max) {
612 wpa_printf(MSG_ERROR,
613 "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
614 name, conf_val >> shift, hw_max >> shift);
615 return 0;
616 }
617 return 1;
618 }
619
620
621 int ieee80211ac_cap_check(u32 hw, u32 conf)
622 {
623 #define VHT_CAP_CHECK(cap) \
624 do { \
625 if (!_ieee80211ac_cap_check(hw, conf, cap, #cap)) \
626 return 0; \
627 } while (0)
628
629 #define VHT_CAP_CHECK_MAX(cap) \
630 do { \
631 if (!ieee80211ac_cap_check_max(hw, conf, cap, cap ## _SHIFT, \
632 #cap)) \
633 return 0; \
634 } while (0)
635
636 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
637 VHT_CAP_CHECK_MAX(VHT_CAP_SUPP_CHAN_WIDTH_MASK);
638 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
639 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
640 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
641 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
642 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
643 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
644 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
645 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
646 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
647 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
648 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
649 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
650 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
651 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
652 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
653 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
654 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
655 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
656
657 #undef VHT_CAP_CHECK
658 #undef VHT_CAP_CHECK_MAX
659
660 return 1;
661 }
662
663 #endif /* CONFIG_IEEE80211AC */
664
665
666 u32 num_chan_to_bw(int num_chans)
667 {
668 switch (num_chans) {
669 case 2:
670 case 4:
671 case 8:
672 return num_chans * 20;
673 default:
674 return 20;
675 }
676 }
677
678
679 /* check if BW is applicable for channel */
680 int chan_bw_allowed(const struct hostapd_channel_data *chan, u32 bw,
681 int ht40_plus, int pri)
682 {
683 u32 bw_mask;
684
685 switch (bw) {
686 case 20:
687 bw_mask = HOSTAPD_CHAN_WIDTH_20;
688 break;
689 case 40:
690 /* HT 40 MHz support declared only for primary channel,
691 * just skip 40 MHz secondary checking */
692 if (pri && ht40_plus)
693 bw_mask = HOSTAPD_CHAN_WIDTH_40P;
694 else if (pri && !ht40_plus)
695 bw_mask = HOSTAPD_CHAN_WIDTH_40M;
696 else
697 bw_mask = 0;
698 break;
699 case 80:
700 bw_mask = HOSTAPD_CHAN_WIDTH_80;
701 break;
702 case 160:
703 bw_mask = HOSTAPD_CHAN_WIDTH_160;
704 break;
705 default:
706 bw_mask = 0;
707 break;
708 }
709
710 return (chan->allowed_bw & bw_mask) == bw_mask;
711 }
712
713
714 /* check if channel is allowed to be used as primary */
715 int chan_pri_allowed(const struct hostapd_channel_data *chan)
716 {
717 return !(chan->flag & HOSTAPD_CHAN_DISABLED) &&
718 (chan->allowed_bw & HOSTAPD_CHAN_WIDTH_20);
719 }