From: Dirk Brenken Date: Sun, 2 Apr 2017 05:41:57 +0000 (+0200) Subject: travelmate: update 0.6.0 X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=cf919894d64f2dcdf553d5bf62871bdc8706aa27;p=feed%2Fpackages.git travelmate: update 0.6.0 * rework automatic mode (active scan/re-connection handling): * much more procd & resource friendly * now enabled by default * save runtime information in ubus service (data section) * final backend preparation for new LuCI-GUI (still WIP!) * documentation update Signed-off-by: Dirk Brenken --- diff --git a/net/travelmate/Makefile b/net/travelmate/Makefile index 9b3048080e..911a3f922d 100644 --- a/net/travelmate/Makefile +++ b/net/travelmate/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=travelmate -PKG_VERSION:=0.5.0 +PKG_VERSION:=0.6.0 PKG_RELEASE:=1 PKG_LICENSE:=GPL-3.0+ PKG_MAINTAINER:=Dirk Brenken diff --git a/net/travelmate/files/README.md b/net/travelmate/files/README.md index 5671e78d9b..b77f8d6b39 100644 --- a/net/travelmate/files/README.md +++ b/net/travelmate/files/README.md @@ -9,10 +9,10 @@ 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 * easy setup within normal OpenWrt/LEDE environment * fast uplink connections -* "active mode" support, where travelmate will be restarted every n seconds (default 60) and checks the existing uplink connection regardless of ifdown event trigger +* manual / automatic mode support, the latter one checks the existing uplink connection regardless of ifdown event trigger every n seconds * support of devices with multiple radios -* procd init system support -* procd based hotplug support, the travelmate start will be triggered by interface triggers +* procd init and hotplug support +* runtime information accessible via ubus service call * status & debug logging to syslog ## Prerequisites @@ -32,23 +32,39 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a * 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: * trm\_enabled => main switch to enable/disable the travelmate service (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\_automatic => keep travelmate in an active state (default: '1', enabled) + * trm\_maxwait => how long (in seconds) should travelmate wait for a successful wlan interface reload action (default: '30') * 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\_timeout => timeout in seconds for "automatic mode" (default: '60') * 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\_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: wan wwan) + + +## Runtime information + +**receive travelmate information via ubus:** +

