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