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 proto_config_add_boolean dhcp
23 proto_config_add_boolean dhcpv6
24 proto_config_add_string pdptype
25 proto_config_add_defaults
33 local device apn pincode delay allow_roaming allow_partner dhcp dhcpv6 pdptype
$PROTO_DEFAULT_OPTIONS
34 json_get_vars device apn pincode delay auth username password allow_roaming allow_partner dhcp dhcpv6 pdptype
$PROTO_DEFAULT_OPTIONS
36 [ -n "$ctl_device" ] && device
=$ctl_device
39 echo "mbim[$$]" "No control device specified"
40 proto_notify_error
"$interface" NO_DEVICE
41 proto_set_available
"$interface" 0
45 echo "mbim[$$]" "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 )"
56 echo "mbim[$$]" "Failed to find matching interface"
57 proto_notify_error
"$interface" NO_IFNAME
58 proto_set_available
"$interface" 0
63 echo "mbim[$$]" "No APN specified"
64 proto_notify_error
"$interface" NO_APN
68 [ -n "$delay" ] && sleep "$delay"
70 echo "mbim[$$]" "Reading capabilities"
71 umbim
$DBG -n -d $device caps ||
{
72 echo "mbim[$$]" "Failed to read modem caps"
74 umbim
$DBG -t $tid -d "$device" disconnect
75 proto_notify_error
"$interface" PIN_FAILED
81 echo "mbim[$$]" "Sending pin"
82 umbim
$DBG -n -t $tid -d $device unlock
"$pincode" ||
{
83 echo "mbim[$$]" "Unable to verify PIN"
85 umbim
$DBG -t $tid -d "$device" disconnect
86 proto_notify_error
"$interface" PIN_FAILED
87 proto_block_restart
"$interface"
93 echo "mbim[$$]" "Checking pin"
94 umbim
$DBG -n -t $tid -d $device pinstate
96 echo "mbim[$$]" "PIN required"
98 umbim
$DBG -t $tid -d "$device" disconnect
99 proto_notify_error
"$interface" PIN_FAILED
100 proto_block_restart
"$interface"
105 echo "mbim[$$]" "Checking subscriber"
106 umbim
$DBG -n -t $tid -d $device subscriber ||
{
107 echo "mbim[$$]" "Subscriber init failed"
109 umbim
$DBG -t $tid -d "$device" disconnect
110 proto_notify_error
"$interface" NO_SUBSCRIBER
115 echo "mbim[$$]" "Register with network"
117 umbim
$DBG -n -t $tid -d $device registration
120 0) echo "mbim[$$]" "Registered in home mode"
123 4) if [ "$allow_roaming" = "1" ]; then
124 echo "mbim[$$]" "Registered in roaming mode"
128 5) if [ "$allow_partner" = "1" ]; then
129 echo "mbim[$$]" "Registered in partner mode"
134 if [ $connected -ne 1 ]; then
135 echo "mbim[$$]" "Subscriber registration failed (code $reg_status)"
137 umbim
$DBG -t $tid -d "$device" disconnect
138 proto_notify_error
"$interface" NO_REGISTRATION
142 echo "mbim[$$]" "Attach to network"
143 umbim
$DBG -n -t $tid -d $device attach ||
{
144 echo "mbim[$$]" "Failed to attach to network"
146 umbim
$DBG -t $tid -d "$device" disconnect
147 proto_notify_error
"$interface" ATTACH_FAILED
152 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
154 local req_pdptype
="" # Pass "default" PDP type to umbim if unconfigured
155 [ "$pdptype" = "ipv4" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && req_pdptype
="$pdptype:"
158 echo "mbim[$$]" "Connect to network"
159 connect_state
=$
(umbim
$DBG -n -t $tid -d $device connect
"$req_pdptype$apn" "$auth" "$username" "$password") ||
{
160 echo "mbim[$$]" "Failed to connect bearer"
162 umbim
$DBG -t $tid -d "$device" disconnect
163 proto_notify_error
"$interface" CONNECT_FAILED
168 echo "$connect_state"
169 local iptype
="$(echo "$connect_state" | grep iptype: | awk '{print $4}')"
171 echo "mbim[$$]" "Connected"
173 local zone
="$(fw3 -q network "$interface" 2>/dev/null)"
175 echo "mbim[$$]" "Setting up $ifname"
176 eval $
(umbim
$DBG -n -t $tid -d $device config |
sed 's/: /=/g')
179 proto_init_update
"$ifname" 1
180 proto_send_update
"$interface"
182 [ "$iptype" != "ipv6" ] && {
183 if [ -z "$dhcp" -o "$dhcp" = 0 ]; then
185 json_add_string name
"${interface}_4"
186 json_add_string ifname
"@$interface"
187 json_add_string proto
"static"
188 json_add_array ipaddr
189 json_add_string
"" "$ipv4address"
191 json_add_string gateway
"$ipv4gateway"
193 [ "$peerdns" = 0 ] || json_add_string
"" "$ipv4dnsserver"
195 proto_add_dynamic_defaults
196 [ -n "$zone" ] && json_add_string zone
"$zone"
198 ubus call network add_dynamic
"$(json_dump)"
200 echo "mbim[$$]" "Starting DHCP on $ifname"
202 json_add_string name
"${interface}_4"
203 json_add_string ifname
"@$interface"
204 json_add_string proto
"dhcp"
205 proto_add_dynamic_defaults
206 [ -n "$zone" ] && json_add_string zone
"$zone"
208 ubus call network add_dynamic
"$(json_dump)"
212 [ "$iptype" != "ipv4" ] && {
213 if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
215 json_add_string name
"${interface}_6"
216 json_add_string ifname
"@$interface"
217 json_add_string proto
"static"
218 json_add_array ip6addr
219 json_add_string
"" "$ipv6address"
221 json_add_string ip6gw
"$ipv6gateway"
223 [ "$peerdns" = 0 ] || json_add_string
"" "$ipv6dnsserver"
225 proto_add_dynamic_defaults
226 [ -n "$zone" ] && json_add_string zone
"$zone"
228 ubus call network add_dynamic
"$(json_dump)"
230 echo "mbim[$$]" "Starting DHCPv6 on $ifname"
232 json_add_string name
"${interface}_6"
233 json_add_string ifname
"@$interface"
234 json_add_string proto
"dhcpv6"
235 json_add_string extendprefix
1
236 proto_add_dynamic_defaults
237 [ -n "$zone" ] && json_add_string zone
"$zone"
239 ubus call network add_dynamic
"$(json_dump)"
243 uci_set_state network
$interface tid
"$tid"
253 logger
"mbim bringup failed, retry in 15s"
260 proto_mbim_teardown
() {
265 local tid
=$
(uci_get_state network
$interface tid
)
267 [ -n "$ctl_device" ] && device
=$ctl_device
269 echo "mbim[$$]" "Stopping network"
271 umbim
$DBG -t $tid -d "$device" disconnect
272 uci_revert_state network
$interface tid
275 proto_init_update
"*" 0
276 proto_send_update
"$interface"
279 [ -n "$INCLUDE_ONLY" ] || add_protocol mbim