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_boolean ipv6
27 local manufacturer initialize setmode connect ifname devname devpath
29 local device apn auth username password pincode delay mode pdptype ipv6
30 json_get_vars device apn auth username password pincode delay mode pdptype ipv6
32 if [ "$ipv6" = 0 ]; then
38 [ -z "$pdptype" ] && {
39 if [ -n "$ipv6" ]; then
46 [ -n "$ctl_device" ] && device=$ctl_device
49 echo "No control device specified"
50 proto_notify_error "$interface" NO_DEVICE
51 proto_set_available "$interface" 0
55 echo "Control device not valid"
56 proto_set_available "$interface" 0
60 echo "No APN specified"
61 proto_notify_error "$interface" NO_APN
65 devname="$(basename "$device")"
68 devpath="$(readlink -f /sys/class/tty/$devname/device)"
69 ifname="$( ls "$devpath"/../../*/net )"
72 devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
73 ifname="$( ls "$devpath"/net )"
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 '/Manufacturer/ { print tolower($2) }'`
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
100 json_get_values initialize initialize
101 for i in $initialize; do
102 eval COMMAND="$i" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
103 echo "Failed to initialize modem"
104 proto_notify_error "$interface" INITIALIZE_FAILED
109 [ -n "$pincode" ] && {
110 PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
111 echo "Unable to verify PIN"
112 proto_notify_error "$interface" PIN_FAILED
113 proto_block_restart "$interface"
119 json_get_var setmode "$mode"
120 COMMAND="$setmode" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
121 echo "Failed to set operating mode"
122 proto_notify_error "$interface" SETMODE_FAILED
128 json_get_vars connect
129 eval COMMAND="$connect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
130 echo "Failed to connect"
131 proto_notify_error "$interface" CONNECT_FAILED
135 echo "Connected, starting DHCP on $ifname"
137 proto_init_update "$ifname" 1
138 proto_send_update "$interface"
141 json_add_string name "${interface}_4"
142 json_add_string ifname "@$interface"
143 json_add_string proto "dhcp"
144 ubus call network add_dynamic "$(json_dump)"
148 json_add_string name "${interface}_6"
149 json_add_string ifname "@$interface"
150 json_add_string proto "dhcpv6"
151 json_add_string extendprefix 1
152 ubus call network add_dynamic "$(json_dump)"
156 proto_ncm_teardown() {
159 local manufacturer disconnect
164 echo "Stopping network"
166 manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print tolower($2) }'`
168 echo "Failed to get modem information"
169 proto_notify_error "$interface" GETINFO_FAILED
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 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" ] || {