]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: add randomise option for sched_scan
authorLuciano Coelho <luciano.coelho@intel.com>
Tue, 17 Mar 2015 14:11:50 +0000 (16:11 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 17 Mar 2015 15:09:53 +0000 (16:09 +0100)
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>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
iw.h
scan.c

diff --git a/iw.h b/iw.h
index fc20838f95adb68816cc504bd1fcf4dca255104f..78195eaab546cd5e58730a86e4d9aefc44fc3c20 100644 (file)
--- 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 7ff04ec7390dc4a34b77c9acd2efe571b4e34eab..e959c1bc9fc05d5927234f48e8026f274219e694 100644 (file)
--- 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)