From a2a63abf36fb4a518545c869fe1e38119bd997f3 Mon Sep 17 00:00:00 2001
From: Yalu Zhang <yalu.zhang@iopsys.eu>
Date: Wed, 29 Jan 2020 16:12:46 +0100
Subject: [PATCH] xDSL and xTM header files updated with advanced parameters

---
 libdsl/common.h |  59 ++++++
 libdsl/xdsl.h   | 497 ++++++++++++++++++++++++++++++++++++++++++++++--
 libdsl/xtm.h    | 243 +++++++++++++++++++++++
 3 files changed, 779 insertions(+), 20 deletions(-)
 create mode 100644 libdsl/common.h
 create mode 100644 libdsl/xtm.h

diff --git a/libdsl/common.h b/libdsl/common.h
new file mode 100644
index 0000000..9e33afe
--- /dev/null
+++ b/libdsl/common.h
@@ -0,0 +1,59 @@
+/*
+ * common.h - Common definitions for xDSL, ATM and PTM
+ *
+ * Copyright (C) 2020 iopsys Software Solutions AB. All rights reserved.
+ *
+ * Author: yalu.zhang@iopsys.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+
+#define LIBDSL_LOG(log_level, format...) fprintf(stderr, ##format)
+
+/** enum dsl_status - operational status of a line, channel or an interface */
+enum itf_status {
+	/* Starts with non-zero in order to distinguish from an uninitialized value which is usually 0 */
+	IF_UP = 1,
+	IF_DOWN,
+	IF_UNKNOWN,
+	IF_DORMANT,
+	IF_NOTPRESENT,
+	IF_LLDOWN,
+	IF_ERROR
+};
+
+/** enum diag_state - The diagnostic state of an ATM loopback test */
+enum diag_state {
+	ATM_DIAG_NONE,
+	ATM_DIAG_REQUESTED,
+	ATM_DIAG_CANCELED,
+	ATM_DIAG_COMPLETE,
+	ATM_DIAG_ERROR,
+	ATM_DIAG_ERROR_INTERNAL,
+	ATM_DIAG_ERROR_OTHER
+};
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _COMMON_H_ */
diff --git a/libdsl/xdsl.h b/libdsl/xdsl.h
index 8fe02cd..5fa6b5c 100644
--- a/libdsl/xdsl.h
+++ b/libdsl/xdsl.h
@@ -3,7 +3,7 @@
  * This file provides definition for the libdsl APIs and related
  * structures.
  *
- * Copyright (C) 2019 iopsys Software Solutions AB. All rights reserved.
+ * Copyright (C) 2020 iopsys Software Solutions AB. All rights reserved.
  *
  * Author: anjan.chanda@iopsys.eu
  *         yalu.zhang@iopsys.eu
@@ -40,18 +40,7 @@ typedef struct { unsigned long us; unsigned long ds; } dsl_ulong_t;
 typedef struct { bool us; bool ds; } dsl_bool_t;
 typedef struct { long array[24]; int count; } dsl_long_sequence_t;
 typedef struct { unsigned long array[24]; int count; } dsl_ulong_sequence_t;