+ubus call service get_data '{"name":"travelmate"}'
+This will output the current connection status, e.g.:
+{
+    "travelmate": {
+        "travelmate": {
+            "last_rundate": "02.04.2017 07:22:03",
+            "online_status": "true",
+            "station_interface": "wwan",
+            "station_radio": "radio1",
+            "station_ssid": "blackhole",
+            "system": "LEDE Reboot SNAPSHOT r3888-8fb39f1682",
+            "travelmate_version": "0.6.0"
+        }
+    }
+}
+
## Setup **1. configure a wwan interface in /etc/config/network:** diff --git a/net/travelmate/files/travelmate.conf b/net/travelmate/files/travelmate.conf index 53c62218d4..00b7b127c6 100644 --- a/net/travelmate/files/travelmate.conf +++ b/net/travelmate/files/travelmate.conf @@ -4,8 +4,8 @@ config travelmate 'global' option trm_enabled '0' option trm_debug '0' - option trm_iface 'wan wwan' - option trm_active '0' + option trm_iface 'wwan' + option trm_automatic '1' option trm_maxwait '30' option trm_maxretry '3' option trm_timeout '60' diff --git a/net/travelmate/files/travelmate.init b/net/travelmate/files/travelmate.init index f17aa1a9e8..f0a6a67873 100755 --- a/net/travelmate/files/travelmate.init +++ b/net/travelmate/files/travelmate.init @@ -24,11 +24,6 @@ start_service() fi } -stop_service() -{ - killall -q -TERM "travelmate.sh" -} - service_triggers() { local iface="$(uci -q get travelmate.global.trm_iface)" diff --git a/net/travelmate/files/travelmate.sh b/net/travelmate/files/travelmate.sh index 3e277def75..b9d728b884 100755 --- a/net/travelmate/files/travelmate.sh +++ b/net/travelmate/files/travelmate.sh @@ -10,28 +10,34 @@ # LC_ALL=C PATH="/usr/sbin:/usr/bin:/sbin:/bin" -trm_ver="0.5.0" +trm_ver="0.6.0" trm_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')" -trm_enabled=1 +trm_enabled=0 trm_debug=0 -trm_active=0 +trm_automatic=0 trm_maxwait=30 trm_maxretry=3 trm_timeout=60 trm_iw=1 +# source required system library +# +if [ -r "/lib/functions.sh" ] +then + . "/lib/functions.sh" +else + f_log "error" "required system library not found" +fi + # f_envload: load travelmate environment # f_envload() { - # source required system libraries + # initialize lists # - if [ -r "/lib/functions.sh" ] - then - . "/lib/functions.sh" - else - f_log "error" "required system library not found" - fi + trm_aplist="" + trm_stalist="" + trm_radiolist="" # load uci config and check 'enabled' option # @@ -125,20 +131,34 @@ f_check() cnt=$((cnt+1)) sleep 1 done - f_log "debug" "mode: ${mode}, 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}, automatic: ${trm_automatic}" } -# f_active: keep travelmate in an active state +# f_ubus: update ubus service # -f_active() +f_ubus() { - if [ ${trm_active} -eq 1 ] - then - (sleep ${trm_timeout}; /etc/init.d/travelmate start >/dev/null 2>&1) & - fi + local active_triggers iface="${1}" radio="${2}" ssid="${3}" + + for name in ${trm_iface} + do + active_triggers="${active_triggers}[\"interface.*.down\",[\"if\",[\"eq\",\"interface\",\"${name}\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]]," + done + active_triggers="${active_triggers}[\"config.change\",[\"if\",[\"eq\",\"package\",\"travelmate\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]]" + + ubus call service add "{\"name\":\"travelmate\", + \"instances\":{\"travelmate\":{\"command\":[\"/usr/bin/travelmate.sh\"], + \"data\":{\"travelmate_version\":\"${trm_ver}\", + \"station_interface\":\"${iface}\", + \"station_radio\":\"${radio}\", + \"station_ssid\":\"${ssid}\", + \"last_rundate\":\"$(/bin/date "+%d.%m.%Y %H:%M:%S")\", + \"online_status\":\"${trm_ifstatus}\", + \"system\":\"${trm_sysver}\"}}}, + \"triggers\":[${active_triggers}]}" } -# f_log: function to write to syslog +# f_log: write to syslog, exit on error # f_log() { @@ -151,7 +171,6 @@ f_log() if [ "${class}" = "error" ] then logger -t "travelmate-[${trm_ver}] ${class}" "Please check 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md' (${trm_sysver})" - f_active exit 255 fi fi @@ -161,7 +180,7 @@ f_log() # f_main() { - local ssid_list config ap_radio sta_radio ssid cnt=1 + local config ssid_list ap ap_radio sta_ssid sta_radio sta_iface cnt=1 f_check "initial" if [ "${trm_ifstatus}" != "true" ] @@ -172,6 +191,7 @@ f_main() then uci -q commit wireless ubus call network reload + sleep 5 fi f_check "ap" f_log "debug" "ap-list: ${trm_aplist}, sta-list: ${trm_stalist}" @@ -205,8 +225,9 @@ f_main() do config="${sta%%_*}" sta_radio="${sta##*_}" - ssid="\"$(uci -q get wireless."${config}".ssid)\"" - if [ -n "$(printf "${ssid_list}" | grep -Fo "${ssid}")" ] && [ "${ap_radio}" = "${sta_radio}" ] + sta_ssid="$(uci -q get wireless."${config}".ssid)" + sta_iface="$(uci -q get wireless."${config}".network)" + if [ -n "$(printf "${ssid_list}" | grep -Fo "\"${sta_ssid}\"")" ] && [ "${ap_radio}" = "${sta_radio}" ] then uci -q set wireless."${config}".disabled=0 ubus call network reload @@ -214,13 +235,15 @@ f_main() if [ "${trm_ifstatus}" = "true" ] then uci -q commit wireless - f_log "info " "wwan interface connected to uplink ${ssid} (${trm_sysver})" + f_log "info " "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_ssid}' (${trm_sysver})" sleep 5 + f_ubus "${sta_iface}" "${sta_radio}" "${sta_ssid}" return 0 else uci -q revert wireless ubus call network reload - f_log "info " "wwan interface can't connect to uplink ${ssid} (${trm_sysver})" + f_log "info " "interface '${sta_iface}' on '${sta_radio}' can't connect to uplink '${sta_ssid}' (${trm_sysver})" + f_ubus "${sta_iface}" "${sta_radio}" "${sta_ssid}" fi fi done @@ -233,9 +256,11 @@ f_main() } f_envload -if [ ${trm_active} -eq 0 ] || ([ ${trm_active} -eq 1 ] && [ $(pgrep -f "/usr/bin/travelmate.sh" | wc -l) -eq 3 ]) -then +f_main +while [ ${trm_automatic} -eq 1 ] +do + sleep ${trm_timeout} + f_envload f_main - f_active -fi +done exit 0