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
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 ifname
="$( ls "$devpath"/../../*/net )"
65 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
66 ifname
="$( ls "$devpath"/net )"
72 echo "The interface could not be found."
73 proto_notify_error
"$interface" NO_IFACE
74 proto_set_available
"$interface" 0
78 [ -n "$delay" ] && sleep "$delay"
80 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
81 [ $?
-ne 0 -o -z "$manufacturer" ] && {
82 echo "Failed to get modem information"
83 proto_notify_error
"$interface" GETINFO_FAILED
87 json_load
"$(cat /etc/gcom/ncm.json)"
88 json_select
"$manufacturer"
90 echo "Unsupported modem"
91 proto_notify_error
"$interface" UNSUPPORTED_MODEM
92 proto_set_available
"$interface" 0
96 json_get_values initialize initialize
97 for i
in $initialize; do
98 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
99 echo "Failed to initialize modem"
100 proto_notify_error
"$interface" INITIALIZE_FAILED
105 [ -n "$pincode" ] && {
106 PINCODE
="$pincode" gcom
-d "$device" -s /etc
/gcom
/setpin.gcom ||
{
107 echo "Unable to verify PIN"
108 proto_notify_error
"$interface" PIN_FAILED
109 proto_block_restart
"$interface"
114 json_get_values configure configure
115 echo "Configuring modem"
116 for i
in $configure; do
117 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
118 echo "Failed to configure modem"
119 proto_notify_error
"$interface" CONFIGURE_FAILED
126 json_get_var setmode
"$mode"
127 [ -n "$setmode" ] && {
129 eval COMMAND
="$setmode" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
130 echo "Failed to set operating mode"
131 proto_notify_error
"$interface" SETMODE_FAILED
138 echo "Starting network $interface"
139 json_get_vars connect
140 [ -n "$connect" ] && {
141 echo "Connecting modem"
142 eval COMMAND
="$connect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
143 echo "Failed to connect"
144 proto_notify_error
"$interface" CONNECT_FAILED
149 json_get_vars finalize
151 echo "Setting up $ifname"
152 proto_init_update
"$ifname" 1
154 json_add_string
"manufacturer" "$manufacturer"
156 proto_send_update
"$interface"
158 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
160 [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
162 json_add_string name
"${interface}_4"
163 json_add_string ifname
"@$interface"
164 json_add_string proto
"dhcp"
165 proto_add_dynamic_defaults
167 json_add_string zone
"$zone"
170 ubus call network add_dynamic
"$(json_dump)"
173 [ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
175 json_add_string name
"${interface}_6"
176 json_add_string ifname
"@$interface"
177 json_add_string proto
"dhcpv6"
178 json_add_string extendprefix
1
179 proto_add_dynamic_defaults
181 json_add_string zone
"$zone"
184 ubus call network add_dynamic
"$(json_dump)"
187 [ -n "$finalize" ] && {
188 eval COMMAND
="$finalize" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
189 echo "Failed to configure modem"
190 proto_notify_error
"$interface" FINALIZE_FAILED
196 proto_ncm_teardown
() {
199 local manufacturer disconnect
202 json_get_vars device profile
204 [ -n "$ctl_device" ] && device
=$ctl_device
206 [ -n "$device" ] ||
{
207 echo "No control device specified"
208 proto_notify_error
"$interface" NO_DEVICE
209 proto_set_available
"$interface" 0
213 device
="$(readlink -f $device)"
214 [ -e "$device" ] ||
{
215 echo "Control device not valid"
216 proto_set_available
"$interface" 0
220 [ -n "$profile" ] || profile
=1
222 echo "Stopping network $interface"
224 json_load
"$(ubus call network.interface.$interface status)"
226 json_get_vars manufacturer
227 [ $?
-ne 0 -o -z "$manufacturer" ] && {
228 # Fallback to direct detect, for proper handle device replug.
229 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
230 [ $?
-ne 0 -o -z "$manufacturer" ] && {
231 echo "Failed to get modem information"
232 proto_notify_error
"$interface" GETINFO_FAILED
235 json_add_string
"manufacturer" "$manufacturer"
238 json_load
"$(cat /etc/gcom/ncm.json)"
239 json_select
"$manufacturer" ||
{
240 echo "Unsupported modem"
241 proto_notify_error
"$interface" UNSUPPORTED_MODEM
245 json_get_vars disconnect
246 [ -n "$disconnect" ] && {
247 eval COMMAND
="$disconnect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
248 echo "Failed to disconnect"
249 proto_notify_error
"$interface" DISCONNECT_FAILED
254 proto_init_update
"*" 0
255 proto_send_update
"$interface"
257 [ -n "$INCLUDE_ONLY" ] ||
{