2 * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
30 * IEEE 802.11 station scanning support.
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <sys/socket.h>
40 #include <net/if_media.h>
41 #include <net/ethernet.h>
43 #include <net80211/ieee80211_var.h>
48 * Parameters for managing cache entries:
50 * o a station with STA_FAILS_MAX failures is not considered
51 * when picking a candidate
52 * o a station that hasn't had an update in STA_PURGE_SCANS
53 * (background) scans is discarded
54 * o after STA_FAILS_AGE seconds we clear the failure count
56 #define STA_FAILS_MAX 2 /* assoc failures before ignored */
57 #define STA_FAILS_AGE (2*60) /* time before clearing fails (secs) */
58 #define STA_PURGE_SCANS 2 /* age for purging entries (scans) */
61 #define STA_RSSI_MIN 8 /* min acceptable rssi */
62 #define STA_RSSI_MAX 40 /* max rssi for comparison */
64 #define RSSI_LPF_LEN 10
65 #define RSSI_DUMMY_MARKER 0x127
66 #define RSSI_EP_MULTIPLIER (1<<7) /* pow2 to optimize out * and / */
67 #define RSSI_IN(x) ((x) * RSSI_EP_MULTIPLIER)
68 #define LPF_RSSI(x, y, len) \
69 ((x != RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
70 #define RSSI_LPF(x, y) do { \
72 x = LPF_RSSI((x), RSSI_IN((y)), RSSI_LPF_LEN); \
74 #define EP_RND(x, mul) \
75 ((((x)%(mul)) >= ((mul)/2)) ? howmany(x, mul) : (x)/(mul))
76 #define RSSI_GET(x) EP_RND(x, RSSI_EP_MULTIPLIER)
79 struct ieee80211_scan_entry base;
80 TAILQ_ENTRY(sta_entry) se_list;
81 LIST_ENTRY(sta_entry) se_hash;
82 uint8_t se_fails; /* failure to associate count */
83 uint8_t se_seen; /* seen during current scan */
84 uint8_t se_notseen; /* not seen in previous scans */
86 uint32_t se_avgrssi; /* LPF rssi state */
87 unsigned long se_lastupdate; /* time of last update */
88 unsigned long se_lastfail; /* time of last failure */
89 unsigned long se_lastassoc; /* time of last association */
90 u_int se_scangen; /* iterator scan gen# */
93 #define STA_HASHSIZE 32
94 /* simple hash is enough for variation of macaddr */
95 #define STA_HASH(addr) \
96 (((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % STA_HASHSIZE)
99 struct mtx st_lock; /* on scan table */
100 TAILQ_HEAD(, sta_entry) st_entry; /* all entries */
101 LIST_HEAD(, sta_entry) st_hash[STA_HASHSIZE];
102 struct mtx st_scanlock; /* on st_scangen */
103 u_int st_scangen; /* gen# for iterator */
107 static void sta_flush_table(struct sta_table *);
109 * match_bss returns a bitmask describing if an entry is suitable
110 * for use. If non-zero the entry was deemed not suitable and it's
111 * contents explains why. The following flags are or'd to to this
112 * mask and can be used to figure out why the entry was rejected.
114 #define MATCH_CHANNEL 0x001 /* channel mismatch */
115 #define MATCH_CAPINFO 0x002 /* capabilities mismatch, e.g. no ess */
116 #define MATCH_PRIVACY 0x004 /* privacy mismatch */
117 #define MATCH_RATE 0x008 /* rate set mismatch */
118 #define MATCH_SSID 0x010 /* ssid mismatch */
119 #define MATCH_BSSID 0x020 /* bssid mismatch */
120 #define MATCH_FAILS 0x040 /* too many failed auth attempts */
121 #define MATCH_NOTSEEN 0x080 /* not seen in recent scans */
122 #define MATCH_RSSI 0x100 /* rssi deemed too low to use */
123 static int match_bss(struct ieee80211com *,
124 const struct ieee80211_scan_state *, struct sta_entry *, int);
126 /* number of references from net80211 layer */
127 static int nrefs = 0;
130 * Attach prior to any scanning work.
133 sta_attach(struct ieee80211_scan_state *ss)
135 struct sta_table *st;
137 MALLOC(st, struct sta_table *, sizeof(struct sta_table),
138 M_80211_SCAN, M_NOWAIT | M_ZERO);
141 mtx_init(&st->st_lock, "scantable", "802.11 scan table", MTX_DEF);
142 mtx_init(&st->st_scanlock, "scangen", "802.11 scangen", MTX_DEF);
143 TAILQ_INIT(&st->st_entry);
145 nrefs++; /* NB: we assume caller locking */
150 * Cleanup any private state.
153 sta_detach(struct ieee80211_scan_state *ss)
155 struct sta_table *st = ss->ss_priv;
159 mtx_destroy(&st->st_lock);
160 mtx_destroy(&st->st_scanlock);
161 FREE(st, M_80211_SCAN);
162 KASSERT(nrefs > 0, ("imbalanced attach/detach"));
163 nrefs--; /* NB: we assume caller locking */
169 * Flush all per-scan state.
172 sta_flush(struct ieee80211_scan_state *ss)
174 struct sta_table *st = ss->ss_priv;
176 mtx_lock(&st->st_lock);
178 mtx_unlock(&st->st_lock);
184 * Flush all entries in the scan cache.
187 sta_flush_table(struct sta_table *st)
189 struct sta_entry *se, *next;
191 TAILQ_FOREACH_SAFE(se, &st->st_entry, se_list, next) {
192 TAILQ_REMOVE(&st->st_entry, se, se_list);
193 LIST_REMOVE(se, se_hash);
194 FREE(se, M_80211_SCAN);
199 * Process a beacon or probe response frame; create an
200 * entry in the scan cache or update any previous entry.
203 sta_add(struct ieee80211_scan_state *ss,
204 const struct ieee80211_scanparams *sp,
205 const struct ieee80211_frame *wh,
206 int subtype, int rssi, int noise, int rstamp)
208 #define ISPROBE(_st) ((_st) == IEEE80211_FC0_SUBTYPE_PROBE_RESP)
209 #define PICK1ST(_ss) \
210 ((ss->ss_flags & (IEEE80211_SCAN_PICK1ST | IEEE80211_SCAN_GOTPICK)) == \
211 IEEE80211_SCAN_PICK1ST)
212 struct sta_table *st = ss->ss_priv;
213 const uint8_t *macaddr = wh->i_addr2;
214 struct ieee80211com *ic = ss->ss_ic;
215 struct sta_entry *se;
216 struct ieee80211_scan_entry *ise;
219 hash = STA_HASH(macaddr);
221 mtx_lock(&st->st_lock);
222 LIST_FOREACH(se, &st->st_hash[hash], se_hash)
223 if (IEEE80211_ADDR_EQ(se->base.se_macaddr, macaddr))
225 MALLOC(se, struct sta_entry *, sizeof(struct sta_entry),
226 M_80211_SCAN, M_NOWAIT | M_ZERO);
228 mtx_unlock(&st->st_lock);
231 se->se_scangen = st->st_scangen-1;
232 se->se_avgrssi = RSSI_DUMMY_MARKER;
233 IEEE80211_ADDR_COPY(se->base.se_macaddr, macaddr);
234 TAILQ_INSERT_TAIL(&st->st_entry, se, se_list);
235 LIST_INSERT_HEAD(&st->st_hash[hash], se, se_hash);
238 /* XXX ap beaconing multiple ssid w/ same bssid */
239 if (sp->ssid[1] != 0 &&
240 (ISPROBE(subtype) || ise->se_ssid[1] == 0))
241 memcpy(ise->se_ssid, sp->ssid, 2+sp->ssid[1]);
242 KASSERT(sp->rates[1] <= IEEE80211_RATE_MAXSIZE,
243 ("rate set too large: %u", sp->rates[1]));
244 memcpy(ise->se_rates, sp->rates, 2+sp->rates[1]);
245 if (sp->xrates != NULL) {
246 /* XXX validate xrates[1] */
247 KASSERT(sp->xrates[1] + sp->rates[1] <= IEEE80211_RATE_MAXSIZE,
248 ("xrate set too large: %u", sp->xrates[1]));
249 memcpy(ise->se_xrates, sp->xrates, 2+sp->xrates[1]);
251 ise->se_xrates[1] = 0;
252 IEEE80211_ADDR_COPY(ise->se_bssid, wh->i_addr3);
253 offchan = (IEEE80211_CHAN2IEEE(sp->curchan) != sp->bchan &&
254 ic->ic_phytype != IEEE80211_T_FH);
257 * Record rssi data using extended precision LPF filter.
259 * NB: use only on-channel data to insure we get a good
260 * estimate of the signal we'll see when associated.
262 RSSI_LPF(se->se_avgrssi, rssi);
263 ise->se_rssi = RSSI_GET(se->se_avgrssi);
264 ise->se_noise = noise;
266 ise->se_rstamp = rstamp;
267 memcpy(ise->se_tstamp.data, sp->tstamp, sizeof(ise->se_tstamp));
268 ise->se_intval = sp->bintval;
269 ise->se_capinfo = sp->capinfo;
271 * Beware of overriding se_chan for frames seen
272 * off-channel; this can cause us to attempt an
273 * assocation on the wrong channel.
276 struct ieee80211_channel *c;
278 * Off-channel, locate the home/bss channel for the sta
279 * using the value broadcast in the DSPARMS ie.
281 c = ieee80211_find_channel_byieee(ic, sp->bchan,
282 sp->curchan->ic_flags);
285 } else if (ise->se_chan == NULL) {
286 /* should not happen, pick something */
287 ise->se_chan = sp->curchan;
290 ise->se_chan = sp->curchan;
291 ise->se_fhdwell = sp->fhdwell;
292 ise->se_fhindex = sp->fhindex;
293 ise->se_erp = sp->erp;
294 ise->se_timoff = sp->timoff;
295 if (sp->tim != NULL) {
296 const struct ieee80211_tim_ie *tim =
297 (const struct ieee80211_tim_ie *) sp->tim;
298 ise->se_dtimperiod = tim->tim_period;
300 /* NB: no need to setup ie ptrs; they are not (currently) used */
301 (void) ieee80211_ies_init(&ise->se_ies, sp->ies, sp->ies_len);
303 /* clear failure count after STA_FAIL_AGE passes */
304 if (se->se_fails && (ticks - se->se_lastfail) > STA_FAILS_AGE*hz) {
306 IEEE80211_NOTE_MAC(ic, IEEE80211_MSG_SCAN, macaddr,
307 "%s: fails %u", __func__, se->se_fails);
310 se->se_lastupdate = ticks; /* update time */
314 mtx_unlock(&st->st_lock);
317 * If looking for a quick choice and nothing's
318 * been found check here.
320 if (PICK1ST(ss) && match_bss(ic, ss, se, IEEE80211_MSG_SCAN) == 0)
321 ss->ss_flags |= IEEE80211_SCAN_GOTPICK;
329 * Check if a channel is excluded by user request.
332 isexcluded(struct ieee80211com *ic, const struct ieee80211_channel *c)
334 return (isclr(ic->ic_chan_active, c->ic_ieee) ||
335 (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
336 c->ic_freq != ic->ic_des_chan->ic_freq));
339 static struct ieee80211_channel *
340 find11gchannel(struct ieee80211com *ic, int i, int freq)
342 struct ieee80211_channel *c;
346 * The normal ordering in the channel list is b channel
347 * immediately followed by g so optimize the search for
348 * this. We'll still do a full search just in case.
350 for (j = i+1; j < ic->ic_nchans; j++) {
351 c = &ic->ic_channels[j];
352 if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
355 for (j = 0; j < i; j++) {
356 c = &ic->ic_channels[j];
357 if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
362 static const u_int chanflags[IEEE80211_MODE_MAX] = {
363 IEEE80211_CHAN_B, /* IEEE80211_MODE_AUTO */
364 IEEE80211_CHAN_A, /* IEEE80211_MODE_11A */
365 IEEE80211_CHAN_B, /* IEEE80211_MODE_11B */
366 IEEE80211_CHAN_G, /* IEEE80211_MODE_11G */
367 IEEE80211_CHAN_FHSS, /* IEEE80211_MODE_FH */
368 IEEE80211_CHAN_A, /* IEEE80211_MODE_TURBO_A (check base channel)*/
369 IEEE80211_CHAN_G, /* IEEE80211_MODE_TURBO_G */
370 IEEE80211_CHAN_ST, /* IEEE80211_MODE_STURBO_A */
371 IEEE80211_CHAN_A, /* IEEE80211_MODE_11NA (check legacy) */
372 IEEE80211_CHAN_G, /* IEEE80211_MODE_11NG (check legacy) */
376 add_channels(struct ieee80211com *ic,
377 struct ieee80211_scan_state *ss,
378 enum ieee80211_phymode mode, const uint16_t freq[], int nfreq)
380 #define N(a) (sizeof(a) / sizeof(a[0]))
381 struct ieee80211_channel *c, *cg;
385 KASSERT(mode < N(chanflags), ("Unexpected mode %u", mode));
386 modeflags = chanflags[mode];
387 for (i = 0; i < nfreq; i++) {
388 if (ss->ss_last >= IEEE80211_SCAN_MAX)
391 c = ieee80211_find_channel(ic, freq[i], modeflags);
392 if (c != NULL && isexcluded(ic, c))
394 if (mode == IEEE80211_MODE_AUTO) {
396 * XXX special-case 11b/g channels so we select
397 * the g channel if both are present or there
398 * are only g channels.
400 if (c == NULL || IEEE80211_IS_CHAN_B(c)) {
401 cg = find11gchannel(ic, i, freq[i]);
409 ss->ss_chans[ss->ss_last++] = c;
414 static const uint16_t rcl1[] = /* 8 FCC channel: 52, 56, 60, 64, 36, 40, 44, 48 */
415 { 5260, 5280, 5300, 5320, 5180, 5200, 5220, 5240 };
416 static const uint16_t rcl2[] = /* 4 MKK channels: 34, 38, 42, 46 */
417 { 5170, 5190, 5210, 5230 };
418 static const uint16_t rcl3[] = /* 2.4Ghz ch: 1,6,11,7,13 */
419 { 2412, 2437, 2462, 2442, 2472 };
420 static const uint16_t rcl4[] = /* 5 FCC channel: 149, 153, 161, 165 */
421 { 5745, 5765, 5785, 5805, 5825 };
422 static const uint16_t rcl7[] = /* 11 ETSI channel: 100,104,108,112,116,120,124,128,132,136,140 */
423 { 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, 5700 };
424 static const uint16_t rcl8[] = /* 2.4Ghz ch: 2,3,4,5,8,9,10,12 */
425 { 2417, 2422, 2427, 2432, 2447, 2452, 2457, 2467 };
426 static const uint16_t rcl9[] = /* 2.4Ghz ch: 14 */
428 static const uint16_t rcl10[] = /* Added Korean channels 2312-2372 */
429 { 2312, 2317, 2322, 2327, 2332, 2337, 2342, 2347, 2352, 2357, 2362, 2367, 2372 };
430 static const uint16_t rcl11[] = /* Added Japan channels in 4.9/5.0 spectrum */
431 { 5040, 5060, 5080, 4920, 4940, 4960, 4980 };
432 #ifdef ATH_TURBO_SCAN
433 static const uint16_t rcl5[] = /* 3 static turbo channels */
434 { 5210, 5250, 5290 };
435 static const uint16_t rcl6[] = /* 2 static turbo channels */
437 static const uint16_t rcl6x[] = /* 4 FCC3 turbo channels */
438 { 5540, 5580, 5620, 5660 };
439 static const uint16_t rcl12[] = /* 2.4Ghz Turbo channel 6 */
441 static const uint16_t rcl13[] = /* dynamic Turbo channels */
442 { 5200, 5240, 5280, 5765, 5805 };
443 #endif /* ATH_TURBO_SCAN */
448 const uint16_t *list;
451 #define X(a) .count = sizeof(a)/sizeof(a[0]), .list = a
453 static const struct scanlist staScanTable[] = {
454 { IEEE80211_MODE_11B, X(rcl3) },
455 { IEEE80211_MODE_11A, X(rcl1) },
456 { IEEE80211_MODE_11A, X(rcl2) },
457 { IEEE80211_MODE_11B, X(rcl8) },
458 { IEEE80211_MODE_11B, X(rcl9) },
459 { IEEE80211_MODE_11A, X(rcl4) },
460 #ifdef ATH_TURBO_SCAN
461 { IEEE80211_MODE_STURBO_A, X(rcl5) },
462 { IEEE80211_MODE_STURBO_A, X(rcl6) },
463 { IEEE80211_MODE_TURBO_A, X(rcl6x) },
464 { IEEE80211_MODE_TURBO_A, X(rcl13) },
465 #endif /* ATH_TURBO_SCAN */
466 { IEEE80211_MODE_11A, X(rcl7) },
467 { IEEE80211_MODE_11B, X(rcl10) },
468 { IEEE80211_MODE_11A, X(rcl11) },
469 #ifdef ATH_TURBO_SCAN
470 { IEEE80211_MODE_TURBO_G, X(rcl12) },
471 #endif /* ATH_TURBO_SCAN */
476 checktable(const struct scanlist *scan, const struct ieee80211_channel *c)
480 for (; scan->list != NULL; scan++) {
481 for (i = 0; i < scan->count; i++)
482 if (scan->list[i] == c->ic_freq)
489 sweepchannels(struct ieee80211_scan_state *ss, struct ieee80211com *ic,
490 const struct scanlist table[])
492 struct ieee80211_channel *c;
496 * Add the channels from the ic (from HAL) that are not present
497 * in the staScanTable.
499 for (i = 0; i < ic->ic_nchans; i++) {
500 if (ss->ss_last >= IEEE80211_SCAN_MAX)
503 c = &ic->ic_channels[i];
505 * Ignore dynamic turbo channels; we scan them
506 * in normal mode (i.e. not boosted). Likewise
507 * for HT channels, they get scanned using
510 if (IEEE80211_IS_CHAN_DTURBO(c) || IEEE80211_IS_CHAN_HT(c))
514 * If a desired mode was specified, scan only
515 * channels that satisfy that constraint.
517 if (ic->ic_des_mode != IEEE80211_MODE_AUTO &&
518 ic->ic_des_mode != ieee80211_chan2mode(c))
522 * Skip channels excluded by user request.
524 if (isexcluded(ic, c))
528 * Add the channel unless it is listed in the
529 * fixed scan order tables. This insures we
530 * don't sweep back in channels we filtered out
533 if (checktable(table, c))
536 /* Add channel to scanning list. */
537 ss->ss_chans[ss->ss_last++] = c;
542 * Start a station-mode scan by populating the channel list.
545 sta_start(struct ieee80211_scan_state *ss, struct ieee80211com *ic)
547 #define N(a) (sizeof(a)/sizeof(a[0]))
548 struct sta_table *st = ss->ss_priv;
549 const struct scanlist *scan;
550 enum ieee80211_phymode mode;
554 * Use the table of ordered channels to construct the list
555 * of channels for scanning. Any channels in the ordered
556 * list not in the master list will be discarded.
558 for (scan = staScanTable; scan->list != NULL; scan++) {
560 if (ic->ic_des_mode != IEEE80211_MODE_AUTO) {
562 * If a desired mode was specified, scan only
563 * channels that satisfy that constraint.
565 if (ic->ic_des_mode != mode) {
567 * The scan table marks 2.4Ghz channels as b
568 * so if the desired mode is 11g, then use
569 * the 11b channel list but upgrade the mode.
571 if (ic->ic_des_mode != IEEE80211_MODE_11G ||
572 mode != IEEE80211_MODE_11B)
574 mode = IEEE80211_MODE_11G; /* upgrade */
578 * This lets add_channels upgrade an 11b channel
579 * to 11g if available.
581 if (mode == IEEE80211_MODE_11B)
582 mode = IEEE80211_MODE_AUTO;
584 #ifdef IEEE80211_F_XR
585 /* XR does not operate on turbo channels */
586 if ((ic->ic_flags & IEEE80211_F_XR) &&
587 (mode == IEEE80211_MODE_TURBO_A ||
588 mode == IEEE80211_MODE_TURBO_G ||
589 mode == IEEE80211_MODE_STURBO_A))
593 * Add the list of the channels; any that are not
594 * in the master channel list will be discarded.
596 add_channels(ic, ss, mode, scan->list, scan->count);
600 * Add the channels from the ic (from HAL) that are not present
601 * in the staScanTable.
603 sweepchannels(ss, ic, staScanTable);
607 ss->ss_mindwell = msecs_to_ticks(20); /* 20ms */
608 ss->ss_maxdwell = msecs_to_ticks(200); /* 200ms */
610 #ifdef IEEE80211_DEBUG
611 if (ieee80211_msg_scan(ic)) {
612 if_printf(ic->ic_ifp, "scan set ");
613 ieee80211_scan_dump_channels(ss);
614 printf(" dwell min %ld max %ld\n",
615 ss->ss_mindwell, ss->ss_maxdwell);
617 #endif /* IEEE80211_DEBUG */
629 sta_restart(struct ieee80211_scan_state *ss, struct ieee80211com *ic)
631 struct sta_table *st = ss->ss_priv;
638 * Cancel an ongoing scan.
641 sta_cancel(struct ieee80211_scan_state *ss, struct ieee80211com *ic)
647 maxrate(const struct ieee80211_scan_entry *se)
653 for (i = 0; i < se->se_rates[1]; i++) {
654 r = se->se_rates[2+i] & IEEE80211_RATE_VAL;
658 for (i = 0; i < se->se_xrates[1]; i++) {
659 r = se->se_xrates[2+i] & IEEE80211_RATE_VAL;
667 * Compare the capabilities of two entries and decide which is
668 * more desirable (return >0 if a is considered better). Note
669 * that we assume compatibility/usability has already been checked
670 * so we don't need to (e.g. validate whether privacy is supported).
671 * Used to select the best scan candidate for association in a BSS.
674 sta_compare(const struct sta_entry *a, const struct sta_entry *b)
676 #define PREFER(_a,_b,_what) do { \
677 if (((_a) ^ (_b)) & (_what)) \
678 return ((_a) & (_what)) ? 1 : -1; \
684 /* privacy support */
685 PREFER(a->base.se_capinfo, b->base.se_capinfo,
686 IEEE80211_CAPINFO_PRIVACY);
688 /* compare count of previous failures */
689 weight = b->se_fails - a->se_fails;
694 * Compare rssi. If the two are considered equivalent
695 * then fallback to other criteria. We threshold the
696 * comparisons to avoid selecting an ap purely by rssi
697 * when both values may be good but one ap is otherwise
698 * more desirable (e.g. an 11b-only ap with stronger
699 * signal than an 11g ap).
701 rssia = MIN(a->base.se_rssi, STA_RSSI_MAX);
702 rssib = MIN(b->base.se_rssi, STA_RSSI_MAX);
703 if (abs(rssib - rssia) < 5) {
704 /* best/max rate preferred if signal level close enough XXX */
705 maxa = maxrate(&a->base);
706 maxb = maxrate(&b->base);
709 /* XXX use freq for channel preference */
710 /* for now just prefer 5Ghz band to all other bands */
711 if (IEEE80211_IS_CHAN_5GHZ(a->base.se_chan) &&
712 !IEEE80211_IS_CHAN_5GHZ(b->base.se_chan))
714 if (!IEEE80211_IS_CHAN_5GHZ(a->base.se_chan) &&
715 IEEE80211_IS_CHAN_5GHZ(b->base.se_chan))
718 /* all things being equal, use signal level */
719 return a->base.se_rssi - b->base.se_rssi;
724 * Check rate set suitability and return the best supported rate.
727 check_rate(struct ieee80211com *ic, const struct ieee80211_scan_entry *se)
729 #define RV(v) ((v) & IEEE80211_RATE_VAL)
730 const struct ieee80211_rateset *srs;
731 int i, j, nrs, r, okrate, badrate, fixedrate;
734 okrate = badrate = fixedrate = 0;
736 srs = ieee80211_get_suprates(ic, se->se_chan);
737 nrs = se->se_rates[1];
739 fixedrate = IEEE80211_FIXED_RATE_NONE;
741 for (i = 0; i < nrs; i++) {
745 * Check any fixed rate is included.
747 if (r == ic->ic_fixed_rate)
750 * Check against our supported rates.
752 for (j = 0; j < srs->rs_nrates; j++)
753 if (r == RV(srs->rs_rates[j])) {
754 if (r > okrate) /* NB: track max */
759 if (j == srs->rs_nrates && (rs[i] & IEEE80211_RATE_BASIC)) {
761 * Don't try joining a BSS, if we don't support
762 * one of its basic rates.
768 if (rs == se->se_rates+2) {
769 /* scan xrates too; sort of an algol68-style for loop */
770 nrs = se->se_xrates[1];
771 rs = se->se_xrates+2;
776 if (okrate == 0 || ic->ic_fixed_rate != fixedrate)
777 return badrate | IEEE80211_RATE_BASIC;
784 match_ssid(const uint8_t *ie,
785 int nssid, const struct ieee80211_scan_ssid ssids[])
789 for (i = 0; i < nssid; i++) {
790 if (ie[1] == ssids[i].len &&
791 memcmp(ie+2, ssids[i].ssid, ie[1]) == 0)
798 * Test a scan candidate for suitability/compatibility.
801 match_bss(struct ieee80211com *ic,
802 const struct ieee80211_scan_state *ss, struct sta_entry *se0,
805 struct ieee80211_scan_entry *se = &se0->base;
810 if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, se->se_chan)))
811 fail |= MATCH_CHANNEL;
813 * NB: normally the desired mode is used to construct
814 * the channel list, but it's possible for the scan
815 * cache to include entries for stations outside this
816 * list so we check the desired mode here to weed them
819 if (ic->ic_des_mode != IEEE80211_MODE_AUTO &&
820 (se->se_chan->ic_flags & IEEE80211_CHAN_ALLTURBO) !=
821 chanflags[ic->ic_des_mode])
822 fail |= MATCH_CHANNEL;
823 if (ic->ic_opmode == IEEE80211_M_IBSS) {
824 if ((se->se_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
825 fail |= MATCH_CAPINFO;
827 if ((se->se_capinfo & IEEE80211_CAPINFO_ESS) == 0)
828 fail |= MATCH_CAPINFO;
830 if (ic->ic_flags & IEEE80211_F_PRIVACY) {
831 if ((se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
832 fail |= MATCH_PRIVACY;
834 /* XXX does this mean privacy is supported or required? */
835 if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY)
836 fail |= MATCH_PRIVACY;
838 rate = check_rate(ic, se);
839 if (rate & IEEE80211_RATE_BASIC)
841 if (ss->ss_nssid != 0 &&
842 !match_ssid(se->se_ssid, ss->ss_nssid, ss->ss_ssid))
844 if ((ic->ic_flags & IEEE80211_F_DESBSSID) &&
845 !IEEE80211_ADDR_EQ(ic->ic_des_bssid, se->se_bssid))
847 if (se0->se_fails >= STA_FAILS_MAX)
849 /* NB: entries may be present awaiting purge, skip */
850 if (se0->se_notseen >= STA_PURGE_SCANS)
851 fail |= MATCH_NOTSEEN;
852 if (se->se_rssi < STA_RSSI_MIN)
854 #ifdef IEEE80211_DEBUG
855 if (ieee80211_msg(ic, debug)) {
857 fail & MATCH_FAILS ? '=' :
858 fail & MATCH_NOTSEEN ? '^' :
859 fail ? '-' : '+', ether_sprintf(se->se_macaddr));
860 printf(" %s%c", ether_sprintf(se->se_bssid),
861 fail & MATCH_BSSID ? '!' : ' ');
862 printf(" %3d%c", ieee80211_chan2ieee(ic, se->se_chan),
863 fail & MATCH_CHANNEL ? '!' : ' ');
864 printf(" %+4d%c", se->se_rssi, fail & MATCH_RSSI ? '!' : ' ');
865 printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2,
866 fail & MATCH_RATE ? '!' : ' ');
868 (se->se_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
869 (se->se_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
871 fail & MATCH_CAPINFO ? '!' : ' ');
873 (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) ?
875 fail & MATCH_PRIVACY ? '!' : ' ');
876 ieee80211_print_essid(se->se_ssid+2, se->se_ssid[1]);
877 printf("%s\n", fail & MATCH_SSID ? "!" : "");
884 sta_update_notseen(struct sta_table *st)
886 struct sta_entry *se;
888 mtx_lock(&st->st_lock);
889 TAILQ_FOREACH(se, &st->st_entry, se_list) {
891 * If seen the reset and don't bump the count;
892 * otherwise bump the ``not seen'' count. Note
893 * that this insures that stations for which we
894 * see frames while not scanning but not during
895 * this scan will not be penalized.
902 mtx_unlock(&st->st_lock);
906 sta_dec_fails(struct sta_table *st)
908 struct sta_entry *se;
910 mtx_lock(&st->st_lock);
911 TAILQ_FOREACH(se, &st->st_entry, se_list)
914 mtx_unlock(&st->st_lock);
917 static struct sta_entry *
918 select_bss(struct ieee80211_scan_state *ss, struct ieee80211com *ic, int debug)
920 struct sta_table *st = ss->ss_priv;
921 struct sta_entry *se, *selbs = NULL;
923 IEEE80211_DPRINTF(ic, debug, " %s\n",
924 "macaddr bssid chan rssi rate flag wep essid");
925 mtx_lock(&st->st_lock);
926 TAILQ_FOREACH(se, &st->st_entry, se_list) {
927 if (match_bss(ic, ss, se, debug) == 0) {
930 else if (sta_compare(se, selbs) > 0)
934 mtx_unlock(&st->st_lock);
940 * Pick an ap or ibss network to join or find a channel
941 * to use to start an ibss network.
944 sta_pick_bss(struct ieee80211_scan_state *ss, struct ieee80211com *ic)
946 struct sta_table *st = ss->ss_priv;
947 struct sta_entry *selbs;
949 KASSERT(ic->ic_opmode == IEEE80211_M_STA,
950 ("wrong mode %u", ic->ic_opmode));
952 if (st->st_newscan) {
953 sta_update_notseen(st);
956 if (ss->ss_flags & IEEE80211_SCAN_NOPICK) {
958 * Manual/background scan, don't select+join the
959 * bss, just return. The scanning framework will
960 * handle notification that this has completed.
962 ss->ss_flags &= ~IEEE80211_SCAN_NOPICK;
966 * Automatic sequencing; look for a candidate and
967 * if found join the network.
969 /* NB: unlocked read should be ok */
970 if (TAILQ_FIRST(&st->st_entry) == NULL) {
971 IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN,
972 "%s: no scan candidate\n", __func__);
975 * If nothing suitable was found decrement
976 * the failure counts so entries will be
977 * reconsidered the next time around. We
978 * really want to do this only for sta's
979 * where we've previously had some success.
983 return 0; /* restart scan */
985 selbs = select_bss(ss, ic, IEEE80211_MSG_SCAN);
986 if (selbs == NULL || !ieee80211_sta_join(ic, &selbs->base))
988 return 1; /* terminate scan */
992 * Lookup an entry in the scan cache. We assume we're
993 * called from the bottom half or such that we don't need
994 * to block the bottom half so that it's safe to return
995 * a reference to an entry w/o holding the lock on the table.
997 static struct sta_entry *
998 sta_lookup(struct sta_table *st, const uint8_t macaddr[IEEE80211_ADDR_LEN])
1000 struct sta_entry *se;
1001 int hash = STA_HASH(macaddr);
1003 mtx_lock(&st->st_lock);
1004 LIST_FOREACH(se, &st->st_hash[hash], se_hash)
1005 if (IEEE80211_ADDR_EQ(se->base.se_macaddr, macaddr))
1007 mtx_unlock(&st->st_lock);
1009 return se; /* NB: unlocked */
1013 sta_roam_check(struct ieee80211_scan_state *ss, struct ieee80211com *ic)
1015 struct ieee80211_node *ni = ic->ic_bss;
1016 struct sta_table *st = ss->ss_priv;
1017 struct sta_entry *se, *selbs;
1018 uint8_t roamRate, curRate;
1019 int8_t roamRssi, curRssi;
1021 se = sta_lookup(st, ni->ni_macaddr);
1023 /* XXX something is wrong */
1027 /* XXX do we need 11g too? */
1028 if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan)) {
1029 roamRate = ic->ic_roam.rate11b;
1030 roamRssi = ic->ic_roam.rssi11b;
1031 } else if (IEEE80211_IS_CHAN_B(ic->ic_bsschan)) {
1032 roamRate = ic->ic_roam.rate11bOnly;
1033 roamRssi = ic->ic_roam.rssi11bOnly;
1035 roamRate = ic->ic_roam.rate11a;
1036 roamRssi = ic->ic_roam.rssi11a;
1038 /* NB: the most up to date rssi is in the node, not the scan cache */
1039 curRssi = ic->ic_node_getrssi(ni);
1040 if (ic->ic_fixed_rate == IEEE80211_FIXED_RATE_NONE) {
1041 curRate = ni->ni_rates.rs_rates[ni->ni_txrate] & IEEE80211_RATE_VAL;
1042 IEEE80211_DPRINTF(ic, IEEE80211_MSG_ROAM,
1043 "%s: currssi %d currate %u roamrssi %d roamrate %u\n",
1044 __func__, curRssi, curRate, roamRssi, roamRate);
1046 curRate = roamRate; /* NB: insure compare below fails */
1047 IEEE80211_DPRINTF(ic, IEEE80211_MSG_ROAM,
1048 "%s: currssi %d roamrssi %d\n", __func__, curRssi, roamRssi);
1051 * Check if a new ap should be used and switch.
1052 * XXX deauth current ap
1054 if (curRate < roamRate || curRssi < roamRssi) {
1055 if (time_after(ticks, ic->ic_lastscan + ic->ic_scanvalid)) {
1057 * Scan cache contents are too old; force a scan now
1058 * if possible so we have current state to make a
1059 * decision with. We don't kick off a bg scan if
1060 * we're using dynamic turbo and boosted or if the
1062 * XXX force immediate switch on scan complete
1064 if (!IEEE80211_IS_CHAN_DTURBO(ic->ic_curchan) &&
1065 time_after(ticks, ic->ic_lastdata + ic->ic_bgscanidle))
1066 ieee80211_bg_scan(ic);
1069 se->base.se_rssi = curRssi;
1070 selbs = select_bss(ss, ic, IEEE80211_MSG_ROAM);
1071 if (selbs != NULL && selbs != se) {
1072 IEEE80211_DPRINTF(ic,
1073 IEEE80211_MSG_ROAM | IEEE80211_MSG_DEBUG,
1074 "%s: ROAM: curRate %u, roamRate %u, "
1075 "curRssi %d, roamRssi %d\n", __func__,
1076 curRate, roamRate, curRssi, roamRssi);
1077 ieee80211_sta_join(ic, &selbs->base);
1083 * Age entries in the scan cache.
1084 * XXX also do roaming since it's convenient
1087 sta_age(struct ieee80211_scan_state *ss)
1089 struct ieee80211com *ic = ss->ss_ic;
1090 struct sta_table *st = ss->ss_priv;
1091 struct sta_entry *se, *next;
1093 mtx_lock(&st->st_lock);
1094 TAILQ_FOREACH_SAFE(se, &st->st_entry, se_list, next) {
1095 if (se->se_notseen > STA_PURGE_SCANS) {
1096 TAILQ_REMOVE(&st->st_entry, se, se_list);
1097 LIST_REMOVE(se, se_hash);
1098 FREE(se, M_80211_SCAN);
1101 mtx_unlock(&st->st_lock);
1103 * If rate control is enabled check periodically to see if
1104 * we should roam from our current connection to one that
1105 * might be better. This only applies when we're operating
1106 * in sta mode and automatic roaming is set.
1108 * XXX repeater station
1109 * XXX do when !bgscan?
1111 KASSERT(ic->ic_opmode == IEEE80211_M_STA,
1112 ("wrong mode %u", ic->ic_opmode));
1113 if (ic->ic_roaming == IEEE80211_ROAMING_AUTO &&
1114 (ic->ic_flags & IEEE80211_F_BGSCAN) &&
1115 ic->ic_state >= IEEE80211_S_RUN)
1116 /* XXX vap is implicit */
1117 sta_roam_check(ss, ic);
1121 * Iterate over the entries in the scan cache, invoking
1122 * the callback function on each one.
1125 sta_iterate(struct ieee80211_scan_state *ss,
1126 ieee80211_scan_iter_func *f, void *arg)
1128 struct sta_table *st = ss->ss_priv;
1129 struct sta_entry *se;
1132 mtx_lock(&st->st_scanlock);
1133 gen = st->st_scangen++;
1135 mtx_lock(&st->st_lock);
1136 TAILQ_FOREACH(se, &st->st_entry, se_list) {
1137 if (se->se_scangen != gen) {
1138 se->se_scangen = gen;
1139 /* update public state */
1140 se->base.se_age = ticks - se->se_lastupdate;
1141 mtx_unlock(&st->st_lock);
1142 (*f)(arg, &se->base);
1146 mtx_unlock(&st->st_lock);
1148 mtx_unlock(&st->st_scanlock);
1152 sta_assoc_fail(struct ieee80211_scan_state *ss,
1153 const uint8_t macaddr[IEEE80211_ADDR_LEN], int reason)
1155 struct sta_table *st = ss->ss_priv;
1156 struct sta_entry *se;
1158 se = sta_lookup(st, macaddr);
1161 se->se_lastfail = ticks;
1162 IEEE80211_NOTE_MAC(ss->ss_ic, IEEE80211_MSG_SCAN,
1163 macaddr, "%s: reason %u fails %u",
1164 __func__, reason, se->se_fails);
1169 sta_assoc_success(struct ieee80211_scan_state *ss,
1170 const uint8_t macaddr[IEEE80211_ADDR_LEN])
1172 struct sta_table *st = ss->ss_priv;
1173 struct sta_entry *se;
1175 se = sta_lookup(st, macaddr);
1179 IEEE80211_NOTE_MAC(ss->ss_ic, IEEE80211_MSG_SCAN,
1180 macaddr, "%s: fails %u",
1181 __func__, se->se_fails);
1183 se->se_lastassoc = ticks;
1187 static const struct ieee80211_scanner sta_default = {
1188 .scan_name = "default",
1189 .scan_attach = sta_attach,
1190 .scan_detach = sta_detach,
1191 .scan_start = sta_start,
1192 .scan_restart = sta_restart,
1193 .scan_cancel = sta_cancel,
1194 .scan_end = sta_pick_bss,
1195 .scan_flush = sta_flush,
1196 .scan_add = sta_add,
1197 .scan_age = sta_age,
1198 .scan_iterate = sta_iterate,
1199 .scan_assoc_fail = sta_assoc_fail,
1200 .scan_assoc_success = sta_assoc_success,
1204 * Adhoc mode-specific support.
1207 static const uint16_t adhocWorld[] = /* 36, 40, 44, 48 */
1208 { 5180, 5200, 5220, 5240 };
1209 static const uint16_t adhocFcc3[] = /* 36, 40, 44, 48 145, 149, 153, 157, 161, 165 */
1210 { 5180, 5200, 5220, 5240, 5725, 5745, 5765, 5785, 5805, 5825 };
1211 static const uint16_t adhocMkk[] = /* 34, 38, 42, 46 */
1212 { 5170, 5190, 5210, 5230 };
1213 static const uint16_t adhoc11b[] = /* 10, 11 */
1216 static const struct scanlist adhocScanTable[] = {
1217 { IEEE80211_MODE_11B, X(adhoc11b) },
1218 { IEEE80211_MODE_11A, X(adhocWorld) },
1219 { IEEE80211_MODE_11A, X(adhocFcc3) },
1220 { IEEE80211_MODE_11B, X(adhocMkk) },
1226 * Start an adhoc-mode scan by populating the channel list.
1229 adhoc_start(struct ieee80211_scan_state *ss, struct ieee80211com *ic)
1231 #define N(a) (sizeof(a)/sizeof(a[0]))
1232 struct sta_table *st = ss->ss_priv;
1233 const struct scanlist *scan;
1234 enum ieee80211_phymode mode;
1238 * Use the table of ordered channels to construct the list
1239 * of channels for scanning. Any channels in the ordered
1240 * list not in the master list will be discarded.
1242 for (scan = adhocScanTable; scan->list != NULL; scan++) {
1244 if (ic->ic_des_mode != IEEE80211_MODE_AUTO) {
1246 * If a desired mode was specified, scan only
1247 * channels that satisfy that constraint.
1249 if (ic->ic_des_mode != mode) {
1251 * The scan table marks 2.4Ghz channels as b
1252 * so if the desired mode is 11g, then use
1253 * the 11b channel list but upgrade the mode.
1255 if (ic->ic_des_mode != IEEE80211_MODE_11G ||
1256 mode != IEEE80211_MODE_11B)
1258 mode = IEEE80211_MODE_11G; /* upgrade */
1262 * This lets add_channels upgrade an 11b channel
1263 * to 11g if available.
1265 if (mode == IEEE80211_MODE_11B)
1266 mode = IEEE80211_MODE_AUTO;
1268 #ifdef IEEE80211_F_XR
1269 /* XR does not operate on turbo channels */
1270 if ((ic->ic_flags & IEEE80211_F_XR) &&
1271 (mode == IEEE80211_MODE_TURBO_A ||
1272 mode == IEEE80211_MODE_TURBO_G))
1276 * Add the list of the channels; any that are not
1277 * in the master channel list will be discarded.
1279 add_channels(ic, ss, mode, scan->list, scan->count);
1283 * Add the channels from the ic (from HAL) that are not present
1284 * in the staScanTable.
1286 sweepchannels(ss, ic, adhocScanTable);
1290 ss->ss_mindwell = msecs_to_ticks(200); /* 200ms */
1291 ss->ss_maxdwell = msecs_to_ticks(200); /* 200ms */
1293 #ifdef IEEE80211_DEBUG
1294 if (ieee80211_msg_scan(ic)) {
1295 if_printf(ic->ic_ifp, "scan set ");
1296 ieee80211_scan_dump_channels(ss);
1297 printf(" dwell min %ld max %ld\n",
1298 ss->ss_mindwell, ss->ss_maxdwell);
1300 #endif /* IEEE80211_DEBUG */
1309 * Select a channel to start an adhoc network on.
1310 * The channel list was populated with appropriate
1311 * channels so select one that looks least occupied.
1312 * XXX need regulatory domain constraints
1314 static struct ieee80211_channel *
1315 adhoc_pick_channel(struct ieee80211_scan_state *ss)
1317 struct sta_table *st = ss->ss_priv;
1318 struct sta_entry *se;
1319 struct ieee80211_channel *c, *bestchan;
1320 int i, bestrssi, maxrssi;
1325 mtx_lock(&st->st_lock);
1326 for (i = 0; i < ss->ss_last; i++) {
1327 c = ss->ss_chans[i];
1328 if (!checktable(adhocScanTable, c))
1331 TAILQ_FOREACH(se, &st->st_entry, se_list) {
1332 if (se->base.se_chan != c)
1334 if (se->base.se_rssi > maxrssi)
1335 maxrssi = se->base.se_rssi;
1337 if (bestchan == NULL || maxrssi < bestrssi)
1340 mtx_unlock(&st->st_lock);
1346 * Pick an ibss network to join or find a channel
1347 * to use to start an ibss network.
1350 adhoc_pick_bss(struct ieee80211_scan_state *ss, struct ieee80211com *ic)
1352 struct sta_table *st = ss->ss_priv;
1353 struct sta_entry *selbs;
1354 struct ieee80211_channel *chan;
1356 KASSERT(ic->ic_opmode == IEEE80211_M_IBSS ||
1357 ic->ic_opmode == IEEE80211_M_AHDEMO,
1358 ("wrong opmode %u", ic->ic_opmode));
1360 if (st->st_newscan) {
1361 sta_update_notseen(st);
1364 if (ss->ss_flags & IEEE80211_SCAN_NOPICK) {
1366 * Manual/background scan, don't select+join the
1367 * bss, just return. The scanning framework will
1368 * handle notification that this has completed.
1370 ss->ss_flags &= ~IEEE80211_SCAN_NOPICK;
1374 * Automatic sequencing; look for a candidate and
1375 * if found join the network.
1377 /* NB: unlocked read should be ok */
1378 if (TAILQ_FIRST(&st->st_entry) == NULL) {
1379 IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN,
1380 "%s: no scan candidate\n", __func__);
1382 if (ic->ic_des_nssid) {
1384 * No existing adhoc network to join and we have
1385 * an ssid; start one up. If no channel was
1386 * specified, try to select a channel.
1388 if (ic->ic_des_chan == IEEE80211_CHAN_ANYC)
1389 chan = ieee80211_ht_adjust_channel(ic,
1390 adhoc_pick_channel(ss), ic->ic_flags_ext);
1392 chan = ic->ic_des_chan;
1394 ieee80211_create_ibss(ic, chan);
1399 * If nothing suitable was found decrement
1400 * the failure counts so entries will be
1401 * reconsidered the next time around. We
1402 * really want to do this only for sta's
1403 * where we've previously had some success.
1407 return 0; /* restart scan */
1409 selbs = select_bss(ss, ic, IEEE80211_MSG_SCAN);
1410 if (selbs == NULL || !ieee80211_sta_join(ic, &selbs->base))
1412 return 1; /* terminate scan */
1416 * Age entries in the scan cache.
1419 adhoc_age(struct ieee80211_scan_state *ss)
1421 struct sta_table *st = ss->ss_priv;
1422 struct sta_entry *se, *next;
1424 mtx_lock(&st->st_lock);
1425 TAILQ_FOREACH_SAFE(se, &st->st_entry, se_list, next) {
1426 if (se->se_notseen > STA_PURGE_SCANS) {
1427 TAILQ_REMOVE(&st->st_entry, se, se_list);
1428 LIST_REMOVE(se, se_hash);
1429 FREE(se, M_80211_SCAN);
1432 mtx_unlock(&st->st_lock);
1435 static const struct ieee80211_scanner adhoc_default = {
1436 .scan_name = "default",
1437 .scan_attach = sta_attach,
1438 .scan_detach = sta_detach,
1439 .scan_start = adhoc_start,
1440 .scan_restart = sta_restart,
1441 .scan_cancel = sta_cancel,
1442 .scan_end = adhoc_pick_bss,
1443 .scan_flush = sta_flush,
1444 .scan_add = sta_add,
1445 .scan_age = adhoc_age,
1446 .scan_iterate = sta_iterate,
1447 .scan_assoc_fail = sta_assoc_fail,
1448 .scan_assoc_success = sta_assoc_success,
1455 wlan_modevent(module_t mod, int type, void *unused)
1459 ieee80211_scanner_register(IEEE80211_M_STA, &sta_default);
1460 ieee80211_scanner_register(IEEE80211_M_IBSS, &adhoc_default);
1461 ieee80211_scanner_register(IEEE80211_M_AHDEMO, &adhoc_default);
1466 printf("wlan_scan_sta: still in use (%u dynamic refs)\n",
1470 if (type == MOD_UNLOAD) {
1471 ieee80211_scanner_unregister_all(&sta_default);
1472 ieee80211_scanner_unregister_all(&adhoc_default);
1479 static moduledata_t wlan_mod = {
1484 DECLARE_MODULE(wlan_scan_sta, wlan_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
1485 MODULE_VERSION(wlan_scan_sta, 1);
1486 MODULE_DEPEND(wlan_scan_sta, wlan, 1, 1, 1);