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_string delay
19 proto_config_add_string modes
20 proto_config_add_boolean ipv6
21 proto_config_add_boolean dhcp
22 proto_config_add_int metric
28 local device apn auth username password pincode delay modes ipv6 dhcp metric
29 local cid_4 pdh_4 cid_6 pdh_6 ipv4
30 local ip subnet gateway dns1 dns2 ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
31 json_get_vars device apn auth username password pincode delay modes ipv6 dhcp metric
35 [ "$ipv6" = 1 ] || ipv6
=""
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 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"
80 echo "No APN specified"
81 proto_notify_error
"$interface" NO_APN
85 uqmi
-s -d "$device" --set-data-format 802.3
86 uqmi
-s -d "$device" --wda-set-data-format 802.3
88 echo "Waiting for network registration"
89 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
93 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes"
95 echo "Starting network $apn"
97 cid_4
=`uqmi -s -d "$device" --get-client-id wds`
99 echo "Unable to obtain client ID"
100 proto_notify_error
"$interface" NO_CID
104 pdh_4
=`uqmi -s -d "$device" --set-client-id wds,"$cid_4" \
105 --start-network "$apn" \
106 ${auth:+--auth-type $auth} \
107 ${username:+--username $username} \
108 ${password:+--password $password} \
111 echo "Unable to connect IPv4"
112 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
117 cid_6
=`uqmi -s -d "$device" --get-client-id wds`
119 pdh_6
=`uqmi -s -d "$device" --set-client-id wds,"$cid_6" \
120 --start-network "$apn" \
121 ${auth:+--auth-type $auth} \
122 ${username:+--username $username} \
123 ${password:+--password $password} \
126 echo "Unable to connect IPv6"
127 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
131 echo "Unable to connect IPv6"
136 [ -z "$ipv4" -a -z "$ipv6" ] && {
137 echo "Unable to connect"
138 proto_notify_error
"$interface" CALL_FAILED
142 if [ -z "$dhcp" -o "$dhcp" = 0 ]; then
143 echo "Setting up $ifname"
145 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)"
147 json_get_vars ip subnet gateway dns1 dns2
149 proto_init_update
"$ifname" 1
151 proto_add_ipv4_address
"$ip" "$subnet"
152 proto_add_dns_server
"$dns1"
153 proto_add_dns_server
"$dns2"
154 proto_add_ipv4_route
"0.0.0.0" 0 "$gateway"
156 json_add_string
"cid_4" "$cid_4"
157 json_add_string
"pdh_4" "$pdh_4"
159 proto_send_update
"$interface"
163 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
166 json_get_var gateway_6 gateway
167 json_get_var dns1_6 dns1
168 json_get_var dns2_6 dns2
169 json_get_var ip_prefix_length ip-prefix-length
171 proto_init_update
"$ifname" 1
173 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
174 proto_add_ipv6_address
"$ip_6" "128"
175 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
176 proto_add_ipv6_route
"$gateway_6" "128"
177 proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
178 proto_add_dns_server
"$dns1_6"
179 proto_add_dns_server
"$dns2_6"
181 json_add_string
"cid_6" "$cid_6"
182 json_add_string
"pdh_6" "$pdh_6"
184 proto_send_update
"$interface"
187 echo "Starting DHCP on $ifname"
188 proto_init_update
"$ifname" 1
191 json_add_string
"cid_4" "$cid_4"
192 json_add_string
"pdh_4" "$pdh_4"
195 json_add_string
"cid_6" "$cid_6"
196 json_add_string
"pdh_6" "$pdh_6"
199 proto_send_update
"$interface"
203 json_add_string name
"${interface}_4"
204 json_add_string ifname
"@$interface"
205 json_add_string proto
"dhcp"
206 json_add_int metric
"$metric"
208 ubus call network add_dynamic
"$(json_dump)"
213 json_add_string name
"${interface}_6"
214 json_add_string ifname
"@$interface"
215 json_add_string proto
"dhcpv6"
216 json_add_int metric
"$metric"
217 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
218 json_add_string extendprefix
1
220 ubus call network add_dynamic
"$(json_dump)"
225 proto_qmi_teardown
() {
228 local device cid_4 pdh_4 cid_6 pdh_6
231 [ -n "$ctl_device" ] && device
=$ctl_device
233 echo "Stopping network"
235 json_load
"$(ubus call network.interface.$interface status)"
237 json_get_vars cid_4 pdh_4 cid_6 pdh_6
241 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --stop-network "$pdh_4"
242 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
247 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --stop-network "$pdh_6"
248 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
252 proto_init_update
"*" 0
253 proto_send_update
"$interface"
256 [ -n "$INCLUDE_ONLY" ] ||
{