2 * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 * IEEE 802.11n protocol support.
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/systm.h>
42 #include <sys/endian.h>
44 #include <sys/socket.h>
47 #include <net/if_var.h>
48 #include <net/if_media.h>
49 #include <net/ethernet.h>
51 #include <net80211/ieee80211_var.h>
52 #include <net80211/ieee80211_action.h>
53 #include <net80211/ieee80211_input.h>
55 /* define here, used throughout file */
56 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
57 #define SM(_v, _f) (((_v) << _f##_S) & _f)
59 const struct ieee80211_mcs_rates ieee80211_htrates[IEEE80211_HTRATE_MAXSIZE] = {
60 { 13, 14, 27, 30 }, /* MCS 0 */
61 { 26, 29, 54, 60 }, /* MCS 1 */
62 { 39, 43, 81, 90 }, /* MCS 2 */
63 { 52, 58, 108, 120 }, /* MCS 3 */
64 { 78, 87, 162, 180 }, /* MCS 4 */
65 { 104, 116, 216, 240 }, /* MCS 5 */
66 { 117, 130, 243, 270 }, /* MCS 6 */
67 { 130, 144, 270, 300 }, /* MCS 7 */
68 { 26, 29, 54, 60 }, /* MCS 8 */
69 { 52, 58, 108, 120 }, /* MCS 9 */
70 { 78, 87, 162, 180 }, /* MCS 10 */
71 { 104, 116, 216, 240 }, /* MCS 11 */
72 { 156, 173, 324, 360 }, /* MCS 12 */
73 { 208, 231, 432, 480 }, /* MCS 13 */
74 { 234, 260, 486, 540 }, /* MCS 14 */
75 { 260, 289, 540, 600 }, /* MCS 15 */
76 { 39, 43, 81, 90 }, /* MCS 16 */
77 { 78, 87, 162, 180 }, /* MCS 17 */
78 { 117, 130, 243, 270 }, /* MCS 18 */
79 { 156, 173, 324, 360 }, /* MCS 19 */
80 { 234, 260, 486, 540 }, /* MCS 20 */
81 { 312, 347, 648, 720 }, /* MCS 21 */
82 { 351, 390, 729, 810 }, /* MCS 22 */
83 { 390, 433, 810, 900 }, /* MCS 23 */
84 { 52, 58, 108, 120 }, /* MCS 24 */
85 { 104, 116, 216, 240 }, /* MCS 25 */
86 { 156, 173, 324, 360 }, /* MCS 26 */
87 { 208, 231, 432, 480 }, /* MCS 27 */
88 { 312, 347, 648, 720 }, /* MCS 28 */
89 { 416, 462, 864, 960 }, /* MCS 29 */
90 { 468, 520, 972, 1080 }, /* MCS 30 */
91 { 520, 578, 1080, 1200 }, /* MCS 31 */
92 { 0, 0, 12, 13 }, /* MCS 32 */
93 { 78, 87, 162, 180 }, /* MCS 33 */
94 { 104, 116, 216, 240 }, /* MCS 34 */
95 { 130, 144, 270, 300 }, /* MCS 35 */
96 { 117, 130, 243, 270 }, /* MCS 36 */
97 { 156, 173, 324, 360 }, /* MCS 37 */
98 { 195, 217, 405, 450 }, /* MCS 38 */
99 { 104, 116, 216, 240 }, /* MCS 39 */
100 { 130, 144, 270, 300 }, /* MCS 40 */
101 { 130, 144, 270, 300 }, /* MCS 41 */
102 { 156, 173, 324, 360 }, /* MCS 42 */
103 { 182, 202, 378, 420 }, /* MCS 43 */
104 { 182, 202, 378, 420 }, /* MCS 44 */
105 { 208, 231, 432, 480 }, /* MCS 45 */
106 { 156, 173, 324, 360 }, /* MCS 46 */
107 { 195, 217, 405, 450 }, /* MCS 47 */
108 { 195, 217, 405, 450 }, /* MCS 48 */
109 { 234, 260, 486, 540 }, /* MCS 49 */
110 { 273, 303, 567, 630 }, /* MCS 50 */
111 { 273, 303, 567, 630 }, /* MCS 51 */
112 { 312, 347, 648, 720 }, /* MCS 52 */
113 { 130, 144, 270, 300 }, /* MCS 53 */
114 { 156, 173, 324, 360 }, /* MCS 54 */
115 { 182, 202, 378, 420 }, /* MCS 55 */
116 { 156, 173, 324, 360 }, /* MCS 56 */
117 { 182, 202, 378, 420 }, /* MCS 57 */
118 { 208, 231, 432, 480 }, /* MCS 58 */
119 { 234, 260, 486, 540 }, /* MCS 59 */
120 { 208, 231, 432, 480 }, /* MCS 60 */
121 { 234, 260, 486, 540 }, /* MCS 61 */
122 { 260, 289, 540, 600 }, /* MCS 62 */
123 { 260, 289, 540, 600 }, /* MCS 63 */
124 { 286, 318, 594, 660 }, /* MCS 64 */
125 { 195, 217, 405, 450 }, /* MCS 65 */
126 { 234, 260, 486, 540 }, /* MCS 66 */
127 { 273, 303, 567, 630 }, /* MCS 67 */
128 { 234, 260, 486, 540 }, /* MCS 68 */
129 { 273, 303, 567, 630 }, /* MCS 69 */
130 { 312, 347, 648, 720 }, /* MCS 70 */
131 { 351, 390, 729, 810 }, /* MCS 71 */
132 { 312, 347, 648, 720 }, /* MCS 72 */
133 { 351, 390, 729, 810 }, /* MCS 73 */
134 { 390, 433, 810, 900 }, /* MCS 74 */
135 { 390, 433, 810, 900 }, /* MCS 75 */
136 { 429, 477, 891, 990 }, /* MCS 76 */
139 static int ieee80211_ampdu_age = -1; /* threshold for ampdu reorder q (ms) */
140 SYSCTL_PROC(_net_wlan, OID_AUTO, ampdu_age, CTLTYPE_INT | CTLFLAG_RW,
141 &ieee80211_ampdu_age, 0, ieee80211_sysctl_msecs_ticks, "I",
142 "AMPDU max reorder age (ms)");
144 static int ieee80211_recv_bar_ena = 1;
145 SYSCTL_INT(_net_wlan, OID_AUTO, recv_bar, CTLFLAG_RW, &ieee80211_recv_bar_ena,
146 0, "BAR frame processing (ena/dis)");
148 static int ieee80211_addba_timeout = -1;/* timeout for ADDBA response */
149 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_timeout, CTLTYPE_INT | CTLFLAG_RW,
150 &ieee80211_addba_timeout, 0, ieee80211_sysctl_msecs_ticks, "I",
151 "ADDBA request timeout (ms)");
152 static int ieee80211_addba_backoff = -1;/* backoff after max ADDBA requests */
153 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_backoff, CTLTYPE_INT | CTLFLAG_RW,
154 &ieee80211_addba_backoff, 0, ieee80211_sysctl_msecs_ticks, "I",
155 "ADDBA request backoff (ms)");
156 static int ieee80211_addba_maxtries = 3;/* max ADDBA requests before backoff */
157 SYSCTL_INT(_net_wlan, OID_AUTO, addba_maxtries, CTLFLAG_RW,
158 &ieee80211_addba_maxtries, 0, "max ADDBA requests sent before backoff");
160 static int ieee80211_bar_timeout = -1; /* timeout waiting for BAR response */
161 static int ieee80211_bar_maxtries = 50;/* max BAR requests before DELBA */
163 static ieee80211_recv_action_func ht_recv_action_ba_addba_request;
164 static ieee80211_recv_action_func ht_recv_action_ba_addba_response;
165 static ieee80211_recv_action_func ht_recv_action_ba_delba;
166 static ieee80211_recv_action_func ht_recv_action_ht_mimopwrsave;
167 static ieee80211_recv_action_func ht_recv_action_ht_txchwidth;
169 static ieee80211_send_action_func ht_send_action_ba_addba;
170 static ieee80211_send_action_func ht_send_action_ba_delba;
171 static ieee80211_send_action_func ht_send_action_ht_txchwidth;
174 ieee80211_ht_init(void)
177 * Setup HT parameters that depends on the clock frequency.
179 ieee80211_ampdu_age = msecs_to_ticks(500);
180 ieee80211_addba_timeout = msecs_to_ticks(250);
181 ieee80211_addba_backoff = msecs_to_ticks(10*1000);
182 ieee80211_bar_timeout = msecs_to_ticks(250);
184 * Register action frame handlers.
186 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
187 IEEE80211_ACTION_BA_ADDBA_REQUEST, ht_recv_action_ba_addba_request);
188 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
189 IEEE80211_ACTION_BA_ADDBA_RESPONSE, ht_recv_action_ba_addba_response);
190 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
191 IEEE80211_ACTION_BA_DELBA, ht_recv_action_ba_delba);
192 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_HT,
193 IEEE80211_ACTION_HT_MIMOPWRSAVE, ht_recv_action_ht_mimopwrsave);
194 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_HT,
195 IEEE80211_ACTION_HT_TXCHWIDTH, ht_recv_action_ht_txchwidth);
197 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
198 IEEE80211_ACTION_BA_ADDBA_REQUEST, ht_send_action_ba_addba);
199 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
200 IEEE80211_ACTION_BA_ADDBA_RESPONSE, ht_send_action_ba_addba);
201 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
202 IEEE80211_ACTION_BA_DELBA, ht_send_action_ba_delba);
203 ieee80211_send_action_register(IEEE80211_ACTION_CAT_HT,
204 IEEE80211_ACTION_HT_TXCHWIDTH, ht_send_action_ht_txchwidth);
206 SYSINIT(wlan_ht, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_ht_init, NULL);
208 static int ieee80211_ampdu_enable(struct ieee80211_node *ni,
209 struct ieee80211_tx_ampdu *tap);
210 static int ieee80211_addba_request(struct ieee80211_node *ni,
211 struct ieee80211_tx_ampdu *tap,
212 int dialogtoken, int baparamset, int batimeout);
213 static int ieee80211_addba_response(struct ieee80211_node *ni,
214 struct ieee80211_tx_ampdu *tap,
215 int code, int baparamset, int batimeout);
216 static void ieee80211_addba_stop(struct ieee80211_node *ni,
217 struct ieee80211_tx_ampdu *tap);
218 static void null_addba_response_timeout(struct ieee80211_node *ni,
219 struct ieee80211_tx_ampdu *tap);
221 static void ieee80211_bar_response(struct ieee80211_node *ni,
222 struct ieee80211_tx_ampdu *tap, int status);
223 static void ampdu_tx_stop(struct ieee80211_tx_ampdu *tap);
224 static void bar_stop_timer(struct ieee80211_tx_ampdu *tap);
225 static int ampdu_rx_start(struct ieee80211_node *, struct ieee80211_rx_ampdu *,
226 int baparamset, int batimeout, int baseqctl);
227 static void ampdu_rx_stop(struct ieee80211_node *, struct ieee80211_rx_ampdu *);
230 ieee80211_ht_attach(struct ieee80211com *ic)
232 /* setup default aggregation policy */
233 ic->ic_recv_action = ieee80211_recv_action;
234 ic->ic_send_action = ieee80211_send_action;
235 ic->ic_ampdu_enable = ieee80211_ampdu_enable;
236 ic->ic_addba_request = ieee80211_addba_request;
237 ic->ic_addba_response = ieee80211_addba_response;
238 ic->ic_addba_response_timeout = null_addba_response_timeout;
239 ic->ic_addba_stop = ieee80211_addba_stop;
240 ic->ic_bar_response = ieee80211_bar_response;
241 ic->ic_ampdu_rx_start = ampdu_rx_start;
242 ic->ic_ampdu_rx_stop = ampdu_rx_stop;
244 ic->ic_htprotmode = IEEE80211_PROT_RTSCTS;
245 ic->ic_curhtprotmode = IEEE80211_HTINFO_OPMODE_PURE;
249 ieee80211_ht_detach(struct ieee80211com *ic)
254 ieee80211_ht_vattach(struct ieee80211vap *vap)
257 /* driver can override defaults */
258 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_8K;
259 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_NA;
260 vap->iv_ampdu_limit = vap->iv_ampdu_rxmax;
261 vap->iv_amsdu_limit = vap->iv_htcaps & IEEE80211_HTCAP_MAXAMSDU;
262 /* tx aggregation traffic thresholds */
263 vap->iv_ampdu_mintraffic[WME_AC_BK] = 128;
264 vap->iv_ampdu_mintraffic[WME_AC_BE] = 64;
265 vap->iv_ampdu_mintraffic[WME_AC_VO] = 32;
266 vap->iv_ampdu_mintraffic[WME_AC_VI] = 32;
268 if (vap->iv_htcaps & IEEE80211_HTC_HT) {
270 * Device is HT capable; enable all HT-related
271 * facilities by default.
272 * XXX these choices may be too aggressive.
274 vap->iv_flags_ht |= IEEE80211_FHT_HT
275 | IEEE80211_FHT_HTCOMPAT
277 if (vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI20)
278 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI20;
279 /* XXX infer from channel list? */
280 if (vap->iv_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
281 vap->iv_flags_ht |= IEEE80211_FHT_USEHT40;
282 if (vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI40)
283 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI40;
285 /* enable RIFS if capable */
286 if (vap->iv_htcaps & IEEE80211_HTC_RIFS)
287 vap->iv_flags_ht |= IEEE80211_FHT_RIFS;
289 /* NB: A-MPDU and A-MSDU rx are mandated, these are tx only */
290 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_RX;
291 if (vap->iv_htcaps & IEEE80211_HTC_AMPDU)
292 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_TX;
293 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_RX;
294 if (vap->iv_htcaps & IEEE80211_HTC_AMSDU)
295 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_TX;
297 if (vap->iv_htcaps & IEEE80211_HTCAP_TXSTBC)
298 vap->iv_flags_ht |= IEEE80211_FHT_STBC_TX;
299 if (vap->iv_htcaps & IEEE80211_HTCAP_RXSTBC)
300 vap->iv_flags_ht |= IEEE80211_FHT_STBC_RX;
302 if (vap->iv_htcaps & IEEE80211_HTCAP_LDPC)
303 vap->iv_flags_ht |= IEEE80211_FHT_LDPC_RX;
304 if (vap->iv_htcaps & IEEE80211_HTC_TXLDPC)
305 vap->iv_flags_ht |= IEEE80211_FHT_LDPC_TX;
307 /* NB: disable default legacy WDS, too many issues right now */
308 if (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY)
309 vap->iv_flags_ht &= ~IEEE80211_FHT_HT;
313 ieee80211_ht_vdetach(struct ieee80211vap *vap)
318 ht_getrate(struct ieee80211com *ic, int index, enum ieee80211_phymode mode,
323 mword = ieee80211_rate2media(ic, index | IEEE80211_RATE_MCS, mode);
324 if (IFM_SUBTYPE(mword) != IFM_IEEE80211_MCS)
328 rate = ieee80211_htrates[index].ht20_rate_800ns;
331 rate = ieee80211_htrates[index].ht20_rate_400ns;
334 rate = ieee80211_htrates[index].ht40_rate_800ns;
337 rate = ieee80211_htrates[index].ht40_rate_400ns;
343 static struct printranges {
354 { 32, 0, 1, 2, IEEE80211_HTC_TXMCS32 },
355 { 33, 38, 2, 0, IEEE80211_HTC_TXUNEQUAL },
356 { 39, 52, 3, 0, IEEE80211_HTC_TXUNEQUAL },
357 { 53, 76, 4, 0, IEEE80211_HTC_TXUNEQUAL },
362 ht_rateprint(struct ieee80211com *ic, enum ieee80211_phymode mode, int ratetype)
364 int minrate, maxrate;
365 struct printranges *range;
367 for (range = ranges; range->txstream != 0; range++) {
368 if (ic->ic_txstream < range->txstream)
370 if (range->htcapflags &&
371 (ic->ic_htcaps & range->htcapflags) == 0)
373 if (ratetype < range->ratetype)
375 minrate = ht_getrate(ic, range->minmcs, mode, ratetype);
376 maxrate = ht_getrate(ic, range->maxmcs, mode, ratetype);
378 ic_printf(ic, "MCS %d-%d: %d%sMbps - %d%sMbps\n",
379 range->minmcs, range->maxmcs,
380 minrate/2, ((minrate & 0x1) != 0 ? ".5" : ""),
381 maxrate/2, ((maxrate & 0x1) != 0 ? ".5" : ""));
383 ic_printf(ic, "MCS %d: %d%sMbps\n", range->minmcs,
384 minrate/2, ((minrate & 0x1) != 0 ? ".5" : ""));
390 ht_announce(struct ieee80211com *ic, enum ieee80211_phymode mode)
392 const char *modestr = ieee80211_phymode_name[mode];
394 ic_printf(ic, "%s MCS 20MHz\n", modestr);
395 ht_rateprint(ic, mode, 0);
396 if (ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI20) {
397 ic_printf(ic, "%s MCS 20MHz SGI\n", modestr);
398 ht_rateprint(ic, mode, 1);
400 if (ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
401 ic_printf(ic, "%s MCS 40MHz:\n", modestr);
402 ht_rateprint(ic, mode, 2);
404 if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) &&
405 (ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI40)) {
406 ic_printf(ic, "%s MCS 40MHz SGI:\n", modestr);
407 ht_rateprint(ic, mode, 3);
412 ieee80211_ht_announce(struct ieee80211com *ic)
415 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NA) ||
416 isset(ic->ic_modecaps, IEEE80211_MODE_11NG))
417 ic_printf(ic, "%dT%dR\n", ic->ic_txstream, ic->ic_rxstream);
418 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NA))
419 ht_announce(ic, IEEE80211_MODE_11NA);
420 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NG))
421 ht_announce(ic, IEEE80211_MODE_11NG);
424 static struct ieee80211_htrateset htrateset;
426 const struct ieee80211_htrateset *
427 ieee80211_get_suphtrates(struct ieee80211com *ic,
428 const struct ieee80211_channel *c)
430 #define ADDRATE(x) do { \
431 htrateset.rs_rates[htrateset.rs_nrates] = x; \
432 htrateset.rs_nrates++; \
436 memset(&htrateset, 0, sizeof(struct ieee80211_htrateset));
437 for (i = 0; i < ic->ic_txstream * 8; i++)
439 if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) &&
440 (ic->ic_htcaps & IEEE80211_HTC_TXMCS32))
442 if (ic->ic_htcaps & IEEE80211_HTC_TXUNEQUAL) {
443 if (ic->ic_txstream >= 2) {
444 for (i = 33; i <= 38; i++)
447 if (ic->ic_txstream >= 3) {
448 for (i = 39; i <= 52; i++)
451 if (ic->ic_txstream == 4) {
452 for (i = 53; i <= 76; i++)
461 * Receive processing.
465 * Decap the encapsulated A-MSDU frames and dispatch all but
466 * the last for delivery. The last frame is returned for
467 * delivery via the normal path.
470 ieee80211_decap_amsdu(struct ieee80211_node *ni, struct mbuf *m)
472 struct ieee80211vap *vap = ni->ni_vap;
476 /* discard 802.3 header inserted by ieee80211_decap */
477 m_adj(m, sizeof(struct ether_header));
479 vap->iv_stats.is_amsdu_decap++;
483 * Decap the first frame, bust it apart from the
484 * remainder and deliver. We leave the last frame
485 * delivery to the caller (for consistency with other
486 * code paths, could also do it here).
488 m = ieee80211_decap1(m, &framelen);
490 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
491 ni->ni_macaddr, "a-msdu", "%s", "decap failed");
492 vap->iv_stats.is_amsdu_tooshort++;
495 if (m->m_pkthdr.len == framelen)
497 n = m_split(m, framelen, M_NOWAIT);
499 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
500 ni->ni_macaddr, "a-msdu",
501 "%s", "unable to split encapsulated frames");
502 vap->iv_stats.is_amsdu_split++;
503 m_freem(m); /* NB: must reclaim */
506 vap->iv_deliver_data(vap, ni, m);
509 * Remove frame contents; each intermediate frame
510 * is required to be aligned to a 4-byte boundary.
513 m_adj(m, roundup2(framelen, 4) - framelen); /* padding */
515 return m; /* last delivered by caller */
519 * Purge all frames in the A-MPDU re-order queue.
522 ampdu_rx_purge(struct ieee80211_rx_ampdu *rap)
527 for (i = 0; i < rap->rxa_wnd; i++) {
530 rap->rxa_m[i] = NULL;
531 rap->rxa_qbytes -= m->m_pkthdr.len;
533 if (--rap->rxa_qframes == 0)
537 KASSERT(rap->rxa_qbytes == 0 && rap->rxa_qframes == 0,
538 ("lost %u data, %u frames on ampdu rx q",
539 rap->rxa_qbytes, rap->rxa_qframes));
543 * Start A-MPDU rx/re-order processing for the specified TID.
546 ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap,
547 int baparamset, int batimeout, int baseqctl)
549 int bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
551 if (rap->rxa_flags & IEEE80211_AGGR_RUNNING) {
553 * AMPDU previously setup and not terminated with a DELBA,
554 * flush the reorder q's in case anything remains.
558 memset(rap, 0, sizeof(*rap));
559 rap->rxa_wnd = (bufsiz == 0) ?
560 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
561 rap->rxa_start = MS(baseqctl, IEEE80211_BASEQ_START);
562 rap->rxa_flags |= IEEE80211_AGGR_RUNNING | IEEE80211_AGGR_XCHGPEND;
568 * Public function; manually setup the RX ampdu state.
571 ieee80211_ampdu_rx_start_ext(struct ieee80211_node *ni, int tid, int seq, int baw)
573 struct ieee80211_rx_ampdu *rap;
575 /* XXX TODO: sanity check tid, seq, baw */
577 rap = &ni->ni_rx_ampdu[tid];
579 if (rap->rxa_flags & IEEE80211_AGGR_RUNNING) {
581 * AMPDU previously setup and not terminated with a DELBA,
582 * flush the reorder q's in case anything remains.
587 memset(rap, 0, sizeof(*rap));
588 rap->rxa_wnd = (baw== 0) ?
589 IEEE80211_AGGR_BAWMAX : min(baw, IEEE80211_AGGR_BAWMAX);
591 /* Wait for the first RX frame, use that as BAW */
593 rap->rxa_flags |= IEEE80211_AGGR_WAITRX;
595 rap->rxa_start = seq;
597 rap->rxa_flags |= IEEE80211_AGGR_RUNNING | IEEE80211_AGGR_XCHGPEND;
599 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
600 "%s: tid=%d, start=%d, wnd=%d, flags=0x%08x",
611 * Public function; manually stop the RX AMPDU state.
614 ieee80211_ampdu_rx_stop_ext(struct ieee80211_node *ni, int tid)
616 struct ieee80211_rx_ampdu *rap;
618 /* XXX TODO: sanity check tid, seq, baw */
619 rap = &ni->ni_rx_ampdu[tid];
620 ampdu_rx_stop(ni, rap);
624 * Stop A-MPDU rx processing for the specified TID.
627 ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
631 rap->rxa_flags &= ~(IEEE80211_AGGR_RUNNING
632 | IEEE80211_AGGR_XCHGPEND
633 | IEEE80211_AGGR_WAITRX);
637 * Dispatch a frame from the A-MPDU reorder queue. The
638 * frame is fed back into ieee80211_input marked with an
639 * M_AMPDU_MPDU flag so it doesn't come back to us (it also
640 * permits ieee80211_input to optimize re-processing).
643 ampdu_dispatch(struct ieee80211_node *ni, struct mbuf *m)
645 m->m_flags |= M_AMPDU_MPDU; /* bypass normal processing */
646 /* NB: rssi and noise are ignored w/ M_AMPDU_MPDU set */
647 (void) ieee80211_input(ni, m, 0, 0);
651 * Dispatch as many frames as possible from the re-order queue.
652 * Frames will always be "at the front"; we process all frames
653 * up to the first empty slot in the window. On completion we
654 * cleanup state if there are still pending frames in the current
655 * BA window. We assume the frame at slot 0 is already handled
656 * by the caller; we always start at slot 1.
659 ampdu_rx_dispatch(struct ieee80211_rx_ampdu *rap, struct ieee80211_node *ni)
661 struct ieee80211vap *vap = ni->ni_vap;
665 /* flush run of frames */
666 for (i = 1; i < rap->rxa_wnd; i++) {
670 rap->rxa_m[i] = NULL;
671 rap->rxa_qbytes -= m->m_pkthdr.len;
674 ampdu_dispatch(ni, m);
677 * If frames remain, copy the mbuf pointers down so
678 * they correspond to the offsets in the new window.
680 if (rap->rxa_qframes != 0) {
681 int n = rap->rxa_qframes, j;
682 for (j = i+1; j < rap->rxa_wnd; j++) {
683 if (rap->rxa_m[j] != NULL) {
684 rap->rxa_m[j-i] = rap->rxa_m[j];
685 rap->rxa_m[j] = NULL;
690 KASSERT(n == 0, ("lost %d frames", n));
691 vap->iv_stats.is_ampdu_rx_copy += rap->rxa_qframes;
694 * Adjust the start of the BA window to
695 * reflect the frames just dispatched.
697 rap->rxa_start = IEEE80211_SEQ_ADD(rap->rxa_start, i);
698 vap->iv_stats.is_ampdu_rx_oor += i;
702 * Dispatch all frames in the A-MPDU re-order queue.
705 ampdu_rx_flush(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
707 struct ieee80211vap *vap = ni->ni_vap;
711 for (i = 0; i < rap->rxa_wnd; i++) {
715 rap->rxa_m[i] = NULL;
716 rap->rxa_qbytes -= m->m_pkthdr.len;
718 vap->iv_stats.is_ampdu_rx_oor++;
720 ampdu_dispatch(ni, m);
721 if (rap->rxa_qframes == 0)
727 * Dispatch all frames in the A-MPDU re-order queue
728 * preceding the specified sequence number. This logic
729 * handles window moves due to a received MSDU or BAR.
732 ampdu_rx_flush_upto(struct ieee80211_node *ni,
733 struct ieee80211_rx_ampdu *rap, ieee80211_seq winstart)
735 struct ieee80211vap *vap = ni->ni_vap;
741 * Flush any complete MSDU's with a sequence number lower
742 * than winstart. Gaps may exist. Note that we may actually
743 * dispatch frames past winstart if a run continues; this is
744 * an optimization that avoids having to do a separate pass
745 * to dispatch frames after moving the BA window start.
747 seqno = rap->rxa_start;
748 for (i = 0; i < rap->rxa_wnd; i++) {
751 rap->rxa_m[i] = NULL;
752 rap->rxa_qbytes -= m->m_pkthdr.len;
754 vap->iv_stats.is_ampdu_rx_oor++;
756 ampdu_dispatch(ni, m);
758 if (!IEEE80211_SEQ_BA_BEFORE(seqno, winstart))
761 seqno = IEEE80211_SEQ_INC(seqno);
764 * If frames remain, copy the mbuf pointers down so
765 * they correspond to the offsets in the new window.
767 if (rap->rxa_qframes != 0) {
768 int n = rap->rxa_qframes, j;
770 /* NB: this loop assumes i > 0 and/or rxa_m[0] is NULL */
771 KASSERT(rap->rxa_m[0] == NULL,
772 ("%s: BA window slot 0 occupied", __func__));
773 for (j = i+1; j < rap->rxa_wnd; j++) {
774 if (rap->rxa_m[j] != NULL) {
775 rap->rxa_m[j-i] = rap->rxa_m[j];
776 rap->rxa_m[j] = NULL;
781 KASSERT(n == 0, ("%s: lost %d frames, qframes %d off %d "
782 "BA win <%d:%d> winstart %d",
783 __func__, n, rap->rxa_qframes, i, rap->rxa_start,
784 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
786 vap->iv_stats.is_ampdu_rx_copy += rap->rxa_qframes;
789 * Move the start of the BA window; we use the
790 * sequence number of the last MSDU that was
791 * passed up the stack+1 or winstart if stopped on
792 * a gap in the reorder buffer.
794 rap->rxa_start = seqno;
798 * Process a received QoS data frame for an HT station. Handle
799 * A-MPDU reordering: if this frame is received out of order
800 * and falls within the BA window hold onto it. Otherwise if
801 * this frame completes a run, flush any pending frames. We
802 * return 1 if the frame is consumed. A 0 is returned if
803 * the frame should be processed normally by the caller.
806 ieee80211_ampdu_reorder(struct ieee80211_node *ni, struct mbuf *m)
808 #define PROCESS 0 /* caller should process frame */
809 #define CONSUMED 1 /* frame consumed, caller does nothing */
810 struct ieee80211vap *vap = ni->ni_vap;
811 struct ieee80211_qosframe *wh;
812 struct ieee80211_rx_ampdu *rap;
817 KASSERT((m->m_flags & (M_AMPDU | M_AMPDU_MPDU)) == M_AMPDU,
818 ("!a-mpdu or already re-ordered, flags 0x%x", m->m_flags));
819 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
821 /* NB: m_len known to be sufficient */
822 wh = mtod(m, struct ieee80211_qosframe *);
823 if (wh->i_fc[0] != IEEE80211_FC0_QOSDATA) {
825 * Not QoS data, shouldn't get here but just
826 * return it to the caller for processing.
832 * 802.11-2012 9.3.2.10 - Duplicate detection and recovery.
834 * Multicast QoS data frames are checked against a different
835 * counter, not the per-TID counter.
837 if (IEEE80211_IS_MULTICAST(wh->i_addr1))
840 if (IEEE80211_IS_DSTODS(wh))
841 tid = ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0];
844 tid &= IEEE80211_QOS_TID;
845 rap = &ni->ni_rx_ampdu[tid];
846 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
848 * No ADDBA request yet, don't touch.
852 rxseq = le16toh(*(uint16_t *)wh->i_seq);
853 if ((rxseq & IEEE80211_SEQ_FRAG_MASK) != 0) {
855 * Fragments are not allowed; toss.
857 IEEE80211_DISCARD_MAC(vap,
858 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
859 "A-MPDU", "fragment, rxseq 0x%x tid %u%s", rxseq, tid,
860 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
861 vap->iv_stats.is_ampdu_rx_drop++;
862 IEEE80211_NODE_STAT(ni, rx_drop);
866 rxseq >>= IEEE80211_SEQ_SEQ_SHIFT;
870 * Handle waiting for the first frame to define the BAW.
871 * Some firmware doesn't provide the RX of the starting point
872 * of the BAW and we have to cope.
874 if (rap->rxa_flags & IEEE80211_AGGR_WAITRX) {
875 rap->rxa_flags &= ~IEEE80211_AGGR_WAITRX;
876 rap->rxa_start = rxseq;
879 if (rxseq == rap->rxa_start) {
881 * First frame in window.
883 if (rap->rxa_qframes != 0) {
885 * Dispatch as many packets as we can.
887 KASSERT(rap->rxa_m[0] == NULL, ("unexpected dup"));
888 ampdu_dispatch(ni, m);
889 ampdu_rx_dispatch(rap, ni);
893 * In order; advance window and notify
894 * caller to dispatch directly.
896 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
901 * Frame is out of order; store if in the BA window.
903 /* calculate offset in BA window */
904 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
905 if (off < rap->rxa_wnd) {
907 * Common case (hopefully): in the BA window.
908 * Sec 9.10.7.6.2 a) (p.137)
912 * Check for frames sitting too long in the reorder queue.
913 * This should only ever happen if frames are not delivered
914 * without the sender otherwise notifying us (e.g. with a
915 * BAR to move the window). Typically this happens because
916 * of vendor bugs that cause the sequence number to jump.
917 * When this happens we get a gap in the reorder queue that
918 * leaves frame sitting on the queue until they get pushed
919 * out due to window moves. When the vendor does not send
920 * BAR this move only happens due to explicit packet sends
922 * NB: we only track the time of the oldest frame in the
923 * reorder q; this means that if we flush we might push
924 * frames that still "new"; if this happens then subsequent
925 * frames will result in BA window moves which cost something
926 * but is still better than a big throughput dip.
928 if (rap->rxa_qframes != 0) {
929 /* XXX honor batimeout? */
930 if (ticks - rap->rxa_age > ieee80211_ampdu_age) {
932 * Too long since we received the first
933 * frame; flush the reorder buffer.
935 if (rap->rxa_qframes != 0) {
936 vap->iv_stats.is_ampdu_rx_age +=
938 ampdu_rx_flush(ni, rap);
940 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
945 * First frame, start aging timer.
947 rap->rxa_age = ticks;
951 if (rap->rxa_m[off] == NULL) {
954 rap->rxa_qbytes += m->m_pkthdr.len;
955 vap->iv_stats.is_ampdu_rx_reorder++;
957 IEEE80211_DISCARD_MAC(vap,
958 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
959 ni->ni_macaddr, "a-mpdu duplicate",
960 "seqno %u tid %u BA win <%u:%u>",
961 rxseq, tid, rap->rxa_start,
962 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1));
963 vap->iv_stats.is_rx_dup++;
964 IEEE80211_NODE_STAT(ni, rx_dup);
969 if (off < IEEE80211_SEQ_BA_RANGE) {
971 * Outside the BA window, but within range;
972 * flush the reorder q and move the window.
973 * Sec 9.10.7.6.2 b) (p.138)
975 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
976 "move BA win <%u:%u> (%u frames) rxseq %u tid %u",
978 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
979 rap->rxa_qframes, rxseq, tid);
980 vap->iv_stats.is_ampdu_rx_move++;
983 * The spec says to flush frames up to but not including:
984 * WinStart_B = rxseq - rap->rxa_wnd + 1
985 * Then insert the frame or notify the caller to process
986 * it immediately. We can safely do this by just starting
987 * over again because we know the frame will now be within
990 /* NB: rxa_wnd known to be >0 */
991 ampdu_rx_flush_upto(ni, rap,
992 IEEE80211_SEQ_SUB(rxseq, rap->rxa_wnd-1));
996 * Outside the BA window and out of range; toss.
997 * Sec 9.10.7.6.2 c) (p.138)
999 IEEE80211_DISCARD_MAC(vap,
1000 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
1001 "MPDU", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
1003 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
1004 rap->rxa_qframes, rxseq, tid,
1005 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
1006 vap->iv_stats.is_ampdu_rx_drop++;
1007 IEEE80211_NODE_STAT(ni, rx_drop);
1016 * Process a BAR ctl frame. Dispatch all frames up to
1017 * the sequence number of the frame. If this frame is
1018 * out of range it's discarded.
1021 ieee80211_recv_bar(struct ieee80211_node *ni, struct mbuf *m0)
1023 struct ieee80211vap *vap = ni->ni_vap;
1024 struct ieee80211_frame_bar *wh;
1025 struct ieee80211_rx_ampdu *rap;
1026 ieee80211_seq rxseq;
1029 if (!ieee80211_recv_bar_ena) {
1031 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_11N,
1032 ni->ni_macaddr, "BAR", "%s", "processing disabled");
1034 vap->iv_stats.is_ampdu_bar_bad++;
1037 wh = mtod(m0, struct ieee80211_frame_bar *);
1038 /* XXX check basic BAR */
1039 tid = MS(le16toh(wh->i_ctl), IEEE80211_BAR_TID);
1040 rap = &ni->ni_rx_ampdu[tid];
1041 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
1043 * No ADDBA request yet, don't touch.
1045 IEEE80211_DISCARD_MAC(vap,
1046 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
1047 ni->ni_macaddr, "BAR", "no BA stream, tid %u", tid);
1048 vap->iv_stats.is_ampdu_bar_bad++;
1051 vap->iv_stats.is_ampdu_bar_rx++;
1052 rxseq = le16toh(wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;
1053 if (rxseq == rap->rxa_start)
1055 /* calculate offset in BA window */
1056 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
1057 if (off < IEEE80211_SEQ_BA_RANGE) {
1059 * Flush the reorder q up to rxseq and move the window.
1060 * Sec 9.10.7.6.3 a) (p.138)
1062 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
1063 "BAR moves BA win <%u:%u> (%u frames) rxseq %u tid %u",
1065 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
1066 rap->rxa_qframes, rxseq, tid);
1067 vap->iv_stats.is_ampdu_bar_move++;
1069 ampdu_rx_flush_upto(ni, rap, rxseq);
1070 if (off >= rap->rxa_wnd) {
1072 * BAR specifies a window start to the right of BA
1073 * window; we must move it explicitly since
1074 * ampdu_rx_flush_upto will not.
1076 rap->rxa_start = rxseq;
1080 * Out of range; toss.
1081 * Sec 9.10.7.6.3 b) (p.138)
1083 IEEE80211_DISCARD_MAC(vap,
1084 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
1085 "BAR", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
1087 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
1088 rap->rxa_qframes, rxseq, tid,
1089 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
1090 vap->iv_stats.is_ampdu_bar_oow++;
1091 IEEE80211_NODE_STAT(ni, rx_drop);
1096 * Setup HT-specific state in a node. Called only
1097 * when HT use is negotiated so we don't do extra
1098 * work for temporary and/or legacy sta's.
1101 ieee80211_ht_node_init(struct ieee80211_node *ni)
1103 struct ieee80211_tx_ampdu *tap;
1106 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
1112 if (ni->ni_flags & IEEE80211_NODE_HT) {
1114 * Clean AMPDU state on re-associate. This handles the case
1115 * where a station leaves w/o notifying us and then returns
1116 * before node is reaped for inactivity.
1118 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
1120 "%s: calling cleanup (%p)",
1122 ieee80211_ht_node_cleanup(ni);
1124 for (tid = 0; tid < WME_NUM_TID; tid++) {
1125 tap = &ni->ni_tx_ampdu[tid];
1128 ieee80211_txampdu_init_pps(tap);
1129 /* NB: further initialization deferred */
1131 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
1135 * Cleanup HT-specific state in a node. Called only
1136 * when HT use has been marked.
1139 ieee80211_ht_node_cleanup(struct ieee80211_node *ni)
1141 struct ieee80211com *ic = ni->ni_ic;
1144 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
1149 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT node"));
1151 /* XXX optimize this */
1152 for (i = 0; i < WME_NUM_TID; i++) {
1153 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[i];
1154 if (tap->txa_flags & IEEE80211_AGGR_SETUP)
1157 for (i = 0; i < WME_NUM_TID; i++)
1158 ic->ic_ampdu_rx_stop(ni, &ni->ni_rx_ampdu[i]);
1161 ni->ni_flags &= ~IEEE80211_NODE_HT_ALL;
1165 * Age out HT resources for a station.
1168 ieee80211_ht_node_age(struct ieee80211_node *ni)
1170 struct ieee80211vap *vap = ni->ni_vap;
1173 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
1175 for (tid = 0; tid < WME_NUM_TID; tid++) {
1176 struct ieee80211_rx_ampdu *rap;
1178 rap = &ni->ni_rx_ampdu[tid];
1179 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0)
1181 if (rap->rxa_qframes == 0)
1184 * Check for frames sitting too long in the reorder queue.
1185 * See above for more details on what's happening here.
1187 /* XXX honor batimeout? */
1188 if (ticks - rap->rxa_age > ieee80211_ampdu_age) {
1190 * Too long since we received the first
1191 * frame; flush the reorder buffer.
1193 vap->iv_stats.is_ampdu_rx_age += rap->rxa_qframes;
1194 ampdu_rx_flush(ni, rap);
1199 static struct ieee80211_channel *
1200 findhtchan(struct ieee80211com *ic, struct ieee80211_channel *c, int htflags)
1202 return ieee80211_find_channel(ic, c->ic_freq,
1203 (c->ic_flags &~ IEEE80211_CHAN_HT) | htflags);
1207 * Adjust a channel to be HT/non-HT according to the vap's configuration.
1209 struct ieee80211_channel *
1210 ieee80211_ht_adjust_channel(struct ieee80211com *ic,
1211 struct ieee80211_channel *chan, int flags)
1213 struct ieee80211_channel *c;
1215 if (flags & IEEE80211_FHT_HT) {
1216 /* promote to HT if possible */
1217 if (flags & IEEE80211_FHT_USEHT40) {
1218 if (!IEEE80211_IS_CHAN_HT40(chan)) {
1219 /* NB: arbitrarily pick ht40+ over ht40- */
1220 c = findhtchan(ic, chan, IEEE80211_CHAN_HT40U);
1222 c = findhtchan(ic, chan,
1223 IEEE80211_CHAN_HT40D);
1225 c = findhtchan(ic, chan,
1226 IEEE80211_CHAN_HT20);
1230 } else if (!IEEE80211_IS_CHAN_HT20(chan)) {
1231 c = findhtchan(ic, chan, IEEE80211_CHAN_HT20);
1235 } else if (IEEE80211_IS_CHAN_HT(chan)) {
1236 /* demote to legacy, HT use is disabled */
1237 c = ieee80211_find_channel(ic, chan->ic_freq,
1238 chan->ic_flags &~ IEEE80211_CHAN_HT);
1246 * Setup HT-specific state for a legacy WDS peer.
1249 ieee80211_ht_wds_init(struct ieee80211_node *ni)
1251 struct ieee80211vap *vap = ni->ni_vap;
1252 struct ieee80211_tx_ampdu *tap;
1255 KASSERT(vap->iv_flags_ht & IEEE80211_FHT_HT, ("no HT requested"));
1257 /* XXX check scan cache in case peer has an ap and we have info */
1259 * If setup with a legacy channel; locate an HT channel.
1260 * Otherwise if the inherited channel (from a companion
1261 * AP) is suitable use it so we use the same location
1262 * for the extension channel).
1264 ni->ni_chan = ieee80211_ht_adjust_channel(ni->ni_ic,
1265 ni->ni_chan, ieee80211_htchanflags(ni->ni_chan));
1268 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20)
1269 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI20;
1270 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {
1271 ni->ni_htcap |= IEEE80211_HTCAP_CHWIDTH40;
1273 if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
1274 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_ABOVE;
1275 else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
1276 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_BELOW;
1277 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40)
1278 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI40;
1281 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_NONE;
1283 ni->ni_htctlchan = ni->ni_chan->ic_ieee;
1284 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
1285 ni->ni_flags |= IEEE80211_NODE_RIFS;
1286 /* XXX does it make sense to enable SMPS? */
1288 ni->ni_htopmode = 0; /* XXX need protection state */
1289 ni->ni_htstbc = 0; /* XXX need info */
1291 for (tid = 0; tid < WME_NUM_TID; tid++) {
1292 tap = &ni->ni_tx_ampdu[tid];
1294 ieee80211_txampdu_init_pps(tap);
1296 /* NB: AMPDU tx/rx governed by IEEE80211_FHT_AMPDU_{TX,RX} */
1297 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
1301 * Notify hostap vaps of a change in the HTINFO ie.
1304 htinfo_notify(struct ieee80211com *ic)
1306 struct ieee80211vap *vap;
1309 IEEE80211_LOCK_ASSERT(ic);
1311 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1312 if (vap->iv_opmode != IEEE80211_M_HOSTAP)
1314 if (vap->iv_state != IEEE80211_S_RUN ||
1315 !IEEE80211_IS_CHAN_HT(vap->iv_bss->ni_chan))
1319 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N,
1321 "HT bss occupancy change: %d sta, %d ht, "
1322 "%d ht40%s, HT protmode now 0x%x"
1324 , ic->ic_ht_sta_assoc
1325 , ic->ic_ht40_sta_assoc
1326 , (ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) ?
1327 ", non-HT sta present" : ""
1328 , ic->ic_curhtprotmode);
1331 ieee80211_beacon_notify(vap, IEEE80211_BEACON_HTINFO);
1336 * Calculate HT protection mode from current
1337 * state and handle updates.
1340 htinfo_update(struct ieee80211com *ic)
1344 if (ic->ic_sta_assoc != ic->ic_ht_sta_assoc) {
1345 protmode = IEEE80211_HTINFO_OPMODE_MIXED
1346 | IEEE80211_HTINFO_NONHT_PRESENT;
1347 } else if (ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) {
1348 protmode = IEEE80211_HTINFO_OPMODE_PROTOPT
1349 | IEEE80211_HTINFO_NONHT_PRESENT;
1350 } else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1351 IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) &&
1352 ic->ic_sta_assoc != ic->ic_ht40_sta_assoc) {
1353 protmode = IEEE80211_HTINFO_OPMODE_HT20PR;
1355 protmode = IEEE80211_HTINFO_OPMODE_PURE;
1357 if (protmode != ic->ic_curhtprotmode) {
1358 ic->ic_curhtprotmode = protmode;
1364 * Handle an HT station joining a BSS.
1367 ieee80211_ht_node_join(struct ieee80211_node *ni)
1369 struct ieee80211com *ic = ni->ni_ic;
1371 IEEE80211_LOCK_ASSERT(ic);
1373 if (ni->ni_flags & IEEE80211_NODE_HT) {
1374 ic->ic_ht_sta_assoc++;
1375 if (ni->ni_chw == 40)
1376 ic->ic_ht40_sta_assoc++;
1382 * Handle an HT station leaving a BSS.
1385 ieee80211_ht_node_leave(struct ieee80211_node *ni)
1387 struct ieee80211com *ic = ni->ni_ic;
1389 IEEE80211_LOCK_ASSERT(ic);
1391 if (ni->ni_flags & IEEE80211_NODE_HT) {
1392 ic->ic_ht_sta_assoc--;
1393 if (ni->ni_chw == 40)
1394 ic->ic_ht40_sta_assoc--;
1400 * Public version of htinfo_update; used for processing
1401 * beacon frames from overlapping bss.
1403 * Caller can specify either IEEE80211_HTINFO_OPMODE_MIXED
1404 * (on receipt of a beacon that advertises MIXED) or
1405 * IEEE80211_HTINFO_OPMODE_PROTOPT (on receipt of a beacon
1406 * from an overlapping legacy bss). We treat MIXED with
1407 * a higher precedence than PROTOPT (i.e. we will not change
1408 * change PROTOPT -> MIXED; only MIXED -> PROTOPT). This
1409 * corresponds to how we handle things in htinfo_update.
1412 ieee80211_htprot_update(struct ieee80211com *ic, int protmode)
1414 #define OPMODE(x) SM(x, IEEE80211_HTINFO_OPMODE)
1417 /* track non-HT station presence */
1418 KASSERT(protmode & IEEE80211_HTINFO_NONHT_PRESENT,
1419 ("protmode 0x%x", protmode));
1420 ic->ic_flags_ht |= IEEE80211_FHT_NONHT_PR;
1421 ic->ic_lastnonht = ticks;
1423 if (protmode != ic->ic_curhtprotmode &&
1424 (OPMODE(ic->ic_curhtprotmode) != IEEE80211_HTINFO_OPMODE_MIXED ||
1425 OPMODE(protmode) == IEEE80211_HTINFO_OPMODE_PROTOPT)) {
1426 /* push beacon update */
1427 ic->ic_curhtprotmode = protmode;
1430 IEEE80211_UNLOCK(ic);
1435 * Time out presence of an overlapping bss with non-HT
1436 * stations. When operating in hostap mode we listen for
1437 * beacons from other stations and if we identify a non-HT
1438 * station is present we update the opmode field of the
1439 * HTINFO ie. To identify when all non-HT stations are
1440 * gone we time out this condition.
1443 ieee80211_ht_timeout(struct ieee80211com *ic)
1445 IEEE80211_LOCK_ASSERT(ic);
1447 if ((ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) &&
1448 ieee80211_time_after(ticks, ic->ic_lastnonht + IEEE80211_NONHT_PRESENT_AGE)) {
1450 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
1451 "%s", "time out non-HT STA present on channel");
1453 ic->ic_flags_ht &= ~IEEE80211_FHT_NONHT_PR;
1459 * Process an 802.11n HT capabilities ie.
1462 ieee80211_parse_htcap(struct ieee80211_node *ni, const uint8_t *ie)
1464 if (ie[0] == IEEE80211_ELEMID_VENDOR) {
1466 * Station used Vendor OUI ie to associate;
1467 * mark the node so when we respond we'll use
1468 * the Vendor OUI's and not the standard ie's.
1470 ni->ni_flags |= IEEE80211_NODE_HTCOMPAT;
1473 ni->ni_flags &= ~IEEE80211_NODE_HTCOMPAT;
1475 ni->ni_htcap = le16dec(ie +
1476 __offsetof(struct ieee80211_ie_htcap, hc_cap));
1477 ni->ni_htparam = ie[__offsetof(struct ieee80211_ie_htcap, hc_param)];
1481 htinfo_parse(struct ieee80211_node *ni,
1482 const struct ieee80211_ie_htinfo *htinfo)
1486 ni->ni_htctlchan = htinfo->hi_ctrlchannel;
1487 ni->ni_ht2ndchan = SM(htinfo->hi_byte1, IEEE80211_HTINFO_2NDCHAN);
1488 w = le16dec(&htinfo->hi_byte2);
1489 ni->ni_htopmode = SM(w, IEEE80211_HTINFO_OPMODE);
1490 w = le16dec(&htinfo->hi_byte45);
1491 ni->ni_htstbc = SM(w, IEEE80211_HTINFO_BASIC_STBCMCS);
1495 * Parse an 802.11n HT info ie and save useful information
1496 * to the node state. Note this does not effect any state
1497 * changes such as for channel width change.
1500 ieee80211_parse_htinfo(struct ieee80211_node *ni, const uint8_t *ie)
1502 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1504 htinfo_parse(ni, (const struct ieee80211_ie_htinfo *) ie);
1508 * Handle 11n/11ac channel switch.
1510 * Use the received HT/VHT ie's to identify the right channel to use.
1511 * If we cannot locate it in the channel table then fallback to
1514 * Note that we use this information to identify the node's
1515 * channel only; the caller is responsible for insuring any
1516 * required channel change is done (e.g. in sta mode when
1517 * parsing the contents of a beacon frame).
1520 htinfo_update_chw(struct ieee80211_node *ni, int htflags, int vhtflags)
1522 struct ieee80211com *ic = ni->ni_ic;
1523 struct ieee80211_channel *c;
1528 * First step - do HT/VHT only channel lookup based on operating mode
1529 * flags. This involves masking out the VHT flags as well.
1530 * Otherwise we end up doing the full channel walk each time
1531 * we trigger this, which is expensive.
1533 chanflags = (ni->ni_chan->ic_flags &~
1534 (IEEE80211_CHAN_HT | IEEE80211_CHAN_VHT)) | htflags | vhtflags;
1536 if (chanflags == ni->ni_chan->ic_flags)
1540 * If HT /or/ VHT flags have changed then check both.
1541 * We need to start by picking a HT channel anyway.
1545 chanflags = (ni->ni_chan->ic_flags &~
1546 (IEEE80211_CHAN_HT | IEEE80211_CHAN_VHT)) | htflags;
1547 /* XXX not right for ht40- */
1548 c = ieee80211_find_channel(ic, ni->ni_chan->ic_freq, chanflags);
1549 if (c == NULL && (htflags & IEEE80211_CHAN_HT40)) {
1551 * No HT40 channel entry in our table; fall back
1552 * to HT20 operation. This should not happen.
1554 c = findhtchan(ic, ni->ni_chan, IEEE80211_CHAN_HT20);
1556 IEEE80211_NOTE(ni->ni_vap,
1557 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1558 "no HT40 channel (freq %u), falling back to HT20",
1559 ni->ni_chan->ic_freq);
1564 /* Nothing found - leave it alone; move onto VHT */
1569 * If it's non-HT, then bail out now.
1571 if (! IEEE80211_IS_CHAN_HT(c)) {
1572 IEEE80211_NOTE(ni->ni_vap,
1573 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1574 "not HT; skipping VHT check (%u/0x%x)",
1575 c->ic_freq, c->ic_flags);
1580 * Next step - look at the current VHT flags and determine
1581 * if we need to upgrade. Mask out the VHT and HT flags since
1582 * the vhtflags field will already have the correct HT
1585 if (IEEE80211_CONF_VHT(ic) && ni->ni_vhtcap != 0 && vhtflags != 0) {
1586 chanflags = (c->ic_flags
1587 &~ (IEEE80211_CHAN_HT | IEEE80211_CHAN_VHT))
1589 IEEE80211_NOTE(ni->ni_vap,
1590 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N,
1592 "%s: VHT; chanwidth=0x%02x; vhtflags=0x%08x",
1593 __func__, ni->ni_vht_chanwidth, vhtflags);
1595 IEEE80211_NOTE(ni->ni_vap,
1596 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N,
1598 "%s: VHT; trying lookup for %d/0x%08x",
1599 __func__, c->ic_freq, chanflags);
1600 c = ieee80211_find_channel(ic, c->ic_freq, chanflags);
1603 /* Finally, if it's changed */
1604 if (c != NULL && c != ni->ni_chan) {
1605 IEEE80211_NOTE(ni->ni_vap,
1606 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1607 "switch station to %s%d channel %u/0x%x",
1608 IEEE80211_IS_CHAN_VHT(c) ? "VHT" : "HT",
1609 IEEE80211_IS_CHAN_VHT80(c) ? 80 :
1610 (IEEE80211_IS_CHAN_HT40(c) ? 40 : 20),
1611 c->ic_freq, c->ic_flags);
1615 /* NB: caller responsible for forcing any channel change */
1618 /* update node's (11n) tx channel width */
1619 ni->ni_chw = IEEE80211_IS_CHAN_HT40(ni->ni_chan)? 40 : 20;
1624 * Update 11n MIMO PS state according to received htcap.
1627 htcap_update_mimo_ps(struct ieee80211_node *ni)
1629 uint16_t oflags = ni->ni_flags;
1631 switch (ni->ni_htcap & IEEE80211_HTCAP_SMPS) {
1632 case IEEE80211_HTCAP_SMPS_DYNAMIC:
1633 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1634 ni->ni_flags |= IEEE80211_NODE_MIMO_RTS;
1636 case IEEE80211_HTCAP_SMPS_ENA:
1637 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1638 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1640 case IEEE80211_HTCAP_SMPS_OFF:
1641 default: /* disable on rx of reserved value */
1642 ni->ni_flags &= ~IEEE80211_NODE_MIMO_PS;
1643 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1646 return (oflags ^ ni->ni_flags);
1650 * Update short GI state according to received htcap
1651 * and local settings.
1653 static __inline void
1654 htcap_update_shortgi(struct ieee80211_node *ni)
1656 struct ieee80211vap *vap = ni->ni_vap;
1658 ni->ni_flags &= ~(IEEE80211_NODE_SGI20|IEEE80211_NODE_SGI40);
1659 if ((ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20) &&
1660 (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20))
1661 ni->ni_flags |= IEEE80211_NODE_SGI20;
1662 if ((ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40) &&
1663 (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40))
1664 ni->ni_flags |= IEEE80211_NODE_SGI40;
1668 * Update LDPC state according to received htcap
1669 * and local settings.
1671 static __inline void
1672 htcap_update_ldpc(struct ieee80211_node *ni)
1674 struct ieee80211vap *vap = ni->ni_vap;
1676 if ((ni->ni_htcap & IEEE80211_HTCAP_LDPC) &&
1677 (vap->iv_flags_ht & IEEE80211_FHT_LDPC_TX))
1678 ni->ni_flags |= IEEE80211_NODE_LDPC;
1682 * Parse and update HT-related state extracted from
1683 * the HT cap and info ie's.
1685 * This is called from the STA management path and
1686 * the ieee80211_node_join() path. It will take into
1687 * account the IEs discovered during scanning and
1688 * adjust things accordingly.
1691 ieee80211_ht_updateparams(struct ieee80211_node *ni,
1692 const uint8_t *htcapie, const uint8_t *htinfoie)
1694 struct ieee80211vap *vap = ni->ni_vap;
1695 const struct ieee80211_ie_htinfo *htinfo;
1697 ieee80211_parse_htcap(ni, htcapie);
1698 if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS)
1699 htcap_update_mimo_ps(ni);
1700 htcap_update_shortgi(ni);
1701 htcap_update_ldpc(ni);
1703 if (htinfoie[0] == IEEE80211_ELEMID_VENDOR)
1705 htinfo = (const struct ieee80211_ie_htinfo *) htinfoie;
1706 htinfo_parse(ni, htinfo);
1709 * Defer the node channel change; we need to now
1710 * update VHT parameters before we do it.
1713 if ((htinfo->hi_byte1 & IEEE80211_HTINFO_RIFSMODE_PERM) &&
1714 (vap->iv_flags_ht & IEEE80211_FHT_RIFS))
1715 ni->ni_flags |= IEEE80211_NODE_RIFS;
1717 ni->ni_flags &= ~IEEE80211_NODE_RIFS;
1721 ieee80211_vht_get_vhtflags(struct ieee80211_node *ni, uint32_t htflags)
1723 struct ieee80211vap *vap = ni->ni_vap;
1724 uint32_t vhtflags = 0;
1727 if (ni->ni_flags & IEEE80211_NODE_VHT && vap->iv_flags_vht & IEEE80211_FVHT_VHT) {
1728 if ((ni->ni_vht_chanwidth == IEEE80211_VHT_CHANWIDTH_160MHZ) &&
1729 /* XXX 2 means "160MHz and 80+80MHz", 1 means "160MHz" */
1730 (MS(vap->iv_vhtcaps,
1731 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK) >= 1) &&
1732 (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT160)) {
1733 vhtflags = IEEE80211_CHAN_VHT160;
1734 /* Mirror the HT40 flags */
1735 if (htflags == IEEE80211_CHAN_HT40U) {
1736 vhtflags |= IEEE80211_CHAN_HT40U;
1737 } else if (htflags == IEEE80211_CHAN_HT40D) {
1738 vhtflags |= IEEE80211_CHAN_HT40D;
1740 } else if ((ni->ni_vht_chanwidth == IEEE80211_VHT_CHANWIDTH_80P80MHZ) &&
1741 /* XXX 2 means "160MHz and 80+80MHz" */
1742 (MS(vap->iv_vhtcaps,
1743 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK) == 2) &&
1744 (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80P80)) {
1745 vhtflags = IEEE80211_CHAN_VHT80_80;
1746 /* Mirror the HT40 flags */
1747 if (htflags == IEEE80211_CHAN_HT40U) {
1748 vhtflags |= IEEE80211_CHAN_HT40U;
1749 } else if (htflags == IEEE80211_CHAN_HT40D) {
1750 vhtflags |= IEEE80211_CHAN_HT40D;
1752 } else if ((ni->ni_vht_chanwidth == IEEE80211_VHT_CHANWIDTH_80MHZ) &&
1753 (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80)) {
1754 vhtflags = IEEE80211_CHAN_VHT80;
1755 /* Mirror the HT40 flags */
1756 if (htflags == IEEE80211_CHAN_HT40U) {
1757 vhtflags |= IEEE80211_CHAN_HT40U;
1758 } else if (htflags == IEEE80211_CHAN_HT40D) {
1759 vhtflags |= IEEE80211_CHAN_HT40D;
1761 } else if (ni->ni_vht_chanwidth == IEEE80211_VHT_CHANWIDTH_USE_HT) {
1762 /* Mirror the HT40 flags */
1764 * XXX TODO: if ht40 is disabled, but vht40 isn't
1765 * disabled then this logic will get very, very sad.
1766 * It's quite possible the only sane thing to do is
1767 * to not have vht40 as an option, and just obey
1768 * 'ht40' as that flag.
1770 if ((htflags == IEEE80211_CHAN_HT40U) &&
1771 (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT40)) {
1772 vhtflags = IEEE80211_CHAN_VHT40U
1773 | IEEE80211_CHAN_HT40U;
1774 } else if (htflags == IEEE80211_CHAN_HT40D &&
1775 (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT40)) {
1776 vhtflags = IEEE80211_CHAN_VHT40D
1777 | IEEE80211_CHAN_HT40D;
1778 } else if (htflags == IEEE80211_CHAN_HT20) {
1779 vhtflags = IEEE80211_CHAN_VHT20
1780 | IEEE80211_CHAN_HT20;
1783 vhtflags = IEEE80211_CHAN_VHT20;
1790 * Final part of updating the HT parameters.
1792 * This is called from the STA management path and
1793 * the ieee80211_node_join() path. It will take into
1794 * account the IEs discovered during scanning and
1795 * adjust things accordingly.
1797 * This is done after a call to ieee80211_ht_updateparams()
1798 * because it (and the upcoming VHT version of updateparams)
1799 * needs to ensure everything is parsed before htinfo_update_chw()
1800 * is called - which will change the channel config for the
1804 ieee80211_ht_updateparams_final(struct ieee80211_node *ni,
1805 const uint8_t *htcapie, const uint8_t *htinfoie)
1807 struct ieee80211vap *vap = ni->ni_vap;
1808 const struct ieee80211_ie_htinfo *htinfo;
1809 int htflags, vhtflags;
1812 htinfo = (const struct ieee80211_ie_htinfo *) htinfoie;
1814 htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ?
1815 IEEE80211_CHAN_HT20 : 0;
1817 /* NB: honor operating mode constraint */
1818 if ((htinfo->hi_byte1 & IEEE80211_HTINFO_TXWIDTH_2040) &&
1819 (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)) {
1820 if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_ABOVE)
1821 htflags = IEEE80211_CHAN_HT40U;
1822 else if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_BELOW)
1823 htflags = IEEE80211_CHAN_HT40D;
1827 * VHT flags - do much the same; check whether VHT is available
1828 * and if so, what our ideal channel use would be based on our
1829 * capabilities and the (pre-parsed) VHT info IE.
1831 vhtflags = ieee80211_vht_get_vhtflags(ni, htflags);
1833 if (htinfo_update_chw(ni, htflags, vhtflags))
1840 * Parse and update HT-related state extracted from the HT cap ie
1841 * for a station joining an HT BSS.
1843 * This is called from the hostap path for each station.
1846 ieee80211_ht_updatehtcap(struct ieee80211_node *ni, const uint8_t *htcapie)
1848 struct ieee80211vap *vap = ni->ni_vap;
1850 ieee80211_parse_htcap(ni, htcapie);
1851 if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS)
1852 htcap_update_mimo_ps(ni);
1853 htcap_update_shortgi(ni);
1854 htcap_update_ldpc(ni);
1858 * Called once HT and VHT capabilities are parsed in hostap mode -
1859 * this will adjust the channel configuration of the given node
1860 * based on the configuration and capabilities.
1863 ieee80211_ht_updatehtcap_final(struct ieee80211_node *ni)
1865 struct ieee80211vap *vap = ni->ni_vap;
1869 /* NB: honor operating mode constraint */
1870 /* XXX 40 MHz intolerant */
1871 htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ?
1872 IEEE80211_CHAN_HT20 : 0;
1873 if ((ni->ni_htcap & IEEE80211_HTCAP_CHWIDTH40) &&
1874 (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)) {
1875 if (IEEE80211_IS_CHAN_HT40U(vap->iv_bss->ni_chan))
1876 htflags = IEEE80211_CHAN_HT40U;
1877 else if (IEEE80211_IS_CHAN_HT40D(vap->iv_bss->ni_chan))
1878 htflags = IEEE80211_CHAN_HT40D;
1881 * VHT flags - do much the same; check whether VHT is available
1882 * and if so, what our ideal channel use would be based on our
1883 * capabilities and the (pre-parsed) VHT info IE.
1885 vhtflags = ieee80211_vht_get_vhtflags(ni, htflags);
1887 (void) htinfo_update_chw(ni, htflags, vhtflags);
1891 * Install received HT rate set by parsing the HT cap ie.
1894 ieee80211_setup_htrates(struct ieee80211_node *ni, const uint8_t *ie, int flags)
1896 struct ieee80211com *ic = ni->ni_ic;
1897 struct ieee80211vap *vap = ni->ni_vap;
1898 const struct ieee80211_ie_htcap *htcap;
1899 struct ieee80211_htrateset *rs;
1900 int i, maxequalmcs, maxunequalmcs;
1902 maxequalmcs = ic->ic_txstream * 8 - 1;
1904 if (ic->ic_htcaps & IEEE80211_HTC_TXUNEQUAL) {
1905 if (ic->ic_txstream >= 2)
1907 if (ic->ic_txstream >= 3)
1909 if (ic->ic_txstream >= 4)
1913 rs = &ni->ni_htrates;
1914 memset(rs, 0, sizeof(*rs));
1916 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1918 htcap = (const struct ieee80211_ie_htcap *) ie;
1919 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) {
1920 if (isclr(htcap->hc_mcsset, i))
1922 if (rs->rs_nrates == IEEE80211_HTRATE_MAXSIZE) {
1924 IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni,
1925 "WARNING, HT rate set too large; only "
1926 "using %u rates", IEEE80211_HTRATE_MAXSIZE);
1927 vap->iv_stats.is_rx_rstoobig++;
1930 if (i <= 31 && i > maxequalmcs)
1933 (ic->ic_htcaps & IEEE80211_HTC_TXMCS32) == 0)
1935 if (i > 32 && i > maxunequalmcs)
1937 rs->rs_rates[rs->rs_nrates++] = i;
1940 return ieee80211_fix_rate(ni, (struct ieee80211_rateset *) rs, flags);
1944 * Mark rates in a node's HT rate set as basic according
1945 * to the information in the supplied HT info ie.
1948 ieee80211_setup_basic_htrates(struct ieee80211_node *ni, const uint8_t *ie)
1950 const struct ieee80211_ie_htinfo *htinfo;
1951 struct ieee80211_htrateset *rs;
1954 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1956 htinfo = (const struct ieee80211_ie_htinfo *) ie;
1957 rs = &ni->ni_htrates;
1958 if (rs->rs_nrates == 0) {
1959 IEEE80211_NOTE(ni->ni_vap,
1960 IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni,
1961 "%s", "WARNING, empty HT rate set");
1964 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) {
1965 if (isclr(htinfo->hi_basicmcsset, i))
1967 for (j = 0; j < rs->rs_nrates; j++)
1968 if ((rs->rs_rates[j] & IEEE80211_RATE_VAL) == i)
1969 rs->rs_rates[j] |= IEEE80211_RATE_BASIC;
1974 ampdu_tx_setup(struct ieee80211_tx_ampdu *tap)
1976 callout_init(&tap->txa_timer, 1);
1977 tap->txa_flags |= IEEE80211_AGGR_SETUP;
1978 tap->txa_lastsample = ticks;
1982 ampdu_tx_stop(struct ieee80211_tx_ampdu *tap)
1984 struct ieee80211_node *ni = tap->txa_ni;
1985 struct ieee80211com *ic = ni->ni_ic;
1987 IEEE80211_NOTE(tap->txa_ni->ni_vap, IEEE80211_MSG_11N,
1992 KASSERT(tap->txa_flags & IEEE80211_AGGR_SETUP,
1993 ("txa_flags 0x%x tid %d ac %d", tap->txa_flags, tap->txa_tid,
1994 TID_TO_WME_AC(tap->txa_tid)));
1997 * Stop BA stream if setup so driver has a chance
1998 * to reclaim any resources it might have allocated.
2000 ic->ic_addba_stop(ni, tap);
2002 * Stop any pending BAR transmit.
2004 bar_stop_timer(tap);
2007 * Reset packet estimate.
2009 ieee80211_txampdu_init_pps(tap);
2011 /* NB: clearing NAK means we may re-send ADDBA */
2012 tap->txa_flags &= ~(IEEE80211_AGGR_SETUP | IEEE80211_AGGR_NAK);
2016 * ADDBA response timeout.
2018 * If software aggregation and per-TID queue management was done here,
2019 * that queue would be unpaused after the ADDBA timeout occurs.
2022 addba_timeout(void *arg)
2024 struct ieee80211_tx_ampdu *tap = arg;
2025 struct ieee80211_node *ni = tap->txa_ni;
2026 struct ieee80211com *ic = ni->ni_ic;
2029 tap->txa_flags &= ~IEEE80211_AGGR_XCHGPEND;
2030 tap->txa_attempts++;
2031 ic->ic_addba_response_timeout(ni, tap);
2035 addba_start_timeout(struct ieee80211_tx_ampdu *tap)
2037 /* XXX use CALLOUT_PENDING instead? */
2038 callout_reset(&tap->txa_timer, ieee80211_addba_timeout,
2039 addba_timeout, tap);
2040 tap->txa_flags |= IEEE80211_AGGR_XCHGPEND;
2041 tap->txa_nextrequest = ticks + ieee80211_addba_timeout;
2045 addba_stop_timeout(struct ieee80211_tx_ampdu *tap)
2047 /* XXX use CALLOUT_PENDING instead? */
2048 if (tap->txa_flags & IEEE80211_AGGR_XCHGPEND) {
2049 callout_stop(&tap->txa_timer);
2050 tap->txa_flags &= ~IEEE80211_AGGR_XCHGPEND;
2055 null_addba_response_timeout(struct ieee80211_node *ni,
2056 struct ieee80211_tx_ampdu *tap)
2061 * Default method for requesting A-MPDU tx aggregation.
2062 * We setup the specified state block and start a timer
2063 * to wait for an ADDBA response frame.
2066 ieee80211_addba_request(struct ieee80211_node *ni,
2067 struct ieee80211_tx_ampdu *tap,
2068 int dialogtoken, int baparamset, int batimeout)
2073 tap->txa_token = dialogtoken;
2074 tap->txa_flags |= IEEE80211_AGGR_IMMEDIATE;
2075 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
2076 tap->txa_wnd = (bufsiz == 0) ?
2077 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
2078 addba_start_timeout(tap);
2083 * Called by drivers that wish to request an ADDBA session be
2084 * setup. This brings it up and starts the request timer.
2087 ieee80211_ampdu_tx_request_ext(struct ieee80211_node *ni, int tid)
2089 struct ieee80211_tx_ampdu *tap;
2091 if (tid < 0 || tid > 15)
2093 tap = &ni->ni_tx_ampdu[tid];
2096 if ((tap->txa_flags & IEEE80211_AGGR_SETUP) == 0) {
2097 /* do deferred setup of state */
2098 ampdu_tx_setup(tap);
2100 /* XXX hack for not doing proper locking */
2101 tap->txa_flags &= ~IEEE80211_AGGR_NAK;
2102 addba_start_timeout(tap);
2107 * Called by drivers that have marked a session as active.
2110 ieee80211_ampdu_tx_request_active_ext(struct ieee80211_node *ni, int tid,
2113 struct ieee80211_tx_ampdu *tap;
2115 if (tid < 0 || tid > 15)
2117 tap = &ni->ni_tx_ampdu[tid];
2120 addba_stop_timeout(tap);
2122 tap->txa_flags |= IEEE80211_AGGR_RUNNING;
2123 tap->txa_attempts = 0;
2125 /* mark tid so we don't try again */
2126 tap->txa_flags |= IEEE80211_AGGR_NAK;
2132 * Default method for processing an A-MPDU tx aggregation
2133 * response. We shutdown any pending timer and update the
2134 * state block according to the reply.
2137 ieee80211_addba_response(struct ieee80211_node *ni,
2138 struct ieee80211_tx_ampdu *tap,
2139 int status, int baparamset, int batimeout)
2144 addba_stop_timeout(tap);
2145 if (status == IEEE80211_STATUS_SUCCESS) {
2146 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
2147 /* XXX override our request? */
2148 tap->txa_wnd = (bufsiz == 0) ?
2149 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
2151 tid = MS(baparamset, IEEE80211_BAPS_TID);
2152 tap->txa_flags |= IEEE80211_AGGR_RUNNING;
2153 tap->txa_attempts = 0;
2155 /* mark tid so we don't try again */
2156 tap->txa_flags |= IEEE80211_AGGR_NAK;
2162 * Default method for stopping A-MPDU tx aggregation.
2163 * Any timer is cleared and we drain any pending frames.
2166 ieee80211_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
2169 addba_stop_timeout(tap);
2170 if (tap->txa_flags & IEEE80211_AGGR_RUNNING) {
2171 /* XXX clear aggregation queue */
2172 tap->txa_flags &= ~IEEE80211_AGGR_RUNNING;
2174 tap->txa_attempts = 0;
2178 * Process a received action frame using the default aggregation
2179 * policy. We intercept ADDBA-related frames and use them to
2180 * update our aggregation state. All other frames are passed up
2181 * for processing by ieee80211_recv_action.
2184 ht_recv_action_ba_addba_request(struct ieee80211_node *ni,
2185 const struct ieee80211_frame *wh,
2186 const uint8_t *frm, const uint8_t *efrm)
2188 struct ieee80211com *ic = ni->ni_ic;
2189 struct ieee80211vap *vap = ni->ni_vap;
2190 struct ieee80211_rx_ampdu *rap;
2191 uint8_t dialogtoken;
2192 uint16_t baparamset, batimeout, baseqctl;
2196 dialogtoken = frm[2];
2197 baparamset = le16dec(frm+3);
2198 batimeout = le16dec(frm+5);
2199 baseqctl = le16dec(frm+7);
2201 tid = MS(baparamset, IEEE80211_BAPS_TID);
2203 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2204 "recv ADDBA request: dialogtoken %u baparamset 0x%x "
2205 "(tid %d bufsiz %d) batimeout %d baseqctl %d:%d",
2206 dialogtoken, baparamset,
2207 tid, MS(baparamset, IEEE80211_BAPS_BUFSIZ),
2209 MS(baseqctl, IEEE80211_BASEQ_START),
2210 MS(baseqctl, IEEE80211_BASEQ_FRAG));
2212 rap = &ni->ni_rx_ampdu[tid];
2214 /* Send ADDBA response */
2215 args[0] = dialogtoken;
2217 * NB: We ack only if the sta associated with HT and
2218 * the ap is configured to do AMPDU rx (the latter
2219 * violates the 11n spec and is mostly for testing).
2221 if ((ni->ni_flags & IEEE80211_NODE_AMPDU_RX) &&
2222 (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_RX)) {
2223 /* XXX handle ampdu_rx_start failure */
2224 ic->ic_ampdu_rx_start(ni, rap,
2225 baparamset, batimeout, baseqctl);
2227 args[1] = IEEE80211_STATUS_SUCCESS;
2229 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
2230 ni, "reject ADDBA request: %s",
2231 ni->ni_flags & IEEE80211_NODE_AMPDU_RX ?
2232 "administratively disabled" :
2233 "not negotiated for station");
2234 vap->iv_stats.is_addba_reject++;
2235 args[1] = IEEE80211_STATUS_UNSPECIFIED;
2237 /* XXX honor rap flags? */
2238 args[2] = IEEE80211_BAPS_POLICY_IMMEDIATE
2239 | SM(tid, IEEE80211_BAPS_TID)
2240 | SM(rap->rxa_wnd, IEEE80211_BAPS_BUFSIZ)
2244 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
2245 IEEE80211_ACTION_BA_ADDBA_RESPONSE, args);
2250 ht_recv_action_ba_addba_response(struct ieee80211_node *ni,
2251 const struct ieee80211_frame *wh,
2252 const uint8_t *frm, const uint8_t *efrm)
2254 struct ieee80211com *ic = ni->ni_ic;
2255 struct ieee80211vap *vap = ni->ni_vap;
2256 struct ieee80211_tx_ampdu *tap;
2257 uint8_t dialogtoken, policy;
2258 uint16_t baparamset, batimeout, code;
2261 dialogtoken = frm[2];
2262 code = le16dec(frm+3);
2263 baparamset = le16dec(frm+5);
2264 tid = MS(baparamset, IEEE80211_BAPS_TID);
2265 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
2266 policy = MS(baparamset, IEEE80211_BAPS_POLICY);
2267 batimeout = le16dec(frm+7);
2269 tap = &ni->ni_tx_ampdu[tid];
2270 if ((tap->txa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
2271 IEEE80211_DISCARD_MAC(vap,
2272 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
2273 ni->ni_macaddr, "ADDBA response",
2274 "no pending ADDBA, tid %d dialogtoken %u "
2275 "code %d", tid, dialogtoken, code);
2276 vap->iv_stats.is_addba_norequest++;
2279 if (dialogtoken != tap->txa_token) {
2280 IEEE80211_DISCARD_MAC(vap,
2281 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
2282 ni->ni_macaddr, "ADDBA response",
2283 "dialogtoken mismatch: waiting for %d, "
2284 "received %d, tid %d code %d",
2285 tap->txa_token, dialogtoken, tid, code);
2286 vap->iv_stats.is_addba_badtoken++;
2289 /* NB: assumes IEEE80211_AGGR_IMMEDIATE is 1 */
2290 if (policy != (tap->txa_flags & IEEE80211_AGGR_IMMEDIATE)) {
2291 IEEE80211_DISCARD_MAC(vap,
2292 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
2293 ni->ni_macaddr, "ADDBA response",
2294 "policy mismatch: expecting %s, "
2295 "received %s, tid %d code %d",
2296 tap->txa_flags & IEEE80211_AGGR_IMMEDIATE,
2298 vap->iv_stats.is_addba_badpolicy++;
2302 /* XXX we take MIN in ieee80211_addba_response */
2303 if (bufsiz > IEEE80211_AGGR_BAWMAX) {
2304 IEEE80211_DISCARD_MAC(vap,
2305 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
2306 ni->ni_macaddr, "ADDBA response",
2307 "BA window too large: max %d, "
2308 "received %d, tid %d code %d",
2309 bufsiz, IEEE80211_AGGR_BAWMAX, tid, code);
2310 vap->iv_stats.is_addba_badbawinsize++;
2314 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2315 "recv ADDBA response: dialogtoken %u code %d "
2316 "baparamset 0x%x (tid %d bufsiz %d) batimeout %d",
2317 dialogtoken, code, baparamset, tid, bufsiz,
2319 ic->ic_addba_response(ni, tap, code, baparamset, batimeout);
2324 ht_recv_action_ba_delba(struct ieee80211_node *ni,
2325 const struct ieee80211_frame *wh,
2326 const uint8_t *frm, const uint8_t *efrm)
2328 struct ieee80211com *ic = ni->ni_ic;
2329 struct ieee80211_rx_ampdu *rap;
2330 struct ieee80211_tx_ampdu *tap;
2331 uint16_t baparamset, code;
2334 baparamset = le16dec(frm+2);
2335 code = le16dec(frm+4);
2337 tid = MS(baparamset, IEEE80211_DELBAPS_TID);
2339 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2340 "recv DELBA: baparamset 0x%x (tid %d initiator %d) "
2341 "code %d", baparamset, tid,
2342 MS(baparamset, IEEE80211_DELBAPS_INIT), code);
2344 if ((baparamset & IEEE80211_DELBAPS_INIT) == 0) {
2345 tap = &ni->ni_tx_ampdu[tid];
2346 ic->ic_addba_stop(ni, tap);
2348 rap = &ni->ni_rx_ampdu[tid];
2349 ic->ic_ampdu_rx_stop(ni, rap);
2355 ht_recv_action_ht_txchwidth(struct ieee80211_node *ni,
2356 const struct ieee80211_frame *wh,
2357 const uint8_t *frm, const uint8_t *efrm)
2361 chw = (frm[2] == IEEE80211_A_HT_TXCHWIDTH_2040) ? 40 : 20;
2363 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2364 "%s: HT txchwidth, width %d%s",
2365 __func__, chw, ni->ni_chw != chw ? "*" : "");
2366 if (chw != ni->ni_chw) {
2367 /* XXX does this need to change the ht40 station count? */
2369 /* XXX notify on change */
2375 ht_recv_action_ht_mimopwrsave(struct ieee80211_node *ni,
2376 const struct ieee80211_frame *wh,
2377 const uint8_t *frm, const uint8_t *efrm)
2379 const struct ieee80211_action_ht_mimopowersave *mps =
2380 (const struct ieee80211_action_ht_mimopowersave *) frm;
2382 /* XXX check iv_htcaps */
2383 if (mps->am_control & IEEE80211_A_HT_MIMOPWRSAVE_ENA)
2384 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
2386 ni->ni_flags &= ~IEEE80211_NODE_MIMO_PS;
2387 if (mps->am_control & IEEE80211_A_HT_MIMOPWRSAVE_MODE)
2388 ni->ni_flags |= IEEE80211_NODE_MIMO_RTS;
2390 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
2391 /* XXX notify on change */
2392 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2393 "%s: HT MIMO PS (%s%s)", __func__,
2394 (ni->ni_flags & IEEE80211_NODE_MIMO_PS) ? "on" : "off",
2395 (ni->ni_flags & IEEE80211_NODE_MIMO_RTS) ? "+rts" : ""
2401 * Transmit processing.
2405 * Check if A-MPDU should be requested/enabled for a stream.
2406 * We require a traffic rate above a per-AC threshold and we
2407 * also handle backoff from previous failed attempts.
2409 * Drivers may override this method to bring in information
2410 * such as link state conditions in making the decision.
2413 ieee80211_ampdu_enable(struct ieee80211_node *ni,
2414 struct ieee80211_tx_ampdu *tap)
2416 struct ieee80211vap *vap = ni->ni_vap;
2418 if (tap->txa_avgpps <
2419 vap->iv_ampdu_mintraffic[TID_TO_WME_AC(tap->txa_tid)])
2421 /* XXX check rssi? */
2422 if (tap->txa_attempts >= ieee80211_addba_maxtries &&
2423 ieee80211_time_after(ticks, tap->txa_nextrequest)) {
2425 * Don't retry too often; txa_nextrequest is set
2426 * to the minimum interval we'll retry after
2427 * ieee80211_addba_maxtries failed attempts are made.
2431 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
2432 "enable AMPDU on tid %d (%s), avgpps %d pkts %d attempt %d",
2433 tap->txa_tid, ieee80211_wme_acnames[TID_TO_WME_AC(tap->txa_tid)],
2434 tap->txa_avgpps, tap->txa_pkts, tap->txa_attempts);
2439 * Request A-MPDU tx aggregation. Setup local state and
2440 * issue an ADDBA request. BA use will only happen after
2441 * the other end replies with ADDBA response.
2444 ieee80211_ampdu_request(struct ieee80211_node *ni,
2445 struct ieee80211_tx_ampdu *tap)
2447 struct ieee80211com *ic = ni->ni_ic;
2449 int tid, dialogtoken;
2450 static int tokens = 0; /* XXX */
2453 if ((tap->txa_flags & IEEE80211_AGGR_SETUP) == 0) {
2454 /* do deferred setup of state */
2455 ampdu_tx_setup(tap);
2457 /* XXX hack for not doing proper locking */
2458 tap->txa_flags &= ~IEEE80211_AGGR_NAK;
2460 dialogtoken = (tokens+1) % 63; /* XXX */
2464 * XXX TODO: This is racy with any other parallel TX going on. :(
2466 tap->txa_start = ni->ni_txseqs[tid];
2468 args[0] = dialogtoken;
2469 args[1] = 0; /* NB: status code not used */
2470 args[2] = IEEE80211_BAPS_POLICY_IMMEDIATE
2471 | SM(tid, IEEE80211_BAPS_TID)
2472 | SM(IEEE80211_AGGR_BAWMAX, IEEE80211_BAPS_BUFSIZ)
2474 args[3] = 0; /* batimeout */
2475 /* NB: do first so there's no race against reply */
2476 if (!ic->ic_addba_request(ni, tap, dialogtoken, args[2], args[3])) {
2477 /* unable to setup state, don't make request */
2478 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2479 ni, "%s: could not setup BA stream for TID %d AC %d",
2480 __func__, tap->txa_tid, TID_TO_WME_AC(tap->txa_tid));
2481 /* defer next try so we don't slam the driver with requests */
2482 tap->txa_attempts = ieee80211_addba_maxtries;
2483 /* NB: check in case driver wants to override */
2484 if (tap->txa_nextrequest <= ticks)
2485 tap->txa_nextrequest = ticks + ieee80211_addba_backoff;
2488 tokens = dialogtoken; /* allocate token */
2489 /* NB: after calling ic_addba_request so driver can set txa_start */
2490 args[4] = SM(tap->txa_start, IEEE80211_BASEQ_START)
2491 | SM(0, IEEE80211_BASEQ_FRAG)
2493 return ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
2494 IEEE80211_ACTION_BA_ADDBA_REQUEST, args);
2498 * Terminate an AMPDU tx stream. State is reclaimed
2499 * and the peer notified with a DelBA Action frame.
2502 ieee80211_ampdu_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
2505 struct ieee80211com *ic = ni->ni_ic;
2506 struct ieee80211vap *vap = ni->ni_vap;
2510 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
2511 if (IEEE80211_AMPDU_RUNNING(tap)) {
2512 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
2513 ni, "%s: stop BA stream for TID %d (reason: %d (%s))",
2514 __func__, tap->txa_tid, reason,
2515 ieee80211_reason_to_string(reason));
2516 vap->iv_stats.is_ampdu_stop++;
2518 ic->ic_addba_stop(ni, tap);
2519 args[0] = tap->txa_tid;
2520 args[1] = IEEE80211_DELBAPS_INIT;
2521 args[2] = reason; /* XXX reason code */
2522 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
2523 IEEE80211_ACTION_BA_DELBA, args);
2525 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
2526 ni, "%s: BA stream for TID %d not running "
2527 "(reason: %d (%s))", __func__, tap->txa_tid, reason,
2528 ieee80211_reason_to_string(reason));
2529 vap->iv_stats.is_ampdu_stop_failed++;
2534 static void bar_start_timer(struct ieee80211_tx_ampdu *tap);
2537 bar_timeout(void *arg)
2539 struct ieee80211_tx_ampdu *tap = arg;
2540 struct ieee80211_node *ni = tap->txa_ni;
2542 KASSERT((tap->txa_flags & IEEE80211_AGGR_XCHGPEND) == 0,
2543 ("bar/addba collision, flags 0x%x", tap->txa_flags));
2545 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2546 ni, "%s: tid %u flags 0x%x attempts %d", __func__,
2547 tap->txa_tid, tap->txa_flags, tap->txa_attempts);
2549 /* guard against race with bar_tx_complete */
2550 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) == 0)
2553 if (tap->txa_attempts >= ieee80211_bar_maxtries) {
2554 struct ieee80211com *ic = ni->ni_ic;
2556 ni->ni_vap->iv_stats.is_ampdu_bar_tx_fail++;
2558 * If (at least) the last BAR TX timeout was due to
2559 * an ieee80211_send_bar() failures, then we need
2560 * to make sure we notify the driver that a BAR
2561 * TX did occur and fail. This gives the driver
2562 * a chance to undo any queue pause that may
2565 ic->ic_bar_response(ni, tap, 1);
2566 ieee80211_ampdu_stop(ni, tap, IEEE80211_REASON_TIMEOUT);
2568 ni->ni_vap->iv_stats.is_ampdu_bar_tx_retry++;
2569 if (ieee80211_send_bar(ni, tap, tap->txa_seqpending) != 0) {
2570 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2571 ni, "%s: failed to TX, starting timer\n",
2574 * If ieee80211_send_bar() fails here, the
2575 * timer may have stopped and/or the pending
2576 * flag may be clear. Because of this,
2577 * fake the BARPEND and reset the timer.
2578 * A retransmission attempt will then occur
2579 * during the next timeout.
2582 tap->txa_flags |= IEEE80211_AGGR_BARPEND;
2583 bar_start_timer(tap);
2589 bar_start_timer(struct ieee80211_tx_ampdu *tap)
2591 IEEE80211_NOTE(tap->txa_ni->ni_vap, IEEE80211_MSG_11N,
2595 callout_reset(&tap->txa_timer, ieee80211_bar_timeout, bar_timeout, tap);
2599 bar_stop_timer(struct ieee80211_tx_ampdu *tap)
2601 IEEE80211_NOTE(tap->txa_ni->ni_vap, IEEE80211_MSG_11N,
2605 callout_stop(&tap->txa_timer);
2609 bar_tx_complete(struct ieee80211_node *ni, void *arg, int status)
2611 struct ieee80211_tx_ampdu *tap = arg;
2613 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2614 ni, "%s: tid %u flags 0x%x pending %d status %d",
2615 __func__, tap->txa_tid, tap->txa_flags,
2616 callout_pending(&tap->txa_timer), status);
2618 ni->ni_vap->iv_stats.is_ampdu_bar_tx++;
2620 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) &&
2621 callout_pending(&tap->txa_timer)) {
2622 struct ieee80211com *ic = ni->ni_ic;
2624 if (status == 0) /* ACK'd */
2625 bar_stop_timer(tap);
2626 ic->ic_bar_response(ni, tap, status);
2627 /* NB: just let timer expire so we pace requests */
2632 ieee80211_bar_response(struct ieee80211_node *ni,
2633 struct ieee80211_tx_ampdu *tap, int status)
2636 IEEE80211_NOTE(tap->txa_ni->ni_vap, IEEE80211_MSG_11N,
2640 if (status == 0) { /* got ACK */
2641 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2642 ni, "BAR moves BA win <%u:%u> (%u frames) txseq %u tid %u",
2644 IEEE80211_SEQ_ADD(tap->txa_start, tap->txa_wnd-1),
2645 tap->txa_qframes, tap->txa_seqpending,
2648 /* NB: timer already stopped in bar_tx_complete */
2649 tap->txa_start = tap->txa_seqpending;
2650 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
2655 * Transmit a BAR frame to the specified node. The
2656 * BAR contents are drawn from the supplied aggregation
2657 * state associated with the node.
2659 * NB: we only handle immediate ACK w/ compressed bitmap.
2662 ieee80211_send_bar(struct ieee80211_node *ni,
2663 struct ieee80211_tx_ampdu *tap, ieee80211_seq seq)
2665 #define senderr(_x, _v) do { vap->iv_stats._v++; ret = _x; goto bad; } while (0)
2666 struct ieee80211vap *vap = ni->ni_vap;
2667 struct ieee80211com *ic = ni->ni_ic;
2668 struct ieee80211_frame_bar *bar;
2670 uint16_t barctl, barseqctl;
2675 IEEE80211_NOTE(tap->txa_ni->ni_vap, IEEE80211_MSG_11N,
2680 if ((tap->txa_flags & IEEE80211_AGGR_RUNNING) == 0) {
2681 /* no ADDBA response, should not happen */
2686 bar_stop_timer(tap);
2688 ieee80211_ref_node(ni);
2690 m = ieee80211_getmgtframe(&frm, ic->ic_headroom, sizeof(*bar));
2692 senderr(ENOMEM, is_tx_nobuf);
2694 if (!ieee80211_add_callback(m, bar_tx_complete, tap)) {
2696 senderr(ENOMEM, is_tx_nobuf); /* XXX */
2700 bar = mtod(m, struct ieee80211_frame_bar *);
2701 bar->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2702 IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_BAR;
2704 IEEE80211_ADDR_COPY(bar->i_ra, ni->ni_macaddr);
2705 IEEE80211_ADDR_COPY(bar->i_ta, vap->iv_myaddr);
2708 barctl = (tap->txa_flags & IEEE80211_AGGR_IMMEDIATE ?
2709 0 : IEEE80211_BAR_NOACK)
2710 | IEEE80211_BAR_COMP
2711 | SM(tid, IEEE80211_BAR_TID)
2713 barseqctl = SM(seq, IEEE80211_BAR_SEQ_START);
2714 /* NB: known to have proper alignment */
2715 bar->i_ctl = htole16(barctl);
2716 bar->i_seq = htole16(barseqctl);
2717 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_bar);
2719 M_WME_SETAC(m, WME_AC_VO);
2721 IEEE80211_NODE_STAT(ni, tx_mgmt); /* XXX tx_ctl? */
2724 /* init/bump attempts counter */
2725 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) == 0)
2726 tap->txa_attempts = 1;
2728 tap->txa_attempts++;
2729 tap->txa_seqpending = seq;
2730 tap->txa_flags |= IEEE80211_AGGR_BARPEND;
2732 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_11N,
2733 ni, "send BAR: tid %u ctl 0x%x start %u (attempt %d)",
2734 tid, barctl, seq, tap->txa_attempts);
2737 * ic_raw_xmit will free the node reference
2738 * regardless of queue/TX success or failure.
2740 IEEE80211_TX_LOCK(ic);
2741 ret = ieee80211_raw_output(vap, ni, m, NULL);
2742 IEEE80211_TX_UNLOCK(ic);
2744 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_11N,
2745 ni, "send BAR: failed: (ret = %d)\n",
2747 /* xmit failed, clear state flag */
2748 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
2749 vap->iv_stats.is_ampdu_bar_tx_fail++;
2752 /* XXX hack against tx complete happening before timer is started */
2753 if (tap->txa_flags & IEEE80211_AGGR_BARPEND)
2754 bar_start_timer(tap);
2757 IEEE80211_NOTE(tap->txa_ni->ni_vap, IEEE80211_MSG_11N,
2761 vap->iv_stats.is_ampdu_bar_tx_fail++;
2762 ieee80211_free_node(ni);
2768 ht_action_output(struct ieee80211_node *ni, struct mbuf *m)
2770 struct ieee80211_bpf_params params;
2772 memset(¶ms, 0, sizeof(params));
2773 params.ibp_pri = WME_AC_VO;
2774 params.ibp_rate0 = ni->ni_txparms->mgmtrate;
2775 /* NB: we know all frames are unicast */
2776 params.ibp_try0 = ni->ni_txparms->maxretry;
2777 params.ibp_power = ni->ni_txpower;
2778 return ieee80211_mgmt_output(ni, m, IEEE80211_FC0_SUBTYPE_ACTION,
2782 #define ADDSHORT(frm, v) do { \
2783 frm[0] = (v) & 0xff; \
2784 frm[1] = (v) >> 8; \
2789 * Send an action management frame. The arguments are stuff
2790 * into a frame without inspection; the caller is assumed to
2791 * prepare them carefully (e.g. based on the aggregation state).
2794 ht_send_action_ba_addba(struct ieee80211_node *ni,
2795 int category, int action, void *arg0)
2797 struct ieee80211vap *vap = ni->ni_vap;
2798 struct ieee80211com *ic = ni->ni_ic;
2799 uint16_t *args = arg0;
2803 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2804 "send ADDBA %s: dialogtoken %d status %d "
2805 "baparamset 0x%x (tid %d) batimeout 0x%x baseqctl 0x%x",
2806 (action == IEEE80211_ACTION_BA_ADDBA_REQUEST) ?
2807 "request" : "response",
2808 args[0], args[1], args[2], MS(args[2], IEEE80211_BAPS_TID),
2811 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2812 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2813 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2814 ieee80211_ref_node(ni);
2816 m = ieee80211_getmgtframe(&frm,
2817 ic->ic_headroom + sizeof(struct ieee80211_frame),
2818 sizeof(uint16_t) /* action+category */
2819 /* XXX may action payload */
2820 + sizeof(struct ieee80211_action_ba_addbaresponse)
2825 *frm++ = args[0]; /* dialog token */
2826 if (action == IEEE80211_ACTION_BA_ADDBA_RESPONSE)
2827 ADDSHORT(frm, args[1]); /* status code */
2828 ADDSHORT(frm, args[2]); /* baparamset */
2829 ADDSHORT(frm, args[3]); /* batimeout */
2830 if (action == IEEE80211_ACTION_BA_ADDBA_REQUEST)
2831 ADDSHORT(frm, args[4]); /* baseqctl */
2832 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2833 return ht_action_output(ni, m);
2835 vap->iv_stats.is_tx_nobuf++;
2836 ieee80211_free_node(ni);
2842 ht_send_action_ba_delba(struct ieee80211_node *ni,
2843 int category, int action, void *arg0)
2845 struct ieee80211vap *vap = ni->ni_vap;
2846 struct ieee80211com *ic = ni->ni_ic;
2847 uint16_t *args = arg0;
2849 uint16_t baparamset;
2852 baparamset = SM(args[0], IEEE80211_DELBAPS_TID)
2855 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2856 "send DELBA action: tid %d, initiator %d reason %d (%s)",
2857 args[0], args[1], args[2], ieee80211_reason_to_string(args[2]));
2859 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2860 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2861 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2862 ieee80211_ref_node(ni);
2864 m = ieee80211_getmgtframe(&frm,
2865 ic->ic_headroom + sizeof(struct ieee80211_frame),
2866 sizeof(uint16_t) /* action+category */
2867 /* XXX may action payload */
2868 + sizeof(struct ieee80211_action_ba_addbaresponse)
2873 ADDSHORT(frm, baparamset);
2874 ADDSHORT(frm, args[2]); /* reason code */
2875 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2876 return ht_action_output(ni, m);
2878 vap->iv_stats.is_tx_nobuf++;
2879 ieee80211_free_node(ni);
2885 ht_send_action_ht_txchwidth(struct ieee80211_node *ni,
2886 int category, int action, void *arg0)
2888 struct ieee80211vap *vap = ni->ni_vap;
2889 struct ieee80211com *ic = ni->ni_ic;
2893 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2894 "send HT txchwidth: width %d",
2895 IEEE80211_IS_CHAN_HT40(ni->ni_chan) ? 40 : 20);
2897 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2898 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2899 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2900 ieee80211_ref_node(ni);
2902 m = ieee80211_getmgtframe(&frm,
2903 ic->ic_headroom + sizeof(struct ieee80211_frame),
2904 sizeof(uint16_t) /* action+category */
2905 /* XXX may action payload */
2906 + sizeof(struct ieee80211_action_ba_addbaresponse)
2911 *frm++ = IEEE80211_IS_CHAN_HT40(ni->ni_chan) ?
2912 IEEE80211_A_HT_TXCHWIDTH_2040 :
2913 IEEE80211_A_HT_TXCHWIDTH_20;
2914 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2915 return ht_action_output(ni, m);
2917 vap->iv_stats.is_tx_nobuf++;
2918 ieee80211_free_node(ni);
2925 * Construct the MCS bit mask for inclusion in an HT capabilities
2926 * information element.
2929 ieee80211_set_mcsset(struct ieee80211com *ic, uint8_t *frm)
2934 KASSERT((ic->ic_rxstream > 0 && ic->ic_rxstream <= 4),
2935 ("ic_rxstream %d out of range", ic->ic_rxstream));
2936 KASSERT((ic->ic_txstream > 0 && ic->ic_txstream <= 4),
2937 ("ic_txstream %d out of range", ic->ic_txstream));
2939 for (i = 0; i < ic->ic_rxstream * 8; i++)
2941 if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) &&
2942 (ic->ic_htcaps & IEEE80211_HTC_RXMCS32))
2944 if (ic->ic_htcaps & IEEE80211_HTC_RXUNEQUAL) {
2945 if (ic->ic_rxstream >= 2) {
2946 for (i = 33; i <= 38; i++)
2949 if (ic->ic_rxstream >= 3) {
2950 for (i = 39; i <= 52; i++)
2953 if (ic->ic_txstream >= 4) {
2954 for (i = 53; i <= 76; i++)
2959 if (ic->ic_rxstream != ic->ic_txstream) {
2960 txparams = 0x1; /* TX MCS set defined */
2961 txparams |= 0x2; /* TX RX MCS not equal */
2962 txparams |= (ic->ic_txstream - 1) << 2; /* num TX streams */
2963 if (ic->ic_htcaps & IEEE80211_HTC_TXUNEQUAL)
2964 txparams |= 0x16; /* TX unequal modulation sup */
2971 * Add body of an HTCAP information element.
2974 ieee80211_add_htcap_body(uint8_t *frm, struct ieee80211_node *ni)
2976 #define ADDSHORT(frm, v) do { \
2977 frm[0] = (v) & 0xff; \
2978 frm[1] = (v) >> 8; \
2981 struct ieee80211com *ic = ni->ni_ic;
2982 struct ieee80211vap *vap = ni->ni_vap;
2983 uint16_t caps, extcaps;
2986 /* HT capabilities */
2987 caps = vap->iv_htcaps & 0xffff;
2989 * Note channel width depends on whether we are operating as
2990 * a sta or not. When operating as a sta we are generating
2991 * a request based on our desired configuration. Otherwise
2992 * we are operational and the channel attributes identify
2993 * how we've been setup (which might be different if a fixed
2994 * channel is specified).
2996 if (vap->iv_opmode == IEEE80211_M_STA) {
2997 /* override 20/40 use based on config */
2998 if (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)
2999 caps |= IEEE80211_HTCAP_CHWIDTH40;
3001 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
3003 /* Start by using the advertised settings */
3004 rxmax = MS(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU);
3005 density = MS(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY);
3007 IEEE80211_DPRINTF(vap, IEEE80211_MSG_11N,
3008 "%s: advertised rxmax=%d, density=%d, vap rxmax=%d, density=%d\n",
3012 vap->iv_ampdu_rxmax,
3013 vap->iv_ampdu_density);
3015 /* Cap at VAP rxmax */
3016 if (rxmax > vap->iv_ampdu_rxmax)
3017 rxmax = vap->iv_ampdu_rxmax;
3020 * If the VAP ampdu density value greater, use that.
3022 * (Larger density value == larger minimum gap between A-MPDU
3025 if (vap->iv_ampdu_density > density)
3026 density = vap->iv_ampdu_density;
3029 * NB: Hardware might support HT40 on some but not all
3030 * channels. We can't determine this earlier because only
3031 * after association the channel is upgraded to HT based
3032 * on the negotiated capabilities.
3034 if (ni->ni_chan != IEEE80211_CHAN_ANYC &&
3035 findhtchan(ic, ni->ni_chan, IEEE80211_CHAN_HT40U) == NULL &&
3036 findhtchan(ic, ni->ni_chan, IEEE80211_CHAN_HT40D) == NULL)
3037 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
3039 /* override 20/40 use based on current channel */
3040 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
3041 caps |= IEEE80211_HTCAP_CHWIDTH40;
3043 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
3045 /* XXX TODO should it start by using advertised settings? */
3046 rxmax = vap->iv_ampdu_rxmax;
3047 density = vap->iv_ampdu_density;
3050 /* adjust short GI based on channel and config */
3051 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20) == 0)
3052 caps &= ~IEEE80211_HTCAP_SHORTGI20;
3053 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40) == 0 ||
3054 (caps & IEEE80211_HTCAP_CHWIDTH40) == 0)
3055 caps &= ~IEEE80211_HTCAP_SHORTGI40;
3057 /* adjust STBC based on receive capabilities */
3058 if ((vap->iv_flags_ht & IEEE80211_FHT_STBC_RX) == 0)
3059 caps &= ~IEEE80211_HTCAP_RXSTBC;
3061 /* adjust LDPC based on receive capabilites */
3062 if ((vap->iv_flags_ht & IEEE80211_FHT_LDPC_RX) == 0)
3063 caps &= ~IEEE80211_HTCAP_LDPC;
3065 ADDSHORT(frm, caps);
3068 *frm = SM(rxmax, IEEE80211_HTCAP_MAXRXAMPDU)
3069 | SM(density, IEEE80211_HTCAP_MPDUDENSITY)
3073 /* pre-zero remainder of ie */
3074 memset(frm, 0, sizeof(struct ieee80211_ie_htcap) -
3075 __offsetof(struct ieee80211_ie_htcap, hc_mcsset));
3077 /* supported MCS set */
3079 * XXX: For sta mode the rate set should be restricted based
3080 * on the AP's capabilities, but ni_htrates isn't setup when
3081 * we're called to form an AssocReq frame so for now we're
3082 * restricted to the device capabilities.
3084 ieee80211_set_mcsset(ni->ni_ic, frm);
3086 frm += __offsetof(struct ieee80211_ie_htcap, hc_extcap) -
3087 __offsetof(struct ieee80211_ie_htcap, hc_mcsset);
3089 /* HT extended capabilities */
3090 extcaps = vap->iv_htextcaps & 0xffff;
3092 ADDSHORT(frm, extcaps);
3094 frm += sizeof(struct ieee80211_ie_htcap) -
3095 __offsetof(struct ieee80211_ie_htcap, hc_txbf);
3102 * Add 802.11n HT capabilities information element
3105 ieee80211_add_htcap(uint8_t *frm, struct ieee80211_node *ni)
3107 frm[0] = IEEE80211_ELEMID_HTCAP;
3108 frm[1] = sizeof(struct ieee80211_ie_htcap) - 2;
3109 return ieee80211_add_htcap_body(frm + 2, ni);
3113 * Non-associated probe request - add HT capabilities based on
3114 * the current channel configuration.
3117 ieee80211_add_htcap_body_ch(uint8_t *frm, struct ieee80211vap *vap,
3118 struct ieee80211_channel *c)
3120 #define ADDSHORT(frm, v) do { \
3121 frm[0] = (v) & 0xff; \
3122 frm[1] = (v) >> 8; \
3125 struct ieee80211com *ic = vap->iv_ic;
3126 uint16_t caps, extcaps;
3129 /* HT capabilities */
3130 caps = vap->iv_htcaps & 0xffff;
3133 * We don't use this in STA mode; only in IBSS mode.
3134 * So in IBSS mode we base our HTCAP flags on the
3138 /* override 20/40 use based on current channel */
3139 if (IEEE80211_IS_CHAN_HT40(c))
3140 caps |= IEEE80211_HTCAP_CHWIDTH40;
3142 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
3144 /* Use the currently configured values */
3145 rxmax = vap->iv_ampdu_rxmax;
3146 density = vap->iv_ampdu_density;
3148 /* adjust short GI based on channel and config */
3149 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20) == 0)
3150 caps &= ~IEEE80211_HTCAP_SHORTGI20;
3151 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40) == 0 ||
3152 (caps & IEEE80211_HTCAP_CHWIDTH40) == 0)
3153 caps &= ~IEEE80211_HTCAP_SHORTGI40;
3154 ADDSHORT(frm, caps);
3157 *frm = SM(rxmax, IEEE80211_HTCAP_MAXRXAMPDU)
3158 | SM(density, IEEE80211_HTCAP_MPDUDENSITY)
3162 /* pre-zero remainder of ie */
3163 memset(frm, 0, sizeof(struct ieee80211_ie_htcap) -
3164 __offsetof(struct ieee80211_ie_htcap, hc_mcsset));
3166 /* supported MCS set */
3168 * XXX: For sta mode the rate set should be restricted based
3169 * on the AP's capabilities, but ni_htrates isn't setup when
3170 * we're called to form an AssocReq frame so for now we're
3171 * restricted to the device capabilities.
3173 ieee80211_set_mcsset(ic, frm);
3175 frm += __offsetof(struct ieee80211_ie_htcap, hc_extcap) -
3176 __offsetof(struct ieee80211_ie_htcap, hc_mcsset);
3178 /* HT extended capabilities */
3179 extcaps = vap->iv_htextcaps & 0xffff;
3181 ADDSHORT(frm, extcaps);
3183 frm += sizeof(struct ieee80211_ie_htcap) -
3184 __offsetof(struct ieee80211_ie_htcap, hc_txbf);
3191 * Add 802.11n HT capabilities information element
3194 ieee80211_add_htcap_ch(uint8_t *frm, struct ieee80211vap *vap,
3195 struct ieee80211_channel *c)
3197 frm[0] = IEEE80211_ELEMID_HTCAP;
3198 frm[1] = sizeof(struct ieee80211_ie_htcap) - 2;
3199 return ieee80211_add_htcap_body_ch(frm + 2, vap, c);
3203 * Add Broadcom OUI wrapped standard HTCAP ie; this is
3204 * used for compatibility w/ pre-draft implementations.
3207 ieee80211_add_htcap_vendor(uint8_t *frm, struct ieee80211_node *ni)
3209 frm[0] = IEEE80211_ELEMID_VENDOR;
3210 frm[1] = 4 + sizeof(struct ieee80211_ie_htcap) - 2;
3211 frm[2] = (BCM_OUI >> 0) & 0xff;
3212 frm[3] = (BCM_OUI >> 8) & 0xff;
3213 frm[4] = (BCM_OUI >> 16) & 0xff;
3214 frm[5] = BCM_OUI_HTCAP;
3215 return ieee80211_add_htcap_body(frm + 6, ni);
3219 * Construct the MCS bit mask of basic rates
3220 * for inclusion in an HT information element.
3223 ieee80211_set_basic_htrates(uint8_t *frm, const struct ieee80211_htrateset *rs)
3227 for (i = 0; i < rs->rs_nrates; i++) {
3228 int r = rs->rs_rates[i] & IEEE80211_RATE_VAL;
3229 if ((rs->rs_rates[i] & IEEE80211_RATE_BASIC) &&
3230 r < IEEE80211_HTRATE_MAXSIZE) {
3231 /* NB: this assumes a particular implementation */
3238 * Update the HTINFO ie for a beacon frame.
3241 ieee80211_ht_update_beacon(struct ieee80211vap *vap,
3242 struct ieee80211_beacon_offsets *bo)
3244 #define PROTMODE (IEEE80211_HTINFO_OPMODE|IEEE80211_HTINFO_NONHT_PRESENT)
3245 struct ieee80211_node *ni;
3246 const struct ieee80211_channel *bsschan;
3247 struct ieee80211com *ic = vap->iv_ic;
3248 struct ieee80211_ie_htinfo *ht =
3249 (struct ieee80211_ie_htinfo *) bo->bo_htinfo;
3251 ni = ieee80211_ref_node(vap->iv_bss);
3252 bsschan = ni->ni_chan;
3254 /* XXX only update on channel change */
3255 ht->hi_ctrlchannel = ieee80211_chan2ieee(ic, bsschan);
3256 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
3257 ht->hi_byte1 = IEEE80211_HTINFO_RIFSMODE_PERM;
3259 ht->hi_byte1 = IEEE80211_HTINFO_RIFSMODE_PROH;
3260 if (IEEE80211_IS_CHAN_HT40U(bsschan))
3261 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_ABOVE;
3262 else if (IEEE80211_IS_CHAN_HT40D(bsschan))
3263 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_BELOW;
3265 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_NONE;
3266 if (IEEE80211_IS_CHAN_HT40(bsschan))
3267 ht->hi_byte1 |= IEEE80211_HTINFO_TXWIDTH_2040;
3269 /* protection mode */
3270 ht->hi_byte2 = (ht->hi_byte2 &~ PROTMODE) | ic->ic_curhtprotmode;
3272 ieee80211_free_node(ni);
3274 /* XXX propagate to vendor ie's */
3279 * Add body of an HTINFO information element.
3281 * NB: We don't use struct ieee80211_ie_htinfo because we can
3282 * be called to fillin both a standard ie and a compat ie that
3283 * has a vendor OUI at the front.
3286 ieee80211_add_htinfo_body(uint8_t *frm, struct ieee80211_node *ni)
3288 struct ieee80211vap *vap = ni->ni_vap;
3289 struct ieee80211com *ic = ni->ni_ic;
3291 /* pre-zero remainder of ie */
3292 memset(frm, 0, sizeof(struct ieee80211_ie_htinfo) - 2);
3294 /* primary/control channel center */
3295 *frm++ = ieee80211_chan2ieee(ic, ni->ni_chan);
3297 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
3298 frm[0] = IEEE80211_HTINFO_RIFSMODE_PERM;
3300 frm[0] = IEEE80211_HTINFO_RIFSMODE_PROH;
3301 if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
3302 frm[0] |= IEEE80211_HTINFO_2NDCHAN_ABOVE;
3303 else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
3304 frm[0] |= IEEE80211_HTINFO_2NDCHAN_BELOW;
3306 frm[0] |= IEEE80211_HTINFO_2NDCHAN_NONE;
3307 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
3308 frm[0] |= IEEE80211_HTINFO_TXWIDTH_2040;
3310 frm[1] = ic->ic_curhtprotmode;
3315 ieee80211_set_basic_htrates(frm, &ni->ni_htrates);
3316 frm += sizeof(struct ieee80211_ie_htinfo) -
3317 __offsetof(struct ieee80211_ie_htinfo, hi_basicmcsset);
3322 * Add 802.11n HT information information element.
3325 ieee80211_add_htinfo(uint8_t *frm, struct ieee80211_node *ni)
3327 frm[0] = IEEE80211_ELEMID_HTINFO;
3328 frm[1] = sizeof(struct ieee80211_ie_htinfo) - 2;
3329 return ieee80211_add_htinfo_body(frm + 2, ni);
3333 * Add Broadcom OUI wrapped standard HTINFO ie; this is
3334 * used for compatibility w/ pre-draft implementations.
3337 ieee80211_add_htinfo_vendor(uint8_t *frm, struct ieee80211_node *ni)
3339 frm[0] = IEEE80211_ELEMID_VENDOR;
3340 frm[1] = 4 + sizeof(struct ieee80211_ie_htinfo) - 2;
3341 frm[2] = (BCM_OUI >> 0) & 0xff;
3342 frm[3] = (BCM_OUI >> 8) & 0xff;
3343 frm[4] = (BCM_OUI >> 16) & 0xff;
3344 frm[5] = BCM_OUI_HTINFO;
3345 return ieee80211_add_htinfo_body(frm + 6, ni);