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 device
="$(readlink -f $device)"
48 echo "The specified control device does not exist"
49 proto_notify_error
"$interface" NO_DEVICE
50 proto_set_available
"$interface" 0
54 devname
="$(basename "$device")"
55 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
56 ifname
="$( ls "$devpath"/net )"
58 echo "The interface could not be found."
59 proto_notify_error
"$interface" NO_IFACE
60 proto_set_available
"$interface" 0
64 [ -n "$delay" ] && sleep "$delay"
66 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
70 [ -n "$pincode" ] && {
71 uqmi
-s -d "$device" --verify-pin1 "$pincode" ||
{
72 echo "Unable to verify PIN"
73 proto_notify_error
"$interface" PIN_FAILED
74 proto_block_restart
"$interface"
79 uqmi
-s -d "$device" --set-data-format 802.3
80 uqmi
-s -d "$device" --wda-set-data-format 802.3
81 uqmi
-s -d "$device" --sync
83 echo "Waiting for network registration"
84 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
88 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes"
90 echo "Starting network $interface"
92 pdptype
=`echo "$pdptype" | awk '{print tolower($0)}'`
93 [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ip"
95 if [ "$pdptype" = "ip" ]; then
96 [ -z "$autoconnect" ] && autoconnect
=1
97 [ "$autoconnect" = 0 ] && autoconnect
=""
99 [ "$autoconnect" = 1 ] || autoconnect
=""
102 [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && {
103 cid_4
=`uqmi -s -d "$device" --get-client-id wds`
105 echo "Unable to obtain client ID"
106 proto_notify_error
"$interface" NO_CID
110 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --set-ip-family ipv4
> /dev
/null
112 # try to clear previous autoconnect state
113 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" \
114 --stop-network 0xffffffff \
115 --autoconnect > /dev
/null
117 pdh_4
=`uqmi -s -d "$device" --set-client-id wds,"$cid_4" \
120 ${profile:+--profile $profile} \
121 ${auth:+--auth-type $auth} \
122 ${username:+--username $username} \
123 ${password:+--password $password} \
124 ${autoconnect:+--autoconnect}`
126 echo "Unable to connect IPv4"
127 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
128 proto_notify_error
"$interface" CALL_FAILED
133 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
134 cid_6
=`uqmi -s -d "$device" --get-client-id wds`
136 echo "Unable to obtain client ID"
137 proto_notify_error
"$interface" NO_CID
141 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --set-ip-family ipv6
> /dev
/null
143 # try to clear previous autoconnect state
144 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" \
145 --stop-network 0xffffffff \
146 --autoconnect > /dev
/null
148 pdh_6
=`uqmi -s -d "$device" --set-client-id wds,"$cid_6" \
151 ${profile:+--profile $profile} \
152 ${auth:+--auth-type $auth} \
153 ${username:+--username $username} \
154 ${password:+--password $password} \
155 ${autoconnect:+--autoconnect}`
157 echo "Unable to connect IPv6"
158 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
159 proto_notify_error
"$interface" CALL_FAILED
164 echo "Setting up $ifname"
165 proto_init_update
"$ifname" 1
169 json_add_string
"cid_4" "$cid_4"
170 json_add_string
"pdh_4" "$pdh_4"
173 json_add_string
"cid_6" "$cid_6"
174 json_add_string
"pdh_6" "$pdh_6"
177 proto_send_update
"$interface"
179 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
180 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
183 json_get_var gateway_6 gateway
184 json_get_var dns1_6 dns1
185 json_get_var dns2_6 dns2
186 json_get_var ip_prefix_length ip-prefix-length
188 proto_init_update
"$ifname" 1
190 proto_add_ipv6_address
"$ip_6" "128"
191 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
192 proto_add_ipv6_route
"$gateway_6" "128"
193 [ "$defaultroute" = 0 ] || proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
194 [ "$peerdns" = 0 ] ||
{
195 proto_add_dns_server
"$dns1_6"
196 proto_add_dns_server
"$dns2_6"
198 proto_send_update
"$interface"
201 json_add_string name
"${interface}_6"
202 json_add_string ifname
"@$interface"
203 json_add_string proto
"dhcpv6"
204 proto_add_dynamic_defaults
205 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
206 json_add_string extendprefix
1
208 ubus call network add_dynamic
"$(json_dump)"
214 json_add_string name
"${interface}_4"
215 json_add_string ifname
"@$interface"
216 json_add_string proto
"dhcp"
217 proto_add_dynamic_defaults
219 ubus call network add_dynamic
"$(json_dump)"
227 [ -n "$cid" ] ||
return
229 uqmi
-s -d "$device" --set-client-id wds
,"$cid" \
230 --stop-network 0xffffffff \
231 --autoconnect > /dev
/null
233 [ -n "$pdh" ] && uqmi
-s -d "$device" --set-client-id wds
,"$cid" --stop-network "$pdh"
234 uqmi
-s -d "$device" --set-client-id wds
,"$cid" --release-client-id wds
237 proto_qmi_teardown
() {
240 local device cid_4 pdh_4 cid_6 pdh_6
243 [ -n "$ctl_device" ] && device
=$ctl_device
245 echo "Stopping network $interface"
247 json_load
"$(ubus call network.interface.$interface status)"
249 json_get_vars cid_4 pdh_4 cid_6 pdh_6
251 qmi_wds_stop
"$cid_4" "$pdh_4"
252 qmi_wds_stop
"$cid_6" "$pdh_6"
254 proto_init_update
"*" 0
255 proto_send_update
"$interface"
258 [ -n "$INCLUDE_ONLY" ] ||
{