From 716ca530e1c4515d8683c9d5be3d56b301758b66 Mon Sep 17 00:00:00 2001 From: James <> Date: Wed, 4 Nov 2015 11:49:21 +0000 Subject: trunk-47381 --- package/network/utils/comgt/files/3g.chat | 12 ++ package/network/utils/comgt/files/3g.sh | 110 ++++++++++++ package/network/utils/comgt/files/3g.usb | 33 ++++ .../network/utils/comgt/files/directip-stop.gcom | 16 ++ package/network/utils/comgt/files/directip.gcom | 55 ++++++ package/network/utils/comgt/files/directip.sh | 111 ++++++++++++ package/network/utils/comgt/files/evdo.chat | 17 ++ package/network/utils/comgt/files/getcardinfo.gcom | 14 ++ package/network/utils/comgt/files/getcarrier.gcom | 20 +++ package/network/utils/comgt/files/getcnum.gcom | 20 +++ package/network/utils/comgt/files/getimsi.gcom | 17 ++ package/network/utils/comgt/files/getstrength.gcom | 14 ++ package/network/utils/comgt/files/ncm.json | 67 +++++++ package/network/utils/comgt/files/ncm.sh | 192 +++++++++++++++++++++ package/network/utils/comgt/files/runcommand.gcom | 31 ++++ package/network/utils/comgt/files/setmode.gcom | 26 +++ package/network/utils/comgt/files/setpin.gcom | 55 ++++++ 17 files changed, 810 insertions(+) create mode 100644 package/network/utils/comgt/files/3g.chat create mode 100644 package/network/utils/comgt/files/3g.sh create mode 100644 package/network/utils/comgt/files/3g.usb create mode 100644 package/network/utils/comgt/files/directip-stop.gcom create mode 100644 package/network/utils/comgt/files/directip.gcom create mode 100644 package/network/utils/comgt/files/directip.sh create mode 100644 package/network/utils/comgt/files/evdo.chat create mode 100644 package/network/utils/comgt/files/getcardinfo.gcom create mode 100644 package/network/utils/comgt/files/getcarrier.gcom create mode 100644 package/network/utils/comgt/files/getcnum.gcom create mode 100644 package/network/utils/comgt/files/getimsi.gcom create mode 100644 package/network/utils/comgt/files/getstrength.gcom create mode 100644 package/network/utils/comgt/files/ncm.json create mode 100644 package/network/utils/comgt/files/ncm.sh create mode 100644 package/network/utils/comgt/files/runcommand.gcom create mode 100644 package/network/utils/comgt/files/setmode.gcom create mode 100644 package/network/utils/comgt/files/setpin.gcom (limited to 'package/network/utils/comgt/files') diff --git a/package/network/utils/comgt/files/3g.chat b/package/network/utils/comgt/files/3g.chat new file mode 100644 index 0000000..6656240 --- /dev/null +++ b/package/network/utils/comgt/files/3g.chat @@ -0,0 +1,12 @@ +ABORT BUSY +ABORT 'NO CARRIER' +ABORT ERROR +REPORT CONNECT +TIMEOUT 10 +"" "AT&F" +OK "ATE1" +OK 'AT+CGDCONT=1,"IP","$USE_APN"' +SAY "Calling UMTS/GPRS" +TIMEOUT 30 +OK "ATD$DIALNUMBER" +CONNECT ' ' diff --git a/package/network/utils/comgt/files/3g.sh b/package/network/utils/comgt/files/3g.sh new file mode 100644 index 0000000..b0cdae2 --- /dev/null +++ b/package/network/utils/comgt/files/3g.sh @@ -0,0 +1,110 @@ +#!/bin/sh + +[ -n "$INCLUDE_ONLY" ] || { + NOT_INCLUDED=1 + INCLUDE_ONLY=1 + + . ../netifd-proto.sh + . ./ppp.sh + init_proto "$@" +} + +proto_3g_init_config() { + no_device=1 + available=1 + ppp_generic_init_config + proto_config_add_string "device:device" + proto_config_add_string "apn" + proto_config_add_string "service" + proto_config_add_string "pincode" + proto_config_add_string "dialnumber" +} + +proto_3g_setup() { + local interface="$1" + local chat + + json_get_var device device + json_get_var apn apn + json_get_var service service + json_get_var pincode pincode + json_get_var dialnumber dialnumber + + [ -n "$dat_device" ] && device=$dat_device + [ -e "$device" ] || { + proto_set_available "$interface" 0 + return 1 + } + + case "$service" in + cdma|evdo) + chat="/etc/chatscripts/evdo.chat" + ;; + *) + chat="/etc/chatscripts/3g.chat" + cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom) + if echo "$cardinfo" | grep -q Novatel; then + case "$service" in + umts_only) CODE=2;; + gprs_only) CODE=1;; + *) CODE=0;; + esac + export MODE="AT\$NWRAT=${CODE},2" + elif echo "$cardinfo" | grep -q Option; then + case "$service" in + umts_only) CODE=1;; + gprs_only) CODE=0;; + *) CODE=3;; + esac + export MODE="AT_OPSYS=${CODE}" + elif echo "$cardinfo" | grep -q "Sierra Wireless"; then + SIERRA=1 + elif echo "$cardinfo" | grep -qi huawei; then + case "$service" in + umts_only) CODE="14,2";; + gprs_only) CODE="13,1";; + *) CODE="2,2";; + esac + export MODE="AT^SYSCFG=${CODE},3FFFFFFF,2,4" + fi + + if [ -n "$pincode" ]; then + PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || { + proto_notify_error "$interface" PIN_FAILED + proto_block_restart "$interface" + return 1 + } + fi + [ -n "$MODE" ] && gcom -d "$device" -s /etc/gcom/setmode.gcom + + # wait for carrier to avoid firmware stability bugs + [ -n "$SIERRA" ] && { + gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1 + } + + if [ -z "$dialnumber" ]; then + dialnumber="*99***1#" + fi + + ;; + esac + + connect="${apn:+USE_APN=$apn }DIALNUMBER=$dialnumber /usr/sbin/chat -t5 -v -E -f $chat" + ppp_generic_setup "$interface" \ + noaccomp \ + nopcomp \ + novj \ + nobsdcomp \ + noauth \ + set EXTENDPREFIX=1 \ + lock \ + crtscts \ + 115200 "$device" + return 0 +} + +proto_3g_teardown() { + proto_kill_command "$interface" +} + +[ -z "NOT_INCLUDED" ] || add_protocol 3g diff --git a/package/network/utils/comgt/files/3g.usb b/package/network/utils/comgt/files/3g.usb new file mode 100644 index 0000000..ac8326b --- /dev/null +++ b/package/network/utils/comgt/files/3g.usb @@ -0,0 +1,33 @@ +#!/bin/sh +. /lib/functions.sh +. /lib/netifd/netifd-proto.sh + +find_3g_iface() { + local cfg="$1" + local tty="$2" + + local proto + config_get proto "$cfg" proto + [ "$proto" = 3g ] || [ "$proto" = ncm ] || return 0 + + # bypass state vars here because 00-netstate could clobber .device + local dev=$(uci_get network "$cfg" device) + + if [ "${dev##*/}" = "${tty##*/}" ]; then + if [ "$ACTION" = add ]; then + available=1 + else + available=0 + fi + proto_set_available "$cfg" $available + fi +} + +case "$DEVICENAME" in + tty*) + [ -e "/dev/$DEVICENAME" ] || [ "$ACTION" = remove ] || exit 0 + config_load network + config_foreach find_3g_iface interface "/dev/$DEVICENAME" + ;; +esac + diff --git a/package/network/utils/comgt/files/directip-stop.gcom b/package/network/utils/comgt/files/directip-stop.gcom new file mode 100644 index 0000000..1c14863 --- /dev/null +++ b/package/network/utils/comgt/files/directip-stop.gcom @@ -0,0 +1,16 @@ +opengt +set com 115200n81 +set comecho off +set senddelay 0.05 +waitquiet 1 0.2 + +:start + send "AT!SCACT=0,3^m" + waitfor 5 "OK" + if % = 0 goto hangupok + print "WWAN error. Hangup failed.\r\n" + exit 1 + +:hangupok + print "WWAN connection established.\r\n" + exit 0 diff --git a/package/network/utils/comgt/files/directip.gcom b/package/network/utils/comgt/files/directip.gcom new file mode 100644 index 0000000..9a772a9 --- /dev/null +++ b/package/network/utils/comgt/files/directip.gcom @@ -0,0 +1,55 @@ +opengt +set com 115200n81 +set comecho off +set senddelay 0.05 +waitquiet 1 0.2 + +:start + if $env("USE_AUTH") = "0" goto connect + send "AT$QCPDPP=3," + send $env("USE_AUTH") + send ",\"" + if $env("USE_USER") <> "" send $env("USE_USER") + send "\",\"" + if $env("USE_PASS") <> "" send $env("USE_PASS") + send "\"^m" + waitfor 5 "OK" + if % = 0 goto connect + print "WWAN error. Auth failed.\r\n" + exit 1 + +:connect + send "AT+CFUN=1^m" + send "AT+CGDCONT=3,\"IP\",\"" + send $env("USE_APN") + send "\"^m" + waitfor 5 "OK" + if % = 0 goto connok + print "WWAN error. Connection failed.\r\n" + exit 1 + +:connok + let c=1 +:loop + sleep 2 + send "AT+CGATT?^m" + waitfor 5 "+CGATT: 1" + if % = 0 goto carrierok + if c > 10 goto carriererr + inc c + goto loop + +:carriererr + print "WWAN error. No carrier.\r\n" + exit 1 + +:carrierok + send "AT!SCACT=1,3^m" + waitfor 5 "OK" + if % = 0 goto dialok + print "WWAN error. Dialing failed.\r\n" + exit 1 + +:dialok + print "WWAN connection established.\r\n" + exit 0 diff --git a/package/network/utils/comgt/files/directip.sh b/package/network/utils/comgt/files/directip.sh new file mode 100644 index 0000000..d828052 --- /dev/null +++ b/package/network/utils/comgt/files/directip.sh @@ -0,0 +1,111 @@ +#!/bin/sh + +[ -n "$INCLUDE_ONLY" ] || { + . /lib/functions.sh + . ../netifd-proto.sh + init_proto "$@" +} + +proto_directip_init_config() { + available=1 + no_device=1 + proto_config_add_string "device:device" + proto_config_add_string "apn" + proto_config_add_string "pincode" + proto_config_add_string "auth" + proto_config_add_string "username" + proto_config_add_string "password" +} + +proto_directip_setup() { + local interface="$1" + local chat devpath devname + + local device apn pincode ifname auth username password + json_get_vars device apn pincode auth username password + + [ -n "$ctl_device" ] && device=$ctl_device + + [ -e "$device" ] || { + proto_notify_error "$interface" NO_DEVICE + proto_set_available "$interface" 0 + return 1 + } + + devname="$(basename "$device")" + devpath="$(readlink -f /sys/class/tty/$devname/device)" + ifname="$( ls "$devpath"/../../*/net )" + + [ -n "$ifname" ] || { + proto_notify_error "$interface" NO_IFNAME + proto_set_available "$interface" 0 + return 1 + } + + cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom) + [ -n $(echo "$cardinfo" | grep -q "Sierra Wireless") ] || { + proto_notify_error "$interface" BAD_DEVICE + proto_block_restart "$interface" + return 1 + } + + if [ -n "$pincode" ]; then + PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || { + proto_notify_error "$interface" PIN_FAILED + proto_block_restart "$interface" + return 1 + } + fi + # wait for carrier to avoid firmware stability bugs + gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1 + + local auth_type=0 + case $auth in + pap) auth_type=1;; + chap) auth_type=2;; + esac + + USE_APN="$apn" USE_USER="$username" USE_PASS="$password" USE_AUTH="$auth_type" \ + gcom -d "$device" -s /etc/gcom/directip.gcom || { + proto_notify_error "$interface" CONNECT_FAILED + proto_block_restart "$interface" + return 1 + } + + logger -p daemon.info -t "directip[$$]" "Connected, starting DHCP" + proto_init_update "$ifname" 1 + proto_send_update "$interface" + + json_init + json_add_string name "${interface}_4" + json_add_string ifname "@$interface" + json_add_string proto "dhcp" + ubus call network add_dynamic "$(json_dump)" + + json_init + json_add_string name "${interface}_6" + json_add_string ifname "@$interface" + json_add_string proto "dhcpv6" + json_add_string extendprefix 1 + ubus call network add_dynamic "$(json_dump)" + + return 0 +} + +proto_directip_teardown() { + local interface="$1" + + local device + json_get_vars device + + [ -n "$ctl_device" ] && device=$ctl_device + + gcom -d "$device" -s /etc/gcom/directip-stop.gcom || proto_notify_error "$interface" CONNECT_FAILED + + proto_init_update "*" 0 + proto_send_update "$interface" +} + +[ -n "$INCLUDE_ONLY" ] || { + add_protocol directip +} diff --git a/package/network/utils/comgt/files/evdo.chat b/package/network/utils/comgt/files/evdo.chat new file mode 100644 index 0000000..de49e41 --- /dev/null +++ b/package/network/utils/comgt/files/evdo.chat @@ -0,0 +1,17 @@ +# This is a simple chat script based off of the one provided by Sierra Wireless +# for CDMA connections. It should work for both Sprint and Verizon networks. + +ABORT BUSY +ABORT 'NO CARRIER' +ABORT ERROR +ABORT 'NO DIAL TONE' +ABORT 'NO ANSWER' +ABORT DELAYED +REPORT CONNECT +TIMEOUT 10 +'' AT +OK ATZ +SAY 'Calling CDMA/EVDO' +TIMEOUT 30 +OK ATDT#777 +CONNECT '' diff --git a/package/network/utils/comgt/files/getcardinfo.gcom b/package/network/utils/comgt/files/getcardinfo.gcom new file mode 100644 index 0000000..5c69a64 --- /dev/null +++ b/package/network/utils/comgt/files/getcardinfo.gcom @@ -0,0 +1,14 @@ +opengt + set com 115200n81 + set comecho off + set senddelay 0.02 + waitquiet 0.2 0.2 + flash 0.1 + +:start + send "ATI^m" + get 1 "" $s + print $s + +:continue + exit 0 diff --git a/package/network/utils/comgt/files/getcarrier.gcom b/package/network/utils/comgt/files/getcarrier.gcom new file mode 100644 index 0000000..1e0216d --- /dev/null +++ b/package/network/utils/comgt/files/getcarrier.gcom @@ -0,0 +1,20 @@ +opengt + set senddelay 0.05 + waitquiet 1 0.2 + let c=1 + :loop + inc c + send "AT+CGATT?^m" + waitfor 5 "+CGATT: 1","+CGATT: 0" + print "\n." + if % = -1 goto error + if c > 10 goto toolong + if % = 0 goto out + sleep 2 + if % = 1 goto loop + :toolong + exit 1 + :error + exit 0 + :out + exit 0 diff --git a/package/network/utils/comgt/files/getcnum.gcom b/package/network/utils/comgt/files/getcnum.gcom new file mode 100644 index 0000000..450cf8c --- /dev/null +++ b/package/network/utils/comgt/files/getcnum.gcom @@ -0,0 +1,20 @@ +opengt + set com 115200n81 + set comecho off + set senddelay 0.02 + waitquiet 0.2 0.2 + flash 0.1 + +:start + send "AT+CNUM^m" + get 1 "^m" $n + get 1 ":" $n + get 1 "\"" $n + get 1 "\"" $n + get 1 "\"" $n + get 1 "\"" $n + let n = len($n) + if n<1 goto continue + print $n +:continue + exit 0 diff --git a/package/network/utils/comgt/files/getimsi.gcom b/package/network/utils/comgt/files/getimsi.gcom new file mode 100644 index 0000000..0485456 --- /dev/null +++ b/package/network/utils/comgt/files/getimsi.gcom @@ -0,0 +1,17 @@ +opengt + set com 115200n81 + set comecho off + set senddelay 0.02 + waitquiet 0.2 0.2 + flash 0.1 + +:start + send "AT+CIMI^m" + get 1 "^m" $s + get 1 "^m" $s + let x = len($s) + if x<2 goto continue + let $s = $right($s, x-1) + print $s +:continue + exit 0 diff --git a/package/network/utils/comgt/files/getstrength.gcom b/package/network/utils/comgt/files/getstrength.gcom new file mode 100644 index 0000000..2886285 --- /dev/null +++ b/package/network/utils/comgt/files/getstrength.gcom @@ -0,0 +1,14 @@ +opengt + set com 115200n81 + set comecho off + set senddelay 0.02 + waitquiet 0.2 0.2 + flash 0.1 + +:start + send "AT+CSQ^m" + get 1 "" $s + print $s + +:continue + exit 0 diff --git a/package/network/utils/comgt/files/ncm.json b/package/network/utils/comgt/files/ncm.json new file mode 100644 index 0000000..d1f8699 --- /dev/null +++ b/package/network/utils/comgt/files/ncm.json @@ -0,0 +1,67 @@ +{ + "huawei": { + "initialize": [ + "AT", + "ATZ", + "ATQ0", + "ATV1", + "ATE1", + "ATS0=0", + "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\"" + ], + "modes": { + "preferlte": "AT^SYSCFGEX=\\\"030201\\\",3fffffff,2,4,7fffffffffffffff,,", + "preferumts": "AT^SYSCFGEX=\\\"0201\\\",3fffffff,2,4,7fffffffffffffff,,", + "lte": "AT^SYSCFGEX=\\\"03\\\",3fffffff,2,4,7fffffffffffffff,,", + "umts": "AT^SYSCFGEX=\\\"02\\\",3fffffff,2,4,7fffffffffffffff,,", + "gsm": "AT^SYSCFGEX=\\\"01\\\",3fffffff,2,4,7fffffffffffffff,,", + "auto": "AT^SYSCFGEX=\\\"00\\\",3fffffff,2,4,7fffffffffffffff,," + }, + "connect": "AT^NDISDUP=1,1,\\\"${apn}\\\"${username:+,\\\"$username\\\"}${password:+,\\\"$password\\\"}${auth:+,$auth}", + "disconnect": "AT^NDISDUP=1,0" + }, + "samsung": { + "initialize": [ + "AT", + "AT+CGREG=2", + "AT+CFUN=5", + "AT+MODESELECT=3", + "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\"" + ], + "modes": { + "umts": "AT+CHANGEALLPATH=1" + }, + "connect": "AT+CGATT=1", + "disconnect": "AT+CGATT=0" + }, + "sierra wireless, incorporated": { + "initialize": [ + "AT+CFUN=1", + "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\"", + "AT$QCPDPP=1${auth:+,$auth}${password:+,\\\"$password\\\"}${username:+,\\\"$username\\\"}" + ], + "modes": { + "preferlte": "AT!SELRAT=07", + "preferumts": "AT!SELRAT=05", + "lte": "AT!SELRAT=06", + "umts": "AT!SELRAT=01", + "gsm": "AT!SELRAT=02", + "auto": "AT!SELRAT=00" + }, + "connect": "AT!SCACT=1,1", + "disconnect": "AT!SCACT=0,1" + }, + "sony ericsson": { + "initialize": [ + "AT+CFUN=1", + "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\"", + "AT*EIAAUW=1,1,\\\"${username}\\\",\\\"${password}\\\",${auth:-00111}" + ], + "modes": { + "umts": "AT+CFUN=6", + "gsm": "AT+CFUN=5" + }, + "connect": "AT*ENAP=1,1", + "disconnect": "AT*ENAP=0" + } +} diff --git a/package/network/utils/comgt/files/ncm.sh b/package/network/utils/comgt/files/ncm.sh new file mode 100644 index 0000000..571cfaa --- /dev/null +++ b/package/network/utils/comgt/files/ncm.sh @@ -0,0 +1,192 @@ +#!/bin/sh + +[ -n "$INCLUDE_ONLY" ] || { + . /lib/functions.sh + . ../netifd-proto.sh + init_proto "$@" +} + +proto_ncm_init_config() { + no_device=1 + available=1 + proto_config_add_string "device:device" + proto_config_add_string apn + proto_config_add_string auth + proto_config_add_string username + proto_config_add_string password + proto_config_add_string pincode + proto_config_add_string delay + proto_config_add_string mode + proto_config_add_string pdptype + proto_config_add_boolean ipv6 +} + +proto_ncm_setup() { + local interface="$1" + + local manufacturer initialize setmode connect ifname devname devpath + + local device apn auth username password pincode delay mode pdptype ipv6 + json_get_vars device apn auth username password pincode delay mode pdptype ipv6 + + if [ "$ipv6" = 0 ]; then + ipv6="" + else + ipv6=1 + fi + + [ -z "$pdptype" ] && { + if [ -n "$ipv6" ]; then + pdptype="IPV4V6" + else + pdptype="IP" + fi + } + + [ -n "$ctl_device" ] && device=$ctl_device + + [ -n "$device" ] || { + echo "No control device specified" + proto_notify_error "$interface" NO_DEVICE + proto_set_available "$interface" 0 + return 1 + } + [ -e "$device" ] || { + echo "Control device not valid" + proto_set_available "$interface" 0 + return 1 + } + [ -n "$apn" ] || { + echo "No APN specified" + proto_notify_error "$interface" NO_APN + return 1 + } + + devname="$(basename "$device")" + case "$devname" in + 'tty'*) + devpath="$(readlink -f /sys/class/tty/$devname/device)" + ifname="$( ls "$devpath"/../../*/net )" + ;; + *) + devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)" + ifname="$( ls "$devpath"/net )" + ;; + esac + [ -n "$ifname" ] || { + echo "The interface could not be found." + proto_notify_error "$interface" NO_IFACE + proto_set_available "$interface" 0 + return 1 + } + + [ -n "$delay" ] && sleep "$delay" + + manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print tolower($2) }'` + [ $? -ne 0 ] && { + echo "Failed to get modem information" + proto_notify_error "$interface" GETINFO_FAILED + return 1 + } + + json_load "$(cat /etc/gcom/ncm.json)" + json_select "$manufacturer" + [ $? -ne 0 ] && { + echo "Unsupported modem" + proto_notify_error "$interface" UNSUPPORTED_MODEM + proto_set_available "$interface" 0 + return 1 + } + json_get_values initialize initialize + for i in $initialize; do + eval COMMAND="$i" gcom -d "$device" -s /etc/gcom/runcommand.gcom || { + echo "Failed to initialize modem" + proto_notify_error "$interface" INITIALIZE_FAILED + return 1 + } + done + + [ -n "$pincode" ] && { + PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || { + echo "Unable to verify PIN" + proto_notify_error "$interface" PIN_FAILED + proto_block_restart "$interface" + return 1 + } + } + [ -n "$mode" ] && { + json_select modes + json_get_var setmode "$mode" + COMMAND="$setmode" gcom -d "$device" -s /etc/gcom/runcommand.gcom || { + echo "Failed to set operating mode" + proto_notify_error "$interface" SETMODE_FAILED + return 1 + } + json_select .. + } + + json_get_vars connect + eval COMMAND="$connect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || { + echo "Failed to connect" + proto_notify_error "$interface" CONNECT_FAILED + return 1 + } + + echo "Connected, starting DHCP on $ifname" + + proto_init_update "$ifname" 1 + proto_send_update "$interface" + + json_init + json_add_string name "${interface}_4" + json_add_string ifname "@$interface" + json_add_string proto "dhcp" + ubus call network add_dynamic "$(json_dump)" + + [ -n "$ipv6" ] && { + json_init + json_add_string name "${interface}_6" + json_add_string ifname "@$interface" + json_add_string proto "dhcpv6" + json_add_string extendprefix 1 + ubus call network add_dynamic "$(json_dump)" + } +} + +proto_ncm_teardown() { + local interface="$1" + + local manufacturer disconnect + + local device + json_get_vars device + + echo "Stopping network" + + manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print tolower($2) }'` + [ $? -ne 0 ] && { + echo "Failed to get modem information" + proto_notify_error "$interface" GETINFO_FAILED + return 1 + } + + json_load "$(cat /etc/gcom/ncm.json)" + json_select "$manufacturer" || { + echo "Unsupported modem" + proto_notify_error "$interface" UNSUPPORTED_MODEM + return 1 + } + + json_get_vars disconnect + COMMAND="$disconnect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || { + echo "Failed to disconnect" + proto_notify_error "$interface" DISCONNECT_FAILED + return 1 + } + + proto_init_update "*" 0 + proto_send_update "$interface" +} +[ -n "$INCLUDE_ONLY" ] || { + add_protocol ncm +} diff --git a/package/network/utils/comgt/files/runcommand.gcom b/package/network/utils/comgt/files/runcommand.gcom new file mode 100644 index 0000000..e99b6f9 --- /dev/null +++ b/package/network/utils/comgt/files/runcommand.gcom @@ -0,0 +1,31 @@ +# run AT-command from environment +opengt + set com 115200n81 + set senddelay 0.02 + waitquiet 1 0.2 + flash 0.1 + +:start + print "sending -> ",$env("COMMAND"),"\n" + send $env("COMMAND") + send "^m" + + waitfor 15 "OK","ERR","ERROR","COMMAND NOT SUPPORT" + if % = 0 goto continue + if % = 1 goto error + if % = 2 goto error + if % = 3 goto notsupported + + print "Timeout running AT-command\n" + exit 1 + +:error + print "Error running AT-command\n" + exit 1 + +:notsupported + print "AT-command not supported\n" + exit 1 + +:continue + exit 0 diff --git a/package/network/utils/comgt/files/setmode.gcom b/package/network/utils/comgt/files/setmode.gcom new file mode 100644 index 0000000..4ce0b5f --- /dev/null +++ b/package/network/utils/comgt/files/setmode.gcom @@ -0,0 +1,26 @@ +# set wwan mode from environment +opengt + set com 115200n81 + set senddelay 0.02 + waitquiet 1 0.2 + flash 0.1 + +:start + print "Trying to set mode\n" + send $env("MODE") + send "^m" + + waitfor 15 "OK","ERR","ERROR" + if % = 0 goto continue + if % = 1 goto modeerror + if % = 2 goto modeerror + + print "Timeout setting WWAN mode!\n" + exit 1 + +:modeerror + print "Error setting WWAN mode!\n" + exit 1 + +:continue + exit 0 diff --git a/package/network/utils/comgt/files/setpin.gcom b/package/network/utils/comgt/files/setpin.gcom new file mode 100644 index 0000000..66350fe --- /dev/null +++ b/package/network/utils/comgt/files/setpin.gcom @@ -0,0 +1,55 @@ +# set pin code from evnironment "$PINCODE" +opengt + set com 115200n81 + set senddelay 0.05 + waitquiet 3 0.5 + flash 0.1 + + let c=0 +:start + send "AT+CPIN?^m" + waitfor 15 "SIM PUK","SIM PIN","READY","ERROR","ERR" + if % = -1 goto timeout + if % = 0 goto ready + if % = 1 goto setpin + if % = 2 goto ready + if % = 3 goto checkrepeat + if % = 4 goto checkrepeat + +:checkrepeat + inc c + if c>3 goto pinerror + waitquiet 12 0.5 + goto start + +:timeout + print "timeout checking for PIN." + exit 1 + +:ready + print "SIM ready\n" + goto continue + exit 0 + +:setpin + # check if output was "SIM PIN2", that's ok. + waitfor 1 "2" + if % = 0 goto ready + + print "Trying to set PIN\n" + send "AT+CPIN=\"" + send $env("PINCODE") + send "\"^m" + + waitfor 20 "OK","ERR" + if % = -1 goto pinerror + if % = 0 goto continue + if % = 1 goto pinerror + +:pinerror + print "Error setting PIN, check card manually\n" + exit 1 + +:continue + print "PIN set successfully\n" + exit 0 -- cgit v1.2.3