ieee80211_proto.h revision 139502
1116742Ssam/*-
2116904Ssam * Copyright (c) 2001 Atsushi Onoe
3138568Ssam * Copyright (c) 2002-2004 Sam Leffler, Errno Consulting
4116742Ssam * All rights reserved.
5116742Ssam *
6116742Ssam * Redistribution and use in source and binary forms, with or without
7116742Ssam * modification, are permitted provided that the following conditions
8116742Ssam * are met:
9116742Ssam * 1. Redistributions of source code must retain the above copyright
10116742Ssam *    notice, this list of conditions and the following disclaimer.
11116742Ssam * 2. Redistributions in binary form must reproduce the above copyright
12116742Ssam *    notice, this list of conditions and the following disclaimer in the
13116742Ssam *    documentation and/or other materials provided with the distribution.
14116904Ssam * 3. The name of the author may not be used to endorse or promote products
15116904Ssam *    derived from this software without specific prior written permission.
16116742Ssam *
17116904Ssam * Alternatively, this software may be distributed under the terms of the
18116904Ssam * GNU General Public License ("GPL") version 2 as published by the Free
19116904Ssam * Software Foundation.
20116742Ssam *
21116904Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22116904Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23116904Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24116904Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25116904Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26116904Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27116904Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28116904Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29116904Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30116904Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31116904Ssam *
32116742Ssam * $FreeBSD: head/sys/net80211/ieee80211_proto.h 139502 2004-12-31 20:38:48Z sam $
33116742Ssam */
34116742Ssam#ifndef _NET80211_IEEE80211_PROTO_H_
35116742Ssam#define _NET80211_IEEE80211_PROTO_H_
36116742Ssam
37116742Ssam/*
38116742Ssam * 802.11 protocol implementation definitions.
39116742Ssam */
40116742Ssam
41116742Ssamenum ieee80211_state {
42117811Ssam	IEEE80211_S_INIT	= 0,	/* default state */
43117811Ssam	IEEE80211_S_SCAN	= 1,	/* scanning */
44117811Ssam	IEEE80211_S_AUTH	= 2,	/* try to authenticate */
45117811Ssam	IEEE80211_S_ASSOC	= 3,	/* try to assoc */
46117811Ssam	IEEE80211_S_RUN		= 4,	/* associated */
47116742Ssam};
48117811Ssam#define	IEEE80211_S_MAX		(IEEE80211_S_RUN+1)
49116742Ssam
50116742Ssam#define	IEEE80211_SEND_MGMT(_ic,_ni,_type,_arg) \
51116742Ssam	((*(_ic)->ic_send_mgmt)(_ic, _ni, _type, _arg))
52116742Ssam
53116742Ssamextern	const char *ieee80211_mgt_subtype_name[];
54139502Ssamextern	const char *ieee80211_phymode_name[];
55116742Ssam
56138568Ssamextern	void ieee80211_proto_attach(struct ieee80211com *);
57138568Ssamextern	void ieee80211_proto_detach(struct ieee80211com *);
58116742Ssam
59119150Ssamstruct ieee80211_node;
60138568Ssamextern	void ieee80211_input(struct ieee80211com *, struct mbuf *,
61119150Ssam		struct ieee80211_node *, int, u_int32_t);
62119150Ssamextern	void ieee80211_recv_mgmt(struct ieee80211com *, struct mbuf *,
63119150Ssam		struct ieee80211_node *, int, int, u_int32_t);
64138568Ssamextern	int ieee80211_send_nulldata(struct ieee80211com *,
65138568Ssam		struct ieee80211_node *);
66116742Ssamextern	int ieee80211_send_mgmt(struct ieee80211com *, struct ieee80211_node *,
67116742Ssam		int, int);
68138568Ssamextern	int ieee80211_classify(struct ieee80211com *, struct mbuf *,
69138568Ssam		struct ieee80211_node *);
70138568Ssamextern	struct mbuf *ieee80211_encap(struct ieee80211com *, struct mbuf *,
71138568Ssam		struct ieee80211_node *);
72138568Ssamextern	void ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *,
73138568Ssam		struct mbuf *);
74138568Ssam
75138568Ssamextern	void ieee80211_reset_erp(struct ieee80211com *);
76138568Ssamextern	void ieee80211_set_shortslottime(struct ieee80211com *, int onoff);
77138568Ssamextern	int ieee80211_iserp_rateset(struct ieee80211com *,
78138568Ssam		struct ieee80211_rateset *);
79138568Ssamextern	void ieee80211_set11gbasicrates(struct ieee80211_rateset *,
80138568Ssam		enum ieee80211_phymode);
81138568Ssam
82138568Ssam/*
83138568Ssam * Return the size of the 802.11 header for a management or data frame.
84138568Ssam */
85138568Ssamstatic inline int
86138568Ssamieee80211_hdrsize(const void *data)
87138568Ssam{
88138568Ssam	const struct ieee80211_frame *wh = data;
89138568Ssam	int size = sizeof(struct ieee80211_frame);
90138568Ssam
91138568Ssam	/* NB: we don't handle control frames */
92138568Ssam	KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL,
93138568Ssam		("%s: control frame", __func__));
94138568Ssam	if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
95138568Ssam		size += IEEE80211_ADDR_LEN;
96138568Ssam	if (IEEE80211_QOS_HAS_SEQ(wh))
97138568Ssam		size += sizeof(u_int16_t);
98138568Ssam	return size;
99138568Ssam}
100138568Ssam
101138568Ssam/*
102138568Ssam * Return the size of the 802.11 header; handles any type of frame.
103138568Ssam */
104138568Ssamstatic inline int
105138568Ssamieee80211_anyhdrsize(const void *data)
106138568Ssam{
107138568Ssam	const struct ieee80211_frame *wh = data;
108138568Ssam
109138568Ssam	if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) {
110138568Ssam		switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
111138568Ssam		case IEEE80211_FC0_SUBTYPE_CTS:
112138568Ssam		case IEEE80211_FC0_SUBTYPE_ACK:
113138568Ssam			return sizeof(struct ieee80211_frame_ack);
114138568Ssam		}
115138568Ssam		return sizeof(struct ieee80211_frame_min);
116138568Ssam	} else
117138568Ssam		return ieee80211_hdrsize(data);
118138568Ssam}
119138568Ssam
120138568Ssam/*
121138568Ssam * Template for an in-kernel authenticator.  Authenticators
122138568Ssam * register with the protocol code and are typically loaded
123138568Ssam * as separate modules as needed.
124138568Ssam */
125138568Ssamstruct ieee80211_authenticator {
126138568Ssam	const char *ia_name;		/* printable name */
127138568Ssam	int	(*ia_attach)(struct ieee80211com *);
128138568Ssam	void	(*ia_detach)(struct ieee80211com *);
129138568Ssam	void	(*ia_node_join)(struct ieee80211com *,
130138568Ssam				struct ieee80211_node *);
131138568Ssam	void	(*ia_node_leave)(struct ieee80211com *,
132138568Ssam				struct ieee80211_node *);
133138568Ssam};
134138568Ssamextern	void ieee80211_authenticator_register(int type,
135138568Ssam		const struct ieee80211_authenticator *);
136138568Ssamextern	void ieee80211_authenticator_unregister(int type);
137138568Ssamextern	const struct ieee80211_authenticator *
138138568Ssam		ieee80211_authenticator_get(int auth);
139138568Ssam
140138568Ssam/*
141138568Ssam * Template for an MAC ACL policy module.  Such modules
142138568Ssam * register with the protocol code and are passed the sender's
143138568Ssam * address of each received frame for validation.
144138568Ssam */
145138568Ssamstruct ieee80211_aclator {
146138568Ssam	const char *iac_name;		/* printable name */
147138568Ssam	int	(*iac_attach)(struct ieee80211com *);
148138568Ssam	void	(*iac_detach)(struct ieee80211com *);
149138568Ssam	int	(*iac_check)(struct ieee80211com *,
150138568Ssam			const u_int8_t mac[IEEE80211_ADDR_LEN]);
151138568Ssam	int	(*iac_add)(struct ieee80211com *,
152138568Ssam			const u_int8_t mac[IEEE80211_ADDR_LEN]);
153138568Ssam	int	(*iac_remove)(struct ieee80211com *,
154138568Ssam			const u_int8_t mac[IEEE80211_ADDR_LEN]);
155138568Ssam	int	(*iac_flush)(struct ieee80211com *);
156138568Ssam	int	(*iac_setpolicy)(struct ieee80211com *, int);
157138568Ssam	int	(*iac_getpolicy)(struct ieee80211com *);
158138568Ssam};
159138568Ssamextern	void ieee80211_aclator_register(const struct ieee80211_aclator *);
160138568Ssamextern	void ieee80211_aclator_unregister(const struct ieee80211_aclator *);
161138568Ssamextern	const struct ieee80211_aclator *ieee80211_aclator_get(const char *name);
162138568Ssam
163138568Ssam/* flags for ieee80211_fix_rate() */
164138568Ssam#define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
165138568Ssam#define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed rate */
166138568Ssam#define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
167138568Ssam#define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
168138568Ssamextern	int ieee80211_fix_rate(struct ieee80211com *,
169138568Ssam		struct ieee80211_node *, int);
170138568Ssam
171138568Ssam/*
172138568Ssam * WME/WMM support.
173138568Ssam */
174138568Ssamstruct wmeParams {
175138568Ssam	u_int8_t	wmep_acm;
176138568Ssam	u_int8_t	wmep_aifsn;
177138568Ssam	u_int8_t	wmep_logcwmin;		/* log2(cwmin) */
178138568Ssam	u_int8_t	wmep_logcwmax;		/* log2(cwmax) */
179138568Ssam	u_int8_t	wmep_txopLimit;
180138568Ssam	u_int8_t	wmep_noackPolicy;	/* 0 (ack), 1 (no ack) */
181138568Ssam};
182138568Ssam
183138568Ssamstruct chanAccParams {
184138568Ssam	u_int8_t	cap_info;		/* version of the current set */
185138568Ssam	struct wmeParams cap_wmeParams[WME_NUM_AC];
186138568Ssam};
187138568Ssam
188138568Ssamstruct ieee80211_wme_state {
189138568Ssam	u_int	wme_flags;
190138568Ssam#define	WME_F_AGGRMODE	0x00000001	/* STATUS: WME agressive mode */
191138568Ssam	u_int	wme_hipri_traffic;	/* VI/VO frames in beacon interval */
192138568Ssam	u_int	wme_hipri_switch_thresh;/* agressive mode switch thresh */
193138568Ssam	u_int	wme_hipri_switch_hysteresis;/* agressive mode switch hysteresis */
194138568Ssam
195138568Ssam	struct wmeParams wme_params[4];		/* from assoc resp for each AC*/
196138568Ssam	struct chanAccParams wme_wmeChanParams;	/* WME params applied to self */
197138568Ssam	struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */
198138568Ssam	struct chanAccParams wme_chanParams;	/* params applied to self */
199138568Ssam	struct chanAccParams wme_bssChanParams;	/* params bcast to stations */
200138568Ssam
201138568Ssam	int	(*wme_update)(struct ieee80211com *);
202138568Ssam};
203138568Ssam
204138568Ssamextern	void ieee80211_wme_initparams(struct ieee80211com *);
205138568Ssamextern	void ieee80211_wme_updateparams(struct ieee80211com *);
206138568Ssamextern	void ieee80211_wme_updateparams_locked(struct ieee80211com *);
207138568Ssam
208117811Ssam#define	ieee80211_new_state(_ic, _nstate, _arg) \
209117811Ssam	(((_ic)->ic_newstate)((_ic), (_nstate), (_arg)))
210138568Ssamextern	void ieee80211_print_essid(const u_int8_t *, int);
211138568Ssamextern	void ieee80211_dump_pkt(const u_int8_t *, int, int, int);
212117811Ssam
213117811Ssamextern	const char *ieee80211_state_name[IEEE80211_S_MAX];
214138568Ssamextern	const char *ieee80211_wme_acnames[];
215138568Ssam
216138568Ssam/*
217138568Ssam * Beacon frames constructed by ieee80211_beacon_alloc
218138568Ssam * have the following structure filled in so drivers
219138568Ssam * can update the frame later w/ minimal overhead.
220138568Ssam */
221138568Ssamstruct ieee80211_beacon_offsets {
222138568Ssam	u_int16_t	*bo_caps;	/* capabilities */
223138568Ssam	u_int8_t	*bo_tim;	/* start of atim/dtim */
224138568Ssam	u_int8_t	*bo_wme;	/* start of WME parameters */
225138568Ssam	u_int8_t	*bo_trailer;	/* start of fixed-size trailer */
226138568Ssam	u_int16_t	bo_tim_len;	/* atim/dtim length in bytes */
227138568Ssam	u_int16_t	bo_trailer_len;	/* trailer length in bytes */
228138568Ssam};
229138568Ssamextern	struct mbuf *ieee80211_beacon_alloc(struct ieee80211com *,
230138568Ssam		struct ieee80211_node *, struct ieee80211_beacon_offsets *);
231138568Ssamextern	int ieee80211_beacon_update(struct ieee80211com *,
232138568Ssam		struct ieee80211_node *, struct ieee80211_beacon_offsets *,
233138568Ssam		struct mbuf *, int broadcast);
234138568Ssam
235138568Ssam/*
236138568Ssam * Notification methods called from the 802.11 state machine.
237138568Ssam * Note that while these are defined here, their implementation
238138568Ssam * is OS-specific.
239138568Ssam */
240138568Ssamextern	void ieee80211_notify_node_join(struct ieee80211com *,
241138568Ssam		struct ieee80211_node *, int newassoc);
242138568Ssamextern	void ieee80211_notify_node_leave(struct ieee80211com *,
243138568Ssam		struct ieee80211_node *);
244138568Ssamextern	void ieee80211_notify_scan_done(struct ieee80211com *);
245116742Ssam#endif /* _NET80211_IEEE80211_PROTO_H_ */
246