From patchwork Thu May 31 11:11:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick X-Patchwork-Id: 923325 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=systemli.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gv0T1/lu"; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=systemli.org header.i=@systemli.org header.b="90wgIte/"; 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 40xQ2x3x9cz9ry1 for ; Thu, 31 May 2018 21:19:21 +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:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=4aXSlGuo5osXZC/UzNY6+6BFxSriCel+G8kKqaDQkM4=; b=gv0T1/luK6fKaJ l7J9grmEVsm9jekCvsMabXMZZTbMl1aaFNush2sKI7JCTzR7UOEHRjq5QibdMUdmbfGrvgOEta1CK JLWSAfW4s9785gkwLY0GtZY0KOYvnCMeOfVvShUY1A0Ylok0cBVJP7PoQXuWGpTs36YeEvyySn3zI 8i/nhCNfIlTB5W/s4Q3WaXM6aq3eRa0Db+8LHfpjW66OZf3tY38yF5MxcVd1+kqBDgaVcGF+u9YYJ qF6H7zmeO2Xeewi6L3vs4AEHOGq361Ocqq1aePJl4bhqT6xfinYQcnzPDJrZbyCxvY0WrYy1zIzlo 5RZY5h0a3Tzjk4e4M61Q==; 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 1fOLbl-0005mv-Jf; Thu, 31 May 2018 11:19:05 +0000 Received: from mail.systemli.org ([2c0f:f930:0:5::214]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fOLbg-0005ke-VJ for openwrt-devel@lists.openwrt.org; Thu, 31 May 2018 11:19:03 +0000 From: PolynomialDivision DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systemli.org; s=default; t=1527765073; bh=qWKSROiaK0kLuFGhWVDYvvZpoYStObf3sNTvUhhXpmI=; h=From:To:Cc:Subject:Date:From; b=90wgIte/BNKusNJsLVHSTXbZgRkA3ukmK9hgJN4WhqTy/+GKulVRFbybujEqDcRHh NoMCTMFvRokVipmX2VGlEqUw9fPvGT/CPr+HZenMwHMsp4/PIDnJcLU82rFvA3Z6Yx 3kCkV0A94TvMp9i2uFmQF8QLxfAo/hvpM70UsYPWT289bkcYvdV8rwg5WydUui9lIg XC23Qm4tEZmnObmNyGqc4UncIcB5fw53tt7RsQKrtRLqL5BWBtwWx/ZVrIh1dMAdAz xzNr4WM1BpDTOhd8KPS04Ps2ZRT+1+/dLxDETYpVhbX/I2krsbAZ2B3jcYQ+Qrry39 DN8v0TMBFNCPA== To: openwrt-devel@lists.openwrt.org Date: Thu, 31 May 2018 13:11:08 +0200 Message-Id: <1527765068-15612-1-git-send-email-vincent@systemli.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180531_041901_489906_F4A1AD8F X-CRM114-Status: UNSURE ( 9.92 ) X-CRM114-Notice: Please train this message. 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [OpenWrt-Devel] [PATCH] iwinfo: add channel 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: Nick Hainke MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Add channel survey data. Signed-off-by: Nick Hainke Signed-off-by: Nick Hainke Signed-off-by: Nick Hainke --- include/iwinfo.h | 11 +++++++++++ iwinfo_cli.c | 31 ++++++++++++++++++++++++++++- iwinfo_nl80211.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/include/iwinfo.h b/include/iwinfo.h index 929f697..004896e 100644 --- a/include/iwinfo.h +++ b/include/iwinfo.h @@ -157,6 +157,16 @@ struct iwinfo_scanlist_entry { struct iwinfo_crypto_entry crypto; }; +struct iwinfo_survey_entry { + uint32_t frequency; + int8_t noise; + uint64_t channel_time; + uint64_t channel_time_busy; + uint64_t channel_time_ext_busy; + uint64_t channel_time_rx; + uint64_t channel_time_tx; +}; + struct iwinfo_country_entry { uint16_t iso3166; char ccode[4]; @@ -203,6 +213,7 @@ struct iwinfo_ops { int (*bitrate)(const char *, int *); int (*signal)(const char *, int *); int (*noise)(const char *, int *); + int (*survey)(const char *ifname, struct iwinfo_survey_entry *entry); int (*quality)(const char *, int *); int (*quality_max)(const char *, int *); int (*mbssid_support)(const char *, int *); diff --git a/iwinfo_cli.c b/iwinfo_cli.c index 49c9035..3d8b82c 100644 --- a/iwinfo_cli.c +++ b/iwinfo_cli.c @@ -116,6 +116,18 @@ static char * format_signal(int sig) return buf; } +static char * format_channel_time(uint64_t time) +{ + static char buf[30]; + + if (!time) + snprintf(buf, sizeof(buf), "unknown"); + else + snprintf(buf, sizeof(buf), "%llu ms", time); + + return buf; +} + static char * format_noise(int noise) { static char buf[10]; @@ -531,6 +543,19 @@ static char * print_phyname(const struct iwinfo_ops *iw, const char *ifname) return "?"; } +static void print_survey(const struct iwinfo_ops *iw, const char *ifname) +{ + struct iwinfo_survey_entry entry; + iw->survey(ifname, &entry); + printf("%s\tESSID:\t\t\t\t%s\n", ifname, print_ssid(iw, ifname)); + printf("\tChannel:\t\t\t%s (%s)\n", print_channel(iw, ifname), format_frequency(entry.frequency)); + printf("\tNoise:\t\t\t\t%s\n", format_noise(entry.noise)); + printf("\tchannel Active Time:\t\t%s\n", format_channel_time(entry.channel_time)); + printf("\tChannel Busy Time:\t\t%s\n",format_channel_time(entry.channel_time_busy)); + printf("\tExtension Channel Busy Time:\t%s\n",format_channel_time(entry.channel_time_ext_busy)); + printf("\tChannel Receive Time:\t\t%s\n",format_channel_time(entry.channel_time_rx)); + printf("\tChannel Transmit Time:\t\t%s\n",format_channel_time(entry.channel_time_tx)); +} static void print_info(const struct iwinfo_ops *iw, const char *ifname) { @@ -805,6 +830,7 @@ int main(int argc, char **argv) "Usage:\n" " iwinfo info\n" " iwinfo scan\n" + " iwinfo survey\n" " iwinfo txpowerlist\n" " iwinfo freqlist\n" " iwinfo assoclist\n" @@ -883,7 +909,10 @@ int main(int argc, char **argv) break; case 's': - print_scanlist(iw, argv[1]); + if(argv[i][1] == 'c') + print_scanlist(iw, argv[1]); + else + print_survey(iw, argv[1]); break; case 't': diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index ecd2d6a..2c741a3 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1357,6 +1357,63 @@ static int nl80211_get_signal(const char *ifname, int *buf) return -1; } +static int nl80211_get_channel_survey_cb(struct nl_msg *msg, void *arg) +{ + struct iwinfo_survey_entry *entry = arg; + struct nlattr *tb[NL80211_ATTR_MAX + 1]; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *si[NL80211_SURVEY_INFO_MAX + 1]; + + static struct nla_policy sp[NL80211_SURVEY_INFO_MAX + 1] = { + [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, + [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, + }; + + nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL); + + if (!tb[NL80211_ATTR_SURVEY_INFO]) + return NL_SKIP; + + if (nla_parse_nested(si, NL80211_SURVEY_INFO_MAX, + tb[NL80211_ATTR_SURVEY_INFO], sp)) + return NL_SKIP; + + if (si[NL80211_SURVEY_INFO_IN_USE]) + { + si[NL80211_SURVEY_INFO_FREQUENCY] ? + entry->frequency = (uint32_t)nla_get_u32(si[NL80211_SURVEY_INFO_FREQUENCY]) : 0; + + si[NL80211_SURVEY_INFO_NOISE] ? + entry->noise = (int8_t)nla_get_u8(si[NL80211_SURVEY_INFO_NOISE]) : 0; + + si[NL80211_SURVEY_INFO_CHANNEL_TIME] ? + entry->channel_time = (uint64_t)nla_get_u64(si[NL80211_SURVEY_INFO_CHANNEL_TIME]) : 0; + + si[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY] ? + entry->channel_time_busy = (uint64_t)nla_get_u64(si[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) : 0; + + si[NL80211_SURVEY_INFO_TIME_EXT_BUSY] ? + entry->channel_time_ext_busy = (uint64_t)nla_get_u64(si[NL80211_SURVEY_INFO_TIME_EXT_BUSY]) : 0; + + si[NL80211_SURVEY_INFO_TIME_RX] ? + entry->channel_time_rx = (uint64_t)nla_get_u64(si[NL80211_SURVEY_INFO_TIME_RX]) : 0; + + si[NL80211_SURVEY_INFO_TIME_TX] ? + entry->channel_time_tx = (uint64_t)nla_get_u64(si[NL80211_SURVEY_INFO_TIME_TX]) : 0; + } + + return NL_SKIP; +} + +static int nl80211_get_channel_survey(const char *ifname, struct iwinfo_survey_entry *entry) +{ + if (nl80211_request(ifname, NL80211_CMD_GET_SURVEY, NLM_F_DUMP, + nl80211_get_channel_survey_cb, entry)) + return -1; + return 0; +} + static int nl80211_get_noise_cb(struct nl_msg *msg, void *arg) { int8_t *noise = arg; @@ -1384,7 +1441,6 @@ static int nl80211_get_noise_cb(struct nl_msg *msg, void *arg) return NL_SKIP; } - static int nl80211_get_noise(const char *ifname, int *buf) { int8_t noise = 0; @@ -2832,6 +2888,7 @@ const struct iwinfo_ops nl80211_ops = { .bitrate = nl80211_get_bitrate, .signal = nl80211_get_signal, .noise = nl80211_get_noise, + .survey = nl80211_get_channel_survey, .quality = nl80211_get_quality, .quality_max = nl80211_get_quality_max, .mbssid_support = nl80211_get_mbssid_support,