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_defaults
30 local device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect
$PROTO_DEFAULT_OPTIONS
31 local cid_4 pdh_4 cid_6 pdh_6
32 local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
33 json_get_vars device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect
$PROTO_DEFAULT_OPTIONS
35 [ "$metric" = "" ] && metric
="0"
37 [ -n "$ctl_device" ] && device
=$ctl_device
40 echo "No control device specified"
41 proto_notify_error
"$interface" NO_DEVICE
42 proto_set_available
"$interface" 0
46 echo "The specified control device does not exist"
47 proto_notify_error
"$interface" NO_DEVICE
48 proto_set_available
"$interface" 0
52 devname
="$(basename "$device")"
53 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
54 ifname
="$( ls "$devpath"/net )"
56 echo "The interface could not be found."
57 proto_notify_error
"$interface" NO_IFACE
58 proto_set_available
"$interface" 0
62 [ -n "$delay" ] && sleep "$delay"
64 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
68 [ -n "$pincode" ] && {
69 uqmi
-s -d "$device" --verify-pin1 "$pincode" ||
{
70 echo "Unable to verify PIN"
71 proto_notify_error
"$interface" PIN_FAILED
72 proto_block_restart
"$interface"
77 uqmi
-s -d "$device" --set-data-format 802.3
78 uqmi
-s -d "$device" --wda-set-data-format 802.3
80 echo "Waiting for network registration"
81 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
85 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes"
87 echo "Starting network $interface"
89 pdptype
=`echo "$pdptype" | awk '{print tolower($0)}'`
90 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
92 if [ "$pdptype" = "ip" ]; then
93 [ -z "$autoconnect" ] && autoconnect
=1
94 [ "$autoconnect" = 0 ] && autoconnect
=""
96 [ "$autoconnect" = 1 ] || autoconnect
=""
99 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
100 cid_4
=`uqmi -s -d "$device" --get-client-id wds`
102 echo "Unable to obtain client ID"
103 proto_notify_error
"$interface" NO_CID
107 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
109 # try to clear previous autoconnect state
110 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
111 --stop-network 0xffffffff \
112 --autoconnect > /dev
/null
114 pdh_4
=`uqmi -s -d "$device" --set-client-id wds,"$cid_4" \
117 ${profile:+--profile $profile} \
118 ${auth:+--auth-type $auth} \
119 ${username:+--username $username} \
120 ${password:+--password $password} \
121 ${autoconnect:+--autoconnect}`
123 echo "Unable to connect IPv4"
124 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
125 proto_notify_error
"$interface" CALL_FAILED
130 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
131 cid_6
=`uqmi -s -d "$device" --get-client-id wds`
133 echo "Unable to obtain client ID"
134 proto_notify_error
"$interface" NO_CID
138 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
140 # try to clear previous autoconnect state
141 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
142 --stop-network 0xffffffff \
143 --autoconnect > /dev
/null
145 pdh_6
=`uqmi -s -d "$device" --set-client-id wds,"$cid_6" \
148 ${profile:+--profile $profile} \
149 ${auth:+--auth-type $auth} \
150 ${username:+--username $username} \
151 ${password:+--password $password} \
152 ${autoconnect:+--autoconnect}`
154 echo "Unable to connect IPv6"
155 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
156 proto_notify_error
"$interface" CALL_FAILED
161 echo "Setting up $ifname"
162 proto_init_update
"$ifname" 1
166 json_add_string
"cid_4" "$cid_4"
167 json_add_string
"pdh_4" "$pdh_4"
170 json_add_string
"cid_6" "$cid_6"
171 json_add_string
"pdh_6" "$pdh_6"
174 proto_send_update
"$interface"
176 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
177 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
180 json_get_var gateway_6 gateway
181 json_get_var dns1_6 dns1
182 json_get_var dns2_6 dns2
183 json_get_var ip_prefix_length ip-prefix-length
185 proto_init_update
"$ifname" 1
187 proto_add_ipv6_address
"$ip_6" "128"
188 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
189 proto_add_ipv6_route
"$gateway_6" "128"
190 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
191 [ "$peerdns" = 0 ] ||
{
192 proto_add_dns_server
"$dns1_6"
193 proto_add_dns_server
"$dns2_6"
195 proto_send_update
"$interface"
198 json_add_string name
"${interface}_6"
199 json_add_string ifname
"@$interface"
200 json_add_string proto
"dhcpv6"
201 proto_add_dynamic_defaults
202 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
203 json_add_string extendprefix
1
205 ubus call network add_dynamic
"$(json_dump)"
211 json_add_string name
"${interface}_4"
212 json_add_string ifname
"@$interface"
213 json_add_string proto
"dhcp"
214 proto_add_dynamic_defaults
216 ubus call network add_dynamic
"$(json_dump)"
224 [ -n "$cid" ] ||
return
226 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
227 --stop-network 0xffffffff \
228 --autoconnect > /dev
/null
230 [ -n "$pdh" ] && uqmi
-s -d "$device" --set-client-id wds
,"$cid" --stop-network "$pdh"
231 uqmi
-s -d "$device" --set-client-id wds
,"$cid" --release-client-id wds
234 proto_qmi_teardown
() {
237 local device cid_4 pdh_4 cid_6 pdh_6
240 [ -n "$ctl_device" ] && device
=$ctl_device
242 echo "Stopping network $interface"
244 json_load
"$(ubus call network.interface.$interface status)"
246 json_get_vars cid_4 pdh_4 cid_6 pdh_6
248 qmi_wds_stop
"$cid_4" "$pdh_4"
249 qmi_wds_stop
"$cid_6" "$pdh_6"
251 proto_init_update
"*" 0
252 proto_send_update
"$interface"
255 [ -n "$INCLUDE_ONLY" ] ||
{