2014-10-10 08:56:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-01-28 19:19:33 +00:00
|
|
|
[ -n "$INCLUDE_ONLY" ] || {
|
|
|
|
. /lib/functions.sh
|
|
|
|
. ../netifd-proto.sh
|
|
|
|
init_proto "$@"
|
|
|
|
}
|
2014-10-10 08:56:33 +00:00
|
|
|
|
|
|
|
proto_ncm_init_config() {
|
|
|
|
no_device=1
|
|
|
|
available=1
|
|
|
|
proto_config_add_string "device:device"
|
2022-03-31 19:16:01 +00:00
|
|
|
proto_config_add_string ifname
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_config_add_string apn
|
|
|
|
proto_config_add_string auth
|
|
|
|
proto_config_add_string username
|
|
|
|
proto_config_add_string password
|
|
|
|
proto_config_add_string pincode
|
|
|
|
proto_config_add_string delay
|
|
|
|
proto_config_add_string mode
|
2015-09-11 06:46:42 +00:00
|
|
|
proto_config_add_string pdptype
|
2024-01-22 14:59:18 +00:00
|
|
|
proto_config_add_boolean sourcefilter
|
2024-05-15 14:46:08 +00:00
|
|
|
proto_config_add_boolean delegate
|
2016-12-11 15:28:52 +00:00
|
|
|
proto_config_add_int profile
|
2016-10-17 00:38:42 +00:00
|
|
|
proto_config_add_defaults
|
2014-10-10 08:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proto_ncm_setup() {
|
|
|
|
local interface="$1"
|
|
|
|
|
2022-03-31 19:16:22 +00:00
|
|
|
local manufacturer initialize setmode connect finalize devname devpath ifpath
|
2014-10-10 08:56:33 +00:00
|
|
|
|
2022-03-31 19:16:01 +00:00
|
|
|
local device ifname apn auth username password pincode delay mode pdptype profile $PROTO_DEFAULT_OPTIONS
|
2024-05-15 14:46:08 +00:00
|
|
|
json_get_vars device ifname apn auth username password pincode delay mode pdptype sourcefilter delegate profile $PROTO_DEFAULT_OPTIONS
|
2016-12-11 15:28:52 +00:00
|
|
|
|
2022-11-30 20:35:29 +00:00
|
|
|
local context_type
|
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
[ "$metric" = "" ] && metric="0"
|
|
|
|
|
|
|
|
[ -n "$profile" ] || profile=1
|
|
|
|
|
2020-05-10 14:47:50 +00:00
|
|
|
pdptype=$(echo "$pdptype" | awk '{print toupper($0)}')
|
2016-12-21 17:02:53 +00:00
|
|
|
[ "$pdptype" = "IP" -o "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] || pdptype="IP"
|
2014-10-10 08:56:33 +00:00
|
|
|
|
2022-11-30 20:35:29 +00:00
|
|
|
[ "$pdptype" = "IPV4V6" ] && context_type=3
|
|
|
|
[ -z "$context_type" -a "$pdptype" = "IPV6" ] && context_type=2
|
|
|
|
[ -n "$context_type" ] || context_type=1
|
|
|
|
|
2015-07-08 14:26:04 +00:00
|
|
|
[ -n "$ctl_device" ] && device=$ctl_device
|
|
|
|
|
2014-10-10 08:56:33 +00:00
|
|
|
[ -n "$device" ] || {
|
2015-01-28 19:19:33 +00:00
|
|
|
echo "No control device specified"
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_notify_error "$interface" NO_DEVICE
|
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
2016-12-16 11:14:05 +00:00
|
|
|
|
|
|
|
device="$(readlink -f $device)"
|
2014-10-10 08:56:33 +00:00
|
|
|
[ -e "$device" ] || {
|
2015-01-28 19:19:33 +00:00
|
|
|
echo "Control device not valid"
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:16:01 +00:00
|
|
|
[ -z "$ifname" ] && {
|
|
|
|
devname="$(basename "$device")"
|
|
|
|
case "$devname" in
|
2022-03-31 19:16:34 +00:00
|
|
|
'ttyACM'*)
|
|
|
|
devpath="$(readlink -f /sys/class/tty/$devname/device)"
|
|
|
|
ifpath="$devpath/../*/net"
|
|
|
|
;;
|
2022-03-31 19:16:01 +00:00
|
|
|
'tty'*)
|
|
|
|
devpath="$(readlink -f /sys/class/tty/$devname/device)"
|
2022-03-31 19:16:22 +00:00
|
|
|
ifpath="$devpath/../../*/net"
|
2022-03-31 19:16:01 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
|
2022-03-31 19:16:22 +00:00
|
|
|
ifpath="$devpath/net"
|
2022-03-31 19:16:01 +00:00
|
|
|
;;
|
|
|
|
esac
|
2022-03-31 19:16:22 +00:00
|
|
|
ifname="$(ls $(ls -1 -d $ifpath | head -n 1))"
|
2022-03-31 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 19:19:33 +00:00
|
|
|
[ -n "$ifname" ] || {
|
|
|
|
echo "The interface could not be found."
|
|
|
|
proto_notify_error "$interface" NO_IFACE
|
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2020-07-20 20:25:33 +00:00
|
|
|
start=$(date +%s)
|
|
|
|
while true; do
|
|
|
|
manufacturer=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
|
|
|
|
[ "$manufacturer" = "error" ] && {
|
|
|
|
manufacturer=""
|
|
|
|
}
|
|
|
|
[ -n "$manufacturer" ] && {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
[ -z "$delay" ] && {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
sleep 1
|
|
|
|
elapsed=$(($(date +%s) - start))
|
|
|
|
[ "$elapsed" -gt "$delay" ] && {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
done
|
|
|
|
[ -z "$manufacturer" ] && {
|
2015-01-28 19:19:33 +00:00
|
|
|
echo "Failed to get modem information"
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_notify_error "$interface" GETINFO_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
json_load "$(cat /etc/gcom/ncm.json)"
|
|
|
|
json_select "$manufacturer"
|
|
|
|
[ $? -ne 0 ] && {
|
2015-01-28 19:19:33 +00:00
|
|
|
echo "Unsupported modem"
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_notify_error "$interface" UNSUPPORTED_MODEM
|
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
2019-08-24 16:41:01 +00:00
|
|
|
|
2014-10-10 08:56:33 +00:00
|
|
|
json_get_values initialize initialize
|
|
|
|
for i in $initialize; do
|
|
|
|
eval COMMAND="$i" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
|
2015-01-28 19:19:33 +00:00
|
|
|
echo "Failed to initialize modem"
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_notify_error "$interface" INITIALIZE_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
|
|
|
[ -n "$pincode" ] && {
|
|
|
|
PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
|
2015-01-28 19:19:33 +00:00
|
|
|
echo "Unable to verify PIN"
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_notify_error "$interface" PIN_FAILED
|
|
|
|
proto_block_restart "$interface"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
2016-12-22 21:12:44 +00:00
|
|
|
|
|
|
|
json_get_values configure configure
|
|
|
|
echo "Configuring modem"
|
|
|
|
for i in $configure; do
|
|
|
|
eval COMMAND="$i" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
|
|
|
|
echo "Failed to configure modem"
|
|
|
|
proto_notify_error "$interface" CONFIGURE_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
2014-10-10 08:56:33 +00:00
|
|
|
[ -n "$mode" ] && {
|
|
|
|
json_select modes
|
|
|
|
json_get_var setmode "$mode"
|
2019-08-24 16:41:01 +00:00
|
|
|
[ -n "$setmode" ] && {
|
|
|
|
echo "Setting mode"
|
|
|
|
eval COMMAND="$setmode" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
|
|
|
|
echo "Failed to set operating mode"
|
|
|
|
proto_notify_error "$interface" SETMODE_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
2014-10-10 08:56:33 +00:00
|
|
|
}
|
|
|
|
json_select ..
|
|
|
|
}
|
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
echo "Starting network $interface"
|
2015-01-28 19:19:33 +00:00
|
|
|
json_get_vars connect
|
2019-08-24 16:41:01 +00:00
|
|
|
[ -n "$connect" ] && {
|
|
|
|
echo "Connecting modem"
|
|
|
|
eval COMMAND="$connect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
|
|
|
|
echo "Failed to connect"
|
|
|
|
proto_notify_error "$interface" CONNECT_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
2014-10-10 08:56:33 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 21:12:44 +00:00
|
|
|
json_get_vars finalize
|
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
echo "Setting up $ifname"
|
2015-01-28 19:19:33 +00:00
|
|
|
proto_init_update "$ifname" 1
|
2016-12-11 15:28:52 +00:00
|
|
|
proto_add_data
|
|
|
|
json_add_string "manufacturer" "$manufacturer"
|
|
|
|
proto_close_data
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_send_update "$interface"
|
|
|
|
|
2018-11-14 11:49:45 +00:00
|
|
|
local zone="$(fw3 -q network "$interface" 2>/dev/null)"
|
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
[ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
|
|
|
|
json_init
|
|
|
|
json_add_string name "${interface}_4"
|
|
|
|
json_add_string ifname "@$interface"
|
|
|
|
json_add_string proto "dhcp"
|
|
|
|
proto_add_dynamic_defaults
|
2018-11-14 11:49:45 +00:00
|
|
|
[ -n "$zone" ] && {
|
|
|
|
json_add_string zone "$zone"
|
|
|
|
}
|
|
|
|
json_close_object
|
2016-12-11 15:28:52 +00:00
|
|
|
ubus call network add_dynamic "$(json_dump)"
|
|
|
|
}
|
2014-10-10 08:56:33 +00:00
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
[ "$pdptype" = "IPV6" -o "$pdptype" = "IPV4V6" ] && {
|
2015-09-11 06:46:42 +00:00
|
|
|
json_init
|
|
|
|
json_add_string name "${interface}_6"
|
|
|
|
json_add_string ifname "@$interface"
|
|
|
|
json_add_string proto "dhcpv6"
|
|
|
|
json_add_string extendprefix 1
|
2024-05-15 14:46:08 +00:00
|
|
|
[ "$delegate" = "0" ] && json_add_boolean delegate "0"
|
2024-01-22 14:59:18 +00:00
|
|
|
[ "$sourcefilter" = "0" ] && json_add_boolean sourcefilter "0"
|
2016-10-17 00:38:42 +00:00
|
|
|
proto_add_dynamic_defaults
|
2018-11-14 11:49:45 +00:00
|
|
|
[ -n "$zone" ] && {
|
|
|
|
json_add_string zone "$zone"
|
|
|
|
}
|
|
|
|
json_close_object
|
2015-09-11 06:46:42 +00:00
|
|
|
ubus call network add_dynamic "$(json_dump)"
|
|
|
|
}
|
2016-12-22 21:12:44 +00:00
|
|
|
|
|
|
|
[ -n "$finalize" ] && {
|
|
|
|
eval COMMAND="$finalize" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
|
|
|
|
echo "Failed to configure modem"
|
|
|
|
proto_notify_error "$interface" FINALIZE_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
2014-10-10 08:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proto_ncm_teardown() {
|
|
|
|
local interface="$1"
|
|
|
|
|
|
|
|
local manufacturer disconnect
|
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
local device profile
|
|
|
|
json_get_vars device profile
|
2014-10-10 08:56:33 +00:00
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
[ -n "$ctl_device" ] && device=$ctl_device
|
2014-10-10 08:56:33 +00:00
|
|
|
|
2019-08-24 16:41:01 +00:00
|
|
|
[ -n "$device" ] || {
|
|
|
|
echo "No control device specified"
|
|
|
|
proto_notify_error "$interface" NO_DEVICE
|
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
device="$(readlink -f $device)"
|
|
|
|
[ -e "$device" ] || {
|
|
|
|
echo "Control device not valid"
|
|
|
|
proto_set_available "$interface" 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2016-12-11 15:28:52 +00:00
|
|
|
[ -n "$profile" ] || profile=1
|
|
|
|
|
|
|
|
echo "Stopping network $interface"
|
|
|
|
|
|
|
|
json_load "$(ubus call network.interface.$interface status)"
|
|
|
|
json_select data
|
|
|
|
json_get_vars manufacturer
|
2019-08-24 16:41:01 +00:00
|
|
|
[ $? -ne 0 -o -z "$manufacturer" ] && {
|
|
|
|
# Fallback to direct detect, for proper handle device replug.
|
|
|
|
manufacturer=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | awk 'NF && $0 !~ /AT\+CGMI/ { sub(/\+CGMI: /,""); print tolower($1); exit; }')
|
|
|
|
[ $? -ne 0 -o -z "$manufacturer" ] && {
|
|
|
|
echo "Failed to get modem information"
|
|
|
|
proto_notify_error "$interface" GETINFO_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
json_add_string "manufacturer" "$manufacturer"
|
|
|
|
}
|
2014-10-10 08:56:33 +00:00
|
|
|
|
|
|
|
json_load "$(cat /etc/gcom/ncm.json)"
|
|
|
|
json_select "$manufacturer" || {
|
2015-01-28 19:19:33 +00:00
|
|
|
echo "Unsupported modem"
|
2014-10-10 08:56:33 +00:00
|
|
|
proto_notify_error "$interface" UNSUPPORTED_MODEM
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-01-28 19:19:33 +00:00
|
|
|
json_get_vars disconnect
|
2019-08-24 16:41:01 +00:00
|
|
|
[ -n "$disconnect" ] && {
|
|
|
|
eval COMMAND="$disconnect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
|
|
|
|
echo "Failed to disconnect"
|
|
|
|
proto_notify_error "$interface" DISCONNECT_FAILED
|
|
|
|
return 1
|
|
|
|
}
|
2014-10-10 08:56:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 19:19:33 +00:00
|
|
|
proto_init_update "*" 0
|
|
|
|
proto_send_update "$interface"
|
|
|
|
}
|
|
|
|
[ -n "$INCLUDE_ONLY" ] || {
|
|
|
|
add_protocol ncm
|
|
|
|
}
|