Newer
Older
* Asterisk -- An open source telephony toolkit.
* Copyright (C) 1999 - 2006, Digium, Inc.
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
*
* \brief Zaptel Pseudo TDM interface
*
* \author Mark Spencer <markster@digium.com>
*
* Connects to the zaptel telephony library as well as
* libpri. Libpri is optional and needed only if you are
* going to use ISDN connections.
*
* You need to install libraries before you attempt to compile
* and install the zaptel channel.
*
* \par See also
* \arg \ref Config_zap
*
* \ingroup channel_drivers
Olle Johansson
committed
*
Kevin P. Fleming
committed
* \todo Deprecate the "musiconhold" configuration option post 1.4
Kevin P. Fleming
committed
/*** MODULEINFO
<depend>zaptel_vldtmf</depend>
<depend>tonezone</depend>
<use>pri</use>
<use>ss7</use>
Kevin P. Fleming
committed
***/
Kevin P. Fleming
committed
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#ifdef __NetBSD__
#include <pthread.h>
#include <signal.h>
#else
#if !defined(SOLARIS) && !defined(__FreeBSD__)
#include <unistd.h>
#include <sys/ioctl.h>
#include <math.h>
#include "asterisk/zapata.h"
Kevin P. Fleming
committed
#ifdef HAVE_SS7
#include <libss7.h>
#endif
Kevin P. Fleming
committed
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/file.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
#include "asterisk/adsi.h"
#include "asterisk/cli.h"
#include "asterisk/cdr.h"
#include "asterisk/features.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/tdd.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/astdb.h"
#include "asterisk/manager.h"
#include "asterisk/causes.h"
#include "asterisk/term.h"
#include "asterisk/utils.h"
#include "asterisk/transcap.h"
#include "asterisk/stringfields.h"
Russell Bryant
committed
#include "asterisk/abstract_jb.h"
Matthew Fredrickson
committed
#include "asterisk/smdi.h"
#include "asterisk/astobj.h"
#define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
Kevin P. Fleming
committed
Russell Bryant
committed
/*! Global jitterbuffer configuration - by default, jb is disabled */
Russell Bryant
committed
static struct ast_jb_conf default_jbconf =
{
.flags = 0,
.max_size = -1,
.resync_threshold = -1,
.impl = ""
};
static struct ast_jb_conf global_jbconf;
Russell Bryant
committed
#if !defined(ZT_SIG_EM_E1) || (defined(HAVE_PRI) && !defined(ZT_SIG_HARDHDLC))
#error "Your zaptel is too old. Please update"
Mark Spencer
committed
#endif
#ifndef ZT_TONEDETECT
/* Work around older code with no tone detect */
#define ZT_EVENT_DTMFDOWN 0
#define ZT_EVENT_DTMFUP 0
#endif
/* define this to send PRI user-user information elements */
#undef SUPPORT_USERUSER
/*!
* \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
* the user hangs up to reset the state machine so ring works properly.
* This is used to be able to support kewlstart by putting the zhone in
* groundstart mode since their forward disconnect supervision is entirely
* broken even though their documentation says it isn't and their support
* is entirely unwilling to provide any assistance with their channel banks
* even though their web site says they support their products for life.
*/
* Define if you want to check the hook state for an FXO (FXS signalled) interface
* before dialing on it. Certain FXO interfaces always think they're out of
* service with this method however.
*/
/* #define ZAP_CHECK_HOOKSTATE */
/*! \brief Typically, how many rings before we should send Caller*ID */
#define AST_LAW(p) (((p)->law == ZT_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
/*! \brief Signaling types that need to use MF detection should be placed in this macro */
#define NEED_MFDETECT(p) (((p)->sig == SIG_FEATDMF) || ((p)->sig == SIG_FEATDMF_TA) || ((p)->sig == SIG_E911) || ((p)->sig == SIG_FGC_CAMA) || ((p)->sig == SIG_FGC_CAMAMF) || ((p)->sig == SIG_FEATB))
static const char tdesc[] = "Zapata Telephony Driver"
#ifdef HAVEL_LIBSS7
"w/SS7"
#endif
static const char config[] = "zapata.conf";
#define SIG_EMWINK (0x0100000 | ZT_SIG_EM)
#define SIG_FEATD (0x0200000 | ZT_SIG_EM)
#define SIG_FEATDMF (0x0400000 | ZT_SIG_EM)
#define SIG_FEATB (0x0800000 | ZT_SIG_EM)
Matthew Fredrickson
committed
#define SIG_FEATDMF_TA (0x2000000 | ZT_SIG_EM)
#define SIG_FGC_CAMA (0x4000000 | ZT_SIG_EM)
#define SIG_FGC_CAMAMF (0x8000000 | ZT_SIG_EM)
#define SIG_FXSLS ZT_SIG_FXSLS
#define SIG_FXSGS ZT_SIG_FXSGS
#define SIG_FXSKS ZT_SIG_FXSKS
#define SIG_FXOLS ZT_SIG_FXOLS
#define SIG_FXOGS ZT_SIG_FXOGS
#define SIG_FXOKS ZT_SIG_FXOKS
#define SIG_PRI ZT_SIG_CLEAR
#define SIG_SS7 (0x1000000 | ZT_SIG_CLEAR)
#define SIG_SFWINK (0x0100000 | ZT_SIG_SF)
#define SIG_SF_FEATD (0x0200000 | ZT_SIG_SF)
#define SIG_SF_FEATDMF (0x0400000 | ZT_SIG_SF)
#define SIG_SF_FEATB (0x0800000 | ZT_SIG_SF)
#define SIG_GR303FXOKS (0x0100000 | ZT_SIG_FXOKS)
#define SIG_GR303FXSKS (0x0100000 | ZT_SIG_FXSKS)
#define NUM_SPANS 32
#define NUM_DCHANS 4 /*!< No more than 4 d-channels */
#define MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
#define DCHAN_PROVISIONED (1 << 0)
#define DCHAN_NOTINALARM (1 << 1)
#define DCHAN_UP (1 << 2)
#define DCHAN_AVAILABLE (DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
Matthew Fredrickson
committed
static char defaultcic[64] = "";
static char defaultozz[64] = "";
static char progzone[10] = "";
static int usedistinctiveringdetection = 0;
Joshua Colp
committed
static int distinctiveringaftercid = 0;
static struct ast_channel inuse;
#ifdef PRI_GETSET_TIMERS
static int pritimers[PRI_MAX_TIMERS];
static char pridebugfilename[1024] = "";
#endif
/*! \brief Wait up to 16 seconds for first digit (FXO logic) */
/*! \brief How long to wait for following digits (FXO logic) */
/*! \brief How long to wait for an extra digit, if there is an ambiguous match */
Matthew Fredrickson
committed
Matthew Fredrickson
committed
AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
Matthew Fredrickson
committed
/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
AST_MUTEX_DEFINE_STATIC(monlock);
/*! \brief This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
static pthread_t monitor_thread = AST_PTHREADT_NULL;
static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
Mark Spencer
committed
static int zt_sendtext(struct ast_channel *c, const char *text);
/*! \brief Avoid the silly zt_getevent which ignores a bunch of events */
static inline int zt_get_event(int fd)
{
int j;
if (ioctl(fd, ZT_GETEVENT, &j) == -1)
return -1;
/*! \brief Avoid the silly zt_waitevent which ignores a bunch of events */
if (ioctl(fd, ZT_IOMUX, &i) == -1)
return -1;
if (ioctl(fd, ZT_GETEVENT, &j) == -1)
return -1;
/*! Chunk size to read -- we use 20ms chunks to make things happy. */
#define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
#define MASK_INUSE (1 << 1) /*!< Channel currently in use */
#define CALLWAITING_SILENT_SAMPLES ( (300 * 8) / READ_SIZE) /*!< 300 ms */
#define CALLWAITING_REPEAT_SAMPLES ( (10000 * 8) / READ_SIZE) /*!< 300 ms */
#define CIDCW_EXPIRE_SAMPLES ( (500 * 8) / READ_SIZE) /*!< 500 ms */
#define MIN_MS_SINCE_FLASH ( (2000) ) /*!< 2000 ms */
#define DEFAULT_RINGT ( (8000 * 8) / READ_SIZE)
static int ringt_base = DEFAULT_RINGT;
#ifdef HAVE_SS7
#define LINKSTATE_INALARM (1 << 0)
#define LINKSTATE_STARTING (1 << 1)
#define LINKSTATE_UP (1 << 2)
#define LINKSTATE_DOWN (1 << 3)
struct zt_ss7 {
pthread_t master; /*!< Thread of master */
ast_mutex_t lock;
int fds[NUM_DCHANS];
int numsigchans;
int linkstate[NUM_DCHANS];
int numchans;
int type;
Matthew Fredrickson
committed
enum {
LINKSET_STATE_DOWN = 0,
LINKSET_STATE_UP
} state;
struct ss7 *ss7;
struct zt_pvt *pvts[MAX_CHANNELS]; /*!< Member channel pvt structs */
};
static struct zt_ss7 linksets[NUM_SPANS];
static int cur_ss7type = -1;
static int cur_linkset = -1;
static int cur_pointcode = -1;
static int cur_cicbeginswith = -1;
static int cur_adjpointcode = -1;
static int cur_networkindicator = -1;
static int cur_defaultdpc = -1;
#endif /* HAVE_SS7 */
Mark Spencer
committed
#define PVT_TO_CHANNEL(p) (((p)->prioffset) | ((p)->logicalspan << 8) | (p->pri->mastertrunkgroup ? 0x10000 : 0))
Mark Spencer
committed
#define PRI_CHANNEL(p) ((p) & 0xff)
#define PRI_SPAN(p) (((p) >> 8) & 0xff)
#define PRI_EXPLICIT(p) (((p) >> 16) & 0x01)
Mark Spencer
committed
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
pthread_t master; /*!< Thread of master */
ast_mutex_t lock; /*!< Mutex */
char idleext[AST_MAX_EXTENSION]; /*!< Where to idle extra calls */
char idlecontext[AST_MAX_CONTEXT]; /*!< What context to use for idle */
char idledial[AST_MAX_EXTENSION]; /*!< What to dial before dumping */
int minunused; /*!< Min # of channels to keep empty */
int minidle; /*!< Min # of "idling" calls to keep active */
int nodetype; /*!< Node type */
int switchtype; /*!< Type of switch to emulate */
int nsf; /*!< Network-Specific Facilities */
int dialplan; /*!< Dialing plan */
int localdialplan; /*!< Local dialing plan */
char internationalprefix[10]; /*!< country access code ('00' for european dialplans) */
char nationalprefix[10]; /*!< area access code ('0' for european dialplans) */
char localprefix[20]; /*!< area access code + area code ('0'+area code for european dialplans) */
char privateprefix[20]; /*!< for private dialplans */
char unknownprefix[20]; /*!< for unknown dialplans */
int dchannels[NUM_DCHANS]; /*!< What channel are the dchannels on */
int trunkgroup; /*!< What our trunkgroup is */
int mastertrunkgroup; /*!< What trunk group is our master */
int prilogicalspan; /*!< Logical span number within trunk group */
int numchans; /*!< Num of channels we represent */
int overlapdial; /*!< In overlap dialing mode */
int facilityenable; /*!< Enable facility IEs */
struct pri *dchans[NUM_DCHANS]; /*!< Actual d-channels */
int dchanavail[NUM_DCHANS]; /*!< Whether each channel is available */
struct pri *pri; /*!< Currently active D-channel */
Mark Spencer
committed
int resetpos;
time_t lastreset; /*!< time when unused channels were last reset */
long resetinterval; /*!< Interval (in seconds) for resetting unused channels */
struct zt_pvt *pvts[MAX_CHANNELS]; /*!< Member channel pvt structs */
struct zt_pvt *crvs; /*!< Member CRV structs */
struct zt_pvt *crvend; /*!< Pointer to end of CRV structs */
};
static struct zt_pri pris[NUM_SPANS];
#if 0
#define DEFAULT_PRI_DEBUG (PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_STATE)
#else
#define DEFAULT_PRI_DEBUG 0
#endif
static inline void pri_rel(struct zt_pri *pri)
{
ast_mutex_unlock(&pri->lock);
#define SUB_REAL 0 /*!< Active call */
#define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
#define SUB_THREEWAY 2 /*!< Three-way call */
/* Polarity states */
#define POLARITY_IDLE 0
#define POLARITY_REV 1
static struct zt_distRings drings;
struct distRingData {
int ring[3];
char contextData[AST_MAX_CONTEXT];
};
struct zt_distRings {
struct distRingData ringnum[3];
struct ringContextData ringContext[3];
};
static char *subnames[] = {
"Real",
"Callwait",
"Threeway"
};
struct zt_subchannel {
int zfd;
struct ast_channel *owner;
int chan;
short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
unsigned int needringing:1;
unsigned int needbusy:1;
unsigned int needcongestion:1;
unsigned int needcallerid:1;
unsigned int needanswer:1;
unsigned int needflash:1;
Mark Spencer
committed
unsigned int needhold:1;
unsigned int needunhold:1;
unsigned int linear:1;
unsigned int inthreeway:1;
};
#define CONF_USER_REAL (1 << 0)
#define CONF_USER_THIRDCALL (1 << 1)
#define MAX_SLAVES 4
ast_mutex_t lock;
struct ast_channel *owner; /*!< Our current active owner (if applicable) */
/*!< Up to three channels can be associated with this call */
struct zt_subchannel sub_unused; /*!< Just a safety precaution */
struct zt_subchannel subs[3]; /*!< Sub-channels */
struct zt_confinfo saveconf; /*!< Saved conference info */
struct zt_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
struct zt_pvt *master; /*!< Master to us (we follow their conferencing) */
int inconference; /*!< If our real should be in the conference */
int sig; /*!< Signalling style */
int radio; /*!< radio type */
int outsigmod; /*!< Outbound Signalling style (modifier) */
int oprmode; /*!< "Operator Services" mode */
struct zt_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
int tonezone; /*!< tone zone for this chan, or -1 for default */
struct zt_pvt *next; /*!< Next channel in list */
struct zt_pvt *prev; /*!< Prev channel in list */
/* flags */
unsigned int adsi:1;
unsigned int answeronpolarityswitch:1;
unsigned int busydetect:1;
unsigned int callreturn:1;
unsigned int callwaiting:1;
unsigned int callwaitingcallerid:1;
unsigned int cancallforward:1;
unsigned int canpark:1;
unsigned int confirmanswer:1; /*!< Wait for '#' to confirm answer */
unsigned int destroy:1;
unsigned int didtdd:1; /*!< flag to say its done it once */
unsigned int dialednone:1;
unsigned int dialing:1;
unsigned int digital:1;
unsigned int dnd:1;
unsigned int echobreak:1;
unsigned int echocanbridged:1;
unsigned int echocanon:1;
unsigned int faxhandled:1; /*!< Has a fax tone already been handled? */
unsigned int firstradio:1;
unsigned int hanguponpolarityswitch:1;
unsigned int hardwaredtmf:1;
Matthew Fredrickson
committed
unsigned int hidecallerid:1;
unsigned int hidecalleridname:1; /*!< Hide just the name not the number for legacy PBX use */
unsigned int ignoredtmf:1;
unsigned int immediate:1; /*!< Answer before getting digits? */
unsigned int inalarm:1;
unsigned int outgoing:1;
unsigned int overlapdial:1;
unsigned int permcallwaiting:1;
unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */
unsigned int priindication_oob:1;
Matthew Fredrickson
committed
unsigned int priexclusive:1;
unsigned int pulse:1;
unsigned int pulsedial:1; /*!< whether a pulse dial phone is detected */
unsigned int restrictcid:1; /*!< Whether restrict the callerid -> only send ANI */
unsigned int threewaycalling:1;
unsigned int transfer:1;
unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
unsigned int use_callingpres:1; /*!< Whether to use the callingpres the calling switch sends */
unsigned int usedistinctiveringdetection:1;
unsigned int zaptrcallerid:1; /*!< should we use the callerid from incoming call on zap transfer or not */
unsigned int transfertobusy:1; /*!< allow flash-transfers to busy channels */
Matthew Fredrickson
committed
/* Channel state or unavilability flags */
unsigned int inservice:1;
unsigned int locallyblocked:1;
unsigned int remotelyblocked:1;
#if defined(HAVE_PRI)
unsigned int alerting:1;
unsigned int alreadyhungup:1;
unsigned int isidlecall:1;
Matthew Fredrickson
committed
unsigned int proceeding:1;
unsigned int progress:1;
unsigned int resetting:1;
unsigned int setup_ack:1;
#endif
Matthew Fredrickson
committed
unsigned int use_smdi:1; /* Whether to use SMDI on this channel */
struct ast_smdi_interface *smdi_iface; /* The serial port to listen for SMDI data on */
Russell Bryant
committed
char context[AST_MAX_CONTEXT];
char defcontext[AST_MAX_CONTEXT];
char exten[AST_MAX_EXTENSION];
char language[MAX_LANGUAGE];
Kevin P. Fleming
committed
char mohinterpret[MAX_MUSICCLASS];
char mohsuggest[MAX_MUSICCLASS];
#ifdef PRI_ANI
Russell Bryant
committed
char cid_ani[AST_MAX_EXTENSION];
Russell Bryant
committed
char cid_num[AST_MAX_EXTENSION];
Russell Bryant
committed
char cid_name[AST_MAX_EXTENSION];
char lastcid_num[AST_MAX_EXTENSION];
char lastcid_name[AST_MAX_EXTENSION];
char *origcid_num; /*!< malloced original callerid */
char *origcid_name; /*!< malloced original callerid */
Russell Bryant
committed
char callwait_num[AST_MAX_EXTENSION];
char callwait_name[AST_MAX_EXTENSION];
Russell Bryant
committed
char dnid[AST_MAX_EXTENSION];
unsigned int group;
int confno; /*!< Our conference */
int confusers; /*!< Who is using our conference */
int propconfno; /*!< Propagated conference number */
ast_group_t callgroup;
ast_group_t pickupgroup;
int channel; /*!< Channel Number or CRV */
int span; /*!< Span number */
time_t guardtime; /*!< Must wait this much time before using for new call */
int cid_signalling; /*!< CID signalling type bell202 or v23 */
int cid_start; /*!< CID start indicator, polarity or ring */
int callingpres; /*!< The value of callling presentation that we're going to use when placing a PRI call */
int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
int cidcwexpire; /*!< When to expire our muting for CID/CW */
unsigned char *cidspill;
int cidpos;
int cidlen;
int ringt;
int ringt_base;
int stripmsd;
int callwaitcas;
int callwaitrings;
int echocancel;
int echotraining;
int busy_tonelength;
int busy_quietlength;
int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
Russell Bryant
committed
char finaldial[64];
char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
int amaflags; /*!< AMA Flags */
struct tdd_state *tdd; /*!< TDD flag */
Russell Bryant
committed
char call_forward[AST_MAX_EXTENSION];
char mailbox[AST_MAX_EXTENSION];
int distinctivering; /*!< Which distinctivering to use */
int cidrings; /*!< Which ring to deliver CID on */
int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
Martin Pycko
committed
int fake_event;
int polarityonanswerdelay;
struct timeval polaritydelaytv;
struct zt_pvt *bearer;
struct zt_pvt *realcall;
int polarity;
#ifdef HAVE_SS7
struct zt_ss7 *ss7;
struct isup_call *ss7call;
int transcap;
int cic; /*!< CIC associated with channel */
unsigned int dpc; /*!< CIC's DPC */
char begindigit;
} *iflist = NULL, *ifend = NULL;
/*! \brief Channel configuration from zapata.conf .
* This struct is used for parsing the [channels] section of zapata.conf.
* Generally there is a field here for every possible configuration item.
*
* The state of fields is saved along the parsing and whenever a 'channel'
* statement is reached, the current zt_chan_conf is used to configure the
* channel (struct zt_pvt)
*
* \see zt_chan_init for the default values.
*/
struct zt_chan_conf {
struct zt_pvt chan;
ZT_PARAMS timing;
char smdi_port[SMDI_MAX_FILENAME_LEN];
};
/** returns a new zt_chan_conf with default values (by-value) */
static struct zt_chan_conf zt_chan_conf_default(void) {
/* recall that if a field is not included here it is initialized
* to 0 or equivalent
*/
struct zt_chan_conf conf = {
#ifdef HAVE_PRI
.nsf = PRI_NSF_NONE,
.switchtype = PRI_SWITCH_NI2,
.dialplan = PRI_NATIONAL_ISDN + 1,
.localdialplan = PRI_NATIONAL_ISDN + 1,
.nodetype = PRI_CPE,
.minunused = 2,
.idleext = "",
.idledial = "",
.internationalprefix = "",
.nationalprefix = "",
.localprefix = "",
.privateprefix = "",
.unknownprefix = "",
.resetinterval = 3600
},
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
.chan = {
.context = "default",
.cid_num = "",
.cid_name = "",
.mohinterpret = "default",
.mohsuggest = "",
.transfertobusy = 1,
.cid_signalling = CID_SIG_BELL,
.cid_start = CID_START_RING,
.zaptrcallerid = 0,
.use_callerid = 1,
.sig = -1,
.outsigmod = -1,
.tonezone = -1,
.echocancel = 1,
.busycount = 3,
.accountcode = "",
.mailbox = "",
.polarityonanswerdelay = 600,
.sendcalleridafter = DEFAULT_CIDRINGS
},
.timing = {
.prewinktime = -1,
.preflashtime = -1,
.winktime = -1,
.flashtime = -1,
.starttime = -1,
.rxwinktime = -1,
.rxflashtime = -1,
.debouncetime = -1
},
.smdi_port = "/dev/ttyS0",
};
return conf;
}
static struct ast_channel *zt_request(const char *type, int format, void *data, int *cause);
static int zt_digit_begin(struct ast_channel *ast, char digit);
static int zt_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
Mark Spencer
committed
static int zt_sendtext(struct ast_channel *c, const char *text);
static int zt_call(struct ast_channel *ast, char *rdest, int timeout);
static int zt_hangup(struct ast_channel *ast);
static int zt_answer(struct ast_channel *ast);
static struct ast_frame *zt_read(struct ast_channel *ast);
static int zt_write(struct ast_channel *ast, struct ast_frame *frame);
static struct ast_frame *zt_exception(struct ast_channel *ast);
Kevin P. Fleming
committed
static int zt_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
static int zt_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static int zt_setoption(struct ast_channel *chan, int option, void *data, int datalen);
static int zt_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
static const struct ast_channel_tech zap_tech = {
.description = tdesc,
.capabilities = AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_ALAW,
.requester = zt_request,
.send_digit_begin = zt_digit_begin,
.send_digit_end = zt_digit_end,
.send_text = zt_sendtext,
.call = zt_call,
.hangup = zt_hangup,
.answer = zt_answer,
.read = zt_read,
.write = zt_write,
.bridge = zt_bridge,
.exception = zt_exception,
.indicate = zt_indicate,
.fixup = zt_fixup,
.setoption = zt_setoption,
BJ Weschke
committed
.func_channel_read = zt_func_read,
};
#define GET_CHANNEL(p) ((p)->bearer ? (p)->bearer->channel : p->channel)
#else
#define GET_CHANNEL(p) ((p)->channel)
#endif
Martin Pycko
committed
struct zt_pvt *round_robin[32];
static inline int pri_grab(struct zt_pvt *pvt, struct zt_pri *pri)
{
int res;
/* Grab the lock first */
do {
ast_mutex_unlock(&pvt->lock);
/* Release the lock and try again */
usleep(1);
ast_mutex_lock(&pvt->lock);
} while (res);
pthread_kill(pri->master, SIGURG);
return 0;
}
#endif
#ifdef HAVE_SS7
static inline void ss7_rel(struct zt_ss7 *ss7)
{
ast_mutex_unlock(&ss7->lock);
}
static inline int ss7_grab(struct zt_pvt *pvt, struct zt_ss7 *pri)
{
int res;
/* Grab the lock first */
do {
res = ast_mutex_trylock(&pri->lock);
if (res) {
ast_mutex_unlock(&pvt->lock);
/* Release the lock and try again */
usleep(1);
ast_mutex_lock(&pvt->lock);
}
} while (res);
/* Then break the poll */
pthread_kill(pri->master, SIGURG);
return 0;
}
#endif
#define NUM_CADENCE_MAX 25
static int num_cadence = 4;
static int user_has_defined_cadences = 0;
static struct zt_ring_cadence cadences[NUM_CADENCE_MAX] = {
{ { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
{ { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
{ { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
{ { 1000, 500, 2500, 5000 } }, /*!< Long ring */
/*! \brief cidrings says in which pause to transmit the cid information, where the first pause
* is 1, the second pause is 2 and so on.
*/
static int cidrings[NUM_CADENCE_MAX] = {
2, /*!< Right after first long ring */
4, /*!< Right after long part */
3, /*!< After third chirp */
2, /*!< Second spell */
#define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
#define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __ZT_SIG_FXO) */)
#define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __ZT_SIG_FXO) */)
static int zt_get_index(struct ast_channel *ast, struct zt_pvt *p, int nullok)
if (p->subs[0].owner == ast)
res = 0;
else if (p->subs[1].owner == ast)
res = 1;
else if (p->subs[2].owner == ast)
res = 2;
else {
res = -1;
if (!nullok)
ast_log(LOG_WARNING, "Unable to get index, and nullok is not asserted\n");
}
return res;
}
Mark Spencer
committed
static void wakeup_sub(struct zt_pvt *p, int a, struct zt_pri *pri)
#else
static void wakeup_sub(struct zt_pvt *p, int a, void *pri)
#endif
Mark Spencer
committed
if (pri)
ast_mutex_unlock(&pri->lock);
#endif
for (;;) {
if (p->subs[a].owner) {
if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
ast_mutex_unlock(&p->lock);
usleep(1);
ast_mutex_lock(&p->lock);
} else {
ast_queue_frame(p->subs[a].owner, &ast_null_frame);
ast_mutex_unlock(&p->subs[a].owner->lock);
Mark Spencer
committed
if (pri)
ast_mutex_lock(&pri->lock);
#endif
static void zap_queue_frame(struct zt_pvt *p, struct ast_frame *f, void *data)
{
struct zt_pri *pri = (struct zt_pri*) data;
#endif
#ifdef HAVE_SS7
struct zt_ss7 *ss7 = (struct zt_ss7*) data;
Mark Spencer
committed
#endif
/* We must unlock the PRI to avoid the possibility of a deadlock */
#if defined(HAVE_PRI) || defined(HAVE_SS7)
if (data) {
switch (p->sig) {
case SIG_PRI:
ast_mutex_unlock(&pri->lock);
break;
#endif
#ifdef HAVE_SS7
case SIG_SS7:
ast_mutex_unlock(&ss7->lock);
break;
#endif
default:
break;
}
}
Mark Spencer
committed
#endif
for (;;) {
if (p->owner) {
if (ast_mutex_trylock(&p->owner->lock)) {
ast_mutex_unlock(&p->lock);
usleep(1);
ast_mutex_lock(&p->lock);
} else {
ast_queue_frame(p->owner, f);
ast_mutex_unlock(&p->owner->lock);
break;
}
} else
break;
}
#if defined(HAVE_PRI) || defined(HAVE_SS7)
if (data) {
switch (p->sig) {
case SIG_PRI:
ast_mutex_lock(&pri->lock);
break;
#endif
#ifdef HAVE_SS7
case SIG_SS7:
ast_mutex_lock(&ss7->lock);
break;
#endif
default:
break;
}
}
Mark Spencer
committed
#endif
static int restore_gains(struct zt_pvt *p);
static void swap_subs(struct zt_pvt *p, int a, int b)
{
int tchan;
int tinthreeway;
struct ast_channel *towner;
if (option_debug)
ast_log(LOG_DEBUG, "Swapping %d and %d\n", a, b);
tchan = p->subs[a].chan;
towner = p->subs[a].owner;
tinthreeway = p->subs[a].inthreeway;
p->subs[a].chan = p->subs[b].chan;
p->subs[a].owner = p->subs[b].owner;
p->subs[a].inthreeway = p->subs[b].inthreeway;
p->subs[b].chan = tchan;
p->subs[b].owner = towner;
p->subs[b].inthreeway = tinthreeway;
Mark Spencer
committed
wakeup_sub(p, a, NULL);
wakeup_sub(p, b, NULL);
}
static int zt_open(char *fn)
{
int fd;
int isnum;
int chan = 0;
int bs;
int x;
isnum = 1;
for (x = 0; x < strlen(fn); x++) {