Skip to main content

Wi-Fi: ConnMan

ConnMan is a daemon for managing Internet connections within embedded device and integrates a vast range of communication features usually split between many daemons such as DHCP, DNS and NTP. The result of this consolidation is low memory consumption with a fast, coherent, synchronized reaction to changing network conditions.

ConnMan is a fully modular system that can be extended, through plug-ins, to support all kinds of wired or wireless technologies. The plug-in approach allows for easy adaption and modification for various use cases.

The ea-image-base image that is flashed by default on all Developer's Kits, and is available on https://imx.embeddedartists.com, uses wpa-supplicant and the iw or wl tools to configure and connect to Wi-Fi networks.

There are several other ways of managing the network configuration.

Configure Yocto

There is no prepared image supporting ConnMan but by adding these lines to the conf/local.conf file as explained in Additional Packages:

# These are the extra packages needed on top of those in
# ea-image-base to make sure that connman works.
IMAGE_INSTALL += "\
connman \
connman-client \
"

# ea-files is not really compatible
IMAGE_INSTALL:remove = "\
ea-files \
"

With those changes, run build bitbake ea-image-base as normal.

Configure for M.2 module

switch_module.sh 1YN
reboot

Interactive use

Run connmanctl without arguments to enter the interactive shell:

root@imx8mnea-ucom:~# connmanctl
connmanctl>

Enable the agent which is needed to handle password request when connecting to a network and enable the actual Wi-Fi.

connmanctl> agent on
Agent registered
connmanctl> enable wifi
Enabled wifi

Scan for nearby Wi-Fi networks.

connmanctl> scan wifi
Scan completed for wifi
connmanctl> services
VSG1 wifi_10a5d099262f_56534731_managed_psk
BSGuest wifi_10a5d099262f_42534775657374_managed_psk
EA Guest wifi_10a5d099262f_4541204775657374_managed_psk
Laras wifi wifi_10a5d099262f_4c617261732077696669_managed_psk
4G-Gateway-E50340 wifi_10a5d099262f_34472d476174657761792d453530333430_managed_psk
Anna123 wifi_10a5d099262f_416e6e61313233_managed_psk

It is possible to show more information about a specific network. Note that connmanctl support tab-completion to speed up typing.

connmanctl> services wifi_10a5d099262f_56534731_managed_psk
/net/connman/service/wifi_10a5d099262f_56534731_managed_psk
Type = wifi
Security = [ psk ]
State = ready
Strength = 60
Favorite = True
Immutable = False
AutoConnect = True
Name = VSG1
Ethernet = [ Method=auto, Interface=wlan0, Address=10:A5:D0:99:26:2F, MTU=1500 ]
IPv4 = [ Method=dhcp, Address=10.158.186.129, Netmask=255.255.255.0, Gateway=10.158.186.69 ]
IPv4.Configuration = [ Method=dhcp ]
IPv6 = [ ]
IPv6.Configuration = [ Method=auto, Privacy=disabled ]
Nameservers = [ 10.158.186.69 ]
Nameservers.Configuration = [ ]
Timeservers = [ ]
Timeservers.Configuration = [ ]
Domains = [ ]
Domains.Configuration = [ ]
Proxy = [ Method=direct ]
Proxy.Configuration = [ ]
mDNS = False
mDNS.Configuration = False
Provider = [ ]

To connect to a network, enter the password (in this case test1234) when it is asked for:

connmanctl> connect wifi_10a5d099262f_56534731_managed_psk
Agent RequestInput wifi_10a5d099262f_56534731_managed_psk
Passphrase = [ Type=psk, Requirement=mandatory ]
Passphrase? test1234
[ 722.641856] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Connected wifi_10a5d099262f_56534731_managed_psk
connmanctl>

A common error here is this:

connmanctl> connect wifi_10a5d099262f_4541204775657374_managed_psk
Error /net/connman/service/wifi_10a5d099262f_4541204775657374_managed_psk: Not registered

Where, regardless of which Wi-Fi network is used, you get a Not registered error. This error appears if you have not executed the agent on command.

