Wi-Fi


This chapter describes common information and instructions of Wi-Fi on IoT Yocto, such as command to configure DHCP or static IP and so on.

But Wi-Fi on different platforms may have some platform-specific instructions or test results. For example, you will get different throughput on different platforms.


Station (Client) Mode

Connect to a Wi-Fi AP

There are two methods to connect evaluation board to a Wi-Fi network: NetworkManager and wpa_supplicant.

NetworkManager is a high level service and should be used when possible, since it automatically configures wpa_supplicant and other system states.

Connect to a Network via NetworkManager

First, make sure service NetworkManager (NetworkManager) is running:

systemctl status NetworkManager.service

You should see an output line like this:

Active: active (running)

If not, launch NetworkManager:

systemctl start NetworkManager.service

Now, please remove the old config file from /etc/wpasupplicant.conf, if wpa_supplicant has been used before. This configuration file interferes NetworkManager.

rm -rf /etc/wpasupplicant.conf

Finally, run nmcli command to configure and connect the board to WIFI with NetworkManager:

Note

Interface name <IFNAME> may be different by modules. It should be wlan0 or wlp1s0 usually. The name depends on the driver default when the module is probed.

nmcli device wifi connect <SSID> ifname <IFNAME> password <PASSWD>

nmcli would report the connection result with following log:

Device 'wlan0' successfully activated with 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.

If everything works fine, you should be able to connect to the internet:

# Check if the board is actually connected to the internet.
ping www.google.com

Connect to a Network via wpa_supplicant

Use this method only if you want to avoid using NetworkManager.

First, stop NetworkManager:

systemctl stop NetworkManager.service

To double check that NetworkManager has been stopped:

systemctl status NetworkManager.service

There should be a status log saying: Active: inactive (dead).

Now, configure /etc/wpa_supplicant.conf with this command:

wpa_passphrase <SSID> <PASSWD> > /etc/wpa_supplicant.conf

And then verify the configuration file by running the following command:

cat /etc/wpa_supplicant.conf

The generated content of wpa_supplicant.conf should be similar to this:

network={
    ssid="<SSID>"
    #psk="<PASSWD>"
    psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}

Please add the following to the top of the configuration file for runtime configuration. By adding the following settings, user will be able to use wpa_cli to control the connection at runtime.

update_config=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel

And we also have to configure the DNS server address:

echo "nameserver x.x.x.x " > /etc/resolv.conf

After setting resolv.conf, restart systemd-resolved service:

systemctl restart systemd-resolved.service

Finally, launch wpa_supplicant with new configuration file /etc/wpasupplicant.conf:

wpa_supplicant -B -i <IFNAME> -c /etc/wpa_supplicant.conf

And you should now be able to connect to the internet:

ping www.google.com

Enable WPA3 Client

Note

IoT Yocto enables WPA3 by default. Modification of the configuration or patching of the Wi-Fi drivers should not be necessary. Before you try it, please make sure WPA3 has been enabled properly on the Wi-Fi Access Point.

WPA3 Setting for NetworkManager

If user wants to enable WPA with NetworkManager, simply enable key-mgmt as sae in interface configuration file wifi.nmconnection. The configuration file should be located in /etc/NetworkManager/system-connections folder with .nmconnection filename extension. If the wireless Access Point is configured correctly, the settings should be automatically added by the NetworkManager. However, if the settings are incorrect, you can execute the sed replacement command for the configuration file to enable WPA3.

sudo sed -i -e '/key-mgmt=/s,wpa-psk,sae,' /etc/NetworkManager/system-connections/YOUR_WIFI_CONNECTION.nmconnection

The [wifi-security] section in the .nmconnection file should looks like this.

[wifi-security]
key-mgmt=sae
psk=12345679

WPA3 Setting for wpa_supplicant

If wpa_supplicant is already running, use pkill to terminate it before updating new configurations.

pkill wpa_supplicant

Please add and check the following settings to /etc/wpa_supplicant.conf for enabling WPA3 support with wpa_supplicant. There are some key configurations for WPA3, for example, sae_pwe, key_mgmt, ieee80211w, and psk. The password here should use explicit content instead of encoded hex string.

update_config=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
sae_pwe=0

network={
    ssid="<SSID>"
    psk="<PASSWD>"
    # psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    pairwise=CCMP
    group=CCMP
    key_mgmt=SAE
    ieee80211w=2
}

Finally, launch wpa_supplicant with new configuration file /etc/wpa_supplicant.conf:

wpa_supplicant -B -i <IFNAME> -c /etc/wpa_supplicant.conf

Use wpa_cli to Configure wpa_supplicant

By enabling the following settings, user could use wpa_cli to control wpa_supplicant

update_config=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel

Here are the wpa_cli examples.

