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_string pdptype
24 proto_config_add_defaults
32 local device apn pincode delay allow_roaming allow_partner dhcp pdptype
$PROTO_DEFAULT_OPTIONS
33 json_get_vars device apn pincode delay auth username password allow_roaming allow_partner dhcp pdptype
$PROTO_DEFAULT_OPTIONS
35 [ -n "$ctl_device" ] && device
=$ctl_device
38 echo "mbim[$$]" "No control device specified"
39 proto_notify_error
"$interface" NO_DEVICE
40 proto_set_available
"$interface" 0
44 echo "mbim[$$]" "The specified control device does not exist"
45 proto_notify_error
"$interface" NO_DEVICE
46 proto_set_available
"$interface" 0
50 devname
="$(basename "$device")"
51 devpath
="$(readlink -f /sys/class/usbmisc/$devname/device/)"
52 ifname
="$( ls "$devpath"/net )"
55 echo "mbim[$$]" "Failed to find matching interface"
56 proto_notify_error
"$interface" NO_IFNAME
57 proto_set_available
"$interface" 0
62 echo "mbim[$$]" "No APN specified"
63 proto_notify_error
"$interface" NO_APN
67 [ -n "$delay" ] && sleep "$delay"
69 echo "mbim[$$]" "Reading capabilities"
70 umbim
$DBG -n -d $device caps ||
{
71 echo "mbim[$$]" "Failed to read modem caps"
73 umbim
$DBG -t $tid -d "$device" disconnect
74 proto_notify_error
"$interface" PIN_FAILED
80 echo "mbim[$$]" "Sending pin"
81 umbim
$DBG -n -t $tid -d $device unlock
"$pincode" ||
{
82 echo "mbim[$$]" "Unable to verify PIN"
84 umbim
$DBG -t $tid -d "$device" disconnect
85 proto_notify_error
"$interface" PIN_FAILED
86 proto_block_restart
"$interface"
92 echo "mbim[$$]" "Checking pin"
93 umbim
$DBG -n -t $tid -d $device pinstate
95 echo "mbim[$$]" "PIN required"
97 umbim
$DBG -t $tid -d "$device" disconnect
98 proto_notify_error
"$interface" PIN_FAILED
99 proto_block_restart
"$interface"
104 echo "mbim[$$]" "Checking subscriber"
105 umbim
$DBG -n -t $tid -d $device subscriber ||
{
106 echo "mbim[$$]" "Subscriber init failed"
108 umbim
$DBG -t $tid -d "$device" disconnect
109 proto_notify_error
"$interface" NO_SUBSCRIBER
114 echo "mbim[$$]" "Register with network"
116 umbim
$DBG -n -t $tid -d $device registration
119 0) echo "mbim[$$]" "Registered in home mode"
122 4) if [ "$allow_roaming" = "1" ]; then
123 echo "mbim[$$]" "Registered in roaming mode"
127 5) if [ "$allow_partner" = "1" ]; then
128 echo "mbim[$$]" "Registered in partner mode"
133 if [ $connected -ne 1 ]; then
134 echo "mbim[$$]" "Subscriber registration failed (code $reg_status)"
136 umbim
$DBG -t $tid -d "$device" disconnect
137 proto_notify_error
"$interface" NO_REGISTRATION
141 echo "mbim[$$]" "Attach to network"
142 umbim
$DBG -n -t $tid -d $device attach ||
{
143 echo "mbim[$$]" "Failed to attach to network"
145 umbim
$DBG -t $tid -d "$device" disconnect
146 proto_notify_error
"$interface" ATTACH_FAILED
151 pdptype
=$
(echo "$pdptype" |
awk '{print tolower($0)}')
152 [ "$pdptype" = "ipv4" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype
="ipv4v6"
154 echo "mbim[$$]" "Connect to network"
155 umbim
$DBG -n -t $tid -d $device connect
"$pdptype:$apn" "$auth" "$username" "$password" ||
{
156 echo "mbim[$$]" "Failed to connect bearer"
158 umbim
$DBG -t $tid -d "$device" disconnect
159 proto_notify_error
"$interface" CONNECT_FAILED
164 echo "mbim[$$]" "Connected"
166 if [ "$dhcp" = 0 ]; then
167 echo "mbim[$$]" "Setting up $ifname"
168 eval $
(umbim
$DBG -n -t $tid -d $device config |
sed 's/: /=/g')
171 proto_init_update
"$ifname" 1
172 proto_send_update
"$interface"
174 [ "$pdptype" = "ipv4" -o "$pdptype" = "ipv4v6" ] && {
176 json_add_string name
"${interface}_4"
177 json_add_string ifname
"@$interface"
178 json_add_string proto
"static"
179 json_add_array ipaddr
180 json_add_string
"" "$ipv4address"
182 json_add_string gateway
"$ipv4gateway"
184 json_add_string
"" "$ipv4dnsserver"
186 proto_add_dynamic_defaults
188 ubus call network add_dynamic
"$(json_dump)"
191 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
193 json_add_string name
"${interface}_6"
194 json_add_string ifname
"@$interface"
195 json_add_string proto
"static"
196 json_add_array ip6addr
197 json_add_string
"" "$ipv6address"
199 json_add_string ip6gw
"$ipv6gateway"
201 json_add_string
"" "$ipv6dnsserver"
203 proto_add_dynamic_defaults
205 ubus call network add_dynamic
"$(json_dump)"
208 echo "mbim[$$]" "Starting DHCP on $ifname"
209 proto_init_update
"$ifname" 1
210 proto_send_update
"$interface"
212 [ "$pdptype" = "ipv4" -o "$pdptype" = "ipv4v6" ] && {
214 json_add_string name
"${interface}_4"
215 json_add_string ifname
"@$interface"
216 json_add_string proto
"dhcp"
217 proto_add_dynamic_defaults
219 ubus call network add_dynamic
"$(json_dump)"
222 [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && {
224 json_add_string name
"${interface}_6"
225 json_add_string ifname
"@$interface"
226 json_add_string proto
"dhcpv6"
227 json_add_string extendprefix
1
228 proto_add_dynamic_defaults
230 ubus call network add_dynamic
"$(json_dump)"
234 uci_set_state network
$interface tid
"$tid"
244 logger
"mbim bringup failed, retry in 15s"
251 proto_mbim_teardown
() {
256 local tid
=$
(uci_get_state network
$interface tid
)
258 [ -n "$ctl_device" ] && device
=$ctl_device
260 echo "mbim[$$]" "Stopping network"
262 umbim
$DBG -t $tid -d "$device" disconnect
263 uci_revert_state network
$interface tid
266 proto_init_update
"*" 0
267 proto_send_update
"$interface"
270 [ -n "$INCLUDE_ONLY" ] || add_protocol mbim