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