diff mbox

[iw,v2,4/4] iw: add randomise option for sched_scan

Message ID 1426601510-8251-5-git-send-email-luca@coelho.fi (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show

Commit Message

Luca Coelho March 17, 2015, 2:11 p.m. UTC
From: Luciano Coelho <luciano.coelho@intel.com>

Like with normal scans, we can randomise the MAC address sent out in
active scheduled scans.  Add the randomise option to sched_scan (and
net-detect) parsing code.

Signed-off-by: Luciano Coelho <luciano.coelho@intel.com>
---
 iw.h   |  2 +-
 scan.c | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/iw.h b/iw.h
index fc20838..78195ea 100644
--- a/iw.h
+++ b/iw.h
@@ -174,7 +174,7 @@  void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen);
 void iw_hexdump(const char *prefix, const __u8 *data, size_t len);
 
 #define SCHED_SCAN_OPTIONS "interval <in_msecs> [delay <in_secs>] " \
-	"[freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] "
+	"[freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] [randomise[=<addr>/<mask>]]"
 int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv);
 
 DECLARE_SECTION(set);
diff --git a/scan.c b/scan.c
index 7ff04ec..e959c1b 100644
--- a/scan.c
+++ b/scan.c
@@ -115,6 +115,7 @@  int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv)
 	unsigned int freq, interval = 0, delay = 0;
 	bool have_matchset = false, have_freqs = false, have_ssids = false;
 	bool have_active = false, have_passive = false;
+	uint32_t flags = 0;
 
 	matchset = nlmsg_alloc();
 	if (!matchset) {
@@ -208,6 +209,14 @@  int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv)
 				}
 
 				have_passive = true;
+			} else if (!strncmp(v[0], "randomise", 9) ||
+				   !strncmp(v[0], "randomize", 9)) {
+				flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
+				if (c > 0) {
+					err = parse_random_mac_addr(msg, v[0]);
+					if (err)
+						goto nla_put_failure;
+				}
 			} else {
 				/* this element is not for us, so
 				 * return to continue parsing.
@@ -312,6 +321,8 @@  int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv)
 		nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs);
 	if (have_matchset)
 		nla_put_nested(msg, NL80211_ATTR_SCHED_SCAN_MATCH, matchset);
+	if (flags)
+		NLA_PUT_U32(msg, NL80211_ATTR_SCAN_FLAGS, flags);
 
 nla_put_failure:
 	if (match)