xref: /openbsd/sys/net80211/ieee80211_node.h (revision 3d8817e4)
1 /*	$OpenBSD: ieee80211_node.h,v 1.41 2009/03/26 20:38:29 damien Exp $	*/
2 /*	$NetBSD: ieee80211_node.h,v 1.9 2004/04/30 22:57:32 dyoung Exp $	*/
3 
4 /*-
5  * Copyright (c) 2001 Atsushi Onoe
6  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD: src/sys/net80211/ieee80211_node.h,v 1.10 2004/04/05 22:10:26 sam Exp $
32  */
33 #ifndef _NET80211_IEEE80211_NODE_H_
34 #define _NET80211_IEEE80211_NODE_H_
35 
36 #define	IEEE80211_PSCAN_WAIT	5		/* passive scan wait */
37 #define	IEEE80211_TRANS_WAIT	5		/* transition wait */
38 #define	IEEE80211_INACT_WAIT	5		/* inactivity timer interval */
39 #define	IEEE80211_INACT_MAX	(300/IEEE80211_INACT_WAIT)
40 #define	IEEE80211_CACHE_SIZE	100
41 
42 struct ieee80211_rateset {
43 	u_int8_t		rs_nrates;
44 	u_int8_t		rs_rates[IEEE80211_RATE_MAXSIZE];
45 };
46 
47 extern const struct ieee80211_rateset ieee80211_std_rateset_11a;
48 extern const struct ieee80211_rateset ieee80211_std_rateset_11b;
49 extern const struct ieee80211_rateset ieee80211_std_rateset_11g;
50 
51 enum ieee80211_node_state {
52 	IEEE80211_STA_CACHE,	/* cached node */
53 	IEEE80211_STA_BSS,	/* ic->ic_bss, the network we joined */
54 	IEEE80211_STA_AUTH,	/* successfully authenticated */
55 	IEEE80211_STA_ASSOC,	/* successfully associated */
56 	IEEE80211_STA_COLLECT	/* This node remains in the cache while
57 				 * the driver sends a de-auth message;
58 				 * afterward it should be freed to make room
59 				 * for a new node.
60 				 */
61 };
62 
63 #define	ieee80211_node_newstate(__ni, __state)	\
64 	do {					\
65 		(__ni)->ni_state = (__state);	\
66 	} while (0)
67 
68 enum ieee80211_node_psstate {
69 	IEEE80211_PS_AWAKE,
70 	IEEE80211_PS_DOZE
71 };
72 
73 #define	IEEE80211_PS_MAX_QUEUE	50	/* maximum saved packets */
74 
75 /* Authenticator state machine: 4-Way Handshake (see 8.5.6.1.1) */
76 enum {
77 	RSNA_INITIALIZE,
78 	RSNA_AUTHENTICATION,
79 	RSNA_AUTHENTICATION_2,
80 	RSNA_INITPMK,
81 	RSNA_INITPSK,
82 	RSNA_PTKSTART,
83 	RSNA_PTKCALCNEGOTIATING,
84 	RSNA_PTKCALCNEGOTIATING_2,
85 	RSNA_PTKINITNEGOTIATING,
86 	RSNA_PTKINITDONE,
87 	RSNA_DISCONNECT,
88 	RSNA_DISCONNECTED
89 };
90 
91 /* Authenticator state machine: Group Key Handshake (see 8.5.6.1.2) */
92 enum {
93 	RSNA_IDLE,
94 	RSNA_REKEYNEGOTIATING,
95 	RSNA_REKEYESTABLISHED,
96 	RSNA_KEYERROR
97 };
98 
99 struct ieee80211_rxinfo {
100 	u_int32_t		rxi_flags;
101 	u_int32_t		rxi_tstamp;
102 	int			rxi_rssi;
103 };
104 #define IEEE80211_RXI_HWDEC		0x00000001
105 #define IEEE80211_RXI_AMPDU_DONE	0x00000002
106 
107 /* Block Acknowledgement Record */
108 struct ieee80211_tx_ba {
109 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
110 	struct timeout		ba_to;
111 	int			ba_timeout_val;
112 #define IEEE80211_BA_MIN_TIMEOUT	(10 * 1000)		/* 10msec */
113 #define IEEE80211_BA_MAX_TIMEOUT	(10 * 1000 * 1000)	/* 10sec */
114 
115 	int			ba_state;
116 #define IEEE80211_BA_INIT	0
117 #define IEEE80211_BA_REQUESTED	1
118 #define IEEE80211_BA_AGREED	2
119 
120 	u_int16_t		ba_winstart;
121 	u_int16_t		ba_winend;
122 	u_int16_t		ba_winsize;
123 #define IEEE80211_BA_MAX_WINSZ	128	/* maximum we will accept */
124 
125 	u_int8_t		ba_token;
126 };
127 
128 struct ieee80211_rx_ba {
129 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
130 	struct {
131 		struct mbuf		*m;
132 		struct ieee80211_rxinfo	rxi;
133 	}			*ba_buf;
134 	struct timeout		ba_to;
135 	int			ba_timeout_val;
136 	int			ba_state;
137 	u_int16_t		ba_winstart;
138 	u_int16_t		ba_winend;
139 	u_int16_t		ba_winsize;
140 	u_int16_t		ba_head;
141 };
142 
143 /*
144  * Node specific information.  Note that drivers are expected
145  * to derive from this structure to add device-specific per-node
146  * state.  This is done by overriding the ic_node_* methods in
147  * the ieee80211com structure.
148  */
149 struct ieee80211_node {
150 	RB_ENTRY(ieee80211_node)	ni_node;
151 
152 	struct ieee80211com	*ni_ic;		/* back-pointer */
153 
154 	u_int			ni_refcnt;
155 	u_int			ni_scangen;	/* gen# for timeout scan */
156 
157 	/* hardware */
158 	u_int32_t		ni_rstamp;	/* recv timestamp */
159 	u_int8_t		ni_rssi;	/* recv ssi */
160 
161 	/* header */
162 	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
163 	u_int8_t		ni_bssid[IEEE80211_ADDR_LEN];
164 
165 	/* beacon, probe response */
166 	u_int8_t		ni_tstamp[8];	/* from last rcv'd beacon */
167 	u_int16_t		ni_intval;	/* beacon interval */
168 	u_int16_t		ni_capinfo;	/* capabilities */
169 	u_int8_t		ni_esslen;
170 	u_int8_t		ni_essid[IEEE80211_NWID_LEN];
171 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
172 	u_int8_t		*ni_country;	/* country information XXX */
173 	struct ieee80211_channel *ni_chan;
174 	u_int8_t		ni_erp;		/* 11g only */
175 
176 #ifdef notyet
177 	/* DTIM and contention free period (CFP) */
178 	u_int8_t		ni_dtimperiod;
179 	u_int8_t		ni_cfpperiod;	/* # of DTIMs between CFPs */
180 	u_int16_t		ni_cfpduremain;	/* remaining cfp duration */
181 	u_int16_t		ni_cfpmaxduration;/* max CFP duration in TU */
182 	u_int16_t		ni_nextdtim;	/* time to next DTIM */
183 	u_int16_t		ni_timoffset;
184 #endif
185 
186 	/* power saving mode */
187 	u_int8_t		ni_pwrsave;
188 	struct ifqueue		ni_savedq;	/* packets queued for pspoll */
189 
190 	/* RSN */
191 	struct timeout		ni_eapol_to;
192 	u_int			ni_rsn_state;
193 	u_int			ni_rsn_gstate;
194 	u_int			ni_rsn_retries;
195 	u_int			ni_rsnprotos;
196 	u_int			ni_rsnakms;
197 	u_int			ni_rsnciphers;
198 	enum ieee80211_cipher	ni_rsngroupcipher;
199 	enum ieee80211_cipher	ni_rsngroupmgmtcipher;
200 	u_int16_t		ni_rsncaps;
201 	enum ieee80211_cipher	ni_rsncipher;
202 	u_int8_t		ni_nonce[EAPOL_KEY_NONCE_LEN];
203 	u_int8_t		ni_pmk[IEEE80211_PMK_LEN];
204 	u_int8_t		ni_pmkid[IEEE80211_PMKID_LEN];
205 	u_int64_t		ni_replaycnt;
206 	u_int8_t		ni_replaycnt_ok;
207 	u_int64_t		ni_reqreplaycnt;
208 	u_int8_t		ni_reqreplaycnt_ok;
209 	u_int8_t		*ni_rsnie;
210 	struct ieee80211_key	ni_pairwise_key;
211 	struct ieee80211_ptk	ni_ptk;
212 	u_int8_t		ni_key_count;
213 	int			ni_port_valid;
214 
215 	/* SA Query */
216 	u_int16_t		ni_sa_query_trid;
217 	struct timeout		ni_sa_query_to;
218 	int			ni_sa_query_count;
219 
220 	/* Block Ack records */
221 	struct ieee80211_tx_ba	ni_tx_ba[IEEE80211_NUM_TID];
222 	struct ieee80211_rx_ba	ni_rx_ba[IEEE80211_NUM_TID];
223 
224 	/* others */
225 	u_int16_t		ni_associd;	/* assoc response */
226 	u_int16_t		ni_txseq;	/* seq to be transmitted */
227 	u_int16_t		ni_rxseq;	/* seq previous received */
228 	u_int16_t		ni_qos_txseqs[IEEE80211_NUM_TID];
229 	u_int16_t		ni_qos_rxseqs[IEEE80211_NUM_TID];
230 	int			ni_fails;	/* failure count to associate */
231 	int			ni_inact;	/* inactivity mark count */
232 	int			ni_txrate;	/* index to ni_rates[] */
233 	int			ni_state;
234 
235 	u_int16_t		ni_flags;	/* special-purpose state */
236 #define IEEE80211_NODE_ERP		0x0001
237 #define IEEE80211_NODE_QOS		0x0002
238 #define IEEE80211_NODE_REKEY		0x0004	/* GTK rekeying in progress */
239 #define IEEE80211_NODE_RXPROT		0x0008	/* RX protection ON */
240 #define IEEE80211_NODE_TXPROT		0x0010	/* TX protection ON */
241 #define IEEE80211_NODE_TXRXPROT	\
242 	(IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT)
243 #define IEEE80211_NODE_RXMGMTPROT	0x0020	/* RX MMPDU protection ON */
244 #define IEEE80211_NODE_TXMGMTPROT	0x0040	/* TX MMPDU protection ON */
245 #define IEEE80211_NODE_MFP		0x0080	/* MFP negotiated */
246 #define IEEE80211_NODE_PMK		0x0100	/* ni_pmk set */
247 #define IEEE80211_NODE_PMKID		0x0200	/* ni_pmkid set */
248 #define IEEE80211_NODE_HT		0x0400	/* HT negotiated */
249 #define IEEE80211_NODE_SA_QUERY		0x0800	/* SA Query in progress */
250 #define IEEE80211_NODE_SA_QUERY_FAILED	0x1000	/* last SA Query failed */
251 };
252 
253 RB_HEAD(ieee80211_tree, ieee80211_node);
254 
255 #define ieee80211_node_incref(ni)			\
256 	do {						\
257 		int _s = splnet();			\
258 		(ni)->ni_refcnt++;			\
259 		splx(_s);				\
260 	} while (0)
261 
262 static __inline int
263 ieee80211_node_decref(struct ieee80211_node *ni)
264 {
265 	int refcnt, s;
266 	s = splnet();
267 	refcnt = --ni->ni_refcnt;
268 	splx(s);
269 	return refcnt;
270 }
271 
272 static __inline struct ieee80211_node *
273 ieee80211_ref_node(struct ieee80211_node *ni)
274 {
275 	ieee80211_node_incref(ni);
276 	return ni;
277 }
278 
279 static __inline void
280 ieee80211_unref_node(struct ieee80211_node **ni)
281 {
282 	ieee80211_node_decref(*ni);
283 	*ni = NULL;			/* guard against use */
284 }
285 
286 struct ieee80211com;
287 
288 #ifdef MALLOC_DECLARE
289 MALLOC_DECLARE(M_80211_NODE);
290 #endif
291 
292 extern	void ieee80211_node_attach(struct ifnet *);
293 extern	void ieee80211_node_lateattach(struct ifnet *);
294 extern	void ieee80211_node_detach(struct ifnet *);
295 
296 extern	void ieee80211_begin_scan(struct ifnet *);
297 extern	void ieee80211_next_scan(struct ifnet *);
298 extern	void ieee80211_end_scan(struct ifnet *);
299 extern	void ieee80211_reset_scan(struct ifnet *);
300 extern	struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *,
301 		const u_int8_t *);
302 extern	struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *,
303 		const u_int8_t *);
304 extern	struct ieee80211_node *ieee80211_find_node(struct ieee80211com *,
305 		const u_int8_t *);
306 extern	struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
307 		const struct ieee80211_frame *);
308 extern	struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
309 		const u_int8_t *);
310 extern	struct ieee80211_node *
311 		ieee80211_find_node_for_beacon(struct ieee80211com *,
312 		const u_int8_t *, const struct ieee80211_channel *,
313 		const char *, u_int8_t);
314 extern	void ieee80211_release_node(struct ieee80211com *,
315 		struct ieee80211_node *);
316 extern	void ieee80211_free_allnodes(struct ieee80211com *);
317 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
318 extern	void ieee80211_iterate_nodes(struct ieee80211com *ic,
319 		ieee80211_iter_func *, void *);
320 extern	void ieee80211_clean_nodes(struct ieee80211com *);
321 extern	int ieee80211_setup_rates(struct ieee80211com *,
322 	    struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int);
323 extern  int ieee80211_iserp_sta(const struct ieee80211_node *);
324 
325 extern	void ieee80211_node_join(struct ieee80211com *,
326 		struct ieee80211_node *, int);
327 extern	void ieee80211_node_leave(struct ieee80211com *,
328 		struct ieee80211_node *);
329 extern	int ieee80211_match_bss(struct ieee80211com *,
330 		struct ieee80211_node *);
331 extern	void ieee80211_create_ibss(struct ieee80211com* ,
332 		struct ieee80211_channel *);
333 extern	void ieee80211_notify_dtim(struct ieee80211com *);
334 
335 extern	int ieee80211_node_cmp(const struct ieee80211_node *,
336 		const struct ieee80211_node *);
337 RB_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp);
338 
339 #endif /* _NET80211_IEEE80211_NODE_H_ */
340