Connecting to the Internet over USB WiFi Print

 

This application note shows how to implement a USB WiFi secure client with the i.MX RT1050 running Linux. The functionality described below is available from the rootfs.uImage project provided by Emcraft for NXP i.MX RT1050 EVK board.

Emcraft tested the functionality documented below using the ComFast CF-WU815N adapter (based on the RT5370 chipset). If you are using some different USB WiFi dongle, then it may require enabling/porting/implementing the appropriate device drivers in the Linux kernel.

Disconnect Ethernet cable, and disable the eth0 interface:

/ # ifconfig eth0 down

Plug-in the USB WiFi device to the USB OTG port (USB1 J9 or USB2 J10 interface connector on the NXP i.MX RT1050 EVK board). The system will print the following to the console:

usb 1-1: new high-speed USB device number 4 using ci_hdrc
usb 1-1: reset high-speed USB device number 4 using ci_hdrc
ieee80211 phy0: rt2x00_set_rt: Info - RT chipset 3070, rev 0201 detected
ieee80211 phy0: rt2x00_set_rf: Info - RF chipset 0005 detected

Start wpa_supplicant to be able to connect to WiFi access points:

/ # wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -B
Successfully initialized wpa_supplicant
ieee80211 phy0: rt2x00lib_request_firmware: Info - Loading firmware file
'rt2870.bin'
ieee80211 phy0: rt2x00lib_request_firmware: Info - Firmware detected -
version: 0.29

Scan for available WiFi access points:

/ # wpa_cli scan
Selected interface 'wlan0'
OK
/ # wpa_cli scan_results
Selected interface 'wlan0'
dc:f8:b9:f0:1a:e8 2442 -43 [WPA2-PSK-CCMP][ESS] MGTS_GPON_E35D
3c:98:72:3f:ea:e2 2412 -45 [WPA2-PSK-CCMP][ESS] MGTS_GPON_2263
54:71:dd:04:4c:e0 2412 -61 [WPA2-PSK-CCMP][ESS] DIRECT-Z6-HUAWEI PixLab X1
44:59:43:7b:d9:78 2427 -69 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FR1000-2_D978_2.4G
c0:25:e9:81:99:91 2472 -77 [WPA2-PSK-CCMP][ESS] Oleg1
28:6c:07:cf:91:6e 2472 -83 [WPA2-PSK-CCMP][ESS] ASUS
9c:53:22:51:af:ab 2412 -63 [WPA2-PSK-CCMP][ESS] MGTS_GPON_2263
52:ff:20:4e:cc:c6 2447 -85 [WPA2-PSK-CCMP][ESS]
64:6e:ea:cc:13:b1 2412 -77 [WPA-PSK-CCMP+TKIP][ESS] RTWiFi-13B3
c4:6e:1f:a1:65:7a 2412 -77 [WPA2-PSK-CCMP][ESS] itce3555
30:42:40:ff:8a:6c 2412 -79 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] RT-WiFi-8A6C
6c:5a:b0:cd:d9:68 2422 -83 [WPA2-PSK-CCMP][ESS] spidermanHOME

Connect to the access point of your choice. Let's use DACHA2020 in our example. Create a new wireless network:

/ # wpa_cli add_network
Selected interface 'wlan0'
1

The number reported in the command above (1) is the identifier that must be used in the commands below. Configure the wireless network specifying the access point name and the password:

/ # wpa_cli set_network 1 ssid '" MGTS_GPON_2263"'
Selected interface 'wlan0'
OK
/ # wpa_cli set_network 1 psk '"change-me"'
Selected interface 'wlan0'
OK

Start the wireless network, obtain its status:

/ # wpa_cli enable_network 1 Selected interface 'wlan0' wlan0: authenticate with 74:4d:28:e4:59:c4 OK wlan0: send auth to 74:4d:28:e4:59:c4 (try 1/3) wlan0: authenticated wlan0: associate with 74:4d:28:e4:59:c4 (try 1/3) wlan0: RX AssocResp from 74:4d:28:e4:59:c4 (capab=0x431 status=0 aid=1) wlan0: associated / # wpa_cli status Selected interface 'wlan0' bssid=3c:98:72:3f:ea:e2 ssid=MGTS_GPON_2263 id=1 mode=station pairwise_cipher=CCMP group_cipher=CCMP key_mgmt=WPA2-PSK wpa_state=COMPLETED address=00:26:5a:11:ca:73 / # ifconfig wlan0 wlan0 Link encap:Ethernet HWaddr 00:26:5A:11:CA:73 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:196 errors:0 dropped:21 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:31145 (30.4 KiB) TX bytes:536 (536.0 B)

Configure the wireless networking using the access point DHCP server:

/ # udhcpc -i wlan0 / # ifconfig wlan0 wlan0 Link encap:Ethernet HWaddr 00:26:5A:11:CA:73 inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:394 errors:0 dropped:47 overruns:0 frame:0 TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:72627 (70.9 KiB) TX bytes:1508 (1.4 KiB) / # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.1.254 0.0.0.0 UG 0 0 0 wlan0 192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0

Validate the Internet connectivity:

/ # ping google.com -c 3 PING google.com (74.125.205.138): 56 data bytes 64 bytes from 74.125.205.138: seq=0 ttl=104 time=34.858 ms 64 bytes from 74.125.205.138: seq=1 ttl=104 time=22.778 ms 64 bytes from 74.125.205.138: seq=2 ttl=104 time=22.403 ms --- google.com ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 22.403/26.679/34.858 ms

The access point parameters are specified in the /etc/wpa_supplicant.conf file. In this case the connection will be established automatically, and the procedure will look like this:

usb 1-1: new high-speed USB device number 5 using ci_hdrc usb 1-1: reset high-speed USB device number 5 using ci_hdrc ieee80211 phy2: rt2x00_set_rt: Info - RT chipset 3070, rev 0201 detected ieee80211 phy2: rt2x00_set_rf: Info - RF chipset 0005 detected ieee80211 phy2: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin' ieee80211 phy2: rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29 wlan0: authenticate with 3c:98:72:3f:ea:e2 wlan0: send auth to 3c:98:72:3f:ea:e2 (try 1/3) wlan0: authenticated wlan0: associate with 3c:98:72:3f:ea:e2 (try 1/3) wlan0: RX AssocResp from 3c:98:72:3f:ea:e2 (capab=0x11 status=0 aid=6) wlan0: associated / # ifconfig eth0 down / # vi /etc/wpa_supplicant.conf / # wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -B Successfully initialized wpa_supplicant wlan0: deauthenticating from 3c:98:72:3f:ea:e2 by local choice (Reason: 3=DEAUTH_LEAVING) ctrl_iface exists and seems to be in use - cannot override it Delete '/var/run/wpa_supplicant/wlan0' manually if it is not used anymore Failed to initialize control interface '/var/run/wpa_supplicant'. You may have another wpa_supplicant process already running or the file was left by an unclean termination of wpa_supplicant in which case you will need to manually remove this file before starting wpa_supplicant again. / # udhcpc -i wlan0 / # ping google.com -c 3 PING google.com (74.125.205.101): 56 data bytes 64 bytes from 74.125.205.101: seq=0 ttl=102 time=23.576 ms 64 bytes from 74.125.205.101: seq=1 ttl=102 time=22.367 ms 64 bytes from 74.125.205.101: seq=2 ttl=102 time=22.607 ms --- google.com ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 22.367/22.850/23.576 ms

You may edit the wpa_supplicant.conf file right in the device console. Please note however that this file is located in the initramfs, so to preserve changes over reboots you should: