Hi,

        After applying Oskari 's NCM patches, I could get my E3276 work.
That's the log of using NCM protocol to set WAN connections.

Tue Apr  1 05:23:14 2014 daemon.notice netifd: Interface 'wan' is now down
Tue Apr  1 05:23:14 2014 daemon.notice netifd: Interface 'wan' is setting up
now
Tue Apr  1 05:23:16 2014 user.notice root: Detected huawei E3276. Using
driver huawei_e3276.
Tue Apr  1 05:23:17 2014 daemon.notice netifd: wan (4337): SIM ready
Tue Apr  1 05:23:17 2014 daemon.notice netifd: wan (4337): PIN set
successfully
Tue Apr  1 05:23:18 2014 daemon.notice netifd: wan (4337): Dongle
initialization complete.
Tue Apr  1 05:23:19 2014 daemon.notice netifd: wan (4337): WWAN mode set to
'prefer3g'
Tue Apr  1 05:23:21 2014 daemon.notice netifd: wan (4337): WWAN connection
established.
Tue Apr  1 05:23:26 2014 daemon.info dnsmasq-dhcp[4321]: DHCPINFORM(br-lan)
192.168.1.117 00:0a:f7:15:ed:19 
Tue Apr  1 05:23:26 2014 daemon.info dnsmasq-dhcp[4321]: DHCPACK(br-lan)
192.168.1.117 00:0a:f7:15:ed:19 DELL-PC
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.510000] IPv6:
ADDRCONF(NETDEV_UP): wwan0: link is not ready
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.520000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 daemon.notice netifd: Interface 'wan6' is enabled
Tue Apr  1 05:23:41 2014 daemon.notice netifd: Interface 'wan6' is setting
up now
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.530000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.530000] IPv6:
ADDRCONF(NETDEV_CHANGE): wwan0: link becomes ready
Tue Apr  1 05:23:41 2014 daemon.notice netifd: Interface 'wan' is now up
Tue Apr  1 05:23:41 2014 daemon.notice netifd: Network device 'wwan0' link
is up
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.550000] cdc_ncm: wwan0:
network connection: disconnected
Tue Apr  1 05:23:41 2014 kern.err kernel: [  387.550000] cdc_ncm 1-1.1:1.2
wwan0: kevent 11 may have been dropped
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.570000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.580000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.600000] cdc_ncm: wwan0:
network connection: disconnected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.610000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.620000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:41 2014 kern.err kernel: [  387.620000] cdc_ncm 1-1.1:1.2
wwan0: kevent 11 may have been dropped
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.650000] cdc_ncm: wwan0:
network connection: disconnected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.660000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.660000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.690000] cdc_ncm: wwan0:
network connection: disconnected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.700000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.700000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.730000] cdc_ncm: wwan0:
network connection: disconnected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.740000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.740000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:41 2014 daemon.notice netifd: wan (4507): udhcpc (v1.19.4)
started
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.770000] cdc_ncm: wwan0:
network connection: disconnected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.780000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.780000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.810000] cdc_ncm: wwan0:
network connection: disconnected
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.820000] cdc_ncm: wwan0:
236 kbit/s downlink 236 kbit/s uplink
Tue Apr  1 05:23:41 2014 kern.info kernel: [  387.820000] cdc_ncm: wwan0:
network connection: connected
Tue Apr  1 05:23:42 2014 daemon.notice netifd: Interface 'wan' has lost the
connection
Tue Apr  1 05:23:42 2014 daemon.notice netifd: wan (4507): Sending
discover...
Tue Apr  1 05:23:42 2014 daemon.notice netifd: wan (4507): Sending select
for 10.66.194.164...
Tue Apr  1 05:23:42 2014 daemon.notice netifd: wan (4507): Lease of
10.66.194.164 obtained, lease time 518400
Tue Apr  1 05:23:42 2014 daemon.notice odhcp6c[4524]: (re)starting
transaction on wwan0
Tue Apr  1 05:23:42 2014 daemon.notice odhcp6c[4524]: Starting SOLICIT
transaction (timeout 4294967295s, max rc 0)
Tue Apr  1 05:23:42 2014 user.notice firewall: Reloading firewall due to
ifup of wan (wwan0)
Tue Apr  1 05:23:42 2014 daemon.notice netifd: Interface 'wan' is now up
Tue Apr  1 05:23:43 2014 daemon.notice netifd: Interface 'wan6' is now down
Tue Apr  1 05:23:43 2014 daemon.notice netifd: Interface 'wan6' is disabled
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4321]: exiting on receipt of
SIGTERM
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: started, version 2.66
cachesize 150
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: compile time options:
IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP
no-conntrack no-ipset no-auth
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq-dhcp[4730]: DHCP, IP range 192.
168.1.100 -- 192.168.1.249, lease time 12h
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: using local addresses
only for domain lan
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: reading
/tmp/resolv.conf.auto
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: using nameserver
112.4.1.36#53
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: using nameserver
112.4.12.200#53
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: using local addresses
only for domain lan
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: read /etc/hosts - 1
addresses
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq[4730]: read /tmp/hosts/odhcpd -
1 addresses
Tue Apr  1 05:23:43 2014 daemon.info dnsmasq-dhcp[4730]: read /etc/ethers -
0 addresses

