OpenWRT under hood
Posted on July 8, 2024 • 3 minutes • 543 words
Table of contents
Wireless configuration
Behind the scenes, UCI (Unified Configuration Interface) in OpenWRT uses various command-line utilities and services to apply the wireless configurations defined in /etc/config/wireless. Here are some key components and commands involved in this process:
- netifd:
- The
netifd(network interface daemon) is responsible for managing network interfaces in OpenWRT. It handles the configuration of interfaces based on the UCI configuration files.
- hostapd and wpa_supplicant:
- OpenWRT typically uses
hostapdfor managing Access Point (AP) interfaces andwpa_supplicantfor client interfaces. These services are controlled and configured bynetifdbased on the UCI settings.
- iw and ip commands:
netifdusesiwto configure wireless devices and interfaces. It also usesipto manage network interfaces at a lower level.
Example Workflow
When you configure an SSID in /etc/config/wireless and run wifi reload, the following steps typically occur:
- netifd reads the UCI configuration:
netifdparses the/etc/config/wirelessfile to understand the desired configuration for wireless interfaces.
- netifd interacts with
hostapdorwpa_supplicant:
- If you are configuring an AP,
netifdwill generate ahostapdconfiguration file based on the UCI settings and start/reloadhostapdwith this configuration. - For client interfaces, it will do the same with
wpa_supplicant.
- Use of
iwandipcommands:
netifdusesiwcommands to set up the physical and virtual wireless interfaces. For example, it usesiw devto list interfaces,iw phyto configure physical wireless settings, andiw dev interface setto configure specific settings for a virtual interface.ipcommands are used to bring interfaces up or down, set IP addresses, and configure other network parameters.
Example Commands Used by netifd
For a given wireless interface setup, the following types of commands might be used:
-
Bringing up an interface:
ip link set dev phy0-ap2 up -
Setting SSID and other wireless parameters (via
iw):iw dev phy0-ap2 set type __ap iw dev phy0-ap2 set ssid YourNewSSID iw dev phy0-ap2 set channel 6 -
Starting
hostapdwith a generated configuration:hostapd /var/run/hostapd-phy0.conf
Example Configuration and Commands
Here is a more detailed look at how you might see these processes play out:
- Configuration in
/etc/config/wireless:
config wifi-device 'radio0'
option type 'mac80211'
option channel '6'
option hwmode '11g'
config wifi-iface
option device 'radio0'
option network 'lan'
option mode 'ap'
option ssid 'YourSSID'
option encryption 'psk2'
option key 'YourPassphrase'
option ifname 'phy0-ap2'
netifdgenerateshostapdconfiguration:
interface=phy0-ap2
driver=nl80211
ssid=YourSSID
hw_mode=g
channel=6
auth_algs=1
wpa=2
wpa_passphrase=YourPassphrase
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
- Commands executed by
netifd:
ip link set dev phy0-ap2 up
iw dev phy0-ap2 set ssid YourSSID
iw dev phy0-ap2 set channel 6
hostapd /var/run/hostapd-phy0.conf
An example of real wifi config
cat /etc/config/wireless
config wifi-device 'radio0'
option type 'mac80211'
option path 'platform/soc/18000000.wifi'
option channel '1'
option band '2g'
option htmode 'HE20'
option disabled '0'
option country 'US'
config wifi-iface 'default_radio0'
option device 'radio0'
option network 'lan'
option mode 'ap'
option ssid 'tuf-ax4200-2g-0-0'
option encryption 'psk2'
option key '12345678'
option ifname 'vif0'
config wifi-iface 'vif1_radio0'
option device 'radio0'
option network 'lan'
option mode 'ap'
option ssid 'tuf-ax4200-2g-0-1'
option encryption 'psk2'
option key '12345678'
option ifname 'vif1'
config wifi-device 'radio1'
option type 'mac80211'
option path 'platform/soc/18000000.wifi+1'
option channel '36'
option band '5g'
option htmode 'HE80'
option disabled '0'
option country 'US'
config wifi-iface 'default_radio1'
option device 'radio1'
option network 'lan'
option mode 'ap'
option ssid 'tuf-ax4200-5g-1'
option encryption 'psk2'
option key '12345678'
Share
Tags
Counters