Search by Tags

Toradex’s Linux Images - How to connect to a Wi-Fi network

 

Article updated at 18 Mar 2020
Subscribe for this article updates

Introduction

This article shows how to set up Linux to connect to a Wi-Fi network in Client mode.

Other Wi-Fi related articles

If this is not the information you are looking for, please, refer to the Wi-Fi Connectivity with Toradex’s Computer on Module (CoM) article for more Wi-Fi related information.

Enable the kernel support for the Wireless adapter

Click here to see a complete list of Toradex Computer on Modules (COMs) with integrated Wi-Fi/Bluetooth

Toradex's Embedded Linux BSPs only provide out-of-the-box software support for the LM006 Wi-Fi dongle, Wi2Wi WM828CC6, and AzureWave AW-CM276NF modules (Integrated to selected CoMs). If you are using a Toradex's CoM with embedded Wi-Fi, (see list above), the kernel support is enabled by default on Toradex's Embedded Linux BSPs and you can proceed to the next step.

For modules that don't come with on-module Wi-Fi hardware, a mini-PCIe, SDIO or USB Wi-Fi module can be used. Please refer to Setting up 3rd Party Wi-Fi Adapters Linux Kernel Support for Toradex’s Linux Images before proceed.

List the available interfaces

Attention: Before proceeding with the next steps, make sure the kernel support is enabled for your Wi-Fi module as the instructions above.

Use the ip addr to list all the available interfaces and check if the kernel support was properly enabled.

Click here for an example of the expected output for a Colibri iMX6ULL with embedded Wi-Fi:

Wi-Fi Connection Bring Up

Select your Linux BSP image below to see how to proceed to connect to a Wi-Fi Network.

To see a list of available Wi-Fi hotspots:

# nmcli device wifi list

Connect to a Wi-Fi:

# nmcli -a device wifi connect <WIFI_NAME>

For more information, see the Networking with TorizonCore page.

On images V2.x the connman package provides connectivity management.

http://connman.net

Automatic (GUI)

The connections can be configured by starting the configuration program connman-properties or by starting the taskbar applet connman-applet.

Interactively

Note: On the Colibri iMX6ULL make sure to connect to the mlan0 Wi-Fi interface which may be distinguished based on their MAC addresses.

root@colibri-imx6ull:~# connmanctl 
Error getting VPN connections: The name net.connman.vpn was not provided by any
connmanctl> enable wifi
[  426.104116] IPv6: ADDRCONF(NETDEV_UP): mlan0: link is not ready
[  426.145123] IPv6: ADDRCONF(NETDEV_UP): uap0: link is not ready
Enabled wifi
connmanctl> scan wifi
[  452.706815] ieee80211 phy0: mwifiex_cfg80211_sched_scan_start : Invalid Sched_scan parameters
Scan completed for wifi
connmanctl> agent on
Agent registered
connmanctl> services
    testnet             wifi_0019885e10de_666167776c616e32_managed_psk
    testnet             wifi_0019885e11de_666167776c616e32_managed_psk
connmanctl> connect wifi_0019885e10de_666167776c616e32_managed_psk
Agent RequestInput wifi_0019885e10de_666167776c616e32_managed_psk
  Passphrase = [ Type=psk, Requirement=mandatory ]
Passphrase? testpw
connmanctl> [  637.111283] mwifiex_sdio mmc1:0001:1: info: trying to associate to 'testnet' bssid 44:d9:e7:fa:cf:d5
[  637.137213] mwifiex_sdio mmc1:0001:1: info: associated to bssid 44:d9:e7:fa:cf:d5 successfully
[  637.194021] IPv6: ADDRCONF(NETDEV_CHANGE): mlan0: link becomes ready
[  676.632838] ieee80211 phy0: mwifiex_cfg80211_sched_scan_start : Invalid Sched_scan parameters
Connected wifi_0019885e10de_666167776c616e32_managed_psk
connmanctl> quit

Manual

Our latest V2.x images also include a command-line configuration tool called connmanctl:

https://gist.github.com/kylemanna/6930087

As follows how to connect to a WPA PSK enabled Wi-Fi using an LM006 USB stick, or the Colibri iMX6ULL 512MB WB on-module Wi2Wi WM828CC6 adapter.

First plug in the Wi-Fi USB stick (LM006 only):

