From patchwork Sun Dec 6 01:18:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1411665 X-Patchwork-Delegate: ansuelsmth@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.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=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=CNN/DGnS; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=K5QvtucB; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CpTCt57Z8z9sW1 for ; Sun, 6 Dec 2020 12:20:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=h6I6kUw7BILw/t3nsLlZtxlFFadxkzfjNjbzYEJEqKY=; b=CNN/DGnSmQBDGCMpY57vyp+aL nah1OAD6GyLWJgmjowngz8ARfSRa58CWN8TxGJpII1Et4QEQuSHw1M2FL7YTxIYuUZ+75zx0C6Ql9 H6ainVdJbAiQIMVyILhM3uCvWZJWsGByDKeh8yRuTmiDHgCfzVvWQHA7z+m+CWV4KWUkec0T/iIea AgHY6IMSzn6X2H7wTgZOdnTdTu9lzZUdIISSeRpVVnwZ49Usz+OfVocjha/GrBMm/IkgDY6APVzeB 4FESR5mJeItv6oHFIcGuAxm8bPoVI+Wmp8P89Usu7jI7751ba3prpkdwaQukcNi/tZclouZAzk2+e imutkDriQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1klihP-0007JH-Uf; Sun, 06 Dec 2020 01:18:51 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1klihA-0007GV-Jn for openwrt-devel@lists.openwrt.org; Sun, 06 Dec 2020 01:18:37 +0000 Received: by mail-wr1-x443.google.com with SMTP id t4so9046011wrr.12 for ; Sat, 05 Dec 2020 17:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IFEHczl1EhNRBu0nBZmKRm1PY7jxTJ74y2X2oT6VwKI=; b=K5QvtucBY5KdzUcc8WC7pec2o0s3rD74UU05TKLJQJlGo2z+c/G/VaKwbqMUe8D++f 027uwDusemT8ietp/GPFsDw6P/DyOCa4YUZrpEIICAVlu9gL+m/WC4YpQ7B4JXHVGESc HRz0hCWbIrQLZC9Ph7teqpjT1sDdUizvDVGXgCJPa2ValUYrvhMGIdmURoIGfMdmP8du f9KX7WijnCRWk1xCEWH5Tx0cY19W2UKdS0Kyy73rHYlQ4Odt2zojk04rbsWX5g/cziDZ YvUqqmvVKMUqOQbY8OPmjezszVkuMnd/ve03ip1xyDTSO2tpL4vQghEg4f8bK6bCPBoJ yYSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IFEHczl1EhNRBu0nBZmKRm1PY7jxTJ74y2X2oT6VwKI=; b=sUcOK2AdqMKv+Iu8KwGlciKRAr80ct8YcV7e+LfvoeTTOqG0YLOxfFgrNgHoz3MvZK lvsuB6Tb+Lc1ozXBa1gIe2Xxks25lN/POcK3XAm7IWYCQjSYCi8TEYn3QwTWubrN9Fw3 dXmD5/BozHxPEXPGvPI+dJVcGJ/a2sqqhxXHVYy0bd+2TYJaywpxrhUF5e7wWVnceMsg 4Gy/EkEviKcwxS2cenhkch/aqrfJmziW2m86t5uI+w0iBbDC+yuhXmAXQ7iq5yN/96My z0EPSwSj6e+YJcLl+UroYnP5U+NJa16wLNWcVkvSpaKIo+lqAqoImYfe6VfxgCM4/vly kLwA== X-Gm-Message-State: AOAM5313+lhTRVhlvPdXUtg3AMQoPNb+4w9pU27cAb7fVRXBiqmrtPnK ufY5Kmc2XHIZzy1GTokr47gXf5oKW0E= X-Google-Smtp-Source: ABdhPJyb2dEpCzDiSho0KdrLTjMJ11I2jq0yandfS8bEQiH+3u1h4xQvN8hvwMPQe87z3AuSjw9U+A== X-Received: by 2002:a5d:4612:: with SMTP id t18mr12553358wrq.401.1607217515069; Sat, 05 Dec 2020 17:18:35 -0800 (PST) Received: from ansuel-xps20.localdomain (host-87-1-248-10.retail.telecomitalia.it. [87.1.248.10]) by smtp.googlemail.com with ESMTPSA id q12sm9143174wrx.86.2020.12.05.17.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2020 17:18:34 -0800 (PST) From: Ansuel Smith To: openwrt-devel@lists.openwrt.org Subject: [IWINFO PATCH v4 2/4] iwinfo: export center_chan info for local wifi Date: Sun, 6 Dec 2020 02:18:25 +0100 Message-Id: <20201206011827.20782-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206011827.20782-1-ansuelsmth@gmail.com> References: <20201206011827.20782-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201205_201836_711247_80247751 X-CRM114-Status: GOOD ( 19.37 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ansuelsmth[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ansuel Smith Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Iwinfo already export the htmode but there is no way to know where the channel expan in case a 40Mhz+ channel width is used. Export the center channels used by the driver to better know the channel utilizzation of the wifi. Signed-off-by: Ansuel Smith --- include/iwinfo.h | 2 ++ iwinfo_cli.c | 23 +++++++++++++++ iwinfo_nl80211.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/include/iwinfo.h b/include/iwinfo.h index 676db91..680f384 100644 --- a/include/iwinfo.h +++ b/include/iwinfo.h @@ -282,6 +282,8 @@ struct iwinfo_ops { int (*survey)(const char *, char *, int *); int (*lookup_phy)(const char *, char *); void (*close)(void); + int (*center_chan1)(const char *, int *); + int (*center_chan2)(const char *, int *); }; const char * iwinfo_type(const char *ifname); diff --git a/iwinfo_cli.c b/iwinfo_cli.c index 6bfe0ab..cc5d298 100644 --- a/iwinfo_cli.c +++ b/iwinfo_cli.c @@ -445,6 +445,24 @@ static char * print_channel(const struct iwinfo_ops *iw, const char *ifname) return format_channel(ch); } +static char * print_center_chan1(const struct iwinfo_ops *iw, const char *ifname) +{ + int ch; + if (iw->center_chan1(ifname, &ch)) + ch = -1; + + return format_channel(ch); +} + +static char * print_center_chan2(const struct iwinfo_ops *iw, const char *ifname) +{ + int ch; + if (iw->center_chan2(ifname, &ch)) + ch = -1; + + return format_channel(ch); +} + static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname) { int freq; @@ -566,6 +584,11 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname) print_mode(iw, ifname), print_channel(iw, ifname), print_frequency(iw, ifname)); + if (iw->center_chan1 != NULL) { + printf(" Center Channel 1: %s", + print_center_chan1(iw, ifname)); + printf(" 2: %s\n", print_center_chan2(iw, ifname)); + } printf(" Tx-Power: %s Link Quality: %s/%s\n", print_txpower(iw, ifname), print_quality(iw, ifname), diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 5917e3a..1bcc5ea 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1262,6 +1262,56 @@ static int nl80211_get_frequency(const char *ifname, int *buf) return (*buf == 0) ? -1 : 0; } +static int nl80211_get_center_freq1_cb(struct nl_msg *msg, void *arg) +{ + int *freq = arg; + struct nlattr **tb = nl80211_parse(msg); + + if (tb[NL80211_ATTR_CENTER_FREQ1]) + *freq = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); + + return NL_SKIP; +} + +static int nl80211_get_center_freq1(const char *ifname, int *buf) +{ + char *res; + + /* try to find frequency from interface info */ + res = nl80211_phy2ifname(ifname); + *buf = 0; + + nl80211_request(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0, + nl80211_get_center_freq1_cb, buf); + + return (*buf == 0) ? -1 : 0; +} + +static int nl80211_get_center_freq2_cb(struct nl_msg *msg, void *arg) +{ + int *freq = arg; + struct nlattr **tb = nl80211_parse(msg); + + if (tb[NL80211_ATTR_CENTER_FREQ2]) + *freq = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); + + return NL_SKIP; +} + +static int nl80211_get_center_freq2(const char *ifname, int *buf) +{ + char *res; + + /* try to find frequency from interface info */ + res = nl80211_phy2ifname(ifname); + *buf = 0; + + nl80211_request(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0, + nl80211_get_center_freq2_cb, buf); + + return (*buf == 0) ? -1 : 0; +} + static int nl80211_get_channel(const char *ifname, int *buf) { if (!nl80211_get_frequency(ifname, buf)) @@ -1273,6 +1323,28 @@ static int nl80211_get_channel(const char *ifname, int *buf) return -1; } +static int nl80211_get_center_chan1(const char *ifname, int *buf) +{ + if (!nl80211_get_center_freq1(ifname, buf)) + { + *buf = nl80211_freq2channel(*buf); + return 0; + } + + return -1; +} + +static int nl80211_get_center_chan2(const char *ifname, int *buf) +{ + if (!nl80211_get_center_freq2(ifname, buf)) + { + *buf = nl80211_freq2channel(*buf); + return 0; + } + + return -1; +} + static int nl80211_get_txpower_cb(struct nl_msg *msg, void *arg) { int *buf = arg; @@ -3242,5 +3314,7 @@ const struct iwinfo_ops nl80211_ops = { .countrylist = nl80211_get_countrylist, .survey = nl80211_get_survey, .lookup_phy = nl80211_lookup_phyname, - .close = nl80211_close + .close = nl80211_close, + .center_chan1 = nl80211_get_center_chan1, + .center_chan2 = nl80211_get_center_chan2 };