From patchwork Mon Jul 16 07:48:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Shvedov X-Patchwork-Id: 944171 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="a5SnCdm6"; 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 41TbD02XWDz9sNL for ; Mon, 16 Jul 2018 17:49:52 +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=rgswE2HLsE+qATfBhlJ8BqsZZWClaP464xqTBerpFVQ=; b=a5SnCdm6064ROp zGpLSNcNUAd0WV+OVMwFtiZoTkJ8mn775D/5HpvXEXV2iaV3ToXd8HBoo0vAkLJM3scVjJ9Xj3lIY +6yT9oW8/nqBRW67S3UHNqhxPUXZZShCD9ediEjmJwoMRe5ljTbKupNQduO339A5n5h6JNCQyZell 9pdgKPEmQVvHLUIgICQmVkMzAIzuclX2ny+SZT2dTf4Q0d/Pw8TPEtulTDh8ghR9L0+/818aSniUc Pf/U1LbG8qqA63Om+2eMpCEwyukxcsDZ/R8jp6z5elp/PhrRQI207TNXvlKeB0xAk/LIqgCmkIMLU cqgIuFLudUtodZ++ON/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 1feyGG-0001x6-1I; Mon, 16 Jul 2018 07:49:36 +0000 Received: from forward100o.mail.yandex.net ([2a02:6b8:0:1a2d::600]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1feyG0-0001vS-3k for openwrt-devel@lists.openwrt.org; Mon, 16 Jul 2018 07:49:22 +0000 Received: from mxback10o.mail.yandex.net (mxback10o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::24]) by forward100o.mail.yandex.net (Yandex) with ESMTP id 135CC2A24B87; Mon, 16 Jul 2018 10:48:56 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback10o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id x7stUKZmBp-mtIqUSMC; Mon, 16 Jul 2018 10:48:56 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id OV1ZZInQf0-mslSsnSV; Mon, 16 Jul 2018 10:48:54 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Yury Shvedov To: Jo-Philipp Wich Date: Mon, 16 Jul 2018 10:48:54 +0300 Message-Id: <20180716074854.11321-1-yshvedov@wimarksystems.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <03716f5d-e5d5-7c5d-c39a-bf1920f19671@mein.io> References: <03716f5d-e5d5-7c5d-c39a-bf1920f19671@mein.io> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180716_004920_511839_E29ABAD3 X-CRM114-Status: GOOD ( 12.71 ) 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 [2a02:6b8:0:1a2d:0:0:0:600 listed in] [list.dnswl.org] Subject: [OpenWrt-Devel] [PATCH 1/2] add htmodelist 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 MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The knowledge about HT and VHT modes could be useful for user experience. So grab it via nl80211 and make it available in both C and LUA APIs, and show htmodelist on CLI scan results. Signed-off-by: Yury Shvedov --- include/iwinfo.h | 1 + iwinfo_cli.c | 13 ++++++-- iwinfo_lua.c | 14 ++++++++- iwinfo_nl80211.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) diff --git a/include/iwinfo.h b/include/iwinfo.h index 929f697..b3f5470 100644 --- a/include/iwinfo.h +++ b/include/iwinfo.h @@ -154,6 +154,7 @@ struct iwinfo_scanlist_entry { uint8_t signal; uint8_t quality; uint8_t quality_max; + uint16_t htmodelist; struct iwinfo_crypto_entry crypto; }; diff --git a/iwinfo_cli.c b/iwinfo_cli.c index 49c9035..0429fbc 100644 --- a/iwinfo_cli.c +++ b/iwinfo_cli.c @@ -572,7 +572,7 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname) static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname) { - int i, x, len; + int i, h, x, len; char buf[IWINFO_BUFSIZE]; struct iwinfo_scanlist_entry *e; @@ -603,8 +603,17 @@ static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname) format_signal(e->signal - 0x100), format_quality(e->quality), format_quality_max(e->quality_max)); - printf(" Encryption: %s\n\n", + printf(" Encryption: %s\n", format_encryption(&e->crypto)); + if (e->htmodelist) + { + printf(" HT Capabilities: "); + for (h = 0; h < ARRAY_SIZE(IWINFO_HTMODE_NAMES); h++) + if (e->htmodelist & (1 << h)) + printf("%s ", IWINFO_HTMODE_NAMES[h]); + printf("\n"); + } + printf("\n"); } } diff --git a/iwinfo_lua.c b/iwinfo_lua.c index eebab8e..303fd08 100644 --- a/iwinfo_lua.c +++ b/iwinfo_lua.c @@ -378,7 +378,7 @@ static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, in /* Wrapper for scan list */ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int *)) { - int i, x, len = 0; + int i, x, h, len = 0; char rv[IWINFO_BUFSIZE]; char macstr[18]; const char *ifname = luaL_checkstring(L, 1); @@ -432,6 +432,18 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int iwinfo_L_cryptotable(L, &e->crypto); lua_setfield(L, -2, "encryption"); + /* HT Modes */ + if (e->htmodelist) + { + lua_newtable(L); + for (h = 0; h < ARRAY_SIZE(IWINFO_HTMODE_NAMES); h++) + { + lua_pushboolean(L, e->htmodelist & (1 << h)); + lua_setfield(L, -2, IWINFO_HTMODE_NAMES[h]); + } + lua_setfield(L, -2, "htmodelist"); + } + lua_rawseti(L, -2, x); } } diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index ecd2d6a..542ac7d 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1980,6 +1980,71 @@ struct nl80211_scanlist { int len; }; +static void nl80211_parse_ht_capa(struct iwinfo_scanlist_entry *e, + unsigned char *ie, + int len) +{ + int capa; + if (len < 2) + return; + e->htmodelist |= IWINFO_HTMODE_HT20; + capa = ie[0] | (ie[8] << 8); + if (capa & (1 << 1)) + { + e->htmodelist |= IWINFO_HTMODE_HT40; + if (e->htmodelist & IWINFO_HTMODE_VHT20) + e->htmodelist |= IWINFO_HTMODE_VHT40; + } +} +static void nl80211_parse_vht_capa(struct iwinfo_scanlist_entry *e, + unsigned char *ie, + int len) +{ + int capa; + if (len < 4) + return; + capa = ie[0] | (ie[1] << 8) | (ie[2] << 16) | (ie[3] << 24); + + e->htmodelist |= IWINFO_HTMODE_VHT20; + if (e->htmodelist & IWINFO_HTMODE_HT40) + e->htmodelist |= IWINFO_HTMODE_VHT40; + + switch ((capa >> 2) & 3) { + /*case 0: neither 160 nor 80+80 */ + case 1: + e->htmodelist |= IWINFO_HTMODE_VHT160; + break; + case 2: + e->htmodelist |= IWINFO_HTMODE_VHT80_80; + break; + } +} +static void nl80211_parse_vht_oper(struct iwinfo_scanlist_entry *e, + unsigned char *ie, + int len) +{ + int chanwidth; + if (len < 1) + return; + chanwidth = ie[0]; + + e->htmodelist |= IWINFO_HTMODE_VHT20; + if (e->htmodelist & IWINFO_HTMODE_HT40) + e->htmodelist |= IWINFO_HTMODE_VHT40; + + switch (chanwidth) { + /*case 0: 20 or 40 MHz */ + case 1: + e->htmodelist |= IWINFO_HTMODE_VHT80; + break; + case 2: + e->htmodelist |= IWINFO_HTMODE_VHT160; + break; + case 3: + e->htmodelist |= IWINFO_HTMODE_VHT80_80; + break; + } +} static void nl80211_get_scanlist_ie(struct nlattr **bss, struct iwinfo_scanlist_entry *e) @@ -1999,11 +2064,23 @@ static void nl80211_get_scanlist_ie(struct nlattr **bss, e->ssid[len] = 0; break; + case 45: /* HT Capabilities */ + nl80211_parse_ht_capa(e, ie + 2, ie[1]); + break; + case 48: /* RSN */ iwinfo_parse_rsn(&e->crypto, ie + 2, ie[1], IWINFO_CIPHER_CCMP, IWINFO_KMGMT_8021x); break; + case 191: /* VHT Capabilities */ + nl80211_parse_vht_capa(e, ie + 2, ie[1]); + break; + + case 192: /* VHT Operation */ + nl80211_parse_vht_oper(e, ie + 2, ie[1]); + break; + case 221: /* Vendor */ if (ie[1] >= 4 && !memcmp(ie + 2, ms_oui, 3) && ie[5] == 1) iwinfo_parse_rsn(&e->crypto, ie + 6, ie[1] - 4, From patchwork Mon Jul 16 07:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Shvedov X-Patchwork-Id: 944173 X-Patchwork-Delegate: jow@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=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="OKXf+Uul"; 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 41TbDK1yzTz9s9N for ; Mon, 16 Jul 2018 17:50:09 +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=qEajsYN1yrP78Xqx0Z7vwhNM3yvzyDsOIAsvkBhSZGo=; b=OKXf+UulGd6KEu IPyMzpkNkFTzkio7l7LEjhuAgjYvbZ84mOaPXdbh72M78IvIvTI+3uIkfNci7f3p0J3GYkATxm/Zx zTRX+R0iqDG5BmZJpiPMew2dQm9ScZap6x+oFVpgrZk/oQhQHWvf9rNCNyso+T5W6ffU99K9hUFBP MSzczYxnox0apIqyNxS8/i64vOKOLH1tfvkKizsRDVM/g63Tx3irhm+NPUjXinIj+MuK1o2MvQsmh 6sruHVwwTaQQeRyl8PYNaQKSefs3lj+KHJvl0xK/AGH2PEcS9OkPN6iqOmfo25eybHEFqxgXdjBOw cwkXGqrNpsNNHryxRz8g==; 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 1feyGi-0002e9-A4; Mon, 16 Jul 2018 07:50:04 +0000 Received: from forward101o.mail.yandex.net ([2a02:6b8:0:1a2d::601]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1feyGe-000291-DO for openwrt-devel@lists.openwrt.org; Mon, 16 Jul 2018 07:50:02 +0000 Received: from mxback15j.mail.yandex.net (mxback15j.mail.yandex.net [IPv6:2a02:6b8:0:1619::91]) by forward101o.mail.yandex.net (Yandex) with ESMTP id 682D0134185B; Mon, 16 Jul 2018 10:49:47 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback15j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id I9SqaT1nJB-nkEi5fmV; Mon, 16 Jul 2018 10:49:47 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id MaNelUIhhy-njKmtCdH; Mon, 16 Jul 2018 10:49:45 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Yury Shvedov To: Jo-Philipp Wich Date: Mon, 16 Jul 2018 10:49:45 +0300 Message-Id: <20180716074945.11422-1-yshvedov@wimarksystems.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <118c587f-ed00-a593-f892-d947b8384ebd@mein.io> References: <118c587f-ed00-a593-f892-d947b8384ebd@mein.io> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180716_005000_825291_FA669B06 X-CRM114-Status: GOOD ( 11.42 ) 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 [2a02:6b8:0:1a2d:0:0:0:601 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 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 --- 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..7bd2da2 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: %d\n", + e->channel_info.center_idx0); + if (e->channel_info.center_idx1) + printf(" VHT Center IDX1: %d\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;