1616190d0SSam Leffler /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni *
4616190d0SSam Leffler * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5616190d0SSam Leffler * All rights reserved.
6616190d0SSam Leffler *
7616190d0SSam Leffler * Redistribution and use in source and binary forms, with or without
8616190d0SSam Leffler * modification, are permitted provided that the following conditions
9616190d0SSam Leffler * are met:
10616190d0SSam Leffler * 1. Redistributions of source code must retain the above copyright
11616190d0SSam Leffler * notice, this list of conditions and the following disclaimer.
12616190d0SSam Leffler * 2. Redistributions in binary form must reproduce the above copyright
13616190d0SSam Leffler * notice, this list of conditions and the following disclaimer in the
14616190d0SSam Leffler * documentation and/or other materials provided with the distribution.
15616190d0SSam Leffler *
16616190d0SSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17616190d0SSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18616190d0SSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19616190d0SSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20616190d0SSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21616190d0SSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22616190d0SSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23616190d0SSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24616190d0SSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25616190d0SSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26616190d0SSam Leffler */
27616190d0SSam Leffler
28616190d0SSam Leffler #include <sys/cdefs.h>
29616190d0SSam Leffler #include "opt_wlan.h"
30616190d0SSam Leffler
319da01550SAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG
329da01550SAdrian Chadd
33616190d0SSam Leffler #include <sys/param.h>
34616190d0SSam Leffler #include <sys/systm.h>
35616190d0SSam Leffler #include <sys/mbuf.h>
36616190d0SSam Leffler #include <sys/kernel.h>
37616190d0SSam Leffler #include <sys/endian.h>
38616190d0SSam Leffler
39616190d0SSam Leffler #include <sys/socket.h>
40616190d0SSam Leffler
41616190d0SSam Leffler #include <net/if.h>
42104dc214SGleb Smirnoff #include <net/if_var.h>
43616190d0SSam Leffler #include <net/if_llc.h>
44616190d0SSam Leffler #include <net/if_media.h>
45104dc214SGleb Smirnoff #include <net/bpf.h>
46104dc214SGleb Smirnoff #include <net/ethernet.h>
47616190d0SSam Leffler
48616190d0SSam Leffler #include <net80211/ieee80211_var.h>
49616190d0SSam Leffler #include <net80211/ieee80211_input.h>
50616190d0SSam Leffler #include <net80211/ieee80211_phy.h>
51616190d0SSam Leffler #include <net80211/ieee80211_superg.h>
52616190d0SSam Leffler
539d90db93SSam Leffler /*
549d90db93SSam Leffler * Atheros fast-frame encapsulation format.
559d90db93SSam Leffler * FF max payload:
569d90db93SSam Leffler * 802.2 + FFHDR + HPAD + 802.3 + 802.2 + 1500 + SPAD + 802.3 + 802.2 + 1500:
579d90db93SSam Leffler * 8 + 4 + 4 + 14 + 8 + 1500 + 6 + 14 + 8 + 1500
589d90db93SSam Leffler * = 3066
599d90db93SSam Leffler */
609d90db93SSam Leffler /* fast frame header is 32-bits */
619d90db93SSam Leffler #define ATH_FF_PROTO 0x0000003f /* protocol */
629d90db93SSam Leffler #define ATH_FF_PROTO_S 0
639d90db93SSam Leffler #define ATH_FF_FTYPE 0x000000c0 /* frame type */
649d90db93SSam Leffler #define ATH_FF_FTYPE_S 6
659d90db93SSam Leffler #define ATH_FF_HLEN32 0x00000300 /* optional hdr length */
669d90db93SSam Leffler #define ATH_FF_HLEN32_S 8
679d90db93SSam Leffler #define ATH_FF_SEQNUM 0x001ffc00 /* sequence number */
689d90db93SSam Leffler #define ATH_FF_SEQNUM_S 10
699d90db93SSam Leffler #define ATH_FF_OFFSET 0xffe00000 /* offset to 2nd payload */
709d90db93SSam Leffler #define ATH_FF_OFFSET_S 21
719d90db93SSam Leffler
729d90db93SSam Leffler #define ATH_FF_MAX_HDR_PAD 4
739d90db93SSam Leffler #define ATH_FF_MAX_SEP_PAD 6
749d90db93SSam Leffler #define ATH_FF_MAX_HDR 30
759d90db93SSam Leffler
769d90db93SSam Leffler #define ATH_FF_PROTO_L2TUNNEL 0 /* L2 tunnel protocol */
779d90db93SSam Leffler #define ATH_FF_ETH_TYPE 0x88bd /* Ether type for encapsulated frames */
789d90db93SSam Leffler #define ATH_FF_SNAP_ORGCODE_0 0x00
799d90db93SSam Leffler #define ATH_FF_SNAP_ORGCODE_1 0x03
809d90db93SSam Leffler #define ATH_FF_SNAP_ORGCODE_2 0x7f
819d90db93SSam Leffler
82339ccfb3SSam Leffler #define ATH_FF_TXQMIN 2 /* min txq depth for staging */
83339ccfb3SSam Leffler #define ATH_FF_TXQMAX 50 /* maximum # of queued frames allowed */
84339ccfb3SSam Leffler #define ATH_FF_STAGEMAX 5 /* max waiting period for staged frame*/
85339ccfb3SSam Leffler
86616190d0SSam Leffler #define ETHER_HEADER_COPY(dst, src) \
87616190d0SSam Leffler memcpy(dst, src, sizeof(struct ether_header))
88616190d0SSam Leffler
89a77b10b3SSam Leffler static int ieee80211_ffppsmin = 2; /* pps threshold for ff aggregation */
90f0188618SHans Petter Selasky SYSCTL_INT(_net_wlan, OID_AUTO, ffppsmin, CTLFLAG_RW,
91a77b10b3SSam Leffler &ieee80211_ffppsmin, 0, "min packet rate before fast-frame staging");
92a77b10b3SSam Leffler static int ieee80211_ffagemax = -1; /* max time frames held on stage q */
9308f5e6bbSPawel Biernacki SYSCTL_PROC(_net_wlan, OID_AUTO, ffagemax,
9408f5e6bbSPawel Biernacki CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
95a77b10b3SSam Leffler &ieee80211_ffagemax, 0, ieee80211_sysctl_msecs_ticks, "I",
96a77b10b3SSam Leffler "max hold time for fast-frame staging (ms)");
97339ccfb3SSam Leffler
98abb0adffSAndriy Voskoboinyk static void
ff_age_all(void * arg,int npending)99abb0adffSAndriy Voskoboinyk ff_age_all(void *arg, int npending)
100abb0adffSAndriy Voskoboinyk {
101abb0adffSAndriy Voskoboinyk struct ieee80211com *ic = arg;
102abb0adffSAndriy Voskoboinyk
103abb0adffSAndriy Voskoboinyk /* XXX cache timer value somewhere (racy) */
104abb0adffSAndriy Voskoboinyk ieee80211_ff_age_all(ic, ieee80211_ffagemax + 1);
105abb0adffSAndriy Voskoboinyk }
106abb0adffSAndriy Voskoboinyk
107616190d0SSam Leffler void
ieee80211_superg_attach(struct ieee80211com * ic)108616190d0SSam Leffler ieee80211_superg_attach(struct ieee80211com *ic)
109616190d0SSam Leffler {
11004f19fd6SSam Leffler struct ieee80211_superg *sg;
11104f19fd6SSam Leffler
112cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_LOCK_INIT(ic, ic->ic_name);
113cdc0cf21SAndriy Voskoboinyk
114b9b53389SAdrian Chadd sg = (struct ieee80211_superg *) IEEE80211_MALLOC(
11504f19fd6SSam Leffler sizeof(struct ieee80211_superg), M_80211_VAP,
116b9b53389SAdrian Chadd IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
11704f19fd6SSam Leffler if (sg == NULL) {
11804f19fd6SSam Leffler printf("%s: cannot allocate SuperG state block\n",
11904f19fd6SSam Leffler __func__);
12004f19fd6SSam Leffler return;
12104f19fd6SSam Leffler }
122abb0adffSAndriy Voskoboinyk TIMEOUT_TASK_INIT(ic->ic_tq, &sg->ff_qtimer, 0, ff_age_all, ic);
12304f19fd6SSam Leffler ic->ic_superg = sg;
1241c7b0c84SAdrian Chadd
1251c7b0c84SAdrian Chadd /*
1261c7b0c84SAdrian Chadd * Default to not being so aggressive for FF/AMSDU
1271c7b0c84SAdrian Chadd * aging, otherwise we may hold a frame around
1281c7b0c84SAdrian Chadd * for way too long before we expire it out.
1291c7b0c84SAdrian Chadd */
1301c7b0c84SAdrian Chadd ieee80211_ffagemax = msecs_to_ticks(2);
131616190d0SSam Leffler }
132616190d0SSam Leffler
133616190d0SSam Leffler void
ieee80211_superg_detach(struct ieee80211com * ic)134616190d0SSam Leffler ieee80211_superg_detach(struct ieee80211com *ic)
135616190d0SSam Leffler {
136cdc0cf21SAndriy Voskoboinyk
13704f19fd6SSam Leffler if (ic->ic_superg != NULL) {
138abb0adffSAndriy Voskoboinyk struct timeout_task *qtask = &ic->ic_superg->ff_qtimer;
139abb0adffSAndriy Voskoboinyk
140abb0adffSAndriy Voskoboinyk while (taskqueue_cancel_timeout(ic->ic_tq, qtask, NULL) != 0)
141abb0adffSAndriy Voskoboinyk taskqueue_drain_timeout(ic->ic_tq, qtask);
142b9b53389SAdrian Chadd IEEE80211_FREE(ic->ic_superg, M_80211_VAP);
14304f19fd6SSam Leffler ic->ic_superg = NULL;
14404f19fd6SSam Leffler }
145abb0adffSAndriy Voskoboinyk IEEE80211_FF_LOCK_DESTROY(ic);
146616190d0SSam Leffler }
147616190d0SSam Leffler
148616190d0SSam Leffler void
ieee80211_superg_vattach(struct ieee80211vap * vap)149616190d0SSam Leffler ieee80211_superg_vattach(struct ieee80211vap *vap)
150616190d0SSam Leffler {
15104f19fd6SSam Leffler struct ieee80211com *ic = vap->iv_ic;
15204f19fd6SSam Leffler
15304f19fd6SSam Leffler if (ic->ic_superg == NULL) /* NB: can't do fast-frames w/o state */
15404f19fd6SSam Leffler vap->iv_caps &= ~IEEE80211_C_FF;
155616190d0SSam Leffler if (vap->iv_caps & IEEE80211_C_FF)
156616190d0SSam Leffler vap->iv_flags |= IEEE80211_F_FF;
157aeab3282SSam Leffler /* NB: we only implement sta mode */
158aeab3282SSam Leffler if (vap->iv_opmode == IEEE80211_M_STA &&
159aeab3282SSam Leffler (vap->iv_caps & IEEE80211_C_TURBOP))
160616190d0SSam Leffler vap->iv_flags |= IEEE80211_F_TURBOP;
161616190d0SSam Leffler }
162616190d0SSam Leffler
163616190d0SSam Leffler void
ieee80211_superg_vdetach(struct ieee80211vap * vap)164616190d0SSam Leffler ieee80211_superg_vdetach(struct ieee80211vap *vap)
165616190d0SSam Leffler {
166616190d0SSam Leffler }
167616190d0SSam Leffler
168616190d0SSam Leffler #define ATH_OUI_BYTES 0x00, 0x03, 0x7f
169616190d0SSam Leffler /*
170616190d0SSam Leffler * Add a WME information element to a frame.
171616190d0SSam Leffler */
172616190d0SSam Leffler uint8_t *
ieee80211_add_ath(uint8_t * frm,uint8_t caps,ieee80211_keyix defkeyix)1734207227cSSam Leffler ieee80211_add_ath(uint8_t *frm, uint8_t caps, ieee80211_keyix defkeyix)
174616190d0SSam Leffler {
175616190d0SSam Leffler static const struct ieee80211_ath_ie info = {
176616190d0SSam Leffler .ath_id = IEEE80211_ELEMID_VENDOR,
177616190d0SSam Leffler .ath_len = sizeof(struct ieee80211_ath_ie) - 2,
178616190d0SSam Leffler .ath_oui = { ATH_OUI_BYTES },
179616190d0SSam Leffler .ath_oui_type = ATH_OUI_TYPE,
180616190d0SSam Leffler .ath_oui_subtype= ATH_OUI_SUBTYPE,
181616190d0SSam Leffler .ath_version = ATH_OUI_VERSION,
182616190d0SSam Leffler };
183616190d0SSam Leffler struct ieee80211_ath_ie *ath = (struct ieee80211_ath_ie *) frm;
184616190d0SSam Leffler
185616190d0SSam Leffler memcpy(frm, &info, sizeof(info));
186616190d0SSam Leffler ath->ath_capability = caps;
1874207227cSSam Leffler if (defkeyix != IEEE80211_KEYIX_NONE) {
188616190d0SSam Leffler ath->ath_defkeyix[0] = (defkeyix & 0xff);
189616190d0SSam Leffler ath->ath_defkeyix[1] = ((defkeyix >> 8) & 0xff);
1904207227cSSam Leffler } else {
1914207227cSSam Leffler ath->ath_defkeyix[0] = 0xff;
1924207227cSSam Leffler ath->ath_defkeyix[1] = 0x7f;
1934207227cSSam Leffler }
194616190d0SSam Leffler return frm + sizeof(info);
195616190d0SSam Leffler }
196616190d0SSam Leffler #undef ATH_OUI_BYTES
197616190d0SSam Leffler
1984207227cSSam Leffler uint8_t *
ieee80211_add_athcaps(uint8_t * frm,const struct ieee80211_node * bss)1994207227cSSam Leffler ieee80211_add_athcaps(uint8_t *frm, const struct ieee80211_node *bss)
2004207227cSSam Leffler {
2014207227cSSam Leffler const struct ieee80211vap *vap = bss->ni_vap;
2024207227cSSam Leffler
2034207227cSSam Leffler return ieee80211_add_ath(frm,
2044207227cSSam Leffler vap->iv_flags & IEEE80211_F_ATHEROS,
2054207227cSSam Leffler ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
2064207227cSSam Leffler bss->ni_authmode != IEEE80211_AUTH_8021X) ?
2074207227cSSam Leffler vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
2084207227cSSam Leffler }
2094207227cSSam Leffler
210616190d0SSam Leffler void
ieee80211_parse_ath(struct ieee80211_node * ni,uint8_t * ie)211616190d0SSam Leffler ieee80211_parse_ath(struct ieee80211_node *ni, uint8_t *ie)
212616190d0SSam Leffler {
213616190d0SSam Leffler const struct ieee80211_ath_ie *ath =
214616190d0SSam Leffler (const struct ieee80211_ath_ie *) ie;
215616190d0SSam Leffler
216616190d0SSam Leffler ni->ni_ath_flags = ath->ath_capability;
21731021a2bSAndriy Voskoboinyk ni->ni_ath_defkeyix = le16dec(&ath->ath_defkeyix);
218616190d0SSam Leffler }
219616190d0SSam Leffler
220616190d0SSam Leffler int
ieee80211_parse_athparams(struct ieee80211_node * ni,uint8_t * frm,const struct ieee80211_frame * wh)221616190d0SSam Leffler ieee80211_parse_athparams(struct ieee80211_node *ni, uint8_t *frm,
222616190d0SSam Leffler const struct ieee80211_frame *wh)
223616190d0SSam Leffler {
224616190d0SSam Leffler struct ieee80211vap *vap = ni->ni_vap;
225616190d0SSam Leffler const struct ieee80211_ath_ie *ath;
226616190d0SSam Leffler u_int len = frm[1];
227616190d0SSam Leffler int capschanged;
228616190d0SSam Leffler uint16_t defkeyix;
229616190d0SSam Leffler
230616190d0SSam Leffler if (len < sizeof(struct ieee80211_ath_ie)-2) {
231616190d0SSam Leffler IEEE80211_DISCARD_IE(vap,
232616190d0SSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_SUPERG,
233616190d0SSam Leffler wh, "Atheros", "too short, len %u", len);
234616190d0SSam Leffler return -1;
235616190d0SSam Leffler }
236616190d0SSam Leffler ath = (const struct ieee80211_ath_ie *)frm;
237616190d0SSam Leffler capschanged = (ni->ni_ath_flags != ath->ath_capability);
23831021a2bSAndriy Voskoboinyk defkeyix = le16dec(ath->ath_defkeyix);
239616190d0SSam Leffler if (capschanged || defkeyix != ni->ni_ath_defkeyix) {
240616190d0SSam Leffler ni->ni_ath_flags = ath->ath_capability;
241616190d0SSam Leffler ni->ni_ath_defkeyix = defkeyix;
242616190d0SSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
243616190d0SSam Leffler "ath ie change: new caps 0x%x defkeyix 0x%x",
244616190d0SSam Leffler ni->ni_ath_flags, ni->ni_ath_defkeyix);
245616190d0SSam Leffler }
246616190d0SSam Leffler if (IEEE80211_ATH_CAP(vap, ni, ATHEROS_CAP_TURBO_PRIME)) {
247616190d0SSam Leffler uint16_t curflags, newflags;
248616190d0SSam Leffler
249616190d0SSam Leffler /*
250616190d0SSam Leffler * Check for turbo mode switch. Calculate flags
251616190d0SSam Leffler * for the new mode and effect the switch.
252616190d0SSam Leffler */
253616190d0SSam Leffler newflags = curflags = vap->iv_ic->ic_bsschan->ic_flags;
254616190d0SSam Leffler /* NB: BOOST is not in ic_flags, so get it from the ie */
255616190d0SSam Leffler if (ath->ath_capability & ATHEROS_CAP_BOOST)
256616190d0SSam Leffler newflags |= IEEE80211_CHAN_TURBO;
257616190d0SSam Leffler else
258616190d0SSam Leffler newflags &= ~IEEE80211_CHAN_TURBO;
259616190d0SSam Leffler if (newflags != curflags)
260616190d0SSam Leffler ieee80211_dturbo_switch(vap, newflags);
261616190d0SSam Leffler }
262616190d0SSam Leffler return capschanged;
263616190d0SSam Leffler }
264616190d0SSam Leffler
265616190d0SSam Leffler /*
266616190d0SSam Leffler * Decap the encapsulated frame pair and dispatch the first
267616190d0SSam Leffler * for delivery. The second frame is returned for delivery
268616190d0SSam Leffler * via the normal path.
269616190d0SSam Leffler */
270616190d0SSam Leffler struct mbuf *
ieee80211_ff_decap(struct ieee80211_node * ni,struct mbuf * m)271616190d0SSam Leffler ieee80211_ff_decap(struct ieee80211_node *ni, struct mbuf *m)
272616190d0SSam Leffler {
273616190d0SSam Leffler #define FF_LLC_SIZE (sizeof(struct ether_header) + sizeof(struct llc))
274616190d0SSam Leffler struct ieee80211vap *vap = ni->ni_vap;
275616190d0SSam Leffler struct llc *llc;
276616190d0SSam Leffler uint32_t ath;
277616190d0SSam Leffler struct mbuf *n;
278616190d0SSam Leffler int framelen;
279616190d0SSam Leffler
280616190d0SSam Leffler /* NB: we assume caller does this check for us */
281616190d0SSam Leffler KASSERT(IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF),
282616190d0SSam Leffler ("ff not negotiated"));
283616190d0SSam Leffler /*
284616190d0SSam Leffler * Check for fast-frame tunnel encapsulation.
285616190d0SSam Leffler */
286616190d0SSam Leffler if (m->m_pkthdr.len < 3*FF_LLC_SIZE)
287616190d0SSam Leffler return m;
288616190d0SSam Leffler if (m->m_len < FF_LLC_SIZE &&
289616190d0SSam Leffler (m = m_pullup(m, FF_LLC_SIZE)) == NULL) {
290616190d0SSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
291616190d0SSam Leffler ni->ni_macaddr, "fast-frame",
292616190d0SSam Leffler "%s", "m_pullup(llc) failed");
293616190d0SSam Leffler vap->iv_stats.is_rx_tooshort++;
294616190d0SSam Leffler return NULL;
295616190d0SSam Leffler }
296616190d0SSam Leffler llc = (struct llc *)(mtod(m, uint8_t *) +
297616190d0SSam Leffler sizeof(struct ether_header));
298616190d0SSam Leffler if (llc->llc_snap.ether_type != htons(ATH_FF_ETH_TYPE))
299616190d0SSam Leffler return m;
300616190d0SSam Leffler m_adj(m, FF_LLC_SIZE);
301616190d0SSam Leffler m_copydata(m, 0, sizeof(uint32_t), (caddr_t) &ath);
302fe5ebb23SBjoern A. Zeeb if (_IEEE80211_MASKSHIFT(ath, ATH_FF_PROTO) != ATH_FF_PROTO_L2TUNNEL) {
303616190d0SSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
304616190d0SSam Leffler ni->ni_macaddr, "fast-frame",
305616190d0SSam Leffler "unsupport tunnel protocol, header 0x%x", ath);
306616190d0SSam Leffler vap->iv_stats.is_ff_badhdr++;
307616190d0SSam Leffler m_freem(m);
308616190d0SSam Leffler return NULL;
309616190d0SSam Leffler }
310616190d0SSam Leffler /* NB: skip header and alignment padding */
311616190d0SSam Leffler m_adj(m, roundup(sizeof(uint32_t) - 2, 4) + 2);
312616190d0SSam Leffler
313616190d0SSam Leffler vap->iv_stats.is_ff_decap++;
314616190d0SSam Leffler
315616190d0SSam Leffler /*
316616190d0SSam Leffler * Decap the first frame, bust it apart from the
317616190d0SSam Leffler * second and deliver; then decap the second frame
318616190d0SSam Leffler * and return it to the caller for normal delivery.
319616190d0SSam Leffler */
320616190d0SSam Leffler m = ieee80211_decap1(m, &framelen);
321616190d0SSam Leffler if (m == NULL) {
322616190d0SSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
323616190d0SSam Leffler ni->ni_macaddr, "fast-frame", "%s", "first decap failed");
324616190d0SSam Leffler vap->iv_stats.is_ff_tooshort++;
325616190d0SSam Leffler return NULL;
326616190d0SSam Leffler }
327bd29f817SBjoern A. Zeeb n = m_split(m, framelen, IEEE80211_M_NOWAIT);
328616190d0SSam Leffler if (n == NULL) {
329616190d0SSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
330616190d0SSam Leffler ni->ni_macaddr, "fast-frame",
331616190d0SSam Leffler "%s", "unable to split encapsulated frames");
332616190d0SSam Leffler vap->iv_stats.is_ff_split++;
333616190d0SSam Leffler m_freem(m); /* NB: must reclaim */
334616190d0SSam Leffler return NULL;
335616190d0SSam Leffler }
336616190d0SSam Leffler /* XXX not right for WDS */
337616190d0SSam Leffler vap->iv_deliver_data(vap, ni, m); /* 1st of pair */
338616190d0SSam Leffler
339616190d0SSam Leffler /*
340616190d0SSam Leffler * Decap second frame.
341616190d0SSam Leffler */
342616190d0SSam Leffler m_adj(n, roundup2(framelen, 4) - framelen); /* padding */
343616190d0SSam Leffler n = ieee80211_decap1(n, &framelen);
344616190d0SSam Leffler if (n == NULL) {
345616190d0SSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
346616190d0SSam Leffler ni->ni_macaddr, "fast-frame", "%s", "second decap failed");
347616190d0SSam Leffler vap->iv_stats.is_ff_tooshort++;
348616190d0SSam Leffler }
349616190d0SSam Leffler /* XXX verify framelen against mbuf contents */
350616190d0SSam Leffler return n; /* 2nd delivered by caller */
351616190d0SSam Leffler #undef FF_LLC_SIZE
352616190d0SSam Leffler }
353616190d0SSam Leffler
354616190d0SSam Leffler /*
355616190d0SSam Leffler * Fast frame encapsulation. There must be two packets
356616190d0SSam Leffler * chained with m_nextpkt. We do header adjustment for
357616190d0SSam Leffler * each, add the tunnel encapsulation, and then concatenate
358616190d0SSam Leffler * the mbuf chains to form a single frame for transmission.
359616190d0SSam Leffler */
360616190d0SSam Leffler struct mbuf *
ieee80211_ff_encap(struct ieee80211vap * vap,struct mbuf * m1,int hdrspace,struct ieee80211_key * key)361616190d0SSam Leffler ieee80211_ff_encap(struct ieee80211vap *vap, struct mbuf *m1, int hdrspace,
362616190d0SSam Leffler struct ieee80211_key *key)
363616190d0SSam Leffler {
364616190d0SSam Leffler struct mbuf *m2;
365616190d0SSam Leffler struct ether_header eh1, eh2;
366616190d0SSam Leffler struct llc *llc;
367616190d0SSam Leffler struct mbuf *m;
368616190d0SSam Leffler int pad;
369616190d0SSam Leffler
370616190d0SSam Leffler m2 = m1->m_nextpkt;
371616190d0SSam Leffler if (m2 == NULL) {
372616190d0SSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
373616190d0SSam Leffler "%s: only one frame\n", __func__);
374616190d0SSam Leffler goto bad;
375616190d0SSam Leffler }
376616190d0SSam Leffler m1->m_nextpkt = NULL;
3771c7b0c84SAdrian Chadd
378616190d0SSam Leffler /*
3791c7b0c84SAdrian Chadd * Adjust to include 802.11 header requirement.
3801c7b0c84SAdrian Chadd */
3811c7b0c84SAdrian Chadd KASSERT(m1->m_len >= sizeof(eh1), ("no ethernet header!"));
3821c7b0c84SAdrian Chadd ETHER_HEADER_COPY(&eh1, mtod(m1, caddr_t));
3831c7b0c84SAdrian Chadd m1 = ieee80211_mbuf_adjust(vap, hdrspace, key, m1);
3841c7b0c84SAdrian Chadd if (m1 == NULL) {
3851c7b0c84SAdrian Chadd printf("%s: failed initial mbuf_adjust\n", __func__);
3861c7b0c84SAdrian Chadd /* NB: ieee80211_mbuf_adjust handles msgs+statistics */
3871c7b0c84SAdrian Chadd m_freem(m2);
3881c7b0c84SAdrian Chadd goto bad;
3891c7b0c84SAdrian Chadd }
3901c7b0c84SAdrian Chadd
3911c7b0c84SAdrian Chadd /*
3921c7b0c84SAdrian Chadd * Copy second frame's Ethernet header out of line
3931c7b0c84SAdrian Chadd * and adjust for possible padding in case there isn't room
3941c7b0c84SAdrian Chadd * at the end of first frame.
3951c7b0c84SAdrian Chadd */
3961c7b0c84SAdrian Chadd KASSERT(m2->m_len >= sizeof(eh2), ("no ethernet header!"));
3971c7b0c84SAdrian Chadd ETHER_HEADER_COPY(&eh2, mtod(m2, caddr_t));
3981c7b0c84SAdrian Chadd m2 = ieee80211_mbuf_adjust(vap, 4, NULL, m2);
3991c7b0c84SAdrian Chadd if (m2 == NULL) {
4001c7b0c84SAdrian Chadd /* NB: ieee80211_mbuf_adjust handles msgs+statistics */
4011c7b0c84SAdrian Chadd printf("%s: failed second \n", __func__);
4021c7b0c84SAdrian Chadd goto bad;
4031c7b0c84SAdrian Chadd }
4041c7b0c84SAdrian Chadd
4051c7b0c84SAdrian Chadd /*
4061c7b0c84SAdrian Chadd * Now do tunnel encapsulation. First, each
4071c7b0c84SAdrian Chadd * frame gets a standard encapsulation.
4081c7b0c84SAdrian Chadd */
4091c7b0c84SAdrian Chadd m1 = ieee80211_ff_encap1(vap, m1, &eh1);
4101c7b0c84SAdrian Chadd if (m1 == NULL)
4111c7b0c84SAdrian Chadd goto bad;
4121c7b0c84SAdrian Chadd m2 = ieee80211_ff_encap1(vap, m2, &eh2);
4131c7b0c84SAdrian Chadd if (m2 == NULL)
4141c7b0c84SAdrian Chadd goto bad;
4151c7b0c84SAdrian Chadd
4161c7b0c84SAdrian Chadd /*
4171c7b0c84SAdrian Chadd * Pad leading frame to a 4-byte boundary. If there
4181c7b0c84SAdrian Chadd * is space at the end of the first frame, put it
4191c7b0c84SAdrian Chadd * there; otherwise prepend to the front of the second
4201c7b0c84SAdrian Chadd * frame. We know doing the second will always work
4211c7b0c84SAdrian Chadd * because we reserve space above. We prefer appending
4221c7b0c84SAdrian Chadd * as this typically has better DMA alignment properties.
4231c7b0c84SAdrian Chadd */
4241c7b0c84SAdrian Chadd for (m = m1; m->m_next != NULL; m = m->m_next)
4251c7b0c84SAdrian Chadd ;
4261c7b0c84SAdrian Chadd pad = roundup2(m1->m_pkthdr.len, 4) - m1->m_pkthdr.len;
4271c7b0c84SAdrian Chadd if (pad) {
4281c7b0c84SAdrian Chadd if (M_TRAILINGSPACE(m) < pad) { /* prepend to second */
4291c7b0c84SAdrian Chadd m2->m_data -= pad;
4301c7b0c84SAdrian Chadd m2->m_len += pad;
4311c7b0c84SAdrian Chadd m2->m_pkthdr.len += pad;
4321c7b0c84SAdrian Chadd } else { /* append to first */
4331c7b0c84SAdrian Chadd m->m_len += pad;
4341c7b0c84SAdrian Chadd m1->m_pkthdr.len += pad;
4351c7b0c84SAdrian Chadd }
4361c7b0c84SAdrian Chadd }
4371c7b0c84SAdrian Chadd
4381c7b0c84SAdrian Chadd /*
4391c7b0c84SAdrian Chadd * A-MSDU's are just appended; the "I'm A-MSDU!" bit is in the
4401c7b0c84SAdrian Chadd * QoS header.
4411c7b0c84SAdrian Chadd *
4421c7b0c84SAdrian Chadd * XXX optimize by prepending together
4431c7b0c84SAdrian Chadd */
4441c7b0c84SAdrian Chadd m->m_next = m2; /* NB: last mbuf from above */
4451c7b0c84SAdrian Chadd m1->m_pkthdr.len += m2->m_pkthdr.len;
446bd29f817SBjoern A. Zeeb M_PREPEND(m1, sizeof(uint32_t)+2, IEEE80211_M_NOWAIT);
4471c7b0c84SAdrian Chadd if (m1 == NULL) { /* XXX cannot happen */
4481c7b0c84SAdrian Chadd IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
4491c7b0c84SAdrian Chadd "%s: no space for tunnel header\n", __func__);
4501c7b0c84SAdrian Chadd vap->iv_stats.is_tx_nobuf++;
4511c7b0c84SAdrian Chadd return NULL;
4521c7b0c84SAdrian Chadd }
4531c7b0c84SAdrian Chadd memset(mtod(m1, void *), 0, sizeof(uint32_t)+2);
4541c7b0c84SAdrian Chadd
455bd29f817SBjoern A. Zeeb M_PREPEND(m1, sizeof(struct llc), IEEE80211_M_NOWAIT);
4561c7b0c84SAdrian Chadd if (m1 == NULL) { /* XXX cannot happen */
4571c7b0c84SAdrian Chadd IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
4581c7b0c84SAdrian Chadd "%s: no space for llc header\n", __func__);
4591c7b0c84SAdrian Chadd vap->iv_stats.is_tx_nobuf++;
4601c7b0c84SAdrian Chadd return NULL;
4611c7b0c84SAdrian Chadd }
4621c7b0c84SAdrian Chadd llc = mtod(m1, struct llc *);
4631c7b0c84SAdrian Chadd llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
4641c7b0c84SAdrian Chadd llc->llc_control = LLC_UI;
4651c7b0c84SAdrian Chadd llc->llc_snap.org_code[0] = ATH_FF_SNAP_ORGCODE_0;
4661c7b0c84SAdrian Chadd llc->llc_snap.org_code[1] = ATH_FF_SNAP_ORGCODE_1;
4671c7b0c84SAdrian Chadd llc->llc_snap.org_code[2] = ATH_FF_SNAP_ORGCODE_2;
4681c7b0c84SAdrian Chadd llc->llc_snap.ether_type = htons(ATH_FF_ETH_TYPE);
4691c7b0c84SAdrian Chadd
4701c7b0c84SAdrian Chadd vap->iv_stats.is_ff_encap++;
4711c7b0c84SAdrian Chadd
4721c7b0c84SAdrian Chadd return m1;
4731c7b0c84SAdrian Chadd bad:
4741c7b0c84SAdrian Chadd vap->iv_stats.is_ff_encapfail++;
4751c7b0c84SAdrian Chadd if (m1 != NULL)
4761c7b0c84SAdrian Chadd m_freem(m1);
4771c7b0c84SAdrian Chadd if (m2 != NULL)
4781c7b0c84SAdrian Chadd m_freem(m2);
4791c7b0c84SAdrian Chadd return NULL;
4801c7b0c84SAdrian Chadd }
4811c7b0c84SAdrian Chadd
4821c7b0c84SAdrian Chadd /*
4831c7b0c84SAdrian Chadd * A-MSDU encapsulation.
4841c7b0c84SAdrian Chadd *
4851c7b0c84SAdrian Chadd * This assumes just two frames for now, since we're borrowing the
4861c7b0c84SAdrian Chadd * same queuing code and infrastructure as fast-frames.
4871c7b0c84SAdrian Chadd *
4881c7b0c84SAdrian Chadd * There must be two packets chained with m_nextpkt.
4891c7b0c84SAdrian Chadd * We do header adjustment for each, and then concatenate the mbuf chains
4901c7b0c84SAdrian Chadd * to form a single frame for transmission.
4911c7b0c84SAdrian Chadd */
4921c7b0c84SAdrian Chadd struct mbuf *
ieee80211_amsdu_encap(struct ieee80211vap * vap,struct mbuf * m1,int hdrspace,struct ieee80211_key * key)4931c7b0c84SAdrian Chadd ieee80211_amsdu_encap(struct ieee80211vap *vap, struct mbuf *m1, int hdrspace,
4941c7b0c84SAdrian Chadd struct ieee80211_key *key)
4951c7b0c84SAdrian Chadd {
4961c7b0c84SAdrian Chadd struct mbuf *m2;
4971c7b0c84SAdrian Chadd struct ether_header eh1, eh2;
4981c7b0c84SAdrian Chadd struct mbuf *m;
4991c7b0c84SAdrian Chadd int pad;
5001c7b0c84SAdrian Chadd
5011c7b0c84SAdrian Chadd m2 = m1->m_nextpkt;
5021c7b0c84SAdrian Chadd if (m2 == NULL) {
5031c7b0c84SAdrian Chadd IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
5041c7b0c84SAdrian Chadd "%s: only one frame\n", __func__);
5051c7b0c84SAdrian Chadd goto bad;
5061c7b0c84SAdrian Chadd }
5071c7b0c84SAdrian Chadd m1->m_nextpkt = NULL;
5081c7b0c84SAdrian Chadd
5091c7b0c84SAdrian Chadd /*
5101c7b0c84SAdrian Chadd * Include A-MSDU header in adjusting header layout.
511616190d0SSam Leffler */
512339ccfb3SSam Leffler KASSERT(m1->m_len >= sizeof(eh1), ("no ethernet header!"));
513339ccfb3SSam Leffler ETHER_HEADER_COPY(&eh1, mtod(m1, caddr_t));
514616190d0SSam Leffler m1 = ieee80211_mbuf_adjust(vap,
5151c7b0c84SAdrian Chadd hdrspace + sizeof(struct llc) + sizeof(uint32_t) +
516616190d0SSam Leffler sizeof(struct ether_header),
517616190d0SSam Leffler key, m1);
518616190d0SSam Leffler if (m1 == NULL) {
519616190d0SSam Leffler /* NB: ieee80211_mbuf_adjust handles msgs+statistics */
520616190d0SSam Leffler m_freem(m2);
521616190d0SSam Leffler goto bad;
522616190d0SSam Leffler }
523616190d0SSam Leffler
524616190d0SSam Leffler /*
525616190d0SSam Leffler * Copy second frame's Ethernet header out of line
526616190d0SSam Leffler * and adjust for encapsulation headers. Note that
527616190d0SSam Leffler * we make room for padding in case there isn't room
528616190d0SSam Leffler * at the end of first frame.
529616190d0SSam Leffler */
530616190d0SSam Leffler KASSERT(m2->m_len >= sizeof(eh2), ("no ethernet header!"));
531616190d0SSam Leffler ETHER_HEADER_COPY(&eh2, mtod(m2, caddr_t));
5321c7b0c84SAdrian Chadd m2 = ieee80211_mbuf_adjust(vap, 4, NULL, m2);
533616190d0SSam Leffler if (m2 == NULL) {
534616190d0SSam Leffler /* NB: ieee80211_mbuf_adjust handles msgs+statistics */
535616190d0SSam Leffler goto bad;
536616190d0SSam Leffler }
537616190d0SSam Leffler
538616190d0SSam Leffler /*
539616190d0SSam Leffler * Now do tunnel encapsulation. First, each
540616190d0SSam Leffler * frame gets a standard encapsulation.
541616190d0SSam Leffler */
54274b4c76eSAdrian Chadd m1 = ieee80211_ff_encap1(vap, m1, &eh1);
543616190d0SSam Leffler if (m1 == NULL)
544616190d0SSam Leffler goto bad;
54574b4c76eSAdrian Chadd m2 = ieee80211_ff_encap1(vap, m2, &eh2);
546616190d0SSam Leffler if (m2 == NULL)
547616190d0SSam Leffler goto bad;
548616190d0SSam Leffler
549616190d0SSam Leffler /*
550616190d0SSam Leffler * Pad leading frame to a 4-byte boundary. If there
551616190d0SSam Leffler * is space at the end of the first frame, put it
552616190d0SSam Leffler * there; otherwise prepend to the front of the second
553616190d0SSam Leffler * frame. We know doing the second will always work
554616190d0SSam Leffler * because we reserve space above. We prefer appending
555616190d0SSam Leffler * as this typically has better DMA alignment properties.
556616190d0SSam Leffler */
557616190d0SSam Leffler for (m = m1; m->m_next != NULL; m = m->m_next)
558616190d0SSam Leffler ;
559616190d0SSam Leffler pad = roundup2(m1->m_pkthdr.len, 4) - m1->m_pkthdr.len;
560616190d0SSam Leffler if (pad) {
561616190d0SSam Leffler if (M_TRAILINGSPACE(m) < pad) { /* prepend to second */
562616190d0SSam Leffler m2->m_data -= pad;
563616190d0SSam Leffler m2->m_len += pad;
564616190d0SSam Leffler m2->m_pkthdr.len += pad;
565616190d0SSam Leffler } else { /* append to first */
566616190d0SSam Leffler m->m_len += pad;
567616190d0SSam Leffler m1->m_pkthdr.len += pad;
568616190d0SSam Leffler }
569616190d0SSam Leffler }
570616190d0SSam Leffler
571616190d0SSam Leffler /*
5721c7b0c84SAdrian Chadd * Now, stick 'em together.
573616190d0SSam Leffler */
574616190d0SSam Leffler m->m_next = m2; /* NB: last mbuf from above */
575616190d0SSam Leffler m1->m_pkthdr.len += m2->m_pkthdr.len;
576616190d0SSam Leffler
5771c7b0c84SAdrian Chadd vap->iv_stats.is_amsdu_encap++;
578616190d0SSam Leffler
579616190d0SSam Leffler return m1;
580616190d0SSam Leffler bad:
5811c7b0c84SAdrian Chadd vap->iv_stats.is_amsdu_encapfail++;
582616190d0SSam Leffler if (m1 != NULL)
583616190d0SSam Leffler m_freem(m1);
584616190d0SSam Leffler if (m2 != NULL)
585616190d0SSam Leffler m_freem(m2);
586616190d0SSam Leffler return NULL;
587616190d0SSam Leffler }
5881c7b0c84SAdrian Chadd
589339ccfb3SSam Leffler static void
ff_transmit(struct ieee80211_node * ni,struct mbuf * m)590339ccfb3SSam Leffler ff_transmit(struct ieee80211_node *ni, struct mbuf *m)
591339ccfb3SSam Leffler {
592339ccfb3SSam Leffler struct ieee80211vap *vap = ni->ni_vap;
5935cda6006SAdrian Chadd struct ieee80211com *ic = ni->ni_ic;
594339ccfb3SSam Leffler
595cdc0cf21SAndriy Voskoboinyk IEEE80211_TX_LOCK_ASSERT(ic);
5965cda6006SAdrian Chadd
597339ccfb3SSam Leffler /* encap and xmit */
598339ccfb3SSam Leffler m = ieee80211_encap(vap, ni, m);
599cdc0cf21SAndriy Voskoboinyk if (m != NULL)
600cdc0cf21SAndriy Voskoboinyk (void) ieee80211_parent_xmitpkt(ic, m);
601cdc0cf21SAndriy Voskoboinyk else
602339ccfb3SSam Leffler ieee80211_free_node(ni);
603339ccfb3SSam Leffler }
604339ccfb3SSam Leffler
605339ccfb3SSam Leffler /*
606339ccfb3SSam Leffler * Flush frames to device; note we re-use the linked list
607339ccfb3SSam Leffler * the frames were stored on and use the sentinel (unchanged)
608339ccfb3SSam Leffler * which may be non-NULL.
609339ccfb3SSam Leffler */
610339ccfb3SSam Leffler static void
ff_flush(struct mbuf * head,struct mbuf * last)611339ccfb3SSam Leffler ff_flush(struct mbuf *head, struct mbuf *last)
612339ccfb3SSam Leffler {
613339ccfb3SSam Leffler struct mbuf *m, *next;
614339ccfb3SSam Leffler struct ieee80211_node *ni;
615339ccfb3SSam Leffler struct ieee80211vap *vap;
616339ccfb3SSam Leffler
617339ccfb3SSam Leffler for (m = head; m != last; m = next) {
618339ccfb3SSam Leffler next = m->m_nextpkt;
619339ccfb3SSam Leffler m->m_nextpkt = NULL;
620339ccfb3SSam Leffler
621339ccfb3SSam Leffler ni = (struct ieee80211_node *) m->m_pkthdr.rcvif;
622339ccfb3SSam Leffler vap = ni->ni_vap;
623339ccfb3SSam Leffler
624339ccfb3SSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
625339ccfb3SSam Leffler "%s: flush frame, age %u", __func__, M_AGE_GET(m));
626339ccfb3SSam Leffler vap->iv_stats.is_ff_flush++;
627339ccfb3SSam Leffler
628339ccfb3SSam Leffler ff_transmit(ni, m);
629339ccfb3SSam Leffler }
630339ccfb3SSam Leffler }
631339ccfb3SSam Leffler
632339ccfb3SSam Leffler /*
633339ccfb3SSam Leffler * Age frames on the staging queue.
634339ccfb3SSam Leffler */
635339ccfb3SSam Leffler void
ieee80211_ff_age(struct ieee80211com * ic,struct ieee80211_stageq * sq,int quanta)63604f19fd6SSam Leffler ieee80211_ff_age(struct ieee80211com *ic, struct ieee80211_stageq *sq,
63704f19fd6SSam Leffler int quanta)
638339ccfb3SSam Leffler {
639339ccfb3SSam Leffler struct mbuf *m, *head;
640339ccfb3SSam Leffler struct ieee80211_node *ni;
641339ccfb3SSam Leffler
642cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_LOCK(ic);
643cdc0cf21SAndriy Voskoboinyk if (sq->depth == 0) {
644cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
645cdc0cf21SAndriy Voskoboinyk return; /* nothing to do */
646cdc0cf21SAndriy Voskoboinyk }
647339ccfb3SSam Leffler
648cdc0cf21SAndriy Voskoboinyk KASSERT(sq->head != NULL, ("stageq empty"));
649cdc0cf21SAndriy Voskoboinyk
650339ccfb3SSam Leffler head = sq->head;
651339ccfb3SSam Leffler while ((m = sq->head) != NULL && M_AGE_GET(m) < quanta) {
6522aa563dfSAdrian Chadd int tid = WME_AC_TO_TID(M_WME_GETAC(m));
6532aa563dfSAdrian Chadd
654d0294711SAdrian Chadd /* clear staging ref to frame */
655339ccfb3SSam Leffler ni = (struct ieee80211_node *) m->m_pkthdr.rcvif;
656d0294711SAdrian Chadd KASSERT(ni->ni_tx_superg[tid] == m, ("staging queue empty"));
657d0294711SAdrian Chadd ni->ni_tx_superg[tid] = NULL;
658339ccfb3SSam Leffler
659339ccfb3SSam Leffler sq->head = m->m_nextpkt;
660339ccfb3SSam Leffler sq->depth--;
661339ccfb3SSam Leffler }
662e79ef949SAndriy Voskoboinyk if (m == NULL)
663339ccfb3SSam Leffler sq->tail = NULL;
664e79ef949SAndriy Voskoboinyk else
665339ccfb3SSam Leffler M_AGE_SUB(m, quanta);
666cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
667339ccfb3SSam Leffler
6685cda6006SAdrian Chadd IEEE80211_TX_LOCK(ic);
669339ccfb3SSam Leffler ff_flush(head, m);
6705cda6006SAdrian Chadd IEEE80211_TX_UNLOCK(ic);
671339ccfb3SSam Leffler }
672339ccfb3SSam Leffler
673339ccfb3SSam Leffler static void
stageq_add(struct ieee80211com * ic,struct ieee80211_stageq * sq,struct mbuf * m)674b3c69eefSAdrian Chadd stageq_add(struct ieee80211com *ic, struct ieee80211_stageq *sq, struct mbuf *m)
675339ccfb3SSam Leffler {
676339ccfb3SSam Leffler int age = ieee80211_ffagemax;
677b3c69eefSAdrian Chadd
678cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_LOCK_ASSERT(ic);
679b3c69eefSAdrian Chadd
680339ccfb3SSam Leffler if (sq->tail != NULL) {
681339ccfb3SSam Leffler sq->tail->m_nextpkt = m;
682339ccfb3SSam Leffler age -= M_AGE_GET(sq->head);
683abb0adffSAndriy Voskoboinyk } else {
684339ccfb3SSam Leffler sq->head = m;
685abb0adffSAndriy Voskoboinyk
686abb0adffSAndriy Voskoboinyk struct timeout_task *qtask = &ic->ic_superg->ff_qtimer;
687dc33c66dSAndriy Voskoboinyk taskqueue_enqueue_timeout(ic->ic_tq, qtask, age);
688abb0adffSAndriy Voskoboinyk }
689339ccfb3SSam Leffler KASSERT(age >= 0, ("age %d", age));
690339ccfb3SSam Leffler M_AGE_SET(m, age);
691339ccfb3SSam Leffler m->m_nextpkt = NULL;
692339ccfb3SSam Leffler sq->tail = m;
693339ccfb3SSam Leffler sq->depth++;
694339ccfb3SSam Leffler }
695339ccfb3SSam Leffler
696339ccfb3SSam Leffler static void
stageq_remove(struct ieee80211com * ic,struct ieee80211_stageq * sq,struct mbuf * mstaged)697b3c69eefSAdrian Chadd stageq_remove(struct ieee80211com *ic, struct ieee80211_stageq *sq, struct mbuf *mstaged)
698339ccfb3SSam Leffler {
699339ccfb3SSam Leffler struct mbuf *m, *mprev;
700339ccfb3SSam Leffler
701cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_LOCK_ASSERT(ic);
702b3c69eefSAdrian Chadd
703339ccfb3SSam Leffler mprev = NULL;
704339ccfb3SSam Leffler for (m = sq->head; m != NULL; m = m->m_nextpkt) {
705339ccfb3SSam Leffler if (m == mstaged) {
706339ccfb3SSam Leffler if (mprev == NULL)
707339ccfb3SSam Leffler sq->head = m->m_nextpkt;
708339ccfb3SSam Leffler else
709339ccfb3SSam Leffler mprev->m_nextpkt = m->m_nextpkt;
710339ccfb3SSam Leffler if (sq->tail == m)
711339ccfb3SSam Leffler sq->tail = mprev;
712339ccfb3SSam Leffler sq->depth--;
713339ccfb3SSam Leffler return;
714339ccfb3SSam Leffler }
715339ccfb3SSam Leffler mprev = m;
716339ccfb3SSam Leffler }
717339ccfb3SSam Leffler printf("%s: packet not found\n", __func__);
718339ccfb3SSam Leffler }
719339ccfb3SSam Leffler
720339ccfb3SSam Leffler static uint32_t
ff_approx_txtime(struct ieee80211_node * ni,const struct mbuf * m1,const struct mbuf * m2)721339ccfb3SSam Leffler ff_approx_txtime(struct ieee80211_node *ni,
722339ccfb3SSam Leffler const struct mbuf *m1, const struct mbuf *m2)
723339ccfb3SSam Leffler {
724339ccfb3SSam Leffler struct ieee80211com *ic = ni->ni_ic;
725339ccfb3SSam Leffler struct ieee80211vap *vap = ni->ni_vap;
726339ccfb3SSam Leffler uint32_t framelen;
7271c7b0c84SAdrian Chadd uint32_t frame_time;
728339ccfb3SSam Leffler
729339ccfb3SSam Leffler /*
730339ccfb3SSam Leffler * Approximate the frame length to be transmitted. A swag to add
731339ccfb3SSam Leffler * the following maximal values to the skb payload:
732339ccfb3SSam Leffler * - 32: 802.11 encap + CRC
733339ccfb3SSam Leffler * - 24: encryption overhead (if wep bit)
734339ccfb3SSam Leffler * - 4 + 6: fast-frame header and padding
735339ccfb3SSam Leffler * - 16: 2 LLC FF tunnel headers
736339ccfb3SSam Leffler * - 14: 1 802.3 FF tunnel header (mbuf already accounts for 2nd)
737339ccfb3SSam Leffler */
738339ccfb3SSam Leffler framelen = m1->m_pkthdr.len + 32 +
739339ccfb3SSam Leffler ATH_FF_MAX_HDR_PAD + ATH_FF_MAX_SEP_PAD + ATH_FF_MAX_HDR;
740339ccfb3SSam Leffler if (vap->iv_flags & IEEE80211_F_PRIVACY)
741339ccfb3SSam Leffler framelen += 24;
742339ccfb3SSam Leffler if (m2 != NULL)
743339ccfb3SSam Leffler framelen += m2->m_pkthdr.len;
7441c7b0c84SAdrian Chadd
7451c7b0c84SAdrian Chadd /*
7461c7b0c84SAdrian Chadd * For now, we assume non-shortgi, 20MHz, just because I want to
7471c7b0c84SAdrian Chadd * at least test 802.11n.
7481c7b0c84SAdrian Chadd */
7491c7b0c84SAdrian Chadd if (ni->ni_txrate & IEEE80211_RATE_MCS)
7501c7b0c84SAdrian Chadd frame_time = ieee80211_compute_duration_ht(framelen,
7511c7b0c84SAdrian Chadd ni->ni_txrate,
7521c7b0c84SAdrian Chadd IEEE80211_HT_RC_2_STREAMS(ni->ni_txrate),
7531c7b0c84SAdrian Chadd 0, /* isht40 */
7541c7b0c84SAdrian Chadd 0); /* isshortgi */
7551c7b0c84SAdrian Chadd else
7561c7b0c84SAdrian Chadd frame_time = ieee80211_compute_duration(ic->ic_rt, framelen,
7571c7b0c84SAdrian Chadd ni->ni_txrate, 0);
7581c7b0c84SAdrian Chadd return (frame_time);
759339ccfb3SSam Leffler }
760339ccfb3SSam Leffler
761339ccfb3SSam Leffler /*
762339ccfb3SSam Leffler * Check if the supplied frame can be partnered with an existing
763339ccfb3SSam Leffler * or pending frame. Return a reference to any frame that should be
764339ccfb3SSam Leffler * sent on return; otherwise return NULL.
765339ccfb3SSam Leffler */
766339ccfb3SSam Leffler struct mbuf *
ieee80211_ff_check(struct ieee80211_node * ni,struct mbuf * m)767339ccfb3SSam Leffler ieee80211_ff_check(struct ieee80211_node *ni, struct mbuf *m)
768339ccfb3SSam Leffler {
769339ccfb3SSam Leffler struct ieee80211vap *vap = ni->ni_vap;
770339ccfb3SSam Leffler struct ieee80211com *ic = ni->ni_ic;
77104f19fd6SSam Leffler struct ieee80211_superg *sg = ic->ic_superg;
772339ccfb3SSam Leffler const int pri = M_WME_GETAC(m);
773339ccfb3SSam Leffler struct ieee80211_stageq *sq;
774339ccfb3SSam Leffler struct ieee80211_tx_ampdu *tap;
775339ccfb3SSam Leffler struct mbuf *mstaged;
776339ccfb3SSam Leffler uint32_t txtime, limit;
777339ccfb3SSam Leffler
7785cda6006SAdrian Chadd IEEE80211_TX_UNLOCK_ASSERT(ic);
7795cda6006SAdrian Chadd
780cdc0cf21SAndriy Voskoboinyk IEEE80211_LOCK(ic);
781cdc0cf21SAndriy Voskoboinyk limit = IEEE80211_TXOP_TO_US(
782cdc0cf21SAndriy Voskoboinyk ic->ic_wme.wme_chanParams.cap_wmeParams[pri].wmep_txopLimit);
783cdc0cf21SAndriy Voskoboinyk IEEE80211_UNLOCK(ic);
784cdc0cf21SAndriy Voskoboinyk
785339ccfb3SSam Leffler /*
786339ccfb3SSam Leffler * Check if the supplied frame can be aggregated.
787339ccfb3SSam Leffler *
788339ccfb3SSam Leffler * NB: we allow EAPOL frames to be aggregated with other ucast traffic.
789339ccfb3SSam Leffler * Do 802.1x EAPOL frames proceed in the clear? Then they couldn't
790339ccfb3SSam Leffler * be aggregated with other types of frames when encryption is on?
791339ccfb3SSam Leffler */
792cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_LOCK(ic);
7932aa563dfSAdrian Chadd tap = &ni->ni_tx_ampdu[WME_AC_TO_TID(pri)];
794d0294711SAdrian Chadd mstaged = ni->ni_tx_superg[WME_AC_TO_TID(pri)];
795d0294711SAdrian Chadd /* XXX NOTE: reusing packet counter state from A-MPDU */
796d0294711SAdrian Chadd /*
797d0294711SAdrian Chadd * XXX NOTE: this means we're double-counting; it should just
798d0294711SAdrian Chadd * be done in ieee80211_output.c once for both superg and A-MPDU.
799d0294711SAdrian Chadd */
800339ccfb3SSam Leffler ieee80211_txampdu_count_packet(tap);
801339ccfb3SSam Leffler
802339ccfb3SSam Leffler /*
803339ccfb3SSam Leffler * When not in station mode never aggregate a multicast
804339ccfb3SSam Leffler * frame; this insures, for example, that a combined frame
805339ccfb3SSam Leffler * does not require multiple encryption keys.
806339ccfb3SSam Leffler */
807339ccfb3SSam Leffler if (vap->iv_opmode != IEEE80211_M_STA &&
808339ccfb3SSam Leffler ETHER_IS_MULTICAST(mtod(m, struct ether_header *)->ether_dhost)) {
809339ccfb3SSam Leffler /* XXX flush staged frame? */
810cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
811339ccfb3SSam Leffler return m;
812339ccfb3SSam Leffler }
813339ccfb3SSam Leffler /*
814339ccfb3SSam Leffler * If there is no frame to combine with and the pps is
815339ccfb3SSam Leffler * too low; then do not attempt to aggregate this frame.
816339ccfb3SSam Leffler */
817339ccfb3SSam Leffler if (mstaged == NULL &&
818339ccfb3SSam Leffler ieee80211_txampdu_getpps(tap) < ieee80211_ffppsmin) {
819cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
820339ccfb3SSam Leffler return m;
821339ccfb3SSam Leffler }
82204f19fd6SSam Leffler sq = &sg->ff_stageq[pri];
823339ccfb3SSam Leffler /*
824339ccfb3SSam Leffler * Check the txop limit to insure the aggregate fits.
825339ccfb3SSam Leffler */
826339ccfb3SSam Leffler if (limit != 0 &&
827339ccfb3SSam Leffler (txtime = ff_approx_txtime(ni, m, mstaged)) > limit) {
828339ccfb3SSam Leffler /*
829339ccfb3SSam Leffler * Aggregate too long, return to the caller for direct
830339ccfb3SSam Leffler * transmission. In addition, flush any pending frame
831339ccfb3SSam Leffler * before sending this one.
832339ccfb3SSam Leffler */
833339ccfb3SSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
834339ccfb3SSam Leffler "%s: txtime %u exceeds txop limit %u\n",
835339ccfb3SSam Leffler __func__, txtime, limit);
836339ccfb3SSam Leffler
837d0294711SAdrian Chadd ni->ni_tx_superg[WME_AC_TO_TID(pri)] = NULL;
838339ccfb3SSam Leffler if (mstaged != NULL)
839b3c69eefSAdrian Chadd stageq_remove(ic, sq, mstaged);
840cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
841339ccfb3SSam Leffler
842339ccfb3SSam Leffler if (mstaged != NULL) {
8435cda6006SAdrian Chadd IEEE80211_TX_LOCK(ic);
844339ccfb3SSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
845339ccfb3SSam Leffler "%s: flush staged frame", __func__);
846339ccfb3SSam Leffler /* encap and xmit */
847339ccfb3SSam Leffler ff_transmit(ni, mstaged);
8485cda6006SAdrian Chadd IEEE80211_TX_UNLOCK(ic);
849339ccfb3SSam Leffler }
850339ccfb3SSam Leffler return m; /* NB: original frame */
851339ccfb3SSam Leffler }
852339ccfb3SSam Leffler /*
853339ccfb3SSam Leffler * An aggregation candidate. If there's a frame to partner
854339ccfb3SSam Leffler * with then combine and return for processing. Otherwise
855339ccfb3SSam Leffler * save this frame and wait for a partner to show up (or
856339ccfb3SSam Leffler * the frame to be flushed). Note that staged frames also
857339ccfb3SSam Leffler * hold their node reference.
858339ccfb3SSam Leffler */
859339ccfb3SSam Leffler if (mstaged != NULL) {
860d0294711SAdrian Chadd ni->ni_tx_superg[WME_AC_TO_TID(pri)] = NULL;
861b3c69eefSAdrian Chadd stageq_remove(ic, sq, mstaged);
862cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
863339ccfb3SSam Leffler
864339ccfb3SSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
865339ccfb3SSam Leffler "%s: aggregate fast-frame", __func__);
866339ccfb3SSam Leffler /*
867339ccfb3SSam Leffler * Release the node reference; we only need
868339ccfb3SSam Leffler * the one already in mstaged.
869339ccfb3SSam Leffler */
870339ccfb3SSam Leffler KASSERT(mstaged->m_pkthdr.rcvif == (void *)ni,
871339ccfb3SSam Leffler ("rcvif %p ni %p", mstaged->m_pkthdr.rcvif, ni));
872339ccfb3SSam Leffler ieee80211_free_node(ni);
873339ccfb3SSam Leffler
874339ccfb3SSam Leffler m->m_nextpkt = NULL;
875339ccfb3SSam Leffler mstaged->m_nextpkt = m;
876339ccfb3SSam Leffler mstaged->m_flags |= M_FF; /* NB: mark for encap work */
877339ccfb3SSam Leffler } else {
878d0294711SAdrian Chadd KASSERT(ni->ni_tx_superg[WME_AC_TO_TID(pri)] == NULL,
879d0294711SAdrian Chadd ("ni_tx_superg[]: %p",
880d0294711SAdrian Chadd ni->ni_tx_superg[WME_AC_TO_TID(pri)]));
881d0294711SAdrian Chadd ni->ni_tx_superg[WME_AC_TO_TID(pri)] = m;
882339ccfb3SSam Leffler
883b3c69eefSAdrian Chadd stageq_add(ic, sq, m);
884cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
885339ccfb3SSam Leffler
886339ccfb3SSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
887339ccfb3SSam Leffler "%s: stage frame, %u queued", __func__, sq->depth);
888339ccfb3SSam Leffler /* NB: mstaged is NULL */
889339ccfb3SSam Leffler }
890339ccfb3SSam Leffler return mstaged;
891339ccfb3SSam Leffler }
892339ccfb3SSam Leffler
8931c7b0c84SAdrian Chadd struct mbuf *
ieee80211_amsdu_check(struct ieee80211_node * ni,struct mbuf * m)8941c7b0c84SAdrian Chadd ieee80211_amsdu_check(struct ieee80211_node *ni, struct mbuf *m)
8951c7b0c84SAdrian Chadd {
8961c7b0c84SAdrian Chadd /*
8971c7b0c84SAdrian Chadd * XXX TODO: actually enforce the node support
8981c7b0c84SAdrian Chadd * and HTCAP requirements for the maximum A-MSDU
8991c7b0c84SAdrian Chadd * size.
9001c7b0c84SAdrian Chadd */
9011c7b0c84SAdrian Chadd
9021c7b0c84SAdrian Chadd /* First: software A-MSDU transmit? */
9031c7b0c84SAdrian Chadd if (! ieee80211_amsdu_tx_ok(ni))
9041c7b0c84SAdrian Chadd return (m);
9051c7b0c84SAdrian Chadd
9061c7b0c84SAdrian Chadd /* Next - EAPOL? Nope, don't aggregate; we don't QoS encap them */
9071c7b0c84SAdrian Chadd if (m->m_flags & (M_EAPOL | M_MCAST | M_BCAST))
9081c7b0c84SAdrian Chadd return (m);
9091c7b0c84SAdrian Chadd
9101c7b0c84SAdrian Chadd /* Next - needs to be a data frame, non-broadcast, etc */
9111c7b0c84SAdrian Chadd if (ETHER_IS_MULTICAST(mtod(m, struct ether_header *)->ether_dhost))
9121c7b0c84SAdrian Chadd return (m);
9131c7b0c84SAdrian Chadd
9141c7b0c84SAdrian Chadd return (ieee80211_ff_check(ni, m));
9151c7b0c84SAdrian Chadd }
9161c7b0c84SAdrian Chadd
917339ccfb3SSam Leffler void
ieee80211_ff_node_init(struct ieee80211_node * ni)918339ccfb3SSam Leffler ieee80211_ff_node_init(struct ieee80211_node *ni)
919339ccfb3SSam Leffler {
920339ccfb3SSam Leffler /*
921339ccfb3SSam Leffler * Clean FF state on re-associate. This handles the case
922339ccfb3SSam Leffler * where a station leaves w/o notifying us and then returns
923339ccfb3SSam Leffler * before node is reaped for inactivity.
924339ccfb3SSam Leffler */
925339ccfb3SSam Leffler ieee80211_ff_node_cleanup(ni);
926339ccfb3SSam Leffler }
927339ccfb3SSam Leffler
928339ccfb3SSam Leffler void
ieee80211_ff_node_cleanup(struct ieee80211_node * ni)929339ccfb3SSam Leffler ieee80211_ff_node_cleanup(struct ieee80211_node *ni)
930339ccfb3SSam Leffler {
931339ccfb3SSam Leffler struct ieee80211com *ic = ni->ni_ic;
93204f19fd6SSam Leffler struct ieee80211_superg *sg = ic->ic_superg;
933132581aaSAdrian Chadd struct mbuf *m, *next_m, *head;
9342aa563dfSAdrian Chadd int tid;
935339ccfb3SSam Leffler
936cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_LOCK(ic);
937339ccfb3SSam Leffler head = NULL;
9382aa563dfSAdrian Chadd for (tid = 0; tid < WME_NUM_TID; tid++) {
9392aa563dfSAdrian Chadd int ac = TID_TO_WME_AC(tid);
940d0294711SAdrian Chadd /*
941d0294711SAdrian Chadd * XXX Initialise the packet counter.
942d0294711SAdrian Chadd *
943d0294711SAdrian Chadd * This may be double-work for 11n stations;
944d0294711SAdrian Chadd * but without it we never setup things.
945d0294711SAdrian Chadd */
946d0294711SAdrian Chadd ieee80211_txampdu_init_pps(&ni->ni_tx_ampdu[tid]);
947d0294711SAdrian Chadd m = ni->ni_tx_superg[tid];
948339ccfb3SSam Leffler if (m != NULL) {
949d0294711SAdrian Chadd ni->ni_tx_superg[tid] = NULL;
950b3c69eefSAdrian Chadd stageq_remove(ic, &sg->ff_stageq[ac], m);
951339ccfb3SSam Leffler m->m_nextpkt = head;
952339ccfb3SSam Leffler head = m;
953339ccfb3SSam Leffler }
954339ccfb3SSam Leffler }
955cdc0cf21SAndriy Voskoboinyk IEEE80211_FF_UNLOCK(ic);
956339ccfb3SSam Leffler
957132581aaSAdrian Chadd /*
958132581aaSAdrian Chadd * Free mbufs, taking care to not dereference the mbuf after
959132581aaSAdrian Chadd * we free it (hence grabbing m_nextpkt before we free it.)
960132581aaSAdrian Chadd */
961132581aaSAdrian Chadd m = head;
962132581aaSAdrian Chadd while (m != NULL) {
963132581aaSAdrian Chadd next_m = m->m_nextpkt;
964339ccfb3SSam Leffler m_freem(m);
965339ccfb3SSam Leffler ieee80211_free_node(ni);
966132581aaSAdrian Chadd m = next_m;
967339ccfb3SSam Leffler }
968339ccfb3SSam Leffler }
969339ccfb3SSam Leffler
970616190d0SSam Leffler /*
971616190d0SSam Leffler * Switch between turbo and non-turbo operating modes.
972616190d0SSam Leffler * Use the specified channel flags to locate the new
973616190d0SSam Leffler * channel, update 802.11 state, and then call back into
974616190d0SSam Leffler * the driver to effect the change.
975616190d0SSam Leffler */
976616190d0SSam Leffler void
ieee80211_dturbo_switch(struct ieee80211vap * vap,int newflags)977616190d0SSam Leffler ieee80211_dturbo_switch(struct ieee80211vap *vap, int newflags)
978616190d0SSam Leffler {
979616190d0SSam Leffler struct ieee80211com *ic = vap->iv_ic;
980616190d0SSam Leffler struct ieee80211_channel *chan;
981616190d0SSam Leffler
982616190d0SSam Leffler chan = ieee80211_find_channel(ic, ic->ic_bsschan->ic_freq, newflags);
983616190d0SSam Leffler if (chan == NULL) { /* XXX should not happen */
984616190d0SSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
985616190d0SSam Leffler "%s: no channel with freq %u flags 0x%x\n",
986616190d0SSam Leffler __func__, ic->ic_bsschan->ic_freq, newflags);
987616190d0SSam Leffler return;
988616190d0SSam Leffler }
989616190d0SSam Leffler
990616190d0SSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
991616190d0SSam Leffler "%s: %s -> %s (freq %u flags 0x%x)\n", __func__,
992616190d0SSam Leffler ieee80211_phymode_name[ieee80211_chan2mode(ic->ic_bsschan)],
993616190d0SSam Leffler ieee80211_phymode_name[ieee80211_chan2mode(chan)],
994616190d0SSam Leffler chan->ic_freq, chan->ic_flags);
995616190d0SSam Leffler
996616190d0SSam Leffler ic->ic_bsschan = chan;
997616190d0SSam Leffler ic->ic_prevchan = ic->ic_curchan;
998616190d0SSam Leffler ic->ic_curchan = chan;
99926d39e2cSSam Leffler ic->ic_rt = ieee80211_get_ratetable(chan);
1000616190d0SSam Leffler ic->ic_set_channel(ic);
10015463c4a4SSam Leffler ieee80211_radiotap_chan_change(ic);
1002616190d0SSam Leffler /* NB: do not need to reset ERP state 'cuz we're in sta mode */
1003616190d0SSam Leffler }
1004616190d0SSam Leffler
1005616190d0SSam Leffler /*
1006616190d0SSam Leffler * Return the current ``state'' of an Atheros capbility.
1007616190d0SSam Leffler * If associated in station mode report the negotiated
1008616190d0SSam Leffler * setting. Otherwise report the current setting.
1009616190d0SSam Leffler */
1010616190d0SSam Leffler static int
getathcap(struct ieee80211vap * vap,int cap)1011616190d0SSam Leffler getathcap(struct ieee80211vap *vap, int cap)
1012616190d0SSam Leffler {
1013616190d0SSam Leffler if (vap->iv_opmode == IEEE80211_M_STA &&
1014616190d0SSam Leffler vap->iv_state == IEEE80211_S_RUN)
1015616190d0SSam Leffler return IEEE80211_ATH_CAP(vap, vap->iv_bss, cap) != 0;
1016616190d0SSam Leffler else
1017616190d0SSam Leffler return (vap->iv_flags & cap) != 0;
1018616190d0SSam Leffler }
1019616190d0SSam Leffler
1020616190d0SSam Leffler static int
superg_ioctl_get80211(struct ieee80211vap * vap,struct ieee80211req * ireq)1021616190d0SSam Leffler superg_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
1022616190d0SSam Leffler {
1023616190d0SSam Leffler switch (ireq->i_type) {
1024616190d0SSam Leffler case IEEE80211_IOC_FF:
1025616190d0SSam Leffler ireq->i_val = getathcap(vap, IEEE80211_F_FF);
1026616190d0SSam Leffler break;
1027616190d0SSam Leffler case IEEE80211_IOC_TURBOP:
1028616190d0SSam Leffler ireq->i_val = getathcap(vap, IEEE80211_F_TURBOP);
1029616190d0SSam Leffler break;
1030616190d0SSam Leffler default:
1031616190d0SSam Leffler return ENOSYS;
1032616190d0SSam Leffler }
1033616190d0SSam Leffler return 0;
1034616190d0SSam Leffler }
1035616190d0SSam Leffler IEEE80211_IOCTL_GET(superg, superg_ioctl_get80211);
1036616190d0SSam Leffler
1037616190d0SSam Leffler static int
superg_ioctl_set80211(struct ieee80211vap * vap,struct ieee80211req * ireq)1038616190d0SSam Leffler superg_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
1039616190d0SSam Leffler {
1040616190d0SSam Leffler switch (ireq->i_type) {
1041616190d0SSam Leffler case IEEE80211_IOC_FF:
1042616190d0SSam Leffler if (ireq->i_val) {
1043616190d0SSam Leffler if ((vap->iv_caps & IEEE80211_C_FF) == 0)
1044616190d0SSam Leffler return EOPNOTSUPP;
1045616190d0SSam Leffler vap->iv_flags |= IEEE80211_F_FF;
1046616190d0SSam Leffler } else
1047616190d0SSam Leffler vap->iv_flags &= ~IEEE80211_F_FF;
104897fc5da0SSam Leffler return ENETRESET;
1049616190d0SSam Leffler case IEEE80211_IOC_TURBOP:
1050616190d0SSam Leffler if (ireq->i_val) {
1051616190d0SSam Leffler if ((vap->iv_caps & IEEE80211_C_TURBOP) == 0)
1052616190d0SSam Leffler return EOPNOTSUPP;
1053616190d0SSam Leffler vap->iv_flags |= IEEE80211_F_TURBOP;
1054616190d0SSam Leffler } else
1055616190d0SSam Leffler vap->iv_flags &= ~IEEE80211_F_TURBOP;
1056616190d0SSam Leffler return ENETRESET;
1057616190d0SSam Leffler default:
1058616190d0SSam Leffler return ENOSYS;
1059616190d0SSam Leffler }
1060616190d0SSam Leffler }
1061616190d0SSam Leffler IEEE80211_IOCTL_SET(superg, superg_ioctl_set80211);
10629da01550SAdrian Chadd
10639da01550SAdrian Chadd #endif /* IEEE80211_SUPPORT_SUPERG */
1064