/* * Copyright (c) 2014 Qualcomm Atheros, Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include"ath9k.h"
/* Set/change channels. If the channel is really being changed, it's done * by resetting the chip. To accomplish this we must first cleanup any pending * DMA, then restart stuff.
*/ staticint ath_set_channel(struct ath_softc *sc)
{ struct ath_hw *ah = sc->sc_ah; struct ath_common *common = ath9k_hw_common(ah); struct ieee80211_hw *hw = sc->hw; struct ath9k_channel *hchan; struct cfg80211_chan_def *chandef = &sc->cur_chan->chandef; struct ieee80211_channel *chan = chandef->chan; int pos = chan->hw_value; unsignedlong flags; int old_pos = -1; int r;
if (test_bit(ATH_OP_INVALID, &common->op_flags)) return -EIO;
if (ah->curchan)
old_pos = ah->curchan - &ah->channels[0];
/* update survey stats for the old channel before switching */
spin_lock_irqsave(&common->cc_lock, flags);
ath_update_survey_stats(sc);
spin_unlock_irqrestore(&common->cc_lock, flags);
ath9k_cmn_get_channel(hw, ah, chandef);
/* If the operating channel changes, change the survey in-use flags * along with it. * Reset the survey data for the new channel, unless we're switching * back to the operating channel from an off-channel operation.
*/ if (!sc->cur_chan->offchannel && sc->cur_survey != &sc->survey[pos]) { if (sc->cur_survey)
sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
hchan = &sc->sc_ah->channels[pos];
r = ath_reset(sc, hchan); if (r) return r;
/* The most recent snapshot of channel->noisefloor for the old * channel is only available after the hardware reset. Copy it to * the survey stats now.
*/ if (old_pos >= 0)
ath_update_survey_nf(sc, old_pos);
/* Enable radar pulse detection if on a DFS channel. Spectral * scanning and radar detection can not be used concurrently.
*/ if (hw->conf.radar_enabled) {
u32 rxfilter;
/**********************************************************/ /* Functions to handle the channel context state machine. */ /**********************************************************/
switch (vif->type) { case NL80211_IFTYPE_P2P_CLIENT: case NL80211_IFTYPE_STATION: if (avp->assoc)
active = true; break; default:
active = true; break;
}
}
ctx->active = active;
ath_for_each_chanctx(sc, ctx) { if (!ctx->assigned || list_empty(&ctx->vifs)) continue;
n_active++;
}
/* Adjust the TSF time of the AP chanctx to keep its beacons * at half beacon interval offset relative to the STA chanctx.
*/
offset = cur_tsf - prev_tsf;
/* Ignore stale data or spurious timestamps */ if (offset < 0 || offset > 3 * beacon_int) return;
/* Configure the TSF based hardware timer for a channel switch. * Also set up backup software timer, in case the gen timer fails. * This could be caused by a hardware reset.
*/ staticvoid ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time)
{ struct ath_common *common = ath9k_hw_common(sc->sc_ah); struct ath_hw *ah = sc->sc_ah; unsignedlong timeout;
staticvoid ath_chanctx_handle_bmiss(struct ath_softc *sc, struct ath_chanctx *ctx, struct ath_vif *avp)
{ /* * Clear the extend_absence flag if it had been * set during the previous beacon transmission, * since we need to revert to the normal NoA * schedule.
*/ if (ctx->active && sc->sched.extend_absence) {
avp->noa_duration = 0;
sc->sched.extend_absence = false;
}
/* If at least two consecutive beacons were missed on the STA * chanctx, stay on the STA channel for one extra beacon period, * to resync the timer properly.
*/ if (ctx->active && sc->sched.beacon_miss >= 2) {
avp->noa_duration = 0;
sc->sched.extend_absence = true;
}
}
/* * When multiple contexts are active, the NoA * has to be recalculated and advertised after * an offchannel operation.
*/ if (ctx->active && avp->noa_duration)
avp->noa_duration = 0;
}
ctx = ath_chanctx_get_next(sc, sc->cur_chan); if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) {
sc->next_chan = ctx;
sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
ath_dbg(common, CHAN_CTX, "Set next context, move chanctx state to WAIT_FOR_BEACON\n");
}
/* if the timer missed its window, use the next interval */ if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER) {
sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
ath_dbg(common, CHAN_CTX, "Move chanctx state from WAIT_FOR_TIMER to WAIT_FOR_BEACON\n");
}
if (sc->sched.mgd_prepare_tx)
sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
/* * When a context becomes inactive, for example, * disassociation of a station context, the NoA * attribute needs to be removed from subsequent * beacons.
*/ if (!ctx->active && avp->noa_duration &&
sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) {
avp->noa_duration = 0;
avp->periodic_noa = false;
/* * If an offchannel switch is scheduled to happen after * a beacon transmission, update the NoA with one-shot * values and increment the index.
*/ if (sc->next_chan == &sc->offchannel.chan) {
ath_chanctx_offchannel_noa(sc, ctx, avp, tsf_time); break;
}
ath_chanctx_handle_bmiss(sc, ctx, avp);
/* * If a mgd_prepare_tx() has been called by mac80211, * a one-shot NoA needs to be sent. This can happen * with one or more active channel contexts - in both * cases, a new NoA schedule has to be advertised.
*/ if (sc->sched.mgd_prepare_tx) {
ath_chanctx_set_oneshot_noa(sc, avp, tsf_time,
jiffies_to_usecs(HZ / 5)); break;
}
/* * If multiple contexts are active, start periodic * NoA and increment the index for the first * announcement.
*/ if (ctx->active &&
(!avp->noa_duration || sc->sched.force_noa_update))
ath_chanctx_set_periodic_noa(sc, avp, cur_conf,
tsf_time, beacon_int);
if (ctx->active && sc->sched.force_noa_update)
sc->sched.force_noa_update = false;
break; case ATH_CHANCTX_EVENT_BEACON_SENT: if (!sc->sched.beacon_pending) {
ath_dbg(common, CHAN_CTX, "No pending beacon\n"); break;
}
if (sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
!sc->sched.beacon_adjust ||
!sc->cur_chan->tsf_val) break;
ath_chanctx_adjust_tbtt_delta(sc);
/* TSF time might have been updated by the incoming beacon, * need update the channel switch timer to reflect the change.
*/
tsf_time = sc->sched.switch_start_time;
tsf_time -= (u32) sc->cur_chan->tsf_val +
ath9k_hw_get_tsf_offset(sc->cur_chan->tsf_ts, 0);
tsf_time += ath9k_hw_gettsf32(ah);
sc->sched.beacon_adjust = false;
ath_chanctx_setup_timer(sc, tsf_time); break; case ATH_CHANCTX_EVENT_AUTHORIZED: if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE ||
avp->chanctx != sc->cur_chan) break;
ath_dbg(common, CHAN_CTX, "Move chanctx state from FORCE_ACTIVE to IDLE\n");
sc->sched.state = ATH_CHANCTX_STATE_IDLE;
fallthrough; case ATH_CHANCTX_EVENT_SWITCH: if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
sc->cur_chan->switch_after_beacon ||
sc->cur_chan == &sc->offchannel.chan) break;
/* If this is a station chanctx, stay active for a half * beacon period (minus channel switch time)
*/
sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
cur_conf = &sc->cur_chan->beacon;
ath_dbg(common, CHAN_CTX, "Move chanctx state to WAIT_FOR_TIMER (event SWITCH)\n");
if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) &&
req->n_ssids) { for (i = 0; i < req->n_ssids; i++)
ath_scan_send_probe(sc, &req->ssids[i]);
}
ath_dbg(common, CHAN_CTX, "Moving offchannel state to ATH_OFFCHANNEL_PROBE_WAIT\n");
switch (sc->offchannel.state) { case ATH_OFFCHANNEL_PROBE_WAIT: if (!sc->offchannel.scan_req) return;
/* get first active channel context */
ctx = ath_chanctx_get_oper_chan(sc, true); if (ctx->active) {
ath_dbg(common, CHAN_CTX, "Switch to oper/active context, " "move offchannel state to ATH_OFFCHANNEL_SUSPEND\n");
sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
ath_chanctx_switch(sc, ctx, NULL);
mod_timer(&sc->offchannel.timer, jiffies + HZ / 10); break;
}
fallthrough; case ATH_OFFCHANNEL_SUSPEND: if (!sc->offchannel.scan_req) return;
ath_scan_next_channel(sc); break; case ATH_OFFCHANNEL_ROC_START: case ATH_OFFCHANNEL_ROC_WAIT:
sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
ath_roc_complete(sc, ATH_ROC_COMPLETE_EXPIRE); break; default: break;
}
}
if (sc->cur_chan == &sc->offchannel.chan) returnfalse;
switch (sc->sched.state) { case ATH_CHANCTX_STATE_SWITCH: returnfalse; case ATH_CHANCTX_STATE_IDLE: if (!sc->cur_chan->switch_after_beacon) returnfalse;
ath_dbg(common, CHAN_CTX, "Defer switch, set chanctx state to WAIT_FOR_BEACON\n");
if (!sc->sched.offchannel_pending)
sc->sched.offchannel_duration = 0;
if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE)
sc->sched.state = ATH_CHANCTX_STATE_IDLE;
spin_unlock_bh(&sc->chan_lock);
if (sc->sc_ah->chip_fullsleep ||
memcmp(&sc->cur_chandef, &sc->cur_chan->chandef, sizeof(sc->cur_chandef))) {
ath_dbg(common, CHAN_CTX, "%s: Set channel %d MHz\n",
__func__, sc->cur_chan->chandef.center_freq1);
ath_set_channel(sc); if (measure_time)
sc->sched.channel_switch_time =
ath9k_hw_get_tsf_offset(ts, 0); /* * A reset will ensure that all queues are woken up, * so there is no need to awaken them again.
*/ goto out;
}
if (queues_stopped)
ath9k_chanctx_wake_queues(sc, old_ctx);
out: if (send_ps)
ath_chanctx_send_ps_frame(sc, false);
for (i = 0; i < ARRAY_SIZE(ctx->acq); i++) {
INIT_LIST_HEAD(&ctx->acq[i].acq_new);
INIT_LIST_HEAD(&ctx->acq[i].acq_old);
spin_lock_init(&ctx->acq[i].lock);
}
/* * Channel switch in multi-channel mode is deferred * by a quarter beacon interval when handling * ATH_CHANCTX_EVENT_BEACON_PREPARE, so the P2P-GO * interface is guaranteed to be discoverable * for that duration after a TBTT.
*/
switch_time = cur_conf->beacon_interval / 4;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.