xref: /openbsd-src/sys/net80211/ieee80211_node.h (revision d59bb9942320b767f2a19aaa7690c8c6e30b724c)
1 /*	$OpenBSD: ieee80211_node.h,v 1.67 2017/03/04 12:44:27 stsp 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	30
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 /* Supplicant state machine: 4-Way Handshake (not documented in standard) */
103 enum {
104 	RSNA_SUPP_INITIALIZE,		/* not expecting any messages */
105 	RSNA_SUPP_PTKSTART,		/* awaiting handshake message 1 */
106 	RSNA_SUPP_PTKNEGOTIATING,	/* got message 1 and derived PTK */
107 	RNSA_SUPP_PTKDONE		/* got message 3 and authenticated AP */
108 };
109 
110 struct ieee80211_rxinfo {
111 	u_int32_t		rxi_flags;
112 	u_int32_t		rxi_tstamp;
113 	int			rxi_rssi;
114 };
115 #define IEEE80211_RXI_HWDEC		0x00000001
116 #define IEEE80211_RXI_AMPDU_DONE	0x00000002
117 
118 /* Block Acknowledgement Record */
119 struct ieee80211_tx_ba {
120 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
121 	struct timeout		ba_to;
122 	int			ba_timeout_val;
123 	int			ba_state;
124 #define IEEE80211_BA_INIT	0
125 #define IEEE80211_BA_REQUESTED	1
126 #define IEEE80211_BA_AGREED	2
127 
128 	/* ADDBA parameter set field for this BA agreement. */
129 	u_int16_t		ba_params;
130 
131 	/* These values are IEEE802.11 frame sequence numbers (0x0-0xfff) */
132 	u_int16_t		ba_winstart;
133 	u_int16_t		ba_winend;
134 
135 	/* Number of A-MPDU subframes in reorder buffer. */
136 	u_int16_t		ba_winsize;
137 #define IEEE80211_BA_MAX_WINSZ	64	/* corresponds to maximum ADDBA BUFSZ */
138 
139 	u_int8_t		ba_token;
140 };
141 
142 struct ieee80211_rx_ba {
143 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
144 	struct {
145 		struct mbuf		*m;
146 		struct ieee80211_rxinfo	rxi;
147 	}			*ba_buf;
148 	struct timeout		ba_to;
149 	int			ba_timeout_val;
150 	int			ba_state;
151 	u_int16_t		ba_params;
152 	u_int16_t		ba_winstart;
153 	u_int16_t		ba_winend;
154 	u_int16_t		ba_winsize;
155 	u_int16_t		ba_head;
156 	struct timeout		ba_gap_to;
157 #define IEEE80211_BA_GAP_TIMEOUT	300 /* msec */
158 	/* Counter for consecutive frames which missed the BA window. */
159 	int			ba_winmiss;
160 	/* Sequence number of previous frame which missed the BA window. */
161 	uint16_t		ba_missedsn;
162 	/* Window moves forward after this many frames have missed it. */
163 #define IEEE80211_BA_MAX_WINMISS	8
164 
165 	uint8_t			ba_token;
166 };
167 
168 /*
169  * Node specific information.  Note that drivers are expected
170  * to derive from this structure to add device-specific per-node
171  * state.  This is done by overriding the ic_node_* methods in
172  * the ieee80211com structure.
173  */
174 struct ieee80211_node {
175 	RBT_ENTRY(ieee80211_node)	ni_node;
176 
177 	struct ieee80211com	*ni_ic;		/* back-pointer */
178 
179 	u_int			ni_refcnt;
180 	u_int			ni_scangen;	/* gen# for timeout scan */
181 
182 	/* hardware */
183 	u_int32_t		ni_rstamp;	/* recv timestamp */
184 	u_int8_t		ni_rssi;	/* recv ssi */
185 
186 	/* header */
187 	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
188 	u_int8_t		ni_bssid[IEEE80211_ADDR_LEN];
189 
190 	/* beacon, probe response */
191 	u_int8_t		ni_tstamp[8];	/* from last rcv'd beacon */
192 	u_int16_t		ni_intval;	/* beacon interval */
193 	u_int16_t		ni_capinfo;	/* capabilities */
194 	u_int8_t		ni_esslen;
195 	u_int8_t		ni_essid[IEEE80211_NWID_LEN];
196 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
197 	u_int8_t		*ni_country;	/* country information XXX */
198 	struct ieee80211_channel *ni_chan;
199 	u_int8_t		ni_erp;		/* 11g only */
200 
201 	/* DTIM and contention free period (CFP) */
202 	u_int8_t		ni_dtimcount;
203 	u_int8_t		ni_dtimperiod;
204 #ifdef notyet
205 	u_int8_t		ni_cfpperiod;	/* # of DTIMs between CFPs */
206 	u_int16_t		ni_cfpduremain;	/* remaining cfp duration */
207 	u_int16_t		ni_cfpmaxduration;/* max CFP duration in TU */
208 	u_int16_t		ni_nextdtim;	/* time to next DTIM */
209 	u_int16_t		ni_timoffset;
210 #endif
211 
212 	/* power saving mode */
213 	u_int8_t		ni_pwrsave;
214 	struct mbuf_queue	ni_savedq;	/* packets queued for pspoll */
215 
216 	/* RSN */
217 	struct timeout		ni_eapol_to;
218 	u_int			ni_rsn_state;
219 	u_int			ni_rsn_supp_state;
220 	u_int			ni_rsn_gstate;
221 	u_int			ni_rsn_retries;
222 	u_int			ni_rsnprotos;
223 	u_int			ni_rsnakms;
224 	u_int			ni_rsnciphers;
225 	enum ieee80211_cipher	ni_rsngroupcipher;
226 	enum ieee80211_cipher	ni_rsngroupmgmtcipher;
227 	u_int16_t		ni_rsncaps;
228 	enum ieee80211_cipher	ni_rsncipher;
229 	u_int8_t		ni_nonce[EAPOL_KEY_NONCE_LEN];
230 	u_int8_t		ni_pmk[IEEE80211_PMK_LEN];
231 	u_int8_t		ni_pmkid[IEEE80211_PMKID_LEN];
232 	u_int64_t		ni_replaycnt;
233 	u_int8_t		ni_replaycnt_ok;
234 	u_int64_t		ni_reqreplaycnt;
235 	u_int8_t		ni_reqreplaycnt_ok;
236 	u_int8_t		*ni_rsnie;
237 	struct ieee80211_key	ni_pairwise_key;
238 	struct ieee80211_ptk	ni_ptk;
239 	u_int8_t		ni_key_count;
240 	int			ni_port_valid;
241 
242 	/* SA Query */
243 	u_int16_t		ni_sa_query_trid;
244 	struct timeout		ni_sa_query_to;
245 	int			ni_sa_query_count;
246 
247 	/* HT capabilities */
248 	uint16_t		ni_htcaps;
249 	uint8_t			ni_ampdu_param;
250 	uint8_t			ni_rxmcs[howmany(80,NBBY)];
251 	uint16_t		ni_max_rxrate;	/* in Mb/s, 0 <= rate <= 1023 */
252 	uint8_t			ni_tx_mcs_set;
253 	uint16_t		ni_htxcaps;
254 	uint32_t		ni_txbfcaps;
255 	uint8_t			ni_aselcaps;
256 
257 	/* HT operation */
258 	uint8_t			ni_primary_chan; /* XXX corresponds to ni_chan */
259 	uint8_t			ni_htop0;
260 	uint16_t		ni_htop1;
261 	uint16_t		ni_htop2;
262 	uint8_t			ni_basic_mcs[howmany(128,NBBY)];
263 
264 	/* Block Ack records */
265 	struct ieee80211_tx_ba	ni_tx_ba[IEEE80211_NUM_TID];
266 	struct ieee80211_rx_ba	ni_rx_ba[IEEE80211_NUM_TID];
267 
268 	int			ni_txmcs;	/* current MCS used for TX */
269 
270 	/* others */
271 	u_int16_t		ni_associd;	/* assoc response */
272 	u_int16_t		ni_txseq;	/* seq to be transmitted */
273 	u_int16_t		ni_rxseq;	/* seq previous received */
274 	u_int16_t		ni_qos_txseqs[IEEE80211_NUM_TID];
275 	u_int16_t		ni_qos_rxseqs[IEEE80211_NUM_TID];
276 	int			ni_fails;	/* failure count to associate */
277 	int			ni_inact;	/* inactivity mark count */
278 	int			ni_txrate;	/* index to ni_rates[] */
279 	int			ni_state;
280 
281 	u_int16_t		ni_flags;	/* special-purpose state */
282 #define IEEE80211_NODE_ERP		0x0001
283 #define IEEE80211_NODE_QOS		0x0002
284 #define IEEE80211_NODE_REKEY		0x0004	/* GTK rekeying in progress */
285 #define IEEE80211_NODE_RXPROT		0x0008	/* RX protection ON */
286 #define IEEE80211_NODE_TXPROT		0x0010	/* TX protection ON */
287 #define IEEE80211_NODE_TXRXPROT	\
288 	(IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT)
289 #define IEEE80211_NODE_RXMGMTPROT	0x0020	/* RX MMPDU protection ON */
290 #define IEEE80211_NODE_TXMGMTPROT	0x0040	/* TX MMPDU protection ON */
291 #define IEEE80211_NODE_MFP		0x0080	/* MFP negotiated */
292 #define IEEE80211_NODE_PMK		0x0100	/* ni_pmk set */
293 #define IEEE80211_NODE_PMKID		0x0200	/* ni_pmkid set */
294 #define IEEE80211_NODE_HT		0x0400	/* HT negotiated */
295 #define IEEE80211_NODE_SA_QUERY		0x0800	/* SA Query in progress */
296 #define IEEE80211_NODE_SA_QUERY_FAILED	0x1000	/* last SA Query failed */
297 };
298 
299 RBT_HEAD(ieee80211_tree, ieee80211_node);
300 
301 static __inline void
302 ieee80211_node_incref(struct ieee80211_node *ni)
303 {
304 	int		s;
305 
306 	s = splnet();
307 	ni->ni_refcnt++;
308 	splx(s);
309 }
310 
311 static __inline u_int
312 ieee80211_node_decref(struct ieee80211_node *ni)
313 {
314 	u_int		refcnt;
315 	int 		s;
316 
317 	s = splnet();
318 	refcnt = --ni->ni_refcnt;
319 	splx(s);
320 	return refcnt;
321 }
322 
323 static __inline struct ieee80211_node *
324 ieee80211_ref_node(struct ieee80211_node *ni)
325 {
326 	ieee80211_node_incref(ni);
327 	return ni;
328 }
329 
330 static __inline void
331 ieee80211_unref_node(struct ieee80211_node **ni)
332 {
333 	ieee80211_node_decref(*ni);
334 	*ni = NULL;			/* guard against use */
335 }
336 
337 struct ieee80211com;
338 
339 #ifdef MALLOC_DECLARE
340 MALLOC_DECLARE(M_80211_NODE);
341 #endif
342 
343 extern	void ieee80211_node_attach(struct ifnet *);
344 extern	void ieee80211_node_lateattach(struct ifnet *);
345 extern	void ieee80211_node_detach(struct ifnet *);
346 
347 extern	void ieee80211_begin_scan(struct ifnet *);
348 extern	void ieee80211_next_scan(struct ifnet *);
349 extern	void ieee80211_end_scan(struct ifnet *);
350 extern	void ieee80211_reset_scan(struct ifnet *);
351 extern	struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *,
352 		const u_int8_t *);
353 extern	struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *,
354 		const u_int8_t *);
355 extern	struct ieee80211_node *ieee80211_find_node(struct ieee80211com *,
356 		const u_int8_t *);
357 extern	struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
358 		const struct ieee80211_frame *);
359 extern	struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
360 		const u_int8_t *);
361 extern	struct ieee80211_node *
362 		ieee80211_find_node_for_beacon(struct ieee80211com *,
363 		const u_int8_t *, const struct ieee80211_channel *,
364 		const char *, u_int8_t);
365 extern	void ieee80211_release_node(struct ieee80211com *,
366 		struct ieee80211_node *);
367 extern	void ieee80211_free_allnodes(struct ieee80211com *);
368 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
369 extern	void ieee80211_iterate_nodes(struct ieee80211com *ic,
370 		ieee80211_iter_func *, void *);
371 extern	void ieee80211_clean_cached(struct ieee80211com *ic);
372 extern	void ieee80211_clean_nodes(struct ieee80211com *, int);
373 void ieee80211_setup_htcaps(struct ieee80211_node *, const uint8_t *,
374     uint8_t);
375 void ieee80211_clear_htcaps(struct ieee80211_node *);
376 int ieee80211_setup_htop(struct ieee80211_node *, const uint8_t *,
377     uint8_t);
378 extern	int ieee80211_setup_rates(struct ieee80211com *,
379 	    struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int);
380 extern  int ieee80211_iserp_sta(const struct ieee80211_node *);
381 extern void ieee80211_count_longslotsta(void *, struct ieee80211_node *);
382 extern void ieee80211_count_nonerpsta(void *, struct ieee80211_node *);
383 extern void ieee80211_count_pssta(void *, struct ieee80211_node *);
384 extern void ieee80211_count_rekeysta(void *, struct ieee80211_node *);
385 extern	void ieee80211_node_join(struct ieee80211com *,
386 		struct ieee80211_node *, int);
387 extern	void ieee80211_node_leave(struct ieee80211com *,
388 		struct ieee80211_node *);
389 extern	int ieee80211_match_bss(struct ieee80211com *,
390 		struct ieee80211_node *);
391 extern	void ieee80211_create_ibss(struct ieee80211com* ,
392 		struct ieee80211_channel *);
393 extern	void ieee80211_notify_dtim(struct ieee80211com *);
394 extern	void ieee80211_set_tim(struct ieee80211com *, int, int);
395 
396 extern	int ieee80211_node_cmp(const struct ieee80211_node *,
397 		const struct ieee80211_node *);
398 RBT_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp);
399 
400 #endif /* _NET80211_IEEE80211_NODE_H_ */
401