2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2008, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief DAHDI for Pseudo TDM
23 * \author Mark Spencer <markster@digium.com>
25 * Connects to the DAHDI telephony library as well as
26 * libpri. Libpri is optional and needed only if you are
27 * going to use ISDN connections.
29 * You need to install libraries before you attempt to compile
30 * and install the DAHDI channel.
33 * \arg \ref Config_dahdi
35 * \ingroup channel_drivers
37 * \todo Deprecate the "musiconhold" configuration option post 1.4
41 <use type="module">res_smdi</use>
42 <depend>dahdi</depend>
43 <depend>tonezone</depend>
44 <use type="external">pri</use>
45 <use type="external">ss7</use>
46 <use type="external">openr2</use>
47 <support_level>core</support_level>
52 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
54 #if defined(__NetBSD__) || defined(__FreeBSD__)
58 #include <sys/signal.h>
60 #include <sys/ioctl.h>
65 #include <dahdi/user.h>
66 #include <dahdi/tonezone.h>
67 #include "sig_analog.h"
68 /* Analog signaling is currently still present in chan_dahdi for use with
69 * radio. Sig_analog does not currently handle any radio operations. If
70 * radio only uses analog signaling, then the radio handling logic could
71 * be placed in sig_analog and the duplicated code could be removed.
80 #endif /* defined(HAVE_SS7) */
83 /* put this here until sig_mfcr2 comes along */
84 #define SIG_MFCR2_MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
88 #include "asterisk/lock.h"
89 #include "asterisk/channel.h"
90 #include "asterisk/config.h"
91 #include "asterisk/module.h"
92 #include "asterisk/pbx.h"
93 #include "asterisk/file.h"
94 #include "asterisk/ulaw.h"
95 #include "asterisk/alaw.h"
96 #include "asterisk/callerid.h"
97 #include "asterisk/adsi.h"
98 #include "asterisk/cli.h"
99 #include "asterisk/cdr.h"
100 #include "asterisk/cel.h"
101 #include "asterisk/features.h"
102 #include "asterisk/musiconhold.h"
103 #include "asterisk/say.h"
104 #include "asterisk/tdd.h"
105 #include "asterisk/app.h"
106 #include "asterisk/dsp.h"
107 #include "asterisk/astdb.h"
108 #include "asterisk/manager.h"
109 #include "asterisk/causes.h"
110 #include "asterisk/term.h"
111 #include "asterisk/utils.h"
112 #include "asterisk/transcap.h"
113 #include "asterisk/stringfields.h"
114 #include "asterisk/abstract_jb.h"
115 #include "asterisk/smdi.h"
116 #include "asterisk/astobj.h"
117 #include "asterisk/event.h"
118 #include "asterisk/devicestate.h"
119 #include "asterisk/paths.h"
120 #include "asterisk/ccss.h"
121 #include "asterisk/data.h"
124 <application name="DAHDISendKeypadFacility" language="en_US">
126 Send digits out of band over a PRI.
129 <parameter name="digits" required="true" />
132 <para>This application will send the given string of digits in a Keypad
133 Facility IE over the current channel.</para>
136 <application name="DAHDISendCallreroutingFacility" language="en_US">
138 Send an ISDN call rerouting/deflection facility message.
141 <parameter name="destination" required="true">
142 <para>Destination number.</para>
144 <parameter name="original">
145 <para>Original called number.</para>
147 <parameter name="reason">
148 <para>Diversion reason, if not specified defaults to <literal>unknown</literal></para>
152 <para>This application will send an ISDN switch specific call
153 rerouting/deflection facility message over the current channel.
154 Supported switches depend upon the version of libpri in use.</para>
157 <application name="DAHDIAcceptR2Call" language="en_US">
159 Accept an R2 call if its not already accepted (you still need to answer it)
162 <parameter name="charge" required="true">
163 <para>Yes or No.</para>
164 <para>Whether you want to accept the call with charge or without charge.</para>
168 <para>This application will Accept the R2 call either with charge or no charge.</para>
171 <manager name="DAHDITransfer" language="en_US">
173 Transfer DAHDI Channel.
176 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
177 <parameter name="DAHDIChannel" required="true">
178 <para>DAHDI channel number to transfer.</para>
182 <para>Simulate a flash hook event by the user connected to the channel.</para>
183 <note><para>Valid only for analog channels.</para></note>
186 <manager name="DAHDIHangup" language="en_US">
188 Hangup DAHDI Channel.
191 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
192 <parameter name="DAHDIChannel" required="true">
193 <para>DAHDI channel number to hangup.</para>
197 <para>Simulate an on-hook event by the user connected to the channel.</para>
198 <note><para>Valid only for analog channels.</para></note>
201 <manager name="DAHDIDialOffhook" language="en_US">
203 Dial over DAHDI channel while offhook.
206 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
207 <parameter name="DAHDIChannel" required="true">
208 <para>DAHDI channel number to dial digits.</para>
210 <parameter name="Number" required="true">
211 <para>Digits to dial.</para>
215 <para>Generate DTMF control frames to the bridged peer.</para>
218 <manager name="DAHDIDNDon" language="en_US">
220 Toggle DAHDI channel Do Not Disturb status ON.
223 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
224 <parameter name="DAHDIChannel" required="true">
225 <para>DAHDI channel number to set DND on.</para>
229 <para>Equivalent to the CLI command "dahdi set dnd <variable>channel</variable> on".</para>
230 <note><para>Feature only supported by analog channels.</para></note>
233 <manager name="DAHDIDNDoff" language="en_US">
235 Toggle DAHDI channel Do Not Disturb status OFF.
238 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
239 <parameter name="DAHDIChannel" required="true">
240 <para>DAHDI channel number to set DND off.</para>
244 <para>Equivalent to the CLI command "dahdi set dnd <variable>channel</variable> off".</para>
245 <note><para>Feature only supported by analog channels.</para></note>
248 <manager name="DAHDIShowChannels" language="en_US">
250 Show status of DAHDI channels.
253 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
254 <parameter name="DAHDIChannel">
255 <para>Specify the specific channel number to show. Show all channels if zero or not present.</para>
259 <para>Similar to the CLI command "dahdi show channels".</para>
262 <manager name="DAHDIRestart" language="en_US">
264 Fully Restart DAHDI channels (terminates calls).
267 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
270 <para>Equivalent to the CLI command "dahdi restart".</para>
273 <manager name="PRIShowSpans" language="en_US">
275 Show status of PRI spans.
278 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
279 <parameter name="Span">
280 <para>Specify the specific span to show. Show all spans if zero or not present.</para>
284 <para>Similar to the CLI command "pri show spans".</para>
289 #define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
291 static const char * const lbostr[] = {
292 "0 db (CSU)/0-133 feet (DSX-1)",
293 "133-266 feet (DSX-1)",
294 "266-399 feet (DSX-1)",
295 "399-533 feet (DSX-1)",
296 "533-655 feet (DSX-1)",
302 /*! Global jitterbuffer configuration - by default, jb is disabled
303 * \note Values shown here match the defaults shown in chan_dahdi.conf.sample */
304 static struct ast_jb_conf default_jbconf =
308 .resync_threshold = 1000,
312 static struct ast_jb_conf global_jbconf;
315 * \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
316 * the user hangs up to reset the state machine so ring works properly.
317 * This is used to be able to support kewlstart by putting the zhone in
318 * groundstart mode since their forward disconnect supervision is entirely
319 * broken even though their documentation says it isn't and their support
320 * is entirely unwilling to provide any assistance with their channel banks
321 * even though their web site says they support their products for life.
323 /* #define ZHONE_HACK */
325 /*! \brief Typically, how many rings before we should send Caller*ID */
326 #define DEFAULT_CIDRINGS 1
328 #define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
331 /*! \brief Signaling types that need to use MF detection should be placed in this macro */
332 #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))
334 static const char tdesc[] = "DAHDI Telephony Driver"
335 #if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2)
337 #if defined(HAVE_PRI)
339 #endif /* defined(HAVE_PRI) */
340 #if defined(HAVE_SS7)
341 #if defined(HAVE_PRI)
343 #endif /* defined(HAVE_PRI) */
345 #endif /* defined(HAVE_SS7) */
346 #if defined(HAVE_OPENR2)
347 #if defined(HAVE_PRI) || defined(HAVE_SS7)
349 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
351 #endif /* defined(HAVE_OPENR2) */
352 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) */
355 static const char config[] = "chan_dahdi.conf";
357 #define SIG_EM DAHDI_SIG_EM
358 #define SIG_EMWINK (0x0100000 | DAHDI_SIG_EM)
359 #define SIG_FEATD (0x0200000 | DAHDI_SIG_EM)
360 #define SIG_FEATDMF (0x0400000 | DAHDI_SIG_EM)
361 #define SIG_FEATB (0x0800000 | DAHDI_SIG_EM)
362 #define SIG_E911 (0x1000000 | DAHDI_SIG_EM)
363 #define SIG_FEATDMF_TA (0x2000000 | DAHDI_SIG_EM)
364 #define SIG_FGC_CAMA (0x4000000 | DAHDI_SIG_EM)
365 #define SIG_FGC_CAMAMF (0x8000000 | DAHDI_SIG_EM)
366 #define SIG_FXSLS DAHDI_SIG_FXSLS
367 #define SIG_FXSGS DAHDI_SIG_FXSGS
368 #define SIG_FXSKS DAHDI_SIG_FXSKS
369 #define SIG_FXOLS DAHDI_SIG_FXOLS
370 #define SIG_FXOGS DAHDI_SIG_FXOGS
371 #define SIG_FXOKS DAHDI_SIG_FXOKS
372 #define SIG_PRI DAHDI_SIG_CLEAR
373 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
374 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
375 #define SIG_SS7 (0x1000000 | DAHDI_SIG_CLEAR)
376 #define SIG_MFCR2 DAHDI_SIG_CAS
377 #define SIG_SF DAHDI_SIG_SF
378 #define SIG_SFWINK (0x0100000 | DAHDI_SIG_SF)
379 #define SIG_SF_FEATD (0x0200000 | DAHDI_SIG_SF)
380 #define SIG_SF_FEATDMF (0x0400000 | DAHDI_SIG_SF)
381 #define SIG_SF_FEATB (0x0800000 | DAHDI_SIG_SF)
382 #define SIG_EM_E1 DAHDI_SIG_EM_E1
385 #define NUM_SPANS DAHDI_MAX_SPANS
390 #define CHAN_PSEUDO -2
392 #define CALLPROGRESS_PROGRESS 1
393 #define CALLPROGRESS_FAX_OUTGOING 2
394 #define CALLPROGRESS_FAX_INCOMING 4
395 #define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
397 #define NUM_CADENCE_MAX 25
398 static int num_cadence = 4;
399 static int user_has_defined_cadences = 0;
401 static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = {
402 { { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
403 { { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
404 { { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
405 { { 1000, 500, 2500, 5000 } }, /*!< Long ring */
408 /*! \brief cidrings says in which pause to transmit the cid information, where the first pause
409 * is 1, the second pause is 2 and so on.
412 static int cidrings[NUM_CADENCE_MAX] = {
413 2, /*!< Right after first long ring */
414 4, /*!< Right after long part */
415 3, /*!< After third chirp */
416 2, /*!< Second spell */
419 /* ETSI EN300 659-1 specifies the ring pulse between 200 and 300 mS */
420 static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}};
422 #define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
423 (p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
425 #define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
426 #define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
428 static char defaultcic[64] = "";
429 static char defaultozz[64] = "";
431 /*! Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled */
432 static char mwimonitornotify[PATH_MAX] = "";
433 #ifndef HAVE_DAHDI_LINEREVERSE_VMWI
434 static int mwisend_rpas = 0;
437 static char progzone[10] = "";
439 static int usedistinctiveringdetection = 0;
440 static int distinctiveringaftercid = 0;
442 static int numbufs = 4;
444 static int mwilevel = 512;
445 static int dtmfcid_level = 256;
447 #define REPORT_CHANNEL_ALARMS 1
448 #define REPORT_SPAN_ALARMS 2
449 static int report_alarms = REPORT_CHANNEL_ALARMS;
452 static int pridebugfd = -1;
453 static char pridebugfilename[1024] = "";
456 /*! \brief Wait up to 16 seconds for first digit (FXO logic) */
457 static int firstdigittimeout = 16000;
459 /*! \brief How long to wait for following digits (FXO logic) */
460 static int gendigittimeout = 8000;
462 /*! \brief How long to wait for an extra digit, if there is an ambiguous match */
463 static int matchdigittimeout = 3000;
465 /*! \brief Protect the interface list (of dahdi_pvt's) */
466 AST_MUTEX_DEFINE_STATIC(iflock);
469 static int ifcount = 0;
472 AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
475 /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
476 when it's doing something critical. */
477 AST_MUTEX_DEFINE_STATIC(monlock);
479 /*! \brief This is the thread for the monitor which checks for input on the channels
480 which are not currently in use. */
481 static pthread_t monitor_thread = AST_PTHREADT_NULL;
482 static ast_cond_t ss_thread_complete;
483 AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
484 AST_MUTEX_DEFINE_STATIC(restart_lock);
485 static int ss_thread_count = 0;
486 static int num_restart_pending = 0;
488 static int restart_monitor(void);
490 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);
492 static int dahdi_sendtext(struct ast_channel *c, const char *text);
494 static void mwi_event_cb(const struct ast_event *event, void *userdata)
496 /* This module does not handle MWI in an event-based manner. However, it
497 * subscribes to MWI for each mailbox that is configured so that the core
498 * knows that we care about it. Then, chan_dahdi will get the MWI from the
499 * event cache instead of checking the mailbox directly. */
502 /*! \brief Avoid the silly dahdi_getevent which ignores a bunch of events */
503 static inline int dahdi_get_event(int fd)
506 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
511 /*! \brief Avoid the silly dahdi_waitevent which ignores a bunch of events */
512 static inline int dahdi_wait_event(int fd)
515 i = DAHDI_IOMUX_SIGEVENT;
516 if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
518 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
523 /*! Chunk size to read -- we use 20ms chunks to make things happy. */
524 #define READ_SIZE 160
526 #define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
527 #define MASK_INUSE (1 << 1) /*!< Channel currently in use */
529 #define CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) /*!< 300 ms */
530 #define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
531 #define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) /*!< 100 ms */
532 #define CIDCW_EXPIRE_SAMPLES ((500 * 8) / READ_SIZE) /*!< 500 ms */
533 #define MIN_MS_SINCE_FLASH ((2000) ) /*!< 2000 ms */
534 #define DEFAULT_RINGT ((8000 * 8) / READ_SIZE) /*!< 8,000 ms */
539 * \brief Configured ring timeout base.
540 * \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
542 static int ringt_base = DEFAULT_RINGT;
544 #if defined(HAVE_SS7)
547 struct sig_ss7_linkset ss7;
550 static struct dahdi_ss7 linksets[NUM_SPANS];
552 static int cur_ss7type = -1;
553 static int cur_linkset = -1;
554 static int cur_pointcode = -1;
555 static int cur_cicbeginswith = -1;
556 static int cur_adjpointcode = -1;
557 static int cur_networkindicator = -1;
558 static int cur_defaultdpc = -1;
559 #endif /* defined(HAVE_SS7) */
563 pthread_t r2master; /*!< Thread of master */
564 openr2_context_t *protocol_context; /*!< OpenR2 context handle */
565 struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
566 int numchans; /*!< Number of channels in this R2 block */
567 int monitored_count; /*!< Number of channels being monitored */
570 struct dahdi_mfcr2_conf {
571 openr2_variant_t variant;
573 int metering_pulse_timeout;
576 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
580 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
581 int dtmf_end_timeout;
583 signed int get_ani_first:2;
584 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
585 signed int skip_category_request:2;
587 unsigned int call_files:1;
588 unsigned int allow_collect_calls:1;
589 unsigned int charge_calls:1;
590 unsigned int accept_on_offer:1;
591 unsigned int forced_release:1;
592 unsigned int double_answer:1;
593 signed int immediate_accept:2;
594 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
595 signed int dtmf_dialing:2;
596 signed int dtmf_detection:2;
598 char logdir[OR2_MAX_PATH];
599 char r2proto_file[OR2_MAX_PATH];
600 openr2_log_level_t loglevel;
601 openr2_calling_party_category_t category;
604 /* malloc'd array of malloc'd r2links */
605 static struct dahdi_mfcr2 **r2links;
606 /* how many r2links have been malloc'd */
607 static int r2links_count = 0;
609 #endif /* HAVE_OPENR2 */
614 int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
615 int mastertrunkgroup; /*!< What trunk group is our master */
616 int prilogicalspan; /*!< Logical span number within trunk group */
617 struct sig_pri_span pri;
620 static struct dahdi_pri pris[NUM_SPANS];
622 #if defined(HAVE_PRI_CCSS)
623 /*! DAHDI PRI CCSS agent and monitor type name. */
624 static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
625 #endif /* defined(HAVE_PRI_CCSS) */
628 /*! Shut up the compiler */
632 #define SUB_REAL 0 /*!< Active call */
633 #define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
634 #define SUB_THREEWAY 2 /*!< Three-way call */
636 /* Polarity states */
637 #define POLARITY_IDLE 0
638 #define POLARITY_REV 1
641 struct distRingData {
645 struct ringContextData {
646 char contextData[AST_MAX_CONTEXT];
648 struct dahdi_distRings {
649 struct distRingData ringnum[3];
650 struct ringContextData ringContext[3];
653 static const char * const subnames[] = {
659 struct dahdi_subchannel {
661 struct ast_channel *owner;
663 short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
664 struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
665 unsigned int needringing:1;
666 unsigned int needbusy:1;
667 unsigned int needcongestion:1;
668 unsigned int needanswer:1;
669 unsigned int needflash:1;
670 unsigned int needhold:1;
671 unsigned int needunhold:1;
672 unsigned int linear:1;
673 unsigned int inthreeway:1;
674 struct dahdi_confinfo curconf;
677 #define CONF_USER_REAL (1 << 0)
678 #define CONF_USER_THIRDCALL (1 << 1)
682 /* States for sending MWI message
683 * First three states are required for send Ring Pulse Alert Signal
695 struct mwisend_info {
696 struct timeval pause;
697 mwisend_states mwisend_current;
700 /*! Specify the lists dahdi_pvt can be put in. */
702 DAHDI_IFLIST_NONE, /*!< The dahdi_pvt is not in any list. */
703 DAHDI_IFLIST_MAIN, /*!< The dahdi_pvt is in the main interface list */
704 #if defined(HAVE_PRI)
705 DAHDI_IFLIST_NO_B_CHAN, /*!< The dahdi_pvt is in a no B channel interface list */
706 #endif /* defined(HAVE_PRI) */
710 ast_mutex_t lock; /*!< Channel private lock. */
711 struct callerid_state *cs;
712 struct ast_channel *owner; /*!< Our current active owner (if applicable) */
713 /*!< Up to three channels can be associated with this call */
715 struct dahdi_subchannel sub_unused; /*!< Just a safety precaution */
716 struct dahdi_subchannel subs[3]; /*!< Sub-channels */
717 struct dahdi_confinfo saveconf; /*!< Saved conference info */
719 struct dahdi_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
720 struct dahdi_pvt *master; /*!< Master to us (we follow their conferencing) */
721 int inconference; /*!< If our real should be in the conference */
723 int bufsize; /*!< Size of the buffers */
724 int buf_no; /*!< Number of buffers */
725 int buf_policy; /*!< Buffer policy */
726 int faxbuf_no; /*!< Number of Fax buffers */
727 int faxbuf_policy; /*!< Fax buffer policy */
728 int sig; /*!< Signalling style */
730 * \brief Nonzero if the signaling type is sent over a radio.
731 * \note Set to a couple of nonzero values but it is only tested like a boolean.
734 int outsigmod; /*!< Outbound Signalling style (modifier) */
735 int oprmode; /*!< "Operator Services" mode */
736 struct dahdi_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
737 /*! \brief Amount of gain to increase during caller id */
739 /*! \brief Rx gain set by chan_dahdi.conf */
741 /*! \brief Tx gain set by chan_dahdi.conf */
744 float txdrc; /*!< Dynamic Range Compression factor. a number between 1 and 6ish */
747 int tonezone; /*!< tone zone for this chan, or -1 for default */
748 enum DAHDI_IFLIST which_iflist; /*!< Which interface list is this structure listed? */
749 struct dahdi_pvt *next; /*!< Next channel in list */
750 struct dahdi_pvt *prev; /*!< Prev channel in list */
755 * \brief TRUE if ADSI (Analog Display Services Interface) available
756 * \note Set from the "adsi" value read in from chan_dahdi.conf
760 * \brief TRUE if we can use a polarity reversal to mark when an outgoing
761 * call is answered by the remote party.
762 * \note Set from the "answeronpolarityswitch" value read in from chan_dahdi.conf
764 unsigned int answeronpolarityswitch:1;
766 * \brief TRUE if busy detection is enabled.
767 * (Listens for the beep-beep busy pattern.)
768 * \note Set from the "busydetect" value read in from chan_dahdi.conf
770 unsigned int busydetect:1;
772 * \brief TRUE if call return is enabled.
773 * (*69, if your dialplan doesn't catch this first)
774 * \note Set from the "callreturn" value read in from chan_dahdi.conf
776 unsigned int callreturn:1;
778 * \brief TRUE if busy extensions will hear the call-waiting tone
779 * and can use hook-flash to switch between callers.
780 * \note Can be disabled by dialing *70.
781 * \note Initialized with the "callwaiting" value read in from chan_dahdi.conf
783 unsigned int callwaiting:1;
785 * \brief TRUE if send caller ID for Call Waiting
786 * \note Set from the "callwaitingcallerid" value read in from chan_dahdi.conf
788 unsigned int callwaitingcallerid:1;
790 * \brief TRUE if support for call forwarding enabled.
791 * Dial *72 to enable call forwarding.
792 * Dial *73 to disable call forwarding.
793 * \note Set from the "cancallforward" value read in from chan_dahdi.conf
795 unsigned int cancallforward:1;
797 * \brief TRUE if support for call parking is enabled.
798 * \note Set from the "canpark" value read in from chan_dahdi.conf
800 unsigned int canpark:1;
801 /*! \brief TRUE if to wait for a DTMF digit to confirm answer */
802 unsigned int confirmanswer:1;
804 * \brief TRUE if the channel is to be destroyed on hangup.
805 * (Used by pseudo channels.)
807 unsigned int destroy:1;
808 unsigned int didtdd:1; /*!< flag to say its done it once */
809 /*! \brief TRUE if analog type line dialed no digits in Dial() */
810 unsigned int dialednone:1;
812 * \brief TRUE if in the process of dialing digits or sending something.
813 * \note This is used as a receive squelch for ISDN until connected.
815 unsigned int dialing:1;
816 /*! \brief TRUE if the transfer capability of the call is digital. */
817 unsigned int digital:1;
818 /*! \brief TRUE if Do-Not-Disturb is enabled, present only for non sig_analog */
820 /*! \brief XXX BOOLEAN Purpose??? */
821 unsigned int echobreak:1;
823 * \brief TRUE if echo cancellation enabled when bridged.
824 * \note Initialized with the "echocancelwhenbridged" value read in from chan_dahdi.conf
825 * \note Disabled if the echo canceller is not setup.
827 unsigned int echocanbridged:1;
828 /*! \brief TRUE if echo cancellation is turned on. */
829 unsigned int echocanon:1;
830 /*! \brief TRUE if a fax tone has already been handled. */
831 unsigned int faxhandled:1;
832 /*! TRUE if dynamic faxbuffers are configured for use, default is OFF */
833 unsigned int usefaxbuffers:1;
834 /*! TRUE while buffer configuration override is in use */
835 unsigned int bufferoverrideinuse:1;
836 /*! \brief TRUE if over a radio and dahdi_read() has been called. */
837 unsigned int firstradio:1;
839 * \brief TRUE if the call will be considered "hung up" on a polarity reversal.
840 * \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf
842 unsigned int hanguponpolarityswitch:1;
843 /*! \brief TRUE if DTMF detection needs to be done by hardware. */
844 unsigned int hardwaredtmf:1;
846 * \brief TRUE if the outgoing caller ID is blocked/hidden.
847 * \note Caller ID can be disabled by dialing *67.
848 * \note Caller ID can be enabled by dialing *82.
849 * \note Initialized with the "hidecallerid" value read in from chan_dahdi.conf
851 unsigned int hidecallerid:1;
853 * \brief TRUE if hide just the name not the number for legacy PBX use.
854 * \note Only applies to PRI channels.
855 * \note Set from the "hidecalleridname" value read in from chan_dahdi.conf
857 unsigned int hidecalleridname:1;
858 /*! \brief TRUE if DTMF detection is disabled. */
859 unsigned int ignoredtmf:1;
861 * \brief TRUE if the channel should be answered immediately
862 * without attempting to gather any digits.
863 * \note Set from the "immediate" value read in from chan_dahdi.conf
865 unsigned int immediate:1;
866 /*! \brief TRUE if in an alarm condition. */
867 unsigned int inalarm:1;
868 /*! \brief TRUE if TDD in MATE mode */
870 /*! \brief TRUE if we originated the call leg. */
871 unsigned int outgoing:1;
872 /* unsigned int overlapdial:1; unused and potentially confusing */
874 * \brief TRUE if busy extensions will hear the call-waiting tone
875 * and can use hook-flash to switch between callers.
876 * \note Set from the "callwaiting" value read in from chan_dahdi.conf
878 unsigned int permcallwaiting:1;
880 * \brief TRUE if the outgoing caller ID is blocked/restricted/hidden.
881 * \note Set from the "hidecallerid" value read in from chan_dahdi.conf
883 unsigned int permhidecallerid:1;
885 * \brief TRUE if PRI congestion/busy indications are sent out-of-band.
886 * \note Set from the "priindication" value read in from chan_dahdi.conf
888 unsigned int priindication_oob:1;
890 * \brief TRUE if PRI B channels are always exclusively selected.
891 * \note Set from the "priexclusive" value read in from chan_dahdi.conf
893 unsigned int priexclusive:1;
895 * \brief TRUE if we will pulse dial.
896 * \note Set from the "pulsedial" value read in from chan_dahdi.conf
898 unsigned int pulse:1;
899 /*! \brief TRUE if a pulsed digit was detected. (Pulse dial phone detected) */
900 unsigned int pulsedial:1;
901 unsigned int restartpending:1; /*!< flag to ensure counted only once for restart */
903 * \brief TRUE if caller ID is restricted.
904 * \note Set but not used. Should be deleted. Redundant with permhidecallerid.
905 * \note Set from the "restrictcid" value read in from chan_dahdi.conf
907 unsigned int restrictcid:1;
909 * \brief TRUE if three way calling is enabled
910 * \note Set from the "threewaycalling" value read in from chan_dahdi.conf
912 unsigned int threewaycalling:1;
914 * \brief TRUE if call transfer is enabled
915 * \note For FXS ports (either direct analog or over T1/E1):
916 * Support flash-hook call transfer
917 * \note For digital ports using ISDN PRI protocols:
918 * Support switch-side transfer (called 2BCT, RLT or other names)
919 * \note Set from the "transfer" value read in from chan_dahdi.conf
921 unsigned int transfer:1;
923 * \brief TRUE if caller ID is used on this channel.
924 * \note PRI and SS7 spans will save caller ID from the networking peer.
925 * \note FXS ports will generate the caller ID spill.
926 * \note FXO ports will listen for the caller ID spill.
927 * \note Set from the "usecallerid" value read in from chan_dahdi.conf
929 unsigned int use_callerid:1;
931 * \brief TRUE if we will use the calling presentation setting
932 * from the Asterisk channel for outgoing calls.
933 * \note Only applies to PRI and SS7 channels.
934 * \note Set from the "usecallingpres" value read in from chan_dahdi.conf
936 unsigned int use_callingpres:1;
938 * \brief TRUE if distinctive rings are to be detected.
939 * \note For FXO lines
940 * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
942 unsigned int usedistinctiveringdetection:1;
944 * \brief TRUE if we should use the callerid from incoming call on dahdi transfer.
945 * \note Set from the "useincomingcalleridondahditransfer" value read in from chan_dahdi.conf
947 unsigned int dahditrcallerid:1;
949 * \brief TRUE if allowed to flash-transfer to busy channels.
950 * \note Set from the "transfertobusy" value read in from chan_dahdi.conf
952 unsigned int transfertobusy:1;
954 * \brief TRUE if the FXO port monitors for neon type MWI indications from the other end.
955 * \note Set if the "mwimonitor" value read in contains "neon" from chan_dahdi.conf
957 unsigned int mwimonitor_neon:1;
959 * \brief TRUE if the FXO port monitors for fsk type MWI indications from the other end.
960 * \note Set if the "mwimonitor" value read in contains "fsk" from chan_dahdi.conf
962 unsigned int mwimonitor_fsk:1;
964 * \brief TRUE if the FXO port monitors for rpas precursor to fsk MWI indications from the other end.
965 * \note RPAS - Ring Pulse Alert Signal
966 * \note Set if the "mwimonitor" value read in contains "rpas" from chan_dahdi.conf
968 unsigned int mwimonitor_rpas:1;
969 /*! \brief TRUE if an MWI monitor thread is currently active */
970 unsigned int mwimonitoractive:1;
971 /*! \brief TRUE if a MWI message sending thread is active */
972 unsigned int mwisendactive:1;
974 * \brief TRUE if channel is out of reset and ready
975 * \note Set but not used.
977 unsigned int inservice:1;
979 * \brief TRUE if the channel is locally blocked.
980 * \note Applies to SS7 and MFCR2 channels.
982 unsigned int locallyblocked:1;
984 * \brief TRUE if the channel is remotely blocked.
985 * \note Applies to SS7 and MFCR2 channels.
987 unsigned int remotelyblocked:1;
989 * \brief TRUE if the channel alarms will be managed also as Span ones
990 * \note Applies to all channels
992 unsigned int manages_span_alarms:1;
994 #if defined(HAVE_PRI)
995 struct sig_pri_span *pri;
999 * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
1000 * \note Set from the "usesmdi" value read in from chan_dahdi.conf
1002 unsigned int use_smdi:1;
1003 struct mwisend_info mwisend_data;
1004 /*! \brief The SMDI interface to get SMDI messages from. */
1005 struct ast_smdi_interface *smdi_iface;
1007 /*! \brief Distinctive Ring data */
1008 struct dahdi_distRings drings;
1011 * \brief The configured context for incoming calls.
1012 * \note The "context" string read in from chan_dahdi.conf
1014 char context[AST_MAX_CONTEXT];
1016 * \brief A description for the channel configuration
1017 * \note The "description" string read in from chan_dahdi.conf
1019 char description[32];
1021 * \brief Saved context string.
1023 char defcontext[AST_MAX_CONTEXT];
1024 /*! \brief Extension to use in the dialplan. */
1025 char exten[AST_MAX_EXTENSION];
1027 * \brief Language configured for calls.
1028 * \note The "language" string read in from chan_dahdi.conf
1030 char language[MAX_LANGUAGE];
1032 * \brief The configured music-on-hold class to use for calls.
1033 * \note The "musicclass" or "mohinterpret" or "musiconhold" string read in from chan_dahdi.conf
1035 char mohinterpret[MAX_MUSICCLASS];
1037 * \brief Suggested music-on-hold class for peer channel to use for calls.
1038 * \note The "mohsuggest" string read in from chan_dahdi.conf
1040 char mohsuggest[MAX_MUSICCLASS];
1041 char parkinglot[AST_MAX_EXTENSION]; /*!< Parking lot for this channel */
1042 #if defined(HAVE_PRI) || defined(HAVE_SS7)
1043 /*! \brief Automatic Number Identification number (Alternate PRI caller ID number) */
1044 char cid_ani[AST_MAX_EXTENSION];
1045 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
1046 /*! \brief Automatic Number Identification code from PRI */
1048 /*! \brief Caller ID number from an incoming call. */
1049 char cid_num[AST_MAX_EXTENSION];
1051 * \brief Caller ID tag from incoming call
1052 * \note the "cid_tag" string read in from chan_dahdi.conf
1054 char cid_tag[AST_MAX_EXTENSION];
1055 /*! \brief Caller ID Q.931 TON/NPI field values. Set by PRI. Zero otherwise. */
1057 /*! \brief Caller ID name from an incoming call. */
1058 char cid_name[AST_MAX_EXTENSION];
1059 /*! \brief Caller ID subaddress from an incoming call. */
1060 char cid_subaddr[AST_MAX_EXTENSION];
1061 char *origcid_num; /*!< malloced original callerid */
1062 char *origcid_name; /*!< malloced original callerid */
1063 /*! \brief Call waiting number. */
1064 char callwait_num[AST_MAX_EXTENSION];
1065 /*! \brief Call waiting name. */
1066 char callwait_name[AST_MAX_EXTENSION];
1067 /*! \brief Redirecting Directory Number Information Service (RDNIS) number */
1068 char rdnis[AST_MAX_EXTENSION];
1069 /*! \brief Dialed Number Identifier */
1070 char dnid[AST_MAX_EXTENSION];
1072 * \brief Bitmapped groups this belongs to.
1073 * \note The "group" bitmapped group string read in from chan_dahdi.conf
1076 /*! \brief Default call PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW. */
1078 /*! \brief Active PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW */
1080 int confno; /*!< Our conference */
1081 int confusers; /*!< Who is using our conference */
1082 int propconfno; /*!< Propagated conference number */
1084 * \brief Bitmapped call groups this belongs to.
1085 * \note The "callgroup" bitmapped group string read in from chan_dahdi.conf
1087 ast_group_t callgroup;
1089 * \brief Bitmapped pickup groups this belongs to.
1090 * \note The "pickupgroup" bitmapped group string read in from chan_dahdi.conf
1092 ast_group_t pickupgroup;
1094 * \brief Channel variable list with associated values to set when a channel is created.
1095 * \note The "setvar" strings read in from chan_dahdi.conf
1097 struct ast_variable *vars;
1098 int channel; /*!< Channel Number */
1099 int span; /*!< Span number */
1100 time_t guardtime; /*!< Must wait this much time before using for new call */
1101 int cid_signalling; /*!< CID signalling type bell202 or v23 */
1102 int cid_start; /*!< CID start indicator, polarity or ring or DTMF without warning event */
1103 int dtmfcid_holdoff_state; /*!< State indicator that allows for line to settle before checking for dtmf energy */
1104 struct timeval dtmfcid_delay; /*!< Time value used for allow line to settle */
1105 int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
1106 int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
1107 int cidcwexpire; /*!< When to stop waiting for CID/CW CAS response (In samples) */
1108 int cid_suppress_expire; /*!< How many samples to suppress after a CID spill. */
1109 /*! \brief Analog caller ID waveform sample buffer */
1110 unsigned char *cidspill;
1111 /*! \brief Position in the cidspill buffer to send out next. */
1113 /*! \brief Length of the cidspill buffer containing samples. */
1115 /*! \brief Ring timeout timer?? */
1118 * \brief Ring timeout base.
1119 * \note Value computed indirectly from "ringtimeout" read in from chan_dahdi.conf
1123 * \brief Number of most significant digits/characters to strip from the dialed number.
1124 * \note Feature is deprecated. Use dialplan logic.
1125 * \note The characters are stripped before the PRI TON/NPI prefix
1126 * characters are processed.
1130 * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
1132 * After CAS is sent, the call waiting caller id will be sent if the phone
1133 * gives a positive reply.
1136 /*! \brief Number of call waiting rings. */
1138 /*! \brief Echo cancel parameters. */
1140 struct dahdi_echocanparams head;
1141 struct dahdi_echocanparam params[DAHDI_MAX_ECHOCANPARAMS];
1144 * \brief Echo training time. 0 = disabled
1145 * \note Set from the "echotraining" value read in from chan_dahdi.conf
1148 /*! \brief Filled with 'w'. XXX Purpose?? */
1151 * \brief Number of times to see "busy" tone before hanging up.
1152 * \note Set from the "busycount" value read in from chan_dahdi.conf
1156 * \brief Busy cadence pattern description.
1157 * \note Set from the "busypattern" value read from chan_dahdi.conf
1159 struct ast_dsp_busy_pattern busy_cadence;
1161 * \brief Bitmapped call progress detection flags. CALLPROGRESS_xxx values.
1162 * \note Bits set from the "callprogress" and "faxdetect" values read in from chan_dahdi.conf
1166 * \brief Number of milliseconds to wait for dialtone.
1167 * \note Set from the "waitfordialtone" value read in from chan_dahdi.conf
1169 int waitfordialtone;
1170 struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
1171 struct timeval flashtime; /*!< Last flash-hook time */
1172 /*! \brief Opaque DSP configuration structure. */
1173 struct ast_dsp *dsp;
1174 /*! \brief DAHDI dial operation command struct for ioctl() call. */
1175 struct dahdi_dialoperation dop;
1176 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
1177 /*! \brief Second part of SIG_FEATDMF_TA wink operation. */
1179 char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
1180 int amaflags; /*!< AMA Flags */
1181 struct tdd_state *tdd; /*!< TDD flag */
1182 /*! \brief Accumulated call forwarding number. */
1183 char call_forward[AST_MAX_EXTENSION];
1185 * \brief Voice mailbox location.
1186 * \note Set from the "mailbox" string read in from chan_dahdi.conf
1188 char mailbox[AST_MAX_EXTENSION];
1189 /*! \brief Opaque event subscription parameters for message waiting indication support. */
1190 struct ast_event_sub *mwi_event_sub;
1191 /*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
1193 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1194 struct dahdi_vmwi_info mwisend_setting; /*!< Which VMWI methods to use */
1195 unsigned int mwisend_fsk: 1; /*! Variable for enabling FSK MWI handling in chan_dahdi */
1196 unsigned int mwisend_rpas:1; /*! Variable for enabling Ring Pulse Alert before MWI FSK Spill */
1198 int distinctivering; /*!< Which distinctivering to use */
1199 int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
1200 /*! \brief Holding place for event injected from outside normal operation. */
1203 * \brief Minimal time period (ms) between the answer polarity
1204 * switch and hangup polarity switch.
1206 int polarityonanswerdelay;
1207 /*! \brief Start delay time if polarityonanswerdelay is nonzero. */
1208 struct timeval polaritydelaytv;
1210 * \brief Send caller ID on FXS after this many rings. Set to 1 for US.
1211 * \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
1213 int sendcalleridafter;
1214 /*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
1216 /*! \brief DSP feature flags: DSP_FEATURE_xxx */
1218 #if defined(HAVE_SS7)
1219 /*! \brief SS7 control parameters */
1220 struct sig_ss7_linkset *ss7;
1221 #endif /* defined(HAVE_SS7) */
1223 struct dahdi_mfcr2 *mfcr2;
1224 openr2_chan_t *r2chan;
1225 openr2_calling_party_category_t mfcr2_recvd_category;
1226 openr2_calling_party_category_t mfcr2_category;
1227 int mfcr2_dnis_index;
1228 int mfcr2_ani_index;
1230 int mfcr2_answer_pending:1;
1231 int mfcr2_charge_calls:1;
1232 int mfcr2_allow_collect_calls:1;
1233 int mfcr2_forced_release:1;
1234 int mfcr2_dnis_matched:1;
1235 int mfcr2_call_accepted:1;
1236 int mfcr2_accept_on_offer:1;
1237 int mfcr2_progress_sent:1;
1239 /*! \brief DTMF digit in progress. 0 when no digit in progress. */
1241 /*! \brief TRUE if confrence is muted. */
1244 struct ast_cc_config_params *cc_params;
1245 /* DAHDI channel names may differ greatly from the
1246 * string that was provided to an app such as Dial. We
1247 * need to save the original string passed to dahdi_request
1248 * for call completion purposes. This way, we can replicate
1249 * the original dialed string later.
1251 char dialstring[AST_CHANNEL_NAME];
1254 #define DATA_EXPORT_DAHDI_PVT(MEMBER) \
1255 MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
1256 MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
1257 MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
1258 MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
1259 MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
1260 MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
1261 MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
1262 MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
1263 MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
1264 MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
1265 MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
1266 MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
1267 MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
1268 MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
1269 MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
1270 MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
1271 MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
1272 MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
1273 MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
1274 MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
1275 MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
1276 MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
1277 MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
1278 MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
1279 MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
1280 MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
1281 MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
1282 MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
1283 MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
1284 MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
1285 MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
1286 MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
1287 MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
1288 MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
1289 MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
1290 MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
1291 MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
1292 MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
1293 MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
1294 MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
1295 MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
1296 MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
1297 MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
1298 MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
1299 MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
1300 MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
1301 MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
1302 MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
1303 MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
1304 MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
1305 MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
1306 MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
1307 MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
1308 MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
1309 MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
1310 MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
1311 MEMBER(dahdi_pvt, locallyblocked, AST_DATA_BOOLEAN) \
1312 MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_BOOLEAN) \
1313 MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
1314 MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
1315 MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
1316 MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
1317 MEMBER(dahdi_pvt, description, AST_DATA_STRING) \
1318 MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
1319 MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
1320 MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
1321 MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
1322 MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
1324 AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
1326 static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
1327 static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
1329 #if defined(HAVE_PRI)
1330 static struct dahdi_parms_pseudo {
1331 int buf_no; /*!< Number of buffers */
1332 int buf_policy; /*!< Buffer policy */
1333 int faxbuf_no; /*!< Number of Fax buffers */
1334 int faxbuf_policy; /*!< Fax buffer policy */
1335 } dahdi_pseudo_parms;
1336 #endif /* defined(HAVE_PRI) */
1338 /*! \brief Channel configuration from chan_dahdi.conf .
1339 * This struct is used for parsing the [channels] section of chan_dahdi.conf.
1340 * Generally there is a field here for every possible configuration item.
1342 * The state of fields is saved along the parsing and whenever a 'channel'
1343 * statement is reached, the current dahdi_chan_conf is used to configure the
1344 * channel (struct dahdi_pvt)
1346 * \see dahdi_chan_init for the default values.
1348 struct dahdi_chan_conf {
1349 struct dahdi_pvt chan;
1351 struct dahdi_pri pri;
1354 #if defined(HAVE_SS7)
1355 struct dahdi_ss7 ss7;
1356 #endif /* defined(HAVE_SS7) */
1359 struct dahdi_mfcr2_conf mfcr2;
1361 struct dahdi_params timing;
1362 int is_sig_auto; /*!< Use channel signalling from DAHDI? */
1363 /*! Continue configuration even if a channel is not there. */
1364 int ignore_failed_channels;
1367 * \brief The serial port to listen for SMDI data on
1368 * \note Set from the "smdiport" string read in from chan_dahdi.conf
1370 char smdi_port[SMDI_MAX_FILENAME_LEN];
1373 /*! returns a new dahdi_chan_conf with default values (by-value) */
1374 static struct dahdi_chan_conf dahdi_chan_conf_default(void)
1376 /* recall that if a field is not included here it is initialized
1377 * to 0 or equivalent
1379 struct dahdi_chan_conf conf = {
1382 .nsf = PRI_NSF_NONE,
1383 .switchtype = PRI_SWITCH_NI2,
1384 .dialplan = PRI_UNKNOWN + 1,
1385 .localdialplan = PRI_NATIONAL_ISDN + 1,
1386 .nodetype = PRI_CPE,
1387 .qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
1389 #if defined(HAVE_PRI_CCSS)
1390 .cc_ptmp_recall_mode = 1,/* specificRecall */
1391 .cc_qsig_signaling_link_req = 1,/* retain */
1392 .cc_qsig_signaling_link_rsp = 1,/* retain */
1393 #endif /* defined(HAVE_PRI_CCSS) */
1398 .internationalprefix = "",
1399 .nationalprefix = "",
1401 .privateprefix = "",
1402 .unknownprefix = "",
1403 .resetinterval = -1,
1406 #if defined(HAVE_SS7)
1408 .called_nai = SS7_NAI_NATIONAL,
1409 .calling_nai = SS7_NAI_NATIONAL,
1410 .internationalprefix = "",
1411 .nationalprefix = "",
1412 .subscriberprefix = "",
1415 #endif /* defined(HAVE_SS7) */
1418 .variant = OR2_VAR_ITU,
1419 .mfback_timeout = -1,
1420 .metering_pulse_timeout = -1,
1423 .get_ani_first = -1,
1424 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
1425 .skip_category_request = -1,
1428 .allow_collect_calls = 0,
1430 .accept_on_offer = 1,
1431 .forced_release = 0,
1433 .immediate_accept = -1,
1434 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
1436 .dtmf_detection = -1,
1437 .dtmf_time_on = OR2_DEFAULT_DTMF_ON,
1438 .dtmf_time_off = OR2_DEFAULT_DTMF_OFF,
1440 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
1441 .dtmf_end_timeout = -1,
1445 .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
1446 .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
1450 .context = "default",
1454 .mohinterpret = "default",
1457 .transfertobusy = 1,
1459 .cid_signalling = CID_SIG_BELL,
1460 .cid_start = CID_START_RING,
1461 .dahditrcallerid = 0,
1470 .echocancel.head.tap_length = 1,
1478 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1481 .polarityonanswerdelay = 600,
1483 .sendcalleridafter = DEFAULT_CIDRINGS,
1485 .buf_policy = DAHDI_POLICY_IMMEDIATE,
1488 .cc_params = ast_cc_config_params_init(),
1501 .smdi_port = "/dev/ttyS0",
1508 static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
1509 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
1510 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
1511 static int dahdi_sendtext(struct ast_channel *c, const char *text);
1512 static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout);
1513 static int dahdi_hangup(struct ast_channel *ast);
1514 static int dahdi_answer(struct ast_channel *ast);
1515 static struct ast_frame *dahdi_read(struct ast_channel *ast);
1516 static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
1517 static struct ast_frame *dahdi_exception(struct ast_channel *ast);
1518 static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1519 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
1520 static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
1521 static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
1522 static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
1523 static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
1524 static int dahdi_devicestate(void *data);
1525 static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
1527 static struct ast_channel_tech dahdi_tech = {
1529 .description = tdesc,
1530 .requester = dahdi_request,
1531 .send_digit_begin = dahdi_digit_begin,
1532 .send_digit_end = dahdi_digit_end,
1533 .send_text = dahdi_sendtext,
1535 .hangup = dahdi_hangup,
1536 .answer = dahdi_answer,
1538 .write = dahdi_write,
1539 .bridge = dahdi_bridge,
1540 .exception = dahdi_exception,
1541 .indicate = dahdi_indicate,
1542 .fixup = dahdi_fixup,
1543 .setoption = dahdi_setoption,
1544 .queryoption = dahdi_queryoption,
1545 .func_channel_read = dahdi_func_read,
1546 .func_channel_write = dahdi_func_write,
1547 .devicestate = dahdi_devicestate,
1548 .cc_callback = dahdi_cc_callback,
1551 #define GET_CHANNEL(p) ((p)->channel)
1553 #define SIG_PRI_LIB_HANDLE_CASES \
1560 * \brief Determine if sig_pri handles the signaling.
1563 * \param signaling Signaling to determine if is for sig_pri.
1565 * \return TRUE if the signaling is for sig_pri.
1567 static inline int dahdi_sig_pri_lib_handles(int signaling)
1571 switch (signaling) {
1572 case SIG_PRI_LIB_HANDLE_CASES:
1583 static enum analog_sigtype dahdisig_to_analogsig(int sig)
1587 return ANALOG_SIG_FXOLS;
1589 return ANALOG_SIG_FXOGS;
1591 return ANALOG_SIG_FXOKS;
1593 return ANALOG_SIG_FXSLS;
1595 return ANALOG_SIG_FXSGS;
1597 return ANALOG_SIG_FXSKS;
1599 return ANALOG_SIG_EMWINK;
1601 return ANALOG_SIG_EM;
1603 return ANALOG_SIG_EM_E1;
1605 return ANALOG_SIG_FEATD;
1607 return ANALOG_SIG_FEATDMF;
1611 return ANALOG_SIG_FGC_CAMA;
1612 case SIG_FGC_CAMAMF:
1613 return ANALOG_SIG_FGC_CAMAMF;
1615 return ANALOG_SIG_FEATB;
1617 return ANALOG_SIG_SFWINK;
1619 return ANALOG_SIG_SF;
1621 return ANALOG_SIG_SF_FEATD;
1622 case SIG_SF_FEATDMF:
1623 return ANALOG_SIG_SF_FEATDMF;
1624 case SIG_FEATDMF_TA:
1625 return ANALOG_SIG_FEATDMF_TA;
1627 return ANALOG_SIG_FEATB;
1634 static int analog_tone_to_dahditone(enum analog_tone tone)
1637 case ANALOG_TONE_RINGTONE:
1638 return DAHDI_TONE_RINGTONE;
1639 case ANALOG_TONE_STUTTER:
1640 return DAHDI_TONE_STUTTER;
1641 case ANALOG_TONE_CONGESTION:
1642 return DAHDI_TONE_CONGESTION;
1643 case ANALOG_TONE_DIALTONE:
1644 return DAHDI_TONE_DIALTONE;
1645 case ANALOG_TONE_DIALRECALL:
1646 return DAHDI_TONE_DIALRECALL;
1647 case ANALOG_TONE_INFO:
1648 return DAHDI_TONE_INFO;
1654 static int analogsub_to_dahdisub(enum analog_sub analogsub)
1658 switch (analogsub) {
1659 case ANALOG_SUB_REAL:
1662 case ANALOG_SUB_CALLWAIT:
1663 index = SUB_CALLWAIT;
1665 case ANALOG_SUB_THREEWAY:
1666 index = SUB_THREEWAY;
1669 ast_log(LOG_ERROR, "Unidentified sub!\n");
1676 static enum analog_event dahdievent_to_analogevent(int event);
1677 static int bump_gains(struct dahdi_pvt *p);
1678 static int dahdi_setlinear(int dfd, int linear);
1680 static int my_start_cid_detect(void *pvt, int cid_signalling)
1682 struct dahdi_pvt *p = pvt;
1683 int index = SUB_REAL;
1684 p->cs = callerid_new(cid_signalling);
1686 ast_log(LOG_ERROR, "Unable to alloc callerid\n");
1690 dahdi_setlinear(p->subs[index].dfd, 0);
1695 static int my_stop_cid_detect(void *pvt)
1697 struct dahdi_pvt *p = pvt;
1698 int index = SUB_REAL;
1700 callerid_free(p->cs);
1701 dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
1705 static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout)
1707 struct dahdi_pvt *p = pvt;
1708 struct analog_pvt *analog_p = p->sig_pvt;
1709 struct pollfd poller;
1711 int index = SUB_REAL;
1713 unsigned char buf[256];
1715 struct ast_format tmpfmt;
1717 poller.fd = p->subs[SUB_REAL].dfd;
1718 poller.events = POLLPRI | POLLIN;
1721 res = poll(&poller, 1, timeout);
1723 if (poller.revents & POLLPRI) {
1724 *ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd));
1728 if (poller.revents & POLLIN) {
1730 /* Change API: remove cid_signalling from get_callerid, add a new start_cid_detect and stop_cid_detect function
1731 * to enable slin mode and allocate cid detector. get_callerid should be able to be called any number of times until
1732 * either a timeout occurs or CID is detected (returns 0). returning 1 should be event received, and -1 should be
1733 * a failure and die, and returning 2 means no event was received. */
1734 res = read(p->subs[index].dfd, buf, sizeof(buf));
1736 if (errno != ELAST) {
1737 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1738 callerid_free(p->cs);
1743 if (analog_p->ringt > 0) {
1744 if (!(--analog_p->ringt)) {
1745 /* only return if we timeout from a ring event */
1750 if (p->cid_signalling == CID_SIG_V23_JP) {
1751 res = callerid_feed_jp(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1753 res = callerid_feed(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1757 * The previous diagnostic message output likely
1758 * explains why it failed.
1760 ast_log(LOG_WARNING, "Failed to decode CallerID\n");
1765 callerid_get(p->cs, &name, &num, &flags);
1767 ast_copy_string(namebuf, name, ANALOG_MAX_CID);
1769 ast_copy_string(numbuf, num, ANALOG_MAX_CID);
1771 ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
1776 *ev = ANALOG_EVENT_NONE;
1780 static const char *event2str(int event);
1781 static int restore_gains(struct dahdi_pvt *p);
1783 static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
1785 unsigned char buf[256];
1787 int curRingData[RING_PATTERNS];
1793 int checkaftercid = 0;
1795 struct dahdi_pvt *p = pvt;
1796 struct analog_pvt *analog_p = p->sig_pvt;
1798 if (ringdata == NULL) {
1799 ringdata = curRingData;
1804 /* We must have a ring by now, so, if configured, lets try to listen for
1805 * distinctive ringing */
1806 if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
1807 /* Clear the current ring data array so we don't have old data in it. */
1808 for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++)
1809 ringdata[receivedRingT] = 0;
1811 if (checkaftercid && distinctiveringaftercid)
1812 ast_verb(3, "Detecting post-CID distinctive ring\n");
1813 /* Check to see if context is what it should be, if not set to be. */
1814 else if (strcmp(p->context,p->defcontext) != 0) {
1815 ast_copy_string(p->context, p->defcontext, sizeof(p->context));
1816 ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
1820 i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
1821 if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
1822 ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
1826 if (i & DAHDI_IOMUX_SIGEVENT) {
1827 res = dahdi_get_event(p->subs[idx].dfd);
1828 if (res == DAHDI_EVENT_NOALARM) {
1830 analog_p->inalarm = 0;
1832 ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
1834 /* Let us detect distinctive ring */
1836 ringdata[receivedRingT] = analog_p->ringt;
1838 if (analog_p->ringt < analog_p->ringt_base/2)
1840 /* Increment the ringT counter so we can match it against
1841 values in chan_dahdi.conf for distinctive ring */
1842 if (++receivedRingT == RING_PATTERNS)
1844 } else if (i & DAHDI_IOMUX_READ) {
1845 res = read(p->subs[idx].dfd, buf, sizeof(buf));
1847 if (errno != ELAST) {
1848 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1854 if (analog_p->ringt > 0) {
1855 if (!(--analog_p->ringt)) {
1863 if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
1864 /* this only shows up if you have n of the dring patterns filled in */
1865 ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]);
1866 for (counter = 0; counter < 3; counter++) {
1867 /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */
1869 /* this only shows up if you have n of the dring patterns filled in */
1870 ast_verb(3, "Checking %d,%d,%d\n",
1871 p->drings.ringnum[counter].ring[0],
1872 p->drings.ringnum[counter].ring[1],
1873 p->drings.ringnum[counter].ring[2]);
1874 for (counter1 = 0; counter1 < 3; counter1++) {
1875 ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
1876 if (p->drings.ringnum[counter].ring[counter1] == -1) {
1877 ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
1878 ringdata[counter1]);
1880 } else if (ringdata[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
1881 ringdata[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
1882 ast_verb(3, "Ring pattern matched in range: %d to %d\n",
1883 (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
1884 (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
1889 if (distMatches == 3) {
1890 /* The ring matches, set the context to whatever is for distinctive ring.. */
1891 ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context));
1892 ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context));
1893 ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
1898 /* Restore linear mode (if appropriate) for Caller*ID processing */
1899 dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
1905 static int my_stop_callwait(void *pvt)
1907 struct dahdi_pvt *p = pvt;
1908 p->callwaitingrepeat = 0;
1910 p->cid_suppress_expire = 0;
1915 static int send_callerid(struct dahdi_pvt *p);
1916 static int save_conference(struct dahdi_pvt *p);
1917 static int restore_conference(struct dahdi_pvt *p);
1919 static int my_callwait(void *pvt)
1921 struct dahdi_pvt *p = pvt;
1922 struct ast_format tmpfmt;
1923 p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
1925 ast_log(LOG_WARNING, "Spill already exists?!?\n");
1926 ast_free(p->cidspill);
1930 * SAS: Subscriber Alert Signal, 440Hz for 300ms
1931 * CAS: CPE Alert Signal, 2130Hz * 2750Hz sine waves
1933 if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
1937 memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
1938 if (!p->callwaitrings && p->callwaitingcallerid) {
1939 ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1941 p->cidlen = 2400 + 680 + READ_SIZE * 4;
1943 ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1945 p->cidlen = 2400 + READ_SIZE * 4;
1953 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
1955 struct dahdi_pvt *p = pvt;
1956 struct ast_format tmpfmt;
1958 ast_debug(2, "Starting cid spill\n");
1961 ast_log(LOG_WARNING, "cidspill already exists??\n");
1962 ast_free(p->cidspill);
1965 if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
1967 p->cidlen = ast_callerid_generate(p->cidspill,
1968 caller->id.name.str,
1969 caller->id.number.str,
1970 ast_format_set(&tmpfmt, AST_LAW(p), 0));
1972 ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n",
1973 caller->id.name.str, caller->id.number.str);
1976 p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
1977 caller->id.name.str,
1978 caller->id.number.str,
1979 ast_format_set(&tmpfmt, AST_LAW(p), 0));
1980 p->cidlen += READ_SIZE * 4;
1983 p->cid_suppress_expire = 0;
1989 static int my_dsp_reset_and_flush_digits(void *pvt)
1991 struct dahdi_pvt *p = pvt;
1993 ast_dsp_digitreset(p->dsp);
1998 static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode)
2000 struct dahdi_pvt *p = pvt;
2002 if (p->channel == CHAN_PSEUDO)
2003 ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n");
2005 if (mode == ANALOG_DIGITMODE_DTMF) {
2006 /* If we do hardware dtmf, no need for a DSP */
2007 if (p->hardwaredtmf) {
2009 ast_dsp_free(p->dsp);
2016 p->dsp = ast_dsp_new();
2018 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
2023 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
2024 } else if (mode == ANALOG_DIGITMODE_MF) {
2026 p->dsp = ast_dsp_new();
2028 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
2032 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
2037 static int dahdi_wink(struct dahdi_pvt *p, int index);
2039 static int my_wink(void *pvt, enum analog_sub sub)
2041 struct dahdi_pvt *p = pvt;
2042 int index = analogsub_to_dahdisub(sub);
2043 if (index != SUB_REAL) {
2044 ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n");
2046 return dahdi_wink(p, index);
2049 static void wakeup_sub(struct dahdi_pvt *p, int a);
2051 static int reset_conf(struct dahdi_pvt *p);
2053 static inline int dahdi_confmute(struct dahdi_pvt *p, int muted);
2055 static void my_handle_dtmf(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
2057 struct ast_frame *f = *dest;
2058 struct dahdi_pvt *p = pvt;
2059 int idx = analogsub_to_dahdisub(analog_index);
2061 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
2062 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
2063 f->subclass.integer, f->subclass.integer, ast->name);
2065 if (f->subclass.integer == 'f') {
2066 if (f->frametype == AST_FRAME_DTMF_END) {
2067 /* Fax tone -- Handle and return NULL */
2068 if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
2069 /* If faxbuffers are configured, use them for the fax transmission */
2070 if (p->usefaxbuffers && !p->bufferoverrideinuse) {
2071 struct dahdi_bufferinfo bi = {
2072 .txbufpolicy = p->faxbuf_policy,
2073 .bufsize = p->bufsize,
2074 .numbufs = p->faxbuf_no
2078 if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
2079 ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast->name, strerror(errno));
2081 p->bufferoverrideinuse = 1;
2086 p->dsp_features &= ~DSP_FEATURE_FAX_DETECT;
2087 ast_dsp_set_features(p->dsp, p->dsp_features);
2088 ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast->name);
2090 if (strcmp(ast->exten, "fax")) {
2091 const char *target_context = S_OR(ast->macrocontext, ast->context);
2093 /* We need to unlock 'ast' here because ast_exists_extension has the
2094 * potential to start autoservice on the channel. Such action is prone
2097 ast_mutex_unlock(&p->lock);
2098 ast_channel_unlock(ast);
2099 if (ast_exists_extension(ast, target_context, "fax", 1,
2100 S_COR(ast->caller.id.number.valid, ast->caller.id.number.str, NULL))) {
2101 ast_channel_lock(ast);
2102 ast_mutex_lock(&p->lock);
2103 ast_verb(3, "Redirecting %s to fax extension\n", ast->name);
2104 /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
2105 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
2106 if (ast_async_goto(ast, target_context, "fax", 1))
2107 ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
2109 ast_channel_lock(ast);
2110 ast_mutex_lock(&p->lock);
2111 ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
2114 ast_debug(1, "Already in a fax extension, not redirecting\n");
2117 ast_debug(1, "Fax already handled\n");
2119 dahdi_confmute(p, 0);
2121 p->subs[idx].f.frametype = AST_FRAME_NULL;
2122 p->subs[idx].f.subclass.integer = 0;
2123 *dest = &p->subs[idx].f;
2127 static void my_lock_private(void *pvt)
2129 struct dahdi_pvt *p = pvt;
2130 ast_mutex_lock(&p->lock);
2133 static void my_unlock_private(void *pvt)
2135 struct dahdi_pvt *p = pvt;
2136 ast_mutex_unlock(&p->lock);
2139 static void my_deadlock_avoidance_private(void *pvt)
2141 struct dahdi_pvt *p = pvt;
2143 DEADLOCK_AVOIDANCE(&p->lock);
2148 * \brief Post an AMI DAHDI channel association event.
2151 * \param p DAHDI private pointer
2152 * \param chan Channel associated with the private pointer
2156 static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *chan)
2160 if (p->channel < CHAN_PSEUDO) {
2162 snprintf(ch_name, sizeof(ch_name), "no-media (%d)", p->channel);
2163 } else if (p->channel == CHAN_PSEUDO) {
2164 /* Pseudo channel */
2165 strcpy(ch_name, "pseudo");
2168 snprintf(ch_name, sizeof(ch_name), "%d", p->channel);
2170 ast_manager_event(chan, EVENT_FLAG_CALL, "DAHDIChannel",
2174 "DAHDIChannel: %s\r\n",
2184 * \brief Post an AMI DAHDI channel association event.
2187 * \param pvt DAHDI private pointer
2188 * \param chan Channel associated with the private pointer
2192 static void my_ami_channel_event(void *pvt, struct ast_channel *chan)
2194 struct dahdi_pvt *p = pvt;
2196 dahdi_ami_channel_event(p, chan);
2200 /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
2201 * returns the last value of the linear setting
2203 static int my_set_linear_mode(void *pvt, enum analog_sub sub, int linear_mode)
2205 struct dahdi_pvt *p = pvt;
2207 int idx = analogsub_to_dahdisub(sub);
2209 dahdi_setlinear(p->subs[idx].dfd, linear_mode);
2210 oldval = p->subs[idx].linear;
2211 p->subs[idx].linear = linear_mode ? 1 : 0;
2215 static void my_set_inthreeway(void *pvt, enum analog_sub sub, int inthreeway)
2217 struct dahdi_pvt *p = pvt;
2218 int idx = analogsub_to_dahdisub(sub);
2220 p->subs[idx].inthreeway = inthreeway;
2223 static int get_alarms(struct dahdi_pvt *p);
2224 static void handle_alarms(struct dahdi_pvt *p, int alms);
2225 static void my_get_and_handle_alarms(void *pvt)
2228 struct dahdi_pvt *p = pvt;
2230 res = get_alarms(p);
2231 handle_alarms(p, res);
2234 static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
2236 struct dahdi_pvt *p = ast_bridged_channel(chan)->tech_pvt;
2243 static int my_get_sub_fd(void *pvt, enum analog_sub sub)
2245 struct dahdi_pvt *p = pvt;
2246 int dahdi_sub = analogsub_to_dahdisub(sub);
2247 return p->subs[dahdi_sub].dfd;
2250 static void my_set_cadence(void *pvt, int *cidrings, struct ast_channel *ast)
2252 struct dahdi_pvt *p = pvt;
2254 /* Choose proper cadence */
2255 if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
2256 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
2257 ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
2258 *cidrings = cidrings[p->distinctivering - 1];
2260 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
2261 ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
2262 *cidrings = p->sendcalleridafter;
2266 static void my_set_alarm(void *pvt, int in_alarm)
2268 struct dahdi_pvt *p = pvt;
2270 p->inalarm = in_alarm;
2273 static void my_set_dialing(void *pvt, int is_dialing)
2275 struct dahdi_pvt *p = pvt;
2277 p->dialing = is_dialing;
2280 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2281 static void my_set_digital(void *pvt, int is_digital)
2283 struct dahdi_pvt *p = pvt;
2285 p->digital = is_digital;
2287 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2289 #if defined(HAVE_SS7)
2290 static void my_set_inservice(void *pvt, int is_inservice)
2292 struct dahdi_pvt *p = pvt;
2294 p->inservice = is_inservice;
2296 #endif /* defined(HAVE_SS7) */
2298 #if defined(HAVE_SS7)
2299 static void my_set_locallyblocked(void *pvt, int is_blocked)
2301 struct dahdi_pvt *p = pvt;
2303 p->locallyblocked = is_blocked;
2305 #endif /* defined(HAVE_SS7) */
2307 #if defined(HAVE_SS7)
2308 static void my_set_remotelyblocked(void *pvt, int is_blocked)
2310 struct dahdi_pvt *p = pvt;
2312 p->remotelyblocked = is_blocked;
2314 #endif /* defined(HAVE_SS7) */
2316 static void my_set_ringtimeout(void *pvt, int ringt)
2318 struct dahdi_pvt *p = pvt;
2322 static void my_set_waitingfordt(void *pvt, struct ast_channel *ast)
2324 struct dahdi_pvt *p = pvt;
2326 if (p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp) {
2327 ast_debug(1, "Defer dialing for %dms or dialtone\n", p->waitfordialtone);
2328 gettimeofday(&p->waitingfordt, NULL);
2329 ast_setstate(ast, AST_STATE_OFFHOOK);
2333 static int my_check_waitingfordt(void *pvt)
2335 struct dahdi_pvt *p = pvt;
2337 if (p->waitingfordt.tv_usec) {
2344 static void my_set_confirmanswer(void *pvt, int flag)
2346 struct dahdi_pvt *p = pvt;
2347 p->confirmanswer = flag;
2350 static int my_check_confirmanswer(void *pvt)
2352 struct dahdi_pvt *p = pvt;
2353 if (p->confirmanswer) {
2360 static void my_set_callwaiting(void *pvt, int callwaiting_enable)
2362 struct dahdi_pvt *p = pvt;
2364 p->callwaiting = callwaiting_enable;
2367 static void my_cancel_cidspill(void *pvt)
2369 struct dahdi_pvt *p = pvt;
2371 ast_free(p->cidspill);
2373 restore_conference(p);
2376 static int my_confmute(void *pvt, int mute)
2378 struct dahdi_pvt *p = pvt;
2379 return dahdi_confmute(p, mute);
2382 static void my_set_pulsedial(void *pvt, int flag)
2384 struct dahdi_pvt *p = pvt;
2385 p->pulsedial = flag;
2388 static void my_set_new_owner(void *pvt, struct ast_channel *new_owner)
2390 struct dahdi_pvt *p = pvt;
2392 p->owner = new_owner;
2395 static const char *my_get_orig_dialstring(void *pvt)
2397 struct dahdi_pvt *p = pvt;
2399 return p->dialstring;
2402 static void my_increase_ss_count(void)
2404 ast_mutex_lock(&ss_thread_lock);
2406 ast_mutex_unlock(&ss_thread_lock);
2409 static void my_decrease_ss_count(void)
2411 ast_mutex_lock(&ss_thread_lock);
2413 ast_cond_signal(&ss_thread_complete);
2414 ast_mutex_unlock(&ss_thread_lock);
2417 static void my_all_subchannels_hungup(void *pvt)
2419 struct dahdi_pvt *p = pvt;
2426 ast_dsp_free(p->dsp);
2430 p->law = p->law_default;
2431 law = p->law_default;
2432 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
2434 ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
2436 dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
2442 /* Cleanup owners here */
2443 for (i = 0; i < 3; i++) {
2444 p->subs[i].owner = NULL;
2450 if (num_restart_pending == 0) {
2455 static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index);
2457 static int my_conf_del(void *pvt, enum analog_sub sub)
2459 struct dahdi_pvt *p = pvt;
2460 int x = analogsub_to_dahdisub(sub);
2462 return conf_del(p, &p->subs[x], x);
2465 static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel);
2467 static int my_conf_add(void *pvt, enum analog_sub sub)
2469 struct dahdi_pvt *p = pvt;
2470 int x = analogsub_to_dahdisub(sub);
2472 return conf_add(p, &p->subs[x], x, 0);
2475 static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out);
2477 static int my_complete_conference_update(void *pvt, int needconference)
2479 struct dahdi_pvt *p = pvt;
2480 int needconf = needconference;
2483 struct dahdi_pvt *slave = NULL;
2485 useslavenative = isslavenative(p, &slave);
2487 /* If we have a slave, add him to our conference now. or DAX
2488 if this is slave native */
2489 for (x = 0; x < MAX_SLAVES; x++) {
2492 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
2494 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
2499 /* If we're supposed to be in there, do so now */
2500 if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
2502 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
2504 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
2508 /* If we have a master, add ourselves to his conference */
2510 if (isslavenative(p->master, NULL)) {
2511 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
2513 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
2517 /* Nobody is left (or should be left) in our conference.
2525 static int check_for_conference(struct dahdi_pvt *p);
2527 static int my_check_for_conference(void *pvt)
2529 struct dahdi_pvt *p = pvt;
2530 return check_for_conference(p);
2533 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)
2535 struct dahdi_pvt *p = pvt;
2540 da = analogsub_to_dahdisub(a);
2541 db = analogsub_to_dahdisub(b);
2543 tchan = p->subs[da].chan;
2544 p->subs[da].chan = p->subs[db].chan;
2545 p->subs[db].chan = tchan;
2547 tinthreeway = p->subs[da].inthreeway;
2548 p->subs[da].inthreeway = p->subs[db].inthreeway;
2549 p->subs[db].inthreeway = tinthreeway;
2551 p->subs[da].owner = ast_a;
2552 p->subs[db].owner = ast_b;
2555 ast_channel_set_fd(ast_a, 0, p->subs[da].dfd);
2557 ast_channel_set_fd(ast_b, 0, p->subs[db].dfd);
2565 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid);
2567 static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
2569 struct dahdi_pvt *p = pvt;
2570 int dsub = analogsub_to_dahdisub(sub);
2572 return dahdi_new(p, state, startpbx, dsub, 0, requestor ? requestor->linkedid : "");
2575 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2576 static int dahdi_setlaw(int dfd, int law)
2579 res = ioctl(dfd, DAHDI_SETLAW, &law);
2584 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2586 #if defined(HAVE_PRI)
2587 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)
2589 struct dahdi_pvt *p = pvt;
2594 case SIG_PRI_LIB_HANDLE_CASES:
2595 if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) {
2596 /* PRI nobch pseudo channel. Does not handle ioctl(DAHDI_AUDIOMODE) */
2601 /* Set to audio mode at this point */
2603 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) {
2604 ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
2605 p->channel, audio, strerror(errno));
2610 if (law != SIG_PRI_DEFLAW) {
2611 dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
2614 ast_copy_string(p->exten, exten, sizeof(p->exten));
2617 case SIG_PRI_DEFLAW:
2621 newlaw = DAHDI_LAW_ALAW;
2624 newlaw = DAHDI_LAW_MULAW;
2627 return dahdi_new(p, state, 0, SUB_REAL, newlaw, requestor ? requestor->linkedid : "");
2629 #endif /* defined(HAVE_PRI) */
2631 static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law);
2633 #if defined(HAVE_PRI)
2636 * \brief Open the PRI channel media path.
2639 * \param p Channel private control structure.
2643 static void my_pri_open_media(void *p)
2645 struct dahdi_pvt *pvt = p;
2650 dfd = pvt->subs[SUB_REAL].dfd;
2652 /* Open the media path. */
2654 res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val);
2656 ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n",
2657 pvt->channel, strerror(errno));
2660 /* Set correct companding law for this call. */
2661 res = dahdi_setlaw(dfd, pvt->law);
2663 ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel);
2666 /* Set correct gain for this call. */
2668 res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law);
2670 res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc,
2674 ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel);
2677 if (pvt->dsp_features && pvt->dsp) {
2678 ast_dsp_set_features(pvt->dsp, pvt->dsp_features);
2679 pvt->dsp_features = 0;
2682 #endif /* defined(HAVE_PRI) */
2684 static int unalloc_sub(struct dahdi_pvt *p, int x);
2686 static int my_unallocate_sub(void *pvt, enum analog_sub analogsub)
2688 struct dahdi_pvt *p = pvt;
2690 return unalloc_sub(p, analogsub_to_dahdisub(analogsub));
2693 static int alloc_sub(struct dahdi_pvt *p, int x);
2695 static int my_allocate_sub(void *pvt, enum analog_sub analogsub)
2697 struct dahdi_pvt *p = pvt;
2699 return alloc_sub(p, analogsub_to_dahdisub(analogsub));
2702 static int has_voicemail(struct dahdi_pvt *p);
2704 static int my_has_voicemail(void *pvt)
2706 struct dahdi_pvt *p = pvt;
2708 return has_voicemail(p);
2711 static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone)
2713 struct dahdi_pvt *p = pvt;
2716 index = analogsub_to_dahdisub(sub);
2718 return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone));
2721 static enum analog_event dahdievent_to_analogevent(int event)
2723 enum analog_event res;
2726 case DAHDI_EVENT_ONHOOK:
2727 res = ANALOG_EVENT_ONHOOK;
2729 case DAHDI_EVENT_RINGOFFHOOK:
2730 res = ANALOG_EVENT_RINGOFFHOOK;
2732 case DAHDI_EVENT_WINKFLASH:
2733 res = ANALOG_EVENT_WINKFLASH;
2735 case DAHDI_EVENT_ALARM:
2736 res = ANALOG_EVENT_ALARM;
2738 case DAHDI_EVENT_NOALARM:
2739 res = ANALOG_EVENT_NOALARM;
2741 case DAHDI_EVENT_DIALCOMPLETE:
2742 res = ANALOG_EVENT_DIALCOMPLETE;
2744 case DAHDI_EVENT_RINGERON:
2745 res = ANALOG_EVENT_RINGERON;
2747 case DAHDI_EVENT_RINGEROFF:
2748 res = ANALOG_EVENT_RINGEROFF;
2750 case DAHDI_EVENT_HOOKCOMPLETE:
2751 res = ANALOG_EVENT_HOOKCOMPLETE;
2753 case DAHDI_EVENT_PULSE_START:
2754 res = ANALOG_EVENT_PULSE_START;
2756 case DAHDI_EVENT_POLARITY:
2757 res = ANALOG_EVENT_POLARITY;
2759 case DAHDI_EVENT_RINGBEGIN:
2760 res = ANALOG_EVENT_RINGBEGIN;
2762 case DAHDI_EVENT_EC_DISABLED:
2763 res = ANALOG_EVENT_EC_DISABLED;
2765 case DAHDI_EVENT_REMOVED:
2766 res = ANALOG_EVENT_REMOVED;
2768 case DAHDI_EVENT_NEONMWI_ACTIVE:
2769 res = ANALOG_EVENT_NEONMWI_ACTIVE;
2771 case DAHDI_EVENT_NEONMWI_INACTIVE:
2772 res = ANALOG_EVENT_NEONMWI_INACTIVE;
2774 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2775 case DAHDI_EVENT_TX_CED_DETECTED:
2776 res = ANALOG_EVENT_TX_CED_DETECTED;
2778 case DAHDI_EVENT_RX_CED_DETECTED:
2779 res = ANALOG_EVENT_RX_CED_DETECTED;
2781 case DAHDI_EVENT_EC_NLP_DISABLED:
2782 res = ANALOG_EVENT_EC_NLP_DISABLED;
2784 case DAHDI_EVENT_EC_NLP_ENABLED:
2785 res = ANALOG_EVENT_EC_NLP_ENABLED;
2788 case DAHDI_EVENT_PULSEDIGIT:
2789 res = ANALOG_EVENT_PULSEDIGIT;
2791 case DAHDI_EVENT_DTMFDOWN:
2792 res = ANALOG_EVENT_DTMFDOWN;
2794 case DAHDI_EVENT_DTMFUP:
2795 res = ANALOG_EVENT_DTMFUP;
2798 switch(event & 0xFFFF0000) {
2799 case DAHDI_EVENT_PULSEDIGIT:
2800 case DAHDI_EVENT_DTMFDOWN:
2801 case DAHDI_EVENT_DTMFUP:
2802 /* The event includes a digit number in the low word.
2803 * Converting it to a 'enum analog_event' would remove
2804 * that information. Thus it is returned as-is.
2809 res = ANALOG_EVENT_ERROR;
2816 static inline int dahdi_wait_event(int fd);
2818 static int my_wait_event(void *pvt)
2820 struct dahdi_pvt *p = pvt;
2822 return dahdi_wait_event(p->subs[SUB_REAL].dfd);
2825 static int my_get_event(void *pvt)
2827 struct dahdi_pvt *p = pvt;
2830 if (p->fake_event) {
2831 res = p->fake_event;
2834 res = dahdi_get_event(p->subs[SUB_REAL].dfd);
2836 return dahdievent_to_analogevent(res);
2839 static int my_is_off_hook(void *pvt)
2841 struct dahdi_pvt *p = pvt;
2843 struct dahdi_params par;
2845 memset(&par, 0, sizeof(par));
2847 if (p->subs[SUB_REAL].dfd > -1)
2848 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
2850 /* Assume not off hook on CVRS */
2852 par.rxisoffhook = 0;
2855 ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
2858 if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
2859 /* When "onhook" that means no battery on the line, and thus
2860 it is out of service..., if it's on a TDM card... If it's a channel
2861 bank, there is no telling... */
2862 return (par.rxbits > -1) || par.rxisoffhook;
2865 return par.rxisoffhook;
2868 static void dahdi_enable_ec(struct dahdi_pvt *p);
2869 static void dahdi_disable_ec(struct dahdi_pvt *p);
2871 static int my_set_echocanceller(void *pvt, int enable)
2873 struct dahdi_pvt *p = pvt;
2878 dahdi_disable_ec(p);
2883 static int dahdi_ring_phone(struct dahdi_pvt *p);
2885 static int my_ring(void *pvt)
2887 struct dahdi_pvt *p = pvt;
2889 return dahdi_ring_phone(p);
2892 static int my_flash(void *pvt)
2894 struct dahdi_pvt *p = pvt;
2895 int func = DAHDI_FLASH;
2896 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &func);
2899 static inline int dahdi_set_hook(int fd, int hs);
2901 static int my_off_hook(void *pvt)
2903 struct dahdi_pvt *p = pvt;
2904 return dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
2907 static void my_set_needringing(void *pvt, int value)
2909 struct dahdi_pvt *p = pvt;
2910 p->subs[SUB_REAL].needringing = value;
2913 static void my_set_polarity(void *pvt, int value)
2915 struct dahdi_pvt *p = pvt;
2917 if (p->channel == CHAN_PSEUDO) {
2920 p->polarity = value;
2921 ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETPOLARITY, &value);
2924 static void my_start_polarityswitch(void *pvt)
2926 struct dahdi_pvt *p = pvt;
2928 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
2929 my_set_polarity(pvt, 0);
2933 static void my_answer_polarityswitch(void *pvt)
2935 struct dahdi_pvt *p = pvt;
2937 if (!p->answeronpolarityswitch) {
2941 my_set_polarity(pvt, 1);
2944 static void my_hangup_polarityswitch(void *pvt)
2946 struct dahdi_pvt *p = pvt;
2948 if (!p->hanguponpolarityswitch) {
2952 if (p->answeronpolarityswitch) {
2953 my_set_polarity(pvt, 0);
2955 my_set_polarity(pvt, 1);
2959 static int my_start(void *pvt)
2961 struct dahdi_pvt *p = pvt;
2962 int x = DAHDI_START;
2964 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
2967 static int my_dial_digits(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
2969 int index = analogsub_to_dahdisub(sub);
2971 struct dahdi_pvt *p = pvt;
2972 struct dahdi_dialoperation ddop;
2974 if (dop->op != ANALOG_DIAL_OP_REPLACE) {
2975 ast_log(LOG_ERROR, "Fix the dial_digits callback!\n");
2979 if (sub != ANALOG_SUB_REAL) {
2980 ast_log(LOG_ERROR, "Trying to dial_digits '%s' on channel %d subchannel %d\n",
2981 dop->dialstr, p->channel, sub);
2985 ddop.op = DAHDI_DIAL_OP_REPLACE;
2986 ast_copy_string(ddop.dialstr, dop->dialstr, sizeof(ddop.dialstr));
2988 ast_debug(1, "Channel %d: Sending '%s' to DAHDI_DIAL.\n", p->channel, ddop.dialstr);
2990 res = ioctl(p->subs[index].dfd, DAHDI_DIAL, &ddop);
2992 ast_debug(1, "DAHDI_DIAL ioctl failed on %s: %s\n", p->owner->name, strerror(errno));
2998 static void dahdi_train_ec(struct dahdi_pvt *p);
3000 static int my_train_echocanceller(void *pvt)
3002 struct dahdi_pvt *p = pvt;
3009 static int my_is_dialing(void *pvt, enum analog_sub sub)
3011 struct dahdi_pvt *p = pvt;
3015 index = analogsub_to_dahdisub(sub);
3017 if (ioctl(p->subs[index].dfd, DAHDI_DIALING, &x)) {
3018 ast_debug(1, "DAHDI_DIALING ioctl failed!\n");
3025 static int my_on_hook(void *pvt)
3027 struct dahdi_pvt *p = pvt;
3028 return dahdi_set_hook(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_ONHOOK);
3031 #if defined(HAVE_PRI)
3032 static void my_pri_fixup_chans(void *chan_old, void *chan_new)
3034 struct dahdi_pvt *old_chan = chan_old;
3035 struct dahdi_pvt *new_chan = chan_new;
3037 new_chan->owner = old_chan->owner;
3038 old_chan->owner = NULL;
3039 if (new_chan->owner) {
3040 new_chan->owner->tech_pvt = new_chan;
3041 new_chan->owner->fds[0] = new_chan->subs[SUB_REAL].dfd;
3042 new_chan->subs[SUB_REAL].owner = old_chan->subs[SUB_REAL].owner;
3043 old_chan->subs[SUB_REAL].owner = NULL;
3045 /* Copy any DSP that may be present */
3046 new_chan->dsp = old_chan->dsp;
3047 new_chan->dsp_features = old_chan->dsp_features;
3048 old_chan->dsp = NULL;
3049 old_chan->dsp_features = 0;
3051 /* Transfer flags from the old channel. */
3052 new_chan->dialing = old_chan->dialing;
3053 new_chan->digital = old_chan->digital;
3054 new_chan->outgoing = old_chan->outgoing;
3055 old_chan->dialing = 0;
3056 old_chan->digital = 0;
3057 old_chan->outgoing = 0;
3059 /* More stuff to transfer to the new channel. */
3060 new_chan->law = old_chan->law;
3061 strcpy(new_chan->dialstring, old_chan->dialstring);
3063 #endif /* defined(HAVE_PRI) */
3065 #if defined(HAVE_PRI)
3066 static int sig_pri_tone_to_dahditone(enum sig_pri_tone tone)
3069 case SIG_PRI_TONE_RINGTONE:
3070 return DAHDI_TONE_RINGTONE;
3071 case SIG_PRI_TONE_STUTTER:
3072 return DAHDI_TONE_STUTTER;
3073 case SIG_PRI_TONE_CONGESTION:
3074 return DAHDI_TONE_CONGESTION;
3075 case SIG_PRI_TONE_DIALTONE:
3076 return DAHDI_TONE_DIALTONE;
3077 case SIG_PRI_TONE_DIALRECALL:
3078 return DAHDI_TONE_DIALRECALL;
3079 case SIG_PRI_TONE_INFO:
3080 return DAHDI_TONE_INFO;
3081 case SIG_PRI_TONE_BUSY:
3082 return DAHDI_TONE_BUSY;
3087 #endif /* defined(HAVE_PRI) */
3089 #if defined(HAVE_PRI)
3090 static void my_handle_dchan_exception(struct sig_pri_span *pri, int index)
3094 ioctl(pri->fds[index], DAHDI_GETEVENT, &x);
3096 ast_log(LOG_NOTICE, "PRI got event: %s (%d) on D-channel of span %d\n", event2str(x), x, pri->span);
3098 /* Keep track of alarm state */
3100 case DAHDI_EVENT_ALARM:
3101 pri_event_alarm(pri, index, 0);
3103 case DAHDI_EVENT_NOALARM:
3104 pri_event_noalarm(pri, index, 0);
3110 #endif /* defined(HAVE_PRI) */
3112 #if defined(HAVE_PRI)
3113 static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone)
3115 struct dahdi_pvt *p = pvt;
3117 return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone));
3119 #endif /* defined(HAVE_PRI) */
3121 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3124 * \brief Set the caller id information.
3127 * \param pvt DAHDI private structure
3128 * \param caller Caller-id information to set.
3132 static void my_set_callerid(void *pvt, const struct ast_party_caller *caller)
3134 struct dahdi_pvt *p = pvt;
3136 ast_copy_string(p->cid_num,
3137 S_COR(caller->id.number.valid, caller->id.number.str, ""),
3138 sizeof(p->cid_num));
3139 ast_copy_string(p->cid_name,
3140 S_COR(caller->id.name.valid, caller->id.name.str, ""),
3141 sizeof(p->cid_name));
3142 ast_copy_string(p->cid_subaddr,
3143 S_COR(caller->id.subaddress.valid, caller->id.subaddress.str, ""),
3144 sizeof(p->cid_subaddr));
3145 p->cid_ton = caller->id.number.plan;
3146 p->callingpres = ast_party_id_presentation(&caller->id);
3147 if (caller->id.tag) {
3148 ast_copy_string(p->cid_tag, caller->id.tag, sizeof(p->cid_tag));
3150 ast_copy_string(p->cid_ani,
3151 S_COR(caller->ani.number.valid, caller->ani.number.str, ""),
3152 sizeof(p->cid_ani));
3153 p->cid_ani2 = caller->ani2;
3155 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3157 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3160 * \brief Set the Dialed Number Identifier.
3163 * \param pvt DAHDI private structure
3164 * \param dnid Dialed Number Identifier string.
3168 static void my_set_dnid(void *pvt, const char *dnid)
3170 struct dahdi_pvt *p = pvt;
3172 ast_copy_string(p->dnid, dnid, sizeof(p->dnid));
3174 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3176 #if defined(HAVE_PRI)
3179 * \brief Set the Redirecting Directory Number Information Service (RDNIS).
3182 * \param pvt DAHDI private structure
3183 * \param rdnis Redirecting Directory Number Information Service (RDNIS) string.
3187 static void my_set_rdnis(void *pvt, const char *rdnis)
3189 struct dahdi_pvt *p = pvt;
3191 ast_copy_string(p->rdnis, rdnis, sizeof(p->rdnis));
3193 #endif /* defined(HAVE_PRI) */
3195 #if defined(HAVE_PRI)
3198 * \brief Make a dialstring for native ISDN CC to recall properly.
3201 * \param priv Channel private control structure.
3202 * \param buf Where to put the modified dialstring.
3203 * \param buf_size Size of modified dialstring buffer.
3206 * original dialstring: