[SOLVED] Modify /etc/rf.button/rfkill to only kill guest network

I have EA8500 with the latest build kernel 4.14.53 OpenWrt SNAPSHOT r7410-d3a7587eb9 / LuCI Master (git-18.188.47906-e617902)

I did configure a guest network based on this link and it works great

https://steven-england.info/2014/11/01/openwrt-how-to-create-a-public-network-without-using-the-wan-interface/

After reading a little bit about how to use a button to turn wifi on and off I figured the the script /etc/rf.button/rfkill is executed to do this. This is already working and kills the whole wifi.

the script is:

#!/bin/sh

[ "${ACTION}" = "released" -o -n "${TYPE}" ] || exit 0

. /lib/functions.sh

rfkill_state=0

wifi_rfkill_set() {
        uci set wireless.$1.disabled=$rfkill_state
}

wifi_rfkill_check() {
        local disabled
        config_get disabled $1 disabled
        [ "$disabled" = "1" ] || rfkill_state=1
}

config_load wireless
case "${TYPE}" in
"switch")
        [ "${ACTION}" = "released" ] && rfkill_state=1
        ;;
*)
        config_foreach wifi_rfkill_check wifi-device
        ;;
esac
config_foreach wifi_rfkill_set wifi-device
uci commit wireless
wifi up

return 0

What do I have to change to the script so it only disables my guest instead of the whole wifi?

I figure it is something is this part of the script

wifi_rfkill_set() {
        uci set wireless.$1.disabled=$rfkill_state
}

Sorry I'm not that good on shell scripting

******* I came up with this solution, but I'm sure there is a better way out there

#!/bin/sh


[ "${ACTION}" = "released" -o -n "${TYPE}" ] || exit 0

. /lib/functions.sh

SW=$(uci -q get wireless.@wifi-iface[2].disabled)
[ "$SW" == "1" ] && uci set wireless.@wifi-iface[2].disabled=0
[ "$SW" == "1" ] || uci set wireless.@wifi-iface[2].disabled=1
uci commit wireless
wifi up

return 0

Thanks

You're already close to the best possible solution. There is no easy possibility to bring down a single SSID on a radio without restarting the entire stack.

This is not the safest approach. $SW may be empty if the interface is enabled. I'd recommend doing:

[ "$SW" == "1" ] && uci set wireless.@wifi-iface[2].disabled=0 || uci set wireless.@wifi-iface[2].disabled=1

Better yet,

if [ ${SW:-0} -eq 1 ] then 
uci set wireless.@wifi-iface[2].disabled=0
else 
uci set wireless.@wifi-iface[2].disabled=1
fi

Also, if you know which radio the guest interface is bound to (and if memory serves me correctly), you can do wifi radioX to restart that specific radio.

Thanks
that works for me

If your problem is solved, please consider marking this topic as [Solved]. (Click the pencil behind the topic...)