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 { 13, 14, 27, 30 }, /* MCS 0 */
59 { 26, 29, 54, 60 }, /* MCS 1 */
60 { 39, 43, 81, 90 }, /* MCS 2 */
61 { 52, 58, 108, 120 }, /* MCS 3 */
62 { 78, 87, 162, 180 }, /* MCS 4 */
63 { 104, 116, 216, 240 }, /* MCS 5 */
64 { 117, 130, 243, 270 }, /* MCS 6 */
65 { 130, 144, 270, 300 }, /* MCS 7 */
66 { 26, 29, 54, 60 }, /* MCS 8 */
67 { 52, 58, 108, 120 }, /* MCS 9 */
68 { 78, 87, 162, 180 }, /* MCS 10 */
69 { 104, 116, 216, 240 }, /* MCS 11 */
70 { 156, 173, 324, 360 }, /* MCS 12 */
71 { 208, 231, 432, 480 }, /* MCS 13 */
72 { 234, 260, 486, 540 }, /* MCS 14 */
73 { 260, 289, 540, 600 } /* MCS 15 */
76 static const struct ieee80211_htrateset ieee80211_rateset_11n =
78 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
79 10, 11, 12, 13, 14, 15 }
82 #ifdef IEEE80211_AMPDU_AGE
83 static int ieee80211_ampdu_age = -1; /* threshold for ampdu reorder q (ms) */
84 SYSCTL_PROC(_net_wlan, OID_AUTO, ampdu_age, CTLTYPE_INT | CTLFLAG_RW,
85 &ieee80211_ampdu_age, 0, ieee80211_sysctl_msecs_ticks, "I",
86 "AMPDU max reorder age (ms)");
89 static int ieee80211_recv_bar_ena = 1;
90 SYSCTL_INT(_net_wlan, OID_AUTO, recv_bar, CTLFLAG_RW, &ieee80211_recv_bar_ena,
91 0, "BAR frame processing (ena/dis)");
93 static int ieee80211_addba_timeout = -1;/* timeout for ADDBA response */
94 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_timeout, CTLTYPE_INT | CTLFLAG_RW,
95 &ieee80211_addba_timeout, 0, ieee80211_sysctl_msecs_ticks, "I",
96 "ADDBA request timeout (ms)");
97 static int ieee80211_addba_backoff = -1;/* backoff after max ADDBA requests */
98 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_backoff, CTLTYPE_INT | CTLFLAG_RW,
99 &ieee80211_addba_backoff, 0, ieee80211_sysctl_msecs_ticks, "I",
100 "ADDBA request backoff (ms)");
101 static int ieee80211_addba_maxtries = 3;/* max ADDBA requests before backoff */
102 SYSCTL_INT(_net_wlan, OID_AUTO, addba_maxtries, CTLTYPE_INT | CTLFLAG_RW,
103 &ieee80211_addba_maxtries, 0, "max ADDBA requests sent before backoff");
105 static int ieee80211_bar_timeout = -1; /* timeout waiting for BAR response */
106 static int ieee80211_bar_maxtries = 50;/* max BAR requests before DELBA */
108 static ieee80211_recv_action_func ht_recv_action_ba_addba_request;
109 static ieee80211_recv_action_func ht_recv_action_ba_addba_response;
110 static ieee80211_recv_action_func ht_recv_action_ba_delba;
111 static ieee80211_recv_action_func ht_recv_action_ht_mimopwrsave;
112 static ieee80211_recv_action_func ht_recv_action_ht_txchwidth;
114 static ieee80211_send_action_func ht_send_action_ba_addba;
115 static ieee80211_send_action_func ht_send_action_ba_delba;
116 static ieee80211_send_action_func ht_send_action_ht_txchwidth;
119 ieee80211_ht_init(void)
122 * Setup HT parameters that depends on the clock frequency.
124 #ifdef IEEE80211_AMPDU_AGE
125 ieee80211_ampdu_age = msecs_to_ticks(500);
127 ieee80211_addba_timeout = msecs_to_ticks(250);
128 ieee80211_addba_backoff = msecs_to_ticks(10*1000);
129 ieee80211_bar_timeout = msecs_to_ticks(250);
131 * Register action frame handlers.
133 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
134 IEEE80211_ACTION_BA_ADDBA_REQUEST, ht_recv_action_ba_addba_request);
135 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
136 IEEE80211_ACTION_BA_ADDBA_RESPONSE, ht_recv_action_ba_addba_response);
137 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_BA,
138 IEEE80211_ACTION_BA_DELBA, ht_recv_action_ba_delba);
139 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_HT,
140 IEEE80211_ACTION_HT_MIMOPWRSAVE, ht_recv_action_ht_mimopwrsave);
141 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_HT,
142 IEEE80211_ACTION_HT_TXCHWIDTH, ht_recv_action_ht_txchwidth);
144 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
145 IEEE80211_ACTION_BA_ADDBA_REQUEST, ht_send_action_ba_addba);
146 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
147 IEEE80211_ACTION_BA_ADDBA_RESPONSE, ht_send_action_ba_addba);
148 ieee80211_send_action_register(IEEE80211_ACTION_CAT_BA,
149 IEEE80211_ACTION_BA_DELBA, ht_send_action_ba_delba);
150 ieee80211_send_action_register(IEEE80211_ACTION_CAT_HT,
151 IEEE80211_ACTION_HT_TXCHWIDTH, ht_send_action_ht_txchwidth);
153 SYSINIT(wlan_ht, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_ht_init, NULL);
155 static int ieee80211_ampdu_enable(struct ieee80211_node *ni,
156 struct ieee80211_tx_ampdu *tap);
157 static int ieee80211_addba_request(struct ieee80211_node *ni,
158 struct ieee80211_tx_ampdu *tap,
159 int dialogtoken, int baparamset, int batimeout);
160 static int ieee80211_addba_response(struct ieee80211_node *ni,
161 struct ieee80211_tx_ampdu *tap,
162 int code, int baparamset, int batimeout);
163 static void ieee80211_addba_stop(struct ieee80211_node *ni,
164 struct ieee80211_tx_ampdu *tap);
165 static void ieee80211_bar_response(struct ieee80211_node *ni,
166 struct ieee80211_tx_ampdu *tap, int status);
167 static void ampdu_tx_stop(struct ieee80211_tx_ampdu *tap);
168 static void bar_stop_timer(struct ieee80211_tx_ampdu *tap);
169 static int ampdu_rx_start(struct ieee80211_node *, struct ieee80211_rx_ampdu *,
170 int baparamset, int batimeout, int baseqctl);
171 static void ampdu_rx_stop(struct ieee80211_node *, struct ieee80211_rx_ampdu *);
174 ieee80211_ht_attach(struct ieee80211com *ic)
176 /* setup default aggregation policy */
177 ic->ic_recv_action = ieee80211_recv_action;
178 ic->ic_send_action = ieee80211_send_action;
179 ic->ic_ampdu_enable = ieee80211_ampdu_enable;
180 ic->ic_addba_request = ieee80211_addba_request;
181 ic->ic_addba_response = ieee80211_addba_response;
182 ic->ic_addba_stop = ieee80211_addba_stop;
183 ic->ic_bar_response = ieee80211_bar_response;
184 ic->ic_ampdu_rx_start = ampdu_rx_start;
185 ic->ic_ampdu_rx_stop = ampdu_rx_stop;
187 ic->ic_htprotmode = IEEE80211_PROT_RTSCTS;
188 ic->ic_curhtprotmode = IEEE80211_HTINFO_OPMODE_PURE;
192 ieee80211_ht_detach(struct ieee80211com *ic)
197 ieee80211_ht_vattach(struct ieee80211vap *vap)
200 /* driver can override defaults */
201 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_8K;
202 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_NA;
203 vap->iv_ampdu_limit = vap->iv_ampdu_rxmax;
204 vap->iv_amsdu_limit = vap->iv_htcaps & IEEE80211_HTCAP_MAXAMSDU;
205 /* tx aggregation traffic thresholds */
206 vap->iv_ampdu_mintraffic[WME_AC_BK] = 128;
207 vap->iv_ampdu_mintraffic[WME_AC_BE] = 64;
208 vap->iv_ampdu_mintraffic[WME_AC_VO] = 32;
209 vap->iv_ampdu_mintraffic[WME_AC_VI] = 32;
211 if (vap->iv_htcaps & IEEE80211_HTC_HT) {
213 * Device is HT capable; enable all HT-related
214 * facilities by default.
215 * XXX these choices may be too aggressive.
217 vap->iv_flags_ht |= IEEE80211_FHT_HT
218 | IEEE80211_FHT_HTCOMPAT
220 if (vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI20)
221 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI20;
222 /* XXX infer from channel list? */
223 if (vap->iv_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
224 vap->iv_flags_ht |= IEEE80211_FHT_USEHT40;
225 if (vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI40)
226 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI40;
228 /* enable RIFS if capable */
229 if (vap->iv_htcaps & IEEE80211_HTC_RIFS)
230 vap->iv_flags_ht |= IEEE80211_FHT_RIFS;
232 /* NB: A-MPDU and A-MSDU rx are mandated, these are tx only */
233 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_RX;
234 if (vap->iv_htcaps & IEEE80211_HTC_AMPDU)
235 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_TX;
236 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_RX;
237 if (vap->iv_htcaps & IEEE80211_HTC_AMSDU)
238 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_TX;
240 /* NB: disable default legacy WDS, too many issues right now */
241 if (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY)
242 vap->iv_flags_ht &= ~IEEE80211_FHT_HT;
246 ieee80211_ht_vdetach(struct ieee80211vap *vap)
251 ht_announce(struct ieee80211com *ic, int mode,
252 const struct ieee80211_htrateset *rs)
254 struct ifnet *ifp = ic->ic_ifp;
257 if_printf(ifp, "%s MCS: ", ieee80211_phymode_name[mode]);
258 for (i = 0; i < rs->rs_nrates; i++) {
259 mword = ieee80211_rate2media(ic,
260 rs->rs_rates[i] | IEEE80211_RATE_MCS, mode);
261 if (IFM_SUBTYPE(mword) != IFM_IEEE80211_MCS)
263 rate = ieee80211_htrates[rs->rs_rates[i]].ht40_rate_400ns;
264 printf("%s%d%sMbps", (i != 0 ? " " : ""),
265 rate / 2, ((rate & 0x1) != 0 ? ".5" : ""));
271 ieee80211_ht_announce(struct ieee80211com *ic)
273 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NA))
274 ht_announce(ic, IEEE80211_MODE_11NA, &ieee80211_rateset_11n);
275 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NG))
276 ht_announce(ic, IEEE80211_MODE_11NG, &ieee80211_rateset_11n);
279 const struct ieee80211_htrateset *
280 ieee80211_get_suphtrates(struct ieee80211com *ic,
281 const struct ieee80211_channel *c)
283 return &ieee80211_rateset_11n;
287 * Receive processing.
291 * Decap the encapsulated A-MSDU frames and dispatch all but
292 * the last for delivery. The last frame is returned for
293 * delivery via the normal path.
296 ieee80211_decap_amsdu(struct ieee80211_node *ni, struct mbuf *m)
298 struct ieee80211vap *vap = ni->ni_vap;
302 /* discard 802.3 header inserted by ieee80211_decap */
303 m_adj(m, sizeof(struct ether_header));
305 vap->iv_stats.is_amsdu_decap++;
309 * Decap the first frame, bust it apart from the
310 * remainder and deliver. We leave the last frame
311 * delivery to the caller (for consistency with other
312 * code paths, could also do it here).
314 m = ieee80211_decap1(m, &framelen);
316 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
317 ni->ni_macaddr, "a-msdu", "%s", "decap failed");
318 vap->iv_stats.is_amsdu_tooshort++;
321 if (m->m_pkthdr.len == framelen)
323 n = m_split(m, framelen, M_NOWAIT);
325 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
326 ni->ni_macaddr, "a-msdu",
327 "%s", "unable to split encapsulated frames");
328 vap->iv_stats.is_amsdu_split++;
329 m_freem(m); /* NB: must reclaim */
332 vap->iv_deliver_data(vap, ni, m);
335 * Remove frame contents; each intermediate frame
336 * is required to be aligned to a 4-byte boundary.
339 m_adj(m, roundup2(framelen, 4) - framelen); /* padding */
341 return m; /* last delivered by caller */
345 * Purge all frames in the A-MPDU re-order queue.
348 ampdu_rx_purge(struct ieee80211_rx_ampdu *rap)
353 for (i = 0; i < rap->rxa_wnd; i++) {
356 rap->rxa_m[i] = NULL;
357 rap->rxa_qbytes -= m->m_pkthdr.len;
359 if (--rap->rxa_qframes == 0)
363 KASSERT(rap->rxa_qbytes == 0 && rap->rxa_qframes == 0,
364 ("lost %u data, %u frames on ampdu rx q",
365 rap->rxa_qbytes, rap->rxa_qframes));
369 * Start A-MPDU rx/re-order processing for the specified TID.
372 ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap,
373 int baparamset, int batimeout, int baseqctl)
375 int bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
377 if (rap->rxa_flags & IEEE80211_AGGR_RUNNING) {
379 * AMPDU previously setup and not terminated with a DELBA,
380 * flush the reorder q's in case anything remains.
384 memset(rap, 0, sizeof(*rap));
385 rap->rxa_wnd = (bufsiz == 0) ?
386 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
387 rap->rxa_start = MS(baseqctl, IEEE80211_BASEQ_START);
388 rap->rxa_flags |= IEEE80211_AGGR_RUNNING | IEEE80211_AGGR_XCHGPEND;
394 * Stop A-MPDU rx processing for the specified TID.
397 ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
400 rap->rxa_flags &= ~(IEEE80211_AGGR_RUNNING | IEEE80211_AGGR_XCHGPEND);
404 * Dispatch a frame from the A-MPDU reorder queue. The
405 * frame is fed back into ieee80211_input marked with an
406 * M_AMPDU_MPDU flag so it doesn't come back to us (it also
407 * permits ieee80211_input to optimize re-processing).
410 ampdu_dispatch(struct ieee80211_node *ni, struct mbuf *m)
412 m->m_flags |= M_AMPDU_MPDU; /* bypass normal processing */
413 /* NB: rssi and noise are ignored w/ M_AMPDU_MPDU set */
414 (void) ieee80211_input(ni, m, 0, 0);
418 * Dispatch as many frames as possible from the re-order queue.
419 * Frames will always be "at the front"; we process all frames
420 * up to the first empty slot in the window. On completion we
421 * cleanup state if there are still pending frames in the current
422 * BA window. We assume the frame at slot 0 is already handled
423 * by the caller; we always start at slot 1.
426 ampdu_rx_dispatch(struct ieee80211_rx_ampdu *rap, struct ieee80211_node *ni)
428 struct ieee80211vap *vap = ni->ni_vap;
432 /* flush run of frames */
433 for (i = 1; i < rap->rxa_wnd; i++) {
437 rap->rxa_m[i] = NULL;
438 rap->rxa_qbytes -= m->m_pkthdr.len;
441 ampdu_dispatch(ni, m);
444 * If frames remain, copy the mbuf pointers down so
445 * they correspond to the offsets in the new window.
447 if (rap->rxa_qframes != 0) {
448 int n = rap->rxa_qframes, j;
449 for (j = i+1; j < rap->rxa_wnd; j++) {
450 if (rap->rxa_m[j] != NULL) {
451 rap->rxa_m[j-i] = rap->rxa_m[j];
452 rap->rxa_m[j] = NULL;
457 KASSERT(n == 0, ("lost %d frames", n));
458 vap->iv_stats.is_ampdu_rx_copy += rap->rxa_qframes;
461 * Adjust the start of the BA window to
462 * reflect the frames just dispatched.
464 rap->rxa_start = IEEE80211_SEQ_ADD(rap->rxa_start, i);
465 vap->iv_stats.is_ampdu_rx_oor += i;
468 #ifdef IEEE80211_AMPDU_AGE
470 * Dispatch all frames in the A-MPDU re-order queue.
473 ampdu_rx_flush(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
475 struct ieee80211vap *vap = ni->ni_vap;
479 for (i = 0; i < rap->rxa_wnd; i++) {
483 rap->rxa_m[i] = NULL;
484 rap->rxa_qbytes -= m->m_pkthdr.len;
486 vap->iv_stats.is_ampdu_rx_oor++;
488 ampdu_dispatch(ni, m);
489 if (rap->rxa_qframes == 0)
493 #endif /* IEEE80211_AMPDU_AGE */
496 * Dispatch all frames in the A-MPDU re-order queue
497 * preceding the specified sequence number. This logic
498 * handles window moves due to a received MSDU or BAR.
501 ampdu_rx_flush_upto(struct ieee80211_node *ni,
502 struct ieee80211_rx_ampdu *rap, ieee80211_seq winstart)
504 struct ieee80211vap *vap = ni->ni_vap;
510 * Flush any complete MSDU's with a sequence number lower
511 * than winstart. Gaps may exist. Note that we may actually
512 * dispatch frames past winstart if a run continues; this is
513 * an optimization that avoids having to do a separate pass
514 * to dispatch frames after moving the BA window start.
516 seqno = rap->rxa_start;
517 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);
527 if (!IEEE80211_SEQ_BA_BEFORE(seqno, winstart))
530 seqno = IEEE80211_SEQ_INC(seqno);
533 * If frames remain, copy the mbuf pointers down so
534 * they correspond to the offsets in the new window.
536 if (rap->rxa_qframes != 0) {
537 int n = rap->rxa_qframes, j;
539 /* NB: this loop assumes i > 0 and/or rxa_m[0] is NULL */
540 KASSERT(rap->rxa_m[0] == NULL,
541 ("%s: BA window slot 0 occupied", __func__));
542 for (j = i+1; j < rap->rxa_wnd; j++) {
543 if (rap->rxa_m[j] != NULL) {
544 rap->rxa_m[j-i] = rap->rxa_m[j];
545 rap->rxa_m[j] = NULL;
550 KASSERT(n == 0, ("%s: lost %d frames, qframes %d off %d "
551 "BA win <%d:%d> winstart %d",
552 __func__, n, rap->rxa_qframes, i, rap->rxa_start,
553 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
555 vap->iv_stats.is_ampdu_rx_copy += rap->rxa_qframes;
558 * Move the start of the BA window; we use the
559 * sequence number of the last MSDU that was
560 * passed up the stack+1 or winstart if stopped on
561 * a gap in the reorder buffer.
563 rap->rxa_start = seqno;
567 * Process a received QoS data frame for an HT station. Handle
568 * A-MPDU reordering: if this frame is received out of order
569 * and falls within the BA window hold onto it. Otherwise if
570 * this frame completes a run, flush any pending frames. We
571 * return 1 if the frame is consumed. A 0 is returned if
572 * the frame should be processed normally by the caller.
575 ieee80211_ampdu_reorder(struct ieee80211_node *ni, struct mbuf *m)
577 #define IEEE80211_FC0_QOSDATA \
578 (IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_VERSION_0)
579 #define PROCESS 0 /* caller should process frame */
580 #define CONSUMED 1 /* frame consumed, caller does nothing */
581 struct ieee80211vap *vap = ni->ni_vap;
582 struct ieee80211_qosframe *wh;
583 struct ieee80211_rx_ampdu *rap;
588 KASSERT((m->m_flags & (M_AMPDU | M_AMPDU_MPDU)) == M_AMPDU,
589 ("!a-mpdu or already re-ordered, flags 0x%x", m->m_flags));
590 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
592 /* NB: m_len known to be sufficient */
593 wh = mtod(m, struct ieee80211_qosframe *);
594 if (wh->i_fc[0] != IEEE80211_FC0_QOSDATA) {
596 * Not QoS data, shouldn't get here but just
597 * return it to the caller for processing.
601 if (IEEE80211_IS_DSTODS(wh))
602 tid = ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0];
605 tid &= IEEE80211_QOS_TID;
606 rap = &ni->ni_rx_ampdu[tid];
607 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
609 * No ADDBA request yet, don't touch.
613 rxseq = le16toh(*(uint16_t *)wh->i_seq);
614 if ((rxseq & IEEE80211_SEQ_FRAG_MASK) != 0) {
616 * Fragments are not allowed; toss.
618 IEEE80211_DISCARD_MAC(vap,
619 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
620 "A-MPDU", "fragment, rxseq 0x%x tid %u%s", rxseq, tid,
621 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
622 vap->iv_stats.is_ampdu_rx_drop++;
623 IEEE80211_NODE_STAT(ni, rx_drop);
627 rxseq >>= IEEE80211_SEQ_SEQ_SHIFT;
630 if (rxseq == rap->rxa_start) {
632 * First frame in window.
634 if (rap->rxa_qframes != 0) {
636 * Dispatch as many packets as we can.
638 KASSERT(rap->rxa_m[0] == NULL, ("unexpected dup"));
639 ampdu_dispatch(ni, m);
640 ampdu_rx_dispatch(rap, ni);
644 * In order; advance window and notify
645 * caller to dispatch directly.
647 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
652 * Frame is out of order; store if in the BA window.
654 /* calculate offset in BA window */
655 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
656 if (off < rap->rxa_wnd) {
658 * Common case (hopefully): in the BA window.
659 * Sec 9.10.7.6 a) (D2.04 p.118 line 47)
661 #ifdef IEEE80211_AMPDU_AGE
663 * Check for frames sitting too long in the reorder queue.
664 * This should only ever happen if frames are not delivered
665 * without the sender otherwise notifying us (e.g. with a
666 * BAR to move the window). Typically this happens because
667 * of vendor bugs that cause the sequence number to jump.
668 * When this happens we get a gap in the reorder queue that
669 * leaves frame sitting on the queue until they get pushed
670 * out due to window moves. When the vendor does not send
671 * BAR this move only happens due to explicit packet sends
673 * NB: we only track the time of the oldest frame in the
674 * reorder q; this means that if we flush we might push
675 * frames that still "new"; if this happens then subsequent
676 * frames will result in BA window moves which cost something
677 * but is still better than a big throughput dip.
679 if (rap->rxa_qframes != 0) {
680 /* XXX honor batimeout? */
681 if (ticks - rap->rxa_age > ieee80211_ampdu_age) {
683 * Too long since we received the first
684 * frame; flush the reorder buffer.
686 if (rap->rxa_qframes != 0) {
687 vap->iv_stats.is_ampdu_rx_age +=
689 ampdu_rx_flush(ni, rap);
691 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
696 * First frame, start aging timer.
698 rap->rxa_age = ticks;
700 #endif /* IEEE80211_AMPDU_AGE */
702 if (rap->rxa_m[off] == NULL) {
705 rap->rxa_qbytes += m->m_pkthdr.len;
706 vap->iv_stats.is_ampdu_rx_reorder++;
708 IEEE80211_DISCARD_MAC(vap,
709 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
710 ni->ni_macaddr, "a-mpdu duplicate",
711 "seqno %u tid %u BA win <%u:%u>",
712 rxseq, tid, rap->rxa_start,
713 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1));
714 vap->iv_stats.is_rx_dup++;
715 IEEE80211_NODE_STAT(ni, rx_dup);
720 if (off < IEEE80211_SEQ_BA_RANGE) {
722 * Outside the BA window, but within range;
723 * flush the reorder q and move the window.
724 * Sec 9.10.7.6 b) (D2.04 p.118 line 60)
726 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
727 "move BA win <%u:%u> (%u frames) rxseq %u tid %u",
729 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
730 rap->rxa_qframes, rxseq, tid);
731 vap->iv_stats.is_ampdu_rx_move++;
734 * The spec says to flush frames up to but not including:
735 * WinStart_B = rxseq - rap->rxa_wnd + 1
736 * Then insert the frame or notify the caller to process
737 * it immediately. We can safely do this by just starting
738 * over again because we know the frame will now be within
741 /* NB: rxa_wnd known to be >0 */
742 ampdu_rx_flush_upto(ni, rap,
743 IEEE80211_SEQ_SUB(rxseq, rap->rxa_wnd-1));
747 * Outside the BA window and out of range; toss.
748 * Sec 9.10.7.6 c) (D2.04 p.119 line 16)
750 IEEE80211_DISCARD_MAC(vap,
751 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
752 "MPDU", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
754 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
755 rap->rxa_qframes, rxseq, tid,
756 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
757 vap->iv_stats.is_ampdu_rx_drop++;
758 IEEE80211_NODE_STAT(ni, rx_drop);
764 #undef IEEE80211_FC0_QOSDATA
768 * Process a BAR ctl frame. Dispatch all frames up to
769 * the sequence number of the frame. If this frame is
770 * out of range it's discarded.
773 ieee80211_recv_bar(struct ieee80211_node *ni, struct mbuf *m0)
775 struct ieee80211vap *vap = ni->ni_vap;
776 struct ieee80211_frame_bar *wh;
777 struct ieee80211_rx_ampdu *rap;
781 if (!ieee80211_recv_bar_ena) {
783 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_11N,
784 ni->ni_macaddr, "BAR", "%s", "processing disabled");
786 vap->iv_stats.is_ampdu_bar_bad++;
789 wh = mtod(m0, struct ieee80211_frame_bar *);
790 /* XXX check basic BAR */
791 tid = MS(le16toh(wh->i_ctl), IEEE80211_BAR_TID);
792 rap = &ni->ni_rx_ampdu[tid];
793 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
795 * No ADDBA request yet, don't touch.
797 IEEE80211_DISCARD_MAC(vap,
798 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
799 ni->ni_macaddr, "BAR", "no BA stream, tid %u", tid);
800 vap->iv_stats.is_ampdu_bar_bad++;
803 vap->iv_stats.is_ampdu_bar_rx++;
804 rxseq = le16toh(wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;
805 if (rxseq == rap->rxa_start)
807 /* calculate offset in BA window */
808 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
809 if (off < IEEE80211_SEQ_BA_RANGE) {
811 * Flush the reorder q up to rxseq and move the window.
812 * Sec 9.10.7.6 a) (D2.04 p.119 line 22)
814 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
815 "BAR moves BA win <%u:%u> (%u frames) rxseq %u tid %u",
817 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
818 rap->rxa_qframes, rxseq, tid);
819 vap->iv_stats.is_ampdu_bar_move++;
821 ampdu_rx_flush_upto(ni, rap, rxseq);
822 if (off >= rap->rxa_wnd) {
824 * BAR specifies a window start to the right of BA
825 * window; we must move it explicitly since
826 * ampdu_rx_flush_upto will not.
828 rap->rxa_start = rxseq;
832 * Out of range; toss.
833 * Sec 9.10.7.6 b) (D2.04 p.119 line 41)
835 IEEE80211_DISCARD_MAC(vap,
836 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
837 "BAR", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
839 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
840 rap->rxa_qframes, rxseq, tid,
841 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
842 vap->iv_stats.is_ampdu_bar_oow++;
843 IEEE80211_NODE_STAT(ni, rx_drop);
848 * Setup HT-specific state in a node. Called only
849 * when HT use is negotiated so we don't do extra
850 * work for temporary and/or legacy sta's.
853 ieee80211_ht_node_init(struct ieee80211_node *ni)
855 struct ieee80211_tx_ampdu *tap;
858 if (ni->ni_flags & IEEE80211_NODE_HT) {
860 * Clean AMPDU state on re-associate. This handles the case
861 * where a station leaves w/o notifying us and then returns
862 * before node is reaped for inactivity.
864 ieee80211_ht_node_cleanup(ni);
866 for (ac = 0; ac < WME_NUM_AC; ac++) {
867 tap = &ni->ni_tx_ampdu[ac];
870 /* NB: further initialization deferred */
872 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
876 * Cleanup HT-specific state in a node. Called only
877 * when HT use has been marked.
880 ieee80211_ht_node_cleanup(struct ieee80211_node *ni)
882 struct ieee80211com *ic = ni->ni_ic;
885 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT node"));
887 /* XXX optimize this */
888 for (i = 0; i < WME_NUM_AC; i++) {
889 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[i];
890 if (tap->txa_flags & IEEE80211_AGGR_SETUP)
893 for (i = 0; i < WME_NUM_TID; i++)
894 ic->ic_ampdu_rx_stop(ni, &ni->ni_rx_ampdu[i]);
897 ni->ni_flags &= ~IEEE80211_NODE_HT_ALL;
901 * Age out HT resources for a station.
904 ieee80211_ht_node_age(struct ieee80211_node *ni)
906 #ifdef IEEE80211_AMPDU_AGE
907 struct ieee80211vap *vap = ni->ni_vap;
911 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
913 #ifdef IEEE80211_AMPDU_AGE
914 for (tid = 0; tid < WME_NUM_TID; tid++) {
915 struct ieee80211_rx_ampdu *rap;
917 rap = &ni->ni_rx_ampdu[tid];
918 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0)
920 if (rap->rxa_qframes == 0)
923 * Check for frames sitting too long in the reorder queue.
924 * See above for more details on what's happening here.
926 /* XXX honor batimeout? */
927 if (ticks - rap->rxa_age > ieee80211_ampdu_age) {
929 * Too long since we received the first
930 * frame; flush the reorder buffer.
932 vap->iv_stats.is_ampdu_rx_age += rap->rxa_qframes;
933 ampdu_rx_flush(ni, rap);
936 #endif /* IEEE80211_AMPDU_AGE */
939 static struct ieee80211_channel *
940 findhtchan(struct ieee80211com *ic, struct ieee80211_channel *c, int htflags)
942 return ieee80211_find_channel(ic, c->ic_freq,
943 (c->ic_flags &~ IEEE80211_CHAN_HT) | htflags);
947 * Adjust a channel to be HT/non-HT according to the vap's configuration.
949 struct ieee80211_channel *
950 ieee80211_ht_adjust_channel(struct ieee80211com *ic,
951 struct ieee80211_channel *chan, int flags)
953 struct ieee80211_channel *c;
955 if (flags & IEEE80211_FHT_HT) {
956 /* promote to HT if possible */
957 if (flags & IEEE80211_FHT_USEHT40) {
958 if (!IEEE80211_IS_CHAN_HT40(chan)) {
959 /* NB: arbitrarily pick ht40+ over ht40- */
960 c = findhtchan(ic, chan, IEEE80211_CHAN_HT40U);
962 c = findhtchan(ic, chan,
963 IEEE80211_CHAN_HT40D);
965 c = findhtchan(ic, chan,
966 IEEE80211_CHAN_HT20);
970 } else if (!IEEE80211_IS_CHAN_HT20(chan)) {
971 c = findhtchan(ic, chan, IEEE80211_CHAN_HT20);
975 } else if (IEEE80211_IS_CHAN_HT(chan)) {
976 /* demote to legacy, HT use is disabled */
977 c = ieee80211_find_channel(ic, chan->ic_freq,
978 chan->ic_flags &~ IEEE80211_CHAN_HT);
986 * Setup HT-specific state for a legacy WDS peer.
989 ieee80211_ht_wds_init(struct ieee80211_node *ni)
991 struct ieee80211vap *vap = ni->ni_vap;
992 struct ieee80211_tx_ampdu *tap;
995 KASSERT(vap->iv_flags_ht & IEEE80211_FHT_HT, ("no HT requested"));
997 /* XXX check scan cache in case peer has an ap and we have info */
999 * If setup with a legacy channel; locate an HT channel.
1000 * Otherwise if the inherited channel (from a companion
1001 * AP) is suitable use it so we use the same location
1002 * for the extension channel).
1004 ni->ni_chan = ieee80211_ht_adjust_channel(ni->ni_ic,
1005 ni->ni_chan, ieee80211_htchanflags(ni->ni_chan));
1008 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20)
1009 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI20;
1010 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {
1011 ni->ni_htcap |= IEEE80211_HTCAP_CHWIDTH40;
1013 if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
1014 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_ABOVE;
1015 else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
1016 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_BELOW;
1017 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40)
1018 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI40;
1021 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_NONE;
1023 ni->ni_htctlchan = ni->ni_chan->ic_ieee;
1024 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
1025 ni->ni_flags |= IEEE80211_NODE_RIFS;
1026 /* XXX does it make sense to enable SMPS? */
1028 ni->ni_htopmode = 0; /* XXX need protection state */
1029 ni->ni_htstbc = 0; /* XXX need info */
1031 for (ac = 0; ac < WME_NUM_AC; ac++) {
1032 tap = &ni->ni_tx_ampdu[ac];
1035 /* NB: AMPDU tx/rx governed by IEEE80211_FHT_AMPDU_{TX,RX} */
1036 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
1040 * Notify hostap vaps of a change in the HTINFO ie.
1043 htinfo_notify(struct ieee80211com *ic)
1045 struct ieee80211vap *vap;
1048 IEEE80211_LOCK_ASSERT(ic);
1050 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1051 if (vap->iv_opmode != IEEE80211_M_HOSTAP)
1053 if (vap->iv_state != IEEE80211_S_RUN ||
1054 !IEEE80211_IS_CHAN_HT(vap->iv_bss->ni_chan))
1058 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N,
1060 "HT bss occupancy change: %d sta, %d ht, "
1061 "%d ht40%s, HT protmode now 0x%x"
1063 , ic->ic_ht_sta_assoc
1064 , ic->ic_ht40_sta_assoc
1065 , (ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) ?
1066 ", non-HT sta present" : ""
1067 , ic->ic_curhtprotmode);
1070 ieee80211_beacon_notify(vap, IEEE80211_BEACON_HTINFO);
1075 * Calculate HT protection mode from current
1076 * state and handle updates.
1079 htinfo_update(struct ieee80211com *ic)
1083 if (ic->ic_sta_assoc != ic->ic_ht_sta_assoc) {
1084 protmode = IEEE80211_HTINFO_OPMODE_MIXED
1085 | IEEE80211_HTINFO_NONHT_PRESENT;
1086 } else if (ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) {
1087 protmode = IEEE80211_HTINFO_OPMODE_PROTOPT
1088 | IEEE80211_HTINFO_NONHT_PRESENT;
1089 } else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1090 IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) &&
1091 ic->ic_sta_assoc != ic->ic_ht40_sta_assoc) {
1092 protmode = IEEE80211_HTINFO_OPMODE_HT20PR;
1094 protmode = IEEE80211_HTINFO_OPMODE_PURE;
1096 if (protmode != ic->ic_curhtprotmode) {
1097 ic->ic_curhtprotmode = protmode;
1103 * Handle an HT station joining a BSS.
1106 ieee80211_ht_node_join(struct ieee80211_node *ni)
1108 struct ieee80211com *ic = ni->ni_ic;
1110 IEEE80211_LOCK_ASSERT(ic);
1112 if (ni->ni_flags & IEEE80211_NODE_HT) {
1113 ic->ic_ht_sta_assoc++;
1114 if (ni->ni_chw == 40)
1115 ic->ic_ht40_sta_assoc++;
1121 * Handle an HT station leaving a BSS.
1124 ieee80211_ht_node_leave(struct ieee80211_node *ni)
1126 struct ieee80211com *ic = ni->ni_ic;
1128 IEEE80211_LOCK_ASSERT(ic);
1130 if (ni->ni_flags & IEEE80211_NODE_HT) {
1131 ic->ic_ht_sta_assoc--;
1132 if (ni->ni_chw == 40)
1133 ic->ic_ht40_sta_assoc--;
1139 * Public version of htinfo_update; used for processing
1140 * beacon frames from overlapping bss.
1142 * Caller can specify either IEEE80211_HTINFO_OPMODE_MIXED
1143 * (on receipt of a beacon that advertises MIXED) or
1144 * IEEE80211_HTINFO_OPMODE_PROTOPT (on receipt of a beacon
1145 * from an overlapping legacy bss). We treat MIXED with
1146 * a higher precedence than PROTOPT (i.e. we will not change
1147 * change PROTOPT -> MIXED; only MIXED -> PROTOPT). This
1148 * corresponds to how we handle things in htinfo_update.
1151 ieee80211_htprot_update(struct ieee80211com *ic, int protmode)
1153 #define OPMODE(x) SM(x, IEEE80211_HTINFO_OPMODE)
1156 /* track non-HT station presence */
1157 KASSERT(protmode & IEEE80211_HTINFO_NONHT_PRESENT,
1158 ("protmode 0x%x", protmode));
1159 ic->ic_flags_ht |= IEEE80211_FHT_NONHT_PR;
1160 ic->ic_lastnonht = ticks;
1162 if (protmode != ic->ic_curhtprotmode &&
1163 (OPMODE(ic->ic_curhtprotmode) != IEEE80211_HTINFO_OPMODE_MIXED ||
1164 OPMODE(protmode) == IEEE80211_HTINFO_OPMODE_PROTOPT)) {
1165 /* push beacon update */
1166 ic->ic_curhtprotmode = protmode;
1169 IEEE80211_UNLOCK(ic);
1174 * Time out presence of an overlapping bss with non-HT
1175 * stations. When operating in hostap mode we listen for
1176 * beacons from other stations and if we identify a non-HT
1177 * station is present we update the opmode field of the
1178 * HTINFO ie. To identify when all non-HT stations are
1179 * gone we time out this condition.
1182 ieee80211_ht_timeout(struct ieee80211com *ic)
1184 IEEE80211_LOCK_ASSERT(ic);
1186 if ((ic->ic_flags_ht & IEEE80211_FHT_NONHT_PR) &&
1187 time_after(ticks, ic->ic_lastnonht + IEEE80211_NONHT_PRESENT_AGE)) {
1189 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
1190 "%s", "time out non-HT STA present on channel");
1192 ic->ic_flags_ht &= ~IEEE80211_FHT_NONHT_PR;
1197 /* unalligned little endian access */
1198 #define LE_READ_2(p) \
1200 ((((const uint8_t *)(p))[0] ) | \
1201 (((const uint8_t *)(p))[1] << 8)))
1204 * Process an 802.11n HT capabilities ie.
1207 ieee80211_parse_htcap(struct ieee80211_node *ni, const uint8_t *ie)
1209 if (ie[0] == IEEE80211_ELEMID_VENDOR) {
1211 * Station used Vendor OUI ie to associate;
1212 * mark the node so when we respond we'll use
1213 * the Vendor OUI's and not the standard ie's.
1215 ni->ni_flags |= IEEE80211_NODE_HTCOMPAT;
1218 ni->ni_flags &= ~IEEE80211_NODE_HTCOMPAT;
1220 ni->ni_htcap = LE_READ_2(ie +
1221 __offsetof(struct ieee80211_ie_htcap, hc_cap));
1222 ni->ni_htparam = ie[__offsetof(struct ieee80211_ie_htcap, hc_param)];
1226 htinfo_parse(struct ieee80211_node *ni,
1227 const struct ieee80211_ie_htinfo *htinfo)
1231 ni->ni_htctlchan = htinfo->hi_ctrlchannel;
1232 ni->ni_ht2ndchan = SM(htinfo->hi_byte1, IEEE80211_HTINFO_2NDCHAN);
1233 w = LE_READ_2(&htinfo->hi_byte2);
1234 ni->ni_htopmode = SM(w, IEEE80211_HTINFO_OPMODE);
1235 w = LE_READ_2(&htinfo->hi_byte45);
1236 ni->ni_htstbc = SM(w, IEEE80211_HTINFO_BASIC_STBCMCS);
1240 * Parse an 802.11n HT info ie and save useful information
1241 * to the node state. Note this does not effect any state
1242 * changes such as for channel width change.
1245 ieee80211_parse_htinfo(struct ieee80211_node *ni, const uint8_t *ie)
1247 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1249 htinfo_parse(ni, (const struct ieee80211_ie_htinfo *) ie);
1253 * Handle 11n channel switch. Use the received HT ie's to
1254 * identify the right channel to use. If we cannot locate it
1255 * in the channel table then fallback to legacy operation.
1256 * Note that we use this information to identify the node's
1257 * channel only; the caller is responsible for insuring any
1258 * required channel change is done (e.g. in sta mode when
1259 * parsing the contents of a beacon frame).
1262 htinfo_update_chw(struct ieee80211_node *ni, int htflags)
1264 struct ieee80211com *ic = ni->ni_ic;
1265 struct ieee80211_channel *c;
1268 chanflags = (ni->ni_chan->ic_flags &~ IEEE80211_CHAN_HT) | htflags;
1269 if (chanflags != ni->ni_chan->ic_flags) {
1270 /* XXX not right for ht40- */
1271 c = ieee80211_find_channel(ic, ni->ni_chan->ic_freq, chanflags);
1272 if (c == NULL && (htflags & IEEE80211_CHAN_HT40)) {
1274 * No HT40 channel entry in our table; fall back
1275 * to HT20 operation. This should not happen.
1277 c = findhtchan(ic, ni->ni_chan, IEEE80211_CHAN_HT20);
1279 IEEE80211_NOTE(ni->ni_vap,
1280 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1281 "no HT40 channel (freq %u), falling back to HT20",
1282 ni->ni_chan->ic_freq);
1286 if (c != NULL && c != ni->ni_chan) {
1287 IEEE80211_NOTE(ni->ni_vap,
1288 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1289 "switch station to HT%d channel %u/0x%x",
1290 IEEE80211_IS_CHAN_HT40(c) ? 40 : 20,
1291 c->ic_freq, c->ic_flags);
1294 /* NB: caller responsible for forcing any channel change */
1296 /* update node's tx channel width */
1297 ni->ni_chw = IEEE80211_IS_CHAN_HT40(ni->ni_chan)? 40 : 20;
1301 * Update 11n MIMO PS state according to received htcap.
1304 htcap_update_mimo_ps(struct ieee80211_node *ni)
1306 uint16_t oflags = ni->ni_flags;
1308 switch (ni->ni_htcap & IEEE80211_HTCAP_SMPS) {
1309 case IEEE80211_HTCAP_SMPS_DYNAMIC:
1310 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1311 ni->ni_flags |= IEEE80211_NODE_MIMO_RTS;
1313 case IEEE80211_HTCAP_SMPS_ENA:
1314 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1315 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1317 case IEEE80211_HTCAP_SMPS_OFF:
1318 default: /* disable on rx of reserved value */
1319 ni->ni_flags &= ~IEEE80211_NODE_MIMO_PS;
1320 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1323 return (oflags ^ ni->ni_flags);
1327 * Update short GI state according to received htcap
1328 * and local settings.
1330 static __inline void
1331 htcap_update_shortgi(struct ieee80211_node *ni)
1333 struct ieee80211vap *vap = ni->ni_vap;
1335 ni->ni_flags &= ~(IEEE80211_NODE_SGI20|IEEE80211_NODE_SGI40);
1336 if ((ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20) &&
1337 (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20))
1338 ni->ni_flags |= IEEE80211_NODE_SGI20;
1339 if ((ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40) &&
1340 (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40))
1341 ni->ni_flags |= IEEE80211_NODE_SGI40;
1345 * Parse and update HT-related state extracted from
1346 * the HT cap and info ie's.
1349 ieee80211_ht_updateparams(struct ieee80211_node *ni,
1350 const uint8_t *htcapie, const uint8_t *htinfoie)
1352 struct ieee80211vap *vap = ni->ni_vap;
1353 const struct ieee80211_ie_htinfo *htinfo;
1356 ieee80211_parse_htcap(ni, htcapie);
1357 if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS)
1358 htcap_update_mimo_ps(ni);
1359 htcap_update_shortgi(ni);
1361 if (htinfoie[0] == IEEE80211_ELEMID_VENDOR)
1363 htinfo = (const struct ieee80211_ie_htinfo *) htinfoie;
1364 htinfo_parse(ni, htinfo);
1366 htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ?
1367 IEEE80211_CHAN_HT20 : 0;
1368 /* NB: honor operating mode constraint */
1369 if ((htinfo->hi_byte1 & IEEE80211_HTINFO_TXWIDTH_2040) &&
1370 (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)) {
1371 if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_ABOVE)
1372 htflags = IEEE80211_CHAN_HT40U;
1373 else if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_BELOW)
1374 htflags = IEEE80211_CHAN_HT40D;
1376 htinfo_update_chw(ni, htflags);
1378 if ((htinfo->hi_byte1 & IEEE80211_HTINFO_RIFSMODE_PERM) &&
1379 (vap->iv_flags_ht & IEEE80211_FHT_RIFS))
1380 ni->ni_flags |= IEEE80211_NODE_RIFS;
1382 ni->ni_flags &= ~IEEE80211_NODE_RIFS;
1386 * Parse and update HT-related state extracted from the HT cap ie
1387 * for a station joining an HT BSS.
1390 ieee80211_ht_updatehtcap(struct ieee80211_node *ni, const uint8_t *htcapie)
1392 struct ieee80211vap *vap = ni->ni_vap;
1395 ieee80211_parse_htcap(ni, htcapie);
1396 if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS)
1397 htcap_update_mimo_ps(ni);
1398 htcap_update_shortgi(ni);
1400 /* NB: honor operating mode constraint */
1401 /* XXX 40 MHZ intolerant */
1402 htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ?
1403 IEEE80211_CHAN_HT20 : 0;
1404 if ((ni->ni_htcap & IEEE80211_HTCAP_CHWIDTH40) &&
1405 (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)) {
1406 if (IEEE80211_IS_CHAN_HT40U(vap->iv_bss->ni_chan))
1407 htflags = IEEE80211_CHAN_HT40U;
1408 else if (IEEE80211_IS_CHAN_HT40D(vap->iv_bss->ni_chan))
1409 htflags = IEEE80211_CHAN_HT40D;
1411 htinfo_update_chw(ni, htflags);
1415 * Install received HT rate set by parsing the HT cap ie.
1418 ieee80211_setup_htrates(struct ieee80211_node *ni, const uint8_t *ie, int flags)
1420 struct ieee80211vap *vap = ni->ni_vap;
1421 const struct ieee80211_ie_htcap *htcap;
1422 struct ieee80211_htrateset *rs;
1425 rs = &ni->ni_htrates;
1426 memset(rs, 0, sizeof(*rs));
1428 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1430 htcap = (const struct ieee80211_ie_htcap *) ie;
1431 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) {
1432 if (isclr(htcap->hc_mcsset, i))
1434 if (rs->rs_nrates == IEEE80211_HTRATE_MAXSIZE) {
1436 IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni,
1437 "WARNING, HT rate set too large; only "
1438 "using %u rates", IEEE80211_HTRATE_MAXSIZE);
1439 vap->iv_stats.is_rx_rstoobig++;
1442 rs->rs_rates[rs->rs_nrates++] = i;
1445 return ieee80211_fix_rate(ni, (struct ieee80211_rateset *) rs, flags);
1449 * Mark rates in a node's HT rate set as basic according
1450 * to the information in the supplied HT info ie.
1453 ieee80211_setup_basic_htrates(struct ieee80211_node *ni, const uint8_t *ie)
1455 const struct ieee80211_ie_htinfo *htinfo;
1456 struct ieee80211_htrateset *rs;
1459 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1461 htinfo = (const struct ieee80211_ie_htinfo *) ie;
1462 rs = &ni->ni_htrates;
1463 if (rs->rs_nrates == 0) {
1464 IEEE80211_NOTE(ni->ni_vap,
1465 IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni,
1466 "%s", "WARNING, empty HT rate set");
1469 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) {
1470 if (isclr(htinfo->hi_basicmcsset, i))
1472 for (j = 0; j < rs->rs_nrates; j++)
1473 if ((rs->rs_rates[j] & IEEE80211_RATE_VAL) == i)
1474 rs->rs_rates[j] |= IEEE80211_RATE_BASIC;
1479 ampdu_tx_setup(struct ieee80211_tx_ampdu *tap)
1481 callout_init(&tap->txa_timer, CALLOUT_MPSAFE);
1482 tap->txa_flags |= IEEE80211_AGGR_SETUP;
1486 ampdu_tx_stop(struct ieee80211_tx_ampdu *tap)
1488 struct ieee80211_node *ni = tap->txa_ni;
1489 struct ieee80211com *ic = ni->ni_ic;
1491 KASSERT(tap->txa_flags & IEEE80211_AGGR_SETUP,
1492 ("txa_flags 0x%x ac %d", tap->txa_flags, tap->txa_ac));
1495 * Stop BA stream if setup so driver has a chance
1496 * to reclaim any resources it might have allocated.
1498 ic->ic_addba_stop(ni, tap);
1500 * Stop any pending BAR transmit.
1502 bar_stop_timer(tap);
1504 tap->txa_lastsample = 0;
1505 tap->txa_avgpps = 0;
1506 /* NB: clearing NAK means we may re-send ADDBA */
1507 tap->txa_flags &= ~(IEEE80211_AGGR_SETUP | IEEE80211_AGGR_NAK);
1511 addba_timeout(void *arg)
1513 struct ieee80211_tx_ampdu *tap = arg;
1516 tap->txa_flags &= ~IEEE80211_AGGR_XCHGPEND;
1517 tap->txa_attempts++;
1521 addba_start_timeout(struct ieee80211_tx_ampdu *tap)
1523 /* XXX use CALLOUT_PENDING instead? */
1524 callout_reset(&tap->txa_timer, ieee80211_addba_timeout,
1525 addba_timeout, tap);
1526 tap->txa_flags |= IEEE80211_AGGR_XCHGPEND;
1527 tap->txa_nextrequest = ticks + ieee80211_addba_timeout;
1531 addba_stop_timeout(struct ieee80211_tx_ampdu *tap)
1533 /* XXX use CALLOUT_PENDING instead? */
1534 if (tap->txa_flags & IEEE80211_AGGR_XCHGPEND) {
1535 callout_stop(&tap->txa_timer);
1536 tap->txa_flags &= ~IEEE80211_AGGR_XCHGPEND;
1541 * Default method for requesting A-MPDU tx aggregation.
1542 * We setup the specified state block and start a timer
1543 * to wait for an ADDBA response frame.
1546 ieee80211_addba_request(struct ieee80211_node *ni,
1547 struct ieee80211_tx_ampdu *tap,
1548 int dialogtoken, int baparamset, int batimeout)
1553 tap->txa_token = dialogtoken;
1554 tap->txa_flags |= IEEE80211_AGGR_IMMEDIATE;
1555 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1556 tap->txa_wnd = (bufsiz == 0) ?
1557 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
1558 addba_start_timeout(tap);
1563 * Default method for processing an A-MPDU tx aggregation
1564 * response. We shutdown any pending timer and update the
1565 * state block according to the reply.
1568 ieee80211_addba_response(struct ieee80211_node *ni,
1569 struct ieee80211_tx_ampdu *tap,
1570 int status, int baparamset, int batimeout)
1575 addba_stop_timeout(tap);
1576 if (status == IEEE80211_STATUS_SUCCESS) {
1577 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1578 /* XXX override our request? */
1579 tap->txa_wnd = (bufsiz == 0) ?
1580 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
1582 tid = MS(baparamset, IEEE80211_BAPS_TID);
1583 tap->txa_flags |= IEEE80211_AGGR_RUNNING;
1584 tap->txa_attempts = 0;
1586 /* mark tid so we don't try again */
1587 tap->txa_flags |= IEEE80211_AGGR_NAK;
1593 * Default method for stopping A-MPDU tx aggregation.
1594 * Any timer is cleared and we drain any pending frames.
1597 ieee80211_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
1600 addba_stop_timeout(tap);
1601 if (tap->txa_flags & IEEE80211_AGGR_RUNNING) {
1602 /* XXX clear aggregation queue */
1603 tap->txa_flags &= ~IEEE80211_AGGR_RUNNING;
1605 tap->txa_attempts = 0;
1609 * Process a received action frame using the default aggregation
1610 * policy. We intercept ADDBA-related frames and use them to
1611 * update our aggregation state. All other frames are passed up
1612 * for processing by ieee80211_recv_action.
1615 ht_recv_action_ba_addba_request(struct ieee80211_node *ni,
1616 const struct ieee80211_frame *wh,
1617 const uint8_t *frm, const uint8_t *efrm)
1619 struct ieee80211com *ic = ni->ni_ic;
1620 struct ieee80211vap *vap = ni->ni_vap;
1621 struct ieee80211_rx_ampdu *rap;
1622 uint8_t dialogtoken;
1623 uint16_t baparamset, batimeout, baseqctl;
1627 dialogtoken = frm[2];
1628 baparamset = LE_READ_2(frm+3);
1629 batimeout = LE_READ_2(frm+5);
1630 baseqctl = LE_READ_2(frm+7);
1632 tid = MS(baparamset, IEEE80211_BAPS_TID);
1634 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1635 "recv ADDBA request: dialogtoken %u baparamset 0x%x "
1636 "(tid %d bufsiz %d) batimeout %d baseqctl %d:%d",
1637 dialogtoken, baparamset,
1638 tid, MS(baparamset, IEEE80211_BAPS_BUFSIZ),
1640 MS(baseqctl, IEEE80211_BASEQ_START),
1641 MS(baseqctl, IEEE80211_BASEQ_FRAG));
1643 rap = &ni->ni_rx_ampdu[tid];
1645 /* Send ADDBA response */
1646 args[0] = dialogtoken;
1648 * NB: We ack only if the sta associated with HT and
1649 * the ap is configured to do AMPDU rx (the latter
1650 * violates the 11n spec and is mostly for testing).
1652 if ((ni->ni_flags & IEEE80211_NODE_AMPDU_RX) &&
1653 (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_RX)) {
1654 /* XXX handle ampdu_rx_start failure */
1655 ic->ic_ampdu_rx_start(ni, rap,
1656 baparamset, batimeout, baseqctl);
1658 args[1] = IEEE80211_STATUS_SUCCESS;
1660 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1661 ni, "reject ADDBA request: %s",
1662 ni->ni_flags & IEEE80211_NODE_AMPDU_RX ?
1663 "administratively disabled" :
1664 "not negotiated for station");
1665 vap->iv_stats.is_addba_reject++;
1666 args[1] = IEEE80211_STATUS_UNSPECIFIED;
1668 /* XXX honor rap flags? */
1669 args[2] = IEEE80211_BAPS_POLICY_IMMEDIATE
1670 | SM(tid, IEEE80211_BAPS_TID)
1671 | SM(rap->rxa_wnd, IEEE80211_BAPS_BUFSIZ)
1674 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1675 IEEE80211_ACTION_BA_ADDBA_RESPONSE, args);
1680 ht_recv_action_ba_addba_response(struct ieee80211_node *ni,
1681 const struct ieee80211_frame *wh,
1682 const uint8_t *frm, const uint8_t *efrm)
1684 struct ieee80211com *ic = ni->ni_ic;
1685 struct ieee80211vap *vap = ni->ni_vap;
1686 struct ieee80211_tx_ampdu *tap;
1687 uint8_t dialogtoken, policy;
1688 uint16_t baparamset, batimeout, code;
1689 int tid, ac, bufsiz;
1691 dialogtoken = frm[2];
1692 code = LE_READ_2(frm+3);
1693 baparamset = LE_READ_2(frm+5);
1694 tid = MS(baparamset, IEEE80211_BAPS_TID);
1695 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1696 policy = MS(baparamset, IEEE80211_BAPS_POLICY);
1697 batimeout = LE_READ_2(frm+7);
1699 ac = TID_TO_WME_AC(tid);
1700 tap = &ni->ni_tx_ampdu[ac];
1701 if ((tap->txa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
1702 IEEE80211_DISCARD_MAC(vap,
1703 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1704 ni->ni_macaddr, "ADDBA response",
1705 "no pending ADDBA, tid %d dialogtoken %u "
1706 "code %d", tid, dialogtoken, code);
1707 vap->iv_stats.is_addba_norequest++;
1710 if (dialogtoken != tap->txa_token) {
1711 IEEE80211_DISCARD_MAC(vap,
1712 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1713 ni->ni_macaddr, "ADDBA response",
1714 "dialogtoken mismatch: waiting for %d, "
1715 "received %d, tid %d code %d",
1716 tap->txa_token, dialogtoken, tid, code);
1717 vap->iv_stats.is_addba_badtoken++;
1720 /* NB: assumes IEEE80211_AGGR_IMMEDIATE is 1 */
1721 if (policy != (tap->txa_flags & IEEE80211_AGGR_IMMEDIATE)) {
1722 IEEE80211_DISCARD_MAC(vap,
1723 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1724 ni->ni_macaddr, "ADDBA response",
1725 "policy mismatch: expecting %s, "
1726 "received %s, tid %d code %d",
1727 tap->txa_flags & IEEE80211_AGGR_IMMEDIATE,
1729 vap->iv_stats.is_addba_badpolicy++;
1733 /* XXX we take MIN in ieee80211_addba_response */
1734 if (bufsiz > IEEE80211_AGGR_BAWMAX) {
1735 IEEE80211_DISCARD_MAC(vap,
1736 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1737 ni->ni_macaddr, "ADDBA response",
1738 "BA window too large: max %d, "
1739 "received %d, tid %d code %d",
1740 bufsiz, IEEE80211_AGGR_BAWMAX, tid, code);
1741 vap->iv_stats.is_addba_badbawinsize++;
1745 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1746 "recv ADDBA response: dialogtoken %u code %d "
1747 "baparamset 0x%x (tid %d bufsiz %d) batimeout %d",
1748 dialogtoken, code, baparamset, tid, bufsiz,
1750 ic->ic_addba_response(ni, tap, code, baparamset, batimeout);
1755 ht_recv_action_ba_delba(struct ieee80211_node *ni,
1756 const struct ieee80211_frame *wh,
1757 const uint8_t *frm, const uint8_t *efrm)
1759 struct ieee80211com *ic = ni->ni_ic;
1760 struct ieee80211_rx_ampdu *rap;
1761 struct ieee80211_tx_ampdu *tap;
1762 uint16_t baparamset, code;
1765 baparamset = LE_READ_2(frm+2);
1766 code = LE_READ_2(frm+4);
1768 tid = MS(baparamset, IEEE80211_DELBAPS_TID);
1770 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1771 "recv DELBA: baparamset 0x%x (tid %d initiator %d) "
1772 "code %d", baparamset, tid,
1773 MS(baparamset, IEEE80211_DELBAPS_INIT), code);
1775 if ((baparamset & IEEE80211_DELBAPS_INIT) == 0) {
1776 ac = TID_TO_WME_AC(tid);
1777 tap = &ni->ni_tx_ampdu[ac];
1778 ic->ic_addba_stop(ni, tap);
1780 rap = &ni->ni_rx_ampdu[tid];
1781 ic->ic_ampdu_rx_stop(ni, rap);
1787 ht_recv_action_ht_txchwidth(struct ieee80211_node *ni,
1788 const struct ieee80211_frame *wh,
1789 const uint8_t *frm, const uint8_t *efrm)
1793 chw = (frm[2] == IEEE80211_A_HT_TXCHWIDTH_2040) ? 40 : 20;
1795 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1796 "%s: HT txchwidth, width %d%s",
1797 __func__, chw, ni->ni_chw != chw ? "*" : "");
1798 if (chw != ni->ni_chw) {
1800 /* XXX notify on change */
1806 ht_recv_action_ht_mimopwrsave(struct ieee80211_node *ni,
1807 const struct ieee80211_frame *wh,
1808 const uint8_t *frm, const uint8_t *efrm)
1810 const struct ieee80211_action_ht_mimopowersave *mps =
1811 (const struct ieee80211_action_ht_mimopowersave *) frm;
1813 /* XXX check iv_htcaps */
1814 if (mps->am_control & IEEE80211_A_HT_MIMOPWRSAVE_ENA)
1815 ni->ni_flags |= IEEE80211_NODE_MIMO_PS;
1817 ni->ni_flags &= ~IEEE80211_NODE_MIMO_PS;
1818 if (mps->am_control & IEEE80211_A_HT_MIMOPWRSAVE_MODE)
1819 ni->ni_flags |= IEEE80211_NODE_MIMO_RTS;
1821 ni->ni_flags &= ~IEEE80211_NODE_MIMO_RTS;
1822 /* XXX notify on change */
1823 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1824 "%s: HT MIMO PS (%s%s)", __func__,
1825 (ni->ni_flags & IEEE80211_NODE_MIMO_PS) ? "on" : "off",
1826 (ni->ni_flags & IEEE80211_NODE_MIMO_RTS) ? "+rts" : ""
1832 * Transmit processing.
1836 * Check if A-MPDU should be requested/enabled for a stream.
1837 * We require a traffic rate above a per-AC threshold and we
1838 * also handle backoff from previous failed attempts.
1840 * Drivers may override this method to bring in information
1841 * such as link state conditions in making the decision.
1844 ieee80211_ampdu_enable(struct ieee80211_node *ni,
1845 struct ieee80211_tx_ampdu *tap)
1847 struct ieee80211vap *vap = ni->ni_vap;
1849 if (tap->txa_avgpps < vap->iv_ampdu_mintraffic[tap->txa_ac])
1851 /* XXX check rssi? */
1852 if (tap->txa_attempts >= ieee80211_addba_maxtries &&
1853 ticks < tap->txa_nextrequest) {
1855 * Don't retry too often; txa_nextrequest is set
1856 * to the minimum interval we'll retry after
1857 * ieee80211_addba_maxtries failed attempts are made.
1861 IEEE80211_NOTE(vap, IEEE80211_MSG_11N, ni,
1862 "enable AMPDU on %s, avgpps %d pkts %d",
1863 ieee80211_wme_acnames[tap->txa_ac], tap->txa_avgpps, tap->txa_pkts);
1868 * Request A-MPDU tx aggregation. Setup local state and
1869 * issue an ADDBA request. BA use will only happen after
1870 * the other end replies with ADDBA response.
1873 ieee80211_ampdu_request(struct ieee80211_node *ni,
1874 struct ieee80211_tx_ampdu *tap)
1876 struct ieee80211com *ic = ni->ni_ic;
1878 int tid, dialogtoken;
1879 static int tokens = 0; /* XXX */
1882 if ((tap->txa_flags & IEEE80211_AGGR_SETUP) == 0) {
1883 /* do deferred setup of state */
1884 ampdu_tx_setup(tap);
1886 /* XXX hack for not doing proper locking */
1887 tap->txa_flags &= ~IEEE80211_AGGR_NAK;
1889 dialogtoken = (tokens+1) % 63; /* XXX */
1890 tid = WME_AC_TO_TID(tap->txa_ac);
1891 tap->txa_start = ni->ni_txseqs[tid];
1893 args[0] = dialogtoken;
1894 args[1] = IEEE80211_BAPS_POLICY_IMMEDIATE
1895 | SM(tid, IEEE80211_BAPS_TID)
1896 | SM(IEEE80211_AGGR_BAWMAX, IEEE80211_BAPS_BUFSIZ)
1898 args[2] = 0; /* batimeout */
1899 /* NB: do first so there's no race against reply */
1900 if (!ic->ic_addba_request(ni, tap, dialogtoken, args[1], args[2])) {
1901 /* unable to setup state, don't make request */
1902 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
1903 ni, "%s: could not setup BA stream for AC %d",
1904 __func__, tap->txa_ac);
1905 /* defer next try so we don't slam the driver with requests */
1906 tap->txa_attempts = ieee80211_addba_maxtries;
1907 /* NB: check in case driver wants to override */
1908 if (tap->txa_nextrequest <= ticks)
1909 tap->txa_nextrequest = ticks + ieee80211_addba_backoff;
1912 tokens = dialogtoken; /* allocate token */
1913 /* NB: after calling ic_addba_request so driver can set txa_start */
1914 args[3] = SM(tap->txa_start, IEEE80211_BASEQ_START)
1915 | SM(0, IEEE80211_BASEQ_FRAG)
1917 return ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1918 IEEE80211_ACTION_BA_ADDBA_REQUEST, args);
1922 * Terminate an AMPDU tx stream. State is reclaimed
1923 * and the peer notified with a DelBA Action frame.
1926 ieee80211_ampdu_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
1929 struct ieee80211com *ic = ni->ni_ic;
1930 struct ieee80211vap *vap = ni->ni_vap;
1934 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
1935 if (IEEE80211_AMPDU_RUNNING(tap)) {
1936 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1937 ni, "%s: stop BA stream for AC %d (reason %d)",
1938 __func__, tap->txa_ac, reason);
1939 vap->iv_stats.is_ampdu_stop++;
1941 ic->ic_addba_stop(ni, tap);
1942 args[0] = WME_AC_TO_TID(tap->txa_ac);
1943 args[1] = IEEE80211_DELBAPS_INIT;
1944 args[2] = reason; /* XXX reason code */
1945 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1946 IEEE80211_ACTION_BA_DELBA, args);
1948 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1949 ni, "%s: BA stream for AC %d not running (reason %d)",
1950 __func__, tap->txa_ac, reason);
1951 vap->iv_stats.is_ampdu_stop_failed++;
1956 bar_timeout(void *arg)
1958 struct ieee80211_tx_ampdu *tap = arg;
1959 struct ieee80211_node *ni = tap->txa_ni;
1961 KASSERT((tap->txa_flags & IEEE80211_AGGR_XCHGPEND) == 0,
1962 ("bar/addba collision, flags 0x%x", tap->txa_flags));
1964 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
1965 ni, "%s: tid %u flags 0x%x attempts %d", __func__,
1966 tap->txa_ac, tap->txa_flags, tap->txa_attempts);
1968 /* guard against race with bar_tx_complete */
1969 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) == 0)
1972 if (tap->txa_attempts >= ieee80211_bar_maxtries)
1973 ieee80211_ampdu_stop(ni, tap, IEEE80211_REASON_TIMEOUT);
1975 ieee80211_send_bar(ni, tap, tap->txa_seqpending);
1979 bar_start_timer(struct ieee80211_tx_ampdu *tap)
1981 callout_reset(&tap->txa_timer, ieee80211_bar_timeout, bar_timeout, tap);
1985 bar_stop_timer(struct ieee80211_tx_ampdu *tap)
1987 callout_stop(&tap->txa_timer);
1991 bar_tx_complete(struct ieee80211_node *ni, void *arg, int status)
1993 struct ieee80211_tx_ampdu *tap = arg;
1995 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
1996 ni, "%s: tid %u flags 0x%x pending %d status %d",
1997 __func__, tap->txa_ac, tap->txa_flags,
1998 callout_pending(&tap->txa_timer), status);
2001 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) &&
2002 callout_pending(&tap->txa_timer)) {
2003 struct ieee80211com *ic = ni->ni_ic;
2005 if (status) /* ACK'd */
2006 bar_stop_timer(tap);
2007 ic->ic_bar_response(ni, tap, status);
2008 /* NB: just let timer expire so we pace requests */
2013 ieee80211_bar_response(struct ieee80211_node *ni,
2014 struct ieee80211_tx_ampdu *tap, int status)
2017 if (status != 0) { /* got ACK */
2018 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N,
2019 ni, "BAR moves BA win <%u:%u> (%u frames) txseq %u tid %u",
2021 IEEE80211_SEQ_ADD(tap->txa_start, tap->txa_wnd-1),
2022 tap->txa_qframes, tap->txa_seqpending,
2023 WME_AC_TO_TID(tap->txa_ac));
2025 /* NB: timer already stopped in bar_tx_complete */
2026 tap->txa_start = tap->txa_seqpending;
2027 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
2032 * Transmit a BAR frame to the specified node. The
2033 * BAR contents are drawn from the supplied aggregation
2034 * state associated with the node.
2036 * NB: we only handle immediate ACK w/ compressed bitmap.
2039 ieee80211_send_bar(struct ieee80211_node *ni,
2040 struct ieee80211_tx_ampdu *tap, ieee80211_seq seq)
2042 #define senderr(_x, _v) do { vap->iv_stats._v++; ret = _x; goto bad; } while (0)
2043 struct ieee80211vap *vap = ni->ni_vap;
2044 struct ieee80211com *ic = ni->ni_ic;
2045 struct ieee80211_frame_bar *bar;
2047 uint16_t barctl, barseqctl;
2051 if ((tap->txa_flags & IEEE80211_AGGR_RUNNING) == 0) {
2052 /* no ADDBA response, should not happen */
2057 bar_stop_timer(tap);
2059 ieee80211_ref_node(ni);
2061 m = ieee80211_getmgtframe(&frm, ic->ic_headroom, sizeof(*bar));
2063 senderr(ENOMEM, is_tx_nobuf);
2065 if (!ieee80211_add_callback(m, bar_tx_complete, tap)) {
2067 senderr(ENOMEM, is_tx_nobuf); /* XXX */
2071 bar = mtod(m, struct ieee80211_frame_bar *);
2072 bar->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2073 IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_BAR;
2075 IEEE80211_ADDR_COPY(bar->i_ra, ni->ni_macaddr);
2076 IEEE80211_ADDR_COPY(bar->i_ta, vap->iv_myaddr);
2078 tid = WME_AC_TO_TID(tap->txa_ac);
2079 barctl = (tap->txa_flags & IEEE80211_AGGR_IMMEDIATE ?
2080 0 : IEEE80211_BAR_NOACK)
2081 | IEEE80211_BAR_COMP
2082 | SM(tid, IEEE80211_BAR_TID)
2084 barseqctl = SM(seq, IEEE80211_BAR_SEQ_START);
2085 /* NB: known to have proper alignment */
2086 bar->i_ctl = htole16(barctl);
2087 bar->i_seq = htole16(barseqctl);
2088 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_bar);
2090 M_WME_SETAC(m, WME_AC_VO);
2092 IEEE80211_NODE_STAT(ni, tx_mgmt); /* XXX tx_ctl? */
2095 /* init/bump attempts counter */
2096 if ((tap->txa_flags & IEEE80211_AGGR_BARPEND) == 0)
2097 tap->txa_attempts = 1;
2099 tap->txa_attempts++;
2100 tap->txa_seqpending = seq;
2101 tap->txa_flags |= IEEE80211_AGGR_BARPEND;
2103 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_11N,
2104 ni, "send BAR: tid %u ctl 0x%x start %u (attempt %d)",
2105 tid, barctl, seq, tap->txa_attempts);
2107 ret = ic->ic_raw_xmit(ni, m, NULL);
2109 /* xmit failed, clear state flag */
2110 tap->txa_flags &= ~IEEE80211_AGGR_BARPEND;
2113 /* XXX hack against tx complete happening before timer is started */
2114 if (tap->txa_flags & IEEE80211_AGGR_BARPEND)
2115 bar_start_timer(tap);
2118 ieee80211_free_node(ni);
2124 ht_action_output(struct ieee80211_node *ni, struct mbuf *m)
2126 struct ieee80211_bpf_params params;
2128 memset(¶ms, 0, sizeof(params));
2129 params.ibp_pri = WME_AC_VO;
2130 params.ibp_rate0 = ni->ni_txparms->mgmtrate;
2131 /* NB: we know all frames are unicast */
2132 params.ibp_try0 = ni->ni_txparms->maxretry;
2133 params.ibp_power = ni->ni_txpower;
2134 return ieee80211_mgmt_output(ni, m, IEEE80211_FC0_SUBTYPE_ACTION,
2138 #define ADDSHORT(frm, v) do { \
2139 frm[0] = (v) & 0xff; \
2140 frm[1] = (v) >> 8; \
2145 * Send an action management frame. The arguments are stuff
2146 * into a frame without inspection; the caller is assumed to
2147 * prepare them carefully (e.g. based on the aggregation state).
2150 ht_send_action_ba_addba(struct ieee80211_node *ni,
2151 int category, int action, void *arg0)
2153 struct ieee80211vap *vap = ni->ni_vap;
2154 struct ieee80211com *ic = ni->ni_ic;
2155 uint16_t *args = arg0;
2159 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2160 "send ADDBA %s: dialogtoken %d "
2161 "baparamset 0x%x (tid %d) batimeout 0x%x baseqctl 0x%x",
2162 (action == IEEE80211_ACTION_BA_ADDBA_REQUEST) ?
2163 "request" : "response",
2164 args[0], args[1], MS(args[1], IEEE80211_BAPS_TID),
2167 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2168 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2169 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2170 ieee80211_ref_node(ni);
2172 m = ieee80211_getmgtframe(&frm,
2173 ic->ic_headroom + sizeof(struct ieee80211_frame),
2174 sizeof(uint16_t) /* action+category */
2175 /* XXX may action payload */
2176 + sizeof(struct ieee80211_action_ba_addbaresponse)
2181 *frm++ = args[0]; /* dialog token */
2182 ADDSHORT(frm, args[1]); /* baparamset */
2183 ADDSHORT(frm, args[2]); /* batimeout */
2184 if (action == IEEE80211_ACTION_BA_ADDBA_REQUEST)
2185 ADDSHORT(frm, args[3]); /* baseqctl */
2186 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2187 return ht_action_output(ni, m);
2189 vap->iv_stats.is_tx_nobuf++;
2190 ieee80211_free_node(ni);
2196 ht_send_action_ba_delba(struct ieee80211_node *ni,
2197 int category, int action, void *arg0)
2199 struct ieee80211vap *vap = ni->ni_vap;
2200 struct ieee80211com *ic = ni->ni_ic;
2201 uint16_t *args = arg0;
2203 uint16_t baparamset;
2206 baparamset = SM(args[0], IEEE80211_DELBAPS_TID)
2209 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2210 "send DELBA action: tid %d, initiator %d reason %d",
2211 args[0], args[1], args[2]);
2213 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2214 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2215 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2216 ieee80211_ref_node(ni);
2218 m = ieee80211_getmgtframe(&frm,
2219 ic->ic_headroom + sizeof(struct ieee80211_frame),
2220 sizeof(uint16_t) /* action+category */
2221 /* XXX may action payload */
2222 + sizeof(struct ieee80211_action_ba_addbaresponse)
2227 ADDSHORT(frm, baparamset);
2228 ADDSHORT(frm, args[2]); /* reason code */
2229 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2230 return ht_action_output(ni, m);
2232 vap->iv_stats.is_tx_nobuf++;
2233 ieee80211_free_node(ni);
2239 ht_send_action_ht_txchwidth(struct ieee80211_node *ni,
2240 int category, int action, void *arg0)
2242 struct ieee80211vap *vap = ni->ni_vap;
2243 struct ieee80211com *ic = ni->ni_ic;
2247 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
2248 "send HT txchwidth: width %d",
2249 IEEE80211_IS_CHAN_HT40(ni->ni_chan) ? 40 : 20);
2251 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2252 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__,
2253 ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1);
2254 ieee80211_ref_node(ni);
2256 m = ieee80211_getmgtframe(&frm,
2257 ic->ic_headroom + sizeof(struct ieee80211_frame),
2258 sizeof(uint16_t) /* action+category */
2259 /* XXX may action payload */
2260 + sizeof(struct ieee80211_action_ba_addbaresponse)
2265 *frm++ = IEEE80211_IS_CHAN_HT40(ni->ni_chan) ?
2266 IEEE80211_A_HT_TXCHWIDTH_2040 :
2267 IEEE80211_A_HT_TXCHWIDTH_20;
2268 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2269 return ht_action_output(ni, m);
2271 vap->iv_stats.is_tx_nobuf++;
2272 ieee80211_free_node(ni);
2279 * Construct the MCS bit mask for inclusion
2280 * in an HT information element.
2283 ieee80211_set_htrates(uint8_t *frm, const struct ieee80211_htrateset *rs)
2287 for (i = 0; i < rs->rs_nrates; i++) {
2288 int r = rs->rs_rates[i] & IEEE80211_RATE_VAL;
2289 if (r < IEEE80211_HTRATE_MAXSIZE) { /* XXX? */
2290 /* NB: this assumes a particular implementation */
2297 * Add body of an HTCAP information element.
2300 ieee80211_add_htcap_body(uint8_t *frm, struct ieee80211_node *ni)
2302 #define ADDSHORT(frm, v) do { \
2303 frm[0] = (v) & 0xff; \
2304 frm[1] = (v) >> 8; \
2307 struct ieee80211vap *vap = ni->ni_vap;
2311 /* HT capabilities */
2312 caps = vap->iv_htcaps & 0xffff;
2314 * Note channel width depends on whether we are operating as
2315 * a sta or not. When operating as a sta we are generating
2316 * a request based on our desired configuration. Otherwise
2317 * we are operational and the channel attributes identify
2318 * how we've been setup (which might be different if a fixed
2319 * channel is specified).
2321 if (vap->iv_opmode == IEEE80211_M_STA) {
2322 /* override 20/40 use based on config */
2323 if (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)
2324 caps |= IEEE80211_HTCAP_CHWIDTH40;
2326 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
2327 /* use advertised setting (XXX locally constraint) */
2328 rxmax = MS(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU);
2329 density = MS(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY);
2331 /* override 20/40 use based on current channel */
2332 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
2333 caps |= IEEE80211_HTCAP_CHWIDTH40;
2335 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
2336 rxmax = vap->iv_ampdu_rxmax;
2337 density = vap->iv_ampdu_density;
2339 /* adjust short GI based on channel and config */
2340 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20) == 0)
2341 caps &= ~IEEE80211_HTCAP_SHORTGI20;
2342 if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40) == 0 ||
2343 (caps & IEEE80211_HTCAP_CHWIDTH40) == 0)
2344 caps &= ~IEEE80211_HTCAP_SHORTGI40;
2345 ADDSHORT(frm, caps);
2348 *frm = SM(rxmax, IEEE80211_HTCAP_MAXRXAMPDU)
2349 | SM(density, IEEE80211_HTCAP_MPDUDENSITY)
2353 /* pre-zero remainder of ie */
2354 memset(frm, 0, sizeof(struct ieee80211_ie_htcap) -
2355 __offsetof(struct ieee80211_ie_htcap, hc_mcsset));
2357 /* supported MCS set */
2359 * XXX it would better to get the rate set from ni_htrates
2360 * so we can restrict it but for sta mode ni_htrates isn't
2361 * setup when we're called to form an AssocReq frame so for
2362 * now we're restricted to the default HT rate set.
2364 ieee80211_set_htrates(frm, &ieee80211_rateset_11n);
2366 frm += sizeof(struct ieee80211_ie_htcap) -
2367 __offsetof(struct ieee80211_ie_htcap, hc_mcsset);
2373 * Add 802.11n HT capabilities information element
2376 ieee80211_add_htcap(uint8_t *frm, struct ieee80211_node *ni)
2378 frm[0] = IEEE80211_ELEMID_HTCAP;
2379 frm[1] = sizeof(struct ieee80211_ie_htcap) - 2;
2380 return ieee80211_add_htcap_body(frm + 2, ni);
2384 * Add Broadcom OUI wrapped standard HTCAP ie; this is
2385 * used for compatibility w/ pre-draft implementations.
2388 ieee80211_add_htcap_vendor(uint8_t *frm, struct ieee80211_node *ni)
2390 frm[0] = IEEE80211_ELEMID_VENDOR;
2391 frm[1] = 4 + sizeof(struct ieee80211_ie_htcap) - 2;
2392 frm[2] = (BCM_OUI >> 0) & 0xff;
2393 frm[3] = (BCM_OUI >> 8) & 0xff;
2394 frm[4] = (BCM_OUI >> 16) & 0xff;
2395 frm[5] = BCM_OUI_HTCAP;
2396 return ieee80211_add_htcap_body(frm + 6, ni);
2400 * Construct the MCS bit mask of basic rates
2401 * for inclusion in an HT information element.
2404 ieee80211_set_basic_htrates(uint8_t *frm, const struct ieee80211_htrateset *rs)
2408 for (i = 0; i < rs->rs_nrates; i++) {
2409 int r = rs->rs_rates[i] & IEEE80211_RATE_VAL;
2410 if ((rs->rs_rates[i] & IEEE80211_RATE_BASIC) &&
2411 r < IEEE80211_HTRATE_MAXSIZE) {
2412 /* NB: this assumes a particular implementation */
2419 * Update the HTINFO ie for a beacon frame.
2422 ieee80211_ht_update_beacon(struct ieee80211vap *vap,
2423 struct ieee80211_beacon_offsets *bo)
2425 #define PROTMODE (IEEE80211_HTINFO_OPMODE|IEEE80211_HTINFO_NONHT_PRESENT)
2426 const struct ieee80211_channel *bsschan = vap->iv_bss->ni_chan;
2427 struct ieee80211com *ic = vap->iv_ic;
2428 struct ieee80211_ie_htinfo *ht =
2429 (struct ieee80211_ie_htinfo *) bo->bo_htinfo;
2431 /* XXX only update on channel change */
2432 ht->hi_ctrlchannel = ieee80211_chan2ieee(ic, bsschan);
2433 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
2434 ht->hi_byte1 = IEEE80211_HTINFO_RIFSMODE_PERM;
2436 ht->hi_byte1 = IEEE80211_HTINFO_RIFSMODE_PROH;
2437 if (IEEE80211_IS_CHAN_HT40U(bsschan))
2438 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_ABOVE;
2439 else if (IEEE80211_IS_CHAN_HT40D(bsschan))
2440 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_BELOW;
2442 ht->hi_byte1 |= IEEE80211_HTINFO_2NDCHAN_NONE;
2443 if (IEEE80211_IS_CHAN_HT40(bsschan))
2444 ht->hi_byte1 |= IEEE80211_HTINFO_TXWIDTH_2040;
2446 /* protection mode */
2447 ht->hi_byte2 = (ht->hi_byte2 &~ PROTMODE) | ic->ic_curhtprotmode;
2449 /* XXX propagate to vendor ie's */
2454 * Add body of an HTINFO information element.
2456 * NB: We don't use struct ieee80211_ie_htinfo because we can
2457 * be called to fillin both a standard ie and a compat ie that
2458 * has a vendor OUI at the front.
2461 ieee80211_add_htinfo_body(uint8_t *frm, struct ieee80211_node *ni)
2463 struct ieee80211vap *vap = ni->ni_vap;
2464 struct ieee80211com *ic = ni->ni_ic;
2466 /* pre-zero remainder of ie */
2467 memset(frm, 0, sizeof(struct ieee80211_ie_htinfo) - 2);
2469 /* primary/control channel center */
2470 *frm++ = ieee80211_chan2ieee(ic, ni->ni_chan);
2472 if (vap->iv_flags_ht & IEEE80211_FHT_RIFS)
2473 frm[0] = IEEE80211_HTINFO_RIFSMODE_PERM;
2475 frm[0] = IEEE80211_HTINFO_RIFSMODE_PROH;
2476 if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
2477 frm[0] |= IEEE80211_HTINFO_2NDCHAN_ABOVE;
2478 else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
2479 frm[0] |= IEEE80211_HTINFO_2NDCHAN_BELOW;
2481 frm[0] |= IEEE80211_HTINFO_2NDCHAN_NONE;
2482 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
2483 frm[0] |= IEEE80211_HTINFO_TXWIDTH_2040;
2485 frm[1] = ic->ic_curhtprotmode;
2490 ieee80211_set_basic_htrates(frm, &ni->ni_htrates);
2491 frm += sizeof(struct ieee80211_ie_htinfo) -
2492 __offsetof(struct ieee80211_ie_htinfo, hi_basicmcsset);
2497 * Add 802.11n HT information information element.
2500 ieee80211_add_htinfo(uint8_t *frm, struct ieee80211_node *ni)
2502 frm[0] = IEEE80211_ELEMID_HTINFO;
2503 frm[1] = sizeof(struct ieee80211_ie_htinfo) - 2;
2504 return ieee80211_add_htinfo_body(frm + 2, ni);
2508 * Add Broadcom OUI wrapped standard HTINFO ie; this is
2509 * used for compatibility w/ pre-draft implementations.
2512 ieee80211_add_htinfo_vendor(uint8_t *frm, struct ieee80211_node *ni)
2514 frm[0] = IEEE80211_ELEMID_VENDOR;
2515 frm[1] = 4 + sizeof(struct ieee80211_ie_htinfo) - 2;
2516 frm[2] = (BCM_OUI >> 0) & 0xff;
2517 frm[3] = (BCM_OUI >> 8) & 0xff;
2518 frm[4] = (BCM_OUI >> 16) & 0xff;
2519 frm[5] = BCM_OUI_HTINFO;
2520 return ieee80211_add_htinfo_body(frm + 6, ni);