Deleted Added
full compact
ieee80211_node.h (192468) ieee80211_node.h (193239)
1/*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
4 * All rights reserved.
5 *
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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
4 * All rights reserved.
5 *
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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/net80211/ieee80211_node.h 192468 2009-05-20 20:00:40Z sam $
26 * $FreeBSD: head/sys/net80211/ieee80211_node.h 193239 2009-06-01 16:36:28Z sam $
27 */
28#ifndef _NET80211_IEEE80211_NODE_H_
29#define _NET80211_IEEE80211_NODE_H_
30
31#include <net80211/ieee80211_ioctl.h> /* for ieee80211_nodestats */
32#include <net80211/ieee80211_ht.h> /* for aggregation state */
33
34/*
35 * Each ieee80211com instance has a single timer that fires every
36 * IEEE80211_INACT_WAIT seconds to handle "inactivity processing".
37 * This is used to do node inactivity processing when operating
38 * as an AP or in adhoc mode. For inactivity processing each node
39 * has a timeout set in it's ni_inact field that is decremented
40 * on each timeout and the node is reclaimed when the counter goes
41 * to zero. We use different inactivity timeout values depending
42 * on whether the node is associated and authorized (either by
43 * 802.1x or open/shared key authentication) or associated but yet
44 * to be authorized. The latter timeout is shorter to more aggressively
45 * reclaim nodes that leave part way through the 802.1x exchange.
46 */
47#define IEEE80211_INACT_WAIT 15 /* inactivity interval (secs) */
48#define IEEE80211_INACT_INIT (30/IEEE80211_INACT_WAIT) /* initial */
49#define IEEE80211_INACT_AUTH (180/IEEE80211_INACT_WAIT) /* associated but not authorized */
50#define IEEE80211_INACT_RUN (300/IEEE80211_INACT_WAIT) /* authorized */
51#define IEEE80211_INACT_PROBE (30/IEEE80211_INACT_WAIT) /* probe */
52#define IEEE80211_INACT_SCAN (300/IEEE80211_INACT_WAIT) /* scanned */
53
54#define IEEE80211_TRANS_WAIT 2 /* mgt frame tx timer (secs) */
55
56/* threshold for aging overlapping non-ERP bss */
57#define IEEE80211_NONERP_PRESENT_AGE msecs_to_ticks(60*1000)
58
59#define IEEE80211_NODE_HASHSIZE 32
60/* simple hash is enough for variation of macaddr */
61#define IEEE80211_NODE_HASH(addr) \
62 (((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
63 IEEE80211_NODE_HASHSIZE)
64
65struct ieee80211_node_table;
66struct ieee80211com;
67struct ieee80211vap;
68
69/*
70 * Information element ``blob''. We use this structure
71 * to capture management frame payloads that need to be
72 * retained. Information elements within the payload that
73 * we need to consult have references recorded.
74 */
75struct ieee80211_ies {
76 /* the following are either NULL or point within data */
77 uint8_t *wpa_ie; /* captured WPA ie */
78 uint8_t *rsn_ie; /* captured RSN ie */
79 uint8_t *wme_ie; /* captured WME ie */
80 uint8_t *ath_ie; /* captured Atheros ie */
81 uint8_t *htcap_ie; /* captured HTCAP ie */
82 uint8_t *htinfo_ie; /* captured HTINFO ie */
83 uint8_t *tdma_ie; /* captured TDMA ie */
27 */
28#ifndef _NET80211_IEEE80211_NODE_H_
29#define _NET80211_IEEE80211_NODE_H_
30
31#include <net80211/ieee80211_ioctl.h> /* for ieee80211_nodestats */
32#include <net80211/ieee80211_ht.h> /* for aggregation state */
33
34/*
35 * Each ieee80211com instance has a single timer that fires every
36 * IEEE80211_INACT_WAIT seconds to handle "inactivity processing".
37 * This is used to do node inactivity processing when operating
38 * as an AP or in adhoc mode. For inactivity processing each node
39 * has a timeout set in it's ni_inact field that is decremented
40 * on each timeout and the node is reclaimed when the counter goes
41 * to zero. We use different inactivity timeout values depending
42 * on whether the node is associated and authorized (either by
43 * 802.1x or open/shared key authentication) or associated but yet
44 * to be authorized. The latter timeout is shorter to more aggressively
45 * reclaim nodes that leave part way through the 802.1x exchange.
46 */
47#define IEEE80211_INACT_WAIT 15 /* inactivity interval (secs) */
48#define IEEE80211_INACT_INIT (30/IEEE80211_INACT_WAIT) /* initial */
49#define IEEE80211_INACT_AUTH (180/IEEE80211_INACT_WAIT) /* associated but not authorized */
50#define IEEE80211_INACT_RUN (300/IEEE80211_INACT_WAIT) /* authorized */
51#define IEEE80211_INACT_PROBE (30/IEEE80211_INACT_WAIT) /* probe */
52#define IEEE80211_INACT_SCAN (300/IEEE80211_INACT_WAIT) /* scanned */
53
54#define IEEE80211_TRANS_WAIT 2 /* mgt frame tx timer (secs) */
55
56/* threshold for aging overlapping non-ERP bss */
57#define IEEE80211_NONERP_PRESENT_AGE msecs_to_ticks(60*1000)
58
59#define IEEE80211_NODE_HASHSIZE 32
60/* simple hash is enough for variation of macaddr */
61#define IEEE80211_NODE_HASH(addr) \
62 (((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
63 IEEE80211_NODE_HASHSIZE)
64
65struct ieee80211_node_table;
66struct ieee80211com;
67struct ieee80211vap;
68
69/*
70 * Information element ``blob''. We use this structure
71 * to capture management frame payloads that need to be
72 * retained. Information elements within the payload that
73 * we need to consult have references recorded.
74 */
75struct ieee80211_ies {
76 /* the following are either NULL or point within data */
77 uint8_t *wpa_ie; /* captured WPA ie */
78 uint8_t *rsn_ie; /* captured RSN ie */
79 uint8_t *wme_ie; /* captured WME ie */
80 uint8_t *ath_ie; /* captured Atheros ie */
81 uint8_t *htcap_ie; /* captured HTCAP ie */
82 uint8_t *htinfo_ie; /* captured HTINFO ie */
83 uint8_t *tdma_ie; /* captured TDMA ie */
84 uint8_t *spare[4];
84 /* NB: these must be the last members of this structure */
85 uint8_t *data; /* frame data > 802.11 header */
86 int len; /* data size in bytes */
87};
88
89/*
90 * Node specific information. Note that drivers are expected
91 * to derive from this structure to add device-specific per-node
92 * state. This is done by overriding the ic_node_* methods in
93 * the ieee80211com structure.
94 */
95struct ieee80211_node {
96 struct ieee80211vap *ni_vap; /* associated vap */
97 struct ieee80211com *ni_ic; /* copy from vap to save deref*/
98 struct ieee80211_node_table *ni_table; /* NB: may be NULL */
99 TAILQ_ENTRY(ieee80211_node) ni_list; /* list of all nodes */
100 LIST_ENTRY(ieee80211_node) ni_hash; /* hash collision list */
101 u_int ni_refcnt; /* count of held references */
102 u_int ni_scangen; /* gen# for timeout scan */
103 u_int ni_flags;
104#define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
105#define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
106#define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
107/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
108#define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
109#define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
110#define IEEE80211_NODE_HT 0x000040 /* HT enabled */
111#define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
112#define IEEE80211_NODE_WPS 0x000100 /* WPS association */
113#define IEEE80211_NODE_TSN 0x000200 /* TSN association */
114#define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
115#define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
116#define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
117#define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
118#define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
119#define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
120#define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
121#define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
122 uint16_t ni_associd; /* association ID */
123 uint16_t ni_vlan; /* vlan tag */
124 uint16_t ni_txpower; /* current transmit power */
125 uint8_t ni_authmode; /* authentication algorithm */
126 uint8_t ni_ath_flags; /* Atheros feature flags */
127 /* NB: These must have the same values as IEEE80211_ATHC_* */
128#define IEEE80211_NODE_TURBOP 0x0001 /* Turbo prime enable */
129#define IEEE80211_NODE_COMP 0x0002 /* Compresssion enable */
130#define IEEE80211_NODE_FF 0x0004 /* Fast Frame capable */
131#define IEEE80211_NODE_XR 0x0008 /* Atheros WME enable */
132#define IEEE80211_NODE_AR 0x0010 /* AR capable */
133#define IEEE80211_NODE_BOOST 0x0080 /* Dynamic Turbo boosted */
134 uint16_t ni_ath_defkeyix;/* Atheros def key index */
135 const struct ieee80211_txparam *ni_txparms;
136 uint32_t ni_jointime; /* time of join (secs) */
137 uint32_t *ni_challenge; /* shared-key challenge */
138 struct ieee80211_ies ni_ies; /* captured ie's */
139 /* tx seq per-tid */
140 ieee80211_seq ni_txseqs[IEEE80211_TID_SIZE];
141 /* rx seq previous per-tid*/
142 ieee80211_seq ni_rxseqs[IEEE80211_TID_SIZE];
143 uint32_t ni_rxfragstamp; /* time stamp of last rx frag */
144 struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */
145 struct ieee80211_key ni_ucastkey; /* unicast key */
146
147 /* hardware */
148 uint32_t ni_avgrssi; /* recv ssi state */
149 int8_t ni_noise; /* noise floor */
150
151 /* header */
152 uint8_t ni_macaddr[IEEE80211_ADDR_LEN];
153 uint8_t ni_bssid[IEEE80211_ADDR_LEN];
154
155 /* beacon, probe response */
156 union {
157 uint8_t data[8];
158 u_int64_t tsf;
159 } ni_tstamp; /* from last rcv'd beacon */
160 uint16_t ni_intval; /* beacon interval */
161 uint16_t ni_capinfo; /* capabilities */
162 uint8_t ni_esslen;
163 uint8_t ni_essid[IEEE80211_NWID_LEN];
164 struct ieee80211_rateset ni_rates; /* negotiated rate set */
165 struct ieee80211_channel *ni_chan;
166 uint16_t ni_fhdwell; /* FH only */
167 uint8_t ni_fhindex; /* FH only */
168 uint16_t ni_erp; /* ERP from beacon/probe resp */
169 uint16_t ni_timoff; /* byte offset to TIM ie */
170 uint8_t ni_dtim_period; /* DTIM period */
171 uint8_t ni_dtim_count; /* DTIM count for last bcn */
172
173 /* 11n state */
174 uint16_t ni_htcap; /* HT capabilities */
175 uint8_t ni_htparam; /* HT params */
176 uint8_t ni_htctlchan; /* HT control channel */
177 uint8_t ni_ht2ndchan; /* HT 2nd channel */
178 uint8_t ni_htopmode; /* HT operating mode */
179 uint8_t ni_htstbc; /* HT */
180 uint8_t ni_chw; /* negotiated channel width */
181 struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */
182 struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC];
183 struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
184
185 /* others */
186 short ni_inact; /* inactivity mark count */
187 short ni_inact_reload;/* inactivity reload value */
188 int ni_txrate; /* legacy rate/MCS */
189 struct ieee80211_psq ni_psq; /* power save queue */
190 struct ieee80211_nodestats ni_stats; /* per-node statistics */
191
192 struct ieee80211vap *ni_wdsvap; /* associated WDS vap */
193 /* XXX move to vap? */
194 struct ifqueue ni_wdsq; /* wds pending queue */
85 /* NB: these must be the last members of this structure */
86 uint8_t *data; /* frame data > 802.11 header */
87 int len; /* data size in bytes */
88};
89
90/*
91 * Node specific information. Note that drivers are expected
92 * to derive from this structure to add device-specific per-node
93 * state. This is done by overriding the ic_node_* methods in
94 * the ieee80211com structure.
95 */
96struct ieee80211_node {
97 struct ieee80211vap *ni_vap; /* associated vap */
98 struct ieee80211com *ni_ic; /* copy from vap to save deref*/
99 struct ieee80211_node_table *ni_table; /* NB: may be NULL */
100 TAILQ_ENTRY(ieee80211_node) ni_list; /* list of all nodes */
101 LIST_ENTRY(ieee80211_node) ni_hash; /* hash collision list */
102 u_int ni_refcnt; /* count of held references */
103 u_int ni_scangen; /* gen# for timeout scan */
104 u_int ni_flags;
105#define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
106#define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
107#define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
108/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
109#define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
110#define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
111#define IEEE80211_NODE_HT 0x000040 /* HT enabled */
112#define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
113#define IEEE80211_NODE_WPS 0x000100 /* WPS association */
114#define IEEE80211_NODE_TSN 0x000200 /* TSN association */
115#define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
116#define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
117#define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
118#define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
119#define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
120#define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
121#define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
122#define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
123 uint16_t ni_associd; /* association ID */
124 uint16_t ni_vlan; /* vlan tag */
125 uint16_t ni_txpower; /* current transmit power */
126 uint8_t ni_authmode; /* authentication algorithm */
127 uint8_t ni_ath_flags; /* Atheros feature flags */
128 /* NB: These must have the same values as IEEE80211_ATHC_* */
129#define IEEE80211_NODE_TURBOP 0x0001 /* Turbo prime enable */
130#define IEEE80211_NODE_COMP 0x0002 /* Compresssion enable */
131#define IEEE80211_NODE_FF 0x0004 /* Fast Frame capable */
132#define IEEE80211_NODE_XR 0x0008 /* Atheros WME enable */
133#define IEEE80211_NODE_AR 0x0010 /* AR capable */
134#define IEEE80211_NODE_BOOST 0x0080 /* Dynamic Turbo boosted */
135 uint16_t ni_ath_defkeyix;/* Atheros def key index */
136 const struct ieee80211_txparam *ni_txparms;
137 uint32_t ni_jointime; /* time of join (secs) */
138 uint32_t *ni_challenge; /* shared-key challenge */
139 struct ieee80211_ies ni_ies; /* captured ie's */
140 /* tx seq per-tid */
141 ieee80211_seq ni_txseqs[IEEE80211_TID_SIZE];
142 /* rx seq previous per-tid*/
143 ieee80211_seq ni_rxseqs[IEEE80211_TID_SIZE];
144 uint32_t ni_rxfragstamp; /* time stamp of last rx frag */
145 struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */
146 struct ieee80211_key ni_ucastkey; /* unicast key */
147
148 /* hardware */
149 uint32_t ni_avgrssi; /* recv ssi state */
150 int8_t ni_noise; /* noise floor */
151
152 /* header */
153 uint8_t ni_macaddr[IEEE80211_ADDR_LEN];
154 uint8_t ni_bssid[IEEE80211_ADDR_LEN];
155
156 /* beacon, probe response */
157 union {
158 uint8_t data[8];
159 u_int64_t tsf;
160 } ni_tstamp; /* from last rcv'd beacon */
161 uint16_t ni_intval; /* beacon interval */
162 uint16_t ni_capinfo; /* capabilities */
163 uint8_t ni_esslen;
164 uint8_t ni_essid[IEEE80211_NWID_LEN];
165 struct ieee80211_rateset ni_rates; /* negotiated rate set */
166 struct ieee80211_channel *ni_chan;
167 uint16_t ni_fhdwell; /* FH only */
168 uint8_t ni_fhindex; /* FH only */
169 uint16_t ni_erp; /* ERP from beacon/probe resp */
170 uint16_t ni_timoff; /* byte offset to TIM ie */
171 uint8_t ni_dtim_period; /* DTIM period */
172 uint8_t ni_dtim_count; /* DTIM count for last bcn */
173
174 /* 11n state */
175 uint16_t ni_htcap; /* HT capabilities */
176 uint8_t ni_htparam; /* HT params */
177 uint8_t ni_htctlchan; /* HT control channel */
178 uint8_t ni_ht2ndchan; /* HT 2nd channel */
179 uint8_t ni_htopmode; /* HT operating mode */
180 uint8_t ni_htstbc; /* HT */
181 uint8_t ni_chw; /* negotiated channel width */
182 struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */
183 struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC];
184 struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
185
186 /* others */
187 short ni_inact; /* inactivity mark count */
188 short ni_inact_reload;/* inactivity reload value */
189 int ni_txrate; /* legacy rate/MCS */
190 struct ieee80211_psq ni_psq; /* power save queue */
191 struct ieee80211_nodestats ni_stats; /* per-node statistics */
192
193 struct ieee80211vap *ni_wdsvap; /* associated WDS vap */
194 /* XXX move to vap? */
195 struct ifqueue ni_wdsq; /* wds pending queue */
196 uint64_t ni_spare[4];
195};
196MALLOC_DECLARE(M_80211_NODE);
197MALLOC_DECLARE(M_80211_NODE_IE);
198
199#define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
200#define IEEE80211_NODE_AMPDU \
201 (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
202#define IEEE80211_NODE_HT_ALL \
203 (IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \
204 IEEE80211_NODE_AMPDU | IEEE80211_NODE_MIMO_PS | \
205 IEEE80211_NODE_MIMO_RTS | IEEE80211_NODE_RIFS | \
206 IEEE80211_NODE_SGI20 | IEEE80211_NODE_SGI40)
207
208#define IEEE80211_NODE_BITS \
209 "\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \
210 "\13AMPDU_RX\14AMPDU_TX\15MIMO_PS\16MIMO_RTS\17RIFS\20SGI20\21SGI40" \
211 "\22ASSOCID"
212
213#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd)
214
215#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++)
216#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v)
217#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v)
218
219/*
220 * Filtered rssi calculation support. The receive rssi is maintained
221 * as an average over the last 10 frames received using a low pass filter
222 * (all frames for now, possibly need to be more selective). Calculations
223 * are designed such that a good compiler can optimize them. The avg
224 * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and
225 * each sample incorporated with IEEE80211_RSSI_LPF. Use IEEE80211_RSSI_GET
226 * to extract the current value.
227 *
228 * Note that we assume rssi data are in the range [-127..127] and we
229 * discard values <-20. This is consistent with assumptions throughout
230 * net80211 that signal strength data are in .5 dBm units relative to
231 * the current noise floor (linear, not log).
232 */
233#define IEEE80211_RSSI_LPF_LEN 10
234#define IEEE80211_RSSI_DUMMY_MARKER 127
235/* NB: pow2 to optimize out * and / */
236#define IEEE80211_RSSI_EP_MULTIPLIER (1<<7)
237#define IEEE80211_RSSI_IN(x) ((x) * IEEE80211_RSSI_EP_MULTIPLIER)
238#define _IEEE80211_RSSI_LPF(x, y, len) \
239 (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
240#define IEEE80211_RSSI_LPF(x, y) do { \
241 if ((y) >= -20) { \
242 x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), \
243 IEEE80211_RSSI_LPF_LEN); \
244 } \
245} while (0)
246#define IEEE80211_RSSI_EP_RND(x, mul) \
247 ((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
248#define IEEE80211_RSSI_GET(x) \
249 IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER)
250
251static __inline struct ieee80211_node *
252ieee80211_ref_node(struct ieee80211_node *ni)
253{
254 ieee80211_node_incref(ni);
255 return ni;
256}
257
258static __inline void
259ieee80211_unref_node(struct ieee80211_node **ni)
260{
261 ieee80211_node_decref(*ni);
262 *ni = NULL; /* guard against use */
263}
264
265struct ieee80211com;
266
267void ieee80211_node_attach(struct ieee80211com *);
268void ieee80211_node_lateattach(struct ieee80211com *);
269void ieee80211_node_detach(struct ieee80211com *);
270void ieee80211_node_vattach(struct ieee80211vap *);
271void ieee80211_node_latevattach(struct ieee80211vap *);
272void ieee80211_node_vdetach(struct ieee80211vap *);
273
274static __inline int
275ieee80211_node_is_authorized(const struct ieee80211_node *ni)
276{
277 return (ni->ni_flags & IEEE80211_NODE_AUTH);
278}
279
280void ieee80211_node_authorize(struct ieee80211_node *);
281void ieee80211_node_unauthorize(struct ieee80211_node *);
282
283void ieee80211_node_set_chan(struct ieee80211_node *,
284 struct ieee80211_channel *);
285void ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *);
286void ieee80211_reset_bss(struct ieee80211vap *);
287void ieee80211_sync_curchan(struct ieee80211com *);
288void ieee80211_setupcurchan(struct ieee80211com *,
289 struct ieee80211_channel *);
290void ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *);
291int ieee80211_ibss_merge(struct ieee80211_node *);
292struct ieee80211_scan_entry;
293int ieee80211_sta_join(struct ieee80211vap *, struct ieee80211_channel *,
294 const struct ieee80211_scan_entry *);
295void ieee80211_sta_leave(struct ieee80211_node *);
296void ieee80211_node_deauth(struct ieee80211_node *, int);
297
298int ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
299void ieee80211_ies_cleanup(struct ieee80211_ies *);
300void ieee80211_ies_expand(struct ieee80211_ies *);
301#define ieee80211_ies_setie(_ies, _ie, _off) do { \
302 (_ies)._ie = (_ies).data + (_off); \
303} while (0)
304
305/*
306 * Table of ieee80211_node instances. Each ieee80211com
307 * has one that holds association stations (when operating
308 * as an ap) or neighbors (in ibss mode).
309 *
310 * XXX embed this in ieee80211com instead of indirect?
311 */
312struct ieee80211_node_table {
313 struct ieee80211com *nt_ic; /* back reference */
314 ieee80211_node_lock_t nt_nodelock; /* on node table */
315 TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */
316 LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
317 struct ieee80211_node **nt_keyixmap; /* key ix -> node map */
318 int nt_keyixmax; /* keyixmap size */
319 const char *nt_name; /* table name for debug msgs */
320 ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */
321 u_int nt_scangen; /* gen# for iterators */
322 int nt_inact_init; /* initial node inact setting */
323};
324
325struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *,
326 struct ieee80211vap *,
327 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
328struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *,
329 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
330struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
331 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
332struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
333 const uint8_t bssid[IEEE80211_ADDR_LEN],
334 struct ieee80211_channel *);
335#ifdef IEEE80211_DEBUG_REFCNT
336void ieee80211_free_node_debug(struct ieee80211_node *,
337 const char *func, int line);
338struct ieee80211_node *ieee80211_find_node_locked_debug(
339 struct ieee80211_node_table *,
340 const uint8_t macaddr[IEEE80211_ADDR_LEN],
341 const char *func, int line);
342struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
343 const uint8_t macaddr[IEEE80211_ADDR_LEN],
344 const char *func, int line);
345struct ieee80211_node *ieee80211_find_vap_node_locked_debug(
346 struct ieee80211_node_table *,
347 const struct ieee80211vap *vap,
348 const uint8_t macaddr[IEEE80211_ADDR_LEN],
349 const char *func, int line);
350struct ieee80211_node *ieee80211_find_vap_node_debug(
351 struct ieee80211_node_table *,
352 const struct ieee80211vap *vap,
353 const uint8_t macaddr[IEEE80211_ADDR_LEN],
354 const char *func, int line);
355struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
356 const struct ieee80211_frame_min *,
357 const char *func, int line);
358struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
359 struct ieee80211com *,
360 const struct ieee80211_frame_min *, uint16_t keyix,
361 const char *func, int line);
362struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
363 const uint8_t *,
364 const char *func, int line);
365#define ieee80211_free_node(ni) \
366 ieee80211_free_node_debug(ni, __func__, __LINE__)
367#define ieee80211_find_node_locked(nt, mac) \
368 ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__)
369#define ieee80211_find_node(nt, mac) \
370 ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
371#define ieee80211_find_vap_node_locked(nt, vap, mac) \
372 ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__)
373#define ieee80211_find_vap_node(nt, vap, mac) \
374 ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__)
375#define ieee80211_find_rxnode(ic, wh) \
376 ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__)
377#define ieee80211_find_rxnode_withkey(ic, wh, keyix) \
378 ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__)
379#define ieee80211_find_txnode(vap, mac) \
380 ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__)
381#else
382void ieee80211_free_node(struct ieee80211_node *);
383struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *,
384 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
385struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
386 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
387struct ieee80211_node *ieee80211_find_vap_node_locked(
388 struct ieee80211_node_table *, const struct ieee80211vap *,
389 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
390struct ieee80211_node *ieee80211_find_vap_node(
391 struct ieee80211_node_table *, const struct ieee80211vap *,
392 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
393struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
394 const struct ieee80211_frame_min *);
395struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
396 const struct ieee80211_frame_min *, uint16_t keyix);
397struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
398 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
399#endif
400int ieee80211_node_delucastkey(struct ieee80211_node *);
401void ieee80211_node_timeout(void *arg);
402
403typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
404void ieee80211_iterate_nodes(struct ieee80211_node_table *,
405 ieee80211_iter_func *, void *);
406
407void ieee80211_notify_erp(struct ieee80211com *);
408void ieee80211_dump_node(struct ieee80211_node_table *,
409 struct ieee80211_node *);
410void ieee80211_dump_nodes(struct ieee80211_node_table *);
411
412struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
413 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
414struct ieee80211_scanparams;
415void ieee80211_init_neighbor(struct ieee80211_node *,
416 const struct ieee80211_frame *,
417 const struct ieee80211_scanparams *);
418struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
419 const struct ieee80211_frame *,
420 const struct ieee80211_scanparams *);
421void ieee80211_node_join(struct ieee80211_node *,int);
422void ieee80211_node_leave(struct ieee80211_node *);
423int8_t ieee80211_getrssi(struct ieee80211vap *);
424void ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
425#endif /* _NET80211_IEEE80211_NODE_H_ */
197};
198MALLOC_DECLARE(M_80211_NODE);
199MALLOC_DECLARE(M_80211_NODE_IE);
200
201#define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
202#define IEEE80211_NODE_AMPDU \
203 (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
204#define IEEE80211_NODE_HT_ALL \
205 (IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \
206 IEEE80211_NODE_AMPDU | IEEE80211_NODE_MIMO_PS | \
207 IEEE80211_NODE_MIMO_RTS | IEEE80211_NODE_RIFS | \
208 IEEE80211_NODE_SGI20 | IEEE80211_NODE_SGI40)
209
210#define IEEE80211_NODE_BITS \
211 "\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \
212 "\13AMPDU_RX\14AMPDU_TX\15MIMO_PS\16MIMO_RTS\17RIFS\20SGI20\21SGI40" \
213 "\22ASSOCID"
214
215#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd)
216
217#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++)
218#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v)
219#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v)
220
221/*
222 * Filtered rssi calculation support. The receive rssi is maintained
223 * as an average over the last 10 frames received using a low pass filter
224 * (all frames for now, possibly need to be more selective). Calculations
225 * are designed such that a good compiler can optimize them. The avg
226 * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and
227 * each sample incorporated with IEEE80211_RSSI_LPF. Use IEEE80211_RSSI_GET
228 * to extract the current value.
229 *
230 * Note that we assume rssi data are in the range [-127..127] and we
231 * discard values <-20. This is consistent with assumptions throughout
232 * net80211 that signal strength data are in .5 dBm units relative to
233 * the current noise floor (linear, not log).
234 */
235#define IEEE80211_RSSI_LPF_LEN 10
236#define IEEE80211_RSSI_DUMMY_MARKER 127
237/* NB: pow2 to optimize out * and / */
238#define IEEE80211_RSSI_EP_MULTIPLIER (1<<7)
239#define IEEE80211_RSSI_IN(x) ((x) * IEEE80211_RSSI_EP_MULTIPLIER)
240#define _IEEE80211_RSSI_LPF(x, y, len) \
241 (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
242#define IEEE80211_RSSI_LPF(x, y) do { \
243 if ((y) >= -20) { \
244 x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), \
245 IEEE80211_RSSI_LPF_LEN); \
246 } \
247} while (0)
248#define IEEE80211_RSSI_EP_RND(x, mul) \
249 ((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
250#define IEEE80211_RSSI_GET(x) \
251 IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER)
252
253static __inline struct ieee80211_node *
254ieee80211_ref_node(struct ieee80211_node *ni)
255{
256 ieee80211_node_incref(ni);
257 return ni;
258}
259
260static __inline void
261ieee80211_unref_node(struct ieee80211_node **ni)
262{
263 ieee80211_node_decref(*ni);
264 *ni = NULL; /* guard against use */
265}
266
267struct ieee80211com;
268
269void ieee80211_node_attach(struct ieee80211com *);
270void ieee80211_node_lateattach(struct ieee80211com *);
271void ieee80211_node_detach(struct ieee80211com *);
272void ieee80211_node_vattach(struct ieee80211vap *);
273void ieee80211_node_latevattach(struct ieee80211vap *);
274void ieee80211_node_vdetach(struct ieee80211vap *);
275
276static __inline int
277ieee80211_node_is_authorized(const struct ieee80211_node *ni)
278{
279 return (ni->ni_flags & IEEE80211_NODE_AUTH);
280}
281
282void ieee80211_node_authorize(struct ieee80211_node *);
283void ieee80211_node_unauthorize(struct ieee80211_node *);
284
285void ieee80211_node_set_chan(struct ieee80211_node *,
286 struct ieee80211_channel *);
287void ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *);
288void ieee80211_reset_bss(struct ieee80211vap *);
289void ieee80211_sync_curchan(struct ieee80211com *);
290void ieee80211_setupcurchan(struct ieee80211com *,
291 struct ieee80211_channel *);
292void ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *);
293int ieee80211_ibss_merge(struct ieee80211_node *);
294struct ieee80211_scan_entry;
295int ieee80211_sta_join(struct ieee80211vap *, struct ieee80211_channel *,
296 const struct ieee80211_scan_entry *);
297void ieee80211_sta_leave(struct ieee80211_node *);
298void ieee80211_node_deauth(struct ieee80211_node *, int);
299
300int ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
301void ieee80211_ies_cleanup(struct ieee80211_ies *);
302void ieee80211_ies_expand(struct ieee80211_ies *);
303#define ieee80211_ies_setie(_ies, _ie, _off) do { \
304 (_ies)._ie = (_ies).data + (_off); \
305} while (0)
306
307/*
308 * Table of ieee80211_node instances. Each ieee80211com
309 * has one that holds association stations (when operating
310 * as an ap) or neighbors (in ibss mode).
311 *
312 * XXX embed this in ieee80211com instead of indirect?
313 */
314struct ieee80211_node_table {
315 struct ieee80211com *nt_ic; /* back reference */
316 ieee80211_node_lock_t nt_nodelock; /* on node table */
317 TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */
318 LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
319 struct ieee80211_node **nt_keyixmap; /* key ix -> node map */
320 int nt_keyixmax; /* keyixmap size */
321 const char *nt_name; /* table name for debug msgs */
322 ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */
323 u_int nt_scangen; /* gen# for iterators */
324 int nt_inact_init; /* initial node inact setting */
325};
326
327struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *,
328 struct ieee80211vap *,
329 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
330struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *,
331 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
332struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
333 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
334struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
335 const uint8_t bssid[IEEE80211_ADDR_LEN],
336 struct ieee80211_channel *);
337#ifdef IEEE80211_DEBUG_REFCNT
338void ieee80211_free_node_debug(struct ieee80211_node *,
339 const char *func, int line);
340struct ieee80211_node *ieee80211_find_node_locked_debug(
341 struct ieee80211_node_table *,
342 const uint8_t macaddr[IEEE80211_ADDR_LEN],
343 const char *func, int line);
344struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
345 const uint8_t macaddr[IEEE80211_ADDR_LEN],
346 const char *func, int line);
347struct ieee80211_node *ieee80211_find_vap_node_locked_debug(
348 struct ieee80211_node_table *,
349 const struct ieee80211vap *vap,
350 const uint8_t macaddr[IEEE80211_ADDR_LEN],
351 const char *func, int line);
352struct ieee80211_node *ieee80211_find_vap_node_debug(
353 struct ieee80211_node_table *,
354 const struct ieee80211vap *vap,
355 const uint8_t macaddr[IEEE80211_ADDR_LEN],
356 const char *func, int line);
357struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
358 const struct ieee80211_frame_min *,
359 const char *func, int line);
360struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
361 struct ieee80211com *,
362 const struct ieee80211_frame_min *, uint16_t keyix,
363 const char *func, int line);
364struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
365 const uint8_t *,
366 const char *func, int line);
367#define ieee80211_free_node(ni) \
368 ieee80211_free_node_debug(ni, __func__, __LINE__)
369#define ieee80211_find_node_locked(nt, mac) \
370 ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__)
371#define ieee80211_find_node(nt, mac) \
372 ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
373#define ieee80211_find_vap_node_locked(nt, vap, mac) \
374 ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__)
375#define ieee80211_find_vap_node(nt, vap, mac) \
376 ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__)
377#define ieee80211_find_rxnode(ic, wh) \
378 ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__)
379#define ieee80211_find_rxnode_withkey(ic, wh, keyix) \
380 ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__)
381#define ieee80211_find_txnode(vap, mac) \
382 ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__)
383#else
384void ieee80211_free_node(struct ieee80211_node *);
385struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *,
386 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
387struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
388 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
389struct ieee80211_node *ieee80211_find_vap_node_locked(
390 struct ieee80211_node_table *, const struct ieee80211vap *,
391 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
392struct ieee80211_node *ieee80211_find_vap_node(
393 struct ieee80211_node_table *, const struct ieee80211vap *,
394 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
395struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
396 const struct ieee80211_frame_min *);
397struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
398 const struct ieee80211_frame_min *, uint16_t keyix);
399struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
400 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
401#endif
402int ieee80211_node_delucastkey(struct ieee80211_node *);
403void ieee80211_node_timeout(void *arg);
404
405typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
406void ieee80211_iterate_nodes(struct ieee80211_node_table *,
407 ieee80211_iter_func *, void *);
408
409void ieee80211_notify_erp(struct ieee80211com *);
410void ieee80211_dump_node(struct ieee80211_node_table *,
411 struct ieee80211_node *);
412void ieee80211_dump_nodes(struct ieee80211_node_table *);
413
414struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
415 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
416struct ieee80211_scanparams;
417void ieee80211_init_neighbor(struct ieee80211_node *,
418 const struct ieee80211_frame *,
419 const struct ieee80211_scanparams *);
420struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
421 const struct ieee80211_frame *,
422 const struct ieee80211_scanparams *);
423void ieee80211_node_join(struct ieee80211_node *,int);
424void ieee80211_node_leave(struct ieee80211_node *);
425int8_t ieee80211_getrssi(struct ieee80211vap *);
426void ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
427#endif /* _NET80211_IEEE80211_NODE_H_ */