connmanctl> state
connmanctl> services wifi_10a5d099262f_4541204775657374_managed_psk (to show the *AR infront of the network we're connected to)

Tethering (i.e. SoftAP to ethernet)

Setting up hotspot is as easy as running:

connmanctl tether wifi on TestAP xyzw123456

This will create a Wi-Fi access point with SSID TestAP and password xyzw123456. The new interface looks like this:

ifconfig
...
tether Link encap:Ethernet HWaddr 10:A5:D0:99:26:2F
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::38a4:a5ff:fe32:af1e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:120 errors:0 dropped:0 overruns:0 frame:0
TX packets:139 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14958 (14.6 KiB) TX bytes:33408 (32.6 KiB)
...

To see a list of connected clients:

connmanctl tethering_clients
aa:26:45:9c:9a:42

If the board have a wired connection as well, then any connected client will have access to the wired network.

Ethernet preferred over Wi-Fi

By default, there is no priority between wired and wireless technology. This can be changed by creating/modifying /etc/connman/main.conf and adding this:

[General]
PreferredTechnologies=ethernet,wifi

Save and then either restart the connman.service or reboot.

This is difficult to verify if it works or not, but one way is to keep pinging a server and check the ping times with only the Wi-Fi connected and then see what happens when the network cable is inserted and then removed:

root@imx8mnea-ucom:~# ping www.sunet.se
PING www.sunet.se (37.156.192.50): 56 data bytes
64 bytes from 37.156.192.50: seq=0 ttl=53 time=114.108 ms
64 bytes from 37.156.192.50: seq=1 ttl=53 time=35.560 ms
64 bytes from 37.156.192.50: seq=2 ttl=53 time=59.609 ms
64 bytes from 37.156.192.50: seq=3 ttl=53 time=83.665 ms
64 bytes from 37.156.192.50: seq=4 ttl=53 time=107.762 ms
64 bytes from 37.156.192.50: seq=5 ttl=53 time=29.409 ms
64 bytes from 37.156.192.50: seq=6 ttl=53 time=53.394 ms
64 bytes from 37.156.192.50: seq=7 ttl=53 time=77.434 ms
64 bytes from 37.156.192.50: seq=8 ttl=53 time=101.356 ms
64 bytes from 37.156.192.50: seq=9 ttl=53 time=22.968 ms
64 bytes from 37.156.192.50: seq=10 ttl=53 time=47.022 ms <-- inserted cable here
64 bytes from 37.156.192.50: seq=11 ttl=53 time=71.223 ms
64 bytes from 37.156.192.50: seq=12 ttl=53 time=95.032 ms
64 bytes from 37.156.192.50: seq=13 ttl=53 time=16.622 ms
64 bytes from 37.156.192.50: seq=14 ttl=53 time=39.718 ms
64 bytes from 37.156.192.50: seq=15 ttl=53 time=62.258 ms
64 bytes from 37.156.192.50: seq=16 ttl=53 time=84.876 ms
64 bytes from 37.156.192.50: seq=17 ttl=53 time=11.680 ms <-- here ConnMan has switched to wired
64 bytes from 37.156.192.50: seq=18 ttl=53 time=11.430 ms
64 bytes from 37.156.192.50: seq=19 ttl=53 time=11.405 ms
64 bytes from 37.156.192.50: seq=20 ttl=53 time=11.428 ms
64 bytes from 37.156.192.50: seq=21 ttl=53 time=11.431 ms
64 bytes from 37.156.192.50: seq=22 ttl=53 time=11.375 ms
64 bytes from 37.156.192.50: seq=23 ttl=53 time=11.440 ms
64 bytes from 37.156.192.50: seq=24 ttl=53 time=11.652 ms
64 bytes from 37.156.192.50: seq=25 ttl=53 time=11.401 ms <-- removed cable here
64 bytes from 37.156.192.50: seq=27 ttl=53 time=29.485 ms
64 bytes from 37.156.192.50: seq=28 ttl=53 time=52.317 ms
64 bytes from 37.156.192.50: seq=29 ttl=53 time=75.358 ms
64 bytes from 37.156.192.50: seq=30 ttl=53 time=98.446 ms

The times vary between 22 and 114 ms while using the Wi-Fi network but when switched to the wired network it becomes lower and very stable at 11.4-11.7 and when the cable is removed it goes back up again.

Disable/Enable a technology

connmanctl disable ethernet

Takes affect immediately, is persistent (still no wired network after a reboot). Restore with connmanctl enable ethernet.

The same thing can be done with Wi-Fi: connman enable wifi and connmanctl disable wifi.

Roaming?

It is possible to configure more than one Wi-Fi network and have ConnMan switch between them based on availability. Note that it could take some time before the switch is made.

Fixed IP

The default setup is to use DHCP when connecting to a network and then get assigned an IP number and one or more nameservers to use. In some cases it is better to have control of this yourself and use a fixed IP address. To do this:

connmanctl> config wifi_10a5d099262f_4541204775657374_managed_psk --ipv4 manual 192.168.0.12 255.255.255.0 192.168.0.1
connmanctl> config wifi_10a5d099262f_4541204775657374_managed_psk --nameservers 192.168.0.1

There are several other configuration options that can be used:

connmanctl> help
...
config <service> Set service configuration options
--nameservers <dns1> [<dns2>] [<dns3>]
--timeservers <ntp1> [<ntp2>] [...]
--domains <domain1> [<domain2>] [...]
--mdns yes|no
--ipv6 off|auto [enable|disable|preferred]|
manual <address> <prefixlength> <gateway>
--proxy direct|auto <URL>|manual <URL1> [<URL2>] [...]
[exclude <exclude1> [<exclude2>] [...]]
--autoconnect yes|no
--ipv4 off|dhcp|manual <address> <netmask> <gateway>
--remove Remove service
...

To see the current configuration:

root@imx8mnea-ucom:~# connmanctl services wifi_2c4cc6f4d3d0_565347315f3547_managed_psk
/net/connman/service/wifi_2c4cc6f4d3d0_565347315f3547_managed_psk
Type = wifi
Security = [ psk ]
State = online
Strength = 79
Favorite = True
Immutable = False
AutoConnect = False
Name = VSG1_5G
Ethernet = [ Method=auto, Interface=mlan0, Address=2C:4C:C6:F4:D3:D0, MTU=1500 ]
IPv4 = [ Method=manual, Address=192.168.0.12, Netmask=255.255.255.0, Gateway=192.168.0.1 ]
IPv4.Configuration = [ Method=manual, Address=192.168.0.12, Netmask=255.255.255.0, Gateway=192.168.0.1 ]
IPv6 = [ ]
IPv6.Configuration = [ Method=auto, Privacy=disabled ]
Nameservers = [ 192.168.0.1 ]
Nameservers.Configuration = [ 192.168.0.1 ]
Timeservers = [ ]
Timeservers.Configuration = [ ]
Domains = [ ]
Domains.Configuration = [ ]
Proxy = [ Method=direct ]
Proxy.Configuration = [ ]
mDNS = False
mDNS.Configuration = False
Provider = [ ]

To go back to DHCP:

connmanctl> config wifi_2c4cc6f4d3d0_565347315f3547_managed_psk --ipv4 dhcp

Troubleshooting

Multiple services with the same name

Problem

In some cases, scanning for available Wi-Fi networks results in a list with multiple entries for each found network like this:

connmanctl> services
...
VSG1 wifi_2e4cc6f4d3d0_56534731_managed_psk
VSG1 wifi_2c4cc6f4d4d0_56534731_managed_psk
VSG1 wifi_2c4cc6f4d3d0_56534731_managed_psk
...

Affects

This seems to be the case for M.2 modules using an NXP chipset (see first table in Introduction).

Solution

ConnMan services are presented as wifi_<HWaddr>_<SSID in hex>_managed_psk. If there are several network interfaces listed in ifconfig then each of them (except for ethX and lo which are not for Wi-Fi) will get its own line.

For an 1XK M.2 module it looks like this:

root@imx8mnea-ucom:~# ifconfig |grep Link
eth0 Link encap:Ethernet HWaddr 00:1A:F1:10:59:43
lo Link encap:Local Loopback
mlan0 Link encap:Ethernet HWaddr 2C:4C:C6:F4:D3:D0
uap0 Link encap:Ethernet HWaddr 2C:4C:C6:F4:D4:D0
wfd0 Link encap:Ethernet HWaddr 2E:4C:C6:F4:D3:D0

ConnMan will show one service for each of mlan0, uap0 and wfd0 but the interface to use is the mlan0 above. Note the HWaddr and compare it to the entries in the services list to find which service to use.

In this example the HWaddr is 2C:4C:C6:F4:D4:D0, so the service ID should contain 2c4cc6f4d4d0 which only wifi_2c4cc6f4d4d0_56534731_managed_psk does.

Alternative Solution

It is possible to blacklist the two other interfaces. To do this, create /etc/connman/main.conf if it doesn't already exist and add:

[General]
NetworkInterfaceBlacklist=wfd,uap

Save and then either restart the connman.service or reboot.

For more information about blacklisting interface see here.