13ff40c12SJohn Marino /*
23ff40c12SJohn Marino * hostapd / IEEE 802.11n HT
33ff40c12SJohn Marino * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
43ff40c12SJohn Marino * Copyright (c) 2007-2008, Intel Corporation
53ff40c12SJohn Marino *
63ff40c12SJohn Marino * This software may be distributed under the terms of the BSD license.
73ff40c12SJohn Marino * See README for more details.
83ff40c12SJohn Marino */
93ff40c12SJohn Marino
103ff40c12SJohn Marino #include "utils/includes.h"
113ff40c12SJohn Marino
123ff40c12SJohn Marino #include "utils/common.h"
13*a1157835SDaniel Fojt #include "utils/eloop.h"
143ff40c12SJohn Marino #include "common/ieee802_11_defs.h"
153ff40c12SJohn Marino #include "hostapd.h"
163ff40c12SJohn Marino #include "ap_config.h"
173ff40c12SJohn Marino #include "sta_info.h"
183ff40c12SJohn Marino #include "beacon.h"
193ff40c12SJohn Marino #include "ieee802_11.h"
20*a1157835SDaniel Fojt #include "hw_features.h"
21*a1157835SDaniel Fojt #include "ap_drv_ops.h"
223ff40c12SJohn Marino
233ff40c12SJohn Marino
hostapd_eid_ht_capabilities(struct hostapd_data * hapd,u8 * eid)243ff40c12SJohn Marino u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
253ff40c12SJohn Marino {
263ff40c12SJohn Marino struct ieee80211_ht_capabilities *cap;
273ff40c12SJohn Marino u8 *pos = eid;
283ff40c12SJohn Marino
293ff40c12SJohn Marino if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
303ff40c12SJohn Marino hapd->conf->disable_11n)
313ff40c12SJohn Marino return eid;
323ff40c12SJohn Marino
333ff40c12SJohn Marino *pos++ = WLAN_EID_HT_CAP;
343ff40c12SJohn Marino *pos++ = sizeof(*cap);
353ff40c12SJohn Marino
363ff40c12SJohn Marino cap = (struct ieee80211_ht_capabilities *) pos;
373ff40c12SJohn Marino os_memset(cap, 0, sizeof(*cap));
383ff40c12SJohn Marino cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
393ff40c12SJohn Marino cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
403ff40c12SJohn Marino os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
413ff40c12SJohn Marino 16);
423ff40c12SJohn Marino
433ff40c12SJohn Marino /* TODO: ht_extended_capabilities (now fully disabled) */
443ff40c12SJohn Marino /* TODO: tx_bf_capability_info (now fully disabled) */
453ff40c12SJohn Marino /* TODO: asel_capabilities (now fully disabled) */
463ff40c12SJohn Marino
473ff40c12SJohn Marino pos += sizeof(*cap);
483ff40c12SJohn Marino
493ff40c12SJohn Marino if (hapd->iconf->obss_interval) {
503ff40c12SJohn Marino struct ieee80211_obss_scan_parameters *scan_params;
513ff40c12SJohn Marino
523ff40c12SJohn Marino *pos++ = WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS;
533ff40c12SJohn Marino *pos++ = sizeof(*scan_params);
543ff40c12SJohn Marino
553ff40c12SJohn Marino scan_params = (struct ieee80211_obss_scan_parameters *) pos;
563ff40c12SJohn Marino os_memset(scan_params, 0, sizeof(*scan_params));
573ff40c12SJohn Marino scan_params->width_trigger_scan_interval =
583ff40c12SJohn Marino host_to_le16(hapd->iconf->obss_interval);
593ff40c12SJohn Marino
60*a1157835SDaniel Fojt /* Fill in default values for remaining parameters
61*a1157835SDaniel Fojt * (IEEE Std 802.11-2012, 8.4.2.61 and MIB defval) */
62*a1157835SDaniel Fojt scan_params->scan_passive_dwell =
63*a1157835SDaniel Fojt host_to_le16(20);
64*a1157835SDaniel Fojt scan_params->scan_active_dwell =
65*a1157835SDaniel Fojt host_to_le16(10);
66*a1157835SDaniel Fojt scan_params->scan_passive_total_per_channel =
67*a1157835SDaniel Fojt host_to_le16(200);
68*a1157835SDaniel Fojt scan_params->scan_active_total_per_channel =
69*a1157835SDaniel Fojt host_to_le16(20);
70*a1157835SDaniel Fojt scan_params->channel_transition_delay_factor =
71*a1157835SDaniel Fojt host_to_le16(5);
72*a1157835SDaniel Fojt scan_params->scan_activity_threshold =
73*a1157835SDaniel Fojt host_to_le16(25);
743ff40c12SJohn Marino
753ff40c12SJohn Marino pos += sizeof(*scan_params);
763ff40c12SJohn Marino }
773ff40c12SJohn Marino
783ff40c12SJohn Marino return pos;
793ff40c12SJohn Marino }
803ff40c12SJohn Marino
813ff40c12SJohn Marino
hostapd_eid_ht_operation(struct hostapd_data * hapd,u8 * eid)823ff40c12SJohn Marino u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
833ff40c12SJohn Marino {
843ff40c12SJohn Marino struct ieee80211_ht_operation *oper;
853ff40c12SJohn Marino u8 *pos = eid;
863ff40c12SJohn Marino
873ff40c12SJohn Marino if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
883ff40c12SJohn Marino return eid;
893ff40c12SJohn Marino
903ff40c12SJohn Marino *pos++ = WLAN_EID_HT_OPERATION;
913ff40c12SJohn Marino *pos++ = sizeof(*oper);
923ff40c12SJohn Marino
933ff40c12SJohn Marino oper = (struct ieee80211_ht_operation *) pos;
943ff40c12SJohn Marino os_memset(oper, 0, sizeof(*oper));
953ff40c12SJohn Marino
96*a1157835SDaniel Fojt oper->primary_chan = hapd->iconf->channel;
973ff40c12SJohn Marino oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
983ff40c12SJohn Marino if (hapd->iconf->secondary_channel == 1)
993ff40c12SJohn Marino oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
100*a1157835SDaniel Fojt HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
1013ff40c12SJohn Marino if (hapd->iconf->secondary_channel == -1)
1023ff40c12SJohn Marino oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
103*a1157835SDaniel Fojt HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
1043ff40c12SJohn Marino
1053ff40c12SJohn Marino pos += sizeof(*oper);
1063ff40c12SJohn Marino
1073ff40c12SJohn Marino return pos;
1083ff40c12SJohn Marino }
1093ff40c12SJohn Marino
1103ff40c12SJohn Marino
hostapd_eid_secondary_channel(struct hostapd_data * hapd,u8 * eid)111*a1157835SDaniel Fojt u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
112*a1157835SDaniel Fojt {
113*a1157835SDaniel Fojt u8 sec_ch;
114*a1157835SDaniel Fojt
115*a1157835SDaniel Fojt if (!hapd->cs_freq_params.channel ||
116*a1157835SDaniel Fojt !hapd->cs_freq_params.sec_channel_offset)
117*a1157835SDaniel Fojt return eid;
118*a1157835SDaniel Fojt
119*a1157835SDaniel Fojt if (hapd->cs_freq_params.sec_channel_offset == -1)
120*a1157835SDaniel Fojt sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
121*a1157835SDaniel Fojt else if (hapd->cs_freq_params.sec_channel_offset == 1)
122*a1157835SDaniel Fojt sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
123*a1157835SDaniel Fojt else
124*a1157835SDaniel Fojt return eid;
125*a1157835SDaniel Fojt
126*a1157835SDaniel Fojt *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
127*a1157835SDaniel Fojt *eid++ = 1;
128*a1157835SDaniel Fojt *eid++ = sec_ch;
129*a1157835SDaniel Fojt
130*a1157835SDaniel Fojt return eid;
131*a1157835SDaniel Fojt }
132*a1157835SDaniel Fojt
133*a1157835SDaniel Fojt
1343ff40c12SJohn Marino /*
1353ff40c12SJohn Marino op_mode
1363ff40c12SJohn Marino Set to 0 (HT pure) under the followign conditions
1373ff40c12SJohn Marino - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1383ff40c12SJohn Marino - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1393ff40c12SJohn Marino Set to 1 (HT non-member protection) if there may be non-HT STAs
1403ff40c12SJohn Marino in both the primary and the secondary channel
1413ff40c12SJohn Marino Set to 2 if only HT STAs are associated in BSS,
1423ff40c12SJohn Marino however and at least one 20 MHz HT STA is associated
1433ff40c12SJohn Marino Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1443ff40c12SJohn Marino */
hostapd_ht_operation_update(struct hostapd_iface * iface)1453ff40c12SJohn Marino int hostapd_ht_operation_update(struct hostapd_iface *iface)
1463ff40c12SJohn Marino {
1473ff40c12SJohn Marino u16 cur_op_mode, new_op_mode;
1483ff40c12SJohn Marino int op_mode_changes = 0;
1493ff40c12SJohn Marino
1503ff40c12SJohn Marino if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
1513ff40c12SJohn Marino return 0;
1523ff40c12SJohn Marino
1533ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
1543ff40c12SJohn Marino __func__, iface->ht_op_mode);
1553ff40c12SJohn Marino
156*a1157835SDaniel Fojt if (!(iface->ht_op_mode & HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT)
1573ff40c12SJohn Marino && iface->num_sta_ht_no_gf) {
158*a1157835SDaniel Fojt iface->ht_op_mode |= HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT;
1593ff40c12SJohn Marino op_mode_changes++;
1603ff40c12SJohn Marino } else if ((iface->ht_op_mode &
161*a1157835SDaniel Fojt HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT) &&
1623ff40c12SJohn Marino iface->num_sta_ht_no_gf == 0) {
163*a1157835SDaniel Fojt iface->ht_op_mode &= ~HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT;
1643ff40c12SJohn Marino op_mode_changes++;
1653ff40c12SJohn Marino }
1663ff40c12SJohn Marino
167*a1157835SDaniel Fojt if (!(iface->ht_op_mode & HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT) &&
1683ff40c12SJohn Marino (iface->num_sta_no_ht || iface->olbc_ht)) {
169*a1157835SDaniel Fojt iface->ht_op_mode |= HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT;
1703ff40c12SJohn Marino op_mode_changes++;
1713ff40c12SJohn Marino } else if ((iface->ht_op_mode &
172*a1157835SDaniel Fojt HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT) &&
1733ff40c12SJohn Marino (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
174*a1157835SDaniel Fojt iface->ht_op_mode &= ~HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT;
1753ff40c12SJohn Marino op_mode_changes++;
1763ff40c12SJohn Marino }
1773ff40c12SJohn Marino
1783ff40c12SJohn Marino if (iface->num_sta_no_ht)
179*a1157835SDaniel Fojt new_op_mode = HT_PROT_NON_HT_MIXED;
1803ff40c12SJohn Marino else if (iface->conf->secondary_channel && iface->num_sta_ht_20mhz)
181*a1157835SDaniel Fojt new_op_mode = HT_PROT_20MHZ_PROTECTION;
1823ff40c12SJohn Marino else if (iface->olbc_ht)
183*a1157835SDaniel Fojt new_op_mode = HT_PROT_NONMEMBER_PROTECTION;
1843ff40c12SJohn Marino else
185*a1157835SDaniel Fojt new_op_mode = HT_PROT_NO_PROTECTION;
1863ff40c12SJohn Marino
187*a1157835SDaniel Fojt cur_op_mode = iface->ht_op_mode & HT_OPER_OP_MODE_HT_PROT_MASK;
1883ff40c12SJohn Marino if (cur_op_mode != new_op_mode) {
189*a1157835SDaniel Fojt iface->ht_op_mode &= ~HT_OPER_OP_MODE_HT_PROT_MASK;
1903ff40c12SJohn Marino iface->ht_op_mode |= new_op_mode;
1913ff40c12SJohn Marino op_mode_changes++;
1923ff40c12SJohn Marino }
1933ff40c12SJohn Marino
1943ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
1953ff40c12SJohn Marino __func__, iface->ht_op_mode, op_mode_changes);
1963ff40c12SJohn Marino
1973ff40c12SJohn Marino return op_mode_changes;
1983ff40c12SJohn Marino }
1993ff40c12SJohn Marino
2003ff40c12SJohn Marino
is_40_allowed(struct hostapd_iface * iface,int channel)201*a1157835SDaniel Fojt static int is_40_allowed(struct hostapd_iface *iface, int channel)
2023ff40c12SJohn Marino {
203*a1157835SDaniel Fojt int pri_freq, sec_freq;
204*a1157835SDaniel Fojt int affected_start, affected_end;
205*a1157835SDaniel Fojt int pri = 2407 + 5 * channel;
206*a1157835SDaniel Fojt
207*a1157835SDaniel Fojt if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
208*a1157835SDaniel Fojt return 1;
209*a1157835SDaniel Fojt
210*a1157835SDaniel Fojt pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
211*a1157835SDaniel Fojt
212*a1157835SDaniel Fojt if (iface->conf->secondary_channel > 0)
213*a1157835SDaniel Fojt sec_freq = pri_freq + 20;
214*a1157835SDaniel Fojt else
215*a1157835SDaniel Fojt sec_freq = pri_freq - 20;
216*a1157835SDaniel Fojt
217*a1157835SDaniel Fojt affected_start = (pri_freq + sec_freq) / 2 - 25;
218*a1157835SDaniel Fojt affected_end = (pri_freq + sec_freq) / 2 + 25;
219*a1157835SDaniel Fojt if ((pri < affected_start || pri > affected_end))
220*a1157835SDaniel Fojt return 1; /* not within affected channel range */
221*a1157835SDaniel Fojt
222*a1157835SDaniel Fojt wpa_printf(MSG_ERROR, "40 MHz affected channel range: [%d,%d] MHz",
223*a1157835SDaniel Fojt affected_start, affected_end);
224*a1157835SDaniel Fojt wpa_printf(MSG_ERROR, "Neighboring BSS: freq=%d", pri);
225*a1157835SDaniel Fojt return 0;
226*a1157835SDaniel Fojt }
227*a1157835SDaniel Fojt
228*a1157835SDaniel Fojt
hostapd_2040_coex_action(struct hostapd_data * hapd,const struct ieee80211_mgmt * mgmt,size_t len)229*a1157835SDaniel Fojt void hostapd_2040_coex_action(struct hostapd_data *hapd,
230*a1157835SDaniel Fojt const struct ieee80211_mgmt *mgmt, size_t len)
231*a1157835SDaniel Fojt {
232*a1157835SDaniel Fojt struct hostapd_iface *iface = hapd->iface;
233*a1157835SDaniel Fojt struct ieee80211_2040_bss_coex_ie *bc_ie;
234*a1157835SDaniel Fojt struct ieee80211_2040_intol_chan_report *ic_report;
235*a1157835SDaniel Fojt int is_ht40_allowed = 1;
236*a1157835SDaniel Fojt int i;
237*a1157835SDaniel Fojt const u8 *start = (const u8 *) mgmt;
238*a1157835SDaniel Fojt const u8 *data = start + IEEE80211_HDRLEN + 2;
239*a1157835SDaniel Fojt struct sta_info *sta;
240*a1157835SDaniel Fojt
241*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
242*a1157835SDaniel Fojt "HT: Received 20/40 BSS Coexistence Management frame from "
243*a1157835SDaniel Fojt MACSTR, MAC2STR(mgmt->sa));
244*a1157835SDaniel Fojt
245*a1157835SDaniel Fojt hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
246*a1157835SDaniel Fojt HOSTAPD_LEVEL_DEBUG, "hostapd_public_action - action=%d",
247*a1157835SDaniel Fojt mgmt->u.action.u.public_action.action);
248*a1157835SDaniel Fojt
249*a1157835SDaniel Fojt if (!(iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
250*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
251*a1157835SDaniel Fojt "Ignore 20/40 BSS Coexistence Management frame since 40 MHz capability is not enabled");
252*a1157835SDaniel Fojt return;
253*a1157835SDaniel Fojt }
254*a1157835SDaniel Fojt
255*a1157835SDaniel Fojt if (len < IEEE80211_HDRLEN + 2 + sizeof(*bc_ie)) {
256*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
257*a1157835SDaniel Fojt "Ignore too short 20/40 BSS Coexistence Management frame");
258*a1157835SDaniel Fojt return;
259*a1157835SDaniel Fojt }
260*a1157835SDaniel Fojt
261*a1157835SDaniel Fojt /* 20/40 BSS Coexistence element */
262*a1157835SDaniel Fojt bc_ie = (struct ieee80211_2040_bss_coex_ie *) data;
263*a1157835SDaniel Fojt if (bc_ie->element_id != WLAN_EID_20_40_BSS_COEXISTENCE ||
264*a1157835SDaniel Fojt bc_ie->length < 1) {
265*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "Unexpected IE (%u,%u) in coex report",
266*a1157835SDaniel Fojt bc_ie->element_id, bc_ie->length);
267*a1157835SDaniel Fojt return;
268*a1157835SDaniel Fojt }
269*a1157835SDaniel Fojt if (len < IEEE80211_HDRLEN + 2 + 2 + bc_ie->length) {
270*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
271*a1157835SDaniel Fojt "Truncated 20/40 BSS Coexistence element");
272*a1157835SDaniel Fojt return;
273*a1157835SDaniel Fojt }
274*a1157835SDaniel Fojt data += 2 + bc_ie->length;
275*a1157835SDaniel Fojt
276*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
277*a1157835SDaniel Fojt "20/40 BSS Coexistence Information field: 0x%x (%s%s%s%s%s%s)",
278*a1157835SDaniel Fojt bc_ie->coex_param,
279*a1157835SDaniel Fojt (bc_ie->coex_param & BIT(0)) ? "[InfoReq]" : "",
280*a1157835SDaniel Fojt (bc_ie->coex_param & BIT(1)) ? "[40MHzIntolerant]" : "",
281*a1157835SDaniel Fojt (bc_ie->coex_param & BIT(2)) ? "[20MHzBSSWidthReq]" : "",
282*a1157835SDaniel Fojt (bc_ie->coex_param & BIT(3)) ? "[OBSSScanExemptionReq]" : "",
283*a1157835SDaniel Fojt (bc_ie->coex_param & BIT(4)) ?
284*a1157835SDaniel Fojt "[OBSSScanExemptionGrant]" : "",
285*a1157835SDaniel Fojt (bc_ie->coex_param & (BIT(5) | BIT(6) | BIT(7))) ?
286*a1157835SDaniel Fojt "[Reserved]" : "");
287*a1157835SDaniel Fojt
288*a1157835SDaniel Fojt if (bc_ie->coex_param & WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ) {
289*a1157835SDaniel Fojt /* Intra-BSS communication prohibiting 20/40 MHz BSS operation
290*a1157835SDaniel Fojt */
291*a1157835SDaniel Fojt sta = ap_get_sta(hapd, mgmt->sa);
292*a1157835SDaniel Fojt if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
293*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
294*a1157835SDaniel Fojt "Ignore intra-BSS 20/40 BSS Coexistence Management frame from not-associated STA");
295*a1157835SDaniel Fojt return;
296*a1157835SDaniel Fojt }
297*a1157835SDaniel Fojt
298*a1157835SDaniel Fojt hostapd_logger(hapd, mgmt->sa,
299*a1157835SDaniel Fojt HOSTAPD_MODULE_IEEE80211,
300*a1157835SDaniel Fojt HOSTAPD_LEVEL_DEBUG,
301*a1157835SDaniel Fojt "20 MHz BSS width request bit is set in BSS coexistence information field");
302*a1157835SDaniel Fojt is_ht40_allowed = 0;
303*a1157835SDaniel Fojt }
304*a1157835SDaniel Fojt
305*a1157835SDaniel Fojt if (bc_ie->coex_param & WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
306*a1157835SDaniel Fojt /* Inter-BSS communication prohibiting 20/40 MHz BSS operation
307*a1157835SDaniel Fojt */
308*a1157835SDaniel Fojt hostapd_logger(hapd, mgmt->sa,
309*a1157835SDaniel Fojt HOSTAPD_MODULE_IEEE80211,
310*a1157835SDaniel Fojt HOSTAPD_LEVEL_DEBUG,
311*a1157835SDaniel Fojt "40 MHz intolerant bit is set in BSS coexistence information field");
312*a1157835SDaniel Fojt is_ht40_allowed = 0;
313*a1157835SDaniel Fojt }
314*a1157835SDaniel Fojt
315*a1157835SDaniel Fojt /* 20/40 BSS Intolerant Channel Report element (zero or more times) */
316*a1157835SDaniel Fojt while (start + len - data >= 3 &&
317*a1157835SDaniel Fojt data[0] == WLAN_EID_20_40_BSS_INTOLERANT && data[1] >= 1) {
318*a1157835SDaniel Fojt u8 ielen = data[1];
319*a1157835SDaniel Fojt
320*a1157835SDaniel Fojt if (ielen > start + len - data - 2) {
321*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
322*a1157835SDaniel Fojt "Truncated 20/40 BSS Intolerant Channel Report element");
323*a1157835SDaniel Fojt return;
324*a1157835SDaniel Fojt }
325*a1157835SDaniel Fojt ic_report = (struct ieee80211_2040_intol_chan_report *) data;
326*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
327*a1157835SDaniel Fojt "20/40 BSS Intolerant Channel Report: Operating Class %u",
328*a1157835SDaniel Fojt ic_report->op_class);
329*a1157835SDaniel Fojt
330*a1157835SDaniel Fojt /* Go through the channel report to find any BSS there in the
331*a1157835SDaniel Fojt * affected channel range */
332*a1157835SDaniel Fojt for (i = 0; i < ielen - 1; i++) {
333*a1157835SDaniel Fojt u8 chan = ic_report->variable[i];
334*a1157835SDaniel Fojt
335*a1157835SDaniel Fojt if (chan == iface->conf->channel)
336*a1157835SDaniel Fojt continue; /* matching own primary channel */
337*a1157835SDaniel Fojt if (is_40_allowed(iface, chan))
338*a1157835SDaniel Fojt continue; /* not within affected channels */
339*a1157835SDaniel Fojt hostapd_logger(hapd, mgmt->sa,
340*a1157835SDaniel Fojt HOSTAPD_MODULE_IEEE80211,
341*a1157835SDaniel Fojt HOSTAPD_LEVEL_DEBUG,
342*a1157835SDaniel Fojt "20_40_INTOLERANT channel %d reported",
343*a1157835SDaniel Fojt chan);
344*a1157835SDaniel Fojt is_ht40_allowed = 0;
345*a1157835SDaniel Fojt }
346*a1157835SDaniel Fojt
347*a1157835SDaniel Fojt data += 2 + ielen;
348*a1157835SDaniel Fojt }
349*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "is_ht40_allowed=%d num_sta_ht40_intolerant=%d",
350*a1157835SDaniel Fojt is_ht40_allowed, iface->num_sta_ht40_intolerant);
351*a1157835SDaniel Fojt
352*a1157835SDaniel Fojt if (!is_ht40_allowed &&
353*a1157835SDaniel Fojt (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
354*a1157835SDaniel Fojt if (iface->conf->secondary_channel) {
355*a1157835SDaniel Fojt hostapd_logger(hapd, mgmt->sa,
356*a1157835SDaniel Fojt HOSTAPD_MODULE_IEEE80211,
357*a1157835SDaniel Fojt HOSTAPD_LEVEL_INFO,
358*a1157835SDaniel Fojt "Switching to 20 MHz operation");
359*a1157835SDaniel Fojt iface->conf->secondary_channel = 0;
360*a1157835SDaniel Fojt ieee802_11_set_beacons(iface);
361*a1157835SDaniel Fojt }
362*a1157835SDaniel Fojt if (!iface->num_sta_ht40_intolerant &&
363*a1157835SDaniel Fojt iface->conf->obss_interval) {
364*a1157835SDaniel Fojt unsigned int delay_time;
365*a1157835SDaniel Fojt delay_time = OVERLAPPING_BSS_TRANS_DELAY_FACTOR *
366*a1157835SDaniel Fojt iface->conf->obss_interval;
367*a1157835SDaniel Fojt eloop_cancel_timeout(ap_ht2040_timeout, hapd->iface,
368*a1157835SDaniel Fojt NULL);
369*a1157835SDaniel Fojt eloop_register_timeout(delay_time, 0, ap_ht2040_timeout,
370*a1157835SDaniel Fojt hapd->iface, NULL);
371*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
372*a1157835SDaniel Fojt "Reschedule HT 20/40 timeout to occur in %u seconds",
373*a1157835SDaniel Fojt delay_time);
374*a1157835SDaniel Fojt }
375*a1157835SDaniel Fojt }
376*a1157835SDaniel Fojt }
377*a1157835SDaniel Fojt
378*a1157835SDaniel Fojt
copy_sta_ht_capab(struct hostapd_data * hapd,struct sta_info * sta,const u8 * ht_capab)379*a1157835SDaniel Fojt u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
380*a1157835SDaniel Fojt const u8 *ht_capab)
381*a1157835SDaniel Fojt {
382*a1157835SDaniel Fojt /*
383*a1157835SDaniel Fojt * Disable HT caps for STAs associated to no-HT BSSes, or for stations
384*a1157835SDaniel Fojt * that did not specify a valid WMM IE in the (Re)Association Request
385*a1157835SDaniel Fojt * frame.
386*a1157835SDaniel Fojt */
387*a1157835SDaniel Fojt if (!ht_capab || !(sta->flags & WLAN_STA_WMM) ||
388*a1157835SDaniel Fojt !hapd->iconf->ieee80211n || hapd->conf->disable_11n) {
3893ff40c12SJohn Marino sta->flags &= ~WLAN_STA_HT;
3903ff40c12SJohn Marino os_free(sta->ht_capabilities);
3913ff40c12SJohn Marino sta->ht_capabilities = NULL;
3923ff40c12SJohn Marino return WLAN_STATUS_SUCCESS;
3933ff40c12SJohn Marino }
3943ff40c12SJohn Marino
3953ff40c12SJohn Marino if (sta->ht_capabilities == NULL) {
3963ff40c12SJohn Marino sta->ht_capabilities =
3973ff40c12SJohn Marino os_zalloc(sizeof(struct ieee80211_ht_capabilities));
3983ff40c12SJohn Marino if (sta->ht_capabilities == NULL)
3993ff40c12SJohn Marino return WLAN_STATUS_UNSPECIFIED_FAILURE;
4003ff40c12SJohn Marino }
4013ff40c12SJohn Marino
4023ff40c12SJohn Marino sta->flags |= WLAN_STA_HT;
4033ff40c12SJohn Marino os_memcpy(sta->ht_capabilities, ht_capab,
4043ff40c12SJohn Marino sizeof(struct ieee80211_ht_capabilities));
4053ff40c12SJohn Marino
4063ff40c12SJohn Marino return WLAN_STATUS_SUCCESS;
4073ff40c12SJohn Marino }
4083ff40c12SJohn Marino
4093ff40c12SJohn Marino
ht40_intolerant_add(struct hostapd_iface * iface,struct sta_info * sta)410*a1157835SDaniel Fojt void ht40_intolerant_add(struct hostapd_iface *iface, struct sta_info *sta)
411*a1157835SDaniel Fojt {
412*a1157835SDaniel Fojt if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
413*a1157835SDaniel Fojt return;
414*a1157835SDaniel Fojt
415*a1157835SDaniel Fojt wpa_printf(MSG_INFO, "HT: Forty MHz Intolerant is set by STA " MACSTR
416*a1157835SDaniel Fojt " in Association Request", MAC2STR(sta->addr));
417*a1157835SDaniel Fojt
418*a1157835SDaniel Fojt if (sta->ht40_intolerant_set)
419*a1157835SDaniel Fojt return;
420*a1157835SDaniel Fojt
421*a1157835SDaniel Fojt sta->ht40_intolerant_set = 1;
422*a1157835SDaniel Fojt iface->num_sta_ht40_intolerant++;
423*a1157835SDaniel Fojt eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
424*a1157835SDaniel Fojt
425*a1157835SDaniel Fojt if (iface->conf->secondary_channel &&
426*a1157835SDaniel Fojt (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
427*a1157835SDaniel Fojt iface->conf->secondary_channel = 0;
428*a1157835SDaniel Fojt ieee802_11_set_beacons(iface);
429*a1157835SDaniel Fojt }
430*a1157835SDaniel Fojt }
431*a1157835SDaniel Fojt
432*a1157835SDaniel Fojt
ht40_intolerant_remove(struct hostapd_iface * iface,struct sta_info * sta)433*a1157835SDaniel Fojt void ht40_intolerant_remove(struct hostapd_iface *iface, struct sta_info *sta)
434*a1157835SDaniel Fojt {
435*a1157835SDaniel Fojt if (!sta->ht40_intolerant_set)
436*a1157835SDaniel Fojt return;
437*a1157835SDaniel Fojt
438*a1157835SDaniel Fojt sta->ht40_intolerant_set = 0;
439*a1157835SDaniel Fojt iface->num_sta_ht40_intolerant--;
440*a1157835SDaniel Fojt
441*a1157835SDaniel Fojt if (iface->num_sta_ht40_intolerant == 0 &&
442*a1157835SDaniel Fojt (iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
443*a1157835SDaniel Fojt (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
444*a1157835SDaniel Fojt unsigned int delay_time = OVERLAPPING_BSS_TRANS_DELAY_FACTOR *
445*a1157835SDaniel Fojt iface->conf->obss_interval;
446*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
447*a1157835SDaniel Fojt "HT: Start 20->40 MHz transition timer (%d seconds)",
448*a1157835SDaniel Fojt delay_time);
449*a1157835SDaniel Fojt eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
450*a1157835SDaniel Fojt eloop_register_timeout(delay_time, 0, ap_ht2040_timeout,
451*a1157835SDaniel Fojt iface, NULL);
452*a1157835SDaniel Fojt }
453*a1157835SDaniel Fojt }
454*a1157835SDaniel Fojt
455*a1157835SDaniel Fojt
update_sta_ht(struct hostapd_data * hapd,struct sta_info * sta)4563ff40c12SJohn Marino static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
4573ff40c12SJohn Marino {
4583ff40c12SJohn Marino u16 ht_capab;
4593ff40c12SJohn Marino
4603ff40c12SJohn Marino ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
4613ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
4623ff40c12SJohn Marino "0x%04x", MAC2STR(sta->addr), ht_capab);
4633ff40c12SJohn Marino if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
4643ff40c12SJohn Marino if (!sta->no_ht_gf_set) {
4653ff40c12SJohn Marino sta->no_ht_gf_set = 1;
4663ff40c12SJohn Marino hapd->iface->num_sta_ht_no_gf++;
4673ff40c12SJohn Marino }
4683ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
4693ff40c12SJohn Marino "of non-gf stations %d",
4703ff40c12SJohn Marino __func__, MAC2STR(sta->addr),
4713ff40c12SJohn Marino hapd->iface->num_sta_ht_no_gf);
4723ff40c12SJohn Marino }
4733ff40c12SJohn Marino if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
4743ff40c12SJohn Marino if (!sta->ht_20mhz_set) {
4753ff40c12SJohn Marino sta->ht_20mhz_set = 1;
4763ff40c12SJohn Marino hapd->iface->num_sta_ht_20mhz++;
4773ff40c12SJohn Marino }
4783ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
4793ff40c12SJohn Marino "20MHz HT STAs %d",
4803ff40c12SJohn Marino __func__, MAC2STR(sta->addr),
4813ff40c12SJohn Marino hapd->iface->num_sta_ht_20mhz);
4823ff40c12SJohn Marino }
483*a1157835SDaniel Fojt
484*a1157835SDaniel Fojt if (ht_capab & HT_CAP_INFO_40MHZ_INTOLERANT)
485*a1157835SDaniel Fojt ht40_intolerant_add(hapd->iface, sta);
4863ff40c12SJohn Marino }
4873ff40c12SJohn Marino
4883ff40c12SJohn Marino
update_sta_no_ht(struct hostapd_data * hapd,struct sta_info * sta)4893ff40c12SJohn Marino static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
4903ff40c12SJohn Marino {
4913ff40c12SJohn Marino if (!sta->no_ht_set) {
4923ff40c12SJohn Marino sta->no_ht_set = 1;
4933ff40c12SJohn Marino hapd->iface->num_sta_no_ht++;
4943ff40c12SJohn Marino }
4953ff40c12SJohn Marino if (hapd->iconf->ieee80211n) {
4963ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
4973ff40c12SJohn Marino "non-HT stations %d",
4983ff40c12SJohn Marino __func__, MAC2STR(sta->addr),
4993ff40c12SJohn Marino hapd->iface->num_sta_no_ht);
5003ff40c12SJohn Marino }
5013ff40c12SJohn Marino }
5023ff40c12SJohn Marino
5033ff40c12SJohn Marino
update_ht_state(struct hostapd_data * hapd,struct sta_info * sta)5043ff40c12SJohn Marino void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
5053ff40c12SJohn Marino {
5063ff40c12SJohn Marino if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
5073ff40c12SJohn Marino update_sta_ht(hapd, sta);
5083ff40c12SJohn Marino else
5093ff40c12SJohn Marino update_sta_no_ht(hapd, sta);
5103ff40c12SJohn Marino
5113ff40c12SJohn Marino if (hostapd_ht_operation_update(hapd->iface) > 0)
5123ff40c12SJohn Marino ieee802_11_set_beacons(hapd->iface);
5133ff40c12SJohn Marino }
5143ff40c12SJohn Marino
5153ff40c12SJohn Marino
hostapd_get_ht_capab(struct hostapd_data * hapd,struct ieee80211_ht_capabilities * ht_cap,struct ieee80211_ht_capabilities * neg_ht_cap)5163ff40c12SJohn Marino void hostapd_get_ht_capab(struct hostapd_data *hapd,
5173ff40c12SJohn Marino struct ieee80211_ht_capabilities *ht_cap,
5183ff40c12SJohn Marino struct ieee80211_ht_capabilities *neg_ht_cap)
5193ff40c12SJohn Marino {
5203ff40c12SJohn Marino u16 cap;
5213ff40c12SJohn Marino
5223ff40c12SJohn Marino if (ht_cap == NULL)
5233ff40c12SJohn Marino return;
5243ff40c12SJohn Marino os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
5253ff40c12SJohn Marino cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
5263ff40c12SJohn Marino
5273ff40c12SJohn Marino /*
5283ff40c12SJohn Marino * Mask out HT features we don't support, but don't overwrite
5293ff40c12SJohn Marino * non-symmetric features like STBC and SMPS. Just because
5303ff40c12SJohn Marino * we're not in dynamic SMPS mode the STA might still be.
5313ff40c12SJohn Marino */
5323ff40c12SJohn Marino cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
5333ff40c12SJohn Marino HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
5343ff40c12SJohn Marino
5353ff40c12SJohn Marino /*
5363ff40c12SJohn Marino * STBC needs to be handled specially
5373ff40c12SJohn Marino * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
5383ff40c12SJohn Marino * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
5393ff40c12SJohn Marino */
5403ff40c12SJohn Marino if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
5413ff40c12SJohn Marino cap &= ~HT_CAP_INFO_TX_STBC;
5423ff40c12SJohn Marino if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
5433ff40c12SJohn Marino cap &= ~HT_CAP_INFO_RX_STBC_MASK;
5443ff40c12SJohn Marino
5453ff40c12SJohn Marino neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
5463ff40c12SJohn Marino }
547*a1157835SDaniel Fojt
548*a1157835SDaniel Fojt
ap_ht2040_timeout(void * eloop_data,void * user_data)549*a1157835SDaniel Fojt void ap_ht2040_timeout(void *eloop_data, void *user_data)
550*a1157835SDaniel Fojt {
551*a1157835SDaniel Fojt struct hostapd_iface *iface = eloop_data;
552*a1157835SDaniel Fojt
553*a1157835SDaniel Fojt wpa_printf(MSG_INFO, "Switching to 40 MHz operation");
554*a1157835SDaniel Fojt
555*a1157835SDaniel Fojt iface->conf->secondary_channel = iface->secondary_ch;
556*a1157835SDaniel Fojt ieee802_11_set_beacons(iface);
557*a1157835SDaniel Fojt }
558