ieee80211_node.c revision 127766
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 127766 2004-04-02 22:56:09Z 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	IEEE80211_NODE_LOCK_INIT(ic, ifp->if_xname);
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	struct ieee80211_node *ni;
103
104	ni = (*ic->ic_node_alloc)(ic);
105	KASSERT(ni != NULL, ("unable to setup inital BSS node"));
106	ni->ni_chan = IEEE80211_CHAN_ANYC;
107	ic->ic_bss = ni;
108	ic->ic_txpower = IEEE80211_TXPOWER_MAX;
109}
110
111void
112ieee80211_node_detach(struct ifnet *ifp)
113{
114	struct ieee80211com *ic = (void *)ifp;
115
116	if (ic->ic_bss != NULL)
117		(*ic->ic_node_free)(ic, ic->ic_bss);
118	ieee80211_free_allnodes(ic);
119	IEEE80211_NODE_LOCK_DESTROY(ic);
120}
121
122/*
123 * AP scanning support.
124 */
125
126/*
127 * Initialize the active channel set based on the set
128 * of available channels and the current PHY mode.
129 */
130static void
131ieee80211_reset_scan(struct ifnet *ifp)
132{
133	struct ieee80211com *ic = (void *)ifp;
134
135	memcpy(ic->ic_chan_scan, ic->ic_chan_active,
136		sizeof(ic->ic_chan_active));
137	/* NB: hack, setup so next_scan starts with the first channel */
138	if (ic->ic_bss->ni_chan == IEEE80211_CHAN_ANYC)
139		ic->ic_bss->ni_chan = &ic->ic_channels[IEEE80211_CHAN_MAX];
140}
141
142/*
143 * Begin an active scan.
144 */
145void
146ieee80211_begin_scan(struct ifnet *ifp)
147{
148	struct ieee80211com *ic = (void *)ifp;
149
150	/*
151	 * In all but hostap mode scanning starts off in
152	 * an active mode before switching to passive.
153	 */
154	if (ic->ic_opmode != IEEE80211_M_HOSTAP) {
155		ic->ic_flags |= IEEE80211_F_ASCAN;
156		ic->ic_stats.is_scan_active++;
157	} else
158		ic->ic_stats.is_scan_passive++;
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 */
180void
181ieee80211_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
212void
213ieee80211_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 */
247void
248ieee80211_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, ic->ic_des_esslen) != 0))
344			fail |= 0x10;
345		if ((ic->ic_flags & IEEE80211_F_DESBSSID) &&
346		    !IEEE80211_ADDR_EQ(ic->ic_des_bssid, ni->ni_bssid))
347			fail |= 0x20;
348		if (ifp->if_flags & IFF_DEBUG) {
349			printf(" %c %s", fail ? '-' : '+',
350			    ether_sprintf(ni->ni_macaddr));
351			printf(" %s%c", ether_sprintf(ni->ni_bssid),
352			    fail & 0x20 ? '!' : ' ');
353			printf(" %3d%c", ieee80211_chan2ieee(ic, ni->ni_chan),
354				fail & 0x01 ? '!' : ' ');
355			printf(" %+4d", ni->ni_rssi);
356			printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2,
357			    fail & 0x08 ? '!' : ' ');
358			printf(" %4s%c",
359			    (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
360			    (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
361			    "????",
362			    fail & 0x02 ? '!' : ' ');
363			printf(" %3s%c ",
364			    (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ?
365			    "wep" : "no",
366			    fail & 0x04 ? '!' : ' ');
367			ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
368			printf("%s\n", fail & 0x10 ? "!" : "");
369		}
370		if (!fail) {
371			if (selbs == NULL)
372				selbs = ni;
373			else if (ni->ni_rssi > selbs->ni_rssi) {
374				ieee80211_unref_node(&selbs);
375				selbs = ni;
376			} else
377				ieee80211_unref_node(&ni);
378		} else {
379			ieee80211_unref_node(&ni);
380		}
381	}
382	if (selbs == NULL)
383		goto notfound;
384	(*ic->ic_node_copy)(ic, ic->ic_bss, selbs);
385	if (ic->ic_opmode == IEEE80211_M_IBSS) {
386		ieee80211_fix_rate(ic, ic->ic_bss, IEEE80211_F_DOFRATE |
387		    IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
388		if (ic->ic_bss->ni_rates.rs_nrates == 0) {
389			selbs->ni_fails++;
390			ieee80211_unref_node(&selbs);
391			goto notfound;
392		}
393		ieee80211_unref_node(&selbs);
394		ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
395	} else {
396		ieee80211_unref_node(&selbs);
397		ieee80211_new_state(ic, IEEE80211_S_AUTH, -1);
398	}
399}
400
401static struct ieee80211_node *
402ieee80211_node_alloc(struct ieee80211com *ic)
403{
404	return malloc(sizeof(struct ieee80211_node), M_80211_NODE,
405		M_NOWAIT | M_ZERO);
406}
407
408static void
409ieee80211_node_free(struct ieee80211com *ic, struct ieee80211_node *ni)
410{
411	free(ni, M_80211_NODE);
412}
413
414static void
415ieee80211_node_copy(struct ieee80211com *ic,
416	struct ieee80211_node *dst, const struct ieee80211_node *src)
417{
418	*dst = *src;
419}
420
421static u_int8_t
422ieee80211_node_getrssi(struct ieee80211com *ic, struct ieee80211_node *ni)
423{
424	return ni->ni_rssi;
425}
426
427static void
428ieee80211_setup_node(struct ieee80211com *ic,
429	struct ieee80211_node *ni, u_int8_t *macaddr)
430{
431	int hash;
432
433	IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
434	hash = IEEE80211_NODE_HASH(macaddr);
435	ni->ni_refcnt = 1;		/* mark referenced */
436	IEEE80211_NODE_LOCK(ic);
437	TAILQ_INSERT_TAIL(&ic->ic_node, ni, ni_list);
438	LIST_INSERT_HEAD(&ic->ic_hash[hash], ni, ni_hash);
439	/*
440	 * Note we don't enable the inactive timer when acting
441	 * as a station.  Nodes created in this mode represent
442	 * AP's identified while scanning.  If we time them out
443	 * then several things happen: we can't return the data
444	 * to users to show the list of AP's we encountered, and
445	 * more importantly, we'll incorrectly deauthenticate
446	 * ourself because the inactivity timer will kick us off.
447	 */
448	if (ic->ic_opmode != IEEE80211_M_STA)
449		ic->ic_inact_timer = IEEE80211_INACT_WAIT;
450	IEEE80211_NODE_UNLOCK(ic);
451}
452
453struct ieee80211_node *
454ieee80211_alloc_node(struct ieee80211com *ic, u_int8_t *macaddr)
455{
456	struct ieee80211_node *ni = (*ic->ic_node_alloc)(ic);
457	if (ni != NULL)
458		ieee80211_setup_node(ic, ni, macaddr);
459	return ni;
460}
461
462struct ieee80211_node *
463ieee80211_dup_bss(struct ieee80211com *ic, u_int8_t *macaddr)
464{
465	struct ieee80211_node *ni = (*ic->ic_node_alloc)(ic);
466	if (ni != NULL) {
467		memcpy(ni, ic->ic_bss, sizeof(struct ieee80211_node));
468		ieee80211_setup_node(ic, ni, macaddr);
469	}
470	return ni;
471}
472
473struct ieee80211_node *
474ieee80211_find_node(struct ieee80211com *ic, u_int8_t *macaddr)
475{
476	struct ieee80211_node *ni;
477	int hash;
478
479	hash = IEEE80211_NODE_HASH(macaddr);
480	IEEE80211_NODE_LOCK(ic);
481	LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) {
482		if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
483			atomic_add_int(&ni->ni_refcnt, 1); /* mark referenced */
484			break;
485		}
486	}
487	IEEE80211_NODE_UNLOCK(ic);
488	return ni;
489}
490
491/*
492 * Like find but search based on the channel too.
493 */
494struct ieee80211_node *
495ieee80211_lookup_node(struct ieee80211com *ic,
496	u_int8_t *macaddr, struct ieee80211_channel *chan)
497{
498	struct ieee80211_node *ni;
499	int hash;
500
501	hash = IEEE80211_NODE_HASH(macaddr);
502	IEEE80211_NODE_LOCK(ic);
503	LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) {
504		if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_chan == chan) {
505			atomic_add_int(&ni->ni_refcnt, 1);/* mark referenced */
506			break;
507		}
508	}
509	IEEE80211_NODE_UNLOCK(ic);
510	return ni;
511}
512
513static void
514_ieee80211_free_node(struct ieee80211com *ic, struct ieee80211_node *ni)
515{
516	KASSERT(ni != ic->ic_bss, ("freeing bss node"));
517
518	TAILQ_REMOVE(&ic->ic_node, ni, ni_list);
519	LIST_REMOVE(ni, ni_hash);
520	if (TAILQ_EMPTY(&ic->ic_node))
521		ic->ic_inact_timer = 0;
522	(*ic->ic_node_free)(ic, ni);
523}
524
525void
526ieee80211_free_node(struct ieee80211com *ic, struct ieee80211_node *ni)
527{
528	KASSERT(ni != ic->ic_bss, ("freeing ic_bss"));
529
530	/* XXX need equivalent of atomic_dec_and_test */
531	atomic_subtract_int(&ni->ni_refcnt, 1);
532	if (atomic_cmpset_int(&ni->ni_refcnt, 0, 1)) {
533		IEEE80211_NODE_LOCK(ic);
534		_ieee80211_free_node(ic, ni);
535		IEEE80211_NODE_UNLOCK(ic);
536	}
537}
538
539void
540ieee80211_free_allnodes(struct ieee80211com *ic)
541{
542	struct ieee80211_node *ni;
543
544	IEEE80211_NODE_LOCK(ic);
545	while ((ni = TAILQ_FIRST(&ic->ic_node)) != NULL)
546		_ieee80211_free_node(ic, ni);
547	IEEE80211_NODE_UNLOCK(ic);
548}
549
550/*
551 * Timeout inactive nodes.  Note that we cannot hold the node
552 * lock while sending a frame as this would lead to a LOR.
553 * Instead we use a generation number to mark nodes that we've
554 * scanned and drop the lock and restart a scan if we have to
555 * time out a node.  Since we are single-threaded by virtue of
556 * controlling the inactivity timer we can be sure this will
557 * process each node only once.
558 */
559void
560ieee80211_timeout_nodes(struct ieee80211com *ic)
561{
562	struct ieee80211_node *ni;
563	u_int gen = ic->ic_scangen++;		/* NB: ok 'cuz single-threaded*/
564
565restart:
566	IEEE80211_NODE_LOCK(ic);
567	TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
568		if (ni->ni_scangen == gen)	/* previously handled */
569			continue;
570		ni->ni_scangen = gen;
571		if (++ni->ni_inact > IEEE80211_INACT_MAX) {
572			IEEE80211_DPRINTF(("station %s timed out "
573			    "due to inactivity (%u secs)\n",
574			    ether_sprintf(ni->ni_macaddr),
575			    ni->ni_inact));
576			/*
577			 * Send a deauthenticate frame.
578			 *
579			 * Drop the node lock before sending the
580			 * deauthentication frame in case the driver takes
581			 * a lock, as this will result in a LOR between the
582			 * node lock and the driver lock.
583			 */
584			IEEE80211_NODE_UNLOCK(ic);
585			IEEE80211_SEND_MGMT(ic, ni,
586			    IEEE80211_FC0_SUBTYPE_DEAUTH,
587			    IEEE80211_REASON_AUTH_EXPIRE);
588			ieee80211_free_node(ic, ni);
589			ic->ic_stats.is_node_timeout++;
590			goto restart;
591		}
592	}
593	if (!TAILQ_EMPTY(&ic->ic_node))
594		ic->ic_inact_timer = IEEE80211_INACT_WAIT;
595	IEEE80211_NODE_UNLOCK(ic);
596}
597
598void
599ieee80211_iterate_nodes(struct ieee80211com *ic, ieee80211_iter_func *f, void *arg)
600{
601	struct ieee80211_node *ni;
602
603	IEEE80211_NODE_LOCK(ic);
604	TAILQ_FOREACH(ni, &ic->ic_node, ni_list)
605		(*f)(arg, ni);
606	IEEE80211_NODE_UNLOCK(ic);
607}
608