xref: /haiku/src/libs/compat/freebsd_wlan/net80211/ieee80211_proto.h (revision 86021fd407331bcef948c739a4870ca453f5c6cd)
1753c7e08SAugustin Cavalier /*-
2*86021fd4SAugustin Cavalier  * SPDX-License-Identifier: BSD-2-Clause
38244a9baSAugustin Cavalier  *
4753c7e08SAugustin Cavalier  * Copyright (c) 2001 Atsushi Onoe
5753c7e08SAugustin Cavalier  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
6753c7e08SAugustin Cavalier  * All rights reserved.
7753c7e08SAugustin Cavalier  *
8753c7e08SAugustin Cavalier  * Redistribution and use in source and binary forms, with or without
9753c7e08SAugustin Cavalier  * modification, are permitted provided that the following conditions
10753c7e08SAugustin Cavalier  * are met:
11753c7e08SAugustin Cavalier  * 1. Redistributions of source code must retain the above copyright
12753c7e08SAugustin Cavalier  *    notice, this list of conditions and the following disclaimer.
13753c7e08SAugustin Cavalier  * 2. Redistributions in binary form must reproduce the above copyright
14753c7e08SAugustin Cavalier  *    notice, this list of conditions and the following disclaimer in the
15753c7e08SAugustin Cavalier  *    documentation and/or other materials provided with the distribution.
16753c7e08SAugustin Cavalier  *
17753c7e08SAugustin Cavalier  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18753c7e08SAugustin Cavalier  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19753c7e08SAugustin Cavalier  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20753c7e08SAugustin Cavalier  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21753c7e08SAugustin Cavalier  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22753c7e08SAugustin Cavalier  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23753c7e08SAugustin Cavalier  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24753c7e08SAugustin Cavalier  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25753c7e08SAugustin Cavalier  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26753c7e08SAugustin Cavalier  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27753c7e08SAugustin Cavalier  */
28753c7e08SAugustin Cavalier #ifndef _NET80211_IEEE80211_PROTO_H_
29753c7e08SAugustin Cavalier #define _NET80211_IEEE80211_PROTO_H_
30753c7e08SAugustin Cavalier 
31753c7e08SAugustin Cavalier /*
32753c7e08SAugustin Cavalier  * 802.11 protocol implementation definitions.
33753c7e08SAugustin Cavalier  */
34753c7e08SAugustin Cavalier 
35753c7e08SAugustin Cavalier enum ieee80211_state {
36753c7e08SAugustin Cavalier 	IEEE80211_S_INIT	= 0,	/* default state */
37753c7e08SAugustin Cavalier 	IEEE80211_S_SCAN	= 1,	/* scanning */
38753c7e08SAugustin Cavalier 	IEEE80211_S_AUTH	= 2,	/* try to authenticate */
39753c7e08SAugustin Cavalier 	IEEE80211_S_ASSOC	= 3,	/* try to assoc */
40753c7e08SAugustin Cavalier 	IEEE80211_S_CAC		= 4,	/* doing channel availability check */
41753c7e08SAugustin Cavalier 	IEEE80211_S_RUN		= 5,	/* operational (e.g. associated) */
42753c7e08SAugustin Cavalier 	IEEE80211_S_CSA		= 6,	/* channel switch announce pending */
43753c7e08SAugustin Cavalier 	IEEE80211_S_SLEEP	= 7,	/* power save */
44753c7e08SAugustin Cavalier };
45753c7e08SAugustin Cavalier #define	IEEE80211_S_MAX		(IEEE80211_S_SLEEP+1)
46753c7e08SAugustin Cavalier 
47753c7e08SAugustin Cavalier #define	IEEE80211_SEND_MGMT(_ni,_type,_arg) \
48753c7e08SAugustin Cavalier 	((*(_ni)->ni_ic->ic_send_mgmt)(_ni, _type, _arg))
49753c7e08SAugustin Cavalier 
50753c7e08SAugustin Cavalier extern	const char *mgt_subtype_name[];
51753c7e08SAugustin Cavalier extern	const char *ctl_subtype_name[];
52753c7e08SAugustin Cavalier extern	const char *ieee80211_phymode_name[IEEE80211_MODE_MAX];
53753c7e08SAugustin Cavalier extern	const int ieee80211_opcap[IEEE80211_OPMODE_MAX];
54753c7e08SAugustin Cavalier 
55753c7e08SAugustin Cavalier static __inline const char *
ieee80211_mgt_subtype_name(uint8_t subtype)56753c7e08SAugustin Cavalier ieee80211_mgt_subtype_name(uint8_t subtype)
57753c7e08SAugustin Cavalier {
58753c7e08SAugustin Cavalier 	return mgt_subtype_name[(subtype & IEEE80211_FC0_SUBTYPE_MASK) >>
59753c7e08SAugustin Cavalier 		   IEEE80211_FC0_SUBTYPE_SHIFT];
60753c7e08SAugustin Cavalier }
61753c7e08SAugustin Cavalier 
62753c7e08SAugustin Cavalier static __inline const char *
ieee80211_ctl_subtype_name(uint8_t subtype)63753c7e08SAugustin Cavalier ieee80211_ctl_subtype_name(uint8_t subtype)
64753c7e08SAugustin Cavalier {
65753c7e08SAugustin Cavalier 	return ctl_subtype_name[(subtype & IEEE80211_FC0_SUBTYPE_MASK) >>
66753c7e08SAugustin Cavalier 		   IEEE80211_FC0_SUBTYPE_SHIFT];
67753c7e08SAugustin Cavalier }
68753c7e08SAugustin Cavalier 
69753c7e08SAugustin Cavalier const char *ieee80211_reason_to_string(uint16_t);
70753c7e08SAugustin Cavalier 
71753c7e08SAugustin Cavalier void	ieee80211_proto_attach(struct ieee80211com *);
72753c7e08SAugustin Cavalier void	ieee80211_proto_detach(struct ieee80211com *);
73753c7e08SAugustin Cavalier void	ieee80211_proto_vattach(struct ieee80211vap *);
74753c7e08SAugustin Cavalier void	ieee80211_proto_vdetach(struct ieee80211vap *);
75753c7e08SAugustin Cavalier 
76753c7e08SAugustin Cavalier void	ieee80211_promisc(struct ieee80211vap *, bool);
77753c7e08SAugustin Cavalier void	ieee80211_allmulti(struct ieee80211vap *, bool);
78753c7e08SAugustin Cavalier void	ieee80211_syncflag(struct ieee80211vap *, int flag);
79753c7e08SAugustin Cavalier void	ieee80211_syncflag_ht(struct ieee80211vap *, int flag);
808244a9baSAugustin Cavalier void	ieee80211_syncflag_vht(struct ieee80211vap *, int flag);
81753c7e08SAugustin Cavalier void	ieee80211_syncflag_ext(struct ieee80211vap *, int flag);
82753c7e08SAugustin Cavalier 
83753c7e08SAugustin Cavalier #define	ieee80211_input(ni, m, rssi, nf) \
84753c7e08SAugustin Cavalier 	((ni)->ni_vap->iv_input(ni, m, NULL, rssi, nf))
85753c7e08SAugustin Cavalier int	ieee80211_input_all(struct ieee80211com *, struct mbuf *, int, int);
86753c7e08SAugustin Cavalier 
878244a9baSAugustin Cavalier int	ieee80211_input_mimo(struct ieee80211_node *, struct mbuf *);
888244a9baSAugustin Cavalier int	ieee80211_input_mimo_all(struct ieee80211com *, struct mbuf *);
89753c7e08SAugustin Cavalier 
90753c7e08SAugustin Cavalier struct ieee80211_bpf_params;
91753c7e08SAugustin Cavalier int	ieee80211_mgmt_output(struct ieee80211_node *, struct mbuf *, int,
92753c7e08SAugustin Cavalier 		struct ieee80211_bpf_params *);
93753c7e08SAugustin Cavalier int	ieee80211_raw_xmit(struct ieee80211_node *, struct mbuf *,
94753c7e08SAugustin Cavalier 		const struct ieee80211_bpf_params *);
95753c7e08SAugustin Cavalier int	ieee80211_output(struct ifnet *, struct mbuf *,
96753c7e08SAugustin Cavalier                const struct sockaddr *, struct route *ro);
97753c7e08SAugustin Cavalier int	ieee80211_vap_pkt_send_dest(struct ieee80211vap *, struct mbuf *,
98753c7e08SAugustin Cavalier 		struct ieee80211_node *);
99753c7e08SAugustin Cavalier int	ieee80211_raw_output(struct ieee80211vap *, struct ieee80211_node *,
100753c7e08SAugustin Cavalier 		struct mbuf *, const struct ieee80211_bpf_params *);
101753c7e08SAugustin Cavalier void	ieee80211_send_setup(struct ieee80211_node *, struct mbuf *, int, int,
102753c7e08SAugustin Cavalier         const uint8_t [IEEE80211_ADDR_LEN], const uint8_t [IEEE80211_ADDR_LEN],
103753c7e08SAugustin Cavalier         const uint8_t [IEEE80211_ADDR_LEN]);
104753c7e08SAugustin Cavalier int	ieee80211_vap_transmit(struct ifnet *ifp, struct mbuf *m);
105753c7e08SAugustin Cavalier void	ieee80211_vap_qflush(struct ifnet *ifp);
106753c7e08SAugustin Cavalier int	ieee80211_send_nulldata(struct ieee80211_node *);
107753c7e08SAugustin Cavalier int	ieee80211_classify(struct ieee80211_node *, struct mbuf *m);
108753c7e08SAugustin Cavalier struct mbuf *ieee80211_mbuf_adjust(struct ieee80211vap *, int,
109753c7e08SAugustin Cavalier 		struct ieee80211_key *, struct mbuf *);
110753c7e08SAugustin Cavalier struct mbuf *ieee80211_encap(struct ieee80211vap *, struct ieee80211_node *,
111753c7e08SAugustin Cavalier 		struct mbuf *);
112753c7e08SAugustin Cavalier void	ieee80211_free_mbuf(struct mbuf *);
113753c7e08SAugustin Cavalier int	ieee80211_send_mgmt(struct ieee80211_node *, int, int);
114753c7e08SAugustin Cavalier struct ieee80211_appie;
115*86021fd4SAugustin Cavalier int	ieee80211_probereq_ie(struct ieee80211vap *, struct ieee80211com *,
116*86021fd4SAugustin Cavalier 		uint8_t **, uint32_t *, const uint8_t *, size_t, bool);
117753c7e08SAugustin Cavalier int	ieee80211_send_probereq(struct ieee80211_node *ni,
118753c7e08SAugustin Cavalier 		const uint8_t sa[IEEE80211_ADDR_LEN],
119753c7e08SAugustin Cavalier 		const uint8_t da[IEEE80211_ADDR_LEN],
120753c7e08SAugustin Cavalier 		const uint8_t bssid[IEEE80211_ADDR_LEN],
121753c7e08SAugustin Cavalier 		const uint8_t *ssid, size_t ssidlen);
122753c7e08SAugustin Cavalier struct mbuf *	ieee80211_ff_encap1(struct ieee80211vap *, struct mbuf *,
123753c7e08SAugustin Cavalier 		const struct ether_header *);
124753c7e08SAugustin Cavalier void	ieee80211_tx_complete(struct ieee80211_node *,
125753c7e08SAugustin Cavalier 		struct mbuf *, int);
126753c7e08SAugustin Cavalier 
127753c7e08SAugustin Cavalier /*
128753c7e08SAugustin Cavalier  * The formation of ProbeResponse frames requires guidance to
129753c7e08SAugustin Cavalier  * deal with legacy clients.  When the client is identified as
130753c7e08SAugustin Cavalier  * "legacy 11b" ieee80211_send_proberesp is passed this token.
131753c7e08SAugustin Cavalier  */
132753c7e08SAugustin Cavalier #define	IEEE80211_SEND_LEGACY_11B	0x1	/* legacy 11b client */
133753c7e08SAugustin Cavalier #define	IEEE80211_SEND_LEGACY_11	0x2	/* other legacy client */
134753c7e08SAugustin Cavalier #define	IEEE80211_SEND_LEGACY		0x3	/* any legacy client */
135753c7e08SAugustin Cavalier struct mbuf *ieee80211_alloc_proberesp(struct ieee80211_node *, int);
136753c7e08SAugustin Cavalier int	ieee80211_send_proberesp(struct ieee80211vap *,
137753c7e08SAugustin Cavalier 		const uint8_t da[IEEE80211_ADDR_LEN], int);
138753c7e08SAugustin Cavalier struct mbuf *ieee80211_alloc_rts(struct ieee80211com *ic,
139753c7e08SAugustin Cavalier 		const uint8_t [IEEE80211_ADDR_LEN],
140753c7e08SAugustin Cavalier 		const uint8_t [IEEE80211_ADDR_LEN], uint16_t);
141753c7e08SAugustin Cavalier struct mbuf *ieee80211_alloc_cts(struct ieee80211com *,
142753c7e08SAugustin Cavalier 		const uint8_t [IEEE80211_ADDR_LEN], uint16_t);
1438244a9baSAugustin Cavalier struct mbuf *ieee80211_alloc_prot(struct ieee80211_node *,
1448244a9baSAugustin Cavalier 		const struct mbuf *, uint8_t, int);
145753c7e08SAugustin Cavalier 
146753c7e08SAugustin Cavalier uint8_t *ieee80211_add_rates(uint8_t *, const struct ieee80211_rateset *);
147753c7e08SAugustin Cavalier uint8_t *ieee80211_add_xrates(uint8_t *, const struct ieee80211_rateset *);
148753c7e08SAugustin Cavalier uint8_t *ieee80211_add_ssid(uint8_t *, const uint8_t *, u_int);
149753c7e08SAugustin Cavalier uint8_t *ieee80211_add_wpa(uint8_t *, const struct ieee80211vap *);
150753c7e08SAugustin Cavalier uint8_t *ieee80211_add_rsn(uint8_t *, const struct ieee80211vap *);
151753c7e08SAugustin Cavalier uint8_t *ieee80211_add_qos(uint8_t *, const struct ieee80211_node *);
152753c7e08SAugustin Cavalier uint16_t ieee80211_getcapinfo(struct ieee80211vap *,
153753c7e08SAugustin Cavalier 		struct ieee80211_channel *);
154753c7e08SAugustin Cavalier struct ieee80211_wme_state;
1555cad57c4SJérôme Duval uint8_t * ieee80211_add_wme_info(uint8_t *frm, struct ieee80211_wme_state *wme,
1565cad57c4SJérôme Duval 	    struct ieee80211_node *ni);
157753c7e08SAugustin Cavalier 
1585cad57c4SJérôme Duval void	ieee80211_vap_reset_erp(struct ieee80211vap *);
159753c7e08SAugustin Cavalier void	ieee80211_reset_erp(struct ieee80211com *);
1605cad57c4SJérôme Duval void	ieee80211_vap_set_shortslottime(struct ieee80211vap *, int onoff);
161753c7e08SAugustin Cavalier int	ieee80211_iserp_rateset(const struct ieee80211_rateset *);
162753c7e08SAugustin Cavalier void	ieee80211_setbasicrates(struct ieee80211_rateset *,
163753c7e08SAugustin Cavalier 		enum ieee80211_phymode);
164753c7e08SAugustin Cavalier void	ieee80211_addbasicrates(struct ieee80211_rateset *,
165753c7e08SAugustin Cavalier 		enum ieee80211_phymode);
166753c7e08SAugustin Cavalier 
167753c7e08SAugustin Cavalier /*
168753c7e08SAugustin Cavalier  * Return the size of the 802.11 header for a management or data frame.
169753c7e08SAugustin Cavalier  */
170753c7e08SAugustin Cavalier static __inline int
ieee80211_hdrsize(const void * data)171753c7e08SAugustin Cavalier ieee80211_hdrsize(const void *data)
172753c7e08SAugustin Cavalier {
1738244a9baSAugustin Cavalier 	const struct ieee80211_frame *wh = (const struct ieee80211_frame *)data;
174753c7e08SAugustin Cavalier 	int size = sizeof(struct ieee80211_frame);
175753c7e08SAugustin Cavalier 
176753c7e08SAugustin Cavalier 	/* NB: we don't handle control frames */
177753c7e08SAugustin Cavalier 	KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL,
178753c7e08SAugustin Cavalier 		("%s: control frame", __func__));
179753c7e08SAugustin Cavalier 	if (IEEE80211_IS_DSTODS(wh))
180753c7e08SAugustin Cavalier 		size += IEEE80211_ADDR_LEN;
181753c7e08SAugustin Cavalier 	if (IEEE80211_QOS_HAS_SEQ(wh))
182753c7e08SAugustin Cavalier 		size += sizeof(uint16_t);
183753c7e08SAugustin Cavalier 	return size;
184753c7e08SAugustin Cavalier }
185753c7e08SAugustin Cavalier 
186753c7e08SAugustin Cavalier /*
187753c7e08SAugustin Cavalier  * Like ieee80211_hdrsize, but handles any type of frame.
188753c7e08SAugustin Cavalier  */
189753c7e08SAugustin Cavalier static __inline int
ieee80211_anyhdrsize(const void * data)190753c7e08SAugustin Cavalier ieee80211_anyhdrsize(const void *data)
191753c7e08SAugustin Cavalier {
1928244a9baSAugustin Cavalier 	const struct ieee80211_frame *wh = (const struct ieee80211_frame *)data;
193753c7e08SAugustin Cavalier 
194753c7e08SAugustin Cavalier 	if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) {
195753c7e08SAugustin Cavalier 		switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
196753c7e08SAugustin Cavalier 		case IEEE80211_FC0_SUBTYPE_CTS:
197753c7e08SAugustin Cavalier 		case IEEE80211_FC0_SUBTYPE_ACK:
198753c7e08SAugustin Cavalier 			return sizeof(struct ieee80211_frame_ack);
199753c7e08SAugustin Cavalier 		case IEEE80211_FC0_SUBTYPE_BAR:
200753c7e08SAugustin Cavalier 			return sizeof(struct ieee80211_frame_bar);
201753c7e08SAugustin Cavalier 		}
202753c7e08SAugustin Cavalier 		return sizeof(struct ieee80211_frame_min);
203753c7e08SAugustin Cavalier 	} else
204753c7e08SAugustin Cavalier 		return ieee80211_hdrsize(data);
205753c7e08SAugustin Cavalier }
206753c7e08SAugustin Cavalier 
207753c7e08SAugustin Cavalier /*
208753c7e08SAugustin Cavalier  * Template for an in-kernel authenticator.  Authenticators
209753c7e08SAugustin Cavalier  * register with the protocol code and are typically loaded
210753c7e08SAugustin Cavalier  * as separate modules as needed.  One special authenticator
211753c7e08SAugustin Cavalier  * is xauth; it intercepts requests so that protocols like
212753c7e08SAugustin Cavalier  * WPA can be handled in user space.
213753c7e08SAugustin Cavalier  */
214753c7e08SAugustin Cavalier struct ieee80211_authenticator {
215753c7e08SAugustin Cavalier 	const char *ia_name;		/* printable name */
216753c7e08SAugustin Cavalier 	int	(*ia_attach)(struct ieee80211vap *);
217753c7e08SAugustin Cavalier 	void	(*ia_detach)(struct ieee80211vap *);
218753c7e08SAugustin Cavalier 	void	(*ia_node_join)(struct ieee80211_node *);
219753c7e08SAugustin Cavalier 	void	(*ia_node_leave)(struct ieee80211_node *);
220753c7e08SAugustin Cavalier };
221753c7e08SAugustin Cavalier void	ieee80211_authenticator_register(int type,
222753c7e08SAugustin Cavalier 		const struct ieee80211_authenticator *);
223753c7e08SAugustin Cavalier void	ieee80211_authenticator_unregister(int type);
224753c7e08SAugustin Cavalier const struct ieee80211_authenticator *ieee80211_authenticator_get(int auth);
225753c7e08SAugustin Cavalier 
226753c7e08SAugustin Cavalier struct ieee80211req;
227753c7e08SAugustin Cavalier /*
228753c7e08SAugustin Cavalier  * Template for an MAC ACL policy module.  Such modules
229753c7e08SAugustin Cavalier  * register with the protocol code and are passed the sender's
230753c7e08SAugustin Cavalier  * address of each received auth frame for validation.
231753c7e08SAugustin Cavalier  */
232753c7e08SAugustin Cavalier struct ieee80211_aclator {
233753c7e08SAugustin Cavalier 	const char *iac_name;		/* printable name */
234753c7e08SAugustin Cavalier 	int	(*iac_attach)(struct ieee80211vap *);
235753c7e08SAugustin Cavalier 	void	(*iac_detach)(struct ieee80211vap *);
236753c7e08SAugustin Cavalier 	int	(*iac_check)(struct ieee80211vap *,
237753c7e08SAugustin Cavalier 			const struct ieee80211_frame *wh);
238753c7e08SAugustin Cavalier 	int	(*iac_add)(struct ieee80211vap *,
239753c7e08SAugustin Cavalier 			const uint8_t mac[IEEE80211_ADDR_LEN]);
240753c7e08SAugustin Cavalier 	int	(*iac_remove)(struct ieee80211vap *,
241753c7e08SAugustin Cavalier 			const uint8_t mac[IEEE80211_ADDR_LEN]);
242753c7e08SAugustin Cavalier 	int	(*iac_flush)(struct ieee80211vap *);
243753c7e08SAugustin Cavalier 	int	(*iac_setpolicy)(struct ieee80211vap *, int);
244753c7e08SAugustin Cavalier 	int	(*iac_getpolicy)(struct ieee80211vap *);
245753c7e08SAugustin Cavalier 	int	(*iac_setioctl)(struct ieee80211vap *, struct ieee80211req *);
246753c7e08SAugustin Cavalier 	int	(*iac_getioctl)(struct ieee80211vap *, struct ieee80211req *);
247753c7e08SAugustin Cavalier };
248753c7e08SAugustin Cavalier void	ieee80211_aclator_register(const struct ieee80211_aclator *);
249753c7e08SAugustin Cavalier void	ieee80211_aclator_unregister(const struct ieee80211_aclator *);
250753c7e08SAugustin Cavalier const struct ieee80211_aclator *ieee80211_aclator_get(const char *name);
251753c7e08SAugustin Cavalier 
252753c7e08SAugustin Cavalier /* flags for ieee80211_fix_rate() */
253753c7e08SAugustin Cavalier #define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
254753c7e08SAugustin Cavalier #define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed legacy rate */
255753c7e08SAugustin Cavalier #define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
256753c7e08SAugustin Cavalier #define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
257753c7e08SAugustin Cavalier #define	IEEE80211_F_DOBRS	0x00000010	/* check basic rate set */
258753c7e08SAugustin Cavalier #define	IEEE80211_F_JOIN	0x00000020	/* sta joining our bss */
259753c7e08SAugustin Cavalier #define	IEEE80211_F_DOFMCS	0x00000040	/* use fixed HT rate */
260753c7e08SAugustin Cavalier int	ieee80211_fix_rate(struct ieee80211_node *,
261753c7e08SAugustin Cavalier 		struct ieee80211_rateset *, int);
262753c7e08SAugustin Cavalier 
263753c7e08SAugustin Cavalier /*
264753c7e08SAugustin Cavalier  * WME/WMM support.
265753c7e08SAugustin Cavalier  */
266753c7e08SAugustin Cavalier struct wmeParams {
267753c7e08SAugustin Cavalier 	uint8_t		wmep_acm;
268753c7e08SAugustin Cavalier 	uint8_t		wmep_aifsn;
269753c7e08SAugustin Cavalier 	uint8_t		wmep_logcwmin;		/* log2(cwmin) */
270753c7e08SAugustin Cavalier 	uint8_t		wmep_logcwmax;		/* log2(cwmax) */
271753c7e08SAugustin Cavalier 	uint8_t		wmep_txopLimit;
272753c7e08SAugustin Cavalier 	uint8_t		wmep_noackPolicy;	/* 0 (ack), 1 (no ack) */
273753c7e08SAugustin Cavalier };
274753c7e08SAugustin Cavalier #define	IEEE80211_TXOP_TO_US(_txop)	((_txop)<<5)
275753c7e08SAugustin Cavalier #define	IEEE80211_US_TO_TXOP(_us)	((_us)>>5)
276753c7e08SAugustin Cavalier 
277753c7e08SAugustin Cavalier struct chanAccParams {
278753c7e08SAugustin Cavalier 	uint8_t		cap_info;		/* version of the current set */
279753c7e08SAugustin Cavalier 	struct wmeParams cap_wmeParams[WME_NUM_AC];
280753c7e08SAugustin Cavalier };
281753c7e08SAugustin Cavalier 
282753c7e08SAugustin Cavalier struct ieee80211_wme_state {
283753c7e08SAugustin Cavalier 	u_int	wme_flags;
284753c7e08SAugustin Cavalier #define	WME_F_AGGRMODE	0x00000001	/* STATUS: WME aggressive mode */
285753c7e08SAugustin Cavalier 	u_int	wme_hipri_traffic;	/* VI/VO frames in beacon interval */
286753c7e08SAugustin Cavalier 	u_int	wme_hipri_switch_thresh;/* aggressive mode switch thresh */
287753c7e08SAugustin Cavalier 	u_int	wme_hipri_switch_hysteresis;/* aggressive mode switch hysteresis */
288753c7e08SAugustin Cavalier 
2895cad57c4SJérôme Duval 	struct wmeParams wme_params[WME_NUM_AC]; /* from assoc resp for each AC */
290753c7e08SAugustin Cavalier 	struct chanAccParams wme_wmeChanParams;	/* WME params applied to self */
291753c7e08SAugustin Cavalier 	struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */
292753c7e08SAugustin Cavalier 	struct chanAccParams wme_chanParams;	/* params applied to self */
293753c7e08SAugustin Cavalier 	struct chanAccParams wme_bssChanParams;	/* params bcast to stations */
294753c7e08SAugustin Cavalier 
295753c7e08SAugustin Cavalier 	int	(*wme_update)(struct ieee80211com *);
296753c7e08SAugustin Cavalier };
297753c7e08SAugustin Cavalier 
298753c7e08SAugustin Cavalier void	ieee80211_wme_initparams(struct ieee80211vap *);
299753c7e08SAugustin Cavalier void	ieee80211_wme_updateparams(struct ieee80211vap *);
300753c7e08SAugustin Cavalier void	ieee80211_wme_updateparams_locked(struct ieee80211vap *);
3018244a9baSAugustin Cavalier void	ieee80211_wme_vap_getparams(struct ieee80211vap *vap,
3028244a9baSAugustin Cavalier 	    struct chanAccParams *);
3038244a9baSAugustin Cavalier void	ieee80211_wme_ic_getparams(struct ieee80211com *ic,
3048244a9baSAugustin Cavalier 	    struct chanAccParams *);
3058244a9baSAugustin Cavalier int	ieee80211_wme_vap_ac_is_noack(struct ieee80211vap *vap, int ac);
3065cad57c4SJérôme Duval void	ieee80211_vap_update_preamble(struct ieee80211vap *vap);
3075cad57c4SJérôme Duval void	ieee80211_vap_update_erp_protmode(struct ieee80211vap *vap);
3085cad57c4SJérôme Duval void	ieee80211_vap_update_ht_protmode(struct ieee80211vap *vap);
3095cad57c4SJérôme Duval 
3105cad57c4SJérôme Duval /*
3115cad57c4SJérôme Duval  * Return pointer to the QoS field from a Qos frame.
3125cad57c4SJérôme Duval  */
3135cad57c4SJérôme Duval static __inline uint8_t *
ieee80211_getqos(void * data)3145cad57c4SJérôme Duval ieee80211_getqos(void *data)
3155cad57c4SJérôme Duval {
3165cad57c4SJérôme Duval 	struct ieee80211_frame *wh = (struct ieee80211_frame *)data;
3175cad57c4SJérôme Duval 
3185cad57c4SJérôme Duval 	KASSERT(IEEE80211_QOS_HAS_SEQ(wh), ("QoS field is absent!"));
3195cad57c4SJérôme Duval 
3205cad57c4SJérôme Duval 	if (IEEE80211_IS_DSTODS(wh))
3215cad57c4SJérôme Duval 		return (((struct ieee80211_qosframe_addr4 *)wh)->i_qos);
3225cad57c4SJérôme Duval 	else
3235cad57c4SJérôme Duval 		return (((struct ieee80211_qosframe *)wh)->i_qos);
3245cad57c4SJérôme Duval }
325753c7e08SAugustin Cavalier 
326753c7e08SAugustin Cavalier /*
327753c7e08SAugustin Cavalier  * Return the WME TID from a QoS frame.  If no TID
328753c7e08SAugustin Cavalier  * is present return the index for the "non-QoS" entry.
329753c7e08SAugustin Cavalier  */
330753c7e08SAugustin Cavalier static __inline uint8_t
ieee80211_gettid(const struct ieee80211_frame * wh)331753c7e08SAugustin Cavalier ieee80211_gettid(const struct ieee80211_frame *wh)
332753c7e08SAugustin Cavalier {
333753c7e08SAugustin Cavalier 	uint8_t tid;
334753c7e08SAugustin Cavalier 
335753c7e08SAugustin Cavalier 	if (IEEE80211_QOS_HAS_SEQ(wh)) {
336753c7e08SAugustin Cavalier 		if (IEEE80211_IS_DSTODS(wh))
337753c7e08SAugustin Cavalier 			tid = ((const struct ieee80211_qosframe_addr4 *)wh)->
338753c7e08SAugustin Cavalier 				i_qos[0];
339753c7e08SAugustin Cavalier 		else
340753c7e08SAugustin Cavalier 			tid = ((const struct ieee80211_qosframe *)wh)->i_qos[0];
341753c7e08SAugustin Cavalier 		tid &= IEEE80211_QOS_TID;
342753c7e08SAugustin Cavalier 	} else
343753c7e08SAugustin Cavalier 		tid = IEEE80211_NONQOS_TID;
344753c7e08SAugustin Cavalier 	return tid;
345753c7e08SAugustin Cavalier }
346753c7e08SAugustin Cavalier 
347753c7e08SAugustin Cavalier void	ieee80211_waitfor_parent(struct ieee80211com *);
348753c7e08SAugustin Cavalier void	ieee80211_start_locked(struct ieee80211vap *);
349753c7e08SAugustin Cavalier void	ieee80211_init(void *);
350753c7e08SAugustin Cavalier void	ieee80211_start_all(struct ieee80211com *);
351753c7e08SAugustin Cavalier void	ieee80211_stop_locked(struct ieee80211vap *);
352753c7e08SAugustin Cavalier void	ieee80211_stop(struct ieee80211vap *);
353753c7e08SAugustin Cavalier void	ieee80211_stop_all(struct ieee80211com *);
354753c7e08SAugustin Cavalier void	ieee80211_suspend_all(struct ieee80211com *);
355753c7e08SAugustin Cavalier void	ieee80211_resume_all(struct ieee80211com *);
356753c7e08SAugustin Cavalier void	ieee80211_restart_all(struct ieee80211com *);
357753c7e08SAugustin Cavalier void	ieee80211_dturbo_switch(struct ieee80211vap *, int newflags);
358753c7e08SAugustin Cavalier void	ieee80211_swbmiss(void *arg);
359753c7e08SAugustin Cavalier void	ieee80211_beacon_miss(struct ieee80211com *);
360753c7e08SAugustin Cavalier int	ieee80211_new_state(struct ieee80211vap *, enum ieee80211_state, int);
361753c7e08SAugustin Cavalier int	ieee80211_new_state_locked(struct ieee80211vap *, enum ieee80211_state,
362753c7e08SAugustin Cavalier 		int);
363753c7e08SAugustin Cavalier void	ieee80211_print_essid(const uint8_t *, int);
364753c7e08SAugustin Cavalier void	ieee80211_dump_pkt(struct ieee80211com *,
365753c7e08SAugustin Cavalier 		const uint8_t *, int, int, int);
366753c7e08SAugustin Cavalier 
367753c7e08SAugustin Cavalier extern 	const char *ieee80211_opmode_name[];
368753c7e08SAugustin Cavalier extern	const char *ieee80211_state_name[IEEE80211_S_MAX];
369753c7e08SAugustin Cavalier extern	const char *ieee80211_wme_acnames[];
370753c7e08SAugustin Cavalier 
371753c7e08SAugustin Cavalier /*
372753c7e08SAugustin Cavalier  * Beacon frames constructed by ieee80211_beacon_alloc
373753c7e08SAugustin Cavalier  * have the following structure filled in so drivers
374753c7e08SAugustin Cavalier  * can update the frame later w/ minimal overhead.
375753c7e08SAugustin Cavalier  */
376753c7e08SAugustin Cavalier struct ieee80211_beacon_offsets {
377753c7e08SAugustin Cavalier 	uint8_t		bo_flags[4];	/* update/state flags */
378753c7e08SAugustin Cavalier 	uint16_t	*bo_caps;	/* capabilities */
379753c7e08SAugustin Cavalier 	uint8_t		*bo_cfp;	/* start of CFParms element */
380753c7e08SAugustin Cavalier 	uint8_t		*bo_tim;	/* start of atim/dtim */
381753c7e08SAugustin Cavalier 	uint8_t		*bo_wme;	/* start of WME parameters */
382753c7e08SAugustin Cavalier 	uint8_t		*bo_tdma;	/* start of TDMA parameters */
383753c7e08SAugustin Cavalier 	uint8_t		*bo_tim_trailer;/* start of fixed-size trailer */
384753c7e08SAugustin Cavalier 	uint16_t	bo_tim_len;	/* atim/dtim length in bytes */
385753c7e08SAugustin Cavalier 	uint16_t	bo_tim_trailer_len;/* tim trailer length in bytes */
386753c7e08SAugustin Cavalier 	uint8_t		*bo_erp;	/* start of ERP element */
387753c7e08SAugustin Cavalier 	uint8_t		*bo_htinfo;	/* start of HT info element */
388753c7e08SAugustin Cavalier 	uint8_t		*bo_ath;	/* start of ATH parameters */
389753c7e08SAugustin Cavalier 	uint8_t		*bo_appie;	/* start of AppIE element */
390753c7e08SAugustin Cavalier 	uint16_t	bo_appie_len;	/* AppIE length in bytes */
391753c7e08SAugustin Cavalier 	uint16_t	bo_csa_trailer_len;
392753c7e08SAugustin Cavalier 	uint8_t		*bo_csa;	/* start of CSA element */
393753c7e08SAugustin Cavalier 	uint8_t		*bo_quiet;	/* start of Quiet element */
394753c7e08SAugustin Cavalier 	uint8_t		*bo_meshconf;	/* start of MESHCONF element */
3958244a9baSAugustin Cavalier 	uint8_t		*bo_vhtinfo;	/* start of VHT info element (XXX VHTCAP?) */
3968244a9baSAugustin Cavalier 	uint8_t		*bo_spare[2];
397753c7e08SAugustin Cavalier };
398753c7e08SAugustin Cavalier struct mbuf *ieee80211_beacon_alloc(struct ieee80211_node *);
399753c7e08SAugustin Cavalier 
400753c7e08SAugustin Cavalier /*
401753c7e08SAugustin Cavalier  * Beacon frame updates are signaled through calls to iv_update_beacon
402753c7e08SAugustin Cavalier  * with one of the IEEE80211_BEACON_* tokens defined below.  For devices
403753c7e08SAugustin Cavalier  * that construct beacon frames on the host this can trigger a rebuild
404753c7e08SAugustin Cavalier  * or defer the processing.  For devices that offload beacon frame
405753c7e08SAugustin Cavalier  * handling this callback can be used to signal a rebuild.  The bo_flags
406753c7e08SAugustin Cavalier  * array in the ieee80211_beacon_offsets structure is intended to record
407753c7e08SAugustin Cavalier  * deferred processing requirements; ieee80211_beacon_update uses the
408753c7e08SAugustin Cavalier  * state to optimize work.  Since this structure is owned by the driver
409753c7e08SAugustin Cavalier  * and not visible to the 802.11 layer drivers must supply an iv_update_beacon
410753c7e08SAugustin Cavalier  * callback that marks the flag bits and schedules (as necessary) an update.
411753c7e08SAugustin Cavalier  */
412753c7e08SAugustin Cavalier enum {
413753c7e08SAugustin Cavalier 	IEEE80211_BEACON_CAPS	= 0,	/* capabilities */
414753c7e08SAugustin Cavalier 	IEEE80211_BEACON_TIM	= 1,	/* DTIM/ATIM */
415753c7e08SAugustin Cavalier 	IEEE80211_BEACON_WME	= 2,
416753c7e08SAugustin Cavalier 	IEEE80211_BEACON_ERP	= 3,	/* Extended Rate Phy */
417753c7e08SAugustin Cavalier 	IEEE80211_BEACON_HTINFO	= 4,	/* HT Information */
418753c7e08SAugustin Cavalier 	IEEE80211_BEACON_APPIE	= 5,	/* Application IE's */
419753c7e08SAugustin Cavalier 	IEEE80211_BEACON_CFP	= 6,	/* CFParms */
420753c7e08SAugustin Cavalier 	IEEE80211_BEACON_CSA	= 7,	/* Channel Switch Announcement */
421753c7e08SAugustin Cavalier 	IEEE80211_BEACON_TDMA	= 9,	/* TDMA Info */
422753c7e08SAugustin Cavalier 	IEEE80211_BEACON_ATH	= 10,	/* ATH parameters */
423753c7e08SAugustin Cavalier 	IEEE80211_BEACON_MESHCONF = 11,	/* Mesh Configuration */
4248244a9baSAugustin Cavalier 	IEEE80211_BEACON_QUIET	= 12,	/* Quiet time IE */
4258244a9baSAugustin Cavalier 	IEEE80211_BEACON_VHTINFO	= 13,	/* VHT information */
426753c7e08SAugustin Cavalier };
427753c7e08SAugustin Cavalier int	ieee80211_beacon_update(struct ieee80211_node *,
428753c7e08SAugustin Cavalier 		struct mbuf *, int mcast);
429753c7e08SAugustin Cavalier 
430753c7e08SAugustin Cavalier void	ieee80211_csa_startswitch(struct ieee80211com *,
431753c7e08SAugustin Cavalier 		struct ieee80211_channel *, int mode, int count);
432753c7e08SAugustin Cavalier void	ieee80211_csa_completeswitch(struct ieee80211com *);
433753c7e08SAugustin Cavalier void	ieee80211_csa_cancelswitch(struct ieee80211com *);
434753c7e08SAugustin Cavalier void	ieee80211_cac_completeswitch(struct ieee80211vap *);
435753c7e08SAugustin Cavalier 
436753c7e08SAugustin Cavalier /*
437753c7e08SAugustin Cavalier  * Notification methods called from the 802.11 state machine.
438753c7e08SAugustin Cavalier  * Note that while these are defined here, their implementation
439753c7e08SAugustin Cavalier  * is OS-specific.
440753c7e08SAugustin Cavalier  */
441753c7e08SAugustin Cavalier void	ieee80211_notify_node_join(struct ieee80211_node *, int newassoc);
442753c7e08SAugustin Cavalier void	ieee80211_notify_node_leave(struct ieee80211_node *);
443753c7e08SAugustin Cavalier void	ieee80211_notify_scan_done(struct ieee80211vap *);
444753c7e08SAugustin Cavalier void	ieee80211_notify_wds_discover(struct ieee80211_node *);
445753c7e08SAugustin Cavalier void	ieee80211_notify_csa(struct ieee80211com *,
446753c7e08SAugustin Cavalier 		const struct ieee80211_channel *, int mode, int count);
447753c7e08SAugustin Cavalier void	ieee80211_notify_radar(struct ieee80211com *,
448753c7e08SAugustin Cavalier 		const struct ieee80211_channel *);
449753c7e08SAugustin Cavalier enum ieee80211_notify_cac_event {
450753c7e08SAugustin Cavalier 	IEEE80211_NOTIFY_CAC_START  = 0, /* CAC timer started */
451753c7e08SAugustin Cavalier 	IEEE80211_NOTIFY_CAC_STOP   = 1, /* CAC intentionally stopped */
452753c7e08SAugustin Cavalier 	IEEE80211_NOTIFY_CAC_RADAR  = 2, /* CAC stopped due to radar detectio */
453753c7e08SAugustin Cavalier 	IEEE80211_NOTIFY_CAC_EXPIRE = 3, /* CAC expired w/o radar */
454753c7e08SAugustin Cavalier };
455753c7e08SAugustin Cavalier void	ieee80211_notify_cac(struct ieee80211com *,
456753c7e08SAugustin Cavalier 		const struct ieee80211_channel *,
457753c7e08SAugustin Cavalier 		enum ieee80211_notify_cac_event);
458753c7e08SAugustin Cavalier void	ieee80211_notify_node_deauth(struct ieee80211_node *);
459753c7e08SAugustin Cavalier void	ieee80211_notify_node_auth(struct ieee80211_node *);
460*86021fd4SAugustin Cavalier void	ieee80211_notify_country(struct ieee80211vap *,
461*86021fd4SAugustin Cavalier 		const uint8_t [IEEE80211_ADDR_LEN], const uint8_t cc[2]);
462753c7e08SAugustin Cavalier void	ieee80211_notify_radio(struct ieee80211com *, int);
463*86021fd4SAugustin Cavalier void	ieee80211_notify_ifnet_change(struct ieee80211vap *, int);
464753c7e08SAugustin Cavalier #endif /* _NET80211_IEEE80211_PROTO_H_ */
465