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_defaults
30 local dataformat connstat
31 local device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn
$PROTO_DEFAULT_OPTIONS
32 local ip4table ip6table
33 local cid_4 pdh_4 cid_6 pdh_6
34 local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
35 json_get_vars device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn ip4table ip6table
$PROTO_DEFAULT_OPTIONS
37 [ "$metric" = "" ] && metric
="0"
39 [ -n "$ctl_device" ] && device
=$ctl_device
42 echo "No control device specified"
43 proto_notify_error
"$interface" NO_DEVICE
44 proto_set_available
"$interface" 0
48 [ -n "$delay" ] && sleep "$delay"
50 device
="$(readlink -f $device)"
52 echo "The specified control device does not exist"
53 proto_notify_error
"$interface" NO_DEVICE
54 proto_set_available
"$interface" 0
58 devname
="$(basename "$device")"
59 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
60 ifname
="$( ls "$devpath"/net )"
62 echo "The interface could not be found."
63 proto_notify_error
"$interface" NO_IFACE
64 proto_set_available
"$interface" 0
68 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
69 [ -e "$device" ] ||
return 1
73 [ -n "$pincode" ] && {
74 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null ||
{
75 echo "Unable to verify PIN"
76 proto_notify_error
"$interface" PIN_FAILED
77 proto_block_restart
"$interface"
84 if [ "$plmn" = 0 ]; then
87 echo "Setting PLMN to auto"
91 echo "Setting PLMN to $plmn"
93 uqmi
-s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" > /dev
/null
2>&1 ||
{
94 echo "Unable to set PLMN"
95 proto_notify_error
"$interface" PLMN_FAILED
96 proto_block_restart
"$interface"
101 # Cleanup current state if any
102 uqmi
-s -d "$device" --stop-network 0xffffffff --autoconnect > /dev
/null
2>&1
105 uqmi
-s -d "$device" --set-data-format 802.3 > /dev
/null
2>&1
106 uqmi
-s -d "$device" --wda-set-data-format 802.3 > /dev
/null
2>&1
107 dataformat
="$(uqmi -s -d "$device" --wda-get-data-format)"
109 if [ "$dataformat" = '"raw-ip"' ]; then
111 [ -f /sys
/class
/net
/$ifname/qmi
/raw_ip
] ||
{
112 echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip"
116 echo "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .."
117 echo "Y" > /sys
/class
/net
/$ifname/qmi
/raw_ip
120 uqmi
-s -d "$device" --sync > /dev
/null
2>&1
122 echo "Waiting for network registration"
123 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
124 [ -e "$device" ] ||
return 1
128 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes" > /dev
/null
2>&1
130 echo "Starting network $interface"
132 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
133 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
135 if [ "$pdptype" = "ip" ]; then
136 [ -z "$autoconnect" ] && autoconnect
=1
137 [ "$autoconnect" = 0 ] && autoconnect
=""
139 [ "$autoconnect" = 1 ] || autoconnect
=""
142 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
143 cid_4
=$
(uqmi
-s -d "$device" --get-client-id wds
)
144 if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev
/null
; then
145 echo "Unable to obtain client ID"
146 proto_notify_error
"$interface" NO_CID
150 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
2>&1
152 pdh_4
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
155 ${profile:+--profile $profile} \
156 ${auth:+--auth-type $auth} \
157 ${username:+--username $username} \
158 ${password:+--password $password} \
159 ${autoconnect:+--autoconnect})
161 # pdh_4 is a numeric value on success
162 if ! [ "$pdh_4" -eq "$pdh_4" ] 2> /dev
/null
; then
163 echo "Unable to connect IPv4"
164 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
165 proto_notify_error
"$interface" CALL_FAILED
169 # Check data connection state
170 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
171 [ "$connstat" == '"connected"' ] ||
{
173 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
174 proto_notify_error
"$interface" CALL_FAILED
179 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
180 cid_6
=$
(uqmi
-s -d "$device" --get-client-id wds
)
181 if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev
/null
; then
182 echo "Unable to obtain client ID"
183 proto_notify_error
"$interface" NO_CID
187 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
2>&1
189 pdh_6
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
192 ${profile:+--profile $profile} \
193 ${auth:+--auth-type $auth} \
194 ${username:+--username $username} \
195 ${password:+--password $password} \
196 ${autoconnect:+--autoconnect})
198 # pdh_6 is a numeric value on success
199 if ! [ "$pdh_6" -eq "$pdh_6" ] 2> /dev
/null
; then
200 echo "Unable to connect IPv6"
201 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
202 proto_notify_error
"$interface" CALL_FAILED
206 # Check data connection state
207 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
208 [ "$connstat" == '"connected"' ] ||
{
210 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
211 proto_notify_error
"$interface" CALL_FAILED
216 echo "Setting up $ifname"
217 proto_init_update
"$ifname" 1
221 json_add_string
"cid_4" "$cid_4"
222 json_add_string
"pdh_4" "$pdh_4"
225 json_add_string
"cid_6" "$cid_6"
226 json_add_string
"pdh_6" "$pdh_6"
229 proto_send_update
"$interface"
231 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
232 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
235 json_get_var gateway_6 gateway
236 json_get_var dns1_6 dns1
237 json_get_var dns2_6 dns2
238 json_get_var ip_prefix_length ip-prefix-length
240 proto_init_update
"$ifname" 1
242 proto_add_ipv6_address
"$ip_6" "128"
243 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
244 proto_add_ipv6_route
"$gateway_6" "128"
245 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
246 [ "$peerdns" = 0 ] ||
{
247 proto_add_dns_server
"$dns1_6"
248 proto_add_dns_server
"$dns2_6"
250 proto_send_update
"$interface"
253 json_add_string name
"${interface}_6"
254 json_add_string ifname
"@$interface"
255 json_add_string proto
"dhcpv6"
256 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
257 proto_add_dynamic_defaults
258 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
259 json_add_string extendprefix
1
261 ubus call network add_dynamic
"$(json_dump)"
267 json_add_string name
"${interface}_4"
268 json_add_string ifname
"@$interface"
269 json_add_string proto
"dhcp"
270 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
271 proto_add_dynamic_defaults
273 ubus call network add_dynamic
"$(json_dump)"
281 [ -n "$cid" ] ||
return
283 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
284 --stop-network 0xffffffff \
285 --autoconnect > /dev
/null
2>&1
288 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
289 --stop-network "$pdh" > /dev
/null
2>&1
292 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
293 --release-client-id wds
> /dev
/null
2>&1
296 proto_qmi_teardown
() {
299 local device cid_4 pdh_4 cid_6 pdh_6
302 [ -n "$ctl_device" ] && device
=$ctl_device
304 echo "Stopping network $interface"
306 json_load
"$(ubus call network.interface.$interface status)"
308 json_get_vars cid_4 pdh_4 cid_6 pdh_6
310 qmi_wds_stop
"$cid_4" "$pdh_4"
311 qmi_wds_stop
"$cid_6" "$pdh_6"
313 proto_init_update
"*" 0
314 proto_send_update
"$interface"
317 [ -n "$INCLUDE_ONLY" ] ||
{