USB WiFi
本次測試的 USB WiFi dongle 硬體資訊
1 2 3 4 5 6 |
裝置描述 802.11b/g Mini Wireless LAN USB 2.0 Adapter 硬體識別碼 USB\VID_07B8&PID_B21D&REV_0001 USB\VID_07B8&PID_B21D |
NanoPi 有支援驅動,可以掃描 AP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
root@NanoPi-NEO2:/# nmcli dev DEVICE TYPE STATE CONNECTION eth0 ethernet connected Wired connection 1 wlx00120e98e332 wifi disconnected -- erspan0 erspan unmanaged -- gretap0 gretap unmanaged -- gre0 iptunnel unmanaged -- lo loopback unmanaged -- root@NanoPi-NEO2:/# nmcli r wifi on root@NanoPi-NEO2:/# nmcli dev wifi * SSID MODE CHAN RATE SIGNAL BARS SECURITY YoYoHome Infra 1 54 Mbit/s 97 ▂▄▆█ WPA2 Home Infra 1 54 Mbit/s 60 ▂▄▆_ WPA2 LiNiNiwireless Infra 11 54 Mbit/s 40 ▂▄__ WPA2 root@NanoPi-NEO2:/# nmcli dev wifi connect "wifi" password "12345678" Device 'wlan0' successfully activated with '7e084707-f30a-462b-b742-2df9538ab735'. |
--
開機完成才執行
--
將 wlx??? 網路卡名稱改成 wlan0
1 2 |
# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules # init 6 |
--
AP mode
vi /etc/network/interfaces
1 2 3 4 5 |
allow-hotplug wlan0 auto wlan0 iface wlan0 inet static address 172.17.1.1 netmask 255.255.255.0 |
啟用
1 |
# systemctl daemon-reload |
vi /etc/hostapd/hostapd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
interface=wlan0 driver=nl80211 ssid=CC2050 hw_mode=g channel=7 #ieee80211n=1 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=1122334455 wpa_key_mgmt=WPA-PSK rsn_pairwise=TKIP CCMP |
vi /etc/dnsmasq.conf
1 2 3 |
interface=wlan0 bogus-priv dhcp-range=172.17.1.100,172.17.1.200,24h |
啟用
1 2 |
# systemctl enable dnsmasq # systemctl restart dnsmasq |
vi /etc/NetworkManager/NetworkManager.conf
1 2 3 4 5 6 7 8 9 10 |
[main] plugins=ifupdown,keyfile,ofono dns=dnsmasq [ifupdown] managed=false [keyfile] unmanaged-devices=interface-name:wlan* #unmanaged-devices=mac:00:12:0e:98:e3:32 |
啟動
1 2 |
# systemctl enable hostapd # systemctl start hostapd |
初次使用時,可以使用以下指令顯示執行訊息方便除錯
1 |
# hostapd -d /etc/hostapd/hostapd.conf |
--
USB 插入
1 2 3 4 5 6 7 8 9 10 11 |
# dmesg [ 481.325226] usb 5-1: USB disconnect, device number 2 [ 487.593530] usb 5-1: new high-speed USB device number 3 using ehci-platform [ 488.097553] usb 5-1: reset high-speed USB device number 3 using ehci-platform [ 488.606313] ieee80211 phy1: rt2x00_set_chip: Info - Chipset detected - rt: 2573, rf: 0002, rev: 000a [ 488.607476] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht' [ 488.722344] rt73usb 5-1:1.0 wlx00120e98e332: renamed from wlan0 [ 488.829879] ieee80211 phy1: rt2x00lib_request_firmware: Info - Loading firmware file 'rt73.bin' [ 488.830021] ieee80211 phy1: rt2x00lib_request_firmware: Info - Firmware detected - version: 1.7 [ 488.907798] IPv6: ADDRCONF(NETDEV_UP): wlx00120e98e332: link is not ready |
--
加入自己的 USB 插入程序
/etc/udev/rules.d/99-usbwifi.rules
1 |
RUN+="/home/wifi_script" |
/home/wifi_script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/sh echo $SEQNUM : $SUBSYSTEM : $ACTION : $DEVNAME : $ID_MODEL >> /home/wifi_script.log # plug usb if [ "$ID_MODEL" = "802.11_bg_WLAN" ] && [ "$DEVNAME" = "" ] && [ "$ACTION" = "add" ]; then /usr/bin/sudo /bin/systemctl start hostapd /usr/bin/sudo /bin/systemctl start dnsmasq fi # remove usb if [ "$ID_MODEL" = "802.11_bg_WLAN" ] && [ "$ACTION" = "remove" ]; then /usr/bin/sudo /bin/systemctl stop dnsmasq /usr/bin/sudo /bin/systemctl stop hostapd fi exit 0 |
完整的 USB WiFi 插入 & 拔出 log 紀錄
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
2419 : usb : add : /dev/bus/usb/005/003 : 802.11_bg_WLAN 2420 : usb : add : : 2430 : leds : add : : 2429 : leds : add : : 2421 : ieee80211 : add : : 2431 : leds : add : : 2422 : rfkill : add : : 2423 : net : add : : 802.11_bg_WLAN 2424 : queues : add : : 2428 : queues : add : : 2427 : queues : add : : 2426 : queues : add : : 2425 : queues : add : : 2434 : net : move : : 802.11_bg_WLAN 2436 : leds : remove : : 2437 : leds : remove : : 2435 : leds : remove : : 2441 : queues : remove : : 2439 : queues : remove : : 2440 : queues : remove : : 2442 : queues : remove : : 2438 : queues : remove : : 2444 : rfkill : remove : : 2443 : net : remove : : 802.11_bg_WLAN 2445 : ieee80211 : remove : : 2447 : usb : remove : : 2449 : usb : remove : /dev/bus/usb/005/003 : 802.11_bg_WLAN |
--
實際使用
--
2,827 total views, 1 views today