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
27 local device apn auth username password pincode delay modes ipv6 dhcp
28 local cid_4 pdh_4 cid_6 pdh_6 ipv4
29 local ip subnet gateway dns1 dns2 ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
30 json_get_vars device apn auth username password pincode delay modes ipv6 dhcp
34 if [ "$ipv6" = 0 ]; then
40 [ -n "$ctl_device" ] && device
=$ctl_device
43 echo "No control device specified"
44 proto_notify_error
"$interface" NO_DEVICE
45 proto_set_available
"$interface" 0
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
71 [ -n "$pincode" ] && {
72 uqmi
-s -d "$device" --verify-pin1 "$pincode" ||
{
73 echo "Unable to verify PIN"
74 proto_notify_error
"$interface" PIN_FAILED
75 proto_block_restart
"$interface"
81 echo "No APN specified"
82 proto_notify_error
"$interface" NO_APN
86 uqmi
-s -d "$device" --set-data-format 802.3
87 uqmi
-s -d "$device" --wda-set-data-format 802.3
89 echo "Waiting for network registration"
90 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
94 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes"
96 echo "Starting network $apn"
98 cid_4
=`uqmi -s -d "$device" --get-client-id wds`
100 echo "Unable to obtain client ID"
101 proto_notify_error
"$interface" NO_CID
105 pdh_4
=`uqmi -s -d "$device" --set-client-id wds,"$cid_4" \
106 --start-network "$apn" \
107 ${auth:+--auth-type $auth} \
108 ${username:+--username $username} \
109 ${password:+--password $password} \
112 echo "Unable to connect IPv4"
113 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
118 cid_6
=`uqmi -s -d "$device" --get-client-id wds`
120 pdh_6
=`uqmi -s -d "$device" --set-client-id wds,"$cid_6" \
121 --start-network "$apn" \
122 ${auth:+--auth-type $auth} \
123 ${username:+--username $username} \
124 ${password:+--password $password} \
127 echo "Unable to connect IPv6"
128 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
132 echo "Unable to connect IPv6"
137 [ -z "$ipv4" -a -z "$ipv6" ] && {
138 echo "Unable to connect"
139 proto_notify_error
"$interface" CALL_FAILED
143 if [ -z "$dhcp" -o "$dhcp" = 0 ]; then
144 echo "Setting up $ifname"
146 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)"
148 json_get_vars ip subnet gateway dns1 dns2
150 proto_init_update
"$ifname" 1
152 proto_add_ipv4_address
"$ip" "$subnet"
153 proto_add_dns_server
"$dns1"
154 proto_add_dns_server
"$dns2"
155 proto_add_ipv4_route
"0.0.0.0" 0 "$gateway"
157 json_add_string
"cid_4" "$cid_4"
158 json_add_string
"pdh_4" "$pdh_4"
160 proto_send_update
"$interface"
164 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
167 json_get_var gateway_6 gateway
168 json_get_var dns1_6 dns1
169 json_get_var dns2_6 dns2
170 json_get_var ip_prefix_length ip-prefix-length
172 proto_init_update
"$ifname" 1
174 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
175 proto_add_ipv6_address
"$ip_6" "128"
176 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
177 proto_add_ipv6_route
"$gateway_6" "128"
178 proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
179 proto_add_dns_server
"$dns1_6"
180 proto_add_dns_server
"$dns2_6"
182 json_add_string
"cid_6" "$cid_6"
183 json_add_string
"pdh_6" "$pdh_6"
185 proto_send_update
"$interface"
188 echo "Starting DHCP on $ifname"
189 proto_init_update
"$ifname" 1
192 json_add_string
"cid_4" "$cid_4"
193 json_add_string
"pdh_4" "$pdh_4"
196 json_add_string
"cid_6" "$cid_6"
197 json_add_string
"pdh_6" "$pdh_6"
200 proto_send_update
"$interface"
204 json_add_string name
"${interface}_4"
205 json_add_string ifname
"@$interface"
206 json_add_string proto
"dhcp"
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 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
217 json_add_string extendprefix
1
219 ubus call network add_dynamic
"$(json_dump)"
224 proto_qmi_teardown
() {
227 local device cid_4 pdh_4 cid_6 pdh_6
230 [ -n "$ctl_device" ] && device
=$ctl_device
232 echo "Stopping network"
234 json_load
"$(ubus call network.interface.$interface status)"
236 json_get_vars cid_4 pdh_4 cid_6 pdh_6
240 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --stop-network "$pdh_4"
241 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
246 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --stop-network "$pdh_6"
247 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
251 proto_init_update
"*" 0
252 proto_send_update
"$interface"
255 [ -n "$INCLUDE_ONLY" ] ||
{