All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] cfg80211: fix dfs channel state after stopping AP
@ 2013-12-16 10:55 Marek Puzyniak
  2013-12-16 14:29 ` Johannes Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Puzyniak @ 2013-12-16 10:55 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, Marek Puzyniak

In AP mode DFS channel state is changed to DFS_AVAILABLE
after successful CAC and remains as such until a radar
signal is detected during the In-Service Monitoring.
When AP is stopped it is no longer monitoring current channel
for radar signals. DFS channel state should be changed
to DFS_USABLE when last AP interface is stopped. Starting AP
again on that channel will start CAC instead of starting radiation.

Signed-off-by: Marek Puzyniak <marek.puzyniak@tieto.com>
---
 net/wireless/ap.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 net/wireless/chan.c | 38 ++++++++++++++++++++++++++++++++++++++
 net/wireless/core.h | 11 +++++++++++
 3 files changed, 89 insertions(+)

diff --git a/net/wireless/ap.c b/net/wireless/ap.c
index 324e8d8..bb7b206 100644
--- a/net/wireless/ap.c
+++ b/net/wireless/ap.c
@@ -6,6 +6,43 @@
 #include "rdev-ops.h"
 
 
+static bool cfg80211_is_last_ap_running(struct cfg80211_registered_device *rdev,
+					struct net_device *dev)
+{
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wireless_dev *wdev_iter;
+
+	ASSERT_WDEV_LOCK(wdev);
+
+	if (rdev->num_running_ifaces == 1) {
+		/* Last running AP iface*/
+		return true;
+	}
+
+	/* More running interfaces */
+	list_for_each_entry(wdev_iter, &rdev->wdev_list, list) {
+		if (wdev_iter == wdev)
+			continue;
+
+		if (!wdev_iter->netdev)
+			continue;
+
+		wdev_lock(wdev_iter);
+		if (!netif_running(wdev_iter->netdev)) {
+			wdev_unlock(wdev_iter);
+			continue;
+		}
+
+		if (wdev_iter->iftype == NL80211_IFTYPE_AP) {
+			wdev_unlock(wdev_iter);
+			return false;
+		}
+		wdev_unlock(wdev_iter);
+	}
+
+	return true;
+}
+
 static int __cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
 			      struct net_device *dev)
 {
@@ -31,6 +68,9 @@ static int __cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
 		wdev->ssid_len = 0;
 	}
 
+	if (cfg80211_is_last_ap_running(rdev, dev))
+		cfg80211_leave_dfs_chandef(wdev->wiphy, &wdev->preset_chandef);
+
 	return err;
 }
 
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index 78559b5..54c217a 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -490,6 +490,44 @@ static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy,
 	return r;
 }
 
+static void cfg80211_leave_dfs_chans(struct wiphy *wiphy,
+				     u32 center_freq,
+				     u32 bandwidth)
+{
+	struct ieee80211_channel *c;
+	u32 freq, start_freq, end_freq;
+
+	start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
+	end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
+
+	for (freq = start_freq; freq <= end_freq; freq += 20) {
+		c = ieee80211_get_channel(wiphy, freq);
+		if (!c)
+			continue;
+		if (c->dfs_state != NL80211_DFS_AVAILABLE)
+			continue;
+
+		c->dfs_state = NL80211_DFS_USABLE;
+		c->dfs_state_entered = jiffies;
+	}
+}
+
+void cfg80211_leave_dfs_chandef(struct wiphy *wiphy,
+				struct cfg80211_chan_def *chandef)
+{
+	int width;
+
+	if (WARN_ON(!cfg80211_chandef_valid(chandef)))
+		return;
+
+	width = cfg80211_chandef_get_width(chandef);
+	cfg80211_leave_dfs_chans(wiphy, chandef->center_freq1, width);
+
+	if (!chandef->center_freq2)
+		return;
+
+	cfg80211_leave_dfs_chans(wiphy, chandef->center_freq2, width);
+}
 
 static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
 					u32 center_freq, u32 bandwidth,
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 37ec16d..4ed2c81 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -398,6 +398,17 @@ void cfg80211_set_dfs_state(struct wiphy *wiphy,
 
 void cfg80211_dfs_channels_update_work(struct work_struct *work);
 
+/**
+ * cfg80211_leave_dfs_chandef - Leaving dfs chandef
+ * @wiphy: the wiphy
+ * @chandef: chandef for the current channel
+ *
+ * This function is called when dfs chandef is being not used for different
+ * reasons. Change channels DFS_AVAILABLE to DFS_USABLE again. Leave channels
+ * DFS_UNAVAILABLE untouched.
+ */
+void cfg80211_leave_dfs_chandef(struct wiphy *wiphy,
+				struct cfg80211_chan_def *chandef);
 
 static inline int
 cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] cfg80211: fix dfs channel state after stopping AP
  2013-12-16 10:55 [PATCH v4] cfg80211: fix dfs channel state after stopping AP Marek Puzyniak
@ 2013-12-16 14:29 ` Johannes Berg
  0 siblings, 0 replies; 3+ messages in thread
