5

While searching for ways to obtain various WiFi information, I found /sys/class/net/wlan7/speed file. Problem is, even though all read permissions are granted, I can't read it.

$ ls -l /sys/class/net/wlan7/speed                                                                                       
-r--r--r-- 1 root root 4096 3月  24 15:08 /sys/class/net/wlan7/speed

$ sudo cat /sys/class/net/wlan7/speed                                                                                    
[sudo] password for xieerqi: 
cat: /sys/class/net/wlan7/speed: Invalid argument

I can stat the file, I can list with ls, but every time I try to read it ( with hexdump, with cat, with Python in binary reading mode, etc. ) it shows invalid argument error.

strace shows that error apparently occurs at this point:

read(3, 0x7f6ad6b44000, 131072)         = -1 EINVAL (Invalid argument)
write(2, "cat: ", 5cat: )                    = 5
write(2, "/sys/class/net/wlan7/speed", 26/sys/class/net/wlan7/speed) = 26
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4

( link to full trace paste: http://paste.ubuntu.com/24252504/ )

By contrast , the corresponding file for the ethernet interface works:

$ cat /sys/class/net/eth3/speed                              
10

So basically my question is this: how do I read this file ?

OS: Ubuntu 16.04 LTS, kernel 4.4.0-67-generic , AR9565 WiFi adapter

6

The file /sys/class/net/<iface>/speed is only valid for devices that support ethtool get_settings method, which mostly applies to Ethernet adapters.

To get the speed of a WiFi device, you can use iwconfig or iwlist.

iwconfig wlan7
iwlist wlan7 rate

From the Kernel documentation:

What:       /sys/class/net/<iface>/speed
...  
Description:
        Indicates the interface latest or current speed value. Value is
        an integer representing the link speed in Mbits/sec.

        Note: this attribute is only valid for interfaces that implement
        the ethtool get_settings method (mostly Ethernet ).
  • 1
    One small request: can you provide the link to the kernel documentation from which the quote comes ? I would like to read more there – Sergiy Kolodyazhnyy Mar 26 '17 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.