Deleted Added
full compact
ieee80211_ht.c (172226) ieee80211_ht.c (173273)
1/*-
2 * Copyright (c) 2007 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

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.
24 */
25
26#include <sys/cdefs.h>
27#ifdef __FreeBSD__
1/*-
2 * Copyright (c) 2007 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

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.
24 */
25
26#include <sys/cdefs.h>
27#ifdef __FreeBSD__
28__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_ht.c 172226 2007-09-18 20:46:36Z sam $");
28__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_ht.c 173273 2007-11-02 05:22:25Z sam $");
29#endif
30
31/*
32 * IEEE 802.11n protocol support.
33 */
34
35#include "opt_inet.h"
36

--- 37 unchanged lines hidden (view full) ---

74static const struct ieee80211_htrateset ieee80211_rateset_11n =
75 { 16, {
76 /* MCS: 6.5 13 19.5 26 39 52 58.5 65 13 26 */
77 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
78 /* 39 52 78 104 117, 130 */
79 10, 11, 12, 13, 14, 15 }
80 };
81
29#endif
30
31/*
32 * IEEE 802.11n protocol support.
33 */
34
35#include "opt_inet.h"
36

--- 37 unchanged lines hidden (view full) ---

74static const struct ieee80211_htrateset ieee80211_rateset_11n =
75 { 16, {
76 /* MCS: 6.5 13 19.5 26 39 52 58.5 65 13 26 */
77 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
78 /* 39 52 78 104 117, 130 */
79 10, 11, 12, 13, 14, 15 }
80 };
81
82#ifdef IEEE80211_AMPDU_AGE
83/* XXX public for sysctl hookup */
84int ieee80211_ampdu_age = -1; /* threshold for ampdu reorder q (ms) */
85#endif
86int ieee80211_recv_bar_ena = 1;
87
82#define IEEE80211_AGGR_TIMEOUT msecs_to_ticks(250)
83#define IEEE80211_AGGR_MINRETRY msecs_to_ticks(10*1000)
84#define IEEE80211_AGGR_MAXTRIES 3
85
86static int ieee80211_addba_request(struct ieee80211_node *ni,
87 struct ieee80211_tx_ampdu *tap,
88 int dialogtoken, int baparamset, int batimeout);
89static int ieee80211_addba_response(struct ieee80211_node *ni,
90 struct ieee80211_tx_ampdu *tap,
91 int code, int baparamset, int batimeout);
92static void ieee80211_addba_stop(struct ieee80211_node *ni,
93 struct ieee80211_tx_ampdu *tap);
94static void ieee80211_aggr_recv_action(struct ieee80211_node *ni,
95 const uint8_t *frm, const uint8_t *efrm);
96
97void
98ieee80211_ht_attach(struct ieee80211com *ic)
99{
88#define IEEE80211_AGGR_TIMEOUT msecs_to_ticks(250)
89#define IEEE80211_AGGR_MINRETRY msecs_to_ticks(10*1000)
90#define IEEE80211_AGGR_MAXTRIES 3
91
92static int ieee80211_addba_request(struct ieee80211_node *ni,
93 struct ieee80211_tx_ampdu *tap,
94 int dialogtoken, int baparamset, int batimeout);
95static int ieee80211_addba_response(struct ieee80211_node *ni,
96 struct ieee80211_tx_ampdu *tap,
97 int code, int baparamset, int batimeout);
98static void ieee80211_addba_stop(struct ieee80211_node *ni,
99 struct ieee80211_tx_ampdu *tap);
100static void ieee80211_aggr_recv_action(struct ieee80211_node *ni,
101 const uint8_t *frm, const uint8_t *efrm);
102
103void
104ieee80211_ht_attach(struct ieee80211com *ic)
105{
106#ifdef IEEE80211_AMPDU_AGE
107 if (ieee80211_ampdu_age == -1)
108 ieee80211_ampdu_age = msecs_to_ticks(500);
109#endif
100
110
101 ic->ic_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_8K;
102 ic->ic_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_NA;
103 ic->ic_ampdu_limit = ic->ic_ampdu_rxmax;
104
105 ic->ic_amsdu_limit = IEEE80211_HTCAP_MAXAMSDU_3839;
106
107 /* setup default aggregation policy */
108 ic->ic_recv_action = ieee80211_aggr_recv_action;
109 ic->ic_send_action = ieee80211_send_action;
110 ic->ic_addba_request = ieee80211_addba_request;
111 ic->ic_addba_response = ieee80211_addba_response;
112 ic->ic_addba_stop = ieee80211_addba_stop;
113
111 /* setup default aggregation policy */
112 ic->ic_recv_action = ieee80211_aggr_recv_action;
113 ic->ic_send_action = ieee80211_send_action;
114 ic->ic_addba_request = ieee80211_addba_request;
115 ic->ic_addba_response = ieee80211_addba_response;
116 ic->ic_addba_stop = ieee80211_addba_stop;
117
114 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NA) ||
115 isset(ic->ic_modecaps, IEEE80211_MODE_11NG)) {
118 ic->ic_htprotmode = IEEE80211_PROT_RTSCTS;
119 ic->ic_curhtprotmode = IEEE80211_HTINFO_OPMODE_PURE;
120
121 /* XXX get from driver */
122 ic->ic_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_8K;
123 ic->ic_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_NA;
124 ic->ic_ampdu_limit = ic->ic_ampdu_rxmax;
125 ic->ic_amsdu_limit = IEEE80211_HTCAP_MAXAMSDU_3839;
126
127 if (ic->ic_htcaps & IEEE80211_HTC_HT) {
116 /*
128 /*
117 * There are HT channels in the channel list; enable
118 * all HT-related facilities by default.
129 * Device is HT capable; enable all HT-related
130 * facilities by default.
119 * XXX these choices may be too aggressive.
120 */
121 ic->ic_flags_ext |= IEEE80211_FEXT_HT
122 | IEEE80211_FEXT_HTCOMPAT
123 ;
124 if (ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI20)
125 ic->ic_flags_ext |= IEEE80211_FEXT_SHORTGI20;
131 * XXX these choices may be too aggressive.
132 */
133 ic->ic_flags_ext |= IEEE80211_FEXT_HT
134 | IEEE80211_FEXT_HTCOMPAT
135 ;
136 if (ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI20)
137 ic->ic_flags_ext |= IEEE80211_FEXT_SHORTGI20;
126 /* XXX infer from channel list */
138 /* XXX infer from channel list? */
127 if (ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
128 ic->ic_flags_ext |= IEEE80211_FEXT_USEHT40;
129 if (ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI40)
130 ic->ic_flags_ext |= IEEE80211_FEXT_SHORTGI40;
131 }
132 /* NB: A-MPDU and A-MSDU rx are mandated, these are tx only */
133 ic->ic_flags_ext |= IEEE80211_FEXT_AMPDU_RX;
134 if (ic->ic_htcaps & IEEE80211_HTC_AMPDU)
135 ic->ic_flags_ext |= IEEE80211_FEXT_AMPDU_TX;
136 ic->ic_flags_ext |= IEEE80211_FEXT_AMSDU_RX;
137 if (ic->ic_htcaps & IEEE80211_HTC_AMSDU)
138 ic->ic_flags_ext |= IEEE80211_FEXT_AMSDU_TX;
139 if (ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
140 ic->ic_flags_ext |= IEEE80211_FEXT_USEHT40;
141 if (ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI40)
142 ic->ic_flags_ext |= IEEE80211_FEXT_SHORTGI40;
143 }
144 /* NB: A-MPDU and A-MSDU rx are mandated, these are tx only */
145 ic->ic_flags_ext |= IEEE80211_FEXT_AMPDU_RX;
146 if (ic->ic_htcaps & IEEE80211_HTC_AMPDU)
147 ic->ic_flags_ext |= IEEE80211_FEXT_AMPDU_TX;
148 ic->ic_flags_ext |= IEEE80211_FEXT_AMSDU_RX;
149 if (ic->ic_htcaps & IEEE80211_HTC_AMSDU)
150 ic->ic_flags_ext |= IEEE80211_FEXT_AMSDU_TX;
139
140 ic->ic_curhtprotmode = IEEE80211_HTINFO_OPMODE_PURE;
141 }
142}
143
144void
145ieee80211_ht_detach(struct ieee80211com *ic)
146{
147}
148

--- 25 unchanged lines hidden (view full) ---

174 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NG))
175 ht_announce(ic, IEEE80211_MODE_11NG, &ieee80211_rateset_11n);
176}
177
178const struct ieee80211_htrateset *
179ieee80211_get_suphtrates(struct ieee80211com *ic,
180 const struct ieee80211_channel *c)
181{
151 }
152}
153
154void
155ieee80211_ht_detach(struct ieee80211com *ic)
156{
157}
158

--- 25 unchanged lines hidden (view full) ---

184 if (isset(ic->ic_modecaps, IEEE80211_MODE_11NG))
185 ht_announce(ic, IEEE80211_MODE_11NG, &ieee80211_rateset_11n);
186}
187
188const struct ieee80211_htrateset *
189ieee80211_get_suphtrates(struct ieee80211com *ic,
190 const struct ieee80211_channel *c)
191{
182 if (IEEE80211_IS_CHAN_HT(c))
183 return &ieee80211_rateset_11n;
184 /* XXX what's the right thing to do here? */
185 return (const struct ieee80211_htrateset *)
186 ieee80211_get_suprates(ic, c);
192 return &ieee80211_rateset_11n;
187}
188
189/*
190 * Receive processing.
191 */
192
193/*
194 * Decap the encapsulated A-MSDU frames and dispatch all but

--- 55 unchanged lines hidden (view full) ---

250 */
251static void
252ampdu_rx_start(struct ieee80211_rx_ampdu *rap, int bufsiz, int start)
253{
254 memset(rap, 0, sizeof(*rap));
255 rap->rxa_wnd = (bufsiz == 0) ?
256 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
257 rap->rxa_start = start;
193}
194
195/*
196 * Receive processing.
197 */
198
199/*
200 * Decap the encapsulated A-MSDU frames and dispatch all but

--- 55 unchanged lines hidden (view full) ---

256 */
257static void
258ampdu_rx_start(struct ieee80211_rx_ampdu *rap, int bufsiz, int start)
259{
260 memset(rap, 0, sizeof(*rap));
261 rap->rxa_wnd = (bufsiz == 0) ?
262 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
263 rap->rxa_start = start;
258 rap->rxa_nxt = rap->rxa_start;
259 rap->rxa_flags |= IEEE80211_AGGR_XCHGPEND;
260}
261
262/*
263 * Purge all frames in the A-MPDU re-order queue.
264 */
265static void
266ampdu_rx_purge(struct ieee80211_rx_ampdu *rap)

