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_int profile
23 proto_config_add_defaults
29 local manufacturer initialize setmode connect finalize devname devpath ifpath
31 local device ifname apn auth username password pincode delay mode pdptype profile
$PROTO_DEFAULT_OPTIONS
32 json_get_vars device ifname apn auth username password pincode delay mode pdptype profile
$PROTO_DEFAULT_OPTIONS
36 [ "$metric" = "" ] && metric
="0"
38 [ -n "$profile" ] || profile
=1
40 pdptype
=$
(echo "$pdptype" |
awk '{print toupper($0)}')
41 [ "$pdptype" = "IP" -o "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] || pdptype
="IP"
43 [ "$pdptype" = "IPV4V6" ] && context_type
=3
44 [ -z "$context_type" -a "$pdptype" = "IPV6" ] && context_type
=2
45 [ -n "$context_type" ] || context_type
=1
47 [ -n "$ctl_device" ] && device
=$ctl_device
50 echo "No control device specified"
51 proto_notify_error
"$interface" NO_DEVICE
52 proto_set_available
"$interface" 0
56 device
="$(readlink -f $device)"
58 echo "Control device not valid"
59 proto_set_available
"$interface" 0
64 devname
="$(basename "$device")"
67 devpath
="$(readlink -f /sys/class/tty/$devname/device)"
68 ifpath
="$devpath/../*/net"
71 devpath
="$(readlink -f /sys/class/tty/$devname/device)"
72 ifpath
="$devpath/../../*/net"
75 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
79 ifname
="$(ls $(ls -1 -d $ifpath | head -n 1))"
83 echo "The interface could not be found."
84 proto_notify_error
"$interface" NO_IFACE
85 proto_set_available
"$interface" 0
89 [ -n "$delay" ] && sleep "$delay"
91 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
92 [ $?
-ne 0 -o -z "$manufacturer" ] && {
93 echo "Failed to get modem information"
94 proto_notify_error
"$interface" GETINFO_FAILED
98 json_load
"$(cat /etc/gcom/ncm.json)"
99 json_select
"$manufacturer"
101 echo "Unsupported modem"
102 proto_notify_error
"$interface" UNSUPPORTED_MODEM
103 proto_set_available
"$interface" 0
107 json_get_values initialize initialize
108 for i
in $initialize; do
109 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
110 echo "Failed to initialize modem"
111 proto_notify_error
"$interface" INITIALIZE_FAILED
116 [ -n "$pincode" ] && {
117 PINCODE
="$pincode" gcom
-d "$device" -s /etc
/gcom
/setpin.gcom ||
{
118 echo "Unable to verify PIN"
119 proto_notify_error
"$interface" PIN_FAILED
120 proto_block_restart
"$interface"
125 json_get_values configure configure
126 echo "Configuring modem"
127 for i
in $configure; do
128 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
129 echo "Failed to configure modem"
130 proto_notify_error
"$interface" CONFIGURE_FAILED
137 json_get_var setmode
"$mode"
138 [ -n "$setmode" ] && {
140 eval COMMAND
="$setmode" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
141 echo "Failed to set operating mode"
142 proto_notify_error
"$interface" SETMODE_FAILED
149 echo "Starting network $interface"
150 json_get_vars connect
151 [ -n "$connect" ] && {
152 echo "Connecting modem"
153 eval COMMAND
="$connect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
154 echo "Failed to connect"
155 proto_notify_error
"$interface" CONNECT_FAILED
160 json_get_vars finalize
162 echo "Setting up $ifname"
163 proto_init_update
"$ifname" 1
165 json_add_string
"manufacturer" "$manufacturer"
167 proto_send_update
"$interface"
169 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
171 [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
173 json_add_string name
"${interface}_4"
174 json_add_string ifname
"@$interface"
175 json_add_string proto
"dhcp"
176 proto_add_dynamic_defaults
178 json_add_string zone
"$zone"
181 ubus call network add_dynamic
"$(json_dump)"
184 [ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
186 json_add_string name
"${interface}_6"
187 json_add_string ifname
"@$interface"
188 json_add_string proto
"dhcpv6"
189 json_add_string extendprefix
1
190 proto_add_dynamic_defaults
192 json_add_string zone
"$zone"
195 ubus call network add_dynamic
"$(json_dump)"
198 [ -n "$finalize" ] && {
199 eval COMMAND
="$finalize" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
200 echo "Failed to configure modem"
201 proto_notify_error
"$interface" FINALIZE_FAILED
207 proto_ncm_teardown
() {
210 local manufacturer disconnect
213 json_get_vars device profile
215 [ -n "$ctl_device" ] && device
=$ctl_device
217 [ -n "$device" ] ||
{
218 echo "No control device specified"
219 proto_notify_error
"$interface" NO_DEVICE
220 proto_set_available
"$interface" 0
224 device
="$(readlink -f $device)"
225 [ -e "$device" ] ||
{
226 echo "Control device not valid"
227 proto_set_available
"$interface" 0
231 [ -n "$profile" ] || profile
=1
233 echo "Stopping network $interface"
235 json_load
"$(ubus call network.interface.$interface status)"
237 json_get_vars manufacturer
238 [ $?
-ne 0 -o -z "$manufacturer" ] && {
239 # Fallback to direct detect, for proper handle device replug.
240 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
241 [ $?
-ne 0 -o -z "$manufacturer" ] && {
242 echo "Failed to get modem information"
243 proto_notify_error
"$interface" GETINFO_FAILED
246 json_add_string
"manufacturer" "$manufacturer"
249 json_load
"$(cat /etc/gcom/ncm.json)"
250 json_select
"$manufacturer" ||
{
251 echo "Unsupported modem"
252 proto_notify_error
"$interface" UNSUPPORTED_MODEM
256 json_get_vars disconnect
257 [ -n "$disconnect" ] && {
258 eval COMMAND
="$disconnect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
259 echo "Failed to disconnect"
260 proto_notify_error
"$interface" DISCONNECT_FAILED
265 proto_init_update
"*" 0
266 proto_send_update
"$interface"
268 [ -n "$INCLUDE_ONLY" ] ||
{