3 [ -n "$INCLUDE_ONLY" ] ||
{
9 proto_ncm_init_config
() {
12 proto_config_add_string
"device:device"
13 proto_config_add_string apn
14 proto_config_add_string auth
15 proto_config_add_string username
16 proto_config_add_string password
17 proto_config_add_string pincode
18 proto_config_add_string delay
19 proto_config_add_string mode
20 proto_config_add_string pdptype
21 proto_config_add_int profile
22 proto_config_add_defaults
28 local manufacturer initialize setmode connect ifname devname devpath
30 local device apn auth username password pincode delay mode pdptype profile
$PROTO_DEFAULT_OPTIONS
31 json_get_vars device apn auth username password pincode delay mode pdptype profile
$PROTO_DEFAULT_OPTIONS
33 [ "$metric" = "" ] && metric
="0"
35 [ -n "$profile" ] || profile
=1
37 pdptype
=`echo "$pdptype" | awk '{print toupper($0)}'`
38 [ "$pdptype" = "IP" -o "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] ||
$pdptype="IP"
40 [ -n "$ctl_device" ] && device
=$ctl_device
43 echo "No control device specified"
44 proto_notify_error
"$interface" NO_DEVICE
45 proto_set_available
"$interface" 0
49 device
="$(readlink -f $device)"
51 echo "Control device not valid"
52 proto_set_available
"$interface" 0
56 devname
="$(basename "$device")"
59 devpath
="$(readlink -f /sys/class/tty/$devname/device)"
60 ifname
="$( ls "$devpath"/../../*/net )"
63 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
64 ifname
="$( ls "$devpath"/net )"
68 echo "The interface could not be found."
69 proto_notify_error
"$interface" NO_IFACE
70 proto_set_available
"$interface" 0
74 [ -n "$delay" ] && sleep "$delay"
76 manufacturer
=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }'`
78 echo "Failed to get modem information"
79 proto_notify_error
"$interface" GETINFO_FAILED
83 json_load
"$(cat /etc/gcom/ncm.json)"
84 json_select
"$manufacturer"
86 echo "Unsupported modem"
87 proto_notify_error
"$interface" UNSUPPORTED_MODEM
88 proto_set_available
"$interface" 0
91 json_get_values initialize initialize
92 for i
in $initialize; do
93 eval COMMAND
="$i" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
94 echo "Failed to initialize modem"
95 proto_notify_error
"$interface" INITIALIZE_FAILED
100 [ -n "$pincode" ] && {
101 PINCODE
="$pincode" gcom
-d "$device" -s /etc
/gcom
/setpin.gcom ||
{
102 echo "Unable to verify PIN"
103 proto_notify_error
"$interface" PIN_FAILED
104 proto_block_restart
"$interface"
110 json_get_var setmode
"$mode"
111 eval COMMAND
="$setmode" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
112 echo "Failed to set operating mode"
113 proto_notify_error
"$interface" SETMODE_FAILED
119 echo "Starting network $interface"
120 json_get_vars connect
121 eval COMMAND
="$connect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
122 echo "Failed to connect"
123 proto_notify_error
"$interface" CONNECT_FAILED
127 echo "Setting up $ifname"
129 proto_init_update
"$ifname" 1
131 json_add_string
"manufacturer" "$manufacturer"
133 proto_send_update
"$interface"
135 [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
137 json_add_string name
"${interface}_4"
138 json_add_string ifname
"@$interface"
139 json_add_string proto
"dhcp"
140 proto_add_dynamic_defaults
141 ubus call network add_dynamic
"$(json_dump)"
144 [ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
146 json_add_string name
"${interface}_6"
147 json_add_string ifname
"@$interface"
148 json_add_string proto
"dhcpv6"
149 json_add_string extendprefix
1
150 proto_add_dynamic_defaults
151 ubus call network add_dynamic
"$(json_dump)"
155 proto_ncm_teardown
() {
158 local manufacturer disconnect
161 json_get_vars device profile
163 [ -n "$ctl_device" ] && device
=$ctl_device
165 [ -n "$profile" ] || profile
=1
167 echo "Stopping network $interface"
169 json_load
"$(ubus call network.interface.$interface status)"
171 json_get_vars manufacturer
173 json_load
"$(cat /etc/gcom/ncm.json)"
174 json_select
"$manufacturer" ||
{
175 echo "Unsupported modem"
176 proto_notify_error
"$interface" UNSUPPORTED_MODEM
180 json_get_vars disconnect
181 eval COMMAND
="$disconnect" gcom
-d "$device" -s /etc
/gcom
/runcommand.gcom ||
{
182 echo "Failed to disconnect"
183 proto_notify_error
"$interface" DISCONNECT_FAILED
187 proto_init_update
"*" 0
188 proto_send_update
"$interface"
190 [ -n "$INCLUDE_ONLY" ] ||
{