ieee80211_superg.c revision 244025
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 244025 2012-12-08 09:48:03Z adrian $");
28190391Ssam
29190391Ssam#include "opt_wlan.h"
30190391Ssam
31190391Ssam#include <sys/param.h>
32190391Ssam#include <sys/systm.h>
33190391Ssam#include <sys/mbuf.h>
34190391Ssam#include <sys/kernel.h>
35190391Ssam#include <sys/endian.h>
36190391Ssam
37190391Ssam#include <sys/socket.h>
38190391Ssam
39190391Ssam#include <net/bpf.h>
40190391Ssam#include <net/ethernet.h>
41190391Ssam#include <net/if.h>
42190391Ssam#include <net/if_llc.h>
43190391Ssam#include <net/if_media.h>
44190391Ssam
45190391Ssam#include <net80211/ieee80211_var.h>
46190391Ssam#include <net80211/ieee80211_input.h>
47190391Ssam#include <net80211/ieee80211_phy.h>
48190391Ssam#include <net80211/ieee80211_superg.h>
49190391Ssam
50190455Ssam/*
51190455Ssam * Atheros fast-frame encapsulation format.
52190455Ssam * FF max payload:
53190455Ssam * 802.2 + FFHDR + HPAD + 802.3 + 802.2 + 1500 + SPAD + 802.3 + 802.2 + 1500:
54190455Ssam *   8   +   4   +  4   +   14  +   8   + 1500 +  6   +   14  +   8   + 1500
55190455Ssam * = 3066
56190455Ssam */
57190455Ssam/* fast frame header is 32-bits */
58190455Ssam#define	ATH_FF_PROTO	0x0000003f	/* protocol */
59190455Ssam#define	ATH_FF_PROTO_S	0
60190455Ssam#define	ATH_FF_FTYPE	0x000000c0	/* frame type */
61190455Ssam#define	ATH_FF_FTYPE_S	6
62190455Ssam#define	ATH_FF_HLEN32	0x00000300	/* optional hdr length */
63190455Ssam#define	ATH_FF_HLEN32_S	8
64190455Ssam#define	ATH_FF_SEQNUM	0x001ffc00	/* sequence number */
65190455Ssam#define	ATH_FF_SEQNUM_S	10
66190455Ssam#define	ATH_FF_OFFSET	0xffe00000	/* offset to 2nd payload */
67190455Ssam#define	ATH_FF_OFFSET_S	21
68190455Ssam
69190455Ssam#define	ATH_FF_MAX_HDR_PAD	4
70190455Ssam#define	ATH_FF_MAX_SEP_PAD	6
71190455Ssam#define	ATH_FF_MAX_HDR		30
72190455Ssam
73190455Ssam#define	ATH_FF_PROTO_L2TUNNEL	0	/* L2 tunnel protocol */
74190455Ssam#define	ATH_FF_ETH_TYPE		0x88bd	/* Ether type for encapsulated frames */
75190455Ssam#define	ATH_FF_SNAP_ORGCODE_0	0x00
76190455Ssam#define	ATH_FF_SNAP_ORGCODE_1	0x03
77190455Ssam#define	ATH_FF_SNAP_ORGCODE_2	0x7f
78190455Ssam
79190579Ssam#define	ATH_FF_TXQMIN	2		/* min txq depth for staging */
80190579Ssam#define	ATH_FF_TXQMAX	50		/* maximum # of queued frames allowed */
81190579Ssam#define	ATH_FF_STAGEMAX	5		/* max waiting period for staged frame*/
82190579Ssam
83190391Ssam#define	ETHER_HEADER_COPY(dst, src) \
84190391Ssam	memcpy(dst, src, sizeof(struct ether_header))
85190391Ssam
86193115Ssamstatic	int ieee80211_ffppsmin = 2;	/* pps threshold for ff aggregation */
87193115SsamSYSCTL_INT(_net_wlan, OID_AUTO, ffppsmin, CTLTYPE_INT | CTLFLAG_RW,
88193115Ssam	&ieee80211_ffppsmin, 0, "min packet rate before fast-frame staging");
89193115Ssamstatic	int ieee80211_ffagemax = -1;	/* max time frames held on stage q */
90193115SsamSYSCTL_PROC(_net_wlan, OID_AUTO, ffagemax, CTLTYPE_INT | CTLFLAG_RW,
91193115Ssam	&ieee80211_ffagemax, 0, ieee80211_sysctl_msecs_ticks, "I",
92193115Ssam	"max hold time for fast-frame staging (ms)");
93190579Ssam
94190391Ssamvoid
95190391Ssamieee80211_superg_attach(struct ieee80211com *ic)
96190391Ssam{
97191753Ssam	struct ieee80211_superg *sg;
98191753Ssam
99191753Ssam	if (ic->ic_caps & IEEE80211_C_FF) {
100191753Ssam		sg = (struct ieee80211_superg *) malloc(
101191753Ssam		     sizeof(struct ieee80211_superg), M_80211_VAP,
102191753Ssam		     M_NOWAIT | M_ZERO);
103191753Ssam		if (sg == NULL) {
104191753Ssam			printf("%s: cannot allocate SuperG state block\n",
105191753Ssam			    __func__);
106191753Ssam			return;
107191753Ssam		}
108191753Ssam		ic->ic_superg = sg;
109191753Ssam	}
110190579Ssam	ieee80211_ffagemax = msecs_to_ticks(150);
111190391Ssam}
112190391Ssam
113190391Ssamvoid
114190391Ssamieee80211_superg_detach(struct ieee80211com *ic)
115190391Ssam{
116191753Ssam	if (ic->ic_superg != NULL) {
117191753Ssam		free(ic->ic_superg, M_80211_VAP);
118191753Ssam		ic->ic_superg = NULL;
119191753Ssam	}
120190391Ssam}
121190391Ssam
122190391Ssamvoid
123190391Ssamieee80211_superg_vattach(struct ieee80211vap *vap)
124190391Ssam{
125191753Ssam	struct ieee80211com *ic = vap->iv_ic;
126191753Ssam
127191753Ssam	if (ic->ic_superg == NULL)	/* NB: can't do fast-frames w/o state */
128191753Ssam		vap->iv_caps &= ~IEEE80211_C_FF;
129190391Ssam	if (vap->iv_caps & IEEE80211_C_FF)
130190391Ssam		vap->iv_flags |= IEEE80211_F_FF;
131190450Ssam	/* NB: we only implement sta mode */
132190450Ssam	if (vap->iv_opmode == IEEE80211_M_STA &&
133190450Ssam	    (vap->iv_caps & IEEE80211_C_TURBOP))
134190391Ssam		vap->iv_flags |= IEEE80211_F_TURBOP;
135190391Ssam}
136190391Ssam
137190391Ssamvoid
138190391Ssamieee80211_superg_vdetach(struct ieee80211vap *vap)
139190391Ssam{
140190391Ssam}
141190391Ssam
142190391Ssam#define	ATH_OUI_BYTES		0x00, 0x03, 0x7f
143190391Ssam/*
144190391Ssam * Add a WME information element to a frame.
145190391Ssam */
146190391Ssamuint8_t *
147190451Ssamieee80211_add_ath(uint8_t *frm, uint8_t caps, ieee80211_keyix defkeyix)
148190391Ssam{
149190391Ssam	static const struct ieee80211_ath_ie info = {
150190391Ssam		.ath_id		= IEEE80211_ELEMID_VENDOR,
151190391Ssam		.ath_len	= sizeof(struct ieee80211_ath_ie) - 2,
152190391Ssam		.ath_oui	= { ATH_OUI_BYTES },
153190391Ssam		.ath_oui_type	= ATH_OUI_TYPE,
154190391Ssam		.ath_oui_subtype= ATH_OUI_SUBTYPE,
155190391Ssam		.ath_version	= ATH_OUI_VERSION,
156190391Ssam	};
157190391Ssam	struct ieee80211_ath_ie *ath = (struct ieee80211_ath_ie *) frm;
158190391Ssam
159190391Ssam	memcpy(frm, &info, sizeof(info));
160190391Ssam	ath->ath_capability = caps;
161190451Ssam	if (defkeyix != IEEE80211_KEYIX_NONE) {
162190451Ssam		ath->ath_defkeyix[0] = (defkeyix & 0xff);
163190451Ssam		ath->ath_defkeyix[1] = ((defkeyix >> 8) & 0xff);
164190451Ssam	} else {
165190451Ssam		ath->ath_defkeyix[0] = 0xff;
166190451Ssam		ath->ath_defkeyix[1] = 0x7f;
167190451Ssam	}
168190391Ssam	return frm + sizeof(info);
169190391Ssam}
170190391Ssam#undef ATH_OUI_BYTES
171190391Ssam
172190451Ssamuint8_t *
173190451Ssamieee80211_add_athcaps(uint8_t *frm, const struct ieee80211_node *bss)
174190451Ssam{
175190451Ssam	const struct ieee80211vap *vap = bss->ni_vap;
176190451Ssam
177190451Ssam	return ieee80211_add_ath(frm,
178190451Ssam	    vap->iv_flags & IEEE80211_F_ATHEROS,
179190451Ssam	    ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
180190451Ssam	    bss->ni_authmode != IEEE80211_AUTH_8021X) ?
181190451Ssam	    vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
182190451Ssam}
183190451Ssam
184190391Ssamvoid
185190391Ssamieee80211_parse_ath(struct ieee80211_node *ni, uint8_t *ie)
186190391Ssam{
187190391Ssam	const struct ieee80211_ath_ie *ath =
188190391Ssam		(const struct ieee80211_ath_ie *) ie;
189190391Ssam
190190391Ssam	ni->ni_ath_flags = ath->ath_capability;
191190391Ssam	ni->ni_ath_defkeyix = LE_READ_2(&ath->ath_defkeyix);
192190391Ssam}
193190391Ssam
194190391Ssamint
195190391Ssamieee80211_parse_athparams(struct ieee80211_node *ni, uint8_t *frm,
196190391Ssam	const struct ieee80211_frame *wh)
197190391Ssam{
198190391Ssam	struct ieee80211vap *vap = ni->ni_vap;
199190391Ssam	const struct ieee80211_ath_ie *ath;
200190391Ssam	u_int len = frm[1];
201190391Ssam	int capschanged;
202190391Ssam	uint16_t defkeyix;
203190391Ssam
204190391Ssam	if (len < sizeof(struct ieee80211_ath_ie)-2) {
205190391Ssam		IEEE80211_DISCARD_IE(vap,
206190391Ssam		    IEEE80211_MSG_ELEMID | IEEE80211_MSG_SUPERG,
207190391Ssam		    wh, "Atheros", "too short, len %u", len);
208190391Ssam		return -1;
209190391Ssam	}
210190391Ssam	ath = (const struct ieee80211_ath_ie *)frm;
211190391Ssam	capschanged = (ni->ni_ath_flags != ath->ath_capability);
212190391Ssam	defkeyix = LE_READ_2(ath->ath_defkeyix);
213190391Ssam	if (capschanged || defkeyix != ni->ni_ath_defkeyix) {
214190391Ssam		ni->ni_ath_flags = ath->ath_capability;
215190391Ssam		ni->ni_ath_defkeyix = defkeyix;
216190391Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
217190391Ssam		    "ath ie change: new caps 0x%x defkeyix 0x%x",
218190391Ssam		    ni->ni_ath_flags, ni->ni_ath_defkeyix);
219190391Ssam	}
220190391Ssam	if (IEEE80211_ATH_CAP(vap, ni, ATHEROS_CAP_TURBO_PRIME)) {
221190391Ssam		uint16_t curflags, newflags;
222190391Ssam
223190391Ssam		/*
224190391Ssam		 * Check for turbo mode switch.  Calculate flags
225190391Ssam		 * for the new mode and effect the switch.
226190391Ssam		 */
227190391Ssam		newflags = curflags = vap->iv_ic->ic_bsschan->ic_flags;
228190391Ssam		/* NB: BOOST is not in ic_flags, so get it from the ie */
229190391Ssam		if (ath->ath_capability & ATHEROS_CAP_BOOST)
230190391Ssam			newflags |= IEEE80211_CHAN_TURBO;
231190391Ssam		else
232190391Ssam			newflags &= ~IEEE80211_CHAN_TURBO;
233190391Ssam		if (newflags != curflags)
234190391Ssam			ieee80211_dturbo_switch(vap, newflags);
235190391Ssam	}
236190391Ssam	return capschanged;
237190391Ssam}
238190391Ssam
239190391Ssam/*
240190391Ssam * Decap the encapsulated frame pair and dispatch the first
241190391Ssam * for delivery.  The second frame is returned for delivery
242190391Ssam * via the normal path.
243190391Ssam */
244190391Ssamstruct mbuf *
245190391Ssamieee80211_ff_decap(struct ieee80211_node *ni, struct mbuf *m)
246190391Ssam{
247190391Ssam#define	FF_LLC_SIZE	(sizeof(struct ether_header) + sizeof(struct llc))
248190391Ssam#define	MS(x,f)	(((x) & f) >> f##_S)
249190391Ssam	struct ieee80211vap *vap = ni->ni_vap;
250190391Ssam	struct llc *llc;
251190391Ssam	uint32_t ath;
252190391Ssam	struct mbuf *n;
253190391Ssam	int framelen;
254190391Ssam
255190391Ssam	/* NB: we assume caller does this check for us */
256190391Ssam	KASSERT(IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF),
257190391Ssam	    ("ff not negotiated"));
258190391Ssam	/*
259190391Ssam	 * Check for fast-frame tunnel encapsulation.
260190391Ssam	 */
261190391Ssam	if (m->m_pkthdr.len < 3*FF_LLC_SIZE)
262190391Ssam		return m;
263190391Ssam	if (m->m_len < FF_LLC_SIZE &&
264190391Ssam	    (m = m_pullup(m, FF_LLC_SIZE)) == NULL) {
265190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
266190391Ssam		    ni->ni_macaddr, "fast-frame",
267190391Ssam		    "%s", "m_pullup(llc) failed");
268190391Ssam		vap->iv_stats.is_rx_tooshort++;
269190391Ssam		return NULL;
270190391Ssam	}
271190391Ssam	llc = (struct llc *)(mtod(m, uint8_t *) +
272190391Ssam	    sizeof(struct ether_header));
273190391Ssam	if (llc->llc_snap.ether_type != htons(ATH_FF_ETH_TYPE))
274190391Ssam		return m;
275190391Ssam	m_adj(m, FF_LLC_SIZE);
276190391Ssam	m_copydata(m, 0, sizeof(uint32_t), (caddr_t) &ath);
277190391Ssam	if (MS(ath, ATH_FF_PROTO) != ATH_FF_PROTO_L2TUNNEL) {
278190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
279190391Ssam		    ni->ni_macaddr, "fast-frame",
280190391Ssam		    "unsupport tunnel protocol, header 0x%x", ath);
281190391Ssam		vap->iv_stats.is_ff_badhdr++;
282190391Ssam		m_freem(m);
283190391Ssam		return NULL;
284190391Ssam	}
285190391Ssam	/* NB: skip header and alignment padding */
286190391Ssam	m_adj(m, roundup(sizeof(uint32_t) - 2, 4) + 2);
287190391Ssam
288190391Ssam	vap->iv_stats.is_ff_decap++;
289190391Ssam
290190391Ssam	/*
291190391Ssam	 * Decap the first frame, bust it apart from the
292190391Ssam	 * second and deliver; then decap the second frame
293190391Ssam	 * and return it to the caller for normal delivery.
294190391Ssam	 */
295190391Ssam	m = ieee80211_decap1(m, &framelen);
296190391Ssam	if (m == NULL) {
297190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
298190391Ssam		    ni->ni_macaddr, "fast-frame", "%s", "first decap failed");
299190391Ssam		vap->iv_stats.is_ff_tooshort++;
300190391Ssam		return NULL;
301190391Ssam	}
302190391Ssam	n = m_split(m, framelen, M_NOWAIT);
303190391Ssam	if (n == NULL) {
304190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
305190391Ssam		    ni->ni_macaddr, "fast-frame",
306190391Ssam		    "%s", "unable to split encapsulated frames");
307190391Ssam		vap->iv_stats.is_ff_split++;
308190391Ssam		m_freem(m);			/* NB: must reclaim */
309190391Ssam		return NULL;
310190391Ssam	}
311190391Ssam	/* XXX not right for WDS */
312190391Ssam	vap->iv_deliver_data(vap, ni, m);	/* 1st of pair */
313190391Ssam
314190391Ssam	/*
315190391Ssam	 * Decap second frame.
316190391Ssam	 */
317190391Ssam	m_adj(n, roundup2(framelen, 4) - framelen);	/* padding */
318190391Ssam	n = ieee80211_decap1(n, &framelen);
319190391Ssam	if (n == NULL) {
320190391Ssam		IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
321190391Ssam		    ni->ni_macaddr, "fast-frame", "%s", "second decap failed");
322190391Ssam		vap->iv_stats.is_ff_tooshort++;
323190391Ssam	}
324190391Ssam	/* XXX verify framelen against mbuf contents */
325190391Ssam	return n;				/* 2nd delivered by caller */
326190391Ssam#undef MS
327190391Ssam#undef FF_LLC_SIZE
328190391Ssam}
329190391Ssam
330190391Ssam/*
331190391Ssam * Do Ethernet-LLC encapsulation for each payload in a fast frame
332190391Ssam * tunnel encapsulation.  The frame is assumed to have an Ethernet
333190391Ssam * header at the front that must be stripped before prepending the
334190391Ssam * LLC followed by the Ethernet header passed in (with an Ethernet
335190391Ssam * type that specifies the payload size).
336190391Ssam */
337190391Ssamstatic struct mbuf *
338190391Ssamff_encap1(struct ieee80211vap *vap, struct mbuf *m,
339190391Ssam	const struct ether_header *eh)
340190391Ssam{
341190391Ssam	struct llc *llc;
342190391Ssam	uint16_t payload;
343190391Ssam
344190391Ssam	/* XXX optimize by combining m_adj+M_PREPEND */
345190391Ssam	m_adj(m, sizeof(struct ether_header) - sizeof(struct llc));
346190391Ssam	llc = mtod(m, struct llc *);
347190391Ssam	llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
348190391Ssam	llc->llc_control = LLC_UI;
349190391Ssam	llc->llc_snap.org_code[0] = 0;
350190391Ssam	llc->llc_snap.org_code[1] = 0;
351190391Ssam	llc->llc_snap.org_code[2] = 0;
352190391Ssam	llc->llc_snap.ether_type = eh->ether_type;
353190391Ssam	payload = m->m_pkthdr.len;		/* NB: w/o Ethernet header */
354190391Ssam
355243882Sglebius	M_PREPEND(m, sizeof(struct ether_header), M_NOWAIT);
356190391Ssam	if (m == NULL) {		/* XXX cannot happen */
357190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
358190391Ssam			"%s: no space for ether_header\n", __func__);
359190391Ssam		vap->iv_stats.is_tx_nobuf++;
360190391Ssam		return NULL;
361190391Ssam	}
362190391Ssam	ETHER_HEADER_COPY(mtod(m, void *), eh);
363190391Ssam	mtod(m, struct ether_header *)->ether_type = htons(payload);
364190391Ssam	return m;
365190391Ssam}
366190391Ssam
367190391Ssam/*
368190391Ssam * Fast frame encapsulation.  There must be two packets
369190391Ssam * chained with m_nextpkt.  We do header adjustment for
370190391Ssam * each, add the tunnel encapsulation, and then concatenate
371190391Ssam * the mbuf chains to form a single frame for transmission.
372190391Ssam */
373190391Ssamstruct mbuf *
374190391Ssamieee80211_ff_encap(struct ieee80211vap *vap, struct mbuf *m1, int hdrspace,
375190391Ssam	struct ieee80211_key *key)
376190391Ssam{
377190391Ssam	struct mbuf *m2;
378190391Ssam	struct ether_header eh1, eh2;
379190391Ssam	struct llc *llc;
380190391Ssam	struct mbuf *m;
381190391Ssam	int pad;
382190391Ssam
383190391Ssam	m2 = m1->m_nextpkt;
384190391Ssam	if (m2 == NULL) {
385190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
386190391Ssam		    "%s: only one frame\n", __func__);
387190391Ssam		goto bad;
388190391Ssam	}
389190391Ssam	m1->m_nextpkt = NULL;
390190391Ssam	/*
391190579Ssam	 * Include fast frame headers in adjusting header layout.
392190391Ssam	 */
393190579Ssam	KASSERT(m1->m_len >= sizeof(eh1), ("no ethernet header!"));
394190579Ssam	ETHER_HEADER_COPY(&eh1, mtod(m1, caddr_t));
395190391Ssam	m1 = ieee80211_mbuf_adjust(vap,
396190391Ssam		hdrspace + sizeof(struct llc) + sizeof(uint32_t) + 2 +
397190391Ssam		    sizeof(struct ether_header),
398190391Ssam		key, m1);
399190391Ssam	if (m1 == NULL) {
400190391Ssam		/* NB: ieee80211_mbuf_adjust handles msgs+statistics */
401190391Ssam		m_freem(m2);
402190391Ssam		goto bad;
403190391Ssam	}
404190391Ssam
405190391Ssam	/*
406190391Ssam	 * Copy second frame's Ethernet header out of line
407190391Ssam	 * and adjust for encapsulation headers.  Note that
408190391Ssam	 * we make room for padding in case there isn't room
409190391Ssam	 * at the end of first frame.
410190391Ssam	 */
411190391Ssam	KASSERT(m2->m_len >= sizeof(eh2), ("no ethernet header!"));
412190391Ssam	ETHER_HEADER_COPY(&eh2, mtod(m2, caddr_t));
413190391Ssam	m2 = ieee80211_mbuf_adjust(vap,
414190391Ssam		ATH_FF_MAX_HDR_PAD + sizeof(struct ether_header),
415190391Ssam		NULL, m2);
416190391Ssam	if (m2 == NULL) {
417190391Ssam		/* NB: ieee80211_mbuf_adjust handles msgs+statistics */
418190391Ssam		goto bad;
419190391Ssam	}
420190391Ssam
421190391Ssam	/*
422190391Ssam	 * Now do tunnel encapsulation.  First, each
423190391Ssam	 * frame gets a standard encapsulation.
424190391Ssam	 */
425190391Ssam	m1 = ff_encap1(vap, m1, &eh1);
426190391Ssam	if (m1 == NULL)
427190391Ssam		goto bad;
428190391Ssam	m2 = ff_encap1(vap, m2, &eh2);
429190391Ssam	if (m2 == NULL)
430190391Ssam		goto bad;
431190391Ssam
432190391Ssam	/*
433190391Ssam	 * Pad leading frame to a 4-byte boundary.  If there
434190391Ssam	 * is space at the end of the first frame, put it
435190391Ssam	 * there; otherwise prepend to the front of the second
436190391Ssam	 * frame.  We know doing the second will always work
437190391Ssam	 * because we reserve space above.  We prefer appending
438190391Ssam	 * as this typically has better DMA alignment properties.
439190391Ssam	 */
440190391Ssam	for (m = m1; m->m_next != NULL; m = m->m_next)
441190391Ssam		;
442190391Ssam	pad = roundup2(m1->m_pkthdr.len, 4) - m1->m_pkthdr.len;
443190391Ssam	if (pad) {
444190391Ssam		if (M_TRAILINGSPACE(m) < pad) {		/* prepend to second */
445190391Ssam			m2->m_data -= pad;
446190391Ssam			m2->m_len += pad;
447190391Ssam			m2->m_pkthdr.len += pad;
448190391Ssam		} else {				/* append to first */
449190391Ssam			m->m_len += pad;
450190391Ssam			m1->m_pkthdr.len += pad;
451190391Ssam		}
452190391Ssam	}
453190391Ssam
454190391Ssam	/*
455190391Ssam	 * Now, stick 'em together and prepend the tunnel headers;
456190391Ssam	 * first the Atheros tunnel header (all zero for now) and
457190391Ssam	 * then a special fast frame LLC.
458190391Ssam	 *
459190391Ssam	 * XXX optimize by prepending together
460190391Ssam	 */
461190391Ssam	m->m_next = m2;			/* NB: last mbuf from above */
462190391Ssam	m1->m_pkthdr.len += m2->m_pkthdr.len;
463243882Sglebius	M_PREPEND(m1, sizeof(uint32_t)+2, M_NOWAIT);
464190391Ssam	if (m1 == NULL) {		/* XXX cannot happen */
465190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
466190391Ssam		    "%s: no space for tunnel header\n", __func__);
467190391Ssam		vap->iv_stats.is_tx_nobuf++;
468190391Ssam		return NULL;
469190391Ssam	}
470190391Ssam	memset(mtod(m1, void *), 0, sizeof(uint32_t)+2);
471190391Ssam
472243882Sglebius	M_PREPEND(m1, sizeof(struct llc), M_NOWAIT);
473190391Ssam	if (m1 == NULL) {		/* XXX cannot happen */
474190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
475190391Ssam		    "%s: no space for llc header\n", __func__);
476190391Ssam		vap->iv_stats.is_tx_nobuf++;
477190391Ssam		return NULL;
478190391Ssam	}
479190391Ssam	llc = mtod(m1, struct llc *);
480190391Ssam	llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
481190391Ssam	llc->llc_control = LLC_UI;
482190391Ssam	llc->llc_snap.org_code[0] = ATH_FF_SNAP_ORGCODE_0;
483190391Ssam	llc->llc_snap.org_code[1] = ATH_FF_SNAP_ORGCODE_1;
484190391Ssam	llc->llc_snap.org_code[2] = ATH_FF_SNAP_ORGCODE_2;
485190391Ssam	llc->llc_snap.ether_type = htons(ATH_FF_ETH_TYPE);
486190391Ssam
487190391Ssam	vap->iv_stats.is_ff_encap++;
488190391Ssam
489190391Ssam	return m1;
490190391Ssambad:
491190391Ssam	if (m1 != NULL)
492190391Ssam		m_freem(m1);
493190391Ssam	if (m2 != NULL)
494190391Ssam		m_freem(m2);
495190391Ssam	return NULL;
496190391Ssam}
497190391Ssam
498190579Ssamstatic void
499190579Ssamff_transmit(struct ieee80211_node *ni, struct mbuf *m)
500190579Ssam{
501190579Ssam	struct ieee80211vap *vap = ni->ni_vap;
502190579Ssam	int error;
503190579Ssam
504190579Ssam	/* encap and xmit */
505190579Ssam	m = ieee80211_encap(vap, ni, m);
506190579Ssam	if (m != NULL) {
507190579Ssam		struct ifnet *ifp = vap->iv_ifp;
508190579Ssam		struct ifnet *parent = ni->ni_ic->ic_ifp;
509190579Ssam
510190579Ssam		error = parent->if_transmit(parent, m);
511190579Ssam		if (error != 0) {
512190579Ssam			/* NB: IFQ_HANDOFF reclaims mbuf */
513190579Ssam			ieee80211_free_node(ni);
514190579Ssam		} else {
515190579Ssam			ifp->if_opackets++;
516190579Ssam		}
517190579Ssam	} else
518190579Ssam		ieee80211_free_node(ni);
519190579Ssam}
520190579Ssam
521190391Ssam/*
522190579Ssam * Flush frames to device; note we re-use the linked list
523190579Ssam * the frames were stored on and use the sentinel (unchanged)
524190579Ssam * which may be non-NULL.
525190579Ssam */
526190579Ssamstatic void
527190579Ssamff_flush(struct mbuf *head, struct mbuf *last)
528190579Ssam{
529190579Ssam	struct mbuf *m, *next;
530190579Ssam	struct ieee80211_node *ni;
531190579Ssam	struct ieee80211vap *vap;
532190579Ssam
533190579Ssam	for (m = head; m != last; m = next) {
534190579Ssam		next = m->m_nextpkt;
535190579Ssam		m->m_nextpkt = NULL;
536190579Ssam
537190579Ssam		ni = (struct ieee80211_node *) m->m_pkthdr.rcvif;
538190579Ssam		vap = ni->ni_vap;
539190579Ssam
540190579Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
541190579Ssam		    "%s: flush frame, age %u", __func__, M_AGE_GET(m));
542190579Ssam		vap->iv_stats.is_ff_flush++;
543190579Ssam
544190579Ssam		ff_transmit(ni, m);
545190579Ssam	}
546190579Ssam}
547190579Ssam
548190579Ssam/*
549190579Ssam * Age frames on the staging queue.
550190579Ssam */
551190579Ssamvoid
552191753Ssamieee80211_ff_age(struct ieee80211com *ic, struct ieee80211_stageq *sq,
553191753Ssam    int quanta)
554190579Ssam{
555191753Ssam	struct ieee80211_superg *sg = ic->ic_superg;
556190579Ssam	struct mbuf *m, *head;
557190579Ssam	struct ieee80211_node *ni;
558190579Ssam	struct ieee80211_tx_ampdu *tap;
559190579Ssam
560190579Ssam	KASSERT(sq->head != NULL, ("stageq empty"));
561190579Ssam
562190579Ssam	IEEE80211_LOCK(ic);
563190579Ssam	head = sq->head;
564190579Ssam	while ((m = sq->head) != NULL && M_AGE_GET(m) < quanta) {
565234324Sadrian		int tid = WME_AC_TO_TID(M_WME_GETAC(m));
566234324Sadrian
567190579Ssam		/* clear tap ref to frame */
568190579Ssam		ni = (struct ieee80211_node *) m->m_pkthdr.rcvif;
569234324Sadrian		tap = &ni->ni_tx_ampdu[tid];
570190579Ssam		KASSERT(tap->txa_private == m, ("staging queue empty"));
571190579Ssam		tap->txa_private = NULL;
572190579Ssam
573190579Ssam		sq->head = m->m_nextpkt;
574190579Ssam		sq->depth--;
575191753Ssam		sg->ff_stageqdepth--;
576190579Ssam	}
577190579Ssam	if (m == NULL)
578190579Ssam		sq->tail = NULL;
579190579Ssam	else
580190579Ssam		M_AGE_SUB(m, quanta);
581190579Ssam	IEEE80211_UNLOCK(ic);
582190579Ssam
583190579Ssam	ff_flush(head, m);
584190579Ssam}
585190579Ssam
586190579Ssamstatic void
587190579Ssamstageq_add(struct ieee80211_stageq *sq, struct mbuf *m)
588190579Ssam{
589190579Ssam	int age = ieee80211_ffagemax;
590190579Ssam	if (sq->tail != NULL) {
591190579Ssam		sq->tail->m_nextpkt = m;
592190579Ssam		age -= M_AGE_GET(sq->head);
593190579Ssam	} else
594190579Ssam		sq->head = m;
595190579Ssam	KASSERT(age >= 0, ("age %d", age));
596190579Ssam	M_AGE_SET(m, age);
597190579Ssam	m->m_nextpkt = NULL;
598190579Ssam	sq->tail = m;
599190579Ssam	sq->depth++;
600190579Ssam}
601190579Ssam
602190579Ssamstatic void
603190579Ssamstageq_remove(struct ieee80211_stageq *sq, struct mbuf *mstaged)
604190579Ssam{
605190579Ssam	struct mbuf *m, *mprev;
606190579Ssam
607190579Ssam	mprev = NULL;
608190579Ssam	for (m = sq->head; m != NULL; m = m->m_nextpkt) {
609190579Ssam		if (m == mstaged) {
610190579Ssam			if (mprev == NULL)
611190579Ssam				sq->head = m->m_nextpkt;
612190579Ssam			else
613190579Ssam				mprev->m_nextpkt = m->m_nextpkt;
614190579Ssam			if (sq->tail == m)
615190579Ssam				sq->tail = mprev;
616190579Ssam			sq->depth--;
617190579Ssam			return;
618190579Ssam		}
619190579Ssam		mprev = m;
620190579Ssam	}
621190579Ssam	printf("%s: packet not found\n", __func__);
622190579Ssam}
623190579Ssam
624190579Ssamstatic uint32_t
625190579Ssamff_approx_txtime(struct ieee80211_node *ni,
626190579Ssam	const struct mbuf *m1, const struct mbuf *m2)
627190579Ssam{
628190579Ssam	struct ieee80211com *ic = ni->ni_ic;
629190579Ssam	struct ieee80211vap *vap = ni->ni_vap;
630190579Ssam	uint32_t framelen;
631190579Ssam
632190579Ssam	/*
633190579Ssam	 * Approximate the frame length to be transmitted. A swag to add
634190579Ssam	 * the following maximal values to the skb payload:
635190579Ssam	 *   - 32: 802.11 encap + CRC
636190579Ssam	 *   - 24: encryption overhead (if wep bit)
637190579Ssam	 *   - 4 + 6: fast-frame header and padding
638190579Ssam	 *   - 16: 2 LLC FF tunnel headers
639190579Ssam	 *   - 14: 1 802.3 FF tunnel header (mbuf already accounts for 2nd)
640190579Ssam	 */
641190579Ssam	framelen = m1->m_pkthdr.len + 32 +
642190579Ssam	    ATH_FF_MAX_HDR_PAD + ATH_FF_MAX_SEP_PAD + ATH_FF_MAX_HDR;
643190579Ssam	if (vap->iv_flags & IEEE80211_F_PRIVACY)
644190579Ssam		framelen += 24;
645190579Ssam	if (m2 != NULL)
646190579Ssam		framelen += m2->m_pkthdr.len;
647190579Ssam	return ieee80211_compute_duration(ic->ic_rt, framelen, ni->ni_txrate, 0);
648190579Ssam}
649190579Ssam
650190579Ssam/*
651190579Ssam * Check if the supplied frame can be partnered with an existing
652190579Ssam * or pending frame.  Return a reference to any frame that should be
653190579Ssam * sent on return; otherwise return NULL.
654190579Ssam */
655190579Ssamstruct mbuf *
656190579Ssamieee80211_ff_check(struct ieee80211_node *ni, struct mbuf *m)
657190579Ssam{
658190579Ssam	struct ieee80211vap *vap = ni->ni_vap;
659190579Ssam	struct ieee80211com *ic = ni->ni_ic;
660191753Ssam	struct ieee80211_superg *sg = ic->ic_superg;
661190579Ssam	const int pri = M_WME_GETAC(m);
662190579Ssam	struct ieee80211_stageq *sq;
663190579Ssam	struct ieee80211_tx_ampdu *tap;
664190579Ssam	struct mbuf *mstaged;
665190579Ssam	uint32_t txtime, limit;
666190579Ssam
667190579Ssam	/*
668190579Ssam	 * Check if the supplied frame can be aggregated.
669190579Ssam	 *
670190579Ssam	 * NB: we allow EAPOL frames to be aggregated with other ucast traffic.
671190579Ssam	 *     Do 802.1x EAPOL frames proceed in the clear? Then they couldn't
672190579Ssam	 *     be aggregated with other types of frames when encryption is on?
673190579Ssam	 */
674190579Ssam	IEEE80211_LOCK(ic);
675234324Sadrian	tap = &ni->ni_tx_ampdu[WME_AC_TO_TID(pri)];
676190579Ssam	mstaged = tap->txa_private;		/* NB: we reuse AMPDU state */
677190579Ssam	ieee80211_txampdu_count_packet(tap);
678190579Ssam
679190579Ssam	/*
680190579Ssam	 * When not in station mode never aggregate a multicast
681190579Ssam	 * frame; this insures, for example, that a combined frame
682190579Ssam	 * does not require multiple encryption keys.
683190579Ssam	 */
684190579Ssam	if (vap->iv_opmode != IEEE80211_M_STA &&
685190579Ssam	    ETHER_IS_MULTICAST(mtod(m, struct ether_header *)->ether_dhost)) {
686190579Ssam		/* XXX flush staged frame? */
687190579Ssam		IEEE80211_UNLOCK(ic);
688190579Ssam		return m;
689190579Ssam	}
690190579Ssam	/*
691190579Ssam	 * If there is no frame to combine with and the pps is
692190579Ssam	 * too low; then do not attempt to aggregate this frame.
693190579Ssam	 */
694190579Ssam	if (mstaged == NULL &&
695190579Ssam	    ieee80211_txampdu_getpps(tap) < ieee80211_ffppsmin) {
696190579Ssam		IEEE80211_UNLOCK(ic);
697190579Ssam		return m;
698190579Ssam	}
699191753Ssam	sq = &sg->ff_stageq[pri];
700190579Ssam	/*
701190579Ssam	 * Check the txop limit to insure the aggregate fits.
702190579Ssam	 */
703190579Ssam	limit = IEEE80211_TXOP_TO_US(
704190579Ssam		ic->ic_wme.wme_chanParams.cap_wmeParams[pri].wmep_txopLimit);
705190579Ssam	if (limit != 0 &&
706190579Ssam	    (txtime = ff_approx_txtime(ni, m, mstaged)) > limit) {
707190579Ssam		/*
708190579Ssam		 * Aggregate too long, return to the caller for direct
709190579Ssam		 * transmission.  In addition, flush any pending frame
710190579Ssam		 * before sending this one.
711190579Ssam		 */
712190579Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
713190579Ssam		    "%s: txtime %u exceeds txop limit %u\n",
714190579Ssam		    __func__, txtime, limit);
715190579Ssam
716190579Ssam		tap->txa_private = NULL;
717190579Ssam		if (mstaged != NULL)
718190579Ssam			stageq_remove(sq, mstaged);
719190579Ssam		IEEE80211_UNLOCK(ic);
720190579Ssam
721190579Ssam		if (mstaged != NULL) {
722190579Ssam			IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
723190579Ssam			    "%s: flush staged frame", __func__);
724190579Ssam			/* encap and xmit */
725190579Ssam			ff_transmit(ni, mstaged);
726190579Ssam		}
727190579Ssam		return m;		/* NB: original frame */
728190579Ssam	}
729190579Ssam	/*
730190579Ssam	 * An aggregation candidate.  If there's a frame to partner
731190579Ssam	 * with then combine and return for processing.  Otherwise
732190579Ssam	 * save this frame and wait for a partner to show up (or
733190579Ssam	 * the frame to be flushed).  Note that staged frames also
734190579Ssam	 * hold their node reference.
735190579Ssam	 */
736190579Ssam	if (mstaged != NULL) {
737190579Ssam		tap->txa_private = NULL;
738190579Ssam		stageq_remove(sq, mstaged);
739190579Ssam		IEEE80211_UNLOCK(ic);
740190579Ssam
741190579Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
742190579Ssam		    "%s: aggregate fast-frame", __func__);
743190579Ssam		/*
744190579Ssam		 * Release the node reference; we only need
745190579Ssam		 * the one already in mstaged.
746190579Ssam		 */
747190579Ssam		KASSERT(mstaged->m_pkthdr.rcvif == (void *)ni,
748190579Ssam		    ("rcvif %p ni %p", mstaged->m_pkthdr.rcvif, ni));
749190579Ssam		ieee80211_free_node(ni);
750190579Ssam
751190579Ssam		m->m_nextpkt = NULL;
752190579Ssam		mstaged->m_nextpkt = m;
753190579Ssam		mstaged->m_flags |= M_FF; /* NB: mark for encap work */
754190579Ssam	} else {
755190579Ssam		KASSERT(tap->txa_private == NULL,
756190579Ssam		    ("txa_private %p", tap->txa_private));
757190579Ssam		tap->txa_private = m;
758190579Ssam
759190579Ssam		stageq_add(sq, m);
760191753Ssam		sg->ff_stageqdepth++;
761190579Ssam		IEEE80211_UNLOCK(ic);
762190579Ssam
763190579Ssam		IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni,
764190579Ssam		    "%s: stage frame, %u queued", __func__, sq->depth);
765190579Ssam		/* NB: mstaged is NULL */
766190579Ssam	}
767190579Ssam	return mstaged;
768190579Ssam}
769190579Ssam
770190579Ssamvoid
771190579Ssamieee80211_ff_node_init(struct ieee80211_node *ni)
772190579Ssam{
773190579Ssam	/*
774190579Ssam	 * Clean FF state on re-associate.  This handles the case
775190579Ssam	 * where a station leaves w/o notifying us and then returns
776190579Ssam	 * before node is reaped for inactivity.
777190579Ssam	 */
778190579Ssam	ieee80211_ff_node_cleanup(ni);
779190579Ssam}
780190579Ssam
781190579Ssamvoid
782190579Ssamieee80211_ff_node_cleanup(struct ieee80211_node *ni)
783190579Ssam{
784190579Ssam	struct ieee80211com *ic = ni->ni_ic;
785191753Ssam	struct ieee80211_superg *sg = ic->ic_superg;
786190579Ssam	struct ieee80211_tx_ampdu *tap;
787244025Sadrian	struct mbuf *m, *next_m, *head;
788234324Sadrian	int tid;
789190579Ssam
790190579Ssam	IEEE80211_LOCK(ic);
791190579Ssam	head = NULL;
792234324Sadrian	for (tid = 0; tid < WME_NUM_TID; tid++) {
793234324Sadrian		int ac = TID_TO_WME_AC(tid);
794234324Sadrian
795234324Sadrian		tap = &ni->ni_tx_ampdu[tid];
796190579Ssam		m = tap->txa_private;
797190579Ssam		if (m != NULL) {
798190579Ssam			tap->txa_private = NULL;
799191753Ssam			stageq_remove(&sg->ff_stageq[ac], m);
800190579Ssam			m->m_nextpkt = head;
801190579Ssam			head = m;
802190579Ssam		}
803190579Ssam	}
804190579Ssam	IEEE80211_UNLOCK(ic);
805190579Ssam
806244025Sadrian	/*
807244025Sadrian	 * Free mbufs, taking care to not dereference the mbuf after
808244025Sadrian	 * we free it (hence grabbing m_nextpkt before we free it.)
809244025Sadrian	 */
810244025Sadrian	m = head;
811244025Sadrian	while (m != NULL) {
812244025Sadrian		next_m = m->m_nextpkt;
813190579Ssam		m_freem(m);
814190579Ssam		ieee80211_free_node(ni);
815244025Sadrian		m = next_m;
816190579Ssam	}
817190579Ssam}
818190579Ssam
819190579Ssam/*
820190391Ssam * Switch between turbo and non-turbo operating modes.
821190391Ssam * Use the specified channel flags to locate the new
822190391Ssam * channel, update 802.11 state, and then call back into
823190391Ssam * the driver to effect the change.
824190391Ssam */
825190391Ssamvoid
826190391Ssamieee80211_dturbo_switch(struct ieee80211vap *vap, int newflags)
827190391Ssam{
828190391Ssam	struct ieee80211com *ic = vap->iv_ic;
829190391Ssam	struct ieee80211_channel *chan;
830190391Ssam
831190391Ssam	chan = ieee80211_find_channel(ic, ic->ic_bsschan->ic_freq, newflags);
832190391Ssam	if (chan == NULL) {		/* XXX should not happen */
833190391Ssam		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
834190391Ssam		    "%s: no channel with freq %u flags 0x%x\n",
835190391Ssam		    __func__, ic->ic_bsschan->ic_freq, newflags);
836190391Ssam		return;
837190391Ssam	}
838190391Ssam
839190391Ssam	IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG,
840190391Ssam	    "%s: %s -> %s (freq %u flags 0x%x)\n", __func__,
841190391Ssam	    ieee80211_phymode_name[ieee80211_chan2mode(ic->ic_bsschan)],
842190391Ssam	    ieee80211_phymode_name[ieee80211_chan2mode(chan)],
843190391Ssam	    chan->ic_freq, chan->ic_flags);
844190391Ssam
845190391Ssam	ic->ic_bsschan = chan;
846190391Ssam	ic->ic_prevchan = ic->ic_curchan;
847190391Ssam	ic->ic_curchan = chan;
848190532Ssam	ic->ic_rt = ieee80211_get_ratetable(chan);
849190391Ssam	ic->ic_set_channel(ic);
850192468Ssam	ieee80211_radiotap_chan_change(ic);
851190391Ssam	/* NB: do not need to reset ERP state 'cuz we're in sta mode */
852190391Ssam}
853190391Ssam
854190391Ssam/*
855190391Ssam * Return the current ``state'' of an Atheros capbility.
856190391Ssam * If associated in station mode report the negotiated
857190391Ssam * setting. Otherwise report the current setting.
858190391Ssam */
859190391Ssamstatic int
860190391Ssamgetathcap(struct ieee80211vap *vap, int cap)
861190391Ssam{
862190391Ssam	if (vap->iv_opmode == IEEE80211_M_STA &&
863190391Ssam	    vap->iv_state == IEEE80211_S_RUN)
864190391Ssam		return IEEE80211_ATH_CAP(vap, vap->iv_bss, cap) != 0;
865190391Ssam	else
866190391Ssam		return (vap->iv_flags & cap) != 0;
867190391Ssam}
868190391Ssam
869190391Ssamstatic int
870190391Ssamsuperg_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
871190391Ssam{
872190391Ssam	switch (ireq->i_type) {
873190391Ssam	case IEEE80211_IOC_FF:
874190391Ssam		ireq->i_val = getathcap(vap, IEEE80211_F_FF);
875190391Ssam		break;
876190391Ssam	case IEEE80211_IOC_TURBOP:
877190391Ssam		ireq->i_val = getathcap(vap, IEEE80211_F_TURBOP);
878190391Ssam		break;
879190391Ssam	default:
880190391Ssam		return ENOSYS;
881190391Ssam	}
882190391Ssam	return 0;
883190391Ssam}
884190391SsamIEEE80211_IOCTL_GET(superg, superg_ioctl_get80211);
885190391Ssam
886190391Ssamstatic int
887190391Ssamsuperg_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
888190391Ssam{
889190391Ssam	switch (ireq->i_type) {
890190391Ssam	case IEEE80211_IOC_FF:
891190391Ssam		if (ireq->i_val) {
892190391Ssam			if ((vap->iv_caps & IEEE80211_C_FF) == 0)
893190391Ssam				return EOPNOTSUPP;
894190391Ssam			vap->iv_flags |= IEEE80211_F_FF;
895190391Ssam		} else
896190391Ssam			vap->iv_flags &= ~IEEE80211_F_FF;
897190530Ssam		return ENETRESET;
898190391Ssam	case IEEE80211_IOC_TURBOP:
899190391Ssam		if (ireq->i_val) {
900190391Ssam			if ((vap->iv_caps & IEEE80211_C_TURBOP) == 0)
901190391Ssam				return EOPNOTSUPP;
902190391Ssam			vap->iv_flags |= IEEE80211_F_TURBOP;
903190391Ssam		} else
904190391Ssam			vap->iv_flags &= ~IEEE80211_F_TURBOP;
905190391Ssam		return ENETRESET;
906190391Ssam	default:
907190391Ssam		return ENOSYS;
908190391Ssam	}
909190391Ssam	return 0;
910190391Ssam}
911190391SsamIEEE80211_IOCTL_SET(superg, superg_ioctl_set80211);
912