root/src/ftmod/ftmod_wanpipe/wanpipe_tdm_api_iface.h

/* [<][>][^][v][top][bottom][index][help] */
   1 /*****************************************************************************
   2 * wanpipe_tdm_api_iface.h 
   3 *               
   4 *               WANPIPE(tm) AFT TE1 Hardware Support
   5 *
   6 * Authors:      Nenad Corbic <ncorbic@sangoma.com>
   7 *
   8 * Copyright (c) 2007 - 08, Sangoma Technologies
   9 * All rights reserved.
  10 *
  11 * Redistribution and use in source and binary forms, with or without
  12 * modification, are permitted provided that the following conditions are met:
  13 *     * Redistributions of source code must retain the above copyright
  14 *       notice, this list of conditions and the following disclaimer.
  15 *     * Redistributions in binary form must reproduce the above copyright
  16 *       notice, this list of conditions and the following disclaimer in the
  17 *       documentation and/or other materials provided with the distribution.
  18 *     * Neither the name of the <organization> nor the
  19 *       names of its contributors may be used to endorse or promote products
  20 *       derived from this software without specific prior written permission.
  21 *
  22 * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
  23 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32 
  33 * ============================================================================
  34 * Oct 04, 2005  Nenad Corbic    Initial version.
  35 *
  36 * Jul 25, 2006  David Rokhvarg  <davidr@sangoma.com>    Ported to Windows.
  37 *****************************************************************************/
  38 
  39 #ifndef __WANPIPE_TDM_API_IFACE_H_
  40 #define __WANPIPE_TDM_API_IFACE_H_ 
  41 
  42 
  43 #if defined(__WINDOWS__)
  44 typedef HANDLE sng_fd_t;
  45 #else
  46 typedef int sng_fd_t;
  47 #endif
  48 
  49 /* Indicate to library that new features exist */
  50 #define WP_TDM_FEATURE_DTMF_EVENTS      1
  51 #define WP_TDM_FEATURE_FE_ALARM         1
  52 #define WP_TDM_FEATURE_EVENTS           1
  53 #define WP_TDM_FEATURE_LINK_STATUS      1
  54 
  55 enum wanpipe_tdm_api_cmds {
  56 
  57         SIOC_WP_TDM_GET_USR_MTU_MRU,    /* 0x00 */
  58 
  59         SIOC_WP_TDM_SET_USR_PERIOD,     /* 0x01 */
  60         SIOC_WP_TDM_GET_USR_PERIOD,     /* 0x02 */
  61         
  62         SIOC_WP_TDM_SET_HW_MTU_MRU,     /* 0x03 */
  63         SIOC_WP_TDM_GET_HW_MTU_MRU,     /* 0x04 */
  64 
  65         SIOC_WP_TDM_SET_CODEC,          /* 0x05 */
  66         SIOC_WP_TDM_GET_CODEC,          /* 0x06 */
  67 
  68         SIOC_WP_TDM_SET_POWER_LEVEL,    /* 0x07 */
  69         SIOC_WP_TDM_GET_POWER_LEVEL,    /* 0x08 */
  70 
  71         SIOC_WP_TDM_TOGGLE_RX,          /* 0x09 */
  72         SIOC_WP_TDM_TOGGLE_TX,          /* 0x0A */
  73 
  74         SIOC_WP_TDM_GET_HW_CODING,      /* 0x0B */
  75         SIOC_WP_TDM_SET_HW_CODING,      /* 0x0C */
  76 
  77         SIOC_WP_TDM_GET_FULL_CFG,       /* 0x0D */
  78 
  79         SIOC_WP_TDM_SET_EC_TAP,         /* 0x0E */
  80         SIOC_WP_TDM_GET_EC_TAP,         /* 0x0F */
  81         
  82         SIOC_WP_TDM_ENABLE_RBS_EVENTS,  /* 0x10 */
  83         SIOC_WP_TDM_DISABLE_RBS_EVENTS, /* 0x11 */
  84         SIOC_WP_TDM_WRITE_RBS_BITS,     /* 0x12 */
  85         
  86         SIOC_WP_TDM_GET_STATS,          /* 0x13 */
  87         SIOC_WP_TDM_FLUSH_BUFFERS,      /* 0x14 */
  88         
  89         SIOC_WP_TDM_READ_EVENT,         /* 0x15 */
  90         
  91         SIOC_WP_TDM_SET_EVENT,          /* 0x16 */
  92 
  93         SIOC_WP_TDM_SET_RX_GAINS,       /* 0x17 */
  94         SIOC_WP_TDM_SET_TX_GAINS,       /* 0x18 */
  95         SIOC_WP_TDM_CLEAR_RX_GAINS,     /* 0x19 */
  96         SIOC_WP_TDM_CLEAR_TX_GAINS,     /* 0x1A */
  97 
  98         SIOC_WP_TDM_GET_FE_ALARMS,      /* 0x1B */
  99 
 100         SIOC_WP_TDM_ENABLE_HWEC,        /* 0x1C */
 101         SIOC_WP_TDM_DISABLE_HWEC,       /* 0x1D */
 102         
 103         SIOC_WP_TDM_SET_FE_STATUS,      /* 0x1E */
 104         SIOC_WP_TDM_GET_FE_STATUS,      /* 0x1F */
 105 
 106         SIOC_WP_TDM_GET_HW_DTMF,        /* 0x20 */
 107 
 108         SIOC_WP_TDM_NOTSUPP             /*  */
 109 
 110 };
 111 
 112 #define SIOC_WP_TDM_GET_LINK_STATUS SIOC_WP_TDM_GET_FE_STATUS
 113 
 114 enum wanpipe_tdm_api_events {
 115         WP_TDMAPI_EVENT_NONE,
 116         WP_TDMAPI_EVENT_RBS,
 117         WP_TDMAPI_EVENT_ALARM,
 118         WP_TDMAPI_EVENT_DTMF,
 119         WP_TDMAPI_EVENT_RM_DTMF,
 120         WP_TDMAPI_EVENT_RXHOOK,
 121         WP_TDMAPI_EVENT_RING,
 122         WP_TDMAPI_EVENT_RING_DETECT,
 123         WP_TDMAPI_EVENT_RING_TRIP_DETECT,
 124         WP_TDMAPI_EVENT_TONE,
 125         WP_TDMAPI_EVENT_TXSIG_KEWL,
 126         WP_TDMAPI_EVENT_TXSIG_START,
 127         WP_TDMAPI_EVENT_TXSIG_OFFHOOK,
 128         WP_TDMAPI_EVENT_TXSIG_ONHOOK,
 129         WP_TDMAPI_EVENT_ONHOOKTRANSFER,
 130         WP_TDMAPI_EVENT_SETPOLARITY,
 131         WP_TDMAPI_EVENT_BRI_CHAN_LOOPBACK,
 132         WP_TDMAPI_EVENT_LINK_STATUS
 133 };
 134 
 135 #define WP_TDMAPI_EVENT_FE_ALARM WP_TDMAPI_EVENT_ALARM
 136 
 137 
 138 #define WP_TDMAPI_EVENT_ENABLE          0x01
 139 #define WP_TDMAPI_EVENT_DISABLE         0x02
 140 #define WP_TDMAPI_EVENT_MODE_DECODE(mode)                               \
 141                 ((mode) == WP_TDMAPI_EVENT_ENABLE) ? "Enable" : \
 142                 ((mode) == WP_TDMAPI_EVENT_DISABLE) ? "Disable" :       \
 143                                                 "(Unknown mode)"
 144 
 145 #define WPTDM_A_BIT                     WAN_RBS_SIG_A
 146 #define WPTDM_B_BIT                     WAN_RBS_SIG_B
 147 #define WPTDM_C_BIT                     WAN_RBS_SIG_C
 148 #define WPTDM_D_BIT                     WAN_RBS_SIG_D
 149  
 150 #define WP_TDMAPI_EVENT_RXHOOK_OFF      0x01
 151 #define WP_TDMAPI_EVENT_RXHOOK_ON       0x02
 152 #define WP_TDMAPI_EVENT_RXHOOK_DECODE(state)                            \
 153                 ((state) == WP_TDMAPI_EVENT_RXHOOK_OFF) ? "Off-hook" :  \
 154                 ((state) == WP_TDMAPI_EVENT_RXHOOK_ON) ? "On-hook" :    \
 155                                                 "(Unknown state)"
 156 
 157 #define WP_TDMAPI_EVENT_RING_PRESENT    0x01
 158 #define WP_TDMAPI_EVENT_RING_STOP       0x02
 159 #define WP_TDMAPI_EVENT_RING_DECODE(state)                              \
 160                 ((state) == WP_TDMAPI_EVENT_RING_PRESENT) ? "Ring Present" :    \
 161                 ((state) == WP_TDMAPI_EVENT_RING_STOP) ? "Ring Stop" :  \
 162                                                 "(Unknown state)"
 163 
 164 #define WP_TDMAPI_EVENT_RING_TRIP_PRESENT       0x01
 165 #define WP_TDMAPI_EVENT_RING_TRIP_STOP  0x02
 166 #define WP_TDMAPI_EVENT_RING_TRIP_DECODE(state)                         \
 167                 ((state) == WP_TDMAPI_EVENT_RING_TRIP_PRESENT) ? "Ring Present" :       \
 168                 ((state) == WP_TDMAPI_EVENT_RING_TRIP_STOP) ? "Ring Stop" :     \
 169                                                 "(Unknown state)"
 170 /*Link Status */
 171 #define WP_TDMAPI_EVENT_LINK_STATUS_CONNECTED           0x01
 172 #define WP_TDMAPI_EVENT_LINK_STATUS_DISCONNECTED        0x02
 173 #define WP_TDMAPI_EVENT_LINK_STATUS_DECODE(status)                                      \
 174                 ((status) == WP_TDMAPI_EVENT_LINK_STATUS_CONNECTED) ? "Connected" :             \
 175                 ((status) == WP_TDMAPI_EVENT_LINK_STATUS_DISCONNECTED)  ? "Disconnected" :              \
 176                                                         "Unknown"
 177 #define WP_TDMAPI_EVENT_TONE_DIAL       0x01
 178 #define WP_TDMAPI_EVENT_TONE_BUSY       0x02
 179 #define WP_TDMAPI_EVENT_TONE_RING       0x03
 180 #define WP_TDMAPI_EVENT_TONE_CONGESTION 0x04
 181 
 182 /* BRI channels list */                                         
 183 #define WAN_BRI_BCHAN1          0x01
 184 #define WAN_BRI_BCHAN2          0x02
 185 #define WAN_BRI_DCHAN           0x03
 186 
 187 
 188 typedef struct {
 189 
 190         u_int8_t        type;
 191         u_int8_t        mode;
 192         u_int32_t       time_stamp;
 193         u_int8_t        channel;
 194         u_int32_t       chan_map;
 195         u_int8_t        span;
 196         union {
 197                 struct {
 198                         u_int8_t        alarm;
 199                 } te1_alarm;
 200                 struct {
 201                         u_int8_t        rbs_bits;
 202                 } te1_rbs;
 203                 struct {
 204                         u_int8_t        state;
 205                         u_int8_t        sig;
 206                 } rm_hook;
 207                 struct {
 208                         u_int8_t        state;
 209                 } rm_ring;
 210                 struct {
 211                         u_int8_t        type;
 212                 } rm_tone;
 213                 struct {
 214                         u_int8_t        digit;  /* DTMF: digit  */
 215                         u_int8_t        port;   /* DTMF: SOUT/ROUT */
 216                         u_int8_t        type;   /* DTMF: PRESET/STOP */
 217                 } dtmf;
 218                 struct {
 219                         u_int16_t       polarity;
 220                         u_int16_t       ohttimer;
 221                 } rm_common;
 222                 struct{
 223                         u_int16_t status;
 224                 } linkstatus;
 225         } wp_tdm_api_event_u;
 226 #define wp_tdm_api_event_type           type
 227 #define wp_tdm_api_event_mode           mode
 228 #define wp_tdm_api_event_alarm          wp_tdm_api_event_u.te1_alarm.alarm
 229 #define wp_tdm_api_event_alarm          wp_tdm_api_event_u.te1_alarm.alarm
 230 #define wp_tdm_api_event_rbs_bits       wp_tdm_api_event_u.te1_rbs.rbs_bits
 231 #define wp_tdm_api_event_hook_state     wp_tdm_api_event_u.rm_hook.state
 232 #define wp_tdm_api_event_hook_sig       wp_tdm_api_event_u.rm_hook.sig
 233 #define wp_tdm_api_event_ring_state     wp_tdm_api_event_u.rm_ring.state
 234 #define wp_tdm_api_event_tone_type      wp_tdm_api_event_u.rm_tone.type
 235 #define wp_tdm_api_event_dtmf_digit     wp_tdm_api_event_u.dtmf.digit
 236 #define wp_tdm_api_event_dtmf_type      wp_tdm_api_event_u.dtmf.type
 237 #define wp_tdm_api_event_dtmf_port      wp_tdm_api_event_u.dtmf.port
 238 #define wp_tdm_api_event_ohttimer       wp_tdm_api_event_u.rm_common.ohttimer
 239 #define wp_tdm_api_event_polarity       wp_tdm_api_event_u.rm_common.polarity
 240 #define wp_tdm_api_event_link_status    wp_tdm_api_event_u.linkstatus.status
 241 } wp_tdm_api_event_t;
 242 
 243 typedef struct {
 244         union {
 245                 unsigned char   reserved[16];
 246         }wp_rx_hdr_u;
 247 } wp_tdm_api_rx_hdr_t;
 248 
 249 typedef struct {
 250         wp_tdm_api_rx_hdr_t     hdr;
 251         unsigned char           data[1];
 252 } wp_tdm_api_rx_element_t;
 253 
 254 typedef struct {
 255         union {
 256                 struct {
 257                         unsigned char   _rbs_rx_bits;
 258                         unsigned int    _time_stamp;
 259                 }wp_tx;
 260                 unsigned char   reserved[16];
 261         }wp_tx_hdr_u;
 262 #define wp_api_time_stamp       wp_tx_hdr_u.wp_tx._time_stamp
 263 } wp_tdm_api_tx_hdr_t;
 264 
 265 typedef struct {
 266         wp_tdm_api_tx_hdr_t     hdr;
 267         unsigned char           data[1];
 268 } wp_tdm_api_tx_element_t;
 269 
 270 
 271 
 272 typedef struct wp_tdm_chan_stats
 273 {
 274         unsigned int    rx_packets;             /* total packets received       */
 275         unsigned int    tx_packets;             /* total packets transmitted    */
 276         unsigned int    rx_bytes;               /* total bytes received         */
 277         unsigned int    tx_bytes;               /* total bytes transmitted      */
 278         unsigned int    rx_errors;              /* bad packets received         */
 279         unsigned int    tx_errors;              /* packet transmit problems     */
 280         unsigned int    rx_dropped;             /* no space in linux buffers    */
 281         unsigned int    tx_dropped;             /* no space available in linux  */
 282         unsigned int    multicast;              /* multicast packets received   */
 283 #if !defined(__WINDOWS__)
 284         unsigned int    collisions;
 285 #endif
 286         /* detailed rx_errors: */
 287         unsigned int    rx_length_errors;
 288         unsigned int    rx_over_errors;         /* receiver ring buff overflow  */
 289         unsigned int    rx_crc_errors;          /* recved pkt with crc error    */
 290         unsigned int    rx_frame_errors;        /* recv'd frame alignment error */
 291 #if !defined(__WINDOWS__)
 292         unsigned int    rx_fifo_errors;         /* recv'r fifo overrun          */
 293 #endif
 294         unsigned int    rx_missed_errors;       /* receiver missed packet       */
 295 
 296         /* detailed tx_errors */
 297 #if !defined(__WINDOWS__)
 298         unsigned int    tx_aborted_errors;
 299         unsigned int    tx_carrier_errors;
 300 #endif
 301         unsigned int    tx_fifo_errors;
 302         unsigned int    tx_heartbeat_errors;
 303         unsigned int    tx_window_errors;
 304         
 305 }wp_tdm_chan_stats_t;          
 306 
 307 
 308  
 309 typedef struct wanpipe_tdm_api_cmd{
 310         unsigned int cmd;
 311         unsigned int hw_tdm_coding;     /* Set/Get HW TDM coding: uLaw muLaw */
 312         unsigned int hw_mtu_mru;        /* Set/Get HW TDM MTU/MRU */
 313         unsigned int usr_period;        /* Set/Get User Period in ms */
 314         unsigned int tdm_codec;         /* Set/Get TDM Codec: SLinear */
 315         unsigned int power_level;       /* Set/Get Power level treshold */
 316         unsigned int rx_disable;        /* Enable/Disable Rx */
 317         unsigned int tx_disable;        /* Enable/Disable Tx */         
 318         unsigned int usr_mtu_mru;       /* Set/Get User TDM MTU/MRU */
 319         unsigned int ec_tap;            /* Echo Cancellation Tap */
 320         unsigned int rbs_poll;          /* Enable/Disable RBS Polling */
 321         unsigned int rbs_rx_bits;       /* Rx RBS Bits */
 322         unsigned int rbs_tx_bits;       /* Tx RBS Bits */
 323         unsigned int hdlc;                      /* HDLC based device */
 324         unsigned int idle_flag;         /* IDLE flag to Tx */
 325         unsigned int fe_alarms;         /* FE Alarms detected */
 326         wp_tdm_chan_stats_t stats;      /* TDM Statistics */
 327         /* Do NOT add anything above this! Important for binary backward compatibility. */
 328         wp_tdm_api_event_t event;       /* TDM Event */
 329         unsigned int data_len;
 330         void *data;     
 331         unsigned char fe_status;        /* FE status - Connected or Disconnected */
 332         unsigned int hw_dtmf;           /* HW DTMF enabled */
 333 }wanpipe_tdm_api_cmd_t;
 334 
 335 typedef struct wanpipe_tdm_api_event{
 336         int (*wp_rbs_event)(sng_fd_t fd, unsigned char rbs_bits);
 337         int (*wp_dtmf_event)(sng_fd_t fd, unsigned char dtmf, unsigned char type, unsigned char port);
 338         int (*wp_rxhook_event)(sng_fd_t fd, unsigned char hook_state);
 339         int (*wp_ring_detect_event)(sng_fd_t fd, unsigned char ring_state);
 340         int (*wp_ring_trip_detect_event)(sng_fd_t fd, unsigned char ring_state);
 341         int (*wp_fe_alarm_event)(sng_fd_t fd, unsigned char fe_alarm_event);
 342         int (*wp_link_status_event)(sng_fd_t fd, unsigned char link_status_event);
 343 }wanpipe_tdm_api_event_t; 
 344 
 345 typedef struct wanpipe_tdm_api{
 346         wanpipe_tdm_api_cmd_t   wp_tdm_cmd;
 347         wanpipe_tdm_api_event_t wp_tdm_event;
 348 }wanpipe_tdm_api_t;
 349 
 350 
 351 #endif

/* [<][>][^][v][top][bottom][index][help] */