diff --git a/inteno-netmodes/files/etc/hotplug.d/iface/01-netmode-handler b/inteno-netmodes/files/etc/hotplug.d/iface/01-netmode-handler index 96e833677..5917f7f18 100755 --- a/inteno-netmodes/files/etc/hotplug.d/iface/01-netmode-handler +++ b/inteno-netmodes/files/etc/hotplug.d/iface/01-netmode-handler @@ -48,14 +48,28 @@ is_inteno_macaddr() switch_mode() { [ "$repeaterready" == "1" ] || return - defroute=$(ip r | grep default | awk '{print$3}') - ping -c 1 -W 1 $defroute >/dev/null 2>&1 - uplinkmac=$(grep "$defroute" /proc/net/arp | awk '{print$4}') - - # will be auto-configured if the uplink device is Inteno - is_inteno_macaddr $uplinkmac && return + # flush iptables in case the MASTER + # tries to configure us before + # firewall is disabled the proper way + iptables -F ubus call leds set '{"state" : "allflash"}' + + local ret=0 + # let netmode-conf up to 20 seconds before switching mode + for tm in 2 4 6 8; do + if [ -f /tmp/wificontrol.txt ]; then + ret=1 + break + fi + sleep $tm + done + + # let netmode-conf take over + [ $ret -eq 1 ] && return + + # go head with switching mode + touch -f /tmp/switching_mode echo "Switching to 'extender' mode" > /dev/console uci -q set netmode.setup.curmode='repeater' uci set netmode.setup.repeaterready=0 @@ -66,6 +80,7 @@ switch_mode() { wifi reload nodat ubus call router.network reload ubus call leds set '{"state" : "normal"}' + rm -f /tmp/switching_mode } test_ip() { diff --git a/inteno-netmodes/files/etc/init.d/netmode b/inteno-netmodes/files/etc/init.d/netmode index cdb629600..f0fe65db4 100755 --- a/inteno-netmodes/files/etc/init.d/netmode +++ b/inteno-netmodes/files/etc/init.d/netmode @@ -207,13 +207,16 @@ switch_netmode() { } start_client_listener() { - local curmode repeaterready - config_load netmode + local curmode repeaterready ulcpid + config_load netmode config_get repeaterready setup repeaterready 0 + ulcpid=$(ps | grep "ubus listen client" | grep -v grep | awk '{print$1}') + [ $repeaterready -eq 1 ] && { killall -SIGKILL netmode-client-detect >/dev/null 2>&1 + kill -9 $ulcpid >/dev/null 2>&1 return } @@ -222,6 +225,7 @@ start_client_listener() { case "$curmode" in repeater*) killall -SIGKILL netmode-client-detect >/dev/null 2>&1 + kill -9 $ulcpid >/dev/null 2>&1 ;; *) pidof netmode-client-detect || /sbin/netmode-client-detect & diff --git a/inteno-netmodes/files/sbin/netmode-conf b/inteno-netmodes/files/sbin/netmode-conf index e00463a8f..0c7f0e719 100755 --- a/inteno-netmodes/files/sbin/netmode-conf +++ b/inteno-netmodes/files/sbin/netmode-conf @@ -108,9 +108,16 @@ backup() { file="$1" from_gui="$2" - [ -f "$file" ] || exit +# let netmode-handler up to 20 seconds to finish switching mode +for tm in 2 4 6 8; do + if [ ! -f /tmp/switching_mode ]; then + break + fi + sleep $tm +done + [ "$from_gui" == "true" ] && backup json_load "`cat $file`"