From patchwork Wed Apr 24 19:03:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 1090334 X-Patchwork-Delegate: mschiffer@universe-factory.net 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=universe-factory.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FHDpyecv"; 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 44q8ql71fbz9s3q for ; Thu, 25 Apr 2019 05:04:03 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version: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=T33A+FY98kjkbKymehKJkSC/pXsZRb0PesP2Bk7nU/c=; b=FHDpyecv2pxwUS x70WgEEQPGZRlo3v9N6wL1ctv1c67WZvEveFDGRHkNVMhkDom/Zy1p6iCwxM78NrkVfJzKygbQXis Zdt6OTMG6yt7B+Pao0mKPyv1EnY7xXE7mms77Vaj5R6ieug7NufnR2Ufl7ART+FvlU/5jvQWSioqI s708geXBMHzqRey5w2uOUs6qea52uSTkhZDfSmwa29azJ8mQXOZYQgpe+wequKzdc3DMQWxLat5Po GhIm9/ASqjXhhQ9Lb8GLJ+OEn7Ezykaw7Wwu5wjPovGzbWPduCvSMjokuidV1w1RU6nUO1T6Hw8el xG9GSw2tPMvnWxruFAFA==; 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 1hJNBK-0004kt-KJ; Wed, 24 Apr 2019 19:03:46 +0000 Received: from orthanc.universe-factory.net ([2001:19f0:6c01:100::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJNBH-0004kA-AL for openwrt-devel@lists.openwrt.org; Wed, 24 Apr 2019 19:03:45 +0000 Received: from localhost.localdomain (unknown [IPv6:2001:19f0:6c01:100::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by orthanc.universe-factory.net (Postfix) with ESMTPSA id 7750D1F41B; Wed, 24 Apr 2019 21:03:39 +0200 (CEST) From: Matthias Schiffer To: openwrt-devel@lists.openwrt.org, jo@mein.io Date: Wed, 24 Apr 2019 21:03:18 +0200 Message-Id: <8dbf417fb12e814f32bac58bf0b0bb1a6246f4e4.1556132277.git.mschiffer@universe-factory.net> X-Mailer: git-send-email 2.21.0 In-Reply-To: <72d19000530fe2b51b5a59c8ccda4d6c51c3f8ba.1556132277.git.mschiffer@universe-factory.net> References: <72d19000530fe2b51b5a59c8ccda4d6c51c3f8ba.1556132277.git.mschiffer@universe-factory.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190424_120343_726242_A196E9E3 X-CRM114-Status: GOOD ( 11.44 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record Subject: [OpenWrt-Devel] [PATCH iwinfo 2/2] Add Lua support for regrulelist 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: Matthias Schiffer Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Example output: # lua -e 'print(require("jsonc").stringify(require("iwinfo").nl80211.regrulelist(), true))' [ { "flags": [ ], "max_ant_gain_mbi": 0, "end_freq_khz": 2483500, "max_eirp_mbm": 2000, "start_freq_khz": 2400000, "max_bw_khz": 40000 }, { "flags": { "auto_bw": true, "no_outdoor": true }, "max_ant_gain_mbi": 0, "end_freq_khz": 5250000, "max_eirp_mbm": 2000, "start_freq_khz": 5150000, "max_bw_khz": 80000 }, ... ] We only add flags that are set to the "flags" field to avoid bloating the output with a large number of entries for unset flags. Signed-off-by: Matthias Schiffer --- iwinfo_lua.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/iwinfo_lua.c b/iwinfo_lua.c index bb43438d8dd5..e91b9fc81455 100644 --- a/iwinfo_lua.c +++ b/iwinfo_lua.c @@ -477,6 +477,82 @@ static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int return 1; } +/* Wrapper for regulatory rules */ +static int iwinfo_L_regrulelist(lua_State *L, int (*func)(const char *, char *, int *)) +{ + int i, x, len; + char rv[IWINFO_BUFSIZE]; + const char *ifname = luaL_optstring(L, 1, NULL); + struct iwinfo_regrule_entry *e; + + lua_newtable(L); + memset(rv, 0, sizeof(rv)); + + if (!(*func)(ifname, rv, &len)) + { + for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_regrule_entry), x++) + { + e = (struct iwinfo_regrule_entry *) &rv[i]; + + lua_newtable(L); + + lua_pushinteger(L, e->start_freq_khz); + lua_setfield(L, -2, "start_freq_khz"); + + lua_pushinteger(L, e->end_freq_khz); + lua_setfield(L, -2, "end_freq_khz"); + + lua_pushinteger(L, e->max_bw_khz); + lua_setfield(L, -2, "max_bw_khz"); + + lua_pushinteger(L, e->max_ant_gain_mbi); + lua_setfield(L, -2, "max_ant_gain_mbi"); + + lua_pushinteger(L, e->max_eirp_mbm); + lua_setfield(L, -2, "max_eirp_mbm"); + + if (e->flags & IWINFO_REGRULE_DFS) { + lua_pushinteger(L, e->dfs_cac_time_ms); + lua_setfield(L, -2, "dfs_cac_time_ms"); + } + + lua_newtable(L); + +#define HANDLE_FLAG(flag, strflag) \ + do { \ + if (e->flags & IWINFO_REGRULE_##flag) { \ + lua_pushboolean(L, true); \ + lua_setfield(L, -2, strflag); \ + } \ + } while (0) + + HANDLE_FLAG(NO_OFDM, "no_ofdm"); + HANDLE_FLAG(NO_CCK, "no_cck"); + HANDLE_FLAG(NO_INDOOR, "no_indoor"); + HANDLE_FLAG(NO_OUTDOOR, "no_outdoor"); + HANDLE_FLAG(DFS, "dfs"); + HANDLE_FLAG(PTP_ONLY, "ptp_only"); + HANDLE_FLAG(AUTO_BW, "auto_bw"); + HANDLE_FLAG(IR_CONCURRENT, "ir_concurrent"); + HANDLE_FLAG(NO_HT40MINUS, "no_ht40minus"); + HANDLE_FLAG(NO_HT40PLUS, "no_ht40plus"); + HANDLE_FLAG(NO_80MHZ, "no_80mhz"); + HANDLE_FLAG(NO_160MHZ, "no_160mhz"); + HANDLE_FLAG(NO_IR, "no_ir"); + HANDLE_FLAG(PASSIVE_SCAN, "passive_scan"); + HANDLE_FLAG(NO_IBSS, "no_ibss"); + +#undef HANDLE_FLAG + + lua_setfield(L, -2, "flags"); + + lua_rawseti(L, -2, x); + } + } + + return 1; +} + /* Wrapper for crypto settings */ static int iwinfo_L_encryption(lua_State *L, int (*func)(const char *, char *)) { @@ -739,6 +815,7 @@ LUA_WRAP_STRUCT_OP(nl80211,freqlist) LUA_WRAP_STRUCT_OP(nl80211,countrylist) LUA_WRAP_STRUCT_OP(nl80211,hwmodelist) LUA_WRAP_STRUCT_OP(nl80211,htmodelist) +LUA_WRAP_STRUCT_OP(nl80211,regrulelist) LUA_WRAP_STRUCT_OP(nl80211,encryption) LUA_WRAP_STRUCT_OP(nl80211,mbssid_support) LUA_WRAP_STRUCT_OP(nl80211,hardware_id) @@ -862,6 +939,7 @@ static const luaL_reg R_nl80211[] = { LUA_REG(nl80211,countrylist), LUA_REG(nl80211,hwmodelist), LUA_REG(nl80211,htmodelist), + LUA_REG(nl80211,regrulelist), LUA_REG(nl80211,encryption), LUA_REG(nl80211,mbssid_support), LUA_REG(nl80211,hardware_id),