. /lib/functions.sh

handle_interface() {
	local config="${1}"
	local prefix="${2}"

	config_get ifname "${config}" ifname
	config_get mode ${config} mode

	if [ "$mode" = "ap" ] ; then
		echo "Get status for ${ifname}"
		ubus call "${prefix}.${ifname}" status
	elif [ "$mode" = "sta" ] ; then
		echo "Get status for bSTA ${ifname}"
		ubus call "wifi.bsta.${ifname}" status
	fi
}

handle_wifi_interface() {
	handle_interface "$1" "wifi.ap"
}

handle_mld_interface() {
	handle_interface "$1" "wifi.apmld"
}

config_load wireless
echo "Get wifi status"
ubus call wifi status

echo "Get wifi status for ap & bsta interfaces"
config_foreach handle_wifi_interface wifi-iface

echo "Get wifi status for apmld interfaces"
config_foreach handle_mld_interface wifi-mld

