/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2008, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
*
* 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.
*/
/*! \file
*
* \brief DAHDI for Pseudo TDM
*
* \author Mark Spencer <markster@digium.com>
*
* Connects to the DAHDI 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 DAHDI channel.
*
* \par See also
* \arg \ref Config_dahdi
*
* \ingroup channel_drivers
*
* \todo Deprecate the "musiconhold" configuration option post 1.4
*/
/*** MODULEINFO
<use type="module">res_smdi</use>
<depend>dahdi</depend>
<depend>tonezone</depend>
<use type="external">pri</use>
<use type="external">ss7</use>
<use type="external">openr2</use>
***/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#if defined(__NetBSD__) || defined(__FreeBSD__)
#include <pthread.h>
#include <signal.h>
#else
#include <sys/signal.h>
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <math.h>
#include <ctype.h>
#include <dahdi/user.h>
#include <dahdi/tonezone.h>
#include "sig_analog.h"
/* Analog signaling is currently still present in chan_dahdi for use with
* radio. Sig_analog does not currently handle any radio operations. If
* radio only uses analog signaling, then the radio handling logic could
* be placed in sig_analog and the duplicated code could be removed.
*/
#ifdef HAVE_PRI
#include "sig_pri.h"
#endif
#if defined(HAVE_SS7)
#include "sig_ss7.h"
#endif /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
/* put this here until sig_mfcr2 comes along */
#define SIG_MFCR2_MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
#include <openr2.h>
#endif
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.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/cel.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"
#include "asterisk/abstract_jb.h"
#include "asterisk/smdi.h"
#include "asterisk/astobj.h"
#include "asterisk/event.h"
#include "asterisk/devicestate.h"
#include "asterisk/paths.h"
#include "asterisk/ccss.h"
#include "asterisk/data.h"
/*** DOCUMENTATION
<application name="DAHDISendKeypadFacility" language="en_US">
<synopsis>
Send digits out of band over a PRI.
</synopsis>
<syntax>
<parameter name="digits" required="true" />
</syntax>
<description>
<para>This application will send the given string of digits in a Keypad
Facility IE over the current channel.</para>
</description>
</application>
<application name="DAHDISendCallreroutingFacility" language="en_US">
<synopsis>
Send an ISDN call rerouting/deflection facility message.
</synopsis>
<syntax argsep=",">
<parameter name="destination" required="true">
<para>Destination number.</para>
</parameter>
<parameter name="original">
<para>Original called number.</para>
</parameter>
<parameter name="reason">
<para>Diversion reason, if not specified defaults to <literal>unknown</literal></para>
</parameter>
</syntax>
<description>
<para>This application will send an ISDN switch specific call
rerouting/deflection facility message over the current channel.
Supported switches depend upon the version of libpri in use.</para>
</description>
</application>
<application name="DAHDIAcceptR2Call" language="en_US">
<synopsis>
Accept an R2 call if its not already accepted (you still need to answer it)
</synopsis>
<syntax>
<parameter name="charge" required="true">
<para>Yes or No.</para>
<para>Whether you want to accept the call with charge or without charge.</para>
</parameter>
</syntax>
<description>
<para>This application will Accept the R2 call either with charge or no charge.</para>
</description>
</application>
<manager name="DAHDITransfer" language="en_US">
<synopsis>
Transfer DAHDI Channel.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true">
<para>DAHDI channel name to transfer.</para>
</parameter>
</syntax>
<description>
<para>Transfer a DAHDI channel.</para>
</description>
</manager>
<manager name="DAHDIHangup" language="en_US">
<synopsis>
Hangup DAHDI Channel.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true">
<para>DAHDI channel name to hangup.</para>
</parameter>
</syntax>
<description>
<para>Hangup a DAHDI channel.</para>
</description>
</manager>
<manager name="DAHDIDialOffhook" language="en_US">
<synopsis>
Dial over DAHDI channel while offhook.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true" />
<parameter name="Number" required="true" />
</syntax>
<description>
</description>
</manager>
<manager name="DAHDIDNDon" language="en_US">
<synopsis>
Toggle DAHDI channel Do Not Disturb status ON.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true" />
</syntax>
<description>
</description>
</manager>
<manager name="DAHDIDNDoff" language="en_US">
<synopsis>
Toggle DAHDI channel Do Not Disturb status OFF.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true" />
</syntax>
<description>
</description>
</manager>
<manager name="DAHDIShowChannels" language="en_US">
<synopsis>
Show status DAHDI channels.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel">
<para>Specify the specific channel to show. Show all channels if zero or not present.</para>
</parameter>
</syntax>
<description>
</description>
</manager>
<manager name="DAHDIRestart" language="en_US">
<synopsis>
Fully Restart DAHDI channels (terminates calls).
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
</syntax>
<description>
</description>
</manager>
<manager name="PRIShowSpans" language="en_US">
<synopsis>
Show status of PRI spans.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Span">
<para>Specify the specific span to show. Show all spans if zero or not present.</para>
</parameter>
</syntax>
<description>
</description>
</manager>
***/
#define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
static const char * const lbostr[] = {
"0 db (CSU)/0-133 feet (DSX-1)",
"133-266 feet (DSX-1)",
"266-399 feet (DSX-1)",
"399-533 feet (DSX-1)",
"533-655 feet (DSX-1)",
"-7.5db (CSU)",
"-15db (CSU)",
"-22.5db (CSU)"
};
/*! Global jitterbuffer configuration - by default, jb is disabled
* \note Values shown here match the defaults shown in chan_dahdi.conf.sample */
static struct ast_jb_conf default_jbconf =
{
.flags = 0,
.max_size = 200,
.resync_threshold = 1000,
.impl = "fixed",
.target_extra = 40,
};
static struct ast_jb_conf global_jbconf;
/*!
* \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 ZHONE_HACK */
/*! \brief Typically, how many rings before we should send Caller*ID */
#define DEFAULT_CIDRINGS 1
#define AST_LAW(p) (((p)->law == DAHDI_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[] = "DAHDI Telephony Driver"
#if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2)
" w/"
#if defined(HAVE_PRI)
"PRI"
#endif /* defined(HAVE_PRI) */
#if defined(HAVE_SS7)
#if defined(HAVE_PRI)
" & "
#endif /* defined(HAVE_PRI) */
"SS7"
#endif /* defined(HAVE_SS7) */
#if defined(HAVE_OPENR2)
#if defined(HAVE_PRI) || defined(HAVE_SS7)
" & "
#endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
"MFC/R2"
#endif /* defined(HAVE_OPENR2) */
#endif /* defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) */
;
static const char config[] = "chan_dahdi.conf";
#define SIG_EM DAHDI_SIG_EM
#define SIG_EMWINK (0x0100000 | DAHDI_SIG_EM)
#define SIG_FEATD (0x0200000 | DAHDI_SIG_EM)
#define SIG_FEATDMF (0x0400000 | DAHDI_SIG_EM)
#define SIG_FEATB (0x0800000 | DAHDI_SIG_EM)
#define SIG_E911 (0x1000000 | DAHDI_SIG_EM)
#define SIG_FEATDMF_TA (0x2000000 | DAHDI_SIG_EM)
#define SIG_FGC_CAMA (0x4000000 | DAHDI_SIG_EM)
#define SIG_FGC_CAMAMF (0x8000000 | DAHDI_SIG_EM)
#define SIG_FXSLS DAHDI_SIG_FXSLS
#define SIG_FXSGS DAHDI_SIG_FXSGS
#define SIG_FXSKS DAHDI_SIG_FXSKS
#define SIG_FXOLS DAHDI_SIG_FXOLS
#define SIG_FXOGS DAHDI_SIG_FXOGS
#define SIG_FXOKS DAHDI_SIG_FXOKS
#define SIG_PRI DAHDI_SIG_CLEAR
#define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
#define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
#define SIG_SS7 (0x1000000 | DAHDI_SIG_CLEAR)
#define SIG_MFCR2 DAHDI_SIG_CAS
#define SIG_SF DAHDI_SIG_SF
#define SIG_SFWINK (0x0100000 | DAHDI_SIG_SF)
#define SIG_SF_FEATD (0x0200000 | DAHDI_SIG_SF)
#define SIG_SF_FEATDMF (0x0400000 | DAHDI_SIG_SF)
#define SIG_SF_FEATB (0x0800000 | DAHDI_SIG_SF)
#define SIG_EM_E1 DAHDI_SIG_EM_E1
#ifdef LOTS_OF_SPANS
#define NUM_SPANS DAHDI_MAX_SPANS
#else
#define NUM_SPANS 32
#endif
#define CHAN_PSEUDO -2
#define CALLPROGRESS_PROGRESS 1
#define CALLPROGRESS_FAX_OUTGOING 2
#define CALLPROGRESS_FAX_INCOMING 4
#define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
#define NUM_CADENCE_MAX 25
static int num_cadence = 4;
static int user_has_defined_cadences = 0;
static struct dahdi_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 */
};
/* ETSI EN300 659-1 specifies the ring pulse between 200 and 300 mS */
static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}};
#define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
(p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
#define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
#define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
static char defaultcic[64] = "";
static char defaultozz[64] = "";
static char parkinglot[AST_MAX_EXTENSION] = ""; /*!< Default parking lot for this channel */
/*! Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled */
static char mwimonitornotify[PATH_MAX] = "";
#ifndef HAVE_DAHDI_LINEREVERSE_VMWI
static int mwisend_rpas = 0;
#endif
static char progzone[10] = "";
static int usedistinctiveringdetection = 0;
static int distinctiveringaftercid = 0;
static int numbufs = 4;
static int mwilevel = 512;
static int dtmfcid_level = 256;
#define REPORT_CHANNEL_ALARMS 1
#define REPORT_SPAN_ALARMS 2
static int report_alarms = REPORT_CHANNEL_ALARMS;
#ifdef HAVE_PRI
static int pridebugfd = -1;
static char pridebugfilename[1024] = "";
#endif
/*! \brief Wait up to 16 seconds for first digit (FXO logic) */
static int firstdigittimeout = 16000;
/*! \brief How long to wait for following digits (FXO logic) */
static int gendigittimeout = 8000;
/*! \brief How long to wait for an extra digit, if there is an ambiguous match */
static int matchdigittimeout = 3000;
/*! \brief Protect the interface list (of dahdi_pvt's) */
AST_MUTEX_DEFINE_STATIC(iflock);
static int ifcount = 0;
#ifdef HAVE_PRI
AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
#endif
/*! \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);
/*! \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 ast_cond_t ss_thread_complete;
AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
AST_MUTEX_DEFINE_STATIC(restart_lock);
static int ss_thread_count = 0;
static int num_restart_pending = 0;
static int restart_monitor(void);
static enum ast_bridge_result dahdi_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
static int dahdi_sendtext(struct ast_channel *c, const char *text);
static void mwi_event_cb(const struct ast_event *event, void *userdata)
{
/* This module does not handle MWI in an event-based manner. However, it
* subscribes to MWI for each mailbox that is configured so that the core
* knows that we care about it. Then, chan_dahdi will get the MWI from the
* event cache instead of checking the mailbox directly. */
}
/*! \brief Avoid the silly dahdi_getevent which ignores a bunch of events */
static inline int dahdi_get_event(int fd)
{
int j;
if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
return -1;
return j;
}
/*! \brief Avoid the silly dahdi_waitevent which ignores a bunch of events */
static inline int dahdi_wait_event(int fd)
{
int i, j = 0;
i = DAHDI_IOMUX_SIGEVENT;
if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
return -1;
if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
return -1;
return j;
}
/*! 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 CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) /*!< 300 ms */
#define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
#define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) /*!< 100 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) /*!< 8,000 ms */
struct dahdi_pvt;
/*!
* \brief Configured ring timeout base.
* \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
*/
static int ringt_base = DEFAULT_RINGT;
#if defined(HAVE_SS7)
struct dahdi_ss7 {
struct sig_ss7_linkset ss7;
};
static struct dahdi_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 /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
struct dahdi_mfcr2 {
pthread_t r2master; /*!< Thread of master */
openr2_context_t *protocol_context; /*!< OpenR2 context handle */
struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
int numchans; /*!< Number of channels in this R2 block */
int monitored_count; /*!< Number of channels being monitored */
};
struct dahdi_mfcr2_conf {
openr2_variant_t variant;
int mfback_timeout;
int metering_pulse_timeout;
int max_ani;
int max_dnis;
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
int dtmf_time_on;
int dtmf_time_off;
#endif
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
int dtmf_end_timeout;
#endif
signed int get_ani_first:2;
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
signed int skip_category_request:2;
#endif
unsigned int call_files:1;
unsigned int allow_collect_calls:1;
unsigned int charge_calls:1;
unsigned int accept_on_offer:1;
unsigned int forced_release:1;
unsigned int double_answer:1;
signed int immediate_accept:2;
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
signed int dtmf_dialing:2;
signed int dtmf_detection:2;
#endif
char logdir[OR2_MAX_PATH];
char r2proto_file[OR2_MAX_PATH];
openr2_log_level_t loglevel;
openr2_calling_party_category_t category;
};
/* malloc'd array of malloc'd r2links */
static struct dahdi_mfcr2 **r2links;
/* how many r2links have been malloc'd */
static int r2links_count = 0;
#endif /* HAVE_OPENR2 */
#ifdef HAVE_PRI
struct dahdi_pri {
int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
int mastertrunkgroup; /*!< What trunk group is our master */
int prilogicalspan; /*!< Logical span number within trunk group */
struct sig_pri_span pri;
};
static struct dahdi_pri pris[NUM_SPANS];
#if defined(HAVE_PRI_CCSS)
/*! DAHDI PRI CCSS agent and monitor type name. */
static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
#endif /* defined(HAVE_PRI_CCSS) */
#else
/*! Shut up the compiler */
struct dahdi_pri;
#endif
#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
struct distRingData {
int ring[3];
int range;
};
struct ringContextData {
char contextData[AST_MAX_CONTEXT];
};
struct dahdi_distRings {
struct distRingData ringnum[3];
struct ringContextData ringContext[3];
};
static const char * const subnames[] = {
"Real",
"Callwait",
"Threeway"
};
struct dahdi_subchannel {
int dfd;
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 needanswer:1;
unsigned int needflash:1;
unsigned int needhold:1;
unsigned int needunhold:1;
unsigned int linear:1;
unsigned int inthreeway:1;
struct dahdi_confinfo curconf;
};
#define CONF_USER_REAL (1 << 0)
#define CONF_USER_THIRDCALL (1 << 1)
#define MAX_SLAVES 4
/* States for sending MWI message
* First three states are required for send Ring Pulse Alert Signal
*/
typedef enum {
MWI_SEND_NULL = 0,
MWI_SEND_SA,
MWI_SEND_SA_WAIT,
MWI_SEND_PAUSE,
MWI_SEND_SPILL,
MWI_SEND_CLEANUP,
MWI_SEND_DONE,
} mwisend_states;
struct mwisend_info {
struct timeval pause;
mwisend_states mwisend_current;
};
/*! Specify the lists dahdi_pvt can be put in. */
enum DAHDI_IFLIST {
DAHDI_IFLIST_NONE, /*!< The dahdi_pvt is not in any list. */
DAHDI_IFLIST_MAIN, /*!< The dahdi_pvt is in the main interface list */
#if defined(HAVE_PRI)
DAHDI_IFLIST_NO_B_CHAN, /*!< The dahdi_pvt is in a no B channel interface list */
#endif /* defined(HAVE_PRI) */
};
struct dahdi_pvt {
ast_mutex_t lock; /*!< Channel private lock. */
struct callerid_state *cs;
struct ast_channel *owner; /*!< Our current active owner (if applicable) */
/*!< Up to three channels can be associated with this call */
struct dahdi_subchannel sub_unused; /*!< Just a safety precaution */
struct dahdi_subchannel subs[3]; /*!< Sub-channels */
struct dahdi_confinfo saveconf; /*!< Saved conference info */
struct dahdi_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
struct dahdi_pvt *master; /*!< Master to us (we follow their conferencing) */
int inconference; /*!< If our real should be in the conference */
int bufsize; /*!< Size of the buffers */
int buf_no; /*!< Number of buffers */
int buf_policy; /*!< Buffer policy */
int faxbuf_no; /*!< Number of Fax buffers */
int faxbuf_policy; /*!< Fax buffer policy */
int sig; /*!< Signalling style */
/*!
* \brief Nonzero if the signaling type is sent over a radio.
* \note Set to a couple of nonzero values but it is only tested like a boolean.
*/
int radio;
int outsigmod; /*!< Outbound Signalling style (modifier) */
int oprmode; /*!< "Operator Services" mode */
struct dahdi_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
/*! \brief Amount of gain to increase during caller id */
float cid_rxgain;
/*! \brief Rx gain set by chan_dahdi.conf */
float rxgain;
/*! \brief Tx gain set by chan_dahdi.conf */
float txgain;
float txdrc; /*!< Dynamic Range Compression factor. a number between 1 and 6ish */
float rxdrc;
int tonezone; /*!< tone zone for this chan, or -1 for default */
enum DAHDI_IFLIST which_iflist; /*!< Which interface list is this structure listed? */
struct dahdi_pvt *next; /*!< Next channel in list */
struct dahdi_pvt *prev; /*!< Prev channel in list */
/* flags */
/*!
* \brief TRUE if ADSI (Analog Display Services Interface) available
* \note Set from the "adsi" value read in from chan_dahdi.conf
*/
unsigned int adsi:1;
/*!
* \brief TRUE if we can use a polarity reversal to mark when an outgoing
* call is answered by the remote party.
* \note Set from the "answeronpolarityswitch" value read in from chan_dahdi.conf
*/
unsigned int answeronpolarityswitch:1;
/*!
* \brief TRUE if busy detection is enabled.
* (Listens for the beep-beep busy pattern.)
* \note Set from the "busydetect" value read in from chan_dahdi.conf
*/
unsigned int busydetect:1;
/*!
* \brief TRUE if call return is enabled.
* (*69, if your dialplan doesn't catch this first)
* \note Set from the "callreturn" value read in from chan_dahdi.conf
*/
unsigned int callreturn:1;
/*!
* \brief TRUE if busy extensions will hear the call-waiting tone
* and can use hook-flash to switch between callers.
* \note Can be disabled by dialing *70.
* \note Initialized with the "callwaiting" value read in from chan_dahdi.conf
*/
unsigned int callwaiting:1;
/*!
* \brief TRUE if send caller ID for Call Waiting
* \note Set from the "callwaitingcallerid" value read in from chan_dahdi.conf
*/
unsigned int callwaitingcallerid:1;
/*!
* \brief TRUE if support for call forwarding enabled.
* Dial *72 to enable call forwarding.
* Dial *73 to disable call forwarding.
* \note Set from the "cancallforward" value read in from chan_dahdi.conf
*/
unsigned int cancallforward:1;
/*!
* \brief TRUE if support for call parking is enabled.
* \note Set from the "canpark" value read in from chan_dahdi.conf
*/
unsigned int canpark:1;
/*! \brief TRUE if to wait for a DTMF digit to confirm answer */
unsigned int confirmanswer:1;
/*!
* \brief TRUE if the channel is to be destroyed on hangup.
* (Used by pseudo channels.)
*/
unsigned int destroy:1;
unsigned int didtdd:1; /*!< flag to say its done it once */
/*! \brief TRUE if analog type line dialed no digits in Dial() */
unsigned int dialednone:1;
/*!
* \brief TRUE if in the process of dialing digits or sending something.
* \note This is used as a receive squelch for ISDN until connected.
*/
unsigned int dialing:1;
/*! \brief TRUE if the transfer capability of the call is digital. */
unsigned int digital:1;
/*! \brief TRUE if Do-Not-Disturb is enabled, present only for non sig_analog */
unsigned int dnd:1;
/*! \brief XXX BOOLEAN Purpose??? */
unsigned int echobreak:1;
/*!
* \brief TRUE if echo cancellation enabled when bridged.
* \note Initialized with the "echocancelwhenbridged" value read in from chan_dahdi.conf
* \note Disabled if the echo canceller is not setup.
*/
unsigned int echocanbridged:1;
/*! \brief TRUE if echo cancellation is turned on. */
unsigned int echocanon:1;
/*! \brief TRUE if a fax tone has already been handled. */
unsigned int faxhandled:1;
/*! TRUE if dynamic faxbuffers are configured for use, default is OFF */
unsigned int usefaxbuffers:1;
/*! TRUE while buffer configuration override is in use */
unsigned int bufferoverrideinuse:1;
/*! \brief TRUE if over a radio and dahdi_read() has been called. */
unsigned int firstradio:1;
/*!
* \brief TRUE if the call will be considered "hung up" on a polarity reversal.
* \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf
*/
unsigned int hanguponpolarityswitch:1;
/*! \brief TRUE if DTMF detection needs to be done by hardware. */
unsigned int hardwaredtmf:1;
/*!
* \brief TRUE if the outgoing caller ID is blocked/hidden.
* \note Caller ID can be disabled by dialing *67.
* \note Caller ID can be enabled by dialing *82.
* \note Initialized with the "hidecallerid" value read in from chan_dahdi.conf
*/
unsigned int hidecallerid:1;
/*!
* \brief TRUE if hide just the name not the number for legacy PBX use.
* \note Only applies to PRI channels.
* \note Set from the "hidecalleridname" value read in from chan_dahdi.conf
*/
unsigned int hidecalleridname:1;
/*! \brief TRUE if DTMF detection is disabled. */
unsigned int ignoredtmf:1;
/*!
* \brief TRUE if the channel should be answered immediately
* without attempting to gather any digits.
* \note Set from the "immediate" value read in from chan_dahdi.conf
*/
unsigned int immediate:1;
/*! \brief TRUE if in an alarm condition. */
unsigned int inalarm:1;
/*! \brief TRUE if TDD in MATE mode */
unsigned int mate:1;
/*! \brief TRUE if we originated the call leg. */
unsigned int outgoing:1;
/* unsigned int overlapdial:1; unused and potentially confusing */
/*!
* \brief TRUE if busy extensions will hear the call-waiting tone
* and can use hook-flash to switch between callers.
* \note Set from the "callwaiting" value read in from chan_dahdi.conf
*/
unsigned int permcallwaiting:1;
/*!
* \brief TRUE if the outgoing caller ID is blocked/restricted/hidden.
* \note Set from the "hidecallerid" value read in from chan_dahdi.conf
*/
unsigned int permhidecallerid:1;
/*!
* \brief TRUE if PRI congestion/busy indications are sent out-of-band.
* \note Set from the "priindication" value read in from chan_dahdi.conf
*/
unsigned int priindication_oob:1;
/*!
* \brief TRUE if PRI B channels are always exclusively selected.
* \note Set from the "priexclusive" value read in from chan_dahdi.conf
*/
unsigned int priexclusive:1;
/*!
* \brief TRUE if we will pulse dial.
* \note Set from the "pulsedial" value read in from chan_dahdi.conf
*/
unsigned int pulse:1;
/*! \brief TRUE if a pulsed digit was detected. (Pulse dial phone detected) */
unsigned int pulsedial:1;
unsigned int restartpending:1; /*!< flag to ensure counted only once for restart */
/*!
* \brief TRUE if caller ID is restricted.
* \note Set but not used. Should be deleted. Redundant with permhidecallerid.
* \note Set from the "restrictcid" value read in from chan_dahdi.conf
*/
unsigned int restrictcid:1;
/*!
* \brief TRUE if three way calling is enabled
* \note Set from the "threewaycalling" value read in from chan_dahdi.conf
*/
unsigned int threewaycalling:1;
/*!
* \brief TRUE if call transfer is enabled
* \note For FXS ports (either direct analog or over T1/E1):
* Support flash-hook call transfer
* \note For digital ports using ISDN PRI protocols:
* Support switch-side transfer (called 2BCT, RLT or other names)
* \note Set from the "transfer" value read in from chan_dahdi.conf
*/
unsigned int transfer:1;
/*!
* \brief TRUE if caller ID is used on this channel.
* \note PRI and SS7 spans will save caller ID from the networking peer.
* \note FXS ports will generate the caller ID spill.
* \note FXO ports will listen for the caller ID spill.
* \note Set from the "usecallerid" value read in from chan_dahdi.conf
*/
unsigned int use_callerid:1;
/*!
* \brief TRUE if we will use the calling presentation setting
* from the Asterisk channel for outgoing calls.
* \note Only applies to PRI and SS7 channels.
* \note Set from the "usecallingpres" value read in from chan_dahdi.conf
*/
unsigned int use_callingpres:1;
/*!
* \brief TRUE if distinctive rings are to be detected.
* \note For FXO lines
* \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
*/
unsigned int usedistinctiveringdetection:1;
/*!
* \brief TRUE if we should use the callerid from incoming call on dahdi transfer.
* \note Set from the "useincomingcalleridondahditransfer" value read in from chan_dahdi.conf
*/
unsigned int dahditrcallerid:1;
/*!
* \brief TRUE if allowed to flash-transfer to busy channels.
* \note Set from the "transfertobusy" value read in from chan_dahdi.conf
*/
unsigned int transfertobusy:1;
/*!
* \brief TRUE if the FXO port monitors for neon type MWI indications from the other end.
* \note Set if the "mwimonitor" value read in contains "neon" from chan_dahdi.conf
*/
unsigned int mwimonitor_neon:1;
/*!
* \brief TRUE if the FXO port monitors for fsk type MWI indications from the other end.
* \note Set if the "mwimonitor" value read in contains "fsk" from chan_dahdi.conf
*/
unsigned int mwimonitor_fsk:1;
/*!
* \brief TRUE if the FXO port monitors for rpas precursor to fsk MWI indications from the other end.
* \note RPAS - Ring Pulse Alert Signal
* \note Set if the "mwimonitor" value read in contains "rpas" from chan_dahdi.conf
*/
unsigned int mwimonitor_rpas:1;
/*! \brief TRUE if an MWI monitor thread is currently active */
unsigned int mwimonitoractive:1;
/*! \brief TRUE if a MWI message sending thread is active */
unsigned int mwisendactive:1;
/*!
* \brief TRUE if channel is out of reset and ready
* \note Set but not used.
*/
unsigned int inservice:1;
/*!
* \brief TRUE if the channel is locally blocked.
* \note Applies to SS7 and MFCR2 channels.
*/
unsigned int locallyblocked:1;
/*!
* \brief TRUE if the channel is remotely blocked.
* \note Applies to SS7 and MFCR2 channels.
*/
unsigned int remotelyblocked:1;
/*!
* \brief TRUE if the channel alarms will be managed also as Span ones
* \note Applies to all channels
*/
unsigned int manages_span_alarms:1;
#if defined(HAVE_PRI)
struct sig_pri_span *pri;
int logicalspan;
#endif
/*!
* \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
* \note Set from the "usesmdi" value read in from chan_dahdi.conf
*/
unsigned int use_smdi:1;
struct mwisend_info mwisend_data;
/*! \brief The SMDI interface to get SMDI messages from. */
struct ast_smdi_interface *smdi_iface;
/*! \brief Distinctive Ring data */
struct dahdi_distRings drings;
/*!
* \brief The configured context for incoming calls.
* \note The "context" string read in from chan_dahdi.conf
*/
char context[AST_MAX_CONTEXT];
/*!
* \brief A description for the channel configuration
* \note The "description" string read in from chan_dahdi.conf
*/
char description[32];
/*!
* \brief Saved context string.
*/
char defcontext[AST_MAX_CONTEXT];
/*! \brief Extension to use in the dialplan. */
char exten[AST_MAX_EXTENSION];
/*!
* \brief Language configured for calls.
* \note The "language" string read in from chan_dahdi.conf
*/
char language[MAX_LANGUAGE];
/*!
* \brief The configured music-on-hold class to use for calls.
* \note The "musicclass" or "mohinterpret" or "musiconhold" string read in from chan_dahdi.conf
*/
char mohinterpret[MAX_MUSICCLASS];
/*!
* \brief Suggested music-on-hold class for peer channel to use for calls.
* \note The "mohsuggest" string read in from chan_dahdi.conf
*/
char mohsuggest[MAX_MUSICCLASS];
char parkinglot[AST_MAX_EXTENSION]; /*!< Parking lot for this channel */
#if defined(HAVE_PRI) || defined(HAVE_SS7)
/*! \brief Automatic Number Identification number (Alternate PRI caller ID number) */
char cid_ani[AST_MAX_EXTENSION];
#endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
/*! \brief Automatic Number Identification code from PRI */
int cid_ani2;
/*! \brief Caller ID number from an incoming call. */
char cid_num[AST_MAX_EXTENSION];
/*!
* \brief Caller ID tag from incoming call
* \note the "cid_tag" string read in from chan_dahdi.conf
*/
char cid_tag[AST_MAX_EXTENSION];
/*! \brief Caller ID Q.931 TON/NPI field values. Set by PRI. Zero otherwise. */
int cid_ton;
/*! \brief Caller ID name from an incoming call. */
char cid_name[AST_MAX_EXTENSION];
/*! \brief Caller ID subaddress from an incoming call. */
char cid_subaddr[AST_MAX_EXTENSION];
char *origcid_num; /*!< malloced original callerid */
char *origcid_name; /*!< malloced original callerid */
/*! \brief Call waiting number. */
char callwait_num[AST_MAX_EXTENSION];
/*! \brief Call waiting name. */
char callwait_name[AST_MAX_EXTENSION];
/*! \brief Redirecting Directory Number Information Service (RDNIS) number */
char rdnis[AST_MAX_EXTENSION];
/*! \brief Dialed Number Identifier */
char dnid[AST_MAX_EXTENSION];
/*!
* \brief Bitmapped groups this belongs to.
* \note The "group" bitmapped group string read in from chan_dahdi.conf
*/
ast_group_t group;
/*! \brief Default call PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW. */
int law_default;
/*! \brief Active PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW */
int law;
int confno; /*!< Our conference */
int confusers; /*!< Who is using our conference */
int propconfno; /*!< Propagated conference number */
/*!
* \brief Bitmapped call groups this belongs to.
* \note The "callgroup" bitmapped group string read in from chan_dahdi.conf
*/
ast_group_t callgroup;
/*!
* \brief Bitmapped pickup groups this belongs to.
* \note The "pickupgroup" bitmapped group string read in from chan_dahdi.conf
*/
ast_group_t pickupgroup;
/*!
* \brief Channel variable list with associated values to set when a channel is created.
* \note The "setvar" strings read in from chan_dahdi.conf
*/
struct ast_variable *vars;
int channel; /*!< Channel Number */
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 or DTMF without warning event */
int dtmfcid_holdoff_state; /*!< State indicator that allows for line to settle before checking for dtmf energy */
struct timeval dtmfcid_delay; /*!< Time value used for allow line to settle */
int callingpres; /*!< The value of calling 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 stop waiting for CID/CW CAS response (In samples) */
int cid_suppress_expire; /*!< How many samples to suppress after a CID spill. */
/*! \brief Analog caller ID waveform sample buffer */
unsigned char *cidspill;
/*! \brief Position in the cidspill buffer to send out next. */
int cidpos;
/*! \brief Length of the cidspill buffer containing samples. */
int cidlen;
/*! \brief Ring timeout timer?? */
int ringt;
/*!
* \brief Ring timeout base.
* \note Value computed indirectly from "ringtimeout" read in from chan_dahdi.conf
*/
int ringt_base;
/*!
* \brief Number of most significant digits/characters to strip from the dialed number.
* \note Feature is deprecated. Use dialplan logic.
* \note The characters are stripped before the PRI TON/NPI prefix
* characters are processed.
*/
int stripmsd;
/*!
* \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
* \note
* After CAS is sent, the call waiting caller id will be sent if the phone
* gives a positive reply.
*/
int callwaitcas;
/*! \brief Number of call waiting rings. */
int callwaitrings;
/*! \brief Echo cancel parameters. */
struct {
struct dahdi_echocanparams head;
struct dahdi_echocanparam params[DAHDI_MAX_ECHOCANPARAMS];
} echocancel;
/*!
* \brief Echo training time. 0 = disabled
* \note Set from the "echotraining" value read in from chan_dahdi.conf
*/
int echotraining;
/*! \brief Filled with 'w'. XXX Purpose?? */
char echorest[20];
/*!
* \brief Number of times to see "busy" tone before hanging up.
* \note Set from the "busycount" value read in from chan_dahdi.conf
*/
int busycount;
/*!
* \brief Busy cadence pattern description.
* \note Set from the "busypattern" value read from chan_dahdi.conf
*/
struct ast_dsp_busy_pattern busy_cadence;
/*!
* \brief Bitmapped call progress detection flags. CALLPROGRESS_xxx values.
* \note Bits set from the "callprogress" and "faxdetect" values read in from chan_dahdi.conf
*/
int callprogress;
/*!
* \brief Number of milliseconds to wait for dialtone.
* \note Set from the "waitfordialtone" value read in from chan_dahdi.conf
*/
int waitfordialtone;
struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
struct timeval flashtime; /*!< Last flash-hook time */
/*! \brief Opaque DSP configuration structure. */
struct ast_dsp *dsp;
/*! \brief DAHDI dial operation command struct for ioctl() call. */
struct dahdi_dialoperation dop;
int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
/*! \brief Second part of SIG_FEATDMF_TA wink operation. */
char finaldial[64];
char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
int amaflags; /*!< AMA Flags */
struct tdd_state *tdd; /*!< TDD flag */
/*! \brief Accumulated call forwarding number. */
char call_forward[AST_MAX_EXTENSION];
/*!
* \brief Voice mailbox location.
* \note Set from the "mailbox" string read in from chan_dahdi.conf
*/
char mailbox[AST_MAX_EXTENSION];
/*! \brief Opaque event subscription parameters for message waiting indication support. */
struct ast_event_sub *mwi_event_sub;
/*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
char dialdest[256];
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI
struct dahdi_vmwi_info mwisend_setting; /*!< Which VMWI methods to use */
unsigned int mwisend_fsk: 1; /*! Variable for enabling FSK MWI handling in chan_dahdi */
unsigned int mwisend_rpas:1; /*! Variable for enabling Ring Pulse Alert before MWI FSK Spill */
#endif
int distinctivering; /*!< Which distinctivering to use */
int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
/*! \brief Holding place for event injected from outside normal operation. */
int fake_event;
/*!
* \brief Minimal time period (ms) between the answer polarity
* switch and hangup polarity switch.
*/
int polarityonanswerdelay;
/*! \brief Start delay time if polarityonanswerdelay is nonzero. */
struct timeval polaritydelaytv;
/*!
* \brief Send caller ID on FXS after this many rings. Set to 1 for US.
* \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
*/
int sendcalleridafter;
/*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
int polarity;
/*! \brief DSP feature flags: DSP_FEATURE_xxx */
int dsp_features;
#if defined(HAVE_SS7)
/*! \brief SS7 control parameters */
struct sig_ss7_linkset *ss7;
#endif /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
struct dahdi_mfcr2 *mfcr2;
openr2_chan_t *r2chan;
openr2_calling_party_category_t mfcr2_recvd_category;
openr2_calling_party_category_t mfcr2_category;
int mfcr2_dnis_index;
int mfcr2_ani_index;
int mfcr2call:1;
int mfcr2_answer_pending:1;
int mfcr2_charge_calls:1;
int mfcr2_allow_collect_calls:1;
int mfcr2_forced_release:1;
int mfcr2_dnis_matched:1;
int mfcr2_call_accepted:1;
int mfcr2_accept_on_offer:1;
int mfcr2_progress_sent:1;
#endif
/*! \brief DTMF digit in progress. 0 when no digit in progress. */
char begindigit;
/*! \brief TRUE if confrence is muted. */
int muting;
void *sig_pvt;
struct ast_cc_config_params *cc_params;
/* DAHDI channel names may differ greatly from the
* string that was provided to an app such as Dial. We
* need to save the original string passed to dahdi_request
* for call completion purposes. This way, we can replicate
* the original dialed string later.
*/
char dialstring[AST_CHANNEL_NAME];
};
#define DATA_EXPORT_DAHDI_PVT(MEMBER) \
MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, locallyblocked, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
MEMBER(dahdi_pvt, description, AST_DATA_STRING) \
MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
#if defined(HAVE_PRI)
static struct dahdi_parms_pseudo {
int buf_no; /*!< Number of buffers */
int buf_policy; /*!< Buffer policy */
int faxbuf_no; /*!< Number of Fax buffers */
int faxbuf_policy; /*!< Fax buffer policy */
} dahdi_pseudo_parms;
#endif /* defined(HAVE_PRI) */
/*! \brief Channel configuration from chan_dahdi.conf .
* This struct is used for parsing the [channels] section of chan_dahdi.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 dahdi_chan_conf is used to configure the
* channel (struct dahdi_pvt)
*
* \see dahdi_chan_init for the default values.
*/
struct dahdi_chan_conf {
struct dahdi_pvt chan;
#ifdef HAVE_PRI
struct dahdi_pri pri;
#endif
#if defined(HAVE_SS7)
struct dahdi_ss7 ss7;
#endif /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
struct dahdi_mfcr2_conf mfcr2;
#endif
struct dahdi_params timing;
int is_sig_auto; /*!< Use channel signalling from DAHDI? */
/*! Continue configuration even if a channel is not there. */
int ignore_failed_channels;
/*!
* \brief The serial port to listen for SMDI data on
* \note Set from the "smdiport" string read in from chan_dahdi.conf
*/
char smdi_port[SMDI_MAX_FILENAME_LEN];
};
/*! returns a new dahdi_chan_conf with default values (by-value) */
static struct dahdi_chan_conf dahdi_chan_conf_default(void)
{
/* recall that if a field is not included here it is initialized
* to 0 or equivalent
*/
struct dahdi_chan_conf conf = {
#ifdef HAVE_PRI
.pri.pri = {
.nsf = PRI_NSF_NONE,
.switchtype = PRI_SWITCH_NI2,
.dialplan = PRI_UNKNOWN + 1,
.localdialplan = PRI_NATIONAL_ISDN + 1,
.nodetype = PRI_CPE,
.qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
#if defined(HAVE_PRI_CCSS)
.cc_ptmp_recall_mode = 1,/* specificRecall */
.cc_qsig_signaling_link_req = 1,/* retain */
.cc_qsig_signaling_link_rsp = 1,/* retain */
#endif /* defined(HAVE_PRI_CCSS) */
.minunused = 2,
.idleext = "",
.idledial = "",
.internationalprefix = "",
.nationalprefix = "",
.localprefix = "",
.privateprefix = "",
.unknownprefix = "",
.resetinterval = -1,
},
#endif
#if defined(HAVE_SS7)
.ss7.ss7 = {
.called_nai = SS7_NAI_NATIONAL,
.calling_nai = SS7_NAI_NATIONAL,
.internationalprefix = "",
.nationalprefix = "",
.subscriberprefix = "",
.unknownprefix = ""
},
#endif /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
.mfcr2 = {
.variant = OR2_VAR_ITU,
.mfback_timeout = -1,
.metering_pulse_timeout = -1,
.max_ani = 10,
.max_dnis = 4,
.get_ani_first = -1,
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
.skip_category_request = -1,
#endif
.call_files = 0,
.allow_collect_calls = 0,
.charge_calls = 1,
.accept_on_offer = 1,
.forced_release = 0,
.double_answer = 0,
.immediate_accept = -1,
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
.dtmf_dialing = -1,
.dtmf_detection = -1,
.dtmf_time_on = OR2_DEFAULT_DTMF_ON,
.dtmf_time_off = OR2_DEFAULT_DTMF_OFF,
#endif
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
.dtmf_end_timeout = -1,
#endif
.logdir = "",
.r2proto_file = "",
.loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
.category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
},
#endif
.chan = {
.context = "default",
.cid_num = "",
.cid_name = "",
.cid_tag = "",
.mohinterpret = "default",
.mohsuggest = "",
.parkinglot = "",
.transfertobusy = 1,
.cid_signalling = CID_SIG_BELL,
.cid_start = CID_START_RING,
.dahditrcallerid = 0,
.use_callerid = 1,
.sig = -1,
.outsigmod = -1,
.cid_rxgain = +5.0,
.tonezone = -1,
.echocancel.head.tap_length = 1,
.busycount = 3,
.accountcode = "",
.mailbox = "",
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI
.mwisend_fsk = 1,
#endif
.polarityonanswerdelay = 600,
.sendcalleridafter = DEFAULT_CIDRINGS,
.buf_policy = DAHDI_POLICY_IMMEDIATE,
.buf_no = numbufs,
.usefaxbuffers = 0,
.cc_params = ast_cc_config_params_init(),
},
.timing = {
.prewinktime = -1,
.preflashtime = -1,
.winktime = -1,
.flashtime = -1,
.starttime = -1,
.rxwinktime = -1,
.rxflashtime = -1,
.debouncetime = -1
},
.is_sig_auto = 1,
.smdi_port = "/dev/ttyS0",
};
return conf;
}
static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
static int dahdi_digit_begin(struct ast_channel *ast, char digit);
static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
static int dahdi_sendtext(struct ast_channel *c, const char *text);
static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout);
static int dahdi_hangup(struct ast_channel *ast);
static int dahdi_answer(struct ast_channel *ast);
static struct ast_frame *dahdi_read(struct ast_channel *ast);
static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
static struct ast_frame *dahdi_exception(struct ast_channel *ast);
static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
static int dahdi_devicestate(void *data);
static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
static struct ast_channel_tech dahdi_tech = {
.type = "DAHDI",
.description = tdesc,
.requester = dahdi_request,
.send_digit_begin = dahdi_digit_begin,
.send_digit_end = dahdi_digit_end,
.send_text = dahdi_sendtext,
.call = dahdi_call,
.hangup = dahdi_hangup,
.answer = dahdi_answer,
.read = dahdi_read,
.write = dahdi_write,
.bridge = dahdi_bridge,
.exception = dahdi_exception,
.indicate = dahdi_indicate,
.fixup = dahdi_fixup,
.setoption = dahdi_setoption,
.queryoption = dahdi_queryoption,
.func_channel_read = dahdi_func_read,
.func_channel_write = dahdi_func_write,
.devicestate = dahdi_devicestate,
.cc_callback = dahdi_cc_callback,
};
#define GET_CHANNEL(p) ((p)->channel)
#define SIG_PRI_LIB_HANDLE_CASES \
SIG_PRI: \
case SIG_BRI: \
case SIG_BRI_PTMP
/*!
* \internal
* \brief Determine if sig_pri handles the signaling.
* \since 1.8
*
* \param signaling Signaling to determine if is for sig_pri.
*
* \return TRUE if the signaling is for sig_pri.
*/
static inline int dahdi_sig_pri_lib_handles(int signaling)
{
int handles;
switch (signaling) {
case SIG_PRI_LIB_HANDLE_CASES:
handles = 1;
break;
default:
handles = 0;
break;
}
return handles;
}
static enum analog_sigtype dahdisig_to_analogsig(int sig)
{
switch (sig) {
case SIG_FXOLS:
return ANALOG_SIG_FXOLS;
case SIG_FXOGS:
return ANALOG_SIG_FXOGS;
case SIG_FXOKS:
return ANALOG_SIG_FXOKS;
case SIG_FXSLS:
return ANALOG_SIG_FXSLS;
case SIG_FXSGS:
return ANALOG_SIG_FXSGS;
case SIG_FXSKS:
return ANALOG_SIG_FXSKS;
case SIG_EMWINK:
return ANALOG_SIG_EMWINK;
case SIG_EM:
return ANALOG_SIG_EM;
case SIG_EM_E1:
return ANALOG_SIG_EM_E1;
case SIG_FEATD:
return ANALOG_SIG_FEATD;
case SIG_FEATDMF:
return ANALOG_SIG_FEATDMF;
case SIG_E911:
return SIG_E911;
case SIG_FGC_CAMA:
return ANALOG_SIG_FGC_CAMA;
case SIG_FGC_CAMAMF:
return ANALOG_SIG_FGC_CAMAMF;
case SIG_FEATB:
return ANALOG_SIG_FEATB;
case SIG_SFWINK:
return ANALOG_SIG_SFWINK;
case SIG_SF:
return ANALOG_SIG_SF;
case SIG_SF_FEATD:
return ANALOG_SIG_SF_FEATD;
case SIG_SF_FEATDMF:
return ANALOG_SIG_SF_FEATDMF;
case SIG_FEATDMF_TA:
return ANALOG_SIG_FEATDMF_TA;
case SIG_SF_FEATB:
return ANALOG_SIG_FEATB;
default:
return -1;
}
}
static int analog_tone_to_dahditone(enum analog_tone tone)
{
switch (tone) {
case ANALOG_TONE_RINGTONE:
return DAHDI_TONE_RINGTONE;
case ANALOG_TONE_STUTTER:
return DAHDI_TONE_STUTTER;
case ANALOG_TONE_CONGESTION:
return DAHDI_TONE_CONGESTION;
case ANALOG_TONE_DIALTONE:
return DAHDI_TONE_DIALTONE;
case ANALOG_TONE_DIALRECALL:
return DAHDI_TONE_DIALRECALL;
case ANALOG_TONE_INFO:
return DAHDI_TONE_INFO;
default:
return -1;
}
}
static int analogsub_to_dahdisub(enum analog_sub analogsub)
{
int index;
switch (analogsub) {
case ANALOG_SUB_REAL:
index = SUB_REAL;
break;
case ANALOG_SUB_CALLWAIT:
index = SUB_CALLWAIT;
break;
case ANALOG_SUB_THREEWAY:
index = SUB_THREEWAY;
break;
default:
ast_log(LOG_ERROR, "Unidentified sub!\n");
index = SUB_REAL;
}
return index;
}
static enum analog_event dahdievent_to_analogevent(int event);
static int bump_gains(struct dahdi_pvt *p);
static int dahdi_setlinear(int dfd, int linear);
static int my_start_cid_detect(void *pvt, int cid_signalling)
{
struct dahdi_pvt *p = pvt;
int index = SUB_REAL;
p->cs = callerid_new(cid_signalling);
if (!p->cs) {
ast_log(LOG_ERROR, "Unable to alloc callerid\n");
return -1;
}
bump_gains(p);
dahdi_setlinear(p->subs[index].dfd, 0);
return 0;
}
static int my_stop_cid_detect(void *pvt)
{
struct dahdi_pvt *p = pvt;
int index = SUB_REAL;
if (p->cs)
callerid_free(p->cs);
dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
return 0;
}
static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout)
{
struct dahdi_pvt *p = pvt;
struct analog_pvt *analog_p = p->sig_pvt;
struct pollfd poller;
char *name, *num;
int index = SUB_REAL;
int res;
unsigned char buf[256];
int flags;
struct ast_format tmpfmt;
poller.fd = p->subs[SUB_REAL].dfd;
poller.events = POLLPRI | POLLIN;
poller.revents = 0;
res = poll(&poller, 1, timeout);
if (poller.revents & POLLPRI) {
*ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd));
return 1;
}
if (poller.revents & POLLIN) {
/*** NOTES ***/
/* Change API: remove cid_signalling from get_callerid, add a new start_cid_detect and stop_cid_detect function
* to enable slin mode and allocate cid detector. get_callerid should be able to be called any number of times until
* either a timeout occurs or CID is detected (returns 0). returning 1 should be event received, and -1 should be
* a failure and die, and returning 2 means no event was received. */
res = read(p->subs[index].dfd, buf, sizeof(buf));
if (res < 0) {
if (errno != ELAST) {
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
callerid_free(p->cs);
return -1;
}
}
if (analog_p->ringt > 0) {
if (!(--analog_p->ringt)) {
/* only return if we timeout from a ring event */
return -1;
}
}
if (p->cid_signalling == CID_SIG_V23_JP) {
res = callerid_feed_jp(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
} else {
res = callerid_feed(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
}
if (res < 0) {
/*
* The previous diagnostic message output likely
* explains why it failed.
*/
ast_log(LOG_WARNING, "Failed to decode CallerID\n");
return -1;
}
if (res == 1) {
callerid_get(p->cs, &name, &num, &flags);
if (name)
ast_copy_string(namebuf, name, ANALOG_MAX_CID);
if (num)
ast_copy_string(numbuf, num, ANALOG_MAX_CID);
ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
return 0;
}
}
*ev = ANALOG_EVENT_NONE;
return 2;
}
static const char *event2str(int event);
static int restore_gains(struct dahdi_pvt *p);
static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
{
unsigned char buf[256];
int distMatches;
int curRingData[RING_PATTERNS];
int receivedRingT;
int counter1;
int counter;
int i;
int res;
int checkaftercid = 0;
struct dahdi_pvt *p = pvt;
struct analog_pvt *analog_p = p->sig_pvt;
if (ringdata == NULL) {
ringdata = curRingData;
} else {
checkaftercid = 1;
}
/* We must have a ring by now, so, if configured, lets try to listen for
* distinctive ringing */
if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
/* Clear the current ring data array so we don't have old data in it. */
for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++)
ringdata[receivedRingT] = 0;
receivedRingT = 0;
if (checkaftercid && distinctiveringaftercid)
ast_verb(3, "Detecting post-CID distinctive ring\n");
/* Check to see if context is what it should be, if not set to be. */
else if (strcmp(p->context,p->defcontext) != 0) {
ast_copy_string(p->context, p->defcontext, sizeof(p->context));
ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
}
for (;;) {
i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
ast_hangup(chan);
return 1;
}
if (i & DAHDI_IOMUX_SIGEVENT) {
res = dahdi_get_event(p->subs[idx].dfd);
if (res == DAHDI_EVENT_NOALARM) {
p->inalarm = 0;
analog_p->inalarm = 0;
}
ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
res = 0;
/* Let us detect distinctive ring */
ringdata[receivedRingT] = analog_p->ringt;
if (analog_p->ringt < analog_p->ringt_base/2)
break;
/* Increment the ringT counter so we can match it against
values in chan_dahdi.conf for distinctive ring */
if (++receivedRingT == RING_PATTERNS)
break;
} else if (i & DAHDI_IOMUX_READ) {
res = read(p->subs[idx].dfd, buf, sizeof(buf));
if (res < 0) {
if (errno != ELAST) {
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
ast_hangup(chan);
return 1;
}
break;
}
if (analog_p->ringt > 0) {
if (!(--analog_p->ringt)) {
res = -1;
break;
}
}
}
}
}
if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
/* this only shows up if you have n of the dring patterns filled in */
ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]);
for (counter = 0; counter < 3; counter++) {
/* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */
distMatches = 0;
/* this only shows up if you have n of the dring patterns filled in */
ast_verb(3, "Checking %d,%d,%d\n",
p->drings.ringnum[counter].ring[0],
p->drings.ringnum[counter].ring[1],
p->drings.ringnum[counter].ring[2]);
for (counter1 = 0; counter1 < 3; counter1++) {
ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
if (p->drings.ringnum[counter].ring[counter1] == -1) {
ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
ringdata[counter1]);
distMatches++;
} else if (ringdata[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
ringdata[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
ast_verb(3, "Ring pattern matched in range: %d to %d\n",
(p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
(p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
distMatches++;
}
}
if (distMatches == 3) {
/* The ring matches, set the context to whatever is for distinctive ring.. */
ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context));
ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context));
ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
break;
}
}
}
/* Restore linear mode (if appropriate) for Caller*ID processing */
dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
restore_gains(p);
return 0;
}
static int my_stop_callwait(void *pvt)
{
struct dahdi_pvt *p = pvt;
p->callwaitingrepeat = 0;
p->cidcwexpire = 0;
p->cid_suppress_expire = 0;
return 0;
}
static int send_callerid(struct dahdi_pvt *p);
static int save_conference(struct dahdi_pvt *p);
static int restore_conference(struct dahdi_pvt *p);
static int my_callwait(void *pvt)
{
struct dahdi_pvt *p = pvt;
struct ast_format tmpfmt;
p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
if (p->cidspill) {
ast_log(LOG_WARNING, "Spill already exists?!?\n");
ast_free(p->cidspill);
}
/*
* SAS: Subscriber Alert Signal, 440Hz for 300ms
* CAS: CPE Alert Signal, 2130Hz * 2750Hz sine waves
*/
if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
return -1;
save_conference(p);
/* Silence */
memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
if (!p->callwaitrings && p->callwaitingcallerid) {
ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
p->callwaitcas = 1;
p->cidlen = 2400 + 680 + READ_SIZE * 4;
} else {
ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
p->callwaitcas = 0;
p->cidlen = 2400 + READ_SIZE * 4;
}
p->cidpos = 0;
send_callerid(p);
return 0;
}
static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
{
struct dahdi_pvt *p = pvt;
struct ast_format tmpfmt;
ast_debug(2, "Starting cid spill\n");
if (p->cidspill) {
ast_log(LOG_WARNING, "cidspill already exists??\n");
ast_free(p->cidspill);
}
if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
if (cwcid == 0) {
p->cidlen = ast_callerid_generate(p->cidspill,
caller->id.name.str,
caller->id.number.str,
ast_format_set(&tmpfmt, AST_LAW(p), 0));
} else {
ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n",
caller->id.name.str, caller->id.number.str);
p->callwaitcas = 0;
p->cidcwexpire = 0;
p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
caller->id.name.str,
caller->id.number.str,
ast_format_set(&tmpfmt, AST_LAW(p), 0));
p->cidlen += READ_SIZE * 4;
}
p->cidpos = 0;
p->cid_suppress_expire = 0;
send_callerid(p);
}
return 0;
}
static int my_dsp_reset_and_flush_digits(void *pvt)
{
struct dahdi_pvt *p = pvt;
if (p->dsp)
ast_dsp_digitreset(p->dsp);
return 0;
}
static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode)
{
struct dahdi_pvt *p = pvt;
if (p->channel == CHAN_PSEUDO)
ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n");
if (mode == ANALOG_DIGITMODE_DTMF) {
/* If we do hardware dtmf, no need for a DSP */
if (p->hardwaredtmf) {
if (p->dsp) {
ast_dsp_free(p->dsp);
p->dsp = NULL;
}
return 0;
}
if (!p->dsp) {
p->dsp = ast_dsp_new();
if (!p->dsp) {
ast_log(LOG_ERROR, "Unable to allocate DSP\n");
return -1;
}
}
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
} else if (mode == ANALOG_DIGITMODE_MF) {
if (!p->dsp) {
p->dsp = ast_dsp_new();
if (!p->dsp) {
ast_log(LOG_ERROR, "Unable to allocate DSP\n");
return -1;
}
}
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
}
return 0;
}
static int dahdi_wink(struct dahdi_pvt *p, int index);
static int my_wink(void *pvt, enum analog_sub sub)
{
struct dahdi_pvt *p = pvt;
int index = analogsub_to_dahdisub(sub);
if (index != SUB_REAL) {
ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n");
}
return dahdi_wink(p, index);
}
static void wakeup_sub(struct dahdi_pvt *p, int a);
static int reset_conf(struct dahdi_pvt *p);
static inline int dahdi_confmute(struct dahdi_pvt *p, int muted);
static void my_handle_dtmf(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
{
struct ast_frame *f = *dest;
struct dahdi_pvt *p = pvt;
int idx = analogsub_to_dahdisub(analog_index);
ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
f->subclass.integer, f->subclass.integer, ast->name);
if (f->subclass.integer == 'f') {
if (f->frametype == AST_FRAME_DTMF_END) {
/* Fax tone -- Handle and return NULL */
if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
/* If faxbuffers are configured, use them for the fax transmission */
if (p->usefaxbuffers && !p->bufferoverrideinuse) {
struct dahdi_bufferinfo bi = {
.txbufpolicy = p->faxbuf_policy,
.bufsize = p->bufsize,
.numbufs = p->faxbuf_no
};
int res;
if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast->name, strerror(errno));
} else {
p->bufferoverrideinuse = 1;
}
}
p->faxhandled = 1;
if (p->dsp) {
p->dsp_features &= ~DSP_FEATURE_FAX_DETECT;
ast_dsp_set_features(p->dsp, p->dsp_features);
ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast->name);
}
if (strcmp(ast->exten, "fax")) {
const char *target_context = S_OR(ast->macrocontext, ast->context);
/* We need to unlock 'ast' here because ast_exists_extension has the
* potential to start autoservice on the channel. Such action is prone
* to deadlock.
*/
ast_mutex_unlock(&p->lock);
ast_channel_unlock(ast);
if (ast_exists_extension(ast, target_context, "fax", 1,
S_COR(ast->caller.id.number.valid, ast->caller.id.number.str, NULL))) {
ast_channel_lock(ast);
ast_mutex_lock(&p->lock);
ast_verb(3, "Redirecting %s to fax extension\n", ast->name);
/* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
if (ast_async_goto(ast, target_context, "fax", 1))
ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
} else {
ast_channel_lock(ast);
ast_mutex_lock(&p->lock);
ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
}
} else {
ast_debug(1, "Already in a fax extension, not redirecting\n");
}
} else {
ast_debug(1, "Fax already handled\n");
}
dahdi_confmute(p, 0);
}
p->subs[idx].f.frametype = AST_FRAME_NULL;
p->subs[idx].f.subclass.integer = 0;
*dest = &p->subs[idx].f;
}
}
static void my_lock_private(void *pvt)
{
struct dahdi_pvt *p = pvt;
ast_mutex_lock(&p->lock);
}
static void my_unlock_private(void *pvt)
{
struct dahdi_pvt *p = pvt;
ast_mutex_unlock(&p->lock);
}
static void my_deadlock_avoidance_private(void *pvt)
{
struct dahdi_pvt *p = pvt;
DEADLOCK_AVOIDANCE(&p->lock);
}
/*!
* \internal
* \brief Post an AMI DAHDI channel association event.
* \since 1.8
*
* \param p DAHDI private pointer
* \param chan Channel associated with the private pointer
*
* \return Nothing
*/
static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *chan)
{
char ch_name[20];
if (p->channel < CHAN_PSEUDO) {
/* No B channel */
snprintf(ch_name, sizeof(ch_name), "no-media (%d)", p->channel);
} else if (p->channel == CHAN_PSEUDO) {
/* Pseudo channel */
strcpy(ch_name, "pseudo");
} else {
/* Real channel */
snprintf(ch_name, sizeof(ch_name), "%d", p->channel);
}
ast_manager_event(chan, EVENT_FLAG_CALL, "DAHDIChannel",
"Channel: %s\r\n"
"Uniqueid: %s\r\n"
"DAHDISpan: %d\r\n"
"DAHDIChannel: %s\r\n",
chan->name,
chan->uniqueid,
p->span,
ch_name);
}
#ifdef HAVE_PRI
/*!
* \internal
* \brief Post an AMI DAHDI channel association event.
* \since 1.8
*
* \param pvt DAHDI private pointer
* \param chan Channel associated with the private pointer
*
* \return Nothing
*/
static void my_ami_channel_event(void *pvt, struct ast_channel *chan)
{
struct dahdi_pvt *p = pvt;
dahdi_ami_channel_event(p, chan);
}
#endif
/* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
* returns the last value of the linear setting
*/
static int my_set_linear_mode(void *pvt, enum analog_sub sub, int linear_mode)
{
struct dahdi_pvt *p = pvt;
int oldval;
int idx = analogsub_to_dahdisub(sub);
dahdi_setlinear(p->subs[idx].dfd, linear_mode);
oldval = p->subs[idx].linear;
p->subs[idx].linear = linear_mode ? 1 : 0;
return oldval;
}
static void my_set_inthreeway(void *pvt, enum analog_sub sub, int inthreeway)
{
struct dahdi_pvt *p = pvt;
int idx = analogsub_to_dahdisub(sub);
p->subs[idx].inthreeway = inthreeway;
}
static int get_alarms(struct dahdi_pvt *p);
static void handle_alarms(struct dahdi_pvt *p, int alms);
static void my_get_and_handle_alarms(void *pvt)
{
int res;
struct dahdi_pvt *p = pvt;
res = get_alarms(p);
handle_alarms(p, res);
}
static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
{
struct dahdi_pvt *p = ast_bridged_channel(chan)->tech_pvt;
if (p)
return p->sig_pvt;
else
return NULL;
}
static int my_get_sub_fd(void *pvt, enum analog_sub sub)
{
struct dahdi_pvt *p = pvt;
int dahdi_sub = analogsub_to_dahdisub(sub);
return p->subs[dahdi_sub].dfd;
}
static void my_set_cadence(void *pvt, int *cidrings, struct ast_channel *ast)
{
struct dahdi_pvt *p = pvt;
/* Choose proper cadence */
if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
*cidrings = cidrings[p->distinctivering - 1];
} else {
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
*cidrings = p->sendcalleridafter;
}
}
static void my_set_alarm(void *pvt, int in_alarm)
{
struct dahdi_pvt *p = pvt;
p->inalarm = in_alarm;
}
static void my_set_dialing(void *pvt, int is_dialing)
{
struct dahdi_pvt *p = pvt;
p->dialing = is_dialing;
}
#if defined(HAVE_PRI) || defined(HAVE_SS7)
static void my_set_digital(void *pvt, int is_digital)
{
struct dahdi_pvt *p = pvt;
p->digital = is_digital;
}
#endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
#if defined(HAVE_SS7)
static void my_set_inservice(void *pvt, int is_inservice)
{
struct dahdi_pvt *p = pvt;
p->inservice = is_inservice;
}
#endif /* defined(HAVE_SS7) */
#if defined(HAVE_SS7)
static void my_set_locallyblocked(void *pvt, int is_blocked)
{
struct dahdi_pvt *p = pvt;
p->locallyblocked = is_blocked;
}
#endif /* defined(HAVE_SS7) */
#if defined(HAVE_SS7)
static void my_set_remotelyblocked(void *pvt, int is_blocked)
{
struct dahdi_pvt *p = pvt;
p->remotelyblocked = is_blocked;
}
#endif /* defined(HAVE_SS7) */
static void my_set_ringtimeout(void *pvt, int ringt)
{
struct dahdi_pvt *p = pvt;
p->ringt = ringt;
}
static void my_set_waitingfordt(void *pvt, struct ast_channel *ast)
{
struct dahdi_pvt *p = pvt;
if (p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp) {
ast_debug(1, "Defer dialing for %dms or dialtone\n", p->waitfordialtone);
gettimeofday(&p->waitingfordt, NULL);
ast_setstate(ast, AST_STATE_OFFHOOK);
}
}
static int my_check_waitingfordt(void *pvt)
{
struct dahdi_pvt *p = pvt;
if (p->waitingfordt.tv_usec) {
return 1;
}
return 0;
}
static void my_set_confirmanswer(void *pvt, int flag)
{
struct dahdi_pvt *p = pvt;
p->confirmanswer = flag;
}
static int my_check_confirmanswer(void *pvt)
{
struct dahdi_pvt *p = pvt;
if (p->confirmanswer) {
return 1;
}
return 0;
}
static void my_set_callwaiting(void *pvt, int callwaiting_enable)
{
struct dahdi_pvt *p = pvt;
p->callwaiting = callwaiting_enable;
}
static void my_cancel_cidspill(void *pvt)
{
struct dahdi_pvt *p = pvt;
ast_free(p->cidspill);
p->cidspill = NULL;
restore_conference(p);
}
static int my_confmute(void *pvt, int mute)
{
struct dahdi_pvt *p = pvt;
return dahdi_confmute(p, mute);
}
static void my_set_pulsedial(void *pvt, int flag)
{
struct dahdi_pvt *p = pvt;
p->pulsedial = flag;
}
static void my_set_new_owner(void *pvt, struct ast_channel *new_owner)
{
struct dahdi_pvt *p = pvt;
p->owner = new_owner;
}
static const char *my_get_orig_dialstring(void *pvt)
{
struct dahdi_pvt *p = pvt;
return p->dialstring;
}
static void my_increase_ss_count(void)
{
ast_mutex_lock(&ss_thread_lock);
ss_thread_count++;
ast_mutex_unlock(&ss_thread_lock);
}
static void my_decrease_ss_count(void)
{
ast_mutex_lock(&ss_thread_lock);
ss_thread_count--;
ast_cond_signal(&ss_thread_complete);
ast_mutex_unlock(&ss_thread_lock);
}
static void my_all_subchannels_hungup(void *pvt)
{
struct dahdi_pvt *p = pvt;
int res, law;
p->faxhandled = 0;
p->didtdd = 0;
if (p->dsp) {
ast_dsp_free(p->dsp);
p->dsp = NULL;
}
p->law = p->law_default;
law = p->law_default;
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
if (res < 0)
ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
#if 1
{
int i;
p->owner = NULL;
/* Cleanup owners here */
for (i = 0; i < 3; i++) {
p->subs[i].owner = NULL;
}
}
#endif
reset_conf(p);
if (num_restart_pending == 0) {
restart_monitor();
}
}
static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index);
static int my_conf_del(void *pvt, enum analog_sub sub)
{
struct dahdi_pvt *p = pvt;
int x = analogsub_to_dahdisub(sub);
return conf_del(p, &p->subs[x], x);
}
static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel);
static int my_conf_add(void *pvt, enum analog_sub sub)
{
struct dahdi_pvt *p = pvt;
int x = analogsub_to_dahdisub(sub);
return conf_add(p, &p->subs[x], x, 0);
}
static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out);
static int my_complete_conference_update(void *pvt, int needconference)
{
struct dahdi_pvt *p = pvt;
int needconf = needconference;
int x;
int useslavenative;
struct dahdi_pvt *slave = NULL;
useslavenative = isslavenative(p, &slave);
/* If we have a slave, add him to our conference now. or DAX
if this is slave native */
for (x = 0; x < MAX_SLAVES; x++) {
if (p->slaves[x]) {
if (useslavenative)
conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
else {
conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
needconf++;
}
}
}
/* If we're supposed to be in there, do so now */
if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
if (useslavenative)
conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
else {
conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
needconf++;
}
}
/* If we have a master, add ourselves to his conference */
if (p->master) {
if (isslavenative(p->master, NULL)) {
conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
} else {
conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
}
}
if (!needconf) {
/* Nobody is left (or should be left) in our conference.
Kill it. */
p->confno = -1;
}
return 0;
}
static int check_for_conference(struct dahdi_pvt *p);
static int my_check_for_conference(void *pvt)
{
struct dahdi_pvt *p = pvt;
return check_for_conference(p);
}
static void my_swap_subchannels(void *pvt, enum analog_sub a, struct ast_channel *ast_a, enum analog_sub b, struct ast_channel *ast_b)
{
struct dahdi_pvt *p = pvt;
int da, db;
int tchan;
int tinthreeway;
da = analogsub_to_dahdisub(a);
db = analogsub_to_dahdisub(b);
tchan = p->subs[da].chan;
p->subs[da].chan = p->subs[db].chan;
p->subs[db].chan = tchan;
tinthreeway = p->subs[da].inthreeway;
p->subs[da].inthreeway = p->subs[db].inthreeway;
p->subs[db].inthreeway = tinthreeway;
p->subs[da].owner = ast_a;
p->subs[db].owner = ast_b;
if (ast_a)
ast_channel_set_fd(ast_a, 0, p->subs[da].dfd);
if (ast_b)
ast_channel_set_fd(ast_b, 0, p->subs[db].dfd);
wakeup_sub(p, a);
wakeup_sub(p, b);
return;
}
static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid);
static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
{
struct dahdi_pvt *p = pvt;
int dsub = analogsub_to_dahdisub(sub);
return dahdi_new(p, state, startpbx, dsub, 0, requestor ? requestor->linkedid : "");
}
#if defined(HAVE_PRI) || defined(HAVE_SS7)
static int dahdi_setlaw(int dfd, int law)
{
int res;
res = ioctl(dfd, DAHDI_SETLAW, &law);
if (res)
return res;
return 0;
}
#endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
#if defined(HAVE_PRI)
static struct ast_channel *my_new_pri_ast_channel(void *pvt, int state, enum sig_pri_law law, char *exten, const struct ast_channel *requestor)
{
struct dahdi_pvt *p = pvt;
int audio;
int newlaw = -1;
switch (p->sig) {
case SIG_PRI_LIB_HANDLE_CASES:
if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) {
/* PRI nobch pseudo channel. Does not handle ioctl(DAHDI_AUDIOMODE) */
break;
}
/* Fall through */
default:
/* Set to audio mode at this point */
audio = 1;
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) {
ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
p->channel, audio, strerror(errno));
}
break;
}
if (law != SIG_PRI_DEFLAW) {
dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
}
ast_copy_string(p->exten, exten, sizeof(p->exten));
switch (law) {
case SIG_PRI_DEFLAW:
newlaw = 0;
break;
case SIG_PRI_ALAW:
newlaw = DAHDI_LAW_ALAW;
break;
case SIG_PRI_ULAW:
newlaw = DAHDI_LAW_MULAW;
break;
}
return dahdi_new(p, state, 0, SUB_REAL, newlaw, requestor ? requestor->linkedid : "");
}
#endif /* defined(HAVE_PRI) */
static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law);
#if defined(HAVE_PRI)
/*!
* \internal
* \brief Open the PRI channel media path.
* \since 1.8
*
* \param p Channel private control structure.
*
* \return Nothing
*/
static void my_pri_open_media(void *p)
{
struct dahdi_pvt *pvt = p;
int res;
int dfd;
int set_val;
dfd = pvt->subs[SUB_REAL].dfd;
/* Open the media path. */
set_val = 1;
res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val);
if (res < 0) {
ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n",
pvt->channel, strerror(errno));
}
/* Set correct companding law for this call. */
res = dahdi_setlaw(dfd, pvt->law);
if (res < 0) {
ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel);
}
/* Set correct gain for this call. */
if (pvt->digital) {
res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law);
} else {
res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc,
pvt->law);
}
if (res < 0) {
ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel);
}
if (pvt->dsp_features && pvt->dsp) {
ast_dsp_set_features(pvt->dsp, pvt->dsp_features);
pvt->dsp_features = 0;
}
}
#endif /* defined(HAVE_PRI) */
static int unalloc_sub(struct dahdi_pvt *p, int x);
static int my_unallocate_sub(void *pvt, enum analog_sub analogsub)
{
struct dahdi_pvt *p = pvt;
return unalloc_sub(p, analogsub_to_dahdisub(analogsub));
}
static int alloc_sub(struct dahdi_pvt *p, int x);
static int my_allocate_sub(void *pvt, enum analog_sub analogsub)
{
struct dahdi_pvt *p = pvt;
return alloc_sub(p, analogsub_to_dahdisub(analogsub));
}
static int has_voicemail(struct dahdi_pvt *p);
static int my_has_voicemail(void *pvt)
{
struct dahdi_pvt *p = pvt;
return has_voicemail(p);
}
static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone)
{
struct dahdi_pvt *p = pvt;
int index;
index = analogsub_to_dahdisub(sub);
return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone));
}
static enum analog_event dahdievent_to_analogevent(int event)
{
enum analog_event res;
switch (event) {
case DAHDI_EVENT_ONHOOK:
res = ANALOG_EVENT_ONHOOK;
break;
case DAHDI_EVENT_RINGOFFHOOK:
res = ANALOG_EVENT_RINGOFFHOOK;
break;
case DAHDI_EVENT_WINKFLASH:
res = ANALOG_EVENT_WINKFLASH;
break;
case DAHDI_EVENT_ALARM:
res = ANALOG_EVENT_ALARM;
break;
case DAHDI_EVENT_NOALARM:
res = ANALOG_EVENT_NOALARM;
break;
case DAHDI_EVENT_DIALCOMPLETE:
res = ANALOG_EVENT_DIALCOMPLETE;
break;
case DAHDI_EVENT_RINGERON:
res = ANALOG_EVENT_RINGERON;
break;
case DAHDI_EVENT_RINGEROFF:
res = ANALOG_EVENT_RINGEROFF;
break;
case DAHDI_EVENT_HOOKCOMPLETE:
res = ANALOG_EVENT_HOOKCOMPLETE;
break;
case DAHDI_EVENT_PULSE_START:
res = ANALOG_EVENT_PULSE_START;
break;
case DAHDI_EVENT_POLARITY:
res = ANALOG_EVENT_POLARITY;
break;
case DAHDI_EVENT_RINGBEGIN:
res = ANALOG_EVENT_RINGBEGIN;
break;
case DAHDI_EVENT_EC_DISABLED:
res = ANALOG_EVENT_EC_DISABLED;
break;
case DAHDI_EVENT_REMOVED:
res = ANALOG_EVENT_REMOVED;
break;
case DAHDI_EVENT_NEONMWI_ACTIVE:
res = ANALOG_EVENT_NEONMWI_ACTIVE;
break;
case DAHDI_EVENT_NEONMWI_INACTIVE:
res = ANALOG_EVENT_NEONMWI_INACTIVE;
break;
#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
case DAHDI_EVENT_TX_CED_DETECTED:
res = ANALOG_EVENT_TX_CED_DETECTED;
break;
case DAHDI_EVENT_RX_CED_DETECTED:
res = ANALOG_EVENT_RX_CED_DETECTED;
break;
case DAHDI_EVENT_EC_NLP_DISABLED:
res = ANALOG_EVENT_EC_NLP_DISABLED;
break;
case DAHDI_EVENT_EC_NLP_ENABLED:
res = ANALOG_EVENT_EC_NLP_ENABLED;
break;
#endif
case DAHDI_EVENT_PULSEDIGIT:
res = ANALOG_EVENT_PULSEDIGIT;
break;
case DAHDI_EVENT_DTMFDOWN:
res = ANALOG_EVENT_DTMFDOWN;
break;
case DAHDI_EVENT_DTMFUP:
res = ANALOG_EVENT_DTMFUP;
break;
default:
switch(event & 0xFFFF0000) {
case DAHDI_EVENT_PULSEDIGIT:
case DAHDI_EVENT_DTMFDOWN:
case DAHDI_EVENT_DTMFUP:
/* The event includes a digit number in the low word.
* Converting it to a 'enum analog_event' would remove
* that information. Thus it is returned as-is.
*/
return event;
}
res = ANALOG_EVENT_ERROR;
break;
}
return res;
}
static inline int dahdi_wait_event(int fd);
static int my_wait_event(void *pvt)
{
struct dahdi_pvt *p = pvt;
return dahdi_wait_event(p->subs[SUB_REAL].dfd);
}
static int my_get_event(void *pvt)
{
struct dahdi_pvt *p = pvt;
int res;
if (p->fake_event) {
res = p->fake_event;
p->fake_event = 0;
} else
res = dahdi_get_event(p->subs[SUB_REAL].dfd);
return dahdievent_to_analogevent(res);
}
static