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