Skip to content

Commit 37fa2bd

Browse files
Michal Kaziorjmberg-intel
authored andcommitted
mac80211: refactor channel switch function
The function was quite big. This splits out beacon updating into a separate function for improved maintenance and extension. Signed-off-by: Michal Kazior <michal.kazior@tieto.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 7c8d5e0 commit 37fa2bd

1 file changed

Lines changed: 63 additions & 50 deletions

File tree

‎net/mac80211/cfg.c‎

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,52 +3089,11 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
30893089
sdata_unlock(sdata);
30903090
}
30913091

3092-
int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3093-
struct cfg80211_csa_settings *params)
3092+
static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3093+
struct cfg80211_csa_settings *params,
3094+
u32 *changed)
30943095
{
3095-
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3096-
struct ieee80211_local *local = sdata->local;
3097-
struct ieee80211_chanctx_conf *chanctx_conf;
3098-
struct ieee80211_chanctx *chanctx;
3099-
struct ieee80211_if_mesh __maybe_unused *ifmsh;
3100-
int err, num_chanctx, changed = 0;
3101-
3102-
sdata_assert_lock(sdata);
3103-
3104-
if (!list_empty(&local->roc_list) || local->scanning)
3105-
return -EBUSY;
3106-
3107-
if (sdata->wdev.cac_started)
3108-
return -EBUSY;
3109-
3110-
if (cfg80211_chandef_identical(&params->chandef,
3111-
&sdata->vif.bss_conf.chandef))
3112-
return -EINVAL;
3113-
3114-
rcu_read_lock();
3115-
chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3116-
if (!chanctx_conf) {
3117-
rcu_read_unlock();
3118-
return -EBUSY;
3119-
}
3120-
3121-
/* don't handle for multi-VIF cases */
3122-
chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
3123-
if (chanctx->refcount > 1) {
3124-
rcu_read_unlock();
3125-
return -EBUSY;
3126-
}
3127-
num_chanctx = 0;
3128-
list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
3129-
num_chanctx++;
3130-
rcu_read_unlock();
3131-
3132-
if (num_chanctx > 1)
3133-
return -EBUSY;
3134-
3135-
/* don't allow another channel switch if one is already active. */
3136-
if (sdata->vif.csa_active)
3137-
return -EBUSY;
3096+
int err;
31383097

31393098
switch (sdata->vif.type) {
31403099
case NL80211_IFTYPE_AP:
@@ -3170,7 +3129,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
31703129
kfree(sdata->u.ap.next_beacon);
31713130
return err;
31723131
}
3173-
changed |= err;
3132+
*changed |= err;
31743133

31753134
break;
31763135
case NL80211_IFTYPE_ADHOC:
@@ -3204,15 +3163,15 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
32043163
err = ieee80211_ibss_csa_beacon(sdata, params);
32053164
if (err < 0)
32063165
return err;
3207-
changed |= err;
3166+
*changed |= err;
32083167
}
32093168

32103169
ieee80211_send_action_csa(sdata, params);
32113170

32123171
break;
32133172
#ifdef CONFIG_MAC80211_MESH
3214-
case NL80211_IFTYPE_MESH_POINT:
3215-
ifmsh = &sdata->u.mesh;
3173+
case NL80211_IFTYPE_MESH_POINT: {
3174+
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
32163175

32173176
if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
32183177
return -EINVAL;
@@ -3237,18 +3196,72 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
32373196
ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
32383197
return err;
32393198
}
3240-
changed |= err;
3199+
*changed |= err;
32413200
}
32423201

32433202
if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
32443203
ieee80211_send_action_csa(sdata, params);
32453204

32463205
break;
3206+
}
32473207
#endif
32483208
default:
32493209
return -EOPNOTSUPP;
32503210
}
32513211

3212+
return 0;
3213+
}
3214+
3215+
int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3216+
struct cfg80211_csa_settings *params)
3217+
{
3218+
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3219+
struct ieee80211_local *local = sdata->local;
3220+
struct ieee80211_chanctx_conf *chanctx_conf;
3221+
struct ieee80211_chanctx *chanctx;
3222+
int err, num_chanctx, changed = 0;
3223+
3224+
sdata_assert_lock(sdata);
3225+
3226+
if (!list_empty(&local->roc_list) || local->scanning)
3227+
return -EBUSY;
3228+
3229+
if (sdata->wdev.cac_started)
3230+
return -EBUSY;
3231+
3232+
if (cfg80211_chandef_identical(&params->chandef,
3233+
&sdata->vif.bss_conf.chandef))
3234+
return -EINVAL;
3235+
3236+
rcu_read_lock();
3237+
chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3238+
if (!chanctx_conf) {
3239+
rcu_read_unlock();
3240+
return -EBUSY;
3241+
}
3242+
3243+
/* don't handle for multi-VIF cases */
3244+
chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
3245+
if (chanctx->refcount > 1) {
3246+
rcu_read_unlock();
3247+
return -EBUSY;
3248+
}
3249+
num_chanctx = 0;
3250+
list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
3251+
num_chanctx++;
3252+
rcu_read_unlock();
3253+
3254+
if (num_chanctx > 1)
3255+
return -EBUSY;
3256+
3257+
/* don't allow another channel switch if one is already active. */
3258+
if (sdata->vif.csa_active)
3259+
return -EBUSY;
3260+
3261+
err = ieee80211_set_csa_beacon(sdata, params, &changed);
3262+
if (err)
3263+
return err;
3264+
32523265
sdata->csa_radar_required = params->radar_required;
32533266

32543267
if (params->block_tx)

0 commit comments

Comments
 (0)