wpa_cli -i <IFNAME> remove_network all
wpa_cli -i <IFNAME> add_network
wpa_cli -i <IFNAME> set_network 0 ssid '"<SSID>"'
wpa_cli -i <IFNAME> set_network 0 pairwise CCMP
wpa_cli -i <IFNAME> set_network 0 group CCMP
wpa_cli -i <IFNAME> set_network 0 key_mgmt SAE
wpa_cli -i <IFNAME> set_network 0 psk '"<PASSWD>"'
wpa_cli -i <IFNAME> set sae_pwe 0
wpa_cli -i <IFNAME> set_network 0 ieee80211w 2
wpa_cli -i <IFNAME> enable_network 0
wpa_cli -i <IFNAME> select_network 0
wpa_cli -i <IFNAME> status

SoftAP (Software Enabled Access Point/Hotspot) Mode

SoftAP (Software Enabled Access Point) allows a device to function as a wireless hotspot. This feature enables the device to share its internet connection with nearby devices.

Starting with IoT Yocto v25.0, the MT7921 Module supports SoftAP. However, it does not allow the device to be both an access point and a client simultaneously. Below are the basic features available with the MT7921 Module.

Hotspot On/Off

You can turn the SoftAP feature on or off. Turning it on lets other devices connect to the network you create, while turning it off disconnects all devices and stops the hotspot.

Enable Hotspot

Note

The hostapd (Host Access Point Daemon) is critical for enabling devices to act as a wireless hotspot by managing all wireless settings. By default, its configuration file should usually be located at /etc/hostapd.conf. However, in the following demonstration, we will use the /usr/share/hostapd directory for storing template configurations and for demonstrating various settings.

Enable DHCP Daemon

Important

You must disable NetworkManager before enabling SoftAP.

systemctl stop NetworkManager
systemctl disable NetworkManager

Enable the DHCP server to assign IP addresses to clients when they connect to the SoftAP. Set up the DHCP daemon by configuring udhcpd.conf as shown:

start           192.168.1.20
end             192.168.1.254
interface       wlp1s0
option subnet   255.255.255.0

Activate the Wi-Fi interface and set its IP address within the DHCP range.

ifconfig wlp1s0 up
ifconfig wlp1s0 192.168.1.1

Enable the DHCP server.

udhcpd -f /etc/udhcpd.conf &

Note

If you see the error: udhcpd: can’t open /var/lib/misc/udhcpd.leases: No such file or directory Run this command: touch /var/lib/misc/udhcpd.leases

Enable SoftAP with VHT80 Bandwidth on the 5GHz Band

Create a configuration file /usr/share/hostapd/hostapd5_wpa3_80M.conf for hostapd to set up SoftAP with VHT80 bandwidth on the 5GHz band.

mkdir -p /usr/share/hostapd
touch /usr/share/hostapd/hostapd5_wpa3_80M.conf
chmod 644 /usr/share/hostapd/hostapd5_wpa3_80M.conf

Add the following settings to /usr/share/hostapd/hostapd5_wpa3_80M.conf:

Note

Caution: Consider replacing the default ssid and wpa_passphrase for production environments.

interface=wlp1s0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
channel=36
vht_oper_centr_freq_seg0_idx=42
country_code=CN
beacon_int=100
macaddr_acl=0
wpa=2
wpa_pairwise=CCMP
wpa_key_mgmt=SAE WPA-PSK
vht_capab=[SHORT-GI-80]
eap_server=1
require_vht=1
wps_state=2
ap_setup_locked=1
config_methods=virtual_display virtual_push_button keypad
hw_mode=a
ieee80211n=1
ht_capab=[HT40-][HT40+][SHORT-GI-20][SHORT-GI-40]
ieee80211ac=1
vht_oper_chwidth=1
ieee80211ax=0
ssid=SAP_5_wpa2_3_80M
wpa_passphrase=12345678

Activate the SoftAP.

hostapd -dd /usr/share/hostapd/hostapd5_wpa3_80M.conf &
sleep 5; # Wait for 5 seconds for the service to be ready.

After activation, hostapd should display messages indicating successful setup:

wlp1s0: interface state COUNTRY_UPDATE-> ENABLED
wlp1s0: AP-ENABLED
wlp1s0: Setup of interface done.
Connect Station (Client) Device to SoftAP

Use another Genio EVK with NetworkManager to connect.

nmcli device wifi rescan
nmcli device wifi connect SAP_5_wpa2_3_80M ifname wlp1s0 password 12345678

Once connected, observe messages showing IP assignment:

udhcpd: sending OFFER to 192.168.1.20
udhcpd: sending OFFER to 192.168.1.20
udhcpd: sending ACK to 192.168.1.20

Try ping 192.168.1.1 to test the connection.

Disable Hotspot

To disable SoftAP, simply run:

killall hostapd
sleep 5; # Wait for 5 seconds for the service to stop.

The following message indicates the SoftAP has been disabled:

wlp1s0: interface state ENABLED->DISABLED

Operating on Different Band

