travelmate: release 0.4.0
* add an "active mode", where travelmate will be restarted every n seconds (default 60) and checks existing uplink connection regardless of ifdown event trigger (disabled by default) * enhance multiple radio support * fix the ap detection * respect different radios during scanning & connection handling * cosmetics Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
parent
03bc8947f5
commit
4dd7e2edc8
5 changed files with 53 additions and 29 deletions
|
@ -6,7 +6,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=travelmate
|
PKG_NAME:=travelmate
|
||||||
PKG_VERSION:=0.3.5
|
PKG_VERSION:=0.4.0
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_LICENSE:=GPL-3.0+
|
PKG_LICENSE:=GPL-3.0+
|
||||||
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
||||||
|
|
|
@ -9,7 +9,8 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
|
||||||
* STA interfaces operating in an "always off" mode, to make sure that the AP is always accessible
|
* STA interfaces operating in an "always off" mode, to make sure that the AP is always accessible
|
||||||
* easy setup within normal OpenWrt/LEDE environment
|
* easy setup within normal OpenWrt/LEDE environment
|
||||||
* fast uplink connections
|
* fast uplink connections
|
||||||
* support multiple radios
|
* "active mode" support, where travelmate will be restarted every n seconds (default 60) and checks the existing uplink connection regardless of ifdown event trigger
|
||||||
|
* support of devices with multiple radios
|
||||||
* procd init system support
|
* procd init system support
|
||||||
* procd based hotplug support, the travelmate start will be triggered by interface triggers
|
* procd based hotplug support, the travelmate start will be triggered by interface triggers
|
||||||
* status & debug logging to syslog
|
* status & debug logging to syslog
|
||||||
|
@ -41,8 +42,10 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
|
||||||
* travelmate config options:
|
* travelmate config options:
|
||||||
* trm\_enabled => main switch to enable/disable the travelmate service (default: '0', disabled)
|
* trm\_enabled => main switch to enable/disable the travelmate service (default: '0', disabled)
|
||||||
* trm\_debug => enable/disable debug logging (default: '0', disabled)
|
* trm\_debug => enable/disable debug logging (default: '0', disabled)
|
||||||
|
* trm\_active => keep travelmate in an active state (default: '0', disabled)
|
||||||
* trm\_maxwait => how long (in seconds) should travelmate wait for wlan interface reload action (default: '20')
|
* trm\_maxwait => how long (in seconds) should travelmate wait for wlan interface reload action (default: '20')
|
||||||
* trm\_maxretry => how many times should travelmate try to find an uplink after a trigger event (default: '3')
|
* trm\_maxretry => how many times should travelmate try to find an uplink after a trigger event (default: '3')
|
||||||
|
* trm\_timeout => timeout in seconds for "active mode" (default: '60')
|
||||||
* trm\_iw => set this option to '0' to use iwinfo for wlan scanning (default: '1', use iw)
|
* trm\_iw => set this option to '0' to use iwinfo for wlan scanning (default: '1', use iw)
|
||||||
* trm\_radio => limit travelmate to a dedicated radio, e.g. 'radio0' (default: not set, use all radios)
|
* trm\_radio => limit travelmate to a dedicated radio, e.g. 'radio0' (default: not set, use all radios)
|
||||||
* trm\_iface => restrict the procd interface trigger to a (list of) certain wan interface(s) or disable it at all (default: not set, disabled)
|
* trm\_iface => restrict the procd interface trigger to a (list of) certain wan interface(s) or disable it at all (default: not set, disabled)
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
config travelmate 'global'
|
config travelmate 'global'
|
||||||
option trm_enabled '0'
|
option trm_enabled '0'
|
||||||
option trm_debug '0'
|
option trm_debug '0'
|
||||||
|
option trm_active '0'
|
||||||
option trm_maxwait '20'
|
option trm_maxwait '20'
|
||||||
option trm_maxretry '3'
|
option trm_maxretry '3'
|
||||||
|
option trm_timeout '60'
|
||||||
option trm_iw '1'
|
option trm_iw '1'
|
||||||
|
|
|
@ -11,7 +11,6 @@ start_service()
|
||||||
then
|
then
|
||||||
ubus -t 30 wait_for network.interface
|
ubus -t 30 wait_for network.interface
|
||||||
procd_open_instance "travelmate"
|
procd_open_instance "travelmate"
|
||||||
procd_set_param env trm_procd="true"
|
|
||||||
procd_set_param command "${trm_script}" "${@}"
|
procd_set_param command "${trm_script}" "${@}"
|
||||||
procd_set_param stdout 1
|
procd_set_param stdout 1
|
||||||
procd_set_param stderr 1
|
procd_set_param stderr 1
|
||||||
|
@ -23,8 +22,6 @@ service_triggers()
|
||||||
{
|
{
|
||||||
local iface="$(uci -q get travelmate.global.trm_iface)"
|
local iface="$(uci -q get travelmate.global.trm_iface)"
|
||||||
|
|
||||||
procd_open_trigger
|
|
||||||
procd_add_config_trigger "config.change" "travelmate" /etc/init.d/travelmate start
|
|
||||||
if [ -z "${iface}" ]
|
if [ -z "${iface}" ]
|
||||||
then
|
then
|
||||||
procd_add_raw_trigger "interface.*.down" 1000 /etc/init.d/travelmate start
|
procd_add_raw_trigger "interface.*.down" 1000 /etc/init.d/travelmate start
|
||||||
|
@ -34,5 +31,5 @@ service_triggers()
|
||||||
procd_add_interface_trigger "interface.*.down" "${name}" /etc/init.d/travelmate start
|
procd_add_interface_trigger "interface.*.down" "${name}" /etc/init.d/travelmate start
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
procd_close_trigger
|
procd_add_config_trigger "config.change" "travelmate" /etc/init.d/travelmate start
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,13 @@
|
||||||
#
|
#
|
||||||
LC_ALL=C
|
LC_ALL=C
|
||||||
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
trm_ver="0.3.5"
|
trm_ver="0.4.0"
|
||||||
trm_enabled=1
|
trm_enabled=1
|
||||||
trm_debug=0
|
trm_debug=0
|
||||||
|
trm_active=0
|
||||||
trm_maxwait=20
|
trm_maxwait=20
|
||||||
trm_maxretry=3
|
trm_maxretry=3
|
||||||
trm_radio="*"
|
trm_timeout=60
|
||||||
trm_iw=1
|
trm_iw=1
|
||||||
|
|
||||||
f_envload()
|
f_envload()
|
||||||
|
@ -65,34 +66,46 @@ f_prepare()
|
||||||
{
|
{
|
||||||
local config="${1}"
|
local config="${1}"
|
||||||
local mode="$(uci -q get wireless."${config}".mode)"
|
local mode="$(uci -q get wireless."${config}".mode)"
|
||||||
local network="$(uci -q get wireless."${config}".network)"
|
local radio="$(uci -q get wireless."${config}".device)"
|
||||||
local disabled="$(uci -q get wireless."${config}".disabled)"
|
local disabled="$(uci -q get wireless."${config}".disabled)"
|
||||||
|
|
||||||
if [ "${mode}" = "sta" ] && [ -n "${network}" ]
|
if [ "${mode}" = "ap" ] && ([ -z "${disabled}" ] || [ "${disabled}" = "0" ]) && \
|
||||||
|
([ -z "${trm_radio}" ] || [ "${trm_radio}" = "${radio}" ])
|
||||||
then
|
then
|
||||||
trm_stalist="${trm_stalist} ${config}_${network}"
|
trm_radiolist="${trm_radiolist} ${radio}"
|
||||||
|
elif [ "${mode}" = "sta" ]
|
||||||
|
then
|
||||||
|
trm_stalist="${trm_stalist} ${config}_${radio}"
|
||||||
if [ -z "${disabled}" ] || [ "${disabled}" = "0" ]
|
if [ -z "${disabled}" ] || [ "${disabled}" = "0" ]
|
||||||
then
|
then
|
||||||
uci -q set wireless."${config}".disabled=1
|
uci -q set wireless."${config}".disabled=1
|
||||||
f_log "debug" "config: ${config}, interface: ${network}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
f_log "debug" "mode: ${mode}, radio: ${radio}, config: ${config}, disabled: ${disabled}"
|
||||||
}
|
}
|
||||||
|
|
||||||
f_check()
|
f_check()
|
||||||
{
|
{
|
||||||
local ifname cnt=1 mode="${1}"
|
local ifname radio cnt=1 mode="${1}"
|
||||||
trm_ifstatus="false"
|
trm_ifstatus="false"
|
||||||
|
|
||||||
while [ ${cnt} -le ${trm_maxwait} ]
|
while [ ${cnt} -le ${trm_maxwait} ]
|
||||||
do
|
do
|
||||||
if [ "${mode}" = "ap" ]
|
if [ "${mode}" = "ap" ]
|
||||||
then
|
then
|
||||||
ifname="$(ubus -S call network.wireless status | jsonfilter -l1 -e "@.${trm_radio}.interfaces[@.config.mode=\"ap\"].ifname")"
|
for radio in ${trm_radiolist}
|
||||||
if [ -n "${ifname}" ]
|
do
|
||||||
|
trm_ifstatus="$(ubus -S call network.wireless status | jsonfilter -e "@.${radio}.up")"
|
||||||
|
if [ "${trm_ifstatus}" = "true" ]
|
||||||
then
|
then
|
||||||
trm_ifstatus="$(ubus -S call network.wireless status | jsonfilter -l1 -e "@.${trm_radio}.up")"
|
trm_aplist="${trm_aplist} $(ubus -S call network.wireless status | jsonfilter -e "@.${radio}.interfaces[@.config.mode=\"ap\"].ifname")_${radio}"
|
||||||
|
ifname="${trm_aplist}"
|
||||||
|
else
|
||||||
|
trm_aplist=""
|
||||||
|
trm_ifstatus="false"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
else
|
else
|
||||||
ifname="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
|
ifname="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
|
||||||
if [ -n "${ifname}" ]
|
if [ -n "${ifname}" ]
|
||||||
|
@ -107,7 +120,7 @@ f_check()
|
||||||
cnt=$((cnt+1))
|
cnt=$((cnt+1))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
f_log "debug" "mode: ${mode}, radio: ${trm_radio}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}"
|
f_log "debug" "mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to write to syslog
|
# function to write to syslog
|
||||||
|
@ -130,7 +143,7 @@ f_log()
|
||||||
|
|
||||||
f_main()
|
f_main()
|
||||||
{
|
{
|
||||||
local ap_list ssid_list config network ssid cnt=1
|
local ssid_list config ap_radio sta_radio ssid cnt=1
|
||||||
local sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
|
local sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
|
||||||
|
|
||||||
f_log "info " "start travelmate scanning ..."
|
f_log "info " "start travelmate scanning ..."
|
||||||
|
@ -145,15 +158,20 @@ f_main()
|
||||||
ubus call network reload
|
ubus call network reload
|
||||||
fi
|
fi
|
||||||
f_check "ap"
|
f_check "ap"
|
||||||
ap_list="$(ubus -S call network.wireless status | jsonfilter -e "@.${trm_radio}.interfaces[@.config.mode=\"ap\"].ifname" | awk '{ORS=" "; print $0}')"
|
f_log "debug" "ap-list: ${trm_aplist}, sta-list: ${trm_stalist}"
|
||||||
f_log "debug" "ap-list: ${ap_list}, sta-list: ${trm_stalist}"
|
if [ -z "${trm_aplist}" ] || [ -z "${trm_stalist}" ]
|
||||||
if [ -z "${ap_list}" ] || [ -z "${trm_stalist}" ]
|
|
||||||
then
|
then
|
||||||
f_log "error" "no usable AP/STA configuration found"
|
f_log "error" "no usable AP/STA configuration found"
|
||||||
fi
|
fi
|
||||||
for ap in ${ap_list}
|
for ap in ${trm_aplist}
|
||||||
do
|
do
|
||||||
cnt=1
|
cnt=1
|
||||||
|
ap_radio="${ap##*_}"
|
||||||
|
ap="${ap%%_*}"
|
||||||
|
if [ -z "$(printf "${trm_stalist}" | grep -Fo "_${ap_radio}")" ]
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
while [ ${cnt} -le ${trm_maxretry} ]
|
while [ ${cnt} -le ${trm_maxretry} ]
|
||||||
do
|
do
|
||||||
if [ ${trm_iw} -eq 1 ]
|
if [ ${trm_iw} -eq 1 ]
|
||||||
|
@ -170,9 +188,9 @@ f_main()
|
||||||
for sta in ${trm_stalist}
|
for sta in ${trm_stalist}
|
||||||
do
|
do
|
||||||
config="${sta%%_*}"
|
config="${sta%%_*}"
|
||||||
network="${sta##*_}"
|
sta_radio="${sta##*_}"
|
||||||
ssid="\"$(uci -q get wireless."${config}".ssid)\""
|
ssid="\"$(uci -q get wireless."${config}".ssid)\""
|
||||||
if [ -n "$(printf "${ssid_list}" | grep -Fo "${ssid}")" ]
|
if [ -n "$(printf "${ssid_list}" | grep -Fo "${ssid}")" ] && [ "${ap_radio}" = "${sta_radio}" ]
|
||||||
then
|
then
|
||||||
uci -q set wireless."${config}".disabled=0
|
uci -q set wireless."${config}".disabled=0
|
||||||
uci -q commit wireless
|
uci -q commit wireless
|
||||||
|
@ -204,9 +222,13 @@ f_main()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "${trm_procd}" = "true" ]
|
f_envload
|
||||||
|
f_main
|
||||||
|
|
||||||
|
# keep travelmate in an active state
|
||||||
|
#
|
||||||
|
if [ ${trm_active} -eq 1 ]
|
||||||
then
|
then
|
||||||
f_envload
|
(sleep ${trm_timeout}; /etc/init.d/travelmate start >/dev/null 2>&1) &
|
||||||
f_main
|
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue