comgt: initialize ifname for directip
[openwrt/staging/chunkeey.git] / package / network / utils / comgt / files / directip.sh
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . ../netifd-proto.sh
5 init_proto "$@"
6
7 proto_directip_init_config() {
8 available=1
9 no_device=1
10 proto_config_add_string "device:device"
11 proto_config_add_string "ifname"
12 proto_config_add_string "apn"
13 proto_config_add_string "pincode"
14 proto_config_add_string "auth"
15 proto_config_add_string "username"
16 proto_config_add_string "password"
17 }
18
19 proto_directip_setup() {
20 local interface="$1"
21 local chat
22
23 local device apn pincode ifname auth username password
24 json_get_vars device apn pincode ifname auth username password
25
26 [ -e "$device" ] || {
27 proto_notify_error "$interface" NO_DEVICE
28 proto_set_available "$interface" 0
29 return 1
30 }
31
32 [ -n "$ifname" ] || {
33 proto_notify_error "$interface" NO_IFNAME
34 proto_set_available "$interface" 0
35 return 1
36 }
37
38 cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom)
39 [ -n $(echo "$cardinfo" | grep -q "Sierra Wireless") ] || {
40 proto_notify_error "$interface" BAD_DEVICE
41 proto_block_restart "$interface"
42 return 1
43 }
44
45 if [ -n "$pincode" ]; then
46 PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
47 proto_notify_error "$interface" PIN_FAILED
48 proto_block_restart "$interface"
49 return 1
50 }
51 fi
52 # wait for carrier to avoid firmware stability bugs
53 gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
54
55 local auth_type=0
56 [ -z "$auth" ] && case $auth in
57 pap) auth_type=1;;
58 chap) auth_type=1;;
59 esac
60
61 USE_APN="$apn" USE_USER="$username" USE_PASS="$password" USE_AUTH="$auth_type" \
62 gcom -d "$device" -s /etc/gcom/directip.gcom || {
63 proto_notify_error "$interface" CONNECT_FAILED
64 proto_block_restart "$interface"
65 return 1
66 }
67
68 logger -p daemon.info -t "directip[$$]" "Connected, starting DHCP"
69 proto_init_update "$ifname" 1
70 proto_send_update "$interface"
71
72 json_init
73 json_add_string name "${interface}_dhcp"
74 json_add_string ifname "@$interface"
75 json_add_string proto "dhcp"
76 ubus call network add_dynamic "$(json_dump)"
77
78 return 0
79 }
80
81 proto_directip_teardown() {
82 local interface="$1"
83
84 local device
85 json_get_vars device
86
87 gcom -d "$device" -s /etc/gcom/directip-stop.gcom || proto_notify_error "$interface" CONNECT_FAILED
88
89 proto_init_update "*" 0
90 proto_send_update "$interface"
91 }
92
93 add_protocol directip