You can switch between 2.4 GHz and 5 GHz bands to optimize network performance based on device compatibility and environmental conditions.

The examples below assume the Wi-Fi interface is active and udhcpd is running. Check: Enable DHCP Daemon. Stop any current SoftAP services before starting new ones: Disable Hotspot.

Enable SoftAP on 2.4GHz Band

Set up a SoftAP using hostapd on the 2.4 GHz band. Create a configuration file /usr/share/hostapd/hostapd24_wpa3.conf for hostapd.

mkdir -p /usr/share/hostapd
touch /usr/share/hostapd/hostapd24_wpa3.conf
chmod 644 /usr/share/hostapd/hostapd24_wpa3.conf

Add the following settings to /usr/share/hostapd/hostapd24_wpa3.conf:

Note

Caution: Consider replacing the default ssid and wpa_passphrase for production environments.

interface=wlp1s0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
channel=6
country_code=CN
beacon_int=100
macaddr_acl=0
wpa=2
wpa_key_mgmt=SAE
ieee80211w=2
wpa_pairwise=CCMP
wpa_group_rekey=86400
vht_capab=[SHORT-GI-80]
eap_server=1
require_vht=1
wps_state=2
ap_setup_locked=1
config_methods=virtual_display virtual_push_button keypad
hw_mode=g
ieee80211n=1
ht_capab=[SHORT-GI-20]
ieee80211ac=0
vht_oper_chwidth=0
ieee80211ax=0
ssid=SAP_24_wpa3
wpa_passphrase=12345678

Activate the SoftAP.

hostapd -dd /usr/share/hostapd/hostapd24_wpa3.conf &
sleep 5; # Wait for 5 seconds for the service to be ready.

After activation, hostapd should display messages indicating successful setup:

wlp1s0: interface state COUNTRY_UPDATE-> ENABLED
wlp1s0: AP-ENABLED
wlp1s0: Setup of interface done.
Connect Station (Client) Device to SoftAP

If using a smartphone, find the hotspot SAP_24_wpa3 and connect (password: 12345678).

Alternatively, use another Genio EVK with NetworkManager.

nmcli device wifi rescan
nmcli device wifi connect SAP_24_wpa3 ifname wlp1s0 password 12345678

After connecting, observe IP assignment messages:

udhcpd: sending OFFER to 192.168.1.20
udhcpd: sending OFFER to 192.168.1.20
udhcpd: sending ACK to 192.168.1.20

Try ping 192.168.1.1 to test the connection.

Enable SoftAP on 5GHz Band

Set up a SoftAP using hostapd on the 5 GHz band. Create a configuration file /usr/share/hostapd/hostapd5_wpa3.conf for hostapd.

mkdir -p /usr/share/hostapd
touch /usr/share/hostapd/hostapd5_wpa3.conf
chmod 644 /usr/share/hostapd/hostapd5_wpa3.conf

Add the following settings to /usr/share/hostapd/hostapd5_wpa3.conf:

Note

Caution: Consider replacing the default ssid and wpa_passphrase for production environments.

interface=wlp1s0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
channel=36
country_code=CN
beacon_int=100
macaddr_acl=0
wpa=2
wpa_key_mgmt=SAE
ieee80211w=2
wpa_pairwise=CCMP
wpa_group_rekey=86400
vht_capab=[SHORT-GI-80]
eap_server=1
require_vht=1
wps_state=2
ap_setup_locked=1
config_methods=virtual_display virtual_push_button keypad
hw_mode=a
ieee80211n=1
ht_capab=[SHORT-GI-20]
ieee80211ac=1
vht_oper_chwidth=0
ieee80211ax=0
ssid=SAP_5G_wpa3
wpa_passphrase=12345678

Activate the SoftAP.

hostapd -dd /usr/share/hostapd/hostapd5_wpa3.conf &
sleep 5; # Wait for 5 seconds for the service to be ready.

After activation, hostapd should display messages indicating successful setup:

wlp1s0: interface state COUNTRY_UPDATE-> ENABLED
wlp1s0: AP-ENABLED
wlp1s0: Setup of interface done.
Connect Station (Client) Device to SoftAP

If you’re using a smartphone to connect to SoftAP, look for the hotspot SAP_5G_wpa3 and connect (password: 12345678).

You can also use another Genio EVK with NetworkManager.

nmcli device wifi rescan
nmcli device wifi connect SAP_5G_wpa3 ifname wlp1s0 password 12345678

Once connected, observe messages showing IP assignment:

udhcpd: sending OFFER to 192.168.1.20
udhcpd: sending OFFER to 192.168.1.20
udhcpd: sending ACK to 192.168.1.20

Try ping 192.168.1.1 to test the connection.

Reference Boards

Wi-Fi on different platforms may have some platform-specific instructions or test results. For example, you will get different benchmark results on different platforms. Please find more details about difference of Wi-Fi on each platform: