[OpenWrt-Devel] [PATCH] comgt: add hso support
Cezary Jackiewicz
cezary.jackiewicz at gmail.com
Sun Feb 22 04:19:31 EST 2015
Add HSO support to comgt. This is work of Kyklas (see
https://dev.openwrt.org/ticket/6995), tested with Option GTM382.
Signed-off-by: Cezary Jackiewicz <cezary.jackiewicz at gmail.com>
---
diff --git a/package/network/utils/comgt/Makefile b/package/network/utils/comgt/Makefile
index 8fcf54e..1e12b68 100644
--- a/package/network/utils/comgt/Makefile
+++ b/package/network/utils/comgt/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=comgt
PKG_VERSION:=0.32
-PKG_RELEASE:=25
+PKG_RELEASE:=26
PKG_SOURCE:=$(PKG_NAME).$(PKG_VERSION).tgz
PKG_SOURCE_URL:=@SF/comgt
@@ -47,6 +47,12 @@ $(call Package/comgt/Default)
DEPENDS:=+comgt
endef
+define Package/comgt-hso
+$(call Package/comgt/Default)
+ TITLE+=HSO Support
+ DEPENDS:=+comgt +kmod-usb-net +kmod-usb-net-hso
+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
@@ -101,6 +107,17 @@ define Package/comgt-ncm/install
$(INSTALL_BIN) ./files/ncm.sh $(1)/lib/netifd/proto/ncm.sh
endef
+define Package/comgt-hso/install
+ $(INSTALL_DIR) $(1)/etc/chatscripts
+ $(INSTALL_DATA) ./files/hso.chat $(1)/etc/chatscripts/hso.chat
+ $(INSTALL_DATA) ./files/hsohup.chat $(1)/etc/chatscripts/hsohup.chat
+ $(INSTALL_DIR) $(1)/etc/gcom
+ $(INSTALL_DATA) ./files/setuser.gcom $(1)/etc/gcom/setuser.gcom
+ $(INSTALL_DIR) $(1)/lib/netifd/proto
+ $(INSTALL_BIN) ./files/hso.sh $(1)/lib/netifd/proto/hso.sh
+endef
+
$(eval $(call BuildPackage,comgt))
$(eval $(call BuildPackage,comgt-directip))
$(eval $(call BuildPackage,comgt-ncm))
+$(eval $(call BuildPackage,comgt-hso))
diff --git a/package/network/utils/comgt/files/hso.chat b/package/network/utils/comgt/files/hso.chat
new file mode 100644
index 0000000..cb87d5a
--- /dev/null
+++ b/package/network/utils/comgt/files/hso.chat
@@ -0,0 +1,13 @@
+ABORT BUSY
+ABORT 'NO CARRIER'
+ABORT ERROR
+REPORT CONNECT
+TIMEOUT 10
+"" "ATZ"
+OK 'AT+CGDCONT=2,"IP","$USE_APN"'
+SAY "Service Mode $MODE"
+TIMEOUT 30
+OK "AT_OPSYS=$MODE,2"
+OK "AT_OWANCALL=2,1,0"
+OK "\d\d\d\d\d\dAT_OWANDATA=2"
+OK ""
diff --git a/package/network/utils/comgt/files/hso.sh b/package/network/utils/comgt/files/hso.sh
new file mode 100644
index 0000000..5f10420
--- /dev/null
+++ b/package/network/utils/comgt/files/hso.sh
@@ -0,0 +1,135 @@
+#!/bin/sh
+INCLUDE_ONLY=1
+
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_hso_init_config() {
+
+ no_device=1
+ available=1
+
+ proto_config_add_string "device"
+ proto_config_add_string "maxwait"
+ proto_config_add_string "apn"
+ proto_config_add_string "pincode"
+ proto_config_add_int "mtu"
+ proto_config_add_string "username"
+ proto_config_add_string "password"
+ proto_config_add_string "ifname"
+}
+
+
+proto_hso_setup() {
+
+ local iface="$1"
+ local chat="/etc/chatscripts/hso.chat"
+
+ json_get_var device device
+ json_get_var maxwait maxwait
+ maxwait=${maxwait:-20}
+ while [ ! -e "$device" -a $maxwait -gt 0 ];do # wait for driver loading to catch up
+ maxwait=$(($maxwait - 1))
+ sleep 1
+ done
+
+ json_get_var apn apn
+ json_get_var pincode pincode
+ json_get_var mtu mtu
+ json_get_var service service
+ json_get_var username username
+ json_get_var password password
+ json_get_type ifnametype ifname
+
+ if [ "$ifnametype" = "array" ]
+ then
+ json_select ifname
+ json_get_var ifname 1
+ json_select ".."
+ fi
+
+ if [ "$ifnametype" = "string" ]
+ then
+ json_get_var ifname ifname
+ fi
+
+ # set pin if configured
+ if [ ! -z "$pincode" ]
+ then
+ PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
+ echo "$iface (hso): Failed to set the PIN code."
+ proto_notify_error "$iface" PIN_FAILED
+ return 1
+ }
+ fi
+
+ # set username and password if configured
+ if [ -n "$username" -a -n "$password" ]
+ then
+ USER="$username" PASS="$password" gcom -d "$device" -s /etc/gcom/setuser.gcom || {
+ echo "$iface (hso): Failed to set username and password."
+ proto_notify_error "$iface" AUTH_FAILED
+ return 1
+ }
+ fi
+
+ case "$service" in
+ umts_only) service_mode=1;;
+ gprs_only) service_mode=0;;
+ *) service_mode=3;;
+ esac
+
+ local pip counter
+ local outputfile="/tmp/hsoout.$$"
+ while [ -z "$pip" -a "$counter" != "---------------" ]
+ do
+ sleep 2
+ rm -f $outputfile
+ ( USE_APN=$apn MODE=$service_mode /usr/sbin/chat -E -v -V -f $chat <$device > $device ) 2> $outputfile
+ iserror=`grep '^ERROR' $outputfile`
+ if [ -z "$iserror" ]
+ then
+ pip="`grep '^_OWANDATA' $outputfile | cut -d, -f2`"
+ gw="`grep '^_OWANDATA' $outputfile | cut -d, -f3`"
+ ns1="`grep '^_OWANDATA' $outputfile | cut -d, -f4`"
+ ns2="`grep '^_OWANDATA' $outputfile | cut -d, -f5`"
+ fi
+
+ counter="${counter}-"
+ done
+
+ rm -f $outputfile
+
+ if [ -z $pip ]
+ then
+ echo "$iface (hso): Failed to connect and obtain IP address."
+ return 1
+ fi
+
+ proto_init_update $ifname 1
+ proto_set_keep 1
+ proto_add_ipv4_address "$pip" 32
+ proto_add_dns_server "$ns1"
+ proto_add_dns_server "$ns2"
+ proto_add_ipv4_route "0.0.0.0" 0 $gw
+ proto_add_data
+ json_add_string "ppp-type" "hso"
+ proto_close_data
+ proto_send_update "$iface"
+
+ touch /var/run/$ifname.pid
+}
+
+
+proto_hso_teardown() {
+
+ local config="$1"
+ local chat="/etc/chatscripts/hsohup.chat"
+
+ json_get_var device device
+ /usr/sbin/chat -v -f $chat <$device > $device
+
+ killall gcom >/dev/null 2>/dev/null
+}
+
+add_protocol hso
diff --git a/package/network/utils/comgt/files/hsohup.chat b/package/network/utils/comgt/files/hsohup.chat
new file mode 100644
index 0000000..9e82183
--- /dev/null
+++ b/package/network/utils/comgt/files/hsohup.chat
@@ -0,0 +1,8 @@
+ABORT BUSY
+ABORT 'NO CARRIER'
+ABORT ERROR
+REPORT CONNECT
+SAY "Hanging up..."
+TIMEOUT 30
+"" "AT_OWANCALL=2,0"
+OK ""
diff --git a/package/network/utils/comgt/files/setuser.gcom b/package/network/utils/comgt/files/setuser.gcom
new file mode 100644
index 0000000..511d90b
--- /dev/null
+++ b/package/network/utils/comgt/files/setuser.gcom
@@ -0,0 +1,29 @@
+# set username and password
+opengt
+ set com 115200n81
+ set senddelay 0.02
+ waitquiet 1 0.2
+ flash 0.1
+
+:start
+ print "Trying to set username and password\n"
+ send "AT$QCPDPP=1,1,"
+ send $env("USER")
+ send ","
+ send $env("PASS")
+ send "^m"
+
+ waitfor 15 "OK","ERR","ERROR"
+ if % = 0 goto continue
+ if % = 1 goto modeerror
+ if % = 2 goto modeerror
+
+ print "Timeout setting username and password!\n"
+ exit 1
+
+:modeerror
+ print "Error setting username and password!\n"
+ exit 1
+
+:continue
+ exit 0
--
Pozdrawiam,
Cezary Jackiewicz
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list