3 [ -n "$INCLUDE_ONLY" ] ||
{
9 proto_ncm_init_config
() {
12 proto_config_add_string
"device:device"
13 proto_config_add_string ifname
14 proto_config_add_string apn
15 proto_config_add_string auth
16 proto_config_add_string username
17 proto_config_add_string password
18 proto_config_add_string pincode
19 proto_config_add_string delay
20 proto_config_add_string mode
21 proto_config_add_string pdptype
22 proto_config_add_boolean sourcefilter
23 proto_config_add_int profile
24 proto_config_add_defaults
30 local manufacturer initialize setmode connect finalize devname devpath ifpath
32 local device ifname apn auth username password pincode delay mode pdptype profile
$PROTO_DEFAULT_OPTIONS
33 json_get_vars device ifname apn auth username password pincode delay mode pdptype sourcefilter profile
$PROTO_DEFAULT_OPTIONS
37 [ "$metric" = "" ] && metric
="0"
39 [ -n "$profile" ] || profile
=1
41 pdptype
=$
(echo "$pdptype" |
awk '{print toupper($0)}')
42 [ "$pdptype" = "IP" -o "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] || pdptype
="IP"
44 [ "$pdptype" = "IPV4V6" ] && context_type
=3
45 [ -z "$context_type" -a "$pdptype" = "IPV6" ] && context_type
=2
46 [ -n "$context_type" ] || context_type
=1
48 [ -n "$ctl_device" ] && device
=$ctl_device
51 echo "No control device specified"
52 proto_notify_error
"$interface" NO_DEVICE
53 proto_set_available
"$interface" 0
57 device
="$(readlink -f $device)"
59 echo "Control device not valid"
60 proto_set_available
"$interface" 0
65 devname
="$(basename "$device")"
68 devpath
="$(readlink -f /sys/class/tty/$devname/device)"
69 ifpath
="$devpath/../*/net"
72 devpath
="$(readlink -f /sys/class/tty/$devname/device)"
73 ifpath
="$devpath/../../*/net"
76 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
80 ifname
="$(ls $(ls -1 -d $ifpath | head -n 1))"
84 echo "The interface could not be found."
85 proto_notify_error
"$interface" NO_IFACE
86 proto_set_available
"$interface" 0
92 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
93 [ "$manufacturer" = "error" ] && {
96 [ -n "$manufacturer" ] && {
103 elapsed
=$
(($
(date +%s
) - start
))
104 [ "$elapsed" -gt "$delay" ] && {
108 [ -z "$manufacturer" ] && {
109 echo "Failed to get modem information"
110 proto_notify_error
"$interface" GETINFO_FAILED
114 json_load
"$(cat /etc/gcom/ncm.json)"
115 json_select
"$manufacturer"
117 echo "Unsupported modem"
118 proto_notify_error
"$interface" UNSUPPORTED_MODEM
119 proto_set_available
"$interface" 0
123 json_get_values initialize initialize
124 for i
in $initialize; do
125 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
126 echo "Failed to initialize modem"
127 proto_notify_error
"$interface" INITIALIZE_FAILED
132 [ -n "$pincode" ] && {
133 PINCODE
="$pincode" gcom
-d "$device" -s /etc
/gcom
/setpin.gcom ||
{
134 echo "Unable to verify PIN"
135 proto_notify_error
"$interface" PIN_FAILED
136 proto_block_restart
"$interface"
141 json_get_values configure configure
142 echo "Configuring modem"
143 for i
in $configure; do
144 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
145 echo "Failed to configure modem"
146 proto_notify_error
"$interface" CONFIGURE_FAILED
153 json_get_var setmode
"$mode"
154 [ -n "$setmode" ] && {
156 eval COMMAND
="$setmode" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
157 echo "Failed to set operating mode"
158 proto_notify_error
"$interface" SETMODE_FAILED
165 echo "Starting network $interface"
166 json_get_vars connect
167 [ -n "$connect" ] && {
168 echo "Connecting modem"
169 eval COMMAND
="$connect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
170 echo "Failed to connect"
171 proto_notify_error
"$interface" CONNECT_FAILED
176 json_get_vars finalize
178 echo "Setting up $ifname"
179 proto_init_update
"$ifname" 1
181 json_add_string
"manufacturer" "$manufacturer"
183 proto_send_update
"$interface"
185 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
187 [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
189 json_add_string name
"${interface}_4"
190 json_add_string ifname
"@$interface"
191 json_add_string proto
"dhcp"
192 proto_add_dynamic_defaults
194 json_add_string zone
"$zone"
197 ubus call network add_dynamic
"$(json_dump)"
200 [ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
202 json_add_string name
"${interface}_6"
203 json_add_string ifname
"@$interface"
204 json_add_string proto
"dhcpv6"
205 json_add_string extendprefix
1
206 [ "$sourcefilter" = "0" ] && json_add_boolean sourcefilter
"0"
207 proto_add_dynamic_defaults
209 json_add_string zone
"$zone"
212 ubus call network add_dynamic
"$(json_dump)"
215 [ -n "$finalize" ] && {
216 eval COMMAND
="$finalize" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
217 echo "Failed to configure modem"
218 proto_notify_error
"$interface" FINALIZE_FAILED
224 proto_ncm_teardown
() {
227 local manufacturer disconnect
230 json_get_vars device profile
232 [ -n "$ctl_device" ] && device
=$ctl_device
234 [ -n "$device" ] ||
{
235 echo "No control device specified"
236 proto_notify_error
"$interface" NO_DEVICE
237 proto_set_available
"$interface" 0
241 device
="$(readlink -f $device)"
242 [ -e "$device" ] ||
{
243 echo "Control device not valid"
244 proto_set_available
"$interface" 0
248 [ -n "$profile" ] || profile
=1
250 echo "Stopping network $interface"
252 json_load
"$(ubus call network.interface.$interface status)"
254 json_get_vars manufacturer
255 [ $?
-ne 0 -o -z "$manufacturer" ] && {
256 # Fallback to direct detect, for proper handle device replug.
257 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
258 [ $?
-ne 0 -o -z "$manufacturer" ] && {
259 echo "Failed to get modem information"
260 proto_notify_error
"$interface" GETINFO_FAILED
263 json_add_string
"manufacturer" "$manufacturer"
266 json_load
"$(cat /etc/gcom/ncm.json)"
267 json_select
"$manufacturer" ||
{
268 echo "Unsupported modem"
269 proto_notify_error
"$interface" UNSUPPORTED_MODEM
273 json_get_vars disconnect
274 [ -n "$disconnect" ] && {
275 eval COMMAND
="$disconnect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
276 echo "Failed to disconnect"
277 proto_notify_error
"$interface" DISCONNECT_FAILED
282 proto_init_update
"*" 0
283 proto_send_update
"$interface"
285 [ -n "$INCLUDE_ONLY" ] ||
{