--- 62 unchanged lines hidden (view full) ---

329 break;
330 rap->rxa_m[i] = NULL;
331 rap->rxa_qbytes -= m->m_pkthdr.len;
332 rap->rxa_qframes--;
333
334 ampdu_dispatch(ni, m);
335 }
336 /*
264 rap->rxa_flags |= IEEE80211_AGGR_XCHGPEND;
265}
266
267/*
268 * Purge all frames in the A-MPDU re-order queue.
269 */
270static void
271ampdu_rx_purge(struct ieee80211_rx_ampdu *rap)

--- 62 unchanged lines hidden (view full) ---

334 break;
335 rap->rxa_m[i] = NULL;
336 rap->rxa_qbytes -= m->m_pkthdr.len;
337 rap->rxa_qframes--;
338
339 ampdu_dispatch(ni, m);
340 }
341 /*
337 * Adjust the start of the BA window to
338 * reflect the frames just dispatched.
339 */
340 rap->rxa_start = IEEE80211_SEQ_ADD(rap->rxa_start, i);
341 rap->rxa_nxt = rap->rxa_start;
342 ic->ic_stats.is_ampdu_rx_oor += i;
343 /*
344 * If frames remain, copy the mbuf pointers down so
345 * they correspond to the offsets in the new window.
346 */
347 if (rap->rxa_qframes != 0) {
348 int n = rap->rxa_qframes, j;
349 for (j = i+1; j < rap->rxa_wnd; j++) {
350 if (rap->rxa_m[j] != NULL) {
351 rap->rxa_m[j-i] = rap->rxa_m[j];
352 rap->rxa_m[j] = NULL;
353 if (--n == 0)
354 break;
355 }
356 }
357 KASSERT(n == 0, ("lost %d frames", n));
358 ic->ic_stats.is_ampdu_rx_copy += rap->rxa_qframes;
359 }
342 * If frames remain, copy the mbuf pointers down so
343 * they correspond to the offsets in the new window.
344 */
345 if (rap->rxa_qframes != 0) {
346 int n = rap->rxa_qframes, j;
347 for (j = i+1; j < rap->rxa_wnd; j++) {
348 if (rap->rxa_m[j] != NULL) {
349 rap->rxa_m[j-i] = rap->rxa_m[j];
350 rap->rxa_m[j] = NULL;
351 if (--n == 0)
352 break;
353 }
354 }
355 KASSERT(n == 0, ("lost %d frames", n));
356 ic->ic_stats.is_ampdu_rx_copy += rap->rxa_qframes;
357 }
358 /*
359 * Adjust the start of the BA window to
360 * reflect the frames just dispatched.
361 */
362 rap->rxa_start = IEEE80211_SEQ_ADD(rap->rxa_start, i);
363 ic->ic_stats.is_ampdu_rx_oor += i;
360}
361
364}
365
366#ifdef IEEE80211_AMPDU_AGE
362/*
367/*
363 * Dispatch all frames in the A-MPDU
364 * re-order queue up to the specified slot.
368 * Dispatch all frames in the A-MPDU re-order queue.
365 */
366static void
369 */
370static void
367ampdu_rx_flush(struct ieee80211_node *ni,
368 struct ieee80211_rx_ampdu *rap, int limit)
371ampdu_rx_flush(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
369{
372{
373 struct ieee80211com *ic = ni->ni_ic;
370 struct mbuf *m;
371 int i;
372
374 struct mbuf *m;
375 int i;
376
373 for (i = 0; i < limit; i++) {
377 for (i = 0; i < rap->rxa_wnd; i++) {
374 m = rap->rxa_m[i];
375 if (m == NULL)
376 continue;
377 rap->rxa_m[i] = NULL;
378 rap->rxa_qbytes -= m->m_pkthdr.len;
378 m = rap->rxa_m[i];
379 if (m == NULL)
380 continue;
381 rap->rxa_m[i] = NULL;
382 rap->rxa_qbytes -= m->m_pkthdr.len;
383 rap->rxa_qframes--;
384 ic->ic_stats.is_ampdu_rx_oor++;
385
379 ampdu_dispatch(ni, m);
386 ampdu_dispatch(ni, m);
380 if (--rap->rxa_qframes == 0)
387 if (rap->rxa_qframes == 0)
381 break;
382 }
383}
388 break;
389 }
390}
391#endif /* IEEE80211_AMPDU_AGE */
384
385/*
392
393/*
394 * Dispatch all frames in the A-MPDU re-order queue
395 * preceding the specified sequence number. This logic
396 * handles window moves due to a received MSDU or BAR.
397 */
398static void
399ampdu_rx_flush_upto(struct ieee80211_node *ni,
400 struct ieee80211_rx_ampdu *rap, ieee80211_seq winstart)
401{
402 struct ieee80211com *ic = ni->ni_ic;
403 struct mbuf *m;
404 ieee80211_seq seqno;
405 int i;
406
407 /*
408 * Flush any complete MSDU's with a sequence number lower
409 * than winstart. Gaps may exist. Note that we may actually
410 * dispatch frames past winstart if a run continues; this is
411 * an optimization that avoids having to do a separate pass
412 * to dispatch frames after moving the BA window start.
413 */
414 seqno = rap->rxa_start;
415 for (i = 0; i < rap->rxa_wnd; i++) {
416 m = rap->rxa_m[i];
417 if (m != NULL) {
418 rap->rxa_m[i] = NULL;
419 rap->rxa_qbytes -= m->m_pkthdr.len;
420 rap->rxa_qframes--;
421 ic->ic_stats.is_ampdu_rx_oor++;
422
423 ampdu_dispatch(ni, m);
424 } else {
425 if (!IEEE80211_SEQ_BA_BEFORE(seqno, winstart))
426 break;
427 }
428 seqno = IEEE80211_SEQ_INC(seqno);
429 }
430 /*
431 * If frames remain, copy the mbuf pointers down so
432 * they correspond to the offsets in the new window.
433 */
434 if (rap->rxa_qframes != 0) {
435 int n = rap->rxa_qframes, j;
436 for (j = i+1; j < rap->rxa_wnd; j++) {
437 if (rap->rxa_m[j] != NULL) {
438 rap->rxa_m[j-i] = rap->rxa_m[j];
439 rap->rxa_m[j] = NULL;
440 if (--n == 0)
441 break;
442 }
443 }
444 KASSERT(n == 0, ("%s: lost %d frames, qframes %d off %d "
445 "BA win <%d:%d> winstart %d",
446 __func__, n, rap->rxa_qframes, i, rap->rxa_start,
447 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
448 winstart));
449 ic->ic_stats.is_ampdu_rx_copy += rap->rxa_qframes;
450 }
451 /*
452 * Move the start of the BA window; we use the
453 * sequence number of the last MSDU that was
454 * passed up the stack+1 or winstart if stopped on
455 * a gap in the reorder buffer.
456 */
457 rap->rxa_start = seqno;
458}
459
460/*
386 * Process a received QoS data frame for an HT station. Handle
387 * A-MPDU reordering: if this frame is received out of order
388 * and falls within the BA window hold onto it. Otherwise if
461 * Process a received QoS data frame for an HT station. Handle
462 * A-MPDU reordering: if this frame is received out of order
463 * and falls within the BA window hold onto it. Otherwise if
389 * this frame completes a run flush any pending frames. We
464 * this frame completes a run, flush any pending frames. We
390 * return 1 if the frame is consumed. A 0 is returned if
391 * the frame should be processed normally by the caller.
392 */
393int
394ieee80211_ampdu_reorder(struct ieee80211_node *ni, struct mbuf *m)
395{
396#define IEEE80211_FC0_QOSDATA \
397 (IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_VERSION_0)
465 * return 1 if the frame is consumed. A 0 is returned if
466 * the frame should be processed normally by the caller.
467 */
468int
469ieee80211_ampdu_reorder(struct ieee80211_node *ni, struct mbuf *m)
470{
471#define IEEE80211_FC0_QOSDATA \
472 (IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_VERSION_0)
473#define PROCESS 0 /* caller should process frame */
474#define CONSUMED 1 /* frame consumed, caller does nothing */
398 struct ieee80211com *ic = ni->ni_ic;
399 struct ieee80211_qosframe *wh;
400 struct ieee80211_rx_ampdu *rap;
401 ieee80211_seq rxseq;
402 uint8_t tid;
403 int off;
404
405 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
406
407 /* NB: m_len known to be sufficient */
408 wh = mtod(m, struct ieee80211_qosframe *);
409 KASSERT(wh->i_fc[0] == IEEE80211_FC0_QOSDATA, ("not QoS data"));
410
475 struct ieee80211com *ic = ni->ni_ic;
476 struct ieee80211_qosframe *wh;
477 struct ieee80211_rx_ampdu *rap;
478 ieee80211_seq rxseq;
479 uint8_t tid;
480 int off;
481
482 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT sta"));
483
484 /* NB: m_len known to be sufficient */
485 wh = mtod(m, struct ieee80211_qosframe *);
486 KASSERT(wh->i_fc[0] == IEEE80211_FC0_QOSDATA, ("not QoS data"));
487
411 /* XXX 4-address frame */
412 tid = wh->i_qos[0] & IEEE80211_QOS_TID;
488 if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
489 tid = ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0];
490 else
491 tid = wh->i_qos[0];
492 tid &= IEEE80211_QOS_TID;
413 rap = &ni->ni_rx_ampdu[tid];
414 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
415 /*
416 * No ADDBA request yet, don't touch.
417 */
493 rap = &ni->ni_rx_ampdu[tid];
494 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
495 /*
496 * No ADDBA request yet, don't touch.
497 */
418 return 0;
498 return PROCESS;
419 }
420 rxseq = le16toh(*(uint16_t *)wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;
499 }
500 rxseq = le16toh(*(uint16_t *)wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;
501 rap->rxa_nframes++;
502again:
421 if (rxseq == rap->rxa_start) {
422 /*
423 * First frame in window.
424 */
425 if (rap->rxa_qframes != 0) {
426 /*
427 * Dispatch as many packets as we can.
428 */
429 KASSERT(rap->rxa_m[0] == NULL, ("unexpected dup"));
430 ampdu_dispatch(ni, m);
431 ampdu_rx_dispatch(rap, ni);
503 if (rxseq == rap->rxa_start) {
504 /*
505 * First frame in window.
506 */
507 if (rap->rxa_qframes != 0) {
508 /*
509 * Dispatch as many packets as we can.
510 */
511 KASSERT(rap->rxa_m[0] == NULL, ("unexpected dup"));
512 ampdu_dispatch(ni, m);
513 ampdu_rx_dispatch(rap, ni);
432 return 1; /* NB: consumed */
514 return CONSUMED;
433 } else {
434 /*
435 * In order; advance window and notify
436 * caller to dispatch directly.
437 */
438 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
515 } else {
516 /*
517 * In order; advance window and notify
518 * caller to dispatch directly.
519 */
520 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
439 rap->rxa_nxt = rap->rxa_start;
440 return 0; /* NB: process packet */
521 return PROCESS;
441 }
442 }
443 /*
522 }
523 }
524 /*
444 * This packet is out of order; store it
445 * if it's in the BA window.
525 * Frame is out of order; store if in the BA window.
446 */
447 /* calculate offset in BA window */
448 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
526 */
527 /* calculate offset in BA window */
528 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
449 if (off >= rap->rxa_wnd) {
529 if (off < rap->rxa_wnd) {
450 /*
530 /*
451 * Outside the window, clear the q and start over.
531 * Common case (hopefully): in the BA window.
532 * Sec 9.10.7.6 a) (D2.04 p.118 line 47)
533 */
534#ifdef IEEE80211_AMPDU_AGE
535 /*
536 * Check for frames sitting too long in the reorder queue.
537 * This should only ever happen if frames are not delivered
538 * without the sender otherwise notifying us (e.g. with a
539 * BAR to move the window). Typically this happens because
540 * of vendor bugs that cause the sequence number to jump.
541 * When this happens we get a gap in the reorder queue that
542 * leaves frame sitting on the queue until they get pushed
543 * out due to window moves. When the vendor does not send
544 * BAR this move only happens due to explicit packet sends
452 *
545 *
453 * NB: this handles the case where rxseq is before
454 * rxa_start because our max BA window is 64
455 * and the sequence number range is 4096.
546 * NB: we only track the time of the oldest frame in the
547 * reorder q; this means that if we flush we might push
548 * frames that still "new"; if this happens then subsequent
549 * frames will result in BA window moves which cost something
550 * but is still better than a big throughput dip.
456 */
551 */
457 IEEE80211_NOTE(ic, IEEE80211_MSG_11N, ni,
458 "flush BA win <%u:%u> (%u frames) rxseq %u tid %u",
459 rap->rxa_start,
460 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd),
461 rap->rxa_qframes, rxseq, tid);
462
463 if (rap->rxa_qframes != 0) {
552 if (rap->rxa_qframes != 0) {
464 ic->ic_stats.is_ampdu_rx_oor += rap->rxa_qframes;
465 ampdu_rx_flush(ni, rap, rap->rxa_wnd);
466 KASSERT(rap->rxa_qbytes == 0 && rap->rxa_qframes == 0,
467 ("lost %u data, %u frames on ampdu rx q",
468 rap->rxa_qbytes, rap->rxa_qframes));
469 }
470 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
471 rap->rxa_nxt = rap->rxa_start;
472 return 0; /* NB: process packet */
473 }
474 if (rap->rxa_qframes != 0) {
475#if 0
476 /* XXX honor batimeout? */
477 if (ticks - mn->mn_age[tid] > 50) {
553 /* XXX honor batimeout? */
554 if (ticks - rap->rxa_age > ieee80211_ampdu_age) {
555 /*
556 * Too long since we received the first
557 * frame; flush the reorder buffer.
558 */
559 if (rap->rxa_qframes != 0) {
560 ic->ic_stats.is_ampdu_rx_age +=
561 rap->rxa_qframes;
562 ampdu_rx_flush(ni, rap);
563 }
564 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
565 return PROCESS;
566 }
567 } else {
478 /*
568 /*
479 * Too long since we received the first frame; flush.
569 * First frame, start aging timer.
480 */
570 */
481 if (rap->rxa_qframes != 0) {
482 ic->ic_stats.is_ampdu_rx_oor +=
483 rap->rxa_qframes;
484 ampdu_rx_flush(ni, rap, rap->rxa_wnd);
485 }
486 rap->rxa_start = IEEE80211_SEQ_INC(rxseq);
487 rap->rxa_nxt = rap->rxa_start;
488 return 0; /* NB: process packet */
571 rap->rxa_age = ticks;
489 }
572 }
490#endif
491 rap->rxa_nxt = rxseq;
492 } else {
573#endif /* IEEE80211_AMPDU_AGE */
574 /* save packet */
575 if (rap->rxa_m[off] == NULL) {
576 rap->rxa_m[off] = m;
577 rap->rxa_qframes++;
578 rap->rxa_qbytes += m->m_pkthdr.len;
579 ic->ic_stats.is_ampdu_rx_reorder++;
580 } else {
581 IEEE80211_DISCARD_MAC(ic,
582 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
583 ni->ni_macaddr, "a-mpdu duplicate",
584 "seqno %u tid %u BA win <%u:%u>",
585 rxseq, tid, rap->rxa_start,
586 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1));
587 ic->ic_stats.is_rx_dup++;
588 IEEE80211_NODE_STAT(ni, rx_dup);
589 m_freem(m);
590 }
591 return CONSUMED;
592 }
593 if (off < IEEE80211_SEQ_BA_RANGE) {
493 /*
594 /*
494 * First frame, start aging timer.
595 * Outside the BA window, but within range;
596 * flush the reorder q and move the window.
597 * Sec 9.10.7.6 b) (D2.04 p.118 line 60)
495 */
598 */
496#if 0
497 mn->mn_age[tid] = ticks;
498#endif
499 }
500 /* save packet */
501 if (rap->rxa_m[off] == NULL) {
502 rap->rxa_m[off] = m;
503 rap->rxa_qframes++;
504 rap->rxa_qbytes += m->m_pkthdr.len;
599 IEEE80211_NOTE(ic, IEEE80211_MSG_11N, ni,
600 "move BA win <%u:%u> (%u frames) rxseq %u tid %u",
601 rap->rxa_start,
602 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
603 rap->rxa_qframes, rxseq, tid);
604 ic->ic_stats.is_ampdu_rx_move++;
605
606 /*
607 * The spec says to flush frames up to but not including:
608 * WinStart_B = rxseq - rap->rxa_wnd + 1
609 * Then insert the frame or notify the caller to process
610 * it immediately. We can safely do this by just starting
611 * over again because we know the frame will now be within
612 * the BA window.
613 */
614 /* NB: rxa_wnd known to be >0 */
615 ampdu_rx_flush_upto(ni, rap,
616 IEEE80211_SEQ_SUB(rxseq, rap->rxa_wnd-1));
617 goto again;
505 } else {
618 } else {
619 /*
620 * Outside the BA window and out of range; toss.
621 * Sec 9.10.7.6 c) (D2.04 p.119 line 16)
622 */
506 IEEE80211_DISCARD_MAC(ic,
623 IEEE80211_DISCARD_MAC(ic,
507 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
508 ni->ni_macaddr, "a-mpdu duplicate",
509 "seqno %u tid %u BA win <%u:%u>",
510 rxseq, tid, rap->rxa_start, rap->rxa_wnd);
511 ic->ic_stats.is_rx_dup++;
512 IEEE80211_NODE_STAT(ni, rx_dup);
624 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
625 "MSDU", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
626 rap->rxa_start,
627 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
628 rap->rxa_qframes, rxseq, tid,
629 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
630 ic->ic_stats.is_ampdu_rx_drop++;
631 IEEE80211_NODE_STAT(ni, rx_drop);
513 m_freem(m);
632 m_freem(m);
633 return CONSUMED;
514 }
634 }
515 return 1; /* NB: consumed */
635#undef CONSUMED
636#undef PROCESS
516#undef IEEE80211_FC0_QOSDATA
517}
518
519/*
520 * Process a BAR ctl frame. Dispatch all frames up to
521 * the sequence number of the frame. If this frame is
637#undef IEEE80211_FC0_QOSDATA
638}
639
640/*
641 * Process a BAR ctl frame. Dispatch all frames up to
642 * the sequence number of the frame. If this frame is
522 * out of the window it's discarded.
643 * out of range it's discarded.
523 */
524void
525ieee80211_recv_bar(struct ieee80211_node *ni, struct mbuf *m0)
526{
527 struct ieee80211com *ic = ni->ni_ic;
528 struct ieee80211_frame_bar *wh;
529 struct ieee80211_rx_ampdu *rap;
530 ieee80211_seq rxseq;
531 int tid, off;
532
644 */
645void
646ieee80211_recv_bar(struct ieee80211_node *ni, struct mbuf *m0)
647{
648 struct ieee80211com *ic = ni->ni_ic;
649 struct ieee80211_frame_bar *wh;
650 struct ieee80211_rx_ampdu *rap;
651 ieee80211_seq rxseq;
652 int tid, off;
653
654 if (!ieee80211_recv_bar_ena) {
655#if 0
656 IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_11N,
657 ni->ni_macaddr, "BAR", "%s", "processing disabled");
658#endif
659 ic->ic_stats.is_ampdu_bar_bad++;
660 return;
661 }
533 wh = mtod(m0, struct ieee80211_frame_bar *);
534 /* XXX check basic BAR */
535 tid = MS(le16toh(wh->i_ctl), IEEE80211_BAR_TID);
536 rap = &ni->ni_rx_ampdu[tid];
537 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
538 /*
539 * No ADDBA request yet, don't touch.
540 */
541 IEEE80211_DISCARD_MAC(ic,
542 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
543 ni->ni_macaddr, "BAR", "no BA stream, tid %u", tid);
544 ic->ic_stats.is_ampdu_bar_bad++;
545 return;
546 }
547 ic->ic_stats.is_ampdu_bar_rx++;
548 rxseq = le16toh(wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;
662 wh = mtod(m0, struct ieee80211_frame_bar *);
663 /* XXX check basic BAR */
664 tid = MS(le16toh(wh->i_ctl), IEEE80211_BAR_TID);
665 rap = &ni->ni_rx_ampdu[tid];
666 if ((rap->rxa_flags & IEEE80211_AGGR_XCHGPEND) == 0) {
667 /*
668 * No ADDBA request yet, don't touch.
669 */
670 IEEE80211_DISCARD_MAC(ic,
671 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N,
672 ni->ni_macaddr, "BAR", "no BA stream, tid %u", tid);
673 ic->ic_stats.is_ampdu_bar_bad++;
674 return;
675 }
676 ic->ic_stats.is_ampdu_bar_rx++;
677 rxseq = le16toh(wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;
678 if (rxseq == rap->rxa_start)
679 return;
549 /* calculate offset in BA window */
550 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
680 /* calculate offset in BA window */
681 off = IEEE80211_SEQ_SUB(rxseq, rap->rxa_start);
551 if (off >= rap->rxa_wnd) {
682 if (off < IEEE80211_SEQ_BA_RANGE) {
552 /*
683 /*
553 * Outside the window, flush the reorder q if
554 * not pulling the sequence # backward. The
555 * latter is typically caused by a dropped BA.
684 * Flush the reorder q up to rxseq and move the window.
685 * Sec 9.10.7.6 a) (D2.04 p.119 line 22)
556 */
686 */
557 IEEE80211_NOTE(ic, IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni,
558 "recv BAR outside BA win <%u:%u> rxseq %u tid %u",
687 IEEE80211_NOTE(ic, IEEE80211_MSG_11N, ni,
688 "BAR moves BA win <%u:%u> (%u frames) rxseq %u tid %u",
559 rap->rxa_start,
689 rap->rxa_start,
560 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd),
561 rxseq, tid);
562 ic->ic_stats.is_ampdu_bar_oow++;
563 if (rxseq < rap->rxa_start) {
564 /* XXX stat? */
565 return;
690 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
691 rap->rxa_qframes, rxseq, tid);
692 ic->ic_stats.is_ampdu_bar_move++;
693
694 ampdu_rx_flush_upto(ni, rap, rxseq);
695 if (off >= rap->rxa_wnd) {
696 /*
697 * BAR specifies a window start to the right of BA
698 * window; we must move it explicitly since
699 * ampdu_rx_flush_upto will not.
700 */
701 rap->rxa_start = rxseq;
566 }
702 }
567 if (rap->rxa_qframes != 0) {
568 ic->ic_stats.is_ampdu_rx_oor += rap->rxa_qframes;
569 ampdu_rx_flush(ni, rap, rap->rxa_wnd);
570 KASSERT(rap->rxa_qbytes == 0 && rap->rxa_qframes == 0,
571 ("lost %u data, %u frames on ampdu rx q",
572 rap->rxa_qbytes, rap->rxa_qframes));
573 }
574 } else if (rap->rxa_qframes != 0) {
703 } else {
575 /*
704 /*
576 * Dispatch packets up to rxseq.
705 * Out of range; toss.
706 * Sec 9.10.7.6 b) (D2.04 p.119 line 41)
577 */
707 */
578 ampdu_rx_flush(ni, rap, off);
579 ic->ic_stats.is_ampdu_rx_oor += off;
580
581 /*
582 * If frames remain, copy the mbuf pointers down so
583 * they correspond to the offsets in the new window.
584 */
585 if (rap->rxa_qframes != 0) {
586 int n = rap->rxa_qframes, j;
587 for (j = off+1; j < rap->rxa_wnd; j++) {
588 if (rap->rxa_m[j] != NULL) {
589 rap->rxa_m[j-off] = rap->rxa_m[j];
590 rap->rxa_m[j] = NULL;
591 if (--n == 0)
592 break;
593 }
594 }
595 KASSERT(n == 0, ("lost %d frames", n));
596 ic->ic_stats.is_ampdu_rx_copy += rap->rxa_qframes;
597 }
708 IEEE80211_DISCARD_MAC(ic,
709 IEEE80211_MSG_INPUT | IEEE80211_MSG_11N, ni->ni_macaddr,
710 "BAR", "BA win <%u:%u> (%u frames) rxseq %u tid %u%s",
711 rap->rxa_start,
712 IEEE80211_SEQ_ADD(rap->rxa_start, rap->rxa_wnd-1),
713 rap->rxa_qframes, rxseq, tid,
714 wh->i_fc[1] & IEEE80211_FC1_RETRY ? " (retransmit)" : "");
715 ic->ic_stats.is_ampdu_bar_oow++;
716 IEEE80211_NODE_STAT(ni, rx_drop);
598 }
717 }
599 rap->rxa_start = rxseq;
600 rap->rxa_nxt = rap->rxa_start;
601}
602
603/*
604 * Setup HT-specific state in a node. Called only
605 * when HT use is negotiated so we don't do extra
606 * work for temporary and/or legacy sta's.
607 */
608void
609ieee80211_ht_node_init(struct ieee80211_node *ni, const uint8_t *htcap)
610{
611 struct ieee80211_tx_ampdu *tap;
612 int ac;
613
718}
719
720/*
721 * Setup HT-specific state in a node. Called only
722 * when HT use is negotiated so we don't do extra
723 * work for temporary and/or legacy sta's.
724 */
725void
726ieee80211_ht_node_init(struct ieee80211_node *ni, const uint8_t *htcap)
727{
728 struct ieee80211_tx_ampdu *tap;
729 int ac;
730
731 if (ni->ni_flags & IEEE80211_NODE_HT) {
732 /*
733 * Clean AMPDU state on re-associate. This handles the case
734 * where a station leaves w/o notifying us and then returns
735 * before node is reaped for inactivity.
736 */
737 ieee80211_ht_node_cleanup(ni);
738 }
614 ieee80211_parse_htcap(ni, htcap);
615 for (ac = 0; ac < WME_NUM_AC; ac++) {
616 tap = &ni->ni_tx_ampdu[ac];
617 tap->txa_ac = ac;
739 ieee80211_parse_htcap(ni, htcap);
740 for (ac = 0; ac < WME_NUM_AC; ac++) {
741 tap = &ni->ni_tx_ampdu[ac];
742 tap->txa_ac = ac;
743 /* NB: further initialization deferred */
618 }
744 }
619 ni->ni_flags |= IEEE80211_NODE_HT;
745 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
620}
621
622/*
623 * Cleanup HT-specific state in a node. Called only
624 * when HT use has been marked.
625 */
626void
627ieee80211_ht_node_cleanup(struct ieee80211_node *ni)
628{
629 struct ieee80211com *ic = ni->ni_ic;
630 int i;
631
632 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT node"));
633
634 /* XXX optimize this */
635 for (i = 0; i < WME_NUM_AC; i++) {
636 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[i];
746}
747
748/*
749 * Cleanup HT-specific state in a node. Called only
750 * when HT use has been marked.
751 */
752void
753ieee80211_ht_node_cleanup(struct ieee80211_node *ni)
754{
755 struct ieee80211com *ic = ni->ni_ic;
756 int i;
757
758 KASSERT(ni->ni_flags & IEEE80211_NODE_HT, ("not an HT node"));
759
760 /* XXX optimize this */
761 for (i = 0; i < WME_NUM_AC; i++) {
762 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[i];
637 if (IEEE80211_AMPDU_REQUESTED(tap))
763 if (tap->txa_flags & IEEE80211_AGGR_SETUP) {
764 /*
765 * Stop BA stream if setup so driver has a chance
766 * to reclaim any resources it might have allocated.
767 */
638 ic->ic_addba_stop(ni, &ni->ni_tx_ampdu[i]);
768 ic->ic_addba_stop(ni, &ni->ni_tx_ampdu[i]);
769 IEEE80211_TAPQ_DESTROY(tap);
770 /* NB: clearing NAK means we may re-send ADDBA */
771 tap->txa_flags &=
772 ~(IEEE80211_AGGR_SETUP | IEEE80211_AGGR_NAK);
773 }
639 }
640 for (i = 0; i < WME_NUM_TID; i++)
641 ampdu_rx_stop(&ni->ni_rx_ampdu[i]);
642
643 ni->ni_htcap = 0;
774 }
775 for (i = 0; i < WME_NUM_TID; i++)
776 ampdu_rx_stop(&ni->ni_rx_ampdu[i]);
777
778 ni->ni_htcap = 0;
644 ni->ni_flags &= ~(IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT);
779 ni->ni_flags &= ~(IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT |
780 IEEE80211_NODE_AMPDU);
645}
646
781}
782
783static struct ieee80211_channel *
784findhtchan(struct ieee80211com *ic, struct ieee80211_channel *c, int htflags)
785{
786 return ieee80211_find_channel(ic, c->ic_freq,
787 (c->ic_flags &~ IEEE80211_CHAN_HT) | htflags);
788}
789
790/*
791 * Adjust a channel to be HT/non-HT according to the vap's configuration.
792 */
793struct ieee80211_channel *
794ieee80211_ht_adjust_channel(struct ieee80211com *ic,
795 struct ieee80211_channel *chan, int flags)
796{
797 struct ieee80211_channel *c;
798
799 if (flags & IEEE80211_FEXT_HT) {
800 /* promote to HT if possible */
801 if (flags & IEEE80211_FEXT_USEHT40) {
802 if (!IEEE80211_IS_CHAN_HT40(chan)) {
803 /* NB: arbitrarily pick ht40+ over ht40- */
804 c = findhtchan(ic, chan, IEEE80211_CHAN_HT40U);
805 if (c == NULL)
806 c = findhtchan(ic, chan,
807 IEEE80211_CHAN_HT40D);
808 if (c == NULL)
809 c = findhtchan(ic, chan,
810 IEEE80211_CHAN_HT20);
811 if (c != NULL)
812 chan = c;
813 }
814 } else if (!IEEE80211_IS_CHAN_HT20(chan)) {
815 c = findhtchan(ic, chan, IEEE80211_CHAN_HT20);
816 if (c != NULL)
817 chan = c;
818 }
819 } else if (IEEE80211_IS_CHAN_HT(chan)) {
820 /* demote to legacy, HT use is disabled */
821 c = ieee80211_find_channel(ic, chan->ic_freq,
822 chan->ic_flags &~ IEEE80211_CHAN_HT);
823 if (c != NULL)
824 chan = c;
825 }
826 return chan;
827}
828
829/*
830 * Setup HT-specific state for a legacy WDS peer.
831 */
832void
833ieee80211_ht_wds_init(struct ieee80211_node *ni)
834{
835 struct ieee80211com *ic = ni->ni_ic;
836 struct ieee80211_tx_ampdu *tap;
837 int ac;
838
839 KASSERT(ic->ic_flags_ext & IEEE80211_FEXT_HT, ("no HT requested"));
840
841 /* XXX check scan cache in case peer has an ap and we have info */
842 /*
843 * If setup with a legacy channel; locate an HT channel.
844 * Otherwise if the inherited channel (from a companion
845 * AP) is suitable use it so we use the same location
846 * for the extension channel).
847 */
848 ni->ni_chan = ieee80211_ht_adjust_channel(ic, ni->ni_chan,
849 ic->ic_flags_ext);
850
851 ni->ni_htcap = 0;
852 if (ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI20)
853 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI20;
854 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {
855 ni->ni_htcap |= IEEE80211_HTCAP_CHWIDTH40;
856 ni->ni_chw = 40;
857 if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
858 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_ABOVE;
859 else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
860 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_BELOW;
861 if (ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI40)
862 ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI40;
863 } else {
864 ni->ni_chw = 20;
865 ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_NONE;
866 }
867 ni->ni_htctlchan = ni->ni_chan->ic_ieee;
868
869 ni->ni_htopmode = 0; /* XXX need protection state */
870 ni->ni_htstbc = 0; /* XXX need info */
871
872 for (ac = 0; ac < WME_NUM_AC; ac++) {
873 tap = &ni->ni_tx_ampdu[ac];
874 tap->txa_ac = ac;
875 }
876 /* NB: AMPDU tx/rx governed by IEEE80211_FEXT_AMPDU_{TX,RX} */
877 ni->ni_flags |= IEEE80211_NODE_HT | IEEE80211_NODE_AMPDU;
878}
879
880/*
881 * Notify hostap vaps of a change in the HTINFO ie.
882 */
883static void
884htinfo_notify(struct ieee80211com *ic)
885{
886 if (ic->ic_opmode != IEEE80211_M_HOSTAP)
887 return;
888 IEEE80211_NOTE(ic,
889 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N,
890 ic->ic_bss,
891 "HT bss occupancy change: %d sta, %d ht, "
892 "%d ht40%s, HT protmode now 0x%x"
893 , ic->ic_sta_assoc
894 , ic->ic_ht_sta_assoc
895 , ic->ic_ht40_sta_assoc
896 , (ic->ic_flags_ext & IEEE80211_FEXT_NONHT_PR) ?
897 ", non-HT sta present" : ""
898 , ic->ic_curhtprotmode);
899 ieee80211_beacon_notify(ic, IEEE80211_BEACON_HTINFO);
900}
901
902/*
903 * Calculate HT protection mode from current
904 * state and handle updates.
905 */
906static void
907htinfo_update(struct ieee80211com *ic)
908{
909 uint8_t protmode;
910
911 if (ic->ic_flags_ext & IEEE80211_FEXT_NONHT_PR) {
912 protmode = IEEE80211_HTINFO_OPMODE_PROTOPT
913 | IEEE80211_HTINFO_NONHT_PRESENT;
914 } else if (ic->ic_sta_assoc != ic->ic_ht_sta_assoc) {
915 protmode = IEEE80211_HTINFO_OPMODE_MIXED
916 | IEEE80211_HTINFO_NONHT_PRESENT;
917 } else if (IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) &&
918 ic->ic_sta_assoc != ic->ic_ht40_sta_assoc) {
919 protmode = IEEE80211_HTINFO_OPMODE_HT20PR;
920 } else {
921 protmode = IEEE80211_HTINFO_OPMODE_PURE;
922 }
923 if (protmode != ic->ic_curhtprotmode) {
924 ic->ic_curhtprotmode = protmode;
925 htinfo_notify(ic);
926 }
927}
928
929/*
930 * Handle an HT station joining a BSS.
931 */
932void
933ieee80211_ht_node_join(struct ieee80211_node *ni)
934{
935 struct ieee80211com *ic = ni->ni_ic;
936
937 IEEE80211_LOCK_ASSERT(ic);
938
939 if (ni->ni_flags & IEEE80211_NODE_HT) {
940 ic->ic_ht_sta_assoc++;
941 if (ni->ni_chw == 40)
942 ic->ic_ht40_sta_assoc++;
943 }
944 htinfo_update(ic);
945}
946
947/*
948 * Handle an HT station leaving a BSS.
949 */
950void
951ieee80211_ht_node_leave(struct ieee80211_node *ni)
952{
953 struct ieee80211com *ic = ni->ni_ic;
954
955 IEEE80211_LOCK_ASSERT(ic);
956
957 if (ni->ni_flags & IEEE80211_NODE_HT) {
958 ic->ic_ht_sta_assoc--;
959 if (ni->ni_chw == 40)
960 ic->ic_ht40_sta_assoc--;
961 }
962 htinfo_update(ic);
963}
964
965/*
966 * Public version of htinfo_update; used for processing
967 * beacon frames from overlapping bss in hostap_recv_mgmt.
968 */
969void
970ieee80211_htinfo_update(struct ieee80211com *ic, int protmode)
971{
972 if (protmode != ic->ic_curhtprotmode) {
973 ic->ic_curhtprotmode = protmode;
974 htinfo_notify(ic);
975 }
976}
977
978/*
979 * Time out presence of an overlapping bss with non-HT
980 * stations. When operating in hostap mode we listen for
981 * beacons from other stations and if we identify a non-HT
982 * station is present we update the opmode field of the
983 * HTINFO ie. To identify when all non-HT stations are
984 * gone we time out this condition.
985 */
986void
987ieee80211_ht_timeout(struct ieee80211com *ic)
988{
989 IEEE80211_LOCK_ASSERT(ic);
990
991 if ((ic->ic_flags_ext & IEEE80211_FEXT_NONHT_PR) &&
992 time_after(ticks, ic->ic_lastnonht + IEEE80211_NONHT_PRESENT_AGE)) {
993#if 0
994 IEEE80211_NOTE(ic, IEEE80211_MSG_11N, ni,
995 "%s", "time out non-HT STA present on channel");
996#endif
997 ic->ic_flags_ext &= ~IEEE80211_FEXT_NONHT_PR;
998 htinfo_update(ic);
999 }
1000}
1001
647/* unalligned little endian access */
648#define LE_READ_2(p) \
649 ((uint16_t) \
650 ((((const uint8_t *)(p))[0] ) | \
651 (((const uint8_t *)(p))[1] << 8)))
652
653/*
654 * Process an 802.11n HT capabilities ie.

--- 11 unchanged lines hidden (view full) ---

666 */
667 ni->ni_flags |= IEEE80211_NODE_HTCOMPAT;
668 ie += 4;
669 } else
670 ni->ni_flags &= ~IEEE80211_NODE_HTCOMPAT;
671
672 ni->ni_htcap = LE_READ_2(ie +
673 __offsetof(struct ieee80211_ie_htcap, hc_cap));
1002/* unalligned little endian access */
1003#define LE_READ_2(p) \
1004 ((uint16_t) \
1005 ((((const uint8_t *)(p))[0] ) | \
1006 (((const uint8_t *)(p))[1] << 8)))
1007
1008/*
1009 * Process an 802.11n HT capabilities ie.

--- 11 unchanged lines hidden (view full) ---

1021 */
1022 ni->ni_flags |= IEEE80211_NODE_HTCOMPAT;
1023 ie += 4;
1024 } else
1025 ni->ni_flags &= ~IEEE80211_NODE_HTCOMPAT;
1026
1027 ni->ni_htcap = LE_READ_2(ie +
1028 __offsetof(struct ieee80211_ie_htcap, hc_cap));
674 if ((ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI40) == 0)
675 ni->ni_htcap &= ~IEEE80211_HTCAP_SHORTGI40;
676 if ((ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI20) == 0)
677 ni->ni_htcap &= ~IEEE80211_HTCAP_SHORTGI20;
678 ni->ni_chw = (ni->ni_htcap & IEEE80211_HTCAP_CHWIDTH40) ? 40 : 20;
679 ni->ni_htparam = ie[__offsetof(struct ieee80211_ie_htcap, hc_param)];
1029 ni->ni_htparam = ie[__offsetof(struct ieee80211_ie_htcap, hc_param)];
680#if 0
681 ni->ni_maxampdu =
682 (8*1024) << MS(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU);
683 ni->ni_mpdudensity = MS(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY);
684#endif
1030 /* XXX needed or will ieee80211_parse_htinfo always be called? */
1031 ni->ni_chw = (ni->ni_htcap & IEEE80211_HTCAP_CHWIDTH40) &&
1032 (ic->ic_flags_ext & IEEE80211_FEXT_USEHT40) ? 40 : 20;
685}
686
687/*
1033}
1034
1035/*
688 * Process an 802.11n HT info ie.
1036 * Process an 802.11n HT info ie and update the node state.
1037 * Note that we handle use this information to identify the
1038 * correct channel (HT20, HT40+, HT40-, legacy). The caller
1039 * is responsible for insuring any required channel change is
1040 * done (e.g. in sta mode when parsing the contents of a
1041 * beacon frame).
689 */
690void
691ieee80211_parse_htinfo(struct ieee80211_node *ni, const uint8_t *ie)
692{
1042 */
1043void
1044ieee80211_parse_htinfo(struct ieee80211_node *ni, const uint8_t *ie)
1045{
1046 struct ieee80211com *ic = ni->ni_ic;
693 const struct ieee80211_ie_htinfo *htinfo;
1047 const struct ieee80211_ie_htinfo *htinfo;
1048 struct ieee80211_channel *c;
694 uint16_t w;
1049 uint16_t w;
695 int chw;
1050 int htflags, chanflags;
696
697 if (ie[0] == IEEE80211_ELEMID_VENDOR)
698 ie += 4;
699 htinfo = (const struct ieee80211_ie_htinfo *) ie;
700 ni->ni_htctlchan = htinfo->hi_ctrlchannel;
701 ni->ni_ht2ndchan = SM(htinfo->hi_byte1, IEEE80211_HTINFO_2NDCHAN);
702 w = LE_READ_2(&htinfo->hi_byte2);
703 ni->ni_htopmode = SM(w, IEEE80211_HTINFO_OPMODE);
704 w = LE_READ_2(&htinfo->hi_byte45);
705 ni->ni_htstbc = SM(w, IEEE80211_HTINFO_BASIC_STBCMCS);
1051
1052 if (ie[0] == IEEE80211_ELEMID_VENDOR)
1053 ie += 4;
1054 htinfo = (const struct ieee80211_ie_htinfo *) ie;
1055 ni->ni_htctlchan = htinfo->hi_ctrlchannel;
1056 ni->ni_ht2ndchan = SM(htinfo->hi_byte1, IEEE80211_HTINFO_2NDCHAN);
1057 w = LE_READ_2(&htinfo->hi_byte2);
1058 ni->ni_htopmode = SM(w, IEEE80211_HTINFO_OPMODE);
1059 w = LE_READ_2(&htinfo->hi_byte45);
1060 ni->ni_htstbc = SM(w, IEEE80211_HTINFO_BASIC_STBCMCS);
706 /* update node's recommended tx channel width */
707 chw = (htinfo->hi_byte1 & IEEE80211_HTINFO_TXWIDTH_2040) ? 40 : 20;
708 if (chw != ni->ni_chw) {
709 ni->ni_chw = chw;
710 ni->ni_flags |= IEEE80211_NODE_CHWUPDATE;
1061 /*
1062 * Handle 11n channel switch. Use the received HT ie's to
1063 * identify the right channel to use. If we cannot locate it
1064 * in the channel table then fallback to legacy operation.
1065 */
1066 htflags = (ic->ic_flags_ext & IEEE80211_FEXT_HT) ?
1067 IEEE80211_CHAN_HT20 : 0;
1068 /* NB: honor operating mode constraint */
1069 if ((htinfo->hi_byte1 & IEEE80211_HTINFO_TXWIDTH_2040) &&
1070 (ic->ic_flags_ext & IEEE80211_FEXT_USEHT40)) {
1071 if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_ABOVE)
1072 htflags = IEEE80211_CHAN_HT40U;
1073 else if (ni->ni_ht2ndchan == IEEE80211_HTINFO_2NDCHAN_BELOW)
1074 htflags = IEEE80211_CHAN_HT40D;
711 }
1075 }
1076 chanflags = (ni->ni_chan->ic_flags &~ IEEE80211_CHAN_HT) | htflags;
1077 if (chanflags != ni->ni_chan->ic_flags) {
1078 c = ieee80211_find_channel(ic, ni->ni_chan->ic_freq, chanflags);
1079 if (c == NULL && htflags != IEEE80211_CHAN_HT20) {
1080 /*
1081 * No HT40 channel entry in our table; fall back
1082 * to HT20 operation. This should not happen.
1083 */
1084 c = findhtchan(ic, ni->ni_chan, IEEE80211_CHAN_HT20);
1085 IEEE80211_NOTE(ni->ni_ic,
1086 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1087 "no HT40 channel (freq %u), falling back to HT20",
1088 ni->ni_chan->ic_freq);
1089 /* XXX stat */
1090 }
1091 if (c != NULL && c != ni->ni_chan) {
1092 IEEE80211_NOTE(ni->ni_ic,
1093 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
1094 "switch station to HT%d channel %u/0x%x",
1095 IEEE80211_IS_CHAN_HT40(c) ? 40 : 20,
1096 c->ic_freq, c->ic_flags);
1097 ni->ni_chan = c;
1098 }
1099 /* NB: caller responsible for forcing any channel change */
1100 }
1101 /* update node's tx channel width */
1102 ni->ni_chw = IEEE80211_IS_CHAN_HT40(ni->ni_chan)? 40 : 20;
712}
713
714/*
715 * Install received HT rate set by parsing the HT cap ie.
716 */
717int
718ieee80211_setup_htrates(struct ieee80211_node *ni, const uint8_t *ie, int flags)
719{

--- 123 unchanged lines hidden (view full) ---

843 /* XXX locking */
844 addba_stop_timeout(tap);
845 if (status == IEEE80211_STATUS_SUCCESS) {
846 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
847 /* XXX override our request? */
848 tap->txa_wnd = (bufsiz == 0) ?
849 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
850 tap->txa_flags |= IEEE80211_AGGR_RUNNING;
1103}
1104
1105/*
1106 * Install received HT rate set by parsing the HT cap ie.
1107 */
1108int
1109ieee80211_setup_htrates(struct ieee80211_node *ni, const uint8_t *ie, int flags)
1110{

--- 123 unchanged lines hidden (view full) ---

1234 /* XXX locking */
1235 addba_stop_timeout(tap);
1236 if (status == IEEE80211_STATUS_SUCCESS) {
1237 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1238 /* XXX override our request? */
1239 tap->txa_wnd = (bufsiz == 0) ?
1240 IEEE80211_AGGR_BAWMAX : min(bufsiz, IEEE80211_AGGR_BAWMAX);
1241 tap->txa_flags |= IEEE80211_AGGR_RUNNING;
1242 } else {
1243 /* mark tid so we don't try again */
1244 tap->txa_flags |= IEEE80211_AGGR_NAK;
851 }
852 return 1;
853}
854
855/*
856 * Default method for stopping A-MPDU tx aggregation.
857 * Any timer is cleared and we drain any pending frames.
858 */

--- 41 unchanged lines hidden (view full) ---

900
901 tid = MS(baparamset, IEEE80211_BAPS_TID);
902 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
903
904 IEEE80211_NOTE(ic,
905 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
906 "recv ADDBA request: dialogtoken %u "
907 "baparamset 0x%x (tid %d bufsiz %d) batimeout %d "
1245 }
1246 return 1;
1247}
1248
1249/*
1250 * Default method for stopping A-MPDU tx aggregation.
1251 * Any timer is cleared and we drain any pending frames.
1252 */

