xref: /dflybsd-src/sys/netproto/802_11/ieee80211_proto.h (revision 294727bf61ff113c99d212fd917091e69cb15a8c)
132176cfdSRui Paulo /*-
2f186073cSJoerg Sonnenberger  * Copyright (c) 2001 Atsushi Onoe
332176cfdSRui Paulo  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
4f186073cSJoerg Sonnenberger  * All rights reserved.
5f186073cSJoerg Sonnenberger  *
6f186073cSJoerg Sonnenberger  * Redistribution and use in source and binary forms, with or without
7f186073cSJoerg Sonnenberger  * modification, are permitted provided that the following conditions
8f186073cSJoerg Sonnenberger  * are met:
9f186073cSJoerg Sonnenberger  * 1. Redistributions of source code must retain the above copyright
10f186073cSJoerg Sonnenberger  *    notice, this list of conditions and the following disclaimer.
11f186073cSJoerg Sonnenberger  * 2. Redistributions in binary form must reproduce the above copyright
12f186073cSJoerg Sonnenberger  *    notice, this list of conditions and the following disclaimer in the
13f186073cSJoerg Sonnenberger  *    documentation and/or other materials provided with the distribution.
14f186073cSJoerg Sonnenberger  *
15f186073cSJoerg Sonnenberger  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16f186073cSJoerg Sonnenberger  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17f186073cSJoerg Sonnenberger  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18f186073cSJoerg Sonnenberger  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19f186073cSJoerg Sonnenberger  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20f186073cSJoerg Sonnenberger  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21f186073cSJoerg Sonnenberger  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22f186073cSJoerg Sonnenberger  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23f186073cSJoerg Sonnenberger  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24f186073cSJoerg Sonnenberger  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25f186073cSJoerg Sonnenberger  *
26085ff963SMatthew Dillon  * $FreeBSD$
27f186073cSJoerg Sonnenberger  */
28841ab66cSSepherosa Ziehau #ifndef _NET80211_IEEE80211_PROTO_H_
29841ab66cSSepherosa Ziehau #define _NET80211_IEEE80211_PROTO_H_
30f186073cSJoerg Sonnenberger 
31f186073cSJoerg Sonnenberger /*
32f186073cSJoerg Sonnenberger  * 802.11 protocol implementation definitions.
33f186073cSJoerg Sonnenberger  */
34f186073cSJoerg Sonnenberger 
35f186073cSJoerg Sonnenberger enum ieee80211_state {
36f186073cSJoerg Sonnenberger 	IEEE80211_S_INIT	= 0,	/* default state */
37f186073cSJoerg Sonnenberger 	IEEE80211_S_SCAN	= 1,	/* scanning */
38f186073cSJoerg Sonnenberger 	IEEE80211_S_AUTH	= 2,	/* try to authenticate */
39f186073cSJoerg Sonnenberger 	IEEE80211_S_ASSOC	= 3,	/* try to assoc */
4032176cfdSRui Paulo 	IEEE80211_S_CAC		= 4,	/* doing channel availability check */
4132176cfdSRui Paulo 	IEEE80211_S_RUN		= 5,	/* operational (e.g. associated) */
4232176cfdSRui Paulo 	IEEE80211_S_CSA		= 6,	/* channel switch announce pending */
4332176cfdSRui Paulo 	IEEE80211_S_SLEEP	= 7,	/* power save */
44f186073cSJoerg Sonnenberger };
4532176cfdSRui Paulo #define	IEEE80211_S_MAX		(IEEE80211_S_SLEEP+1)
46f186073cSJoerg Sonnenberger 
4732176cfdSRui Paulo #define	IEEE80211_SEND_MGMT(_ni,_type,_arg) \
4832176cfdSRui Paulo 	((*(_ni)->ni_ic->ic_send_mgmt)(_ni, _type, _arg))
49f186073cSJoerg Sonnenberger 
50f186073cSJoerg Sonnenberger extern	const char *ieee80211_mgt_subtype_name[];
5132176cfdSRui Paulo extern	const char *ieee80211_phymode_name[IEEE80211_MODE_MAX];
5232176cfdSRui Paulo extern	const int ieee80211_opcap[IEEE80211_OPMODE_MAX];
53f186073cSJoerg Sonnenberger 
54841ab66cSSepherosa Ziehau void	ieee80211_proto_attach(struct ieee80211com *);
55841ab66cSSepherosa Ziehau void	ieee80211_proto_detach(struct ieee80211com *);
5632176cfdSRui Paulo void	ieee80211_proto_vattach(struct ieee80211vap *);
5732176cfdSRui Paulo void	ieee80211_proto_vdetach(struct ieee80211vap *);
58f186073cSJoerg Sonnenberger 
5932176cfdSRui Paulo void	ieee80211_syncifflag_locked(struct ieee80211com *, int flag);
6032176cfdSRui Paulo void	ieee80211_syncflag(struct ieee80211vap *, int flag);
6132176cfdSRui Paulo void	ieee80211_syncflag_ht(struct ieee80211vap *, int flag);
6232176cfdSRui Paulo void	ieee80211_syncflag_ext(struct ieee80211vap *, int flag);
6332176cfdSRui Paulo 
64085ff963SMatthew Dillon #define	IEEE80211_R_NF		0x0000001	/* global NF value valid */
65085ff963SMatthew Dillon #define	IEEE80211_R_RSSI	0x0000002	/* global RSSI value valid */
66085ff963SMatthew Dillon #define	IEEE80211_R_C_CHAIN	0x0000004	/* RX chain count valid */
67085ff963SMatthew Dillon #define	IEEE80211_R_C_NF	0x0000008	/* per-chain NF value valid */
68085ff963SMatthew Dillon #define	IEEE80211_R_C_RSSI	0x0000010	/* per-chain RSSI value valid */
69085ff963SMatthew Dillon #define	IEEE80211_R_C_EVM	0x0000020	/* per-chain EVM valid */
70085ff963SMatthew Dillon #define	IEEE80211_R_C_HT40	0x0000040	/* RX'ed packet is 40mhz, pilots 4,5 valid */
71085ff963SMatthew Dillon 
72085ff963SMatthew Dillon struct ieee80211_rx_stats {
73085ff963SMatthew Dillon 	uint32_t r_flags;		/* IEEE80211_R_* flags */
74085ff963SMatthew Dillon 	uint8_t c_chain;		/* number of RX chains involved */
75085ff963SMatthew Dillon 	int16_t	c_nf_ctl[IEEE80211_MAX_CHAINS];	/* per-chain NF */
76085ff963SMatthew Dillon 	int16_t	c_nf_ext[IEEE80211_MAX_CHAINS];	/* per-chain NF */
77085ff963SMatthew Dillon 	int16_t	c_rssi_ctl[IEEE80211_MAX_CHAINS];	/* per-chain RSSI */
78085ff963SMatthew Dillon 	int16_t	c_rssi_ext[IEEE80211_MAX_CHAINS];	/* per-chain RSSI */
79085ff963SMatthew Dillon 	uint8_t nf;			/* global NF */
80085ff963SMatthew Dillon 	uint8_t rssi;			/* global RSSI */
81085ff963SMatthew Dillon 	uint8_t evm[IEEE80211_MAX_CHAINS][IEEE80211_MAX_EVM_PILOTS];
82085ff963SMatthew Dillon 					/* per-chain, per-pilot EVM values */
83085ff963SMatthew Dillon };
84085ff963SMatthew Dillon 
85085ff963SMatthew Dillon #if defined(__DragonFly__)
86085ff963SMatthew Dillon struct route;
87085ff963SMatthew Dillon #endif
88085ff963SMatthew Dillon 
8932176cfdSRui Paulo #define	ieee80211_input(ni, m, rssi, nf) \
9032176cfdSRui Paulo 	((ni)->ni_vap->iv_input(ni, m, rssi, nf))
9132176cfdSRui Paulo int	ieee80211_input_all(struct ieee80211com *, struct mbuf *, int, int);
92085ff963SMatthew Dillon 
93085ff963SMatthew Dillon int	ieee80211_input_mimo(struct ieee80211_node *, struct mbuf *,
94085ff963SMatthew Dillon 	    struct ieee80211_rx_stats *);
95085ff963SMatthew Dillon int	ieee80211_input_mimo_all(struct ieee80211com *, struct mbuf *,
96085ff963SMatthew Dillon 	    struct ieee80211_rx_stats *);
97085ff963SMatthew Dillon 
9832176cfdSRui Paulo struct ieee80211_bpf_params;
9932176cfdSRui Paulo int	ieee80211_mgmt_output(struct ieee80211_node *, struct mbuf *, int,
10032176cfdSRui Paulo 		struct ieee80211_bpf_params *);
10132176cfdSRui Paulo int	ieee80211_raw_xmit(struct ieee80211_node *, struct mbuf *,
10232176cfdSRui Paulo 		const struct ieee80211_bpf_params *);
103085ff963SMatthew Dillon #if defined(__DragonFly__)
10432176cfdSRui Paulo int	ieee80211_output(struct ifnet *, struct mbuf *,
10534a60cf6SRui Paulo                struct sockaddr *, struct rtentry *rt);
106085ff963SMatthew Dillon #else
107085ff963SMatthew Dillon int	ieee80211_output(struct ifnet *, struct mbuf *,
108*294727bfSImre Vadász                const struct sockaddr *, struct route *ro);
109085ff963SMatthew Dillon #endif
110085ff963SMatthew Dillon int	ieee80211_vap_pkt_send_dest(struct ieee80211vap *, struct mbuf *,
111085ff963SMatthew Dillon 		struct ieee80211_node *);
112085ff963SMatthew Dillon int	ieee80211_raw_output(struct ieee80211vap *, struct ieee80211_node *,
113085ff963SMatthew Dillon 		struct mbuf *, const struct ieee80211_bpf_params *);
11432176cfdSRui Paulo void	ieee80211_send_setup(struct ieee80211_node *, struct mbuf *, int, int,
11532176cfdSRui Paulo         const uint8_t [IEEE80211_ADDR_LEN], const uint8_t [IEEE80211_ADDR_LEN],
11632176cfdSRui Paulo         const uint8_t [IEEE80211_ADDR_LEN]);
117085ff963SMatthew Dillon void	ieee80211_vap_start(struct ifnet *ifp, struct ifaltq_subque *ifsq);
118085ff963SMatthew Dillon int	ieee80211_vap_transmit(struct ifnet *ifp, struct mbuf *m);
119085ff963SMatthew Dillon void	ieee80211_vap_qflush(struct ifnet *ifp);
120841ab66cSSepherosa Ziehau int	ieee80211_send_nulldata(struct ieee80211_node *);
12132176cfdSRui Paulo int	ieee80211_classify(struct ieee80211_node *, struct mbuf *m);
12232176cfdSRui Paulo struct mbuf *ieee80211_mbuf_adjust(struct ieee80211vap *, int,
12332176cfdSRui Paulo 		struct ieee80211_key *, struct mbuf *);
12432176cfdSRui Paulo struct mbuf *ieee80211_encap(struct ieee80211vap *, struct ieee80211_node *,
12532176cfdSRui Paulo 		struct mbuf *);
12632176cfdSRui Paulo int	ieee80211_send_mgmt(struct ieee80211_node *, int, int);
12732176cfdSRui Paulo struct ieee80211_appie;
128841ab66cSSepherosa Ziehau int	ieee80211_send_probereq(struct ieee80211_node *ni,
129841ab66cSSepherosa Ziehau 		const uint8_t sa[IEEE80211_ADDR_LEN],
130841ab66cSSepherosa Ziehau 		const uint8_t da[IEEE80211_ADDR_LEN],
131841ab66cSSepherosa Ziehau 		const uint8_t bssid[IEEE80211_ADDR_LEN],
13232176cfdSRui Paulo 		const uint8_t *ssid, size_t ssidlen);
133085ff963SMatthew Dillon struct mbuf *	ieee80211_ff_encap1(struct ieee80211vap *, struct mbuf *,
134085ff963SMatthew Dillon 		const struct ether_header *);
1357115973eSMatthew Dillon void	ieee80211_tx_complete(struct ieee80211_node *,
1367115973eSMatthew Dillon 		struct mbuf *, int);
1377115973eSMatthew Dillon 
13832176cfdSRui Paulo /*
13932176cfdSRui Paulo  * The formation of ProbeResponse frames requires guidance to
14032176cfdSRui Paulo  * deal with legacy clients.  When the client is identified as
14132176cfdSRui Paulo  * "legacy 11b" ieee80211_send_proberesp is passed this token.
14232176cfdSRui Paulo  */
14332176cfdSRui Paulo #define	IEEE80211_SEND_LEGACY_11B	0x1	/* legacy 11b client */
14432176cfdSRui Paulo #define	IEEE80211_SEND_LEGACY_11	0x2	/* other legacy client */
14532176cfdSRui Paulo #define	IEEE80211_SEND_LEGACY		0x3	/* any legacy client */
14632176cfdSRui Paulo struct mbuf *ieee80211_alloc_proberesp(struct ieee80211_node *, int);
14732176cfdSRui Paulo int	ieee80211_send_proberesp(struct ieee80211vap *,
14832176cfdSRui Paulo 		const uint8_t da[IEEE80211_ADDR_LEN], int);
14932176cfdSRui Paulo struct mbuf *ieee80211_alloc_rts(struct ieee80211com *ic,
15032176cfdSRui Paulo 		const uint8_t [IEEE80211_ADDR_LEN],
15132176cfdSRui Paulo 		const uint8_t [IEEE80211_ADDR_LEN], uint16_t);
15232176cfdSRui Paulo struct mbuf *ieee80211_alloc_cts(struct ieee80211com *,
15332176cfdSRui Paulo 		const uint8_t [IEEE80211_ADDR_LEN], uint16_t);
15432176cfdSRui Paulo 
15532176cfdSRui Paulo uint8_t *ieee80211_add_rates(uint8_t *, const struct ieee80211_rateset *);
15632176cfdSRui Paulo uint8_t *ieee80211_add_xrates(uint8_t *, const struct ieee80211_rateset *);
157e218318cSMatthew Dillon uint8_t *ieee80211_add_ssid(uint8_t *frm, const uint8_t *ssid, u_int len);
158085ff963SMatthew Dillon uint8_t *ieee80211_add_wpa(uint8_t *, const struct ieee80211vap *);
159085ff963SMatthew Dillon uint8_t *ieee80211_add_rsn(uint8_t *, const struct ieee80211vap *);
160085ff963SMatthew Dillon uint8_t *ieee80211_add_qos(uint8_t *, const struct ieee80211_node *);
16132176cfdSRui Paulo uint16_t ieee80211_getcapinfo(struct ieee80211vap *,
16232176cfdSRui Paulo 		struct ieee80211_channel *);
163841ab66cSSepherosa Ziehau 
164841ab66cSSepherosa Ziehau void	ieee80211_reset_erp(struct ieee80211com *);
16532176cfdSRui Paulo void	ieee80211_set_shortslottime(struct ieee80211com *, int onoff);
16632176cfdSRui Paulo int	ieee80211_iserp_rateset(const struct ieee80211_rateset *);
16732176cfdSRui Paulo void	ieee80211_setbasicrates(struct ieee80211_rateset *,
16832176cfdSRui Paulo 		enum ieee80211_phymode);
16932176cfdSRui Paulo void	ieee80211_addbasicrates(struct ieee80211_rateset *,
17032176cfdSRui Paulo 		enum ieee80211_phymode);
171841ab66cSSepherosa Ziehau 
172841ab66cSSepherosa Ziehau /*
173841ab66cSSepherosa Ziehau  * Return the size of the 802.11 header for a management or data frame.
174841ab66cSSepherosa Ziehau  */
175841ab66cSSepherosa Ziehau static __inline int
176841ab66cSSepherosa Ziehau ieee80211_hdrsize(const void *data)
177841ab66cSSepherosa Ziehau {
178841ab66cSSepherosa Ziehau 	const struct ieee80211_frame *wh = data;
179841ab66cSSepherosa Ziehau 	int size = sizeof(struct ieee80211_frame);
180841ab66cSSepherosa Ziehau 
181841ab66cSSepherosa Ziehau 	/* NB: we don't handle control frames */
182841ab66cSSepherosa Ziehau 	KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL,
183841ab66cSSepherosa Ziehau 		("%s: control frame", __func__));
18432176cfdSRui Paulo 	if (IEEE80211_IS_DSTODS(wh))
185841ab66cSSepherosa Ziehau 		size += IEEE80211_ADDR_LEN;
186841ab66cSSepherosa Ziehau 	if (IEEE80211_QOS_HAS_SEQ(wh))
187841ab66cSSepherosa Ziehau 		size += sizeof(uint16_t);
188841ab66cSSepherosa Ziehau 	return size;
189841ab66cSSepherosa Ziehau }
190841ab66cSSepherosa Ziehau 
191841ab66cSSepherosa Ziehau /*
19232176cfdSRui Paulo  * Like ieee80211_hdrsize, but handles any type of frame.
193841ab66cSSepherosa Ziehau  */
194841ab66cSSepherosa Ziehau static __inline int
195841ab66cSSepherosa Ziehau ieee80211_anyhdrsize(const void *data)
196841ab66cSSepherosa Ziehau {
197841ab66cSSepherosa Ziehau 	const struct ieee80211_frame *wh = data;
198841ab66cSSepherosa Ziehau 
199841ab66cSSepherosa Ziehau 	if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) {
200841ab66cSSepherosa Ziehau 		switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
201841ab66cSSepherosa Ziehau 		case IEEE80211_FC0_SUBTYPE_CTS:
202841ab66cSSepherosa Ziehau 		case IEEE80211_FC0_SUBTYPE_ACK:
203841ab66cSSepherosa Ziehau 			return sizeof(struct ieee80211_frame_ack);
20432176cfdSRui Paulo 		case IEEE80211_FC0_SUBTYPE_BAR:
20532176cfdSRui Paulo 			return sizeof(struct ieee80211_frame_bar);
206841ab66cSSepherosa Ziehau 		}
207841ab66cSSepherosa Ziehau 		return sizeof(struct ieee80211_frame_min);
208841ab66cSSepherosa Ziehau 	} else
209841ab66cSSepherosa Ziehau 		return ieee80211_hdrsize(data);
210841ab66cSSepherosa Ziehau }
211841ab66cSSepherosa Ziehau 
212841ab66cSSepherosa Ziehau /*
213841ab66cSSepherosa Ziehau  * Template for an in-kernel authenticator.  Authenticators
214841ab66cSSepherosa Ziehau  * register with the protocol code and are typically loaded
21532176cfdSRui Paulo  * as separate modules as needed.  One special authenticator
21632176cfdSRui Paulo  * is xauth; it intercepts requests so that protocols like
21732176cfdSRui Paulo  * WPA can be handled in user space.
218841ab66cSSepherosa Ziehau  */
219841ab66cSSepherosa Ziehau struct ieee80211_authenticator {
220841ab66cSSepherosa Ziehau 	const char *ia_name;		/* printable name */
22132176cfdSRui Paulo 	int	(*ia_attach)(struct ieee80211vap *);
22232176cfdSRui Paulo 	void	(*ia_detach)(struct ieee80211vap *);
22332176cfdSRui Paulo 	void	(*ia_node_join)(struct ieee80211_node *);
22432176cfdSRui Paulo 	void	(*ia_node_leave)(struct ieee80211_node *);
225841ab66cSSepherosa Ziehau };
226841ab66cSSepherosa Ziehau void	ieee80211_authenticator_register(int type,
227841ab66cSSepherosa Ziehau 		const struct ieee80211_authenticator *);
228841ab66cSSepherosa Ziehau void	ieee80211_authenticator_unregister(int type);
229841ab66cSSepherosa Ziehau const struct ieee80211_authenticator *ieee80211_authenticator_get(int auth);
230841ab66cSSepherosa Ziehau 
231841ab66cSSepherosa Ziehau struct ieee80211req;
232841ab66cSSepherosa Ziehau /*
233841ab66cSSepherosa Ziehau  * Template for an MAC ACL policy module.  Such modules
234841ab66cSSepherosa Ziehau  * register with the protocol code and are passed the sender's
23532176cfdSRui Paulo  * address of each received auth frame for validation.
236841ab66cSSepherosa Ziehau  */
237841ab66cSSepherosa Ziehau struct ieee80211_aclator {
238841ab66cSSepherosa Ziehau 	const char *iac_name;		/* printable name */
23932176cfdSRui Paulo 	int	(*iac_attach)(struct ieee80211vap *);
24032176cfdSRui Paulo 	void	(*iac_detach)(struct ieee80211vap *);
24132176cfdSRui Paulo 	int	(*iac_check)(struct ieee80211vap *,
242085ff963SMatthew Dillon 			const struct ieee80211_frame *wh);
24332176cfdSRui Paulo 	int	(*iac_add)(struct ieee80211vap *,
244841ab66cSSepherosa Ziehau 			const uint8_t mac[IEEE80211_ADDR_LEN]);
24532176cfdSRui Paulo 	int	(*iac_remove)(struct ieee80211vap *,
246841ab66cSSepherosa Ziehau 			const uint8_t mac[IEEE80211_ADDR_LEN]);
24732176cfdSRui Paulo 	int	(*iac_flush)(struct ieee80211vap *);
24832176cfdSRui Paulo 	int	(*iac_setpolicy)(struct ieee80211vap *, int);
24932176cfdSRui Paulo 	int	(*iac_getpolicy)(struct ieee80211vap *);
25032176cfdSRui Paulo 	int	(*iac_setioctl)(struct ieee80211vap *, struct ieee80211req *);
25132176cfdSRui Paulo 	int	(*iac_getioctl)(struct ieee80211vap *, struct ieee80211req *);
252841ab66cSSepherosa Ziehau };
253841ab66cSSepherosa Ziehau void	ieee80211_aclator_register(const struct ieee80211_aclator *);
254841ab66cSSepherosa Ziehau void	ieee80211_aclator_unregister(const struct ieee80211_aclator *);
255841ab66cSSepherosa Ziehau const struct ieee80211_aclator *ieee80211_aclator_get(const char *name);
256841ab66cSSepherosa Ziehau 
257841ab66cSSepherosa Ziehau /* flags for ieee80211_fix_rate() */
258841ab66cSSepherosa Ziehau #define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
25932176cfdSRui Paulo #define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed legacy rate */
260841ab66cSSepherosa Ziehau #define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
261841ab66cSSepherosa Ziehau #define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
26232176cfdSRui Paulo #define	IEEE80211_F_DOBRS	0x00000010	/* check basic rate set */
26332176cfdSRui Paulo #define	IEEE80211_F_JOIN	0x00000020	/* sta joining our bss */
26432176cfdSRui Paulo #define	IEEE80211_F_DOFMCS	0x00000040	/* use fixed HT rate */
26532176cfdSRui Paulo int	ieee80211_fix_rate(struct ieee80211_node *,
26632176cfdSRui Paulo 		struct ieee80211_rateset *, int);
267841ab66cSSepherosa Ziehau 
268841ab66cSSepherosa Ziehau /*
269841ab66cSSepherosa Ziehau  * WME/WMM support.
270841ab66cSSepherosa Ziehau  */
271841ab66cSSepherosa Ziehau struct wmeParams {
272841ab66cSSepherosa Ziehau 	uint8_t		wmep_acm;
273841ab66cSSepherosa Ziehau 	uint8_t		wmep_aifsn;
274841ab66cSSepherosa Ziehau 	uint8_t		wmep_logcwmin;		/* log2(cwmin) */
275841ab66cSSepherosa Ziehau 	uint8_t		wmep_logcwmax;		/* log2(cwmax) */
276841ab66cSSepherosa Ziehau 	uint8_t		wmep_txopLimit;
277841ab66cSSepherosa Ziehau 	uint8_t		wmep_noackPolicy;	/* 0 (ack), 1 (no ack) */
278841ab66cSSepherosa Ziehau };
279841ab66cSSepherosa Ziehau #define	IEEE80211_TXOP_TO_US(_txop)	((_txop)<<5)
280841ab66cSSepherosa Ziehau #define	IEEE80211_US_TO_TXOP(_us)	((_us)>>5)
281841ab66cSSepherosa Ziehau 
282841ab66cSSepherosa Ziehau struct chanAccParams {
283841ab66cSSepherosa Ziehau 	uint8_t		cap_info;		/* version of the current set */
284841ab66cSSepherosa Ziehau 	struct wmeParams cap_wmeParams[WME_NUM_AC];
285841ab66cSSepherosa Ziehau };
286841ab66cSSepherosa Ziehau 
287841ab66cSSepherosa Ziehau struct ieee80211_wme_state {
288841ab66cSSepherosa Ziehau 	u_int	wme_flags;
289841ab66cSSepherosa Ziehau #define	WME_F_AGGRMODE	0x00000001	/* STATUS: WME agressive mode */
290841ab66cSSepherosa Ziehau 	u_int	wme_hipri_traffic;	/* VI/VO frames in beacon interval */
291841ab66cSSepherosa Ziehau 	u_int	wme_hipri_switch_thresh;/* agressive mode switch thresh */
292841ab66cSSepherosa Ziehau 	u_int	wme_hipri_switch_hysteresis;/* agressive mode switch hysteresis */
293841ab66cSSepherosa Ziehau 
294841ab66cSSepherosa Ziehau 	struct wmeParams wme_params[4];		/* from assoc resp for each AC*/
295841ab66cSSepherosa Ziehau 	struct chanAccParams wme_wmeChanParams;	/* WME params applied to self */
296841ab66cSSepherosa Ziehau 	struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */
297841ab66cSSepherosa Ziehau 	struct chanAccParams wme_chanParams;	/* params applied to self */
298841ab66cSSepherosa Ziehau 	struct chanAccParams wme_bssChanParams;	/* params bcast to stations */
299841ab66cSSepherosa Ziehau 
300841ab66cSSepherosa Ziehau 	int	(*wme_update)(struct ieee80211com *);
301841ab66cSSepherosa Ziehau };
302841ab66cSSepherosa Ziehau 
30332176cfdSRui Paulo void	ieee80211_wme_initparams(struct ieee80211vap *);
30432176cfdSRui Paulo void	ieee80211_wme_updateparams(struct ieee80211vap *);
30532176cfdSRui Paulo void	ieee80211_wme_updateparams_locked(struct ieee80211vap *);
306841ab66cSSepherosa Ziehau 
30732176cfdSRui Paulo /*
30832176cfdSRui Paulo  * Return the WME TID from a QoS frame.  If no TID
30932176cfdSRui Paulo  * is present return the index for the "non-QoS" entry.
31032176cfdSRui Paulo  */
31132176cfdSRui Paulo static __inline uint8_t
31232176cfdSRui Paulo ieee80211_gettid(const struct ieee80211_frame *wh)
31332176cfdSRui Paulo {
31432176cfdSRui Paulo 	uint8_t tid;
31532176cfdSRui Paulo 
31632176cfdSRui Paulo 	if (IEEE80211_QOS_HAS_SEQ(wh)) {
31732176cfdSRui Paulo 		if (IEEE80211_IS_DSTODS(wh))
31832176cfdSRui Paulo 			tid = ((const struct ieee80211_qosframe_addr4 *)wh)->
31932176cfdSRui Paulo 				i_qos[0];
32032176cfdSRui Paulo 		else
32132176cfdSRui Paulo 			tid = ((const struct ieee80211_qosframe *)wh)->i_qos[0];
32232176cfdSRui Paulo 		tid &= IEEE80211_QOS_TID;
32332176cfdSRui Paulo 	} else
32432176cfdSRui Paulo 		tid = IEEE80211_NONQOS_TID;
32532176cfdSRui Paulo 	return tid;
32632176cfdSRui Paulo }
32732176cfdSRui Paulo 
32832176cfdSRui Paulo void	ieee80211_waitfor_parent(struct ieee80211com *);
32932176cfdSRui Paulo void	ieee80211_start_locked(struct ieee80211vap *);
33032176cfdSRui Paulo void	ieee80211_init(void *);
33132176cfdSRui Paulo void	ieee80211_start_all(struct ieee80211com *);
33232176cfdSRui Paulo void	ieee80211_stop_locked(struct ieee80211vap *);
33332176cfdSRui Paulo void	ieee80211_stop(struct ieee80211vap *);
33432176cfdSRui Paulo void	ieee80211_stop_all(struct ieee80211com *);
33532176cfdSRui Paulo void	ieee80211_suspend_all(struct ieee80211com *);
33632176cfdSRui Paulo void	ieee80211_resume_all(struct ieee80211com *);
33732176cfdSRui Paulo void	ieee80211_dturbo_switch(struct ieee80211vap *, int newflags);
338085ff963SMatthew Dillon void	ieee80211_swbmiss(void *arg);
339841ab66cSSepherosa Ziehau void	ieee80211_beacon_miss(struct ieee80211com *);
34032176cfdSRui Paulo int	ieee80211_new_state(struct ieee80211vap *, enum ieee80211_state, int);
341d98a0bcfSMatthew Dillon int	ieee80211_new_state_locked(struct ieee80211vap *, enum ieee80211_state,
342d98a0bcfSMatthew Dillon 		int);
343841ab66cSSepherosa Ziehau void	ieee80211_print_essid(const uint8_t *, int);
34432176cfdSRui Paulo void	ieee80211_dump_pkt(struct ieee80211com *,
34532176cfdSRui Paulo 		const uint8_t *, int, int, int);
346f186073cSJoerg Sonnenberger 
34732176cfdSRui Paulo extern 	const char *ieee80211_opmode_name[];
348f186073cSJoerg Sonnenberger extern	const char *ieee80211_state_name[IEEE80211_S_MAX];
349841ab66cSSepherosa Ziehau extern	const char *ieee80211_wme_acnames[];
350841ab66cSSepherosa Ziehau 
351841ab66cSSepherosa Ziehau /*
352841ab66cSSepherosa Ziehau  * Beacon frames constructed by ieee80211_beacon_alloc
353841ab66cSSepherosa Ziehau  * have the following structure filled in so drivers
354841ab66cSSepherosa Ziehau  * can update the frame later w/ minimal overhead.
355841ab66cSSepherosa Ziehau  */
356841ab66cSSepherosa Ziehau struct ieee80211_beacon_offsets {
35732176cfdSRui Paulo 	uint8_t		bo_flags[4];	/* update/state flags */
358841ab66cSSepherosa Ziehau 	uint16_t	*bo_caps;	/* capabilities */
35932176cfdSRui Paulo 	uint8_t		*bo_cfp;	/* start of CFParms element */
360841ab66cSSepherosa Ziehau 	uint8_t		*bo_tim;	/* start of atim/dtim */
361841ab66cSSepherosa Ziehau 	uint8_t		*bo_wme;	/* start of WME parameters */
36232176cfdSRui Paulo 	uint8_t		*bo_tdma;	/* start of TDMA parameters */
36332176cfdSRui Paulo 	uint8_t		*bo_tim_trailer;/* start of fixed-size trailer */
364841ab66cSSepherosa Ziehau 	uint16_t	bo_tim_len;	/* atim/dtim length in bytes */
36532176cfdSRui Paulo 	uint16_t	bo_tim_trailer_len;/* tim trailer length in bytes */
366841ab66cSSepherosa Ziehau 	uint8_t		*bo_erp;	/* start of ERP element */
36732176cfdSRui Paulo 	uint8_t		*bo_htinfo;	/* start of HT info element */
36832176cfdSRui Paulo 	uint8_t		*bo_ath;	/* start of ATH parameters */
36932176cfdSRui Paulo 	uint8_t		*bo_appie;	/* start of AppIE element */
37032176cfdSRui Paulo 	uint16_t	bo_appie_len;	/* AppIE length in bytes */
37132176cfdSRui Paulo 	uint16_t	bo_csa_trailer_len;
37232176cfdSRui Paulo 	uint8_t		*bo_csa;	/* start of CSA element */
373085ff963SMatthew Dillon 	uint8_t		*bo_quiet;	/* start of Quiet element */
37432176cfdSRui Paulo 	uint8_t		*bo_meshconf;	/* start of MESHCONF element */
37532176cfdSRui Paulo 	uint8_t		*bo_spare[3];
376841ab66cSSepherosa Ziehau };
37732176cfdSRui Paulo struct mbuf *ieee80211_beacon_alloc(struct ieee80211_node *,
37832176cfdSRui Paulo 		struct ieee80211_beacon_offsets *);
379841ab66cSSepherosa Ziehau 
38032176cfdSRui Paulo /*
38132176cfdSRui Paulo  * Beacon frame updates are signaled through calls to iv_update_beacon
38232176cfdSRui Paulo  * with one of the IEEE80211_BEACON_* tokens defined below.  For devices
38332176cfdSRui Paulo  * that construct beacon frames on the host this can trigger a rebuild
38432176cfdSRui Paulo  * or defer the processing.  For devices that offload beacon frame
38532176cfdSRui Paulo  * handling this callback can be used to signal a rebuild.  The bo_flags
38632176cfdSRui Paulo  * array in the ieee80211_beacon_offsets structure is intended to record
38732176cfdSRui Paulo  * deferred processing requirements; ieee80211_beacon_update uses the
38832176cfdSRui Paulo  * state to optimize work.  Since this structure is owned by the driver
38932176cfdSRui Paulo  * and not visible to the 802.11 layer drivers must supply an iv_update_beacon
39032176cfdSRui Paulo  * callback that marks the flag bits and schedules (as necessary) an update.
39132176cfdSRui Paulo  */
39232176cfdSRui Paulo enum {
39332176cfdSRui Paulo 	IEEE80211_BEACON_CAPS	= 0,	/* capabilities */
39432176cfdSRui Paulo 	IEEE80211_BEACON_TIM	= 1,	/* DTIM/ATIM */
39532176cfdSRui Paulo 	IEEE80211_BEACON_WME	= 2,
39632176cfdSRui Paulo 	IEEE80211_BEACON_ERP	= 3,	/* Extended Rate Phy */
39732176cfdSRui Paulo 	IEEE80211_BEACON_HTINFO	= 4,	/* HT Information */
39832176cfdSRui Paulo 	IEEE80211_BEACON_APPIE	= 5,	/* Application IE's */
39932176cfdSRui Paulo 	IEEE80211_BEACON_CFP	= 6,	/* CFParms */
40032176cfdSRui Paulo 	IEEE80211_BEACON_CSA	= 7,	/* Channel Switch Announcement */
40132176cfdSRui Paulo 	IEEE80211_BEACON_TDMA	= 9,	/* TDMA Info */
40232176cfdSRui Paulo 	IEEE80211_BEACON_ATH	= 10,	/* ATH parameters */
40332176cfdSRui Paulo 	IEEE80211_BEACON_MESHCONF = 11,	/* Mesh Configuration */
40432176cfdSRui Paulo };
40532176cfdSRui Paulo int	ieee80211_beacon_update(struct ieee80211_node *,
40632176cfdSRui Paulo 		struct ieee80211_beacon_offsets *, struct mbuf *, int mcast);
4073da93495SSepherosa Ziehau 
40832176cfdSRui Paulo void	ieee80211_csa_startswitch(struct ieee80211com *,
40932176cfdSRui Paulo 		struct ieee80211_channel *, int mode, int count);
41032176cfdSRui Paulo void	ieee80211_csa_completeswitch(struct ieee80211com *);
41132176cfdSRui Paulo void	ieee80211_csa_cancelswitch(struct ieee80211com *);
41232176cfdSRui Paulo void	ieee80211_cac_completeswitch(struct ieee80211vap *);
4132d7dda79SSepherosa Ziehau 
414841ab66cSSepherosa Ziehau /*
415841ab66cSSepherosa Ziehau  * Notification methods called from the 802.11 state machine.
416841ab66cSSepherosa Ziehau  * Note that while these are defined here, their implementation
417841ab66cSSepherosa Ziehau  * is OS-specific.
418841ab66cSSepherosa Ziehau  */
41932176cfdSRui Paulo void	ieee80211_notify_node_join(struct ieee80211_node *, int newassoc);
42032176cfdSRui Paulo void	ieee80211_notify_node_leave(struct ieee80211_node *);
42132176cfdSRui Paulo void	ieee80211_notify_scan_done(struct ieee80211vap *);
42232176cfdSRui Paulo void	ieee80211_notify_wds_discover(struct ieee80211_node *);
42332176cfdSRui Paulo void	ieee80211_notify_csa(struct ieee80211com *,
42432176cfdSRui Paulo 		const struct ieee80211_channel *, int mode, int count);
42532176cfdSRui Paulo void	ieee80211_notify_radar(struct ieee80211com *,
42632176cfdSRui Paulo 		const struct ieee80211_channel *);
42732176cfdSRui Paulo enum ieee80211_notify_cac_event {
42832176cfdSRui Paulo 	IEEE80211_NOTIFY_CAC_START  = 0, /* CAC timer started */
42932176cfdSRui Paulo 	IEEE80211_NOTIFY_CAC_STOP   = 1, /* CAC intentionally stopped */
43032176cfdSRui Paulo 	IEEE80211_NOTIFY_CAC_RADAR  = 2, /* CAC stopped due to radar detectio */
43132176cfdSRui Paulo 	IEEE80211_NOTIFY_CAC_EXPIRE = 3, /* CAC expired w/o radar */
43232176cfdSRui Paulo };
43332176cfdSRui Paulo void	ieee80211_notify_cac(struct ieee80211com *,
43432176cfdSRui Paulo 		const struct ieee80211_channel *,
43532176cfdSRui Paulo 		enum ieee80211_notify_cac_event);
43632176cfdSRui Paulo void	ieee80211_notify_node_deauth(struct ieee80211_node *);
43732176cfdSRui Paulo void	ieee80211_notify_node_auth(struct ieee80211_node *);
43832176cfdSRui Paulo void	ieee80211_notify_country(struct ieee80211vap *, const uint8_t [],
43932176cfdSRui Paulo 		const uint8_t cc[2]);
44032176cfdSRui Paulo void	ieee80211_notify_radio(struct ieee80211com *, int);
441841ab66cSSepherosa Ziehau #endif /* _NET80211_IEEE80211_PROTO_H_ */
442