Scripting: how to iterate over all WiFi devices?

I want to iterate over all the wifi interfaces on my device.

uci show wireless gives me this:

wireless.radio0=wifi-device
wireless.radio0.type='mac80211'
wireless.radio0.path='soc/1b500000.pci/pci0000:00/0000:00:00.0/0000:01:00.0'
wireless.radio0.band='5g'
wireless.radio0.htmode='VHT80'
wireless.radio0.cell_density='0'
wireless.radio0.country='US'
wireless.radio0.channel='144'
wireless.default_radio0=wifi-iface
wireless.default_radio0.device='radio0'
wireless.default_radio0.mode='ap'
wireless.default_radio0.key='private'
wireless.default_radio0.network='LAN100'
wireless.default_radio0.ieee80211r='1'
wireless.default_radio0.mobility_domain='123a'
wireless.default_radio0.ft_over_ds='0'
wireless.default_radio0.ft_psk_generate_local='1'
wireless.default_radio0.wpa_disable_eapol_key_retries='1'
wireless.default_radio0.disassoc_low_ack='0'
wireless.default_radio0.ssid='NETB'
wireless.default_radio0.ieee80211w='0'
wireless.default_radio0.encryption='psk2+ccmp'
wireless.default_radio0.bss_transition='1'
wireless.default_radio0.wnm_sleep_mode='1'
wireless.default_radio0.time_advertisement='2'
wireless.default_radio0.time_zone='EST5EDT'
wireless.default_radio0.ieee80211k='1'
wireless.default_radio0.rrm_neighbor_report='1'
wireless.default_radio0.rrm_beacon_report='1'
wireless.default_radio0.skip_inactivity_poll='1'
wireless.default_radio0.dtim_period='2'
wireless.radio1=wifi-device
wireless.radio1.type='mac80211'
wireless.radio1.path='soc/1b700000.pci/pci0001:00/0001:00:00.0/0001:01:00.0'
wireless.radio1.band='2g'
wireless.radio1.cell_density='0'
wireless.radio1.channel='11'
wireless.radio1.htmode='HT20'
wireless.radio1.country='US'
wireless.radio1.txpower='19'
wireless.default_radio1=wifi-iface
wireless.default_radio1.device='radio1'
wireless.default_radio1.mode='ap'
wireless.default_radio1.ssid='NETB'
wireless.default_radio1.key='private'
wireless.default_radio1.network='LAN100'
wireless.default_radio1.ieee80211r='1'
wireless.default_radio1.mobility_domain='123a'
wireless.default_radio1.ft_over_ds='0'
wireless.default_radio1.ft_psk_generate_local='1'
wireless.default_radio1.wpa_disable_eapol_key_retries='1'
wireless.default_radio1.ieee80211w='0'
wireless.default_radio1.encryption='psk2+ccmp'
wireless.default_radio1.bss_transition='1'
wireless.default_radio1.wnm_sleep_mode='1'
wireless.default_radio1.time_advertisement='2'
wireless.default_radio1.time_zone='EST5EDT'
wireless.default_radio1.ieee80211k='1'
wireless.default_radio1.rrm_neighbor_report='1'
wireless.default_radio1.rrm_beacon_report='1'
wireless.default_radio1.dtim_period='2'
wireless.default_radio1.skip_inactivity_poll='1'
wireless.default_radio1.disassoc_low_ack='0'
wireless.wifinet2=wifi-iface
wireless.wifinet2.device='radio0'
wireless.wifinet2.mode='ap'
wireless.wifinet2.network='CHILDSAFE'
wireless.wifinet2.key='private'
wireless.wifinet2.ieee80211r='1'
wireless.wifinet2.mobility_domain='123a'
wireless.wifinet2.ft_over_ds='0'
wireless.wifinet2.ft_psk_generate_local='1'
wireless.wifinet2.wpa_disable_eapol_key_retries='1'
wireless.wifinet2.disassoc_low_ack='0'
wireless.wifinet2.ssid='NETK'
wireless.wifinet2.encryption='psk2+ccmp'
wireless.wifinet2.bss_transition='1'
wireless.wifinet2.wnm_sleep_mode='1'
wireless.wifinet2.time_advertisement='2'
wireless.wifinet2.time_zone='EST5EDT'
wireless.wifinet2.ieee80211k='1'
wireless.wifinet2.rrm_neighbor_report='1'
wireless.wifinet2.rrm_beacon_report='1'
wireless.wifinet2.dtim_period='2'
wireless.wifinet2.skip_inactivity_poll='1'
wireless.wifinet3=wifi-iface
wireless.wifinet3.device='radio1'
wireless.wifinet3.mode='ap'
wireless.wifinet3.ssid='NETK'
wireless.wifinet3.key='private'
wireless.wifinet3.network='CHILDSAFE'
wireless.wifinet3.wpa_disable_eapol_key_retries='1'
wireless.wifinet3.dtim_period='3'
wireless.wifinet3.ieee80211r='1'
wireless.wifinet3.mobility_domain='123a'
wireless.wifinet3.ft_over_ds='0'
wireless.wifinet3.ft_psk_generate_local='1'
wireless.wifinet3.encryption='psk2+ccmp'
wireless.wifinet3.bss_transition='1'
wireless.wifinet3.wnm_sleep_mode='1'
wireless.wifinet3.time_advertisement='2'
wireless.wifinet3.time_zone='EST5EDT'
wireless.wifinet3.ieee80211k='1'
wireless.wifinet3.rrm_neighbor_report='1'
wireless.wifinet3.rrm_beacon_report='1'
wireless.wifinet4=wifi-iface
wireless.wifinet4.device='radio1'
wireless.wifinet4.mode='ap'
wireless.wifinet4.ssid='GUEST'
wireless.wifinet4.encryption='psk2+ccmp'
wireless.wifinet4.isolate='1'
wireless.wifinet4.key='private'
wireless.wifinet4.wpa_disable_eapol_key_retries='1'
wireless.wifinet4.network='GUEST'
wireless.wifinet4.ieee80211r='1'
wireless.wifinet4.mobility_domain='123a'
wireless.wifinet4.ft_over_ds='0'
wireless.wifinet4.ft_psk_generate_local='1'
wireless.wifinet4.bss_transition='1'
wireless.wifinet4.wnm_sleep_mode='1'
wireless.wifinet4.time_advertisement='2'
wireless.wifinet4.time_zone='EST5EDT'
wireless.wifinet4.ieee80211k='1'
wireless.wifinet4.rrm_neighbor_report='1'
wireless.wifinet4.rrm_beacon_report='1'
wireless.wifinet4.skip_inactivity_poll='1'
wireless.wifinet4.disassoc_low_ack='0'
wireless.wifinet5=wifi-iface
wireless.wifinet5.device='radio0'
wireless.wifinet5.mode='ap'
wireless.wifinet5.ssid='IOT-5'
wireless.wifinet5.encryption='psk2+ccmp'
wireless.wifinet5.key='private'
wireless.wifinet5.wpa_disable_eapol_key_retries='1'
wireless.wifinet5.network='IOT'
wireless.wifinet5.skip_inactivity_poll='1'
wireless.wifinet5.disassoc_low_ack='0'
wireless.wifinet5.ieee80211r='1'
wireless.wifinet5.mobility_domain='123a'
wireless.wifinet5.ft_over_ds='0'
wireless.wifinet5.ft_psk_generate_local='1'
wireless.wifinet5.bss_transition='1'
wireless.wifinet5.wnm_sleep_mode='1'
wireless.wifinet5.time_advertisement='2'
wireless.wifinet5.time_zone='EST5EDT'
wireless.wifinet5.ieee80211k='1'
wireless.wifinet5.rrm_neighbor_report='1'
wireless.wifinet5.rrm_beacon_report='1'
wireless.wifinet6=wifi-iface
wireless.wifinet6.device='radio1'
wireless.wifinet6.mode='ap'
wireless.wifinet6.ssid='IOT'
wireless.wifinet6.encryption='psk2+ccmp'
wireless.wifinet6.key='private'
wireless.wifinet6.wpa_disable_eapol_key_retries='1'
wireless.wifinet6.network='IOT'
wireless.wifinet6.skip_inactivity_poll='1'
wireless.wifinet6.disassoc_low_ack='0'
wireless.wifinet6.ieee80211r='1'
wireless.wifinet6.mobility_domain='123a'
wireless.wifinet6.ft_psk_generate_local='1'
wireless.wifinet6.ft_over_ds='0'
wireless.wifinet6.bss_transition='1'
wireless.wifinet6.wnm_sleep_mode='1'
wireless.wifinet6.time_advertisement='2'
wireless.wifinet6.time_zone='EST5EDT'
wireless.wifinet6.ieee80211k='1'
wireless.wifinet6.rrm_neighbor_report='1'
wireless.wifinet6.rrm_beacon_report='1'

...so I need to execute the command for each wireless.wifinet entry. Is there a way in uci to do this, or do I need to hack something together using CLI tools like grep or sed?

Thanks!

Please try something like this as a starting point, e.g.:

#!/bin/sh

# standard OpenWrt function library
#
. "/lib/functions.sh"

# stub uci function 
#
f_test() {
	local mode radio essid bssid section="${1}" optional="${2}"

	mode="$(uci_get "wireless" "${section}" "mode")"
	radio="$(uci_get "wireless" "${section}" "device")"
	essid="$(uci_get "wireless" "${section}" "ssid")"
	bssid="$(uci_get "wireless" "${section}" "bssid")"
    # [...]
}

# load wireless config
#
config_load wireless

# iterate over wifi-iface sections
#
config_foreach f_test "wifi-iface" "${optional}"
1 Like