--- 41 unchanged lines hidden (view full) ---

1294
1295 tid = MS(baparamset, IEEE80211_BAPS_TID);
1296 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1297
1298 IEEE80211_NOTE(ic,
1299 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1300 "recv ADDBA request: dialogtoken %u "
1301 "baparamset 0x%x (tid %d bufsiz %d) batimeout %d "
908 "baseqctl %d",
909 dialogtoken, baparamset, tid, bufsiz,
910 batimeout, baseqctl);
1302 "baseqctl %d:%d",
1303 dialogtoken, baparamset, tid, bufsiz, batimeout,
1304 MS(baseqctl, IEEE80211_BASEQ_START),
1305 MS(baseqctl, IEEE80211_BASEQ_FRAG));
911
912 rap = &ni->ni_rx_ampdu[tid];
913
914 /* Send ADDBA response */
915 args[0] = dialogtoken;
1306
1307 rap = &ni->ni_rx_ampdu[tid];
1308
1309 /* Send ADDBA response */
1310 args[0] = dialogtoken;
916 if (ic->ic_flags_ext & IEEE80211_FEXT_AMPDU_RX) {
1311 /*
1312 * NB: We ack only if the sta associated with HT and
1313 * the ap is configured to do AMPDU rx (the latter
1314 * violates the 11n spec and is mostly for testing).
1315 */
1316 if ((ni->ni_flags & IEEE80211_NODE_AMPDU_RX) &&
1317 (ic->ic_flags_ext & IEEE80211_FEXT_AMPDU_RX)) {
917 ampdu_rx_start(rap, bufsiz,
918 MS(baseqctl, IEEE80211_BASEQ_START));
919
920 args[1] = IEEE80211_STATUS_SUCCESS;
1318 ampdu_rx_start(rap, bufsiz,
1319 MS(baseqctl, IEEE80211_BASEQ_START));
1320
1321 args[1] = IEEE80211_STATUS_SUCCESS;
921 } else
1322 } else {
1323 IEEE80211_NOTE(ic,
1324 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1325 ni, "reject ADDBA request: %s",
1326 ni->ni_flags & IEEE80211_NODE_AMPDU_RX ?
1327 "administratively disabled" :
1328 "not negotiated for station");
1329 ic->ic_stats.is_addba_reject++;
922 args[1] = IEEE80211_STATUS_UNSPECIFIED;
1330 args[1] = IEEE80211_STATUS_UNSPECIFIED;
1331 }
923 /* XXX honor rap flags? */
924 args[2] = IEEE80211_BAPS_POLICY_IMMEDIATE
925 | SM(tid, IEEE80211_BAPS_TID)
926 | SM(rap->rxa_wnd, IEEE80211_BAPS_BUFSIZ)
927 ;
928 args[3] = 0;
929 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
930 IEEE80211_ACTION_BA_ADDBA_RESPONSE, args);
931 return;
932
933 case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
934 dialogtoken = frm[2];
935 code = LE_READ_2(frm+3);
936 baparamset = LE_READ_2(frm+5);
937 tid = MS(baparamset, IEEE80211_BAPS_TID);
938 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
939 batimeout = LE_READ_2(frm+7);
940
1332 /* XXX honor rap flags? */
1333 args[2] = IEEE80211_BAPS_POLICY_IMMEDIATE
1334 | SM(tid, IEEE80211_BAPS_TID)
1335 | SM(rap->rxa_wnd, IEEE80211_BAPS_BUFSIZ)
1336 ;
1337 args[3] = 0;
1338 ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1339 IEEE80211_ACTION_BA_ADDBA_RESPONSE, args);
1340 return;
1341
1342 case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
1343 dialogtoken = frm[2];
1344 code = LE_READ_2(frm+3);
1345 baparamset = LE_READ_2(frm+5);
1346 tid = MS(baparamset, IEEE80211_BAPS_TID);
1347 bufsiz = MS(baparamset, IEEE80211_BAPS_BUFSIZ);
1348 batimeout = LE_READ_2(frm+7);
1349
1350 ac = TID_TO_WME_AC(tid);
1351 tap = &ni->ni_tx_ampdu[ac];
1352 if ((tap->txa_flags & ~IEEE80211_AGGR_XCHGPEND) == 0) {
1353 IEEE80211_DISCARD_MAC(ic,
1354 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1355 ni->ni_macaddr, "ADDBA response",
1356 "no pending ADDBA, tid %d dialogtoken %u "
1357 "code %d", tid, dialogtoken, code);
1358 ic->ic_stats.is_addba_norequest++;
1359 return;
1360 }
1361 if (dialogtoken != tap->txa_token) {
1362 IEEE80211_DISCARD_MAC(ic,
1363 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1364 ni->ni_macaddr, "ADDBA response",
1365 "dialogtoken mismatch: waiting for %d, "
1366 "received %d, tid %d code %d",
1367 tap->txa_token, dialogtoken, tid, code);
1368 ic->ic_stats.is_addba_badtoken++;
1369 return;
1370 }
1371
941 IEEE80211_NOTE(ic,
942 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
943 "recv ADDBA response: dialogtoken %u code %d "
944 "baparamset 0x%x (tid %d bufsiz %d) batimeout %d",
945 dialogtoken, code, baparamset, tid, bufsiz,
946 batimeout);
1372 IEEE80211_NOTE(ic,
1373 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1374 "recv ADDBA response: dialogtoken %u code %d "
1375 "baparamset 0x%x (tid %d bufsiz %d) batimeout %d",
1376 dialogtoken, code, baparamset, tid, bufsiz,
1377 batimeout);
947
948 ac = TID_TO_WME_AC(tid);
949 tap = &ni->ni_tx_ampdu[ac];
950
951 ic->ic_addba_response(ni, tap,
952 code, baparamset, batimeout);
953 return;
954
955 case IEEE80211_ACTION_BA_DELBA:
956 baparamset = LE_READ_2(frm+2);
957 code = LE_READ_2(frm+4);
958

