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 echo "Waiting for SIM initialization"
72 local uninitialized_timeout
=0
73 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
74 [ -e "$device" ] ||
return 1
78 [ -n "$pincode" ] && {
79 uqmi
-s -d "$device" --verify-pin1 "$pincode" > /dev
/null || uqmi
-s -d "$device" --uim-verify-pin1 "$pincode" > /dev
/null ||
{
80 echo "Unable to verify PIN"
81 proto_notify_error
"$interface" PIN_FAILED
82 proto_block_restart
"$interface"
89 if [ "$plmn" = 0 ]; then
92 echo "Setting PLMN to auto"
96 echo "Setting PLMN to $plmn"
98 uqmi
-s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" > /dev
/null
2>&1 ||
{
99 echo "Unable to set PLMN"
100 proto_notify_error
"$interface" PLMN_FAILED
101 proto_block_restart
"$interface"
106 # Cleanup current state if any
107 uqmi
-s -d "$device" --stop-network 0xffffffff --autoconnect > /dev
/null
2>&1
110 uqmi
-s -d "$device" --set-data-format 802.3 > /dev
/null
2>&1
111 uqmi
-s -d "$device" --wda-set-data-format 802.3 > /dev
/null
2>&1
112 dataformat
="$(uqmi -s -d "$device" --wda-get-data-format)"
114 if [ "$dataformat" = '"raw-ip"' ]; then
116 [ -f /sys
/class
/net
/$ifname/qmi
/raw_ip
] ||
{
117 echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip"
121 echo "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .."
122 echo "Y" > /sys
/class
/net
/$ifname/qmi
/raw_ip
125 uqmi
-s -d "$device" --sync > /dev
/null
2>&1
127 echo "Waiting for network registration"
128 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
129 [ -e "$device" ] ||
return 1
133 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes" > /dev
/null
2>&1
135 echo "Starting network $interface"
137 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
138 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
140 if [ "$pdptype" = "ip" ]; then
141 [ -z "$autoconnect" ] && autoconnect
=1
142 [ "$autoconnect" = 0 ] && autoconnect
=""
144 [ "$autoconnect" = 1 ] || autoconnect
=""
147 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
148 cid_4
=$
(uqmi
-s -d "$device" --get-client-id wds
)
149 if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev
/null
; then
150 echo "Unable to obtain client ID"
151 proto_notify_error
"$interface" NO_CID
155 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
2>&1
157 pdh_4
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
160 ${profile:+--profile $profile} \
161 ${auth:+--auth-type $auth} \
162 ${username:+--username $username} \
163 ${password:+--password $password} \
164 ${autoconnect:+--autoconnect})
166 # pdh_4 is a numeric value on success
167 if ! [ "$pdh_4" -eq "$pdh_4" ] 2> /dev
/null
; then
168 echo "Unable to connect IPv4"
169 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
170 proto_notify_error
"$interface" CALL_FAILED
174 # Check data connection state
175 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
176 [ "$connstat" == '"connected"' ] ||
{
178 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
> /dev
/null
2>&1
179 proto_notify_error
"$interface" CALL_FAILED
184 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
185 cid_6
=$
(uqmi
-s -d "$device" --get-client-id wds
)
186 if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev
/null
; then
187 echo "Unable to obtain client ID"
188 proto_notify_error
"$interface" NO_CID
192 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
2>&1
194 pdh_6
=$
(uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
197 ${profile:+--profile $profile} \
198 ${auth:+--auth-type $auth} \
199 ${username:+--username $username} \
200 ${password:+--password $password} \
201 ${autoconnect:+--autoconnect})
203 # pdh_6 is a numeric value on success
204 if ! [ "$pdh_6" -eq "$pdh_6" ] 2> /dev
/null
; then
205 echo "Unable to connect IPv6"
206 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
207 proto_notify_error
"$interface" CALL_FAILED
211 # Check data connection state
212 connstat
=$
(uqmi
-s -d "$device" --get-data-status)
213 [ "$connstat" == '"connected"' ] ||
{
215 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
> /dev
/null
2>&1
216 proto_notify_error
"$interface" CALL_FAILED
221 echo "Setting up $ifname"
222 proto_init_update
"$ifname" 1
226 json_add_string
"cid_4" "$cid_4"
227 json_add_string
"pdh_4" "$pdh_4"
230 json_add_string
"cid_6" "$cid_6"
231 json_add_string
"pdh_6" "$pdh_6"
234 proto_send_update
"$interface"
236 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
237 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
240 json_get_var gateway_6 gateway
241 json_get_var dns1_6 dns1
242 json_get_var dns2_6 dns2
243 json_get_var ip_prefix_length ip-prefix-length
245 proto_init_update
"$ifname" 1
247 proto_add_ipv6_address
"$ip_6" "128"
248 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
249 proto_add_ipv6_route
"$gateway_6" "128"
250 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
251 [ "$peerdns" = 0 ] ||
{
252 proto_add_dns_server
"$dns1_6"
253 proto_add_dns_server
"$dns2_6"
255 proto_send_update
"$interface"
258 json_add_string name
"${interface}_6"
259 json_add_string ifname
"@$interface"
260 json_add_string proto
"dhcpv6"
261 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
262 proto_add_dynamic_defaults
263 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
264 json_add_string extendprefix
1
266 ubus call network add_dynamic
"$(json_dump)"
272 json_add_string name
"${interface}_4"
273 json_add_string ifname
"@$interface"
274 json_add_string proto
"dhcp"
275 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
276 proto_add_dynamic_defaults
278 ubus call network add_dynamic
"$(json_dump)"
286 [ -n "$cid" ] ||
return
288 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
289 --stop-network 0xffffffff \
290 --autoconnect > /dev
/null
2>&1
293 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
294 --stop-network "$pdh" > /dev
/null
2>&1
297 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
298 --release-client-id wds
> /dev
/null
2>&1
301 proto_qmi_teardown
() {
304 local device cid_4 pdh_4 cid_6 pdh_6
307 [ -n "$ctl_device" ] && device
=$ctl_device
309 echo "Stopping network $interface"
311 json_load
"$(ubus call network.interface.$interface status)"
313 json_get_vars cid_4 pdh_4 cid_6 pdh_6
315 qmi_wds_stop
"$cid_4" "$pdh_4"
316 qmi_wds_stop
"$cid_6" "$pdh_6"
318 proto_init_update
"*" 0
319 proto_send_update
"$interface"
322 [ -n "$INCLUDE_ONLY" ] ||
{