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/tty/$devname/device)"
66 ifpath
="$devpath/../../*/net"
69 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
73 ifname
="$(ls $(ls -1 -d $ifpath | head -n 1))"
77 echo "The interface could not be found."
78 proto_notify_error
"$interface" NO_IFACE
79 proto_set_available
"$interface" 0
83 [ -n "$delay" ] && sleep "$delay"
85 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
86 [ $?
-ne 0 -o -z "$manufacturer" ] && {
87 echo "Failed to get modem information"
88 proto_notify_error
"$interface" GETINFO_FAILED
92 json_load
"$(cat /etc/gcom/ncm.json)"
93 json_select
"$manufacturer"
95 echo "Unsupported modem"
96 proto_notify_error
"$interface" UNSUPPORTED_MODEM
97 proto_set_available
"$interface" 0
101 json_get_values initialize initialize
102 for i
in $initialize; do
103 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
104 echo "Failed to initialize modem"
105 proto_notify_error
"$interface" INITIALIZE_FAILED
110 [ -n "$pincode" ] && {
111 PINCODE
="$pincode" gcom
-d "$device" -s /etc
/gcom
/setpin.gcom ||
{
112 echo "Unable to verify PIN"
113 proto_notify_error
"$interface" PIN_FAILED
114 proto_block_restart
"$interface"
119 json_get_values configure configure
120 echo "Configuring modem"
121 for i
in $configure; do
122 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
123 echo "Failed to configure modem"
124 proto_notify_error
"$interface" CONFIGURE_FAILED
131 json_get_var setmode
"$mode"
132 [ -n "$setmode" ] && {
134 eval COMMAND
="$setmode" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
135 echo "Failed to set operating mode"
136 proto_notify_error
"$interface" SETMODE_FAILED
143 echo "Starting network $interface"
144 json_get_vars connect
145 [ -n "$connect" ] && {
146 echo "Connecting modem"
147 eval COMMAND
="$connect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
148 echo "Failed to connect"
149 proto_notify_error
"$interface" CONNECT_FAILED
154 json_get_vars finalize
156 echo "Setting up $ifname"
157 proto_init_update
"$ifname" 1
159 json_add_string
"manufacturer" "$manufacturer"
161 proto_send_update
"$interface"
163 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
165 [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
167 json_add_string name
"${interface}_4"
168 json_add_string ifname
"@$interface"
169 json_add_string proto
"dhcp"
170 proto_add_dynamic_defaults
172 json_add_string zone
"$zone"
175 ubus call network add_dynamic
"$(json_dump)"
178 [ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
180 json_add_string name
"${interface}_6"
181 json_add_string ifname
"@$interface"
182 json_add_string proto
"dhcpv6"
183 json_add_string extendprefix
1
184 proto_add_dynamic_defaults
186 json_add_string zone
"$zone"
189 ubus call network add_dynamic
"$(json_dump)"
192 [ -n "$finalize" ] && {
193 eval COMMAND
="$finalize" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
194 echo "Failed to configure modem"
195 proto_notify_error
"$interface" FINALIZE_FAILED
201 proto_ncm_teardown
() {
204 local manufacturer disconnect
207 json_get_vars device profile
209 [ -n "$ctl_device" ] && device
=$ctl_device
211 [ -n "$device" ] ||
{
212 echo "No control device specified"
213 proto_notify_error
"$interface" NO_DEVICE
214 proto_set_available
"$interface" 0
218 device
="$(readlink -f $device)"
219 [ -e "$device" ] ||
{
220 echo "Control device not valid"
221 proto_set_available
"$interface" 0
225 [ -n "$profile" ] || profile
=1
227 echo "Stopping network $interface"
229 json_load
"$(ubus call network.interface.$interface status)"
231 json_get_vars manufacturer
232 [ $?
-ne 0 -o -z "$manufacturer" ] && {
233 # Fallback to direct detect, for proper handle device replug.
234 manufacturer
=$
(gcom
-d "$device" -s /etc
/gcom
/getcardinfo.gcom |
awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
235 [ $?
-ne 0 -o -z "$manufacturer" ] && {
236 echo "Failed to get modem information"
237 proto_notify_error
"$interface" GETINFO_FAILED
240 json_add_string
"manufacturer" "$manufacturer"
243 json_load
"$(cat /etc/gcom/ncm.json)"
244 json_select
"$manufacturer" ||
{
245 echo "Unsupported modem"
246 proto_notify_error
"$interface" UNSUPPORTED_MODEM
250 json_get_vars disconnect
251 [ -n "$disconnect" ] && {
252 eval COMMAND
="$disconnect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
253 echo "Failed to disconnect"
254 proto_notify_error
"$interface" DISCONNECT_FAILED
259 proto_init_update
"*" 0
260 proto_send_update
"$interface"
262 [ -n "$INCLUDE_ONLY" ] ||
{