--- 12 unchanged lines hidden (view full) ---

971 } else {
972 rap = &ni->ni_rx_ampdu[tid];
973 ampdu_rx_stop(rap);
974 }
975 return;
976 }
977 break;
978 }
1378 ic->ic_addba_response(ni, tap,
1379 code, baparamset, batimeout);
1380 return;
1381
1382 case IEEE80211_ACTION_BA_DELBA:
1383 baparamset = LE_READ_2(frm+2);
1384 code = LE_READ_2(frm+4);
1385

--- 12 unchanged lines hidden (view full) ---

1398 } else {
1399 rap = &ni->ni_rx_ampdu[tid];
1400 ampdu_rx_stop(rap);
1401 }
1402 return;
1403 }
1404 break;
1405 }
979 return ieee80211_recv_action(ni, frm, efrm);
1406 ieee80211_recv_action(ni, frm, efrm);
980}
981
982/*
983 * Process a received 802.11n action frame.
984 * Aggregation-related frames are assumed to be handled
985 * already; we handle any other frames we can, otherwise
986 * complain about being unsupported (with debugging).
987 */

--- 19 unchanged lines hidden (view full) ---

1007 case IEEE80211_ACTION_HT_TXCHWIDTH:
1008 chw = frm[2] == IEEE80211_A_HT_TXCHWIDTH_2040 ? 40 : 20;
1009 if (chw != ni->ni_chw) {
1010 ni->ni_chw = chw;
1011 ni->ni_flags |= IEEE80211_NODE_CHWUPDATE;
1012 }
1013 IEEE80211_NOTE(ic,
1014 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1407}
1408
1409/*
1410 * Process a received 802.11n action frame.
1411 * Aggregation-related frames are assumed to be handled
1412 * already; we handle any other frames we can, otherwise
1413 * complain about being unsupported (with debugging).
1414 */

