Skip to content

Commit 5336fa8

Browse files
Simon Wunderlichjmberg-intel
authored andcommitted
nl80211/cfg80211: enable DFS for IBSS mode
To use DFS in IBSS mode, userspace is required to react to radar events. It can inform nl80211 that it is capable of doing so by adding a NL80211_ATTR_HANDLE_DFS attribute when joining the IBSS. This attribute is supplied to let the kernelspace know that the userspace application can and will handle radar events, e.g. by intiating channel switches to a valid channel. DFS channels may only be used if this attribute is supplied and the driver supports it. Driver support will be checked even if a channel without DFS will be initially joined, as a DFS channel may be chosen later. Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de> Signed-off-by: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de> [fix attribute name in commit message] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 687da13 commit 5336fa8

6 files changed

Lines changed: 53 additions & 11 deletions

File tree

‎include/net/cfg80211.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,9 @@ struct cfg80211_disassoc_request {
16641664
* sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is
16651665
* required to assume that the port is unauthorized until authorized by
16661666
* user space. Otherwise, port is marked authorized by default.
1667+
* @userspace_handles_dfs: whether user space controls DFS operation, i.e.
1668+
* changes the channel when a radar is detected. This is required
1669+
* to operate on DFS channels.
16671670
* @basic_rates: bitmap of basic rates to use when creating the IBSS
16681671
* @mcast_rate: per-band multicast rate index + 1 (0: disabled)
16691672
* @ht_capa: HT Capabilities over-rides. Values set in ht_capa_mask
@@ -1681,6 +1684,7 @@ struct cfg80211_ibss_params {
16811684
bool channel_fixed;
16821685
bool privacy;
16831686
bool control_port;
1687+
bool userspace_handles_dfs;
16841688
int mcast_rate[IEEE80211_NUM_BANDS];
16851689
struct ieee80211_ht_cap ht_capa;
16861690
struct ieee80211_ht_cap ht_capa_mask;
@@ -3061,6 +3065,7 @@ struct cfg80211_cached_keys;
30613065
* @conn: (private) cfg80211 software SME connection state machine data
30623066
* @connect_keys: (private) keys to set after connection is established
30633067
* @ibss_fixed: (private) IBSS is using fixed BSSID
3068+
* @ibss_dfs_possible: (private) IBSS may change to a DFS channel
30643069
* @event_list: (private) list for internal event processing
30653070
* @event_lock: (private) lock for event list
30663071
*/
@@ -3099,6 +3104,7 @@ struct wireless_dev {
30993104
struct ieee80211_channel *channel;
31003105

31013106
bool ibss_fixed;
3107+
bool ibss_dfs_possible;
31023108

31033109
bool ps;
31043110
int ps_timeout;

‎include/uapi/linux/nl80211.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,13 @@ enum nl80211_commands {
15011501
* @NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES: array of supported
15021502
* supported operating classes.
15031503
*
1504+
* @NL80211_ATTR_HANDLE_DFS: A flag indicating whether user space
1505+
* controls DFS operation in IBSS mode. If the flag is included in
1506+
* %NL80211_CMD_JOIN_IBSS request, the driver will allow use of DFS
1507+
* channels and reports radar events to userspace. Userspace is required
1508+
* to react to radar events, e.g. initiate a channel switch or leave the
1509+
* IBSS network.
1510+
*
15041511
* @NL80211_ATTR_MAX: highest attribute number currently defined
15051512
* @__NL80211_ATTR_AFTER_LAST: internal use
15061513
*/
@@ -1815,6 +1822,8 @@ enum nl80211_attrs {
18151822

18161823
NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
18171824

1825+
NL80211_ATTR_HANDLE_DFS,
1826+
18181827
/* add attributes here, update the policy in nl80211.c */
18191828

18201829
__NL80211_ATTR_AFTER_LAST,

‎net/wireless/chan.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ cfg80211_get_chan_state(struct wireless_dev *wdev,
504504
case NL80211_IFTYPE_ADHOC:
505505
if (wdev->current_bss) {
506506
*chan = wdev->current_bss->pub.channel;
507-
*chanmode = wdev->ibss_fixed
507+
*chanmode = (wdev->ibss_fixed &&
508+
!wdev->ibss_dfs_possible)
508509
? CHAN_MODE_SHARED
509510
: CHAN_MODE_EXCLUSIVE;
510511
return;

‎net/wireless/ibss.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
8383
struct cfg80211_cached_keys *connkeys)
8484
{
8585
struct wireless_dev *wdev = dev->ieee80211_ptr;
86+
struct ieee80211_channel *check_chan;
87+
u8 radar_detect_width = 0;
8688
int err;
8789

8890
ASSERT_WDEV_LOCK(wdev);
@@ -114,14 +116,28 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
114116
wdev->connect_keys = connkeys;
115117

116118
wdev->ibss_fixed = params->channel_fixed;
119+
wdev->ibss_dfs_possible = params->userspace_handles_dfs;
117120
#ifdef CONFIG_CFG80211_WEXT
118121
wdev->wext.ibss.chandef = params->chandef;
119122
#endif
123+
check_chan = params->chandef.chan;
124+
if (params->userspace_handles_dfs) {
125+
/* use channel NULL to check for radar even if the current
126+
* channel is not a radar channel - it might decide to change
127+
* to DFS channel later.
128+
*/
129+
radar_detect_width = BIT(params->chandef.width);
130+
check_chan = NULL;
131+
}
132+
133+
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
134+
check_chan,
135+
(params->channel_fixed &&
136+
!radar_detect_width)
137+
? CHAN_MODE_SHARED
138+
: CHAN_MODE_EXCLUSIVE,
139+
radar_detect_width);
120140

121-
err = cfg80211_can_use_chan(rdev, wdev, params->chandef.chan,
122-
params->channel_fixed
123-
? CHAN_MODE_SHARED
124-
: CHAN_MODE_EXCLUSIVE);
125141
if (err) {
126142
wdev->connect_keys = NULL;
127143
return err;

‎net/wireless/nl80211.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
356356
[NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
357357
[NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
358358
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
359+
[NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
359360
};
360361

361362
/* policy for the key attributes */
@@ -5768,9 +5769,9 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
57685769
if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
57695770
return -EINVAL;
57705771

5771-
/* DFS channels are only supported for AP/P2P GO ... for now. */
57725772
if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
5773-
dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO) {
5773+
dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5774+
dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
57745775
err = cfg80211_chandef_dfs_required(wdev->wiphy,
57755776
&params.chandef);
57765777
if (err < 0) {
@@ -6602,6 +6603,9 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
66026603
ibss.control_port =
66036604
nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
66046605

6606+
ibss.userspace_handles_dfs =
6607+
nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6608+
66056609
err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
66066610
if (err)
66076611
kfree(connkeys);

‎net/wireless/util.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
12491249
enum cfg80211_chan_mode chmode;
12501250
int num_different_channels = 0;
12511251
int total = 1;
1252-
bool radar_required;
1252+
bool radar_required = false;
12531253
int i, j;
12541254

12551255
ASSERT_RTNL();
@@ -1264,14 +1264,20 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
12641264
case NL80211_IFTYPE_MESH_POINT:
12651265
case NL80211_IFTYPE_P2P_GO:
12661266
case NL80211_IFTYPE_WDS:
1267-
radar_required = !!(chan &&
1268-
(chan->flags & IEEE80211_CHAN_RADAR));
1267+
/* if the interface could potentially choose a DFS channel,
1268+
* then mark DFS as required.
1269+
*/
1270+
if (!chan) {
1271+
if (chanmode != CHAN_MODE_UNDEFINED && radar_detect)
1272+
radar_required = true;
1273+
break;
1274+
}
1275+
radar_required = !!(chan->flags & IEEE80211_CHAN_RADAR);
12691276
break;
12701277
case NL80211_IFTYPE_P2P_CLIENT:
12711278
case NL80211_IFTYPE_STATION:
12721279
case NL80211_IFTYPE_P2P_DEVICE:
12731280
case NL80211_IFTYPE_MONITOR:
1274-
radar_required = false;
12751281
break;
12761282
case NUM_NL80211_IFTYPES:
12771283
case NL80211_IFTYPE_UNSPECIFIED:

0 commit comments

Comments
 (0)