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
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 ipv6 $PROTO_DEFAULT_OPTIONS
31 json_get_vars device apn auth username password pincode delay mode pdptype ipv6 $PROTO_DEFAULT_OPTIONS
33 if [ "$ipv6" = 0 ]; then
39 [ -z "$pdptype" ] && {
40 if [ -n "$ipv6" ]; then
47 [ -n "$ctl_device" ] && device=$ctl_device
50 echo "No control device specified"
51 proto_notify_error "$interface" NO_DEVICE
52 proto_set_available "$interface" 0
56 echo "Control device not valid"
57 proto_set_available "$interface" 0
61 echo "No APN specified"
62 proto_notify_error "$interface" NO_APN
66 devname="$(basename "$device")"
69 devpath="$(readlink -f /sys/class/tty/$devname/device)"
70 ifname="$( ls "$devpath"/../../*/net )"
73 devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
74 ifname="$( ls "$devpath"/net )"
78 echo "The interface could not be found."
79 proto_notify_error "$interface" NO_IFACE
80 proto_set_available "$interface" 0
84 [ -n "$delay" ] && sleep "$delay"
86 manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print tolower($2) }'`
88 echo "Failed to get modem information"
89 proto_notify_error "$interface" GETINFO_FAILED
93 json_load "$(cat /etc/gcom/ncm.json)"
94 json_select "$manufacturer"
96 echo "Unsupported modem"
97 proto_notify_error "$interface" UNSUPPORTED_MODEM
98 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"
120 json_get_var setmode "$mode"
121 COMMAND="$setmode" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
122 echo "Failed to set operating mode"
123 proto_notify_error "$interface" SETMODE_FAILED
129 json_get_vars connect
130 eval COMMAND="$connect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
131 echo "Failed to connect"
132 proto_notify_error "$interface" CONNECT_FAILED
136 echo "Connected, starting DHCP on $ifname"
138 proto_init_update "$ifname" 1
139 proto_send_update "$interface"
142 json_add_string name "${interface}_4"
143 json_add_string ifname "@$interface"
144 json_add_string proto "dhcp"
145 proto_add_dynamic_defaults
146 ubus call network add_dynamic "$(json_dump)"
150 json_add_string name "${interface}_6"
151 json_add_string ifname "@$interface"
152 json_add_string proto "dhcpv6"
153 json_add_string extendprefix 1
154 proto_add_dynamic_defaults
155 ubus call network add_dynamic "$(json_dump)"
159 proto_ncm_teardown() {
162 local manufacturer disconnect
167 echo "Stopping network"
169 manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print tolower($2) }'`
171 echo "Failed to get modem information"
172 proto_notify_error "$interface" GETINFO_FAILED
176 json_load "$(cat /etc/gcom/ncm.json)"
177 json_select "$manufacturer" || {
178 echo "Unsupported modem"
179 proto_notify_error "$interface" UNSUPPORTED_MODEM
183 json_get_vars disconnect
184 COMMAND="$disconnect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
185 echo "Failed to disconnect"
186 proto_notify_error "$interface" DISCONNECT_FAILED
190 proto_init_update "*" 0
191 proto_send_update "$interface"
193 [ -n "$INCLUDE_ONLY" ] || {