2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: head/sys/net80211/ieee80211_node.c 201758 2010-01-07 21:01:37Z mbr $
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/malloc.h>
36 #include <sys/kernel.h>
38 #include <sys/socket.h>
41 #include <net/if_media.h>
42 #include <net/ethernet.h>
43 #include <net/route.h>
45 #include <netproto/802_11/ieee80211_var.h>
46 #include <netproto/802_11/ieee80211_input.h>
47 #ifdef IEEE80211_SUPPORT_SUPERG
48 #include <netproto/802_11/ieee80211_superg.h>
50 #ifdef IEEE80211_SUPPORT_TDMA
51 #include <netproto/802_11/ieee80211_tdma.h>
53 #include <netproto/802_11/ieee80211_wds.h>
54 #include <netproto/802_11/ieee80211_mesh.h>
59 * IEEE80211_NODE_HASHSIZE must be a power of 2.
61 CTASSERT((IEEE80211_NODE_HASHSIZE & (IEEE80211_NODE_HASHSIZE-1)) == 0);
64 * Association id's are managed with a bit vector.
66 #define IEEE80211_AID_SET(_vap, b) \
67 ((_vap)->iv_aid_bitmap[IEEE80211_AID(b) / 32] |= \
68 (1 << (IEEE80211_AID(b) % 32)))
69 #define IEEE80211_AID_CLR(_vap, b) \
70 ((_vap)->iv_aid_bitmap[IEEE80211_AID(b) / 32] &= \
71 ~(1 << (IEEE80211_AID(b) % 32)))
72 #define IEEE80211_AID_ISSET(_vap, b) \
73 ((_vap)->iv_aid_bitmap[IEEE80211_AID(b) / 32] & (1 << (IEEE80211_AID(b) % 32)))
75 #ifdef IEEE80211_DEBUG_REFCNT
76 #define REFCNT_LOC "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line
78 #define REFCNT_LOC "%s %p<%s> refcnt %d\n", __func__
81 static int ieee80211_sta_join1(struct ieee80211_node *);
83 static struct ieee80211_node *node_alloc(struct ieee80211vap *,
84 const uint8_t [IEEE80211_ADDR_LEN]);
85 static void node_cleanup(struct ieee80211_node *);
86 static void node_free(struct ieee80211_node *);
87 static void node_age(struct ieee80211_node *);
88 static int8_t node_getrssi(const struct ieee80211_node *);
89 static void node_getsignal(const struct ieee80211_node *, int8_t *, int8_t *);
90 static void node_getmimoinfo(const struct ieee80211_node *,
91 struct ieee80211_mimo_info *);
93 static void _ieee80211_free_node(struct ieee80211_node *);
95 static void ieee80211_node_table_init(struct ieee80211com *ic,
96 struct ieee80211_node_table *nt, const char *name,
97 int inact, int keymaxix);
98 static void ieee80211_node_table_reset(struct ieee80211_node_table *,
99 struct ieee80211vap *);
100 static void ieee80211_node_table_cleanup(struct ieee80211_node_table *nt);
101 static void ieee80211_erp_timeout(struct ieee80211com *);
103 MALLOC_DEFINE(M_80211_NODE, "80211node", "802.11 node state");
104 MALLOC_DEFINE(M_80211_NODE_IE, "80211nodeie", "802.11 node ie");
107 ieee80211_node_attach(struct ieee80211com *ic)
109 /* XXX really want maxlen enforced per-sta */
110 ieee80211_ageq_init(&ic->ic_stageq, ic->ic_max_keyix * 8,
112 ieee80211_node_table_init(ic, &ic->ic_sta, "station",
113 IEEE80211_INACT_INIT, ic->ic_max_keyix);
114 callout_init_mp(&ic->ic_inact);
115 callout_reset(&ic->ic_inact, IEEE80211_INACT_WAIT*hz,
116 ieee80211_node_timeout, ic);
118 ic->ic_node_alloc = node_alloc;
119 ic->ic_node_free = node_free;
120 ic->ic_node_cleanup = node_cleanup;
121 ic->ic_node_age = node_age;
122 ic->ic_node_drain = node_age; /* NB: same as age */
123 ic->ic_node_getrssi = node_getrssi;
124 ic->ic_node_getsignal = node_getsignal;
125 ic->ic_node_getmimoinfo = node_getmimoinfo;
128 * Set flags to be propagated to all vap's;
129 * these define default behaviour/configuration.
131 ic->ic_flags_ext |= IEEE80211_FEXT_INACT; /* inactivity processing */
135 ieee80211_node_detach(struct ieee80211com *ic)
138 callout_stop(&ic->ic_inact);
139 ieee80211_node_table_cleanup(&ic->ic_sta);
140 ieee80211_ageq_cleanup(&ic->ic_stageq);
144 ieee80211_node_vattach(struct ieee80211vap *vap)
146 /* NB: driver can override */
147 vap->iv_max_aid = IEEE80211_AID_DEF;
149 /* default station inactivity timer setings */
150 vap->iv_inact_init = IEEE80211_INACT_INIT;
151 vap->iv_inact_auth = IEEE80211_INACT_AUTH;
152 vap->iv_inact_run = IEEE80211_INACT_RUN;
153 vap->iv_inact_probe = IEEE80211_INACT_PROBE;
155 IEEE80211_DPRINTF(vap, IEEE80211_MSG_INACT,
156 "%s: init %u auth %u run %u probe %u\n", __func__,
157 vap->iv_inact_init, vap->iv_inact_auth,
158 vap->iv_inact_run, vap->iv_inact_probe);
162 ieee80211_node_latevattach(struct ieee80211vap *vap)
164 if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
165 /* XXX should we allow max aid to be zero? */
166 if (vap->iv_max_aid < IEEE80211_AID_MIN) {
167 vap->iv_max_aid = IEEE80211_AID_MIN;
168 if_printf(vap->iv_ifp,
169 "WARNING: max aid too small, changed to %d\n",
172 vap->iv_aid_bitmap = (uint32_t *) kmalloc(
173 howmany(vap->iv_max_aid, 32) * sizeof(uint32_t),
174 M_80211_NODE, M_INTWAIT | M_ZERO);
175 if (vap->iv_aid_bitmap == NULL) {
176 /* XXX no way to recover */
177 kprintf("%s: no memory for AID bitmap, max aid %d!\n",
178 __func__, vap->iv_max_aid);
183 ieee80211_reset_bss(vap);
185 vap->iv_auth = ieee80211_authenticator_get(vap->iv_bss->ni_authmode);
189 ieee80211_node_vdetach(struct ieee80211vap *vap)
191 struct ieee80211com *ic = vap->iv_ic;
193 ieee80211_node_table_reset(&ic->ic_sta, vap);
194 if (vap->iv_bss != NULL) {
195 ieee80211_free_node(vap->iv_bss);
198 if (vap->iv_aid_bitmap != NULL) {
199 kfree(vap->iv_aid_bitmap, M_80211_NODE);
200 vap->iv_aid_bitmap = NULL;
205 * Port authorize/unauthorize interfaces for use by an authenticator.
209 ieee80211_node_authorize(struct ieee80211_node *ni)
211 struct ieee80211vap *vap = ni->ni_vap;
213 ni->ni_flags |= IEEE80211_NODE_AUTH;
214 ni->ni_inact_reload = vap->iv_inact_run;
215 ni->ni_inact = ni->ni_inact_reload;
217 IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
218 "%s: inact_reload %u", __func__, ni->ni_inact_reload);
222 ieee80211_node_unauthorize(struct ieee80211_node *ni)
224 struct ieee80211vap *vap = ni->ni_vap;
226 ni->ni_flags &= ~IEEE80211_NODE_AUTH;
227 ni->ni_inact_reload = vap->iv_inact_auth;
228 if (ni->ni_inact > ni->ni_inact_reload)
229 ni->ni_inact = ni->ni_inact_reload;
231 IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
232 "%s: inact_reload %u inact %u", __func__,
233 ni->ni_inact_reload, ni->ni_inact);
237 * Fix tx parameters for a node according to ``association state''.
240 ieee80211_node_setuptxparms(struct ieee80211_node *ni)
242 struct ieee80211vap *vap = ni->ni_vap;
243 enum ieee80211_phymode mode;
245 if (ni->ni_flags & IEEE80211_NODE_HT) {
246 if (IEEE80211_IS_CHAN_5GHZ(ni->ni_chan))
247 mode = IEEE80211_MODE_11NA;
249 mode = IEEE80211_MODE_11NG;
250 } else { /* legacy rate handling */
251 if (IEEE80211_IS_CHAN_ST(ni->ni_chan))
252 mode = IEEE80211_MODE_STURBO_A;
253 else if (IEEE80211_IS_CHAN_HALF(ni->ni_chan))
254 mode = IEEE80211_MODE_HALF;
255 else if (IEEE80211_IS_CHAN_QUARTER(ni->ni_chan))
256 mode = IEEE80211_MODE_QUARTER;
257 /* NB: 108A should be handled as 11a */
258 else if (IEEE80211_IS_CHAN_A(ni->ni_chan))
259 mode = IEEE80211_MODE_11A;
260 else if (IEEE80211_IS_CHAN_108G(ni->ni_chan) ||
261 (ni->ni_flags & IEEE80211_NODE_ERP))
262 mode = IEEE80211_MODE_11G;
264 mode = IEEE80211_MODE_11B;
266 ni->ni_txparms = &vap->iv_txparms[mode];
270 * Set/change the channel. The rate set is also updated as
271 * to insure a consistent view by drivers.
272 * XXX should be private but hostap needs it to deal with CSA
275 ieee80211_node_set_chan(struct ieee80211_node *ni,
276 struct ieee80211_channel *chan)
278 struct ieee80211com *ic = ni->ni_ic;
279 struct ieee80211vap *vap = ni->ni_vap;
280 enum ieee80211_phymode mode;
282 KASSERT(chan != IEEE80211_CHAN_ANYC, ("no channel"));
285 mode = ieee80211_chan2mode(chan);
286 if (IEEE80211_IS_CHAN_HT(chan)) {
288 * XXX Gotta be careful here; the rate set returned by
289 * ieee80211_get_suprates is actually any HT rate
290 * set so blindly copying it will be bad. We must
291 * install the legacy rate est in ni_rates and the
292 * HT rate set in ni_htrates.
294 ni->ni_htrates = *ieee80211_get_suphtrates(ic, chan);
296 * Setup bss tx parameters based on operating mode. We
297 * use legacy rates when operating in a mixed HT+non-HT bss
298 * and non-ERP rates in 11g for mixed ERP+non-ERP bss.
300 if (mode == IEEE80211_MODE_11NA &&
301 (vap->iv_flags_ht & IEEE80211_FHT_PUREN) == 0)
302 mode = IEEE80211_MODE_11A;
303 else if (mode == IEEE80211_MODE_11NG &&
304 (vap->iv_flags_ht & IEEE80211_FHT_PUREN) == 0)
305 mode = IEEE80211_MODE_11G;
306 if (mode == IEEE80211_MODE_11G &&
307 (vap->iv_flags & IEEE80211_F_PUREG) == 0)
308 mode = IEEE80211_MODE_11B;
310 ni->ni_txparms = &vap->iv_txparms[mode];
311 ni->ni_rates = *ieee80211_get_suprates(ic, chan);
315 copy_bss(struct ieee80211_node *nbss, const struct ieee80211_node *obss)
317 /* propagate useful state */
318 nbss->ni_authmode = obss->ni_authmode;
319 nbss->ni_txpower = obss->ni_txpower;
320 nbss->ni_vlan = obss->ni_vlan;
321 /* XXX statistics? */
322 /* XXX legacy WDS bssid? */
326 ieee80211_create_ibss(struct ieee80211vap* vap, struct ieee80211_channel *chan)
328 struct ieee80211com *ic = vap->iv_ic;
329 struct ieee80211_node *ni;
331 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
332 "%s: creating %s on channel %u\n", __func__,
333 ieee80211_opmode_name[vap->iv_opmode],
334 ieee80211_chan2ieee(ic, chan));
336 ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr);
341 IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_myaddr);
342 ni->ni_esslen = vap->iv_des_ssid[0].len;
343 memcpy(ni->ni_essid, vap->iv_des_ssid[0].ssid, ni->ni_esslen);
344 if (vap->iv_bss != NULL)
345 copy_bss(ni, vap->iv_bss);
346 ni->ni_intval = ic->ic_bintval;
347 if (vap->iv_flags & IEEE80211_F_PRIVACY)
348 ni->ni_capinfo |= IEEE80211_CAPINFO_PRIVACY;
349 if (ic->ic_phytype == IEEE80211_T_FH) {
350 ni->ni_fhdwell = 200; /* XXX */
353 if (vap->iv_opmode == IEEE80211_M_IBSS) {
354 vap->iv_flags |= IEEE80211_F_SIBSS;
355 ni->ni_capinfo |= IEEE80211_CAPINFO_IBSS; /* XXX */
356 if (vap->iv_flags & IEEE80211_F_DESBSSID)
357 IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_des_bssid);
359 get_random_bytes(ni->ni_bssid, IEEE80211_ADDR_LEN);
360 /* clear group bit, add local bit */
361 ni->ni_bssid[0] = (ni->ni_bssid[0] &~ 0x01) | 0x02;
363 } else if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
364 if (vap->iv_flags & IEEE80211_F_DESBSSID)
365 IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_des_bssid);
367 #ifdef IEEE80211_SUPPORT_TDMA
368 if ((vap->iv_caps & IEEE80211_C_TDMA) == 0)
370 memset(ni->ni_bssid, 0, IEEE80211_ADDR_LEN);
371 #ifdef IEEE80211_SUPPORT_MESH
372 } else if (vap->iv_opmode == IEEE80211_M_MBSS) {
373 ni->ni_meshidlen = vap->iv_mesh->ms_idlen;
374 memcpy(ni->ni_meshid, vap->iv_mesh->ms_id, ni->ni_meshidlen);
378 * Fix the channel and related attributes.
380 /* clear DFS CAC state on previous channel */
381 if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
382 ic->ic_bsschan->ic_freq != chan->ic_freq &&
383 IEEE80211_IS_CHAN_CACDONE(ic->ic_bsschan))
384 ieee80211_dfs_cac_clear(ic, ic->ic_bsschan);
385 ic->ic_bsschan = chan;
386 ieee80211_node_set_chan(ni, chan);
387 ic->ic_curmode = ieee80211_chan2mode(chan);
389 * Do mode-specific setup.
391 if (IEEE80211_IS_CHAN_FULL(chan)) {
392 if (IEEE80211_IS_CHAN_ANYG(chan)) {
394 * Use a mixed 11b/11g basic rate set.
396 ieee80211_setbasicrates(&ni->ni_rates,
398 if (vap->iv_flags & IEEE80211_F_PUREG) {
400 * Also mark OFDM rates basic so 11b
401 * stations do not join (WiFi compliance).
403 ieee80211_addbasicrates(&ni->ni_rates,
406 } else if (IEEE80211_IS_CHAN_B(chan)) {
408 * Force pure 11b rate set.
410 ieee80211_setbasicrates(&ni->ni_rates,
415 (void) ieee80211_sta_join1(ieee80211_ref_node(ni));
419 * Reset bss state on transition to the INIT state.
420 * Clear any stations from the table (they have been
421 * deauth'd) and reset the bss node (clears key, rate
425 ieee80211_reset_bss(struct ieee80211vap *vap)
427 struct ieee80211com *ic = vap->iv_ic;
428 struct ieee80211_node *ni, *obss;
430 ieee80211_node_table_reset(&ic->ic_sta, vap);
431 /* XXX multi-bss: wrong */
432 ieee80211_reset_erp(ic);
434 ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr);
435 KASSERT(ni != NULL, ("unable to setup inital BSS node"));
437 vap->iv_bss = ieee80211_ref_node(ni);
440 ni->ni_intval = ic->ic_bintval;
441 ieee80211_free_node(obss);
443 IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_myaddr);
447 match_ssid(const struct ieee80211_node *ni,
448 int nssid, const struct ieee80211_scan_ssid ssids[])
452 for (i = 0; i < nssid; i++) {
453 if (ni->ni_esslen == ssids[i].len &&
454 memcmp(ni->ni_essid, ssids[i].ssid, ni->ni_esslen) == 0)
461 * Test a node for suitability/compatibility.
464 check_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
466 struct ieee80211com *ic = ni->ni_ic;
469 if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
471 if (vap->iv_opmode == IEEE80211_M_IBSS) {
472 if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
475 if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
478 if (vap->iv_flags & IEEE80211_F_PRIVACY) {
479 if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
482 /* XXX does this mean privacy is supported or required? */
483 if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
486 rate = ieee80211_fix_rate(ni, &ni->ni_rates,
487 IEEE80211_F_JOIN | IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
488 if (rate & IEEE80211_RATE_BASIC)
490 if (vap->iv_des_nssid != 0 &&
491 !match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
493 if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
494 !IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
499 #ifdef IEEE80211_DEBUG
501 * Display node suitability/compatibility.
504 check_bss_debug(struct ieee80211vap *vap, struct ieee80211_node *ni)
506 struct ieee80211com *ic = ni->ni_ic;
511 if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
513 if (vap->iv_opmode == IEEE80211_M_IBSS) {
514 if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
517 if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
520 if (vap->iv_flags & IEEE80211_F_PRIVACY) {
521 if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
524 /* XXX does this mean privacy is supported or required? */
525 if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
528 rate = ieee80211_fix_rate(ni, &ni->ni_rates,
529 IEEE80211_F_JOIN | IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
530 if (rate & IEEE80211_RATE_BASIC)
532 if (vap->iv_des_nssid != 0 &&
533 !match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
535 if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
536 !IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
539 kprintf(" %c %6D", fail ? '-' : '+', ni->ni_macaddr, ":");
540 kprintf(" %6D%c", ni->ni_bssid, ":", fail & 0x20 ? '!' : ' ');
542 ieee80211_chan2ieee(ic, ni->ni_chan), fail & 0x01 ? '!' : ' ');
543 kprintf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2,
544 fail & 0x08 ? '!' : ' ');
546 (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
547 (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
549 fail & 0x02 ? '!' : ' ');
551 (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? "wep" : "no",
552 fail & 0x04 ? '!' : ' ');
553 ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
554 kprintf("%s\n", fail & 0x10 ? "!" : "");
556 #endif /* IEEE80211_DEBUG */
559 * Handle 802.11 ad hoc network merge. The
560 * convention, set by the Wireless Ethernet Compatibility Alliance
561 * (WECA), is that an 802.11 station will change its BSSID to match
562 * the "oldest" 802.11 ad hoc network, on the same channel, that
563 * has the station's desired SSID. The "oldest" 802.11 network
564 * sends beacons with the greatest TSF timestamp.
566 * The caller is assumed to validate TSF's before attempting a merge.
568 * Return !0 if the BSSID changed, 0 otherwise.
571 ieee80211_ibss_merge(struct ieee80211_node *ni)
573 struct ieee80211vap *vap = ni->ni_vap;
574 #ifdef IEEE80211_DEBUG
575 struct ieee80211com *ic = ni->ni_ic;
578 if (ni == vap->iv_bss ||
579 IEEE80211_ADDR_EQ(ni->ni_bssid, vap->iv_bss->ni_bssid)) {
580 /* unchanged, nothing to do */
583 if (!check_bss(vap, ni)) {
584 /* capabilities mismatch */
585 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
586 "%s: merge failed, capabilities mismatch\n", __func__);
587 #ifdef IEEE80211_DEBUG
588 if (ieee80211_msg_assoc(vap))
589 check_bss_debug(vap, ni);
591 vap->iv_stats.is_ibss_capmismatch++;
594 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
595 "%s: new bssid %6D: %s preamble, %s slot time%s\n", __func__,
597 ic->ic_flags&IEEE80211_F_SHPREAMBLE ? "short" : "long",
598 ic->ic_flags&IEEE80211_F_SHSLOT ? "short" : "long",
599 ic->ic_flags&IEEE80211_F_USEPROT ? ", protection" : ""
601 return ieee80211_sta_join1(ieee80211_ref_node(ni));
605 * Calculate HT channel promotion flags for all vaps.
606 * This assumes ni_chan have been setup for each vap.
609 gethtadjustflags(struct ieee80211com *ic)
611 struct ieee80211vap *vap;
616 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
617 if (vap->iv_state < IEEE80211_S_RUN)
619 switch (vap->iv_opmode) {
620 case IEEE80211_M_WDS:
621 case IEEE80211_M_STA:
622 case IEEE80211_M_AHDEMO:
623 case IEEE80211_M_HOSTAP:
624 case IEEE80211_M_IBSS:
625 case IEEE80211_M_MBSS:
626 flags |= ieee80211_htchanflags(vap->iv_bss->ni_chan);
636 * Check if the current channel needs to change based on whether
637 * any vap's are using HT20/HT40. This is used to sync the state
638 * of ic_curchan after a channel width change on a running vap.
641 ieee80211_sync_curchan(struct ieee80211com *ic)
643 struct ieee80211_channel *c;
645 c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, gethtadjustflags(ic));
646 if (c != ic->ic_curchan) {
648 ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan);
649 ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
650 IEEE80211_UNLOCK(ic);
651 ic->ic_set_channel(ic);
652 ieee80211_radiotap_chan_change(ic);
658 * Setup the current channel. The request channel may be
659 * promoted if other vap's are operating with HT20/HT40.
662 ieee80211_setupcurchan(struct ieee80211com *ic, struct ieee80211_channel *c)
664 if (ic->ic_htcaps & IEEE80211_HTC_HT) {
665 int flags = gethtadjustflags(ic);
667 * Check for channel promotion required to support the
668 * set of running vap's. This assumes we are called
669 * after ni_chan is setup for each vap.
671 /* NB: this assumes IEEE80211_FHT_USEHT40 > IEEE80211_FHT_HT */
672 if (flags > ieee80211_htchanflags(c))
673 c = ieee80211_ht_adjust_channel(ic, c, flags);
675 ic->ic_bsschan = ic->ic_curchan = c;
676 ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan);
677 ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
681 * Change the current channel. The channel change is guaranteed to have
682 * happened before the next state change.
685 ieee80211_setcurchan(struct ieee80211com *ic, struct ieee80211_channel *c)
687 ieee80211_setupcurchan(ic, c);
688 ieee80211_runtask(ic, &ic->ic_chan_task);
692 * Join the specified IBSS/BSS network. The node is assumed to
693 * be passed in with a held reference.
696 ieee80211_sta_join1(struct ieee80211_node *selbs)
698 struct ieee80211vap *vap = selbs->ni_vap;
699 struct ieee80211com *ic = selbs->ni_ic;
700 struct ieee80211_node *obss;
704 * Committed to selbs, setup state.
708 * Check if old+new node have the same address in which
709 * case we can reassociate when operating in sta mode.
711 canreassoc = (obss != NULL &&
712 vap->iv_state == IEEE80211_S_RUN &&
713 IEEE80211_ADDR_EQ(obss->ni_macaddr, selbs->ni_macaddr));
714 vap->iv_bss = selbs; /* NB: caller assumed to bump refcnt */
716 copy_bss(selbs, obss);
717 ieee80211_node_decref(obss); /* iv_bss reference */
718 ieee80211_free_node(obss); /* station table reference */
719 obss = NULL; /* NB: guard against later use */
723 * Delete unusable rates; we've already checked
724 * that the negotiated rate set is acceptable.
726 ieee80211_fix_rate(vap->iv_bss, &vap->iv_bss->ni_rates,
727 IEEE80211_F_DODEL | IEEE80211_F_JOIN);
729 ieee80211_setcurchan(ic, selbs->ni_chan);
731 * Set the erp state (mostly the slot time) to deal with
732 * the auto-select case; this should be redundant if the
735 ieee80211_reset_erp(ic);
736 ieee80211_wme_initparams(vap);
738 if (vap->iv_opmode == IEEE80211_M_STA) {
741 ieee80211_new_state(vap, IEEE80211_S_ASSOC, 1);
744 * Act as if we received a DEAUTH frame in case we
745 * are invoked from the RUN state. This will cause
746 * us to try to re-authenticate if we are operating
749 ieee80211_new_state(vap, IEEE80211_S_AUTH,
750 IEEE80211_FC0_SUBTYPE_DEAUTH);
753 ieee80211_new_state(vap, IEEE80211_S_RUN, -1);
758 ieee80211_sta_join(struct ieee80211vap *vap, struct ieee80211_channel *chan,
759 const struct ieee80211_scan_entry *se)
761 struct ieee80211com *ic = vap->iv_ic;
762 struct ieee80211_node *ni;
764 ni = ieee80211_alloc_node(&ic->ic_sta, vap, se->se_macaddr);
770 * Expand scan state into node's format.
771 * XXX may not need all this stuff
773 IEEE80211_ADDR_COPY(ni->ni_bssid, se->se_bssid);
774 ni->ni_esslen = se->se_ssid[1];
775 memcpy(ni->ni_essid, se->se_ssid+2, ni->ni_esslen);
776 ni->ni_tstamp.tsf = se->se_tstamp.tsf;
777 ni->ni_intval = se->se_intval;
778 ni->ni_capinfo = se->se_capinfo;
780 ni->ni_timoff = se->se_timoff;
781 ni->ni_fhdwell = se->se_fhdwell;
782 ni->ni_fhindex = se->se_fhindex;
783 ni->ni_erp = se->se_erp;
784 IEEE80211_RSSI_LPF(ni->ni_avgrssi, se->se_rssi);
785 ni->ni_noise = se->se_noise;
786 if (vap->iv_opmode == IEEE80211_M_STA) {
787 /* NB: only infrastructure mode requires an associd */
788 ni->ni_flags |= IEEE80211_NODE_ASSOCID;
791 if (ieee80211_ies_init(&ni->ni_ies, se->se_ies.data, se->se_ies.len)) {
792 ieee80211_ies_expand(&ni->ni_ies);
793 #ifdef IEEE80211_SUPPORT_SUPERG
794 if (ni->ni_ies.ath_ie != NULL)
795 ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
797 if (ni->ni_ies.htcap_ie != NULL)
798 ieee80211_parse_htcap(ni, ni->ni_ies.htcap_ie);
799 if (ni->ni_ies.htinfo_ie != NULL)
800 ieee80211_parse_htinfo(ni, ni->ni_ies.htinfo_ie);
801 #ifdef IEEE80211_SUPPORT_MESH
802 if (ni->ni_ies.meshid_ie != NULL)
803 ieee80211_parse_meshid(ni, ni->ni_ies.meshid_ie);
805 #ifdef IEEE80211_SUPPORT_TDMA
806 if (ni->ni_ies.tdma_ie != NULL)
807 ieee80211_parse_tdma(ni, ni->ni_ies.tdma_ie);
811 vap->iv_dtim_period = se->se_dtimperiod;
812 vap->iv_dtim_count = 0;
814 /* NB: must be after ni_chan is setup */
815 ieee80211_setup_rates(ni, se->se_rates, se->se_xrates,
817 if (ieee80211_iserp_rateset(&ni->ni_rates))
818 ni->ni_flags |= IEEE80211_NODE_ERP;
819 ieee80211_node_setuptxparms(ni);
821 return ieee80211_sta_join1(ieee80211_ref_node(ni));
825 * Leave the specified IBSS/BSS network. The node is assumed to
826 * be passed in with a held reference.
829 ieee80211_sta_leave(struct ieee80211_node *ni)
831 struct ieee80211com *ic = ni->ni_ic;
833 ic->ic_node_cleanup(ni);
834 ieee80211_notify_node_leave(ni);
838 * Send a deauthenticate frame and drop the station.
841 ieee80211_node_deauth(struct ieee80211_node *ni, int reason)
843 /* NB: bump the refcnt to be sure temporay nodes are not reclaimed */
844 ieee80211_ref_node(ni);
845 if (ni->ni_associd != 0)
846 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH, reason);
847 ieee80211_node_leave(ni);
848 ieee80211_free_node(ni);
851 static struct ieee80211_node *
852 node_alloc(struct ieee80211vap *vap, const uint8_t macaddr[IEEE80211_ADDR_LEN])
854 struct ieee80211_node *ni;
856 ni = (struct ieee80211_node *) kmalloc(sizeof(struct ieee80211_node),
857 M_80211_NODE, M_INTWAIT | M_ZERO);
862 * Initialize an ie blob with the specified data. If previous
863 * data exists re-use the data block. As a side effect we clear
864 * all references to specific ie's; the caller is required to
868 ieee80211_ies_init(struct ieee80211_ies *ies, const uint8_t *data, int len)
870 /* NB: assumes data+len are the last fields */
871 memset(ies, 0, offsetof(struct ieee80211_ies, data));
872 if (ies->data != NULL && ies->len != len) {
873 /* data size changed */
874 kfree(ies->data, M_80211_NODE_IE);
877 if (ies->data == NULL) {
878 ies->data = (uint8_t *) kmalloc(len, M_80211_NODE_IE, M_INTWAIT);
879 if (ies->data == NULL) {
881 /* NB: pointers have already been zero'd above */
885 memcpy(ies->data, data, len);
891 * Reclaim storage for an ie blob.
894 ieee80211_ies_cleanup(struct ieee80211_ies *ies)
896 if (ies->data != NULL)
897 kfree(ies->data, M_80211_NODE_IE);
901 * Expand an ie blob data contents and to fillin individual
902 * ie pointers. The data blob is assumed to be well-formed;
903 * we don't do any validity checking of ie lengths.
906 ieee80211_ies_expand(struct ieee80211_ies *ies)
915 case IEEE80211_ELEMID_VENDOR:
918 else if (iswmeoui(ie))
920 #ifdef IEEE80211_SUPPORT_SUPERG
921 else if (isatherosoui(ie))
924 #ifdef IEEE80211_SUPPORT_TDMA
925 else if (istdmaoui(ie))
929 case IEEE80211_ELEMID_RSN:
932 case IEEE80211_ELEMID_HTCAP:
935 #ifdef IEEE80211_SUPPORT_MESH
936 case IEEE80211_ELEMID_MESHID:
947 * Reclaim any resources in a node and reset any critical
948 * state. Typically nodes are free'd immediately after,
949 * but in some cases the storage may be reused so we need
950 * to insure consistent state (should probably fix that).
953 node_cleanup(struct ieee80211_node *ni)
955 #define N(a) (sizeof(a)/sizeof(a[0]))
956 struct ieee80211vap *vap = ni->ni_vap;
957 struct ieee80211com *ic = ni->ni_ic;
960 /* NB: preserve ni_table */
961 if (ni->ni_flags & IEEE80211_NODE_PWR_MGT) {
962 if (vap->iv_opmode != IEEE80211_M_STA)
964 ni->ni_flags &= ~IEEE80211_NODE_PWR_MGT;
965 IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni,
966 "power save mode off, %u sta's in ps mode", vap->iv_ps_sta);
969 * Cleanup any HT-related state.
971 if (ni->ni_flags & IEEE80211_NODE_HT)
972 ieee80211_ht_node_cleanup(ni);
973 #ifdef IEEE80211_SUPPORT_SUPERG
974 else if (ni->ni_ath_flags & IEEE80211_NODE_ATH)
975 ieee80211_ff_node_cleanup(ni);
977 #ifdef IEEE80211_SUPPORT_MESH
979 * Cleanup any mesh-related state.
981 if (vap->iv_opmode == IEEE80211_M_MBSS)
982 ieee80211_mesh_node_cleanup(ni);
985 * Clear any staging queue entries.
987 ieee80211_ageq_drain_node(&ic->ic_stageq, ni);
990 * Clear AREF flag that marks the authorization refcnt bump
991 * has happened. This is probably not needed as the node
992 * should always be removed from the table so not found but
993 * do it just in case.
994 * Likewise clear the ASSOCID flag as these flags are intended
995 * to be managed in tandem.
997 ni->ni_flags &= ~(IEEE80211_NODE_AREF | IEEE80211_NODE_ASSOCID);
1000 * Drain power save queue and, if needed, clear TIM.
1002 if (ieee80211_node_psq_drain(ni) != 0 && vap->iv_set_tim != NULL)
1003 vap->iv_set_tim(ni, 0);
1006 if (ni->ni_challenge != NULL) {
1007 kfree(ni->ni_challenge, M_80211_NODE);
1008 ni->ni_challenge = NULL;
1011 * Preserve SSID, WPA, and WME ie's so the bss node is
1012 * reusable during a re-auth/re-assoc state transition.
1013 * If we remove these data they will not be recreated
1014 * because they come from a probe-response or beacon frame
1015 * which cannot be expected prior to the association-response.
1016 * This should not be an issue when operating in other modes
1017 * as stations leaving always go through a full state transition
1018 * which will rebuild this state.
1020 * XXX does this leave us open to inheriting old state?
1022 for (i = 0; i < N(ni->ni_rxfrag); i++)
1023 if (ni->ni_rxfrag[i] != NULL) {
1024 m_freem(ni->ni_rxfrag[i]);
1025 ni->ni_rxfrag[i] = NULL;
1028 * Must be careful here to remove any key map entry w/o a LOR.
1030 ieee80211_node_delucastkey(ni);
1035 node_free(struct ieee80211_node *ni)
1037 struct ieee80211com *ic = ni->ni_ic;
1039 ic->ic_node_cleanup(ni);
1040 ieee80211_ies_cleanup(&ni->ni_ies);
1041 ieee80211_psq_cleanup(&ni->ni_psq);
1042 kfree(ni, M_80211_NODE);
1046 node_age(struct ieee80211_node *ni)
1048 struct ieee80211vap *vap = ni->ni_vap;
1050 IEEE80211_NODE_LOCK_ASSERT(&vap->iv_ic->ic_sta);
1053 * Age frames on the power save queue.
1055 if (ieee80211_node_psq_age(ni) != 0 &&
1056 ni->ni_psq.psq_len == 0 && vap->iv_set_tim != NULL)
1057 vap->iv_set_tim(ni, 0);
1059 * Age out HT resources (e.g. frames on the
1060 * A-MPDU reorder queues).
1062 if (ni->ni_associd != 0 && (ni->ni_flags & IEEE80211_NODE_HT))
1063 ieee80211_ht_node_age(ni);
1067 node_getrssi(const struct ieee80211_node *ni)
1069 uint32_t avgrssi = ni->ni_avgrssi;
1072 if (avgrssi == IEEE80211_RSSI_DUMMY_MARKER)
1074 rssi = IEEE80211_RSSI_GET(avgrssi);
1075 return rssi < 0 ? 0 : rssi > 127 ? 127 : rssi;
1079 node_getsignal(const struct ieee80211_node *ni, int8_t *rssi, int8_t *noise)
1081 *rssi = node_getrssi(ni);
1082 *noise = ni->ni_noise;
1086 node_getmimoinfo(const struct ieee80211_node *ni,
1087 struct ieee80211_mimo_info *info)
1089 /* XXX zero data? */
1092 struct ieee80211_node *
1093 ieee80211_alloc_node(struct ieee80211_node_table *nt,
1094 struct ieee80211vap *vap, const uint8_t macaddr[IEEE80211_ADDR_LEN])
1096 struct ieee80211com *ic = nt->nt_ic;
1097 struct ieee80211_node *ni;
1100 ni = ic->ic_node_alloc(vap, macaddr);
1102 vap->iv_stats.is_rx_nodealloc++;
1106 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1107 "%s %p<%6D> in %s table\n", __func__, ni,
1108 macaddr, ":", nt->nt_name);
1110 IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
1111 hash = IEEE80211_NODE_HASH(ic, macaddr);
1112 ieee80211_node_initref(ni); /* mark referenced */
1113 ni->ni_chan = IEEE80211_CHAN_ANYC;
1114 ni->ni_authmode = IEEE80211_AUTH_OPEN;
1115 ni->ni_txpower = ic->ic_txpowlimit; /* max power */
1116 ni->ni_txparms = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)];
1117 ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey, IEEE80211_KEYIX_NONE);
1118 ni->ni_avgrssi = IEEE80211_RSSI_DUMMY_MARKER;
1119 ni->ni_inact_reload = nt->nt_inact_init;
1120 ni->ni_inact = ni->ni_inact_reload;
1121 ni->ni_ath_defkeyix = 0x7fff;
1122 ieee80211_psq_init(&ni->ni_psq, "unknown");
1123 #ifdef IEEE80211_SUPPORT_MESH
1124 if (vap->iv_opmode == IEEE80211_M_MBSS)
1125 ieee80211_mesh_node_init(vap, ni);
1127 IEEE80211_NODE_LOCK(nt);
1128 TAILQ_INSERT_TAIL(&nt->nt_node, ni, ni_list);
1129 LIST_INSERT_HEAD(&nt->nt_hash[hash], ni, ni_hash);
1133 IEEE80211_NODE_UNLOCK(nt);
1135 IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
1136 "%s: inact_reload %u", __func__, ni->ni_inact_reload);
1142 * Craft a temporary node suitable for sending a management frame
1143 * to the specified station. We craft only as much state as we
1144 * need to do the work since the node will be immediately reclaimed
1145 * once the send completes.
1147 struct ieee80211_node *
1148 ieee80211_tmp_node(struct ieee80211vap *vap,
1149 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1151 struct ieee80211com *ic = vap->iv_ic;
1152 struct ieee80211_node *ni;
1154 ni = ic->ic_node_alloc(vap, macaddr);
1156 struct ieee80211_node *bss = vap->iv_bss;
1158 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1159 "%s %p<%6D>\n", __func__, ni, macaddr, ":");
1161 ni->ni_table = NULL; /* NB: pedantic */
1162 ni->ni_ic = ic; /* NB: needed to set channel */
1165 IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
1166 IEEE80211_ADDR_COPY(ni->ni_bssid, bss->ni_bssid);
1167 ieee80211_node_initref(ni); /* mark referenced */
1168 /* NB: required by ieee80211_fix_rate */
1169 ieee80211_node_set_chan(ni, bss->ni_chan);
1170 ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey,
1171 IEEE80211_KEYIX_NONE);
1172 ni->ni_txpower = bss->ni_txpower;
1173 /* XXX optimize away */
1174 ieee80211_psq_init(&ni->ni_psq, "unknown");
1177 vap->iv_stats.is_rx_nodealloc++;
1182 struct ieee80211_node *
1183 ieee80211_dup_bss(struct ieee80211vap *vap,
1184 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1186 struct ieee80211com *ic = vap->iv_ic;
1187 struct ieee80211_node *ni;
1189 ni = ieee80211_alloc_node(&ic->ic_sta, vap, macaddr);
1191 struct ieee80211_node *bss = vap->iv_bss;
1193 * Inherit from iv_bss.
1196 IEEE80211_ADDR_COPY(ni->ni_bssid, bss->ni_bssid);
1197 ieee80211_node_set_chan(ni, bss->ni_chan);
1203 * Create a bss node for a legacy WDS vap. The far end does
1204 * not associate so we just create create a new node and
1205 * simulate an association. The caller is responsible for
1206 * installing the node as the bss node and handling any further
1207 * setup work like authorizing the port.
1209 struct ieee80211_node *
1210 ieee80211_node_create_wds(struct ieee80211vap *vap,
1211 const uint8_t bssid[IEEE80211_ADDR_LEN], struct ieee80211_channel *chan)
1213 struct ieee80211com *ic = vap->iv_ic;
1214 struct ieee80211_node *ni;
1216 /* XXX check if node already in sta table? */
1217 ni = ieee80211_alloc_node(&ic->ic_sta, vap, bssid);
1219 ni->ni_wdsvap = vap;
1220 IEEE80211_ADDR_COPY(ni->ni_bssid, bssid);
1222 * Inherit any manually configured settings.
1224 copy_bss(ni, vap->iv_bss);
1225 ieee80211_node_set_chan(ni, chan);
1226 /* NB: propagate ssid so available to WPA supplicant */
1227 ni->ni_esslen = vap->iv_des_ssid[0].len;
1228 memcpy(ni->ni_essid, vap->iv_des_ssid[0].ssid, ni->ni_esslen);
1229 /* NB: no associd for peer */
1231 * There are no management frames to use to
1232 * discover neighbor capabilities, so blindly
1233 * propagate the local configuration.
1235 if (vap->iv_flags & IEEE80211_F_WME)
1236 ni->ni_flags |= IEEE80211_NODE_QOS;
1237 #ifdef IEEE80211_SUPPORT_SUPERG
1238 if (vap->iv_flags & IEEE80211_F_FF)
1239 ni->ni_flags |= IEEE80211_NODE_FF;
1241 if ((ic->ic_htcaps & IEEE80211_HTC_HT) &&
1242 (vap->iv_flags_ht & IEEE80211_FHT_HT)) {
1244 * Device is HT-capable and HT is enabled for
1245 * the vap; setup HT operation. On return
1246 * ni_chan will be adjusted to an HT channel.
1248 ieee80211_ht_wds_init(ni);
1250 struct ieee80211_channel *c = ni->ni_chan;
1252 * Force a legacy channel to be used.
1254 c = ieee80211_find_channel(ic,
1255 c->ic_freq, c->ic_flags &~ IEEE80211_CHAN_HT);
1256 KASSERT(c != NULL, ("no legacy channel, %u/%x",
1257 ni->ni_chan->ic_freq, ni->ni_chan->ic_flags));
1264 struct ieee80211_node *
1265 #ifdef IEEE80211_DEBUG_REFCNT
1266 ieee80211_find_node_locked_debug(struct ieee80211_node_table *nt,
1267 const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1269 ieee80211_find_node_locked(struct ieee80211_node_table *nt,
1270 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1273 struct ieee80211_node *ni;
1276 IEEE80211_NODE_LOCK_ASSERT(nt);
1278 hash = IEEE80211_NODE_HASH(nt->nt_ic, macaddr);
1279 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
1280 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
1281 ieee80211_ref_node(ni); /* mark referenced */
1282 #ifdef IEEE80211_DEBUG_REFCNT
1283 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1284 "%s (%s:%u) %p<%6D> refcnt %d\n", __func__,
1286 ni, ni->ni_macaddr, ":",
1287 ieee80211_node_refcnt(ni));
1295 struct ieee80211_node *
1296 #ifdef IEEE80211_DEBUG_REFCNT
1297 ieee80211_find_node_debug(struct ieee80211_node_table *nt,
1298 const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1300 ieee80211_find_node(struct ieee80211_node_table *nt,
1301 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1304 struct ieee80211_node *ni;
1306 IEEE80211_NODE_LOCK(nt);
1307 ni = ieee80211_find_node_locked(nt, macaddr);
1308 IEEE80211_NODE_UNLOCK(nt);
1312 struct ieee80211_node *
1313 #ifdef IEEE80211_DEBUG_REFCNT
1314 ieee80211_find_vap_node_locked_debug(struct ieee80211_node_table *nt,
1315 const struct ieee80211vap *vap,
1316 const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1318 ieee80211_find_vap_node_locked(struct ieee80211_node_table *nt,
1319 const struct ieee80211vap *vap,
1320 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1323 struct ieee80211_node *ni;
1326 IEEE80211_NODE_LOCK_ASSERT(nt);
1328 hash = IEEE80211_NODE_HASH(nt->nt_ic, macaddr);
1329 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
1330 if (ni->ni_vap == vap &&
1331 IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
1332 ieee80211_ref_node(ni); /* mark referenced */
1333 #ifdef IEEE80211_DEBUG_REFCNT
1334 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1335 "%s (%s:%u) %p<%6D> refcnt %d\n", __func__,
1337 ni, ni->ni_macaddr, ":",
1338 ieee80211_node_refcnt(ni));
1346 struct ieee80211_node *
1347 #ifdef IEEE80211_DEBUG_REFCNT
1348 ieee80211_find_vap_node_debug(struct ieee80211_node_table *nt,
1349 const struct ieee80211vap *vap,
1350 const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
1352 ieee80211_find_vap_node(struct ieee80211_node_table *nt,
1353 const struct ieee80211vap *vap,
1354 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1357 struct ieee80211_node *ni;
1359 IEEE80211_NODE_LOCK(nt);
1360 ni = ieee80211_find_vap_node_locked(nt, vap, macaddr);
1361 IEEE80211_NODE_UNLOCK(nt);
1366 * Fake up a node; this handles node discovery in adhoc mode.
1367 * Note that for the driver's benefit we we treat this like
1368 * an association so the driver has an opportunity to setup
1369 * it's private state.
1371 struct ieee80211_node *
1372 ieee80211_fakeup_adhoc_node(struct ieee80211vap *vap,
1373 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1375 struct ieee80211_node *ni;
1377 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1378 "%s: mac<%6D>\n", __func__, macaddr, ":");
1379 ni = ieee80211_dup_bss(vap, macaddr);
1381 struct ieee80211com *ic = vap->iv_ic;
1383 /* XXX no rate negotiation; just dup */
1384 ni->ni_rates = vap->iv_bss->ni_rates;
1385 if (ieee80211_iserp_rateset(&ni->ni_rates))
1386 ni->ni_flags |= IEEE80211_NODE_ERP;
1387 if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
1389 * In adhoc demo mode there are no management
1390 * frames to use to discover neighbor capabilities,
1391 * so blindly propagate the local configuration
1392 * so we can do interesting things (e.g. use
1393 * WME to disable ACK's).
1395 if (vap->iv_flags & IEEE80211_F_WME)
1396 ni->ni_flags |= IEEE80211_NODE_QOS;
1397 #ifdef IEEE80211_SUPPORT_SUPERG
1398 if (vap->iv_flags & IEEE80211_F_FF)
1399 ni->ni_flags |= IEEE80211_NODE_FF;
1402 ieee80211_node_setuptxparms(ni);
1403 if (ic->ic_newassoc != NULL)
1404 ic->ic_newassoc(ni, 1);
1405 /* XXX not right for 802.1x/WPA */
1406 ieee80211_node_authorize(ni);
1412 ieee80211_init_neighbor(struct ieee80211_node *ni,
1413 const struct ieee80211_frame *wh,
1414 const struct ieee80211_scanparams *sp)
1416 ni->ni_esslen = sp->ssid[1];
1417 memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]);
1418 IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
1419 memcpy(ni->ni_tstamp.data, sp->tstamp, sizeof(ni->ni_tstamp));
1420 ni->ni_intval = sp->bintval;
1421 ni->ni_capinfo = sp->capinfo;
1422 ni->ni_chan = ni->ni_ic->ic_curchan;
1423 ni->ni_fhdwell = sp->fhdwell;
1424 ni->ni_fhindex = sp->fhindex;
1425 ni->ni_erp = sp->erp;
1426 ni->ni_timoff = sp->timoff;
1427 #ifdef IEEE80211_SUPPORT_MESH
1428 if (ni->ni_vap->iv_opmode == IEEE80211_M_MBSS)
1429 ieee80211_mesh_init_neighbor(ni, wh, sp);
1431 if (ieee80211_ies_init(&ni->ni_ies, sp->ies, sp->ies_len)) {
1432 ieee80211_ies_expand(&ni->ni_ies);
1433 if (ni->ni_ies.wme_ie != NULL)
1434 ni->ni_flags |= IEEE80211_NODE_QOS;
1436 ni->ni_flags &= ~IEEE80211_NODE_QOS;
1437 #ifdef IEEE80211_SUPPORT_SUPERG
1438 if (ni->ni_ies.ath_ie != NULL)
1439 ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
1443 /* NB: must be after ni_chan is setup */
1444 ieee80211_setup_rates(ni, sp->rates, sp->xrates,
1445 IEEE80211_F_DOSORT | IEEE80211_F_DOFRATE |
1446 IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
1450 * Do node discovery in adhoc mode on receipt of a beacon
1451 * or probe response frame. Note that for the driver's
1452 * benefit we we treat this like an association so the
1453 * driver has an opportunity to setup it's private state.
1455 struct ieee80211_node *
1456 ieee80211_add_neighbor(struct ieee80211vap *vap,
1457 const struct ieee80211_frame *wh,
1458 const struct ieee80211_scanparams *sp)
1460 struct ieee80211_node *ni;
1462 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1463 "%s: mac<%6D>\n", __func__, wh->i_addr2, ":");
1464 ni = ieee80211_dup_bss(vap, wh->i_addr2);/* XXX alloc_node? */
1466 struct ieee80211com *ic = vap->iv_ic;
1468 ieee80211_init_neighbor(ni, wh, sp);
1469 if (ieee80211_iserp_rateset(&ni->ni_rates))
1470 ni->ni_flags |= IEEE80211_NODE_ERP;
1471 ieee80211_node_setuptxparms(ni);
1472 if (ic->ic_newassoc != NULL)
1473 ic->ic_newassoc(ni, 1);
1474 /* XXX not right for 802.1x/WPA */
1475 ieee80211_node_authorize(ni);
1480 #define IS_PROBEREQ(wh) \
1481 ((wh->i_fc[0] & (IEEE80211_FC0_TYPE_MASK|IEEE80211_FC0_SUBTYPE_MASK)) \
1482 == (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ))
1483 #define IS_BCAST_PROBEREQ(wh) \
1484 (IS_PROBEREQ(wh) && IEEE80211_IS_MULTICAST( \
1485 ((const struct ieee80211_frame *)(wh))->i_addr3))
1487 static __inline struct ieee80211_node *
1488 _find_rxnode(struct ieee80211_node_table *nt,
1489 const struct ieee80211_frame_min *wh)
1491 if (IS_BCAST_PROBEREQ(wh))
1492 return NULL; /* spam bcast probe req to all vap's */
1493 return ieee80211_find_node_locked(nt, wh->i_addr2);
1497 * Locate the node for sender, track state, and then pass the
1498 * (referenced) node up to the 802.11 layer for its use. Note
1499 * we can return NULL if the sender is not in the table.
1501 struct ieee80211_node *
1502 #ifdef IEEE80211_DEBUG_REFCNT
1503 ieee80211_find_rxnode_debug(struct ieee80211com *ic,
1504 const struct ieee80211_frame_min *wh, const char *func, int line)
1506 ieee80211_find_rxnode(struct ieee80211com *ic,
1507 const struct ieee80211_frame_min *wh)
1510 struct ieee80211_node_table *nt;
1511 struct ieee80211_node *ni;
1514 IEEE80211_NODE_LOCK(nt);
1515 ni = _find_rxnode(nt, wh);
1516 IEEE80211_NODE_UNLOCK(nt);
1522 * Like ieee80211_find_rxnode but use the supplied h/w
1523 * key index as a hint to locate the node in the key
1524 * mapping table. If an entry is present at the key
1525 * index we return it; otherwise do a normal lookup and
1526 * update the mapping table if the station has a unicast
1527 * key assigned to it.
1529 struct ieee80211_node *
1530 #ifdef IEEE80211_DEBUG_REFCNT
1531 ieee80211_find_rxnode_withkey_debug(struct ieee80211com *ic,
1532 const struct ieee80211_frame_min *wh, ieee80211_keyix keyix,
1533 const char *func, int line)
1535 ieee80211_find_rxnode_withkey(struct ieee80211com *ic,
1536 const struct ieee80211_frame_min *wh, ieee80211_keyix keyix)
1539 struct ieee80211_node_table *nt;
1540 struct ieee80211_node *ni;
1543 IEEE80211_NODE_LOCK(nt);
1544 if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax)
1545 ni = nt->nt_keyixmap[keyix];
1549 ni = _find_rxnode(nt, wh);
1550 if (ni != NULL && nt->nt_keyixmap != NULL) {
1552 * If the station has a unicast key cache slot
1553 * assigned update the key->node mapping table.
1555 keyix = ni->ni_ucastkey.wk_rxkeyix;
1556 /* XXX can keyixmap[keyix] != NULL? */
1557 if (keyix < nt->nt_keyixmax &&
1558 nt->nt_keyixmap[keyix] == NULL) {
1559 IEEE80211_DPRINTF(ni->ni_vap,
1561 "%s: add key map entry %p<%6D> refcnt %d\n",
1562 __func__, ni, ni->ni_macaddr, ":",
1563 ieee80211_node_refcnt(ni)+1);
1564 nt->nt_keyixmap[keyix] = ieee80211_ref_node(ni);
1568 if (IS_BCAST_PROBEREQ(wh))
1569 ni = NULL; /* spam bcast probe req to all vap's */
1571 ieee80211_ref_node(ni);
1573 IEEE80211_NODE_UNLOCK(nt);
1577 #undef IS_BCAST_PROBEREQ
1581 * Return a reference to the appropriate node for sending
1582 * a data frame. This handles node discovery in adhoc networks.
1584 struct ieee80211_node *
1585 #ifdef IEEE80211_DEBUG_REFCNT
1586 ieee80211_find_txnode_debug(struct ieee80211vap *vap,
1587 const uint8_t macaddr[IEEE80211_ADDR_LEN],
1588 const char *func, int line)
1590 ieee80211_find_txnode(struct ieee80211vap *vap,
1591 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1594 struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
1595 struct ieee80211_node *ni;
1598 * The destination address should be in the node table
1599 * unless this is a multicast/broadcast frame. We can
1600 * also optimize station mode operation, all frames go
1603 /* XXX can't hold lock across dup_bss 'cuz of recursive locking */
1604 IEEE80211_NODE_LOCK(nt);
1605 if (vap->iv_opmode == IEEE80211_M_STA ||
1606 vap->iv_opmode == IEEE80211_M_WDS ||
1607 IEEE80211_IS_MULTICAST(macaddr))
1608 ni = ieee80211_ref_node(vap->iv_bss);
1610 ni = ieee80211_find_node_locked(nt, macaddr);
1611 IEEE80211_NODE_UNLOCK(nt);
1614 if (vap->iv_opmode == IEEE80211_M_IBSS ||
1615 vap->iv_opmode == IEEE80211_M_AHDEMO) {
1617 * In adhoc mode cons up a node for the destination.
1618 * Note that we need an additional reference for the
1619 * caller to be consistent with
1620 * ieee80211_find_node_locked.
1622 ni = ieee80211_fakeup_adhoc_node(vap, macaddr);
1624 (void) ieee80211_ref_node(ni);
1626 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_OUTPUT, macaddr,
1627 "no node, discard frame (%s)", __func__);
1628 vap->iv_stats.is_tx_nonode++;
1635 _ieee80211_free_node(struct ieee80211_node *ni)
1637 struct ieee80211_node_table *nt = ni->ni_table;
1640 * NB: careful about referencing the vap as it may be
1641 * gone if the last reference was held by a driver.
1642 * We know the com will always be present so it's safe
1643 * to use ni_ic below to reclaim resources.
1646 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1647 "%s %p<%6D> in %s table\n", __func__, ni,
1648 ni->ni_macaddr, ":",
1649 nt != NULL ? nt->nt_name : "<gone>");
1651 if (ni->ni_associd != 0) {
1652 struct ieee80211vap *vap = ni->ni_vap;
1653 if (vap->iv_aid_bitmap != NULL)
1654 IEEE80211_AID_CLR(vap, ni->ni_associd);
1657 TAILQ_REMOVE(&nt->nt_node, ni, ni_list);
1658 LIST_REMOVE(ni, ni_hash);
1660 ni->ni_ic->ic_node_free(ni);
1664 #ifdef IEEE80211_DEBUG_REFCNT
1665 ieee80211_free_node_debug(struct ieee80211_node *ni, const char *func, int line)
1667 ieee80211_free_node(struct ieee80211_node *ni)
1670 struct ieee80211_node_table *nt = ni->ni_table;
1672 #ifdef IEEE80211_DEBUG_REFCNT
1673 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1674 "%s (%s:%u) %p<%6D> refcnt %d\n", __func__, func, line, ni,
1675 ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)-1);
1678 IEEE80211_NODE_LOCK(nt);
1679 if (ieee80211_node_dectestref(ni)) {
1681 * Last reference, reclaim state.
1683 _ieee80211_free_node(ni);
1684 } else if (ieee80211_node_refcnt(ni) == 1 &&
1685 nt->nt_keyixmap != NULL) {
1686 ieee80211_keyix keyix;
1688 * Check for a last reference in the key mapping table.
1690 keyix = ni->ni_ucastkey.wk_rxkeyix;
1691 if (keyix < nt->nt_keyixmax &&
1692 nt->nt_keyixmap[keyix] == ni) {
1693 IEEE80211_DPRINTF(ni->ni_vap,
1695 "%s: %p<%6D> clear key map entry", __func__,
1696 ni, ni->ni_macaddr, ":");
1697 nt->nt_keyixmap[keyix] = NULL;
1698 ieee80211_node_decref(ni); /* XXX needed? */
1699 _ieee80211_free_node(ni);
1702 IEEE80211_NODE_UNLOCK(nt);
1704 if (ieee80211_node_dectestref(ni))
1705 _ieee80211_free_node(ni);
1710 * Reclaim a unicast key and clear any key cache state.
1713 ieee80211_node_delucastkey(struct ieee80211_node *ni)
1715 struct ieee80211com *ic = ni->ni_ic;
1716 struct ieee80211_node_table *nt = &ic->ic_sta;
1717 struct ieee80211_node *nikey;
1718 ieee80211_keyix keyix;
1719 int isowned, status;
1722 * NB: We must beware of LOR here; deleting the key
1723 * can cause the crypto layer to block traffic updates
1724 * which can generate a LOR against the node table lock;
1725 * grab it here and stash the key index for our use below.
1727 * Must also beware of recursion on the node table lock.
1728 * When called from node_cleanup we may already have
1729 * the node table lock held. Unfortunately there's no
1730 * way to separate out this path so we must do this
1733 isowned = IEEE80211_NODE_IS_LOCKED(nt);
1735 IEEE80211_NODE_LOCK(nt);
1737 status = 1; /* NB: success */
1738 if (ni->ni_ucastkey.wk_keyix != IEEE80211_KEYIX_NONE) {
1739 keyix = ni->ni_ucastkey.wk_rxkeyix;
1740 status = ieee80211_crypto_delkey(ni->ni_vap, &ni->ni_ucastkey);
1741 if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax) {
1742 nikey = nt->nt_keyixmap[keyix];
1743 nt->nt_keyixmap[keyix] = NULL;
1747 IEEE80211_NODE_UNLOCK(nt);
1749 if (nikey != NULL) {
1750 KASSERT(nikey == ni,
1751 ("key map out of sync, ni %p nikey %p", ni, nikey));
1752 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1753 "%s: delete key map entry %p<%6D> refcnt %d\n",
1754 __func__, ni, ni->ni_macaddr, ":",
1755 ieee80211_node_refcnt(ni)-1);
1756 ieee80211_free_node(ni);
1762 * Reclaim a node. If this is the last reference count then
1763 * do the normal free work. Otherwise remove it from the node
1764 * table and mark it gone by clearing the back-reference.
1767 node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
1769 ieee80211_keyix keyix;
1771 IEEE80211_NODE_LOCK_ASSERT(nt);
1773 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1774 "%s: remove %p<%6D> from %s table, refcnt %d\n",
1775 __func__, ni, ni->ni_macaddr, ":",
1776 nt->nt_name, ieee80211_node_refcnt(ni)-1);
1778 * Clear any entry in the unicast key mapping table.
1779 * We need to do it here so rx lookups don't find it
1780 * in the mapping table even if it's not in the hash
1781 * table. We cannot depend on the mapping table entry
1782 * being cleared because the node may not be free'd.
1784 keyix = ni->ni_ucastkey.wk_rxkeyix;
1785 if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax &&
1786 nt->nt_keyixmap[keyix] == ni) {
1787 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
1788 "%s: %p<%6D> clear key map entry %u\n",
1789 __func__, ni, ni->ni_macaddr, ":", keyix);
1790 nt->nt_keyixmap[keyix] = NULL;
1791 ieee80211_node_decref(ni); /* NB: don't need free */
1793 if (!ieee80211_node_dectestref(ni)) {
1795 * Other references are present, just remove the
1796 * node from the table so it cannot be found. When
1797 * the references are dropped storage will be
1800 TAILQ_REMOVE(&nt->nt_node, ni, ni_list);
1801 LIST_REMOVE(ni, ni_hash);
1802 ni->ni_table = NULL; /* clear reference */
1804 _ieee80211_free_node(ni);
1808 * Node table support.
1812 ieee80211_node_table_init(struct ieee80211com *ic,
1813 struct ieee80211_node_table *nt,
1814 const char *name, int inact, int keyixmax)
1816 struct ifnet *ifp = ic->ic_ifp;
1819 IEEE80211_NODE_LOCK_INIT(nt, ifp->if_xname);
1820 IEEE80211_NODE_ITERATE_LOCK_INIT(nt, ifp->if_xname);
1821 TAILQ_INIT(&nt->nt_node);
1824 nt->nt_inact_init = inact;
1825 nt->nt_keyixmax = keyixmax;
1826 if (nt->nt_keyixmax > 0) {
1827 nt->nt_keyixmap = (struct ieee80211_node **) kmalloc(
1828 keyixmax * sizeof(struct ieee80211_node *),
1829 M_80211_NODE, M_INTWAIT | M_ZERO);
1830 if (nt->nt_keyixmap == NULL)
1831 if_printf(ic->ic_ifp,
1832 "Cannot allocate key index map with %u entries\n",
1835 nt->nt_keyixmap = NULL;
1839 ieee80211_node_table_reset(struct ieee80211_node_table *nt,
1840 struct ieee80211vap *match)
1842 struct ieee80211_node *ni, *next;
1844 IEEE80211_NODE_LOCK(nt);
1845 TAILQ_FOREACH_MUTABLE(ni, &nt->nt_node, ni_list, next) {
1846 if (match != NULL && ni->ni_vap != match)
1848 /* XXX can this happen? if so need's work */
1849 if (ni->ni_associd != 0) {
1850 struct ieee80211vap *vap = ni->ni_vap;
1852 if (vap->iv_auth->ia_node_leave != NULL)
1853 vap->iv_auth->ia_node_leave(ni);
1854 if (vap->iv_aid_bitmap != NULL)
1855 IEEE80211_AID_CLR(vap, ni->ni_associd);
1857 ni->ni_wdsvap = NULL; /* clear reference */
1858 node_reclaim(nt, ni);
1860 if (match != NULL && match->iv_opmode == IEEE80211_M_WDS) {
1862 * Make a separate pass to clear references to this vap
1863 * held by DWDS entries. They will not be matched above
1864 * because ni_vap will point to the ap vap but we still
1865 * need to clear ni_wdsvap when the WDS vap is destroyed
1868 TAILQ_FOREACH_MUTABLE(ni, &nt->nt_node, ni_list, next)
1869 if (ni->ni_wdsvap == match)
1870 ni->ni_wdsvap = NULL;
1872 IEEE80211_NODE_UNLOCK(nt);
1876 ieee80211_node_table_cleanup(struct ieee80211_node_table *nt)
1878 ieee80211_node_table_reset(nt, NULL);
1879 if (nt->nt_keyixmap != NULL) {
1881 /* XXX verify all entries are NULL */
1883 for (i = 0; i < nt->nt_keyixmax; i++)
1884 if (nt->nt_keyixmap[i] != NULL)
1885 printf("%s: %s[%u] still active\n", __func__,
1888 kfree(nt->nt_keyixmap, M_80211_NODE);
1889 nt->nt_keyixmap = NULL;
1891 IEEE80211_NODE_ITERATE_LOCK_DESTROY(nt);
1892 IEEE80211_NODE_LOCK_DESTROY(nt);
1896 * Timeout inactive stations and do related housekeeping.
1897 * Note that we cannot hold the node lock while sending a
1898 * frame as this would lead to a LOR. Instead we use a
1899 * generation number to mark nodes that we've scanned and
1900 * drop the lock and restart a scan if we have to time out
1901 * a node. Since we are single-threaded by virtue of
1902 * controlling the inactivity timer we can be sure this will
1903 * process each node only once.
1906 ieee80211_timeout_stations(struct ieee80211com *ic)
1908 struct ieee80211_node_table *nt = &ic->ic_sta;
1909 struct ieee80211vap *vap;
1910 struct ieee80211_node *ni;
1913 IEEE80211_NODE_ITERATE_LOCK(nt);
1914 gen = ++nt->nt_scangen;
1916 IEEE80211_NODE_LOCK(nt);
1917 TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
1918 if (ni->ni_scangen == gen) /* previously handled */
1920 ni->ni_scangen = gen;
1922 * Ignore entries for which have yet to receive an
1923 * authentication frame. These are transient and
1924 * will be reclaimed when the last reference to them
1925 * goes away (when frame xmits complete).
1929 * Only process stations when in RUN state. This
1930 * insures, for example, that we don't timeout an
1931 * inactive station during CAC. Note that CSA state
1932 * is actually handled in ieee80211_node_timeout as
1933 * it applies to more than timeout processing.
1935 if (vap->iv_state != IEEE80211_S_RUN)
1937 /* XXX can vap be NULL? */
1938 if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
1939 vap->iv_opmode == IEEE80211_M_STA) &&
1940 (ni->ni_flags & IEEE80211_NODE_AREF) == 0)
1943 * Free fragment if not needed anymore
1944 * (last fragment older than 1s).
1945 * XXX doesn't belong here, move to node_age
1947 if (ni->ni_rxfrag[0] != NULL &&
1948 ticks > ni->ni_rxfragstamp + hz) {
1949 m_freem(ni->ni_rxfrag[0]);
1950 ni->ni_rxfrag[0] = NULL;
1952 if (ni->ni_inact > 0) {
1954 IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
1955 "%s: inact %u inact_reload %u nrates %u",
1956 __func__, ni->ni_inact, ni->ni_inact_reload,
1957 ni->ni_rates.rs_nrates);
1960 * Special case ourself; we may be idle for extended periods
1961 * of time and regardless reclaiming our state is wrong.
1962 * XXX run ic_node_age
1964 if (ni == vap->iv_bss)
1966 if (ni->ni_associd != 0 ||
1967 (vap->iv_opmode == IEEE80211_M_IBSS ||
1968 vap->iv_opmode == IEEE80211_M_AHDEMO)) {
1970 * Age/drain resources held by the station.
1972 ic->ic_node_age(ni);
1974 * Probe the station before time it out. We
1975 * send a null data frame which may not be
1976 * universally supported by drivers (need it
1977 * for ps-poll support so it should be...).
1979 * XXX don't probe the station unless we've
1980 * received a frame from them (and have
1981 * some idea of the rates they are capable
1982 * of); this will get fixed more properly
1983 * soon with better handling of the rate set.
1985 if ((vap->iv_flags_ext & IEEE80211_FEXT_INACT) &&
1986 (0 < ni->ni_inact &&
1987 ni->ni_inact <= vap->iv_inact_probe) &&
1988 ni->ni_rates.rs_nrates != 0) {
1990 IEEE80211_MSG_INACT | IEEE80211_MSG_NODE,
1992 "probe station due to inactivity");
1994 * Grab a reference before unlocking the table
1995 * so the node cannot be reclaimed before we
1996 * send the frame. ieee80211_send_nulldata
1997 * understands we've done this and reclaims the
1998 * ref for us as needed.
2000 ieee80211_ref_node(ni);
2001 IEEE80211_NODE_UNLOCK(nt);
2002 ieee80211_send_nulldata(ni);
2007 if ((vap->iv_flags_ext & IEEE80211_FEXT_INACT) &&
2008 ni->ni_inact <= 0) {
2010 IEEE80211_MSG_INACT | IEEE80211_MSG_NODE, ni,
2011 "station timed out due to inactivity "
2012 "(refcnt %u)", ieee80211_node_refcnt(ni));
2014 * Send a deauthenticate frame and drop the station.
2015 * This is somewhat complicated due to reference counts
2016 * and locking. At this point a station will typically
2017 * have a reference count of 1. ieee80211_node_leave
2018 * will do a "free" of the node which will drop the
2019 * reference count. But in the meantime a reference
2020 * wil be held by the deauth frame. The actual reclaim
2021 * of the node will happen either after the tx is
2022 * completed or by ieee80211_node_leave.
2024 * Separately we must drop the node lock before sending
2025 * in case the driver takes a lock, as this can result
2026 * in a LOR between the node lock and the driver lock.
2028 ieee80211_ref_node(ni);
2029 IEEE80211_NODE_UNLOCK(nt);
2030 if (ni->ni_associd != 0) {
2031 IEEE80211_SEND_MGMT(ni,
2032 IEEE80211_FC0_SUBTYPE_DEAUTH,
2033 IEEE80211_REASON_AUTH_EXPIRE);
2035 ieee80211_node_leave(ni);
2036 ieee80211_free_node(ni);
2037 vap->iv_stats.is_node_timeout++;
2041 IEEE80211_NODE_UNLOCK(nt);
2043 IEEE80211_NODE_ITERATE_UNLOCK(nt);
2047 * Aggressively reclaim resources. This should be used
2048 * only in a critical situation to reclaim mbuf resources.
2051 ieee80211_drain(struct ieee80211com *ic)
2053 struct ieee80211_node_table *nt = &ic->ic_sta;
2054 struct ieee80211vap *vap;
2055 struct ieee80211_node *ni;
2057 IEEE80211_NODE_LOCK(nt);
2058 TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
2060 * Ignore entries for which have yet to receive an
2061 * authentication frame. These are transient and
2062 * will be reclaimed when the last reference to them
2063 * goes away (when frame xmits complete).
2067 * Only process stations when in RUN state. This
2068 * insures, for example, that we don't timeout an
2069 * inactive station during CAC. Note that CSA state
2070 * is actually handled in ieee80211_node_timeout as
2071 * it applies to more than timeout processing.
2073 if (vap->iv_state != IEEE80211_S_RUN)
2075 /* XXX can vap be NULL? */
2076 if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
2077 vap->iv_opmode == IEEE80211_M_STA) &&
2078 (ni->ni_flags & IEEE80211_NODE_AREF) == 0)
2082 * XXX doesn't belong here, move to node_drain
2084 if (ni->ni_rxfrag[0] != NULL) {
2085 m_freem(ni->ni_rxfrag[0]);
2086 ni->ni_rxfrag[0] = NULL;
2089 * Drain resources held by the station.
2091 ic->ic_node_drain(ni);
2093 IEEE80211_NODE_UNLOCK(nt);
2097 * Per-ieee80211com inactivity timer callback.
2100 ieee80211_node_timeout(void *arg)
2102 struct ieee80211com *ic = arg;
2105 * Defer timeout processing if a channel switch is pending.
2106 * We typically need to be mute so not doing things that
2107 * might generate frames is good to handle in one place.
2108 * Supressing the station timeout processing may extend the
2109 * lifetime of inactive stations (by not decrementing their
2110 * idle counters) but this should be ok unless the CSA is
2111 * active for an unusually long time.
2113 if ((ic->ic_flags & IEEE80211_F_CSAPENDING) == 0) {
2114 ieee80211_scan_timeout(ic);
2115 ieee80211_timeout_stations(ic);
2116 ieee80211_ageq_age(&ic->ic_stageq, IEEE80211_INACT_WAIT);
2119 ieee80211_erp_timeout(ic);
2120 ieee80211_ht_timeout(ic);
2121 IEEE80211_UNLOCK(ic);
2123 callout_reset(&ic->ic_inact, IEEE80211_INACT_WAIT*hz,
2124 ieee80211_node_timeout, ic);
2128 ieee80211_iterate_nodes(struct ieee80211_node_table *nt,
2129 ieee80211_iter_func *f, void *arg)
2131 struct ieee80211_node *ni;
2134 IEEE80211_NODE_ITERATE_LOCK(nt);
2135 gen = ++nt->nt_scangen;
2137 IEEE80211_NODE_LOCK(nt);
2138 TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
2139 if (ni->ni_scangen != gen) {
2140 ni->ni_scangen = gen;
2141 (void) ieee80211_ref_node(ni);
2142 IEEE80211_NODE_UNLOCK(nt);
2144 ieee80211_free_node(ni);
2148 IEEE80211_NODE_UNLOCK(nt);
2150 IEEE80211_NODE_ITERATE_UNLOCK(nt);
2154 ieee80211_dump_node(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
2156 kprintf("0x%p: mac %6D refcnt %d\n", ni, ni->ni_macaddr, ":",
2157 ieee80211_node_refcnt(ni));
2158 kprintf("\tscangen %u authmode %u flags 0x%x\n",
2159 ni->ni_scangen, ni->ni_authmode, ni->ni_flags);
2160 kprintf("\tassocid 0x%x txpower %u vlan %u\n",
2161 ni->ni_associd, ni->ni_txpower, ni->ni_vlan);
2162 kprintf("\ttxseq %u rxseq %u fragno %u rxfragstamp %u\n",
2163 ni->ni_txseqs[IEEE80211_NONQOS_TID],
2164 ni->ni_rxseqs[IEEE80211_NONQOS_TID] >> IEEE80211_SEQ_SEQ_SHIFT,
2165 ni->ni_rxseqs[IEEE80211_NONQOS_TID] & IEEE80211_SEQ_FRAG_MASK,
2166 ni->ni_rxfragstamp);
2167 kprintf("\trssi %d noise %d intval %u capinfo 0x%x\n",
2168 node_getrssi(ni), ni->ni_noise,
2169 ni->ni_intval, ni->ni_capinfo);
2170 kprintf("\tbssid %6D essid \"%.*s\" channel %u:0x%x\n",
2172 ni->ni_esslen, ni->ni_essid,
2173 ni->ni_chan->ic_freq, ni->ni_chan->ic_flags);
2174 kprintf("\tinact %u inact_reload %u txrate %u\n",
2175 ni->ni_inact, ni->ni_inact_reload, ni->ni_txrate);
2176 kprintf("\thtcap %x htparam %x htctlchan %u ht2ndchan %u\n",
2177 ni->ni_htcap, ni->ni_htparam,
2178 ni->ni_htctlchan, ni->ni_ht2ndchan);
2179 kprintf("\thtopmode %x htstbc %x chw %u\n",
2180 ni->ni_htopmode, ni->ni_htstbc, ni->ni_chw);
2184 ieee80211_dump_nodes(struct ieee80211_node_table *nt)
2186 ieee80211_iterate_nodes(nt,
2187 (ieee80211_iter_func *) ieee80211_dump_node, nt);
2191 ieee80211_notify_erp_locked(struct ieee80211com *ic)
2193 struct ieee80211vap *vap;
2195 IEEE80211_LOCK_ASSERT(ic);
2197 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
2198 if (vap->iv_opmode == IEEE80211_M_HOSTAP)
2199 ieee80211_beacon_notify(vap, IEEE80211_BEACON_ERP);
2203 ieee80211_notify_erp(struct ieee80211com *ic)
2206 ieee80211_notify_erp_locked(ic);
2207 IEEE80211_UNLOCK(ic);
2211 * Handle a station joining an 11g network.
2214 ieee80211_node_join_11g(struct ieee80211_node *ni)
2216 struct ieee80211com *ic = ni->ni_ic;
2218 IEEE80211_LOCK_ASSERT(ic);
2221 * Station isn't capable of short slot time. Bump
2222 * the count of long slot time stations and disable
2223 * use of short slot time. Note that the actual switch
2224 * over to long slot time use may not occur until the
2225 * next beacon transmission (per sec. 7.3.1.4 of 11g).
2227 if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) {
2228 ic->ic_longslotsta++;
2229 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2230 "station needs long slot time, count %d",
2231 ic->ic_longslotsta);
2232 /* XXX vap's w/ conflicting needs won't work */
2233 if (!IEEE80211_IS_CHAN_108G(ic->ic_bsschan)) {
2235 * Don't force slot time when switched to turbo
2236 * mode as non-ERP stations won't be present; this
2237 * need only be done when on the normal G channel.
2239 ieee80211_set_shortslottime(ic, 0);
2243 * If the new station is not an ERP station
2244 * then bump the counter and enable protection
2247 if (!ieee80211_iserp_rateset(&ni->ni_rates)) {
2249 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2250 "station is !ERP, %d non-ERP stations associated",
2253 * If station does not support short preamble
2254 * then we must enable use of Barker preamble.
2256 if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE) == 0) {
2257 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2258 "%s", "station needs long preamble");
2259 ic->ic_flags |= IEEE80211_F_USEBARKER;
2260 ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
2263 * If protection is configured and this is the first
2264 * indication we should use protection, enable it.
2266 if (ic->ic_protmode != IEEE80211_PROT_NONE &&
2267 ic->ic_nonerpsta == 1 &&
2268 (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0) {
2269 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
2270 "%s: enable use of protection\n", __func__);
2271 ic->ic_flags |= IEEE80211_F_USEPROT;
2272 ieee80211_notify_erp_locked(ic);
2275 ni->ni_flags |= IEEE80211_NODE_ERP;
2279 ieee80211_node_join(struct ieee80211_node *ni, int resp)
2281 struct ieee80211com *ic = ni->ni_ic;
2282 struct ieee80211vap *vap = ni->ni_vap;
2285 if (ni->ni_associd == 0) {
2288 KASSERT(vap->iv_aid_bitmap != NULL, ("no aid bitmap"));
2290 * It would be good to search the bitmap
2291 * more efficiently, but this will do for now.
2293 for (aid = 1; aid < vap->iv_max_aid; aid++) {
2294 if (!IEEE80211_AID_ISSET(vap, aid))
2297 if (aid >= vap->iv_max_aid) {
2298 IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_TOOMANY);
2299 ieee80211_node_leave(ni);
2302 ni->ni_associd = aid | 0xc000;
2303 ni->ni_jointime = time_second;
2305 IEEE80211_AID_SET(vap, ni->ni_associd);
2306 vap->iv_sta_assoc++;
2309 if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan))
2310 ieee80211_ht_node_join(ni);
2311 if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2312 IEEE80211_IS_CHAN_FULL(ic->ic_bsschan))
2313 ieee80211_node_join_11g(ni);
2314 IEEE80211_UNLOCK(ic);
2320 IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, ni,
2321 "station associated at aid %d: %s preamble, %s slot time%s%s%s%s%s%s%s%s",
2322 IEEE80211_NODE_AID(ni),
2323 ic->ic_flags & IEEE80211_F_SHPREAMBLE ? "short" : "long",
2324 ic->ic_flags & IEEE80211_F_SHSLOT ? "short" : "long",
2325 ic->ic_flags & IEEE80211_F_USEPROT ? ", protection" : "",
2326 ni->ni_flags & IEEE80211_NODE_QOS ? ", QoS" : "",
2327 ni->ni_flags & IEEE80211_NODE_HT ?
2328 (ni->ni_chw == 40 ? ", HT40" : ", HT20") : "",
2329 ni->ni_flags & IEEE80211_NODE_AMPDU ? " (+AMPDU)" : "",
2330 ni->ni_flags & IEEE80211_NODE_MIMO_RTS ? " (+SMPS-DYN)" :
2331 ni->ni_flags & IEEE80211_NODE_MIMO_PS ? " (+SMPS)" : "",
2332 ni->ni_flags & IEEE80211_NODE_RIFS ? " (+RIFS)" : "",
2333 IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF) ?
2334 ", fast-frames" : "",
2335 IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_TURBOP) ?
2339 ieee80211_node_setuptxparms(ni);
2340 /* give driver a chance to setup state like ni_txrate */
2341 if (ic->ic_newassoc != NULL)
2342 ic->ic_newassoc(ni, newassoc);
2343 IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_SUCCESS);
2344 /* tell the authenticator about new station */
2345 if (vap->iv_auth->ia_node_join != NULL)
2346 vap->iv_auth->ia_node_join(ni);
2347 ieee80211_notify_node_join(ni,
2348 resp == IEEE80211_FC0_SUBTYPE_ASSOC_RESP);
2352 disable_protection(struct ieee80211com *ic)
2354 KASSERT(ic->ic_nonerpsta == 0 &&
2355 (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0,
2356 ("%d non ERP stations, flags 0x%x", ic->ic_nonerpsta,
2359 ic->ic_flags &= ~IEEE80211_F_USEPROT;
2360 /* XXX verify mode? */
2361 if (ic->ic_caps & IEEE80211_C_SHPREAMBLE) {
2362 ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
2363 ic->ic_flags &= ~IEEE80211_F_USEBARKER;
2365 ieee80211_notify_erp_locked(ic);
2369 * Handle a station leaving an 11g network.
2372 ieee80211_node_leave_11g(struct ieee80211_node *ni)
2374 struct ieee80211com *ic = ni->ni_ic;
2376 IEEE80211_LOCK_ASSERT(ic);
2378 KASSERT(IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan),
2379 ("not in 11g, bss %u:0x%x", ic->ic_bsschan->ic_freq,
2380 ic->ic_bsschan->ic_flags));
2383 * If a long slot station do the slot time bookkeeping.
2385 if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) {
2386 KASSERT(ic->ic_longslotsta > 0,
2387 ("bogus long slot station count %d", ic->ic_longslotsta));
2388 ic->ic_longslotsta--;
2389 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2390 "long slot time station leaves, count now %d",
2391 ic->ic_longslotsta);
2392 if (ic->ic_longslotsta == 0) {
2394 * Re-enable use of short slot time if supported
2395 * and not operating in IBSS mode (per spec).
2397 if ((ic->ic_caps & IEEE80211_C_SHSLOT) &&
2398 ic->ic_opmode != IEEE80211_M_IBSS) {
2399 IEEE80211_DPRINTF(ni->ni_vap,
2400 IEEE80211_MSG_ASSOC,
2401 "%s: re-enable use of short slot time\n",
2403 ieee80211_set_shortslottime(ic, 1);
2408 * If a non-ERP station do the protection-related bookkeeping.
2410 if ((ni->ni_flags & IEEE80211_NODE_ERP) == 0) {
2411 KASSERT(ic->ic_nonerpsta > 0,
2412 ("bogus non-ERP station count %d", ic->ic_nonerpsta));
2414 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ASSOC, ni,
2415 "non-ERP station leaves, count now %d%s", ic->ic_nonerpsta,
2416 (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) ?
2417 " (non-ERP sta present)" : "");
2418 if (ic->ic_nonerpsta == 0 &&
2419 (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) == 0) {
2420 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_ASSOC,
2421 "%s: disable use of protection\n", __func__);
2422 disable_protection(ic);
2428 * Time out presence of an overlapping bss with non-ERP
2429 * stations. When operating in hostap mode we listen for
2430 * beacons from other stations and if we identify a non-ERP
2431 * station is present we enable protection. To identify
2432 * when all non-ERP stations are gone we time out this
2436 ieee80211_erp_timeout(struct ieee80211com *ic)
2439 IEEE80211_LOCK_ASSERT(ic);
2441 if ((ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR) &&
2442 time_after(ticks, ic->ic_lastnonerp + IEEE80211_NONERP_PRESENT_AGE)) {
2444 IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
2445 "%s", "age out non-ERP sta present on channel");
2447 ic->ic_flags_ext &= ~IEEE80211_FEXT_NONERP_PR;
2448 if (ic->ic_nonerpsta == 0)
2449 disable_protection(ic);
2454 * Handle bookkeeping for station deauthentication/disassociation
2455 * when operating as an ap.
2458 ieee80211_node_leave(struct ieee80211_node *ni)
2460 struct ieee80211com *ic = ni->ni_ic;
2461 struct ieee80211vap *vap = ni->ni_vap;
2462 struct ieee80211_node_table *nt = ni->ni_table;
2464 IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, ni,
2465 "station with aid %d leaves", IEEE80211_NODE_AID(ni));
2467 KASSERT(vap->iv_opmode != IEEE80211_M_STA,
2468 ("unexpected operating mode %u", vap->iv_opmode));
2470 * If node wasn't previously associated all
2471 * we need to do is reclaim the reference.
2473 /* XXX ibss mode bypasses 11g and notification */
2474 if (ni->ni_associd == 0)
2477 * Tell the authenticator the station is leaving.
2478 * Note that we must do this before yanking the
2479 * association id as the authenticator uses the
2480 * associd to locate it's state block.
2482 if (vap->iv_auth->ia_node_leave != NULL)
2483 vap->iv_auth->ia_node_leave(ni);
2486 IEEE80211_AID_CLR(vap, ni->ni_associd);
2488 vap->iv_sta_assoc--;
2491 if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan))
2492 ieee80211_ht_node_leave(ni);
2493 if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2494 IEEE80211_IS_CHAN_FULL(ic->ic_bsschan))
2495 ieee80211_node_leave_11g(ni);
2496 IEEE80211_UNLOCK(ic);
2498 * Cleanup station state. In particular clear various
2499 * state that might otherwise be reused if the node
2500 * is reused before the reference count goes to zero
2501 * (and memory is reclaimed).
2503 ieee80211_sta_leave(ni);
2506 * Remove the node from any table it's recorded in and
2507 * drop the caller's reference. Removal from the table
2508 * is important to insure the node is not reprocessed
2512 IEEE80211_NODE_LOCK(nt);
2513 node_reclaim(nt, ni);
2514 IEEE80211_NODE_UNLOCK(nt);
2516 ieee80211_free_node(ni);
2520 struct ieee80211vap *vap;
2522 uint32_t rssi_total;
2526 get_hostap_rssi(void *arg, struct ieee80211_node *ni)
2528 struct rssiinfo *info = arg;
2529 struct ieee80211vap *vap = ni->ni_vap;
2532 if (info->vap != vap)
2534 /* only associated stations */
2535 if (ni->ni_associd == 0)
2537 rssi = vap->iv_ic->ic_node_getrssi(ni);
2539 info->rssi_samples++;
2540 info->rssi_total += rssi;
2545 get_adhoc_rssi(void *arg, struct ieee80211_node *ni)
2547 struct rssiinfo *info = arg;
2548 struct ieee80211vap *vap = ni->ni_vap;
2551 if (info->vap != vap)
2553 /* only neighbors */
2554 /* XXX check bssid */
2555 if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
2557 rssi = vap->iv_ic->ic_node_getrssi(ni);
2559 info->rssi_samples++;
2560 info->rssi_total += rssi;
2564 #ifdef IEEE80211_SUPPORT_MESH
2566 get_mesh_rssi(void *arg, struct ieee80211_node *ni)
2568 struct rssiinfo *info = arg;
2569 struct ieee80211vap *vap = ni->ni_vap;
2572 if (info->vap != vap)
2574 /* only neighbors that peered successfully */
2575 if (ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED)
2577 rssi = vap->iv_ic->ic_node_getrssi(ni);
2579 info->rssi_samples++;
2580 info->rssi_total += rssi;
2583 #endif /* IEEE80211_SUPPORT_MESH */
2586 ieee80211_getrssi(struct ieee80211vap *vap)
2588 #define NZ(x) ((x) == 0 ? 1 : (x))
2589 struct ieee80211com *ic = vap->iv_ic;
2590 struct rssiinfo info;
2592 info.rssi_total = 0;
2593 info.rssi_samples = 0;
2595 switch (vap->iv_opmode) {
2596 case IEEE80211_M_IBSS: /* average of all ibss neighbors */
2597 case IEEE80211_M_AHDEMO: /* average of all neighbors */
2598 ieee80211_iterate_nodes(&ic->ic_sta, get_adhoc_rssi, &info);
2600 case IEEE80211_M_HOSTAP: /* average of all associated stations */
2601 ieee80211_iterate_nodes(&ic->ic_sta, get_hostap_rssi, &info);
2603 #ifdef IEEE80211_SUPPORT_MESH
2604 case IEEE80211_M_MBSS: /* average of all mesh neighbors */
2605 ieee80211_iterate_nodes(&ic->ic_sta, get_mesh_rssi, &info);
2608 case IEEE80211_M_MONITOR: /* XXX */
2609 case IEEE80211_M_STA: /* use stats from associated ap */
2611 if (vap->iv_bss != NULL)
2612 info.rssi_total = ic->ic_node_getrssi(vap->iv_bss);
2613 info.rssi_samples = 1;
2616 return info.rssi_total / NZ(info.rssi_samples);
2621 ieee80211_getsignal(struct ieee80211vap *vap, int8_t *rssi, int8_t *noise)
2624 if (vap->iv_bss == NULL) /* NB: shouldn't happen */
2626 vap->iv_ic->ic_node_getsignal(vap->iv_bss, rssi, noise);
2627 /* for non-station mode return avg'd rssi accounting */
2628 if (vap->iv_opmode != IEEE80211_M_STA)
2629 *rssi = ieee80211_getrssi(vap);