Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # @Author LI Zhuohuan <zixia@zixia.net>
- # @Date 3/10/2015
- #
- # This script fix lost AP signal when STA fail.
- # it runs background, loop & check.
- # if STA fail, it disable STA and re-enable AP.
- #
- # I believe when wifi radio in both AP & STA(client) mode,
- # the driver need to know which channel to use first.
- # so AP will not functional until STA established the link.
- # after STA link connect, AP will know and use the same channel that STA use.
- # so AP have to wait, and there will no AP at all if STA setting error.
- #
- DEBUG=1
- TIMEOUT=30
- SLEEP=2
- disable_sta() {
- n=`uci show wireless.@wifi-iface[99] 2>/dev/null | grep @wifi-iface | grep -v =wifi-iface | cut -d. -f2 | uniq | cut -d[ -f2 | cut -d] -f1 | sort | tail -1`
- [ $DEBUG -gt 0 ] && echo "disable_sta: found $n ifaces"
- ap=0
- while [ $n -ge 0 ]; do
- mode=`uci get wireless.@wifi-iface[$n].mode`
- echo "iface[$n] mode[$mode]"
- if [ X$mode == Xsta ]; then
- echo "deleting wifi-iface[$n] for it's in sta mode"
- uci delete wireless.@wifi-iface[$n]
- uci commit wireless
- elif [ X$mode == Xap ]; then
- echo "found wifi-iface[$n] in ap mode."
- ap=1
- fi
- let n=n-1
- done
- if [ $ap -eq 0 ]; then
- echo "adding wifi default ap..."
- uci add wireless wifi-iface
- uci set wireless.@wifi-iface[-1].device='radio0'
- uci set wireless.@wifi-iface[-1].network='lan'
- uci set wireless.@wifi-iface[-1].mode='ap'
- uci set wireless.@wifi-iface[-1].ssid='VoCore'
- uci set wireless.@wifi-iface[-1].encryption='none'
- uci commit wireless
- fi
- wifi up
- }
- sta_err=0
- while [ 1 -gt 0 ]; do
- ifnames=`ubus call network.wireless status | grep ifname | cut -d\" -f4`
- for ifname in $ifnames ; do
- [ $DEBUG -gt 0 ] && echo "checking $ifname after sleep $SLEEP seconds..."
- iftype=`iw dev $ifname info | grep type | cut -d' ' -f2`
- [ $DEBUG -gt 0 ] && echo "checking $ifname 's type: $iftype"
- if [ X$iftype == Xmanaged ]; then
- ssid=`iw dev $ifname link | grep SSID | cut -d' ' -f 2`
- echo "ifname $ifname is STA mode, ssid[$ssid]"
- if [ X$ssid == "X" ]; then # AP mode disabled
- let sta_err=$sta_err+1
- echo "ifname $ifname not connected. err counter: $sta_err"
- else
- sta_err=0
- fi
- fi
- done
- sleep $SLEEP;
- let err_time=$sta_err*$SLEEP
- [ $DEBUG -gt 0 ] && [ $err_time -gt 0 ] && echo "err_time: $err_time"
- if [ $err_time -gt $TIMEOUT ]; then
- echo "*** STA connect timeout[$err_time]. disable STA mode now... ***"
- sleep 1
- disable_sta
- sta_err=0
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement