From patchwork Sun Sep 27 18:07:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 523163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 90AD41401CD for ; Mon, 28 Sep 2015 04:08:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=vpgUFn1G; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 81A922848DA; Sun, 27 Sep 2015 20:06:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 16EDF2845EA for ; Sun, 27 Sep 2015 20:06:24 +0200 (CEST) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 27 Sep 2015 20:06:19 +0200 (CEST) Received: by wiclk2 with SMTP id lk2so74450521wic.1 for ; Sun, 27 Sep 2015 11:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=QG/1OFPc3oeTf9SXOcMOKOVSf0YoiyKoO4kgiTodU/g=; b=vpgUFn1GxgvGl9VtPqS8OrhzZP7CnjjfYPLak9rfJK6SWrdvB5u5fsRfxcXn48DYSV rJgHiG7BxgAuFNhul+2LIMobMixQZ+0SK9a+aTkIYb+3ZwgrYkS+q0iuZZDgf0h6Neg4 oKsGWKdqrYay5eYKnZQr/DofGeHLJsiiCTGbOMVbasTj3ZR3QCvq8F9ZrAAUrY6cgyS5 VE4KXXmRook8uaVdTBnYuWatfDbdu1CM1+G+8jlNQtZDoEgZImljWNi8GfEeJJ4dL0nW oMDi91Dkwn5nIb+3npFRSejbzl2fBXMVQ5+kWR4OzyyJ56d+Syck+KjycFE9xzdOobWl /ctA== X-Received: by 10.194.79.196 with SMTP id l4mr19146210wjx.93.1443377258890; Sun, 27 Sep 2015 11:07:38 -0700 (PDT) Received: from linux-tdhb.lan (das130.neoplus.adsl.tpnet.pl. [83.23.18.130]) by smtp.gmail.com with ESMTPSA id bu19sm14156857wjb.45.2015.09.27.11.07.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Sep 2015 11:07:36 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: openwrt-devel@lists.openwrt.org, Jo-Philipp Wich Date: Sun, 27 Sep 2015 20:07:22 +0200 Message-Id: <1443377242-18087-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH][iwinfo] nl80211: read TX power using NL80211_CMD_GET_INTERFACE X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" With the mac80211 commit d55d0d598e66 ("nl80211: put current TX power in interface info") it is possible now to get TX power using nl80211. Signed-off-by: Rafał Miłecki --- include/iwinfo/utils.h | 4 ++++ iwinfo_nl80211.c | 29 +++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/iwinfo/utils.h b/include/iwinfo/utils.h index 95f9238..b5c42a2 100644 --- a/include/iwinfo/utils.h +++ b/include/iwinfo/utils.h @@ -37,6 +37,10 @@ int iwinfo_ioctl(int cmd, void *ifr); int iwinfo_dbm2mw(int in); int iwinfo_mw2dbm(int in); +inline int iwinfo_mbm2dbm(int gain) +{ + return gain / 100; +} int iwinfo_ifup(const char *ifname); int iwinfo_ifdown(const char *ifname); diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 7aaae6b..ef1465d 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1188,20 +1188,33 @@ static int nl80211_get_channel(const char *ifname, int *buf) return -1; } +static int nl80211_get_txpower_cb(struct nl_msg *msg, void *arg) +{ + int *buf = arg; + struct nlattr **tb = nl80211_parse(msg); + + if (tb[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]) + *buf = iwinfo_mbm2dbm(nla_get_u32(tb[NL80211_ATTR_WIPHY_TX_POWER_LEVEL])); + + return NL_SKIP; +} static int nl80211_get_txpower(const char *ifname, int *buf) { -#if 0 char *res; - char path[PATH_MAX]; + struct nl80211_msg_conveyor *req; - res = nl80211_ifname2phy(ifname); - snprintf(path, sizeof(path), "/sys/kernel/debug/ieee80211/%s/power", - res ? res : ifname); + res = nl80211_phy2ifname(ifname); + req = nl80211_msg(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0); - if ((*buf = nl80211_readint(path)) > -1) - return 0; -#endif + if (req) + { + *buf = 0; + nl80211_send(req, nl80211_get_txpower_cb, buf); + nl80211_free(req); + if (*buf) + return 0; + } return wext_ops.txpower(ifname, buf); }