Skip to contentSkip to conversation

iw: Add common chandef parser and new DFS related commands

PATCH In review Benjamin Berg 3 participants 12 messages Nov 7, 2016 – Nov 17, 2016

lore
Share & tools
lore
#0 lore raw

cover iw: Add common chandef parser and new DFS related commands

From: Benjamin Berg <[email protected]>

Hi,

This patchset adds commands for doing a CAC and sending CSA.

Another change is that parsing of command line frequency and channel definitions is split out so that it can be shared between the different users.

Benjamin

Benjamin Berg (7):
util: Add generic frequency/channel command line handler
phy: Use common freqchan helper for setting the operating channel
ibss: Use common freqchan helper for joining an ibss
mesh: Use common freqchan helper for joining a mesh Add cac command to allow clearing channels
Add commands to send CSA
Print frequency of radar events.

Simon Wunderlich (1):
Add flag for DFS handling in IBSS

 event.c     |  48 +++++------
 ibss.c      |  78 ++++--------------
 interface.c |  72 ++++++++++++++++
 iw.h        |  11 +++
 mesh.c      |  67 +++------------
 phy.c       | 266 ++++++++++++++++++++++++++++++++++++------------------------
 util.c      | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 533 insertions(+), 248 deletions(-)
Signature · 1 line
2.10.2
#1 lore raw

PATCH 1/8 util: Add generic frequency/channel command line handler

From: Benjamin Berg <[email protected]>

The ability to parse channel definitions is required in a lot of places inside iw. However, right now each of these duplicates a lot of code to handle it.

So add a new helper which can be used everywhere.

---
 iw.h   |  10 +++
 util.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 249 insertions(+)
iw.h +10 -0
index 2837bd3..7d56391 100644
@@ -70,6 +70,14 @@ struct chanmode {
 	int chantype; /* for older kernel */
 };
 
+struct chandef {
+	enum nl80211_chan_width width;
+
+	unsigned int control_freq;
+	unsigned int center_freq1;
+	unsigned int center_freq2;
+};
+
 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
 #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
 
@@ -150,6 +158,8 @@ int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len,
 unsigned char *parse_hex(char *hex, size_t *outlen);
 
 int parse_keys(struct nl_msg *msg, char **argv, int argc);
+int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv, int *parsed);
+int put_chandef(struct nl_msg *msg, struct chandef *chandef);
 
 void print_ht_mcs(const __u8 *mcs);
 void print_ampdu_length(__u8 exponent);
util.c +239 -0

245 lines not on this page · raw message

Signature · 1 line
2.10.2
#2 lore raw

PATCH 2/8 phy: Use common freqchan helper for setting the operating channel

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

Simplify code by using the helper which has been introduced earlier.

---
 phy.c | 143 ++++++++++++------------------------------------------------------
 1 file changed, 25 insertions(+), 118 deletions(-)
phy.c +25 -118
index c57a71f..266de4d 100644
@@ -183,140 +183,47 @@ static int handle_name(struct nl80211_state *state,
 COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name,
 	"Rename this wireless device.");
 
