ieee80211_superg.c revision 288318
1190391Ssam/*-
2190391Ssam * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3190391Ssam * All rights reserved.
4190391Ssam *
5190391Ssam * Redistribution and use in source and binary forms, with or without
6190391Ssam * modification, are permitted provided that the following conditions
7190391Ssam * are met:
8190391Ssam * 1. Redistributions of source code must retain the above copyright
9190391Ssam *    notice, this list of conditions and the following disclaimer.
10190391Ssam * 2. Redistributions in binary form must reproduce the above copyright
11190391Ssam *    notice, this list of conditions and the following disclaimer in the
12190391Ssam *    documentation and/or other materials provided with the distribution.
13190391Ssam *
14190391Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15190391Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16190391Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17190391Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18190391Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19190391Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20190391Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21190391Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22190391Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23190391Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24190391Ssam */
25190391Ssam
26190391Ssam#include <sys/cdefs.h>
27190391Ssam__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_superg.c 288318 2015-09-28 00:59:07Z adrian $");
28190391Ssam
29190391Ssam#include "opt_wlan.h"
30190391Ssam
31246226Sadrian#ifdef	IEEE80211_SUPPORT_SUPERG
32246226Sadrian
33190391Ssam#include <sys/param.h>
34190391Ssam#include <sys/systm.h>
35190391Ssam#include <sys/mbuf.h>
36190391Ssam#include <sys/kernel.h>
37190391Ssam#include <sys/endian.h>
38190391Ssam
39190391Ssam#include <sys/socket.h>
40190391Ssam
41190391Ssam#include <net/if.h>
42257284Sglebius#include <net/if_var.h>
43190391Ssam#include <net/if_llc.h>
44190391Ssam#include <net/if_media.h>
45257284Sglebius#include <net/bpf.h>
46257284Sglebius#include <net/ethernet.h>
47190391Ssam
48190391Ssam#include <net80211/ieee80211_var.h>
49190391Ssam#include <net80211/ieee80211_input.h>
50190391Ssam#include <net80211/ieee80211_phy.h>
51190391Ssam#include <net80211/ieee80211_superg.h>
52190391Ssam
53190455Ssam/*
54190455Ssam * Atheros fast-frame encapsulation format.
55190455Ssam * FF max payload:
56190455Ssam * 802.2 + FFHDR + HPAD + 802.3 + 802.2 + 1500 + SPAD + 802.3 + 802.2 + 1500:
57190455Ssam *   8   +   4   +  4   +   14  +   8   + 1500 +  6   +   14  +   8   + 1500
58190455Ssam * = 3066
59190455Ssam */
60190455Ssam/* fast frame header is 32-bits */
61190455Ssam#define	ATH_FF_PROTO	0x0000003f	/* protocol */
62190455Ssam#define	ATH_FF_PROTO_S	0
63190455Ssam#define	ATH_FF_FTYPE	0x000000c0	/* frame type */
64190455Ssam#define	ATH_FF_FTYPE_S	6
65190455Ssam#define	ATH_FF_HLEN32	0x00000300	/* optional hdr length */
66190455Ssam#define	ATH_FF_HLEN32_S	8
67190455Ssam#define	ATH_FF_SEQNUM	0x001ffc00	/* sequence number */
68190455Ssam#define	ATH_FF_SEQNUM_S	10
69190455Ssam#define	ATH_FF_OFFSET	0xffe00000	/* offset to 2nd payload */
70190455Ssam#define	ATH_FF_OFFSET_S	21
71190455Ssam
72190455Ssam#define	ATH_FF_MAX_HDR_PAD	4
73190455Ssam#define	ATH_FF_MAX_SEP_PAD	6
74190455Ssam#define	ATH_FF_MAX_HDR		30
75190455Ssam
76190455Ssam#define	ATH_FF_PROTO_L2TUNNEL	0	/* L2 tunnel protocol */
77190455Ssam#define	ATH_FF_ETH_TYPE		0x88bd	/* Ether type for encapsulated frames */
78190455Ssam#define	ATH_FF_SNAP_ORGCODE_0	0x00
79190455Ssam#define	ATH_FF_SNAP_ORGCODE_1	0x03
80190455Ssam#define	ATH_FF_SNAP_ORGCODE_2	0x7f
81190455Ssam
82190579Ssam#define	ATH_FF_TXQMIN	2		/* min txq depth for staging */
83190579Ssam#define	ATH_FF_TXQMAX	50		/* maximum # of queued frames allowed */
84190579Ssam#define	ATH_FF_STAGEMAX	5		/* max waiting period for staged frame*/
85190579Ssam
86190391Ssam#define	ETHER_HEADER_COPY(dst, src) \
87190391Ssam	memcpy(dst, src, sizeof(struct ether_header))
88190391Ssam
89193115Ssamstatic	int ieee80211_ffppsmin = 2;	/* pps threshold for ff aggregation */
90273377ShselaskySYSCTL_INT(_net_wlan, OID_AUTO, ffppsmin, CTLFLAG_RW,
91193115Ssam	&ieee80211_ffppsmin, 0, "min packet rate before fast-frame staging");
92193115Ssamstatic	int ieee80211_ffagemax = -1;	/* max time frames held on stage q */
93193115SsamSYSCTL_PROC(_net_wlan, OID_AUTO, ffagemax, CTLTYPE_INT | CTLFLAG_RW,
94193115Ssam	&ieee80211_ffagemax, 0, ieee80211_sysctl_msecs_ticks, "I",
95193115Ssam	"max hold time for fast-frame staging (ms)");
96190579Ssam
97190391Ssamvoid
98190391Ssamieee80211_superg_attach(struct ieee80211com *ic)
99190391Ssam{
100191753Ssam	struct ieee80211_superg *sg;
101191753Ssam
102191753Ssam	if (ic->ic_caps & IEEE80211_C_FF) {
103283538Sadrian		sg = (struct ieee80211_superg *) IEEE80211_MALLOC(
104191753Ssam		     sizeof(struct ieee80211_superg), M_80211_VAP,
105283538Sadrian		     IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
106191753Ssam		if (sg == NULL) {
107191753Ssam			printf("%s: cannot allocate SuperG state block\n",
108191753Ssam			    __func__);
109191753Ssam			return;
110191753Ssam		}
111191753Ssam		ic->ic_superg = sg;
112191753Ssam	}
113190579Ssam	ieee80211_ffagemax = msecs_to_ticks(150);
114190391Ssam}
115190391Ssam
116190391Ssamvoid
117190391Ssamieee80211_superg_detach(struct ieee80211com *ic)
118190391Ssam{
119191753Ssam	if (ic->ic_superg != NULL) {
120283538Sadrian		IEEE80211_FREE(ic->ic_superg, M_80211_VAP);
121191753Ssam		ic->ic_superg = NULL;
122191753Ssam	}
123190391Ssam}
124190391Ssam
125190391Ssamvoid
126190391Ssamieee80211_superg_vattach(struct ieee80211vap *vap)
127190391Ssam{
128191753Ssam	struct ieee80211com *ic = vap->iv_ic;
129191753Ssam
130191753Ssam	if (ic->ic_superg == NULL)	/* NB: can't do fast-frames w/o state */
131191753Ssam		vap->iv_caps &= ~IEEE80211_C_FF;
132190391Ssam	if (vap->iv_caps & IEEE80211_C_FF)
133190391Ssam		vap->iv_flags |= IEEE80211_F_FF;
134190450Ssam	/* NB: we only implement sta mode */
135190450Ssam	if (vap->iv_opmode == IEEE80211_M_STA &&
136190450Ssam	    (vap->iv_caps & IEEE80211_C_TURBOP))
137190391Ssam		vap->iv_flags |= IEEE80211_F_TURBOP;
138190391Ssam}
139190391Ssam
140190391Ssamvoid
141190391Ssamieee80211_superg_vdetach(struct ieee80211vap *vap)
142190391Ssam{
143190391Ssam}
144190391Ssam
145190391Ssam#define	ATH_OUI_BYTES		0x00, 0x03, 0x7f
146190391Ssam/*
147190391Ssam * Add a WME information element to a frame.
148190391Ssam */
149190391Ssamuint8_t *
150190451Ssamieee80211_add_ath(uint8_t *frm, uint8_t caps, ieee80211_keyix defkeyix)
151190391Ssam{
152190391Ssam	static const struct ieee80211_ath_ie info = {
153190391Ssam		.ath_id		= IEEE80211_ELEMID_VENDOR,
154190391Ssam		.ath_len	= sizeof(struct ieee80211_ath_ie) - 2,
155190391Ssam		.ath_oui	= { ATH_OUI_BYTES },
156190391Ssam		.ath_oui_type	= ATH_OUI_TYPE,
157190391Ssam		.ath_oui_subtype= ATH_OUI_SUBTYPE,
158190391Ssam		.ath_version	= ATH_OUI_VERSION,
159190391Ssam	};
160190391Ssam	struct ieee80211_ath_ie *ath = (struct ieee80211_ath_ie *) frm;
161190391Ssam
162190391Ssam	memcpy(frm, &info, sizeof(info));
163190391Ssam	ath->ath_capability = caps;
164190451Ssam	if (defkeyix != IEEE80211_KEYIX_NONE) {
165190451Ssam		ath->ath_defkeyix[0] = (defkeyix & 0xff);
166190451Ssam		ath->ath_defkeyix[1] = ((defkeyix >> 8) & 0xff);
167190451Ssam	} else {
168190451Ssam		ath->ath_defkeyix[0] = 0xff;
169190451Ssam		ath->ath_defkeyix[1] = 0x7f;
170190451Ssam	}
171190391Ssam	return frm + sizeof(info);
172190391Ssam}
173190391Ssam#undef ATH_OUI_BYTES
174190391Ssam
175190451Ssamuint8_t *
176190451Ssamieee80211_add_athcaps(uint8_t *frm, const struct ieee80211_node *bss)
177190451Ssam{
178190451Ssam	const struct ieee80211vap *vap = bss->ni_vap;
179190451Ssam
180190451Ssam	return ieee80211_add_ath(frm,
181190451Ssam	    vap->iv_flags & IEEE80211_F_ATHEROS,
182190451Ssam	    ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
183190451Ssam	    bss->ni_authmode != IEEE80211_AUTH_8021X) ?
184190451Ssam	    vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
185190451Ssam}
186190451Ssam
187190391Ssamvoid
188190391Ssamieee80211_parse_ath(struct ieee80211_node *ni, uint8_t *ie)
189190391Ssam{
190190391Ssam	const struct ieee80211_ath_ie *ath =
191190391Ssam		(const struct ieee80211_ath_ie *) ie;
192190391Ssam
193190391Ssam	ni->ni_ath_flags = ath->ath_capability;
194190391Ssam	ni->ni_ath_defkeyix = LE_READ_2(&ath->ath_defkeyix);
195190391Ssam}
196190391Ssam
197190391Ssamint
198190391Ssamieee80211_parse_athparams(struct ieee80211_node *ni, uint8_t *frm,
199190391Ssam	const struct ieee80211_frame *wh)
200190391Ssam{
201190391Ssam	struct ieee80211vap *vap = ni->ni_vap;
202190391Ssam	const struct ieee80211_ath_ie *ath;
203190391Ssam	u_int len = frm[1];
204190391Ssam	int capschanged;
205190391Ssam	uint16_t defkeyix;
206190391Ssam
207190391Ssam	if (len < sizeof(struct ieee80211_ath_ie)-2) {
208190391Ssam		IEEE80211_DISCARD_IE(vap,
209190391Ssam		    IEEE80211_MSG_ELEMID | IEEE80211_MSG_SUPERG,
210190391Ssam		    wh, "Atheros", "too short, len %u", len);
211190391Ssam		return -1;
212190391Ssam	}
213190391Ssam	ath = (const struct ieee80211_ath_ie *)frm;
214190391Ssam	capschanged = (ni->ni_ath_flags != ath->ath_capability);
215190391Ssam	defkeyix = LE_READ_2(ath->ath_defkeyix);
216190391Ssam	if (capschanged || defkeyix != ni->ni_ath_defkeyix) {
217190391Ssam		ni->ni_ath_flags = ath->ath_capability;
218190391Ssam		ni->ni_ath_defkeyix = defkeyix;
219190391Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
220190391Ssam		    "ath ie change: new caps 0x%x defkeyix 0x%x",
221190391Ssam		    ni->ni_ath_flags, ni->ni_ath_defkeyix);
222190391Ssam	}
223190391Ssam	if (IEEE80211_ATH_CAP(vap, ni, ATHEROS_CAP_TURBO_PRIME)) {
224190391Ssam		uint16_t curflags, newflags;
225190391Ssam
226190391Ssam		/*
227190391Ssam		 * Check for turbo mode switch.  Calculate flags
228190391Ssam		 * for the new mode and effect the switch.
229190391Ssam		 */
230190391Ssam		newflags = curflags = vap->iv_ic->ic_bsschan->ic_flags;
231190391Ssam		/* NB: BOOST is not in ic_flags, so get it from the ie */
232190391Ssam		if (ath->ath_capability & ATHEROS_CAP_BOOST)
233190391Ssam			newflags |= IEEE80211_CHAN_TURBO;
234190391Ssam		else
235190391Ssam			newflags &= ~IEEE80211_CHAN_TURBO;
236190391Ssam		if (newflags != curflags)
237190391Ssam			ieee80211_dturbo_switch(vap, newflags);
238190391Ssam	}
239190391Ssam	return capschanged;
240190391Ssam}
241190391Ssam
242190391Ssam/*
243190391Ssam * Decap the encapsulated frame pair and dispatch the first
244190391Ssam * for delivery.  The second frame is returned for delivery
245190391Ssam * via the normal path.
246190391Ssam */
247190391Ssamstruct mbuf *
248190391Ssamieee80211_ff_decap(struct ieee80211_node *ni, struct mbuf *m)
249190391Ssam{
250190391Ssam#define	FF_LLC_SIZE	(sizeof(struct ether_header) + sizeof(struct llc))
251190391Ssam#define	MS(x,f)	(((x) & f) >> f##_S)
252190391Ssam	struct ieee80211vap *vap = ni->ni_vap;
253190391Ssam	struct llc *llc;
254190391Ssam	uint32_t ath;
255190391Ssam	struct mbuf *n;
256190391Ssam	int framelen;
257190391Ssam
258190391Ssam	/* NB: we assume caller does this check for us */
259190391Ssam	KASSERT(IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF),
260190391Ssam	    ("ff not negotiated"));
261190391Ssam	/*
262190391Ssam	 * Check for fast-frame tunnel encapsulation.
263190391Ssam	 */
264190391Ssam	if (m->m_pkthdr.len < 3*FF_LLC_SIZE)
265190391Ssam		return m;
266190391Ssam	if (m->m_len < FF_LLC_SIZE &&
267190391Ssam	    (m = m_pullup(m, FF_LLC_SIZE)) == NULL) {
268190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
269190391Ssam		    ni->ni_macaddr, "fast-frame",
270190391Ssam		    "%s", "m_pullup(llc) failed");
271190391Ssam		vap->iv_stats.is_rx_tooshort++;
272190391Ssam		return NULL;
273190391Ssam	}
274190391Ssam	llc = (struct llc *)(mtod(m, uint8_t *) +
275190391Ssam	    sizeof(struct ether_header));
276190391Ssam	if (llc->llc_snap.ether_type != htons(ATH_FF_ETH_TYPE))
277190391Ssam		return m;
278190391Ssam	m_adj(m, FF_LLC_SIZE);
279190391Ssam	m_copydata(m, 0, sizeof(uint32_t), (caddr_t) &ath);
280190391Ssam	if (MS(ath, ATH_FF_PROTO) != ATH_FF_PROTO_L2TUNNEL) {
281190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
282190391Ssam		    ni->ni_macaddr, "fast-frame",
283190391Ssam		    "unsupport tunnel protocol, header 0x%x", ath);
284190391Ssam		vap->iv_stats.is_ff_badhdr++;
285190391Ssam		m_freem(m);
286190391Ssam		return NULL;
287190391Ssam	}
288190391Ssam	/* NB: skip header and alignment padding */
289190391Ssam	m_adj(m, roundup(sizeof(uint32_t) - 2, 4) + 2);
290190391Ssam
291190391Ssam	vap->iv_stats.is_ff_decap++;
292190391Ssam
293190391Ssam	/*
294190391Ssam	 * Decap the first frame, bust it apart from the
295190391Ssam	 * second and deliver; then decap the second frame
296190391Ssam	 * and return it to the caller for normal delivery.
297190391Ssam	 */
298190391Ssam	m = ieee80211_decap1(m, &framelen);
299190391Ssam	if (m == NULL) {
300190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
301190391Ssam		    ni->ni_macaddr, "fast-frame", "%s", "first decap failed");
302190391Ssam		vap->iv_stats.is_ff_tooshort++;
303190391Ssam		return NULL;
304190391Ssam	}
305190391Ssam	n = m_split(m, framelen, M_NOWAIT);
306190391Ssam	if (n == NULL) {
307190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
308190391Ssam		    ni->ni_macaddr, "fast-frame",
309190391Ssam		    "%s", "unable to split encapsulated frames");
310190391Ssam		vap->iv_stats.is_ff_split++;
311190391Ssam		m_freem(m);			/* NB: must reclaim */
312190391Ssam		return NULL;
313190391Ssam	}
314190391Ssam	/* XXX not right for WDS */
315190391Ssam	vap->iv_deliver_data(vap, ni, m);	/* 1st of pair */
316190391Ssam
317190391Ssam	/*
318190391Ssam	 * Decap second frame.
319190391Ssam	 */
320190391Ssam	m_adj(n, roundup2(framelen, 4) - framelen);	/* padding */
321190391Ssam	n = ieee80211_decap1(n, &framelen);
322190391Ssam	if (n == NULL) {
323190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
324190391Ssam		    ni->ni_macaddr, "fast-frame", "%s", "second decap failed");
325190391Ssam		vap->iv_stats.is_ff_tooshort++;
326190391Ssam	}
327190391Ssam	/* XXX verify framelen against mbuf contents */
328190391Ssam	return n;				/* 2nd delivered by caller */
329190391Ssam#undef MS
330190391Ssam#undef FF_LLC_SIZE
331190391Ssam}
332190391Ssam
333190391Ssam/*
334190391Ssam * Fast frame encapsulation.  There must be two packets
335190391Ssam * chained with m_nextpkt.  We do header adjustment for
336190391Ssam * each, add the tunnel encapsulation, and then concatenate
337190391Ssam * the mbuf chains to form a single frame for transmission.
338190391Ssam */
339190391Ssamstruct mbuf *
340190391Ssamieee80211_ff_encap(struct ieee80211vap *vap, struct mbuf *m1, int hdrspace,
341190391Ssam	struct ieee80211_key *key)
342190391Ssam{
343190391Ssam	struct mbuf *m2;
344190391Ssam	struct ether_header eh1, eh2;
345190391Ssam	struct llc *llc;
346190391Ssam	struct mbuf *m;
347190391Ssam	int pad;
348190391Ssam
349190391Ssam	m2 = m1->m_nextpkt;
350190391Ssam	if (m2 == NULL) {
351190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
352190391Ssam		    "%s: only one frame\n", __func__);
353190391Ssam		goto bad;
354190391Ssam	}
355190391Ssam	m1->m_nextpkt = NULL;
356190391Ssam	/*
357190579Ssam	 * Include fast frame headers in adjusting header layout.
358190391Ssam	 */
359190579Ssam	KASSERT(m1->m_len >= sizeof(eh1), ("no ethernet header!"));
360190579Ssam	ETHER_HEADER_COPY(&eh1, mtod(m1, caddr_t));
361190391Ssam	m1 = ieee80211_mbuf_adjust(vap,
362190391Ssam		hdrspace + sizeof(struct llc) + sizeof(uint32_t) + 2 +
363190391Ssam		    sizeof(struct ether_header),
364190391Ssam		key, m1);
365190391Ssam	if (m1 == NULL) {
366190391Ssam		/* NB: ieee80211_mbuf_adjust handles msgs+statistics */
367190391Ssam		m_freem(m2);
368190391Ssam		goto bad;
369190391Ssam	}
370190391Ssam
371190391Ssam	/*
372190391Ssam	 * Copy second frame's Ethernet header out of line
373190391Ssam	 * and adjust for encapsulation headers.  Note that
374190391Ssam	 * we make room for padding in case there isn't room
375190391Ssam	 * at the end of first frame.
376190391Ssam	 */
377190391Ssam	KASSERT(m2->m_len >= sizeof(eh2), ("no ethernet header!"));
378190391Ssam	ETHER_HEADER_COPY(&eh2, mtod(m2, caddr_t));
379190391Ssam	m2 = ieee80211_mbuf_adjust(vap,
380190391Ssam		ATH_FF_MAX_HDR_PAD + sizeof(struct ether_header),
381190391Ssam		NULL, m2);
382190391Ssam	if (m2 == NULL) {
383190391Ssam		/* NB: ieee80211_mbuf_adjust handles msgs+statistics */
384190391Ssam		goto bad;
385190391Ssam	}
386190391Ssam
387190391Ssam	/*
388190391Ssam	 * Now do tunnel encapsulation.  First, each
389190391Ssam	 * frame gets a standard encapsulation.
390190391Ssam	 */
391254900Sadrian	m1 = ieee80211_ff_encap1(vap, m1, &eh1);
392190391Ssam	if (m1 == NULL)
393190391Ssam		goto bad;
394254900Sadrian	m2 = ieee80211_ff_encap1(vap, m2, &eh2);
395190391Ssam	if (m2 == NULL)
396190391Ssam		goto bad;
397190391Ssam
398190391Ssam	/*
399190391Ssam	 * Pad leading frame to a 4-byte boundary.  If there
400190391Ssam	 * is space at the end of the first frame, put it
401190391Ssam	 * there; otherwise prepend to the front of the second
402190391Ssam	 * frame.  We know doing the second will always work
403190391Ssam	 * because we reserve space above.  We prefer appending
404190391Ssam	 * as this typically has better DMA alignment properties.
405190391Ssam	 */
406190391Ssam	for (m = m1; m->m_next != NULL; m = m->m_next)
407190391Ssam		;
408190391Ssam	pad = roundup2(m1->m_pkthdr.len, 4) - m1->m_pkthdr.len;
409190391Ssam	if (pad) {
410190391Ssam		if (M_TRAILINGSPACE(m) < pad) {		/* prepend to second */
411190391Ssam			m2->m_data -= pad;
412190391Ssam			m2->m_len += pad;
413190391Ssam			m2->m_pkthdr.len += pad;
414190391Ssam		} else {				/* append to first */
415190391Ssam			m->m_len += pad;
416190391Ssam			m1->m_pkthdr.len += pad;
417190391Ssam		}
418190391Ssam	}
419190391Ssam
420190391Ssam	/*
421190391Ssam	 * Now, stick 'em together and prepend the tunnel headers;
422190391Ssam	 * first the Atheros tunnel header (all zero for now) and
423190391Ssam	 * then a special fast frame LLC.
424190391Ssam	 *
425190391Ssam	 * XXX optimize by prepending together
426190391Ssam	 */
427190391Ssam	m->m_next = m2;			/* NB: last mbuf from above */
428190391Ssam	m1->m_pkthdr.len += m2->m_pkthdr.len;
429243882Sglebius	M_PREPEND(m1, sizeof(uint32_t)+2, M_NOWAIT);
430190391Ssam	if (m1 == NULL) {		/* XXX cannot happen */
431190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
432190391Ssam		    "%s: no space for tunnel header\n", __func__);
433190391Ssam		vap->iv_stats.is_tx_nobuf++;
434190391Ssam		return NULL;
435190391Ssam	}
436190391Ssam	memset(mtod(m1, void *), 0, sizeof(uint32_t)+2);
437190391Ssam
438243882Sglebius	M_PREPEND(m1, sizeof(struct llc), M_NOWAIT);
439190391Ssam	if (m1 == NULL) {		/* XXX cannot happen */
440190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
441190391Ssam		    "%s: no space for llc header\n", __func__);
442190391Ssam		vap->iv_stats.is_tx_nobuf++;
443190391Ssam		return NULL;
444190391Ssam	}
445190391Ssam	llc = mtod(m1, struct llc *);
446190391Ssam	llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
447190391Ssam	llc->llc_control = LLC_UI;
448190391Ssam	llc->llc_snap.org_code[0] = ATH_FF_SNAP_ORGCODE_0;
449190391Ssam	llc->llc_snap.org_code[1] = ATH_FF_SNAP_ORGCODE_1;
450190391Ssam	llc->llc_snap.org_code[2] = ATH_FF_SNAP_ORGCODE_2;
451190391Ssam	llc->llc_snap.ether_type = htons(ATH_FF_ETH_TYPE);
452190391Ssam
453190391Ssam	vap->iv_stats.is_ff_encap++;
454190391Ssam
455190391Ssam	return m1;
456190391Ssambad:
457190391Ssam	if (m1 != NULL)
458190391Ssam		m_freem(m1);
459190391Ssam	if (m2 != NULL)
460190391Ssam		m_freem(m2);
461190391Ssam	return NULL;
462190391Ssam}
463190391Ssam
464190579Ssamstatic void
465190579Ssamff_transmit(struct ieee80211_node *ni, struct mbuf *m)
466190579Ssam{
467190579Ssam	struct ieee80211vap *vap = ni->ni_vap;
468248069Sadrian	struct ieee80211com *ic = ni->ni_ic;
469190579Ssam	int error;
470190579Ssam
471248069Sadrian	IEEE80211_TX_LOCK_ASSERT(vap->iv_ic);
472248069Sadrian
473190579Ssam	/* encap and xmit */
474190579Ssam	m = ieee80211_encap(vap, ni, m);
475190579Ssam	if (m != NULL) {
476190579Ssam		struct ifnet *ifp = vap->iv_ifp;
477190579Ssam
478254082Sadrian		error = ieee80211_parent_xmitpkt(ic, m);;
479190579Ssam		if (error != 0) {
480190579Ssam			/* NB: IFQ_HANDOFF reclaims mbuf */
481190579Ssam			ieee80211_free_node(ni);
482190579Ssam		} else {
483271861Sglebius			if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
484190579Ssam		}
485190579Ssam	} else
486190579Ssam		ieee80211_free_node(ni);
487190579Ssam}
488190579Ssam
489190391Ssam/*
490190579Ssam * Flush frames to device; note we re-use the linked list
491190579Ssam * the frames were stored on and use the sentinel (unchanged)
492190579Ssam * which may be non-NULL.
493190579Ssam */
494190579Ssamstatic void
495190579Ssamff_flush(struct mbuf *head, struct mbuf *last)
496190579Ssam{
497190579Ssam	struct mbuf *m, *next;
498190579Ssam	struct ieee80211_node *ni;
499190579Ssam	struct ieee80211vap *vap;
500190579Ssam
501190579Ssam	for (m = head; m != last; m = next) {
502190579Ssam		next = m->m_nextpkt;
503190579Ssam		m->m_nextpkt = NULL;
504190579Ssam
505190579Ssam		ni = (struct ieee80211_node *) m->m_pkthdr.rcvif;
506190579Ssam		vap = ni->ni_vap;
507190579Ssam
508190579Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
509190579Ssam		    "%s: flush frame, age %u", __func__, M_AGE_GET(m));
510190579Ssam		vap->iv_stats.is_ff_flush++;
511190579Ssam
512190579Ssam		ff_transmit(ni, m);
513190579Ssam	}
514190579Ssam}
515190579Ssam
516190579Ssam/*
517190579Ssam * Age frames on the staging queue.
518244044Sadrian *
519244044Sadrian * This is called without the comlock held, but it does all its work
520244044Sadrian * behind the comlock.  Because of this, it's possible that the
521244044Sadrian * staging queue will be serviced between the function which called
522244044Sadrian * it and now; thus simply checking that the queue has work in it
523244044Sadrian * may fail.
524244044Sadrian *
525244044Sadrian * See PR kern/174283 for more details.
526190579Ssam */
527190579Ssamvoid
528191753Ssamieee80211_ff_age(struct ieee80211com *ic, struct ieee80211_stageq *sq,
529191753Ssam    int quanta)
530190579Ssam{
531190579Ssam	struct mbuf *m, *head;
532190579Ssam	struct ieee80211_node *ni;
533190579Ssam
534244044Sadrian#if 0
535190579Ssam	KASSERT(sq->head != NULL, ("stageq empty"));
536244044Sadrian#endif
537190579Ssam
538190579Ssam	IEEE80211_LOCK(ic);
539190579Ssam	head = sq->head;
540190579Ssam	while ((m = sq->head) != NULL && M_AGE_GET(m) < quanta) {
541234324Sadrian		int tid = WME_AC_TO_TID(M_WME_GETAC(m));
542234324Sadrian
543288318Sadrian		/* clear staging ref to frame */
544190579Ssam		ni = (struct ieee80211_node *) m->m_pkthdr.rcvif;
545288318Sadrian		KASSERT(ni->ni_tx_superg[tid] == m, ("staging queue empty"));
546288318Sadrian		ni->ni_tx_superg[tid] = NULL;
547190579Ssam
548190579Ssam		sq->head = m->m_nextpkt;
549190579Ssam		sq->depth--;
550190579Ssam	}
551190579Ssam	if (m == NULL)
552190579Ssam		sq->tail = NULL;
553190579Ssam	else
554190579Ssam		M_AGE_SUB(m, quanta);
555190579Ssam	IEEE80211_UNLOCK(ic);
556190579Ssam
557248069Sadrian	IEEE80211_TX_LOCK(ic);
558190579Ssam	ff_flush(head, m);
559248069Sadrian	IEEE80211_TX_UNLOCK(ic);
560190579Ssam}
561190579Ssam
562190579Ssamstatic void
563244051Sadrianstageq_add(struct ieee80211com *ic, struct ieee80211_stageq *sq, struct mbuf *m)
564190579Ssam{
565190579Ssam	int age = ieee80211_ffagemax;
566244051Sadrian
567244051Sadrian	IEEE80211_LOCK_ASSERT(ic);
568244051Sadrian
569190579Ssam	if (sq->tail != NULL) {
570190579Ssam		sq->tail->m_nextpkt = m;
571190579Ssam		age -= M_AGE_GET(sq->head);
572190579Ssam	} else
573190579Ssam		sq->head = m;
574190579Ssam	KASSERT(age >= 0, ("age %d", age));
575190579Ssam	M_AGE_SET(m, age);
576190579Ssam	m->m_nextpkt = NULL;
577190579Ssam	sq->tail = m;
578190579Ssam	sq->depth++;
579190579Ssam}
580190579Ssam
581190579Ssamstatic void
582244051Sadrianstageq_remove(struct ieee80211com *ic, struct ieee80211_stageq *sq, struct mbuf *mstaged)
583190579Ssam{
584190579Ssam	struct mbuf *m, *mprev;
585190579Ssam
586244051Sadrian	IEEE80211_LOCK_ASSERT(ic);
587244051Sadrian
588190579Ssam	mprev = NULL;
589190579Ssam	for (m = sq->head; m != NULL; m = m->m_nextpkt) {
590190579Ssam		if (m == mstaged) {
591190579Ssam			if (mprev == NULL)
592190579Ssam				sq->head = m->m_nextpkt;
593190579Ssam			else
594190579Ssam				mprev->m_nextpkt = m->m_nextpkt;
595190579Ssam			if (sq->tail == m)
596190579Ssam				sq->tail = mprev;
597190579Ssam			sq->depth--;
598190579Ssam			return;
599190579Ssam		}
600190579Ssam		mprev = m;
601190579Ssam	}
602190579Ssam	printf("%s: packet not found\n", __func__);
603190579Ssam}
604190579Ssam
605190579Ssamstatic uint32_t
606190579Ssamff_approx_txtime(struct ieee80211_node *ni,
607190579Ssam	const struct mbuf *m1, const struct mbuf *m2)
608190579Ssam{
609190579Ssam	struct ieee80211com *ic = ni->ni_ic;
610190579Ssam	struct ieee80211vap *vap = ni->ni_vap;
611190579Ssam	uint32_t framelen;
612190579Ssam
613190579Ssam	/*
614190579Ssam	 * Approximate the frame length to be transmitted. A swag to add
615190579Ssam	 * the following maximal values to the skb payload:
616190579Ssam	 *   - 32: 802.11 encap + CRC
617190579Ssam	 *   - 24: encryption overhead (if wep bit)
618190579Ssam	 *   - 4 + 6: fast-frame header and padding
619190579Ssam	 *   - 16: 2 LLC FF tunnel headers
620190579Ssam	 *   - 14: 1 802.3 FF tunnel header (mbuf already accounts for 2nd)
621190579Ssam	 */
622190579Ssam	framelen = m1->m_pkthdr.len + 32 +
623190579Ssam	    ATH_FF_MAX_HDR_PAD + ATH_FF_MAX_SEP_PAD + ATH_FF_MAX_HDR;
624190579Ssam	if (vap->iv_flags & IEEE80211_F_PRIVACY)
625190579Ssam		framelen += 24;
626190579Ssam	if (m2 != NULL)
627190579Ssam		framelen += m2->m_pkthdr.len;
628190579Ssam	return ieee80211_compute_duration(ic->ic_rt, framelen, ni->ni_txrate, 0);
629190579Ssam}
630190579Ssam
631190579Ssam/*
632190579Ssam * Check if the supplied frame can be partnered with an existing
633190579Ssam * or pending frame.  Return a reference to any frame that should be
634190579Ssam * sent on return; otherwise return NULL.
635190579Ssam */
636190579Ssamstruct mbuf *
637190579Ssamieee80211_ff_check(struct ieee80211_node *ni, struct mbuf *m)
638190579Ssam{
639190579Ssam	struct ieee80211vap *vap = ni->ni_vap;
640190579Ssam	struct ieee80211com *ic = ni->ni_ic;
641191753Ssam	struct ieee80211_superg *sg = ic->ic_superg;
642190579Ssam	const int pri = M_WME_GETAC(m);
643190579Ssam	struct ieee80211_stageq *sq;
644190579Ssam	struct ieee80211_tx_ampdu *tap;
645190579Ssam	struct mbuf *mstaged;
646190579Ssam	uint32_t txtime, limit;
647190579Ssam
648248069Sadrian	IEEE80211_TX_UNLOCK_ASSERT(ic);
649248069Sadrian
650190579Ssam	/*
651190579Ssam	 * Check if the supplied frame can be aggregated.
652190579Ssam	 *
653190579Ssam	 * NB: we allow EAPOL frames to be aggregated with other ucast traffic.
654190579Ssam	 *     Do 802.1x EAPOL frames proceed in the clear? Then they couldn't
655190579Ssam	 *     be aggregated with other types of frames when encryption is on?
656190579Ssam	 */
657190579Ssam	IEEE80211_LOCK(ic);
658234324Sadrian	tap = &ni->ni_tx_ampdu[WME_AC_TO_TID(pri)];
659288318Sadrian	mstaged = ni->ni_tx_superg[WME_AC_TO_TID(pri)];
660288318Sadrian	/* XXX NOTE: reusing packet counter state from A-MPDU */
661288318Sadrian	/*
662288318Sadrian	 * XXX NOTE: this means we're double-counting; it should just
663288318Sadrian	 * be done in ieee80211_output.c once for both superg and A-MPDU.
664288318Sadrian	 */
665190579Ssam	ieee80211_txampdu_count_packet(tap);
666190579Ssam
667190579Ssam	/*
668190579Ssam	 * When not in station mode never aggregate a multicast
669190579Ssam	 * frame; this insures, for example, that a combined frame
670190579Ssam	 * does not require multiple encryption keys.
671190579Ssam	 */
672190579Ssam	if (vap->iv_opmode != IEEE80211_M_STA &&
673190579Ssam	    ETHER_IS_MULTICAST(mtod(m, struct ether_header *)->ether_dhost)) {
674190579Ssam		/* XXX flush staged frame? */
675190579Ssam		IEEE80211_UNLOCK(ic);
676190579Ssam		return m;
677190579Ssam	}
678190579Ssam	/*
679190579Ssam	 * If there is no frame to combine with and the pps is
680190579Ssam	 * too low; then do not attempt to aggregate this frame.
681190579Ssam	 */
682288318Sadrian	IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
683288318Sadrian	    "%s: staged: %p; pps: %d\n", __func__, mstaged, ieee80211_txampdu_getpps(tap));
684190579Ssam	if (mstaged == NULL &&
685190579Ssam	    ieee80211_txampdu_getpps(tap) < ieee80211_ffppsmin) {
686190579Ssam		IEEE80211_UNLOCK(ic);
687190579Ssam		return m;
688190579Ssam	}
689191753Ssam	sq = &sg->ff_stageq[pri];
690190579Ssam	/*
691190579Ssam	 * Check the txop limit to insure the aggregate fits.
692190579Ssam	 */
693190579Ssam	limit = IEEE80211_TXOP_TO_US(
694190579Ssam		ic->ic_wme.wme_chanParams.cap_wmeParams[pri].wmep_txopLimit);
695190579Ssam	if (limit != 0 &&
696190579Ssam	    (txtime = ff_approx_txtime(ni, m, mstaged)) > limit) {
697190579Ssam		/*
698190579Ssam		 * Aggregate too long, return to the caller for direct
699190579Ssam		 * transmission.  In addition, flush any pending frame
700190579Ssam		 * before sending this one.
701190579Ssam		 */
702190579Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
703190579Ssam		    "%s: txtime %u exceeds txop limit %u\n",
704190579Ssam		    __func__, txtime, limit);
705190579Ssam
706288318Sadrian		ni->ni_tx_superg[WME_AC_TO_TID(pri)] = NULL;
707190579Ssam		if (mstaged != NULL)
708244051Sadrian			stageq_remove(ic, sq, mstaged);
709190579Ssam		IEEE80211_UNLOCK(ic);
710190579Ssam
711190579Ssam		if (mstaged != NULL) {
712248069Sadrian			IEEE80211_TX_LOCK(ic);
713190579Ssam			IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
714190579Ssam			    "%s: flush staged frame", __func__);
715190579Ssam			/* encap and xmit */
716190579Ssam			ff_transmit(ni, mstaged);
717248069Sadrian			IEEE80211_TX_UNLOCK(ic);
718190579Ssam		}
719190579Ssam		return m;		/* NB: original frame */
720190579Ssam	}
721190579Ssam	/*
722190579Ssam	 * An aggregation candidate.  If there's a frame to partner
723190579Ssam	 * with then combine and return for processing.  Otherwise
724190579Ssam	 * save this frame and wait for a partner to show up (or
725190579Ssam	 * the frame to be flushed).  Note that staged frames also
726190579Ssam	 * hold their node reference.
727190579Ssam	 */
728190579Ssam	if (mstaged != NULL) {
729288318Sadrian		ni->ni_tx_superg[WME_AC_TO_TID(pri)] = NULL;
730244051Sadrian		stageq_remove(ic, sq, mstaged);
731190579Ssam		IEEE80211_UNLOCK(ic);
732190579Ssam
733190579Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
734190579Ssam		    "%s: aggregate fast-frame", __func__);
735190579Ssam		/*
736190579Ssam		 * Release the node reference; we only need
737190579Ssam		 * the one already in mstaged.
738190579Ssam		 */
739190579Ssam		KASSERT(mstaged->m_pkthdr.rcvif == (void *)ni,
740190579Ssam		    ("rcvif %p ni %p", mstaged->m_pkthdr.rcvif, ni));
741190579Ssam		ieee80211_free_node(ni);
742190579Ssam
743190579Ssam		m->m_nextpkt = NULL;
744190579Ssam		mstaged->m_nextpkt = m;
745190579Ssam		mstaged->m_flags |= M_FF; /* NB: mark for encap work */
746190579Ssam	} else {
747288318Sadrian		KASSERT(ni->ni_tx_superg[WME_AC_TO_TID(pri)]== NULL,
748288318Sadrian		    ("ni_tx_superg[]: %p",
749288318Sadrian		    ni->ni_tx_superg[WME_AC_TO_TID(pri)]));
750288318Sadrian		ni->ni_tx_superg[WME_AC_TO_TID(pri)] = m;
751190579Ssam
752244051Sadrian		stageq_add(ic, sq, m);
753190579Ssam		IEEE80211_UNLOCK(ic);
754190579Ssam
755190579Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
756190579Ssam		    "%s: stage frame, %u queued", __func__, sq->depth);
757190579Ssam		/* NB: mstaged is NULL */
758190579Ssam	}
759190579Ssam	return mstaged;
760190579Ssam}
761190579Ssam
762190579Ssamvoid
763190579Ssamieee80211_ff_node_init(struct ieee80211_node *ni)
764190579Ssam{
765190579Ssam	/*
766190579Ssam	 * Clean FF state on re-associate.  This handles the case
767190579Ssam	 * where a station leaves w/o notifying us and then returns
768190579Ssam	 * before node is reaped for inactivity.
769190579Ssam	 */
770190579Ssam	ieee80211_ff_node_cleanup(ni);
771190579Ssam}
772190579Ssam
773190579Ssamvoid
774190579Ssamieee80211_ff_node_cleanup(struct ieee80211_node *ni)
775190579Ssam{
776190579Ssam	struct ieee80211com *ic = ni->ni_ic;
777191753Ssam	struct ieee80211_superg *sg = ic->ic_superg;
778244025Sadrian	struct mbuf *m, *next_m, *head;
779234324Sadrian	int tid;
780190579Ssam
781190579Ssam	IEEE80211_LOCK(ic);
782190579Ssam	head = NULL;
783234324Sadrian	for (tid = 0; tid < WME_NUM_TID; tid++) {
784234324Sadrian		int ac = TID_TO_WME_AC(tid);
785288318Sadrian		/*
786288318Sadrian		 * XXX Initialise the packet counter.
787288318Sadrian		 *
788288318Sadrian		 * This may be double-work for 11n stations;
789288318Sadrian		 * but without it we never setup things.
790288318Sadrian		 */
791288318Sadrian		ieee80211_txampdu_init_pps(&ni->ni_tx_ampdu[tid]);
792288318Sadrian		m = ni->ni_tx_superg[tid];
793190579Ssam		if (m != NULL) {
794288318Sadrian			ni->ni_tx_superg[tid] = NULL;
795244051Sadrian			stageq_remove(ic, &sg->ff_stageq[ac], m);
796190579Ssam			m->m_nextpkt = head;
797190579Ssam			head = m;
798190579Ssam		}
799190579Ssam	}
800190579Ssam	IEEE80211_UNLOCK(ic);
801190579Ssam
802244025Sadrian	/*
803244025Sadrian	 * Free mbufs, taking care to not dereference the mbuf after
804244025Sadrian	 * we free it (hence grabbing m_nextpkt before we free it.)
805244025Sadrian	 */
806244025Sadrian	m = head;
807244025Sadrian	while (m != NULL) {
808244025Sadrian		next_m = m->m_nextpkt;
809190579Ssam		m_freem(m);
810190579Ssam		ieee80211_free_node(ni);
811244025Sadrian		m = next_m;
812190579Ssam	}
813190579Ssam}
814190579Ssam
815190579Ssam/*
816190391Ssam * Switch between turbo and non-turbo operating modes.
817190391Ssam * Use the specified channel flags to locate the new
818190391Ssam * channel, update 802.11 state, and then call back into
819190391Ssam * the driver to effect the change.
820190391Ssam */
821190391Ssamvoid
822190391Ssamieee80211_dturbo_switch(struct ieee80211vap *vap, int newflags)
823190391Ssam{
824190391Ssam	struct ieee80211com *ic = vap->iv_ic;
825190391Ssam	struct ieee80211_channel *chan;
826190391Ssam
827190391Ssam	chan = ieee80211_find_channel(ic, ic->ic_bsschan->ic_freq, newflags);
828190391Ssam	if (chan == NULL) {		/* XXX should not happen */
829190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
830190391Ssam		    "%s: no channel with freq %u flags 0x%x\n",
831190391Ssam		    __func__, ic->ic_bsschan->ic_freq, newflags);
832190391Ssam		return;
833190391Ssam	}
834190391Ssam
835190391Ssam	IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
836190391Ssam	    "%s: %s -> %s (freq %u flags 0x%x)\n", __func__,
837190391Ssam	    ieee80211_phymode_name[ieee80211_chan2mode(ic->ic_bsschan)],
838190391Ssam	    ieee80211_phymode_name[ieee80211_chan2mode(chan)],
839190391Ssam	    chan->ic_freq, chan->ic_flags);
840190391Ssam
841190391Ssam	ic->ic_bsschan = chan;
842190391Ssam	ic->ic_prevchan = ic->ic_curchan;
843190391Ssam	ic->ic_curchan = chan;
844190532Ssam	ic->ic_rt = ieee80211_get_ratetable(chan);
845190391Ssam	ic->ic_set_channel(ic);
846192468Ssam	ieee80211_radiotap_chan_change(ic);
847190391Ssam	/* NB: do not need to reset ERP state 'cuz we're in sta mode */
848190391Ssam}
849190391Ssam
850190391Ssam/*
851190391Ssam * Return the current ``state'' of an Atheros capbility.
852190391Ssam * If associated in station mode report the negotiated
853190391Ssam * setting. Otherwise report the current setting.
854190391Ssam */
855190391Ssamstatic int
856190391Ssamgetathcap(struct ieee80211vap *vap, int cap)
857190391Ssam{
858190391Ssam	if (vap->iv_opmode == IEEE80211_M_STA &&
859190391Ssam	    vap->iv_state == IEEE80211_S_RUN)
860190391Ssam		return IEEE80211_ATH_CAP(vap, vap->iv_bss, cap) != 0;
861190391Ssam	else
862190391Ssam		return (vap->iv_flags & cap) != 0;
863190391Ssam}
864190391Ssam
865190391Ssamstatic int
866190391Ssamsuperg_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
867190391Ssam{
868190391Ssam	switch (ireq->i_type) {
869190391Ssam	case IEEE80211_IOC_FF:
870190391Ssam		ireq->i_val = getathcap(vap, IEEE80211_F_FF);
871190391Ssam		break;
872190391Ssam	case IEEE80211_IOC_TURBOP:
873190391Ssam		ireq->i_val = getathcap(vap, IEEE80211_F_TURBOP);
874190391Ssam		break;
875190391Ssam	default:
876190391Ssam		return ENOSYS;
877190391Ssam	}
878190391Ssam	return 0;
879190391Ssam}
880190391SsamIEEE80211_IOCTL_GET(superg, superg_ioctl_get80211);
881190391Ssam
882190391Ssamstatic int
883190391Ssamsuperg_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
884190391Ssam{
885190391Ssam	switch (ireq->i_type) {
886190391Ssam	case IEEE80211_IOC_FF:
887190391Ssam		if (ireq->i_val) {
888190391Ssam			if ((vap->iv_caps & IEEE80211_C_FF) == 0)
889190391Ssam				return EOPNOTSUPP;
890190391Ssam			vap->iv_flags |= IEEE80211_F_FF;
891190391Ssam		} else
892190391Ssam			vap->iv_flags &= ~IEEE80211_F_FF;
893190530Ssam		return ENETRESET;
894190391Ssam	case IEEE80211_IOC_TURBOP:
895190391Ssam		if (ireq->i_val) {
896190391Ssam			if ((vap->iv_caps & IEEE80211_C_TURBOP) == 0)
897190391Ssam				return EOPNOTSUPP;
898190391Ssam			vap->iv_flags |= IEEE80211_F_TURBOP;
899190391Ssam		} else
900190391Ssam			vap->iv_flags &= ~IEEE80211_F_TURBOP;
901190391Ssam		return ENETRESET;
902190391Ssam	default:
903190391Ssam		return ENOSYS;
904190391Ssam	}
905190391Ssam	return 0;
906190391Ssam}
907190391SsamIEEE80211_IOCTL_SET(superg, superg_ioctl_set80211);
908246226Sadrian
909246226Sadrian#endif	/* IEEE80211_SUPPORT_SUPERG */
910