Home | History | Annotate | Line # | Download | only in net80211
ieee80211_node.c revision 1.2
      1 /*-
      2  * Copyright (c) 2001 Atsushi Onoe
      3  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * Alternatively, this software may be distributed under the terms of the
     18  * GNU General Public License ("GPL") version 2 as published by the Free
     19  * Software Foundation.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_node.c,v 1.6 2003/08/19 22:17:03 sam Exp $");
     35 
     36 #include "opt_inet.h"
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/mbuf.h>
     41 #include <sys/malloc.h>
     42 #include <sys/kernel.h>
     43 #include <sys/socket.h>
     44 #include <sys/sockio.h>
     45 #include <sys/endian.h>
     46 #include <sys/errno.h>
     47 #include <sys/bus.h>
     48 #include <sys/proc.h>
     49 #include <sys/sysctl.h>
     50 
     51 #ifdef __FreeBSD__
     52 #include <machine/atomic.h>
     53 #endif
     54 
     55 #include <net/if.h>
     56 #include <net/if_dl.h>
     57 #include <net/if_media.h>
     58 #include <net/if_arp.h>
     59 #ifdef __FreeBSD__
     60 #include <net/ethernet.h>
     61 #endif
     62 #include <net/if_llc.h>
     63 
     64 #include <net80211/ieee80211_var.h>
     65 
     66 #include <net/bpf.h>
     67 
     68 #ifdef INET
     69 #include <netinet/in.h>
     70 #include <netinet/if_ether.h>
     71 #endif
     72 
     73 static struct ieee80211_node *ieee80211_node_alloc(struct ieee80211com *);
     74 static void ieee80211_node_free(struct ieee80211com *, struct ieee80211_node *);
     75 static void ieee80211_node_copy(struct ieee80211com *,
     76 		struct ieee80211_node *, const struct ieee80211_node *);
     77 static void ieee80211_setup_node(struct ieee80211com *ic,
     78 		struct ieee80211_node *ni, u_int8_t *macaddr);
     79 static void _ieee80211_free_node(struct ieee80211com *,
     80 		struct ieee80211_node *);
     81 
     82 void
     83 ieee80211_node_attach(struct ifnet *ifp)
     84 {
     85 	struct ieee80211com *ic = (void *)ifp;
     86 
     87 #ifdef __FreeBSD__
     88 	/* XXX need unit */
     89 	mtx_init(&ic->ic_nodelock, ifp->if_name, "802.11 node table", MTX_DEF);
     90 #endif
     91 	TAILQ_INIT(&ic->ic_node);
     92 	ic->ic_node_alloc = ieee80211_node_alloc;
     93 	ic->ic_node_free = ieee80211_node_free;
     94 	ic->ic_node_copy = ieee80211_node_copy;
     95 }
     96 
     97 void
     98 ieee80211_node_lateattach(struct ifnet *ifp)
     99 {
    100 	struct ieee80211com *ic = (void *)ifp;
    101 
    102 	ic->ic_bss = (*ic->ic_node_alloc)(ic);
    103 	KASSERT(ic->ic_bss != NULL, ("unable to setup inital BSS node"));
    104 	ic->ic_bss->ni_chan = IEEE80211_CHAN_ANYC;
    105 }
    106 
    107 void
    108 ieee80211_node_detach(struct ifnet *ifp)
    109 {
    110 	struct ieee80211com *ic = (void *)ifp;
    111 
    112 	if (ic->ic_bss != NULL)
    113 		(*ic->ic_node_free)(ic, ic->ic_bss);
    114 	ieee80211_free_allnodes(ic);
    115 #ifdef __FreeBSD__
    116 	mtx_destroy(&ic->ic_nodelock);
    117 #endif
    118 }
    119 
    120 /*
    121  * AP scanning support.
    122  */
    123 
    124 /*
    125  * Initialize the active channel set based on the set
    126  * of available channels and the current PHY mode.
    127  */
    128 static void
    129 ieee80211_reset_scan(struct ifnet *ifp)
    130 {
    131 	struct ieee80211com *ic = (void *)ifp;
    132 
    133 	memcpy(ic->ic_chan_scan, ic->ic_chan_active,
    134 		sizeof(ic->ic_chan_active));
    135 	/* NB: hack, setup so next_scan starts with the first channel */
    136 	if (ic->ic_bss->ni_chan == IEEE80211_CHAN_ANYC)
    137 		ic->ic_bss->ni_chan = &ic->ic_channels[IEEE80211_CHAN_MAX];
    138 }
    139 
    140 /*
    141  * Begin an active scan.
    142  */
    143 void
    144 ieee80211_begin_scan(struct ifnet *ifp)
    145 {
    146 	struct ieee80211com *ic = (void *)ifp;
    147 
    148 	/*
    149 	 * In all but hostap mode scanning starts off in
    150 	 * an active mode before switching to passive.
    151 	 */
    152 	if (ic->ic_opmode != IEEE80211_M_HOSTAP)
    153 		ic->ic_flags |= IEEE80211_F_ASCAN;
    154 	if (ifp->if_flags & IFF_DEBUG)
    155 		if_printf(ifp, "begin %s scan\n",
    156 			(ic->ic_flags & IEEE80211_F_ASCAN) ?
    157 				"active" : "passive");
    158 	/*
    159 	 * Clear scan state and flush any previously seen
    160 	 * AP's.  Note that the latter assumes we don't act
    161 	 * as both an AP and a station, otherwise we'll
    162 	 * potentially flush state of stations associated
    163 	 * with us.
    164 	 */
    165 	ieee80211_reset_scan(ifp);
    166 	ieee80211_free_allnodes(ic);
    167 
    168 	/* Scan the next channel. */
    169 	ieee80211_next_scan(ifp);
    170 }
    171 
    172 /*
    173  * Switch to the next channel marked for scanning.
    174  */
    175 void
    176 ieee80211_next_scan(struct ifnet *ifp)
    177 {
    178 	struct ieee80211com *ic = (void *)ifp;
    179 	struct ieee80211_channel *chan;
    180 
    181 	chan = ic->ic_bss->ni_chan;
    182 	for (;;) {
    183 		if (++chan > &ic->ic_channels[IEEE80211_CHAN_MAX])
    184 			chan = &ic->ic_channels[0];
    185 		if (isset(ic->ic_chan_scan, ieee80211_chan2ieee(ic, chan))) {
    186 			/*
    187 			 * Honor channels marked passive-only
    188 			 * during an active scan.
    189 			 */
    190 			if ((ic->ic_flags & IEEE80211_F_ASCAN) == 0 ||
    191 			    (chan->ic_flags & IEEE80211_CHAN_PASSIVE) == 0)
    192 				break;
    193 		}
    194 		if (chan == ic->ic_bss->ni_chan) {
    195 			ieee80211_end_scan(ifp);
    196 			return;
    197 		}
    198 	}
    199 	clrbit(ic->ic_chan_scan, ieee80211_chan2ieee(ic, chan));
    200 	IEEE80211_DPRINTF(("ieee80211_next_scan: chan %d->%d\n",
    201 	    ieee80211_chan2ieee(ic, ic->ic_bss->ni_chan),
    202 	    ieee80211_chan2ieee(ic, chan)));
    203 	ic->ic_bss->ni_chan = chan;
    204 	ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
    205 }
    206 
    207 void
    208 ieee80211_create_ibss(struct ieee80211com* ic, struct ieee80211_channel *chan)
    209 {
    210 	struct ieee80211_node *ni;
    211 	struct ifnet *ifp = &ic->ic_if;
    212 
    213 	ni = ic->ic_bss;
    214 	if (ifp->if_flags & IFF_DEBUG)
    215 		if_printf(ifp, "creating ibss\n");
    216 	ic->ic_flags |= IEEE80211_F_SIBSS;
    217 	ni->ni_chan = chan;
    218 	ni->ni_rates = ic->ic_sup_rates[ieee80211_chan2mode(ic, ni->ni_chan)];
    219 	IEEE80211_ADDR_COPY(ni->ni_macaddr, ic->ic_myaddr);
    220 	IEEE80211_ADDR_COPY(ni->ni_bssid, ic->ic_myaddr);
    221 	if (ic->ic_opmode == IEEE80211_M_IBSS)
    222 		ni->ni_bssid[0] |= 0x02;	/* local bit for IBSS */
    223 	ni->ni_esslen = ic->ic_des_esslen;
    224 	memcpy(ni->ni_essid, ic->ic_des_essid, ni->ni_esslen);
    225 	ni->ni_rssi = 0;
    226 	ni->ni_rstamp = 0;
    227 	memset(ni->ni_tstamp, 0, sizeof(ni->ni_tstamp));
    228 	ni->ni_intval = ic->ic_lintval;
    229 	ni->ni_capinfo = IEEE80211_CAPINFO_IBSS;
    230 	if (ic->ic_flags & IEEE80211_F_WEPON)
    231 		ni->ni_capinfo |= IEEE80211_CAPINFO_PRIVACY;
    232 	if (ic->ic_phytype == IEEE80211_T_FH) {
    233 		ni->ni_fhdwell = 200;	/* XXX */
    234 		ni->ni_fhindex = 1;
    235 	}
    236 	ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
    237 }
    238 
    239 /*
    240  * Complete a scan of potential channels.
    241  */
    242 void
    243 ieee80211_end_scan(struct ifnet *ifp)
    244 {
    245 	struct ieee80211com *ic = (void *)ifp;
    246 	struct ieee80211_node *ni, *nextbs, *selbs;
    247 	u_int8_t rate;
    248 	int i, fail;
    249 
    250 	ic->ic_flags &= ~IEEE80211_F_ASCAN;
    251 	ni = TAILQ_FIRST(&ic->ic_node);
    252 
    253 	if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
    254 		/* XXX off stack? */
    255 		u_char occupied[roundup(IEEE80211_CHAN_MAX, NBBY)];
    256 		/*
    257 		 * The passive scan to look for existing AP's completed,
    258 		 * select a channel to camp on.  Identify the channels
    259 		 * that already have one or more AP's and try to locate
    260 		 * an unnoccupied one.  If that fails, pick a random
    261 		 * channel from the active set.
    262 		 */
    263 		for (; ni != NULL; ni = nextbs) {
    264 			ieee80211_ref_node(ni);
    265 			nextbs = TAILQ_NEXT(ni, ni_list);
    266 			setbit(occupied, ieee80211_chan2ieee(ic, ni->ni_chan));
    267 			ieee80211_free_node(ic, ni);
    268 		}
    269 		for (i = 0; i < IEEE80211_CHAN_MAX; i++)
    270 			if (isset(ic->ic_chan_active, i) && isclr(occupied, i))
    271 				break;
    272 		if (i == IEEE80211_CHAN_MAX) {
    273 			fail = arc4random() & 3;	/* random 0-3 */
    274 			for (i = 0; i < IEEE80211_CHAN_MAX; i++)
    275 				if (isset(ic->ic_chan_active, i) && fail-- == 0)
    276 					break;
    277 		}
    278 		ieee80211_create_ibss(ic, &ic->ic_channels[i]);
    279 		return;
    280 	}
    281 	if (ni == NULL) {
    282 		IEEE80211_DPRINTF(("%s: no scan candidate\n", __func__));
    283   notfound:
    284 		if (ic->ic_opmode == IEEE80211_M_IBSS &&
    285 		    (ic->ic_flags & IEEE80211_F_IBSSON) &&
    286 		    ic->ic_des_esslen != 0) {
    287 			ieee80211_create_ibss(ic, ic->ic_ibss_chan);
    288 			return;
    289 		}
    290 		/*
    291 		 * Reset the list of channels to scan and start again.
    292 		 */
    293 		ieee80211_reset_scan(ifp);
    294 		ieee80211_next_scan(ifp);
    295 		return;
    296 	}
    297 	selbs = NULL;
    298 	if (ifp->if_flags & IFF_DEBUG)
    299 		if_printf(ifp, "\tmacaddr          bssid         chan  rssi rate flag  wep  essid\n");
    300 	for (; ni != NULL; ni = nextbs) {
    301 		ieee80211_ref_node(ni);
    302 		nextbs = TAILQ_NEXT(ni, ni_list);
    303 		if (ni->ni_fails) {
    304 			/*
    305 			 * The configuration of the access points may change
    306 			 * during my scan.  So delete the entry for the AP
    307 			 * and retry to associate if there is another beacon.
    308 			 */
    309 			if (ni->ni_fails++ > 2)
    310 				ieee80211_free_node(ic, ni);
    311 			continue;
    312 		}
    313 		fail = 0;
    314 		if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
    315 			fail |= 0x01;
    316 		if (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
    317 		    ni->ni_chan != ic->ic_des_chan)
    318 			fail |= 0x01;
    319 		if (ic->ic_opmode == IEEE80211_M_IBSS) {
    320 			if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
    321 				fail |= 0x02;
    322 		} else {
    323 			if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
    324 				fail |= 0x02;
    325 		}
    326 		if (ic->ic_flags & IEEE80211_F_WEPON) {
    327 			if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
    328 				fail |= 0x04;
    329 		} else {
    330 			if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
    331 				fail |= 0x04;
    332 		}
    333 		rate = ieee80211_fix_rate(ic, ni, IEEE80211_F_DONEGO);
    334 		if (rate & IEEE80211_RATE_BASIC)
    335 			fail |= 0x08;
    336 		if (ic->ic_des_esslen != 0 &&
    337 		    (ni->ni_esslen != ic->ic_des_esslen ||
    338 		     memcmp(ni->ni_essid, ic->ic_des_essid,
    339 		     ic->ic_des_esslen != 0)))
    340 			fail |= 0x10;
    341 		if ((ic->ic_flags & IEEE80211_F_DESBSSID) &&
    342 		    !IEEE80211_ADDR_EQ(ic->ic_des_bssid, ni->ni_bssid))
    343 			fail |= 0x20;
    344 		if (ifp->if_flags & IFF_DEBUG) {
    345 			printf(" %c %s", fail ? '-' : '+',
    346 			    ether_sprintf(ni->ni_macaddr));
    347 			printf(" %s%c", ether_sprintf(ni->ni_bssid),
    348 			    fail & 0x20 ? '!' : ' ');
    349 			printf(" %3d%c", ieee80211_chan2ieee(ic, ni->ni_chan),
    350 				fail & 0x01 ? '!' : ' ');
    351 			printf(" %+4d", ni->ni_rssi);
    352 			printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2,
    353 			    fail & 0x08 ? '!' : ' ');
    354 			printf(" %4s%c",
    355 			    (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
    356 			    (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
    357 			    "????",
    358 			    fail & 0x02 ? '!' : ' ');
    359 			printf(" %3s%c ",
    360 			    (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ?
    361 			    "wep" : "no",
    362 			    fail & 0x04 ? '!' : ' ');
    363 			ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
    364 			printf("%s\n", fail & 0x10 ? "!" : "");
    365 		}
    366 		if (!fail) {
    367 			if (selbs == NULL)
    368 				selbs = ni;
    369 			else if (ni->ni_rssi > selbs->ni_rssi) {
    370 				ieee80211_unref_node(&selbs);
    371 				selbs = ni;
    372 			} else
    373 				ieee80211_unref_node(&ni);
    374 		} else {
    375 			ieee80211_unref_node(&ni);
    376 		}
    377 	}
    378 	if (selbs == NULL)
    379 		goto notfound;
    380 	(*ic->ic_node_copy)(ic, ic->ic_bss, selbs);
    381 	if (ic->ic_opmode == IEEE80211_M_IBSS) {
    382 		ieee80211_fix_rate(ic, ic->ic_bss, IEEE80211_F_DOFRATE |
    383 		    IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
    384 		if (ic->ic_bss->ni_rates.rs_nrates == 0) {
    385 			selbs->ni_fails++;
    386 			ieee80211_unref_node(&selbs);
    387 			goto notfound;
    388 		}
    389 		ieee80211_unref_node(&selbs);
    390 		ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
    391 	} else {
    392 		ieee80211_unref_node(&selbs);
    393 		ieee80211_new_state(ic, IEEE80211_S_AUTH, -1);
    394 	}
    395 }
    396 
    397 static struct ieee80211_node *
    398 ieee80211_node_alloc(struct ieee80211com *ic)
    399 {
    400 	return malloc(sizeof(struct ieee80211_node), M_DEVBUF,
    401 		M_NOWAIT | M_ZERO);
    402 }
    403 
    404 static void
    405 ieee80211_node_free(struct ieee80211com *ic, struct ieee80211_node *ni)
    406 {
    407 	free(ni, M_DEVBUF);
    408 }
    409 
    410 static void
    411 ieee80211_node_copy(struct ieee80211com *ic,
    412 	struct ieee80211_node *dst, const struct ieee80211_node *src)
    413 {
    414 	*dst = *src;
    415 }
    416 
    417 static void
    418 ieee80211_setup_node(struct ieee80211com *ic,
    419 	struct ieee80211_node *ni, u_int8_t *macaddr)
    420 {
    421 	int hash;
    422 	ieee80211_node_critsec_decl(s);
    423 
    424 	IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
    425 	hash = IEEE80211_NODE_HASH(macaddr);
    426 	ni->ni_refcnt = 1;		/* mark referenced */
    427 	ieee80211_node_critsec_begin(ic, s);
    428 	TAILQ_INSERT_TAIL(&ic->ic_node, ni, ni_list);
    429 	LIST_INSERT_HEAD(&ic->ic_hash[hash], ni, ni_hash);
    430 	/*
    431 	 * Note we don't enable the inactive timer when acting
    432 	 * as a station.  Nodes created in this mode represent
    433 	 * AP's identified while scanning.  If we time them out
    434 	 * then several things happen: we can't return the data
    435 	 * to users to show the list of AP's we encountered, and
    436 	 * more importantly, we'll incorrectly deauthenticate
    437 	 * ourself because the inactivity timer will kick us off.
    438 	 */
    439 	if (ic->ic_opmode != IEEE80211_M_STA)
    440 		ic->ic_inact_timer = IEEE80211_INACT_WAIT;
    441 	ieee80211_node_critsec_end(ic, s);
    442 }
    443 
    444 struct ieee80211_node *
    445 ieee80211_alloc_node(struct ieee80211com *ic, u_int8_t *macaddr)
    446 {
    447 	struct ieee80211_node *ni = (*ic->ic_node_alloc)(ic);
    448 	if (ni != NULL)
    449 		ieee80211_setup_node(ic, ni, macaddr);
    450 	return ni;
    451 }
    452 
    453 struct ieee80211_node *
    454 ieee80211_dup_bss(struct ieee80211com *ic, u_int8_t *macaddr)
    455 {
    456 	struct ieee80211_node *ni = (*ic->ic_node_alloc)(ic);
    457 	if (ni != NULL) {
    458 		memcpy(ni, ic->ic_bss, sizeof(struct ieee80211_node));
    459 		ieee80211_setup_node(ic, ni, macaddr);
    460 	}
    461 	return ni;
    462 }
    463 
    464 struct ieee80211_node *
    465 ieee80211_find_node(struct ieee80211com *ic, u_int8_t *macaddr)
    466 {
    467 	struct ieee80211_node *ni;
    468 	int hash;
    469 	ieee80211_node_critsec_decl(s);
    470 
    471 	hash = IEEE80211_NODE_HASH(macaddr);
    472 	ieee80211_node_critsec_begin(ic, s);
    473 	LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) {
    474 		if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
    475 			ieee80211_node_incref(ni); /* mark referenced */
    476 			break;
    477 		}
    478 	}
    479 	ieee80211_node_critsec_end(ic, s);
    480 	return ni;
    481 }
    482 
    483 /*
    484  * Like find but search based on the channel too.
    485  */
    486 struct ieee80211_node *
    487 ieee80211_lookup_node(struct ieee80211com *ic,
    488 	u_int8_t *macaddr, struct ieee80211_channel *chan)
    489 {
    490 	struct ieee80211_node *ni;
    491 	int hash;
    492 	ieee80211_node_critsec_decl(s);
    493 
    494 	hash = IEEE80211_NODE_HASH(macaddr);
    495 	ieee80211_node_critsec_begin(ic, s);
    496 	LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) {
    497 		if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_chan == chan) {
    498 			ieee80211_node_incref(ni);/* mark referenced */
    499 			break;
    500 		}
    501 	}
    502 	ieee80211_node_critsec_end(ic, s);
    503 	return ni;
    504 }
    505 
    506 static void
    507 _ieee80211_free_node(struct ieee80211com *ic, struct ieee80211_node *ni)
    508 {
    509 	KASSERT(ni != ic->ic_bss, ("freeing bss node"));
    510 
    511 	TAILQ_REMOVE(&ic->ic_node, ni, ni_list);
    512 	LIST_REMOVE(ni, ni_hash);
    513 	if (TAILQ_EMPTY(&ic->ic_node))
    514 		ic->ic_inact_timer = 0;
    515 	(*ic->ic_node_free)(ic, ni);
    516 }
    517 
    518 void
    519 ieee80211_free_node(struct ieee80211com *ic, struct ieee80211_node *ni)
    520 {
    521 	ieee80211_node_critsec_decl(s);
    522 
    523 	KASSERT(ni != ic->ic_bss, ("freeing ic_bss"));
    524 
    525 	if (ieee80211_node_decref(ni) == 0) {
    526 		ieee80211_node_critsec_begin(ic, s);
    527 		_ieee80211_free_node(ic, ni);
    528 		ieee80211_node_critsec_end(ic, s);
    529 	}
    530 }
    531 
    532 void
    533 ieee80211_free_allnodes(struct ieee80211com *ic)
    534 {
    535 	struct ieee80211_node *ni;
    536 	ieee80211_node_critsec_decl(s);
    537 
    538 	ieee80211_node_critsec_begin(ic, s);
    539 	while ((ni = TAILQ_FIRST(&ic->ic_node)) != NULL)
    540 		_ieee80211_free_node(ic, ni);
    541 	ieee80211_node_critsec_end(ic, s);
    542 }
    543 
    544 void
    545 ieee80211_timeout_nodes(struct ieee80211com *ic)
    546 {
    547 	struct ieee80211_node *ni, *nextbs;
    548 	ieee80211_node_critsec_decl(s);
    549 
    550 	ieee80211_node_critsec_begin(ic, s);
    551 	for (ni = TAILQ_FIRST(&ic->ic_node); ni != NULL;) {
    552 		if (++ni->ni_inact > IEEE80211_INACT_MAX) {
    553 			IEEE80211_DPRINTF(("station %s timed out "
    554 			    "due to inactivity (%u secs)\n",
    555 			    ether_sprintf(ni->ni_macaddr),
    556 			    ni->ni_inact));
    557 			nextbs = TAILQ_NEXT(ni, ni_list);
    558 			/*
    559 			 * Send a deauthenticate frame.
    560 			 */
    561 			IEEE80211_SEND_MGMT(ic, ni,
    562 			    IEEE80211_FC0_SUBTYPE_DEAUTH,
    563 			    IEEE80211_REASON_AUTH_EXPIRE);
    564 			ieee80211_free_node(ic, ni);
    565 			ni = nextbs;
    566 		} else
    567 			ni = TAILQ_NEXT(ni, ni_list);
    568 	}
    569 	if (!TAILQ_EMPTY(&ic->ic_node))
    570 		ic->ic_inact_timer = IEEE80211_INACT_WAIT;
    571 	ieee80211_node_critsec_end(ic, s);
    572 }
    573 
    574 void
    575 ieee80211_iterate_nodes(struct ieee80211com *ic, ieee80211_iter_func *f, void *arg)
    576 {
    577 	struct ieee80211_node *ni;
    578 	ieee80211_node_critsec_decl(s);
    579 
    580 	ieee80211_node_critsec_begin(ic, s);
    581 	TAILQ_FOREACH(ni, &ic->ic_node, ni_list)
    582 		(*f)(arg, ni);
    583 	ieee80211_node_critsec_end(ic, s);
    584 }
    585