2013-09-03 17:43:34

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 0/4] add IBSS-DFS support

This patchset adds DFS support for the IBSS mode. It builds on top of
the previously sent AP DFS mode and channel switch announcement support.

The implementation differs from the DFS support as described in IEEE 802.11.
It does not implement the DFS owner service or uses IBSS DFS elements as
described in IEEE 802.11-2012 10.9.8.3. The DFS owner service has various
shortcomings:

* it requires synchronization to find one central IBSS owner
* citation: "The potential for hidden nodes within an IBSS means that the
IBSS channel switch protocol is best effort."
* the mechanism does not provide any way to handle big adhoc cells like
mesh networks (which is a major target).

Therefore, a stripped down approach is implemented:

* userspace must announce that it wants support for DFS and will handle
events using a flag for the ibss_join command.
* if a radar is detected, inform userspace. Userspace should then select
a channel (e.g. decide on it with the peers on higher level protocols
before, or wait a random backoff time) and start a channel switch process.
* if a channel switch announcement from another peeris received, adopt it
and re-transmit it (this has been implemented in the IBSS-CSA patchset
before)
* channel switch announcements on DFS channels are interpreted as
radar signals and will mark the channel as unusable.

As always, any comments are appreciated.

Cheers,
Simon

Simon Wunderlich (4):
nl80211: allow CAC only if no operation is going on
nl80211/cfg80211: enable DFS for IBSS mode
mac80211: enable DFS for IBSS mode
ath9k: enable DFS for IBSS mode

drivers/net/wireless/ath/ath9k/init.c | 3 +-
include/net/cfg80211.h | 6 ++++
include/uapi/linux/nl80211.h | 7 +++++
net/mac80211/ibss.c | 50 +++++++++++++++++++++++++++++----
net/mac80211/ieee80211_i.h | 1 +
net/wireless/chan.c | 3 +-
net/wireless/ibss.c | 24 +++++++++++++---
net/wireless/nl80211.c | 11 ++++++--
net/wireless/util.c | 11 ++++++--
9 files changed, 101 insertions(+), 15 deletions(-)

--
1.7.10.4



2013-09-03 17:43:34

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 4/4] ath9k: enable DFS for IBSS mode

Signed-off-by: Simon Wunderlich <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
drivers/net/wireless/ath/ath9k/init.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 9a1f349..bcc5698 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -791,7 +791,8 @@ static const struct ieee80211_iface_limit if_limits[] = {


static const struct ieee80211_iface_limit if_dfs_limits[] = {
- { .max = 1, .types = BIT(NL80211_IFTYPE_AP) },
+ { .max = 1, .types = BIT(NL80211_IFTYPE_AP) |
+ BIT(NL80211_IFTYPE_ADHOC) },
};

static const struct ieee80211_iface_combination if_comb[] = {
--
1.7.10.4


2013-09-03 17:43:35

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 3/4] mac80211: enable DFS for IBSS mode

Allow changing to DFS channels if the channel is available for
beaconing and a control program is available.

Channel switch announcement on DFS channels will trigger a radar event
and mark these channels as unavailable.

Signed-off-by: Simon Wunderlich <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
net/mac80211/ibss.c | 50 +++++++++++++++++++++++++++++++++++++++-----
net/mac80211/ieee80211_i.h | 1 +
2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 5ea9b3a..c3bf369 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -229,6 +229,8 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
struct beacon_data *presp;
enum nl80211_bss_scan_width scan_width;
bool have_higher_than_11mbit;
+ bool radar_required = false;
+ int err;

sdata_assert_lock(sdata);

@@ -271,6 +273,23 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
}
chandef.width = NL80211_CHAN_WIDTH_20;
chandef.center_freq1 = chan->center_freq;
+ /* check again for downgraded chandef */
+ if (!cfg80211_reg_can_beacon(local->hw.wiphy, &chandef)) {
+ sdata_info(sdata,
+ "Failed to join IBSS, beacons forbidden\n");
+ return;
+ }
+ }
+
+ err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
+ &chandef);
+ if (err > 0) {
+ if (!ifibss->control_port_dfs) {
+ sdata_info(sdata,
+ "Failed to join IBSS, DFS channel without control program\n");
+ return;
+ }
+ radar_required = true;
}

ieee80211_vif_release_channel(sdata);
@@ -295,6 +314,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
rcu_assign_pointer(ifibss->presp, presp);
mgmt = (void *)presp->head;

+ sdata->radar_required = radar_required;
sdata->vif.bss_conf.enable_beacon = true;
sdata->vif.bss_conf.beacon_int = beacon_int;
sdata->vif.bss_conf.basic_rates = basic_rates;
@@ -778,6 +798,21 @@ static void ieee80211_csa_connection_drop_work(struct work_struct *work)
ieee80211_queue_work(&sdata->local->hw, &sdata->work);
}

