root/src/ftmod/ftmod_zt/ftmod_zt.h

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

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2007, Anthony Minessale II
   3  * All rights reserved.
   4  * 
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 
   9  * * Redistributions of source code must retain the above copyright
  10  * notice, this list of conditions and the following disclaimer.
  11  * 
  12  * * Redistributions in binary form must reproduce the above copyright
  13  * notice, this list of conditions and the following disclaimer in the
  14  * documentation and/or other materials provided with the distribution.
  15  * 
  16  * * Neither the name of the original author; nor the names of any contributors
  17  * may be used to endorse or promote products derived from this software
  18  * without specific prior written permission.
  19  * 
  20  * 
  21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  * 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 #ifndef FTDM_ZT_H
  35 #define FTDM_ZT_H
  36 #include "freetdm.h"
  37 #include <sys/ioctl.h>
  38 #include <poll.h>
  39 
  40 #ifdef __sun
  41 #include <unistd.h>
  42 #include <sys/ioccom.h>
  43 #include <stropts.h>
  44 #endif
  45 
  46 /* Hardware interface structures and defines */
  47 /* Based on documentation of the structures required for the hardware interface */
  48 /* from http://wiki.freeswitch.org/wiki/Zapata_ftdmtel_interface */
  49 
  50 /* Structures */
  51 
  52 /* Used with ioctl: ZT_GET_PARAMS and ZT_SET_PARAMS */
  53 struct zt_params {
  54         int chan_no;                    /* Channel Number                                                       */
  55         int span_no;                    /* Span Number                                                          */
  56         int chan_position;              /* Channel Position                                                     */
  57         int sig_type;                   /* Signal Type (read-only)                                      */
  58         int sig_cap;                    /* Signal Cap (read-only)                                       */
  59         int receive_offhook;    /* Receive is offhook (read-only)                       */
  60         int receive_bits;               /* Number of bits in receive (read-only)        */
  61         int transmit_bits;              /* Number of bits in transmit (read-only)       */
  62         int transmit_hook_sig;  /* Transmit Hook Signal (read-only)                     */
  63         int receive_hook_sig;   /* Receive Hook Signal (read-only)                      */
  64         int g711_type;                  /* Member of zt_g711_t (read-only)                      */
  65         int idlebits;                   /* bits for the idle state (read-only)          */
  66         char chan_name[40];             /* Channel Name                                                         */
  67         int prewink_time;
  68         int preflash_time;
  69         int wink_time;
  70         int flash_time;
  71         int start_time;
  72         int receive_wink_time;
  73         int receive_flash_time;
  74         int debounce_time;
  75         int pulse_break_time;
  76         int pulse_make_time;
  77         int pulse_after_time;
  78     /* latest version of this struct include chan_alarms field */
  79     uint32_t chan_alarms;
  80 };
  81 
  82 typedef struct zt_params zt_params_t;
  83 
  84 /* Used with ioctl: ZT_CONFLINK, ZT_GETCONF and ZT_SETCONF */
  85 struct zt_confinfo {
  86         int chan_no;                    /* Channel Number, 0 for current */
  87         int conference_number;
  88         int conference_mode;
  89 };
  90 
  91 /* Used with ioctl: ZT_GETGAINS and ZT_SETGAINS */
  92 struct zt_gains {
  93         int chan_no;                                            /* Channel Number, 0 for current        */
  94         unsigned char receive_gain[256];        /* Receive gain table                           */
  95         unsigned char transmit_gain[256];       /* Transmit gain table                          */
  96 };
  97 
  98 /* Used with ioctl: ZT_SPANSTAT */
  99 struct zt_spaninfo {
 100         int span_no;                                            /* span number (-1 to use name)                         */
 101         char name[20];                                          /* Name of span                                                         */
 102         char description[40];                           /* Description of span                                          */
 103         int alarms;                                                     /* alarms status                                                        */
 104         int transmit_level;                                     /* Transmit level                                                       */
 105         int receive_level;                                      /* Receive level                                                        */
 106         int bpv_count;                                          /* Current BPV count                                            */
 107         int crc4_count;                                         /* Current CRC4 error count                                     */
 108         int ebit_count;                                         /* Current E-bit error count                            */
 109         int fas_count;                                          /* Current FAS error count                                      */
 110         int irq_misses;                                         /* Current IRQ misses                                           */
 111         int sync_src;                                           /* Span # of sync source (0 = free run)         */
 112         int configured_chan_count;                      /* Count of channels configured on the span     */
 113         int channel_count;                                      /* Total count of channels on the span          */
 114         int span_count;                                         /* Total count of ftdmtel spans on the system*/
 115     /* end v1 of the struct */
 116     /* as long as we don't use the fields below we should be ok regardless of the ftdmtel/dahdi version */
 117     int lbo;                            /* Line Build Out */
 118     int lineconfig;                     /* framing/coding */
 119     /* end of v2 of the struct */
 120     char lboname[40];                   /* Line Build Out in text form */
 121     char location[40];                  /* span's device location in system */
 122     char manufacturer[40];              /* manufacturer of span's device */
 123     char devicetype[40];                /* span's device type */
 124     int irq;                            /* span's device IRQ */
 125     int linecompat;                     /* signaling modes possible on this span */
 126     char spantype[6];                   /* type of span in text form */
 127 };
 128 
 129 struct zt_maintinfo {
 130         int span_no;                                            /* span number                                                                                  */
 131         int command;                                            /* Maintenance mode to set (from zt_maintenance_mode_t) */
 132 };
 133 
 134 struct zt_lineconfig {
 135 /* Used in ZT_SPANCONFIG */
 136         int span;                                                       /* Which span number (0 to use name)            */
 137         char name[20];                                          /* Name of span to use                                          */
 138         int lbo;                                                        /* line build-outs                                                      */
 139         int lineconfig;                                         /* line config parameters (framing, coding) */
 140         int sync;                                                       /* what level of sync source we are                     */
 141 };
 142 
 143 struct zt_chanconfig {
 144 /* Used in ZT_CHANCONFIG */
 145         int chan;                                                       /* Channel we're applying this to (0 to use name)                                                                               */
 146         char name[40];                                          /* Name of channel to use                                                                                                                               */
 147         int sigtype;                                            /* Signal type                                                                                                                                                  */
 148         int deflaw;                                                     /* Default law (ZT_LAW_DEFAULT, ZT_LAW_MULAW, or ZT_LAW_ALAW                                                    */
 149         int master;                                                     /* Master channel if sigtype is ZT_SLAVE                                                                                                */
 150         int idlebits;                                           /* Idle bits (if this is a CAS channel) or channel to monitor (if this is DACS channel) */
 151         char netdev_name[16];                           /* name for the hdlc network device                                                                                                             */
 152 };
 153 
 154 struct zt_bufferinfo {
 155 /* used in ZT_SET_BUFINFO and ZT_GET_BUFINFO */
 156         int txbufpolicy;                                        /* Policy for handling receive buffers                  */
 157         int rxbufpolicy;                                        /* Policy for handling receive buffers                  */
 158         int numbufs;                                            /* How many buffers to use                                              */
 159         int bufsize;                                            /* How big each buffer is                                               */
 160         int readbufs;                                           /* How many read buffers are full (read-only)   */
 161         int writebufs;                                          /* How many write buffers are full (read-only)  */
 162 };
 163 
 164 /* Enumerations */
 165 
 166 /* Values in zt_params structure for member g711_type */
 167 typedef enum {
 168         ZT_G711_DEFAULT         = 0,    /* Default mulaw/alaw from the span */
 169         ZT_G711_MULAW           = 1,
 170         ZT_G711_ALAW            = 2
 171 } zt_g711_t;
 172 
 173 typedef enum {
 174         ZT_EVENT_NONE                   = 0,
 175         ZT_EVENT_ONHOOK                 = 1,
 176         ZT_EVENT_RINGOFFHOOK    = 2,
 177         ZT_EVENT_WINKFLASH              = 3,
 178         ZT_EVENT_ALARM                  = 4,
 179         ZT_EVENT_NOALARM                = 5,
 180         ZT_EVENT_ABORT                  = 6,
 181         ZT_EVENT_OVERRUN                = 7,
 182         ZT_EVENT_BADFCS                 = 8,
 183         ZT_EVENT_DIALCOMPLETE   = 9, 
 184         ZT_EVENT_RINGERON               = 10,
 185         ZT_EVENT_RINGEROFF              = 11,
 186         ZT_EVENT_HOOKCOMPLETE   = 12,
 187         ZT_EVENT_BITSCHANGED    = 13,
 188         ZT_EVENT_PULSE_START    = 14,
 189         ZT_EVENT_TIMER_EXPIRED  = 15,
 190         ZT_EVENT_TIMER_PING             = 16,
 191         ZT_EVENT_POLARITY               = 17,
 192         ZT_EVENT_RINGBEGIN              = 18
 193 } zt_event_t;
 194 
 195 typedef enum {
 196         ZT_FLUSH_READ                   = 1,
 197         ZT_FLUSH_WRITE                  = 2,
 198         ZT_FLUSH_BOTH                   = (ZT_FLUSH_READ | ZT_FLUSH_WRITE),
 199         ZT_FLUSH_EVENT                  = 4,
 200         ZT_FLUSH_ALL                    = (ZT_FLUSH_READ | ZT_FLUSH_WRITE | ZT_FLUSH_EVENT)
 201 } zt_flush_t;
 202 
 203 typedef enum {
 204         ZT_IOMUX_READ                   = 1,
 205         ZT_IOMUX_WRITE                  = 2,
 206         ZT_IOMUX_WRITEEMPTY             = 4,
 207         ZT_IOMUX_SIGEVENT               = 8,
 208         ZT_IOMUX_NOWAIT                 = 256
 209 } zt_iomux_t;
 210 
 211 typedef enum {
 212         ZT_ONHOOK                               = 0,
 213         ZT_OFFHOOK                              = 1,
 214         ZT_WINK                                 = 2,
 215         ZT_FLASH                                = 3,
 216         ZT_START                                = 4,
 217         ZT_RING                                 = 5,
 218         ZT_RINGOFF                              = 6
 219 } zt_hookstate_t;
 220 
 221 typedef enum {
 222         ZT_MAINT_NONE                   = 0, /* Normal Mode                             */
 223         ZT_MAINT_LOCALLOOP              = 1, /* Local Loopback                  */
 224         ZT_MAINT_REMOTELOOP             = 2, /* Remote Loopback                 */
 225         ZT_MAINT_LOOPUP                 = 3, /* Send Loopup Code                */
 226         ZT_MAINT_LOOPDOWN               = 4, /* Send Loopdown Code              */
 227         ZT_MAINT_LOOPSTOP               = 5  /* Stop Sending Loop Codes */
 228 } zt_maintenance_mode_t;
 229 
 230 typedef enum {
 231 /* Signalling type */
 232 ZT_SIG_NONE                                     = 0,                                            /* chan not configured. */
 233 
 234 ZT_SIG_FXSLS                            = ((1 << 0) | (1 << 13)),       /* FXS, Loopstart */
 235 ZT_SIG_FXSGS                            = ((1 << 1) | (1 << 13)),       /* FXS, Groundstart */
 236 ZT_SIG_FXSKS                            = ((1 << 2) | (1 << 13)),       /* FXS, Kewlstart */
 237 ZT_SIG_FXOLS                            = ((1 << 3) | (1 << 12)),       /* FXO, Loopstart */
 238 ZT_SIG_FXOGS                            = ((1 << 4) | (1 << 12)),       /* FXO, Groupstart */
 239 ZT_SIG_FXOKS                            = ((1 << 5) | (1 << 12)),       /* FXO, Kewlstart */
 240 ZT_SIG_EM                                       = (1 << 6),                                     /* E&M */
 241 ZT_SIG_CLEAR                            = (1 << 7),
 242 ZT_SIG_HDLCRAW                          = ((1 << 8)  | ZT_SIG_CLEAR),
 243 ZT_SIG_HDLCFCS                          = ((1 << 9)  | ZT_SIG_HDLCRAW),
 244 ZT_SIG_CAS                  = (1 << 15),
 245 ZT_SIG_HARDHDLC                         = ((1 << 19) | ZT_SIG_CLEAR),
 246 } zt_sigtype_t;
 247 
 248 typedef enum {
 249 ZT_DBIT = 1,
 250 ZT_CBIT = 2,
 251 ZT_BBIT = 4,
 252 ZT_ABIT = 8
 253 } zt_cas_bit_t;
 254 
 255 /* Defines */
 256 
 257 #define         ZT_MAX_BLOCKSIZE        8192
 258 #define         ZT_DEFAULT_MTU_MRU      2048
 259 
 260 /* ioctl defines */
 261 
 262 #define         ZT_CODE                         'J'
 263 #define     DAHDI_CODE          0xDA
 264 
 265 
 266 #define         ZT_GET_BLOCKSIZE        _IOR  (ZT_CODE, 1, int)                                 /* Get Transfer Block Size. */
 267 #define         ZT_SET_BLOCKSIZE        _IOW  (ZT_CODE, 2, int)                                 /* Set Transfer Block Size. */
 268 #define         ZT_FLUSH                        _IOW  (ZT_CODE, 3, int)                                 /* Flush Buffer(s) and stop I/O */
 269 #define         ZT_SYNC                         _IOW  (ZT_CODE, 4, int)                                 /* Wait for Write to Finish */
 270 #define         ZT_GET_PARAMS           _IOR  (ZT_CODE, 5, struct zt_params)    /* Get channel parameters */
 271 #define         ZT_SET_PARAMS           _IOW  (ZT_CODE, 6, struct zt_params)    /* Set channel parameters */
 272 #define         ZT_HOOK                         _IOW  (ZT_CODE, 7, int)                                 /* Set Hookswitch Status */
 273 #define         ZT_GETEVENT                     _IOR  (ZT_CODE, 8, int)                                 /* Get Signalling Event */
 274 #define         ZT_IOMUX                        _IOWR (ZT_CODE, 9, int)                                 /* Wait for something to happen (IO Mux) */
 275 #define         ZT_SPANSTAT                     _IOWR (ZT_CODE, 10, struct zt_spaninfo) /* Get Span Status */
 276 #define         ZT_MAINT                        _IOW  (ZT_CODE, 11, struct zt_maintinfo)/* Set Maintenance Mode for a span */
 277 #define         ZT_GETCONF                      _IOWR (ZT_CODE, 12, struct zt_confinfo) /* Get Conference Mode */
 278 #define         ZT_SETCONF                      _IOWR (ZT_CODE, 13, struct zt_confinfo) /* Set Conference Mode */
 279 #define         ZT_CONFLINK                     _IOW  (ZT_CODE, 14, struct zt_confinfo) /* Setup or Remove Conference Link */
 280 #define         ZT_CONFDIAG                     _IOR  (ZT_CODE, 15, int)                                /* Display Conference Diagnostic Information on Console */
 281 
 282 #define         ZT_GETGAINS                     _IOWR (ZT_CODE, 16, struct zt_gains)    /* Get Channel audio gains */
 283 #define         ZT_SETGAINS                     _IOWR (ZT_CODE, 17, struct zt_gains)    /* Set Channel audio gains */
 284 #define         ZT_SPANCONFIG           _IOW (ZT_CODE, 18, struct zt_lineconfig)/* Set Line (T1) Configurations and start system  */
 285 #define         ZT_CHANCONFIG           _IOW (ZT_CODE, 19, struct zt_chanconfig)/* Set Channel Configuration  */
 286 #define         ZT_SET_BUFINFO          _IOW (ZT_CODE, 27, struct zt_bufferinfo)/* Set buffer policy */
 287 #define         ZT_GET_BUFINFO          _IOR (ZT_CODE, 28, struct zt_bufferinfo)/* Get current buffer info */
 288 #define         ZT_AUDIOMODE            _IOW  (ZT_CODE, 32, int)                                /* Set a clear channel into audio mode */
 289 #define         ZT_ECHOCANCEL           _IOW  (ZT_CODE, 33, int)                                /* Control Echo Canceller */
 290 #define         ZT_HDLCRAWMODE          _IOW  (ZT_CODE, 36, int)                                /* Set a clear channel into HDLC w/out FCS checking/calculation mode */
 291 #define         ZT_HDLCFCSMODE          _IOW  (ZT_CODE, 37, int)                                /* Set a clear channel into HDLC w/ FCS mode */
 292 
 293 /* Specify a channel on /dev/ftdm/chan -- must be done before any other ioctl's and is only valid on /dev/ftdm/chan */
 294 #define         ZT_SPECIFY                      _IOW  (ZT_CODE, 38, int)
 295 
 296 /* Temporarily set the law on a channel to ZT_LAW_DEFAULT, ZT_LAW_ALAW, or ZT_LAW_MULAW. Is reset on close. */
 297 #define         ZT_SETLAW                       _IOW  (ZT_CODE, 39, int)
 298 
 299 /* Temporarily set the channel to operate in linear mode when non-zero or default law if 0 */
 300 #define         ZT_SETLINEAR            _IOW  (ZT_CODE, 40, int)
 301 
 302 #define         ZT_GETCONFMUTE          _IOR  (ZT_CODE, 49, int)                                /* Get Conference to mute mode */
 303 #define         ZT_ECHOTRAIN            _IOW  (ZT_CODE, 50, int)                                /* Control Echo Trainer */
 304 
 305 /* Set/Get CAS bits */
 306 #define ZT_SETTXBITS _IOW (ZT_CODE, 43, int)
 307 #define ZT_GETRXBITS _IOR (ZT_CODE, 45, int)
 308 
 309 #define         DAHDI_GET_BLOCKSIZE     _IOR  (DAHDI_CODE, 1, int)                                      /* Get Transfer Block Size. */
 310 #define         DAHDI_SET_BLOCKSIZE     _IOW  (DAHDI_CODE, 1, int)                                      /* Set Transfer Block Size. */
 311 #define         DAHDI_FLUSH                     _IOW  (DAHDI_CODE, 3, int)                                      /* Flush Buffer(s) and stop I/O */
 312 #define         DAHDI_SYNC                      _IO   (DAHDI_CODE, 4)                                   /* Wait for Write to Finish */
 313 #define         DAHDI_GET_PARAMS        _IOR  (DAHDI_CODE, 5, struct zt_params) /* Get channel parameters */
 314 #define         DAHDI_SET_PARAMS        _IOW  (DAHDI_CODE, 5, struct zt_params) /* Set channel parameters */
 315 #define         DAHDI_HOOK                      _IOW  (DAHDI_CODE, 7, int)                                      /* Set Hookswitch Status */
 316 #define         DAHDI_GETEVENT          _IOR  (DAHDI_CODE, 8, int)                                      /* Get Signalling Event */
 317 #define         DAHDI_IOMUX                     _IOWR (DAHDI_CODE, 9, int)                                      /* Wait for something to happen (IO Mux) */
 318 #define         DAHDI_SPANSTAT          _IOWR (DAHDI_CODE, 10, struct zt_spaninfo)  /* Get Span Status */
 319 #define         DAHDI_MAINT                     _IOW  (DAHDI_CODE, 11, struct zt_maintinfo) /* Set Maintenance Mode for a span */
 320 #define         DAHDI_GETCONF           _IOR  (DAHDI_CODE, 12, struct zt_confinfo)      /* Get Conference Mode */
 321 #define         DAHDI_SETCONF           _IOW  (DAHDI_CODE, 12, struct zt_confinfo)      /* Set Conference Mode */
 322 #define         DAHDI_CONFLINK          _IOW  (DAHDI_CODE, 14, struct zt_confinfo)      /* Setup or Remove Conference Link */
 323 #define         DAHDI_CONFDIAG          _IOR  (DAHDI_CODE, 15, int)                             /* Display Conference Diagnostic Information on Console */
 324 
 325 #define         DAHDI_GETGAINS          _IOR (DAHDI_CODE, 16, struct zt_gains)  /* Get Channel audio gains */
 326 #define         DAHDI_SETGAINS          _IOW (DAHDI_CODE, 16, struct zt_gains)  /* Set Channel audio gains */
 327 #define         DAHDI_SPANCONFIG        _IOW (DAHDI_CODE, 18, struct zt_lineconfig)/* Set Line (T1) Configurations and start system  */
 328 #define         DAHDI_CHANCONFIG        _IOW (DAHDI_CODE, 19, struct zt_chanconfig)/* Set Channel Configuration  */
 329 #define         DAHDI_SET_BUFINFO       _IOW (DAHDI_CODE, 27, struct zt_bufferinfo)/* Set buffer policy */
 330 #define         DAHDI_GET_BUFINFO       _IOR (DAHDI_CODE, 27, struct zt_bufferinfo)/* Get current buffer info */
 331 #define         DAHDI_AUDIOMODE         _IOW (DAHDI_CODE, 32, int)                              /* Set a clear channel into audio mode */
 332 #define         DAHDI_ECHOCANCEL        _IOW (DAHDI_CODE, 33, int)                              /* Control Echo Canceller */
 333 #define         DAHDI_HDLCRAWMODE       _IOW (DAHDI_CODE, 36, int)                              /* Set a clear channel into HDLC w/out FCS checking/calculation mode */
 334 #define         DAHDI_HDLCFCSMODE       _IOW (DAHDI_CODE, 37, int)                              /* Set a clear channel into HDLC w/ FCS mode */
 335 
 336 /* Specify a channel on /dev/dahdi/chan -- must be done before any other ioctl's and is only valid on /dev/dahdi/chan */
 337 #define         DAHDI_SPECIFY           _IOW  (DAHDI_CODE, 38, int)
 338 
 339 /* Temporarily set the law on a channel to DAHDI_LAW_DEFAULT, DAHDI_LAW_ALAW, or DAHDI_LAW_MULAW. Is reset on close. */
 340 #define         DAHDI_SETLAW            _IOW  (DAHDI_CODE, 39, int)
 341 
 342 /* Temporarily set the channel to operate in linear mode when non-zero or default law if 0 */
 343 #define         DAHDI_SETLINEAR         _IOW  (DAHDI_CODE, 40, int)
 344 
 345 #define         DAHDI_GETCONFMUTE       _IOR  (DAHDI_CODE, 49, int)                             /* Get Conference to mute mode */
 346 #define         DAHDI_ECHOTRAIN         _IOW  (DAHDI_CODE, 50, int)                             /* Control Echo Trainer */
 347 
 348 /* Set/Get CAS bits */
 349 #define DAHDI_SETTXBITS _IOW (DAHDI_CODE, 43, int)
 350 #define DAHDI_GETRXBITS _IOR (DAHDI_CODE, 43, int)
 351 
 352 
 353 #endif
 354 
 355 /* For Emacs:
 356  * Local Variables:
 357  * mode:c
 358  * indent-tabs-mode:t
 359  * tab-width:4
 360  * c-basic-offset:4
 361  * End:
 362  * For VIM:
 363  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 364  */

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