-static int handle_freqs(struct nl_msg *msg, int argc, char **argv)
-{
-	static const struct {
-		const char *name;
-		unsigned int val;
-	} bwmap[] = {
-		{ .name = "20", .val = NL80211_CHAN_WIDTH_20, },
-		{ .name = "40", .val = NL80211_CHAN_WIDTH_40, },
-		{ .name = "80", .val = NL80211_CHAN_WIDTH_80, },
-		{ .name = "80+80", .val = NL80211_CHAN_WIDTH_80P80, },
-		{ .name = "160", .val = NL80211_CHAN_WIDTH_160, },
-	};
-	uint32_t freq;
-	unsigned int i, bwval = NL80211_CHAN_WIDTH_20_NOHT;
-	char *end;
-
-	if (argc < 1)
-		return 1;
-
-	for (i = 0; i < ARRAY_SIZE(bwmap); i++) {
-		if (strcasecmp(bwmap[i].name, argv[0]) == 0) {
-			bwval = bwmap[i].val;
-			break;
-		}
-	}
-
-	if (bwval == NL80211_CHAN_WIDTH_20_NOHT)
-		return 1;
-
-	NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, bwval);
-
-	if (argc == 1)
-		return 0;
-
-	/* center freq 1 */
-	if (!*argv[1])
-		return 1;
-	freq = strtoul(argv[1], &end, 10);
-	if (*end)
-		return 1;
-	NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq);
-
-	if (argc == 2)
-		return 0;
-
-	/* center freq 2 */
-	if (!*argv[2])
-		return 1;
-	freq = strtoul(argv[2], &end, 10);
-	if (*end)
-		return 1;
-	NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, freq);
-
-	return 0;
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-static int handle_freqchan(struct nl_msg *msg, bool chan,
-			   int argc, char **argv)
-{
-	char *end;
-	static const struct {
-		const char *name;
-		unsigned int val;
-	} htmap[] = {
-		{ .name = "HT20", .val = NL80211_CHAN_HT20, },
-		{ .name = "HT40+", .val = NL80211_CHAN_HT40PLUS, },
-		{ .name = "HT40-", .val = NL80211_CHAN_HT40MINUS, },
-	};
-	unsigned int htval = NL80211_CHAN_NO_HT;
-	unsigned int freq;
-	unsigned int i;
-
-	if (!argc || argc > 4)
-		return 1;
-
-	if (!*argv[0])
-		return 1;
-	freq = strtoul(argv[0], &end, 10);
-	if (*end)
-		return 1;
-
-	if (chan) {
-		enum nl80211_band band;
-		band = freq <= 14 ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
-		freq = ieee80211_channel_to_frequency(freq, band);
-	}
-
-	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
-
-	if (argc > 2) {
-		return handle_freqs(msg, argc - 1, argv + 1);
-	} else if (argc == 2) {
-		for (i = 0; i < ARRAY_SIZE(htmap); i++) {
-			if (strcasecmp(htmap[i].name, argv[1]) == 0) {
-				htval = htmap[i].val;
-				break;
-			}
-		}
-		if (htval == NL80211_CHAN_NO_HT)
-			return handle_freqs(msg, argc - 1, argv + 1);
-	}
-
-	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, htval);
-
-	return 0;
- nla_put_failure:
-	return -ENOBUFS;
-}
-
 static int handle_freq(struct nl80211_state *state, struct nl_msg *msg,
 		       int argc, char **argv,
 		       enum id_input id)
 {
-	return handle_freqchan(msg, false, argc, argv);
+	struct chandef chandef;
+	int res;
+
+	res = parse_freqchan(&chandef, false, argc, argv, NULL);
+	if (res)
+		return res;
+
+	return put_chandef(msg, &chandef);
 }
-COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
+
+COMMAND(set, freq,
+	"<freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
+	"<control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
 	NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq,
 	"Set frequency/channel the hardware is using, including HT\n"
 	"configuration.");
-COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]\n"
-		   "<control freq> [20|40|80|80+80|160] [<center freq 1>] [<center freq 2>]",
+COMMAND(set, freq,
+	"<freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
+	"<control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
 	NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq, NULL);
 
 static int handle_chan(struct nl80211_state *state, struct nl_msg *msg,
 		       int argc, char **argv,
 		       enum id_input id)
 {
-	return handle_freqchan(msg, true, argc, argv);
+	struct chandef chandef;
+	int res;
+
+	res = parse_freqchan(&chandef, true, argc, argv, NULL);
+	if (res)
+		return res;
+
+	return put_chandef(msg, &chandef);
 }
-COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
+COMMAND(set, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]",
 	NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan, NULL);
-COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
+COMMAND(set, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]",
 	NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan, NULL);
 
 static int handle_fragmentation(struct nl80211_state *state,
Signature · 1 line
2.10.2
#3 lore raw

PATCH 3/8 ibss: Use common freqchan helper for joining an ibss

In reply to Benjamin Berg

Simplify code by using the helper which has been introduced earlier.

---
 ibss.c | 72 ++++++++++--------------------------------------------------------
 1 file changed, 10 insertions(+), 62 deletions(-)
ibss.c +10 -62
index 2b0b495..84f1e95 100644
@@ -13,45 +13,14 @@ static int join_ibss(struct nl80211_state *state,
 		     enum id_input id)
 {
 	char *end;
+	struct chandef chandef;
 	unsigned char abssid[6];
 	unsigned char rates[NL80211_MAX_SUPP_RATES];
 	int n_rates = 0;
 	char *value = NULL, *sptr = NULL;
 	float rate;
 	int bintval;
-	unsigned int i;
-	unsigned long freq;
-	const struct chanmode *chanmode_selected = NULL;
-	static const struct chanmode chanmode[] = {
-		{ .name = "HT20",
-		  .width = NL80211_CHAN_WIDTH_20,
-		  .freq1_diff = 0,
-		  .chantype = NL80211_CHAN_HT20 },
-		{ .name = "HT40+",
-		  .width = NL80211_CHAN_WIDTH_40,
-		  .freq1_diff = 10,
-		  .chantype = NL80211_CHAN_HT40PLUS },
-		{ .name = "HT40-",
-		  .width = NL80211_CHAN_WIDTH_40,
-		  .freq1_diff = -10,
-		  .chantype = NL80211_CHAN_HT40MINUS },
-		{ .name = "NOHT",
-		  .width = NL80211_CHAN_WIDTH_20_NOHT,
-		  .freq1_diff = 0,
-		  .chantype = NL80211_CHAN_NO_HT },
-		{ .name = "5MHz",
-		  .width = NL80211_CHAN_WIDTH_5,
-		  .freq1_diff = 0,
-		  .chantype = -1 },
-		{ .name = "10MHz",
-		  .width = NL80211_CHAN_WIDTH_10,
-		  .freq1_diff = 0,
-		  .chantype = -1 },
-		{ .name = "80MHz",
-		  .width = NL80211_CHAN_WIDTH_80,
-		  .freq1_diff = 0,
-		  .chantype = -1 },
-	};
+	int parsed, err;
 
 	if (argc < 2)
 		return 1;
@@ -61,37 +30,16 @@ static int join_ibss(struct nl80211_state *state,
 	argv++;
 	argc--;
 
-	/* freq */
-	freq = strtoul(argv[0], &end, 10);
-	if (*end != '\0')
-		return 1;
-
-	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
-	argv++;
-	argc--;
+	err = parse_freqchan(&chandef, false, argc, argv, &parsed);
+	if (err)
+		return err;
 
-	if (argc) {
-		for (i = 0; i < ARRAY_SIZE(chanmode); i++) {
-			if (strcasecmp(chanmode[i].name, argv[0]) == 0) {
-				chanmode_selected = &chanmode[i];
-				break;
-			}
-		}
-		if (chanmode_selected) {
-			NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH,
-				    chanmode_selected->width);
-			NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1,
-				    get_cf1(chanmode_selected, freq));
-			if (chanmode_selected->chantype != -1)
-				NLA_PUT_U32(msg,
-					    NL80211_ATTR_WIPHY_CHANNEL_TYPE,
-					    chanmode_selected->chantype);
+	argv += parsed;
+	argc -= parsed;
 
-			argv++;
-			argc--;
-		}
-
-	}
+	put_chandef(msg, &chandef);
+	if (err)
+		return err;
 
 	if (argc && strcmp(argv[0], "fixed-freq") == 0) {
 		NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
Signature · 1 line
2.10.2
#4 lore raw

PATCH 4/8 mesh: Use common freqchan helper for joining a mesh

In reply to Benjamin Berg

Simplify code by using the helper which has been introduced earlier.

---
 mesh.c | 67 +++++++++++-------------------------------------------------------
 1 file changed, 11 insertions(+), 56 deletions(-)
mesh.c +11 -56
index a0047fe..97f236b 100644
@@ -446,31 +446,6 @@ static int join_mesh(struct nl80211_state *state,
 	unsigned char rates[NL80211_MAX_SUPP_RATES];
 	int bintval, dtim_period, n_rates = 0;
 	char *end, *value = NULL, *sptr = NULL;
-	unsigned int i;
-	unsigned long freq = 0;
-	const struct chanmode *chanmode_selected = NULL;
-	static const struct chanmode chanmode[] = {
-		{ .name = "HT20",
-		  .width = NL80211_CHAN_WIDTH_20,
-		  .freq1_diff = 0,
-		  .chantype = NL80211_CHAN_HT20 },
-		{ .name = "HT40+",
-		  .width = NL80211_CHAN_WIDTH_40,
-		  .freq1_diff = 10,
-		  .chantype = NL80211_CHAN_HT40PLUS },
-		{ .name = "HT40-",
-		  .width = NL80211_CHAN_WIDTH_40,
-		  .freq1_diff = -10,
-		  .chantype = NL80211_CHAN_HT40MINUS },
-		{ .name = "NOHT",
-		  .width = NL80211_CHAN_WIDTH_20_NOHT,
-		  .freq1_diff = 0,
-		  .chantype = NL80211_CHAN_NO_HT },
-		{ .name = "80MHz",
-		  .width = NL80211_CHAN_WIDTH_80,
-		  .freq1_diff = 0,
-		  .chantype = -1 },
-	};
 
 	if (argc < 1)
 		return 1;
@@ -481,40 +456,20 @@ static int join_mesh(struct nl80211_state *state,
 
 	/* freq */
 	if (argc > 1 && strcmp(argv[0], "freq") == 0) {
-		argv++;
-		argc--;
-
-		freq = strtoul(argv[0], &end, 10);
-		if (*end != '\0')
-			return 1;
-		NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
-
-		argv++;
-		argc--;
-	}
+		struct chandef chandef;
+		int err, parsed;
 
-	/* channel type */
-	if (argc) {
-		for (i = 0; i < ARRAY_SIZE(chanmode); i++) {
-			if (strcasecmp(chanmode[i].name, argv[0]) == 0) {
-				chanmode_selected = &chanmode[i];
-				break;
-			}
-		}
+		err = parse_freqchan(&chandef, false, argc - 1, argv + 1,
+				     &parsed);
+		if (err)
+			return err;
 
-		if (chanmode_selected) {
-			NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH,
-				    chanmode_selected->width);
-			NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1,
-				    get_cf1(chanmode_selected, freq));
-			if (chanmode_selected->chantype != -1)
-				NLA_PUT_U32(msg,
-					    NL80211_ATTR_WIPHY_CHANNEL_TYPE,
-					    chanmode_selected->chantype);
+		argv += parsed + 1;
+		argc -= parsed + 1;
 
-			argv++;
-			argc--;
-		}
+		put_chandef(msg, &chandef);
+		if (err)
+			return err;
 	}
 
 	/* basic rates */
Signature · 1 line
2.10.2
#5 lore raw

PATCH 5/8 Add cac command to allow clearing channels

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

Allow the user to start a CAC for clearing DFS channels.

---
 phy.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 145 insertions(+)
phy.c +145 -0
index 266de4d..be31820 100644
@@ -226,6 +226,151 @@ COMMAND(set, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]",
 COMMAND(set, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]",
 	NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan, NULL);
 
+
+struct cac_event {
+	int ret;
+	uint32_t freq;
+};
+
+static int print_cac_event(struct nl_msg *msg, void *arg)
+{
+	struct nlattr *tb[NL80211_ATTR_MAX + 1];
+	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+	enum nl80211_radar_event event_type;
+	struct cac_event *cac_event = arg;
+	uint32_t freq;
+
+	if (gnlh->cmd != NL80211_CMD_RADAR_DETECT)
+		return NL_SKIP;
+
+	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+		  genlmsg_attrlen(gnlh, 0), NULL);
+
+	if (!tb[NL80211_ATTR_RADAR_EVENT] || !tb[NL80211_ATTR_WIPHY_FREQ])
+		return NL_SKIP;
+
+	freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
+	event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]);
+	if (freq != cac_event->freq)
+		return NL_SKIP;
+
+	switch (event_type) {
+	case NL80211_RADAR_DETECTED:
+		printf("%d MHz: radar detected\n", freq);
+		break;
+	case NL80211_RADAR_CAC_FINISHED:
+		printf("%d MHz: CAC finished\n", freq);
+		break;
+	case NL80211_RADAR_CAC_ABORTED:
+		printf("%d MHz: CAC was aborted\n", freq);
+		break;
+	case NL80211_RADAR_NOP_FINISHED:
+		printf("%d MHz: NOP finished\n", freq);
+		break;
+	default:
+		printf("%d MHz: unknown radar event\n", freq);
+	}
+	cac_event->ret = 0;
+
+	return NL_SKIP;
+}
+
+static int handle_cac_trigger(struct nl80211_state *state,
+			    struct nl_msg *msg,
+			    int argc, char **argv,
+			    enum id_input id)
+{
+	struct chandef chandef;
+	int res;
+
+	if (argc < 2)
+		return 1;
+
+	if (strcmp(argv[0], "channel") == 0) {
+		res = parse_freqchan(&chandef, true, argc - 1, argv + 1, NULL);
+	} else if (strcmp(argv[0], "freq") == 0) {
+		res = parse_freqchan(&chandef, false, argc - 1, argv + 1, NULL);
+	} else {
+		return 1;
+	}
+
+	if (res)
+		return res;
+
+	return put_chandef(msg, &chandef);
+}
+
+static int no_seq_check(struct nl_msg *msg, void *arg)
+{
+	return NL_OK;
+}
+
+static int handle_cac(struct nl80211_state *state,
+		      struct nl_msg *msg,
+		      int argc, char **argv,
+		      enum id_input id)
+{
+	int err;
+	struct nl_cb *radar_cb;
+	struct chandef chandef;
+	struct cac_event cac_event;
+	char **cac_trigger_argv = NULL;
+
+	radar_cb = nl_cb_alloc(iw_debug ? NL_CB_DEBUG : NL_CB_DEFAULT);
+	if (!radar_cb)
+		return 1;
+
+	if (argc < 3)
+		return 1;
+
+	if (strcmp(argv[2], "channel") == 0) {
+		err = parse_freqchan(&chandef, true, argc - 3, argv + 3, NULL);
+	} else if (strcmp(argv[2], "freq") == 0) {
+		err = parse_freqchan(&chandef, false, argc - 3, argv + 3, NULL);
+	} else {
+		return 1;
+	}
+
+	cac_trigger_argv = calloc(argc + 1, sizeof(char*));
+	if (!cac_trigger_argv)
+		return -ENOMEM;
+
+	cac_trigger_argv[0] = argv[0];
+	cac_trigger_argv[1] = "cac";
+	cac_trigger_argv[2] = "trigger";
+	memcpy(&cac_trigger_argv[3], &argv[2], (argc - 2) * sizeof(char*));
+
+	err = handle_cmd(state, id, argc + 1, cac_trigger_argv);
+	free(cac_trigger_argv);
+	if (err)
+		return err;
+
+	cac_event.ret = 1;
+	cac_event.freq = chandef.control_freq;
+
+	__prepare_listen_events(state);
+	nl_socket_set_cb(state->nl_sock, radar_cb);
+
+	/* need to turn off sequence number checking */
+	nl_cb_set(radar_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
+	nl_cb_set(radar_cb, NL_CB_VALID, NL_CB_CUSTOM, print_cac_event, &cac_event);
+	while (cac_event.ret > 0)
+		nl_recvmsgs(state->nl_sock, radar_cb);
+
+	return 0;
+}
+TOPLEVEL(cac, "channel <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
+	      "freq <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
+	      "freq <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
+	 0, 0, CIB_NETDEV, handle_cac, NULL);
+COMMAND(cac, trigger,
+	"channel <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
+	"freq <frequency> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
+	"freq <frequency> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
+	NL80211_CMD_RADAR_DETECT, 0, CIB_NETDEV, handle_cac_trigger,
+	"Start or trigger a channel availability check (CAC) looking to look for\n"
+	"radars on the given channel.");
+
 static int handle_fragmentation(struct nl80211_state *state,
 				struct nl_msg *msg,
 				int argc, char **argv,
Signature · 1 line
2.10.2
#6 lore raw

PATCH 6/8 Add commands to send CSA

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

Add a new set of commands to send a CSA. Both the number of beacons and the flag to block TX can be given optionally.

---
 interface.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 iw.h        |  1 +
 2 files changed, 73 insertions(+)
interface.c +72 -0
index 57dd3c3..1c9ebfb 100644
@@ -644,3 +644,75 @@ nla_put_failure:
 COMMAND(set, mcast_rate, "<rate in Mbps>",
 	NL80211_CMD_SET_MCAST_RATE, 0, CIB_NETDEV, set_mcast_rate,
 	"Set the multicast bitrate.");
+
+
+static int handle_chanfreq(struct nl80211_state *state, struct nl_msg *msg,
+			   bool chan, int argc, char **argv,
+			   enum id_input id)
+{
+	struct chandef chandef;
+	int res;
+	int parsed;
+	char *end;
+
+	res = parse_freqchan(&chandef, chan, argc, argv, &parsed);
+	if (res)
+		return res;
+
+	argc -= parsed;
+	argv += parsed;
+
+	while (argc) {
+		unsigned int beacons = 10;
+
+		if (strcmp(argv[0], "beacons") == 0) {
+			if (argc < 2)
+				return 1;
+
+			beacons = strtol(argv[1], &end, 10);
+			if (*end)
+				return 1;
+
+			argc -= 2;
+			argv += 2;
+
+			NLA_PUT_U32(msg, NL80211_ATTR_CH_SWITCH_COUNT, beacons);
+		} else if (strcmp(argv[0], "block-tx") == 0) {
+			argc -= 1;
+			argv += 1;
+
+			NLA_PUT_FLAG(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX);
+		} else {
+			return 1;
+		}
+	}
+
+	return put_chandef(msg, &chandef);
+
+ nla_put_failure:
+	return -ENOBUFS;
+}
+
+static int handle_freq(struct nl80211_state *state, struct nl_msg *msg,
+		       int argc, char **argv,
+		       enum id_input id)
+{
+	return handle_chanfreq(state, msg, false, argc, argv, id);
+}
+
+static int handle_chan(struct nl80211_state *state, struct nl_msg *msg,
+		       int argc, char **argv,
+		       enum id_input id)
+{
+	return handle_chanfreq(state, msg, true, argc, argv, id);
+}
+
+SECTION(switch);
+COMMAND(switch, freq,
+	"<freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]\n"
+	"<control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]] [beacons <count>] [block-tx]",
+	NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_freq,
+	"Switch the operating channel by sending a channel switch announcement (CSA).");
+COMMAND(switch, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]",
+	NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_chan, NULL);
+
iw.h +1 -0
index 7d56391..0857baf 100644
@@ -202,6 +202,7 @@ int get_cf1(const struct chanmode *chanmode, unsigned long freq);
 	"[randomise[=<addr>/<mask>]]"
 int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv);
 
