Home | History | Annotate | Line # | Download | only in net80211
ieee80211_node.h revision 1.23.4.1
      1 /*	$NetBSD: ieee80211_node.h,v 1.23.4.1 2008/02/22 16:50:25 skrll Exp $	*/
      2 /*-
      3  * Copyright (c) 2001 Atsushi Onoe
      4  * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  *
     27  * $FreeBSD: src/sys/net80211/ieee80211_node.h,v 1.30 2007/11/02 05:22:25 sam Exp $
     28  */
     29 #ifndef _NET80211_IEEE80211_NODE_H_
     30 #define _NET80211_IEEE80211_NODE_H_
     31 
     32 #include <net80211/ieee80211_netbsd.h>
     33 #include <net80211/ieee80211_ioctl.h>		/* for ieee80211_nodestats */
     34 #include <net80211/ieee80211_ht.h>		/* for aggregation state */
     35 
     36 #ifdef _KERNEL
     37 /*
     38  * Each ieee80211com instance has a single timer that fires once a
     39  * second.  This is used to initiate various work depending on the
     40  * state of the instance: scanning (passive or active), ``transition''
     41  * (waiting for a response to a management frame when operating
     42  * as a station), and node inactivity processing (when operating
     43  * as an AP).  For inactivity processing each node has a timeout
     44  * set in it's ni_inact field that is decremented on each timeout
     45  * and the node is reclaimed when the counter goes to zero.  We
     46  * use different inactivity timeout values depending on whether
     47  * the node is associated and authorized (either by 802.1x or
     48  * open/shared key authentication) or associated but yet to be
     49  * authorized.  The latter timeout is shorter to more aggressively
     50  * reclaim nodes that leave part way through the 802.1x exchange.
     51  */
     52 #define	IEEE80211_INACT_WAIT	15		/* inactivity interval (secs) */
     53 #define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
     54 #define	IEEE80211_INACT_AUTH	(180/IEEE80211_INACT_WAIT)	/* associated but not authorized */
     55 #define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
     56 #define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
     57 #define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
     58 
     59 #define	IEEE80211_TRANS_WAIT 	2		/* mgt frame tx timer (secs) */
     60 
     61 /* threshold for aging overlapping non-ERP bss */
     62 #define	IEEE80211_NONERP_PRESENT_AGE	msecs_to_ticks(60*1000)
     63 
     64 #define	IEEE80211_NODE_HASHSIZE	32
     65 /* simple hash is enough for variation of macaddr */
     66 #define	IEEE80211_NODE_HASH(addr)	\
     67 	(((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
     68 		IEEE80211_NODE_HASHSIZE)
     69 
     70 struct ieee80211_rsnparms {
     71 	uint8_t		rsn_mcastcipher;	/* mcast/group cipher */
     72 	uint8_t		rsn_mcastkeylen;	/* mcast key length */
     73 	uint8_t		rsn_ucastcipherset;	/* unicast cipher set */
     74 	uint8_t		rsn_ucastcipher;	/* selected unicast cipher */
     75 	uint8_t		rsn_ucastkeylen;	/* unicast key length */
     76 	uint8_t		rsn_keymgmtset;		/* key mangement algorithms */
     77 	uint8_t		rsn_keymgmt;		/* selected key mgmt algo */
     78 	uint16_t	rsn_caps;		/* capabilities */
     79 };
     80 
     81 struct ieee80211_node_table;
     82 struct ieee80211com;
     83 
     84 /*
     85  * Node specific information.  Note that drivers are expected
     86  * to derive from this structure to add device-specific per-node
     87  * state.  This is done by overriding the ic_node_* methods in
     88  * the ieee80211com structure.
     89  */
     90 struct ieee80211_node {
     91 	struct ieee80211com	*ni_ic;
     92 	struct ieee80211_node_table *ni_table;
     93 	TAILQ_ENTRY(ieee80211_node)	ni_list;
     94 	LIST_ENTRY(ieee80211_node)	ni_hash;
     95 	u_int			ni_refcnt;
     96 	u_int			ni_scangen;	/* gen# for timeout scan */
     97 	uint8_t			ni_authmode;	/* authentication algorithm */
     98 	uint8_t			ni_ath_flags;	/* Atheros feature flags */
     99 	/* NB: These must have the same values as IEEE80211_ATHC_* */
    100 #define IEEE80211_NODE_TURBOP	0x0001		/* Turbo prime enable */
    101 #define IEEE80211_NODE_COMP	0x0002		/* Compresssion enable */
    102 #define IEEE80211_NODE_FF	0x0004          /* Fast Frame capable */
    103 #define IEEE80211_NODE_XR	0x0008		/* Atheros WME enable */
    104 #define IEEE80211_NODE_AR	0x0010		/* AR capable */
    105 #define IEEE80211_NODE_BOOST	0x0080
    106 #define IEEE80211_NODE_PSUPDATE	0x0200		/* power save state changed */
    107 #define	IEEE80211_NODE_CHWUPDATE 0x0400		/* 11n channel width change */
    108 	uint16_t		ni_flags;	/* special-purpose state */
    109 #define	IEEE80211_NODE_AUTH	0x0001		/* authorized for data */
    110 #define	IEEE80211_NODE_QOS	0x0002		/* QoS enabled */
    111 #define	IEEE80211_NODE_ERP	0x0004		/* ERP enabled */
    112 /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
    113 #define	IEEE80211_NODE_PWR_MGT	0x0010		/* power save mode enabled */
    114 #define	IEEE80211_NODE_AREF	0x0020		/* authentication ref held */
    115 #define	IEEE80211_NODE_HT	0x0040		/* HT enabled */
    116 #define	IEEE80211_NODE_HTCOMPAT	0x0080		/* HT setup w/ vendor OUI's */
    117 #define	IEEE80211_NODE_AMPDU_RX	0x0400		/* AMPDU rx enabled */
    118 #define	IEEE80211_NODE_AMPDU_TX	0x0800		/* AMPDU tx enabled */
    119 	uint16_t		ni_ath_defkeyix;/* Atheros def key index */
    120 	uint16_t		ni_associd;	/* assoc response */
    121 	uint16_t		ni_txpower;	/* current transmit power */
    122 	uint16_t		ni_vlan;	/* vlan tag */
    123 	uint32_t		ni_jointime;	/* time of join (secs) */
    124 	uint32_t		*ni_challenge;	/* shared-key challenge */
    125 	uint8_t			*ni_wpa_ie;	/* captured WPA ie */
    126 	uint8_t			*ni_rsn_ie;	/* captured RSN ie */
    127 	uint8_t			*ni_wme_ie;	/* captured WME ie */
    128 	uint8_t			*ni_ath_ie;	/* captured Atheros ie */
    129 						/* tx seq per-tid */
    130 	uint16_t		ni_txseqs[IEEE80211_TID_SIZE];
    131 						/* rx seq previous per-tid*/
    132 	uint16_t		ni_rxseqs[IEEE80211_TID_SIZE];
    133 	uint32_t		ni_rxfragstamp;	/* time stamp of last rx frag */
    134 	struct mbuf		*ni_rxfrag[3];	/* rx frag reassembly */
    135 	struct ieee80211_rsnparms ni_rsn;	/* RSN/WPA parameters */
    136 	struct ieee80211_key	ni_ucastkey;	/* unicast key */
    137 
    138 	/* hardware */
    139 	uint32_t		ni_rstamp;	/* recv timestamp */
    140 	int8_t			ni_rssi;	/* recv ssi */
    141 	int8_t			ni_noise;	/* noise floor */
    142 
    143 	/* header */
    144 	uint8_t			ni_macaddr[IEEE80211_ADDR_LEN];
    145 	uint8_t			ni_bssid[IEEE80211_ADDR_LEN];
    146 
    147 	/* beacon, probe response */
    148 	union {
    149 		uint8_t		data[8];
    150 		uint64_t	tsf;
    151 	} ni_tstamp;				/* from last rcv'd beacon */
    152 	uint16_t		ni_intval;	/* beacon interval */
    153 	uint16_t		ni_capinfo;	/* capabilities */
    154 	uint8_t			ni_esslen;
    155 	uint8_t			ni_essid[IEEE80211_NWID_LEN];
    156 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
    157 	struct ieee80211_channel *ni_chan;
    158 	uint16_t		ni_fhdwell;	/* FH only */
    159 	uint8_t			ni_fhindex;	/* FH only */
    160 	uint8_t			ni_erp;		/* ERP from beacon/probe resp */
    161 	uint16_t		ni_timoff;	/* byte offset to TIM ie */
    162 	uint8_t			ni_dtim_period;	/* DTIM period */
    163 	uint8_t			ni_dtim_count;	/* DTIM count for last bcn */
    164 
    165 	/* 11n state */
    166 	uint8_t			*ni_htcap_ie;	/* captured HTCAP ie */
    167 	uint16_t		ni_htcap;	/* HT capabilities */
    168 	uint8_t			ni_htparam;	/* HT params */
    169 	uint8_t			ni_htctlchan;	/* HT control channel */
    170 	uint8_t			ni_ht2ndchan;	/* HT 2nd channel */
    171 	uint8_t			ni_htopmode;	/* HT operating mode */
    172 	uint8_t			ni_htstbc;	/* HT */
    173 	uint8_t			ni_reqcw;	/* requested tx channel width */
    174 	uint8_t			ni_chw;		/* negotiated channel width */
    175 	struct ieee80211_htrateset ni_htrates;	/* negotiated ht rate set */
    176 	struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC];
    177 	struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
    178 
    179 	/* others */
    180 	int			ni_fails;	/* failure count to associate */
    181 	short			ni_inact;	/* inactivity mark count */
    182 	short			ni_inact_reload;/* inactivity reload value */
    183 	int			ni_txrate;	/* index to ni_rates[] */
    184 	struct	ifqueue		ni_savedq;	/* ps-poll queue */
    185 	struct ieee80211_nodestats ni_stats;	/* per-node statistics */
    186 };
    187 MALLOC_DECLARE(M_80211_NODE);
    188 
    189 #define	IEEE80211_NODE_ATH	(IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
    190 #define	IEEE80211_NODE_AMPDU \
    191 	(IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
    192 
    193 #define	IEEE80211_NODE_AID(ni)	IEEE80211_AID(ni->ni_associd)
    194 
    195 #define	IEEE80211_NODE_STAT(ni,stat)	(ni->ni_stats.ns_##stat++)
    196 #define	IEEE80211_NODE_STAT_ADD(ni,stat,v)	(ni->ni_stats.ns_##stat += v)
    197 #define	IEEE80211_NODE_STAT_SET(ni,stat,v)	(ni->ni_stats.ns_##stat = v)
    198 
    199 static __inline struct ieee80211_node *
    200 ieee80211_ref_node(struct ieee80211_node *ni)
    201 {
    202 	ieee80211_node_incref(ni);
    203 	return ni;
    204 }
    205 
    206 static __inline void
    207 ieee80211_unref_node(struct ieee80211_node **ni)
    208 {
    209 	ieee80211_node_decref(*ni);
    210 	*ni = NULL;			/* guard against use */
    211 }
    212 
    213 struct ieee80211com;
    214 
    215 void	ieee80211_node_attach(struct ieee80211com *);
    216 void	ieee80211_node_lateattach(struct ieee80211com *);
    217 void	ieee80211_node_detach(struct ieee80211com *);
    218 
    219 static __inline int
    220 ieee80211_node_is_authorized(const struct ieee80211_node *ni)
    221 {
    222 	return (ni->ni_flags & IEEE80211_NODE_AUTH);
    223 }
    224 
    225 void	ieee80211_node_authorize(struct ieee80211_node *);
    226 void	ieee80211_node_unauthorize(struct ieee80211_node *);
    227 
    228 void	ieee80211_probe_curchan(struct ieee80211com *, int);
    229 void	ieee80211_create_ibss(struct ieee80211com*, struct ieee80211_channel *);
    230 void	ieee80211_reset_bss(struct ieee80211com *);
    231 void	ieee80211_setbsschan(struct ieee80211com *, struct ieee80211_channel *);
    232 int	ieee80211_ibss_merge(struct ieee80211_node *);
    233 struct ieee80211_scan_entry;
    234 int	ieee80211_sta_join(struct ieee80211com *,
    235 		const struct ieee80211_scan_entry *);
    236 void	ieee80211_sta_leave(struct ieee80211com *, struct ieee80211_node *);
    237 
    238 /*
    239  * Table of ieee80211_node instances.  Each ieee80211com
    240  * has at least one for holding the scan candidates.
    241  * When operating as an access point or in ibss mode there
    242  * is a second table for associated stations or neighbors.
    243  */
    244 struct ieee80211_node_table {
    245 	struct ieee80211com	*nt_ic;		/* back reference */
    246 	ieee80211_node_lock_t	nt_nodelock;	/* on node table */
    247 	TAILQ_HEAD(, ieee80211_node) nt_node;	/* information of all nodes */
    248 	LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
    249 	struct ieee80211_node	**nt_keyixmap;	/* key ix -> node map */
    250 	int			nt_keyixmax;	/* keyixmap size */
    251 	const char		*nt_name;	/* for debugging */
    252 	ieee80211_scan_lock_t	nt_scanlock;	/* on nt_scangen */
    253 	u_int			nt_scangen;	/* gen# for timeout scan */
    254 	int			nt_inact_init;	/* initial node inact setting */
    255 };
    256 
    257 struct ieee80211_node *ieee80211_alloc_node(
    258 		struct ieee80211_node_table *, const uint8_t *);
    259 struct ieee80211_node *ieee80211_tmp_node(struct ieee80211com *,
    260 		const uint8_t *macaddr);
    261 struct ieee80211_node *ieee80211_dup_bss(struct ieee80211_node_table *,
    262 		const uint8_t *);
    263 #ifdef IEEE80211_DEBUG_REFCNT
    264 void	ieee80211_free_node_debug(struct ieee80211_node *,
    265 		const char *func, int line);
    266 struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
    267 		const uint8_t *,
    268 		const char *func, int line);
    269 struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
    270 		const struct ieee80211_frame_min *,
    271 		const char *func, int line);
    272 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
    273 		struct ieee80211com *,
    274 		const struct ieee80211_frame_min *, uint16_t keyix,
    275 		const char *func, int line);
    276 struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
    277 		struct ieee80211com *,
    278 		const struct ieee80211_frame_min *, uint16_t keyix,
    279 		const char *func, int line);
    280 struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211com *,
    281 		const uint8_t *,
    282 		const char *func, int line);
    283 struct ieee80211_node *ieee80211_find_node_with_ssid_debug(
    284 		struct ieee80211_node_table *, const uint8_t *macaddr,
    285 		u_int ssidlen, const uint8_t *ssid,
    286 		const char *func, int line);
    287 #define	ieee80211_free_node(ni) \
    288 	ieee80211_free_node_debug(ni, __func__, __LINE__)
    289 #define	ieee80211_find_node(nt, mac) \
    290 	ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
    291 #define	ieee80211_find_rxnode(nt, wh) \
    292 	ieee80211_find_rxnode_debug(nt, wh, __func__, __LINE__)
    293 #define	ieee80211_find_rxnode_withkey(nt, wh, keyix) \
    294 	ieee80211_find_rxnode_withkey_debug(nt, wh, keyix, __func__, __LINE__)
    295 #define	ieee80211_find_txnode(nt, mac) \
    296 	ieee80211_find_txnode_debug(nt, mac, __func__, __LINE__)
    297 #define	ieee80211_find_node_with_ssid(nt, mac, sl, ss) \
    298 	ieee80211_find_node_with_ssid_debug(nt, mac, sl, ss, __func__, __LINE__)
    299 #else
    300 void	ieee80211_free_node(struct ieee80211_node *);
    301 struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
    302 		const uint8_t *);
    303 struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
    304 		const struct ieee80211_frame_min *);
    305 struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
    306 		const struct ieee80211_frame_min *, uint16_t keyix);
    307 struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
    308 		const uint8_t *);
    309 struct ieee80211_node *ieee80211_find_node_with_ssid(
    310 		struct ieee80211_node_table *, const uint8_t *macaddr,
    311 		u_int ssidlen, const uint8_t *ssid);
    312 #endif
    313 int	ieee80211_node_delucastkey(struct ieee80211_node *);
    314 void	ieee80211_node_timeout(void *arg);
    315 
    316 struct ieee80211_node *ieee80211_refine_node_for_beacon(
    317 		struct ieee80211com *, struct ieee80211_node *,
    318 		struct ieee80211_channel *, const u_int8_t *ssid);
    319 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
    320 void	ieee80211_iterate_nodes(struct ieee80211_node_table *,
    321 		ieee80211_iter_func *, void *);
    322 
    323 void	ieee80211_dump_node(struct ieee80211_node_table *,
    324 		struct ieee80211_node *);
    325 void	ieee80211_dump_nodes(struct ieee80211_node_table *);
    326 
    327 void	ieee80211_notify_erp(struct ieee80211com *);
    328 
    329 struct ieee80211_node *ieee80211_fakeup_adhoc_node(
    330 		struct ieee80211_node_table *, const uint8_t macaddr[]);
    331 struct ieee80211_scanparams;
    332 void	ieee80211_init_neighbor(struct ieee80211_node *,
    333 		const struct ieee80211_frame *,
    334 		const struct ieee80211_scanparams *);
    335 struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211com *,
    336 		const struct ieee80211_frame *,
    337 		const struct ieee80211_scanparams *);
    338 void	ieee80211_node_join(struct ieee80211com *, struct ieee80211_node *,int);
    339 void	ieee80211_node_leave(struct ieee80211com *, struct ieee80211_node *);
    340 int8_t	ieee80211_getrssi(struct ieee80211com *);
    341 void	ieee80211_getsignal(struct ieee80211com *, int8_t *, int8_t *);
    342 #endif /* _KERNEL */
    343 #endif /* !_NET80211_IEEE80211_NODE_H_ */
    344