[ 55.779953] usb 3-1: new high speed USB device number 3 using tegra-ehci
[ 55.971825] usb 3-1: New USB device found, idVendor=0bda, idProduct=8176
[ 55.978538] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 55.985743] usb 3-1: Product: 802.11n WLAN Adapter
[ 55.990587] usb 3-1: Manufacturer: Realtek
[ 55.994688] usb 3-1: SerialNumber: 00e04c000001
[ 56.151090] rtl8192cu: MAC address: 5c:f3:70:24:97:e5
[ 56.156167] rtl8192cu: Board Type 0
[ 56.171585] rtlwifi: rx_max_size 15360, rx_urb_num 8, in_ep 1

Then enable the Wi-Fi technology layer:

root@colibri-t30:~# connmanctl enable wifi
[ 531.793311] rtl8192cu: MAC auto ON okay!
[ 531.857315] rtl8192cu: Tx queue select: 0x05
[ 531.863386] rtl8192c_common: Loading firmware file rtlwifi/rtl8192cufw.bin
[ 532.376983] ADDRCONF(NETDEV_UP): wlan0: link is not ready
Enabled wifi

And scan for available networks:

root@colibri-t30:~# connmanctl scan wifi
Scan completed for wifi

Now show what the above actually found:

root@colibri-t30:~# connmanctl services
*AR Wired { ethernet_00142d486cef_cable }
<SSID> { wifi_<HASH>_managed_psk }

Finally adjust the security aka WPA PSK configuration:

root@colibri_t30:~# vi /var/lib/connman/<SSID>-psk.config
[service_wifi_<HASH>_managed_psk]
Type = wifi
Name = <SSID>
Passphrase = <PASSPHRASE>

Last but not least attempt to connect:

root@colibri_t30:~# connmanctl connect wifi_<HASH>_managed_psk
[ 1165.219739] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Connected

If you still have wired Ethernet connected make sure to disconnect the cable in order for Wi-Fi to take over:

root@colibri-t30:~# [ 653.968178] eth0: ax88772b - Link status is: 0
[ 654.026020] ADDRCONF(NETDEV_UP): eth0: link is not ready

Configuring Wi-Fi with static IP address

Configuring Wi-Fi with a static IP address can be done using the connman-applet with a graphical user interface. If one does not have a GUI, the process must be done via the command line interface.

When a WPA PSK configuration file is created, connman automatically configures Wi-Fi to use DHCP and does not allow manual changes to the IP address as it would for an Ethernet connection using connmanctl.

If the following file was created before, it needs to be deleted, as it conflicts with a new file that will be created:

/var/lib/connman/<SSID>-psk.config

First create the following directory (where is the hash identifier assigned to the device by connman):

mkdir /var/lib/connman/wifi_<HASH>_managed_psk

Inside the directory, create a file named “settings”:

vi /var/lib/connman/wifi_<HASH>_managed_psk/settings

The file should contain the following:

[wifi_<HASH>_managed_psk]
Name=<SSID> ← Name of your network
SSID=544f52414445585f4252 ← Name of your network in hexadecimal format
Favorite=true
IPv4.method=manual ← Method to be used (in our case manual IP)
IPv4.netmask_prefixlen=24
IPv4.local_address=192.168.0.133 ← Desired IP address
IPv4.gateway=192.168.0.1
Passphrase=<PASS> ← Wi-Fi network password
AutoConnect=true

In this next step we have three options, one can use what is best suited to the application:

  • reboot the module;
  • disconnect and reconnect the Wi-Fi module (if it was already connected);
  • restart the USB bus port with the following commands:
echo '1-1' > /sys/bus/usb/drivers/usb/unbind
echo '1-1' > /sys/bus/usb/drivers/usb/bind

Now enable the Wi-Fi technology layer:

connmanctl enable wifi

Finally, simply connect to the network:

connmanctl connect wifi_<HASH>_managed_psk

On images V1.x the following brings up the connection from the command line:

ifconfig wlan0 up
iwlist wlan0 scanning
wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
# -dd for debugging
# -B for background daemon

To do WEP, WPA or WPA2 just edit /etc/wpa_supplicant.conf and add the information about your wireless network infrastructure.

If you erroneously specify proto=WPA but do have a WPA2 infrastructure, wpa_supplicant returns the following error message if run with debugging (-dd) enabled:

wlan0: skip - no WPA/RSN proto match

With all the steps concluded, the module should be connected with the chosen static IP address and it is now possible to freely change the IP address using connmanctl.