summaryrefslogtreecommitdiffstats
path: root/package/query3g/files/query3g.sh
blob: 33cfe23790d94726bf627f8e4a86573b866f765c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh

reset=/usr/bin/usbreset
comgt=/usr/bin/gcom
script=/usr/share/query3g.gcom

last_reset="x"

wan_proto="$(uci -q get network.wan.proto)"

if [ "$wan_proto" = "3g" ]; then
	ifdown wan
fi

for port in 0 1 2 3 4 5 6 7 8 9; do
	for tty in $(find /sys/devices/ -name "ttyUSB$port" -type d | sort -u); do
		[ -f "$tty/../../idProduct" ] || continue

		local dir="$(cd "$tty/../.."; pwd)"
		local uid="$(basename "$dir")"
		local dev="/dev/$(basename "$tty")"
		local vid="$(cat "$tty/../../idVendor")"
		local pid="$(cat "$tty/../../idProduct")"

		if [ "$last_reset" != "$vid:$pid" ] && [ "$vid:$pid" != "0685:7000" ]; then
			last_reset="$vid:$pid"
#			$reset "$vid:$pid" >/dev/null

			local try=0
			while [ $((try++)) -lt 5 ] && [ ! -e "$dev" ]; do sleep 1; done 
		fi

		if $comgt -s "$script" -d "$dev" 2>/dev/null; then
			echo "PORT:$dev"
			echo "VID:$vid"
			echo "PID:$pid"
			echo "UID:$uid"
			exit 0
		fi
	done
done
exit 1