summaryrefslogtreecommitdiffstats
path: root/package/query3g/files/usr/bin
diff options
context:
space:
mode:
Diffstat (limited to 'package/query3g/files/usr/bin')
-rwxr-xr-xpackage/query3g/files/usr/bin/3gdetect.sh173
-rwxr-xr-xpackage/query3g/files/usr/bin/modemname.sh33
-rwxr-xr-xpackage/query3g/files/usr/bin/query3g.sh42
3 files changed, 248 insertions, 0 deletions
diff --git a/package/query3g/files/usr/bin/3gdetect.sh b/package/query3g/files/usr/bin/3gdetect.sh
new file mode 100755
index 000000000..53715a9cc
--- /dev/null
+++ b/package/query3g/files/usr/bin/3gdetect.sh
@@ -0,0 +1,173 @@
+#!/bin/sh
+DATA_DIR=./data
+GCOM=comgt
+GCOM_MODEMDETECT="/usr/share/3gmodem/model.gcom"
+MODEM_INFO="modemname.sh"
+RETURN_APN=$DATA_DIR/apnprovider
+usbreset=/usr/bin/usbreset
+GCOM_CMD="/tmp/cmds.gcom"
+
+detect_model()
+{
+ $GCOM -d $1 $2 | tail -n 1
+}
+
+modem_info()
+{
+ $MODEM_INFO "$1" $2
+}
+
+gcomscr_start()
+{
+ rm $GCOM_CMD
+ echo "opengt
+ set com 115200n81
+ set comecho off
+ set senddelay 0.02
+ waitquiet 0.2 0.2
+
+ send \"AT^m\"
+ waitfor 1 \"OK\",\"ERROR\" " >> $GCOM_CMD
+}
+
+gcomscr_add_cmd()
+{
+ echo "
+ let \$c=\"$1^m\"
+ gosub readatcmdnr
+" >> $GCOM_CMD
+}
+
+gcomscr_end()
+{
+ echo -e "
+ exit 0
+
+:readatcmdnr
+ let i=10
+ send \$c
+:loop3
+ get 1 \"^m\" \$s
+ if len(\$s) < 2 goto loop5
+ if \$mid(\$s,1,2) = \"ER\" goto loop4
+ if \$mid(\$s,1,2) = \"OK\" goto loop5
+ if \$mid(\$s,1,2) = \"AT\" goto loop5
+ if \$mid(\$s,1,2) = \"TE\" goto loop5
+ if \$mid(\$s,1,1) = \"+\" goto loop5
+ if \$mid(\$s,1,1) = \"\^\" goto loop5
+ let l=len(\$s)
+ let \$s=\$mid(\$s,1,l)
+ return
+
+:loop4
+ let \$s=\"\"
+ return
+
+:loop5
+ if i = 0 return
+ let i=i-1
+ sleep 0.25
+ goto loop3
+ " >> $GCOM_CMD
+}
+
+gcomscr_run()
+{
+ $GCOM -d $1 $GCOM_CMD
+}
+
+skip_cycles=0
+skip_passed=0
+known_modems=""
+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
+ if [ $skip_cycles -gt 0 ]; then
+ skip_cycles=$((skip_cycles-1))
+ skip_passed=1
+ continue
+ fi
+ dir="$(cd "$tty/../.."; pwd)"
+ uid="$(basename "$dir")"
+ dev="/dev/$(basename "$tty")"
+ vid="$(cat "$tty/../../idVendor")"
+ pid="$(cat "$tty/../../idProduct")"
+ #echo $dir
+ #echo $uid
+ echo "DEVICE:"$dev
+ #echo $vid":"$pid
+
+ ret=$(detect_model "$dev" $GCOM_MODEMDETECT)
+ #echo $ret
+ manuf=$(echo $ret | cut -d',' -f1 | tr '[A-Z]' '[a-z]' )
+ model=$(echo $ret | cut -d',' -f2 | tr '[A-Z]' '[a-z]' )
+ serialnum=$(echo $ret | cut -d',' -f3 )
+ echo "MODEL: "$model
+ echo "MANUF: "$manuf
+ echo "SERIAL:"$serialnum
+
+ #FILE="/tmp/modem3g.$serialnum"
+ #echo "FILE:"$FILE
+ if [ -f $FILE ]; then
+ found=1
+ else
+ found=0
+ fi
+
+ if [ "$model" != "" ] && \
+ [ "$manuf" != "" ]; then
+ if [ $found -eq 0 ]; then
+ touch /tmp/modem3g.$serialnum
+ manuf="${manuf//[[:space:]]/}"
+ ret=$(modem_info "$manuf" $model)
+ reti="$?"
+ ##echo "modem_info == "$ret
+ #echo "reti"$reti
+ if [ "$reti" == "0" ];then
+ echo "FOUND 3G MODEM "$model" "$manuf"?"
+ #echo "ret="$ret
+ #read usbid TMP TMP serialportnum serialport cmds reset<<<$(IFS=",";echo $ret)
+ tmp="/tmp/tmp.txt"
+ echo "$ret" >> $tmp
+ usbid=`awk -F "," '{print $1}' $tmp`
+ serialportnum=`awk -F "," '{print $4}' $tmp`
+ serialport=`awk -F "," '{print $5}' $tmp`
+ cmds=`awk -F "," '{print $6}' $tmp`
+ reset=`awk -F "," '{print $7}' $tmp`
+ rm -f $tmp
+
+
+
+ #echo usbid "$usbid"
+ #echo serialportnum "$serialportnum"
+ #echo serialport "$serialport"
+
+ if [ "$reset" == "1" ]; then
+ echo "RESET MODEM"
+ $usbreset "$vid:$pid" >/dev/null
+ fi
+
+ #echo "cmds="$cmds
+ if [ "$cmds" != "" ]; then
+
+ gcomscr_start
+ old_ifs="$IFS"
+ IFS=$';'
+ for cmd in $cmds; do
+ #echo "CMD : "$cmd
+ gcomscr_add_cmd $cmd
+ done
+ IFS="$old_ifs"
+ gcomscr_end
+ gcomscr_run $dev
+ fi
+ fi
+ fi
+ fi
+ done
+done
+rm -f /tmp/modem3g.*
+
+exit 1
+
+
diff --git a/package/query3g/files/usr/bin/modemname.sh b/package/query3g/files/usr/bin/modemname.sh
new file mode 100755
index 000000000..f19e42543
--- /dev/null
+++ b/package/query3g/files/usr/bin/modemname.sh
@@ -0,0 +1,33 @@
+. /usr/share/libubox/jshn.sh
+
+ret=1
+
+s=`cat /usr/share/3gmodem/modem.json`
+json_load "$s"
+#echo "JSON file loaded"
+
+#echo "modemname params $1--$2---$3"
+
+json_select data
+__idx=1
+#json_select "$((__idx))"
+while json_is_a "$__idx" object; do
+ json_select "$((__idx++))"
+ json_get_var var1 usbid
+ json_get_var var2 manufacture
+ json_get_var var3 model
+ json_get_var var4 serialportnum
+ json_get_var var5 serialport
+ json_get_var var6 cmds
+ json_get_var var7 reset
+ if [ "$var1" != "" ] && \
+ [ "$var2" == "$1" ] && \
+ [ "$var3" == "$2" ]; then
+ echo $var1","$var2","$var3","$var4","$var5","$var6","$var7
+ #echo "-------------------------------------------------"
+ ret=0
+ fi
+ json_select ".."
+done
+
+exit $ret
diff --git a/package/query3g/files/usr/bin/query3g.sh b/package/query3g/files/usr/bin/query3g.sh
new file mode 100755
index 000000000..33cfe2379
--- /dev/null
+++ b/package/query3g/files/usr/bin/query3g.sh
@@ -0,0 +1,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