+static void ieee80211_ibss_csa_mark_radar(struct ieee80211_sub_if_data *sdata)
+{
+ struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
+ int err;
+
+ /* if the current channel is a DFS channel, mark the channel as
+ * unavailable.
+ */
+ err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
+ &ifibss->chandef);
+ if (err > 0)
+ cfg80211_radar_event(sdata->local->hw.wiphy, &ifibss->chandef,
+ GFP_ATOMIC);
+}
+
static bool
ieee80211_ibss_process_chanswitch(struct ieee80211_sub_if_data *sdata,
struct ieee802_11_elems *elems,
@@ -862,8 +897,7 @@ ieee80211_ibss_process_chanswitch(struct ieee80211_sub_if_data *sdata,
goto disconnect;
}

- if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, &params.chandef,
- IEEE80211_CHAN_DISABLED)) {
+ if (!cfg80211_reg_can_beacon(sdata->local->hw.wiphy, &params.chandef)) {
sdata_info(sdata,
"IBSS %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
ifibss->bssid,
@@ -879,10 +913,11 @@ ieee80211_ibss_process_chanswitch(struct ieee80211_sub_if_data *sdata,
if (err < 0)
goto disconnect;
if (err) {
+ /* IBSS-DFS only allowed with a control program */
+ if (!ifibss->control_port_dfs)
+ goto disconnect;
+
params.radar_required = true;
-
- /* TODO: IBSS-DFS not (yet) supported, disconnect. */
- goto disconnect;
}

rcu_read_lock();
@@ -929,12 +964,16 @@ ieee80211_ibss_process_chanswitch(struct ieee80211_sub_if_data *sdata,
ieee80211_bss_info_change_notify(sdata, err);
drv_channel_switch_beacon(sdata, &params.chandef);

+ ieee80211_ibss_csa_mark_radar(sdata);
+
return true;
disconnect:
ibss_dbg(sdata, "Can't handle channel switch, disconnect\n");
ieee80211_queue_work(&sdata->local->hw,
&ifibss->csa_connection_drop_work);

+ ieee80211_ibss_csa_mark_radar(sdata);
+
return true;
}

@@ -1670,6 +1709,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,

sdata->u.ibss.privacy = params->privacy;
sdata->u.ibss.control_port = params->control_port;
+ sdata->u.ibss.control_port_dfs = params->control_port_dfs;
sdata->u.ibss.basic_rates = params->basic_rates;

/* fix basic_rates if channel does not support these rates */
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 3a87c89..2bb01b6 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -497,6 +497,7 @@ struct ieee80211_if_ibss {
bool privacy;

bool control_port;
+ bool control_port_dfs;

u8 bssid[ETH_ALEN] __aligned(2);
u8 ssid[IEEE80211_MAX_SSID_LEN];
--
1.7.10.4


2013-09-03 17:43:34

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 1/4] nl80211: allow CAC only if no operation is going on

A CAC should fail if it is triggered while the interface is already
running.

Signed-off-by: Simon Wunderlich <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
net/wireless/nl80211.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index da8de5b..cbbef88 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5591,6 +5591,9 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
if (err)
return err;

+ if (netif_carrier_ok(dev))
+ return -EBUSY;
+
if (wdev->cac_started)
return -EBUSY;

--
1.7.10.4


2013-09-03 17:43:34

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 2/4] 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_CONTROL_PORT_DFS attribute when joining the IBSS.

If this attribute is supplied, DFS channels may be used if the driver
supports it. Support will be checked even if a channel without DFS will
be joined, as the channel might change later due to scan activity or
channel switch announcements.

Signed-off-by: Simon Wunderlich <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
include/net/cfg80211.h | 6 ++++++
include/uapi/linux/nl80211.h | 7 +++++++
net/wireless/chan.c | 3 ++-
net/wireless/ibss.c | 24 ++++++++++++++++++++----
net/wireless/nl80211.c | 8 ++++++--
net/wireless/util.c | 11 +++++++++--
6 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 0a2aafe..b20e8ca 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1656,6 +1656,9 @@ struct cfg80211_disassoc_request {
* sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is
* required to assume that the port is unauthorized until authorized by
* user space. Otherwise, port is marked authorized by default.
+ * @control_port_dfs: whether user space controls DFS operation, i.e.
+ * changes the channel when a radar is detected. This is required
+ * to operate on DFS channels.
* @basic_rates: bitmap of basic rates to use when creating the IBSS
* @mcast_rate: per-band multicast rate index + 1 (0: disabled)
* @ht_capa: HT Capabilities over-rides. Values set in ht_capa_mask
@@ -1673,6 +1676,7 @@ struct cfg80211_ibss_params {
bool channel_fixed;
bool privacy;
bool control_port;
+ bool control_port_dfs;
int mcast_rate[IEEE80211_NUM_BANDS];
struct ieee80211_ht_cap ht_capa;
struct ieee80211_ht_cap ht_capa_mask;
@@ -3053,6 +3057,7 @@ struct cfg80211_cached_keys;
* @conn: (private) cfg80211 software SME connection state machine data
* @connect_keys: (private) keys to set after connection is established
* @ibss_fixed: (private) IBSS is using fixed BSSID
+ * @ibss_dfs_possible: (private) IBSS may change to a DFS channel
* @event_list: (private) list for internal event processing
* @event_lock: (private) lock for event list
*/
@@ -3091,6 +3096,7 @@ struct wireless_dev {
struct ieee80211_channel *channel;

bool ibss_fixed;
+ bool ibss_dfs_possible;

bool ps;
int ps_timeout;
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index fde2c02..80e68e0 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -1496,6 +1496,11 @@ enum nl80211_commands {
* @NL80211_ATTR_RXMGMT_FLAGS: flags for nl80211_send_mgmt(), u32.
* As specified in the &enum nl80211_rxmgmt_flags.
*
+ * @NL80211_ATTR_CONTROL_PORT_DFS: A flag indicating whether user space
+ * controls DFS operation in IBSS mode. If the flag is included in
+ * %NL80211_CMD_JOIN_IBSS request, the driver will allow use of DFS
+ * channels and reports radar events to userspace.
+ *
* @NL80211_ATTR_MAX: highest attribute number currently defined
* @__NL80211_ATTR_AFTER_LAST: internal use
*/
@@ -1806,6 +1811,8 @@ enum nl80211_attrs {

NL80211_ATTR_RXMGMT_FLAGS,

+ NL80211_ATTR_CONTROL_PORT_DFS,
+
/* add attributes here, update the policy in nl80211.c */

__NL80211_ATTR_AFTER_LAST,
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index 80504e6..92cf75f 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -504,7 +504,8 @@ cfg80211_get_chan_state(struct wireless_dev *wdev,
case NL80211_IFTYPE_ADHOC:
if (wdev->current_bss) {
*chan = wdev->current_bss->pub.channel;
- *chanmode = wdev->ibss_fixed
+ *chanmode = (wdev->ibss_fixed &&
+ !wdev->ibss_dfs_possible)
? CHAN_MODE_SHARED
: CHAN_MODE_EXCLUSIVE;
return;
diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c
index 39bff7d..5edd69e 100644
--- a/net/wireless/ibss.c
+++ b/net/wireless/ibss.c
@@ -83,6 +83,8 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
struct cfg80211_cached_keys *connkeys)
{
struct wireless_dev *wdev = dev->ieee80211_ptr;
+ struct ieee80211_channel *check_chan;
+ u8 radar_detect_width = 0;
int err;

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

wdev->ibss_fixed = params->channel_fixed;
+ wdev->ibss_dfs_possible = params->control_port_dfs;
#ifdef CONFIG_CFG80211_WEXT
wdev->wext.ibss.chandef = params->chandef;
#endif
+ check_chan = params->chandef.chan;
+ if (params->control_port_dfs) {
+ /* use channel NULL to check for radar even if the current
+ * channel is not a radar channel - it might decide to change
+ * to DFS channel later.
+ */
+ radar_detect_width = BIT(params->chandef.width);
+ check_chan = NULL;
+ }
+
+ err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
+ check_chan,
+ (params->channel_fixed &&
+ !radar_detect_width)
+ ? CHAN_MODE_SHARED
+ : CHAN_MODE_EXCLUSIVE,
+ radar_detect_width);

- err = cfg80211_can_use_chan(rdev, wdev, params->chandef.chan,
- params->channel_fixed
- ? CHAN_MODE_SHARED
- : CHAN_MODE_EXCLUSIVE);
if (err) {
wdev->connect_keys = NULL;
return err;
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index cbbef88..d10410a 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -354,6 +354,7 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
[NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
[NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
[NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
+ [NL80211_ATTR_CONTROL_PORT_DFS] = { .type = NLA_FLAG },
};

/* policy for the key attributes */
@@ -5722,9 +5723,9 @@ skip_beacons:
if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
return -EINVAL;

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

+ ibss.control_port_dfs =
+ nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_DFS]);
+
err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
if (err)
kfree(connkeys);
diff --git a/net/wireless/util.c b/net/wireless/util.c
index ce090c1..beee988 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -1255,8 +1255,15 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
case NL80211_IFTYPE_MESH_POINT:
case NL80211_IFTYPE_P2P_GO:
case NL80211_IFTYPE_WDS:
- radar_required = !!(chan &&
- (chan->flags & IEEE80211_CHAN_RADAR));
+ /* if the interface could potentially choose a DFS channel,
+ * then mark DFS as required.
+ */
+ if (!chan) {
+ if (chanmode != CHAN_MODE_UNDEFINED && radar_detect)
+ radar_required = true;
+ break;
+ }
+ radar_required = !!(chan->flags & IEEE80211_CHAN_RADAR);
break;
case NL80211_IFTYPE_P2P_CLIENT:
case NL80211_IFTYPE_STATION:
--
1.7.10.4


2013-10-02 12:40:10

by Simon Wunderlich

[permalink] [raw]
Subject: Re: [PATCH 2/4] nl80211/cfg80211: enable DFS for IBSS mode

On Tue, Oct 01, 2013 at 01:09:17PM +0200, Johannes Berg wrote:
> On Tue, 2013-09-03 at 19:43 +0200, Simon Wunderlich wrote:
> > 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_CONTROL_PORT_DFS attribute when joining the IBSS.
>
> I don't like that name, it makes no sense. This has nothing to do with
> the port control (802.1X-style) at all.
>

How about NL80211_ATTR_DFS_CAPABLE instead?


> > If this attribute is supplied, DFS channels may be used if the driver
> > supports it. Support will be checked even if a channel without DFS will
> > be joined, as the channel might change later due to scan activity or
> > channel switch announcements.
>
> You also really should document *what* is required of userspace here.
> You're kinda saying this needs to be implemented, but not saying what
> needs to be done. I can't even tell - what does it really have to do?

Yeah, I should document this a little more: Userspace should react to
radar events and apprioately switch the channel when this happens. As
non-capable tools (like wpa_supplicant in it's current state) do not
react on radar events but might select DFS channels when available, there
might be non-conforming behaviour. Therefore I'm introducing this flag.

Userspace programs are supposed to set this flag when they have channel
management and radar avoidance/channel change functionality is implemented
to unlock DFS channels.

> Don't you implement most of it in patches 3 and 4 anyway in the kernel?

Nope, I don't.

I can resend the patchset with some more documentation on this.

Thanks,
Simon


Attachments:
(No filename) (1.64 kB)
signature.asc (198.00 B)
Digital signature
Download all attachments

2013-10-02 16:07:34

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 2/4] nl80211/cfg80211: enable DFS for IBSS mode

On Wed, 2013-10-02 at 14:40 +0200, Simon Wunderlich wrote:

> > > NL80211_ATTR_CONTROL_PORT_DFS attribute when joining the IBSS.
> >
> > I don't like that name, it makes no sense. This has nothing to do with
> > the port control (802.1X-style) at all.
>
> How about NL80211_ATTR_DFS_CAPABLE instead?

That seems also confusing, like a hardware capability or something...

Maybe rather "NL80211_ATTR_HANDLE_DFS" or something?

> Yeah, I should document this a little more: Userspace should react to
> radar events and apprioately switch the channel when this happens. As
> non-capable tools (like wpa_supplicant in it's current state) do not
> react on radar events but might select DFS channels when available, there
> might be non-conforming behaviour. Therefore I'm introducing this flag.
>
> Userspace programs are supposed to set this flag when they have channel
> management and radar avoidance/channel change functionality is implemented
> to unlock DFS channels.

I think we may we want some safeguard, e.g. only give the userspace a
second or so to react and tear down the IBSS otherwise? Even with
userspace that is capable of handling it, it could have crashed and the
IBSS will continue operating in that case since we don't tear down the
IBSS when it crashes. Or we could do that, require userspace to keep the
nl80211 socket open, but the timing seems easier?

> I can resend the patchset with some more documentation on this.

Thanks.

johannes


2013-10-01 11:06:39

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/4] nl80211: allow CAC only if no operation is going on

On Tue, 2013-09-03 at 19:43 +0200, Simon Wunderlich wrote:
> A CAC should fail if it is triggered while the interface is already
> running.

Applied, though this is a bit questionable - it forces every driver
implementing this to have the same carrier semantics as mac80211. That
might very well be a good thing, but those semantics aren't really
documented.

johannes


2013-10-01 11:09:21

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 2/4] nl80211/cfg80211: enable DFS for IBSS mode

On Tue, 2013-09-03 at 19:43 +0200, Simon Wunderlich wrote:
> 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_CONTROL_PORT_DFS attribute when joining the IBSS.

I don't like that name, it makes no sense. This has nothing to do with
the port control (802.1X-style) at all.

> If this attribute is supplied, DFS channels may be used if the driver
> supports it. Support will be checked even if a channel without DFS will
> be joined, as the channel might change later due to scan activity or
> channel switch announcements.

You also really should document *what* is required of userspace here.
You're kinda saying this needs to be implemented, but not saying what
needs to be done. I can't even tell - what does it really have to do?
Don't you implement most of it in patches 3 and 4 anyway in the kernel?

johannes