diff mbox

[OpenWrt-Devel,iwinfo] nl80211: read TX power using NL80211_CMD_GET_INTERFACE

Message ID 1443377242-18087-1-git-send-email-zajec5@gmail.com
State Changes Requested
Headers show

Commit Message

Rafał Miłecki Sept. 27, 2015, 6:07 p.m. UTC
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 <zajec5@gmail.com>
---
 include/iwinfo/utils.h |  4 ++++
 iwinfo_nl80211.c       | 29 +++++++++++++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)

Comments

Felix Fietkau Sept. 27, 2015, 7:07 p.m. UTC | #1
On 2015-09-27 20:07, Rafał Miłecki wrote:
> With the mac80211 commit d55d0d598e66 ("nl80211: put current TX power in
> interface info") it is possible now to get TX power using nl80211.
We should pull that commit into OpenWrt before applying this patch.

> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
> ---
>  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)
Should be static inline.

- Felix
Rafał Miłecki Sept. 27, 2015, 8:37 p.m. UTC | #2
On 27 September 2015 at 21:07, Felix Fietkau <nbd@openwrt.org> wrote:
> On 2015-09-27 20:07, Rafał Miłecki wrote:
>> With the mac80211 commit d55d0d598e66 ("nl80211: put current TX power in
>> interface info") it is possible now to get TX power using nl80211.
> We should pull that commit into OpenWrt before applying this patch.

I did that obviously:
http://git.openwrt.org/?p=openwrt.git;a=commit;h=07efcbd1ec2858f55e9927b98578a3bc06e6f796
http://dev.openwrt.org/changeset/47059


>> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
>> ---
>>  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)
> Should be static inline.

I'll send V2.
diff mbox

Patch

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);
 }