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_string auth
18 proto_config_add_string username
19 proto_config_add_string password
20 proto_config_add_defaults
28 local device apn pincode delay
$PROTO_DEFAULT_OPTIONS
29 json_get_vars device apn pincode delay auth username password
$PROTO_DEFAULT_OPTIONS
31 [ -n "$ctl_device" ] && device
=$ctl_device
34 echo "mbim[$$]" "No control device specified"
35 proto_notify_error
"$interface" NO_DEVICE
36 proto_set_available
"$interface" 0
40 echo "mbim[$$]" "The specified control device does not exist"
41 proto_notify_error
"$interface" NO_DEVICE
42 proto_set_available
"$interface" 0
46 devname
="$(basename "$device")"
47 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
48 ifname
="$( ls "$devpath"/net )"
51 echo "mbim[$$]" "Failed to find matching interface"
52 proto_notify_error
"$interface" NO_IFNAME
53 proto_set_available
"$interface" 0
58 echo "mbim[$$]" "No APN specified"
59 proto_notify_error
"$interface" NO_APN
63 [ -n "$delay" ] && sleep "$delay"
65 echo "mbim[$$]" "Reading capabilities"
66 umbim
$DBG -n -d $device caps ||
{
67 echo "mbim[$$]" "Failed to read modem caps"
69 umbim
$DBG -t $tid -d "$device" disconnect
70 proto_notify_error
"$interface" PIN_FAILED
76 echo "mbim[$$]" "Sending pin"
77 umbim
$DBG -n -t $tid -d $device unlock
"$pincode" ||
{
78 echo "mbim[$$]" "Unable to verify PIN"
80 umbim
$DBG -t $tid -d "$device" disconnect
81 proto_notify_error
"$interface" PIN_FAILED
82 proto_block_restart
"$interface"
88 echo "mbim[$$]" "Checking pin"
89 umbim
$DBG -n -t $tid -d $device pinstate ||
{
90 echo "mbim[$$]" "PIN required"
92 umbim
$DBG -t $tid -d "$device" disconnect
93 proto_notify_error
"$interface" PIN_FAILED
94 proto_block_restart
"$interface"
99 echo "mbim[$$]" "Checking subscriber"
100 umbim
$DBG -n -t $tid -d $device subscriber ||
{
101 echo "mbim[$$]" "Subscriber init failed"
103 umbim
$DBG -t $tid -d "$device" disconnect
104 proto_notify_error
"$interface" NO_SUBSCRIBER
109 echo "mbim[$$]" "Register with network"
110 umbim
$DBG -n -t $tid -d $device registration ||
{
111 echo "mbim[$$]" "Subscriber registration failed"
113 umbim
$DBG -t $tid -d "$device" disconnect
114 proto_notify_error
"$interface" NO_REGISTRATION
119 echo "mbim[$$]" "Attach to network"
120 umbim
$DBG -n -t $tid -d $device attach ||
{
121 echo "mbim[$$]" "Failed to attach to network"
123 umbim
$DBG -t $tid -d "$device" disconnect
124 proto_notify_error
"$interface" ATTACH_FAILED
129 echo "mbim[$$]" "Connect to network"
130 while ! umbim
$DBG -n -t $tid -d $device connect
"$apn" "$auth" "$username" "$password"; do
136 uci_set_state network
$interface tid
"$tid"
138 echo "mbim[$$]" "Connected, starting DHCP"
139 proto_init_update
"$ifname" 1
140 proto_send_update
"$interface"
143 json_add_string name
"${interface}_4"
144 json_add_string ifname
"@$interface"
145 json_add_string proto
"dhcp"
146 proto_add_dynamic_defaults
148 ubus call network add_dynamic
"$(json_dump)"
151 json_add_string name
"${interface}_6"
152 json_add_string ifname
"@$interface"
153 json_add_string proto
"dhcpv6"
154 json_add_string extendprefix
1
155 proto_add_dynamic_defaults
156 ubus call network add_dynamic
"$(json_dump)"
166 logger
"mbim bringup failed, retry in 15s"
173 proto_mbim_teardown
() {
178 local tid
=$
(uci_get_state network
$interface tid
)
180 [ -n "$ctl_device" ] && device
=$ctl_device
182 echo "mbim[$$]" "Stopping network"
184 umbim
$DBG -t $tid -d "$device" disconnect
185 uci_revert_state network
$interface tid
188 proto_init_update
"*" 0
189 proto_send_update
"$interface"
192 [ -n "$INCLUDE_ONLY" ] || add_protocol mbim