7 proto_ncm_init_config() {
10 proto_config_add_string "device:device"
11 proto_config_add_string apn
12 proto_config_add_string auth
13 proto_config_add_string username
14 proto_config_add_string password
15 proto_config_add_string pincode
16 proto_config_add_string delay
17 proto_config_add_string mode
23 local manufacturer initialize setmode connect
25 local device apn auth username password pincode delay mode
26 json_get_vars device apn auth username password pincode delay mode
29 echo "ncm[$$]" "No control device specified"
30 proto_notify_error "$interface" NO_DEVICE
31 proto_set_available "$interface" 0
35 echo "ncm[$$]" "Control device not valid"
36 proto_set_available "$interface" 0
40 echo "ncm[$$]" "No APN specified"
41 proto_notify_error "$interface" NO_APN
42 proto_set_available "$interface" 0
46 [ -n "$delay" ] && sleep "$delay"
48 manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print $2 }'`
50 echo "ncm[$$]" "Failed to get modem information"
51 proto_notify_error "$interface" GETINFO_FAILED
52 proto_set_available "$interface" 0
56 json_load "$(cat /etc/gcom/ncm.json)"
57 json_select "$manufacturer"
59 echo "ncm[$$]" "Unsupported modem"
60 proto_notify_error "$interface" UNSUPPORTED_MODEM
61 proto_set_available "$interface" 0
64 json_get_values initialize initialize
65 for i in $initialize; do
66 eval COMMAND="$i" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
67 echo "ncm[$$]" "Failed to initialize modem"
68 proto_notify_error "$interface" INITIALIZE_FAILED
69 proto_set_available "$interface" 0
74 [ -n "$pincode" ] && {
75 PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
76 echo "ncm[$$]" "Unable to verify PIN"
77 proto_notify_error "$interface" PIN_FAILED
78 proto_block_restart "$interface"
84 json_get_var setmode "$mode"
85 COMMAND="$setmode" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
86 echo "ncm[$$]" "Failed to set operating mode"
87 proto_notify_error "$interface" SETMODE_FAILED
88 proto_set_available "$interface" 0
94 json_get_var connect connect
95 eval COMMAND="$connect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
96 echo "ncm[$$]" "Failed to connect"
97 proto_notify_error "$interface" CONNECT_FAILED
98 proto_set_available "$interface" 0
102 echo "ncm[$$]" "Connected, starting DHCP"
103 proto_init_update "*" 1
104 proto_send_update "$interface"
107 json_add_string name "${interface}_dhcp"
108 json_add_string ifname "@$interface"
109 json_add_string proto "dhcp"
111 ubus call network add_dynamic "$(json_dump)"
114 json_add_string name "${interface}_dhcpv6"
115 json_add_string ifname "@$interface"
116 json_add_string proto "dhcpv6"
118 ubus call network add_dynamic "$(json_dump)"
121 proto_ncm_teardown() {
124 proto_init_update "*" 0
125 proto_send_update "$interface"
127 local manufacturer disconnect
132 echo "ncm[$$]" "Stopping network"
134 manufacturer=`gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk '/Manufacturer/ { print $2 }'`
136 echo "ncm[$$]" "Failed to get modem information"
137 proto_notify_error "$interface" GETINFO_FAILED
141 json_load "$(cat /etc/gcom/ncm.json)"
142 json_select "$manufacturer" || {
143 echo "ncm[$$]" "Unsupported modem"
144 proto_notify_error "$interface" UNSUPPORTED_MODEM
148 json_get_var disconnect disconnect
149 COMMAND="$disconnect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
150 echo "ncm[$$]" "Failed to disconnect"
151 proto_notify_error "$interface" DISCONNECT_FAILED