From patchwork Tue Jul 3 13:32:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Danzberger X-Patchwork-Id: 938674 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=dd-wrt.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Vt2QCnvN"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=dd-wrt.com header.i=@dd-wrt.com header.b="rtW4PYzg"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KlSW5dSjz9s29 for ; Tue, 3 Jul 2018 23:33:31 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s08J8SCBEbe/P7Gt4Qf8NetFsnFv+YeYkcwIdsos9Gs=; b=Vt2QCnvN4ylmgJ 9aTjf5aLcor8FNEzJDjIcIbkn4753OjaHYT4o0lYU44rAi4G92dBNgJcHlM3m8I7j6PIjI8KvFcFs 0Z6ikSuPKhM8jy8YhuW25mf/i+Yz0U5K+79zRDko6XmZYpHxY3DGU+vzUa72Q+Izj/s2P9pRAO1AC rrsDF91SzZNWb7j+GTDde3VXMelPwJZXwFvoXCpSqn6gXS3JZw/K69PGibU22iU0H9kdbPrpX3SaI rBqjwRUCm3M77SWiyKoHrvm7gEGK3KU+u0T18VA+ZlfugrqNlgVLG4Wbg6TKH2tUy/gl9ig3s2XKg 8iNbQrFNV46DWYrDpYTg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1faLQu-0004Pm-Ay; Tue, 03 Jul 2018 13:33:28 +0000 Received: from smtps.newmedia-net.de ([2a05:a1c0:0:de::167] helo=webmail.newmedia-net.de) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1faLQS-0003uu-Pp for openwrt-devel@lists.openwrt.org; Tue, 03 Jul 2018 13:33:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dd-wrt.com; s=mikd; h=Subject:References:In-Reply-To:Message-Id:Date:Cc:To:From; bh=rAx/yoWXDfNvabPKGOitQiu2y1wHiGnt7Wsb8cOpZeU=; b=rtW4PYzglUxiAEcswF3cz2XRuMa7cS7zgYqsC6fpoHcWyCCQNenZwxC4k/yUw4/ihZ9pktaoCssT600wZLQ5tmuYvXWvpT85F0ohtk/gP1VL+apqdnfFUrITB6eApOT/JFub+lyhnKJ8F4/mYYDJH0d1k6YlksDzsAfJ2wxYeyw=; From: Daniel Danzberger To: openwrt-devel@lists.openwrt.org Date: Tue, 3 Jul 2018 15:32:11 +0200 Message-Id: <20180703133211.23120-3-daniel@dd-wrt.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180703133211.23120-1-daniel@dd-wrt.com> References: <20180703133211.23120-1-daniel@dd-wrt.com> X-SA-Exim-Connect-IP: 2a05:a1c7:1:b101:c961:6254:c20e:6974 X-SA-Exim-Mail-From: daniel@dd-wrt.com X-Spam-Checker-Version: SpamAssassin 3.1.9 (2007-02-13) on webmail.newmedia-net.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=4.0 tests=BAYES_00,NO_RELAYS autolearn=ham version=3.1.9, No X-SA-Exim-Version: 4.2.1 (built Thu, 26 May 2011 15:22:33 +0200) X-SA-Exim-Scanned: Yes (on webmail.newmedia-net.de) X-NMN-MailScanner-Information: Please contact the ISP for more information X-NMN-MailScanner-ID: 1faLQ4-000715-T4 X-NMN-MailScanner: Found to be clean X-NMN-MailScanner-From: daniel@dd-wrt.com X-Received: from [2a05:a1c7:1:b101:c961:6254:c20e:6974] (helo=lappi.newmedia-net.de) by webmail.newmedia-net.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1faLQ4-000715-T4; Tue, 03 Jul 2018 15:32:37 +0200 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180703_063302_000832_02024C3B X-CRM114-Status: GOOD ( 10.52 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [OpenWrt-Devel] [PATCH 2/2] iwinfo: nl80211: add survey. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Danzberger MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Signed-off-by: Daniel Danzberger --- include/iwinfo.h | 11 ++++++++ iwinfo_nl80211.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/iwinfo.h b/include/iwinfo.h index 4111205..49ee7f0 100644 --- a/include/iwinfo.h +++ b/include/iwinfo.h @@ -128,6 +128,16 @@ struct iwinfo_assoclist_entry { uint32_t thr; }; +struct iwinfo_survey_entry { + uint64_t active_time; + uint64_t busy_time; + uint64_t busy_time_ext; + uint64_t rxtime; + uint64_t txtime; + uint32_t mhz; + uint8_t noise; +}; + struct iwinfo_txpwrlist_entry { uint8_t dbm; uint16_t mw; @@ -223,6 +233,7 @@ struct iwinfo_ops { int (*scanlist)(const char *, char *, int *); int (*freqlist)(const char *, char *, int *); int (*countrylist)(const char *, char *, int *); + int (*survey)(const char *, char *, int *); int (*lookup_phy)(const char *, char *); void (*close)(void); }; diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 0e0206b..71465b5 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1678,6 +1678,59 @@ static void nl80211_parse_rateinfo(struct nlattr **ri, re->is_40mhz = (re->mhz == 40); } +static int nl80211_get_survey_cb(struct nl_msg *msg, void *arg) +{ + struct nl80211_array_buf *arr = arg; + struct iwinfo_survey_entry *e = arr->buf; + struct nlattr **attr = nl80211_parse(msg); + struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; + int rc; + + static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { + [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, + [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, + [NL80211_SURVEY_INFO_TIME] = { .type = NLA_U64 }, + [NL80211_SURVEY_INFO_TIME_BUSY] = { .type = NLA_U64 }, + [NL80211_SURVEY_INFO_TIME_EXT_BUSY] = { .type = NLA_U64 }, + [NL80211_SURVEY_INFO_TIME_RX] = { .type = NLA_U64 }, + [NL80211_SURVEY_INFO_TIME_TX] = { .type = NLA_U64 }, + }; + + rc = nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, + attr[NL80211_ATTR_SURVEY_INFO], + survey_policy); + if (rc) + return NL_SKIP; + + /* advance to end of array */ + e += arr->count; + memset(e, 0, sizeof(*e)); + + if (sinfo[NL80211_SURVEY_INFO_FREQUENCY]) + e->mhz = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); + + if (sinfo[NL80211_SURVEY_INFO_NOISE]) + e->noise = nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); + + if (sinfo[NL80211_SURVEY_INFO_TIME]) + e->active_time = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME]); + + if (sinfo[NL80211_SURVEY_INFO_TIME_BUSY]) + e->busy_time = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_BUSY]); + + if (sinfo[NL80211_SURVEY_INFO_TIME_EXT_BUSY]) + e->busy_time_ext = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_EXT_BUSY]); + + if (sinfo[NL80211_SURVEY_INFO_TIME_RX]) + e->rxtime = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_RX]); + + if (sinfo[NL80211_SURVEY_INFO_TIME_TX]) + e->txtime = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_TX]); + + arr->count++; + return NL_SKIP; +} + static int nl80211_get_assoclist_cb(struct nl_msg *msg, void *arg) { struct nl80211_array_buf *arr = arg; @@ -1812,6 +1865,21 @@ static int nl80211_get_assoclist_cb(struct nl_msg *msg, void *arg) return NL_SKIP; } +static int nl80211_get_survey(const char *ifname, char *buf, int *len) +{ + struct nl80211_array_buf arr = { .buf = buf, .count = 0 }; + int rc; + + rc = nl80211_request(ifname, NL80211_CMD_GET_SURVEY, + NLM_F_DUMP, nl80211_get_survey_cb, &arr); + if (!rc) + *len = (arr.count * sizeof(struct iwinfo_survey_entry)); + else + *len = 0; + + return 0; +} + static int nl80211_get_assoclist(const char *ifname, char *buf, int *len) { DIR *d; @@ -2862,6 +2930,7 @@ const struct iwinfo_ops nl80211_ops = { .scanlist = nl80211_get_scanlist, .freqlist = nl80211_get_freqlist, .countrylist = nl80211_get_countrylist, + .survey = nl80211_get_survey, .lookup_phy = nl80211_lookup_phyname, .close = nl80211_close };