9 proto_mbim_init_config() {
12 proto_config_add_string "device:device"
13 proto_config_add_string apn
14 proto_config_add_string pincode
15 proto_config_add_string delay
16 proto_config_add_string auth
17 proto_config_add_string username
18 proto_config_add_string password
26 local device apn pincode delay
27 json_get_vars device apn pincode delay auth username password
30 echo "mbim[$$]" "No control device specified"
31 proto_notify_error "$interface" NO_DEVICE
32 proto_set_available "$interface" 0
36 echo "mbim[$$]" "The specified control device does not exist"
37 proto_notify_error "$interface" NO_DEVICE
38 proto_set_available "$interface" 0
42 devname="$(basename "$device")"
43 devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
44 ifname="$( ls "$devpath"/net )"
47 echo "mbim[$$]" "Failed to find matching interface"
48 proto_notify_error "$interface" NO_IFNAME
49 proto_set_available "$interface" 0
54 echo "mbim[$$]" "No APN specified"
55 proto_notify_error "$interface" NO_APN
59 [ -n "$delay" ] && sleep "$delay"
61 echo "mbim[$$]" "Reading capabilities"
62 umbim $DBG -n -d $device caps || {
63 echo "mbim[$$]" "Failed to read modem caps"
64 proto_notify_error "$interface" PIN_FAILED
70 echo "mbim[$$]" "Sending pin"
71 umbim $DBG -n -t $tid -d $device unlock "$pincode" || {
72 echo "mbim[$$]" "Unable to verify PIN"
73 proto_notify_error "$interface" PIN_FAILED
74 proto_block_restart "$interface"
80 echo "mbim[$$]" "Checking pin"
81 umbim $DBG -n -t $tid -d $device pinstate || {
82 echo "mbim[$$]" "PIN required"
83 proto_notify_error "$interface" PIN_FAILED
84 proto_block_restart "$interface"
89 echo "mbim[$$]" "Checking subscriber"
90 umbim $DBG -n -t $tid -d $device subscriber || {
91 echo "mbim[$$]" "Subscriber init failed"
92 proto_notify_error "$interface" NO_SUBSCRIBER
97 echo "mbim[$$]" "Register with network"
98 umbim $DBG -n -t $tid -d $device registration || {
99 echo "mbim[$$]" "Subscriber registration failed"
100 proto_notify_error "$interface" NO_REGISTRATION
105 echo "mbim[$$]" "Attach to network"
106 umbim $DBG -n -t $tid -d $device attach || {
107 echo "mbim[$$]" "Failed to attach to network"
108 proto_notify_error "$interface" ATTACH_FAILED
113 echo "mbim[$$]" "Connect to network"
114 while ! umbim $DBG -n -t $tid -d $device connect "$apn" "$auth" "$username" "$password"; do
120 uci_set_state network $interface tid "$tid"
122 echo "mbim[$$]" "Connected, starting DHCP"
123 proto_init_update "$ifname" 1
124 proto_send_update "$interface"
127 json_add_string name "${interface}_dhcp"
128 json_add_string ifname "@$interface"
129 json_add_string proto "dhcp"
131 ubus call network add_dynamic "$(json_dump)"
134 json_add_string name "${interface}_dhcpv6"
135 json_add_string ifname "@$interface"
136 json_add_string proto "dhcpv6"
137 ubus call network add_dynamic "$(json_dump)"
140 proto_mbim_teardown() {
145 local tid=$(uci_get_state network $interface tid)
147 echo "mbim[$$]" "Stopping network"
149 umbim $DBG -t$tid -d "$device" disconnect
150 uci_revert_state network $interface tid
153 proto_init_update "*" 0
154 proto_send_update "$interface"