ltq-vdsl-app: use ubus to provide metrics
[openwrt/staging/dedeckeh.git] / package / network / config / ltq-vdsl-app / files / dsl_control
index c659d50e1b8d2fa5c98a3afc666626b4ba767124..54b739e2cd9d00eae0c6ba4b04ab362e47f36782 100644 (file)
@@ -1,15 +1,14 @@
 #!/bin/sh /etc/rc.common
 # Copyright (C) 2012 OpenWrt.org
 
-# needs to start before the atm layer which starts at 50
-START=48
+START=97
 USE_PROCD=1
 
-EXTRA_COMMANDS="status lucistat"
-EXTRA_HELP="   status  Get DSL status information
-       lucistat  Get status information if lua friendly format"
+dslstat() {
+       ubus call dsl metrics
+}
 
-[ -f /lib/functions/lantiq_dsl.sh ] && . /lib/functions/lantiq_dsl.sh
+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))
@@ -109,7 +108,7 @@ locs 0 $1
 }
 
 [Common]={
-}" > /tmp/adsl.scr
+}" > /tmp/dsl.scr
 }
 
 lowlevel_cfg() {
@@ -180,6 +179,7 @@ start_service() {
        local xtse
        local xfer_mode
        local line_mode
+       local tc_layer
        local mode
        local lowlevel
        local snr
@@ -194,37 +194,44 @@ start_service() {
 
        eval "xtse=\"\${xtse_xdsl_$annex}\""
 
-       [ -z "${xfer_mode}" ] && xfer_mode=ptm
-
        case "${xfer_mode}" in
        atm)
-               LOAD=ltq_atm_vr9
-               UNLOAD=ltq_ptm_vr9
-
-               # in most cases atm is used on top of adsl
-               [ -z "${line_mode}" ] && line_mode=adsl
+               tc_layer="-T1:0x1:0x1_1:0x1:0x1"
                ;;
-       *)
-               LOAD=ltq_ptm_vr9
-               UNLOAD=ltq_atm_vr9
-
-               # in most cases ptm is used on top of vdsl
-               [ -z "${line_mode}" ] && line_mode=vdsl
+       ptm)
+               tc_layer="-T2:0x1:0x1_2:0x1:0x1"
                ;;
        esac
 
        case "${line_mode}" in
        adsl)
-               mode=1
+               mode="-M1"
 
-               # mask out VDSL bits when ATM is requested
+               # mask out VDSL bits when ADSL is requested
                xtse="${xtse%_*}_00"
                ;;
-       *)
-               mode=2
+       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
@@ -245,7 +252,9 @@ start_service() {
                                fi
                                ;;
                        b*|j*)
-                               if [ -f "/lib/firmware/lantiq-vrx200-b.bin" ]; then
+                               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"
@@ -283,24 +292,22 @@ start_service() {
        [ -z "${snr}" ] || {
            # for SNR offset setting
            autoboot_script "$snr"
-           autoboot="-a /tmp/adsl.scr"
+           autoboot="-a /tmp/dsl.scr -A /tmp/dsl.scr"
        }
 
        procd_open_instance
-       procd_set_param command /sbin/vdsl_cpe_control_wrapper \
+       procd_set_param command /sbin/vdsl_cpe_control \
                        -i$xtse \
                        -n /sbin/dsl_notify.sh \
                        -f ${firmware} \
                        $lowlevel \
-                       -M ${mode} \
+                       ${mode} \
+                       ${tc_layer} \
                        $autoboot
-       procd_append_param env "LOAD=$LOAD" "UNLOAD=$UNLOAD"
        procd_close_instance
 }
 
 stop_service() {
-       # do not use dsl_cmd to not block when this is locked up by some other proess
-       echo quit > /tmp/pipe/dsl_cpe0_cmd
        DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
        DSL_INTERFACE_STATUS="DOWN" \
                /sbin/dsl_notify.sh