1248 shaares
en cas de défaillance ou absence du réseau wifi à répéter, basculer sur un AP simple
Create a fallback 'AP-only' configuration -
cp /etc/config/wireless /etc/config/wireless_AP
Edit /etc/config/wireless_AP, delete the wifi-interface section containing the STA definition, and save.
Edit /etc/config/wireless adding a new section and save -
config wifi-repeater 'STA_name'
option interface wwan # this is also the value of 'option network XXXX' in the STA section
option wait 15
Create a directory for the script -
mkdir /usr/local/bin
Place the script in /usr/local/bin/revert_to_AP.sh -
#!/bin/sh
# Restore wireless access to the local AP for STA (Client) failures (association or login) with a remote AP (revert to 'AP-only') configuration.
. /usr/share/libubox/jshn.sh
local _rc _sta_err
let _sta_err++
json_init
json_load $(ubus -S call network.interface."$2" status)
json_get_var _rc up
while [ $_rc = 0 ] || [ $ACTION = ifdown -a $_rc = 0 ]
do
if [ $((_sta_err * 3)) -ge $1 ]; then
cp /etc/config/wireless /etc/config/wireless_AP+STA
cp /etc/config/wireless_AP /etc/config/wireless
wifi down
wifi up
sleep 3
mv -f /etc/config/wireless_AP+STA /etc/config/wireless
break
fi
sleep 3
json_load $(ubus -S call network.interface."$2" status)
json_get_var _rc up
let ++_sta_err
done
json_cleanup
N.B. the script will unconditionally restore the AP + STA configuration because it detects and recovers from all failures.
Place this filter script in /etc/hotplug.d/net/99-recover-STA -
#!/bin/sh
logger -t DEBUG -s "hotplug (net): action='$ACTION' devicename='$DEVICENAME' devname='$DEVNAME' devpath='$DEVPATH' product='$PRODUCT' type='$TYPE' interface='$INTERFACE'"
. /usr/share/libubox/jshn.sh
local _wwan _wait _device _up
_wwan=$(uci -q get wireless.STA_name.interface)
[ -z "$_wwan" ] && _wwan=wwan # <-- a popular name for 'repeater STAs'
_wait=$(uci -q get wireless.STA_name.wait)
[ -z "$_wait" ] && _wait=15
json_init
# the interface is known but not the device
json_load $(ubus -S call network.interface."$_wwan" status)
# the update to the ubus object might be delayed...
json_get_var _up up
[ "$_up" = 0 ] && sleep $_wait && json_load $(ubus -S call network.interface."$_wwan" status)
# extract the device that is hosting the STA interface
json_get_var _device device
json_cleanup
if [ $_device -a "$ACTION" = add -a "$INTERFACE" = "$_device" ]; then
/bin/sh /usr/local/bin/revert_to_AP.sh $_wait $_wwan
fi
Place this filter script in /etc/hotplug.d/iface/99-recover-STA -
#!/bin/sh
logger -t DEBUG "hotplug (iface): action='$ACTION' devicename='$DEVICENAME' devname='$DEVNAME' devpath='$DEVPATH' product='$PRODUCT' type='$TYPE' interface='$INTERFACE'"
local _wwan _wait
_wwan=$(uci -q get wireless.STA_name.interface)
[ -z "$_wwan" ] && _wwan=wwan # <-- a popular name for 'repeater STAs'
_wait=$(uci -q get wireless.STA_name.wait)
[ -z "$_wait" ] && _wait=15
if [ "$ACTION" = ifdown -a "$INTERFACE" = "$_wwan" ]; then
/bin/sh /usr/local/bin/revert_to_AP.sh $_wait $_wwan
fi