📄 ieee80211_scan.c.svn-base
字号:
*/ if (((SCAN_PRIVATE(ss)->ss_iflags & ISCAN_CANCEL) == 0) && !ss->ss_ops->scan_end(ss, vap, NULL, 0) && ((ss->ss_flags & IEEE80211_SCAN_ONCE) == 0) && time_before(jiffies + ss->ss_mindwell, scanend)) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s: done, restart " "[jiffies %lu, dwell min %lu scanend %lu]\n", __func__, jiffies, ss->ss_mindwell, scanend); ss->ss_next = 0; /* reset to beginning */ if (ss->ss_flags & IEEE80211_SCAN_ACTIVE) vap->iv_stats.is_scan_active++; else vap->iv_stats.is_scan_passive++; ic->ic_scan_start(ic); /* notify driver */ goto again; } else { if ((ss->ss_flags & IEEE80211_SCAN_BGSCAN) == 0) scandone = 1; IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s: %s, " "[jiffies %lu, dwell min %lu scanend %lu]\n", __func__, scandone ? "done" : "stopped", jiffies, ss->ss_mindwell, scanend); /* * Clear the SCAN bit first in case frames are * pending on the station power save queue. If * we defer this then the dispatch of the frames * may generate a request to cancel scanning. */ ic->ic_flags &= ~IEEE80211_F_SCAN; /* * Drop out of power save mode when a scan has * completed. If this scan was prematurely terminated * because it is a background scan then don't notify * the ap; we'll either return to scanning after we * receive the beacon frame or we'll drop out of power * save mode because the beacon indicates we have frames * waiting for us. */ if (scandone) { ieee80211_sta_pwrsave(vap, 0); if (ss->ss_next >= ss->ss_last) { ieee80211_notify_scan_done(vap); ic->ic_flags_ext &= ~IEEE80211_FEXT_BGSCAN; } } SCAN_PRIVATE(ss)->ss_iflags &= ~ISCAN_CANCEL; ss->ss_flags &= ~(IEEE80211_SCAN_ONCE | IEEE80211_SCAN_PICK1ST); } }#undef ISCAN_REP}#ifdef IEEE80211_DEBUGstatic voiddump_probe_beacon(u_int8_t subtype, int isnew, const u_int8_t mac[IEEE80211_ADDR_LEN], const struct ieee80211_scanparams *sp){ printk("[" MAC_FMT "] %s%s on chan %u (bss chan %u) ", MAC_ADDR(mac), isnew ? "new " : "", ieee80211_mgt_subtype_name[subtype >> IEEE80211_FC0_SUBTYPE_SHIFT], sp->chan, sp->bchan); ieee80211_print_essid(sp->ssid + 2, sp->ssid[1]); printk("\n"); if (isnew) { printk("[" MAC_FMT "] caps 0x%x bintval %u erp 0x%x", MAC_ADDR(mac), sp->capinfo, sp->bintval, sp->erp); if (sp->country != NULL) {#ifdef __FreeBSD__ printk(" country info %*D", sp->country[1], sp->country + 2, " ");#else int i; printk(" country info"); for (i = 0; i < sp->country[1]; i++) printk(" %02x", sp->country[i + 2]);#endif } printk("\n"); }}#endif /* IEEE80211_DEBUG *//* * Process a beacon or probe response frame. */voidieee80211_add_scan(struct ieee80211vap *vap, const struct ieee80211_scanparams *sp, const struct ieee80211_frame *wh, int subtype, int rssi, u_int64_t rtsf){ struct ieee80211com *ic = vap->iv_ic; struct ieee80211_scan_state *ss = ic->ic_scan; /* * Frames received during startup are discarded to avoid * using scan state setup on the initial entry to the timer * callback. This can occur because the device may enable * rx prior to our doing the initial channel change in the * timer routine (we defer the channel change to the timer * code to simplify locking on linux). */ if (SCAN_PRIVATE(ss)->ss_iflags & ISCAN_DISCARD) return;#ifdef IEEE80211_DEBUG if (ieee80211_msg_scan(vap) && (ic->ic_flags & IEEE80211_F_SCAN)) dump_probe_beacon(subtype, 1, wh->i_addr2, sp);#endif if (ss->ss_ops != NULL && ss->ss_ops->scan_add(ss, sp, wh, subtype, rssi, rtsf)) { /* * If we've reached the min dwell time terminate * the timer so we'll switch to the next channel. */ if ((SCAN_PRIVATE(ss)->ss_iflags & ISCAN_MINDWELL) == 0 && time_after_eq(jiffies, SCAN_PRIVATE(ss)->ss_chanmindwell)) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s: chan %3d%c min dwell met (%lu > %lu)\n", __func__, ieee80211_chan2ieee(ic, ic->ic_curchan), channel_type(ic->ic_curchan), jiffies, SCAN_PRIVATE(ss)->ss_chanmindwell); /* * XXX * We want to just kick the timer and still * process frames until it fires but linux * will livelock unless we discard frames. */#if 0 SCAN_PRIVATE(ss)->ss_iflags |= ISCAN_MINDWELL;#else SCAN_PRIVATE(ss)->ss_iflags |= ISCAN_DISCARD;#endif /* NB: trigger at next clock tick */ mod_timer(&SCAN_PRIVATE(ss)->ss_scan_timer, jiffies); } }}/* * Timeout/age scan cache entries; called from sta timeout * timer (XXX should be self-contained). */voidieee80211_scan_timeout(struct ieee80211com *ic){ struct ieee80211_scan_state *ss = ic->ic_scan; if (ss->ss_ops != NULL) ss->ss_ops->scan_age(ss);}/* * Mark a scan cache entry after a successful associate. */voidieee80211_scan_assoc_success(struct ieee80211com *ic, const u_int8_t mac[]){ struct ieee80211_scan_state *ss = ic->ic_scan; if (ss->ss_ops != NULL) { IEEE80211_NOTE_MAC(ss->ss_vap, IEEE80211_MSG_SCAN, mac, "%s", __func__); ss->ss_ops->scan_assoc_success(ss, mac); }}/* * Demerit a scan cache entry after failing to associate. */voidieee80211_scan_assoc_fail(struct ieee80211com *ic, const u_int8_t mac[], int reason){ struct ieee80211_scan_state *ss = ic->ic_scan; if (ss->ss_ops != NULL) { IEEE80211_NOTE_MAC(ss->ss_vap, IEEE80211_MSG_SCAN, mac, "%s: reason %u", __func__, reason); ss->ss_ops->scan_assoc_fail(ss, mac, reason); }}/* * Iterate over the contents of the scan cache. */intieee80211_scan_iterate(struct ieee80211com *ic, ieee80211_scan_iter_func *f, void *arg){ int res = 0; struct ieee80211_scan_state *ss = ic->ic_scan; if (ss->ss_ops != NULL) { res = ss->ss_ops->scan_iterate(ss, f, arg); } return res;}/* * Flush the contents of the scan cache. */voidieee80211_scan_flush(struct ieee80211com *ic){ struct ieee80211_scan_state *ss = ic->ic_scan; if (ss->ss_ops != NULL) { IEEE80211_DPRINTF(ss->ss_vap, IEEE80211_MSG_SCAN, "%s\n", __func__); ss->ss_ops->scan_flush(ss); }}/* * Execute radar channel change. This is called when a radar/dfs * signal is detected. AP mode only. Return 1 on success, 0 on * failure */intieee80211_scan_dfs_action(struct ieee80211vap *vap, const struct ieee80211_scan_entry *se){ struct ieee80211com *ic = vap->iv_ic; struct ieee80211_channel *new_channel = NULL; if (!IEEE80211_IS_MODE_DFS_MASTER(vap->iv_opmode)) return 0; if (se != NULL) { new_channel = se->se_chan; if (new_channel != NULL) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: new channel found in scan cache\n", __func__); } } else { /* No channel was found via scan module, means no good scanlist * was found */ int chanStart, i, count; u_int32_t curChanFlags; if ((ic->ic_curchan != NULL) && (ic->ic_curchan != IEEE80211_CHAN_ANYC)) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: ic_curchan is %3d (%4d MHz)\n", __func__, ic->ic_curchan->ic_ieee, ic->ic_curchan->ic_freq); } if ((ic->ic_bsschan != NULL) && (ic->ic_bsschan != IEEE80211_CHAN_ANYC)) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: ic_bsschan is %3d (%4d MHz)\n", __func__, ic->ic_bsschan->ic_ieee, ic->ic_bsschan->ic_freq); } /* According to FCC/ETSI rules on uniform spreading, we shall * select a channel out of the list of usable channels so that * the probability of selecting a given channel shall be the * same for all channels (reference: ETSI 301 893 v1.3.1 * $4.6.2.5.1 */ /* First, we count the usable channels */ count = 0; curChanFlags = (ic->ic_bsschan->ic_flags) & ~(IEEE80211_CHAN_RADAR); for (i = 0; i < ic->ic_nchans; i++) { if ((ic->ic_channels[i].ic_ieee != ic->ic_bsschan->ic_ieee) && (ic->ic_channels[i].ic_flags == curChanFlags)) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: usable channel %3d " "(%4d MHz)\n", __func__, ic->ic_channels[i].ic_ieee, ic->ic_channels[i].ic_freq); count ++; } } if (count != 0) { /* Next, we pickup a random usable channel */ chanStart = jiffies % count; count = 0; for (i = 0; i < ic->ic_nchans; i++) { if ((ic->ic_channels[i].ic_ieee != ic->ic_bsschan->ic_ieee) && (ic->ic_channels[i].ic_flags == curChanFlags)) { if (count++ == chanStart) { new_channel = &ic->ic_channels[i]; break; } } } } if (new_channel != NULL) IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: new random channel found %3d " "(%4d MHz)\n", __func__, new_channel->ic_ieee, new_channel->ic_freq); } if (!new_channel) { /* Search for the first channel with no radar detected */ int n = 0; for (n = 0; n < ic->ic_nchans; n++) { if (0 == (ic->ic_channels[n].ic_flags & IEEE80211_CHAN_RADAR)) { new_channel = &ic->ic_channels[n]; break; } } if (new_channel != NULL) IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: new non-radar channel found\n", __func__); } if (new_channel != NULL) { /* A suitable scan entry was found, so change channels */ if (vap->iv_state == IEEE80211_S_RUN) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: CSA switching to channel %3d (%4d MHz)\n", __func__, new_channel->ic_ieee, new_channel->ic_freq); ic->ic_chanchange_chan = new_channel->ic_ieee; ic->ic_chanchange_tbtt = IEEE80211_RADAR_CHANCHANGE_TBTT_COUNT; ic->ic_flags |= IEEE80211_F_CHANSWITCH; } else { IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: directly switching to channel " "%3d (%4d MHz)\n", __func__, new_channel->ic_ieee, new_channel->ic_freq); /* VAP is not in run state yet. so * change the channel here. */ change_channel(ic, new_channel); ic->ic_bsschan = new_channel; if (vap->iv_bss) vap->iv_bss->ni_chan = new_channel; } } else { /* A suitable scan entry was not found */ IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOTH, "%s: new channel not found\n", __func__); return 0; } return 1;}EXPORT_SYMBOL(ieee80211_scan_dfs_action);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -