update madwifi
[linux-2.6/zen-sources.git] / drivers / net / wireless / madwifi / net80211 / ieee80211_node.h
blob757521260dbc2e78a6a10f25ea08e3badc59955f
1 /*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2 as published by the Free
19 * Software Foundation.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * $Id: ieee80211_node.h 3743 2008-06-22 02:12:53Z mentor $
34 #ifndef _NET80211_IEEE80211_NODE_H_
35 #define _NET80211_IEEE80211_NODE_H_
37 #include <net80211/ieee80211_var.h>
38 #include <net80211/ieee80211_ioctl.h> /* for ieee80211_nodestats */
39 #include <net80211/ieee80211_proto.h> /* for proto macros on node */
42 * Each ieee80211com instance has a single timer that fires once a
43 * second. This is used to initiate various work depending on the
44 * state of the instance: scanning (passive or active), ``transition''
45 * (waiting for a response to a management frame when operating
46 * as a station), and node inactivity processing (when operating
47 * as an AP). For inactivity processing each node has a timeout
48 * set in its ni_inact field that is decremented on each timeout
49 * and the node is reclaimed when the counter goes to zero. We
50 * use different inactivity timeout values depending on whether
51 * the node is associated and authorized (either by 802.1x or
52 * open/shared key authentication) or associated but yet to be
53 * authorized. The latter timeout is shorter to more aggressively
54 * reclaim nodes that leave part way through the 802.1x exchange.
56 #define IEEE80211_INACT_WAIT 15 /* inactivity interval (secs) */
57 #define IEEE80211_INACT_INIT (30/IEEE80211_INACT_WAIT) /* initial */
58 #define IEEE80211_INACT_AUTH (180/IEEE80211_INACT_WAIT) /* associated but not authorized */
59 #define IEEE80211_INACT_RUN (300/IEEE80211_INACT_WAIT) /* authorized */
60 #define IEEE80211_INACT_PROBE (30/IEEE80211_INACT_WAIT) /* probe */
61 #define IEEE80211_INACT_SCAN (300/IEEE80211_INACT_WAIT) /* scanned */
63 #define IEEE80211_TRANS_WAIT 5 /* mgt frame tx timer (secs) */
65 #define IEEE80211_NODE_HASHSIZE 32
66 /* simple hash is enough for variation of macaddr */
67 #define IEEE80211_NODE_HASH(addr) \
68 (((const u_int8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
69 IEEE80211_NODE_HASHSIZE)
71 struct ieee80211_rsnparms {
72 u_int8_t rsn_mcastcipher; /* mcast/group cipher */
73 u_int8_t rsn_mcastkeylen; /* mcast key length */
74 u_int8_t rsn_ucastcipherset; /* unicast cipher set */
75 u_int8_t rsn_ucastcipher; /* selected unicast cipher */
76 u_int8_t rsn_ucastkeylen; /* unicast key length */
77 u_int8_t rsn_keymgmtset; /* key management algorithms */
78 u_int8_t rsn_keymgmt; /* selected key mgmt algo */
79 u_int16_t rsn_caps; /* capabilities */
82 struct ieee80211_node_table;
83 struct ieee80211com;
84 struct ieee80211vap;
85 struct ath_buf;
86 struct ath_softc;
89 * Node specific information. Note that drivers are expected
90 * to derive from this structure to add device-specific per-node
91 * state. This is done by overriding the ic_node_* methods in
92 * the ieee80211com structure.
94 struct ieee80211_node {
95 struct ieee80211vap *ni_vap;
96 struct ieee80211com *ni_ic;
97 struct ieee80211_node_table *ni_table;
98 TAILQ_ENTRY(ieee80211_node) ni_list;
99 LIST_ENTRY(ieee80211_node) ni_hash;
100 atomic_t ni_refcnt;
101 u_int ni_scangen; /* gen# for timeout scan */
102 u_int8_t ni_authmode; /* authentication algorithm */
103 u_int16_t ni_flags; /* special-purpose state */
104 #define IEEE80211_NODE_AUTH 0x0001 /* authorized for data */
105 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
106 #define IEEE80211_NODE_ERP 0x0004 /* ERP enabled */
107 /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
108 #define IEEE80211_NODE_PWR_MGT 0x0010 /* power save mode enabled */
109 #define IEEE80211_NODE_AREF 0x0020 /* authentication ref held */
110 #define IEEE80211_NODE_UAPSD 0x0040 /* U-APSD power save enabled */
111 #define IEEE80211_NODE_UAPSD_TRIG 0x0080 /* U-APSD triggerable state */
112 #define IEEE80211_NODE_UAPSD_SP 0x0100 /* U-APSD SP in progress */
113 #define IEEE80211_NODE_PS_CHANGED 0x0200 /* PS state change */
114 u_int8_t ni_ath_flags; /* Atheros feature flags */
115 /* NB: These must have the same values as IEEE80211_ATHC_* */
116 #define IEEE80211_NODE_TURBOP 0x0001 /* Turbo prime enable */
117 #define IEEE80211_NODE_COMP 0x0002 /* Compresssion enable */
118 #define IEEE80211_NODE_FF 0x0004 /* Fast Frame capable */
119 #define IEEE80211_NODE_XR 0x0008 /* Atheros WME enable */
120 #define IEEE80211_NODE_AR 0x0010 /* AR capable */
121 #define IEEE80211_NODE_BOOST 0x0080
122 u_int16_t ni_ath_defkeyindex; /* Atheros def key index */
123 #define IEEE80211_INVAL_DEFKEY 0x7FFF
124 u_int16_t ni_associd; /* assoc response */
125 u_int16_t ni_txpower; /* current transmit power (in 0.5 dBm) */
126 u_int16_t ni_vlan; /* vlan tag */
127 u_int32_t *ni_challenge; /* shared-key challenge */
128 u_int8_t *ni_wpa_ie; /* captured WPA ie */
129 u_int8_t *ni_rsn_ie; /* captured RSN ie */
130 u_int8_t *ni_wme_ie; /* captured WME ie */
131 u_int8_t *ni_ath_ie; /* captured Atheros ie */
132 u_int8_t *ni_suppchans; /* supported channels */
133 u_int8_t *ni_suppchans_new; /* supported channels of ongoing association */
134 u_int8_t *ni_needed_chans; /* nodes which don't support these will be removed */
135 u_int8_t ni_n_needed_chans; /* size of ni_needed_chans list */
136 u_int16_t ni_txseqs[17]; /* tx seq per-tid */
137 u_int16_t ni_rxseqs[17]; /* rx seq previous per-tid */
138 unsigned long ni_rxfragstamp; /* time stamp of last rx frag */
139 struct sk_buff *ni_rxfrag; /* rx frag reassembly */
140 struct ieee80211_rsnparms ni_rsn; /* RSN/WPA parameters */
141 struct ieee80211_key ni_ucastkey; /* unicast key */
142 int ni_rxkeyoff; /* Receive key offset */
144 /* hardware */
145 u_int64_t ni_rtsf; /* recv timestamp */
146 unsigned long ni_last_rx; /* recv jiffies */
147 u_int8_t ni_rssi; /* recv ssi */
149 /* header */
150 u_int8_t ni_macaddr[IEEE80211_ADDR_LEN];
151 u_int8_t ni_bssid[IEEE80211_ADDR_LEN];
153 /* beacon, probe response */
154 union {
155 u_int8_t data[8];
156 __le64 tsf;
157 } ni_tstamp; /* from last rcv'd beacon */
159 u_int16_t ni_intval; /* beacon interval */
160 u_int16_t ni_intval_old; /* beacon interval before first change */
161 u_int16_t ni_intval_cnt; /* count of ni_intval != ni_intval_old */
162 unsigned long ni_intval_end; /* end of transition interval jiffies */
164 u_int16_t ni_capinfo; /* capabilities */
165 u_int8_t ni_esslen;
166 u_int8_t ni_essid[IEEE80211_NWID_LEN];
167 struct ieee80211_rateset ni_rates; /* negotiated rate set */
168 struct ieee80211_channel *ni_chan;
169 u_int16_t ni_fhdwell; /* FH only */
170 u_int8_t ni_fhindex; /* FH only */
171 u_int8_t ni_erp; /* ERP from beacon/probe resp */
172 u_int16_t ni_timoff; /* byte offset to TIM ie */
174 /* others */
175 struct sk_buff_head ni_savedq; /* packets queued for pspoll */
176 short ni_inact; /* inactivity mark count */
177 short ni_inact_reload; /* inactivity reload value */
178 int ni_txrate; /* index to ni_rates[] */
179 struct ieee80211_nodestats ni_stats; /* per-node statistics */
180 struct ieee80211vap *ni_prev_vap; /* previously associated vap */
181 u_int8_t ni_uapsd; /* U-APSD per-node flags matching WMM STA Qos Info field */
182 u_int8_t ni_uapsd_maxsp; /* maxsp from flags above */
183 u_int16_t ni_uapsd_trigseq[WME_NUM_AC]; /* trigger suppression on retry */
184 __le16 ni_pschangeseq;
186 MALLOC_DECLARE(M_80211_NODE);
188 #define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd)
190 #define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++)
191 #define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v)
192 #define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v)
194 #define WME_UAPSD_AC_CAN_TRIGGER(_ac, _ni) ( \
195 ((_ni)->ni_flags & IEEE80211_NODE_UAPSD_TRIG) && \
196 WME_UAPSD_AC_ENABLED((_ac), (_ni)->ni_uapsd))
197 #define WME_UAPSD_NODE_MAXQDEPTH 8
198 #define IEEE80211_NODE_UAPSD_USETIM(_ni) (((_ni)->ni_uapsd & 0xF) == 0xF)
199 #define WME_UAPSD_NODE_INVALIDSEQ 0xffff
200 #define WME_UAPSD_NODE_TRIGSEQINIT(_ni) \
201 (memset(&(_ni)->ni_uapsd_trigseq[0], \
202 0xff, sizeof((_ni)->ni_uapsd_trigseq)))
204 void ieee80211_node_attach(struct ieee80211com *);
205 void ieee80211_node_detach(struct ieee80211com *);
206 void ieee80211_node_vattach(struct ieee80211vap *);
207 void ieee80211_node_latevattach(struct ieee80211vap *);
208 void ieee80211_node_vdetach(struct ieee80211vap *);
210 static __inline int
211 ieee80211_node_is_authorized(const struct ieee80211_node *ni)
213 return (ni->ni_flags & IEEE80211_NODE_AUTH);
216 void ieee80211_node_authorize(struct ieee80211_node *);
217 void ieee80211_node_unauthorize(struct ieee80211_node *);
219 void ieee80211_create_ibss(struct ieee80211vap *, struct ieee80211_channel *);
220 void ieee80211_reset_bss(struct ieee80211vap *);
221 int ieee80211_ibss_merge(struct ieee80211_node *);
222 struct ieee80211_scan_entry;
223 int ieee80211_sta_join(struct ieee80211vap *, const struct ieee80211_scan_entry *);
224 void ieee80211_sta_join1_tasklet(IEEE80211_TQUEUE_ARG);
225 void ieee80211_sta_leave(struct ieee80211_node *);
227 #define WDS_AGING_TIME 600 /* 10 minutes */
228 #define WDS_AGING_COUNT 2
229 #define WDS_AGING_STATIC 0xffff
230 #define WDS_AGING_TIMER_VAL (WDS_AGING_TIME / 2)
232 struct ieee80211_wds_addr {
233 LIST_ENTRY(ieee80211_wds_addr) wds_hash;
234 u_int8_t wds_macaddr[IEEE80211_ADDR_LEN];
235 struct ieee80211_node *wds_ni;
236 u_int16_t wds_agingcount;
240 * Table of ieee80211_node instances. Each ieee80211com
241 * has at least one for holding the scan candidates.
242 * When operating as an access point or in ibss mode there
243 * is a second table for associated stations or neighbors.
245 struct ieee80211_node_table {
246 const char *nt_name; /* for debugging */
247 struct ieee80211com *nt_ic; /* back reference */
248 ieee80211_node_table_lock_t nt_nodelock; /* on node table */
249 TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */
250 ATH_LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
251 ATH_LIST_HEAD(, ieee80211_wds_addr) nt_wds_hash[IEEE80211_NODE_HASHSIZE];
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 struct timer_list nt_wds_aging_timer; /* timer to age out wds entries */
258 /* Allocates a new ieee80211_node * that has a reference count of one, and
259 * adds it to the node table. */
260 struct ieee80211_node *ieee80211_alloc_node_table(struct ieee80211vap *,
261 const u_int8_t *);
263 /* Allocates a new ieee80211_node * that has a reference count.
264 * If tmp is 0, it is added to the node table and the reference is used.
265 * If tmp is 1, then the caller gets to use the reference. */
266 struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
267 const u_int8_t *, unsigned char tmp);
269 void ieee80211_node_reset(struct ieee80211_node *, struct ieee80211vap *);
271 /* The following return node reference that the caller must manage. */
272 struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
273 const u_int8_t *);
274 struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
275 const struct ieee80211_frame_min *);
276 struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
277 const u_int8_t *);
279 void ieee80211_free_node(struct ieee80211_node *ni);
281 /* Reference counting only needs to be locked out against the transitions,
282 * 0->1 and 1->0 (i.e., when we do not own the reference we are getting).
283 * This only happens when finding the a node reference from the node table,
284 * which is locked seperately. Thus, we do not need to lock the follwoing
285 * functions.
286 * Increment the reference counter for ieee80211_node *. */
287 struct ieee80211_node *ieee80211_ref_node(struct ieee80211_node *ni);
289 #define PASS_NODE(_ni) \
290 ieee80211_pass_node(&_ni)
292 static __inline struct ieee80211_node *
293 ieee80211_pass_node(struct ieee80211_node **pni) {
294 struct ieee80211_node *tmp = *pni;
295 *pni = NULL;
296 return (tmp);
299 void ieee80211_unref_node(struct ieee80211_node **pni);
301 /* Increments reference count of ieee80211_node *ni */
302 int ieee80211_add_wds_addr(struct ieee80211_node_table *, struct ieee80211_node *,
303 const u_int8_t *, u_int8_t);
305 /* Decrements reference count of ieee80211_node *ni */
306 void ieee80211_remove_wds_addr(struct ieee80211_node_table *, const u_int8_t *);
308 /* Decrements reference count of node, if found */
309 void ieee80211_del_wds_node(struct ieee80211_node_table *, struct ieee80211_node *);
311 /* Increments reference count of node, if found */
312 struct ieee80211_node *ieee80211_find_wds_node(struct ieee80211_node_table *,
313 const u_int8_t *);
314 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
315 void ieee80211_iterate_nodes(struct ieee80211_node_table *,
316 ieee80211_iter_func *, void *);
317 void ieee80211_iterate_dev_nodes(struct net_device *,
318 struct ieee80211_node_table *, ieee80211_iter_func *, void *);
319 void ieee80211_dump_node(struct ieee80211_node_table *,
320 struct ieee80211_node *);
321 void ieee80211_dump_nodes(struct ieee80211_node_table *);
322 /* Returns a node with refcount of one. Caller must release that reference */
323 struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
324 const u_int8_t macaddr[]);
325 struct ieee80211_scanparams;
326 /* Returns a node with refcount of one. Caller must release that reference */
327 struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
328 const struct ieee80211_frame *, const struct ieee80211_scanparams *);
329 /* Increments reference count of node */
330 void ieee80211_node_join(struct ieee80211_node *, int);
331 /* Decrements reference count of node */
332 void ieee80211_node_leave(struct ieee80211_node *);
333 u_int8_t ieee80211_getrssi(struct ieee80211com *);
334 int32_t ieee80211_get_node_count(struct ieee80211com *);
335 #endif /* _NET80211_IEEE80211_NODE_H_ */