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