ieee80211_node.h revision 172225
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 172225 2007-09-18 20:40:21Z 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 */ 123172225Ssam /* tx seq per-tid */ 124172225Ssam uint16_t ni_txseqs[IEEE80211_TID_SIZE]; 125172225Ssam /* rx seq previous per-tid*/ 126172225Ssam uint16_t ni_rxseqs[IEEE80211_TID_SIZE]; 127170530Ssam uint32_t ni_rxfragstamp; /* time stamp of last rx frag */ 128138568Ssam struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */ 129138568Ssam struct ieee80211_rsnparms ni_rsn; /* RSN/WPA parameters */ 130138568Ssam struct ieee80211_key ni_ucastkey; /* unicast key */ 131116742Ssam 132116742Ssam /* hardware */ 133170530Ssam uint32_t ni_rstamp; /* recv timestamp */ 134170530Ssam int8_t ni_rssi; /* recv ssi */ 135170530Ssam int8_t ni_noise; /* noise floor */ 136116742Ssam 137116742Ssam /* header */ 138170530Ssam uint8_t ni_macaddr[IEEE80211_ADDR_LEN]; 139170530Ssam uint8_t ni_bssid[IEEE80211_ADDR_LEN]; 140116742Ssam 141116742Ssam /* beacon, probe response */ 142138568Ssam union { 143170530Ssam uint8_t data[8]; 144170530Ssam uint64_t tsf; 145138568Ssam } ni_tstamp; /* from last rcv'd beacon */ 146170530Ssam uint16_t ni_intval; /* beacon interval */ 147170530Ssam uint16_t ni_capinfo; /* capabilities */ 148170530Ssam uint8_t ni_esslen; 149170530Ssam uint8_t ni_essid[IEEE80211_NWID_LEN]; 150116742Ssam struct ieee80211_rateset ni_rates; /* negotiated rate set */ 151170530Ssam struct ieee80211_channel *ni_chan; 152170530Ssam uint16_t ni_fhdwell; /* FH only */ 153170530Ssam uint8_t ni_fhindex; /* FH only */ 154170530Ssam uint8_t ni_erp; /* ERP from beacon/probe resp */ 155170530Ssam uint16_t ni_timoff; /* byte offset to TIM ie */ 156170530Ssam uint8_t ni_dtim_period; /* DTIM period */ 157170530Ssam uint8_t ni_dtim_count; /* DTIM count for last bcn */ 158116742Ssam 159170530Ssam /* 11n state */ 160170530Ssam uint16_t ni_htcap; /* HT capabilities */ 161170530Ssam uint8_t ni_htparam; /* HT params */ 162170530Ssam uint8_t ni_htctlchan; /* HT control channel */ 163170530Ssam uint8_t ni_ht2ndchan; /* HT 2nd channel */ 164170530Ssam uint8_t ni_htopmode; /* HT operating mode */ 165170530Ssam uint8_t ni_htstbc; /* HT */ 166170530Ssam uint8_t ni_reqcw; /* requested tx channel width */ 167170530Ssam uint8_t ni_chw; /* negotiated channel width */ 168170530Ssam struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */ 169170530Ssam struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC]; 170170530Ssam struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID]; 171170530Ssam 172116742Ssam /* others */ 173116742Ssam int ni_fails; /* failure count to associate */ 174138568Ssam short ni_inact; /* inactivity mark count */ 175138568Ssam short ni_inact_reload;/* inactivity reload value */ 176116742Ssam int ni_txrate; /* index to ni_rates[] */ 177138568Ssam struct ifqueue ni_savedq; /* ps-poll queue */ 178138568Ssam struct ieee80211_nodestats ni_stats; /* per-node statistics */ 179116742Ssam}; 180138568SsamMALLOC_DECLARE(M_80211_NODE); 181116742Ssam 182170530Ssam#define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP) 183170530Ssam 184138568Ssam#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd) 185138568Ssam 186138568Ssam#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++) 187138568Ssam#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v) 188138568Ssam#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v) 189138568Ssam 190116742Ssamstatic __inline struct ieee80211_node * 191116742Ssamieee80211_ref_node(struct ieee80211_node *ni) 192116742Ssam{ 193138568Ssam ieee80211_node_incref(ni); 194116742Ssam return ni; 195116742Ssam} 196116742Ssam 197116742Ssamstatic __inline void 198116742Ssamieee80211_unref_node(struct ieee80211_node **ni) 199116742Ssam{ 200138568Ssam ieee80211_node_decref(*ni); 201116742Ssam *ni = NULL; /* guard against use */ 202116742Ssam} 203116742Ssam 204116742Ssamstruct ieee80211com; 205116742Ssam 206144618Ssamvoid ieee80211_node_attach(struct ieee80211com *); 207144618Ssamvoid ieee80211_node_lateattach(struct ieee80211com *); 208144618Ssamvoid ieee80211_node_detach(struct ieee80211com *); 209127877Ssam 210138568Ssamstatic __inline int 211138568Ssamieee80211_node_is_authorized(const struct ieee80211_node *ni) 212138568Ssam{ 213138568Ssam return (ni->ni_flags & IEEE80211_NODE_AUTH); 214138568Ssam} 215116742Ssam 216148302Ssamvoid ieee80211_node_authorize(struct ieee80211_node *); 217148302Ssamvoid ieee80211_node_unauthorize(struct ieee80211_node *); 218138568Ssam 219156358Ssamvoid ieee80211_probe_curchan(struct ieee80211com *, int); 220144618Ssamvoid ieee80211_create_ibss(struct ieee80211com*, struct ieee80211_channel *); 221144618Ssamvoid ieee80211_reset_bss(struct ieee80211com *); 222148306Ssamint ieee80211_ibss_merge(struct ieee80211_node *); 223170530Ssamstruct ieee80211_scan_entry; 224170530Ssamint ieee80211_sta_join(struct ieee80211com *, 225170530Ssam const struct ieee80211_scan_entry *); 226144618Ssamvoid ieee80211_sta_leave(struct ieee80211com *, struct ieee80211_node *); 227138568Ssam 228138568Ssam/* 229138568Ssam * Table of ieee80211_node instances. Each ieee80211com 230138568Ssam * has at least one for holding the scan candidates. 231138568Ssam * When operating as an access point or in ibss mode there 232138568Ssam * is a second table for associated stations or neighbors. 233138568Ssam */ 234138568Ssamstruct ieee80211_node_table { 235138568Ssam struct ieee80211com *nt_ic; /* back reference */ 236138568Ssam ieee80211_node_lock_t nt_nodelock; /* on node table */ 237138568Ssam TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */ 238138568Ssam LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE]; 239170530Ssam struct ieee80211_node **nt_keyixmap; /* key ix -> node map */ 240170530Ssam int nt_keyixmax; /* keyixmap size */ 241138568Ssam const char *nt_name; /* for debugging */ 242138568Ssam ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */ 243138568Ssam u_int nt_scangen; /* gen# for timeout scan */ 244138568Ssam int nt_inact_init; /* initial node inact setting */ 245138568Ssam}; 246138568Ssam 247144618Ssamstruct ieee80211_node *ieee80211_alloc_node( 248170530Ssam struct ieee80211_node_table *, const uint8_t *); 249148777Ssamstruct ieee80211_node *ieee80211_tmp_node(struct ieee80211com *, 250170530Ssam const uint8_t *macaddr); 251144618Ssamstruct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *, 252170530Ssam const uint8_t *); 253138568Ssam#ifdef IEEE80211_DEBUG_REFCNT 254144618Ssamvoid ieee80211_free_node_debug(struct ieee80211_node *, 255138568Ssam const char *func, int line); 256170530Ssamstruct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *, 257170530Ssam const uint8_t *, 258138568Ssam const char *func, int line); 259170530Ssamstruct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *, 260170530Ssam const struct ieee80211_frame_min *, 261138568Ssam const char *func, int line); 262148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 263148863Ssam struct ieee80211com *, 264170530Ssam const struct ieee80211_frame_min *, uint16_t keyix, 265148863Ssam const char *func, int line); 266170530Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 267170530Ssam struct ieee80211com *, 268170530Ssam const struct ieee80211_frame_min *, uint16_t keyix, 269138568Ssam const char *func, int line); 270170530Ssamstruct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211com *, 271170530Ssam const uint8_t *, 272170530Ssam const char *func, int line); 273144618Ssamstruct ieee80211_node *ieee80211_find_node_with_ssid_debug( 274170530Ssam struct ieee80211_node_table *, const uint8_t *macaddr, 275170530Ssam u_int ssidlen, const uint8_t *ssid, 276138568Ssam const char *func, int line); 277138568Ssam#define ieee80211_free_node(ni) \ 278138568Ssam ieee80211_free_node_debug(ni, __func__, __LINE__) 279138568Ssam#define ieee80211_find_node(nt, mac) \ 280138568Ssam ieee80211_find_node_debug(nt, mac, __func__, __LINE__) 281138568Ssam#define ieee80211_find_rxnode(nt, wh) \ 282138568Ssam ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__) 283148863Ssam#define ieee80211_find_rxnode_withkey(nt, wh, keyix) \ 284148863Ssam ieee80211_find_rxnode_withkey_debug(nt, wh, keyix, __func__, __LINE__) 285138568Ssam#define ieee80211_find_txnode(nt, mac) \ 286138568Ssam ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__) 287138568Ssam#define ieee80211_find_node_with_ssid(nt, mac, sl, ss) \ 288138568Ssam ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__) 289138568Ssam#else 290144618Ssamvoid ieee80211_free_node(struct ieee80211_node *); 291170530Ssamstruct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *, 292170530Ssam const uint8_t *); 293170530Ssamstruct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *, 294170530Ssam const struct ieee80211_frame_min *); 295148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *, 296170530Ssam const struct ieee80211_frame_min *, uint16_t keyix); 297170530Ssamstruct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 298170530Ssam const uint8_t *); 299144618Ssamstruct ieee80211_node *ieee80211_find_node_with_ssid( 300170530Ssam struct ieee80211_node_table *, const uint8_t *macaddr, 301170530Ssam u_int ssidlen, const uint8_t *ssid); 302138568Ssam#endif 303148863Ssamint ieee80211_node_delucastkey(struct ieee80211_node *); 304170530Ssamvoid ieee80211_node_timeout(void *arg); 305138568Ssam 306116742Ssamtypedef void ieee80211_iter_func(void *, struct ieee80211_node *); 307144618Ssamvoid ieee80211_iterate_nodes(struct ieee80211_node_table *, 308116742Ssam ieee80211_iter_func *, void *); 309116742Ssam 310144618Ssamvoid ieee80211_dump_node(struct ieee80211_node_table *, 311138568Ssam struct ieee80211_node *); 312144618Ssamvoid ieee80211_dump_nodes(struct ieee80211_node_table *); 313138568Ssam 314172211Ssamvoid ieee80211_notify_erp(struct ieee80211com *); 315172211Ssam 316144618Ssamstruct ieee80211_node *ieee80211_fakeup_adhoc_node( 317170530Ssam struct ieee80211_node_table *, const uint8_t macaddr[]); 318170530Ssamstruct ieee80211_scanparams; 319153073Ssamvoid ieee80211_init_neighbor(struct ieee80211_node *, 320153073Ssam const struct ieee80211_frame *, 321153073Ssam const struct ieee80211_scanparams *); 322148936Ssamstruct ieee80211_node *ieee80211_add_neighbor(struct ieee80211com *, 323148936Ssam const struct ieee80211_frame *, 324148936Ssam const struct ieee80211_scanparams *); 325170530Ssamvoid ieee80211_node_join(struct ieee80211com *, struct ieee80211_node *,int); 326170530Ssamvoid ieee80211_node_leave(struct ieee80211com *, struct ieee80211_node *); 327170530Ssamint8_t ieee80211_getrssi(struct ieee80211com *); 328170530Ssamvoid ieee80211_getsignal(struct ieee80211com *, int8_t *, int8_t *); 329116742Ssam#endif /* _NET80211_IEEE80211_NODE_H_ */ 330