2 # travelmate, a wlan connection manager for travel router
3 # written by Dirk Brenken (dev@brenken.org)
5 # This is free software, licensed under the GNU General Public License v3.
6 # You should have received a copy of the GNU General Public License
7 # along with this program. If not, see <http://www.gnu.org/licenses/>.
9 # (s)hellcheck exceptions
10 # shellcheck disable=1091 disable=2039 disable=2143 disable=2181 disable=2188
12 # set initial defaults
15 PATH
="/usr/sbin:/usr/bin:/sbin:/bin"
24 trm_captiveurl
="http://captive.apple.com"
33 trm_rtfile
="/tmp/trm_runtime.json"
34 trm_wifi
="$(command -v wifi)"
36 trm_fetch
="$(command -v uclient-fetch)"
37 trm_iwinfo
="$(command -v iwinfo)"
38 trm_wpa
="$(command -v wpa_supplicant)"
39 trm_logger
="$(command -v logger)"
40 trm_action
="${1:-"start"}"
41 trm_pidfile
="/var/run/travelmate.pid"
43 # load travelmate environment
47 local IFS check wpa_checks
49 # (re-)initialize global list variables
51 unset trm_devlist trm_stalist trm_radiolist trm_active_sta
53 # get system information
55 trm_sysver
="$(ubus -S call system board 2>/dev/null | jsonfilter -e '@.model' -e '@.release.description' | \
56 awk 'BEGIN{ORS=", "}{print $0}' | awk '{print substr($0,1,length($0)-2)}')"
58 # load config and check 'enabled' option
62 local name
="${1}" type="${2}"
63 if [ "${name}" = "travelmate" ] && [ "${type}" = "global" ]
67 local option
="${1}" value
="${2}"
68 eval "${option}=\"${value}\""
77 config_load travelmate
79 if [ "${trm_enabled}" -ne 1 ]
81 f_log
"info" "travelmate is currently disabled, please set 'trm_enabled' to '1' to use this service"
86 # get wpa_supplicant capabilities
88 wpa_checks
="eap sae owe"
89 for check
in ${wpa_checks}
91 if [ -x "${trm_wpa}" ]
93 eval "trm_${check}check=\"$("${trm_wpa}" -v${check} >/dev/null 2>&1; printf "%u" "${?}")\""
95 eval "trm_
${check}check
=\"1\""
99 # get wifi reconf capabilities
101 if [ -n "$
(grep -F "reconf" "${trm_wifi}" 2>/dev
/null
)" ]
106 # enable 'disabled' wifi devices
109 config_foreach f_prepdev wifi-device
110 if [ -n "$
(uci
-q changes
"wireless")" ]
112 uci_commit "wireless
"
113 "${trm_wifi}" "${trm_wificmd}"
114 sleep $((trm_maxwait/6))
117 # validate input ranges
119 if [ "${trm_minquality}" -lt 20 ] || [ "${trm_minquality}" -gt 80 ]
123 if [ "${trm_listexpiry}" -lt 0 ] || [ "${trm_listexpiry}" -gt 300 ]
127 if [ "${trm_maxretry}" -lt 1 ] || [ "${trm_maxretry}" -gt 10 ]
131 if [ "${trm_maxwait}" -lt 20 ] || [ "${trm_maxwait}" -gt 40 ] || [ "${trm_maxwait}" -ge "${trm_timeout}" ]
135 if [ "${trm_timeout}" -lt 30 ] || [ "${trm_timeout}" -gt 300 ] || [ "${trm_timeout}" -le "${trm_maxwait}" ]
140 # load json runtime file
142 json_load_file "${trm_rtfile}" >/dev/null 2>&1
143 json_select data >/dev/null 2>&1
148 json_add_object "data
"
150 f_log "debug
" "f_env
::: trm_eapcheck
: ${trm_eapcheck:-"-"}, trm_saecheck: ${trm_saecheck:-"-"}, trm_owecheck: ${trm_owecheck:-"-"}, trm_wificmd: ${trm_wificmd}"
153 # trim leading and trailing whitespace characters
157 local IFS trim="${1}"
159 trim="${trim#"${trim%%[![:space:]]*}"}"
160 trim="${trim%"${trim##*[![:space:]]}"}"
161 printf '%s' "${trim}"
164 # prepare the 'wifi-device' sections
168 local IFS disabled config="${1}"
170 disabled="$
(uci_get
"wireless" "${config}" "disabled")"
171 if [ "${disabled}" = "1" ]
173 uci_set wireless "${config}" disabled 0
175 f_log "debug
" "f_prepdev
::: config
: ${config}, disabled
: ${disabled:-"-"}"
178 # prepare the 'wifi-iface' sections
182 local IFS mode network radio encryption eaptype disabled config="${1}" proactive="${2}"
184 mode="$
(uci_get
"wireless" "${config}" "mode")"
185 network="$
(uci_get
"wireless" "${config}" "network")"
186 radio="$
(uci_get
"wireless" "${config}" "device")"
187 encryption="$
(uci_get
"wireless" "${config}" "encryption")"
188 eaptype="$
(uci_get
"wireless" "${config}" "eap_type")"
189 disabled="$
(uci_get
"wireless" "${config}" "disabled")"
190 if [ -n "${config}" ] && [ -n "${radio}" ] && [ -n "${mode}" ] && [ -n "${network}" ]
192 if [ -z "${trm_radio}" ] && [ -z "$(printf "%s" "${trm_radiolist}" | grep -Fo "${radio}")" ]
194 trm_radiolist
="$(f_trim "${trm_radiolist} ${radio}")"
195 elif [ -n "${trm_radio}" ] && [ -z "${trm_radiolist}" ]
197 trm_radiolist
="$(f_trim "$
(printf "%s" "${trm_radio}" | \
198 awk '{while(match(tolower($0),/radio[0-9]/)){ORS=" ";print substr(tolower($0),RSTART,RLENGTH);$0=substr($0,RSTART+RLENGTH)}}')")"
200 if [ "${mode}" = "sta" ] && [ "${network}" = "${trm_iface}" ]
202 if { [ -z "${disabled}" ] || [ "${disabled}" = "0" ]; } && { [ "${proactive}" -eq 0 ] || [ "${trm_ifstatus}" != "true" ]; }
204 uci_set wireless "${config}" disabled 1
205 elif [ "${disabled}" = "0" ] && [ "${trm_ifstatus}" = "true" ] && [ "${proactive}" -eq 1 ]
207 if [ -z "${trm_active_sta}" ]
209 trm_active_sta="${config}"
211 uci_set wireless "${config}" disabled 1
214 if [ -z "${eaptype}" ] || { [ -n "${eaptype}" ] && [ "${trm_eapcheck}" -eq 0 ]; }
216 if { [ "${encryption%-*}" != "sae" ] && [ "${encryption%-*}" != "wpa3" ] && [ "${encryption}" != "owe" ]; } || \
217 { { [ "${encryption%-*}" = "sae" ] || [ "${encryption%-*}" = "wpa3" ]; } && [ "${trm_saecheck}" -eq 0 ]; } || \
218 { [ "${encryption}" = "owe" ] && [ "${trm_owecheck}" -eq 0 ]; }
220 trm_stalist="$
(f_trim
"${trm_stalist} ${config}-${radio}")"
225 f_log "debug
" "f_prepif
::: config
: ${config}, mode: ${mode}, network: ${network}, radio: ${radio}, trm_radio: ${trm_radio:-"-"}, trm_active_sta: ${trm_active_sta:-"-"}, proactive: ${proactive}, disabled: ${disabled}"
234 result="$
(${trm_fetch} --timeout=$
((trm_maxwait
/6)) "${trm_captiveurl}" -O /dev
/null
2>&1 | \
235 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}')"
236 printf "%s
" "${result}"
237 f_log "debug
" "f_net
::: fetch
: ${trm_fetch}, timeout: $((trm_maxwait/6)), url: ${trm_captiveurl}, result: ${result}"
240 # check interface status
244 local IFS ifname radio dev_status config sta_essid sta_bssid result uci_essid uci_bssid login_command login_command_args wait_time=1 mode="${1}" status="${2:-"false"}" cp_domain="${3:-"false"}"
246 if [ "${mode}" != "initial" ] && [ "${mode}" != "dev" ] && [ "${status}" = "false
" ]
248 "${trm_wifi}" "${trm_wificmd}"
249 sleep $((trm_maxwait/6))
252 while [ "${wait_time}" -le "${trm_maxwait}" ]
254 dev_status="$
(ubus
-S call network.wireless status
2>/dev
/null
)"
255 if [ -n "${dev_status}" ]
257 if [ "${mode}" = "dev
" ]
259 if [ "${trm_ifstatus}" != "${status}" ]
261 trm_ifstatus="${status}"
264 for radio in ${trm_radiolist}
266 result="$
(printf "%s" "${dev_status}" | jsonfilter
-l1 -e "@.${radio}.up")"
267 if [ "${result}" = "true" ] && [ -z "$(printf "%s" "${trm_devlist}" | grep -Fo "${radio}")" ]
269 trm_devlist
="$(f_trim "${trm_devlist} ${radio}")"
272 if [ "${trm_devlist}" = "${trm_radiolist}" ] || [ "${wait_time}" -eq "${trm_maxwait}" ]
274 ifname
="${trm_devlist}"
279 elif [ "${mode}" = "rev" ]
283 ifname
="$(printf "%s
" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta
"].ifname')"
284 if [ -n "${ifname}" ]
286 trm_ifquality
="$(${trm_iwinfo} "${ifname}" info 2>/dev/null | awk -F "[ ]" '/Link Quality:/{split($NF,var0,"/");printf "%i\n",(var0[1]*100/var0[2])}')"
287 if [ "${mode}" = "initial" ] && [ "${trm_captive}" -eq 1 ]
290 if [ "${cp_domain}" = "true" ]
292 cp_domain
="$(printf "%s
" "${result}" | awk -F "[\\'| ]" '/^net cp
/{printf "%s" $4}')"
293 uci_essid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.
*.interfaces
[@.config.mode
="sta"].config.ssid
')"
294 uci_essid="${uci_essid//[^[:alnum:]_]/_}"
295 uci_bssid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.
*.interfaces
[@.config.mode
="sta"].config.bssid
')"
296 uci_bssid="${uci_bssid//[^[:alnum:]_]/_}"
299 if [ "${trm_ifquality}" -ge "${trm_minquality}" ] && [ "${result}" != "net nok" ]
301 trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
302 if [ "${trm_ifstatus}" = "true" ]
304 if [ "${mode}" = "sta" ] && [ "${trm_captive}" -eq 1 ]
309 cp_domain="$(printf "%s" "${result}" | awk -F "[\\'|
]" '/^net cp/{printf "%s
" $4}')"
310 uci_essid
="$(printf "%s
" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta
"].config.ssid')"
311 uci_essid
="${uci_essid//[^[:alnum:]_]/_}"
312 uci_bssid
="$(printf "%s
" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta
"].config.bssid')"
313 uci_bssid
="${uci_bssid//[^[:alnum:]_]/_}"
314 if [ "${trm_netcheck}" -eq 1 ] && [ "${result}" = "net nok" ]
316 trm_ifstatus
="${status}"
320 if [ -z "${cp_domain}" ] ||
[ -n "$(uci_get "dhcp
" "@dnsmasq
[0]" "rebind_domain
" | grep -Fo "${cp_domain}")" ]
324 uci
-q add_list dhcp.@dnsmasq
[0].rebind_domain
="${cp_domain}"
325 f_log
"info" "captive portal domain '${cp_domain}' added to to dhcp rebind whitelist"
326 if [ -z "$(uci_get "travelmate
" "${trm_radio}_${uci_essid}_${uci_bssid}")" ]
328 uci_add travelmate
"login" "${trm_radio}_${uci_essid}_${uci_bssid}"
329 uci_set travelmate
"${trm_radio}_${uci_essid}_${uci_bssid}" "command" "none"
330 f_log
"info" "captive portal login section '${trm_radio}_${uci_essid}_${uci_bssid}' added to travelmate config section"
333 if [ -n "$(uci -q changes "dhcp
")" ]
336 /etc
/init.d
/dnsmasq reload
338 if [ -n "$(uci -q changes "travelmate
")" ]
340 uci_commit
"travelmate"
343 if [ -n "${cp_domain}" ] && [ "${cp_domain}" != "false" ] && [ -n "${uci_essid}" ] && [ "${trm_captive}" -eq 1 ]
345 trm_connection
="${result:-"-"}/${trm_ifquality}"
347 login_command
="$(uci_get "travelmate
" "${trm_radio}_${uci_essid}_${uci_bssid}" "command")"
348 if [ -x "${login_command}" ]
350 login_command_args
="$(uci_get "travelmate
" "${trm_radio}_${uci_essid}_${uci_bssid}" "command_args
")"
351 "${login_command}" ${login_command_args} >/dev
/null
2>&1
353 f_log
"info" "captive portal login '${login_command:0:40} ${login_command_args:0:20}' for '${cp_domain}' has been executed with rc '${rc}'"
360 trm_connection
="${result:-"-"}/${trm_ifquality}"
364 elif [ -n "${trm_connection}" ]
366 sta_essid
="$(printf "%s
" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta
"].*.ssid')"
367 sta_bssid
="$(printf "%s
" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta
"].*.bssid')"
368 if [ "${trm_ifquality}" -lt "${trm_minquality}" ]
371 trm_ifstatus
="${status}"
372 f_log
"info" "uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' is out of range (${trm_ifquality}/${trm_minquality})"
373 elif [ "${trm_netcheck}" -eq 1 ] && [ "${result}" = "net nok" ]
376 trm_ifstatus
="${status}"
377 f_log
"info" "uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' has no internet (${result})"
381 elif [ "${mode}" = "initial" ]
386 elif [ -n "${trm_connection}" ]
389 trm_ifstatus
="${status}"
392 elif [ "${mode}" = "initial" ]
399 wait_time
=$
((wait_time
+1))
402 f_log
"debug" "f_check ::: mode: ${mode}, name: ${ifname:-"-"}, status: ${trm_ifstatus}, connection: ${trm_connection:-"-"}, wait: ${wait_time}, max_wait: ${trm_maxwait}, min_quality: ${trm_minquality}, captive: ${trm_captive}, netcheck: ${trm_netcheck}"
405 # update runtime information
409 local IFS config d1 d2 d3 last_date last_station sta_iface sta_radio sta_essid sta_bssid last_status dev_status wpa_status status
="${trm_ifstatus}" faulty_list faulty_station
="${1}"
411 dev_status
="$(ubus -S call network.wireless status 2>/dev/null)"
412 if [ -n "${dev_status}" ]
414 config
="$(printf "%s
" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta
"].section')"
415 if [ -n "${config}" ]
417 sta_iface
="$(uci_get "wireless
" "${config}" "network
")"
418 sta_radio
="$(uci_get "wireless
" "${config}" "device
")"
419 sta_essid
="$(uci_get "wireless
" "${config}" "ssid
")"
420 sta_bssid
="$(uci_get "wireless
" "${config}" "bssid
")"
424 json_get_var last_date
"last_rundate"
425 json_get_var last_station
"station_id"
426 if [ "${status}" = "true" ]
428 status
="connected (${trm_connection:-"-"})"
429 json_get_var last_status
"travelmate_status"
430 if [ "${last_status}" = "running / not connected" ] || [ "${last_station}" != "${sta_radio:-"-"}/${sta_essid:-"-"}/${sta_bssid:-"-"}" ]
432 last_date
="$(date "+%Y.
%m.
%d-
%H
:%M
:%S
")"
434 elif [ "${status}" = "error" ]
437 status
="program error"
440 status
="running / not connected"
442 if [ -z "${last_date}" ]
444 last_date
="$(date "+%Y.
%m.
%d-
%H
:%M
:%S
")"
447 json_get_var faulty_list
"faulty_stations"
448 if [ -n "${faulty_list}" ] && [ "${trm_listexpiry}" -gt 0 ]
450 d1
="$(date -d "${last_date}" "+%s
")"
453 if [ "${d3}" -ge "${trm_listexpiry}" ]
459 if [ -n "${faulty_station}" ]
461 if [ -z "$(printf "%s
" "${faulty_list}" | grep -Fo "${faulty_station}")" ]
463 faulty_list
="$(f_trim "${faulty_list} ${faulty_station}")"
464 last_date
="$(date "+%Y.
%m.
%d-
%H
:%M
:%S
")"
468 if [ "${trm_eapcheck}" -eq 0 ]
474 if [ "${trm_saecheck}" -eq 0 ]
476 wpa_status
="${wpa_status}/SAE"
478 wpa_status
="${wpa_status}/-"
480 if [ "${trm_owecheck}" -eq 0 ]
482 wpa_status
="${wpa_status}/OWE"
484 wpa_status
="${wpa_status}/-"
486 json_add_string
"travelmate_status" "${status}"
487 json_add_string
"travelmate_version" "${trm_ver}"
488 json_add_string
"station_id" "${sta_radio:-"-"}/${sta_essid:-"-"}/${sta_bssid:-"-"}"
489 json_add_string
"station_interface" "${sta_iface:-"-"}"
490 json_add_string
"faulty_stations" "${faulty_list}"
491 json_add_string
"wpa_capabilities" "${wpa_status:-"-"}"
492 json_add_string
"last_rundate" "${last_date}"
493 json_add_string
"system" "${trm_sysver}"
494 json_dump
> "${trm_rtfile}"
495 f_log
"debug" "f_jsnup ::: config: ${config:-"-"}, status: ${status:-"-"}, sta_iface: ${sta_iface:-"-"}, sta_radio: ${sta_radio:-"-"}, sta_essid: ${sta_essid:-"-"}, sta_bssid: ${sta_bssid:-"-"}, faulty_list: ${faulty_list:-"-"}, list_expiry: ${trm_listexpiry}"
502 local IFS class
="${1}" log_msg
="${2}"
504 if [ -n "${log_msg}" ] && { [ "${class}" != "debug" ] || [ "${trm_debug}" -eq 1 ]; }
506 if [ -x "${trm_logger}" ]
508 "${trm_logger}" -p "${class}" -t "travelmate-${trm_ver}[${$}]" "${log_msg}"
510 printf "%s
%s
%s
\\n
" "${class}" "travelmate-${trm_ver}[${$}]" "${log_msg}"
512 if [ "${class}" = "err
" ]
522 # main function for connection handling
526 local IFS cnt dev config spec scan_list scan_essid scan_bssid scan_open scan_quality uci_essid cfg_essid faulty_list
527 local station_id sta sta_essid sta_bssid sta_radio sta_iface active_essid active_bssid active_radio
529 f_check "initial
" "false
" "true
"
530 f_log "debug
" "f_main
::: status
: ${trm_ifstatus}, proactive
: ${trm_proactive}"
531 if [ "${trm_ifstatus}" != "true
" ] || [ "${trm_proactive}" -eq 1 ]
534 config_foreach f_prepif wifi-iface ${trm_proactive}
535 if [ "${trm_ifstatus}" = "true" ] && [ -n "${trm_active_sta}" ] && [ "${trm_proactive}" -eq 1 ]
537 json_get_var station_id "station_id
"
538 active_radio="${station_id%%/*}"
539 active_essid="${station_id%/*}"
540 active_essid="${active_essid#*/}"
541 active_bssid="${station_id##*/}"
543 f_log "debug
" "f_main
::: active_radio
: ${active_radio}, active_essid: \"${active_essid}\", active_bssid: ${active_bssid:-"-"}"
545 uci_commit "wireless
"
548 json_get_var faulty_list "faulty_stations
"
549 f_log "debug
" "f_main
::: iwinfo
: ${trm_iwinfo:-"-"}, dev_list: ${trm_devlist:-"-"}, sta_list: ${trm_stalist:0:${trm_scanbuffer}}, faulty_list: ${faulty_list:-"-"}"
552 for dev in ${trm_devlist}
554 if [ -z "$
(printf "%s" "${trm_stalist}" |
grep -o "\\-${dev}")" ]
556 f_log "debug
" "f_main
::: no station on
'${dev}' - continue"
561 for sta in ${trm_stalist}
564 sta_radio="${sta##*-}"
565 sta_essid="$
(uci_get
"wireless" "${config}" "ssid")"
566 sta_bssid="$
(uci_get
"wireless" "${config}" "bssid")"
567 sta_iface="$
(uci_get
"wireless" "${config}" "network")"
568 json_get_var faulty_list "faulty_stations
"
569 if [ -n "$
(printf "%s" "${faulty_list}" | grep -Fo "${sta_radio}/${sta_essid}/${sta_bssid}")" ]
571 f_log "debug
" "f_main
::: faulty station
'${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' - continue"
574 if [ "${dev}" = "${active_radio}" ] && [ "${sta_essid}" = "${active_essid}" ] && [ "${sta_bssid:-"-"}" = "${active_bssid}" ]
576 f_log "debug
" "f_main
::: active station prioritized
'${active_radio}/${active_essid}/${active_bssid:-"-"}' - break"
579 f_log "debug
" "f_main
::: sta_radio
: ${sta_radio}, sta_essid: \"${sta_essid}\", sta_bssid: ${sta_bssid:-"-"}"
580 if [ -z "${scan_list}" ]
582 scan_list="$
("${trm_iwinfo}" "${dev}" scan
2>/dev
/null | \
583 awk 'BEGIN{FS="[[:space:]]"}/Address:/{var1=$NF}/ESSID:/{var2="";for(i=12;i<=NF;i++)if(var2==""){var2=$i}else{var2=var2" "$i};
584 gsub(/,/,".",var2)}/Quality:/{split($NF,var0,"/")}/Encryption:/{if($NF=="none"){var3="+"}else{var3="-"};printf "%i,%s,%s,%s\n",(var0[1]*100/var0[2]),var1,var2,var3}' | \
585 sort -rn |
awk -v buf
="${trm_scanbuffer}" 'BEGIN{ORS=","}{print substr($0,1,buf)}')"
586 f_log "debug
" "f_main
::: scan_radio
: ${dev}, scan_buffer: ${trm_scanbuffer}, scan_list: ${scan_list}"
587 if [ -z "${scan_list}" ]
589 f_log "debug
" "f_main
::: no scan results on
'${dev}' - continue"
596 for spec in ${scan_list}
598 if [ -z "${scan_quality}" ]
600 scan_quality="${spec}"
601 elif [ -z "${scan_bssid}" ]
604 elif [ -z "${scan_essid}" ]
607 elif [ -z "${scan_open}" ]
611 if [ -n "${scan_quality}" ] && [ -n "${scan_bssid}" ] && [ -n "${scan_essid}" ] && [ -n "${scan_open}" ]
613 if [ "${scan_quality}" -ge "${trm_minquality}" ]
615 if { { [ "${scan_essid}" = "\"${sta_essid//,/.}\"" ] && { [ -z "${sta_bssid}" ] || [ "${scan_bssid}" = "${sta_bssid}" ]; } } || \
616 { [ "${scan_bssid}" = "${sta_bssid}" ] && [ "${scan_essid}" = "unknown" ]; } } && [ "${dev}" = "${sta_radio}" ]
618 f_log
"debug" "f_main ::: scan_quality: ${scan_quality}, scan_essid: ${scan_essid}, scan_bssid: ${scan_bssid:-"-"}, scan_open: ${scan_open}"
619 if [ -n "${active_radio}" ]
621 uci_set
"wireless" "${trm_active_sta}" "disabled" "1"
622 uci_commit
"wireless"
623 f_log
"debug" "f_main ::: active uplink connection '${active_radio}/${active_essid}/${active_bssid:-"-"}' terminated"
624 unset trm_connection active_radio active_essid active_bssid
629 while [ "${cnt}" -le "${trm_maxretry}" ]
631 uci_set
"wireless" "${config}" "disabled" "0"
632 trm_radio
="${sta_radio}"
634 if [ "${trm_ifstatus}" = "true" ]
637 uci_commit
"wireless"
638 f_log
"info" "connected to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${cnt}/${trm_maxretry}, ${trm_sysver})"
641 uci
-q revert
"wireless"
643 if [ "${cnt}" -eq "${trm_maxretry}" ]
645 faulty_station
="${sta_radio}/${sta_essid}/${sta_bssid:-"-"}"
646 f_jsnup
"${faulty_station}"
647 f_log
"info" "uplink disabled '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${cnt}/${trm_maxretry}, ${trm_sysver})"
651 f_log
"info" "can't connect to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${cnt}/${trm_maxretry}, ${trm_sysver})"
655 sleep $
((trm_maxwait
/6))
657 elif [ "${trm_autoadd}" -eq 1 ] && [ "${scan_open}" = "+" ] && [ "${scan_essid}" != "unknown" ]
659 cfg_essid
="${scan_essid#*\"}"
660 cfg_essid
="${cfg_essid%\"*}"
661 uci_essid
="${cfg_essid//[^[:alnum:]_]/_}"
662 if [ -z "$(uci_get "wireless
" "trm_
${uci_essid}")" ]
664 uci_add
"wireless" "wifi-iface" "trm_${uci_essid}"
665 uci_set
"wireless" "trm_${uci_essid}" "mode" "sta"
666 uci_set
"wireless" "trm_${uci_essid}" "network" "${trm_iface}"
667 uci_set
"wireless" "trm_${uci_essid}" "device" "${sta_radio}"
668 uci_set
"wireless" "trm_${uci_essid}" "ssid" "${cfg_essid}"
669 uci_set
"wireless" "trm_${uci_essid}" "encryption" "none"
670 uci_set
"wireless" "trm_${uci_essid}" "disabled" "1"
671 uci_commit
"wireless"
672 f_log
"info" "open uplink '${sta_radio}/${cfg_essid}' added to wireless config"
675 unset scan_quality scan_bssid scan_essid scan_open
678 unset scan_quality scan_bssid scan_essid scan_open
683 unset IFS scan_quality scan_bssid scan_essid scan_open
690 # source required system libraries
692 if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]
694 .
"/lib/functions.sh"
695 .
"/usr/share/libubox/jshn.sh"
697 f_log
"err" "system libraries not found"
700 # control travelmate actions
705 if [ -z "${trm_action}" ]
714 sleep ${trm_timeout} 0
720 if [ "${rc}" -eq 0 ] || { [ "${rc}" -ne 0 ] && [ "${trm_ifstatus}" = "false" ]; }
725 elif [ "${trm_action}" = "stop
" ]
727 f_log "info
" "travelmate instance stopped
::: action
: ${trm_action}, pid
: $
(cat ${trm_pidfile} 2>/dev
/null
)"
732 f_log "info
" "travelmate instance started
::: action
: ${trm_action}, pid
: ${$}"