几年前,入了一个tl wn725的usb无线网卡,在windows下使用还可以,连接速度150M,40Mhz,MCS7。于是想把这个无线网卡用在raspiberry 2上面,编译内核的时候加上mt7601支持,把系统cp到ssd卡boot分区,启动,然后插入wn725,看dmesg
Jun 24 14:15:57 pi kernel: [ 2826.232039] usb 1-1.4: new high-speed USB device number 8 using dwc_otg
Jun 24 14:15:57 pi kernel: [ 2826.332869] usb 1-1.4: New USB device found, idVendor=148f, idProduct=2878
Jun 24 14:15:57 pi kernel: [ 2826.332898] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Jun 24 14:15:57 pi kernel: [ 2826.332914] usb 1-1.4: Product: Љ
Jun 24 14:15:57 pi kernel: [ 2826.332929] usb 1-1.4: Manufacturer: Љ
Jun 24 14:15:57 pi kernel: [ 2826.333986] usb-storage 1-1.4:1.0: USB Mass Storage device detected
Jun 24 14:15:57 pi kernel: [ 2826.334472] scsi host2: usb-storage 1-1.4:1.0
Jun 24 14:15:58 pi-mao kernel: [ 2827.332761] scsi 2:0:0:0: CD-ROM MediaTek Flash autorun 0.01 PQ: 0 ANSI: 0 CCS
Jun 24 14:15:58 pi kernel: [ 2827.334241] sr 2:0:0:0: [sr0] scsi3-mmc drive: 52x/52x cd/rw xa/form2 cdda tray
Jun 24 14:15:58 pi kernel: [ 2827.335913] sr 2:0:0:0: Attached scsi generic sg0 type 5
不认设备啊,google了一下,手工可以使用eject /dev/sr0,弹出存储设备,设备就会做为网卡
#eject /dev/sr0
dmesg看输出:
Jun 24 14:18:37 pi kernel: [ 2986.274120] usb 1-1.4: USB disconnect, device number 8
Jun 24 14:18:38 pi kernel: [ 2986.673329] usb 1-1.4: new high-speed USB device number 9 using dwc_otg
Jun 24 14:18:38 pi kernel: [ 2986.784543] usb 1-1.4: New USB device found, idVendor=148f, idProduct=7601
Jun 24 14:18:38 pi kernel: [ 2986.784569] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 24 14:18:38 pi kernel: [ 2986.784585] usb 1-1.4: Product: 802.11 n WLAN
Jun 24 14:18:38 pi kernel: [ 2986.784600] usb 1-1.4: Manufacturer: MediaTek
Jun 24 14:18:38 pi kernel: [ 2986.784615] usb 1-1.4: SerialNumber: 1.0
Jun 24 14:18:38 pi kernel: [ 2986.863351] usb 1-1.4: reset high-speed USB device number 9 using dwc_otg
Jun 24 14:18:38 pi kernel: [ 2986.966276] mt7601u 1-1.4:1.0: ASIC revision: 76010001 MAC revision: 76010500
Jun 24 14:18:38 pi kernel: [ 2986.967770] mt7601u 1-1.4:1.0: Firmware Version: 0.1.00 Build: 7640 Build time: 201302052146____
Jun 24 14:18:39 pi kernel: [ 2987.372699] mt7601u 1-1.4:1.0: Warning: unsupported EEPROM version 0d
Jun 24 14:18:39 pi kernel: [ 2987.372727] mt7601u 1-1.4:1.0: EEPROM ver:0d fae:00
Jun 24 14:18:39 pi kernel: [ 2987.374216] mt7601u 1-1.4:1.0: EEPROM country region 01 (channels 1-13)
看到系统已经识别出网卡,但是不能每次使用都手工输入eject啊,于是使用udev,在设备初始化的时候自动eject sr0/sg0
在/etc/udev/rules.d目录下增加一个725.udev
#148f:2878#
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="148f", ATTRS{idProduct}=="2878", RUN+="/usr/bin/logger detected WN725"
KERNEL=="sr0", RUN+="/usr/bin/eject /dev/sr0"
这样就在每次插入后自动eject设备,下面开始配置无线,使用 wpa_supplicant套件。
配置/etc/network/interfaces
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
其中最后一句是重点,网上的资料基本上都没有 说,我是通过查看日志才知道应该这么写的
然后需要配置/etc/wpa_supplicant/wpa_supplicant.conf,其中psk通过wpa_passphrase生成
也可以使用wpa_gui
最后配置文件是这个样子:
network={
ssid="xxxx"
psk=a0de260342bf0bf270966b1ac100b7174ab733c26c1d24f875cba1f98abc6447
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
priority=1
}
配置完了就可以再测试一下了,重新插拨一下网卡,日志如下:
Jun 24 14:28:01 pi kernel: [ 3550.123212] scsi 3:0:0:0: CD-ROM MediaTek Flash autorun 0.01 PQ: 0 ANSI: 0 CCS
Jun 24 14:28:01 pi kernel: [ 3550.124648] sr 3:0:0:0: [sr0] scsi3-mmc drive: 52x/52x cd/rw xa/form2 cdda tray
Jun 24 14:28:01 pi kernel: [ 3550.126224] sr 3:0:0:0: Attached scsi generic sg0 type 5
Jun 24 14:28:02 pi kernel: [ 3550.393264] usb 1-1.4: USB disconnect, device number 10
Jun 24 14:28:02 pi kernel: [ 3550.812474] usb 1-1.4: new high-speed USB device number 11 using dwc_otg
Jun 24 14:28:02 pi kernel: [ 3550.923690] usb 1-1.4: New USB device found, idVendor=148f, idProduct=7601
Jun 24 14:28:02 pi kernel: [ 3550.923716] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 24 14:28:02 pi kernel: [ 3550.923732] usb 1-1.4: Product: 802.11 n WLAN
Jun 24 14:28:02 pi kernel: [ 3550.923747] usb 1-1.4: Manufacturer: MediaTek
Jun 24 14:28:02 pi kernel: [ 3550.923762] usb 1-1.4: SerialNumber: 1.0
Jun 24 14:28:02 pi kernel: [ 3551.002474] usb 1-1.4: reset high-speed USB device number 11 using dwc_otg
Jun 24 14:28:02 pi kernel: [ 3551.105431] mt7601u 1-1.4:1.0: ASIC revision: 76010001 MAC revision: 76010500
Jun 24 14:28:02 pi kernel: [ 3551.106925] mt7601u 1-1.4:1.0: Firmware Version: 0.1.00 Build: 7640 Build time: 201302052146____
Jun 24 14:28:03 pi kernel: [ 3551.509358] mt7601u 1-1.4:1.0: Warning: unsupported EEPROM version 0d
Jun 24 14:28:03 pi kernel: [ 3551.509387] mt7601u 1-1.4:1.0: EEPROM ver:0d fae:00
Jun 24 14:28:03 pi kernel: [ 3551.509948] mt7601u 1-1.4:1.0: EEPROM country region 01 (channels 1-13)
Jun 24 14:28:04 pi kernel: [ 3553.144356] cfg80211: Exceeded CRDA call max attempts. Not calling CRDA
Jun 24 14:28:04 pi kernel: [ 3553.316305] wlan0: authenticate with 20:76:93:42:ec:c4
Jun 24 14:28:05 pi kernel: [ 3553.355888] wlan0: send auth to 20:76:93:42:ec:c4 (try 1/3)
Jun 24 14:28:05 pi kernel: [ 3553.357961] wlan0: authenticated
Jun 24 14:28:05 pi kernel: [ 3553.362475] wlan0: associate with 20:76:93:42:ec:c4 (try 1/3)
Jun 24 14:28:05 pi kernel: [ 3553.372739] wlan0: RX AssocResp from 20:76:93:42:ec:c4 (capab=0xc31 status=0 aid=8)
Jun 24 14:28:05 pi kernel: [ 3553.401508] wlan0: associated
Jun 24 14:28:05 pi kernel: [ 3553.402884] cfg80211: Calling CRDA to update world regulatory domain
ifconfig可以看到ip已经分配。
ps -ef | grep wlan0可以看到启动的进程:
root 3903 1 0 14:28 ? 00:00:00 /usr/sbin/ifplugd -i wlan0 -q -f -u0 -d10 -w -I
root 3923 1 0 14:28 ? 00:00:00 /sbin/wpa_supplicant -s -B -P /var/run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf
root 3989 1 0 14:28 ? 00:00:00 dhclient -v -pf /run/dhclient.wlan0.pid -lf /var/lib/dhcp/dhclient.wlan0.leases wlan0
这样每次插入网卡的时候,就会自动启动网络了,但是还有个问题:
就是如果是插着网卡上电或者重启,udev可能不会执行,sr0就无法弹出,后面的步骤就无法执行,不知道有没有 好的方法?