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/Makefile | 103 +++++++++++ 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 ++++++ .../utils/comgt/patches/001-compile_fix.patch | 23 +++ .../network/utils/comgt/patches/002-termios.patch | 105 +++++++++++ .../network/utils/comgt/patches/003-no_XCASE.patch | 20 +++ .../utils/comgt/patches/004-check_tty.patch | 68 ++++++++ 22 files changed, 1129 insertions(+) create mode 100644 package/network/utils/comgt/Makefile 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 create mode 100644 package/network/utils/comgt/patches/001-compile_fix.patch create mode 100644 package/network/utils/comgt/patches/002-termios.patch create mode 100644 package/network/utils/comgt/patches/003-no_XCASE.patch create mode 100644 package/network/utils/comgt/patches/004-check_tty.patch (limited to 'package/network/utils/comgt') diff --git a/package/network/utils/comgt/Makefile b/package/network/utils/comgt/Makefile new file mode 100644 index 0000000..ac19aad --- /dev/null +++ b/package/network/utils/comgt/Makefile @@ -0,0 +1,103 @@ +# +# Copyright (C) 2006-2014 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=comgt +PKG_VERSION:=0.32 +PKG_RELEASE:=27 + +PKG_SOURCE:=$(PKG_NAME).$(PKG_VERSION).tgz +PKG_SOURCE_URL:=@SF/comgt +PKG_MD5SUM:=db2452680c3d953631299e331daf49ef + +PKG_MAINTAINER:=Felix Fietkau +PKG_LICENSE:=GPL-2.0+ + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME).$(PKG_VERSION) +PKG_CHECK_FORMAT_SECURITY:=0 + +include $(INCLUDE_DIR)/package.mk + +define Package/comgt/Default + SECTION:=utils + CATEGORY:=Utilities +endef + +define Package/comgt +$(call Package/comgt/Default) + TITLE:=Option/Vodafone 3G/GPRS control tool + DEPENDS:=+chat + URL:=http://www.pharscape.org/comgt.html +endef + +define Package/comgt-directip +$(call Package/comgt/Default) + TITLE:=Sierra Wireless Direct-IP support + DEPENDS:=+comgt +kmod-usb-serial +kmod-usb-serial-sierrawireless +kmod-usb-net +kmod-usb-net-sierrawireless +endef + +define Package/comgt-ncm +$(call Package/comgt/Default) + TITLE+=NCM 3G/4G Support + DEPENDS:=+comgt +wwan +endef + +define Package/comgt/description + comgt is a scripting language interpreter useful for establishing + communications on serial lines and through PCMCIA modems as well as GPRS + and 3G datacards. +endef + +define Build/Compile + $(MAKE) -C $(PKG_BUILD_DIR) \ + $(TARGET_CONFIGURE_OPTS) \ + CFLAGS="$(TARGET_CFLAGS)" \ + LDFLAGS="" \ + comgt +endef + +define Package/comgt/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/comgt $(1)/usr/bin/ + $(LN) comgt $(1)/usr/bin/gcom + $(INSTALL_DIR) $(1)/etc/chatscripts + $(INSTALL_DATA) ./files/3g.chat $(1)/etc/chatscripts/3g.chat + $(INSTALL_DATA) ./files/evdo.chat $(1)/etc/chatscripts/evdo.chat + $(INSTALL_DIR) $(1)/etc/gcom + $(INSTALL_DATA) ./files/setpin.gcom $(1)/etc/gcom/setpin.gcom + $(INSTALL_DATA) ./files/setmode.gcom $(1)/etc/gcom/setmode.gcom + $(INSTALL_DATA) ./files/getcardinfo.gcom $(1)/etc/gcom/getcardinfo.gcom + $(INSTALL_DATA) ./files/getstrength.gcom $(1)/etc/gcom/getstrength.gcom + $(INSTALL_DATA) ./files/getcarrier.gcom $(1)/etc/gcom/getcarrier.gcom + $(INSTALL_DATA) ./files/getcnum.gcom $(1)/etc/gcom/getcnum.gcom + $(INSTALL_DATA) ./files/getimsi.gcom $(1)/etc/gcom/getimsi.gcom + $(INSTALL_DIR) $(1)/etc/hotplug.d/tty + $(INSTALL_DATA) ./files/3g.usb $(1)/etc/hotplug.d/tty/30-3g + $(INSTALL_DIR) $(1)/lib/netifd/proto + $(INSTALL_BIN) ./files/3g.sh $(1)/lib/netifd/proto/3g.sh +endef + +define Package/comgt-directip/install + $(INSTALL_DIR) $(1)/etc/gcom + $(INSTALL_DATA) ./files/directip.gcom $(1)/etc/gcom/directip.gcom + $(INSTALL_DATA) ./files/directip-stop.gcom $(1)/etc/gcom/directip-stop.gcom + $(INSTALL_DIR) $(1)/lib/netifd/proto + $(INSTALL_BIN) ./files/directip.sh $(1)/lib/netifd/proto/directip.sh +endef + +define Package/comgt-ncm/install + $(INSTALL_DIR) $(1)/etc/gcom + $(INSTALL_DATA) ./files/ncm.json $(1)/etc/gcom/ncm.json + $(INSTALL_DATA) ./files/runcommand.gcom $(1)/etc/gcom/runcommand.gcom + $(INSTALL_DIR) $(1)/lib/netifd/proto + $(INSTALL_BIN) ./files/ncm.sh $(1)/lib/netifd/proto/ncm.sh +endef + +$(eval $(call BuildPackage,comgt)) +$(eval $(call BuildPackage,comgt-directip)) +$(eval $(call BuildPackage,comgt-ncm)) 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 diff --git a/package/network/utils/comgt/patches/001-compile_fix.patch b/package/network/utils/comgt/patches/001-compile_fix.patch new file mode 100644 index 0000000..15de850 --- /dev/null +++ b/package/network/utils/comgt/patches/001-compile_fix.patch @@ -0,0 +1,23 @@ +--- a/Makefile ++++ b/Makefile +@@ -32,6 +32,7 @@ SCRIPTPATH = /etc/comgt/ + SCRIPTSRC = ./scripts/ + BIN = $(CPROG) + MANP = comgt.1 sigmon.1 ++CC = cc + + CFLAGS = -c + LDFLAGS = +@@ -70,10 +71,5 @@ clean: + -rm *~ + -rm $(SCRIPTSRC)*~ + +- +-comgt: comgt.o +- cc comgt.o $(LDFLAGS) -o comgt +- +-comgt.o: comgt.c comgt.h +- cc comgt.c $(CFLAGS) +- ++comgt: comgt.c comgt.h ++ $(CC) $(CFLAGS) -o comgt $< $(LDFLAGS) diff --git a/package/network/utils/comgt/patches/002-termios.patch b/package/network/utils/comgt/patches/002-termios.patch new file mode 100644 index 0000000..08f22d1 --- /dev/null +++ b/package/network/utils/comgt/patches/002-termios.patch @@ -0,0 +1,105 @@ +--- a/comgt.c ++++ b/comgt.c +@@ -30,7 +30,7 @@ + #include + #include + #include +-#include ++#include + #include + #include + #include +@@ -81,7 +81,7 @@ char token[MAXTOKEN]; /* For gettoken( + char scriptfile[MAXPATH]; /* Script file name */ + char scriptfilepath[MAXPATH]; /* temp storage for full path */ + BOOL verbose=0; /* Log actions */ +-struct termio cons, stbuf, svbuf; /* termios: svbuf=before, stbuf=while */ ++struct termios cons, stbuf, svbuf; /* termios: svbuf=before, stbuf=while */ + int comfd=0; /* Communication file descriptor. Defaults to stdin. */ + char msg[STRINGL]; /* Massage messages here */ + int preturn,returns[MAXGOSUBS]; +@@ -172,7 +172,7 @@ void dotestkey(void) { + + /* Exit after resetting terminal settings */ + void ext(long xtc) { +- ioctl(1, TCSETA, &cons); ++ ioctl(1, TCSETS, &cons); + exit(xtc); + } + +@@ -920,24 +920,24 @@ BOOL getonoroff(void) { + void setcom(void) { + stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB); + stbuf.c_cflag |= (speed | bits | CREAD | clocal | parity | stopbits ); +- if (ioctl(comfd, TCSETA, &stbuf) < 0) { ++ if (ioctl(comfd, TCSETS, &stbuf) < 0) { + serror("Can't ioctl set device",1); + } + } + + void doset(void) { +- struct termio console; ++ struct termios console; + int a,b; + gettoken(); + if(strcmp(token,"echo")==0) { + a=0; + if(getonoroff()) a=ECHO|ECHOE; +- if(ioctl(0, TCGETA, &console)<0) { ++ if(ioctl(0, TCGETS, &console)<0) { + serror("Can't ioctl FD zero!\n",2); + } + console.c_lflag &= ~(ECHO | ECHOE); + console.c_lflag |= a; +- ioctl(0, TCSETA, &console); ++ ioctl(0, TCSETS, &console); + } + else if(strcmp(token,"senddelay")==0) { + senddelay=10000L*getdvalue(); +@@ -1224,7 +1224,7 @@ void doclose(void) { + if(strcmp(token,"hardcom")==0) { + if(comfd== -1) serror("Com device not open",1); + vmsg("Closing device"); +- if (ioctl(comfd, TCSETA, &svbuf) < 0) { ++ if (ioctl(comfd, TCSETS, &svbuf) < 0) { + sprintf(msg,"Can't ioctl set device %s.\n",device); + serror(msg,1); + } +@@ -1266,12 +1266,12 @@ void opengt(void) { + ext(1); + } + } +- if (ioctl (comfd, TCGETA, &svbuf) < 0) { ++ if (ioctl (comfd, TCGETS, &svbuf) < 0) { + sprintf(msg,"Can't control %s, please try again.\n",device); + serror(msg,1); + } + setenv("COMGTDEVICE",device,1); +- ioctl(comfd, TCGETA, &stbuf); ++ ioctl(comfd, TCGETS, &stbuf); + speed=stbuf.c_cflag & CBAUD; + if (high_speed == 0) strcpy(cspeed,"115200"); + else strcpy(cspeed,"57600"); +@@ -1303,11 +1303,11 @@ void opendevice(void) { + } + else comfd=0; + +- if (ioctl (comfd, TCGETA, &svbuf) < 0) { ++ if (ioctl (comfd, TCGETS, &svbuf) < 0) { + sprintf(msg,"Can't ioctl get device %s.\n",device); + serror(msg,1); + } +- ioctl(comfd, TCGETA, &stbuf); ++ ioctl(comfd, TCGETS, &stbuf); + speed=stbuf.c_cflag & CBAUD; + switch(speed) { + case B0: strcpy(cspeed,"0");break; +@@ -1553,7 +1553,7 @@ int main(int argc,char **argv) { + skip_default=0; + filep=NULL; + scriptspace=4096; +- ioctl(1, TCGETA, &cons); ++ ioctl(1, TCGETS, &cons); + if((script=( char *)malloc(scriptspace))==NULL) { + serror("Could not malloc()",3); + } diff --git a/package/network/utils/comgt/patches/003-no_XCASE.patch b/package/network/utils/comgt/patches/003-no_XCASE.patch new file mode 100644 index 0000000..f2060a8 --- /dev/null +++ b/package/network/utils/comgt/patches/003-no_XCASE.patch @@ -0,0 +1,20 @@ +--- a/comgt.c ++++ b/comgt.c +@@ -1281,7 +1281,7 @@ void opengt(void) { + parity=stbuf.c_cflag & (PARENB | PARODD); + stbuf.c_iflag &= ~(IGNCR | ICRNL | IUCLC | INPCK | IXON | IXANY | IGNPAR ); + stbuf.c_oflag &= ~(OPOST | OLCUC | OCRNL | ONLCR | ONLRET); +- stbuf.c_lflag &= ~(ICANON | XCASE | ECHO | ECHOE | ECHONL); ++ stbuf.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHONL); + stbuf.c_lflag &= ~(ECHO | ECHOE); + stbuf.c_cc[VMIN] = 1; + stbuf.c_cc[VTIME] = 0; +@@ -1336,7 +1336,7 @@ void opendevice(void) { + parity=stbuf.c_cflag & (PARENB | PARODD); + stbuf.c_iflag &= ~(IGNCR | ICRNL | IUCLC | INPCK | IXON | IXANY | IGNPAR ); + stbuf.c_oflag &= ~(OPOST | OLCUC | OCRNL | ONLCR | ONLRET); +- stbuf.c_lflag &= ~(ICANON | XCASE | ECHO | ECHOE | ECHONL); ++ stbuf.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHONL); + stbuf.c_lflag &= ~(ECHO | ECHOE); + stbuf.c_cc[VMIN] = 1; + stbuf.c_cc[VTIME] = 0; diff --git a/package/network/utils/comgt/patches/004-check_tty.patch b/package/network/utils/comgt/patches/004-check_tty.patch new file mode 100644 index 0000000..fb1d9af --- /dev/null +++ b/package/network/utils/comgt/patches/004-check_tty.patch @@ -0,0 +1,68 @@ +--- a/comgt.c ++++ b/comgt.c +@@ -91,6 +91,7 @@ unsigned long hstart,hset; + char NullString[]={ "" }; + BOOL lastcharnl=1; /* Indicate that last char printed from getonebyte + was a nl, so no new one is needed */ ++BOOL tty=1; + + + //"open com \"/dev/modem\"\nset com 38400n81\nset senddelay 0.05\nsend \"ATi^m\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response :\",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\n\n"; +@@ -920,7 +921,7 @@ BOOL getonoroff(void) { + void setcom(void) { + stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB); + stbuf.c_cflag |= (speed | bits | CREAD | clocal | parity | stopbits ); +- if (ioctl(comfd, TCSETS, &stbuf) < 0) { ++ if (tty && ioctl(comfd, TCSETS, &stbuf) < 0) { + serror("Can't ioctl set device",1); + } + } +@@ -1224,7 +1225,7 @@ void doclose(void) { + if(strcmp(token,"hardcom")==0) { + if(comfd== -1) serror("Com device not open",1); + vmsg("Closing device"); +- if (ioctl(comfd, TCSETS, &svbuf) < 0) { ++ if (tty && ioctl(comfd, TCSETS, &svbuf) < 0) { + sprintf(msg,"Can't ioctl set device %s.\n",device); + serror(msg,1); + } +@@ -1266,12 +1267,17 @@ void opengt(void) { + ext(1); + } + } +- if (ioctl (comfd, TCGETS, &svbuf) < 0) { ++ if (isatty (comfd)) ++ tty=1; ++ else ++ tty=0; ++ if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) { + sprintf(msg,"Can't control %s, please try again.\n",device); + serror(msg,1); + } + setenv("COMGTDEVICE",device,1); +- ioctl(comfd, TCGETS, &stbuf); ++ if (tty) ++ ioctl(comfd, TCGETS, &stbuf); + speed=stbuf.c_cflag & CBAUD; + if (high_speed == 0) strcpy(cspeed,"115200"); + else strcpy(cspeed,"57600"); +@@ -1302,12 +1308,16 @@ void opendevice(void) { + } + } + else comfd=0; +- +- if (ioctl (comfd, TCGETS, &svbuf) < 0) { ++ if (isatty (comfd)) ++ tty=1; ++ else ++ tty=0; ++ if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) { + sprintf(msg,"Can't ioctl get device %s.\n",device); + serror(msg,1); + } +- ioctl(comfd, TCGETS, &stbuf); ++ if (tty) ++ ioctl(comfd, TCGETS, &stbuf); + speed=stbuf.c_cflag & CBAUD; + switch(speed) { + case B0: strcpy(cspeed,"0");break; -- cgit v1.2.3