|
|
@ -10,7 +10,7 @@ |
|
|
|
# |
|
|
|
LC_ALL=C |
|
|
|
PATH="/usr/sbin:/usr/bin:/sbin:/bin" |
|
|
|
trm_ver="1.3.7" |
|
|
|
trm_ver="1.4.0" |
|
|
|
trm_sysver="unknown" |
|
|
|
trm_enabled=0 |
|
|
|
trm_debug=0 |
|
|
@ -145,17 +145,12 @@ f_prep() |
|
|
|
# |
|
|
|
f_check() |
|
|
|
{ |
|
|
|
local IFS ifname radio dev_status config sta_essid sta_bssid result cp_domain wait=1 mode="${1}" status="${2:-"false"}" |
|
|
|
local IFS ifname radio dev_status last_status config sta_essid sta_bssid result cp_domain wait=1 mode="${1}" status="${2:-"false"}" |
|
|
|
|
|
|
|
trm_ifquality=0 |
|
|
|
if [ "${mode}" = "initial" ] |
|
|
|
if [ "${mode}" != "initial" ] && [ "${status}" = "false" ] |
|
|
|
then |
|
|
|
trm_ifstatus="false" |
|
|
|
else |
|
|
|
if [ "${status}" = "false" ] |
|
|
|
then |
|
|
|
ubus call network reload |
|
|
|
fi |
|
|
|
ubus call network reload |
|
|
|
fi |
|
|
|
while [ ${wait} -le ${trm_maxwait} ] |
|
|
|
do |
|
|
@ -197,7 +192,7 @@ f_check() |
|
|
|
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} ] |
|
|
|
elif [ "${mode}" = "initial" ] && [ ${trm_ifquality} -lt ${trm_minquality} ] && [ "${trm_ifstatus}" != "${status}" ] |
|
|
|
then |
|
|
|
trm_ifstatus="${status}" |
|
|
|
sta_essid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].*.ssid')" |
|
|
@ -208,16 +203,17 @@ f_check() |
|
|
|
fi |
|
|
|
if [ "${mode}" = "initial" ] || [ "${trm_ifstatus}" = "true" ] |
|
|
|
then |
|
|
|
if ([ "${trm_ifstatus}" != "true" ] && [ "${trm_ifstatus}" != "${status}" ]) || \ |
|
|
|
json_get_var last_status "travelmate_status" |
|
|
|
if ([ "${trm_ifstatus}" = "false" ] && [ "${trm_ifstatus}" != "${status}" ]) || \ |
|
|
|
([ "${trm_ifstatus}" = "true" ] && [ "${mode}" = "sta" ] && [ -n "${trm_active_sta}" ]) || \ |
|
|
|
[ ${trm_ifquality} -lt ${trm_minquality} ] |
|
|
|
[ -z "${last_status}" ] || [ "${last_status}" = "running / not connected" ] || [ ${trm_ifquality} -lt ${trm_minquality} ] |
|
|
|
then |
|
|
|
f_jsnup |
|
|
|
fi |
|
|
|
if [ "${mode}" = "initial" ] && [ ${trm_captive} -eq 1 ] && [ "${trm_ifstatus}" = "true" ] |
|
|
|
then |
|
|
|
result="$(${trm_fetch} --timeout=$(( ${trm_maxwait} / 3 )) "${trm_captiveurl}" -O /dev/null 2>&1 | \ |
|
|
|
awk '/^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|^Connection error/{printf "%s" "net nok";exit}')" |
|
|
|
awk '/^Failed to redirect|^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|^Connection error/{printf "%s" "net nok";exit}')" |
|
|
|
if [ -n "${result}" ] && ([ -z "${trm_connection}" ] || [ "${result}" != "${trm_connection%/*}" ]) |
|
|
|
then |
|
|
|
cp_domain="$(printf "%s" "${result}" | awk -F "['| ]" '/^net cp/{printf "%s" $4}')" |
|
|
@ -411,7 +407,7 @@ f_main() |
|
|
|
then |
|
|
|
uci_commit wireless |
|
|
|
f_log "info" "connected to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${trm_sysver})" |
|
|
|
return 0 |
|
|
|
return |
|
|
|
else |
|
|
|
uci -q revert wireless |
|
|
|
f_check "rev" |
|
|
@ -436,8 +432,8 @@ f_main() |
|
|
|
done |
|
|
|
cnt=$(( cnt + 1 )) |
|
|
|
sleep $(( ${trm_maxwait} / 6 )) |
|
|
|
unset scan_list |
|
|
|
done |
|
|
|
unset scan_list |
|
|
|
done |
|
|
|
fi |
|
|
|
} |
|
|
@ -469,14 +465,20 @@ while true |
|
|
|
do |
|
|
|
if [ -z "${trm_action}" ] |
|
|
|
then |
|
|
|
rc=0 |
|
|
|
while true |
|
|
|
do |
|
|
|
f_check "initial" |
|
|
|
if [ "${trm_ifstatus}" = "true" ] |
|
|
|
if [ ${rc} -eq 0 ] |
|
|
|
then |
|
|
|
f_check "initial" |
|
|
|
fi |
|
|
|
sleep ${trm_timeout} 0 |
|
|
|
rc=${?} |
|
|
|
if [ ${rc} -ne 0 ] |
|
|
|
then |
|
|
|
sleep ${trm_timeout} 0 |
|
|
|
f_check "initial" |
|
|
|
fi |
|
|
|
if [ $? -eq 0 ] || [ "${trm_ifstatus}" = "false" ] |
|
|
|
if [ ${rc} -eq 0 ] || ([ ${rc} -ne 0 ] && [ "${trm_ifstatus}" = "false" ]) |
|
|
|
then |
|
|
|
break |
|
|
|
fi |
|
|
|