--- 19 unchanged lines hidden (view full) ---

1434 case IEEE80211_ACTION_HT_TXCHWIDTH:
1435 chw = frm[2] == IEEE80211_A_HT_TXCHWIDTH_2040 ? 40 : 20;
1436 if (chw != ni->ni_chw) {
1437 ni->ni_chw = chw;
1438 ni->ni_flags |= IEEE80211_NODE_CHWUPDATE;
1439 }
1440 IEEE80211_NOTE(ic,
1441 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1015 "%s: HT txchwidth. width %d (%s)",
1442 "%s: HT txchwidth, width %d (%s)",
1016 __func__, chw,
1017 ni->ni_flags & IEEE80211_NODE_CHWUPDATE ?
1018 "new" : "no change");
1019 break;
1443 __func__, chw,
1444 ni->ni_flags & IEEE80211_NODE_CHWUPDATE ?
1445 "new" : "no change");
1446 break;
1447 case IEEE80211_ACTION_HT_MIMOPWRSAVE:
1448 IEEE80211_NOTE(ic,
1449 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1450 "%s: HT MIMO PS", __func__);
1451 break;
1020 default:
1021 IEEE80211_NOTE(ic,
1022 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1023 "%s: HT action %d not implemented", __func__,
1024 ia->ia_action);
1025 ic->ic_stats.is_rx_mgtdiscard++;
1026 break;
1027 }

