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;