ieee80211_node.h revision 173273
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 173273 2007-11-02 05:22:25Z 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 */ 114173273Ssam#define IEEE80211_NODE_AMPDU_RX 0x0400 /* AMPDU rx enabled */ 115173273Ssam#define IEEE80211_NODE_AMPDU_TX 0x0800 /* AMPDU tx enabled */ 116170530Ssam uint16_t ni_ath_defkeyix;/* Atheros def key index */ 117170530Ssam uint16_t ni_associd; /* assoc response */ 118170530Ssam uint16_t ni_txpower; /* current transmit power */ 119170530Ssam uint16_t ni_vlan; /* vlan tag */ 120173273Ssam uint32_t ni_jointime; /* time of join (secs) */ 121170530Ssam uint32_t *ni_challenge; /* shared-key challenge */ 122170530Ssam uint8_t *ni_wpa_ie; /* captured WPA ie */ 123170530Ssam uint8_t *ni_rsn_ie; /* captured RSN ie */ 124170530Ssam uint8_t *ni_wme_ie; /* captured WME ie */ 125170530Ssam uint8_t *ni_ath_ie; /* captured Atheros ie */ 126172225Ssam /* tx seq per-tid */ 127172225Ssam uint16_t ni_txseqs[IEEE80211_TID_SIZE]; 128172225Ssam /* rx seq previous per-tid*/ 129172225Ssam uint16_t ni_rxseqs[IEEE80211_TID_SIZE]; 130170530Ssam uint32_t ni_rxfragstamp; /* time stamp of last rx frag */ 131138568Ssam struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */ 132138568Ssam struct ieee80211_rsnparms ni_rsn; /* RSN/WPA parameters */ 133138568Ssam struct ieee80211_key ni_ucastkey; /* unicast key */ 134116742Ssam 135116742Ssam /* hardware */ 136170530Ssam uint32_t ni_rstamp; /* recv timestamp */ 137170530Ssam int8_t ni_rssi; /* recv ssi */ 138170530Ssam int8_t ni_noise; /* noise floor */ 139116742Ssam 140116742Ssam /* header */ 141170530Ssam uint8_t ni_macaddr[IEEE80211_ADDR_LEN]; 142170530Ssam uint8_t ni_bssid[IEEE80211_ADDR_LEN]; 143116742Ssam 144116742Ssam /* beacon, probe response */ 145138568Ssam union { 146170530Ssam uint8_t data[8]; 147170530Ssam uint64_t tsf; 148138568Ssam } ni_tstamp; /* from last rcv'd beacon */ 149170530Ssam uint16_t ni_intval; /* beacon interval */ 150170530Ssam uint16_t ni_capinfo; /* capabilities */ 151170530Ssam uint8_t ni_esslen; 152170530Ssam uint8_t ni_essid[IEEE80211_NWID_LEN]; 153116742Ssam struct ieee80211_rateset ni_rates; /* negotiated rate set */ 154170530Ssam struct ieee80211_channel *ni_chan; 155170530Ssam uint16_t ni_fhdwell; /* FH only */ 156170530Ssam uint8_t ni_fhindex; /* FH only */ 157170530Ssam uint8_t ni_erp; /* ERP from beacon/probe resp */ 158170530Ssam uint16_t ni_timoff; /* byte offset to TIM ie */ 159170530Ssam uint8_t ni_dtim_period; /* DTIM period */ 160170530Ssam uint8_t ni_dtim_count; /* DTIM count for last bcn */ 161116742Ssam 162170530Ssam /* 11n state */ 163173273Ssam uint8_t *ni_htcap_ie; /* captured HTCAP ie */ 164170530Ssam uint16_t ni_htcap; /* HT capabilities */ 165170530Ssam uint8_t ni_htparam; /* HT params */ 166170530Ssam uint8_t ni_htctlchan; /* HT control channel */ 167170530Ssam uint8_t ni_ht2ndchan; /* HT 2nd channel */ 168170530Ssam uint8_t ni_htopmode; /* HT operating mode */ 169170530Ssam uint8_t ni_htstbc; /* HT */ 170170530Ssam uint8_t ni_reqcw; /* requested tx channel width */ 171170530Ssam uint8_t ni_chw; /* negotiated channel width */ 172170530Ssam struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */ 173170530Ssam struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC]; 174170530Ssam struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID]; 175170530Ssam 176116742Ssam /* others */ 177116742Ssam int ni_fails; /* failure count to associate */ 178138568Ssam short ni_inact; /* inactivity mark count */ 179138568Ssam short ni_inact_reload;/* inactivity reload value */ 180116742Ssam int ni_txrate; /* index to ni_rates[] */ 181138568Ssam struct ifqueue ni_savedq; /* ps-poll queue */ 182138568Ssam struct ieee80211_nodestats ni_stats; /* per-node statistics */ 183116742Ssam}; 184138568SsamMALLOC_DECLARE(M_80211_NODE); 185116742Ssam 186170530Ssam#define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP) 187173273Ssam#define IEEE80211_NODE_AMPDU \ 188173273Ssam (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX) 189170530Ssam 190138568Ssam#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd) 191138568Ssam 192138568Ssam#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++) 193138568Ssam#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v) 194138568Ssam#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v) 195138568Ssam 196116742Ssamstatic __inline struct ieee80211_node * 197116742Ssamieee80211_ref_node(struct ieee80211_node *ni) 198116742Ssam{ 199138568Ssam ieee80211_node_incref(ni); 200116742Ssam return ni; 201116742Ssam} 202116742Ssam 203116742Ssamstatic __inline void 204116742Ssamieee80211_unref_node(struct ieee80211_node **ni) 205116742Ssam{ 206138568Ssam ieee80211_node_decref(*ni); 207116742Ssam *ni = NULL; /* guard against use */ 208116742Ssam} 209116742Ssam 210116742Ssamstruct ieee80211com; 211116742Ssam 212144618Ssamvoid ieee80211_node_attach(struct ieee80211com *); 213144618Ssamvoid ieee80211_node_lateattach(struct ieee80211com *); 214144618Ssamvoid ieee80211_node_detach(struct ieee80211com *); 215127877Ssam 216138568Ssamstatic __inline int 217138568Ssamieee80211_node_is_authorized(const struct ieee80211_node *ni) 218138568Ssam{ 219138568Ssam return (ni->ni_flags & IEEE80211_NODE_AUTH); 220138568Ssam} 221116742Ssam 222148302Ssamvoid ieee80211_node_authorize(struct ieee80211_node *); 223148302Ssamvoid ieee80211_node_unauthorize(struct ieee80211_node *); 224138568Ssam 225156358Ssamvoid ieee80211_probe_curchan(struct ieee80211com *, int); 226144618Ssamvoid ieee80211_create_ibss(struct ieee80211com*, struct ieee80211_channel *); 227144618Ssamvoid ieee80211_reset_bss(struct ieee80211com *); 228173273Ssamvoid ieee80211_setbsschan(struct ieee80211com *, struct ieee80211_channel *); 229148306Ssamint ieee80211_ibss_merge(struct ieee80211_node *); 230170530Ssamstruct ieee80211_scan_entry; 231170530Ssamint ieee80211_sta_join(struct ieee80211com *, 232170530Ssam const struct ieee80211_scan_entry *); 233144618Ssamvoid ieee80211_sta_leave(struct ieee80211com *, struct ieee80211_node *); 234138568Ssam 235138568Ssam/* 236138568Ssam * Table of ieee80211_node instances. Each ieee80211com 237138568Ssam * has at least one for holding the scan candidates. 238138568Ssam * When operating as an access point or in ibss mode there 239138568Ssam * is a second table for associated stations or neighbors. 240138568Ssam */ 241138568Ssamstruct ieee80211_node_table { 242138568Ssam struct ieee80211com *nt_ic; /* back reference */ 243138568Ssam ieee80211_node_lock_t nt_nodelock; /* on node table */ 244138568Ssam TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */ 245138568Ssam LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE]; 246170530Ssam struct ieee80211_node **nt_keyixmap; /* key ix -> node map */ 247170530Ssam int nt_keyixmax; /* keyixmap size */ 248138568Ssam const char *nt_name; /* for debugging */ 249138568Ssam ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */ 250138568Ssam u_int nt_scangen; /* gen# for timeout scan */ 251138568Ssam int nt_inact_init; /* initial node inact setting */ 252138568Ssam}; 253138568Ssam 254144618Ssamstruct ieee80211_node *ieee80211_alloc_node( 255170530Ssam struct ieee80211_node_table *, const uint8_t *); 256148777Ssamstruct ieee80211_node *ieee80211_tmp_node(struct ieee80211com *, 257170530Ssam const uint8_t *macaddr); 258144618Ssamstruct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *, 259170530Ssam const uint8_t *); 260138568Ssam#ifdef IEEE80211_DEBUG_REFCNT 261144618Ssamvoid ieee80211_free_node_debug(struct ieee80211_node *, 262138568Ssam const char *func, int line); 263170530Ssamstruct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *, 264170530Ssam const uint8_t *, 265138568Ssam const char *func, int line); 266170530Ssamstruct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *, 267170530Ssam const struct ieee80211_frame_min *, 268138568Ssam const char *func, int line); 269148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 270148863Ssam struct ieee80211com *, 271170530Ssam const struct ieee80211_frame_min *, uint16_t keyix, 272148863Ssam const char *func, int line); 273170530Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey_debug( 274170530Ssam struct ieee80211com *, 275170530Ssam const struct ieee80211_frame_min *, uint16_t keyix, 276138568Ssam const char *func, int line); 277170530Ssamstruct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211com *, 278170530Ssam const uint8_t *, 279170530Ssam const char *func, int line); 280144618Ssamstruct ieee80211_node *ieee80211_find_node_with_ssid_debug( 281170530Ssam struct ieee80211_node_table *, const uint8_t *macaddr, 282170530Ssam u_int ssidlen, const uint8_t *ssid, 283138568Ssam const char *func, int line); 284138568Ssam#define ieee80211_free_node(ni) \ 285138568Ssam ieee80211_free_node_debug(ni, __func__, __LINE__) 286138568Ssam#define ieee80211_find_node(nt, mac) \ 287138568Ssam ieee80211_find_node_debug(nt, mac, __func__, __LINE__) 288138568Ssam#define ieee80211_find_rxnode(nt, wh) \ 289138568Ssam ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__) 290148863Ssam#define ieee80211_find_rxnode_withkey(nt, wh, keyix) \ 291148863Ssam ieee80211_find_rxnode_withkey_debug(nt, wh, keyix, __func__, __LINE__) 292138568Ssam#define ieee80211_find_txnode(nt, mac) \ 293138568Ssam ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__) 294138568Ssam#define ieee80211_find_node_with_ssid(nt, mac, sl, ss) \ 295138568Ssam ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__) 296138568Ssam#else 297144618Ssamvoid ieee80211_free_node(struct ieee80211_node *); 298170530Ssamstruct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *, 299170530Ssam const uint8_t *); 300170530Ssamstruct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *, 301170530Ssam const struct ieee80211_frame_min *); 302148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *, 303170530Ssam const struct ieee80211_frame_min *, uint16_t keyix); 304170530Ssamstruct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 305170530Ssam const uint8_t *); 306144618Ssamstruct ieee80211_node *ieee80211_find_node_with_ssid( 307170530Ssam struct ieee80211_node_table *, const uint8_t *macaddr, 308170530Ssam u_int ssidlen, const uint8_t *ssid); 309138568Ssam#endif 310148863Ssamint ieee80211_node_delucastkey(struct ieee80211_node *); 311170530Ssamvoid ieee80211_node_timeout(void *arg); 312138568Ssam 313116742Ssamtypedef void ieee80211_iter_func(void *, struct ieee80211_node *); 314144618Ssamvoid ieee80211_iterate_nodes(struct ieee80211_node_table *, 315116742Ssam ieee80211_iter_func *, void *); 316116742Ssam 317144618Ssamvoid ieee80211_dump_node(struct ieee80211_node_table *, 318138568Ssam struct ieee80211_node *); 319144618Ssamvoid ieee80211_dump_nodes(struct ieee80211_node_table *); 320138568Ssam 321172211Ssamvoid ieee80211_notify_erp(struct ieee80211com *); 322172211Ssam 323144618Ssamstruct ieee80211_node *ieee80211_fakeup_adhoc_node( 324170530Ssam struct ieee80211_node_table *, const uint8_t macaddr[]); 325170530Ssamstruct ieee80211_scanparams; 326153073Ssamvoid ieee80211_init_neighbor(struct ieee80211_node *, 327153073Ssam const struct ieee80211_frame *, 328153073Ssam const struct ieee80211_scanparams *); 329148936Ssamstruct ieee80211_node *ieee80211_add_neighbor(struct ieee80211com *, 330148936Ssam const struct ieee80211_frame *, 331148936Ssam const struct ieee80211_scanparams *); 332170530Ssamvoid ieee80211_node_join(struct ieee80211com *, struct ieee80211_node *,int); 333170530Ssamvoid ieee80211_node_leave(struct ieee80211com *, struct ieee80211_node *); 334170530Ssamint8_t ieee80211_getrssi(struct ieee80211com *); 335170530Ssamvoid ieee80211_getsignal(struct ieee80211com *, int8_t *, int8_t *); 336116742Ssam#endif /* _NET80211_IEEE80211_NODE_H_ */ 337