Wifi NetworkManager: Difference between revisions

From Variscite Wiki
(Add Debian_Platform_Customization)
(33 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<!-- Set release according to "release" parameter in URL and use RELEASE_SUMO_V1.0_DART-MX8M as default
<!-- Set release according to "release" parameter in URL and use RELEASE_SUMO_V1.0_DART-MX8M as default
--> {{#vardefine:RELEASE_PARAM|{{#urlget:release}}}} <!--
--> {{INIT_RELEASE_PARAM|RELEASE_SUMO_V1.0_DART-MX8M}}<!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM|RELEASE_SUMO_V1.0_DART-MX8M}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{PageHeader|Wireless}}  
--> {{PageHeader|Wireless}}  
{{DocImage|category1=Yocto|category2=DART-MX8M}}[[Category:DART-MX8M-MINI]] __toc__
{{DocImage|category1=Yocto|category2=Debian}}[[Category:DART-MX8M]][[Category:DART-MX8M-MINI]][[Category:DART-MX8M-PLUS]] __toc__


= Managing WiFi using NetworkManager =
= Managing WiFi using NetworkManager =
NetworkManager is a program for providing detection and configuration for systems to automatically connect to network.<br>
NetworkManager's functionality can be useful for both wireless and wired networks.<br>
This guide describes how to use NetworkManager to configure wireless networks.


== Enabling and disabling WiFi ==
== Enabling and disabling WiFi ==
Line 22: Line 27:
  # nmcli radio wifi off
  # nmcli radio wifi off


== Scanning for available WiFi APs ==
== Configuring WiFi Client ==
=== Scanning for available WiFi APs ===


If WiFi is enabled you can get the list of available APs by running
If WiFi is enabled you can get the list of available APs by running
Line 28: Line 34:
  # nmcli dev wifi list
  # nmcli dev wifi list


== Connecting to an open WiFi network ==
=== Connecting to an open WiFi network ===


To connect to an open WiFi network run
To connect to an open WiFi network run
Line 37: Line 43:


To check connection status run  
To check connection status run  
# nmcli con show <SSID>
To check WiFi device status run


  # nmcli dev show wlan0
  # nmcli dev show wlan0


== Connecting to a protected WiFi network ==
=== Connecting to a protected WiFi network ===


To connect to a protected WiFi network run
To connect to a protected WiFi network run
  # nmcli dev wifi connect <SSID> password <password>
  # nmcli dev wifi connect <SSID> password <password> ifname wlan0


To connect to a protected hidden WiFi network run
To connect to a protected hidden WiFi network run
  # nmcli dev wifi connect <SSID> password <password> hidden yes
  # nmcli dev wifi connect <SSID> password <password> hidden yes ifname wlan0


To check connection status run  
To check connection status run  
# nmcli con show <SSID>
To check WiFi device status run


  # nmcli dev show wlan0
  # nmcli dev show wlan0


== Managing existing connections ==
=== Managing existing connections ===


Once established, the connection is preserved across reboots unless deleted explicitly.  
Once established, the connection is preserved across reboots unless deleted explicitly.  


To show existing connections run
To show existing connections, run


  # nmcli con show
  # nmcli con show


To disconnect from WiFi network run
To disconnect from a WiFi network, run
   
   
  # nmcli con down <SSID>
  # nmcli con down <SSID>


To reconnect to WiFi network run
To reconnect to a WiFi network, run


  # nmcli con up <SSID>
  # nmcli con up <SSID>


To permanently delete connection run
To permanently delete a connection, run


  # nmcli con delete <SSID>
  # nmcli con delete <SSID>
== Configuring WiFi Access Point ==
NetworkManager can also be used to turn WiFi interface into Access Point.<br>
The benefit of using NetworkManager in this scenario is the complete automation of WiFi, DHCP server and NAT configuration.
=== Disabling standalone dnsmasq service ===
Dnsmasq is a lightweight DNS forwarder and DHCP server.<br>
By default dnsmasq runs as a standalone service and will conflict with dnsmasq instance launched by NetworkManager.<br>
To prevent the conflict, disable dnsmasq service by running the following commands:
<pre>
# systemctl disable dnsmasq
# systemctl stop dnsmasq
</pre>
For NetworkManager to run dnsmasq as a local caching DNS server, edit/create /etc/NetworkManager/NetworkManager.conf and add the following
<pre>
[main]
dns=dnsmasq
</pre>
=== Creating WiFi AP ===
Use the following commands to create the initial AP setup
<pre>
# nmcli con add type wifi ifname wlan0 mode ap con-name <name> ssid <ssid>
# nmcli con modify <name> 802-11-wireless.band <band>
# nmcli con modify <name> 802-11-wireless.channel <channel>
# nmcli con modify <name> 802-11-wireless-security.key-mgmt <key-mgmt>
# nmcli con modify <name> 802-11-wireless-security.proto <proto>
# nmcli con modify <name> 802-11-wireless-security.group <group>
# nmcli con modify <name> 802-11-wireless-security.pairwise <pairwise>
# nmcli con modify <name> 802-11-wireless-security.psk <passphrase>
# nmcli con modify <name> ipv4.method shared
# nmcli con up <name>
</pre>
For example, the following commands will create AP configuration named WIFI_AP on interface wlan0, with SSID MY_AP, 2.4GHz band, channel 1, WPA2-PSK security, CCMP encryption and passphrase 11223344
<pre>
# nmcli con add type wifi ifname wlan0 mode ap con-name WIFI_AP ssid MY_AP
# nmcli con modify WIFI_AP 802-11-wireless.band bg
# nmcli con modify WIFI_AP 802-11-wireless.channel 1
# nmcli con modify WIFI_AP 802-11-wireless-security.key-mgmt wpa-psk
# nmcli con modify WIFI_AP 802-11-wireless-security.proto rsn
# nmcli con modify WIFI_AP 802-11-wireless-security.group ccmp
# nmcli con modify WIFI_AP 802-11-wireless-security.pairwise ccmp
# nmcli con modify WIFI_AP 802-11-wireless-security.psk 11223344
# nmcli con modify WIFI_AP ipv4.method shared
# nmcli con up WIFI_AP
</pre>
If you are planning to use the 5 GHz band and channel 36, you can partially change the above commands as follow
<pre>
...
# nmcli con modify WIFI_AP 802-11-wireless.band a
# nmcli con modify WIFI_AP 802-11-wireless.channel 36
...
</pre>
The complete list of nmcli configuration parameters is described in https://developer.gnome.org/NetworkManager/stable/ref-settings.html
=== Configuring DHCP subnet ===
By default 10.42.0.x/24 subnet is used by NetworkManager DHCP server, with 10.42.0.1 address assigned to AP itself. To modify it use the following command
# nmcli con modify <name> ipv4.addr <ipaddress/prefix>
For example, the following command will set DHCP subnet to 192.168.5.x/24
# nmcli con modify WIFI_AP ipv4.addr 192.168.5.1/24
=== Editing AP configuration file ===
NetworkManager will create /etc/NetworkManager/system-connections/WIFI_AP configuration file.<br>
In addition to executing nmcli commands one can also edit this file to modify the AP settings.<br>
For changes in configuration file to take effect, restart NetworkManager by running
# systemctl NetworkManager restart
=== Managing existing connections ===
Once created, the AP configuration is preserved across reboots unless deleted explicitly.
To show existing connections, run
# nmcli con show
To temporarily disable AP configuration, run
# nmcli con down <name>
To enable AP configuration, run
# nmcli con up <name>
To permanently delete AP configuration, run
# nmcli con delete <name>
== WiFi STA/AP concurrency ==
To get the WiFi module to work in concurrent AP-STA mode, a virtual wireless interface is required.
This can be achieved creating a virtual ''wlan1'' interface, running
# iw dev wlan0 interface add wlan1 type __ap
STA setup can be managed simply following the steps described in [[Wifi_NetworkManager#Configuring_WiFi_Client|Configuring WiFi Client]] section.
AP setup can be managed following the steps described in [[Wifi_NetworkManager#Configuring_WiFi_Access_Point|Configuring WiFi Access Point]] section, but when creating the access point, be careful to use wlan1 instead of wlan0.
=== Notes ===
nmcli commands create a permanent setup, that does not require to be repeated at every boot.
However, the ''iw'' command (used to create the virtual wlan1 interface) does not create permanent changes: we suggest to introduce it in the variscite-wifi script (located in /etc/wifi for latest releases), when checking for the wlan0 existance, something like
<syntaxhighlight lang="bash">
if [ -d /sys/class/net/wlan0 ]; then
# create wlan1 interface
iw dev wlan0 interface add wlan1 type __ap
return 0
else
...
</syntaxhighlight>
Also, in the same file, just before shutting down wlan0, you may want to delete this virtual interface, something like
<syntaxhighlight lang="bash">
...
# delete wlan1 interface
iw dev wlan1 del
# Down WIFI
wifi_down
...
</syntaxhighlight>
=== Limitations ===
By HW design, Sterling-LWB/LWB5 WiFi modules provide a single channel tuner.
AP-STA operations are possible, but the local AP channel is actually the one negotiated between the local client and the remote AP.


= Testing WiFi throughput =
= Testing WiFi throughput =
Line 87: Line 244:
  # iperf3 -c <IP_ADDRESS_OF_IPERF_SERVER> -t 30
  # iperf3 -c <IP_ADDRESS_OF_IPERF_SERVER> -t 30


= Access Point =
= Configuring WiFi Regulatory Domain =
Following example will demonstrate you how to use the target as an access point. It will forward packets from wlan0 to eth0.
According the mounting option of the SoM in use, the kernel loads dedicated firmware files from the folder /lib/firmware/brcm:
Setting up DHCP server DHCPD
 
DHCPD:
{| class="wikitable" style="text-align: center;"
<pre>$ vi /etc/udhcpd.conf
! mounting option
# Sample udhcpd configuration file (/etc/udhcpd.conf)
! WiFi chip
# The start and end of the IP lease block
! firmware files
start          192.168.5.20    #default: 192.168.0.20
|-
end            192.168.5.25    #default: 192.168.0.254
| WB
# The interface that udhcpd will use
| [https://www.lairdconnect.com/wireless-modules/wifi-modules-bluetooth/sterling-lwb-24-ghz-wifi-module Sterling LWB]
interface  wlan0              #default: eth0
| brcmfmac43430-sdio.bin / brcmfmac43430-sdio.txt
#Example
|-
opt    dns    8.8.8.8  8.8.4.4 # public google dns servers
| WBD
option  subnet  255.255.255.0
| [https://www.lairdconnect.com/wireless-modules/wifi-modules-bluetooth/sterling-lwb5-dual-band-wifi-module-bluetooth-42 Sterling LWB5]
opt    router  192.168.5.1
| brcmfmac4339-sdio.bin / brcmfmac4339-sdio.txt
option  lease  864000          # 10 days of seconds
|}
</pre>
 
This is a network example. You need to set the IP address based on your network.  
Each txt file contains the ''ccode'' parameter selecting the regulatory domain.
<br>Make sure WiFi is turned on and Ethernet is connected as per previous steps above before proceeding.
 
<br>First ensure that wpa_supplicant is not holding the device
Additionally, for Sterling LWB5 only, the ''regrev'' parameter must change according the ccode (it's always zero for Sterling LWB).
<pre>$ killall wpa_supplicant
 
</pre>
By default, the BSP ships firmware configurations matching FCC Regulatory Domain, one of the most restrictive in terms of available channels.
Enable IP Forwarding:
 
<pre>$ echo 1 > /proc/sys/net/ipv4/ip_forward
For Sterling LWB5 and FCC you can read
$ ifconfig wlan0 192.168.5.1
 
$ hostapd -B /etc/hostapd.conf -P /var/run/hostapd.pid
ccode=US
$ udhcpd /etc/udhcpd.conf
regrev=911
$ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 
</pre>
The following table reports the valid options for ccode / regrev parameter.
Using your phone or other device connect to the access point named "test" created using the steps above. <br>
 
You should be able to connect and access the internet if your Ethernet has access. <br>
{| class="wikitable" style="text-align: center;"
As a next step one should take a look at /etc/hostapd.conf. You may want to configure password access point name etc. <br>
! rowspan=2 | regulatory<br>authority
* For more details refer to: https://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf <br>
! colspan=2 | Sterling LWB
! colspan=2 | Sterling LWB5
|-
! ccode
! regrev
! ccode
! regrev
|-
| [https://www.fcc.gov/ FCC]
| US
| 0
| US
| 911
|-
| [https://www.etsi.org/ ETSI]
| EU
| 0
| EU
| 116
|-
| [https://www.ic.gc.ca/ ISED]
| US*
| 0
| CA
| 938
|-
| [https://www.soumu.go.jp/english/ MIC]
| JP
| 0
| JP
| 101
|}
<nowiki>*</nowiki> ISED for Sterling LWB is managed using ''ccode=US'', it's not a typo.
{{#ifexpr: {{#rpos: {{#var:MACHINE_NAME}} | var-som-mx6}} < 0 and {{#rpos: {{#var:MACHINE_NAME}} | imx8mn-var-som}} < 0 |                    <!-- if not var-som-mx6 and not var-som-mx8m-nano -->
= Note on {{#var:HARDWARE_NAME}} WiFi Initialization =
 
<p>WiFi is initialized by '''/etc/wifi/variscite-wifi'''. During initialization, the Linux device tree '''model''' property is read from '''/sys/devices/soc0/machine''' and is used to
determine the Variscite SOM model and configure the SoM GPIO pins.</p>
{{#ifexpr: {{#rpos: {{#var:MACHINE_NAME}} | imx8mq-var-dart}} >= 0 or {{#rpos: {{#var:MACHINE_NAME}} | imx8m-var-dart}} >= 0 or {{#rpos: {{#var:MACHINE_NAME}} | imx8qxp-var-som}} >= 0 |  <!-- if imx8mq-var-dart or imx8qxp-var-som -->
<p>Additionally, on the {{#var:HARDWARE_NAME}}, the WiFi and the SD card share the same SDIO controller and therefore cannot be used simultaneously. The WiFi script looks for a "WIFI" sub-string to determine whether or not the WiFi device tree was selected.</p>
}}
<p>Therefore, customers who choose to modify the Linux device tree '''model''' property should only append to the string provided by Variscite.</p><br>
|}}

Revision as of 15:35, 7 February 2023

Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release RELEASE_SUMO_V1.0_DART-MX8M.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release
Wireless

Managing WiFi using NetworkManager

NetworkManager is a program for providing detection and configuration for systems to automatically connect to network.
NetworkManager's functionality can be useful for both wireless and wired networks.
This guide describes how to use NetworkManager to configure wireless networks.

Enabling and disabling WiFi

To check if WiFi is enabled by NetworkManager run

# nmcli dev show wlan0

and check the GENERAL.STATE line. If WiFi is enabled, the state is either connected or disconnected. If WiFi is disabled the state is unavailable.

To enable WiFi run

# nmcli radio wifi on

or if you need to disable it you can run

# nmcli radio wifi off

Configuring WiFi Client

Scanning for available WiFi APs

If WiFi is enabled you can get the list of available APs by running

# nmcli dev wifi list

Connecting to an open WiFi network

To connect to an open WiFi network run

# nmcli dev wifi connect <SSID>

To connect to an open hidden WiFi network run

# nmcli dev wifi connect <SSID> hidden yes

To check connection status run

# nmcli con show <SSID>

To check WiFi device status run

# nmcli dev show wlan0

Connecting to a protected WiFi network

To connect to a protected WiFi network run

# nmcli dev wifi connect <SSID> password <password> ifname wlan0

To connect to a protected hidden WiFi network run

# nmcli dev wifi connect <SSID> password <password> hidden yes ifname wlan0

To check connection status run

# nmcli con show <SSID>

To check WiFi device status run

# nmcli dev show wlan0

Managing existing connections

Once established, the connection is preserved across reboots unless deleted explicitly.

To show existing connections, run

# nmcli con show

To disconnect from a WiFi network, run

# nmcli con down <SSID>

To reconnect to a WiFi network, run

# nmcli con up <SSID>

To permanently delete a connection, run

# nmcli con delete <SSID>

Configuring WiFi Access Point

NetworkManager can also be used to turn WiFi interface into Access Point.
The benefit of using NetworkManager in this scenario is the complete automation of WiFi, DHCP server and NAT configuration.

Disabling standalone dnsmasq service

Dnsmasq is a lightweight DNS forwarder and DHCP server.
By default dnsmasq runs as a standalone service and will conflict with dnsmasq instance launched by NetworkManager.
To prevent the conflict, disable dnsmasq service by running the following commands:

# systemctl disable dnsmasq
# systemctl stop dnsmasq

For NetworkManager to run dnsmasq as a local caching DNS server, edit/create /etc/NetworkManager/NetworkManager.conf and add the following

[main]
dns=dnsmasq

Creating WiFi AP

Use the following commands to create the initial AP setup

# nmcli con add type wifi ifname wlan0 mode ap con-name <name> ssid <ssid>
# nmcli con modify <name> 802-11-wireless.band <band>
# nmcli con modify <name> 802-11-wireless.channel <channel>
# nmcli con modify <name> 802-11-wireless-security.key-mgmt <key-mgmt>
# nmcli con modify <name> 802-11-wireless-security.proto <proto>
# nmcli con modify <name> 802-11-wireless-security.group <group>
# nmcli con modify <name> 802-11-wireless-security.pairwise <pairwise>
# nmcli con modify <name> 802-11-wireless-security.psk <passphrase>
# nmcli con modify <name> ipv4.method shared
# nmcli con up <name>

For example, the following commands will create AP configuration named WIFI_AP on interface wlan0, with SSID MY_AP, 2.4GHz band, channel 1, WPA2-PSK security, CCMP encryption and passphrase 11223344

# nmcli con add type wifi ifname wlan0 mode ap con-name WIFI_AP ssid MY_AP
# nmcli con modify WIFI_AP 802-11-wireless.band bg
# nmcli con modify WIFI_AP 802-11-wireless.channel 1
# nmcli con modify WIFI_AP 802-11-wireless-security.key-mgmt wpa-psk
# nmcli con modify WIFI_AP 802-11-wireless-security.proto rsn
# nmcli con modify WIFI_AP 802-11-wireless-security.group ccmp
# nmcli con modify WIFI_AP 802-11-wireless-security.pairwise ccmp
# nmcli con modify WIFI_AP 802-11-wireless-security.psk 11223344
# nmcli con modify WIFI_AP ipv4.method shared
# nmcli con up WIFI_AP

If you are planning to use the 5 GHz band and channel 36, you can partially change the above commands as follow

...
# nmcli con modify WIFI_AP 802-11-wireless.band a
# nmcli con modify WIFI_AP 802-11-wireless.channel 36
...

The complete list of nmcli configuration parameters is described in https://developer.gnome.org/NetworkManager/stable/ref-settings.html

Configuring DHCP subnet

By default 10.42.0.x/24 subnet is used by NetworkManager DHCP server, with 10.42.0.1 address assigned to AP itself. To modify it use the following command

# nmcli con modify <name> ipv4.addr <ipaddress/prefix>

For example, the following command will set DHCP subnet to 192.168.5.x/24

# nmcli con modify WIFI_AP ipv4.addr 192.168.5.1/24

Editing AP configuration file

NetworkManager will create /etc/NetworkManager/system-connections/WIFI_AP configuration file.
In addition to executing nmcli commands one can also edit this file to modify the AP settings.

For changes in configuration file to take effect, restart NetworkManager by running

# systemctl NetworkManager restart

Managing existing connections

Once created, the AP configuration is preserved across reboots unless deleted explicitly.

To show existing connections, run

# nmcli con show

To temporarily disable AP configuration, run

# nmcli con down <name>

To enable AP configuration, run

# nmcli con up <name>

To permanently delete AP configuration, run

# nmcli con delete <name>

WiFi STA/AP concurrency

To get the WiFi module to work in concurrent AP-STA mode, a virtual wireless interface is required.

This can be achieved creating a virtual wlan1 interface, running

# iw dev wlan0 interface add wlan1 type __ap

STA setup can be managed simply following the steps described in Configuring WiFi Client section.

AP setup can be managed following the steps described in Configuring WiFi Access Point section, but when creating the access point, be careful to use wlan1 instead of wlan0.

Notes

nmcli commands create a permanent setup, that does not require to be repeated at every boot.

However, the iw command (used to create the virtual wlan1 interface) does not create permanent changes: we suggest to introduce it in the variscite-wifi script (located in /etc/wifi for latest releases), when checking for the wlan0 existance, something like

if [ -d /sys/class/net/wlan0 ]; then
	# create wlan1 interface
	iw dev wlan0 interface add wlan1 type __ap
	return 0
else
	...

Also, in the same file, just before shutting down wlan0, you may want to delete this virtual interface, something like

...
# delete wlan1 interface
iw dev wlan1 del
# Down WIFI
wifi_down
...

Limitations

By HW design, Sterling-LWB/LWB5 WiFi modules provide a single channel tuner.

AP-STA operations are possible, but the local AP channel is actually the one negotiated between the local client and the remote AP.

Testing WiFi throughput

Establish connection to WiFi network and use iperf3 tool on target and another host:

iperf3 server (on Target/Host):

# iperf3 -s

iperf3 client (on Host/Target):

Run UDP test for 30 seconds
# iperf3 -c <IP_ADDRESS_OF_IPERF_SERVER> -t 30 -u -b 0
Run TCP test for 30 seconds
# iperf3 -c <IP_ADDRESS_OF_IPERF_SERVER> -t 30

Configuring WiFi Regulatory Domain

According the mounting option of the SoM in use, the kernel loads dedicated firmware files from the folder /lib/firmware/brcm:

mounting option WiFi chip firmware files
WB Sterling LWB brcmfmac43430-sdio.bin / brcmfmac43430-sdio.txt
WBD Sterling LWB5 brcmfmac4339-sdio.bin / brcmfmac4339-sdio.txt

Each txt file contains the ccode parameter selecting the regulatory domain.

Additionally, for Sterling LWB5 only, the regrev parameter must change according the ccode (it's always zero for Sterling LWB).

By default, the BSP ships firmware configurations matching FCC Regulatory Domain, one of the most restrictive in terms of available channels.

For Sterling LWB5 and FCC you can read

ccode=US
regrev=911

The following table reports the valid options for ccode / regrev parameter.

regulatory
authority
Sterling LWB Sterling LWB5
ccode regrev ccode regrev
FCC US 0 US 911
ETSI EU 0 EU 116
ISED US* 0 CA 938
MIC JP 0 JP 101

* ISED for Sterling LWB is managed using ccode=US, it's not a typo.

Note on DART-MX8M WiFi Initialization

WiFi is initialized by /etc/wifi/variscite-wifi. During initialization, the Linux device tree model property is read from /sys/devices/soc0/machine and is used to determine the Variscite SOM model and configure the SoM GPIO pins.

Additionally, on the DART-MX8M, the WiFi and the SD card share the same SDIO controller and therefore cannot be used simultaneously. The WiFi script looks for a "WIFI" sub-string to determine whether or not the WiFi device tree was selected.

Therefore, customers who choose to modify the Linux device tree model property should only append to the string provided by Variscite.