comgt-ncm: Add support for specifying profile index
authorMatti Laakso <malaakso@elisanet.fi>
Sun, 11 Dec 2016 15:28:52 +0000 (17:28 +0200)
committerJohn Crispin <john@phrozen.org>
Wed, 14 Dec 2016 09:37:01 +0000 (10:37 +0100)
Add support for specifying a call profile index instead of APN. A
specific index different from 1 must be used for some service
provider and modem combinations.

In addition, change the manufacturer detection to use the standard
AT+CGMI command, which produces more predictable output than ATI,
remove the redundant ipv6 option, since it is less ambiguous to
directly specify the PDP context type with mobile connections, and
fix missing device during teardown when using ncm through the wwan
proto.

Signed-off-by: Matti Laakso <malaakso@elisanet.fi>
package/network/utils/comgt/Makefile
package/network/utils/comgt/files/getcardinfo.gcom
package/network/utils/comgt/files/ncm.json
package/network/utils/comgt/files/ncm.sh

index 9d99d640bcff4292230110e8b1d2674b03236215..4b6e6eaf82b45152bfd1d9340c1782ad55dff288 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=comgt
 PKG_VERSION:=0.32
-PKG_RELEASE:=27
+PKG_RELEASE:=28
 
 PKG_SOURCE:=$(PKG_NAME).$(PKG_VERSION).tgz
 PKG_SOURCE_URL:=@SF/comgt
index 5c69a64604ecaf4baaf286a31aeb6d0057b5be49..f91665f72eaa38c008c6a6f4bee1d84d47265f75 100644 (file)
@@ -6,7 +6,7 @@ opengt
  flash 0.1
 
 :start
- send "ATI^m"
+ send "AT+CGMI^m"
  get 1 "" $s
  print $s
 
index d1f869974a5c485e0b398041e7c864853aee5518..8f74e173d14edc9cfb9a01972ec6b89e6145fb74 100644 (file)
@@ -7,7 +7,7 @@
                        "ATV1",
                        "ATE1",
                        "ATS0=0",
