2 * Common hostapd/wpa_supplicant HW features
3 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2015, Qualcomm Atheros, Inc.
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
14 #include "ieee802_11_defs.h"
15 #include "ieee802_11_common.h"
16 #include "hw_features_common.h"
19 struct hostapd_channel_data
* hw_get_channel_chan(struct hostapd_hw_modes
*mode
,
30 for (i
= 0; i
< mode
->num_channels
; i
++) {
31 struct hostapd_channel_data
*ch
= &mode
->channels
[i
];
32 if (ch
->chan
== chan
) {
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
)
55 for (j
= 0; j
< num_hw_features
; j
++) {
56 struct hostapd_hw_modes
*curr_mode
= &hw_features
[j
];
58 if (curr_mode
->mode
!= mode
)
60 for (i
= 0; i
< curr_mode
->num_channels
; i
++) {
61 struct hostapd_channel_data
*ch
=
62 &curr_mode
->channels
[i
];
64 if (ch
->freq
== freq
) {
76 int hw_get_freq(struct hostapd_hw_modes
*mode
, int chan
)
80 hw_get_channel_chan(mode
, chan
, &freq
);
86 int hw_get_chan(enum hostapd_hw_mode mode
, int freq
,
87 struct hostapd_hw_modes
*hw_features
, int num_hw_features
)
91 hw_get_channel_freq(mode
, freq
, &chan
, hw_features
, num_hw_features
);
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
)
102 int allowed
[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 140,
103 149, 157, 165, 184, 192 };
105 int ht40_plus
, pri_chan
, sec_chan
;
107 if (!p_chan
|| !s_chan
)
109 pri_chan
= p_chan
->chan
;
110 sec_chan
= s_chan
->chan
;
112 ht40_plus
= pri_chan
< sec_chan
;
114 if (pri_chan
== sec_chan
|| !sec_chan
) {
115 if (chan_pri_allowed(p_chan
))
116 return 1; /* HT40 not used */
118 wpa_printf(MSG_ERROR
, "Channel %d is not allowed as primary",
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
);
127 /* Verify that HT40 secondary channel is an allowed 20 MHz
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",
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).
143 if (mode
!= HOSTAPD_MODE_IEEE80211A
)
146 first
= pri_chan
< sec_chan
? pri_chan
: sec_chan
;
149 for (k
= 0; k
< ARRAY_SIZE(allowed
); k
++) {
150 if (first
== allowed
[k
]) {
156 wpa_printf(MSG_ERROR
, "HT40 channel pair (%d, %d) not allowed",
165 void get_pri_sec_chan(struct wpa_scan_res
*bss
, int *pri_chan
, int *sec_chan
)
167 struct ieee80211_ht_operation
*oper
;
168 struct ieee802_11_elems elems
;
170 *pri_chan
= *sec_chan
= 0;
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;
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
)
192 int pri_bss
, sec_bss
;
193 int bss_pri_chan
, bss_sec_chan
;
197 if (!scan_res
|| !pri_chan
|| !sec_chan
||
198 pri_chan
->freq
== sec_chan
->freq
)
202 * Switch PRI/SEC channels if Beacons were detected on selected SEC
203 * channel, but not on selected PRI channel.
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
)
210 else if (bss
->freq
== sec_chan
->freq
)
213 if (sec_bss
&& !pri_bss
) {
215 "Switch own primary and secondary channel to get secondary channel with no Beacons from other BSSes");
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).
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
) {
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
));
253 static int check_20mhz_bss(struct wpa_scan_res
*bss
, int pri_freq
, int start
,
256 struct ieee802_11_elems elems
;
257 struct ieee80211_ht_operation
*oper
;
259 if (bss
->freq
< start
|| bss
->freq
> end
|| bss
->freq
== pri_freq
)
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
);
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
)
274 wpa_printf(MSG_DEBUG
, "Found overlapping 20 MHz HT BSS: "
275 MACSTR
" freq=%d", MAC2STR(bss
->bssid
), bss
->freq
);
286 * 2: overlapping BSS with 40 MHz intolerant advertisement
288 int check_bss_coex_40mhz(struct wpa_scan_res
*bss
, int pri_freq
, int sec_freq
)
290 int affected_start
, affected_end
;
291 struct ieee802_11_elems elems
;
292 int pri_chan
, sec_chan
;
296 if (pri_freq
== sec_freq
)
299 affected_start
= (pri_freq
+ sec_freq
) / 2 - 25;
300 affected_end
= (pri_freq
+ sec_freq
) / 2 + 25;
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");
308 get_pri_sec_chan(bss
, &pri_chan
, &sec_chan
);
311 if (sec_chan
< pri_chan
)
317 if ((pri
< affected_start
|| pri
> affected_end
) &&
318 (sec
< affected_start
|| sec
> affected_end
))
319 return 0; /* not within affected channel range */
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
);
326 if (pri_freq
!= pri
|| sec_freq
!= sec
) {
327 wpa_printf(MSG_DEBUG
,
328 "40 MHz pri/sec mismatch with BSS "
330 " <%d,%d> (chan=%d%c) vs. <%d,%d>",
333 sec
> pri
? '+' : '-',
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
;
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
));
358 int check_40mhz_2g4(struct hostapd_hw_modes
*mode
,
359 struct wpa_scan_results
*scan_res
, int pri_chan
,
362 int pri_freq
, sec_freq
;
365 if (!mode
|| !scan_res
|| !pri_chan
|| !sec_chan
||
366 pri_chan
== sec_chan
)
369 pri_freq
= hw_get_freq(mode
, pri_chan
);
370 sec_freq
= hw_get_freq(mode
, sec_chan
);
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
))
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
)
396 os_memset(data
, 0, sizeof(*data
));
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;
408 hostapd_encode_edmg_chan(enable_edmg
, edmg_channel
, channel
,
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");
418 if (center_idx_to_bw_6ghz(channel
) != 0) {
419 wpa_printf(MSG_ERROR
,
420 "Invalid control channel for 6 GHz band");
424 if (!center_segment0
) {
425 if (center_segment1
) {
426 wpa_printf(MSG_ERROR
,
427 "Segment 0 center frequency isn't set");
431 data
->center_freq1
= data
->freq
;
432 data
->bandwidth
= 20;
434 int freq1
, freq2
= 0;
435 int bw
= center_idx_to_bw_6ghz(center_segment0
);
438 wpa_printf(MSG_ERROR
,
439 "Invalid center frequency index for 6 GHz");
443 freq1
= ieee80211_chan_to_freq(NULL
, 131,
446 wpa_printf(MSG_ERROR
,
447 "Invalid segment 0 center frequency for 6 GHz");
451 if (center_segment1
) {
452 if (center_idx_to_bw_6ghz(center_segment1
) != 2 ||
454 wpa_printf(MSG_ERROR
,
455 "6 GHz 80+80 MHz configuration doesn't use valid 80 MHz channels");
459 freq2
= ieee80211_chan_to_freq(NULL
, 131,
462 wpa_printf(MSG_ERROR
,
463 "Invalid segment 1 center frequency for UHB");
468 data
->bandwidth
= (1 << (u8
) bw
) * 20;
469 data
->center_freq1
= freq1
;
470 data
->center_freq2
= freq2
;
472 data
->ht_enabled
= 0;
473 data
->vht_enabled
= 0;
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
))
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!");
492 if (center_segment1
== center_segment0
+ 4 ||
493 center_segment1
== center_segment0
- 4)
495 data
->center_freq2
= 5000 + center_segment1
* 5;
497 case CHANWIDTH_80MHZ
:
498 data
->bandwidth
= 80;
499 if ((oper_chwidth
== CHANWIDTH_80MHZ
&&
501 (oper_chwidth
== CHANWIDTH_80P80MHZ
&&
505 if (!center_segment0
) {
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;
521 * Note: HT/VHT config and params are coupled. Check if
522 * HT40 channel band is in VHT80 Pri channel band
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;
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!");
544 if (!sec_channel_offset
)
547 * Note: HT/VHT config and params are coupled. Check if
548 * HT40 channel band is in VHT160 channel band configuration.
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;
568 void set_disable_ht40(struct ieee80211_ht_capabilities
*htcaps
,
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
);
576 htcaps
->ht_capabilities_info
&= ~msk
;
578 htcaps
->ht_capabilities_info
|= msk
;
582 #ifdef CONFIG_IEEE80211AC
584 static int _ieee80211ac_cap_check(u32 hw
, u32 conf
, u32 cap
,
587 u32 req_cap
= conf
& cap
;
590 * Make sure we support all requested capabilities.
591 * NOTE: We assume that 'cap' represents a capability mask,
592 * not a discrete value.
594 if ((hw
& req_cap
) != req_cap
) {
595 wpa_printf(MSG_ERROR
,
596 "Driver does not support configured VHT capability [%s]",
604 static int ieee80211ac_cap_check_max(u32 hw
, u32 conf
, u32 mask
,
608 u32 hw_max
= hw
& mask
;
609 u32 conf_val
= conf
& mask
;
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
);
621 int ieee80211ac_cap_check(u32 hw
, u32 conf
)
623 #define VHT_CAP_CHECK(cap) \
625 if (!_ieee80211ac_cap_check(hw, conf, cap, #cap)) \
629 #define VHT_CAP_CHECK_MAX(cap) \
631 if (!ieee80211ac_cap_check_max(hw, conf, cap, cap ## _SHIFT, \
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
);
658 #undef VHT_CAP_CHECK_MAX
663 #endif /* CONFIG_IEEE80211AC */
666 u32
num_chan_to_bw(int num_chans
)
672 return num_chans
* 20;
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
)
687 bw_mask
= HOSTAPD_CHAN_WIDTH_20
;
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
;
700 bw_mask
= HOSTAPD_CHAN_WIDTH_80
;
703 bw_mask
= HOSTAPD_CHAN_WIDTH_160
;
710 return (chan
->allowed_bw
& bw_mask
) == bw_mask
;
714 /* check if channel is allowed to be used as primary */
715 int chan_pri_allowed(const struct hostapd_channel_data
*chan
)
717 return !(chan
->flag
& HOSTAPD_CHAN_DISABLED
) &&
718 (chan
->allowed_bw
& HOSTAPD_CHAN_WIDTH_20
);