wfb-ng 锁定WiFi接口
为了更加方便的调试和使用wfb-ng软件,解决由于设备枚举发现时命名可能存在无法与硬件一一对应的问题,需要锁定实际硬件网卡与逻辑WiFi接口。
1. 源由
Raspberry Pi Zero W硬件本身自带一个WiFi网卡,其内置PCB天线的特殊性,仅能用于调试和近距离维护使用。
wfb-ng真正需要的是大功率发射的无线网卡,如果在设备发现阶段将设备逻辑WiFi接口自动命名为调试,那将会极大的影响传输距离和性能。
2. 需求
- Raspberry Pi Zero W硬件自带WiFi网卡,用于调试维护。
- 外置usb大功率无线网卡,用于远距离传输。
3. 分析
udev(userspace/dev)是Linux内核的设备管理器。作为devfsd和热插拔的继承者,udev主要管理/dev/目录中的设备节点。同时,udev还处理将硬件设备添加到系统或从系统中移除时引发的所有用户空间事件,包括某些设备所需的固件加载。
这里我们将使用到这软件来处理上述需求。
4. 步骤
因为网卡MAC地址是唯一的,因此用于绑定WiFi接口是不二之选。
4.1 确认网卡MAC地址
- Raspberry Pi Zero W
板载WiFi:b8:27:eb:53:31:30
USB-WiFi:0c:91:60:03:5b:62
- Raspberry Pi 3b+
板载WiFi:b8:27:eb:a6:3c:f3
USB-WiFi:20:0d:b0:32:da:3a
4.2 修改udev配置文件
- Raspberry Pi Zero W
pi@piCamera:~ $ sudo nano /etc/udev/rules.d/75-wifi-interface-name-change.rules
pi@piCamera:~ $ cat /etc/udev/rules.d/75-wifi-interface-name-change.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:27:eb:53:31:30", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="w*", NAME="wlan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="0c:91:60:03:5b:62", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="w*", NAME="wfb-rf1"
- Raspberry Pi 3b+
pi@piGs:~ $ sudo nano /etc/udev/rules.d/75-wifi-interface-name-change.rules
pi@piGs:~ $ cat /etc/udev/rules.d/75-wifi-interface-name-change.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:27:eb:a6:3c:f3", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="w*", NAME="wlan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="20:0d:b0:32:da:3a", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="w*", NAME="wfb-rf1"
4.3 配置重载&重启
$ sudo udevadm control --reload
$ sudo reboot
4.4 确认逻辑网卡接口
- Raspberry Pi Zero W
pi@piCamera:~ $ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 8 bytes 752 (752.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 752 (752.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wfb-rf1: flags=4099<UP,BROADCAST,MULTICAST> mtu 2312
ether 0c:91:60:03:5b:62 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.68.245 netmask 255.255.255.0 broadcast 192.168.68.255
ether b8:27:eb:53:31:30 txqueuelen 1000 (Ethernet)
RX packets 10380 bytes 873141 (852.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9753 bytes 780746 (762.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- Raspberry Pi 3b+
pi@piGs:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.68.232 netmask 255.255.255.0 broadcast 192.168.68.255
ether b8:27:eb:f3:69:a6 txqueuelen 1000 (Ethernet)
RX packets 32 bytes 4708 (4.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 2705 (2.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 8 bytes 770 (770.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 770 (770.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wfb-rf0: flags=4099<UP,BROADCAST,MULTICAST> mtu 2312
ether 20:0d:b0:32:da:3a txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.68.231 netmask 255.255.255.0 broadcast 192.168.68.255
ether b8:27:eb:a6:3c:f3 txqueuelen 1000 (Ethernet)
RX packets 267 bytes 23990 (23.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 275 bytes 36457 (35.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4.6 修改wfb-ng逻辑WiFi通信接口
$ cat /etc/default/wifibroadcast
#WFB_NICS="wlx00c0caa578a9"
#WFB_NICS="wlan1 wlan2"
#WFB_NICS="wlan0"
WFB_NICS="wfb-rf2"
5. 参考资料
【1】RPI zero W doesn’t find wlanx interface on Release 23.01 image #287
【2】udev @Wikipedia
【3】An introduction to Udev: The Linux subsystem for managing device events
【4】write udev rules for changing network interface name
【5】wfb-ng Release 23.01镜像无头烧录&配置
【6】Raspbian镜像无头烧录
【7】the next generation of long-range packet radio link
【8】 [DOC] docfix about udev rules #277
6. 补充资料
- 确认usb设备被识别到
$ dmesg|tail
[ 97.293626] usb 1-1.4: new high-speed USB device number 3 using dwc_otg
[ 97.423965] usb 1-1.4: config 1 interface 0 altsetting 0 endpoint 0x85 has an invalid bInterval 0, changing to 7
[ 97.424424] usb 1-1.4: New USB device found, idVendor=0bda, idProduct=881a, bcdDevice= 0.00
[ 97.424456] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 97.424477] usb 1-1.4: Product: 802.11n NIC
[ 97.424495] usb 1-1.4: Manufacturer: Realtek
[ 97.424510] usb 1-1.4: SerialNumber: 123456
[ 5528.320934] 88XXau_wfb: loading out-of-tree module taints kernel.
[ 5528.639401] usbcore: registered new interface driver rtl88xxau_wfb
[ 5529.849054] rtl88xxau_wfb 1-1.4:1.0 wfb-rf1: renamed from wlan1
- 确认88XXau_wfb驱动已经加载
$ lsmod |grep wfb
88XXau_wfb 1916928 0
cfg80211 782336 2 brcmfmac,88XXau_wfb
- 确认内核版本
$ uname -r
5.15.84+