summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--[-rwxr-xr-x]package/query3g/files/usr/bin/3gdetect.sh66
-rwxr-xr-xpackage/query3g/files/usr/bin/query3g205
-rw-r--r--package/query3g/files/usr/share/3gmodem/model.gcom70
-rw-r--r--package/query3g/files/usr/share/query3g.gcom8
4 files changed, 229 insertions, 120 deletions
diff --git a/package/query3g/files/usr/bin/3gdetect.sh b/package/query3g/files/usr/bin/3gdetect.sh
index 53715a9cc..da93c499e 100755..100644
--- a/package/query3g/files/usr/bin/3gdetect.sh
+++ b/package/query3g/files/usr/bin/3gdetect.sh
@@ -1,15 +1,18 @@
#!/bin/sh
DATA_DIR=./data
GCOM=comgt
-GCOM_MODEMDETECT="/usr/share/3gmodem/model.gcom"
+GCOM_MODEMDETECT="/usr/share/query3g.gcom"
MODEM_INFO="modemname.sh"
RETURN_APN=$DATA_DIR/apnprovider
usbreset=/usr/bin/usbreset
GCOM_CMD="/tmp/cmds.gcom"
+GCOM_OUT="/tmp/gcom.out"
detect_model()
{
- $GCOM -d $1 $2 | tail -n 1
+ #$1 device
+ #$2 script
+ $GCOM -d $1 -s $2 >> $GCOM_OUT
}
modem_info()
@@ -28,6 +31,7 @@ gcomscr_start()
send \"AT^m\"
waitfor 1 \"OK\",\"ERROR\" " >> $GCOM_CMD
+
}
gcomscr_add_cmd()
@@ -76,6 +80,10 @@ gcomscr_run()
$GCOM -d $1 $GCOM_CMD
}
+rm -f /tmp/modem3g.*
+rm -f $GCOM_OUT
+rm -f $GCOM_CMD
+
skip_cycles=0
skip_passed=0
known_modems=""
@@ -94,19 +102,21 @@ for port in 0 1 2 3 4 5 6 7 8 9; do
pid="$(cat "$tty/../../idProduct")"
#echo $dir
#echo $uid
- echo "DEVICE:"$dev
+ #echo "PORT:"$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
+ $GCOM -d $dev -s $GCOM_MODEMDETECT > $GCOM_OUT
+ model=$( echo `awk -F ':' '{if ($1=="DEVICE") {gsub(/^ */,"",$2);l_a=split($2,a," ");print a[l_a]}}' $GCOM_OUT | tr '[A-Z]' '[a-z]'` )
+ serialnum=$( echo `awk -F ':' '{if ($1=="SERIAL") {gsub(/^ */,"",$2);print $2}}' $GCOM_OUT` )
+ manuf=$(echo `awk -F ':' '{if ($1=="DEVICE") {gsub(/^ */,"",$2);l_a=split($2,a," ");r="";for(i=1;i<l_a;i++)r=r""a[i]" ";gsub(/[[:space:]]*/,"",r); print r}}' $GCOM_OUT | tr '[A-Z]' '[a-z]'`)
- #FILE="/tmp/modem3g.$serialnum"
+ if [ "$model" != "" ] && [ "$manuf" != "" ]; then
+ manuf="${manuf//[[:space:]]/}"
+ #echo "DEVICE:["$manuf"] ["$model"]"
+ #echo "IMEI:"$serialnum
+ fi
+
+ FILE="/tmp/modem3g.$serialnum"
#echo "FILE:"$FILE
if [ -f $FILE ]; then
found=1
@@ -119,21 +129,23 @@ for port in 0 1 2 3 4 5 6 7 8 9; do
if [ $found -eq 0 ]; then
touch /tmp/modem3g.$serialnum
manuf="${manuf//[[:space:]]/}"
+ #echo "$manuf" $model
ret=$(modem_info "$manuf" $model)
reti="$?"
- ##echo "modem_info == "$ret
+ #echo "modem_info == "$ret
#echo "reti"$reti
if [ "$reti" == "0" ];then
- echo "FOUND 3G MODEM "$model" "$manuf"?"
+ #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`
+ 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
@@ -143,7 +155,7 @@ for port in 0 1 2 3 4 5 6 7 8 9; do
#echo serialport "$serialport"
if [ "$reset" == "1" ]; then
- echo "RESET MODEM"
+ #echo "RESET MODEM"
$usbreset "$vid:$pid" >/dev/null
fi
@@ -161,12 +173,20 @@ for port in 0 1 2 3 4 5 6 7 8 9; do
gcomscr_end
gcomscr_run $dev
fi
+
+ awk '1' $GCOM_OUT
+
+ echo "PORT:$dev"
+ echo "VID:$vid"
+ echo "PID:$pid"
+ echo "UID:$uid"
+ exit 0
fi
fi
fi
done
done
-rm -f /tmp/modem3g.*
+
exit 1
diff --git a/package/query3g/files/usr/bin/query3g b/package/query3g/files/usr/bin/query3g
index 33cfe2379..da93c499e 100755
--- a/package/query3g/files/usr/bin/query3g
+++ b/package/query3g/files/usr/bin/query3g
@@ -1,42 +1,193 @@
#!/bin/sh
+DATA_DIR=./data
+GCOM=comgt
+GCOM_MODEMDETECT="/usr/share/query3g.gcom"
+MODEM_INFO="modemname.sh"
+RETURN_APN=$DATA_DIR/apnprovider
+usbreset=/usr/bin/usbreset
+GCOM_CMD="/tmp/cmds.gcom"
+GCOM_OUT="/tmp/gcom.out"
-reset=/usr/bin/usbreset
-comgt=/usr/bin/gcom
-script=/usr/share/query3g.gcom
+detect_model()
+{
+ #$1 device
+ #$2 script
+ $GCOM -d $1 -s $2 >> $GCOM_OUT
+}
-last_reset="x"
+modem_info()
+{
+ $MODEM_INFO "$1" $2
+}
-wan_proto="$(uci -q get network.wan.proto)"
+gcomscr_start()
+{
+ rm $GCOM_CMD
+ echo "opengt
+ set com 115200n81
+ set comecho off
+ set senddelay 0.02
+ waitquiet 0.2 0.2
-if [ "$wan_proto" = "3g" ]; then
- ifdown wan
-fi
+ send \"AT^m\"
+ waitfor 1 \"OK\",\"ERROR\" " >> $GCOM_CMD
+
+}
-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
+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
- local dir="$(cd "$tty/../.."; pwd)"
- local uid="$(basename "$dir")"
- local dev="/dev/$(basename "$tty")"
- local vid="$(cat "$tty/../../idVendor")"
- local pid="$(cat "$tty/../../idProduct")"
+:loop4
+ let \$s=\"\"
+ return
- if [ "$last_reset" != "$vid:$pid" ] && [ "$vid:$pid" != "0685:7000" ]; then
- last_reset="$vid:$pid"
-# $reset "$vid:$pid" >/dev/null
+:loop5
+ if i = 0 return
+ let i=i-1
+ sleep 0.25
+ goto loop3
+ " >> $GCOM_CMD
+}
- local try=0
- while [ $((try++)) -lt 5 ] && [ ! -e "$dev" ]; do sleep 1; done
+gcomscr_run()
+{
+ $GCOM -d $1 $GCOM_CMD
+}
+
+rm -f /tmp/modem3g.*
+rm -f $GCOM_OUT
+rm -f $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 "PORT:"$dev
+ #echo $vid":"$pid
+
+ $GCOM -d $dev -s $GCOM_MODEMDETECT > $GCOM_OUT
+ model=$( echo `awk -F ':' '{if ($1=="DEVICE") {gsub(/^ */,"",$2);l_a=split($2,a," ");print a[l_a]}}' $GCOM_OUT | tr '[A-Z]' '[a-z]'` )
+ serialnum=$( echo `awk -F ':' '{if ($1=="SERIAL") {gsub(/^ */,"",$2);print $2}}' $GCOM_OUT` )
+ manuf=$(echo `awk -F ':' '{if ($1=="DEVICE") {gsub(/^ */,"",$2);l_a=split($2,a," ");r="";for(i=1;i<l_a;i++)r=r""a[i]" ";gsub(/[[:space:]]*/,"",r); print r}}' $GCOM_OUT | tr '[A-Z]' '[a-z]'`)
+
+ if [ "$model" != "" ] && [ "$manuf" != "" ]; then
+ manuf="${manuf//[[:space:]]/}"
+ #echo "DEVICE:["$manuf"] ["$model"]"
+ #echo "IMEI:"$serialnum
+ fi
+
+ FILE="/tmp/modem3g.$serialnum"
+ #echo "FILE:"$FILE
+ if [ -f $FILE ]; then
+ found=1
+ else
+ found=0
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
+ if [ "$model" != "" ] && \
+ [ "$manuf" != "" ]; then
+ if [ $found -eq 0 ]; then
+ touch /tmp/modem3g.$serialnum
+ manuf="${manuf//[[:space:]]/}"
+ #echo "$manuf" $model
+ 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
+
+
+ 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
+
+ awk '1' $GCOM_OUT
+
+ echo "PORT:$dev"
+ echo "VID:$vid"
+ echo "PID:$pid"
+ echo "UID:$uid"
+ exit 0
+ fi
+ fi
fi
done
done
+
+
exit 1
+
+
diff --git a/package/query3g/files/usr/share/3gmodem/model.gcom b/package/query3g/files/usr/share/3gmodem/model.gcom
deleted file mode 100644
index 40dcc4096..000000000
--- a/package/query3g/files/usr/share/3gmodem/model.gcom
+++ /dev/null
@@ -1,70 +0,0 @@
-opengt
- set com 115200n81
- set comecho off
- set senddelay 0.02
- waitquiet 0.2 0.2
-
- send "AT^m"
- waitfor 1 "OK","ERROR"
-
- let $c="AT+CGMI^m"
- gosub readatcmdnr
- let $v=$s
-
- let $c="AT+CGSN^m"
- gosub readatcmdnr
- let $n=$s
-
- let $c="AT+CGMM^m"
- gosub readatcmdnr
- print $v,",",$s,",",$n,"\n"
-
- exit 0
-
-
-:readatcmd
- let i=5
- send $c
-:loop
- get 1 "^m" $s
- let l=len($r)
- if len($s) < l goto loop1
- if $mid($s,1,l) <> $r goto loop1
- print $s
- return
-
-:loop1
- if len($s) < 2 goto loop2
- if $mid($s,1,2) = "ER" return
- if $mid($s,1,2) = "CO" return
-:loop2
- if i = 0 return
- let i=i-1
- sleep 0.25
- goto loop
-
-: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
diff --git a/package/query3g/files/usr/share/query3g.gcom b/package/query3g/files/usr/share/query3g.gcom
index 9b3ecc6cb..08770310d 100644
--- a/package/query3g/files/usr/share/query3g.gcom
+++ b/package/query3g/files/usr/share/query3g.gcom
@@ -139,6 +139,12 @@ opengt
:next1
+ let $c="AT+CGSN^m"
+ gosub readatcmdnr
+ let $n=$s
+ print "\nIMEI: ",$n,""
+
+
let $c="AT+CREG=2; +CREG?^m"
let $r="+CREG"
gosub readatcmd
@@ -151,6 +157,8 @@ opengt
let $r="+CGEQNEG"
gosub readatcmd
+
+
let $c="ATE1; +CGMM^m"
gosub readatcmdnr
print "\nDEVICE:",$v," ",$s,"\n"