2 * hostapd / IEEE 802.11n HT
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007-2008, Intel Corporation
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include "utils/includes.h"
12 #include "utils/common.h"
13 #include "utils/eloop.h"
14 #include "common/ieee802_11_defs.h"
16 #include "ap_config.h"
19 #include "ieee802_11.h"
20 #include "hw_features.h"
21 #include "ap_drv_ops.h"
24 u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
26 struct ieee80211_ht_capabilities *cap;
29 if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
30 hapd->conf->disable_11n)
33 *pos++ = WLAN_EID_HT_CAP;
34 *pos++ = sizeof(*cap);
36 cap = (struct ieee80211_ht_capabilities *) pos;
37 os_memset(cap, 0, sizeof(*cap));
38 cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
39 cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
40 os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
43 /* TODO: ht_extended_capabilities (now fully disabled) */
44 /* TODO: tx_bf_capability_info (now fully disabled) */
45 /* TODO: asel_capabilities (now fully disabled) */
49 if (hapd->iconf->obss_interval) {
50 struct ieee80211_obss_scan_parameters *scan_params;
52 *pos++ = WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS;
53 *pos++ = sizeof(*scan_params);
55 scan_params = (struct ieee80211_obss_scan_parameters *) pos;
56 os_memset(scan_params, 0, sizeof(*scan_params));
57 scan_params->width_trigger_scan_interval =
58 host_to_le16(hapd->iconf->obss_interval);
60 /* Fill in default values for remaining parameters
61 * (IEEE Std 802.11-2012, 8.4.2.61 and MIB defval) */
62 scan_params->scan_passive_dwell =
64 scan_params->scan_active_dwell =
66 scan_params->scan_passive_total_per_channel =
68 scan_params->scan_active_total_per_channel =
70 scan_params->channel_transition_delay_factor =
72 scan_params->scan_activity_threshold =
75 pos += sizeof(*scan_params);
82 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
84 struct ieee80211_ht_operation *oper;
87 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
90 *pos++ = WLAN_EID_HT_OPERATION;
91 *pos++ = sizeof(*oper);
93 oper = (struct ieee80211_ht_operation *) pos;
94 os_memset(oper, 0, sizeof(*oper));
96 oper->primary_chan = hapd->iconf->channel;
97 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
98 if (hapd->iconf->secondary_channel == 1)
99 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
100 HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
101 if (hapd->iconf->secondary_channel == -1)
102 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
103 HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
105 pos += sizeof(*oper);
113 Set to 0 (HT pure) under the followign conditions
114 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
115 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
116 Set to 1 (HT non-member protection) if there may be non-HT STAs
117 in both the primary and the secondary channel
118 Set to 2 if only HT STAs are associated in BSS,
119 however and at least one 20 MHz HT STA is associated
120 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
122 int hostapd_ht_operation_update(struct hostapd_iface *iface)
124 u16 cur_op_mode, new_op_mode;
125 int op_mode_changes = 0;
127 if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
130 wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
131 __func__, iface->ht_op_mode);
133 if (!(iface->ht_op_mode & HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT)
134 && iface->num_sta_ht_no_gf) {
135 iface->ht_op_mode |= HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT;
137 } else if ((iface->ht_op_mode &
138 HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT) &&
139 iface->num_sta_ht_no_gf == 0) {
140 iface->ht_op_mode &= ~HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT;
144 if (!(iface->ht_op_mode & HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT) &&
145 (iface->num_sta_no_ht || iface->olbc_ht)) {
146 iface->ht_op_mode |= HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT;
148 } else if ((iface->ht_op_mode &
149 HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT) &&
150 (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
151 iface->ht_op_mode &= ~HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT;
155 if (iface->num_sta_no_ht)
156 new_op_mode = HT_PROT_NON_HT_MIXED;
157 else if (iface->conf->secondary_channel && iface->num_sta_ht_20mhz)
158 new_op_mode = HT_PROT_20MHZ_PROTECTION;
159 else if (iface->olbc_ht)
160 new_op_mode = HT_PROT_NONMEMBER_PROTECTION;
162 new_op_mode = HT_PROT_NO_PROTECTION;
164 cur_op_mode = iface->ht_op_mode & HT_OPER_OP_MODE_HT_PROT_MASK;
165 if (cur_op_mode != new_op_mode) {
166 iface->ht_op_mode &= ~HT_OPER_OP_MODE_HT_PROT_MASK;
167 iface->ht_op_mode |= new_op_mode;
171 wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
172 __func__, iface->ht_op_mode, op_mode_changes);
174 return op_mode_changes;
178 u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
179 const u8 *ht_capab, size_t ht_capab_len)
181 /* Disable HT caps for STAs associated to no-HT BSSes. */
183 ht_capab_len < sizeof(struct ieee80211_ht_capabilities) ||
184 hapd->conf->disable_11n) {
185 sta->flags &= ~WLAN_STA_HT;
186 os_free(sta->ht_capabilities);
187 sta->ht_capabilities = NULL;
188 return WLAN_STATUS_SUCCESS;
191 if (sta->ht_capabilities == NULL) {
192 sta->ht_capabilities =
193 os_zalloc(sizeof(struct ieee80211_ht_capabilities));
194 if (sta->ht_capabilities == NULL)
195 return WLAN_STATUS_UNSPECIFIED_FAILURE;
198 sta->flags |= WLAN_STA_HT;
199 os_memcpy(sta->ht_capabilities, ht_capab,
200 sizeof(struct ieee80211_ht_capabilities));
202 return WLAN_STATUS_SUCCESS;
206 void ht40_intolerant_add(struct hostapd_iface *iface, struct sta_info *sta)
208 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
211 wpa_printf(MSG_INFO, "HT: Forty MHz Intolerant is set by STA " MACSTR
212 " in Association Request", MAC2STR(sta->addr));
214 if (sta->ht40_intolerant_set)
217 sta->ht40_intolerant_set = 1;
218 iface->num_sta_ht40_intolerant++;
219 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
221 if (iface->conf->secondary_channel &&
222 (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
223 iface->conf->secondary_channel = 0;
224 ieee802_11_set_beacons(iface);
229 void ht40_intolerant_remove(struct hostapd_iface *iface, struct sta_info *sta)
231 if (!sta->ht40_intolerant_set)
234 sta->ht40_intolerant_set = 0;
235 iface->num_sta_ht40_intolerant--;
237 if (iface->num_sta_ht40_intolerant == 0 &&
238 (iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
239 (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
240 unsigned int delay_time = OVERLAPPING_BSS_TRANS_DELAY_FACTOR *
241 iface->conf->obss_interval;
242 wpa_printf(MSG_DEBUG,
243 "HT: Start 20->40 MHz transition timer (%d seconds)",
245 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
246 eloop_register_timeout(delay_time, 0, ap_ht2040_timeout,
252 static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
256 ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
257 wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
258 "0x%04x", MAC2STR(sta->addr), ht_capab);
259 if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
260 if (!sta->no_ht_gf_set) {
261 sta->no_ht_gf_set = 1;
262 hapd->iface->num_sta_ht_no_gf++;
264 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
265 "of non-gf stations %d",
266 __func__, MAC2STR(sta->addr),
267 hapd->iface->num_sta_ht_no_gf);
269 if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
270 if (!sta->ht_20mhz_set) {
271 sta->ht_20mhz_set = 1;
272 hapd->iface->num_sta_ht_20mhz++;
274 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
276 __func__, MAC2STR(sta->addr),
277 hapd->iface->num_sta_ht_20mhz);
280 if (ht_capab & HT_CAP_INFO_40MHZ_INTOLERANT)
281 ht40_intolerant_add(hapd->iface, sta);
285 static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
287 if (!sta->no_ht_set) {
289 hapd->iface->num_sta_no_ht++;
291 if (hapd->iconf->ieee80211n) {
292 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
293 "non-HT stations %d",
294 __func__, MAC2STR(sta->addr),
295 hapd->iface->num_sta_no_ht);
300 void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
302 if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
303 update_sta_ht(hapd, sta);
305 update_sta_no_ht(hapd, sta);
307 if (hostapd_ht_operation_update(hapd->iface) > 0)
308 ieee802_11_set_beacons(hapd->iface);
312 void hostapd_get_ht_capab(struct hostapd_data *hapd,
313 struct ieee80211_ht_capabilities *ht_cap,
314 struct ieee80211_ht_capabilities *neg_ht_cap)
320 os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
321 cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
324 * Mask out HT features we don't support, but don't overwrite
325 * non-symmetric features like STBC and SMPS. Just because
326 * we're not in dynamic SMPS mode the STA might still be.
328 cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
329 HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
332 * STBC needs to be handled specially
333 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
334 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
336 if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
337 cap &= ~HT_CAP_INFO_TX_STBC;
338 if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
339 cap &= ~HT_CAP_INFO_RX_STBC_MASK;
341 neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
345 void ap_ht2040_timeout(void *eloop_data, void *user_data)
347 struct hostapd_iface *iface = eloop_data;
349 wpa_printf(MSG_INFO, "Switching to 40 MHz operation");
351 iface->conf->secondary_channel = iface->secondary_ch;
352 ieee802_11_set_beacons(iface);