diff --git a/dectmngr/files/etc/init.d/dectmngr b/dectmngr/files/etc/init.d/dectmngr index 4925bbeee..37908d066 100755 --- a/dectmngr/files/etc/init.d/dectmngr +++ b/dectmngr/files/etc/init.d/dectmngr @@ -10,6 +10,7 @@ NAME=dectmngr PROG=/usr/sbin/dectmngr LOG_PATH=/var/log/dectmngr DB_PATH=/etc/dect +DCX81_UART_DT_ALIAS=/proc/device-tree/aliases/dcx81-uart DECT_GPIO=$(db -q get hw.board.dect_gpio) @@ -24,13 +25,43 @@ stop_and_wait_dectmngr() { done } +has_dect() { + [ -f "$DCX81_UART_DT_ALIAS" ] +} + +get_dcx81_device() { + readonly dcx81_uart_dt_node="/proc/device-tree/$(cat "$DCX81_UART_DT_ALIAS" 2>/dev/null)" + [ -e "$dcx81_uart_dt_node" ] || return 1 + for tty_dt_node in /sys/class/tty/*/device/of_node; do + if [ "$tty_dt_node" -ef "$dcx81_uart_dt_node" ]; then + readonly uevent_file="${tty_dt_node%%/device/of_node}/uevent" + local device_name_line + device_name_line="$(grep '^DEVNAME=' "$uevent_file")" || return 1 + readonly device="/dev/${device_name_line##DEVNAME=}" + [ -c "$device" ] || return 1 + printf "%s" "$device" + return 0 + fi + done + return 1 +} + start_service() { local opt_ext= local rfpi= local model_id= local rxtun= - test $(db get hw.board.hasDect) = "0" && return + if ! has_dect; then + logger -t "$PROG" "Not starting because no DECT hardware is available." + return 0 + fi + + local dcx81_uart_device + if ! dcx81_uart_device="$(get_dcx81_device)"; then + logger -t "$PROG" -p daemon.error "Could not determine DCX81 UART device. Cannot start $PROG" + return 1 + fi [ -n "$DECT_GPIO" ] && echo 1 > /sys/class/gpio/gpio${DECT_GPIO}/value @@ -51,19 +82,22 @@ start_service() { config_get log_dect_cmbs global log_dect_cmbs syslog procd_open_instance + + # dectmngr takes expects device without /dev + readonly dcx81_uart_device_wo_dev="${dcx81_uart_device##/dev/}" case "$log_dect_cmbs" in none) echo "Starting dectmngr with cmbs logging disabled" - procd_set_param command $PROG -comname ttyH0 $opt_ext + procd_set_param command "$PROG" -comname "$dcx81_uart_device_wo_dev" $opt_ext rm -f $LOG_PATH/* ;; file) echo "Starting dectmngr with cmbs logging enabled to file" - procd_set_param command $PROG -comname ttyH0 -log $LOG_PATH/dect-cmbs.log $opt_ext + procd_set_param command "$PROG" -comname "$dcx81_uart_device_wo_dev" -log $LOG_PATH/dect-cmbs.log $opt_ext ;; *) echo "Starting dectmngr with cmbs logging enabled to syslog" - procd_set_param command $PROG -comname ttyH0 -syslog $opt_ext + procd_set_param command "$PROG" -comname "$dcx81_uart_device_wo_dev" -syslog $opt_ext rm -f $LOG_PATH/* ;; esac @@ -75,7 +109,7 @@ start_service() { } stop_service() { - test $(db get hw.board.hasDect) = "0" && return + has_dect || return 0 [ -n "$DECT_GPIO" ] && echo 0 > /sys/class/gpio/gpio${DECT_GPIO}/value stop_and_wait_dectmngr