OpenWrt Forum Archive

Topic: Confusing wifi interface name assignment (phy, radio, wlan)?

The content of this topic has been archived on 17 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I got a TP-Link WR710N router with USB interface, to which I connect a second wifi interface (USB dongle).

My issue is how to differentiate between the two interfaces, how to get the wlanX or phyX of the USB.

I have several devices and rebooted a few times, it seems the wlanX (0 or 1) is assigned rather randomly.


uci shows me which one is the USB wifi (path=platform/ehci-platform/usb1)

~# uci show wireless
wireless.radio0=wifi-device
wireless.radio0.type=mac80211
wireless.radio0.hwmode=11ng
wireless.radio0.path=platform/ar933x_wmac
wireless.radio0.ht_capab=SHORT-GI-20 SHORT-GI-40 RX-STBC1 DSSS_CCK-40
wireless.radio0.htmode=HT20
wireless.radio1=wifi-device
wireless.radio1.type=mac80211
wireless.radio1.channel=11
wireless.radio1.hwmode=11ng
wireless.radio1.path=platform/ehci-platform/usb1/1-1/1-1:1.0
wireless.radio1.ht_capab=GF SHORT-GI-20 SHORT-GI-40 RX-STBC1
wireless.radio1.htmode=HT20

wifi doesn't make clear by itself which one is internal and external, if wlanX is not up, it's name is not displayed

~# wifi status
{
    "radio0": {
        "up": true,
        "pending": false,
        "autostart": true,
        "disabled": false,
        "interfaces": [
            {
                "section": "cfg033579",
                "ifname": "wlan1"
            }
        ]
    },
    "radio1": {
        "up": true,
        "pending": false,
        "autostart": true,
        "disabled": false,
        "interfaces": [
            {
                "section": "cfg063579",
                "ifname": "wlan0"
            }
        ]
    }
}

iw gives no indication which one is USB

~# iw list
Wiphy phy1
    max # scan SSIDs: 4
    max scan IEs length: 2257 bytes
    Coverage class: 0 (up to 0m)
    ...
Wiphy phy0
    max # scan SSIDs: 4
    max scan IEs length: 2257 bytes
    Coverage class: 0 (up to 0m)
    ...

ifconfig has also no indication

~# ifconfig
wlan0     Link encap:Ethernet  HWaddr 7C:DD:90:11:22:33  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:9604 (9.3 KiB)

wlan1     Link encap:Ethernet  HWaddr 10:FE:ED:11:22:33  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:4575 (4.4 KiB)

What's the logic for the name assignments?

If I want to get the wlanX or phyX name of the USB interface, whats the best solution?

run
dmesg | grep "phy0"

or

"dmesg | grep "phy1"

this will help you to figure out which is which. phy0 is alias for radio0 in /etc/config/wireless, phy1 is radio1.

This does not seem to work as the dmesg lines do not contain the wlanX part:

root@openwrt:~# dmesg | grep "phy0" 
[   12.260000] ieee80211 phy0: rt2x00_set_rt: Info - RT chipset 5390, rev 0502 detected
[   12.290000] ieee80211 phy0: rt2x00_set_rf: Info - RF chipset 5370 detected
[   12.300000] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   82.310000] ieee80211 phy0: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'
[   82.320000] ieee80211 phy0: rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29
root@openwrt:~# dmesg | grep "phy1"
[   12.370000] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht'
[   12.380000] ieee80211 phy1: Atheros AR9330 Rev:1 mem=0xb8100000, irq=2
root@openwrt:~# dmesg | grep "phy" | grep "wlan"
root@openwrt:~# 

Maybe the /sys directory can bring you further. Try

ls -l /sys/class/net/

well commonly wlan0 is virtual interface that works on top of radio0, wlan1 - radio1, so looking at your dmesg I bet that your built-in wifi card is wlan1 and usb dongle is wlan0

(Last edited by valentin2208 on 27 Mar 2014, 12:08)

Well, even in Barrier Breaker (14.07, r42625) it is still the case that radioX may turn into wlanY.

root@tp710:/#   wifi status
{
        "radio0": {
                "up": true,
                "pending": false,
                "autostart": true,
                "disabled": false,
                "interfaces": [
                        {
                                "section": "cfg033579",
                                "ifname": "wlan1"
                        }
                ]
        },
        "radio1": {
                "up": true,
                "pending": false,
                "autostart": true,
                "disabled": false,
                "interfaces": [
                        {
                                "section": "cfg063579",
                                "ifname": "wlan0"
                        }
                ]
        }
}

