* [PATCH 0/8] iw: Add common chandef parser and new DFS related commands
@ 2016-11-07 14:59 Benjamin Berg
2016-11-07 14:59 ` [PATCH 1/8] util: Add generic frequency/channel command line handler Benjamin Berg
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg
From: Benjamin Berg <benjamin.berg@open-mesh.com>
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(-)
--
2.10.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/8] util: Add generic frequency/channel command line handler
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-07 14:59 ` [PATCH 2/8] phy: Use common freqchan helper for setting the operating channel Benjamin Berg
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg
From: Benjamin Berg <benjamin.berg@open-mesh.com>
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.
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
iw.h | 10 +++
util.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 249 insertions(+)
diff --git a/iw.h b/iw.h
index 2837bd3..7d56391 100644
--- a/iw.h
+++ b/iw.h
@@ -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);
diff --git a/util.c b/util.c
index a338464..833b1ce 100644
--- a/util.c
+++ b/util.c
@@ -469,6 +469,245 @@ int parse_keys(struct nl_msg *msg, char **argv, int argc)
return 2;
}
+static int parse_freqs(struct chandef *chandef, int argc, char **argv,
+ int *parsed)
+{
+ static const struct {
+ const char *name;
+ unsigned int val;
+ } bwmap[] = {
+ { .name = "5", .val = NL80211_CHAN_WIDTH_5, },
+ { .name = "10", .val = NL80211_CHAN_WIDTH_10, },
+ { .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 0;
+
+ for (i = 0; i < ARRAY_SIZE(bwmap); i++) {
+ if (strcasecmp(bwmap[i].name, argv[0]) == 0) {
+ bwval = bwmap[i].val;
+ *parsed += 1;
+ break;
+ }
+ }
+ chandef->width = bwval;
+
+ /* First argument was not understood, give up gracefully. */
+ if (bwval == NL80211_CHAN_WIDTH_20_NOHT)
+ return 0;
+
+ if (argc < 2)
+ return 0;
+
+ /* center freq 1 */
+ if (!*argv[1])
+ return 0;
+ freq = strtoul(argv[1], &end, 10);
+ if (*end)
+ return 0;
+ *parsed += 1;
+
+ chandef->center_freq1 = freq;
+
+ if (argc < 3)
+ return 0;
+
+ /* center freq 2 */
+ if (!*argv[2])
+ return 0;
+ freq = strtoul(argv[2], &end, 10);
+ if (*end)
+ return 0;
+ chandef->center_freq2 = freq;
+
+ *parsed += 1;
+
+ return 0;
+}
+
+
+/**
+ * parse_freqchan - Parse frequency or channel definition
+ *
+ * @chandef: chandef structure to be filled in
+ * @chan: Boolean whether to parse a channel or frequency based specifier
+ * @argc: Number of arguments
+ * @argv: Array of string arguments
+ * @parsed: Pointer to return the number of used arguments, or NULL to error
+ * out if any argument is left unused.
+ *
+ * The given chandef structure will be filled in from the command line
+ * arguments. argc/argv will be updated so that further arguments from the
+ * command line can be parsed.
+ *
+ * Note that no integer argument may follow a frequency definition to allow the
+ * user to skip the center frequency definition(s).
+ *
+ * The working specifier if chan is set are:
+ * <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
+ *
+ * And if frequency is set:
+ * <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
+ * <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]
+ *
+ * If the mode/channel width is not given the NOHT is assumed.
+ *
+ * Return: Number of used arguments, zero or negative error number otherwise
+ */
+int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv,
+ int *parsed)
+{
+ char *end;
+ 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 },
+ };
+ const struct chanmode *chanmode_selected = NULL;
+ unsigned int freq;
+ unsigned int i;
+ int _parsed = 0;
+ int res = 0;
+
+ if (argc < 1)
+ return 1;
+
+ if (!argv[0])
+ goto out;
+ freq = strtoul(argv[0], &end, 10);
+ if (*end) {
+ res = 1;
+ goto out;
+ }
+
+ _parsed += 1;
+
+ memset(chandef, 0, sizeof(struct chandef));
+
+ if (chan) {
+ enum nl80211_band band;
+
+ band = freq <= 14 ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
+ freq = ieee80211_channel_to_frequency(freq, band);
+ }
+ chandef->control_freq = freq;
+ /* Assume 20MHz NOHT channel for now. */
+ chandef->center_freq1 = freq;
+
+ /* Try to parse HT mode definitions */
+ if (argc > 1) {
+ for (i = 0; i < ARRAY_SIZE(chanmode); i++) {
+ if (strcasecmp(chanmode[i].name, argv[1]) == 0) {
+ chanmode_selected = &chanmode[i];
+ _parsed += 1;
+ break;
+ }
+ }
+ }
+
+ /* channel mode given, use it and return. */
+ if (chanmode_selected) {
+ chandef->center_freq1 = get_cf1(chanmode_selected, freq);
+ chandef->width = chanmode_selected->width;
+ goto out;
+ }
+
+ /* This was a only a channel definition, nothing further may follow. */
+ if (chan)
+ goto out;
+
+ res = parse_freqs(chandef, argc - 1, argv + 1, &_parsed);
+
+ out:
+ /* Error out if parsed is NULL. */
+ if (!parsed && _parsed != argc)
+ return 1;
+
+ if (parsed)
+ *parsed = _parsed;
+
+ return res;
+}
+
+int put_chandef(struct nl_msg *msg, struct chandef *chandef)
+{
+ NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chandef->control_freq);
+ NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width);
+
+ switch (chandef->width) {
+ case NL80211_CHAN_WIDTH_20_NOHT:
+ NLA_PUT_U32(msg,
+ NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+ NL80211_CHAN_NO_HT);
+ break;
+ case NL80211_CHAN_WIDTH_20:
+ NLA_PUT_U32(msg,
+ NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+ NL80211_CHAN_HT20);
+ break;
+ case NL80211_CHAN_WIDTH_40:
+ if (chandef->control_freq > chandef->center_freq1)
+ NLA_PUT_U32(msg,
+ NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+ NL80211_CHAN_HT40MINUS);
+ else
+ NLA_PUT_U32(msg,
+ NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+ NL80211_CHAN_HT40PLUS);
+ break;
+ default:
+ break;
+ }
+
+ if (chandef->center_freq1)
+ NLA_PUT_U32(msg,
+ NL80211_ATTR_CENTER_FREQ1,
+ chandef->center_freq1);
+
+ if (chandef->center_freq2)
+ NLA_PUT_U32(msg,
+ NL80211_ATTR_CENTER_FREQ2,
+ chandef->center_freq2);
+
+ return 0;
+
+ nla_put_failure:
+ return -ENOBUFS;
+}
+
static void print_mcs_index(const __u8 *mcs)
{
int mcs_bit, prev_bit = -2, prev_cont = 0;
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/8] phy: Use common freqchan helper for setting the operating channel
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
2016-11-07 14:59 ` [PATCH 1/8] util: Add generic frequency/channel command line handler Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-07 14:59 ` [PATCH 3/8] ibss: Use common freqchan helper for joining an ibss Benjamin Berg
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg
From: Benjamin Berg <benjamin.berg@open-mesh.com>
Simplify code by using the helper which has been introduced earlier.
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
phy.c | 143 ++++++++++++------------------------------------------------------
1 file changed, 25 insertions(+), 118 deletions(-)
diff --git a/phy.c b/phy.c
index c57a71f..266de4d 100644
--- a/phy.c
+++ b/phy.c
@@ -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,
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/8] ibss: Use common freqchan helper for joining an ibss
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
2016-11-07 14:59 ` [PATCH 1/8] util: Add generic frequency/channel command line handler Benjamin Berg
2016-11-07 14:59 ` [PATCH 2/8] phy: Use common freqchan helper for setting the operating channel Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-07 14:59 ` [PATCH 4/8] mesh: Use common freqchan helper for joining a mesh Benjamin Berg
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg, Benjamin Berg
Simplify code by using the helper which has been introduced earlier.
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
ibss.c | 72 ++++++++++--------------------------------------------------------
1 file changed, 10 insertions(+), 62 deletions(-)
diff --git a/ibss.c b/ibss.c
index 2b0b495..84f1e95 100644
--- a/ibss.c
+++ b/ibss.c
@@ -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);
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/8] mesh: Use common freqchan helper for joining a mesh
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
` (2 preceding siblings ...)
2016-11-07 14:59 ` [PATCH 3/8] ibss: Use common freqchan helper for joining an ibss Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-07 14:59 ` [PATCH 5/8] Add cac command to allow clearing channels Benjamin Berg
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg, Benjamin Berg
Simplify code by using the helper which has been introduced earlier.
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
mesh.c | 67 +++++++++++-------------------------------------------------------
1 file changed, 11 insertions(+), 56 deletions(-)
diff --git a/mesh.c b/mesh.c
index a0047fe..97f236b 100644
--- a/mesh.c
+++ b/mesh.c
@@ -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 */
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/8] Add cac command to allow clearing channels
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
` (3 preceding siblings ...)
2016-11-07 14:59 ` [PATCH 4/8] mesh: Use common freqchan helper for joining a mesh Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-07 14:59 ` [PATCH 6/8] Add commands to send CSA Benjamin Berg
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg
From: Benjamin Berg <benjamin.berg@open-mesh.com>
Allow the user to start a CAC for clearing DFS channels.
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
phy.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 145 insertions(+)
diff --git a/phy.c b/phy.c
index 266de4d..be31820 100644
--- a/phy.c
+++ b/phy.c
@@ -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,
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/8] Add commands to send CSA
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
` (4 preceding siblings ...)
2016-11-07 14:59 ` [PATCH 5/8] Add cac command to allow clearing channels Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-07 14:59 ` [PATCH 7/8] Add flag for DFS handling in IBSS Benjamin Berg
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg
From: Benjamin Berg <benjamin.berg@open-mesh.com>
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.
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
interface.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
iw.h | 1 +
2 files changed, 73 insertions(+)
diff --git a/interface.c b/interface.c
index 57dd3c3..1c9ebfb 100644
--- a/interface.c
+++ b/interface.c
@@ -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);
+
diff --git a/iw.h b/iw.h
index 7d56391..0857baf 100644
--- a/iw.h
+++ b/iw.h
@@ -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);
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 7/8] Add flag for DFS handling in IBSS
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
` (5 preceding siblings ...)
2016-11-07 14:59 ` [PATCH 6/8] Add commands to send CSA Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-07 14:59 ` [PATCH 8/8] Print frequency of radar events Benjamin Berg
2016-11-16 12:41 ` [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Johannes Berg
8 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg
From: Simon Wunderlich <sw@simonwunderlich.de>
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.
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
ibss.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/ibss.c b/ibss.c
index 84f1e95..7087cc9 100644
--- a/ibss.c
+++ b/ibss.c
@@ -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);
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 8/8] Print frequency of radar events.
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
` (6 preceding siblings ...)
2016-11-07 14:59 ` [PATCH 7/8] Add flag for DFS handling in IBSS Benjamin Berg
@ 2016-11-07 14:59 ` Benjamin Berg
2016-11-17 17:21 ` Henrik Eriksson
2016-11-16 12:41 ` [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Johannes Berg
8 siblings, 1 reply; 12+ messages in thread
From: Benjamin Berg @ 2016-11-07 14:59 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, sw, Benjamin Berg
From: Benjamin Berg <benjamin.berg@open-mesh.com>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
---
event.c | 48 +++++++++++++++++++++++++-----------------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/event.c b/event.c
index 446debb..8014d73 100644
--- a/event.c
+++ b/event.c
@@ -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");
--
2.10.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 0/8] iw: Add common chandef parser and new DFS related commands
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
` (7 preceding siblings ...)
2016-11-07 14:59 ` [PATCH 8/8] Print frequency of radar events Benjamin Berg
@ 2016-11-16 12:41 ` Johannes Berg
8 siblings, 0 replies; 12+ messages in thread
From: Johannes Berg @ 2016-11-16 12:41 UTC (permalink / raw)
To: Benjamin Berg; +Cc: linux-wireless, sw, Benjamin Berg
On Mon, 2016-11-07 at 15:59 +0100, Benjamin Berg wrote:
> From: Benjamin Berg <benjamin.berg@open-mesh.com>
>
> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 8/8] Print frequency of radar events.
2016-11-07 14:59 ` [PATCH 8/8] Print frequency of radar events Benjamin Berg
@ 2016-11-17 17:21 ` Henrik Eriksson
2016-11-17 17:25 ` Benjamin Berg
0 siblings, 1 reply; 12+ messages in thread
From: Henrik Eriksson @ 2016-11-17 17:21 UTC (permalink / raw)
To: Benjamin Berg; +Cc: Johannes Berg, linux-wireless, sw, Benjamin Berg
On Mon, Nov 07, 2016 at 15:59:43 +0100, Benjamin Berg wrote:
> From: Benjamin Berg <benjamin.berg@open-mesh.com>
>
> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
> Signed-off-by: Benjamin Berg <benjamin.berg@open-mesh.com>
> ---
> event.c | 48 +++++++++++++++++++++++++-----------------------
> 1 file changed, 25 insertions(+), 23 deletions(-)
>
> diff --git a/event.c b/event.c
> index 446debb..8014d73 100644
> --- a/event.c
> +++ b/event.c
> @@ -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");
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.
> + freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
> + event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]);
br,
henrik
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 8/8] Print frequency of radar events.
2016-11-17 17:21 ` Henrik Eriksson
@ 2016-11-17 17:25 ` Benjamin Berg
0 siblings, 0 replies; 12+ messages in thread
From: Benjamin Berg @ 2016-11-17 17:25 UTC (permalink / raw)
To: Henrik Eriksson; +Cc: Johannes Berg, linux-wireless, sw
[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]
On Thu, 2016-11-17 at 18:21 +0100, Henrik Eriksson wrote:
> On Mon, Nov 07, 2016 at 15:59:43 +0100, Benjamin Berg wrote:
> > > > + 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.
>
> > > > + 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
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2016-11-17 17:25 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-07 14:59 [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Benjamin Berg
2016-11-07 14:59 ` [PATCH 1/8] util: Add generic frequency/channel command line handler Benjamin Berg
2016-11-07 14:59 ` [PATCH 2/8] phy: Use common freqchan helper for setting the operating channel Benjamin Berg
2016-11-07 14:59 ` [PATCH 3/8] ibss: Use common freqchan helper for joining an ibss Benjamin Berg
2016-11-07 14:59 ` [PATCH 4/8] mesh: Use common freqchan helper for joining a mesh Benjamin Berg
2016-11-07 14:59 ` [PATCH 5/8] Add cac command to allow clearing channels Benjamin Berg
2016-11-07 14:59 ` [PATCH 6/8] Add commands to send CSA Benjamin Berg
2016-11-07 14:59 ` [PATCH 7/8] Add flag for DFS handling in IBSS Benjamin Berg
2016-11-07 14:59 ` [PATCH 8/8] Print frequency of radar events Benjamin Berg
2016-11-17 17:21 ` Henrik Eriksson
2016-11-17 17:25 ` Benjamin Berg
2016-11-16 12:41 ` [PATCH 0/8] iw: Add common chandef parser and new DFS related commands Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).