]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net80211/ieee80211_node.h
This commit was generated by cvs2svn to compensate for changes in r174531,
[FreeBSD/FreeBSD.git] / sys / net80211 / ieee80211_node.h
1 /*-
2  * Copyright (c) 2001 Atsushi Onoe
3  * Copyright (c) 2002-2007 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 once a
36  * second.  This is used to initiate various work depending on the
37  * state of the instance: scanning (passive or active), ``transition''
38  * (waiting for a response to a management frame when operating
39  * as a station), and node inactivity processing (when operating
40  * as an AP).  For inactivity processing each node has a timeout
41  * set in it's ni_inact field that is decremented on each timeout
42  * and the node is reclaimed when the counter goes to zero.  We
43  * use different inactivity timeout values depending on whether
44  * the node is associated and authorized (either by 802.1x or
45  * open/shared key authentication) or associated but yet to be
46  * authorized.  The latter timeout is shorter to more aggressively
47  * reclaim nodes that leave part way through the 802.1x exchange.
48  */
49 #define IEEE80211_INACT_WAIT    15              /* inactivity interval (secs) */
50 #define IEEE80211_INACT_INIT    (30/IEEE80211_INACT_WAIT)       /* initial */
51 #define IEEE80211_INACT_AUTH    (180/IEEE80211_INACT_WAIT)      /* associated but not authorized */
52 #define IEEE80211_INACT_RUN     (300/IEEE80211_INACT_WAIT)      /* authorized */
53 #define IEEE80211_INACT_PROBE   (30/IEEE80211_INACT_WAIT)       /* probe */
54 #define IEEE80211_INACT_SCAN    (300/IEEE80211_INACT_WAIT)      /* scanned */
55
56 #define IEEE80211_TRANS_WAIT    2               /* mgt frame tx timer (secs) */
57
58 /* threshold for aging overlapping non-ERP bss */
59 #define IEEE80211_NONERP_PRESENT_AGE    msecs_to_ticks(60*1000)
60
61 #define IEEE80211_NODE_HASHSIZE 32
62 /* simple hash is enough for variation of macaddr */
63 #define IEEE80211_NODE_HASH(addr)       \
64         (((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
65                 IEEE80211_NODE_HASHSIZE)
66
67 struct ieee80211_rsnparms {
68         uint8_t         rsn_mcastcipher;        /* mcast/group cipher */
69         uint8_t         rsn_mcastkeylen;        /* mcast key length */
70         uint8_t         rsn_ucastcipherset;     /* unicast cipher set */
71         uint8_t         rsn_ucastcipher;        /* selected unicast cipher */
72         uint8_t         rsn_ucastkeylen;        /* unicast key length */
73         uint8_t         rsn_keymgmtset;         /* key mangement algorithms */
74         uint8_t         rsn_keymgmt;            /* selected key mgmt algo */
75         uint16_t        rsn_caps;               /* capabilities */
76 };
77
78 struct ieee80211_node_table;
79 struct ieee80211com;
80
81 /*
82  * Node specific information.  Note that drivers are expected
83  * to derive from this structure to add device-specific per-node
84  * state.  This is done by overriding the ic_node_* methods in
85  * the ieee80211com structure.
86  */
87 struct ieee80211_node {
88         struct ieee80211com     *ni_ic;
89         struct ieee80211_node_table *ni_table;
90         TAILQ_ENTRY(ieee80211_node)     ni_list;
91         LIST_ENTRY(ieee80211_node)      ni_hash;
92         u_int                   ni_refcnt;
93         u_int                   ni_scangen;     /* gen# for timeout scan */
94         uint8_t                 ni_authmode;    /* authentication algorithm */
95         uint8_t                 ni_ath_flags;   /* Atheros feature flags */
96         /* NB: These must have the same values as IEEE80211_ATHC_* */
97 #define IEEE80211_NODE_TURBOP   0x0001          /* Turbo prime enable */
98 #define IEEE80211_NODE_COMP     0x0002          /* Compresssion enable */
99 #define IEEE80211_NODE_FF       0x0004          /* Fast Frame capable */
100 #define IEEE80211_NODE_XR       0x0008          /* Atheros WME enable */
101 #define IEEE80211_NODE_AR       0x0010          /* AR capable */
102 #define IEEE80211_NODE_BOOST    0x0080 
103 #define IEEE80211_NODE_PSUPDATE 0x0200          /* power save state changed */ 
104 #define IEEE80211_NODE_CHWUPDATE 0x0400         /* 11n channel width change */
105         uint16_t                ni_flags;       /* special-purpose state */
106 #define IEEE80211_NODE_AUTH     0x0001          /* authorized for data */
107 #define IEEE80211_NODE_QOS      0x0002          /* QoS enabled */
108 #define IEEE80211_NODE_ERP      0x0004          /* ERP enabled */
109 /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
110 #define IEEE80211_NODE_PWR_MGT  0x0010          /* power save mode enabled */
111 #define IEEE80211_NODE_AREF     0x0020          /* authentication ref held */
112 #define IEEE80211_NODE_HT       0x0040          /* HT enabled */
113 #define IEEE80211_NODE_HTCOMPAT 0x0080          /* HT setup w/ vendor OUI's */
114 #define IEEE80211_NODE_AMPDU_RX 0x0400          /* AMPDU rx enabled */
115 #define IEEE80211_NODE_AMPDU_TX 0x0800          /* AMPDU tx enabled */
116         uint16_t                ni_ath_defkeyix;/* Atheros def key index */
117         uint16_t                ni_associd;     /* assoc response */
118         uint16_t                ni_txpower;     /* current transmit power */
119         uint16_t                ni_vlan;        /* vlan tag */
120         uint32_t                ni_jointime;    /* time of join (secs) */
121         uint32_t                *ni_challenge;  /* shared-key challenge */
122         uint8_t                 *ni_wpa_ie;     /* captured WPA ie */
123         uint8_t                 *ni_rsn_ie;     /* captured RSN ie */
124         uint8_t                 *ni_wme_ie;     /* captured WME ie */
125         uint8_t                 *ni_ath_ie;     /* captured Atheros ie */
126                                                 /* tx seq per-tid */
127         uint16_t                ni_txseqs[IEEE80211_TID_SIZE];
128                                                 /* rx seq previous per-tid*/
129         uint16_t                ni_rxseqs[IEEE80211_TID_SIZE];
130         uint32_t                ni_rxfragstamp; /* time stamp of last rx frag */
131         struct mbuf             *ni_rxfrag[3];  /* rx frag reassembly */
132         struct ieee80211_rsnparms ni_rsn;       /* RSN/WPA parameters */
133         struct ieee80211_key    ni_ucastkey;    /* unicast key */
134
135         /* hardware */
136         uint32_t                ni_rstamp;      /* recv timestamp */
137         int8_t                  ni_rssi;        /* recv ssi */
138         int8_t                  ni_noise;       /* noise floor */
139
140         /* header */
141         uint8_t                 ni_macaddr[IEEE80211_ADDR_LEN];
142         uint8_t                 ni_bssid[IEEE80211_ADDR_LEN];
143
144         /* beacon, probe response */
145         union {
146                 uint8_t         data[8];
147                 uint64_t        tsf;
148         } ni_tstamp;                            /* from last rcv'd beacon */
149         uint16_t                ni_intval;      /* beacon interval */
150         uint16_t                ni_capinfo;     /* capabilities */
151         uint8_t                 ni_esslen;
152         uint8_t                 ni_essid[IEEE80211_NWID_LEN];
153         struct ieee80211_rateset ni_rates;      /* negotiated rate set */
154         struct ieee80211_channel *ni_chan;
155         uint16_t                ni_fhdwell;     /* FH only */
156         uint8_t                 ni_fhindex;     /* FH only */
157         uint8_t                 ni_erp;         /* ERP from beacon/probe resp */
158         uint16_t                ni_timoff;      /* byte offset to TIM ie */
159         uint8_t                 ni_dtim_period; /* DTIM period */
160         uint8_t                 ni_dtim_count;  /* DTIM count for last bcn */
161
162         /* 11n state */
163         uint8_t                 *ni_htcap_ie;   /* captured HTCAP ie */
164         uint16_t                ni_htcap;       /* HT capabilities */
165         uint8_t                 ni_htparam;     /* HT params */
166         uint8_t                 ni_htctlchan;   /* HT control channel */
167         uint8_t                 ni_ht2ndchan;   /* HT 2nd channel */
168         uint8_t                 ni_htopmode;    /* HT operating mode */
169         uint8_t                 ni_htstbc;      /* HT */
170         uint8_t                 ni_reqcw;       /* requested tx channel width */
171         uint8_t                 ni_chw;         /* negotiated channel width */
172         struct ieee80211_htrateset ni_htrates;  /* negotiated ht rate set */
173         struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC];
174         struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
175
176         /* others */
177         int                     ni_fails;       /* failure count to associate */
178         short                   ni_inact;       /* inactivity mark count */
179         short                   ni_inact_reload;/* inactivity reload value */
180         int                     ni_txrate;      /* index to ni_rates[] */
181         struct  ifqueue         ni_savedq;      /* ps-poll queue */
182         struct ieee80211_nodestats ni_stats;    /* per-node statistics */
183 };
184 MALLOC_DECLARE(M_80211_NODE);
185
186 #define IEEE80211_NODE_ATH      (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
187 #define IEEE80211_NODE_AMPDU \
188         (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
189
190 #define IEEE80211_NODE_AID(ni)  IEEE80211_AID(ni->ni_associd)
191
192 #define IEEE80211_NODE_STAT(ni,stat)    (ni->ni_stats.ns_##stat++)
193 #define IEEE80211_NODE_STAT_ADD(ni,stat,v)      (ni->ni_stats.ns_##stat += v)
194 #define IEEE80211_NODE_STAT_SET(ni,stat,v)      (ni->ni_stats.ns_##stat = v)
195
196 static __inline struct ieee80211_node *
197 ieee80211_ref_node(struct ieee80211_node *ni)
198 {
199         ieee80211_node_incref(ni);
200         return ni;
201 }
202
203 static __inline void
204 ieee80211_unref_node(struct ieee80211_node **ni)
205 {
206         ieee80211_node_decref(*ni);
207         *ni = NULL;                     /* guard against use */
208 }
209
210 struct ieee80211com;
211
212 void    ieee80211_node_attach(struct ieee80211com *);
213 void    ieee80211_node_lateattach(struct ieee80211com *);
214 void    ieee80211_node_detach(struct ieee80211com *);
215
216 static __inline int
217 ieee80211_node_is_authorized(const struct ieee80211_node *ni)
218 {
219         return (ni->ni_flags & IEEE80211_NODE_AUTH);
220 }
221
222 void    ieee80211_node_authorize(struct ieee80211_node *);
223 void    ieee80211_node_unauthorize(struct ieee80211_node *);
224
225 void    ieee80211_probe_curchan(struct ieee80211com *, int);
226 void    ieee80211_create_ibss(struct ieee80211com*, struct ieee80211_channel *);
227 void    ieee80211_reset_bss(struct ieee80211com *);
228 void    ieee80211_setbsschan(struct ieee80211com *, struct ieee80211_channel *);
229 int     ieee80211_ibss_merge(struct ieee80211_node *);
230 struct ieee80211_scan_entry;
231 int     ieee80211_sta_join(struct ieee80211com *,
232                 const struct ieee80211_scan_entry *);
233 void    ieee80211_sta_leave(struct ieee80211com *, struct ieee80211_node *);
234
235 /*
236  * Table of ieee80211_node instances.  Each ieee80211com
237  * has at least one for holding the scan candidates.
238  * When operating as an access point or in ibss mode there
239  * is a second table for associated stations or neighbors.
240  */
241 struct ieee80211_node_table {
242         struct ieee80211com     *nt_ic;         /* back reference */
243         ieee80211_node_lock_t   nt_nodelock;    /* on node table */
244         TAILQ_HEAD(, ieee80211_node) nt_node;   /* information of all nodes */
245         LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
246         struct ieee80211_node   **nt_keyixmap;  /* key ix -> node map */
247         int                     nt_keyixmax;    /* keyixmap size */
248         const char              *nt_name;       /* for debugging */
249         ieee80211_scan_lock_t   nt_scanlock;    /* on nt_scangen */
250         u_int                   nt_scangen;     /* gen# for timeout scan */
251         int                     nt_inact_init;  /* initial node inact setting */
252 };
253
254 struct ieee80211_node *ieee80211_alloc_node(
255                 struct ieee80211_node_table *, const uint8_t *);
256 struct ieee80211_node *ieee80211_tmp_node(struct ieee80211com *,
257                 const uint8_t *macaddr);
258 struct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *,
259                 const uint8_t *);
260 #ifdef IEEE80211_DEBUG_REFCNT
261 void    ieee80211_free_node_debug(struct ieee80211_node *,
262                 const char *func, int line);
263 struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
264                 const uint8_t *,
265                 const char *func, int line);
266 struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
267                 const struct ieee80211_frame_min *,
268                 const char *func, int line);
269 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
270                 struct ieee80211com *,
271                 const struct ieee80211_frame_min *, uint16_t keyix,
272                 const char *func, int line);
273 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
274                 struct ieee80211com *,
275                 const struct ieee80211_frame_min *, uint16_t keyix,
276                 const char *func, int line);
277 struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211com *,
278                 const uint8_t *,
279                 const char *func, int line);
280 struct ieee80211_node *ieee80211_find_node_with_ssid_debug(
281                 struct ieee80211_node_table *, const uint8_t *macaddr,
282                 u_int ssidlen, const uint8_t *ssid,
283                 const char *func, int line);
284 #define ieee80211_free_node(ni) \
285         ieee80211_free_node_debug(ni, __func__, __LINE__)
286 #define ieee80211_find_node(nt, mac) \
287         ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
288 #define ieee80211_find_rxnode(nt, wh) \
289         ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__)
290 #define ieee80211_find_rxnode_withkey(nt, wh, keyix) \
291         ieee80211_find_rxnode_withkey_debug(nt, wh, keyix, __func__, __LINE__)
292 #define ieee80211_find_txnode(nt, mac) \
293         ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__)
294 #define ieee80211_find_node_with_ssid(nt, mac, sl, ss) \
295         ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__)
296 #else
297 void    ieee80211_free_node(struct ieee80211_node *);
298 struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
299                 const uint8_t *);
300 struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
301                 const struct ieee80211_frame_min *);
302 struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
303                 const struct ieee80211_frame_min *, uint16_t keyix);
304 struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
305                 const uint8_t *);
306 struct ieee80211_node *ieee80211_find_node_with_ssid(
307                 struct ieee80211_node_table *, const uint8_t *macaddr,
308                 u_int ssidlen, const uint8_t *ssid);
309 #endif
310 int     ieee80211_node_delucastkey(struct ieee80211_node *);
311 void    ieee80211_node_timeout(void *arg);
312
313 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
314 void    ieee80211_iterate_nodes(struct ieee80211_node_table *,
315                 ieee80211_iter_func *, void *);
316
317 void    ieee80211_dump_node(struct ieee80211_node_table *,
318                 struct ieee80211_node *);
319 void    ieee80211_dump_nodes(struct ieee80211_node_table *);
320
321 void    ieee80211_notify_erp(struct ieee80211com *);
322
323 struct ieee80211_node *ieee80211_fakeup_adhoc_node(
324                 struct ieee80211_node_table *, const uint8_t macaddr[]);
325 struct ieee80211_scanparams;
326 void    ieee80211_init_neighbor(struct ieee80211_node *,
327                 const struct ieee80211_frame *,
328                 const struct ieee80211_scanparams *);
329 struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211com *,
330                 const struct ieee80211_frame *,
331                 const struct ieee80211_scanparams *);
332 void    ieee80211_node_join(struct ieee80211com *, struct ieee80211_node *,int);
333 void    ieee80211_node_leave(struct ieee80211com *, struct ieee80211_node *);
334 int8_t  ieee80211_getrssi(struct ieee80211com *);
335 void    ieee80211_getsignal(struct ieee80211com *, int8_t *, int8_t *);
336 #endif /* _NET80211_IEEE80211_NODE_H_ */