diff options
Diffstat (limited to 'channels/chan_zap.c')
-rwxr-xr-x | channels/chan_zap.c | 258 |
1 files changed, 134 insertions, 124 deletions
diff --git a/channels/chan_zap.c b/channels/chan_zap.c index f44ebac29..199a377ba 100755 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -20,6 +20,17 @@ * * \brief Zaptel Pseudo TDM interface * + * 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 */ #include <stdio.h> @@ -96,8 +107,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define ZT_EVENT_DTMFUP 0 #endif -/* - * Define ZHONE_HACK to cause us to go off hook and then back on hook when +/*! + * \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 @@ -105,24 +116,23 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") * is entirely unwilling to provide any assistance with their channel banks * even though their web site says they support their products for life. */ - /* #define ZHONE_HACK */ -/* +/*! \note * 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 */ -/* Typically, how many rings before we should send Caller*ID */ +/*! \brief Typically, how many rings before we should send Caller*ID */ #define DEFAULT_CIDRINGS 1 #define CHANNEL_PSEUDO -12 #define AST_LAW(p) (((p)->law == ZT_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW) -/* Signaling types that need to use MF detection should be placed in this macro */ +/*! \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_FEATB)) static const char desc[] = "Zapata Telephony" @@ -171,8 +181,8 @@ static const char config[] = "zapata.conf"; #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 NUM_DCHANS 4 /*!< No more than 4 d-channels */ +#define MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */ #define CHAN_PSEUDO -2 @@ -287,7 +297,7 @@ static char nationalprefix[10] = ""; static char localprefix[20] = ""; static char privateprefix[20] = ""; static char unknownprefix[20] = ""; -static long resetinterval = 3600; /* How often (in seconds) to reset unused channels. Default 1 hour. */ +static long resetinterval = 3600; /*!< How often (in seconds) to reset unused channels. Default 1 hour. */ static struct ast_channel inuse = { "GR-303InUse" }; #ifdef PRI_GETSET_TIMERS static int pritimers[PRI_MAX_TIMERS]; @@ -296,19 +306,19 @@ static int pridebugfd = -1; static char pridebugfilename[1024]=""; #endif -/* Wait up to 16 seconds for first digit (FXO logic) */ +/*! \brief Wait up to 16 seconds for first digit (FXO logic) */ static int firstdigittimeout = 16000; -/* How long to wait for following digits (FXO logic) */ +/*! \brief How long to wait for following digits (FXO logic) */ static int gendigittimeout = 8000; -/* How long to wait for an extra digit, if there is an ambiguous match */ +/*! \brief How long to wait for an extra digit, if there is an ambiguous match */ static int matchdigittimeout = 3000; static int usecnt =0; AST_MUTEX_DEFINE_STATIC(usecnt_lock); -/* Protect the interface list (of zt_pvt's) */ +/*! \brief Protect the interface list (of zt_pvt's) */ AST_MUTEX_DEFINE_STATIC(iflock); @@ -318,23 +328,23 @@ static int ifcount = 0; AST_MUTEX_DEFINE_STATIC(pridebugfdlock); #endif -/* Whether we answer on a Polarity Switch event */ +/*! \brief Whether we answer on a Polarity Switch event */ static int answeronpolarityswitch = 0; -/* Whether we hang up on a Polarity Switch event */ +/*! \brief Whether we hang up on a Polarity Switch event */ static int hanguponpolarityswitch = 0; -/* How long (ms) to ignore Polarity Switch events after we answer a call */ +/*! \brief How long (ms) to ignore Polarity Switch events after we answer a call */ static int polarityonanswerdelay = 600; -/* When to send the CallerID signals (rings) */ +/*! \brief When to send the CallerID signals (rings) */ static int sendcalleridafter = DEFAULT_CIDRINGS; -/* Protect the monitoring thread, so only one process can kill or start it, and not +/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. */ AST_MUTEX_DEFINE_STATIC(monlock); -/* This is the thread for the monitor which checks for input on the channels +/*! \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; @@ -344,17 +354,17 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann 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) { - /* Avoid the silly zt_getevent which ignores a bunch of events */ int j; if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1; return j; } +/*! \brief Avoid the silly zt_waitevent which ignores a bunch of events */ static inline int zt_wait_event(int fd) { - /* Avoid the silly zt_waitevent which ignores a bunch of events */ int i,j=0; i = ZT_IOMUX_SIGEVENT; if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1; @@ -362,16 +372,16 @@ static inline int zt_wait_event(int fd) return j; } -/* Chunk size to read -- we use 20ms chunks to make things happy. */ +/*! Chunk size to read -- we use 20ms chunks to make things happy. */ #define READ_SIZE 160 -#define MASK_AVAIL (1 << 0) /* Channel available for PRI use */ -#define MASK_INUSE (1 << 1) /* Channel currently in use */ +#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 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) struct zt_pvt; @@ -391,44 +401,44 @@ static int ringt_base = DEFAULT_RINGT; #define PRI_EXPLICIT(p) (((p) >> 16) & 0x01) struct zt_pri { - 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 */ + 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 */ int debug; - int fds[NUM_DCHANS]; /* FD's for d-channels */ + int fds[NUM_DCHANS]; /*!< FD's for d-channels */ int offset; int span; int resetting; 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 */ + 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 */ }; @@ -453,13 +463,13 @@ static int dialplan = PRI_NATIONAL_ISDN + 1; static int localdialplan = PRI_NATIONAL_ISDN + 1; #else -/* Shut up the compiler */ +/*! Shut up the compiler */ struct zt_pri; #endif -#define SUB_REAL 0 /* Active call */ -#define SUB_CALLWAIT 1 /* Call-Waiting call on hold */ -#define SUB_THREEWAY 2 /* Three-way call */ +#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 @@ -490,7 +500,7 @@ struct zt_subchannel { 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? */ + 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; @@ -509,24 +519,24 @@ struct zt_subchannel { static struct zt_pvt { 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 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_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 */ + 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 sig; /*!< Signalling style */ + int radio; /*!< radio type */ float rxgain; float txgain; - 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 */ + 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; @@ -537,9 +547,9 @@ static struct zt_pvt { unsigned int callwaitingcallerid:1; unsigned int cancallforward:1; unsigned int canpark:1; - unsigned int confirmanswer:1; /* Wait for '#' to confirm answer */ + 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 didtdd:1; /*!< flag to say its done it once */ unsigned int dialednone:1; unsigned int dialing:1; unsigned int digital:1; @@ -547,31 +557,31 @@ static struct zt_pvt { 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 faxhandled:1; /*!< Has a fax tone already been handled? */ unsigned int firstradio:1; unsigned int hanguponpolarityswitch:1; unsigned int hardwaredtmf:1; unsigned int hidecallerid; unsigned int ignoredtmf:1; - unsigned int immediate:1; /* Answer before getting digits? */ + unsigned int immediate:1; /*!< Answer before getting digits? */ unsigned int inalarm:1; - unsigned int mate:1; /* flag to say its in MATE mode */ + unsigned int mate:1; /*!< flag to say its in MATE mode */ 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 permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */ unsigned int priindication_oob:1; 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 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 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 */ + 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 */ #if defined(ZAPATA_PRI) unsigned int alerting:1; unsigned int alreadyhungup:1; @@ -598,31 +608,31 @@ static struct zt_pvt { char cid_ani[AST_MAX_EXTENSION]; #endif char cid_num[AST_MAX_EXTENSION]; - int cid_ton; /* Type Of Number (TON) */ + int cid_ton; /*!< Type Of Number (TON) */ 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 */ + char *origcid_num; /*!< malloced original callerid */ + char *origcid_name; /*!< malloced original callerid */ char callwait_num[AST_MAX_EXTENSION]; char callwait_name[AST_MAX_EXTENSION]; char rdnis[AST_MAX_EXTENSION]; char dnid[AST_MAX_EXTENSION]; unsigned int group; int law; - int confno; /* Our conference */ - int confusers; /* Who is using our conference */ - int propconfno; /* Propagated conference number */ + 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 */ + 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; @@ -638,23 +648,23 @@ static struct zt_pvt { int busy_tonelength; int busy_quietlength; int callprogress; - struct timeval flashtime; /* Last flash-hook time */ + struct timeval flashtime; /*!< Last flash-hook time */ struct ast_dsp *dsp; - int cref; /* Call reference number */ + int cref; /*!< Call reference number */ ZT_DIAL_OPERATION dop; - int whichwink; /* SIG_FEATDMF_TA Which wink are we on? */ + int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */ char finaldial[64]; - char accountcode[AST_MAX_ACCOUNT_CODE]; /* Account code */ - int amaflags; /* AMA Flags */ - struct tdd_state *tdd; /* TDD flag */ + char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */ + int amaflags; /*!< AMA Flags */ + struct tdd_state *tdd; /*!< TDD flag */ char call_forward[AST_MAX_EXTENSION]; char mailbox[AST_MAX_EXTENSION]; char dialdest[256]; int onhooktime; int msgstate; - int distinctivering; /* Which distinctivering to use */ - int cidrings; /* Which ring to deliver CID on */ - int dtmfrelax; /* whether to run in relaxed DTMF mode */ + int distinctivering; /*!< Which distinctivering to use */ + int cidrings; /*!< Which ring to deliver CID on */ + int dtmfrelax; /*!< whether to run in relaxed DTMF mode */ int fake_event; int polarityonanswerdelay; struct timeval polaritydelaytv; @@ -741,23 +751,23 @@ 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 */ + { { 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 */ }; -int receivedRingT; /* Used to find out what ringtone we are on */ +int receivedRingT; /*!< Used to find out what ringtone we are on */ -/* cidrings says in which pause to transmit the cid information, where the first pause +/*! \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 */ + 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) || \ |