Browse Source

Merge pull request #5636 from dibdot/travelmate

travelmate: release 1.1.0
lilik-openwrt-22.03
dibdot 7 years ago
committed by GitHub
parent
commit
9df6a01bb1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 160 additions and 110 deletions
  1. +2
    -2
      net/travelmate/Makefile
  2. +25
    -25
      net/travelmate/files/README.md
  3. +6
    -4
      net/travelmate/files/travelmate.conf
  4. +5
    -5
      net/travelmate/files/travelmate.init
  5. +122
    -74
      net/travelmate/files/travelmate.sh

+ 2
- 2
net/travelmate/Makefile View File

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=travelmate PKG_NAME:=travelmate
PKG_VERSION:=1.0.2
PKG_VERSION:=1.1.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>
@ -17,7 +17,7 @@ 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
DEPENDS:=+iwinfo +jshn +jsonfilter +uclient-fetch
PKGARCH:=all PKGARCH:=all
endef endef


+ 25
- 25
net/travelmate/files/README.md View File

@ -2,27 +2,29 @@
## Description ## Description
If you’re planning an upcoming vacation or a business trip, taking your laptop, tablet or smartphone give you the ability to connect with friends or complete work on the go. But many hotels don’t have a secure wireless network setup or you’re limited on using a single device at once. Investing in a portable, mini travel router is a great way to connect all of your devices at once while having total control over your own personalized wireless network. If you’re planning an upcoming vacation or a business trip, taking your laptop, tablet or smartphone give you the ability to connect with friends or complete work on the go. But many hotels don’t have a secure wireless network setup or you’re limited on using a single device at once. Investing in a portable, mini travel router is a great way to connect all of your devices at once while having total control over your own personalized wireless network.
A logical combination of AP+STA mode on one physical radio allows most of OpenWrt/LEDE supported router devices to connect to a wireless hotspot/station (STA) and provide a wireless access point (AP) from that hotspot at the same time. Downside of this solution: whenever the STA interface looses the connection it will go into an active scan cycle which renders the radio unusable for AP mode operation, therefore the AP is taken down if the STA looses its association.
A logical combination of AP+STA mode on one physical radio allows most of OpenWrt supported router devices to connect to a wireless hotspot/station (STA) and provide a wireless access point (AP) from that hotspot at the same time. Downside of this solution: whenever the STA interface looses the connection it will go into an active scan cycle which renders the radio unusable for AP mode operation, therefore the AP is taken down if the STA looses its association.
To avoid these kind of deadlocks, travelmate set all station interfaces in an "always off" mode and connects automatically to available/configured hotspots. To avoid these kind of deadlocks, travelmate set all station interfaces in an "always off" mode and connects automatically to available/configured hotspots.
## 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 environment
* strong LuCI-Support with builtin interface wizard and a wireless station manager * strong LuCI-Support with builtin interface wizard and a wireless station manager
* fast uplink connections * fast uplink connections
* support all kinds of uplinks, incl. hidden and enterprise uplinks * support all kinds of uplinks, incl. hidden and enterprise uplinks
* 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 * 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
* checks continuously the signal quality for conditional uplink (dis-) connections
* captive portal detection with internet online check and a 'heartbeat' function to keep the uplink connection up & running
* support of devices with multiple radios * support of devices with multiple radios
* procd init and hotplug support * procd init and hotplug support
* runtime information available via LuCI & via 'status' init command * runtime information available via LuCI & via 'status' init command
* status & debug logging to syslog * status & debug logging to syslog
## Prerequisites ## Prerequisites
* [LEDE](https://www.lede-project.org) 17.01 or latest snapshot
* iwinfo for wlan scanning
* [OpenWrt](https://openwrt.org), tested with the stable release series (17.01.x) and with the latest OpenWrt snapshot
* iwinfo for wlan scanning, uclient-fetch for captive portal detection
## LEDE trunk Installation & Usage
* download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/packages)
## Installation & Usage
* download the package [here](https://downloads.openwrt.org/snapshots/packages/x86_64/packages)
* install 'travelmate' (_opkg install travelmate_) * install 'travelmate' (_opkg install travelmate_)
* configure your network: * configure your network:
* recommended: use the LuCI frontend with builtin interface wizard and a wireless station manager * recommended: use the LuCI frontend with builtin interface wizard and a wireless station manager
@ -30,34 +32,36 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
* at least you need one configured AP and one STA interface * 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.openwrt.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
## 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: * 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\_debug => enable/disable debug logging (default: '0', disabled)
* 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 connect to an uplink, '0' means unlimited retries. (default: '3')
* trm\_timeout => timeout in seconds for "automatic mode" (default: '60')
* trm\_enabled => main switch to enable/disable the travelmate service (bool/default: '0', disabled)
* trm\_debug => enable/disable debug logging (bool/default: '0', disabled)
* trm\_automatic => keep travelmate in an active state (bool/default: '1', enabled)
* trm\_captive => enable/disable the captive portal detection (bool/default: '1', enabled)
* trm\_minquality => minimum signal quality threshold as percent for conditional uplink (dis-) connections (int/default: '30')
* trm\_maxwait => how long (in seconds) should travelmate wait for a successful wlan interface reload action (int/default: '30')
* trm\_maxretry => how many times should travelmate try to connect to an uplink, '0' means unlimited retries. (int/default: '3')
* trm\_timeout => timeout in seconds for "automatic mode" (int/default: '60')
* 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 => main uplink / procd trigger network interface (default: trm_wwan) * trm\_iface => main uplink / procd trigger network interface (default: trm_wwan)
* trm\_triggerdelay => additional trigger delay in seconds before travelmate processing starts (default: '2')
* trm\_triggerdelay => additional trigger delay in seconds before travelmate processing starts (int/default: '2')
## Runtime information ## Runtime information
**receive travelmate runtime information:** **receive travelmate runtime information:**
<pre><code> <pre><code>
::: travelmate runtime information ::: 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
+ travelmate_status : connected (net ok/55)
+ travelmate_version : 1.1.0
+ station_id : Turris/-
+ station_interface : trm_wwan
+ station_radio : radio1
+ last_rundate : 19.02.2018 17:02:25
+ system : GL.iNet GL-AR750, OpenWrt SNAPSHOT r5988+25-60e07ffec5
</code></pre> </code></pre>
## Manual Setup ## Manual Setup
@ -123,10 +127,6 @@ edit /etc/config/travelmate and set 'trm_enabled' to '1'
**Q:** What happen with misconfigured uplinks, e.g. due to outdated wlan passwords? **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. **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.lede-project.org/t/travelmate-support-thread/5155) 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)


