From patchwork Fri Mar 13 20:27:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Coelho X-Patchwork-Id: 6009071 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E89D8BF90F for ; Fri, 13 Mar 2015 20:27:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 13AEF20256 for ; Fri, 13 Mar 2015 20:27:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 20B5720274 for ; Fri, 13 Mar 2015 20:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754110AbbCMU1i (ORCPT ); Fri, 13 Mar 2015 16:27:38 -0400 Received: from dedo.coelho.fi ([88.198.205.34]:41880 "EHLO dedo.coelho.fi" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753515AbbCMU1e (ORCPT ); Fri, 13 Mar 2015 16:27:34 -0400 Received: from a88-113-225-236.elisa-laajakaista.fi ([88.113.225.236] helo=dubbel.amr.corp.intel.com) by dedo.coelho.fi with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA256:128) (Exim 4.80) (envelope-from ) id 1YWWBA-0006LU-Cu; Fri, 13 Mar 2015 22:27:32 +0200 From: Luca Coelho To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org Date: Fri, 13 Mar 2015 22:27:20 +0200 Message-Id: <1426278441-10304-4-git-send-email-luca@coelho.fi> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426278441-10304-1-git-send-email-luca@coelho.fi> References: <1426278441-10304-1-git-send-email-luca@coelho.fi> X-SA-Exim-Connect-IP: 88.113.225.236 X-SA-Exim-Mail-From: luca@coelho.fi X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Subject: [PATCH iw 3/4] iw: add support for active scheduled scan X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on dedo.coelho.fi) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Luciano Coelho Add options to explicitly use active or passive scans on schedule scans (and net-detect). If neither active nor passive parameters are passed, the default is to do active scans with the wildcard SSID. Signed-off-by: Luciano Coelho --- iw.h | 2 +- scan.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/iw.h b/iw.h index 21e2229..d6b51cf 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 [delay " \ - "[freqs +] [matches [ssid ]+]]" + "[freqs +] [matches [ssid ]+]] [active [ssid ]+|passive] " int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv); DECLARE_SECTION(set); diff --git a/scan.c b/scan.c index e534fd4..7ff04ec 100644 --- a/scan.c +++ b/scan.c @@ -101,18 +101,20 @@ static int parse_random_mac_addr(struct nl_msg *msg, char *arg) int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv) { - struct nl_msg *matchset = NULL, *freqs = NULL; + struct nl_msg *matchset = NULL, *freqs = NULL, *ssids = NULL; struct nlattr *match = NULL; enum { ND_TOPLEVEL, ND_MATCH, ND_FREQS, + ND_ACTIVE, } parse_state = ND_TOPLEVEL; int c = *argc; char *end, **v = *argv; int err = 0, i = 0; unsigned int freq, interval = 0, delay = 0; - bool have_matchset = false, have_freqs = false; + bool have_matchset = false, have_freqs = false, have_ssids = false; + bool have_active = false, have_passive = false; matchset = nlmsg_alloc(); if (!matchset) { @@ -126,6 +128,12 @@ int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv) goto out; } + ssids = nlmsg_alloc(); + if (!ssids) { + err = -ENOMEM; + goto out; + } + while (c) { switch (parse_state) { case ND_TOPLEVEL: @@ -184,6 +192,22 @@ int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv) have_freqs = true; i = 0; + } else if (!strcmp(v[0], "active")) { + parse_state = ND_ACTIVE; + if (have_active || have_passive) { + err = -EINVAL; + goto nla_put_failure; + } + + have_active = true; + i = 0; + } else if (!strcmp(v[0], "passive")) { + if (have_active || have_passive) { + err = -EINVAL; + goto nla_put_failure; + } + + have_passive = true; } else { /* this element is not for us, so * return to continue parsing. @@ -249,9 +273,41 @@ int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv) c--; v++; } break; + case ND_ACTIVE: + if (!strcmp(v[0], "ssid")) { + c--; v++; + if (c == 0) { + err = -EINVAL; + goto nla_put_failure; + } + + NLA_PUT(ssids, + NL80211_SCHED_SCAN_MATCH_ATTR_SSID, + strlen(v[0]), v[0]); + + have_ssids = true; + i++; + c--; v++; + } else { + /* other element that cannot be part + * of a match indicates the end of the + * active set. */ + /* need at least one item in the set */ + if (i == 0) { + err = -EINVAL; + goto nla_put_failure; + } + + parse_state = ND_TOPLEVEL; + } + break; } } + if (!have_ssids) + NLA_PUT(ssids, 1, 0, ""); + if (!have_passive) + nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids); if (have_freqs) nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs); if (have_matchset)