diff options
-rw-r--r-- | package/query3g/Makefile | 37 | ||||
-rw-r--r-- | package/query3g/files/query3g.gcom | 148 | ||||
-rw-r--r-- | package/query3g/files/query3g.sh | 42 |
3 files changed, 227 insertions, 0 deletions
diff --git a/package/query3g/Makefile b/package/query3g/Makefile new file mode 100644 index 000000000..f18e09903 --- /dev/null +++ b/package/query3g/Makefile @@ -0,0 +1,37 @@ +# +# Copyright (C) 2012 Jo-Philipp Wich <xm@subsignal.org> +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=query3g +PKG_RELEASE:=2 + +include $(INCLUDE_DIR)/package.mk + +define Package/query3g + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:=+usbreset +comgt + TITLE:=Utility to find 3G dongle information + MAINTAINER:=Jo-Philipp Wich <xm@subsignal.org> +endef + +define Package/query3g/description + This package contains the small query3g utility to find 3G dongle information. +endef + +define Build/Compile +endef + +define Package/query3g/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) ./files/query3g.sh $(1)/usr/bin/query3g + $(INSTALL_DIR) $(1)/usr/share + $(INSTALL_DATA) ./files/query3g.gcom $(1)/usr/share/query3g.gcom +endef + +$(eval $(call BuildPackage,query3g)) diff --git a/package/query3g/files/query3g.gcom b/package/query3g/files/query3g.gcom new file mode 100644 index 000000000..f63207805 --- /dev/null +++ b/package/query3g/files/query3g.gcom @@ -0,0 +1,148 @@ +opengt + set com 115200n81 + set comecho off + set senddelay 0.02 + waitquiet 0.2 0.2 + + send "AT\^CURC=0^m" + waitfor 5 "OK","ERROR" + + let $c="AT+CPIN?^m" + let $r="+CPIN" + gosub readatcmd + + let $c="AT+CSQ^m" + let $r="+CSQ" + gosub readatcmd + + let $c="ATE1; +CGMI^m" + gosub readatcmdnr + let $v=$s + + if $toupper($mid($v,0,3)) = "ZTE" goto zte + if $toupper($mid($v,0,3)) = "OPT" goto option + if $toupper($mid($v,0,3)) = "SIE" goto sierra + if $toupper($mid($v,0,3)) = "NOV" goto novatel + if $toupper($mid($v,0,3)) = "HUA" goto huawei + if $toupper($mid($v,0,3)) = "VOD" goto vodafone + if $toupper($mid($v,0,3)) = "NOK" goto vodafone + goto generic + +:vodafone + let $c="AT%NWSTATE=1^m" + let $r="%NWSTATE" + gosub readatcmd + goto next + +:novatel + let $c="AT$CNTI=0^m" + let $r="$CNTI" + gosub readatcmd + goto next + +:sierra + let $c="AT*CNTI=0^m" + let $r="*CNTI" + gosub readatcmd + goto next + +:option + let $c="AT_OCTI?^m" + let $r="_OCTI" + gosub readatcmd + + let $c="AT_OWCTI?^m" + let $r="_OWCTI" + gosub readatcmd + goto next + +:zte + let $c="AT+COPS?^m" + let $r="+COPS" + gosub readatcmd + + let $c="AT+ZPAS?^m" + let $r="+ZPAS" + gosub readatcmd + goto next1 + +:huawei + let $c="AT\^SYSINFOEX^m" + let $r="\^SYSINFOEX" + gosub readatcmd + +:generic + let $c="AT\^SYSINFO^m" + let $r="\^SYSINFO" + gosub readatcmd + +:next + let $c="AT+COPS=3,2; +COPS?^m" + let $r="+COPS" + gosub readatcmd + +:next1 + let $c="AT+CREG=2; +CREG?^m" + let $r="+CREG" + gosub readatcmd + + let $c="AT+CGREG=2; +CGREG?^m" + let $r="+CGREG" + gosub readatcmd + + let $c="AT+CGEQNEG=1^m" + let $r="+CGEQNEG" + gosub readatcmd + + let $c="ATE1; +CGMM^m" + gosub readatcmdnr + print "\nDEVICE:",$v," ",$s,"\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/query3g.sh b/package/query3g/files/query3g.sh new file mode 100644 index 000000000..b591d61a3 --- /dev/null +++ b/package/query3g/files/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" ]; 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 |