ieee80211_node.c revision 1.75.4.2 1 1.75.4.2 phil /* $NetBSD: ieee80211_node.c,v 1.75.4.2 2018/07/12 16:35:34 phil Exp $ */
2 1.75.4.2 phil
3 1.75.4.1 phil /*-
4 1.75.4.1 phil * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 1.75.4.1 phil *
6 1.1 dyoung * Copyright (c) 2001 Atsushi Onoe
7 1.75.4.1 phil * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
8 1.1 dyoung * All rights reserved.
9 1.1 dyoung *
10 1.1 dyoung * Redistribution and use in source and binary forms, with or without
11 1.1 dyoung * modification, are permitted provided that the following conditions
12 1.1 dyoung * are met:
13 1.1 dyoung * 1. Redistributions of source code must retain the above copyright
14 1.1 dyoung * notice, this list of conditions and the following disclaimer.
15 1.1 dyoung * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 dyoung * notice, this list of conditions and the following disclaimer in the
17 1.1 dyoung * documentation and/or other materials provided with the distribution.
18 1.1 dyoung *
19 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.1 dyoung * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.1 dyoung * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.1 dyoung * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.1 dyoung * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 1.1 dyoung * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.1 dyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.1 dyoung * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.1 dyoung * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 1.1 dyoung * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.1 dyoung */
30 1.1 dyoung
31 1.1 dyoung #include <sys/cdefs.h>
32 1.75.4.2 phil #if __FreeBSD__
33 1.75.4.1 phil __FBSDID("$FreeBSD$");
34 1.75.4.2 phil #endif
35 1.1 dyoung
36 1.75.4.1 phil #include "opt_wlan.h"
37 1.1 dyoung
38 1.1 dyoung #include <sys/param.h>
39 1.75.4.1 phil #include <sys/systm.h>
40 1.75.4.1 phil #include <sys/mbuf.h>
41 1.1 dyoung #include <sys/malloc.h>
42 1.1 dyoung #include <sys/kernel.h>
43 1.75.4.2 phil #ifdef __NetBSD__
44 1.75.4.2 phil #include <sys/sbuf.h>
45 1.75.4.2 phil #endif
46 1.39 dyoung
47 1.1 dyoung #include <sys/socket.h>
48 1.75.4.1 phil
49 1.1 dyoung #include <net/if.h>
50 1.75.4.2 phil #if __FreeBSD__
51 1.75.4.1 phil #include <net/if_var.h>
52 1.75.4.2 phil #endif
53 1.1 dyoung #include <net/if_media.h>
54 1.75.4.2 phil #if __FreeBSD__
55 1.75.4.1 phil #include <net/ethernet.h>
56 1.75.4.2 phil #endif
57 1.75.4.2 phil #ifdef __NetBSD__
58 1.75.4.2 phil #include <net/if_ether.h>
59 1.75.4.2 phil #include <net/route.h>
60 1.75.4.2 phil #endif
61 1.1 dyoung
62 1.1 dyoung #include <net80211/ieee80211_var.h>
63 1.75.4.1 phil #include <net80211/ieee80211_input.h>
64 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
65 1.75.4.1 phil #include <net80211/ieee80211_superg.h>
66 1.75.4.1 phil #endif
67 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_TDMA
68 1.75.4.1 phil #include <net80211/ieee80211_tdma.h>
69 1.75.4.1 phil #endif
70 1.75.4.1 phil #include <net80211/ieee80211_wds.h>
71 1.75.4.1 phil #include <net80211/ieee80211_mesh.h>
72 1.75.4.1 phil #include <net80211/ieee80211_ratectl.h>
73 1.75.4.1 phil #include <net80211/ieee80211_vht.h>
74 1.1 dyoung
75 1.1 dyoung #include <net/bpf.h>
76 1.1 dyoung
77 1.75.4.2 phil #ifdef __NetBSD__
78 1.75.4.2 phil #undef KASSERT
79 1.75.4.2 phil #define KASSERT(__cond, __complaint) FBSDKASSERT(__cond, __complaint)
80 1.75.4.2 phil #endif
81 1.75.4.2 phil
82 1.75.4.1 phil /*
83 1.75.4.1 phil * IEEE80211_NODE_HASHSIZE must be a power of 2.
84 1.75.4.1 phil */
85 1.75.4.1 phil CTASSERT((IEEE80211_NODE_HASHSIZE & (IEEE80211_NODE_HASHSIZE-1)) == 0);
86 1.1 dyoung
87 1.42 dyoung /*
88 1.42 dyoung * Association id's are managed with a bit vector.
89 1.42 dyoung */
90 1.75.4.1 phil #define IEEE80211_AID_SET(_vap, b) \
91 1.75.4.1 phil ((_vap)->iv_aid_bitmap[IEEE80211_AID(b) / 32] |= \
92 1.75.4.1 phil (1 << (IEEE80211_AID(b) % 32)))
93 1.75.4.1 phil #define IEEE80211_AID_CLR(_vap, b) \
94 1.75.4.1 phil ((_vap)->iv_aid_bitmap[IEEE80211_AID(b) / 32] &= \
95 1.75.4.1 phil ~(1 << (IEEE80211_AID(b) % 32)))
96 1.75.4.1 phil #define IEEE80211_AID_ISSET(_vap, b) \
97 1.75.4.1 phil ((_vap)->iv_aid_bitmap[IEEE80211_AID(b) / 32] & (1 << (IEEE80211_AID(b) % 32)))
98 1.75.4.1 phil
99 1.75.4.1 phil static int ieee80211_sta_join1(struct ieee80211_node *);
100 1.42 dyoung
101 1.75.4.1 phil static struct ieee80211_node *node_alloc(struct ieee80211vap *,
102 1.75.4.1 phil const uint8_t [IEEE80211_ADDR_LEN]);
103 1.39 dyoung static void node_cleanup(struct ieee80211_node *);
104 1.39 dyoung static void node_free(struct ieee80211_node *);
105 1.75.4.1 phil static void node_age(struct ieee80211_node *);
106 1.75.4.1 phil static int8_t node_getrssi(const struct ieee80211_node *);
107 1.75.4.1 phil static void node_getsignal(const struct ieee80211_node *, int8_t *, int8_t *);
108 1.75.4.1 phil static void node_getmimoinfo(const struct ieee80211_node *,
109 1.75.4.1 phil struct ieee80211_mimo_info *);
110 1.39 dyoung
111 1.39 dyoung static void _ieee80211_free_node(struct ieee80211_node *);
112 1.39 dyoung
113 1.75.4.1 phil static void node_reclaim(struct ieee80211_node_table *nt,
114 1.75.4.1 phil struct ieee80211_node *ni);
115 1.39 dyoung static void ieee80211_node_table_init(struct ieee80211com *ic,
116 1.45 skrll struct ieee80211_node_table *nt, const char *name,
117 1.75.4.1 phil int inact, int keymaxix);
118 1.75.4.1 phil static void ieee80211_node_table_reset(struct ieee80211_node_table *,
119 1.75.4.1 phil struct ieee80211vap *);
120 1.39 dyoung static void ieee80211_node_table_cleanup(struct ieee80211_node_table *nt);
121 1.75.4.1 phil static void ieee80211_erp_timeout(struct ieee80211com *);
122 1.1 dyoung
123 1.11 dyoung MALLOC_DEFINE(M_80211_NODE, "80211node", "802.11 node state");
124 1.75.4.1 phil MALLOC_DEFINE(M_80211_NODE_IE, "80211nodeie", "802.11 node ie");
125 1.9 dyoung
126 1.1 dyoung void
127 1.23 mycroft ieee80211_node_attach(struct ieee80211com *ic)
128 1.1 dyoung {
129 1.75.4.1 phil /* XXX really want maxlen enforced per-sta */
130 1.75.4.1 phil ieee80211_ageq_init(&ic->ic_stageq, ic->ic_max_keyix * 8,
131 1.75.4.1 phil "802.11 staging q");
132 1.75.4.1 phil ieee80211_node_table_init(ic, &ic->ic_sta, "station",
133 1.75.4.1 phil IEEE80211_INACT_INIT, ic->ic_max_keyix);
134 1.75.4.1 phil callout_init(&ic->ic_inact, 1);
135 1.75.4.1 phil callout_reset(&ic->ic_inact, IEEE80211_INACT_WAIT*hz,
136 1.75.4.1 phil ieee80211_node_timeout, ic);
137 1.1 dyoung
138 1.39 dyoung ic->ic_node_alloc = node_alloc;
139 1.39 dyoung ic->ic_node_free = node_free;
140 1.39 dyoung ic->ic_node_cleanup = node_cleanup;
141 1.75.4.1 phil ic->ic_node_age = node_age;
142 1.75.4.1 phil ic->ic_node_drain = node_age; /* NB: same as age */
143 1.39 dyoung ic->ic_node_getrssi = node_getrssi;
144 1.75.4.1 phil ic->ic_node_getsignal = node_getsignal;
145 1.75.4.1 phil ic->ic_node_getmimoinfo = node_getmimoinfo;
146 1.39 dyoung
147 1.75.4.1 phil /*
148 1.75.4.1 phil * Set flags to be propagated to all vap's;
149 1.75.4.1 phil * these define default behaviour/configuration.
150 1.75.4.1 phil */
151 1.75.4.1 phil ic->ic_flags_ext |= IEEE80211_FEXT_INACT; /* inactivity processing */
152 1.75.4.1 phil }
153 1.75.4.1 phil
154 1.75.4.1 phil void
155 1.75.4.1 phil ieee80211_node_detach(struct ieee80211com *ic)
156 1.75.4.1 phil {
157 1.22 mycroft
158 1.75.4.1 phil callout_drain(&ic->ic_inact);
159 1.75.4.1 phil ieee80211_node_table_cleanup(&ic->ic_sta);
160 1.75.4.1 phil ieee80211_ageq_cleanup(&ic->ic_stageq);
161 1.45 skrll }
162 1.45 skrll
163 1.45 skrll void
164 1.75.4.1 phil ieee80211_node_vattach(struct ieee80211vap *vap)
165 1.45 skrll {
166 1.75.4.1 phil /* NB: driver can override */
167 1.75.4.1 phil vap->iv_max_aid = IEEE80211_AID_DEF;
168 1.45 skrll
169 1.75.4.1 phil /* default station inactivity timer setings */
170 1.75.4.1 phil vap->iv_inact_init = IEEE80211_INACT_INIT;
171 1.75.4.1 phil vap->iv_inact_auth = IEEE80211_INACT_AUTH;
172 1.75.4.1 phil vap->iv_inact_run = IEEE80211_INACT_RUN;
173 1.75.4.1 phil vap->iv_inact_probe = IEEE80211_INACT_PROBE;
174 1.1 dyoung
175 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_INACT,
176 1.75.4.1 phil "%s: init %u auth %u run %u probe %u\n", __func__,
177 1.75.4.1 phil vap->iv_inact_init, vap->iv_inact_auth,
178 1.75.4.1 phil vap->iv_inact_run, vap->iv_inact_probe);
179 1.75.4.1 phil }
180 1.75.4.1 phil
181 1.75.4.1 phil void
182 1.75.4.1 phil ieee80211_node_latevattach(struct ieee80211vap *vap)
183 1.75.4.1 phil {
184 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
185 1.75.4.1 phil /* XXX should we allow max aid to be zero? */
186 1.75.4.1 phil if (vap->iv_max_aid < IEEE80211_AID_MIN) {
187 1.75.4.1 phil vap->iv_max_aid = IEEE80211_AID_MIN;
188 1.75.4.1 phil if_printf(vap->iv_ifp,
189 1.75.4.1 phil "WARNING: max aid too small, changed to %d\n",
190 1.75.4.1 phil vap->iv_max_aid);
191 1.75.4.1 phil }
192 1.75.4.1 phil vap->iv_aid_bitmap = (uint32_t *) IEEE80211_MALLOC(
193 1.75.4.1 phil howmany(vap->iv_max_aid, 32) * sizeof(uint32_t),
194 1.75.4.1 phil M_80211_NODE,
195 1.75.4.1 phil IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
196 1.75.4.1 phil if (vap->iv_aid_bitmap == NULL) {
197 1.75.4.1 phil /* XXX no way to recover */
198 1.75.4.1 phil printf("%s: no memory for AID bitmap, max aid %d!\n",
199 1.75.4.1 phil __func__, vap->iv_max_aid);
200 1.75.4.1 phil vap->iv_max_aid = 0;
201 1.75.4.1 phil }
202 1.39 dyoung }
203 1.33 dyoung
204 1.75.4.1 phil ieee80211_reset_bss(vap);
205 1.39 dyoung
206 1.75.4.1 phil vap->iv_auth = ieee80211_authenticator_get(vap->iv_bss->ni_authmode);
207 1.1 dyoung }
208 1.1 dyoung
209 1.1 dyoung void
210 1.75.4.1 phil ieee80211_node_vdetach(struct ieee80211vap *vap)
211 1.1 dyoung {
212 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
213 1.1 dyoung
214 1.75.4.1 phil ieee80211_node_table_reset(&ic->ic_sta, vap);
215 1.75.4.1 phil if (vap->iv_bss != NULL) {
216 1.75.4.1 phil ieee80211_free_node(vap->iv_bss);
217 1.75.4.1 phil vap->iv_bss = NULL;
218 1.23 mycroft }
219 1.75.4.1 phil if (vap->iv_aid_bitmap != NULL) {
220 1.75.4.1 phil IEEE80211_FREE(vap->iv_aid_bitmap, M_80211_NODE);
221 1.75.4.1 phil vap->iv_aid_bitmap = NULL;
222 1.39 dyoung }
223 1.39 dyoung }
224 1.39 dyoung
225 1.75.4.1 phil /*
226 1.39 dyoung * Port authorize/unauthorize interfaces for use by an authenticator.
227 1.39 dyoung */
228 1.39 dyoung
229 1.39 dyoung void
230 1.45 skrll ieee80211_node_authorize(struct ieee80211_node *ni)
231 1.39 dyoung {
232 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
233 1.45 skrll
234 1.39 dyoung ni->ni_flags |= IEEE80211_NODE_AUTH;
235 1.75.4.1 phil ni->ni_inact_reload = vap->iv_inact_run;
236 1.75.4.1 phil ni->ni_inact = ni->ni_inact_reload;
237 1.75.4.1 phil
238 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
239 1.75.4.1 phil "%s: inact_reload %u", __func__, ni->ni_inact_reload);
240 1.39 dyoung }
241 1.39 dyoung
242 1.39 dyoung void
243 1.45 skrll ieee80211_node_unauthorize(struct ieee80211_node *ni)
244 1.39 dyoung {
245 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
246 1.1 dyoung
247 1.75.4.1 phil ni->ni_flags &= ~IEEE80211_NODE_AUTH;
248 1.75.4.1 phil ni->ni_inact_reload = vap->iv_inact_auth;
249 1.75.4.1 phil if (ni->ni_inact > ni->ni_inact_reload)
250 1.75.4.1 phil ni->ni_inact = ni->ni_inact_reload;
251 1.39 dyoung
252 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
253 1.75.4.1 phil "%s: inact_reload %u inact %u", __func__,
254 1.75.4.1 phil ni->ni_inact_reload, ni->ni_inact);
255 1.39 dyoung }
256 1.39 dyoung
257 1.1 dyoung /*
258 1.75.4.1 phil * Fix tx parameters for a node according to ``association state''.
259 1.1 dyoung */
260 1.75.4.1 phil void
261 1.75.4.1 phil ieee80211_node_setuptxparms(struct ieee80211_node *ni)
262 1.1 dyoung {
263 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
264 1.75.4.1 phil enum ieee80211_phymode mode;
265 1.1 dyoung
266 1.75.4.1 phil if (ni->ni_flags & IEEE80211_NODE_VHT) {
267 1.75.4.1 phil if (IEEE80211_IS_CHAN_5GHZ(ni->ni_chan))
268 1.75.4.1 phil mode = IEEE80211_MODE_VHT_5GHZ;
269 1.75.4.1 phil else
270 1.75.4.1 phil mode = IEEE80211_MODE_VHT_2GHZ;
271 1.75.4.1 phil } else if (ni->ni_flags & IEEE80211_NODE_HT) {
272 1.75.4.1 phil if (IEEE80211_IS_CHAN_5GHZ(ni->ni_chan))
273 1.75.4.1 phil mode = IEEE80211_MODE_11NA;
274 1.75.4.1 phil else
275 1.75.4.1 phil mode = IEEE80211_MODE_11NG;
276 1.75.4.1 phil } else { /* legacy rate handling */
277 1.75.4.1 phil if (IEEE80211_IS_CHAN_ST(ni->ni_chan))
278 1.75.4.1 phil mode = IEEE80211_MODE_STURBO_A;
279 1.75.4.1 phil else if (IEEE80211_IS_CHAN_HALF(ni->ni_chan))
280 1.75.4.1 phil mode = IEEE80211_MODE_HALF;
281 1.75.4.1 phil else if (IEEE80211_IS_CHAN_QUARTER(ni->ni_chan))
282 1.75.4.1 phil mode = IEEE80211_MODE_QUARTER;
283 1.75.4.1 phil /* NB: 108A should be handled as 11a */
284 1.75.4.1 phil else if (IEEE80211_IS_CHAN_A(ni->ni_chan))
285 1.75.4.1 phil mode = IEEE80211_MODE_11A;
286 1.75.4.1 phil else if (IEEE80211_IS_CHAN_108G(ni->ni_chan) ||
287 1.75.4.1 phil (ni->ni_flags & IEEE80211_NODE_ERP))
288 1.75.4.1 phil mode = IEEE80211_MODE_11G;
289 1.75.4.1 phil else
290 1.75.4.1 phil mode = IEEE80211_MODE_11B;
291 1.39 dyoung }
292 1.75.4.1 phil ni->ni_txparms = &vap->iv_txparms[mode];
293 1.1 dyoung }
294 1.1 dyoung
295 1.1 dyoung /*
296 1.75.4.1 phil * Set/change the channel. The rate set is also updated as
297 1.75.4.1 phil * to insure a consistent view by drivers.
298 1.75.4.1 phil * XXX should be private but hostap needs it to deal with CSA
299 1.1 dyoung */
300 1.1 dyoung void
301 1.75.4.1 phil ieee80211_node_set_chan(struct ieee80211_node *ni,
302 1.75.4.1 phil struct ieee80211_channel *chan)
303 1.1 dyoung {
304 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
305 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
306 1.75.4.1 phil enum ieee80211_phymode mode;
307 1.39 dyoung
308 1.75.4.1 phil KASSERT(chan != IEEE80211_CHAN_ANYC, ("no channel"));
309 1.57 tacha
310 1.75.4.1 phil ni->ni_chan = chan;
311 1.75.4.1 phil mode = ieee80211_chan2mode(chan);
312 1.75.4.1 phil if (IEEE80211_IS_CHAN_HT(chan)) {
313 1.57 tacha /*
314 1.75.4.1 phil * We must install the legacy rate est in ni_rates and the
315 1.75.4.1 phil * HT rate set in ni_htrates.
316 1.57 tacha */
317 1.75.4.1 phil ni->ni_htrates = *ieee80211_get_suphtrates(ic, chan);
318 1.75.4.1 phil /*
319 1.75.4.1 phil * Setup bss tx parameters based on operating mode. We
320 1.75.4.1 phil * use legacy rates when operating in a mixed HT+non-HT bss
321 1.75.4.1 phil * and non-ERP rates in 11g for mixed ERP+non-ERP bss.
322 1.75.4.1 phil */
323 1.75.4.1 phil if (mode == IEEE80211_MODE_11NA &&
324 1.75.4.1 phil (vap->iv_flags_ht & IEEE80211_FHT_PUREN) == 0)
325 1.75.4.1 phil mode = IEEE80211_MODE_11A;
326 1.75.4.1 phil else if (mode == IEEE80211_MODE_11NG &&
327 1.75.4.1 phil (vap->iv_flags_ht & IEEE80211_FHT_PUREN) == 0)
328 1.75.4.1 phil mode = IEEE80211_MODE_11G;
329 1.75.4.1 phil if (mode == IEEE80211_MODE_11G &&
330 1.75.4.1 phil (vap->iv_flags & IEEE80211_F_PUREG) == 0)
331 1.75.4.1 phil mode = IEEE80211_MODE_11B;
332 1.75.4.1 phil }
333 1.75.4.1 phil ni->ni_txparms = &vap->iv_txparms[mode];
334 1.75.4.1 phil ni->ni_rates = *ieee80211_get_suprates(ic, chan);
335 1.57 tacha }
336 1.57 tacha
337 1.39 dyoung static __inline void
338 1.39 dyoung copy_bss(struct ieee80211_node *nbss, const struct ieee80211_node *obss)
339 1.39 dyoung {
340 1.39 dyoung /* propagate useful state */
341 1.39 dyoung nbss->ni_authmode = obss->ni_authmode;
342 1.39 dyoung nbss->ni_txpower = obss->ni_txpower;
343 1.39 dyoung nbss->ni_vlan = obss->ni_vlan;
344 1.39 dyoung /* XXX statistics? */
345 1.75.4.1 phil /* XXX legacy WDS bssid? */
346 1.1 dyoung }
347 1.1 dyoung
348 1.1 dyoung void
349 1.75.4.1 phil ieee80211_create_ibss(struct ieee80211vap* vap, struct ieee80211_channel *chan)
350 1.1 dyoung {
351 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
352 1.1 dyoung struct ieee80211_node *ni;
353 1.1 dyoung
354 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
355 1.75.4.1 phil "%s: creating %s on channel %u%c flags 0x%08x\n", __func__,
356 1.75.4.1 phil ieee80211_opmode_name[vap->iv_opmode],
357 1.75.4.1 phil ieee80211_chan2ieee(ic, chan),
358 1.75.4.1 phil ieee80211_channel_type_char(chan),
359 1.75.4.1 phil chan->ic_flags);
360 1.39 dyoung
361 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr);
362 1.39 dyoung if (ni == NULL) {
363 1.39 dyoung /* XXX recovery? */
364 1.39 dyoung return;
365 1.16 dyoung }
366 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_myaddr);
367 1.75.4.1 phil ni->ni_esslen = vap->iv_des_ssid[0].len;
368 1.75.4.1 phil memcpy(ni->ni_essid, vap->iv_des_ssid[0].ssid, ni->ni_esslen);
369 1.75.4.1 phil if (vap->iv_bss != NULL)
370 1.75.4.1 phil copy_bss(ni, vap->iv_bss);
371 1.45 skrll ni->ni_intval = ic->ic_bintval;
372 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_PRIVACY)
373 1.1 dyoung ni->ni_capinfo |= IEEE80211_CAPINFO_PRIVACY;
374 1.1 dyoung if (ic->ic_phytype == IEEE80211_T_FH) {
375 1.1 dyoung ni->ni_fhdwell = 200; /* XXX */
376 1.1 dyoung ni->ni_fhindex = 1;
377 1.1 dyoung }
378 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS) {
379 1.39 dyoung ni->ni_capinfo |= IEEE80211_CAPINFO_IBSS; /* XXX */
380 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_DESBSSID)
381 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_des_bssid);
382 1.75.4.1 phil else {
383 1.75.4.1 phil get_random_bytes(ni->ni_bssid, IEEE80211_ADDR_LEN);
384 1.75.4.1 phil /* clear group bit, add local bit */
385 1.75.4.1 phil ni->ni_bssid[0] = (ni->ni_bssid[0] &~ 0x01) | 0x02;
386 1.75.4.1 phil }
387 1.75.4.1 phil } else if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
388 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_DESBSSID)
389 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_des_bssid);
390 1.39 dyoung else
391 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_TDMA
392 1.75.4.1 phil if ((vap->iv_caps & IEEE80211_C_TDMA) == 0)
393 1.75.4.1 phil #endif
394 1.75.4.1 phil memset(ni->ni_bssid, 0, IEEE80211_ADDR_LEN);
395 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
396 1.75.4.1 phil } else if (vap->iv_opmode == IEEE80211_M_MBSS) {
397 1.75.4.1 phil ni->ni_meshidlen = vap->iv_mesh->ms_idlen;
398 1.75.4.1 phil memcpy(ni->ni_meshid, vap->iv_mesh->ms_id, ni->ni_meshidlen);
399 1.75.4.1 phil #endif
400 1.39 dyoung }
401 1.75.4.1 phil /*
402 1.39 dyoung * Fix the channel and related attributes.
403 1.39 dyoung */
404 1.75.4.1 phil /* clear DFS CAC state on previous channel */
405 1.75.4.1 phil if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
406 1.75.4.1 phil ic->ic_bsschan->ic_freq != chan->ic_freq &&
407 1.75.4.1 phil IEEE80211_IS_CHAN_CACDONE(ic->ic_bsschan))
408 1.75.4.1 phil ieee80211_dfs_cac_clear(ic, ic->ic_bsschan);
409 1.75.4.1 phil ic->ic_bsschan = chan;
410 1.75.4.1 phil ieee80211_node_set_chan(ni, chan);
411 1.75.4.1 phil ic->ic_curmode = ieee80211_chan2mode(chan);
412 1.39 dyoung /*
413 1.75.4.1 phil * Do mode-specific setup.
414 1.39 dyoung */
415 1.75.4.1 phil if (IEEE80211_IS_CHAN_FULL(chan)) {
416 1.75.4.1 phil if (IEEE80211_IS_CHAN_ANYG(chan)) {
417 1.75.4.1 phil /*
418 1.75.4.1 phil * Use a mixed 11b/11g basic rate set.
419 1.75.4.1 phil */
420 1.75.4.1 phil ieee80211_setbasicrates(&ni->ni_rates,
421 1.75.4.1 phil IEEE80211_MODE_11G);
422 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_PUREG) {
423 1.75.4.1 phil /*
424 1.75.4.1 phil * Also mark OFDM rates basic so 11b
425 1.75.4.1 phil * stations do not join (WiFi compliance).
426 1.75.4.1 phil */
427 1.75.4.1 phil ieee80211_addbasicrates(&ni->ni_rates,
428 1.75.4.1 phil IEEE80211_MODE_11A);
429 1.75.4.1 phil }
430 1.75.4.1 phil } else if (IEEE80211_IS_CHAN_B(chan)) {
431 1.75.4.1 phil /*
432 1.75.4.1 phil * Force pure 11b rate set.
433 1.75.4.1 phil */
434 1.75.4.1 phil ieee80211_setbasicrates(&ni->ni_rates,
435 1.75.4.1 phil IEEE80211_MODE_11B);
436 1.75.4.1 phil }
437 1.75.4.1 phil }
438 1.75.4.1 phil
439 1.75.4.1 phil /* XXX TODO: other bits and pieces - eg fast-frames? */
440 1.75.4.1 phil
441 1.75.4.1 phil /* If we're an 11n channel then initialise the 11n bits */
442 1.75.4.1 phil if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) {
443 1.75.4.1 phil /* XXX what else? */
444 1.75.4.1 phil ieee80211_ht_node_init(ni);
445 1.75.4.1 phil ieee80211_vht_node_init(ni);
446 1.75.4.1 phil } else if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {
447 1.75.4.1 phil /* XXX what else? */
448 1.75.4.1 phil ieee80211_ht_node_init(ni);
449 1.39 dyoung }
450 1.39 dyoung
451 1.75.4.1 phil (void) ieee80211_sta_join1(ieee80211_ref_node(ni));
452 1.1 dyoung }
453 1.1 dyoung
454 1.75.4.1 phil /*
455 1.75.4.1 phil * Reset bss state on transition to the INIT state.
456 1.75.4.1 phil * Clear any stations from the table (they have been
457 1.75.4.1 phil * deauth'd) and reset the bss node (clears key, rate
458 1.75.4.1 phil * etc. state).
459 1.75.4.1 phil */
460 1.39 dyoung void
461 1.75.4.1 phil ieee80211_reset_bss(struct ieee80211vap *vap)
462 1.39 dyoung {
463 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
464 1.39 dyoung struct ieee80211_node *ni, *obss;
465 1.39 dyoung
466 1.75.4.1 phil ieee80211_node_table_reset(&ic->ic_sta, vap);
467 1.75.4.1 phil /* XXX multi-bss: wrong */
468 1.75.4.1 phil ieee80211_reset_erp(ic);
469 1.39 dyoung
470 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr);
471 1.75.4.1 phil KASSERT(ni != NULL, ("unable to setup initial BSS node"));
472 1.75.4.1 phil obss = vap->iv_bss;
473 1.75.4.1 phil vap->iv_bss = ieee80211_ref_node(ni);
474 1.39 dyoung if (obss != NULL) {
475 1.39 dyoung copy_bss(ni, obss);
476 1.45 skrll ni->ni_intval = ic->ic_bintval;
477 1.39 dyoung ieee80211_free_node(obss);
478 1.75.4.1 phil } else
479 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_myaddr);
480 1.39 dyoung }
481 1.39 dyoung
482 1.75.4.1 phil static int
483 1.75.4.1 phil match_ssid(const struct ieee80211_node *ni,
484 1.75.4.1 phil int nssid, const struct ieee80211_scan_ssid ssids[])
485 1.75.4.1 phil {
486 1.75.4.1 phil int i;
487 1.75.4.1 phil
488 1.75.4.1 phil for (i = 0; i < nssid; i++) {
489 1.75.4.1 phil if (ni->ni_esslen == ssids[i].len &&
490 1.75.4.1 phil memcmp(ni->ni_essid, ssids[i].ssid, ni->ni_esslen) == 0)
491 1.75.4.1 phil return 1;
492 1.75.4.1 phil }
493 1.75.4.1 phil return 0;
494 1.75.4.1 phil }
495 1.45 skrll
496 1.75.4.1 phil /*
497 1.75.4.1 phil * Test a node for suitability/compatibility.
498 1.75.4.1 phil */
499 1.39 dyoung static int
500 1.75.4.1 phil check_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
501 1.75.4.1 phil {
502 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
503 1.75.4.1 phil uint8_t rate;
504 1.75.4.1 phil
505 1.75.4.1 phil if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
506 1.75.4.1 phil return 0;
507 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS) {
508 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
509 1.75.4.1 phil return 0;
510 1.75.4.1 phil } else {
511 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
512 1.75.4.1 phil return 0;
513 1.75.4.1 phil }
514 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_PRIVACY) {
515 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
516 1.75.4.1 phil return 0;
517 1.75.4.1 phil } else {
518 1.75.4.1 phil /* XXX does this mean privacy is supported or required? */
519 1.75.4.1 phil if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
520 1.75.4.1 phil return 0;
521 1.75.4.1 phil }
522 1.75.4.1 phil rate = ieee80211_fix_rate(ni, &ni->ni_rates,
523 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
524 1.75.4.1 phil if (rate & IEEE80211_RATE_BASIC)
525 1.75.4.1 phil return 0;
526 1.75.4.1 phil if (vap->iv_des_nssid != 0 &&
527 1.75.4.1 phil !match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
528 1.75.4.1 phil return 0;
529 1.75.4.1 phil if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
530 1.75.4.1 phil !IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
531 1.75.4.1 phil return 0;
532 1.75.4.1 phil return 1;
533 1.75.4.1 phil }
534 1.75.4.1 phil
535 1.75.4.1 phil #ifdef IEEE80211_DEBUG
536 1.75.4.1 phil /*
537 1.75.4.1 phil * Display node suitability/compatibility.
538 1.75.4.1 phil */
539 1.75.4.1 phil static void
540 1.75.4.1 phil check_bss_debug(struct ieee80211vap *vap, struct ieee80211_node *ni)
541 1.5 dyoung {
542 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
543 1.75.4.1 phil uint8_t rate;
544 1.75.4.1 phil int fail;
545 1.5 dyoung
546 1.5 dyoung fail = 0;
547 1.5 dyoung if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
548 1.5 dyoung fail |= 0x01;
549 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS) {
550 1.5 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
551 1.5 dyoung fail |= 0x02;
552 1.5 dyoung } else {
553 1.5 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
554 1.5 dyoung fail |= 0x02;
555 1.5 dyoung }
556 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_PRIVACY) {
557 1.5 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
558 1.5 dyoung fail |= 0x04;
559 1.5 dyoung } else {
560 1.11 dyoung /* XXX does this mean privacy is supported or required? */
561 1.5 dyoung if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
562 1.5 dyoung fail |= 0x04;
563 1.5 dyoung }
564 1.75.4.1 phil rate = ieee80211_fix_rate(ni, &ni->ni_rates,
565 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
566 1.5 dyoung if (rate & IEEE80211_RATE_BASIC)
567 1.5 dyoung fail |= 0x08;
568 1.75.4.1 phil if (vap->iv_des_nssid != 0 &&
569 1.75.4.1 phil !match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
570 1.5 dyoung fail |= 0x10;
571 1.75.4.1 phil if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
572 1.75.4.1 phil !IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
573 1.5 dyoung fail |= 0x20;
574 1.75 maxv
575 1.75.4.1 phil printf(" %c %s", fail ? '-' : '+', ether_sprintf(ni->ni_macaddr));
576 1.75.4.1 phil printf(" %s%c", ether_sprintf(ni->ni_bssid), fail & 0x20 ? '!' : ' ');
577 1.75.4.1 phil printf(" %3d%c",
578 1.75.4.1 phil ieee80211_chan2ieee(ic, ni->ni_chan), fail & 0x01 ? '!' : ' ');
579 1.75.4.1 phil printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2,
580 1.75.4.1 phil fail & 0x08 ? '!' : ' ');
581 1.75.4.1 phil printf(" %4s%c",
582 1.75.4.1 phil (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
583 1.75.4.1 phil (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
584 1.75.4.1 phil "????",
585 1.75.4.1 phil fail & 0x02 ? '!' : ' ');
586 1.75.4.1 phil printf(" %3s%c ",
587 1.75.4.1 phil (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? "wep" : "no",
588 1.75.4.1 phil fail & 0x04 ? '!' : ' ');
589 1.75.4.1 phil ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
590 1.75.4.1 phil printf("%s\n", fail & 0x10 ? "!" : "");
591 1.39 dyoung }
592 1.75.4.1 phil #endif /* IEEE80211_DEBUG */
593 1.75.4.1 phil
594 1.39 dyoung
595 1.75.4.1 phil int
596 1.75.4.1 phil ieee80211_ibss_merge_check(struct ieee80211_node *ni)
597 1.39 dyoung {
598 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
599 1.39 dyoung
600 1.75.4.1 phil if (ni == vap->iv_bss ||
601 1.75.4.1 phil IEEE80211_ADDR_EQ(ni->ni_bssid, vap->iv_bss->ni_bssid)) {
602 1.75.4.1 phil /* unchanged, nothing to do */
603 1.75.4.1 phil return 0;
604 1.75.4.1 phil }
605 1.39 dyoung
606 1.75.4.1 phil if (!check_bss(vap, ni)) {
607 1.75.4.1 phil /* capabilities mismatch */
608 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
609 1.75.4.1 phil "%s: merge failed, capabilities mismatch\n", __func__);
610 1.75.4.1 phil #ifdef IEEE80211_DEBUG
611 1.75.4.1 phil if (ieee80211_msg_assoc(vap))
612 1.75.4.1 phil check_bss_debug(vap, ni);
613 1.75.4.1 phil #endif
614 1.75.4.1 phil vap->iv_stats.is_ibss_capmismatch++;
615 1.75.4.1 phil return 0;
616 1.75.4.1 phil }
617 1.39 dyoung
618 1.75.4.1 phil return 1;
619 1.39 dyoung }
620 1.39 dyoung
621 1.1 dyoung /*
622 1.75.4.1 phil * Check if the given node should populate the node table.
623 1.75.4.1 phil *
624 1.75.4.1 phil * We need to be in "see all beacons for all ssids" mode in order
625 1.75.4.1 phil * to do IBSS merges, however this means we will populate nodes for
626 1.75.4.1 phil * /all/ IBSS SSIDs, versus just the one we care about.
627 1.75.4.1 phil *
628 1.75.4.1 phil * So this check ensures the node can actually belong to our IBSS
629 1.75.4.1 phil * configuration. For now it simply checks the SSID.
630 1.1 dyoung */
631 1.75.4.1 phil int
632 1.75.4.1 phil ieee80211_ibss_node_check_new(struct ieee80211_node *ni,
633 1.75.4.1 phil const struct ieee80211_scanparams *scan)
634 1.1 dyoung {
635 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
636 1.75.4.1 phil int i;
637 1.39 dyoung
638 1.39 dyoung /*
639 1.75.4.1 phil * If we have no SSID and no scan SSID, return OK.
640 1.39 dyoung */
641 1.75.4.1 phil if (vap->iv_des_nssid == 0 && scan->ssid == NULL)
642 1.75.4.1 phil goto ok;
643 1.75 maxv
644 1.39 dyoung /*
645 1.75.4.1 phil * If we have one of (SSID, scan SSID) then return error.
646 1.39 dyoung */
647 1.75.4.1 phil if (!! (vap->iv_des_nssid == 0) != !! (scan->ssid == NULL))
648 1.75.4.1 phil goto mismatch;
649 1.75 maxv
650 1.75.4.1 phil /*
651 1.75.4.1 phil * Double-check - we need scan SSID.
652 1.75.4.1 phil */
653 1.75.4.1 phil if (scan->ssid == NULL)
654 1.75.4.1 phil goto mismatch;
655 1.75 maxv
656 1.75.4.1 phil /*
657 1.75.4.1 phil * Check if the scan SSID matches the SSID list for the VAP.
658 1.75.4.1 phil */
659 1.75.4.1 phil for (i = 0; i < vap->iv_des_nssid; i++) {
660 1.75 maxv
661 1.75.4.1 phil /* Sanity length check */
662 1.75.4.1 phil if (vap->iv_des_ssid[i].len != scan->ssid[1])
663 1.75.4.1 phil continue;
664 1.75 maxv
665 1.75.4.1 phil /* Note: SSID in the scan entry is the IE format */
666 1.75.4.1 phil if (memcmp(vap->iv_des_ssid[i].ssid, scan->ssid + 2,
667 1.75.4.1 phil vap->iv_des_ssid[i].len) == 0)
668 1.75.4.1 phil goto ok;
669 1.1 dyoung }
670 1.75 maxv
671 1.75.4.1 phil mismatch:
672 1.75.4.1 phil return (0);
673 1.75.4.1 phil ok:
674 1.75.4.1 phil return (1);
675 1.39 dyoung }
676 1.65 christos
677 1.39 dyoung /*
678 1.39 dyoung * Handle 802.11 ad hoc network merge. The
679 1.39 dyoung * convention, set by the Wireless Ethernet Compatibility Alliance
680 1.39 dyoung * (WECA), is that an 802.11 station will change its BSSID to match
681 1.39 dyoung * the "oldest" 802.11 ad hoc network, on the same channel, that
682 1.39 dyoung * has the station's desired SSID. The "oldest" 802.11 network
683 1.39 dyoung * sends beacons with the greatest TSF timestamp.
684 1.39 dyoung *
685 1.39 dyoung * The caller is assumed to validate TSF's before attempting a merge.
686 1.39 dyoung *
687 1.39 dyoung * Return !0 if the BSSID changed, 0 otherwise.
688 1.39 dyoung */
689 1.39 dyoung int
690 1.45 skrll ieee80211_ibss_merge(struct ieee80211_node *ni)
691 1.39 dyoung {
692 1.75.4.1 phil #ifdef IEEE80211_DEBUG
693 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
694 1.45 skrll struct ieee80211com *ic = ni->ni_ic;
695 1.75.4.1 phil #endif
696 1.39 dyoung
697 1.75.4.1 phil if (! ieee80211_ibss_merge_check(ni))
698 1.39 dyoung return 0;
699 1.75.4.1 phil
700 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
701 1.39 dyoung "%s: new bssid %s: %s preamble, %s slot time%s\n", __func__,
702 1.39 dyoung ether_sprintf(ni->ni_bssid),
703 1.39 dyoung ic->ic_flags&IEEE80211_F_SHPREAMBLE ? "short" : "long",
704 1.39 dyoung ic->ic_flags&IEEE80211_F_SHSLOT ? "short" : "long",
705 1.39 dyoung ic->ic_flags&IEEE80211_F_USEPROT ? ", protection" : ""
706 1.39 dyoung );
707 1.75.4.1 phil return ieee80211_sta_join1(ieee80211_ref_node(ni));
708 1.39 dyoung }
709 1.39 dyoung
710 1.39 dyoung /*
711 1.75.4.1 phil * Calculate HT channel promotion flags for all vaps.
712 1.75.4.1 phil * This assumes ni_chan have been setup for each vap.
713 1.39 dyoung */
714 1.75.4.1 phil static int
715 1.75.4.1 phil gethtadjustflags(struct ieee80211com *ic)
716 1.39 dyoung {
717 1.75.4.1 phil struct ieee80211vap *vap;
718 1.75.4.1 phil int flags;
719 1.39 dyoung
720 1.75.4.1 phil flags = 0;
721 1.75.4.1 phil /* XXX locking */
722 1.75.4.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
723 1.75.4.1 phil if (vap->iv_state < IEEE80211_S_RUN)
724 1.75.4.1 phil continue;
725 1.75.4.1 phil switch (vap->iv_opmode) {
726 1.75.4.1 phil case IEEE80211_M_WDS:
727 1.75.4.1 phil case IEEE80211_M_STA:
728 1.75.4.1 phil case IEEE80211_M_AHDEMO:
729 1.75.4.1 phil case IEEE80211_M_HOSTAP:
730 1.75.4.1 phil case IEEE80211_M_IBSS:
731 1.75.4.1 phil case IEEE80211_M_MBSS:
732 1.75.4.1 phil flags |= ieee80211_htchanflags(vap->iv_bss->ni_chan);
733 1.75.4.1 phil break;
734 1.75.4.1 phil default:
735 1.75.4.1 phil break;
736 1.75.4.1 phil }
737 1.75.4.1 phil }
738 1.75.4.1 phil return flags;
739 1.75.4.1 phil }
740 1.75 maxv
741 1.75.4.1 phil /*
742 1.75.4.1 phil * Calculate VHT channel promotion flags for all vaps.
743 1.75.4.1 phil * This assumes ni_chan have been setup for each vap.
744 1.75.4.1 phil */
745 1.75.4.1 phil static int
746 1.75.4.1 phil getvhtadjustflags(struct ieee80211com *ic)
747 1.75.4.1 phil {
748 1.75.4.1 phil struct ieee80211vap *vap;
749 1.75.4.1 phil int flags;
750 1.75.4.1 phil
751 1.75.4.1 phil flags = 0;
752 1.75.4.1 phil /* XXX locking */
753 1.75.4.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
754 1.75.4.1 phil if (vap->iv_state < IEEE80211_S_RUN)
755 1.75.4.1 phil continue;
756 1.75.4.1 phil switch (vap->iv_opmode) {
757 1.75.4.1 phil case IEEE80211_M_WDS:
758 1.75.4.1 phil case IEEE80211_M_STA:
759 1.75.4.1 phil case IEEE80211_M_AHDEMO:
760 1.75.4.1 phil case IEEE80211_M_HOSTAP:
761 1.75.4.1 phil case IEEE80211_M_IBSS:
762 1.75.4.1 phil case IEEE80211_M_MBSS:
763 1.75.4.1 phil flags |= ieee80211_vhtchanflags(vap->iv_bss->ni_chan);
764 1.75.4.1 phil break;
765 1.75.4.1 phil default:
766 1.75.4.1 phil break;
767 1.75.4.1 phil }
768 1.75.4.1 phil }
769 1.75.4.1 phil return flags;
770 1.75.4.1 phil }
771 1.75.4.1 phil
772 1.75.4.1 phil /*
773 1.75.4.1 phil * Check if the current channel needs to change based on whether
774 1.75.4.1 phil * any vap's are using HT20/HT40. This is used to sync the state
775 1.75.4.1 phil * of ic_curchan after a channel width change on a running vap.
776 1.75.4.1 phil *
777 1.75.4.1 phil * Same applies for VHT.
778 1.75.4.1 phil */
779 1.75.4.1 phil void
780 1.75.4.1 phil ieee80211_sync_curchan(struct ieee80211com *ic)
781 1.75.4.1 phil {
782 1.75.4.1 phil struct ieee80211_channel *c;
783 1.75.4.1 phil
784 1.75.4.1 phil c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, gethtadjustflags(ic));
785 1.75.4.1 phil c = ieee80211_vht_adjust_channel(ic, c, getvhtadjustflags(ic));
786 1.75 maxv
787 1.75.4.1 phil if (c != ic->ic_curchan) {
788 1.75.4.1 phil ic->ic_curchan = c;
789 1.75.4.1 phil ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan);
790 1.75.4.1 phil ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
791 1.75.4.1 phil IEEE80211_UNLOCK(ic);
792 1.75.4.1 phil ic->ic_set_channel(ic);
793 1.75.4.1 phil ieee80211_radiotap_chan_change(ic);
794 1.75.4.1 phil IEEE80211_LOCK(ic);
795 1.75.4.1 phil }
796 1.75.4.1 phil }
797 1.75.4.1 phil
798 1.75.4.1 phil /*
799 1.75.4.1 phil * Setup the current channel. The request channel may be
800 1.75.4.1 phil * promoted if other vap's are operating with HT20/HT40.
801 1.75.4.1 phil */
802 1.75.4.1 phil void
803 1.75.4.1 phil ieee80211_setupcurchan(struct ieee80211com *ic, struct ieee80211_channel *c)
804 1.75.4.1 phil {
805 1.75.4.1 phil if (ic->ic_htcaps & IEEE80211_HTC_HT) {
806 1.75.4.1 phil int flags = gethtadjustflags(ic);
807 1.39 dyoung /*
808 1.75.4.1 phil * Check for channel promotion required to support the
809 1.75.4.1 phil * set of running vap's. This assumes we are called
810 1.75.4.1 phil * after ni_chan is setup for each vap.
811 1.39 dyoung */
812 1.75.4.1 phil /* XXX VHT? */
813 1.75.4.1 phil /* NB: this assumes IEEE80211_FHT_USEHT40 > IEEE80211_FHT_HT */
814 1.75.4.1 phil if (flags > ieee80211_htchanflags(c))
815 1.75.4.1 phil c = ieee80211_ht_adjust_channel(ic, c, flags);
816 1.39 dyoung }
817 1.39 dyoung
818 1.39 dyoung /*
819 1.75.4.1 phil * VHT promotion - this will at least promote to VHT20/40
820 1.75.4.1 phil * based on what HT has done; it may further promote the
821 1.75.4.1 phil * channel to VHT80 or above.
822 1.75.4.1 phil */
823 1.75.4.1 phil if (ic->ic_vhtcaps != 0) {
824 1.75.4.1 phil int flags = getvhtadjustflags(ic);
825 1.75.4.1 phil if (flags > ieee80211_vhtchanflags(c))
826 1.75.4.1 phil c = ieee80211_vht_adjust_channel(ic, c, flags);
827 1.75.4.1 phil }
828 1.75.4.1 phil
829 1.75.4.1 phil ic->ic_bsschan = ic->ic_curchan = c;
830 1.75.4.1 phil ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan);
831 1.75.4.1 phil ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
832 1.75.4.1 phil }
833 1.75.4.1 phil
834 1.75.4.1 phil /*
835 1.75.4.1 phil * Change the current channel. The channel change is guaranteed to have
836 1.75.4.1 phil * happened before the next state change.
837 1.75.4.1 phil */
838 1.75.4.1 phil void
839 1.75.4.1 phil ieee80211_setcurchan(struct ieee80211com *ic, struct ieee80211_channel *c)
840 1.75.4.1 phil {
841 1.75.4.1 phil ieee80211_setupcurchan(ic, c);
842 1.75.4.1 phil ieee80211_runtask(ic, &ic->ic_chan_task);
843 1.75.4.1 phil }
844 1.75.4.1 phil
845 1.75.4.1 phil void
846 1.75.4.1 phil ieee80211_update_chw(struct ieee80211com *ic)
847 1.75.4.1 phil {
848 1.75.4.1 phil
849 1.75.4.1 phil ieee80211_setupcurchan(ic, ic->ic_curchan);
850 1.75.4.1 phil ieee80211_runtask(ic, &ic->ic_chw_task);
851 1.75.4.1 phil }
852 1.75.4.1 phil
853 1.75.4.1 phil /*
854 1.75.4.1 phil * Join the specified IBSS/BSS network. The node is assumed to
855 1.75.4.1 phil * be passed in with a held reference.
856 1.75.4.1 phil */
857 1.75.4.1 phil static int
858 1.75.4.1 phil ieee80211_sta_join1(struct ieee80211_node *selbs)
859 1.75.4.1 phil {
860 1.75.4.1 phil struct ieee80211vap *vap = selbs->ni_vap;
861 1.75.4.1 phil struct ieee80211com *ic = selbs->ni_ic;
862 1.75.4.1 phil struct ieee80211_node *obss;
863 1.75.4.1 phil int canreassoc;
864 1.75.4.1 phil
865 1.75.4.1 phil /*
866 1.39 dyoung * Committed to selbs, setup state.
867 1.39 dyoung */
868 1.75.4.1 phil obss = vap->iv_bss;
869 1.75.4.1 phil /*
870 1.75.4.1 phil * Check if old+new node have the same address in which
871 1.75.4.1 phil * case we can reassociate when operating in sta mode.
872 1.75.4.1 phil */
873 1.75.4.1 phil canreassoc = (obss != NULL &&
874 1.75.4.1 phil vap->iv_state == IEEE80211_S_RUN &&
875 1.75.4.1 phil IEEE80211_ADDR_EQ(obss->ni_macaddr, selbs->ni_macaddr));
876 1.75.4.1 phil vap->iv_bss = selbs; /* NB: caller assumed to bump refcnt */
877 1.52 dyoung if (obss != NULL) {
878 1.75.4.1 phil struct ieee80211_node_table *nt = obss->ni_table;
879 1.75.4.1 phil
880 1.52 dyoung copy_bss(selbs, obss);
881 1.75.4.1 phil ieee80211_node_decref(obss); /* iv_bss reference */
882 1.75.4.1 phil
883 1.75.4.1 phil IEEE80211_NODE_LOCK(nt);
884 1.75.4.1 phil node_reclaim(nt, obss); /* station table reference */
885 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
886 1.75.4.1 phil
887 1.75.4.1 phil obss = NULL; /* NB: guard against later use */
888 1.52 dyoung }
889 1.75 maxv
890 1.39 dyoung /*
891 1.75.4.1 phil * Delete unusable rates; we've already checked
892 1.75.4.1 phil * that the negotiated rate set is acceptable.
893 1.75.4.1 phil */
894 1.75.4.1 phil ieee80211_fix_rate(vap->iv_bss, &vap->iv_bss->ni_rates,
895 1.75.4.1 phil IEEE80211_F_DODEL | IEEE80211_F_JOIN);
896 1.75.4.1 phil
897 1.75.4.1 phil ieee80211_setcurchan(ic, selbs->ni_chan);
898 1.75.4.1 phil /*
899 1.39 dyoung * Set the erp state (mostly the slot time) to deal with
900 1.39 dyoung * the auto-select case; this should be redundant if the
901 1.39 dyoung * mode is locked.
902 1.75.4.1 phil */
903 1.39 dyoung ieee80211_reset_erp(ic);
904 1.75.4.1 phil ieee80211_wme_initparams(vap);
905 1.39 dyoung
906 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_STA) {
907 1.75.4.1 phil if (canreassoc) {
908 1.75.4.1 phil /* Reassociate */
909 1.75.4.1 phil ieee80211_new_state(vap, IEEE80211_S_ASSOC, 1);
910 1.75.4.1 phil } else {
911 1.75.4.1 phil /*
912 1.75.4.1 phil * Act as if we received a DEAUTH frame in case we
913 1.75.4.1 phil * are invoked from the RUN state. This will cause
914 1.75.4.1 phil * us to try to re-authenticate if we are operating
915 1.75.4.1 phil * as a station.
916 1.75.4.1 phil */
917 1.75.4.1 phil ieee80211_new_state(vap, IEEE80211_S_AUTH,
918 1.75.4.1 phil IEEE80211_FC0_SUBTYPE_DEAUTH);
919 1.75.4.1 phil }
920 1.75.4.1 phil } else
921 1.75.4.1 phil ieee80211_new_state(vap, IEEE80211_S_RUN, -1);
922 1.39 dyoung return 1;
923 1.39 dyoung }
924 1.39 dyoung
925 1.75.4.1 phil int
926 1.75.4.1 phil ieee80211_sta_join(struct ieee80211vap *vap, struct ieee80211_channel *chan,
927 1.75.4.1 phil const struct ieee80211_scan_entry *se)
928 1.75.4.1 phil {
929 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
930 1.75.4.1 phil struct ieee80211_node *ni;
931 1.75.4.1 phil int do_ht = 0;
932 1.75.4.1 phil
933 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, se->se_macaddr);
934 1.75.4.1 phil if (ni == NULL) {
935 1.75.4.1 phil /* XXX msg */
936 1.75.4.1 phil return 0;
937 1.75.4.1 phil }
938 1.75.4.1 phil
939 1.75.4.1 phil /*
940 1.75.4.1 phil * Expand scan state into node's format.
941 1.75.4.1 phil * XXX may not need all this stuff
942 1.75.4.1 phil */
943 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, se->se_bssid);
944 1.75.4.1 phil ni->ni_esslen = se->se_ssid[1];
945 1.75.4.1 phil memcpy(ni->ni_essid, se->se_ssid+2, ni->ni_esslen);
946 1.75.4.1 phil ni->ni_tstamp.tsf = se->se_tstamp.tsf;
947 1.75.4.1 phil ni->ni_intval = se->se_intval;
948 1.75.4.1 phil ni->ni_capinfo = se->se_capinfo;
949 1.75.4.1 phil ni->ni_chan = chan;
950 1.75.4.1 phil ni->ni_timoff = se->se_timoff;
951 1.75.4.1 phil ni->ni_fhdwell = se->se_fhdwell;
952 1.75.4.1 phil ni->ni_fhindex = se->se_fhindex;
953 1.75.4.1 phil ni->ni_erp = se->se_erp;
954 1.75.4.1 phil IEEE80211_RSSI_LPF(ni->ni_avgrssi, se->se_rssi);
955 1.75.4.1 phil ni->ni_noise = se->se_noise;
956 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_STA) {
957 1.75.4.1 phil /* NB: only infrastructure mode requires an associd */
958 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ASSOCID;
959 1.75.4.1 phil }
960 1.75.4.1 phil
961 1.75.4.1 phil if (ieee80211_ies_init(&ni->ni_ies, se->se_ies.data, se->se_ies.len)) {
962 1.75.4.1 phil ieee80211_ies_expand(&ni->ni_ies);
963 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
964 1.75.4.1 phil if (ni->ni_ies.ath_ie != NULL)
965 1.75.4.1 phil ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
966 1.75.4.1 phil #endif
967 1.75.4.1 phil if (ni->ni_ies.htcap_ie != NULL)
968 1.75.4.1 phil ieee80211_parse_htcap(ni, ni->ni_ies.htcap_ie);
969 1.75.4.1 phil if (ni->ni_ies.htinfo_ie != NULL)
970 1.75.4.1 phil ieee80211_parse_htinfo(ni, ni->ni_ies.htinfo_ie);
971 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
972 1.75.4.1 phil if (ni->ni_ies.meshid_ie != NULL)
973 1.75.4.1 phil ieee80211_parse_meshid(ni, ni->ni_ies.meshid_ie);
974 1.75.4.1 phil #endif
975 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_TDMA
976 1.75.4.1 phil if (ni->ni_ies.tdma_ie != NULL)
977 1.75.4.1 phil ieee80211_parse_tdma(ni, ni->ni_ies.tdma_ie);
978 1.75.4.1 phil #endif
979 1.75.4.1 phil if (ni->ni_ies.vhtcap_ie != NULL)
980 1.75.4.1 phil ieee80211_parse_vhtcap(ni, ni->ni_ies.vhtcap_ie);
981 1.75.4.1 phil if (ni->ni_ies.vhtopmode_ie != NULL)
982 1.75.4.1 phil ieee80211_parse_vhtopmode(ni, ni->ni_ies.vhtopmode_ie);
983 1.75.4.1 phil
984 1.75.4.1 phil /* XXX parse BSSLOAD IE */
985 1.75.4.1 phil /* XXX parse TXPWRENV IE */
986 1.75.4.1 phil /* XXX parse APCHANREP IE */
987 1.75.4.1 phil }
988 1.75.4.1 phil
989 1.75.4.1 phil vap->iv_dtim_period = se->se_dtimperiod;
990 1.75.4.1 phil vap->iv_dtim_count = 0;
991 1.75.4.1 phil
992 1.75.4.1 phil /* NB: must be after ni_chan is setup */
993 1.75.4.1 phil ieee80211_setup_rates(ni, se->se_rates, se->se_xrates,
994 1.75.4.1 phil IEEE80211_F_DOSORT);
995 1.75.4.1 phil if (ieee80211_iserp_rateset(&ni->ni_rates))
996 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ERP;
997 1.75.4.1 phil
998 1.75.4.1 phil /*
999 1.75.4.1 phil * Setup HT state for this node if it's available, otherwise
1000 1.75.4.1 phil * non-STA modes won't pick this state up.
1001 1.75.4.1 phil *
1002 1.75.4.1 phil * For IBSS and related modes that don't go through an
1003 1.75.4.1 phil * association request/response, the only appropriate place
1004 1.75.4.1 phil * to setup the HT state is here.
1005 1.75.4.1 phil */
1006 1.75.4.1 phil if (ni->ni_ies.htinfo_ie != NULL &&
1007 1.75.4.1 phil ni->ni_ies.htcap_ie != NULL &&
1008 1.75.4.1 phil vap->iv_flags_ht & IEEE80211_FHT_HT) {
1009 1.75.4.1 phil ieee80211_ht_node_init(ni);
1010 1.75.4.1 phil ieee80211_ht_updateparams(ni,
1011 1.75.4.1 phil ni->ni_ies.htcap_ie,
1012 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1013 1.75.4.1 phil do_ht = 1;
1014 1.75.4.1 phil }
1015 1.75.4.1 phil
1016 1.75.4.1 phil /*
1017 1.75.4.1 phil * Setup VHT state for this node if it's available.
1018 1.75.4.1 phil * Same as the above.
1019 1.75.4.1 phil *
1020 1.75.4.1 phil * For now, don't allow 2GHz VHT operation.
1021 1.75.4.1 phil */
1022 1.75.4.1 phil if (ni->ni_ies.vhtopmode_ie != NULL &&
1023 1.75.4.1 phil ni->ni_ies.vhtcap_ie != NULL &&
1024 1.75.4.1 phil vap->iv_flags_vht & IEEE80211_FVHT_VHT) {
1025 1.75.4.2 phil #if __FreeBSD__
1026 1.75.4.1 phil if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
1027 1.75.4.1 phil printf("%s: BSS %6D: 2GHz channel, VHT info; ignoring\n",
1028 1.75.4.1 phil __func__,
1029 1.75.4.1 phil ni->ni_macaddr,
1030 1.75.4.1 phil ":");
1031 1.75.4.2 phil #elif __NetBSD__
1032 1.75.4.2 phil if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
1033 1.75.4.2 phil printf("%s: BSS %6ld: 2GHz channel, VHT info; ignoring\n",
1034 1.75.4.2 phil __func__, (long int)ni->ni_macaddr);
1035 1.75.4.2 phil #endif
1036 1.75.4.1 phil } else {
1037 1.75.4.1 phil ieee80211_vht_node_init(ni);
1038 1.75.4.1 phil ieee80211_vht_updateparams(ni,
1039 1.75.4.1 phil ni->ni_ies.vhtcap_ie,
1040 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1041 1.75.4.1 phil ieee80211_setup_vht_rates(ni, ni->ni_ies.vhtcap_ie,
1042 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1043 1.75.4.1 phil do_ht = 1;
1044 1.75.4.1 phil }
1045 1.75.4.1 phil }
1046 1.75.4.1 phil
1047 1.75.4.1 phil /* Finally do the node channel change */
1048 1.75.4.1 phil if (do_ht) {
1049 1.75.4.1 phil ieee80211_ht_updateparams_final(ni, ni->ni_ies.htcap_ie,
1050 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1051 1.75.4.1 phil ieee80211_setup_htrates(ni, ni->ni_ies.htcap_ie,
1052 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DOBRS);
1053 1.75.4.1 phil ieee80211_setup_basic_htrates(ni, ni->ni_ies.htinfo_ie);
1054 1.75.4.1 phil }
1055 1.75.4.1 phil
1056 1.75.4.1 phil /* XXX else check for ath FF? */
1057 1.75.4.1 phil /* XXX QoS? Difficult given that WME config is specific to a master */
1058 1.75.4.1 phil
1059 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1060 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1061 1.75.4.1 phil
1062 1.75.4.1 phil return ieee80211_sta_join1(ieee80211_ref_node(ni));
1063 1.75.4.1 phil }
1064 1.75.4.1 phil
1065 1.39 dyoung /*
1066 1.39 dyoung * Leave the specified IBSS/BSS network. The node is assumed to
1067 1.39 dyoung * be passed in with a held reference.
1068 1.39 dyoung */
1069 1.39 dyoung void
1070 1.75.4.1 phil ieee80211_sta_leave(struct ieee80211_node *ni)
1071 1.39 dyoung {
1072 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
1073 1.75.4.1 phil
1074 1.39 dyoung ic->ic_node_cleanup(ni);
1075 1.75.4.1 phil ieee80211_notify_node_leave(ni);
1076 1.1 dyoung }
1077 1.1 dyoung
1078 1.75.4.1 phil /*
1079 1.75.4.1 phil * Send a deauthenticate frame and drop the station.
1080 1.75.4.1 phil */
1081 1.75.4.1 phil void
1082 1.75.4.1 phil ieee80211_node_deauth(struct ieee80211_node *ni, int reason)
1083 1.5 dyoung {
1084 1.75.4.1 phil /* NB: bump the refcnt to be sure temporary nodes are not reclaimed */
1085 1.75.4.1 phil ieee80211_ref_node(ni);
1086 1.75.4.1 phil if (ni->ni_associd != 0)
1087 1.75.4.1 phil IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH, reason);
1088 1.75.4.1 phil ieee80211_node_leave(ni);
1089 1.75.4.1 phil ieee80211_free_node(ni);
1090 1.75.4.1 phil }
1091 1.5 dyoung
1092 1.75.4.1 phil static struct ieee80211_node *
1093 1.75.4.1 phil node_alloc(struct ieee80211vap *vap, const uint8_t macaddr[IEEE80211_ADDR_LEN])
1094 1.75.4.1 phil {
1095 1.75.4.1 phil struct ieee80211_node *ni;
1096 1.75.4.1 phil
1097 1.75.4.1 phil ni = (struct ieee80211_node *) IEEE80211_MALLOC(sizeof(struct ieee80211_node),
1098 1.75.4.1 phil M_80211_NODE, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
1099 1.75.4.1 phil return ni;
1100 1.75.4.1 phil }
1101 1.75.4.1 phil
1102 1.75.4.1 phil /*
1103 1.75.4.1 phil * Initialize an ie blob with the specified data. If previous
1104 1.75.4.1 phil * data exists re-use the data block. As a side effect we clear
1105 1.75.4.1 phil * all references to specific ie's; the caller is required to
1106 1.75.4.1 phil * recalculate them.
1107 1.75.4.1 phil */
1108 1.75.4.1 phil int
1109 1.75.4.1 phil ieee80211_ies_init(struct ieee80211_ies *ies, const uint8_t *data, int len)
1110 1.75.4.1 phil {
1111 1.75.4.1 phil /* NB: assumes data+len are the last fields */
1112 1.75.4.1 phil memset(ies, 0, offsetof(struct ieee80211_ies, data));
1113 1.75.4.1 phil if (ies->data != NULL && ies->len != len) {
1114 1.75.4.1 phil /* data size changed */
1115 1.75.4.1 phil IEEE80211_FREE(ies->data, M_80211_NODE_IE);
1116 1.75.4.1 phil ies->data = NULL;
1117 1.75.4.1 phil }
1118 1.75.4.1 phil if (ies->data == NULL) {
1119 1.75.4.1 phil ies->data = (uint8_t *) IEEE80211_MALLOC(len, M_80211_NODE_IE,
1120 1.75.4.1 phil IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
1121 1.75.4.1 phil if (ies->data == NULL) {
1122 1.75.4.1 phil ies->len = 0;
1123 1.75.4.1 phil /* NB: pointers have already been zero'd above */
1124 1.75.4.1 phil return 0;
1125 1.55 dyoung }
1126 1.55 dyoung }
1127 1.75.4.1 phil memcpy(ies->data, data, len);
1128 1.75.4.1 phil ies->len = len;
1129 1.75.4.1 phil return 1;
1130 1.75.4.1 phil }
1131 1.75 maxv
1132 1.75.4.1 phil /*
1133 1.75.4.1 phil * Reclaim storage for an ie blob.
1134 1.75.4.1 phil */
1135 1.75.4.1 phil void
1136 1.75.4.1 phil ieee80211_ies_cleanup(struct ieee80211_ies *ies)
1137 1.75.4.1 phil {
1138 1.75.4.1 phil if (ies->data != NULL)
1139 1.75.4.1 phil IEEE80211_FREE(ies->data, M_80211_NODE_IE);
1140 1.5 dyoung }
1141 1.5 dyoung
1142 1.75.4.1 phil /*
1143 1.75.4.1 phil * Expand an ie blob data contents and to fillin individual
1144 1.75.4.1 phil * ie pointers. The data blob is assumed to be well-formed;
1145 1.75.4.1 phil * we don't do any validity checking of ie lengths.
1146 1.75.4.1 phil */
1147 1.75.4.1 phil void
1148 1.75.4.1 phil ieee80211_ies_expand(struct ieee80211_ies *ies)
1149 1.1 dyoung {
1150 1.75.4.1 phil uint8_t *ie;
1151 1.75.4.1 phil int ielen;
1152 1.39 dyoung
1153 1.75.4.1 phil ie = ies->data;
1154 1.75.4.1 phil ielen = ies->len;
1155 1.75.4.1 phil while (ielen > 0) {
1156 1.75.4.1 phil switch (ie[0]) {
1157 1.75.4.1 phil case IEEE80211_ELEMID_VENDOR:
1158 1.75.4.1 phil if (iswpaoui(ie))
1159 1.75.4.1 phil ies->wpa_ie = ie;
1160 1.75.4.1 phil else if (iswmeoui(ie))
1161 1.75.4.1 phil ies->wme_ie = ie;
1162 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1163 1.75.4.1 phil else if (isatherosoui(ie))
1164 1.75.4.1 phil ies->ath_ie = ie;
1165 1.75.4.1 phil #endif
1166 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_TDMA
1167 1.75.4.1 phil else if (istdmaoui(ie))
1168 1.75.4.1 phil ies->tdma_ie = ie;
1169 1.75.4.1 phil #endif
1170 1.75.4.1 phil break;
1171 1.75.4.1 phil case IEEE80211_ELEMID_RSN:
1172 1.75.4.1 phil ies->rsn_ie = ie;
1173 1.75.4.1 phil break;
1174 1.75.4.1 phil case IEEE80211_ELEMID_HTCAP:
1175 1.75.4.1 phil ies->htcap_ie = ie;
1176 1.75.4.1 phil break;
1177 1.75.4.1 phil case IEEE80211_ELEMID_HTINFO:
1178 1.75.4.1 phil ies->htinfo_ie = ie;
1179 1.75.4.1 phil break;
1180 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
1181 1.75.4.1 phil case IEEE80211_ELEMID_MESHID:
1182 1.75.4.1 phil ies->meshid_ie = ie;
1183 1.75.4.1 phil break;
1184 1.75.4.1 phil #endif
1185 1.75.4.1 phil case IEEE80211_ELEMID_VHT_CAP:
1186 1.75.4.1 phil ies->vhtcap_ie = ie;
1187 1.75.4.1 phil break;
1188 1.75.4.1 phil case IEEE80211_ELEMID_VHT_OPMODE:
1189 1.75.4.1 phil ies->vhtopmode_ie = ie;
1190 1.75.4.1 phil break;
1191 1.75.4.1 phil case IEEE80211_ELEMID_VHT_PWR_ENV:
1192 1.75.4.1 phil ies->vhtpwrenv_ie = ie;
1193 1.75.4.1 phil break;
1194 1.75.4.1 phil case IEEE80211_ELEMID_BSSLOAD:
1195 1.75.4.1 phil ies->bssload_ie = ie;
1196 1.75.4.1 phil break;
1197 1.75.4.1 phil case IEEE80211_ELEMID_APCHANREP:
1198 1.75.4.1 phil ies->apchanrep_ie = ie;
1199 1.75.4.1 phil break;
1200 1.75.4.1 phil }
1201 1.75.4.1 phil ielen -= 2 + ie[1];
1202 1.75.4.1 phil ie += 2 + ie[1];
1203 1.75.4.1 phil }
1204 1.1 dyoung }
1205 1.1 dyoung
1206 1.39 dyoung /*
1207 1.39 dyoung * Reclaim any resources in a node and reset any critical
1208 1.39 dyoung * state. Typically nodes are free'd immediately after,
1209 1.39 dyoung * but in some cases the storage may be reused so we need
1210 1.39 dyoung * to insure consistent state (should probably fix that).
1211 1.39 dyoung */
1212 1.1 dyoung static void
1213 1.39 dyoung node_cleanup(struct ieee80211_node *ni)
1214 1.22 mycroft {
1215 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
1216 1.39 dyoung struct ieee80211com *ic = ni->ni_ic;
1217 1.75.4.1 phil int i;
1218 1.39 dyoung
1219 1.39 dyoung /* NB: preserve ni_table */
1220 1.39 dyoung if (ni->ni_flags & IEEE80211_NODE_PWR_MGT) {
1221 1.75.4.1 phil if (vap->iv_opmode != IEEE80211_M_STA)
1222 1.75.4.1 phil vap->iv_ps_sta--;
1223 1.39 dyoung ni->ni_flags &= ~IEEE80211_NODE_PWR_MGT;
1224 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni,
1225 1.75.4.1 phil "power save mode off, %u sta's in ps mode", vap->iv_ps_sta);
1226 1.39 dyoung }
1227 1.75.4.1 phil /*
1228 1.75.4.1 phil * Cleanup any VHT and HT-related state.
1229 1.75.4.1 phil */
1230 1.75.4.1 phil if (ni->ni_flags & IEEE80211_NODE_VHT)
1231 1.75.4.1 phil ieee80211_vht_node_cleanup(ni);
1232 1.75.4.1 phil if (ni->ni_flags & IEEE80211_NODE_HT)
1233 1.75.4.1 phil ieee80211_ht_node_cleanup(ni);
1234 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1235 1.75.4.1 phil /* Always do FF node cleanup; for A-MSDU */
1236 1.75.4.1 phil ieee80211_ff_node_cleanup(ni);
1237 1.75.4.1 phil #endif
1238 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
1239 1.75.4.1 phil /*
1240 1.75.4.1 phil * Cleanup any mesh-related state.
1241 1.75.4.1 phil */
1242 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_MBSS)
1243 1.75.4.1 phil ieee80211_mesh_node_cleanup(ni);
1244 1.75.4.1 phil #endif
1245 1.75.4.1 phil /*
1246 1.75.4.1 phil * Clear any staging queue entries.
1247 1.75.4.1 phil */
1248 1.75.4.1 phil ieee80211_ageq_drain_node(&ic->ic_stageq, ni);
1249 1.75 maxv
1250 1.42 dyoung /*
1251 1.42 dyoung * Clear AREF flag that marks the authorization refcnt bump
1252 1.42 dyoung * has happened. This is probably not needed as the node
1253 1.42 dyoung * should always be removed from the table so not found but
1254 1.42 dyoung * do it just in case.
1255 1.75.4.1 phil * Likewise clear the ASSOCID flag as these flags are intended
1256 1.75.4.1 phil * to be managed in tandem.
1257 1.42 dyoung */
1258 1.75.4.1 phil ni->ni_flags &= ~(IEEE80211_NODE_AREF | IEEE80211_NODE_ASSOCID);
1259 1.39 dyoung
1260 1.39 dyoung /*
1261 1.39 dyoung * Drain power save queue and, if needed, clear TIM.
1262 1.39 dyoung */
1263 1.75.4.1 phil if (ieee80211_node_psq_drain(ni) != 0 && vap->iv_set_tim != NULL)
1264 1.75.4.1 phil vap->iv_set_tim(ni, 0);
1265 1.39 dyoung
1266 1.39 dyoung ni->ni_associd = 0;
1267 1.39 dyoung if (ni->ni_challenge != NULL) {
1268 1.75.4.1 phil IEEE80211_FREE(ni->ni_challenge, M_80211_NODE);
1269 1.39 dyoung ni->ni_challenge = NULL;
1270 1.39 dyoung }
1271 1.39 dyoung /*
1272 1.39 dyoung * Preserve SSID, WPA, and WME ie's so the bss node is
1273 1.39 dyoung * reusable during a re-auth/re-assoc state transition.
1274 1.39 dyoung * If we remove these data they will not be recreated
1275 1.39 dyoung * because they come from a probe-response or beacon frame
1276 1.39 dyoung * which cannot be expected prior to the association-response.
1277 1.39 dyoung * This should not be an issue when operating in other modes
1278 1.39 dyoung * as stations leaving always go through a full state transition
1279 1.39 dyoung * which will rebuild this state.
1280 1.39 dyoung *
1281 1.39 dyoung * XXX does this leave us open to inheriting old state?
1282 1.39 dyoung */
1283 1.75.4.1 phil for (i = 0; i < nitems(ni->ni_rxfrag); i++)
1284 1.39 dyoung if (ni->ni_rxfrag[i] != NULL) {
1285 1.39 dyoung m_freem(ni->ni_rxfrag[i]);
1286 1.39 dyoung ni->ni_rxfrag[i] = NULL;
1287 1.39 dyoung }
1288 1.45 skrll /*
1289 1.45 skrll * Must be careful here to remove any key map entry w/o a LOR.
1290 1.45 skrll */
1291 1.45 skrll ieee80211_node_delucastkey(ni);
1292 1.22 mycroft }
1293 1.22 mycroft
1294 1.22 mycroft static void
1295 1.39 dyoung node_free(struct ieee80211_node *ni)
1296 1.1 dyoung {
1297 1.39 dyoung struct ieee80211com *ic = ni->ni_ic;
1298 1.39 dyoung
1299 1.75.4.1 phil ieee80211_ratectl_node_deinit(ni);
1300 1.39 dyoung ic->ic_node_cleanup(ni);
1301 1.75.4.1 phil ieee80211_ies_cleanup(&ni->ni_ies);
1302 1.75.4.1 phil ieee80211_psq_cleanup(&ni->ni_psq);
1303 1.75.4.1 phil IEEE80211_FREE(ni, M_80211_NODE);
1304 1.75.4.1 phil }
1305 1.75.4.1 phil
1306 1.75.4.1 phil static void
1307 1.75.4.1 phil node_age(struct ieee80211_node *ni)
1308 1.75.4.1 phil {
1309 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
1310 1.75.4.1 phil
1311 1.75.4.1 phil /*
1312 1.75.4.1 phil * Age frames on the power save queue.
1313 1.75.4.1 phil */
1314 1.75.4.1 phil if (ieee80211_node_psq_age(ni) != 0 &&
1315 1.75.4.1 phil ni->ni_psq.psq_len == 0 && vap->iv_set_tim != NULL)
1316 1.75.4.1 phil vap->iv_set_tim(ni, 0);
1317 1.75.4.1 phil /*
1318 1.75.4.1 phil * Age out HT resources (e.g. frames on the
1319 1.75.4.1 phil * A-MPDU reorder queues).
1320 1.75.4.1 phil */
1321 1.75.4.1 phil if (ni->ni_associd != 0 && (ni->ni_flags & IEEE80211_NODE_HT))
1322 1.75.4.1 phil ieee80211_ht_node_age(ni);
1323 1.1 dyoung }
1324 1.1 dyoung
1325 1.75.4.1 phil static int8_t
1326 1.39 dyoung node_getrssi(const struct ieee80211_node *ni)
1327 1.9 dyoung {
1328 1.75.4.1 phil uint32_t avgrssi = ni->ni_avgrssi;
1329 1.75.4.1 phil int32_t rssi;
1330 1.75.4.1 phil
1331 1.75.4.1 phil if (avgrssi == IEEE80211_RSSI_DUMMY_MARKER)
1332 1.75.4.1 phil return 0;
1333 1.75.4.1 phil rssi = IEEE80211_RSSI_GET(avgrssi);
1334 1.75.4.1 phil return rssi < 0 ? 0 : rssi > 127 ? 127 : rssi;
1335 1.75.4.1 phil }
1336 1.75.4.1 phil
1337 1.75.4.1 phil static void
1338 1.75.4.1 phil node_getsignal(const struct ieee80211_node *ni, int8_t *rssi, int8_t *noise)
1339 1.75.4.1 phil {
1340 1.75.4.1 phil *rssi = node_getrssi(ni);
1341 1.75.4.1 phil *noise = ni->ni_noise;
1342 1.75.4.1 phil }
1343 1.75.4.1 phil
1344 1.75.4.1 phil static void
1345 1.75.4.1 phil node_getmimoinfo(const struct ieee80211_node *ni,
1346 1.75.4.1 phil struct ieee80211_mimo_info *info)
1347 1.75.4.1 phil {
1348 1.75.4.1 phil int i;
1349 1.75.4.1 phil uint32_t avgrssi;
1350 1.75.4.1 phil int32_t rssi;
1351 1.75.4.1 phil
1352 1.75.4.1 phil bzero(info, sizeof(*info));
1353 1.75.4.1 phil
1354 1.75.4.1 phil for (i = 0; i < MIN(IEEE80211_MAX_CHAINS, ni->ni_mimo_chains); i++) {
1355 1.75.4.1 phil /* Note: for now, just pri20 channel info */
1356 1.75.4.1 phil avgrssi = ni->ni_mimo_rssi_ctl[i];
1357 1.75.4.1 phil if (avgrssi == IEEE80211_RSSI_DUMMY_MARKER) {
1358 1.75.4.1 phil info->ch[i].rssi[0] = 0;
1359 1.75.4.1 phil } else {
1360 1.75.4.1 phil rssi = IEEE80211_RSSI_GET(avgrssi);
1361 1.75.4.1 phil info->ch[i].rssi[0] = rssi < 0 ? 0 : rssi > 127 ? 127 : rssi;
1362 1.75.4.1 phil }
1363 1.75.4.1 phil info->ch[i].noise[0] = ni->ni_mimo_noise_ctl[i];
1364 1.75.4.1 phil }
1365 1.75.4.1 phil
1366 1.75.4.1 phil /* XXX ext radios? */
1367 1.75.4.1 phil
1368 1.75.4.1 phil /* XXX EVM? */
1369 1.9 dyoung }
1370 1.9 dyoung
1371 1.1 dyoung static void
1372 1.75.4.1 phil ieee80211_add_node_nt(struct ieee80211_node_table *nt,
1373 1.75.4.1 phil struct ieee80211_node *ni)
1374 1.1 dyoung {
1375 1.39 dyoung struct ieee80211com *ic = nt->nt_ic;
1376 1.1 dyoung int hash;
1377 1.1 dyoung
1378 1.75.4.1 phil IEEE80211_NODE_LOCK_ASSERT(nt);
1379 1.75.4.1 phil
1380 1.75.4.1 phil hash = IEEE80211_NODE_HASH(ic, ni->ni_macaddr);
1381 1.75.4.1 phil (void) ic; /* XXX IEEE80211_NODE_HASH */
1382 1.75.4.1 phil TAILQ_INSERT_TAIL(&nt->nt_node, ni, ni_list);
1383 1.75.4.1 phil LIST_INSERT_HEAD(&nt->nt_hash[hash], ni, ni_hash);
1384 1.75.4.1 phil nt->nt_count++;
1385 1.75.4.1 phil ni->ni_table = nt;
1386 1.75.4.1 phil }
1387 1.75.4.1 phil
1388 1.75.4.1 phil static void
1389 1.75.4.1 phil ieee80211_del_node_nt(struct ieee80211_node_table *nt,
1390 1.75.4.1 phil struct ieee80211_node *ni)
1391 1.75.4.1 phil {
1392 1.75.4.1 phil
1393 1.75.4.1 phil IEEE80211_NODE_LOCK_ASSERT(nt);
1394 1.75.4.1 phil
1395 1.75.4.1 phil TAILQ_REMOVE(&nt->nt_node, ni, ni_list);
1396 1.75.4.1 phil LIST_REMOVE(ni, ni_hash);
1397 1.75.4.1 phil nt->nt_count--;
1398 1.75.4.1 phil KASSERT(nt->nt_count >= 0,
1399 1.75.4.1 phil ("nt_count is negative (%d)!\n", nt->nt_count));
1400 1.75.4.1 phil ni->ni_table = NULL;
1401 1.75.4.1 phil }
1402 1.75.4.1 phil
1403 1.75.4.1 phil struct ieee80211_node *
1404 1.75.4.1 phil ieee80211_alloc_node(struct ieee80211_node_table *nt,
1405 1.75.4.1 phil struct ieee80211vap *vap, const uint8_t macaddr[IEEE80211_ADDR_LEN])
1406 1.75.4.1 phil {
1407 1.75.4.1 phil struct ieee80211com *ic = nt->nt_ic;
1408 1.75.4.1 phil struct ieee80211_node *ni;
1409 1.75.4.1 phil
1410 1.75.4.1 phil ni = ic->ic_node_alloc(vap, macaddr);
1411 1.75.4.1 phil if (ni == NULL) {
1412 1.75.4.1 phil vap->iv_stats.is_rx_nodealloc++;
1413 1.75.4.1 phil return NULL;
1414 1.75.4.1 phil }
1415 1.75.4.1 phil
1416 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1417 1.39 dyoung "%s %p<%s> in %s table\n", __func__, ni,
1418 1.39 dyoung ether_sprintf(macaddr), nt->nt_name);
1419 1.39 dyoung
1420 1.1 dyoung IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
1421 1.39 dyoung ieee80211_node_initref(ni); /* mark referenced */
1422 1.39 dyoung ni->ni_chan = IEEE80211_CHAN_ANYC;
1423 1.39 dyoung ni->ni_authmode = IEEE80211_AUTH_OPEN;
1424 1.39 dyoung ni->ni_txpower = ic->ic_txpowlimit; /* max power */
1425 1.75.4.1 phil ni->ni_txparms = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)];
1426 1.75.4.1 phil ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey, IEEE80211_KEYIX_NONE);
1427 1.75.4.1 phil ni->ni_avgrssi = IEEE80211_RSSI_DUMMY_MARKER;
1428 1.39 dyoung ni->ni_inact_reload = nt->nt_inact_init;
1429 1.39 dyoung ni->ni_inact = ni->ni_inact_reload;
1430 1.75.4.1 phil ni->ni_ath_defkeyix = 0x7fff;
1431 1.75.4.1 phil ieee80211_psq_init(&ni->ni_psq, "unknown");
1432 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
1433 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_MBSS)
1434 1.75.4.1 phil ieee80211_mesh_node_init(vap, ni);
1435 1.75.4.1 phil #endif
1436 1.39 dyoung IEEE80211_NODE_LOCK(nt);
1437 1.75.4.1 phil ieee80211_add_node_nt(nt, ni);
1438 1.75.4.1 phil ni->ni_vap = vap;
1439 1.39 dyoung ni->ni_ic = ic;
1440 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
1441 1.1 dyoung
1442 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
1443 1.75.4.1 phil "%s: inact_reload %u", __func__, ni->ni_inact_reload);
1444 1.75.4.1 phil
1445 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1446 1.39 dyoung
1447 1.1 dyoung return ni;
1448 1.1 dyoung }
1449 1.1 dyoung
1450 1.45 skrll /*
1451 1.45 skrll * Craft a temporary node suitable for sending a management frame
1452 1.45 skrll * to the specified station. We craft only as much state as we
1453 1.45 skrll * need to do the work since the node will be immediately reclaimed
1454 1.45 skrll * once the send completes.
1455 1.45 skrll */
1456 1.45 skrll struct ieee80211_node *
1457 1.75.4.1 phil ieee80211_tmp_node(struct ieee80211vap *vap,
1458 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1459 1.45 skrll {
1460 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1461 1.45 skrll struct ieee80211_node *ni;
1462 1.45 skrll
1463 1.75.4.1 phil ni = ic->ic_node_alloc(vap, macaddr);
1464 1.45 skrll if (ni != NULL) {
1465 1.75.4.1 phil struct ieee80211_node *bss = vap->iv_bss;
1466 1.75.4.1 phil
1467 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1468 1.45 skrll "%s %p<%s>\n", __func__, ni, ether_sprintf(macaddr));
1469 1.45 skrll
1470 1.75.4.1 phil ni->ni_table = NULL; /* NB: pedantic */
1471 1.75.4.1 phil ni->ni_ic = ic; /* NB: needed to set channel */
1472 1.75.4.1 phil ni->ni_vap = vap;
1473 1.75.4.1 phil
1474 1.45 skrll IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
1475 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, bss->ni_bssid);
1476 1.45 skrll ieee80211_node_initref(ni); /* mark referenced */
1477 1.45 skrll /* NB: required by ieee80211_fix_rate */
1478 1.75.4.1 phil ieee80211_node_set_chan(ni, bss->ni_chan);
1479 1.75.4.1 phil ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey,
1480 1.45 skrll IEEE80211_KEYIX_NONE);
1481 1.75.4.1 phil ni->ni_txpower = bss->ni_txpower;
1482 1.45 skrll /* XXX optimize away */
1483 1.75.4.1 phil ieee80211_psq_init(&ni->ni_psq, "unknown");
1484 1.45 skrll
1485 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1486 1.45 skrll } else {
1487 1.45 skrll /* XXX msg */
1488 1.75.4.1 phil vap->iv_stats.is_rx_nodealloc++;
1489 1.45 skrll }
1490 1.45 skrll return ni;
1491 1.45 skrll }
1492 1.45 skrll
1493 1.1 dyoung struct ieee80211_node *
1494 1.75.4.1 phil ieee80211_dup_bss(struct ieee80211vap *vap,
1495 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1496 1.1 dyoung {
1497 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1498 1.39 dyoung struct ieee80211_node *ni;
1499 1.39 dyoung
1500 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, macaddr);
1501 1.1 dyoung if (ni != NULL) {
1502 1.75.4.1 phil struct ieee80211_node *bss = vap->iv_bss;
1503 1.11 dyoung /*
1504 1.75.4.1 phil * Inherit from iv_bss.
1505 1.11 dyoung */
1506 1.75.4.1 phil copy_bss(ni, bss);
1507 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, bss->ni_bssid);
1508 1.75.4.1 phil ieee80211_node_set_chan(ni, bss->ni_chan);
1509 1.75 maxv }
1510 1.1 dyoung return ni;
1511 1.1 dyoung }
1512 1.1 dyoung
1513 1.75.4.1 phil /*
1514 1.75.4.1 phil * Create a bss node for a legacy WDS vap. The far end does
1515 1.75.4.1 phil * not associate so we just create create a new node and
1516 1.75.4.1 phil * simulate an association. The caller is responsible for
1517 1.75.4.1 phil * installing the node as the bss node and handling any further
1518 1.75.4.1 phil * setup work like authorizing the port.
1519 1.75.4.1 phil */
1520 1.75.4.1 phil struct ieee80211_node *
1521 1.75.4.1 phil ieee80211_node_create_wds(struct ieee80211vap *vap,
1522 1.75.4.1 phil const uint8_t bssid[IEEE80211_ADDR_LEN], struct ieee80211_channel *chan)
1523 1.75.4.1 phil {
1524 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1525 1.75.4.1 phil struct ieee80211_node *ni;
1526 1.75.4.1 phil
1527 1.75.4.1 phil /* XXX check if node already in sta table? */
1528 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, bssid);
1529 1.75.4.1 phil if (ni != NULL) {
1530 1.75.4.1 phil ni->ni_wdsvap = vap;
1531 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, bssid);
1532 1.75.4.1 phil /*
1533 1.75.4.1 phil * Inherit any manually configured settings.
1534 1.75.4.1 phil */
1535 1.75.4.1 phil copy_bss(ni, vap->iv_bss);
1536 1.75.4.1 phil ieee80211_node_set_chan(ni, chan);
1537 1.75.4.1 phil /* NB: propagate ssid so available to WPA supplicant */
1538 1.75.4.1 phil ni->ni_esslen = vap->iv_des_ssid[0].len;
1539 1.75.4.1 phil memcpy(ni->ni_essid, vap->iv_des_ssid[0].ssid, ni->ni_esslen);
1540 1.75.4.1 phil /* NB: no associd for peer */
1541 1.75.4.1 phil /*
1542 1.75.4.1 phil * There are no management frames to use to
1543 1.75.4.1 phil * discover neighbor capabilities, so blindly
1544 1.75.4.1 phil * propagate the local configuration.
1545 1.75.4.1 phil */
1546 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_WME)
1547 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_QOS;
1548 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1549 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_FF)
1550 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_FF;
1551 1.75.4.1 phil #endif
1552 1.75.4.1 phil /* XXX VHT */
1553 1.75.4.1 phil if ((ic->ic_htcaps & IEEE80211_HTC_HT) &&
1554 1.75.4.1 phil (vap->iv_flags_ht & IEEE80211_FHT_HT)) {
1555 1.75.4.1 phil /*
1556 1.75.4.1 phil * Device is HT-capable and HT is enabled for
1557 1.75.4.1 phil * the vap; setup HT operation. On return
1558 1.75.4.1 phil * ni_chan will be adjusted to an HT channel.
1559 1.75.4.1 phil */
1560 1.75.4.1 phil ieee80211_ht_wds_init(ni);
1561 1.75.4.1 phil if (vap->iv_flags_vht & IEEE80211_FVHT_VHT) {
1562 1.75.4.1 phil printf("%s: TODO: vht_wds_init\n", __func__);
1563 1.75.4.1 phil }
1564 1.75.4.1 phil } else {
1565 1.75.4.1 phil struct ieee80211_channel *c = ni->ni_chan;
1566 1.75.4.1 phil /*
1567 1.75.4.1 phil * Force a legacy channel to be used.
1568 1.75.4.1 phil */
1569 1.75.4.1 phil c = ieee80211_find_channel(ic,
1570 1.75.4.1 phil c->ic_freq, c->ic_flags &~ IEEE80211_CHAN_HT);
1571 1.75.4.1 phil KASSERT(c != NULL, ("no legacy channel, %u/%x",
1572 1.75.4.1 phil ni->ni_chan->ic_freq, ni->ni_chan->ic_flags));
1573 1.75.4.1 phil ni->ni_chan = c;
1574 1.75.4.1 phil }
1575 1.75.4.1 phil }
1576 1.75.4.1 phil return ni;
1577 1.75.4.1 phil }
1578 1.75.4.1 phil
1579 1.75.4.1 phil struct ieee80211_node *
1580 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1581 1.75.4.1 phil ieee80211_find_node_locked_debug(struct ieee80211_node_table *nt,
1582 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1583 1.39 dyoung #else
1584 1.75.4.1 phil ieee80211_find_node_locked(struct ieee80211_node_table *nt,
1585 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1586 1.39 dyoung #endif
1587 1.1 dyoung {
1588 1.1 dyoung struct ieee80211_node *ni;
1589 1.1 dyoung int hash;
1590 1.11 dyoung
1591 1.39 dyoung IEEE80211_NODE_LOCK_ASSERT(nt);
1592 1.1 dyoung
1593 1.75.4.1 phil hash = IEEE80211_NODE_HASH(nt->nt_ic, macaddr);
1594 1.39 dyoung LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
1595 1.1 dyoung if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
1596 1.39 dyoung ieee80211_ref_node(ni); /* mark referenced */
1597 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1598 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1599 1.39 dyoung "%s (%s:%u) %p<%s> refcnt %d\n", __func__,
1600 1.39 dyoung func, line,
1601 1.39 dyoung ni, ether_sprintf(ni->ni_macaddr),
1602 1.39 dyoung ieee80211_node_refcnt(ni));
1603 1.39 dyoung #endif
1604 1.11 dyoung return ni;
1605 1.1 dyoung }
1606 1.1 dyoung }
1607 1.11 dyoung return NULL;
1608 1.11 dyoung }
1609 1.11 dyoung
1610 1.11 dyoung struct ieee80211_node *
1611 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1612 1.39 dyoung ieee80211_find_node_debug(struct ieee80211_node_table *nt,
1613 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1614 1.39 dyoung #else
1615 1.75.4.1 phil ieee80211_find_node(struct ieee80211_node_table *nt,
1616 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1617 1.39 dyoung #endif
1618 1.11 dyoung {
1619 1.11 dyoung struct ieee80211_node *ni;
1620 1.11 dyoung
1621 1.39 dyoung IEEE80211_NODE_LOCK(nt);
1622 1.75.4.1 phil ni = ieee80211_find_node_locked(nt, macaddr);
1623 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
1624 1.7 dyoung return ni;
1625 1.7 dyoung }
1626 1.7 dyoung
1627 1.7 dyoung struct ieee80211_node *
1628 1.75.4.1 phil #ifdef IEEE80211_DEBUG_REFCNT
1629 1.75.4.1 phil ieee80211_find_vap_node_locked_debug(struct ieee80211_node_table *nt,
1630 1.75.4.1 phil const struct ieee80211vap *vap,
1631 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1632 1.75.4.1 phil #else
1633 1.75.4.1 phil ieee80211_find_vap_node_locked(struct ieee80211_node_table *nt,
1634 1.75.4.1 phil const struct ieee80211vap *vap,
1635 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1636 1.75.4.1 phil #endif
1637 1.7 dyoung {
1638 1.7 dyoung struct ieee80211_node *ni;
1639 1.75.4.1 phil int hash;
1640 1.7 dyoung
1641 1.75.4.1 phil IEEE80211_NODE_LOCK_ASSERT(nt);
1642 1.45 skrll
1643 1.75.4.1 phil hash = IEEE80211_NODE_HASH(nt->nt_ic, macaddr);
1644 1.75.4.1 phil LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
1645 1.75.4.1 phil if (ni->ni_vap == vap &&
1646 1.75.4.1 phil IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
1647 1.75.4.1 phil ieee80211_ref_node(ni); /* mark referenced */
1648 1.75.4.1 phil #ifdef IEEE80211_DEBUG_REFCNT
1649 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1650 1.75.4.1 phil "%s (%s:%u) %p<%s> refcnt %d\n", __func__,
1651 1.75.4.1 phil func, line,
1652 1.75.4.1 phil ni, ether_sprintf(ni->ni_macaddr),
1653 1.75.4.1 phil ieee80211_node_refcnt(ni));
1654 1.45 skrll #endif
1655 1.75.4.1 phil return ni;
1656 1.45 skrll }
1657 1.45 skrll }
1658 1.75.4.1 phil return NULL;
1659 1.45 skrll }
1660 1.45 skrll
1661 1.75.4.1 phil struct ieee80211_node *
1662 1.75.4.1 phil #ifdef IEEE80211_DEBUG_REFCNT
1663 1.75.4.1 phil ieee80211_find_vap_node_debug(struct ieee80211_node_table *nt,
1664 1.75.4.1 phil const struct ieee80211vap *vap,
1665 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1666 1.75.4.1 phil #else
1667 1.75.4.1 phil ieee80211_find_vap_node(struct ieee80211_node_table *nt,
1668 1.75.4.1 phil const struct ieee80211vap *vap,
1669 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1670 1.75.4.1 phil #endif
1671 1.45 skrll {
1672 1.75.4.1 phil struct ieee80211_node *ni;
1673 1.45 skrll
1674 1.75.4.1 phil IEEE80211_NODE_LOCK(nt);
1675 1.75.4.1 phil ni = ieee80211_find_vap_node_locked(nt, vap, macaddr);
1676 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
1677 1.75.4.1 phil return ni;
1678 1.45 skrll }
1679 1.45 skrll
1680 1.45 skrll /*
1681 1.75.4.1 phil * Fake up a node; this handles node discovery in adhoc mode.
1682 1.75.4.1 phil * Note that for the driver's benefit we we treat this like
1683 1.75.4.1 phil * an association so the driver has an opportunity to setup
1684 1.75.4.1 phil * it's private state.
1685 1.45 skrll */
1686 1.75.4.1 phil struct ieee80211_node *
1687 1.75.4.1 phil ieee80211_fakeup_adhoc_node(struct ieee80211vap *vap,
1688 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1689 1.45 skrll {
1690 1.45 skrll struct ieee80211_node *ni;
1691 1.45 skrll
1692 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE | IEEE80211_MSG_ASSOC,
1693 1.75.4.1 phil "%s: mac<%s>\n", __func__, ether_sprintf(macaddr));
1694 1.75.4.1 phil ni = ieee80211_dup_bss(vap, macaddr);
1695 1.75.4.1 phil if (ni != NULL) {
1696 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1697 1.75.4.1 phil
1698 1.75.4.1 phil /* XXX no rate negotiation; just dup */
1699 1.75.4.1 phil ni->ni_rates = vap->iv_bss->ni_rates;
1700 1.75.4.1 phil if (ieee80211_iserp_rateset(&ni->ni_rates))
1701 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ERP;
1702 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
1703 1.75.4.1 phil /*
1704 1.75.4.1 phil * In adhoc demo mode there are no management
1705 1.75.4.1 phil * frames to use to discover neighbor capabilities,
1706 1.75.4.1 phil * so blindly propagate the local configuration
1707 1.75.4.1 phil * so we can do interesting things (e.g. use
1708 1.75.4.1 phil * WME to disable ACK's).
1709 1.75.4.1 phil */
1710 1.75.4.1 phil /*
1711 1.75.4.1 phil * XXX TODO: 11n?
1712 1.75.4.1 phil */
1713 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_WME)
1714 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_QOS;
1715 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1716 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_FF)
1717 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_FF;
1718 1.75.4.1 phil #endif
1719 1.75.4.1 phil }
1720 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1721 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1722 1.75.4.1 phil
1723 1.75.4.1 phil /*
1724 1.75.4.1 phil * XXX TODO: 11n? At least 20MHz, at least A-MPDU RX,
1725 1.75.4.1 phil * not A-MPDU TX; not 11n rates, etc. We'll cycle
1726 1.75.4.1 phil * that after we hear that we can indeed do 11n
1727 1.75.4.1 phil * (either by a beacon frame or by a probe response.)
1728 1.75.4.1 phil */
1729 1.75.4.1 phil
1730 1.75.4.1 phil /*
1731 1.75.4.1 phil * This is the first time we see the node.
1732 1.75.4.1 phil */
1733 1.75.4.1 phil if (ic->ic_newassoc != NULL)
1734 1.75.4.1 phil ic->ic_newassoc(ni, 1);
1735 1.75.4.1 phil
1736 1.45 skrll /*
1737 1.75.4.1 phil * Kick off a probe request to the given node;
1738 1.75.4.1 phil * we will then use the probe response to update
1739 1.75.4.1 phil * 11n/etc configuration state.
1740 1.75.4.1 phil *
1741 1.75.4.1 phil * XXX TODO: this isn't guaranteed, and until we get
1742 1.75.4.1 phil * a probe response, we won't be able to actually
1743 1.75.4.1 phil * do anything 802.11n related to the node.
1744 1.75.4.1 phil * So if this does indeed work, maybe we should hold
1745 1.75.4.1 phil * off on sending responses until we get the probe
1746 1.75.4.1 phil * response, or just default to some sensible subset
1747 1.75.4.1 phil * of 802.11n behaviour (eg always allow aggregation
1748 1.75.4.1 phil * negotiation TO us, but not FROM us, etc) so we
1749 1.75.4.1 phil * aren't entirely busted.
1750 1.45 skrll */
1751 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS) {
1752 1.75.4.1 phil ieee80211_send_probereq(ni, /* node */
1753 1.75.4.1 phil vap->iv_myaddr, /* SA */
1754 1.75.4.1 phil ni->ni_macaddr, /* DA */
1755 1.75.4.1 phil vap->iv_bss->ni_bssid, /* BSSID */
1756 1.75.4.1 phil vap->iv_bss->ni_essid,
1757 1.75.4.1 phil vap->iv_bss->ni_esslen); /* SSID */
1758 1.45 skrll }
1759 1.74 maxv
1760 1.75.4.1 phil /* XXX not right for 802.1x/WPA */
1761 1.75.4.1 phil ieee80211_node_authorize(ni);
1762 1.45 skrll }
1763 1.75.4.1 phil return ni;
1764 1.75.4.1 phil }
1765 1.74 maxv
1766 1.75.4.1 phil void
1767 1.75.4.1 phil ieee80211_init_neighbor(struct ieee80211_node *ni,
1768 1.75.4.1 phil const struct ieee80211_frame *wh,
1769 1.75.4.1 phil const struct ieee80211_scanparams *sp)
1770 1.75.4.1 phil {
1771 1.75.4.1 phil int do_ht_setup = 0, do_vht_setup = 0;
1772 1.74 maxv
1773 1.75.4.1 phil ni->ni_esslen = sp->ssid[1];
1774 1.75.4.1 phil memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]);
1775 1.45 skrll IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
1776 1.75.4.1 phil memcpy(ni->ni_tstamp.data, sp->tstamp, sizeof(ni->ni_tstamp));
1777 1.75.4.1 phil ni->ni_intval = sp->bintval;
1778 1.75.4.1 phil ni->ni_capinfo = sp->capinfo;
1779 1.75.4.1 phil ni->ni_chan = ni->ni_ic->ic_curchan;
1780 1.75.4.1 phil ni->ni_fhdwell = sp->fhdwell;
1781 1.75.4.1 phil ni->ni_fhindex = sp->fhindex;
1782 1.75.4.1 phil ni->ni_erp = sp->erp;
1783 1.75.4.1 phil ni->ni_timoff = sp->timoff;
1784 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
1785 1.75.4.1 phil if (ni->ni_vap->iv_opmode == IEEE80211_M_MBSS)
1786 1.75.4.1 phil ieee80211_mesh_init_neighbor(ni, wh, sp);
1787 1.75.4.1 phil #endif
1788 1.75.4.1 phil if (ieee80211_ies_init(&ni->ni_ies, sp->ies, sp->ies_len)) {
1789 1.75.4.1 phil ieee80211_ies_expand(&ni->ni_ies);
1790 1.75.4.1 phil if (ni->ni_ies.wme_ie != NULL)
1791 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_QOS;
1792 1.75.4.1 phil else
1793 1.75.4.1 phil ni->ni_flags &= ~IEEE80211_NODE_QOS;
1794 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1795 1.75.4.1 phil if (ni->ni_ies.ath_ie != NULL)
1796 1.75.4.1 phil ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
1797 1.75.4.1 phil #endif
1798 1.75.4.1 phil if (ni->ni_ies.htcap_ie != NULL)
1799 1.75.4.1 phil ieee80211_parse_htcap(ni, ni->ni_ies.htcap_ie);
1800 1.75.4.1 phil if (ni->ni_ies.htinfo_ie != NULL)
1801 1.75.4.1 phil ieee80211_parse_htinfo(ni, ni->ni_ies.htinfo_ie);
1802 1.75.4.1 phil
1803 1.75.4.1 phil if (ni->ni_ies.vhtcap_ie != NULL)
1804 1.75.4.1 phil ieee80211_parse_vhtcap(ni, ni->ni_ies.vhtcap_ie);
1805 1.75.4.1 phil if (ni->ni_ies.vhtopmode_ie != NULL)
1806 1.75.4.1 phil ieee80211_parse_vhtopmode(ni, ni->ni_ies.vhtopmode_ie);
1807 1.75.4.1 phil
1808 1.75.4.1 phil if ((ni->ni_ies.htcap_ie != NULL) &&
1809 1.75.4.1 phil (ni->ni_ies.htinfo_ie != NULL) &&
1810 1.75.4.1 phil (ni->ni_vap->iv_flags_ht & IEEE80211_FHT_HT)) {
1811 1.75.4.1 phil do_ht_setup = 1;
1812 1.75.4.1 phil }
1813 1.75.4.1 phil
1814 1.75.4.1 phil if ((ni->ni_ies.vhtcap_ie != NULL) &&
1815 1.75.4.1 phil (ni->ni_ies.vhtopmode_ie != NULL) &&
1816 1.75.4.1 phil (ni->ni_vap->iv_flags_vht & IEEE80211_FVHT_VHT)) {
1817 1.75.4.1 phil do_vht_setup = 1;
1818 1.75.4.1 phil }
1819 1.45 skrll
1820 1.45 skrll }
1821 1.74 maxv
1822 1.45 skrll /* NB: must be after ni_chan is setup */
1823 1.75.4.1 phil ieee80211_setup_rates(ni, sp->rates, sp->xrates,
1824 1.75.4.1 phil IEEE80211_F_DOSORT | IEEE80211_F_DOFRATE |
1825 1.75.4.1 phil IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
1826 1.75.4.1 phil
1827 1.75.4.1 phil /*
1828 1.75.4.1 phil * If the neighbor is HT compatible, flip that on.
1829 1.75.4.1 phil */
1830 1.75.4.1 phil if (do_ht_setup) {
1831 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
1832 1.75.4.1 phil "%s: doing HT setup\n", __func__);
1833 1.75.4.1 phil ieee80211_ht_node_init(ni);
1834 1.75.4.1 phil ieee80211_ht_updateparams(ni,
1835 1.75.4.1 phil ni->ni_ies.htcap_ie,
1836 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1837 1.75.4.1 phil
1838 1.75.4.1 phil if (do_vht_setup) {
1839 1.75.4.1 phil if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
1840 1.75.4.2 phil #if __FreeBSD__
1841 1.75.4.1 phil printf("%s: BSS %6D: 2GHz channel, VHT info; ignoring\n",
1842 1.75.4.1 phil __func__,
1843 1.75.4.1 phil ni->ni_macaddr,
1844 1.75.4.1 phil ":");
1845 1.75.4.2 phil #elif __NetBSD__
1846 1.75.4.2 phil printf("%s: BSS %6ld: 2GHz channel, VHT info; ignoring\n",
1847 1.75.4.2 phil __func__, (long int)ni->ni_macaddr);
1848 1.75.4.2 phil #endif
1849 1.75.4.1 phil } else {
1850 1.75.4.1 phil ieee80211_vht_node_init(ni);
1851 1.75.4.1 phil ieee80211_vht_updateparams(ni,
1852 1.75.4.1 phil ni->ni_ies.vhtcap_ie,
1853 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1854 1.75.4.1 phil ieee80211_setup_vht_rates(ni,
1855 1.75.4.1 phil ni->ni_ies.vhtcap_ie,
1856 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1857 1.75.4.1 phil }
1858 1.75.4.1 phil }
1859 1.45 skrll
1860 1.75.4.1 phil /*
1861 1.75.4.1 phil * Finally do the channel upgrade/change based
1862 1.75.4.1 phil * on the HT/VHT configuration.
1863 1.75.4.1 phil */
1864 1.75.4.1 phil ieee80211_ht_updateparams_final(ni, ni->ni_ies.htcap_ie,
1865 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1866 1.75.4.1 phil ieee80211_setup_htrates(ni,
1867 1.75.4.1 phil ni->ni_ies.htcap_ie,
1868 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DOBRS);
1869 1.75.4.1 phil ieee80211_setup_basic_htrates(ni,
1870 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1871 1.46 dyoung
1872 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1873 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1874 1.46 dyoung
1875 1.75.4.1 phil /* Reassociate; we're now 11n/11ac */
1876 1.75.4.1 phil /*
1877 1.75.4.1 phil * XXX TODO: this is the wrong thing to do -
1878 1.75.4.1 phil * we're calling it with isnew=1 so the ath(4)
1879 1.75.4.1 phil * driver reinitialises the rate tables.
1880 1.75.4.1 phil * This "mostly" works for ath(4), but it won't
1881 1.75.4.1 phil * be right for firmware devices which allocate
1882 1.75.4.1 phil * node states.
1883 1.75.4.1 phil *
1884 1.75.4.1 phil * So, do we just create a new node and delete
1885 1.75.4.1 phil * the old one? Or?
1886 1.75.4.1 phil */
1887 1.75.4.1 phil if (ni->ni_ic->ic_newassoc)
1888 1.75.4.1 phil ni->ni_ic->ic_newassoc(ni, 1);
1889 1.75.4.1 phil }
1890 1.46 dyoung }
1891 1.46 dyoung
1892 1.45 skrll /*
1893 1.45 skrll * Do node discovery in adhoc mode on receipt of a beacon
1894 1.45 skrll * or probe response frame. Note that for the driver's
1895 1.45 skrll * benefit we we treat this like an association so the
1896 1.75.4.1 phil * driver has an opportunity to setup it's private state.
1897 1.45 skrll */
1898 1.45 skrll struct ieee80211_node *
1899 1.75.4.1 phil ieee80211_add_neighbor(struct ieee80211vap *vap,
1900 1.45 skrll const struct ieee80211_frame *wh,
1901 1.45 skrll const struct ieee80211_scanparams *sp)
1902 1.45 skrll {
1903 1.45 skrll struct ieee80211_node *ni;
1904 1.45 skrll
1905 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
1906 1.75.4.1 phil "%s: mac<%s>\n", __func__, ether_sprintf(wh->i_addr2));
1907 1.75.4.1 phil ni = ieee80211_dup_bss(vap, wh->i_addr2);/* XXX alloc_node? */
1908 1.45 skrll if (ni != NULL) {
1909 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1910 1.75.4.1 phil
1911 1.75.4.1 phil ieee80211_init_neighbor(ni, wh, sp);
1912 1.75.4.1 phil if (ieee80211_iserp_rateset(&ni->ni_rates))
1913 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ERP;
1914 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1915 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1916 1.75.4.1 phil if (ic->ic_newassoc != NULL)
1917 1.75.4.1 phil ic->ic_newassoc(ni, 1);
1918 1.39 dyoung /* XXX not right for 802.1x/WPA */
1919 1.45 skrll ieee80211_node_authorize(ni);
1920 1.7 dyoung }
1921 1.39 dyoung return ni;
1922 1.7 dyoung }
1923 1.7 dyoung
1924 1.75.4.1 phil #define IS_PROBEREQ(wh) \
1925 1.75.4.1 phil ((wh->i_fc[0] & (IEEE80211_FC0_TYPE_MASK|IEEE80211_FC0_SUBTYPE_MASK)) \
1926 1.75.4.1 phil == (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ))
1927 1.75.4.1 phil #define IS_BCAST_PROBEREQ(wh) \
1928 1.75.4.1 phil (IS_PROBEREQ(wh) && IEEE80211_IS_MULTICAST( \
1929 1.75.4.1 phil ((const struct ieee80211_frame *)(wh))->i_addr3))
1930 1.75.4.1 phil
1931 1.75.4.1 phil static __inline struct ieee80211_node *
1932 1.75.4.1 phil _find_rxnode(struct ieee80211_node_table *nt,
1933 1.75.4.1 phil const struct ieee80211_frame_min *wh)
1934 1.75.4.1 phil {
1935 1.75.4.1 phil if (IS_BCAST_PROBEREQ(wh))
1936 1.75.4.1 phil return NULL; /* spam bcast probe req to all vap's */
1937 1.75.4.1 phil return ieee80211_find_node_locked(nt, wh->i_addr2);
1938 1.75.4.1 phil }
1939 1.75.4.1 phil
1940 1.7 dyoung /*
1941 1.39 dyoung * Locate the node for sender, track state, and then pass the
1942 1.75.4.1 phil * (referenced) node up to the 802.11 layer for its use. Note
1943 1.75.4.1 phil * we can return NULL if the sender is not in the table.
1944 1.7 dyoung */
1945 1.39 dyoung struct ieee80211_node *
1946 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1947 1.39 dyoung ieee80211_find_rxnode_debug(struct ieee80211com *ic,
1948 1.39 dyoung const struct ieee80211_frame_min *wh, const char *func, int line)
1949 1.39 dyoung #else
1950 1.39 dyoung ieee80211_find_rxnode(struct ieee80211com *ic,
1951 1.39 dyoung const struct ieee80211_frame_min *wh)
1952 1.39 dyoung #endif
1953 1.7 dyoung {
1954 1.39 dyoung struct ieee80211_node_table *nt;
1955 1.39 dyoung struct ieee80211_node *ni;
1956 1.7 dyoung
1957 1.75.4.1 phil nt = &ic->ic_sta;
1958 1.39 dyoung IEEE80211_NODE_LOCK(nt);
1959 1.75.4.1 phil ni = _find_rxnode(nt, wh);
1960 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
1961 1.7 dyoung
1962 1.45 skrll return ni;
1963 1.45 skrll }
1964 1.45 skrll
1965 1.45 skrll /*
1966 1.45 skrll * Like ieee80211_find_rxnode but use the supplied h/w
1967 1.45 skrll * key index as a hint to locate the node in the key
1968 1.45 skrll * mapping table. If an entry is present at the key
1969 1.45 skrll * index we return it; otherwise do a normal lookup and
1970 1.45 skrll * update the mapping table if the station has a unicast
1971 1.45 skrll * key assigned to it.
1972 1.45 skrll */
1973 1.45 skrll struct ieee80211_node *
1974 1.45 skrll #ifdef IEEE80211_DEBUG_REFCNT
1975 1.45 skrll ieee80211_find_rxnode_withkey_debug(struct ieee80211com *ic,
1976 1.45 skrll const struct ieee80211_frame_min *wh, ieee80211_keyix keyix,
1977 1.45 skrll const char *func, int line)
1978 1.45 skrll #else
1979 1.45 skrll ieee80211_find_rxnode_withkey(struct ieee80211com *ic,
1980 1.45 skrll const struct ieee80211_frame_min *wh, ieee80211_keyix keyix)
1981 1.45 skrll #endif
1982 1.45 skrll {
1983 1.45 skrll struct ieee80211_node_table *nt;
1984 1.45 skrll struct ieee80211_node *ni;
1985 1.45 skrll
1986 1.75.4.1 phil nt = &ic->ic_sta;
1987 1.45 skrll IEEE80211_NODE_LOCK(nt);
1988 1.75.4.1 phil if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax)
1989 1.45 skrll ni = nt->nt_keyixmap[keyix];
1990 1.75.4.1 phil else
1991 1.45 skrll ni = NULL;
1992 1.45 skrll if (ni == NULL) {
1993 1.75.4.1 phil ni = _find_rxnode(nt, wh);
1994 1.75.4.1 phil if (ni != NULL && nt->nt_keyixmap != NULL) {
1995 1.45 skrll /*
1996 1.45 skrll * If the station has a unicast key cache slot
1997 1.45 skrll * assigned update the key->node mapping table.
1998 1.45 skrll */
1999 1.45 skrll keyix = ni->ni_ucastkey.wk_rxkeyix;
2000 1.45 skrll /* XXX can keyixmap[keyix] != NULL? */
2001 1.45 skrll if (keyix < nt->nt_keyixmax &&
2002 1.45 skrll nt->nt_keyixmap[keyix] == NULL) {
2003 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap,
2004 1.75.4.1 phil IEEE80211_MSG_NODE,
2005 1.45 skrll "%s: add key map entry %p<%s> refcnt %d\n",
2006 1.45 skrll __func__, ni, ether_sprintf(ni->ni_macaddr),
2007 1.45 skrll ieee80211_node_refcnt(ni)+1);
2008 1.45 skrll nt->nt_keyixmap[keyix] = ieee80211_ref_node(ni);
2009 1.45 skrll }
2010 1.45 skrll }
2011 1.45 skrll } else {
2012 1.75.4.1 phil if (IS_BCAST_PROBEREQ(wh))
2013 1.75.4.1 phil ni = NULL; /* spam bcast probe req to all vap's */
2014 1.75.4.1 phil else
2015 1.75.4.1 phil ieee80211_ref_node(ni);
2016 1.45 skrll }
2017 1.45 skrll IEEE80211_NODE_UNLOCK(nt);
2018 1.45 skrll
2019 1.45 skrll return ni;
2020 1.45 skrll }
2021 1.75.4.1 phil #undef IS_BCAST_PROBEREQ
2022 1.75.4.1 phil #undef IS_PROBEREQ
2023 1.7 dyoung
2024 1.39 dyoung /*
2025 1.39 dyoung * Return a reference to the appropriate node for sending
2026 1.39 dyoung * a data frame. This handles node discovery in adhoc networks.
2027 1.33 dyoung */
2028 1.7 dyoung struct ieee80211_node *
2029 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
2030 1.75.4.1 phil ieee80211_find_txnode_debug(struct ieee80211vap *vap,
2031 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN],
2032 1.39 dyoung const char *func, int line)
2033 1.39 dyoung #else
2034 1.75.4.1 phil ieee80211_find_txnode(struct ieee80211vap *vap,
2035 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
2036 1.39 dyoung #endif
2037 1.7 dyoung {
2038 1.75.4.1 phil struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
2039 1.7 dyoung struct ieee80211_node *ni;
2040 1.7 dyoung
2041 1.39 dyoung /*
2042 1.39 dyoung * The destination address should be in the node table
2043 1.45 skrll * unless this is a multicast/broadcast frame. We can
2044 1.45 skrll * also optimize station mode operation, all frames go
2045 1.45 skrll * to the bss node.
2046 1.39 dyoung */
2047 1.39 dyoung /* XXX can't hold lock across dup_bss 'cuz of recursive locking */
2048 1.39 dyoung IEEE80211_NODE_LOCK(nt);
2049 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_STA ||
2050 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_WDS ||
2051 1.75.4.1 phil IEEE80211_IS_MULTICAST(macaddr))
2052 1.75.4.1 phil ni = ieee80211_ref_node(vap->iv_bss);
2053 1.45 skrll else
2054 1.75.4.1 phil ni = ieee80211_find_node_locked(nt, macaddr);
2055 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
2056 1.15 dyoung
2057 1.39 dyoung if (ni == NULL) {
2058 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS ||
2059 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_AHDEMO) {
2060 1.39 dyoung /*
2061 1.39 dyoung * In adhoc mode cons up a node for the destination.
2062 1.39 dyoung * Note that we need an additional reference for the
2063 1.75.4.1 phil * caller to be consistent with
2064 1.75.4.1 phil * ieee80211_find_node_locked.
2065 1.75.4.1 phil */
2066 1.75.4.1 phil /*
2067 1.75.4.1 phil * XXX TODO: this doesn't fake up 11n state; we need
2068 1.75.4.1 phil * to find another way to get it upgraded.
2069 1.39 dyoung */
2070 1.75.4.1 phil ni = ieee80211_fakeup_adhoc_node(vap, macaddr);
2071 1.39 dyoung if (ni != NULL)
2072 1.75.4.1 phil (void) ieee80211_ref_node(ni);
2073 1.39 dyoung } else {
2074 1.75.4.1 phil IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_OUTPUT, macaddr,
2075 1.75.4.1 phil "no node, discard frame (%s)", __func__);
2076 1.75.4.1 phil vap->iv_stats.is_tx_nonode++;
2077 1.39 dyoung }
2078 1.39 dyoung }
2079 1.39 dyoung return ni;
2080 1.1 dyoung }
2081 1.1 dyoung
2082 1.75.4.1 phil static void
2083 1.75.4.1 phil _ieee80211_free_node(struct ieee80211_node *ni)
2084 1.1 dyoung {
2085 1.75.4.1 phil struct ieee80211_node_table *nt = ni->ni_table;
2086 1.75 maxv
2087 1.75.4.1 phil /*
2088 1.75.4.1 phil * NB: careful about referencing the vap as it may be
2089 1.75.4.1 phil * gone if the last reference was held by a driver.
2090 1.75.4.1 phil * We know the com will always be present so it's safe
2091 1.75.4.1 phil * to use ni_ic below to reclaim resources.
2092 1.75.4.1 phil */
2093 1.75.4.1 phil #if 0
2094 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2095 1.75.4.1 phil "%s %p<%s> in %s table\n", __func__, ni,
2096 1.75.4.1 phil ether_sprintf(ni->ni_macaddr),
2097 1.75.4.1 phil nt != NULL ? nt->nt_name : "<gone>");
2098 1.61 gmcgarry #endif
2099 1.75.4.1 phil if (ni->ni_associd != 0) {
2100 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2101 1.75.4.1 phil if (vap->iv_aid_bitmap != NULL)
2102 1.75.4.1 phil IEEE80211_AID_CLR(vap, ni->ni_associd);
2103 1.1 dyoung }
2104 1.75.4.1 phil if (nt != NULL)
2105 1.75.4.1 phil ieee80211_del_node_nt(nt, ni);
2106 1.75.4.1 phil ni->ni_ic->ic_node_free(ni);
2107 1.1 dyoung }
2108 1.1 dyoung
2109 1.39 dyoung /*
2110 1.75.4.1 phil * Clear any entry in the unicast key mapping table.
2111 1.39 dyoung */
2112 1.75.4.1 phil static int
2113 1.75.4.1 phil node_clear_keyixmap(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
2114 1.39 dyoung {
2115 1.75.4.1 phil ieee80211_keyix keyix;
2116 1.72 christos
2117 1.75.4.1 phil keyix = ni->ni_ucastkey.wk_rxkeyix;
2118 1.75.4.1 phil if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax &&
2119 1.75.4.1 phil nt->nt_keyixmap[keyix] == ni) {
2120 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2121 1.75.4.1 phil "%s: %p<%s> clear key map entry %u\n",
2122 1.75.4.1 phil __func__, ni, ether_sprintf(ni->ni_macaddr), keyix);
2123 1.75.4.1 phil nt->nt_keyixmap[keyix] = NULL;
2124 1.75.4.1 phil ieee80211_node_decref(ni);
2125 1.75.4.1 phil return 1;
2126 1.39 dyoung }
2127 1.75 maxv
2128 1.75.4.1 phil return 0;
2129 1.1 dyoung }
2130 1.1 dyoung
2131 1.1 dyoung void
2132 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
2133 1.39 dyoung ieee80211_free_node_debug(struct ieee80211_node *ni, const char *func, int line)
2134 1.39 dyoung #else
2135 1.39 dyoung ieee80211_free_node(struct ieee80211_node *ni)
2136 1.39 dyoung #endif
2137 1.39 dyoung {
2138 1.39 dyoung struct ieee80211_node_table *nt = ni->ni_table;
2139 1.39 dyoung
2140 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
2141 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2142 1.39 dyoung "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line, ni,
2143 1.39 dyoung ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)-1);
2144 1.39 dyoung #endif
2145 1.45 skrll if (nt != NULL) {
2146 1.45 skrll IEEE80211_NODE_LOCK(nt);
2147 1.45 skrll if (ieee80211_node_dectestref(ni)) {
2148 1.45 skrll /*
2149 1.45 skrll * Last reference, reclaim state.
2150 1.45 skrll */
2151 1.39 dyoung _ieee80211_free_node(ni);
2152 1.75.4.1 phil } else if (ieee80211_node_refcnt(ni) == 1)
2153 1.75.4.1 phil if (node_clear_keyixmap(nt, ni))
2154 1.45 skrll _ieee80211_free_node(ni);
2155 1.45 skrll IEEE80211_NODE_UNLOCK(nt);
2156 1.45 skrll } else {
2157 1.45 skrll if (ieee80211_node_dectestref(ni))
2158 1.39 dyoung _ieee80211_free_node(ni);
2159 1.39 dyoung }
2160 1.39 dyoung }
2161 1.39 dyoung
2162 1.39 dyoung /*
2163 1.45 skrll * Reclaim a unicast key and clear any key cache state.
2164 1.45 skrll */
2165 1.45 skrll int
2166 1.45 skrll ieee80211_node_delucastkey(struct ieee80211_node *ni)
2167 1.45 skrll {
2168 1.45 skrll struct ieee80211com *ic = ni->ni_ic;
2169 1.45 skrll struct ieee80211_node_table *nt = &ic->ic_sta;
2170 1.45 skrll struct ieee80211_node *nikey;
2171 1.45 skrll ieee80211_keyix keyix;
2172 1.45 skrll int isowned, status;
2173 1.45 skrll
2174 1.45 skrll /*
2175 1.45 skrll * NB: We must beware of LOR here; deleting the key
2176 1.45 skrll * can cause the crypto layer to block traffic updates
2177 1.45 skrll * which can generate a LOR against the node table lock;
2178 1.45 skrll * grab it here and stash the key index for our use below.
2179 1.45 skrll *
2180 1.45 skrll * Must also beware of recursion on the node table lock.
2181 1.45 skrll * When called from node_cleanup we may already have
2182 1.45 skrll * the node table lock held. Unfortunately there's no
2183 1.45 skrll * way to separate out this path so we must do this
2184 1.45 skrll * conditionally.
2185 1.45 skrll */
2186 1.45 skrll isowned = IEEE80211_NODE_IS_LOCKED(nt);
2187 1.45 skrll if (!isowned)
2188 1.45 skrll IEEE80211_NODE_LOCK(nt);
2189 1.75.4.1 phil nikey = NULL;
2190 1.75.4.1 phil status = 1; /* NB: success */
2191 1.75.4.1 phil if (ni->ni_ucastkey.wk_keyix != IEEE80211_KEYIX_NONE) {
2192 1.75.4.1 phil keyix = ni->ni_ucastkey.wk_rxkeyix;
2193 1.75.4.1 phil status = ieee80211_crypto_delkey(ni->ni_vap, &ni->ni_ucastkey);
2194 1.75.4.1 phil if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax) {
2195 1.75.4.1 phil nikey = nt->nt_keyixmap[keyix];
2196 1.75.4.1 phil nt->nt_keyixmap[keyix] = NULL;
2197 1.75.4.1 phil }
2198 1.75.4.1 phil }
2199 1.45 skrll if (!isowned)
2200 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
2201 1.45 skrll
2202 1.45 skrll if (nikey != NULL) {
2203 1.75.4.1 phil KASSERT(nikey == ni,
2204 1.45 skrll ("key map out of sync, ni %p nikey %p", ni, nikey));
2205 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2206 1.45 skrll "%s: delete key map entry %p<%s> refcnt %d\n",
2207 1.45 skrll __func__, ni, ether_sprintf(ni->ni_macaddr),
2208 1.45 skrll ieee80211_node_refcnt(ni)-1);
2209 1.45 skrll ieee80211_free_node(ni);
2210 1.45 skrll }
2211 1.45 skrll return status;
2212 1.45 skrll }
2213 1.45 skrll
2214 1.45 skrll /*
2215 1.39 dyoung * Reclaim a node. If this is the last reference count then
2216 1.39 dyoung * do the normal free work. Otherwise remove it from the node
2217 1.39 dyoung * table and mark it gone by clearing the back-reference.
2218 1.39 dyoung */
2219 1.39 dyoung static void
2220 1.39 dyoung node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
2221 1.39 dyoung {
2222 1.45 skrll
2223 1.45 skrll IEEE80211_NODE_LOCK_ASSERT(nt);
2224 1.39 dyoung
2225 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2226 1.39 dyoung "%s: remove %p<%s> from %s table, refcnt %d\n",
2227 1.39 dyoung __func__, ni, ether_sprintf(ni->ni_macaddr),
2228 1.39 dyoung nt->nt_name, ieee80211_node_refcnt(ni)-1);
2229 1.45 skrll /*
2230 1.45 skrll * Clear any entry in the unicast key mapping table.
2231 1.45 skrll * We need to do it here so rx lookups don't find it
2232 1.45 skrll * in the mapping table even if it's not in the hash
2233 1.45 skrll * table. We cannot depend on the mapping table entry
2234 1.45 skrll * being cleared because the node may not be free'd.
2235 1.45 skrll */
2236 1.75.4.1 phil (void)node_clear_keyixmap(nt, ni);
2237 1.75.4.1 phil if (!ieee80211_node_dectestref(ni)) {
2238 1.75.4.1 phil /*
2239 1.75.4.1 phil * Other references are present, just remove the
2240 1.75.4.1 phil * node from the table so it cannot be found. When
2241 1.75.4.1 phil * the references are dropped storage will be
2242 1.75.4.1 phil * reclaimed.
2243 1.75.4.1 phil */
2244 1.75.4.1 phil ieee80211_del_node_nt(nt, ni);
2245 1.75.4.1 phil } else
2246 1.75.4.1 phil _ieee80211_free_node(ni);
2247 1.75.4.1 phil }
2248 1.75.4.1 phil
2249 1.75.4.1 phil /*
2250 1.75.4.1 phil * Node table support.
2251 1.75.4.1 phil */
2252 1.75.4.1 phil
2253 1.75.4.1 phil static void
2254 1.75.4.1 phil ieee80211_node_table_init(struct ieee80211com *ic,
2255 1.75.4.1 phil struct ieee80211_node_table *nt,
2256 1.75.4.1 phil const char *name, int inact, int keyixmax)
2257 1.75.4.1 phil {
2258 1.75.4.1 phil
2259 1.75.4.1 phil nt->nt_ic = ic;
2260 1.75.4.1 phil IEEE80211_NODE_LOCK_INIT(nt, ic->ic_name);
2261 1.75.4.1 phil TAILQ_INIT(&nt->nt_node);
2262 1.75.4.1 phil nt->nt_count = 0;
2263 1.75.4.1 phil nt->nt_name = name;
2264 1.75.4.1 phil nt->nt_inact_init = inact;
2265 1.75.4.1 phil nt->nt_keyixmax = keyixmax;
2266 1.75.4.1 phil if (nt->nt_keyixmax > 0) {
2267 1.75.4.1 phil nt->nt_keyixmap = (struct ieee80211_node **) IEEE80211_MALLOC(
2268 1.75.4.1 phil keyixmax * sizeof(struct ieee80211_node *),
2269 1.75.4.1 phil M_80211_NODE,
2270 1.75.4.1 phil IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
2271 1.75.4.1 phil if (nt->nt_keyixmap == NULL)
2272 1.75.4.1 phil ic_printf(ic,
2273 1.75.4.1 phil "Cannot allocate key index map with %u entries\n",
2274 1.75.4.1 phil keyixmax);
2275 1.75.4.1 phil } else
2276 1.75.4.1 phil nt->nt_keyixmap = NULL;
2277 1.75.4.1 phil }
2278 1.75.4.1 phil
2279 1.75.4.1 phil static void
2280 1.75.4.1 phil ieee80211_node_table_reset(struct ieee80211_node_table *nt,
2281 1.75.4.1 phil struct ieee80211vap *match)
2282 1.75.4.1 phil {
2283 1.75.4.1 phil struct ieee80211_node *ni, *next;
2284 1.75.4.1 phil
2285 1.75.4.1 phil IEEE80211_NODE_LOCK(nt);
2286 1.75.4.1 phil TAILQ_FOREACH_SAFE(ni, &nt->nt_node, ni_list, next) {
2287 1.75.4.1 phil if (match != NULL && ni->ni_vap != match)
2288 1.75.4.1 phil continue;
2289 1.75.4.1 phil /* XXX can this happen? if so need's work */
2290 1.75.4.1 phil if (ni->ni_associd != 0) {
2291 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2292 1.75.4.1 phil
2293 1.75.4.1 phil if (vap->iv_auth->ia_node_leave != NULL)
2294 1.75.4.1 phil vap->iv_auth->ia_node_leave(ni);
2295 1.75.4.1 phil if (vap->iv_aid_bitmap != NULL)
2296 1.75.4.1 phil IEEE80211_AID_CLR(vap, ni->ni_associd);
2297 1.75.4.1 phil }
2298 1.75.4.1 phil ni->ni_wdsvap = NULL; /* clear reference */
2299 1.75.4.1 phil node_reclaim(nt, ni);
2300 1.75.4.1 phil }
2301 1.75.4.1 phil if (match != NULL && match->iv_opmode == IEEE80211_M_WDS) {
2302 1.75.4.1 phil /*
2303 1.75.4.1 phil * Make a separate pass to clear references to this vap
2304 1.75.4.1 phil * held by DWDS entries. They will not be matched above
2305 1.75.4.1 phil * because ni_vap will point to the ap vap but we still
2306 1.75.4.1 phil * need to clear ni_wdsvap when the WDS vap is destroyed
2307 1.75.4.1 phil * and/or reset.
2308 1.75.4.1 phil */
2309 1.75.4.1 phil TAILQ_FOREACH_SAFE(ni, &nt->nt_node, ni_list, next)
2310 1.75.4.1 phil if (ni->ni_wdsvap == match)
2311 1.75.4.1 phil ni->ni_wdsvap = NULL;
2312 1.75.4.1 phil }
2313 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
2314 1.75.4.1 phil }
2315 1.75.4.1 phil
2316 1.75.4.1 phil static void
2317 1.75.4.1 phil ieee80211_node_table_cleanup(struct ieee80211_node_table *nt)
2318 1.75.4.1 phil {
2319 1.75.4.1 phil ieee80211_node_table_reset(nt, NULL);
2320 1.75.4.1 phil if (nt->nt_keyixmap != NULL) {
2321 1.75.4.1 phil #ifdef DIAGNOSTIC
2322 1.75.4.1 phil /* XXX verify all entries are NULL */
2323 1.75.4.1 phil int i;
2324 1.75.4.1 phil for (i = 0; i < nt->nt_keyixmax; i++)
2325 1.75.4.1 phil if (nt->nt_keyixmap[i] != NULL)
2326 1.75.4.1 phil printf("%s: %s[%u] still active\n", __func__,
2327 1.75.4.1 phil nt->nt_name, i);
2328 1.75.4.1 phil #endif
2329 1.75.4.1 phil IEEE80211_FREE(nt->nt_keyixmap, M_80211_NODE);
2330 1.75.4.1 phil nt->nt_keyixmap = NULL;
2331 1.75.4.1 phil }
2332 1.75.4.1 phil IEEE80211_NODE_LOCK_DESTROY(nt);
2333 1.75.4.1 phil }
2334 1.75.4.1 phil
2335 1.75.4.1 phil static void
2336 1.75.4.1 phil timeout_stations(void *arg __unused, struct ieee80211_node *ni)
2337 1.75.4.1 phil {
2338 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2339 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2340 1.75.4.1 phil
2341 1.75.4.1 phil /*
2342 1.75.4.1 phil * Only process stations when in RUN state. This
2343 1.75.4.1 phil * insures, for example, that we don't timeout an
2344 1.75.4.1 phil * inactive station during CAC. Note that CSA state
2345 1.75.4.1 phil * is actually handled in ieee80211_node_timeout as
2346 1.75.4.1 phil * it applies to more than timeout processing.
2347 1.75.4.1 phil */
2348 1.75.4.1 phil if (vap->iv_state != IEEE80211_S_RUN)
2349 1.75.4.1 phil return;
2350 1.75.4.1 phil /*
2351 1.75.4.1 phil * Ignore entries for which have yet to receive an
2352 1.75.4.1 phil * authentication frame. These are transient and
2353 1.75.4.1 phil * will be reclaimed when the last reference to them
2354 1.75.4.1 phil * goes away (when frame xmits complete).
2355 1.75.4.1 phil */
2356 1.75.4.1 phil if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
2357 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_STA) &&
2358 1.75.4.1 phil (ni->ni_flags & IEEE80211_NODE_AREF) == 0)
2359 1.75.4.1 phil return;
2360 1.75.4.1 phil /*
2361 1.75.4.1 phil * Free fragment if not needed anymore
2362 1.75.4.1 phil * (last fragment older than 1s).
2363 1.75.4.1 phil * XXX doesn't belong here, move to node_age
2364 1.75.4.1 phil */
2365 1.75.4.1 phil if (ni->ni_rxfrag[0] != NULL &&
2366 1.75.4.1 phil ticks > ni->ni_rxfragstamp + hz) {
2367 1.75.4.1 phil m_freem(ni->ni_rxfrag[0]);
2368 1.75.4.1 phil ni->ni_rxfrag[0] = NULL;
2369 1.75.4.1 phil }
2370 1.75.4.1 phil if (ni->ni_inact > 0) {
2371 1.75.4.1 phil ni->ni_inact--;
2372 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
2373 1.75.4.1 phil "%s: inact %u inact_reload %u nrates %u",
2374 1.75.4.1 phil __func__, ni->ni_inact, ni->ni_inact_reload,
2375 1.75.4.1 phil ni->ni_rates.rs_nrates);
2376 1.75.4.1 phil }
2377 1.75.4.1 phil /*
2378 1.75.4.1 phil * Special case ourself; we may be idle for extended periods
2379 1.75.4.1 phil * of time and regardless reclaiming our state is wrong.
2380 1.75.4.1 phil * XXX run ic_node_age
2381 1.75.4.1 phil */
2382 1.75.4.1 phil /* XXX before inact decrement? */
2383 1.75.4.1 phil if (ni == vap->iv_bss)
2384 1.75.4.1 phil return;
2385 1.75.4.1 phil if (ni->ni_associd != 0 ||
2386 1.75.4.1 phil (vap->iv_opmode == IEEE80211_M_IBSS ||
2387 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_AHDEMO)) {
2388 1.75.4.1 phil /*
2389 1.75.4.1 phil * Age/drain resources held by the station.
2390 1.75.4.1 phil */
2391 1.75.4.1 phil ic->ic_node_age(ni);
2392 1.75.4.1 phil /*
2393 1.75.4.1 phil * Probe the station before time it out. We
2394 1.75.4.1 phil * send a null data frame which may not be
2395 1.75.4.1 phil * universally supported by drivers (need it
2396 1.75.4.1 phil * for ps-poll support so it should be...).
2397 1.75.4.1 phil *
2398 1.75.4.1 phil * XXX don't probe the station unless we've
2399 1.75.4.1 phil * received a frame from them (and have
2400 1.75.4.1 phil * some idea of the rates they are capable
2401 1.75.4.1 phil * of); this will get fixed more properly
2402 1.75.4.1 phil * soon with better handling of the rate set.
2403 1.75.4.1 phil */
2404 1.75.4.1 phil if ((vap->iv_flags_ext & IEEE80211_FEXT_INACT) &&
2405 1.75.4.1 phil (0 < ni->ni_inact &&
2406 1.75.4.1 phil ni->ni_inact <= vap->iv_inact_probe) &&
2407 1.75.4.1 phil ni->ni_rates.rs_nrates != 0) {
2408 1.75.4.1 phil IEEE80211_NOTE(vap,
2409 1.75.4.1 phil IEEE80211_MSG_INACT | IEEE80211_MSG_NODE,
2410 1.75.4.1 phil ni, "%s",
2411 1.75.4.1 phil "probe station due to inactivity");
2412 1.75.4.1 phil /*
2413 1.75.4.1 phil * Grab a reference so the node cannot
2414 1.75.4.1 phil * be reclaimed before we send the frame.
2415 1.75.4.1 phil * ieee80211_send_nulldata understands
2416 1.75.4.1 phil * we've done this and reclaims the
2417 1.75.4.1 phil * ref for us as needed.
2418 1.75.4.1 phil */
2419 1.75.4.1 phil /* XXX fix this (not required anymore). */
2420 1.75.4.1 phil ieee80211_ref_node(ni);
2421 1.75.4.1 phil /* XXX useless */
2422 1.75.4.1 phil ieee80211_send_nulldata(ni);
2423 1.75.4.1 phil /* XXX stat? */
2424 1.75.4.1 phil return;
2425 1.75.4.1 phil }
2426 1.45 skrll }
2427 1.75.4.1 phil if ((vap->iv_flags_ext & IEEE80211_FEXT_INACT) &&
2428 1.75.4.1 phil ni->ni_inact <= 0) {
2429 1.75.4.1 phil IEEE80211_NOTE(vap,
2430 1.75.4.1 phil IEEE80211_MSG_INACT | IEEE80211_MSG_NODE, ni,
2431 1.75.4.1 phil "station timed out due to inactivity "
2432 1.75.4.1 phil "(refcnt %u)", ieee80211_node_refcnt(ni));
2433 1.39 dyoung /*
2434 1.75.4.1 phil * Send a deauthenticate frame and drop the station.
2435 1.75.4.1 phil * This is somewhat complicated due to reference counts
2436 1.75.4.1 phil * and locking. At this point a station will typically
2437 1.75.4.1 phil * have a reference count of 2. ieee80211_node_leave
2438 1.75.4.1 phil * will do a "free" of the node which will drop the
2439 1.75.4.1 phil * reference count. But in the meantime a reference
2440 1.75.4.1 phil * wil be held by the deauth frame. The actual reclaim
2441 1.75.4.1 phil * of the node will happen either after the tx is
2442 1.75.4.1 phil * completed or by ieee80211_node_leave.
2443 1.39 dyoung */
2444 1.39 dyoung if (ni->ni_associd != 0) {
2445 1.75.4.1 phil IEEE80211_SEND_MGMT(ni,
2446 1.75.4.1 phil IEEE80211_FC0_SUBTYPE_DEAUTH,
2447 1.75.4.1 phil IEEE80211_REASON_AUTH_EXPIRE);
2448 1.39 dyoung }
2449 1.75.4.1 phil ieee80211_node_leave(ni);
2450 1.75.4.1 phil vap->iv_stats.is_node_timeout++;
2451 1.1 dyoung }
2452 1.39 dyoung }
2453 1.39 dyoung
2454 1.39 dyoung /*
2455 1.75.4.1 phil * Timeout inactive stations and do related housekeeping.
2456 1.39 dyoung */
2457 1.39 dyoung static void
2458 1.75.4.1 phil ieee80211_timeout_stations(struct ieee80211com *ic)
2459 1.1 dyoung {
2460 1.75.4.1 phil struct ieee80211_node_table *nt = &ic->ic_sta;
2461 1.22 mycroft
2462 1.75.4.1 phil ieee80211_iterate_nodes(nt, timeout_stations, NULL);
2463 1.1 dyoung }
2464 1.1 dyoung
2465 1.9 dyoung /*
2466 1.75.4.1 phil * Aggressively reclaim resources. This should be used
2467 1.75.4.1 phil * only in a critical situation to reclaim mbuf resources.
2468 1.9 dyoung */
2469 1.75.4.1 phil void
2470 1.75.4.1 phil ieee80211_drain(struct ieee80211com *ic)
2471 1.1 dyoung {
2472 1.75.4.1 phil struct ieee80211_node_table *nt = &ic->ic_sta;
2473 1.75.4.1 phil struct ieee80211vap *vap;
2474 1.9 dyoung struct ieee80211_node *ni;
2475 1.66 christos
2476 1.39 dyoung IEEE80211_NODE_LOCK(nt);
2477 1.39 dyoung TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
2478 1.39 dyoung /*
2479 1.42 dyoung * Ignore entries for which have yet to receive an
2480 1.42 dyoung * authentication frame. These are transient and
2481 1.42 dyoung * will be reclaimed when the last reference to them
2482 1.42 dyoung * goes away (when frame xmits complete).
2483 1.42 dyoung */
2484 1.75.4.1 phil vap = ni->ni_vap;
2485 1.75.4.1 phil /*
2486 1.75.4.1 phil * Only process stations when in RUN state. This
2487 1.75.4.1 phil * insures, for example, that we don't timeout an
2488 1.75.4.1 phil * inactive station during CAC. Note that CSA state
2489 1.75.4.1 phil * is actually handled in ieee80211_node_timeout as
2490 1.75.4.1 phil * it applies to more than timeout processing.
2491 1.75.4.1 phil */
2492 1.75.4.1 phil if (vap->iv_state != IEEE80211_S_RUN)
2493 1.75.4.1 phil continue;
2494 1.75.4.1 phil /* XXX can vap be NULL? */
2495 1.75.4.1 phil if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
2496 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_STA) &&
2497 1.45 skrll (ni->ni_flags & IEEE80211_NODE_AREF) == 0)
2498 1.42 dyoung continue;
2499 1.42 dyoung /*
2500 1.75.4.1 phil * Free fragments.
2501 1.75.4.1 phil * XXX doesn't belong here, move to node_drain
2502 1.39 dyoung */
2503 1.75.4.1 phil if (ni->ni_rxfrag[0] != NULL) {
2504 1.39 dyoung m_freem(ni->ni_rxfrag[0]);
2505 1.39 dyoung ni->ni_rxfrag[0] = NULL;
2506 1.39 dyoung }
2507 1.39 dyoung /*
2508 1.75.4.1 phil * Drain resources held by the station.
2509 1.39 dyoung */
2510 1.75.4.1 phil ic->ic_node_drain(ni);
2511 1.1 dyoung }
2512 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
2513 1.1 dyoung }
2514 1.1 dyoung
2515 1.75.4.1 phil /*
2516 1.75.4.1 phil * Per-ieee80211com inactivity timer callback.
2517 1.75.4.1 phil */
2518 1.1 dyoung void
2519 1.75.4.1 phil ieee80211_node_timeout(void *arg)
2520 1.1 dyoung {
2521 1.75.4.1 phil struct ieee80211com *ic = arg;
2522 1.39 dyoung
2523 1.75.4.1 phil /*
2524 1.75.4.1 phil * Defer timeout processing if a channel switch is pending.
2525 1.75.4.1 phil * We typically need to be mute so not doing things that
2526 1.75.4.1 phil * might generate frames is good to handle in one place.
2527 1.75.4.1 phil * Suppressing the station timeout processing may extend the
2528 1.75.4.1 phil * lifetime of inactive stations (by not decrementing their
2529 1.75.4.1 phil * idle counters) but this should be ok unless the CSA is
2530 1.75.4.1 phil * active for an unusually long time.
2531 1.75.4.1 phil */
2532 1.75.4.1 phil if ((ic->ic_flags & IEEE80211_F_CSAPENDING) == 0) {
2533 1.75.4.1 phil ieee80211_scan_timeout(ic);
2534 1.75.4.1 phil ieee80211_timeout_stations(ic);
2535 1.75.4.1 phil ieee80211_ageq_age(&ic->ic_stageq, IEEE80211_INACT_WAIT);
2536 1.75.4.1 phil
2537 1.75.4.1 phil IEEE80211_LOCK(ic);
2538 1.75.4.1 phil ieee80211_erp_timeout(ic);
2539 1.75.4.1 phil ieee80211_ht_timeout(ic);
2540 1.75.4.1 phil ieee80211_vht_timeout(ic);
2541 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2542 1.66 christos }
2543 1.75.4.1 phil callout_reset(&ic->ic_inact, IEEE80211_INACT_WAIT*hz,
2544 1.75.4.1 phil ieee80211_node_timeout, ic);
2545 1.75.4.1 phil }
2546 1.75.4.1 phil
2547 1.75.4.1 phil /*
2548 1.75.4.1 phil * The same as ieee80211_iterate_nodes(), but for one vap only.
2549 1.75.4.1 phil */
2550 1.75.4.1 phil int
2551 1.75.4.1 phil ieee80211_iterate_nodes_vap(struct ieee80211_node_table *nt,
2552 1.75.4.1 phil struct ieee80211vap *vap, ieee80211_iter_func *f, void *arg)
2553 1.75.4.1 phil {
2554 1.75.4.1 phil struct ieee80211_node **ni_arr;
2555 1.75.4.1 phil struct ieee80211_node *ni;
2556 1.75.4.1 phil size_t size;
2557 1.75.4.1 phil int count, i;
2558 1.66 christos
2559 1.75.4.1 phil /*
2560 1.75.4.1 phil * Iterate over the node table and save an array of ref'ed nodes.
2561 1.75.4.1 phil *
2562 1.75.4.1 phil * This is separated out from calling the actual node function so that
2563 1.75.4.1 phil * no LORs will occur.
2564 1.75.4.1 phil */
2565 1.39 dyoung IEEE80211_NODE_LOCK(nt);
2566 1.75.4.1 phil count = nt->nt_count;
2567 1.75.4.1 phil size = count * sizeof(struct ieee80211_node *);
2568 1.75.4.1 phil ni_arr = (struct ieee80211_node **) IEEE80211_MALLOC(size, M_80211_NODE,
2569 1.75.4.1 phil IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
2570 1.75.4.1 phil if (ni_arr == NULL) {
2571 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
2572 1.75.4.1 phil return (ENOMEM);
2573 1.75.4.1 phil }
2574 1.75.4.1 phil
2575 1.75.4.1 phil i = 0;
2576 1.39 dyoung TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
2577 1.75.4.1 phil if (vap != NULL && ni->ni_vap != vap)
2578 1.75.4.1 phil continue;
2579 1.75.4.1 phil KASSERT(i < count,
2580 1.75.4.1 phil ("node array overflow (vap %p, i %d, count %d)\n",
2581 1.75.4.1 phil vap, i, count));
2582 1.75.4.1 phil ni_arr[i] = ieee80211_ref_node(ni);
2583 1.75.4.1 phil i++;
2584 1.39 dyoung }
2585 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
2586 1.75.4.1 phil
2587 1.75.4.1 phil for (i = 0; i < count; i++) {
2588 1.75.4.1 phil if (ni_arr[i] == NULL) /* end of the list */
2589 1.75.4.1 phil break;
2590 1.75.4.1 phil (*f)(arg, ni_arr[i]);
2591 1.75.4.1 phil /* ieee80211_free_node() locks by itself */
2592 1.75.4.1 phil ieee80211_free_node(ni_arr[i]);
2593 1.75.4.1 phil }
2594 1.75.4.1 phil
2595 1.75.4.1 phil IEEE80211_FREE(ni_arr, M_80211_NODE);
2596 1.75.4.1 phil
2597 1.75.4.1 phil return (0);
2598 1.39 dyoung }
2599 1.39 dyoung
2600 1.75.4.1 phil /*
2601 1.75.4.1 phil * Just a wrapper, so we don't have to change every ieee80211_iterate_nodes()
2602 1.75.4.1 phil * reference in the source.
2603 1.75.4.1 phil */
2604 1.39 dyoung void
2605 1.75.4.1 phil ieee80211_iterate_nodes(struct ieee80211_node_table *nt,
2606 1.75.4.1 phil ieee80211_iter_func *f, void *arg)
2607 1.75.4.1 phil {
2608 1.75.4.1 phil /* XXX no way to pass error to the caller. */
2609 1.75.4.1 phil (void) ieee80211_iterate_nodes_vap(nt, NULL, f, arg);
2610 1.75.4.1 phil }
2611 1.75.4.1 phil
2612 1.75.4.1 phil void
2613 1.75.4.1 phil ieee80211_dump_node(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
2614 1.39 dyoung {
2615 1.39 dyoung printf("0x%p: mac %s refcnt %d\n", ni,
2616 1.39 dyoung ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni));
2617 1.75.4.1 phil printf("\tauthmode %u flags 0x%x\n",
2618 1.75.4.1 phil ni->ni_authmode, ni->ni_flags);
2619 1.39 dyoung printf("\tassocid 0x%x txpower %u vlan %u\n",
2620 1.39 dyoung ni->ni_associd, ni->ni_txpower, ni->ni_vlan);
2621 1.39 dyoung printf("\ttxseq %u rxseq %u fragno %u rxfragstamp %u\n",
2622 1.75.4.1 phil ni->ni_txseqs[IEEE80211_NONQOS_TID],
2623 1.75.4.1 phil ni->ni_rxseqs[IEEE80211_NONQOS_TID] >> IEEE80211_SEQ_SEQ_SHIFT,
2624 1.75.4.1 phil ni->ni_rxseqs[IEEE80211_NONQOS_TID] & IEEE80211_SEQ_FRAG_MASK,
2625 1.39 dyoung ni->ni_rxfragstamp);
2626 1.75.4.1 phil printf("\trssi %d noise %d intval %u capinfo 0x%x\n",
2627 1.75.4.1 phil node_getrssi(ni), ni->ni_noise,
2628 1.75.4.1 phil ni->ni_intval, ni->ni_capinfo);
2629 1.39 dyoung printf("\tbssid %s essid \"%.*s\" channel %u:0x%x\n",
2630 1.39 dyoung ether_sprintf(ni->ni_bssid),
2631 1.39 dyoung ni->ni_esslen, ni->ni_essid,
2632 1.39 dyoung ni->ni_chan->ic_freq, ni->ni_chan->ic_flags);
2633 1.75.4.1 phil printf("\tinact %u inact_reload %u txrate %u\n",
2634 1.75.4.1 phil ni->ni_inact, ni->ni_inact_reload, ni->ni_txrate);
2635 1.75.4.1 phil printf("\thtcap %x htparam %x htctlchan %u ht2ndchan %u\n",
2636 1.75.4.1 phil ni->ni_htcap, ni->ni_htparam,
2637 1.75.4.1 phil ni->ni_htctlchan, ni->ni_ht2ndchan);
2638 1.75.4.1 phil printf("\thtopmode %x htstbc %x htchw %u\n",
2639 1.75.4.1 phil ni->ni_htopmode, ni->ni_htstbc, ni->ni_chw);
2640 1.75.4.1 phil printf("\tvhtcap %x freq1 %d freq2 %d vhtbasicmcs %x\n",
2641 1.75.4.1 phil ni->ni_vhtcap, (int) ni->ni_vht_chan1, (int) ni->ni_vht_chan2,
2642 1.75.4.1 phil (int) ni->ni_vht_basicmcs);
2643 1.75.4.1 phil /* XXX VHT state */
2644 1.39 dyoung }
2645 1.39 dyoung
2646 1.39 dyoung void
2647 1.39 dyoung ieee80211_dump_nodes(struct ieee80211_node_table *nt)
2648 1.39 dyoung {
2649 1.39 dyoung ieee80211_iterate_nodes(nt,
2650 1.39 dyoung (ieee80211_iter_func *) ieee80211_dump_node, nt);
2651 1.39 dyoung }
2652 1.39 dyoung
2653 1.75.4.1 phil static void
2654 1.75.4.1 phil ieee80211_notify_erp_locked(struct ieee80211com *ic)
2655 1.75.4.1 phil {
2656 1.75.4.1 phil struct ieee80211vap *vap;
2657 1.75.4.1 phil
2658 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2659 1.75.4.1 phil
2660 1.75.4.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
2661 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_HOSTAP)
2662 1.75.4.1 phil ieee80211_beacon_notify(vap, IEEE80211_BEACON_ERP);
2663 1.75.4.1 phil }
2664 1.75.4.1 phil
2665 1.75.4.1 phil void
2666 1.75.4.1 phil ieee80211_notify_erp(struct ieee80211com *ic)
2667 1.75.4.1 phil {
2668 1.75.4.1 phil IEEE80211_LOCK(ic);
2669 1.75.4.1 phil ieee80211_notify_erp_locked(ic);
2670 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2671 1.75.4.1 phil }
2672 1.75.4.1 phil
2673 1.39 dyoung /*
2674 1.39 dyoung * Handle a station joining an 11g network.
2675 1.39 dyoung */
2676 1.39 dyoung static void
2677 1.75.4.1 phil ieee80211_node_join_11g(struct ieee80211_node *ni)
2678 1.39 dyoung {
2679 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2680 1.75.4.1 phil
2681 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2682 1.1 dyoung
2683 1.39 dyoung /*
2684 1.39 dyoung * Station isn't capable of short slot time. Bump
2685 1.39 dyoung * the count of long slot time stations and disable
2686 1.39 dyoung * use of short slot time. Note that the actual switch
2687 1.39 dyoung * over to long slot time use may not occur until the
2688 1.39 dyoung * next beacon transmission (per sec. 7.3.1.4 of 11g).
2689 1.39 dyoung */
2690 1.39 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) {
2691 1.39 dyoung ic->ic_longslotsta++;
2692 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2693 1.75.4.1 phil "station needs long slot time, count %d",
2694 1.75.4.1 phil ic->ic_longslotsta);
2695 1.39 dyoung /* XXX vap's w/ conflicting needs won't work */
2696 1.75.4.1 phil if (!IEEE80211_IS_CHAN_108G(ic->ic_bsschan)) {
2697 1.75.4.1 phil /*
2698 1.75.4.1 phil * Don't force slot time when switched to turbo
2699 1.75.4.1 phil * mode as non-ERP stations won't be present; this
2700 1.75.4.1 phil * need only be done when on the normal G channel.
2701 1.75.4.1 phil */
2702 1.75.4.1 phil ieee80211_set_shortslottime(ic, 0);
2703 1.75.4.1 phil }
2704 1.39 dyoung }
2705 1.39 dyoung /*
2706 1.39 dyoung * If the new station is not an ERP station
2707 1.39 dyoung * then bump the counter and enable protection
2708 1.39 dyoung * if configured.
2709 1.39 dyoung */
2710 1.75.4.1 phil if (!ieee80211_iserp_rateset(&ni->ni_rates)) {
2711 1.39 dyoung ic->ic_nonerpsta++;
2712 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2713 1.75.4.1 phil "station is !ERP, %d non-ERP stations associated",
2714 1.75.4.1 phil ic->ic_nonerpsta);
2715 1.39 dyoung /*
2716 1.39 dyoung * If station does not support short preamble
2717 1.39 dyoung * then we must enable use of Barker preamble.
2718 1.39 dyoung */
2719 1.39 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE) == 0) {
2720 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2721 1.75.4.1 phil "%s", "station needs long preamble");
2722 1.39 dyoung ic->ic_flags |= IEEE80211_F_USEBARKER;
2723 1.39 dyoung ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
2724 1.39 dyoung }
2725 1.75.4.1 phil /*
2726 1.75.4.1 phil * If protection is configured and this is the first
2727 1.75.4.1 phil * indication we should use protection, enable it.
2728 1.75.4.1 phil */
2729 1.75.4.1 phil if (ic->ic_protmode != IEEE80211_PROT_NONE &&
2730 1.75.4.1 phil ic->ic_nonerpsta == 1 &&
2731 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0) {
2732 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
2733 1.75.4.1 phil "%s: enable use of protection\n", __func__);
2734 1.75.4.1 phil ic->ic_flags |= IEEE80211_F_USEPROT;
2735 1.75.4.1 phil ieee80211_notify_erp_locked(ic);
2736 1.75.4.1 phil }
2737 1.75.4.1 phil } else
2738 1.39 dyoung ni->ni_flags |= IEEE80211_NODE_ERP;
2739 1.1 dyoung }
2740 1.22 mycroft
2741 1.22 mycroft void
2742 1.75.4.1 phil ieee80211_node_join(struct ieee80211_node *ni, int resp)
2743 1.22 mycroft {
2744 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2745 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2746 1.22 mycroft int newassoc;
2747 1.22 mycroft
2748 1.22 mycroft if (ni->ni_associd == 0) {
2749 1.75.4.1 phil uint16_t aid;
2750 1.22 mycroft
2751 1.75.4.1 phil KASSERT(vap->iv_aid_bitmap != NULL, ("no aid bitmap"));
2752 1.22 mycroft /*
2753 1.39 dyoung * It would be good to search the bitmap
2754 1.22 mycroft * more efficiently, but this will do for now.
2755 1.22 mycroft */
2756 1.75.4.1 phil for (aid = 1; aid < vap->iv_max_aid; aid++) {
2757 1.75.4.1 phil if (!IEEE80211_AID_ISSET(vap, aid))
2758 1.22 mycroft break;
2759 1.22 mycroft }
2760 1.75.4.1 phil if (aid >= vap->iv_max_aid) {
2761 1.75.4.1 phil IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_TOOMANY);
2762 1.75.4.1 phil ieee80211_node_leave(ni);
2763 1.22 mycroft return;
2764 1.22 mycroft }
2765 1.22 mycroft ni->ni_associd = aid | 0xc000;
2766 1.75.4.1 phil ni->ni_jointime = time_uptime;
2767 1.75.4.1 phil IEEE80211_LOCK(ic);
2768 1.75.4.1 phil IEEE80211_AID_SET(vap, ni->ni_associd);
2769 1.75.4.1 phil vap->iv_sta_assoc++;
2770 1.39 dyoung ic->ic_sta_assoc++;
2771 1.75.4.1 phil
2772 1.75.4.1 phil if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan))
2773 1.75.4.1 phil ieee80211_ht_node_join(ni);
2774 1.75.4.1 phil if (IEEE80211_IS_CHAN_VHT(ic->ic_bsschan))
2775 1.75.4.1 phil ieee80211_vht_node_join(ni);
2776 1.75.4.1 phil if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2777 1.75.4.1 phil IEEE80211_IS_CHAN_FULL(ic->ic_bsschan))
2778 1.75.4.1 phil ieee80211_node_join_11g(ni);
2779 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2780 1.75.4.1 phil
2781 1.22 mycroft newassoc = 1;
2782 1.22 mycroft } else
2783 1.22 mycroft newassoc = 0;
2784 1.22 mycroft
2785 1.75.4.1 phil /*
2786 1.75.4.1 phil * XXX VHT - should log VHT channel width, etc
2787 1.75.4.1 phil */
2788 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, ni,
2789 1.75.4.1 phil "station associated at aid %d: %s preamble, %s slot time%s%s%s%s%s%s%s%s",
2790 1.39 dyoung IEEE80211_NODE_AID(ni),
2791 1.39 dyoung ic->ic_flags & IEEE80211_F_SHPREAMBLE ? "short" : "long",
2792 1.39 dyoung ic->ic_flags & IEEE80211_F_SHSLOT ? "short" : "long",
2793 1.39 dyoung ic->ic_flags & IEEE80211_F_USEPROT ? ", protection" : "",
2794 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_QOS ? ", QoS" : "",
2795 1.75.4.1 phil /* XXX update for VHT string */
2796 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_HT ?
2797 1.75.4.1 phil (ni->ni_chw == 40 ? ", HT40" : ", HT20") : "",
2798 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_AMPDU ? " (+AMPDU)" : "",
2799 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_MIMO_RTS ? " (+SMPS-DYN)" :
2800 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_MIMO_PS ? " (+SMPS)" : "",
2801 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_RIFS ? " (+RIFS)" : "",
2802 1.75.4.1 phil IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF) ?
2803 1.75.4.1 phil ", fast-frames" : "",
2804 1.75.4.1 phil IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_TURBOP) ?
2805 1.75.4.1 phil ", turbo" : ""
2806 1.39 dyoung );
2807 1.22 mycroft
2808 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
2809 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
2810 1.22 mycroft /* give driver a chance to setup state like ni_txrate */
2811 1.39 dyoung if (ic->ic_newassoc != NULL)
2812 1.45 skrll ic->ic_newassoc(ni, newassoc);
2813 1.75.4.1 phil IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_SUCCESS);
2814 1.39 dyoung /* tell the authenticator about new station */
2815 1.75.4.1 phil if (vap->iv_auth->ia_node_join != NULL)
2816 1.75.4.1 phil vap->iv_auth->ia_node_join(ni);
2817 1.75.4.1 phil ieee80211_notify_node_join(ni,
2818 1.75.4.1 phil resp == IEEE80211_FC0_SUBTYPE_ASSOC_RESP);
2819 1.75.4.1 phil }
2820 1.75.4.1 phil
2821 1.75.4.1 phil static void
2822 1.75.4.1 phil disable_protection(struct ieee80211com *ic)
2823 1.75.4.1 phil {
2824 1.75.4.1 phil KASSERT(ic->ic_nonerpsta == 0 &&
2825 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0,
2826 1.75.4.1 phil ("%d non ERP stations, flags 0x%x", ic->ic_nonerpsta,
2827 1.75.4.1 phil ic->ic_flags_ext));
2828 1.75.4.1 phil
2829 1.75.4.1 phil ic->ic_flags &= ~IEEE80211_F_USEPROT;
2830 1.75.4.1 phil /* XXX verify mode? */
2831 1.75.4.1 phil if (ic->ic_caps & IEEE80211_C_SHPREAMBLE) {
2832 1.75.4.1 phil ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
2833 1.75.4.1 phil ic->ic_flags &= ~IEEE80211_F_USEBARKER;
2834 1.75.4.1 phil }
2835 1.75.4.1 phil ieee80211_notify_erp_locked(ic);
2836 1.39 dyoung }
2837 1.39 dyoung
2838 1.39 dyoung /*
2839 1.39 dyoung * Handle a station leaving an 11g network.
2840 1.39 dyoung */
2841 1.39 dyoung static void
2842 1.75.4.1 phil ieee80211_node_leave_11g(struct ieee80211_node *ni)
2843 1.39 dyoung {
2844 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2845 1.75.4.1 phil
2846 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2847 1.39 dyoung
2848 1.75.4.1 phil KASSERT(IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan),
2849 1.75.4.1 phil ("not in 11g, bss %u:0x%x", ic->ic_bsschan->ic_freq,
2850 1.75.4.1 phil ic->ic_bsschan->ic_flags));
2851 1.39 dyoung
2852 1.39 dyoung /*
2853 1.39 dyoung * If a long slot station do the slot time bookkeeping.
2854 1.39 dyoung */
2855 1.39 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) {
2856 1.75.4.1 phil KASSERT(ic->ic_longslotsta > 0,
2857 1.39 dyoung ("bogus long slot station count %d", ic->ic_longslotsta));
2858 1.39 dyoung ic->ic_longslotsta--;
2859 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2860 1.75.4.1 phil "long slot time station leaves, count now %d",
2861 1.75.4.1 phil ic->ic_longslotsta);
2862 1.39 dyoung if (ic->ic_longslotsta == 0) {
2863 1.39 dyoung /*
2864 1.39 dyoung * Re-enable use of short slot time if supported
2865 1.39 dyoung * and not operating in IBSS mode (per spec).
2866 1.39 dyoung */
2867 1.39 dyoung if ((ic->ic_caps & IEEE80211_C_SHSLOT) &&
2868 1.39 dyoung ic->ic_opmode != IEEE80211_M_IBSS) {
2869 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap,
2870 1.75.4.1 phil IEEE80211_MSG_ASSOC,
2871 1.39 dyoung "%s: re-enable use of short slot time\n",
2872 1.39 dyoung __func__);
2873 1.39 dyoung ieee80211_set_shortslottime(ic, 1);
2874 1.39 dyoung }
2875 1.39 dyoung }
2876 1.39 dyoung }
2877 1.39 dyoung /*
2878 1.39 dyoung * If a non-ERP station do the protection-related bookkeeping.
2879 1.39 dyoung */
2880 1.39 dyoung if ((ni->ni_flags & IEEE80211_NODE_ERP) == 0) {
2881 1.75.4.1 phil KASSERT(ic->ic_nonerpsta > 0,
2882 1.39 dyoung ("bogus non-ERP station count %d", ic->ic_nonerpsta));
2883 1.39 dyoung ic->ic_nonerpsta--;
2884 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2885 1.75.4.1 phil "non-ERP station leaves, count now %d%s", ic->ic_nonerpsta,
2886 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) ?
2887 1.75.4.1 phil " (non-ERP sta present)" : "");
2888 1.75.4.1 phil if (ic->ic_nonerpsta == 0 &&
2889 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0) {
2890 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
2891 1.39 dyoung "%s: disable use of protection\n", __func__);
2892 1.75.4.1 phil disable_protection(ic);
2893 1.39 dyoung }
2894 1.39 dyoung }
2895 1.22 mycroft }
2896 1.22 mycroft
2897 1.22 mycroft /*
2898 1.75.4.1 phil * Time out presence of an overlapping bss with non-ERP
2899 1.75.4.1 phil * stations. When operating in hostap mode we listen for
2900 1.75.4.1 phil * beacons from other stations and if we identify a non-ERP
2901 1.75.4.1 phil * station is present we enable protection. To identify
2902 1.75.4.1 phil * when all non-ERP stations are gone we time out this
2903 1.75.4.1 phil * condition.
2904 1.75.4.1 phil */
2905 1.75.4.1 phil static void
2906 1.75.4.1 phil ieee80211_erp_timeout(struct ieee80211com *ic)
2907 1.75.4.1 phil {
2908 1.75.4.1 phil
2909 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2910 1.75.4.1 phil
2911 1.75.4.1 phil if ((ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) &&
2912 1.75.4.1 phil ieee80211_time_after(ticks, ic->ic_lastnonerp + IEEE80211_NONERP_PRESENT_AGE)) {
2913 1.75.4.1 phil #if 0
2914 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
2915 1.75.4.1 phil "%s", "age out non-ERP sta present on channel");
2916 1.75.4.1 phil #endif
2917 1.75.4.1 phil ic->ic_flags_ext &= ~IEEE80211_FEXT_NONERP_PR;
2918 1.75.4.1 phil if (ic->ic_nonerpsta == 0)
2919 1.75.4.1 phil disable_protection(ic);
2920 1.75.4.1 phil }
2921 1.75.4.1 phil }
2922 1.75.4.1 phil
2923 1.75.4.1 phil /*
2924 1.26 dyoung * Handle bookkeeping for station deauthentication/disassociation
2925 1.26 dyoung * when operating as an ap.
2926 1.22 mycroft */
2927 1.22 mycroft void
2928 1.75.4.1 phil ieee80211_node_leave(struct ieee80211_node *ni)
2929 1.22 mycroft {
2930 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2931 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2932 1.39 dyoung struct ieee80211_node_table *nt = ni->ni_table;
2933 1.39 dyoung
2934 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, ni,
2935 1.75.4.1 phil "station with aid %d leaves", IEEE80211_NODE_AID(ni));
2936 1.75 maxv
2937 1.75.4.1 phil KASSERT(vap->iv_opmode != IEEE80211_M_STA,
2938 1.75.4.1 phil ("unexpected operating mode %u", vap->iv_opmode));
2939 1.22 mycroft /*
2940 1.22 mycroft * If node wasn't previously associated all
2941 1.22 mycroft * we need to do is reclaim the reference.
2942 1.22 mycroft */
2943 1.39 dyoung /* XXX ibss mode bypasses 11g and notification */
2944 1.22 mycroft if (ni->ni_associd == 0)
2945 1.39 dyoung goto done;
2946 1.39 dyoung /*
2947 1.39 dyoung * Tell the authenticator the station is leaving.
2948 1.39 dyoung * Note that we must do this before yanking the
2949 1.39 dyoung * association id as the authenticator uses the
2950 1.75.4.1 phil * associd to locate it's state block.
2951 1.39 dyoung */
2952 1.75.4.1 phil if (vap->iv_auth->ia_node_leave != NULL)
2953 1.75.4.1 phil vap->iv_auth->ia_node_leave(ni);
2954 1.39 dyoung
2955 1.75.4.1 phil IEEE80211_LOCK(ic);
2956 1.75.4.1 phil IEEE80211_AID_CLR(vap, ni->ni_associd);
2957 1.75.4.1 phil vap->iv_sta_assoc--;
2958 1.75.4.1 phil ic->ic_sta_assoc--;
2959 1.75 maxv
2960 1.75.4.1 phil if (IEEE80211_IS_CHAN_VHT(ic->ic_bsschan))
2961 1.75.4.1 phil ieee80211_vht_node_leave(ni);
2962 1.75.4.1 phil if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan))
2963 1.75.4.1 phil ieee80211_ht_node_leave(ni);
2964 1.75.4.1 phil if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2965 1.75.4.1 phil IEEE80211_IS_CHAN_FULL(ic->ic_bsschan))
2966 1.75.4.1 phil ieee80211_node_leave_11g(ni);
2967 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2968 1.39 dyoung /*
2969 1.39 dyoung * Cleanup station state. In particular clear various
2970 1.39 dyoung * state that might otherwise be reused if the node
2971 1.39 dyoung * is reused before the reference count goes to zero
2972 1.39 dyoung * (and memory is reclaimed).
2973 1.39 dyoung */
2974 1.75.4.1 phil ieee80211_sta_leave(ni);
2975 1.39 dyoung done:
2976 1.39 dyoung /*
2977 1.39 dyoung * Remove the node from any table it's recorded in and
2978 1.39 dyoung * drop the caller's reference. Removal from the table
2979 1.39 dyoung * is important to insure the node is not reprocessed
2980 1.39 dyoung * for inactivity.
2981 1.39 dyoung */
2982 1.39 dyoung if (nt != NULL) {
2983 1.39 dyoung IEEE80211_NODE_LOCK(nt);
2984 1.39 dyoung node_reclaim(nt, ni);
2985 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
2986 1.39 dyoung } else
2987 1.39 dyoung ieee80211_free_node(ni);
2988 1.39 dyoung }
2989 1.39 dyoung
2990 1.75.4.1 phil struct rssiinfo {
2991 1.75.4.1 phil int rssi_samples;
2992 1.75.4.1 phil uint32_t rssi_total;
2993 1.75.4.1 phil };
2994 1.75.4.1 phil
2995 1.75.4.1 phil static void
2996 1.75.4.1 phil get_hostap_rssi(void *arg, struct ieee80211_node *ni)
2997 1.39 dyoung {
2998 1.75.4.1 phil struct rssiinfo *info = arg;
2999 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
3000 1.75.4.1 phil int8_t rssi;
3001 1.39 dyoung
3002 1.75.4.1 phil /* only associated stations */
3003 1.75.4.1 phil if (ni->ni_associd == 0)
3004 1.75.4.1 phil return;
3005 1.75.4.1 phil rssi = vap->iv_ic->ic_node_getrssi(ni);
3006 1.75.4.1 phil if (rssi != 0) {
3007 1.75.4.1 phil info->rssi_samples++;
3008 1.75.4.1 phil info->rssi_total += rssi;
3009 1.39 dyoung }
3010 1.39 dyoung }
3011 1.39 dyoung
3012 1.39 dyoung static void
3013 1.75.4.1 phil get_adhoc_rssi(void *arg, struct ieee80211_node *ni)
3014 1.39 dyoung {
3015 1.75.4.1 phil struct rssiinfo *info = arg;
3016 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
3017 1.75.4.1 phil int8_t rssi;
3018 1.75.4.1 phil
3019 1.75.4.1 phil /* only neighbors */
3020 1.75.4.1 phil /* XXX check bssid */
3021 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
3022 1.75.4.1 phil return;
3023 1.75.4.1 phil rssi = vap->iv_ic->ic_node_getrssi(ni);
3024 1.75.4.1 phil if (rssi != 0) {
3025 1.75.4.1 phil info->rssi_samples++;
3026 1.75.4.1 phil info->rssi_total += rssi;
3027 1.39 dyoung }
3028 1.39 dyoung }
3029 1.39 dyoung
3030 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
3031 1.39 dyoung static void
3032 1.75.4.1 phil get_mesh_rssi(void *arg, struct ieee80211_node *ni)
3033 1.39 dyoung {
3034 1.75.4.1 phil struct rssiinfo *info = arg;
3035 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
3036 1.75.4.1 phil int8_t rssi;
3037 1.39 dyoung
3038 1.75.4.1 phil /* only neighbors that peered successfully */
3039 1.75.4.1 phil if (ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED)
3040 1.75.4.1 phil return;
3041 1.75.4.1 phil rssi = vap->iv_ic->ic_node_getrssi(ni);
3042 1.75.4.1 phil if (rssi != 0) {
3043 1.75.4.1 phil info->rssi_samples++;
3044 1.75.4.1 phil info->rssi_total += rssi;
3045 1.75.4.1 phil }
3046 1.39 dyoung }
3047 1.75.4.1 phil #endif /* IEEE80211_SUPPORT_MESH */
3048 1.39 dyoung
3049 1.75.4.1 phil int8_t
3050 1.75.4.1 phil ieee80211_getrssi(struct ieee80211vap *vap)
3051 1.39 dyoung {
3052 1.75.4.1 phil #define NZ(x) ((x) == 0 ? 1 : (x))
3053 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
3054 1.75.4.1 phil struct rssiinfo info;
3055 1.39 dyoung
3056 1.75.4.1 phil info.rssi_total = 0;
3057 1.75.4.1 phil info.rssi_samples = 0;
3058 1.75.4.1 phil switch (vap->iv_opmode) {
3059 1.75.4.1 phil case IEEE80211_M_IBSS: /* average of all ibss neighbors */
3060 1.75.4.1 phil case IEEE80211_M_AHDEMO: /* average of all neighbors */
3061 1.75.4.1 phil ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_adhoc_rssi,
3062 1.75.4.1 phil &info);
3063 1.75.4.1 phil break;
3064 1.75.4.1 phil case IEEE80211_M_HOSTAP: /* average of all associated stations */
3065 1.75.4.1 phil ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_hostap_rssi,
3066 1.75.4.1 phil &info);
3067 1.75.4.1 phil break;
3068 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
3069 1.75.4.1 phil case IEEE80211_M_MBSS: /* average of all mesh neighbors */
3070 1.75.4.1 phil ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_mesh_rssi,
3071 1.75.4.1 phil &info);
3072 1.75.4.1 phil break;
3073 1.75.4.1 phil #endif
3074 1.75.4.1 phil case IEEE80211_M_MONITOR: /* XXX */
3075 1.75.4.1 phil case IEEE80211_M_STA: /* use stats from associated ap */
3076 1.75.4.1 phil default:
3077 1.75.4.1 phil if (vap->iv_bss != NULL)
3078 1.75.4.1 phil info.rssi_total = ic->ic_node_getrssi(vap->iv_bss);
3079 1.75.4.1 phil info.rssi_samples = 1;
3080 1.75.4.1 phil break;
3081 1.75.4.1 phil }
3082 1.75.4.1 phil return info.rssi_total / NZ(info.rssi_samples);
3083 1.75.4.1 phil #undef NZ
3084 1.39 dyoung }
3085 1.39 dyoung
3086 1.75.4.1 phil void
3087 1.75.4.1 phil ieee80211_getsignal(struct ieee80211vap *vap, int8_t *rssi, int8_t *noise)
3088 1.39 dyoung {
3089 1.39 dyoung
3090 1.75.4.1 phil if (vap->iv_bss == NULL) /* NB: shouldn't happen */
3091 1.75.4.1 phil return;
3092 1.75.4.1 phil vap->iv_ic->ic_node_getsignal(vap->iv_bss, rssi, noise);
3093 1.75.4.1 phil /* for non-station mode return avg'd rssi accounting */
3094 1.75.4.1 phil if (vap->iv_opmode != IEEE80211_M_STA)
3095 1.75.4.1 phil *rssi = ieee80211_getrssi(vap);
3096 1.22 mycroft }
3097