2014-09-11 12:26:31 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2014-10-08 08:01:20 +00:00
|
|
|
[ -n "$INCLUDE_ONLY" ] || {
|
|
|
|
. /lib/functions.sh
|
|
|
|
. ../netifd-proto.sh
|
|
|
|
init_proto "$@"
|
|
|
|
}
|
2014-09-11 12:26:31 +00:00
|
|
|
|
|
|
|
proto_directip_init_config() {
|
|
|
|
available=1
|
2014-09-24 08:07:45 +00:00
|
|
|
no_device=1
|
2014-09-11 12:26:31 +00:00
|
|
|
proto_config_add_string "device:device"
|
|
|
|
proto_config_add_string "apn"
|
|
|
|
proto_config_add_string "pincode"
|
|
|
|
proto_config_add_string "auth"
|
|
|
|
proto_config_add_string "username"
|
|
|
|
proto_config_add_string "password"
|
2016-10-17 00:39:08 +00:00
|
|
|
proto_config_add_defaults
|
2014-09-11 12:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proto_directip_setup() {
|
|
|
|
local interface="$1"
|
2014-09-26 13:44:21 +00:00
|
|
|
local chat devpath devname
|
2014-09-11 12:26:31 +00:00
|
|
|
|
2016-10-17 00:39:08 +00:00
|
|
|
local device apn pincode ifname auth username password $PROTO_DEFAULT_OPTIONS
|
|
|
|
json_get_vars device apn pincode auth username password $PROTO_DEFAULT_OPTIONS
|
2014-09-11 12:26:31 +00:00
|
|
|
|
2014-10-08 08:01:20 +00:00
|
|
|
[ -n "$ctl_device" ] && device=$ctl_device
|
|
|
|
|
2016-12-16 11:14:05 +00:00
|
|
|
device="$(readlink -f $device)"
|
2014-09-11 12:26:31 +00:00
|
|
|
[ -e "$device" ] || {
|
|
|
|
proto_notify_error "$interface" NO_DEVICE
|
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2014-09-26 13:44:21 +00:00
|
|
|
devname="$(basename "$device")"
|
|
|
|
devpath="$(readlink -f /sys/class/tty/$devname/device)"
|
|
|
|
ifname="$( ls "$devpath"/../../*/net )"
|
|
|
|
|
2014-09-11 12:26:31 +00:00
|
|
|
[ -n "$ifname" ] || {
|
|
|
|
proto_notify_error "$interface" NO_IFNAME
|
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-09-11 13:27:53 +00:00
|
|
|
gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | grep -q "Sierra Wireless" || {
|
2014-09-11 12:26:31 +00:00
|
|
|
proto_notify_error "$interface" BAD_DEVICE
|
|
|
|
proto_block_restart "$interface"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "$pincode" ]; then
|
|
|
|
PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
|
|
|
|
proto_notify_error "$interface" PIN_FAILED
|
|
|
|
proto_block_restart "$interface"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
# wait for carrier to avoid firmware stability bugs
|
|
|
|
gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
|
|
|
|
|
|
|
|
local auth_type=0
|
2014-09-26 15:55:45 +00:00
|
|
|
case $auth in
|
2014-09-11 12:26:31 +00:00
|
|
|
pap) auth_type=1;;
|
2014-09-26 15:55:45 +00:00
|
|
|
chap) auth_type=2;;
|
2014-09-11 12:26:31 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
USE_APN="$apn" USE_USER="$username" USE_PASS="$password" USE_AUTH="$auth_type" \
|
|
|
|
gcom -d "$device" -s /etc/gcom/directip.gcom || {
|
|
|
|
proto_notify_error "$interface" CONNECT_FAILED
|
|
|
|
proto_block_restart "$interface"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
logger -p daemon.info -t "directip[$$]" "Connected, starting DHCP"
|
2014-09-24 17:04:20 +00:00
|
|
|
proto_init_update "$ifname" 1
|
2014-09-11 12:26:31 +00:00
|
|
|
proto_send_update "$interface"
|
|
|
|
|
|
|
|
json_init
|
2015-04-17 14:47:12 +00:00
|
|
|
json_add_string name "${interface}_4"
|
2014-09-11 12:26:31 +00:00
|
|
|
json_add_string ifname "@$interface"
|
|
|
|
json_add_string proto "dhcp"
|
2016-10-17 00:39:08 +00:00
|
|
|
proto_add_dynamic_defaults
|
2014-09-11 12:26:31 +00:00
|
|
|
ubus call network add_dynamic "$(json_dump)"
|
|
|
|
|
2014-09-26 13:58:40 +00:00
|
|
|
json_init
|
2015-04-17 14:47:12 +00:00
|
|
|
json_add_string name "${interface}_6"
|
2014-09-26 13:58:40 +00:00
|
|
|
json_add_string ifname "@$interface"
|
|
|
|
json_add_string proto "dhcpv6"
|
2015-09-03 15:53:40 +00:00
|
|
|
json_add_string extendprefix 1
|
2016-10-17 00:39:08 +00:00
|
|
|
proto_add_dynamic_defaults
|
2014-09-26 13:58:40 +00:00
|
|
|
ubus call network add_dynamic "$(json_dump)"
|
|
|
|
|
2014-09-11 12:26:31 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_directip_teardown() {
|
|
|
|
local interface="$1"
|
|
|
|
|
|
|
|
local device
|
|
|
|
json_get_vars device
|
|
|
|
|
2014-10-08 08:01:20 +00:00
|
|
|
[ -n "$ctl_device" ] && device=$ctl_device
|
|
|
|
|
2014-09-11 12:26:31 +00:00
|
|
|
gcom -d "$device" -s /etc/gcom/directip-stop.gcom || proto_notify_error "$interface" CONNECT_FAILED
|
|
|
|
|
|
|
|
proto_init_update "*" 0
|
|
|
|
proto_send_update "$interface"
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:01:20 +00:00
|
|
|
[ -n "$INCLUDE_ONLY" ] || {
|
|
|
|
add_protocol directip
|
|
|
|
}
|