ieee80211_node.h revision 182828
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: head/sys/net80211/ieee80211_node.h 182828 2008-09-06 17:33:46Z sam $ 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 65struct ieee80211_node_table; 66struct ieee80211com; 67struct 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 */ 75struct 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 */ 94struct 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 uint8_t ni_authmode; /* authentication algorithm */ 103 uint8_t ni_ath_flags; /* Atheros feature flags */ 104 /* NB: These must have the same values as IEEE80211_ATHC_* */ 105#define IEEE80211_NODE_TURBOP 0x0001 /* Turbo prime enable */ 106#define IEEE80211_NODE_COMP 0x0002 /* Compresssion enable */ 107#define IEEE80211_NODE_FF 0x0004 /* Fast Frame capable */ 108#define IEEE80211_NODE_XR 0x0008 /* Atheros WME enable */ 109#define IEEE80211_NODE_AR 0x0010 /* AR capable */ 110#define IEEE80211_NODE_BOOST 0x0080 111#define IEEE80211_NODE_PSUPDATE 0x0200 /* power save state changed */ 112#define IEEE80211_NODE_CHWUPDATE 0x0400 /* 11n channel width change */ 113 uint16_t ni_flags; /* special-purpose state */ 114#define IEEE80211_NODE_AUTH 0x0001 /* authorized for data */ 115#define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */ 116#define IEEE80211_NODE_ERP 0x0004 /* ERP enabled */ 117/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */ 118#define IEEE80211_NODE_PWR_MGT 0x0010 /* power save mode enabled */ 119#define IEEE80211_NODE_AREF 0x0020 /* authentication ref held */ 120#define IEEE80211_NODE_HT 0x0040 /* HT enabled */ 121#define IEEE80211_NODE_HTCOMPAT 0x0080 /* HT setup w/ vendor OUI's */ 122#define IEEE80211_NODE_WPS 0x0100 /* WPS association */ 123#define IEEE80211_NODE_TSN 0x0200 /* TSN association */ 124#define IEEE80211_NODE_AMPDU_RX 0x0400 /* AMPDU rx enabled */ 125#define IEEE80211_NODE_AMPDU_TX 0x0800 /* AMPDU tx enabled */ 126 uint16_t ni_ath_defkeyix;/* Atheros def key index */ 127 uint16_t ni_associd; /* assoc response */ 128 uint16_t ni_txpower; /* current transmit power */ 129 uint16_t ni_vlan; /* vlan tag */ 130 uint32_t ni_jointime; /* time of join (secs) */ 131 uint32_t *ni_challenge; /* shared-key challenge */ 132 struct ieee80211_ies ni_ies; /* captured ie's */ 133 /* tx seq per-tid */ 134 uint16_t ni_txseqs[IEEE80211_TID_SIZE]; 135 /* rx seq previous per-tid*/ 136 uint16_t ni_rxseqs[IEEE80211_TID_SIZE]; 137 uint32_t ni_rxfragstamp; /* time stamp of last rx frag */ 138 struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */ 139 struct ieee80211_key ni_ucastkey; /* unicast key */ 140 141 /* hardware */ 142 uint32_t ni_rstamp; /* recv timestamp */ 143 uint32_t ni_avgrssi; /* recv ssi state */ 144 int8_t ni_noise; /* noise floor */ 145 146 /* header */ 147 uint8_t ni_macaddr[IEEE80211_ADDR_LEN]; 148 uint8_t ni_bssid[IEEE80211_ADDR_LEN]; 149 150 /* beacon, probe response */ 151 union { 152 uint8_t data[8]; 153 u_int64_t tsf; 154 } ni_tstamp; /* from last rcv'd beacon */ 155 uint16_t ni_intval; /* beacon interval */ 156 uint16_t ni_capinfo; /* capabilities */ 157 uint8_t ni_esslen; 158 uint8_t ni_essid[IEEE80211_NWID_LEN]; 159 struct ieee80211_rateset ni_rates; /* negotiated rate set */ 160 struct ieee80211_channel *ni_chan; 161 uint16_t ni_fhdwell; /* FH only */ 162 uint8_t ni_fhindex; /* FH only */ 163 uint16_t ni_erp; /* ERP from beacon/probe resp */ 164 uint16_t ni_timoff; /* byte offset to TIM ie */ 165 uint8_t ni_dtim_period; /* DTIM period */ 166 uint8_t ni_dtim_count; /* DTIM count for last bcn */ 167 168 /* 11n state */ 169 uint16_t ni_htcap; /* HT capabilities */ 170 uint8_t ni_htparam; /* HT params */ 171 uint8_t ni_htctlchan; /* HT control channel */ 172 uint8_t ni_ht2ndchan; /* HT 2nd channel */ 173 uint8_t ni_htopmode; /* HT operating mode */ 174 uint8_t ni_htstbc; /* HT */ 175 uint8_t ni_chw; /* negotiated channel width */ 176 struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */ 177 struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC]; 178 struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID]; 179 180 /* others */ 181 short ni_inact; /* inactivity mark count */ 182 short ni_inact_reload;/* inactivity reload value */ 183 int ni_txrate; /* legacy rate/MCS */ 184 struct ifqueue ni_savedq; /* ps-poll queue */ 185 struct ieee80211_nodestats ni_stats; /* per-node statistics */ 186 187 struct ieee80211vap *ni_wdsvap; /* associated WDS vap */ 188 /* XXX move to vap? */ 189 struct ifqueue ni_wdsq; /* wds pending queue */ 190}; 191MALLOC_DECLARE(M_80211_NODE); 192MALLOC_DECLARE(M_80211_NODE_IE); 193 194#define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP) 195#define IEEE80211_NODE_AMPDU \ 196 (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX) 197#define IEEE80211_NODE_HT_ALL \ 198 (IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \ 199 IEEE80211_NODE_AMPDU) 200 201#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd) 202 203#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++) 204#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v) 205#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v) 206 207/* 208 * Filtered rssi calculation support. The receive rssi is maintained 209 * as an average over the last 10 frames received using a low pass filter 210 * (all frames for now, possibly need to be more selective). Calculations 211 * are designed such that a good compiler can optimize them. The avg 212 * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and 213 * each sample incorporated with IEEE80211_RSSI_LPF. Use IEEE80211_RSSI_GET 214 * to extract the current value. 215 * 216 * Note that we assume rssi data are in the range [-127..127] and we 217 * discard values <-20. This is consistent with assumptions throughout 218 * net80211 that signal strength data are in .5 dBm units relative to 219 * the current noise floor (linear, not log). 220 */ 221#define IEEE80211_RSSI_LPF_LEN 10 222#define IEEE80211_RSSI_DUMMY_MARKER 127 223/* NB: pow2 to optimize out * and / */ 224#define IEEE80211_RSSI_EP_MULTIPLIER (1<<7) 225#define IEEE80211_RSSI_IN(x) ((x) * IEEE80211_RSSI_EP_MULTIPLIER) 226#define _IEEE80211_RSSI_LPF(x, y, len) \ 227 (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y)) 228#define IEEE80211_RSSI_LPF(x, y) do { \ 229 if ((y) >= -20) { \ 230 x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), \ 231 IEEE80211_RSSI_LPF_LEN); \ 232 } \ 233} while (0) 234#define IEEE80211_RSSI_EP_RND(x, mul) \ 235 ((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul)) 236#define IEEE80211_RSSI_GET(x) \ 237 IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER) 238 239static __inline struct ieee80211_node * 240ieee80211_ref_node(struct ieee80211_node *ni) 241{ 242 ieee80211_node_incref(ni); 243 return ni; 244} 245 246static __inline void 247ieee80211_unref_node(struct ieee80211_node **ni) 248{ 249 ieee80211_node_decref(*ni); 250 *ni = NULL; /* guard against use */ 251} 252 253struct ieee80211com; 254 255void ieee80211_node_attach(struct ieee80211com *); 256void ieee80211_node_lateattach(struct ieee80211com *); 257void ieee80211_node_detach(struct ieee80211com *); 258void ieee80211_node_vattach(struct ieee80211vap *); 259void ieee80211_node_latevattach(struct ieee80211vap *); 260void ieee80211_node_vdetach(struct ieee80211vap *); 261 262static __inline int 263ieee80211_node_is_authorized(const struct ieee80211_node *ni) 264{ 265 return (ni->ni_flags & IEEE80211_NODE_AUTH); 266} 267 268void ieee80211_node_authorize(struct ieee80211_node *); 269void ieee80211_node_unauthorize(struct ieee80211_node *); 270 271void ieee80211_node_set_chan(struct ieee80211_node *, 272 struct ieee80211_channel *); 273void ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *); 274void ieee80211_reset_bss(struct ieee80211vap *); 275void ieee80211_sync_curchan(struct ieee80211com *); 276void ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *); 277int ieee80211_ibss_merge(struct ieee80211_node *); 278struct ieee80211_scan_entry; 279int ieee80211_sta_join(struct ieee80211vap *, 280 const struct ieee80211_scan_entry *); 281void ieee80211_sta_leave(struct ieee80211_node *); 282void ieee80211_node_deauth(struct ieee80211_node *, int); 283 284int ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int); 285void ieee80211_ies_cleanup(struct ieee80211_ies *); 286void ieee80211_ies_expand(struct ieee80211_ies *); 287#define ieee80211_ies_setie(_ies, _ie, _off) do { \ 288 (_ies)._ie = (_ies).data + (_off); \ 289} while (0) 290 291/* 292 * Table of ieee80211_node instances. Each ieee80211com 293 * has one that holds association stations (when operating 294 * as an ap) or neighbors (in ibss mode). 295 * 296 * XXX embed this in ieee80211com instead of indirect? 297 */ 298struct ieee80211_node_table { 299 struct ieee80211com *nt_ic; /* back reference */ 300 ieee80211_node_lock_t nt_nodelock; /* on node table */ 301 TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */ 302 LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE]; 303 struct ieee80211_node **nt_keyixmap; /* key ix -> node map */ 304 int nt_keyixmax; /* keyixmap size */ 305 const char *nt_name; /* table name for debug msgs */ 306 ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */ 307 u_int nt_scangen; /* gen# for iterators */ 308 int nt_inact_init; /* initial node inact setting */ 309}; 310 311struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *, 312 struct ieee80211vap *, 313 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 314struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *, 315 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 316struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *, 317 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 318struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *, 319 const uint8_t bssid[IEEE80211_ADDR_LEN], 320 struct ieee80211_channel *); 321#ifdef IEEE80211_DEBUG_REFCNT 322void ieee80211_free_node_debug(struct ieee80211_node *, 323 const char *func, int line); 324struct ieee80211_node *ieee80211_find_node_locked_debug( 325 struct ieee80211_node_table *, 326 const uint8_t macaddr[IEEE80211_ADDR_LEN], 327 const char *func, int line); 328struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *, 329 const uint8_t macaddr[IEEE80211_ADDR_LEN], 330 const char *func, int line); 331struct ieee80211_node *ieee80211_find_vap_node_locked_debug( 332 struct ieee80211_node_table *, 333 const struct ieee80211vap *vap, 334 const uint8_t macaddr[IEEE80211_ADDR_LEN], 335 const char *func, int line); 336struct ieee80211_node *ieee80211_find_vap_node_debug( 337 struct ieee80211_node_table *, 338 const struct ieee80211vap *vap, 339 const uint8_t macaddr[IEEE80211_ADDR_LEN], 340 const char *func, int line); 341struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *, 342 const struct ieee80211_frame_min *, 343 const char *func, int line); 344struct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 345 struct ieee80211com *, 346 const struct ieee80211_frame_min *, uint16_t keyix, 347 const char *func, int line); 348struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *, 349 const uint8_t *, 350 const char *func, int line); 351#define ieee80211_free_node(ni) \ 352 ieee80211_free_node_debug(ni, __func__, __LINE__) 353#define ieee80211_find_node_locked(nt, mac) \ 354 ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__) 355#define ieee80211_find_node(nt, mac) \ 356 ieee80211_find_node_debug(nt, mac, __func__, __LINE__) 357#define ieee80211_find_vap_node_locked(nt, vap, mac) \ 358 ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__) 359#define ieee80211_find_vap_node(nt, vap, mac) \ 360 ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__) 361#define ieee80211_find_rxnode(ic, wh) \ 362 ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__) 363#define ieee80211_find_rxnode_withkey(ic, wh, keyix) \ 364 ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__) 365#define ieee80211_find_txnode(vap, mac) \ 366 ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__) 367#else 368void ieee80211_free_node(struct ieee80211_node *); 369struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *, 370 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 371struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *, 372 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 373struct ieee80211_node *ieee80211_find_vap_node_locked( 374 struct ieee80211_node_table *, const struct ieee80211vap *, 375 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 376struct ieee80211_node *ieee80211_find_vap_node( 377 struct ieee80211_node_table *, const struct ieee80211vap *, 378 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 379struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *, 380 const struct ieee80211_frame_min *); 381struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *, 382 const struct ieee80211_frame_min *, uint16_t keyix); 383struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *, 384 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 385#endif 386int ieee80211_node_delucastkey(struct ieee80211_node *); 387void ieee80211_node_timeout(void *arg); 388 389typedef void ieee80211_iter_func(void *, struct ieee80211_node *); 390void ieee80211_iterate_nodes(struct ieee80211_node_table *, 391 ieee80211_iter_func *, void *); 392 393void ieee80211_notify_erp(struct ieee80211com *); 394void ieee80211_dump_node(struct ieee80211_node_table *, 395 struct ieee80211_node *); 396void ieee80211_dump_nodes(struct ieee80211_node_table *); 397 398struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *, 399 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 400struct ieee80211_scanparams; 401void ieee80211_init_neighbor(struct ieee80211_node *, 402 const struct ieee80211_frame *, 403 const struct ieee80211_scanparams *); 404struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *, 405 const struct ieee80211_frame *, 406 const struct ieee80211_scanparams *); 407void ieee80211_node_join(struct ieee80211_node *,int); 408void ieee80211_node_leave(struct ieee80211_node *); 409int8_t ieee80211_getrssi(struct ieee80211vap *); 410void ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *); 411#endif /* _NET80211_IEEE80211_NODE_H_ */ 412