The issue is that if I unplug the external USB radio1, that suddenly internal radio0 will change from wlan1 to wlan0 after reboot.

I would be great to have an option to assign a radioX to a fixed wlanX name. Or it should always have the same number.

bluepuma wrote:

I got a TP-Link WR710N router with USB interface, to which I connect a second wifi interface (USB dongle).

My issue is how to differentiate between the two interfaces, how to get the wlanX or phyX of the USB.

I have several devices and rebooted a few times, it seems the wlanX (0 or 1) is assigned rather randomly.

[...]

If I want to get the wlanX or phyX name of the USB interface, whats the best solution?

As I said earlier:

tmo26 wrote:

Maybe the /sys directory can bring you further. Try

ls -l /sys/class/net/

Only now I had the chance to test this (2 wifi adapters arrived today).

My findings:

root@DIR-505-2:~# ls -l /sys/class/net/
lrwxrwxrwx    1 root     root             0 Jan  7 21:13 br-lan -> ../../devices/virtual/net/br-lan
lrwxrwxrwx    1 root     root             0 Jan  1  1970 eth0 -> ../../devices/platform/ag71xx.1/net/eth0
lrwxrwxrwx    1 root     root             0 Jan  1  1970 eth1 -> ../../devices/platform/ag71xx.0/net/eth1
lrwxrwxrwx    1 root     root             0 Jan  1  1970 lo -> ../../devices/virtual/net/lo
lrwxrwxrwx    1 root     root             0 Jan  7 21:18 wlan0 -> ../../devices/platform/ehci-platform/usb1/1-1/1-1.4/1-1.4:1.0/net/wlan0
lrwxrwxrwx    1 root     root             0 Jan  7 21:22 wlan1 -> ../../devices/platform/ehci-platform/usb1/1-1/1-1.3/1-1.3:1.0/net/wlan1
lrwxrwxrwx    1 root     root             0 Jan  7 21:13 wlan2 -> ../../devices/platform/ar933x_wmac/net/wlan2
root@DIR-505-2:~# ls -l /sys/class/net/wlan0/
-r--r--r--    1 root     root          4096 Jan  7 21:23 addr_assign_type
-r--r--r--    1 root     root          4096 Jan  7 21:23 addr_len
-r--r--r--    1 root     root          4096 Jan  7 21:23 address
-r--r--r--    1 root     root          4096 Jan  7 21:23 broadcast
-rw-r--r--    1 root     root          4096 Jan  7 21:23 carrier
-r--r--r--    1 root     root          4096 Jan  7 21:23 dev_id
lrwxrwxrwx    1 root     root             0 Jan  7 21:23 device -> ../../../1-1.4:1.0
-r--r--r--    1 root     root          4096 Jan  7 21:23 dormant
-r--r--r--    1 root     root          4096 Jan  7 21:23 duplex
-rw-r--r--    1 root     root          4096 Jan  7 21:23 flags
-rw-r--r--    1 root     root          4096 Jan  7 21:23 ifalias
-r--r--r--    1 root     root          4096 Jan  7 21:23 ifindex
-r--r--r--    1 root     root          4096 Jan  7 21:23 iflink
-r--r--r--    1 root     root          4096 Jan  7 21:23 link_mode
-rw-r--r--    1 root     root          4096 Jan  7 21:23 mtu
-rw-r--r--    1 root     root          4096 Jan  7 21:23 netdev_group
-r--r--r--    1 root     root          4096 Jan  7 21:23 operstate
lrwxrwxrwx    1 root     root             0 Jan  7 21:23 phy80211 -> ../../ieee80211/phy3
drwxr-xr-x    6 root     root             0 Jan  7 21:23 queues
-r--r--r--    1 root     root          4096 Jan  7 21:23 speed
drwxr-xr-x    2 root     root             0 Jan  7 21:23 statistics
lrwxrwxrwx    1 root     root             0 Jan  7 21:23 subsystem -> ../../../../../../../../../class/net
-rw-r--r--    1 root     root          4096 Jan  7 21:23 tx_queue_len
-r--r--r--    1 root     root          4096 Jan  7 21:23 type
-rw-r--r--    1 root     root          4096 Jan  7 21:23 uevent
drwxr-xr-x    2 root     root             0 Jan  7 21:23 wireless
root@DIR-505-2:~# ls -l /sys/class/net/wlan0/phy80211
lrwxrwxrwx    1 root     root             0 Jan  7 21:23 /sys/class/net/wlan0/phy80211 -> ../../ieee80211/phy3

