mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 15:38:40 +01:00
[17.01] travelmate: release 1.0.2
* bump travelmate version in stable tree Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
@@ -1,32 +1,33 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2016-2017 Dirk Brenken (dev@brenken.org)
|
# Copyright (c) 2016-2018 Dirk Brenken (dev@brenken.org)
|
||||||
# This is free software, licensed under the GNU General Public License v3.
|
# This is free software, licensed under the GNU General Public License v3.
|
||||||
#
|
#
|
||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=travelmate
|
PKG_NAME:=travelmate
|
||||||
PKG_VERSION:=0.3.2
|
PKG_VERSION:=1.0.2
|
||||||
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>
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
define Package/$(PKG_NAME)
|
define Package/travelmate
|
||||||
SECTION:=net
|
SECTION:=net
|
||||||
CATEGORY:=Network
|
CATEGORY:=Network
|
||||||
TITLE:=A wlan connection manager for travel router
|
TITLE:=A wlan connection manager for travel router
|
||||||
|
DEPENDS:=+iwinfo +jshn +jsonfilter
|
||||||
PKGARCH:=all
|
PKGARCH:=all
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/$(PKG_NAME)/description
|
define Package/travelmate/description
|
||||||
A wlan connection manager for travel router.
|
A wlan connection manager for travel router.
|
||||||
Please see https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md for further information.
|
Please see https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md for further information.
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/$(PKG_NAME)/conffiles
|
define Package/travelmate/conffiles
|
||||||
/etc/config/travelmate
|
/etc/config/travelmate
|
||||||
endef
|
endef
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ endef
|
|||||||
define Build/Compile
|
define Build/Compile
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/$(PKG_NAME)/install
|
define Package/travelmate/install
|
||||||
$(INSTALL_DIR) $(1)/usr/bin
|
$(INSTALL_DIR) $(1)/usr/bin
|
||||||
$(INSTALL_BIN) ./files/travelmate.sh $(1)/usr/bin/
|
$(INSTALL_BIN) ./files/travelmate.sh $(1)/usr/bin/
|
||||||
|
|
||||||
@@ -50,4 +51,4 @@ define Package/$(PKG_NAME)/install
|
|||||||
$(INSTALL_CONF) ./files/travelmate.conf $(1)/etc/config/travelmate
|
$(INSTALL_CONF) ./files/travelmate.conf $(1)/etc/config/travelmate
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
$(eval $(call BuildPackage,travelmate))
|
||||||
|
|||||||
@@ -8,48 +8,63 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
|
|||||||
## Main Features
|
## Main Features
|
||||||
* 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
|
||||||
|
* strong LuCI-Support with builtin interface wizard and a wireless station manager
|
||||||
* fast uplink connections
|
* fast uplink connections
|
||||||
* procd init system support
|
* support all kinds of uplinks, incl. hidden and enterprise uplinks
|
||||||
* procd based hotplug support, the travelmate start will be triggered by interface triggers
|
* trigger- or automatic-mode support, the latter one is the default and checks the existing uplink connection regardless of ifdown event trigger actions every n seconds
|
||||||
|
* support of devices with multiple radios
|
||||||
|
* procd init and hotplug support
|
||||||
|
* runtime information available via LuCI & via 'status' init command
|
||||||
* status & debug logging to syslog
|
* status & debug logging to syslog
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
* [OpenWrt](https://openwrt.org) or [LEDE](https://www.lede-project.org) trunk
|
* [LEDE](https://www.lede-project.org) 17.01 or latest snapshot
|
||||||
* iw (default) or iwinfo for wlan scanning
|
* iwinfo for wlan scanning
|
||||||
|
|
||||||
## OpenWrt / LEDE trunk Installation & Usage
|
## LEDE trunk Installation & Usage
|
||||||
* download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/packages)
|
* download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/packages)
|
||||||
* install 'travelmate' (_opkg install travelmate_)
|
* install 'travelmate' (_opkg install travelmate_)
|
||||||
* configure your network to support (multiple) wlan uplinks and set travelmate config options (details see below)
|
* configure your network:
|
||||||
* set 'trm\_enabled' option in travelmate config to '1'
|
* recommended: use the LuCI frontend with builtin interface wizard and a wireless station manager
|
||||||
* travelmate starts automatically during boot and will be triggered by procd interface triggers
|
* manual: see detailed configure steps below
|
||||||
|
* at least you need one configured AP and one STA interface
|
||||||
|
|
||||||
## LuCI travelmate companion package
|
## LuCI travelmate companion package
|
||||||
* download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/luci)
|
* download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/luci)
|
||||||
* install 'luci-app-travelmate' (_opkg install luci-app-travelmate_)
|
* install 'luci-app-travelmate' (_opkg install luci-app-travelmate_)
|
||||||
* the application is located in LuCI under 'Services' menu
|
* the application is located in LuCI under 'Services' menu
|
||||||
* _Thanks to Hannu Nyman for this great LuCI frontend!_
|
|
||||||
|
|
||||||
## Chaos Calmer installation notes
|
|
||||||
* 'travelmate' and 'luci-app-travelmate' are _not_ available as ipk packages in the Chaos Calmer download repository
|
|
||||||
* download the packages from a development snapshot directory (see download links above)
|
|
||||||
* manually transfer the packages to your routers temp directory (with tools like _sshfs_ or _winscp_)
|
|
||||||
* install the packages as described above
|
|
||||||
|
|
||||||
## Travelmate config options
|
## Travelmate config options
|
||||||
* travelmate config options:
|
* usually the pre-configured travelmate setup works quite well and no manual config overrides are needed, all listed options apply to the 'global' config section:
|
||||||
* 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\_maxwait => how long (in seconds) should travelmate wait for wlan interface reload action (default: '20')
|
* trm\_automatic => keep travelmate in an active state (default: '1', enabled)
|
||||||
* trm\_maxretry => how many times should travelmate try to find an uplink after a trigger event (default: '3')
|
* trm\_maxwait => how long (in seconds) should travelmate wait for a successful wlan interface reload action (default: '30')
|
||||||
* trm\_iw => set this option to '0' to use iwinfo for wlan scanning (default: '1', use iw)
|
* trm\_maxretry => how many times should travelmate try to connect to an uplink, '0' means unlimited retries. (default: '3')
|
||||||
* 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\_timeout => timeout in seconds for "automatic mode" (default: '60')
|
||||||
|
* trm\_radio => limit travelmate to a dedicated radio, e.g. 'radio0' (default: not set, use all radios)
|
||||||
|
* trm\_iface => main uplink / procd trigger network interface (default: trm_wwan)
|
||||||
|
* trm\_triggerdelay => additional trigger delay in seconds before travelmate processing starts (default: '2')
|
||||||
|
|
||||||
## Setup
|
## Runtime information
|
||||||
**1. configure a wwan interface in /etc/config/network:**
|
|
||||||
|
**receive travelmate runtime information:**
|
||||||
|
<pre><code>
|
||||||
|
::: travelmate runtime information
|
||||||
|
travelmate_version : 1.0.0
|
||||||
|
station_connection : true
|
||||||
|
station_id : blackhole/04:F0:21:2F:B7:64
|
||||||
|
station_interface : trm_wwan
|
||||||
|
station_radio : radio1
|
||||||
|
last_rundate : 15.12.2017 13:51:30
|
||||||
|
system : TP-LINK RE450, OpenWrt SNAPSHOT r5422+84-9fe59abef8
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
## Manual Setup
|
||||||
|
**1. configure the travelmate wwan interface in /etc/config/network:**
|
||||||
<pre><code>
|
<pre><code>
|
||||||
[...]
|
[...]
|
||||||
config interface 'wwan'
|
config interface 'trm_wwan'
|
||||||
option proto 'dhcp'
|
option proto 'dhcp'
|
||||||
[...]
|
[...]
|
||||||
</code></pre>
|
</code></pre>
|
||||||
@@ -59,22 +74,16 @@ config interface 'wwan'
|
|||||||
[...]
|
[...]
|
||||||
config zone
|
config zone
|
||||||
option name 'wan'
|
option name 'wan'
|
||||||
option input 'REJECT'
|
option network 'wan wan6 trm_wwan'
|
||||||
option output 'ACCEPT'
|
|
||||||
option forward 'REJECT'
|
|
||||||
option masq '1'
|
|
||||||
option mtu_fix '1'
|
|
||||||
option network 'wan wan6 wwan'
|
|
||||||
[...]
|
[...]
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
**3. add required ap and wwan stations to your wireless configuration in etc/config/wireless:**
|
**3. at least add one ap and (multiple) wwan stations to your wireless configuration in etc/config/wireless:**
|
||||||
<pre><code>
|
<pre><code>
|
||||||
[...]
|
[...]
|
||||||
config wifi-iface
|
config wifi-iface
|
||||||
option device 'radio0'
|
option device 'radio0'
|
||||||
option network 'lan'
|
option network 'lan'
|
||||||
option ifname 'wlan0'
|
|
||||||
option mode 'ap'
|
option mode 'ap'
|
||||||
option ssid 'example_ap'
|
option ssid 'example_ap'
|
||||||
option encryption 'psk2+ccmp'
|
option encryption 'psk2+ccmp'
|
||||||
@@ -83,41 +92,43 @@ config wifi-iface
|
|||||||
[...]
|
[...]
|
||||||
config wifi-iface
|
config wifi-iface
|
||||||
option device 'radio0'
|
option device 'radio0'
|
||||||
option network 'wwan'
|
option network 'trm_wwan'
|
||||||
option mode 'sta'
|
option mode 'sta'
|
||||||
option ssid 'example_01'
|
option ssid 'example_01'
|
||||||
option ifname 'wwan01'
|
|
||||||
option encryption 'psk2+ccmp'
|
option encryption 'psk2+ccmp'
|
||||||
option key 'abc'
|
option key 'abc'
|
||||||
option disabled '1'
|
option disabled '1'
|
||||||
|
[...]
|
||||||
config wifi-iface
|
config wifi-iface
|
||||||
option device 'radio0'
|
option device 'radio0'
|
||||||
option network 'wwan'
|
option network 'trm_wwan'
|
||||||
option mode 'sta'
|
option mode 'sta'
|
||||||
option ssid 'example_02'
|
option ssid 'example_02'
|
||||||
option ifname 'wwan02'
|
|
||||||
option encryption 'psk2+ccmp'
|
option encryption 'psk2+ccmp'
|
||||||
option key 'xyz'
|
option key 'xyz'
|
||||||
option disabled '1'
|
option disabled '1'
|
||||||
config wifi-iface
|
|
||||||
option device 'radio0'
|
|
||||||
option network 'wwan'
|
|
||||||
option mode 'sta'
|
|
||||||
option ssid 'example_03'
|
|
||||||
option ifname 'wwan03'
|
|
||||||
option encryption 'none'
|
|
||||||
option disabled '1'
|
|
||||||
[...]
|
[...]
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
**4. reload network configuration & start travelmate:**
|
**4. start travelmate:**
|
||||||
<pre><code>
|
<pre><code>
|
||||||
/etc/init.d/network reload
|
edit /etc/config/travelmate and set 'trm_enabled' to '1'
|
||||||
/etc/init.d/travelmate start
|
/etc/init.d/travelmate restart
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
**Q:** What's about 'trigger' and 'automatic' mode?
|
||||||
|
**A:** In "trigger" mode travelmate will be triggered solely by procd interface down events, whenever an uplink disappears travelmate tries n times (default 3) to find a new uplink or reconnect to the old one. The 'automatic' mode keeps travelmate in an active state and checks every n seconds the connection status / the uplink availability regardless of procd event trigger.
|
||||||
|
|
||||||
|
**Q:** What happen with misconfigured uplinks, e.g. due to outdated wlan passwords?
|
||||||
|
**A:** Travelmate tries n times (default 3) to connect, then the respective uplink SSID will be marked / renamed to '_SSID_\_err'. In this case use the builtin wireless station manager to update your wireless credentials. To disable this functionality at all set the Connection Limit ('trm\_maxretry') to '0', which means unlimited retries.
|
||||||
|
|
||||||
|
**Q:** Is travelmate compatible with CC/Openwrt?
|
||||||
|
**A:** Travelmate was never tested with an ancient CC/OpenWrt release ... it should still work, but no promises.
|
||||||
|
|
||||||
|
[...] to be continued [...]
|
||||||
## Support
|
## Support
|
||||||
Please join the travelmate discussion in this [forum thread](https://forum.openwrt.org/viewtopic.php?id=67697) or contact me by [mail](mailto:dev@brenken.org)
|
Please join the travelmate discussion in this [forum thread](https://forum.lede-project.org/t/travelmate-support-thread/5155) or contact me by [mail](mailto:dev@brenken.org)
|
||||||
|
|
||||||
## Removal
|
## Removal
|
||||||
* stop the travelmate daemon with _/etc/init.d/travelmate stop_
|
* stop the travelmate daemon with _/etc/init.d/travelmate stop_
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
config travelmate 'global'
|
config travelmate 'global'
|
||||||
option trm_enabled '0'
|
option trm_enabled '0'
|
||||||
option trm_debug '0'
|
option trm_debug '0'
|
||||||
option trm_maxwait '20'
|
option trm_triggerdelay '1'
|
||||||
|
option trm_automatic '1'
|
||||||
|
option trm_maxwait '30'
|
||||||
option trm_maxretry '3'
|
option trm_maxretry '3'
|
||||||
option trm_iw '1'
|
option trm_timeout '60'
|
||||||
|
option trm_iface 'trm_wwan'
|
||||||
|
option trm_rtfile '/tmp/trm_runtime.json'
|
||||||
|
|||||||
@@ -1,39 +1,73 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
START=85
|
START=25
|
||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
|
|
||||||
|
EXTRA_COMMANDS="status"
|
||||||
|
EXTRA_HELP=" status Print runtime information"
|
||||||
|
|
||||||
|
trm_init="/etc/init.d/travelmate"
|
||||||
trm_script="/usr/bin/travelmate.sh"
|
trm_script="/usr/bin/travelmate.sh"
|
||||||
|
|
||||||
boot()
|
boot()
|
||||||
{
|
{
|
||||||
ubus -t 30 wait_for network.interface
|
ubus -t 30 wait_for network.interface network.wireless 2>/dev/null
|
||||||
rc_procd start_service
|
rc_procd start_service
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service()
|
start_service()
|
||||||
{
|
{
|
||||||
|
if [ $("${trm_init}" enabled; printf "%u" ${?}) -eq 0 ]
|
||||||
|
then
|
||||||
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
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_service()
|
||||||
|
{
|
||||||
|
local rtfile="$(uci -q get travelmate.global.trm_rtfile)"
|
||||||
|
|
||||||
|
rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
|
||||||
|
> "${rtfile}"
|
||||||
|
rc_procd start_service
|
||||||
|
}
|
||||||
|
|
||||||
|
status()
|
||||||
|
{
|
||||||
|
local key keylist value rtfile="$(uci_get travelmate.global.trm_rtfile)"
|
||||||
|
|
||||||
|
rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
|
||||||
|
if [ -s "${rtfile}" ]
|
||||||
|
then
|
||||||
|
printf "%s\n" "::: travelmate runtime information"
|
||||||
|
json_load "$(cat "${rtfile}" 2>/dev/null)"
|
||||||
|
json_select data
|
||||||
|
json_get_keys keylist
|
||||||
|
for key in ${keylist}
|
||||||
|
do
|
||||||
|
json_get_var value "${key}"
|
||||||
|
printf " + %-18s : %s\n" "${key}" "${value}"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
printf "%s\n" "::: no travelmate runtime information available"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
service_triggers()
|
service_triggers()
|
||||||
{
|
{
|
||||||
local iface="$(uci -q get travelmate.global.trm_iface)"
|
local auto="$(uci_get travelmate.global.trm_automatic)"
|
||||||
|
|
||||||
if [ -z "${iface}" ]
|
if [ "${auto}" = "0" ]
|
||||||
then
|
then
|
||||||
procd_add_raw_trigger "interface.*.down" 1000 /etc/init.d/travelmate start
|
local trigger="$(uci_get travelmate.global.trm_iface)"
|
||||||
else
|
local delay="$(uci_get travelmate.global.trm_triggerdelay)"
|
||||||
for name in ${iface}
|
|
||||||
do
|
|
||||||
procd_add_interface_trigger "interface.*.down" "${name}" /etc/init.d/travelmate start
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
procd_add_config_trigger "config.change" "travelmate" /etc/init.d/travelmate start
|
PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
|
||||||
|
procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" start
|
||||||
|
fi
|
||||||
|
procd_add_reload_trigger "travelmate"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,27 +6,49 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# prepare environment
|
# set initial defaults
|
||||||
#
|
#
|
||||||
LC_ALL=C
|
LC_ALL=C
|
||||||
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
trm_ver="0.3.2"
|
trm_ver="1.0.2"
|
||||||
trm_enabled=1
|
trm_sysver="unknown"
|
||||||
|
trm_enabled=0
|
||||||
trm_debug=0
|
trm_debug=0
|
||||||
trm_maxwait=20
|
trm_automatic=1
|
||||||
trm_maxretry=3
|
trm_maxretry=3
|
||||||
trm_iw=1
|
trm_maxwait=30
|
||||||
|
trm_timeout=60
|
||||||
|
trm_iwinfo="$(command -v iwinfo)"
|
||||||
|
trm_radio=""
|
||||||
|
trm_rtfile="/tmp/trm_runtime.json"
|
||||||
|
trm_wpa="$(command -v wpa_supplicant)"
|
||||||
|
|
||||||
|
# load travelmate environment
|
||||||
|
#
|
||||||
f_envload()
|
f_envload()
|
||||||
{
|
{
|
||||||
# source required system libraries
|
local sys_call sys_desc sys_model sys_ver
|
||||||
|
|
||||||
|
# get system information
|
||||||
#
|
#
|
||||||
if [ -r "/lib/functions.sh" ]
|
sys_call="$(ubus -S call system board 2>/dev/null)"
|
||||||
|
if [ -n "${sys_call}" ]
|
||||||
then
|
then
|
||||||
. "/lib/functions.sh"
|
sys_desc="$(printf '%s' "${sys_call}" | jsonfilter -e '@.release.description')"
|
||||||
else
|
sys_model="$(printf '%s' "${sys_call}" | jsonfilter -e '@.model')"
|
||||||
f_log "error" "status ::: required system library not found"
|
sys_ver="$(cat /etc/turris-version 2>/dev/null)"
|
||||||
|
if [ -n "${sys_ver}" ]
|
||||||
|
then
|
||||||
|
sys_desc="${sys_desc}/${sys_ver}"
|
||||||
fi
|
fi
|
||||||
|
trm_sysver="${sys_model}, ${sys_desc}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# initialize lists
|
||||||
|
#
|
||||||
|
trm_devlist=""
|
||||||
|
trm_stalist=""
|
||||||
|
trm_radiolist=""
|
||||||
|
|
||||||
# load uci config and check 'enabled' option
|
# load uci config and check 'enabled' option
|
||||||
#
|
#
|
||||||
@@ -40,72 +62,134 @@ f_envload()
|
|||||||
|
|
||||||
if [ ${trm_enabled} -ne 1 ]
|
if [ ${trm_enabled} -ne 1 ]
|
||||||
then
|
then
|
||||||
f_log "info " "status ::: travelmate is currently disabled, please set 'trm_enabled' to '1' to use this service"
|
f_log "info" "travelmate is currently disabled, please set 'trm_enabled' to '1' to use this service"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for preferred wireless tool
|
# check eap capabilities
|
||||||
#
|
#
|
||||||
if [ ${trm_iw} -eq 1 ]
|
trm_eap="$("${trm_wpa}" -veap >/dev/null 2>&1; printf "%u" ${?})"
|
||||||
then
|
|
||||||
trm_scanner="$(which iw)"
|
|
||||||
else
|
|
||||||
trm_scanner="$(which iwinfo)"
|
|
||||||
fi
|
|
||||||
if [ -z "${trm_scanner}" ]
|
|
||||||
then
|
|
||||||
f_log "error" "status ::: no wireless tool for wlan scanning found, please install 'iw' or 'iwinfo'"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to bring down all STA interfaces
|
# gather radio information & bring down all STA interfaces
|
||||||
#
|
#
|
||||||
f_prepare()
|
f_prep()
|
||||||
{
|
{
|
||||||
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 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)"
|
||||||
|
local eaptype="$(uci -q get wireless."${config}".eap_type)"
|
||||||
|
|
||||||
if [ "${mode}" = "sta" ] && [ -n "${network}" ]
|
if ([ -z "${trm_radio}" ] || [ "${trm_radio}" = "${radio}" ]) && \
|
||||||
|
[ -z "$(printf "%s" "${trm_radiolist}" | grep -Fo " ${radio}")" ]
|
||||||
|
then
|
||||||
|
trm_radiolist="${trm_radiolist} ${radio}"
|
||||||
|
fi
|
||||||
|
if [ "${mode}" = "sta" ] && [ "${network}" = "${trm_iface}" ]
|
||||||
then
|
then
|
||||||
trm_stalist="${trm_stalist} ${config}_${network}"
|
|
||||||
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" "prepare ::: config: ${config}, interface: ${network}"
|
fi
|
||||||
|
if [ -z "${eaptype}" ] || [ ${trm_eap} -eq 0 ]
|
||||||
|
then
|
||||||
|
trm_stalist="${trm_stalist} ${config}_${radio}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
f_log "debug" "f_prep ::: config: ${config}, mode: ${mode}, network: ${network}, radio: ${radio}, disabled: ${disabled}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# check interface status
|
||||||
|
#
|
||||||
f_check()
|
f_check()
|
||||||
{
|
{
|
||||||
local ifname cnt=1 mode="${1}"
|
local ifname radio dev_status cnt=1 mode="${1}" status="${2:-"false"}"
|
||||||
trm_ifstatus="false"
|
|
||||||
|
|
||||||
|
trm_ifstatus="false"
|
||||||
|
ubus call network reload
|
||||||
while [ ${cnt} -le ${trm_maxwait} ]
|
while [ ${cnt} -le ${trm_maxwait} ]
|
||||||
do
|
do
|
||||||
if [ "${mode}" = "ap" ]
|
dev_status="$(ubus -S call network.wireless status 2>/dev/null)"
|
||||||
|
if [ -n "${dev_status}" ]
|
||||||
then
|
then
|
||||||
trm_ifstatus="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.up')"
|
if [ "${mode}" = "dev" ]
|
||||||
|
then
|
||||||
|
if [ "${trm_ifstatus}" != "${status}" ]
|
||||||
|
then
|
||||||
|
trm_ifstatus="${status}"
|
||||||
|
f_jsnup
|
||||||
|
fi
|
||||||
|
for radio in ${trm_radiolist}
|
||||||
|
do
|
||||||
|
trm_ifstatus="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e "@.${radio}.up")"
|
||||||
|
if [ "${trm_ifstatus}" = "true" ] && [ -z "$(printf "%s" "${trm_devlist}" | grep -Fo " ${radio}")" ]
|
||||||
|
then
|
||||||
|
trm_devlist="${trm_devlist} ${radio}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "${trm_radiolist}" = "${trm_devlist}" ] || [ ${cnt} -eq ${trm_maxwait} ] || [ "${status}" = "false" ]
|
||||||
|
then
|
||||||
|
ifname="${trm_devlist}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
ifname="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
|
ifname="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
|
||||||
if [ -n "${ifname}" ]
|
if [ -n "${ifname}" ]
|
||||||
then
|
then
|
||||||
trm_ifstatus="$(ubus -S call network.interface dump | jsonfilter -e "@.interface[@.device=\"${ifname}\"].up")"
|
trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "${mode}" = "initial" ] || [ "${trm_ifstatus}" = "true" ]
|
if [ "${mode}" = "initial" ] || [ "${trm_ifstatus}" = "true" ]
|
||||||
then
|
then
|
||||||
|
if [ "${mode}" != "initial" ] && [ "${trm_ifstatus}" != "${status}" ]
|
||||||
|
then
|
||||||
|
f_jsnup
|
||||||
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
cnt=$((cnt+1))
|
cnt=$((cnt+1))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
f_log "debug" "check ::: mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}"
|
f_log "debug" "f_check::: mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, cnt: ${cnt}, max-wait: ${trm_maxwait}, automatic: ${trm_automatic}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to write to syslog
|
# update runtime information
|
||||||
|
#
|
||||||
|
f_jsnup()
|
||||||
|
{
|
||||||
|
local status iface="${1}" radio="${2}" essid="${3}" bssid="${4}"
|
||||||
|
|
||||||
|
if [ "${trm_ifstatus}" = "true" ]
|
||||||
|
then
|
||||||
|
status="connected"
|
||||||
|
elif [ "${trm_ifstatus}" = "false" ]
|
||||||
|
then
|
||||||
|
status="not connected"
|
||||||
|
elif [ "${trm_ifstatus}" = "running" ]
|
||||||
|
then
|
||||||
|
status="running"
|
||||||
|
elif [ "${trm_ifstatus}" = "error" ]
|
||||||
|
then
|
||||||
|
status="error"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_init
|
||||||
|
json_add_object "data"
|
||||||
|
json_add_string "travelmate_status" "${status}"
|
||||||
|
json_add_string "travelmate_version" "${trm_ver}"
|
||||||
|
json_add_string "station_id" "${essid:-"-"}/${bssid:-"-"}"
|
||||||
|
json_add_string "station_interface" "${iface:-"n/a"}"
|
||||||
|
json_add_string "station_radio" "${radio:-"n/a"}"
|
||||||
|
json_add_string "last_rundate" "$(/bin/date "+%d.%m.%Y %H:%M:%S")"
|
||||||
|
json_add_string "system" "${trm_sysver}"
|
||||||
|
json_close_object
|
||||||
|
json_dump > "${trm_rtfile}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# write to syslog
|
||||||
#
|
#
|
||||||
f_log()
|
f_log()
|
||||||
{
|
{
|
||||||
@@ -114,91 +198,136 @@ f_log()
|
|||||||
|
|
||||||
if [ -n "${log_msg}" ] && ([ "${class}" != "debug" ] || [ ${trm_debug} -eq 1 ])
|
if [ -n "${log_msg}" ] && ([ "${class}" != "debug" ] || [ ${trm_debug} -eq 1 ])
|
||||||
then
|
then
|
||||||
logger -t "travelmate-[${trm_ver}] ${class}" "${log_msg}"
|
logger -p "${class}" -t "travelmate-[${trm_ver}]" "${log_msg}"
|
||||||
if [ "${class}" = "error" ]
|
if [ "${class}" = "err" ]
|
||||||
then
|
then
|
||||||
exit 255
|
trm_ifstatus="error"
|
||||||
|
f_jsnup
|
||||||
|
logger -p "${class}" -t "travelmate-[${trm_ver}]" "Please check 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md' (${trm_sysver})"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# main function for connection handling
|
||||||
|
#
|
||||||
f_main()
|
f_main()
|
||||||
{
|
{
|
||||||
local ap_list ssid_list config network ssid cnt=1
|
local dev config raw_scan essid_list bssid_list sta_essid sta_bssid sta_radio sta_iface cnt=1
|
||||||
local sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
|
|
||||||
|
|
||||||
f_check "initial"
|
f_check "initial"
|
||||||
if [ "${trm_ifstatus}" != "true" ]
|
if [ "${trm_ifstatus}" != "true" ]
|
||||||
then
|
then
|
||||||
config_load wireless
|
config_load wireless
|
||||||
config_foreach f_prepare wifi-iface
|
config_foreach f_prep wifi-iface
|
||||||
if [ -n "$(uci -q changes wireless)" ]
|
if [ -n "$(uci -q changes wireless)" ]
|
||||||
then
|
then
|
||||||
uci -q commit wireless
|
uci -q commit wireless
|
||||||
ubus call network reload
|
|
||||||
fi
|
fi
|
||||||
f_check "ap"
|
f_check "dev" "running"
|
||||||
ap_list="$(ubus -S call network.wireless status | jsonfilter -e '@.*.interfaces[@.config.mode="ap"].ifname')"
|
f_log "debug" "f_main ::: iwinfo: ${trm_iwinfo}, eap_rc: ${trm_eap}, dev_list: ${trm_devlist}, sta_list: ${trm_stalist}"
|
||||||
f_log "debug" "main ::: ap-list: ${ap_list}, sta-list: ${trm_stalist}"
|
for dev in ${trm_devlist}
|
||||||
if [ -z "${ap_list}" ] || [ -z "${trm_stalist}" ]
|
|
||||||
then
|
|
||||||
f_log "error" "status ::: no usable AP/STA configuration found"
|
|
||||||
fi
|
|
||||||
for ap in ${ap_list}
|
|
||||||
do
|
do
|
||||||
while [ ${cnt} -le ${trm_maxretry} ]
|
cnt=1
|
||||||
do
|
if [ -z "$(printf "%s" "${trm_stalist}" | grep -Fo "_${dev}")" ]
|
||||||
if [ ${trm_iw} -eq 1 ]
|
|
||||||
then
|
then
|
||||||
ssid_list="$(${trm_scanner} dev "${ap}" scan 2>/dev/null | \
|
continue
|
||||||
awk '/SSID: /{if(!seen[$0]++){printf "\"";for(i=2; i<=NF; i++)if(i==2)printf $i;else printf " "$i;printf "\" "}}')"
|
|
||||||
else
|
|
||||||
ssid_list="$(${trm_scanner} "${ap}" scan | \
|
|
||||||
awk '/ESSID: ".*"/{ORS=" ";if (!seen[$0]++) for(i=2; i<=NF; i++) print $i}')"
|
|
||||||
fi
|
fi
|
||||||
f_log "debug" "main ::: scan-tool: ${trm_scanner}, ssidlist: ${ssid_list}"
|
while [ ${trm_maxretry} -eq 0 ] || [ ${cnt} -le ${trm_maxretry} ]
|
||||||
if [ -n "${ssid_list}" ]
|
do
|
||||||
|
raw_scan="$(${trm_iwinfo} "${dev}" scan)"
|
||||||
|
essid_list="$(printf "%s" "${raw_scan}" | awk '/ESSID: "/{ORS=" ";if (!seen[$0]++) for(i=2; i<=NF; i++) print $i}')"
|
||||||
|
bssid_list="$(printf "%s" "${raw_scan}" | awk '/Address: /{ORS=" ";if (!seen[$5]++) print $5}')"
|
||||||
|
f_log "debug" "f_main ::: dev: ${dev}, ssid_list: ${essid_list}, bssid_list: ${bssid_list}"
|
||||||
|
if [ -n "${essid_list}" ] || [ -n "${bssid_list}" ]
|
||||||
then
|
then
|
||||||
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)\""
|
sta_essid="$(uci -q get wireless."${config}".ssid)"
|
||||||
if [ -n "$(printf "${ssid_list}" | grep -Fo "${ssid}")" ]
|
sta_bssid="$(uci -q get wireless."${config}".bssid)"
|
||||||
|
sta_iface="$(uci -q get wireless."${config}".network)"
|
||||||
|
if (([ -n "$(printf "%s" "${essid_list}" | grep -Fo "\"${sta_essid}\"")" ] && [ -z "${sta_bssid}" ]) || \
|
||||||
|
([ -n "$(printf "%s" "${bssid_list}" | grep -Fo "${sta_bssid}")" ] && [ -z "$(printf "%s" "${essid_list}" | grep -Fo "\"${sta_essid}\"")" ]) || \
|
||||||
|
([ -n "$(printf "%s" "${essid_list}" | grep -Fo "\"${sta_essid}\"")" ] && [ -n "$(printf "%s" "${bssid_list}" | grep -Fo "${sta_bssid}")" ])) && \
|
||||||
|
[ "${dev}" = "${sta_radio}" ]
|
||||||
then
|
then
|
||||||
uci -q set wireless."${config}".disabled=0
|
uci -q set wireless."${config}".disabled=0
|
||||||
uci -q commit wireless
|
|
||||||
ubus call network reload
|
|
||||||
f_check "sta"
|
f_check "sta"
|
||||||
if [ "${trm_ifstatus}" = "true" ]
|
if [ "${trm_ifstatus}" = "true" ]
|
||||||
then
|
then
|
||||||
f_log "info " "status ::: wwan interface connected to uplink ${ssid} (${cnt}/${trm_maxretry}, ${sysver})"
|
|
||||||
sleep 5
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
uci -q set wireless."${config}".disabled=1
|
|
||||||
uci -q commit wireless
|
uci -q commit wireless
|
||||||
ubus call network reload
|
f_log "info" "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${trm_sysver})"
|
||||||
f_log "info " "status ::: wwan interface can't connect to uplink ${ssid} (${cnt}/${trm_maxretry}, ${sysver})"
|
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
|
||||||
|
return 0
|
||||||
|
elif [ ${trm_maxretry} -ne 0 ] && [ ${cnt} -eq ${trm_maxretry} ]
|
||||||
|
then
|
||||||
|
uci -q set wireless."${config}".disabled=1
|
||||||
|
if [ -n "${sta_essid}" ]
|
||||||
|
then
|
||||||
|
uci -q set wireless."${config}".ssid="${sta_essid}_err"
|
||||||
fi
|
fi
|
||||||
|
if [ -n "${sta_bssid}" ]
|
||||||
|
then
|
||||||
|
uci -q set wireless."${config}".bssid="${sta_bssid}_err"
|
||||||
|
fi
|
||||||
|
uci -q commit wireless
|
||||||
|
f_check "dev"
|
||||||
|
f_log "info" "can't connect to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${cnt}/${trm_maxretry}), uplink disabled (${trm_sysver})"
|
||||||
|
else
|
||||||
|
if [ ${trm_maxretry} -eq 0 ]
|
||||||
|
then
|
||||||
|
cnt=0
|
||||||
|
fi
|
||||||
|
uci -q revert wireless
|
||||||
|
f_check "dev"
|
||||||
|
f_log "info" "can't connect to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${cnt}/${trm_maxretry}) (${trm_sysver})"
|
||||||
|
fi
|
||||||
|
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
|
||||||
f_log "info " "status ::: empty uplink list (${cnt}/${trm_maxretry}, ${sysver})"
|
|
||||||
fi
|
fi
|
||||||
cnt=$((cnt+1))
|
cnt=$((cnt+1))
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
f_log "info " "status ::: no wwan uplink found (${sysver})"
|
if [ ! -s "${trm_rtfile}" ]
|
||||||
|
then
|
||||||
|
trm_ifstatus="false"
|
||||||
|
f_jsnup
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
f_log "info " "status ::: wwan uplink still connected (${sysver})"
|
if [ ! -s "${trm_rtfile}" ]
|
||||||
|
then
|
||||||
|
config="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].section')"
|
||||||
|
sta_radio="$(uci -q get wireless."${config}".device)"
|
||||||
|
sta_essid="$(uci -q get wireless."${config}".ssid)"
|
||||||
|
sta_bssid="$(uci -q get wireless."${config}".bssid)"
|
||||||
|
sta_iface="$(uci -q get wireless."${config}".network)"
|
||||||
|
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "${trm_procd}" = "true" ]
|
# source required system libraries
|
||||||
|
#
|
||||||
|
if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]
|
||||||
then
|
then
|
||||||
|
. "/lib/functions.sh"
|
||||||
|
. "/usr/share/libubox/jshn.sh"
|
||||||
|
else
|
||||||
|
f_log "err" "system libraries not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# control travelmate actions
|
||||||
|
#
|
||||||
f_envload
|
f_envload
|
||||||
f_main
|
f_main
|
||||||
fi
|
while [ ${trm_automatic} -eq 1 ]
|
||||||
|
do
|
||||||
|
sleep ${trm_timeout}
|
||||||
|
f_envload
|
||||||
|
f_main
|
||||||
|
done
|
||||||
exit 0
|
exit 0
|
||||||
Reference in New Issue
Block a user