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
31 local device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn
$PROTO_DEFAULT_OPTIONS
32 local cid_4 pdh_4 cid_6 pdh_6
33 local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
34 json_get_vars device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn
$PROTO_DEFAULT_OPTIONS
36 [ "$metric" = "" ] && metric
="0"
38 [ -n "$ctl_device" ] && device
=$ctl_device
41 echo "No control device specified"
42 proto_notify_error
"$interface" NO_DEVICE
43 proto_set_available
"$interface" 0
47 device
="$(readlink -f $device)"
49 echo "The specified control device does not exist"
50 proto_notify_error
"$interface" NO_DEVICE
51 proto_set_available
"$interface" 0
55 devname
="$(basename "$device")"
56 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
57 ifname
="$( ls "$devpath"/net )"
59 echo "The interface could not be found."
60 proto_notify_error
"$interface" NO_IFACE
61 proto_set_available
"$interface" 0
65 [ -n "$delay" ] && sleep "$delay"
67 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
68 [ -e "$device" ] ||
return 1
72 [ -n "$pincode" ] && {
73 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null ||
{
74 echo "Unable to verify PIN"
75 proto_notify_error
"$interface" PIN_FAILED
76 proto_block_restart
"$interface"
83 if [ "$plmn" = 0 ]; then
86 echo "Setting PLMN to auto"
90 echo "Setting PLMN to $plmn"
92 uqmi
-s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" ||
{
93 echo "Unable to set PLMN"
94 proto_notify_error
"$interface" PLMN_FAILED
95 proto_block_restart
"$interface"
100 uqmi
-s -d "$device" --set-data-format 802.3
101 uqmi
-s -d "$device" --wda-set-data-format 802.3
102 dataformat
="$(uqmi -s -d "$device" --wda-get-data-format)"
104 if [ "$dataformat" = '"raw-ip"' ]; then
106 [ -f /sys
/class
/net
/$ifname/qmi
/raw_ip
] ||
{
107 echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip"
111 echo "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .."
112 echo "Y" > /sys
/class
/net
/$ifname/qmi
/raw_ip
115 uqmi
-s -d "$device" --sync
117 echo "Waiting for network registration"
118 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
119 [ -e "$device" ] ||
return 1
123 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes"
125 echo "Starting network $interface"
127 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
128 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
130 if [ "$pdptype" = "ip" ]; then
131 [ -z "$autoconnect" ] && autoconnect
=1
132 [ "$autoconnect" = 0 ] && autoconnect
=""
134 [ "$autoconnect" = 1 ] || autoconnect
=""
137 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
138 cid_4
=$
(uqmi
-s -d "$device" --get-client-id wds
)
140 echo "Unable to obtain client ID"
141 proto_notify_error
"$interface" NO_CID
145 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
147 # try to clear previous autoconnect state
148 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
149 --stop-network 0xffffffff \
150 --autoconnect > /dev
/null
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 echo "Unable to connect IPv4"
162 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
163 proto_notify_error
"$interface" CALL_FAILED
168 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
169 cid_6
=$
(uqmi
-s -d "$device" --get-client-id wds
)
171 echo "Unable to obtain client ID"
172 proto_notify_error
"$interface" NO_CID
176 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
178 # try to clear previous autoconnect state
179 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
180 --stop-network 0xffffffff \
181 --autoconnect > /dev
/null
183 pdh_6
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
186 ${profile:+--profile $profile} \
187 ${auth:+--auth-type $auth} \
188 ${username:+--username $username} \
189 ${password:+--password $password} \
190 ${autoconnect:+--autoconnect})
192 echo "Unable to connect IPv6"
193 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
194 proto_notify_error
"$interface" CALL_FAILED
199 echo "Setting up $ifname"
200 proto_init_update
"$ifname" 1
204 json_add_string
"cid_4" "$cid_4"
205 json_add_string
"pdh_4" "$pdh_4"
208 json_add_string
"cid_6" "$cid_6"
209 json_add_string
"pdh_6" "$pdh_6"
212 proto_send_update
"$interface"
214 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
215 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
218 json_get_var gateway_6 gateway
219 json_get_var dns1_6 dns1
220 json_get_var dns2_6 dns2
221 json_get_var ip_prefix_length ip-prefix-length
223 proto_init_update
"$ifname" 1
225 proto_add_ipv6_address
"$ip_6" "128"
226 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
227 proto_add_ipv6_route
"$gateway_6" "128"
228 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
229 [ "$peerdns" = 0 ] ||
{
230 proto_add_dns_server
"$dns1_6"
231 proto_add_dns_server
"$dns2_6"
233 proto_send_update
"$interface"
236 json_add_string name
"${interface}_6"
237 json_add_string ifname
"@$interface"
238 json_add_string proto
"dhcpv6"
239 proto_add_dynamic_defaults
240 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
241 json_add_string extendprefix
1
243 ubus call network add_dynamic
"$(json_dump)"
249 json_add_string name
"${interface}_4"
250 json_add_string ifname
"@$interface"
251 json_add_string proto
"dhcp"
252 proto_add_dynamic_defaults
254 ubus call network add_dynamic
"$(json_dump)"
262 [ -n "$cid" ] ||
return
264 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
265 --stop-network 0xffffffff \
266 --autoconnect > /dev
/null
268 [ -n "$pdh" ] && uqmi
-s -d "$device" --set-client-id wds
,"$cid" --stop-network "$pdh"
269 uqmi
-s -d "$device" --set-client-id wds
,"$cid" --release-client-id wds
272 proto_qmi_teardown
() {
275 local device cid_4 pdh_4 cid_6 pdh_6
278 [ -n "$ctl_device" ] && device
=$ctl_device
280 echo "Stopping network $interface"
282 json_load
"$(ubus call network.interface.$interface status)"
284 json_get_vars cid_4 pdh_4 cid_6 pdh_6
286 qmi_wds_stop
"$cid_4" "$pdh_4"
287 qmi_wds_stop
"$cid_6" "$pdh_6"
289 proto_init_update
"*" 0
290 proto_send_update
"$interface"
293 [ -n "$INCLUDE_ONLY" ] ||
{