ieee80211_node.c revision 127769
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 127769 2004-04-02 23:06:41Z 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 244static int 245ieee80211_match_bss(struct ifnet *ifp, struct ieee80211_node *ni) 246{ 247 struct ieee80211com *ic = (void *)ifp; 248 u_int8_t rate; 249 int fail; 250 251 fail = 0; 252 if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan))) 253 fail |= 0x01; 254 if (ic->ic_des_chan != IEEE80211_CHAN_ANYC && 255 ni->ni_chan != ic->ic_des_chan) 256 fail |= 0x01; 257 if (ic->ic_opmode == IEEE80211_M_IBSS) { 258 if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0) 259 fail |= 0x02; 260 } else { 261 if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0) 262 fail |= 0x02; 263 } 264 if (ic->ic_flags & IEEE80211_F_WEPON) { 265 if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0) 266 fail |= 0x04; 267 } else { 268 /* XXX does this mean privacy is supported or required? */ 269 if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) 270 fail |= 0x04; 271 } 272 rate = ieee80211_fix_rate(ic, ni, IEEE80211_F_DONEGO); 273 if (rate & IEEE80211_RATE_BASIC) 274 fail |= 0x08; 275 if (ic->ic_des_esslen != 0 && 276 (ni->ni_esslen != ic->ic_des_esslen || 277 memcmp(ni->ni_essid, ic->ic_des_essid, ic->ic_des_esslen) != 0)) 278 fail |= 0x10; 279 if ((ic->ic_flags & IEEE80211_F_DESBSSID) && 280 !IEEE80211_ADDR_EQ(ic->ic_des_bssid, ni->ni_bssid)) 281 fail |= 0x20; 282#ifdef IEEE80211_DEBUG 283 if (ifp->if_flags & IFF_DEBUG) { 284 printf(" %c %s", fail ? '-' : '+', 285 ether_sprintf(ni->ni_macaddr)); 286 printf(" %s%c", ether_sprintf(ni->ni_bssid), 287 fail & 0x20 ? '!' : ' '); 288 printf(" %3d%c", ieee80211_chan2ieee(ic, ni->ni_chan), 289 fail & 0x01 ? '!' : ' '); 290 printf(" %+4d", ni->ni_rssi); 291 printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2, 292 fail & 0x08 ? '!' : ' '); 293 printf(" %4s%c", 294 (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" : 295 (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" : 296 "????", 297 fail & 0x02 ? '!' : ' '); 298 printf(" %3s%c ", 299 (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? 300 "wep" : "no", 301 fail & 0x04 ? '!' : ' '); 302 ieee80211_print_essid(ni->ni_essid, ni->ni_esslen); 303 printf("%s\n", fail & 0x10 ? "!" : ""); 304 } 305#endif 306 return fail; 307} 308 309/* 310 * Complete a scan of potential channels. 311 */ 312void 313ieee80211_end_scan(struct ifnet *ifp) 314{ 315 struct ieee80211com *ic = (void *)ifp; 316 struct ieee80211_node *ni, *nextbs, *selbs; 317 int i, fail; 318 319 ic->ic_flags &= ~IEEE80211_F_ASCAN; 320 ni = TAILQ_FIRST(&ic->ic_node); 321 322 if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 323 /* XXX off stack? */ 324 u_char occupied[roundup(IEEE80211_CHAN_MAX, NBBY)]; 325 /* 326 * The passive scan to look for existing AP's completed, 327 * select a channel to camp on. Identify the channels 328 * that already have one or more AP's and try to locate 329 * an unnoccupied one. If that fails, pick a random 330 * channel from the active set. 331 */ 332 for (; ni != NULL; ni = nextbs) { 333 ieee80211_ref_node(ni); 334 nextbs = TAILQ_NEXT(ni, ni_list); 335 setbit(occupied, ieee80211_chan2ieee(ic, ni->ni_chan)); 336 ieee80211_free_node(ic, ni); 337 } 338 for (i = 0; i < IEEE80211_CHAN_MAX; i++) 339 if (isset(ic->ic_chan_active, i) && isclr(occupied, i)) 340 break; 341 if (i == IEEE80211_CHAN_MAX) { 342 fail = arc4random() & 3; /* random 0-3 */ 343 for (i = 0; i < IEEE80211_CHAN_MAX; i++) 344 if (isset(ic->ic_chan_active, i) && fail-- == 0) 345 break; 346 } 347 ieee80211_create_ibss(ic, &ic->ic_channels[i]); 348 return; 349 } 350 if (ni == NULL) { 351 IEEE80211_DPRINTF(("%s: no scan candidate\n", __func__)); 352 notfound: 353 if (ic->ic_opmode == IEEE80211_M_IBSS && 354 (ic->ic_flags & IEEE80211_F_IBSSON) && 355 ic->ic_des_esslen != 0) { 356 ieee80211_create_ibss(ic, ic->ic_ibss_chan); 357 return; 358 } 359 /* 360 * Reset the list of channels to scan and start again. 361 */ 362 ieee80211_reset_scan(ifp); 363 ieee80211_next_scan(ifp); 364 return; 365 } 366 selbs = NULL; 367 if (ifp->if_flags & IFF_DEBUG) 368 if_printf(ifp, "\tmacaddr bssid chan rssi rate flag wep essid\n"); 369 for (; ni != NULL; ni = nextbs) { 370 ieee80211_ref_node(ni); 371 nextbs = TAILQ_NEXT(ni, ni_list); 372 if (ni->ni_fails) { 373 /* 374 * The configuration of the access points may change 375 * during my scan. So delete the entry for the AP 376 * and retry to associate if there is another beacon. 377 */ 378 if (ni->ni_fails++ > 2) 379 ieee80211_free_node(ic, ni); 380 continue; 381 } 382 if (ieee80211_match_bss(ifp, ni) == 0) { 383 if (selbs == NULL) 384 selbs = ni; 385 else if (ni->ni_rssi > selbs->ni_rssi) { 386 ieee80211_unref_node(&selbs); 387 selbs = ni; 388 } else 389 ieee80211_unref_node(&ni); 390 } else { 391 ieee80211_unref_node(&ni); 392 } 393 } 394 if (selbs == NULL) 395 goto notfound; 396 (*ic->ic_node_copy)(ic, ic->ic_bss, selbs); 397 if (ic->ic_opmode == IEEE80211_M_IBSS) { 398 ieee80211_fix_rate(ic, ic->ic_bss, IEEE80211_F_DOFRATE | 399 IEEE80211_F_DONEGO | IEEE80211_F_DODEL); 400 if (ic->ic_bss->ni_rates.rs_nrates == 0) { 401 selbs->ni_fails++; 402 ieee80211_unref_node(&selbs); 403 goto notfound; 404 } 405 ieee80211_unref_node(&selbs); 406 ieee80211_new_state(ic, IEEE80211_S_RUN, -1); 407 } else { 408 ieee80211_unref_node(&selbs); 409 ieee80211_new_state(ic, IEEE80211_S_AUTH, -1); 410 } 411} 412 413static struct ieee80211_node * 414ieee80211_node_alloc(struct ieee80211com *ic) 415{ 416 struct ieee80211_node *ni; 417 MALLOC(ni, struct ieee80211_node *, sizeof(struct ieee80211_node), 418 M_80211_NODE, M_NOWAIT | M_ZERO); 419 return ni; 420} 421 422static void 423ieee80211_node_free(struct ieee80211com *ic, struct ieee80211_node *ni) 424{ 425 FREE(ni, M_80211_NODE); 426} 427 428static void 429ieee80211_node_copy(struct ieee80211com *ic, 430 struct ieee80211_node *dst, const struct ieee80211_node *src) 431{ 432 *dst = *src; 433} 434 435static u_int8_t 436ieee80211_node_getrssi(struct ieee80211com *ic, struct ieee80211_node *ni) 437{ 438 return ni->ni_rssi; 439} 440 441static void 442ieee80211_setup_node(struct ieee80211com *ic, 443 struct ieee80211_node *ni, u_int8_t *macaddr) 444{ 445 int hash; 446 447 IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr); 448 hash = IEEE80211_NODE_HASH(macaddr); 449 ni->ni_refcnt = 1; /* mark referenced */ 450 IEEE80211_NODE_LOCK(ic); 451 TAILQ_INSERT_TAIL(&ic->ic_node, ni, ni_list); 452 LIST_INSERT_HEAD(&ic->ic_hash[hash], ni, ni_hash); 453 /* 454 * Note we don't enable the inactive timer when acting 455 * as a station. Nodes created in this mode represent 456 * AP's identified while scanning. If we time them out 457 * then several things happen: we can't return the data 458 * to users to show the list of AP's we encountered, and 459 * more importantly, we'll incorrectly deauthenticate 460 * ourself because the inactivity timer will kick us off. 461 */ 462 if (ic->ic_opmode != IEEE80211_M_STA) 463 ic->ic_inact_timer = IEEE80211_INACT_WAIT; 464 IEEE80211_NODE_UNLOCK(ic); 465} 466 467struct ieee80211_node * 468ieee80211_alloc_node(struct ieee80211com *ic, u_int8_t *macaddr) 469{ 470 struct ieee80211_node *ni = (*ic->ic_node_alloc)(ic); 471 if (ni != NULL) 472 ieee80211_setup_node(ic, ni, macaddr); 473 else 474 ic->ic_stats.is_rx_nodealloc++; 475 return ni; 476} 477 478struct ieee80211_node * 479ieee80211_dup_bss(struct ieee80211com *ic, u_int8_t *macaddr) 480{ 481 struct ieee80211_node *ni = (*ic->ic_node_alloc)(ic); 482 if (ni != NULL) { 483 memcpy(ni, ic->ic_bss, sizeof(struct ieee80211_node)); 484 ieee80211_setup_node(ic, ni, macaddr); 485 } 486 return ni; 487} 488 489struct ieee80211_node * 490ieee80211_find_node(struct ieee80211com *ic, u_int8_t *macaddr) 491{ 492 struct ieee80211_node *ni; 493 int hash; 494 495 hash = IEEE80211_NODE_HASH(macaddr); 496 IEEE80211_NODE_LOCK(ic); 497 LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) { 498 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) { 499 atomic_add_int(&ni->ni_refcnt, 1); /* mark referenced */ 500 break; 501 } 502 } 503 IEEE80211_NODE_UNLOCK(ic); 504 return ni; 505} 506 507/* 508 * Like find but search based on the channel too. 509 */ 510struct ieee80211_node * 511ieee80211_lookup_node(struct ieee80211com *ic, 512 u_int8_t *macaddr, struct ieee80211_channel *chan) 513{ 514 struct ieee80211_node *ni; 515 int hash; 516 517 hash = IEEE80211_NODE_HASH(macaddr); 518 IEEE80211_NODE_LOCK(ic); 519 LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) { 520 if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_chan == chan) { 521 atomic_add_int(&ni->ni_refcnt, 1);/* mark referenced */ 522 break; 523 } 524 } 525 IEEE80211_NODE_UNLOCK(ic); 526 return ni; 527} 528 529static void 530_ieee80211_free_node(struct ieee80211com *ic, struct ieee80211_node *ni) 531{ 532 KASSERT(ni != ic->ic_bss, ("freeing bss node")); 533 534 TAILQ_REMOVE(&ic->ic_node, ni, ni_list); 535 LIST_REMOVE(ni, ni_hash); 536 if (TAILQ_EMPTY(&ic->ic_node)) 537 ic->ic_inact_timer = 0; 538 (*ic->ic_node_free)(ic, ni); 539} 540 541void 542ieee80211_free_node(struct ieee80211com *ic, struct ieee80211_node *ni) 543{ 544 KASSERT(ni != ic->ic_bss, ("freeing ic_bss")); 545 546 /* XXX need equivalent of atomic_dec_and_test */ 547 atomic_subtract_int(&ni->ni_refcnt, 1); 548 if (atomic_cmpset_int(&ni->ni_refcnt, 0, 1)) { 549 IEEE80211_NODE_LOCK(ic); 550 _ieee80211_free_node(ic, ni); 551 IEEE80211_NODE_UNLOCK(ic); 552 } 553} 554 555void 556ieee80211_free_allnodes(struct ieee80211com *ic) 557{ 558 struct ieee80211_node *ni; 559 560 IEEE80211_NODE_LOCK(ic); 561 while ((ni = TAILQ_FIRST(&ic->ic_node)) != NULL) 562 _ieee80211_free_node(ic, ni); 563 IEEE80211_NODE_UNLOCK(ic); 564} 565 566/* 567 * Timeout inactive nodes. Note that we cannot hold the node 568 * lock while sending a frame as this would lead to a LOR. 569 * Instead we use a generation number to mark nodes that we've 570 * scanned and drop the lock and restart a scan if we have to 571 * time out a node. Since we are single-threaded by virtue of 572 * controlling the inactivity timer we can be sure this will 573 * process each node only once. 574 */ 575void 576ieee80211_timeout_nodes(struct ieee80211com *ic) 577{ 578 struct ieee80211_node *ni; 579 u_int gen = ic->ic_scangen++; /* NB: ok 'cuz single-threaded*/ 580 581restart: 582 IEEE80211_NODE_LOCK(ic); 583 TAILQ_FOREACH(ni, &ic->ic_node, ni_list) { 584 if (ni->ni_scangen == gen) /* previously handled */ 585 continue; 586 ni->ni_scangen = gen; 587 if (++ni->ni_inact > IEEE80211_INACT_MAX) { 588 IEEE80211_DPRINTF(("station %s timed out " 589 "due to inactivity (%u secs)\n", 590 ether_sprintf(ni->ni_macaddr), 591 ni->ni_inact)); 592 /* 593 * Send a deauthenticate frame. 594 * 595 * Drop the node lock before sending the 596 * deauthentication frame in case the driver takes 597 * a lock, as this will result in a LOR between the 598 * node lock and the driver lock. 599 */ 600 IEEE80211_NODE_UNLOCK(ic); 601 IEEE80211_SEND_MGMT(ic, ni, 602 IEEE80211_FC0_SUBTYPE_DEAUTH, 603 IEEE80211_REASON_AUTH_EXPIRE); 604 ieee80211_free_node(ic, ni); 605 ic->ic_stats.is_node_timeout++; 606 goto restart; 607 } 608 } 609 if (!TAILQ_EMPTY(&ic->ic_node)) 610 ic->ic_inact_timer = IEEE80211_INACT_WAIT; 611 IEEE80211_NODE_UNLOCK(ic); 612} 613 614void 615ieee80211_iterate_nodes(struct ieee80211com *ic, ieee80211_iter_func *f, void *arg) 616{ 617 struct ieee80211_node *ni; 618 619 IEEE80211_NODE_LOCK(ic); 620 TAILQ_FOREACH(ni, &ic->ic_node, ni_list) 621 (*f)(arg, ni); 622 IEEE80211_NODE_UNLOCK(ic); 623} 624