Connecting to the Internet over USB WiFi Print

 

This application note shows how to implement a USB WiFi secure client with the STM32F7 running Linux. The functionality described below is available from the rootfs.uImage project installed by Emcraft to every shipping STM32F7 SOM Starter Kit.

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.

Plug-in a USB WiFi device to the USB HS port (P19 of the SOM-BSB-EXT baseboard). The system will print the following to the console:

usb 1-1: new high-speed USB device number 3 using dwc2
usb 1-1: reset high-speed USB device number 3 using dwc2
ieee80211 phy0: rt2x00_set_rt: Info - RT chipset 5390, rev 0502 detected
ieee80211 phy0: rt2x00_set_rf: Info - RF chipset 5370 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'
bssid / frequency / signal level / flags / ssid
ec:43:f6:e1:4a:d8 2462 -55 [WPA2-PSK-CCMP][ESS] Tik
ec:43:f6:02:75:54 2437 -93 [WPA2-PSK-CCMP][ESS] MAXIM
ea:28:5d:7b:5a:f8 2432 -97 [WPA2-PSK-CCMP][ESS] ELDAR

Connect to the access point of your choice. Let's use Tik 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 '"Tik"'
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'
OK
wlan0: authenticate with ec:43:f6:e1:4a:d8
wlan0: send auth to ec:43:f6:e1:4a:d8 (try 1/3)
wlan0: authenticated
wlan0: associate with ec:43:f6:e1:4a:d8 (try 1/3)
wlan0: RX AssocResp from ec:43:f6:e1:4a:d8 (capab=0x411 status=0 aid=1)
wlan0: associated
/ # wpa_cli status
Selected interface 'wlan0'
bssid=ec:43:f6:e1:4a:d8
ssid=Tik
id=1
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
address=00:0f:12:71:0e:06
/ # ifconfig wlan0
wlan0Link encap:Ethernet HWaddr 00:0F:12:71:0E:06
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:402 (402.0 B) TX bytes:288 (288.0 B)

Configure wireless networking using the access point DHCP server (get IP, etc):

/ # udhcpc -i wlan0
/ # ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:0F:12:71:0E:06
inet addr:192.168.1.45 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32 errors:0 dropped:2 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8396 (8.1 KiB) TX bytes:980 (980.0 B)

Validate internet connectivity:

/ # ping google.com
PING google.com (173.194.32.169): 56 data bytes
64 bytes from 173.194.32.169: seq=0 ttl=56 time=5.210 ms
64 bytes from 173.194.32.169: seq=1 ttl=56 time=5.198 ms
64 bytes from 173.194.32.169: seq=2 ttl=56 time=12.898 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 5.198/7.768/12.898 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:

/ # vi /etc/wpa_supplicant.conf
/ # 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
wlan0: authenticate with ec:43:f6:e1:4a:d8
wlan0: send auth to ec:43:f6:e1:4a:d8 (try 1/3)
wlan0: authenticated
wlan0: associate with ec:43:f6:e1:4a:d8 (try 1/3)
wlan0: RX AssocResp from ec:43:f6:e1:4a:d8 (capab=0x411 status=0 aid=1)
wlan0: associated
/ # udhcpc -i wlan0
/ # ping google.com
PING google.com (173.194.122.230): 56 data bytes
64 bytes from 173.194.122.230: seq=0 ttl=56 time=5.302 ms
64 bytes from 173.194.122.230: seq=1 ttl=56 time=7.732 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 5.302/6.517/7.732 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: