ieee80211_node.c revision 1.75.4.3 1 1.75.4.3 phil /* $NetBSD: ieee80211_node.c,v 1.75.4.3 2018/07/16 20:11:11 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.3 phil printf ("reset_bss: vap is 0x%lx\n", (unsigned long) vap);
468 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
469 1.39 dyoung struct ieee80211_node *ni, *obss;
470 1.39 dyoung
471 1.75.4.3 phil printf ("reset_bss: ic is 0x%lx\n", (unsigned long) ic);
472 1.75.4.3 phil
473 1.75.4.1 phil ieee80211_node_table_reset(&ic->ic_sta, vap);
474 1.75.4.3 phil
475 1.75.4.3 phil printf ("reset_bss: after table_reset\n");
476 1.75.4.1 phil /* XXX multi-bss: wrong */
477 1.75.4.1 phil ieee80211_reset_erp(ic);
478 1.39 dyoung
479 1.75.4.3 phil printf ("reset_bss: after reset_erp\n");
480 1.75.4.3 phil
481 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr);
482 1.75.4.1 phil KASSERT(ni != NULL, ("unable to setup initial BSS node"));
483 1.75.4.3 phil
484 1.75.4.3 phil printf ("reset_bss: after alloc_node\n");
485 1.75.4.3 phil
486 1.75.4.1 phil obss = vap->iv_bss;
487 1.75.4.3 phil printf ("reset_bss: obss is 0x%lx\n", (unsigned long int)obss);
488 1.75.4.1 phil vap->iv_bss = ieee80211_ref_node(ni);
489 1.39 dyoung if (obss != NULL) {
490 1.39 dyoung copy_bss(ni, obss);
491 1.45 skrll ni->ni_intval = ic->ic_bintval;
492 1.39 dyoung ieee80211_free_node(obss);
493 1.75.4.1 phil } else
494 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_myaddr);
495 1.39 dyoung }
496 1.39 dyoung
497 1.75.4.1 phil static int
498 1.75.4.1 phil match_ssid(const struct ieee80211_node *ni,
499 1.75.4.1 phil int nssid, const struct ieee80211_scan_ssid ssids[])
500 1.75.4.1 phil {
501 1.75.4.1 phil int i;
502 1.75.4.1 phil
503 1.75.4.1 phil for (i = 0; i < nssid; i++) {
504 1.75.4.1 phil if (ni->ni_esslen == ssids[i].len &&
505 1.75.4.1 phil memcmp(ni->ni_essid, ssids[i].ssid, ni->ni_esslen) == 0)
506 1.75.4.1 phil return 1;
507 1.75.4.1 phil }
508 1.75.4.1 phil return 0;
509 1.75.4.1 phil }
510 1.45 skrll
511 1.75.4.1 phil /*
512 1.75.4.1 phil * Test a node for suitability/compatibility.
513 1.75.4.1 phil */
514 1.39 dyoung static int
515 1.75.4.1 phil check_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
516 1.75.4.1 phil {
517 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
518 1.75.4.1 phil uint8_t rate;
519 1.75.4.1 phil
520 1.75.4.1 phil if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
521 1.75.4.1 phil return 0;
522 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS) {
523 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
524 1.75.4.1 phil return 0;
525 1.75.4.1 phil } else {
526 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
527 1.75.4.1 phil return 0;
528 1.75.4.1 phil }
529 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_PRIVACY) {
530 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
531 1.75.4.1 phil return 0;
532 1.75.4.1 phil } else {
533 1.75.4.1 phil /* XXX does this mean privacy is supported or required? */
534 1.75.4.1 phil if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
535 1.75.4.1 phil return 0;
536 1.75.4.1 phil }
537 1.75.4.1 phil rate = ieee80211_fix_rate(ni, &ni->ni_rates,
538 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
539 1.75.4.1 phil if (rate & IEEE80211_RATE_BASIC)
540 1.75.4.1 phil return 0;
541 1.75.4.1 phil if (vap->iv_des_nssid != 0 &&
542 1.75.4.1 phil !match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
543 1.75.4.1 phil return 0;
544 1.75.4.1 phil if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
545 1.75.4.1 phil !IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
546 1.75.4.1 phil return 0;
547 1.75.4.1 phil return 1;
548 1.75.4.1 phil }
549 1.75.4.1 phil
550 1.75.4.1 phil #ifdef IEEE80211_DEBUG
551 1.75.4.1 phil /*
552 1.75.4.1 phil * Display node suitability/compatibility.
553 1.75.4.1 phil */
554 1.75.4.1 phil static void
555 1.75.4.1 phil check_bss_debug(struct ieee80211vap *vap, struct ieee80211_node *ni)
556 1.5 dyoung {
557 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
558 1.75.4.1 phil uint8_t rate;
559 1.75.4.1 phil int fail;
560 1.5 dyoung
561 1.5 dyoung fail = 0;
562 1.5 dyoung if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
563 1.5 dyoung fail |= 0x01;
564 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS) {
565 1.5 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
566 1.5 dyoung fail |= 0x02;
567 1.5 dyoung } else {
568 1.5 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
569 1.5 dyoung fail |= 0x02;
570 1.5 dyoung }
571 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_PRIVACY) {
572 1.5 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
573 1.5 dyoung fail |= 0x04;
574 1.5 dyoung } else {
575 1.11 dyoung /* XXX does this mean privacy is supported or required? */
576 1.5 dyoung if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
577 1.5 dyoung fail |= 0x04;
578 1.5 dyoung }
579 1.75.4.1 phil rate = ieee80211_fix_rate(ni, &ni->ni_rates,
580 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
581 1.5 dyoung if (rate & IEEE80211_RATE_BASIC)
582 1.5 dyoung fail |= 0x08;
583 1.75.4.1 phil if (vap->iv_des_nssid != 0 &&
584 1.75.4.1 phil !match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
585 1.5 dyoung fail |= 0x10;
586 1.75.4.1 phil if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
587 1.75.4.1 phil !IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
588 1.5 dyoung fail |= 0x20;
589 1.75 maxv
590 1.75.4.1 phil printf(" %c %s", fail ? '-' : '+', ether_sprintf(ni->ni_macaddr));
591 1.75.4.1 phil printf(" %s%c", ether_sprintf(ni->ni_bssid), fail & 0x20 ? '!' : ' ');
592 1.75.4.1 phil printf(" %3d%c",
593 1.75.4.1 phil ieee80211_chan2ieee(ic, ni->ni_chan), fail & 0x01 ? '!' : ' ');
594 1.75.4.1 phil printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2,
595 1.75.4.1 phil fail & 0x08 ? '!' : ' ');
596 1.75.4.1 phil printf(" %4s%c",
597 1.75.4.1 phil (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
598 1.75.4.1 phil (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
599 1.75.4.1 phil "????",
600 1.75.4.1 phil fail & 0x02 ? '!' : ' ');
601 1.75.4.1 phil printf(" %3s%c ",
602 1.75.4.1 phil (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? "wep" : "no",
603 1.75.4.1 phil fail & 0x04 ? '!' : ' ');
604 1.75.4.1 phil ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
605 1.75.4.1 phil printf("%s\n", fail & 0x10 ? "!" : "");
606 1.39 dyoung }
607 1.75.4.1 phil #endif /* IEEE80211_DEBUG */
608 1.75.4.1 phil
609 1.39 dyoung
610 1.75.4.1 phil int
611 1.75.4.1 phil ieee80211_ibss_merge_check(struct ieee80211_node *ni)
612 1.39 dyoung {
613 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
614 1.39 dyoung
615 1.75.4.1 phil if (ni == vap->iv_bss ||
616 1.75.4.1 phil IEEE80211_ADDR_EQ(ni->ni_bssid, vap->iv_bss->ni_bssid)) {
617 1.75.4.1 phil /* unchanged, nothing to do */
618 1.75.4.1 phil return 0;
619 1.75.4.1 phil }
620 1.39 dyoung
621 1.75.4.1 phil if (!check_bss(vap, ni)) {
622 1.75.4.1 phil /* capabilities mismatch */
623 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
624 1.75.4.1 phil "%s: merge failed, capabilities mismatch\n", __func__);
625 1.75.4.1 phil #ifdef IEEE80211_DEBUG
626 1.75.4.1 phil if (ieee80211_msg_assoc(vap))
627 1.75.4.1 phil check_bss_debug(vap, ni);
628 1.75.4.1 phil #endif
629 1.75.4.1 phil vap->iv_stats.is_ibss_capmismatch++;
630 1.75.4.1 phil return 0;
631 1.75.4.1 phil }
632 1.39 dyoung
633 1.75.4.1 phil return 1;
634 1.39 dyoung }
635 1.39 dyoung
636 1.1 dyoung /*
637 1.75.4.1 phil * Check if the given node should populate the node table.
638 1.75.4.1 phil *
639 1.75.4.1 phil * We need to be in "see all beacons for all ssids" mode in order
640 1.75.4.1 phil * to do IBSS merges, however this means we will populate nodes for
641 1.75.4.1 phil * /all/ IBSS SSIDs, versus just the one we care about.
642 1.75.4.1 phil *
643 1.75.4.1 phil * So this check ensures the node can actually belong to our IBSS
644 1.75.4.1 phil * configuration. For now it simply checks the SSID.
645 1.1 dyoung */
646 1.75.4.1 phil int
647 1.75.4.1 phil ieee80211_ibss_node_check_new(struct ieee80211_node *ni,
648 1.75.4.1 phil const struct ieee80211_scanparams *scan)
649 1.1 dyoung {
650 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
651 1.75.4.1 phil int i;
652 1.39 dyoung
653 1.39 dyoung /*
654 1.75.4.1 phil * If we have no SSID and no scan SSID, return OK.
655 1.39 dyoung */
656 1.75.4.1 phil if (vap->iv_des_nssid == 0 && scan->ssid == NULL)
657 1.75.4.1 phil goto ok;
658 1.75 maxv
659 1.39 dyoung /*
660 1.75.4.1 phil * If we have one of (SSID, scan SSID) then return error.
661 1.39 dyoung */
662 1.75.4.1 phil if (!! (vap->iv_des_nssid == 0) != !! (scan->ssid == NULL))
663 1.75.4.1 phil goto mismatch;
664 1.75 maxv
665 1.75.4.1 phil /*
666 1.75.4.1 phil * Double-check - we need scan SSID.
667 1.75.4.1 phil */
668 1.75.4.1 phil if (scan->ssid == NULL)
669 1.75.4.1 phil goto mismatch;
670 1.75 maxv
671 1.75.4.1 phil /*
672 1.75.4.1 phil * Check if the scan SSID matches the SSID list for the VAP.
673 1.75.4.1 phil */
674 1.75.4.1 phil for (i = 0; i < vap->iv_des_nssid; i++) {
675 1.75 maxv
676 1.75.4.1 phil /* Sanity length check */
677 1.75.4.1 phil if (vap->iv_des_ssid[i].len != scan->ssid[1])
678 1.75.4.1 phil continue;
679 1.75 maxv
680 1.75.4.1 phil /* Note: SSID in the scan entry is the IE format */
681 1.75.4.1 phil if (memcmp(vap->iv_des_ssid[i].ssid, scan->ssid + 2,
682 1.75.4.1 phil vap->iv_des_ssid[i].len) == 0)
683 1.75.4.1 phil goto ok;
684 1.1 dyoung }
685 1.75 maxv
686 1.75.4.1 phil mismatch:
687 1.75.4.1 phil return (0);
688 1.75.4.1 phil ok:
689 1.75.4.1 phil return (1);
690 1.39 dyoung }
691 1.65 christos
692 1.39 dyoung /*
693 1.39 dyoung * Handle 802.11 ad hoc network merge. The
694 1.39 dyoung * convention, set by the Wireless Ethernet Compatibility Alliance
695 1.39 dyoung * (WECA), is that an 802.11 station will change its BSSID to match
696 1.39 dyoung * the "oldest" 802.11 ad hoc network, on the same channel, that
697 1.39 dyoung * has the station's desired SSID. The "oldest" 802.11 network
698 1.39 dyoung * sends beacons with the greatest TSF timestamp.
699 1.39 dyoung *
700 1.39 dyoung * The caller is assumed to validate TSF's before attempting a merge.
701 1.39 dyoung *
702 1.39 dyoung * Return !0 if the BSSID changed, 0 otherwise.
703 1.39 dyoung */
704 1.39 dyoung int
705 1.45 skrll ieee80211_ibss_merge(struct ieee80211_node *ni)
706 1.39 dyoung {
707 1.75.4.1 phil #ifdef IEEE80211_DEBUG
708 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
709 1.45 skrll struct ieee80211com *ic = ni->ni_ic;
710 1.75.4.1 phil #endif
711 1.39 dyoung
712 1.75.4.1 phil if (! ieee80211_ibss_merge_check(ni))
713 1.39 dyoung return 0;
714 1.75.4.1 phil
715 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
716 1.39 dyoung "%s: new bssid %s: %s preamble, %s slot time%s\n", __func__,
717 1.39 dyoung ether_sprintf(ni->ni_bssid),
718 1.39 dyoung ic->ic_flags&IEEE80211_F_SHPREAMBLE ? "short" : "long",
719 1.39 dyoung ic->ic_flags&IEEE80211_F_SHSLOT ? "short" : "long",
720 1.39 dyoung ic->ic_flags&IEEE80211_F_USEPROT ? ", protection" : ""
721 1.39 dyoung );
722 1.75.4.1 phil return ieee80211_sta_join1(ieee80211_ref_node(ni));
723 1.39 dyoung }
724 1.39 dyoung
725 1.39 dyoung /*
726 1.75.4.1 phil * Calculate HT channel promotion flags for all vaps.
727 1.75.4.1 phil * This assumes ni_chan have been setup for each vap.
728 1.39 dyoung */
729 1.75.4.1 phil static int
730 1.75.4.1 phil gethtadjustflags(struct ieee80211com *ic)
731 1.39 dyoung {
732 1.75.4.1 phil struct ieee80211vap *vap;
733 1.75.4.1 phil int flags;
734 1.39 dyoung
735 1.75.4.1 phil flags = 0;
736 1.75.4.1 phil /* XXX locking */
737 1.75.4.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
738 1.75.4.1 phil if (vap->iv_state < IEEE80211_S_RUN)
739 1.75.4.1 phil continue;
740 1.75.4.1 phil switch (vap->iv_opmode) {
741 1.75.4.1 phil case IEEE80211_M_WDS:
742 1.75.4.1 phil case IEEE80211_M_STA:
743 1.75.4.1 phil case IEEE80211_M_AHDEMO:
744 1.75.4.1 phil case IEEE80211_M_HOSTAP:
745 1.75.4.1 phil case IEEE80211_M_IBSS:
746 1.75.4.1 phil case IEEE80211_M_MBSS:
747 1.75.4.1 phil flags |= ieee80211_htchanflags(vap->iv_bss->ni_chan);
748 1.75.4.1 phil break;
749 1.75.4.1 phil default:
750 1.75.4.1 phil break;
751 1.75.4.1 phil }
752 1.75.4.1 phil }
753 1.75.4.1 phil return flags;
754 1.75.4.1 phil }
755 1.75 maxv
756 1.75.4.1 phil /*
757 1.75.4.1 phil * Calculate VHT channel promotion flags for all vaps.
758 1.75.4.1 phil * This assumes ni_chan have been setup for each vap.
759 1.75.4.1 phil */
760 1.75.4.1 phil static int
761 1.75.4.1 phil getvhtadjustflags(struct ieee80211com *ic)
762 1.75.4.1 phil {
763 1.75.4.1 phil struct ieee80211vap *vap;
764 1.75.4.1 phil int flags;
765 1.75.4.1 phil
766 1.75.4.1 phil flags = 0;
767 1.75.4.1 phil /* XXX locking */
768 1.75.4.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
769 1.75.4.1 phil if (vap->iv_state < IEEE80211_S_RUN)
770 1.75.4.1 phil continue;
771 1.75.4.1 phil switch (vap->iv_opmode) {
772 1.75.4.1 phil case IEEE80211_M_WDS:
773 1.75.4.1 phil case IEEE80211_M_STA:
774 1.75.4.1 phil case IEEE80211_M_AHDEMO:
775 1.75.4.1 phil case IEEE80211_M_HOSTAP:
776 1.75.4.1 phil case IEEE80211_M_IBSS:
777 1.75.4.1 phil case IEEE80211_M_MBSS:
778 1.75.4.1 phil flags |= ieee80211_vhtchanflags(vap->iv_bss->ni_chan);
779 1.75.4.1 phil break;
780 1.75.4.1 phil default:
781 1.75.4.1 phil break;
782 1.75.4.1 phil }
783 1.75.4.1 phil }
784 1.75.4.1 phil return flags;
785 1.75.4.1 phil }
786 1.75.4.1 phil
787 1.75.4.1 phil /*
788 1.75.4.1 phil * Check if the current channel needs to change based on whether
789 1.75.4.1 phil * any vap's are using HT20/HT40. This is used to sync the state
790 1.75.4.1 phil * of ic_curchan after a channel width change on a running vap.
791 1.75.4.1 phil *
792 1.75.4.1 phil * Same applies for VHT.
793 1.75.4.1 phil */
794 1.75.4.1 phil void
795 1.75.4.1 phil ieee80211_sync_curchan(struct ieee80211com *ic)
796 1.75.4.1 phil {
797 1.75.4.1 phil struct ieee80211_channel *c;
798 1.75.4.1 phil
799 1.75.4.1 phil c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, gethtadjustflags(ic));
800 1.75.4.1 phil c = ieee80211_vht_adjust_channel(ic, c, getvhtadjustflags(ic));
801 1.75 maxv
802 1.75.4.1 phil if (c != ic->ic_curchan) {
803 1.75.4.1 phil ic->ic_curchan = c;
804 1.75.4.1 phil ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan);
805 1.75.4.1 phil ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
806 1.75.4.1 phil IEEE80211_UNLOCK(ic);
807 1.75.4.1 phil ic->ic_set_channel(ic);
808 1.75.4.1 phil ieee80211_radiotap_chan_change(ic);
809 1.75.4.1 phil IEEE80211_LOCK(ic);
810 1.75.4.1 phil }
811 1.75.4.1 phil }
812 1.75.4.1 phil
813 1.75.4.1 phil /*
814 1.75.4.1 phil * Setup the current channel. The request channel may be
815 1.75.4.1 phil * promoted if other vap's are operating with HT20/HT40.
816 1.75.4.1 phil */
817 1.75.4.1 phil void
818 1.75.4.1 phil ieee80211_setupcurchan(struct ieee80211com *ic, struct ieee80211_channel *c)
819 1.75.4.1 phil {
820 1.75.4.1 phil if (ic->ic_htcaps & IEEE80211_HTC_HT) {
821 1.75.4.1 phil int flags = gethtadjustflags(ic);
822 1.39 dyoung /*
823 1.75.4.1 phil * Check for channel promotion required to support the
824 1.75.4.1 phil * set of running vap's. This assumes we are called
825 1.75.4.1 phil * after ni_chan is setup for each vap.
826 1.39 dyoung */
827 1.75.4.1 phil /* XXX VHT? */
828 1.75.4.1 phil /* NB: this assumes IEEE80211_FHT_USEHT40 > IEEE80211_FHT_HT */
829 1.75.4.1 phil if (flags > ieee80211_htchanflags(c))
830 1.75.4.1 phil c = ieee80211_ht_adjust_channel(ic, c, flags);
831 1.39 dyoung }
832 1.39 dyoung
833 1.39 dyoung /*
834 1.75.4.1 phil * VHT promotion - this will at least promote to VHT20/40
835 1.75.4.1 phil * based on what HT has done; it may further promote the
836 1.75.4.1 phil * channel to VHT80 or above.
837 1.75.4.1 phil */
838 1.75.4.1 phil if (ic->ic_vhtcaps != 0) {
839 1.75.4.1 phil int flags = getvhtadjustflags(ic);
840 1.75.4.1 phil if (flags > ieee80211_vhtchanflags(c))
841 1.75.4.1 phil c = ieee80211_vht_adjust_channel(ic, c, flags);
842 1.75.4.1 phil }
843 1.75.4.1 phil
844 1.75.4.1 phil ic->ic_bsschan = ic->ic_curchan = c;
845 1.75.4.1 phil ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan);
846 1.75.4.1 phil ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
847 1.75.4.1 phil }
848 1.75.4.1 phil
849 1.75.4.1 phil /*
850 1.75.4.1 phil * Change the current channel. The channel change is guaranteed to have
851 1.75.4.1 phil * happened before the next state change.
852 1.75.4.1 phil */
853 1.75.4.1 phil void
854 1.75.4.1 phil ieee80211_setcurchan(struct ieee80211com *ic, struct ieee80211_channel *c)
855 1.75.4.1 phil {
856 1.75.4.1 phil ieee80211_setupcurchan(ic, c);
857 1.75.4.1 phil ieee80211_runtask(ic, &ic->ic_chan_task);
858 1.75.4.1 phil }
859 1.75.4.1 phil
860 1.75.4.1 phil void
861 1.75.4.1 phil ieee80211_update_chw(struct ieee80211com *ic)
862 1.75.4.1 phil {
863 1.75.4.1 phil
864 1.75.4.1 phil ieee80211_setupcurchan(ic, ic->ic_curchan);
865 1.75.4.1 phil ieee80211_runtask(ic, &ic->ic_chw_task);
866 1.75.4.1 phil }
867 1.75.4.1 phil
868 1.75.4.1 phil /*
869 1.75.4.1 phil * Join the specified IBSS/BSS network. The node is assumed to
870 1.75.4.1 phil * be passed in with a held reference.
871 1.75.4.1 phil */
872 1.75.4.1 phil static int
873 1.75.4.1 phil ieee80211_sta_join1(struct ieee80211_node *selbs)
874 1.75.4.1 phil {
875 1.75.4.1 phil struct ieee80211vap *vap = selbs->ni_vap;
876 1.75.4.1 phil struct ieee80211com *ic = selbs->ni_ic;
877 1.75.4.1 phil struct ieee80211_node *obss;
878 1.75.4.1 phil int canreassoc;
879 1.75.4.1 phil
880 1.75.4.1 phil /*
881 1.39 dyoung * Committed to selbs, setup state.
882 1.39 dyoung */
883 1.75.4.1 phil obss = vap->iv_bss;
884 1.75.4.1 phil /*
885 1.75.4.1 phil * Check if old+new node have the same address in which
886 1.75.4.1 phil * case we can reassociate when operating in sta mode.
887 1.75.4.1 phil */
888 1.75.4.1 phil canreassoc = (obss != NULL &&
889 1.75.4.1 phil vap->iv_state == IEEE80211_S_RUN &&
890 1.75.4.1 phil IEEE80211_ADDR_EQ(obss->ni_macaddr, selbs->ni_macaddr));
891 1.75.4.1 phil vap->iv_bss = selbs; /* NB: caller assumed to bump refcnt */
892 1.52 dyoung if (obss != NULL) {
893 1.75.4.1 phil struct ieee80211_node_table *nt = obss->ni_table;
894 1.75.4.1 phil
895 1.52 dyoung copy_bss(selbs, obss);
896 1.75.4.1 phil ieee80211_node_decref(obss); /* iv_bss reference */
897 1.75.4.1 phil
898 1.75.4.1 phil IEEE80211_NODE_LOCK(nt);
899 1.75.4.1 phil node_reclaim(nt, obss); /* station table reference */
900 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
901 1.75.4.1 phil
902 1.75.4.1 phil obss = NULL; /* NB: guard against later use */
903 1.52 dyoung }
904 1.75 maxv
905 1.39 dyoung /*
906 1.75.4.1 phil * Delete unusable rates; we've already checked
907 1.75.4.1 phil * that the negotiated rate set is acceptable.
908 1.75.4.1 phil */
909 1.75.4.1 phil ieee80211_fix_rate(vap->iv_bss, &vap->iv_bss->ni_rates,
910 1.75.4.1 phil IEEE80211_F_DODEL | IEEE80211_F_JOIN);
911 1.75.4.1 phil
912 1.75.4.1 phil ieee80211_setcurchan(ic, selbs->ni_chan);
913 1.75.4.1 phil /*
914 1.39 dyoung * Set the erp state (mostly the slot time) to deal with
915 1.39 dyoung * the auto-select case; this should be redundant if the
916 1.39 dyoung * mode is locked.
917 1.75.4.1 phil */
918 1.39 dyoung ieee80211_reset_erp(ic);
919 1.75.4.1 phil ieee80211_wme_initparams(vap);
920 1.39 dyoung
921 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_STA) {
922 1.75.4.1 phil if (canreassoc) {
923 1.75.4.1 phil /* Reassociate */
924 1.75.4.1 phil ieee80211_new_state(vap, IEEE80211_S_ASSOC, 1);
925 1.75.4.1 phil } else {
926 1.75.4.1 phil /*
927 1.75.4.1 phil * Act as if we received a DEAUTH frame in case we
928 1.75.4.1 phil * are invoked from the RUN state. This will cause
929 1.75.4.1 phil * us to try to re-authenticate if we are operating
930 1.75.4.1 phil * as a station.
931 1.75.4.1 phil */
932 1.75.4.1 phil ieee80211_new_state(vap, IEEE80211_S_AUTH,
933 1.75.4.1 phil IEEE80211_FC0_SUBTYPE_DEAUTH);
934 1.75.4.1 phil }
935 1.75.4.1 phil } else
936 1.75.4.1 phil ieee80211_new_state(vap, IEEE80211_S_RUN, -1);
937 1.39 dyoung return 1;
938 1.39 dyoung }
939 1.39 dyoung
940 1.75.4.1 phil int
941 1.75.4.1 phil ieee80211_sta_join(struct ieee80211vap *vap, struct ieee80211_channel *chan,
942 1.75.4.1 phil const struct ieee80211_scan_entry *se)
943 1.75.4.1 phil {
944 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
945 1.75.4.1 phil struct ieee80211_node *ni;
946 1.75.4.1 phil int do_ht = 0;
947 1.75.4.1 phil
948 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, se->se_macaddr);
949 1.75.4.1 phil if (ni == NULL) {
950 1.75.4.1 phil /* XXX msg */
951 1.75.4.1 phil return 0;
952 1.75.4.1 phil }
953 1.75.4.1 phil
954 1.75.4.1 phil /*
955 1.75.4.1 phil * Expand scan state into node's format.
956 1.75.4.1 phil * XXX may not need all this stuff
957 1.75.4.1 phil */
958 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, se->se_bssid);
959 1.75.4.1 phil ni->ni_esslen = se->se_ssid[1];
960 1.75.4.1 phil memcpy(ni->ni_essid, se->se_ssid+2, ni->ni_esslen);
961 1.75.4.1 phil ni->ni_tstamp.tsf = se->se_tstamp.tsf;
962 1.75.4.1 phil ni->ni_intval = se->se_intval;
963 1.75.4.1 phil ni->ni_capinfo = se->se_capinfo;
964 1.75.4.1 phil ni->ni_chan = chan;
965 1.75.4.1 phil ni->ni_timoff = se->se_timoff;
966 1.75.4.1 phil ni->ni_fhdwell = se->se_fhdwell;
967 1.75.4.1 phil ni->ni_fhindex = se->se_fhindex;
968 1.75.4.1 phil ni->ni_erp = se->se_erp;
969 1.75.4.1 phil IEEE80211_RSSI_LPF(ni->ni_avgrssi, se->se_rssi);
970 1.75.4.1 phil ni->ni_noise = se->se_noise;
971 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_STA) {
972 1.75.4.1 phil /* NB: only infrastructure mode requires an associd */
973 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ASSOCID;
974 1.75.4.1 phil }
975 1.75.4.1 phil
976 1.75.4.1 phil if (ieee80211_ies_init(&ni->ni_ies, se->se_ies.data, se->se_ies.len)) {
977 1.75.4.1 phil ieee80211_ies_expand(&ni->ni_ies);
978 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
979 1.75.4.1 phil if (ni->ni_ies.ath_ie != NULL)
980 1.75.4.1 phil ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
981 1.75.4.1 phil #endif
982 1.75.4.1 phil if (ni->ni_ies.htcap_ie != NULL)
983 1.75.4.1 phil ieee80211_parse_htcap(ni, ni->ni_ies.htcap_ie);
984 1.75.4.1 phil if (ni->ni_ies.htinfo_ie != NULL)
985 1.75.4.1 phil ieee80211_parse_htinfo(ni, ni->ni_ies.htinfo_ie);
986 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
987 1.75.4.1 phil if (ni->ni_ies.meshid_ie != NULL)
988 1.75.4.1 phil ieee80211_parse_meshid(ni, ni->ni_ies.meshid_ie);
989 1.75.4.1 phil #endif
990 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_TDMA
991 1.75.4.1 phil if (ni->ni_ies.tdma_ie != NULL)
992 1.75.4.1 phil ieee80211_parse_tdma(ni, ni->ni_ies.tdma_ie);
993 1.75.4.1 phil #endif
994 1.75.4.1 phil if (ni->ni_ies.vhtcap_ie != NULL)
995 1.75.4.1 phil ieee80211_parse_vhtcap(ni, ni->ni_ies.vhtcap_ie);
996 1.75.4.1 phil if (ni->ni_ies.vhtopmode_ie != NULL)
997 1.75.4.1 phil ieee80211_parse_vhtopmode(ni, ni->ni_ies.vhtopmode_ie);
998 1.75.4.1 phil
999 1.75.4.1 phil /* XXX parse BSSLOAD IE */
1000 1.75.4.1 phil /* XXX parse TXPWRENV IE */
1001 1.75.4.1 phil /* XXX parse APCHANREP IE */
1002 1.75.4.1 phil }
1003 1.75.4.1 phil
1004 1.75.4.1 phil vap->iv_dtim_period = se->se_dtimperiod;
1005 1.75.4.1 phil vap->iv_dtim_count = 0;
1006 1.75.4.1 phil
1007 1.75.4.1 phil /* NB: must be after ni_chan is setup */
1008 1.75.4.1 phil ieee80211_setup_rates(ni, se->se_rates, se->se_xrates,
1009 1.75.4.1 phil IEEE80211_F_DOSORT);
1010 1.75.4.1 phil if (ieee80211_iserp_rateset(&ni->ni_rates))
1011 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ERP;
1012 1.75.4.1 phil
1013 1.75.4.1 phil /*
1014 1.75.4.1 phil * Setup HT state for this node if it's available, otherwise
1015 1.75.4.1 phil * non-STA modes won't pick this state up.
1016 1.75.4.1 phil *
1017 1.75.4.1 phil * For IBSS and related modes that don't go through an
1018 1.75.4.1 phil * association request/response, the only appropriate place
1019 1.75.4.1 phil * to setup the HT state is here.
1020 1.75.4.1 phil */
1021 1.75.4.1 phil if (ni->ni_ies.htinfo_ie != NULL &&
1022 1.75.4.1 phil ni->ni_ies.htcap_ie != NULL &&
1023 1.75.4.1 phil vap->iv_flags_ht & IEEE80211_FHT_HT) {
1024 1.75.4.1 phil ieee80211_ht_node_init(ni);
1025 1.75.4.1 phil ieee80211_ht_updateparams(ni,
1026 1.75.4.1 phil ni->ni_ies.htcap_ie,
1027 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1028 1.75.4.1 phil do_ht = 1;
1029 1.75.4.1 phil }
1030 1.75.4.1 phil
1031 1.75.4.1 phil /*
1032 1.75.4.1 phil * Setup VHT state for this node if it's available.
1033 1.75.4.1 phil * Same as the above.
1034 1.75.4.1 phil *
1035 1.75.4.1 phil * For now, don't allow 2GHz VHT operation.
1036 1.75.4.1 phil */
1037 1.75.4.1 phil if (ni->ni_ies.vhtopmode_ie != NULL &&
1038 1.75.4.1 phil ni->ni_ies.vhtcap_ie != NULL &&
1039 1.75.4.1 phil vap->iv_flags_vht & IEEE80211_FVHT_VHT) {
1040 1.75.4.2 phil #if __FreeBSD__
1041 1.75.4.1 phil if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
1042 1.75.4.1 phil printf("%s: BSS %6D: 2GHz channel, VHT info; ignoring\n",
1043 1.75.4.1 phil __func__,
1044 1.75.4.1 phil ni->ni_macaddr,
1045 1.75.4.1 phil ":");
1046 1.75.4.2 phil #elif __NetBSD__
1047 1.75.4.2 phil if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
1048 1.75.4.2 phil printf("%s: BSS %6ld: 2GHz channel, VHT info; ignoring\n",
1049 1.75.4.2 phil __func__, (long int)ni->ni_macaddr);
1050 1.75.4.2 phil #endif
1051 1.75.4.1 phil } else {
1052 1.75.4.1 phil ieee80211_vht_node_init(ni);
1053 1.75.4.1 phil ieee80211_vht_updateparams(ni,
1054 1.75.4.1 phil ni->ni_ies.vhtcap_ie,
1055 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1056 1.75.4.1 phil ieee80211_setup_vht_rates(ni, ni->ni_ies.vhtcap_ie,
1057 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1058 1.75.4.1 phil do_ht = 1;
1059 1.75.4.1 phil }
1060 1.75.4.1 phil }
1061 1.75.4.1 phil
1062 1.75.4.1 phil /* Finally do the node channel change */
1063 1.75.4.1 phil if (do_ht) {
1064 1.75.4.1 phil ieee80211_ht_updateparams_final(ni, ni->ni_ies.htcap_ie,
1065 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1066 1.75.4.1 phil ieee80211_setup_htrates(ni, ni->ni_ies.htcap_ie,
1067 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DOBRS);
1068 1.75.4.1 phil ieee80211_setup_basic_htrates(ni, ni->ni_ies.htinfo_ie);
1069 1.75.4.1 phil }
1070 1.75.4.1 phil
1071 1.75.4.1 phil /* XXX else check for ath FF? */
1072 1.75.4.1 phil /* XXX QoS? Difficult given that WME config is specific to a master */
1073 1.75.4.1 phil
1074 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1075 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1076 1.75.4.1 phil
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.3 phil printf ("before ratectl_node_init call\n");
1461 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1462 1.75.4.3 phil printf ("after ratectl_node_init\n");
1463 1.39 dyoung
1464 1.1 dyoung return ni;
1465 1.1 dyoung }
1466 1.1 dyoung
1467 1.45 skrll /*
1468 1.45 skrll * Craft a temporary node suitable for sending a management frame
1469 1.45 skrll * to the specified station. We craft only as much state as we
1470 1.45 skrll * need to do the work since the node will be immediately reclaimed
1471 1.45 skrll * once the send completes.
1472 1.45 skrll */
1473 1.45 skrll struct ieee80211_node *
1474 1.75.4.1 phil ieee80211_tmp_node(struct ieee80211vap *vap,
1475 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1476 1.45 skrll {
1477 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1478 1.45 skrll struct ieee80211_node *ni;
1479 1.45 skrll
1480 1.75.4.1 phil ni = ic->ic_node_alloc(vap, macaddr);
1481 1.45 skrll if (ni != NULL) {
1482 1.75.4.1 phil struct ieee80211_node *bss = vap->iv_bss;
1483 1.75.4.1 phil
1484 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1485 1.45 skrll "%s %p<%s>\n", __func__, ni, ether_sprintf(macaddr));
1486 1.45 skrll
1487 1.75.4.1 phil ni->ni_table = NULL; /* NB: pedantic */
1488 1.75.4.1 phil ni->ni_ic = ic; /* NB: needed to set channel */
1489 1.75.4.1 phil ni->ni_vap = vap;
1490 1.75.4.1 phil
1491 1.45 skrll IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
1492 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, bss->ni_bssid);
1493 1.45 skrll ieee80211_node_initref(ni); /* mark referenced */
1494 1.45 skrll /* NB: required by ieee80211_fix_rate */
1495 1.75.4.1 phil ieee80211_node_set_chan(ni, bss->ni_chan);
1496 1.75.4.1 phil ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey,
1497 1.45 skrll IEEE80211_KEYIX_NONE);
1498 1.75.4.1 phil ni->ni_txpower = bss->ni_txpower;
1499 1.45 skrll /* XXX optimize away */
1500 1.75.4.1 phil ieee80211_psq_init(&ni->ni_psq, "unknown");
1501 1.45 skrll
1502 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1503 1.45 skrll } else {
1504 1.45 skrll /* XXX msg */
1505 1.75.4.1 phil vap->iv_stats.is_rx_nodealloc++;
1506 1.45 skrll }
1507 1.45 skrll return ni;
1508 1.45 skrll }
1509 1.45 skrll
1510 1.1 dyoung struct ieee80211_node *
1511 1.75.4.1 phil ieee80211_dup_bss(struct ieee80211vap *vap,
1512 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1513 1.1 dyoung {
1514 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1515 1.39 dyoung struct ieee80211_node *ni;
1516 1.39 dyoung
1517 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, macaddr);
1518 1.1 dyoung if (ni != NULL) {
1519 1.75.4.1 phil struct ieee80211_node *bss = vap->iv_bss;
1520 1.11 dyoung /*
1521 1.75.4.1 phil * Inherit from iv_bss.
1522 1.11 dyoung */
1523 1.75.4.1 phil copy_bss(ni, bss);
1524 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, bss->ni_bssid);
1525 1.75.4.1 phil ieee80211_node_set_chan(ni, bss->ni_chan);
1526 1.75 maxv }
1527 1.1 dyoung return ni;
1528 1.1 dyoung }
1529 1.1 dyoung
1530 1.75.4.1 phil /*
1531 1.75.4.1 phil * Create a bss node for a legacy WDS vap. The far end does
1532 1.75.4.1 phil * not associate so we just create create a new node and
1533 1.75.4.1 phil * simulate an association. The caller is responsible for
1534 1.75.4.1 phil * installing the node as the bss node and handling any further
1535 1.75.4.1 phil * setup work like authorizing the port.
1536 1.75.4.1 phil */
1537 1.75.4.1 phil struct ieee80211_node *
1538 1.75.4.1 phil ieee80211_node_create_wds(struct ieee80211vap *vap,
1539 1.75.4.1 phil const uint8_t bssid[IEEE80211_ADDR_LEN], struct ieee80211_channel *chan)
1540 1.75.4.1 phil {
1541 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1542 1.75.4.1 phil struct ieee80211_node *ni;
1543 1.75.4.1 phil
1544 1.75.4.1 phil /* XXX check if node already in sta table? */
1545 1.75.4.1 phil ni = ieee80211_alloc_node(&ic->ic_sta, vap, bssid);
1546 1.75.4.1 phil if (ni != NULL) {
1547 1.75.4.1 phil ni->ni_wdsvap = vap;
1548 1.75.4.1 phil IEEE80211_ADDR_COPY(ni->ni_bssid, bssid);
1549 1.75.4.1 phil /*
1550 1.75.4.1 phil * Inherit any manually configured settings.
1551 1.75.4.1 phil */
1552 1.75.4.1 phil copy_bss(ni, vap->iv_bss);
1553 1.75.4.1 phil ieee80211_node_set_chan(ni, chan);
1554 1.75.4.1 phil /* NB: propagate ssid so available to WPA supplicant */
1555 1.75.4.1 phil ni->ni_esslen = vap->iv_des_ssid[0].len;
1556 1.75.4.1 phil memcpy(ni->ni_essid, vap->iv_des_ssid[0].ssid, ni->ni_esslen);
1557 1.75.4.1 phil /* NB: no associd for peer */
1558 1.75.4.1 phil /*
1559 1.75.4.1 phil * There are no management frames to use to
1560 1.75.4.1 phil * discover neighbor capabilities, so blindly
1561 1.75.4.1 phil * propagate the local configuration.
1562 1.75.4.1 phil */
1563 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_WME)
1564 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_QOS;
1565 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1566 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_FF)
1567 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_FF;
1568 1.75.4.1 phil #endif
1569 1.75.4.1 phil /* XXX VHT */
1570 1.75.4.1 phil if ((ic->ic_htcaps & IEEE80211_HTC_HT) &&
1571 1.75.4.1 phil (vap->iv_flags_ht & IEEE80211_FHT_HT)) {
1572 1.75.4.1 phil /*
1573 1.75.4.1 phil * Device is HT-capable and HT is enabled for
1574 1.75.4.1 phil * the vap; setup HT operation. On return
1575 1.75.4.1 phil * ni_chan will be adjusted to an HT channel.
1576 1.75.4.1 phil */
1577 1.75.4.1 phil ieee80211_ht_wds_init(ni);
1578 1.75.4.1 phil if (vap->iv_flags_vht & IEEE80211_FVHT_VHT) {
1579 1.75.4.1 phil printf("%s: TODO: vht_wds_init\n", __func__);
1580 1.75.4.1 phil }
1581 1.75.4.1 phil } else {
1582 1.75.4.1 phil struct ieee80211_channel *c = ni->ni_chan;
1583 1.75.4.1 phil /*
1584 1.75.4.1 phil * Force a legacy channel to be used.
1585 1.75.4.1 phil */
1586 1.75.4.1 phil c = ieee80211_find_channel(ic,
1587 1.75.4.1 phil c->ic_freq, c->ic_flags &~ IEEE80211_CHAN_HT);
1588 1.75.4.1 phil KASSERT(c != NULL, ("no legacy channel, %u/%x",
1589 1.75.4.1 phil ni->ni_chan->ic_freq, ni->ni_chan->ic_flags));
1590 1.75.4.1 phil ni->ni_chan = c;
1591 1.75.4.1 phil }
1592 1.75.4.1 phil }
1593 1.75.4.1 phil return ni;
1594 1.75.4.1 phil }
1595 1.75.4.1 phil
1596 1.75.4.1 phil struct ieee80211_node *
1597 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1598 1.75.4.1 phil ieee80211_find_node_locked_debug(struct ieee80211_node_table *nt,
1599 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1600 1.39 dyoung #else
1601 1.75.4.1 phil ieee80211_find_node_locked(struct ieee80211_node_table *nt,
1602 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1603 1.39 dyoung #endif
1604 1.1 dyoung {
1605 1.1 dyoung struct ieee80211_node *ni;
1606 1.1 dyoung int hash;
1607 1.11 dyoung
1608 1.39 dyoung IEEE80211_NODE_LOCK_ASSERT(nt);
1609 1.1 dyoung
1610 1.75.4.1 phil hash = IEEE80211_NODE_HASH(nt->nt_ic, macaddr);
1611 1.39 dyoung LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
1612 1.1 dyoung if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
1613 1.39 dyoung ieee80211_ref_node(ni); /* mark referenced */
1614 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1615 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1616 1.39 dyoung "%s (%s:%u) %p<%s> refcnt %d\n", __func__,
1617 1.39 dyoung func, line,
1618 1.39 dyoung ni, ether_sprintf(ni->ni_macaddr),
1619 1.39 dyoung ieee80211_node_refcnt(ni));
1620 1.39 dyoung #endif
1621 1.11 dyoung return ni;
1622 1.1 dyoung }
1623 1.1 dyoung }
1624 1.11 dyoung return NULL;
1625 1.11 dyoung }
1626 1.11 dyoung
1627 1.11 dyoung struct ieee80211_node *
1628 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1629 1.39 dyoung ieee80211_find_node_debug(struct ieee80211_node_table *nt,
1630 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1631 1.39 dyoung #else
1632 1.75.4.1 phil ieee80211_find_node(struct ieee80211_node_table *nt,
1633 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1634 1.39 dyoung #endif
1635 1.11 dyoung {
1636 1.11 dyoung struct ieee80211_node *ni;
1637 1.11 dyoung
1638 1.39 dyoung IEEE80211_NODE_LOCK(nt);
1639 1.75.4.1 phil ni = ieee80211_find_node_locked(nt, macaddr);
1640 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
1641 1.7 dyoung return ni;
1642 1.7 dyoung }
1643 1.7 dyoung
1644 1.7 dyoung struct ieee80211_node *
1645 1.75.4.1 phil #ifdef IEEE80211_DEBUG_REFCNT
1646 1.75.4.1 phil ieee80211_find_vap_node_locked_debug(struct ieee80211_node_table *nt,
1647 1.75.4.1 phil const struct ieee80211vap *vap,
1648 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1649 1.75.4.1 phil #else
1650 1.75.4.1 phil ieee80211_find_vap_node_locked(struct ieee80211_node_table *nt,
1651 1.75.4.1 phil const struct ieee80211vap *vap,
1652 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1653 1.75.4.1 phil #endif
1654 1.7 dyoung {
1655 1.7 dyoung struct ieee80211_node *ni;
1656 1.75.4.1 phil int hash;
1657 1.7 dyoung
1658 1.75.4.1 phil IEEE80211_NODE_LOCK_ASSERT(nt);
1659 1.45 skrll
1660 1.75.4.1 phil hash = IEEE80211_NODE_HASH(nt->nt_ic, macaddr);
1661 1.75.4.1 phil LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
1662 1.75.4.1 phil if (ni->ni_vap == vap &&
1663 1.75.4.1 phil IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
1664 1.75.4.1 phil ieee80211_ref_node(ni); /* mark referenced */
1665 1.75.4.1 phil #ifdef IEEE80211_DEBUG_REFCNT
1666 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1667 1.75.4.1 phil "%s (%s:%u) %p<%s> refcnt %d\n", __func__,
1668 1.75.4.1 phil func, line,
1669 1.75.4.1 phil ni, ether_sprintf(ni->ni_macaddr),
1670 1.75.4.1 phil ieee80211_node_refcnt(ni));
1671 1.45 skrll #endif
1672 1.75.4.1 phil return ni;
1673 1.45 skrll }
1674 1.45 skrll }
1675 1.75.4.1 phil return NULL;
1676 1.45 skrll }
1677 1.45 skrll
1678 1.75.4.1 phil struct ieee80211_node *
1679 1.75.4.1 phil #ifdef IEEE80211_DEBUG_REFCNT
1680 1.75.4.1 phil ieee80211_find_vap_node_debug(struct ieee80211_node_table *nt,
1681 1.75.4.1 phil const struct ieee80211vap *vap,
1682 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1683 1.75.4.1 phil #else
1684 1.75.4.1 phil ieee80211_find_vap_node(struct ieee80211_node_table *nt,
1685 1.75.4.1 phil const struct ieee80211vap *vap,
1686 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1687 1.75.4.1 phil #endif
1688 1.45 skrll {
1689 1.75.4.1 phil struct ieee80211_node *ni;
1690 1.45 skrll
1691 1.75.4.1 phil IEEE80211_NODE_LOCK(nt);
1692 1.75.4.1 phil ni = ieee80211_find_vap_node_locked(nt, vap, macaddr);
1693 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
1694 1.75.4.1 phil return ni;
1695 1.45 skrll }
1696 1.45 skrll
1697 1.45 skrll /*
1698 1.75.4.1 phil * Fake up a node; this handles node discovery in adhoc mode.
1699 1.75.4.1 phil * Note that for the driver's benefit we we treat this like
1700 1.75.4.1 phil * an association so the driver has an opportunity to setup
1701 1.75.4.1 phil * it's private state.
1702 1.45 skrll */
1703 1.75.4.1 phil struct ieee80211_node *
1704 1.75.4.1 phil ieee80211_fakeup_adhoc_node(struct ieee80211vap *vap,
1705 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
1706 1.45 skrll {
1707 1.45 skrll struct ieee80211_node *ni;
1708 1.45 skrll
1709 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE | IEEE80211_MSG_ASSOC,
1710 1.75.4.1 phil "%s: mac<%s>\n", __func__, ether_sprintf(macaddr));
1711 1.75.4.1 phil ni = ieee80211_dup_bss(vap, macaddr);
1712 1.75.4.1 phil if (ni != NULL) {
1713 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1714 1.75.4.1 phil
1715 1.75.4.1 phil /* XXX no rate negotiation; just dup */
1716 1.75.4.1 phil ni->ni_rates = vap->iv_bss->ni_rates;
1717 1.75.4.1 phil if (ieee80211_iserp_rateset(&ni->ni_rates))
1718 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ERP;
1719 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
1720 1.75.4.1 phil /*
1721 1.75.4.1 phil * In adhoc demo mode there are no management
1722 1.75.4.1 phil * frames to use to discover neighbor capabilities,
1723 1.75.4.1 phil * so blindly propagate the local configuration
1724 1.75.4.1 phil * so we can do interesting things (e.g. use
1725 1.75.4.1 phil * WME to disable ACK's).
1726 1.75.4.1 phil */
1727 1.75.4.1 phil /*
1728 1.75.4.1 phil * XXX TODO: 11n?
1729 1.75.4.1 phil */
1730 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_WME)
1731 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_QOS;
1732 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1733 1.75.4.1 phil if (vap->iv_flags & IEEE80211_F_FF)
1734 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_FF;
1735 1.75.4.1 phil #endif
1736 1.75.4.1 phil }
1737 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1738 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1739 1.75.4.1 phil
1740 1.75.4.1 phil /*
1741 1.75.4.1 phil * XXX TODO: 11n? At least 20MHz, at least A-MPDU RX,
1742 1.75.4.1 phil * not A-MPDU TX; not 11n rates, etc. We'll cycle
1743 1.75.4.1 phil * that after we hear that we can indeed do 11n
1744 1.75.4.1 phil * (either by a beacon frame or by a probe response.)
1745 1.75.4.1 phil */
1746 1.75.4.1 phil
1747 1.75.4.1 phil /*
1748 1.75.4.1 phil * This is the first time we see the node.
1749 1.75.4.1 phil */
1750 1.75.4.1 phil if (ic->ic_newassoc != NULL)
1751 1.75.4.1 phil ic->ic_newassoc(ni, 1);
1752 1.75.4.1 phil
1753 1.45 skrll /*
1754 1.75.4.1 phil * Kick off a probe request to the given node;
1755 1.75.4.1 phil * we will then use the probe response to update
1756 1.75.4.1 phil * 11n/etc configuration state.
1757 1.75.4.1 phil *
1758 1.75.4.1 phil * XXX TODO: this isn't guaranteed, and until we get
1759 1.75.4.1 phil * a probe response, we won't be able to actually
1760 1.75.4.1 phil * do anything 802.11n related to the node.
1761 1.75.4.1 phil * So if this does indeed work, maybe we should hold
1762 1.75.4.1 phil * off on sending responses until we get the probe
1763 1.75.4.1 phil * response, or just default to some sensible subset
1764 1.75.4.1 phil * of 802.11n behaviour (eg always allow aggregation
1765 1.75.4.1 phil * negotiation TO us, but not FROM us, etc) so we
1766 1.75.4.1 phil * aren't entirely busted.
1767 1.45 skrll */
1768 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS) {
1769 1.75.4.1 phil ieee80211_send_probereq(ni, /* node */
1770 1.75.4.1 phil vap->iv_myaddr, /* SA */
1771 1.75.4.1 phil ni->ni_macaddr, /* DA */
1772 1.75.4.1 phil vap->iv_bss->ni_bssid, /* BSSID */
1773 1.75.4.1 phil vap->iv_bss->ni_essid,
1774 1.75.4.1 phil vap->iv_bss->ni_esslen); /* SSID */
1775 1.45 skrll }
1776 1.74 maxv
1777 1.75.4.1 phil /* XXX not right for 802.1x/WPA */
1778 1.75.4.1 phil ieee80211_node_authorize(ni);
1779 1.45 skrll }
1780 1.75.4.1 phil return ni;
1781 1.75.4.1 phil }
1782 1.74 maxv
1783 1.75.4.1 phil void
1784 1.75.4.1 phil ieee80211_init_neighbor(struct ieee80211_node *ni,
1785 1.75.4.1 phil const struct ieee80211_frame *wh,
1786 1.75.4.1 phil const struct ieee80211_scanparams *sp)
1787 1.75.4.1 phil {
1788 1.75.4.1 phil int do_ht_setup = 0, do_vht_setup = 0;
1789 1.74 maxv
1790 1.75.4.1 phil ni->ni_esslen = sp->ssid[1];
1791 1.75.4.1 phil memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]);
1792 1.45 skrll IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
1793 1.75.4.1 phil memcpy(ni->ni_tstamp.data, sp->tstamp, sizeof(ni->ni_tstamp));
1794 1.75.4.1 phil ni->ni_intval = sp->bintval;
1795 1.75.4.1 phil ni->ni_capinfo = sp->capinfo;
1796 1.75.4.1 phil ni->ni_chan = ni->ni_ic->ic_curchan;
1797 1.75.4.1 phil ni->ni_fhdwell = sp->fhdwell;
1798 1.75.4.1 phil ni->ni_fhindex = sp->fhindex;
1799 1.75.4.1 phil ni->ni_erp = sp->erp;
1800 1.75.4.1 phil ni->ni_timoff = sp->timoff;
1801 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
1802 1.75.4.1 phil if (ni->ni_vap->iv_opmode == IEEE80211_M_MBSS)
1803 1.75.4.1 phil ieee80211_mesh_init_neighbor(ni, wh, sp);
1804 1.75.4.1 phil #endif
1805 1.75.4.1 phil if (ieee80211_ies_init(&ni->ni_ies, sp->ies, sp->ies_len)) {
1806 1.75.4.1 phil ieee80211_ies_expand(&ni->ni_ies);
1807 1.75.4.1 phil if (ni->ni_ies.wme_ie != NULL)
1808 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_QOS;
1809 1.75.4.1 phil else
1810 1.75.4.1 phil ni->ni_flags &= ~IEEE80211_NODE_QOS;
1811 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_SUPERG
1812 1.75.4.1 phil if (ni->ni_ies.ath_ie != NULL)
1813 1.75.4.1 phil ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
1814 1.75.4.1 phil #endif
1815 1.75.4.1 phil if (ni->ni_ies.htcap_ie != NULL)
1816 1.75.4.1 phil ieee80211_parse_htcap(ni, ni->ni_ies.htcap_ie);
1817 1.75.4.1 phil if (ni->ni_ies.htinfo_ie != NULL)
1818 1.75.4.1 phil ieee80211_parse_htinfo(ni, ni->ni_ies.htinfo_ie);
1819 1.75.4.1 phil
1820 1.75.4.1 phil if (ni->ni_ies.vhtcap_ie != NULL)
1821 1.75.4.1 phil ieee80211_parse_vhtcap(ni, ni->ni_ies.vhtcap_ie);
1822 1.75.4.1 phil if (ni->ni_ies.vhtopmode_ie != NULL)
1823 1.75.4.1 phil ieee80211_parse_vhtopmode(ni, ni->ni_ies.vhtopmode_ie);
1824 1.75.4.1 phil
1825 1.75.4.1 phil if ((ni->ni_ies.htcap_ie != NULL) &&
1826 1.75.4.1 phil (ni->ni_ies.htinfo_ie != NULL) &&
1827 1.75.4.1 phil (ni->ni_vap->iv_flags_ht & IEEE80211_FHT_HT)) {
1828 1.75.4.1 phil do_ht_setup = 1;
1829 1.75.4.1 phil }
1830 1.75.4.1 phil
1831 1.75.4.1 phil if ((ni->ni_ies.vhtcap_ie != NULL) &&
1832 1.75.4.1 phil (ni->ni_ies.vhtopmode_ie != NULL) &&
1833 1.75.4.1 phil (ni->ni_vap->iv_flags_vht & IEEE80211_FVHT_VHT)) {
1834 1.75.4.1 phil do_vht_setup = 1;
1835 1.75.4.1 phil }
1836 1.45 skrll
1837 1.45 skrll }
1838 1.74 maxv
1839 1.45 skrll /* NB: must be after ni_chan is setup */
1840 1.75.4.1 phil ieee80211_setup_rates(ni, sp->rates, sp->xrates,
1841 1.75.4.1 phil IEEE80211_F_DOSORT | IEEE80211_F_DOFRATE |
1842 1.75.4.1 phil IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
1843 1.75.4.1 phil
1844 1.75.4.1 phil /*
1845 1.75.4.1 phil * If the neighbor is HT compatible, flip that on.
1846 1.75.4.1 phil */
1847 1.75.4.1 phil if (do_ht_setup) {
1848 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
1849 1.75.4.1 phil "%s: doing HT setup\n", __func__);
1850 1.75.4.1 phil ieee80211_ht_node_init(ni);
1851 1.75.4.1 phil ieee80211_ht_updateparams(ni,
1852 1.75.4.1 phil ni->ni_ies.htcap_ie,
1853 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1854 1.75.4.1 phil
1855 1.75.4.1 phil if (do_vht_setup) {
1856 1.75.4.1 phil if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
1857 1.75.4.2 phil #if __FreeBSD__
1858 1.75.4.1 phil printf("%s: BSS %6D: 2GHz channel, VHT info; ignoring\n",
1859 1.75.4.1 phil __func__,
1860 1.75.4.1 phil ni->ni_macaddr,
1861 1.75.4.1 phil ":");
1862 1.75.4.2 phil #elif __NetBSD__
1863 1.75.4.2 phil printf("%s: BSS %6ld: 2GHz channel, VHT info; ignoring\n",
1864 1.75.4.2 phil __func__, (long int)ni->ni_macaddr);
1865 1.75.4.2 phil #endif
1866 1.75.4.1 phil } else {
1867 1.75.4.1 phil ieee80211_vht_node_init(ni);
1868 1.75.4.1 phil ieee80211_vht_updateparams(ni,
1869 1.75.4.1 phil ni->ni_ies.vhtcap_ie,
1870 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1871 1.75.4.1 phil ieee80211_setup_vht_rates(ni,
1872 1.75.4.1 phil ni->ni_ies.vhtcap_ie,
1873 1.75.4.1 phil ni->ni_ies.vhtopmode_ie);
1874 1.75.4.1 phil }
1875 1.75.4.1 phil }
1876 1.45 skrll
1877 1.75.4.1 phil /*
1878 1.75.4.1 phil * Finally do the channel upgrade/change based
1879 1.75.4.1 phil * on the HT/VHT configuration.
1880 1.75.4.1 phil */
1881 1.75.4.1 phil ieee80211_ht_updateparams_final(ni, ni->ni_ies.htcap_ie,
1882 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1883 1.75.4.1 phil ieee80211_setup_htrates(ni,
1884 1.75.4.1 phil ni->ni_ies.htcap_ie,
1885 1.75.4.1 phil IEEE80211_F_JOIN | IEEE80211_F_DOBRS);
1886 1.75.4.1 phil ieee80211_setup_basic_htrates(ni,
1887 1.75.4.1 phil ni->ni_ies.htinfo_ie);
1888 1.46 dyoung
1889 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1890 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1891 1.46 dyoung
1892 1.75.4.1 phil /* Reassociate; we're now 11n/11ac */
1893 1.75.4.1 phil /*
1894 1.75.4.1 phil * XXX TODO: this is the wrong thing to do -
1895 1.75.4.1 phil * we're calling it with isnew=1 so the ath(4)
1896 1.75.4.1 phil * driver reinitialises the rate tables.
1897 1.75.4.1 phil * This "mostly" works for ath(4), but it won't
1898 1.75.4.1 phil * be right for firmware devices which allocate
1899 1.75.4.1 phil * node states.
1900 1.75.4.1 phil *
1901 1.75.4.1 phil * So, do we just create a new node and delete
1902 1.75.4.1 phil * the old one? Or?
1903 1.75.4.1 phil */
1904 1.75.4.1 phil if (ni->ni_ic->ic_newassoc)
1905 1.75.4.1 phil ni->ni_ic->ic_newassoc(ni, 1);
1906 1.75.4.1 phil }
1907 1.46 dyoung }
1908 1.46 dyoung
1909 1.45 skrll /*
1910 1.45 skrll * Do node discovery in adhoc mode on receipt of a beacon
1911 1.45 skrll * or probe response frame. Note that for the driver's
1912 1.45 skrll * benefit we we treat this like an association so the
1913 1.75.4.1 phil * driver has an opportunity to setup it's private state.
1914 1.45 skrll */
1915 1.45 skrll struct ieee80211_node *
1916 1.75.4.1 phil ieee80211_add_neighbor(struct ieee80211vap *vap,
1917 1.45 skrll const struct ieee80211_frame *wh,
1918 1.45 skrll const struct ieee80211_scanparams *sp)
1919 1.45 skrll {
1920 1.45 skrll struct ieee80211_node *ni;
1921 1.45 skrll
1922 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
1923 1.75.4.1 phil "%s: mac<%s>\n", __func__, ether_sprintf(wh->i_addr2));
1924 1.75.4.1 phil ni = ieee80211_dup_bss(vap, wh->i_addr2);/* XXX alloc_node? */
1925 1.45 skrll if (ni != NULL) {
1926 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
1927 1.75.4.1 phil
1928 1.75.4.1 phil ieee80211_init_neighbor(ni, wh, sp);
1929 1.75.4.1 phil if (ieee80211_iserp_rateset(&ni->ni_rates))
1930 1.75.4.1 phil ni->ni_flags |= IEEE80211_NODE_ERP;
1931 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
1932 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
1933 1.75.4.1 phil if (ic->ic_newassoc != NULL)
1934 1.75.4.1 phil ic->ic_newassoc(ni, 1);
1935 1.39 dyoung /* XXX not right for 802.1x/WPA */
1936 1.45 skrll ieee80211_node_authorize(ni);
1937 1.7 dyoung }
1938 1.39 dyoung return ni;
1939 1.7 dyoung }
1940 1.7 dyoung
1941 1.75.4.1 phil #define IS_PROBEREQ(wh) \
1942 1.75.4.1 phil ((wh->i_fc[0] & (IEEE80211_FC0_TYPE_MASK|IEEE80211_FC0_SUBTYPE_MASK)) \
1943 1.75.4.1 phil == (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ))
1944 1.75.4.1 phil #define IS_BCAST_PROBEREQ(wh) \
1945 1.75.4.1 phil (IS_PROBEREQ(wh) && IEEE80211_IS_MULTICAST( \
1946 1.75.4.1 phil ((const struct ieee80211_frame *)(wh))->i_addr3))
1947 1.75.4.1 phil
1948 1.75.4.1 phil static __inline struct ieee80211_node *
1949 1.75.4.1 phil _find_rxnode(struct ieee80211_node_table *nt,
1950 1.75.4.1 phil const struct ieee80211_frame_min *wh)
1951 1.75.4.1 phil {
1952 1.75.4.1 phil if (IS_BCAST_PROBEREQ(wh))
1953 1.75.4.1 phil return NULL; /* spam bcast probe req to all vap's */
1954 1.75.4.1 phil return ieee80211_find_node_locked(nt, wh->i_addr2);
1955 1.75.4.1 phil }
1956 1.75.4.1 phil
1957 1.7 dyoung /*
1958 1.39 dyoung * Locate the node for sender, track state, and then pass the
1959 1.75.4.1 phil * (referenced) node up to the 802.11 layer for its use. Note
1960 1.75.4.1 phil * we can return NULL if the sender is not in the table.
1961 1.7 dyoung */
1962 1.39 dyoung struct ieee80211_node *
1963 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
1964 1.39 dyoung ieee80211_find_rxnode_debug(struct ieee80211com *ic,
1965 1.39 dyoung const struct ieee80211_frame_min *wh, const char *func, int line)
1966 1.39 dyoung #else
1967 1.39 dyoung ieee80211_find_rxnode(struct ieee80211com *ic,
1968 1.39 dyoung const struct ieee80211_frame_min *wh)
1969 1.39 dyoung #endif
1970 1.7 dyoung {
1971 1.39 dyoung struct ieee80211_node_table *nt;
1972 1.39 dyoung struct ieee80211_node *ni;
1973 1.7 dyoung
1974 1.75.4.1 phil nt = &ic->ic_sta;
1975 1.39 dyoung IEEE80211_NODE_LOCK(nt);
1976 1.75.4.1 phil ni = _find_rxnode(nt, wh);
1977 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
1978 1.7 dyoung
1979 1.45 skrll return ni;
1980 1.45 skrll }
1981 1.45 skrll
1982 1.45 skrll /*
1983 1.45 skrll * Like ieee80211_find_rxnode but use the supplied h/w
1984 1.45 skrll * key index as a hint to locate the node in the key
1985 1.45 skrll * mapping table. If an entry is present at the key
1986 1.45 skrll * index we return it; otherwise do a normal lookup and
1987 1.45 skrll * update the mapping table if the station has a unicast
1988 1.45 skrll * key assigned to it.
1989 1.45 skrll */
1990 1.45 skrll struct ieee80211_node *
1991 1.45 skrll #ifdef IEEE80211_DEBUG_REFCNT
1992 1.45 skrll ieee80211_find_rxnode_withkey_debug(struct ieee80211com *ic,
1993 1.45 skrll const struct ieee80211_frame_min *wh, ieee80211_keyix keyix,
1994 1.45 skrll const char *func, int line)
1995 1.45 skrll #else
1996 1.45 skrll ieee80211_find_rxnode_withkey(struct ieee80211com *ic,
1997 1.45 skrll const struct ieee80211_frame_min *wh, ieee80211_keyix keyix)
1998 1.45 skrll #endif
1999 1.45 skrll {
2000 1.45 skrll struct ieee80211_node_table *nt;
2001 1.45 skrll struct ieee80211_node *ni;
2002 1.45 skrll
2003 1.75.4.1 phil nt = &ic->ic_sta;
2004 1.45 skrll IEEE80211_NODE_LOCK(nt);
2005 1.75.4.1 phil if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax)
2006 1.45 skrll ni = nt->nt_keyixmap[keyix];
2007 1.75.4.1 phil else
2008 1.45 skrll ni = NULL;
2009 1.45 skrll if (ni == NULL) {
2010 1.75.4.1 phil ni = _find_rxnode(nt, wh);
2011 1.75.4.1 phil if (ni != NULL && nt->nt_keyixmap != NULL) {
2012 1.45 skrll /*
2013 1.45 skrll * If the station has a unicast key cache slot
2014 1.45 skrll * assigned update the key->node mapping table.
2015 1.45 skrll */
2016 1.45 skrll keyix = ni->ni_ucastkey.wk_rxkeyix;
2017 1.45 skrll /* XXX can keyixmap[keyix] != NULL? */
2018 1.45 skrll if (keyix < nt->nt_keyixmax &&
2019 1.45 skrll nt->nt_keyixmap[keyix] == NULL) {
2020 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap,
2021 1.75.4.1 phil IEEE80211_MSG_NODE,
2022 1.45 skrll "%s: add key map entry %p<%s> refcnt %d\n",
2023 1.45 skrll __func__, ni, ether_sprintf(ni->ni_macaddr),
2024 1.45 skrll ieee80211_node_refcnt(ni)+1);
2025 1.45 skrll nt->nt_keyixmap[keyix] = ieee80211_ref_node(ni);
2026 1.45 skrll }
2027 1.45 skrll }
2028 1.45 skrll } else {
2029 1.75.4.1 phil if (IS_BCAST_PROBEREQ(wh))
2030 1.75.4.1 phil ni = NULL; /* spam bcast probe req to all vap's */
2031 1.75.4.1 phil else
2032 1.75.4.1 phil ieee80211_ref_node(ni);
2033 1.45 skrll }
2034 1.45 skrll IEEE80211_NODE_UNLOCK(nt);
2035 1.45 skrll
2036 1.45 skrll return ni;
2037 1.45 skrll }
2038 1.75.4.1 phil #undef IS_BCAST_PROBEREQ
2039 1.75.4.1 phil #undef IS_PROBEREQ
2040 1.7 dyoung
2041 1.39 dyoung /*
2042 1.39 dyoung * Return a reference to the appropriate node for sending
2043 1.39 dyoung * a data frame. This handles node discovery in adhoc networks.
2044 1.33 dyoung */
2045 1.7 dyoung struct ieee80211_node *
2046 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
2047 1.75.4.1 phil ieee80211_find_txnode_debug(struct ieee80211vap *vap,
2048 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN],
2049 1.39 dyoung const char *func, int line)
2050 1.39 dyoung #else
2051 1.75.4.1 phil ieee80211_find_txnode(struct ieee80211vap *vap,
2052 1.75.4.1 phil const uint8_t macaddr[IEEE80211_ADDR_LEN])
2053 1.39 dyoung #endif
2054 1.7 dyoung {
2055 1.75.4.1 phil struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
2056 1.7 dyoung struct ieee80211_node *ni;
2057 1.7 dyoung
2058 1.39 dyoung /*
2059 1.39 dyoung * The destination address should be in the node table
2060 1.45 skrll * unless this is a multicast/broadcast frame. We can
2061 1.45 skrll * also optimize station mode operation, all frames go
2062 1.45 skrll * to the bss node.
2063 1.39 dyoung */
2064 1.39 dyoung /* XXX can't hold lock across dup_bss 'cuz of recursive locking */
2065 1.39 dyoung IEEE80211_NODE_LOCK(nt);
2066 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_STA ||
2067 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_WDS ||
2068 1.75.4.1 phil IEEE80211_IS_MULTICAST(macaddr))
2069 1.75.4.1 phil ni = ieee80211_ref_node(vap->iv_bss);
2070 1.45 skrll else
2071 1.75.4.1 phil ni = ieee80211_find_node_locked(nt, macaddr);
2072 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
2073 1.15 dyoung
2074 1.39 dyoung if (ni == NULL) {
2075 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_IBSS ||
2076 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_AHDEMO) {
2077 1.39 dyoung /*
2078 1.39 dyoung * In adhoc mode cons up a node for the destination.
2079 1.39 dyoung * Note that we need an additional reference for the
2080 1.75.4.1 phil * caller to be consistent with
2081 1.75.4.1 phil * ieee80211_find_node_locked.
2082 1.75.4.1 phil */
2083 1.75.4.1 phil /*
2084 1.75.4.1 phil * XXX TODO: this doesn't fake up 11n state; we need
2085 1.75.4.1 phil * to find another way to get it upgraded.
2086 1.39 dyoung */
2087 1.75.4.1 phil ni = ieee80211_fakeup_adhoc_node(vap, macaddr);
2088 1.39 dyoung if (ni != NULL)
2089 1.75.4.1 phil (void) ieee80211_ref_node(ni);
2090 1.39 dyoung } else {
2091 1.75.4.1 phil IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_OUTPUT, macaddr,
2092 1.75.4.1 phil "no node, discard frame (%s)", __func__);
2093 1.75.4.1 phil vap->iv_stats.is_tx_nonode++;
2094 1.39 dyoung }
2095 1.39 dyoung }
2096 1.39 dyoung return ni;
2097 1.1 dyoung }
2098 1.1 dyoung
2099 1.75.4.1 phil static void
2100 1.75.4.1 phil _ieee80211_free_node(struct ieee80211_node *ni)
2101 1.1 dyoung {
2102 1.75.4.1 phil struct ieee80211_node_table *nt = ni->ni_table;
2103 1.75 maxv
2104 1.75.4.1 phil /*
2105 1.75.4.1 phil * NB: careful about referencing the vap as it may be
2106 1.75.4.1 phil * gone if the last reference was held by a driver.
2107 1.75.4.1 phil * We know the com will always be present so it's safe
2108 1.75.4.1 phil * to use ni_ic below to reclaim resources.
2109 1.75.4.1 phil */
2110 1.75.4.1 phil #if 0
2111 1.75.4.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2112 1.75.4.1 phil "%s %p<%s> in %s table\n", __func__, ni,
2113 1.75.4.1 phil ether_sprintf(ni->ni_macaddr),
2114 1.75.4.1 phil nt != NULL ? nt->nt_name : "<gone>");
2115 1.61 gmcgarry #endif
2116 1.75.4.1 phil if (ni->ni_associd != 0) {
2117 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2118 1.75.4.1 phil if (vap->iv_aid_bitmap != NULL)
2119 1.75.4.1 phil IEEE80211_AID_CLR(vap, ni->ni_associd);
2120 1.1 dyoung }
2121 1.75.4.1 phil if (nt != NULL)
2122 1.75.4.1 phil ieee80211_del_node_nt(nt, ni);
2123 1.75.4.1 phil ni->ni_ic->ic_node_free(ni);
2124 1.1 dyoung }
2125 1.1 dyoung
2126 1.39 dyoung /*
2127 1.75.4.1 phil * Clear any entry in the unicast key mapping table.
2128 1.39 dyoung */
2129 1.75.4.1 phil static int
2130 1.75.4.1 phil node_clear_keyixmap(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
2131 1.39 dyoung {
2132 1.75.4.1 phil ieee80211_keyix keyix;
2133 1.72 christos
2134 1.75.4.1 phil keyix = ni->ni_ucastkey.wk_rxkeyix;
2135 1.75.4.1 phil if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax &&
2136 1.75.4.1 phil nt->nt_keyixmap[keyix] == ni) {
2137 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2138 1.75.4.1 phil "%s: %p<%s> clear key map entry %u\n",
2139 1.75.4.1 phil __func__, ni, ether_sprintf(ni->ni_macaddr), keyix);
2140 1.75.4.1 phil nt->nt_keyixmap[keyix] = NULL;
2141 1.75.4.1 phil ieee80211_node_decref(ni);
2142 1.75.4.1 phil return 1;
2143 1.39 dyoung }
2144 1.75 maxv
2145 1.75.4.1 phil return 0;
2146 1.1 dyoung }
2147 1.1 dyoung
2148 1.1 dyoung void
2149 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
2150 1.39 dyoung ieee80211_free_node_debug(struct ieee80211_node *ni, const char *func, int line)
2151 1.39 dyoung #else
2152 1.39 dyoung ieee80211_free_node(struct ieee80211_node *ni)
2153 1.39 dyoung #endif
2154 1.39 dyoung {
2155 1.39 dyoung struct ieee80211_node_table *nt = ni->ni_table;
2156 1.39 dyoung
2157 1.39 dyoung #ifdef IEEE80211_DEBUG_REFCNT
2158 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2159 1.39 dyoung "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line, ni,
2160 1.39 dyoung ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)-1);
2161 1.39 dyoung #endif
2162 1.45 skrll if (nt != NULL) {
2163 1.45 skrll IEEE80211_NODE_LOCK(nt);
2164 1.45 skrll if (ieee80211_node_dectestref(ni)) {
2165 1.45 skrll /*
2166 1.45 skrll * Last reference, reclaim state.
2167 1.45 skrll */
2168 1.39 dyoung _ieee80211_free_node(ni);
2169 1.75.4.1 phil } else if (ieee80211_node_refcnt(ni) == 1)
2170 1.75.4.1 phil if (node_clear_keyixmap(nt, ni))
2171 1.45 skrll _ieee80211_free_node(ni);
2172 1.45 skrll IEEE80211_NODE_UNLOCK(nt);
2173 1.45 skrll } else {
2174 1.45 skrll if (ieee80211_node_dectestref(ni))
2175 1.39 dyoung _ieee80211_free_node(ni);
2176 1.39 dyoung }
2177 1.39 dyoung }
2178 1.39 dyoung
2179 1.39 dyoung /*
2180 1.45 skrll * Reclaim a unicast key and clear any key cache state.
2181 1.45 skrll */
2182 1.45 skrll int
2183 1.45 skrll ieee80211_node_delucastkey(struct ieee80211_node *ni)
2184 1.45 skrll {
2185 1.45 skrll struct ieee80211com *ic = ni->ni_ic;
2186 1.45 skrll struct ieee80211_node_table *nt = &ic->ic_sta;
2187 1.45 skrll struct ieee80211_node *nikey;
2188 1.45 skrll ieee80211_keyix keyix;
2189 1.45 skrll int isowned, status;
2190 1.45 skrll
2191 1.45 skrll /*
2192 1.45 skrll * NB: We must beware of LOR here; deleting the key
2193 1.45 skrll * can cause the crypto layer to block traffic updates
2194 1.45 skrll * which can generate a LOR against the node table lock;
2195 1.45 skrll * grab it here and stash the key index for our use below.
2196 1.45 skrll *
2197 1.45 skrll * Must also beware of recursion on the node table lock.
2198 1.45 skrll * When called from node_cleanup we may already have
2199 1.45 skrll * the node table lock held. Unfortunately there's no
2200 1.45 skrll * way to separate out this path so we must do this
2201 1.45 skrll * conditionally.
2202 1.45 skrll */
2203 1.45 skrll isowned = IEEE80211_NODE_IS_LOCKED(nt);
2204 1.45 skrll if (!isowned)
2205 1.45 skrll IEEE80211_NODE_LOCK(nt);
2206 1.75.4.1 phil nikey = NULL;
2207 1.75.4.1 phil status = 1; /* NB: success */
2208 1.75.4.1 phil if (ni->ni_ucastkey.wk_keyix != IEEE80211_KEYIX_NONE) {
2209 1.75.4.1 phil keyix = ni->ni_ucastkey.wk_rxkeyix;
2210 1.75.4.1 phil status = ieee80211_crypto_delkey(ni->ni_vap, &ni->ni_ucastkey);
2211 1.75.4.1 phil if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax) {
2212 1.75.4.1 phil nikey = nt->nt_keyixmap[keyix];
2213 1.75.4.1 phil nt->nt_keyixmap[keyix] = NULL;
2214 1.75.4.1 phil }
2215 1.75.4.1 phil }
2216 1.45 skrll if (!isowned)
2217 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
2218 1.45 skrll
2219 1.45 skrll if (nikey != NULL) {
2220 1.75.4.1 phil KASSERT(nikey == ni,
2221 1.45 skrll ("key map out of sync, ni %p nikey %p", ni, nikey));
2222 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2223 1.45 skrll "%s: delete key map entry %p<%s> refcnt %d\n",
2224 1.45 skrll __func__, ni, ether_sprintf(ni->ni_macaddr),
2225 1.45 skrll ieee80211_node_refcnt(ni)-1);
2226 1.45 skrll ieee80211_free_node(ni);
2227 1.45 skrll }
2228 1.45 skrll return status;
2229 1.45 skrll }
2230 1.45 skrll
2231 1.45 skrll /*
2232 1.39 dyoung * Reclaim a node. If this is the last reference count then
2233 1.39 dyoung * do the normal free work. Otherwise remove it from the node
2234 1.39 dyoung * table and mark it gone by clearing the back-reference.
2235 1.39 dyoung */
2236 1.39 dyoung static void
2237 1.39 dyoung node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
2238 1.39 dyoung {
2239 1.45 skrll
2240 1.45 skrll IEEE80211_NODE_LOCK_ASSERT(nt);
2241 1.39 dyoung
2242 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
2243 1.39 dyoung "%s: remove %p<%s> from %s table, refcnt %d\n",
2244 1.39 dyoung __func__, ni, ether_sprintf(ni->ni_macaddr),
2245 1.39 dyoung nt->nt_name, ieee80211_node_refcnt(ni)-1);
2246 1.45 skrll /*
2247 1.45 skrll * Clear any entry in the unicast key mapping table.
2248 1.45 skrll * We need to do it here so rx lookups don't find it
2249 1.45 skrll * in the mapping table even if it's not in the hash
2250 1.45 skrll * table. We cannot depend on the mapping table entry
2251 1.45 skrll * being cleared because the node may not be free'd.
2252 1.45 skrll */
2253 1.75.4.1 phil (void)node_clear_keyixmap(nt, ni);
2254 1.75.4.1 phil if (!ieee80211_node_dectestref(ni)) {
2255 1.75.4.1 phil /*
2256 1.75.4.1 phil * Other references are present, just remove the
2257 1.75.4.1 phil * node from the table so it cannot be found. When
2258 1.75.4.1 phil * the references are dropped storage will be
2259 1.75.4.1 phil * reclaimed.
2260 1.75.4.1 phil */
2261 1.75.4.1 phil ieee80211_del_node_nt(nt, ni);
2262 1.75.4.1 phil } else
2263 1.75.4.1 phil _ieee80211_free_node(ni);
2264 1.75.4.1 phil }
2265 1.75.4.1 phil
2266 1.75.4.1 phil /*
2267 1.75.4.1 phil * Node table support.
2268 1.75.4.1 phil */
2269 1.75.4.1 phil
2270 1.75.4.1 phil static void
2271 1.75.4.1 phil ieee80211_node_table_init(struct ieee80211com *ic,
2272 1.75.4.1 phil struct ieee80211_node_table *nt,
2273 1.75.4.1 phil const char *name, int inact, int keyixmax)
2274 1.75.4.1 phil {
2275 1.75.4.1 phil
2276 1.75.4.1 phil nt->nt_ic = ic;
2277 1.75.4.1 phil IEEE80211_NODE_LOCK_INIT(nt, ic->ic_name);
2278 1.75.4.1 phil TAILQ_INIT(&nt->nt_node);
2279 1.75.4.1 phil nt->nt_count = 0;
2280 1.75.4.1 phil nt->nt_name = name;
2281 1.75.4.1 phil nt->nt_inact_init = inact;
2282 1.75.4.1 phil nt->nt_keyixmax = keyixmax;
2283 1.75.4.1 phil if (nt->nt_keyixmax > 0) {
2284 1.75.4.1 phil nt->nt_keyixmap = (struct ieee80211_node **) IEEE80211_MALLOC(
2285 1.75.4.1 phil keyixmax * sizeof(struct ieee80211_node *),
2286 1.75.4.1 phil M_80211_NODE,
2287 1.75.4.1 phil IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
2288 1.75.4.1 phil if (nt->nt_keyixmap == NULL)
2289 1.75.4.1 phil ic_printf(ic,
2290 1.75.4.1 phil "Cannot allocate key index map with %u entries\n",
2291 1.75.4.1 phil keyixmax);
2292 1.75.4.1 phil } else
2293 1.75.4.1 phil nt->nt_keyixmap = NULL;
2294 1.75.4.1 phil }
2295 1.75.4.1 phil
2296 1.75.4.1 phil static void
2297 1.75.4.1 phil ieee80211_node_table_reset(struct ieee80211_node_table *nt,
2298 1.75.4.1 phil struct ieee80211vap *match)
2299 1.75.4.1 phil {
2300 1.75.4.1 phil struct ieee80211_node *ni, *next;
2301 1.75.4.1 phil
2302 1.75.4.1 phil IEEE80211_NODE_LOCK(nt);
2303 1.75.4.1 phil TAILQ_FOREACH_SAFE(ni, &nt->nt_node, ni_list, next) {
2304 1.75.4.1 phil if (match != NULL && ni->ni_vap != match)
2305 1.75.4.1 phil continue;
2306 1.75.4.1 phil /* XXX can this happen? if so need's work */
2307 1.75.4.1 phil if (ni->ni_associd != 0) {
2308 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2309 1.75.4.1 phil
2310 1.75.4.1 phil if (vap->iv_auth->ia_node_leave != NULL)
2311 1.75.4.1 phil vap->iv_auth->ia_node_leave(ni);
2312 1.75.4.1 phil if (vap->iv_aid_bitmap != NULL)
2313 1.75.4.1 phil IEEE80211_AID_CLR(vap, ni->ni_associd);
2314 1.75.4.1 phil }
2315 1.75.4.1 phil ni->ni_wdsvap = NULL; /* clear reference */
2316 1.75.4.1 phil node_reclaim(nt, ni);
2317 1.75.4.1 phil }
2318 1.75.4.1 phil if (match != NULL && match->iv_opmode == IEEE80211_M_WDS) {
2319 1.75.4.1 phil /*
2320 1.75.4.1 phil * Make a separate pass to clear references to this vap
2321 1.75.4.1 phil * held by DWDS entries. They will not be matched above
2322 1.75.4.1 phil * because ni_vap will point to the ap vap but we still
2323 1.75.4.1 phil * need to clear ni_wdsvap when the WDS vap is destroyed
2324 1.75.4.1 phil * and/or reset.
2325 1.75.4.1 phil */
2326 1.75.4.1 phil TAILQ_FOREACH_SAFE(ni, &nt->nt_node, ni_list, next)
2327 1.75.4.1 phil if (ni->ni_wdsvap == match)
2328 1.75.4.1 phil ni->ni_wdsvap = NULL;
2329 1.75.4.1 phil }
2330 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
2331 1.75.4.1 phil }
2332 1.75.4.1 phil
2333 1.75.4.1 phil static void
2334 1.75.4.1 phil ieee80211_node_table_cleanup(struct ieee80211_node_table *nt)
2335 1.75.4.1 phil {
2336 1.75.4.1 phil ieee80211_node_table_reset(nt, NULL);
2337 1.75.4.1 phil if (nt->nt_keyixmap != NULL) {
2338 1.75.4.1 phil #ifdef DIAGNOSTIC
2339 1.75.4.1 phil /* XXX verify all entries are NULL */
2340 1.75.4.1 phil int i;
2341 1.75.4.1 phil for (i = 0; i < nt->nt_keyixmax; i++)
2342 1.75.4.1 phil if (nt->nt_keyixmap[i] != NULL)
2343 1.75.4.1 phil printf("%s: %s[%u] still active\n", __func__,
2344 1.75.4.1 phil nt->nt_name, i);
2345 1.75.4.1 phil #endif
2346 1.75.4.1 phil IEEE80211_FREE(nt->nt_keyixmap, M_80211_NODE);
2347 1.75.4.1 phil nt->nt_keyixmap = NULL;
2348 1.75.4.1 phil }
2349 1.75.4.1 phil IEEE80211_NODE_LOCK_DESTROY(nt);
2350 1.75.4.1 phil }
2351 1.75.4.1 phil
2352 1.75.4.1 phil static void
2353 1.75.4.1 phil timeout_stations(void *arg __unused, struct ieee80211_node *ni)
2354 1.75.4.1 phil {
2355 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2356 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2357 1.75.4.1 phil
2358 1.75.4.1 phil /*
2359 1.75.4.1 phil * Only process stations when in RUN state. This
2360 1.75.4.1 phil * insures, for example, that we don't timeout an
2361 1.75.4.1 phil * inactive station during CAC. Note that CSA state
2362 1.75.4.1 phil * is actually handled in ieee80211_node_timeout as
2363 1.75.4.1 phil * it applies to more than timeout processing.
2364 1.75.4.1 phil */
2365 1.75.4.1 phil if (vap->iv_state != IEEE80211_S_RUN)
2366 1.75.4.1 phil return;
2367 1.75.4.1 phil /*
2368 1.75.4.1 phil * Ignore entries for which have yet to receive an
2369 1.75.4.1 phil * authentication frame. These are transient and
2370 1.75.4.1 phil * will be reclaimed when the last reference to them
2371 1.75.4.1 phil * goes away (when frame xmits complete).
2372 1.75.4.1 phil */
2373 1.75.4.1 phil if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
2374 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_STA) &&
2375 1.75.4.1 phil (ni->ni_flags & IEEE80211_NODE_AREF) == 0)
2376 1.75.4.1 phil return;
2377 1.75.4.1 phil /*
2378 1.75.4.1 phil * Free fragment if not needed anymore
2379 1.75.4.1 phil * (last fragment older than 1s).
2380 1.75.4.1 phil * XXX doesn't belong here, move to node_age
2381 1.75.4.1 phil */
2382 1.75.4.1 phil if (ni->ni_rxfrag[0] != NULL &&
2383 1.75.4.1 phil ticks > ni->ni_rxfragstamp + hz) {
2384 1.75.4.1 phil m_freem(ni->ni_rxfrag[0]);
2385 1.75.4.1 phil ni->ni_rxfrag[0] = NULL;
2386 1.75.4.1 phil }
2387 1.75.4.1 phil if (ni->ni_inact > 0) {
2388 1.75.4.1 phil ni->ni_inact--;
2389 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
2390 1.75.4.1 phil "%s: inact %u inact_reload %u nrates %u",
2391 1.75.4.1 phil __func__, ni->ni_inact, ni->ni_inact_reload,
2392 1.75.4.1 phil ni->ni_rates.rs_nrates);
2393 1.75.4.1 phil }
2394 1.75.4.1 phil /*
2395 1.75.4.1 phil * Special case ourself; we may be idle for extended periods
2396 1.75.4.1 phil * of time and regardless reclaiming our state is wrong.
2397 1.75.4.1 phil * XXX run ic_node_age
2398 1.75.4.1 phil */
2399 1.75.4.1 phil /* XXX before inact decrement? */
2400 1.75.4.1 phil if (ni == vap->iv_bss)
2401 1.75.4.1 phil return;
2402 1.75.4.1 phil if (ni->ni_associd != 0 ||
2403 1.75.4.1 phil (vap->iv_opmode == IEEE80211_M_IBSS ||
2404 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_AHDEMO)) {
2405 1.75.4.1 phil /*
2406 1.75.4.1 phil * Age/drain resources held by the station.
2407 1.75.4.1 phil */
2408 1.75.4.1 phil ic->ic_node_age(ni);
2409 1.75.4.1 phil /*
2410 1.75.4.1 phil * Probe the station before time it out. We
2411 1.75.4.1 phil * send a null data frame which may not be
2412 1.75.4.1 phil * universally supported by drivers (need it
2413 1.75.4.1 phil * for ps-poll support so it should be...).
2414 1.75.4.1 phil *
2415 1.75.4.1 phil * XXX don't probe the station unless we've
2416 1.75.4.1 phil * received a frame from them (and have
2417 1.75.4.1 phil * some idea of the rates they are capable
2418 1.75.4.1 phil * of); this will get fixed more properly
2419 1.75.4.1 phil * soon with better handling of the rate set.
2420 1.75.4.1 phil */
2421 1.75.4.1 phil if ((vap->iv_flags_ext & IEEE80211_FEXT_INACT) &&
2422 1.75.4.1 phil (0 < ni->ni_inact &&
2423 1.75.4.1 phil ni->ni_inact <= vap->iv_inact_probe) &&
2424 1.75.4.1 phil ni->ni_rates.rs_nrates != 0) {
2425 1.75.4.1 phil IEEE80211_NOTE(vap,
2426 1.75.4.1 phil IEEE80211_MSG_INACT | IEEE80211_MSG_NODE,
2427 1.75.4.1 phil ni, "%s",
2428 1.75.4.1 phil "probe station due to inactivity");
2429 1.75.4.1 phil /*
2430 1.75.4.1 phil * Grab a reference so the node cannot
2431 1.75.4.1 phil * be reclaimed before we send the frame.
2432 1.75.4.1 phil * ieee80211_send_nulldata understands
2433 1.75.4.1 phil * we've done this and reclaims the
2434 1.75.4.1 phil * ref for us as needed.
2435 1.75.4.1 phil */
2436 1.75.4.1 phil /* XXX fix this (not required anymore). */
2437 1.75.4.1 phil ieee80211_ref_node(ni);
2438 1.75.4.1 phil /* XXX useless */
2439 1.75.4.1 phil ieee80211_send_nulldata(ni);
2440 1.75.4.1 phil /* XXX stat? */
2441 1.75.4.1 phil return;
2442 1.75.4.1 phil }
2443 1.45 skrll }
2444 1.75.4.1 phil if ((vap->iv_flags_ext & IEEE80211_FEXT_INACT) &&
2445 1.75.4.1 phil ni->ni_inact <= 0) {
2446 1.75.4.1 phil IEEE80211_NOTE(vap,
2447 1.75.4.1 phil IEEE80211_MSG_INACT | IEEE80211_MSG_NODE, ni,
2448 1.75.4.1 phil "station timed out due to inactivity "
2449 1.75.4.1 phil "(refcnt %u)", ieee80211_node_refcnt(ni));
2450 1.39 dyoung /*
2451 1.75.4.1 phil * Send a deauthenticate frame and drop the station.
2452 1.75.4.1 phil * This is somewhat complicated due to reference counts
2453 1.75.4.1 phil * and locking. At this point a station will typically
2454 1.75.4.1 phil * have a reference count of 2. ieee80211_node_leave
2455 1.75.4.1 phil * will do a "free" of the node which will drop the
2456 1.75.4.1 phil * reference count. But in the meantime a reference
2457 1.75.4.1 phil * wil be held by the deauth frame. The actual reclaim
2458 1.75.4.1 phil * of the node will happen either after the tx is
2459 1.75.4.1 phil * completed or by ieee80211_node_leave.
2460 1.39 dyoung */
2461 1.39 dyoung if (ni->ni_associd != 0) {
2462 1.75.4.1 phil IEEE80211_SEND_MGMT(ni,
2463 1.75.4.1 phil IEEE80211_FC0_SUBTYPE_DEAUTH,
2464 1.75.4.1 phil IEEE80211_REASON_AUTH_EXPIRE);
2465 1.39 dyoung }
2466 1.75.4.1 phil ieee80211_node_leave(ni);
2467 1.75.4.1 phil vap->iv_stats.is_node_timeout++;
2468 1.1 dyoung }
2469 1.39 dyoung }
2470 1.39 dyoung
2471 1.39 dyoung /*
2472 1.75.4.1 phil * Timeout inactive stations and do related housekeeping.
2473 1.39 dyoung */
2474 1.39 dyoung static void
2475 1.75.4.1 phil ieee80211_timeout_stations(struct ieee80211com *ic)
2476 1.1 dyoung {
2477 1.75.4.1 phil struct ieee80211_node_table *nt = &ic->ic_sta;
2478 1.22 mycroft
2479 1.75.4.1 phil ieee80211_iterate_nodes(nt, timeout_stations, NULL);
2480 1.1 dyoung }
2481 1.1 dyoung
2482 1.9 dyoung /*
2483 1.75.4.1 phil * Aggressively reclaim resources. This should be used
2484 1.75.4.1 phil * only in a critical situation to reclaim mbuf resources.
2485 1.9 dyoung */
2486 1.75.4.1 phil void
2487 1.75.4.1 phil ieee80211_drain(struct ieee80211com *ic)
2488 1.1 dyoung {
2489 1.75.4.1 phil struct ieee80211_node_table *nt = &ic->ic_sta;
2490 1.75.4.1 phil struct ieee80211vap *vap;
2491 1.9 dyoung struct ieee80211_node *ni;
2492 1.66 christos
2493 1.39 dyoung IEEE80211_NODE_LOCK(nt);
2494 1.39 dyoung TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
2495 1.39 dyoung /*
2496 1.42 dyoung * Ignore entries for which have yet to receive an
2497 1.42 dyoung * authentication frame. These are transient and
2498 1.42 dyoung * will be reclaimed when the last reference to them
2499 1.42 dyoung * goes away (when frame xmits complete).
2500 1.42 dyoung */
2501 1.75.4.1 phil vap = ni->ni_vap;
2502 1.75.4.1 phil /*
2503 1.75.4.1 phil * Only process stations when in RUN state. This
2504 1.75.4.1 phil * insures, for example, that we don't timeout an
2505 1.75.4.1 phil * inactive station during CAC. Note that CSA state
2506 1.75.4.1 phil * is actually handled in ieee80211_node_timeout as
2507 1.75.4.1 phil * it applies to more than timeout processing.
2508 1.75.4.1 phil */
2509 1.75.4.1 phil if (vap->iv_state != IEEE80211_S_RUN)
2510 1.75.4.1 phil continue;
2511 1.75.4.1 phil /* XXX can vap be NULL? */
2512 1.75.4.1 phil if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
2513 1.75.4.1 phil vap->iv_opmode == IEEE80211_M_STA) &&
2514 1.45 skrll (ni->ni_flags & IEEE80211_NODE_AREF) == 0)
2515 1.42 dyoung continue;
2516 1.42 dyoung /*
2517 1.75.4.1 phil * Free fragments.
2518 1.75.4.1 phil * XXX doesn't belong here, move to node_drain
2519 1.39 dyoung */
2520 1.75.4.1 phil if (ni->ni_rxfrag[0] != NULL) {
2521 1.39 dyoung m_freem(ni->ni_rxfrag[0]);
2522 1.39 dyoung ni->ni_rxfrag[0] = NULL;
2523 1.39 dyoung }
2524 1.39 dyoung /*
2525 1.75.4.1 phil * Drain resources held by the station.
2526 1.39 dyoung */
2527 1.75.4.1 phil ic->ic_node_drain(ni);
2528 1.1 dyoung }
2529 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
2530 1.1 dyoung }
2531 1.1 dyoung
2532 1.75.4.1 phil /*
2533 1.75.4.1 phil * Per-ieee80211com inactivity timer callback.
2534 1.75.4.1 phil */
2535 1.1 dyoung void
2536 1.75.4.1 phil ieee80211_node_timeout(void *arg)
2537 1.1 dyoung {
2538 1.75.4.1 phil struct ieee80211com *ic = arg;
2539 1.39 dyoung
2540 1.75.4.1 phil /*
2541 1.75.4.1 phil * Defer timeout processing if a channel switch is pending.
2542 1.75.4.1 phil * We typically need to be mute so not doing things that
2543 1.75.4.1 phil * might generate frames is good to handle in one place.
2544 1.75.4.1 phil * Suppressing the station timeout processing may extend the
2545 1.75.4.1 phil * lifetime of inactive stations (by not decrementing their
2546 1.75.4.1 phil * idle counters) but this should be ok unless the CSA is
2547 1.75.4.1 phil * active for an unusually long time.
2548 1.75.4.1 phil */
2549 1.75.4.1 phil if ((ic->ic_flags & IEEE80211_F_CSAPENDING) == 0) {
2550 1.75.4.1 phil ieee80211_scan_timeout(ic);
2551 1.75.4.1 phil ieee80211_timeout_stations(ic);
2552 1.75.4.1 phil ieee80211_ageq_age(&ic->ic_stageq, IEEE80211_INACT_WAIT);
2553 1.75.4.1 phil
2554 1.75.4.1 phil IEEE80211_LOCK(ic);
2555 1.75.4.1 phil ieee80211_erp_timeout(ic);
2556 1.75.4.1 phil ieee80211_ht_timeout(ic);
2557 1.75.4.1 phil ieee80211_vht_timeout(ic);
2558 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2559 1.66 christos }
2560 1.75.4.1 phil callout_reset(&ic->ic_inact, IEEE80211_INACT_WAIT*hz,
2561 1.75.4.1 phil ieee80211_node_timeout, ic);
2562 1.75.4.1 phil }
2563 1.75.4.1 phil
2564 1.75.4.1 phil /*
2565 1.75.4.1 phil * The same as ieee80211_iterate_nodes(), but for one vap only.
2566 1.75.4.1 phil */
2567 1.75.4.1 phil int
2568 1.75.4.1 phil ieee80211_iterate_nodes_vap(struct ieee80211_node_table *nt,
2569 1.75.4.1 phil struct ieee80211vap *vap, ieee80211_iter_func *f, void *arg)
2570 1.75.4.1 phil {
2571 1.75.4.1 phil struct ieee80211_node **ni_arr;
2572 1.75.4.1 phil struct ieee80211_node *ni;
2573 1.75.4.1 phil size_t size;
2574 1.75.4.1 phil int count, i;
2575 1.66 christos
2576 1.75.4.1 phil /*
2577 1.75.4.1 phil * Iterate over the node table and save an array of ref'ed nodes.
2578 1.75.4.1 phil *
2579 1.75.4.1 phil * This is separated out from calling the actual node function so that
2580 1.75.4.1 phil * no LORs will occur.
2581 1.75.4.1 phil */
2582 1.39 dyoung IEEE80211_NODE_LOCK(nt);
2583 1.75.4.1 phil count = nt->nt_count;
2584 1.75.4.1 phil size = count * sizeof(struct ieee80211_node *);
2585 1.75.4.1 phil ni_arr = (struct ieee80211_node **) IEEE80211_MALLOC(size, M_80211_NODE,
2586 1.75.4.1 phil IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
2587 1.75.4.1 phil if (ni_arr == NULL) {
2588 1.75.4.1 phil IEEE80211_NODE_UNLOCK(nt);
2589 1.75.4.1 phil return (ENOMEM);
2590 1.75.4.1 phil }
2591 1.75.4.1 phil
2592 1.75.4.1 phil i = 0;
2593 1.39 dyoung TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
2594 1.75.4.1 phil if (vap != NULL && ni->ni_vap != vap)
2595 1.75.4.1 phil continue;
2596 1.75.4.1 phil KASSERT(i < count,
2597 1.75.4.1 phil ("node array overflow (vap %p, i %d, count %d)\n",
2598 1.75.4.1 phil vap, i, count));
2599 1.75.4.1 phil ni_arr[i] = ieee80211_ref_node(ni);
2600 1.75.4.1 phil i++;
2601 1.39 dyoung }
2602 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
2603 1.75.4.1 phil
2604 1.75.4.1 phil for (i = 0; i < count; i++) {
2605 1.75.4.1 phil if (ni_arr[i] == NULL) /* end of the list */
2606 1.75.4.1 phil break;
2607 1.75.4.1 phil (*f)(arg, ni_arr[i]);
2608 1.75.4.1 phil /* ieee80211_free_node() locks by itself */
2609 1.75.4.1 phil ieee80211_free_node(ni_arr[i]);
2610 1.75.4.1 phil }
2611 1.75.4.1 phil
2612 1.75.4.1 phil IEEE80211_FREE(ni_arr, M_80211_NODE);
2613 1.75.4.1 phil
2614 1.75.4.1 phil return (0);
2615 1.39 dyoung }
2616 1.39 dyoung
2617 1.75.4.1 phil /*
2618 1.75.4.1 phil * Just a wrapper, so we don't have to change every ieee80211_iterate_nodes()
2619 1.75.4.1 phil * reference in the source.
2620 1.75.4.1 phil */
2621 1.39 dyoung void
2622 1.75.4.1 phil ieee80211_iterate_nodes(struct ieee80211_node_table *nt,
2623 1.75.4.1 phil ieee80211_iter_func *f, void *arg)
2624 1.75.4.1 phil {
2625 1.75.4.1 phil /* XXX no way to pass error to the caller. */
2626 1.75.4.1 phil (void) ieee80211_iterate_nodes_vap(nt, NULL, f, arg);
2627 1.75.4.1 phil }
2628 1.75.4.1 phil
2629 1.75.4.1 phil void
2630 1.75.4.1 phil ieee80211_dump_node(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
2631 1.39 dyoung {
2632 1.39 dyoung printf("0x%p: mac %s refcnt %d\n", ni,
2633 1.39 dyoung ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni));
2634 1.75.4.1 phil printf("\tauthmode %u flags 0x%x\n",
2635 1.75.4.1 phil ni->ni_authmode, ni->ni_flags);
2636 1.39 dyoung printf("\tassocid 0x%x txpower %u vlan %u\n",
2637 1.39 dyoung ni->ni_associd, ni->ni_txpower, ni->ni_vlan);
2638 1.39 dyoung printf("\ttxseq %u rxseq %u fragno %u rxfragstamp %u\n",
2639 1.75.4.1 phil ni->ni_txseqs[IEEE80211_NONQOS_TID],
2640 1.75.4.1 phil ni->ni_rxseqs[IEEE80211_NONQOS_TID] >> IEEE80211_SEQ_SEQ_SHIFT,
2641 1.75.4.1 phil ni->ni_rxseqs[IEEE80211_NONQOS_TID] & IEEE80211_SEQ_FRAG_MASK,
2642 1.39 dyoung ni->ni_rxfragstamp);
2643 1.75.4.1 phil printf("\trssi %d noise %d intval %u capinfo 0x%x\n",
2644 1.75.4.1 phil node_getrssi(ni), ni->ni_noise,
2645 1.75.4.1 phil ni->ni_intval, ni->ni_capinfo);
2646 1.39 dyoung printf("\tbssid %s essid \"%.*s\" channel %u:0x%x\n",
2647 1.39 dyoung ether_sprintf(ni->ni_bssid),
2648 1.39 dyoung ni->ni_esslen, ni->ni_essid,
2649 1.39 dyoung ni->ni_chan->ic_freq, ni->ni_chan->ic_flags);
2650 1.75.4.1 phil printf("\tinact %u inact_reload %u txrate %u\n",
2651 1.75.4.1 phil ni->ni_inact, ni->ni_inact_reload, ni->ni_txrate);
2652 1.75.4.1 phil printf("\thtcap %x htparam %x htctlchan %u ht2ndchan %u\n",
2653 1.75.4.1 phil ni->ni_htcap, ni->ni_htparam,
2654 1.75.4.1 phil ni->ni_htctlchan, ni->ni_ht2ndchan);
2655 1.75.4.1 phil printf("\thtopmode %x htstbc %x htchw %u\n",
2656 1.75.4.1 phil ni->ni_htopmode, ni->ni_htstbc, ni->ni_chw);
2657 1.75.4.1 phil printf("\tvhtcap %x freq1 %d freq2 %d vhtbasicmcs %x\n",
2658 1.75.4.1 phil ni->ni_vhtcap, (int) ni->ni_vht_chan1, (int) ni->ni_vht_chan2,
2659 1.75.4.1 phil (int) ni->ni_vht_basicmcs);
2660 1.75.4.1 phil /* XXX VHT state */
2661 1.39 dyoung }
2662 1.39 dyoung
2663 1.39 dyoung void
2664 1.39 dyoung ieee80211_dump_nodes(struct ieee80211_node_table *nt)
2665 1.39 dyoung {
2666 1.39 dyoung ieee80211_iterate_nodes(nt,
2667 1.39 dyoung (ieee80211_iter_func *) ieee80211_dump_node, nt);
2668 1.39 dyoung }
2669 1.39 dyoung
2670 1.75.4.1 phil static void
2671 1.75.4.1 phil ieee80211_notify_erp_locked(struct ieee80211com *ic)
2672 1.75.4.1 phil {
2673 1.75.4.1 phil struct ieee80211vap *vap;
2674 1.75.4.1 phil
2675 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2676 1.75.4.1 phil
2677 1.75.4.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
2678 1.75.4.1 phil if (vap->iv_opmode == IEEE80211_M_HOSTAP)
2679 1.75.4.1 phil ieee80211_beacon_notify(vap, IEEE80211_BEACON_ERP);
2680 1.75.4.1 phil }
2681 1.75.4.1 phil
2682 1.75.4.1 phil void
2683 1.75.4.1 phil ieee80211_notify_erp(struct ieee80211com *ic)
2684 1.75.4.1 phil {
2685 1.75.4.1 phil IEEE80211_LOCK(ic);
2686 1.75.4.1 phil ieee80211_notify_erp_locked(ic);
2687 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2688 1.75.4.1 phil }
2689 1.75.4.1 phil
2690 1.39 dyoung /*
2691 1.39 dyoung * Handle a station joining an 11g network.
2692 1.39 dyoung */
2693 1.39 dyoung static void
2694 1.75.4.1 phil ieee80211_node_join_11g(struct ieee80211_node *ni)
2695 1.39 dyoung {
2696 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2697 1.75.4.1 phil
2698 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2699 1.1 dyoung
2700 1.39 dyoung /*
2701 1.39 dyoung * Station isn't capable of short slot time. Bump
2702 1.39 dyoung * the count of long slot time stations and disable
2703 1.39 dyoung * use of short slot time. Note that the actual switch
2704 1.39 dyoung * over to long slot time use may not occur until the
2705 1.39 dyoung * next beacon transmission (per sec. 7.3.1.4 of 11g).
2706 1.39 dyoung */
2707 1.39 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) {
2708 1.39 dyoung ic->ic_longslotsta++;
2709 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2710 1.75.4.1 phil "station needs long slot time, count %d",
2711 1.75.4.1 phil ic->ic_longslotsta);
2712 1.39 dyoung /* XXX vap's w/ conflicting needs won't work */
2713 1.75.4.1 phil if (!IEEE80211_IS_CHAN_108G(ic->ic_bsschan)) {
2714 1.75.4.1 phil /*
2715 1.75.4.1 phil * Don't force slot time when switched to turbo
2716 1.75.4.1 phil * mode as non-ERP stations won't be present; this
2717 1.75.4.1 phil * need only be done when on the normal G channel.
2718 1.75.4.1 phil */
2719 1.75.4.1 phil ieee80211_set_shortslottime(ic, 0);
2720 1.75.4.1 phil }
2721 1.39 dyoung }
2722 1.39 dyoung /*
2723 1.39 dyoung * If the new station is not an ERP station
2724 1.39 dyoung * then bump the counter and enable protection
2725 1.39 dyoung * if configured.
2726 1.39 dyoung */
2727 1.75.4.1 phil if (!ieee80211_iserp_rateset(&ni->ni_rates)) {
2728 1.39 dyoung ic->ic_nonerpsta++;
2729 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2730 1.75.4.1 phil "station is !ERP, %d non-ERP stations associated",
2731 1.75.4.1 phil ic->ic_nonerpsta);
2732 1.39 dyoung /*
2733 1.39 dyoung * If station does not support short preamble
2734 1.39 dyoung * then we must enable use of Barker preamble.
2735 1.39 dyoung */
2736 1.39 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE) == 0) {
2737 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2738 1.75.4.1 phil "%s", "station needs long preamble");
2739 1.39 dyoung ic->ic_flags |= IEEE80211_F_USEBARKER;
2740 1.39 dyoung ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
2741 1.39 dyoung }
2742 1.75.4.1 phil /*
2743 1.75.4.1 phil * If protection is configured and this is the first
2744 1.75.4.1 phil * indication we should use protection, enable it.
2745 1.75.4.1 phil */
2746 1.75.4.1 phil if (ic->ic_protmode != IEEE80211_PROT_NONE &&
2747 1.75.4.1 phil ic->ic_nonerpsta == 1 &&
2748 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0) {
2749 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
2750 1.75.4.1 phil "%s: enable use of protection\n", __func__);
2751 1.75.4.1 phil ic->ic_flags |= IEEE80211_F_USEPROT;
2752 1.75.4.1 phil ieee80211_notify_erp_locked(ic);
2753 1.75.4.1 phil }
2754 1.75.4.1 phil } else
2755 1.39 dyoung ni->ni_flags |= IEEE80211_NODE_ERP;
2756 1.1 dyoung }
2757 1.22 mycroft
2758 1.22 mycroft void
2759 1.75.4.1 phil ieee80211_node_join(struct ieee80211_node *ni, int resp)
2760 1.22 mycroft {
2761 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2762 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2763 1.22 mycroft int newassoc;
2764 1.22 mycroft
2765 1.22 mycroft if (ni->ni_associd == 0) {
2766 1.75.4.1 phil uint16_t aid;
2767 1.22 mycroft
2768 1.75.4.1 phil KASSERT(vap->iv_aid_bitmap != NULL, ("no aid bitmap"));
2769 1.22 mycroft /*
2770 1.39 dyoung * It would be good to search the bitmap
2771 1.22 mycroft * more efficiently, but this will do for now.
2772 1.22 mycroft */
2773 1.75.4.1 phil for (aid = 1; aid < vap->iv_max_aid; aid++) {
2774 1.75.4.1 phil if (!IEEE80211_AID_ISSET(vap, aid))
2775 1.22 mycroft break;
2776 1.22 mycroft }
2777 1.75.4.1 phil if (aid >= vap->iv_max_aid) {
2778 1.75.4.1 phil IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_TOOMANY);
2779 1.75.4.1 phil ieee80211_node_leave(ni);
2780 1.22 mycroft return;
2781 1.22 mycroft }
2782 1.22 mycroft ni->ni_associd = aid | 0xc000;
2783 1.75.4.1 phil ni->ni_jointime = time_uptime;
2784 1.75.4.1 phil IEEE80211_LOCK(ic);
2785 1.75.4.1 phil IEEE80211_AID_SET(vap, ni->ni_associd);
2786 1.75.4.1 phil vap->iv_sta_assoc++;
2787 1.39 dyoung ic->ic_sta_assoc++;
2788 1.75.4.1 phil
2789 1.75.4.1 phil if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan))
2790 1.75.4.1 phil ieee80211_ht_node_join(ni);
2791 1.75.4.1 phil if (IEEE80211_IS_CHAN_VHT(ic->ic_bsschan))
2792 1.75.4.1 phil ieee80211_vht_node_join(ni);
2793 1.75.4.1 phil if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2794 1.75.4.1 phil IEEE80211_IS_CHAN_FULL(ic->ic_bsschan))
2795 1.75.4.1 phil ieee80211_node_join_11g(ni);
2796 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2797 1.75.4.1 phil
2798 1.22 mycroft newassoc = 1;
2799 1.22 mycroft } else
2800 1.22 mycroft newassoc = 0;
2801 1.22 mycroft
2802 1.75.4.1 phil /*
2803 1.75.4.1 phil * XXX VHT - should log VHT channel width, etc
2804 1.75.4.1 phil */
2805 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, ni,
2806 1.75.4.1 phil "station associated at aid %d: %s preamble, %s slot time%s%s%s%s%s%s%s%s",
2807 1.39 dyoung IEEE80211_NODE_AID(ni),
2808 1.39 dyoung ic->ic_flags & IEEE80211_F_SHPREAMBLE ? "short" : "long",
2809 1.39 dyoung ic->ic_flags & IEEE80211_F_SHSLOT ? "short" : "long",
2810 1.39 dyoung ic->ic_flags & IEEE80211_F_USEPROT ? ", protection" : "",
2811 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_QOS ? ", QoS" : "",
2812 1.75.4.1 phil /* XXX update for VHT string */
2813 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_HT ?
2814 1.75.4.1 phil (ni->ni_chw == 40 ? ", HT40" : ", HT20") : "",
2815 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_AMPDU ? " (+AMPDU)" : "",
2816 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_MIMO_RTS ? " (+SMPS-DYN)" :
2817 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_MIMO_PS ? " (+SMPS)" : "",
2818 1.75.4.1 phil ni->ni_flags & IEEE80211_NODE_RIFS ? " (+RIFS)" : "",
2819 1.75.4.1 phil IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF) ?
2820 1.75.4.1 phil ", fast-frames" : "",
2821 1.75.4.1 phil IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_TURBOP) ?
2822 1.75.4.1 phil ", turbo" : ""
2823 1.39 dyoung );
2824 1.22 mycroft
2825 1.75.4.1 phil ieee80211_node_setuptxparms(ni);
2826 1.75.4.1 phil ieee80211_ratectl_node_init(ni);
2827 1.22 mycroft /* give driver a chance to setup state like ni_txrate */
2828 1.39 dyoung if (ic->ic_newassoc != NULL)
2829 1.45 skrll ic->ic_newassoc(ni, newassoc);
2830 1.75.4.1 phil IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_SUCCESS);
2831 1.39 dyoung /* tell the authenticator about new station */
2832 1.75.4.1 phil if (vap->iv_auth->ia_node_join != NULL)
2833 1.75.4.1 phil vap->iv_auth->ia_node_join(ni);
2834 1.75.4.1 phil ieee80211_notify_node_join(ni,
2835 1.75.4.1 phil resp == IEEE80211_FC0_SUBTYPE_ASSOC_RESP);
2836 1.75.4.1 phil }
2837 1.75.4.1 phil
2838 1.75.4.1 phil static void
2839 1.75.4.1 phil disable_protection(struct ieee80211com *ic)
2840 1.75.4.1 phil {
2841 1.75.4.1 phil KASSERT(ic->ic_nonerpsta == 0 &&
2842 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0,
2843 1.75.4.1 phil ("%d non ERP stations, flags 0x%x", ic->ic_nonerpsta,
2844 1.75.4.1 phil ic->ic_flags_ext));
2845 1.75.4.1 phil
2846 1.75.4.1 phil ic->ic_flags &= ~IEEE80211_F_USEPROT;
2847 1.75.4.1 phil /* XXX verify mode? */
2848 1.75.4.1 phil if (ic->ic_caps & IEEE80211_C_SHPREAMBLE) {
2849 1.75.4.1 phil ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
2850 1.75.4.1 phil ic->ic_flags &= ~IEEE80211_F_USEBARKER;
2851 1.75.4.1 phil }
2852 1.75.4.1 phil ieee80211_notify_erp_locked(ic);
2853 1.39 dyoung }
2854 1.39 dyoung
2855 1.39 dyoung /*
2856 1.39 dyoung * Handle a station leaving an 11g network.
2857 1.39 dyoung */
2858 1.39 dyoung static void
2859 1.75.4.1 phil ieee80211_node_leave_11g(struct ieee80211_node *ni)
2860 1.39 dyoung {
2861 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2862 1.75.4.1 phil
2863 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2864 1.39 dyoung
2865 1.75.4.1 phil KASSERT(IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan),
2866 1.75.4.1 phil ("not in 11g, bss %u:0x%x", ic->ic_bsschan->ic_freq,
2867 1.75.4.1 phil ic->ic_bsschan->ic_flags));
2868 1.39 dyoung
2869 1.39 dyoung /*
2870 1.39 dyoung * If a long slot station do the slot time bookkeeping.
2871 1.39 dyoung */
2872 1.39 dyoung if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) {
2873 1.75.4.1 phil KASSERT(ic->ic_longslotsta > 0,
2874 1.39 dyoung ("bogus long slot station count %d", ic->ic_longslotsta));
2875 1.39 dyoung ic->ic_longslotsta--;
2876 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2877 1.75.4.1 phil "long slot time station leaves, count now %d",
2878 1.75.4.1 phil ic->ic_longslotsta);
2879 1.39 dyoung if (ic->ic_longslotsta == 0) {
2880 1.39 dyoung /*
2881 1.39 dyoung * Re-enable use of short slot time if supported
2882 1.39 dyoung * and not operating in IBSS mode (per spec).
2883 1.39 dyoung */
2884 1.39 dyoung if ((ic->ic_caps & IEEE80211_C_SHSLOT) &&
2885 1.39 dyoung ic->ic_opmode != IEEE80211_M_IBSS) {
2886 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap,
2887 1.75.4.1 phil IEEE80211_MSG_ASSOC,
2888 1.39 dyoung "%s: re-enable use of short slot time\n",
2889 1.39 dyoung __func__);
2890 1.39 dyoung ieee80211_set_shortslottime(ic, 1);
2891 1.39 dyoung }
2892 1.39 dyoung }
2893 1.39 dyoung }
2894 1.39 dyoung /*
2895 1.39 dyoung * If a non-ERP station do the protection-related bookkeeping.
2896 1.39 dyoung */
2897 1.39 dyoung if ((ni->ni_flags & IEEE80211_NODE_ERP) == 0) {
2898 1.75.4.1 phil KASSERT(ic->ic_nonerpsta > 0,
2899 1.39 dyoung ("bogus non-ERP station count %d", ic->ic_nonerpsta));
2900 1.39 dyoung ic->ic_nonerpsta--;
2901 1.75.4.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2902 1.75.4.1 phil "non-ERP station leaves, count now %d%s", ic->ic_nonerpsta,
2903 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) ?
2904 1.75.4.1 phil " (non-ERP sta present)" : "");
2905 1.75.4.1 phil if (ic->ic_nonerpsta == 0 &&
2906 1.75.4.1 phil (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0) {
2907 1.75.4.1 phil IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
2908 1.39 dyoung "%s: disable use of protection\n", __func__);
2909 1.75.4.1 phil disable_protection(ic);
2910 1.39 dyoung }
2911 1.39 dyoung }
2912 1.22 mycroft }
2913 1.22 mycroft
2914 1.22 mycroft /*
2915 1.75.4.1 phil * Time out presence of an overlapping bss with non-ERP
2916 1.75.4.1 phil * stations. When operating in hostap mode we listen for
2917 1.75.4.1 phil * beacons from other stations and if we identify a non-ERP
2918 1.75.4.1 phil * station is present we enable protection. To identify
2919 1.75.4.1 phil * when all non-ERP stations are gone we time out this
2920 1.75.4.1 phil * condition.
2921 1.75.4.1 phil */
2922 1.75.4.1 phil static void
2923 1.75.4.1 phil ieee80211_erp_timeout(struct ieee80211com *ic)
2924 1.75.4.1 phil {
2925 1.75.4.1 phil
2926 1.75.4.1 phil IEEE80211_LOCK_ASSERT(ic);
2927 1.75.4.1 phil
2928 1.75.4.1 phil if ((ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) &&
2929 1.75.4.1 phil ieee80211_time_after(ticks, ic->ic_lastnonerp + IEEE80211_NONERP_PRESENT_AGE)) {
2930 1.75.4.1 phil #if 0
2931 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
2932 1.75.4.1 phil "%s", "age out non-ERP sta present on channel");
2933 1.75.4.1 phil #endif
2934 1.75.4.1 phil ic->ic_flags_ext &= ~IEEE80211_FEXT_NONERP_PR;
2935 1.75.4.1 phil if (ic->ic_nonerpsta == 0)
2936 1.75.4.1 phil disable_protection(ic);
2937 1.75.4.1 phil }
2938 1.75.4.1 phil }
2939 1.75.4.1 phil
2940 1.75.4.1 phil /*
2941 1.26 dyoung * Handle bookkeeping for station deauthentication/disassociation
2942 1.26 dyoung * when operating as an ap.
2943 1.22 mycroft */
2944 1.22 mycroft void
2945 1.75.4.1 phil ieee80211_node_leave(struct ieee80211_node *ni)
2946 1.22 mycroft {
2947 1.75.4.1 phil struct ieee80211com *ic = ni->ni_ic;
2948 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
2949 1.39 dyoung struct ieee80211_node_table *nt = ni->ni_table;
2950 1.39 dyoung
2951 1.75.4.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, ni,
2952 1.75.4.1 phil "station with aid %d leaves", IEEE80211_NODE_AID(ni));
2953 1.75 maxv
2954 1.75.4.1 phil KASSERT(vap->iv_opmode != IEEE80211_M_STA,
2955 1.75.4.1 phil ("unexpected operating mode %u", vap->iv_opmode));
2956 1.22 mycroft /*
2957 1.22 mycroft * If node wasn't previously associated all
2958 1.22 mycroft * we need to do is reclaim the reference.
2959 1.22 mycroft */
2960 1.39 dyoung /* XXX ibss mode bypasses 11g and notification */
2961 1.22 mycroft if (ni->ni_associd == 0)
2962 1.39 dyoung goto done;
2963 1.39 dyoung /*
2964 1.39 dyoung * Tell the authenticator the station is leaving.
2965 1.39 dyoung * Note that we must do this before yanking the
2966 1.39 dyoung * association id as the authenticator uses the
2967 1.75.4.1 phil * associd to locate it's state block.
2968 1.39 dyoung */
2969 1.75.4.1 phil if (vap->iv_auth->ia_node_leave != NULL)
2970 1.75.4.1 phil vap->iv_auth->ia_node_leave(ni);
2971 1.39 dyoung
2972 1.75.4.1 phil IEEE80211_LOCK(ic);
2973 1.75.4.1 phil IEEE80211_AID_CLR(vap, ni->ni_associd);
2974 1.75.4.1 phil vap->iv_sta_assoc--;
2975 1.75.4.1 phil ic->ic_sta_assoc--;
2976 1.75 maxv
2977 1.75.4.1 phil if (IEEE80211_IS_CHAN_VHT(ic->ic_bsschan))
2978 1.75.4.1 phil ieee80211_vht_node_leave(ni);
2979 1.75.4.1 phil if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan))
2980 1.75.4.1 phil ieee80211_ht_node_leave(ni);
2981 1.75.4.1 phil if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2982 1.75.4.1 phil IEEE80211_IS_CHAN_FULL(ic->ic_bsschan))
2983 1.75.4.1 phil ieee80211_node_leave_11g(ni);
2984 1.75.4.1 phil IEEE80211_UNLOCK(ic);
2985 1.39 dyoung /*
2986 1.39 dyoung * Cleanup station state. In particular clear various
2987 1.39 dyoung * state that might otherwise be reused if the node
2988 1.39 dyoung * is reused before the reference count goes to zero
2989 1.39 dyoung * (and memory is reclaimed).
2990 1.39 dyoung */
2991 1.75.4.1 phil ieee80211_sta_leave(ni);
2992 1.39 dyoung done:
2993 1.39 dyoung /*
2994 1.39 dyoung * Remove the node from any table it's recorded in and
2995 1.39 dyoung * drop the caller's reference. Removal from the table
2996 1.39 dyoung * is important to insure the node is not reprocessed
2997 1.39 dyoung * for inactivity.
2998 1.39 dyoung */
2999 1.39 dyoung if (nt != NULL) {
3000 1.39 dyoung IEEE80211_NODE_LOCK(nt);
3001 1.39 dyoung node_reclaim(nt, ni);
3002 1.39 dyoung IEEE80211_NODE_UNLOCK(nt);
3003 1.39 dyoung } else
3004 1.39 dyoung ieee80211_free_node(ni);
3005 1.39 dyoung }
3006 1.39 dyoung
3007 1.75.4.1 phil struct rssiinfo {
3008 1.75.4.1 phil int rssi_samples;
3009 1.75.4.1 phil uint32_t rssi_total;
3010 1.75.4.1 phil };
3011 1.75.4.1 phil
3012 1.75.4.1 phil static void
3013 1.75.4.1 phil get_hostap_rssi(void *arg, struct ieee80211_node *ni)
3014 1.39 dyoung {
3015 1.75.4.1 phil struct rssiinfo *info = arg;
3016 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
3017 1.75.4.1 phil int8_t rssi;
3018 1.39 dyoung
3019 1.75.4.1 phil /* only associated stations */
3020 1.75.4.1 phil if (ni->ni_associd == 0)
3021 1.75.4.1 phil return;
3022 1.75.4.1 phil rssi = vap->iv_ic->ic_node_getrssi(ni);
3023 1.75.4.1 phil if (rssi != 0) {
3024 1.75.4.1 phil info->rssi_samples++;
3025 1.75.4.1 phil info->rssi_total += rssi;
3026 1.39 dyoung }
3027 1.39 dyoung }
3028 1.39 dyoung
3029 1.39 dyoung static void
3030 1.75.4.1 phil get_adhoc_rssi(void *arg, struct ieee80211_node *ni)
3031 1.39 dyoung {
3032 1.75.4.1 phil struct rssiinfo *info = arg;
3033 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
3034 1.75.4.1 phil int8_t rssi;
3035 1.75.4.1 phil
3036 1.75.4.1 phil /* only neighbors */
3037 1.75.4.1 phil /* XXX check bssid */
3038 1.75.4.1 phil if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
3039 1.75.4.1 phil return;
3040 1.75.4.1 phil rssi = vap->iv_ic->ic_node_getrssi(ni);
3041 1.75.4.1 phil if (rssi != 0) {
3042 1.75.4.1 phil info->rssi_samples++;
3043 1.75.4.1 phil info->rssi_total += rssi;
3044 1.39 dyoung }
3045 1.39 dyoung }
3046 1.39 dyoung
3047 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
3048 1.39 dyoung static void
3049 1.75.4.1 phil get_mesh_rssi(void *arg, struct ieee80211_node *ni)
3050 1.39 dyoung {
3051 1.75.4.1 phil struct rssiinfo *info = arg;
3052 1.75.4.1 phil struct ieee80211vap *vap = ni->ni_vap;
3053 1.75.4.1 phil int8_t rssi;
3054 1.39 dyoung
3055 1.75.4.1 phil /* only neighbors that peered successfully */
3056 1.75.4.1 phil if (ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED)
3057 1.75.4.1 phil return;
3058 1.75.4.1 phil rssi = vap->iv_ic->ic_node_getrssi(ni);
3059 1.75.4.1 phil if (rssi != 0) {
3060 1.75.4.1 phil info->rssi_samples++;
3061 1.75.4.1 phil info->rssi_total += rssi;
3062 1.75.4.1 phil }
3063 1.39 dyoung }
3064 1.75.4.1 phil #endif /* IEEE80211_SUPPORT_MESH */
3065 1.39 dyoung
3066 1.75.4.1 phil int8_t
3067 1.75.4.1 phil ieee80211_getrssi(struct ieee80211vap *vap)
3068 1.39 dyoung {
3069 1.75.4.1 phil #define NZ(x) ((x) == 0 ? 1 : (x))
3070 1.75.4.1 phil struct ieee80211com *ic = vap->iv_ic;
3071 1.75.4.1 phil struct rssiinfo info;
3072 1.39 dyoung
3073 1.75.4.1 phil info.rssi_total = 0;
3074 1.75.4.1 phil info.rssi_samples = 0;
3075 1.75.4.1 phil switch (vap->iv_opmode) {
3076 1.75.4.1 phil case IEEE80211_M_IBSS: /* average of all ibss neighbors */
3077 1.75.4.1 phil case IEEE80211_M_AHDEMO: /* average of all neighbors */
3078 1.75.4.1 phil ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_adhoc_rssi,
3079 1.75.4.1 phil &info);
3080 1.75.4.1 phil break;
3081 1.75.4.1 phil case IEEE80211_M_HOSTAP: /* average of all associated stations */
3082 1.75.4.1 phil ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_hostap_rssi,
3083 1.75.4.1 phil &info);
3084 1.75.4.1 phil break;
3085 1.75.4.1 phil #ifdef IEEE80211_SUPPORT_MESH
3086 1.75.4.1 phil case IEEE80211_M_MBSS: /* average of all mesh neighbors */
3087 1.75.4.1 phil ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_mesh_rssi,
3088 1.75.4.1 phil &info);
3089 1.75.4.1 phil break;
3090 1.75.4.1 phil #endif
3091 1.75.4.1 phil case IEEE80211_M_MONITOR: /* XXX */
3092 1.75.4.1 phil case IEEE80211_M_STA: /* use stats from associated ap */
3093 1.75.4.1 phil default:
3094 1.75.4.1 phil if (vap->iv_bss != NULL)
3095 1.75.4.1 phil info.rssi_total = ic->ic_node_getrssi(vap->iv_bss);
3096 1.75.4.1 phil info.rssi_samples = 1;
3097 1.75.4.1 phil break;
3098 1.75.4.1 phil }
3099 1.75.4.1 phil return info.rssi_total / NZ(info.rssi_samples);
3100 1.75.4.1 phil #undef NZ
3101 1.39 dyoung }
3102 1.39 dyoung
3103 1.75.4.1 phil void
3104 1.75.4.1 phil ieee80211_getsignal(struct ieee80211vap *vap, int8_t *rssi, int8_t *noise)
3105 1.39 dyoung {
3106 1.39 dyoung
3107 1.75.4.1 phil if (vap->iv_bss == NULL) /* NB: shouldn't happen */
3108 1.75.4.1 phil return;
3109 1.75.4.1 phil vap->iv_ic->ic_node_getsignal(vap->iv_bss, rssi, noise);
3110 1.75.4.1 phil /* for non-station mode return avg'd rssi accounting */
3111 1.75.4.1 phil if (vap->iv_opmode != IEEE80211_M_STA)
3112 1.75.4.1 phil *rssi = ieee80211_getrssi(vap);
3113 1.22 mycroft }
3114