Skip to content

Commit 2beb6da

Browse files
lucacoelhojmberg-intel
authored andcommitted
cfg80211/mac80211: refactor cfg80211_chandef_dfs_required()
Some interface types don't require DFS (such as STATION, P2P_CLIENT etc). In order to centralize these decisions, make cfg80211_chandef_dfs_required() take the iftype into consideration. Signed-off-by: Luciano Coelho <luciano.coelho@intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent cb2d956 commit 2beb6da

6 files changed

Lines changed: 104 additions & 62 deletions

File tree

‎include/net/cfg80211.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,13 @@ bool cfg80211_chandef_usable(struct wiphy *wiphy,
446446
* cfg80211_chandef_dfs_required - checks if radar detection is required
447447
* @wiphy: the wiphy to validate against
448448
* @chandef: the channel definition to check
449-
* Return: 1 if radar detection is required, 0 if it is not, < 0 on error
449+
* @iftype: the interface type as specified in &enum nl80211_iftype
450+
* Returns:
451+
* 1 if radar detection is required, 0 if it is not, < 0 on error
450452
*/
451453
int cfg80211_chandef_dfs_required(struct wiphy *wiphy,
452-
const struct cfg80211_chan_def *chandef);
454+
const struct cfg80211_chan_def *chandef,
455+
enum nl80211_iftype);
453456

454457
/**
455458
* ieee80211_chandef_rate_flags - returns rate flags for a channel

‎net/mac80211/ibss.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
228228
struct beacon_data *presp;
229229
enum nl80211_bss_scan_width scan_width;
230230
bool have_higher_than_11mbit;
231-
bool radar_required = false;
231+
bool radar_required;
232232
int err;
233233

234234
sdata_assert_lock(sdata);
@@ -284,21 +284,20 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
284284
}
285285

286286
err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
287-
&chandef);
287+
&chandef, NL80211_IFTYPE_ADHOC);
288288
if (err < 0) {
289289
sdata_info(sdata,
290290
"Failed to join IBSS, invalid chandef\n");
291291
return;
292292
}
293-
if (err > 0) {
294-
if (!ifibss->userspace_handles_dfs) {
295-
sdata_info(sdata,
296-
"Failed to join IBSS, DFS channel without control program\n");
297-
return;
298-
}
299-
radar_required = true;
293+
if (err > 0 && !ifibss->userspace_handles_dfs) {
294+
sdata_info(sdata,
295+
"Failed to join IBSS, DFS channel without control program\n");
296+
return;
300297
}
301298

299+
radar_required = err;
300+
302301
mutex_lock(&local->mtx);
303302
if (ieee80211_vif_use_channel(sdata, &chandef,
304303
ifibss->fixed_channel ?
@@ -777,7 +776,8 @@ static void ieee80211_ibss_csa_mark_radar(struct ieee80211_sub_if_data *sdata)
777776
* unavailable.
778777
*/
779778
err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
780-
&ifibss->chandef);
779+
&ifibss->chandef,
780+
NL80211_IFTYPE_ADHOC);
781781
if (err > 0)
782782
cfg80211_radar_event(sdata->local->hw.wiphy, &ifibss->chandef,
783783
GFP_ATOMIC);
@@ -876,17 +876,17 @@ ieee80211_ibss_process_chanswitch(struct ieee80211_sub_if_data *sdata,
876876
}
877877

