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 * hw_get_channel_freq(struct hostapd_hw_modes *mode,
54 for (i = 0; i < mode->num_channels; i++) {
55 struct hostapd_channel_data *ch = &mode->channels[i];
56 if (ch->freq == freq) {
67 int hw_get_freq(struct hostapd_hw_modes *mode, int chan)
71 hw_get_channel_chan(mode, chan, &freq);
77 int hw_get_chan(struct hostapd_hw_modes *mode, int freq)
81 hw_get_channel_freq(mode, freq, &chan);
87 int allowed_ht40_channel_pair(struct hostapd_hw_modes *mode, int pri_chan,
91 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 140,
92 149, 157, 165, 184, 192 };
95 if (pri_chan == sec_chan || !sec_chan)
96 return 1; /* HT40 not used */
99 "HT40: control channel: %d secondary channel: %d",
102 /* Verify that HT40 secondary channel is an allowed 20 MHz
105 for (j = 0; j < mode->num_channels; j++) {
106 struct hostapd_channel_data *chan = &mode->channels[j];
107 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
108 chan->chan == sec_chan) {
114 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
120 * Verify that HT40 primary,secondary channel pair is allowed per
121 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
122 * 2.4 GHz rules allow all cases where the secondary channel fits into
123 * the list of allowed channels (already checked above).
125 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
128 first = pri_chan < sec_chan ? pri_chan : sec_chan;
131 for (k = 0; k < ARRAY_SIZE(allowed); k++) {
132 if (first == allowed[k]) {
138 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
147 void get_pri_sec_chan(struct wpa_scan_res *bss, int *pri_chan, int *sec_chan)
149 struct ieee80211_ht_operation *oper;
150 struct ieee802_11_elems elems;
152 *pri_chan = *sec_chan = 0;
154 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
155 if (elems.ht_operation) {
156 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
157 *pri_chan = oper->primary_chan;
158 if (oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
159 int sec = oper->ht_param &
160 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
161 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
162 *sec_chan = *pri_chan + 4;
163 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
164 *sec_chan = *pri_chan - 4;
170 int check_40mhz_5g(struct hostapd_hw_modes *mode,
171 struct wpa_scan_results *scan_res, int pri_chan,
174 int pri_freq, sec_freq, pri_bss, sec_bss;
175 int bss_pri_chan, bss_sec_chan;
179 if (!mode || !scan_res || !pri_chan || !sec_chan ||
180 pri_chan == sec_chan)
183 pri_freq = hw_get_freq(mode, pri_chan);
184 sec_freq = hw_get_freq(mode, sec_chan);
187 * Switch PRI/SEC channels if Beacons were detected on selected SEC
188 * channel, but not on selected PRI channel.
190 pri_bss = sec_bss = 0;
191 for (i = 0; i < scan_res->num; i++) {
192 struct wpa_scan_res *bss = scan_res->res[i];
193 if (bss->freq == pri_freq)
195 else if (bss->freq == sec_freq)
198 if (sec_bss && !pri_bss) {
200 "Switch own primary and secondary channel to get secondary channel with no Beacons from other BSSes");
205 * Match PRI/SEC channel with any existing HT40 BSS on the same
206 * channels that we are about to use (if already mixed order in
207 * existing BSSes, use own preference).
210 for (i = 0; i < scan_res->num; i++) {
211 struct wpa_scan_res *bss = scan_res->res[i];
212 get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
213 if (pri_chan == bss_pri_chan &&
214 sec_chan == bss_sec_chan) {
220 for (i = 0; i < scan_res->num; i++) {
221 struct wpa_scan_res *bss = scan_res->res[i];
222 get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
223 if (pri_chan == bss_sec_chan &&
224 sec_chan == bss_pri_chan) {
225 wpa_printf(MSG_INFO, "Switch own primary and "
226 "secondary channel due to BSS "
227 "overlap with " MACSTR,
228 MAC2STR(bss->bssid));
238 static int check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq, int start,
241 struct ieee802_11_elems elems;
242 struct ieee80211_ht_operation *oper;
244 if (bss->freq < start || bss->freq > end || bss->freq == pri_freq)
247 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
248 if (!elems.ht_capabilities) {
249 wpa_printf(MSG_DEBUG, "Found overlapping legacy BSS: "
250 MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
254 if (elems.ht_operation) {
255 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
256 if (oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)
259 wpa_printf(MSG_DEBUG, "Found overlapping 20 MHz HT BSS: "
260 MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
267 int check_40mhz_2g4(struct hostapd_hw_modes *mode,
268 struct wpa_scan_results *scan_res, int pri_chan,
271 int pri_freq, sec_freq;
272 int affected_start, affected_end;
275 if (!mode || !scan_res || !pri_chan || !sec_chan ||
276 pri_chan == sec_chan)
279 pri_freq = hw_get_freq(mode, pri_chan);
280 sec_freq = hw_get_freq(mode, sec_chan);
282 affected_start = (pri_freq + sec_freq) / 2 - 25;
283 affected_end = (pri_freq + sec_freq) / 2 + 25;
284 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
285 affected_start, affected_end);
286 for (i = 0; i < scan_res->num; i++) {
287 struct wpa_scan_res *bss = scan_res->res[i];
290 struct ieee802_11_elems elems;
292 /* Check for overlapping 20 MHz BSS */
293 if (check_20mhz_bss(bss, pri_freq, affected_start,
295 wpa_printf(MSG_DEBUG,
296 "Overlapping 20 MHz BSS is found");
300 get_pri_sec_chan(bss, &pri_chan, &sec_chan);
303 if (sec_chan < pri_chan)
309 if ((pri < affected_start || pri > affected_end) &&
310 (sec < affected_start || sec > affected_end))
311 continue; /* not within affected channel range */
313 wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
314 " freq=%d pri=%d sec=%d",
315 MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
318 if (pri_freq != pri || sec_freq != sec) {
319 wpa_printf(MSG_DEBUG,
320 "40 MHz pri/sec mismatch with BSS "
322 " <%d,%d> (chan=%d%c) vs. <%d,%d>",
325 sec > pri ? '+' : '-',
331 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems,
333 if (elems.ht_capabilities) {
334 struct ieee80211_ht_capabilities *ht_cap =
335 (struct ieee80211_ht_capabilities *)
336 elems.ht_capabilities;
338 if (le_to_host16(ht_cap->ht_capabilities_info) &
339 HT_CAP_INFO_40MHZ_INTOLERANT) {
340 wpa_printf(MSG_DEBUG,
341 "40 MHz Intolerant is set on channel %d in BSS "
342 MACSTR, pri, MAC2STR(bss->bssid));
352 int hostapd_set_freq_params(struct hostapd_freq_params *data,
353 enum hostapd_hw_mode mode,
354 int freq, int channel, int ht_enabled,
355 int vht_enabled, int sec_channel_offset,
356 int vht_oper_chwidth, int center_segment0,
357 int center_segment1, u32 vht_caps)
359 os_memset(data, 0, sizeof(*data));
362 data->channel = channel;
363 data->ht_enabled = ht_enabled;
364 data->vht_enabled = vht_enabled;
365 data->sec_channel_offset = sec_channel_offset;
366 data->center_freq1 = freq + sec_channel_offset * 10;
367 data->center_freq2 = 0;
368 data->bandwidth = sec_channel_offset ? 40 : 20;
370 if (data->vht_enabled) switch (vht_oper_chwidth) {
371 case VHT_CHANWIDTH_USE_HT:
372 if (center_segment1 ||
373 (center_segment0 != 0 &&
374 5000 + center_segment0 * 5 != data->center_freq1 &&
375 2407 + center_segment0 * 5 != data->center_freq1))
378 case VHT_CHANWIDTH_80P80MHZ:
379 if (!(vht_caps & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) {
380 wpa_printf(MSG_ERROR,
381 "80+80 channel width is not supported!");
384 if (center_segment1 == center_segment0 + 4 ||
385 center_segment1 == center_segment0 - 4)
387 data->center_freq2 = 5000 + center_segment1 * 5;
389 case VHT_CHANWIDTH_80MHZ:
390 data->bandwidth = 80;
391 if ((vht_oper_chwidth == VHT_CHANWIDTH_80MHZ &&
393 (vht_oper_chwidth == VHT_CHANWIDTH_80P80MHZ &&
397 if (!center_segment0) {
399 center_segment0 = 42;
400 else if (channel <= 64)
401 center_segment0 = 58;
402 else if (channel <= 112)
403 center_segment0 = 106;
404 else if (channel <= 128)
405 center_segment0 = 122;
406 else if (channel <= 144)
407 center_segment0 = 138;
408 else if (channel <= 161)
409 center_segment0 = 155;
410 data->center_freq1 = 5000 + center_segment0 * 5;
413 * Note: HT/VHT config and params are coupled. Check if
414 * HT40 channel band is in VHT80 Pri channel band
417 if (center_segment0 == channel + 6 ||
418 center_segment0 == channel + 2 ||
419 center_segment0 == channel - 2 ||
420 center_segment0 == channel - 6)
421 data->center_freq1 = 5000 + center_segment0 * 5;
426 case VHT_CHANWIDTH_160MHZ:
427 data->bandwidth = 160;
428 if (!(vht_caps & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
429 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) {
430 wpa_printf(MSG_ERROR,
431 "160MHZ channel width is not supported!");
436 if (!sec_channel_offset)
439 * Note: HT/VHT config and params are coupled. Check if
440 * HT40 channel band is in VHT160 channel band configuration.
442 if (center_segment0 == channel + 14 ||
443 center_segment0 == channel + 10 ||
444 center_segment0 == channel + 6 ||
445 center_segment0 == channel + 2 ||
446 center_segment0 == channel - 2 ||
447 center_segment0 == channel - 6 ||
448 center_segment0 == channel - 10 ||
449 center_segment0 == channel - 14)
450 data->center_freq1 = 5000 + center_segment0 * 5;
460 void set_disable_ht40(struct ieee80211_ht_capabilities *htcaps,
463 /* Masking these out disables HT40 */
464 le16 msk = host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET |
465 HT_CAP_INFO_SHORT_GI40MHZ);
468 htcaps->ht_capabilities_info &= ~msk;
470 htcaps->ht_capabilities_info |= msk;
474 #ifdef CONFIG_IEEE80211AC
476 static int _ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap,
479 u32 req_cap = conf & cap;
482 * Make sure we support all requested capabilities.
483 * NOTE: We assume that 'cap' represents a capability mask,
484 * not a discrete value.
486 if ((hw & req_cap) != req_cap) {
487 wpa_printf(MSG_ERROR,
488 "Driver does not support configured VHT capability [%s]",
496 static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 mask,
500 u32 hw_max = hw & mask;
501 u32 conf_val = conf & mask;
503 if (conf_val > hw_max) {
504 wpa_printf(MSG_ERROR,
505 "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
506 name, conf_val >> shift, hw_max >> shift);
513 int ieee80211ac_cap_check(u32 hw, u32 conf)
515 #define VHT_CAP_CHECK(cap) \
517 if (!_ieee80211ac_cap_check(hw, conf, cap, #cap)) \
521 #define VHT_CAP_CHECK_MAX(cap) \
523 if (!ieee80211ac_cap_check_max(hw, conf, cap, cap ## _SHIFT, \
528 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
529 VHT_CAP_CHECK_MAX(VHT_CAP_SUPP_CHAN_WIDTH_MASK);
530 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
531 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
532 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
533 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
534 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
535 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
536 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
537 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
538 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
539 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
540 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
541 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
542 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
543 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
544 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
545 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
546 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
547 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
550 #undef VHT_CAP_CHECK_MAX
555 #endif /* CONFIG_IEEE80211AC */