Line data Source code
1 : /*
2 : * hostapd / IEEE 802.11n HT
3 : * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 : * Copyright (c) 2007-2008, Intel Corporation
5 : *
6 : * This software may be distributed under the terms of the BSD license.
7 : * See README for more details.
8 : */
9 :
10 : #include "utils/includes.h"
11 :
12 : #include "utils/common.h"
13 : #include "utils/eloop.h"
14 : #include "common/ieee802_11_defs.h"
15 : #include "hostapd.h"
16 : #include "ap_config.h"
17 : #include "sta_info.h"
18 : #include "beacon.h"
19 : #include "ieee802_11.h"
20 : #include "hw_features.h"
21 : #include "ap_drv_ops.h"
22 :
23 :
24 3531 : u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
25 : {
26 : struct ieee80211_ht_capabilities *cap;
27 3531 : u8 *pos = eid;
28 :
29 7046 : if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
30 3515 : hapd->conf->disable_11n)
31 91 : return eid;
32 :
33 3440 : *pos++ = WLAN_EID_HT_CAP;
34 3440 : *pos++ = sizeof(*cap);
35 :
36 3440 : cap = (struct ieee80211_ht_capabilities *) pos;
37 3440 : os_memset(cap, 0, sizeof(*cap));
38 3440 : cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
39 3440 : cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
40 3440 : os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
41 : 16);
42 :
43 : /* TODO: ht_extended_capabilities (now fully disabled) */
44 : /* TODO: tx_bf_capability_info (now fully disabled) */
45 : /* TODO: asel_capabilities (now fully disabled) */
46 :
47 3440 : pos += sizeof(*cap);
48 :
49 3440 : if (hapd->iconf->obss_interval) {
50 : struct ieee80211_obss_scan_parameters *scan_params;
51 :
52 24 : *pos++ = WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS;
53 24 : *pos++ = sizeof(*scan_params);
54 :
55 24 : scan_params = (struct ieee80211_obss_scan_parameters *) pos;
56 24 : os_memset(scan_params, 0, sizeof(*scan_params));
57 24 : scan_params->width_trigger_scan_interval =
58 24 : host_to_le16(hapd->iconf->obss_interval);
59 :
60 : /* Fill in default values for remaining parameters
61 : * (IEEE Std 802.11-2012, 8.4.2.61 and MIB defval) */
62 24 : scan_params->scan_passive_dwell =
63 : host_to_le16(20);
64 24 : scan_params->scan_active_dwell =
65 : host_to_le16(10);
66 24 : scan_params->scan_passive_total_per_channel =
67 : host_to_le16(200);
68 24 : scan_params->scan_active_total_per_channel =
69 : host_to_le16(20);
70 24 : scan_params->channel_transition_delay_factor =
71 : host_to_le16(5);
72 24 : scan_params->scan_activity_threshold =
73 : host_to_le16(25);
74 :
75 24 : pos += sizeof(*scan_params);
76 : }
77 :
78 3440 : return pos;
79 : }
80 :
81 :
82 3531 : u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
83 : {
84 : struct ieee80211_ht_operation *oper;
85 3531 : u8 *pos = eid;
86 :
87 3531 : if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
88 91 : return eid;
89 :
90 3440 : *pos++ = WLAN_EID_HT_OPERATION;
91 3440 : *pos++ = sizeof(*oper);
92 :
93 3440 : oper = (struct ieee80211_ht_operation *) pos;
94 3440 : os_memset(oper, 0, sizeof(*oper));
95 :
96 3440 : oper->primary_chan = hapd->iconf->channel;
97 3440 : oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
98 3440 : if (hapd->iconf->secondary_channel == 1)
99 54 : oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
100 : HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
101 3440 : if (hapd->iconf->secondary_channel == -1)
102 32 : oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
103 : HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
104 :
105 3440 : pos += sizeof(*oper);
106 :
107 3440 : return pos;
108 : }
109 :
110 :
111 : /*
112 : op_mode
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
121 : */
122 2358 : int hostapd_ht_operation_update(struct hostapd_iface *iface)
123 : {
124 : u16 cur_op_mode, new_op_mode;
125 2358 : int op_mode_changes = 0;
126 :
127 2358 : if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
128 8 : return 0;
129 :
130 2350 : wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
131 2350 : __func__, iface->ht_op_mode);
132 :
133 2350 : if (!(iface->ht_op_mode & HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT)
134 2350 : && iface->num_sta_ht_no_gf) {
135 0 : iface->ht_op_mode |= HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT;
136 0 : op_mode_changes++;
137 2350 : } else if ((iface->ht_op_mode &
138 0 : HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT) &&
139 0 : iface->num_sta_ht_no_gf == 0) {
140 0 : iface->ht_op_mode &= ~HT_OPER_OP_MODE_NON_GF_HT_STAS_PRESENT;
141 0 : op_mode_changes++;
142 : }
143 :
144 4672 : if (!(iface->ht_op_mode & HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT) &&
145 4628 : (iface->num_sta_no_ht || iface->olbc_ht)) {
146 18 : iface->ht_op_mode |= HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT;
147 18 : op_mode_changes++;
148 2332 : } else if ((iface->ht_op_mode &
149 28 : HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT) &&
150 45 : (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
151 17 : iface->ht_op_mode &= ~HT_OPER_OP_MODE_OBSS_NON_HT_STAS_PRESENT;
152 17 : op_mode_changes++;
153 : }
154 :
155 2350 : if (iface->num_sta_no_ht)
156 27 : new_op_mode = HT_PROT_NON_HT_MIXED;
157 2323 : else if (iface->conf->secondary_channel && iface->num_sta_ht_20mhz)
158 0 : new_op_mode = HT_PROT_20MHZ_PROTECTION;
159 2323 : else if (iface->olbc_ht)
160 2 : new_op_mode = HT_PROT_NONMEMBER_PROTECTION;
161 : else
162 2321 : new_op_mode = HT_PROT_NO_PROTECTION;
163 :
164 2350 : cur_op_mode = iface->ht_op_mode & HT_OPER_OP_MODE_HT_PROT_MASK;
165 2350 : if (cur_op_mode != new_op_mode) {
166 35 : iface->ht_op_mode &= ~HT_OPER_OP_MODE_HT_PROT_MASK;
167 35 : iface->ht_op_mode |= new_op_mode;
168 35 : op_mode_changes++;
169 : }
170 :
171 2350 : wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
172 2350 : __func__, iface->ht_op_mode, op_mode_changes);
173 :
174 2350 : return op_mode_changes;
175 : }
176 :
177 :
178 0 : static int is_40_allowed(struct hostapd_iface *iface, int channel)
179 : {
180 : int pri_freq, sec_freq;
181 : int affected_start, affected_end;
182 0 : int pri = 2407 + 5 * channel;
183 :
184 0 : if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
185 0 : return 1;
186 :
187 0 : pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
188 :
189 0 : if (iface->conf->secondary_channel > 0)
190 0 : sec_freq = pri_freq + 20;
191 : else
192 0 : sec_freq = pri_freq - 20;
193 :
194 0 : affected_start = (pri_freq + sec_freq) / 2 - 25;
195 0 : affected_end = (pri_freq + sec_freq) / 2 + 25;
196 0 : if ((pri < affected_start || pri > affected_end))
197 0 : return 1; /* not within affected channel range */
198 :
199 0 : wpa_printf(MSG_ERROR, "40 MHz affected channel range: [%d,%d] MHz",
200 : affected_start, affected_end);
201 0 : wpa_printf(MSG_ERROR, "Neighboring BSS: freq=%d", pri);
202 0 : return 0;
203 : }
204 :
205 :
206 4 : void hostapd_2040_coex_action(struct hostapd_data *hapd,
207 : const struct ieee80211_mgmt *mgmt, size_t len)
208 : {
209 4 : struct hostapd_iface *iface = hapd->iface;
210 : struct ieee80211_2040_bss_coex_ie *bc_ie;
211 : struct ieee80211_2040_intol_chan_report *ic_report;
212 4 : int is_ht_allowed = 1;
213 : int i;
214 4 : const u8 *data = ((const u8 *) mgmt) + 1;
215 :
216 4 : hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
217 : HOSTAPD_LEVEL_DEBUG, "hostapd_public_action - action=%d",
218 4 : mgmt->u.action.u.public_action.action);
219 :
220 4 : if (!(iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
221 0 : return;
222 :
223 4 : if (len < IEEE80211_HDRLEN + 1)
224 0 : return;
225 4 : data++;
226 :
227 4 : bc_ie = (struct ieee80211_2040_bss_coex_ie *) &data[0];
228 4 : ic_report = (struct ieee80211_2040_intol_chan_report *)
229 : (&data[0] + sizeof(*bc_ie));
230 :
231 4 : if (bc_ie->coex_param & WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ) {
232 0 : hostapd_logger(hapd, mgmt->sa,
233 : HOSTAPD_MODULE_IEEE80211,
234 : HOSTAPD_LEVEL_DEBUG,
235 : "20 MHz BSS width request bit is set in BSS coexistence information field");
236 0 : is_ht_allowed = 0;
237 : }
238 :
239 4 : if (bc_ie->coex_param & WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
240 4 : hostapd_logger(hapd, mgmt->sa,
241 : HOSTAPD_MODULE_IEEE80211,
242 : HOSTAPD_LEVEL_DEBUG,
243 : "40 MHz intolerant bit is set in BSS coexistence information field");
244 4 : is_ht_allowed = 0;
245 : }
246 :
247 8 : if (ic_report &&
248 4 : (ic_report->element_id == WLAN_EID_20_40_BSS_INTOLERANT)) {
249 : /* Go through the channel report to find any BSS there in the
250 : * affected channel range */
251 0 : for (i = 0; i < ic_report->length - 1; i++) {
252 0 : if (is_40_allowed(iface, ic_report->variable[i]))
253 0 : continue;
254 0 : hostapd_logger(hapd, mgmt->sa,
255 : HOSTAPD_MODULE_IEEE80211,
256 : HOSTAPD_LEVEL_DEBUG,
257 : "20_40_INTOLERANT channel %d reported",
258 0 : ic_report->variable[i]);
259 0 : is_ht_allowed = 0;
260 0 : break;
261 : }
262 : }
263 :
264 8 : if (!is_ht_allowed &&
265 4 : (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
266 4 : if (iface->conf->secondary_channel) {
267 4 : hostapd_logger(hapd, mgmt->sa,
268 : HOSTAPD_MODULE_IEEE80211,
269 : HOSTAPD_LEVEL_INFO,
270 : "Switching to 20 MHz operation");
271 4 : iface->conf->secondary_channel = 0;
272 4 : ieee802_11_set_beacons(iface);
273 : }
274 4 : if (!iface->num_sta_ht40_intolerant) {
275 : unsigned int delay_time;
276 4 : delay_time = OVERLAPPING_BSS_TRANS_DELAY_FACTOR *
277 4 : iface->conf->obss_interval;
278 4 : eloop_cancel_timeout(ap_ht2040_timeout, hapd->iface,
279 : NULL);
280 4 : eloop_register_timeout(delay_time, 0, ap_ht2040_timeout,
281 4 : hapd->iface, NULL);
282 : }
283 : }
284 : }
285 :
286 :
287 1309 : u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
288 : const u8 *ht_capab, size_t ht_capab_len)
289 : {
290 : /* Disable HT caps for STAs associated to no-HT BSSes. */
291 1309 : if (!ht_capab ||
292 1279 : ht_capab_len < sizeof(struct ieee80211_ht_capabilities) ||
293 1279 : hapd->conf->disable_11n) {
294 30 : sta->flags &= ~WLAN_STA_HT;
295 30 : os_free(sta->ht_capabilities);
296 30 : sta->ht_capabilities = NULL;
297 30 : return WLAN_STATUS_SUCCESS;
298 : }
299 :
300 1279 : if (sta->ht_capabilities == NULL) {
301 1015 : sta->ht_capabilities =
302 1015 : os_zalloc(sizeof(struct ieee80211_ht_capabilities));
303 1015 : if (sta->ht_capabilities == NULL)
304 0 : return WLAN_STATUS_UNSPECIFIED_FAILURE;
305 : }
306 :
307 1279 : sta->flags |= WLAN_STA_HT;
308 1279 : os_memcpy(sta->ht_capabilities, ht_capab,
309 : sizeof(struct ieee80211_ht_capabilities));
310 :
311 1279 : return WLAN_STATUS_SUCCESS;
312 : }
313 :
314 :
315 1 : void ht40_intolerant_add(struct hostapd_iface *iface, struct sta_info *sta)
316 : {
317 1 : if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
318 0 : return;
319 :
320 6 : wpa_printf(MSG_INFO, "HT: Forty MHz Intolerant is set by STA " MACSTR
321 6 : " in Association Request", MAC2STR(sta->addr));
322 :
323 1 : if (sta->ht40_intolerant_set)
324 0 : return;
325 :
326 1 : sta->ht40_intolerant_set = 1;
327 1 : iface->num_sta_ht40_intolerant++;
328 1 : eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
329 :
330 2 : if (iface->conf->secondary_channel &&
331 1 : (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
332 1 : iface->conf->secondary_channel = 0;
333 1 : ieee802_11_set_beacons(iface);
334 : }
335 : }
336 :
337 :
338 1056 : void ht40_intolerant_remove(struct hostapd_iface *iface, struct sta_info *sta)
339 : {
340 1056 : if (!sta->ht40_intolerant_set)
341 2111 : return;
342 :
343 1 : sta->ht40_intolerant_set = 0;
344 1 : iface->num_sta_ht40_intolerant--;
345 :
346 2 : if (iface->num_sta_ht40_intolerant == 0 &&
347 2 : (iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
348 1 : (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX)) {
349 1 : unsigned int delay_time = OVERLAPPING_BSS_TRANS_DELAY_FACTOR *
350 1 : iface->conf->obss_interval;
351 1 : wpa_printf(MSG_DEBUG,
352 : "HT: Start 20->40 MHz transition timer (%d seconds)",
353 : delay_time);
354 1 : eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
355 1 : eloop_register_timeout(delay_time, 0, ap_ht2040_timeout,
356 : iface, NULL);
357 : }
358 : }
359 :
360 :
361 1276 : static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
362 : {
363 : u16 ht_capab;
364 :
365 1276 : ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
366 8932 : wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
367 7656 : "0x%04x", MAC2STR(sta->addr), ht_capab);
368 1276 : if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
369 0 : if (!sta->no_ht_gf_set) {
370 0 : sta->no_ht_gf_set = 1;
371 0 : hapd->iface->num_sta_ht_no_gf++;
372 : }
373 0 : wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
374 : "of non-gf stations %d",
375 0 : __func__, MAC2STR(sta->addr),
376 0 : hapd->iface->num_sta_ht_no_gf);
377 : }
378 1276 : if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
379 1255 : if (!sta->ht_20mhz_set) {
380 993 : sta->ht_20mhz_set = 1;
381 993 : hapd->iface->num_sta_ht_20mhz++;
382 : }
383 8785 : wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
384 : "20MHz HT STAs %d",
385 7530 : __func__, MAC2STR(sta->addr),
386 1255 : hapd->iface->num_sta_ht_20mhz);
387 : }
388 :
389 1276 : if (ht_capab & HT_CAP_INFO_40MHZ_INTOLERANT)
390 1 : ht40_intolerant_add(hapd->iface, sta);
391 1276 : }
392 :
393 :
394 23 : static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
395 : {
396 23 : if (!sta->no_ht_set) {
397 23 : sta->no_ht_set = 1;
398 23 : hapd->iface->num_sta_no_ht++;
399 : }
400 23 : if (hapd->iconf->ieee80211n) {
401 133 : wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
402 : "non-HT stations %d",
403 114 : __func__, MAC2STR(sta->addr),
404 19 : hapd->iface->num_sta_no_ht);
405 : }
406 23 : }
407 :
408 :
409 1299 : void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
410 : {
411 1299 : if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
412 1276 : update_sta_ht(hapd, sta);
413 : else
414 23 : update_sta_no_ht(hapd, sta);
415 :
416 1299 : if (hostapd_ht_operation_update(hapd->iface) > 0)
417 16 : ieee802_11_set_beacons(hapd->iface);
418 1299 : }
419 :
420 :
421 1276 : void hostapd_get_ht_capab(struct hostapd_data *hapd,
422 : struct ieee80211_ht_capabilities *ht_cap,
423 : struct ieee80211_ht_capabilities *neg_ht_cap)
424 : {
425 : u16 cap;
426 :
427 1276 : if (ht_cap == NULL)
428 1276 : return;
429 1276 : os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
430 1276 : cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
431 :
432 : /*
433 : * Mask out HT features we don't support, but don't overwrite
434 : * non-symmetric features like STBC and SMPS. Just because
435 : * we're not in dynamic SMPS mode the STA might still be.
436 : */
437 1276 : cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
438 : HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
439 :
440 : /*
441 : * STBC needs to be handled specially
442 : * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
443 : * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
444 : */
445 1276 : if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
446 1276 : cap &= ~HT_CAP_INFO_TX_STBC;
447 1276 : if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
448 1276 : cap &= ~HT_CAP_INFO_RX_STBC_MASK;
449 :
450 1276 : neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
451 : }
452 :
453 :
454 4 : void ap_ht2040_timeout(void *eloop_data, void *user_data)
455 : {
456 4 : struct hostapd_iface *iface = eloop_data;
457 :
458 4 : wpa_printf(MSG_INFO, "Switching to 40 MHz operation");
459 :
460 4 : iface->conf->secondary_channel = iface->secondary_ch;
461 4 : ieee802_11_set_beacons(iface);
462 4 : }
|