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/systm.h>
41 #include <sys/endian.h>
43 #include <sys/socket.h>
46 #include <net/if_media.h>
47 #include <net/ethernet.h>
49 #include <net80211/ieee80211_var.h>
50 #include <net80211/ieee80211_action.h>
51 #include <net80211/ieee80211_input.h>
53 /* define here, used throughout file */
54 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
55 #define SM(_v, _f) (((_v) << _f##_S) & _f)
57 const struct ieee80211_mcs_rates ieee80211_htrates[16] = {
58 /* 20Mhz SGI 40Mhz SGI */
59 { 13, 14, 27, 30 }, /* MCS 0 */
60 { 26, 29, 54, 60 }, /* MCS 1 */
61 { 39, 43, 81, 90 }, /* MCS 2 */
62 { 52, 58, 108, 120 }, /* MCS 3 */
63 { 78, 87, 162, 180 }, /* MCS 4 */
64 { 104, 116, 216, 240 }, /* MCS 5 */
65 { 117, 130, 243, 270 }, /* MCS 6 */
66 { 130, 144, 270, 300 }, /* MCS 7 */
67 { 26, 29, 54, 60 }, /* MCS 8 */
68 { 52, 58, 108, 120 }, /* MCS 9 */
69 { 78, 87, 162, 180 }, /* MCS 10 */
70 { 104, 116, 216, 240 }, /* MCS 11 */
71 { 156, 173, 324, 360 }, /* MCS 12 */
72 { 208, 231, 432, 480 }, /* MCS 13 */
73 { 234, 260, 486, 540 }, /* MCS 14 */
74 { 260, 289, 540, 600 } /* MCS 15 */
77 static const struct ieee80211_htrateset ieee80211_rateset_11n =
79 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
80 10, 11, 12, 13, 14, 15 }
83 #ifdef IEEE80211_AMPDU_AGE
84 static int ieee80211_ampdu_age = -1; /* threshold for ampdu reorder q (ms) */
85 SYSCTL_PROC(_net_wlan, OID_AUTO, ampdu_age, CTLTYPE_INT | CTLFLAG_RW,
86 &ieee80211_ampdu_age, 0, ieee80211_sysctl_msecs_ticks, "I",
87 "AMPDU max reorder age (ms)");
90 static int ieee80211_recv_bar_ena = 1;
91 SYSCTL_INT(_net_wlan, OID_AUTO, recv_bar, CTLFLAG_RW, &ieee80211_recv_bar_ena,
92 0, "BAR frame processing (ena/dis)");
94 static int ieee80211_addba_timeout = -1;/* timeout for ADDBA response */
95 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_timeout, CTLTYPE_INT | CTLFLAG_RW,
96 &ieee80211_addba_timeout, 0, ieee80211_sysctl_msecs_ticks, "I",
97 "ADDBA request timeout (ms)");
98 static int ieee80211_addba_backoff = -1;/* backoff after max ADDBA requests */
99 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_backoff, CTLTYPE_INT | CTLFLAG_RW,
100 &ieee80211_addba_backoff, 0, ieee80211_sysctl_msecs_ticks, "I",
101 "ADDBA request backoff (ms)");
102 static int ieee80211_addba_maxtries = 3;/* max ADDBA requests before backoff */
103 SYSCTL_INT(_net_wlan, OID_AUTO, addba_maxtries, CTLTYPE_INT | CTLFLAG_RW,
104 &ieee80211_addba_maxtries, 0, "max ADDBA requests sent before backoff");
106 static int ieee80211_bar_timeout = -1; /* timeout waiting for BAR response */
107 static int ieee80211_bar_maxtries = 50;/* max BAR requests before DELBA */
109 static ieee80211_recv_action_func ht_recv_action_ba_addba_request;
110 static ieee80211_recv_action_func ht_recv_action_ba_addba_response;
111 static ieee80211_recv_action_func ht_recv_action_ba_delba;
112 static ieee80211_recv_action_func ht_recv_action_ht_mimopwrsave;
113 static ieee80211_recv_action_func ht_recv_action_ht_txchwidth;
115 static ieee80211_send_action_func ht_send_action_ba_addba;
116 static ieee80211_send_action_func ht_send_action_ba_delba;
117 static ieee80211_send_action_func ht_send_action_ht_txchwidth;
120 ieee80211_ht_init(void)
123 * Setup HT parameters that depends on the clock frequency.
125 #ifdef IEEE80211_AMPDU_AGE
126 ieee80211_ampdu_age = msecs_to_ticks(500);
128 ieee80211_addba_timeout = msecs_to_ticks(250);
129 ieee80211_addba_backoff = msecs_to_ticks(10*1000);
130 ieee80211_bar_timeout = msecs_to_ticks(250);
132 * Register action frame handlers.
134 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
135 IEEE80211_ACTION_BA_ADDBA_REQUEST, ht_recv_action_ba_addba_request);
136 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
137 IEEE80211_ACTION_BA_ADDBA_RESPONSE, ht_recv_action_ba_addba_response);
138 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
139 IEEE80211_ACTION_BA_DELBA, ht_recv_action_ba_delba);
140 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_HT,
141 IEEE80211_ACTION_HT_MIMOPWRSAVE, ht_recv_action_ht_mimopwrsave);
142 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_HT,
143 IEEE80211_ACTION_HT_TXCHWIDTH, ht_recv_action_ht_txchwidth);
145 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
146 IEEE80211_ACTION_BA_ADDBA_REQUEST, ht_send_action_ba_addba);
147 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
148 IEEE80211_ACTION_BA_ADDBA_RESPONSE, ht_send_action_ba_addba);
149 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
150 IEEE80211_ACTION_BA_DELBA, ht_send_action_ba_delba);
151 ieee80211_send_action_register(IEEE80211_ACTION_CAT_HT,
152 IEEE80211_ACTION_HT_TXCHWIDTH, ht_send_action_ht_txchwidth);
154 SYSINIT(wlan_ht, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_ht_init, NULL);
156 static int ieee80211_ampdu_enable(struct ieee80211_node *ni,
157 struct ieee80211_tx_ampdu *tap);
158 static int ieee80211_addba_request(struct ieee80211_node *ni,
159 struct ieee80211_tx_ampdu *tap,
160 int dialogtoken, int baparamset, int batimeout);
161 static int ieee80211_addba_response(struct ieee80211_node *ni,
162 struct ieee80211_tx_ampdu *tap,
163 int code, int baparamset, int batimeout);
164 static void ieee80211_addba_stop(struct ieee80211_node *ni,
165 struct ieee80211_tx_ampdu *tap);
166 static void ieee80211_bar_response(struct ieee80211_node *ni,
167 struct ieee80211_tx_ampdu *tap, int status);
168 static void ampdu_tx_stop(struct ieee80211_tx_ampdu *tap);
169 static void bar_stop_timer(struct ieee80211_tx_ampdu *tap);
170 static int ampdu_rx_start(struct ieee80211_node *, struct ieee80211_rx_ampdu *,
171 int baparamset, int batimeout, int baseqctl);
172 static void ampdu_rx_stop(struct ieee80211_node *, struct ieee80211_rx_ampdu *);
175 ieee80211_ht_attach(struct ieee80211com *ic)
177 /* setup default aggregation policy */
178 ic->ic_recv_action = ieee80211_recv_action;
179 ic->ic_send_action = ieee80211_send_action;
180 ic->ic_ampdu_enable = ieee80211_ampdu_enable;
181 ic->ic_addba_request = ieee80211_addba_request;
182 ic->ic_addba_response = ieee80211_addba_response;
183 ic->ic_addba_stop = ieee80211_addba_stop;
184 ic->ic_bar_response = ieee80211_bar_response;
185 ic->ic_ampdu_rx_start = ampdu_rx_start;
186 ic->ic_ampdu_rx_stop = ampdu_rx_stop;
188 ic->ic_htprotmode = IEEE80211_PROT_RTSCTS;
189 ic->ic_curhtprotmode = IEEE80211_HTINFO_OPMODE_PURE;
193 ieee80211_ht_detach(struct ieee80211com *ic)
198 ieee80211_ht_vattach(struct ieee80211vap *vap)
201 /* driver can override defaults */
202 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_8K;
203 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_NA;
204 vap->iv_ampdu_limit = vap->iv_ampdu_rxmax;
205 vap->iv_amsdu_limit = vap->iv_htcaps & IEEE80211_HTCAP_MAXAMSDU;
206 /* tx aggregation traffic thresholds */
207 vap->iv_ampdu_mintraffic[WME_AC_BK] = 128;
208 vap->iv_ampdu_mintraffic[WME_AC_BE] = 64;
209 vap->iv_ampdu_mintraffic[WME_AC_VO] = 32;
210 vap->iv_ampdu_mintraffic[WME_AC_VI] = 32;
212 if (vap->iv_htcaps & IEEE80211_HTC_HT) {
214 * Device is HT capable; enable all HT-related
215 * facilities by default.
216 * XXX these choices may be too aggressive.
218 vap->iv_flags_ht |= IEEE80211_FHT_HT
219 | IEEE80211_FHT_HTCOMPAT
221 if (vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI20)
222 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI20;
223 /* XXX infer from channel list? */
224 if (vap->iv_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
225 vap->iv_flags_ht |= IEEE80211_FHT_USEHT40;
226 if (vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI40)
227 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI40;
229 /* enable RIFS if capable */
230 if (vap->iv_htcaps & IEEE80211_HTC_RIFS)
231 vap->iv_flags_ht |= IEEE80211_FHT_RIFS;
233 /* NB: A-MPDU and A-MSDU rx are mandated, these are tx only */
234 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_RX;
235 if (vap->iv_htcaps & IEEE80211_HTC_AMPDU)
236 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_TX;
237 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_RX;
238 if (vap->iv_htcaps & IEEE80211_HTC_AMSDU)
239 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_TX;
241 /* NB: disable default legacy WDS, too many issues right now */
242 if (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY)
243 vap->iv_flags_ht &= ~IEEE80211_FHT_HT;
247 ieee80211_ht_vdetach(struct ieee80211vap *vap)
252 ht_rateprint(struct ieee80211com *ic, int mode,
253 const struct ieee80211_htrateset *rs, int maxmcs, int ratetype)
257 for (i = 0; i < rs->rs_nrates && i < maxmcs; i++) {
258 mword = ieee80211_rate2media(ic,
259 rs->rs_rates[i] | IEEE80211_RATE_MCS, mode);
260 if (IFM_SUBTYPE(mword) != IFM_IEEE80211_MCS)
264 rate = ieee80211_htrates[
265 rs->rs_rates[i]].ht20_rate_800ns;
268 rate = ieee80211_htrates[
269 rs->rs_rates[i]].ht20_rate_400ns;
272 rate = ieee80211_htrates[
273 rs->rs_rates[i]].ht40_rate_800ns;
276 rate = ieee80211_htrates[
277 rs->rs_rates[i]].ht40_rate_400ns;
280 printf("%s%d%sMbps", (i != 0 ? " " : ""),
281 rate / 2, ((rate & 0x1) != 0 ? ".5" : ""));
287 ht_announce(struct ieee80211com *ic, int mode,
288 const struct ieee80211_htrateset *rs)
290 struct ifnet *ifp = ic->ic_ifp;
292 const char *modestr = ieee80211_phymode_name[mode];
294 KASSERT(maxmcs <= 16, ("maxmcs > 16"));
295 if_printf(ifp, "%d MCS rates\n", maxmcs);
296 if_printf(ifp, "%s MCS 20Mhz: ", modestr);
297 ht_rateprint(ic, mode, rs, maxmcs, 0);
298 if_printf(ifp, "%s MCS 20Mhz SGI: ", modestr);
299 ht_rateprint(ic, mode, rs, maxmcs, 1);
300 if_printf(ifp, "%s MCS 40Mhz: ", modestr);
301 ht_rateprint(ic, mode, rs, maxmcs, 2);
302 if_printf(ifp, "%s MCS 40Mhz SGI: ", modestr);
303 ht_rateprint(ic, mode, rs, maxmcs, 3);
307 ieee80211_ht_announce(struct ieee80211com *ic)
309 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NA))
310 ht_announce(ic, IEEE80211_MODE_11NA, &ieee80211_rateset_11n);
311 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NG))
312 ht_announce(ic, IEEE80211_MODE_11NG, &ieee80211_rateset_11n);
315 const struct ieee80211_htrateset *
316 ieee80211_get_suphtrates(struct ieee80211com *ic,
317 const struct ieee80211_channel *c)
319 return &ieee80211_rateset_11n;
323 * Receive processing.
327 * Decap the encapsulated A-MSDU frames and dispatch all but
328 * the last for delivery. The last frame is returned for
329 * delivery via the normal path.
332 ieee80211_decap_amsdu(struct ieee80211_node *ni, struct mbuf *m)
334 struct ieee80211vap *vap = ni->ni_vap;
338 /* discard 802.3 header inserted by ieee80211_decap */
339 m_adj(m, sizeof(struct ether_header));
341 vap->iv_stats.is_amsdu_decap++;
345 * Decap the first frame, bust it apart from the
346 * remainder and deliver. We leave the last frame
347 * delivery to the caller (for consistency with other
348 * code paths, could also do it here).
350 m = ieee80211_decap1(m, &framelen);
352 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
353 ni->ni_macaddr, "a-msdu", "%s", "decap failed");
354 vap->iv_stats.is_amsdu_tooshort++;
357 if (m->m_pkthdr.len == framelen)
359 n = m_split(m, framelen, M_NOWAIT);
361 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
362 ni->ni_macaddr, "a-msdu",
363 "%s", "unable to split encapsulated frames");
364 vap->iv_stats.is_amsdu_split++;
365 m_freem(m); /* NB: must reclaim */
368 vap->iv_deliver_data(vap, ni, m);
371 * Remove frame contents; each intermediate frame
372 * is required to be aligned to a 4-byte boundary.
375 m_adj(m, roundup2(framelen, 4) - framelen); /* padding */
377 return m; /* last delivered by caller */
381 * Purge all frames in the A-MPDU re-order queue.
384 ampdu_rx_purge(struct ieee80211_rx_ampdu *rap)
389 for (i = 0; i < rap->rxa_wnd; i++) {
392 rap->rxa_m[i] = NULL;
393 rap->rxa_qbytes -= m->m_pkthdr.len;
395 if (--rap->rxa_qframes == 0)
399 KASSERT(rap->rxa_qbytes == 0 && rap->rxa_qframes == 0,
400 ("lost %u data, %u frames on ampdu rx q",
401 rap->rxa_qbytes, rap->rxa_qframes));
405 * Start A-MPDU rx/re-order processing for the specified TID.
408 ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap,
409 int baparamset, int batimeout, int baseqctl)
411 int bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
413 if (rap->rxa_flags & IEEE80211_AGGR_RUNNING) {
415 * AMPDU previously setup and not terminated with a DELBA,
416 * flush the reorder q's in case anything remains.
420 memset(rap, 0, sizeof(*rap));
421 rap->rxa_wnd = (bufsiz == 0) ?
422 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
423 rap->rxa_start = MS(baseqctl, IEEE80211_BASEQ_START);
424 rap->rxa_flags |= IEEE80211_AGGR_RUNNING | IEEE80211_AGGR_XCHGPEND;
430 * Stop A-MPDU rx processing for the specified TID.
433 ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
437 rap->rxa_flags &= ~(IEEE80211_AGGR_RUNNING | IEEE80211_AGGR_XCHGPEND);
441 * Dispatch a frame from the A-MPDU reorder queue. The
442 * frame is fed back into ieee80211_input marked with an
443 * M_AMPDU_MPDU flag so it doesn't come back to us (it also
444 * permits ieee80211_input to optimize re-processing).
447 ampdu_dispatch(struct ieee80211_node *ni, struct mbuf *m)
449 m->m_flags |= M_AMPDU_MPDU; /* bypass normal processing */
450 /* NB: rssi and noise are ignored w/ M_AMPDU_MPDU set */
451 (void) ieee80211_input(ni, m, 0, 0);
455 * Dispatch as many frames as possible from the re-order queue.
456 * Frames will always be "at the front"; we process all frames
457 * up to the first empty slot in the window. On completion we
458 * cleanup state if there are still pending frames in the current
459 * BA window. We assume the frame at slot 0 is already handled
460 * by the caller; we always start at slot 1.
463 ampdu_rx_dispatch(struct ieee80211_rx_ampdu *rap, struct ieee80211_node *ni)
465 struct ieee80211vap *vap = ni->ni_vap;
469 /* flush run of frames */
470 for (i = 1; i < rap->rxa_wnd; i++) {
474 rap->rxa_m[i] = NULL;
475 rap->rxa_qbytes -= m->m_pkthdr.len;
478 ampdu_dispatch(ni, m);
481 * If frames remain, copy the mbuf pointers down so
482 * they correspond to the offsets in the new window.
484 if (rap->rxa_qframes != 0) {
485 int n = rap->rxa_qframes, j;
486 for (j = i+1; j < rap->rxa_wnd; j++) {
487 if (rap->rxa_m[j] != NULL) {
488 rap->rxa_m[j-i] = rap->rxa_m[j];
489 rap->rxa_m[j] = NULL;
494 KASSERT(n == 0, ("lost %d frames", n));
495 vap->iv_stats.is_ampdu_rx_copy += rap->rxa_qframes;
498 * Adjust the start of the BA window to
499 * reflect the frames just dispatched.
501 rap->rxa_start = IEEE80211_SEQ_ADD(rap->rxa_start, i);
502 vap->iv_stats.is_ampdu_rx_oor += i;
505 #ifdef IEEE80211_AMPDU_AGE
507 * Dispatch all frames in the A-MPDU re-order queue.
510 ampdu_rx_flush(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
512 struct ieee80211vap *vap = ni->ni_vap;
516 for (i = 0; i < rap->rxa_wnd; i++) {
520 rap->rxa_m[i] = NULL;
521 rap->rxa_qbytes -= m->m_pkthdr.len;
523 vap->iv_stats.is_ampdu_rx_oor++;
525 ampdu_dispatch(ni, m);
526 if (rap->rxa_qframes == 0)
530 #endif /* IEEE80211_AMPDU_AGE */
533 * Dispatch all frames in the A-MPDU re-order queue
534 * preceding the specified sequence number. This logic
535 * handles window moves due to a received MSDU or BAR.
538 ampdu_rx_flush_upto(struct ieee80211_node *ni,
539 struct ieee80211_rx_ampdu *rap, ieee80211_seq winstart)
541 struct ieee80211vap *vap = ni->ni_vap;
547 * Flush any complete MSDU's with a sequence number lower
548 * than winstart. Gaps may exist. Note that we may actually
549 * dispatch frames past winstart if a run continues; this is
550 * an optimization that avoids having to do a separate pass
551 * to dispatch frames after moving the BA window start.
553 seqno = rap->rxa_start;
554 for (i = 0; i < rap->rxa_wnd; i++) {
557 rap->rxa_m[i] = NULL;
558 rap->rxa_qbytes -= m->m_pkthdr.len;
560 vap->iv_stats.is_ampdu_rx_oor++;
562 ampdu_dispatch(ni, m);
564 if (!IEEE80211_SEQ_BA_BEFORE(seqno, winstart))
567 seqno = IEEE80211_SEQ_INC(seqno);
570 * If frames remain, copy the mbuf pointers down so
571 * they correspond to the offsets in the new window.
573 if (rap->rxa_qframes != 0) {
574 int n = rap->rxa_qframes, j;
576 /* NB: this loop assumes i > 0 and/or rxa_m[0] is NULL */
577 KASSERT(rap->rxa_m[0] == NULL,
578 ("%s: BA window slot 0 occupied", __func__));
579 for (j = i+1; j < rap->rxa_wnd; j++) {
580 if (rap->rxa_m[j] != NULL) {
581 rap->rxa_m[j-i] = rap->rxa_m[j];
582 rap->rxa_m[j] = NULL;
587 KASSERT(n == 0, ("%s: lost %d frames, qframes %d off %d "
588 "BA win <%d:%d> winstart %d",
589 __func__, n, rap->rxa_qframes, i, rap->rxa_start,
590 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
592 vap->iv_stats.is_ampdu_rx_copy += rap->rxa_qframes;
595 * Move the start of the BA window; we use the
596 * sequence number of the last MSDU that was
597 * passed up the stack+1 or winstart if stopped on
598 * a gap in the reorder buffer.
600 rap->rxa_start = seqno;
604 * Process a received QoS data frame for an HT station. Handle
605 * A-MPDU reordering: if this frame is received out of order
606 * and falls within the BA window hold onto it. Otherwise if
607 * this frame completes a run, flush any pending frames. We
608 * return 1 if the frame is consumed. A 0 is returned if
609 * the frame should be processed normally by the caller.
612 ieee80211_ampdu_reorder(struct ieee80211_node *ni, struct mbuf *m)
614 #define IEEE80211_FC0_QOSDATA \
615 (IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_VERSION_0)
616 #define PROCESS 0 /* caller should process frame */
617 #define CONSUMED 1 /* frame consumed, caller does nothing */
618 struct ieee80211vap *vap = ni->ni_vap;
619 struct ieee80211_qosframe *wh;
620 struct ieee80211_rx_ampdu *rap;
625 KASSERT((m->m_flags & (M_AMPDU | M_AMPDU_MPDU)) == M_AMPDU,
626 ("!a-mpdu or already re-ordered, flags 0x%x", m->m_flags));
627 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
629 /* NB: m_len known to be sufficient */
630 wh = mtod(m, struct ieee80211_qosframe *);
631 if (wh->i_fc[0] != IEEE80211_FC0_QOSDATA) {
633 * Not QoS data, shouldn't get here but just
634 * return it to the caller for processing.
638 if (IEEE80211_IS_DSTODS(wh))
639 tid = ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0];
642 tid &= IEEE80211_QOS_TID;
643 rap = &ni->ni_rx_ampdu[tid];
644 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
646 * No ADDBA request yet, don't touch.
650 rxseq = le16toh(*(uint16_t *)wh->i_seq);
651 if ((rxseq & IEEE80211_SEQ_FRAG_MASK) != 0) {
653 * Fragments are not allowed; toss.
655 IEEE80211_DISCARD_MAC(vap,
656 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
657 "A-MPDU", "fragment, rxseq 0x%x tid %u%s", rxseq, tid,
658 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
659 vap->iv_stats.is_ampdu_rx_drop++;
660 IEEE80211_NODE_STAT(ni, rx_drop);
664 rxseq >>= IEEE80211_SEQ_SEQ_SHIFT;
667 if (rxseq == rap->rxa_start) {
669 * First frame in window.
671 if (rap->rxa_qframes != 0) {
673 * Dispatch as many packets as we can.
675 KASSERT(rap->rxa_m[0] == NULL, ("unexpected dup"));
676 ampdu_dispatch(ni, m);
677 ampdu_rx_dispatch(rap, ni);
681 * In order; advance window and notify
682 * caller to dispatch directly.
684 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
689 * Frame is out of order; store if in the BA window.
691 /* calculate offset in BA window */
692 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
693 if (off < rap->rxa_wnd) {
695 * Common case (hopefully): in the BA window.
696 * Sec 9.10.7.6.2 a) (p.137)
698 #ifdef IEEE80211_AMPDU_AGE
700 * Check for frames sitting too long in the reorder queue.
701 * This should only ever happen if frames are not delivered
702 * without the sender otherwise notifying us (e.g. with a
703 * BAR to move the window). Typically this happens because
704 * of vendor bugs that cause the sequence number to jump.
705 * When this happens we get a gap in the reorder queue that
706 * leaves frame sitting on the queue until they get pushed
707 * out due to window moves. When the vendor does not send
708 * BAR this move only happens due to explicit packet sends
710 * NB: we only track the time of the oldest frame in the
711 * reorder q; this means that if we flush we might push
712 * frames that still "new"; if this happens then subsequent
713 * frames will result in BA window moves which cost something
714 * but is still better than a big throughput dip.
716 if (rap->rxa_qframes != 0) {
717 /* XXX honor batimeout? */
718 if (ticks - rap->rxa_age > ieee80211_ampdu_age) {
720 * Too long since we received the first
721 * frame; flush the reorder buffer.
723 if (rap->rxa_qframes != 0) {
724 vap->iv_stats.is_ampdu_rx_age +=
726 ampdu_rx_flush(ni, rap);
728 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
733 * First frame, start aging timer.
735 rap->rxa_age = ticks;
737 #endif /* IEEE80211_AMPDU_AGE */
739 if (rap->rxa_m[off] == NULL) {
742 rap->rxa_qbytes += m->m_pkthdr.len;
743 vap->iv_stats.is_ampdu_rx_reorder++;
745 IEEE80211_DISCARD_MAC(vap,
746 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
747 ni->ni_macaddr, "a-mpdu duplicate",
748 "seqno %u tid %u BA win <%u:%u>",
749 rxseq, tid, rap->rxa_start,
750 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1));
751 vap->iv_stats.is_rx_dup++;
752 IEEE80211_NODE_STAT(ni, rx_dup);
757 if (off < IEEE80211_SEQ_BA_RANGE) {
759 * Outside the BA window, but within range;
760 * flush the reorder q and move the window.
761 * Sec 9.10.7.6.2 b) (p.138)
763 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
764 "move BA win <%u:%u> (%u frames) rxseq %u tid %u",
766 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
767 rap->rxa_qframes, rxseq, tid);
768 vap->iv_stats.is_ampdu_rx_move++;
771 * The spec says to flush frames up to but not including:
772 * WinStart_B = rxseq - rap->rxa_wnd + 1
773 * Then insert the frame or notify the caller to process
774 * it immediately. We can safely do this by just starting
775 * over again because we know the frame will now be within
778 /* NB: rxa_wnd known to be >0 */
779 ampdu_rx_flush_upto(ni, rap,
780 IEEE80211_SEQ_SUB(rxseq, rap->rxa_wnd-1));
784 * Outside the BA window and out of range; toss.
785 * Sec 9.10.7.6.2 c) (p.138)
787 IEEE80211_DISCARD_MAC(vap,
788 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
789 "MPDU", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
791 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
792 rap->rxa_qframes, rxseq, tid,
793 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
794 vap->iv_stats.is_ampdu_rx_drop++;
795 IEEE80211_NODE_STAT(ni, rx_drop);
801 #undef IEEE80211_FC0_QOSDATA
805 * Process a BAR ctl frame. Dispatch all frames up to
806 * the sequence number of the frame. If this frame is
807 * out of range it's discarded.
810 ieee80211_recv_bar(struct ieee80211_node *ni, struct mbuf *m0)
812 struct ieee80211vap *vap = ni->ni_vap;
813 struct ieee80211_frame_bar *wh;
814 struct ieee80211_rx_ampdu *rap;
818 if (!ieee80211_recv_bar_ena) {
820 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_11N,
821 ni->ni_macaddr, "BAR", "%s", "processing disabled");
823 vap->iv_stats.is_ampdu_bar_bad++;
826 wh = mtod(m0, struct ieee80211_frame_bar *);
827 /* XXX check basic BAR */
828 tid = MS(le16toh(wh->i_ctl), IEEE80211_BAR_TID);
829 rap = &ni->ni_rx_ampdu[tid];
830 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
832 * No ADDBA request yet, don't touch.
834 IEEE80211_DISCARD_MAC(vap,
835 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
836 ni->ni_macaddr, "BAR", "no BA stream, tid %u", tid);
837 vap->iv_stats.is_ampdu_bar_bad++;
840 vap->iv_stats.is_ampdu_bar_rx++;
841 rxseq = le16toh(wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;
842 if (rxseq == rap->rxa_start)
844 /* calculate offset in BA window */
845 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
846 if (off < IEEE80211_SEQ_BA_RANGE) {
848 * Flush the reorder q up to rxseq and move the window.
849 * Sec 9.10.7.6.3 a) (p.138)
851 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
852 "BAR moves BA win <%u:%u> (%u frames) rxseq %u tid %u",
854 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
855 rap->rxa_qframes, rxseq, tid);
856 vap->iv_stats.is_ampdu_bar_move++;
858 ampdu_rx_flush_upto(ni, rap, rxseq);
859 if (off >= rap->rxa_wnd) {
861 * BAR specifies a window start to the right of BA
862 * window; we must move it explicitly since
863 * ampdu_rx_flush_upto will not.
865 rap->rxa_start = rxseq;
869 * Out of range; toss.
870 * Sec 9.10.7.6.3 b) (p.138)
872 IEEE80211_DISCARD_MAC(vap,
873 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
874 "BAR", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
876 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
877 rap->rxa_qframes, rxseq, tid,
878 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
879 vap->iv_stats.is_ampdu_bar_oow++;
880 IEEE80211_NODE_STAT(ni, rx_drop);
885 * Setup HT-specific state in a node. Called only
886 * when HT use is negotiated so we don't do extra
887 * work for temporary and/or legacy sta's.
890 ieee80211_ht_node_init(struct ieee80211_node *ni)
892 struct ieee80211_tx_ampdu *tap;
895 if (ni->ni_flags & IEEE80211_NODE_HT) {
897 * Clean AMPDU state on re-associate. This handles the case
898 * where a station leaves w/o notifying us and then returns
899 * before node is reaped for inactivity.
901 ieee80211_ht_node_cleanup(ni);
903 for (ac = 0; ac < WME_NUM_AC; ac++) {
904 tap = &ni->ni_tx_ampdu[ac];
907 /* NB: further initialization deferred */
909 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
913 * Cleanup HT-specific state in a node. Called only
914 * when HT use has been marked.
917 ieee80211_ht_node_cleanup(struct ieee80211_node *ni)
919 struct ieee80211com *ic = ni->ni_ic;
922 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT node"));
924 /* XXX optimize this */
925 for (i = 0; i < WME_NUM_AC; i++) {
926 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[i];
927 if (tap->txa_flags & IEEE80211_AGGR_SETUP)
930 for (i = 0; i < WME_NUM_TID; i++)
931 ic->ic_ampdu_rx_stop(ni, &ni->ni_rx_ampdu[i]);
934 ni->ni_flags &= ~IEEE80211_NODE_HT_ALL;
938 * Age out HT resources for a station.
941 ieee80211_ht_node_age(struct ieee80211_node *ni)
943 #ifdef IEEE80211_AMPDU_AGE
944 struct ieee80211vap *vap = ni->ni_vap;
948 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
950 #ifdef IEEE80211_AMPDU_AGE
951 for (tid = 0; tid < WME_NUM_TID; tid++) {
952 struct ieee80211_rx_ampdu *rap;
954 rap = &ni->ni_rx_ampdu[tid];
955 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0)
957 if (rap->rxa_qframes == 0)
960 * Check for frames sitting too long in the reorder queue.
961 * See above for more details on what's happening here.
963 /* XXX honor batimeout? */
964 if (ticks - rap->rxa_age > ieee80211_ampdu_age) {
966 * Too long since we received the first
967 * frame; flush the reorder buffer.
969 vap->iv_stats.is_ampdu_rx_age += rap->rxa_qframes;
970 ampdu_rx_flush(ni, rap);
973 #endif /* IEEE80211_AMPDU_AGE */
976 static struct ieee80211_channel *
977 findhtchan(struct ieee80211com *ic, struct ieee80211_channel *c, int htflags)
979 return ieee80211_find_channel(ic, c->ic_freq,
980 (c->ic_flags &~ IEEE80211_CHAN_HT) | htflags);
984 * Adjust a channel to be HT/non-HT according to the vap's configuration.
986 struct ieee80211_channel *
987 ieee80211_ht_adjust_channel(struct ieee80211com *ic,
988 struct ieee80211_channel *chan, int flags)
990 struct ieee80211_channel *c;
992 if (flags & IEEE80211_FHT_HT) {
993 /* promote to HT if possible */
994 if (flags & IEEE80211_FHT_USEHT40) {
995 if (!IEEE80211_IS_CHAN_HT40(chan)) {
996 /* NB: arbitrarily pick ht40+ over ht40- */
997 c = findhtchan(ic, chan, IEEE80211_CHAN_HT40U);
999 c = findhtchan(ic, chan,
1000 IEEE80211_CHAN_HT40D);
1002 c = findhtchan(ic, chan,
1003 IEEE80211_CHAN_HT20);
1007 } else if (!IEEE80211_IS_CHAN_HT20(chan)) {
1008 c = findhtchan(ic, chan, IEEE80211_CHAN_HT20);
1012 } else if (IEEE80211_IS_CHAN_HT(chan)) {
1013 /* demote to legacy, HT use is disabled */
1014 c = ieee80211_find_channel(ic, chan->ic_freq,
1015 chan->ic_flags &~ IEEE80211_CHAN_HT);
1023 * Setup HT-specific state for a legacy WDS peer.
1026 ieee80211_ht_wds_init(struct ieee80211_node *ni)
1028 struct ieee80211vap *vap = ni->ni_vap;
1029 struct ieee80211_tx_ampdu *tap;
1032 KASSERT(vap->iv_flags_ht & IEEE80211_FHT_HT, ("no HT requested"));
1034 /* XXX check scan cache in case peer has an ap and we have info */
1036 * If setup with a legacy channel; locate an HT channel.
1037 * Otherwise if the inherited channel (from a companion
1038 * AP) is suitable use it so we use the same location
1039 * for the extension channel).
1041 ni->ni_chan = ieee80211_ht_adjust_channel(ni->ni_ic,
1042 ni->ni_chan, ieee80211_htchanflags(ni->ni_chan));
1045 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20)
1046 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI20;
1047 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {
1048 ni->ni_htcap |= IEEE80211_HTCAP_CHWIDTH40;
1050 if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
1051 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_ABOVE;
1052 else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
1053 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_BELOW;
1054 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40)
1055 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI40;
1058 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_NONE;
1060 ni->ni_htctlchan = ni->ni_chan->ic_ieee;
1061 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
1062 ni->ni_flags |= IEEE80211_NODE_RIFS;
1063 /* XXX does it make sense to enable SMPS? */
1065 ni->ni_htopmode = 0; /* XXX need protection state */
1066 ni->ni_htstbc = 0; /* XXX need info */
1068 for (ac = 0; ac < WME_NUM_AC; ac++) {
1069 tap = &ni->ni_tx_ampdu[ac];
1072 /* NB: AMPDU tx/rx governed by IEEE80211_FHT_AMPDU_{TX,RX} */
1073 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
1077 * Notify hostap vaps of a change in the HTINFO ie.
1080 htinfo_notify(struct ieee80211com *ic)
1082 struct ieee80211vap *vap;
1085 IEEE80211_LOCK_ASSERT(ic);
1087 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1088 if (vap->iv_opmode != IEEE80211_M_HOSTAP)
1090 if (vap->iv_state != IEEE80211_S_RUN ||
1091 !IEEE80211_IS_CHAN_HT(vap->iv_bss->ni_chan))
1095 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N,
1097 "HT bss occupancy change: %d sta, %d ht, "
1098 "%d ht40%s, HT protmode now 0x%x"
1100 , ic->ic_ht_sta_assoc
1101 , ic->ic_ht40_sta_assoc
1102 , (ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) ?
1103 ", non-HT sta present" : ""
1104 , ic->ic_curhtprotmode);
1107 ieee80211_beacon_notify(vap, IEEE80211_BEACON_HTINFO);
1112 * Calculate HT protection mode from current
1113 * state and handle updates.
1116 htinfo_update(struct ieee80211com *ic)
1120 if (ic->ic_sta_assoc != ic->ic_ht_sta_assoc) {
1121 protmode = IEEE80211_HTINFO_OPMODE_MIXED
1122 | IEEE80211_HTINFO_NONHT_PRESENT;
1123 } else if (ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) {
1124 protmode = IEEE80211_HTINFO_OPMODE_PROTOPT
1125 | IEEE80211_HTINFO_NONHT_PRESENT;
1126 } else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1127 IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) &&
1128 ic->ic_sta_assoc != ic->ic_ht40_sta_assoc) {
1129 protmode = IEEE80211_HTINFO_OPMODE_HT20PR;
1131 protmode = IEEE80211_HTINFO_OPMODE_PURE;
1133 if (protmode != ic->ic_curhtprotmode) {
1134 ic->ic_curhtprotmode = protmode;
1140 * Handle an HT station joining a BSS.
1143 ieee80211_ht_node_join(struct ieee80211_node *ni)
1145 struct ieee80211com *ic = ni->ni_ic;
1147 IEEE80211_LOCK_ASSERT(ic);
1149 if (ni->ni_flags & IEEE80211_NODE_HT) {
1150 ic->ic_ht_sta_assoc++;
1151 if (ni->ni_chw == 40)
1152 ic->ic_ht40_sta_assoc++;
1158 * Handle an HT station leaving a BSS.
1161 ieee80211_ht_node_leave(struct ieee80211_node *ni)
1163 struct ieee80211com *ic = ni->ni_ic;
1165 IEEE80211_LOCK_ASSERT(ic);
1167 if (ni->ni_flags & IEEE80211_NODE_HT) {
1168 ic->ic_ht_sta_assoc--;
1169 if (ni->ni_chw == 40)
1170 ic->ic_ht40_sta_assoc--;
1176 * Public version of htinfo_update; used for processing
1177 * beacon frames from overlapping bss.
1179 * Caller can specify either IEEE80211_HTINFO_OPMODE_MIXED
1180 * (on receipt of a beacon that advertises MIXED) or
1181 * IEEE80211_HTINFO_OPMODE_PROTOPT (on receipt of a beacon
1182 * from an overlapping legacy bss). We treat MIXED with
1183 * a higher precedence than PROTOPT (i.e. we will not change
1184 * change PROTOPT -> MIXED; only MIXED -> PROTOPT). This
1185 * corresponds to how we handle things in htinfo_update.
1188 ieee80211_htprot_update(struct ieee80211com *ic, int protmode)
1190 #define OPMODE(x) SM(x, IEEE80211_HTINFO_OPMODE)
1193 /* track non-HT station presence */
1194 KASSERT(protmode & IEEE80211_HTINFO_NONHT_PRESENT,
1195 ("protmode 0x%x", protmode));
1196 ic->ic_flags_ht |= IEEE80211_FHT_NONHT_PR;
1197 ic->ic_lastnonht = ticks;
1199 if (protmode != ic->ic_curhtprotmode &&
1200 (OPMODE(ic->ic_curhtprotmode) != IEEE80211_HTINFO_OPMODE_MIXED ||
1201 OPMODE(protmode) == IEEE80211_HTINFO_OPMODE_PROTOPT)) {
1202 /* push beacon update */
1203 ic->ic_curhtprotmode = protmode;
1206 IEEE80211_UNLOCK(ic);
1211 * Time out presence of an overlapping bss with non-HT
1212 * stations. When operating in hostap mode we listen for
1213 * beacons from other stations and if we identify a non-HT
1214 * station is present we update the opmode field of the
1215 * HTINFO ie. To identify when all non-HT stations are
1216 * gone we time out this condition.
1219 ieee80211_ht_timeout(struct ieee80211com *ic)
1221 IEEE80211_LOCK_ASSERT(ic);
1223 if ((ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) &&
1224 time_after(ticks, ic->ic_lastnonht + IEEE80211_NONHT_PRESENT_AGE)) {
1226 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
1227 "%s", "time out non-HT STA present on channel");
1229 ic->ic_flags_ht &= ~IEEE80211_FHT_NONHT_PR;
1234 /* unalligned little endian access */
1235 #define LE_READ_2(p) \
1237 ((((const uint8_t *)(p))[0] ) | \
1238 (((const uint8_t *)(p))[1] << 8)))
1241 * Process an 802.11n HT capabilities ie.
1244 ieee80211_parse_htcap(struct ieee80211_node *ni, const uint8_t *ie)
1246 if (ie[0] == IEEE80211_ELEMID_VENDOR) {
1248 * Station used Vendor OUI ie to associate;
1249 * mark the node so when we respond we'll use
1250 * the Vendor OUI's and not the standard ie's.
1252 ni->ni_flags |= IEEE80211_NODE_HTCOMPAT;
1255 ni->ni_flags &= ~IEEE80211_NODE_HTCOMPAT;
1257 ni->ni_htcap = LE_READ_2(ie +
1258 __offsetof(struct ieee80211_ie_htcap, hc_cap));
1259 ni->ni_htparam = ie[__offsetof(struct ieee80211_ie_htcap, hc_param)];
1263 htinfo_parse(struct ieee80211_node *ni,
1264 const struct ieee80211_ie_htinfo *htinfo)
1268 ni->ni_htctlchan = htinfo->hi_ctrlchannel;
1269 ni->ni_ht2ndchan = SM(htinfo->hi_byte1, IEEE80211_HTINFO_2NDCHAN);
1270 w = LE_READ_2(&htinfo->hi_byte2);
1271 ni->ni_htopmode = SM(w, IEEE80211_HTINFO_OPMODE);
1272 w = LE_READ_2(&htinfo->hi_byte45);
1273 ni->ni_htstbc = SM(w, IEEE80211_HTINFO_BASIC_STBCMCS);
1277 * Parse an 802.11n HT info ie and save useful information
1278 * to the node state. Note this does not effect any state
1279 * changes such as for channel width change.
1282 ieee80211_parse_htinfo(struct ieee80211_node *ni, const uint8_t *ie)
1284 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1286 htinfo_parse(ni, (const struct ieee80211_ie_htinfo *) ie);
1290 * Handle 11n channel switch. Use the received HT ie's to
1291 * identify the right channel to use. If we cannot locate it
1292 * in the channel table then fallback to legacy operation.
1293 * Note that we use this information to identify the node's
1294 * channel only; the caller is responsible for insuring any
1295 * required channel change is done (e.g. in sta mode when
1296 * parsing the contents of a beacon frame).
1299 htinfo_update_chw(struct ieee80211_node *ni, int htflags)
1301 struct ieee80211com *ic = ni->ni_ic;
1302 struct ieee80211_channel *c;
1305 chanflags = (ni->ni_chan->ic_flags &~ IEEE80211_CHAN_HT) | htflags;
1306 if (chanflags != ni->ni_chan->ic_flags) {
1307 /* XXX not right for ht40- */
1308 c = ieee80211_find_channel(ic, ni->ni_chan->ic_freq, chanflags);
1309 if (c == NULL && (htflags & IEEE80211_CHAN_HT40)) {
1311 * No HT40 channel entry in our table; fall back
1312 * to HT20 operation. This should not happen.
1314 c = findhtchan(ic, ni->ni_chan, IEEE80211_CHAN_HT20);
1316 IEEE80211_NOTE(ni->ni_vap,
1317 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1318 "no HT40 channel (freq %u), falling back to HT20",
1319 ni->ni_chan->ic_freq);
1323 if (c != NULL && c != ni->ni_chan) {
1324 IEEE80211_NOTE(ni->ni_vap,
1325 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1326 "switch station to HT%d channel %u/0x%x",
1327 IEEE80211_IS_CHAN_HT40(c) ? 40 : 20,
1328 c->ic_freq, c->ic_flags);
1331 /* NB: caller responsible for forcing any channel change */
1333 /* update node's tx channel width */
1334 ni->ni_chw = IEEE80211_IS_CHAN_HT40(ni->ni_chan)? 40 : 20;
1338 * Update 11n MIMO PS state according to received htcap.
1341 htcap_update_mimo_ps(struct ieee80211_node *ni)
1343 uint16_t oflags = ni->ni_flags;
1345 switch (ni->ni_htcap & IEEE80211_HTCAP_SMPS) {
1346 case IEEE80211_HTCAP_SMPS_DYNAMIC:
1347 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1348 ni->ni_flags |= IEEE80211_NODE_MIMO_RTS;
1350 case IEEE80211_HTCAP_SMPS_ENA:
1351 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1352 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1354 case IEEE80211_HTCAP_SMPS_OFF:
1355 default: /* disable on rx of reserved value */
1356 ni->ni_flags &= ~IEEE80211_NODE_MIMO_PS;
1357 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1360 return (oflags ^ ni->ni_flags);
1364 * Update short GI state according to received htcap
1365 * and local settings.
1367 static __inline void
1368 htcap_update_shortgi(struct ieee80211_node *ni)
1370 struct ieee80211vap *vap = ni->ni_vap;
1372 ni->ni_flags &= ~(IEEE80211_NODE_SGI20|IEEE80211_NODE_SGI40);
1373 if ((ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20) &&
1374 (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20))
1375 ni->ni_flags |= IEEE80211_NODE_SGI20;
1376 if ((ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40) &&
1377 (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40))
1378 ni->ni_flags |= IEEE80211_NODE_SGI40;
1382 * Parse and update HT-related state extracted from
1383 * the HT cap and info ie's.
1386 ieee80211_ht_updateparams(struct ieee80211_node *ni,
1387 const uint8_t *htcapie, const uint8_t *htinfoie)
1389 struct ieee80211vap *vap = ni->ni_vap;
1390 const struct ieee80211_ie_htinfo *htinfo;
1393 ieee80211_parse_htcap(ni, htcapie);
1394 if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS)
1395 htcap_update_mimo_ps(ni);
1396 htcap_update_shortgi(ni);
1398 if (htinfoie[0] == IEEE80211_ELEMID_VENDOR)
1400 htinfo = (const struct ieee80211_ie_htinfo *) htinfoie;
1401 htinfo_parse(ni, htinfo);
1403 htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ?
1404 IEEE80211_CHAN_HT20 : 0;
1405 /* NB: honor operating mode constraint */
1406 if ((htinfo->hi_byte1 & IEEE80211_HTINFO_TXWIDTH_2040) &&
1407 (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)) {
1408 if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_ABOVE)
1409 htflags = IEEE80211_CHAN_HT40U;
1410 else if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_BELOW)
1411 htflags = IEEE80211_CHAN_HT40D;
1413 htinfo_update_chw(ni, htflags);
1415 if ((htinfo->hi_byte1 & IEEE80211_HTINFO_RIFSMODE_PERM) &&
1416 (vap->iv_flags_ht & IEEE80211_FHT_RIFS))
1417 ni->ni_flags |= IEEE80211_NODE_RIFS;
1419 ni->ni_flags &= ~IEEE80211_NODE_RIFS;
1423 * Parse and update HT-related state extracted from the HT cap ie
1424 * for a station joining an HT BSS.
1427 ieee80211_ht_updatehtcap(struct ieee80211_node *ni, const uint8_t *htcapie)
1429 struct ieee80211vap *vap = ni->ni_vap;
1432 ieee80211_parse_htcap(ni, htcapie);
1433 if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS)
1434 htcap_update_mimo_ps(ni);
1435 htcap_update_shortgi(ni);
1437 /* NB: honor operating mode constraint */
1438 /* XXX 40 MHZ intolerant */
1439 htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ?
1440 IEEE80211_CHAN_HT20 : 0;
1441 if ((ni->ni_htcap & IEEE80211_HTCAP_CHWIDTH40) &&
1442 (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)) {
1443 if (IEEE80211_IS_CHAN_HT40U(vap->iv_bss->ni_chan))
1444 htflags = IEEE80211_CHAN_HT40U;
1445 else if (IEEE80211_IS_CHAN_HT40D(vap->iv_bss->ni_chan))
1446 htflags = IEEE80211_CHAN_HT40D;
1448 htinfo_update_chw(ni, htflags);
1452 * Install received HT rate set by parsing the HT cap ie.
1455 ieee80211_setup_htrates(struct ieee80211_node *ni, const uint8_t *ie, int flags)
1457 struct ieee80211vap *vap = ni->ni_vap;
1458 const struct ieee80211_ie_htcap *htcap;
1459 struct ieee80211_htrateset *rs;
1462 rs = &ni->ni_htrates;
1463 memset(rs, 0, sizeof(*rs));
1465 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1467 htcap = (const struct ieee80211_ie_htcap *) ie;
1468 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) {
1469 if (isclr(htcap->hc_mcsset, i))
1471 if (rs->rs_nrates == IEEE80211_HTRATE_MAXSIZE) {
1473 IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni,
1474 "WARNING, HT rate set too large; only "
1475 "using %u rates", IEEE80211_HTRATE_MAXSIZE);
1476 vap->iv_stats.is_rx_rstoobig++;
1479 rs->rs_rates[rs->rs_nrates++] = i;
1482 return ieee80211_fix_rate(ni, (struct ieee80211_rateset *) rs, flags);
1486 * Mark rates in a node's HT rate set as basic according
1487 * to the information in the supplied HT info ie.
1490 ieee80211_setup_basic_htrates(struct ieee80211_node *ni, const uint8_t *ie)
1492 const struct ieee80211_ie_htinfo *htinfo;
1493 struct ieee80211_htrateset *rs;
1496 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1498 htinfo = (const struct ieee80211_ie_htinfo *) ie;
1499 rs = &ni->ni_htrates;
1500 if (rs->rs_nrates == 0) {
1501 IEEE80211_NOTE(ni->ni_vap,
1502 IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni,
1503 "%s", "WARNING, empty HT rate set");
1506 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) {
1507 if (isclr(htinfo->hi_basicmcsset, i))
1509 for (j = 0; j < rs->rs_nrates; j++)
1510 if ((rs->rs_rates[j] & IEEE80211_RATE_VAL) == i)
1511 rs->rs_rates[j] |= IEEE80211_RATE_BASIC;
1516 ampdu_tx_setup(struct ieee80211_tx_ampdu *tap)
1518 callout_init(&tap->txa_timer, CALLOUT_MPSAFE);
1519 tap->txa_flags |= IEEE80211_AGGR_SETUP;
1523 ampdu_tx_stop(struct ieee80211_tx_ampdu *tap)
1525 struct ieee80211_node *ni = tap->txa_ni;
1526 struct ieee80211com *ic = ni->ni_ic;
1528 KASSERT(tap->txa_flags & IEEE80211_AGGR_SETUP,
1529 ("txa_flags 0x%x ac %d", tap->txa_flags, tap->txa_ac));
1532 * Stop BA stream if setup so driver has a chance
1533 * to reclaim any resources it might have allocated.
1535 ic->ic_addba_stop(ni, tap);
1537 * Stop any pending BAR transmit.
1539 bar_stop_timer(tap);
1541 tap->txa_lastsample = 0;
1542 tap->txa_avgpps = 0;
1543 /* NB: clearing NAK means we may re-send ADDBA */
1544 tap->txa_flags &= ~(IEEE80211_AGGR_SETUP | IEEE80211_AGGR_NAK);
1548 addba_timeout(void *arg)
1550 struct ieee80211_tx_ampdu *tap = arg;
1553 tap->txa_flags &= ~IEEE80211_AGGR_XCHGPEND;
1554 tap->txa_attempts++;
1558 addba_start_timeout(struct ieee80211_tx_ampdu *tap)
1560 /* XXX use CALLOUT_PENDING instead? */
1561 callout_reset(&tap->txa_timer, ieee80211_addba_timeout,
1562 addba_timeout, tap);
1563 tap->txa_flags |= IEEE80211_AGGR_XCHGPEND;
1564 tap->txa_nextrequest = ticks + ieee80211_addba_timeout;
1568 addba_stop_timeout(struct ieee80211_tx_ampdu *tap)
1570 /* XXX use CALLOUT_PENDING instead? */
1571 if (tap->txa_flags & IEEE80211_AGGR_XCHGPEND) {
1572 callout_stop(&tap->txa_timer);
1573 tap->txa_flags &= ~IEEE80211_AGGR_XCHGPEND;
1578 * Default method for requesting A-MPDU tx aggregation.
1579 * We setup the specified state block and start a timer
1580 * to wait for an ADDBA response frame.
1583 ieee80211_addba_request(struct ieee80211_node *ni,
1584 struct ieee80211_tx_ampdu *tap,
1585 int dialogtoken, int baparamset, int batimeout)
1590 tap->txa_token = dialogtoken;
1591 tap->txa_flags |= IEEE80211_AGGR_IMMEDIATE;
1592 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1593 tap->txa_wnd = (bufsiz == 0) ?
1594 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
1595 addba_start_timeout(tap);
1600 * Default method for processing an A-MPDU tx aggregation
1601 * response. We shutdown any pending timer and update the
1602 * state block according to the reply.
1605 ieee80211_addba_response(struct ieee80211_node *ni,
1606 struct ieee80211_tx_ampdu *tap,
1607 int status, int baparamset, int batimeout)
1612 addba_stop_timeout(tap);
1613 if (status == IEEE80211_STATUS_SUCCESS) {
1614 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1615 /* XXX override our request? */
1616 tap->txa_wnd = (bufsiz == 0) ?
1617 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
1619 tid = MS(baparamset, IEEE80211_BAPS_TID);
1620 tap->txa_flags |= IEEE80211_AGGR_RUNNING;
1621 tap->txa_attempts = 0;
1623 /* mark tid so we don't try again */
1624 tap->txa_flags |= IEEE80211_AGGR_NAK;
1630 * Default method for stopping A-MPDU tx aggregation.
1631 * Any timer is cleared and we drain any pending frames.
1634 ieee80211_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
1637 addba_stop_timeout(tap);
1638 if (tap->txa_flags & IEEE80211_AGGR_RUNNING) {
1639 /* XXX clear aggregation queue */
1640 tap->txa_flags &= ~IEEE80211_AGGR_RUNNING;
1642 tap->txa_attempts = 0;
1646 * Process a received action frame using the default aggregation
1647 * policy. We intercept ADDBA-related frames and use them to
1648 * update our aggregation state. All other frames are passed up
1649 * for processing by ieee80211_recv_action.
1652 ht_recv_action_ba_addba_request(struct ieee80211_node *ni,
1653 const struct ieee80211_frame *wh,
1654 const uint8_t *frm, const uint8_t *efrm)
1656 struct ieee80211com *ic = ni->ni_ic;
1657 struct ieee80211vap *vap = ni->ni_vap;
1658 struct ieee80211_rx_ampdu *rap;
1659 uint8_t dialogtoken;
1660 uint16_t baparamset, batimeout, baseqctl;
1664 dialogtoken = frm[2];
1665 baparamset = LE_READ_2(frm+3);
1666 batimeout = LE_READ_2(frm+5);
1667 baseqctl = LE_READ_2(frm+7);
1669 tid = MS(baparamset, IEEE80211_BAPS_TID);
1671 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1672 "recv ADDBA request: dialogtoken %u baparamset 0x%x "
1673 "(tid %d bufsiz %d) batimeout %d baseqctl %d:%d",
1674 dialogtoken, baparamset,
1675 tid, MS(baparamset, IEEE80211_BAPS_BUFSIZ),
1677 MS(baseqctl, IEEE80211_BASEQ_START),
1678 MS(baseqctl, IEEE80211_BASEQ_FRAG));
1680 rap = &ni->ni_rx_ampdu[tid];
1682 /* Send ADDBA response */
1683 args[0] = dialogtoken;
1685 * NB: We ack only if the sta associated with HT and
1686 * the ap is configured to do AMPDU rx (the latter
1687 * violates the 11n spec and is mostly for testing).
1689 if ((ni->ni_flags & IEEE80211_NODE_AMPDU_RX) &&
1690 (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_RX)) {
1691 /* XXX handle ampdu_rx_start failure */
1692 ic->ic_ampdu_rx_start(ni, rap,
1693 baparamset, batimeout, baseqctl);
1695 args[1] = IEEE80211_STATUS_SUCCESS;
1697 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1698 ni, "reject ADDBA request: %s",
1699 ni->ni_flags & IEEE80211_NODE_AMPDU_RX ?
1700 "administratively disabled" :
1701 "not negotiated for station");
1702 vap->iv_stats.is_addba_reject++;
1703 args[1] = IEEE80211_STATUS_UNSPECIFIED;
1705 /* XXX honor rap flags? */
1706 args[2] = IEEE80211_BAPS_POLICY_IMMEDIATE
1707 | SM(tid, IEEE80211_BAPS_TID)
1708 | SM(rap->rxa_wnd, IEEE80211_BAPS_BUFSIZ)
1712 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1713 IEEE80211_ACTION_BA_ADDBA_RESPONSE, args);
1718 ht_recv_action_ba_addba_response(struct ieee80211_node *ni,
1719 const struct ieee80211_frame *wh,
1720 const uint8_t *frm, const uint8_t *efrm)
1722 struct ieee80211com *ic = ni->ni_ic;
1723 struct ieee80211vap *vap = ni->ni_vap;
1724 struct ieee80211_tx_ampdu *tap;
1725 uint8_t dialogtoken, policy;
1726 uint16_t baparamset, batimeout, code;
1727 int tid, ac, bufsiz;
1729 dialogtoken = frm[2];
1730 code = LE_READ_2(frm+3);
1731 baparamset = LE_READ_2(frm+5);
1732 tid = MS(baparamset, IEEE80211_BAPS_TID);
1733 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1734 policy = MS(baparamset, IEEE80211_BAPS_POLICY);
1735 batimeout = LE_READ_2(frm+7);
1737 ac = TID_TO_WME_AC(tid);
1738 tap = &ni->ni_tx_ampdu[ac];
1739 if ((tap->txa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
1740 IEEE80211_DISCARD_MAC(vap,
1741 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1742 ni->ni_macaddr, "ADDBA response",
1743 "no pending ADDBA, tid %d dialogtoken %u "
1744 "code %d", tid, dialogtoken, code);
1745 vap->iv_stats.is_addba_norequest++;
1748 if (dialogtoken != tap->txa_token) {
1749 IEEE80211_DISCARD_MAC(vap,
1750 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1751 ni->ni_macaddr, "ADDBA response",
1752 "dialogtoken mismatch: waiting for %d, "
1753 "received %d, tid %d code %d",
1754 tap->txa_token, dialogtoken, tid, code);
1755 vap->iv_stats.is_addba_badtoken++;
1758 /* NB: assumes IEEE80211_AGGR_IMMEDIATE is 1 */
1759 if (policy != (tap->txa_flags & IEEE80211_AGGR_IMMEDIATE)) {
1760 IEEE80211_DISCARD_MAC(vap,
1761 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1762 ni->ni_macaddr, "ADDBA response",
1763 "policy mismatch: expecting %s, "
1764 "received %s, tid %d code %d",
1765 tap->txa_flags & IEEE80211_AGGR_IMMEDIATE,
1767 vap->iv_stats.is_addba_badpolicy++;
1771 /* XXX we take MIN in ieee80211_addba_response */
1772 if (bufsiz > IEEE80211_AGGR_BAWMAX) {
1773 IEEE80211_DISCARD_MAC(vap,
1774 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1775 ni->ni_macaddr, "ADDBA response",
1776 "BA window too large: max %d, "
1777 "received %d, tid %d code %d",
1778 bufsiz, IEEE80211_AGGR_BAWMAX, tid, code);
1779 vap->iv_stats.is_addba_badbawinsize++;
1783 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1784 "recv ADDBA response: dialogtoken %u code %d "
1785 "baparamset 0x%x (tid %d bufsiz %d) batimeout %d",
1786 dialogtoken, code, baparamset, tid, bufsiz,
1788 ic->ic_addba_response(ni, tap, code, baparamset, batimeout);
1793 ht_recv_action_ba_delba(struct ieee80211_node *ni,
1794 const struct ieee80211_frame *wh,
1795 const uint8_t *frm, const uint8_t *efrm)
1797 struct ieee80211com *ic = ni->ni_ic;
1798 struct ieee80211_rx_ampdu *rap;
1799 struct ieee80211_tx_ampdu *tap;
1800 uint16_t baparamset, code;
1803 baparamset = LE_READ_2(frm+2);
1804 code = LE_READ_2(frm+4);
1806 tid = MS(baparamset, IEEE80211_DELBAPS_TID);
1808 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1809 "recv DELBA: baparamset 0x%x (tid %d initiator %d) "
1810 "code %d", baparamset, tid,
1811 MS(baparamset, IEEE80211_DELBAPS_INIT), code);
1813 if ((baparamset & IEEE80211_DELBAPS_INIT) == 0) {
1814 ac = TID_TO_WME_AC(tid);
1815 tap = &ni->ni_tx_ampdu[ac];
1816 ic->ic_addba_stop(ni, tap);
1818 rap = &ni->ni_rx_ampdu[tid];
1819 ic->ic_ampdu_rx_stop(ni, rap);
1825 ht_recv_action_ht_txchwidth(struct ieee80211_node *ni,
1826 const struct ieee80211_frame *wh,
1827 const uint8_t *frm, const uint8_t *efrm)
1831 chw = (frm[2] == IEEE80211_A_HT_TXCHWIDTH_2040) ? 40 : 20;
1833 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1834 "%s: HT txchwidth, width %d%s",
1835 __func__, chw, ni->ni_chw != chw ? "*" : "");
1836 if (chw != ni->ni_chw) {
1838 /* XXX notify on change */
1844 ht_recv_action_ht_mimopwrsave(struct ieee80211_node *ni,
1845 const struct ieee80211_frame *wh,
1846 const uint8_t *frm, const uint8_t *efrm)
1848 const struct ieee80211_action_ht_mimopowersave *mps =
1849 (const struct ieee80211_action_ht_mimopowersave *) frm;
1851 /* XXX check iv_htcaps */
1852 if (mps->am_control & IEEE80211_A_HT_MIMOPWRSAVE_ENA)
1853 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1855 ni->ni_flags &= ~IEEE80211_NODE_MIMO_PS;
1856 if (mps->am_control & IEEE80211_A_HT_MIMOPWRSAVE_MODE)
1857 ni->ni_flags |= IEEE80211_NODE_MIMO_RTS;
1859 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1860 /* XXX notify on change */
1861 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1862 "%s: HT MIMO PS (%s%s)", __func__,
1863 (ni->ni_flags & IEEE80211_NODE_MIMO_PS) ? "on" : "off",
1864 (ni->ni_flags & IEEE80211_NODE_MIMO_RTS) ? "+rts" : ""
1870 * Transmit processing.
1874 * Check if A-MPDU should be requested/enabled for a stream.
1875 * We require a traffic rate above a per-AC threshold and we
1876 * also handle backoff from previous failed attempts.
1878 * Drivers may override this method to bring in information
1879 * such as link state conditions in making the decision.
1882 ieee80211_ampdu_enable(struct ieee80211_node *ni,
1883 struct ieee80211_tx_ampdu *tap)
1885 struct ieee80211vap *vap = ni->ni_vap;
1887 if (tap->txa_avgpps < vap->iv_ampdu_mintraffic[tap->txa_ac])
1889 /* XXX check rssi? */
1890 if (tap->txa_attempts >= ieee80211_addba_maxtries &&
1891 ticks < tap->txa_nextrequest) {
1893 * Don't retry too often; txa_nextrequest is set
1894 * to the minimum interval we'll retry after
1895 * ieee80211_addba_maxtries failed attempts are made.
1899 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
1900 "enable AMPDU on %s, avgpps %d pkts %d",
1901 ieee80211_wme_acnames[tap->txa_ac], tap->txa_avgpps, tap->txa_pkts);
1906 * Request A-MPDU tx aggregation. Setup local state and
1907 * issue an ADDBA request. BA use will only happen after
1908 * the other end replies with ADDBA response.
1911 ieee80211_ampdu_request(struct ieee80211_node *ni,
1912 struct ieee80211_tx_ampdu *tap)
1914 struct ieee80211com *ic = ni->ni_ic;
1916 int tid, dialogtoken;
1917 static int tokens = 0; /* XXX */
1920 if ((tap->txa_flags & IEEE80211_AGGR_SETUP) == 0) {
1921 /* do deferred setup of state */
1922 ampdu_tx_setup(tap);
1924 /* XXX hack for not doing proper locking */
1925 tap->txa_flags &= ~IEEE80211_AGGR_NAK;
1927 dialogtoken = (tokens+1) % 63; /* XXX */
1928 tid = WME_AC_TO_TID(tap->txa_ac);
1929 tap->txa_start = ni->ni_txseqs[tid];
1931 args[0] = dialogtoken;
1932 args[1] = 0; /* NB: status code not used */
1933 args[2] = IEEE80211_BAPS_POLICY_IMMEDIATE
1934 | SM(tid, IEEE80211_BAPS_TID)
1935 | SM(IEEE80211_AGGR_BAWMAX, IEEE80211_BAPS_BUFSIZ)
1937 args[3] = 0; /* batimeout */
1938 /* NB: do first so there's no race against reply */
1939 if (!ic->ic_addba_request(ni, tap, dialogtoken, args[2], args[3])) {
1940 /* unable to setup state, don't make request */
1941 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
1942 ni, "%s: could not setup BA stream for AC %d",
1943 __func__, tap->txa_ac);
1944 /* defer next try so we don't slam the driver with requests */
1945 tap->txa_attempts = ieee80211_addba_maxtries;
1946 /* NB: check in case driver wants to override */
1947 if (tap->txa_nextrequest <= ticks)
1948 tap->txa_nextrequest = ticks + ieee80211_addba_backoff;
1951 tokens = dialogtoken; /* allocate token */
1952 /* NB: after calling ic_addba_request so driver can set txa_start */
1953 args[4] = SM(tap->txa_start, IEEE80211_BASEQ_START)
1954 | SM(0, IEEE80211_BASEQ_FRAG)
1956 return ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1957 IEEE80211_ACTION_BA_ADDBA_REQUEST, args);
1961 * Terminate an AMPDU tx stream. State is reclaimed
1962 * and the peer notified with a DelBA Action frame.
1965 ieee80211_ampdu_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
1968 struct ieee80211com *ic = ni->ni_ic;
1969 struct ieee80211vap *vap = ni->ni_vap;
1973 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
1974 if (IEEE80211_AMPDU_RUNNING(tap)) {
1975 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1976 ni, "%s: stop BA stream for AC %d (reason %d)",
1977 __func__, tap->txa_ac, reason);
1978 vap->iv_stats.is_ampdu_stop++;
1980 ic->ic_addba_stop(ni, tap);
1981 args[0] = WME_AC_TO_TID(tap->txa_ac);
1982 args[1] = IEEE80211_DELBAPS_INIT;
1983 args[2] = reason; /* XXX reason code */
1984 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1985 IEEE80211_ACTION_BA_DELBA, args);
1987 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1988 ni, "%s: BA stream for AC %d not running (reason %d)",
1989 __func__, tap->txa_ac, reason);
1990 vap->iv_stats.is_ampdu_stop_failed++;
1995 bar_timeout(void *arg)
1997 struct ieee80211_tx_ampdu *tap = arg;
1998 struct ieee80211_node *ni = tap->txa_ni;
2000 KASSERT((tap->txa_flags & IEEE80211_AGGR_XCHGPEND) == 0,
2001 ("bar/addba collision, flags 0x%x", tap->txa_flags));
2003 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2004 ni, "%s: tid %u flags 0x%x attempts %d", __func__,
2005 tap->txa_ac, tap->txa_flags, tap->txa_attempts);
2007 /* guard against race with bar_tx_complete */
2008 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) == 0)
2011 if (tap->txa_attempts >= ieee80211_bar_maxtries)
2012 ieee80211_ampdu_stop(ni, tap, IEEE80211_REASON_TIMEOUT);
2014 ieee80211_send_bar(ni, tap, tap->txa_seqpending);
2018 bar_start_timer(struct ieee80211_tx_ampdu *tap)
2020 callout_reset(&tap->txa_timer, ieee80211_bar_timeout, bar_timeout, tap);
2024 bar_stop_timer(struct ieee80211_tx_ampdu *tap)
2026 callout_stop(&tap->txa_timer);
2030 bar_tx_complete(struct ieee80211_node *ni, void *arg, int status)
2032 struct ieee80211_tx_ampdu *tap = arg;
2034 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2035 ni, "%s: tid %u flags 0x%x pending %d status %d",
2036 __func__, tap->txa_ac, tap->txa_flags,
2037 callout_pending(&tap->txa_timer), status);
2040 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) &&
2041 callout_pending(&tap->txa_timer)) {
2042 struct ieee80211com *ic = ni->ni_ic;
2044 if (status) /* ACK'd */
2045 bar_stop_timer(tap);
2046 ic->ic_bar_response(ni, tap, status);
2047 /* NB: just let timer expire so we pace requests */
2052 ieee80211_bar_response(struct ieee80211_node *ni,
2053 struct ieee80211_tx_ampdu *tap, int status)
2056 if (status != 0) { /* got ACK */
2057 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2058 ni, "BAR moves BA win <%u:%u> (%u frames) txseq %u tid %u",
2060 IEEE80211_SEQ_ADD(tap->txa_start, tap->txa_wnd-1),
2061 tap->txa_qframes, tap->txa_seqpending,
2062 WME_AC_TO_TID(tap->txa_ac));
2064 /* NB: timer already stopped in bar_tx_complete */
2065 tap->txa_start = tap->txa_seqpending;
2066 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
2071 * Transmit a BAR frame to the specified node. The
2072 * BAR contents are drawn from the supplied aggregation
2073 * state associated with the node.
2075 * NB: we only handle immediate ACK w/ compressed bitmap.
2078 ieee80211_send_bar(struct ieee80211_node *ni,
2079 struct ieee80211_tx_ampdu *tap, ieee80211_seq seq)
2081 #define senderr(_x, _v) do { vap->iv_stats._v++; ret = _x; goto bad; } while (0)
2082 struct ieee80211vap *vap = ni->ni_vap;
2083 struct ieee80211com *ic = ni->ni_ic;
2084 struct ieee80211_frame_bar *bar;
2086 uint16_t barctl, barseqctl;
2090 if ((tap->txa_flags & IEEE80211_AGGR_RUNNING) == 0) {
2091 /* no ADDBA response, should not happen */
2096 bar_stop_timer(tap);
2098 ieee80211_ref_node(ni);
2100 m = ieee80211_getmgtframe(&frm, ic->ic_headroom, sizeof(*bar));
2102 senderr(ENOMEM, is_tx_nobuf);
2104 if (!ieee80211_add_callback(m, bar_tx_complete, tap)) {
2106 senderr(ENOMEM, is_tx_nobuf); /* XXX */
2110 bar = mtod(m, struct ieee80211_frame_bar *);
2111 bar->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2112 IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_BAR;
2114 IEEE80211_ADDR_COPY(bar->i_ra, ni->ni_macaddr);
2115 IEEE80211_ADDR_COPY(bar->i_ta, vap->iv_myaddr);
2117 tid = WME_AC_TO_TID(tap->txa_ac);
2118 barctl = (tap->txa_flags & IEEE80211_AGGR_IMMEDIATE ?
2119 0 : IEEE80211_BAR_NOACK)
2120 | IEEE80211_BAR_COMP
2121 | SM(tid, IEEE80211_BAR_TID)
2123 barseqctl = SM(seq, IEEE80211_BAR_SEQ_START);
2124 /* NB: known to have proper alignment */
2125 bar->i_ctl = htole16(barctl);
2126 bar->i_seq = htole16(barseqctl);
2127 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_bar);
2129 M_WME_SETAC(m, WME_AC_VO);
2131 IEEE80211_NODE_STAT(ni, tx_mgmt); /* XXX tx_ctl? */
2134 /* init/bump attempts counter */
2135 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) == 0)
2136 tap->txa_attempts = 1;
2138 tap->txa_attempts++;
2139 tap->txa_seqpending = seq;
2140 tap->txa_flags |= IEEE80211_AGGR_BARPEND;
2142 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_11N,
2143 ni, "send BAR: tid %u ctl 0x%x start %u (attempt %d)",
2144 tid, barctl, seq, tap->txa_attempts);
2146 ret = ic->ic_raw_xmit(ni, m, NULL);
2148 /* xmit failed, clear state flag */
2149 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
2152 /* XXX hack against tx complete happening before timer is started */
2153 if (tap->txa_flags & IEEE80211_AGGR_BARPEND)
2154 bar_start_timer(tap);
2157 ieee80211_free_node(ni);
2163 ht_action_output(struct ieee80211_node *ni, struct mbuf *m)
2165 struct ieee80211_bpf_params params;
2167 memset(¶ms, 0, sizeof(params));
2168 params.ibp_pri = WME_AC_VO;
2169 params.ibp_rate0 = ni->ni_txparms->mgmtrate;
2170 /* NB: we know all frames are unicast */
2171 params.ibp_try0 = ni->ni_txparms->maxretry;
2172 params.ibp_power = ni->ni_txpower;
2173 return ieee80211_mgmt_output(ni, m, IEEE80211_FC0_SUBTYPE_ACTION,
2177 #define ADDSHORT(frm, v) do { \
2178 frm[0] = (v) & 0xff; \
2179 frm[1] = (v) >> 8; \
2184 * Send an action management frame. The arguments are stuff
2185 * into a frame without inspection; the caller is assumed to
2186 * prepare them carefully (e.g. based on the aggregation state).
2189 ht_send_action_ba_addba(struct ieee80211_node *ni,
2190 int category, int action, void *arg0)
2192 struct ieee80211vap *vap = ni->ni_vap;
2193 struct ieee80211com *ic = ni->ni_ic;
2194 uint16_t *args = arg0;
2198 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2199 "send ADDBA %s: dialogtoken %d status %d "
2200 "baparamset 0x%x (tid %d) batimeout 0x%x baseqctl 0x%x",
2201 (action == IEEE80211_ACTION_BA_ADDBA_REQUEST) ?
2202 "request" : "response",
2203 args[0], args[1], args[2], MS(args[2], IEEE80211_BAPS_TID),
2206 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2207 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2208 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2209 ieee80211_ref_node(ni);
2211 m = ieee80211_getmgtframe(&frm,
2212 ic->ic_headroom + sizeof(struct ieee80211_frame),
2213 sizeof(uint16_t) /* action+category */
2214 /* XXX may action payload */
2215 + sizeof(struct ieee80211_action_ba_addbaresponse)
2220 *frm++ = args[0]; /* dialog token */
2221 if (action == IEEE80211_ACTION_BA_ADDBA_RESPONSE)
2222 ADDSHORT(frm, args[1]); /* status code */
2223 ADDSHORT(frm, args[2]); /* baparamset */
2224 ADDSHORT(frm, args[3]); /* batimeout */
2225 if (action == IEEE80211_ACTION_BA_ADDBA_REQUEST)
2226 ADDSHORT(frm, args[4]); /* baseqctl */
2227 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2228 return ht_action_output(ni, m);
2230 vap->iv_stats.is_tx_nobuf++;
2231 ieee80211_free_node(ni);
2237 ht_send_action_ba_delba(struct ieee80211_node *ni,
2238 int category, int action, void *arg0)
2240 struct ieee80211vap *vap = ni->ni_vap;
2241 struct ieee80211com *ic = ni->ni_ic;
2242 uint16_t *args = arg0;
2244 uint16_t baparamset;
2247 baparamset = SM(args[0], IEEE80211_DELBAPS_TID)
2250 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2251 "send DELBA action: tid %d, initiator %d reason %d",
2252 args[0], args[1], args[2]);
2254 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2255 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2256 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2257 ieee80211_ref_node(ni);
2259 m = ieee80211_getmgtframe(&frm,
2260 ic->ic_headroom + sizeof(struct ieee80211_frame),
2261 sizeof(uint16_t) /* action+category */
2262 /* XXX may action payload */
2263 + sizeof(struct ieee80211_action_ba_addbaresponse)
2268 ADDSHORT(frm, baparamset);
2269 ADDSHORT(frm, args[2]); /* reason code */
2270 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2271 return ht_action_output(ni, m);
2273 vap->iv_stats.is_tx_nobuf++;
2274 ieee80211_free_node(ni);
2280 ht_send_action_ht_txchwidth(struct ieee80211_node *ni,
2281 int category, int action, void *arg0)
2283 struct ieee80211vap *vap = ni->ni_vap;
2284 struct ieee80211com *ic = ni->ni_ic;
2288 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2289 "send HT txchwidth: width %d",
2290 IEEE80211_IS_CHAN_HT40(ni->ni_chan) ? 40 : 20);
2292 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2293 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2294 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2295 ieee80211_ref_node(ni);
2297 m = ieee80211_getmgtframe(&frm,
2298 ic->ic_headroom + sizeof(struct ieee80211_frame),
2299 sizeof(uint16_t) /* action+category */
2300 /* XXX may action payload */
2301 + sizeof(struct ieee80211_action_ba_addbaresponse)
2306 *frm++ = IEEE80211_IS_CHAN_HT40(ni->ni_chan) ?
2307 IEEE80211_A_HT_TXCHWIDTH_2040 :
2308 IEEE80211_A_HT_TXCHWIDTH_20;
2309 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2310 return ht_action_output(ni, m);
2312 vap->iv_stats.is_tx_nobuf++;
2313 ieee80211_free_node(ni);
2320 * Construct the MCS bit mask for inclusion
2321 * in an HT information element.
2324 ieee80211_set_htrates(uint8_t *frm, const struct ieee80211_htrateset *rs)
2328 for (i = 0; i < rs->rs_nrates; i++) {
2329 int r = rs->rs_rates[i] & IEEE80211_RATE_VAL;
2330 if (r < IEEE80211_HTRATE_MAXSIZE) { /* XXX? */
2331 /* NB: this assumes a particular implementation */
2338 * Add body of an HTCAP information element.
2341 ieee80211_add_htcap_body(uint8_t *frm, struct ieee80211_node *ni)
2343 #define ADDSHORT(frm, v) do { \
2344 frm[0] = (v) & 0xff; \
2345 frm[1] = (v) >> 8; \
2348 struct ieee80211vap *vap = ni->ni_vap;
2349 uint16_t caps, extcaps;
2352 /* HT capabilities */
2353 caps = vap->iv_htcaps & 0xffff;
2355 * Note channel width depends on whether we are operating as
2356 * a sta or not. When operating as a sta we are generating
2357 * a request based on our desired configuration. Otherwise
2358 * we are operational and the channel attributes identify
2359 * how we've been setup (which might be different if a fixed
2360 * channel is specified).
2362 if (vap->iv_opmode == IEEE80211_M_STA) {
2363 /* override 20/40 use based on config */
2364 if (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)
2365 caps |= IEEE80211_HTCAP_CHWIDTH40;
2367 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
2368 /* use advertised setting (XXX locally constraint) */
2369 rxmax = MS(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU);
2370 density = MS(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY);
2372 /* override 20/40 use based on current channel */
2373 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
2374 caps |= IEEE80211_HTCAP_CHWIDTH40;
2376 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
2377 rxmax = vap->iv_ampdu_rxmax;
2378 density = vap->iv_ampdu_density;
2380 /* adjust short GI based on channel and config */
2381 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20) == 0)
2382 caps &= ~IEEE80211_HTCAP_SHORTGI20;
2383 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40) == 0 ||
2384 (caps & IEEE80211_HTCAP_CHWIDTH40) == 0)
2385 caps &= ~IEEE80211_HTCAP_SHORTGI40;
2386 ADDSHORT(frm, caps);
2389 *frm = SM(rxmax, IEEE80211_HTCAP_MAXRXAMPDU)
2390 | SM(density, IEEE80211_HTCAP_MPDUDENSITY)
2394 /* pre-zero remainder of ie */
2395 memset(frm, 0, sizeof(struct ieee80211_ie_htcap) -
2396 __offsetof(struct ieee80211_ie_htcap, hc_mcsset));
2398 /* supported MCS set */
2400 * XXX it would better to get the rate set from ni_htrates
2401 * so we can restrict it but for sta mode ni_htrates isn't
2402 * setup when we're called to form an AssocReq frame so for
2403 * now we're restricted to the default HT rate set.
2405 ieee80211_set_htrates(frm, &ieee80211_rateset_11n);
2407 frm += __offsetof(struct ieee80211_ie_htcap, hc_extcap) -
2408 __offsetof(struct ieee80211_ie_htcap, hc_mcsset);
2410 /* HT extended capabilities */
2411 extcaps = vap->iv_htextcaps & 0xffff;
2413 ADDSHORT(frm, extcaps);
2415 frm += sizeof(struct ieee80211_ie_htcap) -
2416 __offsetof(struct ieee80211_ie_htcap, hc_txbf);
2423 * Add 802.11n HT capabilities information element
2426 ieee80211_add_htcap(uint8_t *frm, struct ieee80211_node *ni)
2428 frm[0] = IEEE80211_ELEMID_HTCAP;
2429 frm[1] = sizeof(struct ieee80211_ie_htcap) - 2;
2430 return ieee80211_add_htcap_body(frm + 2, ni);
2434 * Add Broadcom OUI wrapped standard HTCAP ie; this is
2435 * used for compatibility w/ pre-draft implementations.
2438 ieee80211_add_htcap_vendor(uint8_t *frm, struct ieee80211_node *ni)
2440 frm[0] = IEEE80211_ELEMID_VENDOR;
2441 frm[1] = 4 + sizeof(struct ieee80211_ie_htcap) - 2;
2442 frm[2] = (BCM_OUI >> 0) & 0xff;
2443 frm[3] = (BCM_OUI >> 8) & 0xff;
2444 frm[4] = (BCM_OUI >> 16) & 0xff;
2445 frm[5] = BCM_OUI_HTCAP;
2446 return ieee80211_add_htcap_body(frm + 6, ni);
2450 * Construct the MCS bit mask of basic rates
2451 * for inclusion in an HT information element.
2454 ieee80211_set_basic_htrates(uint8_t *frm, const struct ieee80211_htrateset *rs)
2458 for (i = 0; i < rs->rs_nrates; i++) {
2459 int r = rs->rs_rates[i] & IEEE80211_RATE_VAL;
2460 if ((rs->rs_rates[i] & IEEE80211_RATE_BASIC) &&
2461 r < IEEE80211_HTRATE_MAXSIZE) {
2462 /* NB: this assumes a particular implementation */
2469 * Update the HTINFO ie for a beacon frame.
2472 ieee80211_ht_update_beacon(struct ieee80211vap *vap,
2473 struct ieee80211_beacon_offsets *bo)
2475 #define PROTMODE (IEEE80211_HTINFO_OPMODE|IEEE80211_HTINFO_NONHT_PRESENT)
2476 const struct ieee80211_channel *bsschan = vap->iv_bss->ni_chan;
2477 struct ieee80211com *ic = vap->iv_ic;
2478 struct ieee80211_ie_htinfo *ht =
2479 (struct ieee80211_ie_htinfo *) bo->bo_htinfo;
2481 /* XXX only update on channel change */
2482 ht->hi_ctrlchannel = ieee80211_chan2ieee(ic, bsschan);
2483 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
2484 ht->hi_byte1 = IEEE80211_HTINFO_RIFSMODE_PERM;
2486 ht->hi_byte1 = IEEE80211_HTINFO_RIFSMODE_PROH;
2487 if (IEEE80211_IS_CHAN_HT40U(bsschan))
2488 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_ABOVE;
2489 else if (IEEE80211_IS_CHAN_HT40D(bsschan))
2490 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_BELOW;
2492 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_NONE;
2493 if (IEEE80211_IS_CHAN_HT40(bsschan))
2494 ht->hi_byte1 |= IEEE80211_HTINFO_TXWIDTH_2040;
2496 /* protection mode */
2497 ht->hi_byte2 = (ht->hi_byte2 &~ PROTMODE) | ic->ic_curhtprotmode;
2499 /* XXX propagate to vendor ie's */
2504 * Add body of an HTINFO information element.
2506 * NB: We don't use struct ieee80211_ie_htinfo because we can
2507 * be called to fillin both a standard ie and a compat ie that
2508 * has a vendor OUI at the front.
2511 ieee80211_add_htinfo_body(uint8_t *frm, struct ieee80211_node *ni)
2513 struct ieee80211vap *vap = ni->ni_vap;
2514 struct ieee80211com *ic = ni->ni_ic;
2516 /* pre-zero remainder of ie */
2517 memset(frm, 0, sizeof(struct ieee80211_ie_htinfo) - 2);
2519 /* primary/control channel center */
2520 *frm++ = ieee80211_chan2ieee(ic, ni->ni_chan);
2522 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
2523 frm[0] = IEEE80211_HTINFO_RIFSMODE_PERM;
2525 frm[0] = IEEE80211_HTINFO_RIFSMODE_PROH;
2526 if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
2527 frm[0] |= IEEE80211_HTINFO_2NDCHAN_ABOVE;
2528 else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
2529 frm[0] |= IEEE80211_HTINFO_2NDCHAN_BELOW;
2531 frm[0] |= IEEE80211_HTINFO_2NDCHAN_NONE;
2532 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
2533 frm[0] |= IEEE80211_HTINFO_TXWIDTH_2040;
2535 frm[1] = ic->ic_curhtprotmode;
2540 ieee80211_set_basic_htrates(frm, &ni->ni_htrates);
2541 frm += sizeof(struct ieee80211_ie_htinfo) -
2542 __offsetof(struct ieee80211_ie_htinfo, hi_basicmcsset);
2547 * Add 802.11n HT information information element.
2550 ieee80211_add_htinfo(uint8_t *frm, struct ieee80211_node *ni)
2552 frm[0] = IEEE80211_ELEMID_HTINFO;
2553 frm[1] = sizeof(struct ieee80211_ie_htinfo) - 2;
2554 return ieee80211_add_htinfo_body(frm + 2, ni);
2558 * Add Broadcom OUI wrapped standard HTINFO ie; this is
2559 * used for compatibility w/ pre-draft implementations.
2562 ieee80211_add_htinfo_vendor(uint8_t *frm, struct ieee80211_node *ni)
2564 frm[0] = IEEE80211_ELEMID_VENDOR;
2565 frm[1] = 4 + sizeof(struct ieee80211_ie_htinfo) - 2;
2566 frm[2] = (BCM_OUI >> 0) & 0xff;
2567 frm[3] = (BCM_OUI >> 8) & 0xff;
2568 frm[4] = (BCM_OUI >> 16) & 0xff;
2569 frm[5] = BCM_OUI_HTINFO;
2570 return ieee80211_add_htinfo_body(frm + 6, ni);