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 [ "$ipv6" = 1 ] || ipv6
=""
36 [ -n "$ctl_device" ] && device
=$ctl_device
39 echo "No control device specified"
40 proto_notify_error
"$interface" NO_DEVICE
41 proto_set_available
"$interface" 0
45 echo "The specified control device does not exist"
46 proto_notify_error
"$interface" NO_DEVICE
47 proto_set_available
"$interface" 0
51 devname
="$(basename "$device")"
52 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
53 ifname
="$( ls "$devpath"/net )"
55 echo "The interface could not be found."
56 proto_notify_error
"$interface" NO_IFACE
57 proto_set_available
"$interface" 0
61 [ -n "$delay" ] && sleep "$delay"
63 while uqmi
-s -d "$device" --get-pin-status |
grep '"UIM uninitialized"' > /dev
/null
; do
67 [ -n "$pincode" ] && {
68 uqmi
-s -d "$device" --verify-pin1 "$pincode" ||
{
69 echo "Unable to verify PIN"
70 proto_notify_error
"$interface" PIN_FAILED
71 proto_block_restart
"$interface"
77 echo "No APN specified"
78 proto_notify_error
"$interface" NO_APN
82 uqmi
-s -d "$device" --set-data-format 802.3
83 uqmi
-s -d "$device" --wda-set-data-format 802.3
85 echo "Waiting for network registration"
86 while uqmi
-s -d "$device" --get-serving-system |
grep '"searching"' > /dev
/null
; do
90 [ -n "$modes" ] && uqmi
-s -d "$device" --set-network-modes "$modes"
92 echo "Starting network $apn"
94 cid_4
=`uqmi -s -d "$device" --get-client-id wds`
96 echo "Unable to obtain client ID"
97 proto_notify_error
"$interface" NO_CID
101 pdh_4
=`uqmi -s -d "$device" --set-client-id wds,"$cid_4" \
102 --start-network "$apn" \
103 ${auth:+--auth-type $auth} \
104 ${username:+--username $username} \
105 ${password:+--password $password} \
108 echo "Unable to connect IPv4"
109 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
114 cid_6
=`uqmi -s -d "$device" --get-client-id wds`
116 pdh_6
=`uqmi -s -d "$device" --set-client-id wds,"$cid_6" \
117 --start-network "$apn" \
118 ${auth:+--auth-type $auth} \
119 ${username:+--username $username} \
120 ${password:+--password $password} \
123 echo "Unable to connect IPv6"
124 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
128 echo "Unable to connect IPv6"
133 [ -z "$ipv4" -a -z "$ipv6" ] && {
134 echo "Unable to connect"
135 proto_notify_error
"$interface" CALL_FAILED
139 if [ -z "$dhcp" -o "$dhcp" = 0 ]; then
140 echo "Setting up $ifname"
142 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)"
144 json_get_vars ip subnet gateway dns1 dns2
146 proto_init_update
"$ifname" 1
148 proto_add_ipv4_address
"$ip" "$subnet"
149 proto_add_dns_server
"$dns1"
150 proto_add_dns_server
"$dns2"
151 proto_add_ipv4_route
"0.0.0.0" 0 "$gateway"
153 json_add_string
"cid_4" "$cid_4"
154 json_add_string
"pdh_4" "$pdh_4"
156 proto_send_update
"$interface"
160 json_load
"$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
163 json_get_var gateway_6 gateway
164 json_get_var dns1_6 dns1
165 json_get_var dns2_6 dns2
166 json_get_var ip_prefix_length ip-prefix-length
168 proto_init_update
"$ifname" 1
170 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
171 proto_add_ipv6_address
"$ip_6" "128"
172 proto_add_ipv6_prefix
"${ip_6}/${ip_prefix_length}"
173 proto_add_ipv6_route
"$gateway_6" "128"
174 proto_add_ipv6_route
"::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
175 proto_add_dns_server
"$dns1_6"
176 proto_add_dns_server
"$dns2_6"
178 json_add_string
"cid_6" "$cid_6"
179 json_add_string
"pdh_6" "$pdh_6"
181 proto_send_update
"$interface"
184 echo "Starting DHCP on $ifname"
185 proto_init_update
"$ifname" 1
188 json_add_string
"cid_4" "$cid_4"
189 json_add_string
"pdh_4" "$pdh_4"
192 json_add_string
"cid_6" "$cid_6"
193 json_add_string
"pdh_6" "$pdh_6"
196 proto_send_update
"$interface"
200 json_add_string name
"${interface}_4"
201 json_add_string ifname
"@$interface"
202 json_add_string proto
"dhcp"
204 ubus call network add_dynamic
"$(json_dump)"
209 json_add_string name
"${interface}_6"
210 json_add_string ifname
"@$interface"
211 json_add_string proto
"dhcpv6"
212 # RFC 7278: Extend an IPv6 /64 Prefix to LAN
213 json_add_string extendprefix
1
215 ubus call network add_dynamic
"$(json_dump)"
220 proto_qmi_teardown
() {
223 local device cid_4 pdh_4 cid_6 pdh_6
226 [ -n "$ctl_device" ] && device
=$ctl_device
228 echo "Stopping network"
230 json_load
"$(ubus call network.interface.$interface status)"
232 json_get_vars cid_4 pdh_4 cid_6 pdh_6
236 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --stop-network "$pdh_4"
237 uqmi
-s -d "$device" --set-client-id wds
,"$cid_4" --release-client-id wds
242 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --stop-network "$pdh_6"
243 uqmi
-s -d "$device" --set-client-id wds
,"$cid_6" --release-client-id wds
247 proto_init_update
"*" 0
248 proto_send_update
"$interface"
251 [ -n "$INCLUDE_ONLY" ] ||
{