+DECLARE_SECTION(switch);
 DECLARE_SECTION(set);
 DECLARE_SECTION(get);
 
Signature · 1 line
2.10.2
#7 lore raw

PATCH 7/8 Add flag for DFS handling in IBSS

In reply to Benjamin Berg

From: Simon Wunderlich <[email protected]>

When Userspace is capable of handling DFS, it can inform the kernel about that by sending the NL80211_ATTR_HANDLE_DFS attribute when joining an IBSS. DFS channels will then be unlocked.

Note that this flag is only added for debugging purposes and therefore hidden from the user by prefixing with __ and not documenting it.

---
 ibss.c | 6 ++++++
 1 file changed, 6 insertions(+)
ibss.c +6 -0
index 84f1e95..7087cc9 100644
@@ -47,6 +47,12 @@ static int join_ibss(struct nl80211_state *state,
 		argc--;
 	}
 
+	if (argc && strcmp(argv[0], "__dfs-enable") == 0) {
+		NLA_PUT_FLAG(msg, NL80211_ATTR_HANDLE_DFS);
+		argv++;
+		argc--;
+	}
+
 	if (argc) {
 		if (mac_addr_a2n(abssid, argv[0]) == 0) {
 			NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
Signature · 1 line
2.10.2
#8 lore raw

PATCH 8/8 Print frequency of radar events.

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

---
 event.c | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)
event.c +25 -23
index 446debb..8014d73 100644
@@ -584,30 +584,32 @@ static int print_event(struct nl_msg *msg, void *arg)
 				   nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
 				   nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
 		break;
-	case NL80211_CMD_RADAR_DETECT:
-		printf("radar event ");
-		if (tb[NL80211_ATTR_RADAR_EVENT]) {
-			switch (nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT])) {
-				case NL80211_RADAR_DETECTED:
-					printf("(radar detected)");
-					break;
-				case NL80211_RADAR_CAC_FINISHED:
-					printf("(cac finished)");
-					break;
-				case NL80211_RADAR_CAC_ABORTED:
-					printf("(cac aborted)");
-					break;
-				case NL80211_RADAR_NOP_FINISHED:
-					printf("(nop finished)");
-					break;
-				default:
-					printf("(unknown)");
-					break;
-			};
-		} else {
-			printf("(unknown)");
+	case NL80211_CMD_RADAR_DETECT: {
+			enum nl80211_radar_event event_type;
+			uint32_t freq;
+
+			if (!tb[NL80211_ATTR_RADAR_EVENT] || !tb[NL80211_ATTR_WIPHY_FREQ])
+				printf("BAD radar event");
+			freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
+			event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]);
+
+			switch (event_type) {
+			case NL80211_RADAR_DETECTED:
+				printf("%d MHz: radar detected\n", freq);
+				break;
+			case NL80211_RADAR_CAC_FINISHED:
+				printf("%d MHz: CAC finished\n", freq);
+				break;
+			case NL80211_RADAR_CAC_ABORTED:
+				printf("%d MHz: CAC was aborted\n", freq);
+				break;
+			case NL80211_RADAR_NOP_FINISHED:
+				printf("%d MHz: NOP finished\n", freq);
+				break;
+			default:
+				printf("%d MHz: unknown radar event\n", freq);
+			}
 		}
