xref: /openbsd/sys/net80211/ieee80211_node.h (revision a6445c1d)
1 /*	$OpenBSD: ieee80211_node.h,v 1.46 2014/09/12 16:02:40 sthen 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 #include <sys/tree.h>
37 
38 #define	IEEE80211_PSCAN_WAIT	5		/* passive scan wait */
39 #define	IEEE80211_TRANS_WAIT	5		/* transition wait */
40 #define	IEEE80211_INACT_WAIT	5		/* inactivity timer interval */
41 #define	IEEE80211_INACT_MAX	(300/IEEE80211_INACT_WAIT)
42 #define	IEEE80211_CACHE_SIZE	100
43 #define	IEEE80211_CACHE_WAIT	3600
44 
45 struct ieee80211_rateset {
46 	u_int8_t		rs_nrates;
47 	u_int8_t		rs_rates[IEEE80211_RATE_MAXSIZE];
48 };
49 
50 extern const struct ieee80211_rateset ieee80211_std_rateset_11a;
51 extern const struct ieee80211_rateset ieee80211_std_rateset_11b;
52 extern const struct ieee80211_rateset ieee80211_std_rateset_11g;
53 
54 enum ieee80211_node_state {
55 	IEEE80211_STA_CACHE,	/* cached node */
56 	IEEE80211_STA_BSS,	/* ic->ic_bss, the network we joined */
57 	IEEE80211_STA_AUTH,	/* successfully authenticated */
58 	IEEE80211_STA_ASSOC,	/* successfully associated */
59 	IEEE80211_STA_COLLECT	/* This node remains in the cache while
60 				 * the driver sends a de-auth message;
61 				 * afterward it should be freed to make room
62 				 * for a new node.
63 				 */
64 };
65 
66 #define	ieee80211_node_newstate(__ni, __state)	\
67 	do {					\
68 		(__ni)->ni_state = (__state);	\
69 	} while (0)
70 
71 enum ieee80211_node_psstate {
72 	IEEE80211_PS_AWAKE,
73 	IEEE80211_PS_DOZE
74 };
75 
76 #define	IEEE80211_PS_MAX_QUEUE	50	/* maximum saved packets */
77 
78 /* Authenticator state machine: 4-Way Handshake (see 8.5.6.1.1) */
79 enum {
80 	RSNA_INITIALIZE,
81 	RSNA_AUTHENTICATION,
82 	RSNA_AUTHENTICATION_2,
83 	RSNA_INITPMK,
84 	RSNA_INITPSK,
85 	RSNA_PTKSTART,
86 	RSNA_PTKCALCNEGOTIATING,
87 	RSNA_PTKCALCNEGOTIATING_2,
88 	RSNA_PTKINITNEGOTIATING,
89 	RSNA_PTKINITDONE,
90 	RSNA_DISCONNECT,
91 	RSNA_DISCONNECTED
92 };
93 
94 /* Authenticator state machine: Group Key Handshake (see 8.5.6.1.2) */
95 enum {
96 	RSNA_IDLE,
97 	RSNA_REKEYNEGOTIATING,
98 	RSNA_REKEYESTABLISHED,
99 	RSNA_KEYERROR
100 };
101 
102 struct ieee80211_rxinfo {
103 	u_int32_t		rxi_flags;
104 	u_int32_t		rxi_tstamp;
105 	int			rxi_rssi;
106 };
107 #define IEEE80211_RXI_HWDEC		0x00000001
108 #define IEEE80211_RXI_AMPDU_DONE	0x00000002
109 
110 /* Block Acknowledgement Record */
111 struct ieee80211_tx_ba {
112 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
113 	struct timeout		ba_to;
114 	int			ba_timeout_val;
115 #define IEEE80211_BA_MIN_TIMEOUT	(10 * 1000)		/* 10msec */
116 #define IEEE80211_BA_MAX_TIMEOUT	(10 * 1000 * 1000)	/* 10sec */
117 
118 	int			ba_state;
119 #define IEEE80211_BA_INIT	0
120 #define IEEE80211_BA_REQUESTED	1
121 #define IEEE80211_BA_AGREED	2
122 
123 	u_int16_t		ba_winstart;
124 	u_int16_t		ba_winend;
125 	u_int16_t		ba_winsize;
126 #define IEEE80211_BA_MAX_WINSZ	128	/* maximum we will accept */
127 
128 	u_int8_t		ba_token;
129 };
130 
131 struct ieee80211_rx_ba {
132 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
133 	struct {
134 		struct mbuf		*m;
135 		struct ieee80211_rxinfo	rxi;
136 	}			*ba_buf;
137 	struct timeout		ba_to;
138 	int			ba_timeout_val;
139 	int			ba_state;
140 	u_int16_t		ba_winstart;
141 	u_int16_t		ba_winend;
142 	u_int16_t		ba_winsize;
143 	u_int16_t		ba_head;
144 };
145 
146 /*
147  * Node specific information.  Note that drivers are expected
148  * to derive from this structure to add device-specific per-node
149  * state.  This is done by overriding the ic_node_* methods in
150  * the ieee80211com structure.
151  */
152 struct ieee80211_node {
153 	RB_ENTRY(ieee80211_node)	ni_node;
154 
155 	struct ieee80211com	*ni_ic;		/* back-pointer */
156 
157 	u_int			ni_refcnt;
158 	u_int			ni_scangen;	/* gen# for timeout scan */
159 
160 	/* hardware */
161 	u_int32_t		ni_rstamp;	/* recv timestamp */
162 	u_int8_t		ni_rssi;	/* recv ssi */
163 
164 	/* header */
165 	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
166 	u_int8_t		ni_bssid[IEEE80211_ADDR_LEN];
167 
168 	/* beacon, probe response */
169 	u_int8_t		ni_tstamp[8];	/* from last rcv'd beacon */
170 	u_int16_t		ni_intval;	/* beacon interval */
171 	u_int16_t		ni_capinfo;	/* capabilities */
172 	u_int8_t		ni_esslen;
173 	u_int8_t		ni_essid[IEEE80211_NWID_LEN];
174 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
175 	u_int8_t		*ni_country;	/* country information XXX */
176 	struct ieee80211_channel *ni_chan;
177 	u_int8_t		ni_erp;		/* 11g only */
178 
179 #ifdef notyet
180 	/* DTIM and contention free period (CFP) */
181 	u_int8_t		ni_dtimperiod;
182 	u_int8_t		ni_cfpperiod;	/* # of DTIMs between CFPs */
183 	u_int16_t		ni_cfpduremain;	/* remaining cfp duration */
184 	u_int16_t		ni_cfpmaxduration;/* max CFP duration in TU */
185 	u_int16_t		ni_nextdtim;	/* time to next DTIM */
186 	u_int16_t		ni_timoffset;
187 #endif
188 
189 	/* power saving mode */
190 	u_int8_t		ni_pwrsave;
191 	struct ifqueue		ni_savedq;	/* packets queued for pspoll */
192 
193 	/* RSN */
194 	struct timeout		ni_eapol_to;
195 	u_int			ni_rsn_state;
196 	u_int			ni_rsn_gstate;
197 	u_int			ni_rsn_retries;
198 	u_int			ni_rsnprotos;
199 	u_int			ni_rsnakms;
200 	u_int			ni_rsnciphers;
201 	enum ieee80211_cipher	ni_rsngroupcipher;
202 	enum ieee80211_cipher	ni_rsngroupmgmtcipher;
203 	u_int16_t		ni_rsncaps;
204 	enum ieee80211_cipher	ni_rsncipher;
205 	u_int8_t		ni_nonce[EAPOL_KEY_NONCE_LEN];
206 	u_int8_t		ni_pmk[IEEE80211_PMK_LEN];
207 	u_int8_t		ni_pmkid[IEEE80211_PMKID_LEN];
208 	u_int64_t		ni_replaycnt;
209 	u_int8_t		ni_replaycnt_ok;
210 	u_int64_t		ni_reqreplaycnt;
211 	u_int8_t		ni_reqreplaycnt_ok;
212 	u_int8_t		*ni_rsnie;
213 	struct ieee80211_key	ni_pairwise_key;
214 	struct ieee80211_ptk	ni_ptk;
215 	u_int8_t		ni_key_count;
216 	int			ni_port_valid;
217 
218 	/* SA Query */
219 	u_int16_t		ni_sa_query_trid;
220 	struct timeout		ni_sa_query_to;
221 	int			ni_sa_query_count;
222 
223 	/* Block Ack records */
224 	struct ieee80211_tx_ba	ni_tx_ba[IEEE80211_NUM_TID];
225 	struct ieee80211_rx_ba	ni_rx_ba[IEEE80211_NUM_TID];
226 
227 	/* others */
228 	u_int16_t		ni_associd;	/* assoc response */
229 	u_int16_t		ni_txseq;	/* seq to be transmitted */
230 	u_int16_t		ni_rxseq;	/* seq previous received */
231 	u_int16_t		ni_qos_txseqs[IEEE80211_NUM_TID];
232 	u_int16_t		ni_qos_rxseqs[IEEE80211_NUM_TID];
233 	int			ni_fails;	/* failure count to associate */
234 	int			ni_inact;	/* inactivity mark count */
235 	int			ni_txrate;	/* index to ni_rates[] */
236 	int			ni_state;
237 
238 	u_int16_t		ni_flags;	/* special-purpose state */
239 #define IEEE80211_NODE_ERP		0x0001
240 #define IEEE80211_NODE_QOS		0x0002
241 #define IEEE80211_NODE_REKEY		0x0004	/* GTK rekeying in progress */
242 #define IEEE80211_NODE_RXPROT		0x0008	/* RX protection ON */
243 #define IEEE80211_NODE_TXPROT		0x0010	/* TX protection ON */
244 #define IEEE80211_NODE_TXRXPROT	\
245 	(IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT)
246 #define IEEE80211_NODE_RXMGMTPROT	0x0020	/* RX MMPDU protection ON */
247 #define IEEE80211_NODE_TXMGMTPROT	0x0040	/* TX MMPDU protection ON */
248 #define IEEE80211_NODE_MFP		0x0080	/* MFP negotiated */
249 #define IEEE80211_NODE_PMK		0x0100	/* ni_pmk set */
250 #define IEEE80211_NODE_PMKID		0x0200	/* ni_pmkid set */
251 #define IEEE80211_NODE_HT		0x0400	/* HT negotiated */
252 #define IEEE80211_NODE_SA_QUERY		0x0800	/* SA Query in progress */
253 #define IEEE80211_NODE_SA_QUERY_FAILED	0x1000	/* last SA Query failed */
254 };
255 
256 RB_HEAD(ieee80211_tree, ieee80211_node);
257 
258 static __inline void
259 ieee80211_node_incref(struct ieee80211_node *ni)
260 {
261 	int		s;
262 
263 	s = splnet();
264 	ni->ni_refcnt++;
265 	splx(s);
266 }
267 
268 static __inline u_int
269 ieee80211_node_decref(struct ieee80211_node *ni)
270 {
271 	u_int		refcnt;
272 	int 		s;
273 
274 	s = splnet();
275 	refcnt = --ni->ni_refcnt;
276 	splx(s);
277 	return refcnt;
278 }
279 
280 static __inline struct ieee80211_node *
281 ieee80211_ref_node(struct ieee80211_node *ni)
282 {
283 	ieee80211_node_incref(ni);
284 	return ni;
285 }
286 
287 static __inline void
288 ieee80211_unref_node(struct ieee80211_node **ni)
289 {
290 	ieee80211_node_decref(*ni);
291 	*ni = NULL;			/* guard against use */
292 }
293 
294 struct ieee80211com;
295 
296 #ifdef MALLOC_DECLARE
297 MALLOC_DECLARE(M_80211_NODE);
298 #endif
299 
300 extern	void ieee80211_node_attach(struct ifnet *);
301 extern	void ieee80211_node_lateattach(struct ifnet *);
302 extern	void ieee80211_node_detach(struct ifnet *);
303 
304 extern	void ieee80211_begin_scan(struct ifnet *);
305 extern	void ieee80211_next_scan(struct ifnet *);
306 extern	void ieee80211_end_scan(struct ifnet *);
307 extern	void ieee80211_reset_scan(struct ifnet *);
308 extern	struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *,
309 		const u_int8_t *);
310 extern	struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *,
311 		const u_int8_t *);
312 extern	struct ieee80211_node *ieee80211_find_node(struct ieee80211com *,
313 		const u_int8_t *);
314 extern	struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
315 		const struct ieee80211_frame *);
316 extern	struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
317 		const u_int8_t *);
318 extern	struct ieee80211_node *
319 		ieee80211_find_node_for_beacon(struct ieee80211com *,
320 		const u_int8_t *, const struct ieee80211_channel *,
321 		const char *, u_int8_t);
322 extern	void ieee80211_release_node(struct ieee80211com *,
323 		struct ieee80211_node *);
324 extern	void ieee80211_free_allnodes(struct ieee80211com *);
325 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
326 extern	void ieee80211_iterate_nodes(struct ieee80211com *ic,
327 		ieee80211_iter_func *, void *);
328 extern	void ieee80211_clean_cached(struct ieee80211com *ic);
329 extern	void ieee80211_clean_nodes(struct ieee80211com *, int);
330 extern	int ieee80211_setup_rates(struct ieee80211com *,
331 	    struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int);
332 extern  int ieee80211_iserp_sta(const struct ieee80211_node *);
333 
334 extern	void ieee80211_node_join(struct ieee80211com *,
335 		struct ieee80211_node *, int);
336 extern	void ieee80211_node_leave(struct ieee80211com *,
337 		struct ieee80211_node *);
338 extern	int ieee80211_match_bss(struct ieee80211com *,
339 		struct ieee80211_node *);
340 extern	void ieee80211_create_ibss(struct ieee80211com* ,
341 		struct ieee80211_channel *);
342 extern	void ieee80211_notify_dtim(struct ieee80211com *);
343 extern	void ieee80211_set_tim(struct ieee80211com *, int, int);
344 
345 extern	int ieee80211_node_cmp(const struct ieee80211_node *,
346 		const struct ieee80211_node *);
347 RB_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp);
348 
349 #endif /* _NET80211_IEEE80211_NODE_H_ */
350