Quando un router openWRT è configurato in modalità repeater è soggetto ad una criticità nel momento in cui il segnale con l’AP originario decade sotto la soglia minima.

In queste condizioni il repeater chiude la sessione Station e disattiva la modalità AP, che così non è più visibile nemmeno per debug.

Una soluzione può essere la gestione di 2 file di configurazione differenti ed uno script shell che gestisca lo switch fra i due file poi letti da init.d.

Step 1: Create AP Only and AP+STA wireless configuration files

cp /etc/config/wireless.original /etc/config/wireless.ap-only
cp /etc/config/wireless /etc/config/wireless.ap+sta

Step 2: Install script fix_sta_ap.sh

Make sure that package iwinfo is installed. Place the following text in /usr/local/bin/fix_sta_ap.sh.

#!/bin/sh
#
# Fix loss of AP when STA (Client) mode fails by reverting to default
# AP only configuration. Default AP configuration is assumed to be in
# /etc/config/wireless.ap-only
#
 
 
TIMEOUT=30
SLEEP=3
 
sta_err=0
 
while [ $(iwinfo | grep -c "ESSID: unknown") -ge 1 ]; do
   let sta_err=$sta_err+1
   if [ $((sta_err * SLEEP)) -ge $TIMEOUT ]; then
     cp /etc/config/wireless.ap-only /etc/config/wireless
     wifi up
#    uncomment the following lines to try AP+STA after reboot
#    sleep 3
#    cp /etc/config/wireless.ap+sta /etc/config/wireless
     break
   fi
 
   sleep $SLEEP
 
done

Step 3: Make fix_sta_ap.sh executable

chmod +x /usr/local/bin/fix_sta_ap.sh

Step 4: Add fix_sta_ap.sh /etc/rc.local

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
 
/bin/sh /usr/local/bin/fix_sta_ap.sh > /dev/null &
 
exit 0

nello stesso articolo uno spunto event_driven può essere :

 

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

N.B. the logger commands in the filter scripts can safely be removed but are useful with

logread -e DEBUG

EDIT: replaced calls to network_is_up (returns 0 when the target is unavailable) with json calls
EDIT: placed comments in 99-recover-STA
EDIT: jow explained the operation of network_is_up and network_flush_cache here and closed the ticket ‘worksforme

 

Da seguire come riferimento tutto il thread

 

 

 

 

Annunci