1

The devices listed by the rfkill command are completely different from the device names listed by the ip command:

> rfkill
ID TYPE DEVICE              SOFT      HARD
 0 wwan tpacpi_wwan_sw unblocked   blocked
 1 wlan phy0           unblocked   blocked
 8 wlan phy7           unblocked unblocked

> ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether 1d:28:4c:95:e6:9b brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 22:5e:9b:23:24:86 brd ff:ff:ff:ff:ff:ff
25: wwp0s20u4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 2e:e1:3b:d9:bc:b2 brd ff:ff:ff:ff:ff:ff
26: wlxda2487111f99: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether da:24:87:11:1f:99 brd ff:ff:ff:ff:ff:ff

Why is this, and how do I work out how they match up?

I read this post explaining how the device names used ip are assigned: Why is my ethernet interface called enp0s10 instead of eth0? but how are the device names used by rfkill assigned?

2

Wireless comes in two aspects:

  • the wireless hardware device phy, usually named phyX.
  • its associated network interface(s) dev usually named wlanY.

For a given wireless hardware device phyX, it's even possible to create additional network interfaces associated to it, when it has the capabilities to do so. That's how it's possible for example to use the same card (when it has the capability) to be both a client and an access point at the same time. And that's probably why there's an additional layer. This lower layer is all managed with the iw command rather than the ip link command which controls only the final network interface.

Separately from this, the system can choose to rename (from wlanY) the network interface according to the so-called Consistent network interface device naming or also called Predictable Network Interface Names. This is an unrelated topic, since it won't help any better to guess the association between phyX (which is typically dynamic) and whatever name.

iw's man page is almost empty, but the command has still a (very) large help page.

# iw help | less

[...]
        dev
                List all network interfaces for wireless hardware.

        dev <devname> info
                Show information for this interface.
[...]

For a given network interface wlanY, using iw dev wlanY info will display in its results an entry called wiphy and an index. That's the index X of the matching phy interface. So you can get the wlanY -> phyX relation.

Example:

# iw dev wlan1 info
Interface wlan1
    ifindex 45
    wdev 0x300000001
    addr 16:c3:0c:a5:63:62
    type managed
    wiphy 3
    txpower 0.00 dBm

Or you can get the list of hardware devices sorted per phyX (displayed phy#X) with their matching network interfaces. Eg:

# iw dev
phy#4
    Interface wlan2
        ifindex 46
        wdev 0x500000001
        addr 2a:5f:7f:7a:30:1b
        type managed
        txpower 0.00 dBm
phy#3
    Interface wlan1
        ifindex 45
        wdev 0x300000001
        addr 16:c3:0c:a5:63:62
        type managed
        txpower 0.00 dBm
phy#0
    Interface wlan0
        ifindex 3
        wdev 0x1
        addr be:2d:23:03:29:c5
        type managed
        txpower 0.00 dBm

And rfkill displays the relation between rfkillZ and phyX (beside LTE modem and bluetooth).

# rfkill -o ID,TYPE,DEVICE,SOFT,HARD list
ID TYPE      DEVICE      SOFT      HARD
 0 wlan      phy0   unblocked unblocked
 4 wlan      phy3   unblocked unblocked
 5 wlan      phy4   unblocked unblocked
 9 bluetooth hci0     blocked unblocked

By navigating through symlinks and reading contents available in /sys/class/ the information is also available, in more than one possible way:

from wlan to phy to rfkill:

$ ls -l /sys/class/net/wlan1/phy80211
lrwxrwxrwx. 1 root root 0 Sep  1 20:58 /sys/class/net/wlan1/phy80211 -> ../../ieee80211/phy3
$ grep ^ /sys/class/net/*/phy80211/name 
/sys/class/net/wlan0/phy80211/name:phy0
/sys/class/net/wlan1/phy80211/name:phy3
/sys/class/net/wlan2/phy80211/name:phy4

$ ls -1d /sys/class/net/*/phy80211/rfkill*
/sys/class/net/wlan0/phy80211/rfkill0
/sys/class/net/wlan1/phy80211/rfkill4
/sys/class/net/wlan2/phy80211/rfkill5

from rfkill to phy to wlan:

$ ls -l /sys/class/rfkill/rfkill4/device
lrwxrwxrwx. 1 root root 0 Sep  1 21:05 /sys/class/rfkill/rfkill4/device -> ../../phy3
$ grep ^ /sys/class/rfkill/rfkill*/device/name
/sys/class/rfkill/rfkill0/device/name:phy0
/sys/class/rfkill/rfkill4/device/name:phy3
/sys/class/rfkill/rfkill5/device/name:phy4
$ ls -1d /sys/class/rfkill/rfkill*/device/device/ieee80211/*
/sys/class/rfkill/rfkill0/device/device/ieee80211/phy0
/sys/class/rfkill/rfkill4/device/device/ieee80211/phy3
/sys/class/rfkill/rfkill5/device/device/ieee80211/phy4

(the bluetooth device above has a different layout and is thus not displayed like this)

ls -1d /sys/class/rfkill/rfkill*/device/device/net/* 
/sys/class/rfkill/rfkill0/device/device/net/wlan0
/sys/class/rfkill/rfkill4/device/device/net/wlan1
/sys/class/rfkill/rfkill5/device/device/net/wlan2

# iw phy phy4 interface add onemorewlan type managed addr 12:34:56:78:ab:cd

$ ls -1d /sys/class/ieee80211/phy*/device/net/*
/sys/class/ieee80211/phy0/device/net/wlan0
/sys/class/ieee80211/phy3/device/net/wlan1
/sys/class/ieee80211/phy4/device/net/onemorewlan
/sys/class/ieee80211/phy4/device/net/wlan2

You get the idea.

3
  • OK, so there's actually at least 3 different devices associated with each wifi adapter: the physical device, the interface device(s), and the rfkill device. Is this correct? – Ben Sep 2 '20 at 14:25
  • Ah.. OK after a bit of googling what I surmise is that there is just one rfkill device (/dev/rfkill) which is used for interacting with the rfkill subsystem which assigns an ID (not a device per say) to each physical device. Not sure why rfkill uses a different number to the physical device number though. – Ben Sep 2 '20 at 14:43
  • 1
    rfkill handles wwan, wireless and bluetooth. There's no way it can keep the same numbering then if each of them also have their own numbering scheme. – A.B Sep 2 '20 at 14:48

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.