ieee80211_node.h revision 138568
1116742Ssam/*- 2116904Ssam * Copyright (c) 2001 Atsushi Onoe 3116742Ssam * Copyright (c) 2002, 2003 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. 14116904Ssam * 3. The name of the author may not be used to endorse or promote products 15116904Ssam * derived from this software without specific prior written permission. 16116742Ssam * 17116904Ssam * Alternatively, this software may be distributed under the terms of the 18116904Ssam * GNU General Public License ("GPL") version 2 as published by the Free 19116904Ssam * Software Foundation. 20116742Ssam * 21116904Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22116904Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23116904Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24116904Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25116904Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26116904Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27116904Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28116904Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29116904Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30116904Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31116904Ssam * 32116742Ssam * $FreeBSD: head/sys/net80211/ieee80211_node.h 138568 2004-12-08 17:26:47Z sam $ 33116742Ssam */ 34116742Ssam#ifndef _NET80211_IEEE80211_NODE_H_ 35116742Ssam#define _NET80211_IEEE80211_NODE_H_ 36116742Ssam 37138568Ssam#include <net80211/ieee80211_ioctl.h> /* for ieee80211_nodestats */ 38116742Ssam 39138568Ssam/* 40138568Ssam * Each ieee80211com instance has a single timer that fires once a 41138568Ssam * second. This is used to initiate various work depending on the 42138568Ssam * state of the instance: scanning (passive or active), ``transition'' 43138568Ssam * (waiting for a response to a management frame when operating 44138568Ssam * as a station), and node inactivity processing (when operating 45138568Ssam * as an AP). For inactivity processing each node has a timeout 46138568Ssam * set in it's ni_inact field that is decremented on each timeout 47138568Ssam * and the node is reclaimed when the counter goes to zero. We 48138568Ssam * use different inactivity timeout values depending on whether 49138568Ssam * the node is associated and authorized (either by 802.1x or 50138568Ssam * open/shared key authentication) or associated but yet to be 51138568Ssam * authorized. The latter timeout is shorter to more aggressively 52138568Ssam * reclaim nodes that leave part way through the 802.1x exchange. 53138568Ssam */ 54138568Ssam#define IEEE80211_INACT_WAIT 15 /* inactivity interval (secs) */ 55138568Ssam#define IEEE80211_INACT_INIT (30/IEEE80211_INACT_WAIT) /* initial */ 56138568Ssam#define IEEE80211_INACT_AUTH (180/IEEE80211_INACT_WAIT) /* associated but not authorized */ 57138568Ssam#define IEEE80211_INACT_RUN (300/IEEE80211_INACT_WAIT) /* authorized */ 58138568Ssam#define IEEE80211_INACT_PROBE (30/IEEE80211_INACT_WAIT) /* probe */ 59138568Ssam#define IEEE80211_INACT_SCAN (300/IEEE80211_INACT_WAIT) /* scanned */ 60138568Ssam 61138568Ssam#define IEEE80211_TRANS_WAIT 5 /* mgt frame tx timer (secs) */ 62138568Ssam 63116742Ssam#define IEEE80211_NODE_HASHSIZE 32 64116742Ssam/* simple hash is enough for variation of macaddr */ 65116742Ssam#define IEEE80211_NODE_HASH(addr) \ 66138568Ssam (((const u_int8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \ 67138568Ssam IEEE80211_NODE_HASHSIZE) 68116742Ssam 69138568Ssamstruct ieee80211_rsnparms { 70138568Ssam u_int8_t rsn_mcastcipher; /* mcast/group cipher */ 71138568Ssam u_int8_t rsn_mcastkeylen; /* mcast key length */ 72138568Ssam u_int8_t rsn_ucastcipherset; /* unicast cipher set */ 73138568Ssam u_int8_t rsn_ucastcipher; /* selected unicast cipher */ 74138568Ssam u_int8_t rsn_ucastkeylen; /* unicast key length */ 75138568Ssam u_int8_t rsn_keymgmtset; /* key mangement algorithms */ 76138568Ssam u_int8_t rsn_keymgmt; /* selected key mgmt algo */ 77138568Ssam u_int16_t rsn_caps; /* capabilities */ 78116742Ssam}; 79116742Ssam 80138568Ssamstruct ieee80211_node_table; 81138568Ssamstruct ieee80211com; 82138568Ssam 83116742Ssam/* 84116742Ssam * Node specific information. Note that drivers are expected 85116742Ssam * to derive from this structure to add device-specific per-node 86116742Ssam * state. This is done by overriding the ic_node_* methods in 87116742Ssam * the ieee80211com structure. 88116742Ssam */ 89116742Ssamstruct ieee80211_node { 90138568Ssam struct ieee80211com *ni_ic; 91138568Ssam struct ieee80211_node_table *ni_table; 92116742Ssam TAILQ_ENTRY(ieee80211_node) ni_list; 93116742Ssam LIST_ENTRY(ieee80211_node) ni_hash; 94116742Ssam u_int ni_refcnt; 95120483Ssam u_int ni_scangen; /* gen# for timeout scan */ 96138568Ssam u_int8_t ni_authmode; /* authentication algorithm */ 97138568Ssam u_int16_t ni_flags; /* special-purpose state */ 98138568Ssam#define IEEE80211_NODE_AUTH 0x0001 /* authorized for data */ 99138568Ssam#define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */ 100138568Ssam#define IEEE80211_NODE_ERP 0x0004 /* ERP enabled */ 101138568Ssam/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */ 102138568Ssam#define IEEE80211_NODE_PWR_MGT 0x0010 /* power save mode enabled */ 103138568Ssam u_int16_t ni_associd; /* assoc response */ 104138568Ssam u_int16_t ni_txpower; /* current transmit power */ 105138568Ssam u_int16_t ni_vlan; /* vlan tag */ 106138568Ssam u_int32_t *ni_challenge; /* shared-key challenge */ 107138568Ssam u_int8_t *ni_wpa_ie; /* captured WPA/RSN ie */ 108138568Ssam u_int8_t *ni_wme_ie; /* captured WME ie */ 109138568Ssam u_int16_t ni_txseqs[17]; /* tx seq per-tid */ 110138568Ssam u_int16_t ni_rxseqs[17]; /* rx seq previous per-tid*/ 111138568Ssam u_int32_t ni_rxfragstamp; /* time stamp of last rx frag */ 112138568Ssam struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */ 113138568Ssam struct ieee80211_rsnparms ni_rsn; /* RSN/WPA parameters */ 114138568Ssam struct ieee80211_key ni_ucastkey; /* unicast key */ 115116742Ssam 116116742Ssam /* hardware */ 117119150Ssam u_int32_t ni_rstamp; /* recv timestamp */ 118116742Ssam u_int8_t ni_rssi; /* recv ssi */ 119116742Ssam 120116742Ssam /* header */ 121116742Ssam u_int8_t ni_macaddr[IEEE80211_ADDR_LEN]; 122116742Ssam u_int8_t ni_bssid[IEEE80211_ADDR_LEN]; 123116742Ssam 124116742Ssam /* beacon, probe response */ 125138568Ssam union { 126138568Ssam u_int8_t data[8]; 127138568Ssam u_int64_t tsf; 128138568Ssam } ni_tstamp; /* from last rcv'd beacon */ 129116742Ssam u_int16_t ni_intval; /* beacon interval */ 130116742Ssam u_int16_t ni_capinfo; /* capabilities */ 131116742Ssam u_int8_t ni_esslen; 132116742Ssam u_int8_t ni_essid[IEEE80211_NWID_LEN]; 133116742Ssam struct ieee80211_rateset ni_rates; /* negotiated rate set */ 134116742Ssam struct ieee80211_channel *ni_chan; 135116742Ssam u_int16_t ni_fhdwell; /* FH only */ 136116742Ssam u_int8_t ni_fhindex; /* FH only */ 137138568Ssam u_int8_t ni_erp; /* ERP from beacon/probe resp */ 138138568Ssam u_int16_t ni_timoff; /* byte offset to TIM ie */ 139116742Ssam 140116742Ssam /* others */ 141116742Ssam int ni_fails; /* failure count to associate */ 142138568Ssam short ni_inact; /* inactivity mark count */ 143138568Ssam short ni_inact_reload;/* inactivity reload value */ 144116742Ssam int ni_txrate; /* index to ni_rates[] */ 145138568Ssam struct ifqueue ni_savedq; /* ps-poll queue */ 146138568Ssam struct ieee80211_nodestats ni_stats; /* per-node statistics */ 147116742Ssam}; 148138568SsamMALLOC_DECLARE(M_80211_NODE); 149116742Ssam 150138568Ssam#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd) 151138568Ssam 152138568Ssam#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++) 153138568Ssam#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v) 154138568Ssam#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v) 155138568Ssam 156116742Ssamstatic __inline struct ieee80211_node * 157116742Ssamieee80211_ref_node(struct ieee80211_node *ni) 158116742Ssam{ 159138568Ssam ieee80211_node_incref(ni); 160116742Ssam return ni; 161116742Ssam} 162116742Ssam 163116742Ssamstatic __inline void 164116742Ssamieee80211_unref_node(struct ieee80211_node **ni) 165116742Ssam{ 166138568Ssam ieee80211_node_decref(*ni); 167116742Ssam *ni = NULL; /* guard against use */ 168116742Ssam} 169116742Ssam 170116742Ssamstruct ieee80211com; 171116742Ssam 172138568Ssamextern void ieee80211_node_attach(struct ieee80211com *); 173138568Ssamextern void ieee80211_node_lateattach(struct ieee80211com *); 174138568Ssamextern void ieee80211_node_detach(struct ieee80211com *); 175127877Ssam 176138568Ssamstatic __inline int 177138568Ssamieee80211_node_is_authorized(const struct ieee80211_node *ni) 178138568Ssam{ 179138568Ssam return (ni->ni_flags & IEEE80211_NODE_AUTH); 180138568Ssam} 181116742Ssam 182138568Ssamextern void ieee80211_node_authorize(struct ieee80211com *, 183116742Ssam struct ieee80211_node *); 184138568Ssamextern void ieee80211_node_unauthorize(struct ieee80211com *, 185138568Ssam struct ieee80211_node *); 186138568Ssam 187138568Ssamextern void ieee80211_begin_scan(struct ieee80211com *, int); 188138568Ssamextern int ieee80211_next_scan(struct ieee80211com *); 189138568Ssamextern void ieee80211_create_ibss(struct ieee80211com*, 190138568Ssam struct ieee80211_channel *); 191138568Ssamextern void ieee80211_reset_bss(struct ieee80211com *); 192138568Ssamextern void ieee80211_end_scan(struct ieee80211com *); 193138568Ssamextern int ieee80211_ibss_merge(struct ieee80211com *, 194138568Ssam struct ieee80211_node *); 195138568Ssamextern int ieee80211_sta_join(struct ieee80211com *, 196138568Ssam struct ieee80211_node *); 197138568Ssamextern void ieee80211_sta_leave(struct ieee80211com *, 198138568Ssam struct ieee80211_node *); 199138568Ssam 200138568Ssam/* 201138568Ssam * Table of ieee80211_node instances. Each ieee80211com 202138568Ssam * has at least one for holding the scan candidates. 203138568Ssam * When operating as an access point or in ibss mode there 204138568Ssam * is a second table for associated stations or neighbors. 205138568Ssam */ 206138568Ssamstruct ieee80211_node_table { 207138568Ssam struct ieee80211com *nt_ic; /* back reference */ 208138568Ssam ieee80211_node_lock_t nt_nodelock; /* on node table */ 209138568Ssam TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */ 210138568Ssam LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE]; 211138568Ssam const char *nt_name; /* for debugging */ 212138568Ssam ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */ 213138568Ssam u_int nt_scangen; /* gen# for timeout scan */ 214138568Ssam int nt_inact_timer; /* inactivity timer */ 215138568Ssam int nt_inact_init; /* initial node inact setting */ 216138568Ssam 217138568Ssam void (*nt_timeout)(struct ieee80211_node_table *); 218138568Ssam}; 219138568Ssamextern void ieee80211_node_table_reset(struct ieee80211_node_table *); 220138568Ssamextern void ieee80211_node_table_free(struct ieee80211_node_table *); 221138568Ssam 222138568Ssamextern struct ieee80211_node *ieee80211_alloc_node( 223138568Ssam struct ieee80211_node_table *, const u_int8_t *); 224138568Ssamextern struct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *, 225138568Ssam const u_int8_t *); 226138568Ssam#ifdef IEEE80211_DEBUG_REFCNT 227138568Ssamextern void ieee80211_free_node_debug(struct ieee80211_node *, 228138568Ssam const char *func, int line); 229138568Ssamextern struct ieee80211_node *ieee80211_find_node_debug( 230138568Ssam struct ieee80211_node_table *, const u_int8_t *, 231138568Ssam const char *func, int line); 232138568Ssamextern struct ieee80211_node * ieee80211_find_rxnode_debug( 233138568Ssam struct ieee80211com *, const struct ieee80211_frame_min *, 234138568Ssam const char *func, int line); 235138568Ssamextern struct ieee80211_node *ieee80211_find_txnode_debug( 236138568Ssam struct ieee80211com *, const u_int8_t *, 237138568Ssam const char *func, int line); 238138568Ssamextern struct ieee80211_node *ieee80211_find_node_with_channel_debug( 239138568Ssam struct ieee80211_node_table *, const u_int8_t *macaddr, 240138568Ssam struct ieee80211_channel *, const char *func, int line); 241138568Ssamextern struct ieee80211_node *ieee80211_find_node_with_ssid_debug( 242138568Ssam struct ieee80211_node_table *, const u_int8_t *macaddr, 243138568Ssam u_int ssidlen, const u_int8_t *ssid, 244138568Ssam const char *func, int line); 245138568Ssam#define ieee80211_free_node(ni) \ 246138568Ssam ieee80211_free_node_debug(ni, __func__, __LINE__) 247138568Ssam#define ieee80211_find_node(nt, mac) \ 248138568Ssam ieee80211_find_node_debug(nt, mac, __func__, __LINE__) 249138568Ssam#define ieee80211_find_rxnode(nt, wh) \ 250138568Ssam ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__) 251138568Ssam#define ieee80211_find_txnode(nt, mac) \ 252138568Ssam ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__) 253138568Ssam#define ieee80211_find_node_with_channel(nt, mac, c) \ 254138568Ssam ieee80211_find_node_with_channel_debug(nt, mac, c, __func__, __LINE__) 255138568Ssam#define ieee80211_find_node_with_ssid(nt, mac, sl, ss) \ 256138568Ssam ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__) 257138568Ssam#else 258138568Ssamextern void ieee80211_free_node(struct ieee80211_node *); 259138568Ssamextern struct ieee80211_node *ieee80211_find_node( 260138568Ssam struct ieee80211_node_table *, const u_int8_t *); 261138568Ssamextern struct ieee80211_node * ieee80211_find_rxnode( 262138568Ssam struct ieee80211com *, const struct ieee80211_frame_min *); 263138568Ssamextern struct ieee80211_node *ieee80211_find_txnode( 264138568Ssam struct ieee80211com *, const u_int8_t *); 265138568Ssamextern struct ieee80211_node *ieee80211_find_node_with_channel( 266138568Ssam struct ieee80211_node_table *, const u_int8_t *macaddr, 267138568Ssam struct ieee80211_channel *); 268138568Ssamextern struct ieee80211_node *ieee80211_find_node_with_ssid( 269138568Ssam struct ieee80211_node_table *, const u_int8_t *macaddr, 270138568Ssam u_int ssidlen, const u_int8_t *ssid); 271138568Ssam#endif 272138568Ssam 273116742Ssamtypedef void ieee80211_iter_func(void *, struct ieee80211_node *); 274138568Ssamextern void ieee80211_iterate_nodes(struct ieee80211_node_table *, 275116742Ssam ieee80211_iter_func *, void *); 276116742Ssam 277138568Ssamextern void ieee80211_dump_node(struct ieee80211_node_table *, 278138568Ssam struct ieee80211_node *); 279138568Ssamextern void ieee80211_dump_nodes(struct ieee80211_node_table *); 280138568Ssam 281138568Ssamextern struct ieee80211_node *ieee80211_fakeup_adhoc_node( 282138568Ssam struct ieee80211_node_table *nt, 283138568Ssam const u_int8_t macaddr[]); 284138568Ssamextern void ieee80211_node_join(struct ieee80211com *, 285138568Ssam struct ieee80211_node *, int); 286138568Ssamextern void ieee80211_node_leave(struct ieee80211com *, 287138568Ssam struct ieee80211_node *); 288138568Ssamextern u_int8_t ieee80211_getrssi(struct ieee80211com *ic); 289116742Ssam#endif /* _NET80211_IEEE80211_NODE_H_ */ 290