Commit 66e01cf9 authored by Luciano Coelho's avatar Luciano Coelho Committed by Johannes Berg

mac80211: only set CSA beacon when at least one beacon must be transmitted

A beacon should never have a Channel Switch Announcement information
element with a count of 0, because a count of 1 means switch just
before the next beacon.  So, if a count of 0 was valid in a beacon, it
would have been transmitted in the next channel already, which is
useless.  A CSA count equal to zero is only meaningful in action
frames or probe_responses.

Fix the ieee80211_csa_is_complete() and ieee80211_update_csa()
functions accordingly.

With a CSA count of 0, we won't transmit any CSA beacons, because the
switch will happen before the next TBTT.  To avoid extra work and
potential confusion in the drivers, complete the CSA immediately,
instead of waiting for the driver to call ieee80211_csa_finish().

To keep things simpler, we also switch immediately when the CSA count
is 1, while in theory we should delay the switch until just before the
next TBTT.

Additionally, move the ieee80211_csa_finish() function to cfg.c,
where it makes more sense.
Tested-by: default avatarSimon Wunderlich <sw@simonwunderlich.de>
Acked-by: default avatarSimon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: default avatarLuciano Coelho <luciano.coelho@intel.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent b58e81e9
...@@ -2750,11 +2750,13 @@ enum ieee80211_roc_type { ...@@ -2750,11 +2750,13 @@ enum ieee80211_roc_type {
* @channel_switch_beacon: Starts a channel switch to a new channel. * @channel_switch_beacon: Starts a channel switch to a new channel.
* Beacons are modified to include CSA or ECSA IEs before calling this * Beacons are modified to include CSA or ECSA IEs before calling this
* function. The corresponding count fields in these IEs must be * function. The corresponding count fields in these IEs must be
* decremented, and when they reach zero the driver must call * decremented, and when they reach 1 the driver must call
* ieee80211_csa_finish(). Drivers which use ieee80211_beacon_get() * ieee80211_csa_finish(). Drivers which use ieee80211_beacon_get()
* get the csa counter decremented by mac80211, but must check if it is * get the csa counter decremented by mac80211, but must check if it is
* zero using ieee80211_csa_is_complete() after the beacon has been * 1 using ieee80211_csa_is_complete() after the beacon has been
* transmitted and then call ieee80211_csa_finish(). * transmitted and then call ieee80211_csa_finish().
* If the CSA count starts as zero or 1, this function will not be called,
* since there won't be any time to beacon before the switch anyway.
* *
* @join_ibss: Join an IBSS (on an IBSS interface); this is called after all * @join_ibss: Join an IBSS (on an IBSS interface); this is called after all
* information in bss_conf is set up and the beacon can be retrieved. A * information in bss_conf is set up and the beacon can be retrieved. A
...@@ -3452,13 +3454,13 @@ static inline struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw, ...@@ -3452,13 +3454,13 @@ static inline struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
* @vif: &struct ieee80211_vif pointer from the add_interface callback. * @vif: &struct ieee80211_vif pointer from the add_interface callback.
* *
* After a channel switch announcement was scheduled and the counter in this * After a channel switch announcement was scheduled and the counter in this
* announcement hit zero, this function must be called by the driver to * announcement hits 1, this function must be called by the driver to
* notify mac80211 that the channel can be changed. * notify mac80211 that the channel can be changed.
*/ */
void ieee80211_csa_finish(struct ieee80211_vif *vif); void ieee80211_csa_finish(struct ieee80211_vif *vif);
/** /**
* ieee80211_csa_is_complete - find out if counters reached zero * ieee80211_csa_is_complete - find out if counters reached 1
* @vif: &struct ieee80211_vif pointer from the add_interface callback. * @vif: &struct ieee80211_vif pointer from the add_interface callback.
* *
* This function returns whether the channel switch counters reached zero. * This function returns whether the channel switch counters reached zero.
......
...@@ -2988,28 +2988,26 @@ cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) ...@@ -2988,28 +2988,26 @@ cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
return new_beacon; return new_beacon;
} }
void ieee80211_csa_finalize_work(struct work_struct *work) void ieee80211_csa_finish(struct ieee80211_vif *vif)
{ {
struct ieee80211_sub_if_data *sdata = struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
container_of(work, struct ieee80211_sub_if_data,
csa_finalize_work);
struct ieee80211_local *local = sdata->local;
int err, changed = 0;
sdata_lock(sdata); ieee80211_queue_work(&sdata->local->hw,
/* AP might have been stopped while waiting for the lock. */ &sdata->csa_finalize_work);
if (!sdata->vif.csa_active) }
goto unlock; EXPORT_SYMBOL(ieee80211_csa_finish);
if (!ieee80211_sdata_running(sdata)) static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
goto unlock; {
struct ieee80211_local *local = sdata->local;
int err, changed = 0;
sdata->radar_required = sdata->csa_radar_required; sdata->radar_required = sdata->csa_radar_required;
mutex_lock(&local->mtx); mutex_lock(&local->mtx);
err = ieee80211_vif_change_channel(sdata, &changed); err = ieee80211_vif_change_channel(sdata, &changed);
mutex_unlock(&local->mtx); mutex_unlock(&local->mtx);
if (WARN_ON(err < 0)) if (WARN_ON(err < 0))
goto unlock; return;
if (!local->use_chanctx) { if (!local->use_chanctx) {
local->_oper_chandef = sdata->csa_chandef; local->_oper_chandef = sdata->csa_chandef;
...@@ -3023,7 +3021,7 @@ void ieee80211_csa_finalize_work(struct work_struct *work) ...@@ -3023,7 +3021,7 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
case NL80211_IFTYPE_AP: case NL80211_IFTYPE_AP:
err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon); err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
if (err < 0) if (err < 0)
goto unlock; return;
changed |= err; changed |= err;
kfree(sdata->u.ap.next_beacon); kfree(sdata->u.ap.next_beacon);
...@@ -3038,12 +3036,12 @@ void ieee80211_csa_finalize_work(struct work_struct *work) ...@@ -3038,12 +3036,12 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
case NL80211_IFTYPE_MESH_POINT: case NL80211_IFTYPE_MESH_POINT:
err = ieee80211_mesh_finish_csa(sdata); err = ieee80211_mesh_finish_csa(sdata);
if (err < 0) if (err < 0)
goto unlock; return;
break; break;
#endif #endif
default: default:
WARN_ON(1); WARN_ON(1);
goto unlock; return;
} }
ieee80211_wake_queues_by_reason(&sdata->local->hw, ieee80211_wake_queues_by_reason(&sdata->local->hw,
...@@ -3051,6 +3049,23 @@ void ieee80211_csa_finalize_work(struct work_struct *work) ...@@ -3051,6 +3049,23 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
IEEE80211_QUEUE_STOP_REASON_CSA); IEEE80211_QUEUE_STOP_REASON_CSA);
cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef); cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
}
void ieee80211_csa_finalize_work(struct work_struct *work)
{
struct ieee80211_sub_if_data *sdata =
container_of(work, struct ieee80211_sub_if_data,
csa_finalize_work);
sdata_lock(sdata);
/* AP might have been stopped while waiting for the lock. */
if (!sdata->vif.csa_active)
goto unlock;
if (!ieee80211_sdata_running(sdata))
goto unlock;
ieee80211_csa_finalize(sdata);
unlock: unlock:
sdata_unlock(sdata); sdata_unlock(sdata);
...@@ -3064,7 +3079,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3064,7 +3079,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_chanctx_conf *chanctx_conf; struct ieee80211_chanctx_conf *chanctx_conf;
struct ieee80211_chanctx *chanctx; struct ieee80211_chanctx *chanctx;
struct ieee80211_if_mesh __maybe_unused *ifmsh; struct ieee80211_if_mesh __maybe_unused *ifmsh;
int err, num_chanctx; int err, num_chanctx, changed = 0;
lockdep_assert_held(&sdata->wdev.mtx); lockdep_assert_held(&sdata->wdev.mtx);
...@@ -3105,19 +3120,40 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3105,19 +3120,40 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
switch (sdata->vif.type) { switch (sdata->vif.type) {
case NL80211_IFTYPE_AP: case NL80211_IFTYPE_AP:
sdata->csa_counter_offset_beacon =
params->counter_offset_beacon;
sdata->csa_counter_offset_presp = params->counter_offset_presp;
sdata->u.ap.next_beacon = sdata->u.ap.next_beacon =
cfg80211_beacon_dup(&params->beacon_after); cfg80211_beacon_dup(&params->beacon_after);
if (!sdata->u.ap.next_beacon) if (!sdata->u.ap.next_beacon)
return -ENOMEM; return -ENOMEM;
/*
* With a count of 0, we don't have to wait for any
* TBTT before switching, so complete the CSA
* immediately. In theory, with a count == 1 we
* should delay the switch until just before the next
* TBTT, but that would complicate things so we switch
* immediately too. If we would delay the switch
* until the next TBTT, we would have to set the probe
* response here.
*
* TODO: A channel switch with count <= 1 without
* sending a CSA action frame is kind of useless,
* because the clients won't know we're changing
* channels. The action frame must be implemented
* either here or in the userspace.
*/
if (params->count <= 1)
break;
sdata->csa_counter_offset_beacon =
params->counter_offset_beacon;
sdata->csa_counter_offset_presp = params->counter_offset_presp;
err = ieee80211_assign_beacon(sdata, &params->beacon_csa); err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
if (err < 0) { if (err < 0) {
kfree(sdata->u.ap.next_beacon); kfree(sdata->u.ap.next_beacon);
return err; return err;
} }
changed |= err;
break; break;
case NL80211_IFTYPE_ADHOC: case NL80211_IFTYPE_ADHOC:
if (!sdata->vif.bss_conf.ibss_joined) if (!sdata->vif.bss_conf.ibss_joined)
...@@ -3145,9 +3181,16 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3145,9 +3181,16 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
params->chandef.chan->band) params->chandef.chan->band)
return -EINVAL; return -EINVAL;
err = ieee80211_ibss_csa_beacon(sdata, params); /* see comments in the NL80211_IFTYPE_AP block */
if (err < 0) if (params->count > 1) {
return err; err = ieee80211_ibss_csa_beacon(sdata, params);
if (err < 0)
return err;
changed |= err;
}
ieee80211_send_action_csa(sdata, params);
break; break;
#ifdef CONFIG_MAC80211_MESH #ifdef CONFIG_MAC80211_MESH
case NL80211_IFTYPE_MESH_POINT: case NL80211_IFTYPE_MESH_POINT:
...@@ -3172,12 +3215,19 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3172,12 +3215,19 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE)
ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT; ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
err = ieee80211_mesh_csa_beacon(sdata, params, /* see comments in the NL80211_IFTYPE_AP block */
(ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)); if (params->count > 1) {
if (err < 0) { err = ieee80211_mesh_csa_beacon(sdata, params);
ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; if (err < 0) {
return err; ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
return err;
}
changed |= err;
} }
if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
ieee80211_send_action_csa(sdata, params);
break; break;
#endif #endif
default: default:
...@@ -3194,8 +3244,13 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, ...@@ -3194,8 +3244,13 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
sdata->csa_chandef = params->chandef; sdata->csa_chandef = params->chandef;
sdata->vif.csa_active = true; sdata->vif.csa_active = true;
ieee80211_bss_info_change_notify(sdata, err); if (changed) {
drv_channel_switch_beacon(sdata, &params->chandef); ieee80211_bss_info_change_notify(sdata, changed);
drv_channel_switch_beacon(sdata, &params->chandef);
} else {
/* if the beacon didn't change, we can finalize immediately */
ieee80211_csa_finalize(sdata);
}
return 0; return 0;
} }
......
...@@ -521,12 +521,6 @@ int ieee80211_ibss_csa_beacon(struct ieee80211_sub_if_data *sdata, ...@@ -521,12 +521,6 @@ int ieee80211_ibss_csa_beacon(struct ieee80211_sub_if_data *sdata,
if (old_presp) if (old_presp)
kfree_rcu(old_presp, rcu_head); kfree_rcu(old_presp, rcu_head);
/* it might not send the beacon for a while. send an action frame
* immediately to announce the channel switch.
*/
if (csa_settings)
ieee80211_send_action_csa(sdata, csa_settings);
return BSS_CHANGED_BEACON; return BSS_CHANGED_BEACON;
out: out:
return ret; return ret;
......
...@@ -1412,8 +1412,7 @@ void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata); ...@@ -1412,8 +1412,7 @@ void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata);
void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
struct sk_buff *skb); struct sk_buff *skb);
int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata, int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
struct cfg80211_csa_settings *csa_settings, struct cfg80211_csa_settings *csa_settings);
bool csa_action);
int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata); int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata);
/* scan/BSS handling */ /* scan/BSS handling */
......
...@@ -1066,7 +1066,8 @@ int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata) ...@@ -1066,7 +1066,8 @@ int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata)
/* Remove the CSA and MCSP elements from the beacon */ /* Remove the CSA and MCSP elements from the beacon */
tmp_csa_settings = rcu_dereference(ifmsh->csa); tmp_csa_settings = rcu_dereference(ifmsh->csa);
rcu_assign_pointer(ifmsh->csa, NULL); rcu_assign_pointer(ifmsh->csa, NULL);
kfree_rcu(tmp_csa_settings, rcu_head); if (tmp_csa_settings)
kfree_rcu(tmp_csa_settings, rcu_head);
ret = ieee80211_mesh_rebuild_beacon(sdata); ret = ieee80211_mesh_rebuild_beacon(sdata);
if (ret) if (ret)
return -EINVAL; return -EINVAL;
...@@ -1079,8 +1080,7 @@ int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata) ...@@ -1079,8 +1080,7 @@ int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata)
} }
int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata, int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
struct cfg80211_csa_settings *csa_settings, struct cfg80211_csa_settings *csa_settings)
bool csa_action)
{ {
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
struct mesh_csa_settings *tmp_csa_settings; struct mesh_csa_settings *tmp_csa_settings;
...@@ -1104,9 +1104,6 @@ int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata, ...@@ -1104,9 +1104,6 @@ int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
return ret; return ret;
} }
if (csa_action)
ieee80211_send_action_csa(sdata, csa_settings);
return BSS_CHANGED_BEACON; return BSS_CHANGED_BEACON;
} }
......
...@@ -2402,15 +2402,6 @@ static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, ...@@ -2402,15 +2402,6 @@ static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
return 0; return 0;
} }
void ieee80211_csa_finish(struct ieee80211_vif *vif)
{
struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
ieee80211_queue_work(&sdata->local->hw,
&sdata->csa_finalize_work);
}
EXPORT_SYMBOL(ieee80211_csa_finish);
static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata, static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata,
struct beacon_data *beacon) struct beacon_data *beacon)
{ {
...@@ -2439,8 +2430,12 @@ static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata, ...@@ -2439,8 +2430,12 @@ static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata,
if (WARN_ON(counter_offset_beacon >= beacon_data_len)) if (WARN_ON(counter_offset_beacon >= beacon_data_len))
return; return;
/* warn if the driver did not check for/react to csa completeness */ /* Warn if the driver did not check for/react to csa
if (WARN_ON(beacon_data[counter_offset_beacon] == 0)) * completeness. A beacon with CSA counter set to 0 should
* never occur, because a counter of 1 means switch just
* before the next beacon.
*/
if (WARN_ON(beacon_data[counter_offset_beacon] == 1))
return; return;
beacon_data[counter_offset_beacon]--; beacon_data[counter_offset_beacon]--;
...@@ -2506,7 +2501,7 @@ bool ieee80211_csa_is_complete(struct ieee80211_vif *vif) ...@@ -2506,7 +2501,7 @@ bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
if (WARN_ON(counter_beacon > beacon_data_len)) if (WARN_ON(counter_beacon > beacon_data_len))
goto out; goto out;
if (beacon_data[counter_beacon] == 0) if (beacon_data[counter_beacon] == 1)
ret = true; ret = true;
out: out:
rcu_read_unlock(); rcu_read_unlock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment