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
34 [ "$metric" = "" ] && metric
="0"
36 [ -n "$profile" ] || profile
=1
38 pdptype
=$
(echo "$pdptype" |
awk '{print toupper($0)}')
39 [ "$pdptype" = "IP" -o "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] || pdptype
="IP"
41 [ -n "$ctl_device" ] && device
=$ctl_device
44 echo "No control device specified"
45 proto_notify_error
"$interface" NO_DEVICE
46 proto_set_available
"$interface" 0
50 device
="$(readlink -f $device)"
52 echo "Control device not valid"
53 proto_set_available
"$interface" 0
58 devname
="$(basename "$device")"
61 devpath
="$(readlink -f /sys/class/tty/$devname/device)"
62 ifpath
="$devpath/../../*/net"
65 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
69 ifname
="$(ls $(ls -1 -d $ifpath | head -n 1))"
73 echo "The interface could not be found."
74 proto_notify_error
"$interface" NO_IFACE
75 proto_set_available
"$interface" 0
79 [ -n "$delay" ] && sleep "$delay"
81 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
82 [ $?
-ne 0 -o -z "$manufacturer" ] && {
83 echo "Failed to get modem information"
84 proto_notify_error
"$interface" GETINFO_FAILED
88 json_load
"$(cat /etc/gcom/ncm.json)"
89 json_select
"$manufacturer"
91 echo "Unsupported modem"
92 proto_notify_error
"$interface" UNSUPPORTED_MODEM
93 proto_set_available
"$interface" 0
97 json_get_values initialize initialize
98 for i
in $initialize; do
99 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
100 echo "Failed to initialize modem"
101 proto_notify_error
"$interface" INITIALIZE_FAILED
106 [ -n "$pincode" ] && {
107 PINCODE
="$pincode" gcom
-d "$device" -s /etc
/gcom
/setpin.gcom ||
{
108 echo "Unable to verify PIN"
109 proto_notify_error
"$interface" PIN_FAILED
110 proto_block_restart
"$interface"
115 json_get_values configure configure
116 echo "Configuring modem"
117 for i
in $configure; do
118 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
119 echo "Failed to configure modem"
120 proto_notify_error
"$interface" CONFIGURE_FAILED
127 json_get_var setmode
"$mode"
128 [ -n "$setmode" ] && {
130 eval COMMAND
="$setmode" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
131 echo "Failed to set operating mode"
132 proto_notify_error
"$interface" SETMODE_FAILED
139 echo "Starting network $interface"
140 json_get_vars connect
141 [ -n "$connect" ] && {
142 echo "Connecting modem"
143 eval COMMAND
="$connect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
144 echo "Failed to connect"
145 proto_notify_error
"$interface" CONNECT_FAILED
150 json_get_vars finalize
152 echo "Setting up $ifname"
153 proto_init_update
"$ifname" 1
155 json_add_string
"manufacturer" "$manufacturer"
157 proto_send_update
"$interface"
159 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
161 [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
163 json_add_string name
"${interface}_4"
164 json_add_string ifname
"@$interface"
165 json_add_string proto
"dhcp"
166 proto_add_dynamic_defaults
168 json_add_string zone
"$zone"
171 ubus call network add_dynamic
"$(json_dump)"
174 [ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
176 json_add_string name
"${interface}_6"
177 json_add_string ifname
"@$interface"
178 json_add_string proto
"dhcpv6"
179 json_add_string extendprefix
1
180 proto_add_dynamic_defaults
182 json_add_string zone
"$zone"
185 ubus call network add_dynamic
"$(json_dump)"
188 [ -n "$finalize" ] && {
189 eval COMMAND
="$finalize" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
190 echo "Failed to configure modem"
191 proto_notify_error
"$interface" FINALIZE_FAILED
197 proto_ncm_teardown
() {
200 local manufacturer disconnect
203 json_get_vars device profile
205 [ -n "$ctl_device" ] && device
=$ctl_device
207 [ -n "$device" ] ||
{
208 echo "No control device specified"
209 proto_notify_error
"$interface" NO_DEVICE
210 proto_set_available
"$interface" 0
214 device
="$(readlink -f $device)"
215 [ -e "$device" ] ||
{
216 echo "Control device not valid"
217 proto_set_available
"$interface" 0
221 [ -n "$profile" ] || profile
=1
223 echo "Stopping network $interface"
225 json_load
"$(ubus call network.interface.$interface status)"
227 json_get_vars manufacturer
228 [ $?
-ne 0 -o -z "$manufacturer" ] && {
229 # Fallback to direct detect, for proper handle device replug.
230 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
231 [ $?
-ne 0 -o -z "$manufacturer" ] && {
232 echo "Failed to get modem information"
233 proto_notify_error
"$interface" GETINFO_FAILED
236 json_add_string
"manufacturer" "$manufacturer"
239 json_load
"$(cat /etc/gcom/ncm.json)"
240 json_select
"$manufacturer" ||
{
241 echo "Unsupported modem"
242 proto_notify_error
"$interface" UNSUPPORTED_MODEM
246 json_get_vars disconnect
247 [ -n "$disconnect" ] && {
248 eval COMMAND
="$disconnect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
249 echo "Failed to disconnect"
250 proto_notify_error
"$interface" DISCONNECT_FAILED
255 proto_init_update
"*" 0
256 proto_send_update
"$interface"
258 [ -n "$INCLUDE_ONLY" ] ||
{