+++ /dev/null
-#
-# This is a minimal example configuration file for ser2net. For a version with
-# detailed comments and all possible configuration directives, please visit:
-# https://github.com/cminyard/ser2net/blob/master/ser2net.conf
-#
-# On OpenWrt/LEDE systems, this configuration serves as a base configuration.
-# During boot of the system, the UCI configuration file /etc/config/ser2net is
-# parsed and converted to additional configuration lines which are _appended_
-# to this file. The ser2net daemon is then started with the combined
-# configuration file /tmp/ser2net.conf.
-#
-# A basic service configuration line has the following format:
-# <network port>:<state>:<timeout>:<device>:<options>
-# network port
-# Name or number of the port to accept connections
-# from for this device. A port number may be of the form
-# [ipv4,|ipv6,][tcp,|udp,][host,]port, such as
-# 127.0.0.1,2000 or ipv4,tcp,localhost,2000. If the host is
-# specified, it will only bind to the IP address
-# specified. Otherwise it will bind to all the ports on the
-# machine. If ipv4 or ipv6 is specified, it will only bind
-# to that network type.
-#
-# state
-# Either raw or rawlp or telnet or off. off disables
-# the port from accepting connections. It can be
-# turned on later from the control port. raw enables
-# the port and transfers all data as-is between the
-# port and the long. rawlp enables the port and
-# transfers all input data to device, device is open
-# without any termios setting. It allow to use
-# /dev/lpX devices and printers connected to them.
-# telnet enables the port and runs the telnet proto-
-# col on the port to set up telnet parameters. This
-# is most useful for using telnet.
-#
-# timeout
-# The time (in seconds) before the port will be dis-
-# connected if there is no activity on it. A zero
-# value disables this function.
-#
-# device
-# The name of the device to connect to. This
-# must be in the form of /dev/<device>.
-#
-# options
-# Sets operational parameters for the serial port.
-# For a serial device (not IPMI SOL):
-# Options 300, 1200, 2400, 4800, 9600, 19200, 38400,
-# 57600, 115200 set the various baud rates. EVEN,
-# ODD, NONE (MARK and SPACE if supported) set the parity.
-# Note that MARK and SPACE are not available on all systems
-# or hardware, if it is not supported then it will be
-# silently set to ODD or EVEN parity.
-# 1STOPBIT, 2STOPBITS set
-# the number of stop bits. 5DATABITS, 6DATABITS,
-# 7DATABITS, 8DATABITS set the number of data bits.
-# [-]XONXOFF turns on (- off) XON/XOFF support.
-# [-]RTSCTS turns on (- off) hardware flow control,
-# [-]LOCAL turns off (- on) monitoring of the modem lines,
-# and [-]HANGUP_WHEN_DONE turns on (- off) lowering the
-# modem control lines when the connection is done.
-# [-]NOBREAK disables automatic setting of the break
-# setting of the serial port.
-#
-# The "[-]remctl" option allow remote control (ala RFC
-# 2217) of serial-port configuration.
-#
-# Example:
-# 5000:telnet:0:/dev/ttyAPP0:115200 8DATABITS NONE 1STOPBIT -XONXOFF -LOCAL -RTSCTS remctl
USE_PROCD=1
PROG=/usr/sbin/ser2net
-STATICCFGFILE="/etc/ser2net.conf"
-DYNAMICCFGFILE="/tmp/ser2net.conf"
+STATICCFGFILE="/etc/ser2net.yaml"
+DYNAMICCFGFILE="/tmp/ser2net.yaml"
list_cb_append() {
local var="$2"
local value="$1"
- local sep="${3:- }"
+ local sep="${3:-,}"
eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
}
-append_bool() {
- local var="$1"
- local key="$2"
- local val="$3"
- local uc="$4"
- local s=""
-
- [ "$uc" -eq 1 ] && key=`echo "$key" | tr '[a-z]' '[A-Z]'`
- [ "$val" -eq 0 ] && s="-"
-
- append "$var" "$s$key"
-}
-
ser2net_default() {
local cfg="$1"
local key val
+ local baudrate parity databits stopbits
+
+ config_get baudrate "$cfg" speed
+ if [ -n "$baudrate" ]; then
+ config_get parity "$cfg" parity
+ case "$parity" in
+ [Nn]one) parity=n ;;
+ [Oo]dd) parity=o ;;
+ [Ee]ven) parity=e ;;
+ "") ;;
+ *) return 1
+ esac
+
+ if [ -n "$parity" ]; then
+ config_get databits "$cfg" databits 8
+ [ "$databits" -ge 5 ] && [ "$databits" -le 9 ] || return 1
+
+ config_get stopbits "$cfg" stopbits 1
+ case "$stopbits" in
+ 1) ;;
+ 2) ;;
+ *) return 1
+ esac
+ fi
+
+ echo "default:"
+ echo " name: speed"
+ echo " value: $baudrate${parity:+$parity$databits$stopbits}"
+ fi
- for key in speed baudrate databits stopbits parity chardelay_scale chardelay_min; do
+ for key in chardelay_scale chardelay_min; do
config_get val "$cfg" "$key"
[ -n "$val" ] || continue
-
- case "$key" in
- baudrate) key="speed" ;;
- hangup_when_done) ;;
- telnet_brk_on_sync) ;;
- deassert_CTS_DCD_DSR_on_connect) ;;
- *) key=`echo "$key" | tr '_' '-'`
- esac
-
- echo "DEFAULT:$key:$val"
+ key=`echo "$key" | tr '_' '-'`
+ echo "default:"
+ echo " name: $key"
+ echo " value: $val"
done
for key in chardelay deassert_CTS_DCD_DSR_on_connect hangup_when_done kickolduser \
local nobreak remctl rtscts telnet_brk_on_sync xonxoff; do
+ case "$key" in
+ remctl) key=rfc2217 ;;
+ esac
config_get_bool val "$cfg" "$key"
[ -n "$val" ] || continue
+ key=`echo "$key" | tr '_' '-'`
[ "$val" -eq 0 ] && val="false" || val="true"
- echo "DEFAULT:$key:$val"
+ echo "default:"
+ echo " name: $key"
+ echo " value: $val"
done
echo
config_get host "$cfg" host
config_get port "$cfg" port
+ [ "$port" -ge 1 ] && [ "$port" -le 65535 ] || return 1
+
+ echo "admin:"
+ echo " accepter: tcp,${host:+$host,}$port"
- echo -e "CONTROLPORT:${host:+$host,}$port\n"
+ echo
}
ser2net_led() {
config_get driver "$cfg" driver sysfs
config_get device "$cfg" device
- config_get state "$cfg" state 1
- config_get duration "$cfg" duration 20
+ [ -z "$device" ] && return 1
+ config_get duration "$cfg" duration
+ config_get state "$cfg" state
+
+ echo "led: &$cfg"
+ echo " driver: $driver"
+ echo " options:"
+ echo " device: \"$device\""
+ [ -n "$duration" ] && echo " duration: $duration"
+ [ -n "$state" ] && echo " state: $state"
- echo -e "LED:$cfg:$driver:device=$device state=$state duration=$duration\n"
+ echo
}
ser2net_proxy() {
local cfg="$1"
local enabled port protocol timeout device baudrate databits parity stopbits
- local led_tx led_rx key boolval options
+ local key boolval options custom_options
+ local echo_options=1
config_get_bool enabled "$cfg" enabled 0
- [ "$enabled" -eq 0 ] && return 0
+
+ config_get device "$cfg" device
+ [ -z "$device" ] && return 1
config_get port "$cfg" port
- [ "$port" -le 0 -o "$port" -gt 65535 ] && return 1
+ [ "$port" -ge 1 ] && [ "$port" -le 65535 ] || return 1
config_get protocol "$cfg" protocol
case "$protocol" in
- raw|rawlp|telnet|off) ;;
+ raw)
+ protocol="tcp"
+ ;;
+ rawlp)
+ protocol="tcp"
+ options="wronly"
+ ;;
+ telnet)
+ protocol="telnet,tcp"
+
+ config_get_bool boolval "$cfg" remctl 0
+ [ "$boolval" -eq 1 ] && protocol="telnet(rfc2217),tcp"
+ ;;
+ off)
+ enabled=0
+ ;;
*) return 1
esac
- config_get timeout "$cfg" timeout 0
- config_get device "$cfg" device
- [ -z "$device" ] && return 1
-
config_get baudrate "$cfg" baudrate
- [ -n "$baudrate" ] && append options "$baudrate"
+ if [ -n "$baudrate" ]; then
+ config_get parity "$cfg" parity
+ case "$parity" in
+ [Nn]one) parity=n ;;
+ [Oo]dd) parity=o ;;
+ [Ee]ven) parity=e ;;
+ "") ;;
+ *) return 1
+ esac
- config_get databits "$cfg" databits
- if [ -n "$databits" ]; then
- [ "$databits" -lt 5 -o "$databits" -gt 8 ] && return 1
- append options "${databits}DATABITS"
+ if [ -n "$parity" ]; then
+ config_get databits "$cfg" databits 8
+ [ "$databits" -ge 5 ] && [ "$databits" -le 9 ] || return 1
+
+ config_get stopbits "$cfg" stopbits 1
+ case "$stopbits" in
+ 1) ;;
+ 2) ;;
+ *) return 1
+ esac
+ fi
fi
- config_get parity "$cfg" parity
- parity=`echo "$parity" | tr '[a-z]' '[A-Z]'`
- case "$parity" in
- EVEN|ODD|NONE|MARK|SPACE) append options "$parity" ;;
- "") ;;
- *) return 1
- esac
-
- config_get stopbits "$cfg" stopbits
- case "$stopbits" in
- 1) append options "${stopbits}STOPBIT" ;;
- 2) append options "${stopbits}STOPBITS" ;;
- "") ;;
- *) return 1
- esac
-
- config_get led_tx "$cfg" led_tx
- [ -n "$led_tx" ] && append options "led-tx=$led_tx"
-
- config_get led_rx "$cfg" led_rx
- [ -n "$led_rx" ] && append options "led-rx=$led_rx"
+ config_get timeout "$cfg" timeout 0
for key in rtscts local xonxoff nobreak hangup_when_done; do
config_get_bool boolval "$cfg" "$key"
[ -n "$boolval" ] || continue
- append_bool options "$key" "$boolval" 1
+ key=`echo "$key" | tr '_' '-'`
+ options="${options:+$options,}$key"
+ [ "$boolval" -eq 0 ] && options="$options=false"
+ done
+
+ config_list_foreach "$cfg" options list_cb_append custom_options
+
+ echo "connection: &$cfg"
+ echo " accepter: $protocol,$port"
+ echo " timeout: $timeout"
+ [ "$enabled" -eq 0 ] && echo " enable: off"
+ echo " connector: serialdev,$device${baudrate:+,$baudrate${parity:+$parity$databits$stopbits}}${options:+,$options}${custom_options:+,$custom_options}"
+
+ for key in led_tx led_rx; do
+ config_get val "$cfg" "$key"
+ [ -n "$val" ] || continue
+ [ "$echo_options" -eq 1 ] && echo " options:" && echo_options=0
+ key=`echo "$key" | tr '_' '-'`
+ echo " $key: *$val"
done
- for key in chardelay telnet_brk_on_sync kickolduser remctl; do
+ for key in chardelay telnet_brk_on_sync kickolduser; do
config_get_bool boolval "$cfg" "$key"
[ -n "$boolval" ] || continue
- append_bool options "$key" "$boolval" 0
+ [ "$echo_options" -eq 1 ] && echo " options:" && echo_options=0
+ key=`echo "$key" | tr '_' '-'`
+ echo " $key: $boolval"
done
- config_list_foreach "$cfg" options list_cb_append options
-
- if [ "`echo "$device" | sed 's/://g'`" != "$device" ]; then
- echo "DEVICE:$cfg:$device"
- device="$cfg"
- fi
-
- echo -e "$port:$protocol:$timeout:$device:$options\n"
+ echo
}
start_service() {
[ "$enabled" -gt 0 ] || return 0
cat "$STATICCFGFILE" - 2>/dev/null <<-EOF > "$DYNAMICCFGFILE"
-
+
#
# Following part is auto-generated from UCI settings in /etc/config/ser2net
#
EOF
- config_foreach ser2net_controlport controlport >> "$DYNAMICCFGFILE"
config_foreach ser2net_default default >> "$DYNAMICCFGFILE"
config_foreach ser2net_led led >> "$DYNAMICCFGFILE"
+ config_foreach ser2net_controlport controlport >> "$DYNAMICCFGFILE"
config_foreach ser2net_proxy proxy >> "$DYNAMICCFGFILE"
procd_open_instance