Search Linux Wireless

[PATCH] wireless: sysfs was displaying different values for level and noise than procfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Subject: [PATCH] wireless: sysfs was displaying different values for level and noise than procfs
From: Andrey Borzenkov <arvidjaar@xxxxxxx>

/proc/net/wireless asjusts display of signal and noise level depending on
whether units are percentage or dBm. Use the same format in sysfs. This
makes it easy to know unit - below zero is dBm, above zero is percent.

Before:
{pts/1}% cat /sys/class/net/eth1/wireless/level
203
{pts/1}% cat /sys/class/net/eth1/wireless/noise
166

After:
{pts/1}% cat /sys/class/net/eth1/wireless/level
-48
{pts/1}% cat /sys/class/net/eth1/wireless/noise
-91

for the following iwconfig output:
eth1      IEEE 802.11b  ESSID:"Home, sweet home"  Nickname:"cooker"
	[...]
          Link Quality=54/92  Signal level=-48 dBm  Noise level=-91 dBm

Signed-off-by: Andrey Borzenkov <arvidjaar@xxxxxxx>

---

 net/core/net-sysfs.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)


diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 92d6b94..24c67bc 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -389,10 +389,23 @@ static ssize_t show_iw_##name(struct device *d,				\
 }									\
 static DEVICE_ATTR(name, S_IRUGO, show_iw_##name, NULL)
 
+#define WIRELESS_SHOW_LEVEL(name, field, format_string)			\
+static ssize_t format_iw_##name(const struct iw_statistics *iw, char *buf) \
+{									\
+	return sprintf(buf, format_string, (__s32)iw->field -		\
+			((iw->qual.updated & IW_QUAL_DBM) ? 0x100 : 0)); \
+}									\
+static ssize_t show_iw_##name(struct device *d,				\
+			      struct device_attribute *attr, char *buf)	\
+{									\
+	return wireless_show(d, buf, format_iw_##name);			\
+}									\
+static DEVICE_ATTR(name, S_IRUGO, show_iw_##name, NULL)
+
 WIRELESS_SHOW(status, status, fmt_hex);
 WIRELESS_SHOW(link, qual.qual, fmt_dec);
-WIRELESS_SHOW(level, qual.level, fmt_dec);
-WIRELESS_SHOW(noise, qual.noise, fmt_dec);
+WIRELESS_SHOW_LEVEL(level, qual.level, fmt_dec);
+WIRELESS_SHOW_LEVEL(noise, qual.noise, fmt_dec);
 WIRELESS_SHOW(nwid, discard.nwid, fmt_dec);
 WIRELESS_SHOW(crypt, discard.code, fmt_dec);
 WIRELESS_SHOW(fragment, discard.fragment, fmt_dec);

Attachment: signature.asc
Description: This is a digitally signed message part.


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux