From patchwork Thu Dec 17 10:47:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Ivanov X-Patchwork-Id: 558206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2D18514029E for ; Thu, 17 Dec 2015 21:47:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ubnt.com header.i=@ubnt.com header.b=l1MNHibG; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2B6942809EF; Thu, 17 Dec 2015 11:47:28 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id ED45E2809D4 for ; Thu, 17 Dec 2015 11:47:20 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .ubnt. - helo: .mail-lf0-f41.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 17 Dec 2015 11:47:16 +0100 (CET) Received: by mail-lf0-f41.google.com with SMTP id p203so49480540lfa.0 for ; Thu, 17 Dec 2015 02:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ubnt.com; s=google; h=date:from:to:subject:message-id:mime-version:content-type :content-transfer-encoding; bh=zdT3dmvUBBl+fqb4pmHr4/+ElCImRGlTO6p+vW7jCkI=; b=l1MNHibGtCN4yC94SE1g7FJ308ABnNcqUsP9vuMDCIJsCMc3Fck/Z+WY4s+aMB77DT 6GI1kYueCNl5wSErdQ0F4AW+GZB5Ix5XCYiMVYGV1QgLchGSRbmSGAbHKhqZGTDtj3Dj Xj5CqCfbjAOy9DLgtPYg9XE0U7uiBP5TymKvA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-transfer-encoding; bh=zdT3dmvUBBl+fqb4pmHr4/+ElCImRGlTO6p+vW7jCkI=; b=cr9IrL4f8R5GFt0UMP6zipPX00P9KR4kIuxy386W58pVNOjYGthECkIDL9EILSfTon 06ag32C0JzFMwIghBzXjd2DrYIvG3Dz8DwmC8vdH43uMYQj3ywZOm+dO8r4/5Gg6BgKP ZpLSmq7yiym9znbn20vrY0HPhPFqLPmifczyKORHvhiwuj44lJThDrxaDGZLGrV0ebFb Rcd9XP4KkkuVe3/ROmwXqlCNLeesgoV0a031UdVBY8zrgk4OUIF04zk7FluIY32xn7ol w0PCp5NNMmC7OqX9FvFln/Zzxk5SYtyxTCPRMNtNXQ30eM5aMj67TfDCEHiCNo6lt6gM cb+g== X-Gm-Message-State: ALoCoQmpfB1oQTzz1nYbQ3Ou0qqr5uD7fb+88FuAf/NOMRA+SiWluS0J2CZK+GSeks7Bz5pYtNFHQn6EjG6TSxWyUcTYyzXKNRqUw/CFhUbm127uU8cDz14mLoimtyviGFiMlabp+EFSpDJJBpqz8CDEB6WU0Cd/danSiUcHNt/9ThZWJ6R4VP0PcEYvUQbD1blTnMR3OYB9UAWA/3bZZTcog7INk6JwzA== X-Received: by 10.25.85.78 with SMTP id j75mr21065409lfb.46.1450349251083; Thu, 17 Dec 2015 02:47:31 -0800 (PST) Received: from di ([80.233.186.214]) by smtp.gmail.com with ESMTPSA id rm5sm1817281lbb.20.2015.12.17.02.47.30 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Dec 2015 02:47:30 -0800 (PST) Date: Thu, 17 Dec 2015 12:47:29 +0200 From: Dmitry Ivanov To: openwrt-devel@lists.openwrt.org Message-Id: <20151217124729.6630c5e8beefc75dc408e6e3@ubnt.com> X-Mailer: Sylpheed 3.5.0beta1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) Mime-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH] Allow scan of single channel X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Sometimes it is enough to scan single channel only. This is much faster than scanning all of them and ingnoring unnecessary data. Signed-off-by: Dmitry Ivanov --- include/iwinfo.h | 1 + iwinfo_cli.c | 65 ++++++++++++++++++++++++++++++++++++++++---------------- iwinfo_nl80211.c | 33 +++++++++++++++++++++------- 3 files changed, 73 insertions(+), 26 deletions(-) diff --git a/include/iwinfo.h b/include/iwinfo.h index f8cec73..e5ea48e 100644 --- a/include/iwinfo.h +++ b/include/iwinfo.h @@ -202,6 +202,7 @@ struct iwinfo_ops { int (*assoclist)(const char *, char *, int *); int (*txpwrlist)(const char *, char *, int *); int (*scanlist)(const char *, char *, int *); + int (*scanlist2)(const char *, char *, int *, unsigned int); int (*freqlist)(const char *, char *, int *); int (*countrylist)(const char *, char *, int *); int (*lookup_phy)(const char *, char *); diff --git a/iwinfo_cli.c b/iwinfo_cli.c index 7cb90c2..b0cc76d 100644 --- a/iwinfo_cli.c +++ b/iwinfo_cli.c @@ -562,18 +562,32 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname) } -static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname) +static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname, unsigned int freq) { int i, x, len; char buf[IWINFO_BUFSIZE]; struct iwinfo_scanlist_entry *e; - if (iw->scanlist(ifname, buf, &len)) + if (freq) + { + if (!iw->scanlist2) + { + printf("Scanning of specific frequency not implemented\n\n"); + return; + } + if (iw->scanlist2(ifname, buf, &len, freq)) + { + printf("Scanning of specific frequency not possible\n\n"); + return; + } + } + else if (iw->scanlist(ifname, buf, &len)) { printf("Scanning not possible\n\n"); return; } - else if (len <= 0) + + if (len <= 0) { printf("No scan results\n\n"); return; @@ -794,6 +808,7 @@ int main(int argc, char **argv) "Usage:\n" " iwinfo info\n" " iwinfo scan\n" + " iwinfo scan \n" " iwinfo txpowerlist\n" " iwinfo freqlist\n" " iwinfo assoclist\n" @@ -831,25 +846,37 @@ int main(int argc, char **argv) if (argc > 3) { - iw = iwinfo_backend_by_name(argv[1]); - - if (!iw) - { - fprintf(stderr, "No such wireless backend: %s\n", argv[1]); - rv = 1; - } - else + switch (argv[2][0]) { - switch (argv[2][0]) + case 'p': + iw = iwinfo_backend_by_name(argv[1]); + + if (!iw) { - case 'p': - lookup_phy(iw, argv[3]); - break; + fprintf(stderr, "No such wireless backend: %s\n", argv[1]); + rv = 1; + goto finish; + } + + lookup_phy(iw, argv[3]); + break; + + case 's': + iw = iwinfo_backend(argv[1]); - default: - fprintf(stderr, "Unknown command: %s\n", argv[2]); + if (!iw) + { + fprintf(stderr, "No such wireless device: %s\n", argv[1]); rv = 1; + goto finish; } + + print_scanlist(iw, argv[1], atoi(argv[3])); + break; + + default: + fprintf(stderr, "Unknown command: %s\n", argv[2]); + rv = 1; } } else @@ -872,7 +899,7 @@ int main(int argc, char **argv) break; case 's': - print_scanlist(iw, argv[1]); + print_scanlist(iw, argv[1], 0); break; case 't': @@ -903,6 +930,8 @@ int main(int argc, char **argv) } } +finish: + iwinfo_finish(); return rv; diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index a65ed1e..de4cdd1 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -2083,7 +2083,7 @@ static int nl80211_get_scanlist_cb(struct nl_msg *msg, void *arg) return NL_SKIP; } -static int nl80211_get_scanlist_nl(const char *ifname, char *buf, int *len) +static int nl80211_get_scanlist_nl(const char *ifname, char *buf, int *len, unsigned int freq) { struct nl80211_msg_conveyor *req; struct nl80211_scanlist sl = { .e = (struct iwinfo_scanlist_entry *)buf }; @@ -2091,6 +2091,17 @@ static int nl80211_get_scanlist_nl(const char *ifname, char *buf, int *len) req = nl80211_msg(ifname, NL80211_CMD_TRIGGER_SCAN, 0); if (req) { + if (freq) + { + struct nlattr *freqs; + freqs = nla_nest_start(req->msg, NL80211_ATTR_SCAN_FREQUENCIES); + if (!freqs) + return -1; + if (nla_put_u32(req->msg, 1, freq)) + return -1; + nla_nest_end(req->msg, freqs); + } + nl80211_send(req, NULL, NULL); nl80211_free(req); } @@ -2298,7 +2309,7 @@ static int nl80211_get_scanlist_wpactl(const char *ifname, char *buf, int *len) return (count >= 0) ? 0 : -1; } -static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) +static int nl80211_get_scanlist2(const char *ifname, char *buf, int *len, unsigned int freq) { char *res; int rv, mode; @@ -2311,13 +2322,13 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) /* Reuse existing interface */ if ((res = nl80211_phy2ifname(ifname)) != NULL) { - return nl80211_get_scanlist(res, buf, len); + return nl80211_get_scanlist2(res, buf, len, freq); } /* Need to spawn a temporary iface for scanning */ else if ((res = nl80211_ifadd(ifname)) != NULL) { - rv = nl80211_get_scanlist(res, buf, len); + rv = nl80211_get_scanlist2(res, buf, len, freq); nl80211_ifdel(res); return rv; } @@ -2337,7 +2348,7 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) mode == IWINFO_OPMODE_MONITOR) && iwinfo_ifup(ifname)) { - return nl80211_get_scanlist_nl(ifname, buf, len); + return nl80211_get_scanlist_nl(ifname, buf, len, freq); } /* AP scan */ @@ -2349,7 +2360,7 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) if (!iwinfo_ifup(ifname)) return -1; - rv = nl80211_get_scanlist_nl(ifname, buf, len); + rv = nl80211_get_scanlist_nl(ifname, buf, len, freq); iwinfo_ifdown(ifname); return rv; } @@ -2366,7 +2377,7 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) * additional interface and there's no need to tear down the ap */ if (iwinfo_ifup(res)) { - rv = nl80211_get_scanlist_nl(res, buf, len); + rv = nl80211_get_scanlist_nl(res, buf, len, freq); iwinfo_ifdown(res); } @@ -2374,7 +2385,7 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) * during scan */ else if (iwinfo_ifdown(ifname) && iwinfo_ifup(res)) { - rv = nl80211_get_scanlist_nl(res, buf, len); + rv = nl80211_get_scanlist_nl(res, buf, len, freq); iwinfo_ifdown(res); iwinfo_ifup(ifname); nl80211_hostapd_hup(ifname); @@ -2388,6 +2399,11 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) return -1; } +static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) +{ + return nl80211_get_scanlist2(ifname, buf, len, 0); +} + static int nl80211_get_freqlist_cb(struct nl_msg *msg, void *arg) { int bands_remain, freqs_remain; @@ -2814,6 +2830,7 @@ const struct iwinfo_ops nl80211_ops = { .assoclist = nl80211_get_assoclist, .txpwrlist = nl80211_get_txpwrlist, .scanlist = nl80211_get_scanlist, + .scanlist2 = nl80211_get_scanlist2, .freqlist = nl80211_get_freqlist, .countrylist = nl80211_get_countrylist, .lookup_phy = nl80211_lookup_phyname,