-                       "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\""
+                       "AT+CGDCONT=${profile},\\\"${pdptype}\\\"${apn:+,\\\"$apn\\\"}"
                ],
                "modes": {
                        "preferlte": "AT^SYSCFGEX=\\\"030201\\\",3fffffff,2,4,7fffffffffffffff,,",
@@ -17,8 +17,8 @@
                        "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"
+               "connect": "AT^NDISDUP=${profile},1${apn:+,\\\"$apn\\\"}${username:+,\\\"$username\\\"}${password:+,\\\"$password\\\"}${auth:+,$auth}",
+               "disconnect": "AT^NDISDUP=${profile},0"
        },
        "samsung": {
                "initialize": [
@@ -26,7 +26,7 @@
                        "AT+CGREG=2",
                        "AT+CFUN=5",
                        "AT+MODESELECT=3",
-                       "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\""
+                       "AT+CGDCONT=${profile},\\\"${pdptype}\\\"${apn:+,\\\"$apn\\\"}"
                ],
                "modes": {
                        "umts": "AT+CHANGEALLPATH=1"
                "connect": "AT+CGATT=1",
                "disconnect": "AT+CGATT=0"
        },
-       "sierra wireless, incorporated": {
+       "sierra": {
                "initialize": [
                        "AT+CFUN=1",
-                       "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\"",
-                       "AT$QCPDPP=1${auth:+,$auth}${password:+,\\\"$password\\\"}${username:+,\\\"$username\\\"}"
+                       "AT+CGDCONT=${profile},\\\"${pdptype}\\\"${apn:+,\\\"$apn\\\"}",
+                       "AT$QCPDPP=${profile},${auth:-0}${password:+,\\\"$password\\\"}${username:+,\\\"$username\\\"}"
                ],
                "modes": {
                        "preferlte": "AT!SELRAT=07",
                        "gsm": "AT!SELRAT=02",
                        "auto": "AT!SELRAT=00"
                },
-               "connect": "AT!SCACT=1,1",
-               "disconnect": "AT!SCACT=0,1"
+               "connect": "AT!SCACT=1,${profile}",
+               "disconnect": "AT!SCACT=0,${profile}"
        },
-       "sony ericsson": {
+       "sony": {
                "initialize": [
                        "AT+CFUN=1",
-                       "AT+CGDCONT=1,\\\"${pdptype}\\\",\\\"${apn}\\\"",
-                       "AT*EIAAUW=1,1,\\\"${username}\\\",\\\"${password}\\\",${auth:-00111}"
+                       "AT+CGDCONT=${profile},\\\"${pdptype}\\\"${apn:+,\\\"$apn\\\"}",
+                       "AT*EIAAUW=${profile},1,\\\"${username}\\\",\\\"${password}\\\",${auth:-00111}"
                ],
                "modes": {
                        "umts": "AT+CFUN=6",
                        "gsm": "AT+CFUN=5"
                },
-               "connect": "AT*ENAP=1,1",
+               "connect": "AT*ENAP=1,${profile}",
                "disconnect": "AT*ENAP=0"
        }
 }
index 14b6347d3fa29a7270dcfb8501b6d6188b25f308..09c2c18b401c1b779386999e59550be813a4eefe 100644 (file)
@@ -18,7 +18,7 @@ proto_ncm_init_config() {
        proto_config_add_string delay
        proto_config_add_string mode
        proto_config_add_string pdptype
-       proto_config_add_boolean ipv6
+       proto_config_add_int profile
        proto_config_add_defaults
 }
 
@@ -27,22 +27,15 @@ proto_ncm_setup() {
 
        local manufacturer initialize setmode connect ifname devname devpath
 
-       local device apn auth username password pincode delay mode pdptype ipv6 $PROTO_DEFAULT_OPTIONS
-       json_get_vars device apn auth username password pincode delay mode pdptype ipv6 $PROTO_DEFAULT_OPTIONS
-       
-       if [ "$ipv6" = 0 ]; then
-               ipv6=""
-       else
-               ipv6=1
-       fi
-       
-       [ -z "$pdptype" ] && {
-               if [ -n "$ipv6" ]; then
-                       pdptype="IPV4V6"
-               else
-                       pdptype="IP"
-               fi
-       }
+       local device apn auth username password pincode delay mode pdptype profile $PROTO_DEFAULT_OPTIONS
+       json_get_vars device apn auth username password pincode delay mode pdptype profile $PROTO_DEFAULT_OPTIONS
+
+       [ "$metric" = "" ] && metric="0"
+
+       [ -n "$profile" ] || profile=1
+
+       pdptype=`echo "$pdptype" | awk '{print toupper($0)}'`
+       [ "$pdptype" = "IP" -o "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] || $pdptype="IP"
 
        [ -n "$ctl_device" ] && device=$ctl_device
 
@@ -57,11 +50,6 @@ proto_ncm_setup() {
                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
@@ -83,7 +71,7 @@ proto_ncm_setup() {
 
        [ -n "$delay" ] && sleep "$delay"
 
-       manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print tolower($2) }'`
+       manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }'`
        [ $? -ne 0 ] && {
                echo "Failed to get modem information"
                proto_notify_error "$interface" GETINFO_FAILED
@@ -126,6 +114,7 @@ proto_ncm_setup() {
                json_select ..
        }
 
+       echo "Starting network $interface"
        json_get_vars connect
        eval COMMAND="$connect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
                echo "Failed to connect"
@@ -133,19 +122,24 @@ proto_ncm_setup() {
                return 1
        }
 
-       echo "Connected, starting DHCP on $ifname"
+       echo "Setting up $ifname"
        
        proto_init_update "$ifname" 1
+       proto_add_data
+       json_add_string "manufacturer" "$manufacturer"
+       proto_close_data
        proto_send_update "$interface"
 
-       json_init
-       json_add_string name "${interface}_4"
-       json_add_string ifname "@$interface"
-       json_add_string proto "dhcp"
-       proto_add_dynamic_defaults
-       ubus call network add_dynamic "$(json_dump)"
+       [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
+               json_init
+               json_add_string name "${interface}_4"
+               json_add_string ifname "@$interface"
+               json_add_string proto "dhcp"
+               proto_add_dynamic_defaults
+               ubus call network add_dynamic "$(json_dump)"
+       }
 
-       [ -n "$ipv6" ] && {
+       [ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
                json_init
                json_add_string name "${interface}_6"
                json_add_string ifname "@$interface"
@@ -161,17 +155,18 @@ proto_ncm_teardown() {
 
        local manufacturer disconnect
 
-       local device
-       json_get_vars device
+       local device profile
+       json_get_vars device profile
 
-       echo "Stopping network"
+       [ -n "$ctl_device" ] && device=$ctl_device
 
-       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
-       }
+       [ -n "$profile" ] || profile=1
+
+       echo "Stopping network $interface"
+
+       json_load "$(ubus call network.interface.$interface status)"
+       json_select data
+       json_get_vars manufacturer
 
        json_load "$(cat /etc/gcom/ncm.json)"
        json_select "$manufacturer" || {
@@ -181,7 +176,7 @@ proto_ncm_teardown() {
        }
 
        json_get_vars disconnect
-       COMMAND="$disconnect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
+       eval COMMAND="$disconnect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
                echo "Failed to disconnect"
                proto_notify_error "$interface" DISCONNECT_FAILED
                return 1