--- 24 unchanged lines hidden (view full) ---

1052 struct ieee80211com *ic = ni->ni_ic;
1053 uint16_t args[4];
1054 int tid, dialogtoken;
1055 static int tokens = 0; /* XXX */
1056
1057 /* XXX locking */
1058 if ((tap->txa_flags & IEEE80211_AGGR_SETUP) == 0) {
1059 /* do deferred setup of state */
1452 default:
1453 IEEE80211_NOTE(ic,
1454 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1455 "%s: HT action %d not implemented", __func__,
1456 ia->ia_action);
1457 ic->ic_stats.is_rx_mgtdiscard++;
1458 break;
1459 }

--- 24 unchanged lines hidden (view full) ---

1484 struct ieee80211com *ic = ni->ni_ic;
1485 uint16_t args[4];
1486 int tid, dialogtoken;
1487 static int tokens = 0; /* XXX */
1488
1489 /* XXX locking */
1490 if ((tap->txa_flags & IEEE80211_AGGR_SETUP) == 0) {
1491 /* do deferred setup of state */
1060 /* XXX tap->txa_q */
1492 IEEE80211_TAPQ_INIT(tap);
1061 callout_init(&tap->txa_timer, CALLOUT_MPSAFE);
1062 tap->txa_flags |= IEEE80211_AGGR_SETUP;
1063 }
1064 if (tap->txa_attempts >= IEEE80211_AGGR_MAXTRIES &&
1065 (ticks - tap->txa_lastrequest) < IEEE80211_AGGR_MINRETRY) {
1066 /*
1067 * Don't retry too often; IEEE80211_AGGR_MINRETRY
1068 * defines the minimum interval we'll retry after
1069 * IEEE80211_AGGR_MAXTRIES failed attempts to
1070 * negotiate use.
1071 */
1072 return 0;
1073 }
1493 callout_init(&tap->txa_timer, CALLOUT_MPSAFE);
1494 tap->txa_flags |= IEEE80211_AGGR_SETUP;
1495 }
1496 if (tap->txa_attempts >= IEEE80211_AGGR_MAXTRIES &&
1497 (ticks - tap->txa_lastrequest) < IEEE80211_AGGR_MINRETRY) {
1498 /*
1499 * Don't retry too often; IEEE80211_AGGR_MINRETRY
1500 * defines the minimum interval we'll retry after
1501 * IEEE80211_AGGR_MAXTRIES failed attempts to
1502 * negotiate use.
1503 */
1504 return 0;
1505 }
1506 /* XXX hack for not doing proper locking */
1507 tap->txa_flags &= ~IEEE80211_AGGR_NAK;
1508
1074 dialogtoken = (tokens+1) % 63; /* XXX */
1075
1076 tid = WME_AC_TO_TID(tap->txa_ac);
1077 args[0] = dialogtoken;
1078 args[1] = IEEE80211_BAPS_POLICY_IMMEDIATE
1079 | SM(tid, IEEE80211_BAPS_TID)
1080 | SM(IEEE80211_AGGR_BAWMAX, IEEE80211_BAPS_BUFSIZ)
1081 ;
1082 args[2] = 0; /* batimeout */
1083 args[3] = SM(0, IEEE80211_BASEQ_START)
1084 | SM(0, IEEE80211_BASEQ_FRAG)
1085 ;
1086 /* NB: do first so there's no race against reply */
1087 if (!ic->ic_addba_request(ni, tap, dialogtoken, args[1], args[2])) {
1088 /* unable to setup state, don't make request */
1509 dialogtoken = (tokens+1) % 63; /* XXX */
1510
1511 tid = WME_AC_TO_TID(tap->txa_ac);
1512 args[0] = dialogtoken;
1513 args[1] = IEEE80211_BAPS_POLICY_IMMEDIATE
1514 | SM(tid, IEEE80211_BAPS_TID)
1515 | SM(IEEE80211_AGGR_BAWMAX, IEEE80211_BAPS_BUFSIZ)
1516 ;
1517 args[2] = 0; /* batimeout */
1518 args[3] = SM(0, IEEE80211_BASEQ_START)
1519 | SM(0, IEEE80211_BASEQ_FRAG)
1520 ;
1521 /* NB: do first so there's no race against reply */
1522 if (!ic->ic_addba_request(ni, tap, dialogtoken, args[1], args[2])) {
1523 /* unable to setup state, don't make request */
1524 IEEE80211_NOTE(ni->ni_ic, IEEE80211_MSG_11N,
1525 ni, "%s: could not setup BA stream for AC %d",
1526 __func__, tap->txa_ac);
1527 /* defer next try so we don't slam the driver with requests */
1528 tap->txa_attempts = IEEE80211_AGGR_MAXTRIES;
1529 tap->txa_lastrequest = ticks;
1089 return 0;
1090 }
1091 tokens = dialogtoken; /* allocate token */
1092 return ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1093 IEEE80211_ACTION_BA_ADDBA_REQUEST, args);
1094}
1095
1096/*
1530 return 0;
1531 }
1532 tokens = dialogtoken; /* allocate token */
1533 return ic->ic_send_action(ni, IEEE80211_ACTION_CAT_BA,
1534 IEEE80211_ACTION_BA_ADDBA_REQUEST, args);
1535}
1536
1537/*
1538 * Terminate an AMPDU tx stream. State is reclaimed
1539 * and the peer notified with a DelBA Action frame.
1540 */
1541void
1542ieee80211_ampdu_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
1543{
1544 struct ieee80211com *ic = ni->ni_ic;
1545 uint16_t args[4];
1546
1547 /* XXX locking */
1548 if (IEEE80211_AMPDU_RUNNING(tap)) {
1549 IEEE80211_NOTE(ic, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1550 ni, "%s: stop BA stream for AC %d", __func__, tap->txa_ac);
1551 ic->ic_stats.is_ampdu_stop++;
1552
1553 ic->ic_addba_stop(ni, tap);
1554 args[0] = WME_AC_TO_TID(tap->txa_ac);
1555 args[1] = IEEE80211_DELBAPS_INIT;
1556 args[2] = 1; /* XXX reason code */
1557 ieee80211_send_action(ni, IEEE80211_ACTION_CAT_BA,
1558 IEEE80211_ACTION_BA_DELBA, args);
1559 } else {
1560 IEEE80211_NOTE(ic, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1561 ni, "%s: BA stream for AC %d not running",
1562 __func__, tap->txa_ac);
1563 ic->ic_stats.is_ampdu_stop_failed++;
1564 }
1565}
1566
1567/*
1097 * Transmit a BAR frame to the specified node. The
1098 * BAR contents are drawn from the supplied aggregation
1099 * state associated with the node.
1100 */
1101int
1102ieee80211_send_bar(struct ieee80211_node *ni,
1103 const struct ieee80211_tx_ampdu *tap)
1104{

--- 38 unchanged lines hidden (view full) ---

1143 | SM(0, IEEE80211_BASEQ_FRAG)
1144 ;
1145 ADDSHORT(frm, barctl);
1146 ADDSHORT(frm, barseqctl);
1147 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
1148
1149 IEEE80211_NODE_STAT(ni, tx_mgmt); /* XXX tx_ctl? */
1150
1568 * Transmit a BAR frame to the specified node. The
1569 * BAR contents are drawn from the supplied aggregation
1570 * state associated with the node.
1571 */
1572int
1573ieee80211_send_bar(struct ieee80211_node *ni,
1574 const struct ieee80211_tx_ampdu *tap)
1575{

--- 38 unchanged lines hidden (view full) ---

1614 | SM(0, IEEE80211_BASEQ_FRAG)
1615 ;
1616 ADDSHORT(frm, barctl);
1617 ADDSHORT(frm, barseqctl);
1618 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
1619
1620 IEEE80211_NODE_STAT(ni, tx_mgmt); /* XXX tx_ctl? */
1621
1151 IEEE80211_DPRINTF(ic, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS,
1152 "[%s] send bar frame (tid %u start %u) on channel %u\n",
1153 ether_sprintf(ni->ni_macaddr), tid, tap->txa_start,
1154 ieee80211_chan2ieee(ic, ic->ic_curchan));
1622 IEEE80211_NOTE(ic, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS,
1623 ni, "send bar frame (tid %u start %u) on channel %u",
1624 tid, tap->txa_start, ieee80211_chan2ieee(ic, ic->ic_curchan));
1155
1156 m->m_pkthdr.rcvif = (void *)ni;
1157 IF_ENQUEUE(&ic->ic_mgtq, m); /* cheat */
1625
1626 m->m_pkthdr.rcvif = (void *)ni;
1627 IF_ENQUEUE(&ic->ic_mgtq, m); /* cheat */
1158 (*ifp->if_start)(ifp);
1628 if_start(ifp);
1159
1160 return 0;
1161bad:
1162 ieee80211_free_node(ni);
1163 return ret;
1164#undef ADDSHORT
1165#undef senderr
1166}

--- 45 unchanged lines hidden (view full) ---

1212 *frm++ = category;
1213 *frm++ = action;
1214 switch (category) {
1215 case IEEE80211_ACTION_CAT_BA:
1216 switch (action) {
1217 case IEEE80211_ACTION_BA_ADDBA_REQUEST:
1218 IEEE80211_NOTE(ic,
1219 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1629
1630 return 0;
1631bad:
1632 ieee80211_free_node(ni);
1633 return ret;
1634#undef ADDSHORT
1635#undef senderr
1636}

--- 45 unchanged lines hidden (view full) ---

1682 *frm++ = category;
1683 *frm++ = action;
1684 switch (category) {
1685 case IEEE80211_ACTION_CAT_BA:
1686 switch (action) {
1687 case IEEE80211_ACTION_BA_ADDBA_REQUEST:
1688 IEEE80211_NOTE(ic,
1689 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
1220 "send ADDBA request: tid %d, baparamset 0x%x",
1221 args[0], args[1]);
1690 "send ADDBA request: dialogtoken %d "
1691 "baparamset 0x%x (tid %d) batimeout 0x%x baseqctl 0x%x",
1692 args[0], args[1], MS(args[1], IEEE80211_BAPS_TID),
1693 args[2], args[3]);
1222
1223 *frm++ = args[0]; /* dialog token */
1224 ADDSHORT(frm, args[1]); /* baparamset */
1225 ADDSHORT(frm, args[2]); /* batimeout */
1226 ADDSHORT(frm, args[3]); /* baseqctl */
1227 break;
1228 case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
1229 IEEE80211_NOTE(ic,

--- 26 unchanged lines hidden (view full) ---

1256 }
1257 break;
1258 case IEEE80211_ACTION_CAT_HT:
1259 switch (action) {
1260 case IEEE80211_ACTION_HT_TXCHWIDTH:
1261 IEEE80211_NOTE(ic,
1262 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1263 ni, "send HT txchwidth: width %d",
1694
1695 *frm++ = args[0]; /* dialog token */
1696 ADDSHORT(frm, args[1]); /* baparamset */
1697 ADDSHORT(frm, args[2]); /* batimeout */
1698 ADDSHORT(frm, args[3]); /* baseqctl */
1699 break;
1700 case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
1701 IEEE80211_NOTE(ic,

--- 26 unchanged lines hidden (view full) ---

1728 }
1729 break;
1730 case IEEE80211_ACTION_CAT_HT:
1731 switch (action) {
1732 case IEEE80211_ACTION_HT_TXCHWIDTH:
1733 IEEE80211_NOTE(ic,
1734 IEEE80211_MSG_ACTION | IEEE80211_MSG_11N,
1735 ni, "send HT txchwidth: width %d",
1264 IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) ? 40 : 20
1736 IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) ? 40 : 20
1265 );
1266 *frm++ = IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) ?
1267 IEEE80211_A_HT_TXCHWIDTH_2040 :
1268 IEEE80211_A_HT_TXCHWIDTH_20;
1269 break;
1270 default:
1271 goto badaction;
1272 }

--- 49 unchanged lines hidden (view full) ---

1322 frm[1] = (v) >> 8; \
1323 frm += 2; \
1324} while (0)
1325 struct ieee80211com *ic = ni->ni_ic;
1326 uint16_t caps;
1327
1328 /* HT capabilities */
1329 caps = ic->ic_htcaps & 0xffff;
1737 );
1738 *frm++ = IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) ?
1739 IEEE80211_A_HT_TXCHWIDTH_2040 :
1740 IEEE80211_A_HT_TXCHWIDTH_20;
1741 break;
1742 default:
1743 goto badaction;
1744 }