From: Johannes Berg @ 2013-12-16 14:29 UTC (permalink / raw)
  To: Marek Puzyniak; +Cc: linux-wireless

On Mon, 2013-12-16 at 11:55 +0100, Marek Puzyniak wrote:
> In AP mode DFS channel state is changed to DFS_AVAILABLE
> after successful CAC and remains as such until a radar
> signal is detected during the In-Service Monitoring.
> When AP is stopped it is no longer monitoring current channel
> for radar signals. DFS channel state should be changed
> to DFS_USABLE when last AP interface is stopped. Starting AP
> again on that channel will start CAC instead of starting radiation.

If you keep changing your patch without any changelog (after the "---"
line!) then I have no idea what I should look at?

> +	if (rdev->num_running_ifaces == 1) {
> +		/* Last running AP iface*/

missing a space

> +		wdev_lock(wdev_iter);

This will almost certainly cause a lockdep warning since you hold the
wdev lock already.

> +		if (!netif_running(wdev_iter->netdev)) {
> +			wdev_unlock(wdev_iter);
> +			continue;
> +		}
> +
> +		if (wdev_iter->iftype == NL80211_IFTYPE_AP) {
> +			wdev_unlock(wdev_iter);
> +			return false;
> +		}
> +		wdev_unlock(wdev_iter);

I don't think checking the iftype needs the lock (this lock - maybe
rtnl) anyway?

johannes


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] cfg80211: fix dfs channel state after stopping AP
@ 2013-12-16 14:53 Marek Puzyniak
  0 siblings, 0 replies; 3+ messages in thread
From: Marek Puzyniak @ 2013-12-16 14:53 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Marek Puzyniak, linux-wireless

2013/12/16 Johannes Berg <johannes@sipsolutions.net>
> If you keep changing your patch without any changelog (after the "---"
> line!) then I have no idea what I should look at?

Right, I will add history of changes.

> > +     if (rdev->num_running_ifaces == 1) {
> > +             /* Last running AP iface*/
>
> missing a space
Yes, right.

> > +             wdev_lock(wdev_iter);
>
> This will almost certainly cause a lockdep warning since you hold the
> wdev lock already.
>
> > +             if (!netif_running(wdev_iter->netdev)) {
> > +                     wdev_unlock(wdev_iter);
> > +                     continue;
> > +             }
> > +
> > +             if (wdev_iter->iftype == NL80211_IFTYPE_AP) {
> > +                     wdev_unlock(wdev_iter);
> > +                     return false;
> > +             }
> > +             wdev_unlock(wdev_iter);
>
> I don't think checking the iftype needs the lock (this lock - maybe
> rtnl) anyway?

I will remove lock here.

> johannes

Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-16 14:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-16 10:55 [PATCH v4] cfg80211: fix dfs channel state after stopping AP Marek Puzyniak
2013-12-16 14:29 ` Johannes Berg
2013-12-16 14:53 Marek Puzyniak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.