-		printf("\n");
 		break;
 	case NL80211_CMD_DEL_WIPHY:
 		printf("delete wiphy\n");
Signature · 1 line
2.10.2
#9 lore raw

Re: [PATCH 8/8] Print frequency of radar events.

Quoted 34 lines · Benjamin Berg

From: Benjamin Berg <[email protected]>

---
 event.c | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)
event.c +0 -18
index 446debb..8014d73 100644
@@ -584,30 +584,32 @@ static int print_event(struct nl_msg *msg, void *arg)
 				   nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
 				   nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
 		break;
-	case NL80211_CMD_RADAR_DETECT:
-		printf("radar event ");
-		if (tb[NL80211_ATTR_RADAR_EVENT]) {
-			switch (nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT])) {
-				case NL80211_RADAR_DETECTED:
-					printf("(radar detected)");
-					break;
-				case NL80211_RADAR_CAC_FINISHED:
-					printf("(cac finished)");
-					break;
-				case NL80211_RADAR_CAC_ABORTED:
-					printf("(cac aborted)");
-					break;
-				case NL80211_RADAR_NOP_FINISHED:
-					printf("(nop finished)");
-					break;
-				default:
-					printf("(unknown)");

event.c static int print_event(struct nl_msg *msg, void *arg) · line 592

Quoted 10 lines
event.c +6 -4
-					break;
-			};
-		} else {
-			printf("(unknown)");
+	case NL80211_CMD_RADAR_DETECT: {
+			enum nl80211_radar_event event_type;
+			uint32_t freq;
+
+			if (!tb[NL80211_ATTR_RADAR_EVENT] || !tb[NL80211_ATTR_WIPHY_FREQ])
+				printf("BAD radar event");

Should not this end the parsing here or at least avoid getting the value of the NULL attributes below? I do not know if libnl nla_get_u32() is intended to be NULL safe, but following
https://www.infradead.org/~tgr/libnl/doc/api/attr_8c_source.html#l00624
it seems like you will get whatever u32 value is at address (NULL+)NLA_HDRLEN, assuming it is readable. The original behavior was to do nothing if tb[NL80211_ATTR_RADAR_EVENT] was not set.

event.c static int print_event(struct nl_msg *msg, void *arg) · line 594

Quoted 2 lines
event.c +2 -0
+			freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
+			event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]);