878878
err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
879-
&params.chandef);
879+
&params.chandef,
880+
NL80211_IFTYPE_ADHOC);
880881
if (err < 0)
881882
goto disconnect;
882-
if (err) {
883+
if (err > 0 && !ifibss->userspace_handles_dfs) {
883884
/* IBSS-DFS only allowed with a control program */
884-
if (!ifibss->userspace_handles_dfs)
885-
goto disconnect;
886-
887-
params.radar_required = true;
885+
goto disconnect;
888886
}
889887

888+
params.radar_required = err;
889+
890890
if (cfg80211_chandef_identical(&params.chandef,
891891
&sdata->vif.bss_conf.chandef)) {
892892
ibss_dbg(sdata,

‎net/mac80211/mesh.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,14 +903,15 @@ ieee80211_mesh_process_chnswitch(struct ieee80211_sub_if_data *sdata,
903903
}
904904

905905
err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
906-
&params.chandef);
906+
&params.chandef,
907+
NL80211_IFTYPE_MESH_POINT);
907908
if (err < 0)
908909
return false;
909-
if (err) {
910-
params.radar_required = true;
910+
if (err > 0)
911911
/* TODO: DFS not (yet) supported */
912912
return false;
913-
}
913+
914+
params.radar_required = err;
914915

915916
if (cfg80211_chandef_identical(&params.chandef,
916917
&sdata->vif.bss_conf.chandef)) {

‎net/wireless/chan.c‎

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -326,28 +326,57 @@ static int cfg80211_get_chans_dfs_required(struct wiphy *wiphy,
326326

327327

328328
int cfg80211_chandef_dfs_required(struct wiphy *wiphy,
329-
const struct cfg80211_chan_def *chandef)
329+
const struct cfg80211_chan_def *chandef,
330+
enum nl80211_iftype iftype)
330331
{
331332
int width;
332-
int r;
333+
int ret;
333334

334335
if (WARN_ON(!cfg80211_chandef_valid(chandef)))
335336
return -EINVAL;
336337

337-
width = cfg80211_chandef_get_width(chandef);
338-
if (width < 0)
339-
return -EINVAL;
338+
switch (iftype) {
339+
case NL80211_IFTYPE_ADHOC:
340+
case NL80211_IFTYPE_AP:
341+
case NL80211_IFTYPE_P2P_GO:
342+
case NL80211_IFTYPE_MESH_POINT:
343+
width = cfg80211_chandef_get_width(chandef);
344+
if (width < 0)
345+
return -EINVAL;
340346

341-
r = cfg80211_get_chans_dfs_required(wiphy, chandef->center_freq1,
342-
width);
343-
if (r)
344-
return r;
347+
ret = cfg80211_get_chans_dfs_required(wiphy,
348+
chandef->center_freq1,
349+
width);
350+
if (ret < 0)
351+
return ret;
352+
else if (ret > 0)
353+
return BIT(chandef->width);
345354

346-
if (!chandef->center_freq2)
347-
return 0;
355+
if (!chandef->center_freq2)
356+
return 0;
357+
358+
ret = cfg80211_get_chans_dfs_required(wiphy,
359+
chandef->center_freq2,
360+
width);
361+
if (ret < 0)
362+
return ret;
363+
else if (ret > 0)
364+
return BIT(chandef->width);
348365

349-
return cfg80211_get_chans_dfs_required(wiphy, chandef->center_freq2,
350-
width);
366+
break;
367+
case NL80211_IFTYPE_STATION:
368+
case NL80211_IFTYPE_P2P_CLIENT:
369+
case NL80211_IFTYPE_MONITOR:
370+
case NL80211_IFTYPE_AP_VLAN:
371+
case NL80211_IFTYPE_WDS:
372+
case NL80211_IFTYPE_P2P_DEVICE:
373+
case NL80211_IFTYPE_UNSPECIFIED:
374+
break;
375+
case NUM_NL80211_IFTYPES:
376+
WARN_ON(1);
377+
}
378+
379+
return 0;
351380
}
352381
EXPORT_SYMBOL(cfg80211_chandef_dfs_required);
353382

@@ -749,7 +778,8 @@ bool cfg80211_reg_can_beacon(struct wiphy *wiphy,
749778
!cfg80211_go_permissive_chan(rdev, chandef->chan))
750779
prohibited_flags |= IEEE80211_CHAN_NO_IR;
751780

752-
if (cfg80211_chandef_dfs_required(wiphy, chandef) > 0 &&
781+
if (cfg80211_chandef_dfs_required(wiphy, chandef,
782+
NL80211_IFTYPE_UNSPECIFIED) > 0 &&
753783
cfg80211_chandef_dfs_available(wiphy, chandef)) {
754784
/* We can skip IEEE80211_CHAN_NO_IR if chandef dfs available */
755785
prohibited_flags = IEEE80211_CHAN_DISABLED;
@@ -779,6 +809,8 @@ cfg80211_get_chan_state(struct wireless_dev *wdev,
779809
enum cfg80211_chan_mode *chanmode,
780810
u8 *radar_detect)
781811
{
812+
int ret;
813+
782814
*chan = NULL;
783815
*chanmode = CHAN_MODE_UNDEFINED;
784816

@@ -821,8 +853,11 @@ cfg80211_get_chan_state(struct wireless_dev *wdev,
821853
*chan = wdev->chandef.chan;
822854
*chanmode = CHAN_MODE_SHARED;
823855

824-
if (cfg80211_chandef_dfs_required(wdev->wiphy,
825-
&wdev->chandef))
856+
ret = cfg80211_chandef_dfs_required(wdev->wiphy,
857+
&wdev->chandef,
858+
wdev->iftype);
859+
WARN_ON(ret < 0);
860+
if (ret > 0)
826861
*radar_detect |= BIT(wdev->chandef.width);
827862
}
828863
return;
@@ -831,8 +866,11 @@ cfg80211_get_chan_state(struct wireless_dev *wdev,
831866
*chan = wdev->chandef.chan;
832867
*chanmode = CHAN_MODE_SHARED;
833868

834-
if (cfg80211_chandef_dfs_required(wdev->wiphy,
835-
&wdev->chandef))
869+
ret = cfg80211_chandef_dfs_required(wdev->wiphy,
870+
&wdev->chandef,
871+
wdev->iftype);
872+
WARN_ON(ret < 0);
873+
if (ret > 0)
836874
*radar_detect |= BIT(wdev->chandef.width);
837875
}
838876
return;

‎net/wireless/mesh.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,13 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
179179
NL80211_IFTYPE_MESH_POINT))
180180
return -EINVAL;
181181

182-
err = cfg80211_chandef_dfs_required(wdev->wiphy, &setup->chandef);
182+
err = cfg80211_chandef_dfs_required(wdev->wiphy,
183+
&setup->chandef,
184+
NL80211_IFTYPE_MESH_POINT);
183185
if (err < 0)
184186
return err;
185-
if (err)
187+
188+
if (err > 0)
186189
radar_detect_width = BIT(setup->chandef.width);
187190

188191
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,

‎net/wireless/nl80211.c‎

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,12 +3275,15 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
32753275
wdev->iftype))
32763276
return -EINVAL;
32773277

3278-
err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3278+
err = cfg80211_chandef_dfs_required(wdev->wiphy,
3279+
&params.chandef,
3280+
NL80211_IFTYPE_AP);
32793281
if (err < 0)
32803282
return err;
3281-
if (err) {
3282-
radar_detect_width = BIT(params.chandef.width);
3283+
3284+
if (err > 0) {
32833285
params.radar_required = true;
3286+
radar_detect_width = BIT(params.chandef.width);
32843287
}
32853288

32863289
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
@@ -5806,7 +5809,8 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
58065809
if (wdev->cac_started)
58075810
return -EBUSY;
58085811

5809-
err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5812+
err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
5813+
NL80211_IFTYPE_UNSPECIFIED);
58105814
if (err < 0)
58115815
return err;
58125816

@@ -5942,22 +5946,15 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
59425946
wdev->iftype))
59435947
return -EINVAL;
59445948

5945-
switch (dev->ieee80211_ptr->iftype) {
5946-
case NL80211_IFTYPE_AP:
5947-
case NL80211_IFTYPE_P2P_GO:
5948-
case NL80211_IFTYPE_ADHOC:
5949-
case NL80211_IFTYPE_MESH_POINT:
5950-
err = cfg80211_chandef_dfs_required(wdev->wiphy,
5951-
&params.chandef);
5952-
if (err < 0)
5953-
return err;
5954-
if (err) {
5955-
radar_detect_width = BIT(params.chandef.width);
5956-
params.radar_required = true;
5957-
}
5958-
break;
5959-
default:
5960-
break;
5949+
err = cfg80211_chandef_dfs_required(wdev->wiphy,
5950+
&params.chandef,
5951+
wdev->iftype);
5952+
if (err < 0)
5953+
return err;
5954+
5955+
if (err > 0) {
5956+
radar_detect_width = BIT(params.chandef.width);
5957+
params.radar_required = true;
59615958
}
59625959

59635960
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,

0 commit comments

Comments
 (0)