From patchwork Mon Jul 16 09:32:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Shvedov X-Patchwork-Id: 944265 X-Patchwork-Delegate: ynezz@true.cz 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=none (p=none dis=none) header.from=wimarksystems.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kJtEUlal"; 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 41TdVh5m8vz9rxs for ; Mon, 16 Jul 2018 19:32:44 +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=/dfPJ/e+QhY6csvvKjEhu9ItfPwYb4efn2kHdAYpBOY=; b=kJtEUlaljHm7H+ 5wrpuQqCcNC9D0u3w/FMZ/2y7qb0QHF/7dgqjLw9AfkJ3GC8AEufUj/8lK4YxRORsfe467TFCgJhw EIzxgcgDrDf4nv5Oo65CbQOaXAPMxW3hVCr1kzbj2560IsjCEpPwZ+5FRMMMNiOj3Z0Jy1KB2LvMW 89WVRV35HIKPOiSYp8WhNUAPCvNTxdoW8/r9dw2Yu+XKsHMExOV9dWdae3s7l5HbHVh7ABeejb3NG qWbACmY7qPifRMltseEyM0QufqhRkxA5PosMEKdrh/9Esu5XH5s8eBV8eNiyn3DDyTr0C8wak2X/p eh/BdEidxwjHemVt8E+g==; 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 1fezrx-0000E6-7w; Mon, 16 Jul 2018 09:32:37 +0000 Received: from forward106o.mail.yandex.net ([37.140.190.187]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fezru-0000Cq-9Q for openwrt-devel@lists.openwrt.org; Mon, 16 Jul 2018 09:32:36 +0000 Received: from mxback13g.mail.yandex.net (mxback13g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:92]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 9050C78507D; Mon, 16 Jul 2018 12:32:12 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback13g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id ioGPxyR9D9-WCaCxG5O; Mon, 16 Jul 2018 12:32:12 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id JOw2QCzuny-WBlCEPuB; Mon, 16 Jul 2018 12:32:11 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Yury Shvedov To: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Date: Mon, 16 Jul 2018 12:32:10 +0300 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180716_023234_701375_56900296 X-CRM114-Status: GOOD ( 12.19 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [37.140.190.187 listed in list.dnswl.org] Subject: [OpenWrt-Devel] [PATCH 2/2] add channel information for scan results 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: openwrt-devel@lists.openwrt.org, Jo-Philipp Wich MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Besides channel number the secondary channel for HT40 and center idx0 and idx1 gives full understanding about real channel position and width on the spectra. So grab it via nl80211 and make it available in both C and LUA APIs, and show detailed channel information on CLI scan results. Signed-off-by: Yury Shvedov --- Sorry, I do not use git mailer frequently. Is this a right place for comments? include/iwinfo.h | 19 +++++++++++++++++++ iwinfo_cli.c | 10 ++++++++++ iwinfo_lua.c | 11 +++++++++++ iwinfo_nl80211.c | 32 ++++++++++++++++++++++++++++++-- 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/include/iwinfo.h b/include/iwinfo.h index b3f5470..1559837 100644 --- a/include/iwinfo.h +++ b/include/iwinfo.h @@ -145,6 +145,24 @@ struct iwinfo_crypto_entry { uint8_t auth_suites; uint8_t auth_algs; }; +struct iwinfo_channel_info_entry { + /** + * sec_channel_offset - Secondary channel offset for HT40 + * + * 0 = HT40 disabled, + * -1 = HT40 enabled, secondary channel below primary, + * 1 = HT40 enabled, secondary channel above primary + */ + int8_t sec_channel_offset; + /** + * Center channel for VHT80 + */ + uint8_t center_idx0; + /** + * Center channel for VHT160 + */ + uint8_t center_idx1; +}; struct iwinfo_scanlist_entry { uint8_t mac[6]; @@ -156,6 +174,7 @@ struct iwinfo_scanlist_entry { uint8_t quality_max; uint16_t htmodelist; struct iwinfo_crypto_entry crypto; + struct iwinfo_channel_info_entry channel_info; }; struct iwinfo_country_entry { diff --git a/iwinfo_cli.c b/iwinfo_cli.c index 0429fbc..7f897c1 100644 --- a/iwinfo_cli.c +++ b/iwinfo_cli.c @@ -612,6 +612,16 @@ static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname) if (e->htmodelist & (1 << h)) printf("%s ", IWINFO_HTMODE_NAMES[h]); printf("\n"); + if (e->channel_info.sec_channel_offset) + printf(" HT secondary channel is %s\n", + e->channel_info.sec_channel_offset < 0 ? "below" : + "above"); + if (e->channel_info.center_idx0) + printf(" VHT Center IDX0: %hhu\n", + e->channel_info.center_idx0); + if (e->channel_info.center_idx1) + printf(" VHT Center IDX1: %hhu\n", + e->channel_info.center_idx1); } printf("\n"); } diff --git a/iwinfo_lua.c b/iwinfo_lua.c index 303fd08..9f95017 100644 --- a/iwinfo_lua.c +++ b/iwinfo_lua.c @@ -444,6 +444,17 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int lua_setfield(L, -2, "htmodelist"); } + lua_pushinteger(L, e->channel_info.sec_channel_offset); + lua_setfield(L, -2, "sec_channel_offset"); + if (e->channel_info.center_idx0) { + lua_pushinteger(L, e->channel_info.center_idx0); + lua_setfield(L, -2, "center_idx0"); + } + if (e->channel_info.center_idx1) { + lua_pushinteger(L, e->channel_info.center_idx1); + lua_setfield(L, -2, "center_idx1"); + } + lua_rawseti(L, -2, x); } } diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 542ac7d..fb137b2 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1996,6 +1996,27 @@ static void nl80211_parse_ht_capa(struct iwinfo_scanlist_entry *e, e->htmodelist |= IWINFO_HTMODE_VHT40; } } +static void nl80211_parse_ht_oper(struct iwinfo_scanlist_entry *e, + unsigned char *ie, + int len) +{ + uint8_t oper_info; + + if (len < 6) + return; + oper_info = ie[1]; + switch (oper_info & 3) { + case 0: + e->channel_info.sec_channel_offset = 0; + break; + case 1: + e->channel_info.sec_channel_offset = 1; + break; + case 3: + e->channel_info.sec_channel_offset = -1; + break; + } +} static void nl80211_parse_vht_capa(struct iwinfo_scanlist_entry *e, unsigned char *ie, int len) @@ -2024,7 +2045,7 @@ static void nl80211_parse_vht_oper(struct iwinfo_scanlist_entry *e, int len) { int chanwidth; - if (len < 1) + if (len < 3) return; chanwidth = ie[0]; @@ -2036,6 +2057,7 @@ static void nl80211_parse_vht_oper(struct iwinfo_scanlist_entry *e, /*case 0: 20 or 40 MHz */ case 1: e->htmodelist |= IWINFO_HTMODE_VHT80; + e->channel_info.center_idx0 = ie[1]; break; case 2: e->htmodelist |= IWINFO_HTMODE_VHT160; @@ -2044,10 +2066,12 @@ static void nl80211_parse_vht_oper(struct iwinfo_scanlist_entry *e, e->htmodelist |= IWINFO_HTMODE_VHT80_80; break; } + e->channel_info.center_idx0 = ie[1]; + e->channel_info.center_idx1 = ie[2]; } static void nl80211_get_scanlist_ie(struct nlattr **bss, - struct iwinfo_scanlist_entry *e) + struct iwinfo_scanlist_entry *e) { int ielen = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); unsigned char *ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); @@ -2073,6 +2097,10 @@ static void nl80211_get_scanlist_ie(struct nlattr **bss, IWINFO_CIPHER_CCMP, IWINFO_KMGMT_8021x); break; + case 61: /* HT Operation */ + nl80211_parse_ht_oper(e, ie + 2, ie[1]); + break; + case 191: /* VHT Capabilities */ nl80211_parse_vht_capa(e, ie + 2, ie[1]); break;