xref: /openbsd-src/sys/net80211/ieee80211_node.h (revision 850e275390052b330d93020bf619a739a3c277ac)
1 /*	$OpenBSD: ieee80211_node.h,v 1.33 2008/09/27 15:16:09 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 /*
100  * Node specific information.  Note that drivers are expected
101  * to derive from this structure to add device-specific per-node
102  * state.  This is done by overriding the ic_node_* methods in
103  * the ieee80211com structure.
104  */
105 struct ieee80211_node {
106 	RB_ENTRY(ieee80211_node)	ni_node;
107 
108 	struct ieee80211com	*ni_ic;		/* back-pointer */
109 
110 	u_int			ni_refcnt;
111 	u_int			ni_scangen;	/* gen# for timeout scan */
112 
113 	/* hardware */
114 	u_int32_t		ni_rstamp;	/* recv timestamp */
115 	u_int8_t		ni_rssi;	/* recv ssi */
116 
117 	/* header */
118 	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
119 	u_int8_t		ni_bssid[IEEE80211_ADDR_LEN];
120 
121 	/* beacon, probe response */
122 	u_int8_t		ni_tstamp[8];	/* from last rcv'd beacon */
123 	u_int16_t		ni_intval;	/* beacon interval */
124 	u_int16_t		ni_capinfo;	/* capabilities */
125 	u_int8_t		ni_esslen;
126 	u_int8_t		ni_essid[IEEE80211_NWID_LEN];
127 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
128 	u_int8_t		*ni_country;	/* country information XXX */
129 	struct ieee80211_channel *ni_chan;
130 	u_int8_t		ni_erp;		/* 11g only */
131 
132 #ifdef notyet
133 	/* DTIM and contention free period (CFP) */
134 	u_int8_t		ni_dtimperiod;
135 	u_int8_t		ni_cfpperiod;	/* # of DTIMs between CFPs */
136 	u_int16_t		ni_cfpduremain;	/* remaining cfp duration */
137 	u_int16_t		ni_cfpmaxduration;/* max CFP duration in TU */
138 	u_int16_t		ni_nextdtim;	/* time to next DTIM */
139 	u_int16_t		ni_timoffset;
140 #endif
141 
142 	/* power saving mode */
143 	u_int8_t		ni_pwrsave;
144 	struct ifqueue		ni_savedq;	/* packets queued for pspoll */
145 
146 	/* RSN */
147 	u_int			ni_rsn_state;
148 	u_int			ni_rsn_gstate;
149 	u_int			ni_rsn_retries;
150 	struct timeout		ni_rsn_timeout;
151 	u_int			ni_rsnprotos;
152 	u_int			ni_rsnakms;
153 	u_int			ni_rsnciphers;
154 	enum ieee80211_cipher	ni_rsngroupcipher;
155 	enum ieee80211_cipher	ni_rsngroupmgmtcipher;
156 	u_int16_t		ni_rsncaps;
157 	enum ieee80211_cipher	ni_rsncipher;
158 	u_int8_t		ni_nonce[EAPOL_KEY_NONCE_LEN];
159 	u_int8_t		ni_pmk[IEEE80211_PMK_LEN];
160 	u_int8_t		ni_pmkid[IEEE80211_PMKID_LEN];
161 	u_int64_t		ni_replaycnt;
162 	u_int8_t		ni_replaycnt_ok;
163 	u_int64_t		ni_reqreplaycnt;
164 	u_int8_t		ni_reqreplaycnt_ok;
165 	u_int8_t		*ni_rsnie;
166 	struct ieee80211_key	ni_pairwise_key;
167 	struct ieee80211_ptk	ni_ptk;
168 	u_int8_t		ni_key_count;
169 	int			ni_port_valid;
170 
171 	/* others */
172 	u_int16_t		ni_associd;	/* assoc response */
173 	u_int16_t		ni_txseq;	/* seq to be transmitted */
174 	u_int16_t		ni_rxseq;	/* seq previous received */
175 	u_int16_t		ni_qos_txseqs[IEEE80211_NUM_TID];
176 	u_int16_t		ni_qos_rxseqs[IEEE80211_NUM_TID];
177 	int			ni_fails;	/* failure count to associate */
178 	int			ni_inact;	/* inactivity mark count */
179 	int			ni_txrate;	/* index to ni_rates[] */
180 	int			ni_state;
181 
182 	u_int16_t		ni_flags;	/* special-purpose state */
183 #define IEEE80211_NODE_ERP		0x0001
184 #define IEEE80211_NODE_QOS		0x0002
185 #define IEEE80211_NODE_REKEY		0x0004	/* GTK rekeying in progress */
186 #define IEEE80211_NODE_RXPROT		0x0008	/* RX protection ON */
187 #define IEEE80211_NODE_TXPROT		0x0010	/* TX protection ON */
188 #define IEEE80211_NODE_TXRXPROT	\
189 	(IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT)
190 #define IEEE80211_NODE_RXMGMTPROT	0x0020	/* RX MMPDU protection ON */
191 #define IEEE80211_NODE_TXMGMTPROT	0x0040	/* TX MMPDU protection ON */
192 #define IEEE80211_NODE_MFP		0x0080	/* MFP negotiated */
193 #define IEEE80211_NODE_PMK		0x0100	/* ni_pmk set */
194 #define IEEE80211_NODE_PMKID		0x0200	/* ni_pmkid set */
195 };
196 
197 RB_HEAD(ieee80211_tree, ieee80211_node);
198 
199 #define ieee80211_node_incref(ni)			\
200 	do {						\
201 		int _s = splnet();			\
202 		(ni)->ni_refcnt++;			\
203 		splx(_s);				\
204 	} while (0)
205 
206 static __inline int
207 ieee80211_node_decref(struct ieee80211_node *ni)
208 {
209 	int refcnt, s;
210 	s = splnet();
211 	refcnt = --ni->ni_refcnt;
212 	splx(s);
213 	return refcnt;
214 }
215 
216 static __inline struct ieee80211_node *
217 ieee80211_ref_node(struct ieee80211_node *ni)
218 {
219 	ieee80211_node_incref(ni);
220 	return ni;
221 }
222 
223 static __inline void
224 ieee80211_unref_node(struct ieee80211_node **ni)
225 {
226 	ieee80211_node_decref(*ni);
227 	*ni = NULL;			/* guard against use */
228 }
229 
230 struct ieee80211com;
231 
232 #ifdef MALLOC_DECLARE
233 MALLOC_DECLARE(M_80211_NODE);
234 #endif
235 
236 extern	void ieee80211_node_attach(struct ifnet *);
237 extern	void ieee80211_node_lateattach(struct ifnet *);
238 extern	void ieee80211_node_detach(struct ifnet *);
239 
240 extern	void ieee80211_begin_scan(struct ifnet *);
241 extern	void ieee80211_next_scan(struct ifnet *);
242 extern	void ieee80211_end_scan(struct ifnet *);
243 extern	void ieee80211_reset_scan(struct ifnet *);
244 extern	struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *,
245 		const u_int8_t *);
246 extern	struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *,
247 		const u_int8_t *);
248 extern	struct ieee80211_node *ieee80211_find_node(struct ieee80211com *,
249 		const u_int8_t *);
250 extern	struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
251 		const struct ieee80211_frame *);
252 extern	struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
253 		const u_int8_t *);
254 extern	struct ieee80211_node *
255 		ieee80211_find_node_for_beacon(struct ieee80211com *,
256 		const u_int8_t *, const struct ieee80211_channel *,
257 		const char *, u_int8_t);
258 extern	void ieee80211_release_node(struct ieee80211com *,
259 		struct ieee80211_node *);
260 extern	void ieee80211_free_allnodes(struct ieee80211com *);
261 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
262 extern	void ieee80211_iterate_nodes(struct ieee80211com *ic,
263 		ieee80211_iter_func *, void *);
264 extern	void ieee80211_clean_nodes(struct ieee80211com *);
265 extern	int ieee80211_setup_rates(struct ieee80211com *,
266 	    struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int);
267 extern  int ieee80211_iserp_sta(const struct ieee80211_node *);
268 
269 extern	void ieee80211_node_join(struct ieee80211com *,
270 		struct ieee80211_node *, int);
271 extern	void ieee80211_node_leave(struct ieee80211com *,
272 		struct ieee80211_node *);
273 extern	int ieee80211_match_bss(struct ieee80211com *,
274 		struct ieee80211_node *);
275 extern	void ieee80211_create_ibss(struct ieee80211com* ,
276 		struct ieee80211_channel *);
277 
278 extern	int ieee80211_node_cmp(const struct ieee80211_node *,
279 		const struct ieee80211_node *);
280 RB_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp);
281 
282 #endif /* _NET80211_IEEE80211_NODE_H_ */
283