xref: /freebsd/sys/net80211/ieee80211_proto.h (revision 188757f54c844f7a1c7d8cd03afd8af160fc3ed1)
11a1e1d21SSam Leffler /*-
27535e66aSSam Leffler  * Copyright (c) 2001 Atsushi Onoe
31f1d7810SSam Leffler  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
41a1e1d21SSam Leffler  * All rights reserved.
51a1e1d21SSam Leffler  *
61a1e1d21SSam Leffler  * Redistribution and use in source and binary forms, with or without
71a1e1d21SSam Leffler  * modification, are permitted provided that the following conditions
81a1e1d21SSam Leffler  * are met:
91a1e1d21SSam Leffler  * 1. Redistributions of source code must retain the above copyright
101a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer.
111a1e1d21SSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
121a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer in the
131a1e1d21SSam Leffler  *    documentation and/or other materials provided with the distribution.
147535e66aSSam Leffler  * 3. The name of the author may not be used to endorse or promote products
157535e66aSSam Leffler  *    derived from this software without specific prior written permission.
161a1e1d21SSam Leffler  *
177535e66aSSam Leffler  * Alternatively, this software may be distributed under the terms of the
187535e66aSSam Leffler  * GNU General Public License ("GPL") version 2 as published by the Free
197535e66aSSam Leffler  * Software Foundation.
207535e66aSSam Leffler  *
217535e66aSSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
227535e66aSSam Leffler  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
237535e66aSSam Leffler  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
247535e66aSSam Leffler  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
257535e66aSSam Leffler  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
267535e66aSSam Leffler  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
277535e66aSSam Leffler  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
287535e66aSSam Leffler  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
297535e66aSSam Leffler  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
307535e66aSSam Leffler  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311a1e1d21SSam Leffler  *
321a1e1d21SSam Leffler  * $FreeBSD$
331a1e1d21SSam Leffler  */
341a1e1d21SSam Leffler #ifndef _NET80211_IEEE80211_PROTO_H_
351a1e1d21SSam Leffler #define _NET80211_IEEE80211_PROTO_H_
361a1e1d21SSam Leffler 
371a1e1d21SSam Leffler /*
381a1e1d21SSam Leffler  * 802.11 protocol implementation definitions.
391a1e1d21SSam Leffler  */
401a1e1d21SSam Leffler 
411a1e1d21SSam Leffler enum ieee80211_state {
42a11c9a5cSSam Leffler 	IEEE80211_S_INIT	= 0,	/* default state */
43a11c9a5cSSam Leffler 	IEEE80211_S_SCAN	= 1,	/* scanning */
44a11c9a5cSSam Leffler 	IEEE80211_S_AUTH	= 2,	/* try to authenticate */
45a11c9a5cSSam Leffler 	IEEE80211_S_ASSOC	= 3,	/* try to assoc */
46a11c9a5cSSam Leffler 	IEEE80211_S_RUN		= 4,	/* associated */
471a1e1d21SSam Leffler };
48a11c9a5cSSam Leffler #define	IEEE80211_S_MAX		(IEEE80211_S_RUN+1)
491a1e1d21SSam Leffler 
501a1e1d21SSam Leffler #define	IEEE80211_SEND_MGMT(_ic,_ni,_type,_arg) \
511a1e1d21SSam Leffler 	((*(_ic)->ic_send_mgmt)(_ic, _ni, _type, _arg))
521a1e1d21SSam Leffler 
531a1e1d21SSam Leffler extern	const char *ieee80211_mgt_subtype_name[];
548da7b74fSSam Leffler extern	const char *ieee80211_phymode_name[];
551a1e1d21SSam Leffler 
560942c81cSSam Leffler void	ieee80211_proto_attach(struct ieee80211com *);
570942c81cSSam Leffler void	ieee80211_proto_detach(struct ieee80211com *);
581a1e1d21SSam Leffler 
590a915fadSSam Leffler struct ieee80211_node;
600942c81cSSam Leffler int	ieee80211_input(struct ieee80211com *, struct mbuf *,
610a915fadSSam Leffler 		struct ieee80211_node *, int, u_int32_t);
627d77cd53SSam Leffler int	ieee80211_setup_rates(struct ieee80211_node *ni,
637d77cd53SSam Leffler 		const u_int8_t *rates, const u_int8_t *xrates, int flags);
64b5c99415SSam Leffler void	ieee80211_saveie(u_int8_t **, const u_int8_t *);
650942c81cSSam Leffler void	ieee80211_recv_mgmt(struct ieee80211com *, struct mbuf *,
660a915fadSSam Leffler 		struct ieee80211_node *, int, int, u_int32_t);
67f62121ceSSam Leffler int	ieee80211_send_nulldata(struct ieee80211_node *);
68af8418dcSSam Leffler int	ieee80211_send_probereq(struct ieee80211_node *ni,
69af8418dcSSam Leffler 		const u_int8_t sa[IEEE80211_ADDR_LEN],
70af8418dcSSam Leffler 		const u_int8_t da[IEEE80211_ADDR_LEN],
71af8418dcSSam Leffler 		const u_int8_t bssid[IEEE80211_ADDR_LEN],
72af8418dcSSam Leffler 		const u_int8_t *ssid, size_t ssidlen,
73af8418dcSSam Leffler 		const void *optie, size_t optielen);
740942c81cSSam Leffler int	ieee80211_send_mgmt(struct ieee80211com *, struct ieee80211_node *,
751a1e1d21SSam Leffler 		int, int);
760942c81cSSam Leffler int	ieee80211_classify(struct ieee80211com *, struct mbuf *,
778a1b9b6aSSam Leffler 		struct ieee80211_node *);
780942c81cSSam Leffler struct mbuf *ieee80211_encap(struct ieee80211com *, struct mbuf *,
798a1b9b6aSSam Leffler 		struct ieee80211_node *);
800942c81cSSam Leffler void	ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *,
818a1b9b6aSSam Leffler 		struct mbuf *);
828a1b9b6aSSam Leffler 
830942c81cSSam Leffler void	ieee80211_reset_erp(struct ieee80211com *);
840942c81cSSam Leffler void	ieee80211_set_shortslottime(struct ieee80211com *, int onoff);
850942c81cSSam Leffler int	ieee80211_iserp_rateset(struct ieee80211com *,
868a1b9b6aSSam Leffler 		struct ieee80211_rateset *);
870942c81cSSam Leffler void	ieee80211_set11gbasicrates(struct ieee80211_rateset *,
888a1b9b6aSSam Leffler 		enum ieee80211_phymode);
898a1b9b6aSSam Leffler 
908a1b9b6aSSam Leffler /*
918a1b9b6aSSam Leffler  * Return the size of the 802.11 header for a management or data frame.
928a1b9b6aSSam Leffler  */
93a95fa8d3SSam Leffler static __inline int
948a1b9b6aSSam Leffler ieee80211_hdrsize(const void *data)
958a1b9b6aSSam Leffler {
968a1b9b6aSSam Leffler 	const struct ieee80211_frame *wh = data;
978a1b9b6aSSam Leffler 	int size = sizeof(struct ieee80211_frame);
988a1b9b6aSSam Leffler 
998a1b9b6aSSam Leffler 	/* NB: we don't handle control frames */
1008a1b9b6aSSam Leffler 	KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL,
1018a1b9b6aSSam Leffler 		("%s: control frame", __func__));
1028a1b9b6aSSam Leffler 	if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
1038a1b9b6aSSam Leffler 		size += IEEE80211_ADDR_LEN;
1048a1b9b6aSSam Leffler 	if (IEEE80211_QOS_HAS_SEQ(wh))
1058a1b9b6aSSam Leffler 		size += sizeof(u_int16_t);
1068a1b9b6aSSam Leffler 	return size;
1078a1b9b6aSSam Leffler }
1088a1b9b6aSSam Leffler 
1098a1b9b6aSSam Leffler /*
1108a1b9b6aSSam Leffler  * Return the size of the 802.11 header; handles any type of frame.
1118a1b9b6aSSam Leffler  */
112a95fa8d3SSam Leffler static __inline int
1138a1b9b6aSSam Leffler ieee80211_anyhdrsize(const void *data)
1148a1b9b6aSSam Leffler {
1158a1b9b6aSSam Leffler 	const struct ieee80211_frame *wh = data;
1168a1b9b6aSSam Leffler 
1178a1b9b6aSSam Leffler 	if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) {
1188a1b9b6aSSam Leffler 		switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
1198a1b9b6aSSam Leffler 		case IEEE80211_FC0_SUBTYPE_CTS:
1208a1b9b6aSSam Leffler 		case IEEE80211_FC0_SUBTYPE_ACK:
1218a1b9b6aSSam Leffler 			return sizeof(struct ieee80211_frame_ack);
1228a1b9b6aSSam Leffler 		}
1238a1b9b6aSSam Leffler 		return sizeof(struct ieee80211_frame_min);
1248a1b9b6aSSam Leffler 	} else
1258a1b9b6aSSam Leffler 		return ieee80211_hdrsize(data);
1268a1b9b6aSSam Leffler }
1278a1b9b6aSSam Leffler 
1288a1b9b6aSSam Leffler /*
1298a1b9b6aSSam Leffler  * Template for an in-kernel authenticator.  Authenticators
1308a1b9b6aSSam Leffler  * register with the protocol code and are typically loaded
1318a1b9b6aSSam Leffler  * as separate modules as needed.
1328a1b9b6aSSam Leffler  */
1338a1b9b6aSSam Leffler struct ieee80211_authenticator {
1348a1b9b6aSSam Leffler 	const char *ia_name;		/* printable name */
1358a1b9b6aSSam Leffler 	int	(*ia_attach)(struct ieee80211com *);
1368a1b9b6aSSam Leffler 	void	(*ia_detach)(struct ieee80211com *);
1378a1b9b6aSSam Leffler 	void	(*ia_node_join)(struct ieee80211com *,
1388a1b9b6aSSam Leffler 				struct ieee80211_node *);
1398a1b9b6aSSam Leffler 	void	(*ia_node_leave)(struct ieee80211com *,
1408a1b9b6aSSam Leffler 				struct ieee80211_node *);
1418a1b9b6aSSam Leffler };
1420942c81cSSam Leffler void	ieee80211_authenticator_register(int type,
1438a1b9b6aSSam Leffler 		const struct ieee80211_authenticator *);
1440942c81cSSam Leffler void	ieee80211_authenticator_unregister(int type);
1450942c81cSSam Leffler const struct ieee80211_authenticator *ieee80211_authenticator_get(int auth);
1468a1b9b6aSSam Leffler 
147188757f5SSam Leffler struct ieee80211req;
1488a1b9b6aSSam Leffler /*
1498a1b9b6aSSam Leffler  * Template for an MAC ACL policy module.  Such modules
1508a1b9b6aSSam Leffler  * register with the protocol code and are passed the sender's
1518a1b9b6aSSam Leffler  * address of each received frame for validation.
1528a1b9b6aSSam Leffler  */
1538a1b9b6aSSam Leffler struct ieee80211_aclator {
1548a1b9b6aSSam Leffler 	const char *iac_name;		/* printable name */
1558a1b9b6aSSam Leffler 	int	(*iac_attach)(struct ieee80211com *);
1568a1b9b6aSSam Leffler 	void	(*iac_detach)(struct ieee80211com *);
1578a1b9b6aSSam Leffler 	int	(*iac_check)(struct ieee80211com *,
1588a1b9b6aSSam Leffler 			const u_int8_t mac[IEEE80211_ADDR_LEN]);
1598a1b9b6aSSam Leffler 	int	(*iac_add)(struct ieee80211com *,
1608a1b9b6aSSam Leffler 			const u_int8_t mac[IEEE80211_ADDR_LEN]);
1618a1b9b6aSSam Leffler 	int	(*iac_remove)(struct ieee80211com *,
1628a1b9b6aSSam Leffler 			const u_int8_t mac[IEEE80211_ADDR_LEN]);
1638a1b9b6aSSam Leffler 	int	(*iac_flush)(struct ieee80211com *);
1648a1b9b6aSSam Leffler 	int	(*iac_setpolicy)(struct ieee80211com *, int);
1658a1b9b6aSSam Leffler 	int	(*iac_getpolicy)(struct ieee80211com *);
166188757f5SSam Leffler 	int	(*iac_setioctl)(struct ieee80211com *, struct ieee80211req *);
167188757f5SSam Leffler 	int	(*iac_getioctl)(struct ieee80211com *, struct ieee80211req *);
1688a1b9b6aSSam Leffler };
1690942c81cSSam Leffler void	ieee80211_aclator_register(const struct ieee80211_aclator *);
1700942c81cSSam Leffler void	ieee80211_aclator_unregister(const struct ieee80211_aclator *);
1710942c81cSSam Leffler const struct ieee80211_aclator *ieee80211_aclator_get(const char *name);
1728a1b9b6aSSam Leffler 
1738a1b9b6aSSam Leffler /* flags for ieee80211_fix_rate() */
1748a1b9b6aSSam Leffler #define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
1758a1b9b6aSSam Leffler #define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed rate */
1768a1b9b6aSSam Leffler #define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
1778a1b9b6aSSam Leffler #define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
1787d77cd53SSam Leffler int	ieee80211_fix_rate(struct ieee80211_node *, int);
1798a1b9b6aSSam Leffler 
1808a1b9b6aSSam Leffler /*
1818a1b9b6aSSam Leffler  * WME/WMM support.
1828a1b9b6aSSam Leffler  */
1838a1b9b6aSSam Leffler struct wmeParams {
1848a1b9b6aSSam Leffler 	u_int8_t	wmep_acm;
1858a1b9b6aSSam Leffler 	u_int8_t	wmep_aifsn;
1868a1b9b6aSSam Leffler 	u_int8_t	wmep_logcwmin;		/* log2(cwmin) */
1878a1b9b6aSSam Leffler 	u_int8_t	wmep_logcwmax;		/* log2(cwmax) */
1888a1b9b6aSSam Leffler 	u_int8_t	wmep_txopLimit;
1898a1b9b6aSSam Leffler 	u_int8_t	wmep_noackPolicy;	/* 0 (ack), 1 (no ack) */
1908a1b9b6aSSam Leffler };
1915a11fbcaSSam Leffler #define	IEEE80211_TXOP_TO_US(_txop)	((_txop)<<5)
1925a11fbcaSSam Leffler #define	IEEE80211_US_TO_TXOP(_us)	((_us)>>5)
1938a1b9b6aSSam Leffler 
1948a1b9b6aSSam Leffler struct chanAccParams {
1958a1b9b6aSSam Leffler 	u_int8_t	cap_info;		/* version of the current set */
1968a1b9b6aSSam Leffler 	struct wmeParams cap_wmeParams[WME_NUM_AC];
1978a1b9b6aSSam Leffler };
1988a1b9b6aSSam Leffler 
1998a1b9b6aSSam Leffler struct ieee80211_wme_state {
2008a1b9b6aSSam Leffler 	u_int	wme_flags;
2018a1b9b6aSSam Leffler #define	WME_F_AGGRMODE	0x00000001	/* STATUS: WME agressive mode */
2028a1b9b6aSSam Leffler 	u_int	wme_hipri_traffic;	/* VI/VO frames in beacon interval */
2038a1b9b6aSSam Leffler 	u_int	wme_hipri_switch_thresh;/* agressive mode switch thresh */
2048a1b9b6aSSam Leffler 	u_int	wme_hipri_switch_hysteresis;/* agressive mode switch hysteresis */
2058a1b9b6aSSam Leffler 
2068a1b9b6aSSam Leffler 	struct wmeParams wme_params[4];		/* from assoc resp for each AC*/
2078a1b9b6aSSam Leffler 	struct chanAccParams wme_wmeChanParams;	/* WME params applied to self */
2088a1b9b6aSSam Leffler 	struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */
2098a1b9b6aSSam Leffler 	struct chanAccParams wme_chanParams;	/* params applied to self */
2108a1b9b6aSSam Leffler 	struct chanAccParams wme_bssChanParams;	/* params bcast to stations */
2118a1b9b6aSSam Leffler 
2128a1b9b6aSSam Leffler 	int	(*wme_update)(struct ieee80211com *);
2138a1b9b6aSSam Leffler };
2148a1b9b6aSSam Leffler 
2150942c81cSSam Leffler void	ieee80211_wme_initparams(struct ieee80211com *);
2160942c81cSSam Leffler void	ieee80211_wme_updateparams(struct ieee80211com *);
2170942c81cSSam Leffler void	ieee80211_wme_updateparams_locked(struct ieee80211com *);
2188a1b9b6aSSam Leffler 
219a11c9a5cSSam Leffler #define	ieee80211_new_state(_ic, _nstate, _arg) \
220a11c9a5cSSam Leffler 	(((_ic)->ic_newstate)((_ic), (_nstate), (_arg)))
2210942c81cSSam Leffler void	ieee80211_print_essid(const u_int8_t *, int);
2220942c81cSSam Leffler void	ieee80211_dump_pkt(const u_int8_t *, int, int, int);
223a11c9a5cSSam Leffler 
224a11c9a5cSSam Leffler extern	const char *ieee80211_state_name[IEEE80211_S_MAX];
2258a1b9b6aSSam Leffler extern	const char *ieee80211_wme_acnames[];
2268a1b9b6aSSam Leffler 
2278a1b9b6aSSam Leffler /*
2288a1b9b6aSSam Leffler  * Beacon frames constructed by ieee80211_beacon_alloc
2298a1b9b6aSSam Leffler  * have the following structure filled in so drivers
2308a1b9b6aSSam Leffler  * can update the frame later w/ minimal overhead.
2318a1b9b6aSSam Leffler  */
2328a1b9b6aSSam Leffler struct ieee80211_beacon_offsets {
2338a1b9b6aSSam Leffler 	u_int16_t	*bo_caps;	/* capabilities */
2348a1b9b6aSSam Leffler 	u_int8_t	*bo_tim;	/* start of atim/dtim */
2358a1b9b6aSSam Leffler 	u_int8_t	*bo_wme;	/* start of WME parameters */
2368a1b9b6aSSam Leffler 	u_int8_t	*bo_trailer;	/* start of fixed-size trailer */
2378a1b9b6aSSam Leffler 	u_int16_t	bo_tim_len;	/* atim/dtim length in bytes */
2388a1b9b6aSSam Leffler 	u_int16_t	bo_trailer_len;	/* trailer length in bytes */
2398a1b9b6aSSam Leffler };
2400942c81cSSam Leffler struct mbuf *ieee80211_beacon_alloc(struct ieee80211com *,
2418a1b9b6aSSam Leffler 		struct ieee80211_node *, struct ieee80211_beacon_offsets *);
2420942c81cSSam Leffler int	ieee80211_beacon_update(struct ieee80211com *,
2438a1b9b6aSSam Leffler 		struct ieee80211_node *, struct ieee80211_beacon_offsets *,
2448a1b9b6aSSam Leffler 		struct mbuf *, int broadcast);
2458a1b9b6aSSam Leffler 
2468a1b9b6aSSam Leffler /*
2478a1b9b6aSSam Leffler  * Notification methods called from the 802.11 state machine.
2488a1b9b6aSSam Leffler  * Note that while these are defined here, their implementation
2498a1b9b6aSSam Leffler  * is OS-specific.
2508a1b9b6aSSam Leffler  */
2510942c81cSSam Leffler void	ieee80211_notify_node_join(struct ieee80211com *,
2528a1b9b6aSSam Leffler 		struct ieee80211_node *, int newassoc);
2530942c81cSSam Leffler void	ieee80211_notify_node_leave(struct ieee80211com *,
2548a1b9b6aSSam Leffler 		struct ieee80211_node *);
2550942c81cSSam Leffler void	ieee80211_notify_scan_done(struct ieee80211com *);
2561a1e1d21SSam Leffler #endif /* _NET80211_IEEE80211_PROTO_H_ */
257