-> There you have the requested relation wlanx/phyx

If you want to know more about the usb device behind wlan0:

root@DIR-505-2:~# ls -l /sys/devices/platform/ehci-platform/usb1/1-1/1-1.4/  (ls -l /sys/class/net/ to see where this path is coming from)
drwxr-xr-x   12 root     root             0 Jan  7 21:18 1-1.4:1.0
-rw-r--r--    1 root     root          4096 Jan  7 21:29 authorized
-rw-r--r--    1 root     root          4096 Jan  7 21:29 avoid_reset_quirk
-rw-r--r--    1 root     root          4096 Jan  7 21:29 bConfigurationValue
-r--r--r--    1 root     root          4096 Jan  7 21:29 bDeviceClass
-r--r--r--    1 root     root          4096 Jan  7 21:29 bDeviceProtocol
-r--r--r--    1 root     root          4096 Jan  7 21:29 bDeviceSubClass
-r--r--r--    1 root     root          4096 Jan  7 21:29 bMaxPacketSize0
-r--r--r--    1 root     root          4096 Jan  7 21:29 bMaxPower
-r--r--r--    1 root     root          4096 Jan  7 21:29 bNumConfigurations
-r--r--r--    1 root     root          4096 Jan  7 21:29 bNumInterfaces
-r--r--r--    1 root     root          4096 Jan  7 21:29 bcdDevice
-r--r--r--    1 root     root          4096 Jan  7 21:29 bmAttributes
-r--r--r--    1 root     root          4096 Jan  7 21:29 busnum
-r--r--r--    1 root     root          4096 Jan  7 21:29 configuration
-r--r--r--    1 root     root         65553 Jan  7 21:29 descriptors
-r--r--r--    1 root     root          4096 Jan  7 21:29 dev
-r--r--r--    1 root     root          4096 Jan  7 21:29 devnum
-r--r--r--    1 root     root          4096 Jan  7 21:29 devpath
lrwxrwxrwx    1 root     root             0 Jan  7 21:29 driver -> ../../../../../../bus/usb/drivers/usb
drwxr-xr-x    2 root     root             0 Jan  7 21:29 ep_00
-r--r--r--    1 root     root          4096 Jan  7 21:29 idProduct
-r--r--r--    1 root     root          4096 Jan  7 21:29 idVendor
-r--r--r--    1 root     root          4096 Jan  7 21:29 ltm_capable
-r--r--r--    1 root     root          4096 Jan  7 21:29 manufacturer
-r--r--r--    1 root     root          4096 Jan  7 21:29 maxchild
lrwxrwxrwx    1 root     root             0 Jan  7 21:29 port -> ../1-1:1.0/port4
-r--r--r--    1 root     root          4096 Jan  7 21:29 product
-r--r--r--    1 root     root          4096 Jan  7 21:29 quirks
-r--r--r--    1 root     root          4096 Jan  7 21:29 removable
--w-------    1 root     root          4096 Jan  7 21:29 remove
-r--r--r--    1 root     root          4096 Jan  7 21:29 serial
-r--r--r--    1 root     root          4096 Jan  7 21:29 speed
lrwxrwxrwx    1 root     root             0 Jan  7 21:29 subsystem -> ../../../../../../bus/usb
-rw-r--r--    1 root     root          4096 Jan  7 21:29 uevent
-r--r--r--    1 root     root          4096 Jan  7 21:29 urbnum
-r--r--r--    1 root     root          4096 Jan  7 21:29 version

-> busnum / devnum / devpath / idProduct / idVendor / manufacturer / port (and others) might be of interest.

-> Now you have the  relation wlanx/phyx and can find out which USB device on which port it is.

You could try not loading the USB driver at boot, but instead delaying it with a script.  Then the built-in wifi is certain to come up first as phy0, and phy1 will be created later attached to the USB device.

(Last edited by mk24 on 8 Jan 2015, 03:57)

The discussion might have continued from here.