Now wwan0 is UP:

wwan0     Link encap:Ethernet  HWaddr 0C:5B:8F:27:9A:64  
          inet addr:10.66.194.164  Bcast:10.66.194.167  Mask:255.255.255.248
          inet6 addr: fe80::e5b:8fff:fe27:9a64/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2008 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2265 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:864560 (844.2 KiB)  TX bytes:8518278 (8.1 MiB)

I hope that patch could merged to Openwrt mainstream to support NCM
protocol.

Winton

-----邮件原件-----
发件人: openwrt-devel [mailto:[email protected]] 代表
Oskari Rauta
发送时间: 2014年3月21日 12:05
收件人: [email protected]
抄送: Oskari Rauta
主题: [OpenWrt-Devel] [PATCH] [packages] ncm: add packages for ncm protocol
support and driver/at-command set for huawei e3276 dongle

This patch adds 2 packages. A package for NCM protocol with modular support
for drivers/at-command sets. Second package adds support/driver/AT-command
set for Huawei E3276 dongle. This package can also easily be used as a base
when creating support for another dongles.

Signed-off-by: Oskari Rauta <oskari.rauta at gmail.com>
---
 net/ncm/Makefile                                   |  80 ++++++++++++
 .../files/etc/gcom/ncm/carrier/huawei_e3276.gcom   |  56 ++++++++
 .../files/etc/gcom/ncm/connect/huawei_e3276.gcom   |  63 +++++++++
 net/ncm/files/etc/gcom/ncm/getcardinfo.gcom        |  38 ++++++
 .../etc/gcom/ncm/initscripts/huawei_e3276.gcom     |  31 +++++
 .../files/etc/gcom/ncm/setmode/huawei_e3276.gcom   |  56 ++++++++
 .../files/etc/gcom/ncm/signal/huawei_e3276.gcom    |  61 +++++++++
 net/ncm/files/lib/netifd/ncm_dhcp.script           |  85 ++++++++++++
 net/ncm/files/lib/netifd/proto/ncm.sh              | 144
+++++++++++++++++++++
 9 files changed, 614 insertions(+)
 create mode 100644 net/ncm/Makefile
 create mode 100644 net/ncm/files/etc/gcom/ncm/carrier/huawei_e3276.gcom
 create mode 100644 net/ncm/files/etc/gcom/ncm/connect/huawei_e3276.gcom
 create mode 100644 net/ncm/files/etc/gcom/ncm/getcardinfo.gcom
 create mode 100644 net/ncm/files/etc/gcom/ncm/initscripts/huawei_e3276.gcom
 create mode 100644 net/ncm/files/etc/gcom/ncm/setmode/huawei_e3276.gcom
 create mode 100644 net/ncm/files/etc/gcom/ncm/signal/huawei_e3276.gcom
 create mode 100755 net/ncm/files/lib/netifd/ncm_dhcp.script
 create mode 100644 net/ncm/files/lib/netifd/proto/ncm.sh

