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_defaults
30 local device apn pincode delay allow_roaming allow_partner
$PROTO_DEFAULT_OPTIONS
31 json_get_vars device apn pincode delay auth username password allow_roaming allow_partner
$PROTO_DEFAULT_OPTIONS
33 [ -n "$ctl_device" ] && device
=$ctl_device
36 echo "mbim[$$]" "No control device specified"
37 proto_notify_error
"$interface" NO_DEVICE
38 proto_set_available
"$interface" 0
42 echo "mbim[$$]" "The specified control device does not exist"
43 proto_notify_error
"$interface" NO_DEVICE
44 proto_set_available
"$interface" 0
48 devname
="$(basename "$device")"
49 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
50 ifname
="$( ls "$devpath"/net )"
53 echo "mbim[$$]" "Failed to find matching interface"
54 proto_notify_error
"$interface" NO_IFNAME
55 proto_set_available
"$interface" 0
60 echo "mbim[$$]" "No APN specified"
61 proto_notify_error
"$interface" NO_APN
65 [ -n "$delay" ] && sleep "$delay"
67 echo "mbim[$$]" "Reading capabilities"
68 umbim
$DBG -n -d $device caps ||
{
69 echo "mbim[$$]" "Failed to read modem caps"
71 umbim
$DBG -t $tid -d "$device" disconnect
72 proto_notify_error
"$interface" PIN_FAILED
78 echo "mbim[$$]" "Sending pin"
79 umbim
$DBG -n -t $tid -d $device unlock
"$pincode" ||
{
80 echo "mbim[$$]" "Unable to verify PIN"
82 umbim
$DBG -t $tid -d "$device" disconnect
83 proto_notify_error
"$interface" PIN_FAILED
84 proto_block_restart
"$interface"
90 echo "mbim[$$]" "Checking pin"
91 umbim
$DBG -n -t $tid -d $device pinstate
93 echo "mbim[$$]" "PIN required"
95 umbim
$DBG -t $tid -d "$device" disconnect
96 proto_notify_error
"$interface" PIN_FAILED
97 proto_block_restart
"$interface"
102 echo "mbim[$$]" "Checking subscriber"
103 umbim
$DBG -n -t $tid -d $device subscriber ||
{
104 echo "mbim[$$]" "Subscriber init failed"
106 umbim
$DBG -t $tid -d "$device" disconnect
107 proto_notify_error
"$interface" NO_SUBSCRIBER
112 echo "mbim[$$]" "Register with network"
114 umbim
$DBG -n -t $tid -d $device registration
117 0) echo "mbim[$$]" "Registered in home mode"
120 4) if [ "$allow_roaming" = "1" ]; then
121 echo "mbim[$$]" "Registered in roaming mode"
125 5) if [ "$allow_partner" = "1" ]; then
126 echo "mbim[$$]" "Registered in partner mode"
131 if [ $connected -ne 1 ]; then
132 echo "mbim[$$]" "Subscriber registration failed (code $reg_status)"
134 umbim
$DBG -t $tid -d "$device" disconnect
135 proto_notify_error
"$interface" NO_REGISTRATION
139 echo "mbim[$$]" "Attach to network"
140 umbim
$DBG -n -t $tid -d $device attach ||
{
141 echo "mbim[$$]" "Failed to attach to network"
143 umbim
$DBG -t $tid -d "$device" disconnect
144 proto_notify_error
"$interface" ATTACH_FAILED
149 echo "mbim[$$]" "Connect to network"
150 while ! umbim
$DBG -n -t $tid -d $device connect
"$apn" "$auth" "$username" "$password"; do
156 uci_set_state network
$interface tid
"$tid"
158 echo "mbim[$$]" "Connected, starting DHCP"
159 proto_init_update
"$ifname" 1
160 proto_send_update
"$interface"
163 json_add_string name
"${interface}_4"
164 json_add_string ifname
"@$interface"
165 json_add_string proto
"dhcp"
166 proto_add_dynamic_defaults
168 ubus call network add_dynamic
"$(json_dump)"
171 json_add_string name
"${interface}_6"
172 json_add_string ifname
"@$interface"
173 json_add_string proto
"dhcpv6"
174 json_add_string extendprefix
1
175 proto_add_dynamic_defaults
177 ubus call network add_dynamic
"$(json_dump)"
187 logger
"mbim bringup failed, retry in 15s"
194 proto_mbim_teardown
() {
199 local tid
=$
(uci_get_state network
$interface tid
)
201 [ -n "$ctl_device" ] && device
=$ctl_device
203 echo "mbim[$$]" "Stopping network"
205 umbim
$DBG -t $tid -d "$device" disconnect
206 uci_revert_state network
$interface tid
209 proto_init_update
"*" 0
210 proto_send_update
"$interface"
213 [ -n "$INCLUDE_ONLY" ] || add_protocol mbim