7 proto_qmi_init_config() {
10 proto_config_add_string "device:device"
11 proto_config_add_string apn
12 proto_config_add_string auth
13 proto_config_add_string username
14 proto_config_add_string password
15 proto_config_add_string pincode
16 proto_config_add_string delay
17 proto_config_add_string modes
21 # disable previous autoconnect state using the global handle
22 # do not reuse previous wds client id to prevent hangs caused by stale data
23 uqmi -s -d "$device" \
24 --stop-network 0xffffffff \
25 --autoconnect > /dev/null
31 local device apn auth username password pincode delay modes cid pdh
32 json_get_vars device apn auth username password pincode delay modes
35 echo "No control device specified"
36 proto_notify_error "$interface" NO_DEVICE
37 proto_block_restart "$interface"
41 echo "The specified control device does not exist"
42 proto_notify_error "$interface" NO_DEVICE
43 proto_block_restart "$interface"
47 devname="$(basename "$device")"
48 devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
49 ifname="$( ls "$devpath"/net )"
51 echo "The interface could not be found."
52 proto_notify_error "$interface" NO_IFACE
53 proto_block_restart "$interface"
57 [ -n "$delay" ] && sleep "$delay"
59 while uqmi -s -d "$device" --get-pin-status | grep '"UIM uninitialized"' > /dev/null; do
63 [ -n "$pincode" ] && {
64 uqmi -s -d "$device" --verify-pin1 "$pincode" || {
65 echo "Unable to verify PIN"
66 proto_notify_error "$interface" PIN_FAILED
67 proto_block_restart "$interface"
73 echo "No APN specified"
74 proto_notify_error "$interface" NO_APN
75 proto_block_restart "$interface"
81 echo "Waiting for network registration"
82 while uqmi -s -d "$device" --get-serving-system | grep '"searching"' > /dev/null; do
86 [ -n "$modes" ] && uqmi -s -d "$device" --set-network-modes "$modes"
88 echo "Starting network $apn"
89 cid=`uqmi -s -d "$device" --get-client-id wds`
91 echo "Unable to obtain client ID"
92 proto_notify_error "$interface" NO_CID
93 proto_block_restart "$interface"
97 uqmi -s -d "$device" --set-client-id wds,"$cid" \
98 --start-network "$apn" \
99 ${auth:+--auth-type $auth} \
100 ${username:+--username $username} \
101 ${password:+--password $password} \
102 --autoconnect > /dev/null
104 if ! uqmi -s -d "$device" --get-data-status | grep '"connected"' > /dev/null; then
105 echo "Connection lost"
106 proto_notify_error "$interface" NOT_CONNECTED
110 echo "Connected, starting DHCP"
111 proto_init_update "$ifname" 1
112 proto_send_update "$interface"
115 json_add_string name "${interface}_dhcp"
116 json_add_string ifname "@$interface"
117 json_add_string proto "dhcp"
119 ubus call network add_dynamic "$(json_dump)"
122 json_add_string name "${interface}_dhcpv6"
123 json_add_string ifname "@$interface"
124 json_add_string proto "dhcpv6"
126 ubus call network add_dynamic "$(json_dump)"
129 proto_qmi_teardown() {
134 local cid=$(uci_get_state network $interface cid)
136 echo "Stopping network"
139 uqmi -s -d "$device" --set-client-id wds,"$cid" --release-client-id wds
140 uci_revert_state network $interface cid
143 proto_init_update "*" 0
144 proto_send_update "$interface"