+ 6
- 4
net/travelmate/files/travelmate.conf View File

@ -3,11 +3,13 @@
config travelmate 'global' config travelmate 'global'
option trm_enabled '0' option trm_enabled '0'
option trm_debug '0'
option trm_triggerdelay '1'
option trm_automatic '1' option trm_automatic '1'
option trm_maxwait '30'
option trm_captive '1'
option trm_iface 'trm_wwan'
option trm_triggerdelay '2'
option trm_debug '0'
option trm_maxretry '3' option trm_maxretry '3'
option trm_minquality '30'
option trm_maxwait '30'
option trm_timeout '60' option trm_timeout '60'
option trm_iface 'trm_wwan'
option trm_rtfile '/tmp/trm_runtime.json' option trm_rtfile '/tmp/trm_runtime.json'

+ 5
- 5
net/travelmate/files/travelmate.init View File

@ -29,7 +29,7 @@ start_service()
stop_service() stop_service()
{ {
local rtfile="$(uci -q get travelmate.global.trm_rtfile)"
local rtfile="$(uci_get travelmate global trm_rtfile)"
rtfile="${rtfile:-"/tmp/trm_runtime.json"}" rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
> "${rtfile}" > "${rtfile}"
@ -38,7 +38,7 @@ stop_service()
status() status()
{ {
local key keylist value rtfile="$(uci_get travelmate.global.trm_rtfile)"
local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
rtfile="${rtfile:-"/tmp/trm_runtime.json"}" rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
if [ -s "${rtfile}" ] if [ -s "${rtfile}" ]
@ -59,12 +59,12 @@ status()
service_triggers() service_triggers()
{ {
local auto="$(uci_get travelmate.global.trm_automatic)"
local auto="$(uci_get travelmate global trm_automatic)"
if [ "${auto}" = "0" ] if [ "${auto}" = "0" ]
then then
local trigger="$(uci_get travelmate.global.trm_iface)"
local delay="$(uci_get travelmate.global.trm_triggerdelay)"
local trigger="$(uci_get travelmate global trm_iface)"
local delay="$(uci_get travelmate global trm_triggerdelay)"
PROCD_RELOAD_DELAY=$((${delay:-2} * 1000)) PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" start procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" start


+ 122
- 74
net/travelmate/files/travelmate.sh View File

@ -10,17 +10,22 @@
# #
LC_ALL=C LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin" PATH="/usr/sbin:/usr/bin:/sbin:/bin"
trm_ver="1.0.2"
trm_ver="1.1.0"
trm_sysver="unknown" trm_sysver="unknown"
trm_enabled=0 trm_enabled=0
trm_debug=0 trm_debug=0
trm_automatic=1 trm_automatic=1
trm_captive=1
trm_captiveurl="http://captive.apple.com"
trm_minquality=30
trm_maxretry=3 trm_maxretry=3
trm_maxwait=30 trm_maxwait=30
trm_timeout=60 trm_timeout=60
trm_iwinfo="$(command -v iwinfo)"
trm_radio="" trm_radio=""
trm_connection=""
trm_rtfile="/tmp/trm_runtime.json" trm_rtfile="/tmp/trm_runtime.json"
trm_fetch="$(command -v uclient-fetch)"
trm_iwinfo="$(command -v iwinfo)"
trm_wpa="$(command -v wpa_supplicant)" trm_wpa="$(command -v wpa_supplicant)"
# load travelmate environment # load travelmate environment
@ -44,7 +49,7 @@ f_envload()
trm_sysver="${sys_model}, ${sys_desc}" trm_sysver="${sys_model}, ${sys_desc}"
fi fi
# initialize lists
# initialize variables
# #
trm_devlist="" trm_devlist=""
trm_stalist="" trm_stalist=""
@ -76,11 +81,11 @@ f_envload()
f_prep() f_prep()
{ {
local config="${1}" local config="${1}"
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 eaptype="$(uci -q get wireless."${config}".eap_type)"
local mode="$(uci_get wireless "${config}" mode)"
local network="$(uci_get wireless "${config}" network)"
local radio="$(uci_get wireless "${config}" device)"
local disabled="$(uci_get wireless "${config}" disabled)"
local eaptype="$(uci_get wireless "${config}" eap_type)"
if ([ -z "${trm_radio}" ] || [ "${trm_radio}" = "${radio}" ]) && \ if ([ -z "${trm_radio}" ] || [ "${trm_radio}" = "${radio}" ]) && \
[ -z "$(printf "%s" "${trm_radiolist}" | grep -Fo " ${radio}")" ] [ -z "$(printf "%s" "${trm_radiolist}" | grep -Fo " ${radio}")" ]
@ -91,7 +96,7 @@ f_prep()
then then
if [ -z "${disabled}" ] || [ "${disabled}" = "0" ] if [ -z "${disabled}" ] || [ "${disabled}" = "0" ]
then then
uci -q set wireless."${config}".disabled=1
uci_set wireless "${config}" disabled 1
fi fi
if [ -z "${eaptype}" ] || [ ${trm_eap} -eq 0 ] if [ -z "${eaptype}" ] || [ ${trm_eap} -eq 0 ]
then then
@ -105,10 +110,14 @@ f_prep()
# #
f_check() f_check()
{ {
local ifname radio dev_status cnt=1 mode="${1}" status="${2:-"false"}"
local ifname radio dev_status config sta_iface sta_radio sta_essid sta_bssid heartbeat cnt=1 mode="${1}" status="${2:-"false"}"
trm_ifquality=0
trm_ifstatus="false" trm_ifstatus="false"
ubus call network reload
if [ "${mode}" != "initial" ]
then
ubus call network reload
fi
while [ ${cnt} -le ${trm_maxwait} ] while [ ${cnt} -le ${trm_maxwait} ]
do do
dev_status="$(ubus -S call network.wireless status 2>/dev/null)" dev_status="$(ubus -S call network.wireless status 2>/dev/null)"
@ -136,44 +145,60 @@ f_check()
fi fi
else else
ifname="$(printf "%s" "${dev_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}" ]
config="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].section')"
if [ -n "${ifname}" ] && [ -n "${config}" ]
then then
trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
sta_iface="$(uci_get wireless "${config}" network)"
sta_radio="$(uci_get wireless "${config}" device)"
sta_essid="$(uci_get wireless "${config}" ssid)"
sta_bssid="$(uci_get wireless "${config}" bssid)"
trm_ifquality="$(${trm_iwinfo} ${ifname} info 2>/dev/null | awk -F "[\/| ]" '/Link Quality:/{printf "%i\n", (100 / $NF * $(NF-1)) }')"
if [ ${trm_ifquality} -ge ${trm_minquality} ]
then
trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
elif [ "${mode}" = "initial" ] && [ ${trm_ifquality} -lt ${trm_minquality} ]
then
trm_connection=""
f_log "info" "uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' is out of range (${trm_ifquality}/${trm_minquality}), uplink disconnected (${trm_sysver})"
fi
fi fi
fi fi
if [ "${mode}" = "initial" ] || [ "${trm_ifstatus}" = "true" ] if [ "${mode}" = "initial" ] || [ "${trm_ifstatus}" = "true" ]
then then
if [ "${mode}" != "initial" ] && [ "${trm_ifstatus}" != "${status}" ]
if ([ "${trm_ifstatus}" != "true" ] && [ "${trm_ifstatus}" != "${status}" ]) || [ ${trm_ifquality} -lt ${trm_minquality} ]
then then
f_jsnup f_jsnup
fi fi
if [ "${mode}" = "initial" ] && [ "${trm_captive}" -eq 1 ] && [ "${trm_ifstatus}" = "true" ]
then
heartbeat="$(${trm_fetch} --timeout=1 --spider "${trm_captiveurl}" 2>&1 | awk '/^Redirected/{printf "%s" "cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed/{printf "%s" "net nok";exit}')"
if ([ -n "${heartbeat}" ] && [ -z "${trm_connection}" ]) || [ "${trm_connection%/*}" != "${heartbeat}" ]
then
trm_connection="${heartbeat}/${trm_ifquality}"
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
fi
fi
break break
fi fi
fi fi
cnt=$((cnt+1)) cnt=$((cnt+1))
sleep 1 sleep 1
done done
f_log "debug" "f_check::: mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, cnt: ${cnt}, max-wait: ${trm_maxwait}, automatic: ${trm_automatic}"
f_log "debug" "f_check::: mode: ${mode}, name: ${ifname:-"-"}, status: ${trm_ifstatus}, quality: ${trm_ifquality}, connection: ${trm_connection:-"-"}, cnt: ${cnt}, max-wait: ${trm_maxwait}, min-quality: ${trm_minquality}, captive: ${trm_captive}, automatic: ${trm_automatic}"
} }
# update runtime information # update runtime information
# #
f_jsnup() f_jsnup()
{ {
local status iface="${1}" radio="${2}" essid="${3}" bssid="${4}"
local status="${trm_ifstatus}" iface="${1}" radio="${2}" essid="${3}" bssid="${4}"
if [ "${trm_ifstatus}" = "true" ]
if [ "${status}" = "true" ]
then then
status="connected"
elif [ "${trm_ifstatus}" = "false" ]
status="connected (${trm_connection:-"-"})"
elif [ "${status}" = "false" ]
then then
status="not connected" status="not connected"
elif [ "${trm_ifstatus}" = "running" ]
then
status="running"
elif [ "${trm_ifstatus}" = "error" ]
then
status="error"
fi fi
json_init json_init
@ -181,8 +206,8 @@ f_jsnup()
json_add_string "travelmate_status" "${status}" json_add_string "travelmate_status" "${status}"
json_add_string "travelmate_version" "${trm_ver}" json_add_string "travelmate_version" "${trm_ver}"
json_add_string "station_id" "${essid:-"-"}/${bssid:-"-"}" 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 "station_interface" "${iface:-"-"}"
json_add_string "station_radio" "${radio:-"-"}"
json_add_string "last_rundate" "$(/bin/date "+%d.%m.%Y %H:%M:%S")" json_add_string "last_rundate" "$(/bin/date "+%d.%m.%Y %H:%M:%S")"
json_add_string "system" "${trm_sysver}" json_add_string "system" "${trm_sysver}"
json_close_object json_close_object
@ -213,7 +238,7 @@ f_log()
# #
f_main() f_main()
{ {
local dev config raw_scan essid_list bssid_list sta_essid sta_bssid sta_radio sta_iface cnt=1
local dev config combo_list scan scan_essid scan_bssid scan_quality sta sta_essid sta_bssid sta_radio sta_iface cnt=1 IFS=" "
f_check "initial" f_check "initial"
if [ "${trm_ifstatus}" != "true" ] if [ "${trm_ifstatus}" != "true" ]
@ -222,7 +247,7 @@ f_main()
config_foreach f_prep 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_commit wireless
fi fi
f_check "dev" "running" f_check "dev" "running"
f_log "debug" "f_main ::: iwinfo: ${trm_iwinfo}, eap_rc: ${trm_eap}, dev_list: ${trm_devlist}, sta_list: ${trm_stalist}" f_log "debug" "f_main ::: iwinfo: ${trm_iwinfo}, eap_rc: ${trm_eap}, dev_list: ${trm_devlist}, sta_list: ${trm_stalist}"
@ -235,57 +260,80 @@ f_main()
fi fi
while [ ${trm_maxretry} -eq 0 ] || [ ${cnt} -le ${trm_maxretry} ] while [ ${trm_maxretry} -eq 0 ] || [ ${cnt} -le ${trm_maxretry} ]
do 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}" ]
combo_list="$(${trm_iwinfo} "${dev}" scan 2>/dev/null | awk 'BEGIN{FS="[/ ]"}/Address:/{var1=$NF}/ESSID:/{var2="";for(i=12;i<=NF;i++)if(var2==""){var2=$i}else{var2=var2" "$i}}/Quality:/{printf "%i,%s,%s\n",(100/$NF*$(NF-1)),var1,var2}' | sort -rn | awk '{ORS=",";print $0}')"
f_log "debug" "f_main ::: dev: ${dev}, combo_list: ${combo_list}"
if [ -n "${combo_list}" ]
then then
for sta in ${trm_stalist} for sta in ${trm_stalist}
do do
config="${sta%%_*}" config="${sta%%_*}"
sta_radio="${sta##*_}" sta_radio="${sta##*_}"
sta_essid="$(uci -q get wireless."${config}".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
uci -q set wireless."${config}".disabled=0
f_check "sta"
if [ "${trm_ifstatus}" = "true" ]
sta_essid="$(uci_get wireless "${config}" ssid)"
sta_bssid="$(uci_get wireless "${config}" bssid)"
sta_iface="$(uci_get wireless "${config}" network)"
IFS=","
for scan in ${combo_list}
do
if [ -z "${scan_quality}" ]
then then
uci -q commit wireless
f_log "info" "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${trm_sysver})"
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
return 0
elif [ ${trm_maxretry} -ne 0 ] && [ ${cnt} -eq ${trm_maxretry} ]
scan_quality="${scan}"
elif [ -z "${scan_bssid}" ]
then then
uci -q set wireless."${config}".disabled=1
if [ -n "${sta_essid}" ]
then
uci -q set wireless."${config}".ssid="${sta_essid}_err"
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 ]
scan_bssid="${scan}"
elif [ -z "${scan_essid}" ]
then
scan_essid="${scan}"
fi
if [ -n "${scan_quality}" ] && [ -n "${scan_bssid}" ] && [ -n "${scan_essid}" ]
then
if [ ${scan_quality} -ge ${trm_minquality} ]
then then
cnt=0
if (([ "${scan_essid}" = "\"${sta_essid}\"" ] && [ -z "${sta_bssid}" ]) || \
[ "${scan_bssid}" = "${sta_bssid}" ]) && [ "${dev}" = "${sta_radio}" ]
then
uci_set wireless "${config}" disabled 0
f_check "sta"
if [ ${trm_ifquality} -ge ${trm_minquality} ]
then
if [ "${trm_ifstatus}" = "true" ]
then
uci_commit wireless
f_log "info" "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${trm_sysver})"
f_check "initial"
return 0
elif [ ${trm_maxretry} -ne 0 ] && [ ${cnt} -eq ${trm_maxretry} ]
then
uci_set wireless "${config}" disabled 1
if [ -n "${sta_essid}" ]
then
uci_set wireless "${config}" ssid "${sta_essid}_err"
fi
if [ -n "${sta_bssid}" ]
then
uci_set wireless "${config}" bssid "${sta_bssid}_err"
fi
uci_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
fi
fi
fi 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})"
scan_quality=""
scan_bssid=""
scan_essid=""
fi fi
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
fi
done
IFS=" "
done done
fi fi
cnt=$((cnt+1)) cnt=$((cnt+1))
@ -301,10 +349,10 @@ f_main()
if [ ! -s "${trm_rtfile}" ] if [ ! -s "${trm_rtfile}" ]
then then
config="$(ubus -S call network.wireless status | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].section')" 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)"
sta_radio="$(uci_get wireless "${config}" device)"
sta_essid="$(uci_get wireless "${config}" ssid)"
sta_bssid="$(uci_get wireless "${config}" bssid)"
sta_iface="$(uci_get wireless "${config}" network)"
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}" f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
fi fi
fi fi


Loading…
Cancel
Save