* 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
## 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
* 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
[...]
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>
config wifi-iface
option device 'radio0'
option network 'lan'
- option ifname 'wlan0'
option mode 'ap'
option ssid 'example_ap'
option encryption 'psk2+ccmp'
option network 'wwan'
option mode 'sta'
option ssid 'example_01'
- option ifname 'wwan01'
option encryption 'psk2+ccmp'
option key 'abc'
option disabled '1'
option network 'wwan'
option mode 'sta'
option ssid 'example_02'
- option ifname 'wwan02'
option encryption 'psk2+ccmp'
option key 'xyz'
option disabled '1'
option network 'wwan'
option mode 'sta'
option ssid 'example_03'
- option ifname 'wwan03'
option encryption 'none'
option disabled '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
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
}
#
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()
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
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
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
}
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
}
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}" ]
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
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
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
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 ]
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}
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
}
f_envload
f_main
fi
-exit 0
\ No newline at end of file
+exit 0