]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net80211/ieee80211_node.h
o widen ni_flags as it's going to be full shortly
[FreeBSD/FreeBSD.git] / sys / net80211 / ieee80211_node.h
1 /*-
2  * Copyright (c) 2001 Atsushi Onoe
3  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef _NET80211_IEEE80211_NODE_H_
29 #define _NET80211_IEEE80211_NODE_H_
30
31 #include <net80211/ieee80211_ioctl.h>           /* for ieee80211_nodestats */
32 #include <net80211/ieee80211_ht.h>              /* for aggregation state */
33
34 /*
35  * Each ieee80211com instance has a single timer that fires every
36  * IEEE80211_INACT_WAIT seconds to handle "inactivity processing".
37  * This is used to do node inactivity processing when operating
38  * as an AP or in adhoc mode.  For inactivity processing each node
39  * has a timeout set in it's ni_inact field that is decremented
40  * on each timeout and the node is reclaimed when the counter goes
41  * to zero.  We use different inactivity timeout values depending
42  * on whether the node is associated and authorized (either by
43  * 802.1x or open/shared key authentication) or associated but yet
44  * to be authorized.  The latter timeout is shorter to more aggressively
45  * reclaim nodes that leave part way through the 802.1x exchange.
46  */
47 #define IEEE80211_INACT_WAIT    15              /* inactivity interval (secs) */
48 #define IEEE80211_INACT_INIT    (30/IEEE80211_INACT_WAIT)       /* initial */
49 #define IEEE80211_INACT_AUTH    (180/IEEE80211_INACT_WAIT)      /* associated but not authorized */
50 #define IEEE80211_INACT_RUN     (300/IEEE80211_INACT_WAIT)      /* authorized */
51 #define IEEE80211_INACT_PROBE   (30/IEEE80211_INACT_WAIT)       /* probe */
52 #define IEEE80211_INACT_SCAN    (300/IEEE80211_INACT_WAIT)      /* scanned */
53
54 #define IEEE80211_TRANS_WAIT    2               /* mgt frame tx timer (secs) */
55
56 /* threshold for aging overlapping non-ERP bss */
57 #define IEEE80211_NONERP_PRESENT_AGE    msecs_to_ticks(60*1000)
58
59 #define IEEE80211_NODE_HASHSIZE 32
60 /* simple hash is enough for variation of macaddr */
61 #define IEEE80211_NODE_HASH(addr)       \
62         (((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
63                 IEEE80211_NODE_HASHSIZE)
64
65 struct ieee80211_node_table;
66 struct ieee80211com;
67 struct ieee80211vap;
68
69 /*
70  * Information element ``blob''.  We use this structure
71  * to capture management frame payloads that need to be
72  * retained.  Information elemnts within the payload that
73  * we need to consult have references recorded.
74  */
75 struct ieee80211_ies {
76         /* the following are either NULL or point within data */
77         uint8_t *wpa_ie;        /* captured WPA ie */
78         uint8_t *rsn_ie;        /* captured RSN ie */
79         uint8_t *wme_ie;        /* captured WME ie */
80         uint8_t *ath_ie;        /* captured Atheros ie */
81         uint8_t *htcap_ie;      /* captured HTCAP ie */
82         uint8_t *htinfo_ie;     /* captured HTINFO ie */
83         /* NB: these must be the last members of this structure */
84         uint8_t *data;          /* frame data > 802.11 header */
85         int     len;            /* data size in bytes */
86 };
87
88 /*
89  * Node specific information.  Note that drivers are expected
90  * to derive from this structure to add device-specific per-node
91  * state.  This is done by overriding the ic_node_* methods in
92  * the ieee80211com structure.
93  */
94 struct ieee80211_node {
95         struct ieee80211vap     *ni_vap;        /* associated vap */
96         struct ieee80211com     *ni_ic;         /* copy from vap to save deref*/
97         struct ieee80211_node_table *ni_table;  /* NB: may be NULL */
98         TAILQ_ENTRY(ieee80211_node) ni_list;    /* list of all nodes */
99         LIST_ENTRY(ieee80211_node) ni_hash;     /* hash collision list */
100         u_int                   ni_refcnt;      /* count of held references */
101         u_int                   ni_scangen;     /* gen# for timeout scan */
102         u_int                   ni_flags;
103 #define IEEE80211_NODE_AUTH     0x000001        /* authorized for data */
104 #define IEEE80211_NODE_QOS      0x000002        /* QoS enabled */
105 #define IEEE80211_NODE_ERP      0x000004        /* ERP enabled */
106 /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
107 #define IEEE80211_NODE_PWR_MGT  0x000010        /* power save mode enabled */
108 #define IEEE80211_NODE_AREF     0x000020        /* authentication ref held */
109 #define IEEE80211_NODE_HT       0x000040        /* HT enabled */
110 #define IEEE80211_NODE_HTCOMPAT 0x000080        /* HT setup w/ vendor OUI's */
111 #define IEEE80211_NODE_WPS      0x000100        /* WPS association */
112 #define IEEE80211_NODE_TSN      0x000200        /* TSN association */
113 #define IEEE80211_NODE_AMPDU_RX 0x000400        /* AMPDU rx enabled */
114 #define IEEE80211_NODE_AMPDU_TX 0x000800        /* AMPDU tx enabled */
115         uint16_t                ni_associd;     /* association ID */
116         uint16_t                ni_vlan;        /* vlan tag */
117         uint16_t                ni_txpower;     /* current transmit power */
118         uint8_t                 ni_authmode;    /* authentication algorithm */
119         uint8_t                 ni_ath_flags;   /* Atheros feature flags */
120         /* NB: These must have the same values as IEEE80211_ATHC_* */
121 #define IEEE80211_NODE_TURBOP   0x0001          /* Turbo prime enable */
122 #define IEEE80211_NODE_COMP     0x0002          /* Compresssion enable */
123 #define IEEE80211_NODE_FF       0x0004          /* Fast Frame capable */
124 #define IEEE80211_NODE_XR       0x0008          /* Atheros WME enable */
125 #define IEEE80211_NODE_AR       0x0010          /* AR capable */
126 #define IEEE80211_NODE_BOOST    0x0080          /* Dynamic Turbo boosted */
127         uint16_t                ni_ath_defkeyix;/* Atheros def key index */
128         const struct ieee80211_txparam *ni_txparms;
129         uint32_t                ni_jointime;    /* time of join (secs) */
130         uint32_t                *ni_challenge;  /* shared-key challenge */
131         struct ieee80211_ies    ni_ies;         /* captured ie's */
132                                                 /* tx seq per-tid */
133         uint16_t                ni_txseqs[IEEE80211_TID_SIZE];
134                                                 /* rx seq previous per-tid*/
135         uint16_t                ni_rxseqs[IEEE80211_TID_SIZE];
136         uint32_t                ni_rxfragstamp; /* time stamp of last rx frag */
137         struct mbuf             *ni_rxfrag[3];  /* rx frag reassembly */
138         struct ieee80211_key    ni_ucastkey;    /* unicast key */
139
140         /* hardware */
141         uint32_t                ni_rstamp;      /* recv timestamp */
142         uint32_t                ni_avgrssi;     /* recv ssi state */
143         int8_t                  ni_noise;       /* noise floor */
144
145         /* header */
146         uint8_t                 ni_macaddr[IEEE80211_ADDR_LEN];
147         uint8_t                 ni_bssid[IEEE80211_ADDR_LEN];
148
149         /* beacon, probe response */
150         union {
151                 uint8_t         data[8];
152                 u_int64_t       tsf;
153         } ni_tstamp;                            /* from last rcv'd beacon */
154         uint16_t                ni_intval;      /* beacon interval */
155         uint16_t                ni_capinfo;     /* capabilities */
156         uint8_t                 ni_esslen;
157         uint8_t                 ni_essid[IEEE80211_NWID_LEN];
158         struct ieee80211_rateset ni_rates;      /* negotiated rate set */
159         struct ieee80211_channel *ni_chan;
160         uint16_t                ni_fhdwell;     /* FH only */
161         uint8_t                 ni_fhindex;     /* FH only */
162         uint16_t                ni_erp;         /* ERP from beacon/probe resp */
163         uint16_t                ni_timoff;      /* byte offset to TIM ie */
164         uint8_t                 ni_dtim_period; /* DTIM period */
165         uint8_t                 ni_dtim_count;  /* DTIM count for last bcn */
166
167         /* 11n state */
168         uint16_t                ni_htcap;       /* HT capabilities */
169         uint8_t                 ni_htparam;     /* HT params */
170         uint8_t                 ni_htctlchan;   /* HT control channel */
171         uint8_t                 ni_ht2ndchan;   /* HT 2nd channel */
172         uint8_t                 ni_htopmode;    /* HT operating mode */
173         uint8_t                 ni_htstbc;      /* HT */
174         uint8_t                 ni_chw;         /* negotiated channel width */
175         struct ieee80211_htrateset ni_htrates;  /* negotiated ht rate set */
176         struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC];
177         struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
178
179         /* others */
180         short                   ni_inact;       /* inactivity mark count */
181         short                   ni_inact_reload;/* inactivity reload value */
182         int                     ni_txrate;      /* legacy rate/MCS */
183         struct ifqueue          ni_savedq;      /* ps-poll queue */
184         struct ieee80211_nodestats ni_stats;    /* per-node statistics */
185
186         struct ieee80211vap     *ni_wdsvap;     /* associated WDS vap */
187         /* XXX move to vap? */
188         struct ifqueue          ni_wdsq;        /* wds pending queue */
189 };
190 MALLOC_DECLARE(M_80211_NODE);
191 MALLOC_DECLARE(M_80211_NODE_IE);
192
193 #define IEEE80211_NODE_ATH      (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
194 #define IEEE80211_NODE_AMPDU \
195         (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
196 #define IEEE80211_NODE_HT_ALL \
197         (IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \
198          IEEE80211_NODE_AMPDU)
199
200 #define IEEE80211_NODE_AID(ni)  IEEE80211_AID(ni->ni_associd)
201
202 #define IEEE80211_NODE_STAT(ni,stat)    (ni->ni_stats.ns_##stat++)
203 #define IEEE80211_NODE_STAT_ADD(ni,stat,v)      (ni->ni_stats.ns_##stat += v)
204 #define IEEE80211_NODE_STAT_SET(ni,stat,v)      (ni->ni_stats.ns_##stat = v)
205
206 /*
207  * Filtered rssi calculation support.  The receive rssi is maintained
208  * as an average over the last 10 frames received using a low pass filter
209  * (all frames for now, possibly need to be more selective).  Calculations
210  * are designed such that a good compiler can optimize them.  The avg
211  * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and
212  * each sample incorporated with IEEE80211_RSSI_LPF.  Use IEEE80211_RSSI_GET
213  * to extract the current value.
214  *
215  * Note that we assume rssi data are in the range [-127..127] and we
216  * discard values <-20.  This is consistent with assumptions throughout
217  * net80211 that signal strength data are in .5 dBm units relative to
218  * the current noise floor (linear, not log).
219  */
220 #define IEEE80211_RSSI_LPF_LEN          10
221 #define IEEE80211_RSSI_DUMMY_MARKER     127
222 /* NB: pow2 to optimize out * and / */
223 #define IEEE80211_RSSI_EP_MULTIPLIER    (1<<7)
224 #define IEEE80211_RSSI_IN(x)            ((x) * IEEE80211_RSSI_EP_MULTIPLIER)
225 #define _IEEE80211_RSSI_LPF(x, y, len) \
226     (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
227 #define IEEE80211_RSSI_LPF(x, y) do {                                   \
228     if ((y) >= -20) {                                                   \
229         x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)),            \
230                 IEEE80211_RSSI_LPF_LEN);                                \
231     }                                                                   \
232 } while (0)
233 #define IEEE80211_RSSI_EP_RND(x, mul) \
234         ((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
235 #define IEEE80211_RSSI_GET(x) \
236         IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER)
237
238 static __inline struct ieee80211_node *
239 ieee80211_ref_node(struct ieee80211_node *ni)
240 {
241         ieee80211_node_incref(ni);
242         return ni;
243 }
244
245 static __inline void
246 ieee80211_unref_node(struct ieee80211_node **ni)
247 {
248         ieee80211_node_decref(*ni);
249         *ni = NULL;                     /* guard against use */
250 }
251
252 struct ieee80211com;
253
254 void    ieee80211_node_attach(struct ieee80211com *);
255 void    ieee80211_node_lateattach(struct ieee80211com *);
256 void    ieee80211_node_detach(struct ieee80211com *);
257 void    ieee80211_node_vattach(struct ieee80211vap *);
258 void    ieee80211_node_latevattach(struct ieee80211vap *);
259 void    ieee80211_node_vdetach(struct ieee80211vap *);
260
261 static __inline int
262 ieee80211_node_is_authorized(const struct ieee80211_node *ni)
263 {
264         return (ni->ni_flags & IEEE80211_NODE_AUTH);
265 }
266
267 void    ieee80211_node_authorize(struct ieee80211_node *);
268 void    ieee80211_node_unauthorize(struct ieee80211_node *);
269
270 void    ieee80211_node_set_chan(struct ieee80211_node *,
271                 struct ieee80211_channel *);
272 void    ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *);
273 void    ieee80211_reset_bss(struct ieee80211vap *);
274 void    ieee80211_sync_curchan(struct ieee80211com *);
275 void    ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *);
276 int     ieee80211_ibss_merge(struct ieee80211_node *);
277 struct ieee80211_scan_entry;
278 int     ieee80211_sta_join(struct ieee80211vap *,
279                 const struct ieee80211_scan_entry *);
280 void    ieee80211_sta_leave(struct ieee80211_node *);
281 void    ieee80211_node_deauth(struct ieee80211_node *, int);
282
283 int     ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
284 void    ieee80211_ies_cleanup(struct ieee80211_ies *);
285 void    ieee80211_ies_expand(struct ieee80211_ies *);
286 #define ieee80211_ies_setie(_ies, _ie, _off) do {               \
287         (_ies)._ie = (_ies).data + (_off);                      \
288 } while (0)
289
290 /*
291  * Table of ieee80211_node instances.  Each ieee80211com
292  * has one that holds association stations (when operating
293  * as an ap) or neighbors (in ibss mode).
294  *
295  * XXX embed this in ieee80211com instead of indirect?
296  */
297 struct ieee80211_node_table {
298         struct ieee80211com     *nt_ic;         /* back reference */
299         ieee80211_node_lock_t   nt_nodelock;    /* on node table */
300         TAILQ_HEAD(, ieee80211_node) nt_node;   /* information of all nodes */
301         LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
302         struct ieee80211_node   **nt_keyixmap;  /* key ix -> node map */
303         int                     nt_keyixmax;    /* keyixmap size */
304         const char              *nt_name;       /* table name for debug msgs */
305         ieee80211_scan_lock_t   nt_scanlock;    /* on nt_scangen */
306         u_int                   nt_scangen;     /* gen# for iterators */
307         int                     nt_inact_init;  /* initial node inact setting */
308 };
309
310 struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *,
311                 struct ieee80211vap *,
312                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
313 struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *,
314                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
315 struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
316                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
317 struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
318                 const uint8_t bssid[IEEE80211_ADDR_LEN],
319                 struct ieee80211_channel *);
320 #ifdef IEEE80211_DEBUG_REFCNT
321 void    ieee80211_free_node_debug(struct ieee80211_node *,
322                 const char *func, int line);
323 struct ieee80211_node *ieee80211_find_node_locked_debug(
324                 struct ieee80211_node_table *,
325                 const uint8_t macaddr[IEEE80211_ADDR_LEN],
326                 const char *func, int line);
327 struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
328                 const uint8_t macaddr[IEEE80211_ADDR_LEN],
329                 const char *func, int line);
330 struct ieee80211_node *ieee80211_find_vap_node_locked_debug(
331                 struct ieee80211_node_table *,
332                 const struct ieee80211vap *vap,
333                 const uint8_t macaddr[IEEE80211_ADDR_LEN],
334                 const char *func, int line);
335 struct ieee80211_node *ieee80211_find_vap_node_debug(
336                 struct ieee80211_node_table *,
337                 const struct ieee80211vap *vap,
338                 const uint8_t macaddr[IEEE80211_ADDR_LEN],
339                 const char *func, int line);
340 struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
341                 const struct ieee80211_frame_min *,
342                 const char *func, int line);
343 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
344                 struct ieee80211com *,
345                 const struct ieee80211_frame_min *, uint16_t keyix,
346                 const char *func, int line);
347 struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
348                 const uint8_t *,
349                 const char *func, int line);
350 #define ieee80211_free_node(ni) \
351         ieee80211_free_node_debug(ni, __func__, __LINE__)
352 #define ieee80211_find_node_locked(nt, mac) \
353         ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__)
354 #define ieee80211_find_node(nt, mac) \
355         ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
356 #define ieee80211_find_vap_node_locked(nt, vap, mac) \
357         ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__)
358 #define ieee80211_find_vap_node(nt, vap, mac) \
359         ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__)
360 #define ieee80211_find_rxnode(ic, wh) \
361         ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__)
362 #define ieee80211_find_rxnode_withkey(ic, wh, keyix) \
363         ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__)
364 #define ieee80211_find_txnode(vap, mac) \
365         ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__)
366 #else
367 void    ieee80211_free_node(struct ieee80211_node *);
368 struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *,
369                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
370 struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
371                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
372 struct ieee80211_node *ieee80211_find_vap_node_locked(
373                 struct ieee80211_node_table *, const struct ieee80211vap *,
374                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
375 struct ieee80211_node *ieee80211_find_vap_node(
376                 struct ieee80211_node_table *, const struct ieee80211vap *,
377                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
378 struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
379                 const struct ieee80211_frame_min *);
380 struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
381                 const struct ieee80211_frame_min *, uint16_t keyix);
382 struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
383                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
384 #endif
385 int     ieee80211_node_delucastkey(struct ieee80211_node *);
386 void    ieee80211_node_timeout(void *arg);
387
388 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
389 void    ieee80211_iterate_nodes(struct ieee80211_node_table *,
390                 ieee80211_iter_func *, void *);
391
392 void    ieee80211_notify_erp(struct ieee80211com *);
393 void    ieee80211_dump_node(struct ieee80211_node_table *,
394                 struct ieee80211_node *);
395 void    ieee80211_dump_nodes(struct ieee80211_node_table *);
396
397 struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
398                 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
399 struct ieee80211_scanparams;
400 void    ieee80211_init_neighbor(struct ieee80211_node *,
401                 const struct ieee80211_frame *,
402                 const struct ieee80211_scanparams *);
403 struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
404                 const struct ieee80211_frame *,
405                 const struct ieee80211_scanparams *);
406 void    ieee80211_node_join(struct ieee80211_node *,int);
407 void    ieee80211_node_leave(struct ieee80211_node *);
408 int8_t  ieee80211_getrssi(struct ieee80211vap *);
409 void    ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
410 #endif /* _NET80211_IEEE80211_NODE_H_ */