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_defaults
31 local dataformat connstat
32 local device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn timeout
$PROTO_DEFAULT_OPTIONS
33 local ip4table ip6table
34 local cid_4 pdh_4 cid_6 pdh_6
35 local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
36 json_get_vars device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn ip4table ip6table timeout
$PROTO_DEFAULT_OPTIONS
38 [ "$timeout" = "" ] && timeout
="10"
40 [ "$metric" = "" ] && metric
="0"
42 [ -n "$ctl_device" ] && device
=$ctl_device
45 echo "No control device specified"
46 proto_notify_error
"$interface" NO_DEVICE
47 proto_set_available
"$interface" 0
51 [ -n "$delay" ] && sleep "$delay"
53 device
="$(readlink -f $device)"
55 echo "The specified control device does not exist"
56 proto_notify_error
"$interface" NO_DEVICE
57 proto_set_available
"$interface" 0
61 devname
="$(basename "$device")"
62 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
63 ifname
="$( ls "$devpath"/net )"
65 echo "The interface could not be found."
66 proto_notify_error
"$interface" NO_IFACE
67 proto_set_available
"$interface" 0
71 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
72 [ -e "$device" ] ||
return 1
76 [ -n "$pincode" ] && {
77 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null ||
{
78 echo "Unable to verify PIN"
79 proto_notify_error
"$interface" PIN_FAILED
80 proto_block_restart
"$interface"
87 if [ "$plmn" = 0 ]; then
90 echo "Setting PLMN to auto"
94 echo "Setting PLMN to $plmn"
96 uqmi
-s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" > /dev
/null
2>&1 ||
{
97 echo "Unable to set PLMN"
98 proto_notify_error
"$interface" PLMN_FAILED
99 proto_block_restart
"$interface"
104 # Cleanup current state if any
105 uqmi
-s -d "$device" --stop-network 0xffffffff --autoconnect > /dev
/null
2>&1
108 uqmi
-s -d "$device" --set-data-format 802.3 > /dev
/null
2>&1
109 uqmi
-s -d "$device" --wda-set-data-format 802.3 > /dev
/null
2>&1
110 dataformat
="$(uqmi -s -d "$device" --wda-get-data-format)"
112 if [ "$dataformat" = '"raw-ip"' ]; then
114 [ -f /sys
/class
/net
/$ifname/qmi
/raw_ip
] ||
{
115 echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip"
119 echo "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .."
120 echo "Y" > /sys
/class
/net
/$ifname/qmi
/raw_ip
123 uqmi
-s -d "$device" --sync > /dev
/null
2>&1
125 echo "Waiting for network registration"
126 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
127 [ -e "$device" ] ||
return 1
131 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes" > /dev
/null
2>&1
133 echo "Starting network $interface"
135 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
136 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
138 if [ "$pdptype" = "ip" ]; then
139 [ -z "$autoconnect" ] && autoconnect
=1
140 [ "$autoconnect" = 0 ] && autoconnect
=""
142 [ "$autoconnect" = 1 ] || autoconnect
=""
145 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
146 cid_4
=$
(uqmi
-s -d "$device" --get-client-id wds
)
147 if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev
/null
; then
148 echo "Unable to obtain client ID"
149 proto_notify_error
"$interface" NO_CID
153 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
2>&1
155 pdh_4
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
158 ${profile:+--profile $profile} \
159 ${auth:+--auth-type $auth} \
160 ${username:+--username $username} \
161 ${password:+--password $password} \
162 ${autoconnect:+--autoconnect})
164 # pdh_4 is a numeric value on success
165 if ! [ "$pdh_4" -eq "$pdh_4" ] 2> /dev
/null
; then
166 echo "Unable to connect IPv4"
167 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
168 proto_notify_error
"$interface" CALL_FAILED
172 # Check data connection state
173 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
174 [ "$connstat" == '"connected"' ] ||
{
176 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
177 proto_notify_error
"$interface" CALL_FAILED
182 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
183 cid_6
=$
(uqmi
-s -d "$device" --get-client-id wds
)
184 if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev
/null
; then
185 echo "Unable to obtain client ID"
186 proto_notify_error
"$interface" NO_CID
190 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
2>&1
192 pdh_6
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
195 ${profile:+--profile $profile} \
196 ${auth:+--auth-type $auth} \
197 ${username:+--username $username} \
198 ${password:+--password $password} \
199 ${autoconnect:+--autoconnect})
201 # pdh_6 is a numeric value on success
202 if ! [ "$pdh_6" -eq "$pdh_6" ] 2> /dev
/null
; then
203 echo "Unable to connect IPv6"
204 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
205 proto_notify_error
"$interface" CALL_FAILED
209 # Check data connection state
210 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
211 [ "$connstat" == '"connected"' ] ||
{
213 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
214 proto_notify_error
"$interface" CALL_FAILED
219 echo "Setting up $ifname"
220 proto_init_update
"$ifname" 1
224 json_add_string
"cid_4" "$cid_4"
225 json_add_string
"pdh_4" "$pdh_4"
228 json_add_string
"cid_6" "$cid_6"
229 json_add_string
"pdh_6" "$pdh_6"
232 proto_send_update
"$interface"
234 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
235 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
238 json_get_var gateway_6 gateway
239 json_get_var dns1_6 dns1
240 json_get_var dns2_6 dns2
241 json_get_var ip_prefix_length ip-prefix-length
243 proto_init_update
"$ifname" 1
245 proto_add_ipv6_address
"$ip_6" "128"
246 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
247 proto_add_ipv6_route
"$gateway_6" "128"
248 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
249 [ "$peerdns" = 0 ] ||
{
250 proto_add_dns_server
"$dns1_6"
251 proto_add_dns_server
"$dns2_6"
253 proto_send_update
"$interface"
256 json_add_string name
"${interface}_6"
257 json_add_string ifname
"@$interface"
258 json_add_string proto
"dhcpv6"
259 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
260 proto_add_dynamic_defaults
261 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
262 json_add_string extendprefix
1
264 ubus call network add_dynamic
"$(json_dump)"
270 json_add_string name
"${interface}_4"
271 json_add_string ifname
"@$interface"
272 json_add_string proto
"dhcp"
273 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
274 proto_add_dynamic_defaults
276 ubus call network add_dynamic
"$(json_dump)"
284 [ -n "$cid" ] ||
return
286 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
287 --stop-network 0xffffffff \
288 --autoconnect > /dev
/null
2>&1
291 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
292 --stop-network "$pdh" > /dev
/null
2>&1
295 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
296 --release-client-id wds
> /dev
/null
2>&1
299 proto_qmi_teardown
() {
302 local device cid_4 pdh_4 cid_6 pdh_6
305 [ -n "$ctl_device" ] && device
=$ctl_device
307 echo "Stopping network $interface"
309 json_load
"$(ubus call network.interface.$interface status)"
311 json_get_vars cid_4 pdh_4 cid_6 pdh_6
313 qmi_wds_stop
"$cid_4" "$pdh_4"
314 qmi_wds_stop
"$cid_6" "$pdh_6"
316 proto_init_update
"*" 0
317 proto_send_update
"$interface"
320 [ -n "$INCLUDE_ONLY" ] ||
{