2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
28 #ifndef _NET80211_IEEE80211_NODE_H_
29 #define _NET80211_IEEE80211_NODE_H_
31 #include <net80211/ieee80211_ioctl.h> /* for ieee80211_nodestats */
32 #include <net80211/ieee80211_ht.h> /* for aggregation state */
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.
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 */
56 #define IEEE80211_TRANS_WAIT 2 /* mgt frame tx timer (secs) */
58 /* threshold for aging overlapping non-ERP bss */
59 #define IEEE80211_NONERP_PRESENT_AGE msecs_to_ticks(60*1000)
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)
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 */
78 struct ieee80211_node_table;
82 * Information element ``blob''. We use this structure
83 * to capture management frame payloads that need to be
84 * retained. Information elemnts within the payload that
85 * we need to consult have references recorded.
87 struct ieee80211_ies {
88 /* the following are either NULL or point within data */
89 uint8_t *wpa_ie; /* captured WPA ie */
90 uint8_t *rsn_ie; /* captured RSN ie */
91 uint8_t *wme_ie; /* captured WME ie */
92 uint8_t *ath_ie; /* captured Atheros ie */
93 uint8_t *htcap_ie; /* captured HTCAP ie */
94 uint8_t *htinfo_ie; /* captured HTINFO ie */
95 /* NB: these must be the last members of this structure */
96 uint8_t *data; /* frame data > 802.11 header */
97 int len; /* data size in bytes */
101 * Node specific information. Note that drivers are expected
102 * to derive from this structure to add device-specific per-node
103 * state. This is done by overriding the ic_node_* methods in
104 * the ieee80211com structure.
106 struct ieee80211_node {
107 struct ieee80211com *ni_ic;
108 struct ieee80211_node_table *ni_table;
109 TAILQ_ENTRY(ieee80211_node) ni_list;
110 LIST_ENTRY(ieee80211_node) ni_hash;
112 u_int ni_scangen; /* gen# for timeout scan */
113 uint8_t ni_authmode; /* authentication algorithm */
114 uint8_t ni_ath_flags; /* Atheros feature flags */
115 /* NB: These must have the same values as IEEE80211_ATHC_* */
116 #define IEEE80211_NODE_TURBOP 0x0001 /* Turbo prime enable */
117 #define IEEE80211_NODE_COMP 0x0002 /* Compresssion enable */
118 #define IEEE80211_NODE_FF 0x0004 /* Fast Frame capable */
119 #define IEEE80211_NODE_XR 0x0008 /* Atheros WME enable */
120 #define IEEE80211_NODE_AR 0x0010 /* AR capable */
121 #define IEEE80211_NODE_BOOST 0x0080
122 #define IEEE80211_NODE_PSUPDATE 0x0200 /* power save state changed */
123 #define IEEE80211_NODE_CHWUPDATE 0x0400 /* 11n channel width change */
124 uint16_t ni_flags; /* special-purpose state */
125 #define IEEE80211_NODE_AUTH 0x0001 /* authorized for data */
126 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
127 #define IEEE80211_NODE_ERP 0x0004 /* ERP enabled */
128 /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
129 #define IEEE80211_NODE_PWR_MGT 0x0010 /* power save mode enabled */
130 #define IEEE80211_NODE_AREF 0x0020 /* authentication ref held */
131 #define IEEE80211_NODE_HT 0x0040 /* HT enabled */
132 #define IEEE80211_NODE_HTCOMPAT 0x0080 /* HT setup w/ vendor OUI's */
133 #define IEEE80211_NODE_AMPDU_RX 0x0400 /* AMPDU rx enabled */
134 #define IEEE80211_NODE_AMPDU_TX 0x0800 /* AMPDU tx enabled */
135 uint16_t ni_ath_defkeyix;/* Atheros def key index */
136 uint16_t ni_associd; /* assoc response */
137 uint16_t ni_txpower; /* current transmit power */
138 uint16_t ni_vlan; /* vlan tag */
139 uint32_t ni_jointime; /* time of join (secs) */
140 uint32_t *ni_challenge; /* shared-key challenge */
141 struct ieee80211_ies ni_ies; /* captured ie's */
143 uint16_t ni_txseqs[IEEE80211_TID_SIZE];
144 /* rx seq previous per-tid*/
145 uint16_t ni_rxseqs[IEEE80211_TID_SIZE];
146 uint32_t ni_rxfragstamp; /* time stamp of last rx frag */
147 struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */
148 struct ieee80211_rsnparms ni_rsn; /* RSN/WPA parameters */
149 struct ieee80211_key ni_ucastkey; /* unicast key */
152 uint32_t ni_rstamp; /* recv timestamp */
153 int8_t ni_rssi; /* recv ssi */
154 int8_t ni_noise; /* noise floor */
157 uint8_t ni_macaddr[IEEE80211_ADDR_LEN];
158 uint8_t ni_bssid[IEEE80211_ADDR_LEN];
160 /* beacon, probe response */
164 } ni_tstamp; /* from last rcv'd beacon */
165 uint16_t ni_intval; /* beacon interval */
166 uint16_t ni_capinfo; /* capabilities */
168 uint8_t ni_essid[IEEE80211_NWID_LEN];
169 struct ieee80211_rateset ni_rates; /* negotiated rate set */
170 struct ieee80211_channel *ni_chan;
171 uint16_t ni_fhdwell; /* FH only */
172 uint8_t ni_fhindex; /* FH only */
173 uint8_t ni_erp; /* ERP from beacon/probe resp */
174 uint16_t ni_timoff; /* byte offset to TIM ie */
175 uint8_t ni_dtim_period; /* DTIM period */
176 uint8_t ni_dtim_count; /* DTIM count for last bcn */
179 uint16_t ni_htcap; /* HT capabilities */
180 uint8_t ni_htparam; /* HT params */
181 uint8_t ni_htctlchan; /* HT control channel */
182 uint8_t ni_ht2ndchan; /* HT 2nd channel */
183 uint8_t ni_htopmode; /* HT operating mode */
184 uint8_t ni_htstbc; /* HT */
185 uint8_t ni_reqcw; /* requested tx channel width */
186 uint8_t ni_chw; /* negotiated channel width */
187 struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */
188 struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC];
189 struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
192 int ni_fails; /* failure count to associate */
193 short ni_inact; /* inactivity mark count */
194 short ni_inact_reload;/* inactivity reload value */
195 int ni_txrate; /* index to ni_rates[] */
196 struct ifqueue ni_savedq; /* ps-poll queue */
197 struct ieee80211_nodestats ni_stats; /* per-node statistics */
199 MALLOC_DECLARE(M_80211_NODE);
201 #define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
202 #define IEEE80211_NODE_AMPDU \
203 (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
205 #define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd)
207 #define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++)
208 #define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v)
209 #define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v)
211 static __inline struct ieee80211_node *
212 ieee80211_ref_node(struct ieee80211_node *ni)
214 ieee80211_node_incref(ni);
219 ieee80211_unref_node(struct ieee80211_node **ni)
221 ieee80211_node_decref(*ni);
222 *ni = NULL; /* guard against use */
227 void ieee80211_node_attach(struct ieee80211com *);
228 void ieee80211_node_lateattach(struct ieee80211com *);
229 void ieee80211_node_detach(struct ieee80211com *);
232 ieee80211_node_is_authorized(const struct ieee80211_node *ni)
234 return (ni->ni_flags & IEEE80211_NODE_AUTH);
237 void ieee80211_node_authorize(struct ieee80211_node *);
238 void ieee80211_node_unauthorize(struct ieee80211_node *);
240 void ieee80211_probe_curchan(struct ieee80211com *, int);
241 void ieee80211_create_ibss(struct ieee80211com*, struct ieee80211_channel *);
242 void ieee80211_reset_bss(struct ieee80211com *);
243 void ieee80211_setbsschan(struct ieee80211com *, struct ieee80211_channel *);
244 int ieee80211_ibss_merge(struct ieee80211_node *);
245 struct ieee80211_scan_entry;
246 int ieee80211_sta_join(struct ieee80211com *,
247 const struct ieee80211_scan_entry *);
248 void ieee80211_sta_leave(struct ieee80211com *, struct ieee80211_node *);
250 int ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
251 void ieee80211_ies_cleanup(struct ieee80211_ies *);
252 void ieee80211_ies_expand(struct ieee80211_ies *);
253 #define ieee80211_ies_setie(_ies, _ie, _off) do { \
254 (_ies)._ie = (_ies).data + (_off); \
258 * Table of ieee80211_node instances. Each ieee80211com
259 * has at least one for holding the scan candidates.
260 * When operating as an access point or in ibss mode there
261 * is a second table for associated stations or neighbors.
263 struct ieee80211_node_table {
264 struct ieee80211com *nt_ic; /* back reference */
265 ieee80211_node_lock_t nt_nodelock; /* on node table */
266 TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */
267 LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
268 struct ieee80211_node **nt_keyixmap; /* key ix -> node map */
269 int nt_keyixmax; /* keyixmap size */
270 const char *nt_name; /* for debugging */
271 ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */
272 u_int nt_scangen; /* gen# for timeout scan */
273 int nt_inact_init; /* initial node inact setting */
276 struct ieee80211_node *ieee80211_alloc_node(
277 struct ieee80211_node_table *, const uint8_t *);
278 struct ieee80211_node *ieee80211_tmp_node(struct ieee80211com *,
279 const uint8_t *macaddr);
280 struct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *,
282 #ifdef IEEE80211_DEBUG_REFCNT
283 void ieee80211_free_node_debug(struct ieee80211_node *,
284 const char *func, int line);
285 struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
287 const char *func, int line);
288 struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
289 const struct ieee80211_frame_min *,
290 const char *func, int line);
291 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
292 struct ieee80211com *,
293 const struct ieee80211_frame_min *, uint16_t keyix,
294 const char *func, int line);
295 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
296 struct ieee80211com *,
297 const struct ieee80211_frame_min *, uint16_t keyix,
298 const char *func, int line);
299 struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211com *,
301 const char *func, int line);
302 struct ieee80211_node *ieee80211_find_node_with_ssid_debug(
303 struct ieee80211_node_table *, const uint8_t *macaddr,
304 u_int ssidlen, const uint8_t *ssid,
305 const char *func, int line);
306 #define ieee80211_free_node(ni) \
307 ieee80211_free_node_debug(ni, __func__, __LINE__)
308 #define ieee80211_find_node(nt, mac) \
309 ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
310 #define ieee80211_find_rxnode(nt, wh) \
311 ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__)
312 #define ieee80211_find_rxnode_withkey(nt, wh, keyix) \
313 ieee80211_find_rxnode_withkey_debug(nt, wh, keyix, __func__, __LINE__)
314 #define ieee80211_find_txnode(nt, mac) \
315 ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__)
316 #define ieee80211_find_node_with_ssid(nt, mac, sl, ss) \
317 ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__)
319 void ieee80211_free_node(struct ieee80211_node *);
320 struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
322 struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
323 const struct ieee80211_frame_min *);
324 struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
325 const struct ieee80211_frame_min *, uint16_t keyix);
326 struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
328 struct ieee80211_node *ieee80211_find_node_with_ssid(
329 struct ieee80211_node_table *, const uint8_t *macaddr,
330 u_int ssidlen, const uint8_t *ssid);
332 int ieee80211_node_delucastkey(struct ieee80211_node *);
333 void ieee80211_node_timeout(void *arg);
335 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
336 void ieee80211_iterate_nodes(struct ieee80211_node_table *,
337 ieee80211_iter_func *, void *);
339 void ieee80211_dump_node(struct ieee80211_node_table *,
340 struct ieee80211_node *);
341 void ieee80211_dump_nodes(struct ieee80211_node_table *);
343 void ieee80211_notify_erp(struct ieee80211com *);
345 struct ieee80211_node *ieee80211_fakeup_adhoc_node(
346 struct ieee80211_node_table *, const uint8_t macaddr[]);
347 struct ieee80211_scanparams;
348 void ieee80211_init_neighbor(struct ieee80211_node *,
349 const struct ieee80211_frame *,
350 const struct ieee80211_scanparams *);
351 struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211com *,
352 const struct ieee80211_frame *,
353 const struct ieee80211_scanparams *);
354 void ieee80211_node_join(struct ieee80211com *, struct ieee80211_node *,int);
355 void ieee80211_node_leave(struct ieee80211com *, struct ieee80211_node *);
356 int8_t ieee80211_getrssi(struct ieee80211com *);
357 void ieee80211_getsignal(struct ieee80211com *, int8_t *, int8_t *);
358 #endif /* _NET80211_IEEE80211_NODE_H_ */