travelmate: update 0.3.5 4030/head
authorDirk Brenken <dev@brenken.org>
Fri, 17 Feb 2017 18:01:20 +0000 (19:01 +0100)
committerDirk Brenken <dev@brenken.org>
Sat, 18 Feb 2017 07:54:11 +0000 (08:54 +0100)
* add 'enabled' check in init script
* support multiple radios (see online doc)
* fix race condition in ap check

Signed-off-by: Dirk Brenken <dev@brenken.org>
net/travelmate/Makefile
net/travelmate/files/README.md
net/travelmate/files/travelmate.init
net/travelmate/files/travelmate.sh

index 6f2d2a0d2cec69562ccd373e3805bdccd0e6e5cb..ca31adb0f7aa9183796b52c42ed4f77e4320164e 100644 (file)
@@ -6,7 +6,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=travelmate
-PKG_VERSION:=0.3.2
+PKG_VERSION:=0.3.5
 PKG_RELEASE:=1
 PKG_LICENSE:=GPL-3.0+
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
index 4cd39d60d285fdbff831b6a9baac6d3fdb414fea..0570558d9a2ebb40ca080c97f5b35e7e0b7a1b55 100644 (file)
@@ -9,6 +9,7 @@ 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
+* support multiple radios
 * procd init system support
 * procd based hotplug support, the travelmate start will be triggered by interface triggers
 * status & debug logging to syslog
@@ -20,7 +21,7 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
 ## OpenWrt / LEDE trunk Installation & Usage
 * download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/packages)
 * install 'travelmate' (_opkg install travelmate_)
-* configure your network to support (multiple) wlan uplinks and set travelmate config options (details see below)
+* configure your network to support (multiple) wlan uplinks and set travelmate config options (see below)
 * set 'trm\_enabled' option in travelmate config to '1'
 * travelmate starts automatically during boot and will be triggered by procd interface triggers
 
@@ -43,6 +44,7 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
     * 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\_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)
 
 ## Setup
@@ -59,11 +61,6 @@ config interface 'wwan'
 [...]
 config zone
         option name 'wan'
-        option input 'REJECT'
-        option output 'ACCEPT'
-        option forward 'REJECT'
-        option masq '1'
-        option mtu_fix '1'
         option network 'wan wan6 wwan'
 [...]
 </code></pre>
@@ -74,7 +71,6 @@ config zone
 config wifi-iface
         option device 'radio0'
         option network 'lan'
-        option ifname 'wlan0'
         option mode 'ap'
         option ssid 'example_ap'
         option encryption 'psk2+ccmp'
@@ -86,7 +82,6 @@ config wifi-iface
         option network 'wwan'
         option mode 'sta'
         option ssid 'example_01'
-        option ifname 'wwan01'
         option encryption 'psk2+ccmp'
         option key 'abc'
         option disabled '1'
@@ -95,7 +90,6 @@ config wifi-iface
         option network 'wwan'
         option mode 'sta'
         option ssid 'example_02'
-        option ifname 'wwan02'
         option encryption 'psk2+ccmp'
         option key 'xyz'
         option disabled '1'
@@ -104,7 +98,6 @@ config wifi-iface
         option network 'wwan'
         option mode 'sta'
         option ssid 'example_03'
-        option ifname 'wwan03'
         option encryption 'none'
         option disabled '1'
 [...]
index 255a641879611dc136843b21aef8a37f345cb80b..c6f81255ab5da44b997d2936f34c883244168cc5 100755 (executable)
@@ -5,26 +5,26 @@ USE_PROCD=1
 
 trm_script="/usr/bin/travelmate.sh"
 
-boot()
-{
-    ubus -t 30 wait_for network.interface
-    rc_procd start_service
-}
-
 start_service()
 {
-    procd_open_instance "travelmate"
-    procd_set_param env trm_procd="true"
-    procd_set_param command "${trm_script}" "${@}"
-    procd_set_param stdout 1
-    procd_set_param stderr 1
-    procd_close_instance
+    if [ $(/etc/init.d/travelmate enabled; printf ${?}) -eq 0 ]
+    then
+        ubus -t 30 wait_for network.interface
+        procd_open_instance "travelmate"
+        procd_set_param env trm_procd="true"
+        procd_set_param command "${trm_script}" "${@}"
+        procd_set_param stdout 1
+        procd_set_param stderr 1
+        procd_close_instance
+    fi
 }
 
 service_triggers()
 {
     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}" ]
     then
         procd_add_raw_trigger "interface.*.down" 1000 /etc/init.d/travelmate start
@@ -34,6 +34,5 @@ service_triggers()
             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_close_trigger
 }
index f626f390c01a85ee343e78427439916904dd5372..734b0167ca2b89f7f8b9620db9cf53cc0cf1ddd4 100755 (executable)
 #
 LC_ALL=C
 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-trm_ver="0.3.2"
+trm_ver="0.3.5"
 trm_enabled=1
 trm_debug=0
 trm_maxwait=20
 trm_maxretry=3
+trm_radio="*"
 trm_iw=1
 
 f_envload()
@@ -25,7 +26,7 @@ f_envload()
     then
         . "/lib/functions.sh"
     else
-        f_log "error" "status  ::: required system library not found"
+        f_log "error" "required system library not found"
     fi
 
     # load uci config and check 'enabled' option
