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 profile dhcpv6 autoconnect plmn timeout mtu
$PROTO_DEFAULT_OPTIONS
34 local ip4table ip6table
35 local cid_4 pdh_4 cid_6 pdh_6
36 local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
37 json_get_vars device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn ip4table ip6table timeout mtu
$PROTO_DEFAULT_OPTIONS
39 [ "$timeout" = "" ] && timeout
="10"
41 [ "$metric" = "" ] && metric
="0"
43 [ -n "$ctl_device" ] && device
=$ctl_device
46 echo "No control device specified"
47 proto_notify_error
"$interface" NO_DEVICE
48 proto_set_available
"$interface" 0
52 [ -n "$delay" ] && sleep "$delay"
54 device
="$(readlink -f $device)"
56 echo "The specified control device does not exist"
57 proto_notify_error
"$interface" NO_DEVICE
58 proto_set_available
"$interface" 0
62 devname
="$(basename "$device")"
63 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
64 ifname
="$( ls "$devpath"/net )"
66 echo "The interface could not be found."
67 proto_notify_error
"$interface" NO_IFACE
68 proto_set_available
"$interface" 0
73 echo "Setting MTU to $mtu"
74 /sbin
/ip link
set dev
$ifname mtu
$mtu
77 echo "Waiting for SIM initialization"
78 local uninitialized_timeout
=0
79 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
80 [ -e "$device" ] ||
return 1
81 if [ "$uninitialized_timeout" -lt "$timeout" ]; then
82 let uninitialized_timeout
++
85 echo "SIM not initialized"
86 proto_notify_error
"$interface" SIM_NOT_INITIALIZED
87 proto_block_restart
"$interface"
92 if uqmi
-s -d "$device" --get-pin-status |
grep '"Not supported"\|"Invalid QMI command"' > /dev
/null
; then
93 [ -n "$pincode" ] && {
94 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null ||
{
95 echo "Unable to verify PIN"
96 proto_notify_error
"$interface" PIN_FAILED
97 proto_block_restart
"$interface"
102 .
/usr
/share
/libubox
/jshn.sh
103 json_load
"$(uqmi -s -d "$device" --get-pin-status)"
104 json_get_var pin1_status pin1_status
105 json_get_var pin1_verify_tries pin1_verify_tries
107 case "$pin1_status" in
109 echo "PIN verification is disabled"
112 echo "SIM locked PUK required"
113 proto_notify_error
"$interface" PUK_NEEDED
114 proto_block_restart
"$interface"
118 [ "$pin1_verify_tries" -lt "3" ] && {
119 echo "PIN verify count value is $pin1_verify_tries this is below the limit of 3"
120 proto_notify_error
"$interface" PIN_TRIES_BELOW_LIMIT
121 proto_block_restart
"$interface"
124 if [ -n "$pincode" ]; then
125 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null
2>&1 || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null
2>&1 ||
{
126 echo "Unable to verify PIN"
127 proto_notify_error
"$interface" PIN_FAILED
128 proto_block_restart
"$interface"
132 echo "PIN not specified but required"
133 proto_notify_error
"$interface" PIN_NOT_SPECIFIED
134 proto_block_restart
"$interface"
139 echo "PIN already verified"
142 echo "PIN status failed ($pin1_status)"
143 proto_notify_error
"$interface" PIN_STATUS_FAILED
144 proto_block_restart
"$interface"
152 if [ "$plmn" = 0 ]; then
155 echo "Setting PLMN to auto"
159 echo "Setting PLMN to $plmn"
161 uqmi
-s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" > /dev
/null
2>&1 ||
{
162 echo "Unable to set PLMN"
163 proto_notify_error
"$interface" PLMN_FAILED
164 proto_block_restart
"$interface"
169 # Cleanup current state if any
170 uqmi
-s -d "$device" --stop-network 0xffffffff --autoconnect > /dev
/null
2>&1
173 uqmi
-s -d "$device" --set-data-format 802.3 > /dev
/null
2>&1
174 uqmi
-s -d "$device" --wda-set-data-format 802.3 > /dev
/null
2>&1
175 dataformat
="$(uqmi -s -d "$device" --wda-get-data-format)"
177 if [ "$dataformat" = '"raw-ip"' ]; then
179 [ -f /sys
/class
/net
/$ifname/qmi
/raw_ip
] ||
{
180 echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip"
184 echo "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .."
185 echo "Y" > /sys
/class
/net
/$ifname/qmi
/raw_ip
188 uqmi
-s -d "$device" --sync > /dev
/null
2>&1
190 echo "Waiting for network registration"
191 local registration_timeout
=0
192 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
193 [ -e "$device" ] ||
return 1
194 if [ "$registration_timeout" -lt "$timeout" ]; then
195 let registration_timeout
++
198 echo "Network registration failed"
199 proto_notify_error
"$interface" NETWORK_REGISTRATION_FAILED
200 proto_block_restart
"$interface"
205 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes" > /dev
/null
2>&1
207 echo "Starting network $interface"
209 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
210 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
212 if [ "$pdptype" = "ip" ]; then
213 [ -z "$autoconnect" ] && autoconnect
=1
214 [ "$autoconnect" = 0 ] && autoconnect
=""
216 [ "$autoconnect" = 1 ] || autoconnect
=""
219 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
220 cid_4
=$
(uqmi
-s -d "$device" --get-client-id wds
)
221 if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev
/null
; then
222 echo "Unable to obtain client ID"
223 proto_notify_error
"$interface" NO_CID
227 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
2>&1
229 pdh_4
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
232 ${profile:+--profile $profile} \
233 ${auth:+--auth-type $auth} \
234 ${username:+--username $username} \
235 ${password:+--password $password} \
236 ${autoconnect:+--autoconnect})
238 # pdh_4 is a numeric value on success
239 if ! [ "$pdh_4" -eq "$pdh_4" ] 2> /dev
/null
; then
240 echo "Unable to connect IPv4"
241 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
242 proto_notify_error
"$interface" CALL_FAILED
246 # Check data connection state
247 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
248 [ "$connstat" == '"connected"' ] ||
{
250 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
251 proto_notify_error
"$interface" CALL_FAILED
256 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
257 cid_6
=$
(uqmi
-s -d "$device" --get-client-id wds
)
258 if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev
/null
; then
259 echo "Unable to obtain client ID"
260 proto_notify_error
"$interface" NO_CID
264 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
2>&1
266 pdh_6
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
269 ${profile:+--profile $profile} \
270 ${auth:+--auth-type $auth} \
271 ${username:+--username $username} \
272 ${password:+--password $password} \
273 ${autoconnect:+--autoconnect})
275 # pdh_6 is a numeric value on success
276 if ! [ "$pdh_6" -eq "$pdh_6" ] 2> /dev
/null
; then
277 echo "Unable to connect IPv6"
278 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
279 proto_notify_error
"$interface" CALL_FAILED
283 # Check data connection state
284 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
285 [ "$connstat" == '"connected"' ] ||
{
287 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
288 proto_notify_error
"$interface" CALL_FAILED
293 echo "Setting up $ifname"
294 proto_init_update
"$ifname" 1
298 json_add_string
"cid_4" "$cid_4"
299 json_add_string
"pdh_4" "$pdh_4"
302 json_add_string
"cid_6" "$cid_6"
303 json_add_string
"pdh_6" "$pdh_6"
306 proto_send_update
"$interface"
308 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
311 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
312 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
315 json_get_var gateway_6 gateway
316 json_get_var dns1_6 dns1
317 json_get_var dns2_6 dns2
318 json_get_var ip_prefix_length ip-prefix-length
320 proto_init_update
"$ifname" 1
322 proto_add_ipv6_address
"$ip_6" "128"
323 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
324 proto_add_ipv6_route
"$gateway_6" "128"
325 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
326 [ "$peerdns" = 0 ] ||
{
327 proto_add_dns_server
"$dns1_6"
328 proto_add_dns_server
"$dns2_6"
332 json_add_string zone
"$zone"
335 proto_send_update
"$interface"
338 json_add_string name
"${interface}_6"
339 json_add_string ifname
"@$interface"
340 json_add_string proto
"dhcpv6"
341 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
342 proto_add_dynamic_defaults
343 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
344 json_add_string extendprefix
1
345 [ -n "$zone" ] && json_add_string zone
"$zone"
347 ubus call network add_dynamic
"$(json_dump)"
353 json_add_string name
"${interface}_4"
354 json_add_string ifname
"@$interface"
355 json_add_string proto
"dhcp"
356 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
357 proto_add_dynamic_defaults
358 [ -n "$zone" ] && json_add_string zone
"$zone"
360 ubus call network add_dynamic
"$(json_dump)"
368 [ -n "$cid" ] ||
return
370 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
371 --stop-network 0xffffffff \
372 --autoconnect > /dev
/null
2>&1
375 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
376 --stop-network "$pdh" > /dev
/null
2>&1
379 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
380 --release-client-id wds
> /dev
/null
2>&1
383 proto_qmi_teardown
() {
386 local device cid_4 pdh_4 cid_6 pdh_6
389 [ -n "$ctl_device" ] && device
=$ctl_device
391 echo "Stopping network $interface"
393 json_load
"$(ubus call network.interface.$interface status)"
395 json_get_vars cid_4 pdh_4 cid_6 pdh_6
397 qmi_wds_stop
"$cid_4" "$pdh_4"
398 qmi_wds_stop
"$cid_6" "$pdh_6"
400 proto_init_update
"*" 0
401 proto_send_update
"$interface"
404 [ -n "$INCLUDE_ONLY" ] ||
{