umbim: remove superflous jshn call
[openwrt/openwrt.git] / package / network / utils / umbim / files / lib / netifd / proto / mbim.sh
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . ../netifd-proto.sh
5 init_proto "$@"
6
7 #DBG=-v
8
9 proto_mbim_init_config() {
10 proto_config_add_string "device:device"
11 proto_config_add_string apn
12 proto_config_add_string pincode
13 proto_config_add_string delay
14 proto_config_add_string auth
15 proto_config_add_string username
16 proto_config_add_string password
17 }
18
19 proto_mbim_setup() {
20 local interface="$1"
21 local tid=2
22 local ret
23
24 local device apn pincode delay
25 json_get_vars device apn pincode delay auth username password
26
27 [ -n "$device" ] || {
28 logger -p daemon.err -t "mbim[$$]" "No control device specified"
29 proto_notify_error "$interface" NO_DEVICE
30 proto_block_restart "$interface"
31 return 1
32 }
33 [ -c "$device" ] || {
34 logger -p daemon.err -t "mbim[$$]" "The specified control device does not exist"
35 proto_notify_error "$interface" NO_DEVICE
36 proto_block_restart "$interface"
37 return 1
38 }
39 [ -n "$apn" ] || {
40 logger -p daemon.err -t "mbim[$$]" "No APN specified"
41 proto_notify_error "$interface" NO_APN
42 proto_block_restart "$interface"
43 return 1
44 }
45
46 [ -n "$delay" ] && sleep "$delay"
47
48 logger -p daemon.info -t "mbim[$$]" "Reading capabilities"
49 umbim $DBG -n -d $device caps || {
50 logger -p daemon.err -t "mbim[$$]" "Failed to read modem caps"
51 proto_notify_error "$interface" PIN_FAILED
52 proto_block_restart "$interface"
53 return 1
54 }
55 tid=$((tid + 1))
56
57 [ "$pincode" ] && {
58 logger -p daemon.info -t "mbim[$$]" "Sending pin"
59 umbim $DBG -n -t $tid -d $device unlock "$pincode" || {
60 logger -p daemon.err -t "mbim[$$]" "Unable to verify PIN"
61 proto_notify_error "$interface" PIN_FAILED
62 proto_block_restart "$interface"
63 return 1
64 }
65 }
66 tid=$((tid + 1))
67
68 logger -p daemon.info -t "mbim[$$]" "Checking pin"
69 umbim $DBG -n -t $tid -d $device pinstate || {
70 logger -p daemon.err -t "mbim[$$]" "PIN required"
71 proto_notify_error "$interface" PIN_FAILED
72 proto_block_restart "$interface"
73 return 1
74 }
75 tid=$((tid + 1))
76
77 logger -p daemon.info -t "mbim[$$]" "Checking subscriber"
78 umbim $DBG -n -t $tid -d $device subscriber || {
79 logger -p daemon.err -t "mbim[$$]" "Subscriber init failed"
80 proto_notify_error "$interface" NO_SUBSCRIBER
81 proto_block_restart "$interface"
82 return 1
83 }
84 tid=$((tid + 1))
85
86 logger -p daemon.info -t "mbim[$$]" "Register with network"
87 umbim $DBG -n -t $tid -d $device registration || {
88 logger -p daemon.err -t "mbim[$$]" "Subscriber registration failed"
89 proto_notify_error "$interface" NO_REGISTRATION
90 proto_block_restart "$interface"
91 return 1
92 }
93 tid=$((tid + 1))
94
95 logger -p daemon.info -t "mbim[$$]" "Attach to network"
96 umbim $DBG -n -t $tid -d $device attach || {
97 logger -p daemon.err -t "mbim[$$]" "Failed to attach to network"
98 proto_notify_error "$interface" ATTACH_FAILED
99 proto_block_restart "$interface"
100 return 1
101 }
102 tid=$((tid + 1))
103
104 logger -p daemon.info -t "mbim[$$]" "Connect to network"
105 while ! umbim $DBG -n -t $tid -d $device connect "$apn" "$auth" "$username" "$password"; do
106 tid=$((tid + 1))
107 sleep 1;
108 done
109 tid=$((tid + 1))
110
111 uci_set_state network $interface tid "$tid"
112
113 logger -p daemon.info -t "mbim[$$]" "Connected, starting DHCP"
114 proto_init_update "*" 1
115 proto_send_update "$interface"
116
117 json_init
118 json_add_string name "${interface}_dhcp"
119 json_add_string ifname "@$interface"
120 json_add_string proto "dhcp"
121 json_close_object
122 ubus call network add_dynamic "$(json_dump)"
123
124 json_init
125 json_add_string name "${interface}_dhcpv6"
126 json_add_string ifname "@$interface"
127 json_add_string proto "dhcpv6"
128 ubus call network add_dynamic "$(json_dump)"
129 }
130
131 proto_mbim_teardown() {
132 local interface="$1"
133
134 local device
135 json_get_vars device
136 local tid=$(uci_get_state network $interface tid)
137
138 logger -p daemon.info -t "mbim[$$]" "Stopping network"
139 [ -n "$tid" ] && {
140 umbim $DBG -t$tid -d "$device" disconnect
141 uci_revert_state network $interface tid
142 }
143
144 proto_init_update "*" 0
145 proto_send_update "$interface"
146 }
147
148 add_protocol mbim