Advertisement
Guest User

Untitled

a guest
Jul 15th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # @Author LI Zhuohuan <zixia@zixia.net>
  4. # @Date 3/10/2015
  5. #
  6. # This script fix lost AP signal when STA fail.
  7. # it runs background, loop & check.
  8. # if STA fail, it disable STA and re-enable AP.
  9. #
  10. # I believe when wifi radio in both AP & STA(client) mode,
  11. # the driver need to know which channel to use first.
  12. # so AP will not functional until STA established the link.
  13. # after STA link connect, AP will know and use the same channel that STA use.
  14. # so AP have to wait, and there will no AP at all if STA setting error.
  15. #
  16.  
  17. DEBUG=1
  18. TIMEOUT=30
  19. SLEEP=2
  20.  
  21. disable_sta() {
  22. 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`
  23. [ $DEBUG -gt 0 ] && echo "disable_sta: found $n ifaces"
  24.  
  25. ap=0
  26. while [ $n -ge 0 ]; do
  27. mode=`uci get wireless.@wifi-iface[$n].mode`
  28. echo "iface[$n] mode[$mode]"
  29. if [ X$mode == Xsta ]; then
  30. echo "deleting wifi-iface[$n] for it's in sta mode"
  31. uci delete wireless.@wifi-iface[$n]
  32. uci commit wireless
  33. elif [ X$mode == Xap ]; then
  34. echo "found wifi-iface[$n] in ap mode."
  35. ap=1
  36. fi
  37. let n=n-1
  38. done
  39.  
  40. if [ $ap -eq 0 ]; then
  41. echo "adding wifi default ap..."
  42. uci add wireless wifi-iface
  43. uci set wireless.@wifi-iface[-1].device='radio0'
  44. uci set wireless.@wifi-iface[-1].network='lan'
  45. uci set wireless.@wifi-iface[-1].mode='ap'
  46. uci set wireless.@wifi-iface[-1].ssid='VoCore'
  47. uci set wireless.@wifi-iface[-1].encryption='none'
  48. uci commit wireless
  49. fi
  50.  
  51. wifi up
  52. }
  53.  
  54. sta_err=0
  55.  
  56. while [ 1 -gt 0 ]; do
  57.  
  58. ifnames=`ubus call network.wireless status | grep ifname | cut -d\" -f4`
  59.  
  60. for ifname in $ifnames ; do
  61. [ $DEBUG -gt 0 ] && echo "checking $ifname after sleep $SLEEP seconds..."
  62. iftype=`iw dev $ifname info | grep type | cut -d' ' -f2`
  63. [ $DEBUG -gt 0 ] && echo "checking $ifname 's type: $iftype"
  64. if [ X$iftype == Xmanaged ]; then
  65. ssid=`iw dev $ifname link | grep SSID | cut -d' ' -f 2`
  66. echo "ifname $ifname is STA mode, ssid[$ssid]"
  67. if [ X$ssid == "X" ]; then # AP mode disabled
  68. let sta_err=$sta_err+1
  69. echo "ifname $ifname not connected. err counter: $sta_err"
  70. else
  71. sta_err=0
  72. fi
  73. fi
  74. done
  75.  
  76. sleep $SLEEP;
  77.  
  78. let err_time=$sta_err*$SLEEP
  79. [ $DEBUG -gt 0 ] && [ $err_time -gt 0 ] && echo "err_time: $err_time"
  80.  
  81. if [ $err_time -gt $TIMEOUT ]; then
  82. echo "*** STA connect timeout[$err_time]. disable STA mode now... ***"
  83. sleep 1
  84. disable_sta
  85. sta_err=0
  86. fi
  87.  
  88. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement