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