Skip to contentSkip to conversation

nl80211/cfg80211: add radar detection command/event

PATCH Superseded Victor Goldenshtein 3 participants 33 messages Jun 19, 2012 – Jun 21, 2012

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/7 nl80211/cfg80211: add radar detection command/event

Add new NL80211_CMD_RADAR_DETECT, which triggers radar detection in the driver/FW, this command will also notify usermode with 'radar detected' event.
Once radar detection has started it should continuously monitor for radars as long as the channel is active.

Add new NL80211_FEATURE_DFS attribute which indicates that driver/HW supports radar detection.

---

v2:

1. Fixed bad indentation in:
nl80211/cfg80211: add ability to enable TX on op-channel
mac80211: add ap channel switch command/event
mac80211: add DFS support to monitor interface

2. Updated commit message in:
mac80211: add DFS support to monitor interface
mac80211: add ap channel switch command/event

 include/linux/nl80211.h |    7 +++++
 include/net/cfg80211.h  |   20 +++++++++++++
 net/wireless/core.h     |    6 ++++
 net/wireless/mlme.c     |   36 ++++++++++++++++++++++++
 net/wireless/nl80211.c  |   69 +++++++++++++++++++++++++++++++++++++++++++++++
 net/wireless/nl80211.h  |    5 +++
 6 files changed, 143 insertions(+), 0 deletions(-)
include/linux/nl80211.h +7 -0
index a6959f7..ea6ce93 100644
@@ -553,6 +553,9 @@
  *	%NL80211_ATTR_IFINDEX is now on %NL80211_ATTR_WIPHY_FREQ with
  *	%NL80211_ATTR_WIPHY_CHANNEL_TYPE.
  *
