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 dhcp
23 proto_config_add_boolean dhcpv6
24 proto_config_add_boolean autoconnect
25 proto_config_add_int plmn
26 proto_config_add_int timeout
27 proto_config_add_int mtu
28 proto_config_add_defaults
33 local dataformat connstat
34 local device apn auth username password pincode delay modes pdptype
35 local profile dhcp dhcpv6 autoconnect plmn timeout mtu
$PROTO_DEFAULT_OPTIONS
36 local ip4table ip6table
37 local cid_4 pdh_4 cid_6 pdh_6
38 local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
40 json_get_vars device apn auth username password pincode delay modes
41 json_get_vars pdptype profile dhcp dhcpv6 autoconnect plmn ip4table
42 json_get_vars ip6table timeout mtu
$PROTO_DEFAULT_OPTIONS
44 [ "$timeout" = "" ] && timeout
="10"
46 [ "$metric" = "" ] && metric
="0"
48 [ -n "$ctl_device" ] && device
=$ctl_device
51 echo "No control device specified"
52 proto_notify_error
"$interface" NO_DEVICE
53 proto_set_available
"$interface" 0
57 [ -n "$delay" ] && sleep "$delay"
59 device
="$(readlink -f $device)"
61 echo "The specified control device does not exist"
62 proto_notify_error
"$interface" NO_DEVICE
63 proto_set_available
"$interface" 0
67 devname
="$(basename "$device")"
68 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
69 ifname
="$( ls "$devpath"/net )"
71 echo "The interface could not be found."
72 proto_notify_error
"$interface" NO_IFACE
73 proto_set_available
"$interface" 0
78 echo "Setting MTU to $mtu"
79 /sbin
/ip link
set dev
$ifname mtu
$mtu
82 echo "Waiting for SIM initialization"
83 local uninitialized_timeout
=0
84 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
85 [ -e "$device" ] ||
return 1
86 if [ "$uninitialized_timeout" -lt "$timeout" -o "$timeout" = "0" ]; then
87 let uninitialized_timeout
++
90 echo "SIM not initialized"
91 proto_notify_error
"$interface" SIM_NOT_INITIALIZED
92 proto_block_restart
"$interface"
97 if uqmi
-s -d "$device" --get-pin-status |
grep '"Not supported"\|"Invalid QMI command"' > /dev
/null
; then
98 [ -n "$pincode" ] && {
99 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null ||
{
100 echo "Unable to verify PIN"
101 proto_notify_error
"$interface" PIN_FAILED
102 proto_block_restart
"$interface"
107 .
/usr
/share
/libubox
/jshn.sh
108 json_load
"$(uqmi -s -d "$device" --get-pin-status)"
109 json_get_var pin1_status pin1_status
110 json_get_var pin1_verify_tries pin1_verify_tries
112 case "$pin1_status" in
114 echo "PIN verification is disabled"
117 echo "SIM locked PUK required"
118 proto_notify_error
"$interface" PUK_NEEDED
119 proto_block_restart
"$interface"
123 [ "$pin1_verify_tries" -lt "3" ] && {
124 echo "PIN verify count value is $pin1_verify_tries this is below the limit of 3"
125 proto_notify_error
"$interface" PIN_TRIES_BELOW_LIMIT
126 proto_block_restart
"$interface"
129 if [ -n "$pincode" ]; then
130 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null
2>&1 || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null
2>&1 ||
{
131 echo "Unable to verify PIN"
132 proto_notify_error
"$interface" PIN_FAILED
133 proto_block_restart
"$interface"
137 echo "PIN not specified but required"
138 proto_notify_error
"$interface" PIN_NOT_SPECIFIED
139 proto_block_restart
"$interface"
144 echo "PIN already verified"
147 echo "PIN status failed ($pin1_status)"
148 proto_notify_error
"$interface" PIN_STATUS_FAILED
149 proto_block_restart
"$interface"
157 if [ "$plmn" = 0 ]; then
160 echo "Setting PLMN to auto"
164 echo "Setting PLMN to $plmn"
166 uqmi
-s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" > /dev
/null
2>&1 ||
{
167 echo "Unable to set PLMN"
168 proto_notify_error
"$interface" PLMN_FAILED
169 proto_block_restart
"$interface"
174 # Cleanup current state if any
175 uqmi
-s -d "$device" --stop-network 0xffffffff --autoconnect > /dev
/null
2>&1
178 uqmi
-s -d "$device" --set-device-operating-mode online
> /dev
/null
2>&1
181 uqmi
-s -d "$device" --set-data-format 802.3 > /dev
/null
2>&1
182 uqmi
-s -d "$device" --wda-set-data-format 802.3 > /dev
/null
2>&1
183 dataformat
="$(uqmi -s -d "$device" --wda-get-data-format)"
185 if [ "$dataformat" = '"raw-ip"' ]; then
187 [ -f /sys
/class
/net
/$ifname/qmi
/raw_ip
] ||
{
188 echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip"
192 echo "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .."
193 echo "Y" > /sys
/class
/net
/$ifname/qmi
/raw_ip
196 uqmi
-s -d "$device" --sync > /dev
/null
2>&1
198 echo "Waiting for network registration"
199 local registration_timeout
=0
200 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
201 [ -e "$device" ] ||
return 1
202 if [ "$registration_timeout" -lt "$timeout" -o "$timeout" = "0" ]; then
203 let registration_timeout
++
206 echo "Network registration failed"
207 proto_notify_error
"$interface" NETWORK_REGISTRATION_FAILED
208 proto_block_restart
"$interface"
213 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes" > /dev
/null
2>&1
215 echo "Starting network $interface"
217 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
218 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
220 if [ "$pdptype" = "ip" ]; then
221 [ -z "$autoconnect" ] && autoconnect
=1
222 [ "$autoconnect" = 0 ] && autoconnect
=""
224 [ "$autoconnect" = 1 ] || autoconnect
=""
227 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
228 cid_4
=$
(uqmi
-s -d "$device" --get-client-id wds
)
229 if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev
/null
; then
230 echo "Unable to obtain client ID"
231 proto_notify_error
"$interface" NO_CID
235 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
2>&1
237 pdh_4
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
240 ${profile:+--profile $profile} \
241 ${auth:+--auth-type $auth} \
242 ${username:+--username $username} \
243 ${password:+--password $password} \
244 ${autoconnect:+--autoconnect})
246 # pdh_4 is a numeric value on success
247 if ! [ "$pdh_4" -eq "$pdh_4" ] 2> /dev
/null
; then
248 echo "Unable to connect IPv4"
249 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
250 proto_notify_error
"$interface" CALL_FAILED
254 # Check data connection state
255 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
256 [ "$connstat" == '"connected"' ] ||
{
258 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
259 proto_notify_error
"$interface" CALL_FAILED
264 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
265 cid_6
=$
(uqmi
-s -d "$device" --get-client-id wds
)
266 if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev
/null
; then
267 echo "Unable to obtain client ID"
268 proto_notify_error
"$interface" NO_CID
272 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
2>&1
274 pdh_6
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
277 ${profile:+--profile $profile} \
278 ${auth:+--auth-type $auth} \
279 ${username:+--username $username} \
280 ${password:+--password $password} \
281 ${autoconnect:+--autoconnect})
283 # pdh_6 is a numeric value on success
284 if ! [ "$pdh_6" -eq "$pdh_6" ] 2> /dev
/null
; then
285 echo "Unable to connect IPv6"
286 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
287 proto_notify_error
"$interface" CALL_FAILED
291 # Check data connection state
292 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
293 [ "$connstat" == '"connected"' ] ||
{
295 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
296 proto_notify_error
"$interface" CALL_FAILED
301 echo "Setting up $ifname"
302 proto_init_update
"$ifname" 1
306 json_add_string
"cid_4" "$cid_4"
307 json_add_string
"pdh_4" "$pdh_4"
310 json_add_string
"cid_6" "$cid_6"
311 json_add_string
"pdh_6" "$pdh_6"
314 proto_send_update
"$interface"
316 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
319 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
320 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
323 json_get_var gateway_6 gateway
324 json_get_var dns1_6 dns1
325 json_get_var dns2_6 dns2
326 json_get_var ip_prefix_length ip-prefix-length
328 proto_init_update
"$ifname" 1
330 proto_add_ipv6_address
"$ip_6" "128"
331 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
332 proto_add_ipv6_route
"$gateway_6" "128"
333 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
334 [ "$peerdns" = 0 ] ||
{
335 proto_add_dns_server
"$dns1_6"
336 proto_add_dns_server
"$dns2_6"
340 json_add_string zone
"$zone"
343 proto_send_update
"$interface"
346 json_add_string name
"${interface}_6"
347 json_add_string ifname
"@$interface"
348 json_add_string proto
"dhcpv6"
349 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
350 proto_add_dynamic_defaults
351 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
352 json_add_string extendprefix
1
353 [ -n "$zone" ] && json_add_string zone
"$zone"
355 ubus call network add_dynamic
"$(json_dump)"
360 if [ "$dhcp" = 0 ]; then
361 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)"
364 json_get_var gateway_4 gateway
365 json_get_var dns1_4 dns1
366 json_get_var dns2_4 dns2
367 json_get_var subnet_4 subnet
369 proto_init_update
"$ifname" 1
371 proto_add_ipv4_address
"$ip_4" "$subnet_4"
372 proto_add_ipv4_route
"$gateway_4" "128"
373 [ "$defaultroute" = 0 ] || proto_add_ipv4_route
"0.0.0.0" 0 "$gateway_4"
374 [ "$peerdns" = 0 ] ||
{
375 proto_add_dns_server
"$dns1_4"
376 proto_add_dns_server
"$dns2_4"
380 json_add_string zone
"$zone"
383 proto_send_update
"$interface"
386 json_add_string name
"${interface}_4"
387 json_add_string ifname
"@$interface"
388 json_add_string proto
"dhcp"
389 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
390 proto_add_dynamic_defaults
391 [ -n "$zone" ] && json_add_string zone
"$zone"
393 ubus call network add_dynamic
"$(json_dump)"
402 [ -n "$cid" ] ||
return
404 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
405 --stop-network 0xffffffff \
406 --autoconnect > /dev
/null
2>&1
409 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
410 --stop-network "$pdh" > /dev
/null
2>&1
413 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
414 --release-client-id wds
> /dev
/null
2>&1
417 proto_qmi_teardown
() {
420 local device cid_4 pdh_4 cid_6 pdh_6
423 [ -n "$ctl_device" ] && device
=$ctl_device
425 echo "Stopping network $interface"
427 json_load
"$(ubus call network.interface.$interface status)"
429 json_get_vars cid_4 pdh_4 cid_6 pdh_6
431 qmi_wds_stop
"$cid_4" "$pdh_4"
432 qmi_wds_stop
"$cid_6" "$pdh_6"
434 proto_init_update
"*" 0
435 proto_send_update
"$interface"
438 [ -n "$INCLUDE_ONLY" ] ||
{