--- 49 unchanged lines hidden (view full) ---

1794 frm[1] = (v) >> 8; \
1795 frm += 2; \
1796} while (0)
1797 struct ieee80211com *ic = ni->ni_ic;
1798 uint16_t caps;
1799
1800 /* HT capabilities */
1801 caps = ic->ic_htcaps & 0xffff;
1330 /* override 20/40 use based on channel and config */
1331 if (IEEE80211_IS_CHAN_HT40(ic->ic_bsschan) &&
1332 (ic->ic_flags_ext & IEEE80211_FEXT_USEHT40))
1333 caps |= IEEE80211_HTCAP_CHWIDTH40;
1334 else
1335 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
1802 /*
1803 * Note channel width depends on whether we are operating as
1804 * a sta or not. When operating as a sta we are generating
1805 * a request based on our desired configuration. Otherwise
1806 * we are operational and the channel attributes identify
1807 * how we've been setup (which might be different if a fixed
1808 * channel is specified).
1809 */
1810 if (ic->ic_opmode == IEEE80211_M_STA) {
1811 /* override 20/40 use based on config */
1812 if (ic->ic_flags_ext & IEEE80211_FEXT_USEHT40)
1813 caps |= IEEE80211_HTCAP_CHWIDTH40;
1814 else
1815 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
1816 } else {
1817 /* override 20/40 use based on current channel */
1818 if (IEEE80211_IS_CHAN_HT40(ic->ic_bsschan))
1819 caps |= IEEE80211_HTCAP_CHWIDTH40;
1820 else
1821 caps &= ~IEEE80211_HTCAP_CHWIDTH40;
1822 }
1336 /* adjust short GI based on channel and config */
1337 if ((ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI20) == 0)
1338 caps &= ~IEEE80211_HTCAP_SHORTGI20;
1339 if ((ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI40) == 0 ||
1340 (caps & IEEE80211_HTCAP_CHWIDTH40) == 0)
1341 caps &= ~IEEE80211_HTCAP_SHORTGI40;
1342 ADDSHORT(frm, caps);
1343
1344 /* HT parameters */
1823 /* adjust short GI based on channel and config */
1824 if ((ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI20) == 0)
1825 caps &= ~IEEE80211_HTCAP_SHORTGI20;
1826 if ((ic->ic_flags_ext & IEEE80211_FEXT_SHORTGI40) == 0 ||
1827 (caps & IEEE80211_HTCAP_CHWIDTH40) == 0)
1828 caps &= ~IEEE80211_HTCAP_SHORTGI40;
1829 ADDSHORT(frm, caps);
1830
1831 /* HT parameters */
1345 switch (ic->ic_ampdu_rxmax / 1024) {
1346 case 8: *frm = IEEE80211_HTCAP_MAXRXAMPDU_8K; break;
1347 case 16: *frm = IEEE80211_HTCAP_MAXRXAMPDU_16K; break;
1348 case 32: *frm = IEEE80211_HTCAP_MAXRXAMPDU_32K; break;
1349 default: *frm = IEEE80211_HTCAP_MAXRXAMPDU_64K; break;
1350 }
1351 *frm |= SM(ic->ic_ampdu_density, IEEE80211_HTCAP_MPDUDENSITY);
1832 *frm = SM(ic->ic_ampdu_rxmax, IEEE80211_HTCAP_MAXRXAMPDU)
1833 | SM(ic->ic_ampdu_density, IEEE80211_HTCAP_MPDUDENSITY)
1834 ;
1352 frm++;
1353
1354 /* pre-zero remainder of ie */
1355 memset(frm, 0, sizeof(struct ieee80211_ie_htcap) -
1356 __offsetof(struct ieee80211_ie_htcap, hc_mcsset));
1357
1358 /* supported MCS set */
1835 frm++;
1836
1837 /* pre-zero remainder of ie */
1838 memset(frm, 0, sizeof(struct ieee80211_ie_htcap) -
1839 __offsetof(struct ieee80211_ie_htcap, hc_mcsset));
1840
1841 /* supported MCS set */
1359 ieee80211_set_htrates(frm, &ni->ni_htrates);
1842 /*
1843 * XXX it would better to get the rate set from ni_htrates
1844 * so we can restrict it but for sta mode ni_htrates isn't
1845 * setup when we're called to form an AssocReq frame so for
1846 * now we're restricted to the default HT rate set.
1847 */
1848 ieee80211_set_htrates(frm, &ieee80211_rateset_11n);
1360
1361 frm += sizeof(struct ieee80211_ie_htcap) -
1362 __offsetof(struct ieee80211_ie_htcap, hc_mcsset);
1363 return frm;
1364#undef ADDSHORT
1365}
1366
1367/*

--- 69 unchanged lines hidden (view full) ---

1437 ht->hi_byte2 = (ht->hi_byte2 &~ PROTMODE) | ic->ic_curhtprotmode;
1438
1439 /* XXX propagate to vendor ie's */
1440#undef PROTMODE
1441}
1442
1443/*
1444 * Add body of an HTINFO information element.
1849
1850 frm += sizeof(struct ieee80211_ie_htcap) -
1851 __offsetof(struct ieee80211_ie_htcap, hc_mcsset);
1852 return frm;
1853#undef ADDSHORT
1854}
1855
1856/*

--- 69 unchanged lines hidden (view full) ---

1926 ht->hi_byte2 = (ht->hi_byte2 &~ PROTMODE) | ic->ic_curhtprotmode;
1927
1928 /* XXX propagate to vendor ie's */
1929#undef PROTMODE
1930}
1931
1932/*
1933 * Add body of an HTINFO information element.
1934 *
1935 * NB: We don't use struct ieee80211_ie_htinfo because we can
1936 * be called to fillin both a standard ie and a compat ie that
1937 * has a vendor OUI at the front.
1445 */
1446static uint8_t *
1447ieee80211_add_htinfo_body(uint8_t *frm, struct ieee80211_node *ni)
1448{
1449 struct ieee80211com *ic = ni->ni_ic;
1450
1451 /* pre-zero remainder of ie */
1452 memset(frm, 0, sizeof(struct ieee80211_ie_htinfo) - 2);

--- 51 unchanged lines hidden ---
1938 */
1939static uint8_t *
1940ieee80211_add_htinfo_body(uint8_t *frm, struct ieee80211_node *ni)
1941{
1942 struct ieee80211com *ic = ni->ni_ic;
1943
1944 /* pre-zero remainder of ie */
1945 memset(frm, 0, sizeof(struct ieee80211_ie_htinfo) - 2);

--- 51 unchanged lines hidden ---