1 /*- 2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include <sys/cdefs.h> 27 __FBSDID("$FreeBSD$"); 28 29 /* 30 * IEEE 802.11 scanning support. 31 */ 32 #include "opt_wlan.h" 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/proc.h> 37 #include <sys/kernel.h> 38 #include <sys/condvar.h> 39 40 #include <sys/socket.h> 41 42 #include <net/if.h> 43 #include <net/if_var.h> 44 #include <net/if_media.h> 45 #include <net/ethernet.h> 46 47 #include <net80211/ieee80211_var.h> 48 49 /* XXX until it's implemented as attach ops */ 50 #include <net80211/ieee80211_scan_sw.h> 51 52 #include <net/bpf.h> 53 54 /* 55 * Roaming-related defaults. RSSI thresholds are as returned by the 56 * driver (.5dBm). Transmit rate thresholds are IEEE rate codes (i.e 57 * .5M units) or MCS. 58 */ 59 /* rssi thresholds */ 60 #define ROAM_RSSI_11A_DEFAULT 14 /* 11a bss */ 61 #define ROAM_RSSI_11B_DEFAULT 14 /* 11b bss */ 62 #define ROAM_RSSI_11BONLY_DEFAULT 14 /* 11b-only bss */ 63 /* transmit rate thresholds */ 64 #define ROAM_RATE_11A_DEFAULT 2*12 /* 11a bss */ 65 #define ROAM_RATE_11B_DEFAULT 2*5 /* 11b bss */ 66 #define ROAM_RATE_11BONLY_DEFAULT 2*1 /* 11b-only bss */ 67 #define ROAM_RATE_HALF_DEFAULT 2*6 /* half-width 11a/g bss */ 68 #define ROAM_RATE_QUARTER_DEFAULT 2*3 /* quarter-width 11a/g bss */ 69 #define ROAM_MCS_11N_DEFAULT (1 | IEEE80211_RATE_MCS) /* 11n bss */ 70 71 void 72 ieee80211_scan_attach(struct ieee80211com *ic) 73 { 74 75 /* 76 * For now, the swscan module does both the 77 * allocation (so it can pad it) and sets up the net80211 78 * bits. 79 * 80 * I'll split this stuff later. 81 */ 82 ieee80211_swscan_attach(ic); 83 } 84 85 void 86 ieee80211_scan_detach(struct ieee80211com *ic) 87 { 88 89 /* 90 * Ideally we'd do the ss_ops detach call here; 91 * but then ieee80211_swscan_detach would need 92 * to be split in two. 93 * 94 * I'll do that later. 95 */ 96 ieee80211_swscan_detach(ic); 97 } 98 99 static const struct ieee80211_roamparam defroam[IEEE80211_MODE_MAX] = { 100 [IEEE80211_MODE_11A] = { .rssi = ROAM_RSSI_11A_DEFAULT, 101 .rate = ROAM_RATE_11A_DEFAULT }, 102 [IEEE80211_MODE_11G] = { .rssi = ROAM_RSSI_11B_DEFAULT, 103 .rate = ROAM_RATE_11B_DEFAULT }, 104 [IEEE80211_MODE_11B] = { .rssi = ROAM_RSSI_11BONLY_DEFAULT, 105 .rate = ROAM_RATE_11BONLY_DEFAULT }, 106 [IEEE80211_MODE_TURBO_A]= { .rssi = ROAM_RSSI_11A_DEFAULT, 107 .rate = ROAM_RATE_11A_DEFAULT }, 108 [IEEE80211_MODE_TURBO_G]= { .rssi = ROAM_RSSI_11A_DEFAULT, 109 .rate = ROAM_RATE_11A_DEFAULT }, 110 [IEEE80211_MODE_STURBO_A]={ .rssi = ROAM_RSSI_11A_DEFAULT, 111 .rate = ROAM_RATE_11A_DEFAULT }, 112 [IEEE80211_MODE_HALF] = { .rssi = ROAM_RSSI_11A_DEFAULT, 113 .rate = ROAM_RATE_HALF_DEFAULT }, 114 [IEEE80211_MODE_QUARTER]= { .rssi = ROAM_RSSI_11A_DEFAULT, 115 .rate = ROAM_RATE_QUARTER_DEFAULT }, 116 [IEEE80211_MODE_11NA] = { .rssi = ROAM_RSSI_11A_DEFAULT, 117 .rate = ROAM_MCS_11N_DEFAULT }, 118 [IEEE80211_MODE_11NG] = { .rssi = ROAM_RSSI_11B_DEFAULT, 119 .rate = ROAM_MCS_11N_DEFAULT }, 120 }; 121 122 void 123 ieee80211_scan_vattach(struct ieee80211vap *vap) 124 { 125 vap->iv_bgscanidle = (IEEE80211_BGSCAN_IDLE_DEFAULT*1000)/hz; 126 vap->iv_bgscanintvl = IEEE80211_BGSCAN_INTVAL_DEFAULT*hz; 127 vap->iv_scanvalid = IEEE80211_SCAN_VALID_DEFAULT*hz; 128 129 vap->iv_roaming = IEEE80211_ROAMING_AUTO; 130 memcpy(vap->iv_roamparms, defroam, sizeof(defroam)); 131 132 ieee80211_swscan_vattach(vap); 133 } 134 135 void 136 ieee80211_scan_vdetach(struct ieee80211vap *vap) 137 { 138 struct ieee80211com *ic = vap->iv_ic; 139 struct ieee80211_scan_state *ss; 140 141 IEEE80211_LOCK(ic); 142 ss = ic->ic_scan; 143 144 ieee80211_swscan_vdetach(vap); 145 146 if (ss != NULL && ss->ss_vap == vap) { 147 if (ss->ss_ops != NULL) { 148 ss->ss_ops->scan_detach(ss); 149 ss->ss_ops = NULL; 150 } 151 ss->ss_vap = NULL; 152 } 153 IEEE80211_UNLOCK(ic); 154 } 155 156 /* 157 * Simple-minded scanner module support. 158 */ 159 static const char *scan_modnames[IEEE80211_OPMODE_MAX] = { 160 "wlan_scan_sta", /* IEEE80211_M_IBSS */ 161 "wlan_scan_sta", /* IEEE80211_M_STA */ 162 "wlan_scan_wds", /* IEEE80211_M_WDS */ 163 "wlan_scan_sta", /* IEEE80211_M_AHDEMO */ 164 "wlan_scan_ap", /* IEEE80211_M_HOSTAP */ 165 "wlan_scan_monitor", /* IEEE80211_M_MONITOR */ 166 "wlan_scan_sta", /* IEEE80211_M_MBSS */ 167 }; 168 static const struct ieee80211_scanner *scanners[IEEE80211_OPMODE_MAX]; 169 170 const struct ieee80211_scanner * 171 ieee80211_scanner_get(enum ieee80211_opmode mode) 172 { 173 if (mode >= IEEE80211_OPMODE_MAX) 174 return NULL; 175 if (scanners[mode] == NULL) 176 ieee80211_load_module(scan_modnames[mode]); 177 return scanners[mode]; 178 } 179 180 void 181 ieee80211_scanner_register(enum ieee80211_opmode mode, 182 const struct ieee80211_scanner *scan) 183 { 184 if (mode >= IEEE80211_OPMODE_MAX) 185 return; 186 scanners[mode] = scan; 187 } 188 189 void 190 ieee80211_scanner_unregister(enum ieee80211_opmode mode, 191 const struct ieee80211_scanner *scan) 192 { 193 if (mode >= IEEE80211_OPMODE_MAX) 194 return; 195 if (scanners[mode] == scan) 196 scanners[mode] = NULL; 197 } 198 199 void 200 ieee80211_scanner_unregister_all(const struct ieee80211_scanner *scan) 201 { 202 int m; 203 204 for (m = 0; m < IEEE80211_OPMODE_MAX; m++) 205 if (scanners[m] == scan) 206 scanners[m] = NULL; 207 } 208 209 /* 210 * Update common scanner state to reflect the current 211 * operating mode. This is called when the state machine 212 * is transitioned to RUN state w/o scanning--e.g. when 213 * operating in monitor mode. The purpose of this is to 214 * ensure later callbacks find ss_ops set to properly 215 * reflect current operating mode. 216 */ 217 void 218 ieee80211_scan_update_locked(struct ieee80211vap *vap, 219 const struct ieee80211_scanner *scan) 220 { 221 struct ieee80211com *ic = vap->iv_ic; 222 struct ieee80211_scan_state *ss = ic->ic_scan; 223 224 IEEE80211_LOCK_ASSERT(ic); 225 226 #ifdef IEEE80211_DEBUG 227 if (ss->ss_vap != vap || ss->ss_ops != scan) { 228 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 229 "%s: current scanner is <%s:%s>, switch to <%s:%s>\n", 230 __func__, 231 ss->ss_vap != NULL ? 232 ss->ss_vap->iv_ifp->if_xname : "none", 233 ss->ss_vap != NULL ? 234 ieee80211_opmode_name[ss->ss_vap->iv_opmode] : "none", 235 vap->iv_ifp->if_xname, 236 ieee80211_opmode_name[vap->iv_opmode]); 237 } 238 #endif 239 ss->ss_vap = vap; 240 if (ss->ss_ops != scan) { 241 /* 242 * Switch scanners; detach old, attach new. Special 243 * case where a single scan module implements multiple 244 * policies by using different scan ops but a common 245 * core. We assume if the old and new attach methods 246 * are identical then it's ok to just change ss_ops 247 * and not flush the internal state of the module. 248 */ 249 if (scan == NULL || ss->ss_ops == NULL || 250 ss->ss_ops->scan_attach != scan->scan_attach) { 251 if (ss->ss_ops != NULL) 252 ss->ss_ops->scan_detach(ss); 253 if (scan != NULL && !scan->scan_attach(ss)) { 254 /* XXX attach failure */ 255 /* XXX stat+msg */ 256 scan = NULL; 257 } 258 } 259 ss->ss_ops = scan; 260 } 261 } 262 263 void 264 ieee80211_scan_dump_channels(const struct ieee80211_scan_state *ss) 265 { 266 struct ieee80211com *ic = ss->ss_ic; 267 const char *sep; 268 int i; 269 270 sep = ""; 271 for (i = ss->ss_next; i < ss->ss_last; i++) { 272 const struct ieee80211_channel *c = ss->ss_chans[i]; 273 274 printf("%s%u%c", sep, ieee80211_chan2ieee(ic, c), 275 ieee80211_channel_type_char(c)); 276 sep = ", "; 277 } 278 } 279 280 #ifdef IEEE80211_DEBUG 281 void 282 ieee80211_scan_dump(struct ieee80211_scan_state *ss) 283 { 284 struct ieee80211vap *vap = ss->ss_vap; 285 286 if_printf(vap->iv_ifp, "scan set "); 287 ieee80211_scan_dump_channels(ss); 288 printf(" dwell min %lums max %lums\n", 289 ticks_to_msecs(ss->ss_mindwell), ticks_to_msecs(ss->ss_maxdwell)); 290 } 291 #endif /* IEEE80211_DEBUG */ 292 293 void 294 ieee80211_scan_copy_ssid(struct ieee80211vap *vap, struct ieee80211_scan_state *ss, 295 int nssid, const struct ieee80211_scan_ssid ssids[]) 296 { 297 if (nssid > IEEE80211_SCAN_MAX_SSID) { 298 /* XXX printf */ 299 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 300 "%s: too many ssid %d, ignoring all of them\n", 301 __func__, nssid); 302 return; 303 } 304 memcpy(ss->ss_ssid, ssids, nssid * sizeof(ssids[0])); 305 ss->ss_nssid = nssid; 306 } 307 308 /* 309 * Start a scan unless one is already going. 310 */ 311 int 312 ieee80211_start_scan(struct ieee80211vap *vap, int flags, 313 u_int duration, u_int mindwell, u_int maxdwell, 314 u_int nssid, const struct ieee80211_scan_ssid ssids[]) 315 { 316 const struct ieee80211_scanner *scan; 317 318 scan = ieee80211_scanner_get(vap->iv_opmode); 319 if (scan == NULL) { 320 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 321 "%s: no scanner support for %s mode\n", 322 __func__, ieee80211_opmode_name[vap->iv_opmode]); 323 /* XXX stat */ 324 return 0; 325 } 326 327 /* XXX ops */ 328 return ieee80211_swscan_start_scan(scan, vap, flags, duration, 329 mindwell, maxdwell, nssid, ssids); 330 } 331 332 /* 333 * Check the scan cache for an ap/channel to use; if that 334 * fails then kick off a new scan. 335 */ 336 int 337 ieee80211_check_scan(struct ieee80211vap *vap, int flags, 338 u_int duration, u_int mindwell, u_int maxdwell, 339 u_int nssid, const struct ieee80211_scan_ssid ssids[]) 340 { 341 struct ieee80211com *ic = vap->iv_ic; 342 struct ieee80211_scan_state *ss = ic->ic_scan; 343 const struct ieee80211_scanner *scan; 344 int result; 345 346 scan = ieee80211_scanner_get(vap->iv_opmode); 347 if (scan == NULL) { 348 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 349 "%s: no scanner support for %s mode\n", 350 __func__, vap->iv_opmode); 351 /* XXX stat */ 352 return 0; 353 } 354 355 /* 356 * Check if there's a list of scan candidates already. 357 * XXX want more than the ap we're currently associated with 358 */ 359 360 IEEE80211_LOCK(ic); 361 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 362 "%s: %s scan, %s%s%s%s%s\n" 363 , __func__ 364 , flags & IEEE80211_SCAN_ACTIVE ? "active" : "passive" 365 , flags & IEEE80211_SCAN_FLUSH ? "flush" : "append" 366 , flags & IEEE80211_SCAN_NOPICK ? ", nopick" : "" 367 , flags & IEEE80211_SCAN_NOJOIN ? ", nojoin" : "" 368 , flags & IEEE80211_SCAN_PICK1ST ? ", pick1st" : "" 369 , flags & IEEE80211_SCAN_ONCE ? ", once" : "" 370 ); 371 372 if (ss->ss_ops != scan) { 373 /* XXX re-use cache contents? e.g. adhoc<->sta */ 374 flags |= IEEE80211_SCAN_FLUSH; 375 } 376 377 /* 378 * XXX TODO: separate things out a bit better. 379 * XXX TODO: ops 380 */ 381 ieee80211_scan_update_locked(vap, scan); 382 383 result = ieee80211_swscan_check_scan(scan, vap, flags, duration, 384 mindwell, maxdwell, nssid, ssids); 385 386 IEEE80211_UNLOCK(ic); 387 388 return (result); 389 } 390 391 /* 392 * Check the scan cache for an ap/channel to use; if that fails 393 * then kick off a scan using the current settings. 394 */ 395 int 396 ieee80211_check_scan_current(struct ieee80211vap *vap) 397 { 398 return ieee80211_check_scan(vap, 399 IEEE80211_SCAN_ACTIVE, 400 IEEE80211_SCAN_FOREVER, 0, 0, 401 vap->iv_des_nssid, vap->iv_des_ssid); 402 } 403 404 /* 405 * Restart a previous scan. If the previous scan completed 406 * then we start again using the existing channel list. 407 */ 408 int 409 ieee80211_bg_scan(struct ieee80211vap *vap, int flags) 410 { 411 const struct ieee80211_scanner *scan; 412 413 // IEEE80211_UNLOCK_ASSERT(sc); 414 415 scan = ieee80211_scanner_get(vap->iv_opmode); 416 if (scan == NULL) { 417 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 418 "%s: no scanner support for %s mode\n", 419 __func__, vap->iv_opmode); 420 /* XXX stat */ 421 return 0; 422 } 423 424 /* 425 * XXX TODO: pull apart the bgscan logic into whatever 426 * belongs here and whatever belongs in the software 427 * scanner. 428 * 429 * XXX TODO: ops 430 */ 431 return (ieee80211_swscan_bg_scan(scan, vap, flags)); 432 } 433 434 /* 435 * Cancel any scan currently going on for the specified vap. 436 */ 437 void 438 ieee80211_cancel_scan(struct ieee80211vap *vap) 439 { 440 441 /* XXX TODO: ops */ 442 ieee80211_swscan_cancel_scan(vap); 443 } 444 445 /* 446 * Cancel any scan currently going on. 447 */ 448 void 449 ieee80211_cancel_anyscan(struct ieee80211vap *vap) 450 { 451 452 /* XXX TODO: ops */ 453 ieee80211_swscan_cancel_anyscan(vap); 454 } 455 456 /* 457 * Public access to scan_next for drivers that manage 458 * scanning themselves (e.g. for firmware-based devices). 459 */ 460 void 461 ieee80211_scan_next(struct ieee80211vap *vap) 462 { 463 464 /* XXX TODO: ops */ 465 ieee80211_swscan_scan_next(vap); 466 } 467 468 /* 469 * Public access to scan_next for drivers that are not able to scan single 470 * channels (e.g. for firmware-based devices). 471 */ 472 void 473 ieee80211_scan_done(struct ieee80211vap *vap) 474 { 475 struct ieee80211com *ic = vap->iv_ic; 476 struct ieee80211_scan_state *ss; 477 478 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s: called\n", __func__); 479 480 IEEE80211_LOCK(ic); 481 ss = ic->ic_scan; 482 ss->ss_next = ss->ss_last; /* all channels are complete */ 483 484 /* XXX TODO: ops */ 485 ieee80211_swscan_scan_done(vap); 486 487 IEEE80211_UNLOCK(ic); 488 } 489 490 /* 491 * Probe the curent channel, if allowed, while scanning. 492 * If the channel is not marked passive-only then send 493 * a probe request immediately. Otherwise mark state and 494 * listen for beacons on the channel; if we receive something 495 * then we'll transmit a probe request. 496 */ 497 void 498 ieee80211_probe_curchan(struct ieee80211vap *vap, int force) 499 { 500 struct ieee80211com *ic = vap->iv_ic; 501 502 if ((ic->ic_curchan->ic_flags & IEEE80211_CHAN_PASSIVE) && !force) { 503 ic->ic_flags_ext |= IEEE80211_FEXT_PROBECHAN; 504 return; 505 } 506 507 /* XXX TODO: ops */ 508 ieee80211_swscan_probe_curchan(vap, force); 509 } 510 511 #ifdef IEEE80211_DEBUG 512 static void 513 dump_country(const uint8_t *ie) 514 { 515 const struct ieee80211_country_ie *cie = 516 (const struct ieee80211_country_ie *) ie; 517 int i, nbands, schan, nchan; 518 519 if (cie->len < 3) { 520 printf(" <bogus country ie, len %d>", cie->len); 521 return; 522 } 523 printf(" country [%c%c%c", cie->cc[0], cie->cc[1], cie->cc[2]); 524 nbands = (cie->len - 3) / sizeof(cie->band[0]); 525 for (i = 0; i < nbands; i++) { 526 schan = cie->band[i].schan; 527 nchan = cie->band[i].nchan; 528 if (nchan != 1) 529 printf(" %u-%u,%u", schan, schan + nchan-1, 530 cie->band[i].maxtxpwr); 531 else 532 printf(" %u,%u", schan, cie->band[i].maxtxpwr); 533 } 534 printf("]"); 535 } 536 537 void 538 ieee80211_scan_dump_probe_beacon(uint8_t subtype, int isnew, 539 const uint8_t mac[IEEE80211_ADDR_LEN], 540 const struct ieee80211_scanparams *sp, int rssi) 541 { 542 543 printf("[%s] %s%s on chan %u (bss chan %u) ", 544 ether_sprintf(mac), isnew ? "new " : "", 545 ieee80211_mgt_subtype_name[subtype >> IEEE80211_FC0_SUBTYPE_SHIFT], 546 sp->chan, sp->bchan); 547 ieee80211_print_essid(sp->ssid + 2, sp->ssid[1]); 548 printf(" rssi %d\n", rssi); 549 550 if (isnew) { 551 printf("[%s] caps 0x%x bintval %u erp 0x%x", 552 ether_sprintf(mac), sp->capinfo, sp->bintval, sp->erp); 553 if (sp->country != NULL) 554 dump_country(sp->country); 555 printf("\n"); 556 } 557 } 558 #endif /* IEEE80211_DEBUG */ 559 560 /* 561 * Process a beacon or probe response frame. 562 */ 563 void 564 ieee80211_add_scan(struct ieee80211vap *vap, 565 struct ieee80211_channel *curchan, 566 const struct ieee80211_scanparams *sp, 567 const struct ieee80211_frame *wh, 568 int subtype, int rssi, int noise) 569 { 570 571 return (ieee80211_swscan_add_scan(vap, curchan, sp, wh, subtype, 572 rssi, noise)); 573 } 574 575 /* 576 * Timeout/age scan cache entries; called from sta timeout 577 * timer (XXX should be self-contained). 578 */ 579 void 580 ieee80211_scan_timeout(struct ieee80211com *ic) 581 { 582 struct ieee80211_scan_state *ss = ic->ic_scan; 583 584 if (ss->ss_ops != NULL) 585 ss->ss_ops->scan_age(ss); 586 } 587 588 /* 589 * Mark a scan cache entry after a successful associate. 590 */ 591 void 592 ieee80211_scan_assoc_success(struct ieee80211vap *vap, const uint8_t mac[]) 593 { 594 struct ieee80211_scan_state *ss = vap->iv_ic->ic_scan; 595 596 if (ss->ss_ops != NULL) { 597 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_SCAN, 598 mac, "%s", __func__); 599 ss->ss_ops->scan_assoc_success(ss, mac); 600 } 601 } 602 603 /* 604 * Demerit a scan cache entry after failing to associate. 605 */ 606 void 607 ieee80211_scan_assoc_fail(struct ieee80211vap *vap, 608 const uint8_t mac[], int reason) 609 { 610 struct ieee80211_scan_state *ss = vap->iv_ic->ic_scan; 611 612 if (ss->ss_ops != NULL) { 613 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_SCAN, mac, 614 "%s: reason %u", __func__, reason); 615 ss->ss_ops->scan_assoc_fail(ss, mac, reason); 616 } 617 } 618 619 /* 620 * Iterate over the contents of the scan cache. 621 */ 622 void 623 ieee80211_scan_iterate(struct ieee80211vap *vap, 624 ieee80211_scan_iter_func *f, void *arg) 625 { 626 struct ieee80211_scan_state *ss = vap->iv_ic->ic_scan; 627 628 if (ss->ss_ops != NULL) 629 ss->ss_ops->scan_iterate(ss, f, arg); 630 } 631 632 /* 633 * Flush the contents of the scan cache. 634 */ 635 void 636 ieee80211_scan_flush(struct ieee80211vap *vap) 637 { 638 struct ieee80211_scan_state *ss = vap->iv_ic->ic_scan; 639 640 if (ss->ss_ops != NULL && ss->ss_vap == vap) { 641 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s\n", __func__); 642 ss->ss_ops->scan_flush(ss); 643 } 644 } 645 646 /* 647 * Check the scan cache for an ap/channel to use; if that 648 * fails then kick off a new scan. 649 */ 650 struct ieee80211_channel * 651 ieee80211_scan_pickchannel(struct ieee80211com *ic, int flags) 652 { 653 struct ieee80211_scan_state *ss = ic->ic_scan; 654 655 IEEE80211_LOCK_ASSERT(ic); 656 657 if (ss == NULL || ss->ss_ops == NULL || ss->ss_vap == NULL) { 658 /* XXX printf? */ 659 return NULL; 660 } 661 if (ss->ss_ops->scan_pickchan == NULL) { 662 IEEE80211_DPRINTF(ss->ss_vap, IEEE80211_MSG_SCAN, 663 "%s: scan module does not support picking a channel, " 664 "opmode %s\n", __func__, ss->ss_vap->iv_opmode); 665 return NULL; 666 } 667 return ss->ss_ops->scan_pickchan(ss, flags); 668 } 669