+ * @NL80211_CMD_RADAR_DETECT: Start radar detection in the driver/HW. Once
+ *	radar detected usermode notified with this event.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -696,6 +699,8 @@ enum nl80211_commands {
 
 	NL80211_CMD_CH_SWITCH_NOTIFY,
 
+	NL80211_CMD_RADAR_DETECT,
+
 	/* add new commands above here */
 
 	/* used to define NL80211_CMD_MAX below */
@@ -2867,11 +2872,13 @@ enum nl80211_ap_sme_features {
  * @NL80211_FEATURE_HT_IBSS: This driver supports IBSS with HT datarates.
  * @NL80211_FEATURE_INACTIVITY_TIMER: This driver takes care of freeing up
  *	the connected inactive stations in AP mode.
+ * @NL80211_FEATURE_DFS: Radar detection is supported in the HW/driver.
  */
 enum nl80211_feature_flags {
 	NL80211_FEATURE_SK_TX_STATUS	= 1 << 0,
 	NL80211_FEATURE_HT_IBSS		= 1 << 1,
 	NL80211_FEATURE_INACTIVITY_TIMER = 1 << 2,
+	NL80211_FEATURE_DFS		= 1 << 3,
 };
 
 /**
include/net/cfg80211.h +20 -0
index 0289d4c..523d953 100644
@@ -127,6 +127,9 @@ enum ieee80211_channel_flags {
  *	to enable this, this is useful only on 5 GHz band.
  * @orig_mag: internal use
  * @orig_mpwr: internal use
+ * @radar_detect_timeout: this timeout indicates the end of the channel
+ *	availability check for radar channels, only after this period the
+ *	user may initiate the tx on the channel.
  */
 struct ieee80211_channel {
 	enum ieee80211_band band;
@@ -139,6 +142,7 @@ struct ieee80211_channel {
 	bool beacon_found;
 	u32 orig_flags;
 	int orig_mag, orig_mpwr;
+	unsigned long radar_detect_timeout;
 };
 
 /**
@@ -1525,6 +1529,8 @@ struct cfg80211_gtk_rekey_data {
  * @get_et_strings:  Ethtool API to get a set of strings to describe stats
  *	and perhaps other supported types of ethtool data-sets.
  *	See @ethtool_ops.get_strings
+ *
+ * @start_radar_detection: Start radar detection in the driver.
  */
 struct cfg80211_ops {
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -1730,6 +1736,10 @@ struct cfg80211_ops {
 				struct ethtool_stats *stats, u64 *data);
 	void	(*get_et_strings)(struct wiphy *wiphy, struct net_device *dev,
 				  u32 sset, u8 *data);
+
+	int	(*start_radar_detection)(struct wiphy *wiphy,
+					 struct net_device *dev,
+					 struct ieee80211_channel *chan);
 };
 
 /*
@@ -3268,6 +3278,16 @@ void cfg80211_cqm_rssi_notify(struct net_device *dev,
 			      gfp_t gfp);
 
 /**
+ * cfg80211_radar_detected - radar detection event
+ * @dev: network device
+ * @freq: radar detected on this channel frequency (in MHz)
+ * @gfp: context flags
+ *
+ * This function is called when a radar is detected on the current channel.
+ */
+void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp);
+
+/**
  * cfg80211_cqm_pktloss_notify - notify userspace about packetloss to peer
  * @dev: network device
  * @peer: peer's MAC address
net/wireless/core.h +6 -0
index 8523f38..03e9744 100644
@@ -445,6 +445,12 @@ int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
 		      struct wireless_dev *wdev, int freq,
 		      enum nl80211_channel_type channel_type);
 
+int cfg80211_start_radar_detection(struct cfg80211_registered_device *rdev,
+				   struct net_device *dev,
+				   struct ieee80211_channel *chan);
+
+u16 cfg80211_calculate_bitrate(struct rate_info *rate);
+
 int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
 			   const u8 *rates, unsigned int n_rates,
 			   u32 *mask);
net/wireless/mlme.c +36 -0
index eb90988..a641db6 100644
@@ -16,6 +16,8 @@
 #include "core.h"
 #include "nl80211.h"
 
+#define IEEE80211_DFS_MIN_CAC_TIME_MS	60000
+
 void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
 {
 	struct wireless_dev *wdev = dev->ieee80211_ptr;
@@ -982,3 +984,37 @@ bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
 	return nl80211_unexpected_4addr_frame(dev, addr, gfp);
 }
 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
+
+int cfg80211_start_radar_detection(struct cfg80211_registered_device *rdev,
+				   struct net_device *dev,
+				   struct ieee80211_channel *chan)
+{
+	int err;
+
+	if (!rdev->ops->start_radar_detection)
+		return -EOPNOTSUPP;
+
+	err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, chan);
+	if (!err)
+		chan->radar_detect_timeout = jiffies +
+			msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
+	else
+		chan->radar_detect_timeout = 0;
+
+	return err;
+}
+
+void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp)
+{
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wiphy *wiphy = wdev->wiphy;
+	struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
+	struct ieee80211_channel *chan;
+
+	chan = ieee80211_get_channel(&rdev->wiphy, freq);
+	if (chan)
+		chan->radar_detect_timeout = 0;
+
+	nl80211_radar_detected_notify(rdev, freq, dev, gfp);
+}
+EXPORT_SYMBOL(cfg80211_radar_detected);
net/wireless/nl80211.c +69 -0

87 lines not on this page · raw message

net/wireless/nl80211.h +5 -0
index 01a1122..a333261 100644
@@ -105,6 +105,11 @@ nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
 			     struct net_device *netdev,
 			     enum nl80211_cqm_rssi_threshold_event rssi_event,
 			     gfp_t gfp);
+
+void
+nl80211_radar_detected_notify(struct cfg80211_registered_device *rdev,
+			      u16 freq, struct net_device *netdev, gfp_t gfp);
+
 void
 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
 				struct net_device *netdev, const u8 *peer,
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH v2 2/7 mac80211: add radar detection command/event

Add command to trigger radar detection in the driver/FW. Once radar detection is started it should continuously monitor for radars as long as the channel active. If radar is detected usermode notified with 'radar detected' event.

---
 include/net/mac80211.h      |   17 +++++++++++++++++
 net/mac80211/cfg.c          |   16 ++++++++++++++++
 net/mac80211/driver-ops.h   |   14 ++++++++++++++
 net/mac80211/driver-trace.h |    6 ++++++
 net/mac80211/mlme.c         |    8 ++++++++
 5 files changed, 61 insertions(+), 0 deletions(-)
include/net/mac80211.h +17 -0
index 95e39b6..a2222cf 100644
@@ -2246,6 +2246,10 @@ enum ieee80211_rate_control_changed {
  * @get_et_strings:  Ethtool API to get a set of strings to describe stats
  *	and perhaps other supported types of ethtool data-sets.
  *
+ * @start_radar_detection: Start radar detection on current operational
+ *	channel, once started it will continuously monitor for radars as long
+ *	as the channel active.
+ *
  */
 struct ieee80211_ops {
 	void (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb);
@@ -2385,6 +2389,9 @@ struct ieee80211_ops {
 	void	(*get_et_strings)(struct ieee80211_hw *hw,
 				  struct ieee80211_vif *vif,
 				  u32 sset, u8 *data);
+	int (*start_radar_detection)(struct ieee80211_hw *hw,
+				     struct ieee80211_vif *vif,
+				     struct ieee80211_channel *chan);
 };
 
 /**
@@ -3557,6 +3564,16 @@ void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
 			       gfp_t gfp);
 
 /**
+ * ieee80211_radar_detected - inform a configured connection that
+ * radar was detected on the current channel
+ *
+ * @vif: &struct ieee80211_vif pointer from the add_interface callback.
+ * @freq: frequency of the 'radar detected' channel.
+ * @gfp: context flags.
+ */
+void ieee80211_radar_detected(struct ieee80211_vif *vif, u16 freq, gfp_t gfp);
+
+/**
  * ieee80211_get_operstate - get the operstate of the vif
  *
  * @vif: &struct ieee80211_vif pointer from the add_interface callback.
net/mac80211/cfg.c +16 -0
index 7d5108a..541b274 100644
@@ -2211,6 +2211,21 @@ static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
 	return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
 }
 
+static int ieee80211_start_radar_detection(struct wiphy *wiphy,
+					   struct net_device *dev,
+					   struct ieee80211_channel *chan)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
+	int ret;
+
+	if (!local->ops->start_radar_detection)
+		return -EOPNOTSUPP;
+
+	ret = drv_start_radar_detection(local, sdata, chan);
+	return ret;
+}
+
 static enum work_done_result
 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
 {
@@ -2979,4 +2994,5 @@ struct cfg80211_ops mac80211_config_ops = {
 	.get_et_sset_count = ieee80211_get_et_sset_count,
 	.get_et_stats = ieee80211_get_et_stats,
 	.get_et_strings = ieee80211_get_et_strings,
+	.start_radar_detection = ieee80211_start_radar_detection,
 };
net/mac80211/driver-ops.h +14 -0
index 6d33a0c..57185df 100644
@@ -329,6 +329,20 @@ static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
 	trace_drv_return_void(local);
 }
 
+static inline int drv_start_radar_detection(struct ieee80211_local *local,
+					    struct ieee80211_sub_if_data *sdata,
+					    struct ieee80211_channel *chan)
+{
+	int ret;
+
+	might_sleep();
+
+	trace_drv_start_radar_detection(local, sdata);
+	ret = local->ops->start_radar_detection(&local->hw, &sdata->vif, chan);
+	trace_drv_return_int(local, ret);
+	return ret;
+}
+
 static inline int
 drv_sched_scan_start(struct ieee80211_local *local,
 		     struct ieee80211_sub_if_data *sdata,
net/mac80211/driver-trace.h +6 -0
index 6de00b2..4112aa3 100644
@@ -484,6 +484,12 @@ DEFINE_EVENT(local_sdata_evt, drv_cancel_hw_scan,
 	TP_ARGS(local, sdata)
 );
 
+DEFINE_EVENT(local_sdata_evt, drv_start_radar_detection,
+	TP_PROTO(struct ieee80211_local *local,
+		 struct ieee80211_sub_if_data *sdata),
+	TP_ARGS(local, sdata)
+);
+
 DEFINE_EVENT(local_sdata_evt, drv_sched_scan_start,
 	TP_PROTO(struct ieee80211_local *local,
 		 struct ieee80211_sub_if_data *sdata),
net/mac80211/mlme.c +8 -0
index 66e4fcd..37ed827 100644
@@ -3562,6 +3562,14 @@ void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
 }
 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
 
+void ieee80211_radar_detected(struct ieee80211_vif *vif, u16 freq, gfp_t gfp)
+{
+	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
+
+	cfg80211_radar_detected(sdata->dev, freq, gfp);
+}
+EXPORT_SYMBOL(ieee80211_radar_detected);
+
 unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
 {
 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH v2 3/7 nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Victor Goldenshtein

The dfs master device should monitor radar channels for potential radar interference for a minimum of CAC (channel availability check) time, during this period no tx can occur. If no radar interference is detected the dfs master may initiate the tx with new NL80211_CMD_DFS_ENABLE_TX command.

If this command is invoked prior performing a CAC or the time passed sines the beginning of the CAC is less than min CAC time (60 sec), -EPERM is returned.

---
 include/linux/nl80211.h |   11 +++++++++++
 include/net/cfg80211.h  |    5 +++++
 net/wireless/nl80211.c  |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)
include/linux/nl80211.h +11 -0
index ea6ce93..2f869a4 100644
@@ -556,6 +556,15 @@
  * @NL80211_CMD_RADAR_DETECT: Start radar detection in the driver/HW. Once
  *	radar detected usermode notified with this event.
  *
+ * @NL80211_CMD_DFS_ENABLE_TX: Initiate tx after verifying radar clearness on
+ *	dfs channel. The dfs master device should monitor radar channels
+ *	for potential radar interference for a minimum of CAC (channel
+ *	availability check) time, during this period no tx can occur. If no
+ *	radar interference is detected during this period the dfs master may
+ *	initiate the tx. If this command is invoked prior performing a CAC or
+ *	the time passed sines the beginning of the CAC is less than
+ *	NL80211_DFS_MIN_CAC_TIME_MS, -EPERM is returned.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -701,6 +710,8 @@ enum nl80211_commands {
 
 	NL80211_CMD_RADAR_DETECT,
 
+	NL80211_CMD_DFS_ENABLE_TX,
+
 	/* add new commands above here */
 
 	/* used to define NL80211_CMD_MAX below */
include/net/cfg80211.h +5 -0
index 523d953..f7fe44e 100644
@@ -1531,6 +1531,8 @@ struct cfg80211_gtk_rekey_data {
  *	See @ethtool_ops.get_strings
  *
  * @start_radar_detection: Start radar detection in the driver.
+ *
+ * @dfs_en_tx: Enable tx after radar interference check.
  */
 struct cfg80211_ops {
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -1740,6 +1742,9 @@ struct cfg80211_ops {
 	int	(*start_radar_detection)(struct wiphy *wiphy,
 					 struct net_device *dev,
 					 struct ieee80211_channel *chan);
+
+	int	(*dfs_en_tx)(struct wiphy *wiphy, struct net_device *dev,
+			     struct ieee80211_channel *chan);
 };
 
 /*
net/wireless/nl80211.c +36 -0
index 573c966..966f7cc 100644
@@ -4273,6 +4273,34 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
 	return cfg80211_start_radar_detection(rdev, dev, chan);
 }
 
+static int nl80211_dfs_en_tx(struct sk_buff *skb, struct genl_info *info)
+{
+	struct cfg80211_registered_device *rdev = info->user_ptr[0];
+	struct net_device *dev = info->user_ptr[1];
+	bool dfs_supported = !!(rdev->wiphy.features & NL80211_FEATURE_DFS);
+	struct ieee80211_channel *chan;
+	int freq;
+
+	if (!rdev->ops->dfs_en_tx || !dfs_supported)
+		return -EOPNOTSUPP;
+
+	if (info->attrs[NL80211_ATTR_WIPHY_FREQ])
+		freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
+	else
+		return -EINVAL;
+
+	chan = ieee80211_get_channel(&rdev->wiphy, freq);
+	if (!chan)
+		return -EINVAL;
+
+	if ((!chan->radar_detect_timeout ||
+	     time_is_after_jiffies(chan->radar_detect_timeout)) &&
+	    (chan->flags & IEEE80211_CHAN_RADAR))
+		return -EPERM;
+
+	return rdev->ops->dfs_en_tx(&rdev->wiphy, dev, chan);
+}
+
 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
 			    u32 seq, int flags,
 			    struct cfg80211_registered_device *rdev,
@@ -7030,6 +7058,14 @@ static struct genl_ops nl80211_ops[] = {
 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
 				  NL80211_FLAG_NEED_RTNL,
 	},
+	{
+		.cmd = NL80211_CMD_DFS_ENABLE_TX,
+		.doit = nl80211_dfs_en_tx,
+		.policy = nl80211_policy,
+		.flags = GENL_ADMIN_PERM,
+		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
+				  NL80211_FLAG_NEED_RTNL,
+	},
 
 };
 
Signature · 1 line
1.7.5.4
#16 lore raw

PATCH v2 4/7 mac80211: add ability to enable TX on op-channel

In reply to Victor Goldenshtein

Prior starting tx on DFS channels, the DFS master device shall perform a Channel Availability Check to ensure that there is no radar interference on those channels. Once CAC done, the tx can be enabled with ieee80211_dfs_en_tx().

---
 include/net/mac80211.h      |    4 ++++
 net/mac80211/cfg.c          |   15 +++++++++++++++
 net/mac80211/driver-ops.h   |   14 ++++++++++++++
 net/mac80211/driver-trace.h |    6 ++++++
 4 files changed, 39 insertions(+), 0 deletions(-)
include/net/mac80211.h +4 -0
index a2222cf..82e5ee7 100644
@@ -2249,6 +2249,8 @@ enum ieee80211_rate_control_changed {
  * @start_radar_detection: Start radar detection on current operational
  *	channel, once started it will continuously monitor for radars as long
  *	as the channel active.
+ * @dfs_en_tx: Once channel pass the DFS initial channel availability check,
+ *	initiate the tx on the channel with this command.
  *
  */
 struct ieee80211_ops {
@@ -2392,6 +2394,8 @@ struct ieee80211_ops {
 	int (*start_radar_detection)(struct ieee80211_hw *hw,
 				     struct ieee80211_vif *vif,
 				     struct ieee80211_channel *chan);
+	int (*dfs_en_tx)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+			 struct ieee80211_channel *chan);
 };
 
 /**
net/mac80211/cfg.c +15 -0
index 541b274..a48d055 100644
@@ -2226,6 +2226,20 @@ static int ieee80211_start_radar_detection(struct wiphy *wiphy,
 	return ret;
 }
 
+static int ieee80211_dfs_en_tx(struct wiphy *wiphy, struct net_device *dev,
+			       struct ieee80211_channel *chan)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
+	int ret = -ENOENT;
+
+	if (!local->ops->dfs_en_tx)
+		return -EOPNOTSUPP;
+
+	ret = drv_dfs_en_tx(local, sdata, chan);
+	return ret;
+}
+
 static enum work_done_result
 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
 {
@@ -2995,4 +3009,5 @@ struct cfg80211_ops mac80211_config_ops = {
 	.get_et_stats = ieee80211_get_et_stats,
 	.get_et_strings = ieee80211_get_et_strings,
 	.start_radar_detection = ieee80211_start_radar_detection,
+	.dfs_en_tx = ieee80211_dfs_en_tx,
 };
net/mac80211/driver-ops.h +14 -0
index 57185df..f49b76b 100644
@@ -343,6 +343,20 @@ static inline int drv_start_radar_detection(struct ieee80211_local *local,
 	return ret;
 }
 
+static inline int drv_dfs_en_tx(struct ieee80211_local *local,
+				struct ieee80211_sub_if_data *sdata,
+				struct ieee80211_channel *chan)
+{
+	int ret;
+
+	might_sleep();
+
+	trace_drv_dfs_en_tx(local, sdata);
+	ret = local->ops->dfs_en_tx(&local->hw, &sdata->vif, chan);
+	trace_drv_return_int(local, ret);
+	return ret;
+}
+
 static inline int
 drv_sched_scan_start(struct ieee80211_local *local,
 		     struct ieee80211_sub_if_data *sdata,
net/mac80211/driver-trace.h +6 -0
index 4112aa3..6df02c4 100644
@@ -490,6 +490,12 @@ DEFINE_EVENT(local_sdata_evt, drv_start_radar_detection,
 	TP_ARGS(local, sdata)
 );
 
+DEFINE_EVENT(local_sdata_evt, drv_dfs_en_tx,
+	TP_PROTO(struct ieee80211_local *local,
+		 struct ieee80211_sub_if_data *sdata),
+	TP_ARGS(local, sdata)
+);
+
 DEFINE_EVENT(local_sdata_evt, drv_sched_scan_start,
 	TP_PROTO(struct ieee80211_local *local,
 		 struct ieee80211_sub_if_data *sdata),
Signature · 1 line
1.7.5.4
#17 lore raw

PATCH v2 5/7 nl80211/cfg80211: add ap channel switch command/event

In reply to Victor Goldenshtein

Add NL80211_CMD_AP_CHANNEL_SWITCH command/event which triggers an AP channel switch process and notifies usermode about channel switch complete event, once it completed.

Usermode (hostapd) is responsible to update the channel switch announcement IE in the beacon prior and after the channel switch operation.

---
 include/linux/nl80211.h |   25 ++++++++++++++
 include/net/cfg80211.h  |   17 +++++++++
 net/wireless/mlme.c     |   11 ++++++
 net/wireless/nl80211.c  |   84 +++++++++++++++++++++++++++++++++++++++++++++++
 net/wireless/nl80211.h  |    5 +++
 5 files changed, 142 insertions(+), 0 deletions(-)
include/linux/nl80211.h +25 -0
index 2f869a4..4279507 100644
@@ -565,6 +565,15 @@
  *	the time passed sines the beginning of the CAC is less than
  *	NL80211_DFS_MIN_CAC_TIME_MS, -EPERM is returned.
  *
+ * @NL80211_CMD_AP_CHANNEL_SWITCH: Perform a channel switch in the driver (for
+ *	AP/GO).
+ *	%NL80211_ATTR_WIPHY_FREQ: new channel frequency.
+ *	%NL80211_ATTR_CH_SWITCH_BLOCK_TX: block tx on the current channel.
+ *	%NL80211_ATTR_CH_SWITCH_POST_BLOCK_TX: block tx on the target channel.
+ *	%NL80211_FREQ_ATTR_CH_SWITCH_COUNT: number of TBTT's until the channel
+ *	switch event.
+ *	This command will also notify about channel switch complete event.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -712,6 +721,8 @@ enum nl80211_commands {
 
 	NL80211_CMD_DFS_ENABLE_TX,
 
+	NL80211_CMD_AP_CHANNEL_SWITCH,
+
 	/* add new commands above here */
 
 	/* used to define NL80211_CMD_MAX below */
@@ -1238,6 +1249,14 @@ enum nl80211_commands {
  * @NL80211_ATTR_BG_SCAN_PERIOD: Background scan period in seconds
  *      or 0 to disable background scan.
  *
+ * @NL80211_ATTR_CH_SWITCH_COUNT: the number of TBTT's until the channel
+ *	switch event
+ * @NL80211_ATTR_CH_SWITCH_BLOCK_TX: block tx on the current channel before the
+ *	channel switch operation.
+ * @NL80211_ATTR_CH_SWITCH_POST_BLOCK_TX: block tx on the target channel after
+ *	the channel switch operation, should be set if the target channel is
+ *	DFS channel.
+ *
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
  */
@@ -1489,6 +1508,10 @@ enum nl80211_attrs {
 
 	NL80211_ATTR_BG_SCAN_PERIOD,
 
+	NL80211_ATTR_CH_SWITCH_COUNT,
+	NL80211_ATTR_CH_SWITCH_BLOCK_TX,
+	NL80211_ATTR_CH_SWITCH_POST_BLOCK_TX,
+
 	/* add attributes here, update the policy in nl80211.c */
 
 	__NL80211_ATTR_AFTER_LAST,
@@ -2884,12 +2907,14 @@ enum nl80211_ap_sme_features {
  * @NL80211_FEATURE_INACTIVITY_TIMER: This driver takes care of freeing up
  *	the connected inactive stations in AP mode.
  * @NL80211_FEATURE_DFS: Radar detection is supported in the HW/driver.
+ * @NL80211_FEATURE_AP_CH_SWITCH: This driver supports AP channel switch.
  */
 enum nl80211_feature_flags {
 	NL80211_FEATURE_SK_TX_STATUS	= 1 << 0,
 	NL80211_FEATURE_HT_IBSS		= 1 << 1,
 	NL80211_FEATURE_INACTIVITY_TIMER = 1 << 2,
 	NL80211_FEATURE_DFS		= 1 << 3,
+	NL80211_FEATURE_AP_CH_SWITCH	= 1 << 4,
 };
 
 /**
include/net/cfg80211.h +17 -0
index f7fe44e..a4994a3 100644
@@ -1533,6 +1533,8 @@ struct cfg80211_gtk_rekey_data {
  * @start_radar_detection: Start radar detection in the driver.
  *
  * @dfs_en_tx: Enable tx after radar interference check.
+ *
+ * @ap_channel_switch: Perform AP channel switch.
  */
 struct cfg80211_ops {
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -1745,6 +1747,11 @@ struct cfg80211_ops {
 
 	int	(*dfs_en_tx)(struct wiphy *wiphy, struct net_device *dev,
 			     struct ieee80211_channel *chan);
+
+	int	(*ap_channel_switch)(struct wiphy *wiphy, struct net_device *dev,
+				     u32 count, bool block_tx,
+				     bool post_switch_block_tx,
+				     struct ieee80211_channel *new_ch);
 };
 
 /*
@@ -3293,6 +3300,16 @@ void cfg80211_cqm_rssi_notify(struct net_device *dev,
 void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp);
 
 /**
+ * cfg80211_ap_ch_switch_complete_notify - channel switch complete event
+ * @dev: network device
+ * @gfp: context flags
+ *
+ * Notify userspace about channel switch complete event.
+ */
+void cfg80211_ap_ch_switch_complete_notify(struct net_device *dev,
+					   u16 freq, gfp_t gfp);
+
+/**
  * cfg80211_cqm_pktloss_notify - notify userspace about packetloss to peer
  * @dev: network device
  * @peer: peer's MAC address
net/wireless/mlme.c +11 -0
index a641db6..d45c875 100644
@@ -1018,3 +1018,14 @@ void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp)
 	nl80211_radar_detected_notify(rdev, freq, dev, gfp);
 }
 EXPORT_SYMBOL(cfg80211_radar_detected);
+
+void cfg80211_ap_ch_switch_complete_notify(struct net_device *dev,
+					   u16 freq, gfp_t gfp)
+{
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wiphy *wiphy = wdev->wiphy;
+	struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
+
+	nl80211_ap_ch_switch_complete_notify(rdev, freq, dev, gfp);
+}
+EXPORT_SYMBOL(cfg80211_ap_ch_switch_complete_notify);
net/wireless/nl80211.c +84 -0

108 lines not on this page · raw message

net/wireless/nl80211.h +5 -0
index a333261..aca0de3 100644
@@ -111,6 +111,11 @@ nl80211_radar_detected_notify(struct cfg80211_registered_device *rdev,
 			      u16 freq, struct net_device *netdev, gfp_t gfp);
 
 void
+nl80211_ap_ch_switch_complete_notify(struct cfg80211_registered_device *rdev,
+				     u16 freq, struct net_device *netdev,
+				     gfp_t gfp);
+
+void
 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
 				struct net_device *netdev, const u8 *peer,
 				u32 num_packets, gfp_t gfp);
Signature · 1 line
1.7.5.4
#23 lore raw

PATCH v2 6/7 mac80211: add ap channel switch command/event

In reply to Victor Goldenshtein

Add ieee80211_ap_process_chanswitch(), to handle a channel switch request for AP.

Add ieee80211_ap_ch_switch_complete_notify() which notifies upper layers about channel switch complete event.

---
 include/net/mac80211.h      |   39 +++++++++++++++++++++++++++++++++++++++
 net/mac80211/cfg.c          |   26 ++++++++++++++++++++++++++
 net/mac80211/driver-ops.h   |   10 ++++++++++
 net/mac80211/driver-trace.h |   31 +++++++++++++++++++++++++++++++
 net/mac80211/main.c         |    3 +++
 net/mac80211/mlme.c         |    9 +++++++++
 6 files changed, 118 insertions(+), 0 deletions(-)
include/net/mac80211.h +39 -0
index 82e5ee7..79239a0 100644
@@ -865,6 +865,32 @@ struct ieee80211_channel_switch {
 };
 
 /**
+ * struct ieee80211_ap_channel_switch - holds the ap channel switch data
+ *
+ * The information provided in this structure is required for the ap channel
+ * switch operation.
+ *
+ * @timestamp: value in microseconds of the 64-bit Time Synchronization
+ *	Function (TSF) timer when the frame containing the channel switch
+ *	announcement was received. This is simply the rx.mactime parameter
+ *	the driver passed into mac80211.
+ * @block_tx: Indicates whether transmission must be blocked before the
+ *	scheduled channel switch, as indicated by the AP.
+ * @post_switch_block_tx: Indicates whether transmission must be blocked after
+ *	the scheduled channel switch, this should be set if the target channel
+ *	is DFS channel.
+ * @channel: the new channel to switch to
+ * @count: the number of TBTT's until the channel switch event
+ */
+struct ieee80211_ap_channel_switch {
+	u64 timestamp;
+	bool block_tx;
+	bool post_switch_block_tx;
+	struct ieee80211_channel *channel;
+	u8 count;
+};
+
+/**
  * enum ieee80211_vif_flags - virtual interface flags
  *
  * @IEEE80211_VIF_BEACON_FILTER: the device performs beacon filtering
@@ -2354,6 +2380,8 @@ struct ieee80211_ops {
 	void (*flush)(struct ieee80211_hw *hw, bool drop);
 	void (*channel_switch)(struct ieee80211_hw *hw,
 			       struct ieee80211_channel_switch *ch_switch);
+	void (*ap_channel_switch)(struct ieee80211_hw *hw,
+			      struct ieee80211_ap_channel_switch *ap_ch_switch);
 	int (*napi_poll)(struct ieee80211_hw *hw, int budget);
 	int (*set_antenna)(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant);
 	int (*get_antenna)(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
@@ -3578,6 +3606,17 @@ void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
 void ieee80211_radar_detected(struct ieee80211_vif *vif, u16 freq, gfp_t gfp);
 
 /**
+ * ieee80211_ap_ch_switch_complete_notify - inform a configured connection that
+ * channel switch is complete
+ *
+ * @vif: &struct ieee80211_vif pointer from the add_interface callback.
+ * @gfp: context flags
+ *
+ */
+void ieee80211_ap_ch_switch_complete_notify(struct ieee80211_vif *vif,
+					    u16 freq, gfp_t gfp);
+
+/**
  * ieee80211_get_operstate - get the operstate of the vif
  *
  * @vif: &struct ieee80211_vif pointer from the add_interface callback.
net/mac80211/cfg.c +26 -0
index a48d055..d017972 100644
@@ -2240,6 +2240,31 @@ static int ieee80211_dfs_en_tx(struct wiphy *wiphy, struct net_device *dev,
 	return ret;
 }
 
+static int ieee80211_ap_process_chanswitch(struct wiphy *wiphy,
+					   struct net_device *dev,
+					   u32 count, bool block_tx,
+					   bool post_switch_block_tx,
+					   struct ieee80211_channel *new_ch)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
+	struct ieee80211_ap_channel_switch ap_ch_switch;
+
+	if (!local->ops->channel_switch)
+		return -EOPNOTSUPP;
+
+	memset(&ap_ch_switch, 0, sizeof(ap_ch_switch));
+	ap_ch_switch.channel = new_ch;
+	ap_ch_switch.count = count;
+	ap_ch_switch.block_tx = block_tx;
+	ap_ch_switch.post_switch_block_tx = post_switch_block_tx;
+
+	mutex_lock(&local->mtx);
+	drv_ap_channel_switch(local, &ap_ch_switch);
+	mutex_unlock(&local->mtx);
+	return 0;
+}
+
 static enum work_done_result
 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
 {
@@ -3010,4 +3035,5 @@ struct cfg80211_ops mac80211_config_ops = {
 	.get_et_strings = ieee80211_get_et_strings,
 	.start_radar_detection = ieee80211_start_radar_detection,
 	.dfs_en_tx = ieee80211_dfs_en_tx,
+	.ap_channel_switch = ieee80211_ap_process_chanswitch,
 };
net/mac80211/driver-ops.h +10 -0
index f49b76b..7f7e6d0 100644
@@ -711,6 +711,16 @@ static inline void drv_channel_switch(struct ieee80211_local *local,
 	trace_drv_return_void(local);
 }
 
+static inline void
+drv_ap_channel_switch(struct ieee80211_local *local,
+		      struct ieee80211_ap_channel_switch *ap_ch_switch)
+{
+	might_sleep();
+
+	trace_drv_ap_channel_switch(local, ap_ch_switch);
+	local->ops->ap_channel_switch(&local->hw, ap_ch_switch);
+	trace_drv_return_void(local);
+}
 
 static inline int drv_set_antenna(struct ieee80211_local *local,
 				  u32 tx_ant, u32 rx_ant)
net/mac80211/driver-trace.h +31 -0
index 6df02c4..972be66 100644
@@ -927,6 +927,37 @@ TRACE_EVENT(drv_channel_switch,
 	)
 );
 
+TRACE_EVENT(drv_ap_channel_switch,
+	TP_PROTO(struct ieee80211_local *local,
+		 struct ieee80211_ap_channel_switch *ap_ch_switch),
+
+	TP_ARGS(local, ap_ch_switch),
+
+	TP_STRUCT__entry(
+		LOCAL_ENTRY
+		__field(u64, timestamp)
+		__field(bool, block_tx)
+		__field(bool, post_switch_block_tx)
+		__field(u16, freq)
+		__field(u8, count)
+	),
+
+	TP_fast_assign(
+		LOCAL_ASSIGN;
+		__entry->timestamp = ap_ch_switch->timestamp;
+		__entry->block_tx = ap_ch_switch->block_tx;
+		__entry->post_switch_block_tx =
+			ap_ch_switch->post_switch_block_tx;
+		__entry->freq = ap_ch_switch->channel->center_freq;
+		__entry->count = ap_ch_switch->count;
+	),
+
+	TP_printk(
+		LOCAL_PR_FMT " new freq:%u count:%d",
+		LOCAL_PR_ARG, __entry->freq, __entry->count
+	)
+);
+
 TRACE_EVENT(drv_set_antenna,
 	TP_PROTO(struct ieee80211_local *local, u32 tx_ant, u32 rx_ant, int ret),
 
net/mac80211/main.c +3 -0
index f5548e9..18094cc 100644
@@ -567,6 +567,9 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
 	wiphy->features = NL80211_FEATURE_SK_TX_STATUS |
 			  NL80211_FEATURE_HT_IBSS;
 
+	if (ops->ap_channel_switch)
+		wiphy->features |= NL80211_FEATURE_AP_CH_SWITCH;
+
 	if (!ops->set_key)
 		wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
 
net/mac80211/mlme.c +9 -0
index 37ed827..ab7e430 100644
@@ -3570,6 +3570,15 @@ void ieee80211_radar_detected(struct ieee80211_vif *vif, u16 freq, gfp_t gfp)
 }
 EXPORT_SYMBOL(ieee80211_radar_detected);
 
+void ieee80211_ap_ch_switch_complete_notify(struct ieee80211_vif *vif,
+					    u16 freq, gfp_t gfp)
+{
+	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
+
+	cfg80211_ap_ch_switch_complete_notify(sdata->dev, freq, gfp);
+}
+EXPORT_SYMBOL(ieee80211_ap_ch_switch_complete_notify);
+
 unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
 {
 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Signature · 1 line
1.7.5.4
#25 lore raw

PATCH v2 7/7 mac80211: add DFS support to monitor interface

In reply to Victor Goldenshtein

AP mode uses monitor interfaces to transmit
management frames which were blocked for "radar
channels" until now.

Stop dropping packets if we are on 'radar channel' and the DFS is enabled.

---
 net/mac80211/tx.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
net/mac80211/tx.c +8 -6
index e453212..8c7f365 100644
@@ -1595,6 +1595,8 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
 	struct ieee80211_sub_if_data *tmp_sdata, *sdata;
 	u16 len_rthdr;
 	int hdrlen;
+	bool dfs_supported = !!(local->hw.wiphy->features &
+				NL80211_FEATURE_DFS);
 
 	/*
 	 * Frame injection is not allowed if beaconing is not allowed
@@ -1607,13 +1609,13 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
 	 * flag.
 	 *
 	 * Since AP mode uses monitor interfaces to inject/TX management
-	 * frames we can make AP mode the exception to this rule once it
-	 * supports radar detection as its implementation can deal with
-	 * radar detection by itself. We can do that later by adding a
-	 * monitor flag interfaces used for AP support.
+	 * frames we can make AP mode the exception to this rule, in the
+	 * case the driver supports radar detection, allow usage of radar
+	 * channels.
 	 */
-	if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
-	     IEEE80211_CHAN_PASSIVE_SCAN)))
+	if ((!(chan->flags & IEEE80211_CHAN_RADAR) || !dfs_supported) &&
+	    ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
+			     IEEE80211_CHAN_PASSIVE_SCAN))))
 		goto fail;
 
 	/* check for not even having the fixed radiotap header part */
Signature · 1 line
1.7.5.4
maintainer
#28 lore raw
In reply to Victor Goldenshtein

include/linux/nl80211.h enum nl80211_commands { · line 702

Quoted 1 line · Victor Goldenshtein
include/linux/nl80211.h +1 -0
+	NL80211_CMD_RADAR_DETECT,

Is there no need to ever stop radar detection?

Quoted 3 lines

+ * @radar_detect_timeout: this timeout indicates the end of the channel
+ * availability check for radar channels, only after this period the
+ * user may initiate the tx on the channel.

units? internal use, or for use by drivers? should it really be stored in the global channel struct that could be shared for multiple devices?

Quoted 9 lines

/**
+ * cfg80211_radar_detected - radar detection event
+ * @dev: network device
+ * @freq: radar detected on this channel frequency (in MHz)
+ * @gfp: context flags
+ *
+ * This function is called when a radar is detected on the current channel.
+ */
+void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp);

Better to pass the channel pointer?

Quoted 1 line

+u16 cfg80211_calculate_bitrate(struct rate_info *rate);

??

net/wireless/mlme.c bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, · line 1016

Quoted 10 lines
net/wireless/mlme.c +10 -0
+void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp)
+{
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wiphy *wiphy = wdev->wiphy;
+	struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
+	struct ieee80211_channel *chan;
+
+	chan = ieee80211_get_channel(&rdev->wiphy, freq);
+	if (chan)
+		chan->radar_detect_timeout = 0;

So how do you distinguish between having ever done radar detection and never even having started it? Also, jiffies + ... can return 0.

How do you intend to handle HT40?

johannes

maintainer
#2 lore raw

Re: [PATCH v2 2/7] mac80211: add radar detection command/event

In reply to Victor Goldenshtein

net/mac80211/mlme.c void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, · line 3567

Quoted 3 lines · Victor Goldenshtein
net/mac80211/mlme.c +3 -0
+void ieee80211_radar_detected(struct ieee80211_vif *vif, u16 freq, gfp_t gfp)
+{
+	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);

add tracing please, also maybe pass channel instead of freq

johannes

maintainer
#4 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Victor Goldenshtein

net/wireless/nl80211.c static int nl80211_start_radar_detection(struct sk_buff *skb, · line 4299

Quoted 5 lines
net/wireless/nl80211.c +4 -0
+	if ((!chan->radar_detect_timeout ||
+	     time_is_after_jiffies(chan->radar_detect_timeout)) &&
+	    (chan->flags & IEEE80211_CHAN_RADAR))
+		return -EPERM;

Ok so you reject it if it's 0, but the jiffies calculation could return 0 too.. in fact, since jiffies start at -5 minutes on boot, you might even hit it if you start radar detection 4 minutes after boot.

johannes

maintainer
#5 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

Quoted 8 lines · Johannes Berg

net/wireless/nl80211.c static int nl80211_start_radar_detection(struct sk_buff *skb, · line 4299

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+	if ((!chan->radar_detect_timeout ||
+	     time_is_after_jiffies(chan->radar_detect_timeout)) &&
+	    (chan->flags & IEEE80211_CHAN_RADAR))
+		return -EPERM;

Ok so you reject it if it's 0, but the jiffies calculation could return 0 too.. in fact, since jiffies start at -5 minutes on boot, you might even hit it if you start radar detection 4 minutes after boot.

Also, it seems that the value should be reset eventually ... at least on interface down or so. Otherwise you can start CAC, then bring the interface down to stop the device, and then bring it back up (CAC check is no longer running) and then you can use the channel after some time even though you never really checked for radar...

And if you start CAC on two different devices on the same channel, but they happen to share channel structs in the driver then this will all conflict quite badly.

This needs a lot of more thinking it seems.

johannes

maintainer
#18 lore raw

Re: [PATCH v2 5/7] nl80211/cfg80211: add ap channel switch command/event

In reply to Victor Goldenshtein

include/linux/nl80211.h line 565

Quoted 2 lines · Victor Goldenshtein
include/linux/nl80211.h +0 -0
@@ -565,6 +565,15 @@
  *	the time passed sines the beginning of the CAC is less than

interestingly now I see a typo in the previous patch: "sines"?

include/linux/nl80211.h enum nl80211_ap_sme_features { · line 2910

Quoted 2 lines
include/linux/nl80211.h +1 -0
  * @NL80211_FEATURE_DFS: Radar detection is supported in the HW/driver.
+ * @NL80211_FEATURE_AP_CH_SWITCH: This driver supports AP channel switch.

what point is there in separating these flags?

include/net/cfg80211.h struct cfg80211_ops { · line 1754

Quoted 4 lines
include/net/cfg80211.h +4 -0
+	int	(*ap_channel_switch)(struct wiphy *wiphy, struct net_device *dev,
+				     u32 count, bool block_tx,
+				     bool post_switch_block_tx,
+				     struct ieee80211_channel *new_ch);

If mac80211 needs a struct, why not have one here already rather than all the parameters?

johannes

maintainer
#24 lore raw

Re: [PATCH v2 6/7] mac80211: add ap channel switch command/event

In reply to Victor Goldenshtein

net/mac80211/mlme.c void ieee80211_radar_detected(struct ieee80211_vif *vif, u16 freq, gfp_t gfp) · line 3577

Quoted 5 lines · Victor Goldenshtein
net/mac80211/mlme.c +5 -0
+void ieee80211_ap_ch_switch_complete_notify(struct ieee80211_vif *vif,
+					    u16 freq, gfp_t gfp)
+{
+	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
+

tracing please

johannes

maintainer
#26 lore raw

Re: [PATCH v2 7/7] mac80211: add DFS support to monitor interface

In reply to Victor Goldenshtein

net/mac80211/tx.c netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, · line 1599

Quoted 2 lines · Victor Goldenshtein
net/mac80211/tx.c +2 -0
+	bool dfs_supported = !!(local->hw.wiphy->features &
+				NL80211_FEATURE_DFS);

No need for !!, also why not inline that into the condition?

johannes

#6 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Johannes Berg
Quoted 10 lines · Johannes Berg
Quoted 8 lines · Johannes Berg

net/wireless/nl80211.c static int nl80211_start_radar_detection(struct sk_buff *skb, · line 4299

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+	if ((!chan->radar_detect_timeout ||
+	     time_is_after_jiffies(chan->radar_detect_timeout)) &&
+	    (chan->flags & IEEE80211_CHAN_RADAR))
+		return -EPERM;

Ok so you reject it if it's 0, but the jiffies calculation could return 0 too.. in fact, since jiffies start at -5 minutes on boot, you might even hit it if you start radar detection 4 minutes after boot.

Quoted 6 lines

Also, it seems that the value should be reset eventually ... at least on interface down or so. Otherwise you can start CAC, then bring the interface down to stop the device, and then bring it back up (CAC check is no longer running) and then you can use the channel after some time even though you never really checked for radar...

No, if you bring it back up on the same DFS channel, radar_detection_timeout will be set back to +60s by start_radar_detection(). Looks safe to me.

Quoted 4 lines

And if you start CAC on two different devices on the same channel, but they happen to share channel structs in the driver then this will all conflict quite badly.

Details ;) In fact, if you start device A at a DFS channel and device B at the same channel 50secs later and device A did not detect radars after 60secs, ideally both should get TX enabled at the same time with B's CAC being aborted after 10secs.

For that radar_detect_timeout had to be per wiphy.

With the proposal here you have to wait for the last device to pass the CAC and if you alternatively put devices A and B up and down every 30secs you can effectively prevent them from TXing forever.

Quoted 5 lines

This needs a lot of more thinking it seems.

johannes

maintainer
#7 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

Quoted 17 lines · Zefir Kurtisi
Quoted 10 lines · Johannes Berg
Quoted 8 lines · Johannes Berg

net/wireless/nl80211.c static int nl80211_start_radar_detection(struct sk_buff *skb, · line 4299

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+	if ((!chan->radar_detect_timeout ||
+	     time_is_after_jiffies(chan->radar_detect_timeout)) &&
+	    (chan->flags & IEEE80211_CHAN_RADAR))
+		return -EPERM;

Ok so you reject it if it's 0, but the jiffies calculation could return 0 too.. in fact, since jiffies start at -5 minutes on boot, you might even hit it if you start radar detection 4 minutes after boot.

Quoted 6 lines

Also, it seems that the value should be reset eventually ... at least on interface down or so. Otherwise you can start CAC, then bring the interface down to stop the device, and then bring it back up (CAC check is no longer running) and then you can use the channel after some time even though you never really checked for radar...

Quoted 3 lines

No, if you bring it back up on the same DFS channel, radar_detection_timeout will be set back to +60s by start_radar_detection(). Looks safe to me.

You need to think a bit more outside the regular code flows ... What if I'm not calling start_radar_detection()?

johannes

#29 lore raw
In reply to Johannes Berg
Quoted 6 lines · Johannes Berg

[...]

How do you intend to handle HT40?

johannes

Not to mention VHT ante portas...

We should start with HT20 support only to have something to start testing with and add HT40 gradually (assuming it will require a lot more locations to be patched to be available initially).

maintainer
#30 lore raw
Quoted 5 lines · Zefir Kurtisi
Quoted 4 lines · Johannes Berg

[...]

How do you intend to handle HT40?

Quoted 8 lines
Quoted 2 lines

johannes

Not to mention VHT ante portas...

We should start with HT20 support only to have something to start testing with and add HT40 gradually (assuming it will require a lot more locations to be patched to be available initially).

Ok, fin with me. However, then somewhere in this code there should be a channel type check ... otherwise you can do the CAC on 20 MHz and then use 40 anyway, no? I see no channel type handling anywhere. Or just add the code to check if all affected channels had CAC to start with, that will refuse HT40 then

johannes

#8 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Johannes Berg
Quoted 18 lines · Johannes Berg
Quoted 17 lines · Zefir Kurtisi
Quoted 16 lines · Johannes Berg
Quoted 8 lines · Johannes Berg

net/wireless/nl80211.c static int nl80211_start_radar_detection(struct sk_buff *skb, · line 4299

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+	if ((!chan->radar_detect_timeout ||
+	     time_is_after_jiffies(chan->radar_detect_timeout)) &&
+	    (chan->flags & IEEE80211_CHAN_RADAR))
+		return -EPERM;

Ok so you reject it if it's 0, but the jiffies calculation could return 0 too.. in fact, since jiffies start at -5 minutes on boot, you might even hit it if you start radar detection 4 minutes after boot.

Also, it seems that the value should be reset eventually ... at least on interface down or so. Otherwise you can start CAC, then bring the interface down to stop the device, and then bring it back up (CAC check is no longer running) and then you can use the channel after some time even though you never really checked for radar...

Quoted 9 lines
Quoted 3 lines

No, if you bring it back up on the same DFS channel, radar_detection_timeout will be set back to +60s by start_radar_detection(). Looks safe to me.

You need to think a bit more outside the regular code flows ... What if I'm not calling start_radar_detection()?

johannes

If you are not calling start_radar_detection() you are not using hostapd. With the design approach we agreed on (when we initially discussed DFS years ago) to have all the logic located in hostapd, it is inevitable that those who intentionally want to bypass DFS regulatory restrictions actually can. You can always replace hostapd by some component that handles DFS control without caring the wait times.

I don't see a reliable and fail-safe method to prevent users doing that. Other than maybe moving the logic part up to mac80211 or create some additional barrier like is done with crda (which is exactly that:
additional barriers, but no prevention).

tl;dr: if the DFS regulatory compliance is provided by hostapd, it is mandatory for master mode - which ensures that start_radar_detection() is called whenever operating a DFS channel.

maintainer
#9 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

Quoted 7 lines · Zefir Kurtisi
Quoted 6 lines
Quoted 3 lines

No, if you bring it back up on the same DFS channel, radar_detection_timeout will be set back to +60s by start_radar_detection(). Looks safe to me.

You need to think a bit more outside the regular code flows ... What if I'm not calling start_radar_detection()?

Quoted 6 lines

If you are not calling start_radar_detection() you are not using hostapd. With the design approach we agreed on (when we initially discussed DFS years ago) to have all the logic located in hostapd, it is inevitable that those who intentionally want to bypass DFS regulatory restrictions actually can. You can always replace hostapd by some component that handles DFS control without caring the wait times.

But this kernel patch is attempting to enforce the wait time. Are you saying it shouldn't even pretend to enforce it?

johannes

#10 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

Quoted 16 lines · Johannes Berg
Quoted 7 lines · Zefir Kurtisi
Quoted 6 lines
Quoted 3 lines

No, if you bring it back up on the same DFS channel, radar_detection_timeout will be set back to +60s by start_radar_detection(). Looks safe to me.

You need to think a bit more outside the regular code flows ... What if I'm not calling start_radar_detection()?

Quoted 6 lines

If you are not calling start_radar_detection() you are not using hostapd. With the design approach we agreed on (when we initially discussed DFS years ago) to have all the logic located in hostapd, it is inevitable that those who intentionally want to bypass DFS regulatory restrictions actually can. You can always replace hostapd by some component that handles DFS control without caring the wait times.

Quoted 3 lines

But this kernel patch is attempting to enforce the wait time. Are you saying it shouldn't even pretend to enforce it?

It's not just attempts, it's ensures that no transmission will occur until we perform a radar detection on the channel.
It's doesn't matter if the usermode use hostapd or some other applications.

Signature · 2 lines
Thanks,
Victor.
#12 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Johannes Berg
Quoted 16 lines · Johannes Berg
Quoted 7 lines · Zefir Kurtisi
Quoted 6 lines
Quoted 3 lines

No, if you bring it back up on the same DFS channel, radar_detection_timeout will be set back to +60s by start_radar_detection(). Looks safe to me.

You need to think a bit more outside the regular code flows ... What if I'm not calling start_radar_detection()?

Quoted 6 lines

If you are not calling start_radar_detection() you are not using hostapd. With the design approach we agreed on (when we initially discussed DFS years ago) to have all the logic located in hostapd, it is inevitable that those who intentionally want to bypass DFS regulatory restrictions actually can. You can always replace hostapd by some component that handles DFS control without caring the wait times.

Quoted 5 lines

But this kernel patch is attempting to enforce the wait time. Are you saying it shouldn't even pretend to enforce it?

johannes

No, it serves its purpose to ensure hostapd is not going mad and tries to enable TX before the CAC is over via redundant checks.

What I'm saying is this: we defined that DFS regulatory compliance is provided by and distributed over driver, mac80211, and hostapd. We always must ensure that a working combination of those operates in compliance. But we have no control over it when a component is exchanged or modified.

The regulatory statement we all signed does not even ask for that, it states that 'average users should not accidentally fail to comply...' which can be denied to be accidental for someone running master mode without hostapd.

Back to topic: as stated above, radar_detection_timeout should be per wiphy. That would also resolve your concern, right?

maintainer
#11 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Goldenshtein, Victor
Quoted 18 lines · Victor
Quoted 16 lines · Johannes Berg
Quoted 13 lines · Zefir Kurtisi
Quoted 6 lines
Quoted 3 lines

No, if you bring it back up on the same DFS channel, radar_detection_timeout will be set back to +60s by start_radar_detection(). Looks safe to me.

You need to think a bit more outside the regular code flows ... What if I'm not calling start_radar_detection()?

If you are not calling start_radar_detection() you are not using hostapd. With the design approach we agreed on (when we initially discussed DFS years ago) to have all the logic located in hostapd, it is inevitable that those who intentionally want to bypass DFS regulatory restrictions actually can. You can always replace hostapd by some component that handles DFS control without caring the wait times.

Quoted 7 lines
Quoted 3 lines

But this kernel patch is attempting to enforce the wait time. Are you saying it shouldn't even pretend to enforce it?

It's not just attempts, it's ensures that no transmission will occur until we perform a radar detection on the channel.
It's doesn't matter if the usermode use hostapd or some other applications.

As written, it doesn't have that effect.

johannes

maintainer
#13 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Zefir Kurtisi
Quoted 8 lines · Zefir Kurtisi

No, it serves its purpose to ensure hostapd is not going mad and tries to enable TX before the CAC is over via redundant checks.

What I'm saying is this: we defined that DFS regulatory compliance is provided by and distributed over driver, mac80211, and hostapd. We always must ensure that a working combination of those operates in compliance. But we have no control over it when a component is exchanged or modified.

Right, but if hostapd does something unexpected, in the code the kernel attempts to verify that it did in fact do radar checking for a certain minimum amount of time. I pointed out how those checks are ineffective, and how they should be fixed.

Quoted 2 lines

Back to topic: as stated above, radar_detection_timeout should be per wiphy. That would also resolve your concern, right?

No.

johannes

#15 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Johannes Berg
Quoted 10 lines · Johannes Berg
Quoted 5 lines

+     if ((!chan->radar_detect_timeout ||
+          time_is_after_jiffies(chan->radar_detect_timeout)) &&
+         (chan->flags & IEEE80211_CHAN_RADAR))
+             return -EPERM;

Ok so you reject it if it's 0, but the jiffies calculation could return 0 too.. in fact, since jiffies start at -5 minutes on boot, you might even hit it if you start radar detection 4 minutes after boot.

good point, I will add additional flag to cover this corner case.

Signature · 2 lines
Thanks,
Victor.
#14 lore raw

Re: [PATCH v2 3/7] nl80211/cfg80211: add ability to enable TX on op-channel

In reply to Johannes Berg
Quoted 6 lines · Johannes Berg

Also, it seems that the value should be reset eventually ... at least on interface down or so. Otherwise you can start CAC, then bring the interface down to stop the device, and then bring it back up (CAC check is no longer running) and then you can use the channel after some time even though you never really checked for radar...

np, will also reset both the timestamp + new flag during interface down.

Quoted 4 lines

And if you start CAC on two different devices on the same channel, but they happen to share channel structs in the driver then this will all conflict quite badly.

We can just return EBUSY if the radar detection has already started on this specific channel. Btw, this is another argument why the "radar_detect_timeout" should be per channel.

Signature · 2 lines
Thanks,
Victor.
#31 lore raw
In reply to Johannes Berg
Quoted 6 lines · Johannes Berg
Quoted 1 line · Victor Goldenshtein

+     NL80211_CMD_RADAR_DETECT,

Is there no need to ever stop radar detection?

no, it should be always enable for DFS channels.

Quoted 6 lines
Quoted 3 lines

+ * @radar_detect_timeout: this timeout indicates the end of the channel
+ *   availability check for radar channels, only after this period the
+ *   user may initiate the tx on the channel.

units? internal use, or for use by drivers? should it really be stored in the global channel struct that could be shared for multiple devices?

will add the units.
Yes, IMHO it should be saved in the channel struct, the radar detection is per channel so it seems very natural place, also we will need it here for the MC.

Quoted 11 lines
Quoted 10 lines

 /**
+ * cfg80211_radar_detected - radar detection event
+ * @dev: network device
+ * @freq: radar detected on this channel frequency (in MHz)
+ * @gfp: context flags
+ *
+ * This function is called when a radar is detected on the current channel.
+ */
+void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp);

Quoted 6 lines

Better to pass the channel pointer?

Quoted 1 line

+u16 cfg80211_calculate_bitrate(struct rate_info *rate);

??

sorry.. :)

Quoted 5 lines
Quoted 5 lines
net/wireless/mlme.c +5 -0
+void cfg80211_radar_detected(struct net_device *dev, u16 freq, gfp_t gfp)
+{
+     struct wireless_dev *wdev = dev->ieee80211_ptr;
+     struct wiphy *wiphy = wdev->wiphy;
+     struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Quoted 9 lines
Quoted 5 lines

+     struct ieee80211_channel *chan;
+
+     chan = ieee80211_get_channel(&rdev->wiphy, freq);
+     if (chan)
+             chan->radar_detect_timeout = 0;

So how do you distinguish between having ever done radar detection and never even having started it? Also, jiffies + ... can return 0.

will add additional flag.

Quoted 3 lines

How do you intend to handle HT40?

At this point we don't have such intention, but as Zefir suggested lets first implement HT20.
To protect from transmitting on HT40 , while CAC was performed only for HT20, will add additional check in enable_tx to validate that we're on NL80211_CHAN_HT20 channel, otherwise will return -EINVAL. Also, will add NL80211_ATTR_WIPHY_CHANNEL_TYPE to the ap_channel_switch command.

Signature · 2 lines
Thanks,
Victor.
#27 lore raw

Re: [PATCH v2 7/7] mac80211: add DFS support to monitor interface

In reply to Johannes Berg
Quoted 7 lines · Johannes Berg
Quoted 2 lines · Victor Goldenshtein

+     bool dfs_supported = !!(local->hw.wiphy->features &
+                             NL80211_FEATURE_DFS);

No need for !!, also why not inline that into the condition?

I will remove the "!!", and if it's ok with you I would prefer to leave the "dfs_supported" flag, I think it a bit simplifies this big "if" statement.

Signature · 2 lines
Thanks,
Victor.
#19 lore raw

Re: [PATCH v2 5/7] nl80211/cfg80211: add ap channel switch command/event

In reply to Johannes Berg
Quoted 8 lines · Johannes Berg

include/linux/nl80211.h line 565

Quoted 2 lines · Victor Goldenshtein
include/linux/nl80211.h +0 -0
@@ -565,6 +565,15 @@
   *   the time passed sines the beginning of the CAC is less than

interestingly now I see a typo in the previous patch: "sines"?

Quoted 5 lines

include/linux/nl80211.h enum nl80211_ap_sme_features { · line 2910

Quoted 2 lines
include/linux/nl80211.h +1 -0
   * @NL80211_FEATURE_DFS: Radar detection is supported in the HW/driver.
+ * @NL80211_FEATURE_AP_CH_SWITCH: This driver supports AP channel switch.

what point is there in separating these flags?

One may support AP channel switch without DFS support, i.e. switching to non DFS channels.

Quoted 9 lines

include/net/cfg80211.h struct cfg80211_ops { · line 1754

Quoted 5 lines
include/net/cfg80211.h +4 -0
+     int     (*ap_channel_switch)(struct wiphy *wiphy, struct net_device *dev,
+                                  u32 count, bool block_tx,
+                                  bool post_switch_block_tx,
+                                  struct ieee80211_channel *new_ch);

If mac80211 needs a struct, why not have one here already rather than all the parameters?

OK, it I will just require additional mac patch before current one, I will split the "mac80211: add ap channel switch command/event".

Signature · 2 lines
Thanks,
Victor.
maintainer
#20 lore raw

Re: [PATCH v2 5/7] nl80211/cfg80211: add ap channel switch command/event

Quoted 8 lines · Victor
Quoted 5 lines
Quoted 2 lines

* @NL80211_FEATURE_DFS: Radar detection is supported in the HW/driver.
+ * @NL80211_FEATURE_AP_CH_SWITCH: This driver supports AP channel switch.

what point is there in separating these flags?

One may support AP channel switch without DFS support, i.e. switching to non DFS channels.

Oh, right, makes sense, though I'd enforce that DFS must support chanswitch?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
include/net/cfg80211.h +4 -0
+     int     (*ap_channel_switch)(struct wiphy *wiphy, struct net_device *dev,
+                                  u32 count, bool block_tx,
+                                  bool post_switch_block_tx,
+                                  struct ieee80211_channel *new_ch);
Quoted 6 lines
Quoted 3 lines

If mac80211 needs a struct, why not have one here already rather than all the parameters?

OK, it I will just require additional mac patch before current one, I will split the "mac80211: add ap channel switch command/event".

Well, you'll have to move the struct definition into cfg80211 and into this patch I think.

johannes

maintainer
#32 lore raw
In reply to Goldenshtein, Victor
Quoted 10 lines · Victor
Quoted 2 lines

How do you intend to handle HT40?

At this point we don't have such intention, but as Zefir suggested lets first implement HT20.
To protect from transmitting on HT40 , while CAC was performed only for HT20, will add additional check in enable_tx to validate that we're on NL80211_CHAN_HT20 channel, otherwise will return -EINVAL. Also, will add NL80211_ATTR_WIPHY_CHANNEL_TYPE to the ap_channel_switch command.

Ok, makes sense, thanks

johannes

#21 lore raw

Re: [PATCH v2 5/7] nl80211/cfg80211: add ap channel switch command/event

In reply to Johannes Berg
Quoted 5 lines · Johannes Berg
Quoted 3 lines · Victor
Quoted 3 lines
Quoted 2 lines

  * @NL80211_FEATURE_DFS: Radar detection is supported in the HW/driver.
+ * @NL80211_FEATURE_AP_CH_SWITCH: This driver supports AP channel switch.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

what point is there in separating these flags?

One may support AP channel switch without DFS support, i.e. switching to non DFS channels.

Oh, right, makes sense, though I'd enforce that DFS must support chanswitch?

we already do that, hostapd can start working on DFS channels only if both flags are set.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

+     int     (*ap_channel_switch)(struct wiphy *wiphy, struct net_device *dev,
+                                  u32 count, bool block_tx,
+                                  bool post_switch_block_tx,
+                                  struct ieee80211_channel *new_ch);

If mac80211 needs a struct, why not have one here already rather than all the parameters?

Quoted 6 lines
Quoted 2 lines

OK, it I will just require additional mac patch before current one, I will split the "mac80211: add ap channel switch command/event".

Well, you'll have to move the struct definition into cfg80211 and into this patch I think.

The STA channel switch struct (struct ieee80211_channel_switch) is defined in mac80211.h, thus I think the new struct for the ap channel switch should be also there, I will just split the mac patch into two.

And, almost forgot, thanks for reviewing so many patches in one day ;-)

Signature · 1 line
Victor.
maintainer
#22 lore raw

Re: [PATCH v2 5/7] nl80211/cfg80211: add ap channel switch command/event

Quoted 7 lines · Victor
Quoted 3 lines

Well, you'll have to move the struct definition into cfg80211 and into this patch I think.

The STA channel switch struct (struct ieee80211_channel_switch) is defined in mac80211.h, thus I think the new struct for the ap channel switch should be also there, I will just split the mac patch into two.

You can't use mac80211 structs from cfg80211 though, and for STA channel switch cfg80211 isn't involved ... you do need to move the struct definition :)

johannes