3 [ -n "$INCLUDE_ONLY" ] ||
{
9 proto_qmi_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_int delay
19 proto_config_add_string modes
20 proto_config_add_string pdptype
21 proto_config_add_int profile
22 proto_config_add_boolean dhcpv6
23 proto_config_add_boolean autoconnect
24 proto_config_add_int plmn
25 proto_config_add_int timeout
26 proto_config_add_int mtu
27 proto_config_add_defaults
32 local dataformat connstat
33 local device apn auth username password pincode delay modes pdptype
34 local profile dhcpv6 autoconnect plmn timeout mtu
$PROTO_DEFAULT_OPTIONS
35 local ip4table ip6table
36 local cid_4 pdh_4 cid_6 pdh_6
37 local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
39 json_get_vars device apn auth username password pincode delay modes
40 json_get_vars pdptype profile dhcpv6 autoconnect plmn ip4table
41 json_get_vars ip6table timeout mtu
$PROTO_DEFAULT_OPTIONS
43 [ "$timeout" = "" ] && timeout
="10"
45 [ "$metric" = "" ] && metric
="0"
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 [ -n "$delay" ] && sleep "$delay"
58 device
="$(readlink -f $device)"
60 echo "The specified control device does not exist"
61 proto_notify_error
"$interface" NO_DEVICE
62 proto_set_available
"$interface" 0
66 devname
="$(basename "$device")"
67 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
68 ifname
="$( ls "$devpath"/net )"
70 echo "The interface could not be found."
71 proto_notify_error
"$interface" NO_IFACE
72 proto_set_available
"$interface" 0
77 echo "Setting MTU to $mtu"
78 /sbin
/ip link
set dev
$ifname mtu
$mtu
81 echo "Waiting for SIM initialization"
82 local uninitialized_timeout
=0
83 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
84 [ -e "$device" ] ||
return 1
85 if [ "$uninitialized_timeout" -lt "$timeout" ]; then
86 let uninitialized_timeout
++
89 echo "SIM not initialized"
90 proto_notify_error
"$interface" SIM_NOT_INITIALIZED
91 proto_block_restart
"$interface"
96 if uqmi
-s -d "$device" --get-pin-status |
grep '"Not supported"\|"Invalid QMI command"' > /dev
/null
; then
97 [ -n "$pincode" ] && {
98 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null ||
{
99 echo "Unable to verify PIN"
100 proto_notify_error
"$interface" PIN_FAILED
101 proto_block_restart
"$interface"
106 .
/usr
/share
/libubox
/jshn.sh
107 json_load
"$(uqmi -s -d "$device" --get-pin-status)"
108 json_get_var pin1_status pin1_status
109 json_get_var pin1_verify_tries pin1_verify_tries
111 case "$pin1_status" in
113 echo "PIN verification is disabled"
116 echo "SIM locked PUK required"
117 proto_notify_error
"$interface" PUK_NEEDED
118 proto_block_restart
"$interface"
122 [ "$pin1_verify_tries" -lt "3" ] && {
123 echo "PIN verify count value is $pin1_verify_tries this is below the limit of 3"
124 proto_notify_error
"$interface" PIN_TRIES_BELOW_LIMIT
125 proto_block_restart
"$interface"
128 if [ -n "$pincode" ]; then
129 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null
2>&1 || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null
2>&1 ||
{
130 echo "Unable to verify PIN"
131 proto_notify_error
"$interface" PIN_FAILED
132 proto_block_restart
"$interface"
136 echo "PIN not specified but required"
137 proto_notify_error
"$interface" PIN_NOT_SPECIFIED
138 proto_block_restart
"$interface"
143 echo "PIN already verified"
146 echo "PIN status failed ($pin1_status)"
147 proto_notify_error
"$interface" PIN_STATUS_FAILED
148 proto_block_restart
"$interface"
156 if [ "$plmn" = 0 ]; then
159 echo "Setting PLMN to auto"
163 echo "Setting PLMN to $plmn"
165 uqmi
-s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" > /dev
/null
2>&1 ||
{
166 echo "Unable to set PLMN"
167 proto_notify_error
"$interface" PLMN_FAILED
168 proto_block_restart
"$interface"
173 # Cleanup current state if any
174 uqmi
-s -d "$device" --stop-network 0xffffffff --autoconnect > /dev
/null
2>&1
177 uqmi
-s -d "$device" --set-data-format 802.3 > /dev
/null
2>&1
178 uqmi
-s -d "$device" --wda-set-data-format 802.3 > /dev
/null
2>&1
179 dataformat
="$(uqmi -s -d "$device" --wda-get-data-format)"
181 if [ "$dataformat" = '"raw-ip"' ]; then
183 [ -f /sys
/class
/net
/$ifname/qmi
/raw_ip
] ||
{
184 echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip"
188 echo "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .."
189 echo "Y" > /sys
/class
/net
/$ifname/qmi
/raw_ip
192 uqmi
-s -d "$device" --sync > /dev
/null
2>&1
194 echo "Waiting for network registration"
195 local registration_timeout
=0
196 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
197 [ -e "$device" ] ||
return 1
198 if [ "$registration_timeout" -lt "$timeout" ]; then
199 let registration_timeout
++
202 echo "Network registration failed"
203 proto_notify_error
"$interface" NETWORK_REGISTRATION_FAILED
204 proto_block_restart
"$interface"
209 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes" > /dev
/null
2>&1
211 echo "Starting network $interface"
213 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
214 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
216 if [ "$pdptype" = "ip" ]; then
217 [ -z "$autoconnect" ] && autoconnect
=1
218 [ "$autoconnect" = 0 ] && autoconnect
=""
220 [ "$autoconnect" = 1 ] || autoconnect
=""
223 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
224 cid_4
=$
(uqmi
-s -d "$device" --get-client-id wds
)
225 if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev
/null
; then
226 echo "Unable to obtain client ID"
227 proto_notify_error
"$interface" NO_CID
231 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
2>&1
233 pdh_4
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
236 ${profile:+--profile $profile} \
237 ${auth:+--auth-type $auth} \
238 ${username:+--username $username} \
239 ${password:+--password $password} \
240 ${autoconnect:+--autoconnect})
242 # pdh_4 is a numeric value on success
243 if ! [ "$pdh_4" -eq "$pdh_4" ] 2> /dev
/null
; then
244 echo "Unable to connect IPv4"
245 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
246 proto_notify_error
"$interface" CALL_FAILED
250 # Check data connection state
251 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
252 [ "$connstat" == '"connected"' ] ||
{
254 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
255 proto_notify_error
"$interface" CALL_FAILED
260 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
261 cid_6
=$
(uqmi
-s -d "$device" --get-client-id wds
)
262 if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev
/null
; then
263 echo "Unable to obtain client ID"
264 proto_notify_error
"$interface" NO_CID
268 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
2>&1
270 pdh_6
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
273 ${profile:+--profile $profile} \
274 ${auth:+--auth-type $auth} \
275 ${username:+--username $username} \
276 ${password:+--password $password} \
277 ${autoconnect:+--autoconnect})
279 # pdh_6 is a numeric value on success
280 if ! [ "$pdh_6" -eq "$pdh_6" ] 2> /dev
/null
; then
281 echo "Unable to connect IPv6"
282 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
283 proto_notify_error
"$interface" CALL_FAILED
287 # Check data connection state
288 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
289 [ "$connstat" == '"connected"' ] ||
{
291 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
292 proto_notify_error
"$interface" CALL_FAILED
297 echo "Setting up $ifname"
298 proto_init_update
"$ifname" 1
302 json_add_string
"cid_4" "$cid_4"
303 json_add_string
"pdh_4" "$pdh_4"
306 json_add_string
"cid_6" "$cid_6"
307 json_add_string
"pdh_6" "$pdh_6"
310 proto_send_update
"$interface"
312 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
315 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
316 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
319 json_get_var gateway_6 gateway
320 json_get_var dns1_6 dns1
321 json_get_var dns2_6 dns2
322 json_get_var ip_prefix_length ip-prefix-length
324 proto_init_update
"$ifname" 1
326 proto_add_ipv6_address
"$ip_6" "128"
327 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
328 proto_add_ipv6_route
"$gateway_6" "128"
329 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
330 [ "$peerdns" = 0 ] ||
{
331 proto_add_dns_server
"$dns1_6"
332 proto_add_dns_server
"$dns2_6"
336 json_add_string zone
"$zone"
339 proto_send_update
"$interface"
342 json_add_string name
"${interface}_6"
343 json_add_string ifname
"@$interface"
344 json_add_string proto
"dhcpv6"
345 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
346 proto_add_dynamic_defaults
347 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
348 json_add_string extendprefix
1
349 [ -n "$zone" ] && json_add_string zone
"$zone"
351 ubus call network add_dynamic
"$(json_dump)"
357 json_add_string name
"${interface}_4"
358 json_add_string ifname
"@$interface"
359 json_add_string proto
"dhcp"
360 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
361 proto_add_dynamic_defaults
362 [ -n "$zone" ] && json_add_string zone
"$zone"
364 ubus call network add_dynamic
"$(json_dump)"
372 [ -n "$cid" ] ||
return
374 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
375 --stop-network 0xffffffff \
376 --autoconnect > /dev
/null
2>&1
379 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
380 --stop-network "$pdh" > /dev
/null
2>&1
383 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
384 --release-client-id wds
> /dev
/null
2>&1
387 proto_qmi_teardown
() {
390 local device cid_4 pdh_4 cid_6 pdh_6
393 [ -n "$ctl_device" ] && device
=$ctl_device
395 echo "Stopping network $interface"
397 json_load
"$(ubus call network.interface.$interface status)"
399 json_get_vars cid_4 pdh_4 cid_6 pdh_6
401 qmi_wds_stop
"$cid_4" "$pdh_4"
402 qmi_wds_stop
"$cid_6" "$pdh_6"
404 proto_init_update
"*" 0
405 proto_send_update
"$interface"
408 [ -n "$INCLUDE_ONLY" ] ||
{