diff --git a/net/ncm/Makefile b/net/ncm/Makefile new file mode 100644 index
0000000..13b4ca9
--- /dev/null
+++ b/net/ncm/Makefile
@@ -0,0 +1,80 @@
+#
+# Copyright (C) 2007-2013 OpenWrt.org
+# Copyright (C) 2010 Vertical Communications # # This is free software, 
+licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=ncm
+PKG_VERSION:=1.0.1
+PKG_RELEASE:=1
+PKG_MAINTAINER:=Oskari Rauta <oskari.rauta at gmail com>
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ncm
+  SECTION:=net
+  CATEGORY:=Network
+  TITLE:=Protocol support for NCM
+  DEPENDS:=+comgt +kmod-usb-net-cdc-ncm +kmod-usb-serial endef
+
+define Package/ncm/Description
+ This package contains protocol support for NCM.
+endef
+
+define Package/ncm-huawei-e3276
+  SECTION:=net
+  CATEGORY:=Network
+  TITLE:=Huawei E3276 support for NCM protocol
+  DEPENDS:=+comgt +kmod-usb-serial +kmod-usb-serial-option ncm endef
+
+define Package/ncm-huawei-e3276/Description
+ This package contains communication scripts for Huawei E3276 endef
+
+define Build/Prepare
+       mkdir -p $(PKG_BUILD_DIR)
+endef
+
+define Build/Configure
+
+endef
+
+define Build/Compile/Default
+
+endef
+
+Build/Compile = $(Build/Compile/Default)
+
+define Package/ncm/install
+       $(INSTALL_DIR) $(1)/lib/ $(1)/lib/netifd/ $(1)/lib/netifd/proto/
$(1)/etc/ \
+               $(1)/etc/gcom/ $(1)/etc/gcom/ncm/ $(1)/etc/gcom/ncm/signal/
\
+               $(1)/etc/gcom/ncm/carrier/ $(1)/etc/gcom/ncm/setmode/ \
+               $(1)/etc/gcom/ncm/connect/ $(1)/etc/gcom/ncm/initscripts/
+
+       $(INSTALL_BIN) ./files/lib/netifd/ncm_dhcp.sh $(1)/lib/netifd/
+       $(INSTALL_BIN) ./files/lib/netifd/proto/ncm.sh
$(1)/lib/netifd/proto/
+       $(INSTALL_DATA) ./files/etc/gcom/ncm/getcardinfo.gcom 
+$(1)/etc/gcom/ncm/ endef
+
+define Package/ncm-huawei-e3276/install
+       $(INSTALL_DIR) $(1)/etc/ $(1)/etc/gcom/ $(1)/etc/gcom/ncm/ \
+               $(1)/etc/gcom/ncm/signal/ $(1)/etc/gcom/ncm/carrier/ \
+               $(1)/etc/gcom/ncm/setmode/ $(1)/etc/gcom/ncm/connect/ \
+               $(1)/etc/gcom/ncm/initscripts/
+
+       $(INSTALL_DATA) ./files/etc/gcom/ncm/signal/huawei_e3276.gcom
$(1)/etc/gcom/ncm/signal/
+       $(INSTALL_DATA) ./files/etc/gcom/ncm/carrier/huawei_e3276.gcom
$(1)/etc/gcom/ncm/carrier/
+       $(INSTALL_DATA) ./files/etc/gcom/ncm/setmode/huawei_e3276.gcom
$(1)/etc/gcom/ncm/setmode/
+       $(INSTALL_DATA) ./files/etc/gcom/ncm/connect/huawei_e3276.gcom
$(1)/etc/gcom/ncm/connect/
+       $(INSTALL_DATA) ./files/etc/gcom/ncm/initscripts/huawei_e3276.gcom 
+$(1)/etc/gcom/ncm/initscripts/ endef
+
+$(eval $(call BuildPackage,ncm))
+$(eval $(call BuildPackage,ncm-huawei-e3276))
diff --git a/net/ncm/files/etc/gcom/ncm/carrier/huawei_e3276.gcom
b/net/ncm/files/etc/gcom/ncm/carrier/huawei_e3276.gcom
new file mode 100644
index 0000000..58684fd
--- /dev/null
+++ b/net/ncm/files/etc/gcom/ncm/carrier/huawei_e3276.gcom
@@ -0,0 +1,56 @@
+opengt
+set com 115200n81
+set comecho off
+set senddelay 0.02
+waitquiet 0.2 0.2
+flash 0.1
+
+:getprovider
+ send "AT+COPS?^m"
+ let $r="+COPS:"
+ gosub readresult
+ system "echo \""+$x+"\" | awk -F\"[:,]\" '{print \"provider \\x27\" $4
\"\\x27\"}'"
+
+:getmode
+ send "AT^^SYSCFGEX?^m"
+ let $r="^^SYSCFGEX:"
+ gosub readresult
+ system "echo \""+$x+"\" | awk -F\"[:,]\" '{ \\
+       if ( $2 == \"01\" ) print \"mode \\x27\" \"2G\\x27\"; \\
+       else if ( $2 == \"02\" ) print \"mode \\x27\" \"3G\\x27\"; \\
+       else if ( $2 == \"03\" ) print \"mode \\x27\" \"LTE\\x27\"; \\
+       else if ( $2 == \"0201\" ) print \"mode \\x27\" \"3G
Preferred\\x27\"; \\
+       else if ( $2 == \"030201\" ) print \"mode \\x27\" \"LTE
Preferred\\x27\"; \\
+       else if (( $2 == \"00\" ) or ( $2 == \"0\" )) print \"mode \\x27\"
\"Automatic/Any\\x27\"; \\
+       else print \"mode \\x27\" \"Unknown\\x27\";}'"
+
+:getrate
+ send "AT+CGEQNEG=1^m"
+ let $r="+CGEQNEG:"
+ gosub readresult
+ system "echo \""+$x+"\" | awk -F\"[:,]\" '{ print \"downlink \\x27\"
int($5) \"kbps\\x27\"; print \"uplink \\x27\" int($4) \"kbps\\x27\"; }'"
+ goto done
+
+:readresult
+ let i=5
+ let $x=""
+:loop
+ get 1 "^m" $s
+ let l=len($r)
+ if len($s) < l goto loop1
+ if $mid($s,1,l) <> $r goto loop1
+ let $x=$mid($s,1,len($s)-1)
+ 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
+
+:done
+ exit 0
+^@^@
diff --git a/net/ncm/files/etc/gcom/ncm/connect/huawei_e3276.gcom
b/net/ncm/files/etc/gcom/ncm/connect/huawei_e3276.gcom
new file mode 100644
index 0000000..d7a604c
--- /dev/null
+++ b/net/ncm/files/etc/gcom/ncm/connect/huawei_e3276.gcom
@@ -0,0 +1,63 @@
+opengt
+set com 115200n81
+set comecho off
+set senddelay 0.05
+waitquiet 1 0.2
+
+:start
+ if $env("USE_DISCONNECT")="1" goto disconnect  send 
+"AT^^NDISDUP=1,1,\""
+ send $env("USE_APN")
+
+ if $env("USE_AUTHTYPE")="-1" goto noauth else goto auth
+
+:noauth
+ send "\"^m"
+ goto result
+
+:auth
+ send "\",\""
+ send $env("USE_USERID")
+ send "\",\""
+ send $env("USE_PASSWORD")
+ send "\","
+ send $env("USE_AUTHTYPE")
+ send "^m"
+ goto result
+
+:result
+ waitfor 5 "OK","ERR","ERROR"
+ if % = 0 goto connok
+ if % = 1 goto connerr
+ if % = 2 goto connerr
+
+:connok
+ print "WWAN connection established.\r\n"
+ goto done
+
+:connerr
+ print "WWAN error. Connection failed.\r\n"
+ exit 1
+
+:disconnect
+ send "AT^^NDISDUP=1,0,\""
+ send $env("USE_APN")
+ send "\"^m"
+
+ waitfor 5 "OK","ERR","ERROR"
+ if % = 0 goto disconnok
+ if % = 1 goto disconnerr
+ if % = 2 goto disconnerr
+
+:disconnok
+ print "WWAN connection disconnected.\r\n"
+ goto done
+
+:disconnerr
+ print "WWAN disconnection error.\r\n"
+ exit 1
+
+:done
+ exit 0
+^@^@
diff --git a/net/ncm/files/etc/gcom/ncm/getcardinfo.gcom
b/net/ncm/files/etc/gcom/ncm/getcardinfo.gcom
new file mode 100644
index 0000000..79bea16
--- /dev/null
+++ b/net/ncm/files/etc/gcom/ncm/getcardinfo.gcom
@@ -0,0 +1,38 @@
+opengt
+ set com 115200n81
+ set comecho on
+ set senddelay 0.02
+ waitquiet 0.2 0.2
+ flash 0.1
+
+:start
+ let i=0
+
+:waitfordevice
+ waitquiet 2 0.5
+ inc i
+ send "AT^m"
+ waitfor 4 "OK","ERR","ERROR"
+ if % = 0 goto detect
+ if i < 5 goto waitfordevice
+ print "Error: Dongle not responding."
+ exit 1
+
+:detect
+ send "ATI^m"
+ waitfor 1 "ATI^m"
+ get 1 "OK" $s
+
+:output
+ system "echo \""+$s+"\" | grep \"Manufacturer:\" | awk '{print \"vendor
\\x27\" $2 \"\\x27\"; }'"
+ system "echo \""+$s+"\" | grep \"Model:\" | awk '{print \"model \\x27\" $2
\"\\x27\"; }'"
+ system "echo \""+$s+"\" | grep \"Revision:\" | awk '{print \"firmware
\\x27\" $2 \"\\x27\"; }'"
+ system "echo \""+$s+"\" | grep \"IMEI:\" | awk '{print \"imei \\x27\" $2
\"\\x27\"; }'"
+ system "echo \""+$s+"\" | egrep -i '^^Manufacturer|^^Model' | cut -d ' '
-f 2 | tr -d '\r' | tr '\n' '_' | sed \"s/\\(.*\\)_$/\\'\\1\\'\\n/\" | awk
'{ gsub(\"\\x27\", \"\"); \\
+       if ( $1 == \"huawei_E3276\" ) print \"driver
\\x27huawei_e3276\\x27\"; \\
+       else print \"driver \\x27-\\x27\";}'"
+
+ goto continue
+
+:continue
+ exit 0
diff --git a/net/ncm/files/etc/gcom/ncm/initscripts/huawei_e3276.gcom
b/net/ncm/files/etc/gcom/ncm/initscripts/huawei_e3276.gcom
new file mode 100644
index 0000000..7d60abd
--- /dev/null
+++ b/net/ncm/files/etc/gcom/ncm/initscripts/huawei_e3276.gcom
@@ -0,0 +1,31 @@
+opengt
+set com 115200n81
+set comecho off
+set senddelay 0.02
+waitquiet 0.2 0.2
+flash 0.1
+
+:start
+ send "AT^m"
+ waitfor 4 "OK","ERR","ERROR"
+ if % = 1 goto initerror
+ if % = 2 goto initerror
+
+ send "ATZ^m"
+ waitfor 4 "OK","ERR","ERROR"
+ if % = 1 goto initerror
+ if % = 2 goto initerror
+
+ send "ATQ V1 E1 S0=0^m"
+ waitfor 4 "OK","ERR","ERROR"
+ if % = 0 goto continue
+ if % = 1 goto initerror
+ if % = 2 goto initerror
+
+:modeerror
+ print "Error while initializing dongle.\n"
+ exit 1
+
+:continue
+ print "Dongle initialization complete.\n"
+ exit 0
diff --git a/net/ncm/files/etc/gcom/ncm/setmode/huawei_e3276.gcom
b/net/ncm/files/etc/gcom/ncm/setmode/huawei_e3276.gcom
new file mode 100644
index 0000000..275cca4
--- /dev/null
+++ b/net/ncm/files/etc/gcom/ncm/setmode/huawei_e3276.gcom
@@ -0,0 +1,56 @@
+# set wwan mode from environment
+opengt
+ set com 115200n81
+ set senddelay 0.02
+ waitquiet 1 0.2
+ flash 0.1
+
+:start
+ if $env("MODE")="2g" goto 2g
+ if $env("MODE")="3g" goto 3g
+ if $env("MODE")="lte" goto lte
+ if $env("MODE")="prefer3g" goto prefer3g  if $env("MODE")="preferlte" 
+goto preferlte  goto auto
+
+:auto
+ send "AT^^SYSCFGEX=\"00\",3FFFFFFF,2,4,7FFFFFFFFFFFFFFF,,^m"
+ goto result
+
+:2g
+ send "AT^^SYSCFGEX=\"01\",3FFFFFFF,2,4,7FFFFFFFFFFFFFFF,,^m"
+ goto result
+
+:3g
+ send "AT^^SYSCFGEX=\"02\",3FFFFFFF,2,4,7FFFFFFFFFFFFFFF,,^m"
+ goto result
+
+:lte
+ send "AT^^SYSCFGEX=\"03\",3FFFFFFF,2,4,7FFFFFFFFFFFFFFF,,^m"
+ goto result
+
+:prefer3g
+ send "AT^^SYSCFGEX=\"0201\",3FFFFFFF,2,4,7FFFFFFFFFFFFFFF,,^m"
+ goto result
+
+:preferlte
+ send "AT^^SYSCFGEX=\"030201\",3FFFFFFF,2,4,7FFFFFFFFFFFFFFF,,^m"
+ goto result
+
+:result
+ waitfor 8 "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
+ print "WWAN mode set to '"
+ print $env("MODE")
+ print "'\r\n"
+ exit 0
diff --git a/net/ncm/files/etc/gcom/ncm/signal/huawei_e3276.gcom
b/net/ncm/files/etc/gcom/ncm/signal/huawei_e3276.gcom
new file mode 100644
index 0000000..a2ddb61
--- /dev/null
+++ b/net/ncm/files/etc/gcom/ncm/signal/huawei_e3276.gcom
@@ -0,0 +1,61 @@
+opengt
+set com 115200n81
+set comecho off
+set senddelay 0.02
+waitquiet 0.2 0.2
+flash 0.1
+
+:getcell
+ send "AT+CREG=2^m"
+ let $r="OK"
+ gosub readresult
+ if $r <> $x goto getnetwork
+
+ send "AT+CREG?^m"
+ let $r="+CREG:"
+ gosub readresult
+ system "echo \""+$x+"\" | awk -F\"[:,]\" '{print \"cellid \\x27\" \"0x\"
$5 \" (\" (\"0x\"$5)+0 \")\\x27\"; print \"lac \\x27\" \"0x\" $4 \" (\"
(\"0x\"$4)+0 \")\\x27\";}'"
+
+:getnetwork
+ send "AT^^SYSINFOEX^m"
+ let $r="^^SYSINFOEX:"
+ gosub readresult
+ system "echo \""+$x+"\" | awk -F\"[:,]\" '{print \"network \\x27\" $8 \" /
\" $10 \"\\x27\";}'"
+
+:getsignalstrength
+ send "AT+CSQ^m"
+ let $r="+CSQ:"
+ gosub readresult
+ system "echo \""+$x+"\" | awk -F\"[:,]\" '{ print \"signal \\x27\" int(($2
* 100 / 31)+0.5) \"%\\x27\"; print \"rssi \\x27\" int(2 * $2 - 113)
\"dBm\\x27\"; print \"csq \\x27\" int($2) \"\\x27\"; }'"
+
+:getnoicelevels
+ send "AT^^CSNR?^m"
+ let $r="^^CSNR:"
+ gosub readresult
+ system "echo \""+$x+"\" | awk -F\"[:,]\" '{ print \"rcsp \\x27\" int($2)
\"dBm\\x27\"; print \"ecio \\x27\" int($3) \"dB\\x27\";}'"
+
+ goto done
+
+:readresult
+ let i=5
+ let $x=""
+:loop
+ get 1 "^m" $s
+ let l=len($r)
+ if len($s) < l goto loop1
+ if $mid($s,1,l) <> $r goto loop1
+ let $x=$mid($s,1,len($s)-1)
+ 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
+
+:done
+ exit 0
+^@^@
diff --git a/net/ncm/files/lib/netifd/ncm_dhcp.script
b/net/ncm/files/lib/netifd/ncm_dhcp.script
new file mode 100755
index 0000000..7454436
--- /dev/null
+++ b/net/ncm/files/lib/netifd/ncm_dhcp.script
@@ -0,0 +1,85 @@
+#!/bin/sh
+[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+
+. /lib/functions.sh
+. /lib/netifd/netifd-proto.sh
+
+set_classless_routes() {
+       local max=128
+       local type
+       while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
+               proto_add_ipv4_route "${1%%/*}" "${1##*/}" "$2"
+               max=$(($max-1))
+               shift 2
+       done
+}
+
+setup_interface () {
+       proto_init_update "$interface" 1
+       proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
+       # TODO: apply $broadcast
+
+       for i in $router; do
+               proto_add_ipv4_route 0.0.0.0 0 "$i"
+       done
+
+       # CIDR STATIC ROUTES (rfc3442)
+       [ -n "$staticroutes" ] && set_classless_routes $staticroutes
+       [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
+
+       for dns in $dns; do
+               proto_add_dns_server "$dns"
+       done
+       for domain in $domain; do
+               proto_add_dns_search "$domain"
+       done
+       proto_send_update "$INTERFACE"
+
+       if [ -n "$IFACE6RD" -a -n "$ip6rd" ]; then
+               local v4mask="${ip6rd%% *}"
+               ip6rd="${ip6rd#* }"
+               local ip6rdprefixlen="${ip6rd%% *}"
+               ip6rd="${ip6rd#* }"
+               local ip6rdprefix="${ip6rd%% *}"
+               ip6rd="${ip6rd#* }"
+               local ip6rdbr="${ip6rd%% *}"
+
+               json_init
+               json_add_string name "$IFACE6RD"
+               json_add_string ifname "@$INTERFACE"
+               json_add_string proto "6rd"
+               json_add_string peeraddr "$ip6rdbr"
+               json_add_int ip4prefixlen "$v4mask"
+               json_add_string ip6prefix "$ip6rdprefix"
+               json_add_int ip6prefixlen "$ip6rdprefixlen"
+               json_add_string tunlink "$INTERFACE"
+               json_close_object
+
+               ubus call network add_dynamic "$(json_dump)"
+       fi
+
+       # TODO
+       # [ -n "$ntpsrv" ] &&   change_state network "$ifc" lease_ntpsrv
"$ntpsrv"
+       # [ -n "$timesvr" ] &&  change_state network "$ifc" lease_timesrv
"$timesvr"
+       # [ -n "$hostname" ] && change_state network "$ifc" lease_hostname
"$hostname"
+       # [ -n "$timezone" ] &&         change_state network "$ifc"
lease_timezone "$timezone"
+}
+
+deconfig_interface() {
+       proto_init_update "$interface" 0
+       proto_send_update "$INTERFACE"
+}
+
+case "$1" in
+       deconfig)
+               deconfig_interface
+       ;;
+       renew|bound)
+               setup_interface
+       ;;
+esac
+
+# user rules
+[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
+
+exit 0
diff --git a/net/ncm/files/lib/netifd/proto/ncm.sh
b/net/ncm/files/lib/netifd/proto/ncm.sh
new file mode 100644
index 0000000..d27ab97
--- /dev/null
+++ b/net/ncm/files/lib/netifd/proto/ncm.sh
@@ -0,0 +1,144 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_ncm_init_config() {
+       no_device=1
+       available=1
+       proto_config_add_string "device"
+       proto_config_add_string "mode"
+       proto_config_add_string "apn"
+       proto_config_add_string "pincode"
+       proto_config_add_string "authtype"
+       proto_config_add_string "delay"
+       proto_config_add_string "username"
+       proto_config_add_string "password"
+       proto_config_add_string "ipaddr"
+       proto_config_add_string "netmask"
+       proto_config_add_string "hostname"
+       proto_config_add_string "clientid"
+       proto_config_add_string "vendorid"
+       proto_config_add_boolean "broadcast"
+       proto_config_add_string "reqopts"
+       proto_config_add_string "iface6rd"
+       proto_config_add_string "sendopts"
+}
+
+proto_ncm_setup() {
+
+       local config="$1"
+       local iface="$JSON_ARRAY1_1"
+
+       local device mode apn pincode authtype delay username password
+       local ipaddr hostname clientid vendorid broadcast reqopts iface6rd
sendopts
+       local cardinfo brand model driver
+       local dialupscript modescript initscript
+
+       json_get_vars device mode apn pincode delay authtype username
password
+       json_get_vars ipaddr hostname clientid vendorid broadcast reqopts 
+iface6rd sendopts
+
+       [ -e "$device" ] || {
+               proto_set_available "$interface" 0
+               return 1
+       }
+
+       cardinfo=$(gcom -d "$device" -s /etc/gcom/ncm/getcardinfo.gcom)
+       brand=$(echo "$cardinfo" | grep "vendor '" | awk '{ gsub("\x27",
""); print $2; }')
+       model=$(echo "$cardinfo" | grep "model '" | awk '{ gsub("\x27", "");
print $2; }')
+       driver=$(echo "$cardinfo" | grep "driver '" | awk '{ gsub("\x27",
""); print $2; }')      
+
+       [ "$driver" = "-" ] && {
+               logger Detected $brand $model. Device is not supported.
+               proto_notify_error "$interface" UNSUPPORTED_DEVICE
+               proto_block_restart "$interface"
+               return 1
+       }
+
+       initscript="/etc/gcom/ncm/initscripts/$driver.gcom"
+       modescript="/etc/gcom/ncm/setmode/$driver.gcom"
+       dialupscript="/etc/gcom/ncm/connect/$driver.gcom"
+
+       logger Detected $brand $model. Using driver $driver.
+
+       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
+
+       [ -e "$initscript" ] &&
+               gcom -d "$device" -s "$initscript"
+
+       [ "$authtype" = "pap" ] && authtype=1 || {
+               [ "$authtype" = "chap" ] && authtype=2 || {
+                       [ "$authtype" = "cleartext" ] && authtype=0 ||
+                               authtype=-1
+               }
+       }
+
+       [ -e "$modescript" ] &&
+               MODE="$mode" gcom -d "$device" -s "$modescript"
+
+       [ -e "$dialupscript" ] || {
+               logger Dial-up script for driver $driver is missing.
+               proto_notify_error "$interface" SCRIPT_MISSING
+               proto_block_restart "$interface"
+               return 1
+       }
+
+       USE_DISCONNECT="0" USE_APN="$apn" USE_AUTHTYPE="$authtype"
USE_USERID="$username" USE_PASSWORD="$password" \
+               gcom -d "$device" -s "$dialupscript"
+
+       [ ! -z "${delay##*[!0-9]*}" ] && [ "$delay" != "0" ] && /bin/sleep 
+$delay
+
+       local opt dhcpopts
+       for opt in $reqopts; do
+               append dhcpopts "-O $opt"
+       done
+
+       for opt in $sendopts; do
+               append dhcpopts "-x $opt"
+       done
+
+       [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
+       [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" ||
clientid="-C"
+       [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
+
+       proto_init_update "$iface" 1
+       proto_send_update "$config"
+
+       proto_export "INTERFACE=$config"
+       proto_run_command "$config" udhcpc \
+               -p /var/run/udhcpc-$iface.pid \
+               -s /lib/netifd/ncm_dhcp.script \
+               -f -t 0 -i "$iface" \
+               ${ipaddr:+-r $ipaddr} \
+               ${hostname:+-H $hostname} \
+               ${vendorid:+-V $vendorid} \
+               $clientid $broadcast $dhcpopts
+}
+
+proto_ncm_teardown() {
+       local interface="$1"
+       local device apn cardinfo driver dialupscript
+
+       json_get_vars device apn
+
+       cardinfo=$(gcom -d "$device" -s /etc/gcom/ncm/getcardinfo.gcom)
+       driver=$(echo "$cardinfo" | grep "driver '" | awk '{ gsub("\x27",
""); print $2; }')
+       dialupscript="/etc/gcom/ncm/connect/$driver.gcom"
+
+       [ "$driver" == "-" ] || 
+               [ -e "$device" ] && 
+                       [ -e "$dialupscript" ] && {
+                               USE_DISCONNECT="1" USE_APN="$apn" gcom -d
"$device" -s "$dialupscript"
+                       }
+
+       proto_kill_command "$interface"
+}
+
+add_protocol ncm
--
1.9.0
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to