ieee80211_node.h revision 172211
1116742Ssam/*- 2116904Ssam * Copyright (c) 2001 Atsushi Onoe 3170360Ssam * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting 4116742Ssam * All rights reserved. 5116742Ssam * 6116742Ssam * Redistribution and use in source and binary forms, with or without 7116742Ssam * modification, are permitted provided that the following conditions 8116742Ssam * are met: 9116742Ssam * 1. Redistributions of source code must retain the above copyright 10116742Ssam * notice, this list of conditions and the following disclaimer. 11116742Ssam * 2. Redistributions in binary form must reproduce the above copyright 12116742Ssam * notice, this list of conditions and the following disclaimer in the 13116742Ssam * documentation and/or other materials provided with the distribution. 14116742Ssam * 15116904Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16116904Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17116904Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18116904Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19116904Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20116904Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21116904Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22116904Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23116904Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24116904Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25116904Ssam * 26116742Ssam * $FreeBSD: head/sys/net80211/ieee80211_node.h 172211 2007-09-17 19:07:24Z sam $ 27116742Ssam */ 28116742Ssam#ifndef _NET80211_IEEE80211_NODE_H_ 29116742Ssam#define _NET80211_IEEE80211_NODE_H_ 30116742Ssam 31138568Ssam#include <net80211/ieee80211_ioctl.h> /* for ieee80211_nodestats */ 32170530Ssam#include <net80211/ieee80211_ht.h> /* for aggregation state */ 33116742Ssam 34138568Ssam/* 35138568Ssam * Each ieee80211com instance has a single timer that fires once a 36138568Ssam * second. This is used to initiate various work depending on the 37138568Ssam * state of the instance: scanning (passive or active), ``transition'' 38138568Ssam * (waiting for a response to a management frame when operating 39138568Ssam * as a station), and node inactivity processing (when operating 40138568Ssam * as an AP). For inactivity processing each node has a timeout 41138568Ssam * set in it's ni_inact field that is decremented on each timeout 42138568Ssam * and the node is reclaimed when the counter goes to zero. We 43138568Ssam * use different inactivity timeout values depending on whether 44138568Ssam * the node is associated and authorized (either by 802.1x or 45138568Ssam * open/shared key authentication) or associated but yet to be 46138568Ssam * authorized. The latter timeout is shorter to more aggressively 47138568Ssam * reclaim nodes that leave part way through the 802.1x exchange. 48138568Ssam */ 49138568Ssam#define IEEE80211_INACT_WAIT 15 /* inactivity interval (secs) */ 50138568Ssam#define IEEE80211_INACT_INIT (30/IEEE80211_INACT_WAIT) /* initial */ 51138568Ssam#define IEEE80211_INACT_AUTH (180/IEEE80211_INACT_WAIT) /* associated but not authorized */ 52138568Ssam#define IEEE80211_INACT_RUN (300/IEEE80211_INACT_WAIT) /* authorized */ 53138568Ssam#define IEEE80211_INACT_PROBE (30/IEEE80211_INACT_WAIT) /* probe */ 54138568Ssam#define IEEE80211_INACT_SCAN (300/IEEE80211_INACT_WAIT) /* scanned */ 55138568Ssam 56170530Ssam#define IEEE80211_TRANS_WAIT 2 /* mgt frame tx timer (secs) */ 57138568Ssam 58172211Ssam/* threshold for aging overlapping non-ERP bss */ 59172211Ssam#define IEEE80211_NONERP_PRESENT_AGE msecs_to_ticks(60*1000) 60172211Ssam 61116742Ssam#define IEEE80211_NODE_HASHSIZE 32 62116742Ssam/* simple hash is enough for variation of macaddr */ 63116742Ssam#define IEEE80211_NODE_HASH(addr) \ 64170530Ssam (((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \ 65138568Ssam IEEE80211_NODE_HASHSIZE) 66116742Ssam 67138568Ssamstruct ieee80211_rsnparms { 68170530Ssam uint8_t rsn_mcastcipher; /* mcast/group cipher */ 69170530Ssam uint8_t rsn_mcastkeylen; /* mcast key length */ 70170530Ssam uint8_t rsn_ucastcipherset; /* unicast cipher set */ 71170530Ssam uint8_t rsn_ucastcipher; /* selected unicast cipher */ 72170530Ssam uint8_t rsn_ucastkeylen; /* unicast key length */ 73170530Ssam uint8_t rsn_keymgmtset; /* key mangement algorithms */ 74170530Ssam uint8_t rsn_keymgmt; /* selected key mgmt algo */ 75170530Ssam uint16_t rsn_caps; /* capabilities */ 76116742Ssam}; 77116742Ssam 78138568Ssamstruct ieee80211_node_table; 79138568Ssamstruct ieee80211com; 80138568Ssam 81116742Ssam/* 82116742Ssam * Node specific information. Note that drivers are expected 83116742Ssam * to derive from this structure to add device-specific per-node 84116742Ssam * state. This is done by overriding the ic_node_* methods in 85116742Ssam * the ieee80211com structure. 86116742Ssam */ 87116742Ssamstruct ieee80211_node { 88138568Ssam struct ieee80211com *ni_ic; 89138568Ssam struct ieee80211_node_table *ni_table; 90116742Ssam TAILQ_ENTRY(ieee80211_node) ni_list; 91116742Ssam LIST_ENTRY(ieee80211_node) ni_hash; 92116742Ssam u_int ni_refcnt; 93120483Ssam u_int ni_scangen; /* gen# for timeout scan */ 94170530Ssam uint8_t ni_authmode; /* authentication algorithm */ 95170530Ssam uint8_t ni_ath_flags; /* Atheros feature flags */ 96170530Ssam /* NB: These must have the same values as IEEE80211_ATHC_* */ 97170530Ssam#define IEEE80211_NODE_TURBOP 0x0001 /* Turbo prime enable */ 98170530Ssam#define IEEE80211_NODE_COMP 0x0002 /* Compresssion enable */ 99170530Ssam#define IEEE80211_NODE_FF 0x0004 /* Fast Frame capable */ 100170530Ssam#define IEEE80211_NODE_XR 0x0008 /* Atheros WME enable */ 101170530Ssam#define IEEE80211_NODE_AR 0x0010 /* AR capable */ 102170530Ssam#define IEEE80211_NODE_BOOST 0x0080 103170530Ssam#define IEEE80211_NODE_PSUPDATE 0x0200 /* power save state changed */ 104170530Ssam#define IEEE80211_NODE_CHWUPDATE 0x0400 /* 11n channel width change */ 105170530Ssam uint16_t ni_flags; /* special-purpose state */ 106138568Ssam#define IEEE80211_NODE_AUTH 0x0001 /* authorized for data */ 107138568Ssam#define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */ 108138568Ssam#define IEEE80211_NODE_ERP 0x0004 /* ERP enabled */ 109138568Ssam/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */ 110138568Ssam#define IEEE80211_NODE_PWR_MGT 0x0010 /* power save mode enabled */ 111147788Ssam#define IEEE80211_NODE_AREF 0x0020 /* authentication ref held */ 112170530Ssam#define IEEE80211_NODE_HT 0x0040 /* HT enabled */ 113170530Ssam#define IEEE80211_NODE_HTCOMPAT 0x0080 /* HT setup w/ vendor OUI's */ 114170530Ssam uint16_t ni_ath_defkeyix;/* Atheros def key index */ 115170530Ssam uint16_t ni_associd; /* assoc response */ 116170530Ssam uint16_t ni_txpower; /* current transmit power */ 117170530Ssam uint16_t ni_vlan; /* vlan tag */ 118170530Ssam uint32_t *ni_challenge; /* shared-key challenge */ 119170530Ssam uint8_t *ni_wpa_ie; /* captured WPA ie */ 120170530Ssam uint8_t *ni_rsn_ie; /* captured RSN ie */ 121170530Ssam uint8_t *ni_wme_ie; /* captured WME ie */ 122170530Ssam uint8_t *ni_ath_ie; /* captured Atheros ie */ 123167439Ssam#define IEEE80211_NONQOS_TID 16 /* index for non-QoS sta */ 124170530Ssam uint16_t ni_txseqs[17]; /* tx seq per-tid */ 125170530Ssam uint16_t ni_rxseqs[17]; /* rx seq previous per-tid*/ 126170530Ssam uint32_t ni_rxfragstamp; /* time stamp of last rx frag */ 127138568Ssam struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */ 128138568Ssam struct ieee80211_rsnparms ni_rsn; /* RSN/WPA parameters */ 129138568Ssam struct ieee80211_key ni_ucastkey; /* unicast key */ 130116742Ssam 131116742Ssam /* hardware */ 132170530Ssam uint32_t ni_rstamp; /* recv timestamp */ 133170530Ssam int8_t ni_rssi; /* recv ssi */ 134170530Ssam int8_t ni_noise; /* noise floor */ 135116742Ssam 136116742Ssam /* header */ 137170530Ssam uint8_t ni_macaddr[IEEE80211_ADDR_LEN]; 138170530Ssam uint8_t ni_bssid[IEEE80211_ADDR_LEN]; 139116742Ssam 140116742Ssam /* beacon, probe response */ 141138568Ssam union { 142170530Ssam uint8_t data[8]; 143170530Ssam uint64_t tsf; 144138568Ssam } ni_tstamp; /* from last rcv'd beacon */ 145170530Ssam uint16_t ni_intval; /* beacon interval */ 146170530Ssam uint16_t ni_capinfo; /* capabilities */ 147170530Ssam uint8_t ni_esslen; 148170530Ssam uint8_t ni_essid[IEEE80211_NWID_LEN]; 149116742Ssam struct ieee80211_rateset ni_rates; /* negotiated rate set */ 150170530Ssam struct ieee80211_channel *ni_chan; 151170530Ssam uint16_t ni_fhdwell; /* FH only */ 152170530Ssam uint8_t ni_fhindex; /* FH only */ 153170530Ssam uint8_t ni_erp; /* ERP from beacon/probe resp */ 154170530Ssam uint16_t ni_timoff; /* byte offset to TIM ie */ 155170530Ssam uint8_t ni_dtim_period; /* DTIM period */ 156170530Ssam uint8_t ni_dtim_count; /* DTIM count for last bcn */ 157116742Ssam 158170530Ssam /* 11n state */ 159170530Ssam uint16_t ni_htcap; /* HT capabilities */ 160170530Ssam uint8_t ni_htparam; /* HT params */ 161170530Ssam uint8_t ni_htctlchan; /* HT control channel */ 162170530Ssam uint8_t ni_ht2ndchan; /* HT 2nd channel */ 163170530Ssam uint8_t ni_htopmode; /* HT operating mode */ 164170530Ssam uint8_t ni_htstbc; /* HT */ 165170530Ssam uint8_t ni_reqcw; /* requested tx channel width */ 166170530Ssam uint8_t ni_chw; /* negotiated channel width */ 167170530Ssam struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */ 168170530Ssam struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC]; 169170530Ssam struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID]; 170170530Ssam 171116742Ssam /* others */ 172116742Ssam int ni_fails; /* failure count to associate */ 173138568Ssam short ni_inact; /* inactivity mark count */ 174138568Ssam short ni_inact_reload;/* inactivity reload value */ 175116742Ssam int ni_txrate; /* index to ni_rates[] */ 176138568Ssam struct ifqueue ni_savedq; /* ps-poll queue */ 177138568Ssam struct ieee80211_nodestats ni_stats; /* per-node statistics */ 178116742Ssam}; 179138568SsamMALLOC_DECLARE(M_80211_NODE); 180116742Ssam 181170530Ssam#define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP) 182170530Ssam 183138568Ssam#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd) 184138568Ssam 185138568Ssam#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++) 186138568Ssam#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v) 187138568Ssam#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v) 188138568Ssam 189116742Ssamstatic __inline struct ieee80211_node * 190116742Ssamieee80211_ref_node(struct ieee80211_node *ni) 191116742Ssam{ 192138568Ssam ieee80211_node_incref(ni); 193116742Ssam return ni; 194116742Ssam} 195116742Ssam 196116742Ssamstatic __inline void 197116742Ssamieee80211_unref_node(struct ieee80211_node **ni) 198116742Ssam{ 199138568Ssam ieee80211_node_decref(*ni); 200116742Ssam *ni = NULL; /* guard against use */ 201116742Ssam} 202116742Ssam 203116742Ssamstruct ieee80211com; 204116742Ssam 205144618Ssamvoid ieee80211_node_attach(struct ieee80211com *); 206144618Ssamvoid ieee80211_node_lateattach(struct ieee80211com *); 207144618Ssamvoid ieee80211_node_detach(struct ieee80211com *); 208127877Ssam 209138568Ssamstatic __inline int 210138568Ssamieee80211_node_is_authorized(const struct ieee80211_node *ni) 211138568Ssam{ 212138568Ssam return (ni->ni_flags & IEEE80211_NODE_AUTH); 213138568Ssam} 214116742Ssam 215148302Ssamvoid ieee80211_node_authorize(struct ieee80211_node *); 216148302Ssamvoid ieee80211_node_unauthorize(struct ieee80211_node *); 217138568Ssam 218156358Ssamvoid ieee80211_probe_curchan(struct ieee80211com *, int); 219144618Ssamvoid ieee80211_create_ibss(struct ieee80211com*, struct ieee80211_channel *); 220144618Ssamvoid ieee80211_reset_bss(struct ieee80211com *); 221148306Ssamint ieee80211_ibss_merge(struct ieee80211_node *); 222170530Ssamstruct ieee80211_scan_entry; 223170530Ssamint ieee80211_sta_join(struct ieee80211com *, 224170530Ssam const struct ieee80211_scan_entry *); 225144618Ssamvoid ieee80211_sta_leave(struct ieee80211com *, struct ieee80211_node *); 226138568Ssam 227138568Ssam/* 228138568Ssam * Table of ieee80211_node instances. Each ieee80211com 229138568Ssam * has at least one for holding the scan candidates. 230138568Ssam * When operating as an access point or in ibss mode there 231138568Ssam * is a second table for associated stations or neighbors. 232138568Ssam */ 233138568Ssamstruct ieee80211_node_table { 234138568Ssam struct ieee80211com *nt_ic; /* back reference */ 235138568Ssam ieee80211_node_lock_t nt_nodelock; /* on node table */ 236138568Ssam TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */ 237138568Ssam LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE]; 238170530Ssam struct ieee80211_node **nt_keyixmap; /* key ix -> node map */ 239170530Ssam int nt_keyixmax; /* keyixmap size */ 240138568Ssam const char *nt_name; /* for debugging */ 241138568Ssam ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */ 242138568Ssam u_int nt_scangen; /* gen# for timeout scan */ 243138568Ssam int nt_inact_init; /* initial node inact setting */ 244138568Ssam}; 245138568Ssam 246144618Ssamstruct ieee80211_node *ieee80211_alloc_node( 247170530Ssam struct ieee80211_node_table *, const uint8_t *); 248148777Ssamstruct ieee80211_node *ieee80211_tmp_node(struct ieee80211com *, 249170530Ssam const uint8_t *macaddr); 250144618Ssamstruct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *, 251170530Ssam const uint8_t *); 252138568Ssam#ifdef IEEE80211_DEBUG_REFCNT 253144618Ssamvoid ieee80211_free_node_debug(struct ieee80211_node *, 254138568Ssam const char *func, int line); 255170530Ssamstruct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *, 256170530Ssam const uint8_t *, 257138568Ssam const char *func, int line); 258170530Ssamstruct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *, 259170530Ssam const struct ieee80211_frame_min *, 260138568Ssam const char *func, int line); 261148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 262148863Ssam struct ieee80211com *, 263170530Ssam const struct ieee80211_frame_min *, uint16_t keyix, 264148863Ssam const char *func, int line); 265170530Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 266170530Ssam struct ieee80211com *, 267170530Ssam const struct ieee80211_frame_min *, uint16_t keyix, 268138568Ssam const char *func, int line); 269170530Ssamstruct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211com *, 270170530Ssam const uint8_t *, 271170530Ssam const char *func, int line); 272144618Ssamstruct ieee80211_node *ieee80211_find_node_with_ssid_debug( 273170530Ssam struct ieee80211_node_table *, const uint8_t *macaddr, 274170530Ssam u_int ssidlen, const uint8_t *ssid, 275138568Ssam const char *func, int line); 276138568Ssam#define ieee80211_free_node(ni) \ 277138568Ssam ieee80211_free_node_debug(ni, __func__, __LINE__) 278138568Ssam#define ieee80211_find_node(nt, mac) \ 279138568Ssam ieee80211_find_node_debug(nt, mac, __func__, __LINE__) 280138568Ssam#define ieee80211_find_rxnode(nt, wh) \ 281138568Ssam ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__) 282148863Ssam#define ieee80211_find_rxnode_withkey(nt, wh, keyix) \ 283148863Ssam ieee80211_find_rxnode_withkey_debug(nt, wh, keyix, __func__, __LINE__) 284138568Ssam#define ieee80211_find_txnode(nt, mac) \ 285138568Ssam ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__) 286138568Ssam#define ieee80211_find_node_with_ssid(nt, mac, sl, ss) \ 287138568Ssam ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__) 288138568Ssam#else 289144618Ssamvoid ieee80211_free_node(struct ieee80211_node *); 290170530Ssamstruct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *, 291170530Ssam const uint8_t *); 292170530Ssamstruct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *, 293170530Ssam const struct ieee80211_frame_min *); 294148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *, 295170530Ssam const struct ieee80211_frame_min *, uint16_t keyix); 296170530Ssamstruct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 297170530Ssam const uint8_t *); 298144618Ssamstruct ieee80211_node *ieee80211_find_node_with_ssid( 299170530Ssam struct ieee80211_node_table *, const uint8_t *macaddr, 300170530Ssam u_int ssidlen, const uint8_t *ssid); 301138568Ssam#endif 302148863Ssamint ieee80211_node_delucastkey(struct ieee80211_node *); 303170530Ssamvoid ieee80211_node_timeout(void *arg); 304138568Ssam 305116742Ssamtypedef void ieee80211_iter_func(void *, struct ieee80211_node *); 306144618Ssamvoid ieee80211_iterate_nodes(struct ieee80211_node_table *, 307116742Ssam ieee80211_iter_func *, void *); 308116742Ssam 309144618Ssamvoid ieee80211_dump_node(struct ieee80211_node_table *, 310138568Ssam struct ieee80211_node *); 311144618Ssamvoid ieee80211_dump_nodes(struct ieee80211_node_table *); 312138568Ssam 313172211Ssamvoid ieee80211_notify_erp(struct ieee80211com *); 314172211Ssam 315144618Ssamstruct ieee80211_node *ieee80211_fakeup_adhoc_node( 316170530Ssam struct ieee80211_node_table *, const uint8_t macaddr[]); 317170530Ssamstruct ieee80211_scanparams; 318153073Ssamvoid ieee80211_init_neighbor(struct ieee80211_node *, 319153073Ssam const struct ieee80211_frame *, 320153073Ssam const struct ieee80211_scanparams *); 321148936Ssamstruct ieee80211_node *ieee80211_add_neighbor(struct ieee80211com *, 322148936Ssam const struct ieee80211_frame *, 323148936Ssam const struct ieee80211_scanparams *); 324170530Ssamvoid ieee80211_node_join(struct ieee80211com *, struct ieee80211_node *,int); 325170530Ssamvoid ieee80211_node_leave(struct ieee80211com *, struct ieee80211_node *); 326170530Ssamint8_t ieee80211_getrssi(struct ieee80211com *); 327170530Ssamvoid ieee80211_getsignal(struct ieee80211com *, int8_t *, int8_t *); 328116742Ssam#endif /* _NET80211_IEEE80211_NODE_H_ */ 329