3 [ -n "$INCLUDE_ONLY" ] ||
{
10 proto_mbim_init_config
() {
13 proto_config_add_string
"device:device"
14 proto_config_add_string apn
15 proto_config_add_string pincode
16 proto_config_add_string delay
17 proto_config_add_boolean allow_roaming
18 proto_config_add_boolean allow_partner
19 proto_config_add_string auth
20 proto_config_add_string username
21 proto_config_add_string password
22 [ -e /proc
/sys
/net
/ipv6
] && proto_config_add_string ipv6
23 proto_config_add_boolean dhcp
24 proto_config_add_boolean dhcpv6
25 proto_config_add_string pdptype
26 proto_config_add_defaults
34 local device apn pincode delay auth username password allow_roaming allow_partner
35 local dhcp dhcpv6 pdptype ip4table ip6table
$PROTO_DEFAULT_OPTIONS
36 json_get_vars device apn pincode delay auth username password allow_roaming allow_partner
37 json_get_vars dhcp dhcpv6 pdptype ip4table ip6table
$PROTO_DEFAULT_OPTIONS
39 [ ! -e /proc
/sys
/net
/ipv6
] && ipv6
=0 || json_get_var ipv6 ipv6
41 [ -n "$ctl_device" ] && device
=$ctl_device
44 echo "mbim[$$]" "No control device specified"
45 proto_notify_error
"$interface" NO_DEVICE
46 proto_set_available
"$interface" 0
50 echo "mbim[$$]" "The specified control device does not exist"
51 proto_notify_error
"$interface" NO_DEVICE
52 proto_set_available
"$interface" 0
56 devname
="$(basename "$device")"
57 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
58 ifname
="$( ls "$devpath"/net )"
61 echo "mbim[$$]" "Failed to find matching interface"
62 proto_notify_error
"$interface" NO_IFNAME
63 proto_set_available
"$interface" 0
68 echo "mbim[$$]" "No APN specified"
69 proto_notify_error
"$interface" NO_APN
73 [ -n "$delay" ] && sleep "$delay"
75 echo "mbim[$$]" "Reading capabilities"
76 umbim
$DBG -n -d $device caps ||
{
77 echo "mbim[$$]" "Failed to read modem caps"
79 umbim
$DBG -t $tid -d "$device" disconnect
80 proto_notify_error
"$interface" PIN_FAILED
86 echo "mbim[$$]" "Sending pin"
87 umbim
$DBG -n -t $tid -d $device unlock
"$pincode" ||
{
88 echo "mbim[$$]" "Unable to verify PIN"
90 umbim
$DBG -t $tid -d "$device" disconnect
91 proto_notify_error
"$interface" PIN_FAILED
92 proto_block_restart
"$interface"
98 echo "mbim[$$]" "Checking pin"
99 umbim
$DBG -n -t $tid -d $device pinstate
101 echo "mbim[$$]" "PIN required"
103 umbim
$DBG -t $tid -d "$device" disconnect
104 proto_notify_error
"$interface" PIN_FAILED
105 proto_block_restart
"$interface"
110 echo "mbim[$$]" "Checking subscriber"
111 umbim
$DBG -n -t $tid -d $device subscriber ||
{
112 echo "mbim[$$]" "Subscriber init failed"
114 umbim
$DBG -t $tid -d "$device" disconnect
115 proto_notify_error
"$interface" NO_SUBSCRIBER
120 echo "mbim[$$]" "Register with network"
122 umbim
$DBG -n -t $tid -d $device registration
125 0) echo "mbim[$$]" "Registered in home mode"
128 4) if [ "$allow_roaming" = "1" ]; then
129 echo "mbim[$$]" "Registered in roaming mode"
133 5) if [ "$allow_partner" = "1" ]; then
134 echo "mbim[$$]" "Registered in partner mode"
139 if [ $connected -ne 1 ]; then
140 echo "mbim[$$]" "Subscriber registration failed (code $reg_status)"
142 umbim
$DBG -t $tid -d "$device" disconnect
143 proto_notify_error
"$interface" NO_REGISTRATION
147 echo "mbim[$$]" "Attach to network"
148 umbim
$DBG -n -t $tid -d $device attach ||
{
149 echo "mbim[$$]" "Failed to attach to network"
151 umbim
$DBG -t $tid -d "$device" disconnect
152 proto_notify_error
"$interface" ATTACH_FAILED
157 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
158 [ "$ipv6" = 0 ] && pdptype
="ipv4"
160 local req_pdptype
="" # Pass "default" PDP type to umbim if unconfigured
161 [ "$pdptype" = "ipv4" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && req_pdptype
="$pdptype:"
164 echo "mbim[$$]" "Connect to network"
165 connect_state
=$
(umbim
$DBG -n -t $tid -d $device connect
"$req_pdptype$apn" "$auth" "$username" "$password") ||
{
166 echo "mbim[$$]" "Failed to connect bearer"
168 umbim
$DBG -t $tid -d "$device" disconnect
169 proto_notify_error
"$interface" CONNECT_FAILED
174 echo "$connect_state"
175 local iptype
="$(echo "$connect_state" | grep iptype: | awk '{print $4}')"
177 echo "mbim[$$]" "Connected"
179 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
181 echo "mbim[$$]" "Setting up $ifname"
182 eval $
(umbim
$DBG -n -t $tid -d $device config |
sed 's/: /=/g')
185 proto_init_update
"$ifname" 1
186 proto_send_update
"$interface"
188 [ -z "$dhcp" ] && dhcp
=1
189 [ -z "$dhcpv6" ] && dhcpv6
=1
191 [ "$iptype" != "ipv6" ] && {
192 if [ -n "$ipv4address" ]; then
194 json_add_string name
"${interface}_4"
195 json_add_string ifname
"@$interface"
196 json_add_string proto
"static"
197 json_add_array ipaddr
198 json_add_string
"" "$ipv4address"
200 json_add_string gateway
"$ipv4gateway"
202 [ "$peerdns" = 0 ] || json_add_string
"" "$ipv4dnsserver"
204 proto_add_dynamic_defaults
205 [ -n "$zone" ] && json_add_string zone
"$zone"
206 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
208 ubus call network add_dynamic
"$(json_dump)"
209 elif [ "$dhcp" != 0 ]; then
210 echo "mbim[$$]" "Starting DHCP on $ifname"
212 json_add_string name
"${interface}_4"
213 json_add_string ifname
"@$interface"
214 json_add_string proto
"dhcp"
215 proto_add_dynamic_defaults
216 [ -n "$zone" ] && json_add_string zone
"$zone"
217 [ -n "$ip4table" ] && json_add_string ip4table
"$ip4table"
219 ubus call network add_dynamic
"$(json_dump)"
223 [ "$iptype" != "ipv4" ] && {
224 if [ -n "$ipv6address" ]; then
226 json_add_string name
"${interface}_6"
227 json_add_string ifname
"@$interface"
228 json_add_string proto
"static"
229 json_add_array ip6addr
230 json_add_string
"" "$ipv6address"
232 json_add_string ip6gw
"$ipv6gateway"
234 [ "$peerdns" = 0 ] || json_add_string
"" "$ipv6dnsserver"
236 proto_add_dynamic_defaults
237 [ -n "$zone" ] && json_add_string zone
"$zone"
238 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
240 ubus call network add_dynamic
"$(json_dump)"
241 elif [ "$dhcpv6" != 0 ]; then
242 echo "mbim[$$]" "Starting DHCPv6 on $ifname"
244 json_add_string name
"${interface}_6"
245 json_add_string ifname
"@$interface"
246 json_add_string proto
"dhcpv6"
247 json_add_string extendprefix
1
248 proto_add_dynamic_defaults
249 [ -n "$zone" ] && json_add_string zone
"$zone"
250 [ -n "$ip6table" ] && json_add_string ip6table
"$ip6table"
252 ubus call network add_dynamic
"$(json_dump)"
256 uci_set_state network
$interface tid
"$tid"
266 logger
"mbim bringup failed, retry in 15s"
273 proto_mbim_teardown
() {
278 local tid
=$
(uci_get_state network
$interface tid
)
280 [ -n "$ctl_device" ] && device
=$ctl_device
282 echo "mbim[$$]" "Stopping network"
284 umbim
$DBG -t $tid -d "$device" disconnect
285 uci_revert_state network
$interface tid
288 proto_init_update
"*" 0
289 proto_send_update
"$interface"
292 [ -n "$INCLUDE_ONLY" ] || add_protocol mbim