-
-/** enum dsl_status - operational status of a line or channel */
-enum dsl_if_status {
-	/* Starts with non-zero in order to distinguish from an uninitialized value which is usually 0 */
-	IF_UP = 1,
-	IF_DOWN,
-	IF_UNKNOWN,
-	IF_DORMANT,
-	IF_NOTPRESENT,
-	IF_LLDOWN,
-	IF_ERROR
-};
+typedef struct { unsigned long *elements; int count; } dsl_ulong_elements_t;
 
 /** enum dsl_link_status - link status */
 enum dsl_link_status {
@@ -224,7 +213,7 @@ enum dsl_power_state {
 /** struct dsl_line - DSL line parameters */
 struct dsl_line {
 	/** The current operational state of the DSL line */
-	enum dsl_if_status status;
+	enum itf_status status;
 	/** Whether the interface points towards the Internet (true) or towards End Devices (false) */
 	bool upstream;
 	/** The version of the modem firmware currently installed for this interface */
@@ -245,22 +234,34 @@ struct dsl_line {
 	enum dsl_power_state power_management_state;
 	/** The success failure cause of the initialization */
 	unsigned int success_failure_cause;
+	/** VTU-R estimated electrical loop length in the range from 0 to 128 dB in steps of 0.1 dB */
+	unsigned int upbokler;
+	/** VTU-O estimated upstream power back-off electrical length per band */
+	dsl_ulong_sequence_t upbokle_pb;
 	/** VTU-R estimated upstream power back-off electrical length per band */
 	dsl_ulong_sequence_t upbokler_pb;
 	/** Downstream receiver signal level threshold */
 	dsl_ulong_sequence_t rxthrsh_ds;
 	/** The actual active rate adaptation mode in both directions */
 	dsl_ulong_t act_ra_mode;
-	/** The actual signal-to-noise margin of the robust overhead channel (ROC) */
-	unsigned int snr_mroc_us;
+	/** The actual impulse noise protection of the robust overhead channel in both directions */
+	dsl_ulong_t act_inp_roc;
+	/** The actual signal-to-noise margin of the robust overhead channel (ROC) in both directions */
+	dsl_ulong_t snr_mroc;
 	/** The last successful transmitted initialization state in both directions */
 	dsl_ulong_t last_state_transmitted;
+	/** VTU-O estimated electrical loop length in the range from 0 to 128 dB in steps of 0.1 dB */
+	unsigned int upbokle;
+	/** The enabled VDSL2 Limit PSD mask of the selected PSD mask class */
+	unsigned int limit_mask;
 	/** The allowed VDSL2 US0 PSD masks for Annex A operation */
 	unsigned int us0_mask;
 	/** Whether trellis coding is enabled in the downstream and upstream directions */
 	dsl_long_t trellis;
 	/** Whether the OPTIONAL virtual noise mechanism is in use in both directions */
 	dsl_ulong_t act_snr_mode;
+	/** The actual cyclic extension */
+	unsigned int actual_ce;
 	/** The line pair that the modem is using to connection */
 	int line_number;
 	/** The current maximum attainable data rate in both directions (expressed in Kbps) */
@@ -271,6 +272,17 @@ struct dsl_line {
 	dsl_long_sequence_t snr_mpb_us;
 	/** The current signal-to-noise ratio margin of each downstream band */
 	dsl_long_sequence_t snr_mpb_ds;
+	/** The Impulse Noise Monitoring (INM) Inter Arrival Time (IAT) Offset ranges from 3 to 511
+	 *  DMT symbols in steps of 1 */
+	unsigned int inmiato_ds;
+	/** The Impulse Noise Monitoring (INM) Inter Arrival Time (IAT) Step ranges from 0 to 7 in step of 1 */
+	unsigned int inmiats_ds;
+	/** The Impulse Noise Monitoring (INM) Cluster Continuation (CC) value ranges from 0 to 64
+	 *  DMT symbols in steps of 1 */
+	unsigned int inmcc_ds;
+	/** The Impulse Noise Monitoring (INM) Equivalent Impulse Noise Protection (INP) Mode that
+	 *  the xTU receiver uses ranges from 0 to 3 */
+	unsigned int inm_inpeq_mode_ds;
 	/** The current upstream and downstream signal loss (expressed in 0.1dB). */
 	dsl_long_t attenuation;
 	/** The current output and received power at the CPE's DSL line (expressed in 0.1dBmV) */
@@ -293,7 +305,11 @@ struct dsl_line {
 	unsigned int xtuc_ansi_rev;
 };
 
-/** struct dsl_line_channel_stats - Statistics counters for DSL line and channel */
+/**
+ * struct dsl_line_channel_stats - Statistics counters for DSL line and channel
+ * Note that only DSL specific statistics counters are defined since generic statistics are define
+ * in an IP interface
+ */
 struct dsl_line_channel_stats {
 	/** The number of seconds since the beginning of the period used for collection of Total statistics */
 	unsigned int total_start;
@@ -328,6 +344,42 @@ enum dsl_stats_type {
 	DSL_STATS_QUARTERHOUR
 };
 
+/** struct dsl_line_test_params - DSL line test parameters that are available during L0 (Showtime) state */
+struct dsl_line_test_params {
+	dsl_ulong_t hlogg; /** Number of sub-carriers per sub-carrier group in both directions */
+	dsl_ulong_elements_t hlogps_ds; /** Downstream logarithmic line characteristics per sub-carrier group */
+	dsl_ulong_elements_t hlogps_us; /** Upstream logarithmic line characteristics per sub-carrier group */
+	dsl_ulong_t hlogmt; /** Number of symbols over which HLOGps were measured in both directions */
+
+	dsl_ulong_t qlng; /* Number of sub-carriers per sub-carrier group for QLNps in both directions */
+	dsl_ulong_elements_t qlnps_ds; /** Downstream quiet line noise per sub-carrier group */
+	dsl_ulong_elements_t qlnps_us; /** Upstream quiet line noise per sub-carrier group */
+	dsl_ulong_t qlnmt; /** Number of symbols over which QLNps were measured in both directions */
+
+	dsl_ulong_t snrg; /* Number of sub-carriers per sub-carrier group for SNRps in both directions */
+	dsl_ulong_elements_t snrps_ds; /** Downstream SNR per sub-carrier group */
+	dsl_ulong_elements_t snrps_us; /** Upstream SNR per sub-carrier group */
+	dsl_ulong_t snrmt; /** Number of symbols over which SNRps were measured in both directions */
+
+	/** Downstream line attenuation averaged across all sub-carriers in the frequency band */
+	dsl_ulong_elements_t latn_ds;
+	/** Upstream line attenuation averaged across all sub-carriers in the frequency band */
+	dsl_ulong_elements_t latn_us;
+
+	/** Downstream line attenuation averaged across all active sub-carriers in the frequency band */
+	dsl_ulong_elements_t satn_ds;
+	/** Upstream line attenuation averaged across all active sub-carriers in the frequency band */
+	dsl_ulong_elements_t satn_us;
+};
+
+/** struct dsl_line_data_gathering - DSL line data gathering at the VTU-R. This only applies to VDSL2 */
+struct dsl_line_data_gathering {
+	/** Max depth of entire data gathering event buffer at VTU-R */
+	unsigned int logging_depth_r;
+	/** Actual depth this is used for reporting data gathering event buffer at VTU-R */
+	unsigned int act_logging_depth_r;
+};
+
 /** enum dsl_link_encapsulation - Type of link encapsulation method defineds as bit maps */
 enum dsl_link_encapsulation {
 	G_992_3_ANNEK_K_ATM	= 1,
@@ -340,7 +392,7 @@ enum dsl_link_encapsulation {
 /** struct dsl_channel - DSL channel parameters */
 struct dsl_channel {
 	/** The current operational state of the DSL channel */
-	enum dsl_if_status status;
+	enum itf_status status;
 	/** Which link encapsulation standards and recommendations are supported by the channel */
 	unsigned long link_encapsulation_supported;
 	/** The link encapsulation standard that the channel instance is using for the connection. */
@@ -391,6 +443,227 @@ struct dsl_channel_stats_interval {
 	unsigned int xtuc_crc_errors;
 };
 
+/** struct adsl_line_test - Diagnostic information for ADSL, ADSL2 and ADSL2+ */
+struct adsl_line_test {
+	dsl_long_t act_psd; /** Actual power spectral density in both directions */
+	dsl_long_t act_atp; /** Actual aggregate transmission power in both directions */
+
+	dsl_long_t hlinsc; /** Linear representation scales in both directions */
+	dsl_ulong_t hling; /** Number of sub-carriers per sub-carrier group for HLINps in both directions */
+
+	dsl_ulong_t hlogg; /** Number of sub-carriers per sub-carrier group for HLOGps in both directions */
+	dsl_ulong_elements_t hlogps_ds; /** Downstream logarithmic channel characteristics per sub-carrier group */
+	dsl_ulong_elements_t hlogps_us; /** Upstream logarithmic channel characteristics per sub-carrier group */
+	dsl_ulong_t hlogmt; /** Number of symbols over which HLOGps were measured in both directions */
+
+	dsl_ulong_sequence_t latnpb_ds; /** Downstream line attenuation per usable band during initialization */
+	dsl_ulong_sequence_t latnpb_us; /** Upstream line attenuation per usable band during initialization */
+
+	dsl_ulong_sequence_t satn_ds; /** Downstream line attenuation per usable band during showtime state */
+	dsl_ulong_sequence_t satn_us; /** Upstream line attenuation per usable band during showtime state */
+
+	dsl_ulong_elements_t hlinps_ds; /** Downstream linear channel characteristics per sub-carrier group */
+	dsl_ulong_elements_t hlinps_us; /** Upstream linear channel characteristics per sub-carrier group */
+
+	dsl_ulong_t qlng; /** Number of sub-carriers per sub-carrier group in both directions */
+	dsl_ulong_elements_t qlnps_ds; /** Downstream quiet line noise per sub-carrier group */
+	dsl_ulong_elements_t qlnps_us; /** Upstream quiet line noise per sub-carrier group */
+
+	dsl_ulong_t qlnmt; /** Number of symbols over which QLNps were measured in both directions */
+
+	dsl_ulong_t snrg; /** Number of sub-carriers per sub-carrier group for SNRps in both directions */
+	dsl_ulong_elements_t snrps_ds; /** Downstream SNR per sub-carrier group */
+	dsl_ulong_elements_t snrps_us; /** Upstream SNR per sub-carrier group */
+
+	dsl_ulong_t snrmt; /** Number of symbols over which SNRps were measured in both directions */
+
+	dsl_ulong_elements_t bitsps_ds; /** Downstream bit allocation per sub-carrier group */
+	dsl_ulong_elements_t bitsps_us; /** Upstream bit allocation per sub-carrier group */
+};
+
+/**
+ *  struct dsl_seltuer - DSL Single Ended Line Test - Physical Medium Dependent (SELT-PMD) Uncalibrated Echo
+ *  Response (UER) diagnostic parameters
+ */
+struct dsl_seltuer {
+	unsigned int uer_max_duration; /** RW SELT UER maximum measurement duration (MMD) in seconds */
+	bool ext_bandwidth_op; /** RO Whether the option of extended bandwidth SELT is applied */
+	dsl_ulong_elements_t uer; /** RO List of UER Complex */
+	unsigned int uer_scale_factor;  /** RO UER scale factor */
+	unsigned int uer_group_size; /** RO UER group size in units of sub-carriers */
+	dsl_ulong_elements_t uer_var; /** RO Variance of UER */
+};
+
+/**
+ *  struct dsl_seltqln - DSL Single Ended Line Test - Physical Medium Dependent (SELT-PMD) Quiet Line
+ *  Noise (QLN) diagnostic parameters
+ */
+struct dsl_seltqln {
+	unsigned int qln_max_measurement_duration;  /** RW SELT QLN max measurement duration in seconds */
+	bool ext_bandwidth_op; /** RO Whether the option of extended bandwidth SELT is applied */
+	dsl_ulong_elements_t qln; /** RO List represents  SELT quiet line noise per sub-carrier group */
+	unsigned int qln_group_size; /** RO QLN group size in units of sub-carriers */
+};
+
+/** enum dsl_loop_termination - DSL loop termination indicator */
+enum dsl_loop_termination {
+	OPEN,
+	SHORT,
+	POWERED_ON,
+	UNKNOWN
+};
+
+/**
+ *  struct dsl_seltp - DSL Single Ended Line Test - Processed diagnostic parameters
+ */
+struct dsl_seltp {
+	bool capacity_estimate_enable; /** RW Whether DSL performance estimation is required */
+	dsl_ulong_elements_t capacity_signal_psd; /** RW Capacity estimate signal Power Spectral Density */
+	dsl_ulong_elements_t capacity_noise_psd; /** RW Capacity estimate noise Power Spectral Density */
+	unsigned int capacity_target_margin; /** RW Capacity estimate target noise margin */
+	enum dsl_loop_termination loop_term; /** RO Loop termination indicator */
+	unsigned int loop_length; /** RO Loop length in units of meters */
+	struct {
+		struct {
+			unsigned int loop_seg_len;
+			unsigned int loop_seg_btap;
+		} pairs[256];
+		int count; /* Number of items in pairs */
+	} loop_topology; /** RO Loop topology */
+	dsl_ulong_elements_t attenuation_characteristics; /** RO TFlog(f) parameter defined in G.996.2 */
+	bool missing_filter; /** RO Missing micro-filter or splitter */
+	unsigned int capacity_estimate; /** RO Capacity estimate in kbit/s */
+};
+
+/** enum fast_profile - FAST profile */
+enum fast_profile {
+	/* Starts with non-zero in order to distinguish from an uninitialized value which is usually 0 */
+	FAST_106a = 1,
+	FAST_212a
+};
+
+/** enum fast_power_state - power states */
+enum fast_power_state {
+	/* Starts with non-zero in order to distinguish from an uninitialized value which is usually 0 */
+	FAST_L0 = 1,
+	FAST_L2_1,
+	FAST_L2_2,
+	FAST_L3
+};
+
+/** struct fast_line - Physical FAST line */
+struct fast_line {
+	/** The current operational state of the FAST line */
+	enum itf_status status;
+	/** Whether the interface points towards the Internet (true) or towards End Devices (false) */
+	bool upstream;
+	/** The version of the modem firmware currently installed for this interface */
+	char firmware_version[64];
+	/** Status of the FAST physical link */
+	enum dsl_link_status link_status;
+	/** FAST profiles are allowed on the line. The bitmap is defined in enum fast_profile */
+	unsigned long allowed_profiles;
+	/** FAST profile is currently in use on the line */
+	enum fast_profile current_profile;
+	/** The power management state of the line */
+	enum fast_power_state power_management_state;
+	/** The success failure cause of the initialization */
+	unsigned int success_failure_cause;
+	/** FTU-R estimated electrical length in the range from 0 to 128 dB in steps of 0.1 dB */
+	unsigned int upbokler;
+	/** The signal count of the last transmitted initialization signal in both directions */
+	dsl_ulong_t last_transmitted_signal;
+	/** FTU-O estimated electrical length in the range from 0 to 128 dB in steps of 0.1 dB */
+	unsigned int upbokle;
+	/** The line pair that the modem is using to connection */
+	int line_number;
+	/** The attainable net data rate in both directions (expressed in Kbps) */
+	dsl_ulong_t max_bit_rate;
+	/** The current signal-to-noise ratio margin (expressed in 0.1dB) in both directions */
+	dsl_long_t noise_margin;
+	/** The current upstream and downstream signal loss (expressed in 0.1dB) */
+	dsl_long_t attenuation;
+	/** The current output and received power at the CPE's FAST line (expressed in 0.1dBmV) */
+	dsl_long_t power;
+	/** The signal-to-noise ratio margin (SNRM, expressed in 0.1dB) for the robust management
+	 *  channel (RMC) in both directions */
+	dsl_long_t snrm_rmc;
+	/** Bit allocation values on RMC sub-carriers in RMC symbols in both directions */
+	dsl_ulong_elements_t bits_rmc_ps;
+	/** Whether FEXT cancellation from all the other vectored lines into the line in the vectored group
+	 *  is enabled in both directions */
+	dsl_bool_t fext_to_cancel_enable;
+	/** Expected Throughput Rate in Kbps in both directions */
+	dsl_ulong_t etr;
+	/** Attainable Expected Throughput Rate in Kbps in both directions */
+	dsl_ulong_t att_etr;
+	/** Minimum Error Free Expected Throughput Rate in Kbps */
+	dsl_ulong_t min_eftr;
+};
+
+/** Keep the backward compatibility in case statistics counters for xDSL and FAST diverge in the future */
+typedef struct dsl_line_channel_stats fast_line_stats;
+
+/** struct fast_line_stats_interval - This is a common structure for all interval statistics for FAST line */
+struct fast_line_stats_interval {
+	/** Number of errored seconds */
+	unsigned int errored_secs;
+	/** Number of severely errored seconds */
+	unsigned int severely_errored_secs;
+	/** Total number of loss of signal seconds */
+	unsigned int loss;
+	/** Total number of loss of RMC seconds */
+	unsigned int lors;
+	/** Total number unavailable seconds */
+	unsigned int uas;
+	/** Count of uncorrected DTU anomalies */
+	unsigned int rtx_uc;
+	/** Count of retransmitted DTU anomalies */
+	unsigned int rtx_tx;
+	/** Count of successful bit swap (BSW) primitives */
+	unsigned int success_bsw;
+	/** Count of successful autonomous SRA (Seamless Rate Adaptation) primitives */
+	unsigned int success_sra;
+	/** Count of successful FRA (Fast Rate Adaptation) primitives */
+	unsigned int success_fra;
+	/** Count of successful RPA (RMC Parameter Adjustment) primitives */
+	unsigned int success_rpa;
+	/** Count of successful (Transmitter Initiated Gain Adjustment) primitives */
+	unsigned int success_tiga;
+};
+
+/** struct fast_line_test_params - FAST line test parameters available during L0 state */
+struct fast_line_test_params {
+	/* Number of sub-carriers in any one sub-carrier group used to represent the SNR(f)
+	 * values in both directions */
+	dsl_ulong_t snrg;
+	dsl_ulong_elements_t snrps_ds; /** Downstream SNR(f) per sub-carrier group */
+	dsl_ulong_elements_t snrps_us; /** Upstream SNR(f) per sub-carrier group */
+	dsl_ulong_t snrmt; /** Number of symbols used to measure SNR(f) in both directions */
+
+	unsigned int act_inp; /** Actual INP against SHINE */
+	unsigned int nfec; /** DTU FEC codeword length (expressed in 1 byte unit) */
+	int rfec; /** DTU FEC codeword redundancy */
+	dsl_ulong_t curr_rate; /** Current physical layer aggregate data rate in Kbps in both directions */
+	unsigned int act_inp_rein; /** Actual INP against REIN */
+};
+
+/** struct dsl_config_params - Configuration parameters of xDSL and FAST */
+struct dsl_config_params {
+	/** xDSL transmission system types to be allowed by the xTU */
+	unsigned char xtse[8];
+	/** VDSL2 profiles are allowed on the line. The bitmap is defined in enum dsl_profile */
+	unsigned long vdsl2_profiles;
+	/** FAST profiles are allowed on the line. The bitmap is defined in enum fast_profile */
+	unsigned long fast_profiles;
+	/** Enable or disable data gathering on the xDSL line */
+	bool enable_data_gathering;
+	/** The enabled VDSL2 Limit PSD mask of the selected PSD mask class */
+	unsigned int limit_mask;
+	/** The allowed VDSL2 US0 PSD masks for Annex A operation */
+	unsigned int us0_mask;
+};
+
 /**
  * This function gets the number of DSL lines
  *
@@ -440,6 +713,26 @@ int dsl_get_line_stats(int line_num, struct dsl_line_channel_stats *stats);
  */
 int dsl_get_line_stats_interval(int line_num, enum dsl_stats_type type, struct dsl_line_stats_interval *stats);
 
+/**
+ * This function gets the test parameters of a DSL line
+ *
+ * @param[in] line_num - The line number which starts with 0
+ * @param[out] test_params The output parameter to receive the data
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int dsl_get_line_test_params(int line_num, struct dsl_line_test_params *test_params);
+
+/**
+ * This function gets the data gathering parameters of a DSL line
+ *
+ * @param[in] line_num - The line number which starts with 0
+ * @param[out] data_gathering The output parameter to receive the data
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int dsl_get_line_data_gathering(int line_num, struct dsl_line_data_gathering *data_gathering);
+
 /**
  * This function gets the DSL channel information
  *
@@ -472,10 +765,150 @@ int dsl_get_channel_stats(int chan_num, struct dsl_line_channel_stats *stats);
 int dsl_get_channel_stats_interval(int chan_num, enum dsl_stats_type type, struct dsl_channel_stats_interval *stats);
 
 /**
- *  struct dsl_ops - This structure defines the DSL operations.
- *  A function pointer shall be NULL if the operation
+ * This function starts or cancels an ADSL line test
+ *
+ * @param[in] line_num - The ADSL line number which starts with 0
+ * @param[in] start - True to start a test. False to cancel an ongoing a test if any.
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int adsl_line_test(int line_num, bool start);
+
+/**
+ * This function gets the results of an ADSL line test
+ *
+ * @param[in] line_num - The ADSL line number which starts with 0
+ * @param[out] results - Output parameter to receive ADSL line test results
+ *
+ * @return The diagnostic state of an ADSL line test
+ */
+enum diag_state adsl_get_line_test_results(int line_num, struct adsl_line_test *results);
+
+/**
+ * This function starts or cancels a diagnostic SELTUER on a DSL line
+ *
+ * @param[in] line_num - The DSL line number which starts with 0
+ * @param[in] seltuer - Diagnostic SELTUER settings. Note that those RO (Read Only) members in
+ *                       struct dsl_seltuer will be ignored
+ * @param[in] start - True to start a test. False to cancel an ongoing a test if any.
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int dsl_seltuer_test(int line_num, const struct dsl_seltuer *seltuer, bool start);
+
+/**
+ * This function gets the results of a diagnostic SELTUER on a DSL line
+ *
+ * @param[in] line_num - The DSL line number which starts with 0
+ * @param[out] seltuer - Output parameter to receive the test results
+ *
+ * @return The diagnostic state of the test
+ */
+enum diag_state dsl_get_seltuer_results(int line_num, struct dsl_seltuer *seltuer);
+
+/**
+ * This function starts or cancels a diagnostic SELTQLN on a DSL line
+ *
+ * @param[in] line_num - The DSL line number which starts with 0
+ * @param[in] seltqln - Diagnostic SELTQLN settings. Note that those RO (Read Only) members in
+ *                       struct dsl_seltqln will be ignored
+ * @param[in] start - True to start a test. False to cancel an ongoing a test if any.
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int dsl_seltqln_test(int line_num, const struct dsl_seltqln *seltqln, bool start);
+
+/**
+ * This function gets the results of a diagnostic SELTQLN on a DSL line
+ *
+ * @param[in] line_num - The DSL line number which starts with 0
+ * @param[out] seltqln - Output parameter to receive the test results
+ *
+ * @return The diagnostic state of the test
+ */
+enum diag_state dsl_get_seltqln_results(int line_num, struct dsl_seltqln *seltqln);
+
+/**
+ * This function starts or cancels a diagnostic SELTP on a DSL line
+ *
+ * @param[in] line_num - The DSL line number which starts with 0
+ * @param[in] seltp - Diagnostic SELTP settings. Note that those RO (Read Only) members in
+ *                       struct dsl_seltp will be ignored
+ * @param[in] start - True to start a test. False to cancel an ongoing a test if any.
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int dsl_seltp_test(int line_num, const struct dsl_seltp *seltp, bool start);
+
+/**
+ * This function gets the results of a diagnostic SELTP on a DSL line
+ *
+ * @param[in] line_num - The DSL line number which starts with 0
+ * @param[out] seltp - Output parameter to receive the test results
+ *
+ * @return The diagnostic state of the test
+ */
+enum diag_state dsl_get_seltp_results(int line_num, struct dsl_seltp *seltp);
+
+/**
+ * This function gets the FAST line information
+ *
+ * @param[in] line_num - The line number which starts with 0
+ * @param[out] line - The output parameter to receive the data
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int fast_get_line_info(int line_num, struct fast_line *line);
+
+/**
+ * This function gets the statistics counters of a FAST line
+ *
+ * @param[in] line_num - The line number which starts with 0
+ * @param[out] stats The output parameter to receive the data
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int fast_get_line_stats(int line_num, struct fast_line_stats *stats);
+
+/**
+ * This function gets the interval statistics counters of a FAST line
+ *
+ * @param[in] line_num - The line number which starts with 0
+ * @param[in] type The type of interval statistics
+ * @param[out] stats The output parameter to receive the data
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int fast_get_line_stats_interval(int line_num, enum dsl_stats_type type, struct fast_line_stats_interval *stats);
+
+/**
+ * This function gets the test parameters of a FAST line
+ *
+ * @param[in] line_num - The line number which starts with 0
+ * @param[out] test_params The output parameter to receive the data
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int fast_get_line_test_params(int line_num, struct fast_line_test_params *test_params);
+
+
+/**
+ * This function configures an xDSL or FAST line
+ *
+ * @param[in] line_num   - The line number which starts with 0
+ * @param[in] cfg_params - The configuration parameters to be applied. Depending upon the capabilities of
+ *                         the platform, not all parameters in cfg_params are applicable
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int dsl_configure(int line_num, struct dsl_config_params *cfg_params);
+
+/**
+ *  struct dsl_ops - This structure defines the DSL and FAST operations.
+ *  A function pointer shall be NULL if the corresponding operation is not supported on a specific platform
  */
 struct dsl_ops {
+	/** Status and statistics of an xDSL line or channel */
 	int (*get_line_info)(int line_num, struct dsl_line *line);
 	int (*get_line_stats)(int line_num, struct dsl_line_channel_stats *stats);
 	int (*get_line_stats_interval)(int line_num, enum dsl_stats_type type,
@@ -484,6 +917,30 @@ struct dsl_ops {
 	int (*get_channel_stats)(int chan_num, struct dsl_line_channel_stats *stats);
 	int (*get_channel_stats_interval)(int chan_num, enum dsl_stats_type type,
 			struct dsl_channel_stats_interval *stats);
+
+	/** Diagnostics and test of an xDSL line or channel */
+	int (*get_line_test_params)(int line_num, struct dsl_line_test_params *test_params);
+	int (*get_line_data_gathering)(int line_num, struct dsl_line_data_gathering *data_gathering);
+	int (*line_test)(int line_num, bool start);
+	enum diag_state (*get_line_test_results)(int line_num, struct adsl_line_test *results);
+	int (*seltuer_test)(int line_num, const struct dsl_seltuer *seltuer, bool start);
+	enum diag_state (*get_seltuer_results)(int line_num, struct dsl_seltuer *seltuer);
+	int (*seltqln_test)(int line_num, const struct dsl_seltqln *seltqln, bool start);
+	enum diag_state (*get_seltqln_results)(int line_num, struct dsl_seltqln *seltqln);
+	int (*seltp_test)(int line_num, const struct dsl_seltp *seltp, bool start);
+	enum diag_state (*get_seltp_results)(int line_num, struct dsl_seltp *seltp);
+
+	/** Status and statistics of a FAST line */
+	int (*get_fast_line_info)(int line_num, struct fast_line *line);
+	int (*get_fast_line_stats)(int line_num, struct fast_line_stats *stats);
+	int (*get_fast_line_stats_interval)(int line_num, enum dsl_stats_type type,
+			struct fast_line_stats_interval *stats);
+
+	/** Diagnostics and test of a FAST line */
+	int (*get_fast_line_test_params)(int line_num, struct fast_line_test_params *test_params);
+
+	/** DSL and/or FAST configuration */
+	int (*configure)(int line_num, struct dsl_config_params *cfg_params);
 };
 
 /** This global variable must be defined for each platform specific implementation */
diff --git a/libdsl/xtm.h b/libdsl/xtm.h
new file mode 100644
index 0000000..bd6af6c
--- /dev/null
+++ b/libdsl/xtm.h
@@ -0,0 +1,243 @@
+/*
+ * xtm.h - library header file
+ * This file provides definition for the libdsl APIs and related
+ * structures.
+ *
+ * Copyright (C) 2020 iopsys Software Solutions AB. All rights reserved.
+ *
+ * Author: yalu.zhang@iopsys.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef _XTM_H_
+#define _XTM_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/** enum atm_link_type - The type of the connection and the complete stack of protocol used for this connection */
+enum atm_link_type {
+	ATM_LINK_UNCONFIGURED = 0,
+	ATM_LINK_EoA,   /** Bridged Ethernet over ATM */
+	ATM_LINK_IPoA,  /** Routed IP over ATM */
+	ATM_LINK_PPPoA, /** PPP over ATM */
+	ATM_LINK_CIP    /** Classical IP over ATM */
+};
+
+/** struct atm_dest_addr - Destination address of this link, i.e. a pair of VPI and VCI */
+struct atm_dest_addr {
+	unsigned int vpi;
+	unsigned int vci;
+};
+
+/** enum atm_encapsulation - ATM connection encapsulation */
+enum atm_encapsulation {
+	ATM_LLC = 1, /** Multiple protocols are transmitted over the same ATM VC (Virtual Connection) */
+	ATM_VCMUX    /** Each protocol is transmitted over a separate ATM VC */
+};
+
+/** enum atm_aal - AAL (ATM Adaptation Layer) currently used on the PVC */
+enum atm_aal {
+	ATM_AAL1 = 1,
+	ATM_AAL2,
+	ATM_AAL3,
+	ATM_AAL4,
+	ATM_AAL5
+};
+
+/** struct atm_link - ATM link configuration and status */
+struct atm_link {
+	/** RO The current operational status of the link */
+	enum itf_status status;
+	/** RW Link type */
+	enum atm_link_type link_type;
+	/** RO Indicates that some auto configuration mechanism is used for this connection currently */
+	bool auto_config;
+	/** RW Destination address */
+	struct atm_dest_addr dest_addr;
+	/** RW Encapsulation */
+	enum atm_encapsulation encapsulation;
+	/** RW Whether checksum should be added in the ATM payload. It only applies to the upstream direction */
+	bool fcs_preserved;
+
+	/** RW Search list of destination addresses if the configured VPI/VCI pair cannot be established */
+	struct atm_dest_addr *vc_search_list;
+	unsigned int vc_list_count;
+
+	/** RO Current ALL in use */
+	enum atm_aal aal;
+};
+
+/**
+ * struct atm_link_stats - Statistics of an ATM link
+ * Note that only ATM specific statistics counters are defined since generic statistics are define
+ * in an IP interface
+ */
+struct atm_link_stats {
+	/** Successfully transmitted cells */
+	unsigned int transmitted_blocks;
+	/** Successfully received cells */
+	unsigned int received_blocks;
+	/** Count of ATM layer CRC errors */
+	unsigned int crc_errors;
+};
+
+/** enum atm_qos_class - ATM QoS used on the VC */
+enum atm_qos_class {
+	ATM_QoS_UBR = 1,
+	ATM_QoS_CBR,
+	ATM_QoS_GFR,
+	ATM_QoS_VBR_nrt,
+	ATM_QoS_VBR_rt,
+	ATM_QoS_UBR_PLUS,
+	ATM_QoS_ABR
+};
+
+/** struct atm_link_qos - ATM link QoS configuration */
+struct atm_link_qos {
+	/** QoS class */
+	enum atm_qos_class qos_class;
+	/** Specifies the upstream peak cell rate in cells per second */
+	unsigned int peak_cell_rate;
+	/** Specifies the upstream maximum burst size in cells */
+	unsigned int max_burst_size;
+	/** Specifies the upstream sustainable cell rate in cells per second */
+	unsigned int sustainable_cell_rate;
+};
+
+/** struct atm_diag_loopback - ATM layer F5 OAM loopback test */
+struct atm_diag_loopback {
+	/** RW Number of repetitions of the ping test to perform before reporting the results */
+	unsigned int num_repetition;
+	/** RW Timeout in milliseconds for the ping test */
+	unsigned int timeout;
+	/** RO Number of successful ping tests */
+	unsigned int success_count;
+	/** RO Number of failed ping tests */
+	unsigned int failure_count;
+	/** RO Average response time in milliseconds of those successful ping tests */
+	unsigned int avg_resp_time;
+	/** RO Minimum response time in milliseconds of those successful ping tests */
+	unsigned int min_resp_time;
+	/** RO Maximum response time in milliseconds of those successful ping tests */
+	unsigned int max_resp_time;
+};
+
+/** struct ptm_link - PTM link status */
+struct ptm_link {
+	/** The current operational status of the link */
+	enum itf_status status;
+	/** MAC address which is not necessarily the same as the Ethernet source of destination address */
+	unsigned char mac_addr[6];
+};
+
+/**
+ *  NOTE
+ *
+ *  There are NO PTM specific statistics since they are the same as a common IP interface's.
+ */
+
+/**
+ * This function configures an ATM link
+ *
+ * @param[in] link_num - The ATM link number which starts with 0
+ * @param[in] qos - QoS settings
+ * @param[in] cfg - The configuration parameters of the ATM link. Note that those RO (Read Only) members in
+ *                  struct atm_link will be ignored
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int atm_configure(int link_num, const struct atm_link *cfg, const struct atm_link_qos *qos);
+
+/**
+ * This function gets the ATM link's information
+ *
+ * @param[in] link_num - The ATM link number which starts with 0
+ * @param[out] link - The output parameter to receive the ATM link's configuration and status
+ * @param[out] qos - The output parameter to receive the ATM QoS settings
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int atm_get_link_info(int link_num, struct atm_link *link, struct atm_link_qos *qos);
+
+/**
+ * This function gets the statistics of an ATM link
+ *
+ * @param[in] link_num - The ATM link number which starts with 0
+ * @param[out] stats The output parameter to receive the data
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int atm_get_link_stats(int link_num, struct atm_link_stats *stats);
+
+/**
+ * This function starts or cancels a loopback test on an ATM link
+ *
+ * @param[in] link_num - The ATM link number which starts with 0
+ * @param[in] loopback - Loopback test settings. Note that those RO (Read Only) members in
+ *                       struct atm_diag_loopback will be ignored
+ * @param[in] start - True to start a test. False to cancel an ongoing a test if any.
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int atm_loopback_test(int link_num, const struct atm_diag_loopback *loopback, bool start);
+
+/**
+ * This function gets the results of a loopback test on an ATM link
+ *
+ * @param[in] link_num - The ATM link number which starts with 0
+ * @param[out] loopback - Output parameter to receive loopback test results
+ *
+ * @return The diagnostic state of a loopback test
+ */
+enum diag_state atm_get_loopback_results(int link_num, struct atm_diag_loopback *loopback);
+
+/**
+ * This function gets the PTM link's information
+ *
+ * @param[in] link_num - The PTM link number which starts with 0
+ * @param[out] link - The output parameter to receive the PTM link's info
+ *
+ * @return 0 on success. Otherwise a negative value is returned
+ */
+int ptm_get_link_info(int link_num, struct ptm_link *link);
+
+/**
+ *  struct xtm_ops - This structure defines the ATM operations.
+ *  A function pointer shall be NULL if the corresponding operation is not supported on a specific platform
+ */
+struct atm_ops {
+	int (*configure)(int link_num, const struct atm_link *cfg, const struct atm_link_qos *qos);
+	int (*get_link_info)(int link_num, struct atm_link *link, struct atm_link_qos *qos);
+	int (*get_link_stats)(int link_num, struct atm_link_stats *stats);
+	int (*loopback_test)(int link_num, const struct atm_diag_loopback *loopback, bool start);
+	enum diag_state (*get_loopback_results)(int link_num, struct atm_diag_loopback *loopback);
+};
+/**
+ *  struct xtm_ops - This structure defines the PTM operations.
+ *  A function pointer shall be NULL if the corresponding operation is not supported on a specific platform
+ */
+struct ptm_ops {
+	int (*get_link_info)(int link_num, struct ptm_link *link);
+};
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _XTM_H_ */
-- 
GitLab