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