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 uint16_t ni_ath_defkeyix;/* Atheros def key index */ 115 uint16_t ni_associd; /* assoc response */ 116 uint16_t ni_txpower; /* current transmit power */ 117 uint16_t ni_vlan; /* vlan tag */ 118 uint32_t *ni_challenge; /* shared-key challenge */ 119 uint8_t *ni_wpa_ie; /* captured WPA ie */ 120 uint8_t *ni_rsn_ie; /* captured RSN ie */ 121 uint8_t *ni_wme_ie; /* captured WME ie */ 122 uint8_t *ni_ath_ie; /* captured Atheros ie */ 123 /* tx seq per-tid */ 124 uint16_t ni_txseqs[IEEE80211_TID_SIZE]; 125 /* rx seq previous per-tid*/ 126 uint16_t ni_rxseqs[IEEE80211_TID_SIZE]; 127 uint32_t ni_rxfragstamp; /* time stamp of last rx frag */ 128 struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */ 129 struct ieee80211_rsnparms ni_rsn; /* RSN/WPA parameters */ 130 struct ieee80211_key ni_ucastkey; /* unicast key */ 131 132 /* hardware */ 133 uint32_t ni_rstamp; /* recv timestamp */ 134 int8_t ni_rssi; /* recv ssi */ 135 int8_t ni_noise; /* noise floor */ 136 137 /* header */ 138 uint8_t ni_macaddr[IEEE80211_ADDR_LEN]; 139 uint8_t ni_bssid[IEEE80211_ADDR_LEN]; 140 141 /* beacon, probe response */ 142 union { 143 uint8_t data[8]; 144 uint64_t tsf; 145 } ni_tstamp; /* from last rcv'd beacon */ 146 uint16_t ni_intval; /* beacon interval */ 147 uint16_t ni_capinfo; /* capabilities */ 148 uint8_t ni_esslen; 149 uint8_t ni_essid[IEEE80211_NWID_LEN]; 150 struct ieee80211_rateset ni_rates; /* negotiated rate set */ 151 struct ieee80211_channel *ni_chan; 152 uint16_t ni_fhdwell; /* FH only */ 153 uint8_t ni_fhindex; /* FH only */ 154 uint8_t ni_erp; /* ERP from beacon/probe resp */ 155 uint16_t ni_timoff; /* byte offset to TIM ie */ 156 uint8_t ni_dtim_period; /* DTIM period */ 157 uint8_t ni_dtim_count; /* DTIM count for last bcn */ 158 159 /* 11n state */ 160 uint16_t ni_htcap; /* HT capabilities */ 161 uint8_t ni_htparam; /* HT params */ 162 uint8_t ni_htctlchan; /* HT control channel */ 163 uint8_t ni_ht2ndchan; /* HT 2nd channel */ 164 uint8_t ni_htopmode; /* HT operating mode */ 165 uint8_t ni_htstbc; /* HT */ 166 uint8_t ni_reqcw; /* requested tx channel width */ 167 uint8_t ni_chw; /* negotiated channel width */ 168 struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */ 169 struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC]; 170 struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID]; 171 172 /* others */ 173 int ni_fails; /* failure count to associate */ 174 short ni_inact; /* inactivity mark count */ 175 short ni_inact_reload;/* inactivity reload value */ 176 int ni_txrate; /* index to ni_rates[] */ 177 struct ifqueue ni_savedq; /* ps-poll queue */ 178 struct ieee80211_nodestats ni_stats; /* per-node statistics */ 179 }; 180 MALLOC_DECLARE(M_80211_NODE); 181 182 #define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP) 183 184 #define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd) 185 186 #define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++) 187 #define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v) 188 #define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v) 189 190 static __inline struct ieee80211_node * 191 ieee80211_ref_node(struct ieee80211_node *ni) 192 { 193 ieee80211_node_incref(ni); 194 return ni; 195 } 196 197 static __inline void 198 ieee80211_unref_node(struct ieee80211_node **ni) 199 { 200 ieee80211_node_decref(*ni); 201 *ni = NULL; /* guard against use */ 202 } 203 204 struct ieee80211com; 205 206 void ieee80211_node_attach(struct ieee80211com *); 207 void ieee80211_node_lateattach(struct ieee80211com *); 208 void ieee80211_node_detach(struct ieee80211com *); 209 210 static __inline int 211 ieee80211_node_is_authorized(const struct ieee80211_node *ni) 212 { 213 return (ni->ni_flags & IEEE80211_NODE_AUTH); 214 } 215 216 void ieee80211_node_authorize(struct ieee80211_node *); 217 void ieee80211_node_unauthorize(struct ieee80211_node *); 218 219 void ieee80211_probe_curchan(struct ieee80211com *, int); 220 void ieee80211_create_ibss(struct ieee80211com*, struct ieee80211_channel *); 221 void ieee80211_reset_bss(struct ieee80211com *); 222 int ieee80211_ibss_merge(struct ieee80211_node *); 223 struct ieee80211_scan_entry; 224 int ieee80211_sta_join(struct ieee80211com *, 225 const struct ieee80211_scan_entry *); 226 void ieee80211_sta_leave(struct ieee80211com *, struct ieee80211_node *); 227 228 /* 229 * Table of ieee80211_node instances. Each ieee80211com 230 * has at least one for holding the scan candidates. 231 * When operating as an access point or in ibss mode there 232 * is a second table for associated stations or neighbors. 233 */ 234 struct ieee80211_node_table { 235 struct ieee80211com *nt_ic; /* back reference */ 236 ieee80211_node_lock_t nt_nodelock; /* on node table */ 237 TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */ 238 LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE]; 239 struct ieee80211_node **nt_keyixmap; /* key ix -> node map */ 240 int nt_keyixmax; /* keyixmap size */ 241 const char *nt_name; /* for debugging */ 242 ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */ 243 u_int nt_scangen; /* gen# for timeout scan */ 244 int nt_inact_init; /* initial node inact setting */ 245 }; 246 247 struct ieee80211_node *ieee80211_alloc_node( 248 struct ieee80211_node_table *, const uint8_t *); 249 struct ieee80211_node *ieee80211_tmp_node(struct ieee80211com *, 250 const uint8_t *macaddr); 251 struct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *, 252 const uint8_t *); 253 #ifdef IEEE80211_DEBUG_REFCNT 254 void ieee80211_free_node_debug(struct ieee80211_node *, 255 const char *func, int line); 256 struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *, 257 const uint8_t *, 258 const char *func, int line); 259 struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *, 260 const struct ieee80211_frame_min *, 261 const char *func, int line); 262 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 263 struct ieee80211com *, 264 const struct ieee80211_frame_min *, uint16_t keyix, 265 const char *func, int line); 266 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 267 struct ieee80211com *, 268 const struct ieee80211_frame_min *, uint16_t keyix, 269 const char *func, int line); 270 struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211com *, 271 const uint8_t *, 272 const char *func, int line); 273 struct ieee80211_node *ieee80211_find_node_with_ssid_debug( 274 struct ieee80211_node_table *, const uint8_t *macaddr, 275 u_int ssidlen, const uint8_t *ssid, 276 const char *func, int line); 277 #define ieee80211_free_node(ni) \ 278 ieee80211_free_node_debug(ni, __func__, __LINE__) 279 #define ieee80211_find_node(nt, mac) \ 280 ieee80211_find_node_debug(nt, mac, __func__, __LINE__) 281 #define ieee80211_find_rxnode(nt, wh) \ 282 ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__) 283 #define ieee80211_find_rxnode_withkey(nt, wh, keyix) \ 284 ieee80211_find_rxnode_withkey_debug(nt, wh, keyix, __func__, __LINE__) 285 #define ieee80211_find_txnode(nt, mac) \ 286 ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__) 287 #define ieee80211_find_node_with_ssid(nt, mac, sl, ss) \ 288 ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__) 289 #else 290 void ieee80211_free_node(struct ieee80211_node *); 291 struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *, 292 const uint8_t *); 293 struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *, 294 const struct ieee80211_frame_min *); 295 struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *, 296 const struct ieee80211_frame_min *, uint16_t keyix); 297 struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 298 const uint8_t *); 299 struct ieee80211_node *ieee80211_find_node_with_ssid( 300 struct ieee80211_node_table *, const uint8_t *macaddr, 301 u_int ssidlen, const uint8_t *ssid); 302 #endif 303 int ieee80211_node_delucastkey(struct ieee80211_node *); 304 void ieee80211_node_timeout(void *arg); 305 306 typedef void ieee80211_iter_func(void *, struct ieee80211_node *); 307 void ieee80211_iterate_nodes(struct ieee80211_node_table *, 308 ieee80211_iter_func *, void *); 309 310 void ieee80211_dump_node(struct ieee80211_node_table *, 311 struct ieee80211_node *); 312 void ieee80211_dump_nodes(struct ieee80211_node_table *); 313 314 void ieee80211_notify_erp(struct ieee80211com *); 315 316 struct ieee80211_node *ieee80211_fakeup_adhoc_node( 317 struct ieee80211_node_table *, const uint8_t macaddr[]); 318 struct ieee80211_scanparams; 319 void ieee80211_init_neighbor(struct ieee80211_node *, 320 const struct ieee80211_frame *, 321 const struct ieee80211_scanparams *); 322 struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211com *, 323 const struct ieee80211_frame *, 324 const struct ieee80211_scanparams *); 325 void ieee80211_node_join(struct ieee80211com *, struct ieee80211_node *,int); 326 void ieee80211_node_leave(struct ieee80211com *, struct ieee80211_node *); 327 int8_t ieee80211_getrssi(struct ieee80211com *); 328 void ieee80211_getsignal(struct ieee80211com *, int8_t *, int8_t *); 329 #endif /* _NET80211_IEEE80211_NODE_H_ */ 330