From 33e2115fe449d1b9e97ce8c5be96f580442fd3d9 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 23 Aug 2022 15:18:49 +0200 Subject: ltq-vdsl-app: rename to ltq-vdsl-vr9-app This matches the scheme used by other target packages and will avoid confusion with any future version. Signed-off-by: Andre Heider --- package/network/config/ltq-adsl-app/Makefile | 2 +- .../100-add-more-script-notifications.patch | 2 +- package/network/config/ltq-vdsl-app/Makefile | 82 -- .../network/config/ltq-vdsl-app/files/10_atm.sh | 14 - .../network/config/ltq-vdsl-app/files/10_ptm.sh | 14 - .../network/config/ltq-vdsl-app/files/dsl_control | 322 -------- .../config/ltq-vdsl-app/files/dsl_cpe_pipe.sh | 18 - .../config/ltq-vdsl-app/patches/100-compat.patch | 11 - .../config/ltq-vdsl-app/patches/101-musl.patch | 10 - .../config/ltq-vdsl-app/patches/200-autoboot.patch | 86 -- .../config/ltq-vdsl-app/patches/201-sigterm.patch | 19 - .../config/ltq-vdsl-app/patches/300-ubus.patch | 50 -- .../config/ltq-vdsl-app/src/src/dsl_cpe_ubus.c | 883 --------------------- package/network/config/ltq-vdsl-vr9-app/Makefile | 82 ++ .../config/ltq-vdsl-vr9-app/files/10_atm.sh | 14 + .../config/ltq-vdsl-vr9-app/files/10_ptm.sh | 14 + .../config/ltq-vdsl-vr9-app/files/dsl_control | 322 ++++++++ .../config/ltq-vdsl-vr9-app/files/dsl_cpe_pipe.sh | 18 + .../ltq-vdsl-vr9-app/patches/100-compat.patch | 11 + .../config/ltq-vdsl-vr9-app/patches/101-musl.patch | 10 + .../ltq-vdsl-vr9-app/patches/200-autoboot.patch | 86 ++ .../ltq-vdsl-vr9-app/patches/201-sigterm.patch | 19 + .../config/ltq-vdsl-vr9-app/patches/300-ubus.patch | 50 ++ .../config/ltq-vdsl-vr9-app/src/src/dsl_cpe_ubus.c | 883 +++++++++++++++++++++ 24 files changed, 1511 insertions(+), 1511 deletions(-) delete mode 100644 package/network/config/ltq-vdsl-app/Makefile delete mode 100755 package/network/config/ltq-vdsl-app/files/10_atm.sh delete mode 100755 package/network/config/ltq-vdsl-app/files/10_ptm.sh delete mode 100644 package/network/config/ltq-vdsl-app/files/dsl_control delete mode 100755 package/network/config/ltq-vdsl-app/files/dsl_cpe_pipe.sh delete mode 100644 package/network/config/ltq-vdsl-app/patches/100-compat.patch delete mode 100644 package/network/config/ltq-vdsl-app/patches/101-musl.patch delete mode 100644 package/network/config/ltq-vdsl-app/patches/200-autoboot.patch delete mode 100644 package/network/config/ltq-vdsl-app/patches/201-sigterm.patch delete mode 100644 package/network/config/ltq-vdsl-app/patches/300-ubus.patch delete mode 100644 package/network/config/ltq-vdsl-app/src/src/dsl_cpe_ubus.c create mode 100644 package/network/config/ltq-vdsl-vr9-app/Makefile create mode 100755 package/network/config/ltq-vdsl-vr9-app/files/10_atm.sh create mode 100755 package/network/config/ltq-vdsl-vr9-app/files/10_ptm.sh create mode 100644 package/network/config/ltq-vdsl-vr9-app/files/dsl_control create mode 100755 package/network/config/ltq-vdsl-vr9-app/files/dsl_cpe_pipe.sh create mode 100644 package/network/config/ltq-vdsl-vr9-app/patches/100-compat.patch create mode 100644 package/network/config/ltq-vdsl-vr9-app/patches/101-musl.patch create mode 100644 package/network/config/ltq-vdsl-vr9-app/patches/200-autoboot.patch create mode 100644 package/network/config/ltq-vdsl-vr9-app/patches/201-sigterm.patch create mode 100644 package/network/config/ltq-vdsl-vr9-app/patches/300-ubus.patch create mode 100644 package/network/config/ltq-vdsl-vr9-app/src/src/dsl_cpe_ubus.c (limited to 'package/network/config') diff --git a/package/network/config/ltq-adsl-app/Makefile b/package/network/config/ltq-adsl-app/Makefile index 2e4792266c..3bc247dfb0 100644 --- a/package/network/config/ltq-adsl-app/Makefile +++ b/package/network/config/ltq-adsl-app/Makefile @@ -77,7 +77,7 @@ TARGET_CFLAGS += -I$(LINUX_DIR)/include define Build/Prepare $(call Build/Prepare/Default) - $(CP) ../ltq-vdsl-app/src/src/dsl_cpe_ubus.c $(PKG_BUILD_DIR)/src/ + $(CP) ../ltq-vdsl-vr9-app/src/src/dsl_cpe_ubus.c $(PKG_BUILD_DIR)/src/ endef define Package/ltq-adsl-app/install diff --git a/package/network/config/ltq-adsl-app/patches/100-add-more-script-notifications.patch b/package/network/config/ltq-adsl-app/patches/100-add-more-script-notifications.patch index 9d611c1caf..875b7ecbf5 100644 --- a/package/network/config/ltq-adsl-app/patches/100-add-more-script-notifications.patch +++ b/package/network/config/ltq-adsl-app/patches/100-add-more-script-notifications.patch @@ -3,7 +3,7 @@ From: Mathias Kresin Date: Mon, 16 Oct 2017 21:08:26 +0200 Subject: ltq-adsl-app: add more script notifications -Backport HANDSHAKE and TRAINING notification from ltq-vdsl-app. It +Backport HANDSHAKE and TRAINING notification from ltq-vdsl-vr9-app. It unifies the dsl led blinking pattern accross all subtargets and allows to get the current line status from the dsl led. diff --git a/package/network/config/ltq-vdsl-app/Makefile b/package/network/config/ltq-vdsl-app/Makefile deleted file mode 100644 index 8baf1e8263..0000000000 --- a/package/network/config/ltq-vdsl-app/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -# Copyright (C) 2010 OpenWrt.org -# Copyright (C) 2015-2016 Lantiq Beteiligungs GmbH & Co KG. -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. - -include $(TOPDIR)/rules.mk -include $(INCLUDE_DIR)/kernel.mk - -PKG_NAME:=ltq-vdsl-app -PKG_VERSION:=4.17.18.6 -PKG_RELEASE:=$(AUTORELEASE) -PKG_BASE_NAME:=dsl_cpe_control -PKG_SOURCE:=$(PKG_BASE_NAME)_vrx-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=@OPENWRT -PKG_HASH:=da8bb929526a61aea0e153ef524331fcd472a1ebbc6d88ca017735a4f82ece02 -PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_BASE_NAME)-$(PKG_VERSION) -PKG_LICENSE:=BSD-2-Clause - -PKG_BUILD_DEPENDS:=ltq-vdsl-vr9 - -PKG_FLAGS:=nonshared -PKG_FIXUP:=autoreconf - -include $(INCLUDE_DIR)/package.mk - -define Package/ltq-vdsl-app - SECTION:=net - CATEGORY:=Network - TITLE:=Lantiq VDSL userland tool - URL:=http://www.lantiq.com/ - DEPENDS:=@TARGET_lantiq_xrx200 +libpthread +librt +ltq-dsl-base +libubox +libubus -endef - -define Package/ltq-vdsl-app/description - Userland tool needed to control Lantiq VDSL CPE -endef - -# ltq-vdsl-app uses a header provided by the MEI driver which has some -# conditionals. -# -# Define them here with the default values they would get in the MEI driver, -# have the same view on both sides. -# -# If you change them, you need to change them for the ltq-vdsl-app as well -VDSL_APP_CFLAGS = \ - -DMAX_CLI_PIPES=1 \ - -DMEI_SUPPORT_DEBUG_STREAMS=1 \ - -DMEI_SUPPORT_OPTIMIZED_FW_DL=1 - -CONFIGURE_ARGS += \ - --enable-vrx \ - --enable-vrx-device=vr9 \ - --enable-driver-include="-I$(STAGING_DIR)/usr/include/drv_vdsl_cpe_api" \ - --enable-device-driver-include="-I$(STAGING_DIR)/usr/include/vdsl/" \ - --enable-ifxos \ - --enable-ifxos-include="-I$(STAGING_DIR)/usr/include/ifxos" \ - --enable-ifxos-library="-I$(STAGING_DIR)/usr/lib" \ - --enable-add-appl-cflags="$(VDSL_APP_CFLAGS)" \ - --enable-debug \ - --disable-dti \ - --with-channels-per-line="1" - -CONFIGURE_ARGS += \ - --enable-model=full \ - --enable-dsl-ceoc=no -#CONFIGURE_ARGS += --enable-model=lite -#CONFIGURE_ARGS += --enable-model=footprint -#CONFIGURE_ARGS += --enable-model=typical -#CONFIGURE_ARGS += --enable-model=debug - -define Package/ltq-vdsl-app/install - $(INSTALL_DIR) $(1)/etc/init.d $(1)/sbin $(1)/etc/hotplug.d/dsl - $(INSTALL_BIN) ./files/dsl_control $(1)/etc/init.d/ - $(INSTALL_BIN) ./files/10_atm.sh $(1)/etc/hotplug.d/dsl - $(INSTALL_BIN) ./files/10_ptm.sh $(1)/etc/hotplug.d/dsl - - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/dsl_cpe_control $(1)/sbin/vdsl_cpe_control - $(INSTALL_BIN) ./files/dsl_cpe_pipe.sh $(1)/sbin/ -endef - -$(eval $(call BuildPackage,ltq-vdsl-app)) diff --git a/package/network/config/ltq-vdsl-app/files/10_atm.sh b/package/network/config/ltq-vdsl-app/files/10_atm.sh deleted file mode 100755 index e104a14b2e..0000000000 --- a/package/network/config/ltq-vdsl-app/files/10_atm.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -[ "$DSL_NOTIFICATION_TYPE" = "DSL_STATUS" ] && \ -[ "$DSL_TC_LAYER_STATUS" = "ATM" ] && \ -! grep -q "ltq_atm_vr9" /proc/modules || exit 0 - -logger -p daemon.notice -t "dsl-notify" "Switching to TC-Layer ATM" - -if grep -q "ltq_ptm_vr9" /proc/modules ; then - logger -p daemon.notice -t "dsl-notify" "Loading ATM driver while EFM/PTM driver is loaded is not possible. Reboot is needed." - exit -fi - -modprobe ltq_atm_vr9 diff --git a/package/network/config/ltq-vdsl-app/files/10_ptm.sh b/package/network/config/ltq-vdsl-app/files/10_ptm.sh deleted file mode 100755 index 1c62617bba..0000000000 --- a/package/network/config/ltq-vdsl-app/files/10_ptm.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -[ "$DSL_NOTIFICATION_TYPE" = "DSL_STATUS" ] && \ -[ "$DSL_TC_LAYER_STATUS" = "EFM" ] && \ -! grep -q "ltq_ptm_vr9" /proc/modules || exit 0 - -logger -p daemon.notice -t "dsl-notify" "Switching to TC-Layer EFM/PTM" - -if grep -q "ltq_atm_vr9" /proc/modules ; then - logger -p daemon.notice -t "dsl-notify" "Loading EFM/PTM driver while ATM driver is loaded is not possible. Reboot is needed." - exit -fi - -modprobe ltq_ptm_vr9 diff --git a/package/network/config/ltq-vdsl-app/files/dsl_control b/package/network/config/ltq-vdsl-app/files/dsl_control deleted file mode 100644 index 34642dbda5..0000000000 --- a/package/network/config/ltq-vdsl-app/files/dsl_control +++ /dev/null @@ -1,322 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2012 OpenWrt.org - -START=97 -USE_PROCD=1 - -dslstat() { - ubus call dsl metrics -} - -extra_command "dslstat" "Get DSL status information" - -# -# ITU-T G.997.1 (06/2012) - Section 7.3.1.1.1 (xTU transmission system enabling (XTSE)) -# ITU-T G.997.1 Amendment 2 (04/2013) - Section 2.1 - (Vectoring mode enable (VECTORMODE_ENABLE)) -# -# G.992.1 Annex A -# G.992.2 Annex A -# G.992.3 Annex A / L-US1 / L_US-2 / M -# G.992.5 Annex A / M -# G.993.2 Annex A/B/C -# G.993.5 Annex A/B/C -xtse_xdsl_a="05_01_04_00_4C_01_04_07" - -# G.992.1 Annex B -# G.992.3 Annex B -# G.992.5 Annex B -# G.993.2 Annex A/B/C -# G.993.5 Annex A/B/C -xtse_xdsl_b="10_00_10_00_00_04_00_07" - -# G.992.1 Annex B -# G.992.3 Annex B -# G.992.3 Annex J -# G.992.5 Annex B -# G.992.5 Annex J -# G.993.2 Annex A/B/C -# G.993.5 Annex A/B/C -xtse_xdsl_j="10_00_10_40_00_04_01_07" - -# G.992.1 Annex B -xtse_xdsl_bdmt="10_00_00_00_00_00_00_00" - -# G.992.3 Annex B -xtse_xdsl_b2="00_00_10_00_00_00_00_00" - -# G.992.5 Annex B -xtse_xdsl_b2p="00_00_00_00_00_04_00_00" - -# ANSI T1.413 -xtse_xdsl_at1="01_00_00_00_00_00_00_00" - -# G.992.2 Annex A -xtse_xdsl_alite="00_01_00_00_00_00_00_00" - -# G.992.1 Annex A -xtse_xdsl_admt="04_00_00_00_00_00_00_00" - -# G.992.3 Annex A -xtse_xdsl_a2="00_00_04_00_00_00_00_00" - -# G.992.5 Annex A -xtse_xdsl_a2p="00_00_00_00_00_01_00_00" - -# G.992.3 Annex L -xtse_xdsl_l="00_00_00_00_0C_00_00_00" - -# G.992.3 Annex M -# G.992.5 Annex M -xtse_xdsl_m="00_00_00_00_40_00_04_00" - -# G.992.3 Annex M -xtse_xdsl_m2="00_00_00_00_40_00_00_00" - -# G.992.5 Annex M -xtse_xdsl_m2p="00_00_00_00_00_00_04_00" - -# -# ITU-T G.994.1 (06/2012) - Table 2 (Mandatory carrier sets) -# - -# A43 -tone_adsl_a="0x142" # A43C + J43 + A43 -tone_vdsl_a="0x142" # A43C + J43 + A43 - -# A43 + V43 -tone_adsl_av="0x142" # A43C + J43 + A43 -tone_vdsl_av="0x146" # A43C + J43 + A43 + V43 - -# B43 -tone_adsl_b="0x81" # B43 + B43c -tone_vdsl_b="0x1" # B43 - -# B43 + V43 -tone_adsl_bv="0x81" # B43 + B43c -tone_vdsl_bv="0x5" # B43 + V43 - -# create DSL autoboot script. Used for SNR margin tweak and to set MAC address for vectoring error reports -autoboot_script() { - echo "[WaitForConfiguration]={ -locs 0 $1 -dsmmcs $2 -} - -[WaitForLinkActivate]={ -} - -[WaitForRestart]={ -} - -[Common]={ -}" > /tmp/dsl.scr -} - -lowlevel_cfg() { - echo "# VRX Low Level Configuration File -# -# Parameters must be separated by tabs or spaces. -# Empty lines and comments will be ignored. -# - -# nFilter -# -# NA = -1 -# OFF = 0 -# ISDN = 1 -# POTS = 2 -# POTS_2 = 3 -# POTS_3 = 4 -# -# (dec) - -1 - -# nHsToneGroupMode nHsToneGroup_A nHsToneGroup_V nHsToneGroup_AV -# -# NA = -1 NA = -1 see see -# AUTO = 0 VDSL2_B43 = 0x0001 nHsToneGroup_A nHsToneGroup_A -# MANUAL = 1 VDSL2_A43 = 0x0002 -# VDSL2_V43 = 0x0004 -# VDSL1_V43P = 0x0008 -# VDSL1_V43I = 0x0010 -# ADSL1_C43 = 0x0020 -# ADSL2_J43 = 0x0040 -# ADSL2_B43C = 0x0080 -# ADSL2_A43C = 0x0100 -# -# (dec) (hex) (hex) (hex) - 1 $1 $2 0x0 - -# nBaseAddr nIrqNum -# -# (hex) (dec) - 0x1e116000 63 - -# nUtopiaPhyAdr nUtopiaBusWidth nPosPhyParity -# default(16b) = 0 NA = -1 -# 8-bit = 1 ODD = 0 -# 16-bit = 2 -# -# -# (hex) (dec) (dec) - 0xFF 0 0 - -# bNtrEnable -# -# (dec) - 0" > /tmp/lowlevel.cfg -} - -get_macaddr() { - local name - config_get name $1 name - [ "$name" = "dsl0" ] && config_get $2 $1 macaddr -} - -service_triggers() { - procd_add_reload_trigger network -} - -start_service() { - local annex - local firmware - local tone - local tone_adsl - local tone_vdsl - local xtse - local xfer_mode - local line_mode - local tc_layer - local mode - local lowlevel - local snr - local macaddr - - config_load network - config_get tone dsl tone - config_get annex dsl annex - config_get firmware dsl firmware - config_get xfer_mode dsl xfer_mode - config_get line_mode dsl line_mode - config_get snr dsl ds_snr_offset - config_foreach get_macaddr device macaddr - - eval "xtse=\"\${xtse_xdsl_$annex}\"" - - case "${xfer_mode}" in - atm) - tc_layer="-T1:0x1:0x1_1:0x1:0x1" - ;; - ptm) - tc_layer="-T2:0x1:0x1_2:0x1:0x1" - ;; - esac - - case "${line_mode}" in - adsl) - mode="-M1" - - # mask out VDSL bits when ADSL is requested - xtse="${xtse%_*}_00" - ;; - vdsl) - mode="-M2" - - # mask out ADSL bits when VDSL is requested - xtse="00_00_00_00_00_00_00_${xtse##*_}" - ;; - esac - - local annexgpio="/sys/class/gpio/annex" - if [ -d "${annexgpio}a" ] && [ -d "${annexgpio}b" ]; then - case "${annex}" in - a*|l*|m*) - echo 1 > "${annexgpio}a/value" - echo 0 > "${annexgpio}b/value" - ;; - b*|j*) - echo 0 > "${annexgpio}a/value" - echo 1 > "${annexgpio}b/value" - ;; - esac - fi - - if [ -z "${firmware}" ]; then - # search for the firmware provided by dsl-vrx200-firmware-xdsl-* - if grep -qE "system type.*: (VR9|xRX200)" /proc/cpuinfo; then - case "${annex}" in - a*|l*|m*) - if [ -f "/lib/firmware/lantiq-vrx200-a.bin" ]; then - firmware="/lib/firmware/lantiq-vrx200-a.bin" - elif [ -f "/tmp/lantiq-vrx200-a.bin" ]; then - firmware="/tmp/lantiq-vrx200-a.bin" - elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-b-to-a.bspatch" ]; then - bspatch /lib/firmware/lantiq-vrx200-b.bin \ - /tmp/lantiq-vrx200-a.bin \ - /lib/firmware/lantiq-vrx200-b-to-a.bspatch - firmware="/tmp/lantiq-vrx200-a.bin" - else - echo "firmware for annex a not found" - return 1 - fi - ;; - b*|j*) - if [ -f "/lib/firmware/vr9_dsl_fw_annex_b.bin" ]; then - firmware="/lib/firmware/vr9_dsl_fw_annex_b.bin" - elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ]; then - firmware="/lib/firmware/lantiq-vrx200-b.bin" - elif [ -f "/tmp/lantiq-vrx200-b.bin" ]; then - firmware="/tmp/lantiq-vrx200-b.bin" - elif [ -f "/lib/firmware/lantiq-vrx200-a.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-a-to-b.bspatch" ]; then - bspatch /lib/firmware/lantiq-vrx200-a.bin \ - /tmp/lantiq-vrx200-b.bin \ - /lib/firmware/lantiq-vrx200-a-to-b.bspatch - firmware="/tmp/lantiq-vrx200-b.bin" - else - echo "firmware for annex b not found" - return 1 - fi - ;; - *) - echo "annex type not supported use a or b" - return 1 - ;; - esac - fi - fi - - [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin - [ -f "${firmware}" ] || { - echo failed to find $firmware - return 1 - } - - eval "tone_adsl=\"\${tone_adsl_$tone}\"" - eval "tone_vdsl=\"\${tone_vdsl_$tone}\"" - [ -n "${tone_adsl}" ] && [ -n "${tone_vdsl}" ] && { - lowlevel_cfg "${tone_adsl}" "${tone_vdsl}" - lowlevel="-l /tmp/lowlevel.cfg" - } - - [ -z "${snr}" ] && snr=0 - [ -z "${macaddr}" ] && macaddr="00:00:00:00:00:00" - autoboot_script "$snr" "$macaddr" - autoboot="-a /tmp/dsl.scr -A /tmp/dsl.scr" - - procd_open_instance - procd_set_param command /sbin/vdsl_cpe_control \ - -i$xtse \ - -n /sbin/dsl_notify.sh \ - -f ${firmware} \ - $lowlevel \ - ${mode} \ - ${tc_layer} \ - $autoboot - procd_close_instance -} - -stop_service() { - DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \ - DSL_INTERFACE_STATUS="DOWN" \ - /sbin/dsl_notify.sh -} diff --git a/package/network/config/ltq-vdsl-app/files/dsl_cpe_pipe.sh b/package/network/config/ltq-vdsl-app/files/dsl_cpe_pipe.sh deleted file mode 100755 index 9002b7b316..0000000000 --- a/package/network/config/ltq-vdsl-app/files/dsl_cpe_pipe.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -pipe_no=0 - -# use specified pipe no -case "$1" in -0|1|2) -pipe_no=$1; shift; ;; -esac - - -#echo "Call dsl_pipe with $*" -lock /var/lock/dsl_pipe -echo $* > /tmp/pipe/dsl_cpe${pipe_no}_cmd -result=$(cat /tmp/pipe/dsl_cpe${pipe_no}_ack) -lock -u /var/lock/dsl_pipe - -echo "$result" diff --git a/package/network/config/ltq-vdsl-app/patches/100-compat.patch b/package/network/config/ltq-vdsl-app/patches/100-compat.patch deleted file mode 100644 index 6bc359c3cc..0000000000 --- a/package/network/config/ltq-vdsl-app/patches/100-compat.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/src/dsl_cpe_init_cfg.c -+++ b/src/dsl_cpe_init_cfg.c -@@ -38,7 +38,7 @@ DSL_InitData_t gInitCfgData = - DSL_DEV_HS_TONE_GROUP_CLEANED, \ - DSL_DEV_HS_TONE_GROUP_CLEANED, \ - DSL_DEV_HS_TONE_GROUP_CLEANED, \ -- 0x1E116000, 0x37, -1), -+ 0x1E116000, 0x3f, -1), - DSL_CPE_SIC_SET(DSL_TC_ATM, DSL_EMF_TC_CLEANED, DSL_EMF_TC_CLEANED, DSL_SYSTEMIF_MII, \ - DSL_TC_EFM, DSL_EMF_TC_CLEANED, DSL_EMF_TC_CLEANED, DSL_SYSTEMIF_MII), - DSL_CPE_MAC_CFG_SET(DSL_EFM_SPEED_100, DSL_EFM_DUPLEX_FULL, DSL_EFM_FLOWCTRL_ON, DSL_EFM_AUTONEG_OFF, \ diff --git a/package/network/config/ltq-vdsl-app/patches/101-musl.patch b/package/network/config/ltq-vdsl-app/patches/101-musl.patch deleted file mode 100644 index d66045db61..0000000000 --- a/package/network/config/ltq-vdsl-app/patches/101-musl.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- a/src/dsl_cpe_control.c -+++ b/src/dsl_cpe_control.c -@@ -11,6 +11,7 @@ - /* - Includes - */ -+#include - #include "dsl_cpe_control.h" - #include "dsl_cpe_cli.h" - #include "dsl_cpe_cli_console.h" diff --git a/package/network/config/ltq-vdsl-app/patches/200-autoboot.patch b/package/network/config/ltq-vdsl-app/patches/200-autoboot.patch deleted file mode 100644 index cc6feb94aa..0000000000 --- a/package/network/config/ltq-vdsl-app/patches/200-autoboot.patch +++ /dev/null @@ -1,86 +0,0 @@ -This enables automatic connection after the control daemon is started, -and also stops the connection on termination. - -Using the autoboot restart command is necessary because the stop command -doesn't actually stop the connection, and would also leave the driver in -a state where an explicit start command is necessary to connect again. - ---- a/src/dsl_cpe_init_cfg.c -+++ b/src/dsl_cpe_init_cfg.c -@@ -27,7 +27,7 @@ DSL_InitData_t gInitCfgData = - DSL_CPE_FW2_SET(DSL_NULL, 0x0), - DSL_CPE_XTU_SET(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7), - DSL_CPE_LINE_INV_NE_SET(DSL_NULL), -- DSL_CPE_AUTOBOOT_CTRL_SET(DSL_AUTOBOOT_CTRL_STOP), -+ DSL_CPE_AUTOBOOT_CTRL_SET(DSL_AUTOBOOT_CTRL_START), - DSL_CPE_AUTOBOOT_CFG_SET(DSL_FALSE, DSL_FALSE, DSL_FALSE), - DSL_CPE_TEST_MODE_CTRL_SET(DSL_TESTMODE_DISABLE), - DSL_CPE_LINE_ACTIVATE_CTRL_SET(DSL_G997_INHIBIT_LDSF, DSL_G997_INHIBIT_ACSF, DSL_G997_NORMAL_STARTUP), ---- a/src/dsl_cpe_control.c -+++ b/src/dsl_cpe_control.c -@@ -6515,10 +6515,13 @@ DSL_CPE_STATIC void DSL_CPE_Termination - DSL_CPE_STATIC DSL_void_t DSL_CPE_Termination (void) - { - #ifdef INCLUDE_DSL_CPE_CLI_SUPPORT -- DSL_int_t nDevice = 0; - DSL_char_t buf[32] = "quit"; - #endif - -+ DSL_Error_t nRet = DSL_SUCCESS; -+ DSL_int_t nDevice = 0; -+ DSL_AutobootConfig_t sAutobootCfg; -+ DSL_AutobootControl_t sAutobootCtl; - DSL_CPE_Control_Context_t *pCtrlCtx; - - pCtrlCtx = DSL_CPE_GetGlobalContext(); -@@ -6527,6 +6530,50 @@ DSL_CPE_STATIC DSL_void_t DSL_CPE_Termi - pCtrlCtx->bRun = DSL_FALSE; - } - -+ for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; ++nDevice) -+ { -+ g_bWaitBeforeConfigWrite[nDevice] = DSL_TRUE; -+ g_bWaitBeforeLinkActivation[nDevice] = DSL_TRUE; -+ g_bWaitBeforeRestart[nDevice] = DSL_TRUE; -+ -+ g_bAutoContinueWaitBeforeConfigWrite[nDevice] = DSL_FALSE; -+ g_bAutoContinueWaitBeforeLinkActivation[nDevice] = DSL_FALSE; -+ g_bAutoContinueWaitBeforeRestart[nDevice] = DSL_FALSE; -+ -+ memset(&sAutobootCfg, 0x0, sizeof(DSL_AutobootConfig_t)); -+ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeConfigWrite = DSL_TRUE; -+ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeLinkActivation = DSL_TRUE; -+ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeRestart = DSL_TRUE; -+ -+ nRet = (DSL_Error_t)DSL_CPE_Ioctl( -+ DSL_CPE_GetGlobalContext()->fd[nDevice], -+ DSL_FIO_AUTOBOOT_CONFIG_SET, (DSL_int_t)&sAutobootCfg); -+ -+ if (nRet < DSL_SUCCESS) -+ { -+ DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX -+ "Autoboot configuration for device (%d) failed!, nRet = %d!" -+ DSL_CPE_CRLF, nDevice, sAutobootCtl.accessCtl.nReturn)); -+ } -+ -+ memset(&sAutobootCtl, 0, sizeof(DSL_AutobootControl_t)); -+ sAutobootCtl.data.nCommand = DSL_AUTOBOOT_CTRL_RESTART; -+ -+ nRet = (DSL_Error_t)DSL_CPE_Ioctl( -+ DSL_CPE_GetGlobalContext()->fd[nDevice], -+ DSL_FIO_AUTOBOOT_CONTROL_SET, (DSL_int_t)&sAutobootCtl); -+ -+ if (nRet < DSL_SUCCESS) -+ { -+ DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX -+ "Autoboot restart for device (%d) failed!, nRet = %d!" -+ DSL_CPE_CRLF, nDevice, sAutobootCtl.accessCtl.nReturn)); -+ } -+ } -+ -+ DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX -+ "Autoboot restart executed" DSL_CPE_CRLF)); -+ - #ifdef INCLUDE_DSL_CPE_CLI_SUPPORT - for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; nDevice++) - { diff --git a/package/network/config/ltq-vdsl-app/patches/201-sigterm.patch b/package/network/config/ltq-vdsl-app/patches/201-sigterm.patch deleted file mode 100644 index 4e97835983..0000000000 --- a/package/network/config/ltq-vdsl-app/patches/201-sigterm.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- a/src/dsl_cpe_control.c -+++ b/src/dsl_cpe_control.c -@@ -6504,7 +6504,7 @@ DSL_CPE_STATIC void DSL_CPE_Termination - /* ignore the signal, we'll handle by ourself */ - signal (sig, SIG_IGN); - -- if (sig == SIGINT) -+ if (sig == SIGINT || sig == SIGTERM) - { - DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX "terminated" DSL_CPE_CRLF)); - DSL_CPE_Termination (); -@@ -6803,6 +6803,7 @@ DSL_int_t dsl_cpe_daemon ( - - #ifndef RTEMS - signal (SIGINT, DSL_CPE_TerminationHandler); -+ signal (SIGTERM, DSL_CPE_TerminationHandler); - #endif /* RTEMS*/ - - /* Open DSL_CPE_MAX_DSL_ENTITIES devices*/ diff --git a/package/network/config/ltq-vdsl-app/patches/300-ubus.patch b/package/network/config/ltq-vdsl-app/patches/300-ubus.patch deleted file mode 100644 index d257ca2fc4..0000000000 --- a/package/network/config/ltq-vdsl-app/patches/300-ubus.patch +++ /dev/null @@ -1,50 +0,0 @@ ---- a/src/dsl_cpe_control.c -+++ b/src/dsl_cpe_control.c -@@ -177,6 +177,9 @@ extern DSL_Error_t DSL_CPE_Pipe_StaticRe - #endif /* INCLUDE_DSL_RESOURCE_STATISTICS*/ - #endif - -+extern void ubus_init(); -+extern void ubus_deinit(); -+ - DSL_char_t *g_sFirmwareName1 = DSL_NULL; - DSL_FirmwareFeatures_t g_nFwFeatures1 = {DSL_FW_XDSLMODE_CLEANED, DSL_FW_XDSLFEATURE_CLEANED, - DSL_FW_XDSLFEATURE_CLEANED}; -@@ -6806,6 +6809,8 @@ DSL_int_t dsl_cpe_daemon ( - signal (SIGTERM, DSL_CPE_TerminationHandler); - #endif /* RTEMS*/ - -+ ubus_init(); -+ - /* Open DSL_CPE_MAX_DSL_ENTITIES devices*/ - for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; nDevice++) - { -@@ -7260,6 +7265,7 @@ DSL_int_t dsl_cpe_daemon ( - #endif /* INCLUDE_DSL_CPE_CLI_SUPPORT */ - - DSL_CPE_CONTROL_EXIT: -+ ubus_deinit(); - - #ifdef INCLUDE_DSL_BONDING - DSL_CPE_BND_Stop((DSL_CPE_BND_Context_t*)pCtrlCtx->pBnd); ---- a/src/Makefile.am -+++ b/src/Makefile.am -@@ -11,7 +11,7 @@ else - dsl_cpe_control_common_ldflags = - endif - --dsl_cpe_control_LDADD = -lpthread -lrt -+dsl_cpe_control_LDADD = -lpthread -lrt -lubox -lubus - - if INCLUDE_DSL_CPE_DTI_SUPPORT - dsl_cpe_control_LDADD += -ldti_agent -@@ -66,7 +66,8 @@ dsl_cpe_control_SOURCES = \ - dsl_cpe_control.c \ - dsl_cpe_init_cfg.c \ - dsl_cpe_linux.c \ -- dsl_cpe_debug.c -+ dsl_cpe_debug.c \ -+ dsl_cpe_ubus.c - - dsl_cpe_control_SOURCES += \ - $(dsl_cpe_control_dti_sources) diff --git a/package/network/config/ltq-vdsl-app/src/src/dsl_cpe_ubus.c b/package/network/config/ltq-vdsl-app/src/src/dsl_cpe_ubus.c deleted file mode 100644 index 61ac7708ba..0000000000 --- a/package/network/config/ltq-vdsl-app/src/src/dsl_cpe_ubus.c +++ /dev/null @@ -1,883 +0,0 @@ -// SPDX-License-Identifier: BSD-2-Clause -/* - * Copyright (C) 2020 Andre Heider - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dsl_cpe_control.h" -#include -#ifdef INCLUDE_DSL_CPE_API_VRX -#include -#endif - -#define U16(v1, v2) ( \ - ((uint16_t)(v1) << 8) | \ - ((uint16_t)(v2))) - -#define U32(v1, v2, v3, v4) ( \ - ((uint32_t)(v1) << 24) | \ - ((uint32_t)(v2) << 16) | \ - ((uint32_t)(v3) << 8) | \ - ((uint32_t)(v4))) - -#define STR_CASE(id, text) \ - case id: \ - str = text; \ - break; - -#define STR_CASE_MAP(id, text, number) \ - case id: \ - str = text; \ - map = number; \ - break; - -#define IOCTL(type, request) \ - type out; \ - memset(&out, 0, sizeof(type)); \ - if (ioctl(fd, request, &out)) \ - return; - -#define IOCTL_DIR(type, request, dir) \ - type out; \ - memset(&out, 0, sizeof(type)); \ - out.nDirection = dir; \ - if (ioctl(fd, request, &out)) \ - return; - -#define IOCTL_DIR_DELT(type, request, dir, delt) \ - type out; \ - memset(&out, 0, sizeof(type)); \ - out.nDirection = dir; \ - out.nDeltDataType = delt; \ - if (ioctl(fd, request, &out)) \ - return; - -typedef enum { - ANNEX_UNKNOWN = 0, - ANNEX_A, - ANNEX_B, - ANNEX_C, - ANNEX_I, - ANNEX_J, - ANNEX_L, - ANNEX_M, -} annex_t; - -typedef enum { - STD_UNKNOWN = 0, - STD_T1_413, - STD_TS_101_388, - STD_G_992_1, - STD_G_992_2, - STD_G_992_3, - STD_G_992_4, - STD_G_992_5, - STD_G_993_1, - STD_G_993_2, -} standard_t; - -typedef enum { - VECTOR_UNKNOWN = 0, - VECTOR_OFF, - VECTOR_ON_DS, - VECTOR_ON_DS_US, -} vector_t; - -typedef enum { - PROFILE_UNKNOWN = 0, - PROFILE_8A, - PROFILE_8B, - PROFILE_8C, - PROFILE_8D, - PROFILE_12A, - PROFILE_12B, - PROFILE_17A, - PROFILE_30A, - PROFILE_35B, -} profile_t; - -/* These values are exported via ubus and backwards compability - * needs to be kept! - */ -enum { - LSTATE_MAP_UNKNOWN = -1, - LSTATE_MAP_NOT_INITIALIZED, - LSTATE_MAP_EXCEPTION, - LSTATE_MAP_IDLE, - LSTATE_MAP_SILENT, - LSTATE_MAP_HANDSHAKE, - LSTATE_MAP_FULL_INIT, - LSTATE_MAP_SHOWTIME_NO_SYNC, - LSTATE_MAP_SHOWTIME_TC_SYNC, - LSTATE_MAP_RESYNC, -}; - -/* These values are exported via ubus and backwards compability - * needs to be kept! - */ -enum { - PSTATE_MAP_UNKNOWN = -2, - PSTATE_MAP_NA, - PSTATE_MAP_L0, - PSTATE_MAP_L1, - PSTATE_MAP_L2, - PSTATE_MAP_L3, -}; - -static DSL_CPE_ThreadCtrl_t thread; -static struct ubus_context *ctx; -static struct blob_buf b; - -static inline void m_double(const char *id, double value) { - blobmsg_add_double(&b, id, value); -} - -static inline void m_bool(const char *id, bool value) { - blobmsg_add_u8(&b, id, value); -} - -static inline void m_u32(const char *id, uint32_t value) { - blobmsg_add_u64(&b, id, value); -} - -static inline void m_str(const char *id, const char *value) { - blobmsg_add_string(&b, id, value); -} - -static inline void m_db(const char *id, int value) { - m_double(id, (double)value / 10); -} - -static inline void m_array(const char *id, const uint8_t *value, uint8_t len) { - void *c = blobmsg_open_array(&b, id); - - for (uint8_t i = 0; i < len; ++i) - blobmsg_add_u16(&b, "", value[i]); - - blobmsg_close_array(&b, c); -} - -static void m_vendor(const char *id, const uint8_t *value) { - // ITU-T T.35: U.S. - if (U16(value[0], value[1]) != 0xb500) - return; - - const char *str = NULL; - switch (U32(value[2], value[3], value[4], value[5])) { - STR_CASE(0x414C4342, "Alcatel") - STR_CASE(0x414E4456, "Analog Devices") - STR_CASE(0x4244434D, "Broadcom") - STR_CASE(0x43454E54, "Centillium") - STR_CASE(0x4753504E, "Globespan") - STR_CASE(0x494B4E53, "Ikanos") - STR_CASE(0x4946544E, "Infineon") - STR_CASE(0x54535443, "Texas Instruments") - STR_CASE(0x544D4D42, "Thomson MultiMedia Broadband") - STR_CASE(0x5443544E, "Trend Chip Technologies") - STR_CASE(0x53544D49, "ST Micro") - }; - - if (!str) - return; - - if ((value[6] == 0) && (value[7] == 0)) { - m_str(id, str); - return; - } - - char buf[64]; - sprintf(buf, "%s %d.%d", str, value[6], value[7]); - m_str(id, buf); - - return; -} - -annex_t get_annex(const uint8_t *xtse) { - if ((xtse[0] & XTSE_1_01_A_T1_413) || - (xtse[0] & XTSE_1_03_A_1_NO) || - (xtse[0] & XTSE_1_04_A_1_O) || - (xtse[1] & XTSE_2_01_A_2_NO) || - (xtse[2] & XTSE_3_03_A_3_NO) || - (xtse[2] & XTSE_3_04_A_3_O) || - (xtse[3] & XTSE_4_01_A_4_NO) || - (xtse[3] & XTSE_4_02_A_4_O) || - (xtse[5] & XTSE_6_01_A_5_NO) || - (xtse[5] & XTSE_6_02_A_5_O) || - (xtse[7] & XTSE_8_01_A)) - return ANNEX_A; - - if ((xtse[0] & XTSE_1_05_B_1_NO) || - (xtse[0] & XTSE_1_06_B_1_O) || - (xtse[1] & XTSE_2_02_B_2_O) || - (xtse[2] & XTSE_3_05_B_3_NO) || - (xtse[2] & XTSE_3_06_B_3_O) || - (xtse[5] & XTSE_6_03_B_5_NO) || - (xtse[5] & XTSE_6_04_B_5_O) || - (xtse[7] & XTSE_8_02_B)) - return ANNEX_B; - - if ((xtse[0] & XTSE_1_02_C_TS_101388) || - (xtse[0] & XTSE_1_07_C_1_NO) || - (xtse[0] & XTSE_1_08_C_1_O) || - (xtse[1] & XTSE_2_03_C_2_NO) || - (xtse[1] & XTSE_2_04_C_2_O) || - (xtse[7] & XTSE_8_03_C)) - return ANNEX_C; - - if ((xtse[3] & XTSE_4_05_I_3_NO) || - (xtse[3] & XTSE_4_06_I_3_O) || - (xtse[4] & XTSE_5_01_I_4_NO) || - (xtse[4] & XTSE_5_02_I_4_O) || - (xtse[5] & XTSE_6_07_I_5_NO) || - (xtse[5] & XTSE_6_08_I_5_O)) - return ANNEX_I; - - if ((xtse[3] & XTSE_4_07_J_3_NO) || - (xtse[3] & XTSE_4_08_J_3_O) || - (xtse[6] & XTSE_7_01_J_5_NO) || - (xtse[6] & XTSE_7_02_J_5_O)) - return ANNEX_J; - - if ((xtse[4] & XTSE_5_03_L_3_NO) || - (xtse[4] & XTSE_5_04_L_3_NO) || - (xtse[4] & XTSE_5_05_L_3_O) || - (xtse[4] & XTSE_5_06_L_3_O)) - return ANNEX_L; - - if ((xtse[4] & XTSE_5_07_M_3_NO) || - (xtse[4] & XTSE_5_08_M_3_O) || - (xtse[6] & XTSE_7_03_M_5_NO) || - (xtse[6] & XTSE_7_04_M_5_O)) - return ANNEX_M; - - return ANNEX_UNKNOWN; -} - -static standard_t get_standard(const uint8_t *xtse) { - if (xtse[0] & XTSE_1_01_A_T1_413) - return STD_T1_413; - - if (xtse[0] & XTSE_1_02_C_TS_101388) - return STD_TS_101_388; - - if ((xtse[0] & XTSE_1_03_A_1_NO) || - (xtse[0] & XTSE_1_04_A_1_O) || - (xtse[0] & XTSE_1_05_B_1_NO) || - (xtse[0] & XTSE_1_06_B_1_O) || - (xtse[0] & XTSE_1_07_C_1_NO) || - (xtse[0] & XTSE_1_08_C_1_O)) - return STD_G_992_1; - - if ((xtse[1] & XTSE_2_01_A_2_NO) || - (xtse[1] & XTSE_2_02_B_2_O) || - (xtse[1] & XTSE_2_03_C_2_NO) || - (xtse[1] & XTSE_2_04_C_2_O)) - return STD_G_992_2; - - if ((xtse[2] & XTSE_3_03_A_3_NO) || - (xtse[2] & XTSE_3_04_A_3_O) || - (xtse[2] & XTSE_3_05_B_3_NO) || - (xtse[2] & XTSE_3_06_B_3_O) || - (xtse[3] & XTSE_4_05_I_3_NO) || - (xtse[3] & XTSE_4_06_I_3_O) || - (xtse[3] & XTSE_4_07_J_3_NO) || - (xtse[3] & XTSE_4_08_J_3_O) || - (xtse[4] & XTSE_5_03_L_3_NO) || - (xtse[4] & XTSE_5_04_L_3_NO) || - (xtse[4] & XTSE_5_05_L_3_O) || - (xtse[4] & XTSE_5_06_L_3_O) || - (xtse[4] & XTSE_5_07_M_3_NO) || - (xtse[4] & XTSE_5_08_M_3_O)) - return STD_G_992_3; - - if ((xtse[3] & XTSE_4_01_A_4_NO) || - (xtse[3] & XTSE_4_02_A_4_O) || - (xtse[4] & XTSE_5_01_I_4_NO) || - (xtse[4] & XTSE_5_02_I_4_O)) - return STD_G_992_4; - - if ((xtse[5] & XTSE_6_01_A_5_NO) || - (xtse[5] & XTSE_6_02_A_5_O) || - (xtse[5] & XTSE_6_03_B_5_NO) || - (xtse[5] & XTSE_6_04_B_5_O) || - (xtse[5] & XTSE_6_07_I_5_NO) || - (xtse[5] & XTSE_6_08_I_5_O) || - (xtse[6] & XTSE_7_01_J_5_NO) || - (xtse[6] & XTSE_7_02_J_5_O) || - (xtse[6] & XTSE_7_03_M_5_NO) || - (xtse[6] & XTSE_7_04_M_5_O)) - return STD_G_992_5; - - if (xtse[7] & XTSE_8_08) - return STD_G_993_1; - - if ((xtse[7] & XTSE_8_01_A) || - (xtse[7] & XTSE_8_02_B) || - (xtse[7] & XTSE_8_03_C)) - return STD_G_993_2; - - return STD_UNKNOWN; -} - -static void version_information(int fd) { - IOCTL(DSL_VersionInformation_t, DSL_FIO_VERSION_INFORMATION_GET) - - m_str("api_version", out.data.DSL_DriverVersionApi); - m_str("firmware_version", out.data.DSL_ChipSetFWVersion); - m_str("chipset", out.data.DSL_ChipSetType); - m_str("driver_version", out.data.DSL_DriverVersionMeiBsp); -} - -static void line_state(int fd) { - IOCTL(DSL_LineState_t, DSL_FIO_LINE_STATE_GET) - - int map = LSTATE_MAP_UNKNOWN; - const char *str; - switch (out.data.nLineState) { - STR_CASE_MAP(DSL_LINESTATE_NOT_INITIALIZED, "Not initialized", LSTATE_MAP_NOT_INITIALIZED) - STR_CASE_MAP(DSL_LINESTATE_EXCEPTION, "Exception", LSTATE_MAP_EXCEPTION) - STR_CASE(DSL_LINESTATE_NOT_UPDATED, "Not updated") - STR_CASE(DSL_LINESTATE_IDLE_REQUEST, "Idle request") - STR_CASE_MAP(DSL_LINESTATE_IDLE, "Idle", LSTATE_MAP_IDLE) - STR_CASE(DSL_LINESTATE_SILENT_REQUEST, "Silent request") - STR_CASE_MAP(DSL_LINESTATE_SILENT, "Silent", LSTATE_MAP_SILENT) - STR_CASE_MAP(DSL_LINESTATE_HANDSHAKE, "Handshake", LSTATE_MAP_HANDSHAKE) - STR_CASE(DSL_LINESTATE_BONDING_CLR, "Bonding CLR") - STR_CASE_MAP(DSL_LINESTATE_FULL_INIT, "Full init", LSTATE_MAP_FULL_INIT) - STR_CASE(DSL_LINESTATE_SHORT_INIT_ENTRY, "Short init entry") - STR_CASE(DSL_LINESTATE_DISCOVERY, "Discovery") - STR_CASE(DSL_LINESTATE_TRAINING, "Training") - STR_CASE(DSL_LINESTATE_ANALYSIS, "Analysis") - STR_CASE(DSL_LINESTATE_EXCHANGE, "Exchange") - STR_CASE_MAP(DSL_LINESTATE_SHOWTIME_NO_SYNC, "Showtime without TC-Layer sync", LSTATE_MAP_SHOWTIME_NO_SYNC) - STR_CASE_MAP(DSL_LINESTATE_SHOWTIME_TC_SYNC, "Showtime with TC-Layer sync", LSTATE_MAP_SHOWTIME_TC_SYNC) - STR_CASE(DSL_LINESTATE_FASTRETRAIN, "Fastretrain") - STR_CASE(DSL_LINESTATE_LOWPOWER_L2, "Lowpower L2") - STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_ACTIVE, "Loopdiagnostic active") - STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_DATA_EXCHANGE, "Loopdiagnostic data exchange") - STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_DATA_REQUEST, "Loopdiagnostic data request") - STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_COMPLETE, "Loopdiagnostic complete") - STR_CASE_MAP(DSL_LINESTATE_RESYNC, "Resync", LSTATE_MAP_RESYNC) - STR_CASE(DSL_LINESTATE_TEST, "Test") - STR_CASE(DSL_LINESTATE_TEST_LOOP, "Test loop") - STR_CASE(DSL_LINESTATE_TEST_REVERB, "Test reverb") - STR_CASE(DSL_LINESTATE_TEST_MEDLEY, "Test medley") - STR_CASE(DSL_LINESTATE_TEST_SHOWTIME_LOCK, "Showtime lock") - STR_CASE(DSL_LINESTATE_TEST_QUIET, "Quiet") - STR_CASE(DSL_LINESTATE_LOWPOWER_L3, "Lowpower L3") -#ifndef INCLUDE_DSL_CPE_API_DANUBE - STR_CASE(DSL_LINESTATE_DISABLED, "Disabled") - STR_CASE(DSL_LINESTATE_T1413, "T1413") - STR_CASE(DSL_LINESTATE_ORDERLY_SHUTDOWN_REQUEST, "Orderly shutdown request") - STR_CASE(DSL_LINESTATE_ORDERLY_SHUTDOWN, "Orderly shutdown") - STR_CASE(DSL_LINESTATE_TEST_FILTERDETECTION_ACTIVE, "Test filterdetection active") - STR_CASE(DSL_LINESTATE_TEST_FILTERDETECTION_COMPLETE, "Test filterdetection complete") -#endif - default: - str = NULL; - break; - }; - - if (str) - m_str("state", str); - - if (map != LSTATE_MAP_UNKNOWN ) - m_u32("state_num", map); - - m_bool("up", out.data.nLineState == DSL_LINESTATE_SHOWTIME_TC_SYNC); -} - -static void pm_channel_counters_showtime(int fd) { - IOCTL_DIR(DSL_PM_ChannelCounters_t, DSL_FIO_PM_CHANNEL_COUNTERS_SHOWTIME_GET, DSL_NEAR_END); - - m_u32("uptime", out.interval.nElapsedTime); -} - -static void g997_line_inventory(int fd) { - IOCTL_DIR(DSL_G997_LineInventory_t, DSL_FIO_G997_LINE_INVENTORY_GET, DSL_DOWNSTREAM) - - m_array("vendor_id", out.data.G994VendorID, DSL_G997_LI_MAXLEN_VENDOR_ID); - m_vendor("vendor", out.data.G994VendorID); - m_array("system_vendor_id", out.data.SystemVendorID, DSL_G997_LI_MAXLEN_VENDOR_ID); - m_vendor("system_vendor", out.data.SystemVendorID); - m_array("version", out.data.VersionNumber, DSL_G997_LI_MAXLEN_VERSION); - m_array("serial", out.data.SerialNumber, DSL_G997_LI_MAXLEN_SERIAL); -} - -static void g997_power_management_status(int fd) { - IOCTL(DSL_G997_PowerManagementStatus_t, DSL_FIO_G997_POWER_MANAGEMENT_STATUS_GET) - - int map = PSTATE_MAP_UNKNOWN; - const char *str; - switch (out.data.nPowerManagementStatus) { - STR_CASE_MAP(DSL_G997_PMS_NA, "Power management state is not available", PSTATE_MAP_NA) - STR_CASE_MAP(DSL_G997_PMS_L0, "L0 - Synchronized", PSTATE_MAP_L0) - STR_CASE_MAP(DSL_G997_PMS_L1, "L1 - Power Down Data transmission (G.992.2)", PSTATE_MAP_L1) - STR_CASE_MAP(DSL_G997_PMS_L2, "L2 - Power Down Data transmission (G.992.3 and G.992.4)", PSTATE_MAP_L2) - STR_CASE_MAP(DSL_G997_PMS_L3, "L3 - No power", PSTATE_MAP_L3) - default: - str = NULL; - break; - }; - - if (str) - m_str("power_state", str); - - if (map != PSTATE_MAP_UNKNOWN) - m_u32("power_state_num", map); -} - -static void g997_xtu_system_enabling(int fd, standard_t *standard) { - IOCTL(DSL_G997_XTUSystemEnabling_t, DSL_FIO_G997_XTU_SYSTEM_ENABLING_STATUS_GET) - - m_array("xtse", out.data.XTSE, DSL_G997_NUM_XTSE_OCTETS); - - const char *str; - switch (get_annex(out.data.XTSE)) { - STR_CASE(ANNEX_A, "A") - STR_CASE(ANNEX_B, "B") - STR_CASE(ANNEX_C, "C") - STR_CASE(ANNEX_I, "I") - STR_CASE(ANNEX_J, "J") - STR_CASE(ANNEX_L, "L") - STR_CASE(ANNEX_M, "M") - default: - str = NULL; - break; - }; - if (str) - m_str("annex", str); - - *standard = get_standard(out.data.XTSE); - - switch (*standard) { - STR_CASE(STD_T1_413, "T1.413") - STR_CASE(STD_TS_101_388, "TS 101 388") - STR_CASE(STD_G_992_1, "G.992.1") - STR_CASE(STD_G_992_2, "G.992.2") - STR_CASE(STD_G_992_3, "G.992.3") - STR_CASE(STD_G_992_4, "G.992.4") - STR_CASE(STD_G_992_5, "G.992.5") - STR_CASE(STD_G_993_1, "G.993.1") - STR_CASE(STD_G_993_2, "G.993.2") - default: - str = NULL; - break; - } - if (str) - m_str("standard", str); -} - -static void get_vector_status(int fd, vector_t *status) { - *status = VECTOR_UNKNOWN; - -#ifdef INCLUDE_DSL_CPE_API_VRX - if (fd < 0) - return; - - IOCTL(IOCTL_MEI_dsmStatus_t, FIO_MEI_DSM_STATUS_GET); - - switch (out.eVectorStatus) { - case e_MEI_VECTOR_STAT_OFF: - *status = VECTOR_OFF; - break; - case e_MEI_VECTOR_STAT_ON_DS: - *status = VECTOR_ON_DS; - break; - case e_MEI_VECTOR_STAT_ON_DS_US: - *status = VECTOR_ON_DS_US; - break; - default: - break; - }; -#endif -} - -static void vector_erb(int fd) { -#ifdef INCLUDE_DSL_CPE_API_VRX - if (fd < 0) - return; - - IOCTL(IOCTL_MEI_dsmStatistics_t, FIO_MEI_DSM_STATISTICS_GET); - - m_u32("sent", out.n_processed); - m_u32("discarded", out.n_fw_dropped_size + out.n_mei_dropped_size + out.n_mei_dropped_no_pp_cb + out.n_pp_dropped); -#endif -} - -static void band_plan_status(int fd, profile_t *profile) { -#if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1) - IOCTL(DSL_BandPlanStatus_t, DSL_FIO_BAND_PLAN_STATUS_GET) - - switch (out.data.nProfile) { - case DSL_PROFILE_8A: - *profile = PROFILE_8A; - break; - case DSL_PROFILE_8B: - *profile = PROFILE_8B; - break; - case DSL_PROFILE_8C: - *profile = PROFILE_8C; - break; - case DSL_PROFILE_8D: - *profile = PROFILE_8D; - break; - case DSL_PROFILE_12A: - *profile = PROFILE_12A; - break; - case DSL_PROFILE_12B: - *profile = PROFILE_12B; - break; - case DSL_PROFILE_17A: - *profile = PROFILE_17A; - break; - case DSL_PROFILE_30A: - *profile = PROFILE_30A; - break; - case DSL_PROFILE_35B: - *profile = PROFILE_35B; - break; - default: - *profile = PROFILE_UNKNOWN; - break; - }; - - const char *str; - switch (*profile) { - STR_CASE(PROFILE_8A, "8a") - STR_CASE(PROFILE_8B, "8b") - STR_CASE(PROFILE_8C, "8c") - STR_CASE(PROFILE_8D, "8d") - STR_CASE(PROFILE_12A, "12a") - STR_CASE(PROFILE_12B, "12b") - STR_CASE(PROFILE_17A, "17a") - STR_CASE(PROFILE_30A, "30a") - STR_CASE(PROFILE_35B, "35b") - default: - str = NULL; - break; - }; - if (str) - m_str("profile", str); -#endif -} - -static void line_feature_config(int fd, DSL_AccessDir_t direction) { - IOCTL_DIR(DSL_LineFeature_t, DSL_FIO_LINE_FEATURE_STATUS_GET, direction) - - m_bool("trellis", out.data.bTrellisEnable); - m_bool("bitswap", out.data.bBitswapEnable); - m_bool("retx", out.data.bReTxEnable); - m_bool("virtual_noise", out.data.bVirtualNoiseSupport); -} - -static void g997_channel_status(int fd, DSL_AccessDir_t direction) { - IOCTL_DIR(DSL_G997_ChannelStatus_t, DSL_FIO_G997_CHANNEL_STATUS_GET, direction); - - m_u32("interleave_delay", out.data.ActualInterleaveDelay * 10); -#ifndef INCLUDE_DSL_CPE_API_DANUBE - // prefer ACTNDR, see comments in drv_dsl_cpe_api_g997.h - m_u32("data_rate", out.data.ActualNetDataRate); -#else - m_u32("data_rate", out.data.ActualDataRate); -#endif -} - -static void g997_line_status(int fd, DSL_AccessDir_t direction) { - IOCTL_DIR_DELT(DSL_G997_LineStatus_t, DSL_FIO_G997_LINE_STATUS_GET, direction, DSL_DELT_DATA_SHOWTIME); - - m_db("latn", out.data.LATN); - m_db("satn", out.data.SATN); - m_db("snr", out.data.SNR); - m_db("actps", out.data.ACTPS); - m_db("actatp", out.data.ACTATP); - m_u32("attndr", out.data.ATTNDR); -} - -static void pm_line_sec_counters_total(int fd, DSL_XTUDir_t direction) { - IOCTL_DIR(DSL_PM_LineSecCountersTotal_t, DSL_FIO_PM_LINE_SEC_COUNTERS_TOTAL_GET, direction) - - m_u32("es", out.data.nES); - m_u32("ses", out.data.nSES); - m_u32("loss", out.data.nLOSS); - m_u32("uas", out.data.nUAS); - m_u32("lofs", out.data.nLOFS); -#ifndef INCLUDE_DSL_CPE_API_DANUBE - m_u32("fecs", out.data.nFECS); -#endif -} - -static void pm_data_path_counters_total(int fd, DSL_XTUDir_t direction) { - IOCTL_DIR(DSL_PM_DataPathCountersTotal_t, DSL_FIO_PM_DATA_PATH_COUNTERS_TOTAL_GET, direction); - - m_u32("hec", out.data.nHEC); - m_u32("ibe", out.data.nIBE); - m_u32("crc_p", out.data.nCRC_P); - m_u32("crcp_p", out.data.nCRCP_P); - m_u32("cv_p", out.data.nCV_P); - m_u32("cvp_p", out.data.nCVP_P); -} - -static void retx_statistics(int fd, DSL_XTUDir_t direction) { -#ifdef INCLUDE_DSL_CPE_PM_RETX_COUNTERS -#ifdef INCLUDE_DSL_CPE_PM_RETX_THRESHOLDS - IOCTL_DIR(DSL_ReTxStatistics_t, DSL_FIO_RETX_STATISTICS_GET, direction); - - m_u32("rx_corrupted", out.data.nRxCorruptedTotal); - m_u32("rx_uncorrected_protected", out.data.nRxUncorrectedProtected); - m_u32("rx_retransmitted", out.data.nRxRetransmitted); - m_u32("rx_corrected", out.data.nRxCorrected); - m_u32("tx_retransmitted", out.data.nTxRetransmitted); -#endif -#endif -} - -static void describe_mode(standard_t standard, profile_t profile, vector_t vector) { - char buf[128]; - - switch (standard) { - case STD_T1_413: - strcpy(buf, "T1.413"); - break; - case STD_TS_101_388: - strcpy(buf, "TS 101 388"); - break; - case STD_G_992_1: - strcpy(buf, "G.992.1 (ADSL)"); - break; - case STD_G_992_2: - strcpy(buf, "G.992.2 (ADSL lite)"); - break; - case STD_G_992_3: - strcpy(buf, "G.992.3 (ADSL2)"); - break; - case STD_G_992_4: - strcpy(buf, "G.992.4 (ADSL2 lite)"); - break; - case STD_G_992_5: - strcpy(buf, "G.992.5 (ADSL2+)"); - break; - case STD_G_993_1: - strcpy(buf, "G.993.1 (VDSL)"); - break; - case STD_G_993_2: - strcpy(buf, "G.993.2 (VDSL2"); - - switch (profile) { - case PROFILE_8A: - strcat(buf, ", Profile 8a"); - break; - case PROFILE_8B: - strcat(buf, ", Profile 8b"); - break; - case PROFILE_8C: - strcat(buf, ", Profile 8c"); - break; - case PROFILE_8D: - strcat(buf, ", Profile 8d"); - break; - case PROFILE_12A: - strcat(buf, ", Profile 12a"); - break; - case PROFILE_12B: - strcat(buf, ", Profile 12b"); - break; - case PROFILE_17A: - strcat(buf, ", Profile 17a"); - break; - case PROFILE_30A: - strcat(buf, ", Profile 30a"); - break; - case PROFILE_35B: - strcat(buf, ", Profile 35b"); - break; - default: - break; - }; - - switch (vector) { - case VECTOR_ON_DS: - strcat(buf, ", with downstream vectoring"); - break; - case VECTOR_ON_DS_US: - strcat(buf, ", with down- and upstream vectoring"); - break; - default: - break; - }; - - strcat(buf, ")"); - break; - default: - return; - }; - - m_str("mode", buf); -} - -static int metrics(struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, const char *method, - struct blob_attr *msg) -{ - int fd, fd_mei; - void *c, *c2; - standard_t standard = STD_UNKNOWN; - profile_t profile = PROFILE_UNKNOWN; - vector_t vector = VECTOR_UNKNOWN; - -#ifndef INCLUDE_DSL_CPE_API_DANUBE - fd = open(DSL_CPE_DEVICE_NAME "/0", O_RDWR, 0644); -#else - fd = open(DSL_CPE_DEVICE_NAME, O_RDWR, 0644); -#endif - if (fd < 0) - return UBUS_STATUS_UNKNOWN_ERROR; - -#ifdef INCLUDE_DSL_CPE_API_VRX - fd_mei = open(DSL_CPE_DSL_LOW_DEV "/0", O_RDWR, 0644); -#else - fd_mei = -1; -#endif - - blob_buf_init(&b, 0); - - version_information(fd); - line_state(fd); - pm_channel_counters_showtime(fd); - - c = blobmsg_open_table(&b, "atu_c"); - g997_line_inventory(fd); - blobmsg_close_table(&b, c); - - g997_power_management_status(fd); - g997_xtu_system_enabling(fd, &standard); - - if (standard == STD_G_993_2) { - band_plan_status(fd, &profile); - get_vector_status(fd_mei, &vector); - } - - describe_mode(standard, profile, vector); - - c = blobmsg_open_table(&b, "upstream"); - switch (vector) { - case VECTOR_OFF: - m_bool("vector", false); - break; - case VECTOR_ON_DS_US: - m_bool("vector", true); - break; - default: - break; - }; - line_feature_config(fd, DSL_UPSTREAM); - g997_channel_status(fd, DSL_UPSTREAM); - g997_line_status(fd, DSL_UPSTREAM); - blobmsg_close_table(&b, c); - - c = blobmsg_open_table(&b, "downstream"); - switch (vector) { - case VECTOR_OFF: - m_bool("vector", false); - break; - case VECTOR_ON_DS: - case VECTOR_ON_DS_US: - m_bool("vector", true); - break; - default: - break; - }; - line_feature_config(fd, DSL_DOWNSTREAM); - g997_channel_status(fd, DSL_DOWNSTREAM); - g997_line_status(fd, DSL_DOWNSTREAM); - blobmsg_close_table(&b, c); - - c = blobmsg_open_table(&b, "errors"); - c2 = blobmsg_open_table(&b, "near"); - pm_line_sec_counters_total(fd, DSL_NEAR_END); - pm_data_path_counters_total(fd, DSL_NEAR_END); - retx_statistics(fd, DSL_NEAR_END); - blobmsg_close_table(&b, c2); - - c2 = blobmsg_open_table(&b, "far"); - pm_line_sec_counters_total(fd, DSL_FAR_END); - pm_data_path_counters_total(fd, DSL_FAR_END); - retx_statistics(fd, DSL_FAR_END); - blobmsg_close_table(&b, c2); - blobmsg_close_table(&b, c); - - switch (vector) { - case VECTOR_ON_DS: - case VECTOR_ON_DS_US: - c = blobmsg_open_table(&b, "erb"); - vector_erb(fd_mei); - blobmsg_close_table(&b, c); - break; - default: - break; - }; - - ubus_send_reply(ctx, req, b.head); - - if (fd_mei >= 0) - close(fd_mei); - close(fd); - - return 0; -} - -static const struct ubus_method dsl_methods[] = { - UBUS_METHOD_NOARG("metrics", metrics), -}; - -static struct ubus_object_type dsl_object_type = - UBUS_OBJECT_TYPE("dsl", dsl_methods); - -static struct ubus_object dsl_object = { - .name = "dsl", - .type = &dsl_object_type, - .methods = dsl_methods, - .n_methods = ARRAY_SIZE(dsl_methods), -}; - -static DSL_int_t ubus_main(DSL_CPE_Thread_Params_t *params) { - uloop_run(); - return 0; -} - -void ubus_init() { - uloop_init(); - - ctx = ubus_connect(NULL); - if (!ctx) - return; - - if (ubus_add_object(ctx, &dsl_object)) { - ubus_free(ctx); - ctx = NULL; - return; - } - - ubus_add_uloop(ctx); - - DSL_CPE_ThreadInit(&thread, "ubus", ubus_main, DSL_CPE_PIPE_STACK_SIZE, DSL_CPE_PIPE_PRIORITY, 0, 0); -} - -void ubus_deinit() { - if (!ctx) - return; - - ubus_free(ctx); - uloop_done(); - - DSL_CPE_ThreadShutdown(&thread, 1000); -} diff --git a/package/network/config/ltq-vdsl-vr9-app/Makefile b/package/network/config/ltq-vdsl-vr9-app/Makefile new file mode 100644 index 0000000000..c7991453c8 --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/Makefile @@ -0,0 +1,82 @@ +# Copyright (C) 2010 OpenWrt.org +# Copyright (C) 2015-2016 Lantiq Beteiligungs GmbH & Co KG. +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/kernel.mk + +PKG_NAME:=ltq-vdsl-vr9-app +PKG_VERSION:=4.17.18.6 +PKG_RELEASE:=$(AUTORELEASE) +PKG_BASE_NAME:=dsl_cpe_control +PKG_SOURCE:=$(PKG_BASE_NAME)_vrx-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=@OPENWRT +PKG_HASH:=da8bb929526a61aea0e153ef524331fcd472a1ebbc6d88ca017735a4f82ece02 +PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_BASE_NAME)-$(PKG_VERSION) +PKG_LICENSE:=BSD-2-Clause + +PKG_BUILD_DEPENDS:=ltq-vdsl-vr9 + +PKG_FLAGS:=nonshared +PKG_FIXUP:=autoreconf + +include $(INCLUDE_DIR)/package.mk + +define Package/ltq-vdsl-vr9-app + SECTION:=net + CATEGORY:=Network + TITLE:=Lantiq VDSL userland tool + URL:=http://www.lantiq.com/ + DEPENDS:=@TARGET_lantiq_xrx200 +libpthread +librt +ltq-dsl-base +libubox +libubus +endef + +define Package/ltq-vdsl-vr9-app/description + Userland tool needed to control Lantiq VDSL CPE +endef + +# ltq-vdsl-vr9-app uses a header provided by the MEI driver which has some +# conditionals. +# +# Define them here with the default values they would get in the MEI driver, +# have the same view on both sides. +# +# If you change them, you need to change them for the ltq-vdsl-vr9-app as well +VDSL_APP_CFLAGS = \ + -DMAX_CLI_PIPES=1 \ + -DMEI_SUPPORT_DEBUG_STREAMS=1 \ + -DMEI_SUPPORT_OPTIMIZED_FW_DL=1 + +CONFIGURE_ARGS += \ + --enable-vrx \ + --enable-vrx-device=vr9 \ + --enable-driver-include="-I$(STAGING_DIR)/usr/include/drv_vdsl_cpe_api" \ + --enable-device-driver-include="-I$(STAGING_DIR)/usr/include/vdsl/" \ + --enable-ifxos \ + --enable-ifxos-include="-I$(STAGING_DIR)/usr/include/ifxos" \ + --enable-ifxos-library="-I$(STAGING_DIR)/usr/lib" \ + --enable-add-appl-cflags="$(VDSL_APP_CFLAGS)" \ + --enable-debug \ + --disable-dti \ + --with-channels-per-line="1" + +CONFIGURE_ARGS += \ + --enable-model=full \ + --enable-dsl-ceoc=no +#CONFIGURE_ARGS += --enable-model=lite +#CONFIGURE_ARGS += --enable-model=footprint +#CONFIGURE_ARGS += --enable-model=typical +#CONFIGURE_ARGS += --enable-model=debug + +define Package/ltq-vdsl-vr9-app/install + $(INSTALL_DIR) $(1)/etc/init.d $(1)/sbin $(1)/etc/hotplug.d/dsl + $(INSTALL_BIN) ./files/dsl_control $(1)/etc/init.d/ + $(INSTALL_BIN) ./files/10_atm.sh $(1)/etc/hotplug.d/dsl + $(INSTALL_BIN) ./files/10_ptm.sh $(1)/etc/hotplug.d/dsl + + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/dsl_cpe_control $(1)/sbin/vdsl_cpe_control + $(INSTALL_BIN) ./files/dsl_cpe_pipe.sh $(1)/sbin/ +endef + +$(eval $(call BuildPackage,ltq-vdsl-vr9-app)) diff --git a/package/network/config/ltq-vdsl-vr9-app/files/10_atm.sh b/package/network/config/ltq-vdsl-vr9-app/files/10_atm.sh new file mode 100755 index 0000000000..e104a14b2e --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/files/10_atm.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +[ "$DSL_NOTIFICATION_TYPE" = "DSL_STATUS" ] && \ +[ "$DSL_TC_LAYER_STATUS" = "ATM" ] && \ +! grep -q "ltq_atm_vr9" /proc/modules || exit 0 + +logger -p daemon.notice -t "dsl-notify" "Switching to TC-Layer ATM" + +if grep -q "ltq_ptm_vr9" /proc/modules ; then + logger -p daemon.notice -t "dsl-notify" "Loading ATM driver while EFM/PTM driver is loaded is not possible. Reboot is needed." + exit +fi + +modprobe ltq_atm_vr9 diff --git a/package/network/config/ltq-vdsl-vr9-app/files/10_ptm.sh b/package/network/config/ltq-vdsl-vr9-app/files/10_ptm.sh new file mode 100755 index 0000000000..1c62617bba --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/files/10_ptm.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +[ "$DSL_NOTIFICATION_TYPE" = "DSL_STATUS" ] && \ +[ "$DSL_TC_LAYER_STATUS" = "EFM" ] && \ +! grep -q "ltq_ptm_vr9" /proc/modules || exit 0 + +logger -p daemon.notice -t "dsl-notify" "Switching to TC-Layer EFM/PTM" + +if grep -q "ltq_atm_vr9" /proc/modules ; then + logger -p daemon.notice -t "dsl-notify" "Loading EFM/PTM driver while ATM driver is loaded is not possible. Reboot is needed." + exit +fi + +modprobe ltq_ptm_vr9 diff --git a/package/network/config/ltq-vdsl-vr9-app/files/dsl_control b/package/network/config/ltq-vdsl-vr9-app/files/dsl_control new file mode 100644 index 0000000000..34642dbda5 --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/files/dsl_control @@ -0,0 +1,322 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2012 OpenWrt.org + +START=97 +USE_PROCD=1 + +dslstat() { + ubus call dsl metrics +} + +extra_command "dslstat" "Get DSL status information" + +# +# ITU-T G.997.1 (06/2012) - Section 7.3.1.1.1 (xTU transmission system enabling (XTSE)) +# ITU-T G.997.1 Amendment 2 (04/2013) - Section 2.1 - (Vectoring mode enable (VECTORMODE_ENABLE)) +# +# G.992.1 Annex A +# G.992.2 Annex A +# G.992.3 Annex A / L-US1 / L_US-2 / M +# G.992.5 Annex A / M +# G.993.2 Annex A/B/C +# G.993.5 Annex A/B/C +xtse_xdsl_a="05_01_04_00_4C_01_04_07" + +# G.992.1 Annex B +# G.992.3 Annex B +# G.992.5 Annex B +# G.993.2 Annex A/B/C +# G.993.5 Annex A/B/C +xtse_xdsl_b="10_00_10_00_00_04_00_07" + +# G.992.1 Annex B +# G.992.3 Annex B +# G.992.3 Annex J +# G.992.5 Annex B +# G.992.5 Annex J +# G.993.2 Annex A/B/C +# G.993.5 Annex A/B/C +xtse_xdsl_j="10_00_10_40_00_04_01_07" + +# G.992.1 Annex B +xtse_xdsl_bdmt="10_00_00_00_00_00_00_00" + +# G.992.3 Annex B +xtse_xdsl_b2="00_00_10_00_00_00_00_00" + +# G.992.5 Annex B +xtse_xdsl_b2p="00_00_00_00_00_04_00_00" + +# ANSI T1.413 +xtse_xdsl_at1="01_00_00_00_00_00_00_00" + +# G.992.2 Annex A +xtse_xdsl_alite="00_01_00_00_00_00_00_00" + +# G.992.1 Annex A +xtse_xdsl_admt="04_00_00_00_00_00_00_00" + +# G.992.3 Annex A +xtse_xdsl_a2="00_00_04_00_00_00_00_00" + +# G.992.5 Annex A +xtse_xdsl_a2p="00_00_00_00_00_01_00_00" + +# G.992.3 Annex L +xtse_xdsl_l="00_00_00_00_0C_00_00_00" + +# G.992.3 Annex M +# G.992.5 Annex M +xtse_xdsl_m="00_00_00_00_40_00_04_00" + +# G.992.3 Annex M +xtse_xdsl_m2="00_00_00_00_40_00_00_00" + +# G.992.5 Annex M +xtse_xdsl_m2p="00_00_00_00_00_00_04_00" + +# +# ITU-T G.994.1 (06/2012) - Table 2 (Mandatory carrier sets) +# + +# A43 +tone_adsl_a="0x142" # A43C + J43 + A43 +tone_vdsl_a="0x142" # A43C + J43 + A43 + +# A43 + V43 +tone_adsl_av="0x142" # A43C + J43 + A43 +tone_vdsl_av="0x146" # A43C + J43 + A43 + V43 + +# B43 +tone_adsl_b="0x81" # B43 + B43c +tone_vdsl_b="0x1" # B43 + +# B43 + V43 +tone_adsl_bv="0x81" # B43 + B43c +tone_vdsl_bv="0x5" # B43 + V43 + +# create DSL autoboot script. Used for SNR margin tweak and to set MAC address for vectoring error reports +autoboot_script() { + echo "[WaitForConfiguration]={ +locs 0 $1 +dsmmcs $2 +} + +[WaitForLinkActivate]={ +} + +[WaitForRestart]={ +} + +[Common]={ +}" > /tmp/dsl.scr +} + +lowlevel_cfg() { + echo "# VRX Low Level Configuration File +# +# Parameters must be separated by tabs or spaces. +# Empty lines and comments will be ignored. +# + +# nFilter +# +# NA = -1 +# OFF = 0 +# ISDN = 1 +# POTS = 2 +# POTS_2 = 3 +# POTS_3 = 4 +# +# (dec) + -1 + +# nHsToneGroupMode nHsToneGroup_A nHsToneGroup_V nHsToneGroup_AV +# +# NA = -1 NA = -1 see see +# AUTO = 0 VDSL2_B43 = 0x0001 nHsToneGroup_A nHsToneGroup_A +# MANUAL = 1 VDSL2_A43 = 0x0002 +# VDSL2_V43 = 0x0004 +# VDSL1_V43P = 0x0008 +# VDSL1_V43I = 0x0010 +# ADSL1_C43 = 0x0020 +# ADSL2_J43 = 0x0040 +# ADSL2_B43C = 0x0080 +# ADSL2_A43C = 0x0100 +# +# (dec) (hex) (hex) (hex) + 1 $1 $2 0x0 + +# nBaseAddr nIrqNum +# +# (hex) (dec) + 0x1e116000 63 + +# nUtopiaPhyAdr nUtopiaBusWidth nPosPhyParity +# default(16b) = 0 NA = -1 +# 8-bit = 1 ODD = 0 +# 16-bit = 2 +# +# +# (hex) (dec) (dec) + 0xFF 0 0 + +# bNtrEnable +# +# (dec) + 0" > /tmp/lowlevel.cfg +} + +get_macaddr() { + local name + config_get name $1 name + [ "$name" = "dsl0" ] && config_get $2 $1 macaddr +} + +service_triggers() { + procd_add_reload_trigger network +} + +start_service() { + local annex + local firmware + local tone + local tone_adsl + local tone_vdsl + local xtse + local xfer_mode + local line_mode + local tc_layer + local mode + local lowlevel + local snr + local macaddr + + config_load network + config_get tone dsl tone + config_get annex dsl annex + config_get firmware dsl firmware + config_get xfer_mode dsl xfer_mode + config_get line_mode dsl line_mode + config_get snr dsl ds_snr_offset + config_foreach get_macaddr device macaddr + + eval "xtse=\"\${xtse_xdsl_$annex}\"" + + case "${xfer_mode}" in + atm) + tc_layer="-T1:0x1:0x1_1:0x1:0x1" + ;; + ptm) + tc_layer="-T2:0x1:0x1_2:0x1:0x1" + ;; + esac + + case "${line_mode}" in + adsl) + mode="-M1" + + # mask out VDSL bits when ADSL is requested + xtse="${xtse%_*}_00" + ;; + vdsl) + mode="-M2" + + # mask out ADSL bits when VDSL is requested + xtse="00_00_00_00_00_00_00_${xtse##*_}" + ;; + esac + + local annexgpio="/sys/class/gpio/annex" + if [ -d "${annexgpio}a" ] && [ -d "${annexgpio}b" ]; then + case "${annex}" in + a*|l*|m*) + echo 1 > "${annexgpio}a/value" + echo 0 > "${annexgpio}b/value" + ;; + b*|j*) + echo 0 > "${annexgpio}a/value" + echo 1 > "${annexgpio}b/value" + ;; + esac + fi + + if [ -z "${firmware}" ]; then + # search for the firmware provided by dsl-vrx200-firmware-xdsl-* + if grep -qE "system type.*: (VR9|xRX200)" /proc/cpuinfo; then + case "${annex}" in + a*|l*|m*) + if [ -f "/lib/firmware/lantiq-vrx200-a.bin" ]; then + firmware="/lib/firmware/lantiq-vrx200-a.bin" + elif [ -f "/tmp/lantiq-vrx200-a.bin" ]; then + firmware="/tmp/lantiq-vrx200-a.bin" + elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-b-to-a.bspatch" ]; then + bspatch /lib/firmware/lantiq-vrx200-b.bin \ + /tmp/lantiq-vrx200-a.bin \ + /lib/firmware/lantiq-vrx200-b-to-a.bspatch + firmware="/tmp/lantiq-vrx200-a.bin" + else + echo "firmware for annex a not found" + return 1 + fi + ;; + b*|j*) + if [ -f "/lib/firmware/vr9_dsl_fw_annex_b.bin" ]; then + firmware="/lib/firmware/vr9_dsl_fw_annex_b.bin" + elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ]; then + firmware="/lib/firmware/lantiq-vrx200-b.bin" + elif [ -f "/tmp/lantiq-vrx200-b.bin" ]; then + firmware="/tmp/lantiq-vrx200-b.bin" + elif [ -f "/lib/firmware/lantiq-vrx200-a.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-a-to-b.bspatch" ]; then + bspatch /lib/firmware/lantiq-vrx200-a.bin \ + /tmp/lantiq-vrx200-b.bin \ + /lib/firmware/lantiq-vrx200-a-to-b.bspatch + firmware="/tmp/lantiq-vrx200-b.bin" + else + echo "firmware for annex b not found" + return 1 + fi + ;; + *) + echo "annex type not supported use a or b" + return 1 + ;; + esac + fi + fi + + [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin + [ -f "${firmware}" ] || { + echo failed to find $firmware + return 1 + } + + eval "tone_adsl=\"\${tone_adsl_$tone}\"" + eval "tone_vdsl=\"\${tone_vdsl_$tone}\"" + [ -n "${tone_adsl}" ] && [ -n "${tone_vdsl}" ] && { + lowlevel_cfg "${tone_adsl}" "${tone_vdsl}" + lowlevel="-l /tmp/lowlevel.cfg" + } + + [ -z "${snr}" ] && snr=0 + [ -z "${macaddr}" ] && macaddr="00:00:00:00:00:00" + autoboot_script "$snr" "$macaddr" + autoboot="-a /tmp/dsl.scr -A /tmp/dsl.scr" + + procd_open_instance + procd_set_param command /sbin/vdsl_cpe_control \ + -i$xtse \ + -n /sbin/dsl_notify.sh \ + -f ${firmware} \ + $lowlevel \ + ${mode} \ + ${tc_layer} \ + $autoboot + procd_close_instance +} + +stop_service() { + DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \ + DSL_INTERFACE_STATUS="DOWN" \ + /sbin/dsl_notify.sh +} diff --git a/package/network/config/ltq-vdsl-vr9-app/files/dsl_cpe_pipe.sh b/package/network/config/ltq-vdsl-vr9-app/files/dsl_cpe_pipe.sh new file mode 100755 index 0000000000..9002b7b316 --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/files/dsl_cpe_pipe.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +pipe_no=0 + +# use specified pipe no +case "$1" in +0|1|2) +pipe_no=$1; shift; ;; +esac + + +#echo "Call dsl_pipe with $*" +lock /var/lock/dsl_pipe +echo $* > /tmp/pipe/dsl_cpe${pipe_no}_cmd +result=$(cat /tmp/pipe/dsl_cpe${pipe_no}_ack) +lock -u /var/lock/dsl_pipe + +echo "$result" diff --git a/package/network/config/ltq-vdsl-vr9-app/patches/100-compat.patch b/package/network/config/ltq-vdsl-vr9-app/patches/100-compat.patch new file mode 100644 index 0000000000..6bc359c3cc --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/patches/100-compat.patch @@ -0,0 +1,11 @@ +--- a/src/dsl_cpe_init_cfg.c ++++ b/src/dsl_cpe_init_cfg.c +@@ -38,7 +38,7 @@ DSL_InitData_t gInitCfgData = + DSL_DEV_HS_TONE_GROUP_CLEANED, \ + DSL_DEV_HS_TONE_GROUP_CLEANED, \ + DSL_DEV_HS_TONE_GROUP_CLEANED, \ +- 0x1E116000, 0x37, -1), ++ 0x1E116000, 0x3f, -1), + DSL_CPE_SIC_SET(DSL_TC_ATM, DSL_EMF_TC_CLEANED, DSL_EMF_TC_CLEANED, DSL_SYSTEMIF_MII, \ + DSL_TC_EFM, DSL_EMF_TC_CLEANED, DSL_EMF_TC_CLEANED, DSL_SYSTEMIF_MII), + DSL_CPE_MAC_CFG_SET(DSL_EFM_SPEED_100, DSL_EFM_DUPLEX_FULL, DSL_EFM_FLOWCTRL_ON, DSL_EFM_AUTONEG_OFF, \ diff --git a/package/network/config/ltq-vdsl-vr9-app/patches/101-musl.patch b/package/network/config/ltq-vdsl-vr9-app/patches/101-musl.patch new file mode 100644 index 0000000000..d66045db61 --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/patches/101-musl.patch @@ -0,0 +1,10 @@ +--- a/src/dsl_cpe_control.c ++++ b/src/dsl_cpe_control.c +@@ -11,6 +11,7 @@ + /* + Includes + */ ++#include + #include "dsl_cpe_control.h" + #include "dsl_cpe_cli.h" + #include "dsl_cpe_cli_console.h" diff --git a/package/network/config/ltq-vdsl-vr9-app/patches/200-autoboot.patch b/package/network/config/ltq-vdsl-vr9-app/patches/200-autoboot.patch new file mode 100644 index 0000000000..cc6feb94aa --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/patches/200-autoboot.patch @@ -0,0 +1,86 @@ +This enables automatic connection after the control daemon is started, +and also stops the connection on termination. + +Using the autoboot restart command is necessary because the stop command +doesn't actually stop the connection, and would also leave the driver in +a state where an explicit start command is necessary to connect again. + +--- a/src/dsl_cpe_init_cfg.c ++++ b/src/dsl_cpe_init_cfg.c +@@ -27,7 +27,7 @@ DSL_InitData_t gInitCfgData = + DSL_CPE_FW2_SET(DSL_NULL, 0x0), + DSL_CPE_XTU_SET(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7), + DSL_CPE_LINE_INV_NE_SET(DSL_NULL), +- DSL_CPE_AUTOBOOT_CTRL_SET(DSL_AUTOBOOT_CTRL_STOP), ++ DSL_CPE_AUTOBOOT_CTRL_SET(DSL_AUTOBOOT_CTRL_START), + DSL_CPE_AUTOBOOT_CFG_SET(DSL_FALSE, DSL_FALSE, DSL_FALSE), + DSL_CPE_TEST_MODE_CTRL_SET(DSL_TESTMODE_DISABLE), + DSL_CPE_LINE_ACTIVATE_CTRL_SET(DSL_G997_INHIBIT_LDSF, DSL_G997_INHIBIT_ACSF, DSL_G997_NORMAL_STARTUP), +--- a/src/dsl_cpe_control.c ++++ b/src/dsl_cpe_control.c +@@ -6515,10 +6515,13 @@ DSL_CPE_STATIC void DSL_CPE_Termination + DSL_CPE_STATIC DSL_void_t DSL_CPE_Termination (void) + { + #ifdef INCLUDE_DSL_CPE_CLI_SUPPORT +- DSL_int_t nDevice = 0; + DSL_char_t buf[32] = "quit"; + #endif + ++ DSL_Error_t nRet = DSL_SUCCESS; ++ DSL_int_t nDevice = 0; ++ DSL_AutobootConfig_t sAutobootCfg; ++ DSL_AutobootControl_t sAutobootCtl; + DSL_CPE_Control_Context_t *pCtrlCtx; + + pCtrlCtx = DSL_CPE_GetGlobalContext(); +@@ -6527,6 +6530,50 @@ DSL_CPE_STATIC DSL_void_t DSL_CPE_Termi + pCtrlCtx->bRun = DSL_FALSE; + } + ++ for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; ++nDevice) ++ { ++ g_bWaitBeforeConfigWrite[nDevice] = DSL_TRUE; ++ g_bWaitBeforeLinkActivation[nDevice] = DSL_TRUE; ++ g_bWaitBeforeRestart[nDevice] = DSL_TRUE; ++ ++ g_bAutoContinueWaitBeforeConfigWrite[nDevice] = DSL_FALSE; ++ g_bAutoContinueWaitBeforeLinkActivation[nDevice] = DSL_FALSE; ++ g_bAutoContinueWaitBeforeRestart[nDevice] = DSL_FALSE; ++ ++ memset(&sAutobootCfg, 0x0, sizeof(DSL_AutobootConfig_t)); ++ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeConfigWrite = DSL_TRUE; ++ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeLinkActivation = DSL_TRUE; ++ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeRestart = DSL_TRUE; ++ ++ nRet = (DSL_Error_t)DSL_CPE_Ioctl( ++ DSL_CPE_GetGlobalContext()->fd[nDevice], ++ DSL_FIO_AUTOBOOT_CONFIG_SET, (DSL_int_t)&sAutobootCfg); ++ ++ if (nRet < DSL_SUCCESS) ++ { ++ DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX ++ "Autoboot configuration for device (%d) failed!, nRet = %d!" ++ DSL_CPE_CRLF, nDevice, sAutobootCtl.accessCtl.nReturn)); ++ } ++ ++ memset(&sAutobootCtl, 0, sizeof(DSL_AutobootControl_t)); ++ sAutobootCtl.data.nCommand = DSL_AUTOBOOT_CTRL_RESTART; ++ ++ nRet = (DSL_Error_t)DSL_CPE_Ioctl( ++ DSL_CPE_GetGlobalContext()->fd[nDevice], ++ DSL_FIO_AUTOBOOT_CONTROL_SET, (DSL_int_t)&sAutobootCtl); ++ ++ if (nRet < DSL_SUCCESS) ++ { ++ DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX ++ "Autoboot restart for device (%d) failed!, nRet = %d!" ++ DSL_CPE_CRLF, nDevice, sAutobootCtl.accessCtl.nReturn)); ++ } ++ } ++ ++ DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX ++ "Autoboot restart executed" DSL_CPE_CRLF)); ++ + #ifdef INCLUDE_DSL_CPE_CLI_SUPPORT + for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; nDevice++) + { diff --git a/package/network/config/ltq-vdsl-vr9-app/patches/201-sigterm.patch b/package/network/config/ltq-vdsl-vr9-app/patches/201-sigterm.patch new file mode 100644 index 0000000000..4e97835983 --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/patches/201-sigterm.patch @@ -0,0 +1,19 @@ +--- a/src/dsl_cpe_control.c ++++ b/src/dsl_cpe_control.c +@@ -6504,7 +6504,7 @@ DSL_CPE_STATIC void DSL_CPE_Termination + /* ignore the signal, we'll handle by ourself */ + signal (sig, SIG_IGN); + +- if (sig == SIGINT) ++ if (sig == SIGINT || sig == SIGTERM) + { + DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX "terminated" DSL_CPE_CRLF)); + DSL_CPE_Termination (); +@@ -6803,6 +6803,7 @@ DSL_int_t dsl_cpe_daemon ( + + #ifndef RTEMS + signal (SIGINT, DSL_CPE_TerminationHandler); ++ signal (SIGTERM, DSL_CPE_TerminationHandler); + #endif /* RTEMS*/ + + /* Open DSL_CPE_MAX_DSL_ENTITIES devices*/ diff --git a/package/network/config/ltq-vdsl-vr9-app/patches/300-ubus.patch b/package/network/config/ltq-vdsl-vr9-app/patches/300-ubus.patch new file mode 100644 index 0000000000..d257ca2fc4 --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/patches/300-ubus.patch @@ -0,0 +1,50 @@ +--- a/src/dsl_cpe_control.c ++++ b/src/dsl_cpe_control.c +@@ -177,6 +177,9 @@ extern DSL_Error_t DSL_CPE_Pipe_StaticRe + #endif /* INCLUDE_DSL_RESOURCE_STATISTICS*/ + #endif + ++extern void ubus_init(); ++extern void ubus_deinit(); ++ + DSL_char_t *g_sFirmwareName1 = DSL_NULL; + DSL_FirmwareFeatures_t g_nFwFeatures1 = {DSL_FW_XDSLMODE_CLEANED, DSL_FW_XDSLFEATURE_CLEANED, + DSL_FW_XDSLFEATURE_CLEANED}; +@@ -6806,6 +6809,8 @@ DSL_int_t dsl_cpe_daemon ( + signal (SIGTERM, DSL_CPE_TerminationHandler); + #endif /* RTEMS*/ + ++ ubus_init(); ++ + /* Open DSL_CPE_MAX_DSL_ENTITIES devices*/ + for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; nDevice++) + { +@@ -7260,6 +7265,7 @@ DSL_int_t dsl_cpe_daemon ( + #endif /* INCLUDE_DSL_CPE_CLI_SUPPORT */ + + DSL_CPE_CONTROL_EXIT: ++ ubus_deinit(); + + #ifdef INCLUDE_DSL_BONDING + DSL_CPE_BND_Stop((DSL_CPE_BND_Context_t*)pCtrlCtx->pBnd); +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -11,7 +11,7 @@ else + dsl_cpe_control_common_ldflags = + endif + +-dsl_cpe_control_LDADD = -lpthread -lrt ++dsl_cpe_control_LDADD = -lpthread -lrt -lubox -lubus + + if INCLUDE_DSL_CPE_DTI_SUPPORT + dsl_cpe_control_LDADD += -ldti_agent +@@ -66,7 +66,8 @@ dsl_cpe_control_SOURCES = \ + dsl_cpe_control.c \ + dsl_cpe_init_cfg.c \ + dsl_cpe_linux.c \ +- dsl_cpe_debug.c ++ dsl_cpe_debug.c \ ++ dsl_cpe_ubus.c + + dsl_cpe_control_SOURCES += \ + $(dsl_cpe_control_dti_sources) diff --git a/package/network/config/ltq-vdsl-vr9-app/src/src/dsl_cpe_ubus.c b/package/network/config/ltq-vdsl-vr9-app/src/src/dsl_cpe_ubus.c new file mode 100644 index 0000000000..61ac7708ba --- /dev/null +++ b/package/network/config/ltq-vdsl-vr9-app/src/src/dsl_cpe_ubus.c @@ -0,0 +1,883 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (C) 2020 Andre Heider + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dsl_cpe_control.h" +#include +#ifdef INCLUDE_DSL_CPE_API_VRX +#include +#endif + +#define U16(v1, v2) ( \ + ((uint16_t)(v1) << 8) | \ + ((uint16_t)(v2))) + +#define U32(v1, v2, v3, v4) ( \ + ((uint32_t)(v1) << 24) | \ + ((uint32_t)(v2) << 16) | \ + ((uint32_t)(v3) << 8) | \ + ((uint32_t)(v4))) + +#define STR_CASE(id, text) \ + case id: \ + str = text; \ + break; + +#define STR_CASE_MAP(id, text, number) \ + case id: \ + str = text; \ + map = number; \ + break; + +#define IOCTL(type, request) \ + type out; \ + memset(&out, 0, sizeof(type)); \ + if (ioctl(fd, request, &out)) \ + return; + +#define IOCTL_DIR(type, request, dir) \ + type out; \ + memset(&out, 0, sizeof(type)); \ + out.nDirection = dir; \ + if (ioctl(fd, request, &out)) \ + return; + +#define IOCTL_DIR_DELT(type, request, dir, delt) \ + type out; \ + memset(&out, 0, sizeof(type)); \ + out.nDirection = dir; \ + out.nDeltDataType = delt; \ + if (ioctl(fd, request, &out)) \ + return; + +typedef enum { + ANNEX_UNKNOWN = 0, + ANNEX_A, + ANNEX_B, + ANNEX_C, + ANNEX_I, + ANNEX_J, + ANNEX_L, + ANNEX_M, +} annex_t; + +typedef enum { + STD_UNKNOWN = 0, + STD_T1_413, + STD_TS_101_388, + STD_G_992_1, + STD_G_992_2, + STD_G_992_3, + STD_G_992_4, + STD_G_992_5, + STD_G_993_1, + STD_G_993_2, +} standard_t; + +typedef enum { + VECTOR_UNKNOWN = 0, + VECTOR_OFF, + VECTOR_ON_DS, + VECTOR_ON_DS_US, +} vector_t; + +typedef enum { + PROFILE_UNKNOWN = 0, + PROFILE_8A, + PROFILE_8B, + PROFILE_8C, + PROFILE_8D, + PROFILE_12A, + PROFILE_12B, + PROFILE_17A, + PROFILE_30A, + PROFILE_35B, +} profile_t; + +/* These values are exported via ubus and backwards compability + * needs to be kept! + */ +enum { + LSTATE_MAP_UNKNOWN = -1, + LSTATE_MAP_NOT_INITIALIZED, + LSTATE_MAP_EXCEPTION, + LSTATE_MAP_IDLE, + LSTATE_MAP_SILENT, + LSTATE_MAP_HANDSHAKE, + LSTATE_MAP_FULL_INIT, + LSTATE_MAP_SHOWTIME_NO_SYNC, + LSTATE_MAP_SHOWTIME_TC_SYNC, + LSTATE_MAP_RESYNC, +}; + +/* These values are exported via ubus and backwards compability + * needs to be kept! + */ +enum { + PSTATE_MAP_UNKNOWN = -2, + PSTATE_MAP_NA, + PSTATE_MAP_L0, + PSTATE_MAP_L1, + PSTATE_MAP_L2, + PSTATE_MAP_L3, +}; + +static DSL_CPE_ThreadCtrl_t thread; +static struct ubus_context *ctx; +static struct blob_buf b; + +static inline void m_double(const char *id, double value) { + blobmsg_add_double(&b, id, value); +} + +static inline void m_bool(const char *id, bool value) { + blobmsg_add_u8(&b, id, value); +} + +static inline void m_u32(const char *id, uint32_t value) { + blobmsg_add_u64(&b, id, value); +} + +static inline void m_str(const char *id, const char *value) { + blobmsg_add_string(&b, id, value); +} + +static inline void m_db(const char *id, int value) { + m_double(id, (double)value / 10); +} + +static inline void m_array(const char *id, const uint8_t *value, uint8_t len) { + void *c = blobmsg_open_array(&b, id); + + for (uint8_t i = 0; i < len; ++i) + blobmsg_add_u16(&b, "", value[i]); + + blobmsg_close_array(&b, c); +} + +static void m_vendor(const char *id, const uint8_t *value) { + // ITU-T T.35: U.S. + if (U16(value[0], value[1]) != 0xb500) + return; + + const char *str = NULL; + switch (U32(value[2], value[3], value[4], value[5])) { + STR_CASE(0x414C4342, "Alcatel") + STR_CASE(0x414E4456, "Analog Devices") + STR_CASE(0x4244434D, "Broadcom") + STR_CASE(0x43454E54, "Centillium") + STR_CASE(0x4753504E, "Globespan") + STR_CASE(0x494B4E53, "Ikanos") + STR_CASE(0x4946544E, "Infineon") + STR_CASE(0x54535443, "Texas Instruments") + STR_CASE(0x544D4D42, "Thomson MultiMedia Broadband") + STR_CASE(0x5443544E, "Trend Chip Technologies") + STR_CASE(0x53544D49, "ST Micro") + }; + + if (!str) + return; + + if ((value[6] == 0) && (value[7] == 0)) { + m_str(id, str); + return; + } + + char buf[64]; + sprintf(buf, "%s %d.%d", str, value[6], value[7]); + m_str(id, buf); + + return; +} + +annex_t get_annex(const uint8_t *xtse) { + if ((xtse[0] & XTSE_1_01_A_T1_413) || + (xtse[0] & XTSE_1_03_A_1_NO) || + (xtse[0] & XTSE_1_04_A_1_O) || + (xtse[1] & XTSE_2_01_A_2_NO) || + (xtse[2] & XTSE_3_03_A_3_NO) || + (xtse[2] & XTSE_3_04_A_3_O) || + (xtse[3] & XTSE_4_01_A_4_NO) || + (xtse[3] & XTSE_4_02_A_4_O) || + (xtse[5] & XTSE_6_01_A_5_NO) || + (xtse[5] & XTSE_6_02_A_5_O) || + (xtse[7] & XTSE_8_01_A)) + return ANNEX_A; + + if ((xtse[0] & XTSE_1_05_B_1_NO) || + (xtse[0] & XTSE_1_06_B_1_O) || + (xtse[1] & XTSE_2_02_B_2_O) || + (xtse[2] & XTSE_3_05_B_3_NO) || + (xtse[2] & XTSE_3_06_B_3_O) || + (xtse[5] & XTSE_6_03_B_5_NO) || + (xtse[5] & XTSE_6_04_B_5_O) || + (xtse[7] & XTSE_8_02_B)) + return ANNEX_B; + + if ((xtse[0] & XTSE_1_02_C_TS_101388) || + (xtse[0] & XTSE_1_07_C_1_NO) || + (xtse[0] & XTSE_1_08_C_1_O) || + (xtse[1] & XTSE_2_03_C_2_NO) || + (xtse[1] & XTSE_2_04_C_2_O) || + (xtse[7] & XTSE_8_03_C)) + return ANNEX_C; + + if ((xtse[3] & XTSE_4_05_I_3_NO) || + (xtse[3] & XTSE_4_06_I_3_O) || + (xtse[4] & XTSE_5_01_I_4_NO) || + (xtse[4] & XTSE_5_02_I_4_O) || + (xtse[5] & XTSE_6_07_I_5_NO) || + (xtse[5] & XTSE_6_08_I_5_O)) + return ANNEX_I; + + if ((xtse[3] & XTSE_4_07_J_3_NO) || + (xtse[3] & XTSE_4_08_J_3_O) || + (xtse[6] & XTSE_7_01_J_5_NO) || + (xtse[6] & XTSE_7_02_J_5_O)) + return ANNEX_J; + + if ((xtse[4] & XTSE_5_03_L_3_NO) || + (xtse[4] & XTSE_5_04_L_3_NO) || + (xtse[4] & XTSE_5_05_L_3_O) || + (xtse[4] & XTSE_5_06_L_3_O)) + return ANNEX_L; + + if ((xtse[4] & XTSE_5_07_M_3_NO) || + (xtse[4] & XTSE_5_08_M_3_O) || + (xtse[6] & XTSE_7_03_M_5_NO) || + (xtse[6] & XTSE_7_04_M_5_O)) + return ANNEX_M; + + return ANNEX_UNKNOWN; +} + +static standard_t get_standard(const uint8_t *xtse) { + if (xtse[0] & XTSE_1_01_A_T1_413) + return STD_T1_413; + + if (xtse[0] & XTSE_1_02_C_TS_101388) + return STD_TS_101_388; + + if ((xtse[0] & XTSE_1_03_A_1_NO) || + (xtse[0] & XTSE_1_04_A_1_O) || + (xtse[0] & XTSE_1_05_B_1_NO) || + (xtse[0] & XTSE_1_06_B_1_O) || + (xtse[0] & XTSE_1_07_C_1_NO) || + (xtse[0] & XTSE_1_08_C_1_O)) + return STD_G_992_1; + + if ((xtse[1] & XTSE_2_01_A_2_NO) || + (xtse[1] & XTSE_2_02_B_2_O) || + (xtse[1] & XTSE_2_03_C_2_NO) || + (xtse[1] & XTSE_2_04_C_2_O)) + return STD_G_992_2; + + if ((xtse[2] & XTSE_3_03_A_3_NO) || + (xtse[2] & XTSE_3_04_A_3_O) || + (xtse[2] & XTSE_3_05_B_3_NO) || + (xtse[2] & XTSE_3_06_B_3_O) || + (xtse[3] & XTSE_4_05_I_3_NO) || + (xtse[3] & XTSE_4_06_I_3_O) || + (xtse[3] & XTSE_4_07_J_3_NO) || + (xtse[3] & XTSE_4_08_J_3_O) || + (xtse[4] & XTSE_5_03_L_3_NO) || + (xtse[4] & XTSE_5_04_L_3_NO) || + (xtse[4] & XTSE_5_05_L_3_O) || + (xtse[4] & XTSE_5_06_L_3_O) || + (xtse[4] & XTSE_5_07_M_3_NO) || + (xtse[4] & XTSE_5_08_M_3_O)) + return STD_G_992_3; + + if ((xtse[3] & XTSE_4_01_A_4_NO) || + (xtse[3] & XTSE_4_02_A_4_O) || + (xtse[4] & XTSE_5_01_I_4_NO) || + (xtse[4] & XTSE_5_02_I_4_O)) + return STD_G_992_4; + + if ((xtse[5] & XTSE_6_01_A_5_NO) || + (xtse[5] & XTSE_6_02_A_5_O) || + (xtse[5] & XTSE_6_03_B_5_NO) || + (xtse[5] & XTSE_6_04_B_5_O) || + (xtse[5] & XTSE_6_07_I_5_NO) || + (xtse[5] & XTSE_6_08_I_5_O) || + (xtse[6] & XTSE_7_01_J_5_NO) || + (xtse[6] & XTSE_7_02_J_5_O) || + (xtse[6] & XTSE_7_03_M_5_NO) || + (xtse[6] & XTSE_7_04_M_5_O)) + return STD_G_992_5; + + if (xtse[7] & XTSE_8_08) + return STD_G_993_1; + + if ((xtse[7] & XTSE_8_01_A) || + (xtse[7] & XTSE_8_02_B) || + (xtse[7] & XTSE_8_03_C)) + return STD_G_993_2; + + return STD_UNKNOWN; +} + +static void version_information(int fd) { + IOCTL(DSL_VersionInformation_t, DSL_FIO_VERSION_INFORMATION_GET) + + m_str("api_version", out.data.DSL_DriverVersionApi); + m_str("firmware_version", out.data.DSL_ChipSetFWVersion); + m_str("chipset", out.data.DSL_ChipSetType); + m_str("driver_version", out.data.DSL_DriverVersionMeiBsp); +} + +static void line_state(int fd) { + IOCTL(DSL_LineState_t, DSL_FIO_LINE_STATE_GET) + + int map = LSTATE_MAP_UNKNOWN; + const char *str; + switch (out.data.nLineState) { + STR_CASE_MAP(DSL_LINESTATE_NOT_INITIALIZED, "Not initialized", LSTATE_MAP_NOT_INITIALIZED) + STR_CASE_MAP(DSL_LINESTATE_EXCEPTION, "Exception", LSTATE_MAP_EXCEPTION) + STR_CASE(DSL_LINESTATE_NOT_UPDATED, "Not updated") + STR_CASE(DSL_LINESTATE_IDLE_REQUEST, "Idle request") + STR_CASE_MAP(DSL_LINESTATE_IDLE, "Idle", LSTATE_MAP_IDLE) + STR_CASE(DSL_LINESTATE_SILENT_REQUEST, "Silent request") + STR_CASE_MAP(DSL_LINESTATE_SILENT, "Silent", LSTATE_MAP_SILENT) + STR_CASE_MAP(DSL_LINESTATE_HANDSHAKE, "Handshake", LSTATE_MAP_HANDSHAKE) + STR_CASE(DSL_LINESTATE_BONDING_CLR, "Bonding CLR") + STR_CASE_MAP(DSL_LINESTATE_FULL_INIT, "Full init", LSTATE_MAP_FULL_INIT) + STR_CASE(DSL_LINESTATE_SHORT_INIT_ENTRY, "Short init entry") + STR_CASE(DSL_LINESTATE_DISCOVERY, "Discovery") + STR_CASE(DSL_LINESTATE_TRAINING, "Training") + STR_CASE(DSL_LINESTATE_ANALYSIS, "Analysis") + STR_CASE(DSL_LINESTATE_EXCHANGE, "Exchange") + STR_CASE_MAP(DSL_LINESTATE_SHOWTIME_NO_SYNC, "Showtime without TC-Layer sync", LSTATE_MAP_SHOWTIME_NO_SYNC) + STR_CASE_MAP(DSL_LINESTATE_SHOWTIME_TC_SYNC, "Showtime with TC-Layer sync", LSTATE_MAP_SHOWTIME_TC_SYNC) + STR_CASE(DSL_LINESTATE_FASTRETRAIN, "Fastretrain") + STR_CASE(DSL_LINESTATE_LOWPOWER_L2, "Lowpower L2") + STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_ACTIVE, "Loopdiagnostic active") + STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_DATA_EXCHANGE, "Loopdiagnostic data exchange") + STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_DATA_REQUEST, "Loopdiagnostic data request") + STR_CASE(DSL_LINESTATE_LOOPDIAGNOSTIC_COMPLETE, "Loopdiagnostic complete") + STR_CASE_MAP(DSL_LINESTATE_RESYNC, "Resync", LSTATE_MAP_RESYNC) + STR_CASE(DSL_LINESTATE_TEST, "Test") + STR_CASE(DSL_LINESTATE_TEST_LOOP, "Test loop") + STR_CASE(DSL_LINESTATE_TEST_REVERB, "Test reverb") + STR_CASE(DSL_LINESTATE_TEST_MEDLEY, "Test medley") + STR_CASE(DSL_LINESTATE_TEST_SHOWTIME_LOCK, "Showtime lock") + STR_CASE(DSL_LINESTATE_TEST_QUIET, "Quiet") + STR_CASE(DSL_LINESTATE_LOWPOWER_L3, "Lowpower L3") +#ifndef INCLUDE_DSL_CPE_API_DANUBE + STR_CASE(DSL_LINESTATE_DISABLED, "Disabled") + STR_CASE(DSL_LINESTATE_T1413, "T1413") + STR_CASE(DSL_LINESTATE_ORDERLY_SHUTDOWN_REQUEST, "Orderly shutdown request") + STR_CASE(DSL_LINESTATE_ORDERLY_SHUTDOWN, "Orderly shutdown") + STR_CASE(DSL_LINESTATE_TEST_FILTERDETECTION_ACTIVE, "Test filterdetection active") + STR_CASE(DSL_LINESTATE_TEST_FILTERDETECTION_COMPLETE, "Test filterdetection complete") +#endif + default: + str = NULL; + break; + }; + + if (str) + m_str("state", str); + + if (map != LSTATE_MAP_UNKNOWN ) + m_u32("state_num", map); + + m_bool("up", out.data.nLineState == DSL_LINESTATE_SHOWTIME_TC_SYNC); +} + +static void pm_channel_counters_showtime(int fd) { + IOCTL_DIR(DSL_PM_ChannelCounters_t, DSL_FIO_PM_CHANNEL_COUNTERS_SHOWTIME_GET, DSL_NEAR_END); + + m_u32("uptime", out.interval.nElapsedTime); +} + +static void g997_line_inventory(int fd) { + IOCTL_DIR(DSL_G997_LineInventory_t, DSL_FIO_G997_LINE_INVENTORY_GET, DSL_DOWNSTREAM) + + m_array("vendor_id", out.data.G994VendorID, DSL_G997_LI_MAXLEN_VENDOR_ID); + m_vendor("vendor", out.data.G994VendorID); + m_array("system_vendor_id", out.data.SystemVendorID, DSL_G997_LI_MAXLEN_VENDOR_ID); + m_vendor("system_vendor", out.data.SystemVendorID); + m_array("version", out.data.VersionNumber, DSL_G997_LI_MAXLEN_VERSION); + m_array("serial", out.data.SerialNumber, DSL_G997_LI_MAXLEN_SERIAL); +} + +static void g997_power_management_status(int fd) { + IOCTL(DSL_G997_PowerManagementStatus_t, DSL_FIO_G997_POWER_MANAGEMENT_STATUS_GET) + + int map = PSTATE_MAP_UNKNOWN; + const char *str; + switch (out.data.nPowerManagementStatus) { + STR_CASE_MAP(DSL_G997_PMS_NA, "Power management state is not available", PSTATE_MAP_NA) + STR_CASE_MAP(DSL_G997_PMS_L0, "L0 - Synchronized", PSTATE_MAP_L0) + STR_CASE_MAP(DSL_G997_PMS_L1, "L1 - Power Down Data transmission (G.992.2)", PSTATE_MAP_L1) + STR_CASE_MAP(DSL_G997_PMS_L2, "L2 - Power Down Data transmission (G.992.3 and G.992.4)", PSTATE_MAP_L2) + STR_CASE_MAP(DSL_G997_PMS_L3, "L3 - No power", PSTATE_MAP_L3) + default: + str = NULL; + break; + }; + + if (str) + m_str("power_state", str); + + if (map != PSTATE_MAP_UNKNOWN) + m_u32("power_state_num", map); +} + +static void g997_xtu_system_enabling(int fd, standard_t *standard) { + IOCTL(DSL_G997_XTUSystemEnabling_t, DSL_FIO_G997_XTU_SYSTEM_ENABLING_STATUS_GET) + + m_array("xtse", out.data.XTSE, DSL_G997_NUM_XTSE_OCTETS); + + const char *str; + switch (get_annex(out.data.XTSE)) { + STR_CASE(ANNEX_A, "A") + STR_CASE(ANNEX_B, "B") + STR_CASE(ANNEX_C, "C") + STR_CASE(ANNEX_I, "I") + STR_CASE(ANNEX_J, "J") + STR_CASE(ANNEX_L, "L") + STR_CASE(ANNEX_M, "M") + default: + str = NULL; + break; + }; + if (str) + m_str("annex", str); + + *standard = get_standard(out.data.XTSE); + + switch (*standard) { + STR_CASE(STD_T1_413, "T1.413") + STR_CASE(STD_TS_101_388, "TS 101 388") + STR_CASE(STD_G_992_1, "G.992.1") + STR_CASE(STD_G_992_2, "G.992.2") + STR_CASE(STD_G_992_3, "G.992.3") + STR_CASE(STD_G_992_4, "G.992.4") + STR_CASE(STD_G_992_5, "G.992.5") + STR_CASE(STD_G_993_1, "G.993.1") + STR_CASE(STD_G_993_2, "G.993.2") + default: + str = NULL; + break; + } + if (str) + m_str("standard", str); +} + +static void get_vector_status(int fd, vector_t *status) { + *status = VECTOR_UNKNOWN; + +#ifdef INCLUDE_DSL_CPE_API_VRX + if (fd < 0) + return; + + IOCTL(IOCTL_MEI_dsmStatus_t, FIO_MEI_DSM_STATUS_GET); + + switch (out.eVectorStatus) { + case e_MEI_VECTOR_STAT_OFF: + *status = VECTOR_OFF; + break; + case e_MEI_VECTOR_STAT_ON_DS: + *status = VECTOR_ON_DS; + break; + case e_MEI_VECTOR_STAT_ON_DS_US: + *status = VECTOR_ON_DS_US; + break; + default: + break; + }; +#endif +} + +static void vector_erb(int fd) { +#ifdef INCLUDE_DSL_CPE_API_VRX + if (fd < 0) + return; + + IOCTL(IOCTL_MEI_dsmStatistics_t, FIO_MEI_DSM_STATISTICS_GET); + + m_u32("sent", out.n_processed); + m_u32("discarded", out.n_fw_dropped_size + out.n_mei_dropped_size + out.n_mei_dropped_no_pp_cb + out.n_pp_dropped); +#endif +} + +static void band_plan_status(int fd, profile_t *profile) { +#if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1) + IOCTL(DSL_BandPlanStatus_t, DSL_FIO_BAND_PLAN_STATUS_GET) + + switch (out.data.nProfile) { + case DSL_PROFILE_8A: + *profile = PROFILE_8A; + break; + case DSL_PROFILE_8B: + *profile = PROFILE_8B; + break; + case DSL_PROFILE_8C: + *profile = PROFILE_8C; + break; + case DSL_PROFILE_8D: + *profile = PROFILE_8D; + break; + case DSL_PROFILE_12A: + *profile = PROFILE_12A; + break; + case DSL_PROFILE_12B: + *profile = PROFILE_12B; + break; + case DSL_PROFILE_17A: + *profile = PROFILE_17A; + break; + case DSL_PROFILE_30A: + *profile = PROFILE_30A; + break; + case DSL_PROFILE_35B: + *profile = PROFILE_35B; + break; + default: + *profile = PROFILE_UNKNOWN; + break; + }; + + const char *str; + switch (*profile) { + STR_CASE(PROFILE_8A, "8a") + STR_CASE(PROFILE_8B, "8b") + STR_CASE(PROFILE_8C, "8c") + STR_CASE(PROFILE_8D, "8d") + STR_CASE(PROFILE_12A, "12a") + STR_CASE(PROFILE_12B, "12b") + STR_CASE(PROFILE_17A, "17a") + STR_CASE(PROFILE_30A, "30a") + STR_CASE(PROFILE_35B, "35b") + default: + str = NULL; + break; + }; + if (str) + m_str("profile", str); +#endif +} + +static void line_feature_config(int fd, DSL_AccessDir_t direction) { + IOCTL_DIR(DSL_LineFeature_t, DSL_FIO_LINE_FEATURE_STATUS_GET, direction) + + m_bool("trellis", out.data.bTrellisEnable); + m_bool("bitswap", out.data.bBitswapEnable); + m_bool("retx", out.data.bReTxEnable); + m_bool("virtual_noise", out.data.bVirtualNoiseSupport); +} + +static void g997_channel_status(int fd, DSL_AccessDir_t direction) { + IOCTL_DIR(DSL_G997_ChannelStatus_t, DSL_FIO_G997_CHANNEL_STATUS_GET, direction); + + m_u32("interleave_delay", out.data.ActualInterleaveDelay * 10); +#ifndef INCLUDE_DSL_CPE_API_DANUBE + // prefer ACTNDR, see comments in drv_dsl_cpe_api_g997.h + m_u32("data_rate", out.data.ActualNetDataRate); +#else + m_u32("data_rate", out.data.ActualDataRate); +#endif +} + +static void g997_line_status(int fd, DSL_AccessDir_t direction) { + IOCTL_DIR_DELT(DSL_G997_LineStatus_t, DSL_FIO_G997_LINE_STATUS_GET, direction, DSL_DELT_DATA_SHOWTIME); + + m_db("latn", out.data.LATN); + m_db("satn", out.data.SATN); + m_db("snr", out.data.SNR); + m_db("actps", out.data.ACTPS); + m_db("actatp", out.data.ACTATP); + m_u32("attndr", out.data.ATTNDR); +} + +static void pm_line_sec_counters_total(int fd, DSL_XTUDir_t direction) { + IOCTL_DIR(DSL_PM_LineSecCountersTotal_t, DSL_FIO_PM_LINE_SEC_COUNTERS_TOTAL_GET, direction) + + m_u32("es", out.data.nES); + m_u32("ses", out.data.nSES); + m_u32("loss", out.data.nLOSS); + m_u32("uas", out.data.nUAS); + m_u32("lofs", out.data.nLOFS); +#ifndef INCLUDE_DSL_CPE_API_DANUBE + m_u32("fecs", out.data.nFECS); +#endif +} + +static void pm_data_path_counters_total(int fd, DSL_XTUDir_t direction) { + IOCTL_DIR(DSL_PM_DataPathCountersTotal_t, DSL_FIO_PM_DATA_PATH_COUNTERS_TOTAL_GET, direction); + + m_u32("hec", out.data.nHEC); + m_u32("ibe", out.data.nIBE); + m_u32("crc_p", out.data.nCRC_P); + m_u32("crcp_p", out.data.nCRCP_P); + m_u32("cv_p", out.data.nCV_P); + m_u32("cvp_p", out.data.nCVP_P); +} + +static void retx_statistics(int fd, DSL_XTUDir_t direction) { +#ifdef INCLUDE_DSL_CPE_PM_RETX_COUNTERS +#ifdef INCLUDE_DSL_CPE_PM_RETX_THRESHOLDS + IOCTL_DIR(DSL_ReTxStatistics_t, DSL_FIO_RETX_STATISTICS_GET, direction); + + m_u32("rx_corrupted", out.data.nRxCorruptedTotal); + m_u32("rx_uncorrected_protected", out.data.nRxUncorrectedProtected); + m_u32("rx_retransmitted", out.data.nRxRetransmitted); + m_u32("rx_corrected", out.data.nRxCorrected); + m_u32("tx_retransmitted", out.data.nTxRetransmitted); +#endif +#endif +} + +static void describe_mode(standard_t standard, profile_t profile, vector_t vector) { + char buf[128]; + + switch (standard) { + case STD_T1_413: + strcpy(buf, "T1.413"); + break; + case STD_TS_101_388: + strcpy(buf, "TS 101 388"); + break; + case STD_G_992_1: + strcpy(buf, "G.992.1 (ADSL)"); + break; + case STD_G_992_2: + strcpy(buf, "G.992.2 (ADSL lite)"); + break; + case STD_G_992_3: + strcpy(buf, "G.992.3 (ADSL2)"); + break; + case STD_G_992_4: + strcpy(buf, "G.992.4 (ADSL2 lite)"); + break; + case STD_G_992_5: + strcpy(buf, "G.992.5 (ADSL2+)"); + break; + case STD_G_993_1: + strcpy(buf, "G.993.1 (VDSL)"); + break; + case STD_G_993_2: + strcpy(buf, "G.993.2 (VDSL2"); + + switch (profile) { + case PROFILE_8A: + strcat(buf, ", Profile 8a"); + break; + case PROFILE_8B: + strcat(buf, ", Profile 8b"); + break; + case PROFILE_8C: + strcat(buf, ", Profile 8c"); + break; + case PROFILE_8D: + strcat(buf, ", Profile 8d"); + break; + case PROFILE_12A: + strcat(buf, ", Profile 12a"); + break; + case PROFILE_12B: + strcat(buf, ", Profile 12b"); + break; + case PROFILE_17A: + strcat(buf, ", Profile 17a"); + break; + case PROFILE_30A: + strcat(buf, ", Profile 30a"); + break; + case PROFILE_35B: + strcat(buf, ", Profile 35b"); + break; + default: + break; + }; + + switch (vector) { + case VECTOR_ON_DS: + strcat(buf, ", with downstream vectoring"); + break; + case VECTOR_ON_DS_US: + strcat(buf, ", with down- and upstream vectoring"); + break; + default: + break; + }; + + strcat(buf, ")"); + break; + default: + return; + }; + + m_str("mode", buf); +} + +static int metrics(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int fd, fd_mei; + void *c, *c2; + standard_t standard = STD_UNKNOWN; + profile_t profile = PROFILE_UNKNOWN; + vector_t vector = VECTOR_UNKNOWN; + +#ifndef INCLUDE_DSL_CPE_API_DANUBE + fd = open(DSL_CPE_DEVICE_NAME "/0", O_RDWR, 0644); +#else + fd = open(DSL_CPE_DEVICE_NAME, O_RDWR, 0644); +#endif + if (fd < 0) + return UBUS_STATUS_UNKNOWN_ERROR; + +#ifdef INCLUDE_DSL_CPE_API_VRX + fd_mei = open(DSL_CPE_DSL_LOW_DEV "/0", O_RDWR, 0644); +#else + fd_mei = -1; +#endif + + blob_buf_init(&b, 0); + + version_information(fd); + line_state(fd); + pm_channel_counters_showtime(fd); + + c = blobmsg_open_table(&b, "atu_c"); + g997_line_inventory(fd); + blobmsg_close_table(&b, c); + + g997_power_management_status(fd); + g997_xtu_system_enabling(fd, &standard); + + if (standard == STD_G_993_2) { + band_plan_status(fd, &profile); + get_vector_status(fd_mei, &vector); + } + + describe_mode(standard, profile, vector); + + c = blobmsg_open_table(&b, "upstream"); + switch (vector) { + case VECTOR_OFF: + m_bool("vector", false); + break; + case VECTOR_ON_DS_US: + m_bool("vector", true); + break; + default: + break; + }; + line_feature_config(fd, DSL_UPSTREAM); + g997_channel_status(fd, DSL_UPSTREAM); + g997_line_status(fd, DSL_UPSTREAM); + blobmsg_close_table(&b, c); + + c = blobmsg_open_table(&b, "downstream"); + switch (vector) { + case VECTOR_OFF: + m_bool("vector", false); + break; + case VECTOR_ON_DS: + case VECTOR_ON_DS_US: + m_bool("vector", true); + break; + default: + break; + }; + line_feature_config(fd, DSL_DOWNSTREAM); + g997_channel_status(fd, DSL_DOWNSTREAM); + g997_line_status(fd, DSL_DOWNSTREAM); + blobmsg_close_table(&b, c); + + c = blobmsg_open_table(&b, "errors"); + c2 = blobmsg_open_table(&b, "near"); + pm_line_sec_counters_total(fd, DSL_NEAR_END); + pm_data_path_counters_total(fd, DSL_NEAR_END); + retx_statistics(fd, DSL_NEAR_END); + blobmsg_close_table(&b, c2); + + c2 = blobmsg_open_table(&b, "far"); + pm_line_sec_counters_total(fd, DSL_FAR_END); + pm_data_path_counters_total(fd, DSL_FAR_END); + retx_statistics(fd, DSL_FAR_END); + blobmsg_close_table(&b, c2); + blobmsg_close_table(&b, c); + + switch (vector) { + case VECTOR_ON_DS: + case VECTOR_ON_DS_US: + c = blobmsg_open_table(&b, "erb"); + vector_erb(fd_mei); + blobmsg_close_table(&b, c); + break; + default: + break; + }; + + ubus_send_reply(ctx, req, b.head); + + if (fd_mei >= 0) + close(fd_mei); + close(fd); + + return 0; +} + +static const struct ubus_method dsl_methods[] = { + UBUS_METHOD_NOARG("metrics", metrics), +}; + +static struct ubus_object_type dsl_object_type = + UBUS_OBJECT_TYPE("dsl", dsl_methods); + +static struct ubus_object dsl_object = { + .name = "dsl", + .type = &dsl_object_type, + .methods = dsl_methods, + .n_methods = ARRAY_SIZE(dsl_methods), +}; + +static DSL_int_t ubus_main(DSL_CPE_Thread_Params_t *params) { + uloop_run(); + return 0; +} + +void ubus_init() { + uloop_init(); + + ctx = ubus_connect(NULL); + if (!ctx) + return; + + if (ubus_add_object(ctx, &dsl_object)) { + ubus_free(ctx); + ctx = NULL; + return; + } + + ubus_add_uloop(ctx); + + DSL_CPE_ThreadInit(&thread, "ubus", ubus_main, DSL_CPE_PIPE_STACK_SIZE, DSL_CPE_PIPE_PRIORITY, 0, 0); +} + +void ubus_deinit() { + if (!ctx) + return; + + ubus_free(ctx); + uloop_done(); + + DSL_CPE_ThreadShutdown(&thread, 1000); +} -- cgit v1.2.3