br,
henrik

#10 lore raw

Re: [PATCH 8/8] Print frequency of radar events.

Quoted 12 lines · Henrik Eriksson
Quoted 2 lines · Benjamin Berg
Quoted 2 lines

event.c static int print_event(struct nl_msg *msg, void *arg) · line 592

Quoted 2 lines
event.c +2 -0
+			if (!tb[NL80211_ATTR_RADAR_EVENT] || !tb[NL80211_ATTR_WIPHY_FREQ])
+				printf("BAD radar event");

Should not this end the parsing here or at least avoid getting the value of the NULL attributes below?  I do not know if libnl nla_get_u32() is intended to be NULL safe, but following
https://www.infradead.org/~tgr/libnl/doc/api/attr_8c_source.html#l00624
it seems like you will get whatever u32 value is at address (NULL+)NLA_HDRLEN, assuming it is readable.  The original behavior was to do nothing if tb[NL80211_ATTR_RADAR_EVENT] was not set.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

event.c static int print_event(struct nl_msg *msg, void *arg) · line 594

Quoted 2 lines
event.c +2 -0
+			freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
+			event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]);

Yes, my version of the patch was somewhat broken in that regard. Johannes fixed it before merging and it will now correctly print "BAD radar event\n" and stop processing in case one of the entries is missing.

Benjamin

#11 lore raw
In reply to Benjamin Berg
Quoted 9 lines · Benjamin Berg

From: Benjamin Berg <[email protected]>

Hi,

This patchset adds commands for doing a CAC and sending CSA.

Another change is that parsing of command line frequency and channel definitions is split out so that it can be shared between the different users.

That's nice :)

I've applied all except for patch 7 - I don't see any justification for adding that - quite clearly iw will not listen to any radar detection events, so even for testing/certification this doesn't seem useful since then you'd want to check/prove that you *do* listen to those ...

johannes