[OpenWrt-Devel] [PATCH] iwinfo: Check DFS support before enabling DFS channels

Chaitanya Tata chaitanya.mgit at gmail.com
Sun Jan 15 08:05:18 EST 2017


Before enabling the DFS channels looks for support of DFS
in interface combinations, NO_IR and DFS flags.

Currently BW level checks are not supported.

Tested-by: Tushar Jobanputra <Tushar.Jobanputra at imgtec.com>
Signed-off-by: Chaitanya Tata <Chaitanya.Tata at imgtec.com>
---
Fix signed tag.
---
 iwinfo_nl80211.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 59 insertions(+), 6 deletions(-)

diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index 63b70d5..d8d2670 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -2404,20 +2404,71 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
 	return -1;
 }
 
+char *channel_width_name(enum nl80211_chan_width width)
+{
+	switch (width) {
+	case NL80211_CHAN_WIDTH_20_NOHT:
+		return "20 MHz (no HT)";
+	case NL80211_CHAN_WIDTH_20:
+		return "20 MHz";
+	case NL80211_CHAN_WIDTH_40:
+		return "40 MHz";
+	case NL80211_CHAN_WIDTH_80:
+		return "80 MHz";
+	case NL80211_CHAN_WIDTH_80P80:
+		return "80+80 MHz";
+	case NL80211_CHAN_WIDTH_160:
+		return "160 MHz";
+	default:
+		return "unknown";
+	}
+}
+
 static int nl80211_get_freqlist_cb(struct nl_msg *msg, void *arg)
 {
-	int bands_remain, freqs_remain;
+	int if_comb_remain, bands_remain, freqs_remain,comb_limits_remain;
 
 	struct nl80211_array_buf *arr = arg;
 	struct iwinfo_freqlist_entry *e = arr->buf;
 
 	struct nlattr **attr = nl80211_parse(msg);
+	struct nlattr *combs[MAX_NL80211_IFACE_COMB + 1];
 	struct nlattr *bands[NL80211_BAND_ATTR_MAX + 1];
 	struct nlattr *freqs[NL80211_FREQUENCY_ATTR_MAX + 1];
-	struct nlattr *band, *freq;
+	struct nlattr *comb, *band, *freq,*comb_limit;
+	struct nlattr *comb_limits[MAX_NL80211_IFACE_COMB + 1];
+	bool dfs_support = 0;
+	unsigned int widths = 0;
+
+	nla_for_each_nested(comb, attr[NL80211_ATTR_INTERFACE_COMBINATIONS], bands_remain)
+	{
+
+		nla_parse(combs, MAX_NL80211_IFACE_COMB,
+		          nla_data(comb), nla_len(comb), NULL);
+
+		nla_for_each_nested(comb_limit, combs[NL80211_IFACE_COMB_LIMITS], comb_limits_remain)
+		{
+			nla_parse(comb_limits, MAX_NL80211_IFACE_LIMIT,
+				  nla_data(comb_limit), nla_len(comb_limit), NULL);
+
+			if (!comb_limits[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
+				continue;
+
+			widths = nla_get_u32(comb_limits[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]);
+			/* Curently there is no 1-1 mappng between
+			 * freq and cbw, so we cannot check dfs support
+			 * for different cbw.
+			 */
+			if (widths)
+				dfs_support = true;
+
+		}
+
+	}
 
 	nla_for_each_nested(band, attr[NL80211_ATTR_WIPHY_BANDS], bands_remain)
 	{
+		struct nlattr *is_ir,*is_dfs;
 		nla_parse(bands, NL80211_BAND_ATTR_MAX,
 		          nla_data(band), nla_len(band), NULL);
 
@@ -2433,16 +2484,18 @@ static int nl80211_get_freqlist_cb(struct nl_msg *msg, void *arg)
 			e->mhz = nla_get_u32(freqs[NL80211_FREQUENCY_ATTR_FREQ]);
 			e->channel = nl80211_freq2channel(e->mhz);
 
-			e->restricted = (
-				freqs[NL80211_FREQUENCY_ATTR_NO_IR] &&
-				!freqs[NL80211_FREQUENCY_ATTR_RADAR]
-			) ? 1 : 0;
+			is_ir = freqs[NL80211_FREQUENCY_ATTR_NO_IR] ;
+			is_dfs = freqs[NL80211_FREQUENCY_ATTR_RADAR];
+
+			e->restricted = is_ir || (is_dfs && !dfs_support);
 
 			e++;
 			arr->count++;
 		}
 	}
 
+
+
 	return NL_SKIP;
 }
 
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list