@@ -40,7 +41,7 @@ f_envload()
 
     if [ ${trm_enabled} -ne 1 ]
     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
     fi
 
@@ -54,7 +55,7 @@ f_envload()
     fi
     if [ -z "${trm_scanner}" ]
     then
-        f_log "error" "status  ::: no wireless tool for wlan scanning found, please install 'iw' or 'iwinfo'"
+        f_log "error" "no wireless tool for wlan scanning found, please install 'iw' or 'iwinfo'"
     fi
 }
 
@@ -73,7 +74,7 @@ f_prepare()
         if [ -z "${disabled}" ] || [ "${disabled}" = "0" ]
         then
             uci -q set wireless."${config}".disabled=1
-            f_log "debug" "prepare ::: config: ${config}, interface: ${network}"
+            f_log "debug" "config: ${config}, interface: ${network}"
         fi
     fi
 }
@@ -87,7 +88,11 @@ f_check()
     do
         if [ "${mode}" = "ap" ]
         then
-            trm_ifstatus="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.up')"
+            ifname="$(ubus -S call network.wireless status | jsonfilter -l1 -e "@.${trm_radio}.interfaces[@.config.mode=\"ap\"].ifname")"
+            if [ -n "${ifname}" ]
+            then
+                trm_ifstatus="$(ubus -S call network.wireless status | jsonfilter -l1 -e "@.${trm_radio}.up")"
+            fi
         else
             ifname="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
             if [ -n "${ifname}" ]
@@ -102,7 +107,7 @@ f_check()
         cnt=$((cnt+1))
         sleep 1
     done
-    f_log "debug" "check   ::: mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}"
+    f_log "debug" "mode: ${mode}, radio: ${trm_radio}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}"
 }
 
 # function to write to syslog
@@ -117,6 +122,7 @@ f_log()
         logger -t "travelmate-[${trm_ver}] ${class}" "${log_msg}"
         if [ "${class}" = "error" ]
         then
+            logger -t "travelmate-[${trm_ver}] ${class}" "Please check the online documentation 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md'"
             exit 255
         fi
     fi
@@ -127,6 +133,7 @@ f_main()
     local ap_list ssid_list config network ssid cnt=1
     local sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
 
+    f_log "info " "start travelmate scanning ..."
     f_check "initial"
     if [ "${trm_ifstatus}" != "true" ]
     then
@@ -138,14 +145,15 @@ f_main()
             ubus call network reload
         fi
         f_check "ap"
-        ap_list="$(ubus -S call network.wireless status | jsonfilter -e '@.*.interfaces[@.config.mode="ap"].ifname')"
-        f_log "debug" "main    ::: ap-list: ${ap_list}, sta-list: ${trm_stalist}"
+        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: ${ap_list}, sta-list: ${trm_stalist}"
         if [ -z "${ap_list}" ] || [ -z "${trm_stalist}" ]
         then
-            f_log "error" "status  ::: no usable AP/STA configuration found"
+            f_log "error" "no usable AP/STA configuration found"
         fi
         for ap in ${ap_list}
         do
+            cnt=1
             while [ ${cnt} -le ${trm_maxretry} ]
             do
                 if [ ${trm_iw} -eq 1 ]
@@ -156,7 +164,7 @@ f_main()
                     ssid_list="$(${trm_scanner} "${ap}" scan | \
                         awk '/ESSID: ".*"/{ORS=" ";if (!seen[$0]++) for(i=2; i<=NF; i++) print $i}')"
                 fi
-                f_log "debug" "main    ::: scan-tool: ${trm_scanner}, ssidlist: ${ssid_list}"
+                f_log "debug" "scanner: ${trm_scanner}, ap: ${ap}, ssids: ${ssid_list}"
                 if [ -n "${ssid_list}" ]
                 then
                     for sta in ${trm_stalist}
@@ -172,27 +180,27 @@ f_main()
                             f_check "sta"
                             if [ "${trm_ifstatus}" = "true" ]
                             then
-                                f_log "info " "status  ::: wwan interface connected to uplink ${ssid} (${cnt}/${trm_maxretry}, ${sysver})"
+                                f_log "info " "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
                                 ubus call network reload
-                                f_log "info " "status  ::: wwan interface can't connect to uplink ${ssid} (${cnt}/${trm_maxretry}, ${sysver})"
+                                f_log "info " "wwan interface can't connect to uplink ${ssid} (${cnt}/${trm_maxretry}, ${sysver})"
                             fi
                         fi
                     done
                 else
-                    f_log "info " "status  ::: empty uplink list (${cnt}/${trm_maxretry}, ${sysver})"
+                    f_log "info " "empty uplink list (${cnt}/${trm_maxretry}, ${sysver})"
                 fi
                 cnt=$((cnt+1))
                 sleep 5
             done
         done
-        f_log "info " "status  ::: no wwan uplink found (${sysver})"
+        f_log "info " "no wwan uplink found (${sysver})"
     else
-        f_log "info " "status  ::: wwan uplink still connected (${sysver})"
+        f_log "info " "wwan uplink still connected (${sysver})"
     fi
 }
 
@@ -201,4 +209,4 @@ then
     f_envload
     f_main
 